@fragmentsx/render-react 1.2.3 → 1.2.5

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 (77) hide show
  1. package/dist/hooks/layer/useExtractProps.d.ts +9 -0
  2. package/dist/hooks/layer/useExtractProps.d.ts.map +1 -0
  3. package/dist/hooks/layer/useLayerCssVariable.d.ts.map +1 -1
  4. package/dist/hooks/layer/useLayerValue.d.ts +2 -3
  5. package/dist/hooks/layer/useLayerValue.d.ts.map +1 -1
  6. package/dist/hooks/layer/useReadVariable.d.ts.map +1 -1
  7. package/dist/hooks/layer-styles/useLayerStyles/index.d.ts.map +1 -1
  8. package/dist/hooks/layer-styles/useLayerStyles/useLayerLayout.d.ts +1 -1
  9. package/dist/hooks/layer-styles/useLayerStyles/useLayerLayout.d.ts.map +1 -1
  10. package/dist/hooks/utils/useForceUpdate.d.ts +2 -0
  11. package/dist/hooks/utils/useForceUpdate.d.ts.map +1 -0
  12. package/dist/index.cjs.js +277 -91
  13. package/dist/index.es.js +278 -92
  14. package/dist/nodes/Area/test/area-project-props.browser.test.d.ts +2 -0
  15. package/dist/nodes/Area/test/area-project-props.browser.test.d.ts.map +1 -0
  16. package/dist/nodes/Collection/Collection.d.ts.map +1 -1
  17. package/dist/nodes/Collection/hooks/useCollection.d.ts.map +1 -1
  18. package/dist/nodes/CollectionItem/CollectionItem.d.ts +7 -0
  19. package/dist/nodes/CollectionItem/CollectionItem.d.ts.map +1 -0
  20. package/dist/nodes/CollectionItem/hooks/useCollection.d.ts +26 -0
  21. package/dist/nodes/CollectionItem/hooks/useCollection.d.ts.map +1 -0
  22. package/dist/nodes/CollectionItem/index.d.ts +3 -0
  23. package/dist/nodes/CollectionItem/index.d.ts.map +1 -0
  24. package/dist/nodes/Frame/Frame.d.ts +1 -0
  25. package/dist/nodes/Frame/Frame.d.ts.map +1 -1
  26. package/dist/nodes/Frame/hooks/useFrame.d.ts +1 -0
  27. package/dist/nodes/Frame/hooks/useFrame.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 +1 -1
  30. package/dist/nodes/Instance/hooks/useInstanceProps.d.ts.map +1 -1
  31. package/dist/nodes/Instance/test/basic.test.d.ts +2 -0
  32. package/dist/nodes/Instance/test/basic.test.d.ts.map +1 -0
  33. package/dist/nodes/Instance/test/collection.browser.test.d.ts +2 -0
  34. package/dist/nodes/Instance/test/collection.browser.test.d.ts.map +1 -0
  35. package/dist/nodes/Instance/test/constraints.browser.test.d.ts +2 -0
  36. package/dist/nodes/Instance/test/constraints.browser.test.d.ts.map +1 -0
  37. package/dist/nodes/Instance/test/css-chunks.browser.test.d.ts +2 -0
  38. package/dist/nodes/Instance/test/css-chunks.browser.test.d.ts.map +1 -0
  39. package/dist/nodes/Instance/test/fragmentDocuments.d.ts +19 -0
  40. package/dist/nodes/Instance/test/fragmentDocuments.d.ts.map +1 -0
  41. package/dist/nodes/Instance/test/layout.browser.test.d.ts +2 -0
  42. package/dist/nodes/Instance/test/layout.browser.test.d.ts.map +1 -0
  43. package/dist/nodes/Instance/test/modified.browser.test.d.ts +2 -0
  44. package/dist/nodes/Instance/test/modified.browser.test.d.ts.map +1 -0
  45. package/dist/nodes/Instance/test/modified.test.d.ts +2 -0
  46. package/dist/nodes/Instance/test/modified.test.d.ts.map +1 -0
  47. package/dist/nodes/Instance/test/nested-instance.browser.test.d.ts +2 -0
  48. package/dist/nodes/Instance/test/nested-instance.browser.test.d.ts.map +1 -0
  49. package/dist/nodes/Instance/test/nested-instance.test.d.ts +2 -0
  50. package/dist/nodes/Instance/test/nested-instance.test.d.ts.map +1 -0
  51. package/dist/nodes/Instance/test/paint.browser.test.d.ts +2 -0
  52. package/dist/nodes/Instance/test/paint.browser.test.d.ts.map +1 -0
  53. package/dist/nodes/Instance/test/resize.browser.test.d.ts +2 -0
  54. package/dist/nodes/Instance/test/resize.browser.test.d.ts.map +1 -0
  55. package/dist/nodes/Instance/test/sizing.browser.test.d.ts +2 -0
  56. package/dist/nodes/Instance/test/sizing.browser.test.d.ts.map +1 -0
  57. package/dist/nodes/Instance/test/standalone-props.browser.test.d.ts +2 -0
  58. package/dist/nodes/Instance/test/standalone-props.browser.test.d.ts.map +1 -0
  59. package/dist/nodes/Instance/test/structure.test.d.ts +2 -0
  60. package/dist/nodes/Instance/test/structure.test.d.ts.map +1 -0
  61. package/dist/nodes/Instance/test/styles.browser.test.d.ts +2 -0
  62. package/dist/nodes/Instance/test/styles.browser.test.d.ts.map +1 -0
  63. package/dist/nodes/Instance/test/text.browser.test.d.ts +2 -0
  64. package/dist/nodes/Instance/test/text.browser.test.d.ts.map +1 -0
  65. package/dist/nodes/Instance/test/text.test.d.ts +2 -0
  66. package/dist/nodes/Instance/test/text.test.d.ts.map +1 -0
  67. package/dist/nodes/Text/Text.d.ts.map +1 -1
  68. package/dist/nodes/Text/hooks/useTextAttributes.d.ts +4 -0
  69. package/dist/nodes/Text/hooks/useTextAttributes.d.ts.map +1 -1
  70. package/dist/nodes/Text/hooks/useTextContent.d.ts.map +1 -1
  71. package/dist/nodes/Text/hooks/useTextHighlight.d.ts +6 -0
  72. package/dist/nodes/Text/hooks/useTextHighlight.d.ts.map +1 -0
  73. package/dist/nodes/Text/index.d.ts +1 -0
  74. package/dist/nodes/Text/index.d.ts.map +1 -1
  75. package/dist/test/setupTests.d.ts +1 -0
  76. package/dist/test/setupTests.d.ts.map +1 -0
  77. package/package.json +20 -8
@@ -0,0 +1,9 @@
1
+ import { GraphState, LinkKey } from '@graph-state/core';
2
+ interface Options {
3
+ inputProps: Record<string, unknown>;
4
+ definitions: LinkKey[];
5
+ manager?: GraphState;
6
+ }
7
+ export declare const useExtractProps: ({ layerKey, definitions, manager, inputProps, }: Options) => unknown;
8
+ export {};
9
+ //# sourceMappingURL=useExtractProps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useExtractProps.d.ts","sourceRoot":"","sources":["../../../src/hooks/layer/useExtractProps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAaxD,UAAU,OAAO;IACf,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,WAAW,EAAE,OAAO,EAAE,CAAC;IACvB,OAAO,CAAC,EAAE,UAAU,CAAC;CACtB;AAED,eAAO,MAAM,eAAe,oDAKzB,OAAO,YAsCT,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"useLayerCssVariable.d.ts","sourceRoot":"","sources":["../../../src/hooks/layer/useLayerCssVariable.ts"],"names":[],"mappings":"AAKA,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI5D,eAAO,MAAM,mBAAmB,YAAa,UAAU;;CAQtD,CAAC;AAEF,eAAO,MAAM,mBAAmB;;CAU/B,CAAC"}
1
+ {"version":3,"file":"useLayerCssVariable.d.ts","sourceRoot":"","sources":["../../../src/hooks/layer/useLayerCssVariable.ts"],"names":[],"mappings":"AAKA,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI5D,eAAO,MAAM,mBAAmB,YAAa,UAAU;;CAQtD,CAAC;AAEF,eAAO,MAAM,mBAAmB;;CAiB/B,CAAC"}
@@ -1,9 +1,8 @@
1
1
  import { GraphState, LinkKey } from '@graph-state/core';
2
2
  import { GetLayerOptions } from './useNormalizeLayer/getLayer';
3
- interface Options extends GetLayerOptions {
3
+ export interface UseLayerValueOptions extends GetLayerOptions {
4
4
  manager?: GraphState;
5
5
  scopes?: unknown[];
6
6
  }
7
- export declare const useLayerValue: (layerKey: LinkKey, fieldKey: string, options?: Options) => any[];
8
- export {};
7
+ export declare const useLayerValue: (layerKey: LinkKey, fieldKey: string, options?: UseLayerValueOptions) => any[];
9
8
  //# sourceMappingURL=useLayerValue.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useLayerValue.d.ts","sourceRoot":"","sources":["../../../src/hooks/layer/useLayerValue.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,UAAU,EAEV,OAAO,EAER,MAAM,mBAAmB,CAAC;AAQ3B,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAI/D,UAAU,OAAQ,SAAQ,eAAe;IACvC,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC;CACpB;AAED,eAAO,MAAM,aAAa,aACd,OAAO,YACP,MAAM,YACN,OAAO,UA4ElB,CAAC"}
1
+ {"version":3,"file":"useLayerValue.d.ts","sourceRoot":"","sources":["../../../src/hooks/layer/useLayerValue.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,UAAU,EAEV,OAAO,EAER,MAAM,mBAAmB,CAAC;AAQ3B,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAI/D,MAAM,WAAW,oBAAqB,SAAQ,eAAe;IAC3D,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC;CACpB;AAED,eAAO,MAAM,aAAa,aACd,OAAO,YACP,MAAM,YACN,oBAAoB,UA4E/B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"useReadVariable.d.ts","sourceRoot":"","sources":["../../../src/hooks/layer/useReadVariable.ts"],"names":[],"mappings":"AACA,OAAO,EAA2B,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAiDrE,eAAO,MAAM,eAAe,iBACZ,OAAO,GAAG,IAAI,iBACb,OAAO,EAAE;iCAgFY,OAAO;;;;;;;;;;CAgI5C,CAAC"}
1
+ {"version":3,"file":"useReadVariable.d.ts","sourceRoot":"","sources":["../../../src/hooks/layer/useReadVariable.ts"],"names":[],"mappings":"AACA,OAAO,EAA2B,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAkDrE,eAAO,MAAM,eAAe,iBACZ,OAAO,GAAG,IAAI,iBACb,OAAO,EAAE;iCAyFY,OAAO;;;;;;;;;;CAkJ5C,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hooks/layer-styles/useLayerStyles/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAa5C,eAAO,MAAM,cAAc,aAAc,OAAO,OAsF/C,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hooks/layer-styles/useLayerStyles/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAa5C,eAAO,MAAM,cAAc,aAAc,OAAO,OAoF/C,CAAC"}
@@ -4,7 +4,7 @@ export declare const useLayerLayout: (layerKey: LinkKey) => {
4
4
  gap: string;
5
5
  flexWrap: string | null;
6
6
  justifyContent: any;
7
- flexFlow: string | null;
7
+ flexFlow: string;
8
8
  alignItems: any;
9
9
  padding: any;
10
10
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useLayerLayout.d.ts","sourceRoot":"","sources":["../../../../src/hooks/layer-styles/useLayerStyles/useLayerLayout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAO5C,eAAO,MAAM,cAAc,aAAc,OAAO;;;;;;;;CA+C/C,CAAC"}
1
+ {"version":3,"file":"useLayerLayout.d.ts","sourceRoot":"","sources":["../../../../src/hooks/layer-styles/useLayerStyles/useLayerLayout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAO5C,eAAO,MAAM,cAAc,aAAc,OAAO;;;;;;;;CAwC/C,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function useForceUpdate(): [unknown, () => void];
2
+ //# sourceMappingURL=useForceUpdate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useForceUpdate.d.ts","sourceRoot":"","sources":["../../../src/hooks/utils/useForceUpdate.ts"],"names":[],"mappings":"AAEA,wBAAgB,cAAc,IAEgC,CAC1D,OAAO,EACP,MAAM,IAAI,CACX,CACF"}
package/dist/index.cjs.js CHANGED
@@ -108,6 +108,9 @@ const useNormalizeLayers = (layerKeys, manager, options) => {
108
108
  (layerKey) => getNormalizeLayer(layerKey, resultManager, options)
109
109
  );
110
110
  };
111
+ function useForceUpdate() {
112
+ return react.useReducer(() => ({}), {});
113
+ }
111
114
  const extractVariableValue = (input, variableId) => {
112
115
  if (utils.isObject(input)) {
113
116
  if (variableId in input) {
@@ -139,6 +142,15 @@ function deepMerge(a, b) {
139
142
  const useReadVariable = (variableKey, customScopes) => {
140
143
  const contextScopes = react.useContext(ScopeContext);
141
144
  const scopes = customScopes ?? contextScopes;
145
+ const unmountAbortController = react.useRef(new AbortController());
146
+ const [dep, forceUpdate] = useForceUpdate();
147
+ react.useEffect(
148
+ () => () => {
149
+ var _a;
150
+ (_a = unmountAbortController.current) == null ? void 0 : _a.abort("unmount");
151
+ },
152
+ []
153
+ );
142
154
  const extractVariableDefaultValue = (manager, variableEntity) => {
143
155
  const variableLayer = manager.resolve(variableEntity);
144
156
  if ((variableLayer == null ? void 0 : variableLayer.type) !== definition.definition.variableType.Object)
@@ -184,7 +196,7 @@ const useReadVariable = (variableKey, customScopes) => {
184
196
  return variableLayer;
185
197
  };
186
198
  const readVariable = (variableKey2) => {
187
- var _a, _b, _c;
199
+ var _a, _b, _c, _d, _e;
188
200
  const variableId = (_a = core.entityOfKey(variableKey2)) == null ? void 0 : _a._id;
189
201
  if (!definition.isVariableLink(variableKey2)) {
190
202
  return {
@@ -207,7 +219,10 @@ const useReadVariable = (variableKey, customScopes) => {
207
219
  instanceScope == null ? void 0 : instanceScope.documentManager,
208
220
  variableKey2
209
221
  );
210
- let instanceProp = (_b = instanceScope == null ? void 0 : instanceScope.props) == null ? void 0 : _b[variableId];
222
+ (_c = instanceScope == null ? void 0 : instanceScope.documentManager) == null ? void 0 : _c.subscribe(variableKey2, forceUpdate, {
223
+ signal: (_b = unmountAbortController.current) == null ? void 0 : _b.signal
224
+ });
225
+ let instanceProp = (_d = instanceScope == null ? void 0 : instanceScope.props) == null ? void 0 : _d[variableId];
211
226
  if (Array.isArray(instanceProp)) {
212
227
  instanceProp = instanceProp.map(
213
228
  (rawProp, index) => {
@@ -224,7 +239,7 @@ const useReadVariable = (variableKey, customScopes) => {
224
239
  lastCollectionItem == null ? void 0 : lastCollectionItem.sourceDefinition,
225
240
  lastCollectionItem == null ? void 0 : lastCollectionItem.value
226
241
  );
227
- const collectionItemProp = utils.isPrimitive(lastCollectionItem == null ? void 0 : lastCollectionItem.value) && ((_c = core.entityOfKey(lastCollectionItem == null ? void 0 : lastCollectionItem.sourceDefinition)) == null ? void 0 : _c._id) === variableId ? lastCollectionItem == null ? void 0 : lastCollectionItem.value : extractVariableValue(lastCollectionItem == null ? void 0 : lastCollectionItem.value, variableId);
242
+ const collectionItemProp = utils.isPrimitive(lastCollectionItem == null ? void 0 : lastCollectionItem.value) && ((_e = core.entityOfKey(lastCollectionItem == null ? void 0 : lastCollectionItem.sourceDefinition)) == null ? void 0 : _e._id) === variableId ? lastCollectionItem == null ? void 0 : lastCollectionItem.value : extractVariableValue(lastCollectionItem == null ? void 0 : lastCollectionItem.value, variableId);
228
243
  const currentValue = variableKey2 === instanceProp ? null : collectionItemProp ?? instanceProp ?? null;
229
244
  const required = (variableLayer == null ? void 0 : variableLayer.required) ?? false;
230
245
  const defaultValue = (variableLayer == null ? void 0 : variableLayer.defaultValue) ?? null;
@@ -504,7 +519,8 @@ function makeSnapshot(globalManager, targetFragmentId) {
504
519
  };
505
520
  }
506
521
  const isInheritField = (manager, layerEntity, field) => {
507
- const layer = manager.resolve(layerEntity);
522
+ var _a;
523
+ const layer = (_a = manager == null ? void 0 : manager.resolve) == null ? void 0 : _a.call(manager, layerEntity);
508
524
  if (layer) {
509
525
  const overrider = getOverrider(manager, layer);
510
526
  if ((overrider == null ? void 0 : overrider._id) === (layer == null ? void 0 : layer._id)) return false;
@@ -974,11 +990,13 @@ const getLayerCssVariable = (manager, inputValue) => {
974
990
  };
975
991
  };
976
992
  const useLayerCssVariable = (inputValue) => {
993
+ var _a;
977
994
  const { manager } = react.useContext(FragmentContext);
978
995
  const isVariable = definition.isVariableLink(inputValue);
979
996
  const { layer } = useNormalizeLayer(inputValue, isVariable ? manager : null);
997
+ const variableId = (layer == null ? void 0 : layer._id) ?? ((_a = core.entityOfKey(inputValue)) == null ? void 0 : _a._id);
980
998
  return {
981
- value: isVariable ? `var(--${layer == null ? void 0 : layer._id}, ${transformCssValue(layer == null ? void 0 : layer.defaultValue)})` : null
999
+ value: isVariable ? `var(--${variableId}, ${transformCssValue(layer == null ? void 0 : layer.defaultValue)})` : null
982
1000
  };
983
1001
  };
984
1002
  const useLayerValue = (layerKey, fieldKey, options) => {
@@ -1357,10 +1375,10 @@ const useLayerLinearGradient = (linearGradientLink) => {
1357
1375
  const stopsPosition = useLayersValue(stops, "position");
1358
1376
  const stopValues = react.useMemo(
1359
1377
  () => (stops == null ? void 0 : stops.flatMap((stop, index) => {
1360
- var _a, _b;
1378
+ var _a, _b, _c;
1361
1379
  return [
1362
- (_a = stopsValue == null ? void 0 : stopsValue.at(index)) == null ? void 0 : _a.at(0),
1363
- (_b = stopsPosition == null ? void 0 : stopsPosition.at(index)) == null ? void 0 : _b.at(0)
1380
+ (_b = (_a = stopsValue == null ? void 0 : stopsValue.at(index)) == null ? void 0 : _a.at(2)) == null ? void 0 : _b.cssVariableValue,
1381
+ (_c = stopsPosition == null ? void 0 : stopsPosition.at(index)) == null ? void 0 : _c.at(0)
1364
1382
  ];
1365
1383
  })) ?? [],
1366
1384
  [stops, stopsValue, stopsPosition]
@@ -1460,7 +1478,7 @@ const useLayerBorder = (layerKey) => {
1460
1478
  if (borderPaint.type === definition.definition.paintMode.LinearGradient) {
1461
1479
  let background = `linear-gradient(${paint.solid}, ${paint.solid}) padding-box, ${borderLinearGradient} border-box`;
1462
1480
  if (paint.type === definition.definition.paintMode.LinearGradient) {
1463
- background = `${linearGradient} padding-box, ${borderLinearGradient} border-box`;
1481
+ background = `${linearGradient["background-image"]} padding-box, ${borderLinearGradient["background-image"]} border-box`;
1464
1482
  }
1465
1483
  if (paint.type === definition.definition.paintMode.None) {
1466
1484
  background = `linear-gradient(transparent, transparent) padding-box, ${borderLinearGradient} border-box`;
@@ -1501,25 +1519,18 @@ const useLayerLayout = (layerKey) => {
1501
1519
  const [padding] = useLayerValue(layerKey, "padding", fragmentManager);
1502
1520
  const [gap] = useLayerValue(layerKey, "layerGap", fragmentManager);
1503
1521
  const isFlex = layerModeValue === definition.definition.layerMode.flex;
1504
- return react.useMemo(
1505
- () => ({
1506
- display: isFlex ? "flex" : null,
1507
- gap: utils.toPx(gap),
1508
- flexWrap: isFlex ? layerWrap ? "wrap" : null : null,
1509
- justifyContent: isFlex ? layerDistribute : null,
1510
- flexFlow: isFlex ? layerDirectionValue === definition.definition.layerDirection.vertical ? "column" : "row" : null,
1511
- alignItems: isFlex ? layerAlign : null,
1512
- padding: isFlex ? padding : null
1513
- }),
1514
- [
1515
- isFlex,
1516
- layerWrap,
1517
- layerDistribute,
1518
- layerDirectionValue,
1519
- layerAlign,
1520
- padding
1521
- ]
1522
- );
1522
+ const baseFlow = layerDirectionValue === definition.definition.layerDirection.vertical ? "column" : "row";
1523
+ const wrap = isFlex ? layerWrap ? "wrap" : null : null;
1524
+ const flexFlow = [baseFlow, wrap].filter(Boolean).join(" ");
1525
+ return {
1526
+ display: isFlex ? "flex" : null,
1527
+ gap: utils.toPx(gap),
1528
+ flexWrap: isFlex ? layerWrap ? "wrap" : null : null,
1529
+ justifyContent: isFlex ? layerDistribute : null,
1530
+ flexFlow,
1531
+ alignItems: isFlex ? layerAlign : null,
1532
+ padding: isFlex ? padding : null
1533
+ };
1523
1534
  };
1524
1535
  const useLayerTextStyles = (layerKey) => {
1525
1536
  const { manager: fragmentManager } = react.useContext(FragmentContext);
@@ -1562,7 +1573,7 @@ const useLayerStyles = (layerKey) => {
1562
1573
  const layout = useLayerLayout(layerKey);
1563
1574
  const [zIndex] = useLayerValue(layerKey, "zIndex", fragmentManager);
1564
1575
  const [rotate] = useLayerValue(layerKey, "rotate", fragmentManager);
1565
- const [borderRadius] = useLayerValue(
1576
+ const [borderRadius, , { rawValue: rawBorderRadius }] = useLayerValue(
1566
1577
  layerKey,
1567
1578
  "borderRadius",
1568
1579
  fragmentManager
@@ -1572,13 +1583,13 @@ const useLayerStyles = (layerKey) => {
1572
1583
  const [overflow] = useLayerValue(layerKey, "overflow", fragmentManager);
1573
1584
  return {
1574
1585
  // ...(props ?? {}),
1575
- ...border,
1576
1586
  ...background,
1587
+ ...border,
1577
1588
  ...position,
1578
1589
  opacity,
1579
1590
  overflow,
1580
1591
  rotate: utils.isValue(rotate) ? `${rotate}deg` : null,
1581
- "border-radius": borderRadius,
1592
+ "border-radius": utils.isValue(rawBorderRadius) ? borderRadius : null,
1582
1593
  "white-space": whiteSpace,
1583
1594
  "z-index": zIndex !== -1 ? zIndex : null,
1584
1595
  ...layout,
@@ -1631,6 +1642,12 @@ const useTextContent = (layerKey, manager) => {
1631
1642
  readVariable(variable.variableKey).value ?? ""
1632
1643
  );
1633
1644
  });
1645
+ if (typeof nextContent === "string") {
1646
+ nextContent = nextContent.replace(
1647
+ /\{\{(.*?)}}/,
1648
+ `<mark class="highlight">$1</mark>`
1649
+ );
1650
+ }
1634
1651
  return nextContent;
1635
1652
  };
1636
1653
  const useHash = (layerKey, manager) => {
@@ -1748,22 +1765,111 @@ const useLayerInteractions = (layerKey, options) => {
1748
1765
  };
1749
1766
  }, [interactions, fireEvent, pause]);
1750
1767
  };
1768
+ const useTextHighlight = (layerKey, options) => {
1769
+ const [highlightLayerKey] = useLayerValue(layerKey, "highlight", options);
1770
+ const [, , { cssVariableValue: fontSize }] = useLayerValue(
1771
+ highlightLayerKey,
1772
+ "fontSize",
1773
+ options
1774
+ );
1775
+ const [, , { cssVariableValue: color }] = useLayerValue(
1776
+ highlightLayerKey,
1777
+ "color",
1778
+ options
1779
+ );
1780
+ const [, , { cssVariableValue: fontWeight }] = useLayerValue(
1781
+ highlightLayerKey,
1782
+ "fontWeight",
1783
+ options
1784
+ );
1785
+ const [, , { cssVariableValue: textAlign }] = useLayerValue(
1786
+ highlightLayerKey,
1787
+ "textAlign",
1788
+ options
1789
+ );
1790
+ const [, , { cssVariableValue: textDecoration }] = useLayerValue(
1791
+ highlightLayerKey,
1792
+ "textDecoration",
1793
+ options
1794
+ );
1795
+ const [, , { cssVariableValue: textTransform }] = useLayerValue(
1796
+ highlightLayerKey,
1797
+ "textTransform",
1798
+ options
1799
+ );
1800
+ const [, , { cssVariableValue: lineHeight }] = useLayerValue(
1801
+ highlightLayerKey,
1802
+ "lineHeight",
1803
+ options
1804
+ );
1805
+ const [, , { cssVariableValue: letterSpacing }] = useLayerValue(
1806
+ highlightLayerKey,
1807
+ "letterSpacing",
1808
+ options
1809
+ );
1810
+ const [, , { cssVariableValue: fontFamily }] = useLayerValue(
1811
+ highlightLayerKey,
1812
+ "fontFamily",
1813
+ options
1814
+ );
1815
+ const styles = {
1816
+ background: "inherit",
1817
+ color: "inherit"
1818
+ };
1819
+ if (!!fontSize) {
1820
+ styles["font-size"] = utils.toPx(fontSize);
1821
+ }
1822
+ if (!!color) {
1823
+ styles["color"] = color;
1824
+ }
1825
+ if (!!fontWeight) {
1826
+ styles["font-weight"] = fontWeight;
1827
+ }
1828
+ if (!!textAlign) {
1829
+ styles["text-align"] = textAlign;
1830
+ }
1831
+ if (!!textDecoration) {
1832
+ styles["text-decoration"] = textDecoration;
1833
+ }
1834
+ if (!!textTransform) {
1835
+ styles["text-transform"] = textTransform;
1836
+ }
1837
+ if (!!lineHeight) {
1838
+ styles["line-height"] = lineHeight;
1839
+ }
1840
+ if (!!letterSpacing) {
1841
+ styles["letter-spacing"] = utils.toPx(letterSpacing);
1842
+ }
1843
+ if (!!fontFamily) {
1844
+ styles["font-family"] = `${fontFamily} !important`;
1845
+ }
1846
+ return {
1847
+ stylesString: Object.entries(styles).reduce(
1848
+ (acc, [key, value]) => acc += `${key}: ${value};`,
1849
+ ""
1850
+ )
1851
+ };
1852
+ };
1751
1853
  const useTextAttributes = (layerKey, options) => {
1752
1854
  const collectStyle = (options == null ? void 0 : options.collectStyle) ?? true;
1753
1855
  const { manager: fragmentManager } = react.useContext(FragmentContext);
1754
1856
  const styles = useLayerStyles(layerKey);
1857
+ const highlight = useTextHighlight(layerKey);
1755
1858
  const content = useTextContent(layerKey);
1756
1859
  const classnames = useClassnames(layerKey, fragmentManager);
1860
+ const hash = useHash(layerKey, fragmentManager);
1757
1861
  const { addLayerStyle } = useStyleSheet(fragmentManager);
1758
1862
  const events = useLayerInteractions(layerKey, options);
1759
1863
  if (collectStyle) {
1760
1864
  addLayerStyle(layerKey, styles, fragmentManager.resolve(layerKey));
1761
1865
  }
1762
1866
  return {
1867
+ hash,
1763
1868
  events,
1764
1869
  styles,
1765
1870
  classnames,
1766
- content
1871
+ content,
1872
+ highlight
1767
1873
  };
1768
1874
  };
1769
1875
  const Text = ({
@@ -1772,15 +1878,28 @@ const Text = ({
1772
1878
  collectStyle,
1773
1879
  ...restProps
1774
1880
  }) => {
1775
- const { classnames, content, events } = useTextAttributes(layerKey, {
1776
- collectStyle
1777
- });
1778
- return /* @__PURE__ */ jsxRuntime.jsx(Tag, { className: classnames, "data-key": layerKey, ...events, ...restProps, children: /* @__PURE__ */ jsxRuntime.jsx(
1779
- "div",
1881
+ const { classnames, content, events, hash, highlight } = useTextAttributes(
1882
+ layerKey,
1780
1883
  {
1781
- dangerouslySetInnerHTML: { __html: content }
1884
+ collectStyle
1782
1885
  }
1783
- ) });
1886
+ );
1887
+ return /* @__PURE__ */ jsxRuntime.jsxs(Tag, { className: classnames, "data-key": layerKey, ...events, ...restProps, children: [
1888
+ /* @__PURE__ */ jsxRuntime.jsx(
1889
+ "style",
1890
+ {
1891
+ dangerouslySetInnerHTML: {
1892
+ __html: `.${hash} .highlight {${highlight.stylesString}}`
1893
+ }
1894
+ }
1895
+ ),
1896
+ /* @__PURE__ */ jsxRuntime.jsx(
1897
+ "div",
1898
+ {
1899
+ dangerouslySetInnerHTML: { __html: content }
1900
+ }
1901
+ )
1902
+ ] });
1784
1903
  };
1785
1904
  const useFrame = (layerKey, options) => {
1786
1905
  const collectStyle = (options == null ? void 0 : options.collectStyle) ?? true;
@@ -1799,8 +1918,7 @@ const useFrame = (layerKey, options) => {
1799
1918
  Tag: (link == null ? void 0 : link.isLink) ? (options == null ? void 0 : options.FrameTag) ?? "a" : (options == null ? void 0 : options.FrameTag) ?? "div",
1800
1919
  type: layer == null ? void 0 : layer._type,
1801
1920
  classnames,
1802
- styles: {},
1803
- //isBrowser ? pick(styles, "background") : {},
1921
+ styles,
1804
1922
  children,
1805
1923
  events,
1806
1924
  linkProps: link.linkProps
@@ -1816,16 +1934,106 @@ const useCollection = (layerKey, options) => {
1816
1934
  });
1817
1935
  const source = collectionLayer == null ? void 0 : collectionLayer.source;
1818
1936
  const sourceDefinition = (_a = fragmentManager == null ? void 0 : fragmentManager.resolve(source)) == null ? void 0 : _a.definition;
1819
- const [sourceValue] = useLayerValue(layerKey, "source", fragmentManager);
1937
+ const [sourceValue] = useLayerValue(layerKey, "source", {
1938
+ manager: fragmentManager
1939
+ });
1940
+ const sourceValues = react$1.useGraphStack(fragmentManager, sourceValue ?? []);
1941
+ const resultValues = (sourceValue ?? []).map(
1942
+ (initValue, index) => (sourceValues == null ? void 0 : sourceValues[index]) ?? initValue
1943
+ );
1820
1944
  return {
1821
1945
  source,
1822
1946
  sourceDefinition,
1823
- sourceValue: sourceValue ?? [],
1947
+ sourceValue: resultValues ?? [],
1824
1948
  fragmentManager,
1825
1949
  children,
1826
1950
  ...frame
1827
1951
  };
1828
1952
  };
1953
+ const useExtractProps = ({
1954
+ layerKey,
1955
+ definitions,
1956
+ manager,
1957
+ inputProps
1958
+ }) => {
1959
+ const flatDefinition = react.useMemo(() => {
1960
+ const acc = [];
1961
+ const run = (defLink) => {
1962
+ var _a;
1963
+ const resolvedDefinition = (_a = getNormalizeLayer(defLink, manager)) == null ? void 0 : _a.layer;
1964
+ if ((resolvedDefinition == null ? void 0 : resolvedDefinition.type) === definition.definition.variableType.Array) return;
1965
+ if ((resolvedDefinition == null ? void 0 : resolvedDefinition.type) === definition.definition.variableType.Object) {
1966
+ Object.values(utils.cleanGraph(resolvedDefinition == null ? void 0 : resolvedDefinition.fields)).forEach(run);
1967
+ } else if (definition.isVariableLink(defLink)) {
1968
+ acc.push(defLink);
1969
+ }
1970
+ };
1971
+ definitions.forEach(run);
1972
+ return acc;
1973
+ }, [definitions]);
1974
+ const definitionsData = react$1.useGraphStack(manager, flatDefinition);
1975
+ const definitionProps = react.useMemo(
1976
+ () => definitionsData.reduce((acc, definition2) => {
1977
+ const defId = definition2._id;
1978
+ acc[defId] = (inputProps == null ? void 0 : inputProps[defId]) ?? (definition2 == null ? void 0 : definition2.defaultValue);
1979
+ return acc;
1980
+ }, {}),
1981
+ [inputProps]
1982
+ );
1983
+ return utils.cleanGraph({
1984
+ ...inputProps,
1985
+ ...definitionProps
1986
+ });
1987
+ };
1988
+ const CollectionItem = ({
1989
+ layer,
1990
+ manager,
1991
+ FrameElement,
1992
+ children,
1993
+ sourceDefinition,
1994
+ ...restProps
1995
+ }) => {
1996
+ var _a;
1997
+ const layerKey = core.keyOfEntity(layer);
1998
+ const definitionId = ((_a = core.entityOfKey(sourceDefinition)) == null ? void 0 : _a._id) ?? "";
1999
+ const value = layer.value ?? layer;
2000
+ const props = useExtractProps({
2001
+ layerKey,
2002
+ definitions: [sourceDefinition],
2003
+ inputProps: utils.isObject(value) ? {
2004
+ // [definitionId]: layer.value,
2005
+ ...value
2006
+ } : {
2007
+ [definitionId]: value
2008
+ },
2009
+ manager
2010
+ });
2011
+ return /* @__PURE__ */ jsxRuntime.jsx(
2012
+ Scope,
2013
+ {
2014
+ fragmentManager: manager,
2015
+ layerKey: core.keyOfEntity(layer),
2016
+ value: {
2017
+ type: definition.definition.scopeTypes.CollectionItemScope,
2018
+ ...restProps,
2019
+ sourceDefinition,
2020
+ value: props,
2021
+ manager
2022
+ },
2023
+ children: children == null ? void 0 : children.map((child) => /* @__PURE__ */ jsxRuntime.jsx(
2024
+ "div",
2025
+ {
2026
+ style: {
2027
+ display: "contents",
2028
+ ...getCssVariables(props ?? {})
2029
+ },
2030
+ children: /* @__PURE__ */ jsxRuntime.jsx(FrameElement, { ...restProps, layerKey: child })
2031
+ },
2032
+ child
2033
+ ))
2034
+ }
2035
+ );
2036
+ };
1829
2037
  const Collection = ({
1830
2038
  layerKey,
1831
2039
  styles: inputStyles,
@@ -1861,30 +2069,17 @@ const Collection = ({
1861
2069
  "data-key": layerKey,
1862
2070
  style: resultStyles,
1863
2071
  ...restProps,
1864
- children: (_a = sourceValue == null ? void 0 : sourceValue.map) == null ? void 0 : _a.call(sourceValue, (collectionItem, index) => /* @__PURE__ */ jsxRuntime.jsx(
1865
- Scope,
2072
+ children: (_a = sourceValue == null ? void 0 : sourceValue.map) == null ? void 0 : _a.call(sourceValue, (itemValue, index) => /* @__PURE__ */ jsxRuntime.jsx(
2073
+ CollectionItem,
1866
2074
  {
1867
- fragmentManager,
1868
- layerKey: `${layerKey}.${index}`,
1869
- value: {
1870
- type: definition.definition.scopeTypes.CollectionItemScope,
1871
- source,
1872
- sourceDefinition,
1873
- value: collectionItem,
1874
- manager: fragmentManager
1875
- },
1876
- children: children == null ? void 0 : children.map((child) => /* @__PURE__ */ jsxRuntime.jsx(
1877
- "div",
1878
- {
1879
- style: {
1880
- display: "contents",
1881
- ...getCssVariables(collectionItem ?? {})
1882
- },
1883
- children: /* @__PURE__ */ jsxRuntime.jsx(FrameElement, { ...restProps, layerKey: child })
1884
- },
1885
- child
1886
- ))
1887
- }
2075
+ layer: itemValue,
2076
+ manager: fragmentManager,
2077
+ source,
2078
+ children,
2079
+ sourceDefinition,
2080
+ FrameElement
2081
+ },
2082
+ index
1888
2083
  ))
1889
2084
  }
1890
2085
  )
@@ -2154,41 +2349,31 @@ const useInstanceProps = (instanceProps) => {
2154
2349
  );
2155
2350
  const { manager: fragmentContextManager } = react.useContext(FragmentContext);
2156
2351
  const { properties: definitions, manager: innerFragmentManager } = useFragmentProperties(instanceProps == null ? void 0 : instanceProps.fragmentId);
2157
- const definitionsData = react$1.useGraphStack(innerFragmentManager, definitions);
2352
+ const { readVariable } = useReadVariable();
2158
2353
  const fragmentManager = isTopInstance ? loadedManager : fragmentContextManager;
2159
2354
  const [instanceLayer] = react$1.useGraph(fragmentManager, instanceProps.layerKey);
2160
2355
  const instanceLayerProps = (instanceLayer == null ? void 0 : instanceLayer.props) ?? {};
2161
2356
  const [localProps, setLocalProps] = react.useState(instanceProps.props ?? {});
2162
- const mergedProps = react.useMemo(() => {
2163
- let base = instanceLayerProps;
2164
- if (isTopInstance && utils.isObject(base) && utils.isObject(localProps)) {
2165
- base = {
2166
- ...base,
2167
- ...localProps
2168
- };
2169
- }
2170
- if (isTopInstance && fragmentManager) {
2171
- definitionsData.forEach((definition2) => {
2172
- const defId = definition2._id;
2173
- base[defId] = (localProps == null ? void 0 : localProps[defId]) ?? (definition2 == null ? void 0 : definition2.defaultValue);
2174
- });
2175
- }
2176
- return utils.omit(base, "_type", "_id");
2177
- }, [
2178
- isTopInstance,
2179
- fragmentManager,
2180
- instanceLayerProps,
2181
- definitionsData,
2182
- localProps
2183
- ]);
2357
+ let inputProps = instanceLayerProps;
2358
+ if (isTopInstance && utils.isObject(inputProps) && utils.isObject(localProps)) {
2359
+ inputProps = {
2360
+ ...inputProps,
2361
+ ...localProps
2362
+ };
2363
+ }
2364
+ const extractProps = useExtractProps({
2365
+ definitions,
2366
+ manager: fragmentManager,
2367
+ inputProps
2368
+ });
2184
2369
  react.useEffect(() => {
2185
2370
  if (utils.isValue(instanceProps == null ? void 0 : instanceProps.props)) {
2186
2371
  setLocalProps(instanceProps.props);
2187
2372
  }
2188
2373
  }, [instanceProps == null ? void 0 : instanceProps.props]);
2189
2374
  return {
2190
- props: mergedProps,
2191
- cssProps: getCssVariables(mergedProps),
2375
+ props: extractProps,
2376
+ cssProps: getCssVariables(extractProps),
2192
2377
  onChangeProps: (variableId, value) => {
2193
2378
  var _a;
2194
2379
  setLocalProps((prev) => ({ ...prev, [variableId]: value }));
@@ -2497,4 +2682,5 @@ exports.useReadVariables = useReadVariables;
2497
2682
  exports.useRenderTarget = useRenderTarget;
2498
2683
  exports.useTextAttributes = useTextAttributes;
2499
2684
  exports.useTextContent = useTextContent;
2685
+ exports.useTextHighlight = useTextHighlight;
2500
2686
  exports.wrapTextInParagraphWithAttributes = wrapTextInParagraphWithAttributes;