@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,31 @@
1
+ import type { VisualStyle } from "../../../model/index.ts";
2
+ import type { FigmaTreeNode } from "../tree.ts";
3
+ import type { NodeWalk } from "../walk.ts";
4
+ /**
5
+ * True when the renderer draws a node with `style` as a plain rectangle, the
6
+ * only shape whose drop shadow it shrinks for a negative spread
7
+ * (`drawShadowedRect` in packages/render-core/cpp/skia/skia_adapter.cc); every
8
+ * other shape's drop shadow ignores a negative spread (`buildPreparedShadows`).
9
+ * Frames are drawn so when their corners are square; rectangles also need at
10
+ * most one plain solid fill or a stroke with unequal per-side weights, or they are drawn as a path
11
+ * (`compileRectangle` and `needsRegionFillPaints` in packages/render-core/src/page-compiler.ts).
12
+ */
13
+ export declare function drawnAsPlainRectangle(style: VisualStyle, isFrame: boolean): boolean;
14
+ /**
15
+ * The node's Figma `effects` as Taco shadows, layer blur and background blur,
16
+ * shadows in Figma's order; a node with an effect style takes the style's
17
+ * effects (`styleBackedList`). Figma's blur radius is twice the Gaussian sigma:
18
+ * its shadow radius is the CSS box-shadow blur radius (sigma = radius / 2, CSS
19
+ * Backgrounds 3 §7.1.1, https://bjango.com/articles/blurradiuscomparison/),
20
+ * and Figma halves a blur radius for CSS `blur()`, whose argument is the sigma
21
+ * (https://forum.figma.com/t/background-blur-is-different-in-dev-mode/81631).
22
+ * Taco's renderer also blurs at a sigma of half the radius, so radii carry
23
+ * over unchanged. Kiwi leaves out an enum field at its first value, so an
24
+ * absent `type` is INNER_SHADOW. As fig2sketch reads effects
25
+ * (src/converter/style.py, `convert_effects`), absent offset, radius and
26
+ * spread are 0. Taco has no hidden shadow or blur, one layer blur and one
27
+ * background blur, and at most 16 shadows; what does not fit is reported.
28
+ * A drop shadow keeps a negative spread only when `plainRectangle` is true
29
+ * (see `drawnAsPlainRectangle`); elsewhere it is drawn with spread 0 and reported.
30
+ */
31
+ export declare function nodeEffects(node: FigmaTreeNode, walk: NodeWalk, plainRectangle?: boolean): Pick<VisualStyle, "shadows" | "layerBlur" | "backgroundBlur">;
@@ -0,0 +1,127 @@
1
+ import { field, isObject } from "../fields.js";
2
+ import { styleBackedList } from "../styles.js";
3
+ import { blendModeOf, hexColor, readNumbers } from "./shared.js";
4
+ import { markShadowBehind } from "../carry.js";
5
+ /** The renderer refuses a node with more shadows than this (`WIRE_LIMITS.shadows` in packages/render-core/src/protocol.ts). */
6
+ const MAX_SHADOWS = 16;
7
+ // Prototype-free, so an effect type such as "constructor" finds no entry.
8
+ const SHADOW_KINDS = Object.assign(Object.create(null), { DROP_SHADOW: "drop", INNER_SHADOW: "inner" });
9
+ const BLUR_KINDS = Object.assign(Object.create(null), { FOREGROUND_BLUR: "layerBlur", BACKGROUND_BLUR: "backgroundBlur" });
10
+ /**
11
+ * True when the renderer draws a node with `style` as a plain rectangle, the
12
+ * only shape whose drop shadow it shrinks for a negative spread
13
+ * (`drawShadowedRect` in packages/render-core/cpp/skia/skia_adapter.cc); every
14
+ * other shape's drop shadow ignores a negative spread (`buildPreparedShadows`).
15
+ * Frames are drawn so when their corners are square; rectangles also need at
16
+ * most one plain solid fill or a stroke with unequal per-side weights, or they are drawn as a path
17
+ * (`compileRectangle` and `needsRegionFillPaints` in packages/render-core/src/page-compiler.ts).
18
+ */
19
+ export function drawnAsPlainRectangle(style, isFrame) {
20
+ const square = (style.cornerRadius ?? 0) === 0 && Object.values(style.cornerRadii ?? {}).every((radius) => radius === 0);
21
+ if (!square || isFrame)
22
+ return square;
23
+ // A stroke with unequal per-side weights makes the rectangle a container, whatever its fills (`hasSidedStroke`).
24
+ const sidedStroke = style.strokes?.some(({ sides }) => sides !== undefined
25
+ && !(sides.right === sides.top && sides.bottom === sides.top && sides.left === sides.top)) ?? false;
26
+ if (sidedStroke)
27
+ return true;
28
+ const fills = style.fills ?? [];
29
+ return fills.length <= 1 && fills.every((paint) => paint.kind === "solid" && paint.visible !== false && (paint.blendMode ?? "normal") === "normal");
30
+ }
31
+ /**
32
+ * The node's Figma `effects` as Taco shadows, layer blur and background blur,
33
+ * shadows in Figma's order; a node with an effect style takes the style's
34
+ * effects (`styleBackedList`). Figma's blur radius is twice the Gaussian sigma:
35
+ * its shadow radius is the CSS box-shadow blur radius (sigma = radius / 2, CSS
36
+ * Backgrounds 3 §7.1.1, https://bjango.com/articles/blurradiuscomparison/),
37
+ * and Figma halves a blur radius for CSS `blur()`, whose argument is the sigma
38
+ * (https://forum.figma.com/t/background-blur-is-different-in-dev-mode/81631).
39
+ * Taco's renderer also blurs at a sigma of half the radius, so radii carry
40
+ * over unchanged. Kiwi leaves out an enum field at its first value, so an
41
+ * absent `type` is INNER_SHADOW. As fig2sketch reads effects
42
+ * (src/converter/style.py, `convert_effects`), absent offset, radius and
43
+ * spread are 0. Taco has no hidden shadow or blur, one layer blur and one
44
+ * background blur, and at most 16 shadows; what does not fit is reported.
45
+ * A drop shadow keeps a negative spread only when `plainRectangle` is true
46
+ * (see `drawnAsPlainRectangle`); elsewhere it is drawn with spread 0 and reported.
47
+ */
48
+ export function nodeEffects(node, walk, plainRectangle = false) {
49
+ const where = `node ${node.id}`;
50
+ const shadows = [];
51
+ const boundZeroBlurs = new Map();
52
+ const blurs = {};
53
+ (styleBackedList(node.change, "effects", walk.styleList, where, walk.report) ?? []).forEach((effect, index) => {
54
+ const at = `${where} effects[${String(index)}]`;
55
+ const label = `effect ${String(index + 1)}`;
56
+ if (!isObject(effect))
57
+ return walk.report("property-left-out", `${label} is not an effect object`);
58
+ const type = field(effect, "type", "string", at) ?? "INNER_SHADOW";
59
+ const shadowKind = SHADOW_KINDS[type];
60
+ const blurKind = BLUR_KINDS[type];
61
+ if (!shadowKind && !blurKind)
62
+ return walk.report("property-left-out", `${label} (${type}) is left out: only shadows and blurs are imported`);
63
+ if (field(effect, "visible", "boolean", at) === false) {
64
+ return walk.report("property-left-out", `${label} (${type}) is hidden and left out: Taco effects cannot be hidden`);
65
+ }
66
+ let radius = field(effect, "radius", "number", at) ?? 0;
67
+ if (radius < 0) {
68
+ walk.report("approximated", `${label} (${type}) radius ${String(radius)} is below 0; 0 is used`);
69
+ radius = 0;
70
+ }
71
+ const blend = field(effect, "blendMode", "string", at);
72
+ if (blend !== undefined && blendModeOf(blend) !== undefined) {
73
+ walk.report("approximated", `${label} (${type}) blend mode ${blend} is not imported; the effect blends normally`);
74
+ }
75
+ if (blurKind) {
76
+ if (field(effect, "blurOpType", "string", at) === "PROGRESSIVE") {
77
+ walk.report("approximated", `${label} (${type}) is a progressive blur; Taco blurs evenly at radius ${String(radius)}`);
78
+ }
79
+ // A blur of radius 0 draws nothing, so it leaves the slot for a later blur of the same kind.
80
+ if (radius === 0) {
81
+ if (walk.effectField && effect["radiusVar"] && !boundZeroBlurs.has(blurKind))
82
+ boundZeroBlurs.set(blurKind, effect);
83
+ return;
84
+ }
85
+ if (blurs[blurKind] !== undefined)
86
+ return walk.report("property-left-out", `${label} (${type}) is left out: Taco keeps one ${type === "FOREGROUND_BLUR" ? "layer" : "background"} blur`);
87
+ walk.effectField?.(effect, "look." + blurKind);
88
+ blurs[blurKind] = radius;
89
+ return;
90
+ }
91
+ const offset = field(effect, "offset", "object", at) ?? {};
92
+ const x = field(offset, "x", "number", `${at} offset`) ?? 0;
93
+ const y = field(offset, "y", "number", `${at} offset`) ?? 0;
94
+ let spread = field(effect, "spread", "number", at) ?? 0;
95
+ const colorObject = field(effect, "color", "object", at);
96
+ const color = colorObject && readNumbers(colorObject, ["r", "g", "b", "a"], `${at} color`);
97
+ if (!color)
98
+ return walk.report("property-left-out", `${label} (${type}) is left out: it has no complete colour`);
99
+ if (shadows.length === MAX_SHADOWS)
100
+ return walk.report("property-left-out", `${label} (${type}) is left out: Taco draws at most ${String(MAX_SHADOWS)} shadows`);
101
+ // Moondraft patch (../carry.ts): Moondraft knocks a drop shadow out under the node's fill, as Figma does unless
102
+ // showShadowBehindNode is set; such a shadow is marked, and the see-through fill is no longer reported.
103
+ const behind = shadowKind === "drop" && field(effect, "showShadowBehindNode", "boolean", at) === true;
104
+ if (shadowKind === "inner" && spread < 0) {
105
+ // The renderer grows an inner shadow only inward and treats a negative spread as 0.
106
+ walk.report("approximated", `${label} (${type}) spread ${String(spread)} is below 0; Taco draws inner shadows with spread 0`);
107
+ spread = 0;
108
+ }
109
+ if (shadowKind === "drop" && spread < 0 && !plainRectangle) {
110
+ walk.report("approximated", `${label} (${type}) spread ${String(spread)} is below 0; Taco shrinks drop shadows only on square-cornered rectangles and frames, so spread 0 is used`);
111
+ spread = 0;
112
+ }
113
+ const shadow = { kind: shadowKind, x, y, blur: radius, spread, color: hexColor(color) };
114
+ if (behind)
115
+ markShadowBehind(shadow);
116
+ walk.effectField?.(effect, "look.shadows." + String(shadows.length));
117
+ shadows.push(shadow);
118
+ });
119
+ for (const [kind, effect] of boundZeroBlurs)
120
+ if (blurs[kind] === undefined)
121
+ walk.effectField(effect, "look." + kind);
122
+ return {
123
+ ...(shadows.length > 0 ? { shadows } : {}),
124
+ ...(blurs.layerBlur ? { layerBlur: blurs.layerBlur } : {}),
125
+ ...(blurs.backgroundBlur ? { backgroundBlur: blurs.backgroundBlur } : {}),
126
+ };
127
+ }
@@ -0,0 +1,7 @@
1
+ import type { FigmaNodeConverter } from "../walk.ts";
2
+ /**
3
+ * A Figma ELLIPSE as a Taco ellipse. Figma's `arcData` (radians, clockwise
4
+ * from the x axis, inner radius as a fraction of the outer one) maps to
5
+ * Taco's `arc` in degrees; a whole ellipse leaves `arc` out.
6
+ */
7
+ export declare const convertEllipse: FigmaNodeConverter;
@@ -0,0 +1,54 @@
1
+ import { isWholeEllipseArc } from "../../../model/index.js";
2
+ import { field, isObject } from "../fields.js";
3
+ import { nodeEffects } from "./effects.js";
4
+ import { framedBase, nodePaints, nodeStrokes } from "./shared.js";
5
+ /** Largest inner radius Taco accepts; its arcs need an inner radius below 1. */
6
+ const MAX_INNER_RADIUS = 0.999;
7
+ /** Figma stores angles as 32-bit floats; a full turn can read a little over or under 360 degrees. */
8
+ const FULL_TURN_TOLERANCE = 1e-3;
9
+ /** Radians to degrees, rounded to 1e-4 degree to drop 32-bit float noise. */
10
+ const degreesOf = (radians) => Math.round(radians * 180 / Math.PI * 1e4) / 1e4 + 0;
11
+ /**
12
+ * A Figma ELLIPSE as a Taco ellipse. Figma's `arcData` (radians, clockwise
13
+ * from the x axis, inner radius as a fraction of the outer one) maps to
14
+ * Taco's `arc` in degrees; a whole ellipse leaves `arc` out.
15
+ */
16
+ export const convertEllipse = (node, walk) => {
17
+ const base = framedBase(node, walk, "Ellipse", true);
18
+ if (base === null)
19
+ return null;
20
+ const fills = nodePaints(node, walk, "fillPaints");
21
+ // Per-side weights only apply to rectangles and frames; an ellipse's strokes use the node's one strokeWeight.
22
+ const strokes = nodeStrokes(node, walk);
23
+ const arc = arcOf(node, walk);
24
+ const ellipse = {
25
+ ...base, type: "shape", shape: "ellipse",
26
+ style: { ...(fills.length > 0 ? { fills } : {}), ...(strokes.length > 0 ? { strokes } : {}), ...nodeEffects(node, walk) }, ...(arc ? { arc } : {}),
27
+ };
28
+ return ellipse;
29
+ };
30
+ /** The node's arc, or `undefined` for a whole ellipse; out-of-range values are clamped and reported. */
31
+ function arcOf(node, walk) {
32
+ const where = `node ${node.id}`;
33
+ const data = field(node.change, "arcData", "object", where);
34
+ if (data === undefined || !isObject(data))
35
+ return undefined;
36
+ const at = `${where} arcData`;
37
+ const startingAngle = degreesOf(field(data, "startingAngle", "number", at) ?? 0);
38
+ let endingAngle = degreesOf(field(data, "endingAngle", "number", at) ?? 2 * Math.PI);
39
+ const sweep = endingAngle - startingAngle;
40
+ // A full turn can read a little under or over 360 after float32 storage and rounding.
41
+ if (Math.abs(sweep) > 360 - FULL_TURN_TOLERANCE) {
42
+ if (Math.abs(sweep) - 360 > FULL_TURN_TOLERANCE)
43
+ walk.report("approximated", "the arc sweeps more than one full turn; one full turn is kept");
44
+ endingAngle = startingAngle + Math.sign(sweep) * 360;
45
+ }
46
+ // Rounded to 1e-6 to drop 32-bit float noise (0.8 reads as 0.800000011920929).
47
+ const rawInner = Math.round((field(data, "innerRadius", "number", at) ?? 0) * 1e6) / 1e6;
48
+ const innerRadius = Math.min(Math.max(rawInner, 0), MAX_INNER_RADIUS);
49
+ if (innerRadius !== rawInner) {
50
+ walk.report("approximated", `the arc inner radius ${String(rawInner)} is outside 0 to below 1; ${String(innerRadius)} is kept`);
51
+ }
52
+ const arc = { startingAngle, endingAngle, innerRadius };
53
+ return isWholeEllipseArc(arc) ? undefined : arc;
54
+ }
@@ -0,0 +1,21 @@
1
+ import { type FigmaObject } from "../fields.ts";
2
+ import type { FigmaNodeConverter } from "../walk.ts";
3
+ /**
4
+ * A Figma FRAME as a Taco frame, with its HORIZONTAL or VERTICAL auto layout
5
+ * as a stack (see `stackLayoutOf`) and free layout otherwise. Frames clip unless
6
+ * `frameMaskDisabled` is true (grida, packages/grida-canvas-io-figma/lib.ts:4246).
7
+ * Figma stores a group as a FRAME. `resizeToFit` alone does not prove it, so a
8
+ * FRAME counts as a group only when it also clips (`frameMaskDisabled` is
9
+ * false), has no fill, stroke or background paints (grida,
10
+ * packages/grida-canvas-io-figma/lib.ts:4567) and has no auto layout
11
+ * (fig2sketch, src/converter/tree.py:169). A group is converted by
12
+ * `convertGroup`. Only a FRAME is checked: a SYMBOL or INSTANCE with the same
13
+ * fields is still a component or an instance, so it imports as a frame.
14
+ */
15
+ export declare const convertFrame: FigmaNodeConverter;
16
+ /**
17
+ * Whether a FRAME's fields mark it as a Figma group (see `convertFrame`).
18
+ * It never throws: a field of the wrong type makes it "not a group", and the
19
+ * converter then refuses that field itself.
20
+ */
21
+ export declare function isFigmaGroup(change: FigmaObject): boolean;
@@ -0,0 +1,55 @@
1
+ import { field } from "../fields.js";
2
+ import { drawnAsPlainRectangle, nodeEffects } from "./effects.js";
3
+ import { stackLayoutOf } from "./layout.js";
4
+ import { convertGroup } from "./group.js";
5
+ import { framedBase, visualStyle } from "./shared.js";
6
+ /**
7
+ * A Figma FRAME as a Taco frame, with its HORIZONTAL or VERTICAL auto layout
8
+ * as a stack (see `stackLayoutOf`) and free layout otherwise. Frames clip unless
9
+ * `frameMaskDisabled` is true (grida, packages/grida-canvas-io-figma/lib.ts:4246).
10
+ * Figma stores a group as a FRAME. `resizeToFit` alone does not prove it, so a
11
+ * FRAME counts as a group only when it also clips (`frameMaskDisabled` is
12
+ * false), has no fill, stroke or background paints (grida,
13
+ * packages/grida-canvas-io-figma/lib.ts:4567) and has no auto layout
14
+ * (fig2sketch, src/converter/tree.py:169). A group is converted by
15
+ * `convertGroup`. Only a FRAME is checked: a SYMBOL or INSTANCE with the same
16
+ * fields is still a component or an instance, so it imports as a frame.
17
+ */
18
+ export const convertFrame = (node, walk) => {
19
+ const stackMode = field(node.change, "stackMode", "string", `node ${node.id}`);
20
+ // The paint lists are checked here, so a malformed list is refused rather than read as "not a group".
21
+ for (const name of ["fillPaints", "strokePaints", "backgroundPaints"])
22
+ field(node.change, name, "list", `node ${node.id}`);
23
+ if (node.type === "FRAME" && isFigmaGroup(node.change))
24
+ return convertGroup(node, walk);
25
+ const base = framedBase(node, walk, "Frame", true);
26
+ if (base === null)
27
+ return null;
28
+ const visual = visualStyle(node, walk);
29
+ const style = { ...visual, ...nodeEffects(node, walk, drawnAsPlainRectangle(visual, true)) };
30
+ const frame = {
31
+ ...base,
32
+ type: "frame",
33
+ children: walk.convertChildren(),
34
+ layout: stackLayoutOf(node.change, walk.report) ?? { kind: "absolute" },
35
+ clipContent: node.change["frameMaskDisabled"] !== true,
36
+ ...(Object.keys(style).length > 0 ? { style } : {}),
37
+ };
38
+ return frame;
39
+ };
40
+ /**
41
+ * Whether a FRAME's fields mark it as a Figma group (see `convertFrame`).
42
+ * It never throws: a field of the wrong type makes it "not a group", and the
43
+ * converter then refuses that field itself.
44
+ */
45
+ export function isFigmaGroup(change) {
46
+ if (change["resizeToFit"] !== true || change["frameMaskDisabled"] !== false)
47
+ return false;
48
+ const stackMode = change["stackMode"];
49
+ if (stackMode !== undefined && stackMode !== "NONE")
50
+ return false;
51
+ return ["fillPaints", "strokePaints", "backgroundPaints"].every((name) => {
52
+ const paints = change[name];
53
+ return paints === undefined || (Array.isArray(paints) && paints.length === 0);
54
+ });
55
+ }
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Figma gradient paints as Taco gradient geometry.
3
+ *
4
+ * A Figma gradient paint's `transform` maps the node's unit box (0..1 on
5
+ * each axis, scaled to the node's size) into gradient space, so it is the
6
+ * inverse of the mapping that places the gradient's handles. In gradient
7
+ * space a linear gradient runs from (0, 0.5) to (1, 0.5); radial, diamond
8
+ * and angular gradients are centred on (0.5, 0.5) with radius 0.5, and an
9
+ * angular gradient starts along +x. fig2sketch's `convert_gradient`
10
+ * (src/converter/style.py) reads the paint the same way.
11
+ */
12
+ /** A colour as Figma stores it: channels from 0 to 1. */
13
+ export interface Rgba {
14
+ readonly r: number;
15
+ readonly g: number;
16
+ readonly b: number;
17
+ readonly a: number;
18
+ }
19
+ /** A gradient stop; `position` is Figma's, or a Taco offset once mapped. */
20
+ export interface ColorStop {
21
+ readonly position: number;
22
+ readonly color: Rgba;
23
+ }
24
+ export type FigmaMatrix = Record<"m00" | "m01" | "m02" | "m10" | "m11" | "m12", number>;
25
+ export type GradientShape = {
26
+ readonly kind: "linear-gradient";
27
+ readonly from: Point;
28
+ readonly to: Point;
29
+ readonly stops: readonly ColorStop[];
30
+ } | {
31
+ readonly kind: "radial-gradient";
32
+ readonly center: Point;
33
+ readonly radius: Point;
34
+ readonly stops: readonly ColorStop[];
35
+ } | {
36
+ readonly kind: "angular-gradient";
37
+ readonly center: Point;
38
+ readonly angle: number;
39
+ readonly stops: readonly ColorStop[];
40
+ } | {
41
+ readonly kind: "solid";
42
+ readonly color: Rgba;
43
+ };
44
+ interface Point {
45
+ readonly x: number;
46
+ readonly y: number;
47
+ }
48
+ /** A box in the node's own pixels. */
49
+ export interface Box {
50
+ readonly x: number;
51
+ readonly y: number;
52
+ readonly width: number;
53
+ readonly height: number;
54
+ }
55
+ /**
56
+ * The paint transform `m` of a `width` by `height` node re-expressed on
57
+ * `box`'s unit box, so the gradient stays where it is in node pixels when it
58
+ * is placed on `box`: unit point (u, v) of `box` is node unit point
59
+ * ((box.x + u box.width) / width, (box.y + v box.height) / height). An axis
60
+ * of size 0 has no unit position, so the gradient does not vary along it.
61
+ */
62
+ export declare function onBox(m: FigmaMatrix, width: number, height: number, box: Box): FigmaMatrix;
63
+ /**
64
+ * The Taco geometry of a Figma gradient of `type` on a `width` by `height`
65
+ * node, plus why it is only approximated, or `null` when the transform is
66
+ * flat or there are no stops.
67
+ */
68
+ export declare function gradientShape(type: string, stops: readonly ColorStop[], m: FigmaMatrix, width: number, height: number): {
69
+ shape: GradientShape;
70
+ approximated?: string;
71
+ } | null;
72
+ export {};
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Figma gradient paints as Taco gradient geometry.
3
+ *
4
+ * A Figma gradient paint's `transform` maps the node's unit box (0..1 on
5
+ * each axis, scaled to the node's size) into gradient space, so it is the
6
+ * inverse of the mapping that places the gradient's handles. In gradient
7
+ * space a linear gradient runs from (0, 0.5) to (1, 0.5); radial, diamond
8
+ * and angular gradients are centred on (0.5, 0.5) with radius 0.5, and an
9
+ * angular gradient starts along +x. fig2sketch's `convert_gradient`
10
+ * (src/converter/style.py) reads the paint the same way.
11
+ */
12
+ /**
13
+ * The paint transform `m` of a `width` by `height` node re-expressed on
14
+ * `box`'s unit box, so the gradient stays where it is in node pixels when it
15
+ * is placed on `box`: unit point (u, v) of `box` is node unit point
16
+ * ((box.x + u box.width) / width, (box.y + v box.height) / height). An axis
17
+ * of size 0 has no unit position, so the gradient does not vary along it.
18
+ */
19
+ export function onBox(m, width, height, box) {
20
+ const fx = width > 0 ? 1 / width : 0;
21
+ const fy = height > 0 ? 1 / height : 0;
22
+ return {
23
+ m00: m.m00 * box.width * fx, m01: m.m01 * box.height * fy, m02: m.m00 * box.x * fx + m.m01 * box.y * fy + m.m02,
24
+ m10: m.m10 * box.width * fx, m11: m.m11 * box.height * fy, m12: m.m10 * box.x * fx + m.m11 * box.y * fy + m.m12,
25
+ };
26
+ }
27
+ /** The colour at `t`: the end colours outside the stops, interpolated between them. */
28
+ function sample(stops, t) {
29
+ const first = stops[0];
30
+ const last = stops[stops.length - 1];
31
+ if (t <= first.position)
32
+ return first.color;
33
+ if (t >= last.position)
34
+ return last.color;
35
+ const after = stops.findIndex((stop) => stop.position > t);
36
+ const a = stops[after - 1];
37
+ const b = stops[after];
38
+ const k = (t - a.position) / (b.position - a.position);
39
+ const mix = (key) => a.color[key] + (b.color[key] - a.color[key]) * k;
40
+ return { r: mix("r"), g: mix("g"), b: mix("b"), a: mix("a") };
41
+ }
42
+ /** Stops cut to 0..1, with the colours sampled at the cut ends; at least two stops. */
43
+ function clipStops(stops) {
44
+ const out = [];
45
+ if (stops[0].position < 0)
46
+ out.push({ position: 0, color: sample(stops, 0) });
47
+ out.push(...stops.filter((stop) => stop.position >= 0 && stop.position <= 1));
48
+ if (stops[stops.length - 1].position > 1)
49
+ out.push({ position: 1, color: sample(stops, 1) });
50
+ return out.length === 1 ? [{ position: 0, color: out[0].color }, { position: 1, color: out[0].color }] : out;
51
+ }
52
+ const DEGREES = 180 / Math.PI;
53
+ const normalizeDegrees = (degrees) => ((degrees % 360) + 360) % 360 + 0;
54
+ /**
55
+ * The Taco geometry of a Figma gradient of `type` on a `width` by `height`
56
+ * node, plus why it is only approximated, or `null` when the transform is
57
+ * flat or there are no stops.
58
+ */
59
+ export function gradientShape(type, stops, m, width, height) {
60
+ if (stops.length === 0)
61
+ return null;
62
+ const sorted = [...stops].sort((a, b) => a.position - b.position);
63
+ if (type === "GRADIENT_LINEAR") {
64
+ // Gradient position t = m00 u + m01 v + m02 at unit point (u, v) = (x / width, y / height),
65
+ // so t grows along (m00 / width, m01 / height) in node pixels.
66
+ const gx = width > 0 ? m.m00 / width : 0;
67
+ const gy = height > 0 ? m.m01 / height : 0;
68
+ const perPixel = Math.hypot(gx, gy);
69
+ const atCenter = (m.m00 + m.m01) / 2 + m.m02;
70
+ if (perPixel < 1e-12)
71
+ return { shape: { kind: "solid", color: sample(sorted, atCenter) } };
72
+ const step = { x: width ? (gx / perPixel) / (perPixel * width) : 0, y: height ? (gy / perPixel) / (perPixel * height) : 0 };
73
+ // Anchor the axis on Figma's first handle. A shear transforms the lines of equal colour
74
+ // by the inverse transpose, so the step follows their normal in local pixels.
75
+ const det = m.m00 * m.m11 - m.m01 * m.m10;
76
+ const from = det
77
+ ? { x: (-m.m02 * m.m11 - (0.5 - m.m12) * m.m01) / det || 0,
78
+ y: ((0.5 - m.m12) * m.m00 + m.m02 * m.m10) / det || 0 }
79
+ : { x: 0.5 - atCenter * step.x, y: 0.5 - atCenter * step.y };
80
+ return { shape: { kind: "linear-gradient", from, to: { x: from.x + step.x, y: from.y + step.y }, stops: clipStops(sorted) } };
81
+ }
82
+ const determinant = m.m00 * m.m11 - m.m01 * m.m10;
83
+ if (Math.abs(determinant) < 1e-12)
84
+ return null;
85
+ // The inverse's linear part, then the centre (0.5, 0.5) of gradient space in the unit box.
86
+ const a = m.m11 / determinant, b = -m.m01 / determinant, c = -m.m10 / determinant, d = m.m00 / determinant;
87
+ const center = { x: a * (0.5 - m.m02) + b * (0.5 - m.m12), y: c * (0.5 - m.m02) + d * (0.5 - m.m12) };
88
+ const clipped = clipStops(sorted);
89
+ if (type === "GRADIENT_RADIAL" || type === "GRADIENT_DIAMOND") {
90
+ // The circle of radius 0.5 maps to an ellipse whose bounding half-extents these are; Taco's ellipse is upright.
91
+ const radius = { x: 0.5 * Math.hypot(a, b), y: 0.5 * Math.hypot(c, d) };
92
+ const tilted = Math.abs(a * c + b * d) > 1e-4 * Math.hypot(a, b) * Math.hypot(c, d);
93
+ const approximated = type === "GRADIENT_DIAMOND" ? "a diamond gradient is drawn as a radial gradient"
94
+ : tilted ? "a rotated or skewed radial gradient is drawn as an upright ellipse" : undefined;
95
+ return { shape: { kind: "radial-gradient", center, radius, stops: clipped }, ...(approximated ? { approximated } : {}) };
96
+ }
97
+ if (type === "GRADIENT_ANGULAR") {
98
+ // Gradient space's +x in node pixels; the sweep is even only when the map is a turn and a uniform scale.
99
+ const p = { a: a * width, b: b * width, c: c * height, d: d * height };
100
+ const scale = Math.hypot(p.a, p.c);
101
+ const even = determinant > 0 && Math.abs(p.a - p.d) <= 1e-4 * scale && Math.abs(p.b + p.c) <= 1e-4 * scale;
102
+ const shape = { kind: "angular-gradient", center, angle: normalizeDegrees(Math.atan2(p.c, p.a) * DEGREES), stops: clipped };
103
+ return even ? { shape } : { shape, approximated: "a stretched or mirrored angular gradient is drawn as an even sweep" };
104
+ }
105
+ return null;
106
+ }
@@ -0,0 +1,21 @@
1
+ import type { FigmaNodeConverter } from "../walk.ts";
2
+ /**
3
+ * A Figma group (a FRAME that `convertFrame` finds to be a group) as a Taco
4
+ * group. Figma stores each child's transform in the group's own space, with
5
+ * the group's top-left at the origin; a Taco group places its children the
6
+ * same way, relative to its frame, rotated and flipped about its middle
7
+ * (`nodeLocalTransform`). So the group's transform converts as a frame's
8
+ * does, and every child keeps its place on the page. A Taco group's frame is
9
+ * always the union of its children's bounds; Figma's size can differ (a mask
10
+ * group is as large as its mask), so the walk fits every imported group to
11
+ * its children afterwards, which moves nothing on the page. A group never
12
+ * clips, as in grida (packages/grida-canvas-io-figma/lib.ts:4605 sets
13
+ * `clipsContent: false`) and fig2sketch (src/converter/group.py:12 builds a
14
+ * plain Sketch group).
15
+ *
16
+ * A Taco group has no constraints of its own; it follows its layers' (see
17
+ * `NodeBase.constraints`). Figma, too, keeps the constraints set on a group
18
+ * on its layers, so each layer imports its own and the group's are left out;
19
+ * the report says so when they differ from a layer's.
20
+ */
21
+ export declare const convertGroup: FigmaNodeConverter;
@@ -0,0 +1,39 @@
1
+ import { constraintsOf, framedBase } from "./shared.js";
2
+ /**
3
+ * A Figma group (a FRAME that `convertFrame` finds to be a group) as a Taco
4
+ * group. Figma stores each child's transform in the group's own space, with
5
+ * the group's top-left at the origin; a Taco group places its children the
6
+ * same way, relative to its frame, rotated and flipped about its middle
7
+ * (`nodeLocalTransform`). So the group's transform converts as a frame's
8
+ * does, and every child keeps its place on the page. A Taco group's frame is
9
+ * always the union of its children's bounds; Figma's size can differ (a mask
10
+ * group is as large as its mask), so the walk fits every imported group to
11
+ * its children afterwards, which moves nothing on the page. A group never
12
+ * clips, as in grida (packages/grida-canvas-io-figma/lib.ts:4605 sets
13
+ * `clipsContent: false`) and fig2sketch (src/converter/group.py:12 builds a
14
+ * plain Sketch group).
15
+ *
16
+ * A Taco group has no constraints of its own; it follows its layers' (see
17
+ * `NodeBase.constraints`). Figma, too, keeps the constraints set on a group
18
+ * on its layers, so each layer imports its own and the group's are left out;
19
+ * the report says so when they differ from a layer's.
20
+ */
21
+ export const convertGroup = (node, walk) => {
22
+ const base = framedBase(node, walk, "Group");
23
+ if (base === null)
24
+ return null;
25
+ // `framedBase` sets no variable bindings; a group's type allows no width or height binding.
26
+ const { variableBindings: _none, constraints, ...fields } = base;
27
+ if (constraints !== undefined) {
28
+ const own = `${String(node.change["horizontalConstraint"] ?? "MIN")}/${String(node.change["verticalConstraint"] ?? "MIN")}`;
29
+ const ignore = () => undefined;
30
+ const differs = node.children.some((child) => {
31
+ const layer = constraintsOf(child.change, ignore);
32
+ return layer?.horizontal !== constraints.horizontal || layer.vertical !== constraints.vertical;
33
+ });
34
+ if (differs)
35
+ walk.report("property-left-out", `the group's constraints ${own} are left out: a Taco group follows its layers' constraints, and its layers have their own`);
36
+ }
37
+ const group = { ...fields, type: "group", children: walk.convertChildren() };
38
+ return group;
39
+ };
@@ -0,0 +1,13 @@
1
+ import type { Paint } from "../../../model/index.ts";
2
+ import { type FigmaObject } from "../fields.ts";
3
+ import type { NodeWalk } from "../walk.ts";
4
+ /** The MIME type of PNG, JPEG, GIF and WebP bytes, read from their first bytes; `undefined` for anything else. */
5
+ export declare function sniffImageMimeType(bytes: Uint8Array): string | undefined;
6
+ export declare function hexText(bytes: Uint8Array): string;
7
+ /**
8
+ * A Figma IMAGE paint as a Taco image paint whose asset the host supplied
9
+ * (`FigmaImportOptions.images`), or a reason it is left out. `null` means it
10
+ * is left out for a reason already reported for the same image. Rotation
11
+ * and image adjustments (`paintFilter`, `filterColorAdjust`) are reported, not kept.
12
+ */
13
+ export declare function imagePaint(paint: FigmaObject, at: string, label: string, walk: NodeWalk): Paint | string | null;
@@ -0,0 +1,83 @@
1
+ import { field } from "../fields.js";
2
+ import { markTile } from "../carry.js";
3
+ /** The MIME type of PNG, JPEG, GIF and WebP bytes, read from their first bytes; `undefined` for anything else. */
4
+ export function sniffImageMimeType(bytes) {
5
+ const starts = (offset, text) => bytes.length >= offset + text.length && [...text].every((char, i) => bytes[offset + i] === char.charCodeAt(0));
6
+ if (starts(0, "\x89PNG\r\n\x1a\n"))
7
+ return "image/png";
8
+ if (starts(0, "\xff\xd8\xff"))
9
+ return "image/jpeg";
10
+ if (starts(0, "GIF87a") || starts(0, "GIF89a"))
11
+ return "image/gif";
12
+ if (starts(0, "RIFF") && starts(8, "WEBP"))
13
+ return "image/webp";
14
+ return undefined;
15
+ }
16
+ export function hexText(bytes) {
17
+ return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
18
+ }
19
+ /**
20
+ * Figma's `imageScaleMode` as a Taco fit. Kiwi leaves out an enum field at its
21
+ * first value, so an absent mode is STRETCH (Figma's "Crop"), which stretches
22
+ * the image to the box and then applies the paint's `transform`. As
23
+ * fig2sketch reads it (src/converter/style.py, `convert_image_paint`),
24
+ * FILL is cover, FIT is contain and STRETCH a stretch; Taco has no tiling.
25
+ */
26
+ function imageFit(paint, at) {
27
+ const mode = field(paint, "imageScaleMode", "string", at) ?? "STRETCH";
28
+ if (mode === "FILL")
29
+ return { fit: "cover" };
30
+ if (mode === "FIT")
31
+ return { fit: "contain" };
32
+ if (mode === "STRETCH") {
33
+ const m = field(paint, "transform", "object", at);
34
+ const identity = { m00: 1, m01: 0, m02: 0, m10: 0, m11: 1, m12: 0 };
35
+ const cropped = m !== undefined && Object.entries(identity).some(([key, value]) => (m[key] ?? value) !== value);
36
+ return cropped ? { fit: "fill", approximated: "the image crop is not kept; the whole image is stretched to the box" } : { fit: "fill" };
37
+ }
38
+ if (mode === "TILE") {
39
+ const scale = field(paint, "scale", "number", at) ?? 1;
40
+ // Moondraft patch (../carry.ts): the tile and its scale are carried; Taco's own paint stays cover.
41
+ return { fit: "cover", tile: scale };
42
+ }
43
+ return { fit: "cover", approximated: `image scale mode ${mode} has no Taco equivalent; the image covers the box` };
44
+ }
45
+ /**
46
+ * A Figma IMAGE paint as a Taco image paint whose asset the host supplied
47
+ * (`FigmaImportOptions.images`), or a reason it is left out. `null` means it
48
+ * is left out for a reason already reported for the same image. Rotation
49
+ * and image adjustments (`paintFilter`, `filterColorAdjust`) are reported, not kept.
50
+ */
51
+ export function imagePaint(paint, at, label, walk) {
52
+ const image = field(paint, "image", "object", at);
53
+ const hash = image?.["hash"];
54
+ if (!(hash instanceof Uint8Array) || hash.length === 0)
55
+ return "the image paint has no image hash";
56
+ const width = field(paint, "originalImageWidth", "number", at);
57
+ const height = field(paint, "originalImageHeight", "number", at);
58
+ const asset = walk.image(hexText(hash), width !== undefined && height !== undefined ? { width, height } : undefined);
59
+ if (asset === null || typeof asset === "string")
60
+ return asset;
61
+ const { fit, approximated, tile } = imageFit(paint, at);
62
+ if (approximated)
63
+ walk.report("approximated", `${label}: ${approximated}`);
64
+ const rotation = field(paint, "rotation", "number", at) ?? 0;
65
+ if (rotation % 360 !== 0)
66
+ walk.report("approximated", `${label}: the image rotation of ${String(rotation)} degrees is not kept`);
67
+ // Kiwi has two adjustment fields (`paintFilter` and the older struct
68
+ // `filterColorAdjust`); the plugin API calls them `filters`.
69
+ const adjusted = new Set();
70
+ for (const name of ["paintFilter", "filterColorAdjust", "filters"]) {
71
+ const filters = field(paint, name, "object", at);
72
+ for (const [key, value] of Object.entries(filters ?? {})) {
73
+ if (typeof value === "number" && value !== 0)
74
+ adjusted.add(key);
75
+ }
76
+ }
77
+ if (adjusted.size > 0)
78
+ walk.report("approximated", `${label}: the image adjustments (${[...adjusted].join(", ")}) are not kept`);
79
+ const imaged = { kind: "image", assetId: asset.assetId, ...(fit !== "cover" ? { fit } : {}) };
80
+ if (tile !== undefined)
81
+ markTile(imaged, tile);
82
+ return imaged;
83
+ }