@symbo.ls/utils 2.11.436 → 2.11.453

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/dist/cjs/index.js CHANGED
@@ -302,6 +302,8 @@ var require_array = __commonJS({
302
302
  arraysEqual: () => arraysEqual,
303
303
  cutArrayAfterValue: () => cutArrayAfterValue,
304
304
  cutArrayBeforeValue: () => cutArrayBeforeValue,
305
+ filterArrays: () => filterArrays,
306
+ filterArraysFast: () => filterArraysFast,
305
307
  getFrequencyInArray: () => getFrequencyInArray,
306
308
  joinArrays: () => joinArrays,
307
309
  mergeAndCloneIfArray: () => mergeAndCloneIfArray,
@@ -410,6 +412,13 @@ var require_array = __commonJS({
410
412
  }
411
413
  return true;
412
414
  };
415
+ var filterArrays = (sourceArr, excludeArr) => {
416
+ return sourceArr.filter((item) => !excludeArr.includes(item));
417
+ };
418
+ var filterArraysFast = (sourceArr, excludeArr) => {
419
+ const excludeSet = new Set(excludeArr);
420
+ return sourceArr.filter((item) => !excludeSet.has(item));
421
+ };
413
422
  }
414
423
  });
415
424
 
@@ -597,14 +606,17 @@ var require_object = __commonJS({
597
606
  deepDiff: () => deepDiff,
598
607
  deepMerge: () => deepMerge,
599
608
  deepStringify: () => deepStringify,
609
+ deepStringifyWithMaxDepth: () => deepStringifyWithMaxDepth,
600
610
  detachFunctionsFromObject: () => detachFunctionsFromObject,
601
611
  detectInfiniteLoop: () => detectInfiniteLoop,
602
612
  diff: () => diff,
603
613
  diffArrays: () => diffArrays,
604
614
  diffObjects: () => diffObjects,
615
+ excludeKeysFromObject: () => excludeKeysFromObject,
605
616
  exec: () => exec,
606
617
  flattenRecursive: () => flattenRecursive,
607
618
  hasOwnProperty: () => hasOwnProperty,
619
+ isCyclic: () => isCyclic,
608
620
  isEmpty: () => isEmpty,
609
621
  isEmptyObject: () => isEmptyObject,
610
622
  isEqualDeep: () => isEqualDeep,
@@ -630,7 +642,8 @@ var require_object = __commonJS({
630
642
  var ENV = "development";
631
643
  var exec = (param, element, state, context) => {
632
644
  if ((0, import_types.isFunction)(param)) {
633
- return param(
645
+ return param.call(
646
+ element,
634
647
  element,
635
648
  state || element.state,
636
649
  context || element.context
@@ -729,24 +742,37 @@ var require_object = __commonJS({
729
742
  }
730
743
  return clone2;
731
744
  };
732
- var deepCloneWithExtend = (obj, excludeFrom = ["node"], options = {}) => {
745
+ var deepCloneWithExtend = (obj, excludeFrom = ["node"], options = {}, visited = /* @__PURE__ */ new WeakSet()) => {
746
+ if ((0, import_types.isObjectLike)(obj)) {
747
+ if (visited.has(obj)) {
748
+ return obj;
749
+ }
750
+ visited.add(obj);
751
+ }
733
752
  const o = options.window ? (0, import_types.isArray)(obj) ? new options.window.Array([]) : new options.window.Object({}) : (0, import_types.isArray)(obj) ? [] : {};
734
753
  for (const prop in obj) {
735
754
  if (!Object.prototype.hasOwnProperty.call(obj, prop))
736
755
  continue;
737
756
  const objProp = obj[prop];
738
- if (excludeFrom.includes(prop) || prop.startsWith("__") || options.cleanUndefined && (0, import_types.isUndefined)(objProp) || options.cleanNull && (0, import_types.isNull)(objProp))
757
+ if (excludeFrom.includes(prop) || prop.startsWith("__") || options.cleanUndefined && (0, import_types.isUndefined)(objProp) || options.cleanNull && (0, import_types.isNull)(objProp)) {
739
758
  continue;
759
+ }
740
760
  if ((0, import_types.isObjectLike)(objProp)) {
741
- o[prop] = deepCloneWithExtend(objProp, excludeFrom, options);
761
+ o[prop] = deepCloneWithExtend(objProp, excludeFrom, options, visited);
742
762
  } else if ((0, import_types.isFunction)(objProp) && options.window) {
743
763
  o[prop] = (options.window || import_globals.window).eval("(" + objProp.toString() + ")");
744
- } else
764
+ } else {
745
765
  o[prop] = objProp;
766
+ }
746
767
  }
747
768
  return o;
748
769
  };
749
770
  var deepStringify = (obj, stringified = {}) => {
771
+ var _a;
772
+ if (obj.node || obj.__ref || obj.parent || obj.__element || obj.parse) {
773
+ console.warn("Trying to clone element or state at", obj);
774
+ obj = (_a = obj.parse) == null ? void 0 : _a.call(obj);
775
+ }
750
776
  for (const prop in obj) {
751
777
  const objProp = obj[prop];
752
778
  if ((0, import_types.isFunction)(objProp)) {
@@ -772,6 +798,39 @@ var require_object = __commonJS({
772
798
  }
773
799
  return stringified;
774
800
  };
801
+ var MAX_DEPTH = 100;
802
+ var deepStringifyWithMaxDepth = (obj, stringified = {}, depth = 0, path = "") => {
803
+ if (depth > MAX_DEPTH) {
804
+ console.warn(`Maximum depth exceeded at path: ${path}. Possible circular reference.`);
805
+ return "[MAX_DEPTH_EXCEEDED]";
806
+ }
807
+ for (const prop in obj) {
808
+ const currentPath = path ? `${path}.${prop}` : prop;
809
+ const objProp = obj[prop];
810
+ if ((0, import_types.isFunction)(objProp)) {
811
+ stringified[prop] = objProp.toString();
812
+ } else if ((0, import_types.isObject)(objProp)) {
813
+ stringified[prop] = {};
814
+ deepStringifyWithMaxDepth(objProp, stringified[prop], depth + 1, currentPath);
815
+ } else if ((0, import_types.isArray)(objProp)) {
816
+ stringified[prop] = [];
817
+ objProp.forEach((v, i) => {
818
+ const itemPath = `${currentPath}[${i}]`;
819
+ if ((0, import_types.isObject)(v)) {
820
+ stringified[prop][i] = {};
821
+ deepStringifyWithMaxDepth(v, stringified[prop][i], depth + 1, itemPath);
822
+ } else if ((0, import_types.isFunction)(v)) {
823
+ stringified[prop][i] = v.toString();
824
+ } else {
825
+ stringified[prop][i] = v;
826
+ }
827
+ });
828
+ } else {
829
+ stringified[prop] = objProp;
830
+ }
831
+ }
832
+ return stringified;
833
+ };
775
834
  var objectToString = (obj = {}, indent = 0) => {
776
835
  const spaces = " ".repeat(indent);
777
836
  let str = "{\n";
@@ -881,7 +940,7 @@ var require_object = __commonJS({
881
940
  };
882
941
  var stringToObject = (str, opts = { verbose: true }) => {
883
942
  try {
884
- return import_globals.window.eval("(" + str + ")");
943
+ return str ? import_globals.window.eval("(" + str + ")") : {};
885
944
  } catch (e) {
886
945
  if (opts.verbose)
887
946
  console.warn(e);
@@ -961,20 +1020,27 @@ var require_object = __commonJS({
961
1020
  return acc;
962
1021
  }, deletedValues);
963
1022
  };
964
- var overwrite = (element, params, excludeFrom = []) => {
965
- const { ref } = element;
966
- const changes = {};
1023
+ var overwrite = (element, params, opts = {}) => {
1024
+ const { __ref: ref } = element;
1025
+ const excl = opts.exclude || [];
1026
+ const allowUnderscore = opts.preventUnderscore;
1027
+ const preventCaching = opts.preventCaching;
967
1028
  for (const e in params) {
968
- if (excludeFrom.includes(e) || e.startsWith("__"))
1029
+ if (excl.includes(e) || !allowUnderscore && e.startsWith("__"))
969
1030
  continue;
970
1031
  const elementProp = element[e];
971
1032
  const paramsProp = params[e];
972
- if (paramsProp) {
973
- ref.__cache[e] = changes[e] = elementProp;
974
- ref[e] = paramsProp;
1033
+ if (paramsProp !== void 0) {
1034
+ element[e] = paramsProp;
1035
+ if (ref && !preventCaching) {
1036
+ ref.__cache[e] = elementProp;
1037
+ }
1038
+ if ((0, import_types.isObject)(opts.diff)) {
1039
+ diff[e] = elementProp;
1040
+ }
975
1041
  }
976
1042
  }
977
- return changes;
1043
+ return element;
978
1044
  };
979
1045
  var overwriteShallow = (obj, params, excludeFrom = []) => {
980
1046
  for (const e in params) {
@@ -984,23 +1050,26 @@ var require_object = __commonJS({
984
1050
  }
985
1051
  return obj;
986
1052
  };
987
- var overwriteDeep = (obj, params, excludeFrom = [], visited = /* @__PURE__ */ new WeakMap()) => {
1053
+ var overwriteDeep = (obj, params, opts = {}, visited = /* @__PURE__ */ new WeakMap()) => {
1054
+ const excl = opts.exclude || [];
1055
+ const forcedExclude = opts.preventForce ? [] : ["node", "window"];
988
1056
  if (!(0, import_types.isObjectLike)(obj) || !(0, import_types.isObjectLike)(params) || (0, import_node.isDOMNode)(obj) || (0, import_node.isDOMNode)(params)) {
989
1057
  return params;
990
1058
  }
991
- if (visited.has(obj)) {
1059
+ if (visited.has(obj))
992
1060
  return visited.get(obj);
993
- }
994
1061
  visited.set(obj, obj);
995
1062
  for (const e in params) {
996
- if (e === "__ref" || excludeFrom.includes(e) || e.startsWith("__"))
1063
+ if (!Object.hasOwnProperty.call(params, e))
1064
+ continue;
1065
+ if (excl.includes(e) || forcedExclude && e.startsWith("__"))
997
1066
  continue;
998
1067
  const objProp = obj[e];
999
1068
  const paramsProp = params[e];
1000
1069
  if ((0, import_node.isDOMNode)(paramsProp)) {
1001
1070
  obj[e] = paramsProp;
1002
1071
  } else if ((0, import_types.isObjectLike)(objProp) && (0, import_types.isObjectLike)(paramsProp)) {
1003
- obj[e] = overwriteDeep(objProp, paramsProp, excludeFrom, visited);
1072
+ obj[e] = overwriteDeep(objProp, paramsProp, opts, visited);
1004
1073
  } else if (paramsProp !== void 0) {
1005
1074
  obj[e] = paramsProp;
1006
1075
  }
@@ -1163,6 +1232,30 @@ var require_object = __commonJS({
1163
1232
  }
1164
1233
  }
1165
1234
  };
1235
+ var isCyclic = (obj) => {
1236
+ const seenObjects = [];
1237
+ function detect(obj2) {
1238
+ if (obj2 && typeof obj2 === "object") {
1239
+ if (seenObjects.indexOf(obj2) !== -1) {
1240
+ return true;
1241
+ }
1242
+ seenObjects.push(obj2);
1243
+ for (const key in obj2) {
1244
+ if (Object.hasOwnProperty.call(obj2, key) && detect(obj2[key])) {
1245
+ console.log(obj2, "cycle at " + key);
1246
+ return true;
1247
+ }
1248
+ }
1249
+ }
1250
+ return false;
1251
+ }
1252
+ return detect(obj);
1253
+ };
1254
+ var excludeKeysFromObject = (obj, excludedKeys) => {
1255
+ const result = { ...obj };
1256
+ excludedKeys.forEach((key) => delete result[key]);
1257
+ return result;
1258
+ };
1166
1259
  }
1167
1260
  });
1168
1261
 
@@ -1319,6 +1412,7 @@ var require_cookie = __commonJS({
1319
1412
  __export2(cookie_exports, {
1320
1413
  getCookie: () => getCookie,
1321
1414
  isMobile: () => isMobile,
1415
+ removeCookie: () => removeCookie,
1322
1416
  setCookie: () => setCookie
1323
1417
  });
1324
1418
  module2.exports = __toCommonJS2(cookie_exports);
@@ -1348,6 +1442,11 @@ var require_cookie = __commonJS({
1348
1442
  }
1349
1443
  return "";
1350
1444
  };
1445
+ var removeCookie = (cname) => {
1446
+ if ((0, import_types.isUndefined)(import_utils3.document) || (0, import_types.isUndefined)(import_utils3.document.cookie))
1447
+ return;
1448
+ import_utils3.document.cookie = cname + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
1449
+ };
1351
1450
  }
1352
1451
  });
1353
1452
 
@@ -1387,10 +1486,13 @@ var require_tags = __commonJS({
1387
1486
  "title",
1388
1487
  "base",
1389
1488
  "meta",
1390
- "style"
1489
+ "style",
1490
+ "noscript",
1491
+ "script"
1391
1492
  ],
1392
1493
  body: [
1393
1494
  "string",
1495
+ "style",
1394
1496
  "fragment",
1395
1497
  "a",
1396
1498
  "abbr",
@@ -1543,6 +1645,7 @@ var require_component = __commonJS({
1543
1645
  var component_exports = {};
1544
1646
  __export2(component_exports, {
1545
1647
  addAdditionalExtend: () => addAdditionalExtend,
1648
+ addChildrenIfNotInOriginal: () => addChildrenIfNotInOriginal,
1546
1649
  applyComponentFromContext: () => applyComponentFromContext,
1547
1650
  applyKeyComponentAsExtend: () => applyKeyComponentAsExtend,
1548
1651
  checkIfKeyIsComponent: () => checkIfKeyIsComponent,
@@ -1551,7 +1654,8 @@ var require_component = __commonJS({
1551
1654
  getChildrenComponentsByKey: () => getChildrenComponentsByKey,
1552
1655
  getExtendsInElement: () => getExtendsInElement,
1553
1656
  hasVariantProp: () => hasVariantProp,
1554
- isVariant: () => isVariant
1657
+ isVariant: () => isVariant,
1658
+ setContentKey: () => setContentKey
1555
1659
  });
1556
1660
  module2.exports = __toCommonJS2(component_exports);
1557
1661
  var import__ = require_cjs();
@@ -1571,26 +1675,51 @@ var require_component = __commonJS({
1571
1675
  return /^[a-z]*$/.test(firstCharKey);
1572
1676
  };
1573
1677
  var addAdditionalExtend = (newExtend, element) => {
1678
+ if (!newExtend)
1679
+ return element;
1574
1680
  const { extend: elementExtend } = element;
1575
1681
  const originalArray = (0, import__.isArray)(elementExtend) ? elementExtend : [elementExtend];
1576
1682
  const receivedArray = (0, import__.isArray)(newExtend) ? newExtend : [newExtend];
1577
1683
  const extend = (0, import__.joinArrays)(receivedArray, originalArray);
1578
1684
  return { ...element, extend };
1579
1685
  };
1686
+ var checkIfSugar = (element, parent, key) => {
1687
+ const {
1688
+ extend,
1689
+ props,
1690
+ childExtend,
1691
+ extends: extendProps,
1692
+ childrenExtends,
1693
+ childProps,
1694
+ children,
1695
+ on,
1696
+ $collection,
1697
+ $stateCollection,
1698
+ $propsCollection
1699
+ } = element;
1700
+ const hasComponentAttrs = extend || childExtend || props || on || $collection || $stateCollection || $propsCollection;
1701
+ if (hasComponentAttrs && (childProps || extendProps || children || childrenExtends)) {
1702
+ element.error("Sugar component includes params for builtin components");
1703
+ }
1704
+ return !hasComponentAttrs || childProps || extendProps || children || childrenExtends;
1705
+ };
1580
1706
  var extendizeByKey = (element, parent, key) => {
1581
1707
  const { context } = parent;
1582
- const { tag, extend, props, attr, state, childExtend, childProps, on, if: condition, data } = element;
1583
- const hasComponentAttrs = extend || childExtend || props || state || on || condition || attr || data;
1708
+ const { tag, extend, childrenExtends } = element;
1709
+ const isSugar = checkIfSugar(element);
1584
1710
  const extendFromKey = key.includes("+") ? key.split("+") : key.includes("_") ? [key.split("_")[0]] : key.includes(".") && !checkIfKeyIsComponent(key.split(".")[1]) ? [key.split(".")[0]] : [key];
1585
1711
  const isExtendKeyComponent = context && context.components[extendFromKey];
1586
1712
  if (element === isExtendKeyComponent)
1587
1713
  return element;
1588
- else if (!hasComponentAttrs || childProps) {
1589
- return {
1714
+ else if (isSugar) {
1715
+ const newElem = addAdditionalExtend(element.extends, {
1590
1716
  extend: extendFromKey,
1591
1717
  tag,
1592
1718
  props: { ...element }
1593
- };
1719
+ });
1720
+ if (childrenExtends)
1721
+ newElem.childExtend = childrenExtends;
1722
+ return newElem;
1594
1723
  } else if (!extend || extend === true) {
1595
1724
  return {
1596
1725
  ...element,
@@ -1607,6 +1736,37 @@ var require_component = __commonJS({
1607
1736
  };
1608
1737
  }
1609
1738
  };
1739
+ function getCapitalCaseKeys(obj) {
1740
+ return Object.keys(obj).filter((key) => /^[A-Z]/.test(key));
1741
+ }
1742
+ var addChildrenIfNotInOriginal = (element, parent, key) => {
1743
+ const childElems = getCapitalCaseKeys(element.props);
1744
+ if (!childElems.length)
1745
+ return element;
1746
+ for (const i in childElems) {
1747
+ const childKey = childElems[i];
1748
+ const childElem = element[childKey];
1749
+ const newChild = element.props[childKey];
1750
+ if (newChild == null ? void 0 : newChild.ignoreExtend)
1751
+ continue;
1752
+ if (!childElem)
1753
+ element[childKey] = (0, import__.deepCloneWithExtend)(newChild);
1754
+ else {
1755
+ const isSugar = checkIfSugar(childElem);
1756
+ if (!isSugar)
1757
+ continue;
1758
+ const inheritedChildElem = element[childKey].props;
1759
+ if ((0, import__.isObjectLike)(newChild)) {
1760
+ (0, import__.overwriteDeep)(inheritedChildElem, newChild);
1761
+ } else if ((0, import__.isFunction)(newChild)) {
1762
+ element[childKey] = {
1763
+ extend: element[childKey],
1764
+ props: newChild
1765
+ };
1766
+ }
1767
+ }
1768
+ }
1769
+ };
1610
1770
  var applyKeyComponentAsExtend = (element, parent, key) => {
1611
1771
  return extendizeByKey(element, parent, key) || element;
1612
1772
  };
@@ -1682,6 +1842,17 @@ var require_component = __commonJS({
1682
1842
  traverse(obj);
1683
1843
  return result;
1684
1844
  };
1845
+ var setContentKey = (el, opts = {}) => {
1846
+ const { __ref: ref } = el;
1847
+ const contentElementKey = opts.contentElementKey;
1848
+ if (contentElementKey !== "content" && contentElementKey !== ref.contentElementKey || !ref.contentElementKey) {
1849
+ ref.contentElementKey = contentElementKey || "content";
1850
+ } else
1851
+ ref.contentElementKey = "content";
1852
+ if (contentElementKey !== "content")
1853
+ opts.contentElementKey = "content";
1854
+ return ref.contentElementKey;
1855
+ };
1685
1856
  }
1686
1857
  });
1687
1858
 
@@ -302,6 +302,8 @@ var require_array = __commonJS({
302
302
  arraysEqual: () => arraysEqual,
303
303
  cutArrayAfterValue: () => cutArrayAfterValue,
304
304
  cutArrayBeforeValue: () => cutArrayBeforeValue,
305
+ filterArrays: () => filterArrays,
306
+ filterArraysFast: () => filterArraysFast,
305
307
  getFrequencyInArray: () => getFrequencyInArray,
306
308
  joinArrays: () => joinArrays,
307
309
  mergeAndCloneIfArray: () => mergeAndCloneIfArray,
@@ -410,6 +412,13 @@ var require_array = __commonJS({
410
412
  }
411
413
  return true;
412
414
  };
415
+ var filterArrays = (sourceArr, excludeArr) => {
416
+ return sourceArr.filter((item) => !excludeArr.includes(item));
417
+ };
418
+ var filterArraysFast = (sourceArr, excludeArr) => {
419
+ const excludeSet = new Set(excludeArr);
420
+ return sourceArr.filter((item) => !excludeSet.has(item));
421
+ };
413
422
  }
414
423
  });
415
424
 
@@ -597,14 +606,17 @@ var require_object = __commonJS({
597
606
  deepDiff: () => deepDiff,
598
607
  deepMerge: () => deepMerge,
599
608
  deepStringify: () => deepStringify,
609
+ deepStringifyWithMaxDepth: () => deepStringifyWithMaxDepth,
600
610
  detachFunctionsFromObject: () => detachFunctionsFromObject,
601
611
  detectInfiniteLoop: () => detectInfiniteLoop,
602
612
  diff: () => diff,
603
613
  diffArrays: () => diffArrays,
604
614
  diffObjects: () => diffObjects,
615
+ excludeKeysFromObject: () => excludeKeysFromObject,
605
616
  exec: () => exec,
606
617
  flattenRecursive: () => flattenRecursive,
607
618
  hasOwnProperty: () => hasOwnProperty,
619
+ isCyclic: () => isCyclic,
608
620
  isEmpty: () => isEmpty,
609
621
  isEmptyObject: () => isEmptyObject,
610
622
  isEqualDeep: () => isEqualDeep,
@@ -630,7 +642,8 @@ var require_object = __commonJS({
630
642
  var ENV = "development";
631
643
  var exec = (param, element, state, context) => {
632
644
  if ((0, import_types.isFunction)(param)) {
633
- return param(
645
+ return param.call(
646
+ element,
634
647
  element,
635
648
  state || element.state,
636
649
  context || element.context
@@ -729,24 +742,37 @@ var require_object = __commonJS({
729
742
  }
730
743
  return clone2;
731
744
  };
732
- var deepCloneWithExtend = (obj, excludeFrom = ["node"], options = {}) => {
745
+ var deepCloneWithExtend = (obj, excludeFrom = ["node"], options = {}, visited = /* @__PURE__ */ new WeakSet()) => {
746
+ if ((0, import_types.isObjectLike)(obj)) {
747
+ if (visited.has(obj)) {
748
+ return obj;
749
+ }
750
+ visited.add(obj);
751
+ }
733
752
  const o = options.window ? (0, import_types.isArray)(obj) ? new options.window.Array([]) : new options.window.Object({}) : (0, import_types.isArray)(obj) ? [] : {};
734
753
  for (const prop in obj) {
735
754
  if (!Object.prototype.hasOwnProperty.call(obj, prop))
736
755
  continue;
737
756
  const objProp = obj[prop];
738
- if (excludeFrom.includes(prop) || prop.startsWith("__") || options.cleanUndefined && (0, import_types.isUndefined)(objProp) || options.cleanNull && (0, import_types.isNull)(objProp))
757
+ if (excludeFrom.includes(prop) || prop.startsWith("__") || options.cleanUndefined && (0, import_types.isUndefined)(objProp) || options.cleanNull && (0, import_types.isNull)(objProp)) {
739
758
  continue;
759
+ }
740
760
  if ((0, import_types.isObjectLike)(objProp)) {
741
- o[prop] = deepCloneWithExtend(objProp, excludeFrom, options);
761
+ o[prop] = deepCloneWithExtend(objProp, excludeFrom, options, visited);
742
762
  } else if ((0, import_types.isFunction)(objProp) && options.window) {
743
763
  o[prop] = (options.window || import_globals.window).eval("(" + objProp.toString() + ")");
744
- } else
764
+ } else {
745
765
  o[prop] = objProp;
766
+ }
746
767
  }
747
768
  return o;
748
769
  };
749
770
  var deepStringify = (obj, stringified = {}) => {
771
+ var _a;
772
+ if (obj.node || obj.__ref || obj.parent || obj.__element || obj.parse) {
773
+ console.warn("Trying to clone element or state at", obj);
774
+ obj = (_a = obj.parse) == null ? void 0 : _a.call(obj);
775
+ }
750
776
  for (const prop in obj) {
751
777
  const objProp = obj[prop];
752
778
  if ((0, import_types.isFunction)(objProp)) {
@@ -772,6 +798,39 @@ var require_object = __commonJS({
772
798
  }
773
799
  return stringified;
774
800
  };
801
+ var MAX_DEPTH = 100;
802
+ var deepStringifyWithMaxDepth = (obj, stringified = {}, depth = 0, path = "") => {
803
+ if (depth > MAX_DEPTH) {
804
+ console.warn(`Maximum depth exceeded at path: ${path}. Possible circular reference.`);
805
+ return "[MAX_DEPTH_EXCEEDED]";
806
+ }
807
+ for (const prop in obj) {
808
+ const currentPath = path ? `${path}.${prop}` : prop;
809
+ const objProp = obj[prop];
810
+ if ((0, import_types.isFunction)(objProp)) {
811
+ stringified[prop] = objProp.toString();
812
+ } else if ((0, import_types.isObject)(objProp)) {
813
+ stringified[prop] = {};
814
+ deepStringifyWithMaxDepth(objProp, stringified[prop], depth + 1, currentPath);
815
+ } else if ((0, import_types.isArray)(objProp)) {
816
+ stringified[prop] = [];
817
+ objProp.forEach((v, i) => {
818
+ const itemPath = `${currentPath}[${i}]`;
819
+ if ((0, import_types.isObject)(v)) {
820
+ stringified[prop][i] = {};
821
+ deepStringifyWithMaxDepth(v, stringified[prop][i], depth + 1, itemPath);
822
+ } else if ((0, import_types.isFunction)(v)) {
823
+ stringified[prop][i] = v.toString();
824
+ } else {
825
+ stringified[prop][i] = v;
826
+ }
827
+ });
828
+ } else {
829
+ stringified[prop] = objProp;
830
+ }
831
+ }
832
+ return stringified;
833
+ };
775
834
  var objectToString = (obj = {}, indent = 0) => {
776
835
  const spaces = " ".repeat(indent);
777
836
  let str = "{\n";
@@ -881,7 +940,7 @@ var require_object = __commonJS({
881
940
  };
882
941
  var stringToObject = (str, opts = { verbose: true }) => {
883
942
  try {
884
- return import_globals.window.eval("(" + str + ")");
943
+ return str ? import_globals.window.eval("(" + str + ")") : {};
885
944
  } catch (e) {
886
945
  if (opts.verbose)
887
946
  console.warn(e);
@@ -961,20 +1020,27 @@ var require_object = __commonJS({
961
1020
  return acc;
962
1021
  }, deletedValues);
963
1022
  };
964
- var overwrite = (element, params, excludeFrom = []) => {
965
- const { ref } = element;
966
- const changes = {};
1023
+ var overwrite = (element, params, opts = {}) => {
1024
+ const { __ref: ref } = element;
1025
+ const excl = opts.exclude || [];
1026
+ const allowUnderscore = opts.preventUnderscore;
1027
+ const preventCaching = opts.preventCaching;
967
1028
  for (const e in params) {
968
- if (excludeFrom.includes(e) || e.startsWith("__"))
1029
+ if (excl.includes(e) || !allowUnderscore && e.startsWith("__"))
969
1030
  continue;
970
1031
  const elementProp = element[e];
971
1032
  const paramsProp = params[e];
972
- if (paramsProp) {
973
- ref.__cache[e] = changes[e] = elementProp;
974
- ref[e] = paramsProp;
1033
+ if (paramsProp !== void 0) {
1034
+ element[e] = paramsProp;
1035
+ if (ref && !preventCaching) {
1036
+ ref.__cache[e] = elementProp;
1037
+ }
1038
+ if ((0, import_types.isObject)(opts.diff)) {
1039
+ diff[e] = elementProp;
1040
+ }
975
1041
  }
976
1042
  }
977
- return changes;
1043
+ return element;
978
1044
  };
979
1045
  var overwriteShallow = (obj, params, excludeFrom = []) => {
980
1046
  for (const e in params) {
@@ -984,23 +1050,26 @@ var require_object = __commonJS({
984
1050
  }
985
1051
  return obj;
986
1052
  };
987
- var overwriteDeep = (obj, params, excludeFrom = [], visited = /* @__PURE__ */ new WeakMap()) => {
1053
+ var overwriteDeep = (obj, params, opts = {}, visited = /* @__PURE__ */ new WeakMap()) => {
1054
+ const excl = opts.exclude || [];
1055
+ const forcedExclude = opts.preventForce ? [] : ["node", "window"];
988
1056
  if (!(0, import_types.isObjectLike)(obj) || !(0, import_types.isObjectLike)(params) || (0, import_node.isDOMNode)(obj) || (0, import_node.isDOMNode)(params)) {
989
1057
  return params;
990
1058
  }
991
- if (visited.has(obj)) {
1059
+ if (visited.has(obj))
992
1060
  return visited.get(obj);
993
- }
994
1061
  visited.set(obj, obj);
995
1062
  for (const e in params) {
996
- if (e === "__ref" || excludeFrom.includes(e) || e.startsWith("__"))
1063
+ if (!Object.hasOwnProperty.call(params, e))
1064
+ continue;
1065
+ if (excl.includes(e) || forcedExclude && e.startsWith("__"))
997
1066
  continue;
998
1067
  const objProp = obj[e];
999
1068
  const paramsProp = params[e];
1000
1069
  if ((0, import_node.isDOMNode)(paramsProp)) {
1001
1070
  obj[e] = paramsProp;
1002
1071
  } else if ((0, import_types.isObjectLike)(objProp) && (0, import_types.isObjectLike)(paramsProp)) {
1003
- obj[e] = overwriteDeep(objProp, paramsProp, excludeFrom, visited);
1072
+ obj[e] = overwriteDeep(objProp, paramsProp, opts, visited);
1004
1073
  } else if (paramsProp !== void 0) {
1005
1074
  obj[e] = paramsProp;
1006
1075
  }
@@ -1163,6 +1232,30 @@ var require_object = __commonJS({
1163
1232
  }
1164
1233
  }
1165
1234
  };
1235
+ var isCyclic = (obj) => {
1236
+ const seenObjects = [];
1237
+ function detect(obj2) {
1238
+ if (obj2 && typeof obj2 === "object") {
1239
+ if (seenObjects.indexOf(obj2) !== -1) {
1240
+ return true;
1241
+ }
1242
+ seenObjects.push(obj2);
1243
+ for (const key in obj2) {
1244
+ if (Object.hasOwnProperty.call(obj2, key) && detect(obj2[key])) {
1245
+ console.log(obj2, "cycle at " + key);
1246
+ return true;
1247
+ }
1248
+ }
1249
+ }
1250
+ return false;
1251
+ }
1252
+ return detect(obj);
1253
+ };
1254
+ var excludeKeysFromObject = (obj, excludedKeys) => {
1255
+ const result = { ...obj };
1256
+ excludedKeys.forEach((key) => delete result[key]);
1257
+ return result;
1258
+ };
1166
1259
  }
1167
1260
  });
1168
1261
 
@@ -1319,6 +1412,7 @@ var require_cookie = __commonJS({
1319
1412
  __export2(cookie_exports, {
1320
1413
  getCookie: () => getCookie,
1321
1414
  isMobile: () => isMobile,
1415
+ removeCookie: () => removeCookie,
1322
1416
  setCookie: () => setCookie
1323
1417
  });
1324
1418
  module2.exports = __toCommonJS2(cookie_exports);
@@ -1348,6 +1442,11 @@ var require_cookie = __commonJS({
1348
1442
  }
1349
1443
  return "";
1350
1444
  };
1445
+ var removeCookie = (cname) => {
1446
+ if ((0, import_types.isUndefined)(import_utils2.document) || (0, import_types.isUndefined)(import_utils2.document.cookie))
1447
+ return;
1448
+ import_utils2.document.cookie = cname + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
1449
+ };
1351
1450
  }
1352
1451
  });
1353
1452
 
@@ -1387,10 +1486,13 @@ var require_tags = __commonJS({
1387
1486
  "title",
1388
1487
  "base",
1389
1488
  "meta",
1390
- "style"
1489
+ "style",
1490
+ "noscript",
1491
+ "script"
1391
1492
  ],
1392
1493
  body: [
1393
1494
  "string",
1495
+ "style",
1394
1496
  "fragment",
1395
1497
  "a",
1396
1498
  "abbr",
@@ -1543,6 +1645,7 @@ var require_component = __commonJS({
1543
1645
  var component_exports = {};
1544
1646
  __export2(component_exports, {
1545
1647
  addAdditionalExtend: () => addAdditionalExtend,
1648
+ addChildrenIfNotInOriginal: () => addChildrenIfNotInOriginal,
1546
1649
  applyComponentFromContext: () => applyComponentFromContext,
1547
1650
  applyKeyComponentAsExtend: () => applyKeyComponentAsExtend,
1548
1651
  checkIfKeyIsComponent: () => checkIfKeyIsComponent,
@@ -1551,7 +1654,8 @@ var require_component = __commonJS({
1551
1654
  getChildrenComponentsByKey: () => getChildrenComponentsByKey,
1552
1655
  getExtendsInElement: () => getExtendsInElement,
1553
1656
  hasVariantProp: () => hasVariantProp,
1554
- isVariant: () => isVariant
1657
+ isVariant: () => isVariant,
1658
+ setContentKey: () => setContentKey
1555
1659
  });
1556
1660
  module2.exports = __toCommonJS2(component_exports);
1557
1661
  var import__ = require_cjs();
@@ -1571,26 +1675,51 @@ var require_component = __commonJS({
1571
1675
  return /^[a-z]*$/.test(firstCharKey);
1572
1676
  };
1573
1677
  var addAdditionalExtend = (newExtend, element) => {
1678
+ if (!newExtend)
1679
+ return element;
1574
1680
  const { extend: elementExtend } = element;
1575
1681
  const originalArray = (0, import__.isArray)(elementExtend) ? elementExtend : [elementExtend];
1576
1682
  const receivedArray = (0, import__.isArray)(newExtend) ? newExtend : [newExtend];
1577
1683
  const extend = (0, import__.joinArrays)(receivedArray, originalArray);
1578
1684
  return { ...element, extend };
1579
1685
  };
1686
+ var checkIfSugar = (element, parent, key) => {
1687
+ const {
1688
+ extend,
1689
+ props,
1690
+ childExtend,
1691
+ extends: extendProps,
1692
+ childrenExtends,
1693
+ childProps,
1694
+ children,
1695
+ on,
1696
+ $collection,
1697
+ $stateCollection,
1698
+ $propsCollection
1699
+ } = element;
1700
+ const hasComponentAttrs = extend || childExtend || props || on || $collection || $stateCollection || $propsCollection;
1701
+ if (hasComponentAttrs && (childProps || extendProps || children || childrenExtends)) {
1702
+ element.error("Sugar component includes params for builtin components");
1703
+ }
1704
+ return !hasComponentAttrs || childProps || extendProps || children || childrenExtends;
1705
+ };
1580
1706
  var extendizeByKey = (element, parent, key) => {
1581
1707
  const { context } = parent;
1582
- const { tag, extend, props, attr, state, childExtend, childProps, on, if: condition, data } = element;
1583
- const hasComponentAttrs = extend || childExtend || props || state || on || condition || attr || data;
1708
+ const { tag, extend, childrenExtends } = element;
1709
+ const isSugar = checkIfSugar(element);
1584
1710
  const extendFromKey = key.includes("+") ? key.split("+") : key.includes("_") ? [key.split("_")[0]] : key.includes(".") && !checkIfKeyIsComponent(key.split(".")[1]) ? [key.split(".")[0]] : [key];
1585
1711
  const isExtendKeyComponent = context && context.components[extendFromKey];
1586
1712
  if (element === isExtendKeyComponent)
1587
1713
  return element;
1588
- else if (!hasComponentAttrs || childProps) {
1589
- return {
1714
+ else if (isSugar) {
1715
+ const newElem = addAdditionalExtend(element.extends, {
1590
1716
  extend: extendFromKey,
1591
1717
  tag,
1592
1718
  props: { ...element }
1593
- };
1719
+ });
1720
+ if (childrenExtends)
1721
+ newElem.childExtend = childrenExtends;
1722
+ return newElem;
1594
1723
  } else if (!extend || extend === true) {
1595
1724
  return {
1596
1725
  ...element,
@@ -1607,6 +1736,37 @@ var require_component = __commonJS({
1607
1736
  };
1608
1737
  }
1609
1738
  };
1739
+ function getCapitalCaseKeys(obj) {
1740
+ return Object.keys(obj).filter((key) => /^[A-Z]/.test(key));
1741
+ }
1742
+ var addChildrenIfNotInOriginal = (element, parent, key) => {
1743
+ const childElems = getCapitalCaseKeys(element.props);
1744
+ if (!childElems.length)
1745
+ return element;
1746
+ for (const i in childElems) {
1747
+ const childKey = childElems[i];
1748
+ const childElem = element[childKey];
1749
+ const newChild = element.props[childKey];
1750
+ if (newChild == null ? void 0 : newChild.ignoreExtend)
1751
+ continue;
1752
+ if (!childElem)
1753
+ element[childKey] = (0, import__.deepCloneWithExtend)(newChild);
1754
+ else {
1755
+ const isSugar = checkIfSugar(childElem);
1756
+ if (!isSugar)
1757
+ continue;
1758
+ const inheritedChildElem = element[childKey].props;
1759
+ if ((0, import__.isObjectLike)(newChild)) {
1760
+ (0, import__.overwriteDeep)(inheritedChildElem, newChild);
1761
+ } else if ((0, import__.isFunction)(newChild)) {
1762
+ element[childKey] = {
1763
+ extend: element[childKey],
1764
+ props: newChild
1765
+ };
1766
+ }
1767
+ }
1768
+ }
1769
+ };
1610
1770
  var applyKeyComponentAsExtend = (element, parent, key) => {
1611
1771
  return extendizeByKey(element, parent, key) || element;
1612
1772
  };
@@ -1682,6 +1842,17 @@ var require_component = __commonJS({
1682
1842
  traverse(obj);
1683
1843
  return result;
1684
1844
  };
1845
+ var setContentKey = (el, opts = {}) => {
1846
+ const { __ref: ref } = el;
1847
+ const contentElementKey = opts.contentElementKey;
1848
+ if (contentElementKey !== "content" && contentElementKey !== ref.contentElementKey || !ref.contentElementKey) {
1849
+ ref.contentElementKey = contentElementKey || "content";
1850
+ } else
1851
+ ref.contentElementKey = "content";
1852
+ if (contentElementKey !== "content")
1853
+ opts.contentElementKey = "content";
1854
+ return ref.contentElementKey;
1855
+ };
1685
1856
  }
1686
1857
  });
1687
1858
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symbo.ls/utils",
3
- "version": "2.11.436",
3
+ "version": "2.11.453",
4
4
  "author": "symbo.ls",
5
5
  "files": [
6
6
  "src",
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "license": "ISC",
26
26
  "dependencies": {
27
- "@domql/utils": "latest"
27
+ "@domql/utils": "^2.5.0"
28
28
  },
29
- "gitHead": "b3af8d5fc0ea1479dd2e2996c35d53e11a54b276"
29
+ "gitHead": "8e5458a957b9d2c75944023e2c31bab157034314"
30
30
  }