@pairdraw/core 0.21.0 → 0.22.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 (626) hide show
  1. package/dist/canvas/boolean.d.ts +6 -1
  2. package/dist/canvas/boolean.d.ts.map +1 -1
  3. package/dist/canvas/boolean.js +10 -2
  4. package/dist/canvas/boolean.js.map +1 -1
  5. package/dist/canvas/color-space.d.ts +45 -0
  6. package/dist/canvas/color-space.d.ts.map +1 -0
  7. package/dist/canvas/color-space.js +39 -0
  8. package/dist/canvas/color-space.js.map +1 -0
  9. package/dist/canvas/fills.d.ts +10 -10
  10. package/dist/canvas/fills.d.ts.map +1 -1
  11. package/dist/canvas/fills.js +116 -62
  12. package/dist/canvas/fills.js.map +1 -1
  13. package/dist/canvas/flatten.d.ts +11 -3
  14. package/dist/canvas/flatten.d.ts.map +1 -1
  15. package/dist/canvas/flatten.js +62 -4
  16. package/dist/canvas/flatten.js.map +1 -1
  17. package/dist/canvas/index.d.ts +2 -1
  18. package/dist/canvas/index.js +2 -1
  19. package/dist/canvas/layout-grids.d.ts +5 -2
  20. package/dist/canvas/layout-grids.d.ts.map +1 -1
  21. package/dist/canvas/layout-grids.js +7 -2
  22. package/dist/canvas/layout-grids.js.map +1 -1
  23. package/dist/canvas/noise/render.d.ts +17 -4
  24. package/dist/canvas/noise/render.d.ts.map +1 -1
  25. package/dist/canvas/noise/render.js +21 -6
  26. package/dist/canvas/noise/render.js.map +1 -1
  27. package/dist/canvas/noise/shader.d.ts +4 -4
  28. package/dist/canvas/noise/shader.d.ts.map +1 -1
  29. package/dist/canvas/noise/shader.js +5 -6
  30. package/dist/canvas/noise/shader.js.map +1 -1
  31. package/dist/canvas/overlays/annotations.d.ts +19 -0
  32. package/dist/canvas/overlays/annotations.d.ts.map +1 -0
  33. package/dist/canvas/overlays/annotations.js +110 -0
  34. package/dist/canvas/overlays/annotations.js.map +1 -0
  35. package/dist/canvas/overlays/auto-layout-hover.d.ts +11 -1
  36. package/dist/canvas/overlays/auto-layout-hover.d.ts.map +1 -1
  37. package/dist/canvas/overlays/auto-layout-hover.js +25 -1
  38. package/dist/canvas/overlays/auto-layout-hover.js.map +1 -1
  39. package/dist/canvas/overlays/feedback.js +1 -1
  40. package/dist/canvas/overlays/feedback.js.map +1 -1
  41. package/dist/canvas/overlays/index.d.ts +2 -2
  42. package/dist/canvas/overlays/index.js +2 -2
  43. package/dist/canvas/overlays/measurement.d.ts +7 -1
  44. package/dist/canvas/overlays/measurement.d.ts.map +1 -1
  45. package/dist/canvas/overlays/measurement.js +42 -4
  46. package/dist/canvas/overlays/measurement.js.map +1 -1
  47. package/dist/canvas/overlays/presence.d.ts.map +1 -1
  48. package/dist/canvas/overlays/presence.js +21 -24
  49. package/dist/canvas/overlays/presence.js.map +1 -1
  50. package/dist/canvas/renderer/colors.d.ts +7 -1
  51. package/dist/canvas/renderer/colors.d.ts.map +1 -1
  52. package/dist/canvas/renderer/colors.js +9 -1
  53. package/dist/canvas/renderer/colors.js.map +1 -1
  54. package/dist/canvas/renderer/document-surface.d.ts +15 -6
  55. package/dist/canvas/renderer/document-surface.d.ts.map +1 -1
  56. package/dist/canvas/renderer/document-surface.js +1 -0
  57. package/dist/canvas/renderer/document-surface.js.map +1 -1
  58. package/dist/canvas/renderer/lifecycle.d.ts.map +1 -1
  59. package/dist/canvas/renderer/lifecycle.js +2 -2
  60. package/dist/canvas/renderer/lifecycle.js.map +1 -1
  61. package/dist/canvas/renderer/methods.d.ts +1 -0
  62. package/dist/canvas/renderer/methods.d.ts.map +1 -1
  63. package/dist/canvas/renderer/methods.js +4 -1
  64. package/dist/canvas/renderer/methods.js.map +1 -1
  65. package/dist/canvas/renderer/overlay-pass.d.ts.map +1 -1
  66. package/dist/canvas/renderer/overlay-pass.js +6 -1
  67. package/dist/canvas/renderer/overlay-pass.js.map +1 -1
  68. package/dist/canvas/renderer/pipeline.d.ts.map +1 -1
  69. package/dist/canvas/renderer/pipeline.js +7 -0
  70. package/dist/canvas/renderer/pipeline.js.map +1 -1
  71. package/dist/canvas/renderer/types.d.ts +10 -0
  72. package/dist/canvas/renderer/types.d.ts.map +1 -1
  73. package/dist/canvas/renderer.d.ts +10 -2
  74. package/dist/canvas/renderer.d.ts.map +1 -1
  75. package/dist/canvas/renderer.js +15 -3
  76. package/dist/canvas/renderer.js.map +1 -1
  77. package/dist/canvas/scene.d.ts.map +1 -1
  78. package/dist/canvas/scene.js +9 -9
  79. package/dist/canvas/scene.js.map +1 -1
  80. package/dist/canvas/shaders/compile.d.ts +3 -1
  81. package/dist/canvas/shaders/compile.d.ts.map +1 -1
  82. package/dist/canvas/shaders/compile.js +12 -3
  83. package/dist/canvas/shaders/compile.js.map +1 -1
  84. package/dist/canvas/shaders/draw.d.ts.map +1 -1
  85. package/dist/canvas/shaders/draw.js +10 -3
  86. package/dist/canvas/shaders/draw.js.map +1 -1
  87. package/dist/canvas/shaders/effect.d.ts.map +1 -1
  88. package/dist/canvas/shaders/effect.js +6 -16
  89. package/dist/canvas/shaders/effect.js.map +1 -1
  90. package/dist/clipboard/pairdraw.d.ts.map +1 -1
  91. package/dist/clipboard/pairdraw.js +1 -0
  92. package/dist/clipboard/pairdraw.js.map +1 -1
  93. package/dist/editor/bridges/clipboard.d.ts +2 -0
  94. package/dist/editor/bridges/clipboard.d.ts.map +1 -1
  95. package/dist/editor/bridges/clipboard.js +1 -0
  96. package/dist/editor/bridges/clipboard.js.map +1 -1
  97. package/dist/editor/bridges/components.d.ts +14 -7
  98. package/dist/editor/bridges/components.d.ts.map +1 -1
  99. package/dist/editor/bridges/components.js +6 -0
  100. package/dist/editor/bridges/components.js.map +1 -1
  101. package/dist/editor/bridges/structure.d.ts +1 -1
  102. package/dist/editor/bridges/structure.d.ts.map +1 -1
  103. package/dist/editor/bridges/undo.d.ts +1 -1
  104. package/dist/editor/clipboard/code.d.ts +32 -0
  105. package/dist/editor/clipboard/code.d.ts.map +1 -0
  106. package/dist/editor/clipboard/code.js +30 -0
  107. package/dist/editor/clipboard/code.js.map +1 -0
  108. package/dist/editor/clipboard/export.js +2 -2
  109. package/dist/editor/clipboard/export.js.map +1 -1
  110. package/dist/editor/clipboard/paste/dependencies.d.ts +14 -0
  111. package/dist/editor/clipboard/paste/dependencies.d.ts.map +1 -0
  112. package/dist/editor/clipboard/paste/dependencies.js +0 -0
  113. package/dist/editor/clipboard/paste/run.d.ts +14 -0
  114. package/dist/editor/clipboard/paste/run.d.ts.map +1 -0
  115. package/dist/editor/clipboard/paste/run.js +47 -0
  116. package/dist/editor/clipboard/paste/run.js.map +1 -0
  117. package/dist/editor/clipboard/styled.d.ts +2 -8
  118. package/dist/editor/clipboard/styled.d.ts.map +1 -1
  119. package/dist/editor/clipboard/styled.js +2 -32
  120. package/dist/editor/clipboard/styled.js.map +1 -1
  121. package/dist/editor/clipboard.d.ts +2 -0
  122. package/dist/editor/clipboard.d.ts.map +1 -1
  123. package/dist/editor/clipboard.js +34 -0
  124. package/dist/editor/clipboard.js.map +1 -1
  125. package/dist/editor/components/instances.d.ts +5 -0
  126. package/dist/editor/components/instances.d.ts.map +1 -1
  127. package/dist/editor/components/instances.js +69 -4
  128. package/dist/editor/components/instances.js.map +1 -1
  129. package/dist/editor/components/slots/index.d.ts.map +1 -1
  130. package/dist/editor/components/slots/index.js +7 -0
  131. package/dist/editor/components/slots/index.js.map +1 -1
  132. package/dist/editor/components.d.ts +6 -0
  133. package/dist/editor/components.d.ts.map +1 -1
  134. package/dist/editor/components.js +14 -2
  135. package/dist/editor/components.js.map +1 -1
  136. package/dist/editor/create.d.ts +30 -3
  137. package/dist/editor/create.d.ts.map +1 -1
  138. package/dist/editor/create.js +11 -2
  139. package/dist/editor/create.js.map +1 -1
  140. package/dist/editor/design-tokens.d.ts +1 -1
  141. package/dist/editor/design-tokens.d.ts.map +1 -1
  142. package/dist/editor/design-tokens.js +4 -18
  143. package/dist/editor/design-tokens.js.map +1 -1
  144. package/dist/editor/image-edit.d.ts.map +1 -1
  145. package/dist/editor/image-edit.js +1 -2
  146. package/dist/editor/image-edit.js.map +1 -1
  147. package/dist/editor/index.d.ts +4 -4
  148. package/dist/editor/index.js +1 -1
  149. package/dist/editor/layout-mode.d.ts +3 -1
  150. package/dist/editor/layout-mode.d.ts.map +1 -1
  151. package/dist/editor/layout-mode.js +97 -2
  152. package/dist/editor/layout-mode.js.map +1 -1
  153. package/dist/editor/nodes.d.ts +2 -0
  154. package/dist/editor/nodes.d.ts.map +1 -1
  155. package/dist/editor/nodes.js +22 -7
  156. package/dist/editor/nodes.js.map +1 -1
  157. package/dist/editor/read-only/actions.js +6 -0
  158. package/dist/editor/read-only/actions.js.map +1 -1
  159. package/dist/editor/selection/overlays.d.ts +1 -0
  160. package/dist/editor/selection/overlays.d.ts.map +1 -1
  161. package/dist/editor/selection/overlays.js +7 -0
  162. package/dist/editor/selection/overlays.js.map +1 -1
  163. package/dist/editor/selection/read.d.ts +8 -0
  164. package/dist/editor/selection.d.ts +9 -0
  165. package/dist/editor/selection.d.ts.map +1 -1
  166. package/dist/editor/state/shared.js +1 -0
  167. package/dist/editor/state/shared.js.map +1 -1
  168. package/dist/editor/state/view.d.ts.map +1 -1
  169. package/dist/editor/state/view.js +2 -0
  170. package/dist/editor/state/view.js.map +1 -1
  171. package/dist/editor/structure/boolean.d.ts +1 -1
  172. package/dist/editor/structure/boolean.d.ts.map +1 -1
  173. package/dist/editor/structure/boolean.js +20 -1
  174. package/dist/editor/structure/boolean.js.map +1 -1
  175. package/dist/editor/structure/container-wrap.d.ts +8 -2
  176. package/dist/editor/structure/container-wrap.d.ts.map +1 -1
  177. package/dist/editor/structure/container-wrap.js +17 -5
  178. package/dist/editor/structure/container-wrap.js.map +1 -1
  179. package/dist/editor/structure/flatten.d.ts.map +1 -1
  180. package/dist/editor/structure/flatten.js +8 -7
  181. package/dist/editor/structure/flatten.js.map +1 -1
  182. package/dist/editor/structure/group/ungroup.d.ts.map +1 -1
  183. package/dist/editor/structure/group/ungroup.js +2 -0
  184. package/dist/editor/structure/group/ungroup.js.map +1 -1
  185. package/dist/editor/structure/outline-stroke.d.ts.map +1 -1
  186. package/dist/editor/structure/outline-stroke.js +5 -0
  187. package/dist/editor/structure/outline-stroke.js.map +1 -1
  188. package/dist/editor/structure.d.ts +1 -1
  189. package/dist/editor/structure.d.ts.map +1 -1
  190. package/dist/editor/styles.d.ts +26 -0
  191. package/dist/editor/styles.d.ts.map +1 -0
  192. package/dist/editor/styles.js +127 -0
  193. package/dist/editor/styles.js.map +1 -0
  194. package/dist/editor/text/selection-style.d.ts +1 -0
  195. package/dist/editor/text/selection-style.d.ts.map +1 -1
  196. package/dist/editor/text/selection-style.js +10 -2
  197. package/dist/editor/text/selection-style.js.map +1 -1
  198. package/dist/editor/tool-registry.d.ts.map +1 -1
  199. package/dist/editor/tool-registry.js +6 -0
  200. package/dist/editor/tool-registry.js.map +1 -1
  201. package/dist/editor/types.d.ts +14 -2
  202. package/dist/editor/types.d.ts.map +1 -1
  203. package/dist/editor/variable-bindings.d.ts.map +1 -1
  204. package/dist/editor/variable-bindings.js +6 -1
  205. package/dist/editor/variable-bindings.js.map +1 -1
  206. package/dist/figma-api/accessors/basic.d.ts.map +1 -1
  207. package/dist/figma-api/accessors/basic.js +22 -1
  208. package/dist/figma-api/accessors/basic.js.map +1 -1
  209. package/dist/figma-api/accessors/shape.js +1 -1
  210. package/dist/figma-api/accessors/text/index.js +1 -1
  211. package/dist/figma-api/accessors/text/ranges.js +1 -1
  212. package/dist/figma-api/accessors/text/references.js +1 -1
  213. package/dist/figma-api/accessors/variables.js +1 -1
  214. package/dist/figma-api/accessors/vector.d.ts.map +1 -1
  215. package/dist/figma-api/accessors/vector.js +8 -22
  216. package/dist/figma-api/accessors/vector.js.map +1 -1
  217. package/dist/figma-api/accessors/visual.js +1 -1
  218. package/dist/figma-api/compatibility.d.ts +1 -1
  219. package/dist/figma-api/compatibility.d.ts.map +1 -1
  220. package/dist/figma-api/component-scope.d.ts +14 -0
  221. package/dist/figma-api/component-scope.d.ts.map +1 -0
  222. package/dist/figma-api/component-scope.js +28 -0
  223. package/dist/figma-api/component-scope.js.map +1 -0
  224. package/dist/figma-api/components.d.ts.map +1 -1
  225. package/dist/figma-api/components.js +26 -2
  226. package/dist/figma-api/components.js.map +1 -1
  227. package/dist/figma-api/flatten.js +3 -3
  228. package/dist/figma-api/flatten.js.map +1 -1
  229. package/dist/figma-api/index.d.ts +77 -6
  230. package/dist/figma-api/index.d.ts.map +1 -1
  231. package/dist/figma-api/index.js +188 -2
  232. package/dist/figma-api/index.js.map +1 -1
  233. package/dist/figma-api/node-types.d.ts +2 -1
  234. package/dist/figma-api/node-types.d.ts.map +1 -1
  235. package/dist/figma-api/overrides.d.ts +26 -1
  236. package/dist/figma-api/overrides.d.ts.map +1 -1
  237. package/dist/figma-api/overrides.js +157 -10
  238. package/dist/figma-api/overrides.js.map +1 -1
  239. package/dist/figma-api/proxy.d.ts +2 -0
  240. package/dist/figma-api/proxy.d.ts.map +1 -1
  241. package/dist/figma-api/proxy.js +10 -2
  242. package/dist/figma-api/proxy.js.map +1 -1
  243. package/dist/figma-api/reactions.d.ts +61 -5
  244. package/dist/figma-api/reactions.d.ts.map +1 -1
  245. package/dist/figma-api/reactions.js +144 -11
  246. package/dist/figma-api/reactions.js.map +1 -1
  247. package/dist/figma-api/shape-with-text.js +1 -1
  248. package/dist/figma-api/slots.d.ts +3 -1
  249. package/dist/figma-api/slots.d.ts.map +1 -1
  250. package/dist/figma-api/slots.js +9 -8
  251. package/dist/figma-api/slots.js.map +1 -1
  252. package/dist/index.d.ts +4 -4
  253. package/dist/index.js +1 -1
  254. package/dist/io/formats/code/detect.d.ts +23 -0
  255. package/dist/io/formats/code/detect.d.ts.map +1 -0
  256. package/dist/io/formats/code/detect.js +46 -0
  257. package/dist/io/formats/code/detect.js.map +1 -0
  258. package/dist/io/formats/code/index.d.ts +5 -0
  259. package/dist/io/formats/code/index.js +5 -0
  260. package/dist/io/formats/code/read.d.ts +45 -0
  261. package/dist/io/formats/code/read.d.ts.map +1 -0
  262. package/dist/io/formats/code/read.js +86 -0
  263. package/dist/io/formats/code/read.js.map +1 -0
  264. package/dist/io/formats/code/stylesheet.d.ts +13 -0
  265. package/dist/io/formats/code/stylesheet.d.ts.map +1 -0
  266. package/dist/io/formats/code/stylesheet.js +21 -0
  267. package/dist/io/formats/code/stylesheet.js.map +1 -0
  268. package/dist/io/formats/code/tokens.d.ts +18 -0
  269. package/dist/io/formats/code/tokens.d.ts.map +1 -0
  270. package/dist/io/formats/code/tokens.js +135 -0
  271. package/dist/io/formats/code/tokens.js.map +1 -0
  272. package/dist/io/formats/design-tokens/apply.d.ts +7 -3
  273. package/dist/io/formats/design-tokens/apply.d.ts.map +1 -1
  274. package/dist/io/formats/design-tokens/apply.js.map +1 -1
  275. package/dist/io/formats/drawio/warnings.d.ts +17 -2
  276. package/dist/io/formats/drawio/warnings.d.ts.map +1 -1
  277. package/dist/io/formats/drawio/warnings.js +14 -7
  278. package/dist/io/formats/drawio/warnings.js.map +1 -1
  279. package/dist/io/formats/fig/export/patch/fields.js +5 -0
  280. package/dist/io/formats/fig/export/patch/fields.js.map +1 -1
  281. package/dist/io/formats/fig/export/patch/index.d.ts.map +1 -1
  282. package/dist/io/formats/fig/export/patch/index.js +20 -20
  283. package/dist/io/formats/fig/export/patch/index.js.map +1 -1
  284. package/dist/io/formats/fig/export/setup.d.ts.map +1 -1
  285. package/dist/io/formats/fig/export/setup.js +5 -1
  286. package/dist/io/formats/fig/export/setup.js.map +1 -1
  287. package/dist/io/formats/fig/index.d.ts +3 -2
  288. package/dist/io/formats/fig/index.js +2 -2
  289. package/dist/io/formats/fig/read.d.ts.map +1 -1
  290. package/dist/io/formats/fig/read.js +5 -2
  291. package/dist/io/formats/fig/read.js.map +1 -1
  292. package/dist/io/formats/html/index.d.ts +1 -0
  293. package/dist/io/formats/html/index.d.ts.map +1 -1
  294. package/dist/io/formats/html/index.js +5 -3
  295. package/dist/io/formats/html/index.js.map +1 -1
  296. package/dist/io/formats/html/layers.d.ts +3 -1
  297. package/dist/io/formats/html/layers.d.ts.map +1 -1
  298. package/dist/io/formats/html/layers.js +6 -1
  299. package/dist/io/formats/html/layers.js.map +1 -1
  300. package/dist/io/formats/pdf/export.d.ts.map +1 -1
  301. package/dist/io/formats/pdf/export.js +7 -3
  302. package/dist/io/formats/pdf/export.js.map +1 -1
  303. package/dist/io/formats/pdf/plan.d.ts +3 -0
  304. package/dist/io/formats/pdf/plan.d.ts.map +1 -1
  305. package/dist/io/formats/pdf/plan.js +60 -36
  306. package/dist/io/formats/pdf/plan.js.map +1 -1
  307. package/dist/io/formats/pen/index.d.ts.map +1 -1
  308. package/dist/io/formats/pen/index.js +13 -4
  309. package/dist/io/formats/pen/index.js.map +1 -1
  310. package/dist/io/formats/raster/headless.d.ts.map +1 -1
  311. package/dist/io/formats/raster/headless.js +3 -2
  312. package/dist/io/formats/raster/headless.js.map +1 -1
  313. package/dist/io/formats/raster/index.d.ts +2 -2
  314. package/dist/io/formats/raster/index.js +2 -2
  315. package/dist/io/formats/raster/render.d.ts +10 -2
  316. package/dist/io/formats/raster/render.d.ts.map +1 -1
  317. package/dist/io/formats/raster/render.js +35 -9
  318. package/dist/io/formats/raster/render.js.map +1 -1
  319. package/dist/io/formats/svg/defs.d.ts.map +1 -1
  320. package/dist/io/formats/svg/defs.js +19 -1
  321. package/dist/io/formats/svg/defs.js.map +1 -1
  322. package/dist/io/formats/svg/export.d.ts +5 -2
  323. package/dist/io/formats/svg/export.d.ts.map +1 -1
  324. package/dist/io/formats/svg/export.js +59 -10
  325. package/dist/io/formats/svg/export.js.map +1 -1
  326. package/dist/io/formats/svg/index.d.ts +2 -2
  327. package/dist/io/formats/svg/index.js +2 -2
  328. package/dist/io/formats/svg/text/layout.d.ts.map +1 -1
  329. package/dist/io/formats/svg/text/layout.js +4 -2
  330. package/dist/io/formats/svg/text/layout.js.map +1 -1
  331. package/dist/io/formats/video/record.d.ts.map +1 -1
  332. package/dist/io/formats/video/record.js +24 -9
  333. package/dist/io/formats/video/record.js.map +1 -1
  334. package/dist/io/formats.d.ts.map +1 -1
  335. package/dist/io/formats.js +30 -17
  336. package/dist/io/formats.js.map +1 -1
  337. package/dist/io/index.d.ts +2 -2
  338. package/dist/io/types.d.ts +11 -2
  339. package/dist/io/types.d.ts.map +1 -1
  340. package/dist/kiwi/fig/population/client.d.ts.map +1 -1
  341. package/dist/kiwi/fig/population/client.js +2 -1
  342. package/dist/kiwi/fig/population/client.js.map +1 -1
  343. package/dist/kiwi/fig/session/document-state.d.ts +46 -2
  344. package/dist/kiwi/fig/session/document-state.d.ts.map +1 -1
  345. package/dist/kiwi/fig/session/document-state.js +113 -5
  346. package/dist/kiwi/fig/session/document-state.js.map +1 -1
  347. package/dist/kiwi/fig/session/options.d.ts +4 -0
  348. package/dist/kiwi/fig/session/options.d.ts.map +1 -1
  349. package/dist/kiwi/fig/session/options.js.map +1 -1
  350. package/dist/layout/apply.d.ts.map +1 -1
  351. package/dist/layout/apply.js +8 -4
  352. package/dist/layout/apply.js.map +1 -1
  353. package/dist/layout/auto-layout-handles.js +1 -1
  354. package/dist/layout/auto-layout-handles.js.map +1 -1
  355. package/dist/layout/axis-sizing.d.ts.map +1 -1
  356. package/dist/layout/axis-sizing.js +1 -1
  357. package/dist/layout/axis-sizing.js.map +1 -1
  358. package/dist/layout/derived.d.ts.map +1 -1
  359. package/dist/layout/derived.js +1 -1
  360. package/dist/layout/derived.js.map +1 -1
  361. package/dist/layout/effective-generated-text.js +1 -1
  362. package/dist/layout/effective-generated-text.js.map +1 -1
  363. package/dist/layout/grid.d.ts +3 -1
  364. package/dist/layout/grid.d.ts.map +1 -1
  365. package/dist/layout/grid.js +57 -16
  366. package/dist/layout/grid.js.map +1 -1
  367. package/dist/layout.d.ts +1 -1
  368. package/dist/layout.js +6 -5
  369. package/dist/layout.js.map +1 -1
  370. package/dist/node/fs.d.ts.map +1 -1
  371. package/dist/node/fs.js +28 -7
  372. package/dist/node/fs.js.map +1 -1
  373. package/dist/prototype/easing.d.ts +13 -5
  374. package/dist/prototype/easing.d.ts.map +1 -1
  375. package/dist/prototype/easing.js +46 -6
  376. package/dist/prototype/easing.js.map +1 -1
  377. package/dist/prototype/scenes.d.ts +31 -0
  378. package/dist/prototype/scenes.d.ts.map +1 -1
  379. package/dist/prototype/scenes.js +220 -31
  380. package/dist/prototype/scenes.js.map +1 -1
  381. package/dist/prototype/session.d.ts.map +1 -1
  382. package/dist/prototype/session.js +1 -0
  383. package/dist/prototype/session.js.map +1 -1
  384. package/dist/prototype/smart-animate/animation.d.ts +2 -1
  385. package/dist/prototype/smart-animate/animation.d.ts.map +1 -1
  386. package/dist/prototype/smart-animate/animation.js +2 -2
  387. package/dist/prototype/smart-animate/animation.js.map +1 -1
  388. package/dist/prototype/timeline.d.ts +10 -1
  389. package/dist/prototype/timeline.d.ts.map +1 -1
  390. package/dist/prototype/timeline.js +69 -23
  391. package/dist/prototype/timeline.js.map +1 -1
  392. package/dist/prototype/variables.d.ts +23 -0
  393. package/dist/prototype/variables.d.ts.map +1 -0
  394. package/dist/prototype/variables.js +237 -0
  395. package/dist/prototype/variables.js.map +1 -0
  396. package/dist/rpc/read-commands.d.ts +5 -0
  397. package/dist/rpc/read-commands.d.ts.map +1 -1
  398. package/dist/rpc/read-commands.js +4 -1
  399. package/dist/rpc/read-commands.js.map +1 -1
  400. package/dist/text/character-style.d.ts +8 -1
  401. package/dist/text/character-style.d.ts.map +1 -1
  402. package/dist/text/character-style.js +39 -1
  403. package/dist/text/character-style.js.map +1 -1
  404. package/dist/text/index.d.ts +2 -2
  405. package/dist/text/index.js +2 -2
  406. package/dist/tools/create/basic.js +3 -4
  407. package/dist/tools/create/basic.js.map +1 -1
  408. package/dist/tools/create/behaviours.js +1 -1
  409. package/dist/tools/create/code.d.ts +6 -0
  410. package/dist/tools/create/code.d.ts.map +1 -0
  411. package/dist/tools/create/code.js +68 -0
  412. package/dist/tools/create/code.js.map +1 -0
  413. package/dist/tools/create/html.d.ts.map +1 -1
  414. package/dist/tools/create/html.js +9 -57
  415. package/dist/tools/create/html.js.map +1 -1
  416. package/dist/tools/create/icons.js +1 -1
  417. package/dist/tools/create/inputs.d.ts +11 -0
  418. package/dist/tools/create/inputs.d.ts.map +1 -0
  419. package/dist/tools/create/inputs.js +15 -0
  420. package/dist/tools/create/inputs.js.map +1 -0
  421. package/dist/tools/create/mermaid.d.ts.map +1 -1
  422. package/dist/tools/create/mermaid.js +5 -6
  423. package/dist/tools/create/mermaid.js.map +1 -1
  424. package/dist/tools/create/place.d.ts +30 -0
  425. package/dist/tools/create/place.d.ts.map +1 -0
  426. package/dist/tools/create/place.js +70 -0
  427. package/dist/tools/create/place.js.map +1 -0
  428. package/dist/tools/create/render.js +1 -1
  429. package/dist/tools/create/svg.js +1 -1
  430. package/dist/tools/create/vector.js +1 -1
  431. package/dist/tools/create.d.ts +2 -1
  432. package/dist/tools/create.js +2 -1
  433. package/dist/tools/css/gradient.d.ts +28 -0
  434. package/dist/tools/css/gradient.d.ts.map +1 -0
  435. package/dist/tools/css/gradient.js +118 -0
  436. package/dist/tools/css/gradient.js.map +1 -0
  437. package/dist/tools/image-ai/generate.js +1 -1
  438. package/dist/tools/modify/geometry.js +5 -5
  439. package/dist/tools/modify/geometry.js.map +1 -1
  440. package/dist/tools/modify/layout.d.ts.map +1 -1
  441. package/dist/tools/modify/layout.js +7 -1
  442. package/dist/tools/modify/layout.js.map +1 -1
  443. package/dist/tools/modify/matching.js +1 -1
  444. package/dist/tools/modify/overrides.d.ts +6 -0
  445. package/dist/tools/modify/overrides.d.ts.map +1 -0
  446. package/dist/tools/modify/overrides.js +27 -0
  447. package/dist/tools/modify/overrides.js.map +1 -0
  448. package/dist/tools/modify/paint.d.ts.map +1 -1
  449. package/dist/tools/modify/paint.js +84 -39
  450. package/dist/tools/modify/paint.js.map +1 -1
  451. package/dist/tools/modify/text.d.ts +2 -1
  452. package/dist/tools/modify/text.d.ts.map +1 -1
  453. package/dist/tools/modify/text.js +79 -8
  454. package/dist/tools/modify/text.js.map +1 -1
  455. package/dist/tools/modify/update.d.ts.map +1 -1
  456. package/dist/tools/modify/update.js +18 -2
  457. package/dist/tools/modify/update.js.map +1 -1
  458. package/dist/tools/modify.d.ts +3 -2
  459. package/dist/tools/modify.js +3 -2
  460. package/dist/tools/read/css.d.ts.map +1 -1
  461. package/dist/tools/read/css.js +29 -12
  462. package/dist/tools/read/css.js.map +1 -1
  463. package/dist/tools/read/libraries.js +1 -1
  464. package/dist/tools/read/nodes.d.ts.map +1 -1
  465. package/dist/tools/read/nodes.js +19 -5
  466. package/dist/tools/read/nodes.js.map +1 -1
  467. package/dist/tools/registry/extended.d.ts.map +1 -1
  468. package/dist/tools/registry/extended.js +6 -1
  469. package/dist/tools/registry/extended.js.map +1 -1
  470. package/dist/tools/text-range.d.ts +11 -0
  471. package/dist/tools/text-range.d.ts.map +1 -0
  472. package/dist/tools/text-range.js +26 -0
  473. package/dist/tools/text-range.js.map +1 -0
  474. package/dist/tools/variables/bindings.js +1 -1
  475. package/dist/tools/variables/bindings.js.map +1 -1
  476. package/dist/tools/variables/unbind.js +1 -1
  477. package/dist/tools/variables/unbind.js.map +1 -1
  478. package/dist/tools/vector/path.d.ts.map +1 -1
  479. package/dist/tools/vector/path.js +7 -21
  480. package/dist/tools/vector/path.js.map +1 -1
  481. package/dist/vector/rebase.d.ts +17 -0
  482. package/dist/vector/rebase.d.ts.map +1 -0
  483. package/dist/vector/rebase.js +32 -0
  484. package/dist/vector/rebase.js.map +1 -0
  485. package/package.json +14 -9
  486. package/src/canvas/boolean.ts +12 -1
  487. package/src/canvas/color-space.ts +73 -0
  488. package/src/canvas/fills.ts +130 -83
  489. package/src/canvas/flatten.ts +92 -7
  490. package/src/canvas/index.ts +9 -0
  491. package/src/canvas/layout-grids.ts +15 -2
  492. package/src/canvas/noise/render.ts +35 -7
  493. package/src/canvas/noise/shader.ts +8 -10
  494. package/src/canvas/overlays/annotations.ts +117 -0
  495. package/src/canvas/overlays/auto-layout-hover.ts +41 -1
  496. package/src/canvas/overlays/feedback.ts +7 -2
  497. package/src/canvas/overlays/index.ts +1 -1
  498. package/src/canvas/overlays/measurement.ts +49 -3
  499. package/src/canvas/overlays/presence.ts +35 -32
  500. package/src/canvas/renderer/colors.ts +14 -0
  501. package/src/canvas/renderer/document-surface.ts +16 -6
  502. package/src/canvas/renderer/lifecycle.ts +2 -2
  503. package/src/canvas/renderer/methods.ts +4 -0
  504. package/src/canvas/renderer/overlay-pass.ts +4 -0
  505. package/src/canvas/renderer/pipeline.ts +8 -0
  506. package/src/canvas/renderer/types.ts +8 -0
  507. package/src/canvas/renderer.ts +21 -2
  508. package/src/canvas/scene.ts +15 -7
  509. package/src/canvas/shaders/compile.ts +14 -3
  510. package/src/canvas/shaders/draw.ts +11 -4
  511. package/src/canvas/shaders/effect.ts +6 -18
  512. package/src/clipboard/pairdraw.ts +1 -0
  513. package/src/editor/bridges/clipboard.ts +1 -0
  514. package/src/editor/bridges/components.ts +10 -0
  515. package/src/editor/clipboard/code.ts +50 -0
  516. package/src/editor/clipboard/export.ts +2 -2
  517. package/src/editor/clipboard/paste/dependencies.ts +18 -0
  518. package/src/editor/clipboard/paste/run.ts +64 -0
  519. package/src/editor/clipboard/styled.ts +4 -52
  520. package/src/editor/clipboard.ts +40 -0
  521. package/src/editor/components/instances.ts +92 -4
  522. package/src/editor/components/slots/index.ts +7 -0
  523. package/src/editor/components.ts +16 -2
  524. package/src/editor/create.ts +15 -1
  525. package/src/editor/design-tokens.ts +3 -23
  526. package/src/editor/image-edit.ts +5 -2
  527. package/src/editor/index.ts +1 -0
  528. package/src/editor/layout-mode.ts +131 -3
  529. package/src/editor/nodes.ts +30 -5
  530. package/src/editor/read-only/actions.ts +6 -0
  531. package/src/editor/selection/overlays.ts +8 -0
  532. package/src/editor/state/shared.ts +1 -0
  533. package/src/editor/state/view.ts +2 -0
  534. package/src/editor/structure/boolean.ts +29 -1
  535. package/src/editor/structure/container-wrap.ts +20 -4
  536. package/src/editor/structure/flatten.ts +15 -8
  537. package/src/editor/structure/group/ungroup.ts +2 -0
  538. package/src/editor/structure/outline-stroke.ts +5 -0
  539. package/src/editor/styles.ts +203 -0
  540. package/src/editor/text/selection-style.ts +18 -1
  541. package/src/editor/tool-registry.ts +2 -0
  542. package/src/editor/types.ts +14 -0
  543. package/src/editor/variable-bindings.ts +11 -0
  544. package/src/figma-api/accessors/basic.ts +33 -1
  545. package/src/figma-api/accessors/vector.ts +6 -13
  546. package/src/figma-api/compatibility.ts +1 -0
  547. package/src/figma-api/component-scope.ts +36 -0
  548. package/src/figma-api/components.ts +24 -0
  549. package/src/figma-api/flatten.ts +7 -3
  550. package/src/figma-api/index.ts +302 -6
  551. package/src/figma-api/node-types.ts +1 -0
  552. package/src/figma-api/overrides.ts +192 -5
  553. package/src/figma-api/proxy.ts +16 -1
  554. package/src/figma-api/reactions.ts +163 -12
  555. package/src/figma-api/slots.ts +10 -9
  556. package/src/io/formats/code/detect.ts +67 -0
  557. package/src/io/formats/code/index.ts +17 -0
  558. package/src/io/formats/code/read.ts +143 -0
  559. package/src/io/formats/code/stylesheet.ts +24 -0
  560. package/src/io/formats/code/tokens.ts +159 -0
  561. package/src/io/formats/design-tokens/apply.ts +3 -2
  562. package/src/io/formats/drawio/warnings.ts +27 -8
  563. package/src/io/formats/fig/export/patch/fields.ts +11 -0
  564. package/src/io/formats/fig/export/patch/index.ts +23 -19
  565. package/src/io/formats/fig/export/setup.ts +8 -1
  566. package/src/io/formats/fig/index.ts +6 -0
  567. package/src/io/formats/fig/read.ts +11 -2
  568. package/src/io/formats/html/index.ts +9 -3
  569. package/src/io/formats/html/layers.ts +7 -0
  570. package/src/io/formats/pdf/export.ts +19 -7
  571. package/src/io/formats/pdf/plan.ts +71 -32
  572. package/src/io/formats/pen/index.ts +14 -6
  573. package/src/io/formats/raster/headless.ts +3 -1
  574. package/src/io/formats/raster/index.ts +2 -0
  575. package/src/io/formats/raster/render.ts +49 -9
  576. package/src/io/formats/svg/defs.ts +27 -1
  577. package/src/io/formats/svg/export.ts +75 -13
  578. package/src/io/formats/svg/index.ts +1 -0
  579. package/src/io/formats/svg/text/layout.ts +5 -3
  580. package/src/io/formats/video/record.ts +33 -9
  581. package/src/io/formats.ts +45 -19
  582. package/src/io/index.ts +1 -0
  583. package/src/io/types.ts +10 -0
  584. package/src/kiwi/fig/population/client.ts +6 -1
  585. package/src/kiwi/fig/session/document-state.ts +195 -5
  586. package/src/kiwi/fig/session/options.ts +2 -0
  587. package/src/layout/apply.ts +12 -4
  588. package/src/layout/auto-layout-handles.ts +1 -1
  589. package/src/layout/axis-sizing.ts +3 -1
  590. package/src/layout/derived.ts +3 -1
  591. package/src/layout/effective-generated-text.ts +1 -1
  592. package/src/layout/grid.ts +91 -21
  593. package/src/layout.ts +16 -3
  594. package/src/node/fs.ts +32 -7
  595. package/src/prototype/easing.ts +79 -7
  596. package/src/prototype/scenes.ts +244 -15
  597. package/src/prototype/session.ts +1 -0
  598. package/src/prototype/smart-animate/animation.ts +4 -3
  599. package/src/prototype/timeline.ts +118 -26
  600. package/src/prototype/variables.ts +189 -0
  601. package/src/rpc/read-commands.ts +19 -1
  602. package/src/text/character-style.ts +47 -0
  603. package/src/text/index.ts +1 -1
  604. package/src/tools/create/basic.ts +2 -3
  605. package/src/tools/create/code.ts +85 -0
  606. package/src/tools/create/html.ts +9 -46
  607. package/src/tools/create/inputs.ts +12 -0
  608. package/src/tools/create/mermaid.ts +6 -6
  609. package/src/tools/create/place.ts +80 -0
  610. package/src/tools/create.ts +1 -0
  611. package/src/tools/css/gradient.ts +147 -0
  612. package/src/tools/modify/geometry.ts +5 -5
  613. package/src/tools/modify/layout.ts +19 -0
  614. package/src/tools/modify/overrides.ts +35 -0
  615. package/src/tools/modify/paint.ts +124 -54
  616. package/src/tools/modify/text.ts +91 -7
  617. package/src/tools/modify/update.ts +23 -2
  618. package/src/tools/modify.ts +9 -1
  619. package/src/tools/read/css.ts +46 -12
  620. package/src/tools/read/nodes.ts +26 -4
  621. package/src/tools/registry/extended.ts +6 -0
  622. package/src/tools/text-range.ts +29 -0
  623. package/src/tools/variables/bindings.ts +4 -1
  624. package/src/tools/variables/unbind.ts +4 -1
  625. package/src/tools/vector/path.ts +11 -13
  626. package/src/vector/rebase.ts +33 -0
@@ -0,0 +1,45 @@
1
+ import { PasteCodeKind } from "./detect.js";
2
+ import { SceneGraph } from "@pairdraw/scene-graph";
3
+ import { CSSRuntime, CodeReport } from "@pairdraw/dom-css";
4
+ //#region src/io/formats/code/read.d.ts
5
+ /** What a paste could not keep, counted for the toast, plus what only the paste knows. */
6
+ interface ReadCodeReport extends CodeReport {
7
+ /** Top-level layers the paste drew. */
8
+ layers: number;
9
+ /** Variant-prefixed utilities left out, such as `md:flex-row`'s `md:`. */
10
+ variantsStripped: number;
11
+ /** Colour and number properties bound to the target document's variables. */
12
+ tokensBound: number;
13
+ /** Values two variables share, which a paste binds nothing to. */
14
+ tokensAmbiguous: number;
15
+ }
16
+ interface ReadCodeOptions {
17
+ /** The paste's own CSS: a `globals.css` or a `<style>` block it came with. */
18
+ css?: string;
19
+ /** The target document's tokens as a stylesheet, so `bg-primary` resolves before binding. */
20
+ tokensCSS?: string;
21
+ /** The CSS runtime a host supplies; the headless one by default. */
22
+ runtime?: CSSRuntime;
23
+ pageName?: string;
24
+ /** The language the caller names, instead of what detection reads. */
25
+ kind?: PasteCodeKind;
26
+ /** Whether Tailwind utilities compile; false reads only inline styles and the paste's CSS. */
27
+ tailwind?: boolean;
28
+ }
29
+ interface ReadCodeResult {
30
+ graph: SceneGraph;
31
+ report: ReadCodeReport;
32
+ kind: PasteCodeKind;
33
+ }
34
+ /**
35
+ * The layers a pasted JSX, TSX, or HTML source draws, styled as a browser would style it with its
36
+ * own CSS and the Tailwind classes it names. Nothing in the source runs. Token binding needs the
37
+ * target document and happens in `bindCodeTokens`. Source past the size a paste reads is refused
38
+ * before it is parsed.
39
+ */
40
+ declare function readCodeDocument(code: string, options?: ReadCodeOptions): Promise<ReadCodeResult>;
41
+ /** Every layer the paste drew, without the document node or its pages. */
42
+ declare function codeLayerCount(graph: SceneGraph): number;
43
+ //#endregion
44
+ export { ReadCodeOptions, ReadCodeReport, ReadCodeResult, codeLayerCount, readCodeDocument };
45
+ //# sourceMappingURL=read.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read.d.ts","names":[],"sources":["../../../../src/io/formats/code/read.ts"],"mappings":";;;;;UAoBiB,uBAAuB;;EAEtC;;EAEA;;EAEA;;EAEA;;UAGe;;EAEf;;EAEA;;EAEA,UAAU;EACV;;EAEA,OAAO;;EAEP;;UAGe;EACf,OAAO;EACP,QAAQ;EACR,MAAM;;;;;;;;iBASc,iBACpB,cACA,UAAS,kBACR,QAAQ;;iBA0EK,eAAe,OAAO"}
@@ -0,0 +1,86 @@
1
+ import { MAX_CODE_LENGTH, detectCode } from "./detect.js";
2
+ import { codeStylesheet } from "./stylesheet.js";
3
+ import { htmlClassNames, htmlElementCount } from "../html/layers.js";
4
+ import { CodeTooLargeError, MAX_CODE_ELEMENTS, createHeadlessCSSRuntime, jsxSourceToTree, tailwindCandidates, tailwindHTMLToSceneGraph, tailwindJSXToSceneGraph, tailwindUtilities } from "@pairdraw/dom-css";
5
+ //#region src/io/formats/code/read.ts
6
+ /**
7
+ * The layers a pasted JSX, TSX, or HTML source draws, styled as a browser would style it with its
8
+ * own CSS and the Tailwind classes it names. Nothing in the source runs. Token binding needs the
9
+ * target document and happens in `bindCodeTokens`. Source past the size a paste reads is refused
10
+ * before it is parsed.
11
+ */
12
+ async function readCodeDocument(code, options = {}) {
13
+ const detection = detectCode(code);
14
+ if (detection === "too-large") throw new CodeTooLargeError(`The paste is longer than ${MAX_CODE_LENGTH} characters; paste a smaller part of it.`);
15
+ const kind = options.kind ?? detection;
16
+ if (!kind) throw new Error("This text does not draw a layout: paste JSX, TSX, or HTML markup.");
17
+ if (kind === "html" && htmlElementCount(code) > MAX_CODE_ELEMENTS) throw new CodeTooLargeError(`The paste draws more than ${MAX_CODE_ELEMENTS} layers; paste a smaller part of it.`);
18
+ const stylesheet = codeStylesheet([options.tokensCSS, options.css]);
19
+ const runtime = options.runtime ?? createHeadlessCSSRuntime();
20
+ const { graph, report } = await (kind === "jsx" ? jsxLayers : htmlLayers)(code, {
21
+ ...options,
22
+ runtime,
23
+ css: stylesheet.css,
24
+ tailwind: options.tailwind !== false
25
+ });
26
+ report.layers = codeLayerCount(graph);
27
+ report.approximations += stylesheet.importsDropped;
28
+ return {
29
+ graph,
30
+ report,
31
+ kind
32
+ };
33
+ }
34
+ async function jsxLayers(code, source) {
35
+ const { children, report } = jsxSourceToTree(code);
36
+ const { candidates, variantsStripped } = source.tailwind ? tailwindCandidates(children) : {
37
+ candidates: [],
38
+ variantsStripped: 0
39
+ };
40
+ return {
41
+ graph: await tailwindJSXToSceneGraph(children, candidates, {
42
+ runtime: source.runtime,
43
+ css: source.css,
44
+ pageName: source.pageName
45
+ }),
46
+ report: withCounts(report, variantsStripped)
47
+ };
48
+ }
49
+ async function htmlLayers(code, source) {
50
+ const { candidates, variantsStripped } = source.tailwind ? tailwindUtilities(htmlClassNames(code)) : {
51
+ candidates: [],
52
+ variantsStripped: 0
53
+ };
54
+ return {
55
+ graph: await tailwindHTMLToSceneGraph(code, candidates, {
56
+ runtime: source.runtime,
57
+ css: source.css,
58
+ pageName: source.pageName
59
+ }),
60
+ report: withCounts({
61
+ placeholders: 0,
62
+ componentsAsFrames: 0,
63
+ droppedProps: 0,
64
+ approximations: 0,
65
+ imagesAsPlaceholders: 0
66
+ }, variantsStripped)
67
+ };
68
+ }
69
+ /** Every layer the paste drew, without the document node or its pages. */
70
+ function codeLayerCount(graph) {
71
+ const pages = new Set(graph.getPages().map((page) => page.id));
72
+ return [...graph.getAllNodes()].filter((node) => node.id !== graph.rootId && !pages.has(node.id)).length;
73
+ }
74
+ function withCounts(report, variantsStripped) {
75
+ return {
76
+ ...report,
77
+ layers: 0,
78
+ variantsStripped,
79
+ tokensBound: 0,
80
+ tokensAmbiguous: 0
81
+ };
82
+ }
83
+ //#endregion
84
+ export { codeLayerCount, readCodeDocument };
85
+
86
+ //# sourceMappingURL=read.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read.js","names":[],"sources":["../../../../src/io/formats/code/read.ts"],"sourcesContent":["import {\n CodeTooLargeError,\n MAX_CODE_ELEMENTS,\n createHeadlessCSSRuntime,\n jsxSourceToTree,\n tailwindCandidates,\n tailwindHTMLToSceneGraph,\n tailwindJSXToSceneGraph,\n tailwindUtilities,\n type CodeReport,\n type CSSRuntime\n} from '@pairdraw/dom-css'\nimport type { SceneGraph } from '@pairdraw/scene-graph'\n\nimport { htmlClassNames, htmlElementCount } from '#core/io/formats/html/layers'\n\nimport { CODE_TOO_LARGE, MAX_CODE_LENGTH, detectCode, type PasteCodeKind } from './detect'\nimport { codeStylesheet } from './stylesheet'\n\n/** What a paste could not keep, counted for the toast, plus what only the paste knows. */\nexport interface ReadCodeReport extends CodeReport {\n /** Top-level layers the paste drew. */\n layers: number\n /** Variant-prefixed utilities left out, such as `md:flex-row`'s `md:`. */\n variantsStripped: number\n /** Colour and number properties bound to the target document's variables. */\n tokensBound: number\n /** Values two variables share, which a paste binds nothing to. */\n tokensAmbiguous: number\n}\n\nexport interface ReadCodeOptions {\n /** The paste's own CSS: a `globals.css` or a `<style>` block it came with. */\n css?: string\n /** The target document's tokens as a stylesheet, so `bg-primary` resolves before binding. */\n tokensCSS?: string\n /** The CSS runtime a host supplies; the headless one by default. */\n runtime?: CSSRuntime\n pageName?: string\n /** The language the caller names, instead of what detection reads. */\n kind?: PasteCodeKind\n /** Whether Tailwind utilities compile; false reads only inline styles and the paste's CSS. */\n tailwind?: boolean\n}\n\nexport interface ReadCodeResult {\n graph: SceneGraph\n report: ReadCodeReport\n kind: PasteCodeKind\n}\n\n/**\n * The layers a pasted JSX, TSX, or HTML source draws, styled as a browser would style it with its\n * own CSS and the Tailwind classes it names. Nothing in the source runs. Token binding needs the\n * target document and happens in `bindCodeTokens`. Source past the size a paste reads is refused\n * before it is parsed.\n */\nexport async function readCodeDocument(\n code: string,\n options: ReadCodeOptions = {}\n): Promise<ReadCodeResult> {\n const detection = detectCode(code)\n if (detection === CODE_TOO_LARGE) {\n throw new CodeTooLargeError(\n `The paste is longer than ${MAX_CODE_LENGTH} characters; paste a smaller part of it.`\n )\n }\n const kind = options.kind ?? detection\n if (!kind) throw new Error('This text does not draw a layout: paste JSX, TSX, or HTML markup.')\n if (kind === 'html' && htmlElementCount(code) > MAX_CODE_ELEMENTS) {\n throw new CodeTooLargeError(\n `The paste draws more than ${MAX_CODE_ELEMENTS} layers; paste a smaller part of it.`\n )\n }\n const stylesheet = codeStylesheet([options.tokensCSS, options.css])\n const runtime = options.runtime ?? createHeadlessCSSRuntime()\n const build = kind === 'jsx' ? jsxLayers : htmlLayers\n const { graph, report } = await build(code, {\n ...options,\n runtime,\n css: stylesheet.css,\n tailwind: options.tailwind !== false\n })\n report.layers = codeLayerCount(graph)\n report.approximations += stylesheet.importsDropped\n return { graph, report, kind }\n}\n\ninterface StyleSource {\n runtime: CSSRuntime\n css: string\n pageName?: string\n tailwind: boolean\n}\n\nasync function jsxLayers(\n code: string,\n source: StyleSource\n): Promise<{ graph: SceneGraph; report: ReadCodeReport }> {\n const { children, report } = jsxSourceToTree(code)\n const { candidates, variantsStripped } = source.tailwind\n ? tailwindCandidates(children)\n : { candidates: [], variantsStripped: 0 }\n const graph = await tailwindJSXToSceneGraph(children, candidates, {\n runtime: source.runtime,\n css: source.css,\n pageName: source.pageName\n })\n return { graph, report: withCounts(report, variantsStripped) }\n}\n\nasync function htmlLayers(\n code: string,\n source: StyleSource\n): Promise<{ graph: SceneGraph; report: ReadCodeReport }> {\n const { candidates, variantsStripped } = source.tailwind\n ? tailwindUtilities(htmlClassNames(code))\n : { candidates: [], variantsStripped: 0 }\n const graph = await tailwindHTMLToSceneGraph(code, candidates, {\n runtime: source.runtime,\n css: source.css,\n pageName: source.pageName\n })\n const report: CodeReport = {\n placeholders: 0,\n componentsAsFrames: 0,\n droppedProps: 0,\n approximations: 0,\n imagesAsPlaceholders: 0\n }\n return { graph, report: withCounts(report, variantsStripped) }\n}\n\n/** Every layer the paste drew, without the document node or its pages. */\nexport function codeLayerCount(graph: SceneGraph): number {\n const pages = new Set(graph.getPages().map((page) => page.id))\n return [...graph.getAllNodes()].filter((node) => node.id !== graph.rootId && !pages.has(node.id))\n .length\n}\n\nfunction withCounts(report: CodeReport, variantsStripped: number): ReadCodeReport {\n return { ...report, layers: 0, variantsStripped, tokensBound: 0, tokensAmbiguous: 0 }\n}\n"],"mappings":";;;;;;;;;;;AAyDA,eAAsB,iBACpB,MACA,UAA2B,CAAC,GACH;CACzB,MAAM,YAAY,WAAW,IAAI;CACjC,IAAI,cAAA,aACF,MAAM,IAAI,kBACR,4BAA4B,gBAAgB,yCAC9C;CAEF,MAAM,OAAO,QAAQ,QAAQ;CAC7B,IAAI,CAAC,MAAM,MAAM,IAAI,MAAM,mEAAmE;CAC9F,IAAI,SAAS,UAAU,iBAAiB,IAAI,IAAI,mBAC9C,MAAM,IAAI,kBACR,6BAA6B,kBAAkB,qCACjD;CAEF,MAAM,aAAa,eAAe,CAAC,QAAQ,WAAW,QAAQ,GAAG,CAAC;CAClE,MAAM,UAAU,QAAQ,WAAW,yBAAyB;CAE5D,MAAM,EAAE,OAAO,WAAW,OADZ,SAAS,QAAQ,YAAY,WAAA,CACL,MAAM;EAC1C,GAAG;EACH;EACA,KAAK,WAAW;EAChB,UAAU,QAAQ,aAAa;CACjC,CAAC;CACD,OAAO,SAAS,eAAe,KAAK;CACpC,OAAO,kBAAkB,WAAW;CACpC,OAAO;EAAE;EAAO;EAAQ;CAAK;AAC/B;AASA,eAAe,UACb,MACA,QACwD;CACxD,MAAM,EAAE,UAAU,WAAW,gBAAgB,IAAI;CACjD,MAAM,EAAE,YAAY,qBAAqB,OAAO,WAC5C,mBAAmB,QAAQ,IAC3B;EAAE,YAAY,CAAC;EAAG,kBAAkB;CAAE;CAM1C,OAAO;EAAE,OAAA,MALW,wBAAwB,UAAU,YAAY;GAChE,SAAS,OAAO;GAChB,KAAK,OAAO;GACZ,UAAU,OAAO;EACnB,CAAC;EACe,QAAQ,WAAW,QAAQ,gBAAgB;CAAE;AAC/D;AAEA,eAAe,WACb,MACA,QACwD;CACxD,MAAM,EAAE,YAAY,qBAAqB,OAAO,WAC5C,kBAAkB,eAAe,IAAI,CAAC,IACtC;EAAE,YAAY,CAAC;EAAG,kBAAkB;CAAE;CAa1C,OAAO;EAAE,OAAA,MAZW,yBAAyB,MAAM,YAAY;GAC7D,SAAS,OAAO;GAChB,KAAK,OAAO;GACZ,UAAU,OAAO;EACnB,CAAC;EAQe,QAAQ,WAAW;GANjC,cAAc;GACd,oBAAoB;GACpB,cAAc;GACd,gBAAgB;GAChB,sBAAsB;EAEgB,GAAG,gBAAgB;CAAE;AAC/D;;AAGA,SAAgB,eAAe,OAA2B;CACxD,MAAM,QAAQ,IAAI,IAAI,MAAM,SAAS,CAAC,CAAC,KAAK,SAAS,KAAK,EAAE,CAAC;CAC7D,OAAO,CAAC,GAAG,MAAM,YAAY,CAAC,CAAC,CAAC,QAAQ,SAAS,KAAK,OAAO,MAAM,UAAU,CAAC,MAAM,IAAI,KAAK,EAAE,CAAC,CAAC,CAC9F;AACL;AAEA,SAAS,WAAW,QAAoB,kBAA0C;CAChF,OAAO;EAAE,GAAG;EAAQ,QAAQ;EAAG;EAAkB,aAAa;EAAG,iBAAiB;CAAE;AACtF"}
@@ -0,0 +1,13 @@
1
+ //#region src/io/formats/code/stylesheet.d.ts
2
+ interface CodeStylesheet {
3
+ css: string;
4
+ importsDropped: number;
5
+ }
6
+ /**
7
+ * The stylesheet a paste styles with: the document's tokens first, then the paste's own CSS, with
8
+ * `@import` rules left out because they name files the paste does not bring with it.
9
+ */
10
+ declare function codeStylesheet(parts: Array<string | undefined>): CodeStylesheet;
11
+ //#endregion
12
+ export { CodeStylesheet, codeStylesheet };
13
+ //# sourceMappingURL=stylesheet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stylesheet.d.ts","names":[],"sources":["../../../../src/io/formats/code/stylesheet.ts"],"mappings":";UAGiB;EACf;EACA;;;;;;iBAOc,eAAe,OAAO,4BAA4B"}
@@ -0,0 +1,21 @@
1
+ //#region src/io/formats/code/stylesheet.ts
2
+ /** The declarations a stylesheet keeps: one import names a file the paste does not carry. */
3
+ const IMPORT = /^\s*@import\b.*$/gm;
4
+ /**
5
+ * The stylesheet a paste styles with: the document's tokens first, then the paste's own CSS, with
6
+ * `@import` rules left out because they name files the paste does not bring with it.
7
+ */
8
+ function codeStylesheet(parts) {
9
+ let importsDropped = 0;
10
+ return {
11
+ css: parts.filter((part) => Boolean(part?.trim())).map((part) => part.replace(IMPORT, () => {
12
+ importsDropped += 1;
13
+ return "";
14
+ })).join("\n"),
15
+ importsDropped
16
+ };
17
+ }
18
+ //#endregion
19
+ export { codeStylesheet };
20
+
21
+ //# sourceMappingURL=stylesheet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stylesheet.js","names":[],"sources":["../../../../src/io/formats/code/stylesheet.ts"],"sourcesContent":["/** The declarations a stylesheet keeps: one import names a file the paste does not carry. */\nconst IMPORT = /^\\s*@import\\b.*$/gm\n\nexport interface CodeStylesheet {\n css: string\n importsDropped: number\n}\n\n/**\n * The stylesheet a paste styles with: the document's tokens first, then the paste's own CSS, with\n * `@import` rules left out because they name files the paste does not bring with it.\n */\nexport function codeStylesheet(parts: Array<string | undefined>): CodeStylesheet {\n let importsDropped = 0\n const kept = parts\n .filter((part): part is string => Boolean(part?.trim()))\n .map((part) =>\n part.replace(IMPORT, () => {\n importsDropped += 1\n return ''\n })\n )\n return { css: kept.join('\\n'), importsDropped }\n}\n"],"mappings":";;AACA,MAAM,SAAS;;;;;AAWf,SAAgB,eAAe,OAAkD;CAC/E,IAAI,iBAAiB;CASrB,OAAO;EAAE,KARI,MACV,QAAQ,SAAyB,QAAQ,MAAM,KAAK,CAAC,CAAC,CAAC,CACvD,KAAK,SACJ,KAAK,QAAQ,cAAc;GACzB,kBAAkB;GAClB,OAAO;EACT,CAAC,CAEY,CAAC,CAAC,KAAK,IAAI;EAAG;CAAe;AAChD"}
@@ -0,0 +1,18 @@
1
+ import { SceneGraph, SceneNode } from "@pairdraw/scene-graph";
2
+ //#region src/io/formats/code/tokens.d.ts
3
+ interface TokenBindingReport {
4
+ tokensBound: number;
5
+ tokensAmbiguous: number;
6
+ }
7
+ /**
8
+ * Binds a pasted layer's colours and numbers to the target document's variables, one property at
9
+ * a time, only when exactly one variable of the matching namespace holds that exact value. A value
10
+ * two variables share binds nothing: guessing would change the design. The layers are the inserted
11
+ * ones, so a binding names a variable the document already has.
12
+ */
13
+ declare function bindCodeTokens(nodes: Iterable<SceneNode>, target: SceneGraph, report: TokenBindingReport): void;
14
+ /** Every layer a paste created, from its roots down, as a transfer inserted them. */
15
+ declare function codeLayerNodes(graph: SceneGraph, rootIds: readonly string[]): SceneNode[];
16
+ //#endregion
17
+ export { TokenBindingReport, bindCodeTokens, codeLayerNodes };
18
+ //# sourceMappingURL=tokens.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokens.d.ts","names":[],"sources":["../../../../src/io/formats/code/tokens.ts"],"mappings":";;UA8BiB;EACf;EACA;;;;;;;;iBASc,eACd,OAAO,SAAS,YAChB,QAAQ,YACR,QAAQ;;iBAQM,eAAe,OAAO,YAAY,6BAA6B"}
@@ -0,0 +1,135 @@
1
+ import { variableValueInMode } from "@pairdraw/scene-graph/variables";
2
+ //#region src/io/formats/code/tokens.ts
3
+ /** The namespaces a layer property can take, in the vocabulary its tokens are named in. */
4
+ const PROPERTY_NAMESPACES = {
5
+ cornerRadius: "radius",
6
+ topLeftRadius: "radius",
7
+ topRightRadius: "radius",
8
+ bottomLeftRadius: "radius",
9
+ bottomRightRadius: "radius",
10
+ fontSize: "text",
11
+ lineHeight: "leading",
12
+ letterSpacing: "tracking",
13
+ itemSpacing: "spacing",
14
+ counterAxisSpacing: "spacing",
15
+ gridColumnGap: "spacing",
16
+ gridRowGap: "spacing",
17
+ paddingLeft: "spacing",
18
+ paddingRight: "spacing",
19
+ paddingTop: "spacing",
20
+ paddingBottom: "spacing"
21
+ };
22
+ /** The numeric properties a pasted layer binds to a matching variable. */
23
+ const BOUND_NUMERIC_FIELDS = Object.keys(PROPERTY_NAMESPACES);
24
+ /**
25
+ * Binds a pasted layer's colours and numbers to the target document's variables, one property at
26
+ * a time, only when exactly one variable of the matching namespace holds that exact value. A value
27
+ * two variables share binds nothing: guessing would change the design. The layers are the inserted
28
+ * ones, so a binding names a variable the document already has.
29
+ */
30
+ function bindCodeTokens(nodes, target, report) {
31
+ const index = variableIndex(target);
32
+ if (index.size === 0) return;
33
+ for (const node of nodes) bindNode(node, index, report);
34
+ }
35
+ /** Every layer a paste created, from its roots down, as a transfer inserted them. */
36
+ function codeLayerNodes(graph, rootIds) {
37
+ const nodes = [];
38
+ const visit = (id) => {
39
+ const node = graph.getNode(id);
40
+ if (!node) return;
41
+ nodes.push(node);
42
+ for (const child of node.childIds) visit(child);
43
+ };
44
+ for (const id of rootIds) visit(id);
45
+ return nodes;
46
+ }
47
+ function variableIndex(target) {
48
+ const index = /* @__PURE__ */ new Map();
49
+ for (const variable of target.variables.values()) {
50
+ if (variable.deleted) continue;
51
+ const namespace = namespaceOf(variable);
52
+ if (!namespace) continue;
53
+ const key = indexKey(namespace, variableValueInMode(target, variable, defaultModeOf(target, variable)));
54
+ if (!key) continue;
55
+ const found = index.get(key);
56
+ if (found) found.push(variable);
57
+ else index.set(key, [variable]);
58
+ }
59
+ return index;
60
+ }
61
+ function defaultModeOf(target, variable) {
62
+ return target.variableCollections.get(variable.collectionId)?.defaultModeId ?? "";
63
+ }
64
+ /** The namespace a variable's scopes name, or none when it names something a layer cannot take. */
65
+ function namespaceOf(variable) {
66
+ if (variable.type === "COLOR") return "color";
67
+ if (variable.type !== "FLOAT") return null;
68
+ for (const scope of variable.scopes ?? []) {
69
+ if (scope === "CORNER_RADIUS") return "radius";
70
+ if (scope === "GAP" || scope === "WIDTH_HEIGHT") return "spacing";
71
+ if (scope === "FONT_SIZE") return "text";
72
+ if (scope === "LINE_HEIGHT") return "leading";
73
+ if (scope === "LETTER_SPACING") return "tracking";
74
+ }
75
+ return null;
76
+ }
77
+ function indexKey(namespace, value) {
78
+ if (typeof value === "number") return `${namespace}:${value.toFixed(3)}`;
79
+ if (!isColor(value)) return null;
80
+ return `${namespace}:${colorKey(value)}`;
81
+ }
82
+ function isColor(value) {
83
+ return typeof value === "object" && value !== null && "r" in value && "g" in value && "b" in value;
84
+ }
85
+ function colorKey(color) {
86
+ return [
87
+ color.r,
88
+ color.g,
89
+ color.b,
90
+ color.a
91
+ ].map((channel) => channel.toFixed(4)).join(",");
92
+ }
93
+ function bindNode(node, index, report) {
94
+ bindPaints(node, "fills", index, report);
95
+ bindPaints(node, "strokes", index, report);
96
+ for (const field of BOUND_NUMERIC_FIELDS) {
97
+ const value = node[field];
98
+ if (typeof value !== "number" || value === 0) continue;
99
+ const namespace = PROPERTY_NAMESPACES[field];
100
+ if (!namespace) continue;
101
+ bindField(node, field, indexKey(namespace, value), index, report);
102
+ }
103
+ }
104
+ function bindPaints(node, list, index, report) {
105
+ node[list].forEach((paint, paintIndex) => {
106
+ if (paint.type !== "SOLID") return;
107
+ const { r, g, b, a } = paint.color;
108
+ bindField(node, `${list}/${paintIndex}/color`, indexKey("color", {
109
+ r,
110
+ g,
111
+ b,
112
+ a
113
+ }), index, report);
114
+ });
115
+ }
116
+ function bindField(node, field, key, index, report) {
117
+ if (!key || node.boundVariables[field]) return;
118
+ const candidates = index.get(key);
119
+ if (!candidates || candidates.length === 0) return;
120
+ if (candidates.length > 1) {
121
+ report.tokensAmbiguous += 1;
122
+ return;
123
+ }
124
+ const variable = candidates.at(0);
125
+ if (!variable) return;
126
+ node.boundVariables = {
127
+ ...node.boundVariables,
128
+ [field]: variable.id
129
+ };
130
+ report.tokensBound += 1;
131
+ }
132
+ //#endregion
133
+ export { bindCodeTokens, codeLayerNodes };
134
+
135
+ //# sourceMappingURL=tokens.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokens.js","names":[],"sources":["../../../../src/io/formats/code/tokens.ts"],"sourcesContent":["import type { SceneGraph, SceneNode, Variable, VariableValue } from '@pairdraw/scene-graph'\nimport type { Color } from '@pairdraw/scene-graph/primitives'\nimport { variableValueInMode } from '@pairdraw/scene-graph/variables'\n\n/** Tailwind namespace a document variable belongs to, which decides what it may bind. */\ntype TokenNamespace = 'color' | 'radius' | 'spacing' | 'text' | 'leading' | 'tracking'\n\n/** The namespaces a layer property can take, in the vocabulary its tokens are named in. */\nconst PROPERTY_NAMESPACES: Partial<Record<string, TokenNamespace>> = {\n cornerRadius: 'radius',\n topLeftRadius: 'radius',\n topRightRadius: 'radius',\n bottomLeftRadius: 'radius',\n bottomRightRadius: 'radius',\n fontSize: 'text',\n lineHeight: 'leading',\n letterSpacing: 'tracking',\n itemSpacing: 'spacing',\n counterAxisSpacing: 'spacing',\n gridColumnGap: 'spacing',\n gridRowGap: 'spacing',\n paddingLeft: 'spacing',\n paddingRight: 'spacing',\n paddingTop: 'spacing',\n paddingBottom: 'spacing'\n}\n\n/** The numeric properties a pasted layer binds to a matching variable. */\nconst BOUND_NUMERIC_FIELDS = Object.keys(PROPERTY_NAMESPACES)\n\nexport interface TokenBindingReport {\n tokensBound: number\n tokensAmbiguous: number\n}\n\n/**\n * Binds a pasted layer's colours and numbers to the target document's variables, one property at\n * a time, only when exactly one variable of the matching namespace holds that exact value. A value\n * two variables share binds nothing: guessing would change the design. The layers are the inserted\n * ones, so a binding names a variable the document already has.\n */\nexport function bindCodeTokens(\n nodes: Iterable<SceneNode>,\n target: SceneGraph,\n report: TokenBindingReport\n): void {\n const index = variableIndex(target)\n if (index.size === 0) return\n for (const node of nodes) bindNode(node, index, report)\n}\n\n/** Every layer a paste created, from its roots down, as a transfer inserted them. */\nexport function codeLayerNodes(graph: SceneGraph, rootIds: readonly string[]): SceneNode[] {\n const nodes: SceneNode[] = []\n const visit = (id: string): void => {\n const node = graph.getNode(id)\n if (!node) return\n nodes.push(node)\n for (const child of node.childIds) visit(child)\n }\n for (const id of rootIds) visit(id)\n return nodes\n}\n\ntype ValueIndex = Map<string, Variable[]>\n\nfunction variableIndex(target: SceneGraph): ValueIndex {\n const index: ValueIndex = new Map()\n for (const variable of target.variables.values()) {\n if (variable.deleted) continue\n const namespace = namespaceOf(variable)\n if (!namespace) continue\n const value = variableValueInMode(target, variable, defaultModeOf(target, variable))\n const key = indexKey(namespace, value)\n if (!key) continue\n const found = index.get(key)\n if (found) found.push(variable)\n else index.set(key, [variable])\n }\n return index\n}\n\nfunction defaultModeOf(target: SceneGraph, variable: Variable): string {\n return target.variableCollections.get(variable.collectionId)?.defaultModeId ?? ''\n}\n\n/** The namespace a variable's scopes name, or none when it names something a layer cannot take. */\nfunction namespaceOf(variable: Variable): TokenNamespace | null {\n if (variable.type === 'COLOR') return 'color'\n if (variable.type !== 'FLOAT') return null\n for (const scope of variable.scopes ?? []) {\n if (scope === 'CORNER_RADIUS') return 'radius'\n if (scope === 'GAP' || scope === 'WIDTH_HEIGHT') return 'spacing'\n if (scope === 'FONT_SIZE') return 'text'\n if (scope === 'LINE_HEIGHT') return 'leading'\n if (scope === 'LETTER_SPACING') return 'tracking'\n }\n return null\n}\n\nfunction indexKey(namespace: TokenNamespace, value: VariableValue | undefined): string | null {\n if (typeof value === 'number') return `${namespace}:${value.toFixed(3)}`\n if (!isColor(value)) return null\n return `${namespace}:${colorKey(value)}`\n}\n\nfunction isColor(value: unknown): value is Color {\n return typeof value === 'object' && value !== null && 'r' in value && 'g' in value && 'b' in value\n}\n\nfunction colorKey(color: Color): string {\n return [color.r, color.g, color.b, color.a].map((channel) => channel.toFixed(4)).join(',')\n}\n\nfunction bindNode(node: SceneNode, index: ValueIndex, report: TokenBindingReport): void {\n bindPaints(node, 'fills', index, report)\n bindPaints(node, 'strokes', index, report)\n for (const field of BOUND_NUMERIC_FIELDS) {\n const value = node[field as keyof SceneNode]\n if (typeof value !== 'number' || value === 0) continue\n const namespace = PROPERTY_NAMESPACES[field]\n if (!namespace) continue\n bindField(node, field, indexKey(namespace, value), index, report)\n }\n}\n\nfunction bindPaints(\n node: SceneNode,\n list: 'fills' | 'strokes',\n index: ValueIndex,\n report: TokenBindingReport\n): void {\n const paints = node[list]\n paints.forEach((paint, paintIndex) => {\n if (paint.type !== 'SOLID') return\n const { r, g, b, a } = paint.color\n bindField(node, `${list}/${paintIndex}/color`, indexKey('color', { r, g, b, a }), index, report)\n })\n}\n\nfunction bindField(\n node: SceneNode,\n field: string,\n key: string | null,\n index: ValueIndex,\n report: TokenBindingReport\n): void {\n if (!key || node.boundVariables[field]) return\n const candidates = index.get(key)\n if (!candidates || candidates.length === 0) return\n if (candidates.length > 1) {\n report.tokensAmbiguous += 1\n return\n }\n const variable = candidates.at(0)\n if (!variable) return\n node.boundVariables = { ...node.boundVariables, [field]: variable.id }\n report.tokensBound += 1\n}\n"],"mappings":";;;AAQA,MAAM,sBAA+D;CACnE,cAAc;CACd,eAAe;CACf,gBAAgB;CAChB,kBAAkB;CAClB,mBAAmB;CACnB,UAAU;CACV,YAAY;CACZ,eAAe;CACf,aAAa;CACb,oBAAoB;CACpB,eAAe;CACf,YAAY;CACZ,aAAa;CACb,cAAc;CACd,YAAY;CACZ,eAAe;AACjB;;AAGA,MAAM,uBAAuB,OAAO,KAAK,mBAAmB;;;;;;;AAa5D,SAAgB,eACd,OACA,QACA,QACM;CACN,MAAM,QAAQ,cAAc,MAAM;CAClC,IAAI,MAAM,SAAS,GAAG;CACtB,KAAK,MAAM,QAAQ,OAAO,SAAS,MAAM,OAAO,MAAM;AACxD;;AAGA,SAAgB,eAAe,OAAmB,SAAyC;CACzF,MAAM,QAAqB,CAAC;CAC5B,MAAM,SAAS,OAAqB;EAClC,MAAM,OAAO,MAAM,QAAQ,EAAE;EAC7B,IAAI,CAAC,MAAM;EAC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E,OAAO,eAAe;AACxB"}
@@ -1,6 +1,6 @@
1
1
  import { PlannedStyle } from "./plan/styles.js";
2
2
  import { PlannedVariable, TokenImportPlan } from "./plan/index.js";
3
- import { CodeSyntaxPlatform, SceneGraph, SceneNode, TokenExpression, TokenUnit, Variable, VariableCollection, VariableScope, VariableValue } from "@pairdraw/scene-graph";
3
+ import { CodeSyntaxPlatform, SceneGraph, SceneNode, SharedStyleType, TokenExpression, TokenUnit, Variable, VariableCollection, VariableScope, VariableValue } from "@pairdraw/scene-graph";
4
4
  //#region src/io/formats/design-tokens/apply.d.ts
5
5
  /** Token fields an import sets; `undefined` clears one. */
6
6
  interface ImportedTokenFields {
@@ -42,8 +42,12 @@ interface TokenImportResult {
42
42
  */
43
43
  declare function applyTokenImport(target: TokenImportTarget, plan: TokenImportPlan): TokenImportResult;
44
44
  /** A style node: hidden from the layer list, found by its style id, as `.fig` styles are. */
45
- declare function styleNodeProps(style: PlannedStyle, fields: Partial<SceneNode>): Partial<SceneNode>;
46
- declare function styleNodeType(style: PlannedStyle): "RECTANGLE" | "TEXT";
45
+ declare function styleNodeProps(style: Pick<PlannedStyle, 'kind'> | {
46
+ kind: SharedStyleType;
47
+ }, fields: Partial<SceneNode>): Partial<SceneNode>;
48
+ declare function styleNodeType(style: Pick<PlannedStyle, 'kind'> | {
49
+ kind: SharedStyleType;
50
+ }): "RECTANGLE" | "TEXT";
47
51
  /**
48
52
  * Imports straight into a graph, for scripts, tools, and the CLI working on a document without
49
53
  * an editor; the layers bound to variables whose values changed are resolved and laid out
@@ -1 +1 @@
1
- {"version":3,"file":"apply.d.ts","names":[],"sources":["../../../../src/io/formats/design-tokens/apply.ts"],"mappings":";;;;;UAyBiB;EACf,OAAO;EACP,SAAS;EACT,aAAa,QAAQ,OAAO;EAC5B;EACA;EACA,cAAc,eAAe;;;;;;UAOd;EACf,OAAO;EACP,cAAc,eAAe;EAC7B,QAAQ,sBAAsB;EAC9B,WAAW,sBAAsB,gBAAgB;EACjD,eA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ACL"}
@@ -1 +1 @@
1
- {"version":3,"file":"apply.js","names":[],"sources":["../../../../src/io/formats/design-tokens/apply.ts"],"sourcesContent":["import { compact } from 'es-toolkit/array'\nimport { pick } from 'es-toolkit/object'\nimport { isEmptyObject, isEqual } from 'es-toolkit/predicate'\n\nimport type {\n CodeSyntaxPlatform,\n SceneGraph,\n SceneNode,\n TokenExpression,\n TokenUnit,\n Variable,\n VariableCollection,\n VariableScope,\n VariableValue\n} from '@pairdraw/scene-graph'\nimport { copyEffects } from '@pairdraw/scene-graph/copy'\nimport { findInstanceAncestor } from '@pairdraw/scene-graph/instances'\nimport { randomHex } from '@pairdraw/scene-graph/random'\n\nimport { reconcileVariableLayouts } from '#core/layout/variables'\n\nimport type { AliasTarget, PlannedCollection, PlannedVariable, TokenImportPlan } from './plan'\nimport type { PlannedStyle } from './plan/styles'\n\n/** Token fields an import sets; `undefined` clears one. */\nexport interface ImportedTokenFields {\n unit?: TokenUnit\n scopes?: VariableScope[]\n codeSyntax?: Partial<Record<CodeSyntaxPlatform, string>>\n hiddenFromPublishing?: boolean\n description?: string\n expressions?: Record<string, TokenExpression>\n}\n\n/**\n * The changes an import makes, so the editor can make them undoable and a headless document can\n * make them directly. Each adds to or changes the document; none deletes.\n */\nexport interface TokenImportTarget {\n graph: SceneGraph\n addCollection(name: string): VariableCollection\n addMode(collectionId: string, name: string): string | undefined\n renameMode(collectionId: string, modeId: string, name: string): void\n setDefaultMode(collectionId: string, modeId: string): void\n setModeCondition(collectionId: string, modeId: string, condition: string): void\n setModeAttribute(collectionId: string, name: string): void\n addVariable(planned: PlannedVariable, collectionId: string): Variable\n setValue(variableId: string, modeId: string, value: VariableValue): void\n setTokenFields(variableId: string, fields: ImportedTokenFields): void\n addStyle(style: PlannedStyle, fields: Partial<SceneNode>): SceneNode\n updateNode(nodeId: string, changes: Partial<SceneNode>): void\n bindVariable(nodeId: string, field: string, variableId: string): void\n}\n\nexport interface TokenImportResult {\n collectionIds: string[]\n variableIds: string[]\n styleNodeIds: string[]\n}\n\n/** Text fields a text style gives the layers that use it. */\nconst TEXT_STYLE_FIELDS = [\n 'fontFamily',\n 'fontWeight',\n 'italic',\n 'fontSize',\n 'lineHeight',\n 'letterSpacing',\n 'textDecoration',\n 'textCase'\n] as const satisfies ReadonlyArray<keyof SceneNode>\n\nfunction targetCollection(target: TokenImportTarget, planned: PlannedCollection): string {\n if (planned.target.kind === 'existing') return planned.target.collectionId\n return target.addCollection(planned.target.name).id\n}\n\n/** Mode ids by planned mode: matched ones, a new collection's first renamed, or new ones. */\nfunction targetModes(\n target: TokenImportTarget,\n planned: PlannedCollection,\n collectionId: string\n): string[] {\n const collection = target.graph.variableCollections.get(collectionId)\n let unclaimed = planned.target.kind === 'new' ? (collection?.defaultModeId ?? null) : null\n const modeIds = planned.modes.map((mode) => {\n if (mode.target.kind === 'existing') return mode.target.modeId\n if (unclaimed) {\n const modeId = unclaimed\n unclaimed = null\n target.renameMode(collectionId, modeId, mode.target.name)\n return modeId\n }\n return target.addMode(collectionId, mode.target.name) ?? ''\n })\n planned.modes.forEach((mode, index) => {\n if (mode.condition) target.setModeCondition(collectionId, modeIds[index], mode.condition)\n })\n if (planned.target.kind === 'new') {\n const defaultIndex = planned.modes.findIndex((mode) => mode.isDefault)\n if (defaultIndex > 0) target.setDefaultMode(collectionId, modeIds[defaultIndex])\n if (planned.modeAttribute) target.setModeAttribute(collectionId, planned.modeAttribute)\n }\n return modeIds\n}\n\nfunction aliasId(target: AliasTarget, created: ReadonlyArray<ReadonlyArray<Variable>>) {\n if (target.kind === 'variable') return target.variableId\n return created.at(target.collection)?.at(target.variable)?.id\n}\n\nfunction plannedValue(\n value: NonNullable<PlannedVariable['values'][number]>,\n created: ReadonlyArray<ReadonlyArray<Variable>>\n): VariableValue | undefined {\n if (value.kind === 'literal') return value.value\n const id = aliasId(value.target, created)\n return id ? { aliasId: id } : undefined\n}\n\nfunction applyVariables(target: TokenImportTarget, plan: TokenImportPlan) {\n const collectionIds = plan.collections.map((planned) => targetCollection(target, planned))\n const modeIds = plan.collections.map((planned, index) =>\n targetModes(target, planned, collectionIds[index])\n )\n // Every variable exists before any value is set, so aliases can point at later ones.\n const created = plan.collections.map((planned, index) =>\n planned.variables.map((variable) =>\n variable.existingId\n ? (target.graph.variables.get(variable.existingId) ??\n target.addVariable(variable, collectionIds[index]))\n : target.addVariable(variable, collectionIds[index])\n )\n )\n plan.collections.forEach((planned, collectionIndex) => {\n planned.variables.forEach((variable, variableIndex) => {\n const made = created[collectionIndex][variableIndex]\n const modes = modeIds[collectionIndex]\n variable.values.forEach((value, modeIndex) => {\n const next = value && plannedValue(value, created)\n const modeId = modes[modeIndex]\n if (next !== undefined && modeId && !isEqual(made.valuesByMode[modeId], next))\n target.setValue(made.id, modeId, next)\n })\n const expressions = Object.fromEntries(\n variable.expressions.flatMap((css, modeIndex) => {\n const resolved = made.valuesByMode[modes[modeIndex]]\n return css && typeof resolved === 'number' ? [[modes[modeIndex], { css, resolved }]] : []\n })\n )\n const fields: ImportedTokenFields = {\n unit: variable.unit,\n scopes: variable.scopes,\n codeSyntax: variable.codeSyntax,\n hiddenFromPublishing: variable.hiddenFromPublishing ?? false,\n description: variable.description ?? made.description\n }\n if (!isEmptyObject(expressions)) fields.expressions = expressions\n target.setTokenFields(made.id, fields)\n })\n })\n return { collectionIds, created }\n}\n\n/** The fields a style gives each layer that uses it, with the reference that keeps it attached. */\nfunction consumerPatch(style: SceneNode, kind: PlannedStyle['kind']): Partial<SceneNode> {\n if (kind === 'EFFECT')\n return { effects: copyEffects(style.effects), effectStyleId: style.source.id }\n const fields: Partial<SceneNode> = { textStyleId: style.source.id }\n for (const field of TEXT_STYLE_FIELDS) Object.assign(fields, { [field]: style[field] })\n return fields\n}\n\n/** The fields of `changes` that differ from what `node` holds, or null when none do. */\nfunction changedFields(node: SceneNode, changes: Partial<SceneNode>): Partial<SceneNode> | null {\n const changed = Object.fromEntries(\n Object.entries(changes).filter(([key, value]) => !isEqual(node[key as keyof SceneNode], value))\n )\n return isEmptyObject(changed) ? null : changed\n}\n\n/**\n * Layers that use a style and hold its values themselves. Layers inside an instance follow their\n * component instead, and changing them would make overrides of what should stay inherited.\n */\nfunction refKeyOf(kind: PlannedStyle['kind']) {\n return kind === 'TEXT' ? ('textStyleId' as const) : ('effectStyleId' as const)\n}\n\nfunction styleConsumers(graph: SceneGraph, style: SceneNode, kind: PlannedStyle['kind']) {\n const refKey = refKeyOf(kind)\n return [...graph.getAllNodes()].filter(\n (node) =>\n node[refKey] === style.source.id &&\n node.id !== style.id &&\n !findInstanceAncestor(graph, node.id)\n )\n}\n\nfunction applyStyles(\n target: TokenImportTarget,\n plan: TokenImportPlan,\n created: ReadonlyArray<ReadonlyArray<Variable>>\n): string[] {\n return plan.styles.map((style) => {\n const existing = style.existingNodeId ? target.graph.getNode(style.existingNodeId) : undefined\n const node = existing ?? target.addStyle(style, { ...style.fields, name: style.name })\n const own = existing && changedFields(existing, style.fields)\n if (own) target.updateNode(node.id, own)\n for (const [field, alias] of Object.entries(style.bindings)) {\n const variableId = aliasId(alias, created)\n if (variableId && node.boundVariables[field] !== variableId)\n target.bindVariable(node.id, field, variableId)\n }\n if (own && node.source.id) {\n const patch = consumerPatch(node, style.kind)\n for (const consumer of styleConsumers(target.graph, node, style.kind)) {\n const changes = changedFields(consumer, patch)\n // The style reference always goes along, or changing styled fields would detach it.\n if (changes)\n target.updateNode(consumer.id, { ...changes, ...pick(patch, [refKeyOf(style.kind)]) })\n }\n }\n return node.id\n })\n}\n\n/**\n * Applies an import plan: collections and modes first, then every variable, then their values,\n * so an alias can point at a variable the same import adds, and last the styles, whose bindings\n * and the layers that use them follow. Nothing is deleted.\n */\nexport function applyTokenImport(\n target: TokenImportTarget,\n plan: TokenImportPlan\n): TokenImportResult {\n const { collectionIds, created } = applyVariables(target, plan)\n const styleNodeIds = applyStyles(target, plan, created)\n return {\n collectionIds,\n variableIds: compact(created.flat().map((variable) => variable.id)),\n styleNodeIds\n }\n}\n\n/** A style node: hidden from the layer list, found by its style id, as `.fig` styles are. */\nexport function styleNodeProps(\n style: PlannedStyle,\n fields: Partial<SceneNode>\n): Partial<SceneNode> {\n return { ...fields, sharedStyleType: style.kind, internalOnly: true }\n}\n\nexport function styleNodeType(style: PlannedStyle) {\n return style.kind === 'TEXT' ? ('TEXT' as const) : ('RECTANGLE' as const)\n}\n\n/** The changes made directly on a graph, without history. */\nfunction graphTokenImportTarget(\n graph: SceneGraph,\n pageId: string,\n changed: Set<string>\n): TokenImportTarget {\n const collection = (id: string) => graph.variableCollections.get(id)\n return {\n graph,\n addCollection: (name) => graph.createCollection(name),\n addMode: (collectionId, name) => graph.createMode(collectionId, name),\n renameMode: (collectionId, modeId, name) => graph.renameMode(collectionId, modeId, name),\n setDefaultMode: (collectionId, modeId) => graph.setDefaultMode(collectionId, modeId),\n setModeCondition: (collectionId, modeId, condition) => {\n const mode = collection(collectionId)?.modes.find((entry) => entry.modeId === modeId)\n if (mode) mode.condition = condition\n },\n setModeAttribute: (collectionId, name) => {\n const found = collection(collectionId)\n if (found) found.modeAttribute = name\n },\n addVariable: (planned, collectionId) =>\n graph.createVariable(planned.name, planned.type, collectionId),\n setValue: (variableId, modeId, value) => {\n const variable = graph.variables.get(variableId)\n if (!variable) return\n variable.valuesByMode[modeId] = structuredClone(value)\n changed.add(variableId)\n },\n setTokenFields: (variableId, fields) => {\n const variable = graph.variables.get(variableId)\n if (!variable) return\n for (const [key, value] of Object.entries(fields))\n if (value === undefined) Reflect.deleteProperty(variable, key)\n else Object.assign(variable, { [key]: structuredClone(value) })\n },\n addStyle: (style, fields) => {\n const node = graph.createNode(styleNodeType(style), pageId, styleNodeProps(style, fields))\n node.source.id = `style:${randomHex(12)}`\n return node\n },\n updateNode: (nodeId, changes) => graph.updateNode(nodeId, changes),\n bindVariable: (nodeId, field, variableId) => graph.bindVariable(nodeId, field, variableId)\n }\n}\n\n/**\n * Imports straight into a graph, for scripts, tools, and the CLI working on a document without\n * an editor; the layers bound to variables whose values changed are resolved and laid out\n * afterwards.\n */\nexport function importTokensIntoGraph(\n graph: SceneGraph,\n pageId: string,\n plan: TokenImportPlan\n): TokenImportResult {\n const changed = new Set<string>()\n const result = applyTokenImport(graphTokenImportTarget(graph, pageId, changed), plan)\n if (changed.size > 0) reconcileVariableLayouts(graph, { variables: changed })\n return result\n}\n"],"mappings":";;;;;;;;;AA6DA,MAAM,oBAAoB;CACxB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,SAAS,iBAAiB,QAA2B,SAAoC;CACvF,IAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,QAAQ,OAAO;CAC9D,OAAO,OAAO,cAAc,QAAQ,OAAO,IAAI,CAAC,CAAC;AACnD;;AAGA,SAAS,YACP,QACA,SACA,cACU;CACV,MAAM,aAAa,OAAO,MAAM,oBAAoB,IAAI,YAAY;CACpE,IAAI,YAAY,QAAQ,OAAO,SAAS,QAAS,YAAY,iBAAiB,OAAQ;CACtF,MAAM,UAAU,QAAQ,MAAM,KAAK,SAAS;EAC1C,IAAI,KAAK,OAAO,SAAS,YAAY,OAAO,KAAK,OAAO;EACxD,IAAI,WAAW;GACb,MAAM,SAAS;GACf,YAAY;GACZ,OAAO,WAAW,cAAc,QAAQ,KAAK,OAAO,IAAI;GACxD,OAAO;EACT;EACA,OAAO,OAAO,QAAQ,cAAc,KAAK,OAAO,IAAI,KAAK;CAC3D,CAAC;CACD,QAAQ,MAAM,SAAS,MAAM,UAAU;EACrC,IAAI,KAAK,WAAW,OAAO,iBAAiB,cAAc,QAAQ,QAAQ,KAAK,SAAS;CAC1F,CAAC;CACD,IAAI,QAAQ,OAAO,SAAS,OAAO;EACjC,MAAM,eAAe,QAAQ,MAAM,WAAW,SAAS,KAAK,SAAS;EACrE,IAAI,eAAe,GAAG,OAAO,eAAe,cAAc,QAAQ,aAAa;EAC/E,IAAI,QAAQ,eAAe,OAAO,iBAAiB,cAAc,QAAQ,aAAa;CACxF;CACA,OAAO;AACT;AAEA,SAAS,QAA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ACjE,eAAe,QAAQ,OAAO,eAAe,MAAM,aAAa,QAAQ,OAAO,UAAU;CAC3F;AACF;;;;;;AAOA,SAAgB,sBACd,OACA,QACA,MACmB;CACnB,MAAM,0BAAU,IAAI,IAAY;CAChC,MAAM,SAAS,iBAAiB,uBAAuB,OAAO,QAAQ,OAAO,GAAG,IAAI;CACpF,IAAI,QAAQ,OAAO,GAAG,yBAAyB,OAAO,EAAE,WAAW,QAAQ,CAAC;CAC5E,OAAO;AACT"}
1
+ {"version":3,"file":"apply.js","names":[],"sources":["../../../../src/io/formats/design-tokens/apply.ts"],"sourcesContent":["import { compact } from 'es-toolkit/array'\nimport { pick } from 'es-toolkit/object'\nimport { isEmptyObject, isEqual } from 'es-toolkit/predicate'\n\nimport type {\n CodeSyntaxPlatform,\n SceneGraph,\n SceneNode,\n SharedStyleType,\n TokenExpression,\n TokenUnit,\n Variable,\n VariableCollection,\n VariableScope,\n VariableValue\n} from '@pairdraw/scene-graph'\nimport { copyEffects } from '@pairdraw/scene-graph/copy'\nimport { findInstanceAncestor } from '@pairdraw/scene-graph/instances'\nimport { randomHex } from '@pairdraw/scene-graph/random'\n\nimport { reconcileVariableLayouts } from '#core/layout/variables'\n\nimport type { AliasTarget, PlannedCollection, PlannedVariable, TokenImportPlan } from './plan'\nimport type { PlannedStyle } from './plan/styles'\n\n/** Token fields an import sets; `undefined` clears one. */\nexport interface ImportedTokenFields {\n unit?: TokenUnit\n scopes?: VariableScope[]\n codeSyntax?: Partial<Record<CodeSyntaxPlatform, string>>\n hiddenFromPublishing?: boolean\n description?: string\n expressions?: Record<string, TokenExpression>\n}\n\n/**\n * The changes an import makes, so the editor can make them undoable and a headless document can\n * make them directly. Each adds to or changes the document; none deletes.\n */\nexport interface TokenImportTarget {\n graph: SceneGraph\n addCollection(name: string): VariableCollection\n addMode(collectionId: string, name: string): string | undefined\n renameMode(collectionId: string, modeId: string, name: string): void\n setDefaultMode(collectionId: string, modeId: string): void\n setModeCondition(collectionId: string, modeId: string, condition: string): void\n setModeAttribute(collectionId: string, name: string): void\n addVariable(planned: PlannedVariable, collectionId: string): Variable\n setValue(variableId: string, modeId: string, value: VariableValue): void\n setTokenFields(variableId: string, fields: ImportedTokenFields): void\n addStyle(style: PlannedStyle, fields: Partial<SceneNode>): SceneNode\n updateNode(nodeId: string, changes: Partial<SceneNode>): void\n bindVariable(nodeId: string, field: string, variableId: string): void\n}\n\nexport interface TokenImportResult {\n collectionIds: string[]\n variableIds: string[]\n styleNodeIds: string[]\n}\n\n/** Text fields a text style gives the layers that use it. */\nconst TEXT_STYLE_FIELDS = [\n 'fontFamily',\n 'fontWeight',\n 'italic',\n 'fontSize',\n 'lineHeight',\n 'letterSpacing',\n 'textDecoration',\n 'textCase'\n] as const satisfies ReadonlyArray<keyof SceneNode>\n\nfunction targetCollection(target: TokenImportTarget, planned: PlannedCollection): string {\n if (planned.target.kind === 'existing') return planned.target.collectionId\n return target.addCollection(planned.target.name).id\n}\n\n/** Mode ids by planned mode: matched ones, a new collection's first renamed, or new ones. */\nfunction targetModes(\n target: TokenImportTarget,\n planned: PlannedCollection,\n collectionId: string\n): string[] {\n const collection = target.graph.variableCollections.get(collectionId)\n let unclaimed = planned.target.kind === 'new' ? (collection?.defaultModeId ?? null) : null\n const modeIds = planned.modes.map((mode) => {\n if (mode.target.kind === 'existing') return mode.target.modeId\n if (unclaimed) {\n const modeId = unclaimed\n unclaimed = null\n target.renameMode(collectionId, modeId, mode.target.name)\n return modeId\n }\n return target.addMode(collectionId, mode.target.name) ?? ''\n })\n planned.modes.forEach((mode, index) => {\n if (mode.condition) target.setModeCondition(collectionId, modeIds[index], mode.condition)\n })\n if (planned.target.kind === 'new') {\n const defaultIndex = planned.modes.findIndex((mode) => mode.isDefault)\n if (defaultIndex > 0) target.setDefaultMode(collectionId, modeIds[defaultIndex])\n if (planned.modeAttribute) target.setModeAttribute(collectionId, planned.modeAttribute)\n }\n return modeIds\n}\n\nfunction aliasId(target: AliasTarget, created: ReadonlyArray<ReadonlyArray<Variable>>) {\n if (target.kind === 'variable') return target.variableId\n return created.at(target.collection)?.at(target.variable)?.id\n}\n\nfunction plannedValue(\n value: NonNullable<PlannedVariable['values'][number]>,\n created: ReadonlyArray<ReadonlyArray<Variable>>\n): VariableValue | undefined {\n if (value.kind === 'literal') return value.value\n const id = aliasId(value.target, created)\n return id ? { aliasId: id } : undefined\n}\n\nfunction applyVariables(target: TokenImportTarget, plan: TokenImportPlan) {\n const collectionIds = plan.collections.map((planned) => targetCollection(target, planned))\n const modeIds = plan.collections.map((planned, index) =>\n targetModes(target, planned, collectionIds[index])\n )\n // Every variable exists before any value is set, so aliases can point at later ones.\n const created = plan.collections.map((planned, index) =>\n planned.variables.map((variable) =>\n variable.existingId\n ? (target.graph.variables.get(variable.existingId) ??\n target.addVariable(variable, collectionIds[index]))\n : target.addVariable(variable, collectionIds[index])\n )\n )\n plan.collections.forEach((planned, collectionIndex) => {\n planned.variables.forEach((variable, variableIndex) => {\n const made = created[collectionIndex][variableIndex]\n const modes = modeIds[collectionIndex]\n variable.values.forEach((value, modeIndex) => {\n const next = value && plannedValue(value, created)\n const modeId = modes[modeIndex]\n if (next !== undefined && modeId && !isEqual(made.valuesByMode[modeId], next))\n target.setValue(made.id, modeId, next)\n })\n const expressions = Object.fromEntries(\n variable.expressions.flatMap((css, modeIndex) => {\n const resolved = made.valuesByMode[modes[modeIndex]]\n return css && typeof resolved === 'number' ? [[modes[modeIndex], { css, resolved }]] : []\n })\n )\n const fields: ImportedTokenFields = {\n unit: variable.unit,\n scopes: variable.scopes,\n codeSyntax: variable.codeSyntax,\n hiddenFromPublishing: variable.hiddenFromPublishing ?? false,\n description: variable.description ?? made.description\n }\n if (!isEmptyObject(expressions)) fields.expressions = expressions\n target.setTokenFields(made.id, fields)\n })\n })\n return { collectionIds, created }\n}\n\n/** The fields a style gives each layer that uses it, with the reference that keeps it attached. */\nfunction consumerPatch(style: SceneNode, kind: PlannedStyle['kind']): Partial<SceneNode> {\n if (kind === 'EFFECT')\n return { effects: copyEffects(style.effects), effectStyleId: style.source.id }\n const fields: Partial<SceneNode> = { textStyleId: style.source.id }\n for (const field of TEXT_STYLE_FIELDS) Object.assign(fields, { [field]: style[field] })\n return fields\n}\n\n/** The fields of `changes` that differ from what `node` holds, or null when none do. */\nfunction changedFields(node: SceneNode, changes: Partial<SceneNode>): Partial<SceneNode> | null {\n const changed = Object.fromEntries(\n Object.entries(changes).filter(([key, value]) => !isEqual(node[key as keyof SceneNode], value))\n )\n return isEmptyObject(changed) ? null : changed\n}\n\n/**\n * Layers that use a style and hold its values themselves. Layers inside an instance follow their\n * component instead, and changing them would make overrides of what should stay inherited.\n */\nfunction refKeyOf(kind: PlannedStyle['kind']) {\n return kind === 'TEXT' ? ('textStyleId' as const) : ('effectStyleId' as const)\n}\n\nfunction styleConsumers(graph: SceneGraph, style: SceneNode, kind: PlannedStyle['kind']) {\n const refKey = refKeyOf(kind)\n return [...graph.getAllNodes()].filter(\n (node) =>\n node[refKey] === style.source.id &&\n node.id !== style.id &&\n !findInstanceAncestor(graph, node.id)\n )\n}\n\nfunction applyStyles(\n target: TokenImportTarget,\n plan: TokenImportPlan,\n created: ReadonlyArray<ReadonlyArray<Variable>>\n): string[] {\n return plan.styles.map((style) => {\n const existing = style.existingNodeId ? target.graph.getNode(style.existingNodeId) : undefined\n const node = existing ?? target.addStyle(style, { ...style.fields, name: style.name })\n const own = existing && changedFields(existing, style.fields)\n if (own) target.updateNode(node.id, own)\n for (const [field, alias] of Object.entries(style.bindings)) {\n const variableId = aliasId(alias, created)\n if (variableId && node.boundVariables[field] !== variableId)\n target.bindVariable(node.id, field, variableId)\n }\n if (own && node.source.id) {\n const patch = consumerPatch(node, style.kind)\n for (const consumer of styleConsumers(target.graph, node, style.kind)) {\n const changes = changedFields(consumer, patch)\n // The style reference always goes along, or changing styled fields would detach it.\n if (changes)\n target.updateNode(consumer.id, { ...changes, ...pick(patch, [refKeyOf(style.kind)]) })\n }\n }\n return node.id\n })\n}\n\n/**\n * Applies an import plan: collections and modes first, then every variable, then their values,\n * so an alias can point at a variable the same import adds, and last the styles, whose bindings\n * and the layers that use them follow. Nothing is deleted.\n */\nexport function applyTokenImport(\n target: TokenImportTarget,\n plan: TokenImportPlan\n): TokenImportResult {\n const { collectionIds, created } = applyVariables(target, plan)\n const styleNodeIds = applyStyles(target, plan, created)\n return {\n collectionIds,\n variableIds: compact(created.flat().map((variable) => variable.id)),\n styleNodeIds\n }\n}\n\n/** A style node: hidden from the layer list, found by its style id, as `.fig` styles are. */\nexport function styleNodeProps(\n style: Pick<PlannedStyle, 'kind'> | { kind: SharedStyleType },\n fields: Partial<SceneNode>\n): Partial<SceneNode> {\n return { ...fields, sharedStyleType: style.kind, internalOnly: true }\n}\n\nexport function styleNodeType(style: Pick<PlannedStyle, 'kind'> | { kind: SharedStyleType }) {\n return style.kind === 'TEXT' ? ('TEXT' as const) : ('RECTANGLE' as const)\n}\n\n/** The changes made directly on a graph, without history. */\nfunction graphTokenImportTarget(\n graph: SceneGraph,\n pageId: string,\n changed: Set<string>\n): TokenImportTarget {\n const collection = (id: string) => graph.variableCollections.get(id)\n return {\n graph,\n addCollection: (name) => graph.createCollection(name),\n addMode: (collectionId, name) => graph.createMode(collectionId, name),\n renameMode: (collectionId, modeId, name) => graph.renameMode(collectionId, modeId, name),\n setDefaultMode: (collectionId, modeId) => graph.setDefaultMode(collectionId, modeId),\n setModeCondition: (collectionId, modeId, condition) => {\n const mode = collection(collectionId)?.modes.find((entry) => entry.modeId === modeId)\n if (mode) mode.condition = condition\n },\n setModeAttribute: (collectionId, name) => {\n const found = collection(collectionId)\n if (found) found.modeAttribute = name\n },\n addVariable: (planned, collectionId) =>\n graph.createVariable(planned.name, planned.type, collectionId),\n setValue: (variableId, modeId, value) => {\n const variable = graph.variables.get(variableId)\n if (!variable) return\n variable.valuesByMode[modeId] = structuredClone(value)\n changed.add(variableId)\n },\n setTokenFields: (variableId, fields) => {\n const variable = graph.variables.get(variableId)\n if (!variable) return\n for (const [key, value] of Object.entries(fields))\n if (value === undefined) Reflect.deleteProperty(variable, key)\n else Object.assign(variable, { [key]: structuredClone(value) })\n },\n addStyle: (style, fields) => {\n const node = graph.createNode(styleNodeType(style), pageId, styleNodeProps(style, fields))\n node.source.id = `style:${randomHex(12)}`\n return node\n },\n updateNode: (nodeId, changes) => graph.updateNode(nodeId, changes),\n bindVariable: (nodeId, field, variableId) => graph.bindVariable(nodeId, field, variableId)\n }\n}\n\n/**\n * Imports straight into a graph, for scripts, tools, and the CLI working on a document without\n * an editor; the layers bound to variables whose values changed are resolved and laid out\n * afterwards.\n */\nexport function importTokensIntoGraph(\n graph: SceneGraph,\n pageId: string,\n plan: TokenImportPlan\n): TokenImportResult {\n const changed = new Set<string>()\n const result = applyTokenImport(graphTokenImportTarget(graph, pageId, changed), plan)\n if (changed.size > 0) reconcileVariableLayouts(graph, { variables: changed })\n return result\n}\n"],"mappings":";;;;;;;;;AA8DA,MAAM,oBAAoB;CACxB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,SAAS,iBAAiB,QAA2B,SAAoC;CACvF,IAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,QAAQ,OAAO;CAC9D,OAAO,OAAO,cAAc,QAAQ,OAAO,IAAI,CAAC,CAAC;AACnD;;AAGA,SAAS,YACP,QACA,SACA,cACU;CACV,MAAM,aAAa,OAAO,MAAM,oBAAoB,IAAI,YAAY;CACpE,IAAI,YAAY,QAAQ,OAAO,SAAS,QAAS,YAAY,iBAAiB,OAAQ;CACtF,MAAM,UAAU,QAAQ,MAAM,KAAK,SAAS;EAC1C,IAAI,KAAK,OAAO,SAAS,YAAY,OAAO,KAAK,OAAO;EACxD,IAAI,WAAW;GACb,MAAM,SAAS;GACf,YAAY;GACZ,OAAO,WAAW,cAAc,QAAQ,KAAK,OAAO,IAAI;GACxD,OAAO;EACT;EACA,OAAO,OAAO,QAAQ,cAAc,KAAK,OAAO,IAAI,KAAK;CAC3D,CAAC;CACD,QAAQ,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O,QAAQ,MAAM,GAC9C,IAAI,UAAU,KAAA,GAAW,QAAQ,eAAe,UAAU,GAAG;QACxD,OAAO,OAAO,UAAU,GAAG,MAAM,gBAAgB,KAAK,EAAE,CAAC;EAClE;EACA,WAAW,OAAO,WAAW;GAC3B,MAAM,OAAO,MAAM,WAAW,cAAc,KAAK,GAAG,QAAQ,eAAe,OAAO,MAAM,CAAC;GACzF,KAAK,OAAO,KAAK,SAAS,UAAU,EAAE;GACtC,OAAO;EACT;EACA,aAAa,QAAQ,YAAY,MAAM,WAAW,QAAQ,OAAO;EACjE,eAAe,QAAQ,OAAO,eAAe,MAAM,aAAa,QAAQ,OAAO,UAAU;CAC3F;AACF;;;;;;AAOA,SAAgB,sBACd,OACA,QACA,MACmB;CACnB,MAAM,0BAAU,IAAI,IAAY;CAChC,MAAM,SAAS,iBAAiB,uBAAuB,OAAO,QAAQ,OAAO,GAAG,IAAI;CACpF,IAAI,QAAQ,OAAO,GAAG,yBAAyB,OAAO,EAAE,WAAW,QAAQ,CAAC;CAC5E,OAAO;AACT"}
@@ -1,11 +1,26 @@
1
1
  import { SceneGraph } from "@pairdraw/scene-graph";
2
2
  //#region src/io/formats/drawio/warnings.d.ts
3
+ /**
4
+ * What a draw.io file could not hold, as facts rather than a sentence: the app shows these in the
5
+ * reader's language, while the CLI and MCP print `drawioWriteWarningText` of each.
6
+ */
7
+ interface DrawioWriteWarning {
8
+ kind: 'unbound-variables';
9
+ /** Variables the graph holds, none of which draw.io can carry. */
10
+ variables: number;
11
+ /** The collections those variables belong to, by name. */
12
+ collections: string[];
13
+ /** Layers painted through a binding, which open without it. */
14
+ layers: number;
15
+ }
3
16
  /**
4
17
  * What a draw.io file cannot hold. draw.io has no variable model and no style that reads one, so
5
18
  * a document that paints with variables arrives in draw.io as plain colours and comes back
6
19
  * unbound. The writer names that loss instead of writing a file that looks complete.
7
20
  */
8
- declare function drawioDroppedWarnings(graph: SceneGraph): string[];
21
+ declare function drawioWriteWarnings(graph: SceneGraph): DrawioWriteWarning[];
22
+ /** The English sentence a write warning has always been reported as. */
23
+ declare function drawioWriteWarningText(warning: DrawioWriteWarning): string;
9
24
  //#endregion
10
- export { drawioDroppedWarnings };
25
+ export { DrawioWriteWarning, drawioWriteWarningText, drawioWriteWarnings };
11
26
  //# sourceMappingURL=warnings.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"warnings.d.ts","names":[],"sources":["../../../../src/io/formats/drawio/warnings.ts"],"mappings":";;;;;;;iBAYgB,sBAAsB,OAAO"}
1
+ {"version":3,"file":"warnings.d.ts","names":[],"sources":["../../../../src/io/formats/drawio/warnings.ts"],"mappings":";;;;;;UAWiB;EACf;;EAEA;;EAEA;;EAEA;;;;;;;iBAQc,oBAAoB,OAAO,aAAa;;iBAWxC,uBAAuB,SAAS"}
@@ -8,16 +8,23 @@ function counted(count, one, many) {
8
8
  * a document that paints with variables arrives in draw.io as plain colours and comes back
9
9
  * unbound. The writer names that loss instead of writing a file that looks complete.
10
10
  */
11
- function drawioDroppedWarnings(graph) {
11
+ function drawioWriteWarnings(graph) {
12
12
  const variables = graph.getLiveVariables().length;
13
13
  if (variables === 0) return [];
14
- const names = graph.getLiveCollections().map((collection) => collection.name);
15
- const dropped = `draw.io has no variables: ${counted(variables, "variable", "variables")} in ${counted(names.length, "collection", "collections")} (${names.join(", ")}) not written`;
16
- const bound = [...graph.nodes.values()].filter((node) => Object.keys(node.boundVariables).length > 0).length;
17
- if (bound === 0) return [dropped];
18
- return [`${dropped}, and ${bound === 1 ? "1 layer that uses one lost the binding" : `${counted(bound, "layer", "layers")} that use them lost the binding`}`];
14
+ return [{
15
+ kind: "unbound-variables",
16
+ variables,
17
+ collections: graph.getLiveCollections().map((collection) => collection.name),
18
+ layers: [...graph.nodes.values()].filter((node) => Object.keys(node.boundVariables).length > 0).length
19
+ }];
20
+ }
21
+ /** The English sentence a write warning has always been reported as. */
22
+ function drawioWriteWarningText(warning) {
23
+ const dropped = `draw.io has no variables: ${counted(warning.variables, "variable", "variables")} in ${counted(warning.collections.length, "collection", "collections")} (${warning.collections.join(", ")}) not written`;
24
+ if (warning.layers === 0) return dropped;
25
+ return `${dropped}, and ${warning.layers === 1 ? "1 layer that uses one lost the binding" : `${counted(warning.layers, "layer", "layers")} that use them lost the binding`}`;
19
26
  }
20
27
  //#endregion
21
- export { drawioDroppedWarnings };
28
+ export { drawioWriteWarningText, drawioWriteWarnings };
22
29
 
23
30
  //# sourceMappingURL=warnings.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"warnings.js","names":[],"sources":["../../../../src/io/formats/drawio/warnings.ts"],"sourcesContent":["import type { SceneGraph } from '@pairdraw/scene-graph'\n\n/** `3 variables`, with the noun matching the count. */\nfunction counted(count: number, one: string, many: string): string {\n return `${count} ${count === 1 ? one : many}`\n}\n\n/**\n * What a draw.io file cannot hold. draw.io has no variable model and no style that reads one, so\n * a document that paints with variables arrives in draw.io as plain colours and comes back\n * unbound. The writer names that loss instead of writing a file that looks complete.\n */\nexport function drawioDroppedWarnings(graph: SceneGraph): string[] {\n const variables = graph.getLiveVariables().length\n if (variables === 0) return []\n const names = graph.getLiveCollections().map((collection) => collection.name)\n const dropped = `draw.io has no variables: ${counted(variables, 'variable', 'variables')} in ${counted(names.length, 'collection', 'collections')} (${names.join(', ')}) not written`\n const bound = [...graph.nodes.values()].filter(\n (node) => Object.keys(node.boundVariables).length > 0\n ).length\n if (bound === 0) return [dropped]\n const users =\n bound === 1\n ? '1 layer that uses one lost the binding'\n : `${counted(bound, 'layer', 'layers')} that use them lost the binding`\n return [`${dropped}, and ${users}`]\n}\n"],"mappings":";;AAGA,SAAS,QAAQ,OAAe,KAAa,MAAsB;CACjE,OAAO,GAAG,MAAM,GAAG,UAAU,IAAI,MAAM;AACzC;;;;;;AAOA,SAAgB,sBAAsB,OAA6B;CACjE,MAAM,YAAY,MAAM,iBAAiB,CAAC,CAAC;CAC3C,IAAI,cAAc,GAAG,OAAO,CAAC;CAC7B,MAAM,QAAQ,MAAM,mBAAmB,CAAC,CAAC,KAAK,eAAe,WAAW,IAAI;CAC5E,MAAM,UAAU,6BAA6B,QAAQ,WAAW,YAAY,WAAW,EAAE,MAAM,QAAQ,MAAM,QAAQ,cAAc,aAAa,EAAE,IAAI,MAAM,KAAK,IAAI,EAAE;CACvK,MAAM,QAAQ,CAAC,GAAG,MAAM,MAAM,OAAO,CAAC,CAAC,CAAC,QACrC,SAAS,OAAO,KAAK,KAAK,cAAc,CAAC,CAAC,SAAS,CACtD,CAAC,CAAC;CACF,IAAI,UAAU,GAAG,OAAO,CAAC,OAAO;CAKhC,OAAO,CAAC,GAAG,QAAQ,QAHjB,UAAU,IACN,2CACA,GAAG,QAAQ,OAAO,SAAS,QAAQ,EAAE,kCACT;AACpC"}
1
+ {"version":3,"file":"warnings.js","names":[],"sources":["../../../../src/io/formats/drawio/warnings.ts"],"sourcesContent":["import type { SceneGraph } from '@pairdraw/scene-graph'\n\n/** `3 variables`, with the noun matching the count. */\nfunction counted(count: number, one: string, many: string): string {\n return `${count} ${count === 1 ? one : many}`\n}\n\n/**\n * What a draw.io file could not hold, as facts rather than a sentence: the app shows these in the\n * reader's language, while the CLI and MCP print `drawioWriteWarningText` of each.\n */\nexport interface DrawioWriteWarning {\n kind: 'unbound-variables'\n /** Variables the graph holds, none of which draw.io can carry. */\n variables: number\n /** The collections those variables belong to, by name. */\n collections: string[]\n /** Layers painted through a binding, which open without it. */\n layers: number\n}\n\n/**\n * What a draw.io file cannot hold. draw.io has no variable model and no style that reads one, so\n * a document that paints with variables arrives in draw.io as plain colours and comes back\n * unbound. The writer names that loss instead of writing a file that looks complete.\n */\nexport function drawioWriteWarnings(graph: SceneGraph): DrawioWriteWarning[] {\n const variables = graph.getLiveVariables().length\n if (variables === 0) return []\n const collections = graph.getLiveCollections().map((collection) => collection.name)\n const layers = [...graph.nodes.values()].filter(\n (node) => Object.keys(node.boundVariables).length > 0\n ).length\n return [{ kind: 'unbound-variables', variables, collections, layers }]\n}\n\n/** The English sentence a write warning has always been reported as. */\nexport function drawioWriteWarningText(warning: DrawioWriteWarning): string {\n const dropped = `draw.io has no variables: ${counted(warning.variables, 'variable', 'variables')} in ${counted(warning.collections.length, 'collection', 'collections')} (${warning.collections.join(', ')}) not written`\n if (warning.layers === 0) return dropped\n const users =\n warning.layers === 1\n ? '1 layer that uses one lost the binding'\n : `${counted(warning.layers, 'layer', 'layers')} that use them lost the binding`\n return `${dropped}, and ${users}`\n}\n"],"mappings":";;AAGA,SAAS,QAAQ,OAAe,KAAa,MAAsB;CACjE,OAAO,GAAG,MAAM,GAAG,UAAU,IAAI,MAAM;AACzC;;;;;;AAqBA,SAAgB,oBAAoB,OAAyC;CAC3E,MAAM,YAAY,MAAM,iBAAiB,CAAC,CAAC;CAC3C,IAAI,cAAc,GAAG,OAAO,CAAC;CAK7B,OAAO,CAAC;EAAE,MAAM;EAAqB;EAAW,aAJ5B,MAAM,mBAAmB,CAAC,CAAC,KAAK,eAAe,WAAW,IAIpB;EAAG,QAH9C,CAAC,GAAG,MAAM,MAAM,OAAO,CAAC,CAAC,CAAC,QACtC,SAAS,OAAO,KAAK,KAAK,cAAc,CAAC,CAAC,SAAS,CACtD,CAAC,CAAC;CACkE,CAAC;AACvE;;AAGA,SAAgB,uBAAuB,SAAqC;CAC1E,MAAM,UAAU,6BAA6B,QAAQ,QAAQ,WAAW,YAAY,WAAW,EAAE,MAAM,QAAQ,QAAQ,YAAY,QAAQ,cAAc,aAAa,EAAE,IAAI,QAAQ,YAAY,KAAK,IAAI,EAAE;CAC3M,IAAI,QAAQ,WAAW,GAAG,OAAO;CAKjC,OAAO,GAAG,QAAQ,QAHhB,QAAQ,WAAW,IACf,2CACA,GAAG,QAAQ,QAAQ,QAAQ,SAAS,QAAQ,EAAE;AAEtD"}
@@ -136,6 +136,11 @@ async function narrowToChangedFields(source, runtime, info, recordOwners, writte
136
136
  const fields = [];
137
137
  for (const record of written) {
138
138
  const id = record.guid ? guidToString(record.guid) : null;
139
+ const owner = id ? recordOwners.get(id) : void 0;
140
+ if (owner && source.getNode(owner)?.source.editedFields.includes("componentPropertyAssignments")) {
141
+ records.push(record);
142
+ continue;
143
+ }
139
144
  const saved = id ? baseline?.get(id) : void 0;
140
145
  if (!saved || !record.guid) {
141
146
  records.push(record);