@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.
- package/dist/src/addon/async/pg/PgJobRepository.js +26 -0
- package/dist/src/addon/auth/api-key/@apiKeyConnectionGuard.js +16 -0
- package/dist/src/addon/auth/api-key/@apiKeyGuard.js +17 -0
- package/dist/src/addon/auth/api-key/ApiKey.js +45 -0
- package/dist/src/addon/auth/api-key/ApiKeyConnectionGuardMiddleware.js +57 -0
- package/dist/src/addon/auth/api-key/ApiKeyGuardMiddleware.js +45 -0
- package/dist/src/addon/auth/api-key/ApiKeyRepository.js +22 -0
- package/dist/src/addon/auth/api-key/PgApiKeyRepository.js +53 -0
- package/dist/src/addon/auth/api-key/RemoteApiKeyRepository.js +62 -0
- package/dist/src/addon/auth/jwt/@jwtConnectionGuard.js +16 -0
- package/dist/src/addon/auth/jwt/@jwtGuard.js +17 -0
- package/dist/src/addon/auth/jwt/Jwt.js +53 -0
- package/dist/src/addon/auth/jwt/JwtAccessAndRefreshTokenDto.js +20 -0
- package/dist/src/addon/auth/jwt/JwtConfig.js +28 -0
- package/dist/src/addon/auth/jwt/JwtConnectionGuardMiddleware.js +57 -0
- package/dist/src/addon/auth/jwt/JwtGuardMiddleware.js +45 -0
- package/dist/src/addon/auth/jwt/JwtRefreshToken.js +56 -0
- package/dist/src/addon/auth/jwt/JwtRefreshTokenRepository.js +25 -0
- package/dist/src/addon/auth/jwt/JwtSigner.js +36 -0
- package/dist/src/addon/auth/jwt/JwtTokenDto.js +22 -0
- package/dist/src/addon/auth/jwt/PgJwtRefreshTokenRepository.js +21 -0
- package/dist/src/addon/chat-bot/anthropic/AnthropicChatAdapter.js +135 -0
- package/dist/src/addon/chat-bot/deepseek/DeepSeekChatAdapter.js +137 -0
- package/dist/src/addon/chat-bot/google/GoogleChatAdapter.js +128 -0
- package/dist/src/addon/chat-bot/openia/OpenaiChatAdapter.js +117 -0
- package/dist/src/{pre-made/repository/chat → addon/chat-bot}/pg/PgChatMemory.js +6 -4
- package/dist/src/{pre-made/repository/chat → addon/chat-bot}/pg/PgChatRepository.js +6 -5
- package/dist/src/{pre-made/repository/chat → addon/chat-bot}/ram/RamChatRepository.js +2 -2
- package/dist/src/addon/chat-bot/wabot/WabotChatAdapter.js +41 -0
- package/dist/src/addon/chat-controller/cmd/@cmd.js +24 -0
- package/dist/src/addon/chat-controller/cmd/CmdChannel.js +91 -0
- package/dist/src/{channels → addon/chat-controller}/socket/@socket.js +10 -4
- package/dist/src/{channels → addon/chat-controller}/socket/SocketChannel.js +9 -23
- package/dist/src/{channels → addon/chat-controller}/socket/SocketChannelConfig.js +1 -1
- package/dist/src/{channels → addon/chat-controller}/telegram/@telegram.js +10 -4
- package/dist/src/{channels → addon/chat-controller}/telegram/TelegramChannel.js +4 -22
- package/dist/src/addon/chat-controller/whatsapp/@whatsApp.js +26 -0
- package/dist/src/{channels → addon/chat-controller}/whatsapp/EnvWhatsAppRepository.js +3 -3
- package/dist/src/{channels → addon/chat-controller}/whatsapp/PgWhatsAppRepository.js +2 -2
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsApp.js +2 -4
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppChannel.js +6 -18
- package/dist/src/addon/chat-controller/whatsapp/WhatsAppReceiver.js +10 -0
- package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppSender.js +15 -39
- package/dist/src/addon/chat-controller/whatsapp/cloud-api/WhatsAppReceiverByCloudApi.js +97 -0
- package/dist/src/{channels/whatsapp → addon/chat-controller/whatsapp/cloud-api}/WhatsAppSenderByCloudApi.js +27 -20
- package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppProxyContracts.js +5 -0
- package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppReceiverByWabotProxy.js +65 -0
- package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppSenderByWabotProxy.js +61 -0
- package/dist/src/addon/chat-controller/whatsapp/proxy/WhatsAppWabotProxyConnection.js +45 -0
- package/dist/src/{pre-made/module → addon/mindset}/html/HtmlModule.js +7 -7
- package/dist/src/core/auth/Auth.js +33 -0
- package/dist/src/core/{Persistent.js → entity/Entity.js} +24 -12
- package/dist/src/core/env/Env.js +39 -0
- package/dist/src/core/error/CustomError.js +15 -0
- package/dist/src/core/injection/index.js +4 -0
- package/dist/src/core/mapper/Mapper.js +42 -0
- package/dist/src/core/password/Password.js +30 -0
- package/dist/src/core/random/Random.js +65 -0
- package/dist/src/core/storable/Storable.js +8 -0
- package/dist/src/core/validation/core/validateArray.js +51 -0
- package/dist/src/core/validation/core/validateModel.js +36 -0
- package/dist/src/{validation/metadata/@isNumber.js → core/validation/metadata/@isArray.js} +5 -4
- package/dist/src/{validation/metadata/@isDate.js → core/validation/metadata/@isModel.js} +5 -4
- package/dist/src/{validation → core/validation}/metadata/@isOptional.js +1 -1
- package/dist/src/core/validation/metadata/ValidationMetadataStore.js +98 -0
- package/dist/src/core/validation/modelInfo.js +9 -0
- package/dist/src/{validation/validateModel2.js → core/validation/validate.js} +3 -3
- package/dist/src/{validation/metadata → core/validation/validators/is-boolean}/@isBoolean.js +3 -3
- package/dist/src/core/validation/validators/is-date/@isDate.js +17 -0
- package/dist/src/core/validation/validators/is-in/@isIn.js +18 -0
- package/dist/src/core/validation/validators/is-in/validateIsIn.js +12 -0
- package/dist/src/{validation/metadata → core/validation/validators/is-not-empty}/@isNotEmpty.js +3 -3
- package/dist/src/core/validation/validators/is-number/@isNumber.js +17 -0
- package/dist/src/{validation/metadata → core/validation/validators/is-present}/@isPresent.js +3 -3
- package/dist/src/{validation/metadata → core/validation/validators/is-string}/@isString.js +3 -3
- package/dist/src/{validation/metadata → core/validation/validators/max}/@max.js +3 -3
- package/dist/src/{validation/metadata → core/validation/validators/min}/@min.js +3 -3
- package/dist/src/feature/async/@command.js +11 -0
- package/dist/src/feature/async/@commandHandler.js +12 -0
- package/dist/src/feature/async/Async.js +38 -0
- package/dist/src/feature/async/Command.js +9 -0
- package/dist/src/feature/async/CommandMetadataStore.js +38 -0
- package/dist/src/feature/async/Job.js +27 -0
- package/dist/src/feature/async/JobRepository.js +31 -0
- package/dist/src/feature/async/JobRunner.js +48 -0
- package/dist/src/feature/async/JobsEventsHub.js +36 -0
- package/dist/src/feature/async/runCommandHandlers.js +29 -0
- package/dist/src/{core/chat → feature/chat-bot}/Chat.js +2 -2
- package/dist/src/feature/chat-bot/ChatAdapter.js +7 -0
- package/dist/src/feature/chat-bot/ChatBot.js +73 -0
- package/dist/src/feature/chat-bot/ChatItem.js +24 -0
- package/dist/src/feature/chat-bot/ChatMemory.js +10 -0
- package/dist/src/{core/chat/repository/IChatRepository.js → feature/chat-bot/ChatRepository.js} +2 -8
- package/dist/src/feature/chat-bot/IChatItem.js +3 -0
- package/dist/src/{chatbot → feature/chat-bot}/metadata/@chatBot.js +1 -1
- package/dist/src/{chatbot → feature/chat-bot}/metadata/ChatBotMetadataStore.js +1 -1
- package/dist/src/{controller/channel → feature/chat-controller}/ChatResolver.js +6 -4
- package/dist/src/{controller → feature/chat-controller}/metadata/ControllerMetadataStore.js +1 -1
- package/dist/src/{controller → feature/chat-controller}/metadata/controller/@chatController.js +1 -1
- package/dist/src/feature/chat-controller/runChatControllers.js +83 -0
- package/dist/src/{channels → feature}/express/ExpressProvider.js +2 -4
- package/dist/src/{channels → feature}/http/HttpServerProvider.js +2 -2
- package/dist/src/{mindset → feature/mindset}/IMindset.js +6 -0
- package/dist/src/feature/mindset/MindsetOperator.js +180 -0
- package/dist/src/{mindset → feature/mindset}/metadata/MindsetMetadataStore.js +1 -1
- package/dist/src/{mindset → feature/mindset}/metadata/functions/@mindsetFunction.js +1 -1
- package/dist/src/{mindset → feature/mindset}/metadata/mindsets/@mindset.js +1 -1
- package/dist/src/{mindset → feature/mindset}/metadata/modules/@mindsetModule.js +1 -2
- package/dist/src/{mindset → feature/mindset}/metadata/params/@param.js +1 -1
- package/dist/src/feature/money/Money.js +61 -0
- package/dist/src/feature/money/MoneyDto.js +22 -0
- package/dist/src/{repository → feature}/pg/PgCrudRepository.js +24 -10
- package/dist/src/{repository → feature}/pg/PgRepositoryBase.js +2 -2
- package/dist/src/feature/rest-controller/injection-tokens.js +4 -0
- package/dist/src/{rest-controller/metadata/@post.js → feature/rest-controller/metadata/@middleware.js} +5 -8
- package/dist/src/feature/rest-controller/metadata/@onDelete.js +7 -0
- package/dist/src/feature/rest-controller/metadata/@onGet.js +7 -0
- package/dist/src/feature/rest-controller/metadata/@onPost.js +7 -0
- package/dist/src/feature/rest-controller/metadata/@onPut.js +7 -0
- package/dist/src/{rest-controller → feature/rest-controller}/metadata/@restController.js +2 -2
- package/dist/src/{rest-controller → feature/rest-controller}/metadata/RestControllerMetadataStore.js +14 -1
- package/dist/src/{rest-controller/metadata/@get.js → feature/rest-controller/metadata/methodDecorator.js} +5 -5
- package/dist/src/feature/rest-controller/runRestControllers.js +103 -0
- package/dist/src/{channels → feature}/socket/SocketServerProvider.js +2 -2
- package/dist/src/feature/socket-controller/metadata/@connectionMiddleware.js +16 -0
- package/dist/src/feature/socket-controller/metadata/@socketConnection.js +18 -0
- package/dist/src/feature/socket-controller/metadata/@socketController.js +15 -0
- package/dist/src/feature/socket-controller/metadata/@socketEvent.js +18 -0
- package/dist/src/feature/socket-controller/metadata/SocketControllerMetadataStore.js +65 -0
- package/dist/src/feature/socket-controller/runSocketControllers.js +99 -0
- package/dist/src/index.d.ts +1219 -718
- package/dist/src/index.js +147 -102
- package/package.json +8 -2
- package/dist/src/_virtual/_commonjsHelpers.js +0 -5
- package/dist/src/_virtual/cjs.js +0 -7
- package/dist/src/ai/deepseek/DeepSeekChatBotAdapter.js +0 -107
- package/dist/src/ai/openia/OpenaiChatBotAdapter.js +0 -88
- package/dist/src/channels/cmd/@cmd.js +0 -18
- package/dist/src/channels/cmd/CmdChannel.js +0 -73
- package/dist/src/channels/wabot/WabotDevConnection.js +0 -57
- package/dist/src/channels/wabot/WabotDevSocketContracts.js +0 -10
- package/dist/src/channels/whatsapp/@whatsapp.js +0 -20
- package/dist/src/channels/whatsapp/WhatsAppReceiver.js +0 -59
- package/dist/src/channels/whatsapp/WhatsAppReceiverByDevConnection.js +0 -32
- package/dist/src/channels/whatsapp/WhatsAppReceiverByWebHook.js +0 -63
- package/dist/src/channels/whatsapp/WhatsAppSenderByDevConnection.js +0 -61
- package/dist/src/chatbot/ChatBot.js +0 -51
- package/dist/src/chatbot/ChatBotAdapter.js +0 -72
- package/dist/src/controller/channel/UserResolver.js +0 -21
- package/dist/src/core/IMessageContext.js +0 -12
- package/dist/src/core/chat/ChatItem.js +0 -15
- package/dist/src/core/chat/repository/IChatMemory.js +0 -10
- package/dist/src/core/user/IUserRepository.js +0 -19
- package/dist/src/core/user/User.js +0 -26
- package/dist/src/env/WabotEnv.js +0 -27
- package/dist/src/injection/index.js +0 -4
- package/dist/src/mindset/MindsetOperator.js +0 -101
- package/dist/src/node_modules/@selderee/plugin-htmlparser2/lib/hp2-builder.js +0 -90
- package/dist/src/node_modules/deepmerge/dist/cjs.js +0 -142
- package/dist/src/node_modules/dom-serializer/lib/esm/foreignNames.js +0 -102
- package/dist/src/node_modules/dom-serializer/lib/esm/index.js +0 -186
- package/dist/src/node_modules/domelementtype/lib/esm/index.js +0 -53
- package/dist/src/node_modules/domhandler/lib/esm/index.js +0 -148
- package/dist/src/node_modules/domhandler/lib/esm/node.js +0 -334
- package/dist/src/node_modules/entities/lib/esm/decode.js +0 -458
- package/dist/src/node_modules/entities/lib/esm/decode_codepoint.js +0 -62
- package/dist/src/node_modules/entities/lib/esm/escape.js +0 -99
- package/dist/src/node_modules/entities/lib/esm/generated/decode-data-html.js +0 -8
- package/dist/src/node_modules/entities/lib/esm/generated/decode-data-xml.js +0 -8
- package/dist/src/node_modules/html-to-text/lib/html-to-text.js +0 -2147
- package/dist/src/node_modules/htmlparser2/lib/esm/Parser.js +0 -491
- package/dist/src/node_modules/htmlparser2/lib/esm/Tokenizer.js +0 -928
- package/dist/src/node_modules/htmlparser2/lib/esm/index.js +0 -18
- package/dist/src/node_modules/leac/lib/leac.js +0 -3
- package/dist/src/node_modules/parseley/lib/parseley.js +0 -270
- package/dist/src/node_modules/peberminta/lib/core.js +0 -171
- package/dist/src/node_modules/selderee/lib/selderee.js +0 -380
- package/dist/src/pre-made/module/authentication/AuthenticationModule.js +0 -97
- package/dist/src/pre-made/module/authentication/requests/SendOneTimePasswordRequest.js +0 -25
- package/dist/src/pre-made/module/authentication/requests/ValidateOneTimePasswordRequest.js +0 -25
- package/dist/src/pre-made/module/register-user/RegisterUserModule.js +0 -56
- package/dist/src/pre-made/module/register-user/requests/RegisterUserWithEmailRequest.js +0 -25
- package/dist/src/pre-made/repository/user/pg/PgUserRepository.js +0 -33
- package/dist/src/pre-made/repository/user/ram/RamUserRepository.js +0 -27
- package/dist/src/pre-made/service/EmailService.js +0 -13
- package/dist/src/pre-made/service/OtpService.js +0 -14
- package/dist/src/rest-controller/runRestControllers.js +0 -74
- package/dist/src/server/prepareChatContainer.js +0 -43
- package/dist/src/server/runChannel.js +0 -27
- package/dist/src/server/runServer.js +0 -40
- package/dist/src/validation/metadata/@validable.js +0 -14
- package/dist/src/validation/metadata/ValidationMetadataStore.js +0 -55
- package/dist/src/validation/validators/validateModel.js +0 -47
- /package/dist/src/{pre-made/repository/chat → addon/chat-bot}/ram/RamChatMemory.js +0 -0
- /package/dist/src/{channels → addon/chat-controller}/telegram/TelegramChannelConfig.js +0 -0
- /package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppChannelConfig.js +0 -0
- /package/dist/src/{channels → addon/chat-controller}/whatsapp/WhatsAppRepository.js +0 -0
- /package/dist/src/{injection → core/injection}/Container.js +0 -0
- /package/dist/src/{logger → core/logger}/Logger.js +0 -0
- /package/dist/src/{validation/validators → core/validation/core}/validateIsOptional.js +0 -0
- /package/dist/src/{validation/validators → core/validation/validators/is-boolean}/validateIsBoolean.js +0 -0
- /package/dist/src/{validation/validators → core/validation/validators/is-date}/validateIsDate.js +0 -0
- /package/dist/src/{validation/validators → core/validation/validators/is-not-empty}/validateIsNotEmpty.js +0 -0
- /package/dist/src/{validation/validators → core/validation/validators/is-number}/validateIsNumber.js +0 -0
- /package/dist/src/{validation/validators → core/validation/validators/is-present}/validateIsPresent.js +0 -0
- /package/dist/src/{validation/validators → core/validation/validators/is-string}/validateIsString.js +0 -0
- /package/dist/src/{validation/validators → core/validation/validators/max}/validateMax.js +0 -0
- /package/dist/src/{validation/validators → core/validation/validators/min}/validateMin.js +0 -0
- /package/dist/src/{mindset → feature/mindset}/metadata/functions/decoratorNames.js +0 -0
- /package/dist/src/{mindset → feature/mindset}/metadata/mindsets/decoratorNames.js +0 -0
- /package/dist/src/{mindset → feature/mindset}/metadata/modules/decoratorNames.js +0 -0
- /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 };
|