@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
@@ -1,4 +1,4 @@
1
- import { nodeHasRadius } from "../../../canvas/shapes.js";
1
+ import { nodeHasRadius, nodeHasSmoothCorners } from "../../../canvas/shapes.js";
2
2
  import { PathSink } from "../../../vector/path-helpers.js";
3
3
  import { SceneNode } from "@pairdraw/scene-graph";
4
4
  //#region src/io/formats/svg/paths.d.ts
@@ -8,11 +8,17 @@ declare function geometryBlobToSVGPath(blob: Uint8Array, decimals?: number | nul
8
8
  declare function roundedPolygonPath(node: SceneNode): string;
9
9
  declare function makePolygonPoints(node: SceneNode): string;
10
10
  declare const hasRadius: typeof nodeHasRadius;
11
+ declare const hasSmoothCorners: typeof nodeHasSmoothCorners;
11
12
  type RectOutlineNode = Pick<SceneNode, 'width' | 'height' | 'cornerRadius' | 'independentCorners' | 'topLeftRadius' | 'topRightRadius' | 'bottomRightRadius' | 'bottomLeftRadius'>;
12
13
  declare function roundedRectPath(node: RectOutlineNode): string;
13
14
  declare function arcPath(node: Pick<SceneNode, 'width' | 'height' | 'arcData'>): string;
14
15
  /** Path commands written as SVG path data into `parts`, as the canvas would build a path. */
15
16
  declare function svgPathSink(parts: string[]): PathSink;
17
+ /**
18
+ * A box layer's outline as path data: its rectangle with its corner radii, smoothed as the canvas
19
+ * draws them. Frames, rectangles, and other box layers share it for fills, strokes, and clips.
20
+ */
21
+ declare function boxOutlinePath(node: RectOutlineNode & Pick<SceneNode, 'cornerSmoothing'>): string;
16
22
  /** What a layer's outline is drawn from. */
17
23
  type OutlineNode = RectOutlineNode & Pick<SceneNode, 'type' | 'arcData' | 'pointCount' | 'starInnerRadius' | 'cornerSmoothing' | 'vectorNetwork'>;
18
24
  /**
@@ -28,5 +34,5 @@ declare function shapeWithTextOutlinePath(node: Pick<SceneNode, 'shapeWithTextTy
28
34
  */
29
35
  declare function shapeWithTextDetailsPath(node: Pick<SceneNode, 'shapeWithTextType' | 'width' | 'height'>): string | null;
30
36
  //#endregion
31
- export { OutlineNode, arcPath, geometryBlobToSVGPath, hasRadius, makePolygonPoints, nodeOutlinePath, round, roundedPolygonPath, roundedRectPath, shapeWithTextDetailsPath, shapeWithTextOutlinePath, svgPathSink };
37
+ export { OutlineNode, arcPath, boxOutlinePath, geometryBlobToSVGPath, hasRadius, hasSmoothCorners, makePolygonPoints, nodeOutlinePath, round, roundedPolygonPath, roundedRectPath, shapeWithTextDetailsPath, shapeWithTextOutlinePath, svgPathSink };
32
38
  //# sourceMappingURL=paths.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"paths.d.ts","names":[],"sources":["../../../../src/io/formats/svg/paths.ts"],"mappings":";;;;iBAkBgB,MAAM,WAAW;iBASjB,sBAAsB,MAAM,YAAY;;iBAuDxC,mBAAmB,MAAM;iBAIzB,kBAAkB,MAAM;cAM3B,kBAAS;KAEjB,kBAAkB,KACrB;iBAWc,gBAAgB,MAAM;iBAgCtB,QAAQ,MAAM,KAAK;;iBA6CnB,YAAY,kBAAkB;;KA2BlC,cAAc,kBACxB,KACE;;;;;iBAUY,gBAAgB,MAAM;;iBAmBtB,yBACd,MAAM,KAAK;;;;;iBAeG,yBACd,MAAM,KAAK"}
1
+ {"version":3,"file":"paths.d.ts","names":[],"sources":["../../../../src/io/formats/svg/paths.ts"],"mappings":";;;;iBAkBgB,MAAM,WAAW;iBASjB,sBAAsB,MAAM,YAAY;;iBAuDxC,mBAAmB,MAAM;iBAIzB,kBAAkB,MAAM;cAM3B,kBAAS;cACT,yBAAgB;KAExB,kBAAkB,KACrB;iBAWc,gBAAgB,MAAM;iBAgCtB,QAAQ,MAAM,KAAK;;iBA6CnB,YAAY,kBAAkB;;;;;iBA8B9B,eAAe,MAAM,kBAAkB,KAAK;;KAKhD,cAAc,kBACxB,KACE;;;;;iBAUY,gBAAgB,MAAM;;iBAmBtB,yBACd,MAAM,KAAK;;;;;iBAeG,yBACd,MAAM,KAAK"}
@@ -1,5 +1,5 @@
1
1
  import { traceSmoothRect } from "../../../canvas/paths/smooth-corners.js";
2
- import { nodeHasRadius } from "../../../canvas/shapes.js";
2
+ import { nodeHasRadius, nodeHasSmoothCorners } from "../../../canvas/shapes.js";
3
3
  import { polygonVertices } from "@pairdraw/scene-graph/geometry";
4
4
  import { compact } from "es-toolkit/array";
5
5
  import { outlineSVGPath, polygonOutline } from "@pairdraw/scene-graph/polygon";
@@ -73,6 +73,7 @@ function makePolygonPoints(node) {
73
73
  return polygonVertices(node).map((point) => `${round(point.x)},${round(point.y)}`).join(" ");
74
74
  }
75
75
  const hasRadius = nodeHasRadius;
76
+ const hasSmoothCorners = nodeHasSmoothCorners;
76
77
  function roundedRectPath(node) {
77
78
  const w = node.width;
78
79
  const h = node.height;
@@ -159,6 +160,13 @@ function smoothRectPath(node) {
159
160
  };
160
161
  return traceSmoothRect(sink, node, box) ? parts.join("") : roundedRectPath(node);
161
162
  }
163
+ /**
164
+ * A box layer's outline as path data: its rectangle with its corner radii, smoothed as the canvas
165
+ * draws them. Frames, rectangles, and other box layers share it for fills, strokes, and clips.
166
+ */
167
+ function boxOutlinePath(node) {
168
+ return node.cornerSmoothing > 0 ? smoothRectPath(node) : roundedRectPath(node);
169
+ }
162
170
  const FULL_ELLIPSE = {
163
171
  startingAngle: 0,
164
172
  endingAngle: Math.PI * 2,
@@ -170,7 +178,7 @@ const FULL_ELLIPSE = {
170
178
  */
171
179
  function nodeOutlinePath(node) {
172
180
  switch (node.type) {
173
- case "RECTANGLE": return node.cornerSmoothing > 0 ? smoothRectPath(node) : roundedRectPath(node);
181
+ case "RECTANGLE": return boxOutlinePath(node);
174
182
  case "ELLIPSE": return arcPath({
175
183
  ...node,
176
184
  arcData: node.arcData ?? FULL_ELLIPSE
@@ -196,6 +204,6 @@ function shapeWithTextDetailsPath(node) {
196
204
  return details.length > 0 ? outlineSVGPath(details, (value) => round(value)) : null;
197
205
  }
198
206
  //#endregion
199
- export { arcPath, geometryBlobToSVGPath, hasRadius, makePolygonPoints, nodeOutlinePath, round, roundedPolygonPath, roundedRectPath, shapeWithTextDetailsPath, shapeWithTextOutlinePath, svgPathSink };
207
+ export { arcPath, boxOutlinePath, geometryBlobToSVGPath, hasRadius, hasSmoothCorners, makePolygonPoints, nodeOutlinePath, round, roundedPolygonPath, roundedRectPath, shapeWithTextDetailsPath, shapeWithTextOutlinePath, svgPathSink };
200
208
 
201
209
  //# sourceMappingURL=paths.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"paths.js","names":[],"sources":["../../../../src/io/formats/svg/paths.ts"],"sourcesContent":["import { compact } from 'es-toolkit/array'\n\nimport type { SceneNode } from '@pairdraw/scene-graph'\nimport { polygonVertices } from '@pairdraw/scene-graph/geometry'\nimport { outlineSVGPath, polygonOutline } from '@pairdraw/scene-graph/polygon'\nimport { shapeWithTextGeometry } from '@pairdraw/scene-graph/shape-with-text'\nimport { vectorNetworkToSVGPaths } from '@pairdraw/scene-graph/vector-network'\n\nimport { traceSmoothRect, type SmoothCornerSink } from '#core/canvas/paths/smooth-corners'\nimport { nodeHasRadius } from '#core/canvas/shapes'\nimport type { PathSink } from '#core/vector/path-helpers'\n\nconst CMD_CLOSE = 0\nconst CMD_MOVE_TO = 1\nconst CMD_LINE_TO = 2\nconst CMD_QUAD_TO = 3\nconst CMD_CUBIC_TO = 4\n\nexport function round(n: number, decimals = 2): number {\n const factor = 10 ** decimals\n return Math.round(n * factor) / factor\n}\n\nfunction coordinate(value: number, decimals: number | null): number {\n return decimals === null ? value : round(value, decimals)\n}\n\nexport function geometryBlobToSVGPath(blob: Uint8Array, decimals: number | null = 2): string {\n if (blob.length === 0) return ''\n const dv = new DataView(blob.buffer, blob.byteOffset, blob.byteLength)\n let o = 0\n const parts: string[] = []\n\n while (o < blob.length) {\n const cmd = blob[o++]\n switch (cmd) {\n case CMD_CLOSE:\n parts.push('Z')\n break\n case CMD_MOVE_TO: {\n const x = coordinate(dv.getFloat32(o, true), decimals)\n const y = coordinate(dv.getFloat32(o + 4, true), decimals)\n o += 8\n parts.push(`M${x} ${y}`)\n break\n }\n case CMD_LINE_TO: {\n const x = coordinate(dv.getFloat32(o, true), decimals)\n const y = coordinate(dv.getFloat32(o + 4, true), decimals)\n o += 8\n parts.push(`L${x} ${y}`)\n break\n }\n case CMD_QUAD_TO: {\n const x1 = coordinate(dv.getFloat32(o, true), decimals)\n const y1 = coordinate(dv.getFloat32(o + 4, true), decimals)\n const x = coordinate(dv.getFloat32(o + 8, true), decimals)\n const y = coordinate(dv.getFloat32(o + 12, true), decimals)\n o += 16\n parts.push(`Q${x1} ${y1} ${x} ${y}`)\n break\n }\n case CMD_CUBIC_TO: {\n const x1 = coordinate(dv.getFloat32(o, true), decimals)\n const y1 = coordinate(dv.getFloat32(o + 4, true), decimals)\n const x2 = coordinate(dv.getFloat32(o + 8, true), decimals)\n const y2 = coordinate(dv.getFloat32(o + 12, true), decimals)\n const x = coordinate(dv.getFloat32(o + 16, true), decimals)\n const y = coordinate(dv.getFloat32(o + 20, true), decimals)\n o += 24\n parts.push(`C${x1} ${y1} ${x2} ${y2} ${x} ${y}`)\n break\n }\n default:\n return parts.join('')\n }\n }\n\n return parts.join('')\n}\n\n/** The outline of a polygon or star whose corners are rounded, as path data. */\nexport function roundedPolygonPath(node: SceneNode): string {\n return outlineSVGPath(polygonOutline(node), (value) => round(value))\n}\n\nexport function makePolygonPoints(node: SceneNode): string {\n return polygonVertices(node)\n .map((point) => `${round(point.x)},${round(point.y)}`)\n .join(' ')\n}\n\nexport const hasRadius = nodeHasRadius\n\ntype RectOutlineNode = Pick<\n SceneNode,\n | 'width'\n | 'height'\n | 'cornerRadius'\n | 'independentCorners'\n | 'topLeftRadius'\n | 'topRightRadius'\n | 'bottomRightRadius'\n | 'bottomLeftRadius'\n>\n\nexport function roundedRectPath(node: RectOutlineNode): string {\n const w = node.width\n const h = node.height\n let tl: number, tr: number, br: number, bl: number\n if (node.independentCorners) {\n tl = node.topLeftRadius\n tr = node.topRightRadius\n br = node.bottomRightRadius\n bl = node.bottomLeftRadius\n } else {\n tl = tr = br = bl = node.cornerRadius\n }\n\n tl = Math.min(tl, w / 2, h / 2)\n tr = Math.min(tr, w / 2, h / 2)\n br = Math.min(br, w / 2, h / 2)\n bl = Math.min(bl, w / 2, h / 2)\n\n return compact([\n `M${round(tl)} 0`,\n `L${round(w - tr)} 0`,\n tr > 0 ? `A${round(tr)} ${round(tr)} 0 0 1 ${round(w)} ${round(tr)}` : '',\n `L${round(w)} ${round(h - br)}`,\n br > 0 ? `A${round(br)} ${round(br)} 0 0 1 ${round(w - br)} ${round(h)}` : '',\n `L${round(bl)} ${round(h)}`,\n bl > 0 ? `A${round(bl)} ${round(bl)} 0 0 1 0 ${round(h - bl)}` : '',\n `L0 ${round(tl)}`,\n tl > 0 ? `A${round(tl)} ${round(tl)} 0 0 1 ${round(tl)} 0` : '',\n 'Z'\n ]).join('')\n}\n\nexport function arcPath(node: Pick<SceneNode, 'width' | 'height' | 'arcData'>): string {\n if (!node.arcData) return ''\n const { startingAngle, endingAngle, innerRadius } = node.arcData\n const cx = node.width / 2\n const cy = node.height / 2\n const rx = node.width / 2\n const ry = node.height / 2\n\n const fullCircle = Math.abs(endingAngle - startingAngle) >= Math.PI * 2 - 0.001\n const ring = (rx: number, ry: number, sweep: 0 | 1) =>\n `M${round(cx - rx)} ${round(cy)}A${round(rx)} ${round(ry)} 0 1 ${sweep} ${round(cx + rx)} ${round(cy)}A${round(rx)} ${round(ry)} 0 1 ${sweep} ${round(cx - rx)} ${round(cy)}Z`\n // A whole ring has no ends to join: it is its outer edge and, for a donut, its hole, wound\n // the other way so the default nonzero fill leaves the hole empty.\n if (fullCircle) {\n const outer = ring(rx, ry, 1)\n return innerRadius > 0 ? outer + ring(rx * innerRadius, ry * innerRadius, 0) : outer\n }\n\n const x1 = round(cx + rx * Math.cos(startingAngle))\n const y1 = round(cy + ry * Math.sin(startingAngle))\n const x2 = round(cx + rx * Math.cos(endingAngle))\n const y2 = round(cy + ry * Math.sin(endingAngle))\n const largeArc = Math.abs(endingAngle - startingAngle) > Math.PI ? 1 : 0\n const sweep = endingAngle > startingAngle ? 1 : 0\n\n const parts = [`M${x1} ${y1}`, `A${round(rx)} ${round(ry)} 0 ${largeArc} ${sweep} ${x2} ${y2}`]\n\n if (innerRadius > 0) {\n const irx = rx * innerRadius\n const iry = ry * innerRadius\n const ix1 = round(cx + irx * Math.cos(endingAngle))\n const iy1 = round(cy + iry * Math.sin(endingAngle))\n const ix2 = round(cx + irx * Math.cos(startingAngle))\n const iy2 = round(cy + iry * Math.sin(startingAngle))\n parts.push(`L${ix1} ${iy1}`)\n parts.push(`A${round(irx)} ${round(iry)} 0 ${largeArc} ${sweep === 1 ? 0 : 1} ${ix2} ${iy2}`)\n parts.push('Z')\n } else {\n parts.push(`L${round(cx)} ${round(cy)}Z`)\n }\n\n return parts.join('')\n}\n\n/** Path commands written as SVG path data into `parts`, as the canvas would build a path. */\nexport function svgPathSink(parts: string[]): PathSink {\n const point = (x: number, y: number) => `${round(x)} ${round(y)}`\n return {\n moveTo: (x, y) => parts.push(`M${point(x, y)}`),\n lineTo: (x, y) => parts.push(`L${point(x, y)}`),\n cubicTo: (x1, y1, x2, y2, x, y) =>\n parts.push(`C${point(x1, y1)} ${point(x2, y2)} ${point(x, y)}`),\n close: () => parts.push('Z')\n }\n}\n\n/** A rectangle with smoothed corners as path data, traced as the canvas draws it. */\nfunction smoothRectPath(node: RectOutlineNode & Pick<SceneNode, 'cornerSmoothing'>): string {\n const parts: string[] = []\n const point = (x: number, y: number) => `${round(x)} ${round(y)}`\n const sink: SmoothCornerSink = {\n ...svgPathSink(parts),\n arcToRotated: (rx, ry, rotation, useSmallArc, isCCW, x, y) =>\n parts.push(\n `A${round(rx)} ${round(ry)} ${rotation} ${useSmallArc ? 0 : 1} ${isCCW ? 0 : 1} ${point(x, y)}`\n )\n }\n const box = { left: 0, top: 0, right: node.width, bottom: node.height }\n return traceSmoothRect(sink, node, box) ? parts.join('') : roundedRectPath(node)\n}\n\n/** What a layer's outline is drawn from. */\nexport type OutlineNode = RectOutlineNode &\n Pick<\n SceneNode,\n 'type' | 'arcData' | 'pointCount' | 'starInnerRadius' | 'cornerSmoothing' | 'vectorNetwork'\n >\n\nconst FULL_ELLIPSE = { startingAngle: 0, endingAngle: Math.PI * 2, innerRadius: 0 }\n\n/**\n * A shape layer's outline in its own box as path data: a rectangle with its corners, an ellipse\n * or arc, a line, a polygon or star, or a vector's network. Null for other layers.\n */\nexport function nodeOutlinePath(node: OutlineNode): string | null {\n switch (node.type) {\n case 'RECTANGLE':\n return node.cornerSmoothing > 0 ? smoothRectPath(node) : roundedRectPath(node)\n case 'ELLIPSE':\n return arcPath({ ...node, arcData: node.arcData ?? FULL_ELLIPSE })\n case 'LINE':\n return `M0 0L${round(node.width)} ${round(node.height)}`\n case 'POLYGON':\n case 'STAR':\n return outlineSVGPath(polygonOutline(node), (value) => round(value))\n case 'VECTOR':\n return node.vectorNetwork ? vectorNetworkToSVGPaths(node.vectorNetwork).join('') : null\n default:\n return null\n }\n}\n\n/** A FigJam shape's outline in its own box as path data, with its corner radius. */\nexport function shapeWithTextOutlinePath(\n node: Pick<SceneNode, 'shapeWithTextType' | 'width' | 'height' | 'cornerRadius'>\n): string {\n const { outline } = shapeWithTextGeometry(\n node.shapeWithTextType,\n node.width,\n node.height,\n node.cornerRadius\n )\n return outlineSVGPath(outline, (value) => round(value))\n}\n\n/**\n * A FigJam shape's stroke-only inner lines, such as a database's front rim, as path data; null for\n * a shape without any.\n */\nexport function shapeWithTextDetailsPath(\n node: Pick<SceneNode, 'shapeWithTextType' | 'width' | 'height'>\n): string | null {\n const { details } = shapeWithTextGeometry(node.shapeWithTextType, node.width, node.height)\n return details.length > 0 ? outlineSVGPath(details, (value) => round(value)) : null\n}\n"],"mappings":";;;;;;;;AAYA,MAAM,YAAY;AAClB,MAAM,cAAc;AACpB,MAAM,cAAc;AACpB,MAAM,cAAc;AACpB,MAAM,eAAe;AAErB,SAAgB,MAAM,GAAW,WAAW,GAAW;CACrD,MAAM,SAAS,MAAM;CACrB,OAAO,KAAK,MAAM,IAAI,MAAM,IAAI;AAClC;AAEA,SAAS,WAAW,OAAe,UAAiC;CAClE,OAAO,aAAa,OAAO,QAAQ,MAAM,OAAO,QAAQ;AAC1D;AAEA,SAAgB,sBAAsB,MAAkB,WAA0B,GAAW;CAC3F,IAAI,KAAK,WAAW,GAAG,OAAO;CAC9B,MAAM,KAAK,IAAI,SAAS,KAAK,QAAQ,KAAK,YAAY,KAAK,UAAU;CACrE,IAAI,IAAI;CACR,MAAM,QAAkB,CAAC;CAEzB,OAAO,IAAI,KAAK,QAEd,QADY,KAAK,MACjB;EACE,KAAK;GACH,MAAM,KAAK,GAAG;GACd;EACF,KAAK,aAAa;GAChB,MAAM,IAAI,WAAW,GAAG,WAAW,GAAG,IAAI,GAAG,QAAQ;GACrD,MAAM,IAAI,WAAW,GAAG,WAAW,IAAI,GAAG,IAAI,GAAG,QAAQ;GACzD,KAAK;GACL,MAAM,KAAK,IAAI,EAAE,GAAG,GAAG;GACvB;EACF;EACA,KAAK,aAAa;GAChB,MAAM,IAAI,WAAW,GAAG,WAAW,GAAG,IAAI,GAAG,QAAQ;GACrD,MAAM,IAAI,WAAW,GAAG,WAAW,IAAI,GAAG,IAAI,GAAG,QAAQ;GACzD,KAAK;GACL,MAAM,KAAK,IAAI,EAAE,GAA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,eAAe,UAAU,UAAU,MAAM,KAAK,CAAC,IAAI;AACjF"}
1
+ {"version":3,"file":"paths.js","names":[],"sources":["../../../../src/io/formats/svg/paths.ts"],"sourcesContent":["import { compact } from 'es-toolkit/array'\n\nimport type { SceneNode } from '@pairdraw/scene-graph'\nimport { polygonVertices } from '@pairdraw/scene-graph/geometry'\nimport { outlineSVGPath, polygonOutline } from '@pairdraw/scene-graph/polygon'\nimport { shapeWithTextGeometry } from '@pairdraw/scene-graph/shape-with-text'\nimport { vectorNetworkToSVGPaths } from '@pairdraw/scene-graph/vector-network'\n\nimport { traceSmoothRect, type SmoothCornerSink } from '#core/canvas/paths/smooth-corners'\nimport { nodeHasRadius, nodeHasSmoothCorners } from '#core/canvas/shapes'\nimport type { PathSink } from '#core/vector/path-helpers'\n\nconst CMD_CLOSE = 0\nconst CMD_MOVE_TO = 1\nconst CMD_LINE_TO = 2\nconst CMD_QUAD_TO = 3\nconst CMD_CUBIC_TO = 4\n\nexport function round(n: number, decimals = 2): number {\n const factor = 10 ** decimals\n return Math.round(n * factor) / factor\n}\n\nfunction coordinate(value: number, decimals: number | null): number {\n return decimals === null ? value : round(value, decimals)\n}\n\nexport function geometryBlobToSVGPath(blob: Uint8Array, decimals: number | null = 2): string {\n if (blob.length === 0) return ''\n const dv = new DataView(blob.buffer, blob.byteOffset, blob.byteLength)\n let o = 0\n const parts: string[] = []\n\n while (o < blob.length) {\n const cmd = blob[o++]\n switch (cmd) {\n case CMD_CLOSE:\n parts.push('Z')\n break\n case CMD_MOVE_TO: {\n const x = coordinate(dv.getFloat32(o, true), decimals)\n const y = coordinate(dv.getFloat32(o + 4, true), decimals)\n o += 8\n parts.push(`M${x} ${y}`)\n break\n }\n case CMD_LINE_TO: {\n const x = coordinate(dv.getFloat32(o, true), decimals)\n const y = coordinate(dv.getFloat32(o + 4, true), decimals)\n o += 8\n parts.push(`L${x} ${y}`)\n break\n }\n case CMD_QUAD_TO: {\n const x1 = coordinate(dv.getFloat32(o, true), decimals)\n const y1 = coordinate(dv.getFloat32(o + 4, true), decimals)\n const x = coordinate(dv.getFloat32(o + 8, true), decimals)\n const y = coordinate(dv.getFloat32(o + 12, true), decimals)\n o += 16\n parts.push(`Q${x1} ${y1} ${x} ${y}`)\n break\n }\n case CMD_CUBIC_TO: {\n const x1 = coordinate(dv.getFloat32(o, true), decimals)\n const y1 = coordinate(dv.getFloat32(o + 4, true), decimals)\n const x2 = coordinate(dv.getFloat32(o + 8, true), decimals)\n const y2 = coordinate(dv.getFloat32(o + 12, true), decimals)\n const x = coordinate(dv.getFloat32(o + 16, true), decimals)\n const y = coordinate(dv.getFloat32(o + 20, true), decimals)\n o += 24\n parts.push(`C${x1} ${y1} ${x2} ${y2} ${x} ${y}`)\n break\n }\n default:\n return parts.join('')\n }\n }\n\n return parts.join('')\n}\n\n/** The outline of a polygon or star whose corners are rounded, as path data. */\nexport function roundedPolygonPath(node: SceneNode): string {\n return outlineSVGPath(polygonOutline(node), (value) => round(value))\n}\n\nexport function makePolygonPoints(node: SceneNode): string {\n return polygonVertices(node)\n .map((point) => `${round(point.x)},${round(point.y)}`)\n .join(' ')\n}\n\nexport const hasRadius = nodeHasRadius\nexport const hasSmoothCorners = nodeHasSmoothCorners\n\ntype RectOutlineNode = Pick<\n SceneNode,\n | 'width'\n | 'height'\n | 'cornerRadius'\n | 'independentCorners'\n | 'topLeftRadius'\n | 'topRightRadius'\n | 'bottomRightRadius'\n | 'bottomLeftRadius'\n>\n\nexport function roundedRectPath(node: RectOutlineNode): string {\n const w = node.width\n const h = node.height\n let tl: number, tr: number, br: number, bl: number\n if (node.independentCorners) {\n tl = node.topLeftRadius\n tr = node.topRightRadius\n br = node.bottomRightRadius\n bl = node.bottomLeftRadius\n } else {\n tl = tr = br = bl = node.cornerRadius\n }\n\n tl = Math.min(tl, w / 2, h / 2)\n tr = Math.min(tr, w / 2, h / 2)\n br = Math.min(br, w / 2, h / 2)\n bl = Math.min(bl, w / 2, h / 2)\n\n return compact([\n `M${round(tl)} 0`,\n `L${round(w - tr)} 0`,\n tr > 0 ? `A${round(tr)} ${round(tr)} 0 0 1 ${round(w)} ${round(tr)}` : '',\n `L${round(w)} ${round(h - br)}`,\n br > 0 ? `A${round(br)} ${round(br)} 0 0 1 ${round(w - br)} ${round(h)}` : '',\n `L${round(bl)} ${round(h)}`,\n bl > 0 ? `A${round(bl)} ${round(bl)} 0 0 1 0 ${round(h - bl)}` : '',\n `L0 ${round(tl)}`,\n tl > 0 ? `A${round(tl)} ${round(tl)} 0 0 1 ${round(tl)} 0` : '',\n 'Z'\n ]).join('')\n}\n\nexport function arcPath(node: Pick<SceneNode, 'width' | 'height' | 'arcData'>): string {\n if (!node.arcData) return ''\n const { startingAngle, endingAngle, innerRadius } = node.arcData\n const cx = node.width / 2\n const cy = node.height / 2\n const rx = node.width / 2\n const ry = node.height / 2\n\n const fullCircle = Math.abs(endingAngle - startingAngle) >= Math.PI * 2 - 0.001\n const ring = (rx: number, ry: number, sweep: 0 | 1) =>\n `M${round(cx - rx)} ${round(cy)}A${round(rx)} ${round(ry)} 0 1 ${sweep} ${round(cx + rx)} ${round(cy)}A${round(rx)} ${round(ry)} 0 1 ${sweep} ${round(cx - rx)} ${round(cy)}Z`\n // A whole ring has no ends to join: it is its outer edge and, for a donut, its hole, wound\n // the other way so the default nonzero fill leaves the hole empty.\n if (fullCircle) {\n const outer = ring(rx, ry, 1)\n return innerRadius > 0 ? outer + ring(rx * innerRadius, ry * innerRadius, 0) : outer\n }\n\n const x1 = round(cx + rx * Math.cos(startingAngle))\n const y1 = round(cy + ry * Math.sin(startingAngle))\n const x2 = round(cx + rx * Math.cos(endingAngle))\n const y2 = round(cy + ry * Math.sin(endingAngle))\n const largeArc = Math.abs(endingAngle - startingAngle) > Math.PI ? 1 : 0\n const sweep = endingAngle > startingAngle ? 1 : 0\n\n const parts = [`M${x1} ${y1}`, `A${round(rx)} ${round(ry)} 0 ${largeArc} ${sweep} ${x2} ${y2}`]\n\n if (innerRadius > 0) {\n const irx = rx * innerRadius\n const iry = ry * innerRadius\n const ix1 = round(cx + irx * Math.cos(endingAngle))\n const iy1 = round(cy + iry * Math.sin(endingAngle))\n const ix2 = round(cx + irx * Math.cos(startingAngle))\n const iy2 = round(cy + iry * Math.sin(startingAngle))\n parts.push(`L${ix1} ${iy1}`)\n parts.push(`A${round(irx)} ${round(iry)} 0 ${largeArc} ${sweep === 1 ? 0 : 1} ${ix2} ${iy2}`)\n parts.push('Z')\n } else {\n parts.push(`L${round(cx)} ${round(cy)}Z`)\n }\n\n return parts.join('')\n}\n\n/** Path commands written as SVG path data into `parts`, as the canvas would build a path. */\nexport function svgPathSink(parts: string[]): PathSink {\n const point = (x: number, y: number) => `${round(x)} ${round(y)}`\n return {\n moveTo: (x, y) => parts.push(`M${point(x, y)}`),\n lineTo: (x, y) => parts.push(`L${point(x, y)}`),\n cubicTo: (x1, y1, x2, y2, x, y) =>\n parts.push(`C${point(x1, y1)} ${point(x2, y2)} ${point(x, y)}`),\n close: () => parts.push('Z')\n }\n}\n\n/** A rectangle with smoothed corners as path data, traced as the canvas draws it. */\nfunction smoothRectPath(node: RectOutlineNode & Pick<SceneNode, 'cornerSmoothing'>): string {\n const parts: string[] = []\n const point = (x: number, y: number) => `${round(x)} ${round(y)}`\n const sink: SmoothCornerSink = {\n ...svgPathSink(parts),\n arcToRotated: (rx, ry, rotation, useSmallArc, isCCW, x, y) =>\n parts.push(\n `A${round(rx)} ${round(ry)} ${rotation} ${useSmallArc ? 0 : 1} ${isCCW ? 0 : 1} ${point(x, y)}`\n )\n }\n const box = { left: 0, top: 0, right: node.width, bottom: node.height }\n return traceSmoothRect(sink, node, box) ? parts.join('') : roundedRectPath(node)\n}\n\n/**\n * A box layer's outline as path data: its rectangle with its corner radii, smoothed as the canvas\n * draws them. Frames, rectangles, and other box layers share it for fills, strokes, and clips.\n */\nexport function boxOutlinePath(node: RectOutlineNode & Pick<SceneNode, 'cornerSmoothing'>): string {\n return node.cornerSmoothing > 0 ? smoothRectPath(node) : roundedRectPath(node)\n}\n\n/** What a layer's outline is drawn from. */\nexport type OutlineNode = RectOutlineNode &\n Pick<\n SceneNode,\n 'type' | 'arcData' | 'pointCount' | 'starInnerRadius' | 'cornerSmoothing' | 'vectorNetwork'\n >\n\nconst FULL_ELLIPSE = { startingAngle: 0, endingAngle: Math.PI * 2, innerRadius: 0 }\n\n/**\n * A shape layer's outline in its own box as path data: a rectangle with its corners, an ellipse\n * or arc, a line, a polygon or star, or a vector's network. Null for other layers.\n */\nexport function nodeOutlinePath(node: OutlineNode): string | null {\n switch (node.type) {\n case 'RECTANGLE':\n return boxOutlinePath(node)\n case 'ELLIPSE':\n return arcPath({ ...node, arcData: node.arcData ?? FULL_ELLIPSE })\n case 'LINE':\n return `M0 0L${round(node.width)} ${round(node.height)}`\n case 'POLYGON':\n case 'STAR':\n return outlineSVGPath(polygonOutline(node), (value) => round(value))\n case 'VECTOR':\n return node.vectorNetwork ? vectorNetworkToSVGPaths(node.vectorNetwork).join('') : null\n default:\n return null\n }\n}\n\n/** A FigJam shape's outline in its own box as path data, with its corner radius. */\nexport function shapeWithTextOutlinePath(\n node: Pick<SceneNode, 'shapeWithTextType' | 'width' | 'height' | 'cornerRadius'>\n): string {\n const { outline } = shapeWithTextGeometry(\n node.shapeWithTextType,\n node.width,\n node.height,\n node.cornerRadius\n )\n return outlineSVGPath(outline, (value) => round(value))\n}\n\n/**\n * A FigJam shape's stroke-only inner lines, such as a database's front rim, as path data; null for\n * a shape without any.\n */\nexport function shapeWithTextDetailsPath(\n node: Pick<SceneNode, 'shapeWithTextType' | 'width' | 'height'>\n): string | null {\n const { details } = shapeWithTextGeometry(node.shapeWithTextType, node.width, node.height)\n return details.length > 0 ? outlineSVGPath(details, (value) => round(value)) : null\n}\n"],"mappings":";;;;;;;;AAYA,MAAM,YAAY;AAClB,MAAM,cAAc;AACpB,MAAM,cAAc;AACpB,MAAM,cAAc;AACpB,MAAM,eAAe;AAErB,SAAgB,MAAM,GAAW,WAAW,GAA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,mBACJ"}
1
+ {"version":3,"file":"strokes.d.ts","names":[],"sources":["../../../../src/io/formats/svg/strokes.ts"],"mappings":";;;;KAaK,QAAQ;;iBA0BG,cAAc,MAAM,WAAW,QAAQ,qBAAqB;;;;;iBAS5D,qBACd,MAAM,WACN,QAAQ,QACR,aAAa,OACb,KAAK,mBACJ;;;;;iBAkCa,4BACd,MAAM,WACN,aAAa,OACb,KAAK,mBACJ"}
@@ -1,5 +1,5 @@
1
1
  import { svg } from "./node.js";
2
- import { nodeOutlinePath, round, shapeWithTextDetailsPath, shapeWithTextOutlinePath } from "./paths.js";
2
+ import { boxOutlinePath, nodeOutlinePath, round, shapeWithTextDetailsPath, shapeWithTextOutlinePath } from "./paths.js";
3
3
  import { nextDefId } from "./defs.js";
4
4
  //#region src/io/formats/svg/strokes.ts
5
5
  /**
@@ -16,10 +16,7 @@ function closedOutlinePath(node) {
16
16
  case "ELLIPSE": return node.arcData ? null : nodeOutlinePath(node);
17
17
  case "POLYGON":
18
18
  case "STAR": return nodeOutlinePath(node);
19
- default: return nodeOutlinePath({
20
- ...node,
21
- type: "RECTANGLE"
22
- });
19
+ default: return boxOutlinePath(node);
23
20
  }
24
21
  }
25
22
  /** The stroke an aligned stroke paints, when it is inside or outside a closed outline. */
@@ -1 +1 @@
1
- {"version":3,"file":"strokes.js","names":[],"sources":["../../../../src/io/formats/svg/strokes.ts"],"sourcesContent":["import type { SceneNode, Stroke } from '@pairdraw/scene-graph'\n\nimport type { SVGExportContext } from './defs'\nimport { nextDefId } from './defs'\nimport { svg, type SVGNode } from './node'\nimport { nodeOutlinePath, round, shapeWithTextDetailsPath, shapeWithTextOutlinePath } from './paths'\n\ntype Attrs = Record<string, string | number | undefined>\n\n/**\n * The closed outline an aligned stroke follows, as path data in the layer's box: a FigJam shape's,\n * an ellipse, polygon or star, or a box with its corners for any other layer. Null for lines,\n * arcs, and vectors, whose strokes the canvas centres on their paths.\n */\nfunction closedOutlinePath(node: SceneNode): string | null {\n switch (node.type) {\n case 'LINE':\n case 'VECTOR':\n case 'BOOLEAN_OPERATION':\n return null\n case 'SHAPE_WITH_TEXT':\n return shapeWithTextOutlinePath(node)\n case 'ELLIPSE':\n return node.arcData ? null : nodeOutlinePath(node)\n case 'POLYGON':\n case 'STAR':\n return nodeOutlinePath(node)\n default:\n return nodeOutlinePath({ ...node, type: 'RECTANGLE' })\n }\n}\n\n/** The stroke an aligned stroke paints, when it is inside or outside a closed outline. */\nexport function alignedStroke(node: SceneNode, stroke: Stroke | undefined): Stroke | null {\n if (!stroke || stroke.align === 'CENTER') return null\n return closedOutlinePath(node) === null ? null : stroke\n}\n\n/**\n * A stroke inside or outside the layer's outline, as the canvas draws it: centred at twice its\n * weight and clipped to the outline, or to everything around it.\n */\nexport function alignedStrokeElement(\n node: SceneNode,\n stroke: Stroke,\n strokeAttrs: Attrs,\n ctx: SVGExportContext\n): SVGNode[] {\n const outline = closedOutlinePath(node)\n if (outline === null) return []\n const clipId = nextDefId(ctx, 'clip')\n if (stroke.align === 'INSIDE') {\n ctx.defs.push(svg('clipPath', { id: clipId }, svg('path', { d: outline })))\n } else {\n // A box wide enough for the stroke, its mitred tips included, with the outline cut out of it.\n // The doubled stroke mitres out to its weight times the miter limit.\n const margin = stroke.weight * Math.max(2, node.strokeMiterLimit)\n const left = round(-margin)\n const top = round(-margin)\n const right = round(node.width + margin)\n const bottom = round(node.height + margin)\n const around = `M${left} ${top}H${right}V${bottom}H${left}Z`\n ctx.defs.push(\n svg('clipPath', { id: clipId }, svg('path', { d: around + outline, 'clip-rule': 'evenodd' }))\n )\n }\n return [\n svg('path', {\n d: outline,\n fill: 'none',\n ...strokeAttrs,\n 'stroke-width': round(stroke.weight * 2),\n 'clip-path': `url(#${clipId})`\n })\n ]\n}\n\n/**\n * A FigJam shape's inner lines, such as a database's front rim, stroked as the canvas strokes\n * them: at the stroke's own weight whatever its alignment, ending where the outline does.\n */\nexport function shapeWithTextDetailElements(\n node: SceneNode,\n strokeAttrs: Attrs,\n ctx: SVGExportContext\n): SVGNode[] {\n const details = strokeAttrs.stroke ? shapeWithTextDetailsPath(node) : null\n if (!details) return []\n const clipId = nextDefId(ctx, 'clip')\n ctx.defs.push(svg('clipPath', { id: clipId }, svg('path', { d: shapeWithTextOutlinePath(node) })))\n return [svg('path', { d: details, fill: 'none', ...strokeAttrs, 'clip-path': `url(#${clipId})` })]\n}\n"],"mappings":";;;;;;;;;AAcA,SAAS,kBAAkB,MAAgC;CACzD,QAAQ,KAAK,MAAb;EACE,KAAK;EACL,KAAK;EACL,KAAK,qBACH,OAAO;EACT,KAAK,mBACH,OAAO,yBAAyB,IAAI;EACtC,KAAK,WACH,OAAO,KAAK,UAAU,OAAO,gBAAgB,IAAI;EACnD,KAAK;EACL,KAAK,QACH,OAAO,gBAAgB,IAAI;EAC7B,SACE,OAAO,gBAAgB;GAAE,GAAG;GAAM,MAAM;EAAY,CAAC;CACzD;AACF;;AAGA,SAAgB,cAAc,MAAiB,QAA2C;CACxF,IAAI,CAAC,UAAU,OAAO,UAAU,UAAU,OAAO;CACjD,OAAO,kBAAkB,IAAI,MAAM,OAAO,OAAO;AACnD;;;;;AAMA,SAAgB,qBACd,MACA,QACA,aACA,KACW;CACX,MAAM,UAAU,kBAAkB,IAAI;CACtC,IAAI,YAAY,MAAM,OAAO,CAAC;CAC9B,MAAM,SAAS,UAAU,KAAK,MAAM;CACpC,IAAI,OAAO,UAAU,UACnB,IAAI,KAAK,KAAK,IAAI,YAAY,EAAE,IAAI,OAAO,GAAG,IAAI,QAAQ,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC;MACrE;EAGL,MAAM,SAAS,OAAO,SAAS,KAAK,IAAI,GAAG,KAAK,gBAAgB;EAChE,MAAM,OAAO,MAAM,CAAC,MAAM;EAI1B,MAAM,SAAS,IAAI,KAAK,GAHZ,MAAM,CAAC,MAGU,EAAE,GAFjB,MAAM,KAAK,QAAQ,MAEK,EAAE,GADzB,MAAM,KAAK,SAAS,MACa,EAAE,GAAG,KAAK;EAC1D,IAAI,KAAK,KACP,IAAI,YAAY,EAAE,IAAI,OAAO,GAAG,IAAI,QAAQ;GAAE,GAAG,SAAS;GAAS,aAAa;EAAU,CAAC,CAAC,CAC9F;CACF;CACA,OAAO,CACL,IAAI,QAAQ;EACV,GAAG;EACH,MAAM;EACN,GAAG;EACH,gBAAgB,MAAM,OAAO,SAAS,CAAC;EACvC,aAAa,QAAQ,OAAO;CAC9B,CAAC,CACH;AACF;;;;;AAMA,SAAgB,4BACd,MACA,aACA,KACW;CACX,MAAM,UAAU,YAAY,SAAS,yBAAyB,IAAI,IAAI;CACtE,IAAI,CAAC,SAAS,OAAO,CAAC;CACtB,MAAM,SAAS,UAAU,KAAK,MAAM;CACpC,IAAI,KAAK,KAAK,IAAI,YAAY,EAAE,IAAI,OAAO,GAAG,IAAI,QAAQ,EAAE,GAAG,yBAAyB,IAAI,EAAE,CAAC,CAAC,CAAC;CACjG,OAAO,CAAC,IAAI,QAAQ;EAAE,GAAG;EAAS,MAAM;EAAQ,GAAG;EAAa,aAAa,QAAQ,OAAO;CAAG,CAAC,CAAC;AACnG"}
1
+ {"version":3,"file":"strokes.js","names":[],"sources":["../../../../src/io/formats/svg/strokes.ts"],"sourcesContent":["import type { SceneNode, Stroke } from '@pairdraw/scene-graph'\n\nimport type { SVGExportContext } from './defs'\nimport { nextDefId } from './defs'\nimport { svg, type SVGNode } from './node'\nimport {\n boxOutlinePath,\n nodeOutlinePath,\n round,\n shapeWithTextDetailsPath,\n shapeWithTextOutlinePath\n} from './paths'\n\ntype Attrs = Record<string, string | number | undefined>\n\n/**\n * The closed outline an aligned stroke follows, as path data in the layer's box: a FigJam shape's,\n * an ellipse, polygon or star, or a box with its corners for any other layer. Null for lines,\n * arcs, and vectors, whose strokes the canvas centres on their paths.\n */\nfunction closedOutlinePath(node: SceneNode): string | null {\n switch (node.type) {\n case 'LINE':\n case 'VECTOR':\n case 'BOOLEAN_OPERATION':\n return null\n case 'SHAPE_WITH_TEXT':\n return shapeWithTextOutlinePath(node)\n case 'ELLIPSE':\n return node.arcData ? null : nodeOutlinePath(node)\n case 'POLYGON':\n case 'STAR':\n return nodeOutlinePath(node)\n default:\n return boxOutlinePath(node)\n }\n}\n\n/** The stroke an aligned stroke paints, when it is inside or outside a closed outline. */\nexport function alignedStroke(node: SceneNode, stroke: Stroke | undefined): Stroke | null {\n if (!stroke || stroke.align === 'CENTER') return null\n return closedOutlinePath(node) === null ? null : stroke\n}\n\n/**\n * A stroke inside or outside the layer's outline, as the canvas draws it: centred at twice its\n * weight and clipped to the outline, or to everything around it.\n */\nexport function alignedStrokeElement(\n node: SceneNode,\n stroke: Stroke,\n strokeAttrs: Attrs,\n ctx: SVGExportContext\n): SVGNode[] {\n const outline = closedOutlinePath(node)\n if (outline === null) return []\n const clipId = nextDefId(ctx, 'clip')\n if (stroke.align === 'INSIDE') {\n ctx.defs.push(svg('clipPath', { id: clipId }, svg('path', { d: outline })))\n } else {\n // A box wide enough for the stroke, its mitred tips included, with the outline cut out of it.\n // The doubled stroke mitres out to its weight times the miter limit.\n const margin = stroke.weight * Math.max(2, node.strokeMiterLimit)\n const left = round(-margin)\n const top = round(-margin)\n const right = round(node.width + margin)\n const bottom = round(node.height + margin)\n const around = `M${left} ${top}H${right}V${bottom}H${left}Z`\n ctx.defs.push(\n svg('clipPath', { id: clipId }, svg('path', { d: around + outline, 'clip-rule': 'evenodd' }))\n )\n }\n return [\n svg('path', {\n d: outline,\n fill: 'none',\n ...strokeAttrs,\n 'stroke-width': round(stroke.weight * 2),\n 'clip-path': `url(#${clipId})`\n })\n ]\n}\n\n/**\n * A FigJam shape's inner lines, such as a database's front rim, stroked as the canvas strokes\n * them: at the stroke's own weight whatever its alignment, ending where the outline does.\n */\nexport function shapeWithTextDetailElements(\n node: SceneNode,\n strokeAttrs: Attrs,\n ctx: SVGExportContext\n): SVGNode[] {\n const details = strokeAttrs.stroke ? shapeWithTextDetailsPath(node) : null\n if (!details) return []\n const clipId = nextDefId(ctx, 'clip')\n ctx.defs.push(svg('clipPath', { id: clipId }, svg('path', { d: shapeWithTextOutlinePath(node) })))\n return [svg('path', { d: details, fill: 'none', ...strokeAttrs, 'clip-path': `url(#${clipId})` })]\n}\n"],"mappings":";;;;;;;;;AAoBA,SAAS,kBAAkB,MAAgC;CACzD,QAAQ,KAAK,MAAb;EACE,KAAK;EACL,KAAK;EACL,KAAK,qBACH,OAAO;EACT,KAAK,mBACH,OAAO,yBAAyB,IAAI;EACtC,KAAK,WACH,OAAO,KAAK,UAAU,OAAO,gBAAgB,IAAI;EACnD,KAAK;EACL,KAAK,QACH,OAAO,gBAAgB,IAAI;EAC7B,SACE,OAAO,eAAe,IAAI;CAC9B;AACF;;AAGA,SAAgB,cAAc,MAAiB,QAA2C;CACxF,IAAI,CAAC,UAAU,OAAO,UAAU,UAAU,OAAO;CACjD,OAAO,kBAAkB,IAAI,MAAM,OAAO,OAAO;AACnD;;;;;AAMA,SAAgB,qBACd,MACA,QACA,aACA,KACW;CACX,MAAM,UAAU,kBAAkB,IAAI;CACtC,IAAI,YAAY,MAAM,OAAO,CAAC;CAC9B,MAAM,SAAS,UAAU,KAAK,MAAM;CACpC,IAAI,OAAO,UAAU,UACnB,IAAI,KAAK,KAAK,IAAI,YAAY,EAAE,IAAI,OAAO,GAAG,IAAI,QAAQ,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC;MACrE;EAGL,MAAM,SAAS,OAAO,SAAS,KAAK,IAAI,GAAG,KAAK,gBAAgB;EAChE,MAAM,OAAO,MAAM,CAAC,MAAM;EAI1B,MAAM,SAAS,IAAI,KAAK,GAHZ,MAAM,CAAC,MAGU,EAAE,GAFjB,MAAM,KAAK,QAAQ,MAEK,EAAE,GADzB,MAAM,KAAK,SAAS,MACa,EAAE,GAAG,KAAK;EAC1D,IAAI,KAAK,KACP,IAAI,YAAY,EAAE,IAAI,OAAO,GAAG,IAAI,QAAQ;GAAE,GAAG,SAAS;GAAS,aAAa;EAAU,CAAC,CAAC,CAC9F;CACF;CACA,OAAO,CACL,IAAI,QAAQ;EACV,GAAG;EACH,MAAM;EACN,GAAG;EACH,gBAAgB,MAAM,OAAO,SAAS,CAAC;EACvC,aAAa,QAAQ,OAAO;CAC9B,CAAC,CACH;AACF;;;;;AAMA,SAAgB,4BACd,MACA,aACA,KACW;CACX,MAAM,UAAU,YAAY,SAAS,yBAAyB,IAAI,IAAI;CACtE,IAAI,CAAC,SAAS,OAAO,CAAC;CACtB,MAAM,SAAS,UAAU,KAAK,MAAM;CACpC,IAAI,KAAK,KAAK,IAAI,YAAY,EAAE,IAAI,OAAO,GAAG,IAAI,QAAQ,EAAE,GAAG,yBAAyB,IAAI,EAAE,CAAC,CAAC,CAAC;CACjG,OAAO,CAAC,IAAI,QAAQ;EAAE,GAAG;EAAS,MAAM;EAAQ,GAAG;EAAa,aAAa,QAAQ,OAAO;CAAG,CAAC,CAAC;AACnG"}
@@ -1 +1 @@
1
- {"version":3,"file":"export.d.ts","names":[],"sources":["../../../../../src/io/formats/svg/text/export.ts"],"mappings":";;;;iBAgLgB,eACd,MAAM,WACN,yBACA,KAAK,kBACL,uBACC"}
1
+ {"version":3,"file":"export.d.ts","names":[],"sources":["../../../../../src/io/formats/svg/text/export.ts"],"mappings":";;;;iBAsMgB,eACd,MAAM,WACN,yBACA,KAAK,kBACL,uBACC"}
@@ -3,7 +3,7 @@ import { textFontFace } from "../../../../text/requirements/collect.js";
3
3
  import { drawnFontVariations } from "../../../../canvas/text/font-families.js";
4
4
  import { svg } from "../node.js";
5
5
  import { round } from "../paths.js";
6
- import { formatColor } from "../defs.js";
6
+ import { formatColor, formatSolidColor } from "../defs.js";
7
7
  import { explicitNewlineLines, laidOutTextSpans, textStyleSpans } from "./lines.js";
8
8
  import { textLengthPixels } from "@pairdraw/scene-graph/text";
9
9
  import { parseFontStyle } from "@pairdraw/scene-graph/font-style";
@@ -63,6 +63,23 @@ function spanFontAttrs(node, style, fallback, fontAlias) {
63
63
  return fallback ? { "font-family": fallback.family } : {};
64
64
  }
65
65
  /**
66
+ * A text layer's stroke, painted on the glyphs themselves. The canvas strokes an outside stroke at
67
+ * twice its weight and clips it to the outside of the glyphs; live text cannot be clipped in SVG,
68
+ * so the same band is painted behind the fill at twice the weight, which hides the inner half. An
69
+ * inside or centred stroke keeps its own weight over the fill.
70
+ */
71
+ function textStrokeAttrs(node, colorSpace) {
72
+ const stroke = node.strokes.find((candidate) => candidate.visible);
73
+ if (!stroke) return {};
74
+ const attrs = {
75
+ stroke: formatSolidColor(stroke.color, 1, colorSpace),
76
+ "stroke-width": round(stroke.weight * (stroke.align === "OUTSIDE" ? 2 : 1))
77
+ };
78
+ if (stroke.opacity < 1) attrs["stroke-opacity"] = round(stroke.opacity);
79
+ if (stroke.align === "OUTSIDE") attrs["paint-order"] = "stroke";
80
+ return attrs;
81
+ }
82
+ /**
66
83
  * The face a run of `node` is drawn in, or the fallback face that draws its characters instead,
67
84
  * with the size and axes its instance follows. A fallback is drawn at the axes the run's own font
68
85
  * is drawn at, as the paragraph draws every font it falls back to.
@@ -136,6 +153,7 @@ function renderTextNode(node, fillAttr, ctx, fillOpacity) {
136
153
  "text-anchor": laidOut ? void 0 : textAnchorForNode(node, direction),
137
154
  "text-decoration": textDecoration,
138
155
  "letter-spacing": letterSpacing ? round(letterSpacing) : void 0,
156
+ ...textStrokeAttrs(node, colorSpace),
139
157
  ...fontAlias ? aliasedFontAttrs(fontRequest(node), fontAlias) : {}
140
158
  };
141
159
  const spanAttrs = (style, fallback) => ({
@@ -1 +1 @@
1
- {"version":3,"file":"export.js","names":[],"sources":["../../../../../src/io/formats/svg/text/export.ts"],"sourcesContent":["import type { CharacterStyleOverride, SceneNode } from '@pairdraw/scene-graph'\nimport { parseFontStyle } from '@pairdraw/scene-graph/font-style'\nimport { textLengthPixels } from '@pairdraw/scene-graph/text'\nimport { resolveNodeTextDirection } from '@pairdraw/scene-graph/text/direction'\n\nimport { drawnFontVariations } from '#core/canvas/text/font-families'\nimport {\n formatColor,\n type SVGExportContext,\n type SVGFontAlias,\n type SVGFontRequest\n} from '#core/io/formats/svg/defs'\nimport { svg, type SVGNode } from '#core/io/formats/svg/node'\nimport { round } from '#core/io/formats/svg/paths'\nimport {\n explicitNewlineLines,\n laidOutTextSpans,\n textStyleSpans,\n type SpanAttrs,\n type SVGFallbackFace\n} from '#core/io/formats/svg/text/lines'\nimport { shownText } from '#core/text/case'\nimport { textFontFace } from '#core/text/requirements/collect'\n\nfunction styleOverrideToTspanAttrs(\n style: CharacterStyleOverride,\n colorSpace: 'srgb' | 'display-p3',\n parentFillOpacity: number | undefined,\n node: Pick<SceneNode, 'fontSize' | 'letterSpacing'>\n): Record<string, string | number | undefined> {\n const attrs: Record<string, string | number | undefined> = {}\n if (style.fontFamily) attrs['font-family'] = style.fontFamily\n if (style.fontSize) attrs['font-size'] = style.fontSize\n if (style.fontWeight) attrs['font-weight'] = style.fontWeight\n if (style.italic) attrs['font-style'] = 'italic'\n // A run's own spacing is written even at zero, or it would inherit the layer's. A percent the\n // run inherits follows its own font size, so a larger or smaller run writes it again.\n const inherited =\n style.fontSize !== undefined &&\n node.letterSpacing.unit === 'PERCENT' &&\n node.letterSpacing.value !== 0\n ? node.letterSpacing\n : undefined\n const spacing = style.letterSpacing ?? inherited\n if (spacing) {\n attrs['letter-spacing'] = round(textLengthPixels(spacing, style.fontSize ?? node.fontSize))\n }\n if (style.textDecoration === 'UNDERLINE') attrs['text-decoration'] = 'underline'\n if (style.textDecoration === 'STRIKETHROUGH') attrs['text-decoration'] = 'line-through'\n if (style.fills) {\n const visibleFill = style.fills.find((f) => f.visible && f.type === 'SOLID')\n if (visibleFill) {\n // Paragraphs and saved glyphs draw a run at color.a * opacity. Shapes paint opacity alone.\n const alpha = round(visibleFill.color.a * visibleFill.opacity)\n if (colorSpace === 'display-p3') {\n attrs.fill = formatColor({ ...visibleFill.color, a: 1 }, alpha, colorSpace)\n } else {\n attrs.fill = formatColor(visibleFill.color, 1, colorSpace)\n if (alpha < 1) attrs['fill-opacity'] = alpha\n }\n // `fill-opacity` inherits, so an opaque run has to cover a translucent parent.\n if (alpha >= 1 && parentFillOpacity !== undefined) attrs['fill-opacity'] = 1\n }\n }\n return attrs\n}\n\n/**\n * Font attributes naming a face's alias, such as the family a PDF embeds its file under, or else\n * the face itself, so text inside an aliased parent does not inherit the alias.\n */\nfunction aliasedFontAttrs(\n face: SVGFontRequest,\n fontAlias: SVGFontAlias\n): Record<string, string | number> {\n const alias = fontAlias(face)\n if (alias) return { 'font-family': alias, 'font-weight': 'normal', 'font-style': 'normal' }\n return {\n 'font-family': face.family,\n 'font-weight': face.weight,\n 'font-style': face.italic ? 'italic' : 'normal'\n }\n}\n\n/**\n * The font attributes of a span: its face's alias where there is one, otherwise the family of the\n * fallback face that draws it, if any.\n */\nfunction spanFontAttrs(\n node: SceneNode,\n style: CharacterStyleOverride,\n fallback: SVGFallbackFace | undefined,\n fontAlias: SVGFontAlias | undefined\n): Record<string, string | number> {\n if (fontAlias) return aliasedFontAttrs(fontRequest(node, style, fallback), fontAlias)\n return fallback ? { 'font-family': fallback.family } : {}\n}\n\n/**\n * The face a run of `node` is drawn in, or the fallback face that draws its characters instead,\n * with the size and axes its instance follows. A fallback is drawn at the axes the run's own font\n * is drawn at, as the paragraph draws every font it falls back to.\n */\nfunction fontRequest(\n node: SceneNode,\n style: CharacterStyleOverride = {},\n fallback?: SVGFallbackFace\n): SVGFontRequest {\n const own: SVGFontRequest = {\n ...textFontFace(node, style),\n fontSize: style.fontSize ?? node.fontSize,\n variations: style.fontVariations ?? node.fontVariations,\n opticalSizeFromFontSize: style.opticalSizeFromFontSize ?? node.opticalSizeFromFontSize\n }\n if (!fallback) return own\n return {\n ...own,\n ...fallback,\n ...parseFontStyle(fallback.style),\n variations: drawnFontVariations(own),\n opticalSizeFromFontSize: false\n }\n}\n\nfunction isLogicalTextEnd(node: SceneNode, direction: 'LTR' | 'RTL'): boolean {\n return (\n (direction === 'LTR' && node.textAlignHorizontal === 'RIGHT') ||\n (direction === 'RTL' && node.textAlignHorizontal === 'LEFT')\n )\n}\n\nfunction textAnchorForNode(\n node: SceneNode,\n direction: 'LTR' | 'RTL'\n): 'middle' | 'end' | undefined {\n if (node.textAlignHorizontal === 'CENTER') return 'middle'\n if (isLogicalTextEnd(node, direction)) return 'end'\n return undefined\n}\n\nfunction textXForNode(node: SceneNode, direction: 'LTR' | 'RTL'): number {\n if (node.textAlignHorizontal === 'CENTER') return round(node.width / 2)\n if (isLogicalTextEnd(node, direction)) return round(node.width)\n return 0\n}\n\n/** Text with no measured layout: explicit newlines on their own baselines, otherwise one line. */\nfunction renderUnmeasuredText(\n node: SceneNode,\n attrs: Record<string, string | number | undefined>,\n spanAttrs: SpanAttrs,\n direction: 'LTR' | 'RTL'\n): SVGNode {\n const x = textXForNode(node, direction)\n const y = node.fontSize || 14\n // No measured wraps: an explicit newline still starts a line, on the same anchor as one line.\n const newlineLines = explicitNewlineLines(node, x, y)\n if (newlineLines) {\n return svg(\n 'text',\n { ...attrs, 'xml:space': 'preserve' },\n ...laidOutTextSpans(node, newlineLines, spanAttrs)\n )\n }\n\n if (node.styleRuns.length > 0) {\n return svg(\n 'text',\n { x, y, ...attrs, 'xml:space': 'preserve' },\n ...textStyleSpans(node, spanAttrs)\n )\n }\n\n return svg('text', { x, y, ...attrs }, shownText(node))\n}\n\nexport function renderTextNode(\n node: SceneNode,\n fillAttr: string | null,\n ctx: SVGExportContext,\n fillOpacity?: number\n): SVGNode {\n const { colorSpace, textLayout, fontAlias } = ctx\n const direction = resolveNodeTextDirection(node)\n const lines = textLayout ? textLayout(node) : null\n const laidOut = lines && lines.length > 0 ? lines : null\n\n let textDecoration: 'underline' | 'line-through' | undefined\n if (node.textDecoration === 'UNDERLINE') textDecoration = 'underline'\n else if (node.textDecoration === 'STRIKETHROUGH') textDecoration = 'line-through'\n const letterSpacing = textLengthPixels(node.letterSpacing, node.fontSize)\n\n const attrs: Record<string, string | number | undefined> = {\n 'font-family': node.fontFamily || undefined,\n 'font-size': node.fontSize || undefined,\n 'font-weight': node.fontWeight !== 400 ? node.fontWeight : undefined,\n 'font-style': node.italic ? 'italic' : undefined,\n fill: fillAttr ?? undefined,\n 'fill-opacity': fillOpacity,\n // Laid-out spans each start at their own left edge, so they take no direction or anchor.\n direction: direction === 'RTL' && !laidOut ? 'rtl' : undefined,\n 'text-anchor': laidOut ? undefined : textAnchorForNode(node, direction),\n 'text-decoration': textDecoration,\n 'letter-spacing': letterSpacing ? round(letterSpacing) : undefined,\n ...(fontAlias ? aliasedFontAttrs(fontRequest(node), fontAlias) : {})\n }\n const spanAttrs = (style: CharacterStyleOverride, fallback?: SVGFallbackFace) => ({\n ...styleOverrideToTspanAttrs(style, colorSpace, fillOpacity, node),\n ...spanFontAttrs(node, style, fallback, fontAlias)\n })\n\n if (laidOut) {\n // Laid-out spans sit where the editor draws them, which keeps every space it draws.\n return svg(\n 'text',\n { ...attrs, 'xml:space': 'preserve' },\n ...laidOutTextSpans(node, laidOut, spanAttrs)\n )\n }\n\n return renderUnmeasuredText(node, attrs, spanAttrs, direction)\n}\n"],"mappings":";;;;;;;;;;;AAwBA,SAAS,0BACP,OACA,YACA,mBACA,MAC6C;CAC7C,MAAM,QAAqD,CAAC;CAC5D,IAAI,MAAM,YAAY,MAAM,iBAAiB,MAAM;CACnD,IAAI,MAAM,UAAU,MAAM,eAAe,MAAM;CAC/C,IAAI,MAAM,YAAY,MAAM,iBAAiB,MAAM;CACnD,IAAI,MAAM,QAAQ,MAAM,gBAAgB;CAGxC,MAAM,YACJ,MAAM,aAAa,KAAA,KACnB,KAAK,cAAc,SAAS,aAC5B,KAAK,cAAc,UAAU,IACzB,KAAK,gBACL,KAAA;CACN,MAAM,UAAU,MAAM,iBAAiB;CACvC,IAAI,SACF,MAAM,oBAAoB,MAAM,iBAAiB,SAAS,MAAM,YAAY,KAAK,QAAQ,CAAC;CAE5F,IAAI,MAAM,mBAAmB,aAAa,MAAM,qBAAqB;CACrE,IAAI,MAAM,mBAAmB,iBAAiB,MAAM,q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EACzD,eAAe,KAAK,cAAc,KAAA;EAClC,aAAa,KAAK,YAAY,KAAA;EAC9B,eAAe,KAAK,eAAe,MAAM,KAAK,aAAa,KAAA;EAC3D,cAAc,KAAK,SAAS,WAAW,KAAA;EACvC,MAAM,YAAY,KAAA;EAClB,gBAAgB;EAEhB,WAAW,cAAc,SAAS,CAAC,UAAU,QAAQ,KAAA;EACrD,eAAe,UAAU,KAAA,IAAY,kBAAkB,MAAM,SAAS;EACtE,mBAAmB;EACnB,kBAAkB,gBAAgB,MAAM,aAAa,IAAI,KAAA;EACzD,GAAI,YAAY,iBAAiB,YAAY,IAAI,GAAG,SAAS,IAAI,CAAC;CACpE;CACA,MAAM,aAAa,OAA+B,cAAgC;EAChF,GAAG,0BAA0B,OAAO,YAAY,aAAa,IAAI;EACjE,GAAG,cAAc,MAAM,OAAO,UAAU,SAAS;CACnD;CAEA,IAAI,SAEF,OAAO,IACL,QACA;EAAE,GAAG;EAAO,aAAa;CAAW,GACpC,GAAG,iBAAiB,MAAM,SAAS,SAAS,CAC9C;CAGF,OAAO,qBAAqB,MAAM,OAAO,WAAW,SAAS;AAC/D"}
1
+ {"version":3,"file":"export.js","names":[],"sources":["../../../../../src/io/formats/svg/text/export.ts"],"sourcesContent":["import type { CharacterStyleOverride, SceneNode } from '@pairdraw/scene-graph'\nimport { parseFontStyle } from '@pairdraw/scene-graph/font-style'\nimport { textLengthPixels } from '@pairdraw/scene-graph/text'\nimport { resolveNodeTextDirection } from '@pairdraw/scene-graph/text/direction'\n\nimport { drawnFontVariations } from '#core/canvas/text/font-families'\nimport {\n formatColor,\n formatSolidColor,\n type SVGExportContext,\n type SVGFontAlias,\n type SVGFontRequest\n} from '#core/io/formats/svg/defs'\nimport { svg, type SVGNode } from '#core/io/formats/svg/node'\nimport { round } from '#core/io/formats/svg/paths'\nimport {\n explicitNewlineLines,\n laidOutTextSpans,\n textStyleSpans,\n type SpanAttrs,\n type SVGFallbackFace\n} from '#core/io/formats/svg/text/lines'\nimport { shownText } from '#core/text/case'\nimport { textFontFace } from '#core/text/requirements/collect'\n\nfunction styleOverrideToTspanAttrs(\n style: CharacterStyleOverride,\n colorSpace: 'srgb' | 'display-p3',\n parentFillOpacity: number | undefined,\n node: Pick<SceneNode, 'fontSize' | 'letterSpacing'>\n): Record<string, string | number | undefined> {\n const attrs: Record<string, string | number | undefined> = {}\n if (style.fontFamily) attrs['font-family'] = style.fontFamily\n if (style.fontSize) attrs['font-size'] = style.fontSize\n if (style.fontWeight) attrs['font-weight'] = style.fontWeight\n if (style.italic) attrs['font-style'] = 'italic'\n // A run's own spacing is written even at zero, or it would inherit the layer's. A percent the\n // run inherits follows its own font size, so a larger or smaller run writes it again.\n const inherited =\n style.fontSize !== undefined &&\n node.letterSpacing.unit === 'PERCENT' &&\n node.letterSpacing.value !== 0\n ? node.letterSpacing\n : undefined\n const spacing = style.letterSpacing ?? inherited\n if (spacing) {\n attrs['letter-spacing'] = round(textLengthPixels(spacing, style.fontSize ?? node.fontSize))\n }\n if (style.textDecoration === 'UNDERLINE') attrs['text-decoration'] = 'underline'\n if (style.textDecoration === 'STRIKETHROUGH') attrs['text-decoration'] = 'line-through'\n if (style.fills) {\n const visibleFill = style.fills.find((f) => f.visible && f.type === 'SOLID')\n if (visibleFill) {\n // Paragraphs and saved glyphs draw a run at color.a * opacity. Shapes paint opacity alone.\n const alpha = round(visibleFill.color.a * visibleFill.opacity)\n if (colorSpace === 'display-p3') {\n attrs.fill = formatColor({ ...visibleFill.color, a: 1 }, alpha, colorSpace)\n } else {\n attrs.fill = formatColor(visibleFill.color, 1, colorSpace)\n if (alpha < 1) attrs['fill-opacity'] = alpha\n }\n // `fill-opacity` inherits, so an opaque run has to cover a translucent parent.\n if (alpha >= 1 && parentFillOpacity !== undefined) attrs['fill-opacity'] = 1\n }\n }\n return attrs\n}\n\n/**\n * Font attributes naming a face's alias, such as the family a PDF embeds its file under, or else\n * the face itself, so text inside an aliased parent does not inherit the alias.\n */\nfunction aliasedFontAttrs(\n face: SVGFontRequest,\n fontAlias: SVGFontAlias\n): Record<string, string | number> {\n const alias = fontAlias(face)\n if (alias) return { 'font-family': alias, 'font-weight': 'normal', 'font-style': 'normal' }\n return {\n 'font-family': face.family,\n 'font-weight': face.weight,\n 'font-style': face.italic ? 'italic' : 'normal'\n }\n}\n\n/**\n * The font attributes of a span: its face's alias where there is one, otherwise the family of the\n * fallback face that draws it, if any.\n */\nfunction spanFontAttrs(\n node: SceneNode,\n style: CharacterStyleOverride,\n fallback: SVGFallbackFace | undefined,\n fontAlias: SVGFontAlias | undefined\n): Record<string, string | number> {\n if (fontAlias) return aliasedFontAttrs(fontRequest(node, style, fallback), fontAlias)\n return fallback ? { 'font-family': fallback.family } : {}\n}\n\n/**\n * A text layer's stroke, painted on the glyphs themselves. The canvas strokes an outside stroke at\n * twice its weight and clips it to the outside of the glyphs; live text cannot be clipped in SVG,\n * so the same band is painted behind the fill at twice the weight, which hides the inner half. An\n * inside or centred stroke keeps its own weight over the fill.\n */\nfunction textStrokeAttrs(\n node: SceneNode,\n colorSpace: 'srgb' | 'display-p3'\n): Record<string, string | number | undefined> {\n const stroke = node.strokes.find((candidate) => candidate.visible)\n if (!stroke) return {}\n const attrs: Record<string, string | number | undefined> = {\n stroke: formatSolidColor(stroke.color, 1, colorSpace),\n 'stroke-width': round(stroke.weight * (stroke.align === 'OUTSIDE' ? 2 : 1))\n }\n if (stroke.opacity < 1) attrs['stroke-opacity'] = round(stroke.opacity)\n if (stroke.align === 'OUTSIDE') attrs['paint-order'] = 'stroke'\n return attrs\n}\n\n/**\n * The face a run of `node` is drawn in, or the fallback face that draws its characters instead,\n * with the size and axes its instance follows. A fallback is drawn at the axes the run's own font\n * is drawn at, as the paragraph draws every font it falls back to.\n */\nfunction fontRequest(\n node: SceneNode,\n style: CharacterStyleOverride = {},\n fallback?: SVGFallbackFace\n): SVGFontRequest {\n const own: SVGFontRequest = {\n ...textFontFace(node, style),\n fontSize: style.fontSize ?? node.fontSize,\n variations: style.fontVariations ?? node.fontVariations,\n opticalSizeFromFontSize: style.opticalSizeFromFontSize ?? node.opticalSizeFromFontSize\n }\n if (!fallback) return own\n return {\n ...own,\n ...fallback,\n ...parseFontStyle(fallback.style),\n variations: drawnFontVariations(own),\n opticalSizeFromFontSize: false\n }\n}\n\nfunction isLogicalTextEnd(node: SceneNode, direction: 'LTR' | 'RTL'): boolean {\n return (\n (direction === 'LTR' && node.textAlignHorizontal === 'RIGHT') ||\n (direction === 'RTL' && node.textAlignHorizontal === 'LEFT')\n )\n}\n\nfunction textAnchorForNode(\n node: SceneNode,\n direction: 'LTR' | 'RTL'\n): 'middle' | 'end' | undefined {\n if (node.textAlignHorizontal === 'CENTER') return 'middle'\n if (isLogicalTextEnd(node, direction)) return 'end'\n return undefined\n}\n\nfunction textXForNode(node: SceneNode, direction: 'LTR' | 'RTL'): number {\n if (node.textAlignHorizontal === 'CENTER') return round(node.width / 2)\n if (isLogicalTextEnd(node, direction)) return round(node.width)\n return 0\n}\n\n/** Text with no measured layout: explicit newlines on their own baselines, otherwise one line. */\nfunction renderUnmeasuredText(\n node: SceneNode,\n attrs: Record<string, string | number | undefined>,\n spanAttrs: SpanAttrs,\n direction: 'LTR' | 'RTL'\n): SVGNode {\n const x = textXForNode(node, direction)\n const y = node.fontSize || 14\n // No measured wraps: an explicit newline still starts a line, on the same anchor as one line.\n const newlineLines = explicitNewlineLines(node, x, y)\n if (newlineLines) {\n return svg(\n 'text',\n { ...attrs, 'xml:space': 'preserve' },\n ...laidOutTextSpans(node, newlineLines, spanAttrs)\n )\n }\n\n if (node.styleRuns.length > 0) {\n return svg(\n 'text',\n { x, y, ...attrs, 'xml:space': 'preserve' },\n ...textStyleSpans(node, spanAttrs)\n )\n }\n\n return svg('text', { x, y, ...attrs }, shownText(node))\n}\n\nexport function renderTextNode(\n node: SceneNode,\n fillAttr: string | null,\n ctx: SVGExportContext,\n fillOpacity?: number\n): SVGNode {\n const { colorSpace, textLayout, fontAlias } = ctx\n const direction = resolveNodeTextDirection(node)\n const lines = textLayout ? textLayout(node) : null\n const laidOut = lines && lines.length > 0 ? lines : null\n\n let textDecoration: 'underline' | 'line-through' | undefined\n if (node.textDecoration === 'UNDERLINE') textDecoration = 'underline'\n else if (node.textDecoration === 'STRIKETHROUGH') textDecoration = 'line-through'\n const letterSpacing = textLengthPixels(node.letterSpacing, node.fontSize)\n\n const attrs: Record<string, string | number | undefined> = {\n 'font-family': node.fontFamily || undefined,\n 'font-size': node.fontSize || undefined,\n 'font-weight': node.fontWeight !== 400 ? node.fontWeight : undefined,\n 'font-style': node.italic ? 'italic' : undefined,\n fill: fillAttr ?? undefined,\n 'fill-opacity': fillOpacity,\n // Laid-out spans each start at their own left edge, so they take no direction or anchor.\n direction: direction === 'RTL' && !laidOut ? 'rtl' : undefined,\n 'text-anchor': laidOut ? undefined : textAnchorForNode(node, direction),\n 'text-decoration': textDecoration,\n 'letter-spacing': letterSpacing ? round(letterSpacing) : undefined,\n ...textStrokeAttrs(node, colorSpace),\n ...(fontAlias ? aliasedFontAttrs(fontRequest(node), fontAlias) : {})\n }\n const spanAttrs = (style: CharacterStyleOverride, fallback?: SVGFallbackFace) => ({\n ...styleOverrideToTspanAttrs(style, colorSpace, fillOpacity, node),\n ...spanFontAttrs(node, style, fallback, fontAlias)\n })\n\n if (laidOut) {\n // Laid-out spans sit where the editor draws them, which keeps every space it draws.\n return svg(\n 'text',\n { ...attrs, 'xml:space': 'preserve' },\n ...laidOutTextSpans(node, laidOut, spanAttrs)\n )\n }\n\n return renderUnmeasuredText(node, attrs, spanAttrs, direction)\n}\n"],"mappings":";;;;;;;;;;;AAyBA,SAAS,0BACP,OACA,YACA,mBACA,MAC6C;CAC7C,MAAM,QAAqD,CAAC;CAC5D,IAAI,MAAM,YAAY,MAAM,iBAAiB,MAAM;CACnD,IAAI,MAAM,UAAU,MAAM,eAAe,MAAM;CAC/C,IAAI,MAAM,YAAY,MAAM,iBAAiB,MAAM;CACnD,IAAI,MAAM,QAAQ,MAAM,gB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I;EACjE,GAAG,cAAc,MAAM,OAAO,UAAU,SAAS;CACnD;CAEA,IAAI,SAEF,OAAO,IACL,QACA;EAAE,GAAG;EAAO,aAAa;CAAW,GACpC,GAAG,iBAAiB,MAAM,SAAS,SAAS,CAC9C;CAGF,OAAO,qBAAqB,MAAM,OAAO,WAAW,SAAS;AAC/D"}
@@ -1 +1 @@
1
- {"version":3,"file":"import.d.ts","names":[],"sources":["../../../../../src/io/formats/svg/text/import.ts"],"mappings":";;;;;iBA4GgB,cACd,OAAO,YACP,kBACA,MAAM,gBACN,SAAS,iBACT,cAAc,kBAAkB,OAAO,QAAQ;;iBAmBjC,eAAe,MAAM,KAAK,+BAA+B;EACvE;EACA;EACA"}
1
+ {"version":3,"file":"import.d.ts","names":[],"sources":["../../../../../src/io/formats/svg/text/import.ts"],"mappings":";;;;;iBA6GgB,cACd,OAAO,YACP,kBACA,MAAM,gBACN,SAAS,iBACT,cAAc,kBAAkB,OAAO,QAAQ;;iBAmBjC,eAAe,MAAM,KAAK,+BAA+B;EACvE;EACA;EACA"}
@@ -3,6 +3,7 @@ import { localTransformFromWorld } from "@pairdraw/scene-graph/coordinate";
3
3
  import { pixelLength } from "@pairdraw/scene-graph/text";
4
4
  import { faceLoadKey } from "@pairdraw/scene-graph/font-style";
5
5
  import Matrix from "@pairdraw/scene-graph/matrix";
6
+ import { textLayerName } from "@pairdraw/scene-graph/node-defaults";
6
7
  import { isEqual } from "es-toolkit/predicate";
7
8
  //#region src/io/formats/svg/text/import.ts
8
9
  const ALIGN = {
@@ -53,7 +54,7 @@ function createTextPiece(graph, parentId, piece, matrix, props) {
53
54
  const scale = Math.hypot(matrix[0], matrix[3]) || 1;
54
55
  const characters = piece.runs.map((run) => run.text).join("");
55
56
  const node = graph.createNode("TEXT", parentId, {
56
- name: characters,
57
+ name: textLayerName("TEXT", characters),
57
58
  ...props,
58
59
  ...runStyle(piece.runs[0], scale),
59
60
  text: characters,
@@ -1 +1 @@
1
- {"version":3,"file":"import.js","names":[],"sources":["../../../../../src/io/formats/svg/text/import.ts"],"sourcesContent":["import { isEqual } from 'es-toolkit/predicate'\n\nimport type { CharacterStyleOverride, SceneGraph, SceneNode, StyleRun } from '@pairdraw/scene-graph'\nimport { localTransformFromWorld } from '@pairdraw/scene-graph/coordinate'\nimport { faceLoadKey } from '@pairdraw/scene-graph/font-style'\nimport Matrix from '@pairdraw/scene-graph/matrix'\nimport { pixelLength } from '@pairdraw/scene-graph/text'\n\nimport type { SVGElementLayer } from '#core/icons/types'\nimport { measureTextForLayout } from '#core/layout/text-measurement'\nimport type {\n SVGVectorizeResult,\n VectorizedText,\n VectorizedTextPiece\n} from '#core/vector/vectorize/svg/to-vectors'\n\nconst ALIGN = { start: 'LEFT', middle: 'CENTER', end: 'RIGHT' } as const\n/** How much of its width a text anchored this way sits left of `x`. */\nconst ANCHOR_OFFSET = { start: 0, middle: 0.5, end: 1 } as const\n\ntype Run = VectorizedTextPiece['runs'][number]\n\n/** A run's style in the text's own units; `scale` takes SVG units to the import's. */\nfunction runStyle(\n run: Run,\n scale: number\n): Required<\n Pick<\n CharacterStyleOverride,\n | 'fontFamily'\n | 'fontSize'\n | 'fontWeight'\n | 'italic'\n | 'letterSpacing'\n | 'textDecoration'\n | 'fills'\n >\n> {\n return {\n // Figma imports SVG text in a font it does not know as Inter.\n fontFamily: run.fontFamily ?? 'Inter',\n fontSize: run.fontSize * scale,\n fontWeight: run.fontWeight,\n italic: run.italic,\n letterSpacing: pixelLength(run.letterSpacing * scale),\n textDecoration: run.textDecoration,\n fills: run.fills\n }\n}\n\n/** Later runs as style runs over the first run's style, which the layer takes. */\nfunction styleRuns(runs: Run[], scale: number): StyleRun[] {\n const base = runStyle(runs[0], scale)\n const result: StyleRun[] = []\n let start = 0\n for (const run of runs) {\n const style = runStyle(run, scale)\n const override = Object.fromEntries(\n Object.entries(style).filter(\n ([key, value]) => !isEqual(value, base[key as keyof typeof base])\n )\n ) as CharacterStyleOverride\n if (Object.keys(override).length > 0)\n result.push({ start, length: run.text.length, style: override })\n start += run.text.length\n }\n return result\n}\n\n/**\n * A text layer sized to its characters and placed as Figma places SVG text: its top a font size\n * above the baseline, its left, centre, or right edge on `x` by `text-anchor`.\n */\nfunction createTextPiece(\n graph: SceneGraph,\n parentId: string,\n piece: VectorizedTextPiece,\n matrix: VectorizedText['matrix'],\n props: Partial<SceneNode>\n): SceneNode {\n const scale = Math.hypot(matrix[0], matrix[3]) || 1\n const characters = piece.runs.map((run) => run.text).join('')\n const node = graph.createNode('TEXT', parentId, {\n name: characters,\n ...props,\n ...runStyle(piece.runs[0], scale),\n text: characters,\n styleRuns: styleRuns(piece.runs, scale),\n textAlignHorizontal: ALIGN[piece.anchor],\n textAutoResize: 'WIDTH_AND_HEIGHT',\n lineHeight: null,\n width: 0\n })\n const size = measureTextForLayout(node)\n const width = size.width / scale\n const left = width * ANCHOR_OFFSET[piece.anchor]\n const world = Matrix.multiply(\n matrix,\n Matrix.translated(piece.x - left, piece.y - piece.runs[0].fontSize),\n Matrix.scaled(1 / scale, 1 / scale)\n )\n const sized = { ...node, width: size.width, height: size.height }\n const place = localTransformFromWorld(sized, world, Matrix.identity())\n graph.updateNode(node.id, { width: size.width, height: size.height, ...place })\n return node\n}\n\n/** Text layers for a `<text>`; one with several pieces is a group of them, as in Figma. */\nexport function createSVGText(\n graph: SceneGraph,\n parentId: string,\n text: VectorizedText,\n element: SVGElementLayer,\n createGroup: (parentId: string, props: Partial<SceneNode>) => string\n): void {\n if (text.pieces.length === 1) {\n createTextPiece(graph, parentId, text.pieces[0], text.matrix, {\n ...(element.name ? { name: element.name } : {}),\n opacity: element.opacity,\n visible: element.visible\n })\n return\n }\n const groupId = createGroup(parentId, {\n name: element.name ?? 'Group',\n opacity: element.opacity,\n visible: element.visible\n })\n for (const piece of text.pieces) createTextPiece(graph, groupId, piece, text.matrix, {})\n}\n\n/** The fonts an import's text is drawn in, to load before it is measured and placed. */\nexport function svgImportFonts(data: Pick<SVGVectorizeResult, 'texts'>): Array<{\n family: string\n style: string\n characters: string\n}> {\n const fonts = new Map<string, { family: string; style: string; characters: string }>()\n for (const run of data.texts.flatMap((text) => text.pieces.flatMap((piece) => piece.runs))) {\n const family = run.fontFamily ?? 'Inter'\n const style = faceLoadKey(run.fontWeight, run.italic)\n const key = `${family}\\u0000${style}`\n const font = fonts.get(key) ?? { family, style, characters: '' }\n fonts.set(key, { ...font, characters: font.characters + run.text })\n }\n return [...fonts.values()]\n}\n"],"mappings":";;;;;;;AAgBA,MAAM,QAAQ;CAAE,OAAO;CAAQ,QAAQ;CAAU,KAAK;AAAQ;;AAE9D,MAAM,gBAAgB;CAAE,OAAO;CAAG,QAAQ;CAAK,KAAK;AAAE;;AAKtD,SAAS,SACP,KACA,OAYA;CACA,OAAO;EAEL,YAAY,IAAI,cAAc;EAC9B,UAAU,IAAI,WAAW;EACzB,YAAY,IAAI;EAChB,QAAQ,IAAI;EACZ,eAAe,YAAY,IAAI,gBAAgB,KAAK;EACpD,gBAAgB,IAAI;EACpB,OAAO,IAAI;CACb;AACF;;AAGA,SAAS,UAAU,MAAa,OAA2B;CACzD,MAAM,OAAO,SAAS,KAAK,IAAI,KAAK;CACpC,MAAM,SAAqB,CAAC;CAC5B,IAAI,QAAQ;CACZ,KAAK,MAAM,OAAO,MAAM;EACtB,MAAM,QAAQ,SAAS,KAAK,KAAK;EACjC,MAAM,WAAW,OAAO,YACtB,OAAO,QAAQ,KAAK,CAAC,CAAC,QACnB,CAAC,KAAK,WAAW,CAAC,QAAQ,OAAO,KAAK,IAAyB,CAClE,CACF;EACA,IAAI,OAAO,KAAK,QAAQ,CAAC,CAAC,SAAS,GACjC,OAAO,KAAK;GAAE;GAAO,QAAQ,IAAI,KAAK;GAAQ,OAAO;EAAS,CAAC;EACjE,SAAS,IAAI,KAAK;CACpB;CACA,OAAO;AACT;;;;;AAMA,SAAS,gBACP,OACA,UACA,OACA,QACA,OACW;CACX,MAAM,QAAQ,KAAK,MAAM,OAAO,IAAI,OAAO,EAAE,K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,QAAQ,CAAC,CAAC;AACzF;;AAGA,SAAgB,eAAe,MAI5B;CACD,MAAM,wBAAQ,IAAI,IAAmE;CACrF,KAAK,MAAM,OAAO,KAAK,MAAM,SAAS,SAAS,KAAK,OAAO,SAAS,UAAU,MAAM,IAAI,CAAC,GAAG;EAC1F,MAAM,SAAS,IAAI,cAAc;EACjC,MAAM,QAAQ,YAAY,IAAI,YAAY,IAAI,MAAM;EACpD,MAAM,MAAM,GAAG,OAAO,QAAQ;EAC9B,MAAM,OAAO,MAAM,IAAI,GAAG,KAAK;GAAE;GAAQ;GAAO,YAAY;EAAG;EAC/D,MAAM,IAAI,KAAK;GAAE,GAAG;GAAM,YAAY,KAAK,aAAa,IAAI;EAAK,CAAC;CACpE;CACA,OAAO,CAAC,GAAG,MAAM,OAAO,CAAC;AAC3B"}
1
+ {"version":3,"file":"import.js","names":[],"sources":["../../../../../src/io/formats/svg/text/import.ts"],"sourcesContent":["import { isEqual } from 'es-toolkit/predicate'\n\nimport type { CharacterStyleOverride, SceneGraph, SceneNode, StyleRun } from '@pairdraw/scene-graph'\nimport { localTransformFromWorld } from '@pairdraw/scene-graph/coordinate'\nimport { faceLoadKey } from '@pairdraw/scene-graph/font-style'\nimport Matrix from '@pairdraw/scene-graph/matrix'\nimport { textLayerName } from '@pairdraw/scene-graph/node-defaults'\nimport { pixelLength } from '@pairdraw/scene-graph/text'\n\nimport type { SVGElementLayer } from '#core/icons/types'\nimport { measureTextForLayout } from '#core/layout/text-measurement'\nimport type {\n SVGVectorizeResult,\n VectorizedText,\n VectorizedTextPiece\n} from '#core/vector/vectorize/svg/to-vectors'\n\nconst ALIGN = { start: 'LEFT', middle: 'CENTER', end: 'RIGHT' } as const\n/** How much of its width a text anchored this way sits left of `x`. */\nconst ANCHOR_OFFSET = { start: 0, middle: 0.5, end: 1 } as const\n\ntype Run = VectorizedTextPiece['runs'][number]\n\n/** A run's style in the text's own units; `scale` takes SVG units to the import's. */\nfunction runStyle(\n run: Run,\n scale: number\n): Required<\n Pick<\n CharacterStyleOverride,\n | 'fontFamily'\n | 'fontSize'\n | 'fontWeight'\n | 'italic'\n | 'letterSpacing'\n | 'textDecoration'\n | 'fills'\n >\n> {\n return {\n // Figma imports SVG text in a font it does not know as Inter.\n fontFamily: run.fontFamily ?? 'Inter',\n fontSize: run.fontSize * scale,\n fontWeight: run.fontWeight,\n italic: run.italic,\n letterSpacing: pixelLength(run.letterSpacing * scale),\n textDecoration: run.textDecoration,\n fills: run.fills\n }\n}\n\n/** Later runs as style runs over the first run's style, which the layer takes. */\nfunction styleRuns(runs: Run[], scale: number): StyleRun[] {\n const base = runStyle(runs[0], scale)\n const result: StyleRun[] = []\n let start = 0\n for (const run of runs) {\n const style = runStyle(run, scale)\n const override = Object.fromEntries(\n Object.entries(style).filter(\n ([key, value]) => !isEqual(value, base[key as keyof typeof base])\n )\n ) as CharacterStyleOverride\n if (Object.keys(override).length > 0)\n result.push({ start, length: run.text.length, style: override })\n start += run.text.length\n }\n return result\n}\n\n/**\n * A text layer sized to its characters and placed as Figma places SVG text: its top a font size\n * above the baseline, its left, centre, or right edge on `x` by `text-anchor`.\n */\nfunction createTextPiece(\n graph: SceneGraph,\n parentId: string,\n piece: VectorizedTextPiece,\n matrix: VectorizedText['matrix'],\n props: Partial<SceneNode>\n): SceneNode {\n const scale = Math.hypot(matrix[0], matrix[3]) || 1\n const characters = piece.runs.map((run) => run.text).join('')\n const node = graph.createNode('TEXT', parentId, {\n name: textLayerName('TEXT', characters),\n ...props,\n ...runStyle(piece.runs[0], scale),\n text: characters,\n styleRuns: styleRuns(piece.runs, scale),\n textAlignHorizontal: ALIGN[piece.anchor],\n textAutoResize: 'WIDTH_AND_HEIGHT',\n lineHeight: null,\n width: 0\n })\n const size = measureTextForLayout(node)\n const width = size.width / scale\n const left = width * ANCHOR_OFFSET[piece.anchor]\n const world = Matrix.multiply(\n matrix,\n Matrix.translated(piece.x - left, piece.y - piece.runs[0].fontSize),\n Matrix.scaled(1 / scale, 1 / scale)\n )\n const sized = { ...node, width: size.width, height: size.height }\n const place = localTransformFromWorld(sized, world, Matrix.identity())\n graph.updateNode(node.id, { width: size.width, height: size.height, ...place })\n return node\n}\n\n/** Text layers for a `<text>`; one with several pieces is a group of them, as in Figma. */\nexport function createSVGText(\n graph: SceneGraph,\n parentId: string,\n text: VectorizedText,\n element: SVGElementLayer,\n createGroup: (parentId: string, props: Partial<SceneNode>) => string\n): void {\n if (text.pieces.length === 1) {\n createTextPiece(graph, parentId, text.pieces[0], text.matrix, {\n ...(element.name ? { name: element.name } : {}),\n opacity: element.opacity,\n visible: element.visible\n })\n return\n }\n const groupId = createGroup(parentId, {\n name: element.name ?? 'Group',\n opacity: element.opacity,\n visible: element.visible\n })\n for (const piece of text.pieces) createTextPiece(graph, groupId, piece, text.matrix, {})\n}\n\n/** The fonts an import's text is drawn in, to load before it is measured and placed. */\nexport function svgImportFonts(data: Pick<SVGVectorizeResult, 'texts'>): Array<{\n family: string\n style: string\n characters: string\n}> {\n const fonts = new Map<string, { family: string; style: string; characters: string }>()\n for (const run of data.texts.flatMap((text) => text.pieces.flatMap((piece) => piece.runs))) {\n const family = run.fontFamily ?? 'Inter'\n const style = faceLoadKey(run.fontWeight, run.italic)\n const key = `${family}\\u0000${style}`\n const font = fonts.get(key) ?? { family, style, characters: '' }\n fonts.set(key, { ...font, characters: font.characters + run.text })\n }\n return [...fonts.values()]\n}\n"],"mappings":";;;;;;;;AAiBA,MAAM,QAAQ;CAAE,OAAO;CAAQ,QAAQ;CAAU,KAAK;AAAQ;;AAE9D,MAAM,gBAAgB;CAAE,OAAO;CAAG,QAAQ;CAAK,KAAK;AAAE;;AAKtD,SAAS,SACP,KACA,OAYA;CACA,OAAO;EAEL,YAAY,IAAI,cAAc;EAC9B,UAAU,IAAI,WAAW;EACzB,YAAY,IAAI;EAChB,QAAQ,IAAI;EACZ,eAAe,YAAY,IAAI,gBAAgB,KAAK;EACpD,gBAAgB,IAAI;EACpB,OAAO,IAAI;CACb;AACF;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WAAW;cA8DX,cAAc;cA2Dd,eAAe;cAsCf,WAAS;cACT,WAAS;cACT,YAAU;cAEV,WAAW;cA4DX,WAAW;cAqCX,YAAY;cA2BZ,WAAW;cA2BX,YAAY;cA8BZ,mBAAmB;cA4BnB,8BAAkB,wBAAA,wBAAA,2BAAA,4BAAA,wBAAA,wBAAA,yBAAA,wBAAA,wBAAA,yBAAA,wBAAA,iCAAA;KAgBnB,4BAA4B"}
1
+ {"version":3,"file":"formats.d.ts","names":[],"sources":["../../src/io/formats.ts"],"mappings":";;;;;cAiKa,qBAAqB,SAAS,OAAO;cAKrC,WAAW;cA8DX,cAAc;cA2Dd,eAAe;cAwCf,WAAS;cACT,WAAS;cACT,YAAU;cAEV,WAAW;cA4DX,WAAW;cAqCX,YAAY;cA2BZ,WAAW;cA2BX,YAAY;cA8BZ,mBAAmB;cA4BnB,8BAAkB,wBAAA,wBAAA,2BAAA,4BAAA,wBAAA,wBAAA,yBAAA,wBAAA,wBAAA,yBAAA,wBAAA,iCAAA;KAgBnB,4BAA4B"}
@@ -255,12 +255,14 @@ const mermaidFormat = {
255
255
  async function writeDrawIO(graph, target) {
256
256
  const { writeDrawIOFile } = await import("@pairdraw/drawio");
257
257
  const { sceneGraphToDrawIO } = await import("./formats/drawio/index.js");
258
+ const { drawioDroppedWarnings } = await import("./formats/drawio/warnings.js");
258
259
  return {
259
260
  format: "drawio",
260
261
  mimeType: "application/vnd.jgraph.mxfile",
261
262
  extension: "drawio",
262
263
  data: writeDrawIOFile(sceneGraphToDrawIO(graph, target)),
263
- encoding: "utf8"
264
+ encoding: "utf8",
265
+ warnings: drawioDroppedWarnings(graph)
264
266
  };
265
267
  }
266
268
  const pngFormat = rasterFormat("PNG");
@@ -1 +1 @@
1
- {"version":3,"file":"formats.js","names":[],"sources":["../../src/io/formats.ts"],"sourcesContent":["import { filename } from 'pathe/utils'\n\nimport { sceneNodeToJSX, selectionToJSX } from '@pairdraw/design-jsx'\nimport { isDrawIOExportFileName } from '@pairdraw/drawio'\nimport type { DocumentKind, SceneGraph } from '@pairdraw/scene-graph'\n\nimport { layoutAuthoredNodes } from '#core/layout'\n\nimport type { DrawIOExportTarget } from './formats/drawio/export'\nimport { exportFigFile, parseFigFile } from './formats/fig'\nimport type { PDFPageSpec } from './formats/pdf/plan'\nimport { penFormat } from './formats/pen'\nimport type { PPTXExportOptions } from './formats/pptx'\nimport { headlessRenderNodes, renderNodesToImage, type RasterExportFormat } from './formats/raster'\nimport { extractExportGraph, findPageId } from './subgraph'\nimport type {\n ExportRequest,\n ExportResult,\n FigWriteOptions,\n HTMLExportOptions,\n IOContext,\n IOFormatAdapter,\n IOFormatExportOptions,\n IOFormatSupport,\n PDFFormatExportOptions,\n RasterExportOptions,\n SVGExportOptions\n} from './types'\n\n/** Formats that export a document, page, selection, or single node alike. */\nconst EXPORT_EVERY_TARGET: IOFormatSupport = {\n exportDocument: true,\n exportPage: true,\n exportSelection: true,\n exportNode: true\n}\n\n/** Formats with a size of their own, so no export scale or quality. */\nconst FIXED_SIZE_EXPORT: IOFormatExportOptions = { scale: false, quality: false }\n\nfunction lowerExt(name: string): string {\n const match = /\\.([^.]+)$/.exec(name.toLowerCase())\n return match?.[1] ?? ''\n}\n\nfunction ensureSingleNode(target: ExportRequest['target']): string | null {\n if (target.scope === 'node') return target.nodeId\n if (target.scope === 'selection' && target.nodeIds.length === 1) return target.nodeIds[0]\n return null\n}\n\nfunction resolveExportNodes(request: ExportRequest): { pageId: string; nodeIds: string[] } | null {\n switch (request.target.scope) {\n case 'document': {\n const page = request.graph.getPages()[0]\n return { pageId: page.id, nodeIds: page.childIds }\n }\n case 'page': {\n const page = request.graph.getNode(request.target.pageId)\n if (!page) return null\n return { pageId: page.id, nodeIds: page.childIds }\n }\n case 'selection': {\n const first = request.target.nodeIds[0]\n if (!first) return null\n const pageId = findPageId(request.graph, first)\n if (!pageId) return null\n if (!request.target.nodeIds.every((nodeId) => findPageId(request.graph, nodeId) === pageId)) {\n throw new Error('Export selection must stay on a single page')\n }\n return { pageId, nodeIds: request.target.nodeIds }\n }\n case 'node':\n return resolveExportNodes({\n ...request,\n target: { scope: 'selection', nodeIds: [request.target.nodeId] }\n })\n default:\n return null\n }\n}\n\nasync function renderRaster(\n request: ExportRequest,\n options: RasterExportOptions,\n context?: IOContext\n): Promise<Uint8Array | null> {\n const target = resolveExportNodes(request)\n if (!target) return null\n const scale = options.scale ?? 1\n\n if (context?.canvasKit && context.renderer) {\n return renderNodesToImage(\n context.canvasKit,\n context.renderer,\n request.graph,\n target.pageId,\n target.nodeIds,\n {\n scale,\n format: options.format,\n quality: options.quality,\n trimTransparent: request.target.scope === 'page' || request.target.scope === 'document'\n }\n )\n }\n\n return headlessRenderNodes(request.graph, target.pageId, target.nodeIds, {\n scale,\n format: options.format,\n quality: options.quality,\n trimTransparent: request.target.scope === 'page' || request.target.scope === 'document'\n })\n}\n\nfunction rasterFormat<F extends RasterExportFormat>(format: F): IOFormatAdapter<Lowercase<F>> {\n const extension = format.toLowerCase() as Lowercase<F>\n let mimeType = 'image/png'\n if (format === 'JPG') mimeType = 'image/jpeg'\n else if (format === 'WEBP') mimeType = 'image/webp'\n\n return {\n id: extension,\n label: format,\n role: 'derived-export',\n category: 'raster',\n extensions: [extension],\n mimeTypes: [mimeType],\n support: {\n exportDocument: true,\n exportPage: true,\n exportSelection: true,\n exportNode: true\n },\n exportOptions: {\n scale: true,\n quality: format !== 'PNG',\n colorSpace: false\n },\n async exportContent(request, options?: RasterExportOptions, context?: IOContext) {\n const data = await renderRaster(\n request,\n {\n format,\n scale: options?.scale,\n quality: options?.quality\n },\n context\n )\n if (!data) throw new Error('Nothing to export')\n return {\n format: extension,\n mimeType,\n extension,\n data\n }\n }\n }\n}\n\n/** The file a document saves as: Figma's `.fig` for a design, FigJam's `.jam` for a board. */\nexport const DOCUMENT_EXTENSIONS: Readonly<Record<DocumentKind, 'fig' | 'jam'>> = {\n design: 'fig',\n board: 'jam'\n}\n\nexport const figFormat: IOFormatAdapter<'fig'> = {\n id: 'fig',\n label: 'Pairdraw Document',\n role: 'native-document',\n category: 'document',\n extensions: ['fig', 'jam'],\n mimeTypes: ['application/octet-stream'],\n support: {\n readDocument: true,\n writeDocument: true,\n exportDocument: true,\n exportPage: true,\n exportSelection: true,\n exportNode: true\n },\n exportOptions: FIXED_SIZE_EXPORT,\n matchesFile(fileName) {\n const ext = lowerExt(fileName)\n return ext === 'fig' || ext === 'jam'\n },\n async readDocument(input) {\n const data = input.data.slice().buffer\n const graph = await parseFigFile(data, { populate: 'first-page' })\n return { graph, sourceFormat: 'fig' }\n },\n async writeDocument(graph, options?: FigWriteOptions, context?: IOContext) {\n return writeFig(graph, options, context, options?.thumbnailPageId)\n },\n async exportContent(request, options?: FigWriteOptions, context?: IOContext) {\n // A whole document is written as it is, so one opened from an archive keeps that archive.\n if (request.target.scope === 'document')\n return writeFig(request.graph, options, context, options?.thumbnailPageId, request.fileName)\n const extracted = extractExportGraph(request.graph, request.target)\n return writeFig(\n extracted.graph,\n options,\n context,\n options?.thumbnailPageId ?? extracted.pageId ?? undefined,\n request.fileName\n )\n }\n}\n\n/** A `.fig` named as asked, or else after the file it is written to, or else Untitled. */\nasync function writeFig(\n graph: SceneGraph,\n options: FigWriteOptions | undefined,\n context: IOContext | undefined,\n pageId: string | undefined,\n fileName?: string\n): Promise<ExportResult> {\n const data = await exportFigFile(graph, {\n ck: context?.canvasKit,\n renderer: context?.renderer,\n pageId,\n renderHeadlessThumbnail: options?.renderThumbnail ?? false,\n documentName: options?.documentName ?? (fileName && filename(fileName))\n })\n const extension = DOCUMENT_EXTENSIONS[graph.documentKind]\n return { format: 'fig', mimeType: 'application/octet-stream', extension, data }\n}\n\nexport const drawioFormat: IOFormatAdapter<'drawio'> = {\n id: 'drawio',\n label: 'draw.io Diagram',\n role: 'interchange-document',\n category: 'document',\n extensions: ['drawio', 'dio'],\n mimeTypes: ['application/vnd.jgraph.mxfile'],\n support: {\n readDocument: true,\n writeDocument: true,\n exportDocument: true,\n exportPage: true,\n exportSelection: true,\n exportNode: true\n },\n exportOptions: FIXED_SIZE_EXPORT,\n laysOutOnRead: true,\n // A draw.io PNG or SVG export opens as its diagram when its name says it is one.\n matchesFile(fileName, mimeType) {\n const ext = lowerExt(fileName)\n return (\n ext === 'drawio' ||\n ext === 'dio' ||\n isDrawIOExportFileName(fileName) ||\n mimeType === 'application/vnd.jgraph.mxfile'\n )\n },\n async readDocument(input) {\n const { readDrawIOBytes } = await import('@pairdraw/drawio')\n const { drawioToSceneGraph } = await import('./formats/drawio')\n const file = readDrawIOBytes(input.data)\n if (!file) throw new Error('This file holds no draw.io diagram')\n if (file.unreadable.length > 0) {\n throw new Error(`Could not read the draw.io pages ${file.unreadable.join(', ')}`)\n }\n const graph = drawioToSceneGraph(file)\n // draw.io stores label text, not the sizes it lays out to.\n layoutAuthoredNodes(\n graph,\n graph.getPages().map((page) => page.id)\n )\n return { graph, sourceFormat: 'drawio' }\n },\n async writeDocument(graph) {\n const pageIds = graph.getPages().map((page) => page.id)\n return writeDrawIO(graph, { pageIds })\n },\n // A page or a selection goes as a one-page diagram; the document, every page.\n async exportContent(request) {\n if (request.target.scope === 'document') {\n const pageIds = request.graph.getPages().map((page) => page.id)\n return writeDrawIO(request.graph, { pageIds })\n }\n const target = resolveExportNodes(request)\n if (!target) throw new Error('Nothing to export')\n return writeDrawIO(request.graph, target)\n }\n}\n\nexport const mermaidFormat: IOFormatAdapter<'mermaid'> = {\n id: 'mermaid',\n label: 'Mermaid Diagram',\n role: 'interchange-document',\n category: 'document',\n extensions: ['mmd', 'mermaid'],\n mimeTypes: ['text/vnd.mermaid'],\n support: {\n readDocument: true\n },\n laysOutOnRead: true,\n matchesFile(fileName, mimeType) {\n const ext = lowerExt(fileName)\n return ext === 'mmd' || ext === 'mermaid' || mimeType === 'text/vnd.mermaid'\n },\n async readDocument(input) {\n const { detectMermaidDiagram } = await import('@pairdraw/mermaid')\n const text = new TextDecoder().decode(input.data)\n if (!detectMermaidDiagram(text)) throw new Error('This file holds no Mermaid flowchart')\n // Mermaid stores a diagram's structure, which reading lays out with its text measured.\n const { mermaidToSceneGraph } = await import('./formats/mermaid')\n return { graph: await mermaidToSceneGraph(text), sourceFormat: 'mermaid' }\n }\n}\n\n/** Pages or layers as a draw.io file, loading the writer only when one is saved. */\nasync function writeDrawIO(graph: SceneGraph, target: DrawIOExportTarget): Promise<ExportResult> {\n const { writeDrawIOFile } = await import('@pairdraw/drawio')\n const { sceneGraphToDrawIO } = await import('./formats/drawio')\n return {\n format: 'drawio',\n mimeType: 'application/vnd.jgraph.mxfile',\n extension: 'drawio',\n data: writeDrawIOFile(sceneGraphToDrawIO(graph, target)),\n encoding: 'utf8'\n }\n}\n\nexport const pngFormat = rasterFormat('PNG')\nexport const jpgFormat = rasterFormat('JPG')\nexport const webpFormat = rasterFormat('WEBP')\n\nexport const svgFormat: IOFormatAdapter<'svg'> = {\n id: 'svg',\n label: 'SVG',\n role: 'derived-export',\n category: 'vector',\n extensions: ['svg'],\n mimeTypes: ['image/svg+xml'],\n support: EXPORT_EVERY_TARGET,\n exportOptions: { ...FIXED_SIZE_EXPORT, colorSpace: true },\n async exportContent(request, options?: SVGExportOptions) {\n const target = resolveExportNodes(request)\n if (!target) throw new Error('Nothing to export')\n const { renderNodesToLaidOutSVG } = await import('./formats/svg/text/layout')\n const data = await renderNodesToLaidOutSVG(\n request.graph,\n target.pageId,\n target.nodeIds,\n options\n )\n if (!data) throw new Error('Nothing to export')\n return {\n format: 'svg',\n mimeType: 'image/svg+xml',\n extension: 'svg',\n data,\n encoding: 'utf8'\n }\n }\n}\n\n/**\n * The PDF pages an export makes. A selection gets a page per layer in the order it lists them,\n * each sized to its layer, as slides and Figma's frame export do, unless `single` asks for one\n * page; a page or a document is one page of its layers unless `frames` asks for a page each.\n */\nasync function pdfPageSpecs(\n request: ExportRequest,\n options: PDFFormatExportOptions | undefined\n): Promise<PDFPageSpec[]> {\n const frames = options?.pages ? options.pages === 'frames' : request.target.scope === 'selection'\n if (frames) {\n const { target } = request\n let ids: string[] | undefined\n if (target.scope === 'selection') ids = target.nodeIds\n else if (target.scope === 'node') ids = [target.nodeId]\n const first = ids?.[0]\n let currentPageId: string | null | undefined\n if (first) currentPageId = findPageId(request.graph, first)\n else if (target.scope === 'page') currentPageId = target.pageId\n else if (target.scope === 'document') currentPageId = request.graph.getPages()[0]?.id\n if (!currentPageId) throw new Error('Nothing to export')\n // Without IDs, the plan takes the page's visible layers, in layer order.\n const { planPDFPages } = await import('./formats/pdf/plan')\n return planPDFPages(request.graph, { mode: 'frames', ids, currentPageId })\n }\n const target = resolveExportNodes(request)\n if (!target) throw new Error('Nothing to export')\n return [target]\n}\n\nexport const pdfFormat: IOFormatAdapter<'pdf'> = {\n id: 'pdf',\n label: 'PDF',\n role: 'derived-export',\n category: 'vector',\n extensions: ['pdf'],\n mimeTypes: ['application/pdf'],\n support: EXPORT_EVERY_TARGET,\n exportOptions: FIXED_SIZE_EXPORT,\n async exportContent(request, options?: PDFFormatExportOptions) {\n const specs = await pdfPageSpecs(request, options)\n // Embedded, as Figma embeds every face its PDFs draw.\n const { exportPDFDocument } = await import('./formats/pdf/document')\n const data = (await exportPDFDocument(request.graph, specs, { embedFonts: true }))?.data\n if (!data) throw new Error('Nothing to export')\n return {\n format: 'pdf',\n mimeType: 'application/pdf',\n extension: 'pdf',\n data\n }\n }\n}\n\n/**\n * Every top-level frame becomes a slide, so a PPTX document export spans all\n * pages — the shared resolver only reaches the first one.\n */\nfunction resolvePPTXExportNodes(\n request: ExportRequest\n): { pageId: string; nodeIds: string[] } | null {\n if (request.target.scope !== 'document') return resolveExportNodes(request)\n const pages = request.graph.getPages()\n if (!pages.length) return null\n return { pageId: pages[0].id, nodeIds: pages.flatMap((page) => page.childIds) }\n}\n\nexport const pptxFormat: IOFormatAdapter<'pptx'> = {\n id: 'pptx',\n label: 'PowerPoint',\n role: 'derived-export',\n category: 'print',\n extensions: ['pptx'],\n mimeTypes: ['application/vnd.openxmlformats-officedocument.presentationml.presentation'],\n support: EXPORT_EVERY_TARGET,\n exportOptions: FIXED_SIZE_EXPORT,\n async exportContent(request, options?: PPTXExportOptions, context?: IOContext) {\n const target = resolvePPTXExportNodes(request)\n if (!target) throw new Error('Nothing to export')\n const { renderNodesToPPTX } = await import('./formats/pptx')\n const data = await renderNodesToPPTX(request.graph, target.pageId, target.nodeIds, {\n ...options,\n context: options?.context ?? context\n })\n if (!data) throw new Error('Nothing to export')\n return {\n format: 'pptx',\n mimeType: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',\n extension: 'pptx',\n data\n }\n }\n}\n\nexport const jsxFormat: IOFormatAdapter<'jsx'> = {\n id: 'jsx',\n label: 'JSX',\n role: 'derived-export',\n category: 'code',\n extensions: ['jsx'],\n mimeTypes: ['text/plain', 'text/jsx'],\n support: EXPORT_EVERY_TARGET,\n exportOptions: FIXED_SIZE_EXPORT,\n async exportContent(request): Promise<ExportResult> {\n const nodeId = ensureSingleNode(request.target)\n // A page or a document exports its top-level layers, as Tailwind JSX does.\n const target = nodeId ? null : resolveExportNodes(request)\n let data = ''\n if (nodeId) data = sceneNodeToJSX(nodeId, request.graph)\n else if (target) data = selectionToJSX(target.nodeIds, request.graph)\n if (!data) throw new Error('Nothing to export')\n return {\n format: 'jsx',\n mimeType: 'text/plain',\n extension: 'jsx',\n data,\n encoding: 'utf8'\n }\n }\n}\n\nexport const htmlFormat: IOFormatAdapter<'html'> = {\n id: 'html',\n label: 'HTML',\n role: 'derived-export',\n category: 'code',\n extensions: ['html'],\n mimeTypes: ['text/html'],\n support: EXPORT_EVERY_TARGET,\n exportOptions: FIXED_SIZE_EXPORT,\n async exportContent(request, options?: HTMLExportOptions) {\n const target = resolveExportNodes(request)\n if (!target) throw new Error('Nothing to export')\n const { renderNodesToHTML } = await import('./formats/html')\n const { html, assets } = await renderNodesToHTML(\n request.graph,\n target.nodeIds,\n options,\n request.fileName\n )\n return {\n format: 'html',\n mimeType: 'text/html',\n extension: 'html',\n data: html,\n encoding: 'utf8',\n assets\n }\n }\n}\n\nexport const tailwindJSXFormat: IOFormatAdapter<'tailwind-jsx'> = {\n id: 'tailwind-jsx',\n label: 'Tailwind JSX',\n role: 'derived-export',\n category: 'code',\n extensions: ['jsx'],\n mimeTypes: ['text/plain', 'text/jsx'],\n support: EXPORT_EVERY_TARGET,\n exportOptions: FIXED_SIZE_EXPORT,\n async exportContent(request) {\n const target = resolveExportNodes(request)\n if (!target) throw new Error('Nothing to export')\n const { sceneNodesToTailwindJSX } = await import('@pairdraw/dom-css/export')\n const { vectorElement } = await import('#core/io/formats/html/vectors')\n const data = sceneNodesToTailwindJSX(request.graph, target.nodeIds, { vectorElement })\n if (!data) throw new Error('Nothing to export')\n return {\n format: 'tailwind-jsx',\n mimeType: 'text/plain',\n extension: 'jsx',\n data,\n encoding: 'utf8'\n }\n }\n}\n\nexport { penFormat }\n\nexport const BUILTIN_IO_FORMATS = [\n figFormat,\n penFormat,\n drawioFormat,\n mermaidFormat,\n pngFormat,\n jpgFormat,\n webpFormat,\n svgFormat,\n pdfFormat,\n pptxFormat,\n jsxFormat,\n tailwindJSXFormat,\n htmlFormat\n] as const satisfies readonly IOFormatAdapter[]\n\nexport type BuiltinIOFormatId = (typeof BUILTIN_IO_FORMATS)[number]['id']\n"],"mappings":";;;;;;;;;;;;AA8BA,MAAM,sBAAuC;CAC3C,gBAAgB;CAChB,YAAY;CACZ,iBAAiB;CACjB,YAAY;AACd;;AAGA,MAAM,oBAA2C;CAAE,OAAO;CAAO,SAAS;AAAM;AAEhF,SAAS,SAAS,MAAsB;CAEtC,OADc,aAAa,KAAK,KAAK,YAAY,CACtC,CAAC,GAAG,MAAM;AACvB;AAEA,SAAS,iBAAiB,QAAgD;CACxE,IAAI,OAAO,UAAU,QAAQ,OAAO,OAAO;CAC3C,IAAI,OAAO,UAAU,eAAe,OAAO,QAAQ,WAAW,GAAG,OAAO,OAAO,QAAQ;CACvF,OAAO;AACT;AAEA,SAAS,mBAAmB,SAAsE;CAChG,QAAQ,QAA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AC7B,QAAQ,OACR,OAAO,SACP,SACA,QAAQ,QACV;EACA,OAAO;GACL,QAAQ;GACR,UAAU;GACV,WAAW;GACX,MAAM;GACN,UAAU;GACV;EACF;CACF;AACF;AAEA,MAAa,oBAAqD;CAChE,IAAI;CACJ,OAAO;CACP,MAAM;CACN,UAAU;CACV,YAAY,CAAC,KAAK;CAClB,WAAW,CAAC,cAAc,UAAU;CACpC,SAAS;CACT,eAAe;CACf,MAAM,cAAc,SAAS;EAC3B,MAAM,SAAS,mBAAmB,OAAO;EACzC,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,mBAAmB;EAChD,MAAM,EAAE,4BAA4B,MAAM,OAAO;EACjD,MAAM,EAAE,kBAAkB,MAAM,OAAO;EACvC,MAAM,OAAO,wBAAwB,QAAQ,OAAO,OAAO,SAAS,EAAE,cAAc,CAAC;EACrF,IAAI,CAAC,MAAM,MAAM,IAAI,MAAM,mBAAmB;EAC9C,OAAO;GACL,QAAQ;GACR,UAAU;GACV,WAAW;GACX;GACA,UAAU;EACZ;CACF;AACF;AAIA,MAAa,qBAAqB;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
1
+ {"version":3,"file":"formats.js","names":[],"sources":["../../src/io/formats.ts"],"sourcesContent":["import { filename } from 'pathe/utils'\n\nimport { sceneNodeToJSX, selectionToJSX } from '@pairdraw/design-jsx'\nimport { isDrawIOExportFileName } from '@pairdraw/drawio'\nimport type { DocumentKind, SceneGraph } from '@pairdraw/scene-graph'\n\nimport { layoutAuthoredNodes } from '#core/layout'\n\nimport type { DrawIOExportTarget } from './formats/drawio/export'\nimport { exportFigFile, parseFigFile } from './formats/fig'\nimport type { PDFPageSpec } from './formats/pdf/plan'\nimport { penFormat } from './formats/pen'\nimport type { PPTXExportOptions } from './formats/pptx'\nimport { headlessRenderNodes, renderNodesToImage, type RasterExportFormat } from './formats/raster'\nimport { extractExportGraph, findPageId } from './subgraph'\nimport type {\n ExportRequest,\n ExportResult,\n FigWriteOptions,\n HTMLExportOptions,\n IOContext,\n IOFormatAdapter,\n IOFormatExportOptions,\n IOFormatSupport,\n PDFFormatExportOptions,\n RasterExportOptions,\n SVGExportOptions\n} from './types'\n\n/** Formats that export a document, page, selection, or single node alike. */\nconst EXPORT_EVERY_TARGET: IOFormatSupport = {\n exportDocument: true,\n exportPage: true,\n exportSelection: true,\n exportNode: true\n}\n\n/** Formats with a size of their own, so no export scale or quality. */\nconst FIXED_SIZE_EXPORT: IOFormatExportOptions = { scale: false, quality: false }\n\nfunction lowerExt(name: string): string {\n const match = /\\.([^.]+)$/.exec(name.toLowerCase())\n return match?.[1] ?? ''\n}\n\nfunction ensureSingleNode(target: ExportRequest['target']): string | null {\n if (target.scope === 'node') return target.nodeId\n if (target.scope === 'selection' && target.nodeIds.length === 1) return target.nodeIds[0]\n return null\n}\n\nfunction resolveExportNodes(request: ExportRequest): { pageId: string; nodeIds: string[] } | null {\n switch (request.target.scope) {\n case 'document': {\n const page = request.graph.getPages()[0]\n return { pageId: page.id, nodeIds: page.childIds }\n }\n case 'page': {\n const page = request.graph.getNode(request.target.pageId)\n if (!page) return null\n return { pageId: page.id, nodeIds: page.childIds }\n }\n case 'selection': {\n const first = request.target.nodeIds[0]\n if (!first) return null\n const pageId = findPageId(request.graph, first)\n if (!pageId) return null\n if (!request.target.nodeIds.every((nodeId) => findPageId(request.graph, nodeId) === pageId)) {\n throw new Error('Export selection must stay on a single page')\n }\n return { pageId, nodeIds: request.target.nodeIds }\n }\n case 'node':\n return resolveExportNodes({\n ...request,\n target: { scope: 'selection', nodeIds: [request.target.nodeId] }\n })\n default:\n return null\n }\n}\n\nasync function renderRaster(\n request: ExportRequest,\n options: RasterExportOptions,\n context?: IOContext\n): Promise<Uint8Array | null> {\n const target = resolveExportNodes(request)\n if (!target) return null\n const scale = options.scale ?? 1\n\n if (context?.canvasKit && context.renderer) {\n return renderNodesToImage(\n context.canvasKit,\n context.renderer,\n request.graph,\n target.pageId,\n target.nodeIds,\n {\n scale,\n format: options.format,\n quality: options.quality,\n trimTransparent: request.target.scope === 'page' || request.target.scope === 'document'\n }\n )\n }\n\n return headlessRenderNodes(request.graph, target.pageId, target.nodeIds, {\n scale,\n format: options.format,\n quality: options.quality,\n trimTransparent: request.target.scope === 'page' || request.target.scope === 'document'\n })\n}\n\nfunction rasterFormat<F extends RasterExportFormat>(format: F): IOFormatAdapter<Lowercase<F>> {\n const extension = format.toLowerCase() as Lowercase<F>\n let mimeType = 'image/png'\n if (format === 'JPG') mimeType = 'image/jpeg'\n else if (format === 'WEBP') mimeType = 'image/webp'\n\n return {\n id: extension,\n label: format,\n role: 'derived-export',\n category: 'raster',\n extensions: [extension],\n mimeTypes: [mimeType],\n support: {\n exportDocument: true,\n exportPage: true,\n exportSelection: true,\n exportNode: true\n },\n exportOptions: {\n scale: true,\n quality: format !== 'PNG',\n colorSpace: false\n },\n async exportContent(request, options?: RasterExportOptions, context?: IOContext) {\n const data = await renderRaster(\n request,\n {\n format,\n scale: options?.scale,\n quality: options?.quality\n },\n context\n )\n if (!data) throw new Error('Nothing to export')\n return {\n format: extension,\n mimeType,\n extension,\n data\n }\n }\n }\n}\n\n/** The file a document saves as: Figma's `.fig` for a design, FigJam's `.jam` for a board. */\nexport const DOCUMENT_EXTENSIONS: Readonly<Record<DocumentKind, 'fig' | 'jam'>> = {\n design: 'fig',\n board: 'jam'\n}\n\nexport const figFormat: IOFormatAdapter<'fig'> = {\n id: 'fig',\n label: 'Pairdraw Document',\n role: 'native-document',\n category: 'document',\n extensions: ['fig', 'jam'],\n mimeTypes: ['application/octet-stream'],\n support: {\n readDocument: true,\n writeDocument: true,\n exportDocument: true,\n exportPage: true,\n exportSelection: true,\n exportNode: true\n },\n exportOptions: FIXED_SIZE_EXPORT,\n matchesFile(fileName) {\n const ext = lowerExt(fileName)\n return ext === 'fig' || ext === 'jam'\n },\n async readDocument(input) {\n const data = input.data.slice().buffer\n const graph = await parseFigFile(data, { populate: 'first-page' })\n return { graph, sourceFormat: 'fig' }\n },\n async writeDocument(graph, options?: FigWriteOptions, context?: IOContext) {\n return writeFig(graph, options, context, options?.thumbnailPageId)\n },\n async exportContent(request, options?: FigWriteOptions, context?: IOContext) {\n // A whole document is written as it is, so one opened from an archive keeps that archive.\n if (request.target.scope === 'document')\n return writeFig(request.graph, options, context, options?.thumbnailPageId, request.fileName)\n const extracted = extractExportGraph(request.graph, request.target)\n return writeFig(\n extracted.graph,\n options,\n context,\n options?.thumbnailPageId ?? extracted.pageId ?? undefined,\n request.fileName\n )\n }\n}\n\n/** A `.fig` named as asked, or else after the file it is written to, or else Untitled. */\nasync function writeFig(\n graph: SceneGraph,\n options: FigWriteOptions | undefined,\n context: IOContext | undefined,\n pageId: string | undefined,\n fileName?: string\n): Promise<ExportResult> {\n const data = await exportFigFile(graph, {\n ck: context?.canvasKit,\n renderer: context?.renderer,\n pageId,\n renderHeadlessThumbnail: options?.renderThumbnail ?? false,\n documentName: options?.documentName ?? (fileName && filename(fileName))\n })\n const extension = DOCUMENT_EXTENSIONS[graph.documentKind]\n return { format: 'fig', mimeType: 'application/octet-stream', extension, data }\n}\n\nexport const drawioFormat: IOFormatAdapter<'drawio'> = {\n id: 'drawio',\n label: 'draw.io Diagram',\n role: 'interchange-document',\n category: 'document',\n extensions: ['drawio', 'dio'],\n mimeTypes: ['application/vnd.jgraph.mxfile'],\n support: {\n readDocument: true,\n writeDocument: true,\n exportDocument: true,\n exportPage: true,\n exportSelection: true,\n exportNode: true\n },\n exportOptions: FIXED_SIZE_EXPORT,\n laysOutOnRead: true,\n // A draw.io PNG or SVG export opens as its diagram when its name says it is one.\n matchesFile(fileName, mimeType) {\n const ext = lowerExt(fileName)\n return (\n ext === 'drawio' ||\n ext === 'dio' ||\n isDrawIOExportFileName(fileName) ||\n mimeType === 'application/vnd.jgraph.mxfile'\n )\n },\n async readDocument(input) {\n const { readDrawIOBytes } = await import('@pairdraw/drawio')\n const { drawioToSceneGraph } = await import('./formats/drawio')\n const file = readDrawIOBytes(input.data)\n if (!file) throw new Error('This file holds no draw.io diagram')\n if (file.unreadable.length > 0) {\n throw new Error(`Could not read the draw.io pages ${file.unreadable.join(', ')}`)\n }\n const graph = drawioToSceneGraph(file)\n // draw.io stores label text, not the sizes it lays out to.\n layoutAuthoredNodes(\n graph,\n graph.getPages().map((page) => page.id)\n )\n return { graph, sourceFormat: 'drawio' }\n },\n async writeDocument(graph) {\n const pageIds = graph.getPages().map((page) => page.id)\n return writeDrawIO(graph, { pageIds })\n },\n // A page or a selection goes as a one-page diagram; the document, every page.\n async exportContent(request) {\n if (request.target.scope === 'document') {\n const pageIds = request.graph.getPages().map((page) => page.id)\n return writeDrawIO(request.graph, { pageIds })\n }\n const target = resolveExportNodes(request)\n if (!target) throw new Error('Nothing to export')\n return writeDrawIO(request.graph, target)\n }\n}\n\nexport const mermaidFormat: IOFormatAdapter<'mermaid'> = {\n id: 'mermaid',\n label: 'Mermaid Diagram',\n role: 'interchange-document',\n category: 'document',\n extensions: ['mmd', 'mermaid'],\n mimeTypes: ['text/vnd.mermaid'],\n support: {\n readDocument: true\n },\n laysOutOnRead: true,\n matchesFile(fileName, mimeType) {\n const ext = lowerExt(fileName)\n return ext === 'mmd' || ext === 'mermaid' || mimeType === 'text/vnd.mermaid'\n },\n async readDocument(input) {\n const { detectMermaidDiagram } = await import('@pairdraw/mermaid')\n const text = new TextDecoder().decode(input.data)\n if (!detectMermaidDiagram(text)) throw new Error('This file holds no Mermaid flowchart')\n // Mermaid stores a diagram's structure, which reading lays out with its text measured.\n const { mermaidToSceneGraph } = await import('./formats/mermaid')\n return { graph: await mermaidToSceneGraph(text), sourceFormat: 'mermaid' }\n }\n}\n\n/** Pages or layers as a draw.io file, loading the writer only when one is saved. */\nasync function writeDrawIO(graph: SceneGraph, target: DrawIOExportTarget): Promise<ExportResult> {\n const { writeDrawIOFile } = await import('@pairdraw/drawio')\n const { sceneGraphToDrawIO } = await import('./formats/drawio')\n const { drawioDroppedWarnings } = await import('./formats/drawio/warnings')\n return {\n format: 'drawio',\n mimeType: 'application/vnd.jgraph.mxfile',\n extension: 'drawio',\n data: writeDrawIOFile(sceneGraphToDrawIO(graph, target)),\n encoding: 'utf8',\n warnings: drawioDroppedWarnings(graph)\n }\n}\n\nexport const pngFormat = rasterFormat('PNG')\nexport const jpgFormat = rasterFormat('JPG')\nexport const webpFormat = rasterFormat('WEBP')\n\nexport const svgFormat: IOFormatAdapter<'svg'> = {\n id: 'svg',\n label: 'SVG',\n role: 'derived-export',\n category: 'vector',\n extensions: ['svg'],\n mimeTypes: ['image/svg+xml'],\n support: EXPORT_EVERY_TARGET,\n exportOptions: { ...FIXED_SIZE_EXPORT, colorSpace: true },\n async exportContent(request, options?: SVGExportOptions) {\n const target = resolveExportNodes(request)\n if (!target) throw new Error('Nothing to export')\n const { renderNodesToLaidOutSVG } = await import('./formats/svg/text/layout')\n const data = await renderNodesToLaidOutSVG(\n request.graph,\n target.pageId,\n target.nodeIds,\n options\n )\n if (!data) throw new Error('Nothing to export')\n return {\n format: 'svg',\n mimeType: 'image/svg+xml',\n extension: 'svg',\n data,\n encoding: 'utf8'\n }\n }\n}\n\n/**\n * The PDF pages an export makes. A selection gets a page per layer in the order it lists them,\n * each sized to its layer, as slides and Figma's frame export do, unless `single` asks for one\n * page; a page or a document is one page of its layers unless `frames` asks for a page each.\n */\nasync function pdfPageSpecs(\n request: ExportRequest,\n options: PDFFormatExportOptions | undefined\n): Promise<PDFPageSpec[]> {\n const frames = options?.pages ? options.pages === 'frames' : request.target.scope === 'selection'\n if (frames) {\n const { target } = request\n let ids: string[] | undefined\n if (target.scope === 'selection') ids = target.nodeIds\n else if (target.scope === 'node') ids = [target.nodeId]\n const first = ids?.[0]\n let currentPageId: string | null | undefined\n if (first) currentPageId = findPageId(request.graph, first)\n else if (target.scope === 'page') currentPageId = target.pageId\n else if (target.scope === 'document') currentPageId = request.graph.getPages()[0]?.id\n if (!currentPageId) throw new Error('Nothing to export')\n // Without IDs, the plan takes the page's visible layers, in layer order.\n const { planPDFPages } = await import('./formats/pdf/plan')\n return planPDFPages(request.graph, { mode: 'frames', ids, currentPageId })\n }\n const target = resolveExportNodes(request)\n if (!target) throw new Error('Nothing to export')\n return [target]\n}\n\nexport const pdfFormat: IOFormatAdapter<'pdf'> = {\n id: 'pdf',\n label: 'PDF',\n role: 'derived-export',\n category: 'vector',\n extensions: ['pdf'],\n mimeTypes: ['application/pdf'],\n support: EXPORT_EVERY_TARGET,\n exportOptions: FIXED_SIZE_EXPORT,\n async exportContent(request, options?: PDFFormatExportOptions) {\n const specs = await pdfPageSpecs(request, options)\n // Embedded, as Figma embeds every face its PDFs draw.\n const { exportPDFDocument } = await import('./formats/pdf/document')\n const data = (await exportPDFDocument(request.graph, specs, { embedFonts: true }))?.data\n if (!data) throw new Error('Nothing to export')\n return {\n format: 'pdf',\n mimeType: 'application/pdf',\n extension: 'pdf',\n data\n }\n }\n}\n\n/**\n * Every top-level frame becomes a slide, so a PPTX document export spans all\n * pages — the shared resolver only reaches the first one.\n */\nfunction resolvePPTXExportNodes(\n request: ExportRequest\n): { pageId: string; nodeIds: string[] } | null {\n if (request.target.scope !== 'document') return resolveExportNodes(request)\n const pages = request.graph.getPages()\n if (!pages.length) return null\n return { pageId: pages[0].id, nodeIds: pages.flatMap((page) => page.childIds) }\n}\n\nexport const pptxFormat: IOFormatAdapter<'pptx'> = {\n id: 'pptx',\n label: 'PowerPoint',\n role: 'derived-export',\n category: 'print',\n extensions: ['pptx'],\n mimeTypes: ['application/vnd.openxmlformats-officedocument.presentationml.presentation'],\n support: EXPORT_EVERY_TARGET,\n exportOptions: FIXED_SIZE_EXPORT,\n async exportContent(request, options?: PPTXExportOptions, context?: IOContext) {\n const target = resolvePPTXExportNodes(request)\n if (!target) throw new Error('Nothing to export')\n const { renderNodesToPPTX } = await import('./formats/pptx')\n const data = await renderNodesToPPTX(request.graph, target.pageId, target.nodeIds, {\n ...options,\n context: options?.context ?? context\n })\n if (!data) throw new Error('Nothing to export')\n return {\n format: 'pptx',\n mimeType: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',\n extension: 'pptx',\n data\n }\n }\n}\n\nexport const jsxFormat: IOFormatAdapter<'jsx'> = {\n id: 'jsx',\n label: 'JSX',\n role: 'derived-export',\n category: 'code',\n extensions: ['jsx'],\n mimeTypes: ['text/plain', 'text/jsx'],\n support: EXPORT_EVERY_TARGET,\n exportOptions: FIXED_SIZE_EXPORT,\n async exportContent(request): Promise<ExportResult> {\n const nodeId = ensureSingleNode(request.target)\n // A page or a document exports its top-level layers, as Tailwind JSX does.\n const target = nodeId ? null : resolveExportNodes(request)\n let data = ''\n if (nodeId) data = sceneNodeToJSX(nodeId, request.graph)\n else if (target) data = selectionToJSX(target.nodeIds, request.graph)\n if (!data) throw new Error('Nothing to export')\n return {\n format: 'jsx',\n mimeType: 'text/plain',\n extension: 'jsx',\n data,\n encoding: 'utf8'\n }\n }\n}\n\nexport const htmlFormat: IOFormatAdapter<'html'> = {\n id: 'html',\n label: 'HTML',\n role: 'derived-export',\n category: 'code',\n extensions: ['html'],\n mimeTypes: ['text/html'],\n support: EXPORT_EVERY_TARGET,\n exportOptions: FIXED_SIZE_EXPORT,\n async exportContent(request, options?: HTMLExportOptions) {\n const target = resolveExportNodes(request)\n if (!target) throw new Error('Nothing to export')\n const { renderNodesToHTML } = await import('./formats/html')\n const { html, assets } = await renderNodesToHTML(\n request.graph,\n target.nodeIds,\n options,\n request.fileName\n )\n return {\n format: 'html',\n mimeType: 'text/html',\n extension: 'html',\n data: html,\n encoding: 'utf8',\n assets\n }\n }\n}\n\nexport const tailwindJSXFormat: IOFormatAdapter<'tailwind-jsx'> = {\n id: 'tailwind-jsx',\n label: 'Tailwind JSX',\n role: 'derived-export',\n category: 'code',\n extensions: ['jsx'],\n mimeTypes: ['text/plain', 'text/jsx'],\n support: EXPORT_EVERY_TARGET,\n exportOptions: FIXED_SIZE_EXPORT,\n async exportContent(request) {\n const target = resolveExportNodes(request)\n if (!target) throw new Error('Nothing to export')\n const { sceneNodesToTailwindJSX } = await import('@pairdraw/dom-css/export')\n const { vectorElement } = await import('#core/io/formats/html/vectors')\n const data = sceneNodesToTailwindJSX(request.graph, target.nodeIds, { vectorElement })\n if (!data) throw new Error('Nothing to export')\n return {\n format: 'tailwind-jsx',\n mimeType: 'text/plain',\n extension: 'jsx',\n data,\n encoding: 'utf8'\n }\n }\n}\n\nexport { penFormat }\n\nexport const BUILTIN_IO_FORMATS = [\n figFormat,\n penFormat,\n drawioFormat,\n mermaidFormat,\n pngFormat,\n jpgFormat,\n webpFormat,\n svgFormat,\n pdfFormat,\n pptxFormat,\n jsxFormat,\n tailwindJSXFormat,\n htmlFormat\n] as const satisfies readonly IOFormatAdapter[]\n\nexport type BuiltinIOFormatId = (typeof BUILTIN_IO_FORMATS)[number]['id']\n"],"mappings":";;;;;;;;;;;;AA8BA,MAAM,sBAAuC;CAC3C,gBAAgB;CAChB,YAAY;CACZ,iBAAiB;CACjB,YAAY;AACd;;AAGA,MAAM,oBAA2C;CAAE,OAAO;CAAO,SAAS;AAAM;AAEhF,SAAS,SAAS,MAAsB;CAEtC,OADc,aAAa,KAAK,KAAK,YAAY,CACtC,CAAC,GAAG,MAAM;AACvB;AAEA,SAAS,iBAAiB,QAAgD;CACxE,IAAI,OAAO,UAAU,QAAQ,OAAO,OAAO;CAC3C,IAAI,OAAO,UAAU,eAAe,OAAO,QAAQ,WAAW,GAAG,OAAO,OAAO,QAAQ;CACvF,OAAO;AACT;AAEA,SAAS,mBAAmB,SAAsE;CAChG,QAAQ,QAAQ,OAAO,OAAvB;EACE,KAAK,YAAY;GACf,MAAM,OAAO,QAAQ,MAAM,SAAS,CAAC,CAAC;GACtC,OAAO;IAAE,QAAQ,KAAK;IAAI,SAAS,KAAK;GAAS;EACnD;EACA,KAAK,QAAQ;GACX,MAAM,OAAO,QAAQ,MAAM,QAAQ,QAAQ,OAAO,MAAM;GACxD,IAAI,CAAC,MAAM,OAAO;GAClB,OAAO;IAAE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V,YAAY,CAAC,KAAK;CAClB,WAAW,CAAC,cAAc,UAAU;CACpC,SAAS;CACT,eAAe;CACf,MAAM,cAAc,SAAS;EAC3B,MAAM,SAAS,mBAAmB,OAAO;EACzC,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,mBAAmB;EAChD,MAAM,EAAE,4BAA4B,MAAM,OAAO;EACjD,MAAM,EAAE,kBAAkB,MAAM,OAAO;EACvC,MAAM,OAAO,wBAAwB,QAAQ,OAAO,OAAO,SAAS,EAAE,cAAc,CAAC;EACrF,IAAI,CAAC,MAAM,MAAM,IAAI,MAAM,mBAAmB;EAC9C,OAAO;GACL,QAAQ;GACR,UAAU;GACV,WAAW;GACX;GACA,UAAU;EACZ;CACF;AACF;AAIA,MAAa,qBAAqB;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
@@ -9,6 +9,8 @@ declare class IORegistry {
9
9
  listReadableFormats(): IOFormatAdapter[];
10
10
  listWritableFormats(): IOFormatAdapter[];
11
11
  listExportFormats(scope: ExportRequest['target']['scope']): IOFormatAdapter[];
12
+ /** The writable format a file name asks for, so a save keeps the document's own format. */
13
+ findWriter(fileName: string): IOFormatAdapter | null;
12
14
  findReader(fileName: string, mimeType?: string): IOFormatAdapter | null;
13
15
  readDocument(input: ReadDocumentInput, context?: IOContext): Promise<ReadDocumentResult>;
14
16
  writeDocument(formatId: string, graph: SceneGraph, options?: unknown, context?: IOContext): Promise<ExportResult>;
@@ -1 +1 @@
1
- {"version":3,"file":"registry.d.ts","names":[],"sources":["../../src/io/registry.ts"],"mappings":";;;cAIa;mBACkB;EAAA,YAAA,mBAAmB;EAEhD,wBAAwB;EAIxB,UAAU,aAAa;EAIvB,uBAAuB;EAIvB,uBAAuB;EAIvB,kBAAkB,OAAO,mCAAmC;EAiB5D,WAAW,kBAAkB,oBAAoB;EAW3C,aAAa,OAAO,mBAAmB,UAAU,YAAS,QAAT;EAQjD,cAAc,kBAAkB,OAAO,YAAY,mBAAmB,UAAU,YAAS,QAAT;EAQhF,cACJ,kBACA,SAAS,eACT,mBACA,UAAU,YAAS,QAAT"}
1
+ {"version":3,"file":"registry.d.ts","names":[],"sources":["../../src/io/registry.ts"],"mappings":";;;cAIa;mBACkB;EAAA,YAAA,mBAAmB;EAEhD,wBAAwB;EAIxB,UAAU,aAAa;EAIvB,uBAAuB;EAIvB,uBAAuB;EAIvB,kBAAkB,OAAO,mCAAmC;;EAkB5D,WAAW,mBAAmB;EAW9B,WAAW,kBAAkB,oBAAoB;EAW3C,aAAa,OAAO,mBAAmB,UAAU,YAAS,QAAT;EAQjD,cAAc,kBAAkB,OAAO,YAAY,mBAAmB,UAAU,YAAS,QAAT;EAQhF,cACJ,kBACA,SAAS,eACT,mBACA,UAAU,YAAS,QAAT"}
@@ -27,6 +27,11 @@ var IORegistry = class {
27
27
  }
28
28
  });
29
29
  }
30
+ /** The writable format a file name asks for, so a save keeps the document's own format. */
31
+ findWriter(fileName) {
32
+ const lower = fileName.toLowerCase();
33
+ return this.adapters.find((adapter) => !!adapter.support.writeDocument && adapter.extensions.some((ext) => lower.endsWith(`.${ext}`))) ?? null;
34
+ }
30
35
  findReader(fileName, mimeType) {
31
36
  return this.adapters.find((adapter) => {
32
37
  if (!adapter.support.readDocument) return false;