(window: WindowLike = getGlobal())
| 228 | }; |
| 229 | |
| 230 | function createDOMPurify(window: WindowLike = getGlobal()): DOMPurify { |
| 231 | const DOMPurify: DOMPurify = (root: WindowLike) => createDOMPurify(root); |
| 232 | |
| 233 | DOMPurify.version = VERSION; |
| 234 | |
| 235 | DOMPurify.removed = []; |
| 236 | |
| 237 | if ( |
| 238 | !window || |
| 239 | !window.document || |
| 240 | window.document.nodeType !== NODE_TYPE.document || |
| 241 | !window.Element |
| 242 | ) { |
| 243 | // Not running in a browser, provide a factory function |
| 244 | // so that you can pass your own Window |
| 245 | DOMPurify.isSupported = false; |
| 246 | |
| 247 | return DOMPurify; |
| 248 | } |
| 249 | |
| 250 | let { document } = window; |
| 251 | |
| 252 | const originalDocument = document; |
| 253 | const currentScript: HTMLScriptElement = |
| 254 | originalDocument.currentScript as HTMLScriptElement; |
| 255 | const { |
| 256 | DocumentFragment, |
| 257 | HTMLTemplateElement, |
| 258 | Node, |
| 259 | Element, |
| 260 | NodeFilter, |
| 261 | NamedNodeMap = window.NamedNodeMap || (window as any).MozNamedAttrMap, |
| 262 | HTMLFormElement, |
| 263 | DOMParser, |
| 264 | trustedTypes, |
| 265 | } = window; |
| 266 | |
| 267 | const ElementPrototype = Element.prototype; |
| 268 | |
| 269 | const cloneNode = lookupGetter(ElementPrototype, 'cloneNode'); |
| 270 | const remove = lookupGetter(ElementPrototype, 'remove'); |
| 271 | const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling'); |
| 272 | const getChildNodes = lookupGetter(ElementPrototype, 'childNodes'); |
| 273 | const getParentNode = lookupGetter(ElementPrototype, 'parentNode'); |
| 274 | const getShadowRoot = lookupGetter(ElementPrototype, 'shadowRoot'); |
| 275 | const getAttributes = lookupGetter(ElementPrototype, 'attributes'); |
| 276 | const getNodeType = |
| 277 | Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeType') : null; |
| 278 | const getNodeName = |
| 279 | Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeName') : null; |
| 280 | const getOwnerDocument = |
| 281 | Node && Node.prototype |
| 282 | ? lookupGetter(Node.prototype, 'ownerDocument') |
| 283 | : null; |
| 284 | |
| 285 | /* Clobber-safe nodeType / nodeName reads through the cached Node.prototype |
| 286 | getters, with a direct-property fallback for environments that lack |
| 287 | Node.prototype. Sites that need a different fallback (e.g. _isClobbered |
no test coverage detected