@pairdraw/core 0.19.0 → 0.19.2

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 (263) hide show
  1. package/dist/canvas/overlays/index.d.ts +2 -2
  2. package/dist/canvas/overlays/index.js +2 -2
  3. package/dist/canvas/overlays/selection.d.ts +1 -2
  4. package/dist/canvas/overlays/selection.d.ts.map +1 -1
  5. package/dist/canvas/overlays/selection.js +2 -9
  6. package/dist/canvas/overlays/selection.js.map +1 -1
  7. package/dist/canvas/renderer/fonts.d.ts.map +1 -1
  8. package/dist/canvas/renderer/fonts.js +2 -0
  9. package/dist/canvas/renderer/fonts.js.map +1 -1
  10. package/dist/canvas/renderer/methods.d.ts +0 -1
  11. package/dist/canvas/renderer/methods.d.ts.map +1 -1
  12. package/dist/canvas/renderer/methods.js +1 -4
  13. package/dist/canvas/renderer/methods.js.map +1 -1
  14. package/dist/canvas/renderer/overlay-pass.d.ts.map +1 -1
  15. package/dist/canvas/renderer/overlay-pass.js +0 -1
  16. package/dist/canvas/renderer/overlay-pass.js.map +1 -1
  17. package/dist/canvas/renderer/pipeline.d.ts.map +1 -1
  18. package/dist/canvas/renderer/pipeline.js +0 -1
  19. package/dist/canvas/renderer/pipeline.js.map +1 -1
  20. package/dist/canvas/renderer/types.d.ts +0 -1
  21. package/dist/canvas/renderer/types.d.ts.map +1 -1
  22. package/dist/canvas/renderer.d.ts +0 -1
  23. package/dist/canvas/renderer.d.ts.map +1 -1
  24. package/dist/canvas/renderer.js.map +1 -1
  25. package/dist/design-jsx/index.d.ts +2 -2
  26. package/dist/design-jsx/index.js +2 -2
  27. package/dist/design-jsx/renderer.d.ts +3 -2
  28. package/dist/design-jsx/renderer.d.ts.map +1 -1
  29. package/dist/design-jsx/renderer.js +2 -2
  30. package/dist/design-jsx/renderer.js.map +1 -1
  31. package/dist/editor/clipboard/snapshot.d.ts.map +1 -1
  32. package/dist/editor/clipboard/snapshot.js +12 -4
  33. package/dist/editor/clipboard/snapshot.js.map +1 -1
  34. package/dist/editor/clipboard.d.ts.map +1 -1
  35. package/dist/editor/clipboard.js +2 -7
  36. package/dist/editor/clipboard.js.map +1 -1
  37. package/dist/editor/color-space.d.ts.map +1 -1
  38. package/dist/editor/color-space.js +33 -38
  39. package/dist/editor/color-space.js.map +1 -1
  40. package/dist/editor/create.d.ts +9 -5
  41. package/dist/editor/create.d.ts.map +1 -1
  42. package/dist/editor/create.js +10 -1
  43. package/dist/editor/create.js.map +1 -1
  44. package/dist/editor/history/edit.d.ts.map +1 -1
  45. package/dist/editor/history/edit.js +2 -1
  46. package/dist/editor/history/edit.js.map +1 -1
  47. package/dist/editor/nudge.js +1 -1
  48. package/dist/editor/nudge.js.map +1 -1
  49. package/dist/editor/read-only/actions.js +2 -0
  50. package/dist/editor/read-only/actions.js.map +1 -1
  51. package/dist/editor/selection/container.d.ts +2 -0
  52. package/dist/editor/selection/container.d.ts.map +1 -1
  53. package/dist/editor/selection/container.js +17 -1
  54. package/dist/editor/selection/container.js.map +1 -1
  55. package/dist/editor/selection/navigation.js +7 -4
  56. package/dist/editor/selection/navigation.js.map +1 -1
  57. package/dist/editor/selection/read.d.ts +2 -2
  58. package/dist/editor/selection.d.ts +4 -2
  59. package/dist/editor/selection.d.ts.map +1 -1
  60. package/dist/editor/shapes/with-text.d.ts.map +1 -1
  61. package/dist/editor/shapes/with-text.js +2 -5
  62. package/dist/editor/shapes/with-text.js.map +1 -1
  63. package/dist/editor/structure/auto-layout-wrap.js +1 -1
  64. package/dist/editor/structure/auto-layout-wrap.js.map +1 -1
  65. package/dist/editor/structure/boolean.d.ts +2 -3
  66. package/dist/editor/structure/boolean.d.ts.map +1 -1
  67. package/dist/editor/structure/boolean.js.map +1 -1
  68. package/dist/editor/structure/group/bounds.d.ts.map +1 -1
  69. package/dist/editor/structure/group/bounds.js +1 -3
  70. package/dist/editor/structure/group/bounds.js.map +1 -1
  71. package/dist/editor/structure/outline-stroke.js +3 -3
  72. package/dist/editor/structure/outline-stroke.js.map +1 -1
  73. package/dist/editor/structure/reorder.d.ts.map +1 -1
  74. package/dist/editor/structure/reorder.js +7 -14
  75. package/dist/editor/structure/reorder.js.map +1 -1
  76. package/dist/editor/structure/state.js +1 -1
  77. package/dist/editor/structure/state.js.map +1 -1
  78. package/dist/editor/structure.d.ts +1 -2
  79. package/dist/editor/structure.d.ts.map +1 -1
  80. package/dist/editor/structure.js +3 -3
  81. package/dist/editor/structure.js.map +1 -1
  82. package/dist/editor/types.d.ts +4 -1
  83. package/dist/editor/types.d.ts.map +1 -1
  84. package/dist/editor/variables.d.ts.map +1 -1
  85. package/dist/editor/variables.js +57 -1
  86. package/dist/editor/variables.js.map +1 -1
  87. package/dist/figma-api/accessors/text/index.d.ts.map +1 -1
  88. package/dist/figma-api/accessors/text/index.js +4 -1
  89. package/dist/figma-api/accessors/text/index.js.map +1 -1
  90. package/dist/figma-api/fonts/loaded.d.ts +3 -1
  91. package/dist/figma-api/fonts/loaded.d.ts.map +1 -1
  92. package/dist/figma-api/fonts/loaded.js +8 -1
  93. package/dist/figma-api/fonts/loaded.js.map +1 -1
  94. package/dist/figma-api/index.d.ts +13 -0
  95. package/dist/figma-api/index.d.ts.map +1 -1
  96. package/dist/figma-api/index.js +13 -0
  97. package/dist/figma-api/index.js.map +1 -1
  98. package/dist/figma-api/serialization.d.ts.map +1 -1
  99. package/dist/figma-api/serialization.js +2 -1
  100. package/dist/figma-api/serialization.js.map +1 -1
  101. package/dist/figma-api/shape-details.d.ts +26 -0
  102. package/dist/figma-api/shape-details.d.ts.map +1 -0
  103. package/dist/figma-api/shape-details.js +28 -0
  104. package/dist/figma-api/shape-details.js.map +1 -0
  105. package/dist/figma-api/shape-with-text.js +2 -5
  106. package/dist/figma-api/shape-with-text.js.map +1 -1
  107. package/dist/figma-api/surface.d.ts +1 -1
  108. package/dist/figma-api/surface.d.ts.map +1 -1
  109. package/dist/figma-api/surface.js +1 -0
  110. package/dist/figma-api/surface.js.map +1 -1
  111. package/dist/icons/svg.js +1 -1
  112. package/dist/icons/svg.js.map +1 -1
  113. package/dist/io/formats/design-tokens/apply.d.ts +1 -1
  114. package/dist/io/formats/drawio/index.d.ts.map +1 -1
  115. package/dist/io/formats/drawio/index.js +1 -1
  116. package/dist/io/formats/drawio/index.js.map +1 -1
  117. package/dist/io/formats/html/layers.d.ts +7 -4
  118. package/dist/io/formats/html/layers.d.ts.map +1 -1
  119. package/dist/io/formats/html/layers.js +4 -1
  120. package/dist/io/formats/html/layers.js.map +1 -1
  121. package/dist/io/formats/pdf/dom.d.ts +6 -1
  122. package/dist/io/formats/pdf/dom.d.ts.map +1 -1
  123. package/dist/io/formats/pdf/dom.js +9 -22
  124. package/dist/io/formats/pdf/dom.js.map +1 -1
  125. package/dist/io/formats/pdf/export.js +1 -1
  126. package/dist/io/formats/pdf/export.js.map +1 -1
  127. package/dist/io/formats/svg/defs.d.ts.map +1 -1
  128. package/dist/io/formats/svg/defs.js +3 -1
  129. package/dist/io/formats/svg/defs.js.map +1 -1
  130. package/dist/io/formats/svg/export.d.ts.map +1 -1
  131. package/dist/io/formats/svg/export.js +52 -16
  132. package/dist/io/formats/svg/export.js.map +1 -1
  133. package/dist/layout/apply.d.ts.map +1 -1
  134. package/dist/layout/apply.js +50 -12
  135. package/dist/layout/apply.js.map +1 -1
  136. package/dist/layout/derived.d.ts +7 -1
  137. package/dist/layout/derived.d.ts.map +1 -1
  138. package/dist/layout/derived.js +11 -1
  139. package/dist/layout/derived.js.map +1 -1
  140. package/dist/layout/grid.d.ts +7 -2
  141. package/dist/layout/grid.d.ts.map +1 -1
  142. package/dist/layout/grid.js +27 -9
  143. package/dist/layout/grid.js.map +1 -1
  144. package/dist/layout/mutations.d.ts +1 -0
  145. package/dist/layout/mutations.d.ts.map +1 -1
  146. package/dist/layout/mutations.js +10 -0
  147. package/dist/layout/mutations.js.map +1 -1
  148. package/dist/layout/strokes.d.ts +9 -1
  149. package/dist/layout/strokes.d.ts.map +1 -1
  150. package/dist/layout/strokes.js +12 -1
  151. package/dist/layout/strokes.js.map +1 -1
  152. package/dist/layout/yoga-helpers.d.ts +3 -1
  153. package/dist/layout/yoga-helpers.d.ts.map +1 -1
  154. package/dist/layout/yoga-helpers.js +16 -2
  155. package/dist/layout/yoga-helpers.js.map +1 -1
  156. package/dist/layout.d.ts.map +1 -1
  157. package/dist/layout.js +71 -38
  158. package/dist/layout.js.map +1 -1
  159. package/dist/lint/linter.d.ts +1 -0
  160. package/dist/lint/linter.d.ts.map +1 -1
  161. package/dist/lint/linter.js +13 -1
  162. package/dist/lint/linter.js.map +1 -1
  163. package/dist/lint/rules/effect-style-required.js +1 -0
  164. package/dist/lint/rules/effect-style-required.js.map +1 -1
  165. package/dist/lint/rules/text-style-required.js +1 -0
  166. package/dist/lint/rules/text-style-required.js.map +1 -1
  167. package/dist/lint/types.d.ts +7 -0
  168. package/dist/lint/types.d.ts.map +1 -1
  169. package/dist/rpc/commands.d.ts +2 -2
  170. package/dist/rpc/index.d.ts +2 -2
  171. package/dist/rpc/read-commands.d.ts +18 -8
  172. package/dist/rpc/read-commands.d.ts.map +1 -1
  173. package/dist/rpc/read-commands.js +18 -9
  174. package/dist/rpc/read-commands.js.map +1 -1
  175. package/dist/text/font/faces.d.ts +12 -1
  176. package/dist/text/font/faces.d.ts.map +1 -1
  177. package/dist/text/font/faces.js +15 -1
  178. package/dist/text/font/faces.js.map +1 -1
  179. package/dist/text/font/manager.d.ts.map +1 -1
  180. package/dist/text/font/manager.js +6 -11
  181. package/dist/text/font/manager.js.map +1 -1
  182. package/dist/text/index.d.ts +2 -2
  183. package/dist/text/index.js +2 -2
  184. package/dist/tools/modify/layout.d.ts.map +1 -1
  185. package/dist/tools/modify/layout.js +1 -0
  186. package/dist/tools/modify/layout.js.map +1 -1
  187. package/dist/tools/read/nodes.d.ts.map +1 -1
  188. package/dist/tools/read/nodes.js.map +1 -1
  189. package/dist/tools/structure/batch.d.ts.map +1 -1
  190. package/dist/tools/structure/batch.js +14 -0
  191. package/dist/tools/structure/batch.js.map +1 -1
  192. package/dist/tools/vector/path.d.ts.map +1 -1
  193. package/dist/tools/vector/path.js +39 -7
  194. package/dist/tools/vector/path.js.map +1 -1
  195. package/dist/xpath.d.ts +3 -0
  196. package/dist/xpath.d.ts.map +1 -1
  197. package/dist/xpath.js +3 -1
  198. package/dist/xpath.js.map +1 -1
  199. package/package.json +9 -9
  200. package/src/canvas/overlays/index.ts +0 -1
  201. package/src/canvas/overlays/selection.ts +1 -12
  202. package/src/canvas/renderer/fonts.ts +2 -0
  203. package/src/canvas/renderer/methods.ts +0 -9
  204. package/src/canvas/renderer/overlay-pass.ts +0 -1
  205. package/src/canvas/renderer/pipeline.ts +0 -1
  206. package/src/canvas/renderer/types.ts +0 -1
  207. package/src/canvas/renderer.ts +0 -1
  208. package/src/design-jsx/index.ts +1 -1
  209. package/src/design-jsx/renderer.ts +1 -1
  210. package/src/editor/clipboard/snapshot.ts +21 -4
  211. package/src/editor/clipboard.ts +4 -14
  212. package/src/editor/color-space.ts +47 -38
  213. package/src/editor/create.ts +14 -2
  214. package/src/editor/history/edit.ts +5 -1
  215. package/src/editor/nudge.ts +1 -1
  216. package/src/editor/read-only/actions.ts +2 -0
  217. package/src/editor/selection/container.ts +24 -1
  218. package/src/editor/selection/navigation.ts +8 -6
  219. package/src/editor/shapes/with-text.ts +2 -5
  220. package/src/editor/structure/auto-layout-wrap.ts +1 -1
  221. package/src/editor/structure/boolean.ts +1 -3
  222. package/src/editor/structure/group/bounds.ts +1 -5
  223. package/src/editor/structure/outline-stroke.ts +3 -3
  224. package/src/editor/structure/reorder.ts +8 -14
  225. package/src/editor/structure/state.ts +1 -1
  226. package/src/editor/structure.ts +5 -8
  227. package/src/editor/types.ts +4 -1
  228. package/src/editor/variables.ts +74 -2
  229. package/src/figma-api/accessors/text/index.ts +10 -1
  230. package/src/figma-api/fonts/loaded.ts +9 -0
  231. package/src/figma-api/index.ts +25 -0
  232. package/src/figma-api/serialization.ts +2 -1
  233. package/src/figma-api/shape-details.ts +50 -0
  234. package/src/figma-api/shape-with-text.ts +2 -5
  235. package/src/figma-api/surface.ts +1 -0
  236. package/src/global.d.ts +5 -0
  237. package/src/icons/svg.ts +3 -1
  238. package/src/io/formats/drawio/index.ts +3 -1
  239. package/src/io/formats/html/layers.ts +11 -2
  240. package/src/io/formats/pdf/dom.ts +10 -18
  241. package/src/io/formats/pdf/export.ts +1 -1
  242. package/src/io/formats/svg/defs.ts +10 -1
  243. package/src/io/formats/svg/export.ts +94 -19
  244. package/src/layout/apply.ts +87 -21
  245. package/src/layout/derived.ts +14 -0
  246. package/src/layout/grid.ts +33 -9
  247. package/src/layout/mutations.ts +13 -1
  248. package/src/layout/strokes.ts +12 -0
  249. package/src/layout/yoga-helpers.ts +18 -1
  250. package/src/layout.ts +94 -49
  251. package/src/lint/linter.ts +17 -2
  252. package/src/lint/rules/effect-style-required.ts +2 -0
  253. package/src/lint/rules/text-style-required.ts +2 -0
  254. package/src/lint/types.ts +8 -0
  255. package/src/rpc/index.ts +1 -0
  256. package/src/rpc/read-commands.ts +40 -23
  257. package/src/text/font/faces.ts +22 -0
  258. package/src/text/font/manager.ts +9 -11
  259. package/src/tools/modify/layout.ts +5 -0
  260. package/src/tools/read/nodes.ts +0 -1
  261. package/src/tools/structure/batch.ts +22 -0
  262. package/src/tools/vector/path.ts +30 -6
  263. package/src/xpath.ts +6 -1
package/dist/layout.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import { autoWidthWrapWidth, estimateTextSize, getTextMeasurer, installTextMeasurer, measureAutoWidthText, measureTextForLayout, setTextMeasurer } from "./layout/text-measurement.js";
2
- import { keepsSavedLayout, usesDetachedDerivedLayout } from "./layout/derived.js";
2
+ import { keepsSavedFrameSize, keepsSavedLayout, usesDetachedDerivedLayout } from "./layout/derived.js";
3
3
  import { applyLockedAspectRatio, applyMinMaxConstraints, configureAbsoluteChild, configureNonTextLeaf, createYogaNode, freeYogaTree, mapAlignSelf, mapGridTrack, parentStretchedAxis } from "./layout/yoga-helpers.js";
4
4
  import { insertFlowBox, setFlexFlow, setFlowEdges } from "./layout/flow-edges.js";
5
+ import { applyContentInsets, applyStrokeMargins, contentInsetsSize, strokeRoom } from "./layout/strokes.js";
5
6
  import { applyYogaLayout } from "./layout/apply.js";
6
7
  import { asFlatLeaf, asLaidOutIn, fillKeepsSizeInHuggingParent, heldHugAxis, ownAxisSizing, setCrossAxisSizing, setMainAxisSizing } from "./layout/axis-sizing.js";
7
8
  import { applyEffectiveGeneratedTextLayout } from "./layout/effective-generated-text.js";
8
- import { applyContentInsets, applyStrokeMargins, strokeRoom } from "./layout/strokes.js";
9
- import { buildGridTree, createGridChildNode } from "./layout/grid.js";
9
+ import { buildGridTree, createGridChildNode, gridTracksForAxis } from "./layout/grid.js";
10
10
  import { sizeAutoResizingText } from "./layout/text-auto-resize.js";
11
11
  import { fitShapeWithTextFrame } from "./layout/shape-with-text.js";
12
12
  import { connectorSublayers, layoutConnector } from "@pairdraw/scene-graph/connectors";
@@ -30,10 +30,14 @@ function computeLayoutInternal(graph, frameId) {
30
30
  fitShapeWithTextFrame(graph, frame);
31
31
  const rootDirection = resolveComputedLayoutDirection(graph, frame);
32
32
  const yogaDirection = rootDirection === "RTL" ? Direction.RTL : Direction.LTR;
33
- const yogaRoot = frame.layoutMode === "GRID" ? buildGridTree(graph, frame, rootDirection) : buildYogaTree(graph, frame, rootDirection);
34
- yogaRoot.calculateLayout(void 0, void 0, yogaDirection);
35
- applyYogaLayout(graph, frame, yogaRoot, computeLayoutInternal);
36
- freeYogaTree(yogaRoot);
33
+ let yogaRoot = null;
34
+ try {
35
+ yogaRoot = frame.layoutMode === "GRID" ? buildGridTree(graph, frame, rootDirection) : buildYogaTree(graph, frame, rootDirection);
36
+ yogaRoot.calculateLayout(void 0, void 0, yogaDirection);
37
+ applyYogaLayout(graph, frame, yogaRoot, computeLayoutInternal);
38
+ } finally {
39
+ if (yogaRoot) freeYogaTree(yogaRoot);
40
+ }
37
41
  }
38
42
  function resolveComputedLayoutDirection(graph, node) {
39
43
  const parent = node.parentId ? graph.getNode(node.parentId) : null;
@@ -97,22 +101,30 @@ function preservesImportedInstanceLayout(node) {
97
101
  function buildYogaTree(graph, frame, inheritedDirection) {
98
102
  const root = createYogaNode();
99
103
  const direction = resolveNodeLayoutDirection(frame, inheritedDirection);
104
+ const insets = keepsSavedFrameSize(graph, frame) ? null : contentInsetsSize(frame);
105
+ const width = insets ? Math.max(frame.width, insets.width) : frame.width;
106
+ const height = insets ? Math.max(frame.height, insets.height) : frame.height;
100
107
  if (frame.primaryAxisSizing === "FIXED") {
101
- if (frame.layoutMode === "HORIZONTAL") root.setWidth(frame.width);
102
- else root.setHeight(frame.height);
108
+ if (frame.layoutMode === "HORIZONTAL") root.setWidth(width);
109
+ else root.setHeight(height);
103
110
  }
104
111
  if (frame.counterAxisSizing === "FIXED") {
105
- if (frame.layoutMode === "HORIZONTAL") root.setHeight(frame.height);
106
- else root.setWidth(frame.width);
112
+ if (frame.layoutMode === "HORIZONTAL") root.setHeight(height);
113
+ else root.setWidth(width);
107
114
  }
108
115
  const stretchedAxis = parentStretchedAxis(graph, frame);
109
- if (stretchedAxis === "width") root.setWidth(frame.width);
110
- if (stretchedAxis === "height") root.setHeight(frame.height);
116
+ if (stretchedAxis === "width") root.setWidth(width);
117
+ if (stretchedAxis === "height") root.setHeight(height);
111
118
  const heldAxis = heldHugAxis(graph, frame);
112
- if (heldAxis === "width") root.setWidth(frame.width);
113
- if (heldAxis === "height") root.setHeight(frame.height);
119
+ if (heldAxis === "width") root.setWidth(width);
120
+ if (heldAxis === "height") root.setHeight(height);
114
121
  configureFlexContainer(root, frame, direction);
115
- insertFlexChildren(root, frame, graph, direction, 1);
122
+ try {
123
+ insertFlexChildren(root, frame, graph, direction, 1);
124
+ } catch (error) {
125
+ freeYogaTree(root);
126
+ throw error;
127
+ }
116
128
  return root;
117
129
  }
118
130
  function configureFlexContainer(yogaNode, node, direction) {
@@ -122,32 +134,43 @@ function configureFlexContainer(yogaNode, node, direction) {
122
134
  applyContentInsets(yogaNode, node);
123
135
  applyMinMaxConstraints(yogaNode, node);
124
136
  }
125
- function configureChildAsGrid(yogaChild, child, parent, graph, inheritedDirection) {
126
- const direction = resolveNodeLayoutDirection(child, inheritedDirection);
127
- yogaChild.setDisplay(Display.Grid);
128
- yogaChild.setDirection(direction === "RTL" ? Direction.RTL : Direction.LTR);
129
- if (child.gridTemplateColumns.length > 0) yogaChild.setGridTemplateColumns(child.gridTemplateColumns.map(mapGridTrack));
130
- if (child.gridTemplateRows.length > 0) yogaChild.setGridTemplateRows(child.gridTemplateRows.map(mapGridTrack));
131
- yogaChild.setGap(Gutter.Column, child.gridColumnGap);
132
- yogaChild.setGap(Gutter.Row, child.gridRowGap);
133
- applyContentInsets(yogaChild, child);
137
+ /**
138
+ * A grid child's box in its flex parent: grow takes the free space, a fixed size is stored, and
139
+ * an axis the grid hugs takes its tracks' size there, as configureAsGrid lays it out.
140
+ */
141
+ function applyGridChildBox(yogaChild, child, parent) {
134
142
  const isParentRow = parent.layoutMode === "HORIZONTAL";
135
143
  const stretchCross = child.layoutAlignSelf !== "AUTO" ? child.layoutAlignSelf === "STRETCH" : parent.counterAxisAlign === "STRETCH";
144
+ const hugWidth = ownAxisSizing(child, "width") === "HUG";
145
+ const hugHeight = ownAxisSizing(child, "height") === "HUG";
136
146
  if (child.layoutGrow > 0) {
137
147
  yogaChild.setFlexGrow(child.layoutGrow);
138
148
  yogaChild.setFlexShrink(1);
139
149
  yogaChild.setFlexBasis(0);
140
- if (!stretchCross) {
141
- if (isParentRow) yogaChild.setHeight(child.height);
142
- else yogaChild.setWidth(child.width);
143
- }
144
- } else if (isParentRow) {
145
- yogaChild.setWidth(child.width);
146
- if (!stretchCross) yogaChild.setHeight(child.height);
147
- } else {
148
- if (child.gridTemplateRows.length > 0) yogaChild.setHeight(child.height);
149
- if (!stretchCross) yogaChild.setWidth(child.width);
150
+ if (stretchCross) return;
151
+ if (isParentRow) {
152
+ if (!hugHeight) yogaChild.setHeight(child.height);
153
+ } else if (!hugWidth) yogaChild.setWidth(child.width);
154
+ return;
155
+ }
156
+ if (isParentRow) {
157
+ if (!hugWidth) yogaChild.setWidth(child.width);
158
+ if (!stretchCross && !hugHeight) yogaChild.setHeight(child.height);
159
+ return;
150
160
  }
161
+ if (child.gridTemplateRows.length > 0 && !hugHeight) yogaChild.setHeight(child.height);
162
+ if (!stretchCross && !hugWidth) yogaChild.setWidth(child.width);
163
+ }
164
+ function configureChildAsGrid(yogaChild, child, parent, graph, inheritedDirection) {
165
+ const direction = resolveNodeLayoutDirection(child, inheritedDirection);
166
+ yogaChild.setDisplay(Display.Grid);
167
+ yogaChild.setDirection(direction === "RTL" ? Direction.RTL : Direction.LTR);
168
+ if (child.gridTemplateColumns.length > 0) yogaChild.setGridTemplateColumns(gridTracksForAxis(child, "width").map(mapGridTrack));
169
+ if (child.gridTemplateRows.length > 0) yogaChild.setGridTemplateRows(gridTracksForAxis(child, "height").map(mapGridTrack));
170
+ yogaChild.setGap(Gutter.Column, child.gridColumnGap);
171
+ yogaChild.setGap(Gutter.Row, child.gridRowGap);
172
+ applyContentInsets(yogaChild, child);
173
+ applyGridChildBox(yogaChild, child, parent);
151
174
  const selfAlign = mapAlignSelf(child.layoutAlignSelf);
152
175
  if (selfAlign != null) yogaChild.setAlignSelf(selfAlign);
153
176
  applyLockedAspectRatio(yogaChild, child, parent);
@@ -220,6 +243,7 @@ function insertFlexChildren(yogaParent, parent, graph, direction, depth) {
220
243
  const flow = [];
221
244
  for (const child of graph.getChildren(parent.id).map((node) => asLaidOutIn(graph, node, parent))) {
222
245
  const yogaChild = createYogaNode();
246
+ box.insertChild(yogaChild, box.getChildCount());
223
247
  if (child.layoutPositioning === "ABSOLUTE") configureAbsoluteChild(yogaChild, child);
224
248
  else if (!child.visible) yogaChild.setDisplay(Display.None);
225
249
  else {
@@ -229,7 +253,6 @@ function insertFlexChildren(yogaParent, parent, graph, direction, depth) {
229
253
  flow.push(yogaChild);
230
254
  }
231
255
  applyStrokeMargins(yogaChild, child, parent);
232
- box.insertChild(yogaChild, box.getChildCount());
233
256
  }
234
257
  setFlowEdges(yogaParent, box, parent, flow, direction);
235
258
  }
@@ -266,7 +289,13 @@ function configureTextLeafWithoutMeasurer(yogaChild, child, parent, fixedDerived
266
289
  }
267
290
  return;
268
291
  }
269
- if (child.textAutoResize !== "HEIGHT") return;
292
+ if (child.textAutoResize !== "HEIGHT") {
293
+ if (child.width > 0 && child.height > 0) {
294
+ yogaChild.setWidth(child.width);
295
+ yogaChild.setHeight(child.height);
296
+ }
297
+ return;
298
+ }
270
299
  const growsWidth = configureGrowingText(yogaChild, child, parent, fixedDerivedMainAxis);
271
300
  const isRow = parent.layoutMode === "HORIZONTAL";
272
301
  const measurementWidth = fixedDerivedMainAxis ? child.derivedLayout?.width ?? child.width : child.width;
@@ -281,7 +310,7 @@ function configureChildAsLeaf(yogaChild, node, parent, graph) {
281
310
  const stretchCross = child.layoutAlignSelf !== "AUTO" ? child.layoutAlignSelf === "STRETCH" : parent.counterAxisAlign === "STRETCH";
282
311
  const isText = child.type === "TEXT";
283
312
  const textMeasurer = getTextMeasurer();
284
- const needsMeasureFunc = isText && textMeasurer && child.textAutoResize !== "NONE";
313
+ const needsMeasureFunc = isText && textMeasurer && growsText(child);
285
314
  const fixedDerivedMainAxis = isRow ? derivedGrowingLeafFitsParent(graph, parent, child, "width") : derivedGrowingLeafFitsParent(graph, parent, child, "height");
286
315
  if (fixedDerivedMainAxis) {
287
316
  if (isRow) yogaChild.setWidth(child.derivedLayout?.width ?? child.width);
@@ -301,6 +330,10 @@ function configureChildAsLeaf(yogaChild, node, parent, graph) {
301
330
  applyLockedAspectRatio(yogaChild, child, parent);
302
331
  applyMinMaxConstraints(yogaChild, child);
303
332
  }
333
+ /** Whether layout measures a text to size it, which only the two growing modes need. */
334
+ function growsText(node) {
335
+ return node.textAutoResize === "WIDTH_AND_HEIGHT" || node.textAutoResize === "HEIGHT";
336
+ }
304
337
  function configureTextLeaf(yogaChild, child, parent, fixedDerivedMainAxis = false) {
305
338
  const autoResize = child.textAutoResize;
306
339
  const isRow = parent.layoutMode === "HORIZONTAL";
@@ -1 +1 @@
1
- {"version":3,"file":"layout.js","names":[],"sources":["../src/layout.ts"],"sourcesContent":["import {\n Direction,\n Display,\n Gutter,\n MeasureMode,\n Overflow,\n type Node as YogaNode\n} from 'yoga-layout'\n\nimport { resolveNodeLayoutDirection } from '@pairdraw/scene-graph/text/direction'\n\nimport { applyYogaLayout } from './layout/apply'\nimport {\n asFlatLeaf,\n asLaidOutIn,\n fillKeepsSizeInHuggingParent,\n heldHugAxis,\n ownAxisSizing,\n setCrossAxisSizing,\n setMainAxisSizing\n} from './layout/axis-sizing'\nimport { keepsSavedLayout, usesDetachedDerivedLayout } from './layout/derived'\nimport { applyEffectiveGeneratedTextLayout } from './layout/effective-generated-text'\nimport { insertFlowBox, setFlexFlow, setFlowEdges } from './layout/flow-edges'\nimport { buildGridTree, createGridChildNode } from './layout/grid'\nimport { sizeAutoResizingText } from './layout/text-auto-resize'\nexport { sizeAutoResizingText } from './layout/text-auto-resize'\nexport {\n estimateTextSize,\n getTextMeasurer,\n installTextMeasurer,\n setTextMeasurer,\n type TextMeasurer\n} from './layout/text-measurement'\nimport type { LayoutSizing, SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { connectorSublayers, layoutConnector } from '@pairdraw/scene-graph/connectors'\nimport { layoutSizing } from '@pairdraw/scene-graph/layout'\n\nimport { fitShapeWithTextFrame } from './layout/shape-with-text'\nimport { applyContentInsets, applyStrokeMargins, strokeRoom } from './layout/strokes'\nimport {\n autoWidthWrapWidth,\n estimateTextSize,\n getTextMeasurer,\n measureAutoWidthText,\n measureTextForLayout\n} from './layout/text-measurement'\nimport {\n applyMinMaxConstraints,\n applyLockedAspectRatio,\n configureAbsoluteChild,\n configureNonTextLeaf,\n createYogaNode,\n freeYogaTree,\n mapAlignSelf,\n mapGridTrack,\n parentStretchedAxis\n} from './layout/yoga-helpers'\n\nexport function computeLayout(graph: SceneGraph, frameId: string): void {\n graph.withLayoutMutations(() => computeLayoutInternal(graph, frameId))\n}\n\n/**\n * The deepest chain of auto-layout frames one layout pass may build. Yoga lays a tree out by\n * recursing in its WebAssembly stack, which overruns at about 150 nested frames here; that throws\n * an out-of-bounds memory error and leaves the shared Yoga instance unusable for every later\n * layout. Refusing the pass before the call keeps the editor working.\n */\nconst MAX_LAYOUT_DEPTH = 128\n\nfunction computeLayoutInternal(graph: SceneGraph, frameId: string): void {\n const frame = graph.getNode(frameId)\n if (!frame || frame.layoutMode === 'NONE') return\n // A shape with text takes its size from its label before laying the label out in it.\n fitShapeWithTextFrame(graph, frame)\n\n const rootDirection = resolveComputedLayoutDirection(graph, frame)\n const yogaDirection = rootDirection === 'RTL' ? Direction.RTL : Direction.LTR\n const yogaRoot =\n frame.layoutMode === 'GRID'\n ? buildGridTree(graph, frame, rootDirection)\n : buildYogaTree(graph, frame, rootDirection)\n yogaRoot.calculateLayout(undefined, undefined, yogaDirection)\n applyYogaLayout(graph, frame, yogaRoot, computeLayoutInternal)\n freeYogaTree(yogaRoot)\n}\nfunction resolveComputedLayoutDirection(\n graph: SceneGraph,\n node: Pick<SceneNode, 'layoutDirection' | 'parentId'>\n): 'LTR' | 'RTL' {\n const parent = node.parentId ? graph.getNode(node.parentId) : null\n const inheritedDirection = parent ? resolveComputedLayoutDirection(graph, parent) : 'LTR'\n return resolveNodeLayoutDirection(node, inheritedDirection)\n}\n\nexport function computeAllLayouts(graph: SceneGraph, scopeId?: string): void {\n graph.withLayoutMutations(() => {\n const rootId = scopeId ?? graph.rootId\n const visited = new Set<string>()\n computeLayoutsBottomUp(graph, rootId, visited)\n if (applyEffectiveGeneratedTextLayout(graph, rootId)) {\n computeLayoutsBottomUp(graph, rootId, new Set())\n }\n routeUnroutedConnectors(graph, rootId)\n })\n}\n\n/**\n * Routes each connector that has no route yet, as one read from a file that saved none, once its\n * label is measured, as FigJam routes such a connector when it opens. A saved route is kept.\n */\nexport function routeUnroutedConnectors(graph: SceneGraph, rootId: string): void {\n for (const { node } of graph.flattenTree(rootId)) {\n if (node.type !== 'CONNECTOR') continue\n const line = connectorSublayers(graph, node)?.line\n if (!line || (line.vectorNetwork?.vertices.length ?? 0) > 0) continue\n sizeAutoResizingText(graph, node.id)\n layoutConnector(graph, node)\n }\n}\n\n/**\n * Gives content an author wrote, such as design JSX, HTML, or a `.pen` file, the sizes and\n * positions its layout implies, which the source does not store, measuring its text first.\n * Documents that store their geometry, such as `.fig` files, keep theirs and do not come here.\n */\nexport function layoutAuthoredNodes(graph: SceneGraph, rootIds: Iterable<string>): void {\n const roots = [...rootIds]\n const pageIds = new Set<string>()\n let outsidePages = false\n for (const id of roots) {\n sizeAutoResizingText(graph, id)\n const page = graph.pageOf(id)\n if (page !== null) pageIds.add(page)\n else outsidePages = true\n }\n const layout = () => {\n if (outsidePages) computeAllLayouts(graph)\n else for (const pageId of pageIds) computeAllLayouts(graph, pageId)\n }\n layout()\n // Layout gives wrapping text its width, which its height follows.\n if (roots.map((id) => sizeAutoResizingText(graph, id, true)).some(Boolean)) layout()\n // Connectors authored with the layers they join route once those layers are in place.\n for (const id of roots) {\n for (const { node } of graph.flattenTree(id)) {\n if (node.type === 'CONNECTOR') layoutConnector(graph, node)\n }\n }\n}\n\nfunction computeLayoutsBottomUp(graph: SceneGraph, nodeId: string, visited: Set<string>): void {\n const node = graph.getNode(nodeId)\n if (!node || visited.has(nodeId)) return\n visited.add(nodeId)\n\n for (const childId of node.childIds) {\n computeLayoutsBottomUp(graph, childId, visited)\n }\n\n if (node.layoutMode !== 'NONE' && !preservesImportedInstanceLayout(node)) {\n computeLayout(graph, nodeId)\n }\n}\n\nfunction preservesImportedInstanceLayout(node: SceneNode): boolean {\n return node.type === 'INSTANCE' && node.source.format === 'fig'\n}\n\nfunction buildYogaTree(\n graph: SceneGraph,\n frame: SceneNode,\n inheritedDirection: 'LTR' | 'RTL'\n): YogaNode {\n const root = createYogaNode()\n const direction = resolveNodeLayoutDirection(frame, inheritedDirection)\n\n if (frame.primaryAxisSizing === 'FIXED') {\n if (frame.layoutMode === 'HORIZONTAL') root.setWidth(frame.width)\n else root.setHeight(frame.height)\n }\n if (frame.counterAxisSizing === 'FIXED') {\n if (frame.layoutMode === 'HORIZONTAL') root.setHeight(frame.height)\n else root.setWidth(frame.width)\n }\n // Laid out on its own, a frame its parent stretches keeps the size the parent gave it on\n // that axis, so its content aligns within that size rather than within a hug.\n const stretchedAxis = parentStretchedAxis(graph, frame)\n if (stretchedAxis === 'width') root.setWidth(frame.width)\n if (stretchedAxis === 'height') root.setHeight(frame.height)\n const heldAxis = heldHugAxis(graph, frame)\n if (heldAxis === 'width') root.setWidth(frame.width)\n if (heldAxis === 'height') root.setHeight(frame.height)\n\n configureFlexContainer(root, frame, direction)\n\n insertFlexChildren(root, frame, graph, direction, 1)\n\n return root\n}\n\nfunction configureFlexContainer(\n yogaNode: YogaNode,\n node: SceneNode,\n direction: Exclude<SceneNode['layoutDirection'], 'AUTO'>\n): void {\n yogaNode.setDirection(direction === 'RTL' ? Direction.RTL : Direction.LTR)\n setFlexFlow(yogaNode, node)\n if (node.clipsContent) yogaNode.setOverflow(Overflow.Hidden)\n applyContentInsets(yogaNode, node)\n\n applyMinMaxConstraints(yogaNode, node)\n}\n\nfunction configureChildAsGrid(\n yogaChild: YogaNode,\n child: SceneNode,\n parent: SceneNode,\n graph: SceneGraph,\n inheritedDirection: 'LTR' | 'RTL'\n): void {\n const direction = resolveNodeLayoutDirection(child, inheritedDirection)\n yogaChild.setDisplay(Display.Grid)\n yogaChild.setDirection(direction === 'RTL' ? Direction.RTL : Direction.LTR)\n\n if (child.gridTemplateColumns.length > 0) {\n yogaChild.setGridTemplateColumns(child.gridTemplateColumns.map(mapGridTrack))\n }\n if (child.gridTemplateRows.length > 0) {\n yogaChild.setGridTemplateRows(child.gridTemplateRows.map(mapGridTrack))\n }\n\n yogaChild.setGap(Gutter.Column, child.gridColumnGap)\n yogaChild.setGap(Gutter.Row, child.gridRowGap)\n\n applyContentInsets(yogaChild, child)\n\n const isParentRow = parent.layoutMode === 'HORIZONTAL'\n const selfOverride = child.layoutAlignSelf !== 'AUTO'\n const stretchCross = selfOverride\n ? child.layoutAlignSelf === 'STRETCH'\n : parent.counterAxisAlign === 'STRETCH'\n\n if (child.layoutGrow > 0) {\n yogaChild.setFlexGrow(child.layoutGrow)\n yogaChild.setFlexShrink(1)\n yogaChild.setFlexBasis(0)\n if (!stretchCross) {\n if (isParentRow) yogaChild.setHeight(child.height)\n else yogaChild.setWidth(child.width)\n }\n } else {\n if (isParentRow) {\n yogaChild.setWidth(child.width)\n if (!stretchCross) yogaChild.setHeight(child.height)\n } else {\n if (child.gridTemplateRows.length > 0) yogaChild.setHeight(child.height)\n if (!stretchCross) yogaChild.setWidth(child.width)\n }\n }\n\n const selfAlign = mapAlignSelf(child.layoutAlignSelf)\n if (selfAlign != null) yogaChild.setAlignSelf(selfAlign)\n\n applyLockedAspectRatio(yogaChild, child, parent)\n applyMinMaxConstraints(yogaChild, child)\n\n const grandchildren = graph.getChildren(child.id)\n for (const gc of grandchildren) {\n if (gc.layoutPositioning === 'ABSOLUTE') {\n const yogaGC = createYogaNode()\n configureAbsoluteChild(yogaGC, gc)\n yogaChild.insertChild(yogaGC, yogaChild.getChildCount())\n } else {\n const yogaGC = createGridChildNode(graph, gc)\n applyStrokeMargins(yogaGC, gc, child)\n yogaChild.insertChild(yogaGC, yogaChild.getChildCount())\n }\n }\n}\n\nfunction sizesFitParent(\n parent: SceneNode,\n children: readonly SceneNode[],\n sizes: Array<number | undefined>,\n axis: 'width' | 'height'\n): boolean {\n if (sizes.some((size) => size === undefined)) return false\n const padding =\n (axis === 'width'\n ? parent.paddingLeft + parent.paddingRight\n : parent.paddingTop + parent.paddingBottom) + strokeRoom(parent, children, axis)\n const gap =\n parent.primaryAxisAlign === 'SPACE_BETWEEN'\n ? 0\n : parent.itemSpacing * Math.max(0, children.length - 1)\n const available = axis === 'width' ? parent.width : parent.height\n const total = sizes.reduce<number>((sum, size) => sum + (size ?? 0), padding + gap)\n return Math.abs(total - available) < 0.001\n}\n\nfunction derivedMainAxisFitsParent(\n graph: SceneGraph,\n parent: SceneNode,\n child: SceneNode,\n axis: 'width' | 'height'\n): boolean {\n if (!keepsSavedLayout(graph, parent)) return false\n const children = graph\n .getChildren(parent.id)\n .filter((candidate) => candidate.visible && candidate.layoutPositioning !== 'ABSOLUTE')\n if (children.length === 0) return false\n\n const sizes = children.map((candidate) => candidate.derivedLayout?.[axis])\n return sizesFitParent(parent, children, sizes, axis) && child.derivedLayout?.[axis] !== undefined\n}\n\nfunction configureAutoLayoutChildSizing(\n yogaChild: YogaNode,\n child: SceneNode,\n parent: SceneNode,\n graph: SceneGraph,\n widthSizing: LayoutSizing,\n heightSizing: LayoutSizing\n): void {\n const isParentRow = parent.layoutMode === 'HORIZONTAL'\n const fixedDerivedMainAxis = isParentRow\n ? derivedMainAxisFitsParent(graph, parent, child, 'width')\n : derivedMainAxisFitsParent(graph, parent, child, 'height')\n\n if (isParentRow) {\n if (fixedDerivedMainAxis) yogaChild.setWidth(child.derivedLayout?.width ?? child.width)\n else setMainAxisSizing(yogaChild, 'width', widthSizing, child.width, child.layoutGrow)\n const keepsSize = fillKeepsSizeInHuggingParent(child, parent, 'height')\n setCrossAxisSizing(yogaChild, 'height', heightSizing, child.height, keepsSize)\n return\n }\n\n const keepsSize = fillKeepsSizeInHuggingParent(child, parent, 'width')\n setCrossAxisSizing(yogaChild, 'width', widthSizing, child.width, keepsSize)\n if (fixedDerivedMainAxis) yogaChild.setHeight(child.derivedLayout?.height ?? child.height)\n else setMainAxisSizing(yogaChild, 'height', heightSizing, child.height, child.layoutGrow)\n}\n\nfunction configureChildAsAutoLayout(\n yogaChild: YogaNode,\n child: SceneNode,\n parent: SceneNode,\n graph: SceneGraph,\n inheritedDirection: 'LTR' | 'RTL',\n depth: number\n): void {\n if (depth > MAX_LAYOUT_DEPTH) {\n throw new RangeError(\n `Layers nest more than ${MAX_LAYOUT_DEPTH} auto-layout frames deep, which the layout engine cannot lay out.`\n )\n }\n const direction = resolveNodeLayoutDirection(child, inheritedDirection)\n const widthSizing = layoutSizing(graph, child, 'HORIZONTAL')\n const heightSizing = layoutSizing(graph, child, 'VERTICAL')\n\n configureAutoLayoutChildSizing(yogaChild, child, parent, graph, widthSizing, heightSizing)\n\n const selfAlign = mapAlignSelf(child.layoutAlignSelf)\n if (selfAlign != null) yogaChild.setAlignSelf(selfAlign)\n applyLockedAspectRatio(yogaChild, child, parent)\n\n if (usesDetachedDerivedLayout(graph, child)) {\n // The imported size is what the child's own hug produced, whether or not it also fills.\n const derived = child.derivedLayout\n if (ownAxisSizing(child, 'width') === 'HUG') yogaChild.setWidth(derived?.width ?? child.width)\n if (ownAxisSizing(child, 'height') === 'HUG') {\n yogaChild.setHeight(derived?.height ?? child.height)\n }\n applyMinMaxConstraints(yogaChild, child)\n return\n }\n\n configureFlexContainer(yogaChild, child, direction)\n const heldAxis = heldHugAxis(graph, child)\n if (heldAxis === 'width' && widthSizing === 'HUG') yogaChild.setWidth(child.width)\n if (heldAxis === 'height' && heightSizing === 'HUG') yogaChild.setHeight(child.height)\n\n insertFlexChildren(yogaChild, child, graph, direction, depth + 1)\n}\n\n/** Puts a frame's children into its Yoga node, through the flow box a negative edge needs. */\nfunction insertFlexChildren(\n yogaParent: YogaNode,\n parent: SceneNode,\n graph: SceneGraph,\n direction: 'LTR' | 'RTL',\n depth: number\n): void {\n const box = insertFlowBox(yogaParent, parent)\n const flow: YogaNode[] = []\n for (const child of graph\n .getChildren(parent.id)\n .map((node) => asLaidOutIn(graph, node, parent))) {\n const yogaChild = createYogaNode()\n\n if (child.layoutPositioning === 'ABSOLUTE') {\n configureAbsoluteChild(yogaChild, child)\n } else if (!child.visible) {\n yogaChild.setDisplay(Display.None)\n } else {\n if (child.layoutMode === 'GRID') {\n configureChildAsGrid(yogaChild, child, parent, graph, direction)\n } else if (child.layoutMode !== 'NONE') {\n configureChildAsAutoLayout(yogaChild, child, parent, graph, direction, depth)\n } else {\n configureChildAsLeaf(yogaChild, child, parent, graph)\n }\n flow.push(yogaChild)\n }\n applyStrokeMargins(yogaChild, child, parent)\n\n box.insertChild(yogaChild, box.getChildCount())\n }\n setFlowEdges(yogaParent, box, parent, flow, direction)\n}\n\nfunction derivedGrowingLeafFitsParent(\n graph: SceneGraph,\n parent: SceneNode,\n child: SceneNode,\n axis: 'width' | 'height'\n): boolean {\n if (child.type !== 'TEXT' || child.layoutGrow <= 0 || child.derivedLayout?.[axis] === undefined) {\n return false\n }\n const children = graph\n .getChildren(parent.id)\n .filter((candidate) => candidate.visible && candidate.layoutPositioning !== 'ABSOLUTE')\n const sizes = children.map((candidate) => {\n if (candidate.layoutGrow > 0) return candidate.derivedLayout?.[axis]\n return axis === 'width' ? candidate.width : candidate.height\n })\n return sizesFitParent(parent, children, sizes, axis)\n}\n\n/**\n * Fill text shares its parent's main axis like a fill frame: it grows and shrinks from a zero\n * basis, so its stored width (100px for new text) never decides its share. Returns whether\n * it fills the row's width, where its stored width must not constrain it either.\n */\nfunction configureGrowingText(\n yogaChild: YogaNode,\n child: SceneNode,\n parent: SceneNode,\n fixedDerivedMainAxis: boolean\n): boolean {\n if (child.layoutGrow <= 0 || fixedDerivedMainAxis) return false\n yogaChild.setFlexGrow(child.layoutGrow)\n yogaChild.setFlexShrink(1)\n yogaChild.setFlexBasis(0)\n return parent.layoutMode === 'HORIZONTAL'\n}\n\nfunction configureTextLeafWithoutMeasurer(\n yogaChild: YogaNode,\n child: SceneNode,\n parent: SceneNode,\n fixedDerivedMainAxis: boolean\n): void {\n const hasStoredSize =\n child.width > 0 && child.height > 0 && !(child.width === 100 && child.height === 100)\n\n if (child.textAutoResize === 'WIDTH_AND_HEIGHT') {\n if (hasStoredSize) {\n yogaChild.setWidth(child.width)\n yogaChild.setHeight(child.height)\n } else {\n const estimated = estimateTextSize(child)\n yogaChild.setWidth(estimated.width)\n yogaChild.setHeight(estimated.height)\n }\n return\n }\n if (child.textAutoResize !== 'HEIGHT') return\n\n const growsWidth = configureGrowingText(yogaChild, child, parent, fixedDerivedMainAxis)\n const isRow = parent.layoutMode === 'HORIZONTAL'\n const measurementWidth = fixedDerivedMainAxis\n ? (child.derivedLayout?.width ?? child.width)\n : child.width\n const stretches =\n child.layoutAlignSelf === 'STRETCH' ||\n (child.layoutAlignSelf === 'AUTO' && parent.counterAxisAlign === 'STRETCH')\n if (!(!isRow && stretches) && !fixedDerivedMainAxis && !growsWidth) {\n yogaChild.setWidth(child.width)\n }\n if (hasStoredSize) yogaChild.setHeight(child.height)\n else yogaChild.setHeight(estimateTextSize(child, measurementWidth).height)\n}\n\nfunction configureChildAsLeaf(\n yogaChild: YogaNode,\n node: SceneNode,\n parent: SceneNode,\n graph: SceneGraph\n): void {\n const child = asFlatLeaf(node, parent)\n const isRow = parent.layoutMode === 'HORIZONTAL'\n const selfOverride = child.layoutAlignSelf !== 'AUTO'\n const stretchCross = selfOverride\n ? child.layoutAlignSelf === 'STRETCH'\n : parent.counterAxisAlign === 'STRETCH'\n\n const isText = child.type === 'TEXT'\n const textMeasurer = getTextMeasurer()\n const needsMeasureFunc = isText && textMeasurer && child.textAutoResize !== 'NONE'\n\n const fixedDerivedMainAxis = isRow\n ? derivedGrowingLeafFitsParent(graph, parent, child, 'width')\n : derivedGrowingLeafFitsParent(graph, parent, child, 'height')\n\n if (fixedDerivedMainAxis) {\n if (isRow) yogaChild.setWidth(child.derivedLayout?.width ?? child.width)\n else yogaChild.setHeight(child.derivedLayout?.height ?? child.height)\n }\n\n if (needsMeasureFunc) {\n configureTextLeaf(yogaChild, child, parent, fixedDerivedMainAxis)\n } else if (isText && !textMeasurer && child.textAutoResize !== 'NONE') {\n configureTextLeafWithoutMeasurer(yogaChild, child, parent, fixedDerivedMainAxis)\n } else {\n configureNonTextLeaf(yogaChild, child, isRow, stretchCross)\n // Fixed text still contributes its box to a HUG cross axis. Without\n // an intrinsic minimum, stretch collapses the text to its siblings.\n if (isText && stretchCross && parent.counterAxisSizing === 'HUG') {\n if (isRow) yogaChild.setMinHeight(child.height)\n else yogaChild.setMinWidth(child.width)\n }\n }\n\n const selfAlign = mapAlignSelf(child.layoutAlignSelf)\n if (selfAlign != null) yogaChild.setAlignSelf(selfAlign)\n\n applyLockedAspectRatio(yogaChild, child, parent)\n applyMinMaxConstraints(yogaChild, child)\n}\n\nfunction configureTextLeaf(\n yogaChild: YogaNode,\n child: SceneNode,\n parent: SceneNode,\n fixedDerivedMainAxis = false\n): void {\n const autoResize = child.textAutoResize\n const isRow = parent.layoutMode === 'HORIZONTAL'\n const growsWidth = configureGrowingText(yogaChild, child, parent, fixedDerivedMainAxis)\n const stretchesCross =\n child.layoutAlignSelf === 'STRETCH' ||\n (child.layoutAlignSelf === 'AUTO' && parent.counterAxisAlign === 'STRETCH')\n // Layout sets the width of text that grows along a row or stretches across a column.\n const fillsWidth = (!isRow && stretchesCross) || growsWidth\n\n const cache = new Map<number, { width: number; height: number }>()\n const UNCONSTRAINED_KEY = -1\n\n if (autoResize === 'WIDTH_AND_HEIGHT') {\n const importedSize = child.derivedLayout\n if (importedSize?.width !== undefined && importedSize.height !== undefined) {\n yogaChild.setWidth(child.width)\n yogaChild.setHeight(child.height)\n return\n }\n\n // Auto-width text keeps each line whole, as Figma's does, in a parent narrower than the text;\n // only a width that layout or a max width sets wraps it.\n const wraps = fillsWidth || child.maxWidth != null\n yogaChild.setMeasureFunc((width, widthMode, _height, _heightMode) => {\n const maxW = wraps && widthMode !== MeasureMode.Undefined ? width : undefined\n const cacheKey = maxW === undefined ? UNCONSTRAINED_KEY : Math.round(maxW)\n const cached = cache.get(cacheKey)\n if (cached) return cached\n\n const result = measureAutoWidthText(child, maxW ?? autoWidthWrapWidth(child))\n cache.set(cacheKey, result)\n return result\n })\n } else if (autoResize === 'HEIGHT') {\n const fixedWidth = fixedDerivedMainAxis\n ? (child.derivedLayout?.width ?? child.width)\n : child.width\n // Let Yoga stretch or grow fill-width text instead of fixing its stored width.\n if (child.layoutGrow <= 0 && !fillsWidth) {\n yogaChild.setWidth(fixedWidth)\n }\n yogaChild.setMeasureFunc((width, widthMode, _height, _heightMode) => {\n let constraintW = fixedWidth\n if (fillsWidth) {\n if (widthMode !== MeasureMode.Undefined) constraintW = width\n } else if (widthMode !== MeasureMode.Undefined) {\n constraintW = Math.min(width, fixedWidth || width)\n }\n const cacheKey = Math.round(constraintW)\n const cached = cache.get(cacheKey)\n if (cached) return cached\n\n if (constraintW === child.width && (child.derivedTextGlyphs?.length ?? 0) > 0) {\n return { width: constraintW, height: child.height }\n }\n const result = { width: constraintW, height: measureTextForLayout(child, constraintW).height }\n cache.set(cacheKey, result)\n return result\n })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA2DA,SAAgB,cAAc,OAAmB,SAAuB;CACtE,MAAM,0BAA0B,sBAAsB,OAAO,OAAO,CAAC;AACvE;;;;;;;AAQA,MAAM,mBAAmB;AAEzB,SAAS,sBAAsB,OAAmB,SAAuB;CACvE,MAAM,QAAQ,MAAM,QAAQ,OAAO;CACnC,IAAI,CAAC,SAAS,MAAM,eAAe,QAAQ;CAE3C,sBAAsB,OAAO,KAAK;CAElC,MAAM,gBAAgB,+BAA+B,OAAO,KAAK;CACjE,MAAM,gBAAgB,kBAAkB,QAAQ,UAAU,MAAM,UAAU;CAC1E,MAAM,WACJ,MAAM,eAAe,SACjB,cAAc,OAAO,OAAO,aAAa,IACzC,cAAc,OAAO,OAAO,aAAa;CAC/C,SAAS,gBAAgB,KAAA,GAAW,KAAA,GAAW,aAAa;CAC5D,gBAAgB,OAAO,OAAO,UAAU,qBAAqB;CAC7D,aAAa,QAAQ;AACvB;AACA,SAAS,+BACP,OACA,MACe;CACf,MAAM,SAAS,KAAK,WAAW,MAAM,QAAQ,KAAK,QAAQ,IAAI;CAC9D,MAAM,qBAAqB,SAAS,+BAA+B,OAAO,MAAM,IAAI;CACpF,OAAO,2BAA2B,MAAM,kBAAkB;AAC5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;CACH;AACF"}
1
+ {"version":3,"file":"layout.js","names":[],"sources":["../src/layout.ts"],"sourcesContent":["import {\n Direction,\n Display,\n Gutter,\n MeasureMode,\n Overflow,\n type Node as YogaNode\n} from 'yoga-layout'\n\nimport { resolveNodeLayoutDirection } from '@pairdraw/scene-graph/text/direction'\n\nimport { applyYogaLayout } from './layout/apply'\nimport {\n asFlatLeaf,\n asLaidOutIn,\n fillKeepsSizeInHuggingParent,\n heldHugAxis,\n ownAxisSizing,\n setCrossAxisSizing,\n setMainAxisSizing\n} from './layout/axis-sizing'\nimport { keepsSavedFrameSize, keepsSavedLayout, usesDetachedDerivedLayout } from './layout/derived'\nimport { applyEffectiveGeneratedTextLayout } from './layout/effective-generated-text'\nimport { insertFlowBox, setFlexFlow, setFlowEdges } from './layout/flow-edges'\nimport { buildGridTree, createGridChildNode, gridTracksForAxis } from './layout/grid'\nimport { sizeAutoResizingText } from './layout/text-auto-resize'\nexport { sizeAutoResizingText } from './layout/text-auto-resize'\nexport {\n estimateTextSize,\n getTextMeasurer,\n installTextMeasurer,\n setTextMeasurer,\n type TextMeasurer\n} from './layout/text-measurement'\nimport type { LayoutSizing, SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { connectorSublayers, layoutConnector } from '@pairdraw/scene-graph/connectors'\nimport { layoutSizing } from '@pairdraw/scene-graph/layout'\n\nimport { fitShapeWithTextFrame } from './layout/shape-with-text'\nimport {\n applyContentInsets,\n applyStrokeMargins,\n contentInsetsSize,\n strokeRoom\n} from './layout/strokes'\nimport {\n autoWidthWrapWidth,\n estimateTextSize,\n getTextMeasurer,\n measureAutoWidthText,\n measureTextForLayout\n} from './layout/text-measurement'\nimport {\n applyMinMaxConstraints,\n applyLockedAspectRatio,\n configureAbsoluteChild,\n configureNonTextLeaf,\n createYogaNode,\n freeYogaTree,\n mapAlignSelf,\n mapGridTrack,\n parentStretchedAxis\n} from './layout/yoga-helpers'\n\nexport function computeLayout(graph: SceneGraph, frameId: string): void {\n graph.withLayoutMutations(() => computeLayoutInternal(graph, frameId))\n}\n\n/**\n * The deepest chain of auto-layout frames one layout pass may build. Yoga lays a tree out by\n * recursing in its WebAssembly stack, which overruns at about 150 nested frames here; that throws\n * an out-of-bounds memory error and leaves the shared Yoga instance unusable for every later\n * layout. Refusing the pass before the call keeps the editor working.\n */\nconst MAX_LAYOUT_DEPTH = 128\n\nfunction computeLayoutInternal(graph: SceneGraph, frameId: string): void {\n const frame = graph.getNode(frameId)\n if (!frame || frame.layoutMode === 'NONE') return\n // A shape with text takes its size from its label before laying the label out in it.\n fitShapeWithTextFrame(graph, frame)\n\n const rootDirection = resolveComputedLayoutDirection(graph, frame)\n const yogaDirection = rootDirection === 'RTL' ? Direction.RTL : Direction.LTR\n // The tree is freed on every path, a refused pass included: Yoga's nodes are WebAssembly memory\n // the caller owns, so a throw must not leave them behind.\n let yogaRoot: YogaNode | null = null\n try {\n yogaRoot =\n frame.layoutMode === 'GRID'\n ? buildGridTree(graph, frame, rootDirection)\n : buildYogaTree(graph, frame, rootDirection)\n yogaRoot.calculateLayout(undefined, undefined, yogaDirection)\n applyYogaLayout(graph, frame, yogaRoot, computeLayoutInternal)\n } finally {\n if (yogaRoot) freeYogaTree(yogaRoot)\n }\n}\nfunction resolveComputedLayoutDirection(\n graph: SceneGraph,\n node: Pick<SceneNode, 'layoutDirection' | 'parentId'>\n): 'LTR' | 'RTL' {\n const parent = node.parentId ? graph.getNode(node.parentId) : null\n const inheritedDirection = parent ? resolveComputedLayoutDirection(graph, parent) : 'LTR'\n return resolveNodeLayoutDirection(node, inheritedDirection)\n}\n\nexport function computeAllLayouts(graph: SceneGraph, scopeId?: string): void {\n graph.withLayoutMutations(() => {\n const rootId = scopeId ?? graph.rootId\n const visited = new Set<string>()\n computeLayoutsBottomUp(graph, rootId, visited)\n if (applyEffectiveGeneratedTextLayout(graph, rootId)) {\n computeLayoutsBottomUp(graph, rootId, new Set())\n }\n routeUnroutedConnectors(graph, rootId)\n })\n}\n\n/**\n * Routes each connector that has no route yet, as one read from a file that saved none, once its\n * label is measured, as FigJam routes such a connector when it opens. A saved route is kept.\n */\nexport function routeUnroutedConnectors(graph: SceneGraph, rootId: string): void {\n for (const { node } of graph.flattenTree(rootId)) {\n if (node.type !== 'CONNECTOR') continue\n const line = connectorSublayers(graph, node)?.line\n if (!line || (line.vectorNetwork?.vertices.length ?? 0) > 0) continue\n sizeAutoResizingText(graph, node.id)\n layoutConnector(graph, node)\n }\n}\n\n/**\n * Gives content an author wrote, such as design JSX, HTML, or a `.pen` file, the sizes and\n * positions its layout implies, which the source does not store, measuring its text first.\n * Documents that store their geometry, such as `.fig` files, keep theirs and do not come here.\n */\nexport function layoutAuthoredNodes(graph: SceneGraph, rootIds: Iterable<string>): void {\n const roots = [...rootIds]\n const pageIds = new Set<string>()\n let outsidePages = false\n for (const id of roots) {\n sizeAutoResizingText(graph, id)\n const page = graph.pageOf(id)\n if (page !== null) pageIds.add(page)\n else outsidePages = true\n }\n const layout = () => {\n if (outsidePages) computeAllLayouts(graph)\n else for (const pageId of pageIds) computeAllLayouts(graph, pageId)\n }\n layout()\n // Layout gives wrapping text its width, which its height follows.\n if (roots.map((id) => sizeAutoResizingText(graph, id, true)).some(Boolean)) layout()\n // Connectors authored with the layers they join route once those layers are in place.\n for (const id of roots) {\n for (const { node } of graph.flattenTree(id)) {\n if (node.type === 'CONNECTOR') layoutConnector(graph, node)\n }\n }\n}\n\nfunction computeLayoutsBottomUp(graph: SceneGraph, nodeId: string, visited: Set<string>): void {\n const node = graph.getNode(nodeId)\n if (!node || visited.has(nodeId)) return\n visited.add(nodeId)\n\n for (const childId of node.childIds) {\n computeLayoutsBottomUp(graph, childId, visited)\n }\n\n if (node.layoutMode !== 'NONE' && !preservesImportedInstanceLayout(node)) {\n computeLayout(graph, nodeId)\n }\n}\n\nfunction preservesImportedInstanceLayout(node: SceneNode): boolean {\n return node.type === 'INSTANCE' && node.source.format === 'fig'\n}\n\nfunction buildYogaTree(\n graph: SceneGraph,\n frame: SceneNode,\n inheritedDirection: 'LTR' | 'RTL'\n): YogaNode {\n const root = createYogaNode()\n const direction = resolveNodeLayoutDirection(frame, inheritedDirection)\n const insets = keepsSavedFrameSize(graph, frame) ? null : contentInsetsSize(frame)\n const width = insets ? Math.max(frame.width, insets.width) : frame.width\n const height = insets ? Math.max(frame.height, insets.height) : frame.height\n\n if (frame.primaryAxisSizing === 'FIXED') {\n if (frame.layoutMode === 'HORIZONTAL') root.setWidth(width)\n else root.setHeight(height)\n }\n if (frame.counterAxisSizing === 'FIXED') {\n if (frame.layoutMode === 'HORIZONTAL') root.setHeight(height)\n else root.setWidth(width)\n }\n // Laid out on its own, a frame its parent stretches keeps the size the parent gave it on\n // that axis, so its content aligns within that size rather than within a hug.\n const stretchedAxis = parentStretchedAxis(graph, frame)\n if (stretchedAxis === 'width') root.setWidth(width)\n if (stretchedAxis === 'height') root.setHeight(height)\n const heldAxis = heldHugAxis(graph, frame)\n if (heldAxis === 'width') root.setWidth(width)\n if (heldAxis === 'height') root.setHeight(height)\n\n configureFlexContainer(root, frame, direction)\n\n try {\n insertFlexChildren(root, frame, graph, direction, 1)\n } catch (error) {\n // The depth check refuses a chain while the tree is half built; every node made so far hangs\n // from the root, which has no other holder.\n freeYogaTree(root)\n throw error\n }\n\n return root\n}\n\nfunction configureFlexContainer(\n yogaNode: YogaNode,\n node: SceneNode,\n direction: Exclude<SceneNode['layoutDirection'], 'AUTO'>\n): void {\n yogaNode.setDirection(direction === 'RTL' ? Direction.RTL : Direction.LTR)\n setFlexFlow(yogaNode, node)\n if (node.clipsContent) yogaNode.setOverflow(Overflow.Hidden)\n applyContentInsets(yogaNode, node)\n\n applyMinMaxConstraints(yogaNode, node)\n}\n\n/**\n * A grid child's box in its flex parent: grow takes the free space, a fixed size is stored, and\n * an axis the grid hugs takes its tracks' size there, as configureAsGrid lays it out.\n */\nfunction applyGridChildBox(yogaChild: YogaNode, child: SceneNode, parent: SceneNode): void {\n const isParentRow = parent.layoutMode === 'HORIZONTAL'\n const selfOverride = child.layoutAlignSelf !== 'AUTO'\n const stretchCross = selfOverride\n ? child.layoutAlignSelf === 'STRETCH'\n : parent.counterAxisAlign === 'STRETCH'\n const hugWidth = ownAxisSizing(child, 'width') === 'HUG'\n const hugHeight = ownAxisSizing(child, 'height') === 'HUG'\n if (child.layoutGrow > 0) {\n yogaChild.setFlexGrow(child.layoutGrow)\n yogaChild.setFlexShrink(1)\n yogaChild.setFlexBasis(0)\n if (stretchCross) return\n if (isParentRow) {\n if (!hugHeight) yogaChild.setHeight(child.height)\n } else if (!hugWidth) {\n yogaChild.setWidth(child.width)\n }\n return\n }\n if (isParentRow) {\n if (!hugWidth) yogaChild.setWidth(child.width)\n if (!stretchCross && !hugHeight) yogaChild.setHeight(child.height)\n return\n }\n if (child.gridTemplateRows.length > 0 && !hugHeight) yogaChild.setHeight(child.height)\n if (!stretchCross && !hugWidth) yogaChild.setWidth(child.width)\n}\n\nfunction configureChildAsGrid(\n yogaChild: YogaNode,\n child: SceneNode,\n parent: SceneNode,\n graph: SceneGraph,\n inheritedDirection: 'LTR' | 'RTL'\n): void {\n const direction = resolveNodeLayoutDirection(child, inheritedDirection)\n yogaChild.setDisplay(Display.Grid)\n yogaChild.setDirection(direction === 'RTL' ? Direction.RTL : Direction.LTR)\n\n if (child.gridTemplateColumns.length > 0) {\n yogaChild.setGridTemplateColumns(gridTracksForAxis(child, 'width').map(mapGridTrack))\n }\n if (child.gridTemplateRows.length > 0) {\n yogaChild.setGridTemplateRows(gridTracksForAxis(child, 'height').map(mapGridTrack))\n }\n\n yogaChild.setGap(Gutter.Column, child.gridColumnGap)\n yogaChild.setGap(Gutter.Row, child.gridRowGap)\n\n applyContentInsets(yogaChild, child)\n applyGridChildBox(yogaChild, child, parent)\n\n const selfAlign = mapAlignSelf(child.layoutAlignSelf)\n if (selfAlign != null) yogaChild.setAlignSelf(selfAlign)\n\n applyLockedAspectRatio(yogaChild, child, parent)\n applyMinMaxConstraints(yogaChild, child)\n\n const grandchildren = graph.getChildren(child.id)\n for (const gc of grandchildren) {\n if (gc.layoutPositioning === 'ABSOLUTE') {\n const yogaGC = createYogaNode()\n configureAbsoluteChild(yogaGC, gc)\n yogaChild.insertChild(yogaGC, yogaChild.getChildCount())\n } else {\n const yogaGC = createGridChildNode(graph, gc)\n applyStrokeMargins(yogaGC, gc, child)\n yogaChild.insertChild(yogaGC, yogaChild.getChildCount())\n }\n }\n}\n\nfunction sizesFitParent(\n parent: SceneNode,\n children: readonly SceneNode[],\n sizes: Array<number | undefined>,\n axis: 'width' | 'height'\n): boolean {\n if (sizes.some((size) => size === undefined)) return false\n const padding =\n (axis === 'width'\n ? parent.paddingLeft + parent.paddingRight\n : parent.paddingTop + parent.paddingBottom) + strokeRoom(parent, children, axis)\n const gap =\n parent.primaryAxisAlign === 'SPACE_BETWEEN'\n ? 0\n : parent.itemSpacing * Math.max(0, children.length - 1)\n const available = axis === 'width' ? parent.width : parent.height\n const total = sizes.reduce<number>((sum, size) => sum + (size ?? 0), padding + gap)\n return Math.abs(total - available) < 0.001\n}\n\nfunction derivedMainAxisFitsParent(\n graph: SceneGraph,\n parent: SceneNode,\n child: SceneNode,\n axis: 'width' | 'height'\n): boolean {\n if (!keepsSavedLayout(graph, parent)) return false\n const children = graph\n .getChildren(parent.id)\n .filter((candidate) => candidate.visible && candidate.layoutPositioning !== 'ABSOLUTE')\n if (children.length === 0) return false\n\n const sizes = children.map((candidate) => candidate.derivedLayout?.[axis])\n return sizesFitParent(parent, children, sizes, axis) && child.derivedLayout?.[axis] !== undefined\n}\n\nfunction configureAutoLayoutChildSizing(\n yogaChild: YogaNode,\n child: SceneNode,\n parent: SceneNode,\n graph: SceneGraph,\n widthSizing: LayoutSizing,\n heightSizing: LayoutSizing\n): void {\n const isParentRow = parent.layoutMode === 'HORIZONTAL'\n const fixedDerivedMainAxis = isParentRow\n ? derivedMainAxisFitsParent(graph, parent, child, 'width')\n : derivedMainAxisFitsParent(graph, parent, child, 'height')\n\n if (isParentRow) {\n if (fixedDerivedMainAxis) yogaChild.setWidth(child.derivedLayout?.width ?? child.width)\n else setMainAxisSizing(yogaChild, 'width', widthSizing, child.width, child.layoutGrow)\n const keepsSize = fillKeepsSizeInHuggingParent(child, parent, 'height')\n setCrossAxisSizing(yogaChild, 'height', heightSizing, child.height, keepsSize)\n return\n }\n\n const keepsSize = fillKeepsSizeInHuggingParent(child, parent, 'width')\n setCrossAxisSizing(yogaChild, 'width', widthSizing, child.width, keepsSize)\n if (fixedDerivedMainAxis) yogaChild.setHeight(child.derivedLayout?.height ?? child.height)\n else setMainAxisSizing(yogaChild, 'height', heightSizing, child.height, child.layoutGrow)\n}\n\nfunction configureChildAsAutoLayout(\n yogaChild: YogaNode,\n child: SceneNode,\n parent: SceneNode,\n graph: SceneGraph,\n inheritedDirection: 'LTR' | 'RTL',\n depth: number\n): void {\n if (depth > MAX_LAYOUT_DEPTH) {\n throw new RangeError(\n `Layers nest more than ${MAX_LAYOUT_DEPTH} auto-layout frames deep, which the layout engine cannot lay out.`\n )\n }\n const direction = resolveNodeLayoutDirection(child, inheritedDirection)\n const widthSizing = layoutSizing(graph, child, 'HORIZONTAL')\n const heightSizing = layoutSizing(graph, child, 'VERTICAL')\n\n configureAutoLayoutChildSizing(yogaChild, child, parent, graph, widthSizing, heightSizing)\n\n const selfAlign = mapAlignSelf(child.layoutAlignSelf)\n if (selfAlign != null) yogaChild.setAlignSelf(selfAlign)\n applyLockedAspectRatio(yogaChild, child, parent)\n\n if (usesDetachedDerivedLayout(graph, child)) {\n // The imported size is what the child's own hug produced, whether or not it also fills.\n const derived = child.derivedLayout\n if (ownAxisSizing(child, 'width') === 'HUG') yogaChild.setWidth(derived?.width ?? child.width)\n if (ownAxisSizing(child, 'height') === 'HUG') {\n yogaChild.setHeight(derived?.height ?? child.height)\n }\n applyMinMaxConstraints(yogaChild, child)\n return\n }\n\n configureFlexContainer(yogaChild, child, direction)\n const heldAxis = heldHugAxis(graph, child)\n if (heldAxis === 'width' && widthSizing === 'HUG') yogaChild.setWidth(child.width)\n if (heldAxis === 'height' && heightSizing === 'HUG') yogaChild.setHeight(child.height)\n\n insertFlexChildren(yogaChild, child, graph, direction, depth + 1)\n}\n\n/** Puts a frame's children into its Yoga node, through the flow box a negative edge needs. */\nfunction insertFlexChildren(\n yogaParent: YogaNode,\n parent: SceneNode,\n graph: SceneGraph,\n direction: 'LTR' | 'RTL',\n depth: number\n): void {\n const box = insertFlowBox(yogaParent, parent)\n const flow: YogaNode[] = []\n for (const child of graph\n .getChildren(parent.id)\n .map((node) => asLaidOutIn(graph, node, parent))) {\n const yogaChild = createYogaNode()\n // Attached before it is configured, so a child the depth check refuses still hangs from the\n // root and is freed with it rather than left in WebAssembly memory.\n box.insertChild(yogaChild, box.getChildCount())\n\n if (child.layoutPositioning === 'ABSOLUTE') {\n configureAbsoluteChild(yogaChild, child)\n } else if (!child.visible) {\n yogaChild.setDisplay(Display.None)\n } else {\n if (child.layoutMode === 'GRID') {\n configureChildAsGrid(yogaChild, child, parent, graph, direction)\n } else if (child.layoutMode !== 'NONE') {\n configureChildAsAutoLayout(yogaChild, child, parent, graph, direction, depth)\n } else {\n configureChildAsLeaf(yogaChild, child, parent, graph)\n }\n flow.push(yogaChild)\n }\n applyStrokeMargins(yogaChild, child, parent)\n }\n setFlowEdges(yogaParent, box, parent, flow, direction)\n}\n\nfunction derivedGrowingLeafFitsParent(\n graph: SceneGraph,\n parent: SceneNode,\n child: SceneNode,\n axis: 'width' | 'height'\n): boolean {\n if (child.type !== 'TEXT' || child.layoutGrow <= 0 || child.derivedLayout?.[axis] === undefined) {\n return false\n }\n const children = graph\n .getChildren(parent.id)\n .filter((candidate) => candidate.visible && candidate.layoutPositioning !== 'ABSOLUTE')\n const sizes = children.map((candidate) => {\n if (candidate.layoutGrow > 0) return candidate.derivedLayout?.[axis]\n return axis === 'width' ? candidate.width : candidate.height\n })\n return sizesFitParent(parent, children, sizes, axis)\n}\n\n/**\n * Fill text shares its parent's main axis like a fill frame: it grows and shrinks from a zero\n * basis, so its stored width (100px for new text) never decides its share. Returns whether\n * it fills the row's width, where its stored width must not constrain it either.\n */\nfunction configureGrowingText(\n yogaChild: YogaNode,\n child: SceneNode,\n parent: SceneNode,\n fixedDerivedMainAxis: boolean\n): boolean {\n if (child.layoutGrow <= 0 || fixedDerivedMainAxis) return false\n yogaChild.setFlexGrow(child.layoutGrow)\n yogaChild.setFlexShrink(1)\n yogaChild.setFlexBasis(0)\n return parent.layoutMode === 'HORIZONTAL'\n}\n\nfunction configureTextLeafWithoutMeasurer(\n yogaChild: YogaNode,\n child: SceneNode,\n parent: SceneNode,\n fixedDerivedMainAxis: boolean\n): void {\n const hasStoredSize =\n child.width > 0 && child.height > 0 && !(child.width === 100 && child.height === 100)\n\n if (child.textAutoResize === 'WIDTH_AND_HEIGHT') {\n if (hasStoredSize) {\n yogaChild.setWidth(child.width)\n yogaChild.setHeight(child.height)\n } else {\n const estimated = estimateTextSize(child)\n yogaChild.setWidth(estimated.width)\n yogaChild.setHeight(estimated.height)\n }\n return\n }\n if (child.textAutoResize !== 'HEIGHT') {\n // A truncating text keeps the box it has, as Figma clips it to that box.\n if (child.width > 0 && child.height > 0) {\n yogaChild.setWidth(child.width)\n yogaChild.setHeight(child.height)\n }\n return\n }\n\n const growsWidth = configureGrowingText(yogaChild, child, parent, fixedDerivedMainAxis)\n const isRow = parent.layoutMode === 'HORIZONTAL'\n const measurementWidth = fixedDerivedMainAxis\n ? (child.derivedLayout?.width ?? child.width)\n : child.width\n const stretches =\n child.layoutAlignSelf === 'STRETCH' ||\n (child.layoutAlignSelf === 'AUTO' && parent.counterAxisAlign === 'STRETCH')\n if (!(!isRow && stretches) && !fixedDerivedMainAxis && !growsWidth) {\n yogaChild.setWidth(child.width)\n }\n if (hasStoredSize) yogaChild.setHeight(child.height)\n else yogaChild.setHeight(estimateTextSize(child, measurementWidth).height)\n}\n\nfunction configureChildAsLeaf(\n yogaChild: YogaNode,\n node: SceneNode,\n parent: SceneNode,\n graph: SceneGraph\n): void {\n const child = asFlatLeaf(node, parent)\n const isRow = parent.layoutMode === 'HORIZONTAL'\n const selfOverride = child.layoutAlignSelf !== 'AUTO'\n const stretchCross = selfOverride\n ? child.layoutAlignSelf === 'STRETCH'\n : parent.counterAxisAlign === 'STRETCH'\n\n const isText = child.type === 'TEXT'\n const textMeasurer = getTextMeasurer()\n // A truncating or fixed text keeps its box, so Yoga measures only text that grows.\n const needsMeasureFunc = isText && textMeasurer && growsText(child)\n\n const fixedDerivedMainAxis = isRow\n ? derivedGrowingLeafFitsParent(graph, parent, child, 'width')\n : derivedGrowingLeafFitsParent(graph, parent, child, 'height')\n\n if (fixedDerivedMainAxis) {\n if (isRow) yogaChild.setWidth(child.derivedLayout?.width ?? child.width)\n else yogaChild.setHeight(child.derivedLayout?.height ?? child.height)\n }\n\n if (needsMeasureFunc) {\n configureTextLeaf(yogaChild, child, parent, fixedDerivedMainAxis)\n } else if (isText && !textMeasurer && child.textAutoResize !== 'NONE') {\n configureTextLeafWithoutMeasurer(yogaChild, child, parent, fixedDerivedMainAxis)\n } else {\n configureNonTextLeaf(yogaChild, child, isRow, stretchCross)\n // Fixed text still contributes its box to a HUG cross axis. Without\n // an intrinsic minimum, stretch collapses the text to its siblings.\n if (isText && stretchCross && parent.counterAxisSizing === 'HUG') {\n if (isRow) yogaChild.setMinHeight(child.height)\n else yogaChild.setMinWidth(child.width)\n }\n }\n\n const selfAlign = mapAlignSelf(child.layoutAlignSelf)\n if (selfAlign != null) yogaChild.setAlignSelf(selfAlign)\n\n applyLockedAspectRatio(yogaChild, child, parent)\n applyMinMaxConstraints(yogaChild, child)\n}\n\n/** Whether layout measures a text to size it, which only the two growing modes need. */\nfunction growsText(node: SceneNode): boolean {\n return node.textAutoResize === 'WIDTH_AND_HEIGHT' || node.textAutoResize === 'HEIGHT'\n}\n\nfunction configureTextLeaf(\n yogaChild: YogaNode,\n child: SceneNode,\n parent: SceneNode,\n fixedDerivedMainAxis = false\n): void {\n const autoResize = child.textAutoResize\n const isRow = parent.layoutMode === 'HORIZONTAL'\n const growsWidth = configureGrowingText(yogaChild, child, parent, fixedDerivedMainAxis)\n const stretchesCross =\n child.layoutAlignSelf === 'STRETCH' ||\n (child.layoutAlignSelf === 'AUTO' && parent.counterAxisAlign === 'STRETCH')\n // Layout sets the width of text that grows along a row or stretches across a column.\n const fillsWidth = (!isRow && stretchesCross) || growsWidth\n\n const cache = new Map<number, { width: number; height: number }>()\n const UNCONSTRAINED_KEY = -1\n\n if (autoResize === 'WIDTH_AND_HEIGHT') {\n const importedSize = child.derivedLayout\n if (importedSize?.width !== undefined && importedSize.height !== undefined) {\n yogaChild.setWidth(child.width)\n yogaChild.setHeight(child.height)\n return\n }\n\n // Auto-width text keeps each line whole, as Figma's does, in a parent narrower than the text;\n // only a width that layout or a max width sets wraps it.\n const wraps = fillsWidth || child.maxWidth != null\n yogaChild.setMeasureFunc((width, widthMode, _height, _heightMode) => {\n const maxW = wraps && widthMode !== MeasureMode.Undefined ? width : undefined\n const cacheKey = maxW === undefined ? UNCONSTRAINED_KEY : Math.round(maxW)\n const cached = cache.get(cacheKey)\n if (cached) return cached\n\n const result = measureAutoWidthText(child, maxW ?? autoWidthWrapWidth(child))\n cache.set(cacheKey, result)\n return result\n })\n } else if (autoResize === 'HEIGHT') {\n const fixedWidth = fixedDerivedMainAxis\n ? (child.derivedLayout?.width ?? child.width)\n : child.width\n // Let Yoga stretch or grow fill-width text instead of fixing its stored width.\n if (child.layoutGrow <= 0 && !fillsWidth) {\n yogaChild.setWidth(fixedWidth)\n }\n yogaChild.setMeasureFunc((width, widthMode, _height, _heightMode) => {\n let constraintW = fixedWidth\n if (fillsWidth) {\n if (widthMode !== MeasureMode.Undefined) constraintW = width\n } else if (widthMode !== MeasureMode.Undefined) {\n constraintW = Math.min(width, fixedWidth || width)\n }\n const cacheKey = Math.round(constraintW)\n const cached = cache.get(cacheKey)\n if (cached) return cached\n\n if (constraintW === child.width && (child.derivedTextGlyphs?.length ?? 0) > 0) {\n return { width: constraintW, height: child.height }\n }\n const result = { width: constraintW, height: measureTextForLayout(child, constraintW).height }\n cache.set(cacheKey, result)\n return result\n })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgEA,SAAgB,cAAc,OAAmB,SAAuB;CACtE,MAAM,0BAA0B,sBAAsB,OAAO,OAAO,CAAC;AACvE;;;;;;;AAQA,MAAM,mBAAmB;AAEzB,SAAS,sBAAsB,OAAmB,SAAuB;CACvE,MAAM,QAAQ,MAAM,QAAQ,OAAO;CACnC,IAAI,CAAC,SAAS,MAAM,eAAe,QAAQ;CAE3C,sBAAsB,OAAO,KAAK;CAElC,MAAM,gBAAgB,+BAA+B,OAAO,KAAK;CACjE,MAAM,gBAAgB,kBAAkB,QAAQ,UAAU,MAAM,UAAU;CAG1E,IAAI,WAA4B;CAChC,IAAI;EACF,WACE,MAAM,eAAe,SACjB,cAAc,OAAO,OAAO,aAAa,IACzC,cAAc,OAAO,OAAO,aAAa;EAC/C,SAAS,gBAAgB,KAAA,GAAW,KAAA,GAAW,aAAa;EAC5D,gBAAgB,OAAO,OAAO,UAAU,qBAAqB;CAC/D,UAAU;EACR,IAAI,UAAU,aAAa,QAAQ;CACrC;AACF;AACA,SAAS,+BACP,OACA,MACe;CACf,MAAM,SAAS,KAAK,WAAW,MAAM,QAAQ,KAAK,QAAQ,IAAI;CAC9D,MAAM,qBAAqB,SAAS,+BAA+B,OAAO,MAAM,IAAI;CACpF,OAAO,2BAA2B,MAAM,kBAAkB;AAC5D;AAEA,SAAgB,kBAAkB,OAAmB,SAAwB;CAC3E,MAAM,0BAA0B;EAC9B,MAAM,SAAS,WAAW,MAAM;EAEhC,uBAAuB,OAAO,wBAAQ,IADlB,IACwB,CAAC;EAC7C,IAAI,kCAAkC,OAAO,MAAM,GACjD,uBAAuB,OAAO,wBAAQ,IAAI,IAAI,CAAC;EAEjD,wBAAwB,OAAO,MAAM;CACvC,CAAC;AACH;;;;;AAMA,SAAgB,wBAAwB,OAAmB,QAAsB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c;GAAA,OAClD,IAAI,cAAc,YAAY,WACnC,cAAc,KAAK,IAAI,OAAO,cAAc,KAAK;GAEnD,MAAM,WAAW,KAAK,MAAM,WAAW;GACvC,MAAM,SAAS,MAAM,IAAI,QAAQ;GACjC,IAAI,QAAQ,OAAO;GAEnB,IAAI,gBAAgB,MAAM,UAAU,MAAM,mBAAmB,UAAU,KAAK,GAC1E,OAAO;IAAE,OAAO;IAAa,QAAQ,MAAM;GAAO;GAEpD,MAAM,SAAS;IAAE,OAAO;IAAa,QAAQ,qBAAqB,OAAO,WAAW,CAAC,CAAC;GAAO;GAC7F,MAAM,IAAI,UAAU,MAAM;GAC1B,OAAO;EACT,CAAC;CACH;AACF"}
@@ -10,6 +10,7 @@ declare class Linter {
10
10
  private checks;
11
11
  private nodes;
12
12
  private variables;
13
+ private sharedStyleTypes;
13
14
  constructor(options?: {
14
15
  config?: LintConfig;
15
16
  preset?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"linter.d.ts","names":[],"sources":["../../src/lint/linter.ts"],"mappings":";;;cAuCa;UACH;UACA;UACA;UACA;;UAEA;UACA;UACA;EAKI,YAAA;IAAW,SAAS;IAAY;IAAiB;;EAyB7D,UAAU,OAAO,YAAY,qBAAqB;;;;;UAsB1C;UAWA;UA6DA;UAoCA;;iBA2CM,aAAa;EAAY,SAAS;EAAY;EAAiB;IAAkB"}
1
+ {"version":3,"file":"linter.d.ts","names":[],"sources":["../../src/lint/linter.ts"],"mappings":";;;cAwCa;UACH;UACA;UACA;UACA;;UAEA;UACA;UACA;UAIA;EAEI,YAAA;IAAW,SAAS;IAAY;IAAiB;;EAyB7D,UAAU,OAAO,YAAY,qBAAqB;;;;;UAuB1C;UAWA;UA+DA;UAsCA;;iBAmDM,aAAa;EAAY,SAAS;EAAY;EAAiB;IAAkB"}
@@ -1,6 +1,7 @@
1
1
  import { getNodePath } from "./utils.js";
2
2
  import { presets } from "./presets.js";
3
3
  import { allRules } from "./rules/index.js";
4
+ import { sharedStyleLayers, sharedStyleTypeForKind } from "@pairdraw/scene-graph/shared-styles";
4
5
  import { uniq } from "es-toolkit";
5
6
  import { colorToHex } from "@pairdraw/scene-graph/color";
6
7
  //#region src/lint/linter.ts
@@ -41,6 +42,7 @@ var Linter = class {
41
42
  },
42
43
  colorsByHex: /* @__PURE__ */ new Map()
43
44
  };
45
+ sharedStyleTypes = /* @__PURE__ */ new Map();
44
46
  constructor(options = {}) {
45
47
  let baseConfig = {};
46
48
  if (options.preset) baseConfig = { ...presetRules(options.preset) };
@@ -71,6 +73,7 @@ var Linter = class {
71
73
  this.nodes.clear();
72
74
  this.graph = graph;
73
75
  this.variables = describeVariables(graph);
76
+ this.sharedStyleTypes = sharedStyleTypes(graph);
74
77
  this.checks = this.ruleChecks();
75
78
  const roots = rootIds && rootIds.length > 0 ? rootIds : graph.getPages().map((p) => p.id);
76
79
  for (const id of outermostRoots(graph, roots)) this.lintNode(id, void 0);
@@ -149,7 +152,9 @@ var Linter = class {
149
152
  type: effect.type,
150
153
  visible: effect.visible,
151
154
  radius: effect.type === "SHADER" ? 0 : effect.radius
152
- }))
155
+ })),
156
+ textStyleId: raw.textStyleId,
157
+ effectStyleId: raw.effectStyleId
153
158
  };
154
159
  }
155
160
  ruleChecks() {
@@ -162,6 +167,7 @@ var Linter = class {
162
167
  rule,
163
168
  context: {
164
169
  variables: this.variables,
170
+ isSharedStyle: (kind, id) => id !== null && this.sharedStyleTypes.get(id) === sharedStyleTypeForKind(kind),
165
171
  report: ({ node, message, suggest, data, fix, suggestions }) => {
166
172
  this.messages.push({
167
173
  ruleId,
@@ -209,6 +215,12 @@ function outermostRoots(graph, ids) {
209
215
  return true;
210
216
  });
211
217
  }
218
+ /** The type of each shared style in the document, by the source id layers link it by. */
219
+ function sharedStyleTypes(graph) {
220
+ const types = /* @__PURE__ */ new Map();
221
+ for (const [id, style] of sharedStyleLayers(graph)) if (style.sharedStyleType) types.set(id, style.sharedStyleType);
222
+ return types;
223
+ }
212
224
  function describeVariables(graph) {
213
225
  const counts = {
214
226
  COLOR: 0,
@@ -1 +1 @@
1
- {"version":3,"file":"linter.js","names":[],"sources":["../../src/lint/linter.ts"],"sourcesContent":["import { uniq } from 'es-toolkit'\n\nimport type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { colorToHex } from '@pairdraw/scene-graph/color'\n\nimport { presets } from './presets'\nimport { allRules } from './rules'\nimport type {\n LintConfig,\n LintVariables,\n LintMessage,\n LintNode,\n LintResult,\n Rule,\n RuleContext,\n Severity\n} from './types'\nimport { getNodePath } from './utils'\n\n/** The size and weight of each stretch of a text layer's characters, as the canvas draws them. */\nfunction effectiveTextStyles(node: SceneNode): { fontSize: number; fontWeight: number }[] {\n const base = { fontSize: node.fontSize, fontWeight: node.fontWeight }\n const runs = node.styleRuns.map((run) => ({\n fontSize: run.style.fontSize ?? base.fontSize,\n fontWeight: run.style.fontWeight ?? base.fontWeight\n }))\n const covered = node.styleRuns.reduce((total, run) => total + run.length, 0)\n return covered < node.text.length || runs.length === 0 ? [base, ...runs] : runs\n}\n\n/** A preset's rules, refusing a name no preset has so a typo cannot silently disable linting. */\nfunction presetRules(id: string) {\n if (!Object.hasOwn(presets, id)) {\n const known = Object.keys(presets).sort().join(', ')\n throw new Error(`Unknown lint preset \"${id}\". Known presets: ${known}`)\n }\n return presets[id].rules\n}\n\nexport class Linter {\n private rules = new Map<string, Rule>()\n private ruleConfigs = new Map<string, { severity: Severity; options?: Record<string, unknown> }>()\n private messages: LintMessage[] = []\n private graph: SceneGraph | null = null\n /** The enabled rules with their contexts, made once per run rather than once per layer. */\n private checks: { rule: Rule; context: RuleContext }[] = []\n private nodes = new Map<string, LintNode>()\n private variables: LintVariables = {\n counts: { COLOR: 0, FLOAT: 0, STRING: 0, BOOLEAN: 0 },\n colorsByHex: new Map()\n }\n\n constructor(options: { config?: LintConfig; preset?: string; rules?: string[] } = {}) {\n let baseConfig: Record<\n string,\n Severity | { severity: Severity; options?: Record<string, unknown> }\n > = {}\n if (options.preset) baseConfig = { ...presetRules(options.preset) }\n if (options.config?.extends) {\n const ids = Array.isArray(options.config.extends)\n ? options.config.extends\n : [options.config.extends]\n for (const id of ids) baseConfig = { ...baseConfig, ...presetRules(id) }\n }\n if (options.config?.rules) baseConfig = { ...baseConfig, ...options.config.rules }\n const rulesToLoad = options.rules ?? Object.keys(baseConfig)\n for (const ruleId of rulesToLoad) {\n if (!Object.hasOwn(allRules, ruleId)) throw new Error(`Unknown lint rule \"${ruleId}\"`)\n const rule = allRules[ruleId]\n const config = baseConfig[ruleId]\n if (config === 'off') continue\n this.rules.set(ruleId, rule)\n if (typeof config === 'string') this.ruleConfigs.set(ruleId, { severity: config })\n else this.ruleConfigs.set(ruleId, config)\n }\n }\n\n lintGraph(graph: SceneGraph, rootIds?: string[]): LintResult {\n this.messages = []\n this.nodes.clear()\n this.graph = graph\n this.variables = describeVariables(graph)\n this.checks = this.ruleChecks()\n const roots = rootIds && rootIds.length > 0 ? rootIds : graph.getPages().map((p) => p.id)\n for (const id of outermostRoots(graph, roots)) this.lintNode(id, undefined)\n this.graph = null\n this.checks = []\n return {\n messages: this.messages,\n errorCount: this.messages.filter((m) => m.severity === 'error').length,\n warningCount: this.messages.filter((m) => m.severity === 'warning').length,\n infoCount: this.messages.filter((m) => m.severity === 'info').length\n }\n }\n\n /**\n * The rules' view of `id`, made the first time the walk or a rule reaches it. Instance sublayers\n * are never linted, so on a page made of instances most layers are never converted at all.\n */\n private nodeFor(id: string, parent: LintNode | undefined): LintNode | undefined {\n const cached = this.nodes.get(id)\n if (cached) return cached\n const raw = this.graph?.getNode(id)\n if (!this.graph || !raw) return undefined\n const node = this.toLintNode(this.graph, raw)\n node.parent = parent\n this.nodes.set(id, node)\n return node\n }\n\n private toLintNode(graph: SceneGraph, raw: SceneNode): LintNode {\n // Rules see the color a paint renders with, including a bound variable in this node's mode.\n const paintColor = (\n field: 'fills' | 'strokes',\n index: number,\n color: SceneNode['fills'][number]['color']\n ) => {\n const variableId = raw.boundVariables[`${field}/${index}/color`]\n return (variableId && graph.resolveColorVariableForNode(raw.id, variableId)) || color\n }\n return {\n id: raw.id,\n name: raw.name,\n type: raw.type,\n width: raw.width,\n height: raw.height,\n x: raw.x,\n y: raw.y,\n rotation: raw.rotation,\n visible: raw.visible,\n locked: raw.locked,\n opacity: raw.opacity,\n layoutMode: raw.layoutMode,\n layoutPositioning: raw.layoutPositioning,\n layoutGrow: raw.layoutGrow,\n layoutAlignSelf: raw.layoutAlignSelf,\n primaryAxisSizing: raw.primaryAxisSizing,\n counterAxisSizing: raw.counterAxisSizing,\n textAutoResize: raw.textAutoResize,\n itemSpacing: raw.itemSpacing,\n paddingTop: raw.paddingTop,\n paddingRight: raw.paddingRight,\n paddingBottom: raw.paddingBottom,\n paddingLeft: raw.paddingLeft,\n cornerRadius: raw.cornerRadius,\n childIds: raw.childIds.slice(),\n componentId: raw.componentId || undefined,\n text: raw.text,\n fontSize: raw.fontSize,\n textStyles: raw.type === 'TEXT' ? effectiveTextStyles(raw) : undefined,\n styleRunCount: raw.styleRuns.length,\n boundVariables: raw.boundVariables,\n fills: raw.fills.map((f, index) => ({\n type: f.type,\n visible: f.visible,\n opacity: f.opacity,\n color: f.type === 'SOLID' ? paintColor('fills', index, f.color) : undefined\n })),\n strokes: raw.strokes.map((stroke, index) => ({\n visible: stroke.visible,\n opacity: stroke.opacity,\n color: paintColor('strokes', index, stroke.color)\n })),\n effects: raw.effects.map((effect) => ({\n type: effect.type,\n visible: effect.visible,\n radius: effect.type === 'SHADER' ? 0 : effect.radius\n }))\n }\n }\n\n private ruleChecks(): { rule: Rule; context: RuleContext }[] {\n const checks: { rule: Rule; context: RuleContext }[] = []\n for (const [ruleId, rule] of this.rules) {\n const config = this.ruleConfigs.get(ruleId)\n if (!config || config.severity === 'off') continue\n const severity = config.severity\n checks.push({\n rule,\n context: {\n variables: this.variables,\n report: ({ node, message, suggest, data, fix, suggestions }) => {\n this.messages.push({\n ruleId,\n severity,\n message,\n nodeId: node.id,\n nodeName: node.name,\n nodePath: getNodePath(this.nodes.get(node.id) ?? node),\n suggest,\n data,\n fix,\n suggestions\n })\n },\n getConfig: () => config.options,\n getParent: (node) => this.nodes.get(node.id)?.parent ?? null,\n getChildren: (node) =>\n node.childIds\n .map((childId) => this.nodeFor(childId, this.nodes.get(node.id)))\n .filter((child): child is LintNode => !!child)\n }\n })\n }\n return checks\n }\n\n private lintNode(id: string, parent: LintNode | undefined) {\n const node = this.nodeFor(id, parent)\n if (!node) return\n for (const { rule, context } of this.checks) {\n if (rule.match && !rule.match.includes(node.type)) continue\n rule.check(node, context)\n }\n // Instance sublayers mirror their main component: issues there are fixed once in the\n // component, so reporting every placed copy only multiplies the same finding.\n if (node.type === 'INSTANCE') return\n for (const childId of node.childIds) this.lintNode(childId, node)\n }\n}\n\n/**\n * The roots no other root contains, each once. A layer inside another root is linted with it,\n * so it has its real parents and reports once.\n */\nfunction outermostRoots(graph: SceneGraph, ids: readonly string[]): string[] {\n const requested = new Set(ids)\n return uniq(ids).filter((id) => {\n for (let parentId = graph.getNode(id)?.parentId; parentId;) {\n if (requested.has(parentId)) return false\n parentId = graph.getNode(parentId)?.parentId\n }\n return true\n })\n}\n\nfunction describeVariables(graph: SceneGraph): LintVariables {\n const counts = { COLOR: 0, FLOAT: 0, STRING: 0, BOOLEAN: 0 }\n const colorsByHex = new Map<string, { id: string; name: string }>()\n for (const variable of graph.variables.values()) {\n counts[variable.type]++\n if (variable.type !== 'COLOR') continue\n const color = graph.resolveColorVariable(variable.id)\n if (!color || color.a < 1) continue\n const hex = colorToHex(color)\n if (!colorsByHex.has(hex)) colorsByHex.set(hex, { id: variable.id, name: variable.name })\n }\n return { counts, colorsByHex }\n}\n\nexport function createLinter(options?: { config?: LintConfig; preset?: string; rules?: string[] }) {\n return new Linter(options)\n}\n"],"mappings":";;;;;;;AAoBA,SAAS,oBAAoB,MAA6D;CACxF,MAAM,OAAO;EAAE,UAAU,KAAK;EAAU,YAAY,KAAK;CAAW;CACpE,MAAM,OAA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;;;AAMA,SAAS,eAAe,OAAmB,KAAkC;CAC3E,MAAM,YAAY,IAAI,IAAI,GAAG;CAC7B,OAAO,KAAK,GAAG,CAAC,CAAC,QAAQ,OAAO;EAC9B,KAAK,IAAI,WAAW,MAAM,QAAQ,EAAE,CAAC,EAAE,UAAU,WAAW;GAC1D,IAAI,UAAU,IAAI,QAAQ,GAAG,OAAO;GACpC,WAAW,MAAM,QAAQ,QAAQ,CAAC,EAAE;EACtC;EACA,OAAO;CACT,CAAC;AACH;AAEA,SAAS,kBAAkB,OAAkC;CAC3D,MAAM,SAAS;EAAE,OAAO;EAAG,OAAO;EAAG,QAAQ;EAAG,SAAS;CAAE;CAC3D,MAAM,8BAAc,IAAI,IAA0C;CAClE,KAAK,MAAM,YAAY,MAAM,UAAU,OAAO,GAAG;EAC/C,OAAO,SAAS,KAAK;EACrB,IAAI,SAAS,SAAS,SAAS;EAC/B,MAAM,QAAQ,MAAM,qBAAqB,SAAS,EAAE;EACpD,IAAI,CAAC,SAAS,MAAM,IAAI,GAAG;EAC3B,MAAM,MAAM,WAAW,KAAK;EAC5B,IAAI,CAAC,YAAY,IAAI,GAAG,GAAG,YAAY,IAAI,KAAK;GAAE,IAAI,SAAS;GAAI,MAAM,SAAS;EAAK,CAAC;CAC1F;CACA,OAAO;EAAE;EAAQ;CAAY;AAC/B;AAEA,SAAgB,aAAa,SAAsE;CACjG,OAAO,IAAI,OAAO,OAAO;AAC3B"}
1
+ {"version":3,"file":"linter.js","names":[],"sources":["../../src/lint/linter.ts"],"sourcesContent":["import { uniq } from 'es-toolkit'\n\nimport type { SceneGraph, SceneNode, SharedStyleType } from '@pairdraw/scene-graph'\nimport { colorToHex } from '@pairdraw/scene-graph/color'\nimport { sharedStyleLayers, sharedStyleTypeForKind } from '@pairdraw/scene-graph/shared-styles'\n\nimport { presets } from './presets'\nimport { allRules } from './rules'\nimport type {\n LintConfig,\n LintVariables,\n LintMessage,\n LintNode,\n LintResult,\n Rule,\n RuleContext,\n Severity\n} from './types'\nimport { getNodePath } from './utils'\n\n/** The size and weight of each stretch of a text layer's characters, as the canvas draws them. */\nfunction effectiveTextStyles(node: SceneNode): { fontSize: number; fontWeight: number }[] {\n const base = { fontSize: node.fontSize, fontWeight: node.fontWeight }\n const runs = node.styleRuns.map((run) => ({\n fontSize: run.style.fontSize ?? base.fontSize,\n fontWeight: run.style.fontWeight ?? base.fontWeight\n }))\n const covered = node.styleRuns.reduce((total, run) => total + run.length, 0)\n return covered < node.text.length || runs.length === 0 ? [base, ...runs] : runs\n}\n\n/** A preset's rules, refusing a name no preset has so a typo cannot silently disable linting. */\nfunction presetRules(id: string) {\n if (!Object.hasOwn(presets, id)) {\n const known = Object.keys(presets).sort().join(', ')\n throw new Error(`Unknown lint preset \"${id}\". Known presets: ${known}`)\n }\n return presets[id].rules\n}\n\nexport class Linter {\n private rules = new Map<string, Rule>()\n private ruleConfigs = new Map<string, { severity: Severity; options?: Record<string, unknown> }>()\n private messages: LintMessage[] = []\n private graph: SceneGraph | null = null\n /** The enabled rules with their contexts, made once per run rather than once per layer. */\n private checks: { rule: Rule; context: RuleContext }[] = []\n private nodes = new Map<string, LintNode>()\n private variables: LintVariables = {\n counts: { COLOR: 0, FLOAT: 0, STRING: 0, BOOLEAN: 0 },\n colorsByHex: new Map()\n }\n private sharedStyleTypes: ReadonlyMap<string, SharedStyleType> = new Map()\n\n constructor(options: { config?: LintConfig; preset?: string; rules?: string[] } = {}) {\n let baseConfig: Record<\n string,\n Severity | { severity: Severity; options?: Record<string, unknown> }\n > = {}\n if (options.preset) baseConfig = { ...presetRules(options.preset) }\n if (options.config?.extends) {\n const ids = Array.isArray(options.config.extends)\n ? options.config.extends\n : [options.config.extends]\n for (const id of ids) baseConfig = { ...baseConfig, ...presetRules(id) }\n }\n if (options.config?.rules) baseConfig = { ...baseConfig, ...options.config.rules }\n const rulesToLoad = options.rules ?? Object.keys(baseConfig)\n for (const ruleId of rulesToLoad) {\n if (!Object.hasOwn(allRules, ruleId)) throw new Error(`Unknown lint rule \"${ruleId}\"`)\n const rule = allRules[ruleId]\n const config = baseConfig[ruleId]\n if (config === 'off') continue\n this.rules.set(ruleId, rule)\n if (typeof config === 'string') this.ruleConfigs.set(ruleId, { severity: config })\n else this.ruleConfigs.set(ruleId, config)\n }\n }\n\n lintGraph(graph: SceneGraph, rootIds?: string[]): LintResult {\n this.messages = []\n this.nodes.clear()\n this.graph = graph\n this.variables = describeVariables(graph)\n this.sharedStyleTypes = sharedStyleTypes(graph)\n this.checks = this.ruleChecks()\n const roots = rootIds && rootIds.length > 0 ? rootIds : graph.getPages().map((p) => p.id)\n for (const id of outermostRoots(graph, roots)) this.lintNode(id, undefined)\n this.graph = null\n this.checks = []\n return {\n messages: this.messages,\n errorCount: this.messages.filter((m) => m.severity === 'error').length,\n warningCount: this.messages.filter((m) => m.severity === 'warning').length,\n infoCount: this.messages.filter((m) => m.severity === 'info').length\n }\n }\n\n /**\n * The rules' view of `id`, made the first time the walk or a rule reaches it. Instance sublayers\n * are never linted, so on a page made of instances most layers are never converted at all.\n */\n private nodeFor(id: string, parent: LintNode | undefined): LintNode | undefined {\n const cached = this.nodes.get(id)\n if (cached) return cached\n const raw = this.graph?.getNode(id)\n if (!this.graph || !raw) return undefined\n const node = this.toLintNode(this.graph, raw)\n node.parent = parent\n this.nodes.set(id, node)\n return node\n }\n\n private toLintNode(graph: SceneGraph, raw: SceneNode): LintNode {\n // Rules see the color a paint renders with, including a bound variable in this node's mode.\n const paintColor = (\n field: 'fills' | 'strokes',\n index: number,\n color: SceneNode['fills'][number]['color']\n ) => {\n const variableId = raw.boundVariables[`${field}/${index}/color`]\n return (variableId && graph.resolveColorVariableForNode(raw.id, variableId)) || color\n }\n return {\n id: raw.id,\n name: raw.name,\n type: raw.type,\n width: raw.width,\n height: raw.height,\n x: raw.x,\n y: raw.y,\n rotation: raw.rotation,\n visible: raw.visible,\n locked: raw.locked,\n opacity: raw.opacity,\n layoutMode: raw.layoutMode,\n layoutPositioning: raw.layoutPositioning,\n layoutGrow: raw.layoutGrow,\n layoutAlignSelf: raw.layoutAlignSelf,\n primaryAxisSizing: raw.primaryAxisSizing,\n counterAxisSizing: raw.counterAxisSizing,\n textAutoResize: raw.textAutoResize,\n itemSpacing: raw.itemSpacing,\n paddingTop: raw.paddingTop,\n paddingRight: raw.paddingRight,\n paddingBottom: raw.paddingBottom,\n paddingLeft: raw.paddingLeft,\n cornerRadius: raw.cornerRadius,\n childIds: raw.childIds.slice(),\n componentId: raw.componentId || undefined,\n text: raw.text,\n fontSize: raw.fontSize,\n textStyles: raw.type === 'TEXT' ? effectiveTextStyles(raw) : undefined,\n styleRunCount: raw.styleRuns.length,\n boundVariables: raw.boundVariables,\n fills: raw.fills.map((f, index) => ({\n type: f.type,\n visible: f.visible,\n opacity: f.opacity,\n color: f.type === 'SOLID' ? paintColor('fills', index, f.color) : undefined\n })),\n strokes: raw.strokes.map((stroke, index) => ({\n visible: stroke.visible,\n opacity: stroke.opacity,\n color: paintColor('strokes', index, stroke.color)\n })),\n effects: raw.effects.map((effect) => ({\n type: effect.type,\n visible: effect.visible,\n radius: effect.type === 'SHADER' ? 0 : effect.radius\n })),\n textStyleId: raw.textStyleId,\n effectStyleId: raw.effectStyleId\n }\n }\n\n private ruleChecks(): { rule: Rule; context: RuleContext }[] {\n const checks: { rule: Rule; context: RuleContext }[] = []\n for (const [ruleId, rule] of this.rules) {\n const config = this.ruleConfigs.get(ruleId)\n if (!config || config.severity === 'off') continue\n const severity = config.severity\n checks.push({\n rule,\n context: {\n variables: this.variables,\n isSharedStyle: (kind, id) =>\n id !== null && this.sharedStyleTypes.get(id) === sharedStyleTypeForKind(kind),\n report: ({ node, message, suggest, data, fix, suggestions }) => {\n this.messages.push({\n ruleId,\n severity,\n message,\n nodeId: node.id,\n nodeName: node.name,\n nodePath: getNodePath(this.nodes.get(node.id) ?? node),\n suggest,\n data,\n fix,\n suggestions\n })\n },\n getConfig: () => config.options,\n getParent: (node) => this.nodes.get(node.id)?.parent ?? null,\n getChildren: (node) =>\n node.childIds\n .map((childId) => this.nodeFor(childId, this.nodes.get(node.id)))\n .filter((child): child is LintNode => !!child)\n }\n })\n }\n return checks\n }\n\n private lintNode(id: string, parent: LintNode | undefined) {\n const node = this.nodeFor(id, parent)\n if (!node) return\n for (const { rule, context } of this.checks) {\n if (rule.match && !rule.match.includes(node.type)) continue\n rule.check(node, context)\n }\n // Instance sublayers mirror their main component: issues there are fixed once in the\n // component, so reporting every placed copy only multiplies the same finding.\n if (node.type === 'INSTANCE') return\n for (const childId of node.childIds) this.lintNode(childId, node)\n }\n}\n\n/**\n * The roots no other root contains, each once. A layer inside another root is linted with it,\n * so it has its real parents and reports once.\n */\nfunction outermostRoots(graph: SceneGraph, ids: readonly string[]): string[] {\n const requested = new Set(ids)\n return uniq(ids).filter((id) => {\n for (let parentId = graph.getNode(id)?.parentId; parentId;) {\n if (requested.has(parentId)) return false\n parentId = graph.getNode(parentId)?.parentId\n }\n return true\n })\n}\n\n/** The type of each shared style in the document, by the source id layers link it by. */\nfunction sharedStyleTypes(graph: SceneGraph): ReadonlyMap<string, SharedStyleType> {\n const types = new Map<string, SharedStyleType>()\n for (const [id, style] of sharedStyleLayers(graph))\n if (style.sharedStyleType) types.set(id, style.sharedStyleType)\n return types\n}\n\nfunction describeVariables(graph: SceneGraph): LintVariables {\n const counts = { COLOR: 0, FLOAT: 0, STRING: 0, BOOLEAN: 0 }\n const colorsByHex = new Map<string, { id: string; name: string }>()\n for (const variable of graph.variables.values()) {\n counts[variable.type]++\n if (variable.type !== 'COLOR') continue\n const color = graph.resolveColorVariable(variable.id)\n if (!color || color.a < 1) continue\n const hex = colorToHex(color)\n if (!colorsByHex.has(hex)) colorsByHex.set(hex, { id: variable.id, name: variable.name })\n }\n return { counts, colorsByHex }\n}\n\nexport function createLinter(options?: { config?: LintConfig; preset?: string; rules?: string[] }) {\n return new Linter(options)\n}\n"],"mappings":";;;;;;;;AAqBA,SAAS,oBAAoB,MAA6D;CACxF,MAAM,OA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AAO;EAAE;EAAQ;CAAY;AAC/B;AAEA,SAAgB,aAAa,SAAsE;CACjG,OAAO,IAAI,OAAO,OAAO;AAC3B"}
@@ -9,6 +9,7 @@ var effect_style_required_default = defineRule({
9
9
  check(node, context) {
10
10
  const visibleEffects = node.effects.filter((effect) => effect.visible);
11
11
  if (visibleEffects.length === 0) return;
12
+ if (context.isSharedStyle("effect", node.effectStyleId)) return;
12
13
  context.report({
13
14
  node,
14
15
  message: `Effect without shared style: ${visibleEffects.map((effect) => `${effect.type} ${effect.radius}px`).join(", ")}`,
@@ -1 +1 @@
1
- {"version":3,"file":"effect-style-required.js","names":[],"sources":["../../../src/lint/rules/effect-style-required.ts"],"sourcesContent":["import { defineRule } from '#core/lint/rule'\n\nexport default defineRule({\n meta: {\n id: 'effect-style-required',\n category: 'design-tokens',\n description: 'Effects should use shared effect presets or tokens'\n },\n check(node, context) {\n const visibleEffects = node.effects.filter((effect) => effect.visible)\n if (visibleEffects.length === 0) return\n context.report({\n node,\n message: `Effect without shared style: ${visibleEffects.map((effect) => `${effect.type} ${effect.radius}px`).join(', ')}`,\n suggest: 'Extract reusable shadows and blurs into shared presets or variables',\n data: { effect: visibleEffects[0].type, count: visibleEffects.length }\n })\n }\n})\n"],"mappings":";;AAEA,IAAA,gCAAe,WAAW;CACxB,MAAM;EACJ,IAAI;EACJ,UAAU;EACV,aAAa;CACf;CACA,MAAM,MAAM,SAAS;EACnB,MAAM,iBAAiB,KAAK,QAAQ,QAAQ,WAAW,OAAO,OAAO;EACrE,IAAI,eAAe,WAAW,GAAG;EACjC,QAAQ,OAAO;GACb;GACA,SAAS,gCAAgC,eAAe,KAAK,WAAW,GAAG,OAAO,KAAK,GAAG,OAAO,OAAO,GAAG,CAAC,CAAC,KAAK,IAAI;GACtH,SAAS;GACT,MAAM;IAAE,QAAQ,eAAe,EAAE,CAAC;IAAM,OAAO,eAAe;GAAO;EACvE,CAAC;CACH;AACF,CAAC"}
1
+ {"version":3,"file":"effect-style-required.js","names":[],"sources":["../../../src/lint/rules/effect-style-required.ts"],"sourcesContent":["import { defineRule } from '#core/lint/rule'\n\nexport default defineRule({\n meta: {\n id: 'effect-style-required',\n category: 'design-tokens',\n description: 'Effects should use shared effect presets or tokens'\n },\n check(node, context) {\n const visibleEffects = node.effects.filter((effect) => effect.visible)\n if (visibleEffects.length === 0) return\n // A link to a shared EFFECT style is already the preset this rule asks for.\n if (context.isSharedStyle('effect', node.effectStyleId)) return\n context.report({\n node,\n message: `Effect without shared style: ${visibleEffects.map((effect) => `${effect.type} ${effect.radius}px`).join(', ')}`,\n suggest: 'Extract reusable shadows and blurs into shared presets or variables',\n data: { effect: visibleEffects[0].type, count: visibleEffects.length }\n })\n }\n})\n"],"mappings":";;AAEA,IAAA,gCAAe,WAAW;CACxB,MAAM;EACJ,IAAI;EACJ,UAAU;EACV,aAAa;CACf;CACA,MAAM,MAAM,SAAS;EACnB,MAAM,iBAAiB,KAAK,QAAQ,QAAQ,WAAW,OAAO,OAAO;EACrE,IAAI,eAAe,WAAW,GAAG;EAEjC,IAAI,QAAQ,cAAc,UAAU,KAAK,aAAa,GAAG;EACzD,QAAQ,OAAO;GACb;GACA,SAAS,gCAAgC,eAAe,KAAK,WAAW,GAAG,OAAO,KAAK,GAAG,OAAO,OAAO,GAAG,CAAC,CAAC,KAAK,IAAI;GACtH,SAAS;GACT,MAAM;IAAE,QAAQ,eAAe,EAAE,CAAC;IAAM,OAAO,eAAe;GAAO;EACvE,CAAC;CACH;AACF,CAAC"}
@@ -9,6 +9,7 @@ var text_style_required_default = defineRule({
9
9
  match: ["TEXT"],
10
10
  check(node, context) {
11
11
  if (node.text.length <= 2) return;
12
+ if (context.isSharedStyle("text", node.textStyleId)) return;
12
13
  if (node.boundVariables.fontSize || node.boundVariables.fontFamily) return;
13
14
  const { FLOAT, STRING } = context.variables.counts;
14
15
  if (FLOAT === 0 && STRING === 0) return;
@@ -1 +1 @@
1
- {"version":3,"file":"text-style-required.js","names":[],"sources":["../../../src/lint/rules/text-style-required.ts"],"sourcesContent":["import { defineRule } from '#core/lint/rule'\n\nexport default defineRule({\n meta: {\n id: 'text-style-required',\n category: 'typography',\n description: 'Text layers should use shared typography tokens or styles'\n },\n match: ['TEXT'],\n check(node, context) {\n if (node.text.length <= 2) return\n if (node.boundVariables.fontSize || node.boundVariables.fontFamily) return\n // Suggesting a binding is only actionable when the document has typography values to bind.\n const { FLOAT, STRING } = context.variables.counts\n if (FLOAT === 0 && STRING === 0) return\n context.report({\n node,\n message: 'Text layer without typography variable bindings',\n suggest: 'Bind font size or font family to a shared text token when possible'\n })\n }\n})\n"],"mappings":";;AAEA,IAAA,8BAAe,WAAW;CACxB,MAAM;EACJ,IAAI;EACJ,UAAU;EACV,aAAa;CACf;CACA,OAAO,CAAC,MAAM;CACd,MAAM,MAAM,SAAS;EACnB,IAAI,KAAK,KAAK,UAAU,GAAG;EAC3B,IAAI,KAAK,eAAe,YAAY,KAAK,eAAe,YAAY;EAEpE,MAAM,EAAE,OAAO,WAAW,QAAQ,UAAU;EAC5C,IAAI,UAAU,KAAK,WAAW,GAAG;EACjC,QAAQ,OAAO;GACb;GACA,SAAS;GACT,SAAS;EACX,CAAC;CACH;AACF,CAAC"}
1
+ {"version":3,"file":"text-style-required.js","names":[],"sources":["../../../src/lint/rules/text-style-required.ts"],"sourcesContent":["import { defineRule } from '#core/lint/rule'\n\nexport default defineRule({\n meta: {\n id: 'text-style-required',\n category: 'typography',\n description: 'Text layers should use shared typography tokens or styles'\n },\n match: ['TEXT'],\n check(node, context) {\n if (node.text.length <= 2) return\n // A shared text style is already the shared typography this rule asks for.\n if (context.isSharedStyle('text', node.textStyleId)) return\n if (node.boundVariables.fontSize || node.boundVariables.fontFamily) return\n // Suggesting a binding is only actionable when the document has typography values to bind.\n const { FLOAT, STRING } = context.variables.counts\n if (FLOAT === 0 && STRING === 0) return\n context.report({\n node,\n message: 'Text layer without typography variable bindings',\n suggest: 'Bind font size or font family to a shared text token when possible'\n })\n }\n})\n"],"mappings":";;AAEA,IAAA,8BAAe,WAAW;CACxB,MAAM;EACJ,IAAI;EACJ,UAAU;EACV,aAAa;CACf;CACA,OAAO,CAAC,MAAM;CACd,MAAM,MAAM,SAAS;EACnB,IAAI,KAAK,KAAK,UAAU,GAAG;EAE3B,IAAI,QAAQ,cAAc,QAAQ,KAAK,WAAW,GAAG;EACrD,IAAI,KAAK,eAAe,YAAY,KAAK,eAAe,YAAY;EAEpE,MAAM,EAAE,OAAO,WAAW,QAAQ,UAAU;EAC5C,IAAI,UAAU,KAAK,WAAW,GAAG;EACjC,QAAQ,OAAO;GACb;GACA,SAAS;GACT,SAAS;EACX,CAAC;CACH;AACF,CAAC"}
@@ -1,3 +1,4 @@
1
+ import { SharedStyleKind } from "@pairdraw/scene-graph";
1
2
  //#region src/lint/types.d.ts
2
3
  type Severity = 'error' | 'warning' | 'info' | 'off';
3
4
  type Category = 'layout' | 'accessibility' | 'naming' | 'structure' | 'components' | 'design-tokens' | 'typography';
@@ -122,6 +123,10 @@ interface LintNode {
122
123
  visible: boolean;
123
124
  radius: number;
124
125
  }>;
126
+ /** The shared text style this layer uses, when it has one. */
127
+ textStyleId: string | null;
128
+ /** The shared effect style this layer uses, when it has one. */
129
+ effectStyleId: string | null;
125
130
  parent?: LintNode;
126
131
  }
127
132
  /** The document's variables, which decide whether a rule suggesting a binding is actionable. */
@@ -136,6 +141,8 @@ interface LintVariables {
136
141
  }
137
142
  interface RuleContext {
138
143
  variables: LintVariables;
144
+ /** Whether `id`, a layer's style link, names a shared style of that kind in the document. */
145
+ isSharedStyle(kind: SharedStyleKind, id: string | null): boolean;
139
146
  report(issue: {
140
147
  node: LintNode;
141
148
  message: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","names":[],"sources":["../../src/lint/types.ts"],"mappings":";KAAY;KAEA;UASK;EACf;EACA,UAAU;EACV,UAAU;EACV;;;KAIU,kBAAkB,SAAS;;KAG3B;;;;;KAiBA;EACN;EAAuB;EAAc;EAAoB;;EACzD;EAAa,SAAS,SAAS,QAAQ,OAAO;;;;EAE9C;;;;EAEA;;UAEW;EACf;EACA,UAAU,QAAQ;EAClB;EACA;EACA;EACA;EACA;EACA,OAAO;;EAEP,MAAM;;EAEN,cAAc;;UAGC;EACf,UAAU;EACV;EACA;EACA;;UAGe;EACf;EACA,OAAO,eAAe;IAAa,UAAU;IAAU,UAAU;;;UAGlD;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;;;EAKA;IAAe;IAAkB;;EACjC;EACA,gBAAgB;EAChB,OAAO;IACL;IACA;IACA;IACA;MAAU;MAAW;MAAW;;;EAElC,SAAS;IACP;IACA;IACA;MAAU;MAAW;MAAW;;;EAElC,SAAS;IACP;IACA;IACA;;EAEF,SAAS;;;UAIM;;EAEf,QAAQ,SAAS;;EAEjB,aAAa;IAAsB;IAAY;;;UAGhC;EACf,WAAW;EACX,OAAO;IACL,MAAM;IACN;IACA;IACA,OAAO;IACP,MAAM;IACN,cAAc;;EAEhB;EACA,UAAU,MAAM,WAAW;EAC3B,YAAY,MAAM,WAAW;;UAGd;EACf,MAAM;EACN;EACA,MAAM,MAAM,UAAU,SAAS"}
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../../src/lint/types.ts"],"mappings":";;KAEY;KAEA;UASK;EACf;EACA,UAAU;EACV,UAAU;EACV;;;KAIU,kBAAkB,SAAS;;KAG3B;;;;;KAiBA;EACN;EAAuB;EAAc;EAAoB;;EACzD;EAAa,SAAS,SAAS,QAAQ,OAAO;;;;EAE9C;;;;EAEA;;UAEW;EACf;EACA,UAAU,QAAQ;EAClB;EACA;EACA;EACA;EACA;EACA,OAAO;;EAEP,MAAM;;EAEN,cAAc;;UAGC;EACf,UAAU;EACV;EACA;EACA;;UAGe;EACf;EACA,OAAO,eAAe;IAAa,UAAU;IAAU,UAAU;;;UAGlD;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;;;EAKA;IAAe;IAAkB;;EACjC;EACA,gBAAgB;EAChB,OAAO;IACL;IACA;IACA;IACA;MAAU;MAAW;MAAW;;;EAElC,SAAS;IACP;IACA;IACA;MAAU;MAAW;MAAW;;;EAElC,SAAS;IACP;IACA;IACA;;;EAGF;;EAEA;EACA,SAAS;;;UAIM;;EAEf,QAAQ,SAAS;;EAEjB,aAAa;IAAsB;IAAY;;;UAGhC;EACf,WAAW;;EAEX,cAAc,MAAM,iBAAiB;EACrC,OAAO;IACL,MAAM;IACN;IACA;IACA,OAAO;IACP,MAAM;IACN,cAAc;;EAEhB;EACA,UAAU,MAAM,WAAW;EAC3B,YAAY,MAAM,WAAW;;UAGd;EACf,MAAM;EACN;EACA,MAAM,MAAM,UAAU,SAAS"}
@@ -1,7 +1,7 @@
1
1
  import { AnalyzeOverlapsArgs, AnalyzeOverlapsResult } from "../tools/analyze/overlaps/index.js";
2
2
  import { RPCCommand } from "./types.js";
3
3
  import { AnalyzeClustersArgs, AnalyzeClustersResult, AnalyzeColorsArgs, AnalyzeColorsResult, AnalyzeSpacingResult, AnalyzeTypographyArgs, AnalyzeTypographyResult, SpacingValue, TypographyStyle, analyzeClustersCommand, analyzeColorsCommand, analyzeOverlapsCommand, analyzeSpacingCommand, analyzeTypographyCommand } from "./analyze-commands.js";
4
- import { FindArgs, FindNodeResult, InfoResult, NodeArgs, NodeResult, PageItem, QueryArgs, QueryNodeResult, TreeArgs, TreeNodeResult, TreeResult, findCommand, fontStatusCommand, infoCommand, nodeCommand, pagesCommand, queryCommand, treeCommand } from "./read-commands.js";
4
+ import { FindArgs, FindNodeResult, InfoResult, NodeArgs, NodeResult, PageArgs, PageItem, QueryArgs, QueryNodeResult, TreeArgs, TreeNodeResult, TreeResult, findCommand, fontStatusCommand, infoCommand, nodeCommand, pagesCommand, queryCommand, treeCommand } from "./read-commands.js";
5
5
  import { TokensArgs, TokensResult, VariablesArgs, VariablesResult, tokensCommand, variablesCommand } from "./variables-command.js";
6
6
  import { SceneGraph } from "@pairdraw/scene-graph";
7
7
  //#region src/rpc/commands.d.ts
@@ -20,5 +20,5 @@ type AutomationDocumentSummary = {
20
20
  declare const ALL_RPC_COMMANDS: RPCCommand[];
21
21
  declare function executeRPCCommand(graph: SceneGraph, name: string, args: unknown): unknown;
22
22
  //#endregion
23
- export { ALL_RPC_COMMANDS, AnalyzeClustersArgs, AnalyzeClustersResult, AnalyzeColorsArgs, AnalyzeColorsResult, type AnalyzeOverlapsArgs, type AnalyzeOverlapsResult, AnalyzeSpacingResult, AnalyzeTypographyArgs, AnalyzeTypographyResult, AutomationDocumentSummary, FindArgs, FindNodeResult, InfoResult, NodeArgs, NodeResult, PageItem, QueryArgs, QueryNodeResult, type RPCCommand, SpacingValue, TokensArgs, TokensResult, TreeArgs, TreeNodeResult, TreeResult, TypographyStyle, VariablesArgs, VariablesResult, analyzeClustersCommand, analyzeColorsCommand, analyzeOverlapsCommand, analyzeSpacingCommand, analyzeTypographyCommand, executeRPCCommand, findCommand, fontStatusCommand, infoCommand, nodeCommand, pagesCommand, queryCommand, tokensCommand, treeCommand, variablesCommand };
23
+ export { ALL_RPC_COMMANDS, AnalyzeClustersArgs, AnalyzeClustersResult, AnalyzeColorsArgs, AnalyzeColorsResult, type AnalyzeOverlapsArgs, type AnalyzeOverlapsResult, AnalyzeSpacingResult, AnalyzeTypographyArgs, AnalyzeTypographyResult, AutomationDocumentSummary, FindArgs, FindNodeResult, InfoResult, NodeArgs, NodeResult, PageArgs, PageItem, QueryArgs, QueryNodeResult, type RPCCommand, SpacingValue, TokensArgs, TokensResult, TreeArgs, TreeNodeResult, TreeResult, TypographyStyle, VariablesArgs, VariablesResult, analyzeClustersCommand, analyzeColorsCommand, analyzeOverlapsCommand, analyzeSpacingCommand, analyzeTypographyCommand, executeRPCCommand, findCommand, fontStatusCommand, infoCommand, nodeCommand, pagesCommand, queryCommand, tokensCommand, treeCommand, variablesCommand };
24
24
  //# sourceMappingURL=commands.d.ts.map
@@ -1,6 +1,6 @@
1
1
  import { AnalyzeOverlapsArgs, AnalyzeOverlapsResult } from "../tools/analyze/overlaps/index.js";
2
2
  import { AnalyzeClustersArgs, AnalyzeClustersResult, AnalyzeColorsArgs, AnalyzeColorsResult, AnalyzeSpacingResult, AnalyzeTypographyArgs, AnalyzeTypographyResult, SpacingValue, TypographyStyle } from "./analyze-commands.js";
3
- import { FindArgs, FindNodeResult, InfoResult, NodeArgs, NodeResult, PageItem, QueryArgs, QueryNodeResult, TreeArgs, TreeNodeResult, TreeResult } from "./read-commands.js";
3
+ import { FindArgs, FindNodeResult, InfoResult, NodeArgs, NodeResult, PageArgs, PageItem, QueryArgs, QueryNodeResult, TreeArgs, TreeNodeResult, TreeResult } from "./read-commands.js";
4
4
  import { TokensArgs, TokensResult, VariablesArgs, VariablesResult } from "./variables-command.js";
5
5
  import { ALL_RPC_COMMANDS, AutomationDocumentSummary, executeRPCCommand } from "./commands.js";
6
- export { ALL_RPC_COMMANDS, type AnalyzeClustersArgs, type AnalyzeClustersResult, type AnalyzeColorsArgs, type AnalyzeColorsResult, type AnalyzeOverlapsArgs, type AnalyzeOverlapsResult, type AnalyzeSpacingResult, type AnalyzeTypographyArgs, type AnalyzeTypographyResult, type AutomationDocumentSummary, type FindArgs, type FindNodeResult, type InfoResult, type NodeArgs, type NodeResult, type PageItem, type QueryArgs, type QueryNodeResult, type SpacingValue, type TokensArgs, type TokensResult, type TreeArgs, type TreeNodeResult, type TreeResult, type TypographyStyle, type VariablesArgs, type VariablesResult, executeRPCCommand };
6
+ export { ALL_RPC_COMMANDS, type AnalyzeClustersArgs, type AnalyzeClustersResult, type AnalyzeColorsArgs, type AnalyzeColorsResult, type AnalyzeOverlapsArgs, type AnalyzeOverlapsResult, type AnalyzeSpacingResult, type AnalyzeTypographyArgs, type AnalyzeTypographyResult, type AutomationDocumentSummary, type FindArgs, type FindNodeResult, type InfoResult, type NodeArgs, type NodeResult, type PageArgs, type PageItem, type QueryArgs, type QueryNodeResult, type SpacingValue, type TokensArgs, type TokensResult, type TreeArgs, type TreeNodeResult, type TreeResult, type TypographyStyle, type VariablesArgs, type VariablesResult, executeRPCCommand };