@mtkruto/node 0.1.289 → 0.1.299

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/README.md +77 -1
  2. package/esm/client/4_client.js +1 -1
  3. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/DomHandler.d.ts +83 -0
  4. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/DomHandler.js +203 -0
  5. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/DomSerializer.d.ts +50 -0
  6. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/DomSerializer.js +274 -0
  7. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/ElementType.d.ts +47 -0
  8. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/ElementType.js +51 -0
  9. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/FeedHandler.d.ts +66 -0
  10. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/FeedHandler.js +191 -0
  11. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Node.d.ts +168 -0
  12. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Node.js +385 -0
  13. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Parser.d.ts +159 -0
  14. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Parser.js +431 -0
  15. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Tokenizer.d.ts +181 -0
  16. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Tokenizer.js +1046 -0
  17. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/mod.d.ts +42 -0
  18. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/mod.js +52 -0
  19. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode.d.ts +11 -0
  20. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode.js +122 -0
  21. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode_codepoint.d.ts +1 -0
  22. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode_codepoint.js +24 -0
  23. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/encode.d.ts +46 -0
  24. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/encode.js +121 -0
  25. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/decode.d.ts +31 -0
  26. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/decode.js +30 -0
  27. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/entities.d.ts +2128 -0
  28. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/entities.js +2127 -0
  29. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/legacy.d.ts +109 -0
  30. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/legacy.js +108 -0
  31. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/xml.d.ts +8 -0
  32. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/xml.js +1 -0
  33. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/mod.d.ts +90 -0
  34. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/mod.js +95 -0
  35. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/helpers.d.ts +50 -0
  36. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/helpers.js +128 -0
  37. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/legacy.d.ts +46 -0
  38. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/legacy.js +110 -0
  39. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/manipulation.d.ts +42 -0
  40. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/manipulation.js +120 -0
  41. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/mod.d.ts +6 -0
  42. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/mod.js +6 -0
  43. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/querying.d.ts +54 -0
  44. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/querying.js +110 -0
  45. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/stringify.d.ts +40 -0
  46. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/stringify.js +75 -0
  47. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/traversal.d.ts +58 -0
  48. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/traversal.js +101 -0
  49. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/deflate.d.ts +2 -0
  50. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/deflate.js +5 -1
  51. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/inflate.d.ts +2 -2
  52. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/inflate.js +5 -1
  53. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/zlib/crc32.js +1 -1
  54. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/zlib/deflate.js +8 -8
  55. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/zlib/inffast.js +2 -2
  56. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/zlib/inflate.js +19 -21
  57. package/esm/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/zlib/trees.js +3 -3
  58. package/package.json +1 -1
  59. package/script/client/4_client.js +1 -1
  60. package/script/deps/deno.land/x/html_parser@v0.1.3/src/DomHandler.d.ts +83 -0
  61. package/script/deps/deno.land/x/html_parser@v0.1.3/src/DomHandler.js +207 -0
  62. package/script/deps/deno.land/x/html_parser@v0.1.3/src/DomSerializer.d.ts +50 -0
  63. package/script/deps/deno.land/x/html_parser@v0.1.3/src/DomSerializer.js +301 -0
  64. package/script/deps/deno.land/x/html_parser@v0.1.3/src/ElementType.d.ts +47 -0
  65. package/script/deps/deno.land/x/html_parser@v0.1.3/src/ElementType.js +55 -0
  66. package/script/deps/deno.land/x/html_parser@v0.1.3/src/FeedHandler.d.ts +66 -0
  67. package/script/deps/deno.land/x/html_parser@v0.1.3/src/FeedHandler.js +222 -0
  68. package/script/deps/deno.land/x/html_parser@v0.1.3/src/Node.d.ts +168 -0
  69. package/script/deps/deno.land/x/html_parser@v0.1.3/src/Node.js +404 -0
  70. package/script/deps/deno.land/x/html_parser@v0.1.3/src/Parser.d.ts +159 -0
  71. package/script/deps/deno.land/x/html_parser@v0.1.3/src/Parser.js +438 -0
  72. package/script/deps/deno.land/x/html_parser@v0.1.3/src/Tokenizer.d.ts +181 -0
  73. package/script/deps/deno.land/x/html_parser@v0.1.3/src/Tokenizer.js +1052 -0
  74. package/script/deps/deno.land/x/html_parser@v0.1.3/src/mod.d.ts +42 -0
  75. package/script/deps/deno.land/x/html_parser@v0.1.3/src/mod.js +88 -0
  76. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode.d.ts +11 -0
  77. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode.js +128 -0
  78. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode_codepoint.d.ts +1 -0
  79. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode_codepoint.js +30 -0
  80. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/encode.d.ts +46 -0
  81. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/encode.js +129 -0
  82. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/decode.d.ts +31 -0
  83. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/decode.js +32 -0
  84. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/entities.d.ts +2128 -0
  85. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/entities.js +2129 -0
  86. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/legacy.d.ts +109 -0
  87. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/legacy.js +110 -0
  88. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/xml.d.ts +8 -0
  89. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/xml.js +3 -0
  90. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/mod.d.ts +90 -0
  91. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/mod.js +114 -0
  92. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/helpers.d.ts +50 -0
  93. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/helpers.js +134 -0
  94. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/legacy.d.ts +46 -0
  95. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/legacy.js +118 -0
  96. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/manipulation.d.ts +42 -0
  97. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/manipulation.js +129 -0
  98. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/mod.d.ts +6 -0
  99. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/mod.js +22 -0
  100. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/querying.d.ts +54 -0
  101. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/querying.js +119 -0
  102. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/stringify.d.ts +40 -0
  103. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/stringify.js +86 -0
  104. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/traversal.d.ts +58 -0
  105. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/traversal.js +112 -0
  106. package/script/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/deflate.d.ts +2 -0
  107. package/script/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/deflate.js +7 -1
  108. package/script/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/inflate.d.ts +2 -2
  109. package/script/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/inflate.js +7 -1
  110. package/script/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/zlib/crc32.js +1 -1
  111. package/script/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/zlib/deflate.js +8 -8
  112. package/script/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/zlib/inffast.js +2 -2
  113. package/script/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/zlib/inflate.js +19 -21
  114. package/script/deps/raw.githubusercontent.com/MTKruto/compress/main/zlib/zlib/trees.js +3 -3
@@ -0,0 +1,1052 @@
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
+ const decode_codepoint_js_1 = __importDefault(require("./utils/entities/decode_codepoint.js"));
7
+ const entities_js_1 = __importDefault(require("./utils/entities/maps/entities.js"));
8
+ const legacy_js_1 = __importDefault(require("./utils/entities/maps/legacy.js"));
9
+ const xml_js_1 = __importDefault(require("./utils/entities/maps/xml.js"));
10
+ /** All the states the tokenizer can be in. */
11
+ var State;
12
+ (function (State) {
13
+ State[State["Text"] = 1] = "Text";
14
+ State[State["BeforeTagName"] = 2] = "BeforeTagName";
15
+ State[State["InTagName"] = 3] = "InTagName";
16
+ State[State["InSelfClosingTag"] = 4] = "InSelfClosingTag";
17
+ State[State["BeforeClosingTagName"] = 5] = "BeforeClosingTagName";
18
+ State[State["InClosingTagName"] = 6] = "InClosingTagName";
19
+ State[State["AfterClosingTagName"] = 7] = "AfterClosingTagName";
20
+ // Attributes
21
+ State[State["BeforeAttributeName"] = 8] = "BeforeAttributeName";
22
+ State[State["InAttributeName"] = 9] = "InAttributeName";
23
+ State[State["AfterAttributeName"] = 10] = "AfterAttributeName";
24
+ State[State["BeforeAttributeValue"] = 11] = "BeforeAttributeValue";
25
+ State[State["InAttributeValueDq"] = 12] = "InAttributeValueDq";
26
+ State[State["InAttributeValueSq"] = 13] = "InAttributeValueSq";
27
+ State[State["InAttributeValueNq"] = 14] = "InAttributeValueNq";
28
+ // Declarations
29
+ State[State["BeforeDeclaration"] = 15] = "BeforeDeclaration";
30
+ State[State["InDeclaration"] = 16] = "InDeclaration";
31
+ // Processing instructions
32
+ State[State["InProcessingInstruction"] = 17] = "InProcessingInstruction";
33
+ // Comments
34
+ State[State["BeforeComment"] = 18] = "BeforeComment";
35
+ State[State["InComment"] = 19] = "InComment";
36
+ State[State["InSpecialComment"] = 20] = "InSpecialComment";
37
+ State[State["AfterComment1"] = 21] = "AfterComment1";
38
+ State[State["AfterComment2"] = 22] = "AfterComment2";
39
+ // Cdata
40
+ State[State["BeforeCdata1"] = 23] = "BeforeCdata1";
41
+ State[State["BeforeCdata2"] = 24] = "BeforeCdata2";
42
+ State[State["BeforeCdata3"] = 25] = "BeforeCdata3";
43
+ State[State["BeforeCdata4"] = 26] = "BeforeCdata4";
44
+ State[State["BeforeCdata5"] = 27] = "BeforeCdata5";
45
+ State[State["BeforeCdata6"] = 28] = "BeforeCdata6";
46
+ State[State["InCdata"] = 29] = "InCdata";
47
+ State[State["AfterCdata1"] = 30] = "AfterCdata1";
48
+ State[State["AfterCdata2"] = 31] = "AfterCdata2";
49
+ // Special tags
50
+ State[State["BeforeSpecialS"] = 32] = "BeforeSpecialS";
51
+ State[State["BeforeSpecialSEnd"] = 33] = "BeforeSpecialSEnd";
52
+ State[State["BeforeScript1"] = 34] = "BeforeScript1";
53
+ State[State["BeforeScript2"] = 35] = "BeforeScript2";
54
+ State[State["BeforeScript3"] = 36] = "BeforeScript3";
55
+ State[State["BeforeScript4"] = 37] = "BeforeScript4";
56
+ State[State["BeforeScript5"] = 38] = "BeforeScript5";
57
+ State[State["AfterScript1"] = 39] = "AfterScript1";
58
+ State[State["AfterScript2"] = 40] = "AfterScript2";
59
+ State[State["AfterScript3"] = 41] = "AfterScript3";
60
+ State[State["AfterScript4"] = 42] = "AfterScript4";
61
+ State[State["AfterScript5"] = 43] = "AfterScript5";
62
+ State[State["BeforeStyle1"] = 44] = "BeforeStyle1";
63
+ State[State["BeforeStyle2"] = 45] = "BeforeStyle2";
64
+ State[State["BeforeStyle3"] = 46] = "BeforeStyle3";
65
+ State[State["BeforeStyle4"] = 47] = "BeforeStyle4";
66
+ State[State["AfterStyle1"] = 48] = "AfterStyle1";
67
+ State[State["AfterStyle2"] = 49] = "AfterStyle2";
68
+ State[State["AfterStyle3"] = 50] = "AfterStyle3";
69
+ State[State["AfterStyle4"] = 51] = "AfterStyle4";
70
+ State[State["BeforeSpecialT"] = 52] = "BeforeSpecialT";
71
+ State[State["BeforeSpecialTEnd"] = 53] = "BeforeSpecialTEnd";
72
+ State[State["BeforeTitle1"] = 54] = "BeforeTitle1";
73
+ State[State["BeforeTitle2"] = 55] = "BeforeTitle2";
74
+ State[State["BeforeTitle3"] = 56] = "BeforeTitle3";
75
+ State[State["BeforeTitle4"] = 57] = "BeforeTitle4";
76
+ State[State["AfterTitle1"] = 58] = "AfterTitle1";
77
+ State[State["AfterTitle2"] = 59] = "AfterTitle2";
78
+ State[State["AfterTitle3"] = 60] = "AfterTitle3";
79
+ State[State["AfterTitle4"] = 61] = "AfterTitle4";
80
+ State[State["BeforeEntity"] = 62] = "BeforeEntity";
81
+ State[State["BeforeNumericEntity"] = 63] = "BeforeNumericEntity";
82
+ State[State["InNamedEntity"] = 64] = "InNamedEntity";
83
+ State[State["InNumericEntity"] = 65] = "InNumericEntity";
84
+ State[State["InHexEntity"] = 66] = "InHexEntity";
85
+ })(State || (State = {}));
86
+ var Special;
87
+ (function (Special) {
88
+ Special[Special["None"] = 1] = "None";
89
+ Special[Special["Script"] = 2] = "Script";
90
+ Special[Special["Style"] = 3] = "Style";
91
+ Special[Special["Title"] = 4] = "Title";
92
+ })(Special || (Special = {}));
93
+ function whitespace(c) {
94
+ return c === ' ' || c === '\n' || c === '\t' || c === '\f' || c === '\r';
95
+ }
96
+ function isASCIIAlpha(c) {
97
+ return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
98
+ }
99
+ function ifElseState(upper, SUCCESS, FAILURE) {
100
+ const lower = upper.toLowerCase();
101
+ if (upper === lower) {
102
+ return (t, c) => {
103
+ if (c === lower) {
104
+ t._state = SUCCESS;
105
+ }
106
+ else {
107
+ t._state = FAILURE;
108
+ t._index--;
109
+ }
110
+ };
111
+ }
112
+ return (t, c) => {
113
+ if (c === lower || c === upper) {
114
+ t._state = SUCCESS;
115
+ }
116
+ else {
117
+ t._state = FAILURE;
118
+ t._index--;
119
+ }
120
+ };
121
+ }
122
+ function consumeSpecialNameChar(upper, NEXT_STATE) {
123
+ const lower = upper.toLowerCase();
124
+ return (t, c) => {
125
+ if (c === lower || c === upper) {
126
+ t._state = NEXT_STATE;
127
+ }
128
+ else {
129
+ t._state = State.InTagName;
130
+ t._index--; // Consume the token again
131
+ }
132
+ };
133
+ }
134
+ const stateBeforeCdata1 = ifElseState('C', State.BeforeCdata2, State.InDeclaration);
135
+ const stateBeforeCdata2 = ifElseState('D', State.BeforeCdata3, State.InDeclaration);
136
+ const stateBeforeCdata3 = ifElseState('A', State.BeforeCdata4, State.InDeclaration);
137
+ const stateBeforeCdata4 = ifElseState('T', State.BeforeCdata5, State.InDeclaration);
138
+ const stateBeforeCdata5 = ifElseState('A', State.BeforeCdata6, State.InDeclaration);
139
+ const stateBeforeScript1 = consumeSpecialNameChar('R', State.BeforeScript2);
140
+ const stateBeforeScript2 = consumeSpecialNameChar('I', State.BeforeScript3);
141
+ const stateBeforeScript3 = consumeSpecialNameChar('P', State.BeforeScript4);
142
+ const stateBeforeScript4 = consumeSpecialNameChar('T', State.BeforeScript5);
143
+ const stateAfterScript1 = ifElseState('R', State.AfterScript2, State.Text);
144
+ const stateAfterScript2 = ifElseState('I', State.AfterScript3, State.Text);
145
+ const stateAfterScript3 = ifElseState('P', State.AfterScript4, State.Text);
146
+ const stateAfterScript4 = ifElseState('T', State.AfterScript5, State.Text);
147
+ const stateBeforeStyle1 = consumeSpecialNameChar('Y', State.BeforeStyle2);
148
+ const stateBeforeStyle2 = consumeSpecialNameChar('L', State.BeforeStyle3);
149
+ const stateBeforeStyle3 = consumeSpecialNameChar('E', State.BeforeStyle4);
150
+ const stateAfterStyle1 = ifElseState('Y', State.AfterStyle2, State.Text);
151
+ const stateAfterStyle2 = ifElseState('L', State.AfterStyle3, State.Text);
152
+ const stateAfterStyle3 = ifElseState('E', State.AfterStyle4, State.Text);
153
+ const stateBeforeSpecialT = consumeSpecialNameChar('I', State.BeforeTitle1);
154
+ const stateBeforeTitle1 = consumeSpecialNameChar('T', State.BeforeTitle2);
155
+ const stateBeforeTitle2 = consumeSpecialNameChar('L', State.BeforeTitle3);
156
+ const stateBeforeTitle3 = consumeSpecialNameChar('E', State.BeforeTitle4);
157
+ const stateAfterSpecialTEnd = ifElseState('I', State.AfterTitle1, State.Text);
158
+ const stateAfterTitle1 = ifElseState('T', State.AfterTitle2, State.Text);
159
+ const stateAfterTitle2 = ifElseState('L', State.AfterTitle3, State.Text);
160
+ const stateAfterTitle3 = ifElseState('E', State.AfterTitle4, State.Text);
161
+ const stateBeforeEntity = ifElseState('#', State.BeforeNumericEntity, State.InNamedEntity);
162
+ const stateBeforeNumericEntity = ifElseState('X', State.InHexEntity, State.InNumericEntity);
163
+ class Tokenizer {
164
+ constructor(options, cbs) {
165
+ /** The current state the tokenizer is in. */
166
+ Object.defineProperty(this, "_state", {
167
+ enumerable: true,
168
+ configurable: true,
169
+ writable: true,
170
+ value: State.Text
171
+ });
172
+ /** The read buffer. */
173
+ Object.defineProperty(this, "buffer", {
174
+ enumerable: true,
175
+ configurable: true,
176
+ writable: true,
177
+ value: ''
178
+ });
179
+ /** The beginning of the section that is currently being read. */
180
+ Object.defineProperty(this, "sectionStart", {
181
+ enumerable: true,
182
+ configurable: true,
183
+ writable: true,
184
+ value: 0
185
+ });
186
+ /** The index within the buffer that we are currently looking at. */
187
+ Object.defineProperty(this, "_index", {
188
+ enumerable: true,
189
+ configurable: true,
190
+ writable: true,
191
+ value: 0
192
+ });
193
+ /**
194
+ * Data that has already been processed will be removed from the buffer occasionally.
195
+ * `_bufferOffset` keeps track of how many characters have been removed, to make sure position information is accurate.
196
+ */
197
+ Object.defineProperty(this, "bufferOffset", {
198
+ enumerable: true,
199
+ configurable: true,
200
+ writable: true,
201
+ value: 0
202
+ });
203
+ /** Some behavior, eg. when decoding entities, is done while we are in another state. This keeps track of the other state type. */
204
+ Object.defineProperty(this, "baseState", {
205
+ enumerable: true,
206
+ configurable: true,
207
+ writable: true,
208
+ value: State.Text
209
+ });
210
+ /** For special parsing behavior inside of script and style tags. */
211
+ Object.defineProperty(this, "special", {
212
+ enumerable: true,
213
+ configurable: true,
214
+ writable: true,
215
+ value: Special.None
216
+ });
217
+ /** Indicates whether the tokenizer has been paused. */
218
+ Object.defineProperty(this, "running", {
219
+ enumerable: true,
220
+ configurable: true,
221
+ writable: true,
222
+ value: true
223
+ });
224
+ /** Indicates whether the tokenizer has finished running / `.end` has been called. */
225
+ Object.defineProperty(this, "ended", {
226
+ enumerable: true,
227
+ configurable: true,
228
+ writable: true,
229
+ value: false
230
+ });
231
+ Object.defineProperty(this, "cbs", {
232
+ enumerable: true,
233
+ configurable: true,
234
+ writable: true,
235
+ value: void 0
236
+ });
237
+ Object.defineProperty(this, "xmlMode", {
238
+ enumerable: true,
239
+ configurable: true,
240
+ writable: true,
241
+ value: void 0
242
+ });
243
+ Object.defineProperty(this, "decodeEntities", {
244
+ enumerable: true,
245
+ configurable: true,
246
+ writable: true,
247
+ value: void 0
248
+ });
249
+ this.cbs = cbs;
250
+ this.xmlMode = !!options?.xmlMode;
251
+ this.decodeEntities = options?.decodeEntities ?? true;
252
+ }
253
+ reset() {
254
+ this._state = State.Text;
255
+ this.buffer = '';
256
+ this.sectionStart = 0;
257
+ this._index = 0;
258
+ this.bufferOffset = 0;
259
+ this.baseState = State.Text;
260
+ this.special = Special.None;
261
+ this.running = true;
262
+ this.ended = false;
263
+ }
264
+ write(chunk) {
265
+ if (this.ended)
266
+ this.cbs.onerror(Error('.write() after done!'));
267
+ this.buffer += chunk;
268
+ this.parse();
269
+ }
270
+ end(chunk) {
271
+ if (this.ended)
272
+ this.cbs.onerror(Error('.end() after done!'));
273
+ if (chunk)
274
+ this.write(chunk);
275
+ this.ended = true;
276
+ if (this.running)
277
+ this.finish();
278
+ }
279
+ pause() {
280
+ this.running = false;
281
+ }
282
+ resume() {
283
+ this.running = true;
284
+ if (this._index < this.buffer.length) {
285
+ this.parse();
286
+ }
287
+ if (this.ended) {
288
+ this.finish();
289
+ }
290
+ }
291
+ /**
292
+ * The current index within all of the written data.
293
+ */
294
+ getAbsoluteIndex() {
295
+ return this.bufferOffset + this._index;
296
+ }
297
+ stateText(c) {
298
+ if (c === '<') {
299
+ if (this._index > this.sectionStart) {
300
+ this.cbs.ontext(this.getSection());
301
+ }
302
+ this._state = State.BeforeTagName;
303
+ this.sectionStart = this._index;
304
+ }
305
+ else if (this.decodeEntities &&
306
+ c === '&' &&
307
+ (this.special === Special.None || this.special === Special.Title)) {
308
+ if (this._index > this.sectionStart) {
309
+ this.cbs.ontext(this.getSection());
310
+ }
311
+ this.baseState = State.Text;
312
+ this._state = State.BeforeEntity;
313
+ this.sectionStart = this._index;
314
+ }
315
+ }
316
+ /**
317
+ * HTML only allows ASCII alpha characters (a-z and A-Z) at the beginning of a tag name.
318
+ *
319
+ * XML allows a lot more characters here (@see https://www.w3.org/TR/REC-xml/#NT-NameStartChar).
320
+ * We allow anything that wouldn't end the tag.
321
+ */
322
+ isTagStartChar(c) {
323
+ return (isASCIIAlpha(c) ||
324
+ (this.xmlMode && !whitespace(c) && c !== '/' && c !== '>'));
325
+ }
326
+ stateBeforeTagName(c) {
327
+ if (c === '/') {
328
+ this._state = State.BeforeClosingTagName;
329
+ }
330
+ else if (c === '<') {
331
+ this.cbs.ontext(this.getSection());
332
+ this.sectionStart = this._index;
333
+ }
334
+ else if (c === '>' ||
335
+ this.special !== Special.None ||
336
+ whitespace(c)) {
337
+ this._state = State.Text;
338
+ }
339
+ else if (c === '!') {
340
+ this._state = State.BeforeDeclaration;
341
+ this.sectionStart = this._index + 1;
342
+ }
343
+ else if (c === '?') {
344
+ this._state = State.InProcessingInstruction;
345
+ this.sectionStart = this._index + 1;
346
+ }
347
+ else if (!this.isTagStartChar(c)) {
348
+ this._state = State.Text;
349
+ }
350
+ else {
351
+ this._state =
352
+ !this.xmlMode && (c === 's' || c === 'S')
353
+ ? State.BeforeSpecialS
354
+ : !this.xmlMode && (c === 't' || c === 'T')
355
+ ? State.BeforeSpecialT
356
+ : State.InTagName;
357
+ this.sectionStart = this._index;
358
+ }
359
+ }
360
+ stateInTagName(c) {
361
+ if (c === '/' || c === '>' || whitespace(c)) {
362
+ this.emitToken('onopentagname');
363
+ this._state = State.BeforeAttributeName;
364
+ this._index--;
365
+ }
366
+ }
367
+ stateBeforeClosingTagName(c) {
368
+ if (whitespace(c)) {
369
+ // Ignore
370
+ }
371
+ else if (c === '>') {
372
+ this._state = State.Text;
373
+ }
374
+ else if (this.special !== Special.None) {
375
+ if (this.special !== Special.Title && (c === 's' || c === 'S')) {
376
+ this._state = State.BeforeSpecialSEnd;
377
+ }
378
+ else if (this.special === Special.Title &&
379
+ (c === 't' || c === 'T')) {
380
+ this._state = State.BeforeSpecialTEnd;
381
+ }
382
+ else {
383
+ this._state = State.Text;
384
+ this._index--;
385
+ }
386
+ }
387
+ else if (!this.isTagStartChar(c)) {
388
+ this._state = State.InSpecialComment;
389
+ this.sectionStart = this._index;
390
+ }
391
+ else {
392
+ this._state = State.InClosingTagName;
393
+ this.sectionStart = this._index;
394
+ }
395
+ }
396
+ stateInClosingTagName(c) {
397
+ if (c === '>' || whitespace(c)) {
398
+ this.emitToken('onclosetag');
399
+ this._state = State.AfterClosingTagName;
400
+ this._index--;
401
+ }
402
+ }
403
+ stateAfterClosingTagName(c) {
404
+ // Skip everything until ">"
405
+ if (c === '>') {
406
+ this._state = State.Text;
407
+ this.sectionStart = this._index + 1;
408
+ }
409
+ }
410
+ stateBeforeAttributeName(c) {
411
+ if (c === '>') {
412
+ this.cbs.onopentagend();
413
+ this._state = State.Text;
414
+ this.sectionStart = this._index + 1;
415
+ }
416
+ else if (c === '/') {
417
+ this._state = State.InSelfClosingTag;
418
+ }
419
+ else if (!whitespace(c)) {
420
+ this._state = State.InAttributeName;
421
+ this.sectionStart = this._index;
422
+ }
423
+ }
424
+ stateInSelfClosingTag(c) {
425
+ if (c === '>') {
426
+ this.cbs.onselfclosingtag();
427
+ this._state = State.Text;
428
+ this.sectionStart = this._index + 1;
429
+ this.special = Special.None; // Reset special state, in case of self-closing special tags
430
+ }
431
+ else if (!whitespace(c)) {
432
+ this._state = State.BeforeAttributeName;
433
+ this._index--;
434
+ }
435
+ }
436
+ stateInAttributeName(c) {
437
+ if (c === '=' || c === '/' || c === '>' || whitespace(c)) {
438
+ this.cbs.onattribname(this.getSection());
439
+ this.sectionStart = -1;
440
+ this._state = State.AfterAttributeName;
441
+ this._index--;
442
+ }
443
+ }
444
+ stateAfterAttributeName(c) {
445
+ if (c === '=') {
446
+ this._state = State.BeforeAttributeValue;
447
+ }
448
+ else if (c === '/' || c === '>') {
449
+ this.cbs.onattribend(undefined);
450
+ this._state = State.BeforeAttributeName;
451
+ this._index--;
452
+ }
453
+ else if (!whitespace(c)) {
454
+ this.cbs.onattribend(undefined);
455
+ this._state = State.InAttributeName;
456
+ this.sectionStart = this._index;
457
+ }
458
+ }
459
+ stateBeforeAttributeValue(c) {
460
+ if (c === '"') {
461
+ this._state = State.InAttributeValueDq;
462
+ this.sectionStart = this._index + 1;
463
+ }
464
+ else if (c === "'") {
465
+ this._state = State.InAttributeValueSq;
466
+ this.sectionStart = this._index + 1;
467
+ }
468
+ else if (!whitespace(c)) {
469
+ this._state = State.InAttributeValueNq;
470
+ this.sectionStart = this._index;
471
+ this._index--; // Reconsume token
472
+ }
473
+ }
474
+ handleInAttributeValue(c, quote) {
475
+ if (c === quote) {
476
+ this.emitToken('onattribdata');
477
+ this.cbs.onattribend(quote);
478
+ this._state = State.BeforeAttributeName;
479
+ }
480
+ else if (this.decodeEntities && c === '&') {
481
+ this.emitToken('onattribdata');
482
+ this.baseState = this._state;
483
+ this._state = State.BeforeEntity;
484
+ this.sectionStart = this._index;
485
+ }
486
+ }
487
+ stateInAttributeValueDoubleQuotes(c) {
488
+ this.handleInAttributeValue(c, '"');
489
+ }
490
+ stateInAttributeValueSingleQuotes(c) {
491
+ this.handleInAttributeValue(c, "'");
492
+ }
493
+ stateInAttributeValueNoQuotes(c) {
494
+ if (whitespace(c) || c === '>') {
495
+ this.emitToken('onattribdata');
496
+ this.cbs.onattribend(null);
497
+ this._state = State.BeforeAttributeName;
498
+ this._index--;
499
+ }
500
+ else if (this.decodeEntities && c === '&') {
501
+ this.emitToken('onattribdata');
502
+ this.baseState = this._state;
503
+ this._state = State.BeforeEntity;
504
+ this.sectionStart = this._index;
505
+ }
506
+ }
507
+ stateBeforeDeclaration(c) {
508
+ this._state =
509
+ c === '['
510
+ ? State.BeforeCdata1
511
+ : c === '-'
512
+ ? State.BeforeComment
513
+ : State.InDeclaration;
514
+ }
515
+ stateInDeclaration(c) {
516
+ if (c === '>') {
517
+ this.cbs.ondeclaration(this.getSection());
518
+ this._state = State.Text;
519
+ this.sectionStart = this._index + 1;
520
+ }
521
+ }
522
+ stateInProcessingInstruction(c) {
523
+ if (c === '>') {
524
+ this.cbs.onprocessinginstruction(this.getSection());
525
+ this._state = State.Text;
526
+ this.sectionStart = this._index + 1;
527
+ }
528
+ }
529
+ stateBeforeComment(c) {
530
+ if (c === '-') {
531
+ this._state = State.InComment;
532
+ this.sectionStart = this._index + 1;
533
+ }
534
+ else {
535
+ this._state = State.InDeclaration;
536
+ }
537
+ }
538
+ stateInComment(c) {
539
+ if (c === '-')
540
+ this._state = State.AfterComment1;
541
+ }
542
+ stateInSpecialComment(c) {
543
+ if (c === '>') {
544
+ this.cbs.oncomment(this.buffer.substring(this.sectionStart, this._index));
545
+ this._state = State.Text;
546
+ this.sectionStart = this._index + 1;
547
+ }
548
+ }
549
+ stateAfterComment1(c) {
550
+ if (c === '-') {
551
+ this._state = State.AfterComment2;
552
+ }
553
+ else {
554
+ this._state = State.InComment;
555
+ }
556
+ }
557
+ stateAfterComment2(c) {
558
+ if (c === '>') {
559
+ // Remove 2 trailing chars
560
+ this.cbs.oncomment(this.buffer.substring(this.sectionStart, this._index - 2));
561
+ this._state = State.Text;
562
+ this.sectionStart = this._index + 1;
563
+ }
564
+ else if (c !== '-') {
565
+ this._state = State.InComment;
566
+ }
567
+ // Else: stay in AFTER_COMMENT_2 (`--->`)
568
+ }
569
+ stateBeforeCdata6(c) {
570
+ if (c === '[') {
571
+ this._state = State.InCdata;
572
+ this.sectionStart = this._index + 1;
573
+ }
574
+ else {
575
+ this._state = State.InDeclaration;
576
+ this._index--;
577
+ }
578
+ }
579
+ stateInCdata(c) {
580
+ if (c === ']')
581
+ this._state = State.AfterCdata1;
582
+ }
583
+ stateAfterCdata1(c) {
584
+ if (c === ']')
585
+ this._state = State.AfterCdata2;
586
+ else
587
+ this._state = State.InCdata;
588
+ }
589
+ stateAfterCdata2(c) {
590
+ if (c === '>') {
591
+ // Remove 2 trailing chars
592
+ this.cbs.oncdata(this.buffer.substring(this.sectionStart, this._index - 2));
593
+ this._state = State.Text;
594
+ this.sectionStart = this._index + 1;
595
+ }
596
+ else if (c !== ']') {
597
+ this._state = State.InCdata;
598
+ }
599
+ // Else: stay in AFTER_CDATA_2 (`]]]>`)
600
+ }
601
+ stateBeforeSpecialS(c) {
602
+ if (c === 'c' || c === 'C') {
603
+ this._state = State.BeforeScript1;
604
+ }
605
+ else if (c === 't' || c === 'T') {
606
+ this._state = State.BeforeStyle1;
607
+ }
608
+ else {
609
+ this._state = State.InTagName;
610
+ this._index--; // Consume the token again
611
+ }
612
+ }
613
+ stateBeforeSpecialSEnd(c) {
614
+ if (this.special === Special.Script && (c === 'c' || c === 'C')) {
615
+ this._state = State.AfterScript1;
616
+ }
617
+ else if (this.special === Special.Style && (c === 't' || c === 'T')) {
618
+ this._state = State.AfterStyle1;
619
+ }
620
+ else
621
+ this._state = State.Text;
622
+ }
623
+ stateBeforeSpecialLast(c, special) {
624
+ if (c === '/' || c === '>' || whitespace(c)) {
625
+ this.special = special;
626
+ }
627
+ this._state = State.InTagName;
628
+ this._index--; // Consume the token again
629
+ }
630
+ stateAfterSpecialLast(c, sectionStartOffset) {
631
+ if (c === '>' || whitespace(c)) {
632
+ this.special = Special.None;
633
+ this._state = State.InClosingTagName;
634
+ this.sectionStart = this._index - sectionStartOffset;
635
+ this._index--; // Reconsume the token
636
+ }
637
+ else
638
+ this._state = State.Text;
639
+ }
640
+ // For entities terminated with a semicolon
641
+ parseFixedEntity(map = this.xmlMode ? xml_js_1.default : entities_js_1.default) {
642
+ // Offset = 1
643
+ if (this.sectionStart + 1 < this._index) {
644
+ const entity = this.buffer.substring(this.sectionStart + 1, this._index);
645
+ if (Object.prototype.hasOwnProperty.call(map, entity)) {
646
+ this.emitPartial(map[entity]);
647
+ this.sectionStart = this._index + 1;
648
+ }
649
+ }
650
+ }
651
+ // Parses legacy entities (without trailing semicolon)
652
+ parseLegacyEntity() {
653
+ const start = this.sectionStart + 1;
654
+ // The max length of legacy entities is 6
655
+ let limit = Math.min(this._index - start, 6);
656
+ while (limit >= 2) {
657
+ // The min length of legacy entities is 2
658
+ const entity = this.buffer.substr(start, limit);
659
+ if (Object.prototype.hasOwnProperty.call(legacy_js_1.default, entity)) {
660
+ this.emitPartial(legacy_js_1.default[entity]);
661
+ this.sectionStart += limit + 1;
662
+ return;
663
+ }
664
+ limit--;
665
+ }
666
+ }
667
+ stateInNamedEntity(c) {
668
+ if (c === ';') {
669
+ this.parseFixedEntity();
670
+ // Retry as legacy entity if entity wasn't parsed
671
+ if (this.baseState === State.Text &&
672
+ this.sectionStart + 1 < this._index &&
673
+ !this.xmlMode) {
674
+ this.parseLegacyEntity();
675
+ }
676
+ this._state = this.baseState;
677
+ }
678
+ else if ((c < '0' || c > '9') && !isASCIIAlpha(c)) {
679
+ if (this.xmlMode || this.sectionStart + 1 === this._index) {
680
+ // Ignore
681
+ }
682
+ else if (this.baseState !== State.Text) {
683
+ if (c !== '=') {
684
+ // Parse as legacy entity, without allowing additional characters.
685
+ this.parseFixedEntity(legacy_js_1.default);
686
+ }
687
+ }
688
+ else {
689
+ this.parseLegacyEntity();
690
+ }
691
+ this._state = this.baseState;
692
+ this._index--;
693
+ }
694
+ }
695
+ decodeNumericEntity(offset, base, strict) {
696
+ const sectionStart = this.sectionStart + offset;
697
+ if (sectionStart !== this._index) {
698
+ // Parse entity
699
+ const entity = this.buffer.substring(sectionStart, this._index);
700
+ const parsed = parseInt(entity, base);
701
+ this.emitPartial((0, decode_codepoint_js_1.default)(parsed));
702
+ this.sectionStart = strict ? this._index + 1 : this._index;
703
+ }
704
+ this._state = this.baseState;
705
+ }
706
+ stateInNumericEntity(c) {
707
+ if (c === ';') {
708
+ this.decodeNumericEntity(2, 10, true);
709
+ }
710
+ else if (c < '0' || c > '9') {
711
+ if (!this.xmlMode) {
712
+ this.decodeNumericEntity(2, 10, false);
713
+ }
714
+ else {
715
+ this._state = this.baseState;
716
+ }
717
+ this._index--;
718
+ }
719
+ }
720
+ stateInHexEntity(c) {
721
+ if (c === ';') {
722
+ this.decodeNumericEntity(3, 16, true);
723
+ }
724
+ else if ((c < 'a' || c > 'f') &&
725
+ (c < 'A' || c > 'F') &&
726
+ (c < '0' || c > '9')) {
727
+ if (!this.xmlMode) {
728
+ this.decodeNumericEntity(3, 16, false);
729
+ }
730
+ else {
731
+ this._state = this.baseState;
732
+ }
733
+ this._index--;
734
+ }
735
+ }
736
+ cleanup() {
737
+ if (this.sectionStart < 0) {
738
+ this.buffer = '';
739
+ this.bufferOffset += this._index;
740
+ this._index = 0;
741
+ }
742
+ else if (this.running) {
743
+ if (this._state === State.Text) {
744
+ if (this.sectionStart !== this._index) {
745
+ this.cbs.ontext(this.buffer.substr(this.sectionStart));
746
+ }
747
+ this.buffer = '';
748
+ this.bufferOffset += this._index;
749
+ this._index = 0;
750
+ }
751
+ else if (this.sectionStart === this._index) {
752
+ // The section just started
753
+ this.buffer = '';
754
+ this.bufferOffset += this._index;
755
+ this._index = 0;
756
+ }
757
+ else {
758
+ // Remove everything unnecessary
759
+ this.buffer = this.buffer.substr(this.sectionStart);
760
+ this._index -= this.sectionStart;
761
+ this.bufferOffset += this.sectionStart;
762
+ }
763
+ this.sectionStart = 0;
764
+ }
765
+ }
766
+ /**
767
+ * Iterates through the buffer, calling the function corresponding to the current state.
768
+ *
769
+ * States that are more likely to be hit are higher up, as a performance improvement.
770
+ */
771
+ parse() {
772
+ while (this._index < this.buffer.length && this.running) {
773
+ const c = this.buffer.charAt(this._index);
774
+ if (this._state === State.Text) {
775
+ this.stateText(c);
776
+ }
777
+ else if (this._state === State.InAttributeValueDq) {
778
+ this.stateInAttributeValueDoubleQuotes(c);
779
+ }
780
+ else if (this._state === State.InAttributeName) {
781
+ this.stateInAttributeName(c);
782
+ }
783
+ else if (this._state === State.InComment) {
784
+ this.stateInComment(c);
785
+ }
786
+ else if (this._state === State.InSpecialComment) {
787
+ this.stateInSpecialComment(c);
788
+ }
789
+ else if (this._state === State.BeforeAttributeName) {
790
+ this.stateBeforeAttributeName(c);
791
+ }
792
+ else if (this._state === State.InTagName) {
793
+ this.stateInTagName(c);
794
+ }
795
+ else if (this._state === State.InClosingTagName) {
796
+ this.stateInClosingTagName(c);
797
+ }
798
+ else if (this._state === State.BeforeTagName) {
799
+ this.stateBeforeTagName(c);
800
+ }
801
+ else if (this._state === State.AfterAttributeName) {
802
+ this.stateAfterAttributeName(c);
803
+ }
804
+ else if (this._state === State.InAttributeValueSq) {
805
+ this.stateInAttributeValueSingleQuotes(c);
806
+ }
807
+ else if (this._state === State.BeforeAttributeValue) {
808
+ this.stateBeforeAttributeValue(c);
809
+ }
810
+ else if (this._state === State.BeforeClosingTagName) {
811
+ this.stateBeforeClosingTagName(c);
812
+ }
813
+ else if (this._state === State.AfterClosingTagName) {
814
+ this.stateAfterClosingTagName(c);
815
+ }
816
+ else if (this._state === State.BeforeSpecialS) {
817
+ this.stateBeforeSpecialS(c);
818
+ }
819
+ else if (this._state === State.AfterComment1) {
820
+ this.stateAfterComment1(c);
821
+ }
822
+ else if (this._state === State.InAttributeValueNq) {
823
+ this.stateInAttributeValueNoQuotes(c);
824
+ }
825
+ else if (this._state === State.InSelfClosingTag) {
826
+ this.stateInSelfClosingTag(c);
827
+ }
828
+ else if (this._state === State.InDeclaration) {
829
+ this.stateInDeclaration(c);
830
+ }
831
+ else if (this._state === State.BeforeDeclaration) {
832
+ this.stateBeforeDeclaration(c);
833
+ }
834
+ else if (this._state === State.AfterComment2) {
835
+ this.stateAfterComment2(c);
836
+ }
837
+ else if (this._state === State.BeforeComment) {
838
+ this.stateBeforeComment(c);
839
+ }
840
+ else if (this._state === State.BeforeSpecialSEnd) {
841
+ this.stateBeforeSpecialSEnd(c);
842
+ }
843
+ else if (this._state === State.BeforeSpecialTEnd) {
844
+ stateAfterSpecialTEnd(this, c);
845
+ }
846
+ else if (this._state === State.AfterScript1) {
847
+ stateAfterScript1(this, c);
848
+ }
849
+ else if (this._state === State.AfterScript2) {
850
+ stateAfterScript2(this, c);
851
+ }
852
+ else if (this._state === State.AfterScript3) {
853
+ stateAfterScript3(this, c);
854
+ }
855
+ else if (this._state === State.BeforeScript1) {
856
+ stateBeforeScript1(this, c);
857
+ }
858
+ else if (this._state === State.BeforeScript2) {
859
+ stateBeforeScript2(this, c);
860
+ }
861
+ else if (this._state === State.BeforeScript3) {
862
+ stateBeforeScript3(this, c);
863
+ }
864
+ else if (this._state === State.BeforeScript4) {
865
+ stateBeforeScript4(this, c);
866
+ }
867
+ else if (this._state === State.BeforeScript5) {
868
+ this.stateBeforeSpecialLast(c, Special.Script);
869
+ }
870
+ else if (this._state === State.AfterScript4) {
871
+ stateAfterScript4(this, c);
872
+ }
873
+ else if (this._state === State.AfterScript5) {
874
+ this.stateAfterSpecialLast(c, 6);
875
+ }
876
+ else if (this._state === State.BeforeStyle1) {
877
+ stateBeforeStyle1(this, c);
878
+ }
879
+ else if (this._state === State.InCdata) {
880
+ this.stateInCdata(c);
881
+ }
882
+ else if (this._state === State.BeforeStyle2) {
883
+ stateBeforeStyle2(this, c);
884
+ }
885
+ else if (this._state === State.BeforeStyle3) {
886
+ stateBeforeStyle3(this, c);
887
+ }
888
+ else if (this._state === State.BeforeStyle4) {
889
+ this.stateBeforeSpecialLast(c, Special.Style);
890
+ }
891
+ else if (this._state === State.AfterStyle1) {
892
+ stateAfterStyle1(this, c);
893
+ }
894
+ else if (this._state === State.AfterStyle2) {
895
+ stateAfterStyle2(this, c);
896
+ }
897
+ else if (this._state === State.AfterStyle3) {
898
+ stateAfterStyle3(this, c);
899
+ }
900
+ else if (this._state === State.AfterStyle4) {
901
+ this.stateAfterSpecialLast(c, 5);
902
+ }
903
+ else if (this._state === State.BeforeSpecialT) {
904
+ stateBeforeSpecialT(this, c);
905
+ }
906
+ else if (this._state === State.BeforeTitle1) {
907
+ stateBeforeTitle1(this, c);
908
+ }
909
+ else if (this._state === State.BeforeTitle2) {
910
+ stateBeforeTitle2(this, c);
911
+ }
912
+ else if (this._state === State.BeforeTitle3) {
913
+ stateBeforeTitle3(this, c);
914
+ }
915
+ else if (this._state === State.BeforeTitle4) {
916
+ this.stateBeforeSpecialLast(c, Special.Title);
917
+ }
918
+ else if (this._state === State.AfterTitle1) {
919
+ stateAfterTitle1(this, c);
920
+ }
921
+ else if (this._state === State.AfterTitle2) {
922
+ stateAfterTitle2(this, c);
923
+ }
924
+ else if (this._state === State.AfterTitle3) {
925
+ stateAfterTitle3(this, c);
926
+ }
927
+ else if (this._state === State.AfterTitle4) {
928
+ this.stateAfterSpecialLast(c, 5);
929
+ }
930
+ else if (this._state === State.InProcessingInstruction) {
931
+ this.stateInProcessingInstruction(c);
932
+ }
933
+ else if (this._state === State.InNamedEntity) {
934
+ this.stateInNamedEntity(c);
935
+ }
936
+ else if (this._state === State.BeforeCdata1) {
937
+ stateBeforeCdata1(this, c);
938
+ }
939
+ else if (this._state === State.BeforeEntity) {
940
+ stateBeforeEntity(this, c);
941
+ }
942
+ else if (this._state === State.BeforeCdata2) {
943
+ stateBeforeCdata2(this, c);
944
+ }
945
+ else if (this._state === State.BeforeCdata3) {
946
+ stateBeforeCdata3(this, c);
947
+ }
948
+ else if (this._state === State.AfterCdata1) {
949
+ this.stateAfterCdata1(c);
950
+ }
951
+ else if (this._state === State.AfterCdata2) {
952
+ this.stateAfterCdata2(c);
953
+ }
954
+ else if (this._state === State.BeforeCdata4) {
955
+ stateBeforeCdata4(this, c);
956
+ }
957
+ else if (this._state === State.BeforeCdata5) {
958
+ stateBeforeCdata5(this, c);
959
+ }
960
+ else if (this._state === State.BeforeCdata6) {
961
+ this.stateBeforeCdata6(c);
962
+ }
963
+ else if (this._state === State.InHexEntity) {
964
+ this.stateInHexEntity(c);
965
+ }
966
+ else if (this._state === State.InNumericEntity) {
967
+ this.stateInNumericEntity(c);
968
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
969
+ }
970
+ else if (this._state === State.BeforeNumericEntity) {
971
+ stateBeforeNumericEntity(this, c);
972
+ }
973
+ else {
974
+ this.cbs.onerror(Error('unknown _state'), this._state);
975
+ }
976
+ this._index++;
977
+ }
978
+ this.cleanup();
979
+ }
980
+ finish() {
981
+ // If there is remaining data, emit it in a reasonable way
982
+ if (this.sectionStart < this._index) {
983
+ this.handleTrailingData();
984
+ }
985
+ this.cbs.onend();
986
+ }
987
+ handleTrailingData() {
988
+ const data = this.buffer.substr(this.sectionStart);
989
+ if (this._state === State.InCdata ||
990
+ this._state === State.AfterCdata1 ||
991
+ this._state === State.AfterCdata2) {
992
+ this.cbs.oncdata(data);
993
+ }
994
+ else if (this._state === State.InComment ||
995
+ this._state === State.AfterComment1 ||
996
+ this._state === State.AfterComment2) {
997
+ this.cbs.oncomment(data);
998
+ }
999
+ else if (this._state === State.InNamedEntity && !this.xmlMode) {
1000
+ this.parseLegacyEntity();
1001
+ if (this.sectionStart < this._index) {
1002
+ this._state = this.baseState;
1003
+ this.handleTrailingData();
1004
+ }
1005
+ }
1006
+ else if (this._state === State.InNumericEntity && !this.xmlMode) {
1007
+ this.decodeNumericEntity(2, 10, false);
1008
+ if (this.sectionStart < this._index) {
1009
+ this._state = this.baseState;
1010
+ this.handleTrailingData();
1011
+ }
1012
+ }
1013
+ else if (this._state === State.InHexEntity && !this.xmlMode) {
1014
+ this.decodeNumericEntity(3, 16, false);
1015
+ if (this.sectionStart < this._index) {
1016
+ this._state = this.baseState;
1017
+ this.handleTrailingData();
1018
+ }
1019
+ }
1020
+ else if (this._state !== State.InTagName &&
1021
+ this._state !== State.BeforeAttributeName &&
1022
+ this._state !== State.BeforeAttributeValue &&
1023
+ this._state !== State.AfterAttributeName &&
1024
+ this._state !== State.InAttributeName &&
1025
+ this._state !== State.InAttributeValueSq &&
1026
+ this._state !== State.InAttributeValueDq &&
1027
+ this._state !== State.InAttributeValueNq &&
1028
+ this._state !== State.InClosingTagName) {
1029
+ this.cbs.ontext(data);
1030
+ }
1031
+ /*
1032
+ * Else, ignore remaining data
1033
+ * TODO add a way to remove current tag
1034
+ */
1035
+ }
1036
+ getSection() {
1037
+ return this.buffer.substring(this.sectionStart, this._index);
1038
+ }
1039
+ emitToken(name) {
1040
+ this.cbs[name](this.getSection());
1041
+ this.sectionStart = -1;
1042
+ }
1043
+ emitPartial(value) {
1044
+ if (this.baseState !== State.Text) {
1045
+ this.cbs.onattribdata(value); // TODO implement the new event
1046
+ }
1047
+ else {
1048
+ this.cbs.ontext(value);
1049
+ }
1050
+ }
1051
+ }
1052
+ exports.default = Tokenizer;