Skip to content

Commit 52116a2

Browse files
committed
Inline the CSP types.
1 parent b07009d commit 52116a2

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

src/index.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
import {CSPTrustedHTMLToStringable, CSPTrustedTypesPolicy} from './trusted-types'
2-
31
const privateData = new WeakMap()
42

53
function isWildcard(accept: string | null) {
64
return accept && !!accept.split(',').find(x => x.match(/^\s*\*\/\*/))
75
}
86

7+
// We don't want to add `@types/trusted-types` as a dependency, so we use this stand-in.
8+
9+
interface CSPTrustedHTMLToStringable {
10+
toString: () => string
11+
}
12+
interface CSPTrustedTypesPolicy {
13+
createHTML: (s: string, response: Response) => CSPTrustedHTMLToStringable
14+
}
915
let cspTrustedTypesPolicy: Promise<CSPTrustedTypesPolicy> | null = null
1016
export function setCSPTrusedTypesPolicy(policy: CSPTrustedTypesPolicy | Promise<CSPTrustedTypesPolicy>): void {
1117
cspTrustedTypesPolicy = Promise.resolve(policy)
@@ -202,7 +208,7 @@ export default class IncludeFragmentElement extends HTMLElement {
202208
throw new Error(`Failed to load resource: expected ${this.accept || 'text/html'} but was ${ct}`)
203209
}
204210

205-
let responseText: string = await response.text()
211+
const responseText: string = await response.text()
206212
let data: string | CSPTrustedHTMLToStringable = responseText
207213
if (cspTrustedTypesPolicy) {
208214
data = await cspTrustedTypesPolicy.then(policy => policy.createHTML(responseText, response))

src/trusted-types.d.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)