@litejs/dom 23.12.0 → 24.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -10
- package/{index.js → dom.js} +21 -13
- package/net.js +3 -6
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ Examples
|
|
|
20
20
|
|
|
21
21
|
```javascript
|
|
22
22
|
const { document, DOMParser, XMLSerializer } = require("@litejs/dom");
|
|
23
|
-
const { XMLHttpRequest } = require("@litejs/dom/net");
|
|
23
|
+
const { XMLHttpRequest } = require("@litejs/dom/net.js");
|
|
24
24
|
|
|
25
25
|
// Use XMLHttpRequest in server side
|
|
26
26
|
var xhr = new XMLHttpRequest()
|
|
@@ -39,11 +39,8 @@ el.id = 123;
|
|
|
39
39
|
el.className = "large";
|
|
40
40
|
|
|
41
41
|
const fragment = document.createDocumentFragment();
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
fragment.appendChild(text1);
|
|
46
|
-
fragment.appendChild(text2);
|
|
42
|
+
fragment.appendChild(document.createTextNode("hello"));
|
|
43
|
+
fragment.appendChild(document.createTextNode(" world"));
|
|
47
44
|
el.appendChild(fragment);
|
|
48
45
|
|
|
49
46
|
el.innerHTML;
|
|
@@ -62,12 +59,11 @@ el.querySelectorAll("b");
|
|
|
62
59
|
|
|
63
60
|
## Contributing
|
|
64
61
|
|
|
65
|
-
Follow [Coding Style Guide](https://github.com/litejs/litejs/wiki/Style-Guide)
|
|
66
|
-
|
|
67
|
-
`npm install; npm test`
|
|
62
|
+
Follow [Coding Style Guide](https://github.com/litejs/litejs/wiki/Style-Guide),
|
|
63
|
+
run tests `npm install; npm test`.
|
|
68
64
|
|
|
69
65
|
|
|
70
|
-
> Copyright (c) 2014-
|
|
66
|
+
> Copyright (c) 2014-2024 Lauri Rooden <lauri@rooden.ee>
|
|
71
67
|
[MIT License](https://litejs.com/MIT-LICENSE.txt) |
|
|
72
68
|
[GitHub repo](https://github.com/litejs/dom) |
|
|
73
69
|
[npm package](https://npmjs.org/package/@litejs/dom) |
|
package/{index.js → dom.js}
RENAMED
|
@@ -33,7 +33,7 @@ var boolAttrs = {
|
|
|
33
33
|
return this.nodeType === 3 || this.nodeType === 8 ? this.data : null
|
|
34
34
|
},
|
|
35
35
|
set nodeValue(text) {
|
|
36
|
-
|
|
36
|
+
if (this.nodeType === 3 || this.nodeType === 8) this.data = text
|
|
37
37
|
},
|
|
38
38
|
get textContent() {
|
|
39
39
|
return this.nodeType === 3 || this.nodeType === 8 ? this.data : this.childNodes.map(function(child) {
|
|
@@ -41,8 +41,8 @@ var boolAttrs = {
|
|
|
41
41
|
}).join("")
|
|
42
42
|
},
|
|
43
43
|
set textContent(text) {
|
|
44
|
-
if (this.nodeType === 3 || this.nodeType === 8)
|
|
45
|
-
replaceChildren.call(this, this.ownerDocument.createTextNode(
|
|
44
|
+
if (this.nodeType === 3 || this.nodeType === 8) this.data = text
|
|
45
|
+
else replaceChildren.call(this, this.ownerDocument.createTextNode(
|
|
46
46
|
rawTextEscape[this.tagName] ? text.replace(rawTextEscape[this.tagName], "<\\") : text
|
|
47
47
|
))
|
|
48
48
|
},
|
|
@@ -83,6 +83,7 @@ var boolAttrs = {
|
|
|
83
83
|
if ((re = rawTextElements[child.tagName])) {
|
|
84
84
|
for (text = ""; (m = tagRe.exec(html)) && !re.test(m[0]); text += m[3] || m[0]);
|
|
85
85
|
child.textContent = text.replace(unescRe, unescFn)
|
|
86
|
+
if (!m) break
|
|
86
87
|
} else if (!voidElements[child.tagName] && !m[8]) tree = child
|
|
87
88
|
} else {
|
|
88
89
|
tree.appendChild(
|
|
@@ -94,8 +95,6 @@ var boolAttrs = {
|
|
|
94
95
|
}
|
|
95
96
|
replaceChildren.call(node, frag)
|
|
96
97
|
|
|
97
|
-
return html
|
|
98
|
-
|
|
99
98
|
function setAttr(_, name, value, q, qvalue) {
|
|
100
99
|
child.setAttribute(name, (q ? qvalue : value || "").replace(unescRe, unescFn))
|
|
101
100
|
}
|
|
@@ -107,7 +106,6 @@ var boolAttrs = {
|
|
|
107
106
|
var frag = this.ownerDocument.createDocumentFragment()
|
|
108
107
|
frag.innerHTML = html
|
|
109
108
|
this.parentNode.replaceChild(frag, this)
|
|
110
|
-
return html
|
|
111
109
|
},
|
|
112
110
|
get style() {
|
|
113
111
|
return this._style || (this._style = new CSSStyleDeclaration(this.getAttribute("style") || ""))
|
|
@@ -161,13 +159,14 @@ var boolAttrs = {
|
|
|
161
159
|
return this.removeChild(ref)
|
|
162
160
|
},
|
|
163
161
|
cloneNode: function(deep) {
|
|
164
|
-
var
|
|
165
|
-
, node = this
|
|
162
|
+
var node = this
|
|
166
163
|
, clone = new node.constructor(node.tagName || node.data)
|
|
167
164
|
clone.ownerDocument = node.ownerDocument
|
|
168
165
|
|
|
169
|
-
if (node.
|
|
170
|
-
|
|
166
|
+
if (node.attributes) {
|
|
167
|
+
node.attributes.names().forEach(function(attr) {
|
|
168
|
+
clone.setAttribute(attr, node.getAttribute(attr))
|
|
169
|
+
})
|
|
171
170
|
}
|
|
172
171
|
|
|
173
172
|
if (deep && node.hasChildNodes()) {
|
|
@@ -184,9 +183,9 @@ var boolAttrs = {
|
|
|
184
183
|
return selector.find(this, sel)
|
|
185
184
|
},
|
|
186
185
|
toString: function(minify) {
|
|
187
|
-
return rawTextElements[this.tagName] ? this.textContent : this.
|
|
186
|
+
return rawTextElements[this.tagName] ? this.textContent : this.childNodes.reduce(function(memo, node) {
|
|
188
187
|
return memo + node.toString(minify)
|
|
189
|
-
}, "")
|
|
188
|
+
}, "")
|
|
190
189
|
}
|
|
191
190
|
}
|
|
192
191
|
, Element = {
|
|
@@ -317,6 +316,7 @@ NamedNodeMap.prototype = {
|
|
|
317
316
|
if (!isXml) {
|
|
318
317
|
if (hasOwn.call(boolAttrs, loName)) return name
|
|
319
318
|
if (minify) {
|
|
319
|
+
value = loName.slice(0, 2) === "on" ? value.replace(/^[\s\uFEFF\xA0;]+|[\s\uFEFF\xA0;]+$/g, "") : value.replace(/\s+/g, " ").trim()
|
|
320
320
|
if (hasOwn.call(defaultAttrs, (tagName + " " + name + " " + value).toLowerCase())) return
|
|
321
321
|
if (!quotedAttrRe.test(value)) return name + "=" + value
|
|
322
322
|
if (value.split("\"").length > value.split("'").length) return name + "='" + value.replace(/'/g, "'") + "'"
|
|
@@ -432,6 +432,14 @@ function Document() {
|
|
|
432
432
|
}
|
|
433
433
|
|
|
434
434
|
extendNode(Document, Element, {
|
|
435
|
+
get title() {
|
|
436
|
+
var el = selector.find(this, "title", 1)
|
|
437
|
+
return el && el.textContent || ""
|
|
438
|
+
},
|
|
439
|
+
set title(text) {
|
|
440
|
+
var el = selector.find(this, "title", 1) || this.appendChild(this.createElement("title"))
|
|
441
|
+
el.textContent = text
|
|
442
|
+
},
|
|
435
443
|
nodeType: 9,
|
|
436
444
|
nodeName: "#document",
|
|
437
445
|
contentType: "text/html",
|
|
@@ -477,7 +485,7 @@ function extendNode(obj, extras) {
|
|
|
477
485
|
}
|
|
478
486
|
|
|
479
487
|
function replaceChildren() {
|
|
480
|
-
for (var arr = this.childNodes, i = 0, l = arr
|
|
488
|
+
for (var arr = this.childNodes, i = 0, l = arr.length; i < l; ) arr[i++].parentNode = null
|
|
481
489
|
for (i = arr.length = 0, l = arguments.length; i < l; ) this.insertBefore(arguments[i++])
|
|
482
490
|
}
|
|
483
491
|
|
package/net.js
CHANGED
|
@@ -8,12 +8,13 @@ var DOM = require(".")
|
|
|
8
8
|
, parser = new DOM.DOMParser()
|
|
9
9
|
, dataUrlRe = /^([^;,]*?)(;[^,]+?|),(.*)$/
|
|
10
10
|
|
|
11
|
-
XMLHttpRequest
|
|
11
|
+
exports.XMLHttpRequest = XMLHttpRequest
|
|
12
|
+
exports.defaultHeaders = {
|
|
12
13
|
accept: ["Accept", "*/*"]
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
function XMLHttpRequest() {
|
|
16
|
-
this._reqHeaders = Object.assign({},
|
|
17
|
+
this._reqHeaders = Object.assign({}, exports.defaultHeaders)
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
function setState(xhr, state) {
|
|
@@ -136,7 +137,3 @@ XMLHttpRequest.prototype = {
|
|
|
136
137
|
}
|
|
137
138
|
|
|
138
139
|
|
|
139
|
-
module.exports = {
|
|
140
|
-
XMLHttpRequest: XMLHttpRequest
|
|
141
|
-
}
|
|
142
|
-
|
package/package.json
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@litejs/dom",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "24.6.0",
|
|
4
4
|
"description": "A small DOM library for server-side testing, rendering, and handling of HTML files",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Lauri Rooden <lauri@rooden.ee>",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"document",
|
|
9
9
|
"dom",
|
|
10
|
+
"html",
|
|
10
11
|
"DOMParser",
|
|
11
12
|
"XMLHttpRequest",
|
|
12
13
|
"XMLSerializer",
|
|
13
14
|
"litejs"
|
|
14
15
|
],
|
|
16
|
+
"main": "dom.js",
|
|
15
17
|
"files": [
|
|
16
18
|
"*.js"
|
|
17
19
|
],
|
|
18
20
|
"scripts": {
|
|
19
|
-
"
|
|
20
|
-
"test
|
|
21
|
+
"lint": "jshint --config .github/jshint.json *.js",
|
|
22
|
+
"test": "lj t test/index.js"
|
|
21
23
|
},
|
|
22
24
|
"repository": "github:litejs/dom",
|
|
23
25
|
"devDependencies": {
|