@wabot-dev/framework 0.1.0-beta.9 → 0.2.0-beta.1

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 (212) hide show
  1. package/dist/src/addon/async/pg/PgJobRepository.js +26 -0
  2. package/dist/src/addon/auth/api-key/@apiKeyConnectionGuard.js +16 -0
  3. package/dist/src/addon/auth/api-key/@apiKeyGuard.js +17 -0
  4. package/dist/src/addon/auth/api-key/ApiKey.js +45 -0
  5. package/dist/src/addon/auth/api-key/ApiKeyConnectionGuardMiddleware.js +57 -0
  6. package/dist/src/addon/auth/api-key/ApiKeyGuardMiddleware.js +45 -0
  7. package/dist/src/addon/auth/api-key/ApiKeyRepository.js +22 -0
  8. package/dist/src/addon/auth/api-key/PgApiKeyRepository.js +53 -0
  9. package/dist/src/addon/auth/api-key/RemoteApiKeyRepository.js +62 -0
  10. package/dist/src/addon/auth/jwt/@jwtConnectionGuard.js +16 -0
  11. package/dist/src/addon/auth/jwt/@jwtGuard.js +17 -0
  12. package/dist/src/addon/auth/jwt/Jwt.js +53 -0
  13. package/dist/src/addon/auth/jwt/JwtAccessAndRefreshTokenDto.js +20 -0
  14. package/dist/src/addon/auth/jwt/JwtConfig.js +28 -0
  15. package/dist/src/addon/auth/jwt/JwtConnectionGuardMiddleware.js +57 -0
  16. package/dist/src/addon/auth/jwt/JwtGuardMiddleware.js +45 -0
  17. package/dist/src/addon/auth/jwt/JwtRefreshToken.js +56 -0
  18. package/dist/src/addon/auth/jwt/JwtRefreshTokenRepository.js +25 -0
  19. package/dist/src/addon/auth/jwt/JwtSigner.js +36 -0
  20. package/dist/src/addon/auth/jwt/JwtTokenDto.js +22 -0
  21. package/dist/src/addon/auth/jwt/PgJwtRefreshTokenRepository.js +21 -0
  22. package/dist/src/addon/chat-bot/anthropic/AnthropicChatAdapter.js +135 -0
  23. package/dist/src/addon/chat-bot/deepseek/DeepSeekChatAdapter.js +137 -0
  24. package/dist/src/addon/chat-bot/google/GoogleChatAdapter.js +128 -0
  25. package/dist/src/addon/chat-bot/openia/OpenaiChatAdapter.js +117 -0
  26. package/dist/src/{pre-made/repository/chat → addon/chat-bot}/pg/PgChatMemory.js +6 -4
  27. package/dist/src/{pre-made/repository/chat → addon/chat-bot}/pg/PgChatRepository.js +6 -5
  28. package/dist/src/{pre-made/repository/chat → addon/chat-bot}/ram/RamChatRepository.js +2 -2
  29. package/dist/src/addon/chat-bot/wabot/WabotChatAdapter.js +41 -0
  30. package/dist/src/addon/chat-controller/cmd/@cmd.js +24 -0
  31. package/dist/src/addon/chat-controller/cmd/CmdChannel.js +91 -0
  32. package/dist/src/{channels → addon/chat-controller}/socket/@socket.js +10 -4
  33. package/dist/src/{channels → addon/chat-controller}/socket/SocketChannel.js +9 -23
  34. package/dist/src/{channels → addon/chat-controller}/socket/SocketChannelConfig.js +1 -1
  35. package/dist/src/{channels → addon/chat-controller}/telegram/@telegram.js +10 -4
  36. package/dist/src/{channels → addon/chat-controller}/telegram/TelegramChannel.js +4 -22
  37. package/dist/src/addon/chat-controller/whatsapp/@whatsApp.js +26 -0
  38. package/dist/src/{channels → addon/chat-controller}/whatsapp/EnvWhatsAppRepository.js +3 -3
  39. package/dist/src/{channels → addon/chat-controller}/whatsapp/PgWhatsAppRepository.js +2 -2
  40. package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsApp.js +2 -4
  41. package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppChannel.js +6 -18
  42. package/dist/src/addon/chat-controller/whatsapp/WhatsAppReceiver.js +10 -0
  43. package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppSender.js +15 -39
  44. package/dist/src/addon/chat-controller/whatsapp/cloud-api/WhatsAppReceiverByCloudApi.js +97 -0
  45. package/dist/src/{channels/whatsapp → addon/chat-controller/whatsapp/cloud-api}/WhatsAppSenderByCloudApi.js +27 -20
  46. package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppProxyContracts.js +5 -0
  47. package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppReceiverByWabotProxy.js +65 -0
  48. package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppSenderByWabotProxy.js +61 -0
  49. package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppWabotProxyConnection.js +45 -0
  50. package/dist/src/{pre-made/module → addon/mindset}/html/HtmlModule.js +7 -7
  51. package/dist/src/core/auth/Auth.js +33 -0
  52. package/dist/src/core/{Persistent.js → entity/Entity.js} +24 -12
  53. package/dist/src/core/env/Env.js +39 -0
  54. package/dist/src/core/error/CustomError.js +15 -0
  55. package/dist/src/core/injection/index.js +4 -0
  56. package/dist/src/core/mapper/Mapper.js +42 -0
  57. package/dist/src/core/password/Password.js +30 -0
  58. package/dist/src/core/random/Random.js +65 -0
  59. package/dist/src/core/storable/Storable.js +8 -0
  60. package/dist/src/core/validation/core/validateArray.js +51 -0
  61. package/dist/src/core/validation/core/validateModel.js +36 -0
  62. package/dist/src/{validation/metadata/@isNumber.js → core/validation/metadata/@isArray.js} +5 -4
  63. package/dist/src/{validation/metadata/@isDate.js → core/validation/metadata/@isModel.js} +5 -4
  64. package/dist/src/{validation → core/validation}/metadata/@isOptional.js +1 -1
  65. package/dist/src/core/validation/metadata/ValidationMetadataStore.js +98 -0
  66. package/dist/src/core/validation/modelInfo.js +9 -0
  67. package/dist/src/{validation/validateModel2.js → core/validation/validate.js} +3 -3
  68. package/dist/src/{validation/metadata → core/validation/validators/is-boolean}/@isBoolean.js +3 -3
  69. package/dist/src/core/validation/validators/is-date/@isDate.js +17 -0
  70. package/dist/src/core/validation/validators/is-in/@isIn.js +18 -0
  71. package/dist/src/core/validation/validators/is-in/validateIsIn.js +12 -0
  72. package/dist/src/{validation/metadata → core/validation/validators/is-not-empty}/@isNotEmpty.js +3 -3
  73. package/dist/src/core/validation/validators/is-number/@isNumber.js +17 -0
  74. package/dist/src/{validation/metadata → core/validation/validators/is-present}/@isPresent.js +3 -3
  75. package/dist/src/{validation/metadata → core/validation/validators/is-string}/@isString.js +3 -3
  76. package/dist/src/{validation/metadata → core/validation/validators/max}/@max.js +3 -3
  77. package/dist/src/{validation/metadata → core/validation/validators/min}/@min.js +3 -3
  78. package/dist/src/feature/async/@command.js +11 -0
  79. package/dist/src/feature/async/@commandHandler.js +12 -0
  80. package/dist/src/feature/async/Async.js +38 -0
  81. package/dist/src/feature/async/Command.js +9 -0
  82. package/dist/src/feature/async/CommandMetadataStore.js +38 -0
  83. package/dist/src/feature/async/Job.js +27 -0
  84. package/dist/src/feature/async/JobRepository.js +31 -0
  85. package/dist/src/feature/async/JobRunner.js +48 -0
  86. package/dist/src/feature/async/JobsEventsHub.js +36 -0
  87. package/dist/src/feature/async/runCommandHandlers.js +29 -0
  88. package/dist/src/{core/chat → feature/chat-bot}/Chat.js +2 -2
  89. package/dist/src/feature/chat-bot/ChatAdapter.js +7 -0
  90. package/dist/src/feature/chat-bot/ChatBot.js +73 -0
  91. package/dist/src/feature/chat-bot/ChatItem.js +24 -0
  92. package/dist/src/feature/chat-bot/ChatMemory.js +10 -0
  93. package/dist/src/{core/chat/repository/IChatRepository.js → feature/chat-bot/ChatRepository.js} +2 -8
  94. package/dist/src/feature/chat-bot/IChatItem.js +3 -0
  95. package/dist/src/{chatbot → feature/chat-bot}/metadata/@chatBot.js +1 -1
  96. package/dist/src/{chatbot → feature/chat-bot}/metadata/ChatBotMetadataStore.js +1 -1
  97. package/dist/src/{controller/channel → feature/chat-controller}/ChatResolver.js +6 -4
  98. package/dist/src/{controller → feature/chat-controller}/metadata/ControllerMetadataStore.js +1 -1
  99. package/dist/src/{controller → feature/chat-controller}/metadata/controller/@chatController.js +1 -1
  100. package/dist/src/feature/chat-controller/runChatControllers.js +83 -0
  101. package/dist/src/{channels → feature}/express/ExpressProvider.js +2 -4
  102. package/dist/src/{channels → feature}/http/HttpServerProvider.js +2 -2
  103. package/dist/src/{mindset → feature/mindset}/IMindset.js +6 -0
  104. package/dist/src/feature/mindset/MindsetOperator.js +180 -0
  105. package/dist/src/{mindset → feature/mindset}/metadata/MindsetMetadataStore.js +1 -1
  106. package/dist/src/{mindset → feature/mindset}/metadata/functions/@mindsetFunction.js +1 -1
  107. package/dist/src/{mindset → feature/mindset}/metadata/mindsets/@mindset.js +1 -1
  108. package/dist/src/{mindset → feature/mindset}/metadata/modules/@mindsetModule.js +1 -2
  109. package/dist/src/{mindset → feature/mindset}/metadata/params/@param.js +1 -1
  110. package/dist/src/feature/money/Money.js +61 -0
  111. package/dist/src/feature/money/MoneyDto.js +22 -0
  112. package/dist/src/{repository → feature}/pg/PgCrudRepository.js +24 -10
  113. package/dist/src/{repository → feature}/pg/PgRepositoryBase.js +2 -2
  114. package/dist/src/feature/rest-controller/injection-tokens.js +4 -0
  115. package/dist/src/{rest-controller/metadata/@post.js → feature/rest-controller/metadata/@middleware.js} +5 -8
  116. package/dist/src/feature/rest-controller/metadata/@onDelete.js +7 -0
  117. package/dist/src/feature/rest-controller/metadata/@onGet.js +7 -0
  118. package/dist/src/feature/rest-controller/metadata/@onPost.js +7 -0
  119. package/dist/src/feature/rest-controller/metadata/@onPut.js +7 -0
  120. package/dist/src/{rest-controller → feature/rest-controller}/metadata/@restController.js +2 -2
  121. package/dist/src/{rest-controller → feature/rest-controller}/metadata/RestControllerMetadataStore.js +14 -1
  122. package/dist/src/{rest-controller/metadata/@get.js → feature/rest-controller/metadata/methodDecorator.js} +5 -5
  123. package/dist/src/feature/rest-controller/runRestControllers.js +103 -0
  124. package/dist/src/{channels → feature}/socket/SocketServerProvider.js +2 -2
  125. package/dist/src/feature/socket-controller/metadata/@connectionMiddleware.js +16 -0
  126. package/dist/src/feature/socket-controller/metadata/@socketConnection.js +18 -0
  127. package/dist/src/feature/socket-controller/metadata/@socketController.js +15 -0
  128. package/dist/src/feature/socket-controller/metadata/@socketEvent.js +18 -0
  129. package/dist/src/feature/socket-controller/metadata/SocketControllerMetadataStore.js +65 -0
  130. package/dist/src/feature/socket-controller/runSocketControllers.js +99 -0
  131. package/dist/src/index.d.ts +1219 -718
  132. package/dist/src/index.js +147 -102
  133. package/package.json +8 -2
  134. package/dist/src/_virtual/_commonjsHelpers.js +0 -5
  135. package/dist/src/_virtual/cjs.js +0 -7
  136. package/dist/src/ai/deepseek/DeepSeekChatBotAdapter.js +0 -107
  137. package/dist/src/ai/openia/OpenaiChatBotAdapter.js +0 -88
  138. package/dist/src/channels/cmd/@cmd.js +0 -18
  139. package/dist/src/channels/cmd/CmdChannel.js +0 -73
  140. package/dist/src/channels/wabot/WabotDevConnection.js +0 -57
  141. package/dist/src/channels/wabot/WabotDevSocketContracts.js +0 -10
  142. package/dist/src/channels/whatsapp/@whatsapp.js +0 -20
  143. package/dist/src/channels/whatsapp/WhatsAppReceiver.js +0 -59
  144. package/dist/src/channels/whatsapp/WhatsAppReceiverByDevConnection.js +0 -32
  145. package/dist/src/channels/whatsapp/WhatsAppReceiverByWebHook.js +0 -63
  146. package/dist/src/channels/whatsapp/WhatsAppSenderByDevConnection.js +0 -61
  147. package/dist/src/chatbot/ChatBot.js +0 -51
  148. package/dist/src/chatbot/ChatBotAdapter.js +0 -72
  149. package/dist/src/controller/channel/UserResolver.js +0 -21
  150. package/dist/src/core/IMessageContext.js +0 -12
  151. package/dist/src/core/chat/ChatItem.js +0 -15
  152. package/dist/src/core/chat/repository/IChatMemory.js +0 -10
  153. package/dist/src/core/user/IUserRepository.js +0 -19
  154. package/dist/src/core/user/User.js +0 -26
  155. package/dist/src/env/WabotEnv.js +0 -27
  156. package/dist/src/injection/index.js +0 -4
  157. package/dist/src/mindset/MindsetOperator.js +0 -101
  158. package/dist/src/node_modules/@selderee/plugin-htmlparser2/lib/hp2-builder.js +0 -90
  159. package/dist/src/node_modules/deepmerge/dist/cjs.js +0 -142
  160. package/dist/src/node_modules/dom-serializer/lib/esm/foreignNames.js +0 -102
  161. package/dist/src/node_modules/dom-serializer/lib/esm/index.js +0 -186
  162. package/dist/src/node_modules/domelementtype/lib/esm/index.js +0 -53
  163. package/dist/src/node_modules/domhandler/lib/esm/index.js +0 -148
  164. package/dist/src/node_modules/domhandler/lib/esm/node.js +0 -334
  165. package/dist/src/node_modules/entities/lib/esm/decode.js +0 -458
  166. package/dist/src/node_modules/entities/lib/esm/decode_codepoint.js +0 -62
  167. package/dist/src/node_modules/entities/lib/esm/escape.js +0 -99
  168. package/dist/src/node_modules/entities/lib/esm/generated/decode-data-html.js +0 -8
  169. package/dist/src/node_modules/entities/lib/esm/generated/decode-data-xml.js +0 -8
  170. package/dist/src/node_modules/html-to-text/lib/html-to-text.js +0 -2147
  171. package/dist/src/node_modules/htmlparser2/lib/esm/Parser.js +0 -491
  172. package/dist/src/node_modules/htmlparser2/lib/esm/Tokenizer.js +0 -928
  173. package/dist/src/node_modules/htmlparser2/lib/esm/index.js +0 -18
  174. package/dist/src/node_modules/leac/lib/leac.js +0 -3
  175. package/dist/src/node_modules/parseley/lib/parseley.js +0 -270
  176. package/dist/src/node_modules/peberminta/lib/core.js +0 -171
  177. package/dist/src/node_modules/selderee/lib/selderee.js +0 -380
  178. package/dist/src/pre-made/module/authentication/AuthenticationModule.js +0 -97
  179. package/dist/src/pre-made/module/authentication/requests/SendOneTimePasswordRequest.js +0 -25
  180. package/dist/src/pre-made/module/authentication/requests/ValidateOneTimePasswordRequest.js +0 -25
  181. package/dist/src/pre-made/module/register-user/RegisterUserModule.js +0 -56
  182. package/dist/src/pre-made/module/register-user/requests/RegisterUserWithEmailRequest.js +0 -25
  183. package/dist/src/pre-made/repository/user/pg/PgUserRepository.js +0 -33
  184. package/dist/src/pre-made/repository/user/ram/RamUserRepository.js +0 -27
  185. package/dist/src/pre-made/service/EmailService.js +0 -13
  186. package/dist/src/pre-made/service/OtpService.js +0 -14
  187. package/dist/src/rest-controller/runRestControllers.js +0 -74
  188. package/dist/src/server/prepareChatContainer.js +0 -43
  189. package/dist/src/server/runChannel.js +0 -27
  190. package/dist/src/server/runServer.js +0 -40
  191. package/dist/src/validation/metadata/@validable.js +0 -14
  192. package/dist/src/validation/metadata/ValidationMetadataStore.js +0 -55
  193. package/dist/src/validation/validators/validateModel.js +0 -47
  194. /package/dist/src/{pre-made/repository/chat → addon/chat-bot}/ram/RamChatMemory.js +0 -0
  195. /package/dist/src/{channels → addon/chat-controller}/telegram/TelegramChannelConfig.js +0 -0
  196. /package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppChannelConfig.js +0 -0
  197. /package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppRepository.js +0 -0
  198. /package/dist/src/{injection → core/injection}/Container.js +0 -0
  199. /package/dist/src/{logger → core/logger}/Logger.js +0 -0
  200. /package/dist/src/{validation/validators → core/validation/core}/validateIsOptional.js +0 -0
  201. /package/dist/src/{validation/validators → core/validation/validators/is-boolean}/validateIsBoolean.js +0 -0
  202. /package/dist/src/{validation/validators → core/validation/validators/is-date}/validateIsDate.js +0 -0
  203. /package/dist/src/{validation/validators → core/validation/validators/is-not-empty}/validateIsNotEmpty.js +0 -0
  204. /package/dist/src/{validation/validators → core/validation/validators/is-number}/validateIsNumber.js +0 -0
  205. /package/dist/src/{validation/validators → core/validation/validators/is-present}/validateIsPresent.js +0 -0
  206. /package/dist/src/{validation/validators → core/validation/validators/is-string}/validateIsString.js +0 -0
  207. /package/dist/src/{validation/validators → core/validation/validators/max}/validateMax.js +0 -0
  208. /package/dist/src/{validation/validators → core/validation/validators/min}/validateMin.js +0 -0
  209. /package/dist/src/{mindset → feature/mindset}/metadata/functions/decoratorNames.js +0 -0
  210. /package/dist/src/{mindset → feature/mindset}/metadata/mindsets/decoratorNames.js +0 -0
  211. /package/dist/src/{mindset → feature/mindset}/metadata/modules/decoratorNames.js +0 -0
  212. /package/dist/src/{mindset → feature/mindset}/metadata/params/decoratorNames.js +0 -0
@@ -1,491 +0,0 @@
1
- import Tokenizer, { QuoteType } from './Tokenizer.js';
2
- import { fromCodePoint } from '../../../entities/lib/esm/decode_codepoint.js';
3
-
4
- const formTags = new Set([
5
- "input",
6
- "option",
7
- "optgroup",
8
- "select",
9
- "button",
10
- "datalist",
11
- "textarea",
12
- ]);
13
- const pTag = new Set(["p"]);
14
- const tableSectionTags = new Set(["thead", "tbody"]);
15
- const ddtTags = new Set(["dd", "dt"]);
16
- const rtpTags = new Set(["rt", "rp"]);
17
- const openImpliesClose = new Map([
18
- ["tr", new Set(["tr", "th", "td"])],
19
- ["th", new Set(["th"])],
20
- ["td", new Set(["thead", "th", "td"])],
21
- ["body", new Set(["head", "link", "script"])],
22
- ["li", new Set(["li"])],
23
- ["p", pTag],
24
- ["h1", pTag],
25
- ["h2", pTag],
26
- ["h3", pTag],
27
- ["h4", pTag],
28
- ["h5", pTag],
29
- ["h6", pTag],
30
- ["select", formTags],
31
- ["input", formTags],
32
- ["output", formTags],
33
- ["button", formTags],
34
- ["datalist", formTags],
35
- ["textarea", formTags],
36
- ["option", new Set(["option"])],
37
- ["optgroup", new Set(["optgroup", "option"])],
38
- ["dd", ddtTags],
39
- ["dt", ddtTags],
40
- ["address", pTag],
41
- ["article", pTag],
42
- ["aside", pTag],
43
- ["blockquote", pTag],
44
- ["details", pTag],
45
- ["div", pTag],
46
- ["dl", pTag],
47
- ["fieldset", pTag],
48
- ["figcaption", pTag],
49
- ["figure", pTag],
50
- ["footer", pTag],
51
- ["form", pTag],
52
- ["header", pTag],
53
- ["hr", pTag],
54
- ["main", pTag],
55
- ["nav", pTag],
56
- ["ol", pTag],
57
- ["pre", pTag],
58
- ["section", pTag],
59
- ["table", pTag],
60
- ["ul", pTag],
61
- ["rt", rtpTags],
62
- ["rp", rtpTags],
63
- ["tbody", tableSectionTags],
64
- ["tfoot", tableSectionTags],
65
- ]);
66
- const voidElements = new Set([
67
- "area",
68
- "base",
69
- "basefont",
70
- "br",
71
- "col",
72
- "command",
73
- "embed",
74
- "frame",
75
- "hr",
76
- "img",
77
- "input",
78
- "isindex",
79
- "keygen",
80
- "link",
81
- "meta",
82
- "param",
83
- "source",
84
- "track",
85
- "wbr",
86
- ]);
87
- const foreignContextElements = new Set(["math", "svg"]);
88
- const htmlIntegrationElements = new Set([
89
- "mi",
90
- "mo",
91
- "mn",
92
- "ms",
93
- "mtext",
94
- "annotation-xml",
95
- "foreignobject",
96
- "desc",
97
- "title",
98
- ]);
99
- const reNameEnd = /\s|\//;
100
- class Parser {
101
- constructor(cbs, options = {}) {
102
- var _a, _b, _c, _d, _e;
103
- this.options = options;
104
- /** The start index of the last event. */
105
- this.startIndex = 0;
106
- /** The end index of the last event. */
107
- this.endIndex = 0;
108
- /**
109
- * Store the start index of the current open tag,
110
- * so we can update the start index for attributes.
111
- */
112
- this.openTagStart = 0;
113
- this.tagname = "";
114
- this.attribname = "";
115
- this.attribvalue = "";
116
- this.attribs = null;
117
- this.stack = [];
118
- this.foreignContext = [];
119
- this.buffers = [];
120
- this.bufferOffset = 0;
121
- /** The index of the last written buffer. Used when resuming after a `pause()`. */
122
- this.writeIndex = 0;
123
- /** Indicates whether the parser has finished running / `.end` has been called. */
124
- this.ended = false;
125
- this.cbs = cbs !== null && cbs !== void 0 ? cbs : {};
126
- this.lowerCaseTagNames = (_a = options.lowerCaseTags) !== null && _a !== void 0 ? _a : !options.xmlMode;
127
- this.lowerCaseAttributeNames =
128
- (_b = options.lowerCaseAttributeNames) !== null && _b !== void 0 ? _b : !options.xmlMode;
129
- this.tokenizer = new ((_c = options.Tokenizer) !== null && _c !== void 0 ? _c : Tokenizer)(this.options, this);
130
- (_e = (_d = this.cbs).onparserinit) === null || _e === void 0 ? void 0 : _e.call(_d, this);
131
- }
132
- // Tokenizer event handlers
133
- /** @internal */
134
- ontext(start, endIndex) {
135
- var _a, _b;
136
- const data = this.getSlice(start, endIndex);
137
- this.endIndex = endIndex - 1;
138
- (_b = (_a = this.cbs).ontext) === null || _b === void 0 ? void 0 : _b.call(_a, data);
139
- this.startIndex = endIndex;
140
- }
141
- /** @internal */
142
- ontextentity(cp) {
143
- var _a, _b;
144
- /*
145
- * Entities can be emitted on the character, or directly after.
146
- * We use the section start here to get accurate indices.
147
- */
148
- const index = this.tokenizer.getSectionStart();
149
- this.endIndex = index - 1;
150
- (_b = (_a = this.cbs).ontext) === null || _b === void 0 ? void 0 : _b.call(_a, fromCodePoint(cp));
151
- this.startIndex = index;
152
- }
153
- isVoidElement(name) {
154
- return !this.options.xmlMode && voidElements.has(name);
155
- }
156
- /** @internal */
157
- onopentagname(start, endIndex) {
158
- this.endIndex = endIndex;
159
- let name = this.getSlice(start, endIndex);
160
- if (this.lowerCaseTagNames) {
161
- name = name.toLowerCase();
162
- }
163
- this.emitOpenTag(name);
164
- }
165
- emitOpenTag(name) {
166
- var _a, _b, _c, _d;
167
- this.openTagStart = this.startIndex;
168
- this.tagname = name;
169
- const impliesClose = !this.options.xmlMode && openImpliesClose.get(name);
170
- if (impliesClose) {
171
- while (this.stack.length > 0 &&
172
- impliesClose.has(this.stack[this.stack.length - 1])) {
173
- const element = this.stack.pop();
174
- (_b = (_a = this.cbs).onclosetag) === null || _b === void 0 ? void 0 : _b.call(_a, element, true);
175
- }
176
- }
177
- if (!this.isVoidElement(name)) {
178
- this.stack.push(name);
179
- if (foreignContextElements.has(name)) {
180
- this.foreignContext.push(true);
181
- }
182
- else if (htmlIntegrationElements.has(name)) {
183
- this.foreignContext.push(false);
184
- }
185
- }
186
- (_d = (_c = this.cbs).onopentagname) === null || _d === void 0 ? void 0 : _d.call(_c, name);
187
- if (this.cbs.onopentag)
188
- this.attribs = {};
189
- }
190
- endOpenTag(isImplied) {
191
- var _a, _b;
192
- this.startIndex = this.openTagStart;
193
- if (this.attribs) {
194
- (_b = (_a = this.cbs).onopentag) === null || _b === void 0 ? void 0 : _b.call(_a, this.tagname, this.attribs, isImplied);
195
- this.attribs = null;
196
- }
197
- if (this.cbs.onclosetag && this.isVoidElement(this.tagname)) {
198
- this.cbs.onclosetag(this.tagname, true);
199
- }
200
- this.tagname = "";
201
- }
202
- /** @internal */
203
- onopentagend(endIndex) {
204
- this.endIndex = endIndex;
205
- this.endOpenTag(false);
206
- // Set `startIndex` for next node
207
- this.startIndex = endIndex + 1;
208
- }
209
- /** @internal */
210
- onclosetag(start, endIndex) {
211
- var _a, _b, _c, _d, _e, _f;
212
- this.endIndex = endIndex;
213
- let name = this.getSlice(start, endIndex);
214
- if (this.lowerCaseTagNames) {
215
- name = name.toLowerCase();
216
- }
217
- if (foreignContextElements.has(name) ||
218
- htmlIntegrationElements.has(name)) {
219
- this.foreignContext.pop();
220
- }
221
- if (!this.isVoidElement(name)) {
222
- const pos = this.stack.lastIndexOf(name);
223
- if (pos !== -1) {
224
- if (this.cbs.onclosetag) {
225
- let count = this.stack.length - pos;
226
- while (count--) {
227
- // We know the stack has sufficient elements.
228
- this.cbs.onclosetag(this.stack.pop(), count !== 0);
229
- }
230
- }
231
- else
232
- this.stack.length = pos;
233
- }
234
- else if (!this.options.xmlMode && name === "p") {
235
- // Implicit open before close
236
- this.emitOpenTag("p");
237
- this.closeCurrentTag(true);
238
- }
239
- }
240
- else if (!this.options.xmlMode && name === "br") {
241
- // We can't use `emitOpenTag` for implicit open, as `br` would be implicitly closed.
242
- (_b = (_a = this.cbs).onopentagname) === null || _b === void 0 ? void 0 : _b.call(_a, "br");
243
- (_d = (_c = this.cbs).onopentag) === null || _d === void 0 ? void 0 : _d.call(_c, "br", {}, true);
244
- (_f = (_e = this.cbs).onclosetag) === null || _f === void 0 ? void 0 : _f.call(_e, "br", false);
245
- }
246
- // Set `startIndex` for next node
247
- this.startIndex = endIndex + 1;
248
- }
249
- /** @internal */
250
- onselfclosingtag(endIndex) {
251
- this.endIndex = endIndex;
252
- if (this.options.xmlMode ||
253
- this.options.recognizeSelfClosing ||
254
- this.foreignContext[this.foreignContext.length - 1]) {
255
- this.closeCurrentTag(false);
256
- // Set `startIndex` for next node
257
- this.startIndex = endIndex + 1;
258
- }
259
- else {
260
- // Ignore the fact that the tag is self-closing.
261
- this.onopentagend(endIndex);
262
- }
263
- }
264
- closeCurrentTag(isOpenImplied) {
265
- var _a, _b;
266
- const name = this.tagname;
267
- this.endOpenTag(isOpenImplied);
268
- // Self-closing tags will be on the top of the stack
269
- if (this.stack[this.stack.length - 1] === name) {
270
- // If the opening tag isn't implied, the closing tag has to be implied.
271
- (_b = (_a = this.cbs).onclosetag) === null || _b === void 0 ? void 0 : _b.call(_a, name, !isOpenImplied);
272
- this.stack.pop();
273
- }
274
- }
275
- /** @internal */
276
- onattribname(start, endIndex) {
277
- this.startIndex = start;
278
- const name = this.getSlice(start, endIndex);
279
- this.attribname = this.lowerCaseAttributeNames
280
- ? name.toLowerCase()
281
- : name;
282
- }
283
- /** @internal */
284
- onattribdata(start, endIndex) {
285
- this.attribvalue += this.getSlice(start, endIndex);
286
- }
287
- /** @internal */
288
- onattribentity(cp) {
289
- this.attribvalue += fromCodePoint(cp);
290
- }
291
- /** @internal */
292
- onattribend(quote, endIndex) {
293
- var _a, _b;
294
- this.endIndex = endIndex;
295
- (_b = (_a = this.cbs).onattribute) === null || _b === void 0 ? void 0 : _b.call(_a, this.attribname, this.attribvalue, quote === QuoteType.Double
296
- ? '"'
297
- : quote === QuoteType.Single
298
- ? "'"
299
- : quote === QuoteType.NoValue
300
- ? undefined
301
- : null);
302
- if (this.attribs &&
303
- !Object.prototype.hasOwnProperty.call(this.attribs, this.attribname)) {
304
- this.attribs[this.attribname] = this.attribvalue;
305
- }
306
- this.attribvalue = "";
307
- }
308
- getInstructionName(value) {
309
- const index = value.search(reNameEnd);
310
- let name = index < 0 ? value : value.substr(0, index);
311
- if (this.lowerCaseTagNames) {
312
- name = name.toLowerCase();
313
- }
314
- return name;
315
- }
316
- /** @internal */
317
- ondeclaration(start, endIndex) {
318
- this.endIndex = endIndex;
319
- const value = this.getSlice(start, endIndex);
320
- if (this.cbs.onprocessinginstruction) {
321
- const name = this.getInstructionName(value);
322
- this.cbs.onprocessinginstruction(`!${name}`, `!${value}`);
323
- }
324
- // Set `startIndex` for next node
325
- this.startIndex = endIndex + 1;
326
- }
327
- /** @internal */
328
- onprocessinginstruction(start, endIndex) {
329
- this.endIndex = endIndex;
330
- const value = this.getSlice(start, endIndex);
331
- if (this.cbs.onprocessinginstruction) {
332
- const name = this.getInstructionName(value);
333
- this.cbs.onprocessinginstruction(`?${name}`, `?${value}`);
334
- }
335
- // Set `startIndex` for next node
336
- this.startIndex = endIndex + 1;
337
- }
338
- /** @internal */
339
- oncomment(start, endIndex, offset) {
340
- var _a, _b, _c, _d;
341
- this.endIndex = endIndex;
342
- (_b = (_a = this.cbs).oncomment) === null || _b === void 0 ? void 0 : _b.call(_a, this.getSlice(start, endIndex - offset));
343
- (_d = (_c = this.cbs).oncommentend) === null || _d === void 0 ? void 0 : _d.call(_c);
344
- // Set `startIndex` for next node
345
- this.startIndex = endIndex + 1;
346
- }
347
- /** @internal */
348
- oncdata(start, endIndex, offset) {
349
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
350
- this.endIndex = endIndex;
351
- const value = this.getSlice(start, endIndex - offset);
352
- if (this.options.xmlMode || this.options.recognizeCDATA) {
353
- (_b = (_a = this.cbs).oncdatastart) === null || _b === void 0 ? void 0 : _b.call(_a);
354
- (_d = (_c = this.cbs).ontext) === null || _d === void 0 ? void 0 : _d.call(_c, value);
355
- (_f = (_e = this.cbs).oncdataend) === null || _f === void 0 ? void 0 : _f.call(_e);
356
- }
357
- else {
358
- (_h = (_g = this.cbs).oncomment) === null || _h === void 0 ? void 0 : _h.call(_g, `[CDATA[${value}]]`);
359
- (_k = (_j = this.cbs).oncommentend) === null || _k === void 0 ? void 0 : _k.call(_j);
360
- }
361
- // Set `startIndex` for next node
362
- this.startIndex = endIndex + 1;
363
- }
364
- /** @internal */
365
- onend() {
366
- var _a, _b;
367
- if (this.cbs.onclosetag) {
368
- // Set the end index for all remaining tags
369
- this.endIndex = this.startIndex;
370
- for (let index = this.stack.length; index > 0; this.cbs.onclosetag(this.stack[--index], true))
371
- ;
372
- }
373
- (_b = (_a = this.cbs).onend) === null || _b === void 0 ? void 0 : _b.call(_a);
374
- }
375
- /**
376
- * Resets the parser to a blank state, ready to parse a new HTML document
377
- */
378
- reset() {
379
- var _a, _b, _c, _d;
380
- (_b = (_a = this.cbs).onreset) === null || _b === void 0 ? void 0 : _b.call(_a);
381
- this.tokenizer.reset();
382
- this.tagname = "";
383
- this.attribname = "";
384
- this.attribs = null;
385
- this.stack.length = 0;
386
- this.startIndex = 0;
387
- this.endIndex = 0;
388
- (_d = (_c = this.cbs).onparserinit) === null || _d === void 0 ? void 0 : _d.call(_c, this);
389
- this.buffers.length = 0;
390
- this.bufferOffset = 0;
391
- this.writeIndex = 0;
392
- this.ended = false;
393
- }
394
- /**
395
- * Resets the parser, then parses a complete document and
396
- * pushes it to the handler.
397
- *
398
- * @param data Document to parse.
399
- */
400
- parseComplete(data) {
401
- this.reset();
402
- this.end(data);
403
- }
404
- getSlice(start, end) {
405
- while (start - this.bufferOffset >= this.buffers[0].length) {
406
- this.shiftBuffer();
407
- }
408
- let slice = this.buffers[0].slice(start - this.bufferOffset, end - this.bufferOffset);
409
- while (end - this.bufferOffset > this.buffers[0].length) {
410
- this.shiftBuffer();
411
- slice += this.buffers[0].slice(0, end - this.bufferOffset);
412
- }
413
- return slice;
414
- }
415
- shiftBuffer() {
416
- this.bufferOffset += this.buffers[0].length;
417
- this.writeIndex--;
418
- this.buffers.shift();
419
- }
420
- /**
421
- * Parses a chunk of data and calls the corresponding callbacks.
422
- *
423
- * @param chunk Chunk to parse.
424
- */
425
- write(chunk) {
426
- var _a, _b;
427
- if (this.ended) {
428
- (_b = (_a = this.cbs).onerror) === null || _b === void 0 ? void 0 : _b.call(_a, new Error(".write() after done!"));
429
- return;
430
- }
431
- this.buffers.push(chunk);
432
- if (this.tokenizer.running) {
433
- this.tokenizer.write(chunk);
434
- this.writeIndex++;
435
- }
436
- }
437
- /**
438
- * Parses the end of the buffer and clears the stack, calls onend.
439
- *
440
- * @param chunk Optional final chunk to parse.
441
- */
442
- end(chunk) {
443
- var _a, _b;
444
- if (this.ended) {
445
- (_b = (_a = this.cbs).onerror) === null || _b === void 0 ? void 0 : _b.call(_a, new Error(".end() after done!"));
446
- return;
447
- }
448
- if (chunk)
449
- this.write(chunk);
450
- this.ended = true;
451
- this.tokenizer.end();
452
- }
453
- /**
454
- * Pauses parsing. The parser won't emit events until `resume` is called.
455
- */
456
- pause() {
457
- this.tokenizer.pause();
458
- }
459
- /**
460
- * Resumes parsing after `pause` was called.
461
- */
462
- resume() {
463
- this.tokenizer.resume();
464
- while (this.tokenizer.running &&
465
- this.writeIndex < this.buffers.length) {
466
- this.tokenizer.write(this.buffers[this.writeIndex++]);
467
- }
468
- if (this.ended)
469
- this.tokenizer.end();
470
- }
471
- /**
472
- * Alias of `write`, for backwards compatibility.
473
- *
474
- * @param chunk Chunk to parse.
475
- * @deprecated
476
- */
477
- parseChunk(chunk) {
478
- this.write(chunk);
479
- }
480
- /**
481
- * Alias of `end`, for backwards compatibility.
482
- *
483
- * @param chunk Optional final chunk to parse.
484
- * @deprecated
485
- */
486
- done(chunk) {
487
- this.end(chunk);
488
- }
489
- }
490
-
491
- export { Parser };