@mtkruto/node 0.1.200 → 0.1.300

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 (231) hide show
  1. package/esm/0_deps.d.ts +1 -1
  2. package/esm/0_deps.js +2 -1
  3. package/esm/1_utilities.d.ts +1 -1
  4. package/esm/1_utilities.js +1 -1
  5. package/esm/4_errors.js +3 -3
  6. package/esm/client/0_markdown.js +5 -5
  7. package/esm/client/0_utilities.d.ts +6 -0
  8. package/esm/client/0_utilities.js +35 -4
  9. package/esm/client/1_account_manager.js +4 -4
  10. package/esm/client/1_client_encrypted.js +4 -4
  11. package/esm/client/1_client_plain.js +3 -3
  12. package/esm/client/1_file_manager.js +6 -5
  13. package/esm/client/1_reaction_manager.js +2 -2
  14. package/esm/client/1_update_manager.js +9 -8
  15. package/esm/client/2_message_manager.js +47 -24
  16. package/esm/client/3_callback_query_manager.js +2 -0
  17. package/esm/client/3_chat_list_manager.js +13 -12
  18. package/esm/client/3_inline_query_manager.js +4 -2
  19. package/esm/client/3_story_manager.js +7 -5
  20. package/esm/client/4_client.d.ts +5 -8
  21. package/esm/client/4_client.js +19 -27
  22. package/esm/connection/1_connection_web_socket.js +3 -2
  23. package/{script/deps/deno.land/x/tgcrypto@0.3.3 → esm/deps/deno.land/x/tgcrypto@0.4.0}/mod.d.ts +0 -1
  24. package/esm/deps/deno.land/x/{tgcrypto@0.3.3 → tgcrypto@0.4.0}/mod.js +0 -11
  25. package/esm/deps/deno.land/x/tgcrypto@0.4.0/tgcrypto.js +308 -0
  26. package/esm/mod.d.ts +1 -1
  27. package/esm/mod.js +1 -1
  28. package/esm/storage/0_storage.js +6 -5
  29. package/esm/storage/1_utilities.d.ts +0 -1
  30. package/esm/storage/1_utilities.js +2 -3
  31. package/esm/storage/2_storage_local_storage.js +1 -4
  32. package/esm/storage/2_storage_session_storage.js +1 -4
  33. package/esm/tl/3_utilities.js +5 -4
  34. package/esm/transport/2_transport_provider.js +4 -4
  35. package/esm/types/0_message_entity.js +3 -3
  36. package/esm/types/0_message_search_filter.js +2 -2
  37. package/esm/types/0_reaction.js +2 -2
  38. package/esm/types/1_bot_command_scope.js +3 -3
  39. package/esm/types/1_chat_p.js +3 -2
  40. package/esm/types/1_keyboard_button.js +3 -3
  41. package/esm/types/1_message_reaction.js +2 -2
  42. package/esm/types/1_story_privacy.js +3 -3
  43. package/esm/types/2_chat_member.js +6 -5
  44. package/esm/types/2_chosen_inline_result.js +3 -2
  45. package/esm/types/2_inactive_chat.js +3 -2
  46. package/esm/types/2_inline_keyboard_button.js +3 -3
  47. package/esm/types/2_inline_query.js +3 -3
  48. package/esm/types/2_invite_link.js +3 -2
  49. package/esm/types/2_story_content.js +5 -5
  50. package/esm/types/2_story_interactive_area.js +5 -5
  51. package/esm/types/3_chat_member_updated.js +4 -3
  52. package/esm/types/3_reply_markup.js +4 -3
  53. package/esm/types/3_story.js +3 -2
  54. package/esm/types/4_inline_query_result.js +5 -5
  55. package/esm/types/4_message.js +17 -16
  56. package/esm/types/5_callback_query.js +4 -3
  57. package/esm/types/5_chat.js +8 -7
  58. package/esm/types/_file_id.js +9 -8
  59. package/esm/utilities/0_bigint.d.ts +1 -0
  60. package/esm/utilities/0_bigint.js +25 -0
  61. package/esm/utilities/0_logger.d.ts +8 -0
  62. package/esm/utilities/0_logger.js +9 -5
  63. package/esm/utilities/1_math.d.ts +1 -0
  64. package/esm/utilities/1_math.js +51 -0
  65. package/esm/utilities/1_misc.js +2 -2
  66. package/package.json +1 -1
  67. package/script/0_deps.d.ts +1 -1
  68. package/script/0_deps.js +3 -3
  69. package/script/1_utilities.d.ts +1 -1
  70. package/script/1_utilities.js +1 -1
  71. package/script/4_errors.js +3 -3
  72. package/script/client/0_markdown.js +5 -5
  73. package/script/client/0_utilities.d.ts +6 -0
  74. package/script/client/0_utilities.js +41 -4
  75. package/script/client/1_account_manager.js +4 -4
  76. package/script/client/1_client_encrypted.js +2 -2
  77. package/script/client/1_client_plain.js +2 -2
  78. package/script/client/1_file_manager.js +5 -4
  79. package/script/client/1_reaction_manager.js +2 -2
  80. package/script/client/1_update_manager.js +8 -7
  81. package/script/client/2_message_manager.js +51 -28
  82. package/script/client/3_callback_query_manager.js +2 -0
  83. package/script/client/3_chat_list_manager.js +12 -11
  84. package/script/client/3_inline_query_manager.js +4 -2
  85. package/script/client/3_story_manager.js +4 -2
  86. package/script/client/4_client.d.ts +5 -8
  87. package/script/client/4_client.js +18 -26
  88. package/script/connection/1_connection_web_socket.js +2 -1
  89. package/{esm/deps/deno.land/x/tgcrypto@0.3.3 → script/deps/deno.land/x/tgcrypto@0.4.0}/mod.d.ts +0 -1
  90. package/script/deps/deno.land/x/{tgcrypto@0.3.3 → tgcrypto@0.4.0}/mod.js +1 -13
  91. package/script/deps/deno.land/x/tgcrypto@0.4.0/tgcrypto.js +310 -0
  92. package/script/mod.d.ts +1 -1
  93. package/script/mod.js +2 -1
  94. package/script/storage/0_storage.js +5 -4
  95. package/script/storage/1_utilities.d.ts +0 -1
  96. package/script/storage/1_utilities.js +3 -4
  97. package/script/storage/2_storage_local_storage.js +0 -3
  98. package/script/storage/2_storage_session_storage.js +0 -3
  99. package/script/tl/3_utilities.js +4 -3
  100. package/script/transport/2_transport_provider.js +4 -4
  101. package/script/types/0_message_entity.js +3 -3
  102. package/script/types/0_message_search_filter.js +2 -2
  103. package/script/types/0_reaction.js +2 -2
  104. package/script/types/1_bot_command_scope.js +3 -3
  105. package/script/types/1_chat_p.js +2 -1
  106. package/script/types/1_keyboard_button.js +3 -3
  107. package/script/types/1_message_reaction.js +2 -2
  108. package/script/types/1_story_privacy.js +3 -3
  109. package/script/types/2_chat_member.js +5 -4
  110. package/script/types/2_chosen_inline_result.js +2 -1
  111. package/script/types/2_inactive_chat.js +2 -1
  112. package/script/types/2_inline_keyboard_button.js +3 -3
  113. package/script/types/2_inline_query.js +3 -3
  114. package/script/types/2_invite_link.js +2 -1
  115. package/script/types/2_story_content.js +5 -5
  116. package/script/types/2_story_interactive_area.js +5 -5
  117. package/script/types/3_chat_member_updated.js +3 -2
  118. package/script/types/3_reply_markup.js +3 -2
  119. package/script/types/3_story.js +2 -1
  120. package/script/types/4_inline_query_result.js +5 -5
  121. package/script/types/4_message.js +16 -15
  122. package/script/types/5_callback_query.js +3 -2
  123. package/script/types/5_chat.js +7 -6
  124. package/script/types/_file_id.js +8 -7
  125. package/script/utilities/0_bigint.d.ts +1 -0
  126. package/script/utilities/0_bigint.js +27 -1
  127. package/script/utilities/0_logger.d.ts +8 -0
  128. package/script/utilities/0_logger.js +11 -6
  129. package/script/utilities/1_math.d.ts +1 -0
  130. package/script/utilities/1_math.js +55 -0
  131. package/script/utilities/1_misc.js +2 -2
  132. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/DomHandler.d.ts +0 -83
  133. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/DomHandler.js +0 -203
  134. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/DomSerializer.d.ts +0 -50
  135. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/DomSerializer.js +0 -274
  136. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/ElementType.d.ts +0 -47
  137. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/ElementType.js +0 -51
  138. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/FeedHandler.d.ts +0 -66
  139. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/FeedHandler.js +0 -191
  140. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Node.d.ts +0 -168
  141. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Node.js +0 -385
  142. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Parser.d.ts +0 -159
  143. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Parser.js +0 -431
  144. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Tokenizer.d.ts +0 -181
  145. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Tokenizer.js +0 -1046
  146. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/mod.d.ts +0 -42
  147. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/mod.js +0 -52
  148. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode.d.ts +0 -11
  149. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode.js +0 -122
  150. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode_codepoint.d.ts +0 -1
  151. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode_codepoint.js +0 -24
  152. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/encode.d.ts +0 -46
  153. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/encode.js +0 -121
  154. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/decode.d.ts +0 -31
  155. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/decode.js +0 -30
  156. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/entities.d.ts +0 -2128
  157. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/entities.js +0 -2127
  158. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/legacy.d.ts +0 -109
  159. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/legacy.js +0 -108
  160. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/xml.d.ts +0 -8
  161. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/xml.js +0 -1
  162. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/mod.d.ts +0 -90
  163. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/mod.js +0 -95
  164. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/helpers.d.ts +0 -50
  165. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/helpers.js +0 -128
  166. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/legacy.d.ts +0 -46
  167. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/legacy.js +0 -110
  168. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/manipulation.d.ts +0 -42
  169. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/manipulation.js +0 -120
  170. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/mod.d.ts +0 -6
  171. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/mod.js +0 -6
  172. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/querying.d.ts +0 -54
  173. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/querying.js +0 -110
  174. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/stringify.d.ts +0 -40
  175. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/stringify.js +0 -75
  176. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/traversal.d.ts +0 -58
  177. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/traversal.js +0 -101
  178. package/esm/deps/deno.land/x/tgcrypto@0.3.3/tgcrypto.js +0 -324
  179. package/esm/utilities/0_control.d.ts +0 -1
  180. package/esm/utilities/0_control.js +0 -3
  181. package/script/deps/deno.land/x/html_parser@v0.1.3/src/DomHandler.d.ts +0 -83
  182. package/script/deps/deno.land/x/html_parser@v0.1.3/src/DomHandler.js +0 -207
  183. package/script/deps/deno.land/x/html_parser@v0.1.3/src/DomSerializer.d.ts +0 -50
  184. package/script/deps/deno.land/x/html_parser@v0.1.3/src/DomSerializer.js +0 -301
  185. package/script/deps/deno.land/x/html_parser@v0.1.3/src/ElementType.d.ts +0 -47
  186. package/script/deps/deno.land/x/html_parser@v0.1.3/src/ElementType.js +0 -55
  187. package/script/deps/deno.land/x/html_parser@v0.1.3/src/FeedHandler.d.ts +0 -66
  188. package/script/deps/deno.land/x/html_parser@v0.1.3/src/FeedHandler.js +0 -222
  189. package/script/deps/deno.land/x/html_parser@v0.1.3/src/Node.d.ts +0 -168
  190. package/script/deps/deno.land/x/html_parser@v0.1.3/src/Node.js +0 -404
  191. package/script/deps/deno.land/x/html_parser@v0.1.3/src/Parser.d.ts +0 -159
  192. package/script/deps/deno.land/x/html_parser@v0.1.3/src/Parser.js +0 -438
  193. package/script/deps/deno.land/x/html_parser@v0.1.3/src/Tokenizer.d.ts +0 -181
  194. package/script/deps/deno.land/x/html_parser@v0.1.3/src/Tokenizer.js +0 -1052
  195. package/script/deps/deno.land/x/html_parser@v0.1.3/src/mod.d.ts +0 -42
  196. package/script/deps/deno.land/x/html_parser@v0.1.3/src/mod.js +0 -88
  197. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode.d.ts +0 -11
  198. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode.js +0 -128
  199. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode_codepoint.d.ts +0 -1
  200. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode_codepoint.js +0 -30
  201. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/encode.d.ts +0 -46
  202. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/encode.js +0 -129
  203. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/decode.d.ts +0 -31
  204. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/decode.js +0 -32
  205. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/entities.d.ts +0 -2128
  206. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/entities.js +0 -2129
  207. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/legacy.d.ts +0 -109
  208. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/legacy.js +0 -110
  209. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/xml.d.ts +0 -8
  210. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/xml.js +0 -3
  211. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/mod.d.ts +0 -90
  212. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/mod.js +0 -114
  213. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/helpers.d.ts +0 -50
  214. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/helpers.js +0 -134
  215. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/legacy.d.ts +0 -46
  216. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/legacy.js +0 -118
  217. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/manipulation.d.ts +0 -42
  218. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/manipulation.js +0 -129
  219. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/mod.d.ts +0 -6
  220. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/mod.js +0 -22
  221. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/querying.d.ts +0 -54
  222. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/querying.js +0 -119
  223. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/stringify.d.ts +0 -40
  224. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/stringify.js +0 -86
  225. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/traversal.d.ts +0 -58
  226. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/traversal.js +0 -112
  227. package/script/deps/deno.land/x/tgcrypto@0.3.3/tgcrypto.js +0 -326
  228. package/script/utilities/0_control.d.ts +0 -1
  229. package/script/utilities/0_control.js +0 -7
  230. /package/esm/deps/deno.land/x/{tgcrypto@0.3.3 → tgcrypto@0.4.0}/tgcrypto.d.ts +0 -0
  231. /package/script/deps/deno.land/x/{tgcrypto@0.3.3 → tgcrypto@0.4.0}/tgcrypto.d.ts +0 -0
@@ -1,1052 +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
- 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;