Comparing version 0.1.4 to 0.1.5
@@ -8,3 +8,6 @@ 'use strict'; | ||
class Attribute extends Node { | ||
/** | ||
* @implements globalThis.Attr | ||
*/ | ||
class Attr extends Node { | ||
@@ -15,2 +18,6 @@ constructor(ownerDocument, name, value) { | ||
this.value = String(value); | ||
/** | ||
* @type {HTMLElement?} | ||
*/ | ||
this.ownerElement = null; | ||
@@ -23,2 +30,2 @@ } | ||
} | ||
exports.Attribute = Attribute | ||
exports.Attr = Attr |
@@ -7,2 +7,5 @@ 'use strict'; | ||
/** | ||
* @implements globalThis.Comment | ||
*/ | ||
class Comment extends NodeText { | ||
@@ -9,0 +12,0 @@ |
@@ -8,9 +8,12 @@ 'use strict'; | ||
const {Attribute} = require('./attribute.js'); | ||
const {Attr} = require('./attribute.js'); | ||
const {Comment} = require('./comment.js'); | ||
const {Element} = require('./element.js'); | ||
const {Fragment} = require('./fragment.js'); | ||
const {DocumentFragment} = require('./fragment.js'); | ||
const {Node} = require('./node.js'); | ||
const {Text} = require('./text.js'); | ||
/** | ||
* @implements globalThis.Document | ||
*/ | ||
class Document extends Node { | ||
@@ -21,2 +24,6 @@ | ||
this._mime = Mime[type]; | ||
/** | ||
* @type {HTMLElement?} | ||
*/ | ||
this.root = null; | ||
@@ -74,3 +81,3 @@ } | ||
createAttribute(name) { | ||
return new Attribute(this, name, ''); | ||
return new Attr(this, name, ''); | ||
} | ||
@@ -94,3 +101,3 @@ | ||
createDocumentFragment() { | ||
return new Fragment(this); | ||
return new DocumentFragment(this); | ||
} | ||
@@ -102,2 +109,6 @@ | ||
/** | ||
* @param {string} name | ||
* @returns {NodeList} | ||
*/ | ||
getElementsByTagName(name) { | ||
@@ -108,2 +119,8 @@ const {root} = this; | ||
/** | ||
* @deprecated | ||
* @param {string} namespace | ||
* @param {string} className | ||
* @returns {NodeList} | ||
*/ | ||
getElementsByTagNameNS(_, name) { | ||
@@ -113,2 +130,6 @@ return this.getElementsByTagName(name); | ||
/** | ||
* @param {string} className | ||
* @returns {NodeList} | ||
*/ | ||
getElementsByClassName(className) { | ||
@@ -115,0 +136,0 @@ const {root} = this; |
@@ -7,3 +7,11 @@ 'use strict'; | ||
/** | ||
* @implements globalThis.DOMParser | ||
*/ | ||
module.exports = class DOMParser { | ||
/** | ||
* @param {string} markupLanguage | ||
* @param {string} mimeType | ||
* @returns {Document} | ||
*/ | ||
parseFromString(markupLanguage, mimeType) { | ||
@@ -10,0 +18,0 @@ let isHTML = false, document; |
@@ -37,8 +37,16 @@ 'use strict'; | ||
function DOMStringMap(value) {'use strict'; | ||
return new Proxy( | ||
defineProperty(this, '_', {value}), | ||
handler | ||
); | ||
/** | ||
* @implements globalThis.DOMStringMap | ||
*/ | ||
class DOMStringMap { | ||
/** | ||
* @param {Element} value | ||
*/ | ||
constructor(value) { | ||
return new Proxy( | ||
defineProperty(this, '_', {value}), | ||
handler | ||
); | ||
} | ||
} | ||
exports.DOMStringMap = DOMStringMap |
@@ -6,2 +6,5 @@ 'use strict'; | ||
/** | ||
* @implements globalThis.DOMTokenList | ||
*/ | ||
class DOMTokenList extends Set { | ||
@@ -18,2 +21,5 @@ | ||
/** | ||
* @param {...string} tokens | ||
*/ | ||
add(...tokens) { | ||
@@ -27,2 +33,5 @@ for (const token of tokens) { | ||
/** | ||
* @param {string} token | ||
*/ | ||
contains(token) { | ||
@@ -32,2 +41,5 @@ return this.has(token); | ||
/** | ||
* @param {...string} tokens | ||
*/ | ||
remove(...tokens) { | ||
@@ -39,2 +51,6 @@ for (const token of tokens) | ||
/** | ||
* @param {string} token | ||
* @param {boolean?} force | ||
*/ | ||
toggle(token, force) { | ||
@@ -55,2 +71,6 @@ if (this.has(token)) { | ||
/** | ||
* @param {string} token | ||
* @param {string} newToken | ||
*/ | ||
replace(token, newToken) { | ||
@@ -66,2 +86,5 @@ if (this.has(token)) { | ||
/** | ||
* @param {string} token | ||
*/ | ||
supports(token) { | ||
@@ -71,2 +94,2 @@ return true; | ||
} | ||
exports.DOMTokenList = DOMTokenList; | ||
exports.DOMTokenList = DOMTokenList |
@@ -20,2 +20,5 @@ 'use strict'; | ||
/** | ||
* @implements globalThis.Element | ||
*/ | ||
class Element extends NodeElement { | ||
@@ -47,2 +50,5 @@ | ||
/** | ||
* @param {...Node|string} nodes | ||
*/ | ||
prepend(...nodes) { | ||
@@ -52,2 +58,5 @@ return ParentNode.prepend(this, ...nodes); | ||
/** | ||
* @param {...Node|string} nodes | ||
*/ | ||
append(...nodes) { | ||
@@ -57,2 +66,5 @@ return ParentNode.append(this, ...nodes); | ||
/** | ||
* @param {...Node|string} nodes | ||
*/ | ||
replaceChildren(...nodes) { | ||
@@ -81,2 +93,5 @@ return ParentNode.replaceChildren(this, ...nodes); | ||
/** | ||
* @type {string} | ||
*/ | ||
get nodeName() { | ||
@@ -86,2 +101,5 @@ return localCase(this); | ||
/** | ||
* @type {string} | ||
*/ | ||
get tagName() { | ||
@@ -91,2 +109,5 @@ return localCase(this); | ||
/** | ||
* @type {DOMTokenList} | ||
*/ | ||
get classList() { | ||
@@ -96,2 +117,5 @@ return this._classList || (this._classList = new DOMTokenList(this)); | ||
/** | ||
* @type {DOMStringMap} | ||
*/ | ||
get dataset() { | ||
@@ -121,2 +145,5 @@ return this._dataset || (this._dataset = new DOMStringMap(this)); | ||
/** | ||
* @type {Attr[]} | ||
*/ | ||
get attributes() { | ||
@@ -132,2 +159,5 @@ const attributes = []; | ||
/** | ||
* @type {Node?} | ||
*/ | ||
get nextSibling() { | ||
@@ -137,2 +167,5 @@ return this._end._next; | ||
/** | ||
* @type {Node?} | ||
*/ | ||
get previousSibling() { | ||
@@ -142,2 +175,5 @@ return this._prev; | ||
/** | ||
* @type {Element?} | ||
*/ | ||
get nextElementSibling() { | ||
@@ -147,2 +183,5 @@ return NonDocumentTypeChildNode.nextElementSibling(this._end); | ||
/** | ||
* @type {Element?} | ||
*/ | ||
get previousElementSibling() { | ||
@@ -152,2 +191,6 @@ return NonDocumentTypeChildNode.previousElementSibling(this); | ||
/** | ||
* @param {string} name | ||
* @returns {Attr?} | ||
*/ | ||
getAttributeNode(name) { | ||
@@ -163,2 +206,5 @@ let {_next} = this; | ||
/** | ||
* @param {Attr} attribute | ||
*/ | ||
removeAttributeNode(attribute) { | ||
@@ -179,2 +225,5 @@ let {_next} = this; | ||
/** | ||
* @param {Attr} attribute | ||
*/ | ||
setAttributeNode(attribute) { | ||
@@ -197,2 +246,5 @@ const previously = this.getAttributeNode(attribute.name); | ||
/** | ||
* @param {string} name | ||
*/ | ||
hasAttribute(name) { | ||
@@ -202,2 +254,7 @@ return !!this.getAttributeNode(name); | ||
/** | ||
* @deprecated | ||
* @param {string} namespace | ||
* @param {string} name | ||
*/ | ||
hasAttributeNS(_, name) { | ||
@@ -215,2 +272,6 @@ return this.hasAttribute(name); | ||
/** | ||
* @param {string} name | ||
* @returns {string?} | ||
*/ | ||
getAttribute(name) { | ||
@@ -221,2 +282,8 @@ const attribute = this.getAttributeNode(name); | ||
/** | ||
* @deprecated | ||
* @param {string} namespace | ||
* @param {string} name | ||
* @returns {string?} | ||
*/ | ||
getAttributeNS(_, name) { | ||
@@ -226,2 +293,5 @@ return this.getAttribute(name); | ||
/** | ||
* @param {string} name | ||
*/ | ||
removeAttribute(name) { | ||
@@ -238,2 +308,7 @@ let {_next} = this; | ||
/** | ||
* @deprecated | ||
* @param {string} namespace | ||
* @param {string} name | ||
*/ | ||
removeAttributeNS(_, name) { | ||
@@ -243,2 +318,6 @@ this.removeAttribute(name); | ||
/** | ||
* @param {string} name | ||
* @param {string|any} value casted, if not string | ||
*/ | ||
setAttribute(name, value) { | ||
@@ -255,2 +334,8 @@ let attribute = this.getAttributeNode(name); | ||
/** | ||
* @deprecated | ||
* @param {string} namespace | ||
* @param {string} name | ||
* @param {string|any} value casted, if not string | ||
*/ | ||
setAttributeNS(_, name, value) { | ||
@@ -260,2 +345,6 @@ this.setAttribute(name, value); | ||
/** | ||
* @param {string} name | ||
* @param {boolean?} force | ||
*/ | ||
toggleAttribute(name, force) { | ||
@@ -308,2 +397,5 @@ if (this.hasAttribute(name)) { | ||
/** | ||
* @param {string} name | ||
*/ | ||
getElementsByTagName(name) { | ||
@@ -322,2 +414,7 @@ const elements = new NodeList; | ||
/** | ||
* @deprecated | ||
* @param {string} namespace | ||
* @param {string} name | ||
*/ | ||
getElementsByTagNameNS(_, name) { | ||
@@ -327,2 +424,5 @@ return this.getElementsByTagName(name); | ||
/** | ||
* @param {string} className | ||
*/ | ||
getElementsByClassName(className) { | ||
@@ -343,2 +443,6 @@ const elements = new NodeList; | ||
/** | ||
* @param {string} selectors | ||
* @returns {boolean} | ||
*/ | ||
matches(selectors) { | ||
@@ -345,0 +449,0 @@ return matches(this, selectors); |
@@ -6,3 +6,6 @@ 'use strict'; | ||
class Fragment extends NodeElement { | ||
/** | ||
* @implements globalThis.DocumentFragment | ||
*/ | ||
class DocumentFragment extends NodeElement { | ||
@@ -15,2 +18,6 @@ constructor(ownerDocument) { | ||
// <NonElementParentNode> | ||
/** | ||
* @param {string} id | ||
* @returns {Element?} | ||
*/ | ||
getElementById(id) { | ||
@@ -28,2 +35,5 @@ return this.children.find( | ||
/** | ||
* @returns {Element?} | ||
*/ | ||
get firstElementChild() { | ||
@@ -33,2 +43,5 @@ return ParentNode.firstElementChild(this); | ||
/** | ||
* @returns {Element?} | ||
*/ | ||
get lastElementChild() { | ||
@@ -38,2 +51,5 @@ return ParentNode.lastElementChild(this); | ||
/** | ||
* @returns {number} | ||
*/ | ||
get childElementCount() { | ||
@@ -43,2 +59,5 @@ return ParentNode.childElementCount(this); | ||
/** | ||
* @param {...Nodes} nodes | ||
*/ | ||
prepend(...nodes) { | ||
@@ -48,2 +67,5 @@ return ParentNode.prepend(this, ...nodes); | ||
/** | ||
* @param {...Nodes} nodes | ||
*/ | ||
append(...nodes) { | ||
@@ -53,2 +75,5 @@ return ParentNode.append(this, ...nodes); | ||
/** | ||
* @param {...Nodes} nodes | ||
*/ | ||
replaceChildren(...nodes) { | ||
@@ -59,2 +84,2 @@ return ParentNode.replaceChildren(this, ...nodes); | ||
} | ||
exports.Fragment = Fragment | ||
exports.DocumentFragment = DocumentFragment |
'use strict'; | ||
const {Document} = require('./document.js'); | ||
/** | ||
* @implements globalThis.HTMLDocument | ||
*/ | ||
class HTMLDocument extends Document { | ||
@@ -12,2 +15,5 @@ | ||
/** | ||
* @type HTMLHtmlElement | ||
*/ | ||
get documentElement() { | ||
@@ -17,2 +23,2 @@ return this.root; | ||
} | ||
exports.HTMLDocument = HTMLDocument; | ||
exports.HTMLDocument = HTMLDocument |
@@ -8,2 +8,5 @@ 'use strict'; | ||
/** | ||
* @implements globalThis.CustomEvent | ||
*/ | ||
class CustomEvent extends Event { | ||
@@ -15,5 +18,7 @@ constructor(type, eventInitDict = {}) { | ||
} | ||
exports.CustomEvent = CustomEvent | ||
// https://dom.spec.whatwg.org/#nodelist | ||
/** | ||
* @implements globalThis.NodeList | ||
*/ | ||
class NodeList extends Array { | ||
@@ -20,0 +25,0 @@ item(i) { |
@@ -24,2 +24,6 @@ 'use strict'; | ||
/** | ||
* @param {Node} node | ||
* @param {...Nodes} nodes | ||
*/ | ||
replaceWith(node, ...nodes) { | ||
@@ -31,2 +35,5 @@ const fragment = node.ownerDocument.createDocumentFragment(); | ||
/** | ||
* @param {Node} node | ||
*/ | ||
remove(node) { | ||
@@ -49,2 +56,6 @@ let {_prev, _next, nodeType} = node; | ||
/** | ||
* @param {Node} node | ||
* @returns {Element?} | ||
*/ | ||
previousElementSibling({_prev}) { | ||
@@ -65,2 +76,6 @@ while (_prev) { | ||
/** | ||
* @param {Node} node | ||
* @returns {Element?} | ||
*/ | ||
nextElementSibling({_next}) { | ||
@@ -84,2 +99,7 @@ while (_next) { | ||
/** | ||
* @param {Node} node | ||
* @param {string} id | ||
* @returns {Element?} | ||
*/ | ||
getElementById({_next}, id) { | ||
@@ -96,2 +116,6 @@ while (_next) { | ||
/** | ||
* @param {Element} element | ||
* @param {...Nodes} nodes | ||
*/ | ||
const append = (element, ...nodes) => { | ||
@@ -109,2 +133,6 @@ const {ownerDocument, _end} = element; | ||
/** | ||
* @param {Element} element | ||
* @returns {NodeList} | ||
*/ | ||
children(element) { | ||
@@ -123,2 +151,6 @@ const children = new NodeList; | ||
/** | ||
* @param {Element} element | ||
* @returns {Element?} | ||
*/ | ||
firstElementChild({_next, _end}) { | ||
@@ -130,2 +162,6 @@ while (_next !== _end && _next.nodeType !== ELEMENT_NODE) | ||
/** | ||
* @param {Element} element | ||
* @returns {Element?} | ||
*/ | ||
lastElementChild({lastChild}) { | ||
@@ -139,2 +175,6 @@ if (lastChild) { | ||
/** | ||
* @param {Element} element | ||
* @returns {number} | ||
*/ | ||
childElementCount({children}) { | ||
@@ -144,2 +184,6 @@ return children.length; | ||
/** | ||
* @param {Element} element | ||
* @param {...Nodes} nodes | ||
*/ | ||
prepend(element, ...nodes) { | ||
@@ -156,2 +200,6 @@ const {ownerDocument, firstChild} = element; | ||
/** | ||
* @param {Element} element | ||
* @param {...Nodes} nodes | ||
*/ | ||
replaceChildren(element, ...nodes) { | ||
@@ -167,2 +215,7 @@ let {_next, _end} = element; | ||
/** | ||
* @param {Element} element | ||
* @param {string} selectors | ||
* @returns {Element?} | ||
*/ | ||
querySelector({_next}, selectors) { | ||
@@ -177,2 +230,7 @@ while (_next) { | ||
/** | ||
* @param {Element} element | ||
* @param {string} selectors | ||
* @returns {NodeList} | ||
*/ | ||
querySelectorAll({_next}, selectors) { | ||
@@ -179,0 +237,0 @@ const elements = new NodeList; |
@@ -23,2 +23,5 @@ 'use strict'; | ||
/** | ||
* @implements globalThis.Node | ||
*/ | ||
class Node extends EventTarget { | ||
@@ -35,5 +38,21 @@ | ||
super(); | ||
/** | ||
* @type {Document} | ||
*/ | ||
this.ownerDocument = ownerDocument; | ||
/** | ||
* @type {string} | ||
*/ | ||
this.localName = localName; | ||
/** | ||
* @type {number} | ||
*/ | ||
this.nodeType = nodeType; | ||
/** | ||
* @type {Element?} | ||
*/ | ||
this.parentNode = null; | ||
@@ -58,2 +77,5 @@ | ||
/** | ||
* @type {Element?} | ||
*/ | ||
get parentElement() { | ||
@@ -72,2 +94,6 @@ let {parentNode} = this; | ||
// it's huge, but it should never suffer a maximum callstack issue | ||
/** | ||
* @param {boolean?} deep | ||
* @returns {Node} | ||
*/ | ||
cloneNode(deep = false) { | ||
@@ -131,2 +157,6 @@ const {ownerDocument, nodeType, localName} = this; | ||
/** | ||
* @type {Node} | ||
* @returns {boolean} | ||
*/ | ||
isEqualNode(node) { | ||
@@ -150,2 +180,5 @@ const {nodeType} = this; | ||
// meh | ||
/** | ||
* @type {Node} | ||
*/ | ||
isSameNode(node) { | ||
@@ -163,2 +196,5 @@ return this === node; | ||
/** | ||
* @type {Node?} | ||
*/ | ||
get firstChild() { | ||
@@ -169,2 +205,5 @@ const {_next, _end} = findNext(this); | ||
/** | ||
* @type {Node?} | ||
*/ | ||
get lastChild() { | ||
@@ -192,2 +231,5 @@ const {_prev} = this._end; | ||
/** | ||
* @returns {Element} | ||
*/ | ||
getRootNode() { | ||
@@ -197,2 +239,6 @@ return this.ownerDocument.root; | ||
/** | ||
* @param {Node} node | ||
* @returns {boolean} | ||
*/ | ||
contains(node) { | ||
@@ -209,2 +255,5 @@ let {parentNode} = node; | ||
/** | ||
* @param {Node} node | ||
*/ | ||
appendChild(node) { | ||
@@ -214,2 +263,7 @@ return this.insertBefore(node, this._end); | ||
/** | ||
* @param {Node} node | ||
* @param {Node?} node | ||
* @returns {Node} | ||
*/ | ||
insertBefore(node, before) { | ||
@@ -269,2 +323,6 @@ const _end = before || this._end; | ||
/** | ||
* @param {Node} node | ||
* @returns {Node} | ||
*/ | ||
removeChild(node) { | ||
@@ -277,2 +335,7 @@ if (node.parentNode !== this) | ||
/** | ||
* @param {Node} node | ||
* @param {Node} replaced | ||
* @returns {Node} | ||
*/ | ||
replaceChild(node, replaced) { | ||
@@ -291,2 +354,6 @@ const {_prev, _next} = getBoundaries(replaced); | ||
/** | ||
* @param {string} selectors | ||
* @returns {Element?} | ||
*/ | ||
querySelector(selectors) { | ||
@@ -296,2 +363,6 @@ return ParentNode.querySelector(this, selectors); | ||
/** | ||
* @param {string} selectors | ||
* @returns {NodeList} | ||
*/ | ||
querySelectorAll(selectors) { | ||
@@ -312,6 +383,20 @@ return ParentNode.querySelectorAll(this, selectors); | ||
/** | ||
* @type {null} | ||
*/ | ||
get firstChild() { return null; } | ||
/** | ||
* @type {null} | ||
*/ | ||
get lastChild() { return null; } | ||
/** | ||
* @type {NodeList} | ||
*/ | ||
get childNodes() { return []; } | ||
/** | ||
* @type {Node?} | ||
*/ | ||
get nextSibling() { | ||
@@ -321,2 +406,5 @@ return this._next; | ||
/** | ||
* @type {Node?} | ||
*/ | ||
get previousSibling() { | ||
@@ -326,2 +414,5 @@ return this._prev; | ||
/** | ||
* @type {Element?} | ||
*/ | ||
get nextElementSibling() { | ||
@@ -331,2 +422,5 @@ return NonDocumentTypeChildNode.nextElementSibling(this); | ||
/** | ||
* @type {Element?} | ||
*/ | ||
get previousElementSibling() { | ||
@@ -333,0 +427,0 @@ return NonDocumentTypeChildNode.previousElementSibling(this); |
'use strict'; | ||
const {Document} = require('./document.js'); | ||
/** | ||
* @implements globalThis.SVGDocument | ||
*/ | ||
class SVGDocument extends Document { | ||
@@ -10,2 +13,2 @@ | ||
} | ||
exports.SVGDocument = SVGDocument; | ||
exports.SVGDocument = SVGDocument |
@@ -7,2 +7,5 @@ 'use strict'; | ||
/** | ||
* @implements globalThis.Text | ||
*/ | ||
class Text extends NodeText { | ||
@@ -9,0 +12,0 @@ |
'use strict'; | ||
const {Document} = require('./document.js'); | ||
/** | ||
* @implements globalThis.XMLDocument | ||
*/ | ||
class XMLDocument extends Document { | ||
@@ -10,2 +13,2 @@ | ||
} | ||
exports.XMLDocument = XMLDocument; | ||
exports.XMLDocument = XMLDocument |
@@ -7,3 +7,6 @@ import {escape} from 'html-escaper'; | ||
export class Attribute extends Node { | ||
/** | ||
* @implements globalThis.Attr | ||
*/ | ||
export class Attr extends Node { | ||
@@ -14,2 +17,6 @@ constructor(ownerDocument, name, value) { | ||
this.value = String(value); | ||
/** | ||
* @type {HTMLElement?} | ||
*/ | ||
this.ownerElement = null; | ||
@@ -16,0 +23,0 @@ } |
@@ -6,2 +6,5 @@ import {escape} from 'html-escaper'; | ||
/** | ||
* @implements globalThis.Comment | ||
*/ | ||
export class Comment extends NodeText { | ||
@@ -8,0 +11,0 @@ |
@@ -7,9 +7,12 @@ import {DOCUMENT_NODE} from './constants.js'; | ||
import {Attribute} from './attribute.js'; | ||
import {Attr} from './attribute.js'; | ||
import {Comment} from './comment.js'; | ||
import {Element} from './element.js'; | ||
import {Fragment} from './fragment.js'; | ||
import {DocumentFragment} from './fragment.js'; | ||
import {Node} from './node.js'; | ||
import {Text} from './text.js'; | ||
/** | ||
* @implements globalThis.Document | ||
*/ | ||
export class Document extends Node { | ||
@@ -20,2 +23,6 @@ | ||
this._mime = Mime[type]; | ||
/** | ||
* @type {HTMLElement?} | ||
*/ | ||
this.root = null; | ||
@@ -73,3 +80,3 @@ } | ||
createAttribute(name) { | ||
return new Attribute(this, name, ''); | ||
return new Attr(this, name, ''); | ||
} | ||
@@ -93,3 +100,3 @@ | ||
createDocumentFragment() { | ||
return new Fragment(this); | ||
return new DocumentFragment(this); | ||
} | ||
@@ -101,2 +108,6 @@ | ||
/** | ||
* @param {string} name | ||
* @returns {NodeList} | ||
*/ | ||
getElementsByTagName(name) { | ||
@@ -107,2 +118,8 @@ const {root} = this; | ||
/** | ||
* @deprecated | ||
* @param {string} namespace | ||
* @param {string} className | ||
* @returns {NodeList} | ||
*/ | ||
getElementsByTagNameNS(_, name) { | ||
@@ -112,2 +129,6 @@ return this.getElementsByTagName(name); | ||
/** | ||
* @param {string} className | ||
* @returns {NodeList} | ||
*/ | ||
getElementsByClassName(className) { | ||
@@ -114,0 +135,0 @@ const {root} = this; |
@@ -6,3 +6,11 @@ import {parseFromString} from './utils.js'; | ||
/** | ||
* @implements globalThis.DOMParser | ||
*/ | ||
export default class DOMParser { | ||
/** | ||
* @param {string} markupLanguage | ||
* @param {string} mimeType | ||
* @returns {Document} | ||
*/ | ||
parseFromString(markupLanguage, mimeType) { | ||
@@ -9,0 +17,0 @@ let isHTML = false, document; |
@@ -36,7 +36,15 @@ import uhyphen from 'uhyphen'; | ||
export function DOMStringMap(value) {'use strict'; | ||
return new Proxy( | ||
defineProperty(this, '_', {value}), | ||
handler | ||
); | ||
/** | ||
* @implements globalThis.DOMStringMap | ||
*/ | ||
export class DOMStringMap { | ||
/** | ||
* @param {Element} value | ||
*/ | ||
constructor(value) { | ||
return new Proxy( | ||
defineProperty(this, '_', {value}), | ||
handler | ||
); | ||
} | ||
} |
@@ -5,2 +5,5 @@ const update = ({_ownerElement, value}) => { | ||
/** | ||
* @implements globalThis.DOMTokenList | ||
*/ | ||
export class DOMTokenList extends Set { | ||
@@ -17,2 +20,5 @@ | ||
/** | ||
* @param {...string} tokens | ||
*/ | ||
add(...tokens) { | ||
@@ -26,2 +32,5 @@ for (const token of tokens) { | ||
/** | ||
* @param {string} token | ||
*/ | ||
contains(token) { | ||
@@ -31,2 +40,5 @@ return this.has(token); | ||
/** | ||
* @param {...string} tokens | ||
*/ | ||
remove(...tokens) { | ||
@@ -38,2 +50,6 @@ for (const token of tokens) | ||
/** | ||
* @param {string} token | ||
* @param {boolean?} force | ||
*/ | ||
toggle(token, force) { | ||
@@ -54,2 +70,6 @@ if (this.has(token)) { | ||
/** | ||
* @param {string} token | ||
* @param {string} newToken | ||
*/ | ||
replace(token, newToken) { | ||
@@ -65,5 +85,8 @@ if (this.has(token)) { | ||
/** | ||
* @param {string} token | ||
*/ | ||
supports(token) { | ||
return true; | ||
} | ||
}; | ||
} |
@@ -19,2 +19,5 @@ import {ELEMENT_NODE, ELEMENT_NODE_END, ATTRIBUTE_NODE, TEXT_NODE, COMMENT_NODE} from './constants.js'; | ||
/** | ||
* @implements globalThis.Element | ||
*/ | ||
export class Element extends NodeElement { | ||
@@ -46,2 +49,5 @@ | ||
/** | ||
* @param {...Node|string} nodes | ||
*/ | ||
prepend(...nodes) { | ||
@@ -51,2 +57,5 @@ return ParentNode.prepend(this, ...nodes); | ||
/** | ||
* @param {...Node|string} nodes | ||
*/ | ||
append(...nodes) { | ||
@@ -56,2 +65,5 @@ return ParentNode.append(this, ...nodes); | ||
/** | ||
* @param {...Node|string} nodes | ||
*/ | ||
replaceChildren(...nodes) { | ||
@@ -80,2 +92,5 @@ return ParentNode.replaceChildren(this, ...nodes); | ||
/** | ||
* @type {string} | ||
*/ | ||
get nodeName() { | ||
@@ -85,2 +100,5 @@ return localCase(this); | ||
/** | ||
* @type {string} | ||
*/ | ||
get tagName() { | ||
@@ -90,2 +108,5 @@ return localCase(this); | ||
/** | ||
* @type {DOMTokenList} | ||
*/ | ||
get classList() { | ||
@@ -95,2 +116,5 @@ return this._classList || (this._classList = new DOMTokenList(this)); | ||
/** | ||
* @type {DOMStringMap} | ||
*/ | ||
get dataset() { | ||
@@ -120,2 +144,5 @@ return this._dataset || (this._dataset = new DOMStringMap(this)); | ||
/** | ||
* @type {Attr[]} | ||
*/ | ||
get attributes() { | ||
@@ -131,2 +158,5 @@ const attributes = []; | ||
/** | ||
* @type {Node?} | ||
*/ | ||
get nextSibling() { | ||
@@ -136,2 +166,5 @@ return this._end._next; | ||
/** | ||
* @type {Node?} | ||
*/ | ||
get previousSibling() { | ||
@@ -141,2 +174,5 @@ return this._prev; | ||
/** | ||
* @type {Element?} | ||
*/ | ||
get nextElementSibling() { | ||
@@ -146,2 +182,5 @@ return NonDocumentTypeChildNode.nextElementSibling(this._end); | ||
/** | ||
* @type {Element?} | ||
*/ | ||
get previousElementSibling() { | ||
@@ -151,2 +190,6 @@ return NonDocumentTypeChildNode.previousElementSibling(this); | ||
/** | ||
* @param {string} name | ||
* @returns {Attr?} | ||
*/ | ||
getAttributeNode(name) { | ||
@@ -162,2 +205,5 @@ let {_next} = this; | ||
/** | ||
* @param {Attr} attribute | ||
*/ | ||
removeAttributeNode(attribute) { | ||
@@ -178,2 +224,5 @@ let {_next} = this; | ||
/** | ||
* @param {Attr} attribute | ||
*/ | ||
setAttributeNode(attribute) { | ||
@@ -196,2 +245,5 @@ const previously = this.getAttributeNode(attribute.name); | ||
/** | ||
* @param {string} name | ||
*/ | ||
hasAttribute(name) { | ||
@@ -201,2 +253,7 @@ return !!this.getAttributeNode(name); | ||
/** | ||
* @deprecated | ||
* @param {string} namespace | ||
* @param {string} name | ||
*/ | ||
hasAttributeNS(_, name) { | ||
@@ -214,2 +271,6 @@ return this.hasAttribute(name); | ||
/** | ||
* @param {string} name | ||
* @returns {string?} | ||
*/ | ||
getAttribute(name) { | ||
@@ -220,2 +281,8 @@ const attribute = this.getAttributeNode(name); | ||
/** | ||
* @deprecated | ||
* @param {string} namespace | ||
* @param {string} name | ||
* @returns {string?} | ||
*/ | ||
getAttributeNS(_, name) { | ||
@@ -225,2 +292,5 @@ return this.getAttribute(name); | ||
/** | ||
* @param {string} name | ||
*/ | ||
removeAttribute(name) { | ||
@@ -237,2 +307,7 @@ let {_next} = this; | ||
/** | ||
* @deprecated | ||
* @param {string} namespace | ||
* @param {string} name | ||
*/ | ||
removeAttributeNS(_, name) { | ||
@@ -242,2 +317,6 @@ this.removeAttribute(name); | ||
/** | ||
* @param {string} name | ||
* @param {string|any} value casted, if not string | ||
*/ | ||
setAttribute(name, value) { | ||
@@ -254,2 +333,8 @@ let attribute = this.getAttributeNode(name); | ||
/** | ||
* @deprecated | ||
* @param {string} namespace | ||
* @param {string} name | ||
* @param {string|any} value casted, if not string | ||
*/ | ||
setAttributeNS(_, name, value) { | ||
@@ -259,2 +344,6 @@ this.setAttribute(name, value); | ||
/** | ||
* @param {string} name | ||
* @param {boolean?} force | ||
*/ | ||
toggleAttribute(name, force) { | ||
@@ -307,2 +396,5 @@ if (this.hasAttribute(name)) { | ||
/** | ||
* @param {string} name | ||
*/ | ||
getElementsByTagName(name) { | ||
@@ -321,2 +413,7 @@ const elements = new NodeList; | ||
/** | ||
* @deprecated | ||
* @param {string} namespace | ||
* @param {string} name | ||
*/ | ||
getElementsByTagNameNS(_, name) { | ||
@@ -326,2 +423,5 @@ return this.getElementsByTagName(name); | ||
/** | ||
* @param {string} className | ||
*/ | ||
getElementsByClassName(className) { | ||
@@ -342,2 +442,6 @@ const elements = new NodeList; | ||
/** | ||
* @param {string} selectors | ||
* @returns {boolean} | ||
*/ | ||
matches(selectors) { | ||
@@ -344,0 +448,0 @@ return matches(this, selectors); |
@@ -5,3 +5,6 @@ import {DOCUMENT_FRAGMENT_NODE} from './constants.js'; | ||
export class Fragment extends NodeElement { | ||
/** | ||
* @implements globalThis.DocumentFragment | ||
*/ | ||
export class DocumentFragment extends NodeElement { | ||
@@ -14,2 +17,6 @@ constructor(ownerDocument) { | ||
// <NonElementParentNode> | ||
/** | ||
* @param {string} id | ||
* @returns {Element?} | ||
*/ | ||
getElementById(id) { | ||
@@ -27,2 +34,5 @@ return this.children.find( | ||
/** | ||
* @returns {Element?} | ||
*/ | ||
get firstElementChild() { | ||
@@ -32,2 +42,5 @@ return ParentNode.firstElementChild(this); | ||
/** | ||
* @returns {Element?} | ||
*/ | ||
get lastElementChild() { | ||
@@ -37,2 +50,5 @@ return ParentNode.lastElementChild(this); | ||
/** | ||
* @returns {number} | ||
*/ | ||
get childElementCount() { | ||
@@ -42,2 +58,5 @@ return ParentNode.childElementCount(this); | ||
/** | ||
* @param {...Nodes} nodes | ||
*/ | ||
prepend(...nodes) { | ||
@@ -47,2 +66,5 @@ return ParentNode.prepend(this, ...nodes); | ||
/** | ||
* @param {...Nodes} nodes | ||
*/ | ||
append(...nodes) { | ||
@@ -52,2 +74,5 @@ return ParentNode.append(this, ...nodes); | ||
/** | ||
* @param {...Nodes} nodes | ||
*/ | ||
replaceChildren(...nodes) { | ||
@@ -57,2 +82,2 @@ return ParentNode.replaceChildren(this, ...nodes); | ||
// </ParentNode> | ||
} | ||
} |
import {Document} from './document.js'; | ||
/** | ||
* @implements globalThis.HTMLDocument | ||
*/ | ||
export class HTMLDocument extends Document { | ||
@@ -11,5 +14,8 @@ | ||
/** | ||
* @type HTMLHtmlElement | ||
*/ | ||
get documentElement() { | ||
return this.root; | ||
} | ||
}; | ||
} |
@@ -6,3 +6,6 @@ import Event from '@ungap/event'; | ||
export class CustomEvent extends Event { | ||
/** | ||
* @implements globalThis.CustomEvent | ||
*/ | ||
class CustomEvent extends Event { | ||
constructor(type, eventInitDict = {}) { | ||
@@ -15,2 +18,5 @@ super(type, eventInitDict); | ||
// https://dom.spec.whatwg.org/#nodelist | ||
/** | ||
* @implements globalThis.NodeList | ||
*/ | ||
export class NodeList extends Array { | ||
@@ -17,0 +23,0 @@ item(i) { |
@@ -23,2 +23,6 @@ import { | ||
/** | ||
* @param {Node} node | ||
* @param {...Nodes} nodes | ||
*/ | ||
replaceWith(node, ...nodes) { | ||
@@ -30,2 +34,5 @@ const fragment = node.ownerDocument.createDocumentFragment(); | ||
/** | ||
* @param {Node} node | ||
*/ | ||
remove(node) { | ||
@@ -47,2 +54,6 @@ let {_prev, _next, nodeType} = node; | ||
/** | ||
* @param {Node} node | ||
* @returns {Element?} | ||
*/ | ||
previousElementSibling({_prev}) { | ||
@@ -63,2 +74,6 @@ while (_prev) { | ||
/** | ||
* @param {Node} node | ||
* @returns {Element?} | ||
*/ | ||
nextElementSibling({_next}) { | ||
@@ -81,2 +96,7 @@ while (_next) { | ||
/** | ||
* @param {Node} node | ||
* @param {string} id | ||
* @returns {Element?} | ||
*/ | ||
getElementById({_next}, id) { | ||
@@ -92,2 +112,6 @@ while (_next) { | ||
/** | ||
* @param {Element} element | ||
* @param {...Nodes} nodes | ||
*/ | ||
const append = (element, ...nodes) => { | ||
@@ -105,2 +129,6 @@ const {ownerDocument, _end} = element; | ||
/** | ||
* @param {Element} element | ||
* @returns {NodeList} | ||
*/ | ||
children(element) { | ||
@@ -119,2 +147,6 @@ const children = new NodeList; | ||
/** | ||
* @param {Element} element | ||
* @returns {Element?} | ||
*/ | ||
firstElementChild({_next, _end}) { | ||
@@ -126,2 +158,6 @@ while (_next !== _end && _next.nodeType !== ELEMENT_NODE) | ||
/** | ||
* @param {Element} element | ||
* @returns {Element?} | ||
*/ | ||
lastElementChild({lastChild}) { | ||
@@ -135,2 +171,6 @@ if (lastChild) { | ||
/** | ||
* @param {Element} element | ||
* @returns {number} | ||
*/ | ||
childElementCount({children}) { | ||
@@ -140,2 +180,6 @@ return children.length; | ||
/** | ||
* @param {Element} element | ||
* @param {...Nodes} nodes | ||
*/ | ||
prepend(element, ...nodes) { | ||
@@ -152,2 +196,6 @@ const {ownerDocument, firstChild} = element; | ||
/** | ||
* @param {Element} element | ||
* @param {...Nodes} nodes | ||
*/ | ||
replaceChildren(element, ...nodes) { | ||
@@ -163,2 +211,7 @@ let {_next, _end} = element; | ||
/** | ||
* @param {Element} element | ||
* @param {string} selectors | ||
* @returns {Element?} | ||
*/ | ||
querySelector({_next}, selectors) { | ||
@@ -173,2 +226,7 @@ while (_next) { | ||
/** | ||
* @param {Element} element | ||
* @param {string} selectors | ||
* @returns {NodeList} | ||
*/ | ||
querySelectorAll({_next}, selectors) { | ||
@@ -175,0 +233,0 @@ const elements = new NodeList; |
@@ -22,2 +22,5 @@ import { | ||
/** | ||
* @implements globalThis.Node | ||
*/ | ||
export class Node extends EventTarget { | ||
@@ -34,5 +37,21 @@ | ||
super(); | ||
/** | ||
* @type {Document} | ||
*/ | ||
this.ownerDocument = ownerDocument; | ||
/** | ||
* @type {string} | ||
*/ | ||
this.localName = localName; | ||
/** | ||
* @type {number} | ||
*/ | ||
this.nodeType = nodeType; | ||
/** | ||
* @type {Element?} | ||
*/ | ||
this.parentNode = null; | ||
@@ -57,2 +76,5 @@ | ||
/** | ||
* @type {Element?} | ||
*/ | ||
get parentElement() { | ||
@@ -71,2 +93,6 @@ let {parentNode} = this; | ||
// it's huge, but it should never suffer a maximum callstack issue | ||
/** | ||
* @param {boolean?} deep | ||
* @returns {Node} | ||
*/ | ||
cloneNode(deep = false) { | ||
@@ -130,2 +156,6 @@ const {ownerDocument, nodeType, localName} = this; | ||
/** | ||
* @type {Node} | ||
* @returns {boolean} | ||
*/ | ||
isEqualNode(node) { | ||
@@ -149,2 +179,5 @@ const {nodeType} = this; | ||
// meh | ||
/** | ||
* @type {Node} | ||
*/ | ||
isSameNode(node) { | ||
@@ -161,2 +194,5 @@ return this === node; | ||
/** | ||
* @type {Node?} | ||
*/ | ||
get firstChild() { | ||
@@ -167,2 +203,5 @@ const {_next, _end} = findNext(this); | ||
/** | ||
* @type {Node?} | ||
*/ | ||
get lastChild() { | ||
@@ -190,2 +229,5 @@ const {_prev} = this._end; | ||
/** | ||
* @returns {Element} | ||
*/ | ||
getRootNode() { | ||
@@ -195,2 +237,6 @@ return this.ownerDocument.root; | ||
/** | ||
* @param {Node} node | ||
* @returns {boolean} | ||
*/ | ||
contains(node) { | ||
@@ -207,2 +253,5 @@ let {parentNode} = node; | ||
/** | ||
* @param {Node} node | ||
*/ | ||
appendChild(node) { | ||
@@ -212,2 +261,7 @@ return this.insertBefore(node, this._end); | ||
/** | ||
* @param {Node} node | ||
* @param {Node?} node | ||
* @returns {Node} | ||
*/ | ||
insertBefore(node, before) { | ||
@@ -267,2 +321,6 @@ const _end = before || this._end; | ||
/** | ||
* @param {Node} node | ||
* @returns {Node} | ||
*/ | ||
removeChild(node) { | ||
@@ -275,2 +333,7 @@ if (node.parentNode !== this) | ||
/** | ||
* @param {Node} node | ||
* @param {Node} replaced | ||
* @returns {Node} | ||
*/ | ||
replaceChild(node, replaced) { | ||
@@ -289,2 +352,6 @@ const {_prev, _next} = getBoundaries(replaced); | ||
/** | ||
* @param {string} selectors | ||
* @returns {Element?} | ||
*/ | ||
querySelector(selectors) { | ||
@@ -294,2 +361,6 @@ return ParentNode.querySelector(this, selectors); | ||
/** | ||
* @param {string} selectors | ||
* @returns {NodeList} | ||
*/ | ||
querySelectorAll(selectors) { | ||
@@ -309,6 +380,20 @@ return ParentNode.querySelectorAll(this, selectors); | ||
/** | ||
* @type {null} | ||
*/ | ||
get firstChild() { return null; } | ||
/** | ||
* @type {null} | ||
*/ | ||
get lastChild() { return null; } | ||
/** | ||
* @type {NodeList} | ||
*/ | ||
get childNodes() { return []; } | ||
/** | ||
* @type {Node?} | ||
*/ | ||
get nextSibling() { | ||
@@ -318,2 +403,5 @@ return this._next; | ||
/** | ||
* @type {Node?} | ||
*/ | ||
get previousSibling() { | ||
@@ -323,2 +411,5 @@ return this._prev; | ||
/** | ||
* @type {Element?} | ||
*/ | ||
get nextElementSibling() { | ||
@@ -328,2 +419,5 @@ return NonDocumentTypeChildNode.nextElementSibling(this); | ||
/** | ||
* @type {Element?} | ||
*/ | ||
get previousElementSibling() { | ||
@@ -330,0 +424,0 @@ return NonDocumentTypeChildNode.previousElementSibling(this); |
import {Document} from './document.js'; | ||
/** | ||
* @implements globalThis.SVGDocument | ||
*/ | ||
export class SVGDocument extends Document { | ||
@@ -8,2 +11,2 @@ | ||
} | ||
}; | ||
} |
@@ -6,2 +6,5 @@ import {escape} from 'html-escaper'; | ||
/** | ||
* @implements globalThis.Text | ||
*/ | ||
export class Text extends NodeText { | ||
@@ -8,0 +11,0 @@ |
import {Document} from './document.js'; | ||
/** | ||
* @implements globalThis.XMLDocument | ||
*/ | ||
export class XMLDocument extends Document { | ||
@@ -8,2 +11,2 @@ | ||
} | ||
}; | ||
} |
{ | ||
"name": "linkedom", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "A triple-linked lists based DOM", | ||
@@ -5,0 +5,0 @@ "main": "./cjs/index.js", |
99937
3321