@mtkruto/node 0.1.200 → 0.1.201

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 (97) hide show
  1. package/esm/client/4_client.d.ts +5 -8
  2. package/esm/client/4_client.js +5 -14
  3. package/package.json +1 -1
  4. package/script/client/4_client.d.ts +5 -8
  5. package/script/client/4_client.js +5 -14
  6. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/DomHandler.d.ts +0 -83
  7. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/DomHandler.js +0 -203
  8. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/DomSerializer.d.ts +0 -50
  9. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/DomSerializer.js +0 -274
  10. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/ElementType.d.ts +0 -47
  11. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/ElementType.js +0 -51
  12. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/FeedHandler.d.ts +0 -66
  13. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/FeedHandler.js +0 -191
  14. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Node.d.ts +0 -168
  15. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Node.js +0 -385
  16. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Parser.d.ts +0 -159
  17. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Parser.js +0 -431
  18. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Tokenizer.d.ts +0 -181
  19. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Tokenizer.js +0 -1046
  20. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/mod.d.ts +0 -42
  21. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/mod.js +0 -52
  22. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode.d.ts +0 -11
  23. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode.js +0 -122
  24. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode_codepoint.d.ts +0 -1
  25. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode_codepoint.js +0 -24
  26. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/encode.d.ts +0 -46
  27. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/encode.js +0 -121
  28. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/decode.d.ts +0 -31
  29. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/decode.js +0 -30
  30. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/entities.d.ts +0 -2128
  31. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/entities.js +0 -2127
  32. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/legacy.d.ts +0 -109
  33. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/legacy.js +0 -108
  34. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/xml.d.ts +0 -8
  35. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/xml.js +0 -1
  36. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/mod.d.ts +0 -90
  37. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/mod.js +0 -95
  38. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/helpers.d.ts +0 -50
  39. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/helpers.js +0 -128
  40. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/legacy.d.ts +0 -46
  41. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/legacy.js +0 -110
  42. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/manipulation.d.ts +0 -42
  43. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/manipulation.js +0 -120
  44. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/mod.d.ts +0 -6
  45. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/mod.js +0 -6
  46. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/querying.d.ts +0 -54
  47. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/querying.js +0 -110
  48. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/stringify.d.ts +0 -40
  49. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/stringify.js +0 -75
  50. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/traversal.d.ts +0 -58
  51. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/traversal.js +0 -101
  52. package/script/deps/deno.land/x/html_parser@v0.1.3/src/DomHandler.d.ts +0 -83
  53. package/script/deps/deno.land/x/html_parser@v0.1.3/src/DomHandler.js +0 -207
  54. package/script/deps/deno.land/x/html_parser@v0.1.3/src/DomSerializer.d.ts +0 -50
  55. package/script/deps/deno.land/x/html_parser@v0.1.3/src/DomSerializer.js +0 -301
  56. package/script/deps/deno.land/x/html_parser@v0.1.3/src/ElementType.d.ts +0 -47
  57. package/script/deps/deno.land/x/html_parser@v0.1.3/src/ElementType.js +0 -55
  58. package/script/deps/deno.land/x/html_parser@v0.1.3/src/FeedHandler.d.ts +0 -66
  59. package/script/deps/deno.land/x/html_parser@v0.1.3/src/FeedHandler.js +0 -222
  60. package/script/deps/deno.land/x/html_parser@v0.1.3/src/Node.d.ts +0 -168
  61. package/script/deps/deno.land/x/html_parser@v0.1.3/src/Node.js +0 -404
  62. package/script/deps/deno.land/x/html_parser@v0.1.3/src/Parser.d.ts +0 -159
  63. package/script/deps/deno.land/x/html_parser@v0.1.3/src/Parser.js +0 -438
  64. package/script/deps/deno.land/x/html_parser@v0.1.3/src/Tokenizer.d.ts +0 -181
  65. package/script/deps/deno.land/x/html_parser@v0.1.3/src/Tokenizer.js +0 -1052
  66. package/script/deps/deno.land/x/html_parser@v0.1.3/src/mod.d.ts +0 -42
  67. package/script/deps/deno.land/x/html_parser@v0.1.3/src/mod.js +0 -88
  68. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode.d.ts +0 -11
  69. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode.js +0 -128
  70. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode_codepoint.d.ts +0 -1
  71. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode_codepoint.js +0 -30
  72. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/encode.d.ts +0 -46
  73. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/encode.js +0 -129
  74. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/decode.d.ts +0 -31
  75. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/decode.js +0 -32
  76. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/entities.d.ts +0 -2128
  77. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/entities.js +0 -2129
  78. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/legacy.d.ts +0 -109
  79. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/legacy.js +0 -110
  80. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/xml.d.ts +0 -8
  81. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/xml.js +0 -3
  82. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/mod.d.ts +0 -90
  83. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/mod.js +0 -114
  84. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/helpers.d.ts +0 -50
  85. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/helpers.js +0 -134
  86. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/legacy.d.ts +0 -46
  87. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/legacy.js +0 -118
  88. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/manipulation.d.ts +0 -42
  89. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/manipulation.js +0 -129
  90. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/mod.d.ts +0 -6
  91. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/mod.js +0 -22
  92. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/querying.d.ts +0 -54
  93. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/querying.js +0 -119
  94. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/stringify.d.ts +0 -40
  95. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/stringify.js +0 -86
  96. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/traversal.d.ts +0 -58
  97. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/traversal.js +0 -112
@@ -1,159 +0,0 @@
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
- }
@@ -1,438 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Parser = void 0;
7
- const Tokenizer_js_1 = __importDefault(require("./Tokenizer.js"));
8
- const formTags = new Set([
9
- 'input',
10
- 'option',
11
- 'optgroup',
12
- 'select',
13
- 'button',
14
- 'datalist',
15
- 'textarea',
16
- ]);
17
- const pTag = new Set(['p']);
18
- const openImpliesClose = {
19
- tr: new Set(['tr', 'th', 'td']),
20
- th: new Set(['th']),
21
- td: new Set(['thead', 'th', 'td']),
22
- body: new Set(['head', 'link', 'script']),
23
- li: new Set(['li']),
24
- p: pTag,
25
- h1: pTag,
26
- h2: pTag,
27
- h3: pTag,
28
- h4: pTag,
29
- h5: pTag,
30
- h6: pTag,
31
- select: formTags,
32
- input: formTags,
33
- output: formTags,
34
- button: formTags,
35
- datalist: formTags,
36
- textarea: formTags,
37
- option: new Set(['option']),
38
- optgroup: new Set(['optgroup', 'option']),
39
- dd: new Set(['dt', 'dd']),
40
- dt: new Set(['dt', 'dd']),
41
- address: pTag,
42
- article: pTag,
43
- aside: pTag,
44
- blockquote: pTag,
45
- details: pTag,
46
- div: pTag,
47
- dl: pTag,
48
- fieldset: pTag,
49
- figcaption: pTag,
50
- figure: pTag,
51
- footer: pTag,
52
- form: pTag,
53
- header: pTag,
54
- hr: pTag,
55
- main: pTag,
56
- nav: pTag,
57
- ol: pTag,
58
- pre: pTag,
59
- section: pTag,
60
- table: pTag,
61
- ul: pTag,
62
- rt: new Set(['rt', 'rp']),
63
- rp: new Set(['rt', 'rp']),
64
- tbody: new Set(['thead', 'tbody']),
65
- tfoot: new Set(['thead', 'tbody']),
66
- };
67
- const voidElements = new Set([
68
- 'area',
69
- 'base',
70
- 'basefont',
71
- 'br',
72
- 'col',
73
- 'command',
74
- 'embed',
75
- 'frame',
76
- 'hr',
77
- 'img',
78
- 'input',
79
- 'isindex',
80
- 'keygen',
81
- 'link',
82
- 'meta',
83
- 'param',
84
- 'source',
85
- 'track',
86
- 'wbr',
87
- ]);
88
- const foreignContextElements = new Set(['math', 'svg']);
89
- const htmlIntegrationElements = new Set([
90
- 'mi',
91
- 'mo',
92
- 'mn',
93
- 'ms',
94
- 'mtext',
95
- 'annotation-xml',
96
- 'foreignObject',
97
- 'desc',
98
- 'title',
99
- ]);
100
- const reNameEnd = /\s|\//;
101
- class Parser {
102
- constructor(cbs, options = {}) {
103
- /** The start index of the last event. */
104
- Object.defineProperty(this, "startIndex", {
105
- enumerable: true,
106
- configurable: true,
107
- writable: true,
108
- value: 0
109
- });
110
- /** The end index of the last event. */
111
- Object.defineProperty(this, "endIndex", {
112
- enumerable: true,
113
- configurable: true,
114
- writable: true,
115
- value: null
116
- });
117
- Object.defineProperty(this, "tagname", {
118
- enumerable: true,
119
- configurable: true,
120
- writable: true,
121
- value: ''
122
- });
123
- Object.defineProperty(this, "attribname", {
124
- enumerable: true,
125
- configurable: true,
126
- writable: true,
127
- value: ''
128
- });
129
- Object.defineProperty(this, "attribvalue", {
130
- enumerable: true,
131
- configurable: true,
132
- writable: true,
133
- value: ''
134
- });
135
- Object.defineProperty(this, "attribs", {
136
- enumerable: true,
137
- configurable: true,
138
- writable: true,
139
- value: null
140
- });
141
- Object.defineProperty(this, "stack", {
142
- enumerable: true,
143
- configurable: true,
144
- writable: true,
145
- value: []
146
- });
147
- Object.defineProperty(this, "foreignContext", {
148
- enumerable: true,
149
- configurable: true,
150
- writable: true,
151
- value: []
152
- });
153
- Object.defineProperty(this, "cbs", {
154
- enumerable: true,
155
- configurable: true,
156
- writable: true,
157
- value: void 0
158
- });
159
- Object.defineProperty(this, "options", {
160
- enumerable: true,
161
- configurable: true,
162
- writable: true,
163
- value: void 0
164
- });
165
- Object.defineProperty(this, "lowerCaseTagNames", {
166
- enumerable: true,
167
- configurable: true,
168
- writable: true,
169
- value: void 0
170
- });
171
- Object.defineProperty(this, "lowerCaseAttributeNames", {
172
- enumerable: true,
173
- configurable: true,
174
- writable: true,
175
- value: void 0
176
- });
177
- Object.defineProperty(this, "tokenizer", {
178
- enumerable: true,
179
- configurable: true,
180
- writable: true,
181
- value: void 0
182
- });
183
- this.options = options;
184
- this.cbs = cbs ?? {};
185
- this.lowerCaseTagNames = options.lowerCaseTags ?? !options.xmlMode;
186
- this.lowerCaseAttributeNames =
187
- options.lowerCaseAttributeNames ?? !options.xmlMode;
188
- this.tokenizer = new (options.Tokenizer ?? Tokenizer_js_1.default)(this.options, this);
189
- this.cbs.onparserinit?.(this);
190
- }
191
- updatePosition(initialOffset) {
192
- if (this.endIndex === null) {
193
- if (this.tokenizer.sectionStart <= initialOffset) {
194
- this.startIndex = 0;
195
- }
196
- else {
197
- this.startIndex = this.tokenizer.sectionStart - initialOffset;
198
- }
199
- }
200
- else {
201
- this.startIndex = this.endIndex + 1;
202
- }
203
- this.endIndex = this.tokenizer.getAbsoluteIndex();
204
- }
205
- // Tokenizer event handlers
206
- ontext(data) {
207
- this.updatePosition(1);
208
- this.endIndex--;
209
- this.cbs.ontext?.(data);
210
- }
211
- isVoidElement(name) {
212
- return !this.options.xmlMode && voidElements.has(name);
213
- }
214
- onopentagname(name) {
215
- if (this.lowerCaseTagNames) {
216
- name = name.toLowerCase();
217
- }
218
- this.tagname = name;
219
- if (!this.options.xmlMode &&
220
- Object.prototype.hasOwnProperty.call(openImpliesClose, name)) {
221
- let el;
222
- while (this.stack.length > 0 &&
223
- openImpliesClose[name]?.has((el = this.stack[this.stack.length - 1]))) {
224
- this.onclosetag(el);
225
- }
226
- }
227
- if (!this.isVoidElement(name)) {
228
- this.stack.push(name);
229
- if (foreignContextElements.has(name)) {
230
- this.foreignContext.push(true);
231
- }
232
- else if (htmlIntegrationElements.has(name)) {
233
- this.foreignContext.push(false);
234
- }
235
- }
236
- this.cbs.onopentagname?.(name);
237
- if (this.cbs.onopentag)
238
- this.attribs = {};
239
- }
240
- onopentagend() {
241
- this.updatePosition(1);
242
- if (this.attribs) {
243
- this.cbs.onopentag?.(this.tagname, this.attribs);
244
- this.attribs = null;
245
- }
246
- if (this.cbs.onclosetag && this.isVoidElement(this.tagname)) {
247
- this.cbs.onclosetag(this.tagname);
248
- }
249
- this.tagname = '';
250
- }
251
- onclosetag(name) {
252
- this.updatePosition(1);
253
- if (this.lowerCaseTagNames) {
254
- name = name.toLowerCase();
255
- }
256
- if (foreignContextElements.has(name) ||
257
- htmlIntegrationElements.has(name)) {
258
- this.foreignContext.pop();
259
- }
260
- if (this.stack.length && !this.isVoidElement(name)) {
261
- let pos = this.stack.lastIndexOf(name);
262
- if (pos !== -1) {
263
- if (this.cbs.onclosetag) {
264
- pos = this.stack.length - pos;
265
- while (pos--) {
266
- // We know the stack has sufficient elements.
267
- this.cbs.onclosetag(this.stack.pop());
268
- }
269
- }
270
- else
271
- this.stack.length = pos;
272
- }
273
- else if (name === 'p' && !this.options.xmlMode) {
274
- this.onopentagname(name);
275
- this.closeCurrentTag();
276
- }
277
- }
278
- else if (!this.options.xmlMode && (name === 'br' || name === 'p')) {
279
- this.onopentagname(name);
280
- this.closeCurrentTag();
281
- }
282
- }
283
- onselfclosingtag() {
284
- if (this.options.xmlMode ||
285
- this.options.recognizeSelfClosing ||
286
- this.foreignContext[this.foreignContext.length - 1]) {
287
- this.closeCurrentTag();
288
- }
289
- else {
290
- this.onopentagend();
291
- }
292
- }
293
- closeCurrentTag() {
294
- const name = this.tagname;
295
- this.onopentagend();
296
- /*
297
- * Self-closing tags will be on the top of the stack
298
- * (cheaper check than in onclosetag)
299
- */
300
- if (this.stack[this.stack.length - 1] === name) {
301
- this.cbs.onclosetag?.(name);
302
- this.stack.pop();
303
- }
304
- }
305
- onattribname(name) {
306
- if (this.lowerCaseAttributeNames) {
307
- name = name.toLowerCase();
308
- }
309
- this.attribname = name;
310
- }
311
- onattribdata(value) {
312
- this.attribvalue += value;
313
- }
314
- onattribend(quote) {
315
- this.cbs.onattribute?.(this.attribname, this.attribvalue, quote);
316
- if (this.attribs &&
317
- !Object.prototype.hasOwnProperty.call(this.attribs, this.attribname)) {
318
- this.attribs[this.attribname] = this.attribvalue;
319
- }
320
- this.attribname = '';
321
- this.attribvalue = '';
322
- }
323
- getInstructionName(value) {
324
- const idx = value.search(reNameEnd);
325
- let name = idx < 0 ? value : value.substr(0, idx);
326
- if (this.lowerCaseTagNames) {
327
- name = name.toLowerCase();
328
- }
329
- return name;
330
- }
331
- ondeclaration(value) {
332
- if (this.cbs.onprocessinginstruction) {
333
- const name = this.getInstructionName(value);
334
- this.cbs.onprocessinginstruction(`!${name}`, `!${value}`);
335
- }
336
- }
337
- onprocessinginstruction(value) {
338
- if (this.cbs.onprocessinginstruction) {
339
- const name = this.getInstructionName(value);
340
- this.cbs.onprocessinginstruction(`?${name}`, `?${value}`);
341
- }
342
- }
343
- oncomment(value) {
344
- this.updatePosition(4);
345
- this.cbs.oncomment?.(value);
346
- this.cbs.oncommentend?.();
347
- }
348
- oncdata(value) {
349
- this.updatePosition(1);
350
- if (this.options.xmlMode || this.options.recognizeCDATA) {
351
- this.cbs.oncdatastart?.();
352
- this.cbs.ontext?.(value);
353
- this.cbs.oncdataend?.();
354
- }
355
- else {
356
- this.oncomment(`[CDATA[${value}]]`);
357
- }
358
- }
359
- onerror(err) {
360
- this.cbs.onerror?.(err);
361
- }
362
- onend() {
363
- if (this.cbs.onclosetag) {
364
- for (let i = this.stack.length; i > 0; this.cbs.onclosetag(this.stack[--i]))
365
- ;
366
- }
367
- this.cbs.onend?.();
368
- }
369
- /**
370
- * Resets the parser to a blank state, ready to parse a new HTML document
371
- */
372
- reset() {
373
- this.cbs.onreset?.();
374
- this.tokenizer.reset();
375
- this.tagname = '';
376
- this.attribname = '';
377
- this.attribs = null;
378
- this.stack = [];
379
- this.cbs.onparserinit?.(this);
380
- }
381
- /**
382
- * Resets the parser, then parses a complete document and
383
- * pushes it to the handler.
384
- *
385
- * @param data Document to parse.
386
- */
387
- parseComplete(data) {
388
- this.reset();
389
- this.end(data);
390
- }
391
- /**
392
- * Parses a chunk of data and calls the corresponding callbacks.
393
- *
394
- * @param chunk Chunk to parse.
395
- */
396
- write(chunk) {
397
- this.tokenizer.write(chunk);
398
- }
399
- /**
400
- * Parses the end of the buffer and clears the stack, calls onend.
401
- *
402
- * @param chunk Optional final chunk to parse.
403
- */
404
- end(chunk) {
405
- this.tokenizer.end(chunk);
406
- }
407
- /**
408
- * Pauses parsing. The parser won't emit events until `resume` is called.
409
- */
410
- pause() {
411
- this.tokenizer.pause();
412
- }
413
- /**
414
- * Resumes parsing after `pause` was called.
415
- */
416
- resume() {
417
- this.tokenizer.resume();
418
- }
419
- /**
420
- * Alias of `write`, for backwards compatibility.
421
- *
422
- * @param chunk Chunk to parse.
423
- * @deprecated
424
- */
425
- parseChunk(chunk) {
426
- this.write(chunk);
427
- }
428
- /**
429
- * Alias of `end`, for backwards compatibility.
430
- *
431
- * @param chunk Optional final chunk to parse.
432
- * @deprecated
433
- */
434
- done(chunk) {
435
- this.end(chunk);
436
- }
437
- }
438
- exports.Parser = Parser;