@litejs/dom 23.12.0 → 23.12.1
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 +5 -9
- package/{index.js → dom.js} +9 -11
- package/net.js +3 -6
- package/package.json +2 -1
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,9 +59,8 @@ 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
66
|
> Copyright (c) 2014-2023 Lauri Rooden <lauri@rooden.ee>
|
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
|
},
|
|
@@ -94,8 +94,6 @@ var boolAttrs = {
|
|
|
94
94
|
}
|
|
95
95
|
replaceChildren.call(node, frag)
|
|
96
96
|
|
|
97
|
-
return html
|
|
98
|
-
|
|
99
97
|
function setAttr(_, name, value, q, qvalue) {
|
|
100
98
|
child.setAttribute(name, (q ? qvalue : value || "").replace(unescRe, unescFn))
|
|
101
99
|
}
|
|
@@ -107,7 +105,6 @@ var boolAttrs = {
|
|
|
107
105
|
var frag = this.ownerDocument.createDocumentFragment()
|
|
108
106
|
frag.innerHTML = html
|
|
109
107
|
this.parentNode.replaceChild(frag, this)
|
|
110
|
-
return html
|
|
111
108
|
},
|
|
112
109
|
get style() {
|
|
113
110
|
return this._style || (this._style = new CSSStyleDeclaration(this.getAttribute("style") || ""))
|
|
@@ -161,13 +158,14 @@ var boolAttrs = {
|
|
|
161
158
|
return this.removeChild(ref)
|
|
162
159
|
},
|
|
163
160
|
cloneNode: function(deep) {
|
|
164
|
-
var
|
|
165
|
-
, node = this
|
|
161
|
+
var node = this
|
|
166
162
|
, clone = new node.constructor(node.tagName || node.data)
|
|
167
163
|
clone.ownerDocument = node.ownerDocument
|
|
168
164
|
|
|
169
|
-
if (node.
|
|
170
|
-
|
|
165
|
+
if (node.attributes) {
|
|
166
|
+
node.attributes.names().forEach(function(attr) {
|
|
167
|
+
clone.setAttribute(attr, node.getAttribute(attr))
|
|
168
|
+
})
|
|
171
169
|
}
|
|
172
170
|
|
|
173
171
|
if (deep && node.hasChildNodes()) {
|
|
@@ -477,7 +475,7 @@ function extendNode(obj, extras) {
|
|
|
477
475
|
}
|
|
478
476
|
|
|
479
477
|
function replaceChildren() {
|
|
480
|
-
for (var arr = this.childNodes, i = 0, l = arr
|
|
478
|
+
for (var arr = this.childNodes, i = 0, l = arr.length; i < l; ) arr[i++].parentNode = null
|
|
481
479
|
for (i = arr.length = 0, l = arguments.length; i < l; ) this.insertBefore(arguments[i++])
|
|
482
480
|
}
|
|
483
481
|
|
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@litejs/dom",
|
|
3
|
-
"version": "23.12.
|
|
3
|
+
"version": "23.12.1",
|
|
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>",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"XMLSerializer",
|
|
13
13
|
"litejs"
|
|
14
14
|
],
|
|
15
|
+
"main": "dom.js",
|
|
15
16
|
"files": [
|
|
16
17
|
"*.js"
|
|
17
18
|
],
|