@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
@@ -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 {
@@ -65,7 +65,8 @@ export class FigmaVariablesAPI {
65
65
 
66
66
  getLocalVariables(type?: FigmaVariableResolvedType): FigmaVariable[] {
67
67
  const wanted = type === undefined ? undefined : assertType('getLocalVariables', type)
68
- return [...this.#graph.variables.values()]
68
+ return this.#graph
69
+ .getLiveVariables()
69
70
  .filter((variable) => wanted === undefined || variable.type === wanted)
70
71
  .map((variable) => new FigmaVariable(this.#graph, variable.id))
71
72
  }
@@ -75,9 +76,9 @@ export class FigmaVariablesAPI {
75
76
  }
76
77
 
77
78
  getLocalVariableCollections(): FigmaVariableCollection[] {
78
- return [...this.#graph.variableCollections.keys()].map(
79
- (id) => new FigmaVariableCollection(this.#graph, id)
80
- )
79
+ return this.#graph
80
+ .getLiveCollections()
81
+ .map((collection) => new FigmaVariableCollection(this.#graph, collection.id))
81
82
  }
82
83
 
83
84
  async getLocalVariableCollectionsAsync(): Promise<FigmaVariableCollection[]> {
@@ -47,7 +47,7 @@ export function knownTokens(graph: SceneGraph): KnownTokens {
47
47
  byCSSName.set(name, { variable, collection, library: isLibraryCollection(collection) })
48
48
  }
49
49
  const byCondition = new Map<string, KnownMode>()
50
- for (const collection of graph.variableCollections.values()) {
50
+ for (const collection of graph.getLiveCollections()) {
51
51
  if (isLibraryCollection(collection)) continue
52
52
  for (const mode of collection.modes) {
53
53
  if (mode.modeId === collection.defaultModeId) continue
@@ -16,6 +16,7 @@ import {
16
16
  } from '@pairdraw/dom-css/export'
17
17
  import {
18
18
  isLibraryCollection,
19
+ type ColorProfile,
19
20
  type SceneGraph,
20
21
  type TokenUnit,
21
22
  type Variable,
@@ -39,6 +40,8 @@ import { namesFont, readCSSTokenValue, type CSSTokenValue } from './values'
39
40
  export interface CSSTokenReadOptions {
40
41
  /** The stylesheet's file name, for issues. */
41
42
  file?: string
43
+ /** The document's profile: a color that names its space converts into it. */
44
+ profile?: ColorProfile
42
45
  /**
43
46
  * What a numeric CSS expression such as `clamp(1rem, 4vw, 1.5rem)` comes to in `unit`, with
44
47
  * the custom properties in scope by name (`--space`). A browser computes it; without one, an
@@ -106,9 +109,9 @@ class CSSTokenReader {
106
109
  group(name: string): Group {
107
110
  const found = this.groups.get(name)
108
111
  if (found) return found
109
- const existing = [...this.graph.variableCollections.values()].find(
110
- (collection) => collection.name === name && !isLibraryCollection(collection)
111
- )
112
+ const existing = this.graph
113
+ .getLiveCollections()
114
+ .find((collection) => collection.name === name && !isLibraryCollection(collection))
112
115
  const defaultName =
113
116
  existing?.modes.find((mode) => mode.modeId === existing.defaultModeId)?.name ?? 'Default'
114
117
  const group: Group = {
@@ -245,7 +248,7 @@ class CSSTokenReader {
245
248
  const property = cssTokenProperty(token)
246
249
  const value = property && scope.get(property)
247
250
  if (!value) continue
248
- const read = readCSSTokenValue(value)
251
+ const read = readCSSTokenValue(value, { profile: this.options.profile })
249
252
  if (read.kind === 'number') return read.unit
250
253
  if (read.kind === 'expression' && read.unit) return read.unit
251
254
  }
@@ -282,10 +285,17 @@ class CSSTokenReader {
282
285
  ): ReadToken {
283
286
  const existing = this.existingVariable(name, group)
284
287
  const tokenName = this.tokenName(name, group)
285
- const value = readCSSTokenValue(css, { font: namesFont(name) })
288
+ const value = readCSSTokenValue(css, {
289
+ font: namesFont(name),
290
+ profile: this.options.profile
291
+ })
286
292
  let fields: TokenFields
287
293
  if (value.kind === 'reference') fields = this.alias(value.name)
288
- else if (value.kind === 'color') fields = { type: 'color', value: colorTokenValue(value.color) }
294
+ else if (value.kind === 'color')
295
+ fields = {
296
+ type: 'color',
297
+ value: colorTokenValue(value.color, this.options.profile)
298
+ }
289
299
  else if (value.kind === 'number')
290
300
  fields = { ...numberToken(value.value, value.unit), unit: value.unit }
291
301
  else if (value.kind === 'string') fields = { type: 'string', value: value.value }
@@ -389,7 +399,10 @@ export function readCSSDesignTokens(
389
399
  } catch {
390
400
  return { collections: [], composites: [], issues: [{ kind: 'invalid-file', file }] }
391
401
  }
392
- const reader = new CSSTokenReader(graph, knownTokens(graph), file, options)
402
+ const reader = new CSSTokenReader(graph, knownTokens(graph), file, {
403
+ ...options,
404
+ profile: options.profile ?? graph.documentColorSpace
405
+ })
393
406
  reader.read(sheet)
394
407
  const issues: DesignTokenReadIssue[] = [
395
408
  ...sheet.skipped.map((rule): DesignTokenReadIssue => ({ kind: 'unsupported-css', file, rule })),
@@ -107,6 +107,8 @@ export function patchTokenStylesheet(
107
107
  const wanted = wantedScopes(generated)
108
108
  const base = wanted.get('')?.values ?? new Map<string, string>()
109
109
  const known = knownTokens(graph)
110
+ // A color that names its own space converts into the profile, and a written one comes from it.
111
+ const profile = graph.documentColorSpace
110
112
 
111
113
  /**
112
114
  * What a scope should declare for a property. A mode writes only what differs from its default,
@@ -136,13 +138,13 @@ export function patchTokenStylesheet(
136
138
  const want = expected(key, declaration.name)
137
139
  if (want === undefined) continue
138
140
  const font = namesFont(declaration.name)
139
- const previous = readCSSTokenValue(declaration.value, { font })
140
- const next = readCSSTokenValue(want, { font })
141
+ const previous = readCSSTokenValue(declaration.value, { font, profile })
142
+ const next = readCSSTokenValue(want, { font, profile })
141
143
  if (sameCSSTokenValue(previous, next)) continue
142
144
  edits.push({
143
145
  start: declaration.start,
144
146
  end: declaration.end,
145
- text: rewriteCSSTokenValue(previous, next, want)
147
+ text: rewriteCSSTokenValue(previous, next, want, profile)
146
148
  })
147
149
  updated++
148
150
  }
@@ -160,7 +162,10 @@ export function patchTokenStylesheet(
160
162
  const from = key === '' ? undefined : inherited.get(name)
161
163
  if (from === undefined) return false
162
164
  const font = namesFont(name)
163
- return sameCSSTokenValue(readCSSTokenValue(from, { font }), readCSSTokenValue(value, { font }))
165
+ return sameCSSTokenValue(
166
+ readCSSTokenValue(from, { font, profile }),
167
+ readCSSTokenValue(value, { font, profile })
168
+ )
164
169
  }
165
170
 
166
171
  let added = 0
@@ -1,8 +1,13 @@
1
- import { converter, formatHex, formatHex8 } from 'culori'
1
+ import { converter, formatHex, formatHex8, parse } from 'culori'
2
2
 
3
3
  import { cssTokenProperty, cssValueTokens } from '@pairdraw/dom-css/export'
4
- import type { TokenUnit } from '@pairdraw/scene-graph'
5
- import { colorToCSS, parseDisplayableColor } from '@pairdraw/scene-graph/color'
4
+ import type { ColorProfile, TokenUnit } from '@pairdraw/scene-graph'
5
+ import {
6
+ colorToCSS,
7
+ parseDisplayableColor,
8
+ SRGB_SYNTAX_MODES,
9
+ tryParseColor
10
+ } from '@pairdraw/scene-graph/color'
6
11
  import type { Color } from '@pairdraw/scene-graph/primitives'
7
12
  import { tokenNumberFromUnit, tokenNumberInUnit } from '@pairdraw/scene-graph/variables'
8
13
 
@@ -114,12 +119,26 @@ function firstFamily(css: string): string | undefined {
114
119
  return family || undefined
115
120
  }
116
121
 
122
+ /**
123
+ * A CSS color in the document's profile: hex, `rgb()`, `hsl()` and `hwb()` give their numbers as
124
+ * the document's own, as an imported stylesheet writes them, and a color that names its space,
125
+ * such as `oklch()` or `color(display-p3 …)`, is converted into that profile.
126
+ */
127
+ function readColor(value: string, profile: ColorProfile): Color | null {
128
+ const parsed = parse(value)
129
+ if (!parsed || SRGB_SYNTAX_MODES.has(parsed.mode)) return parseDisplayableColor(value)
130
+ return tryParseColor(value, profile)
131
+ }
132
+
117
133
  /**
118
134
  * A custom property's value as a token: a color, a number in a token unit, a quoted string, a
119
135
  * font family where the property names fonts, a `var()` reference, a numeric expression, or
120
136
  * something no variable holds, such as a shadow.
121
137
  */
122
- export function readCSSTokenValue(css: string, { font = false } = {}): CSSTokenValue {
138
+ export function readCSSTokenValue(
139
+ css: string,
140
+ { font = false, profile = 'srgb' }: { font?: boolean; profile?: ColorProfile } = {}
141
+ ): CSSTokenValue {
123
142
  const value = css.trim()
124
143
  const tokens = cssValueTokens(value)
125
144
  const [only] = tokens
@@ -137,7 +156,7 @@ export function readCSSTokenValue(css: string, { font = false } = {}): CSSTokenV
137
156
  )
138
157
  if (color) return { kind: 'color', color, notation: 'hsl-channels' }
139
158
  }
140
- const color = parseDisplayableColor(value)
159
+ const color = readColor(value, profile)
141
160
  if (color) return { kind: 'color', color, notation: notationOf(value) }
142
161
  const expression = readExpression(value)
143
162
  if (expression) return expression
@@ -211,8 +230,16 @@ const toOklab = converter('oklab')
211
230
  const toOklch = converter('oklch')
212
231
 
213
232
  /** A color written in a notation: `oklch(0.7 0.19 41)`, `#ff5b2e`, `16 100% 59%`. */
214
- export function formatCSSColor(color: Color, notation: ColorNotation): string {
215
- const rgb = { mode: 'rgb' as const, r: color.r, g: color.g, b: color.b, alpha: color.a }
233
+ export function formatCSSColor(
234
+ color: Color,
235
+ notation: ColorNotation,
236
+ profile: ColorProfile = 'srgb'
237
+ ): string {
238
+ // The components sit in the document's profile, so the notation is derived from that space.
239
+ const rgb =
240
+ profile === 'display-p3'
241
+ ? { mode: 'p3' as const, r: color.r, g: color.g, b: color.b, alpha: color.a }
242
+ : { mode: 'rgb' as const, r: color.r, g: color.g, b: color.b, alpha: color.a }
216
243
  const a = alphaSuffix(color.a)
217
244
  switch (notation) {
218
245
  case 'rgb':
@@ -255,10 +282,11 @@ export function formatCSSColor(color: Color, notation: ColorNotation): string {
255
282
  export function rewriteCSSTokenValue(
256
283
  previous: CSSTokenValue,
257
284
  next: CSSTokenValue,
258
- nextCSS: string
285
+ nextCSS: string,
286
+ profile: ColorProfile = 'srgb'
259
287
  ): string {
260
288
  if (previous.kind === 'color' && next.kind === 'color' && previous.notation !== 'other')
261
- return formatCSSColor(next.color, previous.notation)
289
+ return formatCSSColor(next.color, previous.notation, profile)
262
290
  if (
263
291
  previous.kind === 'number' &&
264
292
  next.kind === 'number' &&
@@ -5,11 +5,12 @@ import {
5
5
  TOKEN_UNITS,
6
6
  VARIABLE_SCOPES,
7
7
  type CodeSyntaxPlatform,
8
+ type DocumentColorSpace,
8
9
  type TokenUnit,
9
10
  type VariableScope,
10
11
  type VariableType
11
12
  } from '@pairdraw/scene-graph'
12
- import { parseDisplayableColor } from '@pairdraw/scene-graph/color'
13
+ import { tryParseColor } from '@pairdraw/scene-graph/color'
13
14
  import { parseCSSNumber } from '@pairdraw/scene-graph/css'
14
15
  import type { Color } from '@pairdraw/scene-graph/primitives'
15
16
  import { ROOT_FONT_SIZE_PX } from '@pairdraw/scene-graph/variables'
@@ -53,12 +54,13 @@ const colorObjectSchema = v.object({
53
54
  })
54
55
 
55
56
  /**
56
- * A DTCG color in sRGB. The 2025.10 object form names its space; it is written as CSS and read
57
- * by culori, then mapped into sRGB. Earlier drafts wrote any CSS color string, which reads the
58
- * same way.
57
+ * A DTCG color as components in `profile`, the importing document's. The 2025.10 object form names
58
+ * its space; it is written as CSS and read as CSS colors are: an sRGB one keeps its numbers, as
59
+ * Figma takes hex, and one in another space, such as Display P3, is converted into `profile`.
60
+ * Earlier drafts wrote any CSS color string, which reads the same way.
59
61
  */
60
- export function decodeColor(value: unknown): Color | null {
61
- if (typeof value === 'string') return parseDisplayableColor(value)
62
+ export function decodeColor(value: unknown, profile: DocumentColorSpace): Color | null {
63
+ if (typeof value === 'string') return tryParseColor(value, profile)
62
64
  const parsed = v.safeParse(colorObjectSchema, value)
63
65
  if (!parsed.success) return null
64
66
  const { colorSpace, components, alpha = 1, hex } = parsed.output
@@ -66,8 +68,8 @@ export function decodeColor(value: unknown): Color | null {
66
68
  const open = PREDEFINED_SPACES.has(colorSpace)
67
69
  ? `color(${colorSpace} ${parts.join(' ')}`
68
70
  : FUNCTION_SPACES[colorSpace]?.(parts)
69
- if (!open) return hex ? parseDisplayableColor(hex) : null
70
- return parseDisplayableColor(`${open} / ${alpha})`)
71
+ if (!open) return hex ? tryParseColor(hex, profile) : null
72
+ return tryParseColor(`${open} / ${alpha})`, profile)
71
73
  }
72
74
 
73
75
  const dimensionSchema = v.object({ value: v.number(), unit: v.picklist(['px', 'rem']) })
@@ -210,11 +212,11 @@ function valueInUnit(literal: Literal, unit: TokenUnit | undefined): Literal['va
210
212
  }
211
213
 
212
214
  /** A literal in the shape its type takes, with the unit it was written in. */
213
- function decodeLiteral(token: ReadToken): Literal | null {
215
+ function decodeLiteral(token: ReadToken, profile: DocumentColorSpace): Literal | null {
214
216
  const { value } = token
215
217
  switch (token.type) {
216
218
  case 'color': {
217
- const color = decodeColor(value)
219
+ const color = decodeColor(value, profile)
218
220
  return color && { value: color }
219
221
  }
220
222
  case 'dimension':
@@ -250,7 +252,10 @@ function impliedScopes(token: ReadToken): VariableScope[] | undefined {
250
252
  }
251
253
 
252
254
  /** A token as a variable value and Pairdraw's own token fields. */
253
- export function decodeVariableToken(token: ReadToken): DecodedVariable | DecodeFailure {
255
+ export function decodeVariableToken(
256
+ token: ReadToken,
257
+ profile: DocumentColorSpace
258
+ ): DecodedVariable | DecodeFailure {
254
259
  const type = variableTypeOf(token)
255
260
  if (type === 'unsupported-type' || type === 'invalid-value') return type
256
261
  const own = v.safeParse(ownFieldsSchema, token.extensions[PAIRDRAW_EXTENSION])
@@ -267,7 +272,7 @@ export function decodeVariableToken(token: ReadToken): DecodedVariable | DecodeF
267
272
  name: figma.success ? figma.output.targetVariableName : undefined
268
273
  }
269
274
  } else {
270
- const literal = decodeLiteral(token)
275
+ const literal = decodeLiteral(token, profile)
271
276
  if (!literal) return 'invalid-value'
272
277
  unit ??= literal.unit === 'px' ? undefined : literal.unit
273
278
  value = { kind: 'literal', value: valueInUnit(literal, unit) }
@@ -103,7 +103,7 @@ function variableToken(
103
103
  formula = printFormula(value.value, (id) => tokenReference(context.references.get(id) ?? []), {
104
104
  type: (id) => context.graph.variables.get(id)?.type
105
105
  })
106
- $value = literalTokenValue(variable, resolved)
106
+ $value = literalTokenValue(variable, resolved, context.graph.documentColorSpace)
107
107
  } else if (typeof value === 'object' && 'expression' in value) {
108
108
  context.issues.push({ kind: 'unsupported-expression', ...where })
109
109
  return undefined
@@ -122,7 +122,7 @@ function variableToken(
122
122
  targetVariableSetName: targetCollection.name
123
123
  }
124
124
  } else {
125
- $value = literalTokenValue(variable, value)
125
+ $value = literalTokenValue(variable, value, context.graph.documentColorSpace)
126
126
  }
127
127
  if (variable.type === 'BOOLEAN') figma['com.figma.type'] = 'boolean'
128
128
  const $extensions = { ...figma, ...pairdrawFields(variable, mode.modeId, formula) }
@@ -190,7 +190,7 @@ function resolverDocument(collections: readonly CollectionFiles[], stylesPath: s
190
190
  */
191
191
  export function exportDesignTokens(graph: SceneGraph): DesignTokenExport {
192
192
  const issues: DesignTokenIssue[] = []
193
- const collections = [...graph.variableCollections.values()]
193
+ const collections = graph.getLiveCollections()
194
194
  const references = new Map<string, string[]>()
195
195
  const collectionOf = new Map<string, VariableCollection>()
196
196
  const placedByCollection = new Map<string, Array<{ variable: Variable; path: string[] }>>()
@@ -125,9 +125,9 @@ export function defaultTokenImportOptions(
125
125
  bundle: DesignTokenBundle
126
126
  ): TokenImportOptions {
127
127
  // A library's collections belong to it, so tokens of the same name make one of the file's.
128
- const existing = [...graph.variableCollections.values()].filter(
129
- (collection) => !isLibraryCollection(collection)
130
- )
128
+ const existing = graph
129
+ .getLiveCollections()
130
+ .filter((collection) => !isLibraryCollection(collection))
131
131
  const claimed = new Set<string>()
132
132
  return {
133
133
  collections: bundle.collections.map((collection): CollectionImportChoice => {
@@ -193,7 +193,7 @@ interface PlannerIndexes {
193
193
  function indexesOf(planner: Planner): PlannerIndexes {
194
194
  if (planner.indexes) return planner.indexes
195
195
  const variables = new Map<string, Variable[]>()
196
- for (const variable of planner.graph.variables.values())
196
+ for (const variable of planner.graph.getLiveVariables())
197
197
  variables.set(variable.name, [...(variables.get(variable.name) ?? []), variable])
198
198
  const planned = new Map<string, { index: number; variables: Map<string, number> }>()
199
199
  planner.collections.forEach((collection, index) => {
@@ -325,7 +325,8 @@ function planVariables(
325
325
  const rows: Array<{ variable: PlannedVariable; decoded: Array<DecodedVariable | undefined> }> = []
326
326
  const existingByName = variablesByName(planner.graph, planner.existingByCollection[index])
327
327
  for (const [name, tokens] of tokensByName(collection, modeIndexes)) {
328
- const decoded = tokens.map((token) => (token ? decodeVariableToken(token) : undefined))
328
+ const profile = planner.graph.documentColorSpace
329
+ const decoded = tokens.map((token) => (token ? decodeVariableToken(token, profile) : undefined))
329
330
  const failure = decoded.find((entry) => typeof entry === 'string')
330
331
  const usable = decoded.map((entry) => (typeof entry === 'string' ? undefined : entry))
331
332
  if (usable.every((entry) => entry === undefined)) {