@mtkruto/node 0.1.191 → 0.1.201

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (265) hide show
  1. package/esm/1_utilities.d.ts +1 -1
  2. package/esm/1_utilities.js +1 -1
  3. package/esm/2_tl.d.ts +6 -6
  4. package/esm/2_tl.js +6 -6
  5. package/esm/3_storage.d.ts +5 -5
  6. package/esm/3_storage.js +5 -5
  7. package/esm/3_types.d.ts +6 -5
  8. package/esm/3_types.js +6 -5
  9. package/esm/4_constants.d.ts +2 -2
  10. package/esm/4_constants.js +2 -2
  11. package/esm/5_client.d.ts +1 -1
  12. package/esm/5_client.js +1 -1
  13. package/esm/client/0_params.d.ts +7 -1
  14. package/esm/client/0_types.d.ts +1 -0
  15. package/esm/client/0_utilities.d.ts +0 -3
  16. package/esm/client/0_utilities.js +0 -20
  17. package/esm/client/1_business_connection_manager.d.ts +11 -0
  18. package/esm/client/1_business_connection_manager.js +47 -0
  19. package/esm/client/1_update_manager.d.ts +8 -1
  20. package/esm/client/1_update_manager.js +88 -8
  21. package/esm/client/2_message_manager.d.ts +7 -6
  22. package/esm/client/2_message_manager.js +48 -31
  23. package/esm/client/4_client.d.ts +426 -428
  24. package/esm/client/4_client.js +570 -530
  25. package/esm/storage/0_storage.d.ts +5 -0
  26. package/esm/storage/0_storage.js +20 -0
  27. package/esm/storage/{1_storage_indexed_db.js → 2_storage_indexed_db.js} +1 -1
  28. package/esm/storage/{1_storage_local_storage.js → 2_storage_local_storage.js} +1 -1
  29. package/{script/storage/1_storage_memory.d.ts → esm/storage/2_storage_memory.d.ts} +1 -4
  30. package/esm/storage/{1_storage_memory.js → 2_storage_memory.js} +8 -28
  31. package/esm/storage/{1_storage_session_storage.js → 2_storage_session_storage.js} +1 -1
  32. package/esm/tl/2_types.d.ts +1071 -183
  33. package/esm/tl/2_types.js +2916 -464
  34. package/esm/tl/3_functions.d.ts +381 -17
  35. package/esm/tl/3_functions.js +1002 -120
  36. package/{script/tl/4_tl_writer.d.ts → esm/tl/5_tl_writer.d.ts} +1 -1
  37. package/{script/tl/4_rpc_result.d.ts → esm/tl/6_rpc_result.d.ts} +1 -1
  38. package/esm/tl/{4_rpc_result.js → 6_rpc_result.js} +1 -1
  39. package/esm/tl/{6_message.d.ts → 7_message.d.ts} +2 -2
  40. package/esm/tl/{6_message.js → 7_message.js} +3 -3
  41. package/esm/tl/{7_message_container.d.ts → 8_message_container.d.ts} +1 -1
  42. package/esm/tl/{7_message_container.js → 8_message_container.js} +3 -3
  43. package/esm/types/0_chat_photo.js +1 -1
  44. package/esm/types/0_message_entity.d.ts +1 -1
  45. package/esm/types/0_thumbnail.js +1 -1
  46. package/esm/types/1_bot_command_scope.d.ts +1 -1
  47. package/esm/types/1_photo.js +2 -2
  48. package/esm/types/1_story_privacy.d.ts +1 -1
  49. package/esm/types/2_business_connection.d.ts +11 -0
  50. package/esm/types/2_business_connection.js +12 -0
  51. package/esm/types/2_chat_member.d.ts +1 -1
  52. package/esm/types/2_chosen_inline_result.d.ts +1 -1
  53. package/esm/types/2_game.js +1 -1
  54. package/esm/types/2_inline_keyboard_button.d.ts +1 -1
  55. package/esm/types/2_inline_query.d.ts +1 -1
  56. package/esm/types/2_invite_link.d.ts +1 -1
  57. package/esm/types/2_message_reaction_count.d.ts +1 -1
  58. package/esm/types/2_message_reactions.d.ts +1 -1
  59. package/esm/types/2_story_content.js +1 -1
  60. package/esm/types/{1_story_interactive_area.d.ts → 2_story_interactive_area.d.ts} +2 -2
  61. package/esm/types/{1_story_interactive_area.js → 2_story_interactive_area.js} +1 -1
  62. package/esm/types/3_chat_member_updated.d.ts +1 -1
  63. package/esm/types/3_reply_markup.d.ts +1 -1
  64. package/esm/types/3_story.d.ts +2 -2
  65. package/esm/types/3_story.js +1 -1
  66. package/esm/types/4_inline_query_result.d.ts +1 -1
  67. package/esm/types/4_inline_query_result.js +1 -1
  68. package/esm/types/4_message.d.ts +9 -3
  69. package/esm/types/4_message.js +22 -5
  70. package/esm/types/5_callback_query.d.ts +1 -1
  71. package/esm/types/5_chat.d.ts +1 -1
  72. package/esm/types/6_update.d.ts +12 -2
  73. package/package.json +1 -1
  74. package/script/1_utilities.d.ts +1 -1
  75. package/script/1_utilities.js +1 -1
  76. package/script/2_tl.d.ts +6 -6
  77. package/script/2_tl.js +6 -6
  78. package/script/3_storage.d.ts +5 -5
  79. package/script/3_storage.js +5 -5
  80. package/script/3_types.d.ts +6 -5
  81. package/script/3_types.js +6 -5
  82. package/script/4_constants.d.ts +2 -2
  83. package/script/4_constants.js +2 -2
  84. package/script/5_client.d.ts +1 -1
  85. package/script/5_client.js +1 -1
  86. package/script/client/0_params.d.ts +7 -1
  87. package/script/client/0_types.d.ts +1 -0
  88. package/script/client/0_utilities.d.ts +0 -3
  89. package/script/client/0_utilities.js +1 -23
  90. package/script/client/1_business_connection_manager.d.ts +11 -0
  91. package/script/client/1_business_connection_manager.js +51 -0
  92. package/script/client/1_update_manager.d.ts +8 -1
  93. package/script/client/1_update_manager.js +88 -8
  94. package/script/client/2_message_manager.d.ts +7 -6
  95. package/script/client/2_message_manager.js +47 -30
  96. package/script/client/4_client.d.ts +426 -428
  97. package/script/client/4_client.js +570 -530
  98. package/script/storage/0_storage.d.ts +5 -0
  99. package/script/storage/0_storage.js +20 -0
  100. package/script/storage/{1_storage_indexed_db.js → 2_storage_indexed_db.js} +7 -7
  101. package/script/storage/{1_storage_local_storage.js → 2_storage_local_storage.js} +10 -10
  102. package/{esm/storage/1_storage_memory.d.ts → script/storage/2_storage_memory.d.ts} +1 -4
  103. package/script/storage/{1_storage_memory.js → 2_storage_memory.js} +12 -32
  104. package/script/storage/{1_storage_session_storage.js → 2_storage_session_storage.js} +10 -10
  105. package/script/tl/2_types.d.ts +1071 -183
  106. package/script/tl/2_types.js +3028 -504
  107. package/script/tl/3_functions.d.ts +381 -17
  108. package/script/tl/3_functions.js +1047 -143
  109. package/{esm/tl/4_tl_writer.d.ts → script/tl/5_tl_writer.d.ts} +1 -1
  110. package/{esm/tl/4_rpc_result.d.ts → script/tl/6_rpc_result.d.ts} +1 -1
  111. package/script/tl/{4_rpc_result.js → 6_rpc_result.js} +2 -2
  112. package/script/tl/{6_message.d.ts → 7_message.d.ts} +2 -2
  113. package/script/tl/{6_message.js → 7_message.js} +8 -8
  114. package/script/tl/{7_message_container.d.ts → 8_message_container.d.ts} +1 -1
  115. package/script/tl/{7_message_container.js → 8_message_container.js} +7 -7
  116. package/script/types/0_chat_photo.js +9 -9
  117. package/script/types/0_message_entity.d.ts +1 -1
  118. package/script/types/0_thumbnail.js +6 -6
  119. package/script/types/1_bot_command_scope.d.ts +1 -1
  120. package/script/types/1_photo.js +7 -7
  121. package/script/types/1_story_privacy.d.ts +1 -1
  122. package/script/types/2_business_connection.d.ts +11 -0
  123. package/script/types/2_business_connection.js +16 -0
  124. package/script/types/2_chat_member.d.ts +1 -1
  125. package/script/types/2_chosen_inline_result.d.ts +1 -1
  126. package/script/types/2_game.js +3 -3
  127. package/script/types/2_inline_keyboard_button.d.ts +1 -1
  128. package/script/types/2_inline_query.d.ts +1 -1
  129. package/script/types/2_invite_link.d.ts +1 -1
  130. package/script/types/2_message_reaction_count.d.ts +1 -1
  131. package/script/types/2_message_reactions.d.ts +1 -1
  132. package/script/types/2_story_content.js +4 -4
  133. package/script/types/{1_story_interactive_area.d.ts → 2_story_interactive_area.d.ts} +2 -2
  134. package/script/types/{1_story_interactive_area.js → 2_story_interactive_area.js} +2 -2
  135. package/script/types/3_chat_member_updated.d.ts +1 -1
  136. package/script/types/3_reply_markup.d.ts +1 -1
  137. package/script/types/3_story.d.ts +2 -2
  138. package/script/types/3_story.js +2 -2
  139. package/script/types/4_inline_query_result.d.ts +1 -1
  140. package/script/types/4_inline_query_result.js +2 -2
  141. package/script/types/4_message.d.ts +9 -3
  142. package/script/types/4_message.js +37 -20
  143. package/script/types/5_callback_query.d.ts +1 -1
  144. package/script/types/5_chat.d.ts +1 -1
  145. package/script/types/6_update.d.ts +12 -2
  146. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/DomHandler.d.ts +0 -83
  147. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/DomHandler.js +0 -203
  148. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/DomSerializer.d.ts +0 -50
  149. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/DomSerializer.js +0 -274
  150. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/ElementType.d.ts +0 -47
  151. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/ElementType.js +0 -51
  152. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/FeedHandler.d.ts +0 -66
  153. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/FeedHandler.js +0 -191
  154. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Node.d.ts +0 -168
  155. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Node.js +0 -385
  156. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Parser.d.ts +0 -159
  157. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Parser.js +0 -431
  158. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Tokenizer.d.ts +0 -181
  159. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/Tokenizer.js +0 -1046
  160. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/mod.d.ts +0 -42
  161. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/mod.js +0 -52
  162. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode.d.ts +0 -11
  163. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode.js +0 -122
  164. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode_codepoint.d.ts +0 -1
  165. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode_codepoint.js +0 -24
  166. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/encode.d.ts +0 -46
  167. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/encode.js +0 -121
  168. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/decode.d.ts +0 -31
  169. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/decode.js +0 -30
  170. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/entities.d.ts +0 -2128
  171. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/entities.js +0 -2127
  172. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/legacy.d.ts +0 -109
  173. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/legacy.js +0 -108
  174. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/xml.d.ts +0 -8
  175. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/xml.js +0 -1
  176. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/mod.d.ts +0 -90
  177. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/mod.js +0 -95
  178. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/helpers.d.ts +0 -50
  179. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/helpers.js +0 -128
  180. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/legacy.d.ts +0 -46
  181. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/legacy.js +0 -110
  182. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/manipulation.d.ts +0 -42
  183. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/manipulation.js +0 -120
  184. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/mod.d.ts +0 -6
  185. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/mod.js +0 -6
  186. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/querying.d.ts +0 -54
  187. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/querying.js +0 -110
  188. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/stringify.d.ts +0 -40
  189. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/stringify.js +0 -75
  190. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/traversal.d.ts +0 -58
  191. package/esm/deps/deno.land/x/html_parser@v0.1.3/src/utils/traversal.js +0 -101
  192. package/script/deps/deno.land/x/html_parser@v0.1.3/src/DomHandler.d.ts +0 -83
  193. package/script/deps/deno.land/x/html_parser@v0.1.3/src/DomHandler.js +0 -207
  194. package/script/deps/deno.land/x/html_parser@v0.1.3/src/DomSerializer.d.ts +0 -50
  195. package/script/deps/deno.land/x/html_parser@v0.1.3/src/DomSerializer.js +0 -301
  196. package/script/deps/deno.land/x/html_parser@v0.1.3/src/ElementType.d.ts +0 -47
  197. package/script/deps/deno.land/x/html_parser@v0.1.3/src/ElementType.js +0 -55
  198. package/script/deps/deno.land/x/html_parser@v0.1.3/src/FeedHandler.d.ts +0 -66
  199. package/script/deps/deno.land/x/html_parser@v0.1.3/src/FeedHandler.js +0 -222
  200. package/script/deps/deno.land/x/html_parser@v0.1.3/src/Node.d.ts +0 -168
  201. package/script/deps/deno.land/x/html_parser@v0.1.3/src/Node.js +0 -404
  202. package/script/deps/deno.land/x/html_parser@v0.1.3/src/Parser.d.ts +0 -159
  203. package/script/deps/deno.land/x/html_parser@v0.1.3/src/Parser.js +0 -438
  204. package/script/deps/deno.land/x/html_parser@v0.1.3/src/Tokenizer.d.ts +0 -181
  205. package/script/deps/deno.land/x/html_parser@v0.1.3/src/Tokenizer.js +0 -1052
  206. package/script/deps/deno.land/x/html_parser@v0.1.3/src/mod.d.ts +0 -42
  207. package/script/deps/deno.land/x/html_parser@v0.1.3/src/mod.js +0 -88
  208. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode.d.ts +0 -11
  209. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode.js +0 -128
  210. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode_codepoint.d.ts +0 -1
  211. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/decode_codepoint.js +0 -30
  212. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/encode.d.ts +0 -46
  213. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/encode.js +0 -129
  214. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/decode.d.ts +0 -31
  215. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/decode.js +0 -32
  216. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/entities.d.ts +0 -2128
  217. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/entities.js +0 -2129
  218. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/legacy.d.ts +0 -109
  219. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/legacy.js +0 -110
  220. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/xml.d.ts +0 -8
  221. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/maps/xml.js +0 -3
  222. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/mod.d.ts +0 -90
  223. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/entities/mod.js +0 -114
  224. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/helpers.d.ts +0 -50
  225. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/helpers.js +0 -134
  226. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/legacy.d.ts +0 -46
  227. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/legacy.js +0 -118
  228. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/manipulation.d.ts +0 -42
  229. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/manipulation.js +0 -129
  230. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/mod.d.ts +0 -6
  231. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/mod.js +0 -22
  232. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/querying.d.ts +0 -54
  233. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/querying.js +0 -119
  234. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/stringify.d.ts +0 -40
  235. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/stringify.js +0 -86
  236. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/traversal.d.ts +0 -58
  237. package/script/deps/deno.land/x/html_parser@v0.1.3/src/utils/traversal.js +0 -112
  238. /package/esm/storage/{0_utilities.d.ts → 1_utilities.d.ts} +0 -0
  239. /package/esm/storage/{0_utilities.js → 1_utilities.js} +0 -0
  240. /package/esm/storage/{1_storage_indexed_db.d.ts → 2_storage_indexed_db.d.ts} +0 -0
  241. /package/esm/storage/{1_storage_local_storage.d.ts → 2_storage_local_storage.d.ts} +0 -0
  242. /package/esm/storage/{1_storage_session_storage.d.ts → 2_storage_session_storage.d.ts} +0 -0
  243. /package/esm/tl/{3_tl_reader.d.ts → 4_tl_reader.d.ts} +0 -0
  244. /package/esm/tl/{3_tl_reader.js → 4_tl_reader.js} +0 -0
  245. /package/esm/tl/{4_tl_writer.js → 5_tl_writer.js} +0 -0
  246. /package/esm/types/{0_venue.d.ts → 1_venue.d.ts} +0 -0
  247. /package/esm/types/{0_venue.js → 1_venue.js} +0 -0
  248. /package/esm/types/{0__file_id.d.ts → _file_id.d.ts} +0 -0
  249. /package/esm/types/{0__file_id.js → _file_id.js} +0 -0
  250. /package/esm/types/{1__getters.d.ts → _getters.d.ts} +0 -0
  251. /package/esm/types/{1__getters.js → _getters.js} +0 -0
  252. /package/script/storage/{0_utilities.d.ts → 1_utilities.d.ts} +0 -0
  253. /package/script/storage/{0_utilities.js → 1_utilities.js} +0 -0
  254. /package/script/storage/{1_storage_indexed_db.d.ts → 2_storage_indexed_db.d.ts} +0 -0
  255. /package/script/storage/{1_storage_local_storage.d.ts → 2_storage_local_storage.d.ts} +0 -0
  256. /package/script/storage/{1_storage_session_storage.d.ts → 2_storage_session_storage.d.ts} +0 -0
  257. /package/script/tl/{3_tl_reader.d.ts → 4_tl_reader.d.ts} +0 -0
  258. /package/script/tl/{3_tl_reader.js → 4_tl_reader.js} +0 -0
  259. /package/script/tl/{4_tl_writer.js → 5_tl_writer.js} +0 -0
  260. /package/script/types/{0_venue.d.ts → 1_venue.d.ts} +0 -0
  261. /package/script/types/{0_venue.js → 1_venue.js} +0 -0
  262. /package/script/types/{0__file_id.d.ts → _file_id.d.ts} +0 -0
  263. /package/script/types/{0__file_id.js → _file_id.js} +0 -0
  264. /package/script/types/{1__getters.d.ts → _getters.d.ts} +0 -0
  265. /package/script/types/{1__getters.js → _getters.js} +0 -0
@@ -1,101 +0,0 @@
1
- import { isTag } from '../Node.js';
2
- const emptyArray = [];
3
- /**
4
- * Get a node's children.
5
- *
6
- * @param elem Node to get the children of.
7
- * @returns `elem`'s children, or an empty array.
8
- */
9
- export function getChildren(elem) {
10
- return elem.children ?? emptyArray;
11
- }
12
- /**
13
- * Get a node's parent.
14
- *
15
- * @param elem Node to get the parent of.
16
- * @returns `elem`'s parent node.
17
- */
18
- export function getParent(elem) {
19
- return elem.parent || null;
20
- }
21
- /**
22
- * Gets an elements siblings, including the element itself.
23
- *
24
- * Attempts to get the children through the element's parent first.
25
- * If we don't have a parent (the element is a root node),
26
- * we walk the element's `prev` & `next` to get all remaining nodes.
27
- *
28
- * @param elem Element to get the siblings of.
29
- * @returns `elem`'s siblings.
30
- */
31
- export function getSiblings(elem) {
32
- const parent = getParent(elem);
33
- if (parent != null)
34
- return getChildren(parent);
35
- const siblings = [elem];
36
- let { prev, next } = elem;
37
- while (prev != null) {
38
- siblings.unshift(prev);
39
- ({ prev } = prev);
40
- }
41
- while (next != null) {
42
- siblings.push(next);
43
- ({ next } = next);
44
- }
45
- return siblings;
46
- }
47
- /**
48
- * Gets an attribute from an element.
49
- *
50
- * @param elem Element to check.
51
- * @param name Attribute name to retrieve.
52
- * @returns The element's attribute value, or `undefined`.
53
- */
54
- export function getAttributeValue(elem, name) {
55
- return elem.attribs?.[name];
56
- }
57
- /**
58
- * Checks whether an element has an attribute.
59
- *
60
- * @param elem Element to check.
61
- * @param name Attribute name to look for.
62
- * @returns Returns whether `elem` has the attribute `name`.
63
- */
64
- export function hasAttrib(elem, name) {
65
- return (elem.attribs != null &&
66
- Object.prototype.hasOwnProperty.call(elem.attribs, name) &&
67
- elem.attribs[name] != null);
68
- }
69
- /**
70
- * Get the tag name of an element.
71
- *
72
- * @param elem The element to get the name for.
73
- * @returns The tag name of `elem`.
74
- */
75
- export function getName(elem) {
76
- return elem.name;
77
- }
78
- /**
79
- * Returns the next element sibling of a node.
80
- *
81
- * @param elem The element to get the next sibling of.
82
- * @returns `elem`'s next sibling that is a tag.
83
- */
84
- export function nextElementSibling(elem) {
85
- let { next } = elem;
86
- while (next !== null && !isTag(next))
87
- ({ next } = next);
88
- return next;
89
- }
90
- /**
91
- * Returns the previous element sibling of a node.
92
- *
93
- * @param elem The element to get the previous sibling of.
94
- * @returns `elem`'s previous sibling that is a tag.
95
- */
96
- export function prevElementSibling(elem) {
97
- let { prev } = elem;
98
- while (prev !== null && !isTag(prev))
99
- ({ prev } = prev);
100
- return prev;
101
- }
@@ -1,83 +0,0 @@
1
- import { Node, Element, Document, NodeWithChildren, DataNode } from './Node.js';
2
- export interface DomHandlerOptions {
3
- /**
4
- * Add a `startIndex` property to nodes.
5
- * When the parser is used in a non-streaming fashion, `startIndex` is an integer
6
- * indicating the position of the start of the node in the document.
7
- *
8
- * @default false
9
- */
10
- withStartIndices?: boolean;
11
- /**
12
- * Add an `endIndex` property to nodes.
13
- * When the parser is used in a non-streaming fashion, `endIndex` is an integer
14
- * indicating the position of the end of the node in the document.
15
- *
16
- * @default false
17
- */
18
- withEndIndices?: boolean;
19
- /**
20
- * Replace all whitespace with single spaces.
21
- *
22
- * **Note:** Enabling this might break your markup.
23
- *
24
- * @default false
25
- * @deprecated
26
- */
27
- normalizeWhitespace?: boolean;
28
- /**
29
- * Treat the markup as XML.
30
- *
31
- * @default false
32
- */
33
- xmlMode?: boolean;
34
- }
35
- interface ParserInterface {
36
- startIndex: number | null;
37
- endIndex: number | null;
38
- }
39
- type Callback = (error: Error | null, dom: Node[]) => void;
40
- type ElementCallback = (element: Element) => void;
41
- export declare class DomHandler {
42
- /** The elements of the DOM */
43
- dom: Node[];
44
- /** The root element for the DOM */
45
- root: Document;
46
- /** Called once parsing has completed. */
47
- private readonly callback;
48
- /** Settings for the handler. */
49
- private readonly options;
50
- /** Callback whenever a tag is closed. */
51
- private readonly elementCB;
52
- /** Indicated whether parsing has been completed. */
53
- private done;
54
- /** Stack of open tags. */
55
- protected tagStack: NodeWithChildren[];
56
- /** A data node that is still being written to. */
57
- protected lastNode: DataNode | null;
58
- /** Reference to the parser instance. Used for location information. */
59
- private parser;
60
- /**
61
- * @param callback Called once parsing has completed.
62
- * @param options Settings for the handler.
63
- * @param elementCB Callback whenever a tag is closed.
64
- */
65
- constructor(callback?: Callback | null, options?: DomHandlerOptions | null, elementCB?: ElementCallback);
66
- onparserinit(parser: ParserInterface): void;
67
- onreset(): void;
68
- onend(): void;
69
- onerror(error: Error): void;
70
- onclosetag(): void;
71
- onopentag(name: string, attribs: {
72
- [key: string]: string;
73
- }): void;
74
- ontext(data: string): void;
75
- oncomment(data: string): void;
76
- oncommentend(): void;
77
- oncdatastart(): void;
78
- oncdataend(): void;
79
- onprocessinginstruction(name: string, data: string): void;
80
- protected handleCallback(error: Error | null): void;
81
- protected addNode(node: Node): void;
82
- }
83
- export default DomHandler;
@@ -1,207 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DomHandler = void 0;
4
- const Node_js_1 = require("./Node.js");
5
- const ElementType_js_1 = require("./ElementType.js");
6
- const reWhitespace = /\s+/g;
7
- // Default options
8
- const defaultOpts = {
9
- normalizeWhitespace: false,
10
- withStartIndices: false,
11
- withEndIndices: false,
12
- };
13
- class DomHandler {
14
- /**
15
- * @param callback Called once parsing has completed.
16
- * @param options Settings for the handler.
17
- * @param elementCB Callback whenever a tag is closed.
18
- */
19
- constructor(callback, options, elementCB) {
20
- /** The elements of the DOM */
21
- Object.defineProperty(this, "dom", {
22
- enumerable: true,
23
- configurable: true,
24
- writable: true,
25
- value: []
26
- });
27
- /** The root element for the DOM */
28
- Object.defineProperty(this, "root", {
29
- enumerable: true,
30
- configurable: true,
31
- writable: true,
32
- value: new Node_js_1.Document(this.dom)
33
- });
34
- /** Called once parsing has completed. */
35
- Object.defineProperty(this, "callback", {
36
- enumerable: true,
37
- configurable: true,
38
- writable: true,
39
- value: void 0
40
- });
41
- /** Settings for the handler. */
42
- Object.defineProperty(this, "options", {
43
- enumerable: true,
44
- configurable: true,
45
- writable: true,
46
- value: void 0
47
- });
48
- /** Callback whenever a tag is closed. */
49
- Object.defineProperty(this, "elementCB", {
50
- enumerable: true,
51
- configurable: true,
52
- writable: true,
53
- value: void 0
54
- });
55
- /** Indicated whether parsing has been completed. */
56
- Object.defineProperty(this, "done", {
57
- enumerable: true,
58
- configurable: true,
59
- writable: true,
60
- value: false
61
- });
62
- /** Stack of open tags. */
63
- Object.defineProperty(this, "tagStack", {
64
- enumerable: true,
65
- configurable: true,
66
- writable: true,
67
- value: [this.root]
68
- });
69
- /** A data node that is still being written to. */
70
- Object.defineProperty(this, "lastNode", {
71
- enumerable: true,
72
- configurable: true,
73
- writable: true,
74
- value: null
75
- });
76
- /** Reference to the parser instance. Used for location information. */
77
- Object.defineProperty(this, "parser", {
78
- enumerable: true,
79
- configurable: true,
80
- writable: true,
81
- value: null
82
- });
83
- // Make it possible to skip arguments, for backwards-compatibility
84
- if (typeof options === 'function') {
85
- elementCB = options;
86
- options = defaultOpts;
87
- }
88
- if (typeof callback === 'object') {
89
- options = callback;
90
- callback = undefined;
91
- }
92
- this.callback = callback ?? null;
93
- this.options = options ?? defaultOpts;
94
- this.elementCB = elementCB ?? null;
95
- }
96
- onparserinit(parser) {
97
- this.parser = parser;
98
- }
99
- // Resets the handler back to starting state
100
- onreset() {
101
- this.dom = [];
102
- this.root = new Node_js_1.Document(this.dom);
103
- this.done = false;
104
- this.tagStack = [this.root];
105
- this.lastNode = null;
106
- this.parser = this.parser ?? null;
107
- }
108
- // Signals the handler that parsing is done
109
- onend() {
110
- if (this.done)
111
- return;
112
- this.done = true;
113
- this.parser = null;
114
- this.handleCallback(null);
115
- }
116
- onerror(error) {
117
- this.handleCallback(error);
118
- }
119
- onclosetag() {
120
- this.lastNode = null;
121
- const elem = this.tagStack.pop();
122
- if (this.options.withEndIndices) {
123
- elem.endIndex = this.parser.endIndex;
124
- }
125
- if (this.elementCB)
126
- this.elementCB(elem);
127
- }
128
- onopentag(name, attribs) {
129
- const type = this.options.xmlMode ? ElementType_js_1.ElementType.Tag : undefined;
130
- const element = new Node_js_1.Element(name, attribs, undefined, type);
131
- this.addNode(element);
132
- this.tagStack.push(element);
133
- }
134
- ontext(data) {
135
- const { normalizeWhitespace } = this.options;
136
- const { lastNode } = this;
137
- if (lastNode && lastNode.type === ElementType_js_1.ElementType.Text) {
138
- if (normalizeWhitespace) {
139
- lastNode.data = (lastNode.data + data).replace(reWhitespace, ' ');
140
- }
141
- else {
142
- lastNode.data += data;
143
- }
144
- }
145
- else {
146
- if (normalizeWhitespace) {
147
- data = data.replace(reWhitespace, ' ');
148
- }
149
- const node = new Node_js_1.Text(data);
150
- this.addNode(node);
151
- this.lastNode = node;
152
- }
153
- }
154
- oncomment(data) {
155
- if (this.lastNode && this.lastNode.type === ElementType_js_1.ElementType.Comment) {
156
- this.lastNode.data += data;
157
- return;
158
- }
159
- const node = new Node_js_1.Comment(data);
160
- this.addNode(node);
161
- this.lastNode = node;
162
- }
163
- oncommentend() {
164
- this.lastNode = null;
165
- }
166
- oncdatastart() {
167
- const text = new Node_js_1.Text('');
168
- const node = new Node_js_1.NodeWithChildren(ElementType_js_1.ElementType.CDATA, [text]);
169
- this.addNode(node);
170
- text.parent = node;
171
- this.lastNode = text;
172
- }
173
- oncdataend() {
174
- this.lastNode = null;
175
- }
176
- onprocessinginstruction(name, data) {
177
- const node = new Node_js_1.ProcessingInstruction(name, data);
178
- this.addNode(node);
179
- }
180
- handleCallback(error) {
181
- if (typeof this.callback === 'function') {
182
- this.callback(error, this.dom);
183
- }
184
- else if (error) {
185
- throw error;
186
- }
187
- }
188
- addNode(node) {
189
- const parent = this.tagStack[this.tagStack.length - 1];
190
- const previousSibling = parent.children[parent.children.length - 1];
191
- if (this.options.withStartIndices) {
192
- node.startIndex = this.parser.startIndex;
193
- }
194
- if (this.options.withEndIndices) {
195
- node.endIndex = this.parser.endIndex;
196
- }
197
- parent.children.push(node);
198
- if (previousSibling) {
199
- node.prev = previousSibling;
200
- previousSibling.next = node;
201
- }
202
- node.parent = parent;
203
- this.lastNode = null;
204
- }
205
- }
206
- exports.DomHandler = DomHandler;
207
- exports.default = DomHandler;
@@ -1,50 +0,0 @@
1
- import type { Node } from './Node.js';
2
- /**
3
- * Mixed-case SVG and MathML tags & attributes
4
- * recognized by the HTML parser.
5
- *
6
- * @see https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inforeign
7
- */
8
- export declare const elementNames: Map<string, string>;
9
- export declare const attributeNames: Map<string, string>;
10
- export interface DomSerializerOptions {
11
- /**
12
- * Print an empty attribute's value.
13
- *
14
- * @default xmlMode
15
- * @example With <code>emptyAttrs: false</code>: <code>&lt;input checked&gt;</code>
16
- * @example With <code>emptyAttrs: true</code>: <code>&lt;input checked=""&gt;</code>
17
- */
18
- emptyAttrs?: boolean;
19
- /**
20
- * Print self-closing tags for tags without contents.
21
- *
22
- * @default xmlMode
23
- * @example With <code>selfClosingTags: false</code>: <code>&lt;foo&gt;&lt;/foo&gt;</code>
24
- * @example With <code>selfClosingTags: true</code>: <code>&lt;foo /&gt;</code>
25
- */
26
- selfClosingTags?: boolean;
27
- /**
28
- * Treat the input as an XML document; enables the `emptyAttrs` and `selfClosingTags` options.
29
- *
30
- * If the value is `"foreign"`, it will try to correct mixed-case attribute names.
31
- *
32
- * @default false
33
- */
34
- xmlMode?: boolean | 'foreign';
35
- /**
36
- * Encode characters that are either reserved in HTML or XML, or are outside of the ASCII range.
37
- *
38
- * @default true
39
- */
40
- decodeEntities?: boolean;
41
- }
42
- /**
43
- * Renders a DOM node or an array of DOM nodes to a string.
44
- *
45
- * Can be thought of as the equivalent of the `outerHTML` of the passed node(s).
46
- *
47
- * @param node Node to be rendered.
48
- * @param options Changes serialization behavior
49
- */
50
- export default function render(node: Node | ArrayLike<Node>, options?: DomSerializerOptions): string;