@pairdraw/core 0.20.0 → 0.21.1

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 (539) hide show
  1. package/dist/canvas/noise/render.js +1 -1
  2. package/dist/canvas/noise/render.js.map +1 -1
  3. package/dist/canvas/noise/shader.d.ts +6 -3
  4. package/dist/canvas/noise/shader.d.ts.map +1 -1
  5. package/dist/canvas/noise/shader.js +12 -7
  6. package/dist/canvas/noise/shader.js.map +1 -1
  7. package/dist/canvas/noise/tile.d.ts.map +1 -1
  8. package/dist/canvas/noise/tile.js +2 -1
  9. package/dist/canvas/noise/tile.js.map +1 -1
  10. package/dist/canvas/renderer/colors.d.ts +20 -5
  11. package/dist/canvas/renderer/colors.d.ts.map +1 -1
  12. package/dist/canvas/renderer/colors.js +48 -42
  13. package/dist/canvas/renderer/colors.js.map +1 -1
  14. package/dist/canvas/renderer/document-surface.d.ts +25 -0
  15. package/dist/canvas/renderer/document-surface.d.ts.map +1 -0
  16. package/dist/canvas/renderer/document-surface.js +46 -0
  17. package/dist/canvas/renderer/document-surface.js.map +1 -0
  18. package/dist/canvas/renderer/fonts.d.ts.map +1 -1
  19. package/dist/canvas/renderer/fonts.js +6 -4
  20. package/dist/canvas/renderer/fonts.js.map +1 -1
  21. package/dist/canvas/renderer/lifecycle.js +4 -3
  22. package/dist/canvas/renderer/lifecycle.js.map +1 -1
  23. package/dist/canvas/renderer/methods.d.ts.map +1 -1
  24. package/dist/canvas/renderer/methods.js +1 -0
  25. package/dist/canvas/renderer/methods.js.map +1 -1
  26. package/dist/canvas/renderer/pipeline.d.ts.map +1 -1
  27. package/dist/canvas/renderer/pipeline.js +23 -2
  28. package/dist/canvas/renderer/pipeline.js.map +1 -1
  29. package/dist/canvas/renderer/retained-backing.d.ts.map +1 -1
  30. package/dist/canvas/renderer/retained-backing.js +2 -1
  31. package/dist/canvas/renderer/retained-backing.js.map +1 -1
  32. package/dist/canvas/renderer/tiles/surface-pool.d.ts.map +1 -1
  33. package/dist/canvas/renderer/tiles/surface-pool.js +2 -7
  34. package/dist/canvas/renderer/tiles/surface-pool.js.map +1 -1
  35. package/dist/canvas/renderer.d.ts +20 -2
  36. package/dist/canvas/renderer.d.ts.map +1 -1
  37. package/dist/canvas/renderer.js +28 -4
  38. package/dist/canvas/renderer.js.map +1 -1
  39. package/dist/canvas/scene.d.ts.map +1 -1
  40. package/dist/canvas/scene.js +4 -3
  41. package/dist/canvas/scene.js.map +1 -1
  42. package/dist/canvas/shaders/compile.d.ts +3 -1
  43. package/dist/canvas/shaders/compile.d.ts.map +1 -1
  44. package/dist/canvas/shaders/compile.js +12 -3
  45. package/dist/canvas/shaders/compile.js.map +1 -1
  46. package/dist/canvas/shaders/draw.d.ts.map +1 -1
  47. package/dist/canvas/shaders/draw.js +10 -3
  48. package/dist/canvas/shaders/draw.js.map +1 -1
  49. package/dist/canvas/shaders/effect.d.ts.map +1 -1
  50. package/dist/canvas/shaders/effect.js +8 -17
  51. package/dist/canvas/shaders/effect.js.map +1 -1
  52. package/dist/canvas/shadows/shape.d.ts.map +1 -1
  53. package/dist/canvas/shadows/shape.js +4 -2
  54. package/dist/canvas/shadows/shape.js.map +1 -1
  55. package/dist/canvas/shadows.d.ts.map +1 -1
  56. package/dist/canvas/shadows.js +4 -2
  57. package/dist/canvas/shadows.js.map +1 -1
  58. package/dist/canvas/text/decorations.d.ts +2 -2
  59. package/dist/canvas/text/decorations.d.ts.map +1 -1
  60. package/dist/canvas/text/decorations.js +5 -5
  61. package/dist/canvas/text/decorations.js.map +1 -1
  62. package/dist/canvas/text/index.js +1 -1
  63. package/dist/canvas/text/index.js.map +1 -1
  64. package/dist/canvas/text/paragraph/index.d.ts +2 -2
  65. package/dist/canvas/text/paragraph/index.d.ts.map +1 -1
  66. package/dist/canvas/text/paragraph/index.js +16 -5
  67. package/dist/canvas/text/paragraph/index.js.map +1 -1
  68. package/dist/canvas/text/renderer.d.ts +2 -1
  69. package/dist/canvas/text/renderer.d.ts.map +1 -1
  70. package/dist/canvas/text/shape.js +4 -4
  71. package/dist/canvas/text/shape.js.map +1 -1
  72. package/dist/canvas/texture.d.ts.map +1 -1
  73. package/dist/canvas/texture.js +2 -1
  74. package/dist/canvas/texture.js.map +1 -1
  75. package/dist/design-memory/rules.js +1 -1
  76. package/dist/editor/clipboard/assets.d.ts.map +1 -1
  77. package/dist/editor/clipboard/assets.js +2 -2
  78. package/dist/editor/clipboard/assets.js.map +1 -1
  79. package/dist/editor/clipboard/component-matches.d.ts +13 -0
  80. package/dist/editor/clipboard/component-matches.d.ts.map +1 -0
  81. package/dist/editor/clipboard/component-matches.js +50 -0
  82. package/dist/editor/clipboard/component-matches.js.map +1 -0
  83. package/dist/editor/clipboard/dependencies.d.ts +7 -0
  84. package/dist/editor/clipboard/dependencies.d.ts.map +1 -1
  85. package/dist/editor/clipboard/dependencies.js +5 -0
  86. package/dist/editor/clipboard/dependencies.js.map +1 -1
  87. package/dist/editor/clipboard/export.js +2 -2
  88. package/dist/editor/clipboard/export.js.map +1 -1
  89. package/dist/editor/clipboard.d.ts.map +1 -1
  90. package/dist/editor/clipboard.js +48 -19
  91. package/dist/editor/clipboard.js.map +1 -1
  92. package/dist/editor/components/properties.d.ts.map +1 -1
  93. package/dist/editor/components/properties.js +3 -3
  94. package/dist/editor/components/properties.js.map +1 -1
  95. package/dist/editor/eyedropper.d.ts +1 -1
  96. package/dist/editor/eyedropper.d.ts.map +1 -1
  97. package/dist/editor/eyedropper.js +6 -3
  98. package/dist/editor/eyedropper.js.map +1 -1
  99. package/dist/editor/history/atomic-tool.d.ts.map +1 -1
  100. package/dist/editor/history/atomic-tool.js +3 -2
  101. package/dist/editor/history/atomic-tool.js.map +1 -1
  102. package/dist/editor/shapes/pencil.js +1 -1
  103. package/dist/editor/structure/state.d.ts.map +1 -1
  104. package/dist/editor/structure/state.js +2 -2
  105. package/dist/editor/structure/state.js.map +1 -1
  106. package/dist/editor/text.d.ts.map +1 -1
  107. package/dist/editor/text.js +2 -2
  108. package/dist/editor/text.js.map +1 -1
  109. package/dist/editor/variables.js +3 -3
  110. package/dist/editor/variables.js.map +1 -1
  111. package/dist/figma-api/fresh-read.d.ts +15 -0
  112. package/dist/figma-api/fresh-read.d.ts.map +1 -0
  113. package/dist/figma-api/fresh-read.js +54 -0
  114. package/dist/figma-api/fresh-read.js.map +1 -0
  115. package/dist/figma-api/graph-ref.d.ts +9 -0
  116. package/dist/figma-api/graph-ref.d.ts.map +1 -0
  117. package/dist/figma-api/graph-ref.js +14 -0
  118. package/dist/figma-api/graph-ref.js.map +1 -0
  119. package/dist/figma-api/index.d.ts +6 -1
  120. package/dist/figma-api/index.d.ts.map +1 -1
  121. package/dist/figma-api/index.js +12 -5
  122. package/dist/figma-api/index.js.map +1 -1
  123. package/dist/figma-api/pending-layout.d.ts +3 -3
  124. package/dist/figma-api/pending-layout.d.ts.map +1 -1
  125. package/dist/figma-api/pending-layout.js +7 -3
  126. package/dist/figma-api/pending-layout.js.map +1 -1
  127. package/dist/figma-api/pending-sync.d.ts +1 -1
  128. package/dist/figma-api/pending-sync.d.ts.map +1 -1
  129. package/dist/figma-api/pending-sync.js +3 -1
  130. package/dist/figma-api/pending-sync.js.map +1 -1
  131. package/dist/figma-api/proxy.d.ts.map +1 -1
  132. package/dist/figma-api/proxy.js +3 -2
  133. package/dist/figma-api/proxy.js.map +1 -1
  134. package/dist/figma-api/reactions.d.ts +20 -4
  135. package/dist/figma-api/reactions.d.ts.map +1 -1
  136. package/dist/figma-api/reactions.js +49 -3
  137. package/dist/figma-api/reactions.js.map +1 -1
  138. package/dist/figma-api/variables/index.d.ts.map +1 -1
  139. package/dist/figma-api/variables/index.js +2 -2
  140. package/dist/figma-api/variables/index.js.map +1 -1
  141. package/dist/io/formats/design-tokens/css/known.js +1 -1
  142. package/dist/io/formats/design-tokens/css/known.js.map +1 -1
  143. package/dist/io/formats/design-tokens/css/read.d.ts +3 -1
  144. package/dist/io/formats/design-tokens/css/read.d.ts.map +1 -1
  145. package/dist/io/formats/design-tokens/css/read.js +11 -5
  146. package/dist/io/formats/design-tokens/css/read.js.map +1 -1
  147. package/dist/io/formats/design-tokens/css/sync.d.ts.map +1 -1
  148. package/dist/io/formats/design-tokens/css/sync.js +17 -4
  149. package/dist/io/formats/design-tokens/css/sync.js.map +1 -1
  150. package/dist/io/formats/design-tokens/css/values.d.ts +6 -5
  151. package/dist/io/formats/design-tokens/css/values.d.ts.map +1 -1
  152. package/dist/io/formats/design-tokens/css/values.js +24 -8
  153. package/dist/io/formats/design-tokens/css/values.js.map +1 -1
  154. package/dist/io/formats/design-tokens/decode.d.ts +7 -6
  155. package/dist/io/formats/design-tokens/decode.d.ts.map +1 -1
  156. package/dist/io/formats/design-tokens/decode.js +13 -12
  157. package/dist/io/formats/design-tokens/decode.js.map +1 -1
  158. package/dist/io/formats/design-tokens/export.js +3 -3
  159. package/dist/io/formats/design-tokens/export.js.map +1 -1
  160. package/dist/io/formats/design-tokens/plan/index.d.ts.map +1 -1
  161. package/dist/io/formats/design-tokens/plan/index.js +4 -3
  162. package/dist/io/formats/design-tokens/plan/index.js.map +1 -1
  163. package/dist/io/formats/design-tokens/plan/styles.d.ts.map +1 -1
  164. package/dist/io/formats/design-tokens/plan/styles.js +9 -9
  165. package/dist/io/formats/design-tokens/plan/styles.js.map +1 -1
  166. package/dist/io/formats/design-tokens/styles.d.ts +4 -4
  167. package/dist/io/formats/design-tokens/styles.d.ts.map +1 -1
  168. package/dist/io/formats/design-tokens/styles.js +7 -7
  169. package/dist/io/formats/design-tokens/styles.js.map +1 -1
  170. package/dist/io/formats/design-tokens/sync/drift.js +2 -2
  171. package/dist/io/formats/design-tokens/sync/drift.js.map +1 -1
  172. package/dist/io/formats/design-tokens/values.d.ts +10 -5
  173. package/dist/io/formats/design-tokens/values.d.ts.map +1 -1
  174. package/dist/io/formats/design-tokens/values.js +13 -7
  175. package/dist/io/formats/design-tokens/values.js.map +1 -1
  176. package/dist/io/formats/drawio/label.js +1 -1
  177. package/dist/io/formats/drawio/paint.js +1 -1
  178. package/dist/io/formats/drawio/warnings.d.ts +17 -2
  179. package/dist/io/formats/drawio/warnings.d.ts.map +1 -1
  180. package/dist/io/formats/drawio/warnings.js +15 -8
  181. package/dist/io/formats/drawio/warnings.js.map +1 -1
  182. package/dist/io/formats/fig/export/index.d.ts.map +1 -1
  183. package/dist/io/formats/fig/export/index.js +15 -3
  184. package/dist/io/formats/fig/export/index.js.map +1 -1
  185. package/dist/io/formats/fig/export/patch/index.d.ts.map +1 -1
  186. package/dist/io/formats/fig/export/patch/index.js +2 -1
  187. package/dist/io/formats/fig/export/patch/index.js.map +1 -1
  188. package/dist/io/formats/fig/export/setup.d.ts +7 -2
  189. package/dist/io/formats/fig/export/setup.d.ts.map +1 -1
  190. package/dist/io/formats/fig/export/setup.js +12 -13
  191. package/dist/io/formats/fig/export/setup.js.map +1 -1
  192. package/dist/io/formats/fig/export/variables.d.ts.map +1 -1
  193. package/dist/io/formats/fig/export/variables.js +9 -7
  194. package/dist/io/formats/fig/export/variables.js.map +1 -1
  195. package/dist/io/formats/html/index.d.ts +1 -0
  196. package/dist/io/formats/html/index.d.ts.map +1 -1
  197. package/dist/io/formats/html/index.js +5 -3
  198. package/dist/io/formats/html/index.js.map +1 -1
  199. package/dist/io/formats/html/vectors.js +1 -0
  200. package/dist/io/formats/html/vectors.js.map +1 -1
  201. package/dist/io/formats/mermaid/layers.js +2 -2
  202. package/dist/io/formats/mermaid/layers.js.map +1 -1
  203. package/dist/io/formats/mermaid/styles.js +1 -1
  204. package/dist/io/formats/pdf/export.d.ts.map +1 -1
  205. package/dist/io/formats/pdf/export.js +1 -0
  206. package/dist/io/formats/pdf/export.js.map +1 -1
  207. package/dist/io/formats/pdf/prepare.d.ts +4 -4
  208. package/dist/io/formats/pdf/prepare.d.ts.map +1 -1
  209. package/dist/io/formats/pdf/prepare.js +2 -2
  210. package/dist/io/formats/pdf/prepare.js.map +1 -1
  211. package/dist/io/formats/pen/index.d.ts.map +1 -1
  212. package/dist/io/formats/pen/index.js +13 -2
  213. package/dist/io/formats/pen/index.js.map +1 -1
  214. package/dist/io/formats/pptx/style.js +1 -1
  215. package/dist/io/formats/raster/render.d.ts +1 -1
  216. package/dist/io/formats/raster/render.d.ts.map +1 -1
  217. package/dist/io/formats/raster/render.js +9 -4
  218. package/dist/io/formats/raster/render.js.map +1 -1
  219. package/dist/io/formats/svg/defs.d.ts +6 -3
  220. package/dist/io/formats/svg/defs.d.ts.map +1 -1
  221. package/dist/io/formats/svg/defs.js +12 -11
  222. package/dist/io/formats/svg/defs.js.map +1 -1
  223. package/dist/io/formats/svg/effects.js +2 -2
  224. package/dist/io/formats/svg/effects.js.map +1 -1
  225. package/dist/io/formats/svg/export.d.ts +5 -2
  226. package/dist/io/formats/svg/export.d.ts.map +1 -1
  227. package/dist/io/formats/svg/export.js +4 -2
  228. package/dist/io/formats/svg/export.js.map +1 -1
  229. package/dist/io/formats/svg/filter.d.ts +4 -1
  230. package/dist/io/formats/svg/filter.d.ts.map +1 -1
  231. package/dist/io/formats/svg/filter.js +6 -2
  232. package/dist/io/formats/svg/filter.js.map +1 -1
  233. package/dist/io/formats/svg/grain.js +1 -1
  234. package/dist/io/formats/svg/grain.js.map +1 -1
  235. package/dist/io/formats/svg/import.d.ts +4 -2
  236. package/dist/io/formats/svg/import.d.ts.map +1 -1
  237. package/dist/io/formats/svg/import.js +2 -1
  238. package/dist/io/formats/svg/import.js.map +1 -1
  239. package/dist/io/formats/svg/text/export.d.ts.map +1 -1
  240. package/dist/io/formats/svg/text/export.js +8 -8
  241. package/dist/io/formats/svg/text/export.js.map +1 -1
  242. package/dist/io/formats/svg/text/layout.js +2 -2
  243. package/dist/io/formats/svg/text/layout.js.map +1 -1
  244. package/dist/io/formats.d.ts.map +1 -1
  245. package/dist/io/formats.js +11 -4
  246. package/dist/io/formats.js.map +1 -1
  247. package/dist/io/index.d.ts +2 -2
  248. package/dist/io/subgraph.d.ts.map +1 -1
  249. package/dist/io/subgraph.js +1 -1
  250. package/dist/io/subgraph.js.map +1 -1
  251. package/dist/io/types.d.ts +12 -3
  252. package/dist/io/types.d.ts.map +1 -1
  253. package/dist/kiwi/fig/session/options.d.ts +3 -0
  254. package/dist/kiwi/fig/session/options.d.ts.map +1 -1
  255. package/dist/kiwi/fig/session/options.js +4 -0
  256. package/dist/kiwi/fig/session/options.js.map +1 -1
  257. package/dist/layout/yoga-helpers.d.ts +2 -1
  258. package/dist/layout/yoga-helpers.d.ts.map +1 -1
  259. package/dist/layout/yoga-helpers.js +7 -1
  260. package/dist/layout/yoga-helpers.js.map +1 -1
  261. package/dist/layout.js +24 -1
  262. package/dist/layout.js.map +1 -1
  263. package/dist/lint/fixes.js +1 -1
  264. package/dist/lint/linter.js +2 -2
  265. package/dist/lint/linter.js.map +1 -1
  266. package/dist/pairdraw-api/comments.d.ts +4 -1
  267. package/dist/pairdraw-api/comments.d.ts.map +1 -1
  268. package/dist/pairdraw-api/comments.js +5 -0
  269. package/dist/pairdraw-api/comments.js.map +1 -1
  270. package/dist/pairdraw-api/index.d.ts +3 -3
  271. package/dist/pairdraw-api/index.d.ts.map +1 -1
  272. package/dist/pairdraw-api/index.js +5 -5
  273. package/dist/pairdraw-api/index.js.map +1 -1
  274. package/dist/pairdraw-api/nodes.d.ts +1 -1
  275. package/dist/prototype/scene.js +1 -1
  276. package/dist/rpc/analyze-commands.js +1 -1
  277. package/dist/rpc/read-commands.d.ts +2 -2
  278. package/dist/rpc/read-commands.js +3 -3
  279. package/dist/rpc/read-commands.js.map +1 -1
  280. package/dist/rpc/variables-command.js +2 -2
  281. package/dist/rpc/variables-command.js.map +1 -1
  282. package/dist/text/font/provider.d.ts +15 -0
  283. package/dist/text/font/provider.d.ts.map +1 -0
  284. package/dist/text/font/provider.js +18 -0
  285. package/dist/text/font/provider.js.map +1 -0
  286. package/dist/text/font/readiness.d.ts +32 -0
  287. package/dist/text/font/readiness.d.ts.map +1 -0
  288. package/dist/text/font/{status.js → readiness.js} +8 -4
  289. package/dist/text/font/readiness.js.map +1 -0
  290. package/dist/text/index.d.ts +4 -3
  291. package/dist/text/index.js +4 -3
  292. package/dist/text/prepare.d.ts +9 -4
  293. package/dist/text/prepare.d.ts.map +1 -1
  294. package/dist/text/prepare.js +9 -4
  295. package/dist/text/prepare.js.map +1 -1
  296. package/dist/tools/analyze/colors.js +1 -1
  297. package/dist/tools/analyze/responsive/index.js +7 -18
  298. package/dist/tools/analyze/responsive/index.js.map +1 -1
  299. package/dist/tools/analyze/responsive/widths.d.ts +27 -0
  300. package/dist/tools/analyze/responsive/widths.d.ts.map +1 -0
  301. package/dist/tools/analyze/responsive/widths.js +49 -0
  302. package/dist/tools/analyze/responsive/widths.js.map +1 -0
  303. package/dist/tools/analyze.d.ts +2 -1
  304. package/dist/tools/analyze.js +2 -1
  305. package/dist/tools/codegen/tokens.d.ts.map +1 -1
  306. package/dist/tools/codegen/tokens.js +2 -2
  307. package/dist/tools/codegen/tokens.js.map +1 -1
  308. package/dist/tools/comments.d.ts.map +1 -1
  309. package/dist/tools/comments.js +2 -2
  310. package/dist/tools/comments.js.map +1 -1
  311. package/dist/tools/component-catalog.d.ts.map +1 -1
  312. package/dist/tools/component-catalog.js +5 -3
  313. package/dist/tools/component-catalog.js.map +1 -1
  314. package/dist/tools/create/basic.js +1 -1
  315. package/dist/tools/create/behaviours.js +1 -1
  316. package/dist/tools/create/html.d.ts.map +1 -1
  317. package/dist/tools/create/html.js +1 -3
  318. package/dist/tools/create/html.js.map +1 -1
  319. package/dist/tools/create/icons.js +2 -2
  320. package/dist/tools/create/icons.js.map +1 -1
  321. package/dist/tools/create/mermaid.js +1 -1
  322. package/dist/tools/create/render.js +1 -1
  323. package/dist/tools/create/svg.js +5 -2
  324. package/dist/tools/create/svg.js.map +1 -1
  325. package/dist/tools/create/vector.js +3 -3
  326. package/dist/tools/create/vector.js.map +1 -1
  327. package/dist/tools/css/shorthand.d.ts +20 -0
  328. package/dist/tools/css/shorthand.d.ts.map +1 -0
  329. package/dist/tools/css/shorthand.js +54 -0
  330. package/dist/tools/css/shorthand.js.map +1 -0
  331. package/dist/tools/describe/index.js +2 -2
  332. package/dist/tools/describe/index.js.map +1 -1
  333. package/dist/tools/describe/issues.js +1 -1
  334. package/dist/tools/html-host.d.ts.map +1 -1
  335. package/dist/tools/html-host.js +5 -3
  336. package/dist/tools/html-host.js.map +1 -1
  337. package/dist/tools/image-ai/apply.d.ts.map +1 -1
  338. package/dist/tools/image-ai/apply.js +1 -3
  339. package/dist/tools/image-ai/apply.js.map +1 -1
  340. package/dist/tools/image-ai/generate.js +1 -1
  341. package/dist/tools/image-ai/service.d.ts.map +1 -1
  342. package/dist/tools/image-ai/service.js +5 -3
  343. package/dist/tools/image-ai/service.js.map +1 -1
  344. package/dist/tools/index.d.ts +2 -1
  345. package/dist/tools/index.js +2 -1
  346. package/dist/tools/modify/effects.js +1 -1
  347. package/dist/tools/modify/effects.js.map +1 -1
  348. package/dist/tools/modify/geometry.d.ts.map +1 -1
  349. package/dist/tools/modify/geometry.js +14 -3
  350. package/dist/tools/modify/geometry.js.map +1 -1
  351. package/dist/tools/modify/layout.d.ts.map +1 -1
  352. package/dist/tools/modify/layout.js +35 -8
  353. package/dist/tools/modify/layout.js.map +1 -1
  354. package/dist/tools/modify/matching.d.ts.map +1 -1
  355. package/dist/tools/modify/matching.js +10 -10
  356. package/dist/tools/modify/matching.js.map +1 -1
  357. package/dist/tools/modify/paint.d.ts.map +1 -1
  358. package/dist/tools/modify/paint.js +57 -5
  359. package/dist/tools/modify/paint.js.map +1 -1
  360. package/dist/tools/modify/reactions.d.ts.map +1 -1
  361. package/dist/tools/modify/reactions.js +2 -2
  362. package/dist/tools/modify/reactions.js.map +1 -1
  363. package/dist/tools/modify/text.d.ts.map +1 -1
  364. package/dist/tools/modify/text.js +3 -3
  365. package/dist/tools/modify/text.js.map +1 -1
  366. package/dist/tools/prompts/codegen.js +1 -1
  367. package/dist/tools/prompts/codegen.js.map +1 -1
  368. package/dist/tools/read/css.d.ts +14 -0
  369. package/dist/tools/read/css.d.ts.map +1 -0
  370. package/dist/tools/read/css.js +306 -0
  371. package/dist/tools/read/css.js.map +1 -0
  372. package/dist/tools/read/libraries.js +1 -1
  373. package/dist/tools/read/reactions.js +1 -1
  374. package/dist/tools/read/reactions.js.map +1 -1
  375. package/dist/tools/read/space.d.ts.map +1 -1
  376. package/dist/tools/read/space.js +0 -2
  377. package/dist/tools/read/space.js.map +1 -1
  378. package/dist/tools/read.d.ts +2 -1
  379. package/dist/tools/read.js +2 -1
  380. package/dist/tools/registry/core.d.ts +1 -1
  381. package/dist/tools/registry/core.js +3 -1
  382. package/dist/tools/registry/core.js.map +1 -1
  383. package/dist/tools/schema.d.ts +6 -4
  384. package/dist/tools/schema.d.ts.map +1 -1
  385. package/dist/tools/schema.js +9 -5
  386. package/dist/tools/schema.js.map +1 -1
  387. package/dist/tools/script/host.d.ts.map +1 -1
  388. package/dist/tools/script/host.js +5 -3
  389. package/dist/tools/script/host.js.map +1 -1
  390. package/dist/tools/variables/collections.js +1 -1
  391. package/dist/tools/variables/collections.js.map +1 -1
  392. package/dist/tools/variables/values.d.ts.map +1 -1
  393. package/dist/tools/variables/values.js +4 -4
  394. package/dist/tools/variables/values.js.map +1 -1
  395. package/dist/tools/vector/vectorize.d.ts.map +1 -1
  396. package/dist/tools/vector/vectorize.js +6 -4
  397. package/dist/tools/vector/vectorize.js.map +1 -1
  398. package/dist/tools/video-host.d.ts.map +1 -1
  399. package/dist/tools/video-host.js +5 -3
  400. package/dist/tools/video-host.js.map +1 -1
  401. package/dist/vector/vectorize/svg/gradients.d.ts +2 -2
  402. package/dist/vector/vectorize/svg/gradients.d.ts.map +1 -1
  403. package/dist/vector/vectorize/svg/gradients.js +5 -5
  404. package/dist/vector/vectorize/svg/gradients.js.map +1 -1
  405. package/dist/vector/vectorize/svg/to-vectors.d.ts +3 -1
  406. package/dist/vector/vectorize/svg/to-vectors.d.ts.map +1 -1
  407. package/dist/vector/vectorize/svg/to-vectors.js +13 -12
  408. package/dist/vector/vectorize/svg/to-vectors.js.map +1 -1
  409. package/package.json +9 -9
  410. package/src/canvas/noise/render.ts +1 -1
  411. package/src/canvas/noise/shader.ts +13 -5
  412. package/src/canvas/noise/tile.ts +2 -1
  413. package/src/canvas/renderer/colors.ts +76 -50
  414. package/src/canvas/renderer/document-surface.ts +53 -0
  415. package/src/canvas/renderer/fonts.ts +6 -4
  416. package/src/canvas/renderer/lifecycle.ts +4 -4
  417. package/src/canvas/renderer/methods.ts +1 -0
  418. package/src/canvas/renderer/pipeline.ts +21 -3
  419. package/src/canvas/renderer/retained-backing.ts +2 -1
  420. package/src/canvas/renderer/tiles/surface-pool.ts +9 -7
  421. package/src/canvas/renderer.ts +36 -11
  422. package/src/canvas/scene.ts +4 -3
  423. package/src/canvas/shaders/compile.ts +14 -3
  424. package/src/canvas/shaders/draw.ts +11 -4
  425. package/src/canvas/shaders/effect.ts +8 -19
  426. package/src/canvas/shadows/shape.ts +4 -2
  427. package/src/canvas/shadows.ts +5 -2
  428. package/src/canvas/text/decorations.ts +15 -5
  429. package/src/canvas/text/index.ts +9 -1
  430. package/src/canvas/text/paragraph/index.ts +16 -6
  431. package/src/canvas/text/renderer.ts +2 -1
  432. package/src/canvas/text/shape.ts +4 -4
  433. package/src/canvas/texture.ts +2 -1
  434. package/src/editor/clipboard/assets.ts +6 -2
  435. package/src/editor/clipboard/component-matches.ts +65 -0
  436. package/src/editor/clipboard/dependencies.ts +22 -1
  437. package/src/editor/clipboard/export.ts +2 -2
  438. package/src/editor/clipboard.ts +74 -20
  439. package/src/editor/components/properties.ts +3 -2
  440. package/src/editor/eyedropper.ts +14 -4
  441. package/src/editor/history/atomic-tool.ts +3 -2
  442. package/src/editor/structure/state.ts +2 -1
  443. package/src/editor/text.ts +2 -1
  444. package/src/editor/variables.ts +3 -3
  445. package/src/figma-api/fresh-read.ts +57 -0
  446. package/src/figma-api/graph-ref.ts +13 -0
  447. package/src/figma-api/index.ts +12 -4
  448. package/src/figma-api/pending-layout.ts +7 -3
  449. package/src/figma-api/pending-sync.ts +4 -1
  450. package/src/figma-api/proxy.ts +2 -1
  451. package/src/figma-api/reactions.ts +91 -10
  452. package/src/figma-api/variables/index.ts +5 -4
  453. package/src/io/formats/design-tokens/css/known.ts +1 -1
  454. package/src/io/formats/design-tokens/css/read.ts +20 -7
  455. package/src/io/formats/design-tokens/css/sync.ts +9 -4
  456. package/src/io/formats/design-tokens/css/values.ts +37 -9
  457. package/src/io/formats/design-tokens/decode.ts +17 -12
  458. package/src/io/formats/design-tokens/export.ts +3 -3
  459. package/src/io/formats/design-tokens/plan/index.ts +6 -5
  460. package/src/io/formats/design-tokens/plan/styles.ts +37 -10
  461. package/src/io/formats/design-tokens/styles.ts +10 -7
  462. package/src/io/formats/design-tokens/sync/drift.ts +6 -4
  463. package/src/io/formats/design-tokens/values.ts +15 -8
  464. package/src/io/formats/drawio/warnings.ts +28 -9
  465. package/src/io/formats/fig/export/index.ts +36 -3
  466. package/src/io/formats/fig/export/patch/index.ts +4 -1
  467. package/src/io/formats/fig/export/setup.ts +25 -15
  468. package/src/io/formats/fig/export/variables.ts +17 -6
  469. package/src/io/formats/html/index.ts +9 -3
  470. package/src/io/formats/html/vectors.ts +1 -0
  471. package/src/io/formats/mermaid/layers.ts +2 -2
  472. package/src/io/formats/pdf/export.ts +1 -0
  473. package/src/io/formats/pdf/prepare.ts +6 -6
  474. package/src/io/formats/pen/index.ts +15 -4
  475. package/src/io/formats/raster/render.ts +12 -4
  476. package/src/io/formats/svg/defs.ts +26 -14
  477. package/src/io/formats/svg/effects.ts +2 -2
  478. package/src/io/formats/svg/export.ts +17 -3
  479. package/src/io/formats/svg/filter.ts +12 -2
  480. package/src/io/formats/svg/grain.ts +1 -1
  481. package/src/io/formats/svg/import.ts +6 -3
  482. package/src/io/formats/svg/text/export.ts +10 -8
  483. package/src/io/formats/svg/text/layout.ts +2 -2
  484. package/src/io/formats.ts +18 -5
  485. package/src/io/index.ts +1 -0
  486. package/src/io/subgraph.ts +4 -1
  487. package/src/io/types.ts +10 -0
  488. package/src/kiwi/fig/session/options.ts +4 -1
  489. package/src/layout/yoga-helpers.ts +8 -0
  490. package/src/layout.ts +47 -1
  491. package/src/lint/linter.ts +1 -1
  492. package/src/pairdraw-api/comments.ts +6 -0
  493. package/src/pairdraw-api/index.ts +7 -9
  494. package/src/rpc/read-commands.ts +4 -4
  495. package/src/rpc/variables-command.ts +2 -2
  496. package/src/text/font/provider.ts +26 -0
  497. package/src/text/font/{status.ts → readiness.ts} +13 -9
  498. package/src/text/index.ts +2 -1
  499. package/src/text/prepare.ts +9 -4
  500. package/src/tools/analyze/responsive/index.ts +8 -15
  501. package/src/tools/analyze/responsive/widths.ts +63 -0
  502. package/src/tools/analyze.ts +2 -0
  503. package/src/tools/codegen/tokens.ts +4 -2
  504. package/src/tools/comments.ts +6 -4
  505. package/src/tools/component-catalog.ts +5 -3
  506. package/src/tools/create/html.ts +0 -3
  507. package/src/tools/create/icons.ts +1 -1
  508. package/src/tools/create/svg.ts +4 -1
  509. package/src/tools/create/vector.ts +2 -2
  510. package/src/tools/css/shorthand.ts +64 -0
  511. package/src/tools/describe/index.ts +2 -8
  512. package/src/tools/html-host.ts +5 -3
  513. package/src/tools/image-ai/apply.ts +0 -2
  514. package/src/tools/image-ai/service.ts +5 -3
  515. package/src/tools/index.ts +2 -0
  516. package/src/tools/modify/effects.ts +1 -1
  517. package/src/tools/modify/geometry.ts +16 -3
  518. package/src/tools/modify/layout.ts +47 -13
  519. package/src/tools/modify/matching.ts +14 -11
  520. package/src/tools/modify/paint.ts +85 -5
  521. package/src/tools/modify/reactions.ts +3 -2
  522. package/src/tools/modify/text.ts +15 -11
  523. package/src/tools/prompts/codegen.md +2 -1
  524. package/src/tools/read/css.ts +365 -0
  525. package/src/tools/read/reactions.ts +3 -2
  526. package/src/tools/read/space.ts +0 -2
  527. package/src/tools/read.ts +1 -0
  528. package/src/tools/registry/core.ts +3 -2
  529. package/src/tools/schema.ts +14 -5
  530. package/src/tools/script/host.ts +6 -3
  531. package/src/tools/variables/collections.ts +1 -1
  532. package/src/tools/variables/values.ts +16 -5
  533. package/src/tools/vector/vectorize.ts +10 -4
  534. package/src/tools/video-host.ts +5 -3
  535. package/src/vector/vectorize/svg/gradients.ts +8 -5
  536. package/src/vector/vectorize/svg/to-vectors.ts +48 -14
  537. package/dist/text/font/status.d.ts +0 -28
  538. package/dist/text/font/status.d.ts.map +0 -1
  539. package/dist/text/font/status.js.map +0 -1
@@ -1,10 +1,13 @@
1
1
  import { isValid, toUint8Array } from 'js-base64'
2
2
  import * as v from 'valibot'
3
3
 
4
+ import type { Variable, VariableCollection, VariableValue } from '@pairdraw/scene-graph'
4
5
  import { gradientTransformRows, linearGradientTransform } from '@pairdraw/scene-graph/gradient'
5
- import type { Vector } from '@pairdraw/scene-graph/primitives'
6
+ import type { Color, Vector } from '@pairdraw/scene-graph/primitives'
6
7
 
8
+ import type { FigmaAPI } from '#core/figma-api'
7
9
  import { storeImage } from '#core/figma-api/images'
10
+ import { PairdrawAPI } from '#core/pairdraw-api'
8
11
  import {
9
12
  defineTool,
10
13
  nodeIdInputSchema,
@@ -22,11 +25,43 @@ const STRETCH_IMAGE_TRANSFORM: [[number, number, number], [number, number, numbe
22
25
  [0, 1, 0]
23
26
  ]
24
27
 
28
+ /**
29
+ * `var(--color/brand)` or `var(--color/brand, #4F46E5)`: a token by name, as `get_css` writes it.
30
+ * The fallback runs to the last `)`, since a Display P3 document writes one as `color(display-p3 …)`.
31
+ */
32
+ const COLOR_TOKEN = /^var\(\s*--([^,()]+?)\s*(?:,(.*))?\)$/
33
+
34
+ function colorVariablesNamed(figma: FigmaAPI, name: string): Variable[] {
35
+ const matches: Variable[] = []
36
+ for (const variable of figma.graph.variables.values()) {
37
+ if (variable.type === 'COLOR' && variable.name === name) matches.push(variable)
38
+ }
39
+ return matches
40
+ }
41
+
42
+ /** A colour, as opposed to a token alias or an expression a variable may hold instead. */
43
+ function isColor(value: VariableValue | undefined): value is Color {
44
+ return typeof value === 'object' && 'r' in value && 'g' in value && 'b' in value && 'a' in value
45
+ }
46
+
47
+ /** The colour a token holds in its default mode, and its collection, for a fill to take. */
48
+ function tokenColor(
49
+ figma: FigmaAPI,
50
+ variable: Variable
51
+ ): { color: Color; collection: VariableCollection | undefined } | { error: string } {
52
+ const collection = figma.graph.variableCollections.get(variable.collectionId)
53
+ const value = collection
54
+ ? variable.valuesByMode[collection.defaultModeId]
55
+ : Object.values(variable.valuesByMode)[0]
56
+ if (!isColor(value)) return { error: `Variable "${variable.name}" holds no colour` }
57
+ return { color: value, collection }
58
+ }
59
+
25
60
  export const setFill = defineTool({
26
61
  name: 'set_fill',
27
62
 
28
63
  description:
29
- 'Set fill on a node. Solid: color="#ff0000". Linear gradient: gradient="top-bottom" or "left-right" with color (start) and color_end (end).',
64
+ 'Set fill on a node. Solid: color="#ff0000". A token by name: color="var(--color/brand)" paints its colour and binds the fill. Linear gradient: gradient="top-bottom" or "left-right" with color (start) and color_end (end); gradient stops take hex colours, not tokens.',
30
65
  execution: { kind: 'sync', mutation: 'properties' },
31
66
  input: v.strictObject({
32
67
  id: nodeIdInputSchema,
@@ -45,11 +80,56 @@ export const setFill = defineTool({
45
80
  const node = figma.getNodeById(id)
46
81
  if (!node) return { error: `Node "${id}" not found` }
47
82
 
48
- const c = parseToolColor(color)
83
+ // A token name paints the colour it holds and binds the fill, so the layer follows the token.
84
+ const token = COLOR_TOKEN.exec(color)
85
+ const endToken = color_end === undefined ? null : COLOR_TOKEN.exec(color_end)
86
+ // Gradient stops carry no variable binding, so a token there would paint the wrong thing.
87
+ if (gradient && (token !== null || endToken !== null)) {
88
+ const named = [
89
+ token === null ? undefined : `"${token[1]}"`,
90
+ endToken === null ? undefined : `"${endToken[1]}"`
91
+ ]
92
+ .filter((entry) => entry !== undefined)
93
+ .join(' and ')
94
+ return {
95
+ error: `A gradient cannot take the token ${named}: gradient stops have no variable binding. Pass hex colours for a gradient, or a token only for a solid fill.`
96
+ }
97
+ }
98
+ const name = token === null ? null : token[1]
99
+ if (name !== null) {
100
+ const matches = colorVariablesNamed(figma, name)
101
+ if (matches.length === 0) {
102
+ return {
103
+ error: `No COLOR variable named "${name}". Call find_variables to list the document's tokens.`
104
+ }
105
+ }
106
+ if (matches.length > 1) {
107
+ const where = matches
108
+ .map(
109
+ (variable) =>
110
+ figma.graph.variableCollections.get(variable.collectionId)?.name ??
111
+ variable.collectionId
112
+ )
113
+ .join(', ')
114
+ return {
115
+ error: `${matches.length} variables named "${name}" (${where}); bind one with bind_variable.`
116
+ }
117
+ }
118
+ for (const variable of matches) {
119
+ const resolved = tokenColor(figma, variable)
120
+ if ('error' in resolved) return resolved
121
+ node.fills = [{ type: 'SOLID', color: resolved.color }]
122
+ new PairdrawAPI(figma).bindVariable(node.id, 'fills/0/color', variable)
123
+ return { id, color: resolved.color, bound: name }
124
+ }
125
+ return { error: `No COLOR variable named "${name}"` }
126
+ }
127
+
128
+ const c = parseToolColor(color, figma.graph.documentColorSpace)
49
129
  if ('error' in c) return c
50
130
 
51
131
  if (gradient && color_end) {
52
- const cEnd = parseToolColor(color_end)
132
+ const cEnd = parseToolColor(color_end, figma.graph.documentColorSpace)
53
133
  if ('error' in cEnd) return cEnd
54
134
  // Edge middles of the layer's unit square that each direction runs between.
55
135
  const ends: Record<string, [Vector, Vector]> = {
@@ -111,7 +191,7 @@ export const setStroke = defineTool({
111
191
  const node = figma.getNodeById(id)
112
192
  if (!node) return { error: `Node "${id}" not found` }
113
193
 
114
- const c = parseToolColor(color)
194
+ const c = parseToolColor(color, figma.graph.documentColorSpace)
115
195
  if ('error' in c) return c
116
196
  node.strokes = [{ type: 'SOLID', color: c }]
117
197
  node.strokeWeight = weight
@@ -15,8 +15,9 @@ const reactionsInputSchema = v.pipe(
15
15
  "'EASE_IN' | 'EASE_IN_AND_OUT' | 'LINEAR' } }, overlayRelativePosition?: 'CENTER' | ... } | " +
16
16
  "{ type: 'BACK' } | { type: 'CLOSE' }] }]. NAVIGATE and OVERLAY point at a top-level frame " +
17
17
  'on the same page; CHANGE_TO at another variant of the set the layer is a variant of, an ' +
18
- 'instance of, or inside (set it once on the main component variant and every instance ' +
19
- "gets it); SCROLL_TO at a layer in the layer's top-level frame. ON_HOVER and ON_PRESS undo " +
18
+ 'instance of, or inside (set it once on the main component variant and every instance gets ' +
19
+ 'it), named by destinationId or by variantProperties such as { State: "Hover" }; SCROLL_TO ' +
20
+ "at a layer in the layer's top-level frame. ON_HOVER and ON_PRESS undo " +
20
21
  'their action when the pointer leaves or lifts. SMART_ANIMATE moves the layers two frames or ' +
21
22
  'variants share by name and place, and fades the rest; easing defaults to EASE_OUT.'
22
23
  )
@@ -1,5 +1,6 @@
1
1
  import * as v from 'valibot'
2
2
 
3
+ import type { DocumentColorSpace } from '@pairdraw/scene-graph'
3
4
  import type { Color } from '@pairdraw/scene-graph/primitives'
4
5
 
5
6
  import type { FigmaAPI, FigmaNodeProxy } from '#core/figma-api'
@@ -223,15 +224,18 @@ function badVariationTag(variations: FigmaVariationSettings | undefined): { erro
223
224
  }
224
225
 
225
226
  /** What a range edit sets, or why it cannot run: nothing named, a bad colour, or a bad link. */
226
- function rangeEdit(args: {
227
- family?: string
228
- size?: number
229
- style?: string
230
- variations?: unknown
231
- font_features?: Record<string, boolean>
232
- color?: string
233
- hyperlink?: string | null
234
- }): RangeEdit | { error: string } {
227
+ function rangeEdit(
228
+ args: {
229
+ family?: string
230
+ size?: number
231
+ style?: string
232
+ variations?: unknown
233
+ font_features?: Record<string, boolean>
234
+ color?: string
235
+ hyperlink?: string | null
236
+ },
237
+ profile: DocumentColorSpace
238
+ ): RangeEdit | { error: string } {
235
239
  if (
236
240
  !args.family &&
237
241
  !args.size &&
@@ -248,7 +252,7 @@ function rangeEdit(args: {
248
252
  }
249
253
  const hyperlink = requestedHyperlink(args.hyperlink)
250
254
  if (hyperlink && 'error' in hyperlink) return hyperlink
251
- const color = parseOptionalToolColor(args.color)
255
+ const color = parseOptionalToolColor(args.color, profile)
252
256
  if ('error' in color) return color
253
257
  return { hyperlink: hyperlink ?? null, color: color.color }
254
258
  }
@@ -287,7 +291,7 @@ export const setFontRange = defineTool({
287
291
  if (badTag) return badTag
288
292
  const badFeature = badFeatureEntry(args.font_features)
289
293
  if (badFeature) return badFeature
290
- const edit = rangeEdit(args)
294
+ const edit = rangeEdit(args, figma.graph.documentColorSpace)
291
295
  if ('error' in edit) return edit
292
296
  const { hyperlink, color } = edit
293
297
  // The range methods reject an empty range or one past the text, before changing anything.
@@ -2,7 +2,7 @@
2
2
 
3
3
  You convert Figma designs into production frontend code. You have full access to the design document through tools. Never guess — always read the actual design data.
4
4
 
5
- > Note: Auto-layout and visual property names match the JSX props in the render system. See `describe` tool output for semantic role and layout analysis of any node.
5
+ > Note: Auto-layout and visual property names match the JSX props in the render system. Read geometry and style with `get_css` (CSS-like lines, colours as tokens), roles and design issues with `describe`, and structure with `get_jsx`.
6
6
 
7
7
  ## Workflow
8
8
 
@@ -34,6 +34,7 @@ Identify the component architecture.
34
34
 
35
35
  ```
36
36
  analyze_clusters → find repeated visual patterns that should be components
37
+ get_css (per node) → CSS shape: flex, gap, padding, size constraints, token colours, text
37
38
  describe (per node) → semantic role, layout direction, visual properties, issues
38
39
  get_jsx (per node) → structural JSX to understand nesting and layout
39
40
  ```
@@ -0,0 +1,365 @@
1
+ import * as v from 'valibot'
2
+
3
+ import type { ColorProfile, SceneGraph, SceneNode, ShadowEffect } from '@pairdraw/scene-graph'
4
+ import { colorToDocumentCSS } from '@pairdraw/scene-graph/color'
5
+ import type { Color } from '@pairdraw/scene-graph/primitives'
6
+
7
+ import { defineTool, nodeIdsField, toolNumber } from '#core/tools/schema'
8
+
9
+ /**
10
+ * A subtree as CSS-shaped lines: one line per node, lengths in px, colours in the document's
11
+ * profile with the token that binds them in `var(--name, …)` form: hex in an sRGB document,
12
+ * `color(display-p3 …)` in a Display P3 one. This is the read side of the CSS shorthand the
13
+ * setters accept, so a value read here can be written back unchanged.
14
+ */
15
+ export const DEFAULT_MAX_BYTES = 6000
16
+ export const HARD_MAX_BYTES = 20_000
17
+
18
+ const AXIS_JUSTIFY: Record<string, string> = {
19
+ CENTER: 'center',
20
+ MAX: 'end',
21
+ SPACE_BETWEEN: 'space-between',
22
+ SPACE_AROUND: 'space-around'
23
+ }
24
+
25
+ const AXIS_ITEMS: Record<string, string> = {
26
+ CENTER: 'center',
27
+ MAX: 'end',
28
+ STRETCH: 'stretch',
29
+ BASELINE: 'baseline'
30
+ }
31
+
32
+ /** A length as CSS writes it: whole px where it is whole, up to two decimals otherwise. */
33
+ function px(value: number): string {
34
+ return `${Math.round(value * 100) / 100}px`
35
+ }
36
+
37
+ /**
38
+ * The radius line, read the way `shape-details` reads corners: the per-corner fields while
39
+ * `independentCorners` is set (the uniform field is stale then), four values in CSS order when
40
+ * they differ, one otherwise. The four values write back through `set_radius`'s shorthand.
41
+ */
42
+ function radiusOf(node: SceneNode): string | null {
43
+ if (node.independentCorners) {
44
+ const corners = [
45
+ node.topLeftRadius,
46
+ node.topRightRadius,
47
+ node.bottomRightRadius,
48
+ node.bottomLeftRadius
49
+ ]
50
+ if (corners.every((value) => value === corners[0])) {
51
+ return corners[0] > 0 ? px(corners[0]) : null
52
+ }
53
+ return corners.map((value) => (value === 0 ? '0' : px(value))).join(' ')
54
+ }
55
+ return node.cornerRadius > 0 ? px(node.cornerRadius) : null
56
+ }
57
+
58
+ function box(value: number): string {
59
+ return String(Math.round(value))
60
+ }
61
+
62
+ /** UTF-8 bytes without a Node Buffer, so the tool runs in the app as well as headless. */
63
+ function utf8Length(text: string): number {
64
+ let bytes = 0
65
+ for (let index = 0; index < text.length; index++) {
66
+ const code = text.charCodeAt(index)
67
+ if (code < 0x80) bytes += 1
68
+ else if (code < 0x800) bytes += 2
69
+ else if (code < 0xd800 || code >= 0xe000) bytes += 3
70
+ else bytes += 4
71
+ }
72
+ return bytes
73
+ }
74
+
75
+ function boundName(graph: SceneGraph, node: SceneNode, field: string): string | null {
76
+ const variableId = node.boundVariables[field]
77
+ if (!variableId) return null
78
+ return graph.variables.get(variableId)?.name ?? null
79
+ }
80
+
81
+ /**
82
+ * A stored colour as the shorthand writes it: `#RRGGBB` in an sRGB document, `color(display-p3 …)`
83
+ * in a Display P3 one, where hex would name a different colour. The shorthand carries no alpha, as
84
+ * it never has, so the paint's opacity is left to `opacity`.
85
+ */
86
+ function cssColor(color: Color, profile: ColorProfile): string {
87
+ return colorToDocumentCSS({ ...color, a: 1 }, profile)
88
+ }
89
+
90
+ /** A colour in the document's profile, or `var(--token, …)` when a variable paints it. */
91
+ function paintOf(node: SceneNode, graph: SceneGraph, field: string, paint: string): string {
92
+ const name = boundName(graph, node, field)
93
+ return name ? `var(--${name}, ${paint})` : paint
94
+ }
95
+
96
+ function background(node: SceneNode, graph: SceneGraph): string | null {
97
+ const index = node.fills.findIndex((candidate) => candidate.type === 'SOLID' && candidate.visible)
98
+ const solid = index === -1 ? undefined : node.fills[index]
99
+ if (solid) {
100
+ const paint = cssColor(solid.color, graph.documentColorSpace)
101
+ return paintOf(node, graph, `fills/${index}/color`, paint)
102
+ }
103
+ const otherIndex = node.fills.findIndex((candidate) => candidate.visible)
104
+ const other = otherIndex === -1 ? undefined : node.fills[otherIndex]
105
+ if (!other) return null
106
+ return other.type.startsWith('GRADIENT') ? 'gradient' : 'image'
107
+ }
108
+
109
+ function border(node: SceneNode, graph: SceneGraph): string | null {
110
+ const index = node.strokes.findIndex((candidate) => candidate.visible)
111
+ const stroke = index === -1 ? undefined : node.strokes[index]
112
+ if (!stroke) return null
113
+ const paint = cssColor(stroke.color, graph.documentColorSpace)
114
+ return `${px(stroke.weight)} ${paintOf(node, graph, `strokes/${index}/color`, paint)}`
115
+ }
116
+
117
+ /** Padding in CSS order, compressed to the fewest values that say the same thing. */
118
+ function padding(node: SceneNode): string | null {
119
+ const top = node.paddingTop
120
+ const right = node.paddingRight
121
+ const bottom = node.paddingBottom
122
+ const left = node.paddingLeft
123
+ if (top === 0 && right === 0 && bottom === 0 && left === 0) return null
124
+ if (top === right && right === bottom && bottom === left) return px(top)
125
+ if (top === bottom && right === left) return `${px(top)} ${px(right)}`
126
+ return `${px(top)} ${px(right)} ${px(bottom)} ${px(left)}`
127
+ }
128
+
129
+ function shadowOf(prefix: string, effect: ShadowEffect, profile: ColorProfile): string {
130
+ return `${prefix}:${px(effect.offset.x)} ${px(effect.offset.y)} ${px(effect.radius)} ${cssColor(effect.color, profile)}`
131
+ }
132
+
133
+ function effects(node: SceneNode, profile: ColorProfile): string[] {
134
+ const out: string[] = []
135
+ for (const effect of node.effects) {
136
+ if (!effect.visible) continue
137
+ if (effect.type === 'DROP_SHADOW') out.push(shadowOf('shadow', effect, profile))
138
+ else if (effect.type === 'INNER_SHADOW') out.push(shadowOf('inner-shadow', effect, profile))
139
+ else if (effect.type === 'LAYER_BLUR' || effect.type === 'FOREGROUND_BLUR')
140
+ out.push(`blur:${px(effect.radius)}`)
141
+ else out.push('backdrop-blur')
142
+ }
143
+ return out
144
+ }
145
+
146
+ function layoutDecls(node: SceneNode): string[] {
147
+ if (node.layoutMode === 'NONE') return []
148
+ const out = [node.layoutMode === 'HORIZONTAL' ? 'flex:row' : 'flex:column']
149
+ if (node.itemSpacing > 0) {
150
+ out.push(
151
+ node.layoutWrap === 'WRAP' && node.counterAxisSpacing > 0
152
+ ? `gap:${px(node.itemSpacing)} ${px(node.counterAxisSpacing)}`
153
+ : `gap:${px(node.itemSpacing)}`
154
+ )
155
+ }
156
+ const paddingValue = padding(node)
157
+ if (paddingValue) out.push(`padding:${paddingValue}`)
158
+ const justify = AXIS_JUSTIFY[node.primaryAxisAlign]
159
+ if (justify) out.push(`justify:${justify}`)
160
+ const items = AXIS_ITEMS[node.counterAxisAlign]
161
+ if (items) out.push(`items:${items}`)
162
+ if (node.layoutWrap === 'WRAP') out.push('wrap')
163
+ if (node.primaryAxisSizing === 'HUG') out.push('hug:main')
164
+ if (node.counterAxisSizing === 'HUG') out.push('hug:cross')
165
+ return out
166
+ }
167
+
168
+ function boxDecls(node: SceneNode, graph: SceneGraph): string[] {
169
+ const out: string[] = []
170
+ if (node.layoutAlignSelf === 'STRETCH') out.push('stretch')
171
+ if (node.layoutGrow > 0) out.push(`grow:${Math.round(node.layoutGrow * 100) / 100}`)
172
+ const bg = background(node, graph)
173
+ if (bg) out.push(`bg:${bg}`)
174
+ const stroke = border(node, graph)
175
+ if (stroke) out.push(`border:${stroke}`)
176
+ const radius = radiusOf(node)
177
+ if (radius) out.push(`radius:${radius}`)
178
+ if (node.minWidth !== null) out.push(`min-w:${px(node.minWidth)}`)
179
+ if (node.maxWidth !== null) out.push(`max-w:${px(node.maxWidth)}`)
180
+ if (node.minHeight !== null) out.push(`min-h:${px(node.minHeight)}`)
181
+ if (node.maxHeight !== null) out.push(`max-h:${px(node.maxHeight)}`)
182
+ out.push(...effects(node, graph.documentColorSpace))
183
+ if (node.opacity !== 1) out.push(`opacity:${Math.round(node.opacity * 100) / 100}`)
184
+ if (node.clipsContent) out.push('clip')
185
+ return out
186
+ }
187
+
188
+ function lineHeightOf(node: SceneNode): string {
189
+ const lineHeight = node.lineHeight
190
+ if (!lineHeight) return 'auto'
191
+ return lineHeight.unit === 'PERCENT'
192
+ ? `${Math.round(lineHeight.value * 100) / 100}%`
193
+ : px(lineHeight.value)
194
+ }
195
+
196
+ function textDecls(node: SceneNode, graph: SceneGraph): string[] {
197
+ const out = [
198
+ `font:${node.fontWeight} ${px(node.fontSize)}/${lineHeightOf(node)} ${node.fontFamily}`
199
+ ]
200
+ const bg = background(node, graph)
201
+ if (bg) out.push(`color:${bg}`)
202
+ if (node.textAlignHorizontal !== 'LEFT') {
203
+ out.push(`text-align:${node.textAlignHorizontal.toLowerCase()}`)
204
+ }
205
+ if (node.maxLines !== null && node.maxLines > 0) out.push(`max-lines:${node.maxLines}`)
206
+ if (node.textAutoResize === 'NONE') out.push('fixed')
207
+ return out
208
+ }
209
+
210
+ function lineOf(node: SceneNode, graph: SceneGraph): string {
211
+ const decls =
212
+ node.type === 'TEXT' ? textDecls(node, graph) : [...layoutDecls(node), ...boxDecls(node, graph)]
213
+ const label =
214
+ node.type === 'TEXT'
215
+ ? `"${node.text.slice(0, 40).replaceAll('\\', '\\\\').replaceAll('"', '\\"').replaceAll('\n', '\\n')}"`
216
+ : node.name
217
+ const body = decls.length > 0 ? ` {${decls.join(';')}}` : ''
218
+ return `${label}#${node.id} ${box(node.width)}×${box(node.height)}${body}`
219
+ }
220
+
221
+ interface Budget {
222
+ bytes: number
223
+ limit: number
224
+ truncated: boolean
225
+ }
226
+
227
+ /** What a cut-off walk left out, counted through the same visible-node rule as the lines. */
228
+ function countVisible(graph: SceneGraph, nodeId: string): number {
229
+ const node = graph.getNode(nodeId)
230
+ if (!node || !node.visible) return 0
231
+ let count = 1
232
+ for (const childId of node.childIds) count += countVisible(graph, childId)
233
+ return count
234
+ }
235
+
236
+ function truncationTail(omitted: number): string {
237
+ return `… +${omitted} node${omitted === 1 ? '' : 's'} (raise max_bytes or narrow with depth)`
238
+ }
239
+
240
+ /**
241
+ * Depth-first lines until the budget is spent. A line that does not fit ends the walk; the kept
242
+ * lines never exceed the limit on their own, so the reply can always stay within `max_bytes`.
243
+ */
244
+ function collect(
245
+ graph: SceneGraph,
246
+ nodeId: string,
247
+ depth: number,
248
+ indent: string,
249
+ lines: string[],
250
+ budget: Budget
251
+ ): void {
252
+ const node = graph.getNode(nodeId)
253
+ if (!node || !node.visible) return
254
+ if (budget.truncated) return
255
+ const line = `${indent}${lineOf(node, graph)}`
256
+ const fits = budget.bytes + utf8Length(line) + 1 <= budget.limit
257
+ if (!fits) {
258
+ budget.truncated = true
259
+ return
260
+ }
261
+ budget.bytes += utf8Length(line) + 1
262
+ lines.push(line)
263
+ if (depth > 0) {
264
+ for (const childId of node.childIds) {
265
+ collect(graph, childId, depth - 1, `${indent} `, lines, budget)
266
+ }
267
+ }
268
+ }
269
+
270
+ /**
271
+ * A subtree within `maxBytes`. The truncation tail is charged to the same budget: trailing lines
272
+ * give way first, then the tail is left out when only the kept lines fit. A block whose first line
273
+ * does not fit returns no CSS at all; the reply's `truncated`/`omitted` fields report the cut.
274
+ */
275
+ function blockFor(
276
+ graph: SceneGraph,
277
+ nodeId: string,
278
+ depth: number,
279
+ maxBytes: number
280
+ ): { css: string; truncated?: true; omitted?: number } {
281
+ const lines: string[] = []
282
+ const budget: Budget = { bytes: 0, limit: maxBytes, truncated: false }
283
+ collect(graph, nodeId, depth, '', lines, budget)
284
+ if (!budget.truncated) return { css: lines.join('\n') }
285
+ // Every visible node either has a line or is left out, so the omitted count follows from the
286
+ // node total. Each dropped line's byte count includes the newline collect charged for it.
287
+ let omitted = countVisible(graph, nodeId) - lines.length
288
+ while (
289
+ lines.length > 1 &&
290
+ budget.bytes + 1 + utf8Length(truncationTail(omitted)) > budget.limit
291
+ ) {
292
+ const last = lines.pop()
293
+ if (last === undefined) break
294
+ budget.bytes -= utf8Length(last) + 1
295
+ omitted = countVisible(graph, nodeId) - lines.length
296
+ }
297
+ if (lines.length === 0) {
298
+ return { css: '', truncated: true, omitted: countVisible(graph, nodeId) }
299
+ }
300
+ const head = lines.join('\n')
301
+ if (budget.bytes + 1 + utf8Length(truncationTail(omitted)) > budget.limit) {
302
+ return { css: head, truncated: true, omitted }
303
+ }
304
+ return { css: `${head}\n${truncationTail(omitted)}`, truncated: true, omitted }
305
+ }
306
+
307
+ export const getCSS = defineTool({
308
+ name: 'get_css',
309
+ description:
310
+ 'Read a node subtree as compact CSS-like lines: `Name#id W×H {flex:row;gap:12px;padding:16px 24px;bg:var(--color/brand, #4F46E5);radius:8px}`. ' +
311
+ 'Lengths are px; short names: flex (implies display:flex), gap, padding, justify, items, wrap, hug, stretch, grow, bg, border, radius, min/max-w/h, shadow, blur, opacity, clip; text: `font:600 14px/20px Inter`, color, text-align, max-lines. ' +
312
+ "Colours follow the document's profile, as get_jsx writes them: `#RRGGBB` in an sRGB document, `color(display-p3 r g b)` in a Display P3 one, and either inside the `var()` fallback. " +
313
+ 'Use it for geometry and style; describe gives roles and design issues. The setters accept the same shorthand (padding/gap/radius strings, `var(--token)` colours).',
314
+ execution: { kind: 'sync', mutation: 'none' },
315
+ input: v.strictObject({
316
+ id: v.optional(v.pipe(v.string(), v.description('Node ID (single node)'))),
317
+ ids: nodeIdsField('Node IDs (several nodes in one call)'),
318
+ depth: v.optional(
319
+ toolNumber(
320
+ v.pipe(
321
+ v.number(),
322
+ v.description('Child levels to include (default: as many as the budget holds)')
323
+ )
324
+ )
325
+ ),
326
+ max_bytes: v.optional(
327
+ toolNumber(
328
+ v.pipe(v.number(), v.description('Byte budget for the reply (default 6000, max 20000)'))
329
+ )
330
+ )
331
+ }),
332
+ execute: (figma, args) => {
333
+ const maxBytes = Math.min(args.max_bytes ?? DEFAULT_MAX_BYTES, HARD_MAX_BYTES)
334
+ const depth = args.depth ?? 100
335
+
336
+ if (args.ids && Array.isArray(args.ids)) {
337
+ const blocks: string[] = []
338
+ let omitted = 0
339
+ let truncated = false
340
+ let used = 0
341
+ for (const nodeId of args.ids) {
342
+ if (!figma.graph.getNode(nodeId)) return { error: `Node "${nodeId}" not found` }
343
+ const separator = blocks.length === 0 ? 0 : 1
344
+ const block = blockFor(figma.graph, nodeId, depth, maxBytes - used - separator)
345
+ if (block.css === '') {
346
+ omitted += block.omitted ?? 0
347
+ truncated = truncated || block.truncated === true
348
+ continue
349
+ }
350
+ blocks.push(block.css)
351
+ used += utf8Length(block.css) + separator
352
+ omitted += block.omitted ?? 0
353
+ truncated = truncated || block.truncated === true
354
+ }
355
+ const css = blocks.join('\n')
356
+ if (!truncated) return { ids: args.ids, css }
357
+ return { ids: args.ids, css, truncated: true, omitted }
358
+ }
359
+
360
+ if (!args.id) return { error: 'Provide id (string) or ids (string[])' }
361
+ if (!figma.graph.getNode(args.id)) return { error: `Node "${args.id}" not found` }
362
+ const block = blockFor(figma.graph, args.id, depth, maxBytes)
363
+ return { id: args.id, ...block }
364
+ }
365
+ })
@@ -7,8 +7,9 @@ export const getReactions = defineTool({
7
7
 
8
8
  description:
9
9
  "Get the prototype connections on a layer, in Figma's plugin shape: each trigger and its " +
10
- 'actions, with a NODE action naming the destination frame. Empty when the layer connects ' +
11
- 'to nothing.',
10
+ 'actions, with a NODE action naming the destination frame or variant. A Change to authored ' +
11
+ 'by variant properties reads back as the destination variant id. Empty when the layer ' +
12
+ 'connects to nothing.',
12
13
  execution: { kind: 'sync', mutation: 'none' },
13
14
  input: v.strictObject({
14
15
  id: nodeIdInputSchema
@@ -5,7 +5,6 @@ import { getAxisAlignedBoundsInParent } from '@pairdraw/scene-graph/coordinate'
5
5
  import { computeBounds } from '@pairdraw/scene-graph/geometry'
6
6
  import type { Rect } from '@pairdraw/scene-graph/primitives'
7
7
 
8
- import { flushPendingLayout } from '#core/figma-api'
9
8
  import { findPageId } from '#core/io/subgraph'
10
9
  import { defineTool, toolNumber } from '#core/tools/schema'
11
10
 
@@ -176,7 +175,6 @@ export const findEmptySpaceTool = defineTool({
176
175
  if (args.near_id && nearParentId !== parentId) {
177
176
  return { error: `Node "${args.near_id}" is not a child of "${parentId}"` }
178
177
  }
179
- flushPendingLayout(graph)
180
178
  const obstacles = childBoxes(graph, parentId)
181
179
  const near = args.near_id ? graph.getNode(args.near_id) : undefined
182
180
  let anchor = obstacles.length > 0 ? computeBounds(obstacles) : null
package/src/tools/read.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { getComponents } from './read/components'
2
+ export { getCSS } from './read/css'
2
3
  export { insertLibraryComponent, listLibraries } from './read/libraries'
3
4
  export { getFontStatus, listAvailableFonts, listFonts } from './read/fonts'
4
5
  export { diffJSX, getJSX } from './read/jsx'
@@ -13,14 +13,14 @@ import {
13
13
  setTextProperties,
14
14
  updateNode
15
15
  } from '#core/tools/modify'
16
- import { diffJSX, findNodes, getJSX, getNode, getSelection } from '#core/tools/read'
16
+ import { diffJSX, findNodes, getCSS, getJSX, getNode, getSelection } from '#core/tools/read'
17
17
  import type { ToolDef } from '#core/tools/schema'
18
18
  import { stockPhoto } from '#core/tools/stock-photo'
19
19
  import { batchUpdate, deleteNode, nodeResize, reparentNode } from '#core/tools/structure'
20
20
  import { viewportZoomToFit } from '#core/tools/vector'
21
21
 
22
22
  /**
23
- * Core tools registered by default in AI chat (27 tools, ~5K schema tokens).
23
+ * Core tools registered by default in AI chat (28 tools, ~5K schema tokens).
24
24
  * Covers 90%+ of design sessions: render, describe, modify, structure, and diff checks.
25
25
  */
26
26
  export const CORE_TOOLS: ToolDef[] = [
@@ -29,6 +29,7 @@ export const CORE_TOOLS: ToolDef[] = [
29
29
  getNode,
30
30
  findNodes,
31
31
  getJSX,
32
+ getCSS,
32
33
  // Create
33
34
  render,
34
35
  // Modify