@fragmentsx/render-react 1.6.2 → 1.7.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 (44) hide show
  1. package/dist/hooks/layer/useReadVariables.d.ts.map +1 -1
  2. package/dist/hooks/layer/useReadVariables.test.d.ts +2 -0
  3. package/dist/hooks/layer/useReadVariables.test.d.ts.map +1 -0
  4. package/dist/hooks/layer/useResolvedLayerVariables.d.ts +1 -0
  5. package/dist/hooks/layer/useResolvedLayerVariables.d.ts.map +1 -1
  6. package/dist/hooks/layer-styles/useLayerStyles/index.d.ts +5 -1
  7. package/dist/hooks/layer-styles/useLayerStyles/index.d.ts.map +1 -1
  8. package/dist/hooks/layer-styles/useLayerStyles/useImagePaint.d.ts +1 -1
  9. package/dist/hooks/layer-styles/useLayerStyles/useImagePaint.d.ts.map +1 -1
  10. package/dist/hooks/layer-styles/useStyleRegistrar.d.ts +8 -0
  11. package/dist/hooks/layer-styles/useStyleRegistrar.d.ts.map +1 -0
  12. package/dist/hooks/utils/useClassnames.d.ts.map +1 -1
  13. package/dist/index.cjs.js +218 -121
  14. package/dist/index.es.js +219 -122
  15. package/dist/nodes/Area/Area.d.ts.map +1 -1
  16. package/dist/nodes/Area/hooks/useArea.types.d.ts +1 -0
  17. package/dist/nodes/Area/hooks/useArea.types.d.ts.map +1 -1
  18. package/dist/nodes/Collection/Collection.d.ts.map +1 -1
  19. package/dist/nodes/Collection/hooks/useCollection.d.ts +0 -1
  20. package/dist/nodes/Collection/hooks/useCollection.d.ts.map +1 -1
  21. package/dist/nodes/CollectionItem/CollectionItem.d.ts.map +1 -1
  22. package/dist/nodes/CollectionItem/hooks/useCollection.d.ts +0 -1
  23. package/dist/nodes/CollectionItem/hooks/useCollection.d.ts.map +1 -1
  24. package/dist/nodes/Frame/Frame.d.ts.map +1 -1
  25. package/dist/nodes/Frame/hooks/useFrame.d.ts +0 -1
  26. package/dist/nodes/Frame/hooks/useFrame.d.ts.map +1 -1
  27. package/dist/nodes/Instance/Instance.d.ts.map +1 -1
  28. package/dist/nodes/Instance/hooks/useInstance.d.ts +1 -1
  29. package/dist/nodes/Instance/hooks/useInstanceProps.d.ts.map +1 -1
  30. package/dist/nodes/Instance/test/collection-isolation.browser.test.d.ts +2 -0
  31. package/dist/nodes/Instance/test/collection-isolation.browser.test.d.ts.map +1 -0
  32. package/dist/nodes/Instance/test/mutate-event.test.d.ts +2 -0
  33. package/dist/nodes/Instance/test/mutate-event.test.d.ts.map +1 -0
  34. package/dist/nodes/Text/Text.d.ts +1 -0
  35. package/dist/nodes/Text/Text.d.ts.map +1 -1
  36. package/dist/nodes/Text/hooks/useTextAttributes.d.ts +0 -1
  37. package/dist/nodes/Text/hooks/useTextAttributes.d.ts.map +1 -1
  38. package/dist/providers/CampaignManager.d.ts +3 -0
  39. package/dist/providers/CampaignManager.d.ts.map +1 -0
  40. package/dist/providers/InstanceContext.d.ts +1 -0
  41. package/dist/providers/InstanceContext.d.ts.map +1 -1
  42. package/dist/providers/index.d.ts +1 -0
  43. package/dist/providers/index.d.ts.map +1 -1
  44. package/package.json +4 -4
package/dist/index.es.js CHANGED
@@ -7,7 +7,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
7
7
  import { useGraph, useGraphStack } from "@graph-state/react";
8
8
  import { cleanGraph, generateId, getKey as getKey$1, isValue, isObject, pick, toPx, setKey as setKey$1, toKebabCase, set, isPrimitive, get, omit, noop, isFiniteNumber, hashGenerator as hashGenerator$1, isBrowser as isBrowser$1 } from "@fragmentsx/utils";
9
9
  import { keyOfEntity, isPartialKey, entityOfKey, isLinkKey } from "@graph-state/core";
10
- import { createAreaManager } from "@fragmentsx/client-core";
10
+ import { createAreaManager, createCampaignManager } from "@fragmentsx/client-core";
11
11
  const GlobalManagerContext = createContext(null);
12
12
  const GlobalManagerProvider = GlobalManagerContext.Provider;
13
13
  const FragmentContext = createContext({
@@ -21,7 +21,8 @@ const InstanceContext = createContext({
21
21
  innerManager: null,
22
22
  props: {},
23
23
  definitions: [],
24
- onChangeProps: null
24
+ onChangeProps: null,
25
+ instanceId: null
25
26
  });
26
27
  const RenderTargetContext = createContext(
27
28
  definition.renderTarget.document
@@ -29,6 +30,8 @@ const RenderTargetContext = createContext(
29
30
  const RenderTargetProvider = RenderTargetContext.Provider;
30
31
  const AreaManagerContext = createContext(null);
31
32
  const AreaManagerProvider = AreaManagerContext.Provider;
33
+ const CampaignManagerContext = createContext(null);
34
+ const CampaignManagerProvider = CampaignManagerContext.Provider;
32
35
  const ScopeContext = createContext([]);
33
36
  const Scope = ({
34
37
  value,
@@ -878,12 +881,13 @@ const extractVariableValue = (input, variableId) => {
878
881
  return void 0;
879
882
  };
880
883
  const useReadVariables = (variableKeys, customManager) => {
881
- var _a, _b, _c, _d;
884
+ var _a, _b, _c, _d, _e;
882
885
  const filterKeys = variableKeys.filter(isVariableLink$1);
883
886
  const { manager: fragmentManager } = useContext(FragmentContext);
884
887
  const { props: instanceProps } = useContext(InstanceContext);
885
888
  const globalManager = useContext(GlobalManagerContext);
886
889
  const areaManager = useContext(AreaManagerContext);
890
+ const campaignManager = useContext(CampaignManagerContext);
887
891
  const scopes = useContext(ScopeContext);
888
892
  const resultManager = customManager ?? ((_a = useContext(InstanceContext)) == null ? void 0 : _a.innerManager) ?? fragmentManager;
889
893
  const safeFilterKeys = resultManager ? filterKeys : [];
@@ -896,6 +900,7 @@ const useReadVariables = (variableKeys, customManager) => {
896
900
  );
897
901
  useGraph(globalManager, (_b = globalManager == null ? void 0 : globalManager.$properties) == null ? void 0 : _b.key);
898
902
  useGraph(areaManager, (_c = areaManager == null ? void 0 : areaManager.$properties) == null ? void 0 : _c.key);
903
+ useGraph(campaignManager, (_d = campaignManager == null ? void 0 : campaignManager.$properties) == null ? void 0 : _d.key);
899
904
  const globalPropertyKeys = useMemo(() => {
900
905
  if (!(globalManager == null ? void 0 : globalManager.$properties)) return [];
901
906
  return filterKeys.filter((key) => globalManager.resolve(key));
@@ -904,54 +909,67 @@ const useReadVariables = (variableKeys, customManager) => {
904
909
  if (!(areaManager == null ? void 0 : areaManager.$properties)) return [];
905
910
  return filterKeys.filter((key) => areaManager.resolve(key));
906
911
  }, [filterKeys, areaManager]);
912
+ const campaignPropertyKeys = useMemo(() => {
913
+ if (!(campaignManager == null ? void 0 : campaignManager.$properties)) return [];
914
+ return filterKeys.filter((key) => campaignManager.resolve(key));
915
+ }, [filterKeys, campaignManager]);
907
916
  useGraphStack(
908
917
  globalPropertyKeys.length ? globalManager : null,
909
918
  globalPropertyKeys
910
919
  );
911
920
  useGraphStack(areaPropertyKeys.length ? areaManager : null, areaPropertyKeys);
912
- const lastCollectionItem = (_d = scopes == null ? void 0 : scopes.findLast) == null ? void 0 : _d.call(
921
+ useGraphStack(
922
+ campaignPropertyKeys.length ? campaignManager : null,
923
+ campaignPropertyKeys
924
+ );
925
+ const lastCollectionItem = (_e = scopes == null ? void 0 : scopes.findLast) == null ? void 0 : _e.call(
913
926
  scopes,
914
927
  (scope) => (scope == null ? void 0 : scope.type) === definition.scopeTypes.CollectionItemScope
915
928
  );
916
929
  return filterKeys.map((variableKey, index) => {
917
930
  var _a2, _b2;
918
931
  variableLayers[index];
919
- const layer = ((_a2 = getNormalizeLayer(variableKey, resultManager)) == null ? void 0 : _a2.layer) ?? null;
932
+ const campaignLayer = campaignManager == null ? void 0 : campaignManager.resolve(variableKey);
933
+ const campaignProp = (campaignLayer == null ? void 0 : campaignLayer.defaultValue) ?? null;
934
+ const areaLayer = areaManager == null ? void 0 : areaManager.resolve(variableKey);
935
+ const areaProp = (areaLayer == null ? void 0 : areaLayer.defaultValue) ?? null;
936
+ const globalLayer = globalManager == null ? void 0 : globalManager.resolve(variableKey);
937
+ const globalProp = (globalLayer == null ? void 0 : globalLayer.defaultValue) ?? null;
938
+ const fragmentLayer = ((_a2 = getNormalizeLayer(variableKey, resultManager)) == null ? void 0 : _a2.layer) ?? null;
939
+ const layer = fragmentLayer ?? campaignLayer ?? areaLayer ?? globalLayer ?? null;
920
940
  const { _id: propertyId } = layer ?? {};
921
941
  let collectionItemProp = void 0;
922
942
  if (lastCollectionItem && propertyId) {
923
943
  collectionItemProp = isPrimitive(lastCollectionItem == null ? void 0 : lastCollectionItem.value) && ((_b2 = entityOfKey(lastCollectionItem == null ? void 0 : lastCollectionItem.sourceDefinition)) == null ? void 0 : _b2._id) === propertyId ? lastCollectionItem == null ? void 0 : lastCollectionItem.value : extractVariableValue(lastCollectionItem == null ? void 0 : lastCollectionItem.value, propertyId);
924
944
  }
925
945
  const instanceProp = (instanceProps == null ? void 0 : instanceProps[propertyId]) ?? null;
926
- const areaLayer = areaManager == null ? void 0 : areaManager.resolve(variableKey);
927
- const areaProp = (areaLayer == null ? void 0 : areaLayer.defaultValue) ?? null;
928
- const globalLayer = globalManager == null ? void 0 : globalManager.resolve(variableKey);
929
- const globalProp = (globalLayer == null ? void 0 : globalLayer.defaultValue) ?? null;
930
- const required = (layer == null ? void 0 : layer.required) ?? false;
931
- const defaultValue = (layer == null ? void 0 : layer.defaultValue) ?? null;
932
- const currentValue = collectionItemProp ?? (variableKey === instanceProp ? null : instanceProp) ?? areaProp ?? globalProp ?? null;
946
+ const required = (fragmentLayer == null ? void 0 : fragmentLayer.required) ?? (layer == null ? void 0 : layer.required) ?? false;
947
+ const defaultValue = (fragmentLayer == null ? void 0 : fragmentLayer.defaultValue) ?? (layer == null ? void 0 : layer.defaultValue) ?? null;
948
+ const currentValue = collectionItemProp ?? (variableKey === instanceProp ? null : instanceProp) ?? campaignProp ?? areaProp ?? globalProp ?? null;
933
949
  const resultValue = required ? currentValue : currentValue ?? defaultValue;
934
950
  if (isVariableLink$1(resultValue)) {
935
951
  const refKey = resultValue;
952
+ const refCampaignLayer = campaignManager == null ? void 0 : campaignManager.resolve(refKey);
936
953
  const refAreaLayer = areaManager == null ? void 0 : areaManager.resolve(refKey);
937
954
  const refGlobalLayer = globalManager == null ? void 0 : globalManager.resolve(refKey);
938
955
  const refFragmentLayer = resultManager == null ? void 0 : resultManager.resolve(refKey);
939
- const refValue = (refAreaLayer == null ? void 0 : refAreaLayer.defaultValue) ?? (refGlobalLayer == null ? void 0 : refGlobalLayer.defaultValue) ?? (refFragmentLayer == null ? void 0 : refFragmentLayer.defaultValue) ?? resultValue;
956
+ const refValue = (refCampaignLayer == null ? void 0 : refCampaignLayer.defaultValue) ?? (refAreaLayer == null ? void 0 : refAreaLayer.defaultValue) ?? (refGlobalLayer == null ? void 0 : refGlobalLayer.defaultValue) ?? (refFragmentLayer == null ? void 0 : refFragmentLayer.defaultValue) ?? resultValue;
940
957
  return {
941
958
  value: refValue,
942
- layer: refAreaLayer ?? refGlobalLayer ?? refFragmentLayer ?? null
959
+ layer: refCampaignLayer ?? refAreaLayer ?? refGlobalLayer ?? refFragmentLayer ?? null
943
960
  };
944
961
  }
945
962
  return {
946
963
  value: resultValue,
947
- layer: layer ?? areaLayer ?? globalLayer ?? null
964
+ layer: layer ?? campaignLayer ?? areaLayer ?? globalLayer ?? null
948
965
  };
949
966
  });
950
967
  };
951
968
  const EMPTY_RESOLVED = {
952
969
  values: {},
953
970
  cssVariableValues: {},
954
- rawValues: {}
971
+ rawValues: {},
972
+ isVariable: {}
955
973
  };
956
974
  const collectVariableKeys = (layer) => {
957
975
  const keys = [];
@@ -977,23 +995,26 @@ const useResolvedLayerVariables = (layer, rawLayer, _customScopes) => {
977
995
  const resolved = useReadVariables(variableKeys);
978
996
  if (!layer) return EMPTY_RESOLVED;
979
997
  const resolvedByKey = {};
998
+ const defaultByKey = {};
980
999
  variableKeys.forEach((key, i) => {
981
- var _a2;
1000
+ var _a2, _b, _c;
982
1001
  resolvedByKey[key] = ((_a2 = resolved[i]) == null ? void 0 : _a2.value) ?? null;
1002
+ defaultByKey[key] = ((_c = (_b = resolved[i]) == null ? void 0 : _b.layer) == null ? void 0 : _c.defaultValue) ?? null;
983
1003
  });
984
1004
  const values = {};
985
1005
  const cssVariableValues = {};
986
1006
  const rawValues = {};
1007
+ const isVariable = {};
987
1008
  const resolveField = (fieldPath, value, raw) => {
988
1009
  var _a2;
989
1010
  rawValues[fieldPath] = raw;
1011
+ isVariable[fieldPath] = isVariableLink$1(value);
990
1012
  if (isVariableLink$1(value)) {
991
- const resolvedValue = resolvedByKey[value] ?? value;
1013
+ const resolvedValue = value in resolvedByKey ? resolvedByKey[value] : value;
992
1014
  values[fieldPath] = resolvedValue;
993
1015
  const variableId = (_a2 = entityOfKey(value)) == null ? void 0 : _a2._id;
994
- cssVariableValues[fieldPath] = `var(--${variableId}, ${transformCssValue(
995
- resolvedValue
996
- )})`;
1016
+ const staticDefault = defaultByKey[value];
1017
+ cssVariableValues[fieldPath] = staticDefault != null ? `var(--${variableId}, ${transformCssValue(staticDefault)})` : `var(--${variableId})`;
997
1018
  } else {
998
1019
  values[fieldPath] = value;
999
1020
  cssVariableValues[fieldPath] = transformCssValue(value);
@@ -1013,7 +1034,7 @@ const useResolvedLayerVariables = (layer, rawLayer, _customScopes) => {
1013
1034
  }
1014
1035
  }
1015
1036
  }
1016
- return { values, cssVariableValues, rawValues };
1037
+ return { values, cssVariableValues, rawValues, isVariable };
1017
1038
  };
1018
1039
  const useRenderTarget = () => {
1019
1040
  const renderTarget = useContext(RenderTargetContext);
@@ -1253,10 +1274,10 @@ const useLayerLinearGradient = (linearGradientLink) => {
1253
1274
  const stopsPosition = useLayersValue(stops, "position");
1254
1275
  const stopValues = useMemo(
1255
1276
  () => (stops == null ? void 0 : stops.flatMap((stop, index) => {
1256
- var _a, _b, _c;
1277
+ var _a, _b;
1257
1278
  return [
1258
- (_b = (_a = stopsValue == null ? void 0 : stopsValue.at(index)) == null ? void 0 : _a.at(2)) == null ? void 0 : _b.cssVariableValue,
1259
- (_c = stopsPosition == null ? void 0 : stopsPosition.at(index)) == null ? void 0 : _c.at(0)
1279
+ (_a = stopsValue == null ? void 0 : stopsValue.at(index)) == null ? void 0 : _a.at(0),
1280
+ (_b = stopsPosition == null ? void 0 : stopsPosition.at(index)) == null ? void 0 : _b.at(0)
1260
1281
  ];
1261
1282
  })) ?? [],
1262
1283
  [stops, stopsValue, stopsPosition]
@@ -1268,6 +1289,38 @@ const useLayerLinearGradient = (linearGradientLink) => {
1268
1289
  [angle, stopValues]
1269
1290
  );
1270
1291
  };
1292
+ const useStyleRegistrar = (layerKey) => {
1293
+ const { manager } = useContext(FragmentContext);
1294
+ const { instanceId } = useContext(InstanceContext);
1295
+ const baseline = {};
1296
+ const instance = {};
1297
+ const hasInstance = !!instanceId;
1298
+ return {
1299
+ add(prop, value, isDynamic) {
1300
+ (isDynamic && hasInstance ? instance : baseline)[prop] = value;
1301
+ },
1302
+ addAll(styles, isDynamic) {
1303
+ if (styles) {
1304
+ Object.assign(isDynamic && hasInstance ? instance : baseline, styles);
1305
+ }
1306
+ },
1307
+ flush() {
1308
+ var _a, _b, _c, _d;
1309
+ (_b = (_a = manager == null ? void 0 : manager.$styleSheet) == null ? void 0 : _a.addBaselineStyle) == null ? void 0 : _b.call(_a, layerKey, baseline);
1310
+ if (instanceId && Object.keys(instance).length > 0) {
1311
+ (_d = (_c = manager == null ? void 0 : manager.$styleSheet) == null ? void 0 : _c.addInstanceStyle) == null ? void 0 : _d.call(
1312
+ _c,
1313
+ layerKey,
1314
+ instanceId,
1315
+ instance
1316
+ );
1317
+ }
1318
+ },
1319
+ getStyles() {
1320
+ return { ...baseline, ...instance };
1321
+ }
1322
+ };
1323
+ };
1271
1324
  const processOptionalSize = (value, type) => {
1272
1325
  if (value === -1) return "";
1273
1326
  if (type === definition.sizing.Fixed) return toPx(value);
@@ -1499,7 +1552,7 @@ const useLayerPosition = (layerKey) => {
1499
1552
  const calcImagePaint = (imageVars) => {
1500
1553
  var _a, _b;
1501
1554
  return {
1502
- background: imageVars.cssVariableValues.src,
1555
+ background: transformCssValue(imageVars.values.src),
1503
1556
  backgroundRepeat: "no-repeat",
1504
1557
  backgroundSize: (_b = (_a = imageVars.values.scale) == null ? void 0 : _a.toLowerCase) == null ? void 0 : _b.call(_a)
1505
1558
  };
@@ -1517,16 +1570,16 @@ const useImagePaint = (imageLinkKey) => {
1517
1570
  };
1518
1571
  const calcLayerBackground = (paintVars, imageVars, imageSizeVars, linearGradient) => {
1519
1572
  const fillType = paintVars.values.type;
1520
- const cssSolidFill = paintVars.cssVariableValues.solid;
1521
- const cssImageSize = imageSizeVars.cssVariableValues.imageSize;
1573
+ const solidFill = paintVars.values.solid;
1574
+ const imageSize = imageSizeVars.values.imageSize;
1522
1575
  if (fillType === definition.paintMode.Solid) {
1523
- return { background: cssSolidFill };
1576
+ return { background: solidFill };
1524
1577
  }
1525
1578
  if (fillType === definition.paintMode.Image) {
1526
1579
  const image = calcImagePaint(imageVars);
1527
1580
  return {
1528
1581
  ...image,
1529
- backgroundSize: cssImageSize ?? image.backgroundSize
1582
+ backgroundSize: imageSize ?? image.backgroundSize
1530
1583
  };
1531
1584
  }
1532
1585
  if (fillType === definition.paintMode.LinearGradient) {
@@ -1644,7 +1697,7 @@ const calcLayerBorder = (borderVars, borderPaintVars, borderLinearGradient, pain
1644
1697
  };
1645
1698
  }
1646
1699
  if (borderPaint.type === definition.paintMode.Solid) {
1647
- return calcBorderSides(type, width, borderPaint.solidCssValue);
1700
+ return calcBorderSides(type, width, borderPaint.solid);
1648
1701
  }
1649
1702
  return { border: null };
1650
1703
  };
@@ -1789,7 +1842,9 @@ const useLayerFlex = (layerKey) => {
1789
1842
  };
1790
1843
  };
1791
1844
  const SKIP_OVERRIDE = { skipOverrideCheck: true };
1792
- const useLayerStyles = (layerKey) => {
1845
+ const useLayerStyles = (layerKey, options) => {
1846
+ const collectStyle = (options == null ? void 0 : options.collectStyle) ?? true;
1847
+ const reg = useStyleRegistrar(layerKey);
1793
1848
  try {
1794
1849
  if (!layerKey) throw new Error("Empty layer key");
1795
1850
  const { manager: fragmentManager } = useContext(FragmentContext);
@@ -1888,24 +1943,47 @@ const useLayerStyles = (layerKey) => {
1888
1943
  const layout = calcLayerLayout(vars);
1889
1944
  const textStyles = calcLayerTextStyles(vars);
1890
1945
  const layerFlex = calcLayerFlex(vars, parentVars);
1891
- return {
1892
- ...background,
1893
- ...border,
1894
- ...position,
1895
- opacity: vars.values.opacity,
1896
- overflow: vars.values.overflow,
1897
- rotate: isValue(vars.values.rotate) ? `${vars.values.rotate}deg` : null,
1898
- "border-radius": isValue(vars.rawValues.borderRadius) ? vars.values.borderRadius : null,
1899
- "white-space": vars.values.whiteSpace,
1900
- "z-index": vars.values.zIndex !== -1 ? vars.values.zIndex : null,
1901
- ...layout,
1902
- ...layerSize,
1903
- ...textStyles,
1904
- ...layerFlex,
1905
- display
1906
- };
1946
+ reg.add("opacity", vars.values.opacity, vars.isVariable.opacity);
1947
+ reg.add("overflow", vars.values.overflow, vars.isVariable.overflow);
1948
+ reg.add(
1949
+ "border-radius",
1950
+ isValue(vars.rawValues.borderRadius) ? vars.values.borderRadius : null,
1951
+ vars.isVariable.borderRadius
1952
+ );
1953
+ reg.add("white-space", vars.values.whiteSpace, vars.isVariable.whiteSpace);
1954
+ reg.add(
1955
+ "rotate",
1956
+ isValue(vars.values.rotate) ? `${vars.values.rotate}deg` : null,
1957
+ vars.isVariable.rotate
1958
+ );
1959
+ reg.add(
1960
+ "z-index",
1961
+ vars.values.zIndex !== -1 ? vars.values.zIndex : null,
1962
+ vars.isVariable.zIndex
1963
+ );
1964
+ const bgDynamic = paintVars.isVariable.solid || paintVars.isVariable.type || imageVars.isVariable.src;
1965
+ reg.addAll(background, bgDynamic);
1966
+ const borderDynamic = borderPaintVars.isVariable.solid || borderVars.isVariable.type;
1967
+ reg.addAll(border, borderDynamic);
1968
+ const posDynamic = vars.isVariable.width || vars.isVariable.height || vars.isVariable.position || vars.isVariable.widthType || vars.isVariable.heightType;
1969
+ reg.addAll(position, posDynamic);
1970
+ const layoutDynamic = vars.isVariable.layerMode || vars.isVariable.layerDirection || vars.isVariable.layerDistribute || vars.isVariable.layerAlign || vars.isVariable.padding || vars.isVariable.layerGap;
1971
+ reg.addAll(layout, layoutDynamic);
1972
+ const flexDynamic = vars.isVariable.widthType || vars.isVariable.heightType || parentVars.isVariable.layerDirection;
1973
+ reg.addAll(layerFlex, flexDynamic);
1974
+ const sizeDynamic = vars.isVariable.minWidth || vars.isVariable.maxWidth || vars.isVariable.minHeight || vars.isVariable.maxHeight;
1975
+ reg.addAll(layerSize, sizeDynamic);
1976
+ const textDynamic = vars.isVariable["attributes.color"];
1977
+ reg.addAll(textStyles, textDynamic);
1978
+ reg.add(
1979
+ "display",
1980
+ display,
1981
+ vars.isVariable.visible || vars.isVariable.layerMode
1982
+ );
1983
+ if (collectStyle) {
1984
+ reg.flush();
1985
+ }
1907
1986
  } catch (e) {
1908
- return {};
1909
1987
  }
1910
1988
  };
1911
1989
  const MAX_NESTING_DEPTH = 5;
@@ -2012,6 +2090,7 @@ const useHash = (layerKey, manager) => {
2012
2090
  };
2013
2091
  const useClassnames = (layerKey, manager) => {
2014
2092
  const hash = useHash(layerKey, manager);
2093
+ const { instanceId } = useContext(InstanceContext);
2015
2094
  const [classnames] = useLayerValue(layerKey, "classnames", { manager });
2016
2095
  const values = useLayersValue(classnames, "value");
2017
2096
  const enables = useLayersValue(classnames, "enabled");
@@ -2023,40 +2102,13 @@ const useClassnames = (layerKey, manager) => {
2023
2102
  [values, enables]
2024
2103
  );
2025
2104
  if (!layerKey || !manager) return null;
2026
- let base = [hash];
2105
+ const instanceHash = instanceId ? hashGenerator$1(instanceId) : null;
2106
+ let base = [hash, instanceHash].filter(Boolean);
2027
2107
  if (classnames == null ? void 0 : classnames.length) {
2028
2108
  base = [...base, ...list];
2029
2109
  }
2030
2110
  return base.join(" ");
2031
2111
  };
2032
- const useStyleSheet = (manager) => {
2033
- var _a, _b;
2034
- const addLayerStyle = useCallback(
2035
- (layerKey, styles, layer) => {
2036
- var _a2, _b2;
2037
- if (!!(manager == null ? void 0 : manager.$styleSheet) && manager && "addStyle" in (manager == null ? void 0 : manager.$styleSheet)) {
2038
- (_b2 = (_a2 = manager == null ? void 0 : manager.$styleSheet) == null ? void 0 : _a2.addStyle) == null ? void 0 : _b2.call(_a2, layerKey, styles, layer);
2039
- }
2040
- },
2041
- [manager]
2042
- );
2043
- const addCssChunk = useCallback(
2044
- (id) => {
2045
- var _a2, _b2;
2046
- if (!!(manager == null ? void 0 : manager.$styleSheet) && manager && "addCssChunk" in (manager == null ? void 0 : manager.$styleSheet)) {
2047
- return (_b2 = (_a2 = manager == null ? void 0 : manager.$styleSheet) == null ? void 0 : _a2.addCssChunk) == null ? void 0 : _b2.call(_a2, id);
2048
- }
2049
- return noop;
2050
- },
2051
- [manager]
2052
- );
2053
- return {
2054
- addLayerStyle,
2055
- addCssChunk,
2056
- mount: ((_a = manager == null ? void 0 : manager.$styleSheet) == null ? void 0 : _a.mount) ?? noop,
2057
- unmount: ((_b = manager == null ? void 0 : manager.$styleSheet) == null ? void 0 : _b.unmount) ?? noop
2058
- };
2059
- };
2060
2112
  const useGlobalManager = (globalManager) => {
2061
2113
  var _a;
2062
2114
  const currentGlobalManager = useContext(GlobalManagerContext);
@@ -2133,7 +2185,7 @@ const useLayerInteractions = (layerKey, options) => {
2133
2185
  }
2134
2186
  }
2135
2187
  },
2136
- [globalManager, fragmentManager, areaScope]
2188
+ [globalManager, fragmentManager, areaScope, onChangeProps]
2137
2189
  );
2138
2190
  useEffect(() => {
2139
2191
  if (!pause && Array.isArray(interactions)) {
@@ -2239,20 +2291,15 @@ const useTextHighlight = (layerKey, options) => {
2239
2291
  const useTextAttributes = (layerKey, options) => {
2240
2292
  const collectStyle = (options == null ? void 0 : options.collectStyle) ?? true;
2241
2293
  const { manager: fragmentManager } = useContext(FragmentContext);
2242
- const styles = useLayerStyles(layerKey);
2294
+ useLayerStyles(layerKey, { collectStyle });
2243
2295
  const highlight = useTextHighlight(layerKey);
2244
2296
  const content = useTextContent(layerKey);
2245
2297
  const classnames = useClassnames(layerKey, fragmentManager);
2246
2298
  const hash = useHash(layerKey, fragmentManager);
2247
- const { addLayerStyle } = useStyleSheet(fragmentManager);
2248
2299
  const events = useLayerInteractions(layerKey, options);
2249
- if (collectStyle) {
2250
- addLayerStyle(layerKey, styles, fragmentManager.resolve(layerKey));
2251
- }
2252
2300
  return {
2253
2301
  hash,
2254
2302
  events,
2255
- styles,
2256
2303
  classnames,
2257
2304
  content,
2258
2305
  highlight
@@ -2279,32 +2326,22 @@ const Text = ({
2279
2326
  }
2280
2327
  }
2281
2328
  ),
2282
- /* @__PURE__ */ jsx(
2283
- "div",
2284
- {
2285
- dangerouslySetInnerHTML: { __html: content }
2286
- }
2287
- )
2329
+ /* @__PURE__ */ jsx("div", { dangerouslySetInnerHTML: { __html: content } })
2288
2330
  ] });
2289
2331
  };
2290
2332
  const useFrame = (layerKey, options) => {
2291
2333
  const collectStyle = (options == null ? void 0 : options.collectStyle) ?? true;
2292
2334
  const { manager: fragmentManager } = useContext(FragmentContext);
2293
2335
  const layer = fragmentManager.entityOfKey(layerKey);
2294
- const styles = useLayerStyles(layerKey);
2336
+ useLayerStyles(layerKey, { collectStyle });
2295
2337
  const children = useLayerChildren(layerKey);
2296
2338
  const classnames = useClassnames(layerKey, fragmentManager);
2297
- const { addLayerStyle } = useStyleSheet(fragmentManager);
2298
2339
  const events = useLayerInteractions(layerKey, options);
2299
2340
  const link = useLayerLink(layerKey);
2300
- if (collectStyle) {
2301
- addLayerStyle(layerKey, styles, fragmentManager.resolve(layerKey));
2302
- }
2303
2341
  return {
2304
2342
  Tag: (link == null ? void 0 : link.isLink) ? (options == null ? void 0 : options.FrameTag) ?? "a" : (options == null ? void 0 : options.FrameTag) ?? "div",
2305
2343
  type: layer == null ? void 0 : layer._type,
2306
2344
  classnames,
2307
- styles,
2308
2345
  children,
2309
2346
  events,
2310
2347
  linkProps: link.linkProps
@@ -2641,12 +2678,15 @@ const CollectionItem = ({
2641
2678
  FrameElement,
2642
2679
  children,
2643
2680
  sourceDefinition,
2681
+ index,
2644
2682
  ...restProps
2645
2683
  }) => {
2646
- var _a;
2684
+ var _a, _b;
2647
2685
  keyOfEntity(layer);
2648
2686
  const definitionId = ((_a = entityOfKey(sourceDefinition)) == null ? void 0 : _a._id) ?? "";
2649
2687
  const value = layer.value ?? layer;
2688
+ const itemId = ((_b = entityOfKey(layer)) == null ? void 0 : _b._id) ?? index;
2689
+ const collectionInstanceId = `ci:${itemId}`;
2650
2690
  const inputProps = {
2651
2691
  [definitionId]: value
2652
2692
  };
@@ -2672,17 +2712,31 @@ const CollectionItem = ({
2672
2712
  value: expandedProps,
2673
2713
  manager
2674
2714
  },
2675
- children: children == null ? void 0 : children.map((child) => /* @__PURE__ */ jsx(
2676
- "div",
2715
+ children: /* @__PURE__ */ jsx(
2716
+ InstanceContext.Provider,
2677
2717
  {
2678
- style: {
2679
- display: "contents",
2680
- ...cssVars
2718
+ value: {
2719
+ layerKey: null,
2720
+ parentManager: null,
2721
+ innerManager: null,
2722
+ props: {},
2723
+ definitions: [],
2724
+ onChangeProps: null,
2725
+ instanceId: collectionInstanceId
2681
2726
  },
2682
- children: /* @__PURE__ */ jsx(FrameElement, { ...restProps, layerKey: child })
2683
- },
2684
- child
2685
- ))
2727
+ children: children == null ? void 0 : children.map((child) => /* @__PURE__ */ jsx(
2728
+ "div",
2729
+ {
2730
+ style: {
2731
+ display: "contents",
2732
+ ...cssVars
2733
+ },
2734
+ children: /* @__PURE__ */ jsx(FrameElement, { ...restProps, layerKey: child })
2735
+ },
2736
+ child
2737
+ ))
2738
+ }
2739
+ )
2686
2740
  }
2687
2741
  );
2688
2742
  };
@@ -2724,6 +2778,7 @@ const Collection = ({
2724
2778
  children: (_a = sourceValue == null ? void 0 : sourceValue.map) == null ? void 0 : _a.call(sourceValue, (itemValue, index) => /* @__PURE__ */ jsx(
2725
2779
  CollectionItem,
2726
2780
  {
2781
+ index,
2727
2782
  layer: itemValue,
2728
2783
  manager: fragmentManager,
2729
2784
  source,
@@ -2755,11 +2810,13 @@ const Frame = ({
2755
2810
  pauseInteractions,
2756
2811
  ...restProps
2757
2812
  }) => {
2758
- const { styles, classnames, children, type, events, linkProps, Tag } = useFrame(layerKey, {
2759
- ...restProps,
2760
- pauseInteractions
2761
- });
2762
- const resultStyles = inputStyles ?? styles;
2813
+ const { classnames, children, type, events, linkProps, Tag } = useFrame(
2814
+ layerKey,
2815
+ {
2816
+ ...restProps,
2817
+ pauseInteractions
2818
+ }
2819
+ );
2763
2820
  const isMounted = useMounted();
2764
2821
  if (isMounted && hidden) {
2765
2822
  return /* @__PURE__ */ jsx("div", {});
@@ -2782,10 +2839,7 @@ const Frame = ({
2782
2839
  {
2783
2840
  className: classnames,
2784
2841
  "data-key": layerKey,
2785
- style: {
2786
- ...resultStyles,
2787
- display: hidden ? "none" : resultStyles.display
2788
- },
2842
+ style: inputStyles ? { ...inputStyles, display: hidden ? "none" : inputStyles.display } : hidden ? { display: "none" } : restProps == null ? void 0 : restProps.style,
2789
2843
  ...events,
2790
2844
  ...linkProps,
2791
2845
  ...restProps,
@@ -2793,6 +2847,34 @@ const Frame = ({
2793
2847
  }
2794
2848
  );
2795
2849
  };
2850
+ const useStyleSheet = (manager) => {
2851
+ var _a, _b;
2852
+ const addLayerStyle = useCallback(
2853
+ (layerKey, styles, layer) => {
2854
+ var _a2, _b2;
2855
+ if (!!(manager == null ? void 0 : manager.$styleSheet) && manager && "addStyle" in (manager == null ? void 0 : manager.$styleSheet)) {
2856
+ (_b2 = (_a2 = manager == null ? void 0 : manager.$styleSheet) == null ? void 0 : _a2.addStyle) == null ? void 0 : _b2.call(_a2, layerKey, styles, layer);
2857
+ }
2858
+ },
2859
+ [manager]
2860
+ );
2861
+ const addCssChunk = useCallback(
2862
+ (id) => {
2863
+ var _a2, _b2;
2864
+ if (!!(manager == null ? void 0 : manager.$styleSheet) && manager && "addCssChunk" in (manager == null ? void 0 : manager.$styleSheet)) {
2865
+ return (_b2 = (_a2 = manager == null ? void 0 : manager.$styleSheet) == null ? void 0 : _a2.addCssChunk) == null ? void 0 : _b2.call(_a2, id);
2866
+ }
2867
+ return noop;
2868
+ },
2869
+ [manager]
2870
+ );
2871
+ return {
2872
+ addLayerStyle,
2873
+ addCssChunk,
2874
+ mount: ((_a = manager == null ? void 0 : manager.$styleSheet) == null ? void 0 : _a.mount) ?? noop,
2875
+ unmount: ((_b = manager == null ? void 0 : manager.$styleSheet) == null ? void 0 : _b.unmount) ?? noop
2876
+ };
2877
+ };
2796
2878
  const useCssChunk = (linkKey) => {
2797
2879
  const { manager } = useContext(FragmentContext);
2798
2880
  const [chunkId] = useLayerValue(linkKey, "chunkId", { manager });
@@ -3097,7 +3179,7 @@ const useInstanceProps = (instanceProps) => {
3097
3179
  const instanceLayerProps = (instanceLayer == null ? void 0 : instanceLayer.props) ?? {};
3098
3180
  const [localProps, setLocalProps] = useState(instanceProps.props ?? {});
3099
3181
  let inputProps = instanceLayerProps;
3100
- if (isTopInstance && isObject(inputProps) && isObject(localProps)) {
3182
+ if (isObject(inputProps) && isObject(localProps)) {
3101
3183
  inputProps = {
3102
3184
  ...inputProps,
3103
3185
  ...localProps
@@ -3149,7 +3231,7 @@ const useInstanceProps = (instanceProps) => {
3149
3231
  );
3150
3232
  continue;
3151
3233
  }
3152
- resolvedProps[key] = resolvedByKey[value] ?? value;
3234
+ resolvedProps[key] = value in resolvedByKey ? resolvedByKey[value] : value;
3153
3235
  }
3154
3236
  }
3155
3237
  useEffect(() => {
@@ -3259,6 +3341,10 @@ const InstanceInitial = ({
3259
3341
  var _a;
3260
3342
  const ssr = ((_a = instanceProps == null ? void 0 : instanceProps.options) == null ? void 0 : _a.ssr) ?? true;
3261
3343
  const link = useLayerLink(instanceProps.layerKey);
3344
+ const parentInstanceId = useContext(InstanceContext).instanceId;
3345
+ const isTopInstance = !(instanceProps == null ? void 0 : instanceProps.layerKey);
3346
+ const instanceIdRef = useRef(isTopInstance ? crypto.randomUUID() : null);
3347
+ const instanceId = parentInstanceId ? `${parentInstanceId}:${instanceProps.layerKey}` : instanceIdRef.current ?? instanceProps.layerKey;
3262
3348
  const Tag = (link == null ? void 0 : link.isLink) ? inputTag ?? "a" : inputTag ?? "div";
3263
3349
  const {
3264
3350
  fragmentId,
@@ -3297,7 +3383,8 @@ const InstanceInitial = ({
3297
3383
  innerManager,
3298
3384
  parentManager,
3299
3385
  props: expandedProps,
3300
- onChangeProps
3386
+ onChangeProps,
3387
+ instanceId
3301
3388
  }),
3302
3389
  [
3303
3390
  instanceProps.layerKey,
@@ -3305,7 +3392,8 @@ const InstanceInitial = ({
3305
3392
  innerManager,
3306
3393
  parentManager,
3307
3394
  expandedProps,
3308
- onChangeProps
3395
+ onChangeProps,
3396
+ instanceId
3309
3397
  ]
3310
3398
  );
3311
3399
  return /* @__PURE__ */ jsx(InstanceContext.Provider, { value: instanceContextValue, children: parentManager ? /* @__PURE__ */ jsx(
@@ -3525,8 +3613,15 @@ const AreaInitial = (areaProps) => {
3525
3613
  }),
3526
3614
  [areaData == null ? void 0 : areaData.areaId]
3527
3615
  );
3616
+ const campaignManager = useMemo(
3617
+ () => (areaData == null ? void 0 : areaData.campaignId) ? createCampaignManager({
3618
+ campaignId: areaData.campaignId,
3619
+ campaignProperties: areaData.campaignProperties ?? void 0
3620
+ }) : null,
3621
+ [areaData == null ? void 0 : areaData.campaignId]
3622
+ );
3528
3623
  if (!areaData) return null;
3529
- return /* @__PURE__ */ jsx(AreaManagerProvider, { value: areaManager, children: /* @__PURE__ */ jsx(
3624
+ return /* @__PURE__ */ jsx(AreaManagerProvider, { value: areaManager, children: /* @__PURE__ */ jsx(CampaignManagerProvider, { value: campaignManager, children: /* @__PURE__ */ jsx(
3530
3625
  Scope,
3531
3626
  {
3532
3627
  fragmentManager,
@@ -3538,7 +3633,7 @@ const AreaInitial = (areaProps) => {
3538
3633
  },
3539
3634
  children: /* @__PURE__ */ jsx(Instance, { fragmentId: areaData.fragmentId, props: resultProps })
3540
3635
  }
3541
- ) });
3636
+ ) }) });
3542
3637
  };
3543
3638
  const Area = (props) => {
3544
3639
  return "globalManager" in props ? /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(GlobalManagerProvider, { value: props.globalManager, children: /* @__PURE__ */ jsx(AreaErrorBoundary, { children: /* @__PURE__ */ jsx(AreaInitial, { ...props }) }) }) }) : /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(AreaErrorBoundary, { children: /* @__PURE__ */ jsx(AreaInitial, { ...props }) }) });
@@ -3567,6 +3662,8 @@ export {
3567
3662
  Area,
3568
3663
  AreaManagerContext,
3569
3664
  AreaManagerProvider,
3665
+ CampaignManagerContext,
3666
+ CampaignManagerProvider,
3570
3667
  Collection,
3571
3668
  CssChunk,
3572
3669
  CustomRender,
@@ -1 +1 @@
1
- {"version":3,"file":"Area.d.ts","sourceRoot":"","sources":["../../../src/nodes/Area/Area.tsx"],"names":[],"mappings":"AAuCA,MAAM,MAAM,WAAW,GAAG,CACxB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAClC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE7B,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,WAAW,CAAC;IAC9C,OAAO,CAAC,EAAE;QACR,GAAG,CAAC,EAAE,OAAO,CAAC;KACf,CAAC;CACH;AAwDD,eAAO,MAAM,IAAI,UAAW,SAAS,4CAgBpC,CAAC"}
1
+ {"version":3,"file":"Area.d.ts","sourceRoot":"","sources":["../../../src/nodes/Area/Area.tsx"],"names":[],"mappings":"AA8CA,MAAM,MAAM,WAAW,GAAG,CACxB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAClC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE7B,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,WAAW,CAAC;IAC9C,OAAO,CAAC,EAAE;QACR,GAAG,CAAC,EAAE,OAAO,CAAC;KACf,CAAC;CACH;AAqED,eAAO,MAAM,IAAI,UAAW,SAAS,4CAgBpC,CAAC"}
@@ -13,6 +13,7 @@ export interface AreaData {
13
13
  campaignId: string;
14
14
  variantId: string;
15
15
  areaProperties?: unknown;
16
+ campaignProperties?: any[] | null;
16
17
  }
17
18
  export interface UseAreaResult {
18
19
  data: AreaData | null;