@moondraft/import 0.0.0-stage → 0.2.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 (337) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/LICENSE +34 -0
  3. package/README.md +36 -2
  4. package/SOURCE.md +394 -0
  5. package/dist/adapter/convert.d.ts +144 -0
  6. package/dist/adapter/convert.js +2811 -0
  7. package/dist/adapter/figma-descriptions.d.ts +7 -0
  8. package/dist/adapter/figma-descriptions.js +34 -0
  9. package/dist/adapter/figma-grids.d.ts +12 -0
  10. package/dist/adapter/figma-grids.js +175 -0
  11. package/dist/adapter/figma-handoff.d.ts +12 -0
  12. package/dist/adapter/figma-handoff.js +167 -0
  13. package/dist/adapter/figma-hyperlinks.d.ts +13 -0
  14. package/dist/adapter/figma-hyperlinks.js +77 -0
  15. package/dist/adapter/figma.d.ts +12 -0
  16. package/dist/adapter/figma.js +40 -0
  17. package/dist/adapter/file-components.d.ts +20 -0
  18. package/dist/adapter/file-components.js +352 -0
  19. package/dist/adapter/file-resources.d.ts +29 -0
  20. package/dist/adapter/file-resources.js +851 -0
  21. package/dist/adapter/image-crop.d.ts +18 -0
  22. package/dist/adapter/image-crop.js +30 -0
  23. package/dist/adapter/index.d.ts +6 -0
  24. package/dist/adapter/index.js +9 -0
  25. package/dist/adapter/link.d.ts +49 -0
  26. package/dist/adapter/link.js +892 -0
  27. package/dist/adapter/payload.d.ts +31 -0
  28. package/dist/adapter/payload.js +78 -0
  29. package/dist/adapter/shapes.d.ts +31 -0
  30. package/dist/adapter/shapes.js +75 -0
  31. package/dist/adapter/variables.d.ts +45 -0
  32. package/dist/adapter/variables.js +106 -0
  33. package/dist/figma-file.d.ts +38 -0
  34. package/dist/figma-file.js +97 -0
  35. package/dist/figma-worker.d.ts +11 -0
  36. package/dist/figma-worker.js +12 -0
  37. package/dist/figma.d.ts +26 -0
  38. package/dist/figma.js +230 -0
  39. package/dist/index.d.ts +29 -0
  40. package/dist/index.js +50 -0
  41. package/dist/report.d.ts +42 -0
  42. package/dist/report.js +142 -0
  43. package/dist/serialize.d.ts +7 -0
  44. package/dist/serialize.js +79 -0
  45. package/dist/svg.d.ts +33 -0
  46. package/dist/svg.js +44 -0
  47. package/dist/syntax.d.ts +8 -0
  48. package/dist/syntax.js +19 -0
  49. package/dist/taco/figma-import/clipboard.d.ts +25 -0
  50. package/dist/taco/figma-import/clipboard.js +87 -0
  51. package/dist/taco/figma-import/clipboardSize.d.ts +31 -0
  52. package/dist/taco/figma-import/clipboardSize.js +107 -0
  53. package/dist/taco/figma-import/container/compression.d.ts +9 -0
  54. package/dist/taco/figma-import/container/compression.js +174 -0
  55. package/dist/taco/figma-import/container/error.d.ts +15 -0
  56. package/dist/taco/figma-import/container/error.js +19 -0
  57. package/dist/taco/figma-import/container/kiwiContainer.d.ts +41 -0
  58. package/dist/taco/figma-import/container/kiwiContainer.js +61 -0
  59. package/dist/taco/figma-import/container/limits.d.ts +22 -0
  60. package/dist/taco/figma-import/container/limits.js +22 -0
  61. package/dist/taco/figma-import/container/zip.d.ts +14 -0
  62. package/dist/taco/figma-import/container/zip.js +154 -0
  63. package/dist/taco/figma-import/figFile.d.ts +34 -0
  64. package/dist/taco/figma-import/figFile.js +91 -0
  65. package/dist/taco/figma-import/figFileDocument.d.ts +25 -0
  66. package/dist/taco/figma-import/figFileDocument.js +100 -0
  67. package/dist/taco/figma-import/import/blobs.d.ts +10 -0
  68. package/dist/taco/figma-import/import/blobs.js +23 -0
  69. package/dist/taco/figma-import/import/carry.d.ts +24 -0
  70. package/dist/taco/figma-import/import/carry.js +66 -0
  71. package/dist/taco/figma-import/import/componentProps.d.ts +90 -0
  72. package/dist/taco/figma-import/import/componentProps.js +329 -0
  73. package/dist/taco/figma-import/import/componentSets.d.ts +85 -0
  74. package/dist/taco/figma-import/import/componentSets.js +647 -0
  75. package/dist/taco/figma-import/import/converters/effects.d.ts +31 -0
  76. package/dist/taco/figma-import/import/converters/effects.js +127 -0
  77. package/dist/taco/figma-import/import/converters/ellipse.d.ts +7 -0
  78. package/dist/taco/figma-import/import/converters/ellipse.js +54 -0
  79. package/dist/taco/figma-import/import/converters/exportSettings.d.ts +4 -0
  80. package/dist/taco/figma-import/import/converters/exportSettings.js +49 -0
  81. package/dist/taco/figma-import/import/converters/frame.d.ts +21 -0
  82. package/dist/taco/figma-import/import/converters/frame.js +63 -0
  83. package/dist/taco/figma-import/import/converters/gradient.d.ts +74 -0
  84. package/dist/taco/figma-import/import/converters/gradient.js +108 -0
  85. package/dist/taco/figma-import/import/converters/group.d.ts +19 -0
  86. package/dist/taco/figma-import/import/converters/group.js +30 -0
  87. package/dist/taco/figma-import/import/converters/image.d.ts +13 -0
  88. package/dist/taco/figma-import/import/converters/image.js +94 -0
  89. package/dist/taco/figma-import/import/converters/layout.d.ts +33 -0
  90. package/dist/taco/figma-import/import/converters/layout.js +187 -0
  91. package/dist/taco/figma-import/import/converters/line.d.ts +11 -0
  92. package/dist/taco/figma-import/import/converters/line.js +40 -0
  93. package/dist/taco/figma-import/import/converters/rectangle.d.ts +3 -0
  94. package/dist/taco/figma-import/import/converters/rectangle.js +11 -0
  95. package/dist/taco/figma-import/import/converters/section.d.ts +8 -0
  96. package/dist/taco/figma-import/import/converters/section.js +29 -0
  97. package/dist/taco/figma-import/import/converters/shared.d.ts +71 -0
  98. package/dist/taco/figma-import/import/converters/shared.js +372 -0
  99. package/dist/taco/figma-import/import/converters/text.d.ts +54 -0
  100. package/dist/taco/figma-import/import/converters/text.js +707 -0
  101. package/dist/taco/figma-import/import/converters/vector.d.ts +105 -0
  102. package/dist/taco/figma-import/import/converters/vector.js +609 -0
  103. package/dist/taco/figma-import/import/converters/vectorNetwork.d.ts +114 -0
  104. package/dist/taco/figma-import/import/converters/vectorNetwork.js +503 -0
  105. package/dist/taco/figma-import/import/fields.d.ts +15 -0
  106. package/dist/taco/figma-import/import/fields.js +29 -0
  107. package/dist/taco/figma-import/import/instances.d.ts +184 -0
  108. package/dist/taco/figma-import/import/instances.js +1530 -0
  109. package/dist/taco/figma-import/import/nestingCycles.d.ts +86 -0
  110. package/dist/taco/figma-import/import/nestingCycles.js +488 -0
  111. package/dist/taco/figma-import/import/slots.d.ts +56 -0
  112. package/dist/taco/figma-import/import/slots.js +96 -0
  113. package/dist/taco/figma-import/import/styles.d.ts +48 -0
  114. package/dist/taco/figma-import/import/styles.js +48 -0
  115. package/dist/taco/figma-import/import/tree.d.ts +66 -0
  116. package/dist/taco/figma-import/import/tree.js +194 -0
  117. package/dist/taco/figma-import/import/types.d.ts +232 -0
  118. package/dist/taco/figma-import/import/types.js +33 -0
  119. package/dist/taco/figma-import/import/variables.d.ts +137 -0
  120. package/dist/taco/figma-import/import/variables.js +769 -0
  121. package/dist/taco/figma-import/import/variantTrees.d.ts +20 -0
  122. package/dist/taco/figma-import/import/variantTrees.js +520 -0
  123. package/dist/taco/figma-import/import/walk.d.ts +207 -0
  124. package/dist/taco/figma-import/import/walk.js +1464 -0
  125. package/dist/taco/figma-import/index.d.ts +22 -0
  126. package/dist/taco/figma-import/index.js +13 -0
  127. package/dist/taco/figma-import/kiwi/byteReader.d.ts +37 -0
  128. package/dist/taco/figma-import/kiwi/byteReader.js +151 -0
  129. package/dist/taco/figma-import/kiwi/error.d.ts +14 -0
  130. package/dist/taco/figma-import/kiwi/error.js +29 -0
  131. package/dist/taco/figma-import/kiwi/limits.d.ts +18 -0
  132. package/dist/taco/figma-import/kiwi/limits.js +18 -0
  133. package/dist/taco/figma-import/kiwi/message.d.ts +12 -0
  134. package/dist/taco/figma-import/kiwi/message.js +147 -0
  135. package/dist/taco/figma-import/kiwi/schema.d.ts +42 -0
  136. package/dist/taco/figma-import/kiwi/schema.js +206 -0
  137. package/dist/taco/figma-import/kiwi/types.d.ts +46 -0
  138. package/dist/taco/figma-import/kiwi/types.js +18 -0
  139. package/dist/taco/model/agent-hidden-fields.d.ts +20 -0
  140. package/dist/taco/model/agent-hidden-fields.js +29 -0
  141. package/dist/taco/model/asset-users.d.ts +23 -0
  142. package/dist/taco/model/asset-users.js +128 -0
  143. package/dist/taco/model/auto-layout-lines.d.ts +32 -0
  144. package/dist/taco/model/auto-layout-lines.js +70 -0
  145. package/dist/taco/model/codec.d.ts +444 -0
  146. package/dist/taco/model/codec.js +5665 -0
  147. package/dist/taco/model/color.d.ts +11 -0
  148. package/dist/taco/model/color.js +61 -0
  149. package/dist/taco/model/comment-operations.d.ts +102 -0
  150. package/dist/taco/model/comment-operations.js +227 -0
  151. package/dist/taco/model/component-evaluation.d.ts +96 -0
  152. package/dist/taco/model/component-evaluation.js +555 -0
  153. package/dist/taco/model/component-expressions.d.ts +242 -0
  154. package/dist/taco/model/component-expressions.js +1082 -0
  155. package/dist/taco/model/component-properties.d.ts +111 -0
  156. package/dist/taco/model/component-properties.js +339 -0
  157. package/dist/taco/model/component-samples.d.ts +83 -0
  158. package/dist/taco/model/component-samples.js +290 -0
  159. package/dist/taco/model/component-validity.d.ts +85 -0
  160. package/dist/taco/model/component-validity.js +397 -0
  161. package/dist/taco/model/components.d.ts +155 -0
  162. package/dist/taco/model/components.js +505 -0
  163. package/dist/taco/model/connector-ends.d.ts +20 -0
  164. package/dist/taco/model/connector-ends.js +188 -0
  165. package/dist/taco/model/connector-geometry.d.ts +74 -0
  166. package/dist/taco/model/connector-geometry.js +293 -0
  167. package/dist/taco/model/corner-radii.d.ts +26 -0
  168. package/dist/taco/model/corner-radii.js +47 -0
  169. package/dist/taco/model/derivations.d.ts +81 -0
  170. package/dist/taco/model/derivations.js +151 -0
  171. package/dist/taco/model/export-settings.d.ts +53 -0
  172. package/dist/taco/model/export-settings.js +156 -0
  173. package/dist/taco/model/expressions/ast.d.ts +153 -0
  174. package/dist/taco/model/expressions/ast.js +6 -0
  175. package/dist/taco/model/expressions/cache.d.ts +23 -0
  176. package/dist/taco/model/expressions/cache.js +43 -0
  177. package/dist/taco/model/expressions/check.d.ts +72 -0
  178. package/dist/taco/model/expressions/check.js +517 -0
  179. package/dist/taco/model/expressions/completion.d.ts +61 -0
  180. package/dist/taco/model/expressions/completion.js +421 -0
  181. package/dist/taco/model/expressions/evaluate.d.ts +32 -0
  182. package/dist/taco/model/expressions/evaluate.js +519 -0
  183. package/dist/taco/model/expressions/forms.d.ts +84 -0
  184. package/dist/taco/model/expressions/forms.js +200 -0
  185. package/dist/taco/model/expressions/index.d.ts +14 -0
  186. package/dist/taco/model/expressions/index.js +17 -0
  187. package/dist/taco/model/expressions/lexer.d.ts +42 -0
  188. package/dist/taco/model/expressions/lexer.js +213 -0
  189. package/dist/taco/model/expressions/library.d.ts +33 -0
  190. package/dist/taco/model/expressions/library.js +117 -0
  191. package/dist/taco/model/expressions/names.d.ts +43 -0
  192. package/dist/taco/model/expressions/names.js +99 -0
  193. package/dist/taco/model/expressions/parser.d.ts +15 -0
  194. package/dist/taco/model/expressions/parser.js +438 -0
  195. package/dist/taco/model/expressions/rename.d.ts +34 -0
  196. package/dist/taco/model/expressions/rename.js +46 -0
  197. package/dist/taco/model/expressions/source.d.ts +15 -0
  198. package/dist/taco/model/expressions/source.js +161 -0
  199. package/dist/taco/model/expressions/types.d.ts +119 -0
  200. package/dist/taco/model/expressions/types.js +102 -0
  201. package/dist/taco/model/expressions/values.d.ts +97 -0
  202. package/dist/taco/model/expressions/values.js +160 -0
  203. package/dist/taco/model/geometry-limits.d.ts +16 -0
  204. package/dist/taco/model/geometry-limits.js +67 -0
  205. package/dist/taco/model/geometry.d.ts +47 -0
  206. package/dist/taco/model/geometry.js +193 -0
  207. package/dist/taco/model/group-bounds.d.ts +38 -0
  208. package/dist/taco/model/group-bounds.js +144 -0
  209. package/dist/taco/model/id-table.d.ts +37 -0
  210. package/dist/taco/model/id-table.js +80 -0
  211. package/dist/taco/model/index.d.ts +25 -0
  212. package/dist/taco/model/index.js +27 -0
  213. package/dist/taco/model/instance-resolver.d.ts +376 -0
  214. package/dist/taco/model/instance-resolver.js +1778 -0
  215. package/dist/taco/model/layer-syntax.d.ts +340 -0
  216. package/dist/taco/model/layer-syntax.js +3506 -0
  217. package/dist/taco/model/layout/constraints.d.ts +84 -0
  218. package/dist/taco/model/layout/constraints.js +445 -0
  219. package/dist/taco/model/layout/frame-layout.d.ts +46 -0
  220. package/dist/taco/model/layout/frame-layout.js +618 -0
  221. package/dist/taco/model/layout/node-sizing.d.ts +163 -0
  222. package/dist/taco/model/layout/node-sizing.js +486 -0
  223. package/dist/taco/model/legacy-connector-caps.d.ts +15 -0
  224. package/dist/taco/model/legacy-connector-caps.js +70 -0
  225. package/dist/taco/model/linear-call.d.ts +48 -0
  226. package/dist/taco/model/linear-call.js +58 -0
  227. package/dist/taco/model/new-nodes.d.ts +145 -0
  228. package/dist/taco/model/new-nodes.js +277 -0
  229. package/dist/taco/model/node-builder.d.ts +449 -0
  230. package/dist/taco/model/node-builder.js +2294 -0
  231. package/dist/taco/model/node-table-watch.d.ts +36 -0
  232. package/dist/taco/model/node-table-watch.js +63 -0
  233. package/dist/taco/model/node-transform.d.ts +39 -0
  234. package/dist/taco/model/node-transform.js +79 -0
  235. package/dist/taco/model/node-users-index.d.ts +10 -0
  236. package/dist/taco/model/node-users-index.js +82 -0
  237. package/dist/taco/model/operation-references.d.ts +80 -0
  238. package/dist/taco/model/operation-references.js +399 -0
  239. package/dist/taco/model/operations.d.ts +610 -0
  240. package/dist/taco/model/operations.js +2882 -0
  241. package/dist/taco/model/overlay-table.d.ts +71 -0
  242. package/dist/taco/model/overlay-table.js +171 -0
  243. package/dist/taco/model/override-remap.d.ts +69 -0
  244. package/dist/taco/model/override-remap.js +230 -0
  245. package/dist/taco/model/parent-table.d.ts +53 -0
  246. package/dist/taco/model/parent-table.js +193 -0
  247. package/dist/taco/model/problem-collector.d.ts +27 -0
  248. package/dist/taco/model/problem-collector.js +101 -0
  249. package/dist/taco/model/sha256.d.ts +10 -0
  250. package/dist/taco/model/sha256.js +79 -0
  251. package/dist/taco/model/shape-geometry.d.ts +96 -0
  252. package/dist/taco/model/shape-geometry.js +368 -0
  253. package/dist/taco/model/shared-node-table.d.ts +97 -0
  254. package/dist/taco/model/shared-node-table.js +546 -0
  255. package/dist/taco/model/slots.d.ts +113 -0
  256. package/dist/taco/model/slots.js +281 -0
  257. package/dist/taco/model/stroke-settings.d.ts +37 -0
  258. package/dist/taco/model/stroke-settings.js +90 -0
  259. package/dist/taco/model/svg-path-import.d.ts +89 -0
  260. package/dist/taco/model/svg-path-import.js +219 -0
  261. package/dist/taco/model/text-measurement.d.ts +142 -0
  262. package/dist/taco/model/text-measurement.js +846 -0
  263. package/dist/taco/model/text-reads.d.ts +66 -0
  264. package/dist/taco/model/text-reads.js +128 -0
  265. package/dist/taco/model/text-sizer.d.ts +358 -0
  266. package/dist/taco/model/text-sizer.js +996 -0
  267. package/dist/taco/model/theme-users.d.ts +59 -0
  268. package/dist/taco/model/theme-users.js +312 -0
  269. package/dist/taco/model/thumbnail.d.ts +15 -0
  270. package/dist/taco/model/thumbnail.js +34 -0
  271. package/dist/taco/model/types.d.ts +2369 -0
  272. package/dist/taco/model/types.js +366 -0
  273. package/dist/taco/model/unknown-property.d.ts +5 -0
  274. package/dist/taco/model/unknown-property.js +7 -0
  275. package/dist/taco/model/validated-documents.d.ts +22 -0
  276. package/dist/taco/model/validated-documents.js +22 -0
  277. package/dist/taco/model/variable-modes.d.ts +61 -0
  278. package/dist/taco/model/variable-modes.js +438 -0
  279. package/dist/taco/model/variable-references.d.ts +54 -0
  280. package/dist/taco/model/variable-references.js +183 -0
  281. package/dist/taco/model/variables.d.ts +24 -0
  282. package/dist/taco/model/variables.js +151 -0
  283. package/dist/taco/model/vector-network.d.ts +34 -0
  284. package/dist/taco/model/vector-network.js +411 -0
  285. package/dist/taco/svg-import/import-svg.d.ts +36 -0
  286. package/dist/taco/svg-import/import-svg.js +729 -0
  287. package/dist/taco/svg-import/index.d.ts +3 -0
  288. package/dist/taco/svg-import/index.js +3 -0
  289. package/dist/taco/svg-import/limits/limits.d.ts +79 -0
  290. package/dist/taco/svg-import/limits/limits.js +160 -0
  291. package/dist/taco/svg-import/paint/gradients.d.ts +64 -0
  292. package/dist/taco/svg-import/paint/gradients.js +429 -0
  293. package/dist/taco/svg-import/paint/paint.d.ts +32 -0
  294. package/dist/taco/svg-import/paint/paint.js +162 -0
  295. package/dist/taco/svg-import/paths/paths.d.ts +58 -0
  296. package/dist/taco/svg-import/paths/paths.js +205 -0
  297. package/dist/taco/svg-import/public-types.d.ts +279 -0
  298. package/dist/taco/svg-import/public-types.js +56 -0
  299. package/dist/taco/svg-import/report/report.d.ts +44 -0
  300. package/dist/taco/svg-import/report/report.js +79 -0
  301. package/dist/taco/svg-import/reuse/reuse.d.ts +99 -0
  302. package/dist/taco/svg-import/reuse/reuse.js +840 -0
  303. package/dist/taco/svg-import/shapes/shapes.d.ts +35 -0
  304. package/dist/taco/svg-import/shapes/shapes.js +386 -0
  305. package/dist/taco/svg-import/structure/effects.d.ts +26 -0
  306. package/dist/taco/svg-import/structure/effects.js +618 -0
  307. package/dist/taco/svg-import/structure/image.d.ts +24 -0
  308. package/dist/taco/svg-import/structure/image.js +495 -0
  309. package/dist/taco/svg-import/structure/walk.d.ts +85 -0
  310. package/dist/taco/svg-import/structure/walk.js +544 -0
  311. package/dist/taco/svg-import/style/color.d.ts +40 -0
  312. package/dist/taco/svg-import/style/color.js +275 -0
  313. package/dist/taco/svg-import/style/computed.d.ts +214 -0
  314. package/dist/taco/svg-import/style/computed.js +1534 -0
  315. package/dist/taco/svg-import/style/css.d.ts +127 -0
  316. package/dist/taco/svg-import/style/css.js +541 -0
  317. package/dist/taco/svg-import/style/media.d.ts +25 -0
  318. package/dist/taco/svg-import/style/media.js +307 -0
  319. package/dist/taco/svg-import/style/properties.d.ts +43 -0
  320. package/dist/taco/svg-import/style/properties.js +135 -0
  321. package/dist/taco/svg-import/style/selector-reach.d.ts +30 -0
  322. package/dist/taco/svg-import/style/selector-reach.js +169 -0
  323. package/dist/taco/svg-import/style/selector-validity.d.ts +14 -0
  324. package/dist/taco/svg-import/style/selector-validity.js +307 -0
  325. package/dist/taco/svg-import/text/text.d.ts +29 -0
  326. package/dist/taco/svg-import/text/text.js +545 -0
  327. package/dist/taco/svg-import/transform/matrix.d.ts +111 -0
  328. package/dist/taco/svg-import/transform/matrix.js +229 -0
  329. package/dist/taco/svg-import/tree/element-data.d.ts +52 -0
  330. package/dist/taco/svg-import/tree/element-data.js +155 -0
  331. package/dist/taco/svg-import/tree/elements.d.ts +36 -0
  332. package/dist/taco/svg-import/tree/elements.js +121 -0
  333. package/dist/taco/svg-import/units/length.d.ts +43 -0
  334. package/dist/taco/svg-import/units/length.js +125 -0
  335. package/dist/taco/svg-import/units/viewbox.d.ts +35 -0
  336. package/dist/taco/svg-import/units/viewbox.js +77 -0
  337. package/package.json +55 -4
@@ -0,0 +1,609 @@
1
+ import { getVectorNetworkBounds, transformIsInvertible, vectorHandleId, vectorRegionId, vectorSegmentId, vectorVertexId, } from "../../../model/index.js";
2
+ import { field, isObject } from "../fields.js";
3
+ import { nodeEffects } from "./effects.js";
4
+ import { sizeLimitsOf } from "./layout.js";
5
+ import { isFigmaGroup } from "./frame.js";
6
+ import { endCapOf, frameGeometry, framedBase, layerBase, nodePaints, nodeStrokes, STROKE_CAPS, visualStyle } from "./shared.js";
7
+ import { NetworkRefused, applyRegionStyles, regionBoxes, vectorDataNetwork, vectorStyleTable } from "./vectorNetwork.js";
8
+ import { carry, imageCropOf } from "../carry.js";
9
+ /**
10
+ * The most paths in one node's `fillGeometry` and the most drawing commands
11
+ * in all of them together. A node over either is left out and reported.
12
+ */
13
+ export const VECTOR_GEOMETRY_LIMITS = { paths: 1_000, commands: 100_000 };
14
+ /**
15
+ * Why a VECTOR's geometry is not imported, named at the start of the report
16
+ * reason as `geometry refused (<name>)`:
17
+ * - `no-geometry`: no `fillGeometry` path draws anything.
18
+ * - `not-a-path`: a `fillGeometry` entry is not a `Path` with a `commandsBlob`.
19
+ * - `unknown-winding-rule`: a `windingRule` other than `NONZERO` or `ODD`.
20
+ * - `blob-missing`: the `commandsBlob` is not in the message's `blobs`.
21
+ * - `blob-too-short`: the blob ends inside a command's coordinates.
22
+ * - `unknown-command`: a command code other than 0 to 4.
23
+ * - `not-finite`: a coordinate is NaN or infinite.
24
+ * - `draw-before-move`: a line or curve before the first moveTo.
25
+ * - `too-many-paths`, `too-many-commands`: over `VECTOR_GEOMETRY_LIMITS`.
26
+ * - `import-command-limit`: the whole import is over `limits.vectorCommands`.
27
+ */
28
+ export const VECTOR_GEOMETRY_PROBLEMS = [
29
+ "no-geometry",
30
+ "not-a-path",
31
+ "unknown-winding-rule",
32
+ "blob-missing",
33
+ "blob-too-short",
34
+ "unknown-command",
35
+ "not-finite",
36
+ "draw-before-move",
37
+ "too-many-paths",
38
+ "too-many-commands",
39
+ "import-command-limit",
40
+ ];
41
+ class GeometryRefused extends Error {
42
+ problem;
43
+ constructor(problem, detail) {
44
+ super(`geometry refused (${problem}): ${detail}`);
45
+ this.problem = problem;
46
+ }
47
+ }
48
+ /**
49
+ * The commands of a `commandsBlob`, as grida reads them
50
+ * (packages/grida-canvas-io-figma/fig-kiwi/blob-parser.ts:12-107): a command
51
+ * code byte, then its coordinates as little-endian float32 numbers. 0 closes
52
+ * the subpath (no coordinates), 1 moves to (x, y), 2 draws a line to (x, y),
53
+ * 3 a quadratic curve through (cx, cy) to (x, y), 4 a cubic curve through
54
+ * (cx1, cy1) and (cx2, cy2) to (x, y).
55
+ */
56
+ const COMMAND_ARGUMENTS = [0, 2, 2, 4, 6];
57
+ const COMMAND_NAMES = ["close", "moveTo", "lineTo", "quadratic curve", "cubic curve"];
58
+ function decodeCommands(bytes, budget, shared, where) {
59
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
60
+ const commands = [];
61
+ let offset = 0;
62
+ while (offset < bytes.length) {
63
+ if (budget.left === 0) {
64
+ throw new GeometryRefused("too-many-commands", `the fillGeometry paths have more than ${String(VECTOR_GEOMETRY_LIMITS.commands)} commands`);
65
+ }
66
+ // Not `=== 0`: a fractional, negative or NaN limit would never reach exactly 0.
67
+ if (!(shared.left > 0)) {
68
+ throw new GeometryRefused("import-command-limit", `the import has read ${String(shared.limit)} vector commands, its limit (limits.vectorCommands)`);
69
+ }
70
+ budget.left -= 1;
71
+ shared.left -= 1;
72
+ const code = bytes[offset];
73
+ const count = COMMAND_ARGUMENTS[code];
74
+ if (count === undefined)
75
+ throw new GeometryRefused("unknown-command", `${where} has command code ${String(code)} at byte ${String(offset)}`);
76
+ if (offset + 1 + count * 4 > bytes.length) {
77
+ throw new GeometryRefused("blob-too-short", `${where} ends at byte ${String(bytes.length)}, inside the ${COMMAND_NAMES[code]} at byte ${String(offset)}`);
78
+ }
79
+ const values = [];
80
+ for (let i = 0; i < count; i++) {
81
+ const value = view.getFloat32(offset + 1 + i * 4, true);
82
+ if (!Number.isFinite(value))
83
+ throw new GeometryRefused("not-finite", `${where} has a coordinate that is ${String(value)} in the ${COMMAND_NAMES[code]} at byte ${String(offset)}`);
84
+ values.push(value);
85
+ }
86
+ commands.push({ code, values });
87
+ offset += 1 + count * 4;
88
+ }
89
+ return commands;
90
+ }
91
+ /**
92
+ * Adds one path's commands to the network as one region. Ids number on
93
+ * across paths. As in `vectorNetworkFromSvgPathData`, a close whose current
94
+ * point is the subpath's start ends the last segment at the start vertex, a
95
+ * close elsewhere adds a line back to it, and an open subpath is closed for
96
+ * filling only (`implicitClose`). A quadratic curve becomes the cubic that
97
+ * draws it: each handle is 2/3 of the way to the control point.
98
+ */
99
+ function addRegion(network, commands, windingRule, where) {
100
+ const { vertices, segments } = network;
101
+ const loops = [];
102
+ let moveTo;
103
+ let start;
104
+ let current;
105
+ let loop = [];
106
+ const addVertex = (x, y) => {
107
+ const vertex = { id: vectorVertexId(`v${String(vertices.length)}`), x, y };
108
+ vertices.push(vertex);
109
+ return vertex;
110
+ };
111
+ const finish = (closed) => {
112
+ if (loop.length > 0)
113
+ loops.push({ segments: loop, ...(closed ? {} : { implicitClose: true }) });
114
+ loop = [];
115
+ start = current = undefined;
116
+ };
117
+ for (const { code, values } of commands) {
118
+ if (code === 1) {
119
+ finish(false);
120
+ moveTo = { x: values[0], y: values[1] };
121
+ continue;
122
+ }
123
+ if (code === 0) {
124
+ if (start !== undefined && current !== undefined && loop.length > 0) {
125
+ if (current !== start && current.x === start.x && current.y === start.y) {
126
+ const last = segments[segments.length - 1];
127
+ segments[segments.length - 1] = { ...last, end: start.id };
128
+ vertices.pop();
129
+ }
130
+ else if (current !== start) {
131
+ const id = vectorSegmentId(`s${String(segments.length)}`);
132
+ segments.push({ id, kind: "line", start: current.id, end: start.id });
133
+ loop.push({ segmentId: id, direction: "forward" });
134
+ }
135
+ moveTo = { x: start.x, y: start.y };
136
+ }
137
+ finish(true);
138
+ continue;
139
+ }
140
+ if (current === undefined) {
141
+ if (moveTo === undefined)
142
+ throw new GeometryRefused("draw-before-move", `${where} draws a ${COMMAND_NAMES[code]} before its first moveTo`);
143
+ start = current = addVertex(moveTo.x, moveTo.y);
144
+ }
145
+ const from = current;
146
+ const end = addVertex(values[values.length - 2], values[values.length - 1]);
147
+ const id = vectorSegmentId(`s${String(segments.length)}`);
148
+ if (code === 2) {
149
+ segments.push({ id, kind: "line", start: from.id, end: end.id });
150
+ }
151
+ else {
152
+ // Control points: the cubic's own, or a quadratic's one control point raised to a cubic.
153
+ const [c1x, c1y, c2x, c2y] = code === 4
154
+ ? values
155
+ : [from.x + 2 / 3 * (values[0] - from.x), from.y + 2 / 3 * (values[1] - from.y),
156
+ end.x + 2 / 3 * (values[0] - end.x), end.y + 2 / 3 * (values[1] - end.y)];
157
+ segments.push({
158
+ id, kind: "cubic", start: from.id, end: end.id,
159
+ startHandle: { id: vectorHandleId(`h${String(segments.length)}-start`), dx: c1x - from.x, dy: c1y - from.y },
160
+ endHandle: { id: vectorHandleId(`h${String(segments.length)}-end`), dx: c2x - end.x, dy: c2y - end.y },
161
+ });
162
+ }
163
+ loop.push({ segmentId: id, direction: "forward" });
164
+ current = end;
165
+ moveTo = { x: end.x, y: end.y };
166
+ }
167
+ finish(false);
168
+ if (loops.length > 0)
169
+ network.regions.push({ id: vectorRegionId(`r${String(network.regions.length)}`), windingRule, loops });
170
+ }
171
+ /** The node's `fillGeometry` as one network, a region per path; throws `GeometryRefused`. */
172
+ function fillGeometryNetwork(node, walk, vectorData) {
173
+ const where = `node ${node.id}`;
174
+ const paths = field(node.change, "fillGeometry", "list", where) ?? [];
175
+ if (paths.length > VECTOR_GEOMETRY_LIMITS.paths) {
176
+ throw new GeometryRefused("too-many-paths", `fillGeometry has ${String(paths.length)} paths, over the limit of ${String(VECTOR_GEOMETRY_LIMITS.paths)}`);
177
+ }
178
+ const network = { vertices: [], segments: [], regions: [] };
179
+ const styled = [];
180
+ const budget = { left: VECTOR_GEOMETRY_LIMITS.commands };
181
+ paths.forEach((path, index) => {
182
+ const at = `fillGeometry[${String(index)}]`;
183
+ const reference = isObject(path) ? field(path, "commandsBlob", "number", `${where} ${at}`) : undefined;
184
+ if (!isObject(path) || reference === undefined)
185
+ throw new GeometryRefused("not-a-path", `${at} is not a Path with a commandsBlob`);
186
+ const rule = field(path, "windingRule", "string", `${where} ${at}`) ?? "NONZERO";
187
+ if (rule !== "NONZERO" && rule !== "ODD")
188
+ throw new GeometryRefused("unknown-winding-rule", `${at} has winding rule ${rule}`);
189
+ const styleId = field(path, "styleID", "number", `${where} ${at}`) ?? 0;
190
+ const bytes = walk.blob(reference);
191
+ if (bytes === undefined)
192
+ throw new GeometryRefused("blob-missing", `${at} refers to commands blob ${String(reference)}, which the message does not have`);
193
+ const blobWhere = `${at} commands blob ${String(reference)}`;
194
+ const regionIndex = network.regions.length;
195
+ addRegion(network, decodeCommands(bytes, budget, walk.vectorCommands, blobWhere), rule === "ODD" ? "evenodd" : "nonzero", blobWhere);
196
+ if (styleId > 0 && network.regions.length > regionIndex)
197
+ styled.push({ index: regionIndex, styleId, at });
198
+ });
199
+ if (network.segments.length === 0) {
200
+ throw new GeometryRefused("no-geometry", paths.length === 0
201
+ ? "the node has no fillGeometry and no vectorData.vectorNetworkBlob"
202
+ : "no fillGeometry path draws a line or curve");
203
+ }
204
+ if (styled.length > 0)
205
+ applyRegionStyles(node, walk, network, vectorStyleTable(vectorData, where), styled, true);
206
+ return network;
207
+ }
208
+ /** The renderer places layer gradients on the path's region bounds, or on its edges when there are no regions. */
209
+ function pathPaintBox(network) {
210
+ const boxes = network.regions.map(regionBoxes(network)).filter((box) => box !== undefined);
211
+ if (boxes.length === 0)
212
+ return getVectorNetworkBounds(network) ?? undefined;
213
+ const left = Math.min(...boxes.map((box) => box.x)), top = Math.min(...boxes.map((box) => box.y));
214
+ const right = Math.max(...boxes.map((box) => box.x + box.width)), bottom = Math.max(...boxes.map((box) => box.y + box.height));
215
+ return { x: left, y: top, width: right - left, height: bottom - top };
216
+ }
217
+ /**
218
+ * A path node's Figma `transform` as its Taco transform (Taco's [a, b, c, d,
219
+ * e, f] is Figma's [m00, m10, m01, m11, m02, m12]), or `null` after reporting
220
+ * the node left out when the transform is incomplete or squashes it flat.
221
+ */
222
+ export function pathTransform(node, walk) {
223
+ const where = `node ${node.id}`;
224
+ const m = field(node.change, "transform", "object", where);
225
+ const values = m && ["m00", "m10", "m01", "m11", "m02", "m12"].map((key) => field(m, key, "number", `${where} transform`));
226
+ if (!values || values.some((value) => value === undefined)) {
227
+ walk.report("node-left-out", "the node has no complete transform");
228
+ return null;
229
+ }
230
+ const transform = values;
231
+ if (!transformIsInvertible(transform)) {
232
+ walk.report("node-left-out", "the transform squashes the node flat");
233
+ return null;
234
+ }
235
+ return transform;
236
+ }
237
+ /**
238
+ * A path node's strokes, gradients placed on `box`, and the cap of its ends
239
+ * and dashes from Figma's `strokeCap`; a cap Taco has no match for is
240
+ * reported and imported flat.
241
+ */
242
+ export function pathStrokes(node, walk, box) {
243
+ const capName = field(node.change, "strokeCap", "string", `node ${node.id}`) ?? "NONE";
244
+ const dashCap = Object.hasOwn(STROKE_CAPS, capName) ? STROKE_CAPS[capName] : undefined;
245
+ const cap = node.type === "VECTOR" ? endCapOf(capName) : dashCap;
246
+ const strokes = nodeStrokes(node, walk, box).map((stroke) => ({ ...stroke, dashCap: dashCap ?? "none" }));
247
+ if (strokes.length > 0 && cap === undefined)
248
+ walk.report("approximated", `stroke cap ${capName} is not imported yet; the ends are flat`);
249
+ return { strokes, cap: cap ?? "none" };
250
+ }
251
+ /**
252
+ * A Figma VECTOR as a Taco path. The shape is the node's editable vector
253
+ * network (`vectorData.vectorNetworkBlob`, what a paste carries) when it has
254
+ * one, else its `fillGeometry`, the outline Figma fills (also when the
255
+ * network is refused, which is reported); either is in the
256
+ * node's own space. Figma's `transform` places it exactly as the path's
257
+ * transform (Taco's [a, b, c, d, e, f] is Figma's [m00, m10, m01, m11, m02,
258
+ * m12]), so scale and skew are kept. Corner radii are already in a
259
+ * `fillGeometry` outline; with a network the node's `cornerRadius` is the
260
+ * path's corner radius. `strokeGeometry` (the stroke outlined) is not
261
+ * read: Taco draws the strokes from the path.
262
+ */
263
+ export const convertVector = (node, walk) => {
264
+ const where = `node ${node.id}`;
265
+ const transform = pathTransform(node, walk);
266
+ if (transform === null)
267
+ return null;
268
+ let vectorNetwork;
269
+ let endpointCaps = {};
270
+ let fromNetwork = false;
271
+ let networkProblem;
272
+ const vectorData = field(node.change, "vectorData", "object", where);
273
+ const networkBlob = vectorData && field(vectorData, "vectorNetworkBlob", "number", `${where} vectorData`);
274
+ const hasFillGeometry = (field(node.change, "fillGeometry", "list", where)?.length ?? 0) > 0;
275
+ if (vectorData !== undefined && networkBlob !== undefined) {
276
+ // Reports about the network are kept only if the network is used.
277
+ const networkReports = [];
278
+ const networkWalk = {
279
+ ...walk,
280
+ report: (kind, reason) => { networkReports.push([kind, reason]); },
281
+ };
282
+ try {
283
+ const decoded = vectorDataNetwork(node, vectorData, networkBlob, networkWalk);
284
+ vectorNetwork = decoded.network;
285
+ endpointCaps = decoded.endpointCaps;
286
+ fromNetwork = true;
287
+ for (const [kind, reason] of networkReports)
288
+ walk.report(kind, reason);
289
+ }
290
+ catch (error) {
291
+ if (!(error instanceof NetworkRefused))
292
+ throw error;
293
+ if (!hasFillGeometry) {
294
+ walk.report("node-left-out", error.message);
295
+ return null;
296
+ }
297
+ networkProblem = error.message;
298
+ }
299
+ }
300
+ if (vectorNetwork === undefined) {
301
+ try {
302
+ vectorNetwork = fillGeometryNetwork(node, walk, vectorData);
303
+ }
304
+ catch (error) {
305
+ if (!(error instanceof GeometryRefused))
306
+ throw error;
307
+ walk.report("node-left-out", networkProblem === undefined ? error.message : `${networkProblem}; ${error.message}`);
308
+ return null;
309
+ }
310
+ if (networkProblem !== undefined)
311
+ walk.report("approximated", `${networkProblem}; the fillGeometry outline is used instead`);
312
+ }
313
+ const base = layerBase(node, walk, "Vector", true);
314
+ let bounds;
315
+ const paintBox = () => {
316
+ if (bounds === undefined)
317
+ bounds = pathPaintBox(vectorNetwork) ?? null;
318
+ return bounds ?? undefined;
319
+ };
320
+ const fills = nodePaints(node, walk, "fillPaints", paintBox);
321
+ const { strokes, cap } = pathStrokes(node, walk, paintBox);
322
+ const radius = fromNetwork ? field(node.change, "cornerRadius", "number", where) ?? 0 : 0;
323
+ const style = {
324
+ ...(fills.length > 0 ? { fills } : {}), ...(strokes.length > 0 ? { strokes } : {}), ...(radius > 0 ? { cornerRadius: radius } : {}),
325
+ ...nodeEffects(node, walk),
326
+ };
327
+ const path = { ...base, type: "shape", shape: "path", vectorNetwork, transform, style, startCap: cap, endCap: cap };
328
+ const converted = lineWhereItFills(path, node.change, endpointCaps);
329
+ if (converted.shape === "path" && (node.type === "VECTOR" || Object.keys(endpointCaps).length > 0)) {
330
+ carry(converted, { vectorStrokeCaps: endpointCaps });
331
+ }
332
+ if (converted.shape === "path" && converted.vectorNetwork.regions.some((region) => region.fills?.some(imageCropOf))) {
333
+ const size = field(node.change, "size", "object", where);
334
+ if (size) {
335
+ const width = field(size, "x", "number", `${where} size`), height = field(size, "y", "number", `${where} size`);
336
+ if (width !== undefined && height !== undefined)
337
+ carry(converted, { regionCropSize: { width, height } });
338
+ }
339
+ }
340
+ return converted;
341
+ };
342
+ /** Moondraft's boolean group operation for each Figma `booleanOperation`. */
343
+ const BOOLEAN_OPERATIONS = { UNION: "union", SUBTRACT: "subtract", INTERSECT: "intersect", XOR: "exclude" };
344
+ /** The Figma layer types a boolean group combines as shapes (Moondraft imports them as paths or rectangles). */
345
+ const OPERAND_SHAPES = new Set(["VECTOR", "RECTANGLE", "ROUNDED_RECTANGLE", "ELLIPSE", "STAR", "REGULAR_POLYGON", "LINE"]);
346
+ /**
347
+ * Moondraft patch 0010: how a Figma BOOLEAN_OPERATION imports. A live boolean
348
+ * group (`operation`, Moondraft's name for it) when Moondraft's boolean group
349
+ * can stand for it: an operation it has, a transform that only moves and
350
+ * turns, a node that does not fill its auto layout parent (a group cannot),
351
+ * and shown operands that are all shapes, nested boolean operations or groups
352
+ * of those (a boolean group skips any other layer, such as text, and a mask).
353
+ * Otherwise `why` says what keeps it flattened to its outline.
354
+ */
355
+ export function liveBooleanOf(node, inFlow = false) {
356
+ const named = node.change["booleanOperation"];
357
+ const operation = typeof named === "string" ? BOOLEAN_OPERATIONS[named] : undefined;
358
+ if (operation === undefined)
359
+ return { why: typeof named === "string" ? `its operation ${named} has no boolean group` : "it names no operation" };
360
+ const geometry = frameGeometry(node);
361
+ if (geometry === null)
362
+ return { why: "it has no complete size or transform" };
363
+ const { m00, m01, m10, m11 } = geometry.m, tolerance = 1e-4;
364
+ if (Math.abs(m00 ** 2 + m10 ** 2 - 1) > tolerance || Math.abs(m01 ** 2 + m11 ** 2 - 1) > tolerance || Math.abs(m00 * m01 + m10 * m11) > tolerance) {
365
+ return { why: "its transform scales or skews, which a boolean group does not" };
366
+ }
367
+ // Moondraft's adapter keeps no flip on a frame, so the operands would land mirrored.
368
+ if (m00 * m11 - m01 * m10 < 0)
369
+ return { why: "it is flipped, which a boolean group does not keep" };
370
+ if (asksToFill(node.change))
371
+ return { why: "it fills its auto layout parent, which a boolean group does not" };
372
+ // A group's box is its layers' (the editor fits it to them), so in an auto layout flow it must be the operation's own.
373
+ if (inFlow && !operandsFill(node, geometry.sides))
374
+ return { why: "it sits in an auto layout flow, where a boolean group would take its operands' box, not its own" };
375
+ const unsupported = (layer) => {
376
+ for (const child of layer.children) {
377
+ if (child.change["visible"] === false)
378
+ continue;
379
+ if (child.change["mask"] === true)
380
+ return "an operand is a mask";
381
+ // A nested boolean operation is an operand either way: a boolean group, or the path it is flattened to.
382
+ if (OPERAND_SHAPES.has(child.type) || child.type === "BOOLEAN_OPERATION")
383
+ continue;
384
+ if (child.type === "GROUP" || (child.type === "FRAME" && isFigmaGroup(child.change))) {
385
+ const inside = unsupported(child);
386
+ if (inside !== undefined)
387
+ return inside;
388
+ continue;
389
+ }
390
+ return `an operand is a ${child.type}, which a boolean group does not combine`;
391
+ }
392
+ return undefined;
393
+ };
394
+ const why = unsupported(node);
395
+ return why === undefined ? { operation } : { why };
396
+ }
397
+ /**
398
+ * Whether the boxes its operands will have (all of them: a group fits its hidden layers too) together are the node's
399
+ * own box. A nested boolean operation kept live is a boolean group fitted to its own operands, so its box is theirs.
400
+ */
401
+ function operandsFill(node, sides) {
402
+ const bounds = fittedBounds(node);
403
+ const near = (a, b) => Math.abs(a - b) < 0.01;
404
+ return bounds !== null && near(bounds[0], 0) && near(bounds[1], 0) && near(bounds[2], sides.x) && near(bounds[3], sides.y);
405
+ }
406
+ /** The box [x0, y0, x1, y1], in the node's own space, of its operands as imported, or `null` if one has no geometry. */
407
+ function fittedBounds(node) {
408
+ let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;
409
+ for (const child of node.children) {
410
+ const geometry = frameGeometry(child);
411
+ if (geometry === null)
412
+ return null;
413
+ const { sides: { x: w, y: h }, m } = geometry;
414
+ let own = [0, 0, w, h];
415
+ if (child.type === "BOOLEAN_OPERATION" && "operation" in liveBooleanOf(child))
416
+ own = fittedBounds(child);
417
+ if (own === null)
418
+ return null;
419
+ const [a0, b0, a1, b1] = own;
420
+ for (const [x, y] of [[a0, b0], [a1, b0], [a0, b1], [a1, b1]]) {
421
+ const px = m.m00 * x + m.m01 * y + m.m02, py = m.m10 * x + m.m11 * y + m.m12;
422
+ x0 = Math.min(x0, px);
423
+ y0 = Math.min(y0, py);
424
+ x1 = Math.max(x1, px);
425
+ y1 = Math.max(y1, py);
426
+ }
427
+ }
428
+ return x0 <= x1 ? [x0, y0, x1, y1] : null;
429
+ }
430
+ /** Why the walk flattened a boolean operation it could otherwise keep live, by node. */
431
+ const flattenedBecause = new WeakMap();
432
+ /** Moondraft patch 0010: why a boolean operation was flattened, for the walk's report line, if it says. */
433
+ export function whyFlattened(node, inFlow = false) {
434
+ const live = liveBooleanOf(node, inFlow);
435
+ return "why" in live ? live.why : flattenedBecause.get(node);
436
+ }
437
+ /**
438
+ * A Figma BOOLEAN_OPERATION. Moondraft patch 0010: one `liveBooleanOf` passes
439
+ * is a frame holding its operands, which the walk imports as its layers; it
440
+ * carries its operation (`metadata.figma.boolean`) for Moondraft's adapter,
441
+ * which makes it a boolean group. Its frame is the operation's own, and it
442
+ * takes the constraints its operands share, as the flattened path does. Its
443
+ * look (fills, strokes, effects) is the one the outline would have. The
444
+ * outline Figma stores for the result (`fillGeometry`) is carried too, as the
445
+ * group's first result, so it draws as the flattened path did until an edit
446
+ * recuts it; without one (Figma often stores none for a nested operation) the
447
+ * renderer cuts the result from the operands, and one in an auto layout flow
448
+ * whose operands do not fill its box carries `fixedBox`, for a frame of its
449
+ * own size around the group. Any other is a Taco path drawn
450
+ * from its `fillGeometry`, its operands not imported (the walk reports the
451
+ * flattening once, with the reason), or is left out without one, as before.
452
+ */
453
+ export const convertBooleanOperation = (node, walk) => {
454
+ const hasOutline = (field(node.change, "fillGeometry", "list", `node ${node.id}`)?.length ?? 0) > 0;
455
+ const { vectorData, ...change } = node.change;
456
+ // Boolean results use the stored outline, which can still refer to the style table.
457
+ const outlineStyles = isObject(vectorData) ? { styleOverrideTable: vectorData["styleOverrideTable"] } : undefined;
458
+ const flat = { ...node, change: { ...change, ...operandConstraints(node), vectorData: outlineStyles } };
459
+ // Without an outline to flatten to, one in a flow stays live (its box becomes its operands'), rather than left out.
460
+ const live = liveBooleanOf(node, walk.inFlow === true && hasOutline);
461
+ // Kept live there, it sits in a frame of its own box (Moondraft's adapter), so that the flow places its siblings right.
462
+ const fixedBox = !hasOutline && walk.inFlow === true && "operation" in live && !operandsFill(node, frameGeometry(node).sides);
463
+ if (!("operation" in live)) {
464
+ if (hasOutline)
465
+ return convertVector(flat, walk);
466
+ walk.report("node-left-out", `the boolean operation has no fillGeometry outline to flatten it to, and ${live.why}`);
467
+ return null;
468
+ }
469
+ // The outline is the group's first result and the source of its look; its reports are kept for the layer it makes.
470
+ const reports = [];
471
+ const outline = hasOutline ? convertVector(flat, { ...walk, report: (kind, reason) => { reports.push([kind, reason]); } }) : null;
472
+ const forward = () => { for (const [kind, reason] of reports)
473
+ walk.report(kind, reason); };
474
+ if (hasOutline && (outline?.type !== "shape" || outline.shape !== "path")) {
475
+ forward();
476
+ return outline;
477
+ }
478
+ if (outline?.type === "shape" && outline.shape === "path" && outline.vectorNetwork.regions.some((region) => region.fills !== undefined)) {
479
+ // Keep authored region paints on a path so recutting the boolean cannot discard them.
480
+ flattenedBecause.set(node, "its regions are painted apart, which one boolean group look does not");
481
+ forward();
482
+ return outline;
483
+ }
484
+ // framedBase reports the layer diagnostics the outline's own conversion reported too: forward the outline's others.
485
+ const shared = new Set();
486
+ const base = framedBase(flat, { ...walk, report: (kind, reason) => { shared.add(`${kind}\n${reason}`); walk.report(kind, reason); } }, "Boolean", true);
487
+ if (base === null)
488
+ return null;
489
+ for (const [kind, reason] of reports)
490
+ if (!shared.has(`${kind}\n${reason}`))
491
+ walk.report(kind, reason);
492
+ const { cornerRadius: _radius, cornerRadii: _radii, cornerSmoothing: _smoothing, ...style } = outline?.type === "shape" ? outline.style
493
+ : { ...visualStyle(node, walk), ...nodeEffects(node, walk) };
494
+ const frame = { ...base, type: "frame", children: walk.convertChildren(), layout: { kind: "absolute" }, style, clipContent: false };
495
+ if (outline?.type === "shape" && outline.shape === "path") {
496
+ // The outline's transform in the operation's own space (its transform only moves and turns, see liveBooleanOf), so
497
+ // that it stays right when the walk moves the operation's frame (a group it is in is fitted to its layers).
498
+ const { m00, m01, m02, m10, m11, m12 } = frameGeometry(node).m;
499
+ const [a, b, c, d, e, f] = outline.transform;
500
+ const turned = [m00 * a + m10 * b, m01 * a + m11 * b, m00 * c + m10 * d, m01 * c + m11 * d,
501
+ m00 * (e - m02) + m10 * (f - m12), m01 * (e - m02) + m11 * (f - m12)];
502
+ // The outline is placed by the operation's own transform, so this is the identity but for float roundoff, which
503
+ // would split clipboard variants that differ only in rotation (variantTrees compares it exactly).
504
+ const identity = [1, 0, 0, 1, 0, 0];
505
+ const local = turned.every((v, i) => Math.abs(v - identity[i]) < 1e-6) ? identity : turned;
506
+ carry(frame, { boolean: { operation: live.operation, transform: local, vectorNetwork: outline.vectorNetwork } });
507
+ }
508
+ else
509
+ carry(frame, { boolean: { operation: live.operation, ...(fixedBox ? { fixedBox: true } : {}) } });
510
+ return frame;
511
+ };
512
+ /**
513
+ * The constraints a flattened boolean operation resizes by. Figma resizes a
514
+ * boolean operation like a group: each operand follows its own constraints
515
+ * and the result is drawn around them, so the operation's own constraints
516
+ * (often left unset, which reads as MIN) do not place it. The flattened path
517
+ * takes, on each axis, the constraint every operand shares (an operand that
518
+ * is itself a boolean operation or group, including a Figma group stored as
519
+ * a FRAME, shares its own operands'; hidden operands do not count); where
520
+ * they differ, or there are no shown operands, the node's own constraint stays.
521
+ * A check icon made as a union of two SCALE strokes, in a component shown
522
+ * smaller, otherwise kept its full size and was clipped.
523
+ */
524
+ function operandConstraints(node) {
525
+ // Hidden operands take no part in the result, so their constraints do not count.
526
+ const shown = (layer) => layer.children.filter((child) => child.change["visible"] !== false);
527
+ const shared = (name, layer) => {
528
+ const own = layer.change[name] ?? "MIN";
529
+ const looksThrough = layer.type === "BOOLEAN_OPERATION" || layer.type === "GROUP" || (layer.type === "FRAME" && isFigmaGroup(layer.change));
530
+ if (!looksThrough)
531
+ return own;
532
+ const values = new Set(shown(layer).map((child) => shared(name, child)));
533
+ return values.size === 1 ? [...values][0] : own;
534
+ };
535
+ const constraints = {};
536
+ for (const name of ["horizontalConstraint", "verticalConstraint"]) {
537
+ const values = new Set(shown(node).map((child) => shared(name, child)));
538
+ if (values.size === 1)
539
+ constraints[name] = [...values][0];
540
+ }
541
+ return constraints;
542
+ }
543
+ /**
544
+ * `path` as a Taco line when the Figma node asks to fill its auto layout
545
+ * parent (`stackChildPrimaryGrow` above 0 or `stackChildAlignSelf` STRETCH)
546
+ * and the path is one straight level segment that is only moved (not turned,
547
+ * flipped, scaled or skewed) and fills no region; else `path` as it is. A
548
+ * path cannot fill its parent in Taco, while a line fills along its length:
549
+ * the renderer draws it from (0, 0) to (width, 0) of its box, so it follows
550
+ * the filled width with its stroke width kept. HeroUI's dividers are such
551
+ * VECTORs and LINEs. A line's stroke is drawn centred, as Figma draws the
552
+ * stroke of an open path.
553
+ */
554
+ export function lineWhereItFills(path, change, endpointCaps) {
555
+ if (!asksToFill(change))
556
+ return path;
557
+ const tolerance = 1e-4;
558
+ const [a, b, c, d, e, f] = path.transform;
559
+ if (Math.abs(a - 1) > tolerance || Math.abs(b) > tolerance || Math.abs(c) > tolerance || Math.abs(d - 1) > tolerance)
560
+ return path;
561
+ const { vertices, segments, regions } = path.vectorNetwork;
562
+ const segment = segments[0];
563
+ if (vertices.length !== 2 || segments.length !== 1 || segment?.kind !== "line" || regions.length > 0)
564
+ return path;
565
+ const start = vertices.find((vertex) => vertex.id === segment.start);
566
+ const end = vertices.find((vertex) => vertex.id === segment.end);
567
+ if (start === undefined || end === undefined || start === end || Math.abs(start.y - end.y) > tolerance)
568
+ return path;
569
+ const { vectorNetwork: _network, transform: _transform, shape: _shape, style, startCap = "round", endCap = "round", ...base } = path;
570
+ const { fills: _fills, cornerRadius: _radius, strokes, ...rest } = style;
571
+ const centred = strokes?.map((stroke) => ({ ...stroke, position: "center" }));
572
+ // A segment drawn right to left keeps its caps on the ends they were on.
573
+ const reversed = end.x < start.x;
574
+ const ownStartCap = endpointCaps?.[start.id] ?? startCap;
575
+ const ownEndCap = endpointCaps?.[end.id] ?? endCap;
576
+ const limits = sizeLimitsOf(change);
577
+ const line = {
578
+ ...base,
579
+ type: "shape",
580
+ shape: "line",
581
+ frame: { x: e + Math.min(start.x, end.x), y: f + start.y, width: Math.abs(end.x - start.x), height: 0 },
582
+ rotation: 0,
583
+ ...(Object.keys(limits).length > 0 ? { resizing: limits } : {}),
584
+ style: { ...rest, ...(centred === undefined ? {} : { strokes: centred }) },
585
+ startCap: reversed ? ownEndCap : ownStartCap,
586
+ endCap: reversed ? ownStartCap : ownEndCap,
587
+ };
588
+ return line;
589
+ }
590
+ /** Whether the Figma node grows along its stack's main axis or stretches across it. */
591
+ function asksToFill(change) {
592
+ const grow = change["stackChildPrimaryGrow"];
593
+ return (typeof grow === "number" && Number.isFinite(grow) && grow > 0) || change["stackChildAlignSelf"] === "STRETCH";
594
+ }
595
+ /** Moondraft patch (../carry.ts): a STAR or REGULAR_POLYGON as its `fillGeometry` path (as a VECTOR), its parameters carried. */
596
+ export const convertStarOrPolygon = (node, walk) => {
597
+ const converted = convertVector(node, walk);
598
+ if (converted === null)
599
+ return null;
600
+ const where = `node ${node.id}`;
601
+ const count = field(node.change, "count", "number", where);
602
+ const size = field(node.change, "size", "object", where);
603
+ const width = size && field(size, "x", "number", `${where} size`), height = size && field(size, "y", "number", `${where} size`);
604
+ if (count === undefined || !(width !== undefined && width > 0) || !(height !== undefined && height > 0))
605
+ return converted;
606
+ const ratio = field(node.change, "starInnerScale", "number", where) ?? 0.382;
607
+ carry(converted, node.type === "STAR" ? { shape: { type: "star", count, ratio, width, height } } : { shape: { type: "polygon", count, width, height } });
608
+ return converted;
609
+ };