@symbo.ls/utils 2.11.436 → 2.11.446

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
@@ -597,6 +597,7 @@ var require_object = __commonJS({
597
597
  deepDiff: () => deepDiff,
598
598
  deepMerge: () => deepMerge,
599
599
  deepStringify: () => deepStringify,
600
+ deepStringifyWithMaxDepth: () => deepStringifyWithMaxDepth,
600
601
  detachFunctionsFromObject: () => detachFunctionsFromObject,
601
602
  detectInfiniteLoop: () => detectInfiniteLoop,
602
603
  diff: () => diff,
@@ -630,7 +631,8 @@ var require_object = __commonJS({
630
631
  var ENV = "development";
631
632
  var exec = (param, element, state, context) => {
632
633
  if ((0, import_types.isFunction)(param)) {
633
- return param(
634
+ return param.call(
635
+ element,
634
636
  element,
635
637
  state || element.state,
636
638
  context || element.context
@@ -747,6 +749,11 @@ var require_object = __commonJS({
747
749
  return o;
748
750
  };
749
751
  var deepStringify = (obj, stringified = {}) => {
752
+ var _a;
753
+ if (obj.node || obj.__ref || obj.parent || obj.__element || obj.parse) {
754
+ console.warn("Trying to clone element or state at", obj);
755
+ obj = (_a = obj.parse) == null ? void 0 : _a.call(obj);
756
+ }
750
757
  for (const prop in obj) {
751
758
  const objProp = obj[prop];
752
759
  if ((0, import_types.isFunction)(objProp)) {
@@ -772,6 +779,39 @@ var require_object = __commonJS({
772
779
  }
773
780
  return stringified;
774
781
  };
782
+ var MAX_DEPTH = 100;
783
+ var deepStringifyWithMaxDepth = (obj, stringified = {}, depth = 0, path = "") => {
784
+ if (depth > MAX_DEPTH) {
785
+ console.warn(`Maximum depth exceeded at path: ${path}. Possible circular reference.`);
786
+ return "[MAX_DEPTH_EXCEEDED]";
787
+ }
788
+ for (const prop in obj) {
789
+ const currentPath = path ? `${path}.${prop}` : prop;
790
+ const objProp = obj[prop];
791
+ if ((0, import_types.isFunction)(objProp)) {
792
+ stringified[prop] = objProp.toString();
793
+ } else if ((0, import_types.isObject)(objProp)) {
794
+ stringified[prop] = {};
795
+ deepStringifyWithMaxDepth(objProp, stringified[prop], depth + 1, currentPath);
796
+ } else if ((0, import_types.isArray)(objProp)) {
797
+ stringified[prop] = [];
798
+ objProp.forEach((v, i) => {
799
+ const itemPath = `${currentPath}[${i}]`;
800
+ if ((0, import_types.isObject)(v)) {
801
+ stringified[prop][i] = {};
802
+ deepStringifyWithMaxDepth(v, stringified[prop][i], depth + 1, itemPath);
803
+ } else if ((0, import_types.isFunction)(v)) {
804
+ stringified[prop][i] = v.toString();
805
+ } else {
806
+ stringified[prop][i] = v;
807
+ }
808
+ });
809
+ } else {
810
+ stringified[prop] = objProp;
811
+ }
812
+ }
813
+ return stringified;
814
+ };
775
815
  var objectToString = (obj = {}, indent = 0) => {
776
816
  const spaces = " ".repeat(indent);
777
817
  let str = "{\n";
@@ -1319,6 +1359,7 @@ var require_cookie = __commonJS({
1319
1359
  __export2(cookie_exports, {
1320
1360
  getCookie: () => getCookie,
1321
1361
  isMobile: () => isMobile,
1362
+ removeCookie: () => removeCookie,
1322
1363
  setCookie: () => setCookie
1323
1364
  });
1324
1365
  module2.exports = __toCommonJS2(cookie_exports);
@@ -1348,6 +1389,11 @@ var require_cookie = __commonJS({
1348
1389
  }
1349
1390
  return "";
1350
1391
  };
1392
+ var removeCookie = (cname) => {
1393
+ if ((0, import_types.isUndefined)(import_utils3.document) || (0, import_types.isUndefined)(import_utils3.document.cookie))
1394
+ return;
1395
+ import_utils3.document.cookie = cname + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
1396
+ };
1351
1397
  }
1352
1398
  });
1353
1399
 
@@ -1387,10 +1433,13 @@ var require_tags = __commonJS({
1387
1433
  "title",
1388
1434
  "base",
1389
1435
  "meta",
1390
- "style"
1436
+ "style",
1437
+ "noscript",
1438
+ "script"
1391
1439
  ],
1392
1440
  body: [
1393
1441
  "string",
1442
+ "style",
1394
1443
  "fragment",
1395
1444
  "a",
1396
1445
  "abbr",
@@ -1543,6 +1592,7 @@ var require_component = __commonJS({
1543
1592
  var component_exports = {};
1544
1593
  __export2(component_exports, {
1545
1594
  addAdditionalExtend: () => addAdditionalExtend,
1595
+ addChildrenIfNotInOriginal: () => addChildrenIfNotInOriginal,
1546
1596
  applyComponentFromContext: () => applyComponentFromContext,
1547
1597
  applyKeyComponentAsExtend: () => applyKeyComponentAsExtend,
1548
1598
  checkIfKeyIsComponent: () => checkIfKeyIsComponent,
@@ -1551,7 +1601,8 @@ var require_component = __commonJS({
1551
1601
  getChildrenComponentsByKey: () => getChildrenComponentsByKey,
1552
1602
  getExtendsInElement: () => getExtendsInElement,
1553
1603
  hasVariantProp: () => hasVariantProp,
1554
- isVariant: () => isVariant
1604
+ isVariant: () => isVariant,
1605
+ setContentKey: () => setContentKey
1555
1606
  });
1556
1607
  module2.exports = __toCommonJS2(component_exports);
1557
1608
  var import__ = require_cjs();
@@ -1577,20 +1628,28 @@ var require_component = __commonJS({
1577
1628
  const extend = (0, import__.joinArrays)(receivedArray, originalArray);
1578
1629
  return { ...element, extend };
1579
1630
  };
1631
+ var checkIfSugar = (element, parent, key) => {
1632
+ const { extend, props, childExtend, extends: extendProps, childrenExtends, childProps, children, on, $collection, $stateCollection, $propsCollection } = element;
1633
+ const hasComponentAttrs = extend || childExtend || props || on || $collection || $stateCollection || $propsCollection;
1634
+ return !hasComponentAttrs || childProps || extendProps || children || childrenExtends;
1635
+ };
1580
1636
  var extendizeByKey = (element, parent, key) => {
1581
1637
  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;
1638
+ const { tag, extend, childrenExtends } = element;
1639
+ const isSugar = checkIfSugar(element);
1584
1640
  const extendFromKey = key.includes("+") ? key.split("+") : key.includes("_") ? [key.split("_")[0]] : key.includes(".") && !checkIfKeyIsComponent(key.split(".")[1]) ? [key.split(".")[0]] : [key];
1585
1641
  const isExtendKeyComponent = context && context.components[extendFromKey];
1586
1642
  if (element === isExtendKeyComponent)
1587
1643
  return element;
1588
- else if (!hasComponentAttrs || childProps) {
1589
- return {
1644
+ else if (isSugar) {
1645
+ const newElem = {
1590
1646
  extend: extendFromKey,
1591
1647
  tag,
1592
1648
  props: { ...element }
1593
1649
  };
1650
+ if (childrenExtends)
1651
+ newElem.childExtend = childrenExtends;
1652
+ return newElem;
1594
1653
  } else if (!extend || extend === true) {
1595
1654
  return {
1596
1655
  ...element,
@@ -1607,6 +1666,37 @@ var require_component = __commonJS({
1607
1666
  };
1608
1667
  }
1609
1668
  };
1669
+ function getCapitalCaseKeys(obj) {
1670
+ return Object.keys(obj).filter((key) => /^[A-Z]/.test(key));
1671
+ }
1672
+ var addChildrenIfNotInOriginal = (element, parent, key) => {
1673
+ const childElems = getCapitalCaseKeys(element.props);
1674
+ if (!childElems.length)
1675
+ return element;
1676
+ for (const i in childElems) {
1677
+ const childKey = childElems[i];
1678
+ const childElem = element[childKey];
1679
+ const newChild = element.props[childKey];
1680
+ if (newChild == null ? void 0 : newChild.ignoreExtend)
1681
+ continue;
1682
+ if (!childElem)
1683
+ element[childKey] = (0, import__.deepCloneWithExtend)(newChild);
1684
+ else {
1685
+ const isSugar = checkIfSugar(childElem);
1686
+ if (!isSugar)
1687
+ continue;
1688
+ const inheritedChildElem = element[childKey].props;
1689
+ if ((0, import__.isObjectLike)(newChild)) {
1690
+ (0, import__.overwriteDeep)(inheritedChildElem, newChild);
1691
+ } else if ((0, import__.isFunction)(newChild)) {
1692
+ element[childKey] = {
1693
+ extend: element[childKey],
1694
+ props: newChild
1695
+ };
1696
+ }
1697
+ }
1698
+ }
1699
+ };
1610
1700
  var applyKeyComponentAsExtend = (element, parent, key) => {
1611
1701
  return extendizeByKey(element, parent, key) || element;
1612
1702
  };
@@ -1682,6 +1772,17 @@ var require_component = __commonJS({
1682
1772
  traverse(obj);
1683
1773
  return result;
1684
1774
  };
1775
+ var setContentKey = (el, opts = {}) => {
1776
+ const { __ref: ref } = el;
1777
+ const contentElementKey = opts.contentElementKey;
1778
+ if (contentElementKey !== "content" && contentElementKey !== ref.contentElementKey || !ref.contentElementKey) {
1779
+ ref.contentElementKey = contentElementKey || "content";
1780
+ } else
1781
+ ref.contentElementKey = "content";
1782
+ if (contentElementKey !== "content")
1783
+ opts.contentElementKey = "content";
1784
+ return ref.contentElementKey;
1785
+ };
1685
1786
  }
1686
1787
  });
1687
1788
 
@@ -597,6 +597,7 @@ var require_object = __commonJS({
597
597
  deepDiff: () => deepDiff,
598
598
  deepMerge: () => deepMerge,
599
599
  deepStringify: () => deepStringify,
600
+ deepStringifyWithMaxDepth: () => deepStringifyWithMaxDepth,
600
601
  detachFunctionsFromObject: () => detachFunctionsFromObject,
601
602
  detectInfiniteLoop: () => detectInfiniteLoop,
602
603
  diff: () => diff,
@@ -630,7 +631,8 @@ var require_object = __commonJS({
630
631
  var ENV = "development";
631
632
  var exec = (param, element, state, context) => {
632
633
  if ((0, import_types.isFunction)(param)) {
633
- return param(
634
+ return param.call(
635
+ element,
634
636
  element,
635
637
  state || element.state,
636
638
  context || element.context
@@ -747,6 +749,11 @@ var require_object = __commonJS({
747
749
  return o;
748
750
  };
749
751
  var deepStringify = (obj, stringified = {}) => {
752
+ var _a;
753
+ if (obj.node || obj.__ref || obj.parent || obj.__element || obj.parse) {
754
+ console.warn("Trying to clone element or state at", obj);
755
+ obj = (_a = obj.parse) == null ? void 0 : _a.call(obj);
756
+ }
750
757
  for (const prop in obj) {
751
758
  const objProp = obj[prop];
752
759
  if ((0, import_types.isFunction)(objProp)) {
@@ -772,6 +779,39 @@ var require_object = __commonJS({
772
779
  }
773
780
  return stringified;
774
781
  };
782
+ var MAX_DEPTH = 100;
783
+ var deepStringifyWithMaxDepth = (obj, stringified = {}, depth = 0, path = "") => {
784
+ if (depth > MAX_DEPTH) {
785
+ console.warn(`Maximum depth exceeded at path: ${path}. Possible circular reference.`);
786
+ return "[MAX_DEPTH_EXCEEDED]";
787
+ }
788
+ for (const prop in obj) {
789
+ const currentPath = path ? `${path}.${prop}` : prop;
790
+ const objProp = obj[prop];
791
+ if ((0, import_types.isFunction)(objProp)) {
792
+ stringified[prop] = objProp.toString();
793
+ } else if ((0, import_types.isObject)(objProp)) {
794
+ stringified[prop] = {};
795
+ deepStringifyWithMaxDepth(objProp, stringified[prop], depth + 1, currentPath);
796
+ } else if ((0, import_types.isArray)(objProp)) {
797
+ stringified[prop] = [];
798
+ objProp.forEach((v, i) => {
799
+ const itemPath = `${currentPath}[${i}]`;
800
+ if ((0, import_types.isObject)(v)) {
801
+ stringified[prop][i] = {};
802
+ deepStringifyWithMaxDepth(v, stringified[prop][i], depth + 1, itemPath);
803
+ } else if ((0, import_types.isFunction)(v)) {
804
+ stringified[prop][i] = v.toString();
805
+ } else {
806
+ stringified[prop][i] = v;
807
+ }
808
+ });
809
+ } else {
810
+ stringified[prop] = objProp;
811
+ }
812
+ }
813
+ return stringified;
814
+ };
775
815
  var objectToString = (obj = {}, indent = 0) => {
776
816
  const spaces = " ".repeat(indent);
777
817
  let str = "{\n";
@@ -1319,6 +1359,7 @@ var require_cookie = __commonJS({
1319
1359
  __export2(cookie_exports, {
1320
1360
  getCookie: () => getCookie,
1321
1361
  isMobile: () => isMobile,
1362
+ removeCookie: () => removeCookie,
1322
1363
  setCookie: () => setCookie
1323
1364
  });
1324
1365
  module2.exports = __toCommonJS2(cookie_exports);
@@ -1348,6 +1389,11 @@ var require_cookie = __commonJS({
1348
1389
  }
1349
1390
  return "";
1350
1391
  };
1392
+ var removeCookie = (cname) => {
1393
+ if ((0, import_types.isUndefined)(import_utils2.document) || (0, import_types.isUndefined)(import_utils2.document.cookie))
1394
+ return;
1395
+ import_utils2.document.cookie = cname + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
1396
+ };
1351
1397
  }
1352
1398
  });
1353
1399
 
@@ -1387,10 +1433,13 @@ var require_tags = __commonJS({
1387
1433
  "title",
1388
1434
  "base",
1389
1435
  "meta",
1390
- "style"
1436
+ "style",
1437
+ "noscript",
1438
+ "script"
1391
1439
  ],
1392
1440
  body: [
1393
1441
  "string",
1442
+ "style",
1394
1443
  "fragment",
1395
1444
  "a",
1396
1445
  "abbr",
@@ -1543,6 +1592,7 @@ var require_component = __commonJS({
1543
1592
  var component_exports = {};
1544
1593
  __export2(component_exports, {
1545
1594
  addAdditionalExtend: () => addAdditionalExtend,
1595
+ addChildrenIfNotInOriginal: () => addChildrenIfNotInOriginal,
1546
1596
  applyComponentFromContext: () => applyComponentFromContext,
1547
1597
  applyKeyComponentAsExtend: () => applyKeyComponentAsExtend,
1548
1598
  checkIfKeyIsComponent: () => checkIfKeyIsComponent,
@@ -1551,7 +1601,8 @@ var require_component = __commonJS({
1551
1601
  getChildrenComponentsByKey: () => getChildrenComponentsByKey,
1552
1602
  getExtendsInElement: () => getExtendsInElement,
1553
1603
  hasVariantProp: () => hasVariantProp,
1554
- isVariant: () => isVariant
1604
+ isVariant: () => isVariant,
1605
+ setContentKey: () => setContentKey
1555
1606
  });
1556
1607
  module2.exports = __toCommonJS2(component_exports);
1557
1608
  var import__ = require_cjs();
@@ -1577,20 +1628,28 @@ var require_component = __commonJS({
1577
1628
  const extend = (0, import__.joinArrays)(receivedArray, originalArray);
1578
1629
  return { ...element, extend };
1579
1630
  };
1631
+ var checkIfSugar = (element, parent, key) => {
1632
+ const { extend, props, childExtend, extends: extendProps, childrenExtends, childProps, children, on, $collection, $stateCollection, $propsCollection } = element;
1633
+ const hasComponentAttrs = extend || childExtend || props || on || $collection || $stateCollection || $propsCollection;
1634
+ return !hasComponentAttrs || childProps || extendProps || children || childrenExtends;
1635
+ };
1580
1636
  var extendizeByKey = (element, parent, key) => {
1581
1637
  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;
1638
+ const { tag, extend, childrenExtends } = element;
1639
+ const isSugar = checkIfSugar(element);
1584
1640
  const extendFromKey = key.includes("+") ? key.split("+") : key.includes("_") ? [key.split("_")[0]] : key.includes(".") && !checkIfKeyIsComponent(key.split(".")[1]) ? [key.split(".")[0]] : [key];
1585
1641
  const isExtendKeyComponent = context && context.components[extendFromKey];
1586
1642
  if (element === isExtendKeyComponent)
1587
1643
  return element;
1588
- else if (!hasComponentAttrs || childProps) {
1589
- return {
1644
+ else if (isSugar) {
1645
+ const newElem = {
1590
1646
  extend: extendFromKey,
1591
1647
  tag,
1592
1648
  props: { ...element }
1593
1649
  };
1650
+ if (childrenExtends)
1651
+ newElem.childExtend = childrenExtends;
1652
+ return newElem;
1594
1653
  } else if (!extend || extend === true) {
1595
1654
  return {
1596
1655
  ...element,
@@ -1607,6 +1666,37 @@ var require_component = __commonJS({
1607
1666
  };
1608
1667
  }
1609
1668
  };
1669
+ function getCapitalCaseKeys(obj) {
1670
+ return Object.keys(obj).filter((key) => /^[A-Z]/.test(key));
1671
+ }
1672
+ var addChildrenIfNotInOriginal = (element, parent, key) => {
1673
+ const childElems = getCapitalCaseKeys(element.props);
1674
+ if (!childElems.length)
1675
+ return element;
1676
+ for (const i in childElems) {
1677
+ const childKey = childElems[i];
1678
+ const childElem = element[childKey];
1679
+ const newChild = element.props[childKey];
1680
+ if (newChild == null ? void 0 : newChild.ignoreExtend)
1681
+ continue;
1682
+ if (!childElem)
1683
+ element[childKey] = (0, import__.deepCloneWithExtend)(newChild);
1684
+ else {
1685
+ const isSugar = checkIfSugar(childElem);
1686
+ if (!isSugar)
1687
+ continue;
1688
+ const inheritedChildElem = element[childKey].props;
1689
+ if ((0, import__.isObjectLike)(newChild)) {
1690
+ (0, import__.overwriteDeep)(inheritedChildElem, newChild);
1691
+ } else if ((0, import__.isFunction)(newChild)) {
1692
+ element[childKey] = {
1693
+ extend: element[childKey],
1694
+ props: newChild
1695
+ };
1696
+ }
1697
+ }
1698
+ }
1699
+ };
1610
1700
  var applyKeyComponentAsExtend = (element, parent, key) => {
1611
1701
  return extendizeByKey(element, parent, key) || element;
1612
1702
  };
@@ -1682,6 +1772,17 @@ var require_component = __commonJS({
1682
1772
  traverse(obj);
1683
1773
  return result;
1684
1774
  };
1775
+ var setContentKey = (el, opts = {}) => {
1776
+ const { __ref: ref } = el;
1777
+ const contentElementKey = opts.contentElementKey;
1778
+ if (contentElementKey !== "content" && contentElementKey !== ref.contentElementKey || !ref.contentElementKey) {
1779
+ ref.contentElementKey = contentElementKey || "content";
1780
+ } else
1781
+ ref.contentElementKey = "content";
1782
+ if (contentElementKey !== "content")
1783
+ opts.contentElementKey = "content";
1784
+ return ref.contentElementKey;
1785
+ };
1685
1786
  }
1686
1787
  });
1687
1788
 
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.446",
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": "d042e0c4fc9379b0ca7584f6405cfa2e7c1301d4"
30
30
  }