]>
Lady’s Gitweb - Lemon/blob - window/mod.js
1 // 🍋🏷 Lemon ∷ window/mod.js
2 // ====================================================================
4 // Copyright © 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/>.
17 { // Polyfill global interfaces.
18 Object
.assign(globalThis
, {
25 { // Polyfill document.
26 globalThis
.document
= new DOMImplementation().createDocument(
31 const { documentElement
} = document
;
32 documentElement
.appendChild(
33 document
.createElementNS(xhtmlNamespace
, "head"),
35 documentElement
.appendChild(
36 document
.createElementNS(xhtmlNamespace
, "body"),
40 { // Polyfill Element::append.
41 Object
.getPrototypeOf(
42 globalThis
.document
.documentElement
,
43 ).append = function (...children
) {
44 for (const child
of children
) {
46 typeof child
=== "string"
47 ? this.ownerDocument
.createTextNode(child
)
54 { // Apply patches to Node::nodeType and Node::normalize.
55 const nodePrototype
= Object
.getPrototypeOf(
56 Object
.getPrototypeOf(document
.createDocumentFragment()),
58 const originalNodeTypeGetter
= Object
.getOwnPropertyDescriptor(
62 const { nodeType
: originalNodeTypeValue
} = nodePrototype
;
63 return () => originalNodeTypeValue
;
65 Object
.defineProperty(nodePrototype
, "nodeType", {
69 * To simulate restrictions on calling `nodeType` only on actual
70 * Nodes, check for inheritance first.
75 // Test whether this object has the node prototype in its
78 let prototype = this === Object(this)
79 ? Object
.getPrototypeOf(this)
82 prototype = Object
.getPrototypeOf(prototype)
84 if (prototype === nodePrototype
) {
85 // This object inherits from the Node prototype.
88 // This object is not yet known to inherits from the Node
95 // This is not a Node.
96 throw new TypeError("nodeType requires this be a Node.");
98 // This is a Node; walk the prototype chain and attempt to get
101 //deno-lint-ignore no-this-alias
103 target
!= null && target
!= nodePrototype
;
104 target
= Object
.getPrototypeOf(target
)
106 if (Object
.hasOwn(target
, "nodeType")) {
107 return Reflect
.get(target
, "nodeType", this);
112 return originalNodeTypeGetter
.call(this);
117 nodePrototype
.normalize = function () {
118 let child
= this.firstChild
;
120 const next
= child
.nextSibling
;
121 if (next
&& next
.nodeType
== 3 && child
.nodeType
== 3) {
122 this.removeChild(next
);
123 child
.appendData(next
.data
);
125 if (child
.nodeType
== 3 && !child
.data
) {
126 this.removeChild(child
);
This page took 0.182714 seconds and 5 git commands to generate.