@shgysk8zer0/polyfills 0.3.10 → 0.3.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/Document.js +3 -1
- package/ShadowRoot.js +18 -1
- package/all.js +2 -0
- package/all.min.js +8 -8
- package/all.min.js.map +1 -1
- package/blob.js +5 -0
- package/element.js +4 -1
- package/methods/dom.js +39 -0
- package/package.json +1 -1
- package/request.js +5 -0
- package/response.js +4 -0
package/blob.js
ADDED
package/element.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { aria } from './aom.js';
|
|
2
|
-
import { polyfillGetterSetter } from './utils.js';
|
|
2
|
+
import { polyfillGetterSetter, polyfillMethod } from './utils.js';
|
|
3
|
+
import { setHTMLUnsafe } from './methods/dom.js';
|
|
3
4
|
import './sanitizer.js';
|
|
4
5
|
|
|
6
|
+
polyfillMethod(Element.prototype, 'setHTMLUnsafe', setHTMLUnsafe);
|
|
7
|
+
|
|
5
8
|
function handlePopover({ currentTarget }) {
|
|
6
9
|
switch(currentTarget.popoverTargetAction) {
|
|
7
10
|
case 'show':
|
package/methods/dom.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
function attachShadow(template){
|
|
2
|
+
if (template instanceof HTMLTemplateElement && template.parentElement instanceof HTMLElement) {
|
|
3
|
+
const shadow = template.parentElement.attachShadow({
|
|
4
|
+
mode: template.getAttribute('shadowrootmode'),
|
|
5
|
+
clonable: template.hasAttribute('shadowrootclonable'),
|
|
6
|
+
delegatesFocus: template.hasAttribute('shadowrootdelegatesfocus'),
|
|
7
|
+
serializable: template.hasAttribute('shadowrootserializable'),
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
shadow.append(template.content);
|
|
11
|
+
template.remove();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function parseHTMLUnsafe(input){
|
|
16
|
+
const parser = new DOMParser();
|
|
17
|
+
// Ensures `URL` is "about:blank"
|
|
18
|
+
const doc = document.implementation.createHTMLDocument();
|
|
19
|
+
// Rely on this method's TrustedTypes implementation, if available
|
|
20
|
+
const parsed = parser.parseFromString(input, 'text/html');
|
|
21
|
+
doc.head.append(...parsed.head.childNodes);
|
|
22
|
+
doc.body.append(...parsed.body.childNodes);
|
|
23
|
+
doc.querySelectorAll('template[shadowrootmode]').forEach(attachShadow);
|
|
24
|
+
return doc;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function setHTMLUnsafe(input) {
|
|
28
|
+
const parser = new DOMParser();
|
|
29
|
+
// Rely on this method's TrustedTypes implementation, if available
|
|
30
|
+
const parsed = parser.parseFromString(input, 'text/html');
|
|
31
|
+
const frag = document.createDocumentFragment();
|
|
32
|
+
frag.append(...parsed.body.childNodes);
|
|
33
|
+
attachShadow(frag.querySelector('template[shadowroootmode]'));
|
|
34
|
+
this.replaceChildren(frag);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function getHTML() {
|
|
38
|
+
return this.innerHTML;
|
|
39
|
+
}
|
package/package.json
CHANGED
package/request.js
ADDED
package/response.js
CHANGED