@moondraft/import 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (323) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/LICENSE +34 -0
  3. package/README.md +36 -2
  4. package/SOURCE.md +169 -0
  5. package/dist/adapter/convert.d.ts +122 -0
  6. package/dist/adapter/convert.js +2302 -0
  7. package/dist/adapter/figma.d.ts +9 -0
  8. package/dist/adapter/figma.js +30 -0
  9. package/dist/adapter/file-components.d.ts +14 -0
  10. package/dist/adapter/file-components.js +262 -0
  11. package/dist/adapter/file-resources.d.ts +29 -0
  12. package/dist/adapter/file-resources.js +562 -0
  13. package/dist/adapter/index.d.ts +6 -0
  14. package/dist/adapter/index.js +9 -0
  15. package/dist/adapter/link.d.ts +45 -0
  16. package/dist/adapter/link.js +688 -0
  17. package/dist/adapter/payload.d.ts +31 -0
  18. package/dist/adapter/payload.js +78 -0
  19. package/dist/adapter/shapes.d.ts +31 -0
  20. package/dist/adapter/shapes.js +75 -0
  21. package/dist/adapter/variables.d.ts +44 -0
  22. package/dist/adapter/variables.js +103 -0
  23. package/dist/figma-file.d.ts +38 -0
  24. package/dist/figma-file.js +97 -0
  25. package/dist/figma-worker.d.ts +11 -0
  26. package/dist/figma-worker.js +12 -0
  27. package/dist/figma.d.ts +26 -0
  28. package/dist/figma.js +96 -0
  29. package/dist/index.d.ts +28 -0
  30. package/dist/index.js +49 -0
  31. package/dist/report.d.ts +15 -0
  32. package/dist/report.js +69 -0
  33. package/dist/svg.d.ts +33 -0
  34. package/dist/svg.js +44 -0
  35. package/dist/syntax.d.ts +8 -0
  36. package/dist/syntax.js +19 -0
  37. package/dist/taco/figma-import/clipboard.d.ts +25 -0
  38. package/dist/taco/figma-import/clipboard.js +87 -0
  39. package/dist/taco/figma-import/clipboardSize.d.ts +31 -0
  40. package/dist/taco/figma-import/clipboardSize.js +107 -0
  41. package/dist/taco/figma-import/container/compression.d.ts +9 -0
  42. package/dist/taco/figma-import/container/compression.js +174 -0
  43. package/dist/taco/figma-import/container/error.d.ts +15 -0
  44. package/dist/taco/figma-import/container/error.js +19 -0
  45. package/dist/taco/figma-import/container/kiwiContainer.d.ts +38 -0
  46. package/dist/taco/figma-import/container/kiwiContainer.js +61 -0
  47. package/dist/taco/figma-import/container/limits.d.ts +22 -0
  48. package/dist/taco/figma-import/container/limits.js +22 -0
  49. package/dist/taco/figma-import/container/zip.d.ts +14 -0
  50. package/dist/taco/figma-import/container/zip.js +154 -0
  51. package/dist/taco/figma-import/figFile.d.ts +34 -0
  52. package/dist/taco/figma-import/figFile.js +91 -0
  53. package/dist/taco/figma-import/figFileDocument.d.ts +25 -0
  54. package/dist/taco/figma-import/figFileDocument.js +100 -0
  55. package/dist/taco/figma-import/import/blobs.d.ts +10 -0
  56. package/dist/taco/figma-import/import/blobs.js +23 -0
  57. package/dist/taco/figma-import/import/carry.d.ts +11 -0
  58. package/dist/taco/figma-import/import/carry.js +33 -0
  59. package/dist/taco/figma-import/import/componentProps.d.ts +84 -0
  60. package/dist/taco/figma-import/import/componentProps.js +313 -0
  61. package/dist/taco/figma-import/import/componentSets.d.ts +83 -0
  62. package/dist/taco/figma-import/import/componentSets.js +647 -0
  63. package/dist/taco/figma-import/import/converters/effects.d.ts +31 -0
  64. package/dist/taco/figma-import/import/converters/effects.js +127 -0
  65. package/dist/taco/figma-import/import/converters/ellipse.d.ts +7 -0
  66. package/dist/taco/figma-import/import/converters/ellipse.js +54 -0
  67. package/dist/taco/figma-import/import/converters/frame.d.ts +21 -0
  68. package/dist/taco/figma-import/import/converters/frame.js +55 -0
  69. package/dist/taco/figma-import/import/converters/gradient.d.ts +72 -0
  70. package/dist/taco/figma-import/import/converters/gradient.js +106 -0
  71. package/dist/taco/figma-import/import/converters/group.d.ts +21 -0
  72. package/dist/taco/figma-import/import/converters/group.js +39 -0
  73. package/dist/taco/figma-import/import/converters/image.d.ts +13 -0
  74. package/dist/taco/figma-import/import/converters/image.js +83 -0
  75. package/dist/taco/figma-import/import/converters/layout.d.ts +34 -0
  76. package/dist/taco/figma-import/import/converters/layout.js +168 -0
  77. package/dist/taco/figma-import/import/converters/line.d.ts +11 -0
  78. package/dist/taco/figma-import/import/converters/line.js +40 -0
  79. package/dist/taco/figma-import/import/converters/rectangle.d.ts +3 -0
  80. package/dist/taco/figma-import/import/converters/rectangle.js +11 -0
  81. package/dist/taco/figma-import/import/converters/section.d.ts +9 -0
  82. package/dist/taco/figma-import/import/converters/section.js +35 -0
  83. package/dist/taco/figma-import/import/converters/shared.d.ts +68 -0
  84. package/dist/taco/figma-import/import/converters/shared.js +362 -0
  85. package/dist/taco/figma-import/import/converters/text.d.ts +41 -0
  86. package/dist/taco/figma-import/import/converters/text.js +576 -0
  87. package/dist/taco/figma-import/import/converters/vector.d.ts +84 -0
  88. package/dist/taco/figma-import/import/converters/vector.js +468 -0
  89. package/dist/taco/figma-import/import/converters/vectorNetwork.d.ts +98 -0
  90. package/dist/taco/figma-import/import/converters/vectorNetwork.js +385 -0
  91. package/dist/taco/figma-import/import/fields.d.ts +15 -0
  92. package/dist/taco/figma-import/import/fields.js +29 -0
  93. package/dist/taco/figma-import/import/instances.d.ts +163 -0
  94. package/dist/taco/figma-import/import/instances.js +1323 -0
  95. package/dist/taco/figma-import/import/nestingCycles.d.ts +86 -0
  96. package/dist/taco/figma-import/import/nestingCycles.js +488 -0
  97. package/dist/taco/figma-import/import/slots.d.ts +56 -0
  98. package/dist/taco/figma-import/import/slots.js +96 -0
  99. package/dist/taco/figma-import/import/styles.d.ts +46 -0
  100. package/dist/taco/figma-import/import/styles.js +42 -0
  101. package/dist/taco/figma-import/import/tree.d.ts +66 -0
  102. package/dist/taco/figma-import/import/tree.js +194 -0
  103. package/dist/taco/figma-import/import/types.d.ts +232 -0
  104. package/dist/taco/figma-import/import/types.js +33 -0
  105. package/dist/taco/figma-import/import/variables.d.ts +136 -0
  106. package/dist/taco/figma-import/import/variables.js +762 -0
  107. package/dist/taco/figma-import/import/variantTrees.d.ts +20 -0
  108. package/dist/taco/figma-import/import/variantTrees.js +480 -0
  109. package/dist/taco/figma-import/import/walk.d.ts +159 -0
  110. package/dist/taco/figma-import/import/walk.js +1297 -0
  111. package/dist/taco/figma-import/index.d.ts +22 -0
  112. package/dist/taco/figma-import/index.js +13 -0
  113. package/dist/taco/figma-import/kiwi/byteReader.d.ts +37 -0
  114. package/dist/taco/figma-import/kiwi/byteReader.js +151 -0
  115. package/dist/taco/figma-import/kiwi/error.d.ts +14 -0
  116. package/dist/taco/figma-import/kiwi/error.js +29 -0
  117. package/dist/taco/figma-import/kiwi/limits.d.ts +18 -0
  118. package/dist/taco/figma-import/kiwi/limits.js +18 -0
  119. package/dist/taco/figma-import/kiwi/message.d.ts +10 -0
  120. package/dist/taco/figma-import/kiwi/message.js +145 -0
  121. package/dist/taco/figma-import/kiwi/schema.d.ts +42 -0
  122. package/dist/taco/figma-import/kiwi/schema.js +206 -0
  123. package/dist/taco/figma-import/kiwi/types.d.ts +46 -0
  124. package/dist/taco/figma-import/kiwi/types.js +18 -0
  125. package/dist/taco/model/agent-hidden-fields.d.ts +20 -0
  126. package/dist/taco/model/agent-hidden-fields.js +29 -0
  127. package/dist/taco/model/asset-users.d.ts +23 -0
  128. package/dist/taco/model/asset-users.js +128 -0
  129. package/dist/taco/model/auto-layout-lines.d.ts +32 -0
  130. package/dist/taco/model/auto-layout-lines.js +70 -0
  131. package/dist/taco/model/codec.d.ts +444 -0
  132. package/dist/taco/model/codec.js +5635 -0
  133. package/dist/taco/model/color.d.ts +11 -0
  134. package/dist/taco/model/color.js +61 -0
  135. package/dist/taco/model/comment-operations.d.ts +102 -0
  136. package/dist/taco/model/comment-operations.js +227 -0
  137. package/dist/taco/model/component-evaluation.d.ts +94 -0
  138. package/dist/taco/model/component-evaluation.js +548 -0
  139. package/dist/taco/model/component-expressions.d.ts +242 -0
  140. package/dist/taco/model/component-expressions.js +1082 -0
  141. package/dist/taco/model/component-properties.d.ts +111 -0
  142. package/dist/taco/model/component-properties.js +339 -0
  143. package/dist/taco/model/component-samples.d.ts +83 -0
  144. package/dist/taco/model/component-samples.js +290 -0
  145. package/dist/taco/model/component-validity.d.ts +85 -0
  146. package/dist/taco/model/component-validity.js +397 -0
  147. package/dist/taco/model/components.d.ts +155 -0
  148. package/dist/taco/model/components.js +505 -0
  149. package/dist/taco/model/connector-ends.d.ts +20 -0
  150. package/dist/taco/model/connector-ends.js +188 -0
  151. package/dist/taco/model/connector-geometry.d.ts +74 -0
  152. package/dist/taco/model/connector-geometry.js +293 -0
  153. package/dist/taco/model/corner-radii.d.ts +26 -0
  154. package/dist/taco/model/corner-radii.js +47 -0
  155. package/dist/taco/model/derivations.d.ts +81 -0
  156. package/dist/taco/model/derivations.js +151 -0
  157. package/dist/taco/model/export-settings.d.ts +53 -0
  158. package/dist/taco/model/export-settings.js +156 -0
  159. package/dist/taco/model/expressions/ast.d.ts +153 -0
  160. package/dist/taco/model/expressions/ast.js +6 -0
  161. package/dist/taco/model/expressions/cache.d.ts +23 -0
  162. package/dist/taco/model/expressions/cache.js +43 -0
  163. package/dist/taco/model/expressions/check.d.ts +72 -0
  164. package/dist/taco/model/expressions/check.js +517 -0
  165. package/dist/taco/model/expressions/completion.d.ts +61 -0
  166. package/dist/taco/model/expressions/completion.js +421 -0
  167. package/dist/taco/model/expressions/evaluate.d.ts +32 -0
  168. package/dist/taco/model/expressions/evaluate.js +519 -0
  169. package/dist/taco/model/expressions/forms.d.ts +84 -0
  170. package/dist/taco/model/expressions/forms.js +200 -0
  171. package/dist/taco/model/expressions/index.d.ts +14 -0
  172. package/dist/taco/model/expressions/index.js +17 -0
  173. package/dist/taco/model/expressions/lexer.d.ts +42 -0
  174. package/dist/taco/model/expressions/lexer.js +213 -0
  175. package/dist/taco/model/expressions/library.d.ts +33 -0
  176. package/dist/taco/model/expressions/library.js +117 -0
  177. package/dist/taco/model/expressions/names.d.ts +43 -0
  178. package/dist/taco/model/expressions/names.js +99 -0
  179. package/dist/taco/model/expressions/parser.d.ts +15 -0
  180. package/dist/taco/model/expressions/parser.js +438 -0
  181. package/dist/taco/model/expressions/rename.d.ts +34 -0
  182. package/dist/taco/model/expressions/rename.js +46 -0
  183. package/dist/taco/model/expressions/source.d.ts +15 -0
  184. package/dist/taco/model/expressions/source.js +161 -0
  185. package/dist/taco/model/expressions/types.d.ts +119 -0
  186. package/dist/taco/model/expressions/types.js +102 -0
  187. package/dist/taco/model/expressions/values.d.ts +97 -0
  188. package/dist/taco/model/expressions/values.js +160 -0
  189. package/dist/taco/model/geometry-limits.d.ts +16 -0
  190. package/dist/taco/model/geometry-limits.js +67 -0
  191. package/dist/taco/model/geometry.d.ts +47 -0
  192. package/dist/taco/model/geometry.js +193 -0
  193. package/dist/taco/model/group-bounds.d.ts +38 -0
  194. package/dist/taco/model/group-bounds.js +144 -0
  195. package/dist/taco/model/id-table.d.ts +37 -0
  196. package/dist/taco/model/id-table.js +80 -0
  197. package/dist/taco/model/index.d.ts +25 -0
  198. package/dist/taco/model/index.js +27 -0
  199. package/dist/taco/model/instance-resolver.d.ts +372 -0
  200. package/dist/taco/model/instance-resolver.js +1748 -0
  201. package/dist/taco/model/layer-syntax.d.ts +340 -0
  202. package/dist/taco/model/layer-syntax.js +3506 -0
  203. package/dist/taco/model/layout/constraints.d.ts +84 -0
  204. package/dist/taco/model/layout/constraints.js +445 -0
  205. package/dist/taco/model/layout/frame-layout.d.ts +46 -0
  206. package/dist/taco/model/layout/frame-layout.js +618 -0
  207. package/dist/taco/model/layout/node-sizing.d.ts +163 -0
  208. package/dist/taco/model/layout/node-sizing.js +486 -0
  209. package/dist/taco/model/legacy-connector-caps.d.ts +15 -0
  210. package/dist/taco/model/legacy-connector-caps.js +70 -0
  211. package/dist/taco/model/linear-call.d.ts +48 -0
  212. package/dist/taco/model/linear-call.js +58 -0
  213. package/dist/taco/model/new-nodes.d.ts +145 -0
  214. package/dist/taco/model/new-nodes.js +277 -0
  215. package/dist/taco/model/node-builder.d.ts +449 -0
  216. package/dist/taco/model/node-builder.js +2294 -0
  217. package/dist/taco/model/node-table-watch.d.ts +36 -0
  218. package/dist/taco/model/node-table-watch.js +63 -0
  219. package/dist/taco/model/node-transform.d.ts +39 -0
  220. package/dist/taco/model/node-transform.js +79 -0
  221. package/dist/taco/model/node-users-index.d.ts +10 -0
  222. package/dist/taco/model/node-users-index.js +82 -0
  223. package/dist/taco/model/operation-references.d.ts +80 -0
  224. package/dist/taco/model/operation-references.js +399 -0
  225. package/dist/taco/model/operations.d.ts +610 -0
  226. package/dist/taco/model/operations.js +2882 -0
  227. package/dist/taco/model/overlay-table.d.ts +71 -0
  228. package/dist/taco/model/overlay-table.js +171 -0
  229. package/dist/taco/model/override-remap.d.ts +69 -0
  230. package/dist/taco/model/override-remap.js +230 -0
  231. package/dist/taco/model/parent-table.d.ts +53 -0
  232. package/dist/taco/model/parent-table.js +193 -0
  233. package/dist/taco/model/problem-collector.d.ts +27 -0
  234. package/dist/taco/model/problem-collector.js +101 -0
  235. package/dist/taco/model/sha256.d.ts +10 -0
  236. package/dist/taco/model/sha256.js +74 -0
  237. package/dist/taco/model/shape-geometry.d.ts +96 -0
  238. package/dist/taco/model/shape-geometry.js +368 -0
  239. package/dist/taco/model/shared-node-table.d.ts +97 -0
  240. package/dist/taco/model/shared-node-table.js +546 -0
  241. package/dist/taco/model/slots.d.ts +113 -0
  242. package/dist/taco/model/slots.js +281 -0
  243. package/dist/taco/model/stroke-settings.d.ts +37 -0
  244. package/dist/taco/model/stroke-settings.js +90 -0
  245. package/dist/taco/model/svg-path-import.d.ts +89 -0
  246. package/dist/taco/model/svg-path-import.js +219 -0
  247. package/dist/taco/model/text-measurement.d.ts +142 -0
  248. package/dist/taco/model/text-measurement.js +846 -0
  249. package/dist/taco/model/text-reads.d.ts +66 -0
  250. package/dist/taco/model/text-reads.js +128 -0
  251. package/dist/taco/model/text-sizer.d.ts +358 -0
  252. package/dist/taco/model/text-sizer.js +996 -0
  253. package/dist/taco/model/theme-users.d.ts +59 -0
  254. package/dist/taco/model/theme-users.js +312 -0
  255. package/dist/taco/model/thumbnail.d.ts +15 -0
  256. package/dist/taco/model/thumbnail.js +34 -0
  257. package/dist/taco/model/types.d.ts +2347 -0
  258. package/dist/taco/model/types.js +366 -0
  259. package/dist/taco/model/unknown-property.d.ts +5 -0
  260. package/dist/taco/model/unknown-property.js +7 -0
  261. package/dist/taco/model/validated-documents.d.ts +22 -0
  262. package/dist/taco/model/validated-documents.js +22 -0
  263. package/dist/taco/model/variable-modes.d.ts +61 -0
  264. package/dist/taco/model/variable-modes.js +438 -0
  265. package/dist/taco/model/variable-references.d.ts +54 -0
  266. package/dist/taco/model/variable-references.js +183 -0
  267. package/dist/taco/model/variables.d.ts +24 -0
  268. package/dist/taco/model/variables.js +151 -0
  269. package/dist/taco/model/vector-network.d.ts +34 -0
  270. package/dist/taco/model/vector-network.js +411 -0
  271. package/dist/taco/svg-import/import-svg.d.ts +36 -0
  272. package/dist/taco/svg-import/import-svg.js +729 -0
  273. package/dist/taco/svg-import/index.d.ts +3 -0
  274. package/dist/taco/svg-import/index.js +3 -0
  275. package/dist/taco/svg-import/limits/limits.d.ts +79 -0
  276. package/dist/taco/svg-import/limits/limits.js +160 -0
  277. package/dist/taco/svg-import/paint/gradients.d.ts +64 -0
  278. package/dist/taco/svg-import/paint/gradients.js +429 -0
  279. package/dist/taco/svg-import/paint/paint.d.ts +32 -0
  280. package/dist/taco/svg-import/paint/paint.js +162 -0
  281. package/dist/taco/svg-import/paths/paths.d.ts +58 -0
  282. package/dist/taco/svg-import/paths/paths.js +205 -0
  283. package/dist/taco/svg-import/public-types.d.ts +279 -0
  284. package/dist/taco/svg-import/public-types.js +56 -0
  285. package/dist/taco/svg-import/report/report.d.ts +44 -0
  286. package/dist/taco/svg-import/report/report.js +79 -0
  287. package/dist/taco/svg-import/reuse/reuse.d.ts +99 -0
  288. package/dist/taco/svg-import/reuse/reuse.js +840 -0
  289. package/dist/taco/svg-import/shapes/shapes.d.ts +35 -0
  290. package/dist/taco/svg-import/shapes/shapes.js +386 -0
  291. package/dist/taco/svg-import/structure/effects.d.ts +26 -0
  292. package/dist/taco/svg-import/structure/effects.js +618 -0
  293. package/dist/taco/svg-import/structure/image.d.ts +24 -0
  294. package/dist/taco/svg-import/structure/image.js +495 -0
  295. package/dist/taco/svg-import/structure/walk.d.ts +85 -0
  296. package/dist/taco/svg-import/structure/walk.js +544 -0
  297. package/dist/taco/svg-import/style/color.d.ts +40 -0
  298. package/dist/taco/svg-import/style/color.js +275 -0
  299. package/dist/taco/svg-import/style/computed.d.ts +214 -0
  300. package/dist/taco/svg-import/style/computed.js +1534 -0
  301. package/dist/taco/svg-import/style/css.d.ts +127 -0
  302. package/dist/taco/svg-import/style/css.js +541 -0
  303. package/dist/taco/svg-import/style/media.d.ts +25 -0
  304. package/dist/taco/svg-import/style/media.js +307 -0
  305. package/dist/taco/svg-import/style/properties.d.ts +43 -0
  306. package/dist/taco/svg-import/style/properties.js +135 -0
  307. package/dist/taco/svg-import/style/selector-reach.d.ts +30 -0
  308. package/dist/taco/svg-import/style/selector-reach.js +169 -0
  309. package/dist/taco/svg-import/style/selector-validity.d.ts +14 -0
  310. package/dist/taco/svg-import/style/selector-validity.js +307 -0
  311. package/dist/taco/svg-import/text/text.d.ts +29 -0
  312. package/dist/taco/svg-import/text/text.js +545 -0
  313. package/dist/taco/svg-import/transform/matrix.d.ts +111 -0
  314. package/dist/taco/svg-import/transform/matrix.js +229 -0
  315. package/dist/taco/svg-import/tree/element-data.d.ts +52 -0
  316. package/dist/taco/svg-import/tree/element-data.js +155 -0
  317. package/dist/taco/svg-import/tree/elements.d.ts +36 -0
  318. package/dist/taco/svg-import/tree/elements.js +121 -0
  319. package/dist/taco/svg-import/units/length.d.ts +43 -0
  320. package/dist/taco/svg-import/units/length.js +125 -0
  321. package/dist/taco/svg-import/units/viewbox.d.ts +35 -0
  322. package/dist/taco/svg-import/units/viewbox.js +77 -0
  323. package/package.json +54 -4
@@ -0,0 +1,362 @@
1
+ import { BLEND_MODES, } from "../../../model/index.js";
2
+ import { field, isObject } from "../fields.js";
3
+ import { imagePaint } from "./image.js";
4
+ import { moveMark } from "../carry.js";
5
+ import { gradientShape, onBox } from "./gradient.js";
6
+ import { styleBackedList } from "../styles.js";
7
+ import { sizeLimitsOf } from "./layout.js";
8
+ /**
9
+ * A Figma blend mode enum name as a Taco blend mode: `undefined` for
10
+ * `NORMAL` and `PASS_THROUGH` (Taco's default), `null` when Taco has no such
11
+ * mode (`LINEAR_BURN`, `LINEAR_DODGE`).
12
+ */
13
+ export function blendModeOf(value) {
14
+ if (value === "NORMAL" || value === "PASS_THROUGH")
15
+ return undefined;
16
+ const name = value.toLowerCase().replace(/_/g, "-");
17
+ return BLEND_MODES.includes(name) ? name : null;
18
+ }
19
+ export function readNumbers(object, keys, where) {
20
+ const out = {};
21
+ for (const key of keys) {
22
+ const value = field(object, key, "number", where);
23
+ if (value === undefined)
24
+ return null;
25
+ out[key] = value;
26
+ }
27
+ return out;
28
+ }
29
+ /** `#rrggbb`, or `#rrggbbaa` when alpha is below 1, from Figma's 0..1 channels. */
30
+ export function hexColor(color) {
31
+ const byte = (value) => Math.round(Math.min(1, Math.max(0, value)) * 255).toString(16).padStart(2, "0");
32
+ const alpha = color.a < 1 ? byte(color.a) : "";
33
+ return `#${byte(color.r)}${byte(color.g)}${byte(color.b)}${alpha}`;
34
+ }
35
+ /**
36
+ * The fields every Taco layer shares (id, name, visibility, lock, opacity and
37
+ * blend mode, the mask flag, the aspect ratio lock and resize constraints, see `constraintsOf`).
38
+ * Reports a blend mode Taco lacks, a mask that is not an alpha mask and, unless the
39
+ * caller imports them (`effectsImported`), effects, which are not imported yet.
40
+ */
41
+ export function layerBase(node, walk, defaultName, effectsImported = false) {
42
+ const where = `node ${node.id}`;
43
+ const blend = field(node.change, "blendMode", "string", where);
44
+ const blendMode = blend === undefined ? undefined : blendModeOf(blend);
45
+ if (blendMode === null)
46
+ walk.report("property-left-out", `blend mode ${String(blend)} has no Taco equivalent`);
47
+ const mask = field(node.change, "mask", "boolean", where) === true;
48
+ let outline = false;
49
+ if (mask) {
50
+ // As grida reads Kiwi masks (packages/grida-canvas-io-figma/lib.ts:4066): maskType defaults to ALPHA,
51
+ // and maskIsOutline (older files) defaults to maskType OUTLINE. Taco masks by alpha only.
52
+ const maskType = field(node.change, "maskType", "string", where) ?? "ALPHA";
53
+ outline = field(node.change, "maskIsOutline", "boolean", where) ?? maskType === "OUTLINE";
54
+ // Moondraft patch (../carry.ts): an outline mask is carried as a vector mask, so it is not reported.
55
+ if (!outline && maskType !== "ALPHA") {
56
+ walk.report("approximated", `the ${maskType.toLowerCase()} mask is imported as an alpha mask`);
57
+ }
58
+ }
59
+ if (!effectsImported && (field(node.change, "effects", "list", where)?.length ?? 0) > 0)
60
+ walk.report("property-left-out", "effects are not imported yet");
61
+ const constraints = constraintsOf(node.change, walk.report);
62
+ // Figma sets `targetAspectRatio` (width and height) when a layer's aspect ratio is locked; auto layout then keeps
63
+ // that ratio, whatever the layer's stored size.
64
+ const aspectRatio = aspectRatioOf(node.change, where);
65
+ return {
66
+ id: walk.newId(),
67
+ name: node.name === "" ? defaultName : node.name,
68
+ visible: field(node.change, "visible", "boolean", where) ?? true,
69
+ locked: field(node.change, "locked", "boolean", where) ?? false,
70
+ opacity: field(node.change, "opacity", "number", where) ?? 1,
71
+ ...(blendMode ? { blendMode } : {}),
72
+ ...(mask ? { mask } : {}),
73
+ ...(constraints ? { constraints } : {}),
74
+ ...(aspectRatio === undefined ? {} : { aspectRatioLocked: true, aspectRatio }),
75
+ ...(outline ? { metadata: { figma: { maskType: "vector" } } } : {}),
76
+ };
77
+ }
78
+ /** Figma's locked aspect ratio (`targetAspectRatio`) as width over height, or `undefined` when unlocked or unusable. */
79
+ function aspectRatioOf(change, where) {
80
+ const target = field(change, "targetAspectRatio", "object", where);
81
+ const value = target === undefined ? undefined : field(target, "value", "object", `${where} targetAspectRatio`);
82
+ const sides = value === undefined ? null : readNumbers(value, ["x", "y"], `${where} targetAspectRatio`);
83
+ if (!sides || !(sides.x > 0) || !(sides.y > 0))
84
+ return undefined;
85
+ const ratio = sides.x / sides.y;
86
+ return Number.isFinite(ratio) ? ratio : undefined;
87
+ }
88
+ const HORIZONTAL = { MIN: "left", MAX: "right", STRETCH: "left-right", CENTER: "center", SCALE: "scale" };
89
+ const VERTICAL = { MIN: "top", MAX: "bottom", STRETCH: "top-bottom", CENTER: "center", SCALE: "scale" };
90
+ /**
91
+ * Figma's `horizontalConstraint` and `verticalConstraint` as Taco
92
+ * `constraints`, or `undefined` when both are MIN (or absent), Taco's
93
+ * default. A value Taco has no match for (such as FIXED_MIN) is reported and
94
+ * read as MIN. They are taken off again where they do not apply: from a
95
+ * group by `convertGroup`, from a child in an auto layout flow by
96
+ * `stackChildFields`, and from a layer in a section (directly or through
97
+ * groups) by the walk, as Figma applies none when a section is resized.
98
+ */
99
+ export function constraintsOf(change, report) {
100
+ const read = (name, table) => {
101
+ const value = change[name];
102
+ if (value === undefined)
103
+ return table["MIN"];
104
+ if (typeof value === "string" && Object.hasOwn(table, value))
105
+ return table[value];
106
+ report("property-left-out", `${name} ${String(value)} has no Taco equivalent; the layer keeps its MIN position on that axis`);
107
+ return table["MIN"];
108
+ };
109
+ const constraints = { horizontal: read("horizontalConstraint", HORIZONTAL), vertical: read("verticalConstraint", VERTICAL) };
110
+ return constraints.horizontal === "left" && constraints.vertical === "top" ? undefined : constraints;
111
+ }
112
+ /** A node's size and transform numbers, or `null` when either is incomplete, so `framedBase` leaves the node out. */
113
+ export function frameGeometry(node) {
114
+ const where = `node ${node.id}`;
115
+ const size = field(node.change, "size", "object", where);
116
+ const transform = field(node.change, "transform", "object", where);
117
+ const sides = size && readNumbers(size, ["x", "y"], `${where} size`);
118
+ const m = transform && readNumbers(transform, ["m00", "m01", "m02", "m10", "m11", "m12"], `${where} transform`);
119
+ return sides && m ? { sides, m } : null;
120
+ }
121
+ /**
122
+ * The fields every framed Taco node shares, or `null` after reporting why
123
+ * the node is left out. Figma's `transform` maps the node's local space to
124
+ * its parent's (x' = m00 x + m01 y + m02, y' = m10 x + m11 y + m12); Taco
125
+ * keeps the unrotated frame plus a rotation about its center, clockwise in
126
+ * degrees, and a horizontal flip when the matrix mirrors.
127
+ */
128
+ export function framedBase(node, walk, defaultName, effectsImported = false) {
129
+ const geometry = frameGeometry(node);
130
+ if (geometry === null) {
131
+ walk.report("node-left-out", "the node has no complete size or transform");
132
+ return null;
133
+ }
134
+ const { sides, m } = geometry;
135
+ const { x: width, y: height } = sides;
136
+ const flipX = m.m00 * m.m11 - m.m01 * m.m10 < 0;
137
+ // With a flip the matrix is R·diag(-1, 1), so R's first column is minus the matrix's.
138
+ const radians = flipX ? Math.atan2(-m.m10, -m.m00) : Math.atan2(m.m10, m.m00);
139
+ const degrees = radians * 180 / Math.PI;
140
+ const rotation = degrees === -180 ? 180 : degrees + 0;
141
+ const tolerance = 1e-4;
142
+ if (Math.abs(m.m00 ** 2 + m.m10 ** 2 - 1) > tolerance || Math.abs(m.m01 ** 2 + m.m11 ** 2 - 1) > tolerance
143
+ || Math.abs(m.m00 * m.m01 + m.m10 * m.m11) > tolerance) {
144
+ walk.report("approximated", "the transform scales or skews; only its position, rotation and flip are kept");
145
+ }
146
+ const centerX = m.m00 * width / 2 + m.m01 * height / 2 + m.m02;
147
+ const centerY = m.m10 * width / 2 + m.m11 * height / 2 + m.m12;
148
+ const base = layerBase(node, walk, defaultName, effectsImported);
149
+ const limits = sizeLimitsOf(node.change);
150
+ return {
151
+ ...base,
152
+ frame: { x: centerX - width / 2, y: centerY - height / 2, width, height },
153
+ rotation,
154
+ ...(flipX ? { flipX } : {}),
155
+ ...(Object.keys(limits).length > 0 ? { resizing: limits } : {}),
156
+ };
157
+ }
158
+ /**
159
+ * The colour that the variable bound to stop `index` of gradient `paint` (its `stopsVar` entry) gives in the modes the
160
+ * node is shown in, or `undefined` when the stop is not bound or the binding gives no colour. Figma stores the stops
161
+ * in the modes of the node's own place, so a layer of a component shown by an instance in other modes needs this.
162
+ */
163
+ function boundStopColor(walk, paint, index, at) {
164
+ const bound = (field(paint, "stopsVar", "list", at) ?? [])[index];
165
+ if (walk.variableColor === undefined || !isObject(bound) || bound["colorVar"] === undefined)
166
+ return undefined;
167
+ const hex = walk.variableColor(bound["colorVar"]);
168
+ if (hex === undefined)
169
+ return undefined;
170
+ const channel = (from) => parseInt(hex.slice(from, from + 2), 16) / 255;
171
+ return { r: channel(1), g: channel(3), b: channel(5), a: hex.length === 9 ? channel(7) : 1 };
172
+ }
173
+ /** A Figma gradient paint as a Taco paint, or a reason it is left out. */
174
+ function gradientPaint(node, walk, paint, type, at, box) {
175
+ const where = `node ${node.id}`;
176
+ const size = field(node.change, "size", "object", where);
177
+ const sides = size && readNumbers(size, ["x", "y"], `${where} size`);
178
+ const transform = field(paint, "transform", "object", at);
179
+ const m = transform && readNumbers(transform, ["m00", "m01", "m02", "m10", "m11", "m12"], `${at} transform`);
180
+ const stops = [];
181
+ for (const [index, stop] of (field(paint, "stops", "list", at) ?? []).entries()) {
182
+ const colorObject = isObject(stop) ? field(stop, "color", "object", `${at} stops[${String(index)}]`) : undefined;
183
+ const color = colorObject && readNumbers(colorObject, ["r", "g", "b", "a"], `${at} stops[${String(index)}] color`);
184
+ const position = isObject(stop) ? field(stop, "position", "number", `${at} stops[${String(index)}]`) : undefined;
185
+ if (!color || position === undefined)
186
+ return "a gradient stop has no colour or position";
187
+ stops.push({ color: boundStopColor(walk, paint, index, at) ?? color, position });
188
+ }
189
+ const result = !sides || !m ? null
190
+ : box ? gradientShape(type, stops, onBox(m, sides.x, sides.y, box), box.width, box.height)
191
+ : gradientShape(type, stops, m, sides.x, sides.y);
192
+ if (!result)
193
+ return "the gradient has no stops, no complete transform or a flat transform";
194
+ const { shape } = result;
195
+ const paintOut = shape.kind === "solid"
196
+ ? { kind: "solid", color: hexColor(shape.color) }
197
+ : { ...shape, stops: shape.stops.map((stop) => ({ offset: stop.position, color: hexColor(stop.color) })) };
198
+ return { paint: paintOut, ...(result.approximated ? { approximated: result.approximated } : {}) };
199
+ }
200
+ /**
201
+ * The solid, gradient and image paints of the node's `fillPaints` or `strokePaints`
202
+ * list, named `fill` or `stroke` in report entries; other paint types are
203
+ * reported and left out. A node that names a fill or stroke style takes the
204
+ * style's paints (`styleBackedList`). `node` may also be a style override entry, with `id`
205
+ * saying where it is; its `change` must then carry the node's `size` for gradients.
206
+ * Figma places a gradient on the node's box (`size`); `box`, in node pixels,
207
+ * is the box the renderer places it on instead when that differs, such as a
208
+ * vector region's bounds.
209
+ */
210
+ export function nodePaints(node, walk, list, box) {
211
+ const where = `node ${node.id}`;
212
+ const what = list === "fillPaints" ? "fill" : "stroke";
213
+ const paints = [];
214
+ const indices = walk.paintIndices ? [] : undefined;
215
+ const source = styleBackedList(node.change, list, walk.styleList, where, walk.report) ?? [];
216
+ source.forEach((paint, index) => {
217
+ const at = `${where} ${list}[${String(index)}]`;
218
+ const label = `${what} ${String(index + 1)}`;
219
+ if (!isObject(paint))
220
+ return walk.report("property-left-out", `${label} is not a paint object`);
221
+ const type = field(paint, "type", "string", at);
222
+ let base;
223
+ if (type?.startsWith("GRADIENT_")) {
224
+ const gradient = gradientPaint(node, walk, paint, type, at, box);
225
+ if (typeof gradient === "string")
226
+ return walk.report("property-left-out", `${label} (${type}) is left out: ${gradient}`);
227
+ if (gradient.approximated)
228
+ walk.report("approximated", `${label}: ${gradient.approximated}`);
229
+ base = gradient.paint;
230
+ }
231
+ else if (type === "IMAGE") {
232
+ const image = imagePaint(paint, at, label, walk);
233
+ if (image === null)
234
+ return;
235
+ if (typeof image === "string")
236
+ return walk.report("property-left-out", `${label} (IMAGE) is left out: ${image}`);
237
+ base = image;
238
+ }
239
+ else {
240
+ const colorObject = field(paint, "color", "object", at);
241
+ const color = colorObject && readNumbers(colorObject, ["r", "g", "b", "a"], `${at} color`);
242
+ if (type !== "SOLID" || !color) {
243
+ return walk.report("property-left-out", `${label} (${type ?? "no type"}) is left out: only solid paints with a colour, gradient paints and image paints are imported`);
244
+ }
245
+ base = { kind: "solid", color: hexColor(color) };
246
+ }
247
+ let opacity = field(paint, "opacity", "number", at) ?? 1;
248
+ if (type === "SOLID" && base.kind === "solid" && opacity !== 1 && paint["colorVar"] && walk.copiedPaintAlpha?.(paint, opacity)) {
249
+ const color = walk.variableColor?.(paint["colorVar"]);
250
+ if (color !== undefined) {
251
+ base = { ...base, color };
252
+ opacity = 1;
253
+ }
254
+ }
255
+ const visible = field(paint, "visible", "boolean", at) ?? true;
256
+ const blend = field(paint, "blendMode", "string", at);
257
+ const blendMode = blend === undefined ? undefined : blendModeOf(blend);
258
+ if (blendMode === null)
259
+ walk.report("property-left-out", `${label} blend mode ${String(blend)} has no Taco equivalent`);
260
+ const placed = {
261
+ ...base,
262
+ ...(opacity !== 1 ? { opacity } : {}),
263
+ ...(visible ? {} : { visible }),
264
+ ...(blendMode ? { blendMode } : {}),
265
+ };
266
+ moveMark(base, placed); // Moondraft patch (../carry.ts)
267
+ paints.push(placed);
268
+ indices?.push(index);
269
+ });
270
+ if (indices)
271
+ walk.paintIndices(source, indices);
272
+ return paints;
273
+ }
274
+ const STROKE_POSITIONS = { CENTER: "center", INSIDE: "inside", OUTSIDE: "outside" };
275
+ const STROKE_JOINS = { MITER: "miter", BEVEL: "bevel", ROUND: "round" };
276
+ /** The most dash lengths a stroke can carry; the renderer rejects longer patterns (`WIRE_LIMITS.strokeDashIntervals`). */
277
+ const MAX_DASH_LENGTHS = 64;
278
+ /** Figma's `strokeCap` names Taco has, as path ends and dash ends alike. */
279
+ export const STROKE_CAPS = { NONE: "none", ROUND: "round", SQUARE: "square" };
280
+ /**
281
+ * Figma's separate side weights as Taco side widths, or `undefined` when the
282
+ * node uses one weight. With `borderStrokeWeightsIndependent` Kiwi leaves out
283
+ * a side of weight 0, so an absent side is 0.
284
+ */
285
+ function strokeSides(node, where) {
286
+ if (field(node.change, "borderStrokeWeightsIndependent", "boolean", where) !== true)
287
+ return undefined;
288
+ const side = (name) => Math.max(0, field(node.change, name, "number", where) ?? 0);
289
+ return { top: side("borderTopWeight"), right: side("borderRightWeight"), bottom: side("borderBottomWeight"), left: side("borderLeftWeight") };
290
+ }
291
+ /**
292
+ * Stroke paints with the node's weight, alignment, join, miter limit and
293
+ * dashes, gradients placed on `box` (the node's box when left out). Kiwi
294
+ * leaves out an enum field at its first value, so an absent `strokeAlign` is
295
+ * CENTER, an absent `strokeJoin` MITER and an absent `strokeCap` NONE.
296
+ * `sides` reads Figma's separate side weights, which only rectangles and
297
+ * frames have. A dashed stroke's dash ends follow `strokeCap`, as in Figma.
298
+ */
299
+ export function nodeStrokes(node, walk, box, sides = false) {
300
+ const where = `node ${node.id}`;
301
+ const paints = nodePaints(node, walk, "strokePaints", box);
302
+ if (paints.length === 0)
303
+ return [];
304
+ const sideWidths = sides ? strokeSides(node, where) : undefined;
305
+ const width = sideWidths ? Math.max(sideWidths.top, sideWidths.right, sideWidths.bottom, sideWidths.left)
306
+ : field(node.change, "strokeWeight", "number", where);
307
+ if (width === undefined) {
308
+ walk.report("property-left-out", "strokes are left out: the node has stroke paints but no strokeWeight");
309
+ return [];
310
+ }
311
+ const align = field(node.change, "strokeAlign", "string", where) ?? "CENTER";
312
+ const position = Object.hasOwn(STROKE_POSITIONS, align) ? STROKE_POSITIONS[align] : "center";
313
+ if (!Object.hasOwn(STROKE_POSITIONS, align))
314
+ walk.report("approximated", `stroke alignment ${align} has no Taco equivalent; the strokes are centered`);
315
+ const joinName = field(node.change, "strokeJoin", "string", where) ?? "MITER";
316
+ const join = Object.hasOwn(STROKE_JOINS, joinName) ? STROKE_JOINS[joinName] : "miter";
317
+ if (!Object.hasOwn(STROKE_JOINS, joinName))
318
+ walk.report("approximated", `stroke join ${joinName} has no Taco equivalent; miter is used`);
319
+ // Figma's miter limit is a length ratio; Taco keeps the angle where a miter bevels: limit = 1 / sin(angle / 2).
320
+ const limit = field(node.change, "miterLimit", "number", where);
321
+ const miterAngle = limit === undefined ? undefined : limit > 1 ? 2 * Math.asin(1 / limit) * 180 / Math.PI : 180;
322
+ if (limit !== undefined && !(limit >= 1))
323
+ walk.report("approximated", `miter limit ${String(limit)} is below 1; every miter corner is beveled`);
324
+ const pattern = field(node.change, "dashPattern", "list", where) ?? [];
325
+ const dashProblem = !pattern.every((length) => typeof length === "number" && Number.isFinite(length) && length >= 0)
326
+ ? "the dash pattern has a length that is not a number of 0 or more"
327
+ : pattern.length > MAX_DASH_LENGTHS ? `the dash pattern has more than ${MAX_DASH_LENGTHS} lengths`
328
+ : pattern.length > 0 && pattern.every((length) => length === 0) ? "every length in the dash pattern is 0"
329
+ : undefined;
330
+ const dash = dashProblem === undefined ? pattern : [];
331
+ if (dashProblem !== undefined)
332
+ walk.report("property-left-out", `dashes are left out: ${dashProblem}`);
333
+ const capName = field(node.change, "strokeCap", "string", where) ?? "NONE";
334
+ const dashCap = Object.hasOwn(STROKE_CAPS, capName) ? STROKE_CAPS[capName] : "none";
335
+ if (dash.length > 0 && !Object.hasOwn(STROKE_CAPS, capName))
336
+ walk.report("approximated", `stroke cap ${capName} has no Taco dash end; the dashes end flat`);
337
+ const boundWidth = walk.paintIndices && node.change["variableConsumptionMap"]
338
+ ?.entries?.some(e => e.variableField === "STROKE_WEIGHT" || /^BORDER_(TOP|RIGHT|BOTTOM|LEFT)_WEIGHT$/.test(e.variableField));
339
+ return paints.map((paint) => ({
340
+ paint, width, position, join, ...(boundWidth && { fileBoundWidth: true }),
341
+ ...(sideWidths ? { sides: sideWidths } : {}),
342
+ ...(miterAngle !== undefined ? { miterAngle } : {}),
343
+ ...(dash.length > 0 ? { dash, dashCap } : {}),
344
+ }));
345
+ }
346
+ /** Solid, gradient and image fills and strokes and corners as a Taco style; other paint types are reported and left out. */
347
+ export function visualStyle(node, walk) {
348
+ const where = `node ${node.id}`;
349
+ const fills = nodePaints(node, walk, "fillPaints");
350
+ const strokes = nodeStrokes(node, walk, undefined, true);
351
+ const radius = field(node.change, "cornerRadius", "number", where) ?? 0;
352
+ const smoothing = field(node.change, "cornerSmoothing", "number", where) ?? 0;
353
+ const corner = (name) => field(node.change, name, "number", where) ?? 0;
354
+ // As grida reads it (packages/grida-canvas-io-figma/lib.ts:4150): per-corner fields only when independent.
355
+ const corners = field(node.change, "rectangleCornerRadiiIndependent", "boolean", where) === true
356
+ ? { cornerRadii: {
357
+ topLeft: corner("rectangleTopLeftCornerRadius"), topRight: corner("rectangleTopRightCornerRadius"),
358
+ bottomRight: corner("rectangleBottomRightCornerRadius"), bottomLeft: corner("rectangleBottomLeftCornerRadius"),
359
+ } }
360
+ : radius > 0 ? { cornerRadius: radius } : {};
361
+ return { ...(fills.length > 0 ? { fills } : {}), ...(strokes.length > 0 ? { strokes } : {}), ...corners, ...(smoothing > 0 ? { cornerSmoothing: smoothing } : {}) };
362
+ }
@@ -0,0 +1,41 @@
1
+ import type { TextStyle } from "../../../model/index.ts";
2
+ import { type FigmaObject } from "../fields.ts";
3
+ import type { FigmaNodeConverter, NodeWalk } from "../walk.ts";
4
+ /** The weight a Figma font style name such as "Semi Bold Italic" names (undefined when it names no known weight), and whether it is italic. */
5
+ export declare function fontStyleWeight(styleName: string): {
6
+ readonly fontWeight: number | undefined;
7
+ readonly italic: boolean;
8
+ };
9
+ /**
10
+ * A field the importer adds to a text layer's Figma fields, never one Figma writes: the line height in pixels Figma laid
11
+ * out every line of this layer at in an instance (its stored `derivedTextData`), which replaces the line height the
12
+ * layer's runs would take from their text style or variable. The runs stay linked to their style, with this line height
13
+ * as an override.
14
+ */
15
+ export declare const KEPT_LINE_HEIGHT_FIELD = "tacoKeptLineHeight";
16
+ /**
17
+ * A Figma TEXT node as a Taco text node. `textData.characters` is split into
18
+ * paragraphs at each newline, and each paragraph into runs where the style id
19
+ * changes. `textData.characterStyleIDs` holds one id per code point and may
20
+ * be shorter than the text: missing ids are 0. Id 0 is the node's own style;
21
+ * every other id names an entry of `textData.styleOverrideTable` whose fields
22
+ * replace the node's. Fonts are named by family, weight and italic only;
23
+ * `fontAssetId` is left for the host to bind. A node or override entry that
24
+ * names a Figma text style (`styleIdForText`) takes the style's typography
25
+ * over the node's stored copies (an override entry's own fields still win, and
26
+ * the colour stays the node's), and its runs link to the shared style the walk made
27
+ * for it (`NodeWalk.textStyle`), with only the fields that differ as overrides.
28
+ * A line height bound to a variable (`LINE_HEIGHT`) is the variable's value in
29
+ * the mode the node uses (`NodeWalk.variableNumber`), as a fixed multiple of the
30
+ * font size, read from the same place as the line height itself (`runBinding`).
31
+ */
32
+ export declare const convertText: FigmaNodeConverter;
33
+ /**
34
+ * A Figma text style node (`styleType` TEXT) as a Taco text style, read as a
35
+ * run of a node without overrides is; a value it lacks is Figma's default.
36
+ * An auto line height is the font's own from the style node's font metadata,
37
+ * else from the first of `layers`, the text layers that name the style, that has it.
38
+ * A line height bound to a variable is the number `variableNumber` gives for it; the
39
+ * layers that use the style report it.
40
+ */
41
+ export declare function figmaTextStyle(change: FigmaObject, name: string, report: NodeWalk["report"], where: string, layers?: readonly FigmaObject[], variableNumber?: NodeWalk["variableNumber"]): TextStyle;