@fragmentsx/render-react 1.2.6 → 1.3.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.
Files changed (60) hide show
  1. package/dist/hooks/layer/index.d.ts +0 -1
  2. package/dist/hooks/layer/index.d.ts.map +1 -1
  3. package/dist/hooks/layer/useLayerValue.d.ts.map +1 -1
  4. package/dist/hooks/layer/useLayersValue.d.ts.map +1 -1
  5. package/dist/hooks/layer-styles/useLayerStyles/useLayerBackground.d.ts.map +1 -1
  6. package/dist/hooks/layer-styles/useLayerStyles/useLayerBorder.d.ts.map +1 -1
  7. package/dist/hooks/suspense/index.d.ts +3 -0
  8. package/dist/hooks/suspense/index.d.ts.map +1 -0
  9. package/dist/hooks/suspense/useSuspenseLoadArea.d.ts +6 -0
  10. package/dist/hooks/suspense/useSuspenseLoadArea.d.ts.map +1 -0
  11. package/dist/hooks/suspense/useSuspenseLoadFragment.d.ts +3 -0
  12. package/dist/hooks/suspense/useSuspenseLoadFragment.d.ts.map +1 -0
  13. package/dist/hooks/utils/useExpandedObjectProps.d.ts +12 -0
  14. package/dist/hooks/utils/useExpandedObjectProps.d.ts.map +1 -0
  15. package/dist/index.cjs.js +286 -138
  16. package/dist/index.es.js +287 -139
  17. package/dist/nodes/Area/Area.d.ts +8 -0
  18. package/dist/nodes/Area/Area.d.ts.map +1 -1
  19. package/dist/nodes/Area/hooks/useArea.d.ts +7 -2
  20. package/dist/nodes/Area/hooks/useArea.d.ts.map +1 -1
  21. package/dist/nodes/Area/index.d.ts +1 -0
  22. package/dist/nodes/Area/index.d.ts.map +1 -1
  23. package/dist/nodes/Collection/Collection.d.ts.map +1 -1
  24. package/dist/nodes/CollectionItem/CollectionItem.d.ts.map +1 -1
  25. package/dist/nodes/CollectionItem/hooks/useCollection.d.ts.map +1 -1
  26. package/dist/nodes/Instance/Instance.d.ts.map +1 -1
  27. package/dist/nodes/Instance/hooks/useInstance.d.ts +0 -1
  28. package/dist/nodes/Instance/hooks/useInstance.d.ts.map +1 -1
  29. package/dist/nodes/Instance/hooks/useInstanceProps.d.ts +0 -1
  30. package/dist/nodes/Instance/hooks/useInstanceProps.d.ts.map +1 -1
  31. package/dist/nodes/Instance/test/dual-instance.browser.test.d.ts +2 -0
  32. package/dist/nodes/Instance/test/dual-instance.browser.test.d.ts.map +1 -0
  33. package/dist/utils/index.d.ts +1 -0
  34. package/dist/utils/index.d.ts.map +1 -1
  35. package/dist/utils/layer/duplicateLayer.d.ts.map +1 -1
  36. package/dist/utils/suspense/createSuspenseResource.d.ts +5 -0
  37. package/dist/utils/suspense/createSuspenseResource.d.ts.map +1 -0
  38. package/dist/utils/suspense/createSuspenseResource.test.d.ts +2 -0
  39. package/dist/utils/suspense/createSuspenseResource.test.d.ts.map +1 -0
  40. package/dist/utils/suspense/index.d.ts +4 -0
  41. package/dist/utils/suspense/index.d.ts.map +1 -0
  42. package/dist/utils/suspense/suspenseCache.d.ts +4 -0
  43. package/dist/utils/suspense/suspenseCache.d.ts.map +1 -0
  44. package/dist/utils/suspense/suspenseCache.test.d.ts +2 -0
  45. package/dist/utils/suspense/suspenseCache.test.d.ts.map +1 -0
  46. package/dist/utils/variables/expandObjectProps.d.ts +9 -0
  47. package/dist/utils/variables/expandObjectProps.d.ts.map +1 -0
  48. package/dist/utils/variables/expandObjectProps.test.d.ts +2 -0
  49. package/dist/utils/variables/expandObjectProps.test.d.ts.map +1 -0
  50. package/dist/utils/variables/index.d.ts +2 -1
  51. package/dist/utils/variables/index.d.ts.map +1 -1
  52. package/dist/utils/variables/toCssCustomProperties.d.ts +7 -0
  53. package/dist/utils/variables/toCssCustomProperties.d.ts.map +1 -0
  54. package/package.json +4 -3
  55. package/dist/hooks/layer/useExtractProps.d.ts +0 -9
  56. package/dist/hooks/layer/useExtractProps.d.ts.map +0 -1
  57. package/dist/hooks/layer/useLayerCssVariable.d.ts +0 -8
  58. package/dist/hooks/layer/useLayerCssVariable.d.ts.map +0 -1
  59. package/dist/utils/variables/getCssVariables.d.ts +0 -3
  60. package/dist/utils/variables/getCssVariables.d.ts.map +0 -1
package/dist/index.es.js CHANGED
@@ -2,7 +2,7 @@ import { createContext, useContext, useReducer, useRef, useEffect, useCallback,
2
2
  import { definition, getNormalizeLayer as getNormalizeLayer$1, isVariableLink as isVariableLink$1, parseLayerField } from "@fragmentsx/definition";
3
3
  import { jsx, jsxs } from "react/jsx-runtime";
4
4
  import { useGraph, useGraphStack } from "@graph-state/react";
5
- import { noop, isPrimitive, isObject, generateId, getKey as getKey$1, isValue, pick, toPx, cleanGraph, flattenObject, setKey as setKey$1, toKebabCase, set, get, omit, isFiniteNumber, hashGenerator as hashGenerator$1, isBrowser as isBrowser$1 } from "@fragmentsx/utils";
5
+ import { noop, isPrimitive, isObject, generateId, getKey as getKey$1, isValue, pick, toPx, cleanGraph, setKey as setKey$1, toKebabCase, set, get, omit, isFiniteNumber, hashGenerator as hashGenerator$1, isBrowser as isBrowser$1 } from "@fragmentsx/utils";
6
6
  import { entityOfKey, keyOfEntity, isPartialKey, isLinkKey } from "@graph-state/core";
7
7
  const GlobalManagerContext = createContext(null);
8
8
  const GlobalManagerProvider = GlobalManagerContext.Provider;
@@ -779,23 +779,21 @@ const calcLinearGradient = (angle, values) => {
779
779
  }
780
780
  return `linear-gradient(${angle}deg, ${parts.join(", ")})`;
781
781
  };
782
- const isVariableLink = (value) => {
783
- var _a;
784
- return isLink(value) && ((_a = value == null ? void 0 : value.split(":")) == null ? void 0 : _a.at(0)) === definition.nodes.Variable;
785
- };
786
- const isLink = (value) => {
787
- var _a, _b;
788
- return value && ((_b = (_a = value == null ? void 0 : value.split) == null ? void 0 : _a.call(value, ":")) == null ? void 0 : _b.length) === 2;
782
+ const getOverriderByLayers = (layerKey, layers) => {
783
+ return layers.find((l) => {
784
+ var _a;
785
+ return (_a = l == null ? void 0 : l.overrides) == null ? void 0 : _a.includes(layerKey);
786
+ });
789
787
  };
790
- const getCssVariables = (props) => {
791
- return Object.entries(cleanGraph(flattenObject(props))).reduce(
788
+ const toCssCustomProperties = (props) => {
789
+ return Object.entries(props).reduce(
792
790
  (acc, [key, value]) => {
793
791
  var _a, _b;
794
- if (isVariableLink(value)) {
792
+ if (isVariableLink$1(value)) {
795
793
  const nestedVariableId = (_a = entityOfKey(value)) == null ? void 0 : _a._id;
796
794
  value = `var(--${nestedVariableId})`;
797
795
  }
798
- if ((_b = value == null ? void 0 : value.startsWith) == null ? void 0 : _b.call(value, "http")) {
796
+ if (typeof value === "string" && ((_b = value.startsWith) == null ? void 0 : _b.call(value, "http"))) {
799
797
  value = `url("${value}")`;
800
798
  }
801
799
  acc[`--${key}`] = value;
@@ -804,11 +802,101 @@ const getCssVariables = (props) => {
804
802
  {}
805
803
  );
806
804
  };
807
- const getOverriderByLayers = (layerKey, layers) => {
808
- return layers.find((l) => {
809
- var _a;
810
- return (_a = l == null ? void 0 : l.overrides) == null ? void 0 : _a.includes(layerKey);
811
- });
805
+ const resolveFieldVar = (field, manager) => {
806
+ if (isObject(field) && (field == null ? void 0 : field._id)) {
807
+ return field;
808
+ }
809
+ if (isVariableLink$1(field) && manager) {
810
+ return manager.resolve(field);
811
+ }
812
+ return void 0;
813
+ };
814
+ const toVariableLink = (field) => {
815
+ if (isVariableLink$1(field)) {
816
+ return field;
817
+ }
818
+ if (isObject(field) && (field == null ? void 0 : field._type) && (field == null ? void 0 : field._id)) {
819
+ return keyOfEntity(field);
820
+ }
821
+ return void 0;
822
+ };
823
+ const expandConcreteValue = (objectVar, valueObj, childManager, result) => {
824
+ const fields = cleanGraph(objectVar.fields);
825
+ for (const [fieldName, childField] of Object.entries(fields)) {
826
+ if (!(fieldName in valueObj)) continue;
827
+ const childFieldVar = resolveFieldVar(childField, childManager);
828
+ if (!(childFieldVar == null ? void 0 : childFieldVar._id)) continue;
829
+ const fieldValue = valueObj[fieldName];
830
+ if (childFieldVar.type === definition.variableType.Object && childFieldVar.fields && isObject(fieldValue)) {
831
+ expandConcreteValue(
832
+ childFieldVar,
833
+ fieldValue,
834
+ childManager,
835
+ result
836
+ );
837
+ continue;
838
+ }
839
+ result[childFieldVar._id] = fieldValue;
840
+ }
841
+ };
842
+ const expandVariableValue = (childObjectVar, parentObjectVar, childManager, resolveManager, result) => {
843
+ const childFields = cleanGraph(childObjectVar.fields);
844
+ const parentFields = cleanGraph(parentObjectVar.fields);
845
+ for (const [fieldName, childField] of Object.entries(childFields)) {
846
+ const parentField = parentFields[fieldName];
847
+ if (!parentField) continue;
848
+ const childFieldVar = resolveFieldVar(childField, childManager);
849
+ if (!(childFieldVar == null ? void 0 : childFieldVar._id)) continue;
850
+ const parentFieldVar = resolveFieldVar(parentField, resolveManager);
851
+ if (childFieldVar.type === definition.variableType.Object && childFieldVar.fields && (parentFieldVar == null ? void 0 : parentFieldVar.type) === definition.variableType.Object && (parentFieldVar == null ? void 0 : parentFieldVar.fields)) {
852
+ expandVariableValue(
853
+ childFieldVar,
854
+ parentFieldVar,
855
+ childManager,
856
+ resolveManager,
857
+ result
858
+ );
859
+ continue;
860
+ }
861
+ const parentFieldLink = toVariableLink(parentField);
862
+ if (parentFieldLink) {
863
+ result[childFieldVar._id] = parentFieldLink;
864
+ }
865
+ }
866
+ };
867
+ const expandObjectProps = (props, childManager, parentManager) => {
868
+ if (!childManager) return props;
869
+ const resolveManager = parentManager ?? childManager;
870
+ const result = {};
871
+ for (const [propKey, propValue] of Object.entries(props)) {
872
+ const childVarKey = `Variable:${propKey}`;
873
+ const childVar = childManager.resolve(childVarKey);
874
+ if ((childVar == null ? void 0 : childVar.type) === definition.variableType.Object && (childVar == null ? void 0 : childVar.fields)) {
875
+ if (isVariableLink$1(propValue)) {
876
+ const parentVar = resolveManager.resolve(propValue);
877
+ if ((parentVar == null ? void 0 : parentVar.type) === definition.variableType.Object && (parentVar == null ? void 0 : parentVar.fields)) {
878
+ expandVariableValue(
879
+ childVar,
880
+ parentVar,
881
+ childManager,
882
+ resolveManager,
883
+ result
884
+ );
885
+ continue;
886
+ }
887
+ } else if (isObject(propValue)) {
888
+ expandConcreteValue(
889
+ childVar,
890
+ propValue,
891
+ childManager,
892
+ result
893
+ );
894
+ continue;
895
+ }
896
+ }
897
+ result[propKey] = propValue;
898
+ }
899
+ return result;
812
900
  };
813
901
  const declareFragmentProperty = (manager, property, fragmentLink = manager.$fragment.root) => {
814
902
  const propertyLayer = createLayer(property);
@@ -877,6 +965,49 @@ const loadFragmentManager = async (globalManager, fragmentId) => {
877
965
  }
878
966
  return null;
879
967
  };
968
+ const createSuspenseResource = (key, valueOrPromise, cache) => {
969
+ if (cache.has(key)) return cache.get(key);
970
+ if (!(valueOrPromise instanceof Promise)) {
971
+ const resource2 = {
972
+ read() {
973
+ return valueOrPromise;
974
+ }
975
+ };
976
+ cache.set(key, resource2);
977
+ return resource2;
978
+ }
979
+ let status = "pending";
980
+ let result;
981
+ let error;
982
+ const suspender = valueOrPromise.then(
983
+ (r) => {
984
+ status = "success";
985
+ result = r;
986
+ },
987
+ (e) => {
988
+ status = "error";
989
+ error = e;
990
+ }
991
+ );
992
+ const resource = {
993
+ read() {
994
+ if (status === "pending") throw suspender;
995
+ if (status === "error") throw error;
996
+ return result;
997
+ }
998
+ };
999
+ cache.set(key, resource);
1000
+ return resource;
1001
+ };
1002
+ const globalCache = /* @__PURE__ */ new WeakMap();
1003
+ const getSuspenseCache = (manager) => {
1004
+ let cache = globalCache.get(manager);
1005
+ if (!cache) {
1006
+ cache = /* @__PURE__ */ new Map();
1007
+ globalCache.set(manager, cache);
1008
+ }
1009
+ return cache;
1010
+ };
880
1011
  const duplicateLayer = (manager, layer) => {
881
1012
  var _a;
882
1013
  const layerGraph = manager.resolve(layer, { deep: true });
@@ -884,6 +1015,9 @@ const duplicateLayer = (manager, layer) => {
884
1015
  const linkedMap = {};
885
1016
  const nextLayer = nodeWalker(layerGraph, (key, value, history) => {
886
1017
  const nextId = generateId();
1018
+ if ((value == null ? void 0 : value._type) === definition.nodes.Instance && key === "props") {
1019
+ return cleanGraph(value);
1020
+ }
887
1021
  if (!!value && n(value)) {
888
1022
  linkedMap[keyOfEntity(value)] = keyOfEntity({ ...value, _id: nextId });
889
1023
  const linkedParent = linkedMap == null ? void 0 : linkedMap[getKey$1(value.parent)];
@@ -950,6 +1084,14 @@ const wrapTextInParagraphWithAttributes = (text, attributes) => {
950
1084
  ).map(([key, value]) => `${toKebabCase(key)}: ${value}`).join("; ");
951
1085
  return `<p style="${style}">${text}</p>`;
952
1086
  };
1087
+ const isVariableLink = (value) => {
1088
+ var _a;
1089
+ return isLink(value) && ((_a = value == null ? void 0 : value.split(":")) == null ? void 0 : _a.at(0)) === definition.nodes.Variable;
1090
+ };
1091
+ const isLink = (value) => {
1092
+ var _a, _b;
1093
+ return value && ((_b = (_a = value == null ? void 0 : value.split) == null ? void 0 : _a.call(value, ":")) == null ? void 0 : _b.length) === 2;
1094
+ };
953
1095
  const layerFieldSetter = (manager, layerKey, fieldKey, currentValue) => (value, options) => {
954
1096
  var _a;
955
1097
  const { success, output } = parseLayerField(
@@ -978,26 +1120,8 @@ const layerFieldSetter = (manager, layerKey, fieldKey, currentValue) => (value,
978
1120
  );
979
1121
  }
980
1122
  };
981
- const getLayerCssVariable = (manager, inputValue) => {
982
- var _a;
983
- const isVariable = isVariableLink$1(inputValue);
984
- const variableValue = manager.resolve(manager, inputValue);
985
- const id = (_a = entityOfKey(inputValue)) == null ? void 0 : _a._id;
986
- return {
987
- value: isVariable ? `var(--${id}, ${variableValue == null ? void 0 : variableValue.defaultValue})` : null
988
- };
989
- };
990
- const useLayerCssVariable = (inputValue) => {
991
- var _a;
992
- const { manager } = useContext(FragmentContext);
993
- const isVariable = isVariableLink$1(inputValue);
994
- const { layer } = useNormalizeLayer(inputValue, isVariable ? manager : null);
995
- const variableId = (layer == null ? void 0 : layer._id) ?? ((_a = entityOfKey(inputValue)) == null ? void 0 : _a._id);
996
- return {
997
- value: isVariable ? `var(--${variableId}, ${transformCssValue(layer == null ? void 0 : layer.defaultValue)})` : null
998
- };
999
- };
1000
1123
  const useLayerValue = (layerKey, fieldKey, options) => {
1124
+ var _a;
1001
1125
  const { manager: fragmentManager } = useContext(FragmentContext);
1002
1126
  const resultManager = (options == null ? void 0 : options.manager) ?? fragmentManager;
1003
1127
  if (!resultManager) {
@@ -1027,8 +1151,8 @@ const useLayerValue = (layerKey, fieldKey, options) => {
1027
1151
  }, [updateLayerData]);
1028
1152
  const restore = useCallback(
1029
1153
  (fallbackValue) => {
1030
- var _a, _b, _c;
1031
- const tempValue = ((_c = (_b = resultManager.resolve((_a = resultManager == null ? void 0 : resultManager.$fragment) == null ? void 0 : _a.temp)) == null ? void 0 : _b[key]) == null ? void 0 : _c[fieldKey]) ?? fallbackValue;
1154
+ var _a2, _b, _c;
1155
+ const tempValue = ((_c = (_b = resultManager.resolve((_a2 = resultManager == null ? void 0 : resultManager.$fragment) == null ? void 0 : _a2.temp)) == null ? void 0 : _b[key]) == null ? void 0 : _c[fieldKey]) ?? fallbackValue;
1032
1156
  updateLayerData({ [fieldKey]: tempValue });
1033
1157
  return tempValue;
1034
1158
  },
@@ -1040,15 +1164,16 @@ const useLayerValue = (layerKey, fieldKey, options) => {
1040
1164
  },
1041
1165
  [setter]
1042
1166
  );
1043
- const { value: cssValue } = useLayerCssVariable(rawValue ?? layerValue);
1167
+ const isVariable = isVariableLink$1(rawValue ?? layerValue);
1168
+ const variableId = isVariable ? (_a = entityOfKey(layerValue)) == null ? void 0 : _a._id : null;
1044
1169
  return [
1045
1170
  currentValue,
1046
1171
  updateValue,
1047
1172
  {
1048
1173
  isOverride,
1049
1174
  resetOverride,
1050
- isVariable: isVariableLink$1(rawValue ?? layerValue),
1051
- cssVariableValue: cssValue ?? transformCssValue(currentValue),
1175
+ isVariable,
1176
+ cssVariableValue: isVariable ? `var(--${variableId}, ${transformCssValue(currentValue)})` : transformCssValue(currentValue),
1052
1177
  rawValue,
1053
1178
  restore,
1054
1179
  ...resultManager.entityOfKey(key)
@@ -1279,18 +1404,16 @@ const useLayersValue = (layerKeys, fieldKey, options) => {
1279
1404
  const updateValue = (value, options2) => {
1280
1405
  setter(value, options2);
1281
1406
  };
1282
- const cssValue = (_b = getLayerCssVariable(
1283
- resultManager,
1284
- rawValue ?? layerValue
1285
- )) == null ? void 0 : _b.value;
1407
+ const isVariable = isVariableLink$1(rawValue ?? layerValue);
1408
+ const variableId = isVariable ? (_b = entityOfKey(layerValue)) == null ? void 0 : _b._id : null;
1286
1409
  return [
1287
1410
  currentValue,
1288
1411
  updateValue,
1289
1412
  {
1290
1413
  isOverride,
1291
1414
  resetOverride,
1292
- isVariable: isVariableLink$1(rawValue ?? layerValue),
1293
- cssVariableValue: cssValue ?? currentValue,
1415
+ isVariable,
1416
+ cssVariableValue: isVariable ? `var(--${variableId}, ${transformCssValue(currentValue)})` : transformCssValue(currentValue),
1294
1417
  rawValue,
1295
1418
  restore,
1296
1419
  ...resultManager.entityOfKey(normalizedLayer.layerKey)
@@ -1429,7 +1552,8 @@ const useLayerBackground = (layerKey) => {
1429
1552
  cssImageFillOptions.cssVariableValue,
1430
1553
  cssSolidFill,
1431
1554
  cssImageSize,
1432
- image
1555
+ image,
1556
+ linearGradient
1433
1557
  ]);
1434
1558
  };
1435
1559
  const useLayerDisplay = (layerKey) => {
@@ -1457,17 +1581,18 @@ const useLayerPaint = (paintLinkKey) => {
1457
1581
  };
1458
1582
  };
1459
1583
  const useLayerBorder = (layerKey) => {
1584
+ var _a, _b;
1460
1585
  const [borderLinkKey] = useLayerValue(layerKey, "border");
1461
1586
  const [type] = useLayerValue(borderLinkKey, "type");
1462
1587
  const [width] = useLayerValue(borderLinkKey, "width");
1463
1588
  const [borderPaintLink] = useLayerValue(borderLinkKey, "paint");
1464
1589
  const borderPaint = useLayerPaint(borderPaintLink);
1465
- const borderLinearGradient = useLayerLinearGradient(
1590
+ const borderLinearGradient = (_a = useLayerLinearGradient(
1466
1591
  borderPaint.linearGradientLink
1467
- );
1592
+ )) == null ? void 0 : _a["background-image"];
1468
1593
  const [paintLinkKey] = useLayerValue(layerKey, "paint");
1469
1594
  const paint = useLayerPaint(paintLinkKey);
1470
- const linearGradient = useLayerLinearGradient(paint.linearGradientLink);
1595
+ const linearGradient = (_b = useLayerLinearGradient(paint.linearGradientLink)) == null ? void 0 : _b["background-image"];
1471
1596
  if (type === definition.borderType.None) {
1472
1597
  return {
1473
1598
  border: null
@@ -1476,7 +1601,7 @@ const useLayerBorder = (layerKey) => {
1476
1601
  if (borderPaint.type === definition.paintMode.LinearGradient) {
1477
1602
  let background = `linear-gradient(${paint.solid}, ${paint.solid}) padding-box, ${borderLinearGradient} border-box`;
1478
1603
  if (paint.type === definition.paintMode.LinearGradient) {
1479
- background = `${linearGradient["background-image"]} padding-box, ${borderLinearGradient["background-image"]} border-box`;
1604
+ background = `${linearGradient} padding-box, ${borderLinearGradient} border-box`;
1480
1605
  }
1481
1606
  if (paint.type === definition.paintMode.None) {
1482
1607
  background = `linear-gradient(transparent, transparent) padding-box, ${borderLinearGradient} border-box`;
@@ -1948,40 +2073,52 @@ const useCollection = (layerKey, options) => {
1948
2073
  ...frame
1949
2074
  };
1950
2075
  };
1951
- const useExtractProps = ({
1952
- layerKey,
1953
- definitions,
1954
- manager,
1955
- inputProps
1956
- }) => {
1957
- const flatDefinition = useMemo(() => {
1958
- const acc = [];
1959
- const run = (defLink) => {
1960
- var _a;
1961
- const resolvedDefinition = (_a = getNormalizeLayer(defLink, manager)) == null ? void 0 : _a.layer;
1962
- if ((resolvedDefinition == null ? void 0 : resolvedDefinition.type) === definition.variableType.Array) return;
1963
- if ((resolvedDefinition == null ? void 0 : resolvedDefinition.type) === definition.variableType.Object) {
1964
- Object.values(cleanGraph(resolvedDefinition == null ? void 0 : resolvedDefinition.fields)).forEach(run);
1965
- } else if (isVariableLink$1(defLink)) {
1966
- acc.push(defLink);
2076
+ const collectLeafFieldKeys = (objectVar, manager, keys) => {
2077
+ if (!(objectVar == null ? void 0 : objectVar.fields)) return;
2078
+ const fields = cleanGraph(objectVar.fields);
2079
+ for (const fieldValue of Object.values(fields)) {
2080
+ let fieldVar;
2081
+ let fieldKey;
2082
+ if (isVariableLink$1(fieldValue)) {
2083
+ fieldKey = fieldValue;
2084
+ fieldVar = manager.resolve(fieldKey);
2085
+ } else if (isObject(fieldValue) && (fieldValue == null ? void 0 : fieldValue._type) && (fieldValue == null ? void 0 : fieldValue._id)) {
2086
+ fieldKey = keyOfEntity(fieldValue);
2087
+ fieldVar = fieldValue;
2088
+ }
2089
+ if (!fieldVar || !fieldKey) continue;
2090
+ if (fieldVar.type === definition.variableType.Object && fieldVar.fields) {
2091
+ collectLeafFieldKeys(fieldVar, manager, keys);
2092
+ } else {
2093
+ keys.push(fieldKey);
2094
+ }
2095
+ }
2096
+ };
2097
+ const useExpandedObjectProps = (props, manager, parentManager, definitions) => {
2098
+ const objectFieldKeys = useMemo(() => {
2099
+ if (!manager || !(definitions == null ? void 0 : definitions.length)) return [];
2100
+ const keys = [];
2101
+ for (const defKey of definitions) {
2102
+ const defVar = manager.resolve(defKey);
2103
+ if ((defVar == null ? void 0 : defVar.type) === definition.variableType.Object && (defVar == null ? void 0 : defVar.fields)) {
2104
+ collectLeafFieldKeys(defVar, manager, keys);
1967
2105
  }
1968
- };
1969
- definitions.forEach(run);
1970
- return acc;
1971
- }, [definitions]);
1972
- const definitionsData = useGraphStack(manager, flatDefinition);
1973
- const definitionProps = useMemo(
1974
- () => definitionsData.reduce((acc, definition2) => {
1975
- const defId = definition2._id;
1976
- acc[defId] = (inputProps == null ? void 0 : inputProps[defId]) ?? (definition2 == null ? void 0 : definition2.defaultValue);
1977
- return acc;
1978
- }, {}),
1979
- [inputProps]
2106
+ }
2107
+ return keys;
2108
+ }, [definitions, manager]);
2109
+ const fieldVarLayers = useGraphStack(
2110
+ objectFieldKeys.length ? manager : null,
2111
+ objectFieldKeys
1980
2112
  );
1981
- return cleanGraph({
1982
- ...inputProps,
1983
- ...definitionProps
1984
- });
2113
+ return useMemo(() => {
2114
+ const base = {};
2115
+ for (const layer of fieldVarLayers) {
2116
+ if ((layer == null ? void 0 : layer._id) && (layer == null ? void 0 : layer.defaultValue) != null) {
2117
+ base[layer._id] = layer.defaultValue;
2118
+ }
2119
+ }
2120
+ return { ...base, ...expandObjectProps(props, manager, parentManager) };
2121
+ }, [fieldVarLayers, props, manager, parentManager]);
1985
2122
  };
1986
2123
  const CollectionItem = ({
1987
2124
  layer,
@@ -1992,20 +2129,24 @@ const CollectionItem = ({
1992
2129
  ...restProps
1993
2130
  }) => {
1994
2131
  var _a;
1995
- const layerKey = keyOfEntity(layer);
2132
+ keyOfEntity(layer);
1996
2133
  const definitionId = ((_a = entityOfKey(sourceDefinition)) == null ? void 0 : _a._id) ?? "";
1997
2134
  const value = layer.value ?? layer;
1998
- const props = useExtractProps({
1999
- layerKey,
2000
- definitions: [sourceDefinition],
2001
- inputProps: isObject(value) ? {
2002
- // [definitionId]: layer.value,
2003
- ...value
2004
- } : {
2005
- [definitionId]: value
2006
- },
2007
- manager
2008
- });
2135
+ const inputProps = isObject(value) ? {
2136
+ ...value
2137
+ } : {
2138
+ [definitionId]: value
2139
+ };
2140
+ const props = cleanGraph(inputProps);
2141
+ const definitions = useMemo(
2142
+ () => sourceDefinition ? [sourceDefinition] : [],
2143
+ [sourceDefinition]
2144
+ );
2145
+ const expandedProps = useExpandedObjectProps(props, manager, void 0, definitions);
2146
+ const cssVars = useMemo(
2147
+ () => toCssCustomProperties(expandedProps),
2148
+ [expandedProps]
2149
+ );
2009
2150
  return /* @__PURE__ */ jsx(
2010
2151
  Scope,
2011
2152
  {
@@ -2015,7 +2156,7 @@ const CollectionItem = ({
2015
2156
  type: definition.scopeTypes.CollectionItemScope,
2016
2157
  ...restProps,
2017
2158
  sourceDefinition,
2018
- value: props,
2159
+ value: expandedProps,
2019
2160
  manager
2020
2161
  },
2021
2162
  children: children == null ? void 0 : children.map((child) => /* @__PURE__ */ jsx(
@@ -2023,7 +2164,7 @@ const CollectionItem = ({
2023
2164
  {
2024
2165
  style: {
2025
2166
  display: "contents",
2026
- ...getCssVariables(props ?? {})
2167
+ ...cssVars
2027
2168
  },
2028
2169
  children: /* @__PURE__ */ jsx(FrameElement, { ...restProps, layerKey: child })
2029
2170
  },
@@ -2346,8 +2487,6 @@ const useInstanceProps = (instanceProps) => {
2346
2487
  isTopInstance ? instanceProps == null ? void 0 : instanceProps.fragmentId : null
2347
2488
  );
2348
2489
  const { manager: fragmentContextManager } = useContext(FragmentContext);
2349
- const { properties: definitions, manager: innerFragmentManager } = useFragmentProperties(instanceProps == null ? void 0 : instanceProps.fragmentId);
2350
- const { readVariable } = useReadVariable();
2351
2490
  const fragmentManager = isTopInstance ? loadedManager : fragmentContextManager;
2352
2491
  const [instanceLayer] = useGraph(fragmentManager, instanceProps.layerKey);
2353
2492
  const instanceLayerProps = (instanceLayer == null ? void 0 : instanceLayer.props) ?? {};
@@ -2359,11 +2498,7 @@ const useInstanceProps = (instanceProps) => {
2359
2498
  ...localProps
2360
2499
  };
2361
2500
  }
2362
- const extractProps = useExtractProps({
2363
- definitions,
2364
- manager: fragmentManager,
2365
- inputProps
2366
- });
2501
+ const extractProps = cleanGraph(inputProps);
2367
2502
  useEffect(() => {
2368
2503
  if (isValue(instanceProps == null ? void 0 : instanceProps.props)) {
2369
2504
  setLocalProps(instanceProps.props);
@@ -2371,7 +2506,6 @@ const useInstanceProps = (instanceProps) => {
2371
2506
  }, [instanceProps == null ? void 0 : instanceProps.props]);
2372
2507
  return {
2373
2508
  props: extractProps,
2374
- cssProps: getCssVariables(extractProps),
2375
2509
  onChangeProps: (variableId, value) => {
2376
2510
  var _a;
2377
2511
  setLocalProps((prev) => ({ ...prev, [variableId]: value }));
@@ -2389,7 +2523,7 @@ const useInstance = (instanceProps) => {
2389
2523
  );
2390
2524
  const resultFragmentId = (instanceProps == null ? void 0 : instanceProps.fragmentId) ?? (instanceLayer == null ? void 0 : instanceLayer.fragment);
2391
2525
  const { properties: definitions, manager: innerFragmentManager } = useFragmentProperties(resultFragmentId);
2392
- const { props, cssProps, onChangeProps } = useInstanceProps(instanceProps);
2526
+ const { props, onChangeProps } = useInstanceProps(instanceProps);
2393
2527
  const classnames = useClassnames(
2394
2528
  instanceProps.layerKey,
2395
2529
  innerFragmentManager
@@ -2400,7 +2534,6 @@ const useInstance = (instanceProps) => {
2400
2534
  events,
2401
2535
  definitions,
2402
2536
  props,
2403
- cssProps,
2404
2537
  parentManager,
2405
2538
  innerManager: innerFragmentManager,
2406
2539
  fragmentId: resultFragmentId,
@@ -2408,6 +2541,22 @@ const useInstance = (instanceProps) => {
2408
2541
  onChangeProps
2409
2542
  };
2410
2543
  };
2544
+ const useSuspenseLoadFragment = (globalManager, fragmentId, skip) => {
2545
+ var _a, _b;
2546
+ if (skip || !globalManager || !fragmentId) return;
2547
+ const cache = getSuspenseCache(globalManager);
2548
+ const valueOrPromise = (_b = (_a = globalManager.$load) == null ? void 0 : _a.loadFragment) == null ? void 0 : _b.call(_a, fragmentId);
2549
+ if (valueOrPromise == null) return;
2550
+ createSuspenseResource(`fragment:${fragmentId}`, valueOrPromise, cache).read();
2551
+ };
2552
+ const useSuspenseLoadArea = (globalManager, areaCode, skip) => {
2553
+ var _a, _b;
2554
+ if (skip || !globalManager || !areaCode) return null;
2555
+ const cache = getSuspenseCache(globalManager);
2556
+ const valueOrPromise = (_b = (_a = globalManager.$load) == null ? void 0 : _a.loadArea) == null ? void 0 : _b.call(_a, areaCode);
2557
+ if (valueOrPromise == null) return null;
2558
+ return createSuspenseResource(`area:${areaCode}`, valueOrPromise, cache).read();
2559
+ };
2411
2560
  const InstanceInitial = ({
2412
2561
  Tag: inputTag,
2413
2562
  style = {},
@@ -2415,13 +2564,12 @@ const InstanceInitial = ({
2415
2564
  FrameElement,
2416
2565
  ...instanceProps
2417
2566
  }) => {
2418
- var _a, _b, _c;
2567
+ var _a;
2419
2568
  const ssr = ((_a = instanceProps == null ? void 0 : instanceProps.options) == null ? void 0 : _a.ssr) ?? true;
2420
2569
  const link = useLayerLink(instanceProps.layerKey);
2421
2570
  const Tag = (link == null ? void 0 : link.isLink) ? inputTag ?? "a" : inputTag ?? "div";
2422
2571
  const {
2423
2572
  fragmentId,
2424
- cssProps,
2425
2573
  parentManager,
2426
2574
  events,
2427
2575
  props,
@@ -2434,9 +2582,17 @@ const InstanceInitial = ({
2434
2582
  ...instanceProps,
2435
2583
  pauseInteractions
2436
2584
  });
2437
- if (ssr) {
2438
- (_c = (_b = globalManager == null ? void 0 : globalManager.$load) == null ? void 0 : _b.loadFragment) == null ? void 0 : _c.call(_b, fragmentId, { suspense: true });
2439
- }
2585
+ const expandedProps = useExpandedObjectProps(
2586
+ props,
2587
+ innerManager,
2588
+ parentManager,
2589
+ definitions
2590
+ );
2591
+ const cssVars = useMemo(
2592
+ () => toCssCustomProperties(expandedProps),
2593
+ [expandedProps]
2594
+ );
2595
+ useSuspenseLoadFragment(globalManager, fragmentId, !ssr);
2440
2596
  return /* @__PURE__ */ jsx(
2441
2597
  Scope,
2442
2598
  {
@@ -2444,7 +2600,7 @@ const InstanceInitial = ({
2444
2600
  layerKey: instanceProps.layerKey,
2445
2601
  value: {
2446
2602
  type: definition.scopeTypes.InstanceScope,
2447
- props,
2603
+ props: expandedProps,
2448
2604
  definitions,
2449
2605
  fragmentId,
2450
2606
  documentManager: innerManager,
@@ -2459,14 +2615,14 @@ const InstanceInitial = ({
2459
2615
  definitions,
2460
2616
  innerManager,
2461
2617
  parentManager,
2462
- props
2618
+ props: expandedProps
2463
2619
  },
2464
2620
  children: parentManager ? /* @__PURE__ */ jsx(
2465
2621
  Tag,
2466
2622
  {
2467
2623
  className: classnames,
2468
2624
  "data-key": instanceProps.layerKey,
2469
- style: { ...style, ...cssProps },
2625
+ style: { ...style, ...cssVars },
2470
2626
  ...link.linkProps,
2471
2627
  ...events,
2472
2628
  children: /* @__PURE__ */ jsx(
@@ -2479,7 +2635,7 @@ const InstanceInitial = ({
2479
2635
  }
2480
2636
  )
2481
2637
  }
2482
- ) : /* @__PURE__ */ jsx(Tag, { style: { ...style, ...cssProps }, ...link.linkProps, children: /* @__PURE__ */ jsx(
2638
+ ) : /* @__PURE__ */ jsx(Tag, { style: { ...style, ...cssVars }, ...link.linkProps, children: /* @__PURE__ */ jsx(
2483
2639
  Fragment,
2484
2640
  {
2485
2641
  fragmentId,
@@ -2509,26 +2665,24 @@ const Instance = (props) => {
2509
2665
  ) });
2510
2666
  };
2511
2667
  const useArea = (options) => {
2512
- const { manager: resultGlobalManager, queryArea } = useGlobalManager(
2668
+ var _a;
2669
+ const { manager: resultGlobalManager } = useGlobalManager(
2513
2670
  options == null ? void 0 : options.globalManager
2514
2671
  );
2515
- const [areaData, setAreaData] = useState(queryArea(options.areaCode));
2672
+ const ssr = ((_a = options == null ? void 0 : options.options) == null ? void 0 : _a.ssr) ?? true;
2673
+ const areaData = useSuspenseLoadArea(
2674
+ resultGlobalManager,
2675
+ options.areaCode,
2676
+ !(isBrowser || ssr)
2677
+ );
2516
2678
  const { manager: fragmentManager } = useFragmentManager(
2517
- areaData.fragmentId,
2679
+ areaData == null ? void 0 : areaData.fragmentId,
2518
2680
  resultGlobalManager
2519
2681
  );
2520
2682
  const resultProps = useMemo(
2521
- () => ({ ...(areaData == null ? void 0 : areaData.props) ?? {}, ...(options == null ? void 0 : options.props) ?? [] }),
2683
+ () => ({ ...(areaData == null ? void 0 : areaData.props) ?? {}, ...(options == null ? void 0 : options.props) ?? {} }),
2522
2684
  [areaData, options]
2523
2685
  );
2524
- useEffect(() => {
2525
- (async () => {
2526
- const response = await queryArea(options.areaCode);
2527
- if (response) {
2528
- setAreaData(response);
2529
- }
2530
- })();
2531
- }, []);
2532
2686
  return {
2533
2687
  ...areaData,
2534
2688
  fragmentManager,
@@ -2537,14 +2691,6 @@ const useArea = (options) => {
2537
2691
  };
2538
2692
  };
2539
2693
  const AreaInitial = (areaProps) => {
2540
- var _a, _b, _c;
2541
- const { manager: globalManager } = useGlobalManager(areaProps == null ? void 0 : areaProps.globalManager);
2542
- const ssr = ((_a = areaProps == null ? void 0 : areaProps.options) == null ? void 0 : _a.ssr) ?? true;
2543
- if (isBrowser || ssr) {
2544
- (_c = (_b = globalManager == null ? void 0 : globalManager.$load) == null ? void 0 : _b.loadArea) == null ? void 0 : _c.call(_b, areaProps.areaCode, {
2545
- suspense: true
2546
- });
2547
- }
2548
2694
  const areaData = useArea(areaProps);
2549
2695
  if (!areaData) return null;
2550
2696
  return /* @__PURE__ */ jsx(
@@ -2611,12 +2757,13 @@ export {
2611
2757
  cloneLayer,
2612
2758
  copyLayer,
2613
2759
  createLayer,
2760
+ createSuspenseResource,
2614
2761
  declareFragmentProperty,
2615
2762
  defaultCustomRender,
2616
2763
  duplicateLayer,
2764
+ expandObjectProps,
2617
2765
  findBreakpoint,
2618
2766
  getAllParents,
2619
- getCssVariables,
2620
2767
  getHydratedData,
2621
2768
  getKey,
2622
2769
  getNormalizeLayer,
@@ -2624,6 +2771,7 @@ export {
2624
2771
  getOverriderByLayers,
2625
2772
  getParent,
2626
2773
  getStylesheetKey,
2774
+ getSuspenseCache,
2627
2775
  hashGenerator,
2628
2776
  insertChildren,
2629
2777
  isBrowser,
@@ -2644,6 +2792,7 @@ export {
2644
2792
  serializeData,
2645
2793
  setKey,
2646
2794
  spliceChildren,
2795
+ toCssCustomProperties,
2647
2796
  transformCssValue,
2648
2797
  useArea,
2649
2798
  useCollection,
@@ -2661,7 +2810,6 @@ export {
2661
2810
  useLayerBorder,
2662
2811
  useLayerChildren,
2663
2812
  useLayerCssOverride,
2664
- useLayerCssVariable,
2665
2813
  useLayerDisplay,
2666
2814
  useLayerFlex,
2667
2815
  useLayerLayout,