@domql/utils 2.5.200 → 3.0.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/array.js +26 -13
- package/cache.js +4 -0
- package/component.js +10 -227
- package/cookie.js +27 -24
- package/dist/cjs/array.js +27 -10
- package/dist/cjs/cache.js +26 -0
- package/dist/cjs/component.js +15 -206
- package/dist/cjs/cookie.js +14 -14
- package/dist/cjs/element.js +137 -0
- package/dist/cjs/events.js +37 -0
- package/dist/cjs/extends.js +351 -0
- package/dist/cjs/if.js +30 -0
- package/dist/cjs/index.js +10 -0
- package/dist/cjs/key.js +5 -0
- package/dist/cjs/keys.js +178 -0
- package/dist/cjs/methods.js +305 -0
- package/dist/cjs/object.js +78 -191
- package/dist/cjs/props.js +220 -0
- package/dist/cjs/scope.js +28 -0
- package/dist/cjs/state.js +175 -0
- package/dist/cjs/string.js +27 -15
- package/dist/cjs/update.js +42 -0
- package/dist/esm/array.js +27 -10
- package/dist/esm/cache.js +6 -0
- package/dist/esm/component.js +16 -225
- package/dist/esm/cookie.js +14 -14
- package/dist/esm/element.js +135 -0
- package/dist/esm/events.js +17 -0
- package/dist/esm/extends.js +349 -0
- package/dist/esm/if.js +10 -0
- package/dist/esm/index.js +10 -0
- package/dist/esm/key.js +5 -0
- package/dist/esm/keys.js +158 -0
- package/dist/esm/methods.js +285 -0
- package/dist/esm/object.js +79 -193
- package/dist/esm/props.js +216 -0
- package/dist/esm/scope.js +8 -0
- package/dist/esm/state.js +185 -0
- package/dist/esm/string.js +27 -15
- package/dist/esm/update.js +22 -0
- package/element.js +149 -0
- package/env.js +5 -2
- package/events.js +17 -0
- package/extends.js +425 -0
- package/if.js +14 -0
- package/index.js +10 -0
- package/key.js +6 -0
- package/keys.js +157 -0
- package/log.js +4 -1
- package/methods.js +315 -0
- package/node.js +21 -13
- package/object.js +122 -236
- package/package.json +3 -3
- package/props.js +249 -0
- package/scope.js +8 -0
- package/state.js +208 -0
- package/string.js +66 -30
- package/update.js +27 -0
package/dist/cjs/object.js
CHANGED
|
@@ -24,18 +24,12 @@ __export(object_exports, {
|
|
|
24
24
|
deepClone: () => deepClone,
|
|
25
25
|
deepContains: () => deepContains,
|
|
26
26
|
deepDestringify: () => deepDestringify,
|
|
27
|
-
deepDiff: () => deepDiff,
|
|
28
27
|
deepMerge: () => deepMerge,
|
|
29
28
|
deepStringify: () => deepStringify,
|
|
30
|
-
deepStringifyWithMaxDepth: () => deepStringifyWithMaxDepth,
|
|
31
|
-
detachFunctionsFromObject: () => detachFunctionsFromObject,
|
|
32
29
|
detectInfiniteLoop: () => detectInfiniteLoop,
|
|
33
|
-
diff: () => diff,
|
|
34
|
-
diffArrays: () => diffArrays,
|
|
35
|
-
diffObjects: () => diffObjects,
|
|
36
30
|
excludeKeysFromObject: () => excludeKeysFromObject,
|
|
37
31
|
exec: () => exec,
|
|
38
|
-
|
|
32
|
+
execPromise: () => execPromise,
|
|
39
33
|
getInObjectByPath: () => getInObjectByPath,
|
|
40
34
|
hasFunction: () => hasFunction,
|
|
41
35
|
hasOwnProperty: () => hasOwnProperty,
|
|
@@ -46,8 +40,6 @@ __export(object_exports, {
|
|
|
46
40
|
makeObjectWithoutPrototype: () => makeObjectWithoutPrototype,
|
|
47
41
|
map: () => map,
|
|
48
42
|
merge: () => merge,
|
|
49
|
-
mergeArrayExclude: () => mergeArrayExclude,
|
|
50
|
-
mergeIfExisted: () => mergeIfExisted,
|
|
51
43
|
objectToString: () => objectToString,
|
|
52
44
|
overwrite: () => overwrite,
|
|
53
45
|
overwriteDeep: () => overwriteDeep,
|
|
@@ -63,6 +55,7 @@ var import_types = require("./types.js");
|
|
|
63
55
|
var import_array = require("./array.js");
|
|
64
56
|
var import_string = require("./string.js");
|
|
65
57
|
var import_node = require("./node.js");
|
|
58
|
+
var import_keys = require("./keys.js");
|
|
66
59
|
const ENV = "development";
|
|
67
60
|
const exec = (param, element, state, context) => {
|
|
68
61
|
if ((0, import_types.isFunction)(param)) {
|
|
@@ -75,6 +68,17 @@ const exec = (param, element, state, context) => {
|
|
|
75
68
|
}
|
|
76
69
|
return param;
|
|
77
70
|
};
|
|
71
|
+
const execPromise = async (param, element, state, context) => {
|
|
72
|
+
if ((0, import_types.isFunction)(param)) {
|
|
73
|
+
return await param.call(
|
|
74
|
+
element,
|
|
75
|
+
element,
|
|
76
|
+
state || element.state,
|
|
77
|
+
context || element.context
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
return param;
|
|
81
|
+
};
|
|
78
82
|
const map = (obj, extention, element) => {
|
|
79
83
|
for (const e in extention) {
|
|
80
84
|
obj[e] = exec(extention[e], element);
|
|
@@ -83,7 +87,9 @@ const map = (obj, extention, element) => {
|
|
|
83
87
|
const merge = (element, obj, excludeFrom = []) => {
|
|
84
88
|
for (const e in obj) {
|
|
85
89
|
const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, e);
|
|
86
|
-
if (!hasOwnProperty2 || excludeFrom.includes(e) || e.startsWith("__"))
|
|
90
|
+
if (!hasOwnProperty2 || excludeFrom.includes(e) || e.startsWith("__")) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
87
93
|
const elementProp = element[e];
|
|
88
94
|
const objProp = obj[e];
|
|
89
95
|
if (elementProp === void 0) {
|
|
@@ -92,10 +98,12 @@ const merge = (element, obj, excludeFrom = []) => {
|
|
|
92
98
|
}
|
|
93
99
|
return element;
|
|
94
100
|
};
|
|
95
|
-
const deepMerge = (element, extend, excludeFrom =
|
|
101
|
+
const deepMerge = (element, extend, excludeFrom = import_keys.METHODS_EXL) => {
|
|
96
102
|
for (const e in extend) {
|
|
97
103
|
const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(extend, e);
|
|
98
|
-
if (!hasOwnProperty2 || excludeFrom.includes(e) || e.startsWith("__"))
|
|
104
|
+
if (!hasOwnProperty2 || excludeFrom.includes(e) || e.startsWith("__")) {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
99
107
|
const elementProp = element[e];
|
|
100
108
|
const extendProp = extend[e];
|
|
101
109
|
if ((0, import_types.isObjectLike)(elementProp) && (0, import_types.isObjectLike)(extendProp)) {
|
|
@@ -110,14 +118,13 @@ const clone = (obj, excludeFrom = []) => {
|
|
|
110
118
|
const o = {};
|
|
111
119
|
for (const prop in obj) {
|
|
112
120
|
const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, prop);
|
|
113
|
-
if (!hasOwnProperty2 || excludeFrom.includes(prop) || prop.startsWith("__"))
|
|
121
|
+
if (!hasOwnProperty2 || excludeFrom.includes(prop) || prop.startsWith("__")) {
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
114
124
|
o[prop] = obj[prop];
|
|
115
125
|
}
|
|
116
126
|
return o;
|
|
117
127
|
};
|
|
118
|
-
const mergeArrayExclude = (arr, exclude = []) => {
|
|
119
|
-
return arr.reduce((acc, curr) => deepMerge(acc, deepClone(curr, { exclude })), {});
|
|
120
|
-
};
|
|
121
128
|
const deepClone = (obj, options = {}) => {
|
|
122
129
|
const {
|
|
123
130
|
exclude = [],
|
|
@@ -125,7 +132,7 @@ const deepClone = (obj, options = {}) => {
|
|
|
125
132
|
cleanNull = false,
|
|
126
133
|
window: targetWindow,
|
|
127
134
|
visited = /* @__PURE__ */ new WeakMap(),
|
|
128
|
-
|
|
135
|
+
handleExtends = false
|
|
129
136
|
} = options;
|
|
130
137
|
if (!(0, import_types.isObjectLike)(obj) || (0, import_node.isDOMNode)(obj)) {
|
|
131
138
|
return obj;
|
|
@@ -137,15 +144,19 @@ const deepClone = (obj, options = {}) => {
|
|
|
137
144
|
visited.set(obj, clone2);
|
|
138
145
|
for (const key in obj) {
|
|
139
146
|
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
|
|
140
|
-
if (exclude.includes(key) || key.startsWith("__") || key === "__proto__")
|
|
147
|
+
if (exclude.includes(key) || key.startsWith("__") || key === "__proto__") {
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
141
150
|
const value = obj[key];
|
|
142
|
-
if (cleanUndefined && (0, import_types.isUndefined)(value) || cleanNull && (0, import_types.isNull)(value))
|
|
151
|
+
if (cleanUndefined && (0, import_types.isUndefined)(value) || cleanNull && (0, import_types.isNull)(value)) {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
143
154
|
if ((0, import_node.isDOMNode)(value)) {
|
|
144
155
|
clone2[key] = value;
|
|
145
156
|
continue;
|
|
146
157
|
}
|
|
147
|
-
if (
|
|
148
|
-
clone2[key] = (0, import_array.
|
|
158
|
+
if (handleExtends && key === "extends" && (0, import_types.isArray)(value)) {
|
|
159
|
+
clone2[key] = (0, import_array.unstackArrayOfObjects)(value, exclude);
|
|
149
160
|
continue;
|
|
150
161
|
}
|
|
151
162
|
if ((0, import_types.isFunction)(value) && targetWindow) {
|
|
@@ -166,7 +177,11 @@ const deepClone = (obj, options = {}) => {
|
|
|
166
177
|
const deepStringify = (obj, stringified = {}) => {
|
|
167
178
|
var _a, _b;
|
|
168
179
|
if (obj.node || obj.__ref || obj.parent || obj.__element || obj.parse) {
|
|
169
|
-
|
|
180
|
+
;
|
|
181
|
+
(obj.__element || ((_a = obj.parent) == null ? void 0 : _a.__element)).warn(
|
|
182
|
+
"Trying to clone element or state at",
|
|
183
|
+
obj
|
|
184
|
+
);
|
|
170
185
|
obj = (_b = obj.parse) == null ? void 0 : _b.call(obj);
|
|
171
186
|
}
|
|
172
187
|
for (const prop in obj) {
|
|
@@ -194,39 +209,6 @@ const deepStringify = (obj, stringified = {}) => {
|
|
|
194
209
|
}
|
|
195
210
|
return stringified;
|
|
196
211
|
};
|
|
197
|
-
const MAX_DEPTH = 100;
|
|
198
|
-
const deepStringifyWithMaxDepth = (obj, stringified = {}, depth = 0, path = "") => {
|
|
199
|
-
if (depth > MAX_DEPTH) {
|
|
200
|
-
console.warn(`Maximum depth exceeded at path: ${path}. Possible circular reference.`);
|
|
201
|
-
return "[MAX_DEPTH_EXCEEDED]";
|
|
202
|
-
}
|
|
203
|
-
for (const prop in obj) {
|
|
204
|
-
const currentPath = path ? `${path}.${prop}` : prop;
|
|
205
|
-
const objProp = obj[prop];
|
|
206
|
-
if ((0, import_types.isFunction)(objProp)) {
|
|
207
|
-
stringified[prop] = objProp.toString();
|
|
208
|
-
} else if ((0, import_types.isObject)(objProp)) {
|
|
209
|
-
stringified[prop] = {};
|
|
210
|
-
deepStringifyWithMaxDepth(objProp, stringified[prop], depth + 1, currentPath);
|
|
211
|
-
} else if ((0, import_types.isArray)(objProp)) {
|
|
212
|
-
stringified[prop] = [];
|
|
213
|
-
objProp.forEach((v, i) => {
|
|
214
|
-
const itemPath = `${currentPath}[${i}]`;
|
|
215
|
-
if ((0, import_types.isObject)(v)) {
|
|
216
|
-
stringified[prop][i] = {};
|
|
217
|
-
deepStringifyWithMaxDepth(v, stringified[prop][i], depth + 1, itemPath);
|
|
218
|
-
} else if ((0, import_types.isFunction)(v)) {
|
|
219
|
-
stringified[prop][i] = v.toString();
|
|
220
|
-
} else {
|
|
221
|
-
stringified[prop][i] = v;
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
} else {
|
|
225
|
-
stringified[prop] = objProp;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
return stringified;
|
|
229
|
-
};
|
|
230
212
|
const objectToString = (obj = {}, indent = 0) => {
|
|
231
213
|
if (obj === null || typeof obj !== "object") {
|
|
232
214
|
return String(obj);
|
|
@@ -237,7 +219,22 @@ const objectToString = (obj = {}, indent = 0) => {
|
|
|
237
219
|
const spaces = " ".repeat(indent);
|
|
238
220
|
let str = "{\n";
|
|
239
221
|
for (const [key, value] of Object.entries(obj)) {
|
|
240
|
-
const keyNotAllowdChars = (0, import_string.stringIncludesAny)(key, [
|
|
222
|
+
const keyNotAllowdChars = (0, import_string.stringIncludesAny)(key, [
|
|
223
|
+
"&",
|
|
224
|
+
"*",
|
|
225
|
+
"-",
|
|
226
|
+
":",
|
|
227
|
+
"%",
|
|
228
|
+
"{",
|
|
229
|
+
"}",
|
|
230
|
+
">",
|
|
231
|
+
"<",
|
|
232
|
+
"@",
|
|
233
|
+
".",
|
|
234
|
+
"/",
|
|
235
|
+
"!",
|
|
236
|
+
" "
|
|
237
|
+
]);
|
|
241
238
|
const stringedKey = keyNotAllowdChars ? `'${key}'` : key;
|
|
242
239
|
str += `${spaces} ${stringedKey}: `;
|
|
243
240
|
if ((0, import_types.isArray)(value)) {
|
|
@@ -267,30 +264,6 @@ const objectToString = (obj = {}, indent = 0) => {
|
|
|
267
264
|
str += `${spaces}}`;
|
|
268
265
|
return str;
|
|
269
266
|
};
|
|
270
|
-
const detachFunctionsFromObject = (obj, detached = {}) => {
|
|
271
|
-
for (const prop in obj) {
|
|
272
|
-
const objProp = obj[prop];
|
|
273
|
-
if ((0, import_types.isFunction)(objProp)) continue;
|
|
274
|
-
else if ((0, import_types.isObject)(objProp)) {
|
|
275
|
-
detached[prop] = {};
|
|
276
|
-
deepStringify(objProp, detached[prop]);
|
|
277
|
-
} else if ((0, import_types.isArray)(objProp)) {
|
|
278
|
-
detached[prop] = [];
|
|
279
|
-
objProp.forEach((v, i) => {
|
|
280
|
-
if ((0, import_types.isFunction)(v)) return;
|
|
281
|
-
if ((0, import_types.isObject)(v)) {
|
|
282
|
-
detached[prop][i] = {};
|
|
283
|
-
detachFunctionsFromObject(v, detached[prop][i]);
|
|
284
|
-
} else {
|
|
285
|
-
detached[prop][i] = v;
|
|
286
|
-
}
|
|
287
|
-
});
|
|
288
|
-
} else {
|
|
289
|
-
detached[prop] = objProp;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
return detached;
|
|
293
|
-
};
|
|
294
267
|
const hasFunction = (str) => {
|
|
295
268
|
if (!str) return false;
|
|
296
269
|
const trimmed = str.trim().replace(/\n\s*/g, " ").trim();
|
|
@@ -362,93 +335,18 @@ const stringToObject = (str, opts = { verbose: true }) => {
|
|
|
362
335
|
if (opts.verbose) console.warn(e);
|
|
363
336
|
}
|
|
364
337
|
};
|
|
365
|
-
const diffObjects = (original, objToDiff, cache) => {
|
|
366
|
-
for (const e in objToDiff) {
|
|
367
|
-
if (e === "ref") continue;
|
|
368
|
-
const originalProp = original[e];
|
|
369
|
-
const objToDiffProp = objToDiff[e];
|
|
370
|
-
if ((0, import_types.isObject)(originalProp) && (0, import_types.isObject)(objToDiffProp)) {
|
|
371
|
-
cache[e] = {};
|
|
372
|
-
diff(originalProp, objToDiffProp, cache[e]);
|
|
373
|
-
} else if (objToDiffProp !== void 0) {
|
|
374
|
-
cache[e] = objToDiffProp;
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
return cache;
|
|
378
|
-
};
|
|
379
|
-
const diffArrays = (original, objToDiff, cache) => {
|
|
380
|
-
if (original.length !== objToDiff.length) {
|
|
381
|
-
cache = objToDiff;
|
|
382
|
-
} else {
|
|
383
|
-
const diffArr = [];
|
|
384
|
-
for (let i = 0; i < original.length; i++) {
|
|
385
|
-
const diffObj = diff(original[i], objToDiff[i]);
|
|
386
|
-
if (Object.keys(diffObj).length > 0) {
|
|
387
|
-
diffArr.push(diffObj);
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
if (diffArr.length > 0) {
|
|
391
|
-
cache = diffArr;
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
return cache;
|
|
395
|
-
};
|
|
396
|
-
const diff = (original, objToDiff, cache = {}) => {
|
|
397
|
-
if ((0, import_types.isArray)(original) && (0, import_types.isArray)(objToDiff)) {
|
|
398
|
-
cache = [];
|
|
399
|
-
diffArrays(original, objToDiff, cache);
|
|
400
|
-
} else {
|
|
401
|
-
diffObjects(original, objToDiff, cache);
|
|
402
|
-
}
|
|
403
|
-
return cache;
|
|
404
|
-
};
|
|
405
338
|
const hasOwnProperty = (o, ...args) => Object.prototype.hasOwnProperty.call(o, ...args);
|
|
406
339
|
const isEmpty = (o) => Object.keys(o).length === 0;
|
|
407
340
|
const isEmptyObject = (o) => (0, import_types.isObject)(o) && isEmpty(o);
|
|
408
341
|
const makeObjectWithoutPrototype = () => /* @__PURE__ */ Object.create(null);
|
|
409
|
-
const deepDiff = (lhs, rhs) => {
|
|
410
|
-
if (lhs === rhs) return {};
|
|
411
|
-
if (!(0, import_types.isObjectLike)(lhs) || !(0, import_types.isObjectLike)(rhs)) return rhs;
|
|
412
|
-
const deletedValues = Object.keys(lhs).reduce((acc, key) => {
|
|
413
|
-
if (!hasOwnProperty(rhs, key)) {
|
|
414
|
-
acc[key] = void 0;
|
|
415
|
-
}
|
|
416
|
-
return acc;
|
|
417
|
-
}, makeObjectWithoutPrototype());
|
|
418
|
-
if ((0, import_types.isDate)(lhs) || (0, import_types.isDate)(rhs)) {
|
|
419
|
-
if (lhs.valueOf() === rhs.valueOf()) return {};
|
|
420
|
-
return rhs;
|
|
421
|
-
}
|
|
422
|
-
return Object.keys(rhs).reduce((acc, key) => {
|
|
423
|
-
if (!hasOwnProperty(lhs, key)) {
|
|
424
|
-
acc[key] = rhs[key];
|
|
425
|
-
return acc;
|
|
426
|
-
}
|
|
427
|
-
const difference = diff(lhs[key], rhs[key]);
|
|
428
|
-
if (isEmptyObject(difference) && !(0, import_types.isDate)(difference) && (isEmptyObject(lhs[key]) || !isEmptyObject(rhs[key]))) {
|
|
429
|
-
return acc;
|
|
430
|
-
}
|
|
431
|
-
acc[key] = difference;
|
|
432
|
-
return acc;
|
|
433
|
-
}, deletedValues);
|
|
434
|
-
};
|
|
435
342
|
const overwrite = (element, params, opts = {}) => {
|
|
436
|
-
const { __ref: ref } = element;
|
|
437
343
|
const excl = opts.exclude || [];
|
|
438
344
|
const allowUnderscore = opts.preventUnderscore;
|
|
439
|
-
const preventCaching = opts.preventCaching;
|
|
440
345
|
for (const e in params) {
|
|
441
346
|
if (excl.includes(e) || !allowUnderscore && e.startsWith("__")) continue;
|
|
442
|
-
const elementProp = element[e];
|
|
443
347
|
const paramsProp = params[e];
|
|
444
348
|
if (paramsProp !== void 0) {
|
|
445
349
|
element[e] = paramsProp;
|
|
446
|
-
if (ref && !preventCaching) {
|
|
447
|
-
ref.__cache[e] = elementProp;
|
|
448
|
-
}
|
|
449
|
-
if ((0, import_types.isObject)(opts.diff)) {
|
|
450
|
-
diff[e] = elementProp;
|
|
451
|
-
}
|
|
452
350
|
}
|
|
453
351
|
}
|
|
454
352
|
return element;
|
|
@@ -483,18 +381,6 @@ const overwriteDeep = (obj, params, opts = {}, visited = /* @__PURE__ */ new Wea
|
|
|
483
381
|
}
|
|
484
382
|
return obj;
|
|
485
383
|
};
|
|
486
|
-
const mergeIfExisted = (a, b) => {
|
|
487
|
-
if ((0, import_types.isObjectLike)(a) && (0, import_types.isObjectLike)(b)) return deepMerge(a, b);
|
|
488
|
-
return a || b;
|
|
489
|
-
};
|
|
490
|
-
const flattenRecursive = (param, prop, stack = []) => {
|
|
491
|
-
const objectized = (0, import_array.mergeAndCloneIfArray)(param);
|
|
492
|
-
stack.push(objectized);
|
|
493
|
-
const extendOfExtend = objectized[prop];
|
|
494
|
-
if (extendOfExtend) flattenRecursive(extendOfExtend, prop, stack);
|
|
495
|
-
delete objectized[prop];
|
|
496
|
-
return stack;
|
|
497
|
-
};
|
|
498
384
|
const isEqualDeep = (param, element, visited = /* @__PURE__ */ new Set()) => {
|
|
499
385
|
if (typeof param !== "object" || typeof element !== "object" || param === null || element === null) {
|
|
500
386
|
return param === element;
|
|
@@ -523,33 +409,29 @@ const isEqualDeep = (param, element, visited = /* @__PURE__ */ new Set()) => {
|
|
|
523
409
|
};
|
|
524
410
|
const deepContains = (obj1, obj2, ignoredKeys = ["node", "__ref"]) => {
|
|
525
411
|
if (obj1 === obj2) return true;
|
|
526
|
-
if (!(0, import_types.isObjectLike)(obj1) || !(0, import_types.isObjectLike)(obj2)) return
|
|
412
|
+
if (!(0, import_types.isObjectLike)(obj1) || !(0, import_types.isObjectLike)(obj2)) return obj1 === obj2;
|
|
527
413
|
if ((0, import_node.isDOMNode)(obj1) || (0, import_node.isDOMNode)(obj2)) return obj1 === obj2;
|
|
528
|
-
const stack = [[obj1, obj2]];
|
|
529
414
|
const visited = /* @__PURE__ */ new WeakSet();
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
if ((0,
|
|
542
|
-
if (
|
|
543
|
-
} else if (
|
|
544
|
-
if (value1 !== value2) {
|
|
545
|
-
stack.push([value1, value2]);
|
|
546
|
-
}
|
|
547
|
-
} else if (value1 !== value2) {
|
|
415
|
+
function checkContains(target, source) {
|
|
416
|
+
if (visited.has(source)) return true;
|
|
417
|
+
visited.add(source);
|
|
418
|
+
for (const key in source) {
|
|
419
|
+
if (!Object.prototype.hasOwnProperty.call(source, key)) continue;
|
|
420
|
+
if (ignoredKeys.includes(key)) continue;
|
|
421
|
+
if (!Object.prototype.hasOwnProperty.call(target, key)) return false;
|
|
422
|
+
const sourceValue = source[key];
|
|
423
|
+
const targetValue = target[key];
|
|
424
|
+
if ((0, import_node.isDOMNode)(sourceValue) || (0, import_node.isDOMNode)(targetValue)) {
|
|
425
|
+
if (sourceValue !== targetValue) return false;
|
|
426
|
+
} else if ((0, import_types.isObjectLike)(sourceValue) && (0, import_types.isObjectLike)(targetValue)) {
|
|
427
|
+
if (!checkContains(targetValue, sourceValue)) return false;
|
|
428
|
+
} else if (sourceValue !== targetValue) {
|
|
548
429
|
return false;
|
|
549
430
|
}
|
|
550
431
|
}
|
|
432
|
+
return true;
|
|
551
433
|
}
|
|
552
|
-
return
|
|
434
|
+
return checkContains(obj1, obj2);
|
|
553
435
|
};
|
|
554
436
|
const removeFromObject = (obj, props) => {
|
|
555
437
|
if (props === void 0 || props === null) return obj;
|
|
@@ -558,7 +440,9 @@ const removeFromObject = (obj, props) => {
|
|
|
558
440
|
} else if ((0, import_types.isArray)(props)) {
|
|
559
441
|
props.forEach((prop) => delete obj[prop]);
|
|
560
442
|
} else {
|
|
561
|
-
throw new Error(
|
|
443
|
+
throw new Error(
|
|
444
|
+
"Invalid input: props must be a string or an array of strings"
|
|
445
|
+
);
|
|
562
446
|
}
|
|
563
447
|
return obj;
|
|
564
448
|
};
|
|
@@ -583,7 +467,7 @@ const createNestedObject = (arr, lastValue) => {
|
|
|
583
467
|
if (!obj[value]) {
|
|
584
468
|
obj[value] = {};
|
|
585
469
|
}
|
|
586
|
-
if (index === arr.length - 1 && lastValue
|
|
470
|
+
if (index === arr.length - 1 && lastValue) {
|
|
587
471
|
obj[value] = lastValue;
|
|
588
472
|
}
|
|
589
473
|
return obj[value];
|
|
@@ -650,7 +534,10 @@ const detectInfiniteLoop = (arr) => {
|
|
|
650
534
|
}
|
|
651
535
|
if (repeatCount >= maxRepeats * 2) {
|
|
652
536
|
if (ENV === "test" || ENV === "development") {
|
|
653
|
-
console.warn(
|
|
537
|
+
console.warn(
|
|
538
|
+
"Warning: Potential infinite loop detected due to repeated sequence:",
|
|
539
|
+
pattern
|
|
540
|
+
);
|
|
654
541
|
}
|
|
655
542
|
return true;
|
|
656
543
|
}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var props_exports = {};
|
|
20
|
+
__export(props_exports, {
|
|
21
|
+
applyProps: () => applyProps,
|
|
22
|
+
createProps: () => createProps,
|
|
23
|
+
createPropsStack: () => createPropsStack,
|
|
24
|
+
inheritParentProps: () => inheritParentProps,
|
|
25
|
+
initProps: () => initProps,
|
|
26
|
+
objectizeStringProperty: () => objectizeStringProperty,
|
|
27
|
+
pickupElementFromProps: () => pickupElementFromProps,
|
|
28
|
+
pickupPropsFromElement: () => pickupPropsFromElement,
|
|
29
|
+
propExists: () => propExists,
|
|
30
|
+
propertizeElement: () => propertizeElement,
|
|
31
|
+
removeDuplicateProps: () => removeDuplicateProps,
|
|
32
|
+
setPropsPrototype: () => setPropsPrototype,
|
|
33
|
+
syncProps: () => syncProps,
|
|
34
|
+
update: () => update,
|
|
35
|
+
updateProps: () => updateProps
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(props_exports);
|
|
38
|
+
var import_keys = require("./keys.js");
|
|
39
|
+
var import_events = require("./events.js");
|
|
40
|
+
var import_object = require("./object.js");
|
|
41
|
+
var import_types = require("./types.js");
|
|
42
|
+
const createProps = (element, parent, key) => {
|
|
43
|
+
const { props, __ref: ref } = element;
|
|
44
|
+
ref.__propsStack = [];
|
|
45
|
+
if (props) ref.__initialProps = props;
|
|
46
|
+
else return {};
|
|
47
|
+
if (!(0, import_types.isObjectLike)(props)) {
|
|
48
|
+
ref.__propsStack.push(props);
|
|
49
|
+
return {};
|
|
50
|
+
}
|
|
51
|
+
return { ...props };
|
|
52
|
+
};
|
|
53
|
+
function pickupPropsFromElement(element, opts = {}) {
|
|
54
|
+
var _a, _b, _c;
|
|
55
|
+
const cachedKeys = opts.cachedKeys || [];
|
|
56
|
+
for (const key in element) {
|
|
57
|
+
const value = element[key];
|
|
58
|
+
const hasDefine = (0, import_types.isObject)((_a = element.define) == null ? void 0 : _a[key]);
|
|
59
|
+
const hasGlobalDefine = (0, import_types.isObject)((_c = (_b = element.context) == null ? void 0 : _b.define) == null ? void 0 : _c[key]);
|
|
60
|
+
const isElement = /^[A-Z]/.test(key) || /^\d+$/.test(key);
|
|
61
|
+
const isBuiltin = import_keys.DOMQ_PROPERTIES.includes(key);
|
|
62
|
+
if (!isElement && !isBuiltin && !hasDefine && !hasGlobalDefine) {
|
|
63
|
+
element.props[key] = value;
|
|
64
|
+
delete element[key];
|
|
65
|
+
cachedKeys.push(key);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return element;
|
|
69
|
+
}
|
|
70
|
+
function pickupElementFromProps(element, opts) {
|
|
71
|
+
var _a, _b, _c;
|
|
72
|
+
const cachedKeys = opts.cachedKeys || [];
|
|
73
|
+
for (const key in element.props) {
|
|
74
|
+
const value = element.props[key];
|
|
75
|
+
const isEvent = key.startsWith("on") && key.length > 2;
|
|
76
|
+
const isFn = (0, import_types.isFunction)(value);
|
|
77
|
+
if (isEvent && isFn) {
|
|
78
|
+
(0, import_events.addEventFromProps)(key, element);
|
|
79
|
+
delete element.props[key];
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (cachedKeys.includes(key)) continue;
|
|
83
|
+
const hasDefine = (0, import_types.isObject)((_a = element.define) == null ? void 0 : _a[key]);
|
|
84
|
+
const hasGlobalDefine = (0, import_types.isObject)((_c = (_b = element.context) == null ? void 0 : _b.define) == null ? void 0 : _c[key]);
|
|
85
|
+
const isElement = /^[A-Z]/.test(key) || /^\d+$/.test(key);
|
|
86
|
+
const isBuiltin = import_keys.DOMQ_PROPERTIES.includes(key);
|
|
87
|
+
if (isElement || isBuiltin || hasDefine || hasGlobalDefine) {
|
|
88
|
+
element[key] = value;
|
|
89
|
+
delete element.props[key];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return element;
|
|
93
|
+
}
|
|
94
|
+
function propertizeElement(element, opts = {}) {
|
|
95
|
+
const cachedKeys = [];
|
|
96
|
+
pickupPropsFromElement(element, { cachedKeys });
|
|
97
|
+
pickupElementFromProps(element, { cachedKeys });
|
|
98
|
+
return element;
|
|
99
|
+
}
|
|
100
|
+
const objectizeStringProperty = (propValue) => {
|
|
101
|
+
if ((0, import_types.is)(propValue)("string", "number")) {
|
|
102
|
+
return { inheritedString: propValue };
|
|
103
|
+
}
|
|
104
|
+
return propValue;
|
|
105
|
+
};
|
|
106
|
+
const propExists = (prop, stack) => {
|
|
107
|
+
if (!prop || !stack.length) return false;
|
|
108
|
+
const key = (0, import_types.isObject)(prop) ? JSON.stringify(prop) : prop;
|
|
109
|
+
return stack.some((existing) => {
|
|
110
|
+
const existingKey = (0, import_types.isObject)(existing) ? JSON.stringify(existing) : existing;
|
|
111
|
+
return existingKey === key;
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
const inheritParentProps = (element, parent) => {
|
|
115
|
+
var _a;
|
|
116
|
+
const { __ref: ref } = element;
|
|
117
|
+
const propsStack = ref.__propsStack || [];
|
|
118
|
+
const parentProps = parent.props;
|
|
119
|
+
if (!parentProps) return propsStack;
|
|
120
|
+
const matchParentKeyProps = parentProps[element.key];
|
|
121
|
+
const matchParentChildProps = parentProps.childProps;
|
|
122
|
+
const ignoreChildProps = (_a = element.props) == null ? void 0 : _a.ignoreChildProps;
|
|
123
|
+
if (matchParentChildProps && !ignoreChildProps) {
|
|
124
|
+
const childProps = objectizeStringProperty(matchParentChildProps);
|
|
125
|
+
propsStack.unshift(childProps);
|
|
126
|
+
}
|
|
127
|
+
if (matchParentKeyProps) {
|
|
128
|
+
const keyProps = objectizeStringProperty(matchParentKeyProps);
|
|
129
|
+
propsStack.unshift(keyProps);
|
|
130
|
+
}
|
|
131
|
+
return propsStack;
|
|
132
|
+
};
|
|
133
|
+
async function update(props, options) {
|
|
134
|
+
const element = this.__element;
|
|
135
|
+
await element.update({ props }, options);
|
|
136
|
+
}
|
|
137
|
+
function setPropsPrototype(element) {
|
|
138
|
+
const methods = { update: update.bind(element.props), __element: element };
|
|
139
|
+
Object.setPrototypeOf(element.props, methods);
|
|
140
|
+
}
|
|
141
|
+
const removeDuplicateProps = (propsStack) => {
|
|
142
|
+
const seen = /* @__PURE__ */ new Set();
|
|
143
|
+
return propsStack.filter((prop) => {
|
|
144
|
+
if (!prop || import_keys.PROPS_METHODS.includes(prop)) return false;
|
|
145
|
+
const key = (0, import_types.isObject)(prop) ? JSON.stringify(prop) : prop;
|
|
146
|
+
if (seen.has(key)) return false;
|
|
147
|
+
seen.add(key);
|
|
148
|
+
return true;
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
const syncProps = (propsStack, element, opts) => {
|
|
152
|
+
element.props = propsStack.reduce((mergedProps, v) => {
|
|
153
|
+
if (import_keys.PROPS_METHODS.includes(v)) return mergedProps;
|
|
154
|
+
while ((0, import_types.isFunction)(v)) v = (0, import_object.exec)(v, element);
|
|
155
|
+
return (0, import_object.deepMerge)(mergedProps, (0, import_object.deepClone)(v, { exclude: import_keys.PROPS_METHODS }));
|
|
156
|
+
}, {});
|
|
157
|
+
setPropsPrototype(element);
|
|
158
|
+
return element.props;
|
|
159
|
+
};
|
|
160
|
+
const createPropsStack = (element, parent) => {
|
|
161
|
+
const { props, __ref: ref } = element;
|
|
162
|
+
let propsStack = ref.__propsStack || [];
|
|
163
|
+
if (parent && parent.props) {
|
|
164
|
+
const parentStack = inheritParentProps(element, parent);
|
|
165
|
+
propsStack = [...parentStack];
|
|
166
|
+
}
|
|
167
|
+
if ((0, import_types.isObject)(props)) propsStack.push(props);
|
|
168
|
+
else if (props === "inherit" && (parent == null ? void 0 : parent.props)) propsStack.push(parent.props);
|
|
169
|
+
else if (props) propsStack.push(props);
|
|
170
|
+
if ((0, import_types.isArray)(ref.__extendsStack)) {
|
|
171
|
+
ref.__extendsStack.forEach((_extends) => {
|
|
172
|
+
if (_extends.props && _extends.props !== props) {
|
|
173
|
+
propsStack.push(_extends.props);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
ref.__propsStack = removeDuplicateProps(propsStack);
|
|
178
|
+
return ref.__propsStack;
|
|
179
|
+
};
|
|
180
|
+
const applyProps = (element, parent) => {
|
|
181
|
+
const { __ref: ref } = element;
|
|
182
|
+
const propsStack = createPropsStack(element, parent);
|
|
183
|
+
if (propsStack.length) {
|
|
184
|
+
syncProps(propsStack, element);
|
|
185
|
+
} else {
|
|
186
|
+
ref.__propsStack = [];
|
|
187
|
+
element.props = {};
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
const initProps = function(element, parent, options) {
|
|
191
|
+
const { __ref: ref } = element;
|
|
192
|
+
if (ref.__if) applyProps(element, parent);
|
|
193
|
+
else {
|
|
194
|
+
try {
|
|
195
|
+
applyProps(element, parent);
|
|
196
|
+
} catch {
|
|
197
|
+
element.props = {};
|
|
198
|
+
ref.__propsStack = [];
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
setPropsPrototype(element);
|
|
202
|
+
return element;
|
|
203
|
+
};
|
|
204
|
+
const updateProps = (newProps, element, parent) => {
|
|
205
|
+
const { __ref: ref } = element;
|
|
206
|
+
const propsStack = ref.__propsStack || [];
|
|
207
|
+
let newStack = [...propsStack];
|
|
208
|
+
const parentProps = inheritParentProps(element, parent);
|
|
209
|
+
if (parentProps.length) {
|
|
210
|
+
newStack = [...parentProps, ...newStack];
|
|
211
|
+
}
|
|
212
|
+
if (newProps) {
|
|
213
|
+
newStack = [newProps, ...newStack];
|
|
214
|
+
}
|
|
215
|
+
ref.__propsStack = removeDuplicateProps(newStack);
|
|
216
|
+
if (ref.__propsStack.length) {
|
|
217
|
+
syncProps(ref.__propsStack, element);
|
|
218
|
+
}
|
|
219
|
+
return element;
|
|
220
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var scope_exports = {};
|
|
20
|
+
__export(scope_exports, {
|
|
21
|
+
createScope: () => createScope
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(scope_exports);
|
|
24
|
+
const createScope = (element, parent) => {
|
|
25
|
+
var _a;
|
|
26
|
+
const { __ref: ref } = element;
|
|
27
|
+
if (!element.scope) element.scope = parent.scope || ((_a = ref.root) == null ? void 0 : _a.scope) || {};
|
|
28
|
+
};
|