@domql/utils 3.1.2 → 3.2.7
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/array.js +11 -5
- package/cache.js +3 -0
- package/component.js +3 -4
- package/dist/cjs/array.js +11 -5
- package/dist/cjs/component.js +4 -6
- package/dist/cjs/element.js +6 -6
- package/dist/cjs/env.js +1 -1
- package/dist/cjs/events.js +3 -3
- package/dist/cjs/extends.js +44 -28
- package/dist/cjs/function.js +3 -3
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/key.js +2 -2
- package/dist/cjs/keys.js +29 -15
- package/dist/cjs/methods.js +88 -33
- package/dist/cjs/object.js +154 -141
- package/dist/cjs/props.js +43 -34
- package/dist/cjs/scope.js +1 -2
- package/dist/cjs/state.js +12 -11
- package/dist/cjs/string.js +15 -20
- package/dist/cjs/tags.js +71 -16
- package/dist/cjs/triggerEvent.js +90 -0
- package/dist/cjs/types.js +4 -12
- package/dist/esm/array.js +11 -5
- package/dist/esm/component.js +4 -6
- package/dist/esm/element.js +9 -27
- package/dist/esm/env.js +1 -1
- package/dist/esm/events.js +3 -3
- package/dist/esm/extends.js +48 -50
- package/dist/esm/function.js +3 -3
- package/dist/esm/index.js +1 -0
- package/dist/esm/key.js +2 -2
- package/dist/esm/keys.js +29 -15
- package/dist/esm/methods.js +86 -31
- package/dist/esm/object.js +158 -165
- package/dist/esm/props.js +43 -50
- package/dist/esm/scope.js +1 -2
- package/dist/esm/state.js +21 -38
- package/dist/esm/string.js +15 -20
- package/dist/esm/tags.js +71 -16
- package/dist/esm/triggerEvent.js +70 -0
- package/dist/esm/types.js +4 -12
- package/dist/iife/index.js +2779 -0
- package/element.js +2 -2
- package/events.js +3 -3
- package/extends.js +28 -17
- package/function.js +10 -9
- package/index.js +1 -0
- package/keys.js +25 -15
- package/log.js +0 -1
- package/methods.js +99 -24
- package/object.js +155 -215
- package/package.json +34 -13
- package/props.js +44 -27
- package/state.js +12 -12
- package/string.js +20 -38
- package/tags.js +45 -16
- package/triggerEvent.js +76 -0
- package/types.js +8 -25
- package/dist/cjs/package.json +0 -4
package/dist/esm/props.js
CHANGED
|
@@ -1,23 +1,10 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
-
var __spreadValues = (a, b) => {
|
|
7
|
-
for (var prop in b || (b = {}))
|
|
8
|
-
if (__hasOwnProp.call(b, prop))
|
|
9
|
-
__defNormalProp(a, prop, b[prop]);
|
|
10
|
-
if (__getOwnPropSymbols)
|
|
11
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
-
if (__propIsEnum.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
}
|
|
15
|
-
return a;
|
|
16
|
-
};
|
|
17
1
|
import { DOMQ_PROPERTIES, PROPS_METHODS } from "./keys.js";
|
|
18
2
|
import { addEventFromProps } from "./events.js";
|
|
19
3
|
import { deepClone, deepMerge, exec } from "./object.js";
|
|
20
4
|
import { is, isArray, isFunction, isObject, isObjectLike } from "./types.js";
|
|
5
|
+
import { lowercaseFirstLetter } from "./string.js";
|
|
6
|
+
const RE_UPPER = /^[A-Z]/;
|
|
7
|
+
const RE_DIGITS = /^\d+$/;
|
|
21
8
|
const createProps = (element, parent, key) => {
|
|
22
9
|
const { props, __ref: ref } = element;
|
|
23
10
|
ref.__propsStack = [];
|
|
@@ -27,17 +14,23 @@ const createProps = (element, parent, key) => {
|
|
|
27
14
|
ref.__propsStack.push(props);
|
|
28
15
|
return {};
|
|
29
16
|
}
|
|
30
|
-
return
|
|
17
|
+
return { ...props };
|
|
31
18
|
};
|
|
32
19
|
function pickupPropsFromElement(obj, opts = {}) {
|
|
33
|
-
var _a, _b, _c;
|
|
34
20
|
const cachedKeys = opts.cachedKeys || [];
|
|
35
21
|
for (const key in obj) {
|
|
36
22
|
const value = obj[key];
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
23
|
+
const isEventHandler = key.length > 2 && key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110 && key[2] === key[2].toUpperCase() && isFunction(value);
|
|
24
|
+
if (isEventHandler) {
|
|
25
|
+
const eventName = lowercaseFirstLetter(key.slice(2));
|
|
26
|
+
if (obj.on) obj.on[eventName] = value;
|
|
27
|
+
delete obj[key];
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const hasDefine = isObject(this.define?.[key]);
|
|
31
|
+
const hasGlobalDefine = isObject(this.context?.define?.[key]);
|
|
32
|
+
const isElement = RE_UPPER.test(key) || RE_DIGITS.test(key);
|
|
33
|
+
const isBuiltin = DOMQ_PROPERTIES.has(key);
|
|
41
34
|
if (!isElement && !isBuiltin && !hasDefine && !hasGlobalDefine) {
|
|
42
35
|
obj.props[key] = value;
|
|
43
36
|
delete obj[key];
|
|
@@ -47,11 +40,10 @@ function pickupPropsFromElement(obj, opts = {}) {
|
|
|
47
40
|
return obj;
|
|
48
41
|
}
|
|
49
42
|
function pickupElementFromProps(obj = this, opts) {
|
|
50
|
-
var _a, _b, _c;
|
|
51
43
|
const cachedKeys = opts.cachedKeys || [];
|
|
52
44
|
for (const key in obj.props) {
|
|
53
45
|
const value = obj.props[key];
|
|
54
|
-
const isEvent = key.
|
|
46
|
+
const isEvent = key.length > 2 && key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110;
|
|
55
47
|
const isFn = isFunction(value);
|
|
56
48
|
if (isEvent && isFn) {
|
|
57
49
|
addEventFromProps(key, obj);
|
|
@@ -59,13 +51,15 @@ function pickupElementFromProps(obj = this, opts) {
|
|
|
59
51
|
continue;
|
|
60
52
|
}
|
|
61
53
|
if (cachedKeys.includes(key)) continue;
|
|
62
|
-
const hasDefine = isObject(
|
|
63
|
-
const hasGlobalDefine = isObject(
|
|
64
|
-
const isElement =
|
|
65
|
-
const isBuiltin = DOMQ_PROPERTIES.
|
|
54
|
+
const hasDefine = isObject(this.define?.[key]);
|
|
55
|
+
const hasGlobalDefine = isObject(this.context?.define?.[key]);
|
|
56
|
+
const isElement = RE_UPPER.test(key) || RE_DIGITS.test(key);
|
|
57
|
+
const isBuiltin = DOMQ_PROPERTIES.has(key);
|
|
66
58
|
if (isElement || isBuiltin || hasDefine || hasGlobalDefine) {
|
|
67
|
-
obj[key]
|
|
68
|
-
|
|
59
|
+
if (obj[key] === void 0 || value === null) {
|
|
60
|
+
obj[key] = value;
|
|
61
|
+
if (obj.props) delete obj.props[key];
|
|
62
|
+
}
|
|
69
63
|
}
|
|
70
64
|
}
|
|
71
65
|
return obj;
|
|
@@ -77,8 +71,9 @@ function propertizeElement(element = this) {
|
|
|
77
71
|
return element;
|
|
78
72
|
}
|
|
79
73
|
function propertizeUpdate(params = {}) {
|
|
80
|
-
|
|
81
|
-
|
|
74
|
+
if (!params.on) params.on = {};
|
|
75
|
+
if (!params.props) params.props = {};
|
|
76
|
+
return propertizeElement.call(this, params);
|
|
82
77
|
}
|
|
83
78
|
const objectizeStringProperty = (propValue) => {
|
|
84
79
|
if (is(propValue)("string", "number")) {
|
|
@@ -88,21 +83,16 @@ const objectizeStringProperty = (propValue) => {
|
|
|
88
83
|
};
|
|
89
84
|
const propExists = (prop, stack) => {
|
|
90
85
|
if (!prop || !stack.length) return false;
|
|
91
|
-
|
|
92
|
-
return stack.some((existing) => {
|
|
93
|
-
const existingKey = isObject(existing) ? JSON.stringify(existing) : existing;
|
|
94
|
-
return existingKey === key;
|
|
95
|
-
});
|
|
86
|
+
return stack.includes(prop);
|
|
96
87
|
};
|
|
97
88
|
const inheritParentProps = (element, parent) => {
|
|
98
|
-
var _a;
|
|
99
89
|
const { __ref: ref } = element;
|
|
100
90
|
const propsStack = ref.__propsStack || [];
|
|
101
91
|
const parentProps = parent.props;
|
|
102
92
|
if (!parentProps) return propsStack;
|
|
103
93
|
const matchParentKeyProps = parentProps[element.key];
|
|
104
94
|
const matchParentChildProps = parentProps.childProps;
|
|
105
|
-
const ignoreChildProps =
|
|
95
|
+
const ignoreChildProps = element.props?.ignoreChildProps;
|
|
106
96
|
if (matchParentChildProps && !ignoreChildProps) {
|
|
107
97
|
const childProps = objectizeStringProperty(matchParentChildProps);
|
|
108
98
|
propsStack.unshift(childProps);
|
|
@@ -113,9 +103,9 @@ const inheritParentProps = (element, parent) => {
|
|
|
113
103
|
}
|
|
114
104
|
return propsStack;
|
|
115
105
|
};
|
|
116
|
-
|
|
106
|
+
function update(props, options) {
|
|
117
107
|
const element = this.__element;
|
|
118
|
-
|
|
108
|
+
element.update({ props }, options);
|
|
119
109
|
}
|
|
120
110
|
function setPropsPrototype(element) {
|
|
121
111
|
const methods = { update: update.bind(element.props), __element: element };
|
|
@@ -124,16 +114,15 @@ function setPropsPrototype(element) {
|
|
|
124
114
|
const removeDuplicateProps = (propsStack) => {
|
|
125
115
|
const seen = /* @__PURE__ */ new Set();
|
|
126
116
|
return propsStack.filter((prop) => {
|
|
127
|
-
if (!prop || PROPS_METHODS.
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
seen.add(key);
|
|
117
|
+
if (!prop || PROPS_METHODS.has(prop)) return false;
|
|
118
|
+
if (seen.has(prop)) return false;
|
|
119
|
+
seen.add(prop);
|
|
131
120
|
return true;
|
|
132
121
|
});
|
|
133
122
|
};
|
|
134
123
|
const syncProps = (propsStack, element, opts) => {
|
|
135
124
|
element.props = propsStack.reduce((mergedProps, v) => {
|
|
136
|
-
if (PROPS_METHODS.
|
|
125
|
+
if (PROPS_METHODS.has(v)) return mergedProps;
|
|
137
126
|
while (isFunction(v)) v = exec(v, element);
|
|
138
127
|
return deepMerge(mergedProps, deepClone(v, { exclude: PROPS_METHODS }));
|
|
139
128
|
}, {});
|
|
@@ -143,19 +132,20 @@ const syncProps = (propsStack, element, opts) => {
|
|
|
143
132
|
const createPropsStack = (element, parent) => {
|
|
144
133
|
const { props, __ref: ref } = element;
|
|
145
134
|
let propsStack = ref.__propsStack || [];
|
|
146
|
-
if (parent
|
|
135
|
+
if (parent?.props) {
|
|
147
136
|
const parentStack = inheritParentProps(element, parent);
|
|
148
137
|
propsStack = [...parentStack];
|
|
149
138
|
}
|
|
150
139
|
if (isObject(props)) propsStack.push(props);
|
|
151
|
-
else if (props === "inherit" &&
|
|
140
|
+
else if (props === "inherit" && parent?.props) propsStack.push(parent.props);
|
|
152
141
|
else if (props) propsStack.push(props);
|
|
153
142
|
if (isArray(ref.__extendsStack)) {
|
|
154
|
-
ref.__extendsStack.
|
|
143
|
+
for (let i = 0; i < ref.__extendsStack.length; i++) {
|
|
144
|
+
const _extends = ref.__extendsStack[i];
|
|
155
145
|
if (_extends.props && _extends.props !== props) {
|
|
156
146
|
propsStack.push(_extends.props);
|
|
157
147
|
}
|
|
158
|
-
}
|
|
148
|
+
}
|
|
159
149
|
}
|
|
160
150
|
ref.__propsStack = removeDuplicateProps(propsStack);
|
|
161
151
|
return ref.__propsStack;
|
|
@@ -177,6 +167,9 @@ const initProps = function(element, parent, options) {
|
|
|
177
167
|
try {
|
|
178
168
|
applyProps(element, parent);
|
|
179
169
|
} catch (e) {
|
|
170
|
+
if (element.context?.designSystem?.verbose) {
|
|
171
|
+
console.warn("initProps error at", ref.path?.join("."), e);
|
|
172
|
+
}
|
|
180
173
|
element.props = {};
|
|
181
174
|
ref.__propsStack = [];
|
|
182
175
|
}
|
package/dist/esm/scope.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const createScope = (element, parent) => {
|
|
2
|
-
var _a;
|
|
3
2
|
const { __ref: ref } = element;
|
|
4
|
-
if (!element.scope) element.scope = parent.scope ||
|
|
3
|
+
if (!element.scope) element.scope = parent.scope || ref.root?.scope || {};
|
|
5
4
|
};
|
|
6
5
|
export {
|
|
7
6
|
createScope
|
package/dist/esm/state.js
CHANGED
|
@@ -1,28 +1,9 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
1
|
import { addProtoToArray } from "./array.js";
|
|
21
2
|
import { STATE_METHODS } from "./keys.js";
|
|
22
3
|
import {
|
|
23
4
|
deepClone,
|
|
24
5
|
deepMerge,
|
|
25
|
-
|
|
6
|
+
exec,
|
|
26
7
|
overwriteDeep,
|
|
27
8
|
overwriteShallow
|
|
28
9
|
} from "./object.js";
|
|
@@ -31,15 +12,14 @@ import {
|
|
|
31
12
|
isFunction,
|
|
32
13
|
isObject,
|
|
33
14
|
isObjectLike,
|
|
34
|
-
isString
|
|
35
|
-
isUndefined
|
|
15
|
+
isString
|
|
36
16
|
} from "./types.js";
|
|
37
|
-
const checkForStateTypes =
|
|
17
|
+
const checkForStateTypes = (element) => {
|
|
38
18
|
const { state: orig, props, __ref: ref } = element;
|
|
39
|
-
const state =
|
|
19
|
+
const state = props?.state || orig;
|
|
40
20
|
if (isFunction(state)) {
|
|
41
21
|
ref.__state = state;
|
|
42
|
-
return
|
|
22
|
+
return exec(state, element);
|
|
43
23
|
} else if (is(state)("string", "number")) {
|
|
44
24
|
ref.__state = state;
|
|
45
25
|
return { value: state };
|
|
@@ -106,7 +86,7 @@ const findInheritedState = (element, parent, options = {}) => {
|
|
|
106
86
|
const createInheritedState = (element, parent) => {
|
|
107
87
|
const ref = element.__ref;
|
|
108
88
|
const inheritedState = findInheritedState(element, parent);
|
|
109
|
-
if (
|
|
89
|
+
if (inheritedState === void 0) return element.state;
|
|
110
90
|
if (is(inheritedState)("object", "array")) {
|
|
111
91
|
return deepClone(inheritedState);
|
|
112
92
|
} else if (is(inheritedState)("string", "number", "boolean")) {
|
|
@@ -117,7 +97,7 @@ const createInheritedState = (element, parent) => {
|
|
|
117
97
|
};
|
|
118
98
|
const checkIfInherits = (element) => {
|
|
119
99
|
const { __ref: ref } = element;
|
|
120
|
-
const stateKey = ref
|
|
100
|
+
const stateKey = ref?.__state;
|
|
121
101
|
if (stateKey && is(stateKey)("number", "string", "boolean")) return true;
|
|
122
102
|
return false;
|
|
123
103
|
};
|
|
@@ -134,27 +114,30 @@ const createNestedObjectByKeyPath = (path, value) => {
|
|
|
134
114
|
const keys = path.split("/");
|
|
135
115
|
const obj = {};
|
|
136
116
|
let ref = obj;
|
|
137
|
-
keys.
|
|
138
|
-
|
|
139
|
-
ref =
|
|
140
|
-
|
|
117
|
+
const lastIdx = keys.length - 1;
|
|
118
|
+
for (let i = 0; i <= lastIdx; i++) {
|
|
119
|
+
ref[keys[i]] = i === lastIdx ? value || {} : {};
|
|
120
|
+
ref = ref[keys[i]];
|
|
121
|
+
}
|
|
141
122
|
return obj;
|
|
142
123
|
};
|
|
143
|
-
const applyDependentState =
|
|
124
|
+
const applyDependentState = (element, state) => {
|
|
144
125
|
const { __element } = state;
|
|
145
|
-
const origState =
|
|
126
|
+
const origState = exec(__element?.state, element);
|
|
146
127
|
if (!origState) return;
|
|
147
128
|
const dependentState = deepClone(origState, STATE_METHODS);
|
|
148
129
|
const newDepends = { [element.key]: dependentState };
|
|
149
|
-
const __depends = isObject(origState.__depends) ?
|
|
130
|
+
const __depends = isObject(origState.__depends) ? { ...origState.__depends, ...newDepends } : newDepends;
|
|
150
131
|
if (Array.isArray(origState)) {
|
|
151
|
-
addProtoToArray(origState,
|
|
132
|
+
addProtoToArray(origState, {
|
|
133
|
+
...Object.getPrototypeOf(origState),
|
|
152
134
|
__depends
|
|
153
|
-
})
|
|
135
|
+
});
|
|
154
136
|
} else {
|
|
155
|
-
Object.setPrototypeOf(origState,
|
|
137
|
+
Object.setPrototypeOf(origState, {
|
|
138
|
+
...Object.getPrototypeOf(origState),
|
|
156
139
|
__depends
|
|
157
|
-
})
|
|
140
|
+
});
|
|
158
141
|
}
|
|
159
142
|
return dependentState;
|
|
160
143
|
};
|
package/dist/esm/string.js
CHANGED
|
@@ -16,15 +16,15 @@ const brackRegex = {
|
|
|
16
16
|
};
|
|
17
17
|
const getNestedValue = (obj, path) => {
|
|
18
18
|
return path.split(".").reduce((acc, part) => {
|
|
19
|
-
return acc
|
|
19
|
+
return acc?.[part];
|
|
20
20
|
}, obj);
|
|
21
21
|
};
|
|
22
|
-
function replaceLiteralsWithObjectFields(str, state
|
|
22
|
+
function replaceLiteralsWithObjectFields(str, state, options = {}) {
|
|
23
23
|
const { bracketsLength = 2 } = options;
|
|
24
24
|
const bracketPattern = bracketsLength === 3 ? "{{{" : "{{";
|
|
25
25
|
if (!str.includes(bracketPattern)) return str;
|
|
26
26
|
const reg = brackRegex[bracketsLength];
|
|
27
|
-
const obj = state || {};
|
|
27
|
+
const obj = state || this.state || {};
|
|
28
28
|
return str.replace(reg, (_, parentPath, variable) => {
|
|
29
29
|
if (parentPath) {
|
|
30
30
|
const parentLevels = (parentPath.match(/\.\.\//g) || []).length;
|
|
@@ -35,13 +35,13 @@ function replaceLiteralsWithObjectFields(str, state = {}, options = {}) {
|
|
|
35
35
|
}
|
|
36
36
|
const key = variable.trim();
|
|
37
37
|
if (key === "parent") {
|
|
38
|
-
return
|
|
38
|
+
return String(parentState.value ?? "");
|
|
39
39
|
}
|
|
40
40
|
const value = getNestedValue(parentState, key);
|
|
41
|
-
return
|
|
41
|
+
return String(value ?? "");
|
|
42
42
|
} else {
|
|
43
43
|
const value = getNestedValue(obj, variable.trim());
|
|
44
|
-
return
|
|
44
|
+
return String(value ?? "");
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
47
|
}
|
|
@@ -94,27 +94,22 @@ const findKeyPosition = (str, key) => {
|
|
|
94
94
|
endLineNumber
|
|
95
95
|
};
|
|
96
96
|
};
|
|
97
|
+
const RE_OCTAL = /\\([0-7]{1,3})/g;
|
|
97
98
|
const replaceOctalEscapeSequences = (str) => {
|
|
98
|
-
|
|
99
|
-
return str.replace(octalRegex, (match, p1) => {
|
|
100
|
-
const octalValue = parseInt(p1, 8);
|
|
101
|
-
const char = String.fromCharCode(octalValue);
|
|
102
|
-
return char;
|
|
103
|
-
});
|
|
99
|
+
return str.replace(RE_OCTAL, (_, p1) => String.fromCharCode(parseInt(p1, 8)));
|
|
104
100
|
};
|
|
105
101
|
const encodeNewlines = (str) => {
|
|
106
|
-
return str.
|
|
102
|
+
return str.replace(/\n/g, "/////n").replace(/`/g, "/////tilde").replace(/\$/g, "/////dlrsgn");
|
|
107
103
|
};
|
|
108
104
|
const decodeNewlines = (encodedStr) => {
|
|
109
|
-
return encodedStr.
|
|
105
|
+
return encodedStr.replace(/\/\/\/\/\/n/g, "\n").replace(/\/\/\/\/\/tilde/g, "`").replace(/\/\/\/\/\/dlrsgn/g, "$");
|
|
110
106
|
};
|
|
107
|
+
const RE_NON_ALNUM = /[^a-zA-Z0-9\s]/g;
|
|
111
108
|
const customEncodeURIComponent = (str) => {
|
|
112
|
-
return str.
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return char;
|
|
117
|
-
}).join("");
|
|
109
|
+
return str.replace(
|
|
110
|
+
RE_NON_ALNUM,
|
|
111
|
+
(char) => "%" + char.charCodeAt(0).toString(16).toUpperCase()
|
|
112
|
+
);
|
|
118
113
|
};
|
|
119
114
|
const customDecodeURIComponent = (encodedStr) => {
|
|
120
115
|
return encodedStr.replace(
|
package/dist/esm/tags.js
CHANGED
|
@@ -1,17 +1,7 @@
|
|
|
1
1
|
const HTML_TAGS = {
|
|
2
|
-
root: [
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
],
|
|
6
|
-
head: [
|
|
7
|
-
"title",
|
|
8
|
-
"base",
|
|
9
|
-
"meta",
|
|
10
|
-
"style",
|
|
11
|
-
"noscript",
|
|
12
|
-
"script"
|
|
13
|
-
],
|
|
14
|
-
body: [
|
|
2
|
+
root: ["body", "html"],
|
|
3
|
+
head: ["title", "base", "meta", "style", "noscript", "script"],
|
|
4
|
+
body: /* @__PURE__ */ new Set([
|
|
15
5
|
"string",
|
|
16
6
|
"style",
|
|
17
7
|
"fragment",
|
|
@@ -135,11 +125,76 @@ const HTML_TAGS = {
|
|
|
135
125
|
"wbr",
|
|
136
126
|
// SVG
|
|
137
127
|
"svg",
|
|
138
|
-
"path"
|
|
139
|
-
|
|
128
|
+
"path",
|
|
129
|
+
"circle",
|
|
130
|
+
"ellipse",
|
|
131
|
+
"line",
|
|
132
|
+
"polygon",
|
|
133
|
+
"polyline",
|
|
134
|
+
"rect",
|
|
135
|
+
"g",
|
|
136
|
+
"defs",
|
|
137
|
+
"symbol",
|
|
138
|
+
"use",
|
|
139
|
+
"text",
|
|
140
|
+
"tspan",
|
|
141
|
+
"image",
|
|
142
|
+
"clipPath",
|
|
143
|
+
"mask",
|
|
144
|
+
"pattern",
|
|
145
|
+
"marker",
|
|
146
|
+
"linearGradient",
|
|
147
|
+
"radialGradient",
|
|
148
|
+
"stop",
|
|
149
|
+
"filter",
|
|
150
|
+
"feGaussianBlur",
|
|
151
|
+
"feOffset",
|
|
152
|
+
"feMerge",
|
|
153
|
+
"feMergeNode",
|
|
154
|
+
"feBlend",
|
|
155
|
+
"feColorMatrix",
|
|
156
|
+
"feFlood",
|
|
157
|
+
"feComposite",
|
|
158
|
+
"foreignObject"
|
|
159
|
+
])
|
|
140
160
|
};
|
|
141
|
-
const
|
|
161
|
+
const SVG_TAGS = /* @__PURE__ */ new Set([
|
|
162
|
+
"svg",
|
|
163
|
+
"path",
|
|
164
|
+
"circle",
|
|
165
|
+
"ellipse",
|
|
166
|
+
"line",
|
|
167
|
+
"polygon",
|
|
168
|
+
"polyline",
|
|
169
|
+
"rect",
|
|
170
|
+
"g",
|
|
171
|
+
"defs",
|
|
172
|
+
"symbol",
|
|
173
|
+
"use",
|
|
174
|
+
"text",
|
|
175
|
+
"tspan",
|
|
176
|
+
"image",
|
|
177
|
+
"clipPath",
|
|
178
|
+
"mask",
|
|
179
|
+
"pattern",
|
|
180
|
+
"marker",
|
|
181
|
+
"linearGradient",
|
|
182
|
+
"radialGradient",
|
|
183
|
+
"stop",
|
|
184
|
+
"filter",
|
|
185
|
+
"feGaussianBlur",
|
|
186
|
+
"feOffset",
|
|
187
|
+
"feMerge",
|
|
188
|
+
"feMergeNode",
|
|
189
|
+
"feBlend",
|
|
190
|
+
"feColorMatrix",
|
|
191
|
+
"feFlood",
|
|
192
|
+
"feComposite",
|
|
193
|
+
"foreignObject"
|
|
194
|
+
]);
|
|
195
|
+
const isValidHtmlTag = (arg) => HTML_TAGS.body.has(arg);
|
|
142
196
|
export {
|
|
143
197
|
HTML_TAGS,
|
|
198
|
+
SVG_TAGS,
|
|
144
199
|
isValidHtmlTag
|
|
145
200
|
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { isFunction } from "./types.js";
|
|
2
|
+
const getOnOrPropsEvent = (param, element) => {
|
|
3
|
+
const onEvent = element.on?.[param];
|
|
4
|
+
if (onEvent) return onEvent;
|
|
5
|
+
const props = element.props;
|
|
6
|
+
if (!props) return;
|
|
7
|
+
const propKey = "on" + param.charAt(0).toUpperCase() + param.slice(1);
|
|
8
|
+
return props[propKey];
|
|
9
|
+
};
|
|
10
|
+
const applyEvent = (param, element, state, context, options) => {
|
|
11
|
+
if (!isFunction(param)) return;
|
|
12
|
+
const result = param.call(
|
|
13
|
+
element,
|
|
14
|
+
element,
|
|
15
|
+
state || element.state,
|
|
16
|
+
context || element.context,
|
|
17
|
+
options
|
|
18
|
+
);
|
|
19
|
+
if (result && typeof result.then === "function") {
|
|
20
|
+
result.catch(() => {
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
const triggerEventOn = (param, element, options) => {
|
|
26
|
+
if (!element) {
|
|
27
|
+
throw new Error("Element is required");
|
|
28
|
+
}
|
|
29
|
+
const appliedFunction = getOnOrPropsEvent(param, element);
|
|
30
|
+
if (appliedFunction) {
|
|
31
|
+
const { state, context } = element;
|
|
32
|
+
return applyEvent(appliedFunction, element, state, context, options);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const applyEventUpdate = (param, updatedObj, element, state, context, options) => {
|
|
36
|
+
if (!isFunction(param)) return;
|
|
37
|
+
const result = param.call(
|
|
38
|
+
element,
|
|
39
|
+
updatedObj,
|
|
40
|
+
element,
|
|
41
|
+
state || element.state,
|
|
42
|
+
context || element.context,
|
|
43
|
+
options
|
|
44
|
+
);
|
|
45
|
+
if (result && typeof result.then === "function") {
|
|
46
|
+
result.catch(() => {
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
};
|
|
51
|
+
const triggerEventOnUpdate = (param, updatedObj, element, options) => {
|
|
52
|
+
const appliedFunction = getOnOrPropsEvent(param, element);
|
|
53
|
+
if (appliedFunction) {
|
|
54
|
+
const { state, context } = element;
|
|
55
|
+
return applyEventUpdate(
|
|
56
|
+
appliedFunction,
|
|
57
|
+
updatedObj,
|
|
58
|
+
element,
|
|
59
|
+
state,
|
|
60
|
+
context,
|
|
61
|
+
options
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
export {
|
|
66
|
+
applyEvent,
|
|
67
|
+
applyEventUpdate,
|
|
68
|
+
triggerEventOn,
|
|
69
|
+
triggerEventOnUpdate
|
|
70
|
+
};
|
package/dist/esm/types.js
CHANGED
|
@@ -14,12 +14,8 @@ const isObjectLike = (arg) => {
|
|
|
14
14
|
if (arg === null) return false;
|
|
15
15
|
return typeof arg === "object";
|
|
16
16
|
};
|
|
17
|
-
const isDefined = (arg) =>
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
const isUndefined = (arg) => {
|
|
21
|
-
return arg === void 0;
|
|
22
|
-
};
|
|
17
|
+
const isDefined = (arg) => arg !== void 0;
|
|
18
|
+
const isUndefined = (arg) => arg === void 0;
|
|
23
19
|
const TYPES = {
|
|
24
20
|
boolean: isBoolean,
|
|
25
21
|
array: isArray,
|
|
@@ -35,14 +31,10 @@ const TYPES = {
|
|
|
35
31
|
defined: isDefined
|
|
36
32
|
};
|
|
37
33
|
const is = (arg) => {
|
|
38
|
-
return (...args) =>
|
|
39
|
-
return args.map((val) => TYPES[val](arg)).filter((v) => v).length > 0;
|
|
40
|
-
};
|
|
34
|
+
return (...args) => args.some((val) => TYPES[val](arg));
|
|
41
35
|
};
|
|
42
36
|
const isNot = (arg) => {
|
|
43
|
-
return (...args) =>
|
|
44
|
-
return args.map((val) => TYPES[val](arg)).filter((v) => v).length === 0;
|
|
45
|
-
};
|
|
37
|
+
return (...args) => !args.some((val) => TYPES[val](arg));
|
|
46
38
|
};
|
|
47
39
|
export {
|
|
48
40
|
TYPES,
|