@pairdraw/core 0.17.0 → 0.19.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1025) hide show
  1. package/dist/canvas/effects.d.ts +5 -11
  2. package/dist/canvas/effects.d.ts.map +1 -1
  3. package/dist/canvas/effects.js +25 -30
  4. package/dist/canvas/effects.js.map +1 -1
  5. package/dist/canvas/labels/hit-test.d.ts +5 -0
  6. package/dist/canvas/labels/hit-test.d.ts.map +1 -1
  7. package/dist/canvas/labels/hit-test.js +1 -1
  8. package/dist/canvas/labels/hit-test.js.map +1 -1
  9. package/dist/canvas/labels/paragraph-cache.d.ts.map +1 -1
  10. package/dist/canvas/labels/paragraph-cache.js +3 -2
  11. package/dist/canvas/labels/paragraph-cache.js.map +1 -1
  12. package/dist/canvas/labels/selection.js +3 -2
  13. package/dist/canvas/labels/selection.js.map +1 -1
  14. package/dist/canvas/labels/style.d.ts +1 -1
  15. package/dist/canvas/node-edit-overlay.js +2 -2
  16. package/dist/canvas/node-edit-overlay.js.map +1 -1
  17. package/dist/canvas/outline-stroke.d.ts.map +1 -1
  18. package/dist/canvas/outline-stroke.js.map +1 -1
  19. package/dist/canvas/overlays/index.d.ts +2 -2
  20. package/dist/canvas/overlays/index.js +2 -2
  21. package/dist/canvas/overlays/prototype.d.ts +2 -5
  22. package/dist/canvas/overlays/prototype.d.ts.map +1 -1
  23. package/dist/canvas/overlays/prototype.js +3 -19
  24. package/dist/canvas/overlays/prototype.js.map +1 -1
  25. package/dist/canvas/overlays/selection.d.ts +1 -2
  26. package/dist/canvas/overlays/selection.d.ts.map +1 -1
  27. package/dist/canvas/overlays/selection.js +4 -37
  28. package/dist/canvas/overlays/selection.js.map +1 -1
  29. package/dist/canvas/region-hatch.js +3 -2
  30. package/dist/canvas/region-hatch.js.map +1 -1
  31. package/dist/canvas/renderer/colors.d.ts.map +1 -1
  32. package/dist/canvas/renderer/colors.js +36 -18
  33. package/dist/canvas/renderer/colors.js.map +1 -1
  34. package/dist/canvas/renderer/font-waiters.d.ts +9 -0
  35. package/dist/canvas/renderer/font-waiters.d.ts.map +1 -0
  36. package/dist/canvas/renderer/font-waiters.js +26 -0
  37. package/dist/canvas/renderer/font-waiters.js.map +1 -0
  38. package/dist/canvas/renderer/fonts.d.ts +4 -2
  39. package/dist/canvas/renderer/fonts.d.ts.map +1 -1
  40. package/dist/canvas/renderer/fonts.js +25 -10
  41. package/dist/canvas/renderer/fonts.js.map +1 -1
  42. package/dist/canvas/renderer/lifecycle.d.ts.map +1 -1
  43. package/dist/canvas/renderer/lifecycle.js +6 -9
  44. package/dist/canvas/renderer/lifecycle.js.map +1 -1
  45. package/dist/canvas/renderer/methods.d.ts +4 -5
  46. package/dist/canvas/renderer/methods.d.ts.map +1 -1
  47. package/dist/canvas/renderer/methods.js +1 -4
  48. package/dist/canvas/renderer/methods.js.map +1 -1
  49. package/dist/canvas/renderer/paints.d.ts.map +1 -1
  50. package/dist/canvas/renderer/paints.js +0 -6
  51. package/dist/canvas/renderer/paints.js.map +1 -1
  52. package/dist/canvas/renderer/pipeline.d.ts.map +1 -1
  53. package/dist/canvas/renderer/pipeline.js +20 -2
  54. package/dist/canvas/renderer/pipeline.js.map +1 -1
  55. package/dist/canvas/renderer/retained-backing.js +4 -4
  56. package/dist/canvas/renderer/retained-backing.js.map +1 -1
  57. package/dist/canvas/renderer/state.js +1 -1
  58. package/dist/canvas/renderer/state.js.map +1 -1
  59. package/dist/canvas/renderer/tiles/controller.d.ts +2 -0
  60. package/dist/canvas/renderer/tiles/controller.d.ts.map +1 -1
  61. package/dist/canvas/renderer/tiles/controller.js +8 -0
  62. package/dist/canvas/renderer/tiles/controller.js.map +1 -1
  63. package/dist/canvas/renderer/tiles/surface-pool.js +1 -1
  64. package/dist/canvas/renderer/tiles/surface-pool.js.map +1 -1
  65. package/dist/canvas/renderer/visual-bounds.d.ts.map +1 -1
  66. package/dist/canvas/renderer/visual-bounds.js +7 -5
  67. package/dist/canvas/renderer/visual-bounds.js.map +1 -1
  68. package/dist/canvas/renderer.d.ts +26 -7
  69. package/dist/canvas/renderer.d.ts.map +1 -1
  70. package/dist/canvas/renderer.js +50 -11
  71. package/dist/canvas/renderer.js.map +1 -1
  72. package/dist/canvas/rulers.d.ts +8 -1
  73. package/dist/canvas/rulers.d.ts.map +1 -1
  74. package/dist/canvas/rulers.js +30 -5
  75. package/dist/canvas/rulers.js.map +1 -1
  76. package/dist/canvas/scene.d.ts +2 -1
  77. package/dist/canvas/scene.d.ts.map +1 -1
  78. package/dist/canvas/scene.js +90 -54
  79. package/dist/canvas/scene.js.map +1 -1
  80. package/dist/canvas/shadows/shape.js +1 -1
  81. package/dist/canvas/shadows/shape.js.map +1 -1
  82. package/dist/canvas/shadows/silhouette.d.ts.map +1 -1
  83. package/dist/canvas/shadows/silhouette.js +4 -2
  84. package/dist/canvas/shadows/silhouette.js.map +1 -1
  85. package/dist/canvas/shadows.d.ts.map +1 -1
  86. package/dist/canvas/shadows.js +3 -2
  87. package/dist/canvas/shadows.js.map +1 -1
  88. package/dist/canvas/text/derived.d.ts +1 -2
  89. package/dist/canvas/text/derived.d.ts.map +1 -1
  90. package/dist/canvas/text/derived.js +1 -7
  91. package/dist/canvas/text/derived.js.map +1 -1
  92. package/dist/canvas/text/emoji/index.js +1 -1
  93. package/dist/canvas/text/emoji/raster.d.ts.map +1 -1
  94. package/dist/canvas/text/emoji/raster.js +14 -10
  95. package/dist/canvas/text/emoji/raster.js.map +1 -1
  96. package/dist/canvas/text/font-families.d.ts +4 -3
  97. package/dist/canvas/text/font-families.d.ts.map +1 -1
  98. package/dist/canvas/text/font-families.js +13 -9
  99. package/dist/canvas/text/font-families.js.map +1 -1
  100. package/dist/canvas/text/index.d.ts +1 -3
  101. package/dist/canvas/text/index.d.ts.map +1 -1
  102. package/dist/canvas/text/index.js +2 -9
  103. package/dist/canvas/text/index.js.map +1 -1
  104. package/dist/canvas/text/layout/build.d.ts.map +1 -1
  105. package/dist/canvas/text/layout/build.js +25 -9
  106. package/dist/canvas/text/layout/build.js.map +1 -1
  107. package/dist/canvas/text/layout/index.d.ts.map +1 -1
  108. package/dist/canvas/text/layout/index.js +8 -4
  109. package/dist/canvas/text/layout/index.js.map +1 -1
  110. package/dist/canvas/text/layout/lines.js +5 -3
  111. package/dist/canvas/text/layout/lines.js.map +1 -1
  112. package/dist/canvas/text/paragraph/index.d.ts +5 -0
  113. package/dist/canvas/text/paragraph/index.d.ts.map +1 -1
  114. package/dist/canvas/text/paragraph/index.js +18 -9
  115. package/dist/canvas/text/paragraph/index.js.map +1 -1
  116. package/dist/canvas/text/paragraph/inputs.d.ts +1 -1
  117. package/dist/canvas/text/paragraph/inputs.d.ts.map +1 -1
  118. package/dist/canvas/text/paragraph/inputs.js +9 -2
  119. package/dist/canvas/text/paragraph/inputs.js.map +1 -1
  120. package/dist/canvas/text/placed.js +3 -3
  121. package/dist/canvas/text/placed.js.map +1 -1
  122. package/dist/canvas/text/renderer.d.ts +2 -0
  123. package/dist/canvas/text/renderer.d.ts.map +1 -1
  124. package/dist/canvas/text/shape.d.ts +4 -3
  125. package/dist/canvas/text/shape.d.ts.map +1 -1
  126. package/dist/canvas/text/shape.js +9 -22
  127. package/dist/canvas/text/shape.js.map +1 -1
  128. package/dist/constants.d.ts +6 -2
  129. package/dist/constants.d.ts.map +1 -1
  130. package/dist/constants.js +6 -2
  131. package/dist/constants.js.map +1 -1
  132. package/dist/design-jsx/renderer.d.ts.map +1 -1
  133. package/dist/editor/bridges/clipboard.d.ts +1 -0
  134. package/dist/editor/bridges/clipboard.js +1 -0
  135. package/dist/editor/bridges/clipboard.js.map +1 -1
  136. package/dist/editor/bridges/components.d.ts +2 -0
  137. package/dist/editor/bridges/components.d.ts.map +1 -1
  138. package/dist/editor/bridges/components.js +2 -0
  139. package/dist/editor/bridges/components.js.map +1 -1
  140. package/dist/editor/bridges/frames.d.ts +4 -3
  141. package/dist/editor/bridges/frames.d.ts.map +1 -1
  142. package/dist/editor/bridges/frames.js +6 -4
  143. package/dist/editor/bridges/frames.js.map +1 -1
  144. package/dist/editor/bridges/structure.d.ts +1 -0
  145. package/dist/editor/bridges/structure.d.ts.map +1 -1
  146. package/dist/editor/bridges/structure.js +1 -0
  147. package/dist/editor/bridges/structure.js.map +1 -1
  148. package/dist/editor/bridges/undo.d.ts +1 -1
  149. package/dist/editor/clipboard/detach.js +2 -2
  150. package/dist/editor/clipboard/detach.js.map +1 -1
  151. package/dist/editor/clipboard/paste/properties.js +1 -1
  152. package/dist/editor/clipboard/paste/target.js +2 -2
  153. package/dist/editor/clipboard/paste/target.js.map +1 -1
  154. package/dist/editor/clipboard/snapshot.d.ts +3 -0
  155. package/dist/editor/clipboard/snapshot.d.ts.map +1 -1
  156. package/dist/editor/clipboard/snapshot.js +2 -0
  157. package/dist/editor/clipboard/snapshot.js.map +1 -1
  158. package/dist/editor/clipboard/variables.d.ts.map +1 -1
  159. package/dist/editor/clipboard/variables.js +14 -1
  160. package/dist/editor/clipboard/variables.js.map +1 -1
  161. package/dist/editor/clipboard.d.ts +1 -0
  162. package/dist/editor/clipboard.d.ts.map +1 -1
  163. package/dist/editor/clipboard.js +122 -16
  164. package/dist/editor/clipboard.js.map +1 -1
  165. package/dist/editor/component-sync.d.ts +10 -1
  166. package/dist/editor/component-sync.d.ts.map +1 -1
  167. package/dist/editor/component-sync.js +25 -8
  168. package/dist/editor/component-sync.js.map +1 -1
  169. package/dist/editor/components/authoring/text-edit.d.ts.map +1 -1
  170. package/dist/editor/components/authoring/text-edit.js +11 -2
  171. package/dist/editor/components/authoring/text-edit.js.map +1 -1
  172. package/dist/editor/components/authoring/visibility-edit.d.ts.map +1 -1
  173. package/dist/editor/components/authoring/visibility-edit.js +7 -3
  174. package/dist/editor/components/authoring/visibility-edit.js.map +1 -1
  175. package/dist/editor/components/instances.d.ts +2 -0
  176. package/dist/editor/components/instances.d.ts.map +1 -1
  177. package/dist/editor/components/instances.js +37 -7
  178. package/dist/editor/components/instances.js.map +1 -1
  179. package/dist/editor/components/properties.d.ts.map +1 -1
  180. package/dist/editor/components/properties.js +3 -0
  181. package/dist/editor/components/properties.js.map +1 -1
  182. package/dist/editor/components/slots/authoring.js +2 -1
  183. package/dist/editor/components/slots/authoring.js.map +1 -1
  184. package/dist/editor/components.d.ts +2 -0
  185. package/dist/editor/components.d.ts.map +1 -1
  186. package/dist/editor/create.d.ts +18 -4
  187. package/dist/editor/create.d.ts.map +1 -1
  188. package/dist/editor/create.js +43 -6
  189. package/dist/editor/create.js.map +1 -1
  190. package/dist/editor/guides.d.ts.map +1 -1
  191. package/dist/editor/guides.js +20 -13
  192. package/dist/editor/guides.js.map +1 -1
  193. package/dist/editor/history/document-change.d.ts +19 -3
  194. package/dist/editor/history/document-change.d.ts.map +1 -1
  195. package/dist/editor/history/document-change.js +94 -8
  196. package/dist/editor/history/document-change.js.map +1 -1
  197. package/dist/editor/history/edit.d.ts.map +1 -1
  198. package/dist/editor/history/edit.js +56 -12
  199. package/dist/editor/history/edit.js.map +1 -1
  200. package/dist/editor/history/position.js +1 -4
  201. package/dist/editor/history/position.js.map +1 -1
  202. package/dist/editor/history/sources.d.ts +14 -0
  203. package/dist/editor/history/sources.d.ts.map +1 -0
  204. package/dist/editor/history/sources.js +24 -0
  205. package/dist/editor/history/sources.js.map +1 -0
  206. package/dist/editor/index.d.ts +2 -2
  207. package/dist/editor/index.js +1 -1
  208. package/dist/editor/layout-mode.d.ts.map +1 -1
  209. package/dist/editor/layout-mode.js +16 -1
  210. package/dist/editor/layout-mode.js.map +1 -1
  211. package/dist/editor/node-preview.d.ts.map +1 -1
  212. package/dist/editor/node-preview.js +26 -7
  213. package/dist/editor/node-preview.js.map +1 -1
  214. package/dist/editor/nodes.d.ts.map +1 -1
  215. package/dist/editor/nodes.js +33 -10
  216. package/dist/editor/nodes.js.map +1 -1
  217. package/dist/editor/nudge.d.ts.map +1 -1
  218. package/dist/editor/nudge.js +12 -2
  219. package/dist/editor/nudge.js.map +1 -1
  220. package/dist/editor/pages.d.ts +2 -1
  221. package/dist/editor/pages.d.ts.map +1 -1
  222. package/dist/editor/pages.js +94 -15
  223. package/dist/editor/pages.js.map +1 -1
  224. package/dist/editor/play/states.d.ts.map +1 -1
  225. package/dist/editor/play/states.js +0 -5
  226. package/dist/editor/play/states.js.map +1 -1
  227. package/dist/editor/read-only/actions.js +3 -0
  228. package/dist/editor/read-only/actions.js.map +1 -1
  229. package/dist/editor/selection/hit-test.d.ts +2 -1
  230. package/dist/editor/selection/hit-test.d.ts.map +1 -1
  231. package/dist/editor/selection/hit-test.js +29 -4
  232. package/dist/editor/selection/hit-test.js.map +1 -1
  233. package/dist/editor/selection.d.ts +2 -2
  234. package/dist/editor/selection.d.ts.map +1 -1
  235. package/dist/editor/shapes/pen.js +6 -2
  236. package/dist/editor/shapes/pen.js.map +1 -1
  237. package/dist/editor/shapes.d.ts.map +1 -1
  238. package/dist/editor/shapes.js +2 -1
  239. package/dist/editor/shapes.js.map +1 -1
  240. package/dist/editor/structure/auto-layout-wrap.d.ts.map +1 -1
  241. package/dist/editor/structure/auto-layout-wrap.js +12 -0
  242. package/dist/editor/structure/auto-layout-wrap.js.map +1 -1
  243. package/dist/editor/structure/boolean.js +1 -1
  244. package/dist/editor/structure/group/bounds.d.ts +4 -2
  245. package/dist/editor/structure/group/bounds.d.ts.map +1 -1
  246. package/dist/editor/structure/group/bounds.js +17 -4
  247. package/dist/editor/structure/group/bounds.js.map +1 -1
  248. package/dist/editor/structure/rename.d.ts +2 -3
  249. package/dist/editor/structure/rename.d.ts.map +1 -1
  250. package/dist/editor/structure/rename.js +2 -5
  251. package/dist/editor/structure/rename.js.map +1 -1
  252. package/dist/editor/structure/reorder.d.ts.map +1 -1
  253. package/dist/editor/structure/reorder.js +20 -9
  254. package/dist/editor/structure/reorder.js.map +1 -1
  255. package/dist/editor/structure/state.js +1 -1
  256. package/dist/editor/structure.d.ts +1 -0
  257. package/dist/editor/structure.d.ts.map +1 -1
  258. package/dist/editor/structure.js +76 -20
  259. package/dist/editor/structure.js.map +1 -1
  260. package/dist/editor/text/hyperlink.d.ts.map +1 -1
  261. package/dist/editor/text/hyperlink.js +1 -1
  262. package/dist/editor/text/hyperlink.js.map +1 -1
  263. package/dist/editor/text/name.d.ts +13 -5
  264. package/dist/editor/text/name.d.ts.map +1 -1
  265. package/dist/editor/text/name.js +47 -17
  266. package/dist/editor/text/name.js.map +1 -1
  267. package/dist/editor/text/pending-layout.d.ts +2 -1
  268. package/dist/editor/text/pending-layout.d.ts.map +1 -1
  269. package/dist/editor/text/pending-layout.js +33 -6
  270. package/dist/editor/text/pending-layout.js.map +1 -1
  271. package/dist/editor/text/selection-style.d.ts +1 -0
  272. package/dist/editor/text/selection-style.d.ts.map +1 -1
  273. package/dist/editor/text/selection-style.js +16 -4
  274. package/dist/editor/text/selection-style.js.map +1 -1
  275. package/dist/editor/text.d.ts +5 -0
  276. package/dist/editor/text.d.ts.map +1 -1
  277. package/dist/editor/text.js +70 -3
  278. package/dist/editor/text.js.map +1 -1
  279. package/dist/editor/types.d.ts +18 -1
  280. package/dist/editor/types.d.ts.map +1 -1
  281. package/dist/editor/undo.d.ts.map +1 -1
  282. package/dist/editor/undo.js +14 -2
  283. package/dist/editor/undo.js.map +1 -1
  284. package/dist/editor/variable-bindings.d.ts.map +1 -1
  285. package/dist/editor/variable-bindings.js +21 -2
  286. package/dist/editor/variable-bindings.js.map +1 -1
  287. package/dist/editor/variables.d.ts +1 -1
  288. package/dist/editor/variables.d.ts.map +1 -1
  289. package/dist/editor/variables.js +7 -8
  290. package/dist/editor/variables.js.map +1 -1
  291. package/dist/editor/viewport.d.ts +11 -2
  292. package/dist/editor/viewport.d.ts.map +1 -1
  293. package/dist/editor/viewport.js +61 -21
  294. package/dist/editor/viewport.js.map +1 -1
  295. package/dist/editor/views/actions.d.ts.map +1 -1
  296. package/dist/editor/views/actions.js +13 -5
  297. package/dist/editor/views/actions.js.map +1 -1
  298. package/dist/editor/views/present.d.ts +6 -4
  299. package/dist/editor/views/present.d.ts.map +1 -1
  300. package/dist/editor/views/present.js +12 -10
  301. package/dist/editor/views/present.js.map +1 -1
  302. package/dist/editor/views/types.d.ts +11 -5
  303. package/dist/editor/views/types.d.ts.map +1 -1
  304. package/dist/figma-api/accessor-utils.d.ts.map +1 -1
  305. package/dist/figma-api/accessor-utils.js +4 -1
  306. package/dist/figma-api/accessor-utils.js.map +1 -1
  307. package/dist/figma-api/accessors/basic.d.ts.map +1 -1
  308. package/dist/figma-api/accessors/basic.js +41 -21
  309. package/dist/figma-api/accessors/basic.js.map +1 -1
  310. package/dist/figma-api/accessors/layout.d.ts.map +1 -1
  311. package/dist/figma-api/accessors/layout.js +37 -7
  312. package/dist/figma-api/accessors/layout.js.map +1 -1
  313. package/dist/figma-api/accessors/reactions.d.ts +11 -0
  314. package/dist/figma-api/accessors/reactions.d.ts.map +1 -0
  315. package/dist/figma-api/accessors/reactions.js +30 -0
  316. package/dist/figma-api/accessors/reactions.js.map +1 -0
  317. package/dist/figma-api/accessors/strokes.d.ts.map +1 -1
  318. package/dist/figma-api/accessors/strokes.js +12 -4
  319. package/dist/figma-api/accessors/strokes.js.map +1 -1
  320. package/dist/figma-api/accessors/text/index.d.ts.map +1 -1
  321. package/dist/figma-api/accessors/text/index.js +3 -1
  322. package/dist/figma-api/accessors/text/index.js.map +1 -1
  323. package/dist/figma-api/accessors/vector.d.ts.map +1 -1
  324. package/dist/figma-api/accessors/vector.js +1 -1
  325. package/dist/figma-api/accessors/vector.js.map +1 -1
  326. package/dist/figma-api/accessors/visual.d.ts +6 -5
  327. package/dist/figma-api/accessors/visual.d.ts.map +1 -1
  328. package/dist/figma-api/accessors/visual.js +20 -17
  329. package/dist/figma-api/accessors/visual.js.map +1 -1
  330. package/dist/figma-api/components.d.ts.map +1 -1
  331. package/dist/figma-api/components.js +2 -1
  332. package/dist/figma-api/components.js.map +1 -1
  333. package/dist/figma-api/finite.d.ts +27 -0
  334. package/dist/figma-api/finite.d.ts.map +1 -0
  335. package/dist/figma-api/finite.js +69 -0
  336. package/dist/figma-api/finite.js.map +1 -0
  337. package/dist/figma-api/fonts/list.d.ts +13 -0
  338. package/dist/figma-api/fonts/list.d.ts.map +1 -0
  339. package/dist/figma-api/fonts/list.js +25 -0
  340. package/dist/figma-api/fonts/list.js.map +1 -0
  341. package/dist/figma-api/index.d.ts +63 -10
  342. package/dist/figma-api/index.d.ts.map +1 -1
  343. package/dist/figma-api/index.js +104 -17
  344. package/dist/figma-api/index.js.map +1 -1
  345. package/dist/figma-api/overrides.d.ts +6 -1
  346. package/dist/figma-api/overrides.d.ts.map +1 -1
  347. package/dist/figma-api/overrides.js +2 -2
  348. package/dist/figma-api/overrides.js.map +1 -1
  349. package/dist/figma-api/pending-layout.d.ts +12 -2
  350. package/dist/figma-api/pending-layout.d.ts.map +1 -1
  351. package/dist/figma-api/pending-layout.js +41 -1
  352. package/dist/figma-api/pending-layout.js.map +1 -1
  353. package/dist/figma-api/pending-sync.d.ts +19 -0
  354. package/dist/figma-api/pending-sync.d.ts.map +1 -0
  355. package/dist/figma-api/pending-sync.js +52 -0
  356. package/dist/figma-api/pending-sync.js.map +1 -0
  357. package/dist/figma-api/proxy.d.ts +15 -2
  358. package/dist/figma-api/proxy.d.ts.map +1 -1
  359. package/dist/figma-api/proxy.js +23 -3
  360. package/dist/figma-api/proxy.js.map +1 -1
  361. package/dist/figma-api/reactions.d.ts +104 -0
  362. package/dist/figma-api/reactions.d.ts.map +1 -0
  363. package/dist/figma-api/reactions.js +157 -0
  364. package/dist/figma-api/reactions.js.map +1 -0
  365. package/dist/figma-api/render-bounds.d.ts.map +1 -1
  366. package/dist/figma-api/render-bounds.js +4 -4
  367. package/dist/figma-api/render-bounds.js.map +1 -1
  368. package/dist/figma-api/serialization.js +12 -2
  369. package/dist/figma-api/serialization.js.map +1 -1
  370. package/dist/figma-api/slots.d.ts +7 -1
  371. package/dist/figma-api/slots.d.ts.map +1 -1
  372. package/dist/figma-api/slots.js +12 -4
  373. package/dist/figma-api/slots.js.map +1 -1
  374. package/dist/figma-api/strokes.d.ts +5 -2
  375. package/dist/figma-api/strokes.d.ts.map +1 -1
  376. package/dist/figma-api/strokes.js +12 -19
  377. package/dist/figma-api/strokes.js.map +1 -1
  378. package/dist/figma-api/text/bindings.js +1 -1
  379. package/dist/figma-api/text/index.d.ts +2 -3
  380. package/dist/figma-api/text/index.d.ts.map +1 -1
  381. package/dist/figma-api/text/index.js +2 -12
  382. package/dist/figma-api/text/index.js.map +1 -1
  383. package/dist/figma-api/variables/bindings.js +1 -1
  384. package/dist/figma-api/variables/variable.d.ts.map +1 -1
  385. package/dist/figma-api/variables/variable.js +2 -2
  386. package/dist/figma-api/variables/variable.js.map +1 -1
  387. package/dist/geometry/connectors.js +2 -14
  388. package/dist/geometry/connectors.js.map +1 -1
  389. package/dist/geometry/figma.d.ts +6 -1
  390. package/dist/geometry/figma.d.ts.map +1 -1
  391. package/dist/geometry/figma.js +8 -1
  392. package/dist/geometry/figma.js.map +1 -1
  393. package/dist/geometry/index.d.ts +3 -3
  394. package/dist/geometry/index.js +2 -2
  395. package/dist/geometry/scene.d.ts +3 -1
  396. package/dist/geometry/scene.d.ts.map +1 -1
  397. package/dist/geometry/scene.js +16 -1
  398. package/dist/geometry/scene.js.map +1 -1
  399. package/dist/geometry/types.d.ts +7 -1
  400. package/dist/geometry/types.d.ts.map +1 -1
  401. package/dist/icons/api.d.ts +3 -2
  402. package/dist/icons/api.d.ts.map +1 -1
  403. package/dist/icons/api.js +12 -12
  404. package/dist/icons/api.js.map +1 -1
  405. package/dist/icons/provider.d.ts +4 -3
  406. package/dist/icons/provider.d.ts.map +1 -1
  407. package/dist/icons/provider.js +6 -13
  408. package/dist/icons/provider.js.map +1 -1
  409. package/dist/icons/schema.d.ts +33 -1
  410. package/dist/icons/schema.d.ts.map +1 -1
  411. package/dist/icons/schema.js +30 -1
  412. package/dist/icons/schema.js.map +1 -1
  413. package/dist/icons/svg/presentation.d.ts +8 -1
  414. package/dist/icons/svg/presentation.d.ts.map +1 -1
  415. package/dist/icons/svg/presentation.js +21 -3
  416. package/dist/icons/svg/presentation.js.map +1 -1
  417. package/dist/icons/svg/text.js +1 -1
  418. package/dist/icons/svg/text.js.map +1 -1
  419. package/dist/icons/svg.d.ts +8 -3
  420. package/dist/icons/svg.d.ts.map +1 -1
  421. package/dist/icons/svg.js +15 -13
  422. package/dist/icons/svg.js.map +1 -1
  423. package/dist/icons/types.d.ts +1 -19
  424. package/dist/icons/types.d.ts.map +1 -1
  425. package/dist/index.d.ts +2 -2
  426. package/dist/index.js +1 -1
  427. package/dist/io/formats/design-tokens/css/read.js +1 -1
  428. package/dist/io/formats/design-tokens/decode.js +1 -1
  429. package/dist/io/formats/design-tokens/plan/index.js +4 -2
  430. package/dist/io/formats/design-tokens/plan/index.js.map +1 -1
  431. package/dist/io/formats/design-tokens/plan/styles.d.ts +9 -1
  432. package/dist/io/formats/design-tokens/plan/styles.d.ts.map +1 -1
  433. package/dist/io/formats/design-tokens/plan/styles.js +23 -3
  434. package/dist/io/formats/design-tokens/plan/styles.js.map +1 -1
  435. package/dist/io/formats/design-tokens/styles.d.ts +9 -1
  436. package/dist/io/formats/design-tokens/styles.d.ts.map +1 -1
  437. package/dist/io/formats/design-tokens/styles.js +41 -4
  438. package/dist/io/formats/design-tokens/styles.js.map +1 -1
  439. package/dist/io/formats/design-tokens/types.d.ts +5 -0
  440. package/dist/io/formats/design-tokens/types.d.ts.map +1 -1
  441. package/dist/io/formats/design-tokens/types.js +1 -0
  442. package/dist/io/formats/design-tokens/types.js.map +1 -1
  443. package/dist/io/formats/drawio/export.d.ts.map +1 -1
  444. package/dist/io/formats/drawio/export.js +10 -0
  445. package/dist/io/formats/drawio/export.js.map +1 -1
  446. package/dist/io/formats/drawio/index.d.ts.map +1 -1
  447. package/dist/io/formats/drawio/index.js +32 -1
  448. package/dist/io/formats/drawio/index.js.map +1 -1
  449. package/dist/io/formats/drawio/shapes.d.ts +10 -5
  450. package/dist/io/formats/drawio/shapes.d.ts.map +1 -1
  451. package/dist/io/formats/drawio/shapes.js +10 -6
  452. package/dist/io/formats/drawio/shapes.js.map +1 -1
  453. package/dist/io/formats/drawio/warnings.d.ts +11 -0
  454. package/dist/io/formats/drawio/warnings.d.ts.map +1 -0
  455. package/dist/io/formats/drawio/warnings.js +23 -0
  456. package/dist/io/formats/drawio/warnings.js.map +1 -0
  457. package/dist/io/formats/fig/export/setup.d.ts.map +1 -1
  458. package/dist/io/formats/fig/export/setup.js +8 -4
  459. package/dist/io/formats/fig/export/setup.js.map +1 -1
  460. package/dist/io/formats/fig/export/variables.d.ts.map +1 -1
  461. package/dist/io/formats/fig/export/variables.js +2 -2
  462. package/dist/io/formats/fig/export/variables.js.map +1 -1
  463. package/dist/io/formats/fig/index.d.ts +2 -2
  464. package/dist/io/formats/fig/index.js +2 -2
  465. package/dist/io/formats/fig/read.d.ts +9 -2
  466. package/dist/io/formats/fig/read.d.ts.map +1 -1
  467. package/dist/io/formats/fig/read.js +44 -20
  468. package/dist/io/formats/fig/read.js.map +1 -1
  469. package/dist/io/formats/html/index.d.ts.map +1 -1
  470. package/dist/io/formats/html/index.js +2 -6
  471. package/dist/io/formats/html/index.js.map +1 -1
  472. package/dist/io/formats/pdf/dom.d.ts +10 -1
  473. package/dist/io/formats/pdf/dom.d.ts.map +1 -1
  474. package/dist/io/formats/pdf/dom.js +96 -2
  475. package/dist/io/formats/pdf/dom.js.map +1 -1
  476. package/dist/io/formats/pdf/export.js +3 -2
  477. package/dist/io/formats/pdf/export.js.map +1 -1
  478. package/dist/io/formats/pdf/prepare.js +1 -1
  479. package/dist/io/formats/pen/fonts.d.ts +14 -0
  480. package/dist/io/formats/pen/fonts.d.ts.map +1 -0
  481. package/dist/io/formats/pen/fonts.js +39 -0
  482. package/dist/io/formats/pen/fonts.js.map +1 -0
  483. package/dist/io/formats/pen/index.d.ts.map +1 -1
  484. package/dist/io/formats/pen/index.js +25 -6
  485. package/dist/io/formats/pen/index.js.map +1 -1
  486. package/dist/io/formats/raster/headless.d.ts +3 -3
  487. package/dist/io/formats/raster/headless.d.ts.map +1 -1
  488. package/dist/io/formats/raster/headless.js +25 -14
  489. package/dist/io/formats/raster/headless.js.map +1 -1
  490. package/dist/io/formats/raster/index.d.ts +2 -2
  491. package/dist/io/formats/raster/index.js +2 -2
  492. package/dist/io/formats/raster/render.d.ts +8 -2
  493. package/dist/io/formats/raster/render.d.ts.map +1 -1
  494. package/dist/io/formats/raster/render.js +42 -8
  495. package/dist/io/formats/raster/render.js.map +1 -1
  496. package/dist/io/formats/svg/export.d.ts.map +1 -1
  497. package/dist/io/formats/svg/export.js +28 -24
  498. package/dist/io/formats/svg/export.js.map +1 -1
  499. package/dist/io/formats/svg/paths.d.ts +8 -2
  500. package/dist/io/formats/svg/paths.d.ts.map +1 -1
  501. package/dist/io/formats/svg/paths.js +11 -3
  502. package/dist/io/formats/svg/paths.js.map +1 -1
  503. package/dist/io/formats/svg/strokes.d.ts.map +1 -1
  504. package/dist/io/formats/svg/strokes.js +2 -5
  505. package/dist/io/formats/svg/strokes.js.map +1 -1
  506. package/dist/io/formats/svg/text/export.d.ts.map +1 -1
  507. package/dist/io/formats/svg/text/export.js +19 -1
  508. package/dist/io/formats/svg/text/export.js.map +1 -1
  509. package/dist/io/formats/svg/text/import.d.ts.map +1 -1
  510. package/dist/io/formats/svg/text/import.js +2 -1
  511. package/dist/io/formats/svg/text/import.js.map +1 -1
  512. package/dist/io/formats.d.ts.map +1 -1
  513. package/dist/io/formats.js +3 -1
  514. package/dist/io/formats.js.map +1 -1
  515. package/dist/io/registry.d.ts +2 -0
  516. package/dist/io/registry.d.ts.map +1 -1
  517. package/dist/io/registry.js +5 -0
  518. package/dist/io/registry.js.map +1 -1
  519. package/dist/io/subgraph.d.ts.map +1 -1
  520. package/dist/io/subgraph.js +5 -2
  521. package/dist/io/subgraph.js.map +1 -1
  522. package/dist/io/types.d.ts +2 -0
  523. package/dist/io/types.d.ts.map +1 -1
  524. package/dist/kiwi/fig/population/client.d.ts.map +1 -1
  525. package/dist/kiwi/fig/population/client.js +63 -45
  526. package/dist/kiwi/fig/population/client.js.map +1 -1
  527. package/dist/kiwi/fig/population/delta.d.ts +34 -3
  528. package/dist/kiwi/fig/population/delta.d.ts.map +1 -1
  529. package/dist/kiwi/fig/population/delta.js +99 -16
  530. package/dist/kiwi/fig/population/delta.js.map +1 -1
  531. package/dist/kiwi/fig/population/edits.d.ts +51 -0
  532. package/dist/kiwi/fig/population/edits.d.ts.map +1 -0
  533. package/dist/kiwi/fig/population/edits.js +169 -0
  534. package/dist/kiwi/fig/population/edits.js.map +1 -0
  535. package/dist/kiwi/fig/session/archive/access.d.ts +3 -0
  536. package/dist/kiwi/fig/session/archive/access.d.ts.map +1 -1
  537. package/dist/kiwi/fig/session/archive/access.js +8 -1
  538. package/dist/kiwi/fig/session/archive/access.js.map +1 -1
  539. package/dist/kiwi/fig/session/archive/changes.d.ts +2 -1
  540. package/dist/kiwi/fig/session/archive/changes.d.ts.map +1 -1
  541. package/dist/kiwi/fig/session/archive/changes.js +12 -5
  542. package/dist/kiwi/fig/session/archive/changes.js.map +1 -1
  543. package/dist/kiwi/fig/session/document-state.d.ts +7 -1
  544. package/dist/kiwi/fig/session/document-state.d.ts.map +1 -1
  545. package/dist/kiwi/fig/session/document-state.js +16 -2
  546. package/dist/kiwi/fig/session/document-state.js.map +1 -1
  547. package/dist/kiwi/fig/session/protocol.d.ts +31 -3
  548. package/dist/kiwi/fig/session/protocol.d.ts.map +1 -1
  549. package/dist/kiwi/fig/session/worker.js +33 -8
  550. package/dist/kiwi/fig/session/worker.js.map +1 -1
  551. package/dist/layout/apply.d.ts +6 -1
  552. package/dist/layout/apply.d.ts.map +1 -1
  553. package/dist/layout/apply.js +39 -14
  554. package/dist/layout/apply.js.map +1 -1
  555. package/dist/layout/arrange/boxes.d.ts.map +1 -1
  556. package/dist/layout/arrange/boxes.js +31 -0
  557. package/dist/layout/arrange/boxes.js.map +1 -1
  558. package/dist/layout/flow-edges.d.ts +26 -0
  559. package/dist/layout/flow-edges.d.ts.map +1 -0
  560. package/dist/layout/flow-edges.js +105 -0
  561. package/dist/layout/flow-edges.js.map +1 -0
  562. package/dist/layout/grid.d.ts.map +1 -1
  563. package/dist/layout/grid.js +9 -5
  564. package/dist/layout/grid.js.map +1 -1
  565. package/dist/layout/text-auto-resize.d.ts.map +1 -1
  566. package/dist/layout/text-auto-resize.js +9 -4
  567. package/dist/layout/text-auto-resize.js.map +1 -1
  568. package/dist/layout/text-measurement.d.ts +15 -1
  569. package/dist/layout/text-measurement.d.ts.map +1 -1
  570. package/dist/layout/text-measurement.js +40 -4
  571. package/dist/layout/text-measurement.js.map +1 -1
  572. package/dist/layout/variables.d.ts +1 -1
  573. package/dist/layout.d.ts.map +1 -1
  574. package/dist/layout.js +35 -35
  575. package/dist/layout.js.map +1 -1
  576. package/dist/library/asset-keys.d.ts +3 -2
  577. package/dist/library/asset-keys.d.ts.map +1 -1
  578. package/dist/library/asset-keys.js +4 -3
  579. package/dist/library/asset-keys.js.map +1 -1
  580. package/dist/library/copied-references.d.ts +8 -3
  581. package/dist/library/copied-references.d.ts.map +1 -1
  582. package/dist/library/copied-references.js +15 -5
  583. package/dist/library/copied-references.js.map +1 -1
  584. package/dist/library/materialize.js +1 -1
  585. package/dist/library/materialize.js.map +1 -1
  586. package/dist/library/schema.js.map +1 -1
  587. package/dist/library/snapshot.d.ts.map +1 -1
  588. package/dist/library/snapshot.js +11 -2
  589. package/dist/library/snapshot.js.map +1 -1
  590. package/dist/lint/linter.d.ts.map +1 -1
  591. package/dist/lint/linter.js +11 -2
  592. package/dist/lint/linter.js.map +1 -1
  593. package/dist/pairdraw-api/variables.d.ts.map +1 -1
  594. package/dist/pairdraw-api/variables.js +0 -2
  595. package/dist/pairdraw-api/variables.js.map +1 -1
  596. package/dist/profiler/hud-controller.d.ts +4 -3
  597. package/dist/profiler/hud-controller.d.ts.map +1 -1
  598. package/dist/profiler/hud-controller.js +7 -5
  599. package/dist/profiler/hud-controller.js.map +1 -1
  600. package/dist/profiler/hud-renderer.d.ts +5 -2
  601. package/dist/profiler/hud-renderer.d.ts.map +1 -1
  602. package/dist/profiler/hud-renderer.js +8 -5
  603. package/dist/profiler/hud-renderer.js.map +1 -1
  604. package/dist/profiler/render-profiler.d.ts +3 -2
  605. package/dist/profiler/render-profiler.d.ts.map +1 -1
  606. package/dist/profiler/render-profiler.js +3 -2
  607. package/dist/profiler/render-profiler.js.map +1 -1
  608. package/dist/rpc/variables-command.d.ts.map +1 -1
  609. package/dist/rpc/variables-command.js +4 -2
  610. package/dist/rpc/variables-command.js.map +1 -1
  611. package/dist/text/character-style.d.ts +11 -1
  612. package/dist/text/character-style.d.ts.map +1 -1
  613. package/dist/text/character-style.js +27 -5
  614. package/dist/text/character-style.js.map +1 -1
  615. package/dist/text/coverage.d.ts.map +1 -1
  616. package/dist/text/coverage.js +16 -14
  617. package/dist/text/coverage.js.map +1 -1
  618. package/dist/text/editor.d.ts.map +1 -1
  619. package/dist/text/editor.js +3 -8
  620. package/dist/text/editor.js.map +1 -1
  621. package/dist/text/fallbacks.d.ts +26 -3
  622. package/dist/text/fallbacks.d.ts.map +1 -1
  623. package/dist/text/fallbacks.js +135 -18
  624. package/dist/text/fallbacks.js.map +1 -1
  625. package/dist/text/font/catalog.d.ts +4 -0
  626. package/dist/text/font/catalog.d.ts.map +1 -1
  627. package/dist/text/font/catalog.js +8 -0
  628. package/dist/text/font/catalog.js.map +1 -1
  629. package/dist/text/font/collection.d.ts +13 -0
  630. package/dist/text/font/collection.d.ts.map +1 -0
  631. package/dist/text/font/collection.js +51 -0
  632. package/dist/text/font/collection.js.map +1 -0
  633. package/dist/text/font/faces.d.ts +2 -1
  634. package/dist/text/font/faces.d.ts.map +1 -1
  635. package/dist/text/font/faces.js +9 -5
  636. package/dist/text/font/faces.js.map +1 -1
  637. package/dist/text/font/glyphs.d.ts +14 -3
  638. package/dist/text/font/glyphs.d.ts.map +1 -1
  639. package/dist/text/font/glyphs.js +22 -5
  640. package/dist/text/font/glyphs.js.map +1 -1
  641. package/dist/text/font/local.js +2 -2
  642. package/dist/text/font/local.js.map +1 -1
  643. package/dist/text/font/manager.d.ts +50 -6
  644. package/dist/text/font/manager.d.ts.map +1 -1
  645. package/dist/text/font/manager.js +178 -32
  646. package/dist/text/font/manager.js.map +1 -1
  647. package/dist/text/font/style.d.ts +7 -2
  648. package/dist/text/font/style.d.ts.map +1 -1
  649. package/dist/text/font/style.js +31 -3
  650. package/dist/text/font/style.js.map +1 -1
  651. package/dist/text/index.d.ts +5 -4
  652. package/dist/text/index.js +5 -4
  653. package/dist/text/outlines.d.ts.map +1 -1
  654. package/dist/text/outlines.js +71 -71
  655. package/dist/text/outlines.js.map +1 -1
  656. package/dist/text/path/caret.d.ts +2 -4
  657. package/dist/text/path/caret.d.ts.map +1 -1
  658. package/dist/text/path/caret.js.map +1 -1
  659. package/dist/text/prepare.d.ts +5 -1
  660. package/dist/text/prepare.d.ts.map +1 -1
  661. package/dist/text/prepare.js +26 -3
  662. package/dist/text/prepare.js.map +1 -1
  663. package/dist/text/style-runs.d.ts +14 -2
  664. package/dist/text/style-runs.d.ts.map +1 -1
  665. package/dist/text/style-runs.js +22 -14
  666. package/dist/text/style-runs.js.map +1 -1
  667. package/dist/text/web-font/assets.d.ts.map +1 -1
  668. package/dist/text/web-font/assets.js +13 -21
  669. package/dist/text/web-font/assets.js.map +1 -1
  670. package/dist/text/web-font/resolver.d.ts.map +1 -1
  671. package/dist/text/web-font/resolver.js +4 -1
  672. package/dist/text/web-font/resolver.js.map +1 -1
  673. package/dist/tools/analyze/overlaps/helpers.d.ts.map +1 -1
  674. package/dist/tools/analyze/overlaps/helpers.js +9 -1
  675. package/dist/tools/analyze/overlaps/helpers.js.map +1 -1
  676. package/dist/tools/analyze/overlaps/index.d.ts.map +1 -1
  677. package/dist/tools/analyze/overlaps/index.js +27 -5
  678. package/dist/tools/analyze/overlaps/index.js.map +1 -1
  679. package/dist/tools/codegen/component-map.js +3 -3
  680. package/dist/tools/codegen/component-map.js.map +1 -1
  681. package/dist/tools/create/basic.d.ts.map +1 -1
  682. package/dist/tools/create/basic.js +5 -4
  683. package/dist/tools/create/basic.js.map +1 -1
  684. package/dist/tools/create/components.d.ts +2 -1
  685. package/dist/tools/create/components.d.ts.map +1 -1
  686. package/dist/tools/create/components.js +27 -1
  687. package/dist/tools/create/components.js.map +1 -1
  688. package/dist/tools/create/html.d.ts.map +1 -1
  689. package/dist/tools/create/html.js +4 -2
  690. package/dist/tools/create/html.js.map +1 -1
  691. package/dist/tools/create/icons.d.ts.map +1 -1
  692. package/dist/tools/create/icons.js +14 -6
  693. package/dist/tools/create/icons.js.map +1 -1
  694. package/dist/tools/create/mermaid.d.ts.map +1 -1
  695. package/dist/tools/create/mermaid.js +2 -0
  696. package/dist/tools/create/mermaid.js.map +1 -1
  697. package/dist/tools/create/render.d.ts.map +1 -1
  698. package/dist/tools/create/render.js +2 -0
  699. package/dist/tools/create/render.js.map +1 -1
  700. package/dist/tools/create/script.js +3 -1
  701. package/dist/tools/create/script.js.map +1 -1
  702. package/dist/tools/create/svg.d.ts.map +1 -1
  703. package/dist/tools/create/svg.js +4 -1
  704. package/dist/tools/create/svg.js.map +1 -1
  705. package/dist/tools/create/vector.d.ts.map +1 -1
  706. package/dist/tools/create/vector.js +13 -10
  707. package/dist/tools/create/vector.js.map +1 -1
  708. package/dist/tools/create.d.ts +2 -2
  709. package/dist/tools/create.js +2 -2
  710. package/dist/tools/image-ai/apply.js +1 -1
  711. package/dist/tools/image-ai/generate.d.ts.map +1 -1
  712. package/dist/tools/image-ai/generate.js +3 -0
  713. package/dist/tools/image-ai/generate.js.map +1 -1
  714. package/dist/tools/modify/effects.d.ts.map +1 -1
  715. package/dist/tools/modify/effects.js +5 -3
  716. package/dist/tools/modify/effects.js.map +1 -1
  717. package/dist/tools/modify/matching.d.ts.map +1 -1
  718. package/dist/tools/modify/matching.js +9 -6
  719. package/dist/tools/modify/matching.js.map +1 -1
  720. package/dist/tools/modify/paint.d.ts.map +1 -1
  721. package/dist/tools/modify/paint.js +7 -5
  722. package/dist/tools/modify/paint.js.map +1 -1
  723. package/dist/tools/modify/reactions.d.ts +6 -0
  724. package/dist/tools/modify/reactions.d.ts.map +1 -0
  725. package/dist/tools/modify/reactions.js +35 -0
  726. package/dist/tools/modify/reactions.js.map +1 -0
  727. package/dist/tools/modify/text.d.ts.map +1 -1
  728. package/dist/tools/modify/text.js +28 -8
  729. package/dist/tools/modify/text.js.map +1 -1
  730. package/dist/tools/modify.d.ts +2 -1
  731. package/dist/tools/modify.js +2 -1
  732. package/dist/tools/read/components.js +20 -22
  733. package/dist/tools/read/components.js.map +1 -1
  734. package/dist/tools/read/fonts.js +1 -1
  735. package/dist/tools/read/fonts.js.map +1 -1
  736. package/dist/tools/read/libraries.d.ts.map +1 -1
  737. package/dist/tools/read/libraries.js +18 -4
  738. package/dist/tools/read/libraries.js.map +1 -1
  739. package/dist/tools/read/nodes.d.ts.map +1 -1
  740. package/dist/tools/read/nodes.js +38 -16
  741. package/dist/tools/read/nodes.js.map +1 -1
  742. package/dist/tools/read/pages.d.ts.map +1 -1
  743. package/dist/tools/read/pages.js +4 -3
  744. package/dist/tools/read/pages.js.map +1 -1
  745. package/dist/tools/read/query.js +1 -0
  746. package/dist/tools/read/query.js.map +1 -1
  747. package/dist/tools/read/reactions.d.ts +6 -0
  748. package/dist/tools/read/reactions.d.ts.map +1 -0
  749. package/dist/tools/read/reactions.js +24 -0
  750. package/dist/tools/read/reactions.js.map +1 -0
  751. package/dist/tools/read/space.js +1 -1
  752. package/dist/tools/read.d.ts +2 -1
  753. package/dist/tools/read.js +2 -1
  754. package/dist/tools/registry/extended.d.ts.map +1 -1
  755. package/dist/tools/registry/extended.js +6 -1
  756. package/dist/tools/registry/extended.js.map +1 -1
  757. package/dist/tools/schema.d.ts +30 -5
  758. package/dist/tools/schema.d.ts.map +1 -1
  759. package/dist/tools/schema.js +125 -7
  760. package/dist/tools/schema.js.map +1 -1
  761. package/dist/tools/stock-photo/apply.js +8 -9
  762. package/dist/tools/stock-photo/apply.js.map +1 -1
  763. package/dist/tools/structure/batch.d.ts.map +1 -1
  764. package/dist/tools/structure/batch.js +86 -90
  765. package/dist/tools/structure/batch.js.map +1 -1
  766. package/dist/tools/variables/values.d.ts.map +1 -1
  767. package/dist/tools/variables/values.js +4 -2
  768. package/dist/tools/variables/values.js.map +1 -1
  769. package/dist/tools/vector/export.d.ts.map +1 -1
  770. package/dist/tools/vector/export.js +5 -2
  771. package/dist/tools/vector/export.js.map +1 -1
  772. package/dist/vector/fill-geometry.d.ts +4 -1
  773. package/dist/vector/fill-geometry.d.ts.map +1 -1
  774. package/dist/vector/fill-geometry.js +8 -5
  775. package/dist/vector/fill-geometry.js.map +1 -1
  776. package/dist/vector/index.js +1 -1
  777. package/dist/vector/index.js.map +1 -1
  778. package/dist/vector/path-helpers.d.ts +1 -1
  779. package/dist/vector/path-helpers.d.ts.map +1 -1
  780. package/dist/vector/path-helpers.js +24 -7
  781. package/dist/vector/path-helpers.js.map +1 -1
  782. package/dist/vector/placement.js +1 -1
  783. package/dist/vector/placement.js.map +1 -1
  784. package/dist/vector/vectorize/preprocess.js +1 -1
  785. package/dist/vector/vectorize/preprocess.js.map +1 -1
  786. package/package.json +10 -10
  787. package/src/canvas/effects.ts +29 -33
  788. package/src/canvas/labels/hit-test.ts +6 -2
  789. package/src/canvas/labels/paragraph-cache.ts +2 -1
  790. package/src/canvas/labels/selection.ts +3 -3
  791. package/src/canvas/node-edit-overlay.ts +3 -2
  792. package/src/canvas/outline-stroke.ts +2 -6
  793. package/src/canvas/overlays/index.ts +0 -1
  794. package/src/canvas/overlays/prototype.ts +5 -27
  795. package/src/canvas/overlays/selection.ts +4 -52
  796. package/src/canvas/region-hatch.ts +7 -2
  797. package/src/canvas/renderer/colors.ts +41 -26
  798. package/src/canvas/renderer/font-waiters.ts +25 -0
  799. package/src/canvas/renderer/fonts.ts +42 -18
  800. package/src/canvas/renderer/lifecycle.ts +8 -10
  801. package/src/canvas/renderer/methods.ts +9 -13
  802. package/src/canvas/renderer/paints.ts +0 -10
  803. package/src/canvas/renderer/pipeline.ts +29 -3
  804. package/src/canvas/renderer/retained-backing.ts +4 -4
  805. package/src/canvas/renderer/state.ts +1 -1
  806. package/src/canvas/renderer/tiles/controller.ts +8 -0
  807. package/src/canvas/renderer/tiles/surface-pool.ts +1 -1
  808. package/src/canvas/renderer/visual-bounds.ts +7 -6
  809. package/src/canvas/renderer.ts +43 -11
  810. package/src/canvas/rulers.ts +55 -26
  811. package/src/canvas/scene.ts +127 -77
  812. package/src/canvas/shadows/shape.ts +1 -1
  813. package/src/canvas/shadows/silhouette.ts +4 -2
  814. package/src/canvas/shadows.ts +4 -2
  815. package/src/canvas/text/derived.ts +0 -9
  816. package/src/canvas/text/emoji/raster.ts +14 -10
  817. package/src/canvas/text/font-families.ts +14 -7
  818. package/src/canvas/text/index.ts +3 -9
  819. package/src/canvas/text/layout/build.ts +35 -18
  820. package/src/canvas/text/layout/index.ts +15 -6
  821. package/src/canvas/text/layout/lines.ts +10 -4
  822. package/src/canvas/text/paragraph/index.ts +19 -10
  823. package/src/canvas/text/paragraph/inputs.ts +4 -2
  824. package/src/canvas/text/placed.ts +2 -2
  825. package/src/canvas/text/renderer.ts +2 -0
  826. package/src/canvas/text/shape.ts +20 -31
  827. package/src/constants.ts +6 -1
  828. package/src/editor/bridges/clipboard.ts +1 -0
  829. package/src/editor/bridges/components.ts +2 -0
  830. package/src/editor/bridges/frames.ts +6 -4
  831. package/src/editor/bridges/structure.ts +1 -0
  832. package/src/editor/clipboard/detach.ts +3 -3
  833. package/src/editor/clipboard/paste/target.ts +2 -2
  834. package/src/editor/clipboard/snapshot.ts +7 -0
  835. package/src/editor/clipboard/variables.ts +20 -0
  836. package/src/editor/clipboard.ts +133 -14
  837. package/src/editor/component-sync.ts +28 -7
  838. package/src/editor/components/authoring/text-edit.ts +15 -2
  839. package/src/editor/components/authoring/visibility-edit.ts +11 -3
  840. package/src/editor/components/instances.ts +61 -11
  841. package/src/editor/components/properties.ts +10 -0
  842. package/src/editor/components/slots/authoring.ts +4 -1
  843. package/src/editor/create.ts +58 -8
  844. package/src/editor/guides.ts +27 -12
  845. package/src/editor/history/document-change.ts +115 -7
  846. package/src/editor/history/edit.ts +62 -14
  847. package/src/editor/history/position.ts +1 -4
  848. package/src/editor/history/sources.ts +25 -0
  849. package/src/editor/index.ts +3 -1
  850. package/src/editor/layout-mode.ts +20 -1
  851. package/src/editor/node-preview.ts +44 -8
  852. package/src/editor/nodes.ts +52 -12
  853. package/src/editor/nudge.ts +16 -2
  854. package/src/editor/pages.ts +100 -17
  855. package/src/editor/play/states.ts +0 -7
  856. package/src/editor/read-only/actions.ts +4 -0
  857. package/src/editor/selection/hit-test.ts +37 -4
  858. package/src/editor/shapes/pen.ts +6 -3
  859. package/src/editor/shapes.ts +2 -1
  860. package/src/editor/structure/auto-layout-wrap.ts +26 -0
  861. package/src/editor/structure/group/bounds.ts +22 -4
  862. package/src/editor/structure/rename.ts +2 -6
  863. package/src/editor/structure/reorder.ts +26 -8
  864. package/src/editor/structure.ts +88 -24
  865. package/src/editor/text/hyperlink.ts +2 -1
  866. package/src/editor/text/name.ts +51 -15
  867. package/src/editor/text/pending-layout.ts +42 -4
  868. package/src/editor/text/selection-style.ts +17 -3
  869. package/src/editor/text.ts +86 -4
  870. package/src/editor/types.ts +19 -0
  871. package/src/editor/undo.ts +21 -2
  872. package/src/editor/variable-bindings.ts +22 -2
  873. package/src/editor/variables.ts +10 -6
  874. package/src/editor/viewport.ts +55 -21
  875. package/src/editor/views/actions.ts +17 -7
  876. package/src/editor/views/present.ts +20 -11
  877. package/src/editor/views/types.ts +11 -5
  878. package/src/figma-api/accessor-utils.ts +4 -1
  879. package/src/figma-api/accessors/basic.ts +54 -18
  880. package/src/figma-api/accessors/layout.ts +46 -7
  881. package/src/figma-api/accessors/reactions.ts +29 -0
  882. package/src/figma-api/accessors/strokes.ts +28 -8
  883. package/src/figma-api/accessors/text/index.ts +4 -0
  884. package/src/figma-api/accessors/vector.ts +3 -1
  885. package/src/figma-api/accessors/visual.ts +25 -28
  886. package/src/figma-api/components.ts +9 -7
  887. package/src/figma-api/finite.ts +102 -0
  888. package/src/figma-api/fonts/list.ts +24 -0
  889. package/src/figma-api/index.ts +170 -19
  890. package/src/figma-api/overrides.ts +1 -1
  891. package/src/figma-api/pending-layout.ts +50 -1
  892. package/src/figma-api/pending-sync.ts +61 -0
  893. package/src/figma-api/proxy.ts +35 -2
  894. package/src/figma-api/reactions.ts +212 -0
  895. package/src/figma-api/render-bounds.ts +13 -4
  896. package/src/figma-api/serialization.ts +16 -2
  897. package/src/figma-api/slots.ts +12 -3
  898. package/src/figma-api/strokes.ts +16 -12
  899. package/src/figma-api/text/index.ts +9 -15
  900. package/src/figma-api/variables/variable.ts +3 -2
  901. package/src/geometry/connectors.ts +2 -12
  902. package/src/geometry/figma.ts +9 -0
  903. package/src/geometry/index.ts +2 -1
  904. package/src/geometry/scene.ts +19 -0
  905. package/src/geometry/types.ts +8 -0
  906. package/src/global.d.ts +6 -0
  907. package/src/icons/api.ts +27 -16
  908. package/src/icons/provider.ts +9 -20
  909. package/src/icons/schema.ts +31 -0
  910. package/src/icons/svg/presentation.ts +27 -3
  911. package/src/icons/svg/text.ts +1 -1
  912. package/src/icons/svg.ts +21 -19
  913. package/src/icons/types.ts +0 -14
  914. package/src/io/formats/design-tokens/plan/index.ts +7 -1
  915. package/src/io/formats/design-tokens/plan/styles.ts +40 -4
  916. package/src/io/formats/design-tokens/styles.ts +60 -3
  917. package/src/io/formats/design-tokens/types.ts +3 -0
  918. package/src/io/formats/drawio/export.ts +11 -0
  919. package/src/io/formats/drawio/index.ts +36 -1
  920. package/src/io/formats/drawio/shapes.ts +13 -9
  921. package/src/io/formats/drawio/warnings.ts +27 -0
  922. package/src/io/formats/fig/export/setup.ts +16 -14
  923. package/src/io/formats/fig/export/variables.ts +7 -8
  924. package/src/io/formats/fig/index.ts +1 -0
  925. package/src/io/formats/fig/read.ts +66 -23
  926. package/src/io/formats/html/index.ts +2 -6
  927. package/src/io/formats/pdf/dom.ts +125 -3
  928. package/src/io/formats/pdf/export.ts +3 -2
  929. package/src/io/formats/pen/fonts.ts +45 -0
  930. package/src/io/formats/pen/index.ts +30 -6
  931. package/src/io/formats/raster/headless.ts +40 -14
  932. package/src/io/formats/raster/index.ts +3 -0
  933. package/src/io/formats/raster/render.ts +66 -8
  934. package/src/io/formats/svg/export.ts +24 -25
  935. package/src/io/formats/svg/paths.ts +11 -2
  936. package/src/io/formats/svg/strokes.ts +8 -2
  937. package/src/io/formats/svg/text/export.ts +23 -0
  938. package/src/io/formats/svg/text/import.ts +2 -1
  939. package/src/io/formats.ts +3 -1
  940. package/src/io/registry.ts +12 -0
  941. package/src/io/subgraph.ts +3 -1
  942. package/src/io/types.ts +2 -0
  943. package/src/kiwi/fig/population/client.ts +77 -43
  944. package/src/kiwi/fig/population/delta.ts +141 -18
  945. package/src/kiwi/fig/population/edits.ts +235 -0
  946. package/src/kiwi/fig/session/archive/access.ts +15 -0
  947. package/src/kiwi/fig/session/archive/changes.ts +27 -6
  948. package/src/kiwi/fig/session/document-state.ts +23 -1
  949. package/src/kiwi/fig/session/protocol.ts +26 -1
  950. package/src/kiwi/fig/session/worker.ts +38 -11
  951. package/src/layout/apply.ts +52 -10
  952. package/src/layout/arrange/boxes.ts +36 -0
  953. package/src/layout/flow-edges.ts +139 -0
  954. package/src/layout/grid.ts +14 -4
  955. package/src/layout/text-auto-resize.ts +13 -4
  956. package/src/layout/text-measurement.ts +46 -3
  957. package/src/layout.ts +60 -66
  958. package/src/library/asset-keys.ts +4 -3
  959. package/src/library/copied-references.ts +29 -5
  960. package/src/library/materialize.ts +1 -1
  961. package/src/library/schema.ts +1 -1
  962. package/src/library/snapshot.ts +12 -2
  963. package/src/lint/linter.ts +12 -2
  964. package/src/pairdraw-api/variables.ts +1 -3
  965. package/src/profiler/hud-controller.ts +8 -6
  966. package/src/profiler/hud-renderer.ts +9 -6
  967. package/src/profiler/render-profiler.ts +4 -3
  968. package/src/rpc/variables-command.ts +6 -5
  969. package/src/text/character-style.ts +29 -9
  970. package/src/text/coverage.ts +29 -15
  971. package/src/text/editor.ts +3 -8
  972. package/src/text/fallbacks.ts +163 -22
  973. package/src/text/font/catalog.ts +10 -0
  974. package/src/text/font/collection.ts +60 -0
  975. package/src/text/font/faces.ts +9 -5
  976. package/src/text/font/glyphs.ts +29 -4
  977. package/src/text/font/local.ts +2 -2
  978. package/src/text/font/manager.ts +220 -49
  979. package/src/text/font/style.ts +52 -3
  980. package/src/text/index.ts +1 -0
  981. package/src/text/outlines.ts +106 -90
  982. package/src/text/path/caret.ts +3 -4
  983. package/src/text/prepare.ts +51 -2
  984. package/src/text/style-runs.ts +43 -16
  985. package/src/text/web-font/assets.ts +11 -15
  986. package/src/text/web-font/resolver.ts +7 -1
  987. package/src/tools/analyze/overlaps/helpers.ts +18 -1
  988. package/src/tools/analyze/overlaps/index.ts +37 -6
  989. package/src/tools/codegen/component-map.ts +3 -3
  990. package/src/tools/create/basic.ts +6 -4
  991. package/src/tools/create/components.ts +33 -0
  992. package/src/tools/create/html.ts +3 -1
  993. package/src/tools/create/icons.ts +16 -6
  994. package/src/tools/create/mermaid.ts +2 -0
  995. package/src/tools/create/render.ts +2 -0
  996. package/src/tools/create/script.ts +5 -1
  997. package/src/tools/create/svg.ts +4 -1
  998. package/src/tools/create/vector.ts +20 -10
  999. package/src/tools/create.ts +1 -0
  1000. package/src/tools/image-ai/generate.ts +3 -0
  1001. package/src/tools/modify/effects.ts +11 -4
  1002. package/src/tools/modify/matching.ts +10 -6
  1003. package/src/tools/modify/paint.ts +13 -5
  1004. package/src/tools/modify/reactions.ts +40 -0
  1005. package/src/tools/modify/text.ts +53 -20
  1006. package/src/tools/modify.ts +1 -0
  1007. package/src/tools/read/components.ts +28 -25
  1008. package/src/tools/read/fonts.ts +1 -1
  1009. package/src/tools/read/libraries.ts +24 -4
  1010. package/src/tools/read/nodes.ts +47 -17
  1011. package/src/tools/read/pages.ts +7 -3
  1012. package/src/tools/read/query.ts +2 -0
  1013. package/src/tools/read/reactions.ts +21 -0
  1014. package/src/tools/read.ts +1 -0
  1015. package/src/tools/registry/extended.ts +6 -0
  1016. package/src/tools/schema.ts +166 -6
  1017. package/src/tools/stock-photo/apply.ts +17 -5
  1018. package/src/tools/structure/batch.ts +84 -98
  1019. package/src/tools/variables/values.ts +6 -3
  1020. package/src/tools/vector/export.ts +5 -1
  1021. package/src/vector/fill-geometry.ts +11 -5
  1022. package/src/vector/index.ts +1 -1
  1023. package/src/vector/path-helpers.ts +34 -8
  1024. package/src/vector/placement.ts +1 -1
  1025. package/src/vector/vectorize/preprocess.ts +1 -1
@@ -3,8 +3,30 @@ import { pathName, placeTokens, tokenPath, tokenReference } from "./paths.js";
3
3
  import { toFigmaEffect } from "../../../figma-api/effects.js";
4
4
  import { colorTokenValue, dimensionTokenValue, trimNumber } from "./values.js";
5
5
  import { lineHeightPixels, textLengthPixels } from "@pairdraw/scene-graph/text";
6
+ import { countBy } from "es-toolkit/array";
6
7
  import { isEmptyObject, isPlainObject } from "es-toolkit/predicate";
7
8
  //#region src/io/formats/design-tokens/styles.ts
9
+ /** The variables a style's bound fields point at, by field, for those a reference was written for. */
10
+ function bindingTargets(graph, node, fields) {
11
+ const targets = {};
12
+ for (const field of fields) {
13
+ const variable = graph.variables.get(node.boundVariables[field] ?? "");
14
+ const collection = variable && graph.variableCollections.get(variable.collectionId);
15
+ if (variable && collection) targets[field] = {
16
+ targetVariableSetName: collection.name,
17
+ targetVariableName: variable.name
18
+ };
19
+ }
20
+ return targets;
21
+ }
22
+ /** The fields a style binds and how a file read back finds each: its reference and its target. */
23
+ function ownBindings(graph, node, bindings) {
24
+ const own = {};
25
+ if (isEmptyObject(bindings)) return own;
26
+ own.bindings = bindings;
27
+ own.aliasData = bindingTargets(graph, node, Object.keys(bindings));
28
+ return own;
29
+ }
8
30
  /** Figma's auto line height, written as the multiplier browsers use for `normal`. */
9
31
  const AUTO_LINE_HEIGHT = 1.2;
10
32
  const TEXT_BINDING_FIELDS = [
@@ -34,7 +56,7 @@ function typographyValue(text, bound) {
34
56
  };
35
57
  }
36
58
  /** A text style as a typography token; its own fields ride along so Pairdraw reads it back exactly. */
37
- function typographyToken(node, references) {
59
+ function typographyToken(graph, node, references) {
38
60
  const bound = bindingReferences(node, references);
39
61
  return {
40
62
  $type: "typography",
@@ -50,7 +72,7 @@ function typographyToken(node, references) {
50
72
  textDecoration: node.textDecoration,
51
73
  textCase: node.textCase
52
74
  },
53
- ...isEmptyObject(bound) ? {} : { bindings: bound }
75
+ ...ownBindings(graph, node, bound)
54
76
  } }
55
77
  };
56
78
  }
@@ -87,11 +109,17 @@ function shadowToken(node) {
87
109
  ...node.effects.every((effect) => isShadow(effect) && effect.visible && (effect.blendMode ?? "NORMAL") === "NORMAL" && effect.showShadowBehindNode !== true) ? {} : { $extensions: { [PAIRDRAW_EXTENSION]: { effects: node.effects.filter((effect) => effect.type !== "SHADER").map(toFigmaEffect) } } }
88
110
  };
89
111
  }
112
+ /** Whether a style's token writes a reference for this bound field. */
113
+ function writesBinding(node, field) {
114
+ return node.sharedStyleType === "TEXT" && TEXT_BINDING_FIELDS.some((bound) => bound === field);
115
+ }
90
116
  /** Text and effect styles as typography and shadow tokens, nested by their names. */
91
117
  function styleTokens(graph, references) {
92
118
  const issues = [];
93
- const candidates = [...graph.getAllNodes()].filter((node) => (node.sharedStyleType === "TEXT" || node.sharedStyleType === "EFFECT") && node.source.id !== null).flatMap((node) => {
94
- const token = node.sharedStyleType === "TEXT" ? typographyToken(node, references) : shadowToken(node);
119
+ const styles = [...graph.getAllNodes()].filter((node) => (node.sharedStyleType === "TEXT" || node.sharedStyleType === "EFFECT") && node.source.id !== null);
120
+ const shared = new Set(Object.entries(countBy([...references.values()], (path) => tokenReference(path))).filter(([, count]) => count > 1).map(([reference]) => reference));
121
+ const candidates = styles.flatMap((node) => {
122
+ const token = node.sharedStyleType === "TEXT" ? typographyToken(graph, node, references) : shadowToken(node);
95
123
  if (!token) {
96
124
  issues.push({
97
125
  kind: "unsupported-effect",
@@ -113,6 +141,15 @@ function styleTokens(graph, references) {
113
141
  collection: "Styles",
114
142
  token: node.name
115
143
  });
144
+ for (const [{ node }] of placed) for (const [field, variableId] of Object.entries(node.boundVariables)) {
145
+ const path = writesBinding(node, field) ? references.get(variableId) : void 0;
146
+ if (path && shared.has(tokenReference(path))) issues.push({
147
+ kind: "ambiguous-reference",
148
+ style: node.name,
149
+ field,
150
+ token: pathName(path)
151
+ });
152
+ }
116
153
  return {
117
154
  tokens: [...placed].map(([{ node, token }, path]) => ({
118
155
  path,
@@ -1 +1 @@
1
- {"version":3,"file":"styles.js","names":[],"sources":["../../../../src/io/formats/design-tokens/styles.ts"],"sourcesContent":["import { isEmptyObject, isPlainObject } from 'es-toolkit/predicate'\n\nimport type { Effect, ShadowEffect, SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { lineHeightPixels, textLengthPixels } from '@pairdraw/scene-graph/text'\n\nimport { toFigmaEffect } from '#core/figma-api/effects'\n\nimport { pathName, placeTokens, tokenPath, tokenReference } from './paths'\nimport { PAIRDRAW_EXTENSION, type DesignToken, type DesignTokenIssue } from './types'\nimport { colorTokenValue, dimensionTokenValue, trimNumber } from './values'\n\n/** Where a variable's token sits, for references to it. */\nexport type TokenReferences = ReadonlyMap<string, readonly string[]>\n\n/** Figma's auto line height, written as the multiplier browsers use for `normal`. */\nconst AUTO_LINE_HEIGHT = 1.2\n\nconst TEXT_BINDING_FIELDS = ['fontFamily', 'fontSize', 'letterSpacing', 'lineHeight'] as const\n\nfunction bindingReferences(\n node: SceneNode,\n references: TokenReferences\n): Partial<Record<(typeof TEXT_BINDING_FIELDS)[number], string>> {\n const bound = TEXT_BINDING_FIELDS.flatMap((field) => {\n const variableId = node.boundVariables[field]\n const path = variableId ? references.get(variableId) : undefined\n return path ? [[field, tokenReference(path)] as const] : []\n })\n return Object.fromEntries(bound)\n}\n\nexport type TypographyFields = Pick<\n SceneNode,\n 'fontFamily' | 'fontSize' | 'fontWeight' | 'lineHeight' | 'letterSpacing'\n>\n\n/** A typography token's `$value`: bound fields as references to their variables' tokens. */\nexport function typographyValue(\n text: TypographyFields,\n bound: Partial<Record<(typeof TEXT_BINDING_FIELDS)[number], string>>\n) {\n // A typography token writes a line height as a multiple of the font size.\n const lineHeightPx = lineHeightPixels(text.lineHeight, text.fontSize)\n const lineHeight =\n lineHeightPx === null || text.fontSize <= 0\n ? AUTO_LINE_HEIGHT\n : trimNumber(lineHeightPx / text.fontSize)\n return {\n fontFamily: bound.fontFamily ?? text.fontFamily,\n fontSize: bound.fontSize ?? dimensionTokenValue(text.fontSize),\n fontWeight: text.fontWeight,\n lineHeight,\n letterSpacing:\n bound.letterSpacing ??\n dimensionTokenValue(textLengthPixels(text.letterSpacing, text.fontSize))\n }\n}\n\n/** A text style as a typography token; its own fields ride along so Pairdraw reads it back exactly. */\nfunction typographyToken(node: SceneNode, references: TokenReferences): DesignToken {\n const bound = bindingReferences(node, references)\n return {\n $type: 'typography',\n $value: typographyValue(node, bound),\n $extensions: {\n [PAIRDRAW_EXTENSION]: {\n text: {\n fontFamily: node.fontFamily,\n fontWeight: node.fontWeight,\n italic: node.italic,\n fontSize: node.fontSize,\n lineHeight: node.lineHeight,\n letterSpacing: node.letterSpacing,\n textDecoration: node.textDecoration,\n textCase: node.textCase\n },\n ...(isEmptyObject(bound) ? {} : { bindings: bound })\n }\n }\n }\n}\n\nexport function isShadow(effect: Effect): effect is ShadowEffect {\n return effect.type === 'DROP_SHADOW' || effect.type === 'INNER_SHADOW'\n}\n\nfunction shadowValue(effect: ShadowEffect) {\n return {\n color: colorTokenValue(effect.color),\n offsetX: dimensionTokenValue(effect.offset.x),\n offsetY: dimensionTokenValue(effect.offset.y),\n blur: dimensionTokenValue(effect.radius),\n spread: dimensionTokenValue(effect.spread),\n ...(effect.type === 'INNER_SHADOW' ? { inset: true } : {})\n }\n}\n\n/** A shadow token's `$value`: the visible shadows of `effects`, or undefined when there are none. */\nexport function shadowTokenValue(effects: readonly Effect[]) {\n const values = effects\n .filter((effect): effect is ShadowEffect => isShadow(effect) && effect.visible)\n .map(shadowValue)\n if (values.length === 0) return undefined\n return values.length === 1 ? values[0] : values\n}\n\n/**\n * An effect style's shadows as a shadow token. Effects a shadow token cannot express, such as\n * blurs or hidden shadows, ride along whole in Pairdraw's extension, in the plugin API's shape;\n * a style with no visible shadow has no token.\n */\nfunction shadowToken(node: SceneNode): DesignToken | undefined {\n const $value = shadowTokenValue(node.effects)\n if ($value === undefined) return undefined\n const exact = node.effects.every(\n (effect) =>\n isShadow(effect) &&\n effect.visible &&\n (effect.blendMode ?? 'NORMAL') === 'NORMAL' &&\n effect.showShadowBehindNode !== true\n )\n return {\n $type: 'shadow',\n $value,\n ...(exact\n ? {}\n : {\n $extensions: {\n [PAIRDRAW_EXTENSION]: {\n effects: node.effects\n .filter((effect): effect is ShadowEffect => effect.type !== 'SHADER')\n .map(toFigmaEffect)\n }\n }\n })\n }\n}\n\n/** Text and effect styles as typography and shadow tokens, nested by their names. */\nexport function styleTokens(\n graph: SceneGraph,\n references: TokenReferences\n): { tokens: Array<{ path: string[]; token: DesignToken }>; issues: DesignTokenIssue[] } {\n const issues: DesignTokenIssue[] = []\n const styles = [...graph.getAllNodes()].filter(\n (node) =>\n (node.sharedStyleType === 'TEXT' || node.sharedStyleType === 'EFFECT') &&\n node.source.id !== null\n )\n const candidates = styles.flatMap((node) => {\n const token =\n node.sharedStyleType === 'TEXT' ? typographyToken(node, references) : shadowToken(node)\n if (!token) {\n issues.push({ kind: 'unsupported-effect', style: node.name })\n return []\n }\n return [{ key: { node, token }, path: tokenPath(node.name) }]\n })\n const { placed, duplicates } = placeTokens(candidates)\n for (const { node } of duplicates)\n issues.push({ kind: 'duplicate-path', collection: 'Styles', token: node.name })\n const tokens = [...placed].map(([{ node, token }, path]) => ({\n path,\n token: withOriginalName(token, node.name, path)\n }))\n return { tokens, issues }\n}\n\n/** Keeps a name the token path could not hold, such as one with a `.`, in Pairdraw's extension. */\nexport function withOriginalName(\n token: DesignToken,\n name: string,\n path: readonly string[]\n): DesignToken {\n if (pathName(path) === name) return token\n const own = token.$extensions?.[PAIRDRAW_EXTENSION]\n return {\n ...token,\n $extensions: {\n ...token.$extensions,\n [PAIRDRAW_EXTENSION]: { ...(isPlainObject(own) ? own : {}), name }\n }\n }\n}\n"],"mappings":";;;;;;;;AAeA,MAAM,mBAAmB;AAEzB,MAAM,sBAAsB;CAAC;CAAc;CAAY;CAAiB;AAAY;AAEpF,SAAS,kBACP,MACA,YAC+D;CAC/D,MAAM,QAAQ,oBAAoB,SAAS,UAAU;EACnD,MAAM,aAAa,KAAK,eAAe;EACvC,MAAM,OAAO,aAAa,WAAW,IAAI,UAAU,IAAI,KAAA;EACvD,OAAO,OAAO,CAAC,CAAC,OAAO,eAAe,IAAI,CAAC,CAAU,IAAI,CAAC;CAC5D,CAAC;CACD,OAAO,OAAO,YAAY,KAAK;AACjC;;AAQA,SAAgB,gBACd,MACA,OACA;CAEA,MAAM,eAAe,iBAAiB,KAAK,YAAY,KAAK,QAAQ;CACpE,MAAM,aACJ,iBAAiB,QAAQ,KAAK,YAAY,IACtC,mBACA,WAAW,eAAe,KAAK,QAAQ;CAC7C,OAAO;EACL,YAAY,MAAM,cAAc,KAAK;EACrC,UAAU,MAAM,YAAY,oBAAoB,KAAK,QAAQ;EAC7D,YAAY,KAAK;EACjB;EACA,eACE,MAAM,iBACN,oBAAoB,iBAAiB,KAAK,eAAe,KAAK,QAAQ,CAAC;CAC3E;AACF;;AAGA,SAAS,gBAAgB,MAAiB,YAA0C;CAClF,MAAM,QAAQ,kBAAkB,MAAM,UAAU;CAChD,OAAO;EACL,OAAO;EACP,QAAQ,gBAAgB,MAAM,KAAK;EACnC,aAAa,GACV,qBAAqB;GACpB,MAAM;IACJ,YAAY,KAAK;IACjB,YAAY,KAAK;IACjB,QAAQ,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,aALS,CAAC,GAAG,MAAM,YAAY,CAAC,CAAC,CAAC,QACrC,UACE,KAAK,oBAAoB,UAAU,KAAK,oBAAoB,aAC7D,KAAK,OAAO,OAAO,IAEC,CAAC,CAAC,SAAS,SAAS;EAC1C,MAAM,QACJ,KAAK,oBAAoB,SAAS,gBAAgB,MAAM,UAAU,IAAI,YAAY,IAAI;EACxF,IAAI,CAAC,OAAO;GACV,OAAO,KAAK;IAAE,MAAM;IAAsB,OAAO,KAAK;GAAK,CAAC;GAC5D,OAAO,CAAC;EACV;EACA,OAAO,CAAC;GAAE,KAAK;IAAE;IAAM;GAAM;GAAG,MAAM,UAAU,KAAK,IAAI;EAAE,CAAC;CAC9D,CAAC;CACD,MAAM,EAAE,QAAQ,eAAe,YAAY,UAAU;CACrD,KAAK,MAAM,EAAE,UAAU,YACrB,OAAO,KAAK;EAAE,MAAM;EAAkB,YAAY;EAAU,OAAO,KAAK;CAAK,CAAC;CAKhF,OAAO;EAAE,QAJM,CAAC,GAAG,MAAM,CAAC,CAAC,KAAK,CAAC,EAAE,MAAM,SAAS,WAAW;GAC3D;GACA,OAAO,iBAAiB,OAAO,KAAK,MAAM,IAAI;EAChD,EACc;EAAG;CAAO;AAC1B;;AAGA,SAAgB,iBACd,OACA,MACA,MACa;CACb,IAAI,SAAS,IAAI,MAAM,MAAM,OAAO;CACpC,MAAM,MAAM,MAAM,cAAc;CAChC,OAAO;EACL,GAAG;EACH,aAAa;GACX,GAAG,MAAM;IACR,qBAAqB;IAAE,GAAI,cAAc,GAAG,IAAI,MAAM,CAAC;IAAI;GAAK;EACnE;CACF;AACF"}
1
+ {"version":3,"file":"styles.js","names":[],"sources":["../../../../src/io/formats/design-tokens/styles.ts"],"sourcesContent":["import { countBy } from 'es-toolkit/array'\nimport { isEmptyObject, isPlainObject } from 'es-toolkit/predicate'\n\nimport type { Effect, ShadowEffect, SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { lineHeightPixels, textLengthPixels } from '@pairdraw/scene-graph/text'\n\nimport { toFigmaEffect } from '#core/figma-api/effects'\n\nimport { pathName, placeTokens, tokenPath, tokenReference } from './paths'\nimport { PAIRDRAW_EXTENSION, type DesignToken, type DesignTokenIssue } from './types'\nimport { colorTokenValue, dimensionTokenValue, trimNumber } from './values'\n\n/** Where a variable's token sits, for references to it. */\nexport type TokenReferences = ReadonlyMap<string, readonly string[]>\n\n/**\n * The variable a bound style field points at, by collection and name, as Figma's\n * `com.figma.aliasData` names an alias target, since a path alone can be in several collections.\n */\nexport interface BindingTarget {\n targetVariableSetName: string\n targetVariableName: string\n}\n\n/** The variables a style's bound fields point at, by field, for those a reference was written for. */\nfunction bindingTargets(\n graph: SceneGraph,\n node: SceneNode,\n fields: Iterable<string>\n): Record<string, BindingTarget> {\n const targets: Record<string, BindingTarget> = {}\n for (const field of fields) {\n const variable = graph.variables.get(node.boundVariables[field] ?? '')\n const collection = variable && graph.variableCollections.get(variable.collectionId)\n if (variable && collection)\n targets[field] = { targetVariableSetName: collection.name, targetVariableName: variable.name }\n }\n return targets\n}\n\n/** The fields a style binds and how a file read back finds each: its reference and its target. */\nfunction ownBindings(graph: SceneGraph, node: SceneNode, bindings: Record<string, string>) {\n const own: Record<string, unknown> = {}\n if (isEmptyObject(bindings)) return own\n own.bindings = bindings\n own.aliasData = bindingTargets(graph, node, Object.keys(bindings))\n return own\n}\n\n/** Figma's auto line height, written as the multiplier browsers use for `normal`. */\nconst AUTO_LINE_HEIGHT = 1.2\n\nconst TEXT_BINDING_FIELDS = ['fontFamily', 'fontSize', 'letterSpacing', 'lineHeight'] as const\n\nfunction bindingReferences(\n node: SceneNode,\n references: TokenReferences\n): Partial<Record<(typeof TEXT_BINDING_FIELDS)[number], string>> {\n const bound = TEXT_BINDING_FIELDS.flatMap((field) => {\n const variableId = node.boundVariables[field]\n const path = variableId ? references.get(variableId) : undefined\n return path ? [[field, tokenReference(path)] as const] : []\n })\n return Object.fromEntries(bound)\n}\n\nexport type TypographyFields = Pick<\n SceneNode,\n 'fontFamily' | 'fontSize' | 'fontWeight' | 'lineHeight' | 'letterSpacing'\n>\n\n/** A typography token's `$value`: bound fields as references to their variables' tokens. */\nexport function typographyValue(\n text: TypographyFields,\n bound: Partial<Record<(typeof TEXT_BINDING_FIELDS)[number], string>>\n) {\n // A typography token writes a line height as a multiple of the font size.\n const lineHeightPx = lineHeightPixels(text.lineHeight, text.fontSize)\n const lineHeight =\n lineHeightPx === null || text.fontSize <= 0\n ? AUTO_LINE_HEIGHT\n : trimNumber(lineHeightPx / text.fontSize)\n return {\n fontFamily: bound.fontFamily ?? text.fontFamily,\n fontSize: bound.fontSize ?? dimensionTokenValue(text.fontSize),\n fontWeight: text.fontWeight,\n lineHeight,\n letterSpacing:\n bound.letterSpacing ??\n dimensionTokenValue(textLengthPixels(text.letterSpacing, text.fontSize))\n }\n}\n\n/** A text style as a typography token; its own fields ride along so Pairdraw reads it back exactly. */\nfunction typographyToken(\n graph: SceneGraph,\n node: SceneNode,\n references: TokenReferences\n): DesignToken {\n const bound = bindingReferences(node, references)\n return {\n $type: 'typography',\n $value: typographyValue(node, bound),\n $extensions: {\n [PAIRDRAW_EXTENSION]: {\n text: {\n fontFamily: node.fontFamily,\n fontWeight: node.fontWeight,\n italic: node.italic,\n fontSize: node.fontSize,\n lineHeight: node.lineHeight,\n letterSpacing: node.letterSpacing,\n textDecoration: node.textDecoration,\n textCase: node.textCase\n },\n ...ownBindings(graph, node, bound)\n }\n }\n }\n}\n\nexport function isShadow(effect: Effect): effect is ShadowEffect {\n return effect.type === 'DROP_SHADOW' || effect.type === 'INNER_SHADOW'\n}\n\nfunction shadowValue(effect: ShadowEffect) {\n return {\n color: colorTokenValue(effect.color),\n offsetX: dimensionTokenValue(effect.offset.x),\n offsetY: dimensionTokenValue(effect.offset.y),\n blur: dimensionTokenValue(effect.radius),\n spread: dimensionTokenValue(effect.spread),\n ...(effect.type === 'INNER_SHADOW' ? { inset: true } : {})\n }\n}\n\n/** A shadow token's `$value`: the visible shadows of `effects`, or undefined when there are none. */\nexport function shadowTokenValue(effects: readonly Effect[]) {\n const values = effects\n .filter((effect): effect is ShadowEffect => isShadow(effect) && effect.visible)\n .map(shadowValue)\n if (values.length === 0) return undefined\n return values.length === 1 ? values[0] : values\n}\n\n/**\n * An effect style's shadows as a shadow token. Effects a shadow token cannot express, such as\n * blurs or hidden shadows, ride along whole in Pairdraw's extension, in the plugin API's shape;\n * a style with no visible shadow has no token.\n */\nfunction shadowToken(node: SceneNode): DesignToken | undefined {\n const $value = shadowTokenValue(node.effects)\n if ($value === undefined) return undefined\n const exact = node.effects.every(\n (effect) =>\n isShadow(effect) &&\n effect.visible &&\n (effect.blendMode ?? 'NORMAL') === 'NORMAL' &&\n effect.showShadowBehindNode !== true\n )\n return {\n $type: 'shadow',\n $value,\n ...(exact\n ? {}\n : {\n $extensions: {\n [PAIRDRAW_EXTENSION]: {\n effects: node.effects\n .filter((effect): effect is ShadowEffect => effect.type !== 'SHADER')\n .map(toFigmaEffect)\n }\n }\n })\n }\n}\n\n/** Whether a style's token writes a reference for this bound field. */\nfunction writesBinding(node: SceneNode, field: string): boolean {\n return node.sharedStyleType === 'TEXT' && TEXT_BINDING_FIELDS.some((bound) => bound === field)\n}\n\n/** Text and effect styles as typography and shadow tokens, nested by their names. */\nexport function styleTokens(\n graph: SceneGraph,\n references: TokenReferences\n): { tokens: Array<{ path: string[]; token: DesignToken }>; issues: DesignTokenIssue[] } {\n const issues: DesignTokenIssue[] = []\n const styles = [...graph.getAllNodes()].filter(\n (node) =>\n (node.sharedStyleType === 'TEXT' || node.sharedStyleType === 'EFFECT') &&\n node.source.id !== null\n )\n // Another tool reads a reference to a path several collections hold as whichever comes last.\n const shared = new Set(\n Object.entries(countBy([...references.values()], (path) => tokenReference(path)))\n .filter(([, count]) => count > 1)\n .map(([reference]) => reference)\n )\n const candidates = styles.flatMap((node) => {\n const token =\n node.sharedStyleType === 'TEXT' ? typographyToken(graph, node, references) : shadowToken(node)\n if (!token) {\n issues.push({ kind: 'unsupported-effect', style: node.name })\n return []\n }\n return [{ key: { node, token }, path: tokenPath(node.name) }]\n })\n const { placed, duplicates } = placeTokens(candidates)\n for (const { node } of duplicates)\n issues.push({ kind: 'duplicate-path', collection: 'Styles', token: node.name })\n for (const [{ node }] of placed) {\n for (const [field, variableId] of Object.entries(node.boundVariables)) {\n const path = writesBinding(node, field) ? references.get(variableId) : undefined\n if (path && shared.has(tokenReference(path)))\n issues.push({ kind: 'ambiguous-reference', style: node.name, field, token: pathName(path) })\n }\n }\n const tokens = [...placed].map(([{ node, token }, path]) => ({\n path,\n token: withOriginalName(token, node.name, path)\n }))\n return { tokens, issues }\n}\n\n/** Keeps a name the token path could not hold, such as one with a `.`, in Pairdraw's extension. */\nexport function withOriginalName(\n token: DesignToken,\n name: string,\n path: readonly string[]\n): DesignToken {\n if (pathName(path) === name) return token\n const own = token.$extensions?.[PAIRDRAW_EXTENSION]\n return {\n ...token,\n $extensions: {\n ...token.$extensions,\n [PAIRDRAW_EXTENSION]: { ...(isPlainObject(own) ? own : {}), name }\n }\n }\n}\n"],"mappings":";;;;;;;;;AAyBA,SAAS,eACP,OACA,MACA,QAC+B;CAC/B,MAAM,UAAyC,CAAC;CAChD,KAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,WAAW,MAAM,UAAU,IAAI,KAAK,eAAe,UAAU,EAAE;EACrE,MAAM,aAAa,YAAY,MAAM,oBAAoB,IAAI,SAAS,YAAY;EAClF,IAAI,YAAY,YACd,QAAQ,SAAS;GAAE,uBAAuB,WAAW;GAAM,oBAAoB,SAAS;EAAK;CACjG;CACA,OAAO;AACT;;AAGA,SAAS,YAAY,OAAmB,MAAiB,UAAkC;CACzF,MAAM,MAA+B,CAAC;CACtC,IAAI,cAAc,QAAQ,GAAG,OAAO;CACpC,IAAI,WAAW;CACf,IAAI,YAAY,eAAe,OAAO,MAAM,OAAO,KAAK,QAAQ,CAAC;CACjE,OAAO;AACT;;AAGA,MAAM,mBAAmB;AAEzB,MAAM,sBA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IAAI,MAAM,CAAC;IAAI;GAAK;EACnE;CACF;AACF"}
@@ -44,6 +44,11 @@ type DesignTokenIssue = {
44
44
  } | {
45
45
  kind: 'unsupported-effect';
46
46
  style: string;
47
+ } | {
48
+ kind: 'ambiguous-reference';
49
+ style: string;
50
+ field: string;
51
+ token: string;
47
52
  };
48
53
  /** An issue as one line of text, for the CLI and tool output. */
49
54
  declare function designTokenIssueMessage(issue: DesignTokenIssue): string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","names":[],"sources":["../../../../src/io/formats/design-tokens/types.ts"],"mappings":";;;;;;KAMY;;UAYK;EACf,OAAO;EACP;EACA;EACA,cAAc;;;KAIJ;GAAsB;;;UAGjB;EACf;EACA,SAAS;;;KAIC;EACN;EAAgC;EAAoB;EAAc;;EAClE;EAAuB;EAAoB;EAAc;;EACzD;EAAuB;EAAoB;EAAc;;EACzD;EAAwB;EAAoB;;EAC5C;EAA4B;;;iBAGlB,wBAAwB,OAAO;;cAalC;;cAGA"}
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../../../../src/io/formats/design-tokens/types.ts"],"mappings":";;;;;;KAMY;;UAYK;EACf,OAAO;EACP;EACA;EACA,cAAc;;;KAIJ;GAAsB;;;UAGjB;EACf;EACA,SAAS;;;KAIC;EACN;EAAgC;EAAoB;EAAc;;EAClE;EAAuB;EAAoB;EAAc;;EACzD;EAAuB;EAAoB;EAAc;;EACzD;EAAwB;EAAoB;;EAC5C;EAA4B;;EAC5B;EAA6B;EAAe;EAAe;;;iBAGjD,wBAAwB,OAAO;;cAelC;;cAGA"}
@@ -5,6 +5,7 @@ function designTokenIssueMessage(issue) {
5
5
  if (issue.kind === "missing-value") return `${issue.collection} / ${issue.mode}: ${issue.token} has no value in this mode`;
6
6
  if (issue.kind === "missing-alias") return `${issue.collection} / ${issue.mode}: ${issue.token} points at a variable that is gone`;
7
7
  if (issue.kind === "duplicate-path") return `${issue.collection}: ${issue.token} has the same token path as another variable`;
8
+ if (issue.kind === "ambiguous-reference") return `${issue.style}: ${issue.field} refers to ${issue.token}, a path several collections hold, so other tools may read another variable`;
8
9
  return `${issue.style}: an effect style with no visible shadow has no token`;
9
10
  }
10
11
  /** The key Pairdraw's own token data is kept under in `$extensions`. */
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../../../../src/io/formats/design-tokens/types.ts"],"sourcesContent":["/**\n * W3C Design Tokens (DTCG 2025.10) as Pairdraw reads and writes them: one token file per\n * collection mode, a resolver document tying them together, and a file of composite style tokens.\n */\n\n/** The `$type` values Pairdraw writes, plus `string`, which Figma reads and writes. */\nexport type DesignTokenType =\n | 'color'\n | 'dimension'\n | 'duration'\n | 'number'\n | 'fontFamily'\n | 'fontWeight'\n | 'string'\n | 'typography'\n | 'shadow'\n\n/** A token as written: its value and the metadata DTCG and tools attach to it. */\nexport interface DesignToken {\n $type: DesignTokenType\n $value: unknown\n $description?: string\n $extensions?: Record<string, unknown>\n}\n\n/** A token document or group: tokens and nested groups by name, and `$` properties. */\nexport type DesignTokenGroup = { [name: string]: unknown }\n\n/** A file of the export, by its path relative to the export's root. */\nexport interface DesignTokenFile {\n path: string\n content: DesignTokenGroup\n}\n\n/** Why a token, mode, or style was left out or changed; the names are as the document has them. */\nexport type DesignTokenIssue =\n | { kind: 'unsupported-expression'; collection: string; mode: string; token: string }\n | { kind: 'missing-value'; collection: string; mode: string; token: string }\n | { kind: 'missing-alias'; collection: string; mode: string; token: string }\n | { kind: 'duplicate-path'; collection: string; token: string }\n | { kind: 'unsupported-effect'; style: string }\n\n/** An issue as one line of text, for the CLI and tool output. */\nexport function designTokenIssueMessage(issue: DesignTokenIssue): string {\n if (issue.kind === 'unsupported-expression')\n return `${issue.collection} / ${issue.mode}: ${issue.token} uses an expression that token export does not support`\n if (issue.kind === 'missing-value')\n return `${issue.collection} / ${issue.mode}: ${issue.token} has no value in this mode`\n if (issue.kind === 'missing-alias')\n return `${issue.collection} / ${issue.mode}: ${issue.token} points at a variable that is gone`\n if (issue.kind === 'duplicate-path')\n return `${issue.collection}: ${issue.token} has the same token path as another variable`\n return `${issue.style}: an effect style with no visible shadow has no token`\n}\n\n/** The key Pairdraw's own token data is kept under in `$extensions`. */\nexport const PAIRDRAW_EXTENSION = 'dev.pairdraw'\n\n/** The resolver document version DTCG 2025.10 requires. */\nexport const RESOLVER_VERSION = '2025-11-01'\n"],"mappings":";;AA2CA,SAAgB,wBAAwB,OAAiC;CACvE,IAAI,MAAM,SAAS,0BACjB,OAAO,GAAG,MAAM,WAAW,KAAK,MAAM,KAAK,IAAI,MAAM,MAAM;CAC7D,IAAI,MAAM,SAAS,iBACjB,OAAO,GAAG,MAAM,WAAW,KAAK,MAAM,KAAK,IAAI,MAAM,MAAM;CAC7D,IAAI,MAAM,SAAS,iBACjB,OAAO,GAAG,MAAM,WAAW,KAAK,MAAM,KAAK,IAAI,MAAM,MAAM;CAC7D,IAAI,MAAM,SAAS,kBACjB,OAAO,GAAG,MAAM,WAAW,IAAI,MAAM,MAAM;CAC7C,OAAO,GAAG,MAAM,MAAM;AACxB;;AAGA,MAAa,qBAAqB;;AAGlC,MAAa,mBAAmB"}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../../../src/io/formats/design-tokens/types.ts"],"sourcesContent":["/**\n * W3C Design Tokens (DTCG 2025.10) as Pairdraw reads and writes them: one token file per\n * collection mode, a resolver document tying them together, and a file of composite style tokens.\n */\n\n/** The `$type` values Pairdraw writes, plus `string`, which Figma reads and writes. */\nexport type DesignTokenType =\n | 'color'\n | 'dimension'\n | 'duration'\n | 'number'\n | 'fontFamily'\n | 'fontWeight'\n | 'string'\n | 'typography'\n | 'shadow'\n\n/** A token as written: its value and the metadata DTCG and tools attach to it. */\nexport interface DesignToken {\n $type: DesignTokenType\n $value: unknown\n $description?: string\n $extensions?: Record<string, unknown>\n}\n\n/** A token document or group: tokens and nested groups by name, and `$` properties. */\nexport type DesignTokenGroup = { [name: string]: unknown }\n\n/** A file of the export, by its path relative to the export's root. */\nexport interface DesignTokenFile {\n path: string\n content: DesignTokenGroup\n}\n\n/** Why a token, mode, or style was left out or changed; the names are as the document has them. */\nexport type DesignTokenIssue =\n | { kind: 'unsupported-expression'; collection: string; mode: string; token: string }\n | { kind: 'missing-value'; collection: string; mode: string; token: string }\n | { kind: 'missing-alias'; collection: string; mode: string; token: string }\n | { kind: 'duplicate-path'; collection: string; token: string }\n | { kind: 'unsupported-effect'; style: string }\n | { kind: 'ambiguous-reference'; style: string; field: string; token: string }\n\n/** An issue as one line of text, for the CLI and tool output. */\nexport function designTokenIssueMessage(issue: DesignTokenIssue): string {\n if (issue.kind === 'unsupported-expression')\n return `${issue.collection} / ${issue.mode}: ${issue.token} uses an expression that token export does not support`\n if (issue.kind === 'missing-value')\n return `${issue.collection} / ${issue.mode}: ${issue.token} has no value in this mode`\n if (issue.kind === 'missing-alias')\n return `${issue.collection} / ${issue.mode}: ${issue.token} points at a variable that is gone`\n if (issue.kind === 'duplicate-path')\n return `${issue.collection}: ${issue.token} has the same token path as another variable`\n if (issue.kind === 'ambiguous-reference')\n return `${issue.style}: ${issue.field} refers to ${issue.token}, a path several collections hold, so other tools may read another variable`\n return `${issue.style}: an effect style with no visible shadow has no token`\n}\n\n/** The key Pairdraw's own token data is kept under in `$extensions`. */\nexport const PAIRDRAW_EXTENSION = 'dev.pairdraw'\n\n/** The resolver document version DTCG 2025.10 requires. */\nexport const RESOLVER_VERSION = '2025-11-01'\n"],"mappings":";;AA4CA,SAAgB,wBAAwB,OAAiC;CACvE,IAAI,MAAM,SAAS,0BACjB,OAAO,GAAG,MAAM,WAAW,KAAK,MAAM,KAAK,IAAI,MAAM,MAAM;CAC7D,IAAI,MAAM,SAAS,iBACjB,OAAO,GAAG,MAAM,WAAW,KAAK,MAAM,KAAK,IAAI,MAAM,MAAM;CAC7D,IAAI,MAAM,SAAS,iBACjB,OAAO,GAAG,MAAM,WAAW,KAAK,MAAM,KAAK,IAAI,MAAM,MAAM;CAC7D,IAAI,MAAM,SAAS,kBACjB,OAAO,GAAG,MAAM,WAAW,IAAI,MAAM,MAAM;CAC7C,IAAI,MAAM,SAAS,uBACjB,OAAO,GAAG,MAAM,MAAM,IAAI,MAAM,MAAM,aAAa,MAAM,MAAM;CACjE,OAAO,GAAG,MAAM,MAAM;AACxB;;AAGA,MAAa,qBAAqB;;AAGlC,MAAa,mBAAmB"}
@@ -1 +1 @@
1
- {"version":3,"file":"export.d.ts","names":[],"sources":["../../../../src/io/formats/drawio/export.ts"],"mappings":";;;;KAuhBY;EACN;;EACA;EAAgB;;;;;;;;iBAQN,mBAAmB,OAAO,YAAY,QAAQ,qBAAqB"}
1
+ {"version":3,"file":"export.d.ts","names":[],"sources":["../../../../src/io/formats/drawio/export.ts"],"mappings":";;;;KAkiBY;EACN;;EACA;EAAgB;;;;;;;;iBAQN,mBAAmB,OAAO,YAAY,QAAQ,qBAAqB"}
@@ -20,6 +20,10 @@ function style(names, values) {
20
20
  values: Object.fromEntries(Object.entries(values).filter(([, v]) => v !== void 0))
21
21
  };
22
22
  }
23
+ /** A layer's name, which draw.io has no field of its own for, so it travels in the style. */
24
+ function nameValues(node) {
25
+ return { pairdrawName: encodeURIComponent(node.name) };
26
+ }
23
27
  /** A layer's first visible solid fill, or the first stop of a gradient, as draw.io's colour. */
24
28
  function fillColor(node) {
25
29
  const fill = node.fills.find((paint) => paint.visible);
@@ -248,6 +252,7 @@ var PageWriter = class {
248
252
  style: style(["text"], {
249
253
  html: "1",
250
254
  whiteSpace: "wrap",
255
+ ...nameValues(node),
251
256
  ...placedValues(placement),
252
257
  ...fontValues(node)
253
258
  }),
@@ -300,6 +305,7 @@ var PageWriter = class {
300
305
  style: style([], {
301
306
  container: "1",
302
307
  html: "1",
308
+ ...nameValues(node),
303
309
  ...paintValues(node),
304
310
  ...placedValues(placement)
305
311
  }),
@@ -311,7 +317,10 @@ var PageWriter = class {
311
317
  kind: "vertex",
312
318
  value: "",
313
319
  style: style(node.type === "ELLIPSE" ? ["ellipse"] : [], {
320
+ ...node.type === "RECTANGLE" ? { pairdrawType: "RECTANGLE" } : {},
314
321
  rounded: node.cornerRadius > 0 ? "1" : void 0,
322
+ pairdrawCornerRadius: node.cornerRadius > 0 ? String(node.cornerRadius) : void 0,
323
+ ...nameValues(node),
315
324
  ...placedValues(placement),
316
325
  ...paintValues(node)
317
326
  }),
@@ -325,6 +334,7 @@ var PageWriter = class {
325
334
  const label = shapeWithTextLabel(this.graph, node);
326
335
  const values = {
327
336
  ...drawioShapeValues(node.shapeWithTextType),
337
+ ...nameValues(node),
328
338
  whiteSpace: "wrap",
329
339
  html: "1",
330
340
  ...paintValues(node),
@@ -1 +1 @@
1
- {"version":3,"file":"export.js","names":[],"sources":["../../../../src/io/formats/drawio/export.ts"],"sourcesContent":["import { escapeText } from 'entities'\nimport { fromUint8Array } from 'js-base64'\n\nimport type {\n DrawIOCell,\n DrawIOFile,\n DrawIOGeometry,\n DrawIOPage,\n DrawIOPoint,\n DrawIOStyle\n} from '@pairdraw/drawio'\nimport type { ConnectorEndpoint, SceneGraph, SceneNode, StrokeCap } from '@pairdraw/scene-graph'\nimport { colorToHex } from '@pairdraw/scene-graph/color'\nimport {\n connectorRoute,\n connectorRouteEnds,\n connectorSublayers,\n curveMidpoint\n} from '@pairdraw/scene-graph/connectors'\nimport { getParentWorldMatrix, getWorldMatrix } from '@pairdraw/scene-graph/coordinate'\nimport {\n isGeneratedFrame,\n shapeWithTextLabel,\n stickySublayers\n} from '@pairdraw/scene-graph/generated'\nimport Matrix from '@pairdraw/scene-graph/matrix'\nimport type { Vector } from '@pairdraw/scene-graph/primitives'\n\nimport { computeContentBounds } from '#core/io/formats/raster'\nimport { renderNodesToSVG } from '#core/io/formats/svg'\n\nimport { DEFAULT_FONT_FAMILY } from './paint'\nimport { EMPTY_GEOMETRY, placed, placedValues, round, type Placed } from './placement'\nimport { drawioShapeValues } from './shapes'\n\n/** draw.io's id for its root cell and for its one layer, as it numbers new files. */\nconst ROOT_ID = '0'\nconst LAYER_ID = '1'\n\nfunction style(names: string[], values: Record<string, string | undefined>): DrawIOStyle {\n return {\n names,\n values: Object.fromEntries(Object.entries(values).filter(([, v]) => v !== undefined))\n }\n}\n\n/** A layer's first visible solid fill, or the first stop of a gradient, as draw.io's colour. */\nfunction fillColor(node: SceneNode): string {\n const fill = node.fills.find((paint) => paint.visible)\n if (!fill) return 'none'\n if (fill.type === 'SOLID') return colorToHex(fill.color)\n const stop = fill.gradientStops?.at(0)\n return stop ? colorToHex(stop.color) : 'none'\n}\n\n/** A layer's fill, outline, dash, and opacity as style pairs. */\nfunction paintValues(node: SceneNode): Record<string, string | undefined> {\n const stroke = node.strokes.find((paint) => paint.visible)\n const weight = stroke?.weight ?? node.strokeWeight\n const dash = stroke?.dashPattern ?? node.dashPattern\n return {\n fillColor: fillColor(node),\n strokeColor: stroke ? colorToHex(stroke.color) : 'none',\n strokeWidth: stroke && weight !== 1 ? String(weight) : undefined,\n dashed: dash.length > 0 ? '1' : undefined,\n dashPattern: dash.length > 0 ? dash.map((n) => round(n / (weight || 1))).join(' ') : undefined,\n opacity: node.opacity < 1 ? String(Math.round(node.opacity * 100)) : undefined\n }\n}\n\nconst ALIGN: Record<SceneNode['textAlignHorizontal'], string> = {\n LEFT: 'left',\n CENTER: 'center',\n RIGHT: 'right',\n JUSTIFIED: 'left'\n}\nconst VERTICAL_ALIGN: Record<SceneNode['textAlignVertical'], string> = {\n TOP: 'top',\n CENTER: 'middle',\n BOTTOM: 'bottom'\n}\n\n/** A text layer's font and alignment as a label's style pairs. */\nfunction fontValues(text: SceneNode): Record<string, string | undefined> {\n const fill = text.fills.find((paint) => paint.visible && paint.type === 'SOLID')\n const bits =\n (text.fontWeight >= 600 ? 1 : 0) |\n (text.italic ? 2 : 0) |\n (text.textDecoration === 'UNDERLINE' ? 4 : 0)\n return {\n fontSize: String(text.fontSize),\n // The font draw.io's default stands for on import goes back as that default.\n fontFamily: text.fontFamily === DEFAULT_FONT_FAMILY ? undefined : text.fontFamily,\n fontColor: fill ? colorToHex(fill.color) : undefined,\n fontStyle: bits ? String(bits) : undefined,\n align: ALIGN[text.textAlignHorizontal],\n verticalAlign: VERTICAL_ALIGN[text.textAlignVertical]\n }\n}\n\n/**\n * A text layer's characters as an HTML label: each style run in a span that sets what it\n * changes, and a line break for each new line.\n */\nfunction labelHTML(text: SceneNode): string {\n const { text: characters, styleRuns } = text\n let html = ''\n let at = 0\n const plain = (to: number) => {\n html += escapeText(characters.slice(at, to)).replaceAll('\\n', '<br>')\n at = to\n }\n for (const run of [...styleRuns].sort((a, b) => a.start - b.start)) {\n plain(run.start)\n const css: string[] = []\n const { style: s } = run\n if (s.fontWeight !== undefined) css.push(`font-weight: ${s.fontWeight}`)\n if (s.italic !== undefined) css.push(`font-style: ${s.italic ? 'italic' : 'normal'}`)\n if (s.textDecoration)\n css.push(`text-decoration: ${s.textDecoration === 'UNDERLINE' ? 'underline' : 'none'}`)\n if (s.fontSize !== undefined) css.push(`font-size: ${s.fontSize}px`)\n if (s.fontFamily) css.push(`font-family: ${s.fontFamily}`)\n const fill = s.fills?.find((paint) => paint.type === 'SOLID')\n if (fill?.type === 'SOLID') css.push(`color: ${colorToHex(fill.color)}`)\n const inner = escapeText(characters.slice(run.start, run.start + run.length)).replaceAll(\n '\\n',\n '<br>'\n )\n html += css.length > 0 ? `<span style=\"${css.join('; ')}\">${inner}</span>` : inner\n at = run.start + run.length\n }\n plain(characters.length)\n return html\n}\n\n/** A connector line's colour, width, and dash as an edge's style pairs. */\nfunction lineValues(line: SceneNode): Record<string, string | undefined> {\n const stroke = line.strokes.find((paint) => paint.visible)\n const weight = stroke?.weight ?? 1\n const dash = stroke?.dashPattern ?? []\n return {\n strokeColor: stroke ? colorToHex(stroke.color) : 'none',\n strokeWidth: weight !== 1 ? String(weight) : undefined,\n dashed: dash.length > 0 ? '1' : undefined,\n dashPattern: dash.length > 0 ? dash.map((n) => round(n / weight)).join(' ') : undefined\n }\n}\n\n/** FigJam's ends and the draw.io arrowheads that draw them. */\nconst ARROWS: Record<StrokeCap, string> = {\n NONE: 'none',\n ROUND: 'none',\n SQUARE: 'none',\n ARROW_LINES: 'open',\n ARROW_EQUILATERAL: 'classic',\n TRIANGLE_FILLED: 'classic',\n DIAMOND_FILLED: 'diamond',\n CIRCLE_FILLED: 'oval'\n}\n\n/** Where a side magnet pins an end, as shares of the layer's box. */\nconst SIDE_POINTS: Partial<Record<ConnectorEndpoint['magnet'], [number, number]>> = {\n TOP: [0.5, 0],\n RIGHT: [1, 0.5],\n BOTTOM: [0.5, 1],\n LEFT: [0, 0.5]\n}\n\n/** Writes one page's layers as draw.io cells, in drawing order. */\nclass PageWriter {\n readonly cells: DrawIOCell[] = []\n private readonly ids = new Map<string, string>()\n /** Where each edge's line last ran from and to, in draw.io's axes. */\n private readonly drawnEnds = new Map<string, { start: DrawIOPoint; end: DrawIOPoint }>()\n /** Where each vertex's box starts on the page: draw.io measures its cells' boxes from there. */\n private readonly origins = new Map<string, Vector>([[LAYER_ID, { x: 0, y: 0 }]])\n private next = 2\n\n constructor(\n private readonly graph: SceneGraph,\n private readonly pageId: string\n ) {}\n\n private idOf(nodeId: string): string {\n let id = this.ids.get(nodeId)\n if (!id) {\n id = String(this.next++)\n this.ids.set(nodeId, id)\n }\n return id\n }\n\n write(nodeIds: readonly string[]) {\n // Every layer gets its id first, so an edge can name a layer drawn above it.\n const assign = (id: string) => {\n const node = this.graph.getNode(id)\n if (!node) return\n this.idOf(id)\n if (!isGeneratedFrame(node)) for (const child of node.childIds) assign(child)\n }\n // A layer inside another chosen one goes with it, as a cell of its own or drawn in its picture.\n const chosen = new Set(nodeIds)\n const roots = nodeIds.filter((id) => {\n const parentId = this.graph.getNode(id)?.parentId\n return !parentId || !this.graph.closest(parentId, (node) => chosen.has(node.id))\n })\n for (const id of roots) assign(id)\n for (const id of roots) {\n const node = this.graph.getNode(id)\n if (node) this.layer(node, LAYER_ID)\n }\n this.freeStrandedEnds()\n }\n\n /**\n * An edge end joined to a layer that has no cell, such as one left out of a selection or\n * drawn inside a picture, goes as a free point where the line last ran.\n */\n private freeStrandedEnds() {\n const written = new Set(this.cells.map((cell) => cell.id))\n for (const cell of this.cells) {\n const drawn = this.drawnEnds.get(cell.id)\n if (!drawn) continue\n if (!cell.source || !written.has(cell.source)) {\n cell.source = null\n cell.geometry.sourcePoint = drawn.start\n }\n if (!cell.target || !written.has(cell.target)) {\n cell.target = null\n cell.geometry.targetPoint = drawn.end\n }\n }\n }\n\n private push(\n node: SceneNode,\n parent: string,\n cell: Omit<DrawIOCell, 'id' | 'parent' | 'visible' | 'attributes' | 'source' | 'target'> &\n Partial<Pick<DrawIOCell, 'source' | 'target'>>\n ) {\n const id = this.idOf(node.id)\n if (cell.kind === 'vertex') {\n const from = this.originOf(parent)\n this.origins.set(id, { x: from.x + cell.geometry.x, y: from.y + cell.geometry.y })\n }\n this.cells.push({\n id,\n parent,\n visible: node.visible,\n attributes: {},\n source: null,\n target: null,\n ...cell\n })\n }\n\n private originOf(parent: string): Vector {\n return this.origins.get(parent) ?? { x: 0, y: 0 }\n }\n\n private place(node: SceneNode, parent: string): Placed {\n return placed(node, getWorldMatrix(node, this.graph), this.originOf(parent))\n }\n\n /** The box a layer covers on the page, square to it, in its parent cell's axes. */\n private bounds(node: SceneNode, parent: string): DrawIOGeometry {\n const bounds = computeContentBounds(this.graph, [node.id])\n if (!bounds) return this.place(node, parent).geometry\n const from = this.originOf(parent)\n return {\n ...EMPTY_GEOMETRY,\n x: round(bounds.minX - from.x),\n y: round(bounds.minY - from.y),\n width: round(bounds.maxX - bounds.minX),\n height: round(bounds.maxY - bounds.minY)\n }\n }\n\n private children(node: SceneNode) {\n for (const id of node.childIds) {\n const child = this.graph.getNode(id)\n if (child) this.layer(child, this.idOf(node.id))\n }\n }\n\n private layer(node: SceneNode, parent: string) {\n const placement = this.place(node, parent)\n const { geometry } = placement\n switch (node.type) {\n case 'SHAPE_WITH_TEXT':\n return this.shape(node, parent, placement)\n case 'TEXT':\n return this.push(node, parent, {\n kind: 'vertex',\n value: labelHTML(node),\n style: style(['text'], {\n html: '1',\n whiteSpace: 'wrap',\n ...placedValues(placement),\n ...fontValues(node)\n }),\n geometry\n })\n case 'STICKY': {\n const body = stickySublayers(this.graph, node)?.body\n return this.push(node, parent, {\n kind: 'vertex',\n value: body ? labelHTML(body) : '',\n style: style([], {\n whiteSpace: 'wrap',\n html: '1',\n ...paintValues(node),\n strokeColor: 'none',\n align: 'left',\n verticalAlign: 'top',\n spacing: '20',\n ...placedValues(placement),\n fontSize: body ? String(body.fontSize) : undefined\n }),\n geometry\n })\n }\n case 'SECTION':\n this.push(node, parent, {\n kind: 'vertex',\n value: escapeText(node.name),\n style: style(['swimlane'], {\n html: '1',\n startSize: '30',\n ...paintValues(node),\n ...placedValues(placement)\n }),\n geometry\n })\n return this.children(node)\n case 'GROUP':\n this.push(node, parent, {\n kind: 'vertex',\n value: '',\n style: style(['group'], {}),\n // A group draws nothing, so it holds what it groups square to the page.\n geometry: this.bounds(node, parent)\n })\n return this.children(node)\n case 'FRAME':\n this.push(node, parent, {\n kind: 'vertex',\n value: '',\n style: style([], {\n container: '1',\n html: '1',\n ...paintValues(node),\n ...placedValues(placement)\n }),\n geometry\n })\n return this.children(node)\n case 'RECTANGLE':\n case 'ELLIPSE':\n return this.push(node, parent, {\n kind: 'vertex',\n value: '',\n style: style(node.type === 'ELLIPSE' ? ['ellipse'] : [], {\n rounded: node.cornerRadius > 0 ? '1' : undefined,\n ...placedValues(placement),\n ...paintValues(node)\n }),\n geometry\n })\n case 'CONNECTOR':\n return this.edge(node, parent)\n default:\n return this.picture(node, parent)\n }\n }\n\n private shape(node: SceneNode, parent: string, placement: Placed) {\n const label = shapeWithTextLabel(this.graph, node)\n const values: Record<string, string | undefined> = {\n ...drawioShapeValues(node.shapeWithTextType),\n whiteSpace: 'wrap',\n html: '1',\n ...paintValues(node),\n ...(label ? fontValues(label) : {})\n }\n let { geometry, rotation } = placement\n // A triangle turned a quarter points the way draw.io's direction says, in the box it fills.\n const mirrored = placement.flipH || placement.flipV\n const quarter =\n !mirrored && Math.abs(rotation) === 90 && node.shapeWithTextType === 'TRIANGLE_UP'\n if (quarter) {\n values.direction = rotation === 90 ? 'east' : 'west'\n geometry = {\n ...geometry,\n x: round(geometry.x + (node.width - node.height) / 2),\n y: round(geometry.y + (node.height - node.width) / 2),\n width: round(node.height),\n height: round(node.width)\n }\n rotation = 0\n }\n // A shape that is draw.io's mirrored one, as a left parallelogram is, mirrors back if the layer is.\n const ownFlipH = values.flipH === '1'\n Object.assign(\n values,\n placedValues({ ...placement, rotation, flipH: placement.flipH !== ownFlipH })\n )\n this.push(node, parent, {\n kind: 'vertex',\n value: label ? labelHTML(label) : '',\n style: style([], values),\n geometry\n })\n }\n\n /** A layer draw.io has no cell for, drawn as the SVG image it exports as, where it covers. */\n private picture(node: SceneNode, parent: string) {\n const svg = renderNodesToSVG(this.graph, this.pageId, [node.id])\n if (!svg) return\n const data = fromUint8Array(new TextEncoder().encode(svg))\n this.push(node, parent, {\n kind: 'vertex',\n value: '',\n // draw.io keeps a data URI in its style without `;base64`, which would end the value.\n style: style([], { shape: 'image', image: `data:image/svg+xml,${data}`, aspect: 'fixed' }),\n geometry: this.bounds(node, parent)\n })\n }\n\n private end(\n endpoint: ConnectorEndpoint | null,\n prefix: 'exit' | 'entry'\n ): Record<string, string> {\n const node = endpoint?.nodeId ? this.graph.getNode(endpoint.nodeId) : undefined\n if (!endpoint || !node) return {}\n const side = SIDE_POINTS[endpoint.magnet]\n const point: [number, number] | null =\n side ??\n (endpoint.magnet === 'NONE' || endpoint.magnet === 'ABSOLUTE'\n ? [endpoint.position.x / (node.width || 1), endpoint.position.y / (node.height || 1)]\n : null)\n if (!point) return {}\n return { [`${prefix}X`]: String(round(point[0])), [`${prefix}Y`]: String(round(point[1])) }\n }\n\n /**\n * Where an edge's free ends sit, its bend points, and its label's place along it, with the\n * points carried into draw.io's axes.\n */\n private edgeGeometry(node: SceneNode, parent: string): DrawIOGeometry {\n const toPage = getParentWorldMatrix(\n node.parentId ? this.graph.getNode(node.parentId) : undefined,\n this.graph\n )\n const from = this.originOf(parent)\n const at = (point: Vector) => {\n const mapped = Matrix.mapPoint(toPage, point)\n return { x: round(mapped.x - from.x), y: round(mapped.y - from.y) }\n }\n const drawn = connectorRouteEnds(this.graph, node)\n if (drawn) {\n this.drawnEnds.set(this.idOf(node.id), { start: at(drawn.start), end: at(drawn.end) })\n }\n const position = node.connectorLabelPosition\n const along = position?.section === 'MIDDLE_TO_START' ? -position.offset : position?.offset\n return {\n ...EMPTY_GEOMETRY,\n relative: true,\n x: round(along ?? 0),\n sourcePoint: !node.connectorStart?.nodeId && drawn ? at(drawn.start) : null,\n targetPoint: !node.connectorEnd?.nodeId && drawn ? at(drawn.end) : null,\n points: this.waypoints(node).map(at)\n }\n }\n\n private edge(node: SceneNode, parent: string) {\n // A connector without its line and label is not one draw.io could draw.\n const parts = connectorSublayers(this.graph, node)\n if (!parts) return\n const startId = node.connectorStart?.nodeId\n const endId = node.connectorEnd?.nodeId\n const lineType = node.connectorLineType\n this.push(node, parent, {\n kind: 'edge',\n value: parts.label.text ? labelHTML(parts.label) : '',\n style: style([], {\n edgeStyle: lineType === 'ELBOWED' ? 'orthogonalEdgeStyle' : undefined,\n rounded: lineType === 'ELBOWED' ? '1' : undefined,\n curved: lineType === 'CURVED' ? '1' : undefined,\n html: '1',\n startArrow: ARROWS[node.connectorStartCap],\n endArrow: ARROWS[node.connectorEndCap],\n ...lineValues(parts.line),\n ...this.end(node.connectorStart, 'exit'),\n ...this.end(node.connectorEnd, 'entry'),\n ...fontValues(parts.label)\n }),\n geometry: this.edgeGeometry(node, parent),\n source: startId ? (this.ids.get(startId) ?? null) : null,\n target: endId ? (this.ids.get(endId) ?? null) : null\n })\n }\n\n /**\n * The points a dragged connector bends through, for draw.io to run its edge the same way: an\n * elbow's corners, or the middle of a curve. A connector routing itself leaves draw.io to route.\n */\n private waypoints(node: SceneNode): Vector[] {\n const route = connectorRoute(this.graph, node)\n if (!route) return []\n if (node.connectorLineType === 'CURVED' && node.connectorCurveHandles) {\n const curve = route.pieces.at(0)\n return curve ? [curveMidpoint(curve)] : []\n }\n if (node.connectorLineType !== 'ELBOWED' || node.connectorControlPoints.length === 0) return []\n return route.pieces.slice(0, -1).map((piece) => piece.to)\n }\n}\n\n/** One page of layers as a draw.io page, holding `nodeIds` or every layer on it. */\nfunction pageOf(graph: SceneGraph, pageId: string, nodeIds?: readonly string[]): DrawIOPage {\n const page = graph.getNode(pageId)\n const writer = new PageWriter(graph, pageId)\n writer.write(nodeIds ?? page?.childIds ?? [])\n return {\n id: pageId,\n name: page?.name ?? 'Page',\n attributes: { grid: '1', gridSize: '10' },\n rootId: ROOT_ID,\n layers: [{ id: LAYER_ID, name: '', visible: true, locked: false }],\n cells: writer.cells\n }\n}\n\n/** What a draw.io export holds: whole pages, or some layers of one page. */\nexport type DrawIOExportTarget =\n | { pageIds: readonly string[] }\n | { pageId: string; nodeIds: readonly string[] }\n\n/**\n * Layers as a draw.io file: FigJam shapes as draw.io's shapes of the same meaning, connectors as\n * edges joined to them, bent the way they were dragged, text as text, sections as swimlanes, and\n * frames and groups as containers. A layer draw.io has no cell for goes as an SVG image of\n * itself, so nothing is lost.\n */\nexport function sceneGraphToDrawIO(graph: SceneGraph, target: DrawIOExportTarget): DrawIOFile {\n const pages =\n 'pageIds' in target\n ? target.pageIds.map((pageId) => pageOf(graph, pageId))\n : [pageOf(graph, target.pageId, target.nodeIds)]\n return { pages, unreadable: [] }\n}\n"],"mappings":";;;;;;;;;;;;;;AAoCA,MAAM,UAAU;AAChB,MAAM,WAAW;AAEjB,SAAS,MAAM,OAAiB,QAAyD;CACvF,OAAO;EACL;EACA,QAAQ,OAAO,YAAY,OAAO,QAAQ,MAAM,CAAC,CAAC,QAAQ,GAAG,OAAO,MAAM,KAAA,CAAS,CAAC;CACtF;AACF;;AAGA,SAAS,UAAU,MAAyB;CAC1C,MAAM,OAAO,KAAK,MAAM,MAAM,UAAU,MAAM,OAA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AAC;CACH;;;;;CAMA,UAAkB,MAA2B;EAC3C,MAAM,QAAQ,eAAe,KAAK,OAAO,IAAI;EAC7C,IAAI,CAAC,OAAO,OAAO,CAAC;EACpB,IAAI,KAAK,sBAAsB,YAAY,KAAK,uBAAuB;GACrE,MAAM,QAAQ,MAAM,OAAO,GAAG,CAAC;GAC/B,OAAO,QAAQ,CAAC,cAAc,KAAK,CAAC,IAAI,CAAC;EAC3C;EACA,IAAI,KAAK,sBAAsB,aAAa,KAAK,uBAAuB,WAAW,GAAG,OAAO,CAAC;EAC9F,OAAO,MAAM,OAAO,MAAM,GAAG,EAAE,CAAC,CAAC,KAAK,UAAU,MAAM,EAAE;CAC1D;AACF;;AAGA,SAAS,OAAO,OAAmB,QAAgB,SAAyC;CAC1F,MAAM,OAAO,MAAM,QAAQ,MAAM;CACjC,MAAM,SAAS,IAAI,WAAW,OAAO,MAAM;CAC3C,OAAO,MAAM,WAAW,MAAM,YAAY,CAAC,CAAC;CAC5C,OAAO;EACL,IAAI;EACJ,MAAM,MAAM,QAAQ;EACpB,YAAY;GAAE,MAAM;GAAK,UAAU;EAAK;EACxC,QAAQ;EACR,QAAQ,CAAC;GAAE,IAAI;GAAU,MAAM;GAAI,SAAS;GAAM,QAAQ;EAAM,CAAC;EACjE,OAAO,OAAO;CAChB;AACF;;;;;;;AAaA,SAAgB,mBAAmB,OAAmB,QAAwC;CAK5F,OAAO;EAAE,OAHP,aAAa,SACT,OAAO,QAAQ,KAAK,WAAW,OAAO,OAAO,MAAM,CAAC,IACpD,CAAC,OAAO,OAAO,OAAO,QAAQ,OAAO,OAAO,CAAC;EACnC,YAAY,CAAC;CAAE;AACjC"}
1
+ {"version":3,"file":"export.js","names":[],"sources":["../../../../src/io/formats/drawio/export.ts"],"sourcesContent":["import { escapeText } from 'entities'\nimport { fromUint8Array } from 'js-base64'\n\nimport type {\n DrawIOCell,\n DrawIOFile,\n DrawIOGeometry,\n DrawIOPage,\n DrawIOPoint,\n DrawIOStyle\n} from '@pairdraw/drawio'\nimport type { ConnectorEndpoint, SceneGraph, SceneNode, StrokeCap } from '@pairdraw/scene-graph'\nimport { colorToHex } from '@pairdraw/scene-graph/color'\nimport {\n connectorRoute,\n connectorRouteEnds,\n connectorSublayers,\n curveMidpoint\n} from '@pairdraw/scene-graph/connectors'\nimport { getParentWorldMatrix, getWorldMatrix } from '@pairdraw/scene-graph/coordinate'\nimport {\n isGeneratedFrame,\n shapeWithTextLabel,\n stickySublayers\n} from '@pairdraw/scene-graph/generated'\nimport Matrix from '@pairdraw/scene-graph/matrix'\nimport type { Vector } from '@pairdraw/scene-graph/primitives'\n\nimport { computeContentBounds } from '#core/io/formats/raster'\nimport { renderNodesToSVG } from '#core/io/formats/svg'\n\nimport { DEFAULT_FONT_FAMILY } from './paint'\nimport { EMPTY_GEOMETRY, placed, placedValues, round, type Placed } from './placement'\nimport { drawioShapeValues } from './shapes'\n\n/** draw.io's id for its root cell and for its one layer, as it numbers new files. */\nconst ROOT_ID = '0'\nconst LAYER_ID = '1'\n\nfunction style(names: string[], values: Record<string, string | undefined>): DrawIOStyle {\n return {\n names,\n values: Object.fromEntries(Object.entries(values).filter(([, v]) => v !== undefined))\n }\n}\n\n/** A layer's name, which draw.io has no field of its own for, so it travels in the style. */\nfunction nameValues(node: SceneNode): Record<string, string> {\n return { pairdrawName: encodeURIComponent(node.name) }\n}\n\n/** A layer's first visible solid fill, or the first stop of a gradient, as draw.io's colour. */\nfunction fillColor(node: SceneNode): string {\n const fill = node.fills.find((paint) => paint.visible)\n if (!fill) return 'none'\n if (fill.type === 'SOLID') return colorToHex(fill.color)\n const stop = fill.gradientStops?.at(0)\n return stop ? colorToHex(stop.color) : 'none'\n}\n\n/** A layer's fill, outline, dash, and opacity as style pairs. */\nfunction paintValues(node: SceneNode): Record<string, string | undefined> {\n const stroke = node.strokes.find((paint) => paint.visible)\n const weight = stroke?.weight ?? node.strokeWeight\n const dash = stroke?.dashPattern ?? node.dashPattern\n return {\n fillColor: fillColor(node),\n strokeColor: stroke ? colorToHex(stroke.color) : 'none',\n strokeWidth: stroke && weight !== 1 ? String(weight) : undefined,\n dashed: dash.length > 0 ? '1' : undefined,\n dashPattern: dash.length > 0 ? dash.map((n) => round(n / (weight || 1))).join(' ') : undefined,\n opacity: node.opacity < 1 ? String(Math.round(node.opacity * 100)) : undefined\n }\n}\n\nconst ALIGN: Record<SceneNode['textAlignHorizontal'], string> = {\n LEFT: 'left',\n CENTER: 'center',\n RIGHT: 'right',\n JUSTIFIED: 'left'\n}\nconst VERTICAL_ALIGN: Record<SceneNode['textAlignVertical'], string> = {\n TOP: 'top',\n CENTER: 'middle',\n BOTTOM: 'bottom'\n}\n\n/** A text layer's font and alignment as a label's style pairs. */\nfunction fontValues(text: SceneNode): Record<string, string | undefined> {\n const fill = text.fills.find((paint) => paint.visible && paint.type === 'SOLID')\n const bits =\n (text.fontWeight >= 600 ? 1 : 0) |\n (text.italic ? 2 : 0) |\n (text.textDecoration === 'UNDERLINE' ? 4 : 0)\n return {\n fontSize: String(text.fontSize),\n // The font draw.io's default stands for on import goes back as that default.\n fontFamily: text.fontFamily === DEFAULT_FONT_FAMILY ? undefined : text.fontFamily,\n fontColor: fill ? colorToHex(fill.color) : undefined,\n fontStyle: bits ? String(bits) : undefined,\n align: ALIGN[text.textAlignHorizontal],\n verticalAlign: VERTICAL_ALIGN[text.textAlignVertical]\n }\n}\n\n/**\n * A text layer's characters as an HTML label: each style run in a span that sets what it\n * changes, and a line break for each new line.\n */\nfunction labelHTML(text: SceneNode): string {\n const { text: characters, styleRuns } = text\n let html = ''\n let at = 0\n const plain = (to: number) => {\n html += escapeText(characters.slice(at, to)).replaceAll('\\n', '<br>')\n at = to\n }\n for (const run of [...styleRuns].sort((a, b) => a.start - b.start)) {\n plain(run.start)\n const css: string[] = []\n const { style: s } = run\n if (s.fontWeight !== undefined) css.push(`font-weight: ${s.fontWeight}`)\n if (s.italic !== undefined) css.push(`font-style: ${s.italic ? 'italic' : 'normal'}`)\n if (s.textDecoration)\n css.push(`text-decoration: ${s.textDecoration === 'UNDERLINE' ? 'underline' : 'none'}`)\n if (s.fontSize !== undefined) css.push(`font-size: ${s.fontSize}px`)\n if (s.fontFamily) css.push(`font-family: ${s.fontFamily}`)\n const fill = s.fills?.find((paint) => paint.type === 'SOLID')\n if (fill?.type === 'SOLID') css.push(`color: ${colorToHex(fill.color)}`)\n const inner = escapeText(characters.slice(run.start, run.start + run.length)).replaceAll(\n '\\n',\n '<br>'\n )\n html += css.length > 0 ? `<span style=\"${css.join('; ')}\">${inner}</span>` : inner\n at = run.start + run.length\n }\n plain(characters.length)\n return html\n}\n\n/** A connector line's colour, width, and dash as an edge's style pairs. */\nfunction lineValues(line: SceneNode): Record<string, string | undefined> {\n const stroke = line.strokes.find((paint) => paint.visible)\n const weight = stroke?.weight ?? 1\n const dash = stroke?.dashPattern ?? []\n return {\n strokeColor: stroke ? colorToHex(stroke.color) : 'none',\n strokeWidth: weight !== 1 ? String(weight) : undefined,\n dashed: dash.length > 0 ? '1' : undefined,\n dashPattern: dash.length > 0 ? dash.map((n) => round(n / weight)).join(' ') : undefined\n }\n}\n\n/** FigJam's ends and the draw.io arrowheads that draw them. */\nconst ARROWS: Record<StrokeCap, string> = {\n NONE: 'none',\n ROUND: 'none',\n SQUARE: 'none',\n ARROW_LINES: 'open',\n ARROW_EQUILATERAL: 'classic',\n TRIANGLE_FILLED: 'classic',\n DIAMOND_FILLED: 'diamond',\n CIRCLE_FILLED: 'oval'\n}\n\n/** Where a side magnet pins an end, as shares of the layer's box. */\nconst SIDE_POINTS: Partial<Record<ConnectorEndpoint['magnet'], [number, number]>> = {\n TOP: [0.5, 0],\n RIGHT: [1, 0.5],\n BOTTOM: [0.5, 1],\n LEFT: [0, 0.5]\n}\n\n/** Writes one page's layers as draw.io cells, in drawing order. */\nclass PageWriter {\n readonly cells: DrawIOCell[] = []\n private readonly ids = new Map<string, string>()\n /** Where each edge's line last ran from and to, in draw.io's axes. */\n private readonly drawnEnds = new Map<string, { start: DrawIOPoint; end: DrawIOPoint }>()\n /** Where each vertex's box starts on the page: draw.io measures its cells' boxes from there. */\n private readonly origins = new Map<string, Vector>([[LAYER_ID, { x: 0, y: 0 }]])\n private next = 2\n\n constructor(\n private readonly graph: SceneGraph,\n private readonly pageId: string\n ) {}\n\n private idOf(nodeId: string): string {\n let id = this.ids.get(nodeId)\n if (!id) {\n id = String(this.next++)\n this.ids.set(nodeId, id)\n }\n return id\n }\n\n write(nodeIds: readonly string[]) {\n // Every layer gets its id first, so an edge can name a layer drawn above it.\n const assign = (id: string) => {\n const node = this.graph.getNode(id)\n if (!node) return\n this.idOf(id)\n if (!isGeneratedFrame(node)) for (const child of node.childIds) assign(child)\n }\n // A layer inside another chosen one goes with it, as a cell of its own or drawn in its picture.\n const chosen = new Set(nodeIds)\n const roots = nodeIds.filter((id) => {\n const parentId = this.graph.getNode(id)?.parentId\n return !parentId || !this.graph.closest(parentId, (node) => chosen.has(node.id))\n })\n for (const id of roots) assign(id)\n for (const id of roots) {\n const node = this.graph.getNode(id)\n if (node) this.layer(node, LAYER_ID)\n }\n this.freeStrandedEnds()\n }\n\n /**\n * An edge end joined to a layer that has no cell, such as one left out of a selection or\n * drawn inside a picture, goes as a free point where the line last ran.\n */\n private freeStrandedEnds() {\n const written = new Set(this.cells.map((cell) => cell.id))\n for (const cell of this.cells) {\n const drawn = this.drawnEnds.get(cell.id)\n if (!drawn) continue\n if (!cell.source || !written.has(cell.source)) {\n cell.source = null\n cell.geometry.sourcePoint = drawn.start\n }\n if (!cell.target || !written.has(cell.target)) {\n cell.target = null\n cell.geometry.targetPoint = drawn.end\n }\n }\n }\n\n private push(\n node: SceneNode,\n parent: string,\n cell: Omit<DrawIOCell, 'id' | 'parent' | 'visible' | 'attributes' | 'source' | 'target'> &\n Partial<Pick<DrawIOCell, 'source' | 'target'>>\n ) {\n const id = this.idOf(node.id)\n if (cell.kind === 'vertex') {\n const from = this.originOf(parent)\n this.origins.set(id, { x: from.x + cell.geometry.x, y: from.y + cell.geometry.y })\n }\n this.cells.push({\n id,\n parent,\n visible: node.visible,\n attributes: {},\n source: null,\n target: null,\n ...cell\n })\n }\n\n private originOf(parent: string): Vector {\n return this.origins.get(parent) ?? { x: 0, y: 0 }\n }\n\n private place(node: SceneNode, parent: string): Placed {\n return placed(node, getWorldMatrix(node, this.graph), this.originOf(parent))\n }\n\n /** The box a layer covers on the page, square to it, in its parent cell's axes. */\n private bounds(node: SceneNode, parent: string): DrawIOGeometry {\n const bounds = computeContentBounds(this.graph, [node.id])\n if (!bounds) return this.place(node, parent).geometry\n const from = this.originOf(parent)\n return {\n ...EMPTY_GEOMETRY,\n x: round(bounds.minX - from.x),\n y: round(bounds.minY - from.y),\n width: round(bounds.maxX - bounds.minX),\n height: round(bounds.maxY - bounds.minY)\n }\n }\n\n private children(node: SceneNode) {\n for (const id of node.childIds) {\n const child = this.graph.getNode(id)\n if (child) this.layer(child, this.idOf(node.id))\n }\n }\n\n private layer(node: SceneNode, parent: string) {\n const placement = this.place(node, parent)\n const { geometry } = placement\n switch (node.type) {\n case 'SHAPE_WITH_TEXT':\n return this.shape(node, parent, placement)\n case 'TEXT':\n return this.push(node, parent, {\n kind: 'vertex',\n value: labelHTML(node),\n style: style(['text'], {\n html: '1',\n whiteSpace: 'wrap',\n ...nameValues(node),\n ...placedValues(placement),\n ...fontValues(node)\n }),\n geometry\n })\n case 'STICKY': {\n const body = stickySublayers(this.graph, node)?.body\n return this.push(node, parent, {\n kind: 'vertex',\n value: body ? labelHTML(body) : '',\n style: style([], {\n whiteSpace: 'wrap',\n html: '1',\n ...paintValues(node),\n strokeColor: 'none',\n align: 'left',\n verticalAlign: 'top',\n spacing: '20',\n ...placedValues(placement),\n fontSize: body ? String(body.fontSize) : undefined\n }),\n geometry\n })\n }\n case 'SECTION':\n this.push(node, parent, {\n kind: 'vertex',\n value: escapeText(node.name),\n style: style(['swimlane'], {\n html: '1',\n startSize: '30',\n ...paintValues(node),\n ...placedValues(placement)\n }),\n geometry\n })\n return this.children(node)\n case 'GROUP':\n this.push(node, parent, {\n kind: 'vertex',\n value: '',\n style: style(['group'], {}),\n // A group draws nothing, so it holds what it groups square to the page.\n geometry: this.bounds(node, parent)\n })\n return this.children(node)\n case 'FRAME':\n this.push(node, parent, {\n kind: 'vertex',\n value: '',\n style: style([], {\n container: '1',\n html: '1',\n ...nameValues(node),\n ...paintValues(node),\n ...placedValues(placement)\n }),\n geometry\n })\n return this.children(node)\n case 'RECTANGLE':\n case 'ELLIPSE':\n return this.push(node, parent, {\n kind: 'vertex',\n value: '',\n style: style(node.type === 'ELLIPSE' ? ['ellipse'] : [], {\n ...(node.type === 'RECTANGLE' ? { pairdrawType: 'RECTANGLE' } : {}),\n rounded: node.cornerRadius > 0 ? '1' : undefined,\n pairdrawCornerRadius: node.cornerRadius > 0 ? String(node.cornerRadius) : undefined,\n ...nameValues(node),\n ...placedValues(placement),\n ...paintValues(node)\n }),\n geometry\n })\n case 'CONNECTOR':\n return this.edge(node, parent)\n default:\n return this.picture(node, parent)\n }\n }\n\n private shape(node: SceneNode, parent: string, placement: Placed) {\n const label = shapeWithTextLabel(this.graph, node)\n const values: Record<string, string | undefined> = {\n ...drawioShapeValues(node.shapeWithTextType),\n ...nameValues(node),\n whiteSpace: 'wrap',\n html: '1',\n ...paintValues(node),\n ...(label ? fontValues(label) : {})\n }\n let { geometry, rotation } = placement\n // A triangle turned a quarter points the way draw.io's direction says, in the box it fills.\n const mirrored = placement.flipH || placement.flipV\n const quarter =\n !mirrored && Math.abs(rotation) === 90 && node.shapeWithTextType === 'TRIANGLE_UP'\n if (quarter) {\n values.direction = rotation === 90 ? 'east' : 'west'\n geometry = {\n ...geometry,\n x: round(geometry.x + (node.width - node.height) / 2),\n y: round(geometry.y + (node.height - node.width) / 2),\n width: round(node.height),\n height: round(node.width)\n }\n rotation = 0\n }\n // A shape that is draw.io's mirrored one, as a left parallelogram is, mirrors back if the layer is.\n const ownFlipH = values.flipH === '1'\n Object.assign(\n values,\n placedValues({ ...placement, rotation, flipH: placement.flipH !== ownFlipH })\n )\n this.push(node, parent, {\n kind: 'vertex',\n value: label ? labelHTML(label) : '',\n style: style([], values),\n geometry\n })\n }\n\n /** A layer draw.io has no cell for, drawn as the SVG image it exports as, where it covers. */\n private picture(node: SceneNode, parent: string) {\n const svg = renderNodesToSVG(this.graph, this.pageId, [node.id])\n if (!svg) return\n const data = fromUint8Array(new TextEncoder().encode(svg))\n this.push(node, parent, {\n kind: 'vertex',\n value: '',\n // draw.io keeps a data URI in its style without `;base64`, which would end the value.\n style: style([], { shape: 'image', image: `data:image/svg+xml,${data}`, aspect: 'fixed' }),\n geometry: this.bounds(node, parent)\n })\n }\n\n private end(\n endpoint: ConnectorEndpoint | null,\n prefix: 'exit' | 'entry'\n ): Record<string, string> {\n const node = endpoint?.nodeId ? this.graph.getNode(endpoint.nodeId) : undefined\n if (!endpoint || !node) return {}\n const side = SIDE_POINTS[endpoint.magnet]\n const point: [number, number] | null =\n side ??\n (endpoint.magnet === 'NONE' || endpoint.magnet === 'ABSOLUTE'\n ? [endpoint.position.x / (node.width || 1), endpoint.position.y / (node.height || 1)]\n : null)\n if (!point) return {}\n return { [`${prefix}X`]: String(round(point[0])), [`${prefix}Y`]: String(round(point[1])) }\n }\n\n /**\n * Where an edge's free ends sit, its bend points, and its label's place along it, with the\n * points carried into draw.io's axes.\n */\n private edgeGeometry(node: SceneNode, parent: string): DrawIOGeometry {\n const toPage = getParentWorldMatrix(\n node.parentId ? this.graph.getNode(node.parentId) : undefined,\n this.graph\n )\n const from = this.originOf(parent)\n const at = (point: Vector) => {\n const mapped = Matrix.mapPoint(toPage, point)\n return { x: round(mapped.x - from.x), y: round(mapped.y - from.y) }\n }\n const drawn = connectorRouteEnds(this.graph, node)\n if (drawn) {\n this.drawnEnds.set(this.idOf(node.id), { start: at(drawn.start), end: at(drawn.end) })\n }\n const position = node.connectorLabelPosition\n const along = position?.section === 'MIDDLE_TO_START' ? -position.offset : position?.offset\n return {\n ...EMPTY_GEOMETRY,\n relative: true,\n x: round(along ?? 0),\n sourcePoint: !node.connectorStart?.nodeId && drawn ? at(drawn.start) : null,\n targetPoint: !node.connectorEnd?.nodeId && drawn ? at(drawn.end) : null,\n points: this.waypoints(node).map(at)\n }\n }\n\n private edge(node: SceneNode, parent: string) {\n // A connector without its line and label is not one draw.io could draw.\n const parts = connectorSublayers(this.graph, node)\n if (!parts) return\n const startId = node.connectorStart?.nodeId\n const endId = node.connectorEnd?.nodeId\n const lineType = node.connectorLineType\n this.push(node, parent, {\n kind: 'edge',\n value: parts.label.text ? labelHTML(parts.label) : '',\n style: style([], {\n edgeStyle: lineType === 'ELBOWED' ? 'orthogonalEdgeStyle' : undefined,\n rounded: lineType === 'ELBOWED' ? '1' : undefined,\n curved: lineType === 'CURVED' ? '1' : undefined,\n html: '1',\n startArrow: ARROWS[node.connectorStartCap],\n endArrow: ARROWS[node.connectorEndCap],\n ...lineValues(parts.line),\n ...this.end(node.connectorStart, 'exit'),\n ...this.end(node.connectorEnd, 'entry'),\n ...fontValues(parts.label)\n }),\n geometry: this.edgeGeometry(node, parent),\n source: startId ? (this.ids.get(startId) ?? null) : null,\n target: endId ? (this.ids.get(endId) ?? null) : null\n })\n }\n\n /**\n * The points a dragged connector bends through, for draw.io to run its edge the same way: an\n * elbow's corners, or the middle of a curve. A connector routing itself leaves draw.io to route.\n */\n private waypoints(node: SceneNode): Vector[] {\n const route = connectorRoute(this.graph, node)\n if (!route) return []\n if (node.connectorLineType === 'CURVED' && node.connectorCurveHandles) {\n const curve = route.pieces.at(0)\n return curve ? [curveMidpoint(curve)] : []\n }\n if (node.connectorLineType !== 'ELBOWED' || node.connectorControlPoints.length === 0) return []\n return route.pieces.slice(0, -1).map((piece) => piece.to)\n }\n}\n\n/** One page of layers as a draw.io page, holding `nodeIds` or every layer on it. */\nfunction pageOf(graph: SceneGraph, pageId: string, nodeIds?: readonly string[]): DrawIOPage {\n const page = graph.getNode(pageId)\n const writer = new PageWriter(graph, pageId)\n writer.write(nodeIds ?? page?.childIds ?? [])\n return {\n id: pageId,\n name: page?.name ?? 'Page',\n attributes: { grid: '1', gridSize: '10' },\n rootId: ROOT_ID,\n layers: [{ id: LAYER_ID, name: '', visible: true, locked: false }],\n cells: writer.cells\n }\n}\n\n/** What a draw.io export holds: whole pages, or some layers of one page. */\nexport type DrawIOExportTarget =\n | { pageIds: readonly string[] }\n | { pageId: string; nodeIds: readonly string[] }\n\n/**\n * Layers as a draw.io file: FigJam shapes as draw.io's shapes of the same meaning, connectors as\n * edges joined to them, bent the way they were dragged, text as text, sections as swimlanes, and\n * frames and groups as containers. A layer draw.io has no cell for goes as an SVG image of\n * itself, so nothing is lost.\n */\nexport function sceneGraphToDrawIO(graph: SceneGraph, target: DrawIOExportTarget): DrawIOFile {\n const pages =\n 'pageIds' in target\n ? target.pageIds.map((pageId) => pageOf(graph, pageId))\n : [pageOf(graph, target.pageId, target.nodeIds)]\n return { pages, unreadable: [] }\n}\n"],"mappings":";;;;;;;;;;;;;;AAoCA,MAAM,UAAU;AAChB,MAAM,WAAW;AAEjB,SAAS,MAAM,OAAiB,QAAyD;CACvF,OAAO;EACL;EACA,QAAQ,OAAO,YAAY,OAAO,QAAQ,MAAM,CAAC,CAAC,QAAQ,GAAG,OAAO,MAAM,KAAA,CAAS,CAAC;CACtF;AACF;;AAGA,SAAS,WAAW,MAAyC;CAC3D,OAAO,EAAE,cAAc,mBAAmB,KAAK,IAAI,EAAE;AACvD;;AAGA,SAAS,UAAU,MAAyB;CAC1C,MAAM,OAAO,KAAK,MAAM,MAAM,UAAU,MAAM,OAAO;CACrD,IAAI,CAAC,MAAM,OAAO;CAClB,IAAI,KAAK,SAAS,SAAS,OAAO,WAAW,KAAK,KAAK;CACvD,MAAM,OAAO,KAAK,eAAe,GAAG,CAAC;CACrC,OAAO,OAAO,WAAW,KAAK,KAAK,IAAI;AACzC;;AAGA,SAAS,YAAY,MAAqD;CACxE,MAAM,SAAS,KAAK,QAAQ,MAAM,UAAU,M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MAA2B;EAC3C,MAAM,QAAQ,eAAe,KAAK,OAAO,IAAI;EAC7C,IAAI,CAAC,OAAO,OAAO,CAAC;EACpB,IAAI,KAAK,sBAAsB,YAAY,KAAK,uBAAuB;GACrE,MAAM,QAAQ,MAAM,OAAO,GAAG,CAAC;GAC/B,OAAO,QAAQ,CAAC,cAAc,KAAK,CAAC,IAAI,CAAC;EAC3C;EACA,IAAI,KAAK,sBAAsB,aAAa,KAAK,uBAAuB,WAAW,GAAG,OAAO,CAAC;EAC9F,OAAO,MAAM,OAAO,MAAM,GAAG,EAAE,CAAC,CAAC,KAAK,UAAU,MAAM,EAAE;CAC1D;AACF;;AAGA,SAAS,OAAO,OAAmB,QAAgB,SAAyC;CAC1F,MAAM,OAAO,MAAM,QAAQ,MAAM;CACjC,MAAM,SAAS,IAAI,WAAW,OAAO,MAAM;CAC3C,OAAO,MAAM,WAAW,MAAM,YAAY,CAAC,CAAC;CAC5C,OAAO;EACL,IAAI;EACJ,MAAM,MAAM,QAAQ;EACpB,YAAY;GAAE,MAAM;GAAK,UAAU;EAAK;EACxC,QAAQ;EACR,QAAQ,CAAC;GAAE,IAAI;GAAU,MAAM;GAAI,SAAS;GAAM,QAAQ;EAAM,CAAC;EACjE,OAAO,OAAO;CAChB;AACF;;;;;;;AAaA,SAAgB,mBAAmB,OAAmB,QAAwC;CAK5F,OAAO;EAAE,OAHP,aAAa,SACT,OAAO,QAAQ,KAAK,WAAW,OAAO,OAAO,MAAM,CAAC,IACpD,CAAC,OAAO,OAAO,OAAO,QAAQ,OAAO,OAAO,CAAC;EACnC,YAAY,CAAC;CAAE;AACjC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/io/formats/drawio/index.ts"],"mappings":";;;;;;;;;iBA+LgB,mBAAmB,MAAM,aAAa"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/io/formats/drawio/index.ts"],"mappings":";;;;;;;;;iBAkOgB,mBAAmB,MAAM,aAAa"}
@@ -36,6 +36,23 @@ function placementOf(style, ownFlipH = false) {
36
36
  function nameOf(text, fallback) {
37
37
  return text.split("\n")[0]?.trim() || fallback;
38
38
  }
39
+ /**
40
+ * The name Pairdraw wrote into a cell's style. draw.io has no field of its own for a layer whose
41
+ * cell draws no text, and a text cell's label is its content, so the name travels beside them.
42
+ */
43
+ function writtenName(style) {
44
+ const value = style.values.pairdrawName;
45
+ if (value === void 0) return void 0;
46
+ try {
47
+ return decodeURIComponent(value);
48
+ } catch {
49
+ return;
50
+ }
51
+ }
52
+ /** A layer's name: the one Pairdraw wrote, else the first line of its label. */
53
+ function layerName(style, text, fallback) {
54
+ return writtenName(style) ?? nameOf(text, fallback);
55
+ }
39
56
  /** Builds one draw.io page's cells into `pageId`, in draw.io's drawing order. */
40
57
  var PageBuilder = class {
41
58
  graph;
@@ -110,12 +127,26 @@ var PageBuilder = class {
110
127
  if (kind.type === "TEXT") return graph.createNode("TEXT", parentId, {
111
128
  ...box,
112
129
  ...placementOf(cell.style),
113
- name: nameOf(label.text, "Text"),
130
+ name: layerName(cell.style, label.text, "Text"),
114
131
  ...labelFields(cell.style, label.format),
115
132
  text: label.text,
116
133
  styleRuns: label.runs,
117
134
  textAutoResize: "NONE"
118
135
  });
136
+ if (kind.type === "FRAME") return graph.createNode("FRAME", parentId, {
137
+ ...box,
138
+ ...shapePaint(cell.style),
139
+ name: layerName(cell.style, label.text, "Frame")
140
+ });
141
+ if (kind.type === "RECTANGLE") {
142
+ const radius = Number.parseFloat(cell.style.values.pairdrawCornerRadius ?? "");
143
+ return graph.createNode("RECTANGLE", parentId, {
144
+ ...box,
145
+ ...shapePaint(cell.style),
146
+ ...radius > 0 ? { cornerRadius: radius } : {},
147
+ name: layerName(cell.style, label.text, "Rectangle")
148
+ });
149
+ }
119
150
  if (kind.type === "SECTION") return graph.createNode("SECTION", parentId, {
120
151
  ...box,
121
152
  ...shapePaint(cell.style),
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../src/io/formats/drawio/index.ts"],"sourcesContent":["import type { DrawIOCell, DrawIOFile, DrawIOPage, DrawIOStyle } from '@pairdraw/drawio'\nimport { SceneGraph, type SceneNode } from '@pairdraw/scene-graph'\nimport { connectorRoute, placeConnectorLabel } from '@pairdraw/scene-graph/connectors'\nimport { createShapeWithText } from '@pairdraw/scene-graph/generated'\nimport { fitEnclosingGroups } from '@pairdraw/scene-graph/group-bounds'\n\nimport { bindEdge, createEdge, labelPositionOf, type PendingEdge } from './edges'\nimport { readLabel } from './label'\nimport { labelFields, labelFormat, shapePaint } from './paint'\nimport { shapeName, vertexKind } from './shapes'\n\n/** A cell's label as text and runs, in the cell's own style. */\nfunction labelOf(cell: DrawIOCell) {\n const format = labelFormat(cell.style)\n return { format, ...readLabel(cell.value, cell.style.values.html === '1', format) }\n}\n\n/**\n * A cell's turn and mirrors as a layer's. draw.io mirrors a cell about its centre and then turns\n * it, negating the turn when it mirrors one way only; a layer turns and then mirrors, so that\n * turn is the layer's own. `ownFlipH` is a mirror the shape itself stands for, as a left\n * parallelogram is draw.io's mirrored one.\n */\nfunction placementOf(style: DrawIOStyle, ownFlipH = false) {\n const flipX = style.values.flipH === '1' && !ownFlipH\n const flipY = style.values.flipV === '1'\n const turn = Number(style.values.rotation ?? 0) || 0\n return { flipX, flipY, rotation: flipX === flipY ? turn : -turn }\n}\n\n/** The first line of a label, as a layer's name. */\nfunction nameOf(text: string, fallback: string): string {\n return text.split('\\n')[0]?.trim() || fallback\n}\n\n/** Builds one draw.io page's cells into `pageId`, in draw.io's drawing order. */\nclass PageBuilder {\n /** The layer each draw.io cell or layer became. */\n private readonly layers = new Map<string, string>()\n private readonly edges: PendingEdge[] = []\n private readonly groups: string[] = []\n\n constructor(\n private readonly graph: SceneGraph,\n private readonly page: DrawIOPage,\n private readonly pageId: string\n ) {}\n\n build() {\n const { graph, page, pageId } = this\n // One layer draws straight onto the page; several each become a group named after it, as\n // does a single layer that is hidden or locked, so it stays so.\n for (const [index, layer] of page.layers.entries()) {\n if (page.layers.length === 1 && layer.visible && !layer.locked) {\n this.layers.set(layer.id, pageId)\n continue\n }\n const group = graph.createNode('GROUP', pageId, {\n name: layer.name || `Layer ${index + 1}`,\n visible: layer.visible,\n locked: layer.locked\n })\n this.layers.set(layer.id, group.id)\n this.groups.push(group.id)\n }\n const parents = new Set(page.cells.map((cell) => cell.parent))\n const labelsOf = new Map<string, DrawIOCell[]>()\n const edgeIds = new Set(\n page.cells.filter((cell) => cell.kind === 'edge').map((cell) => cell.id)\n )\n for (const cell of page.cells) {\n // A vertex inside an edge is one of its labels.\n if (edgeIds.has(cell.parent)) {\n const labels = labelsOf.get(cell.parent) ?? []\n labels.push(cell)\n labelsOf.set(cell.parent, labels)\n }\n }\n const cells = new Map(page.cells.map((cell) => [cell.id, cell]))\n const placing = new Set<string>()\n const place = (cell: DrawIOCell) => {\n if (edgeIds.has(cell.parent) || this.layers.has(cell.id) || placing.has(cell.id)) return\n placing.add(cell.id)\n // A cell listed before its parent, as draw.io's format allows, waits for the parent.\n const parent = cells.get(cell.parent)\n if (parent) place(parent)\n const parentId = this.layers.get(cell.parent) ?? pageId\n if (cell.kind === 'edge') {\n const pending = createEdge(graph, parentId, cell, labelsOf.get(cell.id) ?? [])\n this.layers.set(cell.id, pending.connector.id)\n this.edges.push(pending)\n return\n }\n const node = this.vertex(cell, parentId, parents.has(cell.id))\n this.layers.set(cell.id, node.id)\n }\n for (const cell of page.cells) place(cell)\n const layerOf = (cellId: string) => this.layers.get(cellId)\n for (const pending of this.edges) {\n for (const extra of bindEdge(graph, pending, layerOf)) this.edgeText(pending, extra)\n }\n // Groups fit around what they hold, the innermost first.\n for (const id of this.groups.toReversed()) fitEnclosingGroups(graph, [id])\n }\n\n private vertex(cell: DrawIOCell, parentId: string, hasChildren: boolean): SceneNode {\n const { graph } = this\n const { x, y, width, height } = cell.geometry\n const kind = vertexKind(cell.style, hasChildren)\n const label = labelOf(cell)\n const box = { x, y, width, height, visible: cell.visible }\n if (kind.type === 'TEXT') {\n return graph.createNode('TEXT', parentId, {\n ...box,\n ...placementOf(cell.style),\n name: nameOf(label.text, 'Text'),\n ...labelFields(cell.style, label.format),\n text: label.text,\n styleRuns: label.runs,\n textAutoResize: 'NONE'\n })\n }\n if (kind.type === 'SECTION') {\n return graph.createNode('SECTION', parentId, {\n ...box,\n ...shapePaint(cell.style),\n name: nameOf(label.text, 'Section')\n })\n }\n if (kind.type === 'GROUP') {\n const group = graph.createNode('GROUP', parentId, {\n ...box,\n name: nameOf(label.text, 'Group')\n })\n this.groups.push(group.id)\n return group\n }\n // A shape turned a quarter swaps its sides, about the centre of the box it fills.\n const quarter = Math.abs(kind.rotation) === 90\n const placed = quarter\n ? { x: x + (width - height) / 2, y: y + (height - width) / 2, width: height, height: width }\n : { x, y, width, height }\n const known = shapeName(cell.style)\n const own = placementOf(cell.style, kind.shape === 'PARALLELOGRAM_LEFT')\n return createShapeWithText(\n graph,\n parentId,\n {\n ...placed,\n visible: cell.visible,\n ...own,\n rotation: own.rotation + kind.rotation,\n shapeWithTextType: kind.shape,\n // draw.io sized it, so it keeps its size, as a FigJam shape whose height was set does.\n shapeTruncates: true,\n ...shapePaint(cell.style),\n // A stencil FigJam has no shape for keeps its name, so it can be found and replaced.\n name: kind.stencil ? known : nameOf(label.text, 'Shape with text')\n },\n { ...labelFields(cell.style, label.format), text: label.text, styleRuns: label.runs }\n )\n }\n\n /** A label beyond an edge's first, as text where draw.io placed it along the edge. */\n private edgeText({ connector }: PendingEdge, cell: DrawIOCell) {\n const { graph } = this\n const node = graph.getNode(connector.id)\n const route = node ? connectorRoute(graph, node) : null\n if (!node?.parentId || !route) return\n const label = labelOf(cell)\n const size = { width: cell.geometry.width, height: cell.geometry.height }\n const plate = placeConnectorLabel(route.pieces, size, labelPositionOf(cell.geometry.x))?.plate\n const offset = cell.geometry.offset ?? { x: 0, y: 0 }\n graph.createNode('TEXT', node.parentId, {\n x: (plate?.x ?? 0) + offset.x,\n y: (plate?.y ?? 0) + offset.y,\n visible: cell.visible,\n name: nameOf(label.text, 'Text'),\n ...labelFields(cell.style, label.format),\n text: label.text,\n styleRuns: label.runs,\n textAutoResize: 'WIDTH_AND_HEIGHT'\n })\n }\n}\n\n/**\n * A draw.io file as layers: each page a page, its shapes FigJam shapes with text, its edges\n * connectors joined to them, its layers groups when there are several, in draw.io's drawing order.\n * Text sizes are left for layout, which measures them once fonts load.\n */\nexport function drawioToSceneGraph(file: DrawIOFile): SceneGraph {\n const graph = new SceneGraph()\n const first = graph.getPages().at(0)\n for (const [index, page] of file.pages.entries()) {\n const pageNode = index === 0 && first ? first : graph.addPage(page.name)\n if (index === 0) graph.updateNode(pageNode.id, { name: page.name })\n new PageBuilder(graph, page, pageNode.id).build()\n }\n return graph\n}\n\nexport { sceneGraphToDrawIO } from './export'\n"],"mappings":";;;;;;;;;;;AAYA,SAAS,QAAQ,MAAkB;CACjC,MAAM,SAAS,YAAY,KAAK,KAAK;CACrC,OAAO;EAAE;EAAQ,GAAG,UAAU,KAAK,OAAO,KAAK,MAAM,OAAO,SAAS,KAAK,MAAM;CAAE;AACpF;;;;;;;AAQA,SAAS,YAAY,OAAoB,WAAW,OAAO;CACzD,MAAM,QAAQ,MAAM,OAAO,UAAU,OAAO,CAAC;CAC7C,MAAM,QAAQ,MAAM,OAAO,UAAU;CACrC,MAAM,OAAO,OAAO,MAAM,OAAO,YAAY,CAAC,KAAK;CACnD,OAAO;EAAE;EAAO;EAAO,UAAU,UAAU,QAAQ,OAAO,CAAC;CAAK;AAClE;;AAGA,SAAS,OAAO,MAAc,UAA0B;CACtD,OAAO,KAAK,MAAM,IAAI,CAAC,CAAC,EAAE,EAAE,KAAK,KAAK;AACxC;;AAGA,IAAM,cAAN,MAAkB;CAOG;CACA;CACA;;CAPnB,yBAA0B,IAAI,IAAoB;CAClD,QAAwC,CAAC;CACzC,SAAoC,CAAC;CAErC,YACE,OACA,MACA,QACA;EAHiB,KAAA,QAAA;EACA,KAAA,OAAA;EACA,K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,QAAQ,oBAAoB,MAAM,QAAQ,MAAM,gBAAgB,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE;EACzF,MAAM,SAAS,KAAK,SAAS,UAAU;GAAE,GAAG;GAAG,GAAG;EAAE;EACpD,MAAM,WAAW,QAAQ,KAAK,UAAU;GACtC,IAAI,OAAO,KAAK,KAAK,OAAO;GAC5B,IAAI,OAAO,KAAK,KAAK,OAAO;GAC5B,SAAS,KAAK;GACd,MAAM,OAAO,MAAM,MAAM,MAAM;GAC/B,GAAG,YAAY,KAAK,OAAO,MAAM,MAAM;GACvC,MAAM,MAAM;GACZ,WAAW,MAAM;GACjB,gBAAgB;EAClB,CAAC;CACH;AACF;;;;;;AAOA,SAAgB,mBAAmB,MAA8B;CAC/D,MAAM,QAAQ,IAAI,WAAW;CAC7B,MAAM,QAAQ,MAAM,SAAS,CAAC,CAAC,GAAG,CAAC;CACnC,KAAK,MAAM,CAAC,OAAO,SAAS,KAAK,MAAM,QAAQ,GAAG;EAChD,MAAM,WAAW,UAAU,KAAK,QAAQ,QAAQ,MAAM,QAAQ,KAAK,IAAI;EACvE,IAAI,UAAU,GAAG,MAAM,WAAW,SAAS,IAAI,EAAE,MAAM,KAAK,KAAK,CAAC;EAClE,IAAI,YAAY,OAAO,MAAM,SAAS,EAAE,CAAC,CAAC,MAAM;CAClD;CACA,OAAO;AACT"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../src/io/formats/drawio/index.ts"],"sourcesContent":["import type { DrawIOCell, DrawIOFile, DrawIOPage, DrawIOStyle } from '@pairdraw/drawio'\nimport { SceneGraph, type SceneNode } from '@pairdraw/scene-graph'\nimport { connectorRoute, placeConnectorLabel } from '@pairdraw/scene-graph/connectors'\nimport { createShapeWithText } from '@pairdraw/scene-graph/generated'\nimport { fitEnclosingGroups } from '@pairdraw/scene-graph/group-bounds'\n\nimport { bindEdge, createEdge, labelPositionOf, type PendingEdge } from './edges'\nimport { readLabel } from './label'\nimport { labelFields, labelFormat, shapePaint } from './paint'\nimport { shapeName, vertexKind } from './shapes'\n\n/** A cell's label as text and runs, in the cell's own style. */\nfunction labelOf(cell: DrawIOCell) {\n const format = labelFormat(cell.style)\n return { format, ...readLabel(cell.value, cell.style.values.html === '1', format) }\n}\n\n/**\n * A cell's turn and mirrors as a layer's. draw.io mirrors a cell about its centre and then turns\n * it, negating the turn when it mirrors one way only; a layer turns and then mirrors, so that\n * turn is the layer's own. `ownFlipH` is a mirror the shape itself stands for, as a left\n * parallelogram is draw.io's mirrored one.\n */\nfunction placementOf(style: DrawIOStyle, ownFlipH = false) {\n const flipX = style.values.flipH === '1' && !ownFlipH\n const flipY = style.values.flipV === '1'\n const turn = Number(style.values.rotation ?? 0) || 0\n return { flipX, flipY, rotation: flipX === flipY ? turn : -turn }\n}\n\n/** The first line of a label, as a layer's name. */\nfunction nameOf(text: string, fallback: string): string {\n return text.split('\\n')[0]?.trim() || fallback\n}\n\n/**\n * The name Pairdraw wrote into a cell's style. draw.io has no field of its own for a layer whose\n * cell draws no text, and a text cell's label is its content, so the name travels beside them.\n */\nfunction writtenName(style: DrawIOStyle): string | undefined {\n const value = style.values.pairdrawName\n if (value === undefined) return undefined\n try {\n return decodeURIComponent(value)\n } catch {\n return undefined\n }\n}\n\n/** A layer's name: the one Pairdraw wrote, else the first line of its label. */\nfunction layerName(style: DrawIOStyle, text: string, fallback: string): string {\n return writtenName(style) ?? nameOf(text, fallback)\n}\n\n/** Builds one draw.io page's cells into `pageId`, in draw.io's drawing order. */\nclass PageBuilder {\n /** The layer each draw.io cell or layer became. */\n private readonly layers = new Map<string, string>()\n private readonly edges: PendingEdge[] = []\n private readonly groups: string[] = []\n\n constructor(\n private readonly graph: SceneGraph,\n private readonly page: DrawIOPage,\n private readonly pageId: string\n ) {}\n\n build() {\n const { graph, page, pageId } = this\n // One layer draws straight onto the page; several each become a group named after it, as\n // does a single layer that is hidden or locked, so it stays so.\n for (const [index, layer] of page.layers.entries()) {\n if (page.layers.length === 1 && layer.visible && !layer.locked) {\n this.layers.set(layer.id, pageId)\n continue\n }\n const group = graph.createNode('GROUP', pageId, {\n name: layer.name || `Layer ${index + 1}`,\n visible: layer.visible,\n locked: layer.locked\n })\n this.layers.set(layer.id, group.id)\n this.groups.push(group.id)\n }\n const parents = new Set(page.cells.map((cell) => cell.parent))\n const labelsOf = new Map<string, DrawIOCell[]>()\n const edgeIds = new Set(\n page.cells.filter((cell) => cell.kind === 'edge').map((cell) => cell.id)\n )\n for (const cell of page.cells) {\n // A vertex inside an edge is one of its labels.\n if (edgeIds.has(cell.parent)) {\n const labels = labelsOf.get(cell.parent) ?? []\n labels.push(cell)\n labelsOf.set(cell.parent, labels)\n }\n }\n const cells = new Map(page.cells.map((cell) => [cell.id, cell]))\n const placing = new Set<string>()\n const place = (cell: DrawIOCell) => {\n if (edgeIds.has(cell.parent) || this.layers.has(cell.id) || placing.has(cell.id)) return\n placing.add(cell.id)\n // A cell listed before its parent, as draw.io's format allows, waits for the parent.\n const parent = cells.get(cell.parent)\n if (parent) place(parent)\n const parentId = this.layers.get(cell.parent) ?? pageId\n if (cell.kind === 'edge') {\n const pending = createEdge(graph, parentId, cell, labelsOf.get(cell.id) ?? [])\n this.layers.set(cell.id, pending.connector.id)\n this.edges.push(pending)\n return\n }\n const node = this.vertex(cell, parentId, parents.has(cell.id))\n this.layers.set(cell.id, node.id)\n }\n for (const cell of page.cells) place(cell)\n const layerOf = (cellId: string) => this.layers.get(cellId)\n for (const pending of this.edges) {\n for (const extra of bindEdge(graph, pending, layerOf)) this.edgeText(pending, extra)\n }\n // Groups fit around what they hold, the innermost first.\n for (const id of this.groups.toReversed()) fitEnclosingGroups(graph, [id])\n }\n\n private vertex(cell: DrawIOCell, parentId: string, hasChildren: boolean): SceneNode {\n const { graph } = this\n const { x, y, width, height } = cell.geometry\n const kind = vertexKind(cell.style, hasChildren)\n const label = labelOf(cell)\n const box = { x, y, width, height, visible: cell.visible }\n if (kind.type === 'TEXT') {\n return graph.createNode('TEXT', parentId, {\n ...box,\n ...placementOf(cell.style),\n name: layerName(cell.style, label.text, 'Text'),\n ...labelFields(cell.style, label.format),\n text: label.text,\n styleRuns: label.runs,\n textAutoResize: 'NONE'\n })\n }\n if (kind.type === 'FRAME') {\n return graph.createNode('FRAME', parentId, {\n ...box,\n ...shapePaint(cell.style),\n name: layerName(cell.style, label.text, 'Frame')\n })\n }\n if (kind.type === 'RECTANGLE') {\n const radius = Number.parseFloat(cell.style.values.pairdrawCornerRadius ?? '')\n return graph.createNode('RECTANGLE', parentId, {\n ...box,\n ...shapePaint(cell.style),\n ...(radius > 0 ? { cornerRadius: radius } : {}),\n name: layerName(cell.style, label.text, 'Rectangle')\n })\n }\n if (kind.type === 'SECTION') {\n return graph.createNode('SECTION', parentId, {\n ...box,\n ...shapePaint(cell.style),\n name: nameOf(label.text, 'Section')\n })\n }\n if (kind.type === 'GROUP') {\n const group = graph.createNode('GROUP', parentId, {\n ...box,\n name: nameOf(label.text, 'Group')\n })\n this.groups.push(group.id)\n return group\n }\n // A shape turned a quarter swaps its sides, about the centre of the box it fills.\n const quarter = Math.abs(kind.rotation) === 90\n const placed = quarter\n ? { x: x + (width - height) / 2, y: y + (height - width) / 2, width: height, height: width }\n : { x, y, width, height }\n const known = shapeName(cell.style)\n const own = placementOf(cell.style, kind.shape === 'PARALLELOGRAM_LEFT')\n return createShapeWithText(\n graph,\n parentId,\n {\n ...placed,\n visible: cell.visible,\n ...own,\n rotation: own.rotation + kind.rotation,\n shapeWithTextType: kind.shape,\n // draw.io sized it, so it keeps its size, as a FigJam shape whose height was set does.\n shapeTruncates: true,\n ...shapePaint(cell.style),\n // A stencil FigJam has no shape for keeps its name, so it can be found and replaced.\n name: kind.stencil ? known : nameOf(label.text, 'Shape with text')\n },\n { ...labelFields(cell.style, label.format), text: label.text, styleRuns: label.runs }\n )\n }\n\n /** A label beyond an edge's first, as text where draw.io placed it along the edge. */\n private edgeText({ connector }: PendingEdge, cell: DrawIOCell) {\n const { graph } = this\n const node = graph.getNode(connector.id)\n const route = node ? connectorRoute(graph, node) : null\n if (!node?.parentId || !route) return\n const label = labelOf(cell)\n const size = { width: cell.geometry.width, height: cell.geometry.height }\n const plate = placeConnectorLabel(route.pieces, size, labelPositionOf(cell.geometry.x))?.plate\n const offset = cell.geometry.offset ?? { x: 0, y: 0 }\n graph.createNode('TEXT', node.parentId, {\n x: (plate?.x ?? 0) + offset.x,\n y: (plate?.y ?? 0) + offset.y,\n visible: cell.visible,\n name: nameOf(label.text, 'Text'),\n ...labelFields(cell.style, label.format),\n text: label.text,\n styleRuns: label.runs,\n textAutoResize: 'WIDTH_AND_HEIGHT'\n })\n }\n}\n\n/**\n * A draw.io file as layers: each page a page, its shapes FigJam shapes with text, its edges\n * connectors joined to them, its layers groups when there are several, in draw.io's drawing order.\n * Text sizes are left for layout, which measures them once fonts load.\n */\nexport function drawioToSceneGraph(file: DrawIOFile): SceneGraph {\n const graph = new SceneGraph()\n const first = graph.getPages().at(0)\n for (const [index, page] of file.pages.entries()) {\n const pageNode = index === 0 && first ? first : graph.addPage(page.name)\n if (index === 0) graph.updateNode(pageNode.id, { name: page.name })\n new PageBuilder(graph, page, pageNode.id).build()\n }\n return graph\n}\n\nexport { sceneGraphToDrawIO } from './export'\n"],"mappings":";;;;;;;;;;;AAYA,SAAS,QAAQ,MAAkB;CACjC,MAAM,SAAS,YAAY,KAAK,KAAK;CACrC,OAAO;EAAE;EAAQ,GAAG,UAAU,KAAK,OAAO,KAAK,MAAM,OAAO,SAAS,KAAK,MAAM;CAAE;AACpF;;;;;;;AAQA,SAAS,YAAY,OAAoB,WAAW,OAAO;CACzD,MAAM,QAAQ,MAAM,OAAO,UAAU,OAAO,CAAC;CAC7C,MAAM,QAAQ,MAAM,OAAO,UAAU;CACrC,MAAM,OAAO,OAAO,MAAM,OAAO,YAAY,CAAC,KAAK;CACnD,OAAO;EAAE;EAAO;EAAO,UAAU,UAAU,QAAQ,OAAO,CAAC;CAAK;AAClE;;AAGA,SAAS,OAAO,MAAc,U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K,KAAK,OAAO;GAC5B,SAAS,KAAK;GACd,MAAM,OAAO,MAAM,MAAM,MAAM;GAC/B,GAAG,YAAY,KAAK,OAAO,MAAM,MAAM;GACvC,MAAM,MAAM;GACZ,WAAW,MAAM;GACjB,gBAAgB;EAClB,CAAC;CACH;AACF;;;;;;AAOA,SAAgB,mBAAmB,MAA8B;CAC/D,MAAM,QAAQ,IAAI,WAAW;CAC7B,MAAM,QAAQ,MAAM,SAAS,CAAC,CAAC,GAAG,CAAC;CACnC,KAAK,MAAM,CAAC,OAAO,SAAS,KAAK,MAAM,QAAQ,GAAG;EAChD,MAAM,WAAW,UAAU,KAAK,QAAQ,QAAQ,MAAM,QAAQ,KAAK,IAAI;EACvE,IAAI,UAAU,GAAG,MAAM,WAAW,SAAS,IAAI,EAAE,MAAM,KAAK,KAAK,CAAC;EAClE,IAAI,YAAY,OAAO,MAAM,SAAS,EAAE,CAAC,CAAC,MAAM;CAClD;CACA,OAAO;AACT"}
@@ -1,7 +1,7 @@
1
1
  import { ShapeWithTextType } from "@pairdraw/scene-graph/shape-with-text";
2
2
  import { DrawIOStyle } from "@pairdraw/drawio";
3
3
  //#region src/io/formats/drawio/shapes.d.ts
4
- /** What a draw.io vertex becomes: a FigJam shape, text, a section around its cells, or a group. */
4
+ /** What a draw.io vertex becomes: a shape, text, a frame or section around its cells, or a group. */
5
5
  type VertexKind =
6
6
  /** A FigJam shape, turned clockwise by `rotation` degrees about its centre. */
7
7
  {
@@ -11,18 +11,23 @@ type VertexKind =
11
11
  stencil: boolean;
12
12
  } | {
13
13
  type: 'TEXT';
14
+ } | {
15
+ type: 'FRAME';
14
16
  } | {
15
17
  type: 'SECTION';
18
+ } | {
19
+ type: 'RECTANGLE';
16
20
  } | {
17
21
  type: 'GROUP';
18
22
  };
19
23
  /** The shape a style draws: its `shape`, else the stylesheet style it names, else a rectangle. */
20
24
  declare function shapeName(style: DrawIOStyle): string;
21
25
  /**
22
- * What a vertex becomes. Text stays text; a swimlane, or a vertex its style makes a container,
23
- * becomes a section holding its cells; a group stays a group. A shape draw.io turns by
24
- * `direction` keeps its turn. Any other shape, a stencil FigJam has no shape for among them,
25
- * becomes a rectangle, named after the stencil so it can be found.
26
+ * What a vertex becomes. Text stays text; a swimlane becomes a section holding its cells, and
27
+ * any other vertex its style makes a container becomes a frame, as Pairdraw writes one; a group
28
+ * stays a group. A style Pairdraw wrote says when it drew a rectangle, which draw.io has no
29
+ * style of its own for. A shape draw.io turns by `direction` keeps its turn. Any other shape, a
30
+ * stencil FigJam has no shape for among them, becomes a shape named after the stencil.
26
31
  */
27
32
  declare function vertexKind(style: DrawIOStyle, hasChildren: boolean): VertexKind;
28
33
  declare function drawioShapeValues(shape: ShapeWithTextType): Record<string, string>;
@@ -1 +1 @@
1
- {"version":3,"file":"shapes.d.ts","names":[],"sources":["../../../../src/io/formats/drawio/shapes.ts"],"mappings":";;;;KAIY;;;EAEN;EAAyB,OAAO;EAAmB;EAAkB;;EACrE;;EACA;;EACA;;;iBA8DU,UAAU,OAAO;;;;;;;iBAkBjB,WAAW,OAAO,aAAa,uBAAuB;iBA+DtD,kBAAkB,OAAO,oBAAoB"}
1
+ {"version":3,"file":"shapes.d.ts","names":[],"sources":["../../../../src/io/formats/drawio/shapes.ts"],"mappings":";;;;KAIY;;;EAEN;EAAyB,OAAO;EAAmB;EAAkB;;EACrE;;EACA;;EACA;;EACA;;EACA;;;iBA8DU,UAAU,OAAO;;;;;;;;iBAmBjB,WAAW,OAAO,aAAa,uBAAuB;iBAgEtD,kBAAkB,OAAO,oBAAoB"}
@@ -74,16 +74,20 @@ const DIRECTION_TURN = /* @__PURE__ */ new Map([
74
74
  ["south", -90]
75
75
  ]);
76
76
  /**
77
- * What a vertex becomes. Text stays text; a swimlane, or a vertex its style makes a container,
78
- * becomes a section holding its cells; a group stays a group. A shape draw.io turns by
79
- * `direction` keeps its turn. Any other shape, a stencil FigJam has no shape for among them,
80
- * becomes a rectangle, named after the stencil so it can be found.
77
+ * What a vertex becomes. Text stays text; a swimlane becomes a section holding its cells, and
78
+ * any other vertex its style makes a container becomes a frame, as Pairdraw writes one; a group
79
+ * stays a group. A style Pairdraw wrote says when it drew a rectangle, which draw.io has no
80
+ * style of its own for. A shape draw.io turns by `direction` keeps its turn. Any other shape, a
81
+ * stencil FigJam has no shape for among them, becomes a shape named after the stencil.
81
82
  */
82
83
  function vertexKind(style, hasChildren) {
83
84
  const name = shapeName(style);
84
85
  if (name === "text") return { type: "TEXT" };
85
- if (name === "swimlane" || hasChildren && style.values.container === "1") return { type: "SECTION" };
86
- if (name === "group" || hasChildren && !SHAPES.has(name)) return { type: "GROUP" };
86
+ if (style.values.pairdrawType === "RECTANGLE") return { type: "RECTANGLE" };
87
+ if (name === "swimlane") return { type: "SECTION" };
88
+ if (name === "group") return { type: "GROUP" };
89
+ if (style.values.container === "1") return { type: "FRAME" };
90
+ if (hasChildren && !SHAPES.has(name)) return { type: "GROUP" };
87
91
  let shape = SHAPES.get(name) ?? "SQUARE";
88
92
  const direction = style.values.direction ?? "east";
89
93
  let rotation = 0;