-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from shgysk8zer0/patch/dom-and-bytes
Several new polyfills
- Loading branch information
Showing
13 changed files
with
94 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ logs | |
*.min.js | ||
*.min.js.map | ||
.bak | ||
.DS_STORE | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
import { polyfillGetterSetter } from './utils.js'; | ||
import { polyfillGetterSetter, polyfillMethod } from './utils.js'; | ||
import { adoptedStyleSheets } from './assets/adoptedStylesheets.js'; | ||
import { parseHTMLUnsafe } from './methods/dom.js'; | ||
|
||
polyfillGetterSetter(Document.prototype, 'adoptedStyleSheets', adoptedStyleSheets); | ||
polyfillMethod(Document, 'parseHTMLUnsafe', parseHTMLUnsafe); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,23 @@ | ||
import { polyfillGetterSetter } from './utils.js'; | ||
import { polyfillGetterSetter, polyfillMethod } from './utils.js'; | ||
import { adoptedStyleSheets } from './assets/adoptedStylesheets.js'; | ||
import { setHTMLUnsafe } from './methods/dom.js'; | ||
|
||
if ('ShadowRoot' in globalThis) { | ||
polyfillGetterSetter(ShadowRoot.prototype, 'adoptedStyleSheets', adoptedStyleSheets); | ||
polyfillMethod(ShadowRoot.prototype, 'setHTMLUnsafe', setHTMLUnsafe); | ||
|
||
polyfillMethod(ShadowRoot.prototype, 'getHTML', function ({ shadowRoots, serializableShadowRoots = false } = {}) { | ||
const clone = this.cloneNode(true); | ||
|
||
if (serializableShadowRoots) { | ||
// | ||
} | ||
|
||
if (Array.isArray(shadowRoots)) { | ||
// | ||
} | ||
|
||
return clone.innerHTML; | ||
}); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { polyfillMethod } from './utils.js'; | ||
|
||
polyfillMethod(Blob.prototype, 'bytes', async function () { | ||
return new Uint8Array(await this.arrayBuffer()); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
function attachShadow(template){ | ||
if (template instanceof HTMLTemplateElement && template.parentElement instanceof HTMLElement) { | ||
const shadow = template.parentElement.attachShadow({ | ||
mode: template.getAttribute('shadowrootmode'), | ||
clonable: template.hasAttribute('shadowrootclonable'), | ||
delegatesFocus: template.hasAttribute('shadowrootdelegatesfocus'), | ||
serializable: template.hasAttribute('shadowrootserializable'), | ||
}); | ||
|
||
shadow.append(template.content); | ||
template.remove(); | ||
} | ||
} | ||
|
||
export function parseHTMLUnsafe(input){ | ||
const parser = new DOMParser(); | ||
// Ensures `URL` is "about:blank" | ||
const doc = document.implementation.createHTMLDocument(); | ||
// Rely on this method's TrustedTypes implementation, if available | ||
const parsed = parser.parseFromString(input, 'text/html'); | ||
doc.head.append(...parsed.head.childNodes); | ||
doc.body.append(...parsed.body.childNodes); | ||
doc.querySelectorAll('template[shadowrootmode]').forEach(attachShadow); | ||
return doc; | ||
} | ||
|
||
export function setHTMLUnsafe(input) { | ||
const parser = new DOMParser(); | ||
// Rely on this method's TrustedTypes implementation, if available | ||
const parsed = parser.parseFromString(input, 'text/html'); | ||
const frag = document.createDocumentFragment(); | ||
frag.append(...parsed.body.childNodes); | ||
attachShadow(frag.querySelector('template[shadowroootmode]')); | ||
this.replaceChildren(frag); | ||
} | ||
|
||
export function getHTML() { | ||
return this.innerHTML; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { polyfillMethod } from './utils.js'; | ||
|
||
polyfillMethod(Request.prototype, 'bytes', async function () { | ||
return new Uint8Array(await this.arrayBuffer()); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters