@shgysk8zer0/polyfills 0.0.2
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 +7 -0
- package/LICENSE +21 -0
- package/README.md +2 -0
- package/abort.js +194 -0
- package/all.js +30 -0
- package/animation.js +33 -0
- package/aom.js +43 -0
- package/appBadge.js +27 -0
- package/array.js +258 -0
- package/assets/CookieStore.js +230 -0
- package/assets/Lock.js +31 -0
- package/assets/LockManager.js +278 -0
- package/assets/Sanitizer.js +59 -0
- package/assets/SanitizerConfig.js +348 -0
- package/assets/SanitizerConfigBase.js +18 -0
- package/assets/SanitizerConfigEdge.js +335 -0
- package/assets/SanitizerConfigW3C.js +766 -0
- package/assets/Scheduler.js +124 -0
- package/assets/TextDecoder.js +83 -0
- package/assets/TextEncoder.js +41 -0
- package/assets/TrustedTypes.js +595 -0
- package/assets/attributes.js +15 -0
- package/assets/csp.js +29 -0
- package/assets/error.js +8 -0
- package/assets/sanitizerUtils.js +270 -0
- package/assets/trust.js +190 -0
- package/assets/utility.js +101 -0
- package/cookieStore.js +2 -0
- package/crypto.js +8 -0
- package/dialog.js +63 -0
- package/element.js +171 -0
- package/elementInternals.js +616 -0
- package/errors.js +21 -0
- package/function.js +31 -0
- package/globalThis.js +36 -0
- package/iterator.js +197 -0
- package/legacy/array.js +15 -0
- package/legacy/element.js +140 -0
- package/legacy/map.js +168 -0
- package/legacy/object.js +42 -0
- package/legacy.js +9 -0
- package/locks.js +33 -0
- package/map.js +32 -0
- package/match-media.js +58 -0
- package/math.js +69 -0
- package/navigator.js +55 -0
- package/number.js +14 -0
- package/package.json +52 -0
- package/performance.js +36 -0
- package/promise.js +70 -0
- package/sanitizer.js +3 -0
- package/scheduler.js +5 -0
- package/secure-context.js +31 -0
- package/set.js +73 -0
- package/share.js +17 -0
- package/symbols.js +9 -0
- package/textEncoder.js +16 -0
- package/trustedTypes.js +3 -0
- package/weakMap.js +28 -0
- package/window.js +85 -0
package/element.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import './dialog.js';
|
|
2
|
+
import { aria } from './aom.js';
|
|
3
|
+
|
|
4
|
+
if (! (HTMLScriptElement.supports instanceof Function)) {
|
|
5
|
+
HTMLScriptElement.supports = function supports(type) {
|
|
6
|
+
switch(type.toLowerCase()) {
|
|
7
|
+
case 'classic':
|
|
8
|
+
return true;
|
|
9
|
+
|
|
10
|
+
case 'module':
|
|
11
|
+
return 'noModule' in HTMLScriptElement.prototype;
|
|
12
|
+
|
|
13
|
+
case 'importmap':
|
|
14
|
+
return false;
|
|
15
|
+
|
|
16
|
+
case 'speculationrules':
|
|
17
|
+
return false;
|
|
18
|
+
|
|
19
|
+
default:
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (! Element.prototype.hasOwnProperty(aria.role)) {
|
|
26
|
+
const enumerable = true;
|
|
27
|
+
const configurable = true;
|
|
28
|
+
|
|
29
|
+
const props = Object.fromEntries(Object.entries(aria).map(([prop, attr]) => [prop, {
|
|
30
|
+
get: function() {
|
|
31
|
+
return this.getAttribute(attr);
|
|
32
|
+
},
|
|
33
|
+
set: function(val) {
|
|
34
|
+
if (typeof val === 'string') {
|
|
35
|
+
this.setAttribute(attr, val);
|
|
36
|
+
} else {
|
|
37
|
+
this.removeAttribute(attr);
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
enumerable, configurable,
|
|
41
|
+
}]));
|
|
42
|
+
|
|
43
|
+
Object.defineProperties(Element.prototype, props);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (! HTMLElement.prototype.hasOwnProperty('inert')) {
|
|
47
|
+
// CSS will handle pointer events
|
|
48
|
+
const previous = new WeakMap();
|
|
49
|
+
const restoreTabIndex = el => {
|
|
50
|
+
if (previous.has(el)) {
|
|
51
|
+
el.tabIndex = previous.get(el);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (el.hasChildNodes()) {
|
|
55
|
+
[...el.children].forEach(restoreTabIndex);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const setTabIndex = el => {
|
|
60
|
+
if (el.tabIndex !== -1) {
|
|
61
|
+
previous.set(el, el.tabIndex);
|
|
62
|
+
el.tabIndex = -1;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (el.hasChildNodes()) {
|
|
66
|
+
[...el.children].forEach(setTabIndex);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
Object.defineProperty(HTMLElement.prototype, 'inert', {
|
|
71
|
+
get: function() {
|
|
72
|
+
return this.hasAttribute('inert');
|
|
73
|
+
},
|
|
74
|
+
set: function(val) {
|
|
75
|
+
if (val) {
|
|
76
|
+
this.setAttribute('aria-hidden', 'true');
|
|
77
|
+
this.setAttribute('inert', '');
|
|
78
|
+
setTabIndex(this);
|
|
79
|
+
} else {
|
|
80
|
+
this.removeAttribute('aria-hidden');
|
|
81
|
+
this.removeAttribute('inert');
|
|
82
|
+
restoreTabIndex(this);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
enumerable: true, configurable: true,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (! HTMLImageElement.prototype.hasOwnProperty('complete')) {
|
|
90
|
+
/**
|
|
91
|
+
* Note: This shim cannot detect if an image has an error while loading
|
|
92
|
+
* and will return false on an invalid URL, for example. It also does not
|
|
93
|
+
* work for 0-sized images, if such a thing is possible.
|
|
94
|
+
*/
|
|
95
|
+
Object.defineProperty(HTMLImageElement.prototype, 'complete', {
|
|
96
|
+
get: function() {
|
|
97
|
+
return this.src === '' || this.naturalHeight > 0;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (! (HTMLImageElement.prototype.decode instanceof Function)) {
|
|
103
|
+
HTMLImageElement.prototype.decode = function () {
|
|
104
|
+
if (this.complete) {
|
|
105
|
+
return Promise.resolve();
|
|
106
|
+
} else {
|
|
107
|
+
return new Promise((resolve, reject) => {
|
|
108
|
+
const load = () => {
|
|
109
|
+
this.removeEventListener('error', error);
|
|
110
|
+
this.removeEventListener('load', load);
|
|
111
|
+
resolve();
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const error = (err) => {
|
|
115
|
+
this.removeEventListener('error', error);
|
|
116
|
+
this.removeEventListener('load', load);
|
|
117
|
+
reject(err);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
this.addEventListener('load', load);
|
|
121
|
+
this.addEventListener('error', error);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (
|
|
128
|
+
! (Element.prototype.setHTML instanceof Function)
|
|
129
|
+
&& 'Sanitizer' in globalThis
|
|
130
|
+
&& globalThis.Sanitizer.sanitizeFor instanceof Function
|
|
131
|
+
) {
|
|
132
|
+
Element.prototype.setHTML = function setHTML(input, { sanitizer = new globalThis.Sanitizer() } = {}) {
|
|
133
|
+
if (
|
|
134
|
+
('Sanitizer' in globalThis && sanitizer instanceof globalThis.Sanitizer)
|
|
135
|
+
|| (typeof sanitizer !== 'undefined' && sanitizer.sanitizeFor instanceof Function)
|
|
136
|
+
) {
|
|
137
|
+
const el = sanitizer.sanitizeFor(this.tagName.toLowerCase(), input);
|
|
138
|
+
this.replaceChildren(...el.children);
|
|
139
|
+
} else {
|
|
140
|
+
throw new TypeError('`sanitizer` is not a valid Sanitizer');
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (! HTMLTemplateElement.prototype.hasOwnProperty('shadowRootMode')) {
|
|
146
|
+
Object.defineProperty(HTMLTemplateElement.prototype, 'shadowRootMode', {
|
|
147
|
+
get: function() {
|
|
148
|
+
return this.getAttribute('shadowrootmode');
|
|
149
|
+
},
|
|
150
|
+
set: function(val) {
|
|
151
|
+
this.setAttribute('shadowrootmode', val);
|
|
152
|
+
},
|
|
153
|
+
enumerable: true,
|
|
154
|
+
configurable: true,
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
const attachShadows = (base = document) => {
|
|
158
|
+
base.querySelectorAll('template[shadowrootmode]').forEach(tmp => {
|
|
159
|
+
const shadow = tmp.parentElement.attachShadow({ mode: tmp.shadowRootMode });
|
|
160
|
+
shadow.append(tmp.content);
|
|
161
|
+
tmp.remove();
|
|
162
|
+
attachShadows(shadow);
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
if (document.readyState === 'loading') {
|
|
167
|
+
document.addEventListener('readystatechange', () => attachShadows(document), { once: true });
|
|
168
|
+
} else {
|
|
169
|
+
attachShadows(document);
|
|
170
|
+
}
|
|
171
|
+
}
|