@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,232 @@
1
+ import type { AssetId, ComponentDefinition, ComponentId, NodeId, SceneNode, TextStyle, VariableCollection, VariableModes } from "../../model/index.ts";
2
+ /**
3
+ * The limits of one import: `nodes` is the most entries in the message's
4
+ * `nodeChanges` list, and also the most Taco layers the import builds: a
5
+ * component's layers count once, and an instance counts as one layer,
6
+ * since it does not copy its component's layers (a node that is left out
7
+ * is not counted); `depth` the deepest nesting, an imported root being
8
+ * level 1; `vectorCommands` the most drawing commands
9
+ * read from all VECTOR geometry together, so that many layers sharing one
10
+ * large blob cannot add up past it (a VECTOR that would go over is left out
11
+ * and reported). The defaults depend on where the roots come from; see
12
+ * `DEFAULT_FIGMA_IMPORT_LIMITS`.
13
+ */
14
+ export interface FigmaImportLimits {
15
+ readonly nodes: number;
16
+ readonly depth: number;
17
+ readonly vectorCommands: number;
18
+ }
19
+ /**
20
+ * The default limits for each root source, a guard against an import that
21
+ * would use up the host's memory. A whole .fig file (`"pages"`) may build
22
+ * 500,000 layers: a design system file such as HeroUI v3 (29,179 node
23
+ * changes; 26,451 layers built, its 2,997 components' layers once and each
24
+ * instance as one) keeps about 1.8 KB of heap per built layer (measured 20
25
+ * Oct 2026; 3 KB when instances copied their components' layers), so
26
+ * 500,000 layers come to about 1 to 1.5 GB. A paste
27
+ * (`"clipboard-selection"`) keeps its limit of 100,000. Both: 64 levels,
28
+ * 1,000,000 vector commands.
29
+ * `FigmaImportOptions.limits` overrides any of them.
30
+ */
31
+ export declare const DEFAULT_FIGMA_IMPORT_LIMITS: Readonly<Record<FigmaRootSource, FigmaImportLimits>>;
32
+ /**
33
+ * Where the roots come from. `"clipboard-selection"`: the nodes named by
34
+ * `clipboardSelectionRegions`, in the message's order (what a person copied).
35
+ * `"pages"`: the children of every `CANVAS` under the `DOCUMENT` node 0:0,
36
+ * leaving out pages marked `internalOnly` (a .fig file).
37
+ */
38
+ export type FigmaRootSource = "clipboard-selection" | "pages";
39
+ export interface FigmaImportOptions {
40
+ /** Returns a fresh id for every created node, so the host controls ids. */
41
+ readonly idSource: () => string;
42
+ /** When omitted: `"clipboard-selection"` if the message has a non-empty `clipboardSelectionRegions`, else `"pages"`. */
43
+ readonly roots?: FigmaRootSource;
44
+ readonly limits?: Partial<FigmaImportLimits>;
45
+ /**
46
+ * The bytes of the image whose SHA-1 hash is `hashHex` (40 lowercase hex
47
+ * digits, as Figma names a .fig file's `images/<hash>` entry), or
48
+ * `undefined` when the host has none. The importer never fetches: an image
49
+ * paint whose bytes are not supplied is left out and reported once. A
50
+ * missing `mimeType` is read from the bytes (PNG, JPEG, GIF or WebP); a
51
+ * missing `width` and `height` come from the paint's original image size.
52
+ */
53
+ readonly images?: (hashHex: string) => FigmaSuppliedImage | undefined;
54
+ /**
55
+ * Returns the `key` of each imported component, unique in the document
56
+ * it goes into, given the Figma node the component comes from (a SYMBOL,
57
+ * or the COMPONENT_SET a set's component is made from). When omitted, a
58
+ * file's (`"pages"`) keys are the same on every import of the same file:
59
+ * the node's Figma `componentKey` where it has one that no other component
60
+ * of the import took, else `figma-<guid>`. A paste's keys are random UUIDs,
61
+ * since the same component may be pasted twice into one document.
62
+ */
63
+ readonly componentKeySource?: (source: FigmaComponentSource) => string;
64
+ /**
65
+ * Whether the message's variables are imported as `variableCollections` and the layers bound to them (the
66
+ * default). `false` is for a host that cannot add variables to the document, such as the clipboard paste: no
67
+ * variable is imported, and every binding keeps its value and is reported.
68
+ */
69
+ readonly bindVariables?: boolean;
70
+ /**
71
+ * Whether each Figma text style a text layer names (`styleIdForText`) is imported as a shared text style in
72
+ * `textStyles` and the layer's runs linked to it (the default). `false` is for a host that cannot add text styles to
73
+ * the document, such as the clipboard paste: the runs keep the style's values as direct formatting, reported once
74
+ * for each style.
75
+ */
76
+ readonly textStyles?: boolean;
77
+ }
78
+ /** The Figma node an imported component comes from, for `FigmaImportOptions.componentKeySource`. */
79
+ export interface FigmaComponentSource {
80
+ /** The SYMBOL's or COMPONENT_SET's guid as `sessionID:localID`. */
81
+ readonly figmaId: string;
82
+ /** Its Figma `componentKey`, when it has one (a published component or set). */
83
+ readonly componentKey?: string;
84
+ }
85
+ /** The bytes of one image, as the host supplies them. */
86
+ export interface FigmaSuppliedImage {
87
+ readonly bytes: Uint8Array;
88
+ readonly mimeType?: string;
89
+ readonly width?: number;
90
+ readonly height?: number;
91
+ }
92
+ /**
93
+ * One image the imported paints use. Its `id` is `figma-image-<hash>`, so the
94
+ * same image is one asset across nodes and imports. The host stores it as a
95
+ * Taco `ImageAsset`, such as with `source: { kind: "data", data: <bytes as base64> }`.
96
+ */
97
+ export interface FigmaImportedImage {
98
+ readonly id: AssetId;
99
+ /** The image's SHA-1 hash as 40 lowercase hex digits. */
100
+ readonly hash: string;
101
+ readonly mimeType: string;
102
+ readonly bytes: Uint8Array;
103
+ readonly width?: number;
104
+ readonly height?: number;
105
+ }
106
+ /**
107
+ * `"node-left-out"`: the node and every layer inside it are not imported.
108
+ * `"property-left-out"`: the node is imported without one property.
109
+ * `"approximated"`: a property is imported, but not exactly.
110
+ */
111
+ export type FigmaImportReportKind = "node-left-out" | "property-left-out" | "approximated";
112
+ export interface FigmaImportReportEntry {
113
+ /** The Figma guid as `sessionID:localID`, such as `12:34`. */
114
+ readonly nodeId: string;
115
+ /** The Figma node type, such as `VECTOR`; empty when the message has no such node. */
116
+ readonly nodeType: string;
117
+ /** Where the node sits, such as `CANVAS "Page 1" > FRAME "Card" > TEXT "Title"`. */
118
+ readonly nodePath: string;
119
+ /** The kind of layer: `nodeType`, except `GROUP` for a FRAME that Figma uses as a group. */
120
+ readonly layerType: string;
121
+ readonly kind: FigmaImportReportKind;
122
+ /** What was left out or changed, in plain words. */
123
+ readonly reason: string;
124
+ /**
125
+ * The layers inside the node that this entry leaves out with it, counted
126
+ * by `layerType` in the order first met; empty when it leaves none out.
127
+ * One import names at most 32 layer types; layers of any type met after
128
+ * those count under `OTHER` (only a crafted message has that many types).
129
+ */
130
+ readonly layersInside: readonly FigmaLayerCount[];
131
+ }
132
+ /** How many layers of one `layerType`. */
133
+ export interface FigmaLayerCount {
134
+ readonly layerType: string;
135
+ readonly count: number;
136
+ }
137
+ /** One imported page of a .fig file, with its top-level nodes back to front. */
138
+ export interface FigmaImportedPage {
139
+ readonly figmaId: string;
140
+ readonly name: string;
141
+ readonly roots: readonly NodeId[];
142
+ /** The variable mode the page chooses for each collection, by collection id; omitted when it chooses none. */
143
+ readonly variableModes?: VariableModes;
144
+ }
145
+ export interface FigmaImportResult {
146
+ /** How the reader selected the imported roots. */
147
+ readonly rootSource: FigmaRootSource;
148
+ /** The imported top-level nodes: every page's roots in page order, or the copied nodes. */
149
+ readonly roots: readonly SceneNode[];
150
+ /** Every created node, `roots` and component layers included, parents before their children. */
151
+ readonly nodes: readonly SceneNode[];
152
+ /** The imported pages; empty when the roots came from a clipboard selection. */
153
+ readonly pages: readonly FigmaImportedPage[];
154
+ /** Everything not imported exactly, in the order the walk met it. */
155
+ readonly report: readonly FigmaImportReportEntry[];
156
+ /** The images the imported paints use, keyed by asset id, each once. */
157
+ readonly assets: Readonly<Record<AssetId, FigmaImportedImage>>;
158
+ /**
159
+ * The layer each Figma node the walk met went to, keyed by the Figma guid
160
+ * as a report entry's `nodeId` gives it: the layer made from the node, or,
161
+ * for a node left out, the layer made from its nearest kept parent (none
162
+ * for a left-out root). A SYMBOL goes to its component's root, not to the
163
+ * instance that shows it where it sits. A slot's content frame goes to no
164
+ * layer. The layers inside it are copied for each instance that puts it
165
+ * in a slot, and each goes to the copy made for the first such instance
166
+ * in walk order; the others are reached through their instances' `slots`.
167
+ */
168
+ readonly layerIds: Readonly<Record<string, NodeId>>;
169
+ /**
170
+ * The components made from SYMBOLs: for a .fig file (`"pages"`) every
171
+ * SYMBOL on its pages, and each one on an internal-only page that an
172
+ * imported instance, swap or property names; for a clipboard selection
173
+ * each SYMBOL under the roots and each one an imported instance, swap or
174
+ * property names, wherever it sits in the message. A variant brings the
175
+ * other variants of its set. Each root is in `nodes` with no parent, at 0, 0; a SYMBOL
176
+ * under the roots shows there as an instance of its component.
177
+ *
178
+ * A COMPONENT_SET's imported variants are one component, named after the
179
+ * set (design 8.1): matching layers share one tree, differing fields use
180
+ * expressions, and missing or reordered children have presence conditions.
181
+ * A field the model cannot compute keeps the whole set as stacked variants
182
+ * and is named in the report. Each VARIANT property is an enum with the id
183
+ * `figma-<def guid>`, listed first in Figma's order, whose options are the
184
+ * values the imported variants use, in the set's value order, with the ids
185
+ * `figma-<def guid>=<value>`; its default is the top-left variant's value,
186
+ * Figma's default variant. The variants' other properties follow, each
187
+ * once. A set that does not have every combination gets a `validity`
188
+ * expression true for exactly the combinations it has. Instances, swaps,
189
+ * instance swap values and preferred components that named a variant name
190
+ * the set's component with the variant's values; an instance Figma shows
191
+ * at another size than its variant's (resized, or filling its parent)
192
+ * keeps that size. Overrides and `layerIds` address the merged layers.
193
+ * Duplicate tuples keep their unused layers hidden; instances show the
194
+ * first variant with those values. A set whose variants would contain
195
+ * the set itself stays one component per variant and is reported.
196
+ *
197
+ * A component's name leaves out the parts of Figma's name, between ` / `,
198
+ * that are only `property=value` pairs, as `Avatar / variant=img, type=success`
199
+ * becomes `Avatar`; a name that is nothing else takes its set's name.
200
+ */
201
+ readonly components: readonly ComponentDefinition[];
202
+ /** The component made from each SYMBOL, and from each merged COMPONENT_SET, keyed by its Figma guid. */
203
+ readonly componentIds: Readonly<Record<string, ComponentId>>;
204
+ /** Ordinary SYMBOL placements on public pages, keyed by the node ID of their intermediate instance. */
205
+ readonly componentPlacements: Readonly<Record<NodeId, ComponentId>>;
206
+ /**
207
+ * The message's variable collections, by id, for the host to add to the document's theme
208
+ * (`DocumentTheme.variableCollections`): the layers' `variableBindings` and `variableModes` name them. Empty
209
+ * when the message has none, or with `bindVariables: false`.
210
+ */
211
+ readonly variableCollections: Readonly<Record<string, VariableCollection>>;
212
+ /**
213
+ * The Figma text styles the text layers name, by id, for the host to add to the document's theme
214
+ * (`DocumentTheme.textStyles`): the runs' `styleId` names them. They name no font asset. Empty when no layer names
215
+ * one, or with `textStyles: false`.
216
+ */
217
+ readonly textStyles: Readonly<Record<string, TextStyle>>;
218
+ }
219
+ /**
220
+ * Why a message is refused: `not-node-changes` (not a `NODE_CHANGES` message,
221
+ * or a malformed node change), `duplicate-guid`, `cycle` (a node is its own
222
+ * ancestor), `no-roots` (no `DOCUMENT` 0:0, or no clipboard selection when
223
+ * one was asked for), `too-many-nodes` (over `limits.nodes`) and `too-deep`
224
+ * (over `limits.depth`).
225
+ */
226
+ export declare const FIGMA_IMPORT_ERROR_CODES: readonly ["not-node-changes", "duplicate-guid", "cycle", "no-roots", "too-many-nodes", "too-deep"];
227
+ export type FigmaImportErrorCode = (typeof FIGMA_IMPORT_ERROR_CODES)[number];
228
+ /** Thrown when a message is refused. Nothing is returned, so nothing is half imported. */
229
+ export declare class FigmaImportError extends Error {
230
+ readonly code: FigmaImportErrorCode;
231
+ constructor(code: FigmaImportErrorCode, message: string);
232
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * The default limits for each root source, a guard against an import that
3
+ * would use up the host's memory. A whole .fig file (`"pages"`) may build
4
+ * 500,000 layers: a design system file such as HeroUI v3 (29,179 node
5
+ * changes; 26,451 layers built, its 2,997 components' layers once and each
6
+ * instance as one) keeps about 1.8 KB of heap per built layer (measured 20
7
+ * Oct 2026; 3 KB when instances copied their components' layers), so
8
+ * 500,000 layers come to about 1 to 1.5 GB. A paste
9
+ * (`"clipboard-selection"`) keeps its limit of 100,000. Both: 64 levels,
10
+ * 1,000,000 vector commands.
11
+ * `FigmaImportOptions.limits` overrides any of them.
12
+ */
13
+ export const DEFAULT_FIGMA_IMPORT_LIMITS = {
14
+ "clipboard-selection": { nodes: 100_000, depth: 64, vectorCommands: 1_000_000 },
15
+ pages: { nodes: 500_000, depth: 64, vectorCommands: 1_000_000 },
16
+ };
17
+ /**
18
+ * Why a message is refused: `not-node-changes` (not a `NODE_CHANGES` message,
19
+ * or a malformed node change), `duplicate-guid`, `cycle` (a node is its own
20
+ * ancestor), `no-roots` (no `DOCUMENT` 0:0, or no clipboard selection when
21
+ * one was asked for), `too-many-nodes` (over `limits.nodes`) and `too-deep`
22
+ * (over `limits.depth`).
23
+ */
24
+ export const FIGMA_IMPORT_ERROR_CODES = ["not-node-changes", "duplicate-guid", "cycle", "no-roots", "too-many-nodes", "too-deep"];
25
+ /** Thrown when a message is refused. Nothing is returned, so nothing is half imported. */
26
+ export class FigmaImportError extends Error {
27
+ code;
28
+ constructor(code, message) {
29
+ super(`Figma import (${code}): ${message}`);
30
+ this.name = "FigmaImportError";
31
+ this.code = code;
32
+ }
33
+ }
@@ -0,0 +1,137 @@
1
+ import { type SceneNode, type TextNode, type VariableCollection, type VariableId, type VariableModeId, type VariableType, type VariableValue } from "../../model/index.ts";
2
+ import { type FigmaObject } from "./fields.ts";
3
+ import type { FigmaTreeNode } from "./tree.ts";
4
+ import { type FigmaStyleList } from "./styles.ts";
5
+ import type { FigmaImportReportKind } from "./types.ts";
6
+ type Report = (node: FigmaTreeNode, kind: FigmaImportReportKind, reason: string) => void;
7
+ /** A Figma variable as imported, or why it is not, under the Figma guid and the library key that name it. */
8
+ type Known = {
9
+ readonly id: VariableId;
10
+ readonly name: string;
11
+ readonly type: VariableType;
12
+ readonly opacity?: true;
13
+ } | {
14
+ readonly missing: string;
15
+ };
16
+ /** The variables of one import, and the collections they went to. */
17
+ export interface FigmaVariables {
18
+ readonly collections: Readonly<Record<string, VariableCollection>>;
19
+ /** Source of each retained collection and variable, keyed by its local ID. */
20
+ readonly sources: ReadonlyMap<string, FigmaTreeNode>;
21
+ /** Direct aliases by variable and local mode, including a missing mode's inherited default. */
22
+ readonly aliases: ReadonlyMap<string, ReadonlyMap<string, string>>;
23
+ /** Tests the mode values reachable through a saved file’s variable and its aliases.
24
+ * @param id - Imported variable ID.
25
+ * @param accepts - Predicate applied to each reachable literal.
26
+ * @returns Whether every mode satisfies the predicate.
27
+ */
28
+ valuesMatch(id: string, accepts: (value: VariableValue) => boolean): boolean;
29
+ /** Looks up a numeric variable with positive length in every reachable mode.
30
+ * @param data - Figma binding.
31
+ * @param where - Source location for diagnostics.
32
+ * @returns Variable ID, or null when any mode has an invalid size.
33
+ */
34
+ positiveLengthOf(data: unknown, where: string): VariableId | null;
35
+ /** The imported variable a Figma `VariableData` names, or why there is none. */
36
+ variableOf(data: unknown, where: string): Known;
37
+ /** The collection and mode a `variableModeBySetMap` entry names, or why there is none. */
38
+ modeOf(entry: unknown, where: string): {
39
+ readonly collectionId: string;
40
+ readonly modeId: VariableModeId;
41
+ } | string;
42
+ /**
43
+ * The style name a `FONT_STYLE` binding `data` of layer `figma` gives, in the mode the layer uses (its own or its
44
+ * nearest parent's choice for the variable's collection, else the default mode), and the variable's name; or why
45
+ * there is none. A variable deleted in Figma still gives its value. With `shownBy`, the layer is read as its instance
46
+ * shows it: the instance's choice comes before the component's, and the instance's parents replace the component's.
47
+ */
48
+ fontStyleOf(data: unknown, figma: FigmaTreeNode, where: string, shownBy?: ShownBy): {
49
+ readonly style: string;
50
+ readonly variable: string;
51
+ } | {
52
+ readonly missing: string;
53
+ };
54
+ /**
55
+ * The number a `FLOAT` variable binding `data` of layer `figma` gives, in the mode the layer uses as for
56
+ * `fontStyleOf` (with `shownBy`, as that instance shows the layer), and the variable's name; or why there is none.
57
+ */
58
+ numberOf(data: unknown, figma: FigmaTreeNode, where: string, shownBy?: ShownBy): {
59
+ readonly value: number;
60
+ readonly variable: string;
61
+ } | {
62
+ readonly missing: string;
63
+ };
64
+ /**
65
+ * The colour, as Taco hex, a `COLOR` variable binding `data` of layer `figma` gives, in the mode the layer uses as for
66
+ * `fontStyleOf` (with `shownBy`, as that instance shows the layer), and the variable's name; or why there is none.
67
+ */
68
+ colorOf(data: unknown, figma: FigmaTreeNode, where: string, shownBy?: ShownBy): {
69
+ readonly value: string;
70
+ readonly variable: string;
71
+ } | {
72
+ readonly missing: string;
73
+ };
74
+ }
75
+ /**
76
+ * An instance that shows a component layer, and the SYMBOL the instance shows; `modes` holds the instance's overrides of
77
+ * `variableModeBySetMap` on the SYMBOL's layers, by layer id.
78
+ */
79
+ export interface ShownBy {
80
+ readonly instance: FigmaTreeNode;
81
+ readonly symbol: FigmaTreeNode;
82
+ readonly modes?: ReadonlyMap<string, unknown>;
83
+ }
84
+ /**
85
+ * Every `VARIABLE_SET` of the message as a collection, its modes in Figma's order (the first is the default), and
86
+ * every `VARIABLE` in it with a value for each mode. A set or variable Figma marks deleted (`isSoftDeleted`) is left
87
+ * out, as is a variable whose set is not in the message or whose type Taco lacks; each is reported. Taco variables
88
+ * hold no aliases, so an alias takes the value it resolves to: in the same mode within its own collection, else in
89
+ * the other collection's default mode. A mode without a value takes the default mode's. Without `keepAliases`, two
90
+ * collections of one name get a number, so that `var('collection/name')` can tell them apart; with it, each keeps
91
+ * its Figma name. A number variable scoped to opacity alone (layer
92
+ * or color opacity) holds Figma's percentage, so it is imported divided by 100, on Taco's 0 to 1 scale. Ids come from
93
+ * `newId`.
94
+ * @param nodes - Source nodes in file order.
95
+ * @param newId - Allocates local identifiers.
96
+ * @param report - Receives import diagnostics.
97
+ * @param keepAliases - Retain source keys and direct alias targets for native file records.
98
+ * @returns Variable definitions and lookup functions.
99
+ */
100
+ export declare function readFigmaVariables(nodes: Iterable<FigmaTreeNode>, newId: () => string, report: Report, keepAliases?: boolean): FigmaVariables;
101
+ /**
102
+ * Sets the variable bindings and variable modes of `layer`, converted from `figma`. A paint's `colorVar` binds
103
+ * `fillColor` or `strokeColor` when it is the bottom fill or the first stroke and solid (a text layer's colour is its
104
+ * top visible solid fill, bound as `textColor`); `variableConsumptionMap` entries bind by `FIELD_PROPERTIES` and
105
+ * `FIELD_GROUPS`. A binding the layer cannot take keeps the imported value and is named, with why, in one entry
106
+ * for the layer. With `variables` undefined (the host adds no variables) every binding is reported so. `overridden`
107
+ * names the binding fields an instance copy dropped because its instance overrides them; they join the same entry.
108
+ * `shownBy` reads a bound font style in the modes that instance shows the layer in (`FigmaVariables.fontStyleOf`).
109
+ * No reason names the layer: the entry's node is the layer, so that a host can count one reason over many layers.
110
+ * `styleList` reads the paints of the fill and stroke styles the layer names (`styleBackedList`), whose bindings it takes.
111
+ */
112
+ export declare function bindLayerVariables(layer: SceneNode, figma: FigmaTreeNode, variables: FigmaVariables | undefined, report: (kind: FigmaImportReportKind, reason: string) => void, overridden?: readonly string[], shownBy?: ShownBy, styleList?: FigmaStyleList): void;
113
+ /**
114
+ * Whether the opacity `opacity` of Figma solid paint `paint` on layer `figma` is its colour variable's alpha, copied
115
+ * there by Figma: the paint's own colour is opaque, and the opacity rounds to the variable's 8-bit alpha in the mode
116
+ * the layer uses. For a saved file, match the paint's stored RGBA against the reachable variable colours.
117
+ * @param paint - Original solid paint.
118
+ * @param opacity - Stored paint opacity.
119
+ * @param figma - Consuming layer.
120
+ * @param variables - Imported variable definitions.
121
+ * @param where - Source location for diagnostics.
122
+ * @param shownBy - Instance displaying the layer.
123
+ * @returns Whether the variable colour already includes this opacity.
124
+ */
125
+ export declare function foldsVariableAlpha(paint: FigmaObject, opacity: number, figma: FigmaTreeNode, variables: FigmaVariables | undefined, where: string, shownBy?: ShownBy): boolean;
126
+ /**
127
+ * The font size Taco draws text `layer`, converted from `figma`, at when `bindLayerVariables` keeps its own `FONT_SIZE`
128
+ * binding: the variable's value in the mode the layer uses (with `shownBy`, as that instance shows it); else `undefined`,
129
+ * and each run is drawn at its own size.
130
+ */
131
+ export declare function keptFontSize(layer: TextNode, figma: FigmaTreeNode, variables: FigmaVariables | undefined, shownBy?: ShownBy): number | undefined;
132
+ /**
133
+ * The variable modes `figma` chooses (`variableModeBySetMap`), by collection id; a choice that names no imported
134
+ * collection or mode is added to `left`.
135
+ */
136
+ export declare function figmaVariableModes(figma: FigmaTreeNode, variables: FigmaVariables | undefined, left: string[]): Record<string, VariableModeId>;
137
+ export {};