]>
Lady’s Gitweb - Lemon/blob - window/mod.js
5e97d4f2af8e289dc45496f943192f12056db703
   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/>. 
  10 import { DOMImplementation
, Node
, xhtmlNamespace 
} from "./deps.js"; 
  12 { // Polyfill document. 
  13   globalThis
.document 
= new DOMImplementation().createDocument( 
  18   const { documentElement 
} = document
; 
  19   documentElement
.appendChild( 
  20     document
.createElementNS(xhtmlNamespace
, "head"), 
  22   documentElement
.appendChild( 
  23     document
.createElementNS(xhtmlNamespace
, "body"), 
  27 { // Polyfill `element.append`. 
  28   Object
.getPrototypeOf( 
  29     globalThis
.document
.documentElement
, 
  30   ).append = function (...children
) { 
  31     for (const child 
of children
) { 
  33         typeof child 
=== "string" 
  34           ? this.ownerDocument
.createTextNode(child
) 
  41 { // Apply patches to `Node.nodeType` and `Node.normalize`. 
  42   const { TEXT_NODE
, prototype: nodePrototype 
} = Node
; 
  43   const originalNodeTypeGetter 
= Object
.getOwnPropertyDescriptor( 
  47     const originalNodeTypeValue 
= nodePrototype
.nodeType
; 
  48     return () => originalNodeTypeValue
; 
  50   Object
.defineProperty(nodePrototype
, "nodeType", { 
  54      * To simulate restrictions on calling `nodeType` only on actual 
  55      * Nodes, check for inheritance first. 
  58       if (!(this instanceof Node
)) { 
  59         // This is not a Node. 
  60         throw new TypeError("nodeType requires this be a Node."); 
  62         // This is a Node; walk the prototype chain and attempt to get 
  65           //deno-lint-ignore no-this-alias 
  67           target 
!= null && target 
!= nodePrototype
; 
  68           target 
= Object
.getPrototypeOf(target
) 
  70           if (Object
.hasOwn(target
, "nodeType")) { 
  71             return Reflect
.get(target
, "nodeType", this); 
  76         return originalNodeTypeGetter
.call(this); 
  81   nodePrototype
.normalize = function () { 
  82     let child 
= this.firstChild
; 
  84       const next 
= child
.nextSibling
; 
  86         next 
&& next
.nodeType 
== TEXT_NODE 
&& 
  87         child
.nodeType 
== TEXT_NODE
 
  89         this.removeChild(next
); 
  90         child
.appendData(next
.data
); 
  92         if (child
.nodeType 
== TEXT_NODE 
&& !child
.data
) { 
  93           this.removeChild(child
); 
 
This page took 0.139883 seconds  and 3 git commands  to generate.