@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.
Files changed (114) hide show
  1. package/README.md +77 -1
  2. package/esm/client/4_client.js +1 -1
  3. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/DomHandler.d.ts +83 -0
  4. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/DomHandler.js +203 -0
  5. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/DomSerializer.d.ts +50 -0
  6. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/DomSerializer.js +274 -0
  7. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/ElementType.d.ts +47 -0
  8. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/ElementType.js +51 -0
  9. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/FeedHandler.d.ts +66 -0
  10. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/FeedHandler.js +191 -0
  11. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Node.d.ts +168 -0
  12. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Node.js +385 -0
  13. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Parser.d.ts +159 -0
  14. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Parser.js +431 -0
  15. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Tokenizer.d.ts +181 -0
  16. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Tokenizer.js +1046 -0
  17. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/mod.d.ts +42 -0
  18. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/mod.js +52 -0
  19. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode.d.ts +11 -0
  20. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode.js +122 -0
  21. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode_codepoint.d.ts +1 -0
  22. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode_codepoint.js +24 -0
  23. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/encode.d.ts +46 -0
  24. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/encode.js +121 -0
  25. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/decode.d.ts +31 -0
  26. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/decode.js +30 -0
  27. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/entities.d.ts +2128 -0
  28. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/entities.js +2127 -0
  29. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/legacy.d.ts +109 -0
  30. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/legacy.js +108 -0
  31. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/xml.d.ts +8 -0
  32. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/xml.js +1 -0
  33. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/mod.d.ts +90 -0
  34. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/mod.js +95 -0
  35. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/helpers.d.ts +50 -0
  36. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/helpers.js +128 -0
  37. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/legacy.d.ts +46 -0
  38. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/legacy.js +110 -0
  39. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/manipulation.d.ts +42 -0
  40. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/manipulation.js +120 -0
  41. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/mod.d.ts +6 -0
  42. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/mod.js +6 -0
  43. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/querying.d.ts +54 -0
  44. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/querying.js +110 -0
  45. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/stringify.d.ts +40 -0
  46. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/stringify.js +75 -0
  47. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/traversal.d.ts +58 -0
  48. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/traversal.js +101 -0
  49. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/deflate.d.ts +2 -0
  50. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/deflate.js +5 -1
  51. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/inflate.d.ts +2 -2
  52. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/inflate.js +5 -1
  53. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/zlib/crc32.js +1 -1
  54. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/zlib/deflate.js +8 -8
  55. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/zlib/inffast.js +2 -2
  56. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/zlib/inflate.js +19 -21
  57. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/zlib/trees.js +3 -3
  58. package/package.json +1 -1
  59. package/script/client/4_client.js +1 -1
  60. package/script/deps/deno.land/x/html_parser@v0.1.3/src/DomHandler.d.ts +83 -0
  61. package/script/deps/deno.land/x/html_parser@v0.1.3/src/DomHandler.js +207 -0
  62. package/script/deps/deno.land/x/html_parser@v0.1.3/src/DomSerializer.d.ts +50 -0
  63. package/script/deps/deno.land/x/html_parser@v0.1.3/src/DomSerializer.js +301 -0
  64. package/script/deps/deno.land/x/html_parser@v0.1.3/src/ElementType.d.ts +47 -0
  65. package/script/deps/deno.land/x/html_parser@v0.1.3/src/ElementType.js +55 -0
  66. package/script/deps/deno.land/x/html_parser@v0.1.3/src/FeedHandler.d.ts +66 -0
  67. package/script/deps/deno.land/x/html_parser@v0.1.3/src/FeedHandler.js +222 -0
  68. package/script/deps/deno.land/x/html_parser@v0.1.3/src/Node.d.ts +168 -0
  69. package/script/deps/deno.land/x/html_parser@v0.1.3/src/Node.js +404 -0
  70. package/script/deps/deno.land/x/html_parser@v0.1.3/src/Parser.d.ts +159 -0
  71. package/script/deps/deno.land/x/html_parser@v0.1.3/src/Parser.js +438 -0
  72. package/script/deps/deno.land/x/html_parser@v0.1.3/src/Tokenizer.d.ts +181 -0
  73. package/script/deps/deno.land/x/html_parser@v0.1.3/src/Tokenizer.js +1052 -0
  74. package/script/deps/deno.land/x/html_parser@v0.1.3/src/mod.d.ts +42 -0
  75. package/script/deps/deno.land/x/html_parser@v0.1.3/src/mod.js +88 -0
  76. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode.d.ts +11 -0
  77. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode.js +128 -0
  78. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode_codepoint.d.ts +1 -0
  79. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode_codepoint.js +30 -0
  80. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/encode.d.ts +46 -0
  81. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/encode.js +129 -0
  82. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/decode.d.ts +31 -0
  83. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/decode.js +32 -0
  84. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/entities.d.ts +2128 -0
  85. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/entities.js +2129 -0
  86. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/legacy.d.ts +109 -0
  87. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/legacy.js +110 -0
  88. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/xml.d.ts +8 -0
  89. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/xml.js +3 -0
  90. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/mod.d.ts +90 -0
  91. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/mod.js +114 -0
  92. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/helpers.d.ts +50 -0
  93. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/helpers.js +134 -0
  94. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/legacy.d.ts +46 -0
  95. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/legacy.js +118 -0
  96. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/manipulation.d.ts +42 -0
  97. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/manipulation.js +129 -0
  98. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/mod.d.ts +6 -0
  99. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/mod.js +22 -0
  100. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/querying.d.ts +54 -0
  101. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/querying.js +119 -0
  102. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/stringify.d.ts +40 -0
  103. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/stringify.js +86 -0
  104. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/traversal.d.ts +58 -0
  105. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/traversal.js +112 -0
  106. package/script/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/deflate.d.ts +2 -0
  107. package/script/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/deflate.js +7 -1
  108. package/script/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/inflate.d.ts +2 -2
  109. package/script/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/inflate.js +7 -1
  110. package/script/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/zlib/crc32.js +1 -1
  111. package/script/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/zlib/deflate.js +8 -8
  112. package/script/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/zlib/inffast.js +2 -2
  113. package/script/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/zlib/inflate.js +19 -21
  114. package/script/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/zlib/trees.js +3 -3
@@ -0,0 +1,404 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cloneNode = exports.hasChildren = exports.isDocument = exports.isDirective = exports.isComment = exports.isText = exports.isCDATA = exports.isTag = exports.Element = exports.Document = exports.NodeWithChildren = exports.ProcessingInstruction = exports.Comment = exports.Text = exports.DataNode = exports.Node = void 0;
4
+ const ElementType_js_1 = require("./ElementType.js");
5
+ const nodeTypes = new Map([
6
+ [ElementType_js_1.ElementType.Tag, 1],
7
+ [ElementType_js_1.ElementType.Script, 1],
8
+ [ElementType_js_1.ElementType.Style, 1],
9
+ [ElementType_js_1.ElementType.Directive, 1],
10
+ [ElementType_js_1.ElementType.Text, 3],
11
+ [ElementType_js_1.ElementType.CDATA, 4],
12
+ [ElementType_js_1.ElementType.Comment, 8],
13
+ [ElementType_js_1.ElementType.Root, 9],
14
+ ]);
15
+ /**
16
+ * This object will be used as the prototype for Nodes when creating a
17
+ * DOM-Level-1-compliant structure.
18
+ */
19
+ class Node {
20
+ /**
21
+ *
22
+ * @param type The type of the node.
23
+ */
24
+ constructor(type) {
25
+ Object.defineProperty(this, "type", {
26
+ enumerable: true,
27
+ configurable: true,
28
+ writable: true,
29
+ value: type
30
+ });
31
+ /** Parent of the node */
32
+ Object.defineProperty(this, "parent", {
33
+ enumerable: true,
34
+ configurable: true,
35
+ writable: true,
36
+ value: null
37
+ });
38
+ /** Previous sibling */
39
+ Object.defineProperty(this, "prev", {
40
+ enumerable: true,
41
+ configurable: true,
42
+ writable: true,
43
+ value: null
44
+ });
45
+ /** Next sibling */
46
+ Object.defineProperty(this, "next", {
47
+ enumerable: true,
48
+ configurable: true,
49
+ writable: true,
50
+ value: null
51
+ });
52
+ /** The start index of the node. Requires `withStartIndices` on the handler to be `true. */
53
+ Object.defineProperty(this, "startIndex", {
54
+ enumerable: true,
55
+ configurable: true,
56
+ writable: true,
57
+ value: null
58
+ });
59
+ /** The end index of the node. Requires `withEndIndices` on the handler to be `true. */
60
+ Object.defineProperty(this, "endIndex", {
61
+ enumerable: true,
62
+ configurable: true,
63
+ writable: true,
64
+ value: null
65
+ });
66
+ }
67
+ // Read-only aliases
68
+ get nodeType() {
69
+ return nodeTypes.get(this.type) ?? 1;
70
+ }
71
+ // Read-write aliases for properties
72
+ get parentNode() {
73
+ return this.parent;
74
+ }
75
+ set parentNode(parent) {
76
+ this.parent = parent;
77
+ }
78
+ get previousSibling() {
79
+ return this.prev;
80
+ }
81
+ set previousSibling(prev) {
82
+ this.prev = prev;
83
+ }
84
+ get nextSibling() {
85
+ return this.next;
86
+ }
87
+ set nextSibling(next) {
88
+ this.next = next;
89
+ }
90
+ /**
91
+ * Clone this node, and optionally its children.
92
+ *
93
+ * @param recursive Clone child nodes as well.
94
+ * @returns A clone of the node.
95
+ */
96
+ cloneNode(recursive = false) {
97
+ return cloneNode(this, recursive);
98
+ }
99
+ }
100
+ exports.Node = Node;
101
+ /**
102
+ * A node that contains some data.
103
+ */
104
+ class DataNode extends Node {
105
+ /**
106
+ * @param type The type of the node
107
+ * @param data The content of the data node
108
+ */
109
+ constructor(type, data) {
110
+ super(type);
111
+ Object.defineProperty(this, "data", {
112
+ enumerable: true,
113
+ configurable: true,
114
+ writable: true,
115
+ value: data
116
+ });
117
+ }
118
+ get nodeValue() {
119
+ return this.data;
120
+ }
121
+ set nodeValue(data) {
122
+ this.data = data;
123
+ }
124
+ }
125
+ exports.DataNode = DataNode;
126
+ /**
127
+ * Text within the document.
128
+ */
129
+ class Text extends DataNode {
130
+ constructor(data) {
131
+ super(ElementType_js_1.ElementType.Text, data);
132
+ }
133
+ }
134
+ exports.Text = Text;
135
+ /**
136
+ * Comments within the document.
137
+ */
138
+ class Comment extends DataNode {
139
+ constructor(data) {
140
+ super(ElementType_js_1.ElementType.Comment, data);
141
+ }
142
+ }
143
+ exports.Comment = Comment;
144
+ /**
145
+ * Processing instructions, including doc types.
146
+ */
147
+ class ProcessingInstruction extends DataNode {
148
+ constructor(name, data) {
149
+ super(ElementType_js_1.ElementType.Directive, data);
150
+ Object.defineProperty(this, "name", {
151
+ enumerable: true,
152
+ configurable: true,
153
+ writable: true,
154
+ value: name
155
+ });
156
+ Object.defineProperty(this, 'x-name', {
157
+ enumerable: true,
158
+ configurable: true,
159
+ writable: true,
160
+ value: void 0
161
+ });
162
+ Object.defineProperty(this, 'x-publicId', {
163
+ enumerable: true,
164
+ configurable: true,
165
+ writable: true,
166
+ value: void 0
167
+ });
168
+ Object.defineProperty(this, 'x-systemId', {
169
+ enumerable: true,
170
+ configurable: true,
171
+ writable: true,
172
+ value: void 0
173
+ });
174
+ }
175
+ }
176
+ exports.ProcessingInstruction = ProcessingInstruction;
177
+ /**
178
+ * A `Node` that can have children.
179
+ */
180
+ class NodeWithChildren extends Node {
181
+ /**
182
+ * @param type Type of the node.
183
+ * @param children Children of the node. Only certain node types can have children.
184
+ */
185
+ constructor(type, children) {
186
+ super(type);
187
+ Object.defineProperty(this, "children", {
188
+ enumerable: true,
189
+ configurable: true,
190
+ writable: true,
191
+ value: children
192
+ });
193
+ }
194
+ // Aliases
195
+ get firstChild() {
196
+ return this.children[0] ?? null;
197
+ }
198
+ get lastChild() {
199
+ return this.children.length > 0
200
+ ? this.children[this.children.length - 1]
201
+ : null;
202
+ }
203
+ get childNodes() {
204
+ return this.children;
205
+ }
206
+ set childNodes(children) {
207
+ this.children = children;
208
+ }
209
+ }
210
+ exports.NodeWithChildren = NodeWithChildren;
211
+ /**
212
+ * The root node of the document.
213
+ */
214
+ class Document extends NodeWithChildren {
215
+ constructor(children) {
216
+ super(ElementType_js_1.ElementType.Root, children);
217
+ Object.defineProperty(this, 'x-mode', {
218
+ enumerable: true,
219
+ configurable: true,
220
+ writable: true,
221
+ value: void 0
222
+ });
223
+ }
224
+ }
225
+ exports.Document = Document;
226
+ /**
227
+ * An element within the DOM.
228
+ */
229
+ class Element extends NodeWithChildren {
230
+ /**
231
+ * @param name Name of the tag, eg. `div`, `span`.
232
+ * @param attribs Object mapping attribute names to attribute values.
233
+ * @param children Children of the node.
234
+ */
235
+ constructor(name, attribs, children = [], type = name === 'script'
236
+ ? ElementType_js_1.ElementType.Script
237
+ : name === 'style'
238
+ ? ElementType_js_1.ElementType.Style
239
+ : ElementType_js_1.ElementType.Tag) {
240
+ super(type, children);
241
+ Object.defineProperty(this, "name", {
242
+ enumerable: true,
243
+ configurable: true,
244
+ writable: true,
245
+ value: name
246
+ });
247
+ Object.defineProperty(this, "attribs", {
248
+ enumerable: true,
249
+ configurable: true,
250
+ writable: true,
251
+ value: attribs
252
+ });
253
+ Object.defineProperty(this, 'x-attribsNamespace', {
254
+ enumerable: true,
255
+ configurable: true,
256
+ writable: true,
257
+ value: void 0
258
+ });
259
+ Object.defineProperty(this, 'x-attribsPrefix', {
260
+ enumerable: true,
261
+ configurable: true,
262
+ writable: true,
263
+ value: void 0
264
+ });
265
+ }
266
+ // DOM Level 1 aliases
267
+ get tagName() {
268
+ return this.name;
269
+ }
270
+ set tagName(name) {
271
+ this.name = name;
272
+ }
273
+ get attributes() {
274
+ return Object.keys(this.attribs).map(name => ({
275
+ name,
276
+ value: this.attribs[name],
277
+ namespace: this['x-attribsNamespace']?.[name],
278
+ prefix: this['x-attribsPrefix']?.[name],
279
+ }));
280
+ }
281
+ }
282
+ exports.Element = Element;
283
+ /**
284
+ * @param node Node to check.
285
+ * @returns `true` if the node is a `Element`, `false` otherwise.
286
+ */
287
+ function isTag(node) {
288
+ return (0, ElementType_js_1.isTag)(node);
289
+ }
290
+ exports.isTag = isTag;
291
+ /**
292
+ * @param node Node to check.
293
+ * @returns `true` if the node has the type `CDATA`, `false` otherwise.
294
+ */
295
+ function isCDATA(node) {
296
+ return node.type === ElementType_js_1.ElementType.CDATA;
297
+ }
298
+ exports.isCDATA = isCDATA;
299
+ /**
300
+ * @param node Node to check.
301
+ * @returns `true` if the node has the type `Text`, `false` otherwise.
302
+ */
303
+ function isText(node) {
304
+ return node.type === ElementType_js_1.ElementType.Text;
305
+ }
306
+ exports.isText = isText;
307
+ /**
308
+ * @param node Node to check.
309
+ * @returns `true` if the node has the type `Comment`, `false` otherwise.
310
+ */
311
+ function isComment(node) {
312
+ return node.type === ElementType_js_1.ElementType.Comment;
313
+ }
314
+ exports.isComment = isComment;
315
+ /**
316
+ * @param node Node to check.
317
+ * @returns `true` if the node has the type `ProcessingInstruction`, `false` otherwise.
318
+ */
319
+ function isDirective(node) {
320
+ return node.type === ElementType_js_1.ElementType.Directive;
321
+ }
322
+ exports.isDirective = isDirective;
323
+ /**
324
+ * @param node Node to check.
325
+ * @returns `true` if the node has the type `ProcessingInstruction`, `false` otherwise.
326
+ */
327
+ function isDocument(node) {
328
+ return node.type === ElementType_js_1.ElementType.Root;
329
+ }
330
+ exports.isDocument = isDocument;
331
+ /**
332
+ * @param node Node to check.
333
+ * @returns `true` if the node is a `NodeWithChildren` (has children), `false` otherwise.
334
+ */
335
+ function hasChildren(node) {
336
+ return Object.prototype.hasOwnProperty.call(node, 'children');
337
+ }
338
+ exports.hasChildren = hasChildren;
339
+ /**
340
+ * Clone a node, and optionally its children.
341
+ *
342
+ * @param recursive Clone child nodes as well.
343
+ * @returns A clone of the node.
344
+ */
345
+ function cloneNode(node, recursive = false) {
346
+ let result;
347
+ if (isText(node)) {
348
+ result = new Text(node.data);
349
+ }
350
+ else if (isComment(node)) {
351
+ result = new Comment(node.data);
352
+ }
353
+ else if (isTag(node)) {
354
+ const children = recursive ? cloneChildren(node.children) : [];
355
+ const clone = new Element(node.name, { ...node.attribs }, children);
356
+ children.forEach(child => (child.parent = clone));
357
+ if (node['x-attribsNamespace']) {
358
+ clone['x-attribsNamespace'] = { ...node['x-attribsNamespace'] };
359
+ }
360
+ if (node['x-attribsPrefix']) {
361
+ clone['x-attribsPrefix'] = { ...node['x-attribsPrefix'] };
362
+ }
363
+ result = clone;
364
+ }
365
+ else if (isCDATA(node)) {
366
+ const children = recursive ? cloneChildren(node.children) : [];
367
+ const clone = new NodeWithChildren(ElementType_js_1.ElementType.CDATA, children);
368
+ children.forEach(child => (child.parent = clone));
369
+ result = clone;
370
+ }
371
+ else if (isDocument(node)) {
372
+ const children = recursive ? cloneChildren(node.children) : [];
373
+ const clone = new Document(children);
374
+ children.forEach(child => (child.parent = clone));
375
+ if (node['x-mode']) {
376
+ clone['x-mode'] = node['x-mode'];
377
+ }
378
+ result = clone;
379
+ }
380
+ else if (isDirective(node)) {
381
+ const instruction = new ProcessingInstruction(node.name, node.data);
382
+ if (node['x-name'] != null) {
383
+ instruction['x-name'] = node['x-name'];
384
+ instruction['x-publicId'] = node['x-publicId'];
385
+ instruction['x-systemId'] = node['x-systemId'];
386
+ }
387
+ result = instruction;
388
+ }
389
+ else {
390
+ throw new Error(`Not implemented yet: ${node.type}`);
391
+ }
392
+ result.startIndex = node.startIndex;
393
+ result.endIndex = node.endIndex;
394
+ return result;
395
+ }
396
+ exports.cloneNode = cloneNode;
397
+ function cloneChildren(childs) {
398
+ const children = childs.map(child => cloneNode(child, true));
399
+ for (let i = 1; i < children.length; i++) {
400
+ children[i].prev = children[i - 1];
401
+ children[i - 1].next = children[i];
402
+ }
403
+ return children;
404
+ }
@@ -0,0 +1,159 @@
1
+ import Tokenizer from './Tokenizer.js';
2
+ export interface ParserOptions {
3
+ /**
4
+ * Indicates whether special tags (`<script>`, `<style>`, and `<title>`) should get special treatment
5
+ * and if "empty" tags (eg. `<br>`) can have children. If `false`, the content of special tags
6
+ * will be text only. For feeds and other XML content (documents that don't consist of HTML),
7
+ * set this to `true`.
8
+ *
9
+ * @default false
10
+ */
11
+ xmlMode?: boolean;
12
+ /**
13
+ * Decode entities within the document.
14
+ *
15
+ * @default true
16
+ */
17
+ decodeEntities?: boolean;
18
+ /**
19
+ * If set to true, all tags will be lowercased.
20
+ *
21
+ * @default !xmlMode
22
+ */
23
+ lowerCaseTags?: boolean;
24
+ /**
25
+ * If set to `true`, all attribute names will be lowercased. This has noticeable impact on speed.
26
+ *
27
+ * @default !xmlMode
28
+ */
29
+ lowerCaseAttributeNames?: boolean;
30
+ /**
31
+ * If set to true, CDATA sections will be recognized as text even if the xmlMode option is not enabled.
32
+ * NOTE: If xmlMode is set to `true` then CDATA sections will always be recognized as text.
33
+ *
34
+ * @default xmlMode
35
+ */
36
+ recognizeCDATA?: boolean;
37
+ /**
38
+ * If set to `true`, self-closing tags will trigger the onclosetag event even if xmlMode is not set to `true`.
39
+ * NOTE: If xmlMode is set to `true` then self-closing tags will always be recognized.
40
+ *
41
+ * @default xmlMode
42
+ */
43
+ recognizeSelfClosing?: boolean;
44
+ /**
45
+ * Allows the default tokenizer to be overwritten.
46
+ */
47
+ Tokenizer?: typeof Tokenizer;
48
+ }
49
+ export interface Handler {
50
+ onparserinit(parser: Parser): void;
51
+ /**
52
+ * Resets the handler back to starting state
53
+ */
54
+ onreset(): void;
55
+ /**
56
+ * Signals the handler that parsing is done
57
+ */
58
+ onend(): void;
59
+ onerror(error: Error): void;
60
+ onclosetag(name: string): void;
61
+ onopentagname(name: string): void;
62
+ /**
63
+ *
64
+ * @param name Name of the attribute
65
+ * @param value Value of the attribute.
66
+ * @param quote Quotes used around the attribute. `null` if the attribute has no quotes around the value, `undefined` if the attribute has no value.
67
+ */
68
+ onattribute(name: string, value: string, quote?: string | undefined | null): void;
69
+ onopentag(name: string, attribs: {
70
+ [s: string]: string;
71
+ }): void;
72
+ ontext(data: string): void;
73
+ oncomment(data: string): void;
74
+ oncdatastart(): void;
75
+ oncdataend(): void;
76
+ oncommentend(): void;
77
+ onprocessinginstruction(name: string, data: string): void;
78
+ }
79
+ export declare class Parser {
80
+ /** The start index of the last event. */
81
+ startIndex: number;
82
+ /** The end index of the last event. */
83
+ endIndex: number | null;
84
+ private tagname;
85
+ private attribname;
86
+ private attribvalue;
87
+ private attribs;
88
+ private stack;
89
+ private readonly foreignContext;
90
+ private readonly cbs;
91
+ private readonly options;
92
+ private readonly lowerCaseTagNames;
93
+ private readonly lowerCaseAttributeNames;
94
+ private readonly tokenizer;
95
+ constructor(cbs: Partial<Handler> | null, options?: ParserOptions);
96
+ private updatePosition;
97
+ ontext(data: string): void;
98
+ isVoidElement(name: string): boolean;
99
+ onopentagname(name: string): void;
100
+ onopentagend(): void;
101
+ onclosetag(name: string): void;
102
+ onselfclosingtag(): void;
103
+ private closeCurrentTag;
104
+ onattribname(name: string): void;
105
+ onattribdata(value: string): void;
106
+ onattribend(quote: string | undefined | null): void;
107
+ private getInstructionName;
108
+ ondeclaration(value: string): void;
109
+ onprocessinginstruction(value: string): void;
110
+ oncomment(value: string): void;
111
+ oncdata(value: string): void;
112
+ onerror(err: Error): void;
113
+ onend(): void;
114
+ /**
115
+ * Resets the parser to a blank state, ready to parse a new HTML document
116
+ */
117
+ reset(): void;
118
+ /**
119
+ * Resets the parser, then parses a complete document and
120
+ * pushes it to the handler.
121
+ *
122
+ * @param data Document to parse.
123
+ */
124
+ parseComplete(data: string): void;
125
+ /**
126
+ * Parses a chunk of data and calls the corresponding callbacks.
127
+ *
128
+ * @param chunk Chunk to parse.
129
+ */
130
+ write(chunk: string): void;
131
+ /**
132
+ * Parses the end of the buffer and clears the stack, calls onend.
133
+ *
134
+ * @param chunk Optional final chunk to parse.
135
+ */
136
+ end(chunk?: string): void;
137
+ /**
138
+ * Pauses parsing. The parser won't emit events until `resume` is called.
139
+ */
140
+ pause(): void;
141
+ /**
142
+ * Resumes parsing after `pause` was called.
143
+ */
144
+ resume(): void;
145
+ /**
146
+ * Alias of `write`, for backwards compatibility.
147
+ *
148
+ * @param chunk Chunk to parse.
149
+ * @deprecated
150
+ */
151
+ parseChunk(chunk: string): void;
152
+ /**
153
+ * Alias of `end`, for backwards compatibility.
154
+ *
155
+ * @param chunk Optional final chunk to parse.
156
+ * @deprecated
157
+ */
158
+ done(chunk?: string): void;
159
+ }