X-Git-Url: https://git.ladys.computer/Lemon/blobdiff_plain/0bcf6926ddc22baf9ba097bf644c908ffcf12c3f..3f0fb84f4cb391464680ba600592df3b811e44a8:/dev-deps.js?ds=sidebyside diff --git a/dev-deps.js b/dev-deps.js index 9a670e7..3382019 100644 --- a/dev-deps.js +++ b/dev-deps.js @@ -7,95 +7,11 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at . -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, - ); -} +export { DOMImplementation } from "./window/deps.js"; -{ // 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 { assertStrictEquals } from "https://deno.land/std@0.134.0/testing/asserts.ts"; +export { + assertEquals, + assertStrictEquals, +} from "https://deno.land/std@0.134.0/testing/asserts.ts";