@mtkruto/node 0.1.289 → 0.1.299
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 +77 -1
- package/esm/client/4_client.js +1 -1
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/DomHandler.d.ts +83 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/DomHandler.js +203 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/DomSerializer.d.ts +50 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/DomSerializer.js +274 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/ElementType.d.ts +47 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/ElementType.js +51 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/FeedHandler.d.ts +66 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/FeedHandler.js +191 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Node.d.ts +168 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Node.js +385 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Parser.d.ts +159 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Parser.js +431 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Tokenizer.d.ts +181 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Tokenizer.js +1046 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/mod.d.ts +42 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/mod.js +52 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode.d.ts +11 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode.js +122 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode_codepoint.d.ts +1 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode_codepoint.js +24 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/encode.d.ts +46 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/encode.js +121 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/decode.d.ts +31 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/decode.js +30 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/entities.d.ts +2128 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/entities.js +2127 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/legacy.d.ts +109 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/legacy.js +108 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/xml.d.ts +8 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/xml.js +1 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/mod.d.ts +90 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/mod.js +95 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/helpers.d.ts +50 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/helpers.js +128 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/legacy.d.ts +46 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/legacy.js +110 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/manipulation.d.ts +42 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/manipulation.js +120 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/mod.d.ts +6 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/mod.js +6 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/querying.d.ts +54 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/querying.js +110 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/stringify.d.ts +40 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/stringify.js +75 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/traversal.d.ts +58 -0
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/traversal.js +101 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/deflate.d.ts +2 -0
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/deflate.js +5 -1
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/inflate.d.ts +2 -2
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/inflate.js +5 -1
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/zlib/crc32.js +1 -1
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/zlib/deflate.js +8 -8
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/zlib/inffast.js +2 -2
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/zlib/inflate.js +19 -21
- package/esm/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/zlib/trees.js +3 -3
- package/package.json +1 -1
- package/script/client/4_client.js +1 -1
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/DomHandler.d.ts +83 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/DomHandler.js +207 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/DomSerializer.d.ts +50 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/DomSerializer.js +301 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/ElementType.d.ts +47 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/ElementType.js +55 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/FeedHandler.d.ts +66 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/FeedHandler.js +222 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/Node.d.ts +168 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/Node.js +404 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/Parser.d.ts +159 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/Parser.js +438 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/Tokenizer.d.ts +181 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/Tokenizer.js +1052 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/mod.d.ts +42 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/mod.js +88 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode.d.ts +11 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode.js +128 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode_codepoint.d.ts +1 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode_codepoint.js +30 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/encode.d.ts +46 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/encode.js +129 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/decode.d.ts +31 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/decode.js +32 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/entities.d.ts +2128 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/entities.js +2129 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/legacy.d.ts +109 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/legacy.js +110 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/xml.d.ts +8 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/xml.js +3 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/mod.d.ts +90 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/mod.js +114 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/helpers.d.ts +50 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/helpers.js +134 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/legacy.d.ts +46 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/legacy.js +118 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/manipulation.d.ts +42 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/manipulation.js +129 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/mod.d.ts +6 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/mod.js +22 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/querying.d.ts +54 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/querying.js +119 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/stringify.d.ts +40 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/stringify.js +86 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/traversal.d.ts +58 -0
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/traversal.js +112 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/deflate.d.ts +2 -0
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/deflate.js +7 -1
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/inflate.d.ts +2 -2
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/inflate.js +7 -1
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/zlib/crc32.js +1 -1
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/zlib/deflate.js +8 -8
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/zlib/inffast.js +2 -2
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/zlib/inflate.js +19 -21
- package/script/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/zlib/trees.js +3 -3
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DomHandler = void 0;
|
|
4
|
+
const Node_js_1 = require("./Node.js");
|
|
5
|
+
const ElementType_js_1 = require("./ElementType.js");
|
|
6
|
+
const reWhitespace = /\s+/g;
|
|
7
|
+
// Default options
|
|
8
|
+
const defaultOpts = {
|
|
9
|
+
normalizeWhitespace: false,
|
|
10
|
+
withStartIndices: false,
|
|
11
|
+
withEndIndices: false,
|
|
12
|
+
};
|
|
13
|
+
class DomHandler {
|
|
14
|
+
/**
|
|
15
|
+
* @param callback Called once parsing has completed.
|
|
16
|
+
* @param options Settings for the handler.
|
|
17
|
+
* @param elementCB Callback whenever a tag is closed.
|
|
18
|
+
*/
|
|
19
|
+
constructor(callback, options, elementCB) {
|
|
20
|
+
/** The elements of the DOM */
|
|
21
|
+
Object.defineProperty(this, "dom", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true,
|
|
25
|
+
value: []
|
|
26
|
+
});
|
|
27
|
+
/** The root element for the DOM */
|
|
28
|
+
Object.defineProperty(this, "root", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
configurable: true,
|
|
31
|
+
writable: true,
|
|
32
|
+
value: new Node_js_1.Document(this.dom)
|
|
33
|
+
});
|
|
34
|
+
/** Called once parsing has completed. */
|
|
35
|
+
Object.defineProperty(this, "callback", {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
configurable: true,
|
|
38
|
+
writable: true,
|
|
39
|
+
value: void 0
|
|
40
|
+
});
|
|
41
|
+
/** Settings for the handler. */
|
|
42
|
+
Object.defineProperty(this, "options", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
configurable: true,
|
|
45
|
+
writable: true,
|
|
46
|
+
value: void 0
|
|
47
|
+
});
|
|
48
|
+
/** Callback whenever a tag is closed. */
|
|
49
|
+
Object.defineProperty(this, "elementCB", {
|
|
50
|
+
enumerable: true,
|
|
51
|
+
configurable: true,
|
|
52
|
+
writable: true,
|
|
53
|
+
value: void 0
|
|
54
|
+
});
|
|
55
|
+
/** Indicated whether parsing has been completed. */
|
|
56
|
+
Object.defineProperty(this, "done", {
|
|
57
|
+
enumerable: true,
|
|
58
|
+
configurable: true,
|
|
59
|
+
writable: true,
|
|
60
|
+
value: false
|
|
61
|
+
});
|
|
62
|
+
/** Stack of open tags. */
|
|
63
|
+
Object.defineProperty(this, "tagStack", {
|
|
64
|
+
enumerable: true,
|
|
65
|
+
configurable: true,
|
|
66
|
+
writable: true,
|
|
67
|
+
value: [this.root]
|
|
68
|
+
});
|
|
69
|
+
/** A data node that is still being written to. */
|
|
70
|
+
Object.defineProperty(this, "lastNode", {
|
|
71
|
+
enumerable: true,
|
|
72
|
+
configurable: true,
|
|
73
|
+
writable: true,
|
|
74
|
+
value: null
|
|
75
|
+
});
|
|
76
|
+
/** Reference to the parser instance. Used for location information. */
|
|
77
|
+
Object.defineProperty(this, "parser", {
|
|
78
|
+
enumerable: true,
|
|
79
|
+
configurable: true,
|
|
80
|
+
writable: true,
|
|
81
|
+
value: null
|
|
82
|
+
});
|
|
83
|
+
// Make it possible to skip arguments, for backwards-compatibility
|
|
84
|
+
if (typeof options === 'function') {
|
|
85
|
+
elementCB = options;
|
|
86
|
+
options = defaultOpts;
|
|
87
|
+
}
|
|
88
|
+
if (typeof callback === 'object') {
|
|
89
|
+
options = callback;
|
|
90
|
+
callback = undefined;
|
|
91
|
+
}
|
|
92
|
+
this.callback = callback ?? null;
|
|
93
|
+
this.options = options ?? defaultOpts;
|
|
94
|
+
this.elementCB = elementCB ?? null;
|
|
95
|
+
}
|
|
96
|
+
onparserinit(parser) {
|
|
97
|
+
this.parser = parser;
|
|
98
|
+
}
|
|
99
|
+
// Resets the handler back to starting state
|
|
100
|
+
onreset() {
|
|
101
|
+
this.dom = [];
|
|
102
|
+
this.root = new Node_js_1.Document(this.dom);
|
|
103
|
+
this.done = false;
|
|
104
|
+
this.tagStack = [this.root];
|
|
105
|
+
this.lastNode = null;
|
|
106
|
+
this.parser = this.parser ?? null;
|
|
107
|
+
}
|
|
108
|
+
// Signals the handler that parsing is done
|
|
109
|
+
onend() {
|
|
110
|
+
if (this.done)
|
|
111
|
+
return;
|
|
112
|
+
this.done = true;
|
|
113
|
+
this.parser = null;
|
|
114
|
+
this.handleCallback(null);
|
|
115
|
+
}
|
|
116
|
+
onerror(error) {
|
|
117
|
+
this.handleCallback(error);
|
|
118
|
+
}
|
|
119
|
+
onclosetag() {
|
|
120
|
+
this.lastNode = null;
|
|
121
|
+
const elem = this.tagStack.pop();
|
|
122
|
+
if (this.options.withEndIndices) {
|
|
123
|
+
elem.endIndex = this.parser.endIndex;
|
|
124
|
+
}
|
|
125
|
+
if (this.elementCB)
|
|
126
|
+
this.elementCB(elem);
|
|
127
|
+
}
|
|
128
|
+
onopentag(name, attribs) {
|
|
129
|
+
const type = this.options.xmlMode ? ElementType_js_1.ElementType.Tag : undefined;
|
|
130
|
+
const element = new Node_js_1.Element(name, attribs, undefined, type);
|
|
131
|
+
this.addNode(element);
|
|
132
|
+
this.tagStack.push(element);
|
|
133
|
+
}
|
|
134
|
+
ontext(data) {
|
|
135
|
+
const { normalizeWhitespace } = this.options;
|
|
136
|
+
const { lastNode } = this;
|
|
137
|
+
if (lastNode && lastNode.type === ElementType_js_1.ElementType.Text) {
|
|
138
|
+
if (normalizeWhitespace) {
|
|
139
|
+
lastNode.data = (lastNode.data + data).replace(reWhitespace, ' ');
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
lastNode.data += data;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
if (normalizeWhitespace) {
|
|
147
|
+
data = data.replace(reWhitespace, ' ');
|
|
148
|
+
}
|
|
149
|
+
const node = new Node_js_1.Text(data);
|
|
150
|
+
this.addNode(node);
|
|
151
|
+
this.lastNode = node;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
oncomment(data) {
|
|
155
|
+
if (this.lastNode && this.lastNode.type === ElementType_js_1.ElementType.Comment) {
|
|
156
|
+
this.lastNode.data += data;
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const node = new Node_js_1.Comment(data);
|
|
160
|
+
this.addNode(node);
|
|
161
|
+
this.lastNode = node;
|
|
162
|
+
}
|
|
163
|
+
oncommentend() {
|
|
164
|
+
this.lastNode = null;
|
|
165
|
+
}
|
|
166
|
+
oncdatastart() {
|
|
167
|
+
const text = new Node_js_1.Text('');
|
|
168
|
+
const node = new Node_js_1.NodeWithChildren(ElementType_js_1.ElementType.CDATA, [text]);
|
|
169
|
+
this.addNode(node);
|
|
170
|
+
text.parent = node;
|
|
171
|
+
this.lastNode = text;
|
|
172
|
+
}
|
|
173
|
+
oncdataend() {
|
|
174
|
+
this.lastNode = null;
|
|
175
|
+
}
|
|
176
|
+
onprocessinginstruction(name, data) {
|
|
177
|
+
const node = new Node_js_1.ProcessingInstruction(name, data);
|
|
178
|
+
this.addNode(node);
|
|
179
|
+
}
|
|
180
|
+
handleCallback(error) {
|
|
181
|
+
if (typeof this.callback === 'function') {
|
|
182
|
+
this.callback(error, this.dom);
|
|
183
|
+
}
|
|
184
|
+
else if (error) {
|
|
185
|
+
throw error;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
addNode(node) {
|
|
189
|
+
const parent = this.tagStack[this.tagStack.length - 1];
|
|
190
|
+
const previousSibling = parent.children[parent.children.length - 1];
|
|
191
|
+
if (this.options.withStartIndices) {
|
|
192
|
+
node.startIndex = this.parser.startIndex;
|
|
193
|
+
}
|
|
194
|
+
if (this.options.withEndIndices) {
|
|
195
|
+
node.endIndex = this.parser.endIndex;
|
|
196
|
+
}
|
|
197
|
+
parent.children.push(node);
|
|
198
|
+
if (previousSibling) {
|
|
199
|
+
node.prev = previousSibling;
|
|
200
|
+
previousSibling.next = node;
|
|
201
|
+
}
|
|
202
|
+
node.parent = parent;
|
|
203
|
+
this.lastNode = null;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
exports.DomHandler = DomHandler;
|
|
207
|
+
exports.default = DomHandler;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Node } from './Node.js';
|
|
2
|
+
/**
|
|
3
|
+
* Mixed-case SVG and MathML tags & attributes
|
|
4
|
+
* recognized by the HTML parser.
|
|
5
|
+
*
|
|
6
|
+
* @see https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inforeign
|
|
7
|
+
*/
|
|
8
|
+
export declare const elementNames: Map<string, string>;
|
|
9
|
+
export declare const attributeNames: Map<string, string>;
|
|
10
|
+
export interface DomSerializerOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Print an empty attribute's value.
|
|
13
|
+
*
|
|
14
|
+
* @default xmlMode
|
|
15
|
+
* @example With <code>emptyAttrs: false</code>: <code><input checked></code>
|
|
16
|
+
* @example With <code>emptyAttrs: true</code>: <code><input checked=""></code>
|
|
17
|
+
*/
|
|
18
|
+
emptyAttrs?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Print self-closing tags for tags without contents.
|
|
21
|
+
*
|
|
22
|
+
* @default xmlMode
|
|
23
|
+
* @example With <code>selfClosingTags: false</code>: <code><foo></foo></code>
|
|
24
|
+
* @example With <code>selfClosingTags: true</code>: <code><foo /></code>
|
|
25
|
+
*/
|
|
26
|
+
selfClosingTags?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Treat the input as an XML document; enables the `emptyAttrs` and `selfClosingTags` options.
|
|
29
|
+
*
|
|
30
|
+
* If the value is `"foreign"`, it will try to correct mixed-case attribute names.
|
|
31
|
+
*
|
|
32
|
+
* @default false
|
|
33
|
+
*/
|
|
34
|
+
xmlMode?: boolean | 'foreign';
|
|
35
|
+
/**
|
|
36
|
+
* Encode characters that are either reserved in HTML or XML, or are outside of the ASCII range.
|
|
37
|
+
*
|
|
38
|
+
* @default true
|
|
39
|
+
*/
|
|
40
|
+
decodeEntities?: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Renders a DOM node or an array of DOM nodes to a string.
|
|
44
|
+
*
|
|
45
|
+
* Can be thought of as the equivalent of the `outerHTML` of the passed node(s).
|
|
46
|
+
*
|
|
47
|
+
* @param node Node to be rendered.
|
|
48
|
+
* @param options Changes serialization behavior
|
|
49
|
+
*/
|
|
50
|
+
export default function render(node: Node | ArrayLike<Node>, options?: DomSerializerOptions): string;
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.attributeNames = exports.elementNames = void 0;
|
|
27
|
+
/*
|
|
28
|
+
* Module dependencies
|
|
29
|
+
*/
|
|
30
|
+
const ElementType = __importStar(require("./ElementType.js"));
|
|
31
|
+
const mod_js_1 = require("./utils/entities/mod.js");
|
|
32
|
+
/**
|
|
33
|
+
* Mixed-case SVG and MathML tags & attributes
|
|
34
|
+
* recognized by the HTML parser.
|
|
35
|
+
*
|
|
36
|
+
* @see https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inforeign
|
|
37
|
+
*/
|
|
38
|
+
exports.elementNames = new Map([
|
|
39
|
+
['altglyph', 'altGlyph'],
|
|
40
|
+
['altglyphdef', 'altGlyphDef'],
|
|
41
|
+
['altglyphitem', 'altGlyphItem'],
|
|
42
|
+
['animatecolor', 'animateColor'],
|
|
43
|
+
['animatemotion', 'animateMotion'],
|
|
44
|
+
['animatetransform', 'animateTransform'],
|
|
45
|
+
['clippath', 'clipPath'],
|
|
46
|
+
['feblend', 'feBlend'],
|
|
47
|
+
['fecolormatrix', 'feColorMatrix'],
|
|
48
|
+
['fecomponenttransfer', 'feComponentTransfer'],
|
|
49
|
+
['fecomposite', 'feComposite'],
|
|
50
|
+
['feconvolvematrix', 'feConvolveMatrix'],
|
|
51
|
+
['fediffuselighting', 'feDiffuseLighting'],
|
|
52
|
+
['fedisplacementmap', 'feDisplacementMap'],
|
|
53
|
+
['fedistantlight', 'feDistantLight'],
|
|
54
|
+
['fedropshadow', 'feDropShadow'],
|
|
55
|
+
['feflood', 'feFlood'],
|
|
56
|
+
['fefunca', 'feFuncA'],
|
|
57
|
+
['fefuncb', 'feFuncB'],
|
|
58
|
+
['fefuncg', 'feFuncG'],
|
|
59
|
+
['fefuncr', 'feFuncR'],
|
|
60
|
+
['fegaussianblur', 'feGaussianBlur'],
|
|
61
|
+
['feimage', 'feImage'],
|
|
62
|
+
['femerge', 'feMerge'],
|
|
63
|
+
['femergenode', 'feMergeNode'],
|
|
64
|
+
['femorphology', 'feMorphology'],
|
|
65
|
+
['feoffset', 'feOffset'],
|
|
66
|
+
['fepointlight', 'fePointLight'],
|
|
67
|
+
['fespecularlighting', 'feSpecularLighting'],
|
|
68
|
+
['fespotlight', 'feSpotLight'],
|
|
69
|
+
['fetile', 'feTile'],
|
|
70
|
+
['feturbulence', 'feTurbulence'],
|
|
71
|
+
['foreignobject', 'foreignObject'],
|
|
72
|
+
['glyphref', 'glyphRef'],
|
|
73
|
+
['lineargradient', 'linearGradient'],
|
|
74
|
+
['radialgradient', 'radialGradient'],
|
|
75
|
+
['textpath', 'textPath'],
|
|
76
|
+
]);
|
|
77
|
+
exports.attributeNames = new Map([
|
|
78
|
+
['definitionurl', 'definitionURL'],
|
|
79
|
+
['attributename', 'attributeName'],
|
|
80
|
+
['attributetype', 'attributeType'],
|
|
81
|
+
['basefrequency', 'baseFrequency'],
|
|
82
|
+
['baseprofile', 'baseProfile'],
|
|
83
|
+
['calcmode', 'calcMode'],
|
|
84
|
+
['clippathunits', 'clipPathUnits'],
|
|
85
|
+
['diffuseconstant', 'diffuseConstant'],
|
|
86
|
+
['edgemode', 'edgeMode'],
|
|
87
|
+
['filterunits', 'filterUnits'],
|
|
88
|
+
['glyphref', 'glyphRef'],
|
|
89
|
+
['gradienttransform', 'gradientTransform'],
|
|
90
|
+
['gradientunits', 'gradientUnits'],
|
|
91
|
+
['kernelmatrix', 'kernelMatrix'],
|
|
92
|
+
['kernelunitlength', 'kernelUnitLength'],
|
|
93
|
+
['keypoints', 'keyPoints'],
|
|
94
|
+
['keysplines', 'keySplines'],
|
|
95
|
+
['keytimes', 'keyTimes'],
|
|
96
|
+
['lengthadjust', 'lengthAdjust'],
|
|
97
|
+
['limitingconeangle', 'limitingConeAngle'],
|
|
98
|
+
['markerheight', 'markerHeight'],
|
|
99
|
+
['markerunits', 'markerUnits'],
|
|
100
|
+
['markerwidth', 'markerWidth'],
|
|
101
|
+
['maskcontentunits', 'maskContentUnits'],
|
|
102
|
+
['maskunits', 'maskUnits'],
|
|
103
|
+
['numoctaves', 'numOctaves'],
|
|
104
|
+
['pathlength', 'pathLength'],
|
|
105
|
+
['patterncontentunits', 'patternContentUnits'],
|
|
106
|
+
['patterntransform', 'patternTransform'],
|
|
107
|
+
['patternunits', 'patternUnits'],
|
|
108
|
+
['pointsatx', 'pointsAtX'],
|
|
109
|
+
['pointsaty', 'pointsAtY'],
|
|
110
|
+
['pointsatz', 'pointsAtZ'],
|
|
111
|
+
['preservealpha', 'preserveAlpha'],
|
|
112
|
+
['preserveaspectratio', 'preserveAspectRatio'],
|
|
113
|
+
['primitiveunits', 'primitiveUnits'],
|
|
114
|
+
['refx', 'refX'],
|
|
115
|
+
['refy', 'refY'],
|
|
116
|
+
['repeatcount', 'repeatCount'],
|
|
117
|
+
['repeatdur', 'repeatDur'],
|
|
118
|
+
['requiredextensions', 'requiredExtensions'],
|
|
119
|
+
['requiredfeatures', 'requiredFeatures'],
|
|
120
|
+
['specularconstant', 'specularConstant'],
|
|
121
|
+
['specularexponent', 'specularExponent'],
|
|
122
|
+
['spreadmethod', 'spreadMethod'],
|
|
123
|
+
['startoffset', 'startOffset'],
|
|
124
|
+
['stddeviation', 'stdDeviation'],
|
|
125
|
+
['stitchtiles', 'stitchTiles'],
|
|
126
|
+
['surfacescale', 'surfaceScale'],
|
|
127
|
+
['systemlanguage', 'systemLanguage'],
|
|
128
|
+
['tablevalues', 'tableValues'],
|
|
129
|
+
['targetx', 'targetX'],
|
|
130
|
+
['targety', 'targetY'],
|
|
131
|
+
['textlength', 'textLength'],
|
|
132
|
+
['viewbox', 'viewBox'],
|
|
133
|
+
['viewtarget', 'viewTarget'],
|
|
134
|
+
['xchannelselector', 'xChannelSelector'],
|
|
135
|
+
['ychannelselector', 'yChannelSelector'],
|
|
136
|
+
['zoomandpan', 'zoomAndPan'],
|
|
137
|
+
]);
|
|
138
|
+
const unencodedElements = new Set([
|
|
139
|
+
'style',
|
|
140
|
+
'script',
|
|
141
|
+
'xmp',
|
|
142
|
+
'iframe',
|
|
143
|
+
'noembed',
|
|
144
|
+
'noframes',
|
|
145
|
+
'plaintext',
|
|
146
|
+
'noscript',
|
|
147
|
+
]);
|
|
148
|
+
/**
|
|
149
|
+
* Format attributes
|
|
150
|
+
*/
|
|
151
|
+
function formatAttributes(attributes, opts) {
|
|
152
|
+
if (!attributes)
|
|
153
|
+
return;
|
|
154
|
+
return Object.keys(attributes)
|
|
155
|
+
.map(key => {
|
|
156
|
+
const value = attributes[key] ?? '';
|
|
157
|
+
if (opts.xmlMode === 'foreign') {
|
|
158
|
+
/* Fix up mixed-case attribute names */
|
|
159
|
+
key = exports.attributeNames.get(key) ?? key;
|
|
160
|
+
}
|
|
161
|
+
if (!opts.emptyAttrs && !opts.xmlMode && value === '') {
|
|
162
|
+
return key;
|
|
163
|
+
}
|
|
164
|
+
return `${key}="${opts.decodeEntities !== false
|
|
165
|
+
? (0, mod_js_1.encodeXML)(value)
|
|
166
|
+
: value.replace(/"/g, '"')}"`;
|
|
167
|
+
})
|
|
168
|
+
.join(' ');
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Self-enclosing tags
|
|
172
|
+
*/
|
|
173
|
+
const singleTag = new Set([
|
|
174
|
+
'area',
|
|
175
|
+
'base',
|
|
176
|
+
'basefont',
|
|
177
|
+
'br',
|
|
178
|
+
'col',
|
|
179
|
+
'command',
|
|
180
|
+
'embed',
|
|
181
|
+
'frame',
|
|
182
|
+
'hr',
|
|
183
|
+
'img',
|
|
184
|
+
'input',
|
|
185
|
+
'isindex',
|
|
186
|
+
'keygen',
|
|
187
|
+
'link',
|
|
188
|
+
'meta',
|
|
189
|
+
'param',
|
|
190
|
+
'source',
|
|
191
|
+
'track',
|
|
192
|
+
'wbr',
|
|
193
|
+
]);
|
|
194
|
+
/**
|
|
195
|
+
* Renders a DOM node or an array of DOM nodes to a string.
|
|
196
|
+
*
|
|
197
|
+
* Can be thought of as the equivalent of the `outerHTML` of the passed node(s).
|
|
198
|
+
*
|
|
199
|
+
* @param node Node to be rendered.
|
|
200
|
+
* @param options Changes serialization behavior
|
|
201
|
+
*/
|
|
202
|
+
function render(node, options = {}) {
|
|
203
|
+
const nodes = 'length' in node ? node : [node];
|
|
204
|
+
let output = '';
|
|
205
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
206
|
+
output += renderNode(nodes[i], options);
|
|
207
|
+
}
|
|
208
|
+
return output;
|
|
209
|
+
}
|
|
210
|
+
exports.default = render;
|
|
211
|
+
function renderNode(node, options) {
|
|
212
|
+
switch (node.type) {
|
|
213
|
+
case ElementType.Root:
|
|
214
|
+
return render(node.children, options);
|
|
215
|
+
case ElementType.Directive:
|
|
216
|
+
case ElementType.Doctype:
|
|
217
|
+
return renderDirective(node);
|
|
218
|
+
case ElementType.Comment:
|
|
219
|
+
return renderComment(node);
|
|
220
|
+
case ElementType.CDATA:
|
|
221
|
+
return renderCdata(node);
|
|
222
|
+
case ElementType.Script:
|
|
223
|
+
case ElementType.Style:
|
|
224
|
+
case ElementType.Tag:
|
|
225
|
+
return renderTag(node, options);
|
|
226
|
+
case ElementType.Text:
|
|
227
|
+
return renderText(node, options);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
const foreignModeIntegrationPoints = new Set([
|
|
231
|
+
'mi',
|
|
232
|
+
'mo',
|
|
233
|
+
'mn',
|
|
234
|
+
'ms',
|
|
235
|
+
'mtext',
|
|
236
|
+
'annotation-xml',
|
|
237
|
+
'foreignObject',
|
|
238
|
+
'desc',
|
|
239
|
+
'title',
|
|
240
|
+
]);
|
|
241
|
+
const foreignElements = new Set(['svg', 'math']);
|
|
242
|
+
function renderTag(elem, opts) {
|
|
243
|
+
// Handle SVG / MathML in HTML
|
|
244
|
+
if (opts.xmlMode === 'foreign') {
|
|
245
|
+
/* Fix up mixed-case element names */
|
|
246
|
+
elem.name = exports.elementNames.get(elem.name) ?? elem.name;
|
|
247
|
+
/* Exit foreign mode at integration points */
|
|
248
|
+
if (elem.parent &&
|
|
249
|
+
foreignModeIntegrationPoints.has(elem.parent.name)) {
|
|
250
|
+
opts = { ...opts, xmlMode: false };
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (!opts.xmlMode && foreignElements.has(elem.name)) {
|
|
254
|
+
opts = { ...opts, xmlMode: 'foreign' };
|
|
255
|
+
}
|
|
256
|
+
let tag = `<${elem.name}`;
|
|
257
|
+
const attribs = formatAttributes(elem.attribs, opts);
|
|
258
|
+
if (attribs) {
|
|
259
|
+
tag += ` ${attribs}`;
|
|
260
|
+
}
|
|
261
|
+
if (elem.children.length === 0 &&
|
|
262
|
+
(opts.xmlMode
|
|
263
|
+
? // In XML mode or foreign mode, and user hasn't explicitly turned off self-closing tags
|
|
264
|
+
opts.selfClosingTags !== false
|
|
265
|
+
: // User explicitly asked for self-closing tags, even in HTML mode
|
|
266
|
+
opts.selfClosingTags && singleTag.has(elem.name))) {
|
|
267
|
+
if (!opts.xmlMode)
|
|
268
|
+
tag += ' ';
|
|
269
|
+
tag += '/>';
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
tag += '>';
|
|
273
|
+
if (elem.children.length > 0) {
|
|
274
|
+
tag += render(elem.children, opts);
|
|
275
|
+
}
|
|
276
|
+
if (opts.xmlMode || !singleTag.has(elem.name)) {
|
|
277
|
+
tag += `</${elem.name}>`;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
return tag;
|
|
281
|
+
}
|
|
282
|
+
function renderDirective(elem) {
|
|
283
|
+
return `<${elem.data}>`;
|
|
284
|
+
}
|
|
285
|
+
function renderText(elem, opts) {
|
|
286
|
+
let data = elem.data || '';
|
|
287
|
+
// If entities weren't decoded, no need to encode them back
|
|
288
|
+
if (opts.decodeEntities !== false &&
|
|
289
|
+
!(!opts.xmlMode &&
|
|
290
|
+
elem.parent &&
|
|
291
|
+
unencodedElements.has(elem.parent.name))) {
|
|
292
|
+
data = (0, mod_js_1.encodeXML)(data);
|
|
293
|
+
}
|
|
294
|
+
return data;
|
|
295
|
+
}
|
|
296
|
+
function renderCdata(elem) {
|
|
297
|
+
return `<![CDATA[${elem.children[0].data}]]>`;
|
|
298
|
+
}
|
|
299
|
+
function renderComment(elem) {
|
|
300
|
+
return `<!--${elem.data}-->`;
|
|
301
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** Types of elements found in htmlparser2's DOM */
|
|
2
|
+
export declare enum ElementType {
|
|
3
|
+
/** Type for the root element of a document */
|
|
4
|
+
Root = "root",
|
|
5
|
+
/** Type for Text */
|
|
6
|
+
Text = "text",
|
|
7
|
+
/** Type for <? ... ?> */
|
|
8
|
+
Directive = "directive",
|
|
9
|
+
/** Type for <!-- ... --> */
|
|
10
|
+
Comment = "comment",
|
|
11
|
+
/** Type for <script> tags */
|
|
12
|
+
Script = "script",
|
|
13
|
+
/** Type for <style> tags */
|
|
14
|
+
Style = "style",
|
|
15
|
+
/** Type for Any tag */
|
|
16
|
+
Tag = "tag",
|
|
17
|
+
/** Type for <![CDATA[ ... ]]> */
|
|
18
|
+
CDATA = "cdata",
|
|
19
|
+
/** Type for <!doctype ...> */
|
|
20
|
+
Doctype = "doctype"
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Tests whether an element is a tag or not.
|
|
24
|
+
*
|
|
25
|
+
* @param elem Element to test
|
|
26
|
+
*/
|
|
27
|
+
export declare function isTag(elem: {
|
|
28
|
+
type: ElementType;
|
|
29
|
+
}): boolean;
|
|
30
|
+
/** Type for the root element of a document */
|
|
31
|
+
export declare const Root = ElementType.Root;
|
|
32
|
+
/** Type for Text */
|
|
33
|
+
export declare const Text = ElementType.Text;
|
|
34
|
+
/** Type for <? ... ?> */
|
|
35
|
+
export declare const Directive = ElementType.Directive;
|
|
36
|
+
/** Type for <!-- ... --> */
|
|
37
|
+
export declare const Comment = ElementType.Comment;
|
|
38
|
+
/** Type for <script> tags */
|
|
39
|
+
export declare const Script = ElementType.Script;
|
|
40
|
+
/** Type for <style> tags */
|
|
41
|
+
export declare const Style = ElementType.Style;
|
|
42
|
+
/** Type for Any tag */
|
|
43
|
+
export declare const Tag = ElementType.Tag;
|
|
44
|
+
/** Type for <![CDATA[ ... ]]> */
|
|
45
|
+
export declare const CDATA = ElementType.CDATA;
|
|
46
|
+
/** Type for <!doctype ...> */
|
|
47
|
+
export declare const Doctype = ElementType.Doctype;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Doctype = exports.CDATA = exports.Tag = exports.Style = exports.Script = exports.Comment = exports.Directive = exports.Text = exports.Root = exports.isTag = exports.ElementType = void 0;
|
|
4
|
+
/** Types of elements found in htmlparser2's DOM */
|
|
5
|
+
var ElementType;
|
|
6
|
+
(function (ElementType) {
|
|
7
|
+
/** Type for the root element of a document */
|
|
8
|
+
ElementType["Root"] = "root";
|
|
9
|
+
/** Type for Text */
|
|
10
|
+
ElementType["Text"] = "text";
|
|
11
|
+
/** Type for <? ... ?> */
|
|
12
|
+
ElementType["Directive"] = "directive";
|
|
13
|
+
/** Type for <!-- ... --> */
|
|
14
|
+
ElementType["Comment"] = "comment";
|
|
15
|
+
/** Type for <script> tags */
|
|
16
|
+
ElementType["Script"] = "script";
|
|
17
|
+
/** Type for <style> tags */
|
|
18
|
+
ElementType["Style"] = "style";
|
|
19
|
+
/** Type for Any tag */
|
|
20
|
+
ElementType["Tag"] = "tag";
|
|
21
|
+
/** Type for <![CDATA[ ... ]]> */
|
|
22
|
+
ElementType["CDATA"] = "cdata";
|
|
23
|
+
/** Type for <!doctype ...> */
|
|
24
|
+
ElementType["Doctype"] = "doctype";
|
|
25
|
+
})(ElementType || (exports.ElementType = ElementType = {}));
|
|
26
|
+
/**
|
|
27
|
+
* Tests whether an element is a tag or not.
|
|
28
|
+
*
|
|
29
|
+
* @param elem Element to test
|
|
30
|
+
*/
|
|
31
|
+
function isTag(elem) {
|
|
32
|
+
return (elem.type === ElementType.Tag ||
|
|
33
|
+
elem.type === ElementType.Script ||
|
|
34
|
+
elem.type === ElementType.Style);
|
|
35
|
+
}
|
|
36
|
+
exports.isTag = isTag;
|
|
37
|
+
// Exports for backwards compatibility
|
|
38
|
+
/** Type for the root element of a document */
|
|
39
|
+
exports.Root = ElementType.Root;
|
|
40
|
+
/** Type for Text */
|
|
41
|
+
exports.Text = ElementType.Text;
|
|
42
|
+
/** Type for <? ... ?> */
|
|
43
|
+
exports.Directive = ElementType.Directive;
|
|
44
|
+
/** Type for <!-- ... --> */
|
|
45
|
+
exports.Comment = ElementType.Comment;
|
|
46
|
+
/** Type for <script> tags */
|
|
47
|
+
exports.Script = ElementType.Script;
|
|
48
|
+
/** Type for <style> tags */
|
|
49
|
+
exports.Style = ElementType.Style;
|
|
50
|
+
/** Type for Any tag */
|
|
51
|
+
exports.Tag = ElementType.Tag;
|
|
52
|
+
/** Type for <![CDATA[ ... ]]> */
|
|
53
|
+
exports.CDATA = ElementType.CDATA;
|
|
54
|
+
/** Type for <!doctype ...> */
|
|
55
|
+
exports.Doctype = ElementType.Doctype;
|