@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
@@ -5,6 +5,8 @@ import { CommittedGraphEventError, type SceneNode } from '@pairdraw/scene-graph'
5
5
  import { attachedConnectors } from '@pairdraw/scene-graph/connectors'
6
6
  import { getAxisAlignedBoundsInParent, getNodeLocalMatrix } from '@pairdraw/scene-graph/coordinate'
7
7
  import { cycleSafeParent, recordInstanceOverride } from '@pairdraw/scene-graph/instances'
8
+ import { ownInstanceOverrides } from '@pairdraw/scene-graph/instances/overrides'
9
+ import { PAIRDRAW_PLUGIN_DATA, withPluginData } from '@pairdraw/scene-graph/plugin-data'
8
10
  import type { Rect, Vector } from '@pairdraw/scene-graph/primitives'
9
11
  import { slotPropertyId } from '@pairdraw/scene-graph/slots'
10
12
  import { keepPastedBoundPaints, type AppliedBoundPaints } from '@pairdraw/scene-graph/variables'
@@ -57,6 +59,10 @@ type PasteOptions = {
57
59
  type PasteNodesOptions = PasteOptions & {
58
60
  /** Resolve the pasted layers' variable bindings where they land, before history records them. */
59
61
  resolveBindings?: boolean
62
+ /** Components this document already has for the snapshot's dependencies, by dependency id. */
63
+ componentMatches?: Map<string, string>
64
+ /** The copying document's root id, recorded on each dependency a paste creates here. */
65
+ clipboardOrigin?: string
60
66
  }
61
67
 
62
68
  /**
@@ -209,7 +215,12 @@ export function createClipboardActions(ctx: EditorContext) {
209
215
  snapshot.sourceRootId === ctx.graph.rootId ? snapshot.appliedBoundPaints : new Map(),
210
216
  dependencies.componentDependencies,
211
217
  cursorPos,
212
- { ...options, resolveBindings: dependencies.resolveBindings }
218
+ {
219
+ ...options,
220
+ resolveBindings: dependencies.resolveBindings,
221
+ componentMatches: dependencies.componentMatches,
222
+ clipboardOrigin: dependencies.clipboardOrigin
223
+ }
213
224
  )
214
225
  })
215
226
  await fontActions.loadFontsForNodes(created)
@@ -340,16 +351,46 @@ export function createClipboardActions(ctx: EditorContext) {
340
351
  const instanceTargets = instanceReplacementTargets(options)
341
352
  for (const [hash, bytes] of images) ctx.graph.images.set(hash, bytes)
342
353
 
354
+ const matches = options.componentMatches ?? new Map<string, string>()
343
355
  const created: string[] = []
344
356
  const copiedIds = new Map<string, string>()
345
- const createNodeTree = (source: SceneNode & { children?: SceneNode[] }, parentId: string) => {
346
- const { id: _id, childIds: _childIds, children = [], parentId: _parentId, ...rest } = source
357
+ const pastedIds = new Set<string>()
358
+ // A dependency this document already has keeps its local main; only the roots it creates are
359
+ // this paste's to undo.
360
+ const seedMatches = () => {
361
+ for (const [sourceId, existingId] of matches)
362
+ if (ctx.graph.getNode(existingId)) copiedIds.set(sourceId, existingId)
363
+ }
364
+ seedMatches()
365
+ const createNodeTree = (
366
+ source: SceneNode & { children?: SceneNode[] },
367
+ parentId: string,
368
+ originDocumentId?: string
369
+ ) => {
370
+ const existing = copiedIds.get(source.id)
371
+ if (existing && ctx.graph.getNode(existing)) return existing
372
+ const {
373
+ id: _id,
374
+ childIds: _childIds,
375
+ children = [],
376
+ parentId: _parentId,
377
+ pluginData,
378
+ ...rest
379
+ } = source
380
+ const record = originDocumentId
381
+ ? withPluginData(pluginData, PAIRDRAW_PLUGIN_DATA.clipboardOrigin, {
382
+ documentId: originDocumentId,
383
+ nodeId: source.id
384
+ })
385
+ : pluginData
347
386
  const node = ctx.graph.createNode(source.type, parentId, {
348
387
  ...structuredClone(rest),
388
+ pluginData: structuredClone(record),
349
389
  childIds: []
350
390
  })
351
391
  copiedIds.set(source.id, node.id)
352
- for (const child of children) createNodeTree(child, node.id)
392
+ pastedIds.add(node.id)
393
+ for (const child of children) createNodeTree(child, node.id, originDocumentId)
353
394
  return node.id
354
395
  }
355
396
 
@@ -365,25 +406,38 @@ export function createClipboardActions(ctx: EditorContext) {
365
406
  pastedComponentIds(ctx.graph, [...nodes, ...dependencies])
366
407
  )
367
408
  if (!prepareSlotEdits(ctx, [pasteTarget])) return created
368
- const dependencyRootIds: string[] = []
369
- for (const dependency of dependencies)
370
- dependencyRootIds.push(createNodeTree(dependency, ctx.state.currentPageId))
409
+ const pasteDependencies = () => {
410
+ const roots: string[] = []
411
+ for (const dependency of dependencies) {
412
+ if (copiedIds.has(dependency.id)) continue
413
+ roots.push(createNodeTree(dependency, ctx.state.currentPageId, options.clipboardOrigin))
414
+ }
415
+ return roots
416
+ }
417
+ const dependencyRootIds = pasteDependencies()
371
418
  for (const node of nodes) created.push(createNodeTree(node, pasteTarget))
372
- for (const id of copiedIds.values()) {
373
- const node = ctx.graph.getNode(id)
374
- if (!node) continue
375
- const componentId = node.componentId ? copiedIds.get(node.componentId) : undefined
376
- const instanceOverrides = {
377
- self: node.instanceOverrides.self,
378
- descendants: new Map(
379
- [...node.instanceOverrides.descendants].map(([target, fields]) => [
380
- copiedIds.get(target) ?? target,
381
- fields
382
- ])
383
- )
419
+ const remapPasted = () => {
420
+ for (const id of pastedIds) {
421
+ const node = ctx.graph.getNode(id)
422
+ if (!node) continue
423
+ const componentId = node.componentId ? copiedIds.get(node.componentId) : undefined
424
+ const owned = ownInstanceOverrides(node)
425
+ const instanceOverrides = {
426
+ self: owned.self,
427
+ descendants: new Map(
428
+ [...owned.descendants].map(([target, fields]) => [
429
+ copiedIds.get(target) ?? target,
430
+ fields
431
+ ])
432
+ )
433
+ }
434
+ ctx.graph.updateNode(id, {
435
+ componentId: componentId ?? node.componentId,
436
+ instanceOverrides
437
+ })
384
438
  }
385
- ctx.graph.updateNode(id, { componentId: componentId ?? node.componentId, instanceOverrides })
386
439
  }
440
+ remapPasted()
387
441
  keepPastedBoundPaints(ctx.graph, copiedIds, applied)
388
442
  // Variables of this document can give the layers other values than the copied ones.
389
443
  if (options.resolveBindings) {
@@ -12,6 +12,7 @@ import {
12
12
  } from '@pairdraw/scene-graph/instances'
13
13
  import {
14
14
  cloneInstanceOverrideState,
15
+ ownInstanceOverrides,
15
16
  setInstanceOverride
16
17
  } from '@pairdraw/scene-graph/instances/overrides'
17
18
 
@@ -112,13 +113,13 @@ export function createComponentPropertyActions(
112
113
  if (!componentId) return
113
114
  ctx.graph.swapInstanceComponent(target.node.id, componentId)
114
115
  setInstanceOverride(
115
- instance.instanceOverrides,
116
+ ownInstanceOverrides(instance),
116
117
  instance.id,
117
118
  target.node.id,
118
119
  'sourceComponentId',
119
120
  target.source.id
120
121
  )
121
- ctx.graph.updateNode(instance.id, { instanceOverrides: instance.instanceOverrides })
122
+ ctx.graph.updateNode(instance.id, { instanceOverrides: ownInstanceOverrides(instance) })
122
123
  }
123
124
  }
124
125
 
@@ -7,6 +7,7 @@ import type { Color } from '@pairdraw/scene-graph/primitives'
7
7
  import type { UndoManager } from '@pairdraw/scene-graph/undo'
8
8
 
9
9
  import type { SkiaRenderer } from '#core/canvas/renderer'
10
+ import { documentImageInfo, skColorSpace } from '#core/canvas/renderer/colors'
10
11
  import { getPageColor } from '#core/figma-api/page-backgrounds'
11
12
 
12
13
  /** Which paint of the selection a sampled colour replaces. Alt samples into the stroke. */
@@ -14,7 +15,12 @@ export type EyedropperTarget = 'fill' | 'stroke'
14
15
 
15
16
  type SampleRenderer = Pick<
16
17
  SkiaRenderer,
17
- 'worldViewport' | 'viewportImageRendering' | 'presentationColorSpace' | 'renderNode'
18
+ | 'worldViewport'
19
+ | 'viewportImageRendering'
20
+ | 'presentationColorSpace'
21
+ | 'documentColorSpace'
22
+ | 'surface'
23
+ | 'renderNode'
18
24
  >
19
25
 
20
26
  /** A square of the document's pixels: RGBA rows, `size` pixels a side, the centre one sampled. */
@@ -47,11 +53,13 @@ export function sampleScenePixels(
47
53
  if (!Number.isInteger(size) || size < 1 || size % 2 === 0 || !(scale > 0)) return null
48
54
  const page = graph.getNode(pageId)
49
55
  if (!page) return null
50
- const surface = ck.MakeSurface(size, size)
51
- if (!surface) return null
56
+ const surface = renderer.surface.makeSurface(
57
+ documentImageInfo(ck, graph.documentColorSpace, size, size)
58
+ )
52
59
  const previousViewport = renderer.worldViewport
53
60
  const previousImageRendering = renderer.viewportImageRendering
54
61
  const previousColorSpace = renderer.presentationColorSpace
62
+ const previousDocumentColorSpace = renderer.documentColorSpace
55
63
  try {
56
64
  const canvas = surface.getCanvas()
57
65
  const background = getPageColor(page)
@@ -65,6 +73,7 @@ export function sampleScenePixels(
65
73
  renderer.worldViewport = { x: x - reach, y: y - reach, w: reach * 2, h: reach * 2 }
66
74
  renderer.viewportImageRendering = false
67
75
  renderer.presentationColorSpace = graph.documentColorSpace
76
+ renderer.documentColorSpace = graph.documentColorSpace
68
77
  for (const childId of page.childIds) renderer.renderNode(canvas, graph, childId, {})
69
78
  surface.flush()
70
79
  const data = canvas.readPixels(0, 0, {
@@ -72,7 +81,7 @@ export function sampleScenePixels(
72
81
  height: size,
73
82
  alphaType: ck.AlphaType.Unpremul,
74
83
  colorType: ck.ColorType.RGBA_8888,
75
- colorSpace: ck.ColorSpace.SRGB
84
+ colorSpace: skColorSpace(ck, renderer.documentColorSpace)
76
85
  })
77
86
  if (!(data instanceof Uint8Array) || data.length < size * size * 4) return null
78
87
  return { size, data }
@@ -80,6 +89,7 @@ export function sampleScenePixels(
80
89
  renderer.worldViewport = previousViewport
81
90
  renderer.viewportImageRendering = previousImageRendering
82
91
  renderer.presentationColorSpace = previousColorSpace
92
+ renderer.documentColorSpace = previousDocumentColorSpace
83
93
  surface.dispose()
84
94
  }
85
95
  }
@@ -5,6 +5,7 @@ import type { Editor } from '#core/editor/create'
5
5
  import { ReadOnlyDocumentError } from '#core/editor/read-only'
6
6
  import { resolveEditorProfile, type EditorProfileInputs } from '#core/editor/views'
7
7
  import type { FigmaAPI } from '#core/figma-api'
8
+ import { underlyingGraph } from '#core/figma-api/graph-ref'
8
9
  import { isAtomicTool, type ToolDef } from '#core/tools/schema'
9
10
 
10
11
  import { diffFields, type FieldChanges } from './diff'
@@ -63,10 +64,10 @@ export function executeAtomicTool(
63
64
  if (!isAtomicTool(def)) throw new Error(`Not an atomic tool: ${def.name}`)
64
65
  if (!resolveEditorProfile(editor.state).edits) throw new ReadOnlyDocumentError()
65
66
  options.signal?.throwIfAborted()
66
- if (editor.graph !== figma.graph || options.isLive?.() === false) {
67
+ if (editor.graph !== underlyingGraph(figma.graph) || options.isLive?.() === false) {
67
68
  throw new Error('The target document is no longer open')
68
69
  }
69
- const graph = figma.graph
70
+ const graph = underlyingGraph(figma.graph)
70
71
  if (graph.nodes.size + graph.variables.size > MAX_TRANSACTION_NODES) {
71
72
  throw new Error('Document too large for atomic agent editing (maximum 10000 nodes)')
72
73
  }
@@ -1,6 +1,7 @@
1
1
  import { findInstanceAncestor } from '@pairdraw/scene-graph/instances'
2
2
  import {
3
3
  cloneInstanceOverrideState,
4
+ ownInstanceOverrides,
4
5
  setInstanceOverride
5
6
  } from '@pairdraw/scene-graph/instances/overrides'
6
7
 
@@ -32,7 +33,7 @@ export function createStructureStateActions(ctx: EditorContext) {
32
33
  const forward = () => {
33
34
  const instance = findInstanceAncestor(ctx.graph, id)
34
35
  if (instance)
35
- setInstanceOverride(instance.instanceOverrides, instance.id, id, 'visible', true)
36
+ setInstanceOverride(ownInstanceOverrides(instance), instance.id, id, 'visible', true)
36
37
  show(visible)
37
38
  }
38
39
  forward()
@@ -3,6 +3,7 @@ import { copyDerivedGlyphs, copyGeometryPaths } from '@pairdraw/scene-graph/copy
3
3
  import { faceStyleKey } from '@pairdraw/scene-graph/font-style'
4
4
  import {
5
5
  cloneInstanceOverrideState,
6
+ ownInstanceOverrides,
6
7
  setInstanceOverride,
7
8
  type InstanceOverrideState
8
9
  } from '@pairdraw/scene-graph/instances/overrides'
@@ -102,7 +103,7 @@ function applyTextInstanceOverride(
102
103
  for (const instanceId of instanceIds) {
103
104
  const instance = ctx.graph.getNode(instanceId)
104
105
  if (instance?.type !== 'INSTANCE') continue
105
- setInstanceOverride(instance.instanceOverrides, instance.id, nodeId, 'text', text)
106
+ setInstanceOverride(ownInstanceOverrides(instance), instance.id, nodeId, 'text', text)
106
107
  ctx.graph.updateNode(instance.id, { instanceOverrides: instance.instanceOverrides })
107
108
  }
108
109
  }
@@ -117,15 +117,15 @@ export function createVariableActions(ctx: EditorContext) {
117
117
  }
118
118
 
119
119
  function getCollections() {
120
- return [...ctx.graph.variableCollections.values()]
120
+ return ctx.graph.getLiveCollections()
121
121
  }
122
122
 
123
123
  function getCollectionCount() {
124
- return ctx.graph.variableCollections.size
124
+ return ctx.graph.getLiveCollections().length
125
125
  }
126
126
 
127
127
  function getVariableCount() {
128
- return ctx.graph.variables.size
128
+ return ctx.graph.getLiveVariables().length
129
129
  }
130
130
 
131
131
  function renameCollection(id: string, newName: string) {
@@ -0,0 +1,57 @@
1
+ import type { SceneGraph } from '@pairdraw/scene-graph'
2
+
3
+ import { registerFreshGraph, underlyingGraph } from './graph-ref'
4
+ import { flushPendingLayout } from './pending-layout'
5
+
6
+ /**
7
+ * The graph reads that must see every edit recorded before them. A read added to SceneGraph and not
8
+ * to this list stays stale, so add it here; `satisfies` catches a rename.
9
+ * `getChildren` pays a flush plus an array per call, so a tool looping parents over children should
10
+ * take the raw graph once and read that.
11
+ */
12
+ const FRESH_READS = new Set<PropertyKey>([
13
+ 'getNode',
14
+ 'getChildren',
15
+ 'getPages',
16
+ 'getAllNodes',
17
+ 'flattenTree',
18
+ 'closest',
19
+ 'getAbsolutePosition',
20
+ 'pageOf'
21
+ ] satisfies (keyof SceneGraph)[])
22
+
23
+ const freshGraphs = new WeakMap<SceneGraph, SceneGraph>()
24
+
25
+ /**
26
+ * Lays out and syncs the edits recorded since the last read, then runs `read`. One seam for every
27
+ * surface that reads the graph, so no caller has to flush first.
28
+ */
29
+ export function freshRead<T>(graph: SceneGraph, read: () => T): T {
30
+ flushPendingLayout(underlyingGraph(graph))
31
+ return read()
32
+ }
33
+
34
+ /**
35
+ * The graph as read surfaces see it. A read lays out pending edits first; a write goes straight
36
+ * through, and the writer decides whether an edit depends on a fresh layout.
37
+ */
38
+ export function freshReadGraph(graph: SceneGraph): SceneGraph {
39
+ const cached = freshGraphs.get(graph)
40
+ if (cached) return cached
41
+ const methods = new Map<PropertyKey, (...args: never[]) => unknown>()
42
+ const proxy = new Proxy(graph, {
43
+ get(target, property, receiver) {
44
+ const value = Reflect.get(target, property, receiver)
45
+ if (!FRESH_READS.has(property) || typeof value !== 'function') return value
46
+ let method = methods.get(property)
47
+ if (!method) {
48
+ method = (...args: never[]) => freshRead(target, () => value.apply(target, args))
49
+ methods.set(property, method)
50
+ }
51
+ return method
52
+ }
53
+ })
54
+ freshGraphs.set(graph, proxy)
55
+ registerFreshGraph(proxy, graph)
56
+ return proxy
57
+ }
@@ -0,0 +1,13 @@
1
+ import type { SceneGraph } from '@pairdraw/scene-graph'
2
+
3
+ const rawByProxy = new WeakMap<object, SceneGraph>()
4
+
5
+ /** Remembers the raw graph behind a read-freshening proxy, so pending work keyed by the raw graph is found. */
6
+ export function registerFreshGraph(proxy: SceneGraph, graph: SceneGraph): void {
7
+ rawByProxy.set(proxy, graph)
8
+ }
9
+
10
+ /** The graph pending layout and instance sync are recorded on. */
11
+ export function underlyingGraph<T extends object>(graph: T): T {
12
+ return (rawByProxy.get(graph) as T | undefined) ?? graph
13
+ }
@@ -26,6 +26,7 @@ import { listFigmaFonts } from './fonts/list'
26
26
  import { loadFigmaFont } from './fonts/load'
27
27
  import type { FigmaFontNameInput } from './fonts/names'
28
28
  import { variationAxisTags } from './fonts/variations'
29
+ import { freshReadGraph } from './fresh-read'
29
30
  import * as images from './images'
30
31
  import type {
31
32
  FigmaBooleanOperationNode,
@@ -45,7 +46,7 @@ import type {
45
46
  FigmaVectorNode
46
47
  } from './node-types'
47
48
  import { startPendingLayout } from './pending-layout'
48
- import { flushPendingComponentSync, startPendingComponentSync } from './pending-sync'
49
+ import { startPendingComponentSync } from './pending-sync'
49
50
  import {
50
51
  FigmaNodeProxy,
51
52
  INTERNAL_ID,
@@ -122,6 +123,7 @@ export interface FigmaAPIOptions {
122
123
 
123
124
  export { FigmaNodeProxy } from './proxy'
124
125
  export { getPageBackgrounds, setPageBackgrounds } from './page-backgrounds'
126
+ export { freshRead, freshReadGraph } from './fresh-read'
125
127
  export { flushPendingLayout } from './pending-layout'
126
128
  export { flushPendingComponentSync } from './pending-sync'
127
129
  export type { FigmaEffect } from './effects'
@@ -185,6 +187,10 @@ const clientStorage: ClientStorageAPI = {
185
187
  }
186
188
 
187
189
  export class FigmaAPI implements NodeProxyHost {
190
+ /**
191
+ * The read-freshening proxy. It is not the raw graph, so an identity check against an editor's
192
+ * graph goes through `underlyingGraph`; node internals already hold the raw graph.
193
+ */
188
194
  readonly graph: SceneGraph
189
195
  private _currentPageId: string
190
196
  private _selection: FigmaNodeProxy[] = []
@@ -213,7 +219,7 @@ export class FigmaAPI implements NodeProxyHost {
213
219
  #pageSwitch = 0
214
220
 
215
221
  constructor(graph: SceneGraph, options: FigmaAPIOptions = {}) {
216
- this.graph = graph
222
+ this.graph = freshReadGraph(graph)
217
223
  this.#fetch = options.fetch ?? ((input, init) => fetch(input, init))
218
224
  if (options.loadPage)
219
225
  setPageHost(this, { load: options.loadPage, pageOfNode: options.pageOfNode })
@@ -298,7 +304,6 @@ export class FigmaAPI implements NodeProxyHost {
298
304
  }
299
305
 
300
306
  getNodeById(id: string): FigmaNodeProxy | null {
301
- flushPendingComponentSync(this.graph)
302
307
  const node = this.graph.getNode(id)
303
308
  return node ? this.wrapNode(id) : null
304
309
  }
@@ -400,7 +405,10 @@ export class FigmaAPI implements NodeProxyHost {
400
405
  /** The layers Figma makes from SVG markup, on the current page at its origin. */
401
406
  // eslint-disable-next-line pairdraw/no-mixed-case-acronym-identifiers -- Figma Plugin API name.
402
407
  createNodeFromSvg(svg: string): FigmaFrameNode {
403
- const node = createSVGNodes(this.graph, this._currentPageId, svg, { keepEmpty: true })
408
+ const node = createSVGNodes(this.graph, this._currentPageId, svg, {
409
+ keepEmpty: true,
410
+ profile: this.graph.documentColorSpace
411
+ })
404
412
  if (!node) throw new Error('in createNodeFromSvg: Failed to convert SVG file')
405
413
  return this.wrapNode(node.id) as FigmaFrameNode
406
414
  }
@@ -7,6 +7,7 @@ import {
7
7
 
8
8
  import { createLayoutRunner } from '#core/layout/mutations'
9
9
 
10
+ import { underlyingGraph } from './graph-ref'
10
11
  import { flushPendingComponentSync } from './pending-sync'
11
12
 
12
13
  interface PendingLayout {
@@ -32,7 +33,8 @@ function mergeImpact(into: SceneMutationImpact, from: SceneMutationImpact): void
32
33
  * one recorder for its lifetime, kept across APIs: a script that failed before its tool laid
33
34
  * out its edits leaves them for the next read to lay out.
34
35
  */
35
- export function startPendingLayout(graph: SceneGraph): void {
36
+ export function startPendingLayout(source: SceneGraph): void {
37
+ const graph = underlyingGraph(source)
36
38
  if (pendingByGraph.has(graph)) return
37
39
  const pending: PendingLayout = { impact: createSceneMutationImpact(), flushing: false }
38
40
  pendingByGraph.set(graph, pending)
@@ -41,7 +43,8 @@ export function startPendingLayout(graph: SceneGraph): void {
41
43
  }
42
44
 
43
45
  /** Lays out the edits recorded since the last geometry read. */
44
- export function flushPendingLayout(graph: SceneGraph): void {
46
+ export function flushPendingLayout(source: SceneGraph): void {
47
+ const graph = underlyingGraph(source)
45
48
  // Instances lay out what their components hold now.
46
49
  flushPendingComponentSync(graph)
47
50
  const pending = pendingByGraph.get(graph)
@@ -94,10 +97,11 @@ function editsReach(graph: SceneGraph, impact: SceneMutationImpact, node: SceneN
94
97
  * that builds many layers lays out once rather than once per layer.
95
98
  */
96
99
  export function flushPendingLayoutBefore(
97
- graph: SceneGraph,
100
+ source: SceneGraph,
98
101
  node: SceneNode,
99
102
  { placesChildren = false }: { placesChildren?: boolean } = {}
100
103
  ): void {
104
+ const graph = underlyingGraph(source)
101
105
  const pending = pendingByGraph.get(graph)
102
106
  if (!pending || pending.flushing || pending.impact.changedNodeIds.size === 0) return
103
107
  const depends =
@@ -6,6 +6,8 @@ import {
6
6
 
7
7
  import { syncComponentsHolding } from '#core/editor/component-sync'
8
8
 
9
+ import { underlyingGraph } from './graph-ref'
10
+
9
11
  const syncByGraph = new WeakMap<SceneGraph, () => void>()
10
12
 
11
13
  /**
@@ -53,7 +55,8 @@ export function startPendingComponentSync(graph: SceneGraph, flush?: () => void)
53
55
  * read or written, only when it is in an instance, as only those layers change. Edits inside a
54
56
  * component then sync once, when an instance is next read, not once per edit.
55
57
  */
56
- export function flushPendingComponentSync(graph: SceneGraph, layerId?: string): void {
58
+ export function flushPendingComponentSync(source: SceneGraph, layerId?: string): void {
59
+ const graph = underlyingGraph(source)
57
60
  const flush = syncByGraph.get(graph)
58
61
  if (!flush) return
59
62
  if (layerId !== undefined && !graph.closest(layerId, (node) => node.type === 'INSTANCE')) return
@@ -42,6 +42,7 @@ import { installVisualNodeProxyAccessors } from './accessors/visual'
42
42
  import { installComponentPropertyAccessors } from './components'
43
43
  import { installDevStatusAccessors, type FigmaDevStatusValue } from './dev-status'
44
44
  import type { FigmaFontName } from './fonts/names'
45
+ import { underlyingGraph } from './graph-ref'
45
46
  import type { FigmaFrameNode, FigmaInstanceNode } from './node-types'
46
47
  import { installInstanceOverrideAccessors, type FigmaInstanceOverride } from './overrides'
47
48
  import { getPageBackgrounds, setPageBackgrounds } from './page-backgrounds'
@@ -301,7 +302,7 @@ export class FigmaNodeProxy {
301
302
 
302
303
  constructor(id: string, graph: SceneGraph, api: NodeProxyHost) {
303
304
  this[INTERNAL_ID] = id
304
- this[INTERNAL_GRAPH] = graph
305
+ this[INTERNAL_GRAPH] = underlyingGraph(graph)
305
306
  this[INTERNAL_API] = api
306
307
  const type = graph.getNode(id)?.type
307
308
  const internals = { id: INTERNAL_ID, graph: INTERNAL_GRAPH, api: INTERNAL_API }
@@ -14,6 +14,7 @@ import type {
14
14
  } from '@pairdraw/scene-graph'
15
15
  import { variantSetsAround } from '@pairdraw/scene-graph/components'
16
16
  import { PROTOTYPE_EASINGS } from '@pairdraw/scene-graph/constants'
17
+ import { parseVariantName } from '@pairdraw/scene-graph/variant-name'
17
18
 
18
19
  import { issuePath } from '#core/figma-api/effects'
19
20
  import { asInstanceEdit, sameReaction } from '#core/prototype/reactions'
@@ -60,17 +61,32 @@ const transitionSchema = v.strictObject({
60
61
  easing: v.optional(easingSchema)
61
62
  })
62
63
 
64
+ /** A variant's values for its set's properties, as `{ State: 'Hover', Size: 'Large' }`. */
65
+ const variantPropertiesSchema = v.pipe(
66
+ v.record(v.string(), v.string()),
67
+ v.minEntries(1),
68
+ v.description(
69
+ "CHANGE_TO: the values of the variant to change to, in the layer's nearest component set, " +
70
+ 'such as { State: "Hover" }. Name every property of a set whose variants share values, as ' +
71
+ 'a partial match is refused. Resolved to the variant, so get_reactions reads it back as ' +
72
+ 'a destinationId.'
73
+ )
74
+ )
75
+
63
76
  const nodeActionSchema = v.strictObject({
64
77
  type: v.literal('NODE'),
65
- destinationId: v.pipe(
66
- v.string(),
67
- v.minLength(1),
68
- v.description(
69
- 'NAVIGATE/OVERLAY: a top-level frame on the page; CHANGE_TO: a variant of the set the ' +
70
- "layer is a variant of, an instance of, or inside; SCROLL_TO: a layer in the layer's " +
71
- 'top-level frame.'
78
+ destinationId: v.optional(
79
+ v.pipe(
80
+ v.string(),
81
+ v.minLength(1),
82
+ v.description(
83
+ 'NAVIGATE/OVERLAY: a top-level frame on the page; CHANGE_TO: a variant of the set the ' +
84
+ "layer is a variant of, an instance of, or inside; SCROLL_TO: a layer in the layer's " +
85
+ 'top-level frame. Omit only for CHANGE_TO, and name the variant with variantProperties.'
86
+ )
72
87
  )
73
88
  ),
89
+ variantProperties: v.optional(variantPropertiesSchema),
74
90
  navigation: v.picklist([
75
91
  'NAVIGATE',
76
92
  'OVERLAY',
@@ -211,10 +227,11 @@ function toAction(
211
227
  reactionIndex: number
212
228
  ): PrototypeAction {
213
229
  if (action.type !== 'NODE') return { type: action.type }
214
- assertDestination(action, context, reactionIndex)
230
+ const destinationId = resolveDestinationId(action, context, reactionIndex)
231
+ assertDestination({ ...action, destinationId }, context, reactionIndex)
215
232
  return {
216
233
  type: 'NODE',
217
- nodeId: action.destinationId,
234
+ nodeId: destinationId,
218
235
  navigation: action.navigation,
219
236
  transition: fromFigmaTransition(action.transition),
220
237
  // Only an overlay uses the spot; Figma keeps CENTER on a navigation.
@@ -222,6 +239,70 @@ function toAction(
222
239
  }
223
240
  }
224
241
 
242
+ /**
243
+ * The layer a NODE action points at: its `destinationId`, or for a Change to, the variant of the
244
+ * layer's set whose `variantProperties` it names.
245
+ */
246
+ function resolveDestinationId(
247
+ action: v.InferOutput<typeof nodeActionSchema>,
248
+ context: ReactionContext,
249
+ index: number
250
+ ): string {
251
+ const at = `reactions[${index}]`
252
+ const { destinationId, variantProperties, navigation } = action
253
+ if (destinationId && variantProperties) {
254
+ throw failure(`${at} names both destinationId and variantProperties; give one`)
255
+ }
256
+ if (variantProperties) {
257
+ if (navigation !== 'CHANGE_TO') {
258
+ throw failure(`${at}: variantProperties is for CHANGE_TO only, not ${navigation}`)
259
+ }
260
+ return variantByProperties(variantProperties, context, at)
261
+ }
262
+ if (!destinationId) {
263
+ throw failure(
264
+ navigation === 'CHANGE_TO'
265
+ ? `${at} must name the variant it Changes to, in destinationId or variantProperties`
266
+ : `${at} must name the layer it goes to, in destinationId`
267
+ )
268
+ }
269
+ return destinationId
270
+ }
271
+
272
+ /** The id of the variant of the sets around the layer whose properties are `properties`. */
273
+ function variantByProperties(
274
+ properties: Record<string, string>,
275
+ context: ReactionContext,
276
+ at: string
277
+ ): string {
278
+ const sets = variantSetsAround(context.graph, context.nodeId)
279
+ const nearest = sets.at(0)
280
+ if (!nearest) {
281
+ throw failure(
282
+ `${at}: only a variant, an instance of one, or a layer inside one can Change to another variant`
283
+ )
284
+ }
285
+ const wanted = Object.entries(properties)
286
+ .map(([name, value]) => `${name}=${value}`)
287
+ .join(', ')
288
+ for (const set of sets) {
289
+ const matches = context.graph.getChildren(set.id).filter((child) => {
290
+ if (child.type !== 'COMPONENT') return false
291
+ const values = { ...parseVariantName(child.name), ...child.componentPropertyValues }
292
+ return Object.entries(properties).every(([name, value]) => values[name] === value)
293
+ })
294
+ if (matches.length === 1) return matches[0].id
295
+ // A set can hold variants a partial map matches equally: refuse rather than pick one.
296
+ if (matches.length > 1) {
297
+ const names = matches.map((match) => `"${match.name}"`).join(', ')
298
+ throw failure(
299
+ `${at}: ${wanted} matches ${matches.length} variants of ${set.name} (${names}); name every property of the variant`
300
+ )
301
+ }
302
+ }
303
+ throw failure(`${at}: no variant of ${nearest.name} with ${wanted}`)
304
+ }
305
+
225
306
  function failure(message: string): Error {
226
307
  return new Error(`Property "reactions" failed validation: ${message}`)
227
308
  }
@@ -232,7 +313,7 @@ function failure(message: string): Error {
232
313
  * top-level frame.
233
314
  */
234
315
  function assertDestination(
235
- action: v.InferOutput<typeof nodeActionSchema>,
316
+ action: Pick<v.InferOutput<typeof nodeActionSchema>, 'navigation'> & { destinationId: string },
236
317
  context: ReactionContext,
237
318
  index: number
238
319
  ): void {