@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.cjs.js CHANGED
@@ -23,7 +23,8 @@ const InstanceContext = react.createContext({
23
23
  innerManager: null,
24
24
  props: {},
25
25
  definitions: [],
26
- onChangeProps: null
26
+ onChangeProps: null,
27
+ instanceId: null
27
28
  });
28
29
  const RenderTargetContext = react.createContext(
29
30
  definition.definition.renderTarget.document
@@ -31,6 +32,8 @@ const RenderTargetContext = react.createContext(
31
32
  const RenderTargetProvider = RenderTargetContext.Provider;
32
33
  const AreaManagerContext = react.createContext(null);
33
34
  const AreaManagerProvider = AreaManagerContext.Provider;
35
+ const CampaignManagerContext = react.createContext(null);
36
+ const CampaignManagerProvider = CampaignManagerContext.Provider;
34
37
  const ScopeContext = react.createContext([]);
35
38
  const Scope = ({
36
39
  value,
@@ -880,12 +883,13 @@ const extractVariableValue = (input, variableId) => {
880
883
  return void 0;
881
884
  };
882
885
  const useReadVariables = (variableKeys, customManager) => {
883
- var _a, _b, _c, _d;
886
+ var _a, _b, _c, _d, _e;
884
887
  const filterKeys = variableKeys.filter(definition.isVariableLink);
885
888
  const { manager: fragmentManager } = react.useContext(FragmentContext);
886
889
  const { props: instanceProps } = react.useContext(InstanceContext);
887
890
  const globalManager = react.useContext(GlobalManagerContext);
888
891
  const areaManager = react.useContext(AreaManagerContext);
892
+ const campaignManager = react.useContext(CampaignManagerContext);
889
893
  const scopes = react.useContext(ScopeContext);
890
894
  const resultManager = customManager ?? ((_a = react.useContext(InstanceContext)) == null ? void 0 : _a.innerManager) ?? fragmentManager;
891
895
  const safeFilterKeys = resultManager ? filterKeys : [];
@@ -898,6 +902,7 @@ const useReadVariables = (variableKeys, customManager) => {
898
902
  );
899
903
  react$1.useGraph(globalManager, (_b = globalManager == null ? void 0 : globalManager.$properties) == null ? void 0 : _b.key);
900
904
  react$1.useGraph(areaManager, (_c = areaManager == null ? void 0 : areaManager.$properties) == null ? void 0 : _c.key);
905
+ react$1.useGraph(campaignManager, (_d = campaignManager == null ? void 0 : campaignManager.$properties) == null ? void 0 : _d.key);
901
906
  const globalPropertyKeys = react.useMemo(() => {
902
907
  if (!(globalManager == null ? void 0 : globalManager.$properties)) return [];
903
908
  return filterKeys.filter((key) => globalManager.resolve(key));
@@ -906,54 +911,67 @@ const useReadVariables = (variableKeys, customManager) => {
906
911
  if (!(areaManager == null ? void 0 : areaManager.$properties)) return [];
907
912
  return filterKeys.filter((key) => areaManager.resolve(key));
908
913
  }, [filterKeys, areaManager]);
914
+ const campaignPropertyKeys = react.useMemo(() => {
915
+ if (!(campaignManager == null ? void 0 : campaignManager.$properties)) return [];
916
+ return filterKeys.filter((key) => campaignManager.resolve(key));
917
+ }, [filterKeys, campaignManager]);
909
918
  react$1.useGraphStack(
910
919
  globalPropertyKeys.length ? globalManager : null,
911
920
  globalPropertyKeys
912
921
  );
913
922
  react$1.useGraphStack(areaPropertyKeys.length ? areaManager : null, areaPropertyKeys);
914
- const lastCollectionItem = (_d = scopes == null ? void 0 : scopes.findLast) == null ? void 0 : _d.call(
923
+ react$1.useGraphStack(
924
+ campaignPropertyKeys.length ? campaignManager : null,
925
+ campaignPropertyKeys
926
+ );
927
+ const lastCollectionItem = (_e = scopes == null ? void 0 : scopes.findLast) == null ? void 0 : _e.call(
915
928
  scopes,
916
929
  (scope) => (scope == null ? void 0 : scope.type) === definition.definition.scopeTypes.CollectionItemScope
917
930
  );
918
931
  return filterKeys.map((variableKey, index) => {
919
932
  var _a2, _b2;
920
933
  variableLayers[index];
921
- const layer = ((_a2 = getNormalizeLayer(variableKey, resultManager)) == null ? void 0 : _a2.layer) ?? null;
934
+ const campaignLayer = campaignManager == null ? void 0 : campaignManager.resolve(variableKey);
935
+ const campaignProp = (campaignLayer == null ? void 0 : campaignLayer.defaultValue) ?? null;
936
+ const areaLayer = areaManager == null ? void 0 : areaManager.resolve(variableKey);
937
+ const areaProp = (areaLayer == null ? void 0 : areaLayer.defaultValue) ?? null;
938
+ const globalLayer = globalManager == null ? void 0 : globalManager.resolve(variableKey);
939
+ const globalProp = (globalLayer == null ? void 0 : globalLayer.defaultValue) ?? null;
940
+ const fragmentLayer = ((_a2 = getNormalizeLayer(variableKey, resultManager)) == null ? void 0 : _a2.layer) ?? null;
941
+ const layer = fragmentLayer ?? campaignLayer ?? areaLayer ?? globalLayer ?? null;
922
942
  const { _id: propertyId } = layer ?? {};
923
943
  let collectionItemProp = void 0;
924
944
  if (lastCollectionItem && propertyId) {
925
945
  collectionItemProp = utils.isPrimitive(lastCollectionItem == null ? void 0 : lastCollectionItem.value) && ((_b2 = core.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);
926
946
  }
927
947
  const instanceProp = (instanceProps == null ? void 0 : instanceProps[propertyId]) ?? null;
928
- const areaLayer = areaManager == null ? void 0 : areaManager.resolve(variableKey);
929
- const areaProp = (areaLayer == null ? void 0 : areaLayer.defaultValue) ?? null;
930
- const globalLayer = globalManager == null ? void 0 : globalManager.resolve(variableKey);
931
- const globalProp = (globalLayer == null ? void 0 : globalLayer.defaultValue) ?? null;
932
- const required = (layer == null ? void 0 : layer.required) ?? false;
933
- const defaultValue = (layer == null ? void 0 : layer.defaultValue) ?? null;
934
- const currentValue = collectionItemProp ?? (variableKey === instanceProp ? null : instanceProp) ?? areaProp ?? globalProp ?? null;
948
+ const required = (fragmentLayer == null ? void 0 : fragmentLayer.required) ?? (layer == null ? void 0 : layer.required) ?? false;
949
+ const defaultValue = (fragmentLayer == null ? void 0 : fragmentLayer.defaultValue) ?? (layer == null ? void 0 : layer.defaultValue) ?? null;
950
+ const currentValue = collectionItemProp ?? (variableKey === instanceProp ? null : instanceProp) ?? campaignProp ?? areaProp ?? globalProp ?? null;
935
951
  const resultValue = required ? currentValue : currentValue ?? defaultValue;
936
952
  if (definition.isVariableLink(resultValue)) {
937
953
  const refKey = resultValue;
954
+ const refCampaignLayer = campaignManager == null ? void 0 : campaignManager.resolve(refKey);
938
955
  const refAreaLayer = areaManager == null ? void 0 : areaManager.resolve(refKey);
939
956
  const refGlobalLayer = globalManager == null ? void 0 : globalManager.resolve(refKey);
940
957
  const refFragmentLayer = resultManager == null ? void 0 : resultManager.resolve(refKey);
941
- const refValue = (refAreaLayer == null ? void 0 : refAreaLayer.defaultValue) ?? (refGlobalLayer == null ? void 0 : refGlobalLayer.defaultValue) ?? (refFragmentLayer == null ? void 0 : refFragmentLayer.defaultValue) ?? resultValue;
958
+ 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;
942
959
  return {
943
960
  value: refValue,
944
- layer: refAreaLayer ?? refGlobalLayer ?? refFragmentLayer ?? null
961
+ layer: refCampaignLayer ?? refAreaLayer ?? refGlobalLayer ?? refFragmentLayer ?? null
945
962
  };
946
963
  }
947
964
  return {
948
965
  value: resultValue,
949
- layer: layer ?? areaLayer ?? globalLayer ?? null
966
+ layer: layer ?? campaignLayer ?? areaLayer ?? globalLayer ?? null
950
967
  };
951
968
  });
952
969
  };
953
970
  const EMPTY_RESOLVED = {
954
971
  values: {},
955
972
  cssVariableValues: {},
956
- rawValues: {}
973
+ rawValues: {},
974
+ isVariable: {}
957
975
  };
958
976
  const collectVariableKeys = (layer) => {
959
977
  const keys = [];
@@ -979,23 +997,26 @@ const useResolvedLayerVariables = (layer, rawLayer, _customScopes) => {
979
997
  const resolved = useReadVariables(variableKeys);
980
998
  if (!layer) return EMPTY_RESOLVED;
981
999
  const resolvedByKey = {};
1000
+ const defaultByKey = {};
982
1001
  variableKeys.forEach((key, i) => {
983
- var _a2;
1002
+ var _a2, _b, _c;
984
1003
  resolvedByKey[key] = ((_a2 = resolved[i]) == null ? void 0 : _a2.value) ?? null;
1004
+ defaultByKey[key] = ((_c = (_b = resolved[i]) == null ? void 0 : _b.layer) == null ? void 0 : _c.defaultValue) ?? null;
985
1005
  });
986
1006
  const values = {};
987
1007
  const cssVariableValues = {};
988
1008
  const rawValues = {};
1009
+ const isVariable = {};
989
1010
  const resolveField = (fieldPath, value, raw) => {
990
1011
  var _a2;
991
1012
  rawValues[fieldPath] = raw;
1013
+ isVariable[fieldPath] = definition.isVariableLink(value);
992
1014
  if (definition.isVariableLink(value)) {
993
- const resolvedValue = resolvedByKey[value] ?? value;
1015
+ const resolvedValue = value in resolvedByKey ? resolvedByKey[value] : value;
994
1016
  values[fieldPath] = resolvedValue;
995
1017
  const variableId = (_a2 = core.entityOfKey(value)) == null ? void 0 : _a2._id;
996
- cssVariableValues[fieldPath] = `var(--${variableId}, ${transformCssValue(
997
- resolvedValue
998
- )})`;
1018
+ const staticDefault = defaultByKey[value];
1019
+ cssVariableValues[fieldPath] = staticDefault != null ? `var(--${variableId}, ${transformCssValue(staticDefault)})` : `var(--${variableId})`;
999
1020
  } else {
1000
1021
  values[fieldPath] = value;
1001
1022
  cssVariableValues[fieldPath] = transformCssValue(value);
@@ -1015,7 +1036,7 @@ const useResolvedLayerVariables = (layer, rawLayer, _customScopes) => {
1015
1036
  }
1016
1037
  }
1017
1038
  }
1018
- return { values, cssVariableValues, rawValues };
1039
+ return { values, cssVariableValues, rawValues, isVariable };
1019
1040
  };
1020
1041
  const useRenderTarget = () => {
1021
1042
  const renderTarget = react.useContext(RenderTargetContext);
@@ -1255,10 +1276,10 @@ const useLayerLinearGradient = (linearGradientLink) => {
1255
1276
  const stopsPosition = useLayersValue(stops, "position");
1256
1277
  const stopValues = react.useMemo(
1257
1278
  () => (stops == null ? void 0 : stops.flatMap((stop, index) => {
1258
- var _a, _b, _c;
1279
+ var _a, _b;
1259
1280
  return [
1260
- (_b = (_a = stopsValue == null ? void 0 : stopsValue.at(index)) == null ? void 0 : _a.at(2)) == null ? void 0 : _b.cssVariableValue,
1261
- (_c = stopsPosition == null ? void 0 : stopsPosition.at(index)) == null ? void 0 : _c.at(0)
1281
+ (_a = stopsValue == null ? void 0 : stopsValue.at(index)) == null ? void 0 : _a.at(0),
1282
+ (_b = stopsPosition == null ? void 0 : stopsPosition.at(index)) == null ? void 0 : _b.at(0)
1262
1283
  ];
1263
1284
  })) ?? [],
1264
1285
  [stops, stopsValue, stopsPosition]
@@ -1270,6 +1291,38 @@ const useLayerLinearGradient = (linearGradientLink) => {
1270
1291
  [angle, stopValues]
1271
1292
  );
1272
1293
  };
1294
+ const useStyleRegistrar = (layerKey) => {
1295
+ const { manager } = react.useContext(FragmentContext);
1296
+ const { instanceId } = react.useContext(InstanceContext);
1297
+ const baseline = {};
1298
+ const instance = {};
1299
+ const hasInstance = !!instanceId;
1300
+ return {
1301
+ add(prop, value, isDynamic) {
1302
+ (isDynamic && hasInstance ? instance : baseline)[prop] = value;
1303
+ },
1304
+ addAll(styles, isDynamic) {
1305
+ if (styles) {
1306
+ Object.assign(isDynamic && hasInstance ? instance : baseline, styles);
1307
+ }
1308
+ },
1309
+ flush() {
1310
+ var _a, _b, _c, _d;
1311
+ (_b = (_a = manager == null ? void 0 : manager.$styleSheet) == null ? void 0 : _a.addBaselineStyle) == null ? void 0 : _b.call(_a, layerKey, baseline);
1312
+ if (instanceId && Object.keys(instance).length > 0) {
1313
+ (_d = (_c = manager == null ? void 0 : manager.$styleSheet) == null ? void 0 : _c.addInstanceStyle) == null ? void 0 : _d.call(
1314
+ _c,
1315
+ layerKey,
1316
+ instanceId,
1317
+ instance
1318
+ );
1319
+ }
1320
+ },
1321
+ getStyles() {
1322
+ return { ...baseline, ...instance };
1323
+ }
1324
+ };
1325
+ };
1273
1326
  const processOptionalSize = (value, type) => {
1274
1327
  if (value === -1) return "";
1275
1328
  if (type === definition.definition.sizing.Fixed) return utils.toPx(value);
@@ -1501,7 +1554,7 @@ const useLayerPosition = (layerKey) => {
1501
1554
  const calcImagePaint = (imageVars) => {
1502
1555
  var _a, _b;
1503
1556
  return {
1504
- background: imageVars.cssVariableValues.src,
1557
+ background: transformCssValue(imageVars.values.src),
1505
1558
  backgroundRepeat: "no-repeat",
1506
1559
  backgroundSize: (_b = (_a = imageVars.values.scale) == null ? void 0 : _a.toLowerCase) == null ? void 0 : _b.call(_a)
1507
1560
  };
@@ -1519,16 +1572,16 @@ const useImagePaint = (imageLinkKey) => {
1519
1572
  };
1520
1573
  const calcLayerBackground = (paintVars, imageVars, imageSizeVars, linearGradient) => {
1521
1574
  const fillType = paintVars.values.type;
1522
- const cssSolidFill = paintVars.cssVariableValues.solid;
1523
- const cssImageSize = imageSizeVars.cssVariableValues.imageSize;
1575
+ const solidFill = paintVars.values.solid;
1576
+ const imageSize = imageSizeVars.values.imageSize;
1524
1577
  if (fillType === definition.definition.paintMode.Solid) {
1525
- return { background: cssSolidFill };
1578
+ return { background: solidFill };
1526
1579
  }
1527
1580
  if (fillType === definition.definition.paintMode.Image) {
1528
1581
  const image = calcImagePaint(imageVars);
1529
1582
  return {
1530
1583
  ...image,
1531
- backgroundSize: cssImageSize ?? image.backgroundSize
1584
+ backgroundSize: imageSize ?? image.backgroundSize
1532
1585
  };
1533
1586
  }
1534
1587
  if (fillType === definition.definition.paintMode.LinearGradient) {
@@ -1646,7 +1699,7 @@ const calcLayerBorder = (borderVars, borderPaintVars, borderLinearGradient, pain
1646
1699
  };
1647
1700
  }
1648
1701
  if (borderPaint.type === definition.definition.paintMode.Solid) {
1649
- return calcBorderSides(type, width, borderPaint.solidCssValue);
1702
+ return calcBorderSides(type, width, borderPaint.solid);
1650
1703
  }
1651
1704
  return { border: null };
1652
1705
  };
@@ -1791,7 +1844,9 @@ const useLayerFlex = (layerKey) => {
1791
1844
  };
1792
1845
  };
1793
1846
  const SKIP_OVERRIDE = { skipOverrideCheck: true };
1794
- const useLayerStyles = (layerKey) => {
1847
+ const useLayerStyles = (layerKey, options) => {
1848
+ const collectStyle = (options == null ? void 0 : options.collectStyle) ?? true;
1849
+ const reg = useStyleRegistrar(layerKey);
1795
1850
  try {
1796
1851
  if (!layerKey) throw new Error("Empty layer key");
1797
1852
  const { manager: fragmentManager } = react.useContext(FragmentContext);
@@ -1890,24 +1945,47 @@ const useLayerStyles = (layerKey) => {
1890
1945
  const layout = calcLayerLayout(vars);
1891
1946
  const textStyles = calcLayerTextStyles(vars);
1892
1947
  const layerFlex = calcLayerFlex(vars, parentVars);
1893
- return {
1894
- ...background,
1895
- ...border,
1896
- ...position,
1897
- opacity: vars.values.opacity,
1898
- overflow: vars.values.overflow,
1899
- rotate: utils.isValue(vars.values.rotate) ? `${vars.values.rotate}deg` : null,
1900
- "border-radius": utils.isValue(vars.rawValues.borderRadius) ? vars.values.borderRadius : null,
1901
- "white-space": vars.values.whiteSpace,
1902
- "z-index": vars.values.zIndex !== -1 ? vars.values.zIndex : null,
1903
- ...layout,
1904
- ...layerSize,
1905
- ...textStyles,
1906
- ...layerFlex,
1907
- display
1908
- };
1948
+ reg.add("opacity", vars.values.opacity, vars.isVariable.opacity);
1949
+ reg.add("overflow", vars.values.overflow, vars.isVariable.overflow);
1950
+ reg.add(
1951
+ "border-radius",
1952
+ utils.isValue(vars.rawValues.borderRadius) ? vars.values.borderRadius : null,
1953
+ vars.isVariable.borderRadius
1954
+ );
1955
+ reg.add("white-space", vars.values.whiteSpace, vars.isVariable.whiteSpace);
1956
+ reg.add(
1957
+ "rotate",
1958
+ utils.isValue(vars.values.rotate) ? `${vars.values.rotate}deg` : null,
1959
+ vars.isVariable.rotate
1960
+ );
1961
+ reg.add(
1962
+ "z-index",
1963
+ vars.values.zIndex !== -1 ? vars.values.zIndex : null,
1964
+ vars.isVariable.zIndex
1965
+ );
1966
+ const bgDynamic = paintVars.isVariable.solid || paintVars.isVariable.type || imageVars.isVariable.src;
1967
+ reg.addAll(background, bgDynamic);
1968
+ const borderDynamic = borderPaintVars.isVariable.solid || borderVars.isVariable.type;
1969
+ reg.addAll(border, borderDynamic);
1970
+ const posDynamic = vars.isVariable.width || vars.isVariable.height || vars.isVariable.position || vars.isVariable.widthType || vars.isVariable.heightType;
1971
+ reg.addAll(position, posDynamic);
1972
+ const layoutDynamic = vars.isVariable.layerMode || vars.isVariable.layerDirection || vars.isVariable.layerDistribute || vars.isVariable.layerAlign || vars.isVariable.padding || vars.isVariable.layerGap;
1973
+ reg.addAll(layout, layoutDynamic);
1974
+ const flexDynamic = vars.isVariable.widthType || vars.isVariable.heightType || parentVars.isVariable.layerDirection;
1975
+ reg.addAll(layerFlex, flexDynamic);
1976
+ const sizeDynamic = vars.isVariable.minWidth || vars.isVariable.maxWidth || vars.isVariable.minHeight || vars.isVariable.maxHeight;
1977
+ reg.addAll(layerSize, sizeDynamic);
1978
+ const textDynamic = vars.isVariable["attributes.color"];
1979
+ reg.addAll(textStyles, textDynamic);
1980
+ reg.add(
1981
+ "display",
1982
+ display,
1983
+ vars.isVariable.visible || vars.isVariable.layerMode
1984
+ );
1985
+ if (collectStyle) {
1986
+ reg.flush();
1987
+ }
1909
1988
  } catch (e) {
1910
- return {};
1911
1989
  }
1912
1990
  };
1913
1991
  const MAX_NESTING_DEPTH = 5;
@@ -2014,6 +2092,7 @@ const useHash = (layerKey, manager) => {
2014
2092
  };
2015
2093
  const useClassnames = (layerKey, manager) => {
2016
2094
  const hash = useHash(layerKey, manager);
2095
+ const { instanceId } = react.useContext(InstanceContext);
2017
2096
  const [classnames] = useLayerValue(layerKey, "classnames", { manager });
2018
2097
  const values = useLayersValue(classnames, "value");
2019
2098
  const enables = useLayersValue(classnames, "enabled");
@@ -2025,40 +2104,13 @@ const useClassnames = (layerKey, manager) => {
2025
2104
  [values, enables]
2026
2105
  );
2027
2106
  if (!layerKey || !manager) return null;
2028
- let base = [hash];
2107
+ const instanceHash = instanceId ? utils.hashGenerator(instanceId) : null;
2108
+ let base = [hash, instanceHash].filter(Boolean);
2029
2109
  if (classnames == null ? void 0 : classnames.length) {
2030
2110
  base = [...base, ...list];
2031
2111
  }
2032
2112
  return base.join(" ");
2033
2113
  };
2034
- const useStyleSheet = (manager) => {
2035
- var _a, _b;
2036
- const addLayerStyle = react.useCallback(
2037
- (layerKey, styles, layer) => {
2038
- var _a2, _b2;
2039
- if (!!(manager == null ? void 0 : manager.$styleSheet) && manager && "addStyle" in (manager == null ? void 0 : manager.$styleSheet)) {
2040
- (_b2 = (_a2 = manager == null ? void 0 : manager.$styleSheet) == null ? void 0 : _a2.addStyle) == null ? void 0 : _b2.call(_a2, layerKey, styles, layer);
2041
- }
2042
- },
2043
- [manager]
2044
- );
2045
- const addCssChunk = react.useCallback(
2046
- (id) => {
2047
- var _a2, _b2;
2048
- if (!!(manager == null ? void 0 : manager.$styleSheet) && manager && "addCssChunk" in (manager == null ? void 0 : manager.$styleSheet)) {
2049
- return (_b2 = (_a2 = manager == null ? void 0 : manager.$styleSheet) == null ? void 0 : _a2.addCssChunk) == null ? void 0 : _b2.call(_a2, id);
2050
- }
2051
- return utils.noop;
2052
- },
2053
- [manager]
2054
- );
2055
- return {
2056
- addLayerStyle,
2057
- addCssChunk,
2058
- mount: ((_a = manager == null ? void 0 : manager.$styleSheet) == null ? void 0 : _a.mount) ?? utils.noop,
2059
- unmount: ((_b = manager == null ? void 0 : manager.$styleSheet) == null ? void 0 : _b.unmount) ?? utils.noop
2060
- };
2061
- };
2062
2114
  const useGlobalManager = (globalManager) => {
2063
2115
  var _a;
2064
2116
  const currentGlobalManager = react.useContext(GlobalManagerContext);
@@ -2135,7 +2187,7 @@ const useLayerInteractions = (layerKey, options) => {
2135
2187
  }
2136
2188
  }
2137
2189
  },
2138
- [globalManager, fragmentManager, areaScope]
2190
+ [globalManager, fragmentManager, areaScope, onChangeProps]
2139
2191
  );
2140
2192
  react.useEffect(() => {
2141
2193
  if (!pause && Array.isArray(interactions)) {
@@ -2241,20 +2293,15 @@ const useTextHighlight = (layerKey, options) => {
2241
2293
  const useTextAttributes = (layerKey, options) => {
2242
2294
  const collectStyle = (options == null ? void 0 : options.collectStyle) ?? true;
2243
2295
  const { manager: fragmentManager } = react.useContext(FragmentContext);
2244
- const styles = useLayerStyles(layerKey);
2296
+ useLayerStyles(layerKey, { collectStyle });
2245
2297
  const highlight = useTextHighlight(layerKey);
2246
2298
  const content = useTextContent(layerKey);
2247
2299
  const classnames = useClassnames(layerKey, fragmentManager);
2248
2300
  const hash = useHash(layerKey, fragmentManager);
2249
- const { addLayerStyle } = useStyleSheet(fragmentManager);
2250
2301
  const events = useLayerInteractions(layerKey, options);
2251
- if (collectStyle) {
2252
- addLayerStyle(layerKey, styles, fragmentManager.resolve(layerKey));
2253
- }
2254
2302
  return {
2255
2303
  hash,
2256
2304
  events,
2257
- styles,
2258
2305
  classnames,
2259
2306
  content,
2260
2307
  highlight
@@ -2281,32 +2328,22 @@ const Text = ({
2281
2328
  }
2282
2329
  }
2283
2330
  ),
2284
- /* @__PURE__ */ jsxRuntime.jsx(
2285
- "div",
2286
- {
2287
- dangerouslySetInnerHTML: { __html: content }
2288
- }
2289
- )
2331
+ /* @__PURE__ */ jsxRuntime.jsx("div", { dangerouslySetInnerHTML: { __html: content } })
2290
2332
  ] });
2291
2333
  };
2292
2334
  const useFrame = (layerKey, options) => {
2293
2335
  const collectStyle = (options == null ? void 0 : options.collectStyle) ?? true;
2294
2336
  const { manager: fragmentManager } = react.useContext(FragmentContext);
2295
2337
  const layer = fragmentManager.entityOfKey(layerKey);
2296
- const styles = useLayerStyles(layerKey);
2338
+ useLayerStyles(layerKey, { collectStyle });
2297
2339
  const children = useLayerChildren(layerKey);
2298
2340
  const classnames = useClassnames(layerKey, fragmentManager);
2299
- const { addLayerStyle } = useStyleSheet(fragmentManager);
2300
2341
  const events = useLayerInteractions(layerKey, options);
2301
2342
  const link = useLayerLink(layerKey);
2302
- if (collectStyle) {
2303
- addLayerStyle(layerKey, styles, fragmentManager.resolve(layerKey));
2304
- }
2305
2343
  return {
2306
2344
  Tag: (link == null ? void 0 : link.isLink) ? (options == null ? void 0 : options.FrameTag) ?? "a" : (options == null ? void 0 : options.FrameTag) ?? "div",
2307
2345
  type: layer == null ? void 0 : layer._type,
2308
2346
  classnames,
2309
- styles,
2310
2347
  children,
2311
2348
  events,
2312
2349
  linkProps: link.linkProps
@@ -2643,12 +2680,15 @@ const CollectionItem = ({
2643
2680
  FrameElement,
2644
2681
  children,
2645
2682
  sourceDefinition,
2683
+ index,
2646
2684
  ...restProps
2647
2685
  }) => {
2648
- var _a;
2686
+ var _a, _b;
2649
2687
  core.keyOfEntity(layer);
2650
2688
  const definitionId = ((_a = core.entityOfKey(sourceDefinition)) == null ? void 0 : _a._id) ?? "";
2651
2689
  const value = layer.value ?? layer;
2690
+ const itemId = ((_b = core.entityOfKey(layer)) == null ? void 0 : _b._id) ?? index;
2691
+ const collectionInstanceId = `ci:${itemId}`;
2652
2692
  const inputProps = {
2653
2693
  [definitionId]: value
2654
2694
  };
@@ -2674,17 +2714,31 @@ const CollectionItem = ({
2674
2714
  value: expandedProps,
2675
2715
  manager
2676
2716
  },
2677
- children: children == null ? void 0 : children.map((child) => /* @__PURE__ */ jsxRuntime.jsx(
2678
- "div",
2717
+ children: /* @__PURE__ */ jsxRuntime.jsx(
2718
+ InstanceContext.Provider,
2679
2719
  {
2680
- style: {
2681
- display: "contents",
2682
- ...cssVars
2720
+ value: {
2721
+ layerKey: null,
2722
+ parentManager: null,
2723
+ innerManager: null,
2724
+ props: {},
2725
+ definitions: [],
2726
+ onChangeProps: null,
2727
+ instanceId: collectionInstanceId
2683
2728
  },
2684
- children: /* @__PURE__ */ jsxRuntime.jsx(FrameElement, { ...restProps, layerKey: child })
2685
- },
2686
- child
2687
- ))
2729
+ children: children == null ? void 0 : children.map((child) => /* @__PURE__ */ jsxRuntime.jsx(
2730
+ "div",
2731
+ {
2732
+ style: {
2733
+ display: "contents",
2734
+ ...cssVars
2735
+ },
2736
+ children: /* @__PURE__ */ jsxRuntime.jsx(FrameElement, { ...restProps, layerKey: child })
2737
+ },
2738
+ child
2739
+ ))
2740
+ }
2741
+ )
2688
2742
  }
2689
2743
  );
2690
2744
  };
@@ -2726,6 +2780,7 @@ const Collection = ({
2726
2780
  children: (_a = sourceValue == null ? void 0 : sourceValue.map) == null ? void 0 : _a.call(sourceValue, (itemValue, index) => /* @__PURE__ */ jsxRuntime.jsx(
2727
2781
  CollectionItem,
2728
2782
  {
2783
+ index,
2729
2784
  layer: itemValue,
2730
2785
  manager: fragmentManager,
2731
2786
  source,
@@ -2757,11 +2812,13 @@ const Frame = ({
2757
2812
  pauseInteractions,
2758
2813
  ...restProps
2759
2814
  }) => {
2760
- const { styles, classnames, children, type, events, linkProps, Tag } = useFrame(layerKey, {
2761
- ...restProps,
2762
- pauseInteractions
2763
- });
2764
- const resultStyles = inputStyles ?? styles;
2815
+ const { classnames, children, type, events, linkProps, Tag } = useFrame(
2816
+ layerKey,
2817
+ {
2818
+ ...restProps,
2819
+ pauseInteractions
2820
+ }
2821
+ );
2765
2822
  const isMounted = useMounted();
2766
2823
  if (isMounted && hidden) {
2767
2824
  return /* @__PURE__ */ jsxRuntime.jsx("div", {});
@@ -2784,10 +2841,7 @@ const Frame = ({
2784
2841
  {
2785
2842
  className: classnames,
2786
2843
  "data-key": layerKey,
2787
- style: {
2788
- ...resultStyles,
2789
- display: hidden ? "none" : resultStyles.display
2790
- },
2844
+ style: inputStyles ? { ...inputStyles, display: hidden ? "none" : inputStyles.display } : hidden ? { display: "none" } : restProps == null ? void 0 : restProps.style,
2791
2845
  ...events,
2792
2846
  ...linkProps,
2793
2847
  ...restProps,
@@ -2795,6 +2849,34 @@ const Frame = ({
2795
2849
  }
2796
2850
  );
2797
2851
  };
2852
+ const useStyleSheet = (manager) => {
2853
+ var _a, _b;
2854
+ const addLayerStyle = react.useCallback(
2855
+ (layerKey, styles, layer) => {
2856
+ var _a2, _b2;
2857
+ if (!!(manager == null ? void 0 : manager.$styleSheet) && manager && "addStyle" in (manager == null ? void 0 : manager.$styleSheet)) {
2858
+ (_b2 = (_a2 = manager == null ? void 0 : manager.$styleSheet) == null ? void 0 : _a2.addStyle) == null ? void 0 : _b2.call(_a2, layerKey, styles, layer);
2859
+ }
2860
+ },
2861
+ [manager]
2862
+ );
2863
+ const addCssChunk = react.useCallback(
2864
+ (id) => {
2865
+ var _a2, _b2;
2866
+ if (!!(manager == null ? void 0 : manager.$styleSheet) && manager && "addCssChunk" in (manager == null ? void 0 : manager.$styleSheet)) {
2867
+ return (_b2 = (_a2 = manager == null ? void 0 : manager.$styleSheet) == null ? void 0 : _a2.addCssChunk) == null ? void 0 : _b2.call(_a2, id);
2868
+ }
2869
+ return utils.noop;
2870
+ },
2871
+ [manager]
2872
+ );
2873
+ return {
2874
+ addLayerStyle,
2875
+ addCssChunk,
2876
+ mount: ((_a = manager == null ? void 0 : manager.$styleSheet) == null ? void 0 : _a.mount) ?? utils.noop,
2877
+ unmount: ((_b = manager == null ? void 0 : manager.$styleSheet) == null ? void 0 : _b.unmount) ?? utils.noop
2878
+ };
2879
+ };
2798
2880
  const useCssChunk = (linkKey) => {
2799
2881
  const { manager } = react.useContext(FragmentContext);
2800
2882
  const [chunkId] = useLayerValue(linkKey, "chunkId", { manager });
@@ -3099,7 +3181,7 @@ const useInstanceProps = (instanceProps) => {
3099
3181
  const instanceLayerProps = (instanceLayer == null ? void 0 : instanceLayer.props) ?? {};
3100
3182
  const [localProps, setLocalProps] = react.useState(instanceProps.props ?? {});
3101
3183
  let inputProps = instanceLayerProps;
3102
- if (isTopInstance && utils.isObject(inputProps) && utils.isObject(localProps)) {
3184
+ if (utils.isObject(inputProps) && utils.isObject(localProps)) {
3103
3185
  inputProps = {
3104
3186
  ...inputProps,
3105
3187
  ...localProps
@@ -3151,7 +3233,7 @@ const useInstanceProps = (instanceProps) => {
3151
3233
  );
3152
3234
  continue;
3153
3235
  }
3154
- resolvedProps[key] = resolvedByKey[value] ?? value;
3236
+ resolvedProps[key] = value in resolvedByKey ? resolvedByKey[value] : value;
3155
3237
  }
3156
3238
  }
3157
3239
  react.useEffect(() => {
@@ -3261,6 +3343,10 @@ const InstanceInitial = ({
3261
3343
  var _a;
3262
3344
  const ssr = ((_a = instanceProps == null ? void 0 : instanceProps.options) == null ? void 0 : _a.ssr) ?? true;
3263
3345
  const link = useLayerLink(instanceProps.layerKey);
3346
+ const parentInstanceId = react.useContext(InstanceContext).instanceId;
3347
+ const isTopInstance = !(instanceProps == null ? void 0 : instanceProps.layerKey);
3348
+ const instanceIdRef = react.useRef(isTopInstance ? crypto.randomUUID() : null);
3349
+ const instanceId = parentInstanceId ? `${parentInstanceId}:${instanceProps.layerKey}` : instanceIdRef.current ?? instanceProps.layerKey;
3264
3350
  const Tag = (link == null ? void 0 : link.isLink) ? inputTag ?? "a" : inputTag ?? "div";
3265
3351
  const {
3266
3352
  fragmentId,
@@ -3299,7 +3385,8 @@ const InstanceInitial = ({
3299
3385
  innerManager,
3300
3386
  parentManager,
3301
3387
  props: expandedProps,
3302
- onChangeProps
3388
+ onChangeProps,
3389
+ instanceId
3303
3390
  }),
3304
3391
  [
3305
3392
  instanceProps.layerKey,
@@ -3307,7 +3394,8 @@ const InstanceInitial = ({
3307
3394
  innerManager,
3308
3395
  parentManager,
3309
3396
  expandedProps,
3310
- onChangeProps
3397
+ onChangeProps,
3398
+ instanceId
3311
3399
  ]
3312
3400
  );
3313
3401
  return /* @__PURE__ */ jsxRuntime.jsx(InstanceContext.Provider, { value: instanceContextValue, children: parentManager ? /* @__PURE__ */ jsxRuntime.jsx(
@@ -3527,8 +3615,15 @@ const AreaInitial = (areaProps) => {
3527
3615
  }),
3528
3616
  [areaData == null ? void 0 : areaData.areaId]
3529
3617
  );
3618
+ const campaignManager = react.useMemo(
3619
+ () => (areaData == null ? void 0 : areaData.campaignId) ? clientCore.createCampaignManager({
3620
+ campaignId: areaData.campaignId,
3621
+ campaignProperties: areaData.campaignProperties ?? void 0
3622
+ }) : null,
3623
+ [areaData == null ? void 0 : areaData.campaignId]
3624
+ );
3530
3625
  if (!areaData) return null;
3531
- return /* @__PURE__ */ jsxRuntime.jsx(AreaManagerProvider, { value: areaManager, children: /* @__PURE__ */ jsxRuntime.jsx(
3626
+ return /* @__PURE__ */ jsxRuntime.jsx(AreaManagerProvider, { value: areaManager, children: /* @__PURE__ */ jsxRuntime.jsx(CampaignManagerProvider, { value: campaignManager, children: /* @__PURE__ */ jsxRuntime.jsx(
3532
3627
  Scope,
3533
3628
  {
3534
3629
  fragmentManager,
@@ -3540,7 +3635,7 @@ const AreaInitial = (areaProps) => {
3540
3635
  },
3541
3636
  children: /* @__PURE__ */ jsxRuntime.jsx(Instance, { fragmentId: areaData.fragmentId, props: resultProps })
3542
3637
  }
3543
- ) });
3638
+ ) }) });
3544
3639
  };
3545
3640
  const Area = (props) => {
3546
3641
  return "globalManager" in props ? /* @__PURE__ */ jsxRuntime.jsx(react.Suspense, { fallback: null, children: /* @__PURE__ */ jsxRuntime.jsx(GlobalManagerProvider, { value: props.globalManager, children: /* @__PURE__ */ jsxRuntime.jsx(AreaErrorBoundary, { children: /* @__PURE__ */ jsxRuntime.jsx(AreaInitial, { ...props }) }) }) }) : /* @__PURE__ */ jsxRuntime.jsx(react.Suspense, { fallback: null, children: /* @__PURE__ */ jsxRuntime.jsx(AreaErrorBoundary, { children: /* @__PURE__ */ jsxRuntime.jsx(AreaInitial, { ...props }) }) });
@@ -3568,6 +3663,8 @@ const useLayerCssOverride = (layerKey) => {
3568
3663
  exports.Area = Area;
3569
3664
  exports.AreaManagerContext = AreaManagerContext;
3570
3665
  exports.AreaManagerProvider = AreaManagerProvider;
3666
+ exports.CampaignManagerContext = CampaignManagerContext;
3667
+ exports.CampaignManagerProvider = CampaignManagerProvider;
3571
3668
  exports.Collection = Collection;
3572
3669
  exports.CssChunk = CssChunk;
3573
3670
  exports.CustomRender = CustomRender;