@shgysk8zer0/polyfills 0.3.10 → 0.3.12
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 +14 -0
- package/Document.js +3 -1
- package/ShadowRoot.js +18 -1
- package/all.js +3 -0
- package/all.min.js +11 -11
- 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 +3 -2
- package/promise.js +21 -0
- package/request.js +5 -0
- package/response.js +4 -0
- package/string.js +5 -0
- package/symbols.js +16 -0
- package/url.js +10 -3
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shgysk8zer0/polyfills",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.12",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "A collection of JavaScript polyfills",
|
|
@@ -78,6 +78,7 @@
|
|
|
78
78
|
},
|
|
79
79
|
"dependencies": {
|
|
80
80
|
"@aegisjsproject/sanitizer": "^0.1.0",
|
|
81
|
-
"@aegisjsproject/trusted-types": "^1.0.1"
|
|
81
|
+
"@aegisjsproject/trusted-types": "^1.0.1",
|
|
82
|
+
"string-dedent": "^3.0.1"
|
|
82
83
|
}
|
|
83
84
|
}
|
package/promise.js
CHANGED
|
@@ -67,4 +67,25 @@ if ('Promise' in globalThis) {
|
|
|
67
67
|
return def;
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
|
+
|
|
71
|
+
if (! (Promise.fromEntries instanceof Function)) {
|
|
72
|
+
Promise.fromEntries = async function fromEntries(entries) {
|
|
73
|
+
const keys = [];
|
|
74
|
+
const values = [];
|
|
75
|
+
|
|
76
|
+
for (const [key, value] of entries) {
|
|
77
|
+
keys.push(key);
|
|
78
|
+
values.push(value);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return await Promise.all(values)
|
|
82
|
+
.then(values => Object.fromEntries(values.map((value, i) => [keys[i], value])));
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (!(Promise.ownProperties instanceof Function)) {
|
|
87
|
+
Promise.ownProperties = async function ownProperties(obj) {
|
|
88
|
+
return await Promise.fromEntries(Object.entries(obj));
|
|
89
|
+
};
|
|
90
|
+
}
|
|
70
91
|
}
|
package/request.js
ADDED
package/response.js
CHANGED
package/string.js
ADDED
package/symbols.js
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
+
import { polyfillMethod } from './utils.js';
|
|
2
|
+
|
|
1
3
|
if ('Symbol' in globalThis) {
|
|
4
|
+
const known = new Set(
|
|
5
|
+
Reflect.ownKeys(Symbol)
|
|
6
|
+
.filter(item => typeof Symbol[item] === 'symbol')
|
|
7
|
+
.map(key => Symbol[key])
|
|
8
|
+
);
|
|
9
|
+
|
|
2
10
|
if (typeof Symbol.toStringTag === 'undefined') {
|
|
3
11
|
Symbol.toStringTag = Symbol('Symbol.toStringTag');
|
|
4
12
|
}
|
|
@@ -6,4 +14,12 @@ if ('Symbol' in globalThis) {
|
|
|
6
14
|
if (typeof Symbol.iterator === 'undefined') {
|
|
7
15
|
Symbol.iterator = Symbol('Symbol.iterator');
|
|
8
16
|
}
|
|
17
|
+
|
|
18
|
+
polyfillMethod(Symbol, 'isRegistered', function(symbol) {
|
|
19
|
+
return typeof symbol === 'symbol' && typeof Symbol.keyFor(symbol) === 'string';
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
polyfillMethod(Symbol, 'isWellKnown', function(symbol) {
|
|
23
|
+
return known.has(symbol);
|
|
24
|
+
});
|
|
9
25
|
}
|
package/url.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { polyfillMethod } from './utils.js';
|
|
2
2
|
|
|
3
|
-
polyfillMethod(URL, '
|
|
3
|
+
polyfillMethod(URL, 'parse', (url, base) => {
|
|
4
4
|
try {
|
|
5
|
-
new URL(
|
|
6
|
-
|
|
5
|
+
return new URL(url, base);
|
|
6
|
+
} catch {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
polyfillMethod(URL, 'canParse', (url, base) => {
|
|
12
|
+
try {
|
|
13
|
+
return new URL(url, base) instanceof URL;
|
|
7
14
|
} catch {
|
|
8
15
|
return false;
|
|
9
16
|
}
|