@litejs/dom 23.8.0 → 23.11.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 +1 -4
- package/index.js +1 -1
- package/net.js +27 -16
- package/package.json +3 -3
package/README.md
CHANGED
package/index.js
CHANGED
|
@@ -493,7 +493,7 @@ function getElement(childs, index, step, type) {
|
|
|
493
493
|
function getSibling(node, step, type) {
|
|
494
494
|
var silbings = node.parentNode && node.parentNode.childNodes
|
|
495
495
|
, index = silbings ? silbings.indexOf(node) : -1
|
|
496
|
-
return type > 0 ? getElement(silbings, index + step, step, type) : silbings[index + step] || null
|
|
496
|
+
return type > 0 ? getElement(silbings, index + step, step, type) : silbings && silbings[index + step] || null
|
|
497
497
|
}
|
|
498
498
|
|
|
499
499
|
function camelCase(str) {
|
package/net.js
CHANGED
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
var DOM = require(".")
|
|
7
|
+
, URL = require("url").URL
|
|
7
8
|
, parser = new DOM.DOMParser()
|
|
8
|
-
, dataUrlRe = /^
|
|
9
|
+
, dataUrlRe = /^([^;,]*?)(;[^,]+?|),(.*)$/
|
|
9
10
|
|
|
10
11
|
function XMLHttpRequest() {}
|
|
11
12
|
|
|
@@ -67,32 +68,42 @@ XMLHttpRequest.prototype = {
|
|
|
67
68
|
},
|
|
68
69
|
send: function (data) {
|
|
69
70
|
var xhr = this
|
|
70
|
-
, url = xhr.responseURL
|
|
71
|
-
, proto = url.split(":", 1)[0]
|
|
72
|
-
, opts = {
|
|
73
|
-
method: xhr.method
|
|
74
|
-
}
|
|
71
|
+
, url = new URL(xhr.responseURL, XMLHttpRequest.base)
|
|
75
72
|
|
|
76
|
-
if (
|
|
77
|
-
|
|
73
|
+
if (url.protocol === "http:" || url.protocol === "https:") {
|
|
74
|
+
url.method = xhr.method
|
|
75
|
+
require(url.protocol.slice(0, -1)).request(url, function(res) {
|
|
78
76
|
head(res.statusCode, res.statusMessage, res.headers)
|
|
79
|
-
res.on("data",
|
|
77
|
+
res.on("data", fillBody)
|
|
80
78
|
res.on("end", done)
|
|
81
79
|
}).end(data)
|
|
82
80
|
return
|
|
83
81
|
}
|
|
84
|
-
if (
|
|
85
|
-
var match = dataUrlRe.exec(url)
|
|
82
|
+
if (url.protocol === "data:") {
|
|
83
|
+
var match = dataUrlRe.exec(url.pathname)
|
|
86
84
|
if (!match) throw Error("Invalid URL: " + url)
|
|
87
|
-
|
|
85
|
+
process.nextTick(function() {
|
|
88
86
|
head(200, "OK", { "content-type": match[1] || "text/plain" })
|
|
89
|
-
|
|
87
|
+
fillBody(match[2] ? Buffer.from(match[3], "base64") : unescape(match[3]))
|
|
88
|
+
done()
|
|
89
|
+
})
|
|
90
|
+
return
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (url.protocol === "file:") {
|
|
94
|
+
require("fs").readFile(url, function(err, chunk) {
|
|
95
|
+
if (err) {
|
|
96
|
+
head(404, "Not Found", {})
|
|
97
|
+
} else {
|
|
98
|
+
head(200, "OK", { "content-type": "text/plain" })
|
|
99
|
+
fillBody(chunk)
|
|
100
|
+
}
|
|
90
101
|
done()
|
|
91
|
-
}
|
|
102
|
+
})
|
|
92
103
|
return
|
|
93
104
|
}
|
|
94
105
|
|
|
95
|
-
throw Error("Unsuported protocol: " +
|
|
106
|
+
throw Error("Unsuported protocol in: " + url)
|
|
96
107
|
|
|
97
108
|
function head(code, text, headers) {
|
|
98
109
|
xhr.status = code
|
|
@@ -100,7 +111,7 @@ XMLHttpRequest.prototype = {
|
|
|
100
111
|
xhr._headers = headers
|
|
101
112
|
setState(xhr, xhr.HEADERS_RECEIVED)
|
|
102
113
|
}
|
|
103
|
-
function
|
|
114
|
+
function fillBody(chunk) {
|
|
104
115
|
xhr.responseText += chunk.toString("utf8")
|
|
105
116
|
setState(xhr, xhr.LOADING)
|
|
106
117
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@litejs/dom",
|
|
3
|
-
"version": "23.
|
|
3
|
+
"version": "23.11.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>",
|
|
@@ -16,12 +16,12 @@
|
|
|
16
16
|
"*.js"
|
|
17
17
|
],
|
|
18
18
|
"scripts": {
|
|
19
|
-
"test": "lj test --coverage --
|
|
19
|
+
"test": "lj test --coverage --brief test/index.js && node --import=@litejs/cli/test.js test/run.mjs && jshint --config .github/jshint.json *.js",
|
|
20
20
|
"test-fast": "lj test --brief test/index.js"
|
|
21
21
|
},
|
|
22
22
|
"repository": "github:litejs/dom",
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@litejs/cli": "23.
|
|
24
|
+
"@litejs/cli": "23.9.0",
|
|
25
25
|
"jshint": "2.13.6"
|
|
26
26
|
},
|
|
27
27
|
"litejs": {
|