@open-pencil/scene-graph 0.17.0-beta.4 → 0.17.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (283) hide show
  1. package/dist/arrays.d.ts +17 -0
  2. package/dist/arrays.d.ts.map +1 -0
  3. package/dist/arrays.js +38 -0
  4. package/dist/arrays.js.map +1 -0
  5. package/dist/buffered-events.js +1 -1
  6. package/dist/buffered-events.js.map +1 -1
  7. package/dist/clipping.d.ts +7 -1
  8. package/dist/clipping.d.ts.map +1 -1
  9. package/dist/clipping.js +23 -19
  10. package/dist/clipping.js.map +1 -1
  11. package/dist/components/index.d.ts +2 -2
  12. package/dist/components/index.js +2 -2
  13. package/dist/components/properties.d.ts +1 -3
  14. package/dist/components/properties.d.ts.map +1 -1
  15. package/dist/components/properties.js +2 -9
  16. package/dist/components/properties.js.map +1 -1
  17. package/dist/corners.d.ts +22 -0
  18. package/dist/corners.d.ts.map +1 -0
  19. package/dist/corners.js +52 -0
  20. package/dist/corners.js.map +1 -0
  21. package/dist/css/grid.d.ts +4 -1
  22. package/dist/css/grid.d.ts.map +1 -1
  23. package/dist/css/grid.js +16 -7
  24. package/dist/css/grid.js.map +1 -1
  25. package/dist/css/index.d.ts +2 -2
  26. package/dist/css/index.js +2 -2
  27. package/dist/css/values.d.ts +6 -1
  28. package/dist/css/values.d.ts.map +1 -1
  29. package/dist/font-style.d.ts +2 -1
  30. package/dist/font-style.d.ts.map +1 -1
  31. package/dist/font-style.js +31 -6
  32. package/dist/font-style.js.map +1 -1
  33. package/dist/geometry.d.ts +68 -3
  34. package/dist/geometry.d.ts.map +1 -1
  35. package/dist/geometry.js +155 -5
  36. package/dist/geometry.js.map +1 -1
  37. package/dist/gradient.d.ts +9 -2
  38. package/dist/gradient.d.ts.map +1 -1
  39. package/dist/gradient.js +29 -1
  40. package/dist/gradient.js.map +1 -1
  41. package/dist/graph.d.ts +4 -0
  42. package/dist/graph.d.ts.map +1 -1
  43. package/dist/graph.js +30 -4
  44. package/dist/graph.js.map +1 -1
  45. package/dist/group-bounds.d.ts.map +1 -1
  46. package/dist/group-bounds.js +4 -3
  47. package/dist/group-bounds.js.map +1 -1
  48. package/dist/guides.d.ts +11 -2
  49. package/dist/guides.d.ts.map +1 -1
  50. package/dist/guides.js +30 -1
  51. package/dist/guides.js.map +1 -1
  52. package/dist/hit-test.d.ts.map +1 -1
  53. package/dist/hit-test.js +57 -5
  54. package/dist/hit-test.js.map +1 -1
  55. package/dist/icons/fit.d.ts +17 -0
  56. package/dist/icons/fit.d.ts.map +1 -0
  57. package/dist/icons/fit.js +21 -0
  58. package/dist/icons/fit.js.map +1 -0
  59. package/dist/icons/glyph.d.ts.map +1 -1
  60. package/dist/icons/glyph.js +5 -4
  61. package/dist/icons/glyph.js.map +1 -1
  62. package/dist/icons/index.d.ts +2 -1
  63. package/dist/icons/index.js +2 -1
  64. package/dist/images.d.ts +14 -4
  65. package/dist/images.d.ts.map +1 -1
  66. package/dist/images.js +45 -5
  67. package/dist/images.js.map +1 -1
  68. package/dist/instances/assignments.js +39 -6
  69. package/dist/instances/assignments.js.map +1 -1
  70. package/dist/instances/index.d.ts.map +1 -1
  71. package/dist/instances/index.js +39 -2
  72. package/dist/instances/index.js.map +1 -1
  73. package/dist/instances/kept-overrides.js +2 -2
  74. package/dist/instances/kept-overrides.js.map +1 -1
  75. package/dist/instances/matching.js +68 -0
  76. package/dist/instances/matching.js.map +1 -0
  77. package/dist/instances/overrides.d.ts +4 -1
  78. package/dist/instances/overrides.d.ts.map +1 -1
  79. package/dist/instances/overrides.js +13 -1
  80. package/dist/instances/overrides.js.map +1 -1
  81. package/dist/instances/protection.js +67 -0
  82. package/dist/instances/protection.js.map +1 -0
  83. package/dist/instances/swap.js +7 -5
  84. package/dist/instances/swap.js.map +1 -1
  85. package/dist/instances/sync.js +10 -116
  86. package/dist/instances/sync.js.map +1 -1
  87. package/dist/layout/guides.d.ts +17 -1
  88. package/dist/layout/guides.d.ts.map +1 -1
  89. package/dist/layout/guides.js +31 -11
  90. package/dist/layout/guides.js.map +1 -1
  91. package/dist/layout/index.d.ts +4 -2
  92. package/dist/layout/index.js +4 -2
  93. package/dist/layout/limits.d.ts +40 -0
  94. package/dist/layout/limits.d.ts.map +1 -0
  95. package/dist/layout/limits.js +54 -0
  96. package/dist/layout/limits.js.map +1 -0
  97. package/dist/layout/sizing.d.ts.map +1 -1
  98. package/dist/layout/sizing.js +0 -1
  99. package/dist/layout/sizing.js.map +1 -1
  100. package/dist/layout/spacing.d.ts +10 -0
  101. package/dist/layout/spacing.d.ts.map +1 -0
  102. package/dist/layout/spacing.js +12 -0
  103. package/dist/layout/spacing.js.map +1 -0
  104. package/dist/masks.d.ts +28 -0
  105. package/dist/masks.d.ts.map +1 -0
  106. package/dist/masks.js +53 -0
  107. package/dist/masks.js.map +1 -0
  108. package/dist/matrix.d.ts +2 -1
  109. package/dist/matrix.d.ts.map +1 -1
  110. package/dist/matrix.js +14 -1
  111. package/dist/matrix.js.map +1 -1
  112. package/dist/node-defaults.d.ts +9 -1
  113. package/dist/node-defaults.d.ts.map +1 -1
  114. package/dist/node-defaults.js +16 -1
  115. package/dist/node-defaults.js.map +1 -1
  116. package/dist/outline/flatten.d.ts.map +1 -1
  117. package/dist/outline/flatten.js +24 -17
  118. package/dist/outline/flatten.js.map +1 -1
  119. package/dist/outline/hit.d.ts +2 -8
  120. package/dist/outline/hit.d.ts.map +1 -1
  121. package/dist/outline/hit.js +16 -25
  122. package/dist/outline/hit.js.map +1 -1
  123. package/dist/outline/index.d.ts +3 -3
  124. package/dist/outline/index.js +3 -3
  125. package/dist/outline/shapes.d.ts +3 -1
  126. package/dist/outline/shapes.d.ts.map +1 -1
  127. package/dist/outline/shapes.js +18 -39
  128. package/dist/outline/shapes.js.map +1 -1
  129. package/dist/paints/index.d.ts +3 -1
  130. package/dist/paints/index.js +3 -1
  131. package/dist/paints/pattern.d.ts +13 -0
  132. package/dist/paints/pattern.d.ts.map +1 -0
  133. package/dist/paints/pattern.js +47 -0
  134. package/dist/paints/pattern.js.map +1 -0
  135. package/dist/paints/shows.d.ts +11 -0
  136. package/dist/paints/shows.d.ts.map +1 -0
  137. package/dist/paints/shows.js +16 -0
  138. package/dist/paints/shows.js.map +1 -0
  139. package/dist/paths/arc.d.ts +32 -0
  140. package/dist/paths/arc.d.ts.map +1 -0
  141. package/dist/paths/arc.js +49 -0
  142. package/dist/paths/arc.js.map +1 -0
  143. package/dist/paths/index.d.ts +5 -0
  144. package/dist/paths/index.js +5 -0
  145. package/dist/paths/network.d.ts +43 -0
  146. package/dist/paths/network.d.ts.map +1 -0
  147. package/dist/paths/network.js +249 -0
  148. package/dist/paths/network.js.map +1 -0
  149. package/dist/paths/sink.d.ts +20 -0
  150. package/dist/paths/sink.d.ts.map +1 -0
  151. package/dist/paths/sink.js +32 -0
  152. package/dist/paths/sink.js.map +1 -0
  153. package/dist/paths/smooth-corners.d.ts +25 -0
  154. package/dist/paths/smooth-corners.d.ts.map +1 -0
  155. package/dist/paths/smooth-corners.js +196 -0
  156. package/dist/paths/smooth-corners.js.map +1 -0
  157. package/dist/plugin-data/fields.d.ts +4 -0
  158. package/dist/plugin-data/fields.d.ts.map +1 -1
  159. package/dist/plugin-data/fields.js +2 -0
  160. package/dist/plugin-data/fields.js.map +1 -1
  161. package/dist/polygon.d.ts +1 -3
  162. package/dist/polygon.d.ts.map +1 -1
  163. package/dist/polygon.js +1 -16
  164. package/dist/polygon.js.map +1 -1
  165. package/dist/resize.d.ts.map +1 -1
  166. package/dist/resize.js +5 -5
  167. package/dist/resize.js.map +1 -1
  168. package/dist/scaling/node.d.ts.map +1 -1
  169. package/dist/scaling/node.js +25 -3
  170. package/dist/scaling/node.js.map +1 -1
  171. package/dist/text/auto-resize.d.ts +15 -0
  172. package/dist/text/auto-resize.d.ts.map +1 -0
  173. package/dist/text/auto-resize.js +23 -0
  174. package/dist/text/auto-resize.js.map +1 -0
  175. package/dist/text/index.d.ts +4 -3
  176. package/dist/text/index.js +4 -3
  177. package/dist/text/lengths.d.ts +6 -1
  178. package/dist/text/lengths.d.ts.map +1 -1
  179. package/dist/text/lengths.js +10 -1
  180. package/dist/text/lengths.js.map +1 -1
  181. package/dist/text/overflow.d.ts +14 -5
  182. package/dist/text/overflow.d.ts.map +1 -1
  183. package/dist/text/overflow.js +24 -6
  184. package/dist/text/overflow.js.map +1 -1
  185. package/dist/text/path.js +10 -0
  186. package/dist/text/path.js.map +1 -0
  187. package/dist/text/picture.js +5 -5
  188. package/dist/text/picture.js.map +1 -1
  189. package/dist/transfer/dependencies.d.ts.map +1 -1
  190. package/dist/transfer/dependencies.js +3 -2
  191. package/dist/transfer/dependencies.js.map +1 -1
  192. package/dist/transfer/nodes.js +2 -1
  193. package/dist/transfer/nodes.js.map +1 -1
  194. package/dist/types.d.ts +21 -8
  195. package/dist/types.d.ts.map +1 -1
  196. package/dist/types.js.map +1 -1
  197. package/dist/variables/index.d.ts +4 -3
  198. package/dist/variables/index.d.ts.map +1 -1
  199. package/dist/variables/index.js +4 -3
  200. package/dist/variables/index.js.map +1 -1
  201. package/dist/variables/lookup.d.ts +20 -0
  202. package/dist/variables/lookup.d.ts.map +1 -0
  203. package/dist/variables/lookup.js +34 -0
  204. package/dist/variables/lookup.js.map +1 -0
  205. package/dist/variables/paints.d.ts +35 -4
  206. package/dist/variables/paints.d.ts.map +1 -1
  207. package/dist/variables/paints.js +67 -16
  208. package/dist/variables/paints.js.map +1 -1
  209. package/dist/variables/resolution.d.ts +3 -1
  210. package/dist/variables/resolution.d.ts.map +1 -1
  211. package/dist/variables/resolution.js +8 -3
  212. package/dist/variables/resolution.js.map +1 -1
  213. package/dist/variables/subtree.js +1 -1
  214. package/dist/variables/subtree.js.map +1 -1
  215. package/dist/vector-network.d.ts.map +1 -1
  216. package/dist/vector-network.js +12 -76
  217. package/dist/vector-network.js.map +1 -1
  218. package/package.json +25 -1
  219. package/src/arrays.ts +37 -0
  220. package/src/buffered-events.ts +2 -1
  221. package/src/clipping.ts +11 -8
  222. package/src/components/properties.ts +1 -13
  223. package/src/corners.ts +93 -0
  224. package/src/css/grid.ts +21 -7
  225. package/src/css/index.ts +1 -1
  226. package/src/font-style.ts +38 -4
  227. package/src/geometry.ts +219 -6
  228. package/src/gradient.ts +23 -1
  229. package/src/graph.ts +22 -4
  230. package/src/group-bounds.ts +7 -3
  231. package/src/guides.ts +26 -1
  232. package/src/hit-test.ts +68 -10
  233. package/src/icons/fit.ts +24 -0
  234. package/src/icons/glyph.ts +5 -4
  235. package/src/icons/index.ts +1 -0
  236. package/src/images.ts +67 -7
  237. package/src/instances/assignments.ts +65 -7
  238. package/src/instances/index.ts +53 -4
  239. package/src/instances/kept-overrides.ts +2 -5
  240. package/src/instances/matching.ts +101 -0
  241. package/src/instances/overrides.ts +18 -0
  242. package/src/instances/protection.ts +103 -0
  243. package/src/instances/swap.ts +11 -9
  244. package/src/instances/sync.ts +11 -184
  245. package/src/layout/guides.ts +42 -9
  246. package/src/layout/index.ts +2 -0
  247. package/src/layout/limits.ts +64 -0
  248. package/src/layout/sizing.ts +0 -2
  249. package/src/layout/spacing.ts +11 -0
  250. package/src/masks.ts +51 -0
  251. package/src/matrix.ts +15 -2
  252. package/src/node-defaults.ts +23 -3
  253. package/src/outline/flatten.ts +30 -18
  254. package/src/outline/hit.ts +16 -33
  255. package/src/outline/index.ts +2 -2
  256. package/src/outline/shapes.ts +19 -36
  257. package/src/paints/index.ts +2 -0
  258. package/src/paints/pattern.ts +45 -0
  259. package/src/paints/shows.ts +13 -0
  260. package/src/paths/arc.ts +59 -0
  261. package/src/paths/index.ts +4 -0
  262. package/src/paths/network.ts +334 -0
  263. package/src/paths/sink.ts +50 -0
  264. package/src/paths/smooth-corners.ts +356 -0
  265. package/src/plugin-data/fields.ts +2 -0
  266. package/src/polygon.ts +0 -17
  267. package/src/resize.ts +6 -7
  268. package/src/scaling/node.ts +29 -3
  269. package/src/text/auto-resize.ts +25 -0
  270. package/src/text/index.ts +1 -0
  271. package/src/text/lengths.ts +11 -0
  272. package/src/text/overflow.ts +32 -6
  273. package/src/text/path.ts +13 -0
  274. package/src/text/picture.ts +5 -5
  275. package/src/transfer/dependencies.ts +3 -2
  276. package/src/transfer/nodes.ts +2 -1
  277. package/src/types.ts +25 -8
  278. package/src/variables/index.ts +1 -0
  279. package/src/variables/lookup.ts +31 -0
  280. package/src/variables/paints.ts +101 -20
  281. package/src/variables/resolution.ts +14 -2
  282. package/src/variables/subtree.ts +1 -1
  283. package/src/vector-network.ts +17 -138
@@ -1 +1 @@
1
- {"version":3,"file":"resize.js","names":[],"sources":["../src/resize.ts"],"sourcesContent":["import { CONSTRAINT_PARENT_TYPES } from './constraints'\nimport { getNodeLocalMatrix } from './coordinate'\nimport {\n cloneVectorNetwork,\n copyDerivedGlyphs,\n copyGeometryPaths,\n copyStroke,\n copyStrokes,\n scaleGeometryPaths\n} from './copy'\nimport { groupFitChanges } from './group-bounds'\nimport { enforcedAspectRatio } from './layout/aspect-ratio'\nimport Matrix, { type Mat3 } from './matrix'\nimport { FITTED_CONTAINER_TYPES } from './node-defaults'\nimport type { Rect } from './primitives'\nimport type { ConstraintType, DerivedTextGlyph, SceneNode, Stroke, VectorNetwork } from './types'\n\n/**\n * Drag-start state a live resize re-scales from. Path text needs more than the\n * layout rect: its OUTSIDE stroke silhouettes and glyph outlines are baked\n * geometry that must scale with the node, and textPathBox is the layout box the\n * glyphs were reflowed against.\n */\nexport type ResizeSnapshot = Pick<\n SceneNode,\n | 'type'\n | 'x'\n | 'y'\n | 'width'\n | 'height'\n | 'flipX'\n | 'flipY'\n | 'vectorNetwork'\n | 'fillGeometry'\n | 'strokeGeometry'\n | 'derivedTextGlyphs'\n | 'strokes'\n | 'textPathData'\n | 'textPathBox'\n>\n\ninterface ResizeGraph {\n readonly rootId: string\n getNode(id: string): SceneNode | undefined\n}\n\n/**\n * Containers whose resize moves their children: the constraint parents, and groups and booleans,\n * which scale theirs.\n */\nconst CONSTRAINT_CONTAINER_TYPES = new Set<SceneNode['type']>([\n ...CONSTRAINT_PARENT_TYPES,\n ...FITTED_CONTAINER_TYPES\n])\n\ntype AxisPlacement = { position: number; size: number; flipped?: boolean }\n\n/** A child's box after its parent resizes, and the axes on which it turned over. */\nexport type ConstrainedRect = Rect & { flipsX?: boolean; flipsY?: boolean }\n\n/**\n * Where a constraint places a child on one axis when its parent goes from `parentBefore` to\n * `parentAfter`, as Figma does (live-measured, #1060, #1816): Right and Left & right move or grow\n * it by the change in the parent's size rounded to whole pixels, Center by the change in its\n * rounded half, and Scale by the exact ratio. The child's own box is never rounded, so a resize\n * to the same size changes nothing. Left & right that would leave no size keeps the axis as it\n * was; past zero, the child turns over and its box runs back from the edge it was pinned to, as\n * the layer is mirrored in Figma.\n */\nfunction constrainedAxis(\n position: number,\n size: number,\n parentBefore: number,\n parentAfter: number,\n constraint: ConstraintType\n): AxisPlacement {\n const delta = Math.round(parentAfter) - Math.round(parentBefore)\n if (constraint === 'MAX') return { position: position + delta, size }\n if (constraint === 'CENTER') {\n return { position: position + Math.round(parentAfter / 2) - Math.round(parentBefore / 2), size }\n }\n if (constraint === 'STRETCH') {\n const stretched = size + delta\n if (stretched === 0) return { position, size }\n if (stretched > 0) return { position, size: stretched }\n return { position: position + stretched, size: -stretched, flipped: true }\n }\n if (constraint === 'SCALE' && parentBefore > 0) {\n const scale = parentAfter / parentBefore\n return { position: position * scale, size: size * scale }\n }\n return { position, size }\n}\n\nconst FLEXIBLE_CONSTRAINTS: ReadonlySet<ConstraintType> = new Set(['STRETCH', 'SCALE'])\n\n/** The axis at `size`, keeping the edge or centre its constraint pins where it was placed. */\nfunction resizedInPlace(\n placed: AxisPlacement,\n size: number,\n constraint: ConstraintType\n): AxisPlacement {\n if (constraint === 'MAX') return { position: placed.position + placed.size - size, size }\n if (constraint === 'CENTER') return { position: placed.position + (placed.size - size) / 2, size }\n return { position: placed.position, size }\n}\n\n/** Keep a placed box's constrained edges or center when its content determines its size. */\nexport function resizedChildRect(\n placed: Rect,\n size: Pick<Rect, 'width' | 'height'>,\n horizontal: ConstraintType,\n vertical: ConstraintType\n): Rect {\n const x = resizedInPlace({ position: placed.x, size: placed.width }, size.width, horizontal)\n const y = resizedInPlace({ position: placed.y, size: placed.height }, size.height, vertical)\n return { x: x.position, y: y.position, width: x.size, height: y.size }\n}\n\n/**\n * A locked aspect ratio holds when exactly one axis follows the parent, as in Figma: that axis\n * sizes the other. With both axes following the parent, or neither, the ratio gives way.\n */\nfunction keepLockedRatio(\n x: AxisPlacement,\n y: AxisPlacement,\n horizontal: ConstraintType,\n vertical: ConstraintType,\n aspectRatio: number | null\n): { x: AxisPlacement; y: AxisPlacement } {\n const flexibleX = FLEXIBLE_CONSTRAINTS.has(horizontal)\n if (aspectRatio === null || flexibleX === FLEXIBLE_CONSTRAINTS.has(vertical)) return { x, y }\n return flexibleX\n ? { x, y: resizedInPlace(y, x.size / aspectRatio, vertical) }\n : { x: resizedInPlace(x, y.size * aspectRatio, horizontal), y }\n}\n\n/**\n * A child's box after its parent resizes, by a handle, `resize()`, layout, or an instance taking\n * another size than its component, keeping a locked aspect ratio as Figma does.\n */\nexport function constrainedChildRect(\n child: Rect,\n parentBefore: Pick<Rect, 'width' | 'height'>,\n parentAfter: Pick<Rect, 'width' | 'height'>,\n horizontal: ConstraintType,\n vertical: ConstraintType,\n aspectRatio: number | null = null\n): ConstrainedRect {\n const { x, y } = keepLockedRatio(\n constrainedAxis(child.x, child.width, parentBefore.width, parentAfter.width, horizontal),\n constrainedAxis(child.y, child.height, parentBefore.height, parentAfter.height, vertical),\n horizontal,\n vertical,\n aspectRatio\n )\n const rect: ConstrainedRect = { x: x.position, y: y.position, width: x.size, height: y.size }\n if (x.flipped) rect.flipsX = true\n if (y.flipped) rect.flipsY = true\n return rect\n}\n\nexport function scaledChildRect(\n child: Rect,\n parentBefore: Pick<Rect, 'width' | 'height'>,\n parentAfter: Pick<Rect, 'width' | 'height'>\n): Rect {\n return constrainedChildRect(child, parentBefore, parentAfter, 'SCALE', 'SCALE')\n}\n\n/** How much a side grows; a flat side, as a straight line's, has nothing to scale along it. */\nfunction sideScale(original: number, size: number): number {\n return original > 0 ? size / original : 1\n}\n\nexport function scaleVectorNetworkForResize(\n vectorNetwork: VectorNetwork | null,\n originalWidth: number,\n originalHeight: number,\n width: number,\n height: number\n): VectorNetwork | null {\n if (!vectorNetwork || (originalWidth <= 0 && originalHeight <= 0)) return null\n\n const scaleX = sideScale(originalWidth, width)\n const scaleY = sideScale(originalHeight, height)\n if (scaleX === 1 && scaleY === 1) return null\n\n return {\n vertices: vectorNetwork.vertices.map((vertex) => ({\n ...vertex,\n x: vertex.x * scaleX,\n y: vertex.y * scaleY\n })),\n segments: vectorNetwork.segments.map((segment) => ({\n ...segment,\n tangentStart: {\n x: segment.tangentStart.x * scaleX,\n y: segment.tangentStart.y * scaleY\n },\n tangentEnd: {\n x: segment.tangentEnd.x * scaleX,\n y: segment.tangentEnd.y * scaleY\n }\n })),\n regions: vectorNetwork.regions\n }\n}\n\n/** Snapshot one node's resize-relevant state (rect + geometry that must scale with it). */\nexport function createResizeSnapshot(node: SceneNode): ResizeSnapshot {\n return {\n type: node.type,\n x: node.x,\n y: node.y,\n width: node.width,\n height: node.height,\n flipX: node.flipX,\n flipY: node.flipY,\n vectorNetwork: node.vectorNetwork ? cloneVectorNetwork(node.vectorNetwork) : null,\n fillGeometry: copyGeometryPaths(node.fillGeometry),\n strokeGeometry: copyGeometryPaths(node.strokeGeometry),\n derivedTextGlyphs: copyDerivedGlyphs(node.derivedTextGlyphs),\n strokes: copyStrokes(node.strokes),\n textPathData: node.textPathData ? structuredClone(node.textPathData) : null,\n textPathBox: node.textPathBox ? { ...node.textPathBox } : null\n }\n}\n\nfunction scaleDerivedGlyphs(\n glyphs: DerivedTextGlyph[] | null,\n sx: number,\n sy: number\n): DerivedTextGlyph[] | null {\n if (!glyphs?.length) return glyphs\n return glyphs.map((g) => ({\n ...g,\n x: g.x * sx,\n y: g.y * sy,\n scaleX: (g.scaleX ?? 1) * sx,\n scaleY: (g.scaleY ?? 1) * sy,\n commandsBlob: new Uint8Array(g.commandsBlob)\n }))\n}\n\nfunction hasPath(orig: Pick<ResizeSnapshot, 'vectorNetwork'>): boolean {\n return (orig.vectorNetwork?.segments.length ?? 0) > 0\n}\n\nfunction scaleStrokes(strokes: Stroke[], sx: number, sy: number): Stroke[] {\n if (strokes.length === 0) return strokes\n // Weight is a scalar; average scale is the usual 2D → 1D compromise.\n const weightScale = (Math.abs(sx) + Math.abs(sy)) / 2\n return strokes.map((s) => ({ ...copyStroke(s), weight: s.weight * weightScale }))\n}\n\n/**\n * All geometry that must track a width/height change. Historically only\n * vectorNetwork + fillGeometry were updated — path-text strokeGeometry and\n * glyphs stayed at the pre-resize size, so shrinking a sticker made the white\n * OUTSIDE outlines look massively thick (DomeSticker resize bug).\n */\nexport function scaledGeometryChanges(\n orig: Pick<\n ResizeSnapshot,\n | 'type'\n | 'vectorNetwork'\n | 'fillGeometry'\n | 'strokeGeometry'\n | 'derivedTextGlyphs'\n | 'strokes'\n | 'textPathData'\n | 'textPathBox'\n >,\n origWidth: number,\n origHeight: number,\n width: number,\n height: number\n): Partial<SceneNode> {\n if (origWidth <= 0 && origHeight <= 0) return {}\n // A straight line's other side still scales.\n const sx = sideScale(origWidth, width)\n const sy = sideScale(origHeight, height)\n if (sx === 1 && sy === 1) return {}\n\n const changes: Partial<SceneNode> = {}\n const resizedVN = scaleVectorNetworkForResize(\n orig.vectorNetwork,\n origWidth,\n origHeight,\n width,\n height\n )\n if (resizedVN) changes.vectorNetwork = resizedVN\n\n if (orig.fillGeometry.length > 0) {\n changes.fillGeometry = scaleGeometryPaths(orig.fillGeometry, sx, sy)\n }\n // A stroke keeps its weight through a resize, as in Figma, so a saved stroke outline goes where\n // the stroke can be drawn again at its weight: from a path, or from a shape's own outline.\n // Text and a vector with only its outline keep scaling the outline, which is all they have.\n const outlineOnly = orig.type === 'TEXT' || (orig.type === 'VECTOR' && !hasPath(orig))\n if (orig.strokeGeometry.length > 0) {\n changes.strokeGeometry = outlineOnly ? scaleGeometryPaths(orig.strokeGeometry, sx, sy) : []\n }\n // Path text scales with its path, including baked path text that kept only rotated glyphs;\n // other text reflows in the new box, so its glyphs are dropped.\n const glyphs = orig.derivedTextGlyphs ?? []\n const pathText =\n !!orig.textPathData || !!orig.textPathBox || glyphs.some((glyph) => (glyph.rotation ?? 0) !== 0)\n if (glyphs.length > 0 && pathText) {\n changes.derivedTextGlyphs = scaleDerivedGlyphs(glyphs, sx, sy)\n // Keep the layout/selection box in sync with the scaled glyphs. reflow\n // overrides this when it applies; this covers the fallback where reflow\n // returns null (no path data) so the box doesn't carry a stale size.\n if (orig.textPathBox) {\n changes.textPathBox = {\n x: orig.textPathBox.x * sx,\n y: orig.textPathBox.y * sy,\n width: orig.textPathBox.width * sx,\n height: orig.textPathBox.height * sy\n }\n }\n }\n // Glyphs scaled as a picture take their strokes along; any other stroke keeps its weight, as\n // Figma reports it, even where only a scaled outline can draw it.\n if (orig.strokes.length > 0 && glyphs.length > 0 && pathText) {\n changes.strokes = scaleStrokes(orig.strokes, sx, sy)\n }\n return changes\n}\n\n/** Copies of the geometry a resize may change, as the snapshot held it before the resize. */\nfunction snapshotGeometry(orig: ResizeSnapshot): Partial<SceneNode> {\n return {\n vectorNetwork: orig.vectorNetwork ? cloneVectorNetwork(orig.vectorNetwork) : null,\n fillGeometry: copyGeometryPaths(orig.fillGeometry),\n strokeGeometry: copyGeometryPaths(orig.strokeGeometry),\n derivedTextGlyphs: copyDerivedGlyphs(orig.derivedTextGlyphs),\n strokes: copyStrokes(orig.strokes),\n textPathBox: orig.textPathBox ? { ...orig.textPathBox } : null\n }\n}\n\n/** Whether a box of `size` scales the snapshot's geometry, a flat side left out. */\nfunction scalesGeometry(orig: ResizeSnapshot, size: Pick<Rect, 'width' | 'height'>): boolean {\n return sideScale(orig.width, size.width) !== 1 || sideScale(orig.height, size.height) !== 1\n}\n\n/**\n * A child's geometry for its constrained `box`, scaled from the snapshot. At a box that scales\n * nothing, after an earlier frame of the same drag scaled it, the child takes its snapshot\n * geometry again, as nothing else would undo that scaling.\n */\nfunction constrainedGeometryChanges(\n orig: ResizeSnapshot,\n current: Pick<SceneNode, 'width' | 'height'>,\n box: Pick<Rect, 'width' | 'height'>\n): Partial<SceneNode> {\n if (scalesGeometry(orig, box))\n return scaledGeometryChanges(orig, orig.width, orig.height, box.width, box.height)\n return scalesGeometry(orig, current) ? snapshotGeometry(orig) : {}\n}\n\nexport function collectResizeDescendants(\n graph: ResizeGraph,\n rootId: string\n): Map<string, ResizeSnapshot> | null {\n const root = graph.getNode(rootId)\n if (!root || !CONSTRAINT_CONTAINER_TYPES.has(root.type)) return null\n const snapshots = new Map<string, ResizeSnapshot>()\n\n const collect = (parentId: string) => {\n const parent = graph.getNode(parentId)\n if (!parent) return\n for (const childId of parent.childIds) {\n const child = graph.getNode(childId)\n if (!child) continue\n snapshots.set(childId, createResizeSnapshot(child))\n collect(childId)\n }\n }\n\n collect(rootId)\n return snapshots.size > 0 ? snapshots : null\n}\n\n/**\n * The flips a child takes when its constraints place it from `from`, written only where they\n * differ from the ones it has now, so a drag that crosses back undoes its own turn.\n */\nexport function flipChanges(\n from: Pick<SceneNode, 'flipX' | 'flipY'>,\n current: Pick<SceneNode, 'flipX' | 'flipY'>,\n flipsX = false,\n flipsY = false\n): Partial<Pick<SceneNode, 'flipX' | 'flipY'>> {\n const changes: Partial<Pick<SceneNode, 'flipX' | 'flipY'>> = {}\n const flipX = from.flipX !== flipsX\n const flipY = from.flipY !== flipsY\n if (flipX !== current.flipX) changes.flipX = flipX\n if (flipY !== current.flipY) changes.flipY = flipY\n return changes\n}\n\ntype Size = Pick<Rect, 'width' | 'height'>\n\n/** One constrained resize: the graph, where each layer was when it began, and what it changes. */\ninterface ResizePlan {\n graph: ResizeGraph\n originals: ReadonlyMap<string, ResizeSnapshot>\n changes: Map<string, Partial<SceneNode>>\n}\n\n/** The layer as the resize found it, or as the resize leaves it with its changes so far. */\nfunction startOf(plan: ResizePlan, id: string): SceneNode | undefined {\n const node = plan.graph.getNode(id)\n const original = plan.originals.get(id)\n return node && original ? { ...node, ...original } : node\n}\n\nfunction plannedOf(plan: ResizePlan, id: string): SceneNode | undefined {\n const node = startOf(plan, id)\n const changes = plan.changes.get(id)\n return node && changes ? { ...node, ...changes } : node\n}\n\nfunction mergeChanges(plan: ResizePlan, id: string, changes: Partial<SceneNode>) {\n plan.changes.set(id, { ...plan.changes.get(id), ...changes })\n}\n\n/** Writes where a layer's constraints put it, then places its own children. */\nfunction placeConstrained(\n plan: ResizePlan,\n child: SceneNode,\n original: ResizeSnapshot,\n rect: ConstrainedRect,\n toParent: Mat3 | null\n) {\n const { flipsX, flipsY, ...box } = rect\n const position = toParent ? Matrix.mapPoint(toParent, box) : box\n plan.changes.set(child.id, {\n ...box,\n ...position,\n ...flipChanges(original, child, flipsX, flipsY),\n ...constrainedGeometryChanges(original, child, box)\n })\n // The final pass sees layout containers after Yoga has resolved HUG/FILL sizing.\n placeChildren(plan, child.id, original, child.layoutMode === 'NONE' ? box : child)\n}\n\n/**\n * Places the layers in a group or boolean whose frame resized. The group owns no constraints: each\n * layer in it keeps its place in the frame by its own, through nested groups, and the groups then\n * fit around them, as in Figma (live, #1835). A layer is placed in the frame's space and written\n * back in its group's.\n */\nfunction placeGroupedLayers(\n plan: ResizePlan,\n group: SceneNode,\n toFrame: Mat3,\n frameBefore: Size,\n frameAfter: Size\n) {\n for (const childId of group.childIds) {\n const child = plan.graph.getNode(childId)\n const original = plan.originals.get(childId)\n const start = startOf(plan, childId)\n if (!child || !original || !start) continue\n if (FITTED_CONTAINER_TYPES.has(child.type)) {\n const inner = Matrix.multiply(toFrame, getNodeLocalMatrix(start))\n placeGroupedLayers(plan, start, inner, frameBefore, frameAfter)\n continue\n }\n const inFrame = Matrix.mapPoint(toFrame, original)\n const rect = constrainedChildRect(\n { ...inFrame, width: original.width, height: original.height },\n frameBefore,\n frameAfter,\n child.horizontalConstraint,\n child.verticalConstraint,\n enforcedAspectRatio(child)\n )\n placeConstrained(plan, child, original, rect, Matrix.invert(toFrame))\n }\n fitPlannedGroup(plan, group.id)\n}\n\nconst PLACEMENT_KEYS = ['x', 'y', 'width', 'height'] as const\n\n/**\n * Fits a group to its layers where the resize put them, when any of them moved: a boolean's box\n * is its result's, which only the renderer measures, so one whose operands stay keeps its box. A\n * drag places from the start each time, so the group's box is always written.\n */\nfunction fitPlannedGroup(plan: ResizePlan, groupId: string) {\n const group = plannedOf(plan, groupId)\n if (!group) return\n const { x, y, width, height } = group\n mergeChanges(plan, groupId, { x, y, width, height })\n const moved = group.childIds.some((id) => {\n const start = startOf(plan, id)\n const planned = plannedOf(plan, id)\n return start && planned && PLACEMENT_KEYS.some((key) => start[key] !== planned[key])\n })\n if (!moved) return\n const reader = { rootId: plan.graph.rootId, getNode: (id: string) => plannedOf(plan, id) }\n const children = group.childIds.flatMap((id) => reader.getNode(id) ?? [])\n const fit = groupFitChanges(reader, group, children)\n for (const [id, changes] of fit ?? []) mergeChanges(plan, id, changes)\n}\n\n/**\n * Places the children of a layer that went from `parentBefore` to `parentAfter`: a frame's by their\n * constraints, the layers in its groups and booleans by theirs, a group's or boolean's own scaled.\n */\nfunction placeChildren(plan: ResizePlan, parentId: string, parentBefore: Size, parentAfter: Size) {\n const parent = plan.graph.getNode(parentId)\n if (!parent) return\n const scalesChildren = FITTED_CONTAINER_TYPES.has(parent.type)\n for (const childId of parent.childIds) {\n const original = plan.originals.get(childId)\n const child = plan.graph.getNode(childId)\n if (!original || !child) continue\n const isInFlow = parent.layoutMode !== 'NONE' && child.layoutPositioning !== 'ABSOLUTE'\n if (isInFlow) {\n placeChildren(plan, childId, original, child)\n continue\n }\n if (!scalesChildren && FITTED_CONTAINER_TYPES.has(child.type)) {\n const start = { ...child, ...original }\n placeGroupedLayers(plan, start, getNodeLocalMatrix(start), parentBefore, parentAfter)\n continue\n }\n const rect: ConstrainedRect = scalesChildren\n ? scaledChildRect(original, parentBefore, parentAfter)\n : constrainedChildRect(\n original,\n parentBefore,\n parentAfter,\n child.horizontalConstraint,\n child.verticalConstraint,\n enforcedAspectRatio(child)\n )\n placeConstrained(plan, child, original, rect, null)\n }\n}\n\n/**\n * Where the descendants of a layer go when it resizes from `rootBefore` to `rootAfter`, from the\n * places `originals` recorded.\n */\nexport function computeConstrainedResizeChanges(\n graph: ResizeGraph,\n rootId: string,\n rootBefore: Size,\n rootAfter: Size,\n originals: ReadonlyMap<string, ResizeSnapshot>\n): Map<string, Partial<SceneNode>> {\n const plan: ResizePlan = { graph, originals, changes: new Map() }\n placeChildren(plan, rootId, rootBefore, rootAfter)\n return plan.changes\n}\n"],"mappings":";;;;;;;;;;;;AAkDA,MAAM,6CAA6B,IAAI,IAAuB,CAC5D,GAAG,yBACH,GAAG,sBACL,CAAC;;;;;;;;;;AAgBD,SAAS,gBACP,UACA,MACA,cACA,aACA,YACe;CACf,MAAM,QAAQ,KAAK,MAAM,WAAW,IAAI,KAAK,MAAM,YAAY;CAC/D,IAAI,eAAe,OAAO,OAAO;EAAE,UAAU,WAAW;EAAO;CAAK;CACpE,IAAI,eAAe,UACjB,OAAO;EAAE,UAAU,WAAW,KAAK,MAAM,cAAc,CAAC,IAAI,KAAK,MAAM,eAAe,CAAC;EAAG;CAAK;CAEjG,IAAI,eAAe,WAAW;EAC5B,MAAM,YAAY,OAAO;EACzB,IAAI,cAAc,GAAG,OAAO;GAAE;GAAU;EAAK;EAC7C,IAAI,YAAY,GAAG,OAAO;GAAE;GAAU,MAAM;EAAU;EACtD,OAAO;GAAE,UAAU,WAAW;GAAW,MAAM,CAAC;GAAW,SAAS;EAAK;CAC3E;CACA,IAAI,eAAe,WAAW,eAAe,GAAG;EAC9C,MAAM,QAAQ,cAAc;EAC5B,OAAO;GAAE,UAAU,WAAW;GAAO,MAAM,OAAO;EAAM;CAC1D;CACA,OAAO;EAAE;EAAU;CAAK;AAC1B;AAEA,MAAM,uCAAoD,IAAI,IAAI,CAAC,WAAW,OAAO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O,UAVA,iBAC1B,gBAAgB,UAAU,cAAc,WAAW,IACnD,qBACE,UACA,cACA,aACA,MAAM,sBACN,MAAM,oBACN,oBAAoB,KAAK,CAC3B,GAC0C,IAAI;CACpD;AACF;;;;;AAMA,SAAgB,gCACd,OACA,QACA,YACA,WACA,WACiC;CACjC,MAAM,OAAmB;EAAE;EAAO;EAAW,yBAAS,IAAI,IAAI;CAAE;CAChE,cAAc,MAAM,QAAQ,YAAY,SAAS;CACjD,OAAO,KAAK;AACd"}
1
+ {"version":3,"file":"resize.js","names":[],"sources":["../src/resize.ts"],"sourcesContent":["import { CONSTRAINT_PARENT_TYPES } from './constraints'\nimport { getNodeLocalMatrix } from './coordinate'\nimport {\n cloneVectorNetwork,\n copyDerivedGlyphs,\n copyGeometryPaths,\n copyStroke,\n copyStrokes,\n scaleGeometryPaths\n} from './copy'\nimport { groupFitChanges } from './group-bounds'\nimport { enforcedAspectRatio } from './layout/aspect-ratio'\nimport Matrix, { type Mat3 } from './matrix'\nimport { FITTED_CONTAINER_TYPES } from './node-defaults'\nimport type { Rect } from './primitives'\nimport { followsPath } from './text/path'\nimport type { ConstraintType, DerivedTextGlyph, SceneNode, Stroke, VectorNetwork } from './types'\n\n/**\n * Drag-start state a live resize re-scales from. Path text needs more than the\n * layout rect: its OUTSIDE stroke silhouettes and glyph outlines are baked\n * geometry that must scale with the node, and textPathBox is the layout box the\n * glyphs were reflowed against.\n */\nexport type ResizeSnapshot = Pick<\n SceneNode,\n | 'type'\n | 'x'\n | 'y'\n | 'width'\n | 'height'\n | 'flipX'\n | 'flipY'\n | 'vectorNetwork'\n | 'fillGeometry'\n | 'strokeGeometry'\n | 'derivedTextGlyphs'\n | 'strokes'\n | 'textPathData'\n | 'textPathBox'\n>\n\ninterface ResizeGraph {\n readonly rootId: string\n getNode(id: string): SceneNode | undefined\n}\n\n/**\n * Containers whose resize moves their children: the constraint parents, and groups and booleans,\n * which scale theirs.\n */\nconst CONSTRAINT_CONTAINER_TYPES = new Set<SceneNode['type']>([\n ...CONSTRAINT_PARENT_TYPES,\n ...FITTED_CONTAINER_TYPES\n])\n\ntype AxisPlacement = { position: number; size: number; flipped?: boolean }\n\n/** A child's box after its parent resizes, and the axes on which it turned over. */\nexport type ConstrainedRect = Rect & { flipsX?: boolean; flipsY?: boolean }\n\n/**\n * Where a constraint places a child on one axis when its parent goes from `parentBefore` to\n * `parentAfter`, as Figma does (live-measured, #1060, #1816): Right and Left & right move or grow\n * it by the change in the parent's size rounded to whole pixels, Center by the change in its\n * rounded half, and Scale by the exact ratio. The child's own box is never rounded, so a resize\n * to the same size changes nothing. Left & right that would leave no size keeps the axis as it\n * was; past zero, the child turns over and its box runs back from the edge it was pinned to, as\n * the layer is mirrored in Figma.\n */\nfunction constrainedAxis(\n position: number,\n size: number,\n parentBefore: number,\n parentAfter: number,\n constraint: ConstraintType\n): AxisPlacement {\n const delta = Math.round(parentAfter) - Math.round(parentBefore)\n if (constraint === 'MAX') return { position: position + delta, size }\n if (constraint === 'CENTER') {\n return { position: position + Math.round(parentAfter / 2) - Math.round(parentBefore / 2), size }\n }\n if (constraint === 'STRETCH') {\n const stretched = size + delta\n if (stretched === 0) return { position, size }\n if (stretched > 0) return { position, size: stretched }\n return { position: position + stretched, size: -stretched, flipped: true }\n }\n if (constraint === 'SCALE' && parentBefore > 0) {\n const scale = parentAfter / parentBefore\n return { position: position * scale, size: size * scale }\n }\n return { position, size }\n}\n\nconst FLEXIBLE_CONSTRAINTS: ReadonlySet<ConstraintType> = new Set(['STRETCH', 'SCALE'])\n\n/** The axis at `size`, keeping the edge or centre its constraint pins where it was placed. */\nfunction resizedInPlace(\n placed: AxisPlacement,\n size: number,\n constraint: ConstraintType\n): AxisPlacement {\n if (constraint === 'MAX') return { position: placed.position + placed.size - size, size }\n if (constraint === 'CENTER') return { position: placed.position + (placed.size - size) / 2, size }\n return { position: placed.position, size }\n}\n\n/** Keep a placed box's constrained edges or center when its content determines its size. */\nexport function resizedChildRect(\n placed: Rect,\n size: Pick<Rect, 'width' | 'height'>,\n horizontal: ConstraintType,\n vertical: ConstraintType\n): Rect {\n const x = resizedInPlace({ position: placed.x, size: placed.width }, size.width, horizontal)\n const y = resizedInPlace({ position: placed.y, size: placed.height }, size.height, vertical)\n return { x: x.position, y: y.position, width: x.size, height: y.size }\n}\n\n/**\n * A locked aspect ratio holds when exactly one axis follows the parent, as in Figma: that axis\n * sizes the other. With both axes following the parent, or neither, the ratio gives way.\n */\nfunction keepLockedRatio(\n x: AxisPlacement,\n y: AxisPlacement,\n horizontal: ConstraintType,\n vertical: ConstraintType,\n aspectRatio: number | null\n): { x: AxisPlacement; y: AxisPlacement } {\n const flexibleX = FLEXIBLE_CONSTRAINTS.has(horizontal)\n if (aspectRatio === null || flexibleX === FLEXIBLE_CONSTRAINTS.has(vertical)) return { x, y }\n return flexibleX\n ? { x, y: resizedInPlace(y, x.size / aspectRatio, vertical) }\n : { x: resizedInPlace(x, y.size * aspectRatio, horizontal), y }\n}\n\n/**\n * A child's box after its parent resizes, by a handle, `resize()`, layout, or an instance taking\n * another size than its component, keeping a locked aspect ratio as Figma does.\n */\nexport function constrainedChildRect(\n child: Rect,\n parentBefore: Pick<Rect, 'width' | 'height'>,\n parentAfter: Pick<Rect, 'width' | 'height'>,\n horizontal: ConstraintType,\n vertical: ConstraintType,\n aspectRatio: number | null = null\n): ConstrainedRect {\n const { x, y } = keepLockedRatio(\n constrainedAxis(child.x, child.width, parentBefore.width, parentAfter.width, horizontal),\n constrainedAxis(child.y, child.height, parentBefore.height, parentAfter.height, vertical),\n horizontal,\n vertical,\n aspectRatio\n )\n const rect: ConstrainedRect = { x: x.position, y: y.position, width: x.size, height: y.size }\n if (x.flipped) rect.flipsX = true\n if (y.flipped) rect.flipsY = true\n return rect\n}\n\nexport function scaledChildRect(\n child: Rect,\n parentBefore: Pick<Rect, 'width' | 'height'>,\n parentAfter: Pick<Rect, 'width' | 'height'>\n): Rect {\n return constrainedChildRect(child, parentBefore, parentAfter, 'SCALE', 'SCALE')\n}\n\n/** How much a side grows; a flat side, as a straight line's, has nothing to scale along it. */\nfunction sideScale(original: number, size: number): number {\n return original > 0 ? size / original : 1\n}\n\nexport function scaleVectorNetworkForResize(\n vectorNetwork: VectorNetwork | null,\n originalWidth: number,\n originalHeight: number,\n width: number,\n height: number\n): VectorNetwork | null {\n if (!vectorNetwork || (originalWidth <= 0 && originalHeight <= 0)) return null\n\n const scaleX = sideScale(originalWidth, width)\n const scaleY = sideScale(originalHeight, height)\n if (scaleX === 1 && scaleY === 1) return null\n\n return {\n vertices: vectorNetwork.vertices.map((vertex) => ({\n ...vertex,\n x: vertex.x * scaleX,\n y: vertex.y * scaleY\n })),\n segments: vectorNetwork.segments.map((segment) => ({\n ...segment,\n tangentStart: {\n x: segment.tangentStart.x * scaleX,\n y: segment.tangentStart.y * scaleY\n },\n tangentEnd: {\n x: segment.tangentEnd.x * scaleX,\n y: segment.tangentEnd.y * scaleY\n }\n })),\n regions: vectorNetwork.regions\n }\n}\n\n/** Snapshot one node's resize-relevant state (rect + geometry that must scale with it). */\nexport function createResizeSnapshot(node: SceneNode): ResizeSnapshot {\n return {\n type: node.type,\n x: node.x,\n y: node.y,\n width: node.width,\n height: node.height,\n flipX: node.flipX,\n flipY: node.flipY,\n vectorNetwork: node.vectorNetwork ? cloneVectorNetwork(node.vectorNetwork) : null,\n fillGeometry: copyGeometryPaths(node.fillGeometry),\n strokeGeometry: copyGeometryPaths(node.strokeGeometry),\n derivedTextGlyphs: copyDerivedGlyphs(node.derivedTextGlyphs),\n strokes: copyStrokes(node.strokes),\n textPathData: node.textPathData ? structuredClone(node.textPathData) : null,\n textPathBox: node.textPathBox ? { ...node.textPathBox } : null\n }\n}\n\nfunction scaleDerivedGlyphs(\n glyphs: DerivedTextGlyph[] | null,\n sx: number,\n sy: number\n): DerivedTextGlyph[] | null {\n if (!glyphs?.length) return glyphs\n return glyphs.map((g) => ({\n ...g,\n x: g.x * sx,\n y: g.y * sy,\n scaleX: (g.scaleX ?? 1) * sx,\n scaleY: (g.scaleY ?? 1) * sy,\n commandsBlob: new Uint8Array(g.commandsBlob)\n }))\n}\n\nfunction hasPath(orig: Pick<ResizeSnapshot, 'vectorNetwork'>): boolean {\n return (orig.vectorNetwork?.segments.length ?? 0) > 0\n}\n\nfunction scaleStrokes(strokes: Stroke[], sx: number, sy: number): Stroke[] {\n if (strokes.length === 0) return strokes\n // Weight is a scalar; average scale is the usual 2D → 1D compromise.\n const weightScale = (Math.abs(sx) + Math.abs(sy)) / 2\n return strokes.map((s) => ({ ...copyStroke(s), weight: s.weight * weightScale }))\n}\n\n/**\n * All geometry that must track a width/height change. Historically only\n * vectorNetwork + fillGeometry were updated — path-text strokeGeometry and\n * glyphs stayed at the pre-resize size, so shrinking a sticker made the white\n * OUTSIDE outlines look massively thick (DomeSticker resize bug).\n */\nexport function scaledGeometryChanges(\n orig: Pick<\n ResizeSnapshot,\n | 'type'\n | 'vectorNetwork'\n | 'fillGeometry'\n | 'strokeGeometry'\n | 'derivedTextGlyphs'\n | 'strokes'\n | 'textPathData'\n | 'textPathBox'\n >,\n origWidth: number,\n origHeight: number,\n width: number,\n height: number\n): Partial<SceneNode> {\n if (origWidth <= 0 && origHeight <= 0) return {}\n // A straight line's other side still scales.\n const sx = sideScale(origWidth, width)\n const sy = sideScale(origHeight, height)\n if (sx === 1 && sy === 1) return {}\n\n const changes: Partial<SceneNode> = {}\n const resizedVN = scaleVectorNetworkForResize(\n orig.vectorNetwork,\n origWidth,\n origHeight,\n width,\n height\n )\n if (resizedVN) changes.vectorNetwork = resizedVN\n\n if (orig.fillGeometry.length > 0) {\n changes.fillGeometry = scaleGeometryPaths(orig.fillGeometry, sx, sy)\n }\n // A stroke keeps its weight through a resize, as in Figma, so a saved stroke outline goes where\n // the stroke can be drawn again at its weight: from a path, or from a shape's own outline.\n // Text and a vector with only its outline keep scaling the outline, which is all they have.\n const outlineOnly = orig.type === 'TEXT' || (orig.type === 'VECTOR' && !hasPath(orig))\n if (orig.strokeGeometry.length > 0) {\n changes.strokeGeometry = outlineOnly ? scaleGeometryPaths(orig.strokeGeometry, sx, sy) : []\n }\n // Path text scales with its path, including baked path text that kept only rotated glyphs;\n // other text reflows in the new box, so its glyphs are dropped.\n const pathText = followsPath(orig)\n if (pathText) {\n changes.derivedTextGlyphs = scaleDerivedGlyphs(orig.derivedTextGlyphs, sx, sy)\n // Keep the layout/selection box in sync with the scaled glyphs. reflow\n // overrides this when it applies; this covers the fallback where reflow\n // returns null (no path data) so the box doesn't carry a stale size.\n if (orig.textPathBox) {\n changes.textPathBox = {\n x: orig.textPathBox.x * sx,\n y: orig.textPathBox.y * sy,\n width: orig.textPathBox.width * sx,\n height: orig.textPathBox.height * sy\n }\n }\n }\n // Glyphs scaled as a picture take their strokes along; any other stroke keeps its weight, as\n // Figma reports it, even where only a scaled outline can draw it.\n if (orig.strokes.length > 0 && pathText) {\n changes.strokes = scaleStrokes(orig.strokes, sx, sy)\n }\n return changes\n}\n\n/** Copies of the geometry a resize may change, as the snapshot held it before the resize. */\nfunction snapshotGeometry(orig: ResizeSnapshot): Partial<SceneNode> {\n return {\n vectorNetwork: orig.vectorNetwork ? cloneVectorNetwork(orig.vectorNetwork) : null,\n fillGeometry: copyGeometryPaths(orig.fillGeometry),\n strokeGeometry: copyGeometryPaths(orig.strokeGeometry),\n derivedTextGlyphs: copyDerivedGlyphs(orig.derivedTextGlyphs),\n strokes: copyStrokes(orig.strokes),\n textPathBox: orig.textPathBox ? { ...orig.textPathBox } : null\n }\n}\n\n/** Whether a box of `size` scales the snapshot's geometry, a flat side left out. */\nfunction scalesGeometry(orig: ResizeSnapshot, size: Pick<Rect, 'width' | 'height'>): boolean {\n return sideScale(orig.width, size.width) !== 1 || sideScale(orig.height, size.height) !== 1\n}\n\n/**\n * A child's geometry for its constrained `box`, scaled from the snapshot. At a box that scales\n * nothing, after an earlier frame of the same drag scaled it, the child takes its snapshot\n * geometry again, as nothing else would undo that scaling.\n */\nfunction constrainedGeometryChanges(\n orig: ResizeSnapshot,\n current: Pick<SceneNode, 'width' | 'height'>,\n box: Pick<Rect, 'width' | 'height'>\n): Partial<SceneNode> {\n if (scalesGeometry(orig, box))\n return scaledGeometryChanges(orig, orig.width, orig.height, box.width, box.height)\n return scalesGeometry(orig, current) ? snapshotGeometry(orig) : {}\n}\n\nexport function collectResizeDescendants(\n graph: ResizeGraph,\n rootId: string\n): Map<string, ResizeSnapshot> | null {\n const root = graph.getNode(rootId)\n if (!root || !CONSTRAINT_CONTAINER_TYPES.has(root.type)) return null\n const snapshots = new Map<string, ResizeSnapshot>()\n\n const collect = (parentId: string) => {\n const parent = graph.getNode(parentId)\n if (!parent) return\n for (const childId of parent.childIds) {\n const child = graph.getNode(childId)\n if (!child) continue\n snapshots.set(childId, createResizeSnapshot(child))\n collect(childId)\n }\n }\n\n collect(rootId)\n return snapshots.size > 0 ? snapshots : null\n}\n\n/**\n * The flips a child takes when its constraints place it from `from`, written only where they\n * differ from the ones it has now, so a drag that crosses back undoes its own turn.\n */\nexport function flipChanges(\n from: Pick<SceneNode, 'flipX' | 'flipY'>,\n current: Pick<SceneNode, 'flipX' | 'flipY'>,\n flipsX = false,\n flipsY = false\n): Partial<Pick<SceneNode, 'flipX' | 'flipY'>> {\n const changes: Partial<Pick<SceneNode, 'flipX' | 'flipY'>> = {}\n const flipX = from.flipX !== flipsX\n const flipY = from.flipY !== flipsY\n if (flipX !== current.flipX) changes.flipX = flipX\n if (flipY !== current.flipY) changes.flipY = flipY\n return changes\n}\n\ntype Size = Pick<Rect, 'width' | 'height'>\n\n/** One constrained resize: the graph, where each layer was when it began, and what it changes. */\ninterface ResizePlan {\n graph: ResizeGraph\n originals: ReadonlyMap<string, ResizeSnapshot>\n changes: Map<string, Partial<SceneNode>>\n}\n\n/** The layer as the resize found it, or as the resize leaves it with its changes so far. */\nfunction startOf(plan: ResizePlan, id: string): SceneNode | undefined {\n const node = plan.graph.getNode(id)\n const original = plan.originals.get(id)\n return node && original ? { ...node, ...original } : node\n}\n\nfunction plannedOf(plan: ResizePlan, id: string): SceneNode | undefined {\n const node = startOf(plan, id)\n const changes = plan.changes.get(id)\n return node && changes ? { ...node, ...changes } : node\n}\n\nfunction mergeChanges(plan: ResizePlan, id: string, changes: Partial<SceneNode>) {\n plan.changes.set(id, { ...plan.changes.get(id), ...changes })\n}\n\n/** Writes where a layer's constraints put it, then places its own children. */\nfunction placeConstrained(\n plan: ResizePlan,\n child: SceneNode,\n original: ResizeSnapshot,\n rect: ConstrainedRect,\n toParent: Mat3 | null\n) {\n const { flipsX, flipsY, ...box } = rect\n const position = toParent ? Matrix.mapPoint(toParent, box) : box\n plan.changes.set(child.id, {\n ...box,\n ...position,\n ...flipChanges(original, child, flipsX, flipsY),\n ...constrainedGeometryChanges(original, child, box)\n })\n // The final pass sees layout containers after layout has resolved HUG/FILL sizing.\n placeChildren(plan, child.id, original, child.layoutMode === 'NONE' ? box : child)\n}\n\n/**\n * Places the layers in a group or boolean whose frame resized. The group owns no constraints: each\n * layer in it keeps its place in the frame by its own, through nested groups, and the groups then\n * fit around them, as in Figma (live, #1835). A layer is placed in the frame's space and written\n * back in its group's.\n */\nfunction placeGroupedLayers(\n plan: ResizePlan,\n group: SceneNode,\n toFrame: Mat3,\n frameBefore: Size,\n frameAfter: Size\n) {\n for (const childId of group.childIds) {\n const child = plan.graph.getNode(childId)\n const original = plan.originals.get(childId)\n const start = startOf(plan, childId)\n if (!child || !original || !start) continue\n if (FITTED_CONTAINER_TYPES.has(child.type)) {\n const inner = Matrix.multiply(toFrame, getNodeLocalMatrix(start))\n placeGroupedLayers(plan, start, inner, frameBefore, frameAfter)\n continue\n }\n const inFrame = Matrix.mapPoint(toFrame, original)\n const rect = constrainedChildRect(\n { ...inFrame, width: original.width, height: original.height },\n frameBefore,\n frameAfter,\n child.horizontalConstraint,\n child.verticalConstraint,\n enforcedAspectRatio(child)\n )\n placeConstrained(plan, child, original, rect, Matrix.invert(toFrame))\n }\n fitPlannedGroup(plan, group.id)\n}\n\nconst PLACEMENT_KEYS = ['x', 'y', 'width', 'height'] as const\n\n/**\n * Fits a group to its layers where the resize put them, when any of them moved: a boolean's box\n * is its result's, which only the renderer measures, so one whose operands stay keeps its box. A\n * drag places from the start each time, so the group's box is always written.\n */\nfunction fitPlannedGroup(plan: ResizePlan, groupId: string) {\n const group = plannedOf(plan, groupId)\n if (!group) return\n const { x, y, width, height } = group\n mergeChanges(plan, groupId, { x, y, width, height })\n const moved = group.childIds.some((id) => {\n const start = startOf(plan, id)\n const planned = plannedOf(plan, id)\n return start && planned && PLACEMENT_KEYS.some((key) => start[key] !== planned[key])\n })\n if (!moved) return\n const reader = { rootId: plan.graph.rootId, getNode: (id: string) => plannedOf(plan, id) }\n const children = group.childIds.flatMap((id) => reader.getNode(id) ?? [])\n const fit = groupFitChanges(reader, group, children)\n for (const [id, changes] of fit ?? []) mergeChanges(plan, id, changes)\n}\n\n/**\n * Places the children of a layer that went from `parentBefore` to `parentAfter`: a frame's by their\n * constraints, the layers in its groups and booleans by theirs, a group's or boolean's own scaled.\n */\nfunction placeChildren(plan: ResizePlan, parentId: string, parentBefore: Size, parentAfter: Size) {\n const parent = plan.graph.getNode(parentId)\n if (!parent) return\n const scalesChildren = FITTED_CONTAINER_TYPES.has(parent.type)\n for (const childId of parent.childIds) {\n const original = plan.originals.get(childId)\n const child = plan.graph.getNode(childId)\n if (!original || !child) continue\n const isInFlow = parent.layoutMode !== 'NONE' && child.layoutPositioning !== 'ABSOLUTE'\n if (isInFlow) {\n placeChildren(plan, childId, original, child)\n continue\n }\n if (!scalesChildren && FITTED_CONTAINER_TYPES.has(child.type)) {\n const start = { ...child, ...original }\n placeGroupedLayers(plan, start, getNodeLocalMatrix(start), parentBefore, parentAfter)\n continue\n }\n const rect: ConstrainedRect = scalesChildren\n ? scaledChildRect(original, parentBefore, parentAfter)\n : constrainedChildRect(\n original,\n parentBefore,\n parentAfter,\n child.horizontalConstraint,\n child.verticalConstraint,\n enforcedAspectRatio(child)\n )\n placeConstrained(plan, child, original, rect, null)\n }\n}\n\n/**\n * Where the descendants of a layer go when it resizes from `rootBefore` to `rootAfter`, from the\n * places `originals` recorded.\n */\nexport function computeConstrainedResizeChanges(\n graph: ResizeGraph,\n rootId: string,\n rootBefore: Size,\n rootAfter: Size,\n originals: ReadonlyMap<string, ResizeSnapshot>\n): Map<string, Partial<SceneNode>> {\n const plan: ResizePlan = { graph, originals, changes: new Map() }\n placeChildren(plan, rootId, rootBefore, rootAfter)\n return plan.changes\n}\n"],"mappings":";;;;;;;;;;;;;AAmDA,MAAM,6CAA6B,IAAI,IAAuB,CAC5D,GAAG,yBACH,GAAG,sBACL,CAAC;;;;;;;;;;AAgBD,SAAS,gBACP,UACA,MACA,cACA,aACA,YACe;CACf,MAAM,QAAQ,KAAK,MAAM,WAAW,IAAI,KAAK,MAAM,YAAY;CAC/D,IAAI,eAAe,OAAO,OAAO;EAAE,UAAU,WAAW;EAAO;CAAK;CACpE,IAAI,eAAe,UACjB,OAAO;EAAE,UAAU,WAAW,KAAK,MAAM,cAAc,CAAC,IAAI,KAAK,MAAM,eAAe,CAAC;EAAG;CAAK;CAEjG,IAAI,eAAe,WAAW;EAC5B,MAAM,YAAY,OAAO;EACzB,IAAI,cAAc,GAAG,OAAO;GAAE;GAAU;EAAK;EAC7C,IAAI,YAAY,GAAG,OAAO;GAAE;GAAU,MAAM;EAAU;EACtD,OAAO;GAAE,UAAU,WAAW;GAAW,MAAM,CAAC;GAAW,SAAS;EAAK;CAC3E;CACA,IAAI,eAAe,WAAW,eAAe,GAAG;EAC9C,MAAM,QAAQ,cAAc;EAC5B,OAAO;GAAE,UAAU,WAAW;GAAO,MAAM,OAAO;EAAM;CAC1D;CACA,OAAO;EAAE;EAAU;CAAK;AAC1B;AAEA,MAAM,uCAAoD,IAAI,IAAI,CAAC,WAAW,OAAO,CAAC;;AAGtF,SAAS,eACP,QACA,MACA,YACe;CACf,IAAI,eAAe,OAAO,OAAO;EAAE,UAAU,OAAO,WAAW,OAAO,OAAO;EAA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cAAc,MAAM,QAAQ,YAAY,SAAS;CACjD,OAAO,KAAK;AACd"}
@@ -1 +1 @@
1
- {"version":3,"file":"node.d.ts","names":[],"sources":["../../src/scaling/node.ts"],"mappings":";;iBAyHgB,iBACd,MAAM,WACN,eACA,yBACC,QAAQ"}
1
+ {"version":3,"file":"node.d.ts","names":[],"sources":["../../src/scaling/node.ts"],"mappings":";;iBAiJgB,iBACd,MAAM,WACN,eACA,yBACC,QAAQ"}
@@ -1,5 +1,6 @@
1
1
  import { scaledTextLength } from "../text/lengths.js";
2
- import { cloneVectorNetwork, scaleGeometryPaths } from "../copy.js";
2
+ import { cloneVectorNetwork, copyDerivedGlyphs, scaleGeometryPaths } from "../copy.js";
3
+ import { followsPath } from "../text/path.js";
3
4
  import { TEXT_PARAGRAPH_SPACING_FIELDS } from "../text/paragraphs.js";
4
5
  //#region src/scaling/node.ts
5
6
  function scaledOptional(value, scale) {
@@ -95,6 +96,25 @@ function scaledVectorNetwork(node, scale) {
95
96
  for (const region of network.regions) if (region.fills) region.fills = scaledFills(region.fills, scale);
96
97
  return network;
97
98
  }
99
+ function scaledPathText(node, scale) {
100
+ if (!node.textPathData && !followsPath(node)) return {};
101
+ const box = node.textPathBox;
102
+ return {
103
+ derivedTextGlyphs: copyDerivedGlyphs(node.derivedTextGlyphs)?.map((glyph) => ({
104
+ ...glyph,
105
+ x: glyph.x * scale,
106
+ y: glyph.y * scale,
107
+ fontSize: glyph.fontSize * scale,
108
+ ...glyph.advance === void 0 ? {} : { advance: glyph.advance * scale }
109
+ })) ?? null,
110
+ textPathBox: box && {
111
+ x: box.x * scale,
112
+ y: box.y * scale,
113
+ width: box.width * scale,
114
+ height: box.height * scale
115
+ }
116
+ };
117
+ }
98
118
  function scaleNodeChanges(node, scale, scalePosition) {
99
119
  return {
100
120
  x: scalePosition ? node.x * scale : node.x,
@@ -120,8 +140,9 @@ function scaleNodeChanges(node, scale, scalePosition) {
120
140
  paragraphSpacing: node.paragraphSpacing * scale,
121
141
  paragraphIndent: node.paragraphIndent * scale,
122
142
  textParagraphs: scaledParagraphStyles(node.textParagraphs, scale),
143
+ derivedTextHeight: scaledOptional(node.derivedTextHeight, scale),
123
144
  itemSpacing: node.itemSpacing * scale,
124
- counterAxisSpacing: node.counterAxisSpacing * scale,
145
+ counterAxisSpacing: node.counterAxisSpacing === null ? null : node.counterAxisSpacing * scale,
125
146
  paddingTop: node.paddingTop * scale,
126
147
  paddingRight: node.paddingRight * scale,
127
148
  paddingBottom: node.paddingBottom * scale,
@@ -143,7 +164,8 @@ function scaleNodeChanges(node, scale, scalePosition) {
143
164
  layoutGrids: scaledLayoutGrids(node.layoutGrids, scale),
144
165
  vectorNetwork: scaledVectorNetwork(node, scale),
145
166
  fillGeometry: scaleGeometryPaths(node.fillGeometry, scale, scale),
146
- strokeGeometry: scaleGeometryPaths(node.strokeGeometry, scale, scale)
167
+ strokeGeometry: scaleGeometryPaths(node.strokeGeometry, scale, scale),
168
+ ...scaledPathText(node, scale)
147
169
  };
148
170
  }
149
171
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"node.js","names":[],"sources":["../../src/scaling/node.ts"],"sourcesContent":["import { cloneVectorNetwork, scaleGeometryPaths } from '../copy'\nimport { scaledTextLength } from '../text/lengths'\nimport { TEXT_PARAGRAPH_SPACING_FIELDS } from '../text/paragraphs'\nimport {\n type Effect,\n type Fill,\n type GridTrack,\n type LayoutGrid,\n type SceneNode,\n type Stroke,\n type StyleRun,\n type TextParagraphStyle\n} from '../types'\n\nfunction scaledOptional(value: number | null, scale: number): number | null {\n return value == null ? null : value * scale\n}\n\nfunction scaledStrokes(strokes: readonly Stroke[], scale: number): Stroke[] {\n return strokes.map((stroke) => ({\n ...structuredClone(stroke),\n weight: stroke.weight * scale,\n dashPattern: stroke.dashPattern?.map((value) => value * scale)\n }))\n}\n\nfunction scaledEffects(effects: readonly Effect[], scale: number): Effect[] {\n return effects.map((effect) => ({\n ...structuredClone(effect),\n offset: { x: effect.offset.x * scale, y: effect.offset.y * scale },\n radius: effect.radius * scale,\n spread: effect.spread * scale,\n ...(effect.progressive\n ? {\n progressive: {\n ...structuredClone(effect.progressive),\n startRadius: effect.progressive.startRadius * scale\n }\n }\n : {})\n }))\n}\n\nfunction scaledFills(fills: readonly Fill[], scale: number): Fill[] {\n return fills.map((fill) => ({\n ...structuredClone(fill),\n scale: fill.scale == null ? undefined : fill.scale * scale,\n spacing: fill.spacing == null ? undefined : fill.spacing * scale,\n patternSpacing: fill.patternSpacing\n ? { x: fill.patternSpacing.x * scale, y: fill.patternSpacing.y * scale }\n : undefined,\n noiseSize: fill.noiseSize\n ? { x: fill.noiseSize.x * scale, y: fill.noiseSize.y * scale }\n : undefined\n }))\n}\n\nfunction scaledStyleRuns(styleRuns: readonly StyleRun[], scale: number): StyleRun[] {\n return styleRuns.map((run) => ({\n ...structuredClone(run),\n style: {\n ...structuredClone(run.style),\n fontSize: run.style.fontSize == null ? undefined : run.style.fontSize * scale,\n letterSpacing: run.style.letterSpacing && scaledTextLength(run.style.letterSpacing, scale),\n lineHeight: run.style.lineHeight && scaledTextLength(run.style.lineHeight, scale),\n textDecorationThickness: scaledOptional(run.style.textDecorationThickness ?? null, scale),\n textUnderlineOffset: scaledOptional(run.style.textUnderlineOffset ?? null, scale)\n }\n }))\n}\n\nfunction scaledParagraphStyles(\n paragraphs: readonly TextParagraphStyle[],\n scale: number\n): TextParagraphStyle[] {\n return paragraphs.map((style) => {\n const scaled = { ...style }\n for (const field of TEXT_PARAGRAPH_SPACING_FIELDS) {\n const value = style[field]\n if (value !== undefined) scaled[field] = value * scale\n }\n return scaled\n })\n}\n\nfunction scaledLayoutGrids(grids: readonly LayoutGrid[], scale: number): LayoutGrid[] {\n return grids.map((grid) => ({\n ...structuredClone(grid),\n offset: grid.offset == null ? undefined : grid.offset * scale,\n sectionSize: grid.sectionSize == null ? undefined : grid.sectionSize * scale,\n gutterSize: grid.gutterSize == null ? undefined : grid.gutterSize * scale\n }))\n}\n\nfunction scaledGridTracks(tracks: readonly GridTrack[], scale: number): GridTrack[] {\n return tracks.map((track) => ({\n ...track,\n value: track.sizing === 'FIXED' ? track.value * scale : track.value\n }))\n}\n\nfunction scaledVectorNetwork(node: SceneNode, scale: number): SceneNode['vectorNetwork'] {\n if (!node.vectorNetwork) return null\n const network = cloneVectorNetwork(node.vectorNetwork)\n for (const vertex of network.vertices) {\n vertex.x *= scale\n vertex.y *= scale\n }\n for (const segment of network.segments) {\n segment.tangentStart.x *= scale\n segment.tangentStart.y *= scale\n segment.tangentEnd.x *= scale\n segment.tangentEnd.y *= scale\n }\n // A region's own paints scale as the layer's do.\n for (const region of network.regions) {\n if (region.fills) region.fills = scaledFills(region.fills, scale)\n }\n return network\n}\n\nexport function scaleNodeChanges(\n node: SceneNode,\n scale: number,\n scalePosition: boolean\n): Partial<SceneNode> {\n return {\n x: scalePosition ? node.x * scale : node.x,\n y: scalePosition ? node.y * scale : node.y,\n width: node.width * scale,\n height: node.height * scale,\n minWidth: scaledOptional(node.minWidth, scale),\n maxWidth: scaledOptional(node.maxWidth, scale),\n minHeight: scaledOptional(node.minHeight, scale),\n maxHeight: scaledOptional(node.maxHeight, scale),\n cornerRadius: node.cornerRadius * scale,\n topLeftRadius: node.topLeftRadius * scale,\n topRightRadius: node.topRightRadius * scale,\n bottomRightRadius: node.bottomRightRadius * scale,\n bottomLeftRadius: node.bottomLeftRadius * scale,\n fontSize: node.fontSize * scale,\n letterSpacing: scaledTextLength(node.letterSpacing, scale),\n lineHeight: node.lineHeight && scaledTextLength(node.lineHeight, scale),\n textDecorationThickness: scaledOptional(node.textDecorationThickness, scale),\n textUnderlineOffset: scaledOptional(node.textUnderlineOffset, scale),\n styleRuns: scaledStyleRuns(node.styleRuns, scale),\n listSpacing: node.listSpacing * scale,\n paragraphSpacing: node.paragraphSpacing * scale,\n paragraphIndent: node.paragraphIndent * scale,\n textParagraphs: scaledParagraphStyles(node.textParagraphs, scale),\n itemSpacing: node.itemSpacing * scale,\n counterAxisSpacing: node.counterAxisSpacing * scale,\n paddingTop: node.paddingTop * scale,\n paddingRight: node.paddingRight * scale,\n paddingBottom: node.paddingBottom * scale,\n paddingLeft: node.paddingLeft * scale,\n gridColumnGap: node.gridColumnGap * scale,\n gridRowGap: node.gridRowGap * scale,\n gridTemplateColumns: scaledGridTracks(node.gridTemplateColumns, scale),\n gridTemplateRows: scaledGridTracks(node.gridTemplateRows, scale),\n strokes: scaledStrokes(node.strokes, scale),\n strokeWeight: node.strokeWeight * scale,\n dashPattern: node.dashPattern.map((value) => value * scale),\n borderTopWeight: node.borderTopWeight * scale,\n borderRightWeight: node.borderRightWeight * scale,\n borderBottomWeight: node.borderBottomWeight * scale,\n borderLeftWeight: node.borderLeftWeight * scale,\n strokeMiterLimit: node.strokeMiterLimit,\n effects: scaledEffects(node.effects, scale),\n fills: scaledFills(node.fills, scale),\n layoutGrids: scaledLayoutGrids(node.layoutGrids, scale),\n vectorNetwork: scaledVectorNetwork(node, scale),\n fillGeometry: scaleGeometryPaths(node.fillGeometry, scale, scale),\n strokeGeometry: scaleGeometryPaths(node.strokeGeometry, scale, scale)\n }\n}\n"],"mappings":";;;;AAcA,SAAS,eAAe,OAAsB,OAA8B;CAC1E,OAAO,SAAS,OAAO,OAAO,QAAQ;AACxC;AAEA,SAAS,cAAc,SAA4B,OAAyB;CAC1E,OAAO,QAAQ,KAAK,YAAY;EAC9B,GAAG,gBAAgB,MAAM;EACzB,QAAQ,OAAO,SAAS;EACxB,aAAa,OAAO,aAAa,KAAK,UAAU,QAAQ,KAAK;CAC/D,EAAE;AACJ;AAEA,SAAS,cAAc,SAA4B,OAAyB;CAC1E,OAAO,QAAQ,KAAK,YAAY;EAC9B,GAAG,gBAAgB,MAAM;EACzB,QAAQ;GAAE,GAAG,OAAO,OAAO,IAAI;GAAO,GAAG,OAAO,OAAO,IAAI;EAAM;EACjE,QAAQ,OAAO,SAAS;EACxB,QAAQ,OAAO,SAAS;EACxB,GAAI,OAAO,cACP,EACE,aAAa;GACX,GAA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,OAAO,KAAK;CACtE;AACF"}
1
+ {"version":3,"file":"node.js","names":[],"sources":["../../src/scaling/node.ts"],"sourcesContent":["import { cloneVectorNetwork, copyDerivedGlyphs, scaleGeometryPaths } from '../copy'\nimport { scaledTextLength } from '../text/lengths'\nimport { TEXT_PARAGRAPH_SPACING_FIELDS } from '../text/paragraphs'\nimport { followsPath } from '../text/path'\nimport {\n type Effect,\n type Fill,\n type GridTrack,\n type LayoutGrid,\n type SceneNode,\n type Stroke,\n type StyleRun,\n type TextParagraphStyle\n} from '../types'\n\nfunction scaledOptional(value: number | null, scale: number): number | null {\n return value == null ? null : value * scale\n}\n\nfunction scaledStrokes(strokes: readonly Stroke[], scale: number): Stroke[] {\n return strokes.map((stroke) => ({\n ...structuredClone(stroke),\n weight: stroke.weight * scale,\n dashPattern: stroke.dashPattern?.map((value) => value * scale)\n }))\n}\n\nfunction scaledEffects(effects: readonly Effect[], scale: number): Effect[] {\n return effects.map((effect) => ({\n ...structuredClone(effect),\n offset: { x: effect.offset.x * scale, y: effect.offset.y * scale },\n radius: effect.radius * scale,\n spread: effect.spread * scale,\n ...(effect.progressive\n ? {\n progressive: {\n ...structuredClone(effect.progressive),\n startRadius: effect.progressive.startRadius * scale\n }\n }\n : {})\n }))\n}\n\nfunction scaledFills(fills: readonly Fill[], scale: number): Fill[] {\n return fills.map((fill) => ({\n ...structuredClone(fill),\n scale: fill.scale == null ? undefined : fill.scale * scale,\n spacing: fill.spacing == null ? undefined : fill.spacing * scale,\n patternSpacing: fill.patternSpacing\n ? { x: fill.patternSpacing.x * scale, y: fill.patternSpacing.y * scale }\n : undefined,\n noiseSize: fill.noiseSize\n ? { x: fill.noiseSize.x * scale, y: fill.noiseSize.y * scale }\n : undefined\n }))\n}\n\nfunction scaledStyleRuns(styleRuns: readonly StyleRun[], scale: number): StyleRun[] {\n return styleRuns.map((run) => ({\n ...structuredClone(run),\n style: {\n ...structuredClone(run.style),\n fontSize: run.style.fontSize == null ? undefined : run.style.fontSize * scale,\n letterSpacing: run.style.letterSpacing && scaledTextLength(run.style.letterSpacing, scale),\n lineHeight: run.style.lineHeight && scaledTextLength(run.style.lineHeight, scale),\n textDecorationThickness: scaledOptional(run.style.textDecorationThickness ?? null, scale),\n textUnderlineOffset: scaledOptional(run.style.textUnderlineOffset ?? null, scale)\n }\n }))\n}\n\nfunction scaledParagraphStyles(\n paragraphs: readonly TextParagraphStyle[],\n scale: number\n): TextParagraphStyle[] {\n return paragraphs.map((style) => {\n const scaled = { ...style }\n for (const field of TEXT_PARAGRAPH_SPACING_FIELDS) {\n const value = style[field]\n if (value !== undefined) scaled[field] = value * scale\n }\n return scaled\n })\n}\n\nfunction scaledLayoutGrids(grids: readonly LayoutGrid[], scale: number): LayoutGrid[] {\n return grids.map((grid) => ({\n ...structuredClone(grid),\n offset: grid.offset == null ? undefined : grid.offset * scale,\n sectionSize: grid.sectionSize == null ? undefined : grid.sectionSize * scale,\n gutterSize: grid.gutterSize == null ? undefined : grid.gutterSize * scale\n }))\n}\n\nfunction scaledGridTracks(tracks: readonly GridTrack[], scale: number): GridTrack[] {\n return tracks.map((track) => ({\n ...track,\n value: track.sizing === 'FIXED' ? track.value * scale : track.value\n }))\n}\n\nfunction scaledVectorNetwork(node: SceneNode, scale: number): SceneNode['vectorNetwork'] {\n if (!node.vectorNetwork) return null\n const network = cloneVectorNetwork(node.vectorNetwork)\n for (const vertex of network.vertices) {\n vertex.x *= scale\n vertex.y *= scale\n }\n for (const segment of network.segments) {\n segment.tangentStart.x *= scale\n segment.tangentStart.y *= scale\n segment.tangentEnd.x *= scale\n segment.tangentEnd.y *= scale\n }\n // A region's own paints scale as the layer's do.\n for (const region of network.regions) {\n if (region.fills) region.fills = scaledFills(region.fills, scale)\n }\n return network\n}\n\nfunction scaledPathText(node: SceneNode, scale: number): Partial<SceneNode> {\n if (!node.textPathData && !followsPath(node)) {\n return {}\n }\n const box = node.textPathBox\n return {\n derivedTextGlyphs:\n copyDerivedGlyphs(node.derivedTextGlyphs)?.map((glyph) => ({\n ...glyph,\n x: glyph.x * scale,\n y: glyph.y * scale,\n fontSize: glyph.fontSize * scale,\n ...(glyph.advance === undefined ? {} : { advance: glyph.advance * scale })\n })) ?? null,\n textPathBox: box && {\n x: box.x * scale,\n y: box.y * scale,\n width: box.width * scale,\n height: box.height * scale\n }\n }\n}\n\nexport function scaleNodeChanges(\n node: SceneNode,\n scale: number,\n scalePosition: boolean\n): Partial<SceneNode> {\n return {\n x: scalePosition ? node.x * scale : node.x,\n y: scalePosition ? node.y * scale : node.y,\n width: node.width * scale,\n height: node.height * scale,\n minWidth: scaledOptional(node.minWidth, scale),\n maxWidth: scaledOptional(node.maxWidth, scale),\n minHeight: scaledOptional(node.minHeight, scale),\n maxHeight: scaledOptional(node.maxHeight, scale),\n cornerRadius: node.cornerRadius * scale,\n topLeftRadius: node.topLeftRadius * scale,\n topRightRadius: node.topRightRadius * scale,\n bottomRightRadius: node.bottomRightRadius * scale,\n bottomLeftRadius: node.bottomLeftRadius * scale,\n fontSize: node.fontSize * scale,\n letterSpacing: scaledTextLength(node.letterSpacing, scale),\n lineHeight: node.lineHeight && scaledTextLength(node.lineHeight, scale),\n textDecorationThickness: scaledOptional(node.textDecorationThickness, scale),\n textUnderlineOffset: scaledOptional(node.textUnderlineOffset, scale),\n styleRuns: scaledStyleRuns(node.styleRuns, scale),\n listSpacing: node.listSpacing * scale,\n paragraphSpacing: node.paragraphSpacing * scale,\n paragraphIndent: node.paragraphIndent * scale,\n textParagraphs: scaledParagraphStyles(node.textParagraphs, scale),\n derivedTextHeight: scaledOptional(node.derivedTextHeight, scale),\n itemSpacing: node.itemSpacing * scale,\n counterAxisSpacing: node.counterAxisSpacing === null ? null : node.counterAxisSpacing * scale,\n paddingTop: node.paddingTop * scale,\n paddingRight: node.paddingRight * scale,\n paddingBottom: node.paddingBottom * scale,\n paddingLeft: node.paddingLeft * scale,\n gridColumnGap: node.gridColumnGap * scale,\n gridRowGap: node.gridRowGap * scale,\n gridTemplateColumns: scaledGridTracks(node.gridTemplateColumns, scale),\n gridTemplateRows: scaledGridTracks(node.gridTemplateRows, scale),\n strokes: scaledStrokes(node.strokes, scale),\n strokeWeight: node.strokeWeight * scale,\n dashPattern: node.dashPattern.map((value) => value * scale),\n borderTopWeight: node.borderTopWeight * scale,\n borderRightWeight: node.borderRightWeight * scale,\n borderBottomWeight: node.borderBottomWeight * scale,\n borderLeftWeight: node.borderLeftWeight * scale,\n strokeMiterLimit: node.strokeMiterLimit,\n effects: scaledEffects(node.effects, scale),\n fills: scaledFills(node.fills, scale),\n layoutGrids: scaledLayoutGrids(node.layoutGrids, scale),\n vectorNetwork: scaledVectorNetwork(node, scale),\n fillGeometry: scaleGeometryPaths(node.fillGeometry, scale, scale),\n strokeGeometry: scaleGeometryPaths(node.strokeGeometry, scale, scale),\n ...scaledPathText(node, scale)\n }\n}\n"],"mappings":";;;;;AAeA,SAAS,eAAe,OAAsB,OAA8B;CAC1E,OAAO,SAAS,OAAO,OAAO,QAAQ;AACxC;AAEA,SAAS,cAAc,SAA4B,OAAyB;CAC1E,OAAO,QAAQ,KAAK,YAAY;EAC9B,GAAG,gBAAgB,MAAM;EACzB,QAAQ,OAAO,SAAS;EACxB,aAAa,OAAO,aAAa,KAAK,UAAU,QAAQ,KAAK;CAC/D,EAAE;AACJ;AAEA,SAAS,cAAc,SAA4B,OAAyB;CAC1E,OAAO,QAAQ,KAAK,YAAY;EAC9B,GAAG,gBAAgB,MAAM;EACzB,QAAQ;GAAE,GAAG,OAAO,OAAO,IAAI;GAAO,GAAG,OAAO,OAAO,IAAI;EAAM;EACjE,QAAQ,OAAO,SAAS;EACxB,QAAQ,OAAO,SAAS;EACxB,GAAI,OAAO,cACP,EACE,aAAa;GACX,GAAG,gBAAgB,OAAO,WAAW;GACrC,aAAa,OAAO,YAAY,cAAc;EAChD,EACF,IACA,CAAC;CACP,EAAE;AACJ;AAEA,SAAS,YAAY,OAAwB,OAAuB;CAClE,OAAO,MAAM,KAAK,UAAU;EAC1B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,aAAa,KAAK,YAAY,KAAK,UAAU,QAAQ,KAAK;EAC1D,iBAAiB,KAAK,kBAAkB;EACxC,mBAAmB,KAAK,oBAAoB;EAC5C,oBAAoB,KAAK,qBAAqB;EAC9C,kBAAkB,KAAK,mBAAmB;EAC1C,kBAAkB,KAAK;EACvB,SAAS,cAAc,KAAK,SAAS,KAAK;EAC1C,OAAO,YAAY,KAAK,OAAO,KAAK;EACpC,aAAa,kBAAkB,KAAK,aAAa,KAAK;EACtD,eAAe,oBAAoB,MAAM,KAAK;EAC9C,cAAc,mBAAmB,KAAK,cAAc,OAAO,KAAK;EAChE,gBAAgB,mBAAmB,KAAK,gBAAgB,OAAO,KAAK;EACpE,GAAG,eAAe,MAAM,KAAK;CAC/B;AACF"}
@@ -0,0 +1,15 @@
1
+ import { SceneNode, TextAutoResize } from "../types.js";
2
+ //#region src/text/auto-resize.d.ts
3
+ /** A text's resizing as Figma's plugin API names it, where `TRUNCATE` is a fixed box that truncates. */
4
+ type FigmaTextAutoResize = TextAutoResize | 'TRUNCATE';
5
+ type TextResizeFields = Pick<SceneNode, 'textAutoResize' | 'textTruncation' | 'maxLines'>;
6
+ /** The resizing Figma's plugin API reads for a text: a fixed box that truncates reads `TRUNCATE`. */
7
+ declare function figmaTextAutoResize(node: Pick<SceneNode, 'textAutoResize' | 'textTruncation'>): FigmaTextAutoResize;
8
+ /**
9
+ * The fields setting a resizing writes, as Figma's setter does: `TRUNCATE` fixes the box and
10
+ * truncates its end with no line limit, and any other mode stops truncating.
11
+ */
12
+ declare function textAutoResizeFields(mode: FigmaTextAutoResize): Partial<TextResizeFields>;
13
+ //#endregion
14
+ export { FigmaTextAutoResize, figmaTextAutoResize, textAutoResizeFields };
15
+ //# sourceMappingURL=auto-resize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auto-resize.d.ts","names":[],"sources":["../../src/text/auto-resize.ts"],"mappings":";;;KAGY,sBAAsB;KAE7B,mBAAmB,KAAK;;iBAGb,oBACd,MAAM,KAAK,kDACV;;;;;iBAUa,qBAAqB,MAAM,sBAAsB,QAAQ"}
@@ -0,0 +1,23 @@
1
+ //#region src/text/auto-resize.ts
2
+ /** The resizing Figma's plugin API reads for a text: a fixed box that truncates reads `TRUNCATE`. */
3
+ function figmaTextAutoResize(node) {
4
+ return node.textAutoResize === "NONE" && node.textTruncation === "ENDING" ? "TRUNCATE" : node.textAutoResize;
5
+ }
6
+ /**
7
+ * The fields setting a resizing writes, as Figma's setter does: `TRUNCATE` fixes the box and
8
+ * truncates its end with no line limit, and any other mode stops truncating.
9
+ */
10
+ function textAutoResizeFields(mode) {
11
+ return mode === "TRUNCATE" ? {
12
+ textAutoResize: "NONE",
13
+ textTruncation: "ENDING",
14
+ maxLines: null
15
+ } : {
16
+ textAutoResize: mode,
17
+ textTruncation: "DISABLED"
18
+ };
19
+ }
20
+ //#endregion
21
+ export { figmaTextAutoResize, textAutoResizeFields };
22
+
23
+ //# sourceMappingURL=auto-resize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auto-resize.js","names":[],"sources":["../../src/text/auto-resize.ts"],"sourcesContent":["import type { SceneNode, TextAutoResize } from '../types'\n\n/** A text's resizing as Figma's plugin API names it, where `TRUNCATE` is a fixed box that truncates. */\nexport type FigmaTextAutoResize = TextAutoResize | 'TRUNCATE'\n\ntype TextResizeFields = Pick<SceneNode, 'textAutoResize' | 'textTruncation' | 'maxLines'>\n\n/** The resizing Figma's plugin API reads for a text: a fixed box that truncates reads `TRUNCATE`. */\nexport function figmaTextAutoResize(\n node: Pick<SceneNode, 'textAutoResize' | 'textTruncation'>\n): FigmaTextAutoResize {\n return node.textAutoResize === 'NONE' && node.textTruncation === 'ENDING'\n ? 'TRUNCATE'\n : node.textAutoResize\n}\n\n/**\n * The fields setting a resizing writes, as Figma's setter does: `TRUNCATE` fixes the box and\n * truncates its end with no line limit, and any other mode stops truncating.\n */\nexport function textAutoResizeFields(mode: FigmaTextAutoResize): Partial<TextResizeFields> {\n return mode === 'TRUNCATE'\n ? { textAutoResize: 'NONE', textTruncation: 'ENDING', maxLines: null }\n : { textAutoResize: mode, textTruncation: 'DISABLED' }\n}\n"],"mappings":";;AAQA,SAAgB,oBACd,MACqB;CACrB,OAAO,KAAK,mBAAmB,UAAU,KAAK,mBAAmB,WAC7D,aACA,KAAK;AACX;;;;;AAMA,SAAgB,qBAAqB,MAAsD;CACzF,OAAO,SAAS,aACZ;EAAE,gBAAgB;EAAQ,gBAAgB;EAAU,UAAU;CAAK,IACnE;EAAE,gBAAgB;EAAM,gBAAgB;CAAW;AACzD"}
@@ -1,7 +1,8 @@
1
+ import { FigmaTextAutoResize, figmaTextAutoResize, textAutoResizeFields } from "./auto-resize.js";
1
2
  import { MAX_LIST_INDENTATION, PLAIN_PARAGRAPH, TEXT_PARAGRAPH_SPACING_FIELDS, TextParagraphRange, hasParagraphSpacing, hasTextList, paragraphCount, paragraphIndexAt, paragraphSpacingAt, paragraphStyleAt, paragraphStylesAfterEdit, paragraphStylesAfterTextChange, paragraphStylesInRange, paragraphStylesWithoutSpacing, sharedParagraphSpacing, textParagraphRanges, trimParagraphStyles, withIndentation, withListType, withParagraphSpacing } from "./paragraphs.js";
2
3
  import { LIST_BULLET, ListNumberFormat, TextListItem, formatListNumber, listNumberFormat, textListItems, topLevelNumberDigits } from "./lists.js";
3
4
  import { StyleRunReferences, remapStyleRunReferences, styleRunReferences } from "./references.js";
4
- import { NO_LETTER_SPACING, formatTextLength, lineHeightPixels, lineStepPixels, percentLength, pixelLength, scaledTextLength, textLengthPixels } from "./lengths.js";
5
- import { textLinesOverflow } from "./overflow.js";
5
+ import { NO_LETTER_SPACING, estimatedLineStep, formatTextLength, lineHeightPixels, lineStepPixels, percentLength, pixelLength, scaledTextLength, textLengthPixels } from "./lengths.js";
6
+ import { TextLinesReach, textLinesReach, textVerticalOffset } from "./overflow.js";
6
7
  import { textLengthSchema } from "./schema.js";
7
- export { LIST_BULLET, ListNumberFormat, MAX_LIST_INDENTATION, NO_LETTER_SPACING, PLAIN_PARAGRAPH, StyleRunReferences, TEXT_PARAGRAPH_SPACING_FIELDS, TextListItem, TextParagraphRange, formatListNumber, formatTextLength, hasParagraphSpacing, hasTextList, lineHeightPixels, lineStepPixels, listNumberFormat, paragraphCount, paragraphIndexAt, paragraphSpacingAt, paragraphStyleAt, paragraphStylesAfterEdit, paragraphStylesAfterTextChange, paragraphStylesInRange, paragraphStylesWithoutSpacing, percentLength, pixelLength, remapStyleRunReferences, scaledTextLength, sharedParagraphSpacing, styleRunReferences, textLengthPixels, textLengthSchema, textLinesOverflow, textListItems, textParagraphRanges, topLevelNumberDigits, trimParagraphStyles, withIndentation, withListType, withParagraphSpacing };
8
+ export { FigmaTextAutoResize, LIST_BULLET, ListNumberFormat, MAX_LIST_INDENTATION, NO_LETTER_SPACING, PLAIN_PARAGRAPH, StyleRunReferences, TEXT_PARAGRAPH_SPACING_FIELDS, TextLinesReach, TextListItem, TextParagraphRange, estimatedLineStep, figmaTextAutoResize, formatListNumber, formatTextLength, hasParagraphSpacing, hasTextList, lineHeightPixels, lineStepPixels, listNumberFormat, paragraphCount, paragraphIndexAt, paragraphSpacingAt, paragraphStyleAt, paragraphStylesAfterEdit, paragraphStylesAfterTextChange, paragraphStylesInRange, paragraphStylesWithoutSpacing, percentLength, pixelLength, remapStyleRunReferences, scaledTextLength, sharedParagraphSpacing, styleRunReferences, textAutoResizeFields, textLengthPixels, textLengthSchema, textLinesReach, textListItems, textParagraphRanges, textVerticalOffset, topLevelNumberDigits, trimParagraphStyles, withIndentation, withListType, withParagraphSpacing };
@@ -1,7 +1,8 @@
1
- import { NO_LETTER_SPACING, formatTextLength, lineHeightPixels, lineStepPixels, percentLength, pixelLength, scaledTextLength, textLengthPixels } from "./lengths.js";
1
+ import { NO_LETTER_SPACING, estimatedLineStep, formatTextLength, lineHeightPixels, lineStepPixels, percentLength, pixelLength, scaledTextLength, textLengthPixels } from "./lengths.js";
2
2
  import { remapStyleRunReferences, styleRunReferences } from "./references.js";
3
3
  import { MAX_LIST_INDENTATION, PLAIN_PARAGRAPH, TEXT_PARAGRAPH_SPACING_FIELDS, hasParagraphSpacing, hasTextList, paragraphCount, paragraphIndexAt, paragraphSpacingAt, paragraphStyleAt, paragraphStylesAfterEdit, paragraphStylesAfterTextChange, paragraphStylesInRange, paragraphStylesWithoutSpacing, sharedParagraphSpacing, textParagraphRanges, trimParagraphStyles, withIndentation, withListType, withParagraphSpacing } from "./paragraphs.js";
4
+ import { figmaTextAutoResize, textAutoResizeFields } from "./auto-resize.js";
4
5
  import { LIST_BULLET, formatListNumber, listNumberFormat, textListItems, topLevelNumberDigits } from "./lists.js";
5
- import { textLinesOverflow } from "./overflow.js";
6
+ import { textLinesReach, textVerticalOffset } from "./overflow.js";
6
7
  import { textLengthSchema } from "./schema.js";
7
- export { LIST_BULLET, MAX_LIST_INDENTATION, NO_LETTER_SPACING, PLAIN_PARAGRAPH, TEXT_PARAGRAPH_SPACING_FIELDS, formatListNumber, formatTextLength, hasParagraphSpacing, hasTextList, lineHeightPixels, lineStepPixels, listNumberFormat, paragraphCount, paragraphIndexAt, paragraphSpacingAt, paragraphStyleAt, paragraphStylesAfterEdit, paragraphStylesAfterTextChange, paragraphStylesInRange, paragraphStylesWithoutSpacing, percentLength, pixelLength, remapStyleRunReferences, scaledTextLength, sharedParagraphSpacing, styleRunReferences, textLengthPixels, textLengthSchema, textLinesOverflow, textListItems, textParagraphRanges, topLevelNumberDigits, trimParagraphStyles, withIndentation, withListType, withParagraphSpacing };
8
+ export { LIST_BULLET, MAX_LIST_INDENTATION, NO_LETTER_SPACING, PLAIN_PARAGRAPH, TEXT_PARAGRAPH_SPACING_FIELDS, estimatedLineStep, figmaTextAutoResize, formatListNumber, formatTextLength, hasParagraphSpacing, hasTextList, lineHeightPixels, lineStepPixels, listNumberFormat, paragraphCount, paragraphIndexAt, paragraphSpacingAt, paragraphStyleAt, paragraphStylesAfterEdit, paragraphStylesAfterTextChange, paragraphStylesInRange, paragraphStylesWithoutSpacing, percentLength, pixelLength, remapStyleRunReferences, scaledTextLength, sharedParagraphSpacing, styleRunReferences, textAutoResizeFields, textLengthPixels, textLengthSchema, textLinesReach, textListItems, textParagraphRanges, textVerticalOffset, topLevelNumberDigits, trimParagraphStyles, withIndentation, withListType, withParagraphSpacing };
@@ -11,6 +11,11 @@ declare function lineHeightPixels(lineHeight: TextLength | null, fontSize: numbe
11
11
  * as it is, a percent one to whole pixels (Figma desktop 126); null when it is automatic.
12
12
  */
13
13
  declare function lineStepPixels(lineHeight: TextLength | null, fontSize: number): number | null;
14
+ /**
15
+ * How far apart lines step where no font metrics measure them: as `lineStepPixels` steps them,
16
+ * and 1.2 times the font size when automatic.
17
+ */
18
+ declare function estimatedLineStep(lineHeight: TextLength | null, fontSize: number): number;
14
19
  /** A length in pixels, as a bound number variable and most authored formats give one. */
15
20
  declare function pixelLength(value: number): TextLength;
16
21
  /** A length as a percent of the font size. */
@@ -20,5 +25,5 @@ declare function scaledTextLength(length: TextLength, factor: number): TextLengt
20
25
  /** `length` as people read it: `24px` or `150%`. */
21
26
  declare function formatTextLength(length: TextLength): string;
22
27
  //#endregion
23
- export { NO_LETTER_SPACING, formatTextLength, lineHeightPixels, lineStepPixels, percentLength, pixelLength, scaledTextLength, textLengthPixels };
28
+ export { NO_LETTER_SPACING, estimatedLineStep, formatTextLength, lineHeightPixels, lineStepPixels, percentLength, pixelLength, scaledTextLength, textLengthPixels };
24
29
  //# sourceMappingURL=lengths.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"lengths.d.ts","names":[],"sources":["../../src/text/lengths.ts"],"mappings":";;;cAGa,mBAAmB;;iBAGhB,iBAAiB,QAAQ,YAAY;;iBAKrC,iBAAiB,YAAY,mBAAmB;;;;;iBAQhD,eAAe,YAAY,mBAAmB;;iBAO9C,YAAY,gBAAgB;;iBAK5B,cAAc,gBAAgB;;iBAK9B,iBAAiB,QAAQ,YAAY,iBAAiB;;iBAKtD,iBAAiB,QAAQ"}
1
+ {"version":3,"file":"lengths.d.ts","names":[],"sources":["../../src/text/lengths.ts"],"mappings":";;;cAGa,mBAAmB;;iBAGhB,iBAAiB,QAAQ,YAAY;;iBAKrC,iBAAiB,YAAY,mBAAmB;;;;;iBAQhD,eAAe,YAAY,mBAAmB;;;;;iBAa9C,kBAAkB,YAAY,mBAAmB;;iBAKjD,YAAY,gBAAgB;;iBAK5B,cAAc,gBAAgB;;iBAK9B,iBAAiB,QAAQ,YAAY,iBAAiB;;iBAKtD,iBAAiB,QAAQ"}
@@ -21,6 +21,15 @@ function lineStepPixels(lineHeight, fontSize) {
21
21
  const pixels = textLengthPixels(lineHeight, fontSize);
22
22
  return lineHeight.unit === "PIXELS" ? pixels : Math.round(pixels);
23
23
  }
24
+ /** How far an automatic line height steps lines when no font metrics measure them. */
25
+ const ESTIMATED_LINE_STEP = 1.2;
26
+ /**
27
+ * How far apart lines step where no font metrics measure them: as `lineStepPixels` steps them,
28
+ * and 1.2 times the font size when automatic.
29
+ */
30
+ function estimatedLineStep(lineHeight, fontSize) {
31
+ return lineStepPixels(lineHeight, fontSize) ?? fontSize * ESTIMATED_LINE_STEP;
32
+ }
24
33
  /** A length in pixels, as a bound number variable and most authored formats give one. */
25
34
  function pixelLength(value) {
26
35
  return {
@@ -44,6 +53,6 @@ function formatTextLength(length) {
44
53
  return length.unit === "PIXELS" ? `${length.value}px` : `${length.value}%`;
45
54
  }
46
55
  //#endregion
47
- export { NO_LETTER_SPACING, formatTextLength, lineHeightPixels, lineStepPixels, percentLength, pixelLength, scaledTextLength, textLengthPixels };
56
+ export { NO_LETTER_SPACING, estimatedLineStep, formatTextLength, lineHeightPixels, lineStepPixels, percentLength, pixelLength, scaledTextLength, textLengthPixels };
48
57
 
49
58
  //# sourceMappingURL=lengths.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"lengths.js","names":[],"sources":["../../src/text/lengths.ts"],"sourcesContent":["import type { TextLength } from '../types'\n\n/** No letter spacing, as a new text has it and as Figma writes it. */\nexport const NO_LETTER_SPACING: TextLength = { value: 0, unit: 'PERCENT' }\n\n/** `length` in pixels at `fontSize`. */\nexport function textLengthPixels(length: TextLength, fontSize: number): number {\n return length.unit === 'PIXELS' ? length.value : (length.value / 100) * fontSize\n}\n\n/** A line height in pixels at `fontSize`, or null when it is automatic. */\nexport function lineHeightPixels(lineHeight: TextLength | null, fontSize: number): number | null {\n return lineHeight ? textLengthPixels(lineHeight, fontSize) : null\n}\n\n/**\n * How far apart a line height sets lines at `fontSize`, as Figma steps them: a height in pixels\n * as it is, a percent one to whole pixels (Figma desktop 126); null when it is automatic.\n */\nexport function lineStepPixels(lineHeight: TextLength | null, fontSize: number): number | null {\n if (!lineHeight) return null\n const pixels = textLengthPixels(lineHeight, fontSize)\n return lineHeight.unit === 'PIXELS' ? pixels : Math.round(pixels)\n}\n\n/** A length in pixels, as a bound number variable and most authored formats give one. */\nexport function pixelLength(value: number): TextLength {\n return { value, unit: 'PIXELS' }\n}\n\n/** A length as a percent of the font size. */\nexport function percentLength(value: number): TextLength {\n return { value, unit: 'PERCENT' }\n}\n\n/** `length` scaled by `factor`: pixels scale, a percent already follows the font size. */\nexport function scaledTextLength(length: TextLength, factor: number): TextLength {\n return length.unit === 'PIXELS' ? pixelLength(length.value * factor) : length\n}\n\n/** `length` as people read it: `24px` or `150%`. */\nexport function formatTextLength(length: TextLength): string {\n return length.unit === 'PIXELS' ? `${length.value}px` : `${length.value}%`\n}\n"],"mappings":";;AAGA,MAAa,oBAAgC;CAAE,OAAO;CAAG,MAAM;AAAU;;AAGzE,SAAgB,iBAAiB,QAAoB,UAA0B;CAC7E,OAAO,OAAO,SAAS,WAAW,OAAO,QAAS,OAAO,QAAQ,MAAO;AAC1E;;AAGA,SAAgB,iBAAiB,YAA+B,UAAiC;CAC/F,OAAO,aAAa,iBAAiB,YAAY,QAAQ,IAAI;AAC/D;;;;;AAMA,SAAgB,eAAe,YAA+B,UAAiC;CAC7F,IAAI,CAAC,YAAY,OAAO;CACxB,MAAM,SAAS,iBAAiB,YAAY,QAAQ;CACpD,OAAO,WAAW,SAAS,WAAW,SAAS,KAAK,MAAM,MAAM;AAClE;;AAGA,SAAgB,YAAY,OAA2B;CACrD,OAAO;EAAE;EAAO,MAAM;CAAS;AACjC;;AAGA,SAAgB,cAAc,OAA2B;CACvD,OAAO;EAAE;EAAO,MAAM;CAAU;AAClC;;AAGA,SAAgB,iBAAiB,QAAoB,QAA4B;CAC/E,OAAO,OAAO,SAAS,WAAW,YAAY,OAAO,QAAQ,MAAM,IAAI;AACzE;;AAGA,SAAgB,iBAAiB,QAA4B;CAC3D,OAAO,OAAO,SAAS,WAAW,GAAG,OAAO,MAAM,MAAM,GAAG,OAAO,MAAM;AAC1E"}
1
+ {"version":3,"file":"lengths.js","names":[],"sources":["../../src/text/lengths.ts"],"sourcesContent":["import type { TextLength } from '../types'\n\n/** No letter spacing, as a new text has it and as Figma writes it. */\nexport const NO_LETTER_SPACING: TextLength = { value: 0, unit: 'PERCENT' }\n\n/** `length` in pixels at `fontSize`. */\nexport function textLengthPixels(length: TextLength, fontSize: number): number {\n return length.unit === 'PIXELS' ? length.value : (length.value / 100) * fontSize\n}\n\n/** A line height in pixels at `fontSize`, or null when it is automatic. */\nexport function lineHeightPixels(lineHeight: TextLength | null, fontSize: number): number | null {\n return lineHeight ? textLengthPixels(lineHeight, fontSize) : null\n}\n\n/**\n * How far apart a line height sets lines at `fontSize`, as Figma steps them: a height in pixels\n * as it is, a percent one to whole pixels (Figma desktop 126); null when it is automatic.\n */\nexport function lineStepPixels(lineHeight: TextLength | null, fontSize: number): number | null {\n if (!lineHeight) return null\n const pixels = textLengthPixels(lineHeight, fontSize)\n return lineHeight.unit === 'PIXELS' ? pixels : Math.round(pixels)\n}\n\n/** How far an automatic line height steps lines when no font metrics measure them. */\nconst ESTIMATED_LINE_STEP = 1.2\n\n/**\n * How far apart lines step where no font metrics measure them: as `lineStepPixels` steps them,\n * and 1.2 times the font size when automatic.\n */\nexport function estimatedLineStep(lineHeight: TextLength | null, fontSize: number): number {\n return lineStepPixels(lineHeight, fontSize) ?? fontSize * ESTIMATED_LINE_STEP\n}\n\n/** A length in pixels, as a bound number variable and most authored formats give one. */\nexport function pixelLength(value: number): TextLength {\n return { value, unit: 'PIXELS' }\n}\n\n/** A length as a percent of the font size. */\nexport function percentLength(value: number): TextLength {\n return { value, unit: 'PERCENT' }\n}\n\n/** `length` scaled by `factor`: pixels scale, a percent already follows the font size. */\nexport function scaledTextLength(length: TextLength, factor: number): TextLength {\n return length.unit === 'PIXELS' ? pixelLength(length.value * factor) : length\n}\n\n/** `length` as people read it: `24px` or `150%`. */\nexport function formatTextLength(length: TextLength): string {\n return length.unit === 'PIXELS' ? `${length.value}px` : `${length.value}%`\n}\n"],"mappings":";;AAGA,MAAa,oBAAgC;CAAE,OAAO;CAAG,MAAM;AAAU;;AAGzE,SAAgB,iBAAiB,QAAoB,UAA0B;CAC7E,OAAO,OAAO,SAAS,WAAW,OAAO,QAAS,OAAO,QAAQ,MAAO;AAC1E;;AAGA,SAAgB,iBAAiB,YAA+B,UAAiC;CAC/F,OAAO,aAAa,iBAAiB,YAAY,QAAQ,IAAI;AAC/D;;;;;AAMA,SAAgB,eAAe,YAA+B,UAAiC;CAC7F,IAAI,CAAC,YAAY,OAAO;CACxB,MAAM,SAAS,iBAAiB,YAAY,QAAQ;CACpD,OAAO,WAAW,SAAS,WAAW,SAAS,KAAK,MAAM,MAAM;AAClE;;AAGA,MAAM,sBAAsB;;;;;AAM5B,SAAgB,kBAAkB,YAA+B,UAA0B;CACzF,OAAO,eAAe,YAAY,QAAQ,KAAK,WAAW;AAC5D;;AAGA,SAAgB,YAAY,OAA2B;CACrD,OAAO;EAAE;EAAO,MAAM;CAAS;AACjC;;AAGA,SAAgB,cAAc,OAA2B;CACvD,OAAO;EAAE;EAAO,MAAM;CAAU;AAClC;;AAGA,SAAgB,iBAAiB,QAAoB,QAA4B;CAC/E,OAAO,OAAO,SAAS,WAAW,YAAY,OAAO,QAAQ,MAAM,IAAI;AACzE;;AAGA,SAAgB,iBAAiB,QAA4B;CAC3D,OAAO,OAAO,SAAS,WAAW,GAAG,OAAO,MAAM,MAAM,GAAG,OAAO,MAAM;AAC1E"}
@@ -1,11 +1,20 @@
1
1
  import { SceneNode } from "../types.js";
2
+ import { VisualBounds } from "../geometry.js";
2
3
  //#region src/text/overflow.d.ts
3
- type TextBoundsNode = Pick<SceneNode, 'type' | 'height' | 'derivedTextHeight'>;
4
+ type TextBoxNode = Pick<SceneNode, 'height' | 'textAlignVertical'>;
5
+ type TextBoundsNode = TextBoxNode & Pick<SceneNode, 'type' | 'derivedTextHeight'>;
6
+ type TextLinesReach = Pick<VisualBounds, 'minY' | 'maxY'>;
4
7
  /**
5
- * How far a text's lines reach below its box: a fixed-size box does not clip them, as in Figma,
6
- * and the renderer starts them at its top.
8
+ * Where the top of laid-out lines `contentHeight` tall sits in a text's box, by its vertical
9
+ * alignment. Lines taller than the box overflow on the side away from the alignment, as Figma
10
+ * lays them out.
7
11
  */
8
- declare function textLinesOverflow(node: TextBoundsNode): number;
12
+ declare function textVerticalOffset(node: TextBoxNode, contentHeight: number): number;
13
+ /**
14
+ * The rows a text draws its lines over, in its own axes: its box, grown by the lines a fixed-size
15
+ * box lets run past it above or below, as in Figma.
16
+ */
17
+ declare function textLinesReach(node: TextBoundsNode): TextLinesReach;
9
18
  //#endregion
10
- export { textLinesOverflow };
19
+ export { TextLinesReach, textLinesReach, textVerticalOffset };
11
20
  //# sourceMappingURL=overflow.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"overflow.d.ts","names":[],"sources":["../../src/text/overflow.ts"],"mappings":";;KAEK,iBAAiB,KAAK;;;;;iBAMX,kBAAkB,MAAM"}
1
+ {"version":3,"file":"overflow.d.ts","names":[],"sources":["../../src/text/overflow.ts"],"mappings":";;;KAGK,cAAc,KAAK;KACnB,iBAAiB,cAAc,KAAK;KAE7B,iBAAiB,KAAK;;;;;;iBAOlB,mBAAmB,MAAM,aAAa;;;;;iBAetC,eAAe,MAAM,iBAAiB"}
@@ -1,13 +1,31 @@
1
1
  //#region src/text/overflow.ts
2
2
  /**
3
- * How far a text's lines reach below its box: a fixed-size box does not clip them, as in Figma,
4
- * and the renderer starts them at its top.
3
+ * Where the top of laid-out lines `contentHeight` tall sits in a text's box, by its vertical
4
+ * alignment. Lines taller than the box overflow on the side away from the alignment, as Figma
5
+ * lays them out.
5
6
  */
6
- function textLinesOverflow(node) {
7
- if (node.type !== "TEXT" || !node.derivedTextHeight) return 0;
8
- return Math.max(0, node.derivedTextHeight - node.height);
7
+ function textVerticalOffset(node, contentHeight) {
8
+ const available = node.height - contentHeight;
9
+ if (node.textAlignVertical === "CENTER") return available / 2;
10
+ if (node.textAlignVertical === "BOTTOM") return available;
11
+ return 0;
12
+ }
13
+ /**
14
+ * The rows a text draws its lines over, in its own axes: its box, grown by the lines a fixed-size
15
+ * box lets run past it above or below, as in Figma.
16
+ */
17
+ function textLinesReach(node) {
18
+ if (node.type !== "TEXT" || !node.derivedTextHeight) return {
19
+ minY: 0,
20
+ maxY: node.height
21
+ };
22
+ const linesTop = textVerticalOffset(node, node.derivedTextHeight);
23
+ return {
24
+ minY: Math.min(0, linesTop),
25
+ maxY: Math.max(node.height, linesTop + node.derivedTextHeight)
26
+ };
9
27
  }
10
28
  //#endregion
11
- export { textLinesOverflow };
29
+ export { textLinesReach, textVerticalOffset };
12
30
 
13
31
  //# sourceMappingURL=overflow.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"overflow.js","names":[],"sources":["../../src/text/overflow.ts"],"sourcesContent":["import type { SceneNode } from '../types'\n\ntype TextBoundsNode = Pick<SceneNode, 'type' | 'height' | 'derivedTextHeight'>\n\n/**\n * How far a text's lines reach below its box: a fixed-size box does not clip them, as in Figma,\n * and the renderer starts them at its top.\n */\nexport function textLinesOverflow(node: TextBoundsNode): number {\n if (node.type !== 'TEXT' || !node.derivedTextHeight) return 0\n return Math.max(0, node.derivedTextHeight - node.height)\n}\n"],"mappings":";;;;;AAQA,SAAgB,kBAAkB,MAA8B;CAC9D,IAAI,KAAK,SAAS,UAAU,CAAC,KAAK,mBAAmB,OAAO;CAC5D,OAAO,KAAK,IAAI,GAAG,KAAK,oBAAoB,KAAK,MAAM;AACzD"}
1
+ {"version":3,"file":"overflow.js","names":[],"sources":["../../src/text/overflow.ts"],"sourcesContent":["import type { VisualBounds } from '../geometry'\nimport type { SceneNode } from '../types'\n\ntype TextBoxNode = Pick<SceneNode, 'height' | 'textAlignVertical'>\ntype TextBoundsNode = TextBoxNode & Pick<SceneNode, 'type' | 'derivedTextHeight'>\n\nexport type TextLinesReach = Pick<VisualBounds, 'minY' | 'maxY'>\n\n/**\n * Where the top of laid-out lines `contentHeight` tall sits in a text's box, by its vertical\n * alignment. Lines taller than the box overflow on the side away from the alignment, as Figma\n * lays them out.\n */\nexport function textVerticalOffset(node: TextBoxNode, contentHeight: number): number {\n const available = node.height - contentHeight\n if (node.textAlignVertical === 'CENTER') {\n return available / 2\n }\n if (node.textAlignVertical === 'BOTTOM') {\n return available\n }\n return 0\n}\n\n/**\n * The rows a text draws its lines over, in its own axes: its box, grown by the lines a fixed-size\n * box lets run past it above or below, as in Figma.\n */\nexport function textLinesReach(node: TextBoundsNode): TextLinesReach {\n if (node.type !== 'TEXT' || !node.derivedTextHeight) {\n return { minY: 0, maxY: node.height }\n }\n const linesTop = textVerticalOffset(node, node.derivedTextHeight)\n return {\n minY: Math.min(0, linesTop),\n maxY: Math.max(node.height, linesTop + node.derivedTextHeight)\n }\n}\n"],"mappings":";;;;;;AAaA,SAAgB,mBAAmB,MAAmB,eAA+B;CACnF,MAAM,YAAY,KAAK,SAAS;CAChC,IAAI,KAAK,sBAAsB,UAC7B,OAAO,YAAY;CAErB,IAAI,KAAK,sBAAsB,UAC7B,OAAO;CAET,OAAO;AACT;;;;;AAMA,SAAgB,eAAe,MAAsC;CACnE,IAAI,KAAK,SAAS,UAAU,CAAC,KAAK,mBAChC,OAAO;EAAE,MAAM;EAAG,MAAM,KAAK;CAAO;CAEtC,MAAM,WAAW,mBAAmB,MAAM,KAAK,iBAAiB;CAChE,OAAO;EACL,MAAM,KAAK,IAAI,GAAG,QAAQ;EAC1B,MAAM,KAAK,IAAI,KAAK,QAAQ,WAAW,KAAK,iBAAiB;CAC/D;AACF"}
@@ -0,0 +1,10 @@
1
+ //#region src/text/path.ts
2
+ function followsPath(node) {
3
+ const glyphs = node.derivedTextGlyphs ?? [];
4
+ if (glyphs.length === 0) return false;
5
+ return !!node.textPathData || !!node.textPathBox || glyphs.some((glyph) => (glyph.rotation ?? 0) !== 0);
6
+ }
7
+ //#endregion
8
+ export { followsPath };
9
+
10
+ //# sourceMappingURL=path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path.js","names":[],"sources":["../../src/text/path.ts"],"sourcesContent":["import type { SceneNode } from '../types'\n\nexport function followsPath(\n node: Pick<SceneNode, 'derivedTextGlyphs' | 'textPathData' | 'textPathBox'>\n): boolean {\n const glyphs = node.derivedTextGlyphs ?? []\n if (glyphs.length === 0) {\n return false\n }\n return (\n !!node.textPathData || !!node.textPathBox || glyphs.some((glyph) => (glyph.rotation ?? 0) !== 0)\n )\n}\n"],"mappings":";AAEA,SAAgB,YACd,MACS;CACT,MAAM,SAAS,KAAK,qBAAqB,CAAC;CAC1C,IAAI,OAAO,WAAW,GACpB,OAAO;CAET,OACE,CAAC,CAAC,KAAK,gBAAgB,CAAC,CAAC,KAAK,eAAe,OAAO,MAAM,WAAW,MAAM,YAAY,OAAO,CAAC;AAEnG"}
@@ -24,11 +24,11 @@ function textCacheInvalidationChanges(node, changes) {
24
24
  if (node.textPicture && keys.some((key) => TEXT_PICTURE_KEYS.has(key))) invalidated.textPicture = null;
25
25
  const glyphsInvalidated = keys.some((key) => GLYPH_AFFECTING_KEYS.has(key)) || TEXT_LAYOUT_FIELDS.some((key) => keys.includes(key));
26
26
  if (glyphsInvalidated && !("derivedLayout" in changes)) invalidated.derivedLayout = null;
27
- if (node.derivedTextGlyphs && glyphsInvalidated && !changes.derivedTextGlyphs) {
28
- if (!(!!node.textPathData && keys.every((key) => key === "width" || key === "height"))) {
29
- invalidated.derivedTextGlyphs = null;
30
- invalidated.textPathData = null;
31
- }
27
+ if (glyphsInvalidated && !changes.derivedTextGlyphs) {
28
+ const onlyPathBoxResize = !!node.textPathData && keys.every((key) => key === "width" || key === "height");
29
+ const placesPath = keys.includes("textPathBox") && !!changes.textPathBox;
30
+ if (node.derivedTextGlyphs && !onlyPathBoxResize) invalidated.derivedTextGlyphs = null;
31
+ if (node.textPathData && !onlyPathBoxResize && !placesPath) invalidated.textPathData = null;
32
32
  }
33
33
  return invalidated;
34
34
  }
@@ -1 +1 @@
1
- {"version":3,"file":"picture.js","names":[],"sources":["../../src/text/picture.ts"],"sourcesContent":["import { isEqual } from 'es-toolkit/predicate'\n\nimport { TEXT_SHAPING_FIELDS, TEXT_LAYOUT_FIELDS } from '../fields/text'\nimport type { SceneNode } from '../types'\n\n/**\n * Invalidate cached Skia textPicture (Paragraph snapshot). Includes width/height\n * because wrapping/layout depends on the box.\n */\nexport const TEXT_PICTURE_KEYS: ReadonlySet<string> = new Set([\n ...TEXT_SHAPING_FIELDS,\n 'textDecoration',\n 'fills',\n 'width',\n 'height'\n])\n\nexport const GLYPH_AFFECTING_KEYS: ReadonlySet<string> = new Set(TEXT_SHAPING_FIELDS)\n\n/**\n * Shared by SceneGraph.updateNode and updateNodePreview (drag hot path) so the\n * two invalidation rules cannot drift. Glyphs are kept when the caller\n * replaces them in the same update (resize supplies scaled copies).\n */\nexport function textCacheInvalidationChanges(\n node: SceneNode,\n changes: Partial<SceneNode>\n): Partial<SceneNode> {\n const invalidated: Partial<SceneNode> = {}\n const keys = Object.keys(changes).filter(\n (key) => !isEqual(node[key as keyof SceneNode], changes[key as keyof SceneNode])\n )\n if (node.textPicture && keys.some((key) => TEXT_PICTURE_KEYS.has(key)))\n invalidated.textPicture = null\n const glyphsInvalidated =\n keys.some((key) => GLYPH_AFFECTING_KEYS.has(key)) ||\n TEXT_LAYOUT_FIELDS.some((key) => keys.includes(key))\n if (glyphsInvalidated && !('derivedLayout' in changes)) invalidated.derivedLayout = null\n // A successful path-text edit supplies reflowed glyphs in `changes`. Every\n // other mutation path must drop stale baked glyphs and path identity rather\n // than pair new text/style with old visible outlines.\n if (node.derivedTextGlyphs && glyphsInvalidated && !changes.derivedTextGlyphs) {\n // Path-text resize supplies transformed glyphs through the resize workflow. A raw box\n // preview keeps them until that workflow commits or an actual shaping edit occurs.\n const onlyPathBoxResize =\n !!node.textPathData && keys.every((key) => key === 'width' || key === 'height')\n if (!onlyPathBoxResize) {\n invalidated.derivedTextGlyphs = null\n invalidated.textPathData = null\n }\n }\n return invalidated\n}\n"],"mappings":";;;;;;;AASA,MAAa,oCAAyC,IAAI,IAAI;CAC5D,GAAG;CACH;CACA;CACA;CACA;AACF,CAAC;AAED,MAAa,uBAA4C,IAAI,IAAI,mBAAmB;;;;;;AAOpF,SAAgB,6BACd,MACA,SACoB;CACpB,MAAM,cAAkC,CAAC;CACzC,MAAM,OAAO,OAAO,KAAK,OAAO,CAAC,CAAC,QAC/B,QAAQ,CAAC,QAAQ,KAAK,MAAyB,QAAQ,IAAuB,CACjF;CACA,IAAI,KAAK,eAAe,KAAK,MAAM,QAAQ,kBAAkB,IAAI,GAAG,CAAC,GACnE,YAAY,cAAc;CAC5B,MAAM,oBACJ,KAAK,MAAM,QAAQ,qBAAqB,IAAI,GAAG,CAAC,KAChD,mBAAmB,MAAM,QAAQ,KAAK,SAAS,GAAG,CAAC;CACrD,IAAI,qBAAqB,EAAE,mBAAmB,UAAU,YAAY,gBAAgB;CAIpF,IAAI,KAAK,qBAAqB,qBAAqB,CAAC,QAAQ,mBAKtD;MAAA,EADF,CAAC,CAAC,KAAK,gBAAgB,KAAK,OAAO,QAAQ,QAAQ,WAAW,QAAQ,QAAQ,IACxD;GACtB,YAAY,oBAAoB;GAChC,YAAY,eAAe;EAC7B;;CAEF,OAAO;AACT"}
1
+ {"version":3,"file":"picture.js","names":[],"sources":["../../src/text/picture.ts"],"sourcesContent":["import { isEqual } from 'es-toolkit/predicate'\n\nimport { TEXT_SHAPING_FIELDS, TEXT_LAYOUT_FIELDS } from '../fields/text'\nimport type { SceneNode } from '../types'\n\n/**\n * Invalidate cached Skia textPicture (Paragraph snapshot). Includes width/height\n * because wrapping/layout depends on the box.\n */\nexport const TEXT_PICTURE_KEYS: ReadonlySet<string> = new Set([\n ...TEXT_SHAPING_FIELDS,\n 'textDecoration',\n 'fills',\n 'width',\n 'height'\n])\n\nexport const GLYPH_AFFECTING_KEYS: ReadonlySet<string> = new Set(TEXT_SHAPING_FIELDS)\n\n/**\n * Shared by SceneGraph.updateNode and updateNodePreview (drag hot path) so the\n * two invalidation rules cannot drift. Glyphs are kept when the caller\n * replaces them in the same update (resize supplies scaled copies).\n */\nexport function textCacheInvalidationChanges(\n node: SceneNode,\n changes: Partial<SceneNode>\n): Partial<SceneNode> {\n const invalidated: Partial<SceneNode> = {}\n const keys = Object.keys(changes).filter(\n (key) => !isEqual(node[key as keyof SceneNode], changes[key as keyof SceneNode])\n )\n if (node.textPicture && keys.some((key) => TEXT_PICTURE_KEYS.has(key)))\n invalidated.textPicture = null\n const glyphsInvalidated =\n keys.some((key) => GLYPH_AFFECTING_KEYS.has(key)) ||\n TEXT_LAYOUT_FIELDS.some((key) => keys.includes(key))\n if (glyphsInvalidated && !('derivedLayout' in changes)) invalidated.derivedLayout = null\n if (glyphsInvalidated && !changes.derivedTextGlyphs) {\n // Path-text resize supplies transformed glyphs through the resize workflow. A raw box\n // preview keeps them until that workflow commits or an actual shaping edit occurs.\n const onlyPathBoxResize =\n !!node.textPathData && keys.every((key) => key === 'width' || key === 'height')\n const placesPath = keys.includes('textPathBox') && !!changes.textPathBox\n if (node.derivedTextGlyphs && !onlyPathBoxResize) {\n invalidated.derivedTextGlyphs = null\n }\n if (node.textPathData && !onlyPathBoxResize && !placesPath) {\n invalidated.textPathData = null\n }\n }\n return invalidated\n}\n"],"m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.d.ts","names":[],"sources":["../../src/transfer/dependencies.ts"],"mappings":";;;;UAWiB;;EAEf,WAAW;;;;;EAKX,aAAa;;EAEb,QAAQ;;EAER,QAAQ;;;iBAIM,iBAAiB,MAAM;;;;;iBAgBvB,iBAAiB,MAAM;;;;;;iBAkBvB,kBACd,OAAO,YACP,QAAQ,SAAS,aAChB;;;;;iBA8Ba,qBACd,OAAO,YACP,KAAK,mBACJ,KAAK"}
@@ -1,4 +1,5 @@
1
1
  import { overriddenBindingField } from "../instances/overrides.js";
2
+ import { appendAll } from "../arrays.js";
2
3
  import { isUnsupportedVariableValue, variableValueReferences } from "../variables/value.js";
3
4
  import { styleRunReferences } from "../text/references.js";
4
5
  import { referencedStyleIds, sharedStyleLayers } from "../shared-styles.js";
@@ -42,7 +43,7 @@ function layerDependencies(graph, layers) {
42
43
  const styleLayer = (id) => (styleLayers ??= sharedStyleLayers(graph)).get(id);
43
44
  const visit = (node) => {
44
45
  for (const hash of layerImageHashes(node)) images.add(hash);
45
- pending.push(...layerVariableIds(node));
46
+ appendAll(pending, layerVariableIds(node));
46
47
  for (const id of Object.keys(node.variableModes)) if (graph.variableCollections.has(id)) collections.add(id);
47
48
  for (const id of referencedStyleIds(node)) {
48
49
  const style = styles.has(id) ? void 0 : styleLayer(id);
@@ -81,7 +82,7 @@ function variableDependencies(graph, ids) {
81
82
  variables.add(id);
82
83
  collections.add(variable.collectionId);
83
84
  for (const value of Object.values(variable.valuesByMode)) {
84
- pending.push(...variableValueReferences(value));
85
+ appendAll(pending, variableValueReferences(value));
85
86
  if (!isUnsupportedVariableValue(value)) continue;
86
87
  for (const modeId of value.modes) {
87
88
  const collection = collectionOfMode(modeId);