@mavogel/cdk-vscode-server 0.0.123 → 0.0.124

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 (88) hide show
  1. package/.jsii +3 -3
  2. package/lib/idle-monitor/idle-monitor.js +1 -1
  3. package/lib/vscode-server.js +1 -1
  4. package/node_modules/node-html-parser/CHANGELOG.md +79 -0
  5. package/node_modules/node-html-parser/README.md +39 -39
  6. package/node_modules/node-html-parser/dist/index.cjs +5079 -0
  7. package/node_modules/node-html-parser/dist/index.d.ts +10 -10
  8. package/node_modules/node-html-parser/dist/index.mjs +5068 -0
  9. package/node_modules/node-html-parser/dist/index.umd.js +5083 -0
  10. package/node_modules/node-html-parser/dist/matcher.d.ts +22 -6
  11. package/node_modules/node-html-parser/dist/nodes/comment.d.ts +1 -1
  12. package/node_modules/node-html-parser/dist/nodes/html.d.ts +2 -2
  13. package/node_modules/node-html-parser/dist/nodes/node.d.ts +2 -2
  14. package/node_modules/node-html-parser/dist/nodes/text.d.ts +1 -1
  15. package/node_modules/node-html-parser/dist/valid.d.ts +1 -1
  16. package/node_modules/node-html-parser/node_modules/entities/LICENSE +11 -0
  17. package/node_modules/node-html-parser/node_modules/entities/dist/decode-codepoint.d.ts +28 -0
  18. package/node_modules/node-html-parser/node_modules/entities/dist/decode-codepoint.d.ts.map +1 -0
  19. package/node_modules/node-html-parser/node_modules/entities/dist/decode-codepoint.js +61 -0
  20. package/node_modules/node-html-parser/node_modules/entities/dist/decode-codepoint.js.map +1 -0
  21. package/node_modules/node-html-parser/node_modules/entities/dist/decode.d.ts +227 -0
  22. package/node_modules/node-html-parser/node_modules/entities/dist/decode.d.ts.map +1 -0
  23. package/node_modules/node-html-parser/node_modules/entities/dist/decode.js +1132 -0
  24. package/node_modules/node-html-parser/node_modules/entities/dist/decode.js.map +1 -0
  25. package/node_modules/node-html-parser/node_modules/entities/dist/encode.d.ts +26 -0
  26. package/node_modules/node-html-parser/node_modules/entities/dist/encode.d.ts.map +1 -0
  27. package/node_modules/node-html-parser/node_modules/entities/dist/encode.js +295 -0
  28. package/node_modules/node-html-parser/node_modules/entities/dist/encode.js.map +1 -0
  29. package/node_modules/node-html-parser/node_modules/entities/dist/escape.d.ts +60 -0
  30. package/node_modules/node-html-parser/node_modules/entities/dist/escape.d.ts.map +1 -0
  31. package/node_modules/node-html-parser/node_modules/entities/dist/escape.js +172 -0
  32. package/node_modules/node-html-parser/node_modules/entities/dist/escape.js.map +1 -0
  33. package/node_modules/node-html-parser/node_modules/entities/dist/generated/decode-data-html.d.ts +3 -0
  34. package/node_modules/node-html-parser/node_modules/entities/dist/generated/decode-data-html.d.ts.map +1 -0
  35. package/node_modules/node-html-parser/node_modules/entities/dist/generated/decode-data-html.js +5 -0
  36. package/node_modules/node-html-parser/node_modules/entities/dist/generated/decode-data-html.js.map +1 -0
  37. package/node_modules/node-html-parser/node_modules/entities/dist/generated/decode-data-xml.d.ts +3 -0
  38. package/node_modules/node-html-parser/node_modules/entities/dist/generated/decode-data-xml.d.ts.map +1 -0
  39. package/node_modules/node-html-parser/node_modules/entities/dist/generated/decode-data-xml.js +7 -0
  40. package/node_modules/node-html-parser/node_modules/entities/dist/generated/decode-data-xml.js.map +1 -0
  41. package/node_modules/node-html-parser/node_modules/entities/dist/generated/encode-html.d.ts +3 -0
  42. package/node_modules/node-html-parser/node_modules/entities/dist/generated/encode-html.d.ts.map +1 -0
  43. package/node_modules/node-html-parser/node_modules/entities/dist/generated/encode-html.js +3 -0
  44. package/node_modules/node-html-parser/node_modules/entities/dist/generated/encode-html.js.map +1 -0
  45. package/node_modules/node-html-parser/node_modules/entities/dist/index.d.ts +89 -0
  46. package/node_modules/node-html-parser/node_modules/entities/dist/index.d.ts.map +1 -0
  47. package/node_modules/node-html-parser/node_modules/entities/dist/index.js +87 -0
  48. package/node_modules/node-html-parser/node_modules/entities/dist/index.js.map +1 -0
  49. package/node_modules/node-html-parser/node_modules/entities/dist/internal/bin-trie-flags.d.ts +48 -0
  50. package/node_modules/node-html-parser/node_modules/entities/dist/internal/bin-trie-flags.d.ts.map +1 -0
  51. package/node_modules/node-html-parser/node_modules/entities/dist/internal/bin-trie-flags.js +49 -0
  52. package/node_modules/node-html-parser/node_modules/entities/dist/internal/bin-trie-flags.js.map +1 -0
  53. package/node_modules/node-html-parser/node_modules/entities/dist/internal/decode-shared.d.ts +38 -0
  54. package/node_modules/node-html-parser/node_modules/entities/dist/internal/decode-shared.d.ts.map +1 -0
  55. package/node_modules/node-html-parser/node_modules/entities/dist/internal/decode-shared.js +195 -0
  56. package/node_modules/node-html-parser/node_modules/entities/dist/internal/decode-shared.js.map +1 -0
  57. package/node_modules/node-html-parser/node_modules/entities/package.json +83 -0
  58. package/node_modules/node-html-parser/node_modules/entities/readme.md +131 -0
  59. package/node_modules/node-html-parser/node_modules/entities/src/decode-codepoint.ts +69 -0
  60. package/node_modules/node-html-parser/node_modules/entities/src/decode.ts +1368 -0
  61. package/node_modules/node-html-parser/node_modules/entities/src/encode.ts +337 -0
  62. package/node_modules/node-html-parser/node_modules/entities/src/escape.ts +187 -0
  63. package/node_modules/node-html-parser/node_modules/entities/src/generated/decode-data-html.ts +12 -0
  64. package/node_modules/node-html-parser/node_modules/entities/src/generated/decode-data-xml.ts +7 -0
  65. package/node_modules/node-html-parser/node_modules/entities/src/generated/encode-html.ts +3 -0
  66. package/node_modules/node-html-parser/node_modules/entities/src/index.ts +160 -0
  67. package/node_modules/node-html-parser/node_modules/entities/src/internal/bin-trie-flags.ts +47 -0
  68. package/node_modules/node-html-parser/node_modules/entities/src/internal/decode-shared.ts +209 -0
  69. package/node_modules/node-html-parser/package.json +35 -30
  70. package/package.json +3 -3
  71. package/node_modules/he/LICENSE-MIT.txt +0 -20
  72. package/node_modules/he/README.md +0 -379
  73. package/node_modules/he/bin/he +0 -148
  74. package/node_modules/he/he.js +0 -345
  75. package/node_modules/he/man/he.1 +0 -78
  76. package/node_modules/he/package.json +0 -58
  77. package/node_modules/node-html-parser/dist/back.js +0 -6
  78. package/node_modules/node-html-parser/dist/index.js +0 -31
  79. package/node_modules/node-html-parser/dist/main.js +0 -1804
  80. package/node_modules/node-html-parser/dist/matcher.js +0 -106
  81. package/node_modules/node-html-parser/dist/nodes/comment.js +0 -33
  82. package/node_modules/node-html-parser/dist/nodes/html.js +0 -1186
  83. package/node_modules/node-html-parser/dist/nodes/node.js +0 -41
  84. package/node_modules/node-html-parser/dist/nodes/text.js +0 -105
  85. package/node_modules/node-html-parser/dist/nodes/type.js +0 -9
  86. package/node_modules/node-html-parser/dist/parse.js +0 -5
  87. package/node_modules/node-html-parser/dist/valid.js +0 -12
  88. package/node_modules/node-html-parser/dist/void-tag.js +0 -27
@@ -1,1804 +0,0 @@
1
- var __importDefault = (this && this.__importDefault) || function (mod) {
2
- return (mod && mod.__esModule) ? mod : { "default": mod };
3
- };
4
- var __extends = (this && this.__extends) || (function () {
5
- var extendStatics = function (d, b) {
6
- extendStatics = Object.setPrototypeOf ||
7
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
8
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
9
- return extendStatics(d, b);
10
- };
11
- return function (d, b) {
12
- if (typeof b !== "function" && b !== null)
13
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
14
- extendStatics(d, b);
15
- function __() { this.constructor = d; }
16
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
17
- };
18
- })();
19
- var __assign = (this && this.__assign) || function () {
20
- __assign = Object.assign || function(t) {
21
- for (var s, i = 1, n = arguments.length; i < n; i++) {
22
- s = arguments[i];
23
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
24
- t[p] = s[p];
25
- }
26
- return t;
27
- };
28
- return __assign.apply(this, arguments);
29
- };
30
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
31
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
32
- if (ar || !(i in from)) {
33
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
34
- ar[i] = from[i];
35
- }
36
- }
37
- return to.concat(ar || Array.prototype.slice.call(from));
38
- };
39
- define("back", ["require", "exports"], function (require, exports) {
40
- "use strict";
41
- Object.defineProperty(exports, "__esModule", { value: true });
42
- function arr_back(arr) {
43
- return arr[arr.length - 1];
44
- }
45
- exports.default = arr_back;
46
- });
47
- define("nodes/type", ["require", "exports"], function (require, exports) {
48
- "use strict";
49
- Object.defineProperty(exports, "__esModule", { value: true });
50
- var NodeType;
51
- (function (NodeType) {
52
- NodeType[NodeType["ELEMENT_NODE"] = 1] = "ELEMENT_NODE";
53
- NodeType[NodeType["TEXT_NODE"] = 3] = "TEXT_NODE";
54
- NodeType[NodeType["COMMENT_NODE"] = 8] = "COMMENT_NODE";
55
- })(NodeType || (NodeType = {}));
56
- exports.default = NodeType;
57
- });
58
- define("nodes/node", ["require", "exports", "he"], function (require, exports, he_1) {
59
- "use strict";
60
- Object.defineProperty(exports, "__esModule", { value: true });
61
- /**
62
- * Node Class as base class for TextNode and HTMLElement.
63
- */
64
- var Node = /** @class */ (function () {
65
- function Node(parentNode, range) {
66
- if (parentNode === void 0) { parentNode = null; }
67
- this.parentNode = parentNode;
68
- this.childNodes = [];
69
- Object.defineProperty(this, 'range', {
70
- enumerable: false,
71
- writable: true,
72
- configurable: true,
73
- value: range !== null && range !== void 0 ? range : [-1, -1]
74
- });
75
- }
76
- /**
77
- * Remove current node
78
- */
79
- Node.prototype.remove = function () {
80
- var _this = this;
81
- if (this.parentNode) {
82
- var children = this.parentNode.childNodes;
83
- this.parentNode.childNodes = children.filter(function (child) {
84
- return _this !== child;
85
- });
86
- this.parentNode = null;
87
- }
88
- return this;
89
- };
90
- Object.defineProperty(Node.prototype, "innerText", {
91
- get: function () {
92
- return this.rawText;
93
- },
94
- enumerable: false,
95
- configurable: true
96
- });
97
- Object.defineProperty(Node.prototype, "textContent", {
98
- get: function () {
99
- return (0, he_1.decode)(this.rawText);
100
- },
101
- set: function (val) {
102
- this.rawText = (0, he_1.encode)(val);
103
- },
104
- enumerable: false,
105
- configurable: true
106
- });
107
- return Node;
108
- }());
109
- exports.default = Node;
110
- });
111
- define("matcher", ["require", "exports", "nodes/type"], function (require, exports, type_1) {
112
- "use strict";
113
- Object.defineProperty(exports, "__esModule", { value: true });
114
- type_1 = __importDefault(type_1);
115
- function isTag(node) {
116
- return node && node.nodeType === type_1.default.ELEMENT_NODE;
117
- }
118
- function getAttributeValue(elem, name) {
119
- return isTag(elem) ? elem.getAttribute(name) : undefined;
120
- }
121
- function getName(elem) {
122
- return ((elem && elem.rawTagName) || '').toLowerCase();
123
- }
124
- function getChildren(node) {
125
- return node && node.childNodes;
126
- }
127
- function getParent(node) {
128
- return node ? node.parentNode : null;
129
- }
130
- function getText(node) {
131
- return node.text;
132
- }
133
- function removeSubsets(nodes) {
134
- var idx = nodes.length;
135
- var node;
136
- var ancestor;
137
- var replace;
138
- // Check if each node (or one of its ancestors) is already contained in the
139
- // array.
140
- while (--idx > -1) {
141
- node = ancestor = nodes[idx];
142
- // Temporarily remove the node under consideration
143
- nodes[idx] = null;
144
- replace = true;
145
- while (ancestor) {
146
- if (nodes.indexOf(ancestor) > -1) {
147
- replace = false;
148
- nodes.splice(idx, 1);
149
- break;
150
- }
151
- ancestor = getParent(ancestor);
152
- }
153
- // If the node has been found to be unique, re-insert it.
154
- if (replace) {
155
- nodes[idx] = node;
156
- }
157
- }
158
- return nodes;
159
- }
160
- function existsOne(test, elems) {
161
- return elems.some(function (elem) {
162
- return isTag(elem) ? test(elem) || existsOne(test, getChildren(elem)) : false;
163
- });
164
- }
165
- function getSiblings(node) {
166
- var parent = getParent(node);
167
- return parent ? getChildren(parent) : [];
168
- }
169
- function hasAttrib(elem, name) {
170
- return getAttributeValue(elem, name) !== undefined;
171
- }
172
- function findOne(test, elems) {
173
- var elem = null;
174
- for (var i = 0, l = elems === null || elems === void 0 ? void 0 : elems.length; i < l && !elem; i++) {
175
- var el = elems[i];
176
- if (test(el)) {
177
- elem = el;
178
- }
179
- else {
180
- var childs = getChildren(el);
181
- if (childs && childs.length > 0) {
182
- elem = findOne(test, childs);
183
- }
184
- }
185
- }
186
- return elem;
187
- }
188
- function findAll(test, nodes) {
189
- var result = [];
190
- for (var i = 0, j = nodes.length; i < j; i++) {
191
- if (!isTag(nodes[i]))
192
- continue;
193
- if (test(nodes[i]))
194
- result.push(nodes[i]);
195
- var childs = getChildren(nodes[i]);
196
- if (childs)
197
- result = result.concat(findAll(test, childs));
198
- }
199
- return result;
200
- }
201
- exports.default = {
202
- isTag: isTag,
203
- getAttributeValue: getAttributeValue,
204
- getName: getName,
205
- getChildren: getChildren,
206
- getParent: getParent,
207
- getText: getText,
208
- removeSubsets: removeSubsets,
209
- existsOne: existsOne,
210
- getSiblings: getSiblings,
211
- hasAttrib: hasAttrib,
212
- findOne: findOne,
213
- findAll: findAll
214
- };
215
- });
216
- define("void-tag", ["require", "exports"], function (require, exports) {
217
- "use strict";
218
- Object.defineProperty(exports, "__esModule", { value: true });
219
- var VoidTag = /** @class */ (function () {
220
- function VoidTag(addClosingSlash, tags) {
221
- if (addClosingSlash === void 0) { addClosingSlash = false; }
222
- this.addClosingSlash = addClosingSlash;
223
- if (Array.isArray(tags)) {
224
- this.voidTags = tags.reduce(function (set, tag) {
225
- return set.add(tag.toLowerCase()).add(tag.toUpperCase()).add(tag);
226
- }, new Set());
227
- }
228
- else {
229
- this.voidTags = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'].reduce(function (set, tag) {
230
- return set.add(tag.toLowerCase()).add(tag.toUpperCase()).add(tag);
231
- }, new Set());
232
- }
233
- }
234
- VoidTag.prototype.formatNode = function (tag, attrs, innerHTML) {
235
- var addClosingSlash = this.addClosingSlash;
236
- var closingSpace = (addClosingSlash && attrs && !attrs.endsWith(' ')) ? ' ' : '';
237
- var closingSlash = addClosingSlash ? "".concat(closingSpace, "/") : '';
238
- return this.isVoidElement(tag.toLowerCase()) ? "<".concat(tag).concat(attrs).concat(closingSlash, ">") : "<".concat(tag).concat(attrs, ">").concat(innerHTML, "</").concat(tag, ">");
239
- };
240
- VoidTag.prototype.isVoidElement = function (tag) {
241
- return this.voidTags.has(tag);
242
- };
243
- return VoidTag;
244
- }());
245
- exports.default = VoidTag;
246
- });
247
- define("nodes/text", ["require", "exports", "he", "nodes/node", "nodes/type"], function (require, exports, he_2, node_1, type_2) {
248
- "use strict";
249
- Object.defineProperty(exports, "__esModule", { value: true });
250
- node_1 = __importDefault(node_1);
251
- type_2 = __importDefault(type_2);
252
- /**
253
- * TextNode to contain a text element in DOM tree.
254
- * @param {string} value [description]
255
- */
256
- var TextNode = /** @class */ (function (_super) {
257
- __extends(TextNode, _super);
258
- function TextNode(rawText, parentNode, range) {
259
- if (parentNode === void 0) { parentNode = null; }
260
- var _this = _super.call(this, parentNode, range) || this;
261
- /**
262
- * Node Type declaration.
263
- * @type {Number}
264
- */
265
- _this.nodeType = type_2.default.TEXT_NODE;
266
- _this.rawTagName = '';
267
- _this._rawText = rawText;
268
- return _this;
269
- }
270
- TextNode.prototype.clone = function () {
271
- return new TextNode(this._rawText, null);
272
- };
273
- Object.defineProperty(TextNode.prototype, "rawText", {
274
- get: function () {
275
- return this._rawText;
276
- },
277
- /**
278
- * Set rawText and invalidate trimmed caches
279
- */
280
- set: function (text) {
281
- this._rawText = text;
282
- this._trimmedRawText = void 0;
283
- this._trimmedText = void 0;
284
- },
285
- enumerable: false,
286
- configurable: true
287
- });
288
- Object.defineProperty(TextNode.prototype, "trimmedRawText", {
289
- /**
290
- * Returns raw text with all whitespace trimmed except single leading/trailing non-breaking space
291
- */
292
- get: function () {
293
- if (this._trimmedRawText !== undefined)
294
- return this._trimmedRawText;
295
- this._trimmedRawText = trimText(this.rawText);
296
- return this._trimmedRawText;
297
- },
298
- enumerable: false,
299
- configurable: true
300
- });
301
- Object.defineProperty(TextNode.prototype, "trimmedText", {
302
- /**
303
- * Returns text with all whitespace trimmed except single leading/trailing non-breaking space
304
- */
305
- get: function () {
306
- if (this._trimmedText !== undefined)
307
- return this._trimmedText;
308
- this._trimmedText = trimText(this.text);
309
- return this._trimmedText;
310
- },
311
- enumerable: false,
312
- configurable: true
313
- });
314
- Object.defineProperty(TextNode.prototype, "text", {
315
- /**
316
- * Get unescaped text value of current node and its children.
317
- * @return {string} text content
318
- */
319
- get: function () {
320
- return (0, he_2.decode)(this.rawText);
321
- },
322
- enumerable: false,
323
- configurable: true
324
- });
325
- Object.defineProperty(TextNode.prototype, "isWhitespace", {
326
- /**
327
- * Detect if the node contains only white space.
328
- * @return {boolean}
329
- */
330
- get: function () {
331
- return /^(\s|&nbsp;)*$/.test(this.rawText);
332
- },
333
- enumerable: false,
334
- configurable: true
335
- });
336
- TextNode.prototype.toString = function () {
337
- return this.rawText;
338
- };
339
- return TextNode;
340
- }(node_1.default));
341
- exports.default = TextNode;
342
- /**
343
- * Trim whitespace except single leading/trailing non-breaking space
344
- */
345
- function trimText(text) {
346
- var i = 0;
347
- var startPos;
348
- var endPos;
349
- while (i >= 0 && i < text.length) {
350
- if (/\S/.test(text[i])) {
351
- if (startPos === undefined) {
352
- startPos = i;
353
- i = text.length;
354
- }
355
- else {
356
- endPos = i;
357
- i = void 0;
358
- }
359
- }
360
- if (startPos === undefined)
361
- i++;
362
- else
363
- i--;
364
- }
365
- if (startPos === undefined)
366
- startPos = 0;
367
- if (endPos === undefined)
368
- endPos = text.length - 1;
369
- var hasLeadingSpace = startPos > 0 && /[^\S\r\n]/.test(text[startPos - 1]);
370
- var hasTrailingSpace = endPos < (text.length - 1) && /[^\S\r\n]/.test(text[endPos + 1]);
371
- return (hasLeadingSpace ? ' ' : '') + text.slice(startPos, endPos + 1) + (hasTrailingSpace ? ' ' : '');
372
- }
373
- });
374
- define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher", "void-tag", "nodes/comment", "nodes/node", "nodes/text", "nodes/type"], function (require, exports, css_select_1, he_3, back_1, matcher_1, void_tag_1, comment_1, node_2, text_1, type_3) {
375
- "use strict";
376
- Object.defineProperty(exports, "__esModule", { value: true });
377
- exports.parse = exports.base_parse = void 0;
378
- he_3 = __importDefault(he_3);
379
- back_1 = __importDefault(back_1);
380
- matcher_1 = __importDefault(matcher_1);
381
- void_tag_1 = __importDefault(void_tag_1);
382
- comment_1 = __importDefault(comment_1);
383
- node_2 = __importDefault(node_2);
384
- text_1 = __importDefault(text_1);
385
- type_3 = __importDefault(type_3);
386
- function decode(val) {
387
- // clone string
388
- return JSON.parse(JSON.stringify(he_3.default.decode(val)));
389
- }
390
- // https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements
391
- var Htags = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hgroup'];
392
- var Dtags = ['details', 'dialog', 'dd', 'div', 'dt'];
393
- var Ftags = ['fieldset', 'figcaption', 'figure', 'footer', 'form'];
394
- var tableTags = ['table', 'td', 'tr'];
395
- var htmlTags = ['address', 'article', 'aside', 'blockquote', 'br', 'hr', 'li', 'main', 'nav', 'ol', 'p', 'pre', 'section', 'ul'];
396
- var kBlockElements = new Set();
397
- function addToKBlockElement() {
398
- var args = [];
399
- for (var _i = 0; _i < arguments.length; _i++) {
400
- args[_i] = arguments[_i];
401
- }
402
- var addToSet = function (array) {
403
- for (var index = 0; index < array.length; index++) {
404
- var element = array[index];
405
- kBlockElements.add(element);
406
- kBlockElements.add(element.toUpperCase());
407
- }
408
- };
409
- for (var _a = 0, args_1 = args; _a < args_1.length; _a++) {
410
- var arg = args_1[_a];
411
- addToSet(arg);
412
- }
413
- }
414
- addToKBlockElement(Htags, Dtags, Ftags, tableTags, htmlTags);
415
- var DOMTokenList = /** @class */ (function () {
416
- function DOMTokenList(valuesInit, afterUpdate) {
417
- if (valuesInit === void 0) { valuesInit = []; }
418
- if (afterUpdate === void 0) { afterUpdate = function () { return null; }; }
419
- this._set = new Set(valuesInit);
420
- this._afterUpdate = afterUpdate;
421
- }
422
- DOMTokenList.prototype._validate = function (c) {
423
- if (/\s/.test(c)) {
424
- throw new Error("DOMException in DOMTokenList.add: The token '".concat(c, "' contains HTML space characters, which are not valid in tokens."));
425
- }
426
- };
427
- DOMTokenList.prototype.add = function (c) {
428
- this._validate(c);
429
- this._set.add(c);
430
- this._afterUpdate(this); // eslint-disable-line @typescript-eslint/no-unsafe-call
431
- };
432
- DOMTokenList.prototype.replace = function (c1, c2) {
433
- this._validate(c2);
434
- this._set.delete(c1);
435
- this._set.add(c2);
436
- this._afterUpdate(this); // eslint-disable-line @typescript-eslint/no-unsafe-call
437
- };
438
- DOMTokenList.prototype.remove = function (c) {
439
- this._set.delete(c) && this._afterUpdate(this); // eslint-disable-line @typescript-eslint/no-unsafe-call
440
- };
441
- DOMTokenList.prototype.toggle = function (c) {
442
- this._validate(c);
443
- if (this._set.has(c))
444
- this._set.delete(c);
445
- else
446
- this._set.add(c);
447
- this._afterUpdate(this); // eslint-disable-line @typescript-eslint/no-unsafe-call
448
- };
449
- DOMTokenList.prototype.contains = function (c) {
450
- return this._set.has(c);
451
- };
452
- Object.defineProperty(DOMTokenList.prototype, "length", {
453
- get: function () {
454
- return this._set.size;
455
- },
456
- enumerable: false,
457
- configurable: true
458
- });
459
- DOMTokenList.prototype.values = function () {
460
- return this._set.values();
461
- };
462
- Object.defineProperty(DOMTokenList.prototype, "value", {
463
- get: function () {
464
- return Array.from(this._set.values());
465
- },
466
- enumerable: false,
467
- configurable: true
468
- });
469
- DOMTokenList.prototype.toString = function () {
470
- return Array.from(this._set.values()).join(' ');
471
- };
472
- return DOMTokenList;
473
- }());
474
- /**
475
- * HTMLElement, which contains a set of children.
476
- *
477
- * Note: this is a minimalist implementation, no complete tree
478
- * structure provided (no parentNode, nextSibling,
479
- * previousSibling etc).
480
- * @class HTMLElement
481
- * @extends {Node}
482
- */
483
- var HTMLElement = /** @class */ (function (_super) {
484
- __extends(HTMLElement, _super);
485
- /**
486
- * Creates an instance of HTMLElement.
487
- * @param keyAttrs id and class attribute
488
- * @param [rawAttrs] attributes in string
489
- *
490
- * @memberof HTMLElement
491
- */
492
- function HTMLElement(tagName, keyAttrs, rawAttrs, parentNode, range, voidTag, _parseOptions) {
493
- if (rawAttrs === void 0) { rawAttrs = ''; }
494
- if (parentNode === void 0) { parentNode = null; }
495
- if (voidTag === void 0) { voidTag = new void_tag_1.default(); }
496
- if (_parseOptions === void 0) { _parseOptions = {}; }
497
- var _this = _super.call(this, parentNode, range) || this;
498
- _this.rawAttrs = rawAttrs;
499
- _this.voidTag = voidTag;
500
- /**
501
- * Node Type declaration.
502
- */
503
- _this.nodeType = type_3.default.ELEMENT_NODE;
504
- _this.rawTagName = tagName;
505
- _this.rawAttrs = rawAttrs || '';
506
- _this._id = keyAttrs.id || '';
507
- _this.childNodes = [];
508
- _this._parseOptions = _parseOptions;
509
- _this.classList = new DOMTokenList(keyAttrs.class ? keyAttrs.class.split(/\s+/) : [], function (classList) { return _this.setAttribute('class', classList.toString()); } // eslint-disable-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
510
- );
511
- if (keyAttrs.id) {
512
- if (!rawAttrs) {
513
- _this.rawAttrs = "id=\"".concat(keyAttrs.id, "\"");
514
- }
515
- }
516
- if (keyAttrs.class) {
517
- if (!rawAttrs) {
518
- var cls = "class=\"".concat(_this.classList.toString(), "\"");
519
- if (_this.rawAttrs) {
520
- _this.rawAttrs += " ".concat(cls);
521
- }
522
- else {
523
- _this.rawAttrs = cls;
524
- }
525
- }
526
- }
527
- return _this;
528
- }
529
- /**
530
- * Quote attribute values
531
- * @param attr attribute value
532
- * @returns {string} quoted value
533
- */
534
- HTMLElement.prototype.quoteAttribute = function (attr) {
535
- if (attr == null) {
536
- return 'null';
537
- }
538
- return JSON.stringify(attr.replace(/"/g, '&quot;'))
539
- .replace(/\\t/g, '\t')
540
- .replace(/\\n/g, '\n')
541
- .replace(/\\r/g, '\r')
542
- .replace(/\\/g, '');
543
- };
544
- /**
545
- * Remove Child element from childNodes array
546
- * @param {HTMLElement} node node to remove
547
- */
548
- HTMLElement.prototype.removeChild = function (node) {
549
- this.childNodes = this.childNodes.filter(function (child) {
550
- return child !== node;
551
- });
552
- return this;
553
- };
554
- /**
555
- * Exchanges given child with new child
556
- * @param {HTMLElement} oldNode node to exchange
557
- * @param {HTMLElement} newNode new node
558
- */
559
- HTMLElement.prototype.exchangeChild = function (oldNode, newNode) {
560
- var children = this.childNodes;
561
- this.childNodes = children.map(function (child) {
562
- if (child === oldNode) {
563
- return newNode;
564
- }
565
- return child;
566
- });
567
- return this;
568
- };
569
- Object.defineProperty(HTMLElement.prototype, "tagName", {
570
- get: function () {
571
- return this.rawTagName ? this.rawTagName.toUpperCase() : this.rawTagName;
572
- },
573
- set: function (newname) {
574
- this.rawTagName = newname.toLowerCase();
575
- },
576
- enumerable: false,
577
- configurable: true
578
- });
579
- Object.defineProperty(HTMLElement.prototype, "localName", {
580
- get: function () {
581
- return this.rawTagName.toLowerCase();
582
- },
583
- enumerable: false,
584
- configurable: true
585
- });
586
- Object.defineProperty(HTMLElement.prototype, "isVoidElement", {
587
- get: function () {
588
- return this.voidTag.isVoidElement(this.localName);
589
- },
590
- enumerable: false,
591
- configurable: true
592
- });
593
- Object.defineProperty(HTMLElement.prototype, "id", {
594
- get: function () {
595
- return this._id;
596
- },
597
- set: function (newid) {
598
- this.setAttribute('id', newid);
599
- },
600
- enumerable: false,
601
- configurable: true
602
- });
603
- Object.defineProperty(HTMLElement.prototype, "rawText", {
604
- /**
605
- * Get escpaed (as-it) text value of current node and its children.
606
- * @return {string} text content
607
- */
608
- get: function () {
609
- // https://github.com/taoqf/node-html-parser/issues/249
610
- if (/^br$/i.test(this.rawTagName)) {
611
- return '\n';
612
- }
613
- return this.childNodes.reduce(function (pre, cur) {
614
- return (pre += cur.rawText);
615
- }, '');
616
- },
617
- enumerable: false,
618
- configurable: true
619
- });
620
- Object.defineProperty(HTMLElement.prototype, "textContent", {
621
- get: function () {
622
- return decode(this.rawText);
623
- },
624
- set: function (val) {
625
- var content = [new text_1.default(val, this)];
626
- this.childNodes = content;
627
- },
628
- enumerable: false,
629
- configurable: true
630
- });
631
- Object.defineProperty(HTMLElement.prototype, "text", {
632
- /**
633
- * Get unescaped text value of current node and its children.
634
- * @return {string} text content
635
- */
636
- get: function () {
637
- return decode(this.rawText);
638
- },
639
- enumerable: false,
640
- configurable: true
641
- });
642
- Object.defineProperty(HTMLElement.prototype, "structuredText", {
643
- /**
644
- * Get structured Text (with '\n' etc.)
645
- * @return {string} structured text
646
- */
647
- get: function () {
648
- var currentBlock = [];
649
- var blocks = [currentBlock];
650
- function dfs(node) {
651
- if (node.nodeType === type_3.default.ELEMENT_NODE) {
652
- if (kBlockElements.has(node.rawTagName)) {
653
- if (currentBlock.length > 0) {
654
- blocks.push((currentBlock = []));
655
- }
656
- node.childNodes.forEach(dfs);
657
- if (currentBlock.length > 0) {
658
- blocks.push((currentBlock = []));
659
- }
660
- }
661
- else {
662
- node.childNodes.forEach(dfs);
663
- }
664
- }
665
- else if (node.nodeType === type_3.default.TEXT_NODE) {
666
- if (node.isWhitespace) {
667
- // Whitespace node, postponed output
668
- currentBlock.prependWhitespace = true;
669
- }
670
- else {
671
- var text = node.trimmedText;
672
- if (currentBlock.prependWhitespace) {
673
- text = " ".concat(text);
674
- currentBlock.prependWhitespace = false;
675
- }
676
- currentBlock.push(text);
677
- }
678
- }
679
- }
680
- dfs(this);
681
- return blocks
682
- .map(function (block) {
683
- return block.join('').replace(/\s{2,}/g, ' '); // Normalize each line's whitespace
684
- })
685
- .join('\n')
686
- .replace(/\s+$/, ''); // trimRight;
687
- },
688
- enumerable: false,
689
- configurable: true
690
- });
691
- HTMLElement.prototype.toString = function () {
692
- var tag = this.rawTagName;
693
- if (tag) {
694
- var attrs = this.rawAttrs ? " ".concat(this.rawAttrs) : '';
695
- return this.voidTag.formatNode(tag, attrs, this.innerHTML);
696
- }
697
- return this.innerHTML;
698
- };
699
- Object.defineProperty(HTMLElement.prototype, "innerHTML", {
700
- get: function () {
701
- return this.childNodes
702
- .map(function (child) {
703
- return child.toString();
704
- })
705
- .join('');
706
- },
707
- set: function (content) {
708
- var r = parse(content, this._parseOptions);
709
- var nodes = r.childNodes.length ? r.childNodes : [new text_1.default(content, this)];
710
- resetParent(nodes, this);
711
- resetParent(this.childNodes, null);
712
- this.childNodes = nodes;
713
- },
714
- enumerable: false,
715
- configurable: true
716
- });
717
- HTMLElement.prototype.set_content = function (content, options) {
718
- if (options === void 0) { options = {}; }
719
- if (content instanceof node_2.default) {
720
- content = [content];
721
- }
722
- else if (typeof content == 'string') {
723
- options = __assign(__assign({}, this._parseOptions), options);
724
- var r = parse(content, options);
725
- content = r.childNodes.length ? r.childNodes : [new text_1.default(r.innerHTML, this)];
726
- }
727
- resetParent(this.childNodes, null);
728
- resetParent(content, this);
729
- this.childNodes = content;
730
- return this;
731
- };
732
- HTMLElement.prototype.replaceWith = function () {
733
- var _this = this;
734
- var nodes = [];
735
- for (var _i = 0; _i < arguments.length; _i++) {
736
- nodes[_i] = arguments[_i];
737
- }
738
- var parent = this.parentNode;
739
- var content = nodes
740
- .map(function (node) {
741
- if (node instanceof node_2.default) {
742
- return [node];
743
- }
744
- else if (typeof node == 'string') {
745
- var r = parse(node, _this._parseOptions);
746
- return r.childNodes.length ? r.childNodes : [new text_1.default(node, _this)];
747
- }
748
- return [];
749
- })
750
- .flat();
751
- var idx = parent.childNodes.findIndex(function (child) {
752
- return child === _this;
753
- });
754
- resetParent([this], null);
755
- parent.childNodes = __spreadArray(__spreadArray(__spreadArray([], parent.childNodes.slice(0, idx), true), resetParent(content, parent), true), parent.childNodes.slice(idx + 1), true);
756
- return this;
757
- };
758
- Object.defineProperty(HTMLElement.prototype, "outerHTML", {
759
- get: function () {
760
- return this.toString();
761
- },
762
- enumerable: false,
763
- configurable: true
764
- });
765
- /**
766
- * Trim element from right (in block) after seeing pattern in a TextNode.
767
- * @param {RegExp} pattern pattern to find
768
- * @return {HTMLElement} reference to current node
769
- */
770
- HTMLElement.prototype.trimRight = function (pattern) {
771
- for (var i = 0; i < this.childNodes.length; i++) {
772
- var childNode = this.childNodes[i];
773
- if (childNode.nodeType === type_3.default.ELEMENT_NODE) {
774
- childNode.trimRight(pattern);
775
- }
776
- else {
777
- var index = childNode.rawText.search(pattern);
778
- if (index > -1) {
779
- childNode.rawText = childNode.rawText.substr(0, index);
780
- // trim all following nodes.
781
- this.childNodes.length = i + 1;
782
- }
783
- }
784
- }
785
- return this;
786
- };
787
- Object.defineProperty(HTMLElement.prototype, "structure", {
788
- /**
789
- * Get DOM structure
790
- * @return {string} structure
791
- */
792
- get: function () {
793
- var res = [];
794
- var indention = 0;
795
- function write(str) {
796
- res.push(' '.repeat(indention) + str);
797
- }
798
- function dfs(node) {
799
- var idStr = node._id ? "#".concat(node._id) : '';
800
- var classStr = node.classList.length ? ".".concat(node.classList.value.join('.')) : ''; // eslint-disable-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-unsafe-call
801
- write("".concat(node.rawTagName).concat(idStr).concat(classStr));
802
- indention++;
803
- node.childNodes.forEach(function (childNode) {
804
- if (childNode.nodeType === type_3.default.ELEMENT_NODE) {
805
- dfs(childNode);
806
- }
807
- else if (childNode.nodeType === type_3.default.TEXT_NODE) {
808
- if (!childNode.isWhitespace) {
809
- write('#text');
810
- }
811
- }
812
- });
813
- indention--;
814
- }
815
- dfs(this);
816
- return res.join('\n');
817
- },
818
- enumerable: false,
819
- configurable: true
820
- });
821
- /**
822
- * Remove whitespaces in this sub tree.
823
- * @return {HTMLElement} pointer to this
824
- */
825
- HTMLElement.prototype.removeWhitespace = function () {
826
- var _this = this;
827
- var o = 0;
828
- this.childNodes.forEach(function (node) {
829
- if (node.nodeType === type_3.default.TEXT_NODE) {
830
- if (node.isWhitespace) {
831
- return;
832
- }
833
- node.rawText = node.trimmedRawText;
834
- }
835
- else if (node.nodeType === type_3.default.ELEMENT_NODE) {
836
- node.removeWhitespace();
837
- }
838
- _this.childNodes[o++] = node;
839
- });
840
- this.childNodes.length = o;
841
- // remove whitespace between attributes
842
- var attrs = Object.keys(this.rawAttributes)
843
- .map(function (key) {
844
- var val = _this.rawAttributes[key];
845
- return "".concat(key, "=").concat(JSON.stringify(val));
846
- })
847
- .join(' ');
848
- this.rawAttrs = attrs;
849
- delete this._rawAttrs;
850
- return this;
851
- };
852
- /**
853
- * Query CSS selector to find matching nodes.
854
- * @param {string} selector Simplified CSS selector
855
- * @return {HTMLElement[]} matching elements
856
- */
857
- HTMLElement.prototype.querySelectorAll = function (selector) {
858
- return (0, css_select_1.selectAll)(selector, this, {
859
- xmlMode: true,
860
- adapter: matcher_1.default,
861
- });
862
- };
863
- /**
864
- * Query CSS Selector to find matching node.
865
- * @param {string} selector Simplified CSS selector
866
- * @return {(HTMLElement|null)} matching node
867
- */
868
- HTMLElement.prototype.querySelector = function (selector) {
869
- return (0, css_select_1.selectOne)(selector, this, {
870
- xmlMode: true,
871
- adapter: matcher_1.default,
872
- });
873
- };
874
- /**
875
- * Tests whether the node matches a given CSS selector.
876
- * @param {string} selector Simplified CSS selector
877
- * @return {boolean}
878
- */
879
- HTMLElement.prototype.matches = function (selector) {
880
- return (0, css_select_1.is)(this, selector, {
881
- xmlMode: true,
882
- adapter: matcher_1.default,
883
- });
884
- };
885
- /**
886
- * find elements by their tagName
887
- * @param {string} tagName the tagName of the elements to select
888
- */
889
- HTMLElement.prototype.getElementsByTagName = function (tagName) {
890
- var upperCasedTagName = tagName.toUpperCase();
891
- var re = [];
892
- var stack = [];
893
- var currentNodeReference = this;
894
- var index = 0;
895
- // index turns to undefined once the stack is empty and the first condition occurs
896
- // which happens once all relevant children are searched through
897
- while (index !== undefined) {
898
- var child = void 0;
899
- // make it work with sparse arrays
900
- do {
901
- child = currentNodeReference.childNodes[index++];
902
- } while (index < currentNodeReference.childNodes.length && child === undefined);
903
- // if the child does not exist we move on with the last provided index (which belongs to the parentNode)
904
- if (child === undefined) {
905
- currentNodeReference = currentNodeReference.parentNode;
906
- index = stack.pop();
907
- continue;
908
- }
909
- if (child.nodeType === type_3.default.ELEMENT_NODE) {
910
- // https://developer.mozilla.org/en-US/docs/Web/API/Element/getElementsByTagName#syntax
911
- if (tagName === '*' || child.tagName === upperCasedTagName)
912
- re.push(child);
913
- // if children are existing push the current status to the stack and keep searching for elements in the level below
914
- if (child.childNodes.length > 0) {
915
- stack.push(index);
916
- currentNodeReference = child;
917
- index = 0;
918
- }
919
- }
920
- }
921
- return re;
922
- };
923
- /**
924
- * find element by it's id
925
- * @param {string} id the id of the element to select
926
- * @returns {HTMLElement | null} the element with the given id or null if not found
927
- */
928
- HTMLElement.prototype.getElementById = function (id) {
929
- var stack = [];
930
- var currentNodeReference = this;
931
- var index = 0;
932
- // index turns to undefined once the stack is empty and the first condition occurs
933
- // which happens once all relevant children are searched through
934
- while (index !== undefined) {
935
- var child = void 0;
936
- // make it work with sparse arrays
937
- do {
938
- child = currentNodeReference.childNodes[index++];
939
- } while (index < currentNodeReference.childNodes.length && child === undefined);
940
- // if the child does not exist we move on with the last provided index (which belongs to the parentNode)
941
- if (child === undefined) {
942
- currentNodeReference = currentNodeReference.parentNode;
943
- index = stack.pop();
944
- continue;
945
- }
946
- if (child.nodeType === type_3.default.ELEMENT_NODE) {
947
- if (child._id === id) {
948
- return child;
949
- }
950
- // if children are existing push the current status to the stack and keep searching for elements in the level below
951
- if (child.childNodes.length > 0) {
952
- stack.push(index);
953
- currentNodeReference = child;
954
- index = 0;
955
- }
956
- }
957
- }
958
- return null;
959
- };
960
- /**
961
- * traverses the Element and its parents (heading toward the document root) until it finds a node that matches the provided selector string. Will return itself or the matching ancestor. If no such element exists, it returns null.
962
- * @param selector a DOMString containing a selector list
963
- * @returns {HTMLElement | null} the element with the given id or null if not found
964
- */
965
- HTMLElement.prototype.closest = function (selector) {
966
- var mapChild = new Map();
967
- var el = this;
968
- var old = null;
969
- function findOne(test, elems) {
970
- var elem = null;
971
- for (var i = 0, l = elems.length; i < l && !elem; i++) {
972
- var el_1 = elems[i];
973
- if (test(el_1)) {
974
- elem = el_1;
975
- }
976
- else {
977
- var child = mapChild.get(el_1);
978
- if (child) {
979
- elem = findOne(test, [child]);
980
- }
981
- }
982
- }
983
- return elem;
984
- }
985
- while (el) {
986
- mapChild.set(el, old);
987
- old = el;
988
- el = el.parentNode;
989
- }
990
- el = this;
991
- while (el) {
992
- var e = (0, css_select_1.selectOne)(selector, el, {
993
- xmlMode: true,
994
- adapter: __assign(__assign({}, matcher_1.default), { getChildren: function (node) {
995
- var child = mapChild.get(node);
996
- return child && [child];
997
- }, getSiblings: function (node) {
998
- return [node];
999
- }, findOne: findOne, findAll: function () {
1000
- return [];
1001
- } }),
1002
- });
1003
- if (e) {
1004
- return e;
1005
- }
1006
- el = el.parentNode;
1007
- }
1008
- return null;
1009
- };
1010
- /**
1011
- * Append a child node to childNodes
1012
- * @param {Node} node node to append
1013
- * @return {Node} node appended
1014
- */
1015
- HTMLElement.prototype.appendChild = function (node) {
1016
- this.append(node);
1017
- return node;
1018
- };
1019
- Object.defineProperty(HTMLElement.prototype, "attrs", {
1020
- /**
1021
- * Get attributes
1022
- * @access private
1023
- * @return {Object} parsed and unescaped attributes
1024
- */
1025
- get: function () {
1026
- if (this._attrs) {
1027
- return this._attrs;
1028
- }
1029
- this._attrs = {};
1030
- var attrs = this.rawAttributes;
1031
- for (var key in attrs) {
1032
- var val = attrs[key] || '';
1033
- this._attrs[key.toLowerCase()] = decode(val);
1034
- }
1035
- return this._attrs;
1036
- },
1037
- enumerable: false,
1038
- configurable: true
1039
- });
1040
- Object.defineProperty(HTMLElement.prototype, "attributes", {
1041
- get: function () {
1042
- var ret_attrs = {};
1043
- var attrs = this.rawAttributes;
1044
- for (var key in attrs) {
1045
- var val = attrs[key] || '';
1046
- ret_attrs[key] = decode(val);
1047
- }
1048
- return ret_attrs;
1049
- },
1050
- enumerable: false,
1051
- configurable: true
1052
- });
1053
- Object.defineProperty(HTMLElement.prototype, "rawAttributes", {
1054
- /**
1055
- * Get escaped (as-is) attributes
1056
- * @return {Object} parsed attributes
1057
- */
1058
- get: function () {
1059
- if (this._rawAttrs) {
1060
- return this._rawAttrs;
1061
- }
1062
- var attrs = {};
1063
- if (this.rawAttrs) {
1064
- var re = /([a-zA-Z()[\]#@$.?:][a-zA-Z0-9-._:()[\]#]*)(?:\s*=\s*((?:'[^']*')|(?:"[^"]*")|\S+))?/g;
1065
- var match = void 0;
1066
- while ((match = re.exec(this.rawAttrs))) {
1067
- var key = match[1];
1068
- var val = match[2] || null;
1069
- if (val && (val[0] === "'" || val[0] === "\""))
1070
- val = val.slice(1, val.length - 1);
1071
- attrs[key] = attrs[key] || val;
1072
- }
1073
- }
1074
- this._rawAttrs = attrs;
1075
- return attrs;
1076
- },
1077
- enumerable: false,
1078
- configurable: true
1079
- });
1080
- HTMLElement.prototype.removeAttribute = function (key) {
1081
- var _this = this;
1082
- var attrs = this.rawAttributes;
1083
- delete attrs[key];
1084
- // Update this.attribute
1085
- if (this._attrs) {
1086
- delete this._attrs[key];
1087
- }
1088
- // Update rawString
1089
- this.rawAttrs = Object.keys(attrs)
1090
- .map(function (name) {
1091
- var val = _this.quoteAttribute(attrs[name]);
1092
- if (val === 'null' || val === '""')
1093
- return name;
1094
- return "".concat(name, "=").concat(val);
1095
- })
1096
- .join(' ');
1097
- // Update this._id
1098
- if (key === 'id') {
1099
- this._id = '';
1100
- }
1101
- return this;
1102
- };
1103
- HTMLElement.prototype.hasAttribute = function (key) {
1104
- return key.toLowerCase() in this.attrs;
1105
- };
1106
- /**
1107
- * Get an attribute
1108
- * @return {string | undefined} value of the attribute; or undefined if not exist
1109
- */
1110
- HTMLElement.prototype.getAttribute = function (key) {
1111
- return this.attrs[key.toLowerCase()];
1112
- };
1113
- /**
1114
- * Set an attribute value to the HTMLElement
1115
- * @param {string} key The attribute name
1116
- * @param {string} value The value to set, or null / undefined to remove an attribute
1117
- */
1118
- HTMLElement.prototype.setAttribute = function (key, value) {
1119
- var _this = this;
1120
- if (arguments.length < 2) {
1121
- throw new Error("Failed to execute 'setAttribute' on 'Element'");
1122
- }
1123
- var k2 = key.toLowerCase();
1124
- var attrs = this.rawAttributes;
1125
- for (var k in attrs) {
1126
- if (k.toLowerCase() === k2) {
1127
- key = k;
1128
- break;
1129
- }
1130
- }
1131
- attrs[key] = String(value);
1132
- // update this.attrs
1133
- if (this._attrs) {
1134
- this._attrs[k2] = decode(attrs[key]);
1135
- }
1136
- // Update rawString
1137
- this.rawAttrs = Object.keys(attrs)
1138
- .map(function (name) {
1139
- var val = _this.quoteAttribute(attrs[name]);
1140
- if (val === 'null' || val === '""')
1141
- return name;
1142
- return "".concat(name, "=").concat(val);
1143
- })
1144
- .join(' ');
1145
- // Update this._id
1146
- if (key === 'id') {
1147
- this._id = value;
1148
- }
1149
- return this;
1150
- };
1151
- /**
1152
- * Replace all the attributes of the HTMLElement by the provided attributes
1153
- * @param {Attributes} attributes the new attribute set
1154
- */
1155
- HTMLElement.prototype.setAttributes = function (attributes) {
1156
- var _this = this;
1157
- // Invalidate current this.attributes
1158
- if (this._attrs) {
1159
- delete this._attrs;
1160
- }
1161
- // Invalidate current this.rawAttributes
1162
- if (this._rawAttrs) {
1163
- delete this._rawAttrs;
1164
- }
1165
- // Update rawString
1166
- this.rawAttrs = Object.keys(attributes)
1167
- .map(function (name) {
1168
- var val = attributes[name];
1169
- if (val === 'null' || val === '""')
1170
- return name;
1171
- return "".concat(name, "=").concat(_this.quoteAttribute(String(val)));
1172
- })
1173
- .join(' ');
1174
- // Update this._id
1175
- if ('id' in attributes) {
1176
- this._id = attributes['id'];
1177
- }
1178
- return this;
1179
- };
1180
- HTMLElement.prototype.insertAdjacentHTML = function (where, html) {
1181
- if (arguments.length < 2) {
1182
- throw new Error('2 arguments required');
1183
- }
1184
- var p = parse(html, this._parseOptions);
1185
- if (where === 'afterend') {
1186
- this.after.apply(this, p.childNodes);
1187
- }
1188
- else if (where === 'afterbegin') {
1189
- this.prepend.apply(this, p.childNodes);
1190
- }
1191
- else if (where === 'beforeend') {
1192
- this.append.apply(this, p.childNodes);
1193
- }
1194
- else if (where === 'beforebegin') {
1195
- this.before.apply(this, p.childNodes);
1196
- }
1197
- else {
1198
- throw new Error("The value provided ('".concat(where, "') is not one of 'beforebegin', 'afterbegin', 'beforeend', or 'afterend'"));
1199
- }
1200
- return this;
1201
- };
1202
- /** Prepend nodes or strings to this node's children. */
1203
- HTMLElement.prototype.prepend = function () {
1204
- var _a;
1205
- var insertable = [];
1206
- for (var _i = 0; _i < arguments.length; _i++) {
1207
- insertable[_i] = arguments[_i];
1208
- }
1209
- var nodes = resolveInsertable(insertable);
1210
- resetParent(nodes, this);
1211
- (_a = this.childNodes).unshift.apply(_a, nodes);
1212
- };
1213
- /** Append nodes or strings to this node's children. */
1214
- HTMLElement.prototype.append = function () {
1215
- var _a;
1216
- var insertable = [];
1217
- for (var _i = 0; _i < arguments.length; _i++) {
1218
- insertable[_i] = arguments[_i];
1219
- }
1220
- var nodes = resolveInsertable(insertable);
1221
- resetParent(nodes, this);
1222
- (_a = this.childNodes).push.apply(_a, nodes);
1223
- };
1224
- /** Insert nodes or strings before this node. */
1225
- HTMLElement.prototype.before = function () {
1226
- var insertable = [];
1227
- for (var _i = 0; _i < arguments.length; _i++) {
1228
- insertable[_i] = arguments[_i];
1229
- }
1230
- var nodes = resolveInsertable(insertable);
1231
- var siblings = this.parentNode.childNodes;
1232
- resetParent(nodes, this.parentNode);
1233
- siblings.splice.apply(siblings, __spreadArray([siblings.indexOf(this), 0], nodes, false));
1234
- };
1235
- /** Insert nodes or strings after this node. */
1236
- HTMLElement.prototype.after = function () {
1237
- var insertable = [];
1238
- for (var _i = 0; _i < arguments.length; _i++) {
1239
- insertable[_i] = arguments[_i];
1240
- }
1241
- var nodes = resolveInsertable(insertable);
1242
- var siblings = this.parentNode.childNodes;
1243
- resetParent(nodes, this.parentNode);
1244
- siblings.splice.apply(siblings, __spreadArray([siblings.indexOf(this) + 1, 0], nodes, false));
1245
- };
1246
- Object.defineProperty(HTMLElement.prototype, "nextSibling", {
1247
- get: function () {
1248
- if (this.parentNode) {
1249
- var children = this.parentNode.childNodes;
1250
- var i = 0;
1251
- while (i < children.length) {
1252
- var child = children[i++];
1253
- if (this === child)
1254
- return children[i] || null;
1255
- }
1256
- return null;
1257
- }
1258
- },
1259
- enumerable: false,
1260
- configurable: true
1261
- });
1262
- Object.defineProperty(HTMLElement.prototype, "nextElementSibling", {
1263
- get: function () {
1264
- if (this.parentNode) {
1265
- var children = this.parentNode.childNodes;
1266
- var i = 0;
1267
- var find = false;
1268
- while (i < children.length) {
1269
- var child = children[i++];
1270
- if (find) {
1271
- if (child instanceof HTMLElement) {
1272
- return child || null;
1273
- }
1274
- }
1275
- else if (this === child) {
1276
- find = true;
1277
- }
1278
- }
1279
- return null;
1280
- }
1281
- },
1282
- enumerable: false,
1283
- configurable: true
1284
- });
1285
- Object.defineProperty(HTMLElement.prototype, "previousSibling", {
1286
- get: function () {
1287
- if (this.parentNode) {
1288
- var children = this.parentNode.childNodes;
1289
- var i = children.length;
1290
- while (i > 0) {
1291
- var child = children[--i];
1292
- if (this === child)
1293
- return children[i - 1] || null;
1294
- }
1295
- return null;
1296
- }
1297
- },
1298
- enumerable: false,
1299
- configurable: true
1300
- });
1301
- Object.defineProperty(HTMLElement.prototype, "previousElementSibling", {
1302
- get: function () {
1303
- if (this.parentNode) {
1304
- var children = this.parentNode.childNodes;
1305
- var i = children.length;
1306
- var find = false;
1307
- while (i > 0) {
1308
- var child = children[--i];
1309
- if (find) {
1310
- if (child instanceof HTMLElement) {
1311
- return child || null;
1312
- }
1313
- }
1314
- else if (this === child) {
1315
- find = true;
1316
- }
1317
- }
1318
- return null;
1319
- }
1320
- },
1321
- enumerable: false,
1322
- configurable: true
1323
- });
1324
- Object.defineProperty(HTMLElement.prototype, "children", {
1325
- /** Get all childNodes of type {@link HTMLElement}. */
1326
- get: function () {
1327
- var children = [];
1328
- for (var _i = 0, _a = this.childNodes; _i < _a.length; _i++) {
1329
- var childNode = _a[_i];
1330
- if (childNode instanceof HTMLElement) {
1331
- children.push(childNode);
1332
- }
1333
- }
1334
- return children;
1335
- },
1336
- enumerable: false,
1337
- configurable: true
1338
- });
1339
- Object.defineProperty(HTMLElement.prototype, "firstChild", {
1340
- /**
1341
- * Get the first child node.
1342
- * @return The first child or undefined if none exists.
1343
- */
1344
- get: function () {
1345
- return this.childNodes[0];
1346
- },
1347
- enumerable: false,
1348
- configurable: true
1349
- });
1350
- Object.defineProperty(HTMLElement.prototype, "firstElementChild", {
1351
- /**
1352
- * Get the first child node of type {@link HTMLElement}.
1353
- * @return The first child element or undefined if none exists.
1354
- */
1355
- get: function () {
1356
- return this.children[0];
1357
- },
1358
- enumerable: false,
1359
- configurable: true
1360
- });
1361
- Object.defineProperty(HTMLElement.prototype, "lastChild", {
1362
- /**
1363
- * Get the last child node.
1364
- * @return The last child or undefined if none exists.
1365
- */
1366
- get: function () {
1367
- return (0, back_1.default)(this.childNodes);
1368
- },
1369
- enumerable: false,
1370
- configurable: true
1371
- });
1372
- Object.defineProperty(HTMLElement.prototype, "lastElementChild", {
1373
- /**
1374
- * Get the last child node of type {@link HTMLElement}.
1375
- * @return The last child element or undefined if none exists.
1376
- */
1377
- get: function () {
1378
- return this.children[this.children.length - 1];
1379
- },
1380
- enumerable: false,
1381
- configurable: true
1382
- });
1383
- Object.defineProperty(HTMLElement.prototype, "childElementCount", {
1384
- get: function () {
1385
- return this.children.length;
1386
- },
1387
- enumerable: false,
1388
- configurable: true
1389
- });
1390
- Object.defineProperty(HTMLElement.prototype, "classNames", {
1391
- get: function () {
1392
- return this.classList.toString();
1393
- },
1394
- enumerable: false,
1395
- configurable: true
1396
- });
1397
- /** Clone this Node */
1398
- HTMLElement.prototype.clone = function () {
1399
- return parse(this.toString(), this._parseOptions).firstChild;
1400
- };
1401
- return HTMLElement;
1402
- }(node_2.default));
1403
- exports.default = HTMLElement;
1404
- // #xB7 | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x203F-#x2040] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
1405
- // https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
1406
- var kMarkupPattern = /<!--[\s\S]*?-->|<(\/?)([a-zA-Z][-.:0-9_a-zA-Z@\xB7\xC0-\xD6\xD8-\xF6\u00F8-\u03A1\u03A3-\u03D9\u03DB-\u03EF\u03F7-\u03FF\u0400-\u04FF\u0500-\u052F\u1D00-\u1D2B\u1D6B-\u1D77\u1D79-\u1D9A\u1E00-\u1E9B\u1F00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2126\u212A-\u212B\u2132\u214E\u2160-\u2188\u2C60-\u2C7F\uA722-\uA787\uA78B-\uA78E\uA790-\uA7AD\uA7B0-\uA7B7\uA7F7-\uA7FF\uAB30-\uAB5A\uAB5C-\uAB5F\uAB64-\uAB65\uFB00-\uFB06\uFB13-\uFB17\uFF21-\uFF3A\uFF41-\uFF5A\x37F-\u1FFF\u200C-\u200D\u203F-\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]*)((?:\s+[^>]*?(?:(?:'[^']*')|(?:"[^"]*"))?)*)\s*(\/?)>/gu;
1407
- // const kMarkupPattern = /<!--[\s\S]*?-->|<(\/?)([a-zA-Z][-.:0-9_a-zA-Z]*)((?:\s+[^>]*?(?:(?:'[^']*')|(?:"[^"]*"))?)*)\s*(\/?)>/g;
1408
- var kAttributePattern = /(?:^|\s)(id|class)\s*=\s*((?:'[^']*')|(?:"[^"]*")|\S+)/gi;
1409
- var kElementsClosedByOpening = {
1410
- li: { li: true, LI: true },
1411
- LI: { li: true, LI: true },
1412
- p: { p: true, div: true, P: true, DIV: true },
1413
- P: { p: true, div: true, P: true, DIV: true },
1414
- b: { div: true, DIV: true },
1415
- B: { div: true, DIV: true },
1416
- td: { td: true, th: true, TD: true, TH: true },
1417
- TD: { td: true, th: true, TD: true, TH: true },
1418
- th: { td: true, th: true, TD: true, TH: true },
1419
- TH: { td: true, th: true, TD: true, TH: true },
1420
- h1: { h1: true, H1: true },
1421
- H1: { h1: true, H1: true },
1422
- h2: { h2: true, H2: true },
1423
- H2: { h2: true, H2: true },
1424
- h3: { h3: true, H3: true },
1425
- H3: { h3: true, H3: true },
1426
- h4: { h4: true, H4: true },
1427
- H4: { h4: true, H4: true },
1428
- h5: { h5: true, H5: true },
1429
- H5: { h5: true, H5: true },
1430
- h6: { h6: true, H6: true },
1431
- H6: { h6: true, H6: true },
1432
- };
1433
- var kElementsClosedByClosing = {
1434
- li: { ul: true, ol: true, UL: true, OL: true },
1435
- LI: { ul: true, ol: true, UL: true, OL: true },
1436
- a: { div: true, DIV: true },
1437
- A: { div: true, DIV: true },
1438
- b: { div: true, DIV: true },
1439
- B: { div: true, DIV: true },
1440
- i: { div: true, DIV: true },
1441
- I: { div: true, DIV: true },
1442
- p: { div: true, DIV: true },
1443
- P: { div: true, DIV: true },
1444
- td: { tr: true, table: true, TR: true, TABLE: true },
1445
- TD: { tr: true, table: true, TR: true, TABLE: true },
1446
- th: { tr: true, table: true, TR: true, TABLE: true },
1447
- TH: { tr: true, table: true, TR: true, TABLE: true },
1448
- };
1449
- var kElementsClosedByClosingExcept = {
1450
- p: { a: true, audio: true, del: true, ins: true, map: true, noscript: true, video: true },
1451
- };
1452
- var frameflag = 'documentfragmentcontainer';
1453
- /**
1454
- * Parses HTML and returns a root element
1455
- * Parse a chuck of HTML source.
1456
- * @param {string} data html
1457
- * @return {HTMLElement} root element
1458
- */
1459
- function base_parse(data, options) {
1460
- var _a, _b;
1461
- if (options === void 0) { options = {}; }
1462
- var voidTag = new void_tag_1.default((_a = options === null || options === void 0 ? void 0 : options.voidTag) === null || _a === void 0 ? void 0 : _a.closingSlash, (_b = options === null || options === void 0 ? void 0 : options.voidTag) === null || _b === void 0 ? void 0 : _b.tags);
1463
- var elements = options.blockTextElements || {
1464
- script: true,
1465
- noscript: true,
1466
- style: true,
1467
- pre: true,
1468
- };
1469
- var element_names = Object.keys(elements);
1470
- var kBlockTextElements = element_names.map(function (it) { return new RegExp("^".concat(it, "$"), 'i'); });
1471
- var kIgnoreElements = element_names.filter(function (it) { return Boolean(elements[it]); }).map(function (it) { return new RegExp("^".concat(it, "$"), 'i'); });
1472
- function element_should_be_ignore(tag) {
1473
- return kIgnoreElements.some(function (it) { return it.test(tag); });
1474
- }
1475
- function is_block_text_element(tag) {
1476
- return kBlockTextElements.some(function (it) { return it.test(tag); });
1477
- }
1478
- var createRange = function (startPos, endPos) { return [startPos - frameFlagOffset, endPos - frameFlagOffset]; };
1479
- var root = new HTMLElement(null, {}, '', null, [0, data.length], voidTag, options);
1480
- var currentParent = root;
1481
- var stack = [root];
1482
- var lastTextPos = -1;
1483
- var noNestedTagIndex = undefined;
1484
- var match;
1485
- // https://github.com/taoqf/node-html-parser/issues/38
1486
- data = "<".concat(frameflag, ">").concat(data, "</").concat(frameflag, ">");
1487
- var lowerCaseTagName = options.lowerCaseTagName, fixNestedATags = options.fixNestedATags;
1488
- var dataEndPos = data.length - (frameflag.length + 2);
1489
- var frameFlagOffset = frameflag.length + 2;
1490
- while ((match = kMarkupPattern.exec(data))) {
1491
- // Note: Object destructuring here consistently tests as higher performance than array destructuring
1492
- // eslint-disable-next-line prefer-const
1493
- var matchText = match[0], leadingSlash = match[1], tagName = match[2], attributes = match[3], closingSlash = match[4];
1494
- var matchLength = matchText.length;
1495
- var tagStartPos = kMarkupPattern.lastIndex - matchLength;
1496
- var tagEndPos = kMarkupPattern.lastIndex;
1497
- // Add TextNode if content
1498
- if (lastTextPos > -1) {
1499
- if (lastTextPos + matchLength < tagEndPos) {
1500
- var text = data.substring(lastTextPos, tagStartPos);
1501
- currentParent.appendChild(new text_1.default(text, currentParent, createRange(lastTextPos, tagStartPos)));
1502
- }
1503
- }
1504
- lastTextPos = kMarkupPattern.lastIndex;
1505
- // https://github.com/taoqf/node-html-parser/issues/38
1506
- // Skip frameflag node
1507
- if (tagName === frameflag)
1508
- continue;
1509
- // Handle comments
1510
- if (matchText[1] === '!') {
1511
- if (options.comment) {
1512
- // Only keep what is in between <!-- and -->
1513
- var text = data.substring(tagStartPos + 4, tagEndPos - 3);
1514
- currentParent.appendChild(new comment_1.default(text, currentParent, createRange(tagStartPos, tagEndPos)));
1515
- }
1516
- continue;
1517
- }
1518
- /* -- Handle tag matching -- */
1519
- // Fix tag casing if necessary
1520
- if (lowerCaseTagName)
1521
- tagName = tagName.toLowerCase();
1522
- // Handle opening tags (ie. <this> not </that>)
1523
- if (!leadingSlash) {
1524
- /* Populate attributes */
1525
- var attrs = {};
1526
- for (var attMatch = void 0; (attMatch = kAttributePattern.exec(attributes));) {
1527
- var key = attMatch[1], val = attMatch[2];
1528
- var isQuoted = val[0] === "'" || val[0] === "\"";
1529
- attrs[key.toLowerCase()] = isQuoted ? val.slice(1, val.length - 1) : val;
1530
- }
1531
- var parentTagName = currentParent.rawTagName;
1532
- if (!closingSlash && !options.preserveTagNesting && kElementsClosedByOpening[parentTagName]) {
1533
- if (kElementsClosedByOpening[parentTagName][tagName]) {
1534
- stack.pop();
1535
- currentParent = (0, back_1.default)(stack);
1536
- }
1537
- }
1538
- // Prevent nested A tags by terminating the last A and starting a new one : see issue #144
1539
- if (fixNestedATags && (tagName === 'a' || tagName === 'A')) {
1540
- if (noNestedTagIndex !== undefined) {
1541
- stack.splice(noNestedTagIndex);
1542
- currentParent = (0, back_1.default)(stack);
1543
- }
1544
- noNestedTagIndex = stack.length;
1545
- }
1546
- var tagEndPos_1 = kMarkupPattern.lastIndex;
1547
- var tagStartPos_1 = tagEndPos_1 - matchLength;
1548
- currentParent = currentParent.appendChild(
1549
- // Initialize range (end position updated later for closed tags)
1550
- new HTMLElement(tagName, attrs, attributes.slice(1), null, createRange(tagStartPos_1, tagEndPos_1), voidTag, options));
1551
- stack.push(currentParent);
1552
- if (is_block_text_element(tagName)) {
1553
- // Find closing tag
1554
- var closeMarkup = "</".concat(tagName, ">");
1555
- var closeIndex = lowerCaseTagName
1556
- ? data.toLocaleLowerCase().indexOf(closeMarkup, kMarkupPattern.lastIndex)
1557
- : data.indexOf(closeMarkup, kMarkupPattern.lastIndex);
1558
- var textEndPos = closeIndex === -1 ? dataEndPos : closeIndex;
1559
- if (element_should_be_ignore(tagName)) {
1560
- var text = data.substring(tagEndPos_1, textEndPos);
1561
- if (text.length > 0 && /\S/.test(text)) {
1562
- currentParent.appendChild(new text_1.default(text, currentParent, createRange(tagEndPos_1, textEndPos)));
1563
- }
1564
- }
1565
- if (closeIndex === -1) {
1566
- lastTextPos = kMarkupPattern.lastIndex = data.length + 1;
1567
- }
1568
- else {
1569
- lastTextPos = kMarkupPattern.lastIndex = closeIndex + closeMarkup.length;
1570
- // Cause to be treated as self-closing, because no close found
1571
- leadingSlash = '/';
1572
- }
1573
- }
1574
- }
1575
- // Handle closing tags or self-closed elements (ie </tag> or <br>)
1576
- if (leadingSlash || closingSlash || voidTag.isVoidElement(tagName)) {
1577
- while (true) {
1578
- if (noNestedTagIndex != null && (tagName === 'a' || tagName === 'A'))
1579
- noNestedTagIndex = undefined;
1580
- if (currentParent.rawTagName === tagName) {
1581
- // Update range end for closed tag
1582
- currentParent.range[1] = createRange(-1, Math.max(lastTextPos, tagEndPos))[1];
1583
- stack.pop();
1584
- currentParent = (0, back_1.default)(stack);
1585
- break;
1586
- }
1587
- else {
1588
- var parentTagName = currentParent.tagName;
1589
- // Trying to close current tag, and move on
1590
- if (kElementsClosedByClosing[parentTagName]) {
1591
- if (kElementsClosedByClosing[parentTagName][tagName]) {
1592
- stack.pop();
1593
- currentParent = (0, back_1.default)(stack);
1594
- continue;
1595
- }
1596
- }
1597
- var openTag = currentParent.rawTagName ?
1598
- currentParent.rawTagName.toLowerCase() :
1599
- '';
1600
- if (kElementsClosedByClosingExcept[openTag]) {
1601
- var closingTag = tagName.toLowerCase();
1602
- if (stack.length > 1) {
1603
- var possibleContainer = stack[stack.length - 2];
1604
- if (possibleContainer &&
1605
- possibleContainer.rawTagName &&
1606
- possibleContainer.rawTagName.toLowerCase() === closingTag &&
1607
- !kElementsClosedByClosingExcept[openTag][closingTag]) {
1608
- // Update range end for closed tag
1609
- currentParent.range[1] = createRange(-1, Math.max(lastTextPos, tagEndPos))[1];
1610
- stack.pop();
1611
- currentParent = (0, back_1.default)(stack);
1612
- continue;
1613
- }
1614
- }
1615
- }
1616
- if (options.closeAllByClosing === true) {
1617
- // If tag was opened, close all nested tags
1618
- var i = void 0;
1619
- for (i = stack.length - 2; i >= 0; i--) {
1620
- if (stack[i].rawTagName === tagName)
1621
- break;
1622
- }
1623
- if (i >= 0) {
1624
- while (stack.length > i) {
1625
- // Update range end for closed tag
1626
- currentParent.range[1] = createRange(-1, Math.max(lastTextPos, tagEndPos))[1];
1627
- stack.pop();
1628
- currentParent = (0, back_1.default)(stack);
1629
- }
1630
- continue;
1631
- }
1632
- }
1633
- // Use aggressive strategy to handle unmatching markups.
1634
- break;
1635
- }
1636
- }
1637
- }
1638
- }
1639
- return stack;
1640
- }
1641
- exports.base_parse = base_parse;
1642
- /**
1643
- * Parses HTML and returns a root element
1644
- * Parse a chuck of HTML source.
1645
- */
1646
- function parse(data, options) {
1647
- if (options === void 0) { options = {}; }
1648
- var stack = base_parse(data, options);
1649
- var root = stack[0];
1650
- var _loop_1 = function () {
1651
- // Handle each error elements.
1652
- var last = stack.pop();
1653
- var oneBefore = (0, back_1.default)(stack);
1654
- if (last.parentNode && last.parentNode.parentNode) {
1655
- if (last.parentNode === oneBefore && last.tagName === oneBefore.tagName) {
1656
- // Pair error case <h3> <h3> handle : Fixes to <h3> </h3>
1657
- // this is wrong, becouse this will put the H3 outside the current right position which should be inside the current Html Element, see issue 152 for more info
1658
- if (options.parseNoneClosedTags !== true) {
1659
- oneBefore.removeChild(last);
1660
- last.childNodes.forEach(function (child) {
1661
- oneBefore.parentNode.appendChild(child);
1662
- });
1663
- stack.pop();
1664
- }
1665
- }
1666
- else {
1667
- // Single error <div> <h3> </div> handle: Just removes <h3>
1668
- // Why remove? this is already a HtmlElement and the missing <H3> is already added in this case. see issue 152 for more info
1669
- // eslint-disable-next-line no-lonely-if
1670
- if (options.parseNoneClosedTags !== true) {
1671
- oneBefore.removeChild(last);
1672
- last.childNodes.forEach(function (child) {
1673
- oneBefore.appendChild(child);
1674
- });
1675
- }
1676
- }
1677
- }
1678
- else {
1679
- // If it's final element just skip.
1680
- }
1681
- };
1682
- while (stack.length > 1) {
1683
- _loop_1();
1684
- }
1685
- // response.childNodes.forEach((node) => {
1686
- // if (node instanceof HTMLElement) {
1687
- // node.parentNode = null;
1688
- // }
1689
- // });
1690
- return root;
1691
- }
1692
- exports.parse = parse;
1693
- /**
1694
- * Resolves a list of {@link NodeInsertable} to a list of nodes,
1695
- * and removes nodes from any potential parent.
1696
- */
1697
- function resolveInsertable(insertable) {
1698
- return insertable.map(function (val) {
1699
- if (typeof val === 'string') {
1700
- return new text_1.default(val);
1701
- }
1702
- val.remove();
1703
- return val;
1704
- });
1705
- }
1706
- function resetParent(nodes, parent) {
1707
- return nodes.map(function (node) {
1708
- node.parentNode = parent;
1709
- return node;
1710
- });
1711
- }
1712
- });
1713
- define("nodes/comment", ["require", "exports", "nodes/node", "nodes/type"], function (require, exports, node_3, type_4) {
1714
- "use strict";
1715
- Object.defineProperty(exports, "__esModule", { value: true });
1716
- node_3 = __importDefault(node_3);
1717
- type_4 = __importDefault(type_4);
1718
- var CommentNode = /** @class */ (function (_super) {
1719
- __extends(CommentNode, _super);
1720
- function CommentNode(rawText, parentNode, range, rawTagName) {
1721
- if (parentNode === void 0) { parentNode = null; }
1722
- if (rawTagName === void 0) { rawTagName = '!--'; }
1723
- var _this = _super.call(this, parentNode, range) || this;
1724
- _this.rawText = rawText;
1725
- _this.rawTagName = rawTagName;
1726
- /**
1727
- * Node Type declaration.
1728
- * @type {Number}
1729
- */
1730
- _this.nodeType = type_4.default.COMMENT_NODE;
1731
- return _this;
1732
- }
1733
- CommentNode.prototype.clone = function () {
1734
- return new CommentNode(this.rawText, null, undefined, this.rawTagName);
1735
- };
1736
- Object.defineProperty(CommentNode.prototype, "text", {
1737
- /**
1738
- * Get unescaped text value of current node and its children.
1739
- * @return {string} text content
1740
- */
1741
- get: function () {
1742
- return this.rawText;
1743
- },
1744
- enumerable: false,
1745
- configurable: true
1746
- });
1747
- CommentNode.prototype.toString = function () {
1748
- return "<!--".concat(this.rawText, "-->");
1749
- };
1750
- return CommentNode;
1751
- }(node_3.default));
1752
- exports.default = CommentNode;
1753
- });
1754
- define("parse", ["require", "exports", "nodes/html"], function (require, exports, html_1) {
1755
- "use strict";
1756
- Object.defineProperty(exports, "__esModule", { value: true });
1757
- exports.default = void 0;
1758
- Object.defineProperty(exports, "default", { enumerable: true, get: function () { return html_1.parse; } });
1759
- });
1760
- define("valid", ["require", "exports", "nodes/html"], function (require, exports, html_2) {
1761
- "use strict";
1762
- Object.defineProperty(exports, "__esModule", { value: true });
1763
- /**
1764
- * Parses HTML and returns a root element
1765
- * Parse a chuck of HTML source.
1766
- */
1767
- function valid(data, options) {
1768
- if (options === void 0) { options = {}; }
1769
- var stack = (0, html_2.base_parse)(data, options);
1770
- return Boolean(stack.length === 1);
1771
- }
1772
- exports.default = valid;
1773
- });
1774
- define("index", ["require", "exports", "nodes/comment", "nodes/html", "nodes/node", "nodes/text", "nodes/type", "parse", "valid"], function (require, exports, comment_2, html_3, node_4, text_2, type_5, parse_1, valid_1) {
1775
- "use strict";
1776
- Object.defineProperty(exports, "__esModule", { value: true });
1777
- exports.NodeType = exports.TextNode = exports.Node = exports.valid = exports.CommentNode = exports.HTMLElement = exports.parse = void 0;
1778
- comment_2 = __importDefault(comment_2);
1779
- html_3 = __importDefault(html_3);
1780
- node_4 = __importDefault(node_4);
1781
- text_2 = __importDefault(text_2);
1782
- type_5 = __importDefault(type_5);
1783
- parse_1 = __importDefault(parse_1);
1784
- valid_1 = __importDefault(valid_1);
1785
- exports.CommentNode = comment_2.default;
1786
- exports.HTMLElement = html_3.default;
1787
- exports.Node = node_4.default;
1788
- exports.TextNode = text_2.default;
1789
- exports.NodeType = type_5.default;
1790
- exports.valid = valid_1.default;
1791
- function parse(data, options) {
1792
- if (options === void 0) { options = {}; }
1793
- return (0, parse_1.default)(data, options);
1794
- }
1795
- exports.default = parse;
1796
- exports.parse = parse;
1797
- parse.parse = parse_1.default;
1798
- parse.HTMLElement = html_3.default;
1799
- parse.CommentNode = comment_2.default;
1800
- parse.valid = valid_1.default;
1801
- parse.Node = node_4.default;
1802
- parse.TextNode = text_2.default;
1803
- parse.NodeType = type_5.default;
1804
- });