@shgysk8zer0/polyfills 0.3.9 → 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 +17 -0
- package/Document.js +3 -1
- package/ShadowRoot.js +18 -1
- package/all.js +2 -0
- package/all.min.js +7 -7
- package/all.min.js.map +1 -1
- package/blob.js +5 -0
- package/element.js +4 -1
- package/math.js +22 -1
- package/methods/dom.js +39 -0
- package/package.json +2 -2
- 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/math.js
CHANGED
|
@@ -67,8 +67,29 @@ if (! (Math.constrain instanceof Function)) {
|
|
|
67
67
|
/**
|
|
68
68
|
* @see https://github.com/tc39/proposal-math-sum
|
|
69
69
|
*/
|
|
70
|
+
if (! (Math.sumPrecise instanceof Function)) {
|
|
71
|
+
Math.sumPrecise = function sumPrecise(nums) {
|
|
72
|
+
let sum = -0;
|
|
73
|
+
|
|
74
|
+
for (const num of nums) {
|
|
75
|
+
if (! Number.isFinite(num)) {
|
|
76
|
+
sum = -0;
|
|
77
|
+
break;
|
|
78
|
+
} else {
|
|
79
|
+
sum += num;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return sum;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @deprecated
|
|
89
|
+
*/
|
|
70
90
|
if(! (Math.sum instanceof Function)) {
|
|
71
91
|
Math.sum = function(...nums) {
|
|
72
|
-
|
|
92
|
+
console.warn('Math.sum is deprecated. Please use Math.sumPrecise instead.');
|
|
93
|
+
return Math.sumPrecise(nums);
|
|
73
94
|
};
|
|
74
95
|
}
|
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.11",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "A collection of JavaScript polyfills",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"http-server": "^14.1.1"
|
|
78
78
|
},
|
|
79
79
|
"dependencies": {
|
|
80
|
-
"@aegisjsproject/sanitizer": "^0.0
|
|
80
|
+
"@aegisjsproject/sanitizer": "^0.1.0",
|
|
81
81
|
"@aegisjsproject/trusted-types": "^1.0.1"
|
|
82
82
|
}
|
|
83
83
|
}
|
package/request.js
ADDED
package/response.js
CHANGED