@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,576 @@
1
+ import { field, isObject } from "../fields.js";
2
+ import { styleBackedList } from "../styles.js";
3
+ import { framedBase, hexColor, readNumbers } from "./shared.js";
4
+ const ALIGN = { LEFT: "left", CENTER: "center", RIGHT: "right", JUSTIFIED: "justify" };
5
+ const VERTICAL_ALIGN = { TOP: "top", CENTER: "middle", BOTTOM: "bottom" };
6
+ const AUTO_RESIZE = { NONE: "none", HEIGHT: "height", WIDTH_AND_HEIGHT: "width-and-height" };
7
+ /** Weights by style-name word, spaces, hyphens and case ignored, as CSS font-weight. */
8
+ const WEIGHTS = {
9
+ thin: 100, hairline: 100, extralight: 200, ultralight: 200, light: 300, regular: 400, normal: 400, book: 400, "": 400,
10
+ medium: 500, semibold: 600, demibold: 600, bold: 700, extrabold: 800, ultrabold: 800, black: 900, heavy: 900,
11
+ };
12
+ /** 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. */
13
+ export function fontStyleWeight(styleName) {
14
+ const words = styleName.toLowerCase().replace(/[\s_-]/g, "");
15
+ return { fontWeight: WEIGHTS[words.replace(/italic|oblique/g, "")], italic: /italic|oblique/.test(words) };
16
+ }
17
+ /** Figma's line height when `lineHeight` is 100 percent ("Auto") and the font's own line height is not in the message. */
18
+ const AUTO_LINE_HEIGHT = 1.2;
19
+ const AUTO_LINE_HEIGHT_REASON = `the auto line height is imported as ${String(AUTO_LINE_HEIGHT)} times the font size; the font's own line height is not in the message`;
20
+ const LINE_HEIGHT_VARIABLE_REASON = "line height variable kept as its value: Taco's line height is a multiple of the font size";
21
+ /**
22
+ * A field the importer adds to a text layer's Figma fields, never one Figma writes: the line height in pixels Figma laid
23
+ * out every line of this layer at in an instance (its stored `derivedTextData`), which replaces the line height the
24
+ * layer's runs would take from their text style or variable. The runs stay linked to their style, with this line height
25
+ * as an override.
26
+ */
27
+ export const KEPT_LINE_HEIGHT_FIELD = "tacoKeptLineHeight";
28
+ /**
29
+ * A Figma TEXT node as a Taco text node. `textData.characters` is split into
30
+ * paragraphs at each newline, and each paragraph into runs where the style id
31
+ * changes. `textData.characterStyleIDs` holds one id per code point and may
32
+ * be shorter than the text: missing ids are 0. Id 0 is the node's own style;
33
+ * every other id names an entry of `textData.styleOverrideTable` whose fields
34
+ * replace the node's. Fonts are named by family, weight and italic only;
35
+ * `fontAssetId` is left for the host to bind. A node or override entry that
36
+ * names a Figma text style (`styleIdForText`) takes the style's typography
37
+ * over the node's stored copies (an override entry's own fields still win, and
38
+ * the colour stays the node's), and its runs link to the shared style the walk made
39
+ * for it (`NodeWalk.textStyle`), with only the fields that differ as overrides.
40
+ * A line height bound to a variable (`LINE_HEIGHT`) is the variable's value in
41
+ * the mode the node uses (`NodeWalk.variableNumber`), as a fixed multiple of the
42
+ * font size, read from the same place as the line height itself (`runBinding`).
43
+ */
44
+ export const convertText = (node, walk) => {
45
+ const where = `node ${node.id}`;
46
+ const change = node.change;
47
+ const base = framedBase(node, walk, "Text");
48
+ if (base === null)
49
+ return null;
50
+ // Taco text has no strokes yet, so a text stroke is reported rather than dropped.
51
+ if ((styleBackedList(change, "strokePaints", walk.styleList, where)?.length ?? 0) > 0)
52
+ walk.report("property-left-out", "text strokes are not imported yet");
53
+ const textData = field(change, "textData", "object", where) ?? {};
54
+ const characters = field(textData, "characters", "string", `${where} textData`) ?? "";
55
+ const ids = field(textData, "characterStyleIDs", "list", `${where} textData`) ?? [];
56
+ const table = new Map();
57
+ for (const entry of field(textData, "styleOverrideTable", "list", `${where} textData`) ?? []) {
58
+ if (!isObject(entry))
59
+ continue;
60
+ const id = field(entry, "styleID", "number", `${where} styleOverrideTable`);
61
+ if (id !== undefined && id !== 0)
62
+ table.set(id, entry);
63
+ }
64
+ // Each report reason once per node, however many runs share it, and at most
65
+ // MAX_REPORTS reasons per node: each entry carries the node's path, so many
66
+ // style ids must not make many entries.
67
+ // Reasons past the limit are still remembered, so each is counted once.
68
+ const reasons = new Set();
69
+ let reasonsLeftOut = 0;
70
+ const report = (kind, reason) => {
71
+ if (reasons.has(`${kind} ${reason}`))
72
+ return;
73
+ reasons.add(`${kind} ${reason}`);
74
+ if (reasons.size > MAX_REPORTS)
75
+ reasonsLeftOut += 1;
76
+ else
77
+ walk.report(kind, reason);
78
+ };
79
+ // Built once per node so each run's lookups do not scan the whole list.
80
+ const lookups = runLookups(change, where);
81
+ const keptLineHeight = typeof change[KEPT_LINE_HEIGHT_FIELD] === "number" ? change[KEPT_LINE_HEIGHT_FIELD] : undefined;
82
+ const nodeTextStyle = change["styleIdForText"] === undefined ? undefined : walk.textStyle?.(change["styleIdForText"], change);
83
+ if (change["styleIdForText"] !== undefined && walk.textStyle === undefined)
84
+ report("property-left-out", "the Figma text style is not imported; its values are kept as direct formatting");
85
+ // A text layer or styled range that names a fill style is drawn in the style's paints (`styleBackedList`).
86
+ const nodeFills = styleBackedList(change, "fillPaints", walk.styleList, where, report);
87
+ const filled = nodeFills === change["fillPaints"] ? change : { ...change, fillPaints: nodeFills };
88
+ const entryFilled = (override) => {
89
+ if (override?.["styleIdForFill"] === undefined)
90
+ return override;
91
+ const fills = styleBackedList(override, "fillPaints", walk.styleList, `${where} styleOverrideTable`, report);
92
+ return fills === override["fillPaints"] ? override : { ...override, fillPaints: fills };
93
+ };
94
+ const styles = new Map();
95
+ const textStyleOfEntry = (override) => override?.["styleIdForText"] === undefined ? nodeTextStyle : walk.textStyle?.(override["styleIdForText"], change);
96
+ // The line height in pixels each style id takes from a variable, for runs drawn at a bound font size (below).
97
+ const boundPixels = new Map();
98
+ const runIds = new Map();
99
+ // The font size and line height (a multiple of the size) each style id draws at, for list indents (`listIndentOf`).
100
+ const sizes = new Map();
101
+ let missingIds = 0;
102
+ const styleOf = (id) => {
103
+ let style = styles.get(id);
104
+ if (style === undefined) {
105
+ const override = table.get(id);
106
+ if (id !== 0 && override === undefined)
107
+ missingIds += 1;
108
+ const textStyle = textStyleOfEntry(override);
109
+ const fields = styleFields(filled, entryFilled(override), textStyle?.change);
110
+ const boundLineHeight = keptLineHeight ?? boundLineHeightOf(change, override, textStyle?.change, where, walk.variableNumber);
111
+ const said = [];
112
+ const own = runStyle(fields, lookups, (kind, reason) => said.push([kind, reason]), where, boundLineHeight);
113
+ sizes.set(id, { fontSize: own.fontSize ?? 12, lineHeight: own.lineHeight ?? AUTO_LINE_HEIGHT });
114
+ if (keptLineHeight !== undefined)
115
+ boundPixels.set(id, keptLineHeight);
116
+ else if (boundLineHeight !== undefined) {
117
+ boundPixels.set(id, boundLineHeight);
118
+ // Reported only where the variable's value replaces a different stored line height.
119
+ const stored = runStyle(fields, lookups, () => undefined, where).lineHeight * (own.fontSize ?? 12);
120
+ if (Math.abs(stored - boundLineHeight) > 1e-6)
121
+ said.push(["approximated", LINE_HEIGHT_VARIABLE_REASON]);
122
+ }
123
+ const bothAuto = textStyle !== undefined && boundLineHeight === undefined && autoLineHeight(fields) && autoLineHeight(textStyle.change);
124
+ style = textStyle?.shared === undefined ? { overrides: own } : linkedRun(textStyle.shared, own, bothAuto);
125
+ if (walk.fontSizeVariable) {
126
+ const data = runBinding(change, override, textStyle?.change, where, "FONT_SIZE", "fontSize");
127
+ if (data !== undefined) {
128
+ const variable = walk.fontSizeVariable(data);
129
+ // An omitted style binding is reported on the definition, once for all its users.
130
+ if (variable || !textStyle?.shared || data !== bindingIn(textStyle.change, "FONT_SIZE", where))
131
+ Object.assign(style, { fileFontSize: variable });
132
+ }
133
+ }
134
+ // A run that keeps its style's auto line height has the style's, which may come from another layer's font metadata.
135
+ const keepsStyleLineHeight = bothAuto && textStyle.shared !== undefined && style.overrides?.lineHeight === undefined;
136
+ for (const [kind, reason] of said)
137
+ if (!(keepsStyleLineHeight && reason === AUTO_LINE_HEIGHT_REASON))
138
+ report(kind, reason);
139
+ styles.set(id, style);
140
+ }
141
+ return style;
142
+ };
143
+ const runOf = (runText, id) => {
144
+ const run = { text: runText, ...styleOf(id) };
145
+ runIds.set(run, id);
146
+ return run;
147
+ };
148
+ const align = ALIGN[field(change, "textAlignHorizontal", "string", where) ?? "LEFT"];
149
+ const paragraphs = [];
150
+ let runs = [];
151
+ let text = "";
152
+ let runId = -1;
153
+ const endRun = () => {
154
+ if (text !== "")
155
+ runs.push(runOf(text, runId));
156
+ text = "";
157
+ };
158
+ let index = 0;
159
+ // `for…of` walks by code point, so an emoji made of two UTF-16 units takes one style id.
160
+ for (const character of characters) {
161
+ const raw = ids[index++];
162
+ const id = typeof raw === "number" ? raw : 0;
163
+ if (character === "\n") {
164
+ endRun();
165
+ paragraphs.push({ runs: runs.length > 0 ? runs : [runOf("", id)], ...(align ? { align } : {}) });
166
+ runs = [];
167
+ runId = -1;
168
+ continue;
169
+ }
170
+ if (id !== runId)
171
+ endRun();
172
+ runId = id;
173
+ text += character;
174
+ }
175
+ endRun();
176
+ paragraphs.push({ runs: runs.length > 0 ? runs : [runOf("", typeof ids[index] === "number" ? ids[index] : 0)], ...(align ? { align } : {}) });
177
+ const lists = listsOf(textData, report, where);
178
+ const markerAdvances = bulletAdvancesOf(change, characters);
179
+ lists.forEach((list, line) => {
180
+ const paragraph = paragraphs[line];
181
+ if (list === undefined || paragraph === undefined)
182
+ return;
183
+ const id = runIds.get(paragraph.runs[0]);
184
+ const size = sizes.get(id ?? 0) ?? { fontSize: 12, lineHeight: AUTO_LINE_HEIGHT };
185
+ paragraphs[line] = { ...paragraph, ...listIndentOf(list, size, markerAdvances[line]) };
186
+ });
187
+ // Figma's paragraph spacing is the space between paragraphs, which is the text's `paragraphSpacing`, so a paragraph
188
+ // added later, such as by a text property with line breaks, is apart by it too. Two list items in a row are apart by
189
+ // the list spacing instead, which the later one keeps as its own space above where it differs. A linked text style's
190
+ // value beats the copy stored on the layer, as for the rest of its typography.
191
+ const spacing = spacingOf("paragraphSpacing", nodeTextStyle?.change, change, where);
192
+ const listSpacing = spacingOf("listSpacing", nodeTextStyle?.change, change, where);
193
+ for (let line = 1; line < paragraphs.length; line += 1) {
194
+ const inList = paragraphs[line].list !== undefined && paragraphs[line - 1].list !== undefined;
195
+ if (inList && listSpacing !== spacing)
196
+ paragraphs[line] = { ...paragraphs[line], spacingBefore: listSpacing };
197
+ }
198
+ // Lists are matched to paragraphs by position, so a count mismatch can drop or misplace them.
199
+ if (lists.length !== paragraphs.length && lists.some((list) => list !== undefined)) {
200
+ report("approximated", `the text has ${String(lists.length)} line entr${lists.length === 1 ? "y" : "ies"} for ${String(paragraphs.length)} paragraph${paragraphs.length === 1 ? "" : "s"}; list formatting is matched by position and may be on the wrong paragraphs or left out`);
201
+ }
202
+ if (missingIds > 0) {
203
+ report("approximated", `${String(missingIds)} style id${missingIds === 1 ? " is" : "s are"} not in the style override table; their characters use the node's style`);
204
+ }
205
+ reportLeftOut(change, textData, table, report, where, nodeTextStyle?.change);
206
+ const autoResize = AUTO_RESIZE[field(change, "textAutoResize", "string", where) ?? "NONE"];
207
+ if (autoResize === undefined)
208
+ report("approximated", `textAutoResize ${String(change["textAutoResize"])} is imported as a fixed size`);
209
+ // Last, after every call to `report`, so the count includes them all.
210
+ if (reasonsLeftOut > 0)
211
+ walk.report("approximated", `${String(reasonsLeftOut)} more report line${reasonsLeftOut === 1 ? " is" : "s are"} left out for this text node`);
212
+ const verticalAlign = VERTICAL_ALIGN[field(change, "textAlignVertical", "string", where) ?? "TOP"];
213
+ const textNode = {
214
+ ...base,
215
+ type: "text",
216
+ paragraphs,
217
+ verticalAlign: verticalAlign ?? "top",
218
+ overflow: "visible",
219
+ autoResize: autoResize ?? "none",
220
+ wrap: autoResize === "width-and-height" ? "none" : "word",
221
+ ...(spacing > 0 ? { paragraphSpacing: spacing } : {}),
222
+ };
223
+ // Taco draws every run at the layer's bound font size where it keeps that binding (`bindLayerVariables`), so a line
224
+ // height from a variable is a multiple of that size instead of the stored one, and the drawn line height is the variable's.
225
+ const drawn = boundPixels.size === 0 ? undefined : walk.keptFontSize?.(textNode);
226
+ if (drawn === undefined)
227
+ return textNode;
228
+ const atDrawnSize = (run) => {
229
+ const id = runIds.get(run);
230
+ const pixels = id === undefined ? undefined : boundPixels.get(id);
231
+ if (pixels === undefined)
232
+ return run;
233
+ const lineHeight = pixels / drawn;
234
+ const { lineHeight: _stored, ...rest } = run.overrides ?? {};
235
+ const shared = run.styleId === undefined ? undefined : textStyleOfEntry(table.get(id))?.shared;
236
+ const overrides = shared !== undefined && shared.style.lineHeight === lineHeight ? rest : { ...rest, lineHeight };
237
+ const { overrides: _overrides, ...plain } = run;
238
+ return Object.keys(overrides).length === 0 ? plain : { ...plain, overrides };
239
+ };
240
+ return { ...textNode, paragraphs: textNode.paragraphs.map((paragraph) => ({ ...paragraph, runs: paragraph.runs.map(atDrawnSize) })) };
241
+ };
242
+ /** Most distinct report reasons one text node adds; the rest are counted in one closing line. */
243
+ const MAX_REPORTS = 20;
244
+ /** The fields `runStyle` reads. */
245
+ const STYLE_FIELDS = ["fontName", "fontSize", "lineHeight", "letterSpacing", "textDecoration", "fontVariations", "fillPaints"];
246
+ /**
247
+ * The fields a run reads, in this order: an override entry's own, then for
248
+ * typography the Figma text style they name (`under`), then the node's. As in
249
+ * Figma, a linked style's typography beats the copies stored on the layer,
250
+ * which can be stale; the colour (`fillPaints`) is the layer's, and the style's
251
+ * only where the layer has none. A linked style that leaves out its decoration
252
+ * has none, so the layer's stale `textDecoration` is not read either (Figma
253
+ * draws no underline there). Only the fields a run reads are copied, so
254
+ * the work per style id does not grow with the number of other fields on the node.
255
+ */
256
+ function styleFields(change, override, under) {
257
+ const style = {};
258
+ for (const name of STYLE_FIELDS) {
259
+ const value = override !== undefined && Object.hasOwn(override, name)
260
+ ? override[name]
261
+ : name === "fillPaints" ? change[name] ?? under?.[name]
262
+ : name === "textDecoration" && under !== undefined ? under[name]
263
+ : under?.[name] ?? change[name];
264
+ if (value !== undefined)
265
+ style[name] = value;
266
+ }
267
+ return style;
268
+ }
269
+ /**
270
+ * The variable data a run's `variableField` (`LINE_HEIGHT` or `FONT_SIZE`) is bound to, read where `styleFields` reads
271
+ * the field it binds (`name`): an override entry's own binding, or none when the entry sets its own value; else the text
272
+ * style's (`under`), else the node's.
273
+ */
274
+ function runBinding(change, override, under, where, variableField, name) {
275
+ const bound = (fields) => bindingIn(fields, variableField, where);
276
+ if (override !== undefined) {
277
+ const own = bound(override);
278
+ if (own !== undefined || Object.hasOwn(override, name))
279
+ return own;
280
+ }
281
+ return under !== undefined && under[name] !== undefined ? bound(under) : bound(change);
282
+ }
283
+ /** The variable data Figma fields bind `variableField` to, or `undefined`. */
284
+ function bindingIn(fields, variableField, where) {
285
+ const map = field(fields, "variableConsumptionMap", "object", where);
286
+ const entry = (map && field(map, "entries", "list", `${where} variableConsumptionMap`) || [])
287
+ .find((item) => isObject(item) && item["variableField"] === variableField);
288
+ return isObject(entry) ? entry["variableData"] : undefined;
289
+ }
290
+ /** A run's line height in pixels from the variable it is bound to (`runBinding`), or `undefined` without one. */
291
+ function boundLineHeightOf(change, override, under, where, variableNumber) {
292
+ if (variableNumber === undefined)
293
+ return undefined;
294
+ const lineData = runBinding(change, override, under, where, "LINE_HEIGHT", "lineHeight");
295
+ return lineData === undefined ? undefined : variableNumber(lineData);
296
+ }
297
+ /** The fields a style has that turn off when a run leaves them out, with the value that turns each off. */
298
+ const STYLE_OFF = [["italic", false], ["underline", false], ["strikethrough", false], ["letterSpacing", 0], ["fontVariations", {}]];
299
+ /**
300
+ * A run linked to its shared style, with the fields of `own` that differ from
301
+ * the style's as its overrides. With `bothAuto` (the run's line height and the
302
+ * style's are Figma's "Auto") and the style's font, the run keeps the style's
303
+ * line height, so editing the style's line height reaches it.
304
+ */
305
+ function linkedRun(shared, own, bothAuto) {
306
+ const style = shared.style;
307
+ const overrides = {};
308
+ for (const [name, value] of Object.entries(own))
309
+ if (JSON.stringify(value) !== JSON.stringify(style[name]))
310
+ overrides[name] = value;
311
+ for (const [name, off] of STYLE_OFF) {
312
+ if (own[name] === undefined && style[name] !== undefined && JSON.stringify(style[name]) !== JSON.stringify(off))
313
+ overrides[name] = off;
314
+ }
315
+ if (bothAuto && !("fontFamily" in overrides || "fontWeight" in overrides || "italic" in overrides))
316
+ delete overrides["lineHeight"];
317
+ return Object.keys(overrides).length === 0 ? { styleId: shared.id } : { styleId: shared.id, overrides: overrides };
318
+ }
319
+ /**
320
+ * A Figma text style node (`styleType` TEXT) as a Taco text style, read as a
321
+ * run of a node without overrides is; a value it lacks is Figma's default.
322
+ * An auto line height is the font's own from the style node's font metadata,
323
+ * else from the first of `layers`, the text layers that name the style, that has it.
324
+ * A line height bound to a variable is the number `variableNumber` gives for it; the
325
+ * layers that use the style report it.
326
+ */
327
+ export function figmaTextStyle(change, name, report, where, layers = [], variableNumber) {
328
+ // A Taco text style binds no font size, so its line height is a multiple of the stored size.
329
+ const boundLineHeight = boundLineHeightOf(change, undefined, undefined, where, variableNumber);
330
+ // `runStyle` names no font asset.
331
+ const { fontAssetId: _fontAssetId, ...own } = runStyle(styleFields(change, undefined), runLookups(change, where, layers), report, where, boundLineHeight);
332
+ return {
333
+ ...own,
334
+ name: name.trim() === "" ? "Text style" : name,
335
+ fontFamily: own.fontFamily ?? "Inter",
336
+ fontSize: own.fontSize ?? 12,
337
+ fontWeight: own.fontWeight ?? 400,
338
+ lineHeight: own.lineHeight ?? AUTO_LINE_HEIGHT,
339
+ color: own.color ?? "#000000",
340
+ };
341
+ }
342
+ /**
343
+ * Fresh run lookups with the font metadata of the node's `derivedTextData`,
344
+ * then each of `more`'s, first entry for each family and style.
345
+ */
346
+ function runLookups(change, where, more = []) {
347
+ const lookups = { fontMeta: new Map(), variations: new Map(), colors: new Map() };
348
+ const metadata = (node) => field(field(node, "derivedTextData", "object", where) ?? {}, "fontMetaData", "list", where) ?? [];
349
+ for (const entry of [change, ...more].flatMap(metadata)) {
350
+ const key = isObject(entry) && isObject(entry["key"]) ? entry["key"] : undefined;
351
+ if (key === undefined || typeof key["family"] !== "string" || typeof key["style"] !== "string")
352
+ continue;
353
+ const name = fontKey(key["family"], key["style"]);
354
+ if (!lookups.fontMeta.has(name))
355
+ lookups.fontMeta.set(name, entry);
356
+ }
357
+ return lookups;
358
+ }
359
+ const fontKey = (family, style) => `${family}\u0000${style}`;
360
+ /** Whether a style's `lineHeight` is Figma's "Auto", the font's own, as `runStyle` reads it. */
361
+ function autoLineHeight(style) {
362
+ const lineHeight = style["lineHeight"];
363
+ return !isObject(lineHeight) || typeof lineHeight["value"] !== "number" || (lineHeight["units"] === "PERCENT" && lineHeight["value"] === 100);
364
+ }
365
+ /**
366
+ * The style of one run from the node's fields with an override entry's fields on top. `boundLineHeight`, in pixels,
367
+ * replaces the stored line height: the value of the variable it is bound to, as a multiple of the stored font size.
368
+ */
369
+ function runStyle(style, lookups, report, where, boundLineHeight) {
370
+ const fontName = field(style, "fontName", "object", where) ?? {};
371
+ const family = field(fontName, "family", "string", `${where} fontName`);
372
+ const styleName = field(fontName, "style", "string", `${where} fontName`) ?? "";
373
+ const fontSize = field(style, "fontSize", "number", where);
374
+ const { fontWeight: weight, italic } = fontStyleWeight(styleName);
375
+ if (weight === undefined)
376
+ report("approximated", `font style "${styleName}" has no known weight; it is imported as weight 400`);
377
+ const fontWeight = weight ?? 400;
378
+ const size = fontSize ?? 12;
379
+ const out = {
380
+ ...(family === undefined ? {} : { fontFamily: family }),
381
+ ...(styleName && { fontStyle: styleName }),
382
+ ...(fontSize === undefined ? {} : { fontSize }),
383
+ fontWeight,
384
+ ...(italic ? { italic } : {}),
385
+ };
386
+ const lineHeight = field(style, "lineHeight", "object", where);
387
+ const lineValue = lineHeight && field(lineHeight, "value", "number", `${where} lineHeight`);
388
+ const lineUnits = lineHeight && field(lineHeight, "units", "string", `${where} lineHeight`);
389
+ if (boundLineHeight !== undefined)
390
+ out.lineHeight = boundLineHeight / size;
391
+ else if (lineValue === undefined || (lineUnits === "PERCENT" && lineValue === 100)) {
392
+ // Figma's "Auto" line height is the font's own, which the message may carry.
393
+ const meta = family === undefined ? undefined : lookups.fontMeta.get(fontKey(family, styleName));
394
+ const natural = meta && field(meta, "fontLineHeight", "number", `${where} fontMetaData`);
395
+ if (natural === undefined)
396
+ report("approximated", AUTO_LINE_HEIGHT_REASON);
397
+ out.lineHeight = natural ?? AUTO_LINE_HEIGHT;
398
+ }
399
+ else if (lineUnits === "PIXELS")
400
+ out.lineHeight = lineValue / size;
401
+ else if (lineUnits === "PERCENT")
402
+ out.lineHeight = lineValue / 100;
403
+ else
404
+ out.lineHeight = lineValue;
405
+ const spacing = field(style, "letterSpacing", "object", where);
406
+ const spacingValue = spacing && field(spacing, "value", "number", `${where} letterSpacing`);
407
+ if (spacing && spacingValue !== undefined && spacingValue !== 0) {
408
+ out.letterSpacing = field(spacing, "units", "string", `${where} letterSpacing`) === "PIXELS" ? spacingValue : size * spacingValue / 100;
409
+ }
410
+ const decoration = field(style, "textDecoration", "string", where);
411
+ if (decoration === "UNDERLINE")
412
+ out.underline = true;
413
+ if (decoration === "STRIKETHROUGH")
414
+ out.strikethrough = true;
415
+ const axes = field(style, "fontVariations", "list", where) ?? [];
416
+ let variations = lookups.variations.get(axes);
417
+ if (variations === undefined) {
418
+ variations = {};
419
+ for (const axis of axes) {
420
+ const tag = isObject(axis) ? axis["axisTag"] : undefined;
421
+ const value = isObject(axis) ? axis["value"] : undefined;
422
+ // `axisTag` packs the four tag letters into a number, first letter in the high byte.
423
+ if (typeof tag === "number" && typeof value === "number")
424
+ variations[String.fromCharCode(tag >>> 24 & 255, tag >>> 16 & 255, tag >>> 8 & 255, tag & 255)] = value;
425
+ }
426
+ lookups.variations.set(axes, variations);
427
+ }
428
+ if (Object.keys(variations).length > 0)
429
+ out.fontVariations = variations;
430
+ const paints = field(style, "fillPaints", "list", where) ?? [];
431
+ let color = lookups.colors.get(paints);
432
+ if (color === undefined) {
433
+ color = textColor(paints, report, where);
434
+ lookups.colors.set(paints, color);
435
+ }
436
+ out.color = color;
437
+ return out;
438
+ }
439
+ /** The top visible solid fill as a colour with the paint's opacity in its alpha; other fills are reported. */
440
+ function textColor(paints, report, where) {
441
+ let color;
442
+ for (let i = paints.length - 1; i >= 0; i--) {
443
+ const paint = paints[i];
444
+ if (!isObject(paint) || field(paint, "visible", "boolean", where) === false)
445
+ continue;
446
+ const type = field(paint, "type", "string", where) ?? "no type";
447
+ const channels = type === "SOLID" ? readNumbers(field(paint, "color", "object", where) ?? {}, ["r", "g", "b", "a"], `${where} fill colour`) : null;
448
+ if (color !== undefined || channels === null) {
449
+ report("property-left-out", `a ${type} text fill is left out: only the top solid fill is imported`);
450
+ continue;
451
+ }
452
+ color = hexColor({ ...channels, a: channels.a * (field(paint, "opacity", "number", where) ?? 1) });
453
+ const blend = field(paint, "blendMode", "string", where);
454
+ if (blend !== undefined && blend !== "NORMAL" && blend !== "PASS_THROUGH")
455
+ report("property-left-out", `the text fill's blend mode ${blend} is left out; its colour is kept`);
456
+ }
457
+ // No visible fill draws no glyphs; the text keeps its layout.
458
+ return color ?? "#00000000";
459
+ }
460
+ /** A spacing in pixels from the Figma text style (`style`), else the node, else 0; negative values are 0. */
461
+ /**
462
+ * The paragraph or list spacing of a text: its linked text style's where it has one, else the layer's. A linked style
463
+ * that leaves the spacing out has none, so the stale copy on the layer is not read (Figma draws no space then).
464
+ */
465
+ function spacingOf(name, style, change, where) {
466
+ const value = (style === undefined ? field(change, name, "number", where) : field(style, name, "number", `${where} text style`)) ?? 0;
467
+ return Number.isFinite(value) && value > 0 ? value : 0;
468
+ }
469
+ /** Each step of list nesting in Figma, as a multiple of the font size: an item at indentation level n starts its text n steps in. */
470
+ const LIST_INDENT_STEP = 1.5;
471
+ /** The width of Figma's bullet as a multiple of the font size (Inter's "•"), used when the message has no laid-out marker. */
472
+ const BULLET_ADVANCE = 0.5625;
473
+ /**
474
+ * The indent and marker gap that put a list item's text and marker where Figma does. Figma starts the text of an item at
475
+ * indentation level n (Taco level n - 1) at n × 1.5 × the font size and centres a bullet in the 1.5 × font size step
476
+ * before it. Taco adds level × line height for nesting (`resolveTextListLayout`) and draws the marker `gap` before the
477
+ * text, so the indent takes the rest of Figma's offset and the gap puts the bullet's centre half a step before the
478
+ * text. `advance` is the bullet's width as laid out by Figma, when the message has it.
479
+ */
480
+ function listIndentOf(list, size, advance) {
481
+ const step = LIST_INDENT_STEP * size.fontSize;
482
+ const left = Math.max(0, (list.level + 1) * step - list.level * size.fontSize * size.lineHeight);
483
+ const indent = { left, right: 0, firstLine: -Math.min(step, left) };
484
+ if (list.kind !== "unordered")
485
+ return { list, indent };
486
+ const gap = Math.max(0, (step - (advance ?? BULLET_ADVANCE * size.fontSize)) / 2);
487
+ return { list: { ...list, marker: { ...list.marker, gap } }, indent };
488
+ }
489
+ /**
490
+ * The width in pixels of the bullet Figma laid out before each paragraph, from `derivedTextData`: a marker is a glyph with
491
+ * no `firstCharacter` on the baseline of its paragraph's first line. Paragraphs without one are left out.
492
+ */
493
+ function bulletAdvancesOf(change, characters) {
494
+ const derived = change["derivedTextData"];
495
+ if (!isObject(derived) || !Array.isArray(derived["baselines"]) || !Array.isArray(derived["glyphs"]))
496
+ return [];
497
+ const markers = derived["glyphs"].filter((glyph) => isObject(glyph) && glyph["firstCharacter"] === undefined);
498
+ const lineYs = new Map();
499
+ for (const baseline of derived["baselines"]) {
500
+ if (!isObject(baseline) || typeof baseline["firstCharacter"] !== "number" || !isObject(baseline["position"]))
501
+ continue;
502
+ const y = baseline["position"]["y"];
503
+ if (typeof y === "number")
504
+ lineYs.set(baseline["firstCharacter"], y);
505
+ }
506
+ const advances = [];
507
+ let start = 0;
508
+ for (const paragraph of characters.split("\n")) {
509
+ const y = lineYs.get(start);
510
+ const marker = y === undefined ? undefined : markers.find((glyph) => isObject(glyph["position"]) && glyph["position"]["y"] === y);
511
+ const advance = marker?.["advance"];
512
+ const fontSize = marker?.["fontSize"];
513
+ advances.push(typeof advance === "number" && typeof fontSize === "number" && Number.isFinite(advance * fontSize) ? advance * fontSize : undefined);
514
+ start += [...paragraph].length + 1;
515
+ }
516
+ return advances;
517
+ }
518
+ /** Reports the text fields Taco does not import yet, one entry for each field. */
519
+ function reportLeftOut(change, textData, table, report, where, textStyle) {
520
+ // The text style's case applies where the node has none of its own.
521
+ const styles = [change, ...table.values(), ...(textStyle !== undefined && change["textCase"] === undefined ? [textStyle] : [])];
522
+ const textCase = styles.map((style) => field(style, "textCase", "string", where)).find((value) => value !== undefined && value !== "ORIGINAL");
523
+ if (textCase !== undefined)
524
+ report("property-left-out", `text case ${textCase} is not imported; the characters are kept as typed`);
525
+ const truncation = field(change, "textTruncation", "string", where);
526
+ if (truncation !== undefined && truncation !== "DISABLED")
527
+ report("property-left-out", `text truncation ${truncation} is not imported`);
528
+ if ((field(change, "maxLines", "number", where) ?? 0) > 0)
529
+ report("property-left-out", "the maximum line count is not imported");
530
+ if (styles.some((style) => isObject(style["hyperlink"]) && Object.keys(style["hyperlink"]).length > 0))
531
+ report("property-left-out", "links are not imported");
532
+ }
533
+ const LIST_KIND = { ORDERED_LIST: "ordered", UNORDERED_LIST: "unordered" };
534
+ /**
535
+ * The list of each paragraph, from `textData.lines` (one entry per paragraph).
536
+ * Figma's `indentationLevel` is 1 for a top-level list item, so Taco's level is
537
+ * one less. Taco draws an ordered item's number as its `start`, or as its
538
+ * paragraph index plus one when `start` is left out (see `resolveTextListLayout` in
539
+ * packages/model/src/text-measurement.ts), so `start` is each item's own number
540
+ * and not only the first number of a run. Items are numbered
541
+ * here the way Figma numbers them: a count for each level that starts at
542
+ * `listStartOffset` + 1 and restarts at a new list, after a plain line, after
543
+ * a shallower item, or when the kind at that level changes. `start` is set
544
+ * only where that number differs from the paragraph index plus one.
545
+ */
546
+ function listsOf(textData, report, where) {
547
+ const lines = field(textData, "lines", "list", `${where} textData`) ?? [];
548
+ const counts = [];
549
+ const kinds = [];
550
+ return lines.map((line, index) => {
551
+ const type = isObject(line) ? line["lineType"] : undefined;
552
+ const kind = typeof type === "string" ? LIST_KIND[type] : undefined;
553
+ if (kind === undefined) {
554
+ if (type !== undefined && type !== "PLAIN")
555
+ report("property-left-out", `line type ${String(type)} is not imported; the line is a plain paragraph`);
556
+ counts.length = 0;
557
+ kinds.length = 0;
558
+ return undefined;
559
+ }
560
+ const object = line;
561
+ const indentation = field(object, "indentationLevel", "number", `${where} textData line`) ?? 1;
562
+ const level = Number.isInteger(indentation) && indentation > 1 ? indentation - 1 : 0;
563
+ counts.length = Math.min(counts.length, level + 1);
564
+ kinds.length = Math.min(kinds.length, level + 1);
565
+ const restart = object["isFirstLineOfList"] === true || kinds[level] !== kind || counts[level] === undefined;
566
+ kinds[level] = kind;
567
+ if (kind === "unordered") {
568
+ counts[level] = undefined;
569
+ return { kind, level };
570
+ }
571
+ const offset = field(object, "listStartOffset", "number", `${where} textData line`) ?? 0;
572
+ const number = restart ? 1 + (Number.isInteger(offset) && offset > 0 ? offset : 0) : (counts[level] ?? 0) + 1;
573
+ counts[level] = number;
574
+ return number === index + 1 ? { kind, level } : { kind, level, start: number };
575
+ });
576
+ }
@@ -0,0 +1,84 @@
1
+ import { type DashCap, type LineNode, type PathNode, type Stroke, type TransformMatrix } from "../../../model/index.ts";
2
+ import { type FigmaObject } from "../fields.ts";
3
+ import type { FigmaTreeNode } from "../tree.ts";
4
+ import type { FigmaNodeConverter, NodeWalk } from "../walk.ts";
5
+ import type { Box } from "./gradient.ts";
6
+ /**
7
+ * The most paths in one node's `fillGeometry` and the most drawing commands
8
+ * in all of them together. A node over either is left out and reported.
9
+ */
10
+ export declare const VECTOR_GEOMETRY_LIMITS: {
11
+ readonly paths: 1000;
12
+ readonly commands: 100000;
13
+ };
14
+ /**
15
+ * Why a VECTOR's geometry is not imported, named at the start of the report
16
+ * reason as `geometry refused (<name>)`:
17
+ * - `no-geometry`: no `fillGeometry` path draws anything.
18
+ * - `not-a-path`: a `fillGeometry` entry is not a `Path` with a `commandsBlob`.
19
+ * - `unknown-winding-rule`: a `windingRule` other than `NONZERO` or `ODD`.
20
+ * - `blob-missing`: the `commandsBlob` is not in the message's `blobs`.
21
+ * - `blob-too-short`: the blob ends inside a command's coordinates.
22
+ * - `unknown-command`: a command code other than 0 to 4.
23
+ * - `not-finite`: a coordinate is NaN or infinite.
24
+ * - `draw-before-move`: a line or curve before the first moveTo.
25
+ * - `too-many-paths`, `too-many-commands`: over `VECTOR_GEOMETRY_LIMITS`.
26
+ * - `import-command-limit`: the whole import is over `limits.vectorCommands`.
27
+ */
28
+ export declare const VECTOR_GEOMETRY_PROBLEMS: readonly ["no-geometry", "not-a-path", "unknown-winding-rule", "blob-missing", "blob-too-short", "unknown-command", "not-finite", "draw-before-move", "too-many-paths", "too-many-commands", "import-command-limit"];
29
+ export type VectorGeometryProblem = (typeof VECTOR_GEOMETRY_PROBLEMS)[number];
30
+ /**
31
+ * The most paints and gradient stops `placedFills` may copy into a VECTOR's
32
+ * regions in total. Over it the node's gradients stay on one box, so a short
33
+ * paint list cannot be copied into thousands of regions.
34
+ */
35
+ export declare const REGION_FILL_COPY_LIMIT = 100000;
36
+ /**
37
+ * A path node's Figma `transform` as its Taco transform (Taco's [a, b, c, d,
38
+ * e, f] is Figma's [m00, m10, m01, m11, m02, m12]), or `null` after reporting
39
+ * the node left out when the transform is incomplete or squashes it flat.
40
+ */
41
+ export declare function pathTransform(node: FigmaTreeNode, walk: NodeWalk): TransformMatrix | null;
42
+ /**
43
+ * A path node's strokes, gradients placed on `box`, and the cap of its ends
44
+ * and dashes from Figma's `strokeCap`; a cap Taco has no match for is
45
+ * reported and imported flat.
46
+ */
47
+ export declare function pathStrokes(node: FigmaTreeNode, walk: NodeWalk, box: Box | undefined): {
48
+ strokes: Stroke[];
49
+ cap: DashCap;
50
+ };
51
+ /**
52
+ * A Figma VECTOR as a Taco path. The shape is the node's editable vector
53
+ * network (`vectorData.vectorNetworkBlob`, what a paste carries) when it has
54
+ * one, else its `fillGeometry`, the outline Figma fills (also when the
55
+ * network is refused, which is reported); either is in the
56
+ * node's own space. Figma's `transform` places it exactly as the path's
57
+ * transform (Taco's [a, b, c, d, e, f] is Figma's [m00, m10, m01, m11, m02,
58
+ * m12]), so scale and skew are kept. Corner radii are already in a
59
+ * `fillGeometry` outline; with a network the node's `cornerRadius` is the
60
+ * path's corner radius. `strokeGeometry` (the stroke outlined) is not
61
+ * read: Taco draws the strokes from the path.
62
+ */
63
+ export declare const convertVector: FigmaNodeConverter;
64
+ /**
65
+ * A Figma BOOLEAN_OPERATION as a Taco path drawn from its `fillGeometry`, the
66
+ * outline Figma stores for the result; Taco has no live boolean, so the
67
+ * operands are not imported (the walk reports the flattening once). Without
68
+ * a `fillGeometry` outline the node is left out, as before.
69
+ */
70
+ export declare const convertBooleanOperation: FigmaNodeConverter;
71
+ /**
72
+ * `path` as a Taco line when the Figma node asks to fill its auto layout
73
+ * parent (`stackChildPrimaryGrow` above 0 or `stackChildAlignSelf` STRETCH)
74
+ * and the path is one straight level segment that is only moved (not turned,
75
+ * flipped, scaled or skewed) and fills no region; else `path` as it is. A
76
+ * path cannot fill its parent in Taco, while a line fills along its length:
77
+ * the renderer draws it from (0, 0) to (width, 0) of its box, so it follows
78
+ * the filled width with its stroke width kept. HeroUI's dividers are such
79
+ * VECTORs and LINEs. A line's stroke is drawn centred, as Figma draws the
80
+ * stroke of an open path.
81
+ */
82
+ export declare function lineWhereItFills(path: PathNode, change: FigmaObject): PathNode | LineNode;
83
+ /** Moondraft patch (../carry.ts): a STAR or REGULAR_POLYGON as its `fillGeometry` path (as a VECTOR), its parameters carried. */
84
+ export declare const convertStarOrPolygon: FigmaNodeConverter;