]>
Lady’s Gitweb - Lemon/blob - dev-deps.js
9a670e71dfd578ae2ea8a7cc52e24b7154ae252c
1 // 🍋🏷 Lemon ∷ dev-deps.js
2 // ====================================================================
4 // Copyright © 2021–2022 Lady [@ Lady’s Computer].
6 // This Source Code Form is subject to the terms of the Mozilla Public
7 // License, v. 2.0. If a copy of the MPL was not distributed with this
8 // file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
10 import { xhtmlNamespace
} from "./names.js";
14 } from "https://esm.sh/@xmldom/xmldom@0.8.2/lib/dom.js";
16 { // Polyfill document.
17 globalThis
.document
= new DOMImplementation().createDocument(
24 { // Polyfill `element.append()`.
25 Object
.getPrototypeOf(
26 globalThis
.document
.documentElement
,
27 ).append = function (...children
) {
28 for (const child
of children
) {
30 typeof child
=== "string"
31 ? this.ownerDocument
.createTextNode(child
)
38 { // Polyfill `Node` and apply patches to `Node.nodeType` and
40 globalThis
.Node
= Node
;
41 const originalNodeTypeGetter
= Object
.getOwnPropertyDescriptor(
45 const originalNodeTypeValue
= Node
.prototype.nodeType
;
46 return () => originalNodeTypeValue
;
48 Object
.defineProperty(Node
.prototype, "nodeType", {
52 * To simulate restrictions on calling `nodeType` only on actual
53 * Nodes, check for inheritance first.
56 if (!(this instanceof Node
)) {
57 // This is not a Node.
58 throw new TypeError("nodeType requires this be a Node.");
60 // This is a Node; walk the prototype chain and attempt to get
63 //deno-lint-ignore no-this-alias
65 target
!= null && target
!= Node
.prototype;
66 target
= Object
.getPrototypeOf(target
)
68 if (Object
.hasOwn(target
, "nodeType")) {
69 return Reflect
.get(target
, "nodeType", this);
74 return originalNodeTypeGetter
.call(this);
79 Node
.prototype.normalize = function () { // modified from xmldom
80 let child
= this.firstChild
;
82 const next
= child
.nextSibling
;
84 next
&& next
.nodeType
== Node
.TEXT_NODE
&&
85 child
.nodeType
== Node
.TEXT_NODE
87 this.removeChild(next
);
88 child
.appendData(next
.data
);
90 if (child
.nodeType
== Node
.TEXT_NODE
&& !child
.data
) {
91 this.removeChild(child
);
101 export { assertStrictEquals
} from "https://deno.land/std@0.134.0/testing/asserts.ts";
This page took 0.093486 seconds and 3 git commands to generate.