@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
@@ -228,7 +228,15 @@ export function buildTextPicture(r: TextRenderer, node: SceneNode): Uint8Array |
228
228
  const layout = buildParagraph(r, node)
229
229
  const paint = new ck.Paint()
230
230
  try {
231
- drawTextLayout(ck, recCanvas, node, { paragraph: layout }, 0, paint)
231
+ drawTextLayout(
232
+ ck,
233
+ recCanvas,
234
+ node,
235
+ { paragraph: layout },
236
+ 0,
237
+ paint,
238
+ r.documentColorSpace ?? 'srgb'
239
+ )
232
240
  } finally {
233
241
  paint.delete()
234
242
  layout.delete()
@@ -9,8 +9,8 @@ import type {
9
9
  TextHeightBehavior
10
10
  } from 'canvaskit-wasm'
11
11
 
12
- import type { SceneNode } from '@pairdraw/scene-graph'
13
- import { resolveRGBAForPreview } from '@pairdraw/scene-graph/color'
12
+ import type { ColorProfile, SceneNode } from '@pairdraw/scene-graph'
13
+ import { normalizeColor, toExtendedSRGB } from '@pairdraw/scene-graph/color'
14
14
  import { faceStyleKey, type NamedFace } from '@pairdraw/scene-graph/font-style'
15
15
  import { rangeFontStyle } from '@pairdraw/scene-graph/shared-styles'
16
16
  import { lineHeightPixels, textLengthPixels } from '@pairdraw/scene-graph/text'
@@ -152,14 +152,24 @@ function drawnFontStyle(
152
152
  export function styleRunColor(
153
153
  ck: CanvasKit,
154
154
  style: SceneNode['styleRuns'][number]['style'],
155
- baseColor: Float32Array
155
+ baseColor: Float32Array,
156
+ space: ColorProfile
156
157
  ): Float32Array {
157
158
  const visibleFill = style.fills?.find((fill) => fill.visible && fill.type === 'SOLID')
158
159
  if (!visibleFill) return baseColor
159
- const color = resolveRGBAForPreview(visibleFill.color).color
160
+ const color = toExtendedSRGB(normalizeColor(visibleFill.color), space)
160
161
  return ck.Color4f(color.r, color.g, color.b, color.a * visibleFill.opacity)
161
162
  }
162
163
 
164
+ /**
165
+ * A text style's color. CanvasKit keeps `color` in 8-bit sRGB, which clips a wide-gamut color, and
166
+ * draws `foregroundColor` with float components, so both carry it; a pushed foreground paint, as a
167
+ * gradient fill draws with, still takes their place.
168
+ */
169
+ function textColor(color: Float32Array) {
170
+ return { color, foregroundColor: color }
171
+ }
172
+
163
173
  function styleRunLanguage(
164
174
  style: SceneNode['styleRuns'][number]['style'],
165
175
  node: Pick<ParagraphNode, 'textLanguage'>
@@ -197,7 +207,7 @@ function pushStyleRun(
197
207
  const runKey = faceStyleKey(runFace)
198
208
 
199
209
  const textStyle = new ck.TextStyle({
200
- color: styleRunColor(ck, style, baseColor),
210
+ ...textColor(styleRunColor(ck, style, baseColor, r.documentColorSpace ?? 'srgb')),
201
211
  fontFamilies: fontFamilies(runFamily, runFace),
202
212
  fontSize: runFontSize,
203
213
  locale: styleRunLanguage(style, node),
@@ -310,7 +320,7 @@ export function buildSkParagraph(
310
320
  const nodeKey = faceStyleKey(node)
311
321
 
312
322
  const baseTextStyle = {
313
- color: baseColor,
323
+ ...textColor(baseColor),
314
324
  fontFamilies: fontFamilies(node.fontFamily || DEFAULT_FONT_FAMILY, node),
315
325
  fontSize: baseFontSize,
316
326
  locale: node.textLanguage ?? undefined,
@@ -1,6 +1,6 @@
1
1
  import type { CanvasKit, TypefaceFontProvider } from 'canvaskit-wasm'
2
2
 
3
- import type { SceneNode } from '@pairdraw/scene-graph'
3
+ import type { ColorProfile, SceneNode } from '@pairdraw/scene-graph'
4
4
 
5
5
  import type { FontResolutionSettled } from '#core/text/resolver'
6
6
 
@@ -19,6 +19,7 @@ export interface FontReadinessRenderer {
19
19
 
20
20
  export interface TextRenderer extends FontReadinessRenderer {
21
21
  ck: CanvasKit
22
+ documentColorSpace?: ColorProfile
22
23
  fontProvider: TypefaceFontProvider | null
23
24
  fontsLoaded: boolean
24
25
  }
@@ -20,8 +20,8 @@ import { getCanvasKit } from '#core/canvaskit'
20
20
  import { shownText } from '#core/text/case'
21
21
  import { EMOJI_METRICS_FAMILY } from '#core/text/emoji'
22
22
  import type { OutlineCommand } from '#core/text/font/glyphs'
23
- import { fontManager } from '#core/text/font/manager'
24
23
  import { faceStyleName } from '#core/text/font/names'
24
+ import { leaseFontProvider } from '#core/text/font/provider'
25
25
  import { nextGraphemeBoundary } from '#core/text/graphemes'
26
26
 
27
27
  /**
@@ -205,11 +205,11 @@ export async function withTextShaper<T>(
205
205
  canvasKit: CanvasKit,
206
206
  use: (shape: (node: SceneNode) => ShapedText | null) => Promise<T>
207
207
  ): Promise<T> {
208
- const provider = fontManager.acquireProvider(canvasKit)
208
+ const lease = leaseFontProvider(canvasKit)
209
209
  try {
210
- return await use((node) => shapeText(canvasKit, provider, node))
210
+ return await use((node) => shapeText(canvasKit, lease.provider, node))
211
211
  } finally {
212
- fontManager.releaseProvider(provider)
212
+ lease.release()
213
213
  }
214
214
  }
215
215
 
@@ -4,6 +4,7 @@ import type { SceneNode, TextureEffect } from '@pairdraw/scene-graph'
4
4
 
5
5
  import { cellValue } from './noise/tile'
6
6
  import type { SkiaRenderer } from './renderer'
7
+ import { skColorSpace } from './renderer/colors'
7
8
 
8
9
  /** Cells on each side of a texture's displacement tile; it repeats beyond them. */
9
10
  const TEXTURE_TILE_CELLS = 256
@@ -67,7 +68,7 @@ export function textureDisplacementTile(
67
68
  height: TEXTURE_TILE_CELLS,
68
69
  alphaType: r.ck.AlphaType.Unpremul,
69
70
  colorType: r.ck.ColorType.RGBA_8888,
70
- colorSpace: r.ck.ColorSpace.SRGB
71
+ colorSpace: skColorSpace(r.ck, r.documentColorSpace)
71
72
  },
72
73
  pixels,
73
74
  TEXTURE_TILE_CELLS * 4
@@ -74,7 +74,9 @@ export function createClipboardAssetActions(
74
74
 
75
75
  async function prepareAsset(file: File): Promise<PreparedAsset | null> {
76
76
  if (isSVGFile(file)) {
77
- const data = prepareSVGImport(await file.text())
77
+ const data = prepareSVGImport(await file.text(), {
78
+ profile: ctx.graph.documentColorSpace
79
+ })
78
80
  return data
79
81
  ? {
80
82
  kind: 'svg',
@@ -181,7 +183,9 @@ export function createClipboardAssetActions(
181
183
 
182
184
  /** Paste SVG markup as layers, as Figma does; false when the text is not SVG. */
183
185
  async function pasteSVG(markup: string, cx: number, cy: number): Promise<boolean> {
184
- const data = isSVGMarkup(markup) ? prepareSVGImport(markup) : null
186
+ const data = isSVGMarkup(markup)
187
+ ? prepareSVGImport(markup, { profile: ctx.graph.documentColorSpace })
188
+ : null
185
189
  if (!data) return false
186
190
  const asset: PreparedAsset = { kind: 'svg', data, width: data.width, height: data.height }
187
191
  await loadSVGFonts([asset])
@@ -0,0 +1,65 @@
1
+ import type { SceneGraph } from '@pairdraw/scene-graph'
2
+ import { PAIRDRAW_PLUGIN_DATA, readPluginData } from '@pairdraw/scene-graph/plugin-data'
3
+
4
+ import { collectSubtrees } from '#core/editor/history/subtree'
5
+
6
+ import type { ClipboardNodeTree } from './snapshot'
7
+
8
+ /**
9
+ * The component or set already in this document that a snapshot's dependency becomes, when the
10
+ * dependency came from here before. A node a paste created carries its clipboard origin, and a
11
+ * component read from a `.fig` carries the source identity Figma stores; names are never compared,
12
+ * so an unrelated same-named component is never reused.
13
+ */
14
+ export function matchClipboardComponents(
15
+ graph: SceneGraph,
16
+ sourceRootId: string,
17
+ dependencies: ClipboardNodeTree[]
18
+ ): Map<string, string> {
19
+ const roots = [...graph.getAllNodes()].filter(
20
+ (node) => node.type === 'COMPONENT' || node.type === 'COMPONENT_SET'
21
+ )
22
+ const byOrigin = new Map<string, string>()
23
+ const bySource = new Map<string, string>()
24
+ const byKey = new Map<string, string>()
25
+ for (const root of roots) {
26
+ const origin = readPluginData(root.pluginData, PAIRDRAW_PLUGIN_DATA.clipboardOrigin)
27
+ if (origin?.documentId === sourceRootId) byOrigin.set(origin.nodeId, root.id)
28
+ if (root.source.id) bySource.set(root.source.id, root.id)
29
+ for (const key of [root.sourceLibraryKey, root.componentKey])
30
+ if (key && !byKey.has(key)) byKey.set(key, root.id)
31
+ }
32
+ const matches = new Map<string, string>()
33
+ const matchedRoots = new Set<string>()
34
+
35
+ const mapExistingChildren = (dependency: ClipboardNodeTree, existingRootId: string) => {
36
+ const byChildOrigin = new Map<string, string>()
37
+ const byChildSource = new Map<string, string>()
38
+ for (const node of collectSubtrees(graph, [existingRootId])) {
39
+ const origin = readPluginData(node.pluginData, PAIRDRAW_PLUGIN_DATA.clipboardOrigin)
40
+ if (origin?.documentId === sourceRootId) byChildOrigin.set(origin.nodeId, node.id)
41
+ if (node.source.id) byChildSource.set(node.source.id, node.id)
42
+ }
43
+ const visit = (node: ClipboardNodeTree) => {
44
+ const existing =
45
+ byChildOrigin.get(node.id) ??
46
+ (node.source.id ? byChildSource.get(node.source.id) : undefined)
47
+ if (existing) matches.set(node.id, existing)
48
+ for (const child of node.children ?? []) visit(child)
49
+ }
50
+ for (const child of dependency.children ?? []) visit(child)
51
+ }
52
+
53
+ for (const dependency of dependencies) {
54
+ const existing =
55
+ byOrigin.get(dependency.id) ??
56
+ (dependency.sourceLibraryKey ? byKey.get(dependency.sourceLibraryKey) : undefined) ??
57
+ (dependency.componentKey ? byKey.get(dependency.componentKey) : undefined) ??
58
+ (dependency.source.id ? bySource.get(dependency.source.id) : undefined)
59
+ if (!existing || matchedRoots.has(existing)) continue
60
+ matchedRoots.add(existing)
61
+ matches.set(dependency.id, existing)
62
+ mapExistingChildren(dependency, existing)
63
+ }
64
+ return matches
65
+ }
@@ -3,6 +3,7 @@ import { numberedName } from '@pairdraw/scene-graph/naming'
3
3
 
4
4
  import type { EditorContext } from '#core/editor/types'
5
5
 
6
+ import { matchClipboardComponents } from './component-matches'
6
7
  import {
7
8
  addsRenamed,
8
9
  matchClipboardCollections,
@@ -18,6 +19,13 @@ import { importClipboardVariables, remapClipboardVariableBindings } from './vari
18
19
  export interface ClipboardDependencyImport {
19
20
  nodes: ClipboardSnapshot['nodes']
20
21
  componentDependencies: ClipboardSnapshot['componentDependencies']
22
+ /**
23
+ * By a dependency's id here, the component or set already in this document it becomes, when the
24
+ * same snapshot was pasted before. A reuse keeps the local main, as in Figma.
25
+ */
26
+ componentMatches: Map<string, string>
27
+ /** The copying document's root id, for a foreign paste that creates dependencies here. */
28
+ clipboardOrigin?: string
21
29
  styleSnapshots: SceneNode[]
22
30
  /**
23
31
  * Whether the layers bind variables of this document now, whose values may differ from the
@@ -77,6 +85,7 @@ export function importClipboardDependencies(
77
85
  return {
78
86
  nodes,
79
87
  componentDependencies: componentDependencies.filter((node) => !ctx.graph.getNode(node.id)),
88
+ componentMatches: new Map(),
80
89
  styleSnapshots: [],
81
90
  resolveBindings: false
82
91
  }
@@ -87,7 +96,13 @@ export function importClipboardDependencies(
87
96
  for (const child of node.children ?? []) detach(child)
88
97
  }
89
98
  for (const node of [...nodes, ...componentDependencies]) detach(node)
90
- return { nodes, componentDependencies, styleSnapshots: [], resolveBindings: false }
99
+ return {
100
+ nodes,
101
+ componentDependencies,
102
+ componentMatches: new Map(),
103
+ styleSnapshots: [],
104
+ resolveBindings: false
105
+ }
91
106
  }
92
107
  const styleIds = new Map<string, string>()
93
108
  /** This document's styles the layers use in place of copied ones, by id. */
@@ -154,6 +169,12 @@ export function importClipboardDependencies(
154
169
  return {
155
170
  nodes,
156
171
  componentDependencies,
172
+ componentMatches: matchClipboardComponents(
173
+ ctx.graph,
174
+ snapshot.sourceRootId,
175
+ componentDependencies
176
+ ),
177
+ clipboardOrigin: snapshot.sourceRootId,
157
178
  styleSnapshots,
158
179
  resolveBindings: snapshot.variableDependencies.variables.length > 0,
159
180
  applyVariables: variables.apply,
@@ -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
+ }