@wabot-dev/framework 0.0.16 → 0.0.50
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/dist/src/_virtual/_commonjsHelpers.js +5 -0
- package/dist/src/_virtual/cjs.js +7 -0
- package/dist/src/ai/deepseek/DeepSeekChatBotAdapter.js +107 -0
- package/dist/src/ai/openia/OpenaiChatBotAdapter.js +9 -7
- package/dist/src/channels/cmd/@cmd.js +0 -4
- package/dist/src/channels/cmd/CmdChannel.js +0 -4
- package/dist/src/channels/express/ExpressProvider.js +46 -0
- package/dist/src/channels/http/HttpServerProvider.js +31 -0
- package/dist/src/channels/socket/@socket.js +20 -0
- package/dist/src/channels/socket/SocketChannel.js +79 -0
- package/dist/src/channels/socket/SocketChannelConfig.js +15 -0
- package/dist/src/channels/socket/SocketServerProvider.js +50 -0
- package/dist/src/channels/telegram/@telegram.js +0 -4
- package/dist/src/channels/telegram/TelegramChannel.js +0 -4
- package/dist/src/channels/wabot/WabotDevConnection.js +57 -0
- package/dist/src/channels/wabot/WabotDevSocketContracts.js +10 -0
- package/dist/src/channels/whatsapp/@whatsapp.js +0 -4
- package/dist/src/channels/whatsapp/EnvWhatsAppRepository.js +49 -0
- package/dist/src/channels/whatsapp/PgWhatsAppRepository.js +41 -0
- package/dist/src/channels/whatsapp/WhatsApp.js +32 -0
- package/dist/src/channels/whatsapp/WhatsAppChannel.js +33 -32
- package/dist/src/channels/whatsapp/{WhatsAppConnection.js → WhatsAppReceiver.js} +4 -6
- package/dist/src/channels/whatsapp/WhatsAppReceiverByDevConnection.js +32 -0
- package/dist/src/channels/whatsapp/WhatsAppReceiverByWebHook.js +63 -0
- package/dist/src/channels/whatsapp/WhatsAppRepository.js +10 -0
- package/dist/src/channels/whatsapp/WhatsAppSender.js +99 -0
- package/dist/src/channels/whatsapp/WhatsAppSenderByCloudApi.js +124 -0
- package/dist/src/channels/whatsapp/WhatsAppSenderByDevConnection.js +61 -0
- package/dist/src/chatbot/ChatBotAdapter.js +1 -5
- package/dist/src/chatbot/metadata/@chatBot.js +0 -5
- package/dist/src/chatbot/metadata/ChatBotMetadataStore.js +0 -5
- package/dist/src/controller/metadata/ControllerMetadataStore.js +0 -2
- package/dist/src/controller/metadata/controller/@chatController.js +0 -2
- package/dist/src/core/IMessageContext.js +0 -2
- package/dist/src/env/WabotEnv.js +6 -0
- package/dist/src/index.d.ts +454 -163
- package/dist/src/index.js +56 -21
- package/dist/src/mindset/MindsetOperator.js +1 -3
- package/dist/src/mindset/metadata/MindsetMetadataStore.js +0 -2
- package/dist/src/mindset/metadata/mindsets/@mindset.js +0 -2
- package/dist/src/mindset/metadata/modules/@mindsetModule.js +0 -2
- package/dist/src/node_modules/@selderee/plugin-htmlparser2/lib/hp2-builder.js +90 -0
- package/dist/src/node_modules/deepmerge/dist/cjs.js +142 -0
- package/dist/src/node_modules/dom-serializer/lib/esm/foreignNames.js +102 -0
- package/dist/src/node_modules/dom-serializer/lib/esm/index.js +186 -0
- package/dist/src/node_modules/domelementtype/lib/esm/index.js +53 -0
- package/dist/src/node_modules/domhandler/lib/esm/index.js +148 -0
- package/dist/src/node_modules/domhandler/lib/esm/node.js +334 -0
- package/dist/src/node_modules/entities/lib/esm/decode.js +458 -0
- package/dist/src/node_modules/entities/lib/esm/decode_codepoint.js +62 -0
- package/dist/src/node_modules/entities/lib/esm/escape.js +99 -0
- package/dist/src/node_modules/entities/lib/esm/generated/decode-data-html.js +8 -0
- package/dist/src/node_modules/entities/lib/esm/generated/decode-data-xml.js +8 -0
- package/dist/src/node_modules/html-to-text/lib/html-to-text.js +2147 -0
- package/dist/src/node_modules/htmlparser2/lib/esm/Parser.js +491 -0
- package/dist/src/node_modules/htmlparser2/lib/esm/Tokenizer.js +928 -0
- package/dist/src/node_modules/htmlparser2/lib/esm/index.js +18 -0
- package/dist/src/node_modules/leac/lib/leac.js +3 -0
- package/dist/src/node_modules/parseley/lib/parseley.js +270 -0
- package/dist/src/node_modules/peberminta/lib/core.js +171 -0
- package/dist/src/node_modules/selderee/lib/selderee.js +380 -0
- package/dist/src/pre-made/module/authentication/requests/SendOneTimePasswordRequest.js +0 -2
- package/dist/src/pre-made/module/authentication/requests/ValidateOneTimePasswordRequest.js +0 -2
- package/dist/src/pre-made/module/html/HtmlModule.js +70 -0
- package/dist/src/pre-made/module/register-user/requests/RegisterUserWithEmailRequest.js +0 -2
- package/dist/src/pre-made/repository/chat/pg/PgChatMemory.js +1 -7
- package/dist/src/pre-made/repository/chat/pg/PgChatRepository.js +0 -5
- package/dist/src/pre-made/repository/user/pg/PgUserRepository.js +0 -5
- package/dist/src/repository/pg/PgCrudRepository.js +0 -1
- package/dist/src/rest-controller/metadata/@get.js +19 -0
- package/dist/src/rest-controller/metadata/@post.js +19 -0
- package/dist/src/rest-controller/metadata/@restController.js +15 -0
- package/dist/src/rest-controller/metadata/RestControllerMetadataStore.js +37 -0
- package/dist/src/rest-controller/runRestControllers.js +74 -0
- package/dist/src/server/prepareChatContainer.js +4 -4
- package/dist/src/server/runChannel.js +2 -10
- package/dist/src/server/runServer.js +0 -43
- package/dist/src/validation/metadata/@isBoolean.js +17 -0
- package/dist/src/validation/metadata/@isDate.js +17 -0
- package/dist/src/validation/metadata/@isNotEmpty.js +17 -0
- package/dist/src/validation/metadata/@isNumber.js +17 -0
- package/dist/src/validation/metadata/@isOptional.js +17 -0
- package/dist/src/validation/metadata/@isPresent.js +17 -0
- package/dist/src/validation/metadata/@isString.js +17 -0
- package/dist/src/validation/metadata/@max.js +18 -0
- package/dist/src/validation/metadata/@min.js +18 -0
- package/dist/src/validation/metadata/@validable.js +14 -0
- package/dist/src/validation/metadata/ValidationMetadataStore.js +55 -0
- package/dist/src/validation/validateModel2.js +11 -0
- package/dist/src/validation/validators/validateIsBoolean.js +12 -0
- package/dist/src/validation/validators/validateIsDate.js +16 -0
- package/dist/src/validation/validators/validateIsNotEmpty.js +12 -0
- package/dist/src/validation/validators/validateIsNumber.js +12 -0
- package/dist/src/validation/validators/validateIsOptional.js +5 -0
- package/dist/src/validation/validators/validateIsPresent.js +12 -0
- package/dist/src/validation/validators/validateIsString.js +12 -0
- package/dist/src/validation/validators/validateMax.js +17 -0
- package/dist/src/validation/validators/validateMin.js +17 -0
- package/dist/src/validation/validators/validateModel.js +47 -0
- package/package.json +4 -6
- package/dist/src/channels/whatsapp/WhatsAppDevConnection.js +0 -61
- package/dist/src/channels/whatsapp/WhatsAppProdConnection.js +0 -36
- package/dist/src/channels/whatsapp/whatsAppDevSocketContracts.js +0 -9
- package/dist/src/controller/express/Express.js +0 -5
- package/dist/src/controller/socket.io/SocketIO.js +0 -5
- package/dist/src/mindset/metadata/params/@isOptional.js +0 -21
- package/dist/src/pre-made/repository/chat/sqlite/SqliteChatMemory.js +0 -23
- package/dist/src/pre-made/repository/chat/sqlite/SqliteChatRepository.js +0 -30
- package/dist/src/pre-made/repository/user/sqlite/SqliteUserRepository.js +0 -23
- package/dist/src/repository/sqlite/SqliteCrudRepository.js +0 -85
- package/dist/src/repository/sqlite/SqlitePersistentMapper.js +0 -17
|
@@ -0,0 +1,491 @@
|
|
|
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 };
|