@wabot-dev/framework 0.1.0-beta.7 → 0.1.0-beta.9

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 (32) hide show
  1. package/dist/src/_virtual/_commonjsHelpers.js +5 -0
  2. package/dist/src/_virtual/cjs.js +7 -0
  3. package/dist/src/index.d.ts +17 -5
  4. package/dist/src/index.js +3 -1
  5. package/dist/src/node_modules/@selderee/plugin-htmlparser2/lib/hp2-builder.js +90 -0
  6. package/dist/src/node_modules/deepmerge/dist/cjs.js +142 -0
  7. package/dist/src/node_modules/dom-serializer/lib/esm/foreignNames.js +102 -0
  8. package/dist/src/node_modules/dom-serializer/lib/esm/index.js +186 -0
  9. package/dist/src/node_modules/domelementtype/lib/esm/index.js +53 -0
  10. package/dist/src/node_modules/domhandler/lib/esm/index.js +148 -0
  11. package/dist/src/node_modules/domhandler/lib/esm/node.js +334 -0
  12. package/dist/src/node_modules/entities/lib/esm/decode.js +458 -0
  13. package/dist/src/node_modules/entities/lib/esm/decode_codepoint.js +62 -0
  14. package/dist/src/node_modules/entities/lib/esm/escape.js +99 -0
  15. package/dist/src/node_modules/entities/lib/esm/generated/decode-data-html.js +8 -0
  16. package/dist/src/node_modules/entities/lib/esm/generated/decode-data-xml.js +8 -0
  17. package/dist/src/node_modules/html-to-text/lib/html-to-text.js +2147 -0
  18. package/dist/src/node_modules/htmlparser2/lib/esm/Parser.js +491 -0
  19. package/dist/src/node_modules/htmlparser2/lib/esm/Tokenizer.js +928 -0
  20. package/dist/src/node_modules/htmlparser2/lib/esm/index.js +18 -0
  21. package/dist/src/node_modules/leac/lib/leac.js +3 -0
  22. package/dist/src/node_modules/parseley/lib/parseley.js +270 -0
  23. package/dist/src/node_modules/peberminta/lib/core.js +171 -0
  24. package/dist/src/node_modules/selderee/lib/selderee.js +380 -0
  25. package/dist/src/pre-made/module/html/HtmlModule.js +70 -0
  26. package/dist/src/repository/pg/PgCrudRepository.js +7 -0
  27. package/dist/src/rest-controller/metadata/@post.js +19 -0
  28. package/dist/src/rest-controller/runRestControllers.js +0 -1
  29. package/dist/src/validation/metadata/@isOptional.js +2 -4
  30. package/dist/src/validation/metadata/ValidationMetadataStore.js +1 -1
  31. package/dist/src/validation/validators/validateIsOptional.js +5 -0
  32. package/package.json +3 -1
@@ -0,0 +1,5 @@
1
+ function getDefaultExportFromCjs (x) {
2
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
3
+ }
4
+
5
+ export { getDefaultExportFromCjs };
@@ -0,0 +1,7 @@
1
+ import { getDefaultExportFromCjs } from './_commonjsHelpers.js';
2
+ import { __require as requireCjs } from '../node_modules/deepmerge/dist/cjs.js';
3
+
4
+ var cjsExports = requireCjs();
5
+ var merge = /*@__PURE__*/getDefaultExportFromCjs(cjsExports);
6
+
7
+ export { merge as default };
@@ -775,6 +775,7 @@ declare class WhatsAppSenderByCloudApi extends WhatsAppSender {
775
775
 
776
776
  interface ICrudRepository<T> {
777
777
  find(id: string): Promise<T | null>;
778
+ findOrThrow(id: string): Promise<T>;
778
779
  findAll(id: string): Promise<T[]>;
779
780
  create(item: T): Promise<void>;
780
781
  update(item: T): Promise<void>;
@@ -825,6 +826,7 @@ declare class PgCrudRepository<P extends Persistent> extends PgRepositoryBase<P>
825
826
  protected readonly config: IPgRepositoryConfig<P>;
826
827
  constructor(pool: Pool, config: IPgRepositoryConfig<P>);
827
828
  find(id: string): Promise<P | null>;
829
+ findOrThrow(id: string): Promise<P>;
828
830
  findAll(): Promise<P[]>;
829
831
  create(item: P): Promise<void>;
830
832
  update(item: P): Promise<void>;
@@ -930,6 +932,14 @@ declare class RegisterUserModule {
930
932
  registerUserWithEmail(request: RegisterUserWithEmailRequest): Promise<string>;
931
933
  }
932
934
 
935
+ interface IHtmlModuleOptions {
936
+ url: string;
937
+ title: string;
938
+ }
939
+ declare function HtmlModule(options: IHtmlModuleOptions): {
940
+ new (): {};
941
+ };
942
+
933
943
  declare class PgUserRepository extends PgCrudRepository<User> implements IUserRepository {
934
944
  constructor(pool: Pool);
935
945
  findByConnection(query: IUserConnection): Promise<User | null>;
@@ -976,6 +986,12 @@ interface IGetConfig {
976
986
 
977
987
  declare function get(config?: IGetConfig): (target: object, propertyKey: string | symbol) => void;
978
988
 
989
+ interface IPostConfig {
990
+ path?: string;
991
+ }
992
+
993
+ declare function post(config?: IPostConfig): (target: object, propertyKey: string | symbol) => void;
994
+
979
995
  interface IRestControllerConfig {
980
996
  path: string;
981
997
  }
@@ -1020,10 +1036,6 @@ declare function isNotEmpty(): (target: object, propertyKey: string | symbol) =>
1020
1036
 
1021
1037
  declare function isNumber(): (target: object, propertyKey: string | symbol) => void;
1022
1038
 
1023
- declare const _IS_OPTIONAL_DUMMY_VALIDATOR_: (value: any) => {
1024
- value: any;
1025
- errors: never[];
1026
- };
1027
1039
  declare function isOptional(): (target: object, propertyKey: string | symbol) => void;
1028
1040
 
1029
1041
  declare function isPresent(): (target: object, propertyKey: string | symbol) => void;
@@ -1109,4 +1121,4 @@ declare function validateModel<V>(value: any, info: IModelValidatorsInfo<V>): IM
1109
1121
 
1110
1122
  declare function validateModel2<V>(value: any, modelConstructor: IConstructor<V>): IModelValidationResult<V>;
1111
1123
 
1112
- export { AuthenticationModule, Chat, ChatBot, ChatBotAdapter, ChatBotMetadataStore, ChatItem, ChatMemory, ChatRepository, ChatResolver, CmdChannel, Container, ControllerMetadataStore, DeepSeekChatBotAdapter, EmailService, EnvWhatsAppRepository, ExpressProvider, HttpServerProvider, type IChannelMetadata, type IChatBot, type IChatBotAdapter, type IChatBotMetadata, type IChatChannel, type IChatConnection, type IChatControllerMetadata, type IChatData, type IChatFunctionCall, type IChatItemData, type IChatItemType, type IChatMemory, type IChatMessage, type IChatRepository, type IChatType, type IConnectionChatMessage, type IConstructor, type ICrudRepository, type IEmailService, type IEndPointMetadata, type IGetConfig, type IGetWhatsAppTemplateRequest, type IListenWhatsAppMessageRequest, type IMessageContext, type IMessageMetadata, type IMindset, type IMindsetDecoration, type IMindsetFunctionConfig, type IMindsetFunctionDecoration, type IMindsetFunctionMetadata, type IMindsetFunctionParamMetadata, type IMindsetIdentity, type IMindsetMetadata, type IMindsetModuleConfig, type IMindsetModuleDecoration, type IMindsetModuleMetadata, type IModelValidationError, type IModelValidationResult, type IModelValidatorsInfo, type IOtpService, type IParamConfig, type IParamDecoration, type IPersistentData, type IPgRepositoryConfig, type IPropertyValidatorInfo, type IReceivedMessage, type IReceivedMessageItem, type IRestControllerConfig, type IRestControllerMetadata, type IReversibleMapper, type ISendEmailRequest, type ISendWhatsAppRequest, type ISendWhatsAppTemplateRequest, type IServerConfig, type IServerProvider, type ISocketChannelConfig, type ISocketChannelReceivedMessage, type ISystemFunctionCallItem, type ISystemMessageItem, type ITelegramChannelConfig, type IUserConnection, type IUserData, type IUserRepository, type IValidateMaxOptions, type IValidateMinOptions, type IValidationError, type IValidationResult, type IValidator, type IValidatorMetadata, type IWabotEnvType, type IWhatsAppBusinessAccount, type IWhatsAppBusinessNumber, type IWhatsAppContact, type IWhatsAppData, type IWhatsAppMessage, type IWhatsAppMessageListener, type IWhatsAppRepository, type IWhatsAppSenderOptions, type IWhatsAppTemplateMessage, type IWhatsAppTemplateParameter, type IWhatsAppWebhookPayload, type IWhatsappChannelConfig, type IchatControllerConfig, type IrunChannelProps, Logger, MINDSET_DECORATION_MINDSET, MINDSET_FUNCTION_DECORATION_FUNCTION, MINDSET_MODULE_DECORATION_MODULE, MessageContext, Mindset, MindsetMetadataStore, MindsetOperator, OpenaiChatBotAdapter, OtpService, PARAM_DECORATION_IS_OPTIONAL, PARAM_DECORATION_PARAM, Persistent, PgChatMemory, PgChatRepository, PgCrudRepository, PgRepositoryBase, PgUserRepository, PgWhatsAppRepository, RamChatMemory, RamChatRepository, RamUserRepository, RegisterUserModule, RegisterUserWithEmailRequest, RestControllerMetadataStore, SendOneTimePasswordRequest, SocketChannel, SocketChannelConfig, SocketServerProvider, TelegramChannel, TelegramChannelConfig, User, UserRepository, UserResolver, ValidateOneTimePasswordRequest, ValidationMetadataStore, WabotEnv, WhatsApp, WhatsAppChannel, WhatsAppReceiver, WhatsAppReceiverByDevConnection, WhatsAppReceiverByWebHook, WhatsAppRepository, WhatsAppSender, WhatsAppSenderByCloudApi, WhatsAppSenderByDevConnection, WhatsappChannelConfig, _IS_OPTIONAL_DUMMY_VALIDATOR_, chatBot, chatController, cmd, container, get, inject, injectable, isBoolean, isDate, isNotEmpty, isNumber, isOptional, isPresent, isString, max, min, mindset, mindsetFunction, mindsetModule, param, prepareChatContainer, restController, runChannel, runRestControllers, runServer, singleton, socket, telegram, validable, validateIsBoolean, validateIsDate, validateIsNotEmpty, validateIsNumber, validateIsPresent, validateIsString, validateMax, validateMin, validateModel, validateModel2, whatsapp };
1124
+ export { AuthenticationModule, Chat, ChatBot, ChatBotAdapter, ChatBotMetadataStore, ChatItem, ChatMemory, ChatRepository, ChatResolver, CmdChannel, Container, ControllerMetadataStore, DeepSeekChatBotAdapter, EmailService, EnvWhatsAppRepository, ExpressProvider, HtmlModule, HttpServerProvider, type IChannelMetadata, type IChatBot, type IChatBotAdapter, type IChatBotMetadata, type IChatChannel, type IChatConnection, type IChatControllerMetadata, type IChatData, type IChatFunctionCall, type IChatItemData, type IChatItemType, type IChatMemory, type IChatMessage, type IChatRepository, type IChatType, type IConnectionChatMessage, type IConstructor, type ICrudRepository, type IEmailService, type IEndPointMetadata, type IGetConfig, type IGetWhatsAppTemplateRequest, type IHtmlModuleOptions, type IListenWhatsAppMessageRequest, type IMessageContext, type IMessageMetadata, type IMindset, type IMindsetDecoration, type IMindsetFunctionConfig, type IMindsetFunctionDecoration, type IMindsetFunctionMetadata, type IMindsetFunctionParamMetadata, type IMindsetIdentity, type IMindsetMetadata, type IMindsetModuleConfig, type IMindsetModuleDecoration, type IMindsetModuleMetadata, type IModelValidationError, type IModelValidationResult, type IModelValidatorsInfo, type IOtpService, type IParamConfig, type IParamDecoration, type IPersistentData, type IPgRepositoryConfig, type IPostConfig, type IPropertyValidatorInfo, type IReceivedMessage, type IReceivedMessageItem, type IRestControllerConfig, type IRestControllerMetadata, type IReversibleMapper, type ISendEmailRequest, type ISendWhatsAppRequest, type ISendWhatsAppTemplateRequest, type IServerConfig, type IServerProvider, type ISocketChannelConfig, type ISocketChannelReceivedMessage, type ISystemFunctionCallItem, type ISystemMessageItem, type ITelegramChannelConfig, type IUserConnection, type IUserData, type IUserRepository, type IValidateMaxOptions, type IValidateMinOptions, type IValidationError, type IValidationResult, type IValidator, type IValidatorMetadata, type IWabotEnvType, type IWhatsAppBusinessAccount, type IWhatsAppBusinessNumber, type IWhatsAppContact, type IWhatsAppData, type IWhatsAppMessage, type IWhatsAppMessageListener, type IWhatsAppRepository, type IWhatsAppSenderOptions, type IWhatsAppTemplateMessage, type IWhatsAppTemplateParameter, type IWhatsAppWebhookPayload, type IWhatsappChannelConfig, type IchatControllerConfig, type IrunChannelProps, Logger, MINDSET_DECORATION_MINDSET, MINDSET_FUNCTION_DECORATION_FUNCTION, MINDSET_MODULE_DECORATION_MODULE, MessageContext, Mindset, MindsetMetadataStore, MindsetOperator, OpenaiChatBotAdapter, OtpService, PARAM_DECORATION_IS_OPTIONAL, PARAM_DECORATION_PARAM, Persistent, PgChatMemory, PgChatRepository, PgCrudRepository, PgRepositoryBase, PgUserRepository, PgWhatsAppRepository, RamChatMemory, RamChatRepository, RamUserRepository, RegisterUserModule, RegisterUserWithEmailRequest, RestControllerMetadataStore, SendOneTimePasswordRequest, SocketChannel, SocketChannelConfig, SocketServerProvider, TelegramChannel, TelegramChannelConfig, User, UserRepository, UserResolver, ValidateOneTimePasswordRequest, ValidationMetadataStore, WabotEnv, WhatsApp, WhatsAppChannel, WhatsAppReceiver, WhatsAppReceiverByDevConnection, WhatsAppReceiverByWebHook, WhatsAppRepository, WhatsAppSender, WhatsAppSenderByCloudApi, WhatsAppSenderByDevConnection, WhatsappChannelConfig, chatBot, chatController, cmd, container, get, inject, injectable, isBoolean, isDate, isNotEmpty, isNumber, isOptional, isPresent, isString, max, min, mindset, mindsetFunction, mindsetModule, param, post, prepareChatContainer, restController, runChannel, runRestControllers, runServer, singleton, socket, telegram, validable, validateIsBoolean, validateIsDate, validateIsNotEmpty, validateIsNumber, validateIsPresent, validateIsString, validateMax, validateMin, validateModel, validateModel2, whatsapp };
package/dist/src/index.js CHANGED
@@ -60,6 +60,7 @@ export { ValidateOneTimePasswordRequest } from './pre-made/module/authentication
60
60
  export { AuthenticationModule } from './pre-made/module/authentication/AuthenticationModule.js';
61
61
  export { RegisterUserWithEmailRequest } from './pre-made/module/register-user/requests/RegisterUserWithEmailRequest.js';
62
62
  export { RegisterUserModule } from './pre-made/module/register-user/RegisterUserModule.js';
63
+ export { HtmlModule } from './pre-made/module/html/HtmlModule.js';
63
64
  export { EmailService } from './pre-made/service/EmailService.js';
64
65
  export { OtpService } from './pre-made/service/OtpService.js';
65
66
  export { PgUserRepository } from './pre-made/repository/user/pg/PgUserRepository.js';
@@ -73,6 +74,7 @@ export { PgRepositoryBase } from './repository/pg/PgRepositoryBase.js';
73
74
  export { Logger } from './logger/Logger.js';
74
75
  export { WabotEnv } from './env/WabotEnv.js';
75
76
  export { get } from './rest-controller/metadata/@get.js';
77
+ export { post } from './rest-controller/metadata/@post.js';
76
78
  export { restController } from './rest-controller/metadata/@restController.js';
77
79
  export { RestControllerMetadataStore } from './rest-controller/metadata/RestControllerMetadataStore.js';
78
80
  export { runRestControllers } from './rest-controller/runRestControllers.js';
@@ -80,7 +82,7 @@ export { isBoolean } from './validation/metadata/@isBoolean.js';
80
82
  export { isDate } from './validation/metadata/@isDate.js';
81
83
  export { isNotEmpty } from './validation/metadata/@isNotEmpty.js';
82
84
  export { isNumber } from './validation/metadata/@isNumber.js';
83
- export { _IS_OPTIONAL_DUMMY_VALIDATOR_, isOptional } from './validation/metadata/@isOptional.js';
85
+ export { isOptional } from './validation/metadata/@isOptional.js';
84
86
  export { isPresent } from './validation/metadata/@isPresent.js';
85
87
  export { isString } from './validation/metadata/@isString.js';
86
88
  export { max } from './validation/metadata/@max.js';
@@ -0,0 +1,90 @@
1
+ import { Picker } from '../../../selderee/lib/selderee.js';
2
+ import { isTag } from '../../../domhandler/lib/esm/node.js';
3
+
4
+ function hp2Builder(nodes) {
5
+ return new Picker(handleArray(nodes));
6
+ }
7
+ function handleArray(nodes) {
8
+ const matchers = nodes.map(handleNode);
9
+ return (el, ...tail) => matchers.flatMap(m => m(el, ...tail));
10
+ }
11
+ function handleNode(node) {
12
+ switch (node.type) {
13
+ case 'terminal': {
14
+ const result = [node.valueContainer];
15
+ return (el, ...tail) => result;
16
+ }
17
+ case 'tagName':
18
+ return handleTagName(node);
19
+ case 'attrValue':
20
+ return handleAttrValueName(node);
21
+ case 'attrPresence':
22
+ return handleAttrPresenceName(node);
23
+ case 'pushElement':
24
+ return handlePushElementNode(node);
25
+ case 'popElement':
26
+ return handlePopElementNode(node);
27
+ }
28
+ }
29
+ function handleTagName(node) {
30
+ const variants = {};
31
+ for (const variant of node.variants) {
32
+ variants[variant.value] = handleArray(variant.cont);
33
+ }
34
+ return (el, ...tail) => {
35
+ const continuation = variants[el.name];
36
+ return (continuation) ? continuation(el, ...tail) : [];
37
+ };
38
+ }
39
+ function handleAttrPresenceName(node) {
40
+ const attrName = node.name;
41
+ const continuation = handleArray(node.cont);
42
+ return (el, ...tail) => (Object.prototype.hasOwnProperty.call(el.attribs, attrName))
43
+ ? continuation(el, ...tail)
44
+ : [];
45
+ }
46
+ function handleAttrValueName(node) {
47
+ const callbacks = [];
48
+ for (const matcher of node.matchers) {
49
+ const predicate = matcher.predicate;
50
+ const continuation = handleArray(matcher.cont);
51
+ callbacks.push((attr, el, ...tail) => (predicate(attr) ? continuation(el, ...tail) : []));
52
+ }
53
+ const attrName = node.name;
54
+ return (el, ...tail) => {
55
+ const attr = el.attribs[attrName];
56
+ return (attr || attr === '')
57
+ ? callbacks.flatMap(cb => cb(attr, el, ...tail))
58
+ : [];
59
+ };
60
+ }
61
+ function handlePushElementNode(node) {
62
+ const continuation = handleArray(node.cont);
63
+ const leftElementGetter = (node.combinator === '+')
64
+ ? getPrecedingElement
65
+ : getParentElement;
66
+ return (el, ...tail) => {
67
+ const next = leftElementGetter(el);
68
+ if (next === null) {
69
+ return [];
70
+ }
71
+ return continuation(next, el, ...tail);
72
+ };
73
+ }
74
+ const getPrecedingElement = (el) => {
75
+ const prev = el.prev;
76
+ if (prev === null) {
77
+ return null;
78
+ }
79
+ return (isTag(prev)) ? prev : getPrecedingElement(prev);
80
+ };
81
+ const getParentElement = (el) => {
82
+ const parent = el.parent;
83
+ return (parent && isTag(parent)) ? parent : null;
84
+ };
85
+ function handlePopElementNode(node) {
86
+ const continuation = handleArray(node.cont);
87
+ return (el, next, ...tail) => continuation(next, ...tail);
88
+ }
89
+
90
+ export { hp2Builder };
@@ -0,0 +1,142 @@
1
+ var cjs;
2
+ var hasRequiredCjs;
3
+
4
+ function requireCjs () {
5
+ if (hasRequiredCjs) return cjs;
6
+ hasRequiredCjs = 1;
7
+
8
+ var isMergeableObject = function isMergeableObject(value) {
9
+ return isNonNullObject(value)
10
+ && !isSpecial(value)
11
+ };
12
+
13
+ function isNonNullObject(value) {
14
+ return !!value && typeof value === 'object'
15
+ }
16
+
17
+ function isSpecial(value) {
18
+ var stringValue = Object.prototype.toString.call(value);
19
+
20
+ return stringValue === '[object RegExp]'
21
+ || stringValue === '[object Date]'
22
+ || isReactElement(value)
23
+ }
24
+
25
+ // see https://github.com/facebook/react/blob/b5ac963fb791d1298e7f396236383bc955f916c1/src/isomorphic/classic/element/ReactElement.js#L21-L25
26
+ var canUseSymbol = typeof Symbol === 'function' && Symbol.for;
27
+ var REACT_ELEMENT_TYPE = canUseSymbol ? Symbol.for('react.element') : 0xeac7;
28
+
29
+ function isReactElement(value) {
30
+ return value.$$typeof === REACT_ELEMENT_TYPE
31
+ }
32
+
33
+ function emptyTarget(val) {
34
+ return Array.isArray(val) ? [] : {}
35
+ }
36
+
37
+ function cloneUnlessOtherwiseSpecified(value, options) {
38
+ return (options.clone !== false && options.isMergeableObject(value))
39
+ ? deepmerge(emptyTarget(value), value, options)
40
+ : value
41
+ }
42
+
43
+ function defaultArrayMerge(target, source, options) {
44
+ return target.concat(source).map(function(element) {
45
+ return cloneUnlessOtherwiseSpecified(element, options)
46
+ })
47
+ }
48
+
49
+ function getMergeFunction(key, options) {
50
+ if (!options.customMerge) {
51
+ return deepmerge
52
+ }
53
+ var customMerge = options.customMerge(key);
54
+ return typeof customMerge === 'function' ? customMerge : deepmerge
55
+ }
56
+
57
+ function getEnumerableOwnPropertySymbols(target) {
58
+ return Object.getOwnPropertySymbols
59
+ ? Object.getOwnPropertySymbols(target).filter(function(symbol) {
60
+ return Object.propertyIsEnumerable.call(target, symbol)
61
+ })
62
+ : []
63
+ }
64
+
65
+ function getKeys(target) {
66
+ return Object.keys(target).concat(getEnumerableOwnPropertySymbols(target))
67
+ }
68
+
69
+ function propertyIsOnObject(object, property) {
70
+ try {
71
+ return property in object
72
+ } catch(_) {
73
+ return false
74
+ }
75
+ }
76
+
77
+ // Protects from prototype poisoning and unexpected merging up the prototype chain.
78
+ function propertyIsUnsafe(target, key) {
79
+ return propertyIsOnObject(target, key) // Properties are safe to merge if they don't exist in the target yet,
80
+ && !(Object.hasOwnProperty.call(target, key) // unsafe if they exist up the prototype chain,
81
+ && Object.propertyIsEnumerable.call(target, key)) // and also unsafe if they're nonenumerable.
82
+ }
83
+
84
+ function mergeObject(target, source, options) {
85
+ var destination = {};
86
+ if (options.isMergeableObject(target)) {
87
+ getKeys(target).forEach(function(key) {
88
+ destination[key] = cloneUnlessOtherwiseSpecified(target[key], options);
89
+ });
90
+ }
91
+ getKeys(source).forEach(function(key) {
92
+ if (propertyIsUnsafe(target, key)) {
93
+ return
94
+ }
95
+
96
+ if (propertyIsOnObject(target, key) && options.isMergeableObject(source[key])) {
97
+ destination[key] = getMergeFunction(key, options)(target[key], source[key], options);
98
+ } else {
99
+ destination[key] = cloneUnlessOtherwiseSpecified(source[key], options);
100
+ }
101
+ });
102
+ return destination
103
+ }
104
+
105
+ function deepmerge(target, source, options) {
106
+ options = options || {};
107
+ options.arrayMerge = options.arrayMerge || defaultArrayMerge;
108
+ options.isMergeableObject = options.isMergeableObject || isMergeableObject;
109
+ // cloneUnlessOtherwiseSpecified is added to `options` so that custom arrayMerge()
110
+ // implementations can use it. The caller may not replace it.
111
+ options.cloneUnlessOtherwiseSpecified = cloneUnlessOtherwiseSpecified;
112
+
113
+ var sourceIsArray = Array.isArray(source);
114
+ var targetIsArray = Array.isArray(target);
115
+ var sourceAndTargetTypesMatch = sourceIsArray === targetIsArray;
116
+
117
+ if (!sourceAndTargetTypesMatch) {
118
+ return cloneUnlessOtherwiseSpecified(source, options)
119
+ } else if (sourceIsArray) {
120
+ return options.arrayMerge(target, source, options)
121
+ } else {
122
+ return mergeObject(target, source, options)
123
+ }
124
+ }
125
+
126
+ deepmerge.all = function deepmergeAll(array, options) {
127
+ if (!Array.isArray(array)) {
128
+ throw new Error('first argument should be an array')
129
+ }
130
+
131
+ return array.reduce(function(prev, next) {
132
+ return deepmerge(prev, next, options)
133
+ }, {})
134
+ };
135
+
136
+ var deepmerge_1 = deepmerge;
137
+
138
+ cjs = deepmerge_1;
139
+ return cjs;
140
+ }
141
+
142
+ export { requireCjs as __require };
@@ -0,0 +1,102 @@
1
+ const elementNames = new Map([
2
+ "altGlyph",
3
+ "altGlyphDef",
4
+ "altGlyphItem",
5
+ "animateColor",
6
+ "animateMotion",
7
+ "animateTransform",
8
+ "clipPath",
9
+ "feBlend",
10
+ "feColorMatrix",
11
+ "feComponentTransfer",
12
+ "feComposite",
13
+ "feConvolveMatrix",
14
+ "feDiffuseLighting",
15
+ "feDisplacementMap",
16
+ "feDistantLight",
17
+ "feDropShadow",
18
+ "feFlood",
19
+ "feFuncA",
20
+ "feFuncB",
21
+ "feFuncG",
22
+ "feFuncR",
23
+ "feGaussianBlur",
24
+ "feImage",
25
+ "feMerge",
26
+ "feMergeNode",
27
+ "feMorphology",
28
+ "feOffset",
29
+ "fePointLight",
30
+ "feSpecularLighting",
31
+ "feSpotLight",
32
+ "feTile",
33
+ "feTurbulence",
34
+ "foreignObject",
35
+ "glyphRef",
36
+ "linearGradient",
37
+ "radialGradient",
38
+ "textPath",
39
+ ].map((val) => [val.toLowerCase(), val]));
40
+ const attributeNames = new Map([
41
+ "definitionURL",
42
+ "attributeName",
43
+ "attributeType",
44
+ "baseFrequency",
45
+ "baseProfile",
46
+ "calcMode",
47
+ "clipPathUnits",
48
+ "diffuseConstant",
49
+ "edgeMode",
50
+ "filterUnits",
51
+ "glyphRef",
52
+ "gradientTransform",
53
+ "gradientUnits",
54
+ "kernelMatrix",
55
+ "kernelUnitLength",
56
+ "keyPoints",
57
+ "keySplines",
58
+ "keyTimes",
59
+ "lengthAdjust",
60
+ "limitingConeAngle",
61
+ "markerHeight",
62
+ "markerUnits",
63
+ "markerWidth",
64
+ "maskContentUnits",
65
+ "maskUnits",
66
+ "numOctaves",
67
+ "pathLength",
68
+ "patternContentUnits",
69
+ "patternTransform",
70
+ "patternUnits",
71
+ "pointsAtX",
72
+ "pointsAtY",
73
+ "pointsAtZ",
74
+ "preserveAlpha",
75
+ "preserveAspectRatio",
76
+ "primitiveUnits",
77
+ "refX",
78
+ "refY",
79
+ "repeatCount",
80
+ "repeatDur",
81
+ "requiredExtensions",
82
+ "requiredFeatures",
83
+ "specularConstant",
84
+ "specularExponent",
85
+ "spreadMethod",
86
+ "startOffset",
87
+ "stdDeviation",
88
+ "stitchTiles",
89
+ "surfaceScale",
90
+ "systemLanguage",
91
+ "tableValues",
92
+ "targetX",
93
+ "targetY",
94
+ "textLength",
95
+ "viewBox",
96
+ "viewTarget",
97
+ "xChannelSelector",
98
+ "yChannelSelector",
99
+ "zoomAndPan",
100
+ ].map((val) => [val.toLowerCase(), val]));
101
+
102
+ export { attributeNames, elementNames };
@@ -0,0 +1,186 @@
1
+ import { Text, Tag, Style, Script, CDATA, Comment, Directive, Doctype, Root } from '../../../domelementtype/lib/esm/index.js';
2
+ import { elementNames, attributeNames } from './foreignNames.js';
3
+ import { encodeXML, escapeText, escapeAttribute } from '../../../entities/lib/esm/escape.js';
4
+
5
+ /*
6
+ * Module dependencies
7
+ */
8
+ const unencodedElements = new Set([
9
+ "style",
10
+ "script",
11
+ "xmp",
12
+ "iframe",
13
+ "noembed",
14
+ "noframes",
15
+ "plaintext",
16
+ "noscript",
17
+ ]);
18
+ function replaceQuotes(value) {
19
+ return value.replace(/"/g, "&quot;");
20
+ }
21
+ /**
22
+ * Format attributes
23
+ */
24
+ function formatAttributes(attributes, opts) {
25
+ var _a;
26
+ if (!attributes)
27
+ return;
28
+ const encode = ((_a = opts.encodeEntities) !== null && _a !== void 0 ? _a : opts.decodeEntities) === false
29
+ ? replaceQuotes
30
+ : opts.xmlMode || opts.encodeEntities !== "utf8"
31
+ ? encodeXML
32
+ : escapeAttribute;
33
+ return Object.keys(attributes)
34
+ .map((key) => {
35
+ var _a, _b;
36
+ const value = (_a = attributes[key]) !== null && _a !== void 0 ? _a : "";
37
+ if (opts.xmlMode === "foreign") {
38
+ /* Fix up mixed-case attribute names */
39
+ key = (_b = attributeNames.get(key)) !== null && _b !== void 0 ? _b : key;
40
+ }
41
+ if (!opts.emptyAttrs && !opts.xmlMode && value === "") {
42
+ return key;
43
+ }
44
+ return `${key}="${encode(value)}"`;
45
+ })
46
+ .join(" ");
47
+ }
48
+ /**
49
+ * Self-enclosing tags
50
+ */
51
+ const singleTag = new Set([
52
+ "area",
53
+ "base",
54
+ "basefont",
55
+ "br",
56
+ "col",
57
+ "command",
58
+ "embed",
59
+ "frame",
60
+ "hr",
61
+ "img",
62
+ "input",
63
+ "isindex",
64
+ "keygen",
65
+ "link",
66
+ "meta",
67
+ "param",
68
+ "source",
69
+ "track",
70
+ "wbr",
71
+ ]);
72
+ /**
73
+ * Renders a DOM node or an array of DOM nodes to a string.
74
+ *
75
+ * Can be thought of as the equivalent of the `outerHTML` of the passed node(s).
76
+ *
77
+ * @param node Node to be rendered.
78
+ * @param options Changes serialization behavior
79
+ */
80
+ function render(node, options = {}) {
81
+ const nodes = "length" in node ? node : [node];
82
+ let output = "";
83
+ for (let i = 0; i < nodes.length; i++) {
84
+ output += renderNode(nodes[i], options);
85
+ }
86
+ return output;
87
+ }
88
+ function renderNode(node, options) {
89
+ switch (node.type) {
90
+ case Root:
91
+ return render(node.children, options);
92
+ // @ts-expect-error We don't use `Doctype` yet
93
+ case Doctype:
94
+ case Directive:
95
+ return renderDirective(node);
96
+ case Comment:
97
+ return renderComment(node);
98
+ case CDATA:
99
+ return renderCdata(node);
100
+ case Script:
101
+ case Style:
102
+ case Tag:
103
+ return renderTag(node, options);
104
+ case Text:
105
+ return renderText(node, options);
106
+ }
107
+ }
108
+ const foreignModeIntegrationPoints = new Set([
109
+ "mi",
110
+ "mo",
111
+ "mn",
112
+ "ms",
113
+ "mtext",
114
+ "annotation-xml",
115
+ "foreignObject",
116
+ "desc",
117
+ "title",
118
+ ]);
119
+ const foreignElements = new Set(["svg", "math"]);
120
+ function renderTag(elem, opts) {
121
+ var _a;
122
+ // Handle SVG / MathML in HTML
123
+ if (opts.xmlMode === "foreign") {
124
+ /* Fix up mixed-case element names */
125
+ elem.name = (_a = elementNames.get(elem.name)) !== null && _a !== void 0 ? _a : elem.name;
126
+ /* Exit foreign mode at integration points */
127
+ if (elem.parent &&
128
+ foreignModeIntegrationPoints.has(elem.parent.name)) {
129
+ opts = { ...opts, xmlMode: false };
130
+ }
131
+ }
132
+ if (!opts.xmlMode && foreignElements.has(elem.name)) {
133
+ opts = { ...opts, xmlMode: "foreign" };
134
+ }
135
+ let tag = `<${elem.name}`;
136
+ const attribs = formatAttributes(elem.attribs, opts);
137
+ if (attribs) {
138
+ tag += ` ${attribs}`;
139
+ }
140
+ if (elem.children.length === 0 &&
141
+ (opts.xmlMode
142
+ ? // In XML mode or foreign mode, and user hasn't explicitly turned off self-closing tags
143
+ opts.selfClosingTags !== false
144
+ : // User explicitly asked for self-closing tags, even in HTML mode
145
+ opts.selfClosingTags && singleTag.has(elem.name))) {
146
+ if (!opts.xmlMode)
147
+ tag += " ";
148
+ tag += "/>";
149
+ }
150
+ else {
151
+ tag += ">";
152
+ if (elem.children.length > 0) {
153
+ tag += render(elem.children, opts);
154
+ }
155
+ if (opts.xmlMode || !singleTag.has(elem.name)) {
156
+ tag += `</${elem.name}>`;
157
+ }
158
+ }
159
+ return tag;
160
+ }
161
+ function renderDirective(elem) {
162
+ return `<${elem.data}>`;
163
+ }
164
+ function renderText(elem, opts) {
165
+ var _a;
166
+ let data = elem.data || "";
167
+ // If entities weren't decoded, no need to encode them back
168
+ if (((_a = opts.encodeEntities) !== null && _a !== void 0 ? _a : opts.decodeEntities) !== false &&
169
+ !(!opts.xmlMode &&
170
+ elem.parent &&
171
+ unencodedElements.has(elem.parent.name))) {
172
+ data =
173
+ opts.xmlMode || opts.encodeEntities !== "utf8"
174
+ ? encodeXML(data)
175
+ : escapeText(data);
176
+ }
177
+ return data;
178
+ }
179
+ function renderCdata(elem) {
180
+ return `<![CDATA[${elem.children[0].data}]]>`;
181
+ }
182
+ function renderComment(elem) {
183
+ return `<!--${elem.data}-->`;
184
+ }
185
+
186
+ export { render as default, render };
@@ -0,0 +1,53 @@
1
+ /** Types of elements found in htmlparser2's DOM */
2
+ var ElementType;
3
+ (function (ElementType) {
4
+ /** Type for the root element of a document */
5
+ ElementType["Root"] = "root";
6
+ /** Type for Text */
7
+ ElementType["Text"] = "text";
8
+ /** Type for <? ... ?> */
9
+ ElementType["Directive"] = "directive";
10
+ /** Type for <!-- ... --> */
11
+ ElementType["Comment"] = "comment";
12
+ /** Type for <script> tags */
13
+ ElementType["Script"] = "script";
14
+ /** Type for <style> tags */
15
+ ElementType["Style"] = "style";
16
+ /** Type for Any tag */
17
+ ElementType["Tag"] = "tag";
18
+ /** Type for <![CDATA[ ... ]]> */
19
+ ElementType["CDATA"] = "cdata";
20
+ /** Type for <!doctype ...> */
21
+ ElementType["Doctype"] = "doctype";
22
+ })(ElementType || (ElementType = {}));
23
+ /**
24
+ * Tests whether an element is a tag or not.
25
+ *
26
+ * @param elem Element to test
27
+ */
28
+ function isTag(elem) {
29
+ return (elem.type === ElementType.Tag ||
30
+ elem.type === ElementType.Script ||
31
+ elem.type === ElementType.Style);
32
+ }
33
+ // Exports for backwards compatibility
34
+ /** Type for the root element of a document */
35
+ const Root = ElementType.Root;
36
+ /** Type for Text */
37
+ const Text = ElementType.Text;
38
+ /** Type for <? ... ?> */
39
+ const Directive = ElementType.Directive;
40
+ /** Type for <!-- ... --> */
41
+ const Comment = ElementType.Comment;
42
+ /** Type for <script> tags */
43
+ const Script = ElementType.Script;
44
+ /** Type for <style> tags */
45
+ const Style = ElementType.Style;
46
+ /** Type for Any tag */
47
+ const Tag = ElementType.Tag;
48
+ /** Type for <![CDATA[ ... ]]> */
49
+ const CDATA = ElementType.CDATA;
50
+ /** Type for <!doctype ...> */
51
+ const Doctype = ElementType.Doctype;
52
+
53
+ export { CDATA, Comment, Directive, Doctype, ElementType, Root, Script, Style, Tag, Text, isTag };