@moondraft/import 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (337) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/LICENSE +34 -0
  3. package/README.md +36 -2
  4. package/SOURCE.md +394 -0
  5. package/dist/adapter/convert.d.ts +144 -0
  6. package/dist/adapter/convert.js +2811 -0
  7. package/dist/adapter/figma-descriptions.d.ts +7 -0
  8. package/dist/adapter/figma-descriptions.js +34 -0
  9. package/dist/adapter/figma-grids.d.ts +12 -0
  10. package/dist/adapter/figma-grids.js +175 -0
  11. package/dist/adapter/figma-handoff.d.ts +12 -0
  12. package/dist/adapter/figma-handoff.js +167 -0
  13. package/dist/adapter/figma-hyperlinks.d.ts +13 -0
  14. package/dist/adapter/figma-hyperlinks.js +77 -0
  15. package/dist/adapter/figma.d.ts +12 -0
  16. package/dist/adapter/figma.js +40 -0
  17. package/dist/adapter/file-components.d.ts +20 -0
  18. package/dist/adapter/file-components.js +352 -0
  19. package/dist/adapter/file-resources.d.ts +29 -0
  20. package/dist/adapter/file-resources.js +851 -0
  21. package/dist/adapter/image-crop.d.ts +18 -0
  22. package/dist/adapter/image-crop.js +30 -0
  23. package/dist/adapter/index.d.ts +6 -0
  24. package/dist/adapter/index.js +9 -0
  25. package/dist/adapter/link.d.ts +49 -0
  26. package/dist/adapter/link.js +892 -0
  27. package/dist/adapter/payload.d.ts +31 -0
  28. package/dist/adapter/payload.js +78 -0
  29. package/dist/adapter/shapes.d.ts +31 -0
  30. package/dist/adapter/shapes.js +75 -0
  31. package/dist/adapter/variables.d.ts +45 -0
  32. package/dist/adapter/variables.js +106 -0
  33. package/dist/figma-file.d.ts +38 -0
  34. package/dist/figma-file.js +97 -0
  35. package/dist/figma-worker.d.ts +11 -0
  36. package/dist/figma-worker.js +12 -0
  37. package/dist/figma.d.ts +26 -0
  38. package/dist/figma.js +230 -0
  39. package/dist/index.d.ts +29 -0
  40. package/dist/index.js +50 -0
  41. package/dist/report.d.ts +42 -0
  42. package/dist/report.js +142 -0
  43. package/dist/serialize.d.ts +7 -0
  44. package/dist/serialize.js +79 -0
  45. package/dist/svg.d.ts +33 -0
  46. package/dist/svg.js +44 -0
  47. package/dist/syntax.d.ts +8 -0
  48. package/dist/syntax.js +19 -0
  49. package/dist/taco/figma-import/clipboard.d.ts +25 -0
  50. package/dist/taco/figma-import/clipboard.js +87 -0
  51. package/dist/taco/figma-import/clipboardSize.d.ts +31 -0
  52. package/dist/taco/figma-import/clipboardSize.js +107 -0
  53. package/dist/taco/figma-import/container/compression.d.ts +9 -0
  54. package/dist/taco/figma-import/container/compression.js +174 -0
  55. package/dist/taco/figma-import/container/error.d.ts +15 -0
  56. package/dist/taco/figma-import/container/error.js +19 -0
  57. package/dist/taco/figma-import/container/kiwiContainer.d.ts +41 -0
  58. package/dist/taco/figma-import/container/kiwiContainer.js +61 -0
  59. package/dist/taco/figma-import/container/limits.d.ts +22 -0
  60. package/dist/taco/figma-import/container/limits.js +22 -0
  61. package/dist/taco/figma-import/container/zip.d.ts +14 -0
  62. package/dist/taco/figma-import/container/zip.js +154 -0
  63. package/dist/taco/figma-import/figFile.d.ts +34 -0
  64. package/dist/taco/figma-import/figFile.js +91 -0
  65. package/dist/taco/figma-import/figFileDocument.d.ts +25 -0
  66. package/dist/taco/figma-import/figFileDocument.js +100 -0
  67. package/dist/taco/figma-import/import/blobs.d.ts +10 -0
  68. package/dist/taco/figma-import/import/blobs.js +23 -0
  69. package/dist/taco/figma-import/import/carry.d.ts +24 -0
  70. package/dist/taco/figma-import/import/carry.js +66 -0
  71. package/dist/taco/figma-import/import/componentProps.d.ts +90 -0
  72. package/dist/taco/figma-import/import/componentProps.js +329 -0
  73. package/dist/taco/figma-import/import/componentSets.d.ts +85 -0
  74. package/dist/taco/figma-import/import/componentSets.js +647 -0
  75. package/dist/taco/figma-import/import/converters/effects.d.ts +31 -0
  76. package/dist/taco/figma-import/import/converters/effects.js +127 -0
  77. package/dist/taco/figma-import/import/converters/ellipse.d.ts +7 -0
  78. package/dist/taco/figma-import/import/converters/ellipse.js +54 -0
  79. package/dist/taco/figma-import/import/converters/exportSettings.d.ts +4 -0
  80. package/dist/taco/figma-import/import/converters/exportSettings.js +49 -0
  81. package/dist/taco/figma-import/import/converters/frame.d.ts +21 -0
  82. package/dist/taco/figma-import/import/converters/frame.js +63 -0
  83. package/dist/taco/figma-import/import/converters/gradient.d.ts +74 -0
  84. package/dist/taco/figma-import/import/converters/gradient.js +108 -0
  85. package/dist/taco/figma-import/import/converters/group.d.ts +19 -0
  86. package/dist/taco/figma-import/import/converters/group.js +30 -0
  87. package/dist/taco/figma-import/import/converters/image.d.ts +13 -0
  88. package/dist/taco/figma-import/import/converters/image.js +94 -0
  89. package/dist/taco/figma-import/import/converters/layout.d.ts +33 -0
  90. package/dist/taco/figma-import/import/converters/layout.js +187 -0
  91. package/dist/taco/figma-import/import/converters/line.d.ts +11 -0
  92. package/dist/taco/figma-import/import/converters/line.js +40 -0
  93. package/dist/taco/figma-import/import/converters/rectangle.d.ts +3 -0
  94. package/dist/taco/figma-import/import/converters/rectangle.js +11 -0
  95. package/dist/taco/figma-import/import/converters/section.d.ts +8 -0
  96. package/dist/taco/figma-import/import/converters/section.js +29 -0
  97. package/dist/taco/figma-import/import/converters/shared.d.ts +71 -0
  98. package/dist/taco/figma-import/import/converters/shared.js +372 -0
  99. package/dist/taco/figma-import/import/converters/text.d.ts +54 -0
  100. package/dist/taco/figma-import/import/converters/text.js +707 -0
  101. package/dist/taco/figma-import/import/converters/vector.d.ts +105 -0
  102. package/dist/taco/figma-import/import/converters/vector.js +609 -0
  103. package/dist/taco/figma-import/import/converters/vectorNetwork.d.ts +114 -0
  104. package/dist/taco/figma-import/import/converters/vectorNetwork.js +503 -0
  105. package/dist/taco/figma-import/import/fields.d.ts +15 -0
  106. package/dist/taco/figma-import/import/fields.js +29 -0
  107. package/dist/taco/figma-import/import/instances.d.ts +184 -0
  108. package/dist/taco/figma-import/import/instances.js +1530 -0
  109. package/dist/taco/figma-import/import/nestingCycles.d.ts +86 -0
  110. package/dist/taco/figma-import/import/nestingCycles.js +488 -0
  111. package/dist/taco/figma-import/import/slots.d.ts +56 -0
  112. package/dist/taco/figma-import/import/slots.js +96 -0
  113. package/dist/taco/figma-import/import/styles.d.ts +48 -0
  114. package/dist/taco/figma-import/import/styles.js +48 -0
  115. package/dist/taco/figma-import/import/tree.d.ts +66 -0
  116. package/dist/taco/figma-import/import/tree.js +194 -0
  117. package/dist/taco/figma-import/import/types.d.ts +232 -0
  118. package/dist/taco/figma-import/import/types.js +33 -0
  119. package/dist/taco/figma-import/import/variables.d.ts +137 -0
  120. package/dist/taco/figma-import/import/variables.js +769 -0
  121. package/dist/taco/figma-import/import/variantTrees.d.ts +20 -0
  122. package/dist/taco/figma-import/import/variantTrees.js +520 -0
  123. package/dist/taco/figma-import/import/walk.d.ts +207 -0
  124. package/dist/taco/figma-import/import/walk.js +1464 -0
  125. package/dist/taco/figma-import/index.d.ts +22 -0
  126. package/dist/taco/figma-import/index.js +13 -0
  127. package/dist/taco/figma-import/kiwi/byteReader.d.ts +37 -0
  128. package/dist/taco/figma-import/kiwi/byteReader.js +151 -0
  129. package/dist/taco/figma-import/kiwi/error.d.ts +14 -0
  130. package/dist/taco/figma-import/kiwi/error.js +29 -0
  131. package/dist/taco/figma-import/kiwi/limits.d.ts +18 -0
  132. package/dist/taco/figma-import/kiwi/limits.js +18 -0
  133. package/dist/taco/figma-import/kiwi/message.d.ts +12 -0
  134. package/dist/taco/figma-import/kiwi/message.js +147 -0
  135. package/dist/taco/figma-import/kiwi/schema.d.ts +42 -0
  136. package/dist/taco/figma-import/kiwi/schema.js +206 -0
  137. package/dist/taco/figma-import/kiwi/types.d.ts +46 -0
  138. package/dist/taco/figma-import/kiwi/types.js +18 -0
  139. package/dist/taco/model/agent-hidden-fields.d.ts +20 -0
  140. package/dist/taco/model/agent-hidden-fields.js +29 -0
  141. package/dist/taco/model/asset-users.d.ts +23 -0
  142. package/dist/taco/model/asset-users.js +128 -0
  143. package/dist/taco/model/auto-layout-lines.d.ts +32 -0
  144. package/dist/taco/model/auto-layout-lines.js +70 -0
  145. package/dist/taco/model/codec.d.ts +444 -0
  146. package/dist/taco/model/codec.js +5665 -0
  147. package/dist/taco/model/color.d.ts +11 -0
  148. package/dist/taco/model/color.js +61 -0
  149. package/dist/taco/model/comment-operations.d.ts +102 -0
  150. package/dist/taco/model/comment-operations.js +227 -0
  151. package/dist/taco/model/component-evaluation.d.ts +96 -0
  152. package/dist/taco/model/component-evaluation.js +555 -0
  153. package/dist/taco/model/component-expressions.d.ts +242 -0
  154. package/dist/taco/model/component-expressions.js +1082 -0
  155. package/dist/taco/model/component-properties.d.ts +111 -0
  156. package/dist/taco/model/component-properties.js +339 -0
  157. package/dist/taco/model/component-samples.d.ts +83 -0
  158. package/dist/taco/model/component-samples.js +290 -0
  159. package/dist/taco/model/component-validity.d.ts +85 -0
  160. package/dist/taco/model/component-validity.js +397 -0
  161. package/dist/taco/model/components.d.ts +155 -0
  162. package/dist/taco/model/components.js +505 -0
  163. package/dist/taco/model/connector-ends.d.ts +20 -0
  164. package/dist/taco/model/connector-ends.js +188 -0
  165. package/dist/taco/model/connector-geometry.d.ts +74 -0
  166. package/dist/taco/model/connector-geometry.js +293 -0
  167. package/dist/taco/model/corner-radii.d.ts +26 -0
  168. package/dist/taco/model/corner-radii.js +47 -0
  169. package/dist/taco/model/derivations.d.ts +81 -0
  170. package/dist/taco/model/derivations.js +151 -0
  171. package/dist/taco/model/export-settings.d.ts +53 -0
  172. package/dist/taco/model/export-settings.js +156 -0
  173. package/dist/taco/model/expressions/ast.d.ts +153 -0
  174. package/dist/taco/model/expressions/ast.js +6 -0
  175. package/dist/taco/model/expressions/cache.d.ts +23 -0
  176. package/dist/taco/model/expressions/cache.js +43 -0
  177. package/dist/taco/model/expressions/check.d.ts +72 -0
  178. package/dist/taco/model/expressions/check.js +517 -0
  179. package/dist/taco/model/expressions/completion.d.ts +61 -0
  180. package/dist/taco/model/expressions/completion.js +421 -0
  181. package/dist/taco/model/expressions/evaluate.d.ts +32 -0
  182. package/dist/taco/model/expressions/evaluate.js +519 -0
  183. package/dist/taco/model/expressions/forms.d.ts +84 -0
  184. package/dist/taco/model/expressions/forms.js +200 -0
  185. package/dist/taco/model/expressions/index.d.ts +14 -0
  186. package/dist/taco/model/expressions/index.js +17 -0
  187. package/dist/taco/model/expressions/lexer.d.ts +42 -0
  188. package/dist/taco/model/expressions/lexer.js +213 -0
  189. package/dist/taco/model/expressions/library.d.ts +33 -0
  190. package/dist/taco/model/expressions/library.js +117 -0
  191. package/dist/taco/model/expressions/names.d.ts +43 -0
  192. package/dist/taco/model/expressions/names.js +99 -0
  193. package/dist/taco/model/expressions/parser.d.ts +15 -0
  194. package/dist/taco/model/expressions/parser.js +438 -0
  195. package/dist/taco/model/expressions/rename.d.ts +34 -0
  196. package/dist/taco/model/expressions/rename.js +46 -0
  197. package/dist/taco/model/expressions/source.d.ts +15 -0
  198. package/dist/taco/model/expressions/source.js +161 -0
  199. package/dist/taco/model/expressions/types.d.ts +119 -0
  200. package/dist/taco/model/expressions/types.js +102 -0
  201. package/dist/taco/model/expressions/values.d.ts +97 -0
  202. package/dist/taco/model/expressions/values.js +160 -0
  203. package/dist/taco/model/geometry-limits.d.ts +16 -0
  204. package/dist/taco/model/geometry-limits.js +67 -0
  205. package/dist/taco/model/geometry.d.ts +47 -0
  206. package/dist/taco/model/geometry.js +193 -0
  207. package/dist/taco/model/group-bounds.d.ts +38 -0
  208. package/dist/taco/model/group-bounds.js +144 -0
  209. package/dist/taco/model/id-table.d.ts +37 -0
  210. package/dist/taco/model/id-table.js +80 -0
  211. package/dist/taco/model/index.d.ts +25 -0
  212. package/dist/taco/model/index.js +27 -0
  213. package/dist/taco/model/instance-resolver.d.ts +376 -0
  214. package/dist/taco/model/instance-resolver.js +1778 -0
  215. package/dist/taco/model/layer-syntax.d.ts +340 -0
  216. package/dist/taco/model/layer-syntax.js +3506 -0
  217. package/dist/taco/model/layout/constraints.d.ts +84 -0
  218. package/dist/taco/model/layout/constraints.js +445 -0
  219. package/dist/taco/model/layout/frame-layout.d.ts +46 -0
  220. package/dist/taco/model/layout/frame-layout.js +618 -0
  221. package/dist/taco/model/layout/node-sizing.d.ts +163 -0
  222. package/dist/taco/model/layout/node-sizing.js +486 -0
  223. package/dist/taco/model/legacy-connector-caps.d.ts +15 -0
  224. package/dist/taco/model/legacy-connector-caps.js +70 -0
  225. package/dist/taco/model/linear-call.d.ts +48 -0
  226. package/dist/taco/model/linear-call.js +58 -0
  227. package/dist/taco/model/new-nodes.d.ts +145 -0
  228. package/dist/taco/model/new-nodes.js +277 -0
  229. package/dist/taco/model/node-builder.d.ts +449 -0
  230. package/dist/taco/model/node-builder.js +2294 -0
  231. package/dist/taco/model/node-table-watch.d.ts +36 -0
  232. package/dist/taco/model/node-table-watch.js +63 -0
  233. package/dist/taco/model/node-transform.d.ts +39 -0
  234. package/dist/taco/model/node-transform.js +79 -0
  235. package/dist/taco/model/node-users-index.d.ts +10 -0
  236. package/dist/taco/model/node-users-index.js +82 -0
  237. package/dist/taco/model/operation-references.d.ts +80 -0
  238. package/dist/taco/model/operation-references.js +399 -0
  239. package/dist/taco/model/operations.d.ts +610 -0
  240. package/dist/taco/model/operations.js +2882 -0
  241. package/dist/taco/model/overlay-table.d.ts +71 -0
  242. package/dist/taco/model/overlay-table.js +171 -0
  243. package/dist/taco/model/override-remap.d.ts +69 -0
  244. package/dist/taco/model/override-remap.js +230 -0
  245. package/dist/taco/model/parent-table.d.ts +53 -0
  246. package/dist/taco/model/parent-table.js +193 -0
  247. package/dist/taco/model/problem-collector.d.ts +27 -0
  248. package/dist/taco/model/problem-collector.js +101 -0
  249. package/dist/taco/model/sha256.d.ts +10 -0
  250. package/dist/taco/model/sha256.js +79 -0
  251. package/dist/taco/model/shape-geometry.d.ts +96 -0
  252. package/dist/taco/model/shape-geometry.js +368 -0
  253. package/dist/taco/model/shared-node-table.d.ts +97 -0
  254. package/dist/taco/model/shared-node-table.js +546 -0
  255. package/dist/taco/model/slots.d.ts +113 -0
  256. package/dist/taco/model/slots.js +281 -0
  257. package/dist/taco/model/stroke-settings.d.ts +37 -0
  258. package/dist/taco/model/stroke-settings.js +90 -0
  259. package/dist/taco/model/svg-path-import.d.ts +89 -0
  260. package/dist/taco/model/svg-path-import.js +219 -0
  261. package/dist/taco/model/text-measurement.d.ts +142 -0
  262. package/dist/taco/model/text-measurement.js +846 -0
  263. package/dist/taco/model/text-reads.d.ts +66 -0
  264. package/dist/taco/model/text-reads.js +128 -0
  265. package/dist/taco/model/text-sizer.d.ts +358 -0
  266. package/dist/taco/model/text-sizer.js +996 -0
  267. package/dist/taco/model/theme-users.d.ts +59 -0
  268. package/dist/taco/model/theme-users.js +312 -0
  269. package/dist/taco/model/thumbnail.d.ts +15 -0
  270. package/dist/taco/model/thumbnail.js +34 -0
  271. package/dist/taco/model/types.d.ts +2369 -0
  272. package/dist/taco/model/types.js +366 -0
  273. package/dist/taco/model/unknown-property.d.ts +5 -0
  274. package/dist/taco/model/unknown-property.js +7 -0
  275. package/dist/taco/model/validated-documents.d.ts +22 -0
  276. package/dist/taco/model/validated-documents.js +22 -0
  277. package/dist/taco/model/variable-modes.d.ts +61 -0
  278. package/dist/taco/model/variable-modes.js +438 -0
  279. package/dist/taco/model/variable-references.d.ts +54 -0
  280. package/dist/taco/model/variable-references.js +183 -0
  281. package/dist/taco/model/variables.d.ts +24 -0
  282. package/dist/taco/model/variables.js +151 -0
  283. package/dist/taco/model/vector-network.d.ts +34 -0
  284. package/dist/taco/model/vector-network.js +411 -0
  285. package/dist/taco/svg-import/import-svg.d.ts +36 -0
  286. package/dist/taco/svg-import/import-svg.js +729 -0
  287. package/dist/taco/svg-import/index.d.ts +3 -0
  288. package/dist/taco/svg-import/index.js +3 -0
  289. package/dist/taco/svg-import/limits/limits.d.ts +79 -0
  290. package/dist/taco/svg-import/limits/limits.js +160 -0
  291. package/dist/taco/svg-import/paint/gradients.d.ts +64 -0
  292. package/dist/taco/svg-import/paint/gradients.js +429 -0
  293. package/dist/taco/svg-import/paint/paint.d.ts +32 -0
  294. package/dist/taco/svg-import/paint/paint.js +162 -0
  295. package/dist/taco/svg-import/paths/paths.d.ts +58 -0
  296. package/dist/taco/svg-import/paths/paths.js +205 -0
  297. package/dist/taco/svg-import/public-types.d.ts +279 -0
  298. package/dist/taco/svg-import/public-types.js +56 -0
  299. package/dist/taco/svg-import/report/report.d.ts +44 -0
  300. package/dist/taco/svg-import/report/report.js +79 -0
  301. package/dist/taco/svg-import/reuse/reuse.d.ts +99 -0
  302. package/dist/taco/svg-import/reuse/reuse.js +840 -0
  303. package/dist/taco/svg-import/shapes/shapes.d.ts +35 -0
  304. package/dist/taco/svg-import/shapes/shapes.js +386 -0
  305. package/dist/taco/svg-import/structure/effects.d.ts +26 -0
  306. package/dist/taco/svg-import/structure/effects.js +618 -0
  307. package/dist/taco/svg-import/structure/image.d.ts +24 -0
  308. package/dist/taco/svg-import/structure/image.js +495 -0
  309. package/dist/taco/svg-import/structure/walk.d.ts +85 -0
  310. package/dist/taco/svg-import/structure/walk.js +544 -0
  311. package/dist/taco/svg-import/style/color.d.ts +40 -0
  312. package/dist/taco/svg-import/style/color.js +275 -0
  313. package/dist/taco/svg-import/style/computed.d.ts +214 -0
  314. package/dist/taco/svg-import/style/computed.js +1534 -0
  315. package/dist/taco/svg-import/style/css.d.ts +127 -0
  316. package/dist/taco/svg-import/style/css.js +541 -0
  317. package/dist/taco/svg-import/style/media.d.ts +25 -0
  318. package/dist/taco/svg-import/style/media.js +307 -0
  319. package/dist/taco/svg-import/style/properties.d.ts +43 -0
  320. package/dist/taco/svg-import/style/properties.js +135 -0
  321. package/dist/taco/svg-import/style/selector-reach.d.ts +30 -0
  322. package/dist/taco/svg-import/style/selector-reach.js +169 -0
  323. package/dist/taco/svg-import/style/selector-validity.d.ts +14 -0
  324. package/dist/taco/svg-import/style/selector-validity.js +307 -0
  325. package/dist/taco/svg-import/text/text.d.ts +29 -0
  326. package/dist/taco/svg-import/text/text.js +545 -0
  327. package/dist/taco/svg-import/transform/matrix.d.ts +111 -0
  328. package/dist/taco/svg-import/transform/matrix.js +229 -0
  329. package/dist/taco/svg-import/tree/element-data.d.ts +52 -0
  330. package/dist/taco/svg-import/tree/element-data.js +155 -0
  331. package/dist/taco/svg-import/tree/elements.d.ts +36 -0
  332. package/dist/taco/svg-import/tree/elements.js +121 -0
  333. package/dist/taco/svg-import/units/length.d.ts +43 -0
  334. package/dist/taco/svg-import/units/length.js +125 -0
  335. package/dist/taco/svg-import/units/viewbox.d.ts +35 -0
  336. package/dist/taco/svg-import/units/viewbox.js +77 -0
  337. package/package.json +55 -4
@@ -0,0 +1,114 @@
1
+ import { type VectorNetwork, type VectorRegion } from "../../../model/index.ts";
2
+ import type { StrokeCap } from "../../../model/types.ts";
3
+ import { type FigmaObject } from "../fields.ts";
4
+ import type { FigmaTreeNode } from "../tree.ts";
5
+ import type { NodeWalk } from "../walk.ts";
6
+ import type { Box } from "./gradient.ts";
7
+ /**
8
+ * A function giving the tight bounds of a region's outline in node pixels,
9
+ * which the renderer places the region's gradient fills on, or `undefined`
10
+ * when it has none. The network's vertices and segments are indexed once, so
11
+ * each region costs only its own loop entries, not the whole network.
12
+ */
13
+ export declare function regionBoxes(network: Pick<VectorNetwork, "vertices" | "segments">): (region: VectorRegion) => Box | undefined;
14
+ /**
15
+ * The most vertices, segments, regions, loops (over all regions) and loop
16
+ * entries (over all loops) one `vectorNetworkBlob` may hold. A blob over any
17
+ * of them is refused before anything is allocated for it.
18
+ */
19
+ export declare const VECTOR_NETWORK_LIMITS: {
20
+ readonly vertices: 100000;
21
+ readonly segments: 100000;
22
+ readonly regions: 10000;
23
+ readonly loops: 10000;
24
+ readonly loopEntries: 200000;
25
+ };
26
+ /**
27
+ * Why a VECTOR's editable vector network is not imported, named at the start
28
+ * of the report reason as `geometry refused (<name>)`:
29
+ * - `network-blob-missing`: the `vectorNetworkBlob` is not in the message's `blobs`.
30
+ * - `network-no-size`: the node has no `size` or its `vectorData` no `normalizedSize`, so the network's scale is unknown.
31
+ * - `network-too-short`: the blob ends inside its header, a vertex, a segment, a region or a loop.
32
+ * - `network-trailing-bytes`: bytes are left after the last region.
33
+ * - `network-too-many-vertices`, `-segments`, `-regions`, `-loops`, `-loop-entries`: over `VECTOR_NETWORK_LIMITS`.
34
+ * - `network-not-finite`: a coordinate or tangent is NaN or infinite.
35
+ * - `network-vertex-out-of-range`: a segment names a vertex the blob does not have.
36
+ * - `network-segment-out-of-range`: a loop names a segment the blob does not have.
37
+ * - `network-empty-region`, `network-empty-loop`: a region with no loops, a loop with no segments.
38
+ * - `network-loop-repeats-segment`: a loop names one segment twice.
39
+ * - `network-loop-broken`: consecutive segments of a loop share no vertex.
40
+ * - `network-no-segments`: the network draws nothing.
41
+ * - `import-command-limit`: the network's segments, each counted as one drawing
42
+ * command, are more than the import has left of `limits.vectorCommands`.
43
+ *
44
+ * The winding rule is one bit (see `decodeNetworkBlob`), so no value of it is unknown.
45
+ */
46
+ export declare const VECTOR_NETWORK_PROBLEMS: readonly ["network-blob-missing", "network-no-size", "network-too-short", "network-trailing-bytes", "network-too-many-vertices", "network-too-many-segments", "network-too-many-regions", "network-too-many-loops", "network-too-many-loop-entries", "network-not-finite", "network-vertex-out-of-range", "network-segment-out-of-range", "network-empty-region", "network-empty-loop", "network-loop-repeats-segment", "network-loop-broken", "network-no-segments", "import-command-limit"];
47
+ export type VectorNetworkProblem = (typeof VECTOR_NETWORK_PROBLEMS)[number];
48
+ export declare class NetworkRefused extends Error {
49
+ readonly problem: VectorNetworkProblem;
50
+ constructor(problem: VectorNetworkProblem, detail: string);
51
+ }
52
+ interface RawVertex {
53
+ readonly styleId: number;
54
+ readonly x: number;
55
+ readonly y: number;
56
+ }
57
+ interface RawSegment {
58
+ readonly styleId: number;
59
+ readonly start: number;
60
+ readonly startDx: number;
61
+ readonly startDy: number;
62
+ readonly end: number;
63
+ readonly endDx: number;
64
+ readonly endDy: number;
65
+ }
66
+ interface RawRegion {
67
+ readonly styleId: number;
68
+ readonly windingRule: VectorRegion["windingRule"];
69
+ readonly loops: readonly (readonly number[])[];
70
+ }
71
+ interface RawNetwork {
72
+ readonly vertices: RawVertex[];
73
+ readonly segments: RawSegment[];
74
+ readonly regions: RawRegion[];
75
+ }
76
+ /**
77
+ * Decodes a `vectorNetworkBlob`, as fig2sketch (src/figformat/vector_network.py:4-69)
78
+ * and grida (packages/grida-canvas-io-figma/fig-kiwi/blob-parser.ts:150-243)
79
+ * read it; every number is little-endian, u32 for counts, indices and style
80
+ * ids, f32 for coordinates:
81
+ * - header: vertex count, segment count, region count;
82
+ * - each vertex (12 bytes): style id, x, y;
83
+ * - each segment (28 bytes): style id, start vertex, start tangent dx, dy,
84
+ * end vertex, end tangent dx, dy (each tangent relative to its own vertex);
85
+ * - each region: one u32 holding the style id above bit 0 and the winding
86
+ * rule in bit 0 (1 NONZERO, 0 ODD), the loop count, then per loop a
87
+ * segment count and that many segment indices.
88
+ */
89
+ export declare function decodeNetworkBlob(bytes: Uint8Array, where: string): RawNetwork;
90
+ /** The node's `styleOverrideTable` entries by `styleID`. */
91
+ export declare function vectorStyleTable(vectorData: FigmaObject | undefined, where: string): Map<number, FigmaObject>;
92
+ interface RegionStyle {
93
+ readonly index: number;
94
+ readonly styleId: number;
95
+ readonly at: string;
96
+ }
97
+ /** Resolve and budget every region's source list before converting paints for any region. */
98
+ export declare function applyRegionStyles(node: FigmaTreeNode, walk: NodeWalk, network: Pick<VectorNetwork, "vertices" | "segments"> & {
99
+ regions: VectorRegion[];
100
+ }, styles: ReadonlyMap<number, FigmaObject>, styled: readonly RegionStyle[], outline?: boolean): void;
101
+ /**
102
+ * Builds a Taco network from the node's `vectorData`, scaled from
103
+ * `normalizedSize` to the node's `size` (grida,
104
+ * packages/grida-canvas-io-figma/lib.ts:5064-5120: x by size.x /
105
+ * normalizedSize.x, y likewise, an axis whose normalized size is 0 unscaled).
106
+ * Region styles become region fills; vertex styles also give corner radii.
107
+ * Cap overrides are collected for open endpoints. Other style fields are
108
+ * reported. Throws `NetworkRefused`.
109
+ */
110
+ export declare function vectorDataNetwork(node: FigmaTreeNode, vectorData: FigmaObject, reference: number, walk: NodeWalk): {
111
+ network: VectorNetwork;
112
+ endpointCaps: Record<string, StrokeCap>;
113
+ };
114
+ export {};
@@ -0,0 +1,503 @@
1
+ import { getPathBounds, vectorHandleId, vectorRegionId, vectorSegmentId, vectorRegionToSvgPathData, vectorVertexId, } from "../../../model/index.js";
2
+ import { field, isObject } from "../fields.js";
3
+ import { styleBackedList } from "../styles.js";
4
+ import { endCapOf, nodePaints } from "./shared.js";
5
+ /**
6
+ * A function giving the tight bounds of a region's outline in node pixels,
7
+ * which the renderer places the region's gradient fills on, or `undefined`
8
+ * when it has none. The network's vertices and segments are indexed once, so
9
+ * each region costs only its own loop entries, not the whole network.
10
+ */
11
+ export function regionBoxes(network) {
12
+ const vertexById = new Map(network.vertices.map((vertex) => [vertex.id, vertex]));
13
+ const segmentById = new Map(network.segments.map((segment) => [segment.id, segment]));
14
+ return (region) => {
15
+ const vertices = new Map();
16
+ const segments = new Map();
17
+ for (const loop of region.loops) {
18
+ for (const reference of loop.segments) {
19
+ const segment = segmentById.get(reference.segmentId);
20
+ if (segment === undefined)
21
+ continue;
22
+ segments.set(segment.id, segment);
23
+ for (const id of [segment.start, segment.end]) {
24
+ const vertex = vertexById.get(id);
25
+ if (vertex !== undefined)
26
+ vertices.set(id, vertex);
27
+ }
28
+ }
29
+ }
30
+ const own = { vertices: [...vertices.values()], segments: [...segments.values()], regions: [] };
31
+ return getPathBounds(vectorRegionToSvgPathData(own, region)) ?? undefined;
32
+ };
33
+ }
34
+ /**
35
+ * The most vertices, segments, regions, loops (over all regions) and loop
36
+ * entries (over all loops) one `vectorNetworkBlob` may hold. A blob over any
37
+ * of them is refused before anything is allocated for it.
38
+ */
39
+ export const VECTOR_NETWORK_LIMITS = {
40
+ vertices: 100_000, segments: 100_000, regions: 10_000, loops: 10_000, loopEntries: 200_000,
41
+ };
42
+ /**
43
+ * Why a VECTOR's editable vector network is not imported, named at the start
44
+ * of the report reason as `geometry refused (<name>)`:
45
+ * - `network-blob-missing`: the `vectorNetworkBlob` is not in the message's `blobs`.
46
+ * - `network-no-size`: the node has no `size` or its `vectorData` no `normalizedSize`, so the network's scale is unknown.
47
+ * - `network-too-short`: the blob ends inside its header, a vertex, a segment, a region or a loop.
48
+ * - `network-trailing-bytes`: bytes are left after the last region.
49
+ * - `network-too-many-vertices`, `-segments`, `-regions`, `-loops`, `-loop-entries`: over `VECTOR_NETWORK_LIMITS`.
50
+ * - `network-not-finite`: a coordinate or tangent is NaN or infinite.
51
+ * - `network-vertex-out-of-range`: a segment names a vertex the blob does not have.
52
+ * - `network-segment-out-of-range`: a loop names a segment the blob does not have.
53
+ * - `network-empty-region`, `network-empty-loop`: a region with no loops, a loop with no segments.
54
+ * - `network-loop-repeats-segment`: a loop names one segment twice.
55
+ * - `network-loop-broken`: consecutive segments of a loop share no vertex.
56
+ * - `network-no-segments`: the network draws nothing.
57
+ * - `import-command-limit`: the network's segments, each counted as one drawing
58
+ * command, are more than the import has left of `limits.vectorCommands`.
59
+ *
60
+ * The winding rule is one bit (see `decodeNetworkBlob`), so no value of it is unknown.
61
+ */
62
+ export const VECTOR_NETWORK_PROBLEMS = [
63
+ "network-blob-missing",
64
+ "network-no-size",
65
+ "network-too-short",
66
+ "network-trailing-bytes",
67
+ "network-too-many-vertices",
68
+ "network-too-many-segments",
69
+ "network-too-many-regions",
70
+ "network-too-many-loops",
71
+ "network-too-many-loop-entries",
72
+ "network-not-finite",
73
+ "network-vertex-out-of-range",
74
+ "network-segment-out-of-range",
75
+ "network-empty-region",
76
+ "network-empty-loop",
77
+ "network-loop-repeats-segment",
78
+ "network-loop-broken",
79
+ "network-no-segments",
80
+ "import-command-limit",
81
+ ];
82
+ export class NetworkRefused extends Error {
83
+ problem;
84
+ constructor(problem, detail) {
85
+ super(`geometry refused (${problem}): ${detail}`);
86
+ this.problem = problem;
87
+ }
88
+ }
89
+ const VERTEX_BYTES = 12;
90
+ const SEGMENT_BYTES = 28;
91
+ /**
92
+ * Decodes a `vectorNetworkBlob`, as fig2sketch (src/figformat/vector_network.py:4-69)
93
+ * and grida (packages/grida-canvas-io-figma/fig-kiwi/blob-parser.ts:150-243)
94
+ * read it; every number is little-endian, u32 for counts, indices and style
95
+ * ids, f32 for coordinates:
96
+ * - header: vertex count, segment count, region count;
97
+ * - each vertex (12 bytes): style id, x, y;
98
+ * - each segment (28 bytes): style id, start vertex, start tangent dx, dy,
99
+ * end vertex, end tangent dx, dy (each tangent relative to its own vertex);
100
+ * - each region: one u32 holding the style id above bit 0 and the winding
101
+ * rule in bit 0 (1 NONZERO, 0 ODD), the loop count, then per loop a
102
+ * segment count and that many segment indices.
103
+ */
104
+ export function decodeNetworkBlob(bytes, where) {
105
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
106
+ let offset = 0;
107
+ const need = (count, what) => {
108
+ if (count > bytes.length - offset) {
109
+ throw new NetworkRefused("network-too-short", `${where} ends at byte ${String(bytes.length)}, inside ${what} at byte ${String(offset)}`);
110
+ }
111
+ };
112
+ const u32 = () => { const value = view.getUint32(offset, true); offset += 4; return value; };
113
+ const f32 = (what) => {
114
+ const value = view.getFloat32(offset, true);
115
+ if (!Number.isFinite(value))
116
+ throw new NetworkRefused("network-not-finite", `${where} has ${what} that is ${String(value)} at byte ${String(offset)}`);
117
+ offset += 4;
118
+ return value;
119
+ };
120
+ const bounded = (count, limit, problem, what) => {
121
+ if (count > limit)
122
+ throw new NetworkRefused(problem, `${where} has ${String(count)} ${what}, over the limit of ${String(limit)}`);
123
+ };
124
+ need(12, "the header");
125
+ const vertexCount = u32();
126
+ const segmentCount = u32();
127
+ const regionCount = u32();
128
+ bounded(vertexCount, VECTOR_NETWORK_LIMITS.vertices, "network-too-many-vertices", "vertices");
129
+ bounded(segmentCount, VECTOR_NETWORK_LIMITS.segments, "network-too-many-segments", "segments");
130
+ bounded(regionCount, VECTOR_NETWORK_LIMITS.regions, "network-too-many-regions", "regions");
131
+ // Each region takes at least 8 bytes, so all three counts are checked before any list is built.
132
+ need(vertexCount * VERTEX_BYTES + segmentCount * SEGMENT_BYTES + regionCount * 8, `the ${String(vertexCount)} vertices, ${String(segmentCount)} segments and ${String(regionCount)} regions it counts`);
133
+ const vertices = [];
134
+ for (let i = 0; i < vertexCount; i++) {
135
+ const styleId = u32();
136
+ vertices.push({ styleId, x: f32(`vertex ${String(i)} x`), y: f32(`vertex ${String(i)} y`) });
137
+ }
138
+ const segments = [];
139
+ for (let i = 0; i < segmentCount; i++) {
140
+ const at = `segment ${String(i)}`;
141
+ const styleId = u32();
142
+ const start = u32();
143
+ const startDx = f32(`${at} start tangent dx`);
144
+ const startDy = f32(`${at} start tangent dy`);
145
+ const end = u32();
146
+ const endDx = f32(`${at} end tangent dx`);
147
+ const endDy = f32(`${at} end tangent dy`);
148
+ for (const vertex of [start, end]) {
149
+ if (vertex >= vertexCount) {
150
+ throw new NetworkRefused("network-vertex-out-of-range", `${where} ${at} names vertex ${String(vertex)}, but the blob has ${String(vertexCount)} vertices`);
151
+ }
152
+ }
153
+ segments.push({ styleId, start, startDx, startDy, end, endDx, endDy });
154
+ }
155
+ const regions = [];
156
+ let loopTotal = 0;
157
+ let entryTotal = 0;
158
+ for (let i = 0; i < regionCount; i++) {
159
+ const at = `region ${String(i)}`;
160
+ need(8, `${at}`);
161
+ const styleAndRule = u32();
162
+ const loopCount = u32();
163
+ if (loopCount === 0)
164
+ throw new NetworkRefused("network-empty-region", `${where} ${at} has no loops`);
165
+ loopTotal += loopCount;
166
+ bounded(loopTotal, VECTOR_NETWORK_LIMITS.loops, "network-too-many-loops", "loops");
167
+ need(loopCount * 4, `the ${String(loopCount)} loops of ${at}`);
168
+ const loops = [];
169
+ for (let j = 0; j < loopCount; j++) {
170
+ const loopAt = `${at} loop ${String(j)}`;
171
+ need(4, loopAt);
172
+ const entryCount = u32();
173
+ if (entryCount === 0)
174
+ throw new NetworkRefused("network-empty-loop", `${where} ${loopAt} has no segments`);
175
+ entryTotal += entryCount;
176
+ bounded(entryTotal, VECTOR_NETWORK_LIMITS.loopEntries, "network-too-many-loop-entries", "loop entries");
177
+ need(entryCount * 4, `the ${String(entryCount)} segment indices of ${loopAt}`);
178
+ const loop = [];
179
+ for (let k = 0; k < entryCount; k++) {
180
+ const segment = u32();
181
+ if (segment >= segmentCount) {
182
+ throw new NetworkRefused("network-segment-out-of-range", `${where} ${loopAt} names segment ${String(segment)}, but the blob has ${String(segmentCount)} segments`);
183
+ }
184
+ loop.push(segment);
185
+ }
186
+ loops.push(loop);
187
+ }
188
+ regions.push({ styleId: styleAndRule >>> 1, windingRule: (styleAndRule & 1) === 1 ? "nonzero" : "evenodd", loops });
189
+ }
190
+ if (offset !== bytes.length) {
191
+ throw new NetworkRefused("network-trailing-bytes", `${where} has ${String(bytes.length - offset)} bytes after its last region, from byte ${String(offset)}`);
192
+ }
193
+ return { vertices, segments, regions };
194
+ }
195
+ /**
196
+ * A loop's segment indices as Taco references with directions. Figma lists
197
+ * a loop's segments in order but not their direction (fig2sketch,
198
+ * src/converter/shape_path.py:308-331), so the first segment runs towards the
199
+ * vertex it shares with the second and each next one starts where the last
200
+ * ended. A loop that does not end where it started closes for filling only.
201
+ */
202
+ function orderLoop(network, indices, where) {
203
+ if (new Set(indices).size !== indices.length) {
204
+ throw new NetworkRefused("network-loop-repeats-segment", `${where} names a segment more than once`);
205
+ }
206
+ const segments = indices.map((index) => network.segments[index]);
207
+ const first = segments[0];
208
+ const second = segments[1];
209
+ const firstForward = second === undefined || first.end === second.start || first.end === second.end;
210
+ if (!firstForward && first.start !== second.start && first.start !== second.end) {
211
+ throw new NetworkRefused("network-loop-broken", `${where}: segments ${String(indices[0])} and ${String(indices[1])} share no vertex`);
212
+ }
213
+ const references = [];
214
+ const startVertex = firstForward ? first.start : first.end;
215
+ let current = startVertex;
216
+ segments.forEach((segment, i) => {
217
+ let direction;
218
+ if (i === 0)
219
+ direction = firstForward ? "forward" : "reverse";
220
+ else if (segment.start === current)
221
+ direction = "forward";
222
+ else if (segment.end === current)
223
+ direction = "reverse";
224
+ else
225
+ throw new NetworkRefused("network-loop-broken", `${where}: segment ${String(indices[i])} does not start at vertex ${String(current)}, where segment ${String(indices[i - 1])} ends`);
226
+ current = direction === "forward" ? segment.end : segment.start;
227
+ references.push({ segmentId: vectorSegmentId(`s${String(indices[i])}`), direction });
228
+ });
229
+ return startVertex === current ? { segments: references } : { segments: references, implicitClose: true };
230
+ }
231
+ /**
232
+ * The segments outside every region, as one loop when they form exactly one
233
+ * closed chain (each vertex they touch joins two of them, and all are
234
+ * connected), else `undefined`. Figma fills such a chain with the node's
235
+ * fills, as fig2sketch reads it (src/converter/shape_path.py:177-223).
236
+ */
237
+ function closedChainOutsideRegions(network, used) {
238
+ const free = network.segments.map((_, index) => index).filter((index) => !used.has(index));
239
+ if (free.length === 0)
240
+ return undefined;
241
+ const first = network.segments[free[0]];
242
+ if (free.length === 1)
243
+ return first.start === first.end ? orderLoop(network, free, "the segment outside every region") : undefined;
244
+ const touching = new Map();
245
+ for (const index of free) {
246
+ const { start, end } = network.segments[index];
247
+ if (start === end)
248
+ return undefined;
249
+ for (const vertex of [start, end]) {
250
+ const list = touching.get(vertex);
251
+ if (list)
252
+ list.push(index);
253
+ else
254
+ touching.set(vertex, [index]);
255
+ }
256
+ }
257
+ for (const list of touching.values())
258
+ if (list.length !== 2)
259
+ return undefined;
260
+ // Walk from the first free segment, always taking the other segment at the vertex just reached.
261
+ const order = [free[0]];
262
+ const seen = new Set(order);
263
+ let vertex = first.end;
264
+ while (order.length < free.length) {
265
+ const next = touching.get(vertex).find((index) => !seen.has(index));
266
+ if (next === undefined)
267
+ return undefined; // back at the start with segments left: more than one chain
268
+ order.push(next);
269
+ seen.add(next);
270
+ const segment = network.segments[next];
271
+ vertex = segment.start === vertex ? segment.end : segment.start;
272
+ }
273
+ return orderLoop(network, order, "the segments outside every region");
274
+ }
275
+ /**
276
+ * Each maximal chain contributes one loop to the node's fill. Join only
277
+ * through two-way vertices, where there is a unique continuation. Extend
278
+ * both ends of the first unused segment so even unordered segments form
279
+ * one chain and its first stored segment keeps its direction.
280
+ */
281
+ function implicitFillLoops(network) {
282
+ const touching = new Map();
283
+ for (const [index, { start, end }] of network.segments.entries()) {
284
+ for (const vertex of [start, end]) {
285
+ const incident = touching.get(vertex);
286
+ if (incident)
287
+ incident.push(index);
288
+ else
289
+ touching.set(vertex, [index]);
290
+ }
291
+ }
292
+ const used = new Uint8Array(network.segments.length);
293
+ const extend = (vertex, references, backward) => {
294
+ while (true) {
295
+ const incident = touching.get(vertex);
296
+ if (incident.length !== 2)
297
+ return vertex;
298
+ const index = incident.find((index) => used[index] === 0);
299
+ if (index === undefined)
300
+ return vertex;
301
+ used[index] = 1;
302
+ const segment = network.segments[index];
303
+ const forward = segment.start === vertex;
304
+ references.push({ segmentId: vectorSegmentId(`s${String(index)}`), direction: forward !== backward ? "forward" : "reverse" });
305
+ vertex = forward ? segment.end : segment.start;
306
+ }
307
+ };
308
+ const loops = [];
309
+ for (const [index, segment] of network.segments.entries()) {
310
+ if (used[index])
311
+ continue;
312
+ used[index] = 1;
313
+ const before = [];
314
+ const after = [{ segmentId: vectorSegmentId(`s${String(index)}`), direction: "forward" }];
315
+ const end = extend(segment.end, after, false);
316
+ const start = extend(segment.start, before, true);
317
+ const segments = before.reverse().concat(after);
318
+ loops.push(start === end ? { segments } : { segments, implicitClose: true });
319
+ }
320
+ return loops;
321
+ }
322
+ /** The node's `styleOverrideTable` entries by `styleID`. */
323
+ export function vectorStyleTable(vectorData, where) {
324
+ const table = new Map();
325
+ if (vectorData === undefined)
326
+ return table;
327
+ (field(vectorData, "styleOverrideTable", "list", `${where} vectorData`) ?? []).forEach((entry, index) => {
328
+ const id = isObject(entry) ? field(entry, "styleID", "number", `${where} vectorData styleOverrideTable[${String(index)}]`) : undefined;
329
+ if (isObject(entry) && id !== undefined)
330
+ table.set(id, entry);
331
+ });
332
+ return table;
333
+ }
334
+ /** Style fields that only steer editing (how handles move together), not the drawing. */
335
+ const EDITING_ONLY_STYLE_FIELDS = new Set(["styleID", "handleMirroring"]);
336
+ /** Style field values that draw nothing different: no corner rounding. */
337
+ const NEUTRAL_STYLE_VALUES = { cornerRadius: 0, cornerSmoothing: 0 };
338
+ /** A field with the layer's own value, or one that draws nothing different, loses nothing. */
339
+ function reportUnusedStyle(node, walk, style, used, at) {
340
+ const left = Object.keys(style).filter((key) => !EDITING_ONLY_STYLE_FIELDS.has(key) && !used.includes(key)
341
+ && style[key] !== node.change[key] && style[key] !== NEUTRAL_STYLE_VALUES[key]);
342
+ if (left.length > 0)
343
+ walk.report("property-left-out", `${at} style ${String(style["styleID"])}: ${left.join(", ")} not imported yet`);
344
+ }
345
+ /** Resolve and budget every region's source list before converting paints for any region. */
346
+ export function applyRegionStyles(node, walk, network, styles, styled, outline = false) {
347
+ if (styled.length === 0)
348
+ return;
349
+ // Keep in sync with the renderer's wire::path budget. Count raw paints and an upper bound on converted stops:
350
+ // clipping can only replace out-of-range stops, except when one stop becomes two.
351
+ let paintsLeft = 100_000, stopsLeft = 1_000_000;
352
+ const stopCounts = new Map();
353
+ const lists = [];
354
+ const represented = outline ? ["fillPaints", "styleIdForFill", "cornerRadius", "cornerSmoothing"] : ["fillPaints", "styleIdForFill"];
355
+ for (const { index, styleId, at } of styled) {
356
+ const style = styles.get(styleId);
357
+ if (style === undefined) {
358
+ walk.report("approximated", `${at} has style ${String(styleId)}, which is not in the styleOverrideTable; the node's style is used`);
359
+ continue;
360
+ }
361
+ const id = `${node.id} ${at} style ${String(styleId)}`;
362
+ const source = styleBackedList(style, "fillPaints", walk.styleList, `node ${id}`, walk.report);
363
+ reportUnusedStyle(node, walk, style, represented, at);
364
+ if (source === undefined)
365
+ continue;
366
+ paintsLeft -= source.length;
367
+ if (paintsLeft < 0) {
368
+ walk.report("approximated", "region fills exceed the renderer's aggregate paints limit; the node's fills are used");
369
+ return;
370
+ }
371
+ let stops = stopCounts.get(source);
372
+ if (stops === undefined) {
373
+ stops = 0;
374
+ for (const paint of source) {
375
+ if (isObject(paint) && typeof paint["type"] === "string" && paint["type"].startsWith("GRADIENT_") && Array.isArray(paint["stops"])) {
376
+ stops += Math.max(2, paint["stops"].length);
377
+ }
378
+ }
379
+ stopCounts.set(source, stops);
380
+ }
381
+ stopsLeft -= stops;
382
+ if (stopsLeft < 0) {
383
+ walk.report("approximated", "region fills exceed the renderer's aggregate gradient stops limit; the node's fills are used");
384
+ return;
385
+ }
386
+ lists.push({ index, id, source });
387
+ }
388
+ if (lists.length === 0)
389
+ return;
390
+ const boxOf = regionBoxes(network);
391
+ for (const { index, id, source } of lists) {
392
+ const region = network.regions[index];
393
+ const fills = nodePaints({ id, change: { size: node.change["size"] } }, walk, "fillPaints", boxOf(region), source);
394
+ network.regions[index] = { ...region, fills };
395
+ }
396
+ }
397
+ /**
398
+ * Builds a Taco network from the node's `vectorData`, scaled from
399
+ * `normalizedSize` to the node's `size` (grida,
400
+ * packages/grida-canvas-io-figma/lib.ts:5064-5120: x by size.x /
401
+ * normalizedSize.x, y likewise, an axis whose normalized size is 0 unscaled).
402
+ * Region styles become region fills; vertex styles also give corner radii.
403
+ * Cap overrides are collected for open endpoints. Other style fields are
404
+ * reported. Throws `NetworkRefused`.
405
+ */
406
+ export function vectorDataNetwork(node, vectorData, reference, walk) {
407
+ const where = `node ${node.id}`;
408
+ const bytes = walk.blob(reference);
409
+ if (bytes === undefined)
410
+ throw new NetworkRefused("network-blob-missing", `vectorData refers to vector network blob ${String(reference)}, which the message does not have`);
411
+ const size = field(node.change, "size", "object", where);
412
+ const normalized = field(vectorData, "normalizedSize", "object", `${where} vectorData`);
413
+ const sizeX = size && field(size, "x", "number", `${where} size`);
414
+ const sizeY = size && field(size, "y", "number", `${where} size`);
415
+ const normalX = normalized && field(normalized, "x", "number", `${where} vectorData normalizedSize`);
416
+ const normalY = normalized && field(normalized, "y", "number", `${where} vectorData normalizedSize`);
417
+ if (sizeX === undefined || sizeY === undefined || normalX === undefined || normalY === undefined) {
418
+ throw new NetworkRefused("network-no-size", "the node needs a size and its vectorData a normalizedSize to place the network");
419
+ }
420
+ const sx = normalX === 0 ? 1 : sizeX / normalX;
421
+ const sy = normalY === 0 ? 1 : sizeY / normalY;
422
+ const raw = decodeNetworkBlob(bytes, `vector network blob ${String(reference)}`);
423
+ if (raw.segments.length === 0)
424
+ throw new NetworkRefused("network-no-segments", "the vector network has no segments");
425
+ // Each segment is one drawing command of the import-wide `limits.vectorCommands`, as each fillGeometry command is.
426
+ const shared = walk.vectorCommands;
427
+ if (!(shared.left >= raw.segments.length)) {
428
+ throw new NetworkRefused("import-command-limit", `the import has read ${String(shared.limit)} vector commands, its limit (limits.vectorCommands)`);
429
+ }
430
+ shared.left -= raw.segments.length;
431
+ const styles = vectorStyleTable(vectorData, where);
432
+ const degree = new Uint32Array(raw.vertices.length);
433
+ for (const { start, end } of raw.segments) {
434
+ degree[start]++;
435
+ degree[end]++;
436
+ }
437
+ const endpointCaps = {};
438
+ const styleOf = (id, what) => {
439
+ if (id === 0)
440
+ return undefined;
441
+ const style = styles.get(id);
442
+ if (style === undefined)
443
+ walk.report("approximated", `${what} has style ${String(id)}, which is not in the styleOverrideTable; the node's style is used`);
444
+ return style;
445
+ };
446
+ const vertices = raw.vertices.map((vertex, index) => {
447
+ const style = styleOf(vertex.styleId, `vertex ${String(index)}`);
448
+ const radius = style && field(style, "cornerRadius", "number", `${where} vertex ${String(index)} style`);
449
+ const id = vectorVertexId(`v${String(index)}`);
450
+ const cap = degree[index] === 1 ? endCapOf(style?.["strokeCap"]) : undefined;
451
+ if (cap !== undefined)
452
+ endpointCaps[id] = cap;
453
+ if (style)
454
+ reportUnusedStyle(node, walk, style, cap === undefined ? ["cornerRadius"] : ["cornerRadius", "strokeCap"], `vertex ${String(index)}`);
455
+ return { id, x: vertex.x * sx, y: vertex.y * sy, ...(radius !== undefined && radius > 0 ? { cornerRadius: radius } : {}) };
456
+ });
457
+ const segments = raw.segments.map((segment, index) => {
458
+ const style = styleOf(segment.styleId, `segment ${String(index)}`);
459
+ const id = vectorSegmentId(`s${String(index)}`);
460
+ const start = vectorVertexId(`v${String(segment.start)}`);
461
+ const end = vectorVertexId(`v${String(segment.end)}`);
462
+ const cap = degree[segment.start] === 1 || degree[segment.end] === 1 ? endCapOf(style?.["strokeCap"]) : undefined;
463
+ if (cap !== undefined) {
464
+ // A vertex's own cap takes precedence over its incident segment's style.
465
+ if (degree[segment.start] === 1)
466
+ endpointCaps[start] ??= cap;
467
+ if (degree[segment.end] === 1)
468
+ endpointCaps[end] ??= cap;
469
+ }
470
+ if (style)
471
+ reportUnusedStyle(node, walk, style, cap === undefined ? [] : ["strokeCap"], `segment ${String(index)}`);
472
+ if (segment.startDx === 0 && segment.startDy === 0 && segment.endDx === 0 && segment.endDy === 0)
473
+ return { id, kind: "line", start, end };
474
+ return {
475
+ id, kind: "cubic", start, end,
476
+ startHandle: { id: vectorHandleId(`h${String(index)}-start`), dx: segment.startDx * sx, dy: segment.startDy * sy },
477
+ endHandle: { id: vectorHandleId(`h${String(index)}-end`), dx: segment.endDx * sx, dy: segment.endDy * sy },
478
+ };
479
+ });
480
+ const used = new Set();
481
+ const styled = [];
482
+ const regions = raw.regions.map((region, index) => {
483
+ const at = `region ${String(index)}`;
484
+ const loops = region.loops.map((loop, loopIndex) => {
485
+ loop.forEach((segment) => used.add(segment));
486
+ return orderLoop(raw, loop, `vector network ${at} loop ${String(loopIndex)}`);
487
+ });
488
+ if (region.styleId !== 0)
489
+ styled.push({ index, styleId: region.styleId, at });
490
+ return { id: vectorRegionId(`r${String(index)}`), windingRule: region.windingRule, loops };
491
+ });
492
+ applyRegionStyles(node, walk, { vertices, segments, regions }, styles, styled);
493
+ const outside = closedChainOutsideRegions(raw, used);
494
+ if (outside) {
495
+ regions.push({ id: vectorRegionId(`r${String(regions.length)}`), windingRule: "nonzero", loops: [outside] });
496
+ }
497
+ else if (regions.length === 0 && (styleBackedList(node.change, "fillPaints", walk.styleList, where)?.length ?? 0) > 0
498
+ // A lone straight line encloses no area. Keep it eligible for the stack's line conversion.
499
+ && (segments.length > 1 || segments[0].kind === "cubic")) {
500
+ regions.push({ id: vectorRegionId("r0"), windingRule: "nonzero", loops: implicitFillLoops(raw) });
501
+ }
502
+ return { network: { vertices, segments, regions }, endpointCaps };
503
+ }
@@ -0,0 +1,15 @@
1
+ /** A decoded Kiwi message or struct, read field by field: unknown fields are ignored. */
2
+ export type FigmaObject = Readonly<Record<string, unknown>>;
3
+ export declare function isObject(value: unknown): value is FigmaObject;
4
+ interface FieldKinds {
5
+ number: number;
6
+ string: string;
7
+ boolean: boolean;
8
+ object: FigmaObject;
9
+ list: readonly unknown[];
10
+ }
11
+ /** Reads a field: `undefined` when absent; a field of the wrong kind refuses the message. */
12
+ export declare function field<K extends keyof FieldKinds>(object: FigmaObject, name: string, kind: K, where: string): FieldKinds[K] | undefined;
13
+ /** Reads a `GUID {sessionID, localID}` as the id text `sessionID:localID`. */
14
+ export declare function guidText(value: unknown, where: string): string;
15
+ export {};
@@ -0,0 +1,29 @@
1
+ import { FigmaImportError } from "./types.js";
2
+ export function isObject(value) {
3
+ return typeof value === "object" && value !== null && !Array.isArray(value) && !(value instanceof Uint8Array);
4
+ }
5
+ const FIELD_CHECKS = {
6
+ number: (value) => typeof value === "number" && Number.isFinite(value),
7
+ string: (value) => typeof value === "string",
8
+ boolean: (value) => typeof value === "boolean",
9
+ object: isObject,
10
+ list: Array.isArray,
11
+ };
12
+ /** Reads a field: `undefined` when absent; a field of the wrong kind refuses the message. */
13
+ export function field(object, name, kind, where) {
14
+ const value = object[name];
15
+ if (value === undefined)
16
+ return undefined;
17
+ if (!FIELD_CHECKS[kind](value))
18
+ throw new FigmaImportError("not-node-changes", `${where}: field "${name}" is not a ${kind === "number" ? "finite number" : kind}`);
19
+ return value;
20
+ }
21
+ /** Reads a `GUID {sessionID, localID}` as the id text `sessionID:localID`. */
22
+ export function guidText(value, where) {
23
+ const session = isObject(value) ? value["sessionID"] : undefined;
24
+ const local = isObject(value) ? value["localID"] : undefined;
25
+ if (!Number.isInteger(session) || !Number.isInteger(local)) {
26
+ throw new FigmaImportError("not-node-changes", `${where}: guid is not a GUID with integer sessionID and localID`);
27
+ }
28
+ return `${String(session)}:${String(local)}`;
29
+ }