@litejs/dom 23.11.1 → 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 +6 -13
- package/{index.js → dom.js} +18 -21
- package/net.js +16 -5
- package/package.json +3 -5
- package/selector.js +1 -2
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,18 +59,14 @@ 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`
|
|
68
|
-
|
|
62
|
+
Follow [Coding Style Guide](https://github.com/litejs/litejs/wiki/Style-Guide),
|
|
63
|
+
run tests `npm install; npm test`.
|
|
69
64
|
|
|
70
|
-
## Licence
|
|
71
65
|
|
|
72
|
-
Copyright (c) 2014-2023 Lauri Rooden <lauri@rooden.ee>
|
|
66
|
+
> Copyright (c) 2014-2023 Lauri Rooden <lauri@rooden.ee>
|
|
73
67
|
[MIT License](https://litejs.com/MIT-LICENSE.txt) |
|
|
74
68
|
[GitHub repo](https://github.com/litejs/dom) |
|
|
75
69
|
[npm package](https://npmjs.org/package/@litejs/dom) |
|
|
76
|
-
[coverage][2] |
|
|
77
70
|
[Buy Me A Tea][6]
|
|
78
71
|
|
|
79
72
|
|
package/{index.js → dom.js}
RENAMED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
|
|
2
|
-
|
|
3
2
|
/*! litejs.com/MIT-LICENSE.txt */
|
|
4
3
|
|
|
5
|
-
|
|
6
4
|
var boolAttrs = {
|
|
7
5
|
async:1, autoplay:1, loop:1, checked:1, defer:1, disabled:1, muted:1, multiple:1, nomodule:1, playsinline:1, readonly:1, required:1, selected:1
|
|
8
6
|
}
|
|
@@ -35,7 +33,7 @@ var boolAttrs = {
|
|
|
35
33
|
return this.nodeType === 3 || this.nodeType === 8 ? this.data : null
|
|
36
34
|
},
|
|
37
35
|
set nodeValue(text) {
|
|
38
|
-
|
|
36
|
+
if (this.nodeType === 3 || this.nodeType === 8) this.data = text
|
|
39
37
|
},
|
|
40
38
|
get textContent() {
|
|
41
39
|
return this.nodeType === 3 || this.nodeType === 8 ? this.data : this.childNodes.map(function(child) {
|
|
@@ -43,8 +41,8 @@ var boolAttrs = {
|
|
|
43
41
|
}).join("")
|
|
44
42
|
},
|
|
45
43
|
set textContent(text) {
|
|
46
|
-
if (this.nodeType === 3 || this.nodeType === 8)
|
|
47
|
-
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(
|
|
48
46
|
rawTextEscape[this.tagName] ? text.replace(rawTextEscape[this.tagName], "<\\") : text
|
|
49
47
|
))
|
|
50
48
|
},
|
|
@@ -96,8 +94,6 @@ var boolAttrs = {
|
|
|
96
94
|
}
|
|
97
95
|
replaceChildren.call(node, frag)
|
|
98
96
|
|
|
99
|
-
return html
|
|
100
|
-
|
|
101
97
|
function setAttr(_, name, value, q, qvalue) {
|
|
102
98
|
child.setAttribute(name, (q ? qvalue : value || "").replace(unescRe, unescFn))
|
|
103
99
|
}
|
|
@@ -109,7 +105,6 @@ var boolAttrs = {
|
|
|
109
105
|
var frag = this.ownerDocument.createDocumentFragment()
|
|
110
106
|
frag.innerHTML = html
|
|
111
107
|
this.parentNode.replaceChild(frag, this)
|
|
112
|
-
return html
|
|
113
108
|
},
|
|
114
109
|
get style() {
|
|
115
110
|
return this._style || (this._style = new CSSStyleDeclaration(this.getAttribute("style") || ""))
|
|
@@ -163,13 +158,14 @@ var boolAttrs = {
|
|
|
163
158
|
return this.removeChild(ref)
|
|
164
159
|
},
|
|
165
160
|
cloneNode: function(deep) {
|
|
166
|
-
var
|
|
167
|
-
, node = this
|
|
161
|
+
var node = this
|
|
168
162
|
, clone = new node.constructor(node.tagName || node.data)
|
|
169
163
|
clone.ownerDocument = node.ownerDocument
|
|
170
164
|
|
|
171
|
-
if (node.
|
|
172
|
-
|
|
165
|
+
if (node.attributes) {
|
|
166
|
+
node.attributes.names().forEach(function(attr) {
|
|
167
|
+
clone.setAttribute(attr, node.getAttribute(attr))
|
|
168
|
+
})
|
|
173
169
|
}
|
|
174
170
|
|
|
175
171
|
if (deep && node.hasChildNodes()) {
|
|
@@ -227,8 +223,8 @@ var boolAttrs = {
|
|
|
227
223
|
}
|
|
228
224
|
, quotedAttrRe = /[\s"'`=<>]/
|
|
229
225
|
, escRe = /<|&(?=[a-z#])/gi
|
|
230
|
-
, unescRe =
|
|
231
|
-
,
|
|
226
|
+
, unescRe = /&[a-z]{1,31};?|&#(x|)([\da-f]+);/ig
|
|
227
|
+
, entities = {
|
|
232
228
|
"&": "&", "'": "'", "¢": "¢", "©": "©", "¤": "¤",
|
|
233
229
|
"°": "°", "€": "€", ">": ">", "<": "<", " ": " ",
|
|
234
230
|
"±": "±", "£": "£", """: "\"", "®": "®",
|
|
@@ -260,7 +256,7 @@ function escFn(chr) {
|
|
|
260
256
|
}
|
|
261
257
|
|
|
262
258
|
function unescFn(ent, hex, num) {
|
|
263
|
-
return num ? String.fromCharCode(parseInt(num, hex === "" ? 10 : 16)) :
|
|
259
|
+
return num ? String.fromCharCode(parseInt(num, hex === "" ? 10 : 16)) : entities[ent] || ent
|
|
264
260
|
}
|
|
265
261
|
|
|
266
262
|
;["hasAttribute", "getAttribute", "setAttribute", "removeAttribute"].forEach(function(name) {
|
|
@@ -479,7 +475,7 @@ function extendNode(obj, extras) {
|
|
|
479
475
|
}
|
|
480
476
|
|
|
481
477
|
function replaceChildren() {
|
|
482
|
-
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
|
|
483
479
|
for (i = arr.length = 0, l = arguments.length; i < l; ) this.insertBefore(arguments[i++])
|
|
484
480
|
}
|
|
485
481
|
|
|
@@ -505,11 +501,12 @@ function hyphenCase(str) {
|
|
|
505
501
|
}
|
|
506
502
|
|
|
507
503
|
exports.document = new Document()
|
|
508
|
-
exports.
|
|
509
|
-
exports.XMLSerializer = XMLSerializer
|
|
504
|
+
exports.entities = entities
|
|
510
505
|
exports.CSSStyleDeclaration = CSSStyleDeclaration
|
|
511
|
-
exports.
|
|
512
|
-
exports.HTMLElement = HTMLElement
|
|
513
|
-
exports.DocumentFragment = DocumentFragment
|
|
506
|
+
exports.DOMParser = DOMParser
|
|
514
507
|
exports.Document = Document
|
|
508
|
+
exports.DocumentFragment = DocumentFragment
|
|
509
|
+
exports.HTMLElement = HTMLElement
|
|
510
|
+
exports.Node = Node
|
|
511
|
+
exports.XMLSerializer = XMLSerializer
|
|
515
512
|
|
package/net.js
CHANGED
|
@@ -8,7 +8,14 @@ var DOM = require(".")
|
|
|
8
8
|
, parser = new DOM.DOMParser()
|
|
9
9
|
, dataUrlRe = /^([^;,]*?)(;[^,]+?|),(.*)$/
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
exports.XMLHttpRequest = XMLHttpRequest
|
|
12
|
+
exports.defaultHeaders = {
|
|
13
|
+
accept: ["Accept", "*/*"]
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function XMLHttpRequest() {
|
|
17
|
+
this._reqHeaders = Object.assign({}, exports.defaultHeaders)
|
|
18
|
+
}
|
|
12
19
|
|
|
13
20
|
function setState(xhr, state) {
|
|
14
21
|
if (xhr.readyState !== state) {
|
|
@@ -51,6 +58,9 @@ XMLHttpRequest.prototype = {
|
|
|
51
58
|
var xhr = this
|
|
52
59
|
return xhr.readyState >= xhr.HEADERS_RECEIVED && xhr._headers[name.toLowerCase()] || null
|
|
53
60
|
},
|
|
61
|
+
setRequestHeader: function(name, value) {
|
|
62
|
+
this._reqHeaders[name.toLowerCase()] = [name, value]
|
|
63
|
+
},
|
|
54
64
|
abort: function() {
|
|
55
65
|
throw Error("XMLHttpRequest abort/reuse not implemented")
|
|
56
66
|
},
|
|
@@ -72,6 +82,11 @@ XMLHttpRequest.prototype = {
|
|
|
72
82
|
|
|
73
83
|
if (url.protocol === "http:" || url.protocol === "https:") {
|
|
74
84
|
url.method = xhr.method
|
|
85
|
+
url.headers = Object.keys(xhr._reqHeaders).reduce(function(result, key) {
|
|
86
|
+
var entrie = xhr._reqHeaders[key]
|
|
87
|
+
result[entrie[0]] = entrie[1]
|
|
88
|
+
return result
|
|
89
|
+
}, {})
|
|
75
90
|
require(url.protocol.slice(0, -1)).request(url, function(res) {
|
|
76
91
|
head(res.statusCode, res.statusMessage, res.headers)
|
|
77
92
|
res.on("data", fillBody)
|
|
@@ -122,7 +137,3 @@ XMLHttpRequest.prototype = {
|
|
|
122
137
|
}
|
|
123
138
|
|
|
124
139
|
|
|
125
|
-
module.exports = {
|
|
126
|
-
XMLHttpRequest: XMLHttpRequest
|
|
127
|
-
}
|
|
128
|
-
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@litejs/dom",
|
|
3
|
-
"version": "23.
|
|
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
|
],
|
|
@@ -21,10 +22,7 @@
|
|
|
21
22
|
},
|
|
22
23
|
"repository": "github:litejs/dom",
|
|
23
24
|
"devDependencies": {
|
|
24
|
-
"@litejs/cli": "23.
|
|
25
|
+
"@litejs/cli": "23.11.1",
|
|
25
26
|
"jshint": "2.13.6"
|
|
26
|
-
},
|
|
27
|
-
"litejs": {
|
|
28
|
-
"build": false
|
|
29
27
|
}
|
|
30
28
|
}
|
package/selector.js
CHANGED
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
return ""
|
|
70
70
|
})
|
|
71
71
|
|
|
72
|
-
if (tag && tag != "*") rules[0] += "&&_.tagName=='" + tag.toUpperCase() + "'"
|
|
72
|
+
if (tag && tag != "*") rules[0] += "&&_.tagName==(_.namespaceURI?'" + tag.toUpperCase() + "':'" + tag + "')"
|
|
73
73
|
if (parentSel) rules.push("(v='" + parentSel + "')", selectorMap[relation + relation])
|
|
74
74
|
return rules.join("&&")
|
|
75
75
|
}).join("||") + "}"
|
|
@@ -106,7 +106,6 @@
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
exports.find = find
|
|
109
|
-
exports.fn = selectorFn
|
|
110
109
|
exports.matches = matches
|
|
111
110
|
exports.next = next
|
|
112
111
|
exports.prev = prev
|