@symbo.ls/utils 3.2.3 → 3.14.0
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/LICENSE +25 -12
- package/README.md +106 -0
- package/array.js +162 -0
- package/cache.js +7 -0
- package/cdn.js +83 -0
- package/component.js +25 -0
- package/cookie.js +71 -0
- package/{src/detectHeight.js → detectHeight.js} +3 -3
- package/dist/cjs/array.js +168 -0
- package/dist/cjs/browser.js +0 -2
- package/dist/cjs/cache.js +26 -0
- package/dist/cjs/cdn.js +85 -0
- package/dist/cjs/component.js +45 -0
- package/dist/cjs/cookie.js +75 -0
- package/dist/cjs/date.js +1 -3
- package/dist/cjs/detectHeight.js +4 -6
- package/dist/cjs/element.js +136 -0
- package/dist/cjs/env.js +43 -0
- package/dist/cjs/events.js +39 -0
- package/dist/cjs/extends.js +434 -0
- package/dist/cjs/fibonacci.js +1 -3
- package/dist/cjs/files.js +1 -3
- package/dist/cjs/function.js +114 -0
- package/dist/cjs/globals.js +30 -0
- package/dist/cjs/if.js +48 -0
- package/dist/cjs/index.js +38 -425
- package/dist/cjs/key.js +38 -0
- package/dist/cjs/keys.js +201 -0
- package/dist/cjs/load.js +5 -7
- package/dist/cjs/log.js +34 -0
- package/dist/cjs/metadata.js +310 -0
- package/dist/cjs/methods.js +599 -0
- package/dist/cjs/node.js +35 -0
- package/dist/cjs/object.js +634 -0
- package/dist/cjs/projectKeys.js +35 -0
- package/dist/cjs/props.js +282 -0
- package/dist/cjs/scaling.js +5 -169
- package/dist/cjs/scope.js +44 -0
- package/dist/cjs/sharedLibraries.js +146 -0
- package/dist/cjs/state.js +173 -0
- package/dist/cjs/string-extra.js +72 -0
- package/dist/cjs/string.js +183 -0
- package/dist/cjs/style.js +1 -3
- package/dist/cjs/tags.js +220 -0
- package/dist/cjs/triggerEvent.js +112 -0
- package/dist/cjs/types.js +74 -0
- package/dist/cjs/update.js +42 -0
- package/dist/esm/array.js +148 -0
- package/dist/esm/browser.js +14 -0
- package/dist/esm/cache.js +6 -0
- package/dist/esm/cdn.js +65 -0
- package/dist/esm/component.js +25 -0
- package/dist/esm/cookie.js +55 -0
- package/dist/esm/date.js +11 -0
- package/dist/esm/detectHeight.js +42 -0
- package/dist/esm/element.js +116 -0
- package/dist/esm/env.js +23 -0
- package/dist/esm/events.js +19 -0
- package/dist/esm/extends.js +414 -0
- package/dist/esm/fibonacci.js +10 -0
- package/dist/esm/files.js +4 -0
- package/dist/esm/function.js +94 -0
- package/dist/esm/globals.js +10 -0
- package/dist/esm/if.js +28 -0
- package/dist/esm/index.js +37 -0
- package/dist/esm/key.js +18 -0
- package/dist/esm/keys.js +181 -0
- package/dist/esm/load.js +151 -0
- package/dist/esm/log.js +14 -0
- package/dist/esm/metadata.js +290 -0
- package/dist/esm/methods.js +569 -0
- package/dist/esm/node.js +15 -0
- package/dist/esm/object.js +621 -0
- package/dist/esm/projectKeys.js +16 -0
- package/dist/esm/props.js +262 -0
- package/dist/esm/scaling.js +15 -0
- package/dist/esm/scope.js +24 -0
- package/dist/esm/sharedLibraries.js +126 -0
- package/dist/esm/state.js +163 -0
- package/dist/esm/string-extra.js +52 -0
- package/dist/esm/string.js +163 -0
- package/dist/esm/style.js +20 -0
- package/dist/esm/tags.js +200 -0
- package/dist/esm/triggerEvent.js +92 -0
- package/dist/esm/types.js +54 -0
- package/dist/esm/update.js +22 -0
- package/dist/iife/index.js +5818 -0
- package/element.js +148 -0
- package/env.js +15 -0
- package/events.js +19 -0
- package/extends.js +519 -0
- package/function.js +145 -0
- package/globals.js +8 -0
- package/if.js +30 -0
- package/index.js +41 -0
- package/key.js +20 -0
- package/keys.js +176 -0
- package/log.js +12 -0
- package/metadata.js +392 -0
- package/methods.js +636 -0
- package/node.js +37 -0
- package/object.js +803 -0
- package/package.json +38 -22
- package/projectKeys.js +30 -0
- package/props.js +327 -0
- package/{src/scaling.js → scaling.js} +1 -1
- package/scope.js +32 -0
- package/sharedLibraries.js +184 -0
- package/state.js +203 -0
- package/{src/index.js → string-extra.js} +11 -17
- package/string.js +206 -0
- package/tags.js +176 -0
- package/triggerEvent.js +102 -0
- package/types.js +55 -0
- package/update.js +27 -0
- package/dist/cjs/package.json +0 -4
- /package/{src/browser.js → browser.js} +0 -0
- /package/{src/date.js → date.js} +0 -0
- /package/{src/fibonacci.js → fibonacci.js} +0 -0
- /package/{src/files.js → files.js} +0 -0
- /package/{src/load.js → load.js} +0 -0
- /package/{src/style.js → style.js} +0 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
const stringIncludesAny = (str, characters) => {
|
|
2
|
+
for (const char of characters) {
|
|
3
|
+
if (str.includes(char)) {
|
|
4
|
+
return true;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
return false;
|
|
8
|
+
};
|
|
9
|
+
const trimStringFromSymbols = (str, characters) => {
|
|
10
|
+
const pattern = new RegExp(`[${characters.join("\\")}]`, "g");
|
|
11
|
+
return str.replace(pattern, "");
|
|
12
|
+
};
|
|
13
|
+
const brackRegex = {
|
|
14
|
+
2: /{{\s*((?:\.\.\/)*)([\w\d.]+)\s*(?:\|\s*([\w\d.]+))?\s*}}/g,
|
|
15
|
+
3: /{{{(\s*(?:\.\.\/)*)([\w\d.]+)\s*(?:\|\s*([\w\d.]+))?\s*}}}/g
|
|
16
|
+
};
|
|
17
|
+
const getNestedValue = (obj, path) => {
|
|
18
|
+
return path.split(".").reduce((acc, part) => {
|
|
19
|
+
return acc?.[part];
|
|
20
|
+
}, obj);
|
|
21
|
+
};
|
|
22
|
+
function replaceLiteralsWithObjectFields(str, state, options = {}) {
|
|
23
|
+
const { bracketsLength = 2 } = options;
|
|
24
|
+
const bracketPattern = bracketsLength === 3 ? "{{{" : "{{";
|
|
25
|
+
if (!str.includes(bracketPattern)) return str;
|
|
26
|
+
const reg = brackRegex[bracketsLength];
|
|
27
|
+
const obj = state || this.state || {};
|
|
28
|
+
const element = this;
|
|
29
|
+
return str.replace(reg, (_, parentPath, variable, filter) => {
|
|
30
|
+
const key = variable.trim();
|
|
31
|
+
if (filter) {
|
|
32
|
+
const ctx = element?.context;
|
|
33
|
+
const filterFn = ctx?.functions?.[filter] || ctx?.utils?.[filter] || ctx?.methods?.[filter] || ctx?.snippets?.[filter] || element?.[filter];
|
|
34
|
+
if (filterFn && typeof filterFn === "function") {
|
|
35
|
+
try {
|
|
36
|
+
return String(filterFn.call(element, key) ?? "");
|
|
37
|
+
} catch (e) {
|
|
38
|
+
return "";
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return "";
|
|
42
|
+
}
|
|
43
|
+
if (parentPath) {
|
|
44
|
+
const parentLevels = (parentPath.match(/\.\.\//g) || []).length;
|
|
45
|
+
let parentState = obj;
|
|
46
|
+
for (let i = 0; i < parentLevels; i++) {
|
|
47
|
+
if (!parentState || !parentState.parent) return "";
|
|
48
|
+
parentState = parentState.parent;
|
|
49
|
+
}
|
|
50
|
+
if (key === "parent") {
|
|
51
|
+
return String(parentState.value ?? "");
|
|
52
|
+
}
|
|
53
|
+
const value = getNestedValue(parentState, key);
|
|
54
|
+
return String(value ?? "");
|
|
55
|
+
} else {
|
|
56
|
+
const value = getNestedValue(obj, key);
|
|
57
|
+
if (value != null) return String(value);
|
|
58
|
+
const poly = element?.context?.polyglot;
|
|
59
|
+
if (poly?.translations) {
|
|
60
|
+
const lang = obj?.root?.lang || obj?.lang || element?.context?.state?.lang || poly.defaultLang || "en";
|
|
61
|
+
const langT = poly.translations[lang];
|
|
62
|
+
if (langT) {
|
|
63
|
+
const tValue = getNestedValue(langT, key);
|
|
64
|
+
if (tValue != null && typeof tValue !== "object") return String(tValue);
|
|
65
|
+
for (const section in langT) {
|
|
66
|
+
const sectionData = langT[section];
|
|
67
|
+
if (sectionData && typeof sectionData === "object" && !Array.isArray(sectionData)) {
|
|
68
|
+
const nested = getNestedValue(sectionData, key);
|
|
69
|
+
if (nested != null && typeof nested !== "object") return String(nested);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const topValue = getNestedValue(poly.translations, key);
|
|
74
|
+
if (topValue != null && typeof topValue !== "object") return String(topValue);
|
|
75
|
+
}
|
|
76
|
+
return "";
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
const lowercaseFirstLetter = (inputString) => {
|
|
81
|
+
return `${inputString.charAt(0).toLowerCase()}${inputString.slice(1)}`;
|
|
82
|
+
};
|
|
83
|
+
const findKeyPosition = (str, key) => {
|
|
84
|
+
const lines = str.split("\n");
|
|
85
|
+
let startLineNumber = -1;
|
|
86
|
+
let endLineNumber = -1;
|
|
87
|
+
let startColumn = -1;
|
|
88
|
+
let endColumn = -1;
|
|
89
|
+
const keyPattern = new RegExp(`\\b${key}\\b\\s*:\\s*`);
|
|
90
|
+
let braceCount = 0;
|
|
91
|
+
let foundKey = false;
|
|
92
|
+
for (let i = 0; i < lines.length; i++) {
|
|
93
|
+
if (keyPattern.test(lines[i]) && !foundKey) {
|
|
94
|
+
foundKey = true;
|
|
95
|
+
startLineNumber = i + 1;
|
|
96
|
+
startColumn = lines[i].indexOf(key) + 1;
|
|
97
|
+
if (lines[i].includes("{}")) {
|
|
98
|
+
endLineNumber = startLineNumber;
|
|
99
|
+
endColumn = lines[i].indexOf("{}") + 3;
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
const line = lines[i].slice(startColumn + key.length);
|
|
103
|
+
if (line.includes("{") || line.includes("[")) {
|
|
104
|
+
braceCount = 1;
|
|
105
|
+
} else {
|
|
106
|
+
endLineNumber = i + 1;
|
|
107
|
+
endColumn = lines[i].length + 1;
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
} else if (foundKey) {
|
|
111
|
+
braceCount += (lines[i].match(/{/g) || []).length;
|
|
112
|
+
braceCount += (lines[i].match(/\[/g) || []).length;
|
|
113
|
+
braceCount -= (lines[i].match(/}/g) || []).length;
|
|
114
|
+
braceCount -= (lines[i].match(/]/g) || []).length;
|
|
115
|
+
if (braceCount === 0) {
|
|
116
|
+
endLineNumber = i + 1;
|
|
117
|
+
endColumn = lines[i].lastIndexOf("}") !== -1 ? lines[i].lastIndexOf("}") + 2 : lines[i].length + 1;
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
startColumn,
|
|
124
|
+
endColumn,
|
|
125
|
+
startLineNumber,
|
|
126
|
+
endLineNumber
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
const RE_OCTAL = /\\([0-7]{1,3})/g;
|
|
130
|
+
const replaceOctalEscapeSequences = (str) => {
|
|
131
|
+
return str.replace(RE_OCTAL, (_, p1) => String.fromCharCode(parseInt(p1, 8)));
|
|
132
|
+
};
|
|
133
|
+
const encodeNewlines = (str) => {
|
|
134
|
+
return str.replace(/\n/g, "/////n").replace(/`/g, "/////tilde").replace(/\$/g, "/////dlrsgn");
|
|
135
|
+
};
|
|
136
|
+
const decodeNewlines = (encodedStr) => {
|
|
137
|
+
return encodedStr.replace(/\/\/\/\/\/n/g, "\n").replace(/\/\/\/\/\/tilde/g, "`").replace(/\/\/\/\/\/dlrsgn/g, "$");
|
|
138
|
+
};
|
|
139
|
+
const RE_NON_ALNUM = /[^a-zA-Z0-9\s]/g;
|
|
140
|
+
const customEncodeURIComponent = (str) => {
|
|
141
|
+
return str.replace(
|
|
142
|
+
RE_NON_ALNUM,
|
|
143
|
+
(char) => "%" + char.charCodeAt(0).toString(16).toUpperCase()
|
|
144
|
+
);
|
|
145
|
+
};
|
|
146
|
+
const customDecodeURIComponent = (encodedStr) => {
|
|
147
|
+
return encodedStr.replace(
|
|
148
|
+
/%[0-9A-Fa-f]{2}/g,
|
|
149
|
+
(match) => String.fromCharCode(parseInt(match.slice(1), 16))
|
|
150
|
+
);
|
|
151
|
+
};
|
|
152
|
+
export {
|
|
153
|
+
customDecodeURIComponent,
|
|
154
|
+
customEncodeURIComponent,
|
|
155
|
+
decodeNewlines,
|
|
156
|
+
encodeNewlines,
|
|
157
|
+
findKeyPosition,
|
|
158
|
+
lowercaseFirstLetter,
|
|
159
|
+
replaceLiteralsWithObjectFields,
|
|
160
|
+
replaceOctalEscapeSequences,
|
|
161
|
+
stringIncludesAny,
|
|
162
|
+
trimStringFromSymbols
|
|
163
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const getEmotionStylesheet = () => {
|
|
2
|
+
const stylesheet = document.styleSheets[0];
|
|
3
|
+
let str = "";
|
|
4
|
+
if (stylesheet) {
|
|
5
|
+
try {
|
|
6
|
+
const cssRules = stylesheet.cssRules || stylesheet.rules;
|
|
7
|
+
for (let i = 0; i < cssRules.length; i++) {
|
|
8
|
+
str += cssRules[i].cssText;
|
|
9
|
+
}
|
|
10
|
+
} catch (error) {
|
|
11
|
+
console.error("Unable to access CSS rules. This may be due to CORS restrictions:", error);
|
|
12
|
+
}
|
|
13
|
+
} else {
|
|
14
|
+
console.log("No stylesheets found in document.styleSheets[0].");
|
|
15
|
+
}
|
|
16
|
+
return str;
|
|
17
|
+
};
|
|
18
|
+
export {
|
|
19
|
+
getEmotionStylesheet
|
|
20
|
+
};
|
package/dist/esm/tags.js
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
const HTML_TAGS = {
|
|
2
|
+
root: ["body", "html"],
|
|
3
|
+
head: ["title", "base", "meta", "style", "noscript", "script"],
|
|
4
|
+
body: /* @__PURE__ */ new Set([
|
|
5
|
+
"string",
|
|
6
|
+
"style",
|
|
7
|
+
"fragment",
|
|
8
|
+
"a",
|
|
9
|
+
"abbr",
|
|
10
|
+
"acronym",
|
|
11
|
+
"address",
|
|
12
|
+
"applet",
|
|
13
|
+
"area",
|
|
14
|
+
"article",
|
|
15
|
+
"aside",
|
|
16
|
+
"audio",
|
|
17
|
+
"b",
|
|
18
|
+
"basefont",
|
|
19
|
+
"bdi",
|
|
20
|
+
"bdo",
|
|
21
|
+
"big",
|
|
22
|
+
"blockquote",
|
|
23
|
+
"br",
|
|
24
|
+
"button",
|
|
25
|
+
"canvas",
|
|
26
|
+
"caption",
|
|
27
|
+
"center",
|
|
28
|
+
"cite",
|
|
29
|
+
"code",
|
|
30
|
+
"search",
|
|
31
|
+
"col",
|
|
32
|
+
"colgroup",
|
|
33
|
+
"data",
|
|
34
|
+
"datalist",
|
|
35
|
+
"dd",
|
|
36
|
+
"del",
|
|
37
|
+
"details",
|
|
38
|
+
"dfn",
|
|
39
|
+
"dialog",
|
|
40
|
+
"dir",
|
|
41
|
+
"div",
|
|
42
|
+
"dl",
|
|
43
|
+
"dt",
|
|
44
|
+
"em",
|
|
45
|
+
"embed",
|
|
46
|
+
"fieldset",
|
|
47
|
+
"figcaption",
|
|
48
|
+
"figure",
|
|
49
|
+
"font",
|
|
50
|
+
"footer",
|
|
51
|
+
"form",
|
|
52
|
+
"frame",
|
|
53
|
+
"frameset",
|
|
54
|
+
"h1",
|
|
55
|
+
"h2",
|
|
56
|
+
"h3",
|
|
57
|
+
"h4",
|
|
58
|
+
"h5",
|
|
59
|
+
"h6",
|
|
60
|
+
"head",
|
|
61
|
+
"header",
|
|
62
|
+
"hr",
|
|
63
|
+
"i",
|
|
64
|
+
"iframe",
|
|
65
|
+
"img",
|
|
66
|
+
"input",
|
|
67
|
+
"ins",
|
|
68
|
+
"kbd",
|
|
69
|
+
"label",
|
|
70
|
+
"legend",
|
|
71
|
+
"li",
|
|
72
|
+
"link",
|
|
73
|
+
"main",
|
|
74
|
+
"map",
|
|
75
|
+
"mark",
|
|
76
|
+
"meter",
|
|
77
|
+
"nav",
|
|
78
|
+
"noframes",
|
|
79
|
+
"noscript",
|
|
80
|
+
"object",
|
|
81
|
+
"ol",
|
|
82
|
+
"optgroup",
|
|
83
|
+
"option",
|
|
84
|
+
"output",
|
|
85
|
+
"p",
|
|
86
|
+
"param",
|
|
87
|
+
"picture",
|
|
88
|
+
"pre",
|
|
89
|
+
"progress",
|
|
90
|
+
"hgroup",
|
|
91
|
+
"q",
|
|
92
|
+
"rp",
|
|
93
|
+
"rt",
|
|
94
|
+
"ruby",
|
|
95
|
+
"s",
|
|
96
|
+
"samp",
|
|
97
|
+
"script",
|
|
98
|
+
"section",
|
|
99
|
+
"select",
|
|
100
|
+
"small",
|
|
101
|
+
"source",
|
|
102
|
+
"span",
|
|
103
|
+
"strike",
|
|
104
|
+
"strong",
|
|
105
|
+
"sub",
|
|
106
|
+
"summary",
|
|
107
|
+
"sup",
|
|
108
|
+
"table",
|
|
109
|
+
"tbody",
|
|
110
|
+
"td",
|
|
111
|
+
"template",
|
|
112
|
+
"hgroup",
|
|
113
|
+
"textarea",
|
|
114
|
+
"tfoot",
|
|
115
|
+
"th",
|
|
116
|
+
"thead",
|
|
117
|
+
"time",
|
|
118
|
+
"tr",
|
|
119
|
+
"track",
|
|
120
|
+
"tt",
|
|
121
|
+
"u",
|
|
122
|
+
"ul",
|
|
123
|
+
"var",
|
|
124
|
+
"video",
|
|
125
|
+
"wbr",
|
|
126
|
+
// SVG
|
|
127
|
+
"svg",
|
|
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
|
+
])
|
|
160
|
+
};
|
|
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);
|
|
196
|
+
export {
|
|
197
|
+
HTML_TAGS,
|
|
198
|
+
SVG_TAGS,
|
|
199
|
+
isValidHtmlTag
|
|
200
|
+
};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { isFunction } from "./types.js";
|
|
2
|
+
import { resolveHandler, runPluginHook } from "./function.js";
|
|
3
|
+
const getOnOrPropsEvent = (param, element) => {
|
|
4
|
+
const propKey = "on" + param.charAt(0).toUpperCase() + param.slice(1);
|
|
5
|
+
return element[propKey];
|
|
6
|
+
};
|
|
7
|
+
const applyEvent = (param, element, state, context, options) => {
|
|
8
|
+
param = resolveHandler(param, element);
|
|
9
|
+
if (!isFunction(param)) return;
|
|
10
|
+
try {
|
|
11
|
+
const result = param.call(
|
|
12
|
+
element,
|
|
13
|
+
element,
|
|
14
|
+
state || element.state,
|
|
15
|
+
context || element.context,
|
|
16
|
+
options
|
|
17
|
+
);
|
|
18
|
+
if (result && typeof result.then === "function") {
|
|
19
|
+
result.catch((err) => {
|
|
20
|
+
element.error = err;
|
|
21
|
+
if (err instanceof ReferenceError) console.warn("[DOMQL] Async event warning:", err.message);
|
|
22
|
+
else console.error("[DOMQL] Async event error:", err);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
} catch (err) {
|
|
27
|
+
element.error = err;
|
|
28
|
+
if (err instanceof ReferenceError) {
|
|
29
|
+
console.warn("[DOMQL] Event handler warning:", err.message);
|
|
30
|
+
} else {
|
|
31
|
+
console.error("[DOMQL] Event handler error:", err);
|
|
32
|
+
}
|
|
33
|
+
if (element.context?.strictMode) throw err;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const triggerEventOn = (param, element, options) => {
|
|
37
|
+
if (!element) {
|
|
38
|
+
throw new Error("Element is required");
|
|
39
|
+
}
|
|
40
|
+
runPluginHook(param, element, options);
|
|
41
|
+
const appliedFunction = getOnOrPropsEvent(param, element);
|
|
42
|
+
if (appliedFunction) {
|
|
43
|
+
const { state, context } = element;
|
|
44
|
+
return applyEvent(appliedFunction, element, state, context, options);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const applyEventUpdate = (param, updatedObj, element, state, context, options) => {
|
|
48
|
+
param = resolveHandler(param, element);
|
|
49
|
+
if (!isFunction(param)) return;
|
|
50
|
+
try {
|
|
51
|
+
const result = param.call(
|
|
52
|
+
element,
|
|
53
|
+
updatedObj,
|
|
54
|
+
element,
|
|
55
|
+
state || element.state,
|
|
56
|
+
context || element.context,
|
|
57
|
+
options
|
|
58
|
+
);
|
|
59
|
+
if (result && typeof result.then === "function") {
|
|
60
|
+
result.catch((err) => {
|
|
61
|
+
element.error = err;
|
|
62
|
+
console.error("[DOMQL] Async event update error:", err);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
} catch (err) {
|
|
67
|
+
element.error = err;
|
|
68
|
+
console.error("[DOMQL] Event update error:", err);
|
|
69
|
+
if (element.context?.strictMode) throw err;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
const triggerEventOnUpdate = (param, updatedObj, element, options) => {
|
|
73
|
+
runPluginHook(param, element, updatedObj, options);
|
|
74
|
+
const appliedFunction = getOnOrPropsEvent(param, element);
|
|
75
|
+
if (appliedFunction) {
|
|
76
|
+
const { state, context } = element;
|
|
77
|
+
return applyEventUpdate(
|
|
78
|
+
appliedFunction,
|
|
79
|
+
updatedObj,
|
|
80
|
+
element,
|
|
81
|
+
state,
|
|
82
|
+
context,
|
|
83
|
+
options
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
export {
|
|
88
|
+
applyEvent,
|
|
89
|
+
applyEventUpdate,
|
|
90
|
+
triggerEventOn,
|
|
91
|
+
triggerEventOnUpdate
|
|
92
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { isHtmlElement, isNode } from "./node.js";
|
|
2
|
+
const isObject = (arg) => {
|
|
3
|
+
if (arg === null) return false;
|
|
4
|
+
return typeof arg === "object" && arg.constructor === Object;
|
|
5
|
+
};
|
|
6
|
+
const isString = (arg) => typeof arg === "string";
|
|
7
|
+
const isNumber = (arg) => typeof arg === "number";
|
|
8
|
+
const isFunction = (arg) => typeof arg === "function";
|
|
9
|
+
const isBoolean = (arg) => arg === true || arg === false;
|
|
10
|
+
const isNull = (arg) => arg === null;
|
|
11
|
+
const isArray = (arg) => Array.isArray(arg);
|
|
12
|
+
const isDate = (d) => d instanceof Date;
|
|
13
|
+
const isObjectLike = (arg) => {
|
|
14
|
+
if (arg === null) return false;
|
|
15
|
+
return typeof arg === "object";
|
|
16
|
+
};
|
|
17
|
+
const isDefined = (arg) => arg !== void 0;
|
|
18
|
+
const isUndefined = (arg) => arg === void 0;
|
|
19
|
+
const TYPES = {
|
|
20
|
+
boolean: isBoolean,
|
|
21
|
+
array: isArray,
|
|
22
|
+
object: isObject,
|
|
23
|
+
string: isString,
|
|
24
|
+
date: isDate,
|
|
25
|
+
number: isNumber,
|
|
26
|
+
null: isNull,
|
|
27
|
+
function: isFunction,
|
|
28
|
+
objectLike: isObjectLike,
|
|
29
|
+
node: isNode,
|
|
30
|
+
htmlElement: isHtmlElement,
|
|
31
|
+
defined: isDefined
|
|
32
|
+
};
|
|
33
|
+
const is = (arg) => {
|
|
34
|
+
return (...args) => args.some((val) => TYPES[val](arg));
|
|
35
|
+
};
|
|
36
|
+
const isNot = (arg) => {
|
|
37
|
+
return (...args) => !args.some((val) => TYPES[val](arg));
|
|
38
|
+
};
|
|
39
|
+
export {
|
|
40
|
+
TYPES,
|
|
41
|
+
is,
|
|
42
|
+
isArray,
|
|
43
|
+
isBoolean,
|
|
44
|
+
isDate,
|
|
45
|
+
isDefined,
|
|
46
|
+
isFunction,
|
|
47
|
+
isNot,
|
|
48
|
+
isNull,
|
|
49
|
+
isNumber,
|
|
50
|
+
isObject,
|
|
51
|
+
isObjectLike,
|
|
52
|
+
isString,
|
|
53
|
+
isUndefined
|
|
54
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createSnapshotId } from "./key.js";
|
|
2
|
+
const snapshot = {
|
|
3
|
+
snapshotId: createSnapshotId
|
|
4
|
+
};
|
|
5
|
+
const captureSnapshot = (element, options) => {
|
|
6
|
+
const ref = element.__ref;
|
|
7
|
+
const { currentSnapshot, calleeElement } = options;
|
|
8
|
+
const isCallee = calleeElement === element;
|
|
9
|
+
if (!calleeElement || isCallee) {
|
|
10
|
+
const createdStanpshot = snapshot.snapshotId();
|
|
11
|
+
ref.__currentSnapshot = createdStanpshot;
|
|
12
|
+
return [createdStanpshot, element];
|
|
13
|
+
}
|
|
14
|
+
const snapshotOnCallee = calleeElement.__ref.__currentSnapshot;
|
|
15
|
+
if (currentSnapshot < snapshotOnCallee) {
|
|
16
|
+
return [snapshotOnCallee, calleeElement, true];
|
|
17
|
+
}
|
|
18
|
+
return [snapshotOnCallee, calleeElement];
|
|
19
|
+
};
|
|
20
|
+
export {
|
|
21
|
+
captureSnapshot
|
|
22
|
+
};
|