Comparing version 0.1.11 to 0.1.12
@@ -6,3 +6,3 @@ 'use strict'; | ||
const {String} = require('./utils.js'); | ||
const {Node} = require('./node.js'); | ||
const {ChildLess} = require('./node.js'); | ||
@@ -12,3 +12,3 @@ /** | ||
*/ | ||
class Attr extends Node { | ||
class Attr extends ChildLess { | ||
@@ -15,0 +15,0 @@ constructor(ownerDocument, name, value) { |
100
cjs/node.js
@@ -114,2 +114,3 @@ 'use strict'; | ||
cloneNode(deep = false) { | ||
/* c8 ignore start */ | ||
const {ownerDocument, nodeType, localName} = this; | ||
@@ -168,5 +169,16 @@ switch (nodeType) { | ||
} | ||
/* c8 ignore stop */ | ||
} | ||
/** | ||
* @returns {Node} | ||
*/ | ||
getRootNode() { | ||
let root = this; | ||
while (root.parentNode) | ||
root = root.parentNode; | ||
return root.nodeType === DOCUMENT_NODE ? root.root : root; | ||
} | ||
/** | ||
* @type {Node} | ||
@@ -176,2 +188,3 @@ * @returns {boolean} | ||
isEqualNode(node) { | ||
/* c8 ignore start */ | ||
const {nodeType} = this; | ||
@@ -181,4 +194,5 @@ if (nodeType === node.nodeType) { | ||
case ELEMENT_NODE: | ||
return this.outerHTML === node.outerHTML; | ||
case ATTRIBUTE_NODE: | ||
case TEXT_NODE: | ||
case COMMENT_NODE: | ||
return this.toString() === node.toString(); | ||
@@ -192,2 +206,3 @@ default: | ||
return false; | ||
/* c8 ignore stop */ | ||
} | ||
@@ -241,9 +256,2 @@ | ||
/** | ||
* @returns {Element} | ||
*/ | ||
getRootNode() { | ||
return this.ownerDocument.root; | ||
} | ||
/** | ||
* @param {Node} node | ||
@@ -285,6 +293,7 @@ * @returns {boolean} | ||
node._end._next = _end; | ||
node.parentNode = this; | ||
break; | ||
} | ||
case DOCUMENT_FRAGMENT_NODE: { | ||
const {firstChild, lastChild} = node; | ||
let {firstChild, lastChild} = node; | ||
if (firstChild) { | ||
@@ -299,2 +308,9 @@ _prev._next = firstChild; | ||
node._end._prev = node; | ||
// set parent node | ||
do { | ||
firstChild.parentNode = this; | ||
} while ( | ||
firstChild !== lastChild && | ||
(firstChild = firstChild._next) | ||
); | ||
} | ||
@@ -308,6 +324,6 @@ break; | ||
node._next = _end; | ||
node.parentNode = this; | ||
break; | ||
} | ||
} | ||
node.parentNode = this; | ||
return node; | ||
@@ -379,11 +395,4 @@ } | ||
class NodeText extends Node { | ||
class ChildLess extends Node { | ||
constructor(ownerDocument, localName, textContent, NODE) { | ||
super(ownerDocument, localName, NODE); | ||
this.textContent = String(textContent); | ||
} | ||
get nodeValue() { return this.textContent; } | ||
/** | ||
@@ -405,27 +414,27 @@ * @type {null} | ||
/** | ||
* @type {Node?} | ||
* @type {null} | ||
*/ | ||
get nextSibling() { | ||
return this._next; | ||
return null; | ||
} | ||
/** | ||
* @type {Node?} | ||
* @type {null} | ||
*/ | ||
get previousSibling() { | ||
return this._prev; | ||
return null; | ||
} | ||
/** | ||
* @type {Element?} | ||
* @type {null} | ||
*/ | ||
get nextElementSibling() { | ||
return NonDocumentTypeChildNode.nextElementSibling(this); | ||
return null; | ||
} | ||
/** | ||
* @type {Element?} | ||
* @type {null} | ||
*/ | ||
get previousElementSibling() { | ||
return NonDocumentTypeChildNode.previousElementSibling(this); | ||
return null; | ||
} | ||
@@ -441,2 +450,41 @@ | ||
} | ||
exports.ChildLess = ChildLess | ||
class NodeText extends ChildLess { | ||
constructor(ownerDocument, localName, textContent, NODE) { | ||
super(ownerDocument, localName, NODE); | ||
this.textContent = String(textContent); | ||
} | ||
get nodeValue() { return this.textContent; } | ||
/** | ||
* @type {Node?} | ||
*/ | ||
get nextSibling() { | ||
return this._next; | ||
} | ||
/** | ||
* @type {Node?} | ||
*/ | ||
get previousSibling() { | ||
return this._prev; | ||
} | ||
/** | ||
* @type {Element?} | ||
*/ | ||
get nextElementSibling() { | ||
return NonDocumentTypeChildNode.nextElementSibling(this); | ||
} | ||
/** | ||
* @type {Element?} | ||
*/ | ||
get previousElementSibling() { | ||
return NonDocumentTypeChildNode.previousElementSibling(this); | ||
} | ||
} | ||
exports.NodeText = NodeText | ||
@@ -443,0 +491,0 @@ |
@@ -5,3 +5,3 @@ import {escape} from 'html-escaper'; | ||
import {String} from './utils.js'; | ||
import {Node} from './node.js'; | ||
import {ChildLess} from './node.js'; | ||
@@ -11,3 +11,3 @@ /** | ||
*/ | ||
export class Attr extends Node { | ||
export class Attr extends ChildLess { | ||
@@ -14,0 +14,0 @@ constructor(ownerDocument, name, value) { |
@@ -428,3 +428,3 @@ import {ELEMENT_NODE, ELEMENT_NODE_END, ATTRIBUTE_NODE, TEXT_NODE, COMMENT_NODE} from './constants.js'; | ||
/* c8 ignore end */ | ||
/* c8 ignore stop */ | ||
} |
@@ -113,2 +113,3 @@ import { | ||
cloneNode(deep = false) { | ||
/* c8 ignore start */ | ||
const {ownerDocument, nodeType, localName} = this; | ||
@@ -167,5 +168,16 @@ switch (nodeType) { | ||
} | ||
/* c8 ignore stop */ | ||
} | ||
/** | ||
* @returns {Node} | ||
*/ | ||
getRootNode() { | ||
let root = this; | ||
while (root.parentNode) | ||
root = root.parentNode; | ||
return root.nodeType === DOCUMENT_NODE ? root.root : root; | ||
} | ||
/** | ||
* @type {Node} | ||
@@ -175,2 +187,3 @@ * @returns {boolean} | ||
isEqualNode(node) { | ||
/* c8 ignore start */ | ||
const {nodeType} = this; | ||
@@ -180,4 +193,5 @@ if (nodeType === node.nodeType) { | ||
case ELEMENT_NODE: | ||
return this.outerHTML === node.outerHTML; | ||
case ATTRIBUTE_NODE: | ||
case TEXT_NODE: | ||
case COMMENT_NODE: | ||
return this.toString() === node.toString(); | ||
@@ -191,2 +205,3 @@ default: | ||
return false; | ||
/* c8 ignore stop */ | ||
} | ||
@@ -239,9 +254,2 @@ | ||
/** | ||
* @returns {Element} | ||
*/ | ||
getRootNode() { | ||
return this.ownerDocument.root; | ||
} | ||
/** | ||
* @param {Node} node | ||
@@ -283,6 +291,7 @@ * @returns {boolean} | ||
node._end._next = _end; | ||
node.parentNode = this; | ||
break; | ||
} | ||
case DOCUMENT_FRAGMENT_NODE: { | ||
const {firstChild, lastChild} = node; | ||
let {firstChild, lastChild} = node; | ||
if (firstChild) { | ||
@@ -297,2 +306,9 @@ _prev._next = firstChild; | ||
node._end._prev = node; | ||
// set parent node | ||
do { | ||
firstChild.parentNode = this; | ||
} while ( | ||
firstChild !== lastChild && | ||
(firstChild = firstChild._next) | ||
); | ||
} | ||
@@ -306,6 +322,6 @@ break; | ||
node._next = _end; | ||
node.parentNode = this; | ||
break; | ||
} | ||
} | ||
node.parentNode = this; | ||
return node; | ||
@@ -376,11 +392,4 @@ } | ||
export class NodeText extends Node { | ||
export class ChildLess extends Node { | ||
constructor(ownerDocument, localName, textContent, NODE) { | ||
super(ownerDocument, localName, NODE); | ||
this.textContent = String(textContent); | ||
} | ||
get nodeValue() { return this.textContent; } | ||
/** | ||
@@ -402,27 +411,27 @@ * @type {null} | ||
/** | ||
* @type {Node?} | ||
* @type {null} | ||
*/ | ||
get nextSibling() { | ||
return this._next; | ||
return null; | ||
} | ||
/** | ||
* @type {Node?} | ||
* @type {null} | ||
*/ | ||
get previousSibling() { | ||
return this._prev; | ||
return null; | ||
} | ||
/** | ||
* @type {Element?} | ||
* @type {null} | ||
*/ | ||
get nextElementSibling() { | ||
return NonDocumentTypeChildNode.nextElementSibling(this); | ||
return null; | ||
} | ||
/** | ||
* @type {Element?} | ||
* @type {null} | ||
*/ | ||
get previousElementSibling() { | ||
return NonDocumentTypeChildNode.previousElementSibling(this); | ||
return null; | ||
} | ||
@@ -439,2 +448,40 @@ | ||
export class NodeText extends ChildLess { | ||
constructor(ownerDocument, localName, textContent, NODE) { | ||
super(ownerDocument, localName, NODE); | ||
this.textContent = String(textContent); | ||
} | ||
get nodeValue() { return this.textContent; } | ||
/** | ||
* @type {Node?} | ||
*/ | ||
get nextSibling() { | ||
return this._next; | ||
} | ||
/** | ||
* @type {Node?} | ||
*/ | ||
get previousSibling() { | ||
return this._prev; | ||
} | ||
/** | ||
* @type {Element?} | ||
*/ | ||
get nextElementSibling() { | ||
return NonDocumentTypeChildNode.nextElementSibling(this); | ||
} | ||
/** | ||
* @type {Element?} | ||
*/ | ||
get previousElementSibling() { | ||
return NonDocumentTypeChildNode.previousElementSibling(this); | ||
} | ||
} | ||
export class NodeElementEnd extends Node { | ||
@@ -441,0 +488,0 @@ constructor(element) { |
{ | ||
"name": "linkedom", | ||
"version": "0.1.11", | ||
"version": "0.1.12", | ||
"description": "A triple-linked lists based DOM", | ||
@@ -5,0 +5,0 @@ "main": "./cjs/index.js", |
@@ -18,3 +18,3 @@ # 🔗 linkedom | ||
Until there is a badge with 100% code coverage, consider this project highly experimental, or a playground, to see where and how a linked-list based DOM can shine, and how difficult it would be to reach at least feature-parity with *basicHTML*. | ||
Until there is a badge with 100% code coverage, and *npm* version is `0.1.x`, consider this project highly experimental, or a playground, to see where and how a linked-list based DOM can shine, and how difficult it would be to reach at least feature-parity with *basicHTML*. | ||
@@ -86,1 +86,7 @@ ```js | ||
``` | ||
### benchmark:dom | ||
 | ||
### benchmark:html | ||
 |
1477084
46
3532
91