@pairdraw/core 0.20.0 → 0.21.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 (517) 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/effect.d.ts.map +1 -1
  43. package/dist/canvas/shaders/effect.js +2 -1
  44. package/dist/canvas/shaders/effect.js.map +1 -1
  45. package/dist/canvas/shadows/shape.d.ts.map +1 -1
  46. package/dist/canvas/shadows/shape.js +4 -2
  47. package/dist/canvas/shadows/shape.js.map +1 -1
  48. package/dist/canvas/shadows.d.ts.map +1 -1
  49. package/dist/canvas/shadows.js +4 -2
  50. package/dist/canvas/shadows.js.map +1 -1
  51. package/dist/canvas/text/decorations.d.ts +2 -2
  52. package/dist/canvas/text/decorations.d.ts.map +1 -1
  53. package/dist/canvas/text/decorations.js +5 -5
  54. package/dist/canvas/text/decorations.js.map +1 -1
  55. package/dist/canvas/text/index.js +1 -1
  56. package/dist/canvas/text/index.js.map +1 -1
  57. package/dist/canvas/text/paragraph/index.d.ts +2 -2
  58. package/dist/canvas/text/paragraph/index.d.ts.map +1 -1
  59. package/dist/canvas/text/paragraph/index.js +16 -5
  60. package/dist/canvas/text/paragraph/index.js.map +1 -1
  61. package/dist/canvas/text/renderer.d.ts +2 -1
  62. package/dist/canvas/text/renderer.d.ts.map +1 -1
  63. package/dist/canvas/text/shape.js +4 -4
  64. package/dist/canvas/text/shape.js.map +1 -1
  65. package/dist/canvas/texture.d.ts.map +1 -1
  66. package/dist/canvas/texture.js +2 -1
  67. package/dist/canvas/texture.js.map +1 -1
  68. package/dist/design-memory/rules.js +1 -1
  69. package/dist/editor/bridges/undo.d.ts +1 -1
  70. package/dist/editor/clipboard/assets.d.ts.map +1 -1
  71. package/dist/editor/clipboard/assets.js +2 -2
  72. package/dist/editor/clipboard/assets.js.map +1 -1
  73. package/dist/editor/clipboard/component-matches.d.ts +13 -0
  74. package/dist/editor/clipboard/component-matches.d.ts.map +1 -0
  75. package/dist/editor/clipboard/component-matches.js +50 -0
  76. package/dist/editor/clipboard/component-matches.js.map +1 -0
  77. package/dist/editor/clipboard/dependencies.d.ts +7 -0
  78. package/dist/editor/clipboard/dependencies.d.ts.map +1 -1
  79. package/dist/editor/clipboard/dependencies.js +5 -0
  80. package/dist/editor/clipboard/dependencies.js.map +1 -1
  81. package/dist/editor/clipboard.d.ts.map +1 -1
  82. package/dist/editor/clipboard.js +48 -19
  83. package/dist/editor/clipboard.js.map +1 -1
  84. package/dist/editor/components/properties.d.ts.map +1 -1
  85. package/dist/editor/components/properties.js +3 -3
  86. package/dist/editor/components/properties.js.map +1 -1
  87. package/dist/editor/create.d.ts +1 -1
  88. package/dist/editor/eyedropper.d.ts +1 -1
  89. package/dist/editor/eyedropper.d.ts.map +1 -1
  90. package/dist/editor/eyedropper.js +6 -3
  91. package/dist/editor/eyedropper.js.map +1 -1
  92. package/dist/editor/history/atomic-tool.d.ts.map +1 -1
  93. package/dist/editor/history/atomic-tool.js +3 -2
  94. package/dist/editor/history/atomic-tool.js.map +1 -1
  95. package/dist/editor/shapes/pencil.js +1 -1
  96. package/dist/editor/structure/state.d.ts.map +1 -1
  97. package/dist/editor/structure/state.js +2 -2
  98. package/dist/editor/structure/state.js.map +1 -1
  99. package/dist/editor/text.d.ts.map +1 -1
  100. package/dist/editor/text.js +2 -2
  101. package/dist/editor/text.js.map +1 -1
  102. package/dist/editor/variables.js +3 -3
  103. package/dist/editor/variables.js.map +1 -1
  104. package/dist/figma-api/fresh-read.d.ts +15 -0
  105. package/dist/figma-api/fresh-read.d.ts.map +1 -0
  106. package/dist/figma-api/fresh-read.js +54 -0
  107. package/dist/figma-api/fresh-read.js.map +1 -0
  108. package/dist/figma-api/graph-ref.d.ts +9 -0
  109. package/dist/figma-api/graph-ref.d.ts.map +1 -0
  110. package/dist/figma-api/graph-ref.js +14 -0
  111. package/dist/figma-api/graph-ref.js.map +1 -0
  112. package/dist/figma-api/index.d.ts +6 -1
  113. package/dist/figma-api/index.d.ts.map +1 -1
  114. package/dist/figma-api/index.js +12 -5
  115. package/dist/figma-api/index.js.map +1 -1
  116. package/dist/figma-api/pending-layout.d.ts +3 -3
  117. package/dist/figma-api/pending-layout.d.ts.map +1 -1
  118. package/dist/figma-api/pending-layout.js +7 -3
  119. package/dist/figma-api/pending-layout.js.map +1 -1
  120. package/dist/figma-api/pending-sync.d.ts +1 -1
  121. package/dist/figma-api/pending-sync.d.ts.map +1 -1
  122. package/dist/figma-api/pending-sync.js +3 -1
  123. package/dist/figma-api/pending-sync.js.map +1 -1
  124. package/dist/figma-api/proxy.d.ts.map +1 -1
  125. package/dist/figma-api/proxy.js +3 -2
  126. package/dist/figma-api/proxy.js.map +1 -1
  127. package/dist/figma-api/reactions.d.ts +20 -4
  128. package/dist/figma-api/reactions.d.ts.map +1 -1
  129. package/dist/figma-api/reactions.js +49 -3
  130. package/dist/figma-api/reactions.js.map +1 -1
  131. package/dist/figma-api/variables/index.d.ts.map +1 -1
  132. package/dist/figma-api/variables/index.js +2 -2
  133. package/dist/figma-api/variables/index.js.map +1 -1
  134. package/dist/io/formats/design-tokens/css/known.js +1 -1
  135. package/dist/io/formats/design-tokens/css/known.js.map +1 -1
  136. package/dist/io/formats/design-tokens/css/read.d.ts +3 -1
  137. package/dist/io/formats/design-tokens/css/read.d.ts.map +1 -1
  138. package/dist/io/formats/design-tokens/css/read.js +11 -5
  139. package/dist/io/formats/design-tokens/css/read.js.map +1 -1
  140. package/dist/io/formats/design-tokens/css/sync.d.ts.map +1 -1
  141. package/dist/io/formats/design-tokens/css/sync.js +17 -4
  142. package/dist/io/formats/design-tokens/css/sync.js.map +1 -1
  143. package/dist/io/formats/design-tokens/css/values.d.ts +6 -5
  144. package/dist/io/formats/design-tokens/css/values.d.ts.map +1 -1
  145. package/dist/io/formats/design-tokens/css/values.js +24 -8
  146. package/dist/io/formats/design-tokens/css/values.js.map +1 -1
  147. package/dist/io/formats/design-tokens/decode.d.ts +7 -6
  148. package/dist/io/formats/design-tokens/decode.d.ts.map +1 -1
  149. package/dist/io/formats/design-tokens/decode.js +13 -12
  150. package/dist/io/formats/design-tokens/decode.js.map +1 -1
  151. package/dist/io/formats/design-tokens/export.js +3 -3
  152. package/dist/io/formats/design-tokens/export.js.map +1 -1
  153. package/dist/io/formats/design-tokens/plan/index.d.ts.map +1 -1
  154. package/dist/io/formats/design-tokens/plan/index.js +4 -3
  155. package/dist/io/formats/design-tokens/plan/index.js.map +1 -1
  156. package/dist/io/formats/design-tokens/plan/styles.d.ts.map +1 -1
  157. package/dist/io/formats/design-tokens/plan/styles.js +9 -9
  158. package/dist/io/formats/design-tokens/plan/styles.js.map +1 -1
  159. package/dist/io/formats/design-tokens/styles.d.ts +4 -4
  160. package/dist/io/formats/design-tokens/styles.d.ts.map +1 -1
  161. package/dist/io/formats/design-tokens/styles.js +7 -7
  162. package/dist/io/formats/design-tokens/styles.js.map +1 -1
  163. package/dist/io/formats/design-tokens/sync/drift.js +2 -2
  164. package/dist/io/formats/design-tokens/sync/drift.js.map +1 -1
  165. package/dist/io/formats/design-tokens/values.d.ts +10 -5
  166. package/dist/io/formats/design-tokens/values.d.ts.map +1 -1
  167. package/dist/io/formats/design-tokens/values.js +13 -7
  168. package/dist/io/formats/design-tokens/values.js.map +1 -1
  169. package/dist/io/formats/drawio/label.js +1 -1
  170. package/dist/io/formats/drawio/paint.js +1 -1
  171. package/dist/io/formats/drawio/warnings.js +2 -2
  172. package/dist/io/formats/drawio/warnings.js.map +1 -1
  173. package/dist/io/formats/fig/export/index.d.ts.map +1 -1
  174. package/dist/io/formats/fig/export/index.js +15 -3
  175. package/dist/io/formats/fig/export/index.js.map +1 -1
  176. package/dist/io/formats/fig/export/patch/index.d.ts.map +1 -1
  177. package/dist/io/formats/fig/export/patch/index.js +2 -1
  178. package/dist/io/formats/fig/export/patch/index.js.map +1 -1
  179. package/dist/io/formats/fig/export/setup.d.ts +7 -2
  180. package/dist/io/formats/fig/export/setup.d.ts.map +1 -1
  181. package/dist/io/formats/fig/export/setup.js +12 -13
  182. package/dist/io/formats/fig/export/setup.js.map +1 -1
  183. package/dist/io/formats/fig/export/variables.d.ts.map +1 -1
  184. package/dist/io/formats/fig/export/variables.js +9 -7
  185. package/dist/io/formats/fig/export/variables.js.map +1 -1
  186. package/dist/io/formats/html/vectors.js +1 -0
  187. package/dist/io/formats/html/vectors.js.map +1 -1
  188. package/dist/io/formats/mermaid/layers.js +2 -2
  189. package/dist/io/formats/mermaid/layers.js.map +1 -1
  190. package/dist/io/formats/mermaid/styles.js +1 -1
  191. package/dist/io/formats/pdf/export.d.ts.map +1 -1
  192. package/dist/io/formats/pdf/export.js +1 -0
  193. package/dist/io/formats/pdf/export.js.map +1 -1
  194. package/dist/io/formats/pdf/prepare.d.ts +4 -4
  195. package/dist/io/formats/pdf/prepare.d.ts.map +1 -1
  196. package/dist/io/formats/pdf/prepare.js +2 -2
  197. package/dist/io/formats/pdf/prepare.js.map +1 -1
  198. package/dist/io/formats/pen/index.js +4 -2
  199. package/dist/io/formats/pen/index.js.map +1 -1
  200. package/dist/io/formats/pptx/style.js +1 -1
  201. package/dist/io/formats/raster/render.d.ts +1 -1
  202. package/dist/io/formats/raster/render.d.ts.map +1 -1
  203. package/dist/io/formats/raster/render.js +9 -4
  204. package/dist/io/formats/raster/render.js.map +1 -1
  205. package/dist/io/formats/svg/defs.d.ts +6 -3
  206. package/dist/io/formats/svg/defs.d.ts.map +1 -1
  207. package/dist/io/formats/svg/defs.js +12 -11
  208. package/dist/io/formats/svg/defs.js.map +1 -1
  209. package/dist/io/formats/svg/effects.js +2 -2
  210. package/dist/io/formats/svg/effects.js.map +1 -1
  211. package/dist/io/formats/svg/export.d.ts +5 -2
  212. package/dist/io/formats/svg/export.d.ts.map +1 -1
  213. package/dist/io/formats/svg/export.js +4 -2
  214. package/dist/io/formats/svg/export.js.map +1 -1
  215. package/dist/io/formats/svg/filter.d.ts +4 -1
  216. package/dist/io/formats/svg/filter.d.ts.map +1 -1
  217. package/dist/io/formats/svg/filter.js +6 -2
  218. package/dist/io/formats/svg/filter.js.map +1 -1
  219. package/dist/io/formats/svg/grain.js +1 -1
  220. package/dist/io/formats/svg/grain.js.map +1 -1
  221. package/dist/io/formats/svg/import.d.ts +4 -2
  222. package/dist/io/formats/svg/import.d.ts.map +1 -1
  223. package/dist/io/formats/svg/import.js +2 -1
  224. package/dist/io/formats/svg/import.js.map +1 -1
  225. package/dist/io/formats/svg/text/export.d.ts.map +1 -1
  226. package/dist/io/formats/svg/text/export.js +8 -8
  227. package/dist/io/formats/svg/text/export.js.map +1 -1
  228. package/dist/io/formats/svg/text/layout.js +2 -2
  229. package/dist/io/formats/svg/text/layout.js.map +1 -1
  230. package/dist/io/formats.d.ts.map +1 -1
  231. package/dist/io/formats.js +1 -0
  232. package/dist/io/formats.js.map +1 -1
  233. package/dist/io/subgraph.d.ts.map +1 -1
  234. package/dist/io/subgraph.js +1 -1
  235. package/dist/io/subgraph.js.map +1 -1
  236. package/dist/io/types.d.ts +1 -1
  237. package/dist/kiwi/fig/session/options.d.ts +3 -0
  238. package/dist/kiwi/fig/session/options.d.ts.map +1 -1
  239. package/dist/kiwi/fig/session/options.js +4 -0
  240. package/dist/kiwi/fig/session/options.js.map +1 -1
  241. package/dist/layout/yoga-helpers.d.ts +2 -1
  242. package/dist/layout/yoga-helpers.d.ts.map +1 -1
  243. package/dist/layout/yoga-helpers.js +7 -1
  244. package/dist/layout/yoga-helpers.js.map +1 -1
  245. package/dist/layout.js +24 -1
  246. package/dist/layout.js.map +1 -1
  247. package/dist/lint/fixes.js +1 -1
  248. package/dist/lint/linter.js +2 -2
  249. package/dist/lint/linter.js.map +1 -1
  250. package/dist/pairdraw-api/comments.d.ts +4 -1
  251. package/dist/pairdraw-api/comments.d.ts.map +1 -1
  252. package/dist/pairdraw-api/comments.js +5 -0
  253. package/dist/pairdraw-api/comments.js.map +1 -1
  254. package/dist/pairdraw-api/index.d.ts +3 -3
  255. package/dist/pairdraw-api/index.d.ts.map +1 -1
  256. package/dist/pairdraw-api/index.js +5 -5
  257. package/dist/pairdraw-api/index.js.map +1 -1
  258. package/dist/pairdraw-api/nodes.d.ts +1 -1
  259. package/dist/prototype/scene.js +1 -1
  260. package/dist/rpc/analyze-commands.js +1 -1
  261. package/dist/rpc/read-commands.d.ts +2 -2
  262. package/dist/rpc/read-commands.js +3 -3
  263. package/dist/rpc/read-commands.js.map +1 -1
  264. package/dist/rpc/variables-command.js +2 -2
  265. package/dist/rpc/variables-command.js.map +1 -1
  266. package/dist/text/font/provider.d.ts +15 -0
  267. package/dist/text/font/provider.d.ts.map +1 -0
  268. package/dist/text/font/provider.js +18 -0
  269. package/dist/text/font/provider.js.map +1 -0
  270. package/dist/text/font/readiness.d.ts +32 -0
  271. package/dist/text/font/readiness.d.ts.map +1 -0
  272. package/dist/text/font/{status.js → readiness.js} +8 -4
  273. package/dist/text/font/readiness.js.map +1 -0
  274. package/dist/text/index.d.ts +4 -3
  275. package/dist/text/index.js +4 -3
  276. package/dist/text/prepare.d.ts +9 -4
  277. package/dist/text/prepare.d.ts.map +1 -1
  278. package/dist/text/prepare.js +9 -4
  279. package/dist/text/prepare.js.map +1 -1
  280. package/dist/tools/analyze/colors.js +1 -1
  281. package/dist/tools/analyze/responsive/index.js +7 -18
  282. package/dist/tools/analyze/responsive/index.js.map +1 -1
  283. package/dist/tools/analyze/responsive/widths.d.ts +27 -0
  284. package/dist/tools/analyze/responsive/widths.d.ts.map +1 -0
  285. package/dist/tools/analyze/responsive/widths.js +49 -0
  286. package/dist/tools/analyze/responsive/widths.js.map +1 -0
  287. package/dist/tools/analyze.d.ts +2 -1
  288. package/dist/tools/analyze.js +2 -1
  289. package/dist/tools/codegen/tokens.d.ts.map +1 -1
  290. package/dist/tools/codegen/tokens.js +2 -2
  291. package/dist/tools/codegen/tokens.js.map +1 -1
  292. package/dist/tools/comments.d.ts.map +1 -1
  293. package/dist/tools/comments.js +2 -2
  294. package/dist/tools/comments.js.map +1 -1
  295. package/dist/tools/component-catalog.d.ts.map +1 -1
  296. package/dist/tools/component-catalog.js +5 -3
  297. package/dist/tools/component-catalog.js.map +1 -1
  298. package/dist/tools/create/basic.js +1 -1
  299. package/dist/tools/create/behaviours.js +1 -1
  300. package/dist/tools/create/html.d.ts.map +1 -1
  301. package/dist/tools/create/html.js +1 -3
  302. package/dist/tools/create/html.js.map +1 -1
  303. package/dist/tools/create/icons.js +2 -2
  304. package/dist/tools/create/icons.js.map +1 -1
  305. package/dist/tools/create/mermaid.js +1 -1
  306. package/dist/tools/create/render.js +1 -1
  307. package/dist/tools/create/svg.js +5 -2
  308. package/dist/tools/create/svg.js.map +1 -1
  309. package/dist/tools/create/vector.js +3 -3
  310. package/dist/tools/create/vector.js.map +1 -1
  311. package/dist/tools/css/shorthand.d.ts +20 -0
  312. package/dist/tools/css/shorthand.d.ts.map +1 -0
  313. package/dist/tools/css/shorthand.js +54 -0
  314. package/dist/tools/css/shorthand.js.map +1 -0
  315. package/dist/tools/describe/index.js +2 -2
  316. package/dist/tools/describe/index.js.map +1 -1
  317. package/dist/tools/describe/issues.js +1 -1
  318. package/dist/tools/html-host.d.ts.map +1 -1
  319. package/dist/tools/html-host.js +5 -3
  320. package/dist/tools/html-host.js.map +1 -1
  321. package/dist/tools/image-ai/apply.d.ts.map +1 -1
  322. package/dist/tools/image-ai/apply.js +1 -3
  323. package/dist/tools/image-ai/apply.js.map +1 -1
  324. package/dist/tools/image-ai/generate.js +1 -1
  325. package/dist/tools/image-ai/service.d.ts.map +1 -1
  326. package/dist/tools/image-ai/service.js +5 -3
  327. package/dist/tools/image-ai/service.js.map +1 -1
  328. package/dist/tools/index.d.ts +2 -1
  329. package/dist/tools/index.js +2 -1
  330. package/dist/tools/modify/effects.js +1 -1
  331. package/dist/tools/modify/effects.js.map +1 -1
  332. package/dist/tools/modify/geometry.d.ts.map +1 -1
  333. package/dist/tools/modify/geometry.js +14 -3
  334. package/dist/tools/modify/geometry.js.map +1 -1
  335. package/dist/tools/modify/layout.d.ts.map +1 -1
  336. package/dist/tools/modify/layout.js +35 -8
  337. package/dist/tools/modify/layout.js.map +1 -1
  338. package/dist/tools/modify/matching.d.ts.map +1 -1
  339. package/dist/tools/modify/matching.js +10 -10
  340. package/dist/tools/modify/matching.js.map +1 -1
  341. package/dist/tools/modify/paint.d.ts.map +1 -1
  342. package/dist/tools/modify/paint.js +57 -5
  343. package/dist/tools/modify/paint.js.map +1 -1
  344. package/dist/tools/modify/reactions.d.ts.map +1 -1
  345. package/dist/tools/modify/reactions.js +2 -2
  346. package/dist/tools/modify/reactions.js.map +1 -1
  347. package/dist/tools/modify/text.d.ts.map +1 -1
  348. package/dist/tools/modify/text.js +3 -3
  349. package/dist/tools/modify/text.js.map +1 -1
  350. package/dist/tools/prompts/codegen.js +1 -1
  351. package/dist/tools/prompts/codegen.js.map +1 -1
  352. package/dist/tools/read/css.d.ts +14 -0
  353. package/dist/tools/read/css.d.ts.map +1 -0
  354. package/dist/tools/read/css.js +306 -0
  355. package/dist/tools/read/css.js.map +1 -0
  356. package/dist/tools/read/libraries.js +1 -1
  357. package/dist/tools/read/reactions.js +1 -1
  358. package/dist/tools/read/reactions.js.map +1 -1
  359. package/dist/tools/read/space.d.ts.map +1 -1
  360. package/dist/tools/read/space.js +0 -2
  361. package/dist/tools/read/space.js.map +1 -1
  362. package/dist/tools/read.d.ts +2 -1
  363. package/dist/tools/read.js +2 -1
  364. package/dist/tools/registry/core.d.ts +1 -1
  365. package/dist/tools/registry/core.js +3 -1
  366. package/dist/tools/registry/core.js.map +1 -1
  367. package/dist/tools/schema.d.ts +6 -4
  368. package/dist/tools/schema.d.ts.map +1 -1
  369. package/dist/tools/schema.js +9 -5
  370. package/dist/tools/schema.js.map +1 -1
  371. package/dist/tools/script/host.d.ts.map +1 -1
  372. package/dist/tools/script/host.js +5 -3
  373. package/dist/tools/script/host.js.map +1 -1
  374. package/dist/tools/variables/collections.js +1 -1
  375. package/dist/tools/variables/collections.js.map +1 -1
  376. package/dist/tools/variables/values.d.ts.map +1 -1
  377. package/dist/tools/variables/values.js +4 -4
  378. package/dist/tools/variables/values.js.map +1 -1
  379. package/dist/tools/vector/vectorize.d.ts.map +1 -1
  380. package/dist/tools/vector/vectorize.js +6 -4
  381. package/dist/tools/vector/vectorize.js.map +1 -1
  382. package/dist/tools/video-host.d.ts.map +1 -1
  383. package/dist/tools/video-host.js +5 -3
  384. package/dist/tools/video-host.js.map +1 -1
  385. package/dist/vector/vectorize/svg/gradients.d.ts +2 -2
  386. package/dist/vector/vectorize/svg/gradients.d.ts.map +1 -1
  387. package/dist/vector/vectorize/svg/gradients.js +5 -5
  388. package/dist/vector/vectorize/svg/gradients.js.map +1 -1
  389. package/dist/vector/vectorize/svg/to-vectors.d.ts +3 -1
  390. package/dist/vector/vectorize/svg/to-vectors.d.ts.map +1 -1
  391. package/dist/vector/vectorize/svg/to-vectors.js +13 -12
  392. package/dist/vector/vectorize/svg/to-vectors.js.map +1 -1
  393. package/package.json +9 -9
  394. package/src/canvas/noise/render.ts +1 -1
  395. package/src/canvas/noise/shader.ts +13 -5
  396. package/src/canvas/noise/tile.ts +2 -1
  397. package/src/canvas/renderer/colors.ts +76 -50
  398. package/src/canvas/renderer/document-surface.ts +53 -0
  399. package/src/canvas/renderer/fonts.ts +6 -4
  400. package/src/canvas/renderer/lifecycle.ts +4 -4
  401. package/src/canvas/renderer/methods.ts +1 -0
  402. package/src/canvas/renderer/pipeline.ts +21 -3
  403. package/src/canvas/renderer/retained-backing.ts +2 -1
  404. package/src/canvas/renderer/tiles/surface-pool.ts +9 -7
  405. package/src/canvas/renderer.ts +36 -11
  406. package/src/canvas/scene.ts +4 -3
  407. package/src/canvas/shaders/effect.ts +2 -1
  408. package/src/canvas/shadows/shape.ts +4 -2
  409. package/src/canvas/shadows.ts +5 -2
  410. package/src/canvas/text/decorations.ts +15 -5
  411. package/src/canvas/text/index.ts +9 -1
  412. package/src/canvas/text/paragraph/index.ts +16 -6
  413. package/src/canvas/text/renderer.ts +2 -1
  414. package/src/canvas/text/shape.ts +4 -4
  415. package/src/canvas/texture.ts +2 -1
  416. package/src/editor/clipboard/assets.ts +6 -2
  417. package/src/editor/clipboard/component-matches.ts +65 -0
  418. package/src/editor/clipboard/dependencies.ts +22 -1
  419. package/src/editor/clipboard.ts +74 -20
  420. package/src/editor/components/properties.ts +3 -2
  421. package/src/editor/eyedropper.ts +14 -4
  422. package/src/editor/history/atomic-tool.ts +3 -2
  423. package/src/editor/structure/state.ts +2 -1
  424. package/src/editor/text.ts +2 -1
  425. package/src/editor/variables.ts +3 -3
  426. package/src/figma-api/fresh-read.ts +57 -0
  427. package/src/figma-api/graph-ref.ts +13 -0
  428. package/src/figma-api/index.ts +12 -4
  429. package/src/figma-api/pending-layout.ts +7 -3
  430. package/src/figma-api/pending-sync.ts +4 -1
  431. package/src/figma-api/proxy.ts +2 -1
  432. package/src/figma-api/reactions.ts +91 -10
  433. package/src/figma-api/variables/index.ts +5 -4
  434. package/src/io/formats/design-tokens/css/known.ts +1 -1
  435. package/src/io/formats/design-tokens/css/read.ts +20 -7
  436. package/src/io/formats/design-tokens/css/sync.ts +9 -4
  437. package/src/io/formats/design-tokens/css/values.ts +37 -9
  438. package/src/io/formats/design-tokens/decode.ts +17 -12
  439. package/src/io/formats/design-tokens/export.ts +3 -3
  440. package/src/io/formats/design-tokens/plan/index.ts +6 -5
  441. package/src/io/formats/design-tokens/plan/styles.ts +37 -10
  442. package/src/io/formats/design-tokens/styles.ts +10 -7
  443. package/src/io/formats/design-tokens/sync/drift.ts +6 -4
  444. package/src/io/formats/design-tokens/values.ts +15 -8
  445. package/src/io/formats/drawio/warnings.ts +2 -2
  446. package/src/io/formats/fig/export/index.ts +36 -3
  447. package/src/io/formats/fig/export/patch/index.ts +4 -1
  448. package/src/io/formats/fig/export/setup.ts +25 -15
  449. package/src/io/formats/fig/export/variables.ts +17 -6
  450. package/src/io/formats/html/vectors.ts +1 -0
  451. package/src/io/formats/mermaid/layers.ts +2 -2
  452. package/src/io/formats/pdf/export.ts +1 -0
  453. package/src/io/formats/pdf/prepare.ts +6 -6
  454. package/src/io/formats/pen/index.ts +5 -2
  455. package/src/io/formats/raster/render.ts +12 -4
  456. package/src/io/formats/svg/defs.ts +26 -14
  457. package/src/io/formats/svg/effects.ts +2 -2
  458. package/src/io/formats/svg/export.ts +17 -3
  459. package/src/io/formats/svg/filter.ts +12 -2
  460. package/src/io/formats/svg/grain.ts +1 -1
  461. package/src/io/formats/svg/import.ts +6 -3
  462. package/src/io/formats/svg/text/export.ts +10 -8
  463. package/src/io/formats/svg/text/layout.ts +2 -2
  464. package/src/io/formats.ts +8 -1
  465. package/src/io/subgraph.ts +4 -1
  466. package/src/kiwi/fig/session/options.ts +4 -1
  467. package/src/layout/yoga-helpers.ts +8 -0
  468. package/src/layout.ts +47 -1
  469. package/src/lint/linter.ts +1 -1
  470. package/src/pairdraw-api/comments.ts +6 -0
  471. package/src/pairdraw-api/index.ts +7 -9
  472. package/src/rpc/read-commands.ts +4 -4
  473. package/src/rpc/variables-command.ts +2 -2
  474. package/src/text/font/provider.ts +26 -0
  475. package/src/text/font/{status.ts → readiness.ts} +13 -9
  476. package/src/text/index.ts +2 -1
  477. package/src/text/prepare.ts +9 -4
  478. package/src/tools/analyze/responsive/index.ts +8 -15
  479. package/src/tools/analyze/responsive/widths.ts +63 -0
  480. package/src/tools/analyze.ts +2 -0
  481. package/src/tools/codegen/tokens.ts +4 -2
  482. package/src/tools/comments.ts +6 -4
  483. package/src/tools/component-catalog.ts +5 -3
  484. package/src/tools/create/html.ts +0 -3
  485. package/src/tools/create/icons.ts +1 -1
  486. package/src/tools/create/svg.ts +4 -1
  487. package/src/tools/create/vector.ts +2 -2
  488. package/src/tools/css/shorthand.ts +64 -0
  489. package/src/tools/describe/index.ts +2 -8
  490. package/src/tools/html-host.ts +5 -3
  491. package/src/tools/image-ai/apply.ts +0 -2
  492. package/src/tools/image-ai/service.ts +5 -3
  493. package/src/tools/index.ts +2 -0
  494. package/src/tools/modify/effects.ts +1 -1
  495. package/src/tools/modify/geometry.ts +16 -3
  496. package/src/tools/modify/layout.ts +47 -13
  497. package/src/tools/modify/matching.ts +14 -11
  498. package/src/tools/modify/paint.ts +85 -5
  499. package/src/tools/modify/reactions.ts +3 -2
  500. package/src/tools/modify/text.ts +15 -11
  501. package/src/tools/prompts/codegen.md +2 -1
  502. package/src/tools/read/css.ts +365 -0
  503. package/src/tools/read/reactions.ts +3 -2
  504. package/src/tools/read/space.ts +0 -2
  505. package/src/tools/read.ts +1 -0
  506. package/src/tools/registry/core.ts +3 -2
  507. package/src/tools/schema.ts +14 -5
  508. package/src/tools/script/host.ts +6 -3
  509. package/src/tools/variables/collections.ts +1 -1
  510. package/src/tools/variables/values.ts +16 -5
  511. package/src/tools/vector/vectorize.ts +10 -4
  512. package/src/tools/video-host.ts +5 -3
  513. package/src/vector/vectorize/svg/gradients.ts +8 -5
  514. package/src/vector/vectorize/svg/to-vectors.ts +48 -14
  515. package/dist/text/font/status.d.ts +0 -28
  516. package/dist/text/font/status.d.ts.map +0 -1
  517. package/dist/text/font/status.js.map +0 -1
@@ -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
@@ -7,7 +7,7 @@
7
7
 
8
8
  import * as v from 'valibot'
9
9
 
10
- import type { SceneNode } from '@pairdraw/scene-graph'
10
+ import type { DocumentColorSpace, SceneNode } from '@pairdraw/scene-graph'
11
11
  import { tryParseColor } from '@pairdraw/scene-graph/color'
12
12
  import type { Color } from '@pairdraw/scene-graph/primitives'
13
13
 
@@ -328,9 +328,12 @@ export function nodeSummary(node: FigmaNodeProxy): { id: string; name: string; t
328
328
  * used to paint black and report success. Read through `tryParseColor`, since a published schema
329
329
  * cannot express what the parser accepts.
330
330
  */
331
- export function parseToolColor(value: string): Color | { error: string } {
331
+ export function parseToolColor(
332
+ value: string,
333
+ profile: DocumentColorSpace = 'srgb'
334
+ ): Color | { error: string } {
332
335
  return (
333
- tryParseColor(value) ?? {
336
+ tryParseColor(value, profile) ?? {
334
337
  error: `"${value}" is not a color; use a hex value, a color name, or a color function`
335
338
  }
336
339
  )
@@ -341,10 +344,11 @@ export function parseToolColor(value: string): Color | { error: string } {
341
344
  * same refusal `parseToolColor` gives, so each tool does not repeat that check.
342
345
  */
343
346
  export function parseOptionalToolColor(
344
- value: string | undefined
347
+ value: string | undefined,
348
+ profile: DocumentColorSpace = 'srgb'
345
349
  ): { color: Color | undefined } | { error: string } {
346
350
  if (value === undefined) return { color: undefined }
347
- const parsed = parseToolColor(value)
351
+ const parsed = parseToolColor(value, profile)
348
352
  if ('error' in parsed) return parsed
349
353
  return { color: parsed }
350
354
  }
@@ -382,3 +386,8 @@ export function toolNumber(schema: v.GenericSchema<number, number> = v.number())
382
386
  )
383
387
  ])
384
388
  }
389
+
390
+ /** `ids`: several node IDs in one call; the description names what they point at. */
391
+ export function nodeIdsField(description: string) {
392
+ return v.optional(v.pipe(v.array(v.string()), v.minLength(1), v.description(description)))
393
+ }
@@ -1,3 +1,5 @@
1
+ import { underlyingGraph } from '#core/figma-api/graph-ref'
2
+
1
3
  /**
2
4
  * What the `script` tool needs from the host: the sandbox and the node that carries its program
3
5
  * live in the app, so the app registers the runner for the documents it shows. A headless host
@@ -21,12 +23,13 @@ const hosts = new WeakMap<object, ScriptToolHost>()
21
23
 
22
24
  /** Lets the `script` tool run for the documents of `owner`, a document's graph. */
23
25
  export function registerScriptToolHost(owner: object, host: ScriptToolHost): () => void {
24
- hosts.set(owner, host)
26
+ const target = underlyingGraph(owner)
27
+ hosts.set(target, host)
25
28
  return () => {
26
- if (hosts.get(owner) === host) hosts.delete(owner)
29
+ if (hosts.get(target) === host) hosts.delete(target)
27
30
  }
28
31
  }
29
32
 
30
33
  export function getScriptToolHost(owner: object): ScriptToolHost | undefined {
31
- return hosts.get(owner)
34
+ return hosts.get(underlyingGraph(owner))
32
35
  }
@@ -8,7 +8,7 @@ export const listCollections = defineTool({
8
8
  execution: { kind: 'sync', mutation: 'none' },
9
9
  input: v.strictObject({}),
10
10
  execute: (figma) => {
11
- const collections = [...figma.graph.variableCollections.values()]
11
+ const collections = figma.graph.getLiveCollections()
12
12
  return { count: collections.length, collections }
13
13
  }
14
14
  })
@@ -1,6 +1,6 @@
1
1
  import * as v from 'valibot'
2
2
 
3
- import type { VariableType } from '@pairdraw/scene-graph'
3
+ import type { DocumentColorSpace, VariableType } from '@pairdraw/scene-graph'
4
4
  import { tryParseColor } from '@pairdraw/scene-graph/color'
5
5
  import type { Color } from '@pairdraw/scene-graph/primitives'
6
6
 
@@ -14,8 +14,12 @@ function figmaValue(value: ToolValue): FigmaVariableValue {
14
14
 
15
15
  type ToolValue = Color | number | string | boolean
16
16
 
17
- function parseVariableValue(type: VariableType, value: string): ToolValue | null {
18
- if (type === 'COLOR') return tryParseColor(value)
17
+ function parseVariableValue(
18
+ type: VariableType,
19
+ value: string,
20
+ profile: DocumentColorSpace
21
+ ): ToolValue | null {
22
+ if (type === 'COLOR') return tryParseColor(value, profile)
19
23
  if (type === 'FLOAT') return Number(value)
20
24
  if (type === 'BOOLEAN') return value === 'true'
21
25
  return value
@@ -40,7 +44,10 @@ export const createVariable = defineTool({
40
44
  execute: (figma, args) => {
41
45
  const type = args.type
42
46
  // The value is checked first, so a value the variable cannot hold creates nothing.
43
- const value = args.value === undefined ? undefined : parseVariableValue(type, args.value)
47
+ const value =
48
+ args.value === undefined
49
+ ? undefined
50
+ : parseVariableValue(type, args.value, figma.graph.documentColorSpace)
44
51
  if (value === null) return { error: `"${args.value}" is not a ${type} value` }
45
52
  if (typeof value === 'number' && !Number.isFinite(value))
46
53
  return { error: `"${args.value}" is not a number` }
@@ -66,7 +73,11 @@ export const setVariable = defineTool({
66
73
  execute: (figma, args) => {
67
74
  const variable = figma.variables.getVariableById(args.id)
68
75
  if (!variable) return { error: `Variable "${args.id}" not found` }
69
- const parsedValue = parseVariableValue(variable.resolvedType, args.value)
76
+ const parsedValue = parseVariableValue(
77
+ variable.resolvedType,
78
+ args.value,
79
+ figma.graph.documentColorSpace
80
+ )
70
81
  if (parsedValue === null)
71
82
  return { error: `"${args.value}" is not a ${variable.resolvedType} value` }
72
83
  variable.setValueForMode(args.mode, figmaValue(parsedValue))
@@ -1,5 +1,6 @@
1
1
  import * as v from 'valibot'
2
2
 
3
+ import { underlyingGraph } from '#core/figma-api/graph-ref'
3
4
  import { defineTool, nodeIdInputSchema, nodeNotFound, toolFailure } from '#core/tools/schema'
4
5
  import {
5
6
  createVectorFrameBeside,
@@ -25,14 +26,15 @@ const vectorizers = new WeakMap<object, ImageVectorizer>()
25
26
 
26
27
  /** Lets `vectorize_image` run for the documents of `owner`, a document's graph. */
27
28
  export function registerImageVectorizer(owner: object, vectorizer: ImageVectorizer): () => void {
28
- vectorizers.set(owner, vectorizer)
29
+ const target = underlyingGraph(owner)
30
+ vectorizers.set(target, vectorizer)
29
31
  return () => {
30
- if (vectorizers.get(owner) === vectorizer) vectorizers.delete(owner)
32
+ if (vectorizers.get(target) === vectorizer) vectorizers.delete(target)
31
33
  }
32
34
  }
33
35
 
34
36
  export function getImageVectorizer(owner: object): ImageVectorizer | undefined {
35
- return vectorizers.get(owner)
37
+ return vectorizers.get(underlyingGraph(owner))
36
38
  }
37
39
 
38
40
  export const vectorizeImage = defineTool({
@@ -73,7 +75,11 @@ export const vectorizeImage = defineTool({
73
75
  if (!current || vectorizableImageFill(current)?.imageHash !== fill.imageHash) {
74
76
  return { error: `The image of "${node.name}" changed before vectorizing finished` }
75
77
  }
76
- const vectorized = svgToVectorPaths(svg, { width: current.width, height: current.height })
78
+ const vectorized = svgToVectorPaths(
79
+ svg,
80
+ { width: current.width, height: current.height },
81
+ { profile: graph.documentColorSpace }
82
+ )
77
83
  if (!vectorized?.paths.length) return { error: 'The vectorize service returned no paths' }
78
84
  const frameId = createVectorFrameBeside(graph, id, vectorized)
79
85
  const frame = frameId ? graph.getNode(frameId) : undefined
@@ -1,3 +1,4 @@
1
+ import { underlyingGraph } from '#core/figma-api/graph-ref'
1
2
  import type { VideoHostEncoder } from '#core/io/formats/video'
2
3
 
3
4
  const encoders = new WeakMap<object, VideoHostEncoder>()
@@ -7,12 +8,13 @@ const encoders = new WeakMap<object, VideoHostEncoder>()
7
8
  * WebCodecs cannot encode in that host, as the CLI does with ffmpeg. The app needs none.
8
9
  */
9
10
  export function registerVideoEncoder(owner: object, encoder: VideoHostEncoder): () => void {
10
- encoders.set(owner, encoder)
11
+ const target = underlyingGraph(owner)
12
+ encoders.set(target, encoder)
11
13
  return () => {
12
- if (encoders.get(owner) === encoder) encoders.delete(owner)
14
+ if (encoders.get(target) === encoder) encoders.delete(target)
13
15
  }
14
16
  }
15
17
 
16
18
  export function getVideoEncoder(owner: object): VideoHostEncoder | undefined {
17
- return encoders.get(owner)
19
+ return encoders.get(underlyingGraph(owner))
18
20
  }
@@ -9,7 +9,7 @@
9
9
  * normalize into each node's bounding box and build the transform in Figma's convention
10
10
  * (see geometry/gradient).
11
11
  */
12
- import type { Fill, GradientStop } from '@pairdraw/scene-graph'
12
+ import type { DocumentColorSpace, Fill, GradientStop } from '@pairdraw/scene-graph'
13
13
  import { parseColor } from '@pairdraw/scene-graph/color'
14
14
  import {
15
15
  ellipticalGradientTransform,
@@ -59,12 +59,12 @@ function coord(value: string | null, fallback: number): number {
59
59
  return Number.isFinite(n) ? n : fallback
60
60
  }
61
61
 
62
- function readStops(gradient: SVGElementLike): RawStop[] {
62
+ function readStops(gradient: SVGElementLike, profile: DocumentColorSpace): RawStop[] {
63
63
  const stops: RawStop[] = []
64
64
  const stopEls = Array.from(gradient.getElementsByTagName('stop'))
65
65
  for (const [i, stop] of stopEls.entries()) {
66
66
  const offset = coord(stop.getAttribute('offset'), i === 0 ? 0 : 1)
67
- const color = parseColor(stop.getAttribute('stop-color') ?? '#000000')
67
+ const color = parseColor(stop.getAttribute('stop-color') ?? '#000000', profile)
68
68
  const opacity = stop.getAttribute('stop-opacity')
69
69
  if (opacity != null) {
70
70
  const a = Number.parseFloat(opacity)
@@ -80,7 +80,10 @@ function readStops(gradient: SVGElementLike): RawStop[] {
80
80
  * (no hand-rolled markup parsing). Returns an empty map on parse failure so a
81
81
  * malformed SVG simply falls back to solid fills.
82
82
  */
83
- export function parseSVGGradients(svg: string): Map<string, ParsedGradient> {
83
+ export function parseSVGGradients(
84
+ svg: string,
85
+ profile: DocumentColorSpace = 'srgb'
86
+ ): Map<string, ParsedGradient> {
84
87
  const map = new Map<string, ParsedGradient>()
85
88
  const doc: SVGQueryable | null = parseSVGDocument(svg)
86
89
  if (!doc) return map
@@ -100,7 +103,7 @@ export function parseSVGGradients(svg: string): Map<string, ParsedGradient> {
100
103
  kind,
101
104
  units,
102
105
  transform: el.getAttribute('gradientTransform'),
103
- stops: readStops(el),
106
+ stops: readStops(el, profile),
104
107
  x1: coord(el.getAttribute('x1'), 0),
105
108
  y1: coord(el.getAttribute('y1'), 0),
106
109
  x2: coord(el.getAttribute('x2'), units === 'objectBoundingBox' ? 1 : 0),