]> Lady’s Gitweb - Lemon/blobdiff - dev-deps.js
Allow document specification and binding
[Lemon] / dev-deps.js
index 9a670e71dfd578ae2ea8a7cc52e24b7154ae252c..95bf219777ebc6682b91dc4e693d5608646b734c 100644 (file)
@@ -7,95 +7,8 @@
 // License, v. 2.0. If a copy of the MPL was not distributed with this
 // file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
 
-import { xhtmlNamespace } from "./names.js";
-import {
-  DOMImplementation,
-  Node,
-} from "https://esm.sh/@xmldom/xmldom@0.8.2/lib/dom.js";
+import "./window/mod.js";
 
-{ // Polyfill document.
-  globalThis.document = new DOMImplementation().createDocument(
-    xhtmlNamespace,
-    "html",
-    null,
-  );
-}
-
-{ // Polyfill `element.append()`.
-  Object.getPrototypeOf(
-    globalThis.document.documentElement,
-  ).append = function (...children) {
-    for (const child of children) {
-      this.appendChild(
-        typeof child === "string"
-          ? this.ownerDocument.createTextNode(child)
-          : child,
-      );
-    }
-  };
-}
-
-{ // Polyfill `Node` and apply patches to `Node.nodeType` and
-  // `Node.normalize`.
-  globalThis.Node = Node;
-  const originalNodeTypeGetter = Object.getOwnPropertyDescriptor(
-    Node.prototype,
-    "nodeType",
-  )?.get ?? (() => {
-    const originalNodeTypeValue = Node.prototype.nodeType;
-    return () => originalNodeTypeValue;
-  })();
-  Object.defineProperty(Node.prototype, "nodeType", {
-    configurable: true,
-    enumerable: true,
-    /**
-     * To simulate restrictions on calling `nodeType` only on actual
-     * Nodes, check for inheritance first.
-     */
-    get() {
-      if (!(this instanceof Node)) {
-        // This is not a Node.
-        throw new TypeError("nodeType requires this be a Node.");
-      } else {
-        // This is a Node; walk the prototype chain and attempt to get
-        // the node type.
-        for (
-          //deno-lint-ignore no-this-alias
-          let target = this;
-          target != null && target != Node.prototype;
-          target = Object.getPrototypeOf(target)
-        ) {
-          if (Object.hasOwn(target, "nodeType")) {
-            return Reflect.get(target, "nodeType", this);
-          } else {
-            continue;
-          }
-        }
-        return originalNodeTypeGetter.call(this);
-      }
-    },
-    set: undefined,
-  });
-  Node.prototype.normalize = function () { // modified from xmldom
-    let child = this.firstChild;
-    while (child) {
-      const next = child.nextSibling;
-      if (
-        next && next.nodeType == Node.TEXT_NODE &&
-        child.nodeType == Node.TEXT_NODE
-      ) {
-        this.removeChild(next);
-        child.appendData(next.data);
-      } else {
-        if (child.nodeType == Node.TEXT_NODE && !child.data) {
-          this.removeChild(child);
-        } else {
-          child.normalize();
-        }
-        child = next;
-      }
-    }
-  };
-}
+export { DOMImplementation } from "./window/deps.js";
 
 export { assertStrictEquals } from "https://deno.land/std@0.134.0/testing/asserts.ts";
This page took 0.054833 seconds and 4 git commands to generate.