@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/blob.js ADDED
@@ -0,0 +1,5 @@
1
+ import { polyfillMethod } from './utils.js';
2
+
3
+ polyfillMethod(Blob.prototype, 'bytes', async function () {
4
+ return new Uint8Array(await this.arrayBuffer());
5
+ });
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.10",
3
+ "version": "0.3.11",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "A collection of JavaScript polyfills",
package/request.js ADDED
@@ -0,0 +1,5 @@
1
+ import { polyfillMethod } from './utils.js';
2
+
3
+ polyfillMethod(Request.prototype, 'bytes', async function () {
4
+ return new Uint8Array(await this.arrayBuffer());
5
+ });
package/response.js CHANGED
@@ -15,3 +15,7 @@ polyfillMethod(Response, 'redirect', (url, status = 302) => {
15
15
  headers: new Headers({ Location: url }),
16
16
  });
17
17
  });
18
+
19
+ polyfillMethod(Response.prototype, 'bytes', async function() {
20
+ return new Uint8Array(await this.arrayBuffer());
21
+ });