(window: WindowLike = getGlobal())
| 164 | }; |
| 165 | |
| 166 | function createDOMPurify(window: WindowLike = getGlobal()): DOMPurify { |
| 167 | const DOMPurify: DOMPurify = (root: WindowLike) => createDOMPurify(root); |
| 168 | |
| 169 | DOMPurify.version = VERSION; |
| 170 | |
| 171 | DOMPurify.removed = []; |
| 172 | |
| 173 | if ( |
| 174 | !window || |
| 175 | !window.document || |
| 176 | window.document.nodeType !== NODE_TYPE.document || |
| 177 | !window.Element |
| 178 | ) { |
| 179 | // Not running in a browser, provide a factory function |
| 180 | // so that you can pass your own Window |
| 181 | DOMPurify.isSupported = false; |
| 182 | |
| 183 | return DOMPurify; |
| 184 | } |
| 185 | |
| 186 | let { document } = window; |
| 187 | |
| 188 | const originalDocument = document; |
| 189 | const currentScript: HTMLScriptElement = |
| 190 | originalDocument.currentScript as HTMLScriptElement; |
| 191 | const { |
| 192 | DocumentFragment, |
| 193 | HTMLTemplateElement, |
| 194 | Node, |
| 195 | Element, |
| 196 | NodeFilter, |
| 197 | NamedNodeMap = window.NamedNodeMap || (window as any).MozNamedAttrMap, |
| 198 | HTMLFormElement, |
| 199 | DOMParser, |
| 200 | trustedTypes, |
| 201 | } = window; |
| 202 | |
| 203 | const ElementPrototype = Element.prototype; |
| 204 | |
| 205 | const cloneNode = lookupGetter(ElementPrototype, 'cloneNode'); |
| 206 | const remove = lookupGetter(ElementPrototype, 'remove'); |
| 207 | const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling'); |
| 208 | const getChildNodes = lookupGetter(ElementPrototype, 'childNodes'); |
| 209 | const getParentNode = lookupGetter(ElementPrototype, 'parentNode'); |
| 210 | const getShadowRoot = lookupGetter(ElementPrototype, 'shadowRoot'); |
| 211 | const getAttributes = lookupGetter(ElementPrototype, 'attributes'); |
| 212 | const getNodeType = |
| 213 | Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeType') : null; |
| 214 | const getNodeName = |
| 215 | Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeName') : null; |
| 216 | |
| 217 | // As per issue #47, the web-components registry is inherited by a |
| 218 | // new document created via createHTMLDocument. As per the spec |
| 219 | // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries) |
| 220 | // a new empty registry is used when creating a template contents owner |
| 221 | // document, so we use that as our parent document to ensure nothing |
| 222 | // is inherited. |
| 223 | if (typeof HTMLTemplateElement === 'function') { |
no test coverage detected
searching dependent graphs…