@domql/utils 2.5.200 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/array.js +26 -13
  2. package/cache.js +4 -0
  3. package/component.js +10 -227
  4. package/cookie.js +27 -24
  5. package/dist/cjs/array.js +27 -10
  6. package/dist/cjs/cache.js +26 -0
  7. package/dist/cjs/component.js +15 -206
  8. package/dist/cjs/cookie.js +14 -14
  9. package/dist/cjs/element.js +136 -0
  10. package/dist/cjs/events.js +37 -0
  11. package/dist/cjs/extends.js +351 -0
  12. package/dist/cjs/if.js +30 -0
  13. package/dist/cjs/index.js +10 -0
  14. package/dist/cjs/key.js +5 -0
  15. package/dist/cjs/keys.js +178 -0
  16. package/dist/cjs/methods.js +305 -0
  17. package/dist/cjs/object.js +78 -191
  18. package/dist/cjs/props.js +220 -0
  19. package/dist/cjs/scope.js +28 -0
  20. package/dist/cjs/state.js +175 -0
  21. package/dist/cjs/string.js +27 -15
  22. package/dist/cjs/update.js +42 -0
  23. package/dist/esm/array.js +27 -10
  24. package/dist/esm/cache.js +6 -0
  25. package/dist/esm/component.js +16 -225
  26. package/dist/esm/cookie.js +14 -14
  27. package/dist/esm/element.js +134 -0
  28. package/dist/esm/events.js +17 -0
  29. package/dist/esm/extends.js +349 -0
  30. package/dist/esm/if.js +10 -0
  31. package/dist/esm/index.js +10 -0
  32. package/dist/esm/key.js +5 -0
  33. package/dist/esm/keys.js +158 -0
  34. package/dist/esm/methods.js +285 -0
  35. package/dist/esm/object.js +79 -193
  36. package/dist/esm/props.js +216 -0
  37. package/dist/esm/scope.js +8 -0
  38. package/dist/esm/state.js +185 -0
  39. package/dist/esm/string.js +27 -15
  40. package/dist/esm/update.js +22 -0
  41. package/element.js +148 -0
  42. package/env.js +5 -2
  43. package/events.js +17 -0
  44. package/extends.js +425 -0
  45. package/if.js +14 -0
  46. package/index.js +10 -0
  47. package/key.js +6 -0
  48. package/keys.js +157 -0
  49. package/log.js +4 -1
  50. package/methods.js +315 -0
  51. package/node.js +21 -13
  52. package/object.js +122 -236
  53. package/package.json +3 -3
  54. package/props.js +249 -0
  55. package/scope.js +8 -0
  56. package/state.js +208 -0
  57. package/string.js +66 -30
  58. package/update.js +27 -0
@@ -26,12 +26,12 @@ import {
26
26
  isString,
27
27
  is,
28
28
  isUndefined,
29
- isDate,
30
29
  isNull
31
30
  } from "./types.js";
32
- import { mergeAndCloneIfArray, mergeArray } from "./array.js";
31
+ import { unstackArrayOfObjects } from "./array.js";
33
32
  import { stringIncludesAny } from "./string.js";
34
33
  import { isDOMNode } from "./node.js";
34
+ import { METHODS_EXL } from "./keys.js";
35
35
  const ENV = "development";
36
36
  const exec = (param, element, state, context) => {
37
37
  if (isFunction(param)) {
@@ -44,6 +44,17 @@ const exec = (param, element, state, context) => {
44
44
  }
45
45
  return param;
46
46
  };
47
+ const execPromise = async (param, element, state, context) => {
48
+ if (isFunction(param)) {
49
+ return await param.call(
50
+ element,
51
+ element,
52
+ state || element.state,
53
+ context || element.context
54
+ );
55
+ }
56
+ return param;
57
+ };
47
58
  const map = (obj, extention, element) => {
48
59
  for (const e in extention) {
49
60
  obj[e] = exec(extention[e], element);
@@ -52,7 +63,9 @@ const map = (obj, extention, element) => {
52
63
  const merge = (element, obj, excludeFrom = []) => {
53
64
  for (const e in obj) {
54
65
  const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, e);
55
- if (!hasOwnProperty2 || excludeFrom.includes(e) || e.startsWith("__")) continue;
66
+ if (!hasOwnProperty2 || excludeFrom.includes(e) || e.startsWith("__")) {
67
+ continue;
68
+ }
56
69
  const elementProp = element[e];
57
70
  const objProp = obj[e];
58
71
  if (elementProp === void 0) {
@@ -61,10 +74,12 @@ const merge = (element, obj, excludeFrom = []) => {
61
74
  }
62
75
  return element;
63
76
  };
64
- const deepMerge = (element, extend, excludeFrom = []) => {
77
+ const deepMerge = (element, extend, excludeFrom = METHODS_EXL) => {
65
78
  for (const e in extend) {
66
79
  const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(extend, e);
67
- if (!hasOwnProperty2 || excludeFrom.includes(e) || e.startsWith("__")) continue;
80
+ if (!hasOwnProperty2 || excludeFrom.includes(e) || e.startsWith("__")) {
81
+ continue;
82
+ }
68
83
  const elementProp = element[e];
69
84
  const extendProp = extend[e];
70
85
  if (isObjectLike(elementProp) && isObjectLike(extendProp)) {
@@ -79,14 +94,13 @@ const clone = (obj, excludeFrom = []) => {
79
94
  const o = {};
80
95
  for (const prop in obj) {
81
96
  const hasOwnProperty2 = Object.prototype.hasOwnProperty.call(obj, prop);
82
- if (!hasOwnProperty2 || excludeFrom.includes(prop) || prop.startsWith("__")) continue;
97
+ if (!hasOwnProperty2 || excludeFrom.includes(prop) || prop.startsWith("__")) {
98
+ continue;
99
+ }
83
100
  o[prop] = obj[prop];
84
101
  }
85
102
  return o;
86
103
  };
87
- const mergeArrayExclude = (arr, exclude = []) => {
88
- return arr.reduce((acc, curr) => deepMerge(acc, deepClone(curr, { exclude })), {});
89
- };
90
104
  const deepClone = (obj, options = {}) => {
91
105
  const {
92
106
  exclude = [],
@@ -94,7 +108,7 @@ const deepClone = (obj, options = {}) => {
94
108
  cleanNull = false,
95
109
  window: targetWindow,
96
110
  visited = /* @__PURE__ */ new WeakMap(),
97
- handleExtend = false
111
+ handleExtends = false
98
112
  } = options;
99
113
  if (!isObjectLike(obj) || isDOMNode(obj)) {
100
114
  return obj;
@@ -106,15 +120,19 @@ const deepClone = (obj, options = {}) => {
106
120
  visited.set(obj, clone2);
107
121
  for (const key in obj) {
108
122
  if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
109
- if (exclude.includes(key) || key.startsWith("__") || key === "__proto__") continue;
123
+ if (exclude.includes(key) || key.startsWith("__") || key === "__proto__") {
124
+ continue;
125
+ }
110
126
  const value = obj[key];
111
- if (cleanUndefined && isUndefined(value) || cleanNull && isNull(value)) continue;
127
+ if (cleanUndefined && isUndefined(value) || cleanNull && isNull(value)) {
128
+ continue;
129
+ }
112
130
  if (isDOMNode(value)) {
113
131
  clone2[key] = value;
114
132
  continue;
115
133
  }
116
- if (handleExtend && key === "extend" && isArray(value)) {
117
- clone2[key] = mergeArray(value, exclude);
134
+ if (handleExtends && key === "extends" && isArray(value)) {
135
+ clone2[key] = unstackArrayOfObjects(value, exclude);
118
136
  continue;
119
137
  }
120
138
  if (isFunction(value) && targetWindow) {
@@ -134,7 +152,11 @@ const deepClone = (obj, options = {}) => {
134
152
  const deepStringify = (obj, stringified = {}) => {
135
153
  var _a, _b;
136
154
  if (obj.node || obj.__ref || obj.parent || obj.__element || obj.parse) {
137
- (obj.__element || ((_a = obj.parent) == null ? void 0 : _a.__element)).warn("Trying to clone element or state at", obj);
155
+ ;
156
+ (obj.__element || ((_a = obj.parent) == null ? void 0 : _a.__element)).warn(
157
+ "Trying to clone element or state at",
158
+ obj
159
+ );
138
160
  obj = (_b = obj.parse) == null ? void 0 : _b.call(obj);
139
161
  }
140
162
  for (const prop in obj) {
@@ -162,39 +184,6 @@ const deepStringify = (obj, stringified = {}) => {
162
184
  }
163
185
  return stringified;
164
186
  };
165
- const MAX_DEPTH = 100;
166
- const deepStringifyWithMaxDepth = (obj, stringified = {}, depth = 0, path = "") => {
167
- if (depth > MAX_DEPTH) {
168
- console.warn(`Maximum depth exceeded at path: ${path}. Possible circular reference.`);
169
- return "[MAX_DEPTH_EXCEEDED]";
170
- }
171
- for (const prop in obj) {
172
- const currentPath = path ? `${path}.${prop}` : prop;
173
- const objProp = obj[prop];
174
- if (isFunction(objProp)) {
175
- stringified[prop] = objProp.toString();
176
- } else if (isObject(objProp)) {
177
- stringified[prop] = {};
178
- deepStringifyWithMaxDepth(objProp, stringified[prop], depth + 1, currentPath);
179
- } else if (isArray(objProp)) {
180
- stringified[prop] = [];
181
- objProp.forEach((v, i) => {
182
- const itemPath = `${currentPath}[${i}]`;
183
- if (isObject(v)) {
184
- stringified[prop][i] = {};
185
- deepStringifyWithMaxDepth(v, stringified[prop][i], depth + 1, itemPath);
186
- } else if (isFunction(v)) {
187
- stringified[prop][i] = v.toString();
188
- } else {
189
- stringified[prop][i] = v;
190
- }
191
- });
192
- } else {
193
- stringified[prop] = objProp;
194
- }
195
- }
196
- return stringified;
197
- };
198
187
  const objectToString = (obj = {}, indent = 0) => {
199
188
  if (obj === null || typeof obj !== "object") {
200
189
  return String(obj);
@@ -205,7 +194,22 @@ const objectToString = (obj = {}, indent = 0) => {
205
194
  const spaces = " ".repeat(indent);
206
195
  let str = "{\n";
207
196
  for (const [key, value] of Object.entries(obj)) {
208
- const keyNotAllowdChars = stringIncludesAny(key, ["&", "*", "-", ":", "%", "{", "}", ">", "<", "@", ".", "/", "!", " "]);
197
+ const keyNotAllowdChars = stringIncludesAny(key, [
198
+ "&",
199
+ "*",
200
+ "-",
201
+ ":",
202
+ "%",
203
+ "{",
204
+ "}",
205
+ ">",
206
+ "<",
207
+ "@",
208
+ ".",
209
+ "/",
210
+ "!",
211
+ " "
212
+ ]);
209
213
  const stringedKey = keyNotAllowdChars ? `'${key}'` : key;
210
214
  str += `${spaces} ${stringedKey}: `;
211
215
  if (isArray(value)) {
@@ -235,30 +239,6 @@ const objectToString = (obj = {}, indent = 0) => {
235
239
  str += `${spaces}}`;
236
240
  return str;
237
241
  };
238
- const detachFunctionsFromObject = (obj, detached = {}) => {
239
- for (const prop in obj) {
240
- const objProp = obj[prop];
241
- if (isFunction(objProp)) continue;
242
- else if (isObject(objProp)) {
243
- detached[prop] = {};
244
- deepStringify(objProp, detached[prop]);
245
- } else if (isArray(objProp)) {
246
- detached[prop] = [];
247
- objProp.forEach((v, i) => {
248
- if (isFunction(v)) return;
249
- if (isObject(v)) {
250
- detached[prop][i] = {};
251
- detachFunctionsFromObject(v, detached[prop][i]);
252
- } else {
253
- detached[prop][i] = v;
254
- }
255
- });
256
- } else {
257
- detached[prop] = objProp;
258
- }
259
- }
260
- return detached;
261
- };
262
242
  const hasFunction = (str) => {
263
243
  if (!str) return false;
264
244
  const trimmed = str.trim().replace(/\n\s*/g, " ").trim();
@@ -330,93 +310,18 @@ const stringToObject = (str, opts = { verbose: true }) => {
330
310
  if (opts.verbose) console.warn(e);
331
311
  }
332
312
  };
333
- const diffObjects = (original, objToDiff, cache) => {
334
- for (const e in objToDiff) {
335
- if (e === "ref") continue;
336
- const originalProp = original[e];
337
- const objToDiffProp = objToDiff[e];
338
- if (isObject(originalProp) && isObject(objToDiffProp)) {
339
- cache[e] = {};
340
- diff(originalProp, objToDiffProp, cache[e]);
341
- } else if (objToDiffProp !== void 0) {
342
- cache[e] = objToDiffProp;
343
- }
344
- }
345
- return cache;
346
- };
347
- const diffArrays = (original, objToDiff, cache) => {
348
- if (original.length !== objToDiff.length) {
349
- cache = objToDiff;
350
- } else {
351
- const diffArr = [];
352
- for (let i = 0; i < original.length; i++) {
353
- const diffObj = diff(original[i], objToDiff[i]);
354
- if (Object.keys(diffObj).length > 0) {
355
- diffArr.push(diffObj);
356
- }
357
- }
358
- if (diffArr.length > 0) {
359
- cache = diffArr;
360
- }
361
- }
362
- return cache;
363
- };
364
- const diff = (original, objToDiff, cache = {}) => {
365
- if (isArray(original) && isArray(objToDiff)) {
366
- cache = [];
367
- diffArrays(original, objToDiff, cache);
368
- } else {
369
- diffObjects(original, objToDiff, cache);
370
- }
371
- return cache;
372
- };
373
313
  const hasOwnProperty = (o, ...args) => Object.prototype.hasOwnProperty.call(o, ...args);
374
314
  const isEmpty = (o) => Object.keys(o).length === 0;
375
315
  const isEmptyObject = (o) => isObject(o) && isEmpty(o);
376
316
  const makeObjectWithoutPrototype = () => /* @__PURE__ */ Object.create(null);
377
- const deepDiff = (lhs, rhs) => {
378
- if (lhs === rhs) return {};
379
- if (!isObjectLike(lhs) || !isObjectLike(rhs)) return rhs;
380
- const deletedValues = Object.keys(lhs).reduce((acc, key) => {
381
- if (!hasOwnProperty(rhs, key)) {
382
- acc[key] = void 0;
383
- }
384
- return acc;
385
- }, makeObjectWithoutPrototype());
386
- if (isDate(lhs) || isDate(rhs)) {
387
- if (lhs.valueOf() === rhs.valueOf()) return {};
388
- return rhs;
389
- }
390
- return Object.keys(rhs).reduce((acc, key) => {
391
- if (!hasOwnProperty(lhs, key)) {
392
- acc[key] = rhs[key];
393
- return acc;
394
- }
395
- const difference = diff(lhs[key], rhs[key]);
396
- if (isEmptyObject(difference) && !isDate(difference) && (isEmptyObject(lhs[key]) || !isEmptyObject(rhs[key]))) {
397
- return acc;
398
- }
399
- acc[key] = difference;
400
- return acc;
401
- }, deletedValues);
402
- };
403
317
  const overwrite = (element, params, opts = {}) => {
404
- const { __ref: ref } = element;
405
318
  const excl = opts.exclude || [];
406
319
  const allowUnderscore = opts.preventUnderscore;
407
- const preventCaching = opts.preventCaching;
408
320
  for (const e in params) {
409
321
  if (excl.includes(e) || !allowUnderscore && e.startsWith("__")) continue;
410
- const elementProp = element[e];
411
322
  const paramsProp = params[e];
412
323
  if (paramsProp !== void 0) {
413
324
  element[e] = paramsProp;
414
- if (ref && !preventCaching) {
415
- ref.__cache[e] = elementProp;
416
- }
417
- if (isObject(opts.diff)) {
418
- diff[e] = elementProp;
419
- }
420
325
  }
421
326
  }
422
327
  return element;
@@ -451,18 +356,6 @@ const overwriteDeep = (obj, params, opts = {}, visited = /* @__PURE__ */ new Wea
451
356
  }
452
357
  return obj;
453
358
  };
454
- const mergeIfExisted = (a, b) => {
455
- if (isObjectLike(a) && isObjectLike(b)) return deepMerge(a, b);
456
- return a || b;
457
- };
458
- const flattenRecursive = (param, prop, stack = []) => {
459
- const objectized = mergeAndCloneIfArray(param);
460
- stack.push(objectized);
461
- const extendOfExtend = objectized[prop];
462
- if (extendOfExtend) flattenRecursive(extendOfExtend, prop, stack);
463
- delete objectized[prop];
464
- return stack;
465
- };
466
359
  const isEqualDeep = (param, element, visited = /* @__PURE__ */ new Set()) => {
467
360
  if (typeof param !== "object" || typeof element !== "object" || param === null || element === null) {
468
361
  return param === element;
@@ -491,33 +384,29 @@ const isEqualDeep = (param, element, visited = /* @__PURE__ */ new Set()) => {
491
384
  };
492
385
  const deepContains = (obj1, obj2, ignoredKeys = ["node", "__ref"]) => {
493
386
  if (obj1 === obj2) return true;
494
- if (!isObjectLike(obj1) || !isObjectLike(obj2)) return false;
387
+ if (!isObjectLike(obj1) || !isObjectLike(obj2)) return obj1 === obj2;
495
388
  if (isDOMNode(obj1) || isDOMNode(obj2)) return obj1 === obj2;
496
- const stack = [[obj1, obj2]];
497
389
  const visited = /* @__PURE__ */ new WeakSet();
498
- while (stack.length > 0) {
499
- const [current1, current2] = stack.pop();
500
- if (visited.has(current1)) continue;
501
- visited.add(current1);
502
- const keys1 = Object.keys(current1).filter((key) => !ignoredKeys.includes(key));
503
- const keys2 = Object.keys(current2).filter((key) => !ignoredKeys.includes(key));
504
- if (keys1.length !== keys2.length) return false;
505
- for (const key of keys1) {
506
- if (!Object.prototype.hasOwnProperty.call(current2, key)) return false;
507
- const value1 = current1[key];
508
- const value2 = current2[key];
509
- if (isDOMNode(value1) || isDOMNode(value2)) {
510
- if (value1 !== value2) return false;
511
- } else if (isObjectLike(value1) && isObjectLike(value2)) {
512
- if (value1 !== value2) {
513
- stack.push([value1, value2]);
514
- }
515
- } else if (value1 !== value2) {
390
+ function checkContains(target, source) {
391
+ if (visited.has(source)) return true;
392
+ visited.add(source);
393
+ for (const key in source) {
394
+ if (!Object.prototype.hasOwnProperty.call(source, key)) continue;
395
+ if (ignoredKeys.includes(key)) continue;
396
+ if (!Object.prototype.hasOwnProperty.call(target, key)) return false;
397
+ const sourceValue = source[key];
398
+ const targetValue = target[key];
399
+ if (isDOMNode(sourceValue) || isDOMNode(targetValue)) {
400
+ if (sourceValue !== targetValue) return false;
401
+ } else if (isObjectLike(sourceValue) && isObjectLike(targetValue)) {
402
+ if (!checkContains(targetValue, sourceValue)) return false;
403
+ } else if (sourceValue !== targetValue) {
516
404
  return false;
517
405
  }
518
406
  }
407
+ return true;
519
408
  }
520
- return true;
409
+ return checkContains(obj1, obj2);
521
410
  };
522
411
  const removeFromObject = (obj, props) => {
523
412
  if (props === void 0 || props === null) return obj;
@@ -526,7 +415,9 @@ const removeFromObject = (obj, props) => {
526
415
  } else if (isArray(props)) {
527
416
  props.forEach((prop) => delete obj[prop]);
528
417
  } else {
529
- throw new Error("Invalid input: props must be a string or an array of strings");
418
+ throw new Error(
419
+ "Invalid input: props must be a string or an array of strings"
420
+ );
530
421
  }
531
422
  return obj;
532
423
  };
@@ -551,7 +442,7 @@ const createNestedObject = (arr, lastValue) => {
551
442
  if (!obj[value]) {
552
443
  obj[value] = {};
553
444
  }
554
- if (index === arr.length - 1 && lastValue !== void 0) {
445
+ if (index === arr.length - 1 && lastValue) {
555
446
  obj[value] = lastValue;
556
447
  }
557
448
  return obj[value];
@@ -618,7 +509,10 @@ const detectInfiniteLoop = (arr) => {
618
509
  }
619
510
  if (repeatCount >= maxRepeats * 2) {
620
511
  if (ENV === "test" || ENV === "development") {
621
- console.warn("Warning: Potential infinite loop detected due to repeated sequence:", pattern);
512
+ console.warn(
513
+ "Warning: Potential infinite loop detected due to repeated sequence:",
514
+ pattern
515
+ );
622
516
  }
623
517
  return true;
624
518
  }
@@ -656,18 +550,12 @@ export {
656
550
  deepClone,
657
551
  deepContains,
658
552
  deepDestringify,
659
- deepDiff,
660
553
  deepMerge,
661
554
  deepStringify,
662
- deepStringifyWithMaxDepth,
663
- detachFunctionsFromObject,
664
555
  detectInfiniteLoop,
665
- diff,
666
- diffArrays,
667
- diffObjects,
668
556
  excludeKeysFromObject,
669
557
  exec,
670
- flattenRecursive,
558
+ execPromise,
671
559
  getInObjectByPath,
672
560
  hasFunction,
673
561
  hasOwnProperty,
@@ -678,8 +566,6 @@ export {
678
566
  makeObjectWithoutPrototype,
679
567
  map,
680
568
  merge,
681
- mergeArrayExclude,
682
- mergeIfExisted,
683
569
  objectToString,
684
570
  overwrite,
685
571
  overwriteDeep,
@@ -0,0 +1,216 @@
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
+ import { DOMQ_PROPERTIES, PROPS_METHODS } from "./keys.js";
18
+ import { addEventFromProps } from "./events.js";
19
+ import { deepClone, deepMerge, exec } from "./object.js";
20
+ import { is, isArray, isFunction, isObject, isObjectLike } from "./types.js";
21
+ const createProps = (element, parent, key) => {
22
+ const { props, __ref: ref } = element;
23
+ ref.__propsStack = [];
24
+ if (props) ref.__initialProps = props;
25
+ else return {};
26
+ if (!isObjectLike(props)) {
27
+ ref.__propsStack.push(props);
28
+ return {};
29
+ }
30
+ return __spreadValues({}, props);
31
+ };
32
+ function pickupPropsFromElement(element, opts = {}) {
33
+ var _a, _b, _c;
34
+ const cachedKeys = opts.cachedKeys || [];
35
+ for (const key in element) {
36
+ const value = element[key];
37
+ const hasDefine = isObject((_a = element.define) == null ? void 0 : _a[key]);
38
+ const hasGlobalDefine = isObject((_c = (_b = element.context) == null ? void 0 : _b.define) == null ? void 0 : _c[key]);
39
+ const isElement = /^[A-Z]/.test(key) || /^\d+$/.test(key);
40
+ const isBuiltin = DOMQ_PROPERTIES.includes(key);
41
+ if (!isElement && !isBuiltin && !hasDefine && !hasGlobalDefine) {
42
+ element.props[key] = value;
43
+ delete element[key];
44
+ cachedKeys.push(key);
45
+ }
46
+ }
47
+ return element;
48
+ }
49
+ function pickupElementFromProps(element, opts) {
50
+ var _a, _b, _c;
51
+ const cachedKeys = opts.cachedKeys || [];
52
+ for (const key in element.props) {
53
+ const value = element.props[key];
54
+ const isEvent = key.startsWith("on") && key.length > 2;
55
+ const isFn = isFunction(value);
56
+ if (isEvent && isFn) {
57
+ addEventFromProps(key, element);
58
+ delete element.props[key];
59
+ continue;
60
+ }
61
+ if (cachedKeys.includes(key)) continue;
62
+ const hasDefine = isObject((_a = element.define) == null ? void 0 : _a[key]);
63
+ const hasGlobalDefine = isObject((_c = (_b = element.context) == null ? void 0 : _b.define) == null ? void 0 : _c[key]);
64
+ const isElement = /^[A-Z]/.test(key) || /^\d+$/.test(key);
65
+ const isBuiltin = DOMQ_PROPERTIES.includes(key);
66
+ if (isElement || isBuiltin || hasDefine || hasGlobalDefine) {
67
+ element[key] = value;
68
+ delete element.props[key];
69
+ }
70
+ }
71
+ return element;
72
+ }
73
+ function propertizeElement(element, opts = {}) {
74
+ const cachedKeys = [];
75
+ pickupPropsFromElement(element, { cachedKeys });
76
+ pickupElementFromProps(element, { cachedKeys });
77
+ return element;
78
+ }
79
+ const objectizeStringProperty = (propValue) => {
80
+ if (is(propValue)("string", "number")) {
81
+ return { inheritedString: propValue };
82
+ }
83
+ return propValue;
84
+ };
85
+ const propExists = (prop, stack) => {
86
+ if (!prop || !stack.length) return false;
87
+ const key = isObject(prop) ? JSON.stringify(prop) : prop;
88
+ return stack.some((existing) => {
89
+ const existingKey = isObject(existing) ? JSON.stringify(existing) : existing;
90
+ return existingKey === key;
91
+ });
92
+ };
93
+ const inheritParentProps = (element, parent) => {
94
+ var _a;
95
+ const { __ref: ref } = element;
96
+ const propsStack = ref.__propsStack || [];
97
+ const parentProps = parent.props;
98
+ if (!parentProps) return propsStack;
99
+ const matchParentKeyProps = parentProps[element.key];
100
+ const matchParentChildProps = parentProps.childProps;
101
+ const ignoreChildProps = (_a = element.props) == null ? void 0 : _a.ignoreChildProps;
102
+ if (matchParentChildProps && !ignoreChildProps) {
103
+ const childProps = objectizeStringProperty(matchParentChildProps);
104
+ propsStack.unshift(childProps);
105
+ }
106
+ if (matchParentKeyProps) {
107
+ const keyProps = objectizeStringProperty(matchParentKeyProps);
108
+ propsStack.unshift(keyProps);
109
+ }
110
+ return propsStack;
111
+ };
112
+ async function update(props, options) {
113
+ const element = this.__element;
114
+ await element.update({ props }, options);
115
+ }
116
+ function setPropsPrototype(element) {
117
+ const methods = { update: update.bind(element.props), __element: element };
118
+ Object.setPrototypeOf(element.props, methods);
119
+ }
120
+ const removeDuplicateProps = (propsStack) => {
121
+ const seen = /* @__PURE__ */ new Set();
122
+ return propsStack.filter((prop) => {
123
+ if (!prop || PROPS_METHODS.includes(prop)) return false;
124
+ const key = isObject(prop) ? JSON.stringify(prop) : prop;
125
+ if (seen.has(key)) return false;
126
+ seen.add(key);
127
+ return true;
128
+ });
129
+ };
130
+ const syncProps = (propsStack, element, opts) => {
131
+ element.props = propsStack.reduce((mergedProps, v) => {
132
+ if (PROPS_METHODS.includes(v)) return mergedProps;
133
+ while (isFunction(v)) v = exec(v, element);
134
+ return deepMerge(mergedProps, deepClone(v, { exclude: PROPS_METHODS }));
135
+ }, {});
136
+ setPropsPrototype(element);
137
+ return element.props;
138
+ };
139
+ const createPropsStack = (element, parent) => {
140
+ const { props, __ref: ref } = element;
141
+ let propsStack = ref.__propsStack || [];
142
+ if (parent && parent.props) {
143
+ const parentStack = inheritParentProps(element, parent);
144
+ propsStack = [...parentStack];
145
+ }
146
+ if (isObject(props)) propsStack.push(props);
147
+ else if (props === "inherit" && (parent == null ? void 0 : parent.props)) propsStack.push(parent.props);
148
+ else if (props) propsStack.push(props);
149
+ if (isArray(ref.__extendsStack)) {
150
+ ref.__extendsStack.forEach((_extends) => {
151
+ if (_extends.props && _extends.props !== props) {
152
+ propsStack.push(_extends.props);
153
+ }
154
+ });
155
+ }
156
+ ref.__propsStack = removeDuplicateProps(propsStack);
157
+ return ref.__propsStack;
158
+ };
159
+ const applyProps = (element, parent) => {
160
+ const { __ref: ref } = element;
161
+ const propsStack = createPropsStack(element, parent);
162
+ if (propsStack.length) {
163
+ syncProps(propsStack, element);
164
+ } else {
165
+ ref.__propsStack = [];
166
+ element.props = {};
167
+ }
168
+ };
169
+ const initProps = function(element, parent, options) {
170
+ const { __ref: ref } = element;
171
+ if (ref.__if) applyProps(element, parent);
172
+ else {
173
+ try {
174
+ applyProps(element, parent);
175
+ } catch (e) {
176
+ element.props = {};
177
+ ref.__propsStack = [];
178
+ }
179
+ }
180
+ setPropsPrototype(element);
181
+ return element;
182
+ };
183
+ const updateProps = (newProps, element, parent) => {
184
+ const { __ref: ref } = element;
185
+ const propsStack = ref.__propsStack || [];
186
+ let newStack = [...propsStack];
187
+ const parentProps = inheritParentProps(element, parent);
188
+ if (parentProps.length) {
189
+ newStack = [...parentProps, ...newStack];
190
+ }
191
+ if (newProps) {
192
+ newStack = [newProps, ...newStack];
193
+ }
194
+ ref.__propsStack = removeDuplicateProps(newStack);
195
+ if (ref.__propsStack.length) {
196
+ syncProps(ref.__propsStack, element);
197
+ }
198
+ return element;
199
+ };
200
+ export {
201
+ applyProps,
202
+ createProps,
203
+ createPropsStack,
204
+ inheritParentProps,
205
+ initProps,
206
+ objectizeStringProperty,
207
+ pickupElementFromProps,
208
+ pickupPropsFromElement,
209
+ propExists,
210
+ propertizeElement,
211
+ removeDuplicateProps,
212
+ setPropsPrototype,
213
+ syncProps,
214
+ update,
215
+ updateProps
216
+ };
@@ -0,0 +1,8 @@
1
+ const createScope = (element, parent) => {
2
+ var _a;
3
+ const { __ref: ref } = element;
4
+ if (!element.scope) element.scope = parent.scope || ((_a = ref.root) == null ? void 0 : _a.scope) || {};
5
+ };
6
+ export {
7
+ createScope
8
+ };