@moondraft/import 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (323) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/LICENSE +34 -0
  3. package/README.md +36 -2
  4. package/SOURCE.md +169 -0
  5. package/dist/adapter/convert.d.ts +122 -0
  6. package/dist/adapter/convert.js +2302 -0
  7. package/dist/adapter/figma.d.ts +9 -0
  8. package/dist/adapter/figma.js +30 -0
  9. package/dist/adapter/file-components.d.ts +14 -0
  10. package/dist/adapter/file-components.js +262 -0
  11. package/dist/adapter/file-resources.d.ts +29 -0
  12. package/dist/adapter/file-resources.js +562 -0
  13. package/dist/adapter/index.d.ts +6 -0
  14. package/dist/adapter/index.js +9 -0
  15. package/dist/adapter/link.d.ts +45 -0
  16. package/dist/adapter/link.js +688 -0
  17. package/dist/adapter/payload.d.ts +31 -0
  18. package/dist/adapter/payload.js +78 -0
  19. package/dist/adapter/shapes.d.ts +31 -0
  20. package/dist/adapter/shapes.js +75 -0
  21. package/dist/adapter/variables.d.ts +44 -0
  22. package/dist/adapter/variables.js +103 -0
  23. package/dist/figma-file.d.ts +38 -0
  24. package/dist/figma-file.js +97 -0
  25. package/dist/figma-worker.d.ts +11 -0
  26. package/dist/figma-worker.js +12 -0
  27. package/dist/figma.d.ts +26 -0
  28. package/dist/figma.js +96 -0
  29. package/dist/index.d.ts +28 -0
  30. package/dist/index.js +49 -0
  31. package/dist/report.d.ts +15 -0
  32. package/dist/report.js +69 -0
  33. package/dist/svg.d.ts +33 -0
  34. package/dist/svg.js +44 -0
  35. package/dist/syntax.d.ts +8 -0
  36. package/dist/syntax.js +19 -0
  37. package/dist/taco/figma-import/clipboard.d.ts +25 -0
  38. package/dist/taco/figma-import/clipboard.js +87 -0
  39. package/dist/taco/figma-import/clipboardSize.d.ts +31 -0
  40. package/dist/taco/figma-import/clipboardSize.js +107 -0
  41. package/dist/taco/figma-import/container/compression.d.ts +9 -0
  42. package/dist/taco/figma-import/container/compression.js +174 -0
  43. package/dist/taco/figma-import/container/error.d.ts +15 -0
  44. package/dist/taco/figma-import/container/error.js +19 -0
  45. package/dist/taco/figma-import/container/kiwiContainer.d.ts +38 -0
  46. package/dist/taco/figma-import/container/kiwiContainer.js +61 -0
  47. package/dist/taco/figma-import/container/limits.d.ts +22 -0
  48. package/dist/taco/figma-import/container/limits.js +22 -0
  49. package/dist/taco/figma-import/container/zip.d.ts +14 -0
  50. package/dist/taco/figma-import/container/zip.js +154 -0
  51. package/dist/taco/figma-import/figFile.d.ts +34 -0
  52. package/dist/taco/figma-import/figFile.js +91 -0
  53. package/dist/taco/figma-import/figFileDocument.d.ts +25 -0
  54. package/dist/taco/figma-import/figFileDocument.js +100 -0
  55. package/dist/taco/figma-import/import/blobs.d.ts +10 -0
  56. package/dist/taco/figma-import/import/blobs.js +23 -0
  57. package/dist/taco/figma-import/import/carry.d.ts +11 -0
  58. package/dist/taco/figma-import/import/carry.js +33 -0
  59. package/dist/taco/figma-import/import/componentProps.d.ts +84 -0
  60. package/dist/taco/figma-import/import/componentProps.js +313 -0
  61. package/dist/taco/figma-import/import/componentSets.d.ts +83 -0
  62. package/dist/taco/figma-import/import/componentSets.js +647 -0
  63. package/dist/taco/figma-import/import/converters/effects.d.ts +31 -0
  64. package/dist/taco/figma-import/import/converters/effects.js +127 -0
  65. package/dist/taco/figma-import/import/converters/ellipse.d.ts +7 -0
  66. package/dist/taco/figma-import/import/converters/ellipse.js +54 -0
  67. package/dist/taco/figma-import/import/converters/frame.d.ts +21 -0
  68. package/dist/taco/figma-import/import/converters/frame.js +55 -0
  69. package/dist/taco/figma-import/import/converters/gradient.d.ts +72 -0
  70. package/dist/taco/figma-import/import/converters/gradient.js +106 -0
  71. package/dist/taco/figma-import/import/converters/group.d.ts +21 -0
  72. package/dist/taco/figma-import/import/converters/group.js +39 -0
  73. package/dist/taco/figma-import/import/converters/image.d.ts +13 -0
  74. package/dist/taco/figma-import/import/converters/image.js +83 -0
  75. package/dist/taco/figma-import/import/converters/layout.d.ts +34 -0
  76. package/dist/taco/figma-import/import/converters/layout.js +168 -0
  77. package/dist/taco/figma-import/import/converters/line.d.ts +11 -0
  78. package/dist/taco/figma-import/import/converters/line.js +40 -0
  79. package/dist/taco/figma-import/import/converters/rectangle.d.ts +3 -0
  80. package/dist/taco/figma-import/import/converters/rectangle.js +11 -0
  81. package/dist/taco/figma-import/import/converters/section.d.ts +9 -0
  82. package/dist/taco/figma-import/import/converters/section.js +35 -0
  83. package/dist/taco/figma-import/import/converters/shared.d.ts +68 -0
  84. package/dist/taco/figma-import/import/converters/shared.js +362 -0
  85. package/dist/taco/figma-import/import/converters/text.d.ts +41 -0
  86. package/dist/taco/figma-import/import/converters/text.js +576 -0
  87. package/dist/taco/figma-import/import/converters/vector.d.ts +84 -0
  88. package/dist/taco/figma-import/import/converters/vector.js +468 -0
  89. package/dist/taco/figma-import/import/converters/vectorNetwork.d.ts +98 -0
  90. package/dist/taco/figma-import/import/converters/vectorNetwork.js +385 -0
  91. package/dist/taco/figma-import/import/fields.d.ts +15 -0
  92. package/dist/taco/figma-import/import/fields.js +29 -0
  93. package/dist/taco/figma-import/import/instances.d.ts +163 -0
  94. package/dist/taco/figma-import/import/instances.js +1323 -0
  95. package/dist/taco/figma-import/import/nestingCycles.d.ts +86 -0
  96. package/dist/taco/figma-import/import/nestingCycles.js +488 -0
  97. package/dist/taco/figma-import/import/slots.d.ts +56 -0
  98. package/dist/taco/figma-import/import/slots.js +96 -0
  99. package/dist/taco/figma-import/import/styles.d.ts +46 -0
  100. package/dist/taco/figma-import/import/styles.js +42 -0
  101. package/dist/taco/figma-import/import/tree.d.ts +66 -0
  102. package/dist/taco/figma-import/import/tree.js +194 -0
  103. package/dist/taco/figma-import/import/types.d.ts +232 -0
  104. package/dist/taco/figma-import/import/types.js +33 -0
  105. package/dist/taco/figma-import/import/variables.d.ts +136 -0
  106. package/dist/taco/figma-import/import/variables.js +762 -0
  107. package/dist/taco/figma-import/import/variantTrees.d.ts +20 -0
  108. package/dist/taco/figma-import/import/variantTrees.js +480 -0
  109. package/dist/taco/figma-import/import/walk.d.ts +159 -0
  110. package/dist/taco/figma-import/import/walk.js +1297 -0
  111. package/dist/taco/figma-import/index.d.ts +22 -0
  112. package/dist/taco/figma-import/index.js +13 -0
  113. package/dist/taco/figma-import/kiwi/byteReader.d.ts +37 -0
  114. package/dist/taco/figma-import/kiwi/byteReader.js +151 -0
  115. package/dist/taco/figma-import/kiwi/error.d.ts +14 -0
  116. package/dist/taco/figma-import/kiwi/error.js +29 -0
  117. package/dist/taco/figma-import/kiwi/limits.d.ts +18 -0
  118. package/dist/taco/figma-import/kiwi/limits.js +18 -0
  119. package/dist/taco/figma-import/kiwi/message.d.ts +10 -0
  120. package/dist/taco/figma-import/kiwi/message.js +145 -0
  121. package/dist/taco/figma-import/kiwi/schema.d.ts +42 -0
  122. package/dist/taco/figma-import/kiwi/schema.js +206 -0
  123. package/dist/taco/figma-import/kiwi/types.d.ts +46 -0
  124. package/dist/taco/figma-import/kiwi/types.js +18 -0
  125. package/dist/taco/model/agent-hidden-fields.d.ts +20 -0
  126. package/dist/taco/model/agent-hidden-fields.js +29 -0
  127. package/dist/taco/model/asset-users.d.ts +23 -0
  128. package/dist/taco/model/asset-users.js +128 -0
  129. package/dist/taco/model/auto-layout-lines.d.ts +32 -0
  130. package/dist/taco/model/auto-layout-lines.js +70 -0
  131. package/dist/taco/model/codec.d.ts +444 -0
  132. package/dist/taco/model/codec.js +5635 -0
  133. package/dist/taco/model/color.d.ts +11 -0
  134. package/dist/taco/model/color.js +61 -0
  135. package/dist/taco/model/comment-operations.d.ts +102 -0
  136. package/dist/taco/model/comment-operations.js +227 -0
  137. package/dist/taco/model/component-evaluation.d.ts +94 -0
  138. package/dist/taco/model/component-evaluation.js +548 -0
  139. package/dist/taco/model/component-expressions.d.ts +242 -0
  140. package/dist/taco/model/component-expressions.js +1082 -0
  141. package/dist/taco/model/component-properties.d.ts +111 -0
  142. package/dist/taco/model/component-properties.js +339 -0
  143. package/dist/taco/model/component-samples.d.ts +83 -0
  144. package/dist/taco/model/component-samples.js +290 -0
  145. package/dist/taco/model/component-validity.d.ts +85 -0
  146. package/dist/taco/model/component-validity.js +397 -0
  147. package/dist/taco/model/components.d.ts +155 -0
  148. package/dist/taco/model/components.js +505 -0
  149. package/dist/taco/model/connector-ends.d.ts +20 -0
  150. package/dist/taco/model/connector-ends.js +188 -0
  151. package/dist/taco/model/connector-geometry.d.ts +74 -0
  152. package/dist/taco/model/connector-geometry.js +293 -0
  153. package/dist/taco/model/corner-radii.d.ts +26 -0
  154. package/dist/taco/model/corner-radii.js +47 -0
  155. package/dist/taco/model/derivations.d.ts +81 -0
  156. package/dist/taco/model/derivations.js +151 -0
  157. package/dist/taco/model/export-settings.d.ts +53 -0
  158. package/dist/taco/model/export-settings.js +156 -0
  159. package/dist/taco/model/expressions/ast.d.ts +153 -0
  160. package/dist/taco/model/expressions/ast.js +6 -0
  161. package/dist/taco/model/expressions/cache.d.ts +23 -0
  162. package/dist/taco/model/expressions/cache.js +43 -0
  163. package/dist/taco/model/expressions/check.d.ts +72 -0
  164. package/dist/taco/model/expressions/check.js +517 -0
  165. package/dist/taco/model/expressions/completion.d.ts +61 -0
  166. package/dist/taco/model/expressions/completion.js +421 -0
  167. package/dist/taco/model/expressions/evaluate.d.ts +32 -0
  168. package/dist/taco/model/expressions/evaluate.js +519 -0
  169. package/dist/taco/model/expressions/forms.d.ts +84 -0
  170. package/dist/taco/model/expressions/forms.js +200 -0
  171. package/dist/taco/model/expressions/index.d.ts +14 -0
  172. package/dist/taco/model/expressions/index.js +17 -0
  173. package/dist/taco/model/expressions/lexer.d.ts +42 -0
  174. package/dist/taco/model/expressions/lexer.js +213 -0
  175. package/dist/taco/model/expressions/library.d.ts +33 -0
  176. package/dist/taco/model/expressions/library.js +117 -0
  177. package/dist/taco/model/expressions/names.d.ts +43 -0
  178. package/dist/taco/model/expressions/names.js +99 -0
  179. package/dist/taco/model/expressions/parser.d.ts +15 -0
  180. package/dist/taco/model/expressions/parser.js +438 -0
  181. package/dist/taco/model/expressions/rename.d.ts +34 -0
  182. package/dist/taco/model/expressions/rename.js +46 -0
  183. package/dist/taco/model/expressions/source.d.ts +15 -0
  184. package/dist/taco/model/expressions/source.js +161 -0
  185. package/dist/taco/model/expressions/types.d.ts +119 -0
  186. package/dist/taco/model/expressions/types.js +102 -0
  187. package/dist/taco/model/expressions/values.d.ts +97 -0
  188. package/dist/taco/model/expressions/values.js +160 -0
  189. package/dist/taco/model/geometry-limits.d.ts +16 -0
  190. package/dist/taco/model/geometry-limits.js +67 -0
  191. package/dist/taco/model/geometry.d.ts +47 -0
  192. package/dist/taco/model/geometry.js +193 -0
  193. package/dist/taco/model/group-bounds.d.ts +38 -0
  194. package/dist/taco/model/group-bounds.js +144 -0
  195. package/dist/taco/model/id-table.d.ts +37 -0
  196. package/dist/taco/model/id-table.js +80 -0
  197. package/dist/taco/model/index.d.ts +25 -0
  198. package/dist/taco/model/index.js +27 -0
  199. package/dist/taco/model/instance-resolver.d.ts +372 -0
  200. package/dist/taco/model/instance-resolver.js +1748 -0
  201. package/dist/taco/model/layer-syntax.d.ts +340 -0
  202. package/dist/taco/model/layer-syntax.js +3506 -0
  203. package/dist/taco/model/layout/constraints.d.ts +84 -0
  204. package/dist/taco/model/layout/constraints.js +445 -0
  205. package/dist/taco/model/layout/frame-layout.d.ts +46 -0
  206. package/dist/taco/model/layout/frame-layout.js +618 -0
  207. package/dist/taco/model/layout/node-sizing.d.ts +163 -0
  208. package/dist/taco/model/layout/node-sizing.js +486 -0
  209. package/dist/taco/model/legacy-connector-caps.d.ts +15 -0
  210. package/dist/taco/model/legacy-connector-caps.js +70 -0
  211. package/dist/taco/model/linear-call.d.ts +48 -0
  212. package/dist/taco/model/linear-call.js +58 -0
  213. package/dist/taco/model/new-nodes.d.ts +145 -0
  214. package/dist/taco/model/new-nodes.js +277 -0
  215. package/dist/taco/model/node-builder.d.ts +449 -0
  216. package/dist/taco/model/node-builder.js +2294 -0
  217. package/dist/taco/model/node-table-watch.d.ts +36 -0
  218. package/dist/taco/model/node-table-watch.js +63 -0
  219. package/dist/taco/model/node-transform.d.ts +39 -0
  220. package/dist/taco/model/node-transform.js +79 -0
  221. package/dist/taco/model/node-users-index.d.ts +10 -0
  222. package/dist/taco/model/node-users-index.js +82 -0
  223. package/dist/taco/model/operation-references.d.ts +80 -0
  224. package/dist/taco/model/operation-references.js +399 -0
  225. package/dist/taco/model/operations.d.ts +610 -0
  226. package/dist/taco/model/operations.js +2882 -0
  227. package/dist/taco/model/overlay-table.d.ts +71 -0
  228. package/dist/taco/model/overlay-table.js +171 -0
  229. package/dist/taco/model/override-remap.d.ts +69 -0
  230. package/dist/taco/model/override-remap.js +230 -0
  231. package/dist/taco/model/parent-table.d.ts +53 -0
  232. package/dist/taco/model/parent-table.js +193 -0
  233. package/dist/taco/model/problem-collector.d.ts +27 -0
  234. package/dist/taco/model/problem-collector.js +101 -0
  235. package/dist/taco/model/sha256.d.ts +10 -0
  236. package/dist/taco/model/sha256.js +74 -0
  237. package/dist/taco/model/shape-geometry.d.ts +96 -0
  238. package/dist/taco/model/shape-geometry.js +368 -0
  239. package/dist/taco/model/shared-node-table.d.ts +97 -0
  240. package/dist/taco/model/shared-node-table.js +546 -0
  241. package/dist/taco/model/slots.d.ts +113 -0
  242. package/dist/taco/model/slots.js +281 -0
  243. package/dist/taco/model/stroke-settings.d.ts +37 -0
  244. package/dist/taco/model/stroke-settings.js +90 -0
  245. package/dist/taco/model/svg-path-import.d.ts +89 -0
  246. package/dist/taco/model/svg-path-import.js +219 -0
  247. package/dist/taco/model/text-measurement.d.ts +142 -0
  248. package/dist/taco/model/text-measurement.js +846 -0
  249. package/dist/taco/model/text-reads.d.ts +66 -0
  250. package/dist/taco/model/text-reads.js +128 -0
  251. package/dist/taco/model/text-sizer.d.ts +358 -0
  252. package/dist/taco/model/text-sizer.js +996 -0
  253. package/dist/taco/model/theme-users.d.ts +59 -0
  254. package/dist/taco/model/theme-users.js +312 -0
  255. package/dist/taco/model/thumbnail.d.ts +15 -0
  256. package/dist/taco/model/thumbnail.js +34 -0
  257. package/dist/taco/model/types.d.ts +2347 -0
  258. package/dist/taco/model/types.js +366 -0
  259. package/dist/taco/model/unknown-property.d.ts +5 -0
  260. package/dist/taco/model/unknown-property.js +7 -0
  261. package/dist/taco/model/validated-documents.d.ts +22 -0
  262. package/dist/taco/model/validated-documents.js +22 -0
  263. package/dist/taco/model/variable-modes.d.ts +61 -0
  264. package/dist/taco/model/variable-modes.js +438 -0
  265. package/dist/taco/model/variable-references.d.ts +54 -0
  266. package/dist/taco/model/variable-references.js +183 -0
  267. package/dist/taco/model/variables.d.ts +24 -0
  268. package/dist/taco/model/variables.js +151 -0
  269. package/dist/taco/model/vector-network.d.ts +34 -0
  270. package/dist/taco/model/vector-network.js +411 -0
  271. package/dist/taco/svg-import/import-svg.d.ts +36 -0
  272. package/dist/taco/svg-import/import-svg.js +729 -0
  273. package/dist/taco/svg-import/index.d.ts +3 -0
  274. package/dist/taco/svg-import/index.js +3 -0
  275. package/dist/taco/svg-import/limits/limits.d.ts +79 -0
  276. package/dist/taco/svg-import/limits/limits.js +160 -0
  277. package/dist/taco/svg-import/paint/gradients.d.ts +64 -0
  278. package/dist/taco/svg-import/paint/gradients.js +429 -0
  279. package/dist/taco/svg-import/paint/paint.d.ts +32 -0
  280. package/dist/taco/svg-import/paint/paint.js +162 -0
  281. package/dist/taco/svg-import/paths/paths.d.ts +58 -0
  282. package/dist/taco/svg-import/paths/paths.js +205 -0
  283. package/dist/taco/svg-import/public-types.d.ts +279 -0
  284. package/dist/taco/svg-import/public-types.js +56 -0
  285. package/dist/taco/svg-import/report/report.d.ts +44 -0
  286. package/dist/taco/svg-import/report/report.js +79 -0
  287. package/dist/taco/svg-import/reuse/reuse.d.ts +99 -0
  288. package/dist/taco/svg-import/reuse/reuse.js +840 -0
  289. package/dist/taco/svg-import/shapes/shapes.d.ts +35 -0
  290. package/dist/taco/svg-import/shapes/shapes.js +386 -0
  291. package/dist/taco/svg-import/structure/effects.d.ts +26 -0
  292. package/dist/taco/svg-import/structure/effects.js +618 -0
  293. package/dist/taco/svg-import/structure/image.d.ts +24 -0
  294. package/dist/taco/svg-import/structure/image.js +495 -0
  295. package/dist/taco/svg-import/structure/walk.d.ts +85 -0
  296. package/dist/taco/svg-import/structure/walk.js +544 -0
  297. package/dist/taco/svg-import/style/color.d.ts +40 -0
  298. package/dist/taco/svg-import/style/color.js +275 -0
  299. package/dist/taco/svg-import/style/computed.d.ts +214 -0
  300. package/dist/taco/svg-import/style/computed.js +1534 -0
  301. package/dist/taco/svg-import/style/css.d.ts +127 -0
  302. package/dist/taco/svg-import/style/css.js +541 -0
  303. package/dist/taco/svg-import/style/media.d.ts +25 -0
  304. package/dist/taco/svg-import/style/media.js +307 -0
  305. package/dist/taco/svg-import/style/properties.d.ts +43 -0
  306. package/dist/taco/svg-import/style/properties.js +135 -0
  307. package/dist/taco/svg-import/style/selector-reach.d.ts +30 -0
  308. package/dist/taco/svg-import/style/selector-reach.js +169 -0
  309. package/dist/taco/svg-import/style/selector-validity.d.ts +14 -0
  310. package/dist/taco/svg-import/style/selector-validity.js +307 -0
  311. package/dist/taco/svg-import/text/text.d.ts +29 -0
  312. package/dist/taco/svg-import/text/text.js +545 -0
  313. package/dist/taco/svg-import/transform/matrix.d.ts +111 -0
  314. package/dist/taco/svg-import/transform/matrix.js +229 -0
  315. package/dist/taco/svg-import/tree/element-data.d.ts +52 -0
  316. package/dist/taco/svg-import/tree/element-data.js +155 -0
  317. package/dist/taco/svg-import/tree/elements.d.ts +36 -0
  318. package/dist/taco/svg-import/tree/elements.js +121 -0
  319. package/dist/taco/svg-import/units/length.d.ts +43 -0
  320. package/dist/taco/svg-import/units/length.js +125 -0
  321. package/dist/taco/svg-import/units/viewbox.d.ts +35 -0
  322. package/dist/taco/svg-import/units/viewbox.js +77 -0
  323. package/package.json +54 -4
@@ -0,0 +1,84 @@
1
+ import type { FrameNode, NodeId, ResizeConstraints, SceneNode } from "../types.ts";
2
+ type NodeRecord = Readonly<Record<string, SceneNode>>;
3
+ /**
4
+ * A frame's size before or after a resize. Constraints only need sizes:
5
+ * children are placed relative to their frame's top-left corner, so where
6
+ * the frame moves on the page does not matter.
7
+ * @since 0.25.0
8
+ */
9
+ export interface FrameSize {
10
+ readonly width: number;
11
+ readonly height: number;
12
+ }
13
+ /**
14
+ * The constraints a layer has when it stores none: Left and Top, Figma's
15
+ * default, which keeps the layer's position and size.
16
+ * @since 0.25.0
17
+ */
18
+ export declare const DEFAULT_RESIZE_CONSTRAINTS: ResizeConstraints;
19
+ /**
20
+ * A layer's constraints, with `DEFAULT_RESIZE_CONSTRAINTS` when it stores
21
+ * none.
22
+ * @since 0.25.0
23
+ */
24
+ export declare function nodeConstraints(node: SceneNode): ResizeConstraints;
25
+ /**
26
+ * Whether a child of `parent` is placed by its constraints when `parent`
27
+ * resizes: every child of a frame without auto layout, and only the absolute
28
+ * children (`layoutPositioning: "absolute"`) of an auto layout frame, whose
29
+ * other children the layout places.
30
+ * @since 0.25.0
31
+ */
32
+ export declare function followsConstraints(parent: FrameNode, child: SceneNode): boolean;
33
+ /**
34
+ * Scales a layer's position and size by (scaleX, scaleY) about its parent's
35
+ * origin, in the parent's coordinates, the way resizing a group or a
36
+ * selection box moves the layers inside it. Positions, sizes and vector
37
+ * geometry scale; stroke widths, corner radii, effects and font sizes do not.
38
+ *
39
+ * - A rotated layer keeps its rotation and takes the size whose bounds are
40
+ * its old bounds scaled, when the rotation allows it (see the source of
41
+ * `rotatedSize` for the fallback near 45 degrees).
42
+ * - A group's descendants scale with it.
43
+ * - A frame's box scales and its children follow by their constraints
44
+ * (`constrainChildren`); an auto layout places its other children later.
45
+ * - Text or code that grew with its content gets a fixed size.
46
+ *
47
+ * Returns the layer followed by every changed descendant. `nodes` must hold
48
+ * the layer's descendants.
49
+ * @since 0.25.0
50
+ */
51
+ export declare function scaleLayerInParent(nodes: NodeRecord, node: SceneNode, scaleX: number, scaleY: number): readonly SceneNode[];
52
+ /**
53
+ * Places each child of the frame `parentId` for a resize of that frame from
54
+ * `from` to `to`, by the child's constraints (`NodeBase.constraints`), as
55
+ * Figma does when a frame is resized. `nodes` holds the frame and its
56
+ * descendants before the change; the frame's own record is only read for
57
+ * its children and layout, so it may hold either size.
58
+ *
59
+ * - Constraints act on each child's axis-aligned bounds in the frame. A
60
+ * child whose bounds change size is resized like a layer in a resized
61
+ * selection box (`scaleLayerInParent`): a rotated or flipped layer keeps
62
+ * its rotation and flips, and a frame's own children follow by their
63
+ * constraints in turn.
64
+ * - An auto layout frame's flow children are left to its layout; only its
65
+ * absolute children move (`followsConstraints`). A child auto layout frame
66
+ * whose size changes is not laid out again here: the caller does that, as
67
+ * `layoutFrameTree` or the editor's auto layout step do.
68
+ * - A group has no constraints of its own. The layers of an upright group
69
+ * (not rotated or flipped) are placed one by one by their own constraints
70
+ * relative to the frame, and the group is fitted to them again. A rotated
71
+ * or flipped group moves and resizes as one layer, by the option its
72
+ * layers share on each axis, or Left or Top when they differ.
73
+ *
74
+ * Returns every changed node, children before descendants, each at most
75
+ * once. An unchanged size returns an empty list.
76
+ *
77
+ * The instance resolver calls this to lay out a resized instance whose
78
+ * component root has no auto layout: `constrainChildren(nodes, rootId,
79
+ * componentRoot.frame, instance.frame)`, writing the result into its node
80
+ * record before it lays out auto layout frames with `layoutFrameTree`.
81
+ * @since 0.25.0
82
+ */
83
+ export declare function constrainChildren(nodes: NodeRecord, parentId: NodeId, from: FrameSize, to: FrameSize): readonly SceneNode[];
84
+ export {};
@@ -0,0 +1,445 @@
1
+ import { getNodeBounds } from "../geometry.js";
2
+ import { fitGroupToChildren } from "../group-bounds.js";
3
+ import { deepFreeze } from "../codec.js";
4
+ import { scaleVectorNetwork } from "../vector-network.js";
5
+ import { entryOf } from "../id-table.js";
6
+ /**
7
+ * The constraints a layer has when it stores none: Left and Top, Figma's
8
+ * default, which keeps the layer's position and size.
9
+ * @since 0.25.0
10
+ */
11
+ export const DEFAULT_RESIZE_CONSTRAINTS = { horizontal: "left", vertical: "top" };
12
+ /**
13
+ * A layer's constraints, with `DEFAULT_RESIZE_CONSTRAINTS` when it stores
14
+ * none.
15
+ * @since 0.25.0
16
+ */
17
+ export function nodeConstraints(node) {
18
+ return node.constraints ?? DEFAULT_RESIZE_CONSTRAINTS;
19
+ }
20
+ /**
21
+ * Whether a child of `parent` is placed by its constraints when `parent`
22
+ * resizes: every child of a frame without auto layout, and only the absolute
23
+ * children (`layoutPositioning: "absolute"`) of an auto layout frame, whose
24
+ * other children the layout places.
25
+ * @since 0.25.0
26
+ */
27
+ export function followsConstraints(parent, child) {
28
+ return parent.layout.kind === "absolute" || child.layoutPositioning === "absolute";
29
+ }
30
+ const HORIZONTAL = {
31
+ left: "start",
32
+ right: "end",
33
+ "left-right": "stretch",
34
+ center: "center",
35
+ scale: "scale",
36
+ };
37
+ const VERTICAL = {
38
+ top: "start",
39
+ bottom: "end",
40
+ "top-bottom": "stretch",
41
+ center: "center",
42
+ scale: "scale",
43
+ };
44
+ /**
45
+ * A layer's span on one axis after its frame's length on that axis changed
46
+ * from `from` to `to`. A stretched span never gets a negative length, and a
47
+ * frame of length zero cannot give shares, so Scale then keeps the span.
48
+ */
49
+ function constrainedSpan(constraint, span, from, to) {
50
+ const change = to - from;
51
+ switch (constraint) {
52
+ case "start": return span;
53
+ case "end": return { start: span.start + change, length: span.length };
54
+ case "stretch": return { start: span.start, length: Math.max(0, span.length + change) };
55
+ case "center": return { start: span.start + change / 2, length: span.length };
56
+ case "scale": {
57
+ if (from === 0)
58
+ return span;
59
+ const share = to / from;
60
+ return { start: span.start * share, length: span.length * share };
61
+ }
62
+ }
63
+ }
64
+ /** Matrix entries smaller than this count as zero when deciding a path's orientation. */
65
+ const AXIS_TOLERANCE = 1e-9;
66
+ /**
67
+ * Scaled copies of frozen vector networks, by scale. Every instance that
68
+ * shows a path at a new size scales it, and instances of one component at
69
+ * one size scale it the same way, so the copy is shared, and frozen like the
70
+ * network it comes from (which also lets `getVectorNetworkBounds` keep its
71
+ * bounds). A few scales per network are kept.
72
+ */
73
+ const scaledNetworks = new WeakMap();
74
+ const MAX_SCALES_PER_NETWORK = 16;
75
+ function scaledNetwork(network, x, y) {
76
+ if (!Object.isFrozen(network))
77
+ return scaleVectorNetwork(network, { x, y }, { x: 0, y: 0 });
78
+ let byScale = scaledNetworks.get(network);
79
+ if (byScale === undefined) {
80
+ byScale = new Map();
81
+ scaledNetworks.set(network, byScale);
82
+ }
83
+ const key = `${Object.is(x, -0) ? "-0" : x},${Object.is(y, -0) ? "-0" : y}`;
84
+ const known = byScale.get(key);
85
+ if (known !== undefined)
86
+ return known;
87
+ const scaled = deepFreeze(scaleVectorNetwork(network, { x, y }, { x: 0, y: 0 }));
88
+ if (byScale.size >= MAX_SCALES_PER_NETWORK)
89
+ byScale.clear();
90
+ byScale.set(key, scaled);
91
+ return scaled;
92
+ }
93
+ /**
94
+ * Scales a path by (scaleX, scaleY) in its parent's coordinate system. When
95
+ * the path's transform is axis-aligned or a quarter turn, the scale is baked
96
+ * into the vector network so stroke widths stay as they are. Any other
97
+ * rotation cannot be expressed that way, so the scale goes into the transform.
98
+ */
99
+ function scaledPath(node, scaleX, scaleY) {
100
+ const [a, b, c, d, e, f] = node.transform;
101
+ const translation = [e * scaleX, f * scaleY];
102
+ if (Math.abs(b) < AXIS_TOLERANCE && Math.abs(c) < AXIS_TOLERANCE) {
103
+ return {
104
+ ...node,
105
+ transform: [a, b, c, d, ...translation],
106
+ vectorNetwork: scaledNetwork(node.vectorNetwork, scaleX, scaleY),
107
+ };
108
+ }
109
+ if (Math.abs(a) < AXIS_TOLERANCE && Math.abs(d) < AXIS_TOLERANCE) {
110
+ return {
111
+ ...node,
112
+ transform: [a, b, c, d, ...translation],
113
+ vectorNetwork: scaledNetwork(node.vectorNetwork, scaleY, scaleX),
114
+ };
115
+ }
116
+ return {
117
+ ...node,
118
+ transform: [a * scaleX, b * scaleY, c * scaleX, d * scaleY, ...translation],
119
+ };
120
+ }
121
+ /**
122
+ * In the fallback of `rotatedSize`, the smallest share of its natural size
123
+ * (see there) a side may shrink to before the layer stops filling its bounds.
124
+ */
125
+ const SMALLEST_SIDE_SHARE = 0.5;
126
+ /** Below this, |cos 2θ| counts as zero: the rotation is too close to 45 degrees to solve for. */
127
+ const DIAGONAL_TOLERANCE = 1e-6;
128
+ /**
129
+ * The new size of a framed layer turned by `rotation` degrees when its
130
+ * parent's coordinates scale by (scaleX, scaleY). The layer keeps its
131
+ * rotation; framed layers cannot store a skew.
132
+ *
133
+ * A layer of size (w, h) turned by θ has axis-aligned bounds of
134
+ * W = w|cos θ| + h|sin θ| by H = w|sin θ| + h|cos θ|. The size returned makes
135
+ * those bounds exactly (scaleX·W, scaleY·H), so a layer's bounds scale like
136
+ * the box around it and the layers keep filling the box. That is a 2 by 2
137
+ * linear system whose determinant is cos²θ − sin²θ = cos 2θ. It is exact
138
+ * for uniform scales and multiples of 90 degrees.
139
+ *
140
+ * The system has no usable answer near 45 degrees (the determinant is about
141
+ * zero) or when a strongly non-uniform scale asks for a side that is
142
+ * negative or tiny. As a fallback the layer stays inside its scaled bounds:
143
+ * - Its natural size is its size scaled along its own axes by
144
+ * (hypot(scaleX cos θ, scaleY sin θ), hypot(scaleX sin θ, scaleY cos θ)),
145
+ * shrunk evenly until it fits inside the scaled bounds.
146
+ * - Near 45 degrees it takes that natural size.
147
+ * - Otherwise, when the exact answer would make a side smaller than
148
+ * `SMALLEST_SIDE_SHARE` of its natural length, that side keeps this
149
+ * smallest length and the other side grows as far as the scaled bounds
150
+ * allow. The layer then fills its bounds in one direction and leaves an
151
+ * even gap in the other. The change from the exact size is continuous, so
152
+ * a drag across that point does not make layers jump.
153
+ * The caller keeps the layer centred in its scaled bounds.
154
+ */
155
+ function rotatedSize(width, height, rotation, scaleX, scaleY) {
156
+ const angle = rotation * Math.PI / 180;
157
+ const cosine = Math.abs(Math.cos(angle));
158
+ const sine = Math.abs(Math.sin(angle));
159
+ const naturalScaleX = Math.hypot(scaleX * cosine, scaleY * sine);
160
+ const naturalScaleY = Math.hypot(scaleX * sine, scaleY * cosine);
161
+ // A layer with no width or no height has no second side to trade against.
162
+ if (width === 0 || height === 0)
163
+ return { width: width * naturalScaleX, height: height * naturalScaleY };
164
+ const boundsWidth = (width * cosine + height * sine) * scaleX;
165
+ const boundsHeight = (width * sine + height * cosine) * scaleY;
166
+ const naturalWidth = width * naturalScaleX;
167
+ const naturalHeight = height * naturalScaleY;
168
+ // Both scales are zero: the layer collapses to no size.
169
+ if (naturalWidth === 0 && naturalHeight === 0)
170
+ return { width: 0, height: 0 };
171
+ const naturalBoundsWidth = naturalWidth * cosine + naturalHeight * sine;
172
+ const naturalBoundsHeight = naturalWidth * sine + naturalHeight * cosine;
173
+ const fit = Math.min(naturalBoundsWidth === 0 ? Infinity : boundsWidth / naturalBoundsWidth, naturalBoundsHeight === 0 ? Infinity : boundsHeight / naturalBoundsHeight);
174
+ const fitted = { width: naturalWidth * fit, height: naturalHeight * fit };
175
+ const determinant = cosine * cosine - sine * sine;
176
+ if (Math.abs(determinant) < DIAGONAL_TOLERANCE)
177
+ return fitted;
178
+ const exactWidth = (cosine * boundsWidth - sine * boundsHeight) / determinant;
179
+ const exactHeight = (cosine * boundsHeight - sine * boundsWidth) / determinant;
180
+ const smallestWidth = fitted.width * SMALLEST_SIDE_SHARE;
181
+ const smallestHeight = fitted.height * SMALLEST_SIDE_SHARE;
182
+ // Both sides cannot fall short at once: `fitted` fits inside the bounds
183
+ // that the exact size fills.
184
+ if (exactHeight < smallestHeight) {
185
+ return { width: longestSide(smallestHeight, cosine, sine, boundsWidth, boundsHeight), height: smallestHeight };
186
+ }
187
+ if (exactWidth < smallestWidth) {
188
+ return { width: smallestWidth, height: longestSide(smallestWidth, cosine, sine, boundsHeight, boundsWidth) };
189
+ }
190
+ return { width: exactWidth, height: exactHeight };
191
+ }
192
+ /**
193
+ * The longest side a turned layer can take, with its other side fixed at
194
+ * `other`, and still fit inside bounds of `along` by `across`: the side's
195
+ * own direction adds `cosine` of it to `along` and `sine` to `across`.
196
+ */
197
+ function longestSide(other, cosine, sine, along, across) {
198
+ const byAlong = cosine === 0 ? Infinity : (along - sine * other) / cosine;
199
+ const byAcross = sine === 0 ? Infinity : (across - cosine * other) / sine;
200
+ return Math.max(0, Math.min(byAlong, byAcross));
201
+ }
202
+ function childNode(nodes, parentId, childId) {
203
+ const child = entryOf(nodes, childId);
204
+ if (child === undefined)
205
+ throw new Error(`${parentId} lists a missing child ${childId}.`);
206
+ return child;
207
+ }
208
+ function scaledNodes(nodes, node, scaleX, scaleY, output) {
209
+ if (node.type === "shape" && node.shape === "path") {
210
+ output.push(scaledPath(node, scaleX, scaleY));
211
+ return;
212
+ }
213
+ const { width, height } = rotatedSize(node.frame.width, node.frame.height, node.rotation, scaleX, scaleY);
214
+ // How much the layer's own sides scaled: its descendants, in its own
215
+ // coordinates, scale by this.
216
+ const local = {
217
+ x: node.frame.width === 0 ? 1 : width / node.frame.width,
218
+ y: node.frame.height === 0 ? 1 : height / node.frame.height,
219
+ };
220
+ // The bounds' center is the frame's center, so centering the new size on
221
+ // the scaled center gives each layer its bounds scaled about the origin.
222
+ const centerX = (node.frame.x + node.frame.width / 2) * scaleX;
223
+ const centerY = (node.frame.y + node.frame.height / 2) * scaleY;
224
+ const frame = { x: centerX - width / 2, y: centerY - height / 2, width, height };
225
+ resizedNodes(nodes, node, frame, local, output);
226
+ }
227
+ /**
228
+ * Writes the framed layer `node` (not a path) with its frame set to `frame`
229
+ * to `output`, followed by its changed descendants. `local` is how much the
230
+ * layer's own sides scaled, by which a group's descendants scale and a
231
+ * connector's ends move.
232
+ */
233
+ function resizedNodes(nodes, node, frame, local, output) {
234
+ switch (node.type) {
235
+ case "group":
236
+ output.push({ ...node, frame });
237
+ for (const childId of node.children) {
238
+ scaledNodes(nodes, childNode(nodes, node.id, childId), local.x, local.y, output);
239
+ }
240
+ return;
241
+ case "frame":
242
+ // A frame keeps its own coordinate system: its box scales and its
243
+ // children follow by their constraints, as with a frame resize (the
244
+ // auto layout places the others).
245
+ output.push({ ...node, frame });
246
+ output.push(...constrainChildren(nodes, node.id, node.frame, frame));
247
+ return;
248
+ case "text":
249
+ output.push(node.autoResize === "width-and-height"
250
+ ? { ...node, frame, autoResize: "none", wrap: "word" }
251
+ : { ...node, frame });
252
+ return;
253
+ case "code":
254
+ output.push(node.autoResize === "width-and-height"
255
+ ? { ...node, frame, autoResize: "none", wordWrap: true }
256
+ : { ...node, frame });
257
+ return;
258
+ case "connector":
259
+ output.push({
260
+ ...node,
261
+ frame,
262
+ start: { ...node.start, x: node.start.x * local.x, y: node.start.y * local.y },
263
+ end: { ...node.end, x: node.end.x * local.x, y: node.end.y * local.y },
264
+ });
265
+ return;
266
+ default:
267
+ output.push({ ...node, frame });
268
+ }
269
+ }
270
+ /**
271
+ * Scales a layer's position and size by (scaleX, scaleY) about its parent's
272
+ * origin, in the parent's coordinates, the way resizing a group or a
273
+ * selection box moves the layers inside it. Positions, sizes and vector
274
+ * geometry scale; stroke widths, corner radii, effects and font sizes do not.
275
+ *
276
+ * - A rotated layer keeps its rotation and takes the size whose bounds are
277
+ * its old bounds scaled, when the rotation allows it (see the source of
278
+ * `rotatedSize` for the fallback near 45 degrees).
279
+ * - A group's descendants scale with it.
280
+ * - A frame's box scales and its children follow by their constraints
281
+ * (`constrainChildren`); an auto layout places its other children later.
282
+ * - Text or code that grew with its content gets a fixed size.
283
+ *
284
+ * Returns the layer followed by every changed descendant. `nodes` must hold
285
+ * the layer's descendants.
286
+ * @since 0.25.0
287
+ */
288
+ export function scaleLayerInParent(nodes, node, scaleX, scaleY) {
289
+ const output = [];
290
+ scaledNodes(nodes, node, scaleX, scaleY, output);
291
+ return output;
292
+ }
293
+ /** Moves a node, or a path's transform, by (dx, dy) in its parent's coordinates. */
294
+ function translatedNode(node, dx, dy) {
295
+ if (dx === 0 && dy === 0)
296
+ return node;
297
+ if (node.type === "shape" && node.shape === "path") {
298
+ const [a, b, c, d, e, f] = node.transform;
299
+ return { ...node, transform: [a, b, c, d, e + dx, f + dy] };
300
+ }
301
+ return { ...node, frame: { ...node.frame, x: node.frame.x + dx, y: node.frame.y + dy } };
302
+ }
303
+ /** Whether a group's coordinates are its frame's moved by its position. */
304
+ function isUpright(group) {
305
+ return group.rotation === 0 && group.flipX !== true && group.flipY !== true;
306
+ }
307
+ /**
308
+ * The constraints a turned or flipped group moves by as one layer: on each
309
+ * axis, the option its layers share, or Left or Top when they differ.
310
+ */
311
+ function sharedConstraints(nodes, group) {
312
+ let horizontal;
313
+ let vertical;
314
+ const visit = (node) => {
315
+ if (node.type === "group") {
316
+ node.children.forEach((childId) => visit(childNode(nodes, node.id, childId)));
317
+ return;
318
+ }
319
+ const constraints = nodeConstraints(node);
320
+ horizontal = horizontal === undefined || horizontal === constraints.horizontal ? constraints.horizontal : null;
321
+ vertical = vertical === undefined || vertical === constraints.vertical ? constraints.vertical : null;
322
+ };
323
+ visit(group);
324
+ return {
325
+ horizontal: horizontal ?? DEFAULT_RESIZE_CONSTRAINTS.horizontal,
326
+ vertical: vertical ?? DEFAULT_RESIZE_CONSTRAINTS.vertical,
327
+ };
328
+ }
329
+ /**
330
+ * Whether a layer with no width or no height needs a constrained length on
331
+ * that axis, which scaling cannot give it. Only a framed layer that is not a
332
+ * group, upright or a quarter turn, takes it (see `constrainChildren`): a
333
+ * path's geometry and a group's layers have nothing to stretch, as in Figma,
334
+ * and at other angles the bounds have no size only when the layer has none.
335
+ */
336
+ function growsFromZero(node, bounds, horizontal, vertical) {
337
+ if ((bounds.width !== 0 || horizontal.length === 0) && (bounds.height !== 0 || vertical.length === 0))
338
+ return false;
339
+ if (node.type === "group" || (node.type === "shape" && node.shape === "path"))
340
+ return false;
341
+ return node.rotation % 90 === 0;
342
+ }
343
+ /**
344
+ * Places each child of the frame `parentId` for a resize of that frame from
345
+ * `from` to `to`, by the child's constraints (`NodeBase.constraints`), as
346
+ * Figma does when a frame is resized. `nodes` holds the frame and its
347
+ * descendants before the change; the frame's own record is only read for
348
+ * its children and layout, so it may hold either size.
349
+ *
350
+ * - Constraints act on each child's axis-aligned bounds in the frame. A
351
+ * child whose bounds change size is resized like a layer in a resized
352
+ * selection box (`scaleLayerInParent`): a rotated or flipped layer keeps
353
+ * its rotation and flips, and a frame's own children follow by their
354
+ * constraints in turn.
355
+ * - An auto layout frame's flow children are left to its layout; only its
356
+ * absolute children move (`followsConstraints`). A child auto layout frame
357
+ * whose size changes is not laid out again here: the caller does that, as
358
+ * `layoutFrameTree` or the editor's auto layout step do.
359
+ * - A group has no constraints of its own. The layers of an upright group
360
+ * (not rotated or flipped) are placed one by one by their own constraints
361
+ * relative to the frame, and the group is fitted to them again. A rotated
362
+ * or flipped group moves and resizes as one layer, by the option its
363
+ * layers share on each axis, or Left or Top when they differ.
364
+ *
365
+ * Returns every changed node, children before descendants, each at most
366
+ * once. An unchanged size returns an empty list.
367
+ *
368
+ * The instance resolver calls this to lay out a resized instance whose
369
+ * component root has no auto layout: `constrainChildren(nodes, rootId,
370
+ * componentRoot.frame, instance.frame)`, writing the result into its node
371
+ * record before it lays out auto layout frames with `layoutFrameTree`.
372
+ * @since 0.25.0
373
+ */
374
+ export function constrainChildren(nodes, parentId, from, to) {
375
+ const parent = entryOf(nodes, parentId);
376
+ if (parent?.type !== "frame")
377
+ return [];
378
+ if (from.width === to.width && from.height === to.height)
379
+ return [];
380
+ const changed = new Map();
381
+ const current = (id) => changed.get(id) ?? childNode(nodes, parentId, id);
382
+ const write = (node) => {
383
+ changed.set(node.id, node);
384
+ };
385
+ // `offset` is the position of the child's parent (the frame or an upright
386
+ // group inside it) in the frame's coordinates.
387
+ const place = (node, offset) => {
388
+ if (node.type === "group" && isUpright(node)) {
389
+ const inner = { x: offset.x + node.frame.x, y: offset.y + node.frame.y };
390
+ node.children.forEach((childId) => place(current(childId), inner));
391
+ const children = Object.fromEntries(node.children.map((childId) => [childId, current(childId)]));
392
+ const fitted = fitGroupToChildren(children, node);
393
+ if (fitted === null)
394
+ return;
395
+ write(fitted.group);
396
+ fitted.children.forEach(write);
397
+ return;
398
+ }
399
+ const constraints = node.type === "group" ? sharedConstraints(nodes, node) : nodeConstraints(node);
400
+ const bounds = getNodeBounds(node);
401
+ const horizontal = constrainedSpan(HORIZONTAL[constraints.horizontal], { start: bounds.x + offset.x, length: bounds.width }, from.width, to.width);
402
+ const vertical = constrainedSpan(VERTICAL[constraints.vertical], { start: bounds.y + offset.y, length: bounds.height }, from.height, to.height);
403
+ const targetX = horizontal.start - offset.x;
404
+ const targetY = vertical.start - offset.y;
405
+ if (horizontal.length === bounds.width && vertical.length === bounds.height) {
406
+ const moved = translatedNode(node, targetX - bounds.x, targetY - bounds.y);
407
+ if (moved !== node)
408
+ write(moved);
409
+ return;
410
+ }
411
+ if (growsFromZero(node, bounds, horizontal, vertical)) {
412
+ // Nothing scales up from no size: a layer that a stretch collapsed
413
+ // takes the constrained lengths as its own sides instead, swapped by a
414
+ // quarter turn, centred in its constrained bounds.
415
+ const swapped = Math.abs(Math.sin(node.rotation * Math.PI / 180)) > 0.5;
416
+ const width = swapped ? vertical.length : horizontal.length;
417
+ const height = swapped ? horizontal.length : vertical.length;
418
+ const frame = {
419
+ x: targetX + (horizontal.length - width) / 2,
420
+ y: targetY + (vertical.length - height) / 2,
421
+ width,
422
+ height,
423
+ };
424
+ const output = [];
425
+ resizedNodes(nodes, node, frame, {
426
+ x: node.frame.width === 0 ? 1 : width / node.frame.width,
427
+ y: node.frame.height === 0 ? 1 : height / node.frame.height,
428
+ }, output);
429
+ output.forEach(write);
430
+ return;
431
+ }
432
+ const scaleX = bounds.width === 0 ? 1 : horizontal.length / bounds.width;
433
+ const scaleY = bounds.height === 0 ? 1 : vertical.length / bounds.height;
434
+ const [scaled, ...descendants] = scaleLayerInParent(nodes, node, scaleX, scaleY);
435
+ const scaledBounds = getNodeBounds(scaled);
436
+ write(translatedNode(scaled, targetX - scaledBounds.x, targetY - scaledBounds.y));
437
+ descendants.forEach(write);
438
+ };
439
+ for (const childId of parent.children) {
440
+ const child = childNode(nodes, parentId, childId);
441
+ if (followsConstraints(parent, child))
442
+ place(child, { x: 0, y: 0 });
443
+ }
444
+ return [...changed.values()];
445
+ }
@@ -0,0 +1,46 @@
1
+ import { type LayoutAxis } from "../auto-layout-lines.ts";
2
+ import type { FrameNode, Layout, NodeId, SceneNode } from "../types.ts";
3
+ /** The gap, in pixels, a new auto layout starts with. */
4
+ export declare const DEFAULT_AUTO_LAYOUT_GAP = 24;
5
+ /**
6
+ * A new layout of the given kind. Auto layouts start with a fixed width, a
7
+ * hugged height, no padding and `gap` between children (a grid uses it for
8
+ * both its column and row gaps).
9
+ */
10
+ export declare function createFrameLayout(kind: Layout["kind"], gap?: number): Layout;
11
+ /**
12
+ * The gap a layout keeps between children: a stack's gap or a grid's column
13
+ * gap. Without an auto layout it is `DEFAULT_AUTO_LAYOUT_GAP`.
14
+ */
15
+ export declare function frameLayoutGap(layout: Layout): number;
16
+ /** A frame and its children after `applyFrameLayout` has placed them. */
17
+ export interface AppliedFrameLayout {
18
+ readonly frame: FrameNode;
19
+ readonly children: ReadonlyMap<NodeId, SceneNode>;
20
+ }
21
+ /**
22
+ * Whether a row or column lays out `child`: not when it ignores auto layout
23
+ * (`layoutPositioning: "absolute"`), and not while it is hidden. As in Figma,
24
+ * a hidden child takes no slot and no gap, so its neighbours close up, and it
25
+ * keeps its own frame until it is shown again, when it gets its slot back.
26
+ * @since 0.32.0
27
+ */
28
+ export declare function inStackFlow(child: SceneNode): boolean;
29
+ /**
30
+ * Lays out one frame's direct children with `layout` and returns the frame
31
+ * with its new size and the moved or resized children. Child frames are not
32
+ * laid out again here; `layoutFrameTree` does that. `contentLength` gives
33
+ * the length a child that fills the cross axis needs for its own content, so
34
+ * a frame that hugs that axis can hug it; without it such a child counts with
35
+ * its minimum.
36
+ */
37
+ export declare function applyFrameLayout(frame: FrameNode, childNodes: readonly SceneNode[], layout: Layout, contentLength?: (node: SceneNode, axis: LayoutAxis) => number | undefined): AppliedFrameLayout;
38
+ /**
39
+ * Lays out the auto layout frame `frameId` in `nodes` (changed in place),
40
+ * then lays out again each child frame whose size it changed, so Fill sizes
41
+ * reach nested auto layouts, and each auto layout frame that constraints
42
+ * resized. Returns the IDs of every node it changed. The
43
+ * caller lays out hugging descendants first, deepest first, so their sizes
44
+ * are known.
45
+ */
46
+ export declare function layoutFrameTree(nodes: Record<string, SceneNode>, frameId: NodeId, changed?: Set<NodeId>): Set<NodeId>;