@pairdraw/core 0.19.2 → 0.20.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 (847) hide show
  1. package/dist/ai/providers.d.ts +6 -0
  2. package/dist/ai/providers.d.ts.map +1 -1
  3. package/dist/ai/providers.js.map +1 -1
  4. package/dist/cache/resource.d.ts +8 -1
  5. package/dist/cache/resource.d.ts.map +1 -1
  6. package/dist/cache/resource.js +18 -0
  7. package/dist/cache/resource.js.map +1 -1
  8. package/dist/canvas/effects.d.ts +6 -4
  9. package/dist/canvas/effects.d.ts.map +1 -1
  10. package/dist/canvas/effects.js +37 -34
  11. package/dist/canvas/effects.js.map +1 -1
  12. package/dist/canvas/fills.d.ts.map +1 -1
  13. package/dist/canvas/fills.js +12 -8
  14. package/dist/canvas/fills.js.map +1 -1
  15. package/dist/canvas/images/adjustments.d.ts +18 -0
  16. package/dist/canvas/images/adjustments.d.ts.map +1 -0
  17. package/dist/canvas/images/adjustments.js +184 -0
  18. package/dist/canvas/images/adjustments.js.map +1 -0
  19. package/dist/canvas/images/sampling.d.ts +13 -0
  20. package/dist/canvas/images/sampling.d.ts.map +1 -0
  21. package/dist/canvas/images/sampling.js +49 -0
  22. package/dist/canvas/images/sampling.js.map +1 -0
  23. package/dist/canvas/index.d.ts +2 -2
  24. package/dist/canvas/masks.d.ts +1 -1
  25. package/dist/canvas/masks.d.ts.map +1 -1
  26. package/dist/canvas/masks.js.map +1 -1
  27. package/dist/canvas/noise/render.d.ts +15 -0
  28. package/dist/canvas/noise/render.d.ts.map +1 -0
  29. package/dist/canvas/noise/render.js +56 -0
  30. package/dist/canvas/noise/render.js.map +1 -0
  31. package/dist/canvas/noise/shader.d.ts +43 -0
  32. package/dist/canvas/noise/shader.d.ts.map +1 -0
  33. package/dist/canvas/noise/shader.js +161 -0
  34. package/dist/canvas/noise/shader.js.map +1 -0
  35. package/dist/canvas/noise/table.d.ts +13 -0
  36. package/dist/canvas/noise/table.d.ts.map +1 -0
  37. package/dist/canvas/noise/table.js +408 -0
  38. package/dist/canvas/noise/table.js.map +1 -0
  39. package/dist/canvas/noise/tile.d.ts +22 -0
  40. package/dist/canvas/noise/tile.d.ts.map +1 -0
  41. package/dist/canvas/noise/tile.js +73 -0
  42. package/dist/canvas/noise/tile.js.map +1 -0
  43. package/dist/canvas/outline-stroke.js +1 -1
  44. package/dist/canvas/overlays/auto-layout-hover.d.ts.map +1 -1
  45. package/dist/canvas/overlays/auto-layout-hover.js +31 -71
  46. package/dist/canvas/overlays/auto-layout-hover.js.map +1 -1
  47. package/dist/canvas/renderer/chunks/index.d.ts +1 -1
  48. package/dist/canvas/renderer/lifecycle.d.ts.map +1 -1
  49. package/dist/canvas/renderer/lifecycle.js +6 -0
  50. package/dist/canvas/renderer/lifecycle.js.map +1 -1
  51. package/dist/canvas/renderer/pipeline.d.ts.map +1 -1
  52. package/dist/canvas/renderer/pipeline.js +13 -1
  53. package/dist/canvas/renderer/pipeline.js.map +1 -1
  54. package/dist/canvas/renderer/play-scenes.d.ts +13 -0
  55. package/dist/canvas/renderer/play-scenes.d.ts.map +1 -0
  56. package/dist/canvas/renderer/play-scenes.js +40 -0
  57. package/dist/canvas/renderer/play-scenes.js.map +1 -0
  58. package/dist/canvas/renderer/tiles/cache.d.ts +19 -1
  59. package/dist/canvas/renderer/tiles/cache.d.ts.map +1 -1
  60. package/dist/canvas/renderer/tiles/cache.js +32 -1
  61. package/dist/canvas/renderer/tiles/cache.js.map +1 -1
  62. package/dist/canvas/renderer/tiles/controller.d.ts +11 -0
  63. package/dist/canvas/renderer/tiles/controller.d.ts.map +1 -1
  64. package/dist/canvas/renderer/tiles/controller.js +18 -1
  65. package/dist/canvas/renderer/tiles/controller.js.map +1 -1
  66. package/dist/canvas/renderer/tiles/index.d.ts +2 -2
  67. package/dist/canvas/renderer/tiles/planner.d.ts +1 -1
  68. package/dist/canvas/renderer/types.d.ts +18 -3
  69. package/dist/canvas/renderer/types.d.ts.map +1 -1
  70. package/dist/canvas/renderer/visual-bounds.d.ts +1 -1
  71. package/dist/canvas/renderer/visual-bounds.js +1 -1
  72. package/dist/canvas/renderer.d.ts +22 -2
  73. package/dist/canvas/renderer.d.ts.map +1 -1
  74. package/dist/canvas/renderer.js +29 -1
  75. package/dist/canvas/renderer.js.map +1 -1
  76. package/dist/canvas/scene.d.ts +2 -1
  77. package/dist/canvas/scene.d.ts.map +1 -1
  78. package/dist/canvas/scene.js +41 -9
  79. package/dist/canvas/scene.js.map +1 -1
  80. package/dist/canvas/shadows/silhouette.js +1 -1
  81. package/dist/canvas/texture.d.ts +20 -0
  82. package/dist/canvas/texture.d.ts.map +1 -0
  83. package/dist/canvas/texture.js +100 -0
  84. package/dist/canvas/texture.js.map +1 -0
  85. package/dist/clipboard.js +16 -5
  86. package/dist/clipboard.js.map +1 -1
  87. package/dist/constants.d.ts +5 -1
  88. package/dist/constants.d.ts.map +1 -1
  89. package/dist/constants.js +5 -1
  90. package/dist/constants.js.map +1 -1
  91. package/dist/design-jsx/renderer.d.ts.map +1 -1
  92. package/dist/design-memory/check.d.ts +90 -0
  93. package/dist/design-memory/check.d.ts.map +1 -0
  94. package/dist/design-memory/check.js +281 -0
  95. package/dist/design-memory/check.js.map +1 -0
  96. package/dist/design-memory/describe.d.ts +37 -0
  97. package/dist/design-memory/describe.d.ts.map +1 -0
  98. package/dist/design-memory/describe.js +52 -0
  99. package/dist/design-memory/describe.js.map +1 -0
  100. package/dist/design-memory/distil.d.ts +22 -0
  101. package/dist/design-memory/distil.d.ts.map +1 -0
  102. package/dist/design-memory/distil.js +54 -0
  103. package/dist/design-memory/distil.js.map +1 -0
  104. package/dist/design-memory/document.d.ts +12 -0
  105. package/dist/design-memory/document.d.ts.map +1 -0
  106. package/dist/design-memory/document.js +64 -0
  107. package/dist/design-memory/document.js.map +1 -0
  108. package/dist/design-memory/guard.d.ts +48 -0
  109. package/dist/design-memory/guard.d.ts.map +1 -0
  110. package/dist/design-memory/guard.js +105 -0
  111. package/dist/design-memory/guard.js.map +1 -0
  112. package/dist/design-memory/index.d.ts +9 -0
  113. package/dist/design-memory/index.js +9 -0
  114. package/dist/design-memory/refusal.d.ts +32 -0
  115. package/dist/design-memory/refusal.d.ts.map +1 -0
  116. package/dist/design-memory/refusal.js +68 -0
  117. package/dist/design-memory/refusal.js.map +1 -0
  118. package/dist/design-memory/rules.d.ts +63 -0
  119. package/dist/design-memory/rules.d.ts.map +1 -0
  120. package/dist/design-memory/rules.js +224 -0
  121. package/dist/design-memory/rules.js.map +1 -0
  122. package/dist/design-memory/values.d.ts +28 -0
  123. package/dist/design-memory/values.d.ts.map +1 -0
  124. package/dist/design-memory/values.js +160 -0
  125. package/dist/design-memory/values.js.map +1 -0
  126. package/dist/editor/alignment.js +1 -1
  127. package/dist/editor/bridges/components.d.ts +2 -0
  128. package/dist/editor/bridges/components.d.ts.map +1 -1
  129. package/dist/editor/bridges/components.js +2 -0
  130. package/dist/editor/bridges/components.js.map +1 -1
  131. package/dist/editor/bridges/undo.d.ts +1 -1
  132. package/dist/editor/clipboard/assets.js +1 -1
  133. package/dist/editor/clipboard/export.d.ts.map +1 -1
  134. package/dist/editor/clipboard/export.js +16 -2
  135. package/dist/editor/clipboard/export.js.map +1 -1
  136. package/dist/editor/clipboard/placement.d.ts +1 -1
  137. package/dist/editor/clipboard/placement.js +1 -1
  138. package/dist/editor/components/instances.d.ts +2 -0
  139. package/dist/editor/components/instances.d.ts.map +1 -1
  140. package/dist/editor/components/instances.js +22 -1
  141. package/dist/editor/components/instances.js.map +1 -1
  142. package/dist/editor/components.d.ts +2 -0
  143. package/dist/editor/components.d.ts.map +1 -1
  144. package/dist/editor/connectors/attach.js +1 -1
  145. package/dist/editor/create.d.ts +27 -3
  146. package/dist/editor/create.d.ts.map +1 -1
  147. package/dist/editor/create.js +16 -60
  148. package/dist/editor/create.js.map +1 -1
  149. package/dist/editor/design-memory.d.ts +11 -0
  150. package/dist/editor/design-memory.d.ts.map +1 -0
  151. package/dist/editor/design-memory.js +40 -0
  152. package/dist/editor/design-memory.js.map +1 -0
  153. package/dist/editor/design-tokens.d.ts +4 -0
  154. package/dist/editor/design-tokens.d.ts.map +1 -1
  155. package/dist/editor/design-tokens.js +30 -1
  156. package/dist/editor/design-tokens.js.map +1 -1
  157. package/dist/editor/document-colors.d.ts +23 -0
  158. package/dist/editor/document-colors.d.ts.map +1 -0
  159. package/dist/editor/document-colors.js +53 -0
  160. package/dist/editor/document-colors.js.map +1 -0
  161. package/dist/editor/eyedropper.d.ts +47 -0
  162. package/dist/editor/eyedropper.d.ts.map +1 -0
  163. package/dist/editor/eyedropper.js +168 -0
  164. package/dist/editor/eyedropper.js.map +1 -0
  165. package/dist/editor/fonts.d.ts +9 -0
  166. package/dist/editor/fonts.d.ts.map +1 -0
  167. package/dist/editor/fonts.js +14 -0
  168. package/dist/editor/fonts.js.map +1 -0
  169. package/dist/editor/history/atomic-tool.d.ts +9 -2
  170. package/dist/editor/history/atomic-tool.d.ts.map +1 -1
  171. package/dist/editor/history/atomic-tool.js +6 -0
  172. package/dist/editor/history/atomic-tool.js.map +1 -1
  173. package/dist/editor/history/capture.d.ts +13 -0
  174. package/dist/editor/history/capture.d.ts.map +1 -0
  175. package/dist/editor/history/capture.js +28 -0
  176. package/dist/editor/history/capture.js.map +1 -0
  177. package/dist/editor/history/document-change.d.ts.map +1 -1
  178. package/dist/editor/history/document-change.js +2 -22
  179. package/dist/editor/history/document-change.js.map +1 -1
  180. package/dist/editor/history/edit.d.ts +7 -0
  181. package/dist/editor/history/edit.d.ts.map +1 -1
  182. package/dist/editor/history/edit.js +4 -2
  183. package/dist/editor/history/edit.js.map +1 -1
  184. package/dist/editor/history/subtree.d.ts +9 -0
  185. package/dist/editor/history/subtree.d.ts.map +1 -1
  186. package/dist/editor/history/subtree.js +12 -2
  187. package/dist/editor/history/subtree.js.map +1 -1
  188. package/dist/editor/index.d.ts +4 -2
  189. package/dist/editor/index.js +4 -2
  190. package/dist/editor/pages.d.ts +7 -5
  191. package/dist/editor/pages.d.ts.map +1 -1
  192. package/dist/editor/pages.js +35 -25
  193. package/dist/editor/pages.js.map +1 -1
  194. package/dist/editor/play/states.d.ts +3 -1
  195. package/dist/editor/play/states.d.ts.map +1 -1
  196. package/dist/editor/play/states.js +1 -1
  197. package/dist/editor/play/states.js.map +1 -1
  198. package/dist/editor/read-only/actions.js +4 -0
  199. package/dist/editor/read-only/actions.js.map +1 -1
  200. package/dist/editor/render-requests.d.ts +18 -0
  201. package/dist/editor/render-requests.d.ts.map +1 -0
  202. package/dist/editor/render-requests.js +76 -0
  203. package/dist/editor/render-requests.js.map +1 -0
  204. package/dist/editor/scale/rescale.d.ts +1 -1
  205. package/dist/editor/selection/overlays.d.ts.map +1 -1
  206. package/dist/editor/selection/overlays.js +1 -1
  207. package/dist/editor/selection/overlays.js.map +1 -1
  208. package/dist/editor/selection/read.d.ts +4 -0
  209. package/dist/editor/selection.d.ts +5 -0
  210. package/dist/editor/selection.d.ts.map +1 -1
  211. package/dist/editor/tool-registry.d.ts.map +1 -1
  212. package/dist/editor/tool-registry.js +2 -1
  213. package/dist/editor/tool-registry.js.map +1 -1
  214. package/dist/editor/types.d.ts +5 -1
  215. package/dist/editor/types.d.ts.map +1 -1
  216. package/dist/editor/variations/create.d.ts +28 -0
  217. package/dist/editor/variations/create.d.ts.map +1 -0
  218. package/dist/editor/variations/create.js +176 -0
  219. package/dist/editor/variations/create.js.map +1 -0
  220. package/dist/editor/variations/pick.d.ts +16 -0
  221. package/dist/editor/variations/pick.d.ts.map +1 -0
  222. package/dist/editor/variations/pick.js +23 -0
  223. package/dist/editor/variations/pick.js.map +1 -0
  224. package/dist/editor/variations.d.ts +28 -0
  225. package/dist/editor/variations.d.ts.map +1 -0
  226. package/dist/editor/variations.js +88 -0
  227. package/dist/editor/variations.js.map +1 -0
  228. package/dist/figma-api/accessors/reactions.d.ts.map +1 -1
  229. package/dist/figma-api/accessors/reactions.js +4 -1
  230. package/dist/figma-api/accessors/reactions.js.map +1 -1
  231. package/dist/figma-api/accessors/text/index.js +3 -0
  232. package/dist/figma-api/accessors/text/index.js.map +1 -1
  233. package/dist/figma-api/accessors/text/opentype.d.ts +17 -0
  234. package/dist/figma-api/accessors/text/opentype.d.ts.map +1 -0
  235. package/dist/figma-api/accessors/text/opentype.js +28 -0
  236. package/dist/figma-api/accessors/text/opentype.js.map +1 -0
  237. package/dist/figma-api/accessors/visual.d.ts.map +1 -1
  238. package/dist/figma-api/accessors/visual.js +33 -0
  239. package/dist/figma-api/accessors/visual.js.map +1 -1
  240. package/dist/figma-api/effects.d.ts +79 -3
  241. package/dist/figma-api/effects.d.ts.map +1 -1
  242. package/dist/figma-api/effects.js +150 -9
  243. package/dist/figma-api/effects.js.map +1 -1
  244. package/dist/figma-api/index.d.ts +5 -0
  245. package/dist/figma-api/index.d.ts.map +1 -1
  246. package/dist/figma-api/index.js +6 -1
  247. package/dist/figma-api/index.js.map +1 -1
  248. package/dist/figma-api/overrides.d.ts +13 -1
  249. package/dist/figma-api/overrides.d.ts.map +1 -1
  250. package/dist/figma-api/overrides.js +196 -4
  251. package/dist/figma-api/overrides.js.map +1 -1
  252. package/dist/figma-api/paints.d.ts +3 -3
  253. package/dist/figma-api/paints.d.ts.map +1 -1
  254. package/dist/figma-api/paints.js +14 -4
  255. package/dist/figma-api/paints.js.map +1 -1
  256. package/dist/figma-api/proxy.d.ts +4 -1
  257. package/dist/figma-api/proxy.d.ts.map +1 -1
  258. package/dist/figma-api/proxy.js +1 -1
  259. package/dist/figma-api/proxy.js.map +1 -1
  260. package/dist/figma-api/reactions.d.ts +41 -13
  261. package/dist/figma-api/reactions.d.ts.map +1 -1
  262. package/dist/figma-api/reactions.js +113 -31
  263. package/dist/figma-api/reactions.js.map +1 -1
  264. package/dist/figma-api/render-bounds.js +1 -1
  265. package/dist/figma-api/surface.d.ts +6 -3
  266. package/dist/figma-api/surface.d.ts.map +1 -1
  267. package/dist/figma-api/surface.js +6 -2
  268. package/dist/figma-api/surface.js.map +1 -1
  269. package/dist/figma-api/transform.d.ts +1 -1
  270. package/dist/geometry/figma.d.ts +1 -1
  271. package/dist/geometry/image-crop.d.ts +1 -1
  272. package/dist/geometry/image-crop.js +1 -1
  273. package/dist/index.d.ts +4 -2
  274. package/dist/index.js +4 -2
  275. package/dist/io/formats/boolean-path.d.ts +19 -0
  276. package/dist/io/formats/boolean-path.d.ts.map +1 -0
  277. package/dist/io/formats/boolean-path.js +47 -0
  278. package/dist/io/formats/boolean-path.js.map +1 -0
  279. package/dist/io/formats/design-tokens/decode.js +1 -1
  280. package/dist/io/formats/design-tokens/index.d.ts +4 -1
  281. package/dist/io/formats/design-tokens/index.js +4 -1
  282. package/dist/io/formats/design-tokens/plan/changes.d.ts +5 -3
  283. package/dist/io/formats/design-tokens/plan/changes.d.ts.map +1 -1
  284. package/dist/io/formats/design-tokens/plan/changes.js +1 -1
  285. package/dist/io/formats/design-tokens/plan/changes.js.map +1 -1
  286. package/dist/io/formats/design-tokens/project.d.ts +17 -2
  287. package/dist/io/formats/design-tokens/project.d.ts.map +1 -1
  288. package/dist/io/formats/design-tokens/project.js +29 -8
  289. package/dist/io/formats/design-tokens/project.js.map +1 -1
  290. package/dist/io/formats/design-tokens/styles.d.ts.map +1 -1
  291. package/dist/io/formats/design-tokens/styles.js.map +1 -1
  292. package/dist/io/formats/design-tokens/sync/apply.d.ts +42 -0
  293. package/dist/io/formats/design-tokens/sync/apply.d.ts.map +1 -0
  294. package/dist/io/formats/design-tokens/sync/apply.js +73 -0
  295. package/dist/io/formats/design-tokens/sync/apply.js.map +1 -0
  296. package/dist/io/formats/design-tokens/sync/drift.d.ts +77 -0
  297. package/dist/io/formats/design-tokens/sync/drift.d.ts.map +1 -0
  298. package/dist/io/formats/design-tokens/sync/drift.js +391 -0
  299. package/dist/io/formats/design-tokens/sync/drift.js.map +1 -0
  300. package/dist/io/formats/design-tokens/sync/files.d.ts +15 -0
  301. package/dist/io/formats/design-tokens/sync/files.d.ts.map +1 -0
  302. package/dist/io/formats/design-tokens/sync/files.js +35 -0
  303. package/dist/io/formats/design-tokens/sync/files.js.map +1 -0
  304. package/dist/io/formats/drawio/edges.d.ts +7 -1
  305. package/dist/io/formats/drawio/edges.d.ts.map +1 -1
  306. package/dist/io/formats/drawio/edges.js +54 -1
  307. package/dist/io/formats/drawio/edges.js.map +1 -1
  308. package/dist/io/formats/drawio/export.d.ts.map +1 -1
  309. package/dist/io/formats/drawio/export.js +19 -2
  310. package/dist/io/formats/drawio/export.js.map +1 -1
  311. package/dist/io/formats/drawio/index.js +1 -0
  312. package/dist/io/formats/drawio/index.js.map +1 -1
  313. package/dist/io/formats/drawio/label.js +1 -1
  314. package/dist/io/formats/drawio/paint.js +1 -1
  315. package/dist/io/formats/drawio/placement.d.ts +1 -1
  316. package/dist/io/formats/fig/export/patch/index.d.ts.map +1 -1
  317. package/dist/io/formats/fig/export/patch/index.js +5 -0
  318. package/dist/io/formats/fig/export/patch/index.js.map +1 -1
  319. package/dist/io/formats/fig/thumbnail-page.d.ts +3 -4
  320. package/dist/io/formats/fig/thumbnail-page.d.ts.map +1 -1
  321. package/dist/io/formats/fig/thumbnail-page.js.map +1 -1
  322. package/dist/io/formats/html/import.d.ts.map +1 -1
  323. package/dist/io/formats/html/import.js +3 -1
  324. package/dist/io/formats/html/import.js.map +1 -1
  325. package/dist/io/formats/html/index.d.ts +2 -2
  326. package/dist/io/formats/html/index.d.ts.map +1 -1
  327. package/dist/io/formats/html/index.js +6 -4
  328. package/dist/io/formats/html/index.js.map +1 -1
  329. package/dist/io/formats/html/vectors.d.ts +2 -1
  330. package/dist/io/formats/html/vectors.d.ts.map +1 -1
  331. package/dist/io/formats/html/vectors.js +3 -2
  332. package/dist/io/formats/html/vectors.js.map +1 -1
  333. package/dist/io/formats/mermaid/styles.js +1 -1
  334. package/dist/io/formats/pdf/document.d.ts +3 -1
  335. package/dist/io/formats/pdf/document.d.ts.map +1 -1
  336. package/dist/io/formats/pdf/document.js +6 -3
  337. package/dist/io/formats/pdf/document.js.map +1 -1
  338. package/dist/io/formats/pdf/prepare.d.ts +1 -1
  339. package/dist/io/formats/pen/imports.d.ts +4 -1
  340. package/dist/io/formats/pen/imports.d.ts.map +1 -1
  341. package/dist/io/formats/pen/imports.js.map +1 -1
  342. package/dist/io/formats/pen/index.d.ts.map +1 -1
  343. package/dist/io/formats/pen/index.js +31 -3
  344. package/dist/io/formats/pen/index.js.map +1 -1
  345. package/dist/io/formats/pptx/export.js +1 -1
  346. package/dist/io/formats/pptx/geometry.d.ts +1 -1
  347. package/dist/io/formats/raster/adjusted-images.d.ts +15 -0
  348. package/dist/io/formats/raster/adjusted-images.d.ts.map +1 -0
  349. package/dist/io/formats/raster/adjusted-images.js +118 -0
  350. package/dist/io/formats/raster/adjusted-images.js.map +1 -0
  351. package/dist/io/formats/raster/headless.d.ts +11 -1
  352. package/dist/io/formats/raster/headless.d.ts.map +1 -1
  353. package/dist/io/formats/raster/headless.js +4 -4
  354. package/dist/io/formats/raster/headless.js.map +1 -1
  355. package/dist/io/formats/raster/index.d.ts +2 -2
  356. package/dist/io/formats/raster/pixels.d.ts +7 -1
  357. package/dist/io/formats/raster/pixels.d.ts.map +1 -1
  358. package/dist/io/formats/raster/pixels.js.map +1 -1
  359. package/dist/io/formats/raster/render.d.ts.map +1 -1
  360. package/dist/io/formats/raster/render.js +4 -0
  361. package/dist/io/formats/raster/render.js.map +1 -1
  362. package/dist/io/formats/svg/defs.d.ts +5 -6
  363. package/dist/io/formats/svg/defs.d.ts.map +1 -1
  364. package/dist/io/formats/svg/defs.js +1 -53
  365. package/dist/io/formats/svg/defs.js.map +1 -1
  366. package/dist/io/formats/svg/effects.d.ts +16 -0
  367. package/dist/io/formats/svg/effects.d.ts.map +1 -0
  368. package/dist/io/formats/svg/effects.js +126 -0
  369. package/dist/io/formats/svg/effects.js.map +1 -0
  370. package/dist/io/formats/svg/export.d.ts +7 -1
  371. package/dist/io/formats/svg/export.d.ts.map +1 -1
  372. package/dist/io/formats/svg/export.js +174 -36
  373. package/dist/io/formats/svg/export.js.map +1 -1
  374. package/dist/io/formats/svg/filter.d.ts +27 -0
  375. package/dist/io/formats/svg/filter.d.ts.map +1 -0
  376. package/dist/io/formats/svg/filter.js +44 -0
  377. package/dist/io/formats/svg/filter.js.map +1 -0
  378. package/dist/io/formats/svg/grain.d.ts +26 -0
  379. package/dist/io/formats/svg/grain.d.ts.map +1 -0
  380. package/dist/io/formats/svg/grain.js +298 -0
  381. package/dist/io/formats/svg/grain.js.map +1 -0
  382. package/dist/io/formats/svg/strokes.d.ts +1 -1
  383. package/dist/io/formats/svg/strokes.d.ts.map +1 -1
  384. package/dist/io/formats/svg/strokes.js +1 -2
  385. package/dist/io/formats/svg/strokes.js.map +1 -1
  386. package/dist/io/formats/svg/text/import.js +1 -1
  387. package/dist/io/formats/svg/text/layout.d.ts +5 -2
  388. package/dist/io/formats/svg/text/layout.d.ts.map +1 -1
  389. package/dist/io/formats/svg/text/layout.js +6 -3
  390. package/dist/io/formats/svg/text/layout.js.map +1 -1
  391. package/dist/io/formats/video/composite.d.ts +18 -0
  392. package/dist/io/formats/video/composite.d.ts.map +1 -0
  393. package/dist/io/formats/video/composite.js +79 -0
  394. package/dist/io/formats/video/composite.js.map +1 -0
  395. package/dist/io/formats/video/formats.d.ts +29 -0
  396. package/dist/io/formats/video/formats.d.ts.map +1 -0
  397. package/dist/io/formats/video/formats.js +43 -0
  398. package/dist/io/formats/video/formats.js.map +1 -0
  399. package/dist/io/formats/video/gif.d.ts +13 -0
  400. package/dist/io/formats/video/gif.d.ts.map +1 -0
  401. package/dist/io/formats/video/gif.js +56 -0
  402. package/dist/io/formats/video/gif.js.map +1 -0
  403. package/dist/io/formats/video/index.d.ts +9 -0
  404. package/dist/io/formats/video/index.js +9 -0
  405. package/dist/io/formats/video/plan.d.ts +64 -0
  406. package/dist/io/formats/video/plan.d.ts.map +1 -0
  407. package/dist/io/formats/video/plan.js +90 -0
  408. package/dist/io/formats/video/plan.js.map +1 -0
  409. package/dist/io/formats/video/record.d.ts +36 -0
  410. package/dist/io/formats/video/record.d.ts.map +1 -0
  411. package/dist/io/formats/video/record.js +154 -0
  412. package/dist/io/formats/video/record.js.map +1 -0
  413. package/dist/io/formats/video/sink.d.ts +29 -0
  414. package/dist/io/formats/video/sink.d.ts.map +1 -0
  415. package/dist/io/formats/video/sink.js +16 -0
  416. package/dist/io/formats/video/sink.js.map +1 -0
  417. package/dist/io/formats/video/size.d.ts +19 -0
  418. package/dist/io/formats/video/size.d.ts.map +1 -0
  419. package/dist/io/formats/video/size.js +26 -0
  420. package/dist/io/formats/video/size.js.map +1 -0
  421. package/dist/io/formats/video/webcodecs.d.ts +18 -0
  422. package/dist/io/formats/video/webcodecs.d.ts.map +1 -0
  423. package/dist/io/formats/video/webcodecs.js +74 -0
  424. package/dist/io/formats/video/webcodecs.js.map +1 -0
  425. package/dist/io/formats.d.ts.map +1 -1
  426. package/dist/io/formats.js +40 -11
  427. package/dist/io/formats.js.map +1 -1
  428. package/dist/io/types.d.ts +19 -4
  429. package/dist/io/types.d.ts.map +1 -1
  430. package/dist/kiwi/fig/parse/transfer.d.ts +1 -1
  431. package/dist/layout/auto-layout-handles.d.ts +66 -0
  432. package/dist/layout/auto-layout-handles.d.ts.map +1 -0
  433. package/dist/layout/auto-layout-handles.js +291 -0
  434. package/dist/layout/auto-layout-handles.js.map +1 -0
  435. package/dist/layout.d.ts +3 -2
  436. package/dist/layout.d.ts.map +1 -1
  437. package/dist/layout.js +2 -1
  438. package/dist/layout.js.map +1 -1
  439. package/dist/lint/fixes.d.ts.map +1 -1
  440. package/dist/lint/fixes.js +9 -3
  441. package/dist/lint/fixes.js.map +1 -1
  442. package/dist/lint/index.d.ts +3 -2
  443. package/dist/lint/index.js +2 -1
  444. package/dist/lint/linter.d.ts +12 -0
  445. package/dist/lint/linter.d.ts.map +1 -1
  446. package/dist/lint/linter.js +110 -8
  447. package/dist/lint/linter.js.map +1 -1
  448. package/dist/lint/presets.d.ts.map +1 -1
  449. package/dist/lint/presets.js +2 -0
  450. package/dist/lint/presets.js.map +1 -1
  451. package/dist/lint/rules/design-memory.d.ts +15 -0
  452. package/dist/lint/rules/design-memory.d.ts.map +1 -0
  453. package/dist/lint/rules/design-memory.js +90 -0
  454. package/dist/lint/rules/design-memory.js.map +1 -0
  455. package/dist/lint/rules/index.d.ts +6 -5
  456. package/dist/lint/rules/index.d.ts.map +1 -1
  457. package/dist/lint/rules/index.js +6 -2
  458. package/dist/lint/rules/index.js.map +1 -1
  459. package/dist/lint/rules/no-unbound-token-values.d.ts +6 -0
  460. package/dist/lint/rules/no-unbound-token-values.d.ts.map +1 -0
  461. package/dist/lint/rules/no-unbound-token-values.js +79 -0
  462. package/dist/lint/rules/no-unbound-token-values.js.map +1 -0
  463. package/dist/lint/types.d.ts +25 -2
  464. package/dist/lint/types.d.ts.map +1 -1
  465. package/dist/node/video.d.ts +12 -0
  466. package/dist/node/video.d.ts.map +1 -0
  467. package/dist/node/video.js +206 -0
  468. package/dist/node/video.js.map +1 -0
  469. package/dist/pairdraw-api/design-memory.d.ts +19 -0
  470. package/dist/pairdraw-api/design-memory.d.ts.map +1 -0
  471. package/dist/pairdraw-api/design-memory.js +39 -0
  472. package/dist/pairdraw-api/design-memory.js.map +1 -0
  473. package/dist/pairdraw-api/index.d.ts +45 -1
  474. package/dist/pairdraw-api/index.d.ts.map +1 -1
  475. package/dist/pairdraw-api/index.js +55 -2
  476. package/dist/pairdraw-api/index.js.map +1 -1
  477. package/dist/pairdraw-api/nodes.d.ts +12 -1
  478. package/dist/pairdraw-api/nodes.d.ts.map +1 -1
  479. package/dist/pairdraw-api/nodes.js +28 -1
  480. package/dist/pairdraw-api/nodes.js.map +1 -1
  481. package/dist/pairdraw-api/variations.d.ts +48 -0
  482. package/dist/pairdraw-api/variations.d.ts.map +1 -0
  483. package/dist/pairdraw-api/variations.js +76 -0
  484. package/dist/pairdraw-api/variations.js.map +1 -0
  485. package/dist/prototype/easing.d.ts +13 -0
  486. package/dist/prototype/easing.d.ts.map +1 -0
  487. package/dist/prototype/easing.js +36 -0
  488. package/dist/prototype/easing.js.map +1 -0
  489. package/dist/prototype/frames.d.ts +10 -0
  490. package/dist/prototype/frames.d.ts.map +1 -0
  491. package/dist/prototype/frames.js +12 -0
  492. package/dist/prototype/frames.js.map +1 -0
  493. package/dist/prototype/hit.d.ts +17 -0
  494. package/dist/prototype/hit.d.ts.map +1 -0
  495. package/dist/prototype/hit.js +45 -0
  496. package/dist/prototype/hit.js.map +1 -0
  497. package/dist/prototype/index.d.ts +14 -0
  498. package/dist/prototype/index.js +14 -0
  499. package/dist/prototype/pointer.d.ts +63 -0
  500. package/dist/prototype/pointer.d.ts.map +1 -0
  501. package/dist/prototype/pointer.js +104 -0
  502. package/dist/prototype/pointer.js.map +1 -0
  503. package/dist/prototype/reactions.d.ts +45 -0
  504. package/dist/prototype/reactions.d.ts.map +1 -0
  505. package/dist/prototype/reactions.js +122 -0
  506. package/dist/prototype/reactions.js.map +1 -0
  507. package/dist/prototype/scene.d.ts +35 -0
  508. package/dist/prototype/scene.d.ts.map +1 -0
  509. package/dist/prototype/scene.js +86 -0
  510. package/dist/prototype/scene.js.map +1 -0
  511. package/dist/prototype/scenes.d.ts +81 -0
  512. package/dist/prototype/scenes.d.ts.map +1 -0
  513. package/dist/prototype/scenes.js +175 -0
  514. package/dist/prototype/scenes.js.map +1 -0
  515. package/dist/prototype/scroll.d.ts +48 -0
  516. package/dist/prototype/scroll.d.ts.map +1 -0
  517. package/dist/prototype/scroll.js +159 -0
  518. package/dist/prototype/scroll.js.map +1 -0
  519. package/dist/prototype/session.d.ts +71 -0
  520. package/dist/prototype/session.d.ts.map +1 -0
  521. package/dist/prototype/session.js +135 -0
  522. package/dist/prototype/session.js.map +1 -0
  523. package/dist/prototype/smart-animate/animation.d.ts +34 -0
  524. package/dist/prototype/smart-animate/animation.d.ts.map +1 -0
  525. package/dist/prototype/smart-animate/animation.js +212 -0
  526. package/dist/prototype/smart-animate/animation.js.map +1 -0
  527. package/dist/prototype/smart-animate/match.d.ts +24 -0
  528. package/dist/prototype/smart-animate/match.d.ts.map +1 -0
  529. package/dist/prototype/smart-animate/match.js +72 -0
  530. package/dist/prototype/smart-animate/match.js.map +1 -0
  531. package/dist/prototype/snapshot.d.ts +19 -0
  532. package/dist/prototype/snapshot.d.ts.map +1 -0
  533. package/dist/prototype/snapshot.js +56 -0
  534. package/dist/prototype/snapshot.js.map +1 -0
  535. package/dist/prototype/timeline.d.ts +132 -0
  536. package/dist/prototype/timeline.d.ts.map +1 -0
  537. package/dist/prototype/timeline.js +260 -0
  538. package/dist/prototype/timeline.js.map +1 -0
  539. package/dist/rpc/read-commands.js +1 -1
  540. package/dist/text/font/features.d.ts +9 -0
  541. package/dist/text/font/features.d.ts.map +1 -0
  542. package/dist/text/font/features.js +27 -0
  543. package/dist/text/font/features.js.map +1 -0
  544. package/dist/text/font/manager.d.ts +12 -0
  545. package/dist/text/font/manager.d.ts.map +1 -1
  546. package/dist/text/font/manager.js +60 -1
  547. package/dist/text/font/manager.js.map +1 -1
  548. package/dist/text/index.d.ts +10 -8
  549. package/dist/text/index.js +3 -1
  550. package/dist/text/replace-fonts.d.ts +41 -0
  551. package/dist/text/replace-fonts.d.ts.map +1 -0
  552. package/dist/text/replace-fonts.js +121 -0
  553. package/dist/text/replace-fonts.js.map +1 -0
  554. package/dist/tools/analyze/responsive/index.d.ts +15 -0
  555. package/dist/tools/analyze/responsive/index.d.ts.map +1 -0
  556. package/dist/tools/analyze/responsive/index.js +203 -0
  557. package/dist/tools/analyze/responsive/index.js.map +1 -0
  558. package/dist/tools/analyze.d.ts +2 -1
  559. package/dist/tools/analyze.js +2 -1
  560. package/dist/tools/codegen/token-sync.d.ts +7 -0
  561. package/dist/tools/codegen/token-sync.d.ts.map +1 -0
  562. package/dist/tools/codegen/token-sync.js +85 -0
  563. package/dist/tools/codegen/token-sync.js.map +1 -0
  564. package/dist/tools/codegen/tokens.d.ts +1 -1
  565. package/dist/tools/codegen.d.ts +2 -1
  566. package/dist/tools/codegen.js +2 -1
  567. package/dist/tools/create/basic.js +1 -1
  568. package/dist/tools/create/behaviours.js +1 -1
  569. package/dist/tools/create/components.d.ts.map +1 -1
  570. package/dist/tools/create/components.js +4 -0
  571. package/dist/tools/create/components.js.map +1 -1
  572. package/dist/tools/create/html.js +3 -2
  573. package/dist/tools/create/html.js.map +1 -1
  574. package/dist/tools/create/icons.d.ts.map +1 -1
  575. package/dist/tools/create/icons.js +2 -1
  576. package/dist/tools/create/icons.js.map +1 -1
  577. package/dist/tools/create/mermaid.js +2 -1
  578. package/dist/tools/create/mermaid.js.map +1 -1
  579. package/dist/tools/create/render.js +1 -1
  580. package/dist/tools/create/svg.js +2 -1
  581. package/dist/tools/create/svg.js.map +1 -1
  582. package/dist/tools/create/vector.js +1 -1
  583. package/dist/tools/design-memory.d.ts +8 -0
  584. package/dist/tools/design-memory.d.ts.map +1 -0
  585. package/dist/tools/design-memory.js +68 -0
  586. package/dist/tools/design-memory.js.map +1 -0
  587. package/dist/tools/image-ai/generate.d.ts.map +1 -1
  588. package/dist/tools/image-ai/generate.js +3 -1
  589. package/dist/tools/image-ai/generate.js.map +1 -1
  590. package/dist/tools/index.d.ts +2 -1
  591. package/dist/tools/index.js +2 -1
  592. package/dist/tools/modify/fonts.d.ts +6 -0
  593. package/dist/tools/modify/fonts.d.ts.map +1 -0
  594. package/dist/tools/modify/fonts.js +27 -0
  595. package/dist/tools/modify/fonts.js.map +1 -0
  596. package/dist/tools/modify/paint.js +1 -1
  597. package/dist/tools/modify/reactions.d.ts.map +1 -1
  598. package/dist/tools/modify/reactions.js +3 -3
  599. package/dist/tools/modify/reactions.js.map +1 -1
  600. package/dist/tools/modify/text.d.ts.map +1 -1
  601. package/dist/tools/modify/text.js +26 -5
  602. package/dist/tools/modify/text.js.map +1 -1
  603. package/dist/tools/modify/update.d.ts +10 -1
  604. package/dist/tools/modify/update.d.ts.map +1 -1
  605. package/dist/tools/modify/update.js +34 -3
  606. package/dist/tools/modify/update.js.map +1 -1
  607. package/dist/tools/modify.d.ts +2 -1
  608. package/dist/tools/modify.js +2 -1
  609. package/dist/tools/read/fonts.d.ts.map +1 -1
  610. package/dist/tools/read/fonts.js +17 -2
  611. package/dist/tools/read/fonts.js.map +1 -1
  612. package/dist/tools/read/libraries.js +2 -1
  613. package/dist/tools/read/libraries.js.map +1 -1
  614. package/dist/tools/read/space.d.ts +3 -1
  615. package/dist/tools/read/space.d.ts.map +1 -1
  616. package/dist/tools/read/space.js +4 -3
  617. package/dist/tools/read/space.js.map +1 -1
  618. package/dist/tools/registry/core.d.ts +1 -1
  619. package/dist/tools/registry/core.d.ts.map +1 -1
  620. package/dist/tools/registry/core.js +3 -1
  621. package/dist/tools/registry/core.js.map +1 -1
  622. package/dist/tools/registry/extended.d.ts.map +1 -1
  623. package/dist/tools/registry/extended.js +16 -1
  624. package/dist/tools/registry/extended.js.map +1 -1
  625. package/dist/tools/schema.d.ts +18 -2
  626. package/dist/tools/schema.d.ts.map +1 -1
  627. package/dist/tools/schema.js +1 -1
  628. package/dist/tools/schema.js.map +1 -1
  629. package/dist/tools/stock-photo.js +1 -0
  630. package/dist/tools/stock-photo.js.map +1 -1
  631. package/dist/tools/structure/basic.d.ts.map +1 -1
  632. package/dist/tools/structure/basic.js +1 -0
  633. package/dist/tools/structure/basic.js.map +1 -1
  634. package/dist/tools/structure/batch.d.ts.map +1 -1
  635. package/dist/tools/structure/batch.js +8 -1
  636. package/dist/tools/structure/batch.js.map +1 -1
  637. package/dist/tools/structure/hierarchy.d.ts.map +1 -1
  638. package/dist/tools/structure/hierarchy.js +4 -0
  639. package/dist/tools/structure/hierarchy.js.map +1 -1
  640. package/dist/tools/structure/variations.d.ts +8 -0
  641. package/dist/tools/structure/variations.d.ts.map +1 -0
  642. package/dist/tools/structure/variations.js +106 -0
  643. package/dist/tools/structure/variations.js.map +1 -0
  644. package/dist/tools/structure.d.ts +2 -1
  645. package/dist/tools/structure.js +2 -1
  646. package/dist/tools/styles/types.d.ts +2 -4
  647. package/dist/tools/styles/types.d.ts.map +1 -1
  648. package/dist/tools/styles/types.js.map +1 -1
  649. package/dist/tools/vector/boolean.d.ts.map +1 -1
  650. package/dist/tools/vector/boolean.js +4 -0
  651. package/dist/tools/vector/boolean.js.map +1 -1
  652. package/dist/tools/vector/vectorize.js +1 -0
  653. package/dist/tools/vector/vectorize.js.map +1 -1
  654. package/dist/tools/vector/video.d.ts +6 -0
  655. package/dist/tools/vector/video.d.ts.map +1 -0
  656. package/dist/tools/vector/video.js +133 -0
  657. package/dist/tools/vector/video.js.map +1 -0
  658. package/dist/tools/vector.d.ts +2 -1
  659. package/dist/tools/vector.js +2 -1
  660. package/dist/tools/video-host.d.ts +12 -0
  661. package/dist/tools/video-host.d.ts.map +1 -0
  662. package/dist/tools/video-host.js +19 -0
  663. package/dist/tools/video-host.js.map +1 -0
  664. package/dist/vector/point-transform.d.ts +1 -1
  665. package/dist/vector/vectorize/svg/to-vectors.d.ts +1 -1
  666. package/package.json +31 -9
  667. package/src/ai/providers.ts +2 -0
  668. package/src/cache/resource.ts +24 -1
  669. package/src/canvas/effects.ts +47 -50
  670. package/src/canvas/fills.ts +19 -15
  671. package/src/canvas/images/adjustments.ts +203 -0
  672. package/src/canvas/images/sampling.ts +88 -0
  673. package/src/canvas/index.ts +1 -0
  674. package/src/canvas/masks.ts +1 -1
  675. package/src/canvas/noise/render.ts +75 -0
  676. package/src/canvas/noise/shader.ts +161 -0
  677. package/src/canvas/noise/table.ts +91 -0
  678. package/src/canvas/noise/tile.ts +94 -0
  679. package/src/canvas/overlays/auto-layout-hover.ts +47 -65
  680. package/src/canvas/renderer/lifecycle.ts +6 -0
  681. package/src/canvas/renderer/pipeline.ts +19 -1
  682. package/src/canvas/renderer/play-scenes.ts +51 -0
  683. package/src/canvas/renderer/tiles/cache.ts +54 -1
  684. package/src/canvas/renderer/tiles/controller.ts +30 -1
  685. package/src/canvas/renderer/types.ts +18 -2
  686. package/src/canvas/renderer.ts +40 -3
  687. package/src/canvas/scene.ts +65 -9
  688. package/src/canvas/texture.ts +136 -0
  689. package/src/clipboard.ts +23 -10
  690. package/src/constants.ts +6 -0
  691. package/src/design-memory/check.ts +376 -0
  692. package/src/design-memory/describe.ts +77 -0
  693. package/src/design-memory/distil.ts +69 -0
  694. package/src/design-memory/document.ts +80 -0
  695. package/src/design-memory/guard.ts +157 -0
  696. package/src/design-memory/index.ts +8 -0
  697. package/src/design-memory/refusal.ts +90 -0
  698. package/src/design-memory/rules.ts +274 -0
  699. package/src/design-memory/values.ts +179 -0
  700. package/src/editor/bridges/components.ts +2 -0
  701. package/src/editor/clipboard/export.ts +24 -7
  702. package/src/editor/components/instances.ts +31 -0
  703. package/src/editor/create.ts +25 -69
  704. package/src/editor/design-memory.ts +39 -0
  705. package/src/editor/design-tokens.ts +41 -2
  706. package/src/editor/document-colors.ts +65 -0
  707. package/src/editor/eyedropper.ts +198 -0
  708. package/src/editor/fonts.ts +19 -0
  709. package/src/editor/history/atomic-tool.ts +29 -1
  710. package/src/editor/history/capture.ts +19 -0
  711. package/src/editor/history/document-change.ts +5 -17
  712. package/src/editor/history/edit.ts +11 -1
  713. package/src/editor/history/subtree.ts +13 -2
  714. package/src/editor/index.ts +11 -0
  715. package/src/editor/pages.ts +40 -29
  716. package/src/editor/play/states.ts +1 -1
  717. package/src/editor/read-only/actions.ts +4 -0
  718. package/src/editor/render-requests.ts +83 -0
  719. package/src/editor/selection/overlays.ts +1 -0
  720. package/src/editor/tool-registry.ts +2 -1
  721. package/src/editor/types.ts +4 -0
  722. package/src/editor/variations/create.ts +235 -0
  723. package/src/editor/variations/pick.ts +35 -0
  724. package/src/editor/variations.ts +110 -0
  725. package/src/figma-api/accessors/reactions.ts +11 -1
  726. package/src/figma-api/accessors/text/index.ts +7 -0
  727. package/src/figma-api/accessors/text/opentype.ts +33 -0
  728. package/src/figma-api/accessors/visual.ts +55 -2
  729. package/src/figma-api/compatibility.ts +5 -2
  730. package/src/figma-api/effects.ts +143 -5
  731. package/src/figma-api/index.ts +10 -0
  732. package/src/figma-api/overrides.ts +295 -3
  733. package/src/figma-api/paints.ts +24 -9
  734. package/src/figma-api/proxy.ts +6 -1
  735. package/src/figma-api/reactions.ts +130 -32
  736. package/src/figma-api/surface.ts +6 -2
  737. package/src/global.d.ts +26 -0
  738. package/src/io/formats/boolean-path.ts +60 -0
  739. package/src/io/formats/design-tokens/index.ts +21 -0
  740. package/src/io/formats/design-tokens/plan/changes.ts +4 -1
  741. package/src/io/formats/design-tokens/project.ts +40 -9
  742. package/src/io/formats/design-tokens/styles.ts +10 -2
  743. package/src/io/formats/design-tokens/sync/apply.ts +130 -0
  744. package/src/io/formats/design-tokens/sync/drift.ts +587 -0
  745. package/src/io/formats/design-tokens/sync/files.ts +40 -0
  746. package/src/io/formats/drawio/edges.ts +65 -0
  747. package/src/io/formats/drawio/export.ts +37 -14
  748. package/src/io/formats/drawio/index.ts +2 -0
  749. package/src/io/formats/fig/export/patch/index.ts +8 -0
  750. package/src/io/formats/fig/thumbnail-page.ts +4 -4
  751. package/src/io/formats/html/import.ts +9 -1
  752. package/src/io/formats/html/index.ts +14 -7
  753. package/src/io/formats/html/vectors.ts +8 -2
  754. package/src/io/formats/pdf/document.ts +14 -4
  755. package/src/io/formats/pen/imports.ts +5 -6
  756. package/src/io/formats/pen/index.ts +36 -5
  757. package/src/io/formats/raster/adjusted-images.ts +125 -0
  758. package/src/io/formats/raster/headless.ts +3 -3
  759. package/src/io/formats/raster/index.ts +6 -1
  760. package/src/io/formats/raster/pixels.ts +7 -0
  761. package/src/io/formats/raster/render.ts +12 -1
  762. package/src/io/formats/svg/defs.ts +4 -72
  763. package/src/io/formats/svg/effects.ts +131 -0
  764. package/src/io/formats/svg/export.ts +278 -46
  765. package/src/io/formats/svg/filter.ts +47 -0
  766. package/src/io/formats/svg/grain.ts +249 -0
  767. package/src/io/formats/svg/strokes.ts +2 -2
  768. package/src/io/formats/svg/text/layout.ts +13 -3
  769. package/src/io/formats/video/composite.ts +79 -0
  770. package/src/io/formats/video/formats.ts +77 -0
  771. package/src/io/formats/video/gif.ts +65 -0
  772. package/src/io/formats/video/index.ts +30 -0
  773. package/src/io/formats/video/plan.ts +116 -0
  774. package/src/io/formats/video/record.ts +227 -0
  775. package/src/io/formats/video/sink.ts +32 -0
  776. package/src/io/formats/video/size.ts +25 -0
  777. package/src/io/formats/video/webcodecs.ts +89 -0
  778. package/src/io/formats.ts +59 -11
  779. package/src/io/types.ts +29 -10
  780. package/src/layout/auto-layout-handles.ts +396 -0
  781. package/src/layout.ts +2 -0
  782. package/src/lint/fixes.ts +12 -3
  783. package/src/lint/index.ts +3 -1
  784. package/src/lint/linter.ts +107 -10
  785. package/src/lint/presets.ts +2 -0
  786. package/src/lint/rules/design-memory.ts +97 -0
  787. package/src/lint/rules/index.ts +6 -1
  788. package/src/lint/rules/no-unbound-token-values.ts +73 -0
  789. package/src/lint/types.ts +32 -0
  790. package/src/node/video.ts +196 -0
  791. package/src/pairdraw-api/design-memory.ts +61 -0
  792. package/src/pairdraw-api/index.ts +81 -0
  793. package/src/pairdraw-api/nodes.ts +38 -0
  794. package/src/pairdraw-api/variations.ts +109 -0
  795. package/src/prototype/easing.ts +37 -0
  796. package/src/prototype/frames.ts +9 -0
  797. package/src/prototype/hit.ts +70 -0
  798. package/src/prototype/index.ts +69 -0
  799. package/src/prototype/pointer.ts +146 -0
  800. package/src/prototype/reactions.ts +178 -0
  801. package/src/prototype/scene.ts +116 -0
  802. package/src/prototype/scenes.ts +256 -0
  803. package/src/prototype/scroll.ts +190 -0
  804. package/src/prototype/session.ts +188 -0
  805. package/src/prototype/smart-animate/animation.ts +267 -0
  806. package/src/prototype/smart-animate/match.ts +85 -0
  807. package/src/prototype/snapshot.ts +60 -0
  808. package/src/prototype/timeline.ts +400 -0
  809. package/src/text/font/features.ts +27 -0
  810. package/src/text/font/manager.ts +79 -1
  811. package/src/text/index.ts +2 -0
  812. package/src/text/replace-fonts.ts +171 -0
  813. package/src/tools/analyze/responsive/index.ts +264 -0
  814. package/src/tools/analyze.ts +2 -0
  815. package/src/tools/codegen/token-sync.ts +98 -0
  816. package/src/tools/codegen.ts +1 -0
  817. package/src/tools/create/components.ts +4 -0
  818. package/src/tools/create/html.ts +1 -0
  819. package/src/tools/create/icons.ts +1 -0
  820. package/src/tools/create/mermaid.ts +1 -0
  821. package/src/tools/create/svg.ts +1 -0
  822. package/src/tools/design-memory.ts +72 -0
  823. package/src/tools/image-ai/generate.ts +2 -0
  824. package/src/tools/index.ts +1 -0
  825. package/src/tools/modify/fonts.ts +34 -0
  826. package/src/tools/modify/reactions.ts +15 -8
  827. package/src/tools/modify/text.ts +42 -5
  828. package/src/tools/modify/update.ts +46 -2
  829. package/src/tools/modify.ts +1 -0
  830. package/src/tools/read/fonts.ts +24 -2
  831. package/src/tools/read/libraries.ts +1 -0
  832. package/src/tools/read/space.ts +3 -2
  833. package/src/tools/registry/core.ts +3 -1
  834. package/src/tools/registry/extended.ts +28 -1
  835. package/src/tools/schema.ts +28 -4
  836. package/src/tools/stock-photo.ts +1 -0
  837. package/src/tools/structure/basic.ts +1 -0
  838. package/src/tools/structure/batch.ts +12 -1
  839. package/src/tools/structure/hierarchy.ts +4 -0
  840. package/src/tools/structure/variations.ts +118 -0
  841. package/src/tools/structure.ts +2 -0
  842. package/src/tools/styles/types.ts +3 -4
  843. package/src/tools/vector/boolean.ts +4 -0
  844. package/src/tools/vector/vectorize.ts +1 -0
  845. package/src/tools/vector/video.ts +228 -0
  846. package/src/tools/vector.ts +1 -0
  847. package/src/tools/video-host.ts +18 -0
@@ -39,6 +39,6 @@ function countTokenImportChanges(graph, plan) {
39
39
  return plan.collections.reduce((count, collection) => count + collectionChanges(graph, plan, collection), plan.styles.length);
40
40
  }
41
41
  //#endregion
42
- export { countTokenImportChanges };
42
+ export { countTokenImportChanges, plannedValue };
43
43
 
44
44
  //# sourceMappingURL=changes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"changes.js","names":[],"sources":["../../../../../src/io/formats/design-tokens/plan/changes.ts"],"sourcesContent":["import { isEqual } from 'es-toolkit/predicate'\n\nimport type { SceneGraph, VariableValue } from '@pairdraw/scene-graph'\n\nimport type { PlannedCollection, PlannedValue, TokenImportPlan } from './index'\n\n/** The value a planned one sets, or undefined where it points at a variable the import adds. */\nfunction plannedValue(plan: TokenImportPlan, value: PlannedValue): VariableValue | undefined {\n if (value.kind === 'literal') return value.value\n const { target } = value\n if (target.kind === 'variable') return { aliasId: target.variableId }\n const existingId = plan.collections[target.collection]?.variables[target.variable]?.existingId\n return existingId ? { aliasId: existingId } : undefined\n}\n\nfunction collectionChanges(\n graph: SceneGraph,\n plan: TokenImportPlan,\n collection: PlannedCollection\n): number {\n if (collection.target.kind === 'new') return collection.variables.length + 1\n const newModes = collection.modes.filter((mode) => mode.target.kind === 'new').length\n let changed = newModes\n for (const variable of collection.variables) {\n const current = variable.existingId ? graph.variables.get(variable.existingId) : undefined\n if (!current) {\n changed++\n continue\n }\n // A changed unit or CSS expression counts even where the number it comes to is the same.\n const unitChanged = variable.unit !== undefined && variable.unit !== current.unit\n const differs = variable.values.some((value, index) => {\n const target = collection.modes.at(index)?.target\n if (!value || !target) return false\n if (target.kind !== 'existing') return true\n const next = plannedValue(plan, value)\n if (next === undefined || !isEqual(current.valuesByMode[target.modeId], next)) return true\n return variable.expressions[index] !== current.expressions?.[target.modeId]?.css\n })\n if (unitChanged || differs) changed++\n }\n return changed\n}\n\n/**\n * How many things an import would change: collections and modes it adds, variables it adds, and\n * variables whose values it changes, so an import that would only write what the document already\n * has can be left out. Styles count whenever they are planned.\n */\nexport function countTokenImportChanges(graph: SceneGraph, plan: TokenImportPlan): number {\n return plan.collections.reduce(\n (count, collection) => count + collectionChanges(graph, plan, collection),\n plan.styles.length\n )\n}\n"],"mappings":";;;AAOA,SAAS,aAAa,MAAuB,OAAgD;CAC3F,IAAI,MAAM,SAAS,WAAW,OAAO,MAAM;CAC3C,MAAM,EAAE,WAAW;CACnB,IAAI,OAAO,SAAS,YAAY,OAAO,EAAE,SAAS,OAAO,WAAW;CACpE,MAAM,aAAa,KAAK,YAAY,OAAO,WAAW,EAAE,UAAU,OAAO,SAAS,EAAE;CACpF,OAAO,aAAa,EAAE,SAAS,WAAW,IAAI,KAAA;AAChD;AAEA,SAAS,kBACP,OACA,MACA,YACQ;CACR,IAAI,WAAW,OAAO,SAAS,OAAO,OAAO,WAAW,UAAU,SAAS;CAE3E,IAAI,UADa,WAAW,MAAM,QAAQ,SAAS,KAAK,OAAO,SAAS,KAAK,CAAC,CAAC;CAE/E,KAAK,MAAM,YAAY,WAAW,WAAW;EAC3C,MAAM,UAAU,SAAS,aAAa,MAAM,UAAU,IAAI,SAAS,UAAU,IAAI,KAAA;EACjF,IAAI,CAAC,SAAS;GACZ;GACA;EACF;EAEA,MAAM,cAAc,SAAS,SAAS,KAAA,KAAa,SAAS,SAAS,QAAQ;EAC7E,MAAM,UAAU,SAAS,OAAO,MAAM,OAAO,UAAU;GACrD,MAAM,SAAS,WAAW,MAAM,GAAG,KAAK,CAAC,EAAE;GAC3C,IAAI,CAAC,SAAS,CAAC,QAAQ,OAAO;GAC9B,IAAI,OAAO,SAAS,YAAY,OAAO;GACvC,MAAM,OAAO,aAAa,MAAM,KAAK;GACrC,IAAI,SAAS,KAAA,KAAa,CAAC,QAAQ,QAAQ,aAAa,OAAO,SAAS,IAAI,GAAG,OAAO;GACtF,OAAO,SAAS,YAAY,WAAW,QAAQ,cAAc,OAAO,OAAO,EAAE;EAC/E,CAAC;EACD,IAAI,eAAe,SAAS;CAC9B;CACA,OAAO;AACT;;;;;;AAOA,SAAgB,wBAAwB,OAAmB,MAA+B;CACxF,OAAO,KAAK,YAAY,QACrB,OAAO,eAAe,QAAQ,kBAAkB,OAAO,MAAM,UAAU,GACxE,KAAK,OAAO,MACd;AACF"}
1
+ {"version":3,"file":"changes.js","names":[],"sources":["../../../../../src/io/formats/design-tokens/plan/changes.ts"],"sourcesContent":["import { isEqual } from 'es-toolkit/predicate'\n\nimport type { SceneGraph, VariableValue } from '@pairdraw/scene-graph'\n\nimport type { PlannedCollection, PlannedValue, TokenImportPlan } from './index'\n\n/** The value a planned one sets, or undefined where it points at a variable the import adds. */\nexport function plannedValue(\n plan: TokenImportPlan,\n value: PlannedValue\n): VariableValue | undefined {\n if (value.kind === 'literal') return value.value\n const { target } = value\n if (target.kind === 'variable') return { aliasId: target.variableId }\n const existingId = plan.collections[target.collection]?.variables[target.variable]?.existingId\n return existingId ? { aliasId: existingId } : undefined\n}\n\nfunction collectionChanges(\n graph: SceneGraph,\n plan: TokenImportPlan,\n collection: PlannedCollection\n): number {\n if (collection.target.kind === 'new') return collection.variables.length + 1\n const newModes = collection.modes.filter((mode) => mode.target.kind === 'new').length\n let changed = newModes\n for (const variable of collection.variables) {\n const current = variable.existingId ? graph.variables.get(variable.existingId) : undefined\n if (!current) {\n changed++\n continue\n }\n // A changed unit or CSS expression counts even where the number it comes to is the same.\n const unitChanged = variable.unit !== undefined && variable.unit !== current.unit\n const differs = variable.values.some((value, index) => {\n const target = collection.modes.at(index)?.target\n if (!value || !target) return false\n if (target.kind !== 'existing') return true\n const next = plannedValue(plan, value)\n if (next === undefined || !isEqual(current.valuesByMode[target.modeId], next)) return true\n return variable.expressions[index] !== current.expressions?.[target.modeId]?.css\n })\n if (unitChanged || differs) changed++\n }\n return changed\n}\n\n/**\n * How many things an import would change: collections and modes it adds, variables it adds, and\n * variables whose values it changes, so an import that would only write what the document already\n * has can be left out. Styles count whenever they are planned.\n */\nexport function countTokenImportChanges(graph: SceneGraph, plan: TokenImportPlan): number {\n return plan.collections.reduce(\n (count, collection) => count + collectionChanges(graph, plan, collection),\n plan.styles.length\n )\n}\n"],"mappings":";;;AAOA,SAAgB,aACd,MACA,OAC2B;CAC3B,IAAI,MAAM,SAAS,WAAW,OAAO,MAAM;CAC3C,MAAM,EAAE,WAAW;CACnB,IAAI,OAAO,SAAS,YAAY,OAAO,EAAE,SAAS,OAAO,WAAW;CACpE,MAAM,aAAa,KAAK,YAAY,OAAO,WAAW,EAAE,UAAU,OAAO,SAAS,EAAE;CACpF,OAAO,aAAa,EAAE,SAAS,WAAW,IAAI,KAAA;AAChD;AAEA,SAAS,kBACP,OACA,MACA,YACQ;CACR,IAAI,WAAW,OAAO,SAAS,OAAO,OAAO,WAAW,UAAU,SAAS;CAE3E,IAAI,UADa,WAAW,MAAM,QAAQ,SAAS,KAAK,OAAO,SAAS,KAAK,CAAC,CAAC;CAE/E,KAAK,MAAM,YAAY,WAAW,WAAW;EAC3C,MAAM,UAAU,SAAS,aAAa,MAAM,UAAU,IAAI,SAAS,UAAU,IAAI,KAAA;EACjF,IAAI,CAAC,SAAS;GACZ;GACA;EACF;EAEA,MAAM,cAAc,SAAS,SAAS,KAAA,KAAa,SAAS,SAAS,QAAQ;EAC7E,MAAM,UAAU,SAAS,OAAO,MAAM,OAAO,UAAU;GACrD,MAAM,SAAS,WAAW,MAAM,GAAG,KAAK,CAAC,EAAE;GAC3C,IAAI,CAAC,SAAS,CAAC,QAAQ,OAAO;GAC9B,IAAI,OAAO,SAAS,YAAY,OAAO;GACvC,MAAM,OAAO,aAAa,MAAM,KAAK;GACrC,IAAI,SAAS,KAAA,KAAa,CAAC,QAAQ,QAAQ,aAAa,OAAO,SAAS,IAAI,GAAG,OAAO;GACtF,OAAO,SAAS,YAAY,WAAW,QAAQ,cAAc,OAAO,OAAO,EAAE;EAC/E,CAAC;EACD,IAAI,eAAe,SAAS;CAC9B;CACA,OAAO;AACT;;;;;;AAOA,SAAgB,wBAAwB,OAAmB,MAA+B;CACxF,OAAO,KAAK,YAAY,QACrB,OAAO,eAAe,QAAQ,kBAAkB,OAAO,MAAM,UAAU,GACxE,KAAK,OAAO,MACd;AACF"}
@@ -1,4 +1,4 @@
1
- import { DesignTokenReadIssue, DesignTokenSourceFile } from "./read.js";
1
+ import { DesignTokenBundle, DesignTokenReadIssue, DesignTokenSourceFile } from "./read.js";
2
2
  import { SceneGraph } from "@pairdraw/scene-graph";
3
3
  //#region src/io/formats/design-tokens/project.d.ts
4
4
  /** A stylesheet or manifest the folder reader already loaded. Paths stay inside the folder. */
@@ -53,6 +53,21 @@ declare const DESIGN_SYSTEM_MAX_FILES = 200;
53
53
  declare const DESIGN_SYSTEM_MAX_TOTAL_BYTES: number;
54
54
  /** A relative path that cannot climb out of the folder it was given against. */
55
55
  declare function confinedDesignSystemPath(path: string): boolean;
56
+ /**
57
+ * The stylesheets a project folder's tokens come from: the one `components.json` names, or every
58
+ * stylesheet that declares custom properties. Paths that leave the folder and JavaScript config
59
+ * are reported, not read.
60
+ */
61
+ declare function designSystemStylesheets(folder: DesignSystemFolder): {
62
+ stylesheets: DesignSystemSourceFile[];
63
+ issues: DesignSystemIssue[];
64
+ manifestPath?: string;
65
+ };
66
+ /**
67
+ * One stylesheet of a project as a token bundle, read against the document as it is now. A
68
+ * shadcn/ui `:root` and `.dark` pair becomes Light and Dark modes; the bundle's issues are noted.
69
+ */
70
+ declare function readDesignSystemStylesheet(graph: SceneGraph, file: DesignSystemSourceFile, issues: DesignSystemIssue[]): DesignTokenBundle;
56
71
  /**
57
72
  * Imports CSS variables from files already read inside one project folder.
58
73
  * A shadcn/ui `:root` and `.dark` pair becomes one collection with Light and Dark modes.
@@ -60,5 +75,5 @@ declare function confinedDesignSystemPath(path: string): boolean;
60
75
  */
61
76
  declare function importDesignSystemFiles(graph: SceneGraph, folder: DesignSystemFolder): DesignSystemImportResult;
62
77
  //#endregion
63
- export { DESIGN_SYSTEM_MAX_FILES, DESIGN_SYSTEM_MAX_FILE_BYTES, DESIGN_SYSTEM_MAX_TOTAL_BYTES, DesignSystemFolder, DesignSystemImportResult, DesignSystemIssue, DesignSystemSourceFile, confinedDesignSystemPath, importDesignSystemFiles };
78
+ export { DESIGN_SYSTEM_MAX_FILES, DESIGN_SYSTEM_MAX_FILE_BYTES, DESIGN_SYSTEM_MAX_TOTAL_BYTES, DesignSystemFolder, DesignSystemImportResult, DesignSystemIssue, DesignSystemSourceFile, confinedDesignSystemPath, designSystemStylesheets, importDesignSystemFiles, readDesignSystemStylesheet };
64
79
  //# sourceMappingURL=project.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"project.d.ts","names":[],"sources":["../../../../src/io/formats/design-tokens/project.ts"],"mappings":";;;;KAeY,yBAAyB;KAEzB,oBACR;EACE;EAA0B;;EAC1B;EAA4B;;EAC5B;EAAsB;;EACtB;EAAwB;;EACxB;EAAwB;;EACxB;EAAyB;;EACzB;EAAoB;;EACpB;EAAiC;;EACjC;EAA2B;EAAc;EAAc;;;UAG5C;EACf,OAAO;EACP,QAAQ;;EAER;;UAGe;EACf;EACA;EACA,QAAQ;;;cAIG;;cAGA;;cAGA;;iBAsBG,yBAAyB;;;;;;iBA+HzB,wBACd,OAAO,YACP,QAAQ,qBACP"}
1
+ {"version":3,"file":"project.d.ts","names":[],"sources":["../../../../src/io/formats/design-tokens/project.ts"],"mappings":";;;;KAeY,yBAAyB;KAEzB,oBACR;EACE;EAA0B;;EAC1B;EAA4B;;EAC5B;EAAsB;;EACtB;EAAwB;;EACxB;EAAwB;;EACxB;EAAyB;;EACzB;EAAoB;;EACpB;EAAiC;;EACjC;EAA2B;EAAc;EAAc;;;UAG5C;EACf,OAAO;EACP,QAAQ;;EAER;;UAGe;EACf;EACA;EACA,QAAQ;;;cAIG;;cAGA;;cAGA;;iBAsBG,yBAAyB;;;;;;iBA0GzB,wBAAwB,QAAQ;EAC9C,aAAa;EACb,QAAQ;EACR;;;;;;iBAgBc,2BACd,OAAO,YACP,MAAM,wBACN,QAAQ,sBACP;;;;;;iBA+Ba,wBACd,OAAO,YACP,QAAQ,qBACP"}
@@ -124,10 +124,33 @@ function manifestChoice(files, issues) {
124
124
  path: manifest.path
125
125
  };
126
126
  }
127
- function importStylesheetFile(graph, pageId, file, issues) {
127
+ /**
128
+ * The stylesheets a project folder's tokens come from: the one `components.json` names, or every
129
+ * stylesheet that declares custom properties. Paths that leave the folder and JavaScript config
130
+ * are reported, not read.
131
+ */
132
+ function designSystemStylesheets(folder) {
133
+ const issues = [...folder.issues];
134
+ const files = confineFiles(folder, issues);
135
+ const manifest = manifestChoice(files, issues);
136
+ return {
137
+ stylesheets: stylesheets(files, manifest.stylesheet, issues),
138
+ issues,
139
+ manifestPath: manifest.path
140
+ };
141
+ }
142
+ /**
143
+ * One stylesheet of a project as a token bundle, read against the document as it is now. A
144
+ * shadcn/ui `:root` and `.dark` pair becomes Light and Dark modes; the bundle's issues are noted.
145
+ */
146
+ function readDesignSystemStylesheet(graph, file, issues) {
128
147
  const bundle = readCSSDesignTokens(graph, file.text, { file: file.path });
129
148
  renameShadcnModes(bundle);
130
149
  for (const issue of bundle.issues) addIssue(issues, issue);
150
+ return bundle;
151
+ }
152
+ function importStylesheetFile(graph, pageId, file, issues) {
153
+ const bundle = readDesignSystemStylesheet(graph, file, issues);
131
154
  const plan = planTokenImport(graph, bundle, defaultTokenImportOptions(graph, bundle));
132
155
  for (const skip of plan.skipped) addIssue(issues, {
133
156
  kind: "unsupported-value",
@@ -143,17 +166,15 @@ function importStylesheetFile(graph, pageId, file, issues) {
143
166
  * JavaScript config is reported and ignored. Component source is recorded and not imported.
144
167
  */
145
168
  function importDesignSystemFiles(graph, folder) {
146
- const issues = [...folder.issues];
147
- const files = confineFiles(folder, issues);
148
- const manifest = manifestChoice(files, issues);
149
- if (manifest.path || folder.componentsPath) addIssue(issues, {
169
+ const { stylesheets: files, issues, manifestPath } = designSystemStylesheets(folder);
170
+ if (manifestPath || folder.componentsPath) addIssue(issues, {
150
171
  kind: "components-not-imported",
151
- path: manifest.path ?? folder.componentsPath ?? "components.json"
172
+ path: manifestPath ?? folder.componentsPath ?? "components.json"
152
173
  });
153
174
  const pageId = graph.getPages()[0]?.id ?? graph.rootId;
154
175
  const collectionIds = [];
155
176
  const variableIds = [];
156
- for (const file of stylesheets(files, manifest.stylesheet, issues)) {
177
+ for (const file of files) {
157
178
  const imported = importStylesheetFile(graph, pageId, file, issues);
158
179
  collectionIds.push(...imported.collectionIds);
159
180
  variableIds.push(...imported.variableIds);
@@ -165,6 +186,6 @@ function importDesignSystemFiles(graph, folder) {
165
186
  };
166
187
  }
167
188
  //#endregion
168
- export { DESIGN_SYSTEM_MAX_FILES, DESIGN_SYSTEM_MAX_FILE_BYTES, DESIGN_SYSTEM_MAX_TOTAL_BYTES, confinedDesignSystemPath, importDesignSystemFiles };
189
+ export { DESIGN_SYSTEM_MAX_FILES, DESIGN_SYSTEM_MAX_FILE_BYTES, DESIGN_SYSTEM_MAX_TOTAL_BYTES, confinedDesignSystemPath, designSystemStylesheets, importDesignSystemFiles, readDesignSystemStylesheet };
169
190
 
170
191
  //# sourceMappingURL=project.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"project.js","names":[],"sources":["../../../../src/io/formats/design-tokens/project.ts"],"sourcesContent":["import { isAbsolute, normalize, posix } from 'pathe'\nimport * as v from 'valibot'\n\nimport type { SceneGraph } from '@pairdraw/scene-graph'\n\nimport { importTokensIntoGraph } from '#core/io/formats/design-tokens/apply'\nimport { readCSSDesignTokens } from '#core/io/formats/design-tokens/css/read'\nimport { defaultTokenImportOptions, planTokenImport } from '#core/io/formats/design-tokens/plan'\nimport type {\n DesignTokenBundle,\n DesignTokenReadIssue,\n DesignTokenSourceFile\n} from '#core/io/formats/design-tokens/read'\n\n/** A stylesheet or manifest the folder reader already loaded. Paths stay inside the folder. */\nexport type DesignSystemSourceFile = DesignTokenSourceFile\n\nexport type DesignSystemIssue =\n | DesignTokenReadIssue\n | { kind: 'invalid-manifest'; path: string }\n | { kind: 'unsupported-config'; path: string }\n | { kind: 'escaped-path'; path: string }\n | { kind: 'file-too-large'; path: string }\n | { kind: 'too-many-files'; path: string }\n | { kind: 'total-too-large'; path: string }\n | { kind: 'unreadable'; path: string }\n | { kind: 'components-not-imported'; path: string }\n | { kind: 'unsupported-value'; path: string; name: string; reason: string }\n\n/** Files and notes a folder walk hands to the importer. The walk itself stays in Node. */\nexport interface DesignSystemFolder {\n files: DesignSystemSourceFile[]\n issues: DesignSystemIssue[]\n /** Set when the folder has component source, which this import does not read. */\n componentsPath?: string\n}\n\nexport interface DesignSystemImportResult {\n collectionIds: string[]\n variableIds: string[]\n issues: DesignSystemIssue[]\n}\n\n/** Files larger than this are reported and not read. */\nexport const DESIGN_SYSTEM_MAX_FILE_BYTES = 1_048_576\n\n/** How many stylesheets and manifests a folder read keeps. The next one is reported and the walk stops. */\nexport const DESIGN_SYSTEM_MAX_FILES = 200\n\n/** Total bytes of files a folder read keeps. The file that would pass this is reported and the walk stops. */\nexport const DESIGN_SYSTEM_MAX_TOTAL_BYTES = 8 * DESIGN_SYSTEM_MAX_FILE_BYTES\n\nconst CONFIG_FILE = /^tailwind\\.config\\.(?:js|ts|mjs|cjs|cts|mts)$/\n\nconst manifestSchema = v.looseObject({\n tailwind: v.optional(\n v.looseObject({\n css: v.optional(v.string()),\n config: v.optional(v.string())\n })\n )\n})\n\nfunction sameIssue(left: DesignSystemIssue, right: DesignSystemIssue): boolean {\n return JSON.stringify(left) === JSON.stringify(right)\n}\n\nfunction addIssue(issues: DesignSystemIssue[], issue: DesignSystemIssue): void {\n if (!issues.some((existing) => sameIssue(existing, issue))) issues.push(issue)\n}\n\n/** A relative path that cannot climb out of the folder it was given against. */\nexport function confinedDesignSystemPath(path: string): boolean {\n if (path.trim() === '') return false\n const normalized = normalize(path)\n if (normalized === '.' || isAbsolute(normalized)) return false\n return !normalized.split('/').includes('..')\n}\n\nfunction isConfigFile(path: string): boolean {\n return CONFIG_FILE.test(posix.basename(normalize(path)))\n}\n\nfunction declaresCustomProperties(text: string): boolean {\n return /@theme\\b/.test(text) || /(?:^|[^\\w-])--[\\w-]+\\s*:/.test(text)\n}\n\n/** shadcn/ui writes the light values on `:root` and the dark values on `.dark`. */\nfunction renameShadcnModes(bundle: DesignTokenBundle): void {\n for (const collection of bundle.collections) {\n const base = collection.modes.find(\n (mode) => mode.isDefault && mode.name === 'Default' && mode.condition === undefined\n )\n const dark = collection.modes.find((mode) => mode.name === 'dark' && mode.condition === '.dark')\n if (!base || !dark) continue\n const taken = new Set(collection.modes.map((mode) => mode.name))\n if (taken.has('Light') || taken.has('Dark')) continue\n base.name = 'Light'\n dark.name = 'Dark'\n }\n}\n\nfunction stylesheets(\n files: readonly DesignSystemSourceFile[],\n named: string | null | undefined,\n issues: DesignSystemIssue[]\n): DesignSystemSourceFile[] {\n if (named === null) return []\n const css = files.filter((file) => posix.basename(file.path).endsWith('.css'))\n if (named === undefined) return css.filter((file) => declaresCustomProperties(file.text))\n const match = css.find((file) => posix.normalize(file.path) === named)\n if (!match) addIssue(issues, { kind: 'missing-file', file: named, from: 'components.json' })\n return match ? [match] : []\n}\n\nfunction confineFiles(\n folder: DesignSystemFolder,\n issues: DesignSystemIssue[]\n): DesignSystemSourceFile[] {\n const files: DesignSystemSourceFile[] = []\n for (const file of folder.files) {\n if (!confinedDesignSystemPath(file.path)) {\n addIssue(issues, { kind: 'escaped-path', path: file.path })\n continue\n }\n files.push(file)\n if (isConfigFile(file.path)) addIssue(issues, { kind: 'unsupported-config', path: file.path })\n }\n return files\n}\n\nfunction noteTailwindConfig(config: string | undefined, issues: DesignSystemIssue[]): void {\n const path = config?.trim()\n if (!path) return\n if (!confinedDesignSystemPath(path)) {\n addIssue(issues, { kind: 'escaped-path', path })\n return\n }\n if (isConfigFile(path)) addIssue(issues, { kind: 'unsupported-config', path })\n}\n\n/** `undefined` scans stylesheets that declare variables. `null` imports none. */\nfunction stylesheetNamedByManifest(\n css: string | undefined,\n issues: DesignSystemIssue[]\n): string | null | undefined {\n const path = css?.trim()\n if (!path) return undefined\n if (!confinedDesignSystemPath(path)) {\n addIssue(issues, { kind: 'escaped-path', path })\n return null\n }\n return posix.normalize(path)\n}\n\nfunction manifestChoice(\n files: readonly DesignSystemSourceFile[],\n issues: DesignSystemIssue[]\n): { stylesheet: string | null | undefined; path?: string } {\n const manifest = files.find((file) => posix.normalize(file.path) === 'components.json')\n if (!manifest) return { stylesheet: undefined }\n const parsed = v.safeParse(v.pipe(v.string(), v.parseJson(), manifestSchema), manifest.text)\n if (!parsed.success) {\n addIssue(issues, { kind: 'invalid-manifest', path: manifest.path })\n return { stylesheet: undefined, path: manifest.path }\n }\n noteTailwindConfig(parsed.output.tailwind?.config, issues)\n return {\n stylesheet: stylesheetNamedByManifest(parsed.output.tailwind?.css, issues),\n path: manifest.path\n }\n}\n\nfunction importStylesheetFile(\n graph: SceneGraph,\n pageId: string,\n file: DesignSystemSourceFile,\n issues: DesignSystemIssue[]\n): { collectionIds: string[]; variableIds: string[] } {\n const bundle = readCSSDesignTokens(graph, file.text, { file: file.path })\n renameShadcnModes(bundle)\n for (const issue of bundle.issues) addIssue(issues, issue)\n const plan = planTokenImport(graph, bundle, defaultTokenImportOptions(graph, bundle))\n for (const skip of plan.skipped) {\n addIssue(issues, {\n kind: 'unsupported-value',\n path: file.path,\n name: skip.name,\n reason: skip.reason\n })\n }\n return importTokensIntoGraph(graph, pageId, plan)\n}\n\n/**\n * Imports CSS variables from files already read inside one project folder.\n * A shadcn/ui `:root` and `.dark` pair becomes one collection with Light and Dark modes.\n * JavaScript config is reported and ignored. Component source is recorded and not imported.\n */\nexport function importDesignSystemFiles(\n graph: SceneGraph,\n folder: DesignSystemFolder\n): DesignSystemImportResult {\n const issues = [...folder.issues]\n const files = confineFiles(folder, issues)\n const manifest = manifestChoice(files, issues)\n if (manifest.path || folder.componentsPath) {\n addIssue(issues, {\n kind: 'components-not-imported',\n path: manifest.path ?? folder.componentsPath ?? 'components.json'\n })\n }\n\n const pageId = graph.getPages()[0]?.id ?? graph.rootId\n const collectionIds: string[] = []\n const variableIds: string[] = []\n for (const file of stylesheets(files, manifest.stylesheet, issues)) {\n const imported = importStylesheetFile(graph, pageId, file, issues)\n collectionIds.push(...imported.collectionIds)\n variableIds.push(...imported.variableIds)\n }\n return { collectionIds, variableIds, issues }\n}\n"],"mappings":";;;;;;;AA4CA,MAAa,+BAA+B;;AAG5C,MAAa,0BAA0B;;AAGvC,MAAa,g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AQ,aAAa,QAAQ,MAAM;CACzC,MAAM,WAAW,eAAe,OAAO,MAAM;CAC7C,IAAI,SAAS,QAAQ,OAAO,gBAC1B,SAAS,QAAQ;EACf,MAAM;EACN,MAAM,SAAS,QAAQ,OAAO,kBAAkB;CAClD,CAAC;CAGH,MAAM,SAAS,MAAM,SAAS,CAAC,CAAC,EAAE,EAAE,MAAM,MAAM;CAChD,MAAM,gBAA0B,CAAC;CACjC,MAAM,cAAwB,CAAC;CAC/B,KAAK,MAAM,QAAQ,YAAY,OAAO,SAAS,YAAY,MAAM,GAAG;EAClE,MAAM,WAAW,qBAAqB,OAAO,QAAQ,MAAM,MAAM;EACjE,cAAc,KAAK,GAAG,SAAS,aAAa;EAC5C,YAAY,KAAK,GAAG,SAAS,WAAW;CAC1C;CACA,OAAO;EAAE;EAAe;EAAa;CAAO;AAC9C"}
1
+ {"version":3,"file":"project.js","names":[],"sources":["../../../../src/io/formats/design-tokens/project.ts"],"sourcesContent":["import { isAbsolute, normalize, posix } from 'pathe'\nimport * as v from 'valibot'\n\nimport type { SceneGraph } from '@pairdraw/scene-graph'\n\nimport { importTokensIntoGraph } from '#core/io/formats/design-tokens/apply'\nimport { readCSSDesignTokens } from '#core/io/formats/design-tokens/css/read'\nimport { defaultTokenImportOptions, planTokenImport } from '#core/io/formats/design-tokens/plan'\nimport type {\n DesignTokenBundle,\n DesignTokenReadIssue,\n DesignTokenSourceFile\n} from '#core/io/formats/design-tokens/read'\n\n/** A stylesheet or manifest the folder reader already loaded. Paths stay inside the folder. */\nexport type DesignSystemSourceFile = DesignTokenSourceFile\n\nexport type DesignSystemIssue =\n | DesignTokenReadIssue\n | { kind: 'invalid-manifest'; path: string }\n | { kind: 'unsupported-config'; path: string }\n | { kind: 'escaped-path'; path: string }\n | { kind: 'file-too-large'; path: string }\n | { kind: 'too-many-files'; path: string }\n | { kind: 'total-too-large'; path: string }\n | { kind: 'unreadable'; path: string }\n | { kind: 'components-not-imported'; path: string }\n | { kind: 'unsupported-value'; path: string; name: string; reason: string }\n\n/** Files and notes a folder walk hands to the importer. The walk itself stays in Node. */\nexport interface DesignSystemFolder {\n files: DesignSystemSourceFile[]\n issues: DesignSystemIssue[]\n /** Set when the folder has component source, which this import does not read. */\n componentsPath?: string\n}\n\nexport interface DesignSystemImportResult {\n collectionIds: string[]\n variableIds: string[]\n issues: DesignSystemIssue[]\n}\n\n/** Files larger than this are reported and not read. */\nexport const DESIGN_SYSTEM_MAX_FILE_BYTES = 1_048_576\n\n/** How many stylesheets and manifests a folder read keeps. The next one is reported and the walk stops. */\nexport const DESIGN_SYSTEM_MAX_FILES = 200\n\n/** Total bytes of files a folder read keeps. The file that would pass this is reported and the walk stops. */\nexport const DESIGN_SYSTEM_MAX_TOTAL_BYTES = 8 * DESIGN_SYSTEM_MAX_FILE_BYTES\n\nconst CONFIG_FILE = /^tailwind\\.config\\.(?:js|ts|mjs|cjs|cts|mts)$/\n\nconst manifestSchema = v.looseObject({\n tailwind: v.optional(\n v.looseObject({\n css: v.optional(v.string()),\n config: v.optional(v.string())\n })\n )\n})\n\nfunction sameIssue(left: DesignSystemIssue, right: DesignSystemIssue): boolean {\n return JSON.stringify(left) === JSON.stringify(right)\n}\n\nfunction addIssue(issues: DesignSystemIssue[], issue: DesignSystemIssue): void {\n if (!issues.some((existing) => sameIssue(existing, issue))) issues.push(issue)\n}\n\n/** A relative path that cannot climb out of the folder it was given against. */\nexport function confinedDesignSystemPath(path: string): boolean {\n if (path.trim() === '') return false\n const normalized = normalize(path)\n if (normalized === '.' || isAbsolute(normalized)) return false\n return !normalized.split('/').includes('..')\n}\n\nfunction isConfigFile(path: string): boolean {\n return CONFIG_FILE.test(posix.basename(normalize(path)))\n}\n\nfunction declaresCustomProperties(text: string): boolean {\n return /@theme\\b/.test(text) || /(?:^|[^\\w-])--[\\w-]+\\s*:/.test(text)\n}\n\n/** shadcn/ui writes the light values on `:root` and the dark values on `.dark`. */\nfunction renameShadcnModes(bundle: DesignTokenBundle): void {\n for (const collection of bundle.collections) {\n const base = collection.modes.find(\n (mode) => mode.isDefault && mode.name === 'Default' && mode.condition === undefined\n )\n const dark = collection.modes.find((mode) => mode.name === 'dark' && mode.condition === '.dark')\n if (!base || !dark) continue\n const taken = new Set(collection.modes.map((mode) => mode.name))\n if (taken.has('Light') || taken.has('Dark')) continue\n base.name = 'Light'\n dark.name = 'Dark'\n }\n}\n\nfunction stylesheets(\n files: readonly DesignSystemSourceFile[],\n named: string | null | undefined,\n issues: DesignSystemIssue[]\n): DesignSystemSourceFile[] {\n if (named === null) return []\n const css = files.filter((file) => posix.basename(file.path).endsWith('.css'))\n if (named === undefined) return css.filter((file) => declaresCustomProperties(file.text))\n const match = css.find((file) => posix.normalize(file.path) === named)\n if (!match) addIssue(issues, { kind: 'missing-file', file: named, from: 'components.json' })\n return match ? [match] : []\n}\n\nfunction confineFiles(\n folder: DesignSystemFolder,\n issues: DesignSystemIssue[]\n): DesignSystemSourceFile[] {\n const files: DesignSystemSourceFile[] = []\n for (const file of folder.files) {\n if (!confinedDesignSystemPath(file.path)) {\n addIssue(issues, { kind: 'escaped-path', path: file.path })\n continue\n }\n files.push(file)\n if (isConfigFile(file.path)) addIssue(issues, { kind: 'unsupported-config', path: file.path })\n }\n return files\n}\n\nfunction noteTailwindConfig(config: string | undefined, issues: DesignSystemIssue[]): void {\n const path = config?.trim()\n if (!path) return\n if (!confinedDesignSystemPath(path)) {\n addIssue(issues, { kind: 'escaped-path', path })\n return\n }\n if (isConfigFile(path)) addIssue(issues, { kind: 'unsupported-config', path })\n}\n\n/** `undefined` scans stylesheets that declare variables. `null` imports none. */\nfunction stylesheetNamedByManifest(\n css: string | undefined,\n issues: DesignSystemIssue[]\n): string | null | undefined {\n const path = css?.trim()\n if (!path) return undefined\n if (!confinedDesignSystemPath(path)) {\n addIssue(issues, { kind: 'escaped-path', path })\n return null\n }\n return posix.normalize(path)\n}\n\nfunction manifestChoice(\n files: readonly DesignSystemSourceFile[],\n issues: DesignSystemIssue[]\n): { stylesheet: string | null | undefined; path?: string } {\n const manifest = files.find((file) => posix.normalize(file.path) === 'components.json')\n if (!manifest) return { stylesheet: undefined }\n const parsed = v.safeParse(v.pipe(v.string(), v.parseJson(), manifestSchema), manifest.text)\n if (!parsed.success) {\n addIssue(issues, { kind: 'invalid-manifest', path: manifest.path })\n return { stylesheet: undefined, path: manifest.path }\n }\n noteTailwindConfig(parsed.output.tailwind?.config, issues)\n return {\n stylesheet: stylesheetNamedByManifest(parsed.output.tailwind?.css, issues),\n path: manifest.path\n }\n}\n\n/**\n * The stylesheets a project folder's tokens come from: the one `components.json` names, or every\n * stylesheet that declares custom properties. Paths that leave the folder and JavaScript config\n * are reported, not read.\n */\nexport function designSystemStylesheets(folder: DesignSystemFolder): {\n stylesheets: DesignSystemSourceFile[]\n issues: DesignSystemIssue[]\n manifestPath?: string\n} {\n const issues = [...folder.issues]\n const files = confineFiles(folder, issues)\n const manifest = manifestChoice(files, issues)\n return {\n stylesheets: stylesheets(files, manifest.stylesheet, issues),\n issues,\n manifestPath: manifest.path\n }\n}\n\n/**\n * One stylesheet of a project as a token bundle, read against the document as it is now. A\n * shadcn/ui `:root` and `.dark` pair becomes Light and Dark modes; the bundle's issues are noted.\n */\nexport function readDesignSystemStylesheet(\n graph: SceneGraph,\n file: DesignSystemSourceFile,\n issues: DesignSystemIssue[]\n): DesignTokenBundle {\n const bundle = readCSSDesignTokens(graph, file.text, { file: file.path })\n renameShadcnModes(bundle)\n for (const issue of bundle.issues) addIssue(issues, issue)\n return bundle\n}\n\nfunction importStylesheetFile(\n graph: SceneGraph,\n pageId: string,\n file: DesignSystemSourceFile,\n issues: DesignSystemIssue[]\n): { collectionIds: string[]; variableIds: string[] } {\n const bundle = readDesignSystemStylesheet(graph, file, issues)\n const plan = planTokenImport(graph, bundle, defaultTokenImportOptions(graph, bundle))\n for (const skip of plan.skipped) {\n addIssue(issues, {\n kind: 'unsupported-value',\n path: file.path,\n name: skip.name,\n reason: skip.reason\n })\n }\n return importTokensIntoGraph(graph, pageId, plan)\n}\n\n/**\n * Imports CSS variables from files already read inside one project folder.\n * A shadcn/ui `:root` and `.dark` pair becomes one collection with Light and Dark modes.\n * JavaScript config is reported and ignored. Component source is recorded and not imported.\n */\nexport function importDesignSystemFiles(\n graph: SceneGraph,\n folder: DesignSystemFolder\n): DesignSystemImportResult {\n const { stylesheets: files, issues, manifestPath } = designSystemStylesheets(folder)\n if (manifestPath || folder.componentsPath) {\n addIssue(issues, {\n kind: 'components-not-imported',\n path: manifestPath ?? folder.componentsPath ?? 'components.json'\n })\n }\n\n const pageId = graph.getPages()[0]?.id ?? graph.rootId\n const collectionIds: string[] = []\n const variableIds: string[] = []\n for (const file of files) {\n const imported = importStylesheetFile(graph, pageId, file, issues)\n collectionIds.push(...imported.collectionIds)\n variableIds.push(...imported.variableIds)\n }\n return { collectionIds, variableIds, issues }\n}\n"],"mappings":";;;;;;;AA4CA,MAAa,+BAA+B;;AAG5C,MAAa,0BAA0B;;AAGvC,MAAa,gCAAgC,IAAI;AAEjD,MAAM,cAAc;AAEpB,MAAM,iBAAiB,EAAE,YAAY,EACnC,UAAU,EAAE,SACV,EAAE,YAAY;CACZ,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC;CAC1B,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC;AAC/B,CAAC,CACH,EACF,CAAC;AAED,SAAS,UAAU,MAAyB,OAAmC;CAC7E,OAAO,KAAK,UAAU,IAAI,MAAM,KAAK,UAAU,KAAK;AACtD;AAEA,SAAS,SAAS,QAA6B,OAAgC;CAC7E,IAAI,CAAC,OAAO,MAAM,aAAa,UAAU,UAAU,KAAK,CAAC,GAAG,OAAO,KAAK,KAAK;AAC/E;;AAGA,SAAgB,yBAAyB,MAAuB;CAC9D,IAAI,KAAK,KAAK,MAAM,IAAI,OAAO;CAC/B,MAAM,aAAa,UAAU,IAAI;CACjC,IAAI,eAAe,OAAO,WAAW,UAAU,GAAG,OAAO;CACzD,OAAO,CAAC,WAAW,MAAM,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BAAqB,OAAO,QAAQ,MAAM,MAAM;EACjE,cAAc,KAAK,GAAG,SAAS,aAAa;EAC5C,YAAY,KAAK,GAAG,SAAS,WAAW;CAC1C;CACA,OAAO;EAAE;EAAe;EAAa;CAAO;AAC9C"}
@@ -1 +1 @@
1
- {"version":3,"file":"styles.d.ts","names":[],"sources":["../../../../src/io/formats/design-tokens/styles.ts"],"mappings":";;;;KAaY,kBAAkB;;;;;UAMb;EACf;EACA;;cA+BI;KAcM,mBAAmB,KAC7B;;iBAKc,gBACd,MAAM,kBACN,OAAO,QAAQ,eAAe;;;;;;;;;;;;;iBA+ChB,SAAS,QAAQ,SAAS,UAAU;;iBAgBpC,iBAAiB,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8CnC,YACd,OAAO,YACP,YAAY;EACT,QAAQ;IAAQ;IAAgB,OAAO;;EAAgB,QAAQ;;;iBAwCpD,iBACd,OAAO,aACP,cACA,0BACC"}
1
+ {"version":3,"file":"styles.d.ts","names":[],"sources":["../../../../src/io/formats/design-tokens/styles.ts"],"mappings":";;;;KAmBY,kBAAkB;;;;;UAMb;EACf;EACA;;cA+BI;KAcM,mBAAmB,KAC7B;;iBAKc,gBACd,MAAM,kBACN,OAAO,QAAQ,eAAe;;;;;;;;;;;;;iBA+ChB,SAAS,QAAQ,SAAS,UAAU;;iBAgBpC,iBAAiB,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAgDnC,YACd,OAAO,YACP,YAAY;EACT,QAAQ;IAAQ;IAAgB,OAAO;;EAAgB,QAAQ;;;iBAwCpD,iBACd,OAAO,aACP,cACA,0BACC"}
@@ -1 +1 @@
1
- {"version":3,"file":"styles.js","names":[],"sources":["../../../../src/io/formats/design-tokens/styles.ts"],"sourcesContent":["import { countBy } from 'es-toolkit/array'\nimport { isEmptyObject, isPlainObject } from 'es-toolkit/predicate'\n\nimport type { Effect, ShadowEffect, SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { lineHeightPixels, textLengthPixels } from '@pairdraw/scene-graph/text'\n\nimport { toFigmaEffect } from '#core/figma-api/effects'\n\nimport { pathName, placeTokens, tokenPath, tokenReference } from './paths'\nimport { PAIRDRAW_EXTENSION, type DesignToken, type DesignTokenIssue } from './types'\nimport { colorTokenValue, dimensionTokenValue, trimNumber } from './values'\n\n/** Where a variable's token sits, for references to it. */\nexport type TokenReferences = ReadonlyMap<string, readonly string[]>\n\n/**\n * The variable a bound style field points at, by collection and name, as Figma's\n * `com.figma.aliasData` names an alias target, since a path alone can be in several collections.\n */\nexport interface BindingTarget {\n targetVariableSetName: string\n targetVariableName: string\n}\n\n/** The variables a style's bound fields point at, by field, for those a reference was written for. */\nfunction bindingTargets(\n graph: SceneGraph,\n node: SceneNode,\n fields: Iterable<string>\n): Record<string, BindingTarget> {\n const targets: Record<string, BindingTarget> = {}\n for (const field of fields) {\n const variable = graph.variables.get(node.boundVariables[field] ?? '')\n const collection = variable && graph.variableCollections.get(variable.collectionId)\n if (variable && collection)\n targets[field] = { targetVariableSetName: collection.name, targetVariableName: variable.name }\n }\n return targets\n}\n\n/** The fields a style binds and how a file read back finds each: its reference and its target. */\nfunction ownBindings(graph: SceneGraph, node: SceneNode, bindings: Record<string, string>) {\n const own: Record<string, unknown> = {}\n if (isEmptyObject(bindings)) return own\n own.bindings = bindings\n own.aliasData = bindingTargets(graph, node, Object.keys(bindings))\n return own\n}\n\n/** Figma's auto line height, written as the multiplier browsers use for `normal`. */\nconst AUTO_LINE_HEIGHT = 1.2\n\nconst TEXT_BINDING_FIELDS = ['fontFamily', 'fontSize', 'letterSpacing', 'lineHeight'] as const\n\nfunction bindingReferences(\n node: SceneNode,\n references: TokenReferences\n): Partial<Record<(typeof TEXT_BINDING_FIELDS)[number], string>> {\n const bound = TEXT_BINDING_FIELDS.flatMap((field) => {\n const variableId = node.boundVariables[field]\n const path = variableId ? references.get(variableId) : undefined\n return path ? [[field, tokenReference(path)] as const] : []\n })\n return Object.fromEntries(bound)\n}\n\nexport type TypographyFields = Pick<\n SceneNode,\n 'fontFamily' | 'fontSize' | 'fontWeight' | 'lineHeight' | 'letterSpacing'\n>\n\n/** A typography token's `$value`: bound fields as references to their variables' tokens. */\nexport function typographyValue(\n text: TypographyFields,\n bound: Partial<Record<(typeof TEXT_BINDING_FIELDS)[number], string>>\n) {\n // A typography token writes a line height as a multiple of the font size.\n const lineHeightPx = lineHeightPixels(text.lineHeight, text.fontSize)\n const lineHeight =\n lineHeightPx === null || text.fontSize <= 0\n ? AUTO_LINE_HEIGHT\n : trimNumber(lineHeightPx / text.fontSize)\n return {\n fontFamily: bound.fontFamily ?? text.fontFamily,\n fontSize: bound.fontSize ?? dimensionTokenValue(text.fontSize),\n fontWeight: text.fontWeight,\n lineHeight,\n letterSpacing:\n bound.letterSpacing ??\n dimensionTokenValue(textLengthPixels(text.letterSpacing, text.fontSize))\n }\n}\n\n/** A text style as a typography token; its own fields ride along so Pairdraw reads it back exactly. */\nfunction typographyToken(\n graph: SceneGraph,\n node: SceneNode,\n references: TokenReferences\n): DesignToken {\n const bound = bindingReferences(node, references)\n return {\n $type: 'typography',\n $value: typographyValue(node, bound),\n $extensions: {\n [PAIRDRAW_EXTENSION]: {\n text: {\n fontFamily: node.fontFamily,\n fontWeight: node.fontWeight,\n italic: node.italic,\n fontSize: node.fontSize,\n lineHeight: node.lineHeight,\n letterSpacing: node.letterSpacing,\n textDecoration: node.textDecoration,\n textCase: node.textCase\n },\n ...ownBindings(graph, node, bound)\n }\n }\n }\n}\n\nexport function isShadow(effect: Effect): effect is ShadowEffect {\n return effect.type === 'DROP_SHADOW' || effect.type === 'INNER_SHADOW'\n}\n\nfunction shadowValue(effect: ShadowEffect) {\n return {\n color: colorTokenValue(effect.color),\n offsetX: dimensionTokenValue(effect.offset.x),\n offsetY: dimensionTokenValue(effect.offset.y),\n blur: dimensionTokenValue(effect.radius),\n spread: dimensionTokenValue(effect.spread),\n ...(effect.type === 'INNER_SHADOW' ? { inset: true } : {})\n }\n}\n\n/** A shadow token's `$value`: the visible shadows of `effects`, or undefined when there are none. */\nexport function shadowTokenValue(effects: readonly Effect[]) {\n const values = effects\n .filter((effect): effect is ShadowEffect => isShadow(effect) && effect.visible)\n .map(shadowValue)\n if (values.length === 0) return undefined\n return values.length === 1 ? values[0] : values\n}\n\n/**\n * An effect style's shadows as a shadow token. Effects a shadow token cannot express, such as\n * blurs or hidden shadows, ride along whole in Pairdraw's extension, in the plugin API's shape;\n * a style with no visible shadow has no token.\n */\nfunction shadowToken(node: SceneNode): DesignToken | undefined {\n const $value = shadowTokenValue(node.effects)\n if ($value === undefined) return undefined\n const exact = node.effects.every(\n (effect) =>\n isShadow(effect) &&\n effect.visible &&\n (effect.blendMode ?? 'NORMAL') === 'NORMAL' &&\n effect.showShadowBehindNode !== true\n )\n return {\n $type: 'shadow',\n $value,\n ...(exact\n ? {}\n : {\n $extensions: {\n [PAIRDRAW_EXTENSION]: {\n effects: node.effects\n .filter((effect): effect is ShadowEffect => effect.type !== 'SHADER')\n .map(toFigmaEffect)\n }\n }\n })\n }\n}\n\n/** Whether a style's token writes a reference for this bound field. */\nfunction writesBinding(node: SceneNode, field: string): boolean {\n return node.sharedStyleType === 'TEXT' && TEXT_BINDING_FIELDS.some((bound) => bound === field)\n}\n\n/** Text and effect styles as typography and shadow tokens, nested by their names. */\nexport function styleTokens(\n graph: SceneGraph,\n references: TokenReferences\n): { tokens: Array<{ path: string[]; token: DesignToken }>; issues: DesignTokenIssue[] } {\n const issues: DesignTokenIssue[] = []\n const styles = [...graph.getAllNodes()].filter(\n (node) =>\n (node.sharedStyleType === 'TEXT' || node.sharedStyleType === 'EFFECT') &&\n node.source.id !== null\n )\n // Another tool reads a reference to a path several collections hold as whichever comes last.\n const shared = new Set(\n Object.entries(countBy([...references.values()], (path) => tokenReference(path)))\n .filter(([, count]) => count > 1)\n .map(([reference]) => reference)\n )\n const candidates = styles.flatMap((node) => {\n const token =\n node.sharedStyleType === 'TEXT' ? typographyToken(graph, node, references) : shadowToken(node)\n if (!token) {\n issues.push({ kind: 'unsupported-effect', style: node.name })\n return []\n }\n return [{ key: { node, token }, path: tokenPath(node.name) }]\n })\n const { placed, duplicates } = placeTokens(candidates)\n for (const { node } of duplicates)\n issues.push({ kind: 'duplicate-path', collection: 'Styles', token: node.name })\n for (const [{ node }] of placed) {\n for (const [field, variableId] of Object.entries(node.boundVariables)) {\n const path = writesBinding(node, field) ? references.get(variableId) : undefined\n if (path && shared.has(tokenReference(path)))\n issues.push({ kind: 'ambiguous-reference', style: node.name, field, token: pathName(path) })\n }\n }\n const tokens = [...placed].map(([{ node, token }, path]) => ({\n path,\n token: withOriginalName(token, node.name, path)\n }))\n return { tokens, issues }\n}\n\n/** Keeps a name the token path could not hold, such as one with a `.`, in Pairdraw's extension. */\nexport function withOriginalName(\n token: DesignToken,\n name: string,\n path: readonly string[]\n): DesignToken {\n if (pathName(path) === name) return token\n const own = token.$extensions?.[PAIRDRAW_EXTENSION]\n return {\n ...token,\n $extensions: {\n ...token.$extensions,\n [PAIRDRAW_EXTENSION]: { ...(isPlainObject(own) ? own : {}), name }\n }\n }\n}\n"],"mappings":";;;;;;;;;AAyBA,SAAS,eACP,OACA,MACA,QAC+B;CAC/B,MAAM,UAAyC,CAAC;CAChD,KAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,WAAW,MAAM,UAAU,IAAI,KAAK,eAAe,UAAU,EAAE;EACrE,MAAM,aAAa,YAAY,MAAM,oBAAoB,IAAI,SAAS,YAAY;EAClF,IAAI,YAAY,YACd,QAAQ,SAAS;GAAE,uBAAuB,WAAW;GAAM,oBAAoB,SAAS;EAAK;CACjG;CACA,OAAO;AACT;;AAGA,SAAS,YAAY,OAAmB,MAAiB,UAAkC;CACzF,MAAM,MAA+B,CAAC;CACtC,IAAI,cAAc,QAAQ,GAAG,OAAO;CACpC,IAAI,WAAW;CACf,IAAI,YAAY,eAAe,OAAO,MAAM,OA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O;EACL,GAAG;EACH,aAAa;GACX,GAAG,MAAM;IACR,qBAAqB;IAAE,GAAI,cAAc,GAAG,IAAI,MAAM,CAAC;IAAI;GAAK;EACnE;CACF;AACF"}
1
+ {"version":3,"file":"styles.js","names":[],"sources":["../../../../src/io/formats/design-tokens/styles.ts"],"sourcesContent":["import { countBy } from 'es-toolkit/array'\nimport { isEmptyObject, isPlainObject } from 'es-toolkit/predicate'\n\nimport type {\n Effect,\n SceneGraph,\n SceneNode,\n ShaderEffect,\n ShadowEffect\n} from '@pairdraw/scene-graph'\nimport { lineHeightPixels, textLengthPixels } from '@pairdraw/scene-graph/text'\n\nimport { toFigmaEffect } from '#core/figma-api/effects'\n\nimport { pathName, placeTokens, tokenPath, tokenReference } from './paths'\nimport { PAIRDRAW_EXTENSION, type DesignToken, type DesignTokenIssue } from './types'\nimport { colorTokenValue, dimensionTokenValue, trimNumber } from './values'\n\n/** Where a variable's token sits, for references to it. */\nexport type TokenReferences = ReadonlyMap<string, readonly string[]>\n\n/**\n * The variable a bound style field points at, by collection and name, as Figma's\n * `com.figma.aliasData` names an alias target, since a path alone can be in several collections.\n */\nexport interface BindingTarget {\n targetVariableSetName: string\n targetVariableName: string\n}\n\n/** The variables a style's bound fields point at, by field, for those a reference was written for. */\nfunction bindingTargets(\n graph: SceneGraph,\n node: SceneNode,\n fields: Iterable<string>\n): Record<string, BindingTarget> {\n const targets: Record<string, BindingTarget> = {}\n for (const field of fields) {\n const variable = graph.variables.get(node.boundVariables[field] ?? '')\n const collection = variable && graph.variableCollections.get(variable.collectionId)\n if (variable && collection)\n targets[field] = { targetVariableSetName: collection.name, targetVariableName: variable.name }\n }\n return targets\n}\n\n/** The fields a style binds and how a file read back finds each: its reference and its target. */\nfunction ownBindings(graph: SceneGraph, node: SceneNode, bindings: Record<string, string>) {\n const own: Record<string, unknown> = {}\n if (isEmptyObject(bindings)) return own\n own.bindings = bindings\n own.aliasData = bindingTargets(graph, node, Object.keys(bindings))\n return own\n}\n\n/** Figma's auto line height, written as the multiplier browsers use for `normal`. */\nconst AUTO_LINE_HEIGHT = 1.2\n\nconst TEXT_BINDING_FIELDS = ['fontFamily', 'fontSize', 'letterSpacing', 'lineHeight'] as const\n\nfunction bindingReferences(\n node: SceneNode,\n references: TokenReferences\n): Partial<Record<(typeof TEXT_BINDING_FIELDS)[number], string>> {\n const bound = TEXT_BINDING_FIELDS.flatMap((field) => {\n const variableId = node.boundVariables[field]\n const path = variableId ? references.get(variableId) : undefined\n return path ? [[field, tokenReference(path)] as const] : []\n })\n return Object.fromEntries(bound)\n}\n\nexport type TypographyFields = Pick<\n SceneNode,\n 'fontFamily' | 'fontSize' | 'fontWeight' | 'lineHeight' | 'letterSpacing'\n>\n\n/** A typography token's `$value`: bound fields as references to their variables' tokens. */\nexport function typographyValue(\n text: TypographyFields,\n bound: Partial<Record<(typeof TEXT_BINDING_FIELDS)[number], string>>\n) {\n // A typography token writes a line height as a multiple of the font size.\n const lineHeightPx = lineHeightPixels(text.lineHeight, text.fontSize)\n const lineHeight =\n lineHeightPx === null || text.fontSize <= 0\n ? AUTO_LINE_HEIGHT\n : trimNumber(lineHeightPx / text.fontSize)\n return {\n fontFamily: bound.fontFamily ?? text.fontFamily,\n fontSize: bound.fontSize ?? dimensionTokenValue(text.fontSize),\n fontWeight: text.fontWeight,\n lineHeight,\n letterSpacing:\n bound.letterSpacing ??\n dimensionTokenValue(textLengthPixels(text.letterSpacing, text.fontSize))\n }\n}\n\n/** A text style as a typography token; its own fields ride along so Pairdraw reads it back exactly. */\nfunction typographyToken(\n graph: SceneGraph,\n node: SceneNode,\n references: TokenReferences\n): DesignToken {\n const bound = bindingReferences(node, references)\n return {\n $type: 'typography',\n $value: typographyValue(node, bound),\n $extensions: {\n [PAIRDRAW_EXTENSION]: {\n text: {\n fontFamily: node.fontFamily,\n fontWeight: node.fontWeight,\n italic: node.italic,\n fontSize: node.fontSize,\n lineHeight: node.lineHeight,\n letterSpacing: node.letterSpacing,\n textDecoration: node.textDecoration,\n textCase: node.textCase\n },\n ...ownBindings(graph, node, bound)\n }\n }\n }\n}\n\nexport function isShadow(effect: Effect): effect is ShadowEffect {\n return effect.type === 'DROP_SHADOW' || effect.type === 'INNER_SHADOW'\n}\n\nfunction shadowValue(effect: ShadowEffect) {\n return {\n color: colorTokenValue(effect.color),\n offsetX: dimensionTokenValue(effect.offset.x),\n offsetY: dimensionTokenValue(effect.offset.y),\n blur: dimensionTokenValue(effect.radius),\n spread: dimensionTokenValue(effect.spread),\n ...(effect.type === 'INNER_SHADOW' ? { inset: true } : {})\n }\n}\n\n/** A shadow token's `$value`: the visible shadows of `effects`, or undefined when there are none. */\nexport function shadowTokenValue(effects: readonly Effect[]) {\n const values = effects\n .filter((effect): effect is ShadowEffect => isShadow(effect) && effect.visible)\n .map(shadowValue)\n if (values.length === 0) return undefined\n return values.length === 1 ? values[0] : values\n}\n\n/**\n * An effect style's shadows as a shadow token. Effects a shadow token cannot express, such as\n * blurs or hidden shadows, ride along whole in Pairdraw's extension, in the plugin API's shape;\n * a style with no visible shadow has no token.\n */\nfunction shadowToken(node: SceneNode): DesignToken | undefined {\n const $value = shadowTokenValue(node.effects)\n if ($value === undefined) return undefined\n const exact = node.effects.every(\n (effect) =>\n isShadow(effect) &&\n effect.visible &&\n (effect.blendMode ?? 'NORMAL') === 'NORMAL' &&\n effect.showShadowBehindNode !== true\n )\n return {\n $type: 'shadow',\n $value,\n ...(exact\n ? {}\n : {\n $extensions: {\n [PAIRDRAW_EXTENSION]: {\n effects: node.effects\n .filter(\n (effect): effect is Exclude<Effect, ShaderEffect> => effect.type !== 'SHADER'\n )\n .map(toFigmaEffect)\n }\n }\n })\n }\n}\n\n/** Whether a style's token writes a reference for this bound field. */\nfunction writesBinding(node: SceneNode, field: string): boolean {\n return node.sharedStyleType === 'TEXT' && TEXT_BINDING_FIELDS.some((bound) => bound === field)\n}\n\n/** Text and effect styles as typography and shadow tokens, nested by their names. */\nexport function styleTokens(\n graph: SceneGraph,\n references: TokenReferences\n): { tokens: Array<{ path: string[]; token: DesignToken }>; issues: DesignTokenIssue[] } {\n const issues: DesignTokenIssue[] = []\n const styles = [...graph.getAllNodes()].filter(\n (node) =>\n (node.sharedStyleType === 'TEXT' || node.sharedStyleType === 'EFFECT') &&\n node.source.id !== null\n )\n // Another tool reads a reference to a path several collections hold as whichever comes last.\n const shared = new Set(\n Object.entries(countBy([...references.values()], (path) => tokenReference(path)))\n .filter(([, count]) => count > 1)\n .map(([reference]) => reference)\n )\n const candidates = styles.flatMap((node) => {\n const token =\n node.sharedStyleType === 'TEXT' ? typographyToken(graph, node, references) : shadowToken(node)\n if (!token) {\n issues.push({ kind: 'unsupported-effect', style: node.name })\n return []\n }\n return [{ key: { node, token }, path: tokenPath(node.name) }]\n })\n const { placed, duplicates } = placeTokens(candidates)\n for (const { node } of duplicates)\n issues.push({ kind: 'duplicate-path', collection: 'Styles', token: node.name })\n for (const [{ node }] of placed) {\n for (const [field, variableId] of Object.entries(node.boundVariables)) {\n const path = writesBinding(node, field) ? references.get(variableId) : undefined\n if (path && shared.has(tokenReference(path)))\n issues.push({ kind: 'ambiguous-reference', style: node.name, field, token: pathName(path) })\n }\n }\n const tokens = [...placed].map(([{ node, token }, path]) => ({\n path,\n token: withOriginalName(token, node.name, path)\n }))\n return { tokens, issues }\n}\n\n/** Keeps a name the token path could not hold, such as one with a `.`, in Pairdraw's extension. */\nexport function withOriginalName(\n token: DesignToken,\n name: string,\n path: readonly string[]\n): DesignToken {\n if (pathName(path) === name) return token\n const own = token.$extensions?.[PAIRDRAW_EXTENSION]\n return {\n ...token,\n $extensions: {\n ...token.$extensions,\n [PAIRDRAW_EXTENSION]: { ...(isPlainObject(own) ? own : {}), name }\n }\n }\n}\n"],"mappings":";;;;;;;;;AA+BA,SAAS,eACP,OACA,MACA,QAC+B;CAC/B,MAAM,UAAyC,CAAC;CAChD,KAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,WAAW,MAAM,UAAU,IAAI,KAAK,eAAe,UAAU,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AO,SAAS,IAAI;EAAE,CAAC;CAC/F;CAMF,OAAO;EAAE,QAJM,CAAC,GAAG,MAAM,CAAC,CAAC,KAAK,CAAC,EAAE,MAAM,SAAS,WAAW;GAC3D;GACA,OAAO,iBAAiB,OAAO,KAAK,MAAM,IAAI;EAChD,EACc;EAAG;CAAO;AAC1B;;AAGA,SAAgB,iBACd,OACA,MACA,MACa;CACb,IAAI,SAAS,IAAI,MAAM,MAAM,OAAO;CACpC,MAAM,MAAM,MAAM,cAAc;CAChC,OAAO;EACL,GAAG;EACH,aAAa;GACX,GAAG,MAAM;IACR,qBAAqB;IAAE,GAAI,cAAc,GAAG,IAAI,MAAM,CAAC;IAAI;GAAK;EACnE;CACF;AACF"}
@@ -0,0 +1,42 @@
1
+ import { DesignTokenBundle, DesignTokenSourceFile } from "../read.js";
2
+ import { DesignSystemIssue } from "../project.js";
3
+ import { TokenDrift, TokenSyncChoice, TokenSyncResolution } from "./drift.js";
4
+ import { SceneGraph } from "@pairdraw/scene-graph";
5
+ import { TokenSource } from "@pairdraw/scene-graph/token-sources";
6
+ //#region src/io/formats/design-tokens/sync/apply.d.ts
7
+ /** A link as a sync records it, before it learns what the code holds. */
8
+ type TokenSourceLink = Omit<TokenSource, 'snapshot' | 'syncedAt'>;
9
+ /**
10
+ * The document's links with `link` recorded as synced now, its snapshot taken from the code once
11
+ * the resolution's imports are applied. A link already there keeps its place.
12
+ */
13
+ declare function syncedTokenSources(graph: SceneGraph, link: TokenSourceLink, bundles: readonly DesignTokenBundle[], resolution: TokenSyncResolution): TokenSource[];
14
+ /** Applies a resolved sync straight to a graph and records the link, for tools and the CLI. */
15
+ declare function syncTokensIntoGraph(graph: SceneGraph, link: TokenSourceLink, bundles: readonly DesignTokenBundle[], resolution: TokenSyncResolution): void;
16
+ /**
17
+ * The link some files of linked code belong to. Given `path`, their place from the document's
18
+ * folder, it is the link recorded there, or one recorded by name only; two files of one name in
19
+ * different folders are two links. Without it, a link whose path or file name is one of theirs.
20
+ * Files no link names are compared without a snapshot.
21
+ */
22
+ declare function tokenSourceForFiles(graph: SceneGraph, files: readonly DesignTokenSourceFile[], path?: string): TokenSource | undefined;
23
+ interface TokenFilesSync {
24
+ /** Tokens that came in or had a side picked. */
25
+ applied: number;
26
+ /** Drift left for a person to review. */
27
+ left: TokenDrift[];
28
+ issues: DesignSystemIssue[];
29
+ }
30
+ /**
31
+ * Syncs a headless document with linked code read from files, for tools and the CLI: what changed
32
+ * only in code and what is new there comes in, a token changed on the canvas or on both sides
33
+ * takes `conflicts` (left as it is by default), and the link is recorded under `path`, a path
34
+ * from the document's folder, when one is known.
35
+ */
36
+ declare function syncTokenFiles(graph: SceneGraph, files: readonly DesignTokenSourceFile[], options?: {
37
+ conflicts?: TokenSyncChoice;
38
+ path?: string;
39
+ }): TokenFilesSync;
40
+ //#endregion
41
+ export { TokenFilesSync, TokenSourceLink, syncTokenFiles, syncTokensIntoGraph, syncedTokenSources, tokenSourceForFiles };
42
+ //# sourceMappingURL=apply.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apply.d.ts","names":[],"sources":["../../../../../src/io/formats/design-tokens/sync/apply.ts"],"mappings":";;;;;;;KAwBY,kBAAkB,KAAK;;;;;iBAMnB,mBACd,OAAO,YACP,MAAM,iBACN,kBAAkB,qBAClB,YAAY,sBACX;;iBAca,oBACd,OAAO,YACP,MAAM,iBACN,kBAAkB,qBAClB,YAAY;;;;;;;iBAeE,oBACd,OAAO,YACP,gBAAgB,yBAChB,gBACC;UA8Bc;;EAEf;;EAEA,MAAM;EACN,QAAQ;;;;;;;;iBASM,eACd,OAAO,YACP,gBAAgB,yBAChB;EAAW,YAAY;EAAiB;IACvC"}
@@ -0,0 +1,73 @@
1
+ import { importTokensIntoGraph } from "../apply.js";
2
+ import { planTokenSync, tokenSnapshot } from "./drift.js";
3
+ import { readTokenSourceFiles } from "./files.js";
4
+ import { randomHex } from "@pairdraw/scene-graph/random";
5
+ import { readTokenSources, tokenSourcesPluginData } from "@pairdraw/scene-graph/token-sources";
6
+ import { posix } from "pathe";
7
+ //#region src/io/formats/design-tokens/sync/apply.ts
8
+ /**
9
+ * The document's links with `link` recorded as synced now, its snapshot taken from the code once
10
+ * the resolution's imports are applied. A link already there keeps its place.
11
+ */
12
+ function syncedTokenSources(graph, link, bundles, resolution) {
13
+ const sources = readTokenSources(graph);
14
+ const previous = sources.find((source) => source.id === link.id);
15
+ const synced = {
16
+ ...link,
17
+ syncedAt: (/* @__PURE__ */ new Date()).toISOString(),
18
+ ...tokenSnapshot(graph, bundles, previous, resolution.undecided)
19
+ };
20
+ return previous ? sources.map((source) => source === previous ? synced : source) : [...sources, synced];
21
+ }
22
+ /** Applies a resolved sync straight to a graph and records the link, for tools and the CLI. */
23
+ function syncTokensIntoGraph(graph, link, bundles, resolution) {
24
+ const pageId = graph.getPages()[0]?.id ?? graph.rootId;
25
+ for (const plan of resolution.plans) importTokensIntoGraph(graph, pageId, plan);
26
+ graph.updateNode(graph.rootId, { pluginData: tokenSourcesPluginData(graph, syncedTokenSources(graph, link, bundles, resolution)) });
27
+ }
28
+ /**
29
+ * The link some files of linked code belong to. Given `path`, their place from the document's
30
+ * folder, it is the link recorded there, or one recorded by name only; two files of one name in
31
+ * different folders are two links. Without it, a link whose path or file name is one of theirs.
32
+ * Files no link names are compared without a snapshot.
33
+ */
34
+ function tokenSourceForFiles(graph, files, path) {
35
+ const sources = readTokenSources(graph);
36
+ if (path !== void 0) {
37
+ const place = posix.normalize(path);
38
+ return sources.find((source) => source.path && posix.normalize(source.path) === place) ?? sources.find((source) => !source.path && source.name === posix.basename(place));
39
+ }
40
+ const paths = files.map((file) => posix.normalize(file.path));
41
+ return sources.find((source) => source.path && paths.includes(posix.normalize(source.path))) ?? sources.find((source) => paths.some((entry) => posix.basename(entry) === source.name));
42
+ }
43
+ /** A link for files no link names yet, named after where they are. */
44
+ function newLink(files, path) {
45
+ const stylesheets = files.every((file) => posix.basename(file.path).endsWith(".css"));
46
+ return {
47
+ id: randomHex(12),
48
+ kind: stylesheets ? files.length > 1 ? "folder" : "css" : "dtcg",
49
+ name: posix.basename(path ?? files.at(0)?.path ?? "tokens"),
50
+ ...path ? { path } : {}
51
+ };
52
+ }
53
+ /**
54
+ * Syncs a headless document with linked code read from files, for tools and the CLI: what changed
55
+ * only in code and what is new there comes in, a token changed on the canvas or on both sides
56
+ * takes `conflicts` (left as it is by default), and the link is recorded under `path`, a path
57
+ * from the document's folder, when one is known.
58
+ */
59
+ function syncTokenFiles(graph, files, options = {}) {
60
+ const { bundles, issues } = readTokenSourceFiles(graph, files);
61
+ const linked = tokenSourceForFiles(graph, files, options.path);
62
+ const resolution = planTokenSync(graph, bundles, linked).resolve((drift) => drift.kind === "missing" ? void 0 : options.conflicts);
63
+ syncTokensIntoGraph(graph, linked ?? newLink(files, options.path), bundles, resolution);
64
+ return {
65
+ applied: resolution.applied,
66
+ left: resolution.undecided,
67
+ issues
68
+ };
69
+ }
70
+ //#endregion
71
+ export { syncTokenFiles, syncTokensIntoGraph, syncedTokenSources, tokenSourceForFiles };
72
+
73
+ //# sourceMappingURL=apply.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apply.js","names":[],"sources":["../../../../../src/io/formats/design-tokens/sync/apply.ts"],"sourcesContent":["import { posix } from 'pathe'\n\nimport type { SceneGraph } from '@pairdraw/scene-graph'\nimport { randomHex } from '@pairdraw/scene-graph/random'\nimport {\n readTokenSources,\n tokenSourcesPluginData,\n type TokenSource\n} from '@pairdraw/scene-graph/token-sources'\n\nimport { importTokensIntoGraph } from '#core/io/formats/design-tokens/apply'\nimport type { DesignSystemIssue } from '#core/io/formats/design-tokens/project'\nimport type { DesignTokenBundle, DesignTokenSourceFile } from '#core/io/formats/design-tokens/read'\n\nimport {\n planTokenSync,\n tokenSnapshot,\n type TokenDrift,\n type TokenSyncChoice,\n type TokenSyncResolution\n} from './drift'\nimport { readTokenSourceFiles } from './files'\n\n/** A link as a sync records it, before it learns what the code holds. */\nexport type TokenSourceLink = Omit<TokenSource, 'snapshot' | 'syncedAt'>\n\n/**\n * The document's links with `link` recorded as synced now, its snapshot taken from the code once\n * the resolution's imports are applied. A link already there keeps its place.\n */\nexport function syncedTokenSources(\n graph: SceneGraph,\n link: TokenSourceLink,\n bundles: readonly DesignTokenBundle[],\n resolution: TokenSyncResolution\n): TokenSource[] {\n const sources = readTokenSources(graph)\n const previous = sources.find((source) => source.id === link.id)\n const synced: TokenSource = {\n ...link,\n syncedAt: new Date().toISOString(),\n ...tokenSnapshot(graph, bundles, previous, resolution.undecided)\n }\n return previous\n ? sources.map((source) => (source === previous ? synced : source))\n : [...sources, synced]\n}\n\n/** Applies a resolved sync straight to a graph and records the link, for tools and the CLI. */\nexport function syncTokensIntoGraph(\n graph: SceneGraph,\n link: TokenSourceLink,\n bundles: readonly DesignTokenBundle[],\n resolution: TokenSyncResolution\n): void {\n const pageId = graph.getPages()[0]?.id ?? graph.rootId\n for (const plan of resolution.plans) importTokensIntoGraph(graph, pageId, plan)\n graph.updateNode(graph.rootId, {\n pluginData: tokenSourcesPluginData(graph, syncedTokenSources(graph, link, bundles, resolution))\n })\n}\n\n/**\n * The link some files of linked code belong to. Given `path`, their place from the document's\n * folder, it is the link recorded there, or one recorded by name only; two files of one name in\n * different folders are two links. Without it, a link whose path or file name is one of theirs.\n * Files no link names are compared without a snapshot.\n */\nexport function tokenSourceForFiles(\n graph: SceneGraph,\n files: readonly DesignTokenSourceFile[],\n path?: string\n): TokenSource | undefined {\n const sources = readTokenSources(graph)\n if (path !== undefined) {\n const place = posix.normalize(path)\n return (\n sources.find((source) => source.path && posix.normalize(source.path) === place) ??\n sources.find((source) => !source.path && source.name === posix.basename(place))\n )\n }\n const paths = files.map((file) => posix.normalize(file.path))\n return (\n sources.find((source) => source.path && paths.includes(posix.normalize(source.path))) ??\n sources.find((source) => paths.some((entry) => posix.basename(entry) === source.name))\n )\n}\n\n/** A link for files no link names yet, named after where they are. */\nfunction newLink(\n files: readonly DesignTokenSourceFile[],\n path: string | undefined\n): TokenSourceLink {\n const stylesheets = files.every((file) => posix.basename(file.path).endsWith('.css'))\n return {\n id: randomHex(12),\n kind: stylesheets ? (files.length > 1 ? 'folder' : 'css') : 'dtcg',\n name: posix.basename(path ?? files.at(0)?.path ?? 'tokens'),\n ...(path ? { path } : {})\n }\n}\n\nexport interface TokenFilesSync {\n /** Tokens that came in or had a side picked. */\n applied: number\n /** Drift left for a person to review. */\n left: TokenDrift[]\n issues: DesignSystemIssue[]\n}\n\n/**\n * Syncs a headless document with linked code read from files, for tools and the CLI: what changed\n * only in code and what is new there comes in, a token changed on the canvas or on both sides\n * takes `conflicts` (left as it is by default), and the link is recorded under `path`, a path\n * from the document's folder, when one is known.\n */\nexport function syncTokenFiles(\n graph: SceneGraph,\n files: readonly DesignTokenSourceFile[],\n options: { conflicts?: TokenSyncChoice; path?: string } = {}\n): TokenFilesSync {\n const { bundles, issues } = readTokenSourceFiles(graph, files)\n const linked = tokenSourceForFiles(graph, files, options.path)\n const sync = planTokenSync(graph, bundles, linked)\n const resolution = sync.resolve((drift) =>\n drift.kind === 'missing' ? undefined : options.conflicts\n )\n syncTokensIntoGraph(graph, linked ?? newLink(files, options.path), bundles, resolution)\n return { applied: resolution.applied, left: resolution.undecided, issues }\n}\n"],"mappings":";;;;;;;;;;;AA8BA,SAAgB,mBACd,OACA,MACA,SACA,YACe;CACf,MAAM,UAAU,iBAAiB,KAAK;CACtC,MAAM,WAAW,QAAQ,MAAM,WAAW,OAAO,OAAO,KAAK,EAAE;CAC/D,MAAM,SAAsB;EAC1B,GAAG;EACH,2BAAU,IAAI,KAAK,EAAA,CAAE,YAAY;EACjC,GAAG,cAAc,OAAO,SAAS,UAAU,WAAW,SAAS;CACjE;CACA,OAAO,WACH,QAAQ,KAAK,WAAY,WAAW,WAAW,SAAS,MAAO,IAC/D,CAAC,GAAG,SAAS,MAAM;AACzB;;AAGA,SAAgB,oBACd,OACA,MACA,SACA,YACM;CACN,MAAM,SAAS,MAAM,SAAS,CAAC,CA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AoB,OAAO,OAAO,QAAQ,IAAI;CAE7D,MAAM,aADO,cAAc,OAAO,SAAS,MACrB,CAAC,CAAC,SAAS,UAC/B,MAAM,SAAS,YAAY,KAAA,IAAY,QAAQ,SACjD;CACA,oBAAoB,OAAO,UAAU,QAAQ,OAAO,QAAQ,IAAI,GAAG,SAAS,UAAU;CACtF,OAAO;EAAE,SAAS,WAAW;EAAS,MAAM,WAAW;EAAW;CAAO;AAC3E"}
@@ -0,0 +1,77 @@
1
+ import { DesignTokenBundle } from "../read.js";
2
+ import { TokenImportPlan } from "../plan/index.js";
3
+ import { SceneGraph, VariableValue } from "@pairdraw/scene-graph";
4
+ import { TokenSource } from "@pairdraw/scene-graph/token-sources";
5
+ //#region src/io/formats/design-tokens/sync/drift.d.ts
6
+ /** What linked code held at the last sync, and the token each variable then was. */
7
+ type TokenSyncBase = Pick<TokenSource, 'snapshot' | 'names' | 'modes'>;
8
+ /**
9
+ * How a token differs between linked code and the canvas, against what the code held at the last
10
+ * sync: changed in code only, on the canvas only, on both, new in code, no longer in code, or
11
+ * deleted on the canvas while the code still has it.
12
+ */
13
+ type TokenDriftKind = 'code' | 'canvas' | 'conflict' | 'added' | 'missing' | 'deleted';
14
+ interface TokenDrift {
15
+ kind: TokenDriftKind;
16
+ collection: string;
17
+ variable: string;
18
+ /** Null for a variable the code adds; a deleted variable keeps the id it had. */
19
+ variableId: string | null;
20
+ /** Null where the whole variable is added, gone, or deleted. */
21
+ mode: string | null;
22
+ modeId: string | null;
23
+ /** The value as the code writes it, for people to read. */
24
+ code?: string;
25
+ /** The value the canvas holds, for people to read. */
26
+ canvas?: string;
27
+ }
28
+ /** Which side a person keeps for a token that changed on the canvas, on both, or left the code. */
29
+ type TokenSyncChoice = 'code' | 'canvas';
30
+ interface TokenSyncResolution {
31
+ /**
32
+ * The imports that bring the code in, one per file, to apply in order. Values that already
33
+ * match are left alone, and nothing is deleted: a token gone from code keeps its variable.
34
+ */
35
+ plans: TokenImportPlan[];
36
+ /** How many tokens the imports write: those changed or added only in code, and those chosen. */
37
+ applied: number;
38
+ /** Drift nobody chose a side for, which the next sync reports again. */
39
+ undecided: TokenDrift[];
40
+ }
41
+ interface TokenSync {
42
+ /** In the order of the code's files, collections, and tokens; tokens gone from code last. */
43
+ drift: TokenDrift[];
44
+ /**
45
+ * Changes made only in code and tokens new in code always come in. A token changed or deleted
46
+ * on the canvas, or changed on both sides, takes the code only where `choose` picks the code;
47
+ * one gone from code stops being reported once a side is picked for it.
48
+ */
49
+ resolve(choose?: (drift: TokenDrift) => TokenSyncChoice | undefined): TokenSyncResolution;
50
+ }
51
+ /** Drift a person decides: the canvas changed or deleted the token, or both sides changed it. */
52
+ declare function driftNeedsChoice(drift: TokenDrift): boolean;
53
+ /**
54
+ * A value as sync compares it: colors to 8-bit channels, numbers to four decimals, aliases by
55
+ * target, and a CSS expression by its text, whatever number an engine computed for it.
56
+ */
57
+ declare function tokenValueSignature(value: VariableValue | undefined, expression?: string): string;
58
+ /**
59
+ * Compares linked code, read into one token bundle per file, with the canvas, and plans bringing
60
+ * it in. Collections and modes match by name and variables by name within them, as an import
61
+ * does. Without a snapshot nobody knows which side changed, so every difference is a conflict.
62
+ */
63
+ declare function planTokenSync(graph: SceneGraph, bundles: readonly DesignTokenBundle[], base?: TokenSyncBase): TokenSync;
64
+ /**
65
+ * Drift against the canvas as it is whenever asked, for a view that follows edits: the code is
66
+ * read and planned once, and a value unchanged since the last call is not compared again.
67
+ */
68
+ declare function trackTokenDrift(graph: SceneGraph, bundles: readonly DesignTokenBundle[], base?: TokenSyncBase): () => TokenDrift[];
69
+ /**
70
+ * What the code holds now for the variables it matches, and the token each one is, to compare
71
+ * later syncs against. Files that set different modes of one variable add up. Drift left
72
+ * undecided keeps what `previous` had, so the next sync still sees both changes.
73
+ */
74
+ declare function tokenSnapshot(graph: SceneGraph, bundles: readonly DesignTokenBundle[], previous?: TokenSyncBase, undecided?: readonly TokenDrift[]): Required<TokenSyncBase>;
75
+ //#endregion
76
+ export { TokenDrift, TokenDriftKind, TokenSync, TokenSyncBase, TokenSyncChoice, TokenSyncResolution, driftNeedsChoice, planTokenSync, tokenSnapshot, tokenValueSignature, trackTokenDrift };
77
+ //# sourceMappingURL=drift.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drift.d.ts","names":[],"sources":["../../../../../src/io/formats/design-tokens/sync/drift.ts"],"mappings":";;;;;;KAoBY,gBAAgB,KAAK;;;;;;KAOrB;UAEK;EACf,MAAM;EACN;EACA;;EAEA;;EAEA;EACA;;EAEA;;EAEA;;;KAIU;UAEK;;;;;EAKf,OAAO;;EAEP;;EAEA,WAAW;;UAGI;;EAEf,OAAO;;;;;;EAMP,QAAQ,UAAU,OAAO,eAAe,8BAA8B;;;iBAIxD,iBAAiB,OAAO;;;;;iBAkBxB,oBAAoB,OAAO,2BAA2B;;;;;;iBA4TtD,cACd,OAAO,YACP,kBAAkB,qBAClB,OAAO,gBACN;;;;;iBAkDa,gBACd,OAAO,YACP,kBAAkB,qBAClB,OAAO,sBACA;;;;;;iBAoGO,cACd,OAAO,YACP,kBAAkB,qBAClB,WAAU,eACV,qBAAoB,eACnB,SAAS"}