@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.
- package/esm/0_deps.d.ts +1 -1
- package/esm/0_deps.js +2 -1
- package/esm/1_utilities.d.ts +1 -1
- package/esm/1_utilities.js +1 -1
- package/esm/4_errors.js +3 -3
- package/esm/client/0_markdown.js +5 -5
- package/esm/client/0_utilities.d.ts +6 -0
- package/esm/client/0_utilities.js +35 -4
- package/esm/client/1_account_manager.js +4 -4
- package/esm/client/1_client_encrypted.js +4 -4
- package/esm/client/1_client_plain.js +3 -3
- package/esm/client/1_file_manager.js +6 -5
- package/esm/client/1_reaction_manager.js +2 -2
- package/esm/client/1_update_manager.js +9 -8
- package/esm/client/2_message_manager.js +47 -24
- package/esm/client/3_callback_query_manager.js +2 -0
- package/esm/client/3_chat_list_manager.js +13 -12
- package/esm/client/3_inline_query_manager.js +4 -2
- package/esm/client/3_story_manager.js +7 -5
- package/esm/client/4_client.d.ts +5 -8
- package/esm/client/4_client.js +19 -27
- package/esm/connection/1_connection_web_socket.js +3 -2
- package/{script/deps/deno.land/x/tgcrypto@0.3.3 → esm/deps/deno.land/x/tgcrypto@0.4.0}/mod.d.ts +0 -1
- package/esm/deps/deno.land/x/{tgcrypto@0.3.3 → tgcrypto@0.4.0}/mod.js +0 -11
- package/esm/deps/deno.land/x/tgcrypto@0.4.0/tgcrypto.js +308 -0
- package/esm/mod.d.ts +1 -1
- package/esm/mod.js +1 -1
- package/esm/storage/0_storage.js +6 -5
- package/esm/storage/1_utilities.d.ts +0 -1
- package/esm/storage/1_utilities.js +2 -3
- package/esm/storage/2_storage_local_storage.js +1 -4
- package/esm/storage/2_storage_session_storage.js +1 -4
- package/esm/tl/3_utilities.js +5 -4
- package/esm/transport/2_transport_provider.js +4 -4
- package/esm/types/0_message_entity.js +3 -3
- package/esm/types/0_message_search_filter.js +2 -2
- package/esm/types/0_reaction.js +2 -2
- package/esm/types/1_bot_command_scope.js +3 -3
- package/esm/types/1_chat_p.js +3 -2
- package/esm/types/1_keyboard_button.js +3 -3
- package/esm/types/1_message_reaction.js +2 -2
- package/esm/types/1_story_privacy.js +3 -3
- package/esm/types/2_chat_member.js +6 -5
- package/esm/types/2_chosen_inline_result.js +3 -2
- package/esm/types/2_inactive_chat.js +3 -2
- package/esm/types/2_inline_keyboard_button.js +3 -3
- package/esm/types/2_inline_query.js +3 -3
- package/esm/types/2_invite_link.js +3 -2
- package/esm/types/2_story_content.js +5 -5
- package/esm/types/2_story_interactive_area.js +5 -5
- package/esm/types/3_chat_member_updated.js +4 -3
- package/esm/types/3_reply_markup.js +4 -3
- package/esm/types/3_story.js +3 -2
- package/esm/types/4_inline_query_result.js +5 -5
- package/esm/types/4_message.js +17 -16
- package/esm/types/5_callback_query.js +4 -3
- package/esm/types/5_chat.js +8 -7
- package/esm/types/_file_id.js +9 -8
- package/esm/utilities/0_bigint.d.ts +1 -0
- package/esm/utilities/0_bigint.js +25 -0
- package/esm/utilities/0_logger.d.ts +8 -0
- package/esm/utilities/0_logger.js +9 -5
- package/esm/utilities/1_math.d.ts +1 -0
- package/esm/utilities/1_math.js +51 -0
- package/esm/utilities/1_misc.js +2 -2
- package/package.json +1 -1
- package/script/0_deps.d.ts +1 -1
- package/script/0_deps.js +3 -3
- package/script/1_utilities.d.ts +1 -1
- package/script/1_utilities.js +1 -1
- package/script/4_errors.js +3 -3
- package/script/client/0_markdown.js +5 -5
- package/script/client/0_utilities.d.ts +6 -0
- package/script/client/0_utilities.js +41 -4
- package/script/client/1_account_manager.js +4 -4
- package/script/client/1_client_encrypted.js +2 -2
- package/script/client/1_client_plain.js +2 -2
- package/script/client/1_file_manager.js +5 -4
- package/script/client/1_reaction_manager.js +2 -2
- package/script/client/1_update_manager.js +8 -7
- package/script/client/2_message_manager.js +51 -28
- package/script/client/3_callback_query_manager.js +2 -0
- package/script/client/3_chat_list_manager.js +12 -11
- package/script/client/3_inline_query_manager.js +4 -2
- package/script/client/3_story_manager.js +4 -2
- package/script/client/4_client.d.ts +5 -8
- package/script/client/4_client.js +18 -26
- package/script/connection/1_connection_web_socket.js +2 -1
- package/{esm/deps/deno.land/x/tgcrypto@0.3.3 → script/deps/deno.land/x/tgcrypto@0.4.0}/mod.d.ts +0 -1
- package/script/deps/deno.land/x/{tgcrypto@0.3.3 → tgcrypto@0.4.0}/mod.js +1 -13
- package/script/deps/deno.land/x/tgcrypto@0.4.0/tgcrypto.js +310 -0
- package/script/mod.d.ts +1 -1
- package/script/mod.js +2 -1
- package/script/storage/0_storage.js +5 -4
- package/script/storage/1_utilities.d.ts +0 -1
- package/script/storage/1_utilities.js +3 -4
- package/script/storage/2_storage_local_storage.js +0 -3
- package/script/storage/2_storage_session_storage.js +0 -3
- package/script/tl/3_utilities.js +4 -3
- package/script/transport/2_transport_provider.js +4 -4
- package/script/types/0_message_entity.js +3 -3
- package/script/types/0_message_search_filter.js +2 -2
- package/script/types/0_reaction.js +2 -2
- package/script/types/1_bot_command_scope.js +3 -3
- package/script/types/1_chat_p.js +2 -1
- package/script/types/1_keyboard_button.js +3 -3
- package/script/types/1_message_reaction.js +2 -2
- package/script/types/1_story_privacy.js +3 -3
- package/script/types/2_chat_member.js +5 -4
- package/script/types/2_chosen_inline_result.js +2 -1
- package/script/types/2_inactive_chat.js +2 -1
- package/script/types/2_inline_keyboard_button.js +3 -3
- package/script/types/2_inline_query.js +3 -3
- package/script/types/2_invite_link.js +2 -1
- package/script/types/2_story_content.js +5 -5
- package/script/types/2_story_interactive_area.js +5 -5
- package/script/types/3_chat_member_updated.js +3 -2
- package/script/types/3_reply_markup.js +3 -2
- package/script/types/3_story.js +2 -1
- package/script/types/4_inline_query_result.js +5 -5
- package/script/types/4_message.js +16 -15
- package/script/types/5_callback_query.js +3 -2
- package/script/types/5_chat.js +7 -6
- package/script/types/_file_id.js +8 -7
- package/script/utilities/0_bigint.d.ts +1 -0
- package/script/utilities/0_bigint.js +27 -1
- package/script/utilities/0_logger.d.ts +8 -0
- package/script/utilities/0_logger.js +11 -6
- package/script/utilities/1_math.d.ts +1 -0
- package/script/utilities/1_math.js +55 -0
- package/script/utilities/1_misc.js +2 -2
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/DomHandler.d.ts +0 -83
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/DomHandler.js +0 -203
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/DomSerializer.d.ts +0 -50
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/DomSerializer.js +0 -274
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/ElementType.d.ts +0 -47
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/ElementType.js +0 -51
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/FeedHandler.d.ts +0 -66
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/FeedHandler.js +0 -191
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Node.d.ts +0 -168
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Node.js +0 -385
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Parser.d.ts +0 -159
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Parser.js +0 -431
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Tokenizer.d.ts +0 -181
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Tokenizer.js +0 -1046
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/mod.d.ts +0 -42
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/mod.js +0 -52
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode.d.ts +0 -11
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode.js +0 -122
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode_codepoint.d.ts +0 -1
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode_codepoint.js +0 -24
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/encode.d.ts +0 -46
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/encode.js +0 -121
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/decode.d.ts +0 -31
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/decode.js +0 -30
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/entities.d.ts +0 -2128
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/entities.js +0 -2127
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/legacy.d.ts +0 -109
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/legacy.js +0 -108
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/xml.d.ts +0 -8
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/xml.js +0 -1
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/mod.d.ts +0 -90
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/mod.js +0 -95
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/helpers.d.ts +0 -50
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/helpers.js +0 -128
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/legacy.d.ts +0 -46
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/legacy.js +0 -110
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/manipulation.d.ts +0 -42
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/manipulation.js +0 -120
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/mod.d.ts +0 -6
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/mod.js +0 -6
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/querying.d.ts +0 -54
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/querying.js +0 -110
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/stringify.d.ts +0 -40
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/stringify.js +0 -75
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/traversal.d.ts +0 -58
- package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/traversal.js +0 -101
- package/esm/deps/deno.land/x/tgcrypto@0.3.3/tgcrypto.js +0 -324
- package/esm/utilities/0_control.d.ts +0 -1
- package/esm/utilities/0_control.js +0 -3
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/DomHandler.d.ts +0 -83
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/DomHandler.js +0 -207
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/DomSerializer.d.ts +0 -50
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/DomSerializer.js +0 -301
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/ElementType.d.ts +0 -47
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/ElementType.js +0 -55
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/FeedHandler.d.ts +0 -66
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/FeedHandler.js +0 -222
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/Node.d.ts +0 -168
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/Node.js +0 -404
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/Parser.d.ts +0 -159
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/Parser.js +0 -438
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/Tokenizer.d.ts +0 -181
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/Tokenizer.js +0 -1052
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/mod.d.ts +0 -42
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/mod.js +0 -88
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode.d.ts +0 -11
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode.js +0 -128
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode_codepoint.d.ts +0 -1
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode_codepoint.js +0 -30
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/encode.d.ts +0 -46
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/encode.js +0 -129
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/decode.d.ts +0 -31
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/decode.js +0 -32
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/entities.d.ts +0 -2128
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/entities.js +0 -2129
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/legacy.d.ts +0 -109
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/legacy.js +0 -110
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/xml.d.ts +0 -8
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/xml.js +0 -3
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/mod.d.ts +0 -90
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/mod.js +0 -114
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/helpers.d.ts +0 -50
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/helpers.js +0 -134
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/legacy.d.ts +0 -46
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/legacy.js +0 -118
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/manipulation.d.ts +0 -42
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/manipulation.js +0 -129
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/mod.d.ts +0 -6
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/mod.js +0 -22
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/querying.d.ts +0 -54
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/querying.js +0 -119
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/stringify.d.ts +0 -40
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/stringify.js +0 -86
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/traversal.d.ts +0 -58
- package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/traversal.js +0 -112
- package/script/deps/deno.land/x/tgcrypto@0.3.3/tgcrypto.js +0 -326
- package/script/utilities/0_control.d.ts +0 -1
- package/script/utilities/0_control.js +0 -7
- /package/esm/deps/deno.land/x/{tgcrypto@0.3.3 → tgcrypto@0.4.0}/tgcrypto.d.ts +0 -0
- /package/script/deps/deno.land/x/{tgcrypto@0.3.3 → tgcrypto@0.4.0}/tgcrypto.d.ts +0 -0
|
@@ -1,431 +0,0 @@
|
|
|
1
|
-
import Tokenizer from './Tokenizer.js';
|
|
2
|
-
const formTags = new Set([
|
|
3
|
-
'input',
|
|
4
|
-
'option',
|
|
5
|
-
'optgroup',
|
|
6
|
-
'select',
|
|
7
|
-
'button',
|
|
8
|
-
'datalist',
|
|
9
|
-
'textarea',
|
|
10
|
-
]);
|
|
11
|
-
const pTag = new Set(['p']);
|
|
12
|
-
const openImpliesClose = {
|
|
13
|
-
tr: new Set(['tr', 'th', 'td']),
|
|
14
|
-
th: new Set(['th']),
|
|
15
|
-
td: new Set(['thead', 'th', 'td']),
|
|
16
|
-
body: new Set(['head', 'link', 'script']),
|
|
17
|
-
li: new Set(['li']),
|
|
18
|
-
p: pTag,
|
|
19
|
-
h1: pTag,
|
|
20
|
-
h2: pTag,
|
|
21
|
-
h3: pTag,
|
|
22
|
-
h4: pTag,
|
|
23
|
-
h5: pTag,
|
|
24
|
-
h6: pTag,
|
|
25
|
-
select: formTags,
|
|
26
|
-
input: formTags,
|
|
27
|
-
output: formTags,
|
|
28
|
-
button: formTags,
|
|
29
|
-
datalist: formTags,
|
|
30
|
-
textarea: formTags,
|
|
31
|
-
option: new Set(['option']),
|
|
32
|
-
optgroup: new Set(['optgroup', 'option']),
|
|
33
|
-
dd: new Set(['dt', 'dd']),
|
|
34
|
-
dt: new Set(['dt', 'dd']),
|
|
35
|
-
address: pTag,
|
|
36
|
-
article: pTag,
|
|
37
|
-
aside: pTag,
|
|
38
|
-
blockquote: pTag,
|
|
39
|
-
details: pTag,
|
|
40
|
-
div: pTag,
|
|
41
|
-
dl: pTag,
|
|
42
|
-
fieldset: pTag,
|
|
43
|
-
figcaption: pTag,
|
|
44
|
-
figure: pTag,
|
|
45
|
-
footer: pTag,
|
|
46
|
-
form: pTag,
|
|
47
|
-
header: pTag,
|
|
48
|
-
hr: pTag,
|
|
49
|
-
main: pTag,
|
|
50
|
-
nav: pTag,
|
|
51
|
-
ol: pTag,
|
|
52
|
-
pre: pTag,
|
|
53
|
-
section: pTag,
|
|
54
|
-
table: pTag,
|
|
55
|
-
ul: pTag,
|
|
56
|
-
rt: new Set(['rt', 'rp']),
|
|
57
|
-
rp: new Set(['rt', 'rp']),
|
|
58
|
-
tbody: new Set(['thead', 'tbody']),
|
|
59
|
-
tfoot: new Set(['thead', 'tbody']),
|
|
60
|
-
};
|
|
61
|
-
const voidElements = new Set([
|
|
62
|
-
'area',
|
|
63
|
-
'base',
|
|
64
|
-
'basefont',
|
|
65
|
-
'br',
|
|
66
|
-
'col',
|
|
67
|
-
'command',
|
|
68
|
-
'embed',
|
|
69
|
-
'frame',
|
|
70
|
-
'hr',
|
|
71
|
-
'img',
|
|
72
|
-
'input',
|
|
73
|
-
'isindex',
|
|
74
|
-
'keygen',
|
|
75
|
-
'link',
|
|
76
|
-
'meta',
|
|
77
|
-
'param',
|
|
78
|
-
'source',
|
|
79
|
-
'track',
|
|
80
|
-
'wbr',
|
|
81
|
-
]);
|
|
82
|
-
const foreignContextElements = new Set(['math', 'svg']);
|
|
83
|
-
const htmlIntegrationElements = new Set([
|
|
84
|
-
'mi',
|
|
85
|
-
'mo',
|
|
86
|
-
'mn',
|
|
87
|
-
'ms',
|
|
88
|
-
'mtext',
|
|
89
|
-
'annotation-xml',
|
|
90
|
-
'foreignObject',
|
|
91
|
-
'desc',
|
|
92
|
-
'title',
|
|
93
|
-
]);
|
|
94
|
-
const reNameEnd = /\s|\//;
|
|
95
|
-
export class Parser {
|
|
96
|
-
constructor(cbs, options = {}) {
|
|
97
|
-
/** The start index of the last event. */
|
|
98
|
-
Object.defineProperty(this, "startIndex", {
|
|
99
|
-
enumerable: true,
|
|
100
|
-
configurable: true,
|
|
101
|
-
writable: true,
|
|
102
|
-
value: 0
|
|
103
|
-
});
|
|
104
|
-
/** The end index of the last event. */
|
|
105
|
-
Object.defineProperty(this, "endIndex", {
|
|
106
|
-
enumerable: true,
|
|
107
|
-
configurable: true,
|
|
108
|
-
writable: true,
|
|
109
|
-
value: null
|
|
110
|
-
});
|
|
111
|
-
Object.defineProperty(this, "tagname", {
|
|
112
|
-
enumerable: true,
|
|
113
|
-
configurable: true,
|
|
114
|
-
writable: true,
|
|
115
|
-
value: ''
|
|
116
|
-
});
|
|
117
|
-
Object.defineProperty(this, "attribname", {
|
|
118
|
-
enumerable: true,
|
|
119
|
-
configurable: true,
|
|
120
|
-
writable: true,
|
|
121
|
-
value: ''
|
|
122
|
-
});
|
|
123
|
-
Object.defineProperty(this, "attribvalue", {
|
|
124
|
-
enumerable: true,
|
|
125
|
-
configurable: true,
|
|
126
|
-
writable: true,
|
|
127
|
-
value: ''
|
|
128
|
-
});
|
|
129
|
-
Object.defineProperty(this, "attribs", {
|
|
130
|
-
enumerable: true,
|
|
131
|
-
configurable: true,
|
|
132
|
-
writable: true,
|
|
133
|
-
value: null
|
|
134
|
-
});
|
|
135
|
-
Object.defineProperty(this, "stack", {
|
|
136
|
-
enumerable: true,
|
|
137
|
-
configurable: true,
|
|
138
|
-
writable: true,
|
|
139
|
-
value: []
|
|
140
|
-
});
|
|
141
|
-
Object.defineProperty(this, "foreignContext", {
|
|
142
|
-
enumerable: true,
|
|
143
|
-
configurable: true,
|
|
144
|
-
writable: true,
|
|
145
|
-
value: []
|
|
146
|
-
});
|
|
147
|
-
Object.defineProperty(this, "cbs", {
|
|
148
|
-
enumerable: true,
|
|
149
|
-
configurable: true,
|
|
150
|
-
writable: true,
|
|
151
|
-
value: void 0
|
|
152
|
-
});
|
|
153
|
-
Object.defineProperty(this, "options", {
|
|
154
|
-
enumerable: true,
|
|
155
|
-
configurable: true,
|
|
156
|
-
writable: true,
|
|
157
|
-
value: void 0
|
|
158
|
-
});
|
|
159
|
-
Object.defineProperty(this, "lowerCaseTagNames", {
|
|
160
|
-
enumerable: true,
|
|
161
|
-
configurable: true,
|
|
162
|
-
writable: true,
|
|
163
|
-
value: void 0
|
|
164
|
-
});
|
|
165
|
-
Object.defineProperty(this, "lowerCaseAttributeNames", {
|
|
166
|
-
enumerable: true,
|
|
167
|
-
configurable: true,
|
|
168
|
-
writable: true,
|
|
169
|
-
value: void 0
|
|
170
|
-
});
|
|
171
|
-
Object.defineProperty(this, "tokenizer", {
|
|
172
|
-
enumerable: true,
|
|
173
|
-
configurable: true,
|
|
174
|
-
writable: true,
|
|
175
|
-
value: void 0
|
|
176
|
-
});
|
|
177
|
-
this.options = options;
|
|
178
|
-
this.cbs = cbs ?? {};
|
|
179
|
-
this.lowerCaseTagNames = options.lowerCaseTags ?? !options.xmlMode;
|
|
180
|
-
this.lowerCaseAttributeNames =
|
|
181
|
-
options.lowerCaseAttributeNames ?? !options.xmlMode;
|
|
182
|
-
this.tokenizer = new (options.Tokenizer ?? Tokenizer)(this.options, this);
|
|
183
|
-
this.cbs.onparserinit?.(this);
|
|
184
|
-
}
|
|
185
|
-
updatePosition(initialOffset) {
|
|
186
|
-
if (this.endIndex === null) {
|
|
187
|
-
if (this.tokenizer.sectionStart <= initialOffset) {
|
|
188
|
-
this.startIndex = 0;
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
this.startIndex = this.tokenizer.sectionStart - initialOffset;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
this.startIndex = this.endIndex + 1;
|
|
196
|
-
}
|
|
197
|
-
this.endIndex = this.tokenizer.getAbsoluteIndex();
|
|
198
|
-
}
|
|
199
|
-
// Tokenizer event handlers
|
|
200
|
-
ontext(data) {
|
|
201
|
-
this.updatePosition(1);
|
|
202
|
-
this.endIndex--;
|
|
203
|
-
this.cbs.ontext?.(data);
|
|
204
|
-
}
|
|
205
|
-
isVoidElement(name) {
|
|
206
|
-
return !this.options.xmlMode && voidElements.has(name);
|
|
207
|
-
}
|
|
208
|
-
onopentagname(name) {
|
|
209
|
-
if (this.lowerCaseTagNames) {
|
|
210
|
-
name = name.toLowerCase();
|
|
211
|
-
}
|
|
212
|
-
this.tagname = name;
|
|
213
|
-
if (!this.options.xmlMode &&
|
|
214
|
-
Object.prototype.hasOwnProperty.call(openImpliesClose, name)) {
|
|
215
|
-
let el;
|
|
216
|
-
while (this.stack.length > 0 &&
|
|
217
|
-
openImpliesClose[name]?.has((el = this.stack[this.stack.length - 1]))) {
|
|
218
|
-
this.onclosetag(el);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
if (!this.isVoidElement(name)) {
|
|
222
|
-
this.stack.push(name);
|
|
223
|
-
if (foreignContextElements.has(name)) {
|
|
224
|
-
this.foreignContext.push(true);
|
|
225
|
-
}
|
|
226
|
-
else if (htmlIntegrationElements.has(name)) {
|
|
227
|
-
this.foreignContext.push(false);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
this.cbs.onopentagname?.(name);
|
|
231
|
-
if (this.cbs.onopentag)
|
|
232
|
-
this.attribs = {};
|
|
233
|
-
}
|
|
234
|
-
onopentagend() {
|
|
235
|
-
this.updatePosition(1);
|
|
236
|
-
if (this.attribs) {
|
|
237
|
-
this.cbs.onopentag?.(this.tagname, this.attribs);
|
|
238
|
-
this.attribs = null;
|
|
239
|
-
}
|
|
240
|
-
if (this.cbs.onclosetag && this.isVoidElement(this.tagname)) {
|
|
241
|
-
this.cbs.onclosetag(this.tagname);
|
|
242
|
-
}
|
|
243
|
-
this.tagname = '';
|
|
244
|
-
}
|
|
245
|
-
onclosetag(name) {
|
|
246
|
-
this.updatePosition(1);
|
|
247
|
-
if (this.lowerCaseTagNames) {
|
|
248
|
-
name = name.toLowerCase();
|
|
249
|
-
}
|
|
250
|
-
if (foreignContextElements.has(name) ||
|
|
251
|
-
htmlIntegrationElements.has(name)) {
|
|
252
|
-
this.foreignContext.pop();
|
|
253
|
-
}
|
|
254
|
-
if (this.stack.length && !this.isVoidElement(name)) {
|
|
255
|
-
let pos = this.stack.lastIndexOf(name);
|
|
256
|
-
if (pos !== -1) {
|
|
257
|
-
if (this.cbs.onclosetag) {
|
|
258
|
-
pos = this.stack.length - pos;
|
|
259
|
-
while (pos--) {
|
|
260
|
-
// We know the stack has sufficient elements.
|
|
261
|
-
this.cbs.onclosetag(this.stack.pop());
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
else
|
|
265
|
-
this.stack.length = pos;
|
|
266
|
-
}
|
|
267
|
-
else if (name === 'p' && !this.options.xmlMode) {
|
|
268
|
-
this.onopentagname(name);
|
|
269
|
-
this.closeCurrentTag();
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
else if (!this.options.xmlMode && (name === 'br' || name === 'p')) {
|
|
273
|
-
this.onopentagname(name);
|
|
274
|
-
this.closeCurrentTag();
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
onselfclosingtag() {
|
|
278
|
-
if (this.options.xmlMode ||
|
|
279
|
-
this.options.recognizeSelfClosing ||
|
|
280
|
-
this.foreignContext[this.foreignContext.length - 1]) {
|
|
281
|
-
this.closeCurrentTag();
|
|
282
|
-
}
|
|
283
|
-
else {
|
|
284
|
-
this.onopentagend();
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
closeCurrentTag() {
|
|
288
|
-
const name = this.tagname;
|
|
289
|
-
this.onopentagend();
|
|
290
|
-
/*
|
|
291
|
-
* Self-closing tags will be on the top of the stack
|
|
292
|
-
* (cheaper check than in onclosetag)
|
|
293
|
-
*/
|
|
294
|
-
if (this.stack[this.stack.length - 1] === name) {
|
|
295
|
-
this.cbs.onclosetag?.(name);
|
|
296
|
-
this.stack.pop();
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
onattribname(name) {
|
|
300
|
-
if (this.lowerCaseAttributeNames) {
|
|
301
|
-
name = name.toLowerCase();
|
|
302
|
-
}
|
|
303
|
-
this.attribname = name;
|
|
304
|
-
}
|
|
305
|
-
onattribdata(value) {
|
|
306
|
-
this.attribvalue += value;
|
|
307
|
-
}
|
|
308
|
-
onattribend(quote) {
|
|
309
|
-
this.cbs.onattribute?.(this.attribname, this.attribvalue, quote);
|
|
310
|
-
if (this.attribs &&
|
|
311
|
-
!Object.prototype.hasOwnProperty.call(this.attribs, this.attribname)) {
|
|
312
|
-
this.attribs[this.attribname] = this.attribvalue;
|
|
313
|
-
}
|
|
314
|
-
this.attribname = '';
|
|
315
|
-
this.attribvalue = '';
|
|
316
|
-
}
|
|
317
|
-
getInstructionName(value) {
|
|
318
|
-
const idx = value.search(reNameEnd);
|
|
319
|
-
let name = idx < 0 ? value : value.substr(0, idx);
|
|
320
|
-
if (this.lowerCaseTagNames) {
|
|
321
|
-
name = name.toLowerCase();
|
|
322
|
-
}
|
|
323
|
-
return name;
|
|
324
|
-
}
|
|
325
|
-
ondeclaration(value) {
|
|
326
|
-
if (this.cbs.onprocessinginstruction) {
|
|
327
|
-
const name = this.getInstructionName(value);
|
|
328
|
-
this.cbs.onprocessinginstruction(`!${name}`, `!${value}`);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
onprocessinginstruction(value) {
|
|
332
|
-
if (this.cbs.onprocessinginstruction) {
|
|
333
|
-
const name = this.getInstructionName(value);
|
|
334
|
-
this.cbs.onprocessinginstruction(`?${name}`, `?${value}`);
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
oncomment(value) {
|
|
338
|
-
this.updatePosition(4);
|
|
339
|
-
this.cbs.oncomment?.(value);
|
|
340
|
-
this.cbs.oncommentend?.();
|
|
341
|
-
}
|
|
342
|
-
oncdata(value) {
|
|
343
|
-
this.updatePosition(1);
|
|
344
|
-
if (this.options.xmlMode || this.options.recognizeCDATA) {
|
|
345
|
-
this.cbs.oncdatastart?.();
|
|
346
|
-
this.cbs.ontext?.(value);
|
|
347
|
-
this.cbs.oncdataend?.();
|
|
348
|
-
}
|
|
349
|
-
else {
|
|
350
|
-
this.oncomment(`[CDATA[${value}]]`);
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
onerror(err) {
|
|
354
|
-
this.cbs.onerror?.(err);
|
|
355
|
-
}
|
|
356
|
-
onend() {
|
|
357
|
-
if (this.cbs.onclosetag) {
|
|
358
|
-
for (let i = this.stack.length; i > 0; this.cbs.onclosetag(this.stack[--i]))
|
|
359
|
-
;
|
|
360
|
-
}
|
|
361
|
-
this.cbs.onend?.();
|
|
362
|
-
}
|
|
363
|
-
/**
|
|
364
|
-
* Resets the parser to a blank state, ready to parse a new HTML document
|
|
365
|
-
*/
|
|
366
|
-
reset() {
|
|
367
|
-
this.cbs.onreset?.();
|
|
368
|
-
this.tokenizer.reset();
|
|
369
|
-
this.tagname = '';
|
|
370
|
-
this.attribname = '';
|
|
371
|
-
this.attribs = null;
|
|
372
|
-
this.stack = [];
|
|
373
|
-
this.cbs.onparserinit?.(this);
|
|
374
|
-
}
|
|
375
|
-
/**
|
|
376
|
-
* Resets the parser, then parses a complete document and
|
|
377
|
-
* pushes it to the handler.
|
|
378
|
-
*
|
|
379
|
-
* @param data Document to parse.
|
|
380
|
-
*/
|
|
381
|
-
parseComplete(data) {
|
|
382
|
-
this.reset();
|
|
383
|
-
this.end(data);
|
|
384
|
-
}
|
|
385
|
-
/**
|
|
386
|
-
* Parses a chunk of data and calls the corresponding callbacks.
|
|
387
|
-
*
|
|
388
|
-
* @param chunk Chunk to parse.
|
|
389
|
-
*/
|
|
390
|
-
write(chunk) {
|
|
391
|
-
this.tokenizer.write(chunk);
|
|
392
|
-
}
|
|
393
|
-
/**
|
|
394
|
-
* Parses the end of the buffer and clears the stack, calls onend.
|
|
395
|
-
*
|
|
396
|
-
* @param chunk Optional final chunk to parse.
|
|
397
|
-
*/
|
|
398
|
-
end(chunk) {
|
|
399
|
-
this.tokenizer.end(chunk);
|
|
400
|
-
}
|
|
401
|
-
/**
|
|
402
|
-
* Pauses parsing. The parser won't emit events until `resume` is called.
|
|
403
|
-
*/
|
|
404
|
-
pause() {
|
|
405
|
-
this.tokenizer.pause();
|
|
406
|
-
}
|
|
407
|
-
/**
|
|
408
|
-
* Resumes parsing after `pause` was called.
|
|
409
|
-
*/
|
|
410
|
-
resume() {
|
|
411
|
-
this.tokenizer.resume();
|
|
412
|
-
}
|
|
413
|
-
/**
|
|
414
|
-
* Alias of `write`, for backwards compatibility.
|
|
415
|
-
*
|
|
416
|
-
* @param chunk Chunk to parse.
|
|
417
|
-
* @deprecated
|
|
418
|
-
*/
|
|
419
|
-
parseChunk(chunk) {
|
|
420
|
-
this.write(chunk);
|
|
421
|
-
}
|
|
422
|
-
/**
|
|
423
|
-
* Alias of `end`, for backwards compatibility.
|
|
424
|
-
*
|
|
425
|
-
* @param chunk Optional final chunk to parse.
|
|
426
|
-
* @deprecated
|
|
427
|
-
*/
|
|
428
|
-
done(chunk) {
|
|
429
|
-
this.end(chunk);
|
|
430
|
-
}
|
|
431
|
-
}
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
/** All the states the tokenizer can be in. */
|
|
2
|
-
declare const enum State {
|
|
3
|
-
Text = 1,
|
|
4
|
-
BeforeTagName = 2,
|
|
5
|
-
InTagName = 3,
|
|
6
|
-
InSelfClosingTag = 4,
|
|
7
|
-
BeforeClosingTagName = 5,
|
|
8
|
-
InClosingTagName = 6,
|
|
9
|
-
AfterClosingTagName = 7,
|
|
10
|
-
BeforeAttributeName = 8,
|
|
11
|
-
InAttributeName = 9,
|
|
12
|
-
AfterAttributeName = 10,
|
|
13
|
-
BeforeAttributeValue = 11,
|
|
14
|
-
InAttributeValueDq = 12,
|
|
15
|
-
InAttributeValueSq = 13,
|
|
16
|
-
InAttributeValueNq = 14,
|
|
17
|
-
BeforeDeclaration = 15,
|
|
18
|
-
InDeclaration = 16,
|
|
19
|
-
InProcessingInstruction = 17,
|
|
20
|
-
BeforeComment = 18,
|
|
21
|
-
InComment = 19,
|
|
22
|
-
InSpecialComment = 20,
|
|
23
|
-
AfterComment1 = 21,
|
|
24
|
-
AfterComment2 = 22,
|
|
25
|
-
BeforeCdata1 = 23,
|
|
26
|
-
BeforeCdata2 = 24,
|
|
27
|
-
BeforeCdata3 = 25,
|
|
28
|
-
BeforeCdata4 = 26,
|
|
29
|
-
BeforeCdata5 = 27,
|
|
30
|
-
BeforeCdata6 = 28,
|
|
31
|
-
InCdata = 29,
|
|
32
|
-
AfterCdata1 = 30,
|
|
33
|
-
AfterCdata2 = 31,
|
|
34
|
-
BeforeSpecialS = 32,
|
|
35
|
-
BeforeSpecialSEnd = 33,
|
|
36
|
-
BeforeScript1 = 34,
|
|
37
|
-
BeforeScript2 = 35,
|
|
38
|
-
BeforeScript3 = 36,
|
|
39
|
-
BeforeScript4 = 37,
|
|
40
|
-
BeforeScript5 = 38,
|
|
41
|
-
AfterScript1 = 39,
|
|
42
|
-
AfterScript2 = 40,
|
|
43
|
-
AfterScript3 = 41,
|
|
44
|
-
AfterScript4 = 42,
|
|
45
|
-
AfterScript5 = 43,
|
|
46
|
-
BeforeStyle1 = 44,
|
|
47
|
-
BeforeStyle2 = 45,
|
|
48
|
-
BeforeStyle3 = 46,
|
|
49
|
-
BeforeStyle4 = 47,
|
|
50
|
-
AfterStyle1 = 48,
|
|
51
|
-
AfterStyle2 = 49,
|
|
52
|
-
AfterStyle3 = 50,
|
|
53
|
-
AfterStyle4 = 51,
|
|
54
|
-
BeforeSpecialT = 52,
|
|
55
|
-
BeforeSpecialTEnd = 53,
|
|
56
|
-
BeforeTitle1 = 54,
|
|
57
|
-
BeforeTitle2 = 55,
|
|
58
|
-
BeforeTitle3 = 56,
|
|
59
|
-
BeforeTitle4 = 57,
|
|
60
|
-
AfterTitle1 = 58,
|
|
61
|
-
AfterTitle2 = 59,
|
|
62
|
-
AfterTitle3 = 60,
|
|
63
|
-
AfterTitle4 = 61,
|
|
64
|
-
BeforeEntity = 62,
|
|
65
|
-
BeforeNumericEntity = 63,
|
|
66
|
-
InNamedEntity = 64,
|
|
67
|
-
InNumericEntity = 65,
|
|
68
|
-
InHexEntity = 66
|
|
69
|
-
}
|
|
70
|
-
export interface Callbacks {
|
|
71
|
-
onattribdata(value: string): void;
|
|
72
|
-
onattribend(quote: string | undefined | null): void;
|
|
73
|
-
onattribname(name: string): void;
|
|
74
|
-
oncdata(data: string): void;
|
|
75
|
-
onclosetag(name: string): void;
|
|
76
|
-
oncomment(data: string): void;
|
|
77
|
-
ondeclaration(content: string): void;
|
|
78
|
-
onend(): void;
|
|
79
|
-
onerror(error: Error, state?: State): void;
|
|
80
|
-
onopentagend(): void;
|
|
81
|
-
onopentagname(name: string): void;
|
|
82
|
-
onprocessinginstruction(instruction: string): void;
|
|
83
|
-
onselfclosingtag(): void;
|
|
84
|
-
ontext(value: string): void;
|
|
85
|
-
}
|
|
86
|
-
export default class Tokenizer {
|
|
87
|
-
/** The current state the tokenizer is in. */
|
|
88
|
-
_state: State;
|
|
89
|
-
/** The read buffer. */
|
|
90
|
-
private buffer;
|
|
91
|
-
/** The beginning of the section that is currently being read. */
|
|
92
|
-
sectionStart: number;
|
|
93
|
-
/** The index within the buffer that we are currently looking at. */
|
|
94
|
-
_index: number;
|
|
95
|
-
/**
|
|
96
|
-
* Data that has already been processed will be removed from the buffer occasionally.
|
|
97
|
-
* `_bufferOffset` keeps track of how many characters have been removed, to make sure position information is accurate.
|
|
98
|
-
*/
|
|
99
|
-
private bufferOffset;
|
|
100
|
-
/** Some behavior, eg. when decoding entities, is done while we are in another state. This keeps track of the other state type. */
|
|
101
|
-
private baseState;
|
|
102
|
-
/** For special parsing behavior inside of script and style tags. */
|
|
103
|
-
private special;
|
|
104
|
-
/** Indicates whether the tokenizer has been paused. */
|
|
105
|
-
private running;
|
|
106
|
-
/** Indicates whether the tokenizer has finished running / `.end` has been called. */
|
|
107
|
-
private ended;
|
|
108
|
-
private readonly cbs;
|
|
109
|
-
private readonly xmlMode;
|
|
110
|
-
private readonly decodeEntities;
|
|
111
|
-
constructor(options: {
|
|
112
|
-
xmlMode?: boolean;
|
|
113
|
-
decodeEntities?: boolean;
|
|
114
|
-
} | null, cbs: Callbacks);
|
|
115
|
-
reset(): void;
|
|
116
|
-
write(chunk: string): void;
|
|
117
|
-
end(chunk?: string): void;
|
|
118
|
-
pause(): void;
|
|
119
|
-
resume(): void;
|
|
120
|
-
/**
|
|
121
|
-
* The current index within all of the written data.
|
|
122
|
-
*/
|
|
123
|
-
getAbsoluteIndex(): number;
|
|
124
|
-
private stateText;
|
|
125
|
-
/**
|
|
126
|
-
* HTML only allows ASCII alpha characters (a-z and A-Z) at the beginning of a tag name.
|
|
127
|
-
*
|
|
128
|
-
* XML allows a lot more characters here (@see https://www.w3.org/TR/REC-xml/#NT-NameStartChar).
|
|
129
|
-
* We allow anything that wouldn't end the tag.
|
|
130
|
-
*/
|
|
131
|
-
private isTagStartChar;
|
|
132
|
-
private stateBeforeTagName;
|
|
133
|
-
private stateInTagName;
|
|
134
|
-
private stateBeforeClosingTagName;
|
|
135
|
-
private stateInClosingTagName;
|
|
136
|
-
private stateAfterClosingTagName;
|
|
137
|
-
private stateBeforeAttributeName;
|
|
138
|
-
private stateInSelfClosingTag;
|
|
139
|
-
private stateInAttributeName;
|
|
140
|
-
private stateAfterAttributeName;
|
|
141
|
-
private stateBeforeAttributeValue;
|
|
142
|
-
private handleInAttributeValue;
|
|
143
|
-
private stateInAttributeValueDoubleQuotes;
|
|
144
|
-
private stateInAttributeValueSingleQuotes;
|
|
145
|
-
private stateInAttributeValueNoQuotes;
|
|
146
|
-
private stateBeforeDeclaration;
|
|
147
|
-
private stateInDeclaration;
|
|
148
|
-
private stateInProcessingInstruction;
|
|
149
|
-
private stateBeforeComment;
|
|
150
|
-
private stateInComment;
|
|
151
|
-
private stateInSpecialComment;
|
|
152
|
-
private stateAfterComment1;
|
|
153
|
-
private stateAfterComment2;
|
|
154
|
-
private stateBeforeCdata6;
|
|
155
|
-
private stateInCdata;
|
|
156
|
-
private stateAfterCdata1;
|
|
157
|
-
private stateAfterCdata2;
|
|
158
|
-
private stateBeforeSpecialS;
|
|
159
|
-
private stateBeforeSpecialSEnd;
|
|
160
|
-
private stateBeforeSpecialLast;
|
|
161
|
-
private stateAfterSpecialLast;
|
|
162
|
-
private parseFixedEntity;
|
|
163
|
-
private parseLegacyEntity;
|
|
164
|
-
private stateInNamedEntity;
|
|
165
|
-
private decodeNumericEntity;
|
|
166
|
-
private stateInNumericEntity;
|
|
167
|
-
private stateInHexEntity;
|
|
168
|
-
private cleanup;
|
|
169
|
-
/**
|
|
170
|
-
* Iterates through the buffer, calling the function corresponding to the current state.
|
|
171
|
-
*
|
|
172
|
-
* States that are more likely to be hit are higher up, as a performance improvement.
|
|
173
|
-
*/
|
|
174
|
-
private parse;
|
|
175
|
-
private finish;
|
|
176
|
-
private handleTrailingData;
|
|
177
|
-
private getSection;
|
|
178
|
-
private emitToken;
|
|
179
|
-
private emitPartial;
|
|
180
|
-
}
|
|
181
|
-
export {};
|