@pairdraw/core 0.19.1 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1031) hide show
  1. package/dist/ai/providers.d.ts +6 -0
  2. package/dist/ai/providers.d.ts.map +1 -1
  3. package/dist/ai/providers.js.map +1 -1
  4. package/dist/cache/resource.d.ts +8 -1
  5. package/dist/cache/resource.d.ts.map +1 -1
  6. package/dist/cache/resource.js +18 -0
  7. package/dist/cache/resource.js.map +1 -1
  8. package/dist/canvas/effects.d.ts +6 -4
  9. package/dist/canvas/effects.d.ts.map +1 -1
  10. package/dist/canvas/effects.js +37 -34
  11. package/dist/canvas/effects.js.map +1 -1
  12. package/dist/canvas/fills.d.ts.map +1 -1
  13. package/dist/canvas/fills.js +12 -8
  14. package/dist/canvas/fills.js.map +1 -1
  15. package/dist/canvas/images/adjustments.d.ts +18 -0
  16. package/dist/canvas/images/adjustments.d.ts.map +1 -0
  17. package/dist/canvas/images/adjustments.js +184 -0
  18. package/dist/canvas/images/adjustments.js.map +1 -0
  19. package/dist/canvas/images/previews.d.ts +1 -1
  20. package/dist/canvas/images/sampling.d.ts +13 -0
  21. package/dist/canvas/images/sampling.d.ts.map +1 -0
  22. package/dist/canvas/images/sampling.js +49 -0
  23. package/dist/canvas/images/sampling.js.map +1 -0
  24. package/dist/canvas/index.d.ts +2 -2
  25. package/dist/canvas/masks.d.ts +1 -1
  26. package/dist/canvas/masks.d.ts.map +1 -1
  27. package/dist/canvas/masks.js.map +1 -1
  28. package/dist/canvas/noise/render.d.ts +15 -0
  29. package/dist/canvas/noise/render.d.ts.map +1 -0
  30. package/dist/canvas/noise/render.js +56 -0
  31. package/dist/canvas/noise/render.js.map +1 -0
  32. package/dist/canvas/noise/shader.d.ts +43 -0
  33. package/dist/canvas/noise/shader.d.ts.map +1 -0
  34. package/dist/canvas/noise/shader.js +161 -0
  35. package/dist/canvas/noise/shader.js.map +1 -0
  36. package/dist/canvas/noise/table.d.ts +13 -0
  37. package/dist/canvas/noise/table.d.ts.map +1 -0
  38. package/dist/canvas/noise/table.js +408 -0
  39. package/dist/canvas/noise/table.js.map +1 -0
  40. package/dist/canvas/noise/tile.d.ts +22 -0
  41. package/dist/canvas/noise/tile.d.ts.map +1 -0
  42. package/dist/canvas/noise/tile.js +73 -0
  43. package/dist/canvas/noise/tile.js.map +1 -0
  44. package/dist/canvas/outline-stroke.js +1 -1
  45. package/dist/canvas/overlays/auto-layout-hover.d.ts.map +1 -1
  46. package/dist/canvas/overlays/auto-layout-hover.js +31 -71
  47. package/dist/canvas/overlays/auto-layout-hover.js.map +1 -1
  48. package/dist/canvas/overlays/index.d.ts +2 -2
  49. package/dist/canvas/overlays/index.js +2 -2
  50. package/dist/canvas/overlays/selection.d.ts +1 -2
  51. package/dist/canvas/overlays/selection.d.ts.map +1 -1
  52. package/dist/canvas/overlays/selection.js +2 -9
  53. package/dist/canvas/overlays/selection.js.map +1 -1
  54. package/dist/canvas/renderer/chunks/index.d.ts +1 -1
  55. package/dist/canvas/renderer/fonts.d.ts.map +1 -1
  56. package/dist/canvas/renderer/fonts.js +2 -0
  57. package/dist/canvas/renderer/fonts.js.map +1 -1
  58. package/dist/canvas/renderer/lifecycle.d.ts.map +1 -1
  59. package/dist/canvas/renderer/lifecycle.js +6 -0
  60. package/dist/canvas/renderer/lifecycle.js.map +1 -1
  61. package/dist/canvas/renderer/methods.d.ts +0 -1
  62. package/dist/canvas/renderer/methods.d.ts.map +1 -1
  63. package/dist/canvas/renderer/methods.js +1 -4
  64. package/dist/canvas/renderer/methods.js.map +1 -1
  65. package/dist/canvas/renderer/overlay-pass.d.ts.map +1 -1
  66. package/dist/canvas/renderer/overlay-pass.js +0 -1
  67. package/dist/canvas/renderer/overlay-pass.js.map +1 -1
  68. package/dist/canvas/renderer/pipeline.d.ts.map +1 -1
  69. package/dist/canvas/renderer/pipeline.js +13 -2
  70. package/dist/canvas/renderer/pipeline.js.map +1 -1
  71. package/dist/canvas/renderer/play-scenes.d.ts +13 -0
  72. package/dist/canvas/renderer/play-scenes.d.ts.map +1 -0
  73. package/dist/canvas/renderer/play-scenes.js +40 -0
  74. package/dist/canvas/renderer/play-scenes.js.map +1 -0
  75. package/dist/canvas/renderer/tiles/cache.d.ts +19 -1
  76. package/dist/canvas/renderer/tiles/cache.d.ts.map +1 -1
  77. package/dist/canvas/renderer/tiles/cache.js +32 -1
  78. package/dist/canvas/renderer/tiles/cache.js.map +1 -1
  79. package/dist/canvas/renderer/tiles/controller.d.ts +11 -0
  80. package/dist/canvas/renderer/tiles/controller.d.ts.map +1 -1
  81. package/dist/canvas/renderer/tiles/controller.js +18 -1
  82. package/dist/canvas/renderer/tiles/controller.js.map +1 -1
  83. package/dist/canvas/renderer/tiles/index.d.ts +2 -2
  84. package/dist/canvas/renderer/tiles/planner.d.ts +1 -1
  85. package/dist/canvas/renderer/types.d.ts +18 -4
  86. package/dist/canvas/renderer/types.d.ts.map +1 -1
  87. package/dist/canvas/renderer/visual-bounds.d.ts +1 -1
  88. package/dist/canvas/renderer/visual-bounds.js +1 -1
  89. package/dist/canvas/renderer.d.ts +22 -3
  90. package/dist/canvas/renderer.d.ts.map +1 -1
  91. package/dist/canvas/renderer.js +29 -1
  92. package/dist/canvas/renderer.js.map +1 -1
  93. package/dist/canvas/scene.d.ts +2 -1
  94. package/dist/canvas/scene.d.ts.map +1 -1
  95. package/dist/canvas/scene.js +41 -9
  96. package/dist/canvas/scene.js.map +1 -1
  97. package/dist/canvas/shadows/silhouette.js +1 -1
  98. package/dist/canvas/texture.d.ts +20 -0
  99. package/dist/canvas/texture.d.ts.map +1 -0
  100. package/dist/canvas/texture.js +100 -0
  101. package/dist/canvas/texture.js.map +1 -0
  102. package/dist/clipboard.js +16 -5
  103. package/dist/clipboard.js.map +1 -1
  104. package/dist/constants.d.ts +5 -1
  105. package/dist/constants.d.ts.map +1 -1
  106. package/dist/constants.js +5 -1
  107. package/dist/constants.js.map +1 -1
  108. package/dist/design-jsx/index.d.ts +2 -2
  109. package/dist/design-jsx/index.js +2 -2
  110. package/dist/design-jsx/renderer.d.ts +3 -2
  111. package/dist/design-jsx/renderer.d.ts.map +1 -1
  112. package/dist/design-jsx/renderer.js +2 -2
  113. package/dist/design-jsx/renderer.js.map +1 -1
  114. package/dist/design-memory/check.d.ts +90 -0
  115. package/dist/design-memory/check.d.ts.map +1 -0
  116. package/dist/design-memory/check.js +281 -0
  117. package/dist/design-memory/check.js.map +1 -0
  118. package/dist/design-memory/describe.d.ts +37 -0
  119. package/dist/design-memory/describe.d.ts.map +1 -0
  120. package/dist/design-memory/describe.js +52 -0
  121. package/dist/design-memory/describe.js.map +1 -0
  122. package/dist/design-memory/distil.d.ts +22 -0
  123. package/dist/design-memory/distil.d.ts.map +1 -0
  124. package/dist/design-memory/distil.js +54 -0
  125. package/dist/design-memory/distil.js.map +1 -0
  126. package/dist/design-memory/document.d.ts +12 -0
  127. package/dist/design-memory/document.d.ts.map +1 -0
  128. package/dist/design-memory/document.js +64 -0
  129. package/dist/design-memory/document.js.map +1 -0
  130. package/dist/design-memory/guard.d.ts +48 -0
  131. package/dist/design-memory/guard.d.ts.map +1 -0
  132. package/dist/design-memory/guard.js +105 -0
  133. package/dist/design-memory/guard.js.map +1 -0
  134. package/dist/design-memory/index.d.ts +9 -0
  135. package/dist/design-memory/index.js +9 -0
  136. package/dist/design-memory/refusal.d.ts +32 -0
  137. package/dist/design-memory/refusal.d.ts.map +1 -0
  138. package/dist/design-memory/refusal.js +68 -0
  139. package/dist/design-memory/refusal.js.map +1 -0
  140. package/dist/design-memory/rules.d.ts +63 -0
  141. package/dist/design-memory/rules.d.ts.map +1 -0
  142. package/dist/design-memory/rules.js +224 -0
  143. package/dist/design-memory/rules.js.map +1 -0
  144. package/dist/design-memory/values.d.ts +28 -0
  145. package/dist/design-memory/values.d.ts.map +1 -0
  146. package/dist/design-memory/values.js +160 -0
  147. package/dist/design-memory/values.js.map +1 -0
  148. package/dist/editor/alignment.js +1 -1
  149. package/dist/editor/bridges/components.d.ts +2 -0
  150. package/dist/editor/bridges/components.d.ts.map +1 -1
  151. package/dist/editor/bridges/components.js +2 -0
  152. package/dist/editor/bridges/components.js.map +1 -1
  153. package/dist/editor/bridges/undo.d.ts +1 -1
  154. package/dist/editor/clipboard/assets.js +1 -1
  155. package/dist/editor/clipboard/export.d.ts.map +1 -1
  156. package/dist/editor/clipboard/export.js +16 -2
  157. package/dist/editor/clipboard/export.js.map +1 -1
  158. package/dist/editor/clipboard/placement.d.ts +1 -1
  159. package/dist/editor/clipboard/placement.js +1 -1
  160. package/dist/editor/clipboard/snapshot.d.ts.map +1 -1
  161. package/dist/editor/clipboard/snapshot.js +12 -4
  162. package/dist/editor/clipboard/snapshot.js.map +1 -1
  163. package/dist/editor/clipboard.d.ts.map +1 -1
  164. package/dist/editor/clipboard.js +2 -7
  165. package/dist/editor/clipboard.js.map +1 -1
  166. package/dist/editor/color-space.d.ts.map +1 -1
  167. package/dist/editor/color-space.js +33 -38
  168. package/dist/editor/color-space.js.map +1 -1
  169. package/dist/editor/components/instances.d.ts +2 -0
  170. package/dist/editor/components/instances.d.ts.map +1 -1
  171. package/dist/editor/components/instances.js +22 -1
  172. package/dist/editor/components/instances.js.map +1 -1
  173. package/dist/editor/components.d.ts +2 -0
  174. package/dist/editor/components.d.ts.map +1 -1
  175. package/dist/editor/connectors/attach.js +1 -1
  176. package/dist/editor/create.d.ts +36 -8
  177. package/dist/editor/create.d.ts.map +1 -1
  178. package/dist/editor/create.js +26 -61
  179. package/dist/editor/create.js.map +1 -1
  180. package/dist/editor/design-memory.d.ts +11 -0
  181. package/dist/editor/design-memory.d.ts.map +1 -0
  182. package/dist/editor/design-memory.js +40 -0
  183. package/dist/editor/design-memory.js.map +1 -0
  184. package/dist/editor/design-tokens.d.ts +4 -0
  185. package/dist/editor/design-tokens.d.ts.map +1 -1
  186. package/dist/editor/design-tokens.js +30 -1
  187. package/dist/editor/design-tokens.js.map +1 -1
  188. package/dist/editor/document-colors.d.ts +23 -0
  189. package/dist/editor/document-colors.d.ts.map +1 -0
  190. package/dist/editor/document-colors.js +53 -0
  191. package/dist/editor/document-colors.js.map +1 -0
  192. package/dist/editor/eyedropper.d.ts +47 -0
  193. package/dist/editor/eyedropper.d.ts.map +1 -0
  194. package/dist/editor/eyedropper.js +168 -0
  195. package/dist/editor/eyedropper.js.map +1 -0
  196. package/dist/editor/fonts.d.ts +9 -0
  197. package/dist/editor/fonts.d.ts.map +1 -0
  198. package/dist/editor/fonts.js +14 -0
  199. package/dist/editor/fonts.js.map +1 -0
  200. package/dist/editor/history/atomic-tool.d.ts +9 -2
  201. package/dist/editor/history/atomic-tool.d.ts.map +1 -1
  202. package/dist/editor/history/atomic-tool.js +6 -0
  203. package/dist/editor/history/atomic-tool.js.map +1 -1
  204. package/dist/editor/history/capture.d.ts +13 -0
  205. package/dist/editor/history/capture.d.ts.map +1 -0
  206. package/dist/editor/history/capture.js +28 -0
  207. package/dist/editor/history/capture.js.map +1 -0
  208. package/dist/editor/history/document-change.d.ts.map +1 -1
  209. package/dist/editor/history/document-change.js +2 -22
  210. package/dist/editor/history/document-change.js.map +1 -1
  211. package/dist/editor/history/edit.d.ts +7 -0
  212. package/dist/editor/history/edit.d.ts.map +1 -1
  213. package/dist/editor/history/edit.js +6 -3
  214. package/dist/editor/history/edit.js.map +1 -1
  215. package/dist/editor/history/subtree.d.ts +9 -0
  216. package/dist/editor/history/subtree.d.ts.map +1 -1
  217. package/dist/editor/history/subtree.js +12 -2
  218. package/dist/editor/history/subtree.js.map +1 -1
  219. package/dist/editor/index.d.ts +4 -2
  220. package/dist/editor/index.js +4 -2
  221. package/dist/editor/nudge.js +1 -1
  222. package/dist/editor/nudge.js.map +1 -1
  223. package/dist/editor/pages.d.ts +7 -5
  224. package/dist/editor/pages.d.ts.map +1 -1
  225. package/dist/editor/pages.js +35 -25
  226. package/dist/editor/pages.js.map +1 -1
  227. package/dist/editor/play/states.d.ts +3 -1
  228. package/dist/editor/play/states.d.ts.map +1 -1
  229. package/dist/editor/play/states.js +1 -1
  230. package/dist/editor/play/states.js.map +1 -1
  231. package/dist/editor/read-only/actions.js +6 -0
  232. package/dist/editor/read-only/actions.js.map +1 -1
  233. package/dist/editor/render-requests.d.ts +18 -0
  234. package/dist/editor/render-requests.d.ts.map +1 -0
  235. package/dist/editor/render-requests.js +76 -0
  236. package/dist/editor/render-requests.js.map +1 -0
  237. package/dist/editor/scale/rescale.d.ts +1 -1
  238. package/dist/editor/selection/container.d.ts +2 -0
  239. package/dist/editor/selection/container.d.ts.map +1 -1
  240. package/dist/editor/selection/container.js +17 -1
  241. package/dist/editor/selection/container.js.map +1 -1
  242. package/dist/editor/selection/navigation.js +7 -4
  243. package/dist/editor/selection/navigation.js.map +1 -1
  244. package/dist/editor/selection/overlays.d.ts.map +1 -1
  245. package/dist/editor/selection/overlays.js +1 -1
  246. package/dist/editor/selection/overlays.js.map +1 -1
  247. package/dist/editor/selection/read.d.ts +6 -2
  248. package/dist/editor/selection.d.ts +9 -2
  249. package/dist/editor/selection.d.ts.map +1 -1
  250. package/dist/editor/shapes/with-text.d.ts.map +1 -1
  251. package/dist/editor/shapes/with-text.js +2 -5
  252. package/dist/editor/shapes/with-text.js.map +1 -1
  253. package/dist/editor/structure/auto-layout-wrap.js +1 -1
  254. package/dist/editor/structure/auto-layout-wrap.js.map +1 -1
  255. package/dist/editor/structure/boolean.d.ts +2 -3
  256. package/dist/editor/structure/boolean.d.ts.map +1 -1
  257. package/dist/editor/structure/boolean.js.map +1 -1
  258. package/dist/editor/structure/group/bounds.d.ts.map +1 -1
  259. package/dist/editor/structure/group/bounds.js +1 -3
  260. package/dist/editor/structure/group/bounds.js.map +1 -1
  261. package/dist/editor/structure/outline-stroke.js +3 -3
  262. package/dist/editor/structure/outline-stroke.js.map +1 -1
  263. package/dist/editor/structure/reorder.d.ts.map +1 -1
  264. package/dist/editor/structure/reorder.js +7 -14
  265. package/dist/editor/structure/reorder.js.map +1 -1
  266. package/dist/editor/structure/state.js +1 -1
  267. package/dist/editor/structure/state.js.map +1 -1
  268. package/dist/editor/structure.d.ts +1 -2
  269. package/dist/editor/structure.d.ts.map +1 -1
  270. package/dist/editor/structure.js +3 -3
  271. package/dist/editor/structure.js.map +1 -1
  272. package/dist/editor/tool-registry.d.ts.map +1 -1
  273. package/dist/editor/tool-registry.js +2 -1
  274. package/dist/editor/tool-registry.js.map +1 -1
  275. package/dist/editor/types.d.ts +9 -2
  276. package/dist/editor/types.d.ts.map +1 -1
  277. package/dist/editor/variables.d.ts.map +1 -1
  278. package/dist/editor/variables.js +57 -1
  279. package/dist/editor/variables.js.map +1 -1
  280. package/dist/editor/variations/create.d.ts +28 -0
  281. package/dist/editor/variations/create.d.ts.map +1 -0
  282. package/dist/editor/variations/create.js +176 -0
  283. package/dist/editor/variations/create.js.map +1 -0
  284. package/dist/editor/variations/pick.d.ts +16 -0
  285. package/dist/editor/variations/pick.d.ts.map +1 -0
  286. package/dist/editor/variations/pick.js +23 -0
  287. package/dist/editor/variations/pick.js.map +1 -0
  288. package/dist/editor/variations.d.ts +28 -0
  289. package/dist/editor/variations.d.ts.map +1 -0
  290. package/dist/editor/variations.js +88 -0
  291. package/dist/editor/variations.js.map +1 -0
  292. package/dist/figma-api/accessors/reactions.d.ts.map +1 -1
  293. package/dist/figma-api/accessors/reactions.js +4 -1
  294. package/dist/figma-api/accessors/reactions.js.map +1 -1
  295. package/dist/figma-api/accessors/text/index.d.ts.map +1 -1
  296. package/dist/figma-api/accessors/text/index.js +7 -1
  297. package/dist/figma-api/accessors/text/index.js.map +1 -1
  298. package/dist/figma-api/accessors/text/opentype.d.ts +17 -0
  299. package/dist/figma-api/accessors/text/opentype.d.ts.map +1 -0
  300. package/dist/figma-api/accessors/text/opentype.js +28 -0
  301. package/dist/figma-api/accessors/text/opentype.js.map +1 -0
  302. package/dist/figma-api/accessors/visual.d.ts.map +1 -1
  303. package/dist/figma-api/accessors/visual.js +33 -0
  304. package/dist/figma-api/accessors/visual.js.map +1 -1
  305. package/dist/figma-api/effects.d.ts +79 -3
  306. package/dist/figma-api/effects.d.ts.map +1 -1
  307. package/dist/figma-api/effects.js +150 -9
  308. package/dist/figma-api/effects.js.map +1 -1
  309. package/dist/figma-api/fonts/loaded.d.ts +3 -1
  310. package/dist/figma-api/fonts/loaded.d.ts.map +1 -1
  311. package/dist/figma-api/fonts/loaded.js +8 -1
  312. package/dist/figma-api/fonts/loaded.js.map +1 -1
  313. package/dist/figma-api/index.d.ts +18 -0
  314. package/dist/figma-api/index.d.ts.map +1 -1
  315. package/dist/figma-api/index.js +19 -1
  316. package/dist/figma-api/index.js.map +1 -1
  317. package/dist/figma-api/overrides.d.ts +13 -1
  318. package/dist/figma-api/overrides.d.ts.map +1 -1
  319. package/dist/figma-api/overrides.js +196 -4
  320. package/dist/figma-api/overrides.js.map +1 -1
  321. package/dist/figma-api/paints.d.ts +3 -3
  322. package/dist/figma-api/paints.d.ts.map +1 -1
  323. package/dist/figma-api/paints.js +14 -4
  324. package/dist/figma-api/paints.js.map +1 -1
  325. package/dist/figma-api/proxy.d.ts +4 -1
  326. package/dist/figma-api/proxy.d.ts.map +1 -1
  327. package/dist/figma-api/proxy.js +1 -1
  328. package/dist/figma-api/proxy.js.map +1 -1
  329. package/dist/figma-api/reactions.d.ts +41 -13
  330. package/dist/figma-api/reactions.d.ts.map +1 -1
  331. package/dist/figma-api/reactions.js +113 -31
  332. package/dist/figma-api/reactions.js.map +1 -1
  333. package/dist/figma-api/render-bounds.js +1 -1
  334. package/dist/figma-api/serialization.d.ts.map +1 -1
  335. package/dist/figma-api/serialization.js +2 -1
  336. package/dist/figma-api/serialization.js.map +1 -1
  337. package/dist/figma-api/shape-details.d.ts +26 -0
  338. package/dist/figma-api/shape-details.d.ts.map +1 -0
  339. package/dist/figma-api/shape-details.js +28 -0
  340. package/dist/figma-api/shape-details.js.map +1 -0
  341. package/dist/figma-api/shape-with-text.js +2 -5
  342. package/dist/figma-api/shape-with-text.js.map +1 -1
  343. package/dist/figma-api/surface.d.ts +7 -4
  344. package/dist/figma-api/surface.d.ts.map +1 -1
  345. package/dist/figma-api/surface.js +7 -2
  346. package/dist/figma-api/surface.js.map +1 -1
  347. package/dist/figma-api/transform.d.ts +1 -1
  348. package/dist/geometry/figma.d.ts +1 -1
  349. package/dist/geometry/image-crop.d.ts +1 -1
  350. package/dist/geometry/image-crop.js +1 -1
  351. package/dist/icons/svg.js +1 -1
  352. package/dist/icons/svg.js.map +1 -1
  353. package/dist/index.d.ts +4 -2
  354. package/dist/index.js +4 -2
  355. package/dist/io/formats/boolean-path.d.ts +19 -0
  356. package/dist/io/formats/boolean-path.d.ts.map +1 -0
  357. package/dist/io/formats/boolean-path.js +47 -0
  358. package/dist/io/formats/boolean-path.js.map +1 -0
  359. package/dist/io/formats/design-tokens/decode.js +1 -1
  360. package/dist/io/formats/design-tokens/index.d.ts +4 -1
  361. package/dist/io/formats/design-tokens/index.js +4 -1
  362. package/dist/io/formats/design-tokens/plan/changes.d.ts +5 -3
  363. package/dist/io/formats/design-tokens/plan/changes.d.ts.map +1 -1
  364. package/dist/io/formats/design-tokens/plan/changes.js +1 -1
  365. package/dist/io/formats/design-tokens/plan/changes.js.map +1 -1
  366. package/dist/io/formats/design-tokens/project.d.ts +17 -2
  367. package/dist/io/formats/design-tokens/project.d.ts.map +1 -1
  368. package/dist/io/formats/design-tokens/project.js +29 -8
  369. package/dist/io/formats/design-tokens/project.js.map +1 -1
  370. package/dist/io/formats/design-tokens/styles.d.ts.map +1 -1
  371. package/dist/io/formats/design-tokens/styles.js.map +1 -1
  372. package/dist/io/formats/design-tokens/sync/apply.d.ts +42 -0
  373. package/dist/io/formats/design-tokens/sync/apply.d.ts.map +1 -0
  374. package/dist/io/formats/design-tokens/sync/apply.js +73 -0
  375. package/dist/io/formats/design-tokens/sync/apply.js.map +1 -0
  376. package/dist/io/formats/design-tokens/sync/drift.d.ts +77 -0
  377. package/dist/io/formats/design-tokens/sync/drift.d.ts.map +1 -0
  378. package/dist/io/formats/design-tokens/sync/drift.js +391 -0
  379. package/dist/io/formats/design-tokens/sync/drift.js.map +1 -0
  380. package/dist/io/formats/design-tokens/sync/files.d.ts +15 -0
  381. package/dist/io/formats/design-tokens/sync/files.d.ts.map +1 -0
  382. package/dist/io/formats/design-tokens/sync/files.js +35 -0
  383. package/dist/io/formats/design-tokens/sync/files.js.map +1 -0
  384. package/dist/io/formats/drawio/edges.d.ts +7 -1
  385. package/dist/io/formats/drawio/edges.d.ts.map +1 -1
  386. package/dist/io/formats/drawio/edges.js +54 -1
  387. package/dist/io/formats/drawio/edges.js.map +1 -1
  388. package/dist/io/formats/drawio/export.d.ts.map +1 -1
  389. package/dist/io/formats/drawio/export.js +19 -2
  390. package/dist/io/formats/drawio/export.js.map +1 -1
  391. package/dist/io/formats/drawio/index.d.ts.map +1 -1
  392. package/dist/io/formats/drawio/index.js +2 -1
  393. package/dist/io/formats/drawio/index.js.map +1 -1
  394. package/dist/io/formats/drawio/label.js +1 -1
  395. package/dist/io/formats/drawio/paint.js +1 -1
  396. package/dist/io/formats/drawio/placement.d.ts +1 -1
  397. package/dist/io/formats/fig/export/patch/index.d.ts.map +1 -1
  398. package/dist/io/formats/fig/export/patch/index.js +5 -0
  399. package/dist/io/formats/fig/export/patch/index.js.map +1 -1
  400. package/dist/io/formats/fig/thumbnail-page.d.ts +3 -4
  401. package/dist/io/formats/fig/thumbnail-page.d.ts.map +1 -1
  402. package/dist/io/formats/fig/thumbnail-page.js.map +1 -1
  403. package/dist/io/formats/html/import.d.ts.map +1 -1
  404. package/dist/io/formats/html/import.js +3 -1
  405. package/dist/io/formats/html/import.js.map +1 -1
  406. package/dist/io/formats/html/index.d.ts +2 -2
  407. package/dist/io/formats/html/index.d.ts.map +1 -1
  408. package/dist/io/formats/html/index.js +6 -4
  409. package/dist/io/formats/html/index.js.map +1 -1
  410. package/dist/io/formats/html/layers.d.ts +7 -4
  411. package/dist/io/formats/html/layers.d.ts.map +1 -1
  412. package/dist/io/formats/html/layers.js +4 -1
  413. package/dist/io/formats/html/layers.js.map +1 -1
  414. package/dist/io/formats/html/vectors.d.ts +2 -1
  415. package/dist/io/formats/html/vectors.d.ts.map +1 -1
  416. package/dist/io/formats/html/vectors.js +3 -2
  417. package/dist/io/formats/html/vectors.js.map +1 -1
  418. package/dist/io/formats/mermaid/styles.js +1 -1
  419. package/dist/io/formats/pdf/document.d.ts +3 -1
  420. package/dist/io/formats/pdf/document.d.ts.map +1 -1
  421. package/dist/io/formats/pdf/document.js +6 -3
  422. package/dist/io/formats/pdf/document.js.map +1 -1
  423. package/dist/io/formats/pdf/dom.d.ts +6 -1
  424. package/dist/io/formats/pdf/dom.d.ts.map +1 -1
  425. package/dist/io/formats/pdf/dom.js +9 -22
  426. package/dist/io/formats/pdf/dom.js.map +1 -1
  427. package/dist/io/formats/pdf/export.js +1 -1
  428. package/dist/io/formats/pdf/export.js.map +1 -1
  429. package/dist/io/formats/pdf/prepare.d.ts +1 -1
  430. package/dist/io/formats/pen/imports.d.ts +4 -1
  431. package/dist/io/formats/pen/imports.d.ts.map +1 -1
  432. package/dist/io/formats/pen/imports.js.map +1 -1
  433. package/dist/io/formats/pen/index.d.ts.map +1 -1
  434. package/dist/io/formats/pen/index.js +31 -3
  435. package/dist/io/formats/pen/index.js.map +1 -1
  436. package/dist/io/formats/pptx/export.js +1 -1
  437. package/dist/io/formats/pptx/geometry.d.ts +1 -1
  438. package/dist/io/formats/raster/adjusted-images.d.ts +15 -0
  439. package/dist/io/formats/raster/adjusted-images.d.ts.map +1 -0
  440. package/dist/io/formats/raster/adjusted-images.js +118 -0
  441. package/dist/io/formats/raster/adjusted-images.js.map +1 -0
  442. package/dist/io/formats/raster/headless.d.ts +11 -1
  443. package/dist/io/formats/raster/headless.d.ts.map +1 -1
  444. package/dist/io/formats/raster/headless.js +4 -4
  445. package/dist/io/formats/raster/headless.js.map +1 -1
  446. package/dist/io/formats/raster/index.d.ts +2 -2
  447. package/dist/io/formats/raster/pixels.d.ts +7 -1
  448. package/dist/io/formats/raster/pixels.d.ts.map +1 -1
  449. package/dist/io/formats/raster/pixels.js.map +1 -1
  450. package/dist/io/formats/raster/render.d.ts.map +1 -1
  451. package/dist/io/formats/raster/render.js +4 -0
  452. package/dist/io/formats/raster/render.js.map +1 -1
  453. package/dist/io/formats/svg/defs.d.ts +5 -6
  454. package/dist/io/formats/svg/defs.d.ts.map +1 -1
  455. package/dist/io/formats/svg/defs.js +4 -54
  456. package/dist/io/formats/svg/defs.js.map +1 -1
  457. package/dist/io/formats/svg/effects.d.ts +16 -0
  458. package/dist/io/formats/svg/effects.d.ts.map +1 -0
  459. package/dist/io/formats/svg/effects.js +126 -0
  460. package/dist/io/formats/svg/effects.js.map +1 -0
  461. package/dist/io/formats/svg/export.d.ts +7 -1
  462. package/dist/io/formats/svg/export.d.ts.map +1 -1
  463. package/dist/io/formats/svg/export.js +224 -50
  464. package/dist/io/formats/svg/export.js.map +1 -1
  465. package/dist/io/formats/svg/filter.d.ts +27 -0
  466. package/dist/io/formats/svg/filter.d.ts.map +1 -0
  467. package/dist/io/formats/svg/filter.js +44 -0
  468. package/dist/io/formats/svg/filter.js.map +1 -0
  469. package/dist/io/formats/svg/grain.d.ts +26 -0
  470. package/dist/io/formats/svg/grain.d.ts.map +1 -0
  471. package/dist/io/formats/svg/grain.js +298 -0
  472. package/dist/io/formats/svg/grain.js.map +1 -0
  473. package/dist/io/formats/svg/strokes.d.ts +1 -1
  474. package/dist/io/formats/svg/strokes.d.ts.map +1 -1
  475. package/dist/io/formats/svg/strokes.js +1 -2
  476. package/dist/io/formats/svg/strokes.js.map +1 -1
  477. package/dist/io/formats/svg/text/import.js +1 -1
  478. package/dist/io/formats/svg/text/layout.d.ts +5 -2
  479. package/dist/io/formats/svg/text/layout.d.ts.map +1 -1
  480. package/dist/io/formats/svg/text/layout.js +6 -3
  481. package/dist/io/formats/svg/text/layout.js.map +1 -1
  482. package/dist/io/formats/video/composite.d.ts +18 -0
  483. package/dist/io/formats/video/composite.d.ts.map +1 -0
  484. package/dist/io/formats/video/composite.js +79 -0
  485. package/dist/io/formats/video/composite.js.map +1 -0
  486. package/dist/io/formats/video/formats.d.ts +29 -0
  487. package/dist/io/formats/video/formats.d.ts.map +1 -0
  488. package/dist/io/formats/video/formats.js +43 -0
  489. package/dist/io/formats/video/formats.js.map +1 -0
  490. package/dist/io/formats/video/gif.d.ts +13 -0
  491. package/dist/io/formats/video/gif.d.ts.map +1 -0
  492. package/dist/io/formats/video/gif.js +56 -0
  493. package/dist/io/formats/video/gif.js.map +1 -0
  494. package/dist/io/formats/video/index.d.ts +9 -0
  495. package/dist/io/formats/video/index.js +9 -0
  496. package/dist/io/formats/video/plan.d.ts +64 -0
  497. package/dist/io/formats/video/plan.d.ts.map +1 -0
  498. package/dist/io/formats/video/plan.js +90 -0
  499. package/dist/io/formats/video/plan.js.map +1 -0
  500. package/dist/io/formats/video/record.d.ts +36 -0
  501. package/dist/io/formats/video/record.d.ts.map +1 -0
  502. package/dist/io/formats/video/record.js +154 -0
  503. package/dist/io/formats/video/record.js.map +1 -0
  504. package/dist/io/formats/video/sink.d.ts +29 -0
  505. package/dist/io/formats/video/sink.d.ts.map +1 -0
  506. package/dist/io/formats/video/sink.js +16 -0
  507. package/dist/io/formats/video/sink.js.map +1 -0
  508. package/dist/io/formats/video/size.d.ts +19 -0
  509. package/dist/io/formats/video/size.d.ts.map +1 -0
  510. package/dist/io/formats/video/size.js +26 -0
  511. package/dist/io/formats/video/size.js.map +1 -0
  512. package/dist/io/formats/video/webcodecs.d.ts +18 -0
  513. package/dist/io/formats/video/webcodecs.d.ts.map +1 -0
  514. package/dist/io/formats/video/webcodecs.js +74 -0
  515. package/dist/io/formats/video/webcodecs.js.map +1 -0
  516. package/dist/io/formats.d.ts.map +1 -1
  517. package/dist/io/formats.js +40 -11
  518. package/dist/io/formats.js.map +1 -1
  519. package/dist/io/types.d.ts +19 -4
  520. package/dist/io/types.d.ts.map +1 -1
  521. package/dist/kiwi/fig/parse/transfer.d.ts +1 -1
  522. package/dist/layout/apply.d.ts.map +1 -1
  523. package/dist/layout/apply.js +50 -12
  524. package/dist/layout/apply.js.map +1 -1
  525. package/dist/layout/auto-layout-handles.d.ts +66 -0
  526. package/dist/layout/auto-layout-handles.d.ts.map +1 -0
  527. package/dist/layout/auto-layout-handles.js +291 -0
  528. package/dist/layout/auto-layout-handles.js.map +1 -0
  529. package/dist/layout/derived.d.ts +7 -1
  530. package/dist/layout/derived.d.ts.map +1 -1
  531. package/dist/layout/derived.js +11 -1
  532. package/dist/layout/derived.js.map +1 -1
  533. package/dist/layout/grid.d.ts +7 -2
  534. package/dist/layout/grid.d.ts.map +1 -1
  535. package/dist/layout/grid.js +27 -9
  536. package/dist/layout/grid.js.map +1 -1
  537. package/dist/layout/mutations.d.ts +1 -0
  538. package/dist/layout/mutations.d.ts.map +1 -1
  539. package/dist/layout/mutations.js +10 -0
  540. package/dist/layout/mutations.js.map +1 -1
  541. package/dist/layout/strokes.d.ts +9 -1
  542. package/dist/layout/strokes.d.ts.map +1 -1
  543. package/dist/layout/strokes.js +12 -1
  544. package/dist/layout/strokes.js.map +1 -1
  545. package/dist/layout/yoga-helpers.d.ts +3 -1
  546. package/dist/layout/yoga-helpers.d.ts.map +1 -1
  547. package/dist/layout/yoga-helpers.js +16 -2
  548. package/dist/layout/yoga-helpers.js.map +1 -1
  549. package/dist/layout.d.ts +3 -2
  550. package/dist/layout.d.ts.map +1 -1
  551. package/dist/layout.js +73 -39
  552. package/dist/layout.js.map +1 -1
  553. package/dist/lint/fixes.d.ts.map +1 -1
  554. package/dist/lint/fixes.js +9 -3
  555. package/dist/lint/fixes.js.map +1 -1
  556. package/dist/lint/index.d.ts +3 -2
  557. package/dist/lint/index.js +2 -1
  558. package/dist/lint/linter.d.ts +13 -0
  559. package/dist/lint/linter.d.ts.map +1 -1
  560. package/dist/lint/linter.js +123 -9
  561. package/dist/lint/linter.js.map +1 -1
  562. package/dist/lint/presets.d.ts.map +1 -1
  563. package/dist/lint/presets.js +2 -0
  564. package/dist/lint/presets.js.map +1 -1
  565. package/dist/lint/rules/design-memory.d.ts +15 -0
  566. package/dist/lint/rules/design-memory.d.ts.map +1 -0
  567. package/dist/lint/rules/design-memory.js +90 -0
  568. package/dist/lint/rules/design-memory.js.map +1 -0
  569. package/dist/lint/rules/effect-style-required.js +1 -0
  570. package/dist/lint/rules/effect-style-required.js.map +1 -1
  571. package/dist/lint/rules/index.d.ts +6 -5
  572. package/dist/lint/rules/index.d.ts.map +1 -1
  573. package/dist/lint/rules/index.js +6 -2
  574. package/dist/lint/rules/index.js.map +1 -1
  575. package/dist/lint/rules/no-unbound-token-values.d.ts +6 -0
  576. package/dist/lint/rules/no-unbound-token-values.d.ts.map +1 -0
  577. package/dist/lint/rules/no-unbound-token-values.js +79 -0
  578. package/dist/lint/rules/no-unbound-token-values.js.map +1 -0
  579. package/dist/lint/rules/text-style-required.js +1 -0
  580. package/dist/lint/rules/text-style-required.js.map +1 -1
  581. package/dist/lint/types.d.ts +32 -2
  582. package/dist/lint/types.d.ts.map +1 -1
  583. package/dist/node/video.d.ts +12 -0
  584. package/dist/node/video.d.ts.map +1 -0
  585. package/dist/node/video.js +206 -0
  586. package/dist/node/video.js.map +1 -0
  587. package/dist/pairdraw-api/design-memory.d.ts +19 -0
  588. package/dist/pairdraw-api/design-memory.d.ts.map +1 -0
  589. package/dist/pairdraw-api/design-memory.js +39 -0
  590. package/dist/pairdraw-api/design-memory.js.map +1 -0
  591. package/dist/pairdraw-api/index.d.ts +45 -1
  592. package/dist/pairdraw-api/index.d.ts.map +1 -1
  593. package/dist/pairdraw-api/index.js +55 -2
  594. package/dist/pairdraw-api/index.js.map +1 -1
  595. package/dist/pairdraw-api/nodes.d.ts +12 -1
  596. package/dist/pairdraw-api/nodes.d.ts.map +1 -1
  597. package/dist/pairdraw-api/nodes.js +28 -1
  598. package/dist/pairdraw-api/nodes.js.map +1 -1
  599. package/dist/pairdraw-api/variations.d.ts +48 -0
  600. package/dist/pairdraw-api/variations.d.ts.map +1 -0
  601. package/dist/pairdraw-api/variations.js +76 -0
  602. package/dist/pairdraw-api/variations.js.map +1 -0
  603. package/dist/prototype/easing.d.ts +13 -0
  604. package/dist/prototype/easing.d.ts.map +1 -0
  605. package/dist/prototype/easing.js +36 -0
  606. package/dist/prototype/easing.js.map +1 -0
  607. package/dist/prototype/frames.d.ts +10 -0
  608. package/dist/prototype/frames.d.ts.map +1 -0
  609. package/dist/prototype/frames.js +12 -0
  610. package/dist/prototype/frames.js.map +1 -0
  611. package/dist/prototype/hit.d.ts +17 -0
  612. package/dist/prototype/hit.d.ts.map +1 -0
  613. package/dist/prototype/hit.js +45 -0
  614. package/dist/prototype/hit.js.map +1 -0
  615. package/dist/prototype/index.d.ts +14 -0
  616. package/dist/prototype/index.js +14 -0
  617. package/dist/prototype/pointer.d.ts +63 -0
  618. package/dist/prototype/pointer.d.ts.map +1 -0
  619. package/dist/prototype/pointer.js +104 -0
  620. package/dist/prototype/pointer.js.map +1 -0
  621. package/dist/prototype/reactions.d.ts +45 -0
  622. package/dist/prototype/reactions.d.ts.map +1 -0
  623. package/dist/prototype/reactions.js +122 -0
  624. package/dist/prototype/reactions.js.map +1 -0
  625. package/dist/prototype/scene.d.ts +35 -0
  626. package/dist/prototype/scene.d.ts.map +1 -0
  627. package/dist/prototype/scene.js +86 -0
  628. package/dist/prototype/scene.js.map +1 -0
  629. package/dist/prototype/scenes.d.ts +81 -0
  630. package/dist/prototype/scenes.d.ts.map +1 -0
  631. package/dist/prototype/scenes.js +175 -0
  632. package/dist/prototype/scenes.js.map +1 -0
  633. package/dist/prototype/scroll.d.ts +48 -0
  634. package/dist/prototype/scroll.d.ts.map +1 -0
  635. package/dist/prototype/scroll.js +159 -0
  636. package/dist/prototype/scroll.js.map +1 -0
  637. package/dist/prototype/session.d.ts +71 -0
  638. package/dist/prototype/session.d.ts.map +1 -0
  639. package/dist/prototype/session.js +135 -0
  640. package/dist/prototype/session.js.map +1 -0
  641. package/dist/prototype/smart-animate/animation.d.ts +34 -0
  642. package/dist/prototype/smart-animate/animation.d.ts.map +1 -0
  643. package/dist/prototype/smart-animate/animation.js +212 -0
  644. package/dist/prototype/smart-animate/animation.js.map +1 -0
  645. package/dist/prototype/smart-animate/match.d.ts +24 -0
  646. package/dist/prototype/smart-animate/match.d.ts.map +1 -0
  647. package/dist/prototype/smart-animate/match.js +72 -0
  648. package/dist/prototype/smart-animate/match.js.map +1 -0
  649. package/dist/prototype/snapshot.d.ts +19 -0
  650. package/dist/prototype/snapshot.d.ts.map +1 -0
  651. package/dist/prototype/snapshot.js +56 -0
  652. package/dist/prototype/snapshot.js.map +1 -0
  653. package/dist/prototype/timeline.d.ts +132 -0
  654. package/dist/prototype/timeline.d.ts.map +1 -0
  655. package/dist/prototype/timeline.js +260 -0
  656. package/dist/prototype/timeline.js.map +1 -0
  657. package/dist/rpc/commands.d.ts +2 -2
  658. package/dist/rpc/index.d.ts +2 -2
  659. package/dist/rpc/read-commands.d.ts +18 -8
  660. package/dist/rpc/read-commands.d.ts.map +1 -1
  661. package/dist/rpc/read-commands.js +18 -9
  662. package/dist/rpc/read-commands.js.map +1 -1
  663. package/dist/text/font/faces.d.ts +12 -1
  664. package/dist/text/font/faces.d.ts.map +1 -1
  665. package/dist/text/font/faces.js +15 -1
  666. package/dist/text/font/faces.js.map +1 -1
  667. package/dist/text/font/features.d.ts +9 -0
  668. package/dist/text/font/features.d.ts.map +1 -0
  669. package/dist/text/font/features.js +27 -0
  670. package/dist/text/font/features.js.map +1 -0
  671. package/dist/text/font/manager.d.ts +12 -0
  672. package/dist/text/font/manager.d.ts.map +1 -1
  673. package/dist/text/font/manager.js +66 -12
  674. package/dist/text/font/manager.js.map +1 -1
  675. package/dist/text/index.d.ts +11 -9
  676. package/dist/text/index.js +4 -2
  677. package/dist/text/replace-fonts.d.ts +41 -0
  678. package/dist/text/replace-fonts.d.ts.map +1 -0
  679. package/dist/text/replace-fonts.js +121 -0
  680. package/dist/text/replace-fonts.js.map +1 -0
  681. package/dist/tools/analyze/responsive/index.d.ts +15 -0
  682. package/dist/tools/analyze/responsive/index.d.ts.map +1 -0
  683. package/dist/tools/analyze/responsive/index.js +203 -0
  684. package/dist/tools/analyze/responsive/index.js.map +1 -0
  685. package/dist/tools/analyze.d.ts +2 -1
  686. package/dist/tools/analyze.js +2 -1
  687. package/dist/tools/codegen/token-sync.d.ts +7 -0
  688. package/dist/tools/codegen/token-sync.d.ts.map +1 -0
  689. package/dist/tools/codegen/token-sync.js +85 -0
  690. package/dist/tools/codegen/token-sync.js.map +1 -0
  691. package/dist/tools/codegen/tokens.d.ts +1 -1
  692. package/dist/tools/codegen.d.ts +2 -1
  693. package/dist/tools/codegen.js +2 -1
  694. package/dist/tools/create/basic.js +1 -1
  695. package/dist/tools/create/behaviours.js +1 -1
  696. package/dist/tools/create/components.d.ts.map +1 -1
  697. package/dist/tools/create/components.js +4 -0
  698. package/dist/tools/create/components.js.map +1 -1
  699. package/dist/tools/create/html.js +3 -2
  700. package/dist/tools/create/html.js.map +1 -1
  701. package/dist/tools/create/icons.d.ts.map +1 -1
  702. package/dist/tools/create/icons.js +2 -1
  703. package/dist/tools/create/icons.js.map +1 -1
  704. package/dist/tools/create/mermaid.js +2 -1
  705. package/dist/tools/create/mermaid.js.map +1 -1
  706. package/dist/tools/create/render.js +1 -1
  707. package/dist/tools/create/svg.js +2 -1
  708. package/dist/tools/create/svg.js.map +1 -1
  709. package/dist/tools/create/vector.js +1 -1
  710. package/dist/tools/design-memory.d.ts +8 -0
  711. package/dist/tools/design-memory.d.ts.map +1 -0
  712. package/dist/tools/design-memory.js +68 -0
  713. package/dist/tools/design-memory.js.map +1 -0
  714. package/dist/tools/image-ai/generate.d.ts.map +1 -1
  715. package/dist/tools/image-ai/generate.js +3 -1
  716. package/dist/tools/image-ai/generate.js.map +1 -1
  717. package/dist/tools/index.d.ts +2 -1
  718. package/dist/tools/index.js +2 -1
  719. package/dist/tools/modify/fonts.d.ts +6 -0
  720. package/dist/tools/modify/fonts.d.ts.map +1 -0
  721. package/dist/tools/modify/fonts.js +27 -0
  722. package/dist/tools/modify/fonts.js.map +1 -0
  723. package/dist/tools/modify/layout.d.ts.map +1 -1
  724. package/dist/tools/modify/layout.js +1 -0
  725. package/dist/tools/modify/layout.js.map +1 -1
  726. package/dist/tools/modify/paint.js +1 -1
  727. package/dist/tools/modify/reactions.d.ts.map +1 -1
  728. package/dist/tools/modify/reactions.js +3 -3
  729. package/dist/tools/modify/reactions.js.map +1 -1
  730. package/dist/tools/modify/text.d.ts.map +1 -1
  731. package/dist/tools/modify/text.js +26 -5
  732. package/dist/tools/modify/text.js.map +1 -1
  733. package/dist/tools/modify/update.d.ts +10 -1
  734. package/dist/tools/modify/update.d.ts.map +1 -1
  735. package/dist/tools/modify/update.js +34 -3
  736. package/dist/tools/modify/update.js.map +1 -1
  737. package/dist/tools/modify.d.ts +2 -1
  738. package/dist/tools/modify.js +2 -1
  739. package/dist/tools/read/fonts.d.ts.map +1 -1
  740. package/dist/tools/read/fonts.js +17 -2
  741. package/dist/tools/read/fonts.js.map +1 -1
  742. package/dist/tools/read/libraries.js +2 -1
  743. package/dist/tools/read/libraries.js.map +1 -1
  744. package/dist/tools/read/nodes.d.ts.map +1 -1
  745. package/dist/tools/read/nodes.js.map +1 -1
  746. package/dist/tools/read/space.d.ts +3 -1
  747. package/dist/tools/read/space.d.ts.map +1 -1
  748. package/dist/tools/read/space.js +4 -3
  749. package/dist/tools/read/space.js.map +1 -1
  750. package/dist/tools/registry/core.d.ts +1 -1
  751. package/dist/tools/registry/core.d.ts.map +1 -1
  752. package/dist/tools/registry/core.js +3 -1
  753. package/dist/tools/registry/core.js.map +1 -1
  754. package/dist/tools/registry/extended.d.ts.map +1 -1
  755. package/dist/tools/registry/extended.js +16 -1
  756. package/dist/tools/registry/extended.js.map +1 -1
  757. package/dist/tools/schema.d.ts +18 -2
  758. package/dist/tools/schema.d.ts.map +1 -1
  759. package/dist/tools/schema.js +1 -1
  760. package/dist/tools/schema.js.map +1 -1
  761. package/dist/tools/stock-photo.js +1 -0
  762. package/dist/tools/stock-photo.js.map +1 -1
  763. package/dist/tools/structure/basic.d.ts.map +1 -1
  764. package/dist/tools/structure/basic.js +1 -0
  765. package/dist/tools/structure/basic.js.map +1 -1
  766. package/dist/tools/structure/batch.d.ts.map +1 -1
  767. package/dist/tools/structure/batch.js +22 -1
  768. package/dist/tools/structure/batch.js.map +1 -1
  769. package/dist/tools/structure/hierarchy.d.ts.map +1 -1
  770. package/dist/tools/structure/hierarchy.js +4 -0
  771. package/dist/tools/structure/hierarchy.js.map +1 -1
  772. package/dist/tools/structure/variations.d.ts +8 -0
  773. package/dist/tools/structure/variations.d.ts.map +1 -0
  774. package/dist/tools/structure/variations.js +106 -0
  775. package/dist/tools/structure/variations.js.map +1 -0
  776. package/dist/tools/structure.d.ts +2 -1
  777. package/dist/tools/structure.js +2 -1
  778. package/dist/tools/styles/types.d.ts +2 -4
  779. package/dist/tools/styles/types.d.ts.map +1 -1
  780. package/dist/tools/styles/types.js.map +1 -1
  781. package/dist/tools/vector/boolean.d.ts.map +1 -1
  782. package/dist/tools/vector/boolean.js +4 -0
  783. package/dist/tools/vector/boolean.js.map +1 -1
  784. package/dist/tools/vector/path.d.ts.map +1 -1
  785. package/dist/tools/vector/path.js +39 -7
  786. package/dist/tools/vector/path.js.map +1 -1
  787. package/dist/tools/vector/vectorize.js +1 -0
  788. package/dist/tools/vector/vectorize.js.map +1 -1
  789. package/dist/tools/vector/video.d.ts +6 -0
  790. package/dist/tools/vector/video.d.ts.map +1 -0
  791. package/dist/tools/vector/video.js +133 -0
  792. package/dist/tools/vector/video.js.map +1 -0
  793. package/dist/tools/vector.d.ts +2 -1
  794. package/dist/tools/vector.js +2 -1
  795. package/dist/tools/video-host.d.ts +12 -0
  796. package/dist/tools/video-host.d.ts.map +1 -0
  797. package/dist/tools/video-host.js +19 -0
  798. package/dist/tools/video-host.js.map +1 -0
  799. package/dist/vector/point-transform.d.ts +1 -1
  800. package/dist/vector/vectorize/svg/to-vectors.d.ts +1 -1
  801. package/dist/xpath.d.ts +3 -0
  802. package/dist/xpath.d.ts.map +1 -1
  803. package/dist/xpath.js +3 -1
  804. package/dist/xpath.js.map +1 -1
  805. package/package.json +31 -9
  806. package/src/ai/providers.ts +2 -0
  807. package/src/cache/resource.ts +24 -1
  808. package/src/canvas/effects.ts +47 -50
  809. package/src/canvas/fills.ts +19 -15
  810. package/src/canvas/images/adjustments.ts +203 -0
  811. package/src/canvas/images/sampling.ts +88 -0
  812. package/src/canvas/index.ts +1 -0
  813. package/src/canvas/masks.ts +1 -1
  814. package/src/canvas/noise/render.ts +75 -0
  815. package/src/canvas/noise/shader.ts +161 -0
  816. package/src/canvas/noise/table.ts +91 -0
  817. package/src/canvas/noise/tile.ts +94 -0
  818. package/src/canvas/overlays/auto-layout-hover.ts +47 -65
  819. package/src/canvas/overlays/index.ts +0 -1
  820. package/src/canvas/overlays/selection.ts +1 -12
  821. package/src/canvas/renderer/fonts.ts +2 -0
  822. package/src/canvas/renderer/lifecycle.ts +6 -0
  823. package/src/canvas/renderer/methods.ts +0 -9
  824. package/src/canvas/renderer/overlay-pass.ts +0 -1
  825. package/src/canvas/renderer/pipeline.ts +19 -2
  826. package/src/canvas/renderer/play-scenes.ts +51 -0
  827. package/src/canvas/renderer/tiles/cache.ts +54 -1
  828. package/src/canvas/renderer/tiles/controller.ts +30 -1
  829. package/src/canvas/renderer/types.ts +18 -3
  830. package/src/canvas/renderer.ts +40 -4
  831. package/src/canvas/scene.ts +65 -9
  832. package/src/canvas/texture.ts +136 -0
  833. package/src/clipboard.ts +23 -10
  834. package/src/constants.ts +6 -0
  835. package/src/design-jsx/index.ts +1 -1
  836. package/src/design-jsx/renderer.ts +1 -1
  837. package/src/design-memory/check.ts +376 -0
  838. package/src/design-memory/describe.ts +77 -0
  839. package/src/design-memory/distil.ts +69 -0
  840. package/src/design-memory/document.ts +80 -0
  841. package/src/design-memory/guard.ts +157 -0
  842. package/src/design-memory/index.ts +8 -0
  843. package/src/design-memory/refusal.ts +90 -0
  844. package/src/design-memory/rules.ts +274 -0
  845. package/src/design-memory/values.ts +179 -0
  846. package/src/editor/bridges/components.ts +2 -0
  847. package/src/editor/clipboard/export.ts +24 -7
  848. package/src/editor/clipboard/snapshot.ts +21 -4
  849. package/src/editor/clipboard.ts +4 -14
  850. package/src/editor/color-space.ts +47 -38
  851. package/src/editor/components/instances.ts +31 -0
  852. package/src/editor/create.ts +39 -71
  853. package/src/editor/design-memory.ts +39 -0
  854. package/src/editor/design-tokens.ts +41 -2
  855. package/src/editor/document-colors.ts +65 -0
  856. package/src/editor/eyedropper.ts +198 -0
  857. package/src/editor/fonts.ts +19 -0
  858. package/src/editor/history/atomic-tool.ts +29 -1
  859. package/src/editor/history/capture.ts +19 -0
  860. package/src/editor/history/document-change.ts +5 -17
  861. package/src/editor/history/edit.ts +16 -2
  862. package/src/editor/history/subtree.ts +13 -2
  863. package/src/editor/index.ts +11 -0
  864. package/src/editor/nudge.ts +1 -1
  865. package/src/editor/pages.ts +40 -29
  866. package/src/editor/play/states.ts +1 -1
  867. package/src/editor/read-only/actions.ts +6 -0
  868. package/src/editor/render-requests.ts +83 -0
  869. package/src/editor/selection/container.ts +24 -1
  870. package/src/editor/selection/navigation.ts +8 -6
  871. package/src/editor/selection/overlays.ts +1 -0
  872. package/src/editor/shapes/with-text.ts +2 -5
  873. package/src/editor/structure/auto-layout-wrap.ts +1 -1
  874. package/src/editor/structure/boolean.ts +1 -3
  875. package/src/editor/structure/group/bounds.ts +1 -5
  876. package/src/editor/structure/outline-stroke.ts +3 -3
  877. package/src/editor/structure/reorder.ts +8 -14
  878. package/src/editor/structure/state.ts +1 -1
  879. package/src/editor/structure.ts +5 -8
  880. package/src/editor/tool-registry.ts +2 -1
  881. package/src/editor/types.ts +8 -1
  882. package/src/editor/variables.ts +74 -2
  883. package/src/editor/variations/create.ts +235 -0
  884. package/src/editor/variations/pick.ts +35 -0
  885. package/src/editor/variations.ts +110 -0
  886. package/src/figma-api/accessors/reactions.ts +11 -1
  887. package/src/figma-api/accessors/text/index.ts +17 -1
  888. package/src/figma-api/accessors/text/opentype.ts +33 -0
  889. package/src/figma-api/accessors/visual.ts +55 -2
  890. package/src/figma-api/compatibility.ts +5 -2
  891. package/src/figma-api/effects.ts +143 -5
  892. package/src/figma-api/fonts/loaded.ts +9 -0
  893. package/src/figma-api/index.ts +35 -0
  894. package/src/figma-api/overrides.ts +295 -3
  895. package/src/figma-api/paints.ts +24 -9
  896. package/src/figma-api/proxy.ts +6 -1
  897. package/src/figma-api/reactions.ts +130 -32
  898. package/src/figma-api/serialization.ts +2 -1
  899. package/src/figma-api/shape-details.ts +50 -0
  900. package/src/figma-api/shape-with-text.ts +2 -5
  901. package/src/figma-api/surface.ts +7 -2
  902. package/src/global.d.ts +31 -0
  903. package/src/icons/svg.ts +3 -1
  904. package/src/io/formats/boolean-path.ts +60 -0
  905. package/src/io/formats/design-tokens/index.ts +21 -0
  906. package/src/io/formats/design-tokens/plan/changes.ts +4 -1
  907. package/src/io/formats/design-tokens/project.ts +40 -9
  908. package/src/io/formats/design-tokens/styles.ts +10 -2
  909. package/src/io/formats/design-tokens/sync/apply.ts +130 -0
  910. package/src/io/formats/design-tokens/sync/drift.ts +587 -0
  911. package/src/io/formats/design-tokens/sync/files.ts +40 -0
  912. package/src/io/formats/drawio/edges.ts +65 -0
  913. package/src/io/formats/drawio/export.ts +37 -14
  914. package/src/io/formats/drawio/index.ts +5 -1
  915. package/src/io/formats/fig/export/patch/index.ts +8 -0
  916. package/src/io/formats/fig/thumbnail-page.ts +4 -4
  917. package/src/io/formats/html/import.ts +9 -1
  918. package/src/io/formats/html/index.ts +14 -7
  919. package/src/io/formats/html/layers.ts +11 -2
  920. package/src/io/formats/html/vectors.ts +8 -2
  921. package/src/io/formats/pdf/document.ts +14 -4
  922. package/src/io/formats/pdf/dom.ts +10 -18
  923. package/src/io/formats/pdf/export.ts +1 -1
  924. package/src/io/formats/pen/imports.ts +5 -6
  925. package/src/io/formats/pen/index.ts +36 -5
  926. package/src/io/formats/raster/adjusted-images.ts +125 -0
  927. package/src/io/formats/raster/headless.ts +3 -3
  928. package/src/io/formats/raster/index.ts +6 -1
  929. package/src/io/formats/raster/pixels.ts +7 -0
  930. package/src/io/formats/raster/render.ts +12 -1
  931. package/src/io/formats/svg/defs.ts +14 -73
  932. package/src/io/formats/svg/effects.ts +131 -0
  933. package/src/io/formats/svg/export.ts +371 -64
  934. package/src/io/formats/svg/filter.ts +47 -0
  935. package/src/io/formats/svg/grain.ts +249 -0
  936. package/src/io/formats/svg/strokes.ts +2 -2
  937. package/src/io/formats/svg/text/layout.ts +13 -3
  938. package/src/io/formats/video/composite.ts +79 -0
  939. package/src/io/formats/video/formats.ts +77 -0
  940. package/src/io/formats/video/gif.ts +65 -0
  941. package/src/io/formats/video/index.ts +30 -0
  942. package/src/io/formats/video/plan.ts +116 -0
  943. package/src/io/formats/video/record.ts +227 -0
  944. package/src/io/formats/video/sink.ts +32 -0
  945. package/src/io/formats/video/size.ts +25 -0
  946. package/src/io/formats/video/webcodecs.ts +89 -0
  947. package/src/io/formats.ts +59 -11
  948. package/src/io/types.ts +29 -10
  949. package/src/layout/apply.ts +87 -21
  950. package/src/layout/auto-layout-handles.ts +396 -0
  951. package/src/layout/derived.ts +14 -0
  952. package/src/layout/grid.ts +33 -9
  953. package/src/layout/mutations.ts +13 -1
  954. package/src/layout/strokes.ts +12 -0
  955. package/src/layout/yoga-helpers.ts +18 -1
  956. package/src/layout.ts +96 -49
  957. package/src/lint/fixes.ts +12 -3
  958. package/src/lint/index.ts +3 -1
  959. package/src/lint/linter.ts +124 -12
  960. package/src/lint/presets.ts +2 -0
  961. package/src/lint/rules/design-memory.ts +97 -0
  962. package/src/lint/rules/effect-style-required.ts +2 -0
  963. package/src/lint/rules/index.ts +6 -1
  964. package/src/lint/rules/no-unbound-token-values.ts +73 -0
  965. package/src/lint/rules/text-style-required.ts +2 -0
  966. package/src/lint/types.ts +40 -0
  967. package/src/node/video.ts +196 -0
  968. package/src/pairdraw-api/design-memory.ts +61 -0
  969. package/src/pairdraw-api/index.ts +81 -0
  970. package/src/pairdraw-api/nodes.ts +38 -0
  971. package/src/pairdraw-api/variations.ts +109 -0
  972. package/src/prototype/easing.ts +37 -0
  973. package/src/prototype/frames.ts +9 -0
  974. package/src/prototype/hit.ts +70 -0
  975. package/src/prototype/index.ts +69 -0
  976. package/src/prototype/pointer.ts +146 -0
  977. package/src/prototype/reactions.ts +178 -0
  978. package/src/prototype/scene.ts +116 -0
  979. package/src/prototype/scenes.ts +256 -0
  980. package/src/prototype/scroll.ts +190 -0
  981. package/src/prototype/session.ts +188 -0
  982. package/src/prototype/smart-animate/animation.ts +267 -0
  983. package/src/prototype/smart-animate/match.ts +85 -0
  984. package/src/prototype/snapshot.ts +60 -0
  985. package/src/prototype/timeline.ts +400 -0
  986. package/src/rpc/index.ts +1 -0
  987. package/src/rpc/read-commands.ts +40 -23
  988. package/src/text/font/faces.ts +22 -0
  989. package/src/text/font/features.ts +27 -0
  990. package/src/text/font/manager.ts +88 -12
  991. package/src/text/index.ts +2 -0
  992. package/src/text/replace-fonts.ts +171 -0
  993. package/src/tools/analyze/responsive/index.ts +264 -0
  994. package/src/tools/analyze.ts +2 -0
  995. package/src/tools/codegen/token-sync.ts +98 -0
  996. package/src/tools/codegen.ts +1 -0
  997. package/src/tools/create/components.ts +4 -0
  998. package/src/tools/create/html.ts +1 -0
  999. package/src/tools/create/icons.ts +1 -0
  1000. package/src/tools/create/mermaid.ts +1 -0
  1001. package/src/tools/create/svg.ts +1 -0
  1002. package/src/tools/design-memory.ts +72 -0
  1003. package/src/tools/image-ai/generate.ts +2 -0
  1004. package/src/tools/index.ts +1 -0
  1005. package/src/tools/modify/fonts.ts +34 -0
  1006. package/src/tools/modify/layout.ts +5 -0
  1007. package/src/tools/modify/reactions.ts +15 -8
  1008. package/src/tools/modify/text.ts +42 -5
  1009. package/src/tools/modify/update.ts +46 -2
  1010. package/src/tools/modify.ts +1 -0
  1011. package/src/tools/read/fonts.ts +24 -2
  1012. package/src/tools/read/libraries.ts +1 -0
  1013. package/src/tools/read/nodes.ts +0 -1
  1014. package/src/tools/read/space.ts +3 -2
  1015. package/src/tools/registry/core.ts +3 -1
  1016. package/src/tools/registry/extended.ts +28 -1
  1017. package/src/tools/schema.ts +28 -4
  1018. package/src/tools/stock-photo.ts +1 -0
  1019. package/src/tools/structure/basic.ts +1 -0
  1020. package/src/tools/structure/batch.ts +34 -1
  1021. package/src/tools/structure/hierarchy.ts +4 -0
  1022. package/src/tools/structure/variations.ts +118 -0
  1023. package/src/tools/structure.ts +2 -0
  1024. package/src/tools/styles/types.ts +3 -4
  1025. package/src/tools/vector/boolean.ts +4 -0
  1026. package/src/tools/vector/path.ts +30 -6
  1027. package/src/tools/vector/vectorize.ts +1 -0
  1028. package/src/tools/vector/video.ts +228 -0
  1029. package/src/tools/vector.ts +1 -0
  1030. package/src/tools/video-host.ts +18 -0
  1031. package/src/xpath.ts +6 -1
@@ -1 +1 @@
1
- {"version":3,"file":"thumbnail-page.js","names":[],"sources":["../../../../src/io/formats/fig/thumbnail-page.ts"],"sourcesContent":["type ThumbnailPage = {\n id: string\n name: string\n}\n\nconst COVER_PAGE_NAME = 'cover'\n\n/**\n * The page a `.fig` thumbnail shows: the conventional Cover page, or the first page when there is\n * none, as Figma's own thumbnail does.\n */\nexport function figThumbnailPageId(pages: readonly ThumbnailPage[]): string | undefined {\n const normalizedNames = pages.map((page) => ({\n page,\n name: page.name.trim().toLocaleLowerCase()\n }))\n return (\n normalizedNames.find(({ name }) => name === COVER_PAGE_NAME)?.page.id ??\n normalizedNames.find(({ name }) => name.includes(COVER_PAGE_NAME))?.page.id ??\n pages.at(0)?.id\n )\n}\n"],"mappings":";AAKA,MAAM,kBAAkB;;;;;AAMxB,SAAgB,mBAAmB,OAAqD;CACtF,MAAM,kBAAkB,MAAM,KAAK,UAAU;EAC3C;EACA,MAAM,KAAK,KAAK,KAAK,CAAC,CAAC,kBAAkB;CAC3C,EAAE;CACF,OACE,gBAAgB,MAAM,EAAE,WAAW,SAAS,eAAe,CAAC,EAAE,KAAK,MACnE,gBAAgB,MAAM,EAAE,WAAW,KAAK,SAAS,eAAe,CAAC,CAAC,EAAE,KAAK,MACzE,MAAM,GAAG,CAAC,CAAC,EAAE;AAEjB"}
1
+ {"version":3,"file":"thumbnail-page.js","names":[],"sources":["../../../../src/io/formats/fig/thumbnail-page.ts"],"sourcesContent":["import type { SceneNode } from '@pairdraw/scene-graph'\n\n/** The fields of a page the thumbnail choice reads. */\ntype ThumbnailPage = Pick<SceneNode, 'id' | 'name'>\n\nconst COVER_PAGE_NAME = 'cover'\n\n/**\n * The page a `.fig` thumbnail shows: the conventional Cover page, or the first page when there is\n * none, as Figma's own thumbnail does.\n */\nexport function figThumbnailPageId(pages: readonly ThumbnailPage[]): string | undefined {\n const normalizedNames = pages.map((page) => ({\n page,\n name: page.name.trim().toLocaleLowerCase()\n }))\n return (\n normalizedNames.find(({ name }) => name === COVER_PAGE_NAME)?.page.id ??\n normalizedNames.find(({ name }) => name.includes(COVER_PAGE_NAME))?.page.id ??\n pages.at(0)?.id\n )\n}\n"],"mappings":";AAKA,MAAM,kBAAkB;;;;;AAMxB,SAAgB,mBAAmB,OAAqD;CACtF,MAAM,kBAAkB,MAAM,KAAK,UAAU;EAC3C;EACA,MAAM,KAAK,KAAK,KAAK,CAAC,CAAC,kBAAkB;CAC3C,EAAE;CACF,OACE,gBAAgB,MAAM,EAAE,WAAW,SAAS,eAAe,CAAC,EAAE,KAAK,MACnE,gBAAgB,MAAM,EAAE,WAAW,KAAK,SAAS,eAAe,CAAC,CAAC,EAAE,KAAK,MACzE,MAAM,GAAG,CAAC,CAAC,EAAE;AAEjB"}
@@ -1 +1 @@
1
- {"version":3,"file":"import.d.ts","names":[],"sources":["../../../../src/io/formats/html/import.ts"],"mappings":";;;;;UAYiB;;EAEf;;EAEA;EACA;;UAGe;;EAEf,QAAQ;EACR,OAAO;;;;;;iBAOa,iBACpB,cACA,UAAS,kBACR,QAAQ;;cASE,oBAAoB;;cAQpB,oBAAoB"}
1
+ {"version":3,"file":"import.d.ts","names":[],"sources":["../../../../src/io/formats/html/import.ts"],"mappings":";;;;;UAYiB;;EAEf;;EAEA;EACA;;UAGe;;EAEf,QAAQ;EACR,OAAO;;;;;;iBAOa,iBACpB,cACA,UAAS,kBACR,QAAQ;;cAiBE,oBAAoB;;cAQpB,oBAAoB"}
@@ -14,9 +14,11 @@ async function readHTMLDocument(html, options = {}) {
14
14
  cssText: options.cssText,
15
15
  runtime
16
16
  });
17
+ const graph = sceneGraphFromStyledHTML(styled, { pageName: options.pageName });
18
+ if (graph.getPages().every((page) => page.childIds.length === 0)) throw new Error("No layers found in this HTML document; check that it is HTML with visible content.");
17
19
  return {
18
20
  styled,
19
- graph: sceneGraphFromStyledHTML(styled, { pageName: options.pageName })
21
+ graph
20
22
  };
21
23
  }
22
24
  /** Styles HTML for `import_html` with the headless CSS runtime, where Node runs the tools. */
@@ -1 +1 @@
1
- {"version":3,"file":"import.js","names":[],"sources":["../../../../src/io/formats/html/import.ts"],"sourcesContent":["import {\n createHeadlessCSSRuntime,\n htmlToDesignDocument,\n tailwindHTMLToDesignDocument,\n type DesignDocument\n} from '@pairdraw/dom-css'\nimport type { SceneGraph } from '@pairdraw/scene-graph'\n\nimport type { IOFormatAdapter } from '#core/io/types'\n\nimport { htmlClassNames, sceneGraphFromStyledHTML, type HTMLStyler } from './layers'\n\nexport interface ReadHTMLOptions {\n /** A stylesheet applied after the document's own `<style>` blocks. */\n cssText?: string\n /** Tailwind utility candidates compiled into the stylesheet, as the page's classes use. */\n tailwind?: readonly string[]\n pageName?: string\n}\n\nexport interface ReadHTMLResult {\n /** The styled DOM the layers were built from. */\n styled: DesignDocument\n graph: SceneGraph\n}\n\n/**\n * HTML and CSS as a laid-out document, styled by the headless CSS runtime. The runtime needs\n * Node, so browser builds style with the browser runtime and call `sceneGraphFromStyledHTML`.\n */\nexport async function readHTMLDocument(\n html: string,\n options: ReadHTMLOptions = {}\n): Promise<ReadHTMLResult> {\n const runtime = createHeadlessCSSRuntime()\n const styled = options.tailwind\n ? await tailwindHTMLToDesignDocument(html, options.tailwind, { css: options.cssText, runtime })\n : await htmlToDesignDocument(html, { cssText: options.cssText, runtime })\n return { styled, graph: sceneGraphFromStyledHTML(styled, { pageName: options.pageName }) }\n}\n\n/** Styles HTML for `import_html` with the headless CSS runtime, where Node runs the tools. */\nexport const headlessHTMLStyler: HTMLStyler = (html, { cssText, tailwind }) => {\n const runtime = createHeadlessCSSRuntime()\n return tailwind\n ? tailwindHTMLToDesignDocument(html, htmlClassNames(html), { css: cssText, runtime })\n : htmlToDesignDocument(html, { cssText, runtime })\n}\n\n/** Reads HTML files where the headless CSS runtime is available, as in the CLI. */\nexport const headlessHTMLReader: IOFormatAdapter<'html'> = {\n id: 'html',\n label: 'HTML',\n role: 'interchange-document',\n category: 'document',\n extensions: ['html', 'htm'],\n mimeTypes: ['text/html'],\n support: { readDocument: true },\n async readDocument(input) {\n const { graph } = await readHTMLDocument(new TextDecoder().decode(input.data))\n return { graph, sourceFormat: 'html' }\n }\n}\n"],"mappings":";;;;;;;AA8BA,eAAsB,iBACpB,MACA,UAA2B,CAAC,GACH;CACzB,MAAM,UAAU,yBAAyB;CACzC,MAAM,SAAS,QAAQ,WACnB,MAAM,6BAA6B,MAAM,QAAQ,UAAU;EAAE,KAAK,QAAQ;EAAS;CAAQ,CAAC,IAC5F,MAAM,qBAAqB,MAAM;EAAE,SAAS,QAAQ;EAAS;CAAQ,CAAC;CAC1E,OAAO;EAAE;EAAQ,OAAO,yBAAyB,QAAQ,EAAE,UAAU,QAAQ,SAAS,CAAC;CAAE;AAC3F;;AAGA,MAAa,sBAAkC,MAAM,EAAE,SAAS,eAAe;CAC7E,MAAM,UAAU,yBAAyB;CACzC,OAAO,WACH,6BAA6B,MAAM,eAAe,IAAI,GAAG;EAAE,KAAK;EAAS;CAAQ,CAAC,IAClF,qBAAqB,MAAM;EAAE;EAAS;CAAQ,CAAC;AACrD;;AAGA,MAAa,qBAA8C;CACzD,IAAI;CACJ,OAAO;CACP,MAAM;CACN,UAAU;CACV,YAAY,CAAC,QAAQ,KAAK;CAC1B,WAAW,CAAC,WAAW;CACvB,SAAS,EAAE,cAAc,KAAK;CAC9B,MAAM,aAAa,OAAO;EACxB,MAAM,EAAE,UAAU,MAAM,iBAAiB,IAAI,YAAY,CAAC,CAAC,OAAO,MAAM,IAAI,CAAC;EAC7E,OAAO;GAAE;GAAO,cAAc;EAAO;CACvC;AACF"}
1
+ {"version":3,"file":"import.js","names":[],"sources":["../../../../src/io/formats/html/import.ts"],"sourcesContent":["import {\n createHeadlessCSSRuntime,\n htmlToDesignDocument,\n tailwindHTMLToDesignDocument,\n type DesignDocument\n} from '@pairdraw/dom-css'\nimport type { SceneGraph } from '@pairdraw/scene-graph'\n\nimport type { IOFormatAdapter } from '#core/io/types'\n\nimport { htmlClassNames, sceneGraphFromStyledHTML, type HTMLStyler } from './layers'\n\nexport interface ReadHTMLOptions {\n /** A stylesheet applied after the document's own `<style>` blocks. */\n cssText?: string\n /** Tailwind utility candidates compiled into the stylesheet, as the page's classes use. */\n tailwind?: readonly string[]\n pageName?: string\n}\n\nexport interface ReadHTMLResult {\n /** The styled DOM the layers were built from. */\n styled: DesignDocument\n graph: SceneGraph\n}\n\n/**\n * HTML and CSS as a laid-out document, styled by the headless CSS runtime. The runtime needs\n * Node, so browser builds style with the browser runtime and call `sceneGraphFromStyledHTML`.\n */\nexport async function readHTMLDocument(\n html: string,\n options: ReadHTMLOptions = {}\n): Promise<ReadHTMLResult> {\n const runtime = createHeadlessCSSRuntime()\n const styled = options.tailwind\n ? await tailwindHTMLToDesignDocument(html, options.tailwind, { css: options.cssText, runtime })\n : await htmlToDesignDocument(html, { cssText: options.cssText, runtime })\n const graph = sceneGraphFromStyledHTML(styled, { pageName: options.pageName })\n // An empty page or markup a parser could not read would otherwise open as an empty document\n // with nothing to tell the user; every caller reports a thrown error.\n if (graph.getPages().every((page) => page.childIds.length === 0)) {\n throw new Error(\n 'No layers found in this HTML document; check that it is HTML with visible content.'\n )\n }\n return { styled, graph }\n}\n\n/** Styles HTML for `import_html` with the headless CSS runtime, where Node runs the tools. */\nexport const headlessHTMLStyler: HTMLStyler = (html, { cssText, tailwind }) => {\n const runtime = createHeadlessCSSRuntime()\n return tailwind\n ? tailwindHTMLToDesignDocument(html, htmlClassNames(html), { css: cssText, runtime })\n : htmlToDesignDocument(html, { cssText, runtime })\n}\n\n/** Reads HTML files where the headless CSS runtime is available, as in the CLI. */\nexport const headlessHTMLReader: IOFormatAdapter<'html'> = {\n id: 'html',\n label: 'HTML',\n role: 'interchange-document',\n category: 'document',\n extensions: ['html', 'htm'],\n mimeTypes: ['text/html'],\n support: { readDocument: true },\n async readDocument(input) {\n const { graph } = await readHTMLDocument(new TextDecoder().decode(input.data))\n return { graph, sourceFormat: 'html' }\n }\n}\n"],"mappings":";;;;;;;AA8BA,eAAsB,iBACpB,MACA,UAA2B,CAAC,GACH;CACzB,MAAM,UAAU,yBAAyB;CACzC,MAAM,SAAS,QAAQ,WACnB,MAAM,6BAA6B,MAAM,QAAQ,UAAU;EAAE,KAAK,QAAQ;EAAS;CAAQ,CAAC,IAC5F,MAAM,qBAAqB,MAAM;EAAE,SAAS,QAAQ;EAAS;CAAQ,CAAC;CAC1E,MAAM,QAAQ,yBAAyB,QAAQ,EAAE,UAAU,QAAQ,SAAS,CAAC;CAG7E,IAAI,MAAM,SAAS,CAAC,CAAC,OAAO,SAAS,KAAK,SAAS,WAAW,CAAC,GAC7D,MAAM,IAAI,MACR,oFACF;CAEF,OAAO;EAAE;EAAQ;CAAM;AACzB;;AAGA,MAAa,sBAAkC,MAAM,EAAE,SAAS,eAAe;CAC7E,MAAM,UAAU,yBAAyB;CACzC,OAAO,WACH,6BAA6B,MAAM,eAAe,IAAI,GAAG;EAAE,KAAK;EAAS;CAAQ,CAAC,IAClF,qBAAqB,MAAM;EAAE;EAAS;CAAQ,CAAC;AACrD;;AAGA,MAAa,qBAA8C;CACzD,IAAI;CACJ,OAAO;CACP,MAAM;CACN,UAAU;CACV,YAAY,CAAC,QAAQ,KAAK;CAC1B,WAAW,CAAC,WAAW;CACvB,SAAS,EAAE,cAAc,KAAK;CAC9B,MAAM,aAAa,OAAO;EACxB,MAAM,EAAE,UAAU,MAAM,iBAAiB,IAAI,YAAY,CAAC,CAAC,OAAO,MAAM,IAAI,CAAC;EAC7E,OAAO;GAAE;GAAO,cAAc;EAAO;CACvC;AACF"}
@@ -1,7 +1,7 @@
1
- import { ExportAsset, HTMLExportOptions } from "../../types.js";
1
+ import { ExportAsset, HTMLExportOptions, IOContext } from "../../types.js";
2
2
  import { SceneGraph } from "@pairdraw/scene-graph";
3
3
  //#region src/io/formats/html/index.d.ts
4
- declare function renderNodesToHTML(graph: SceneGraph, nodeIds: string[], options?: HTMLExportOptions, fileName?: string): Promise<{
4
+ declare function renderNodesToHTML(graph: SceneGraph, nodeIds: string[], options?: HTMLExportOptions, fileName?: string, context?: IOContext): Promise<{
5
5
  html: string;
6
6
  assets: ExportAsset[];
7
7
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/io/formats/html/index.ts"],"mappings":";;;iBAkCsB,kBACpB,OAAO,YACP,mBACA,UAAS,mBACT,oBACC;EAAU;EAAc,QAAQ"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/io/formats/html/index.ts"],"mappings":";;;iBAwCsB,kBACpB,OAAO,YACP,mBACA,UAAS,mBACT,mBACA,UAAU,YACT;EAAU;EAAc,QAAQ"}
@@ -3,9 +3,11 @@ import { exportWebFontFaceAssets } from "../../../text/web-font/assets.js";
3
3
  import { filename } from "pathe/utils";
4
4
  import { exportHTMLBundle, sceneNodesToDesignDocument } from "@pairdraw/dom-css/export";
5
5
  //#region src/io/formats/html/index.ts
6
- function designDocument(graph, nodeIds, options) {
6
+ async function designDocument(graph, nodeIds, options, context) {
7
+ const { booleanPathResolver, needsBooleanPaths } = await import("../boolean-path.js");
8
+ const booleanPath = needsBooleanPaths(graph) ? await booleanPathResolver(context?.canvasKit, context?.renderer) : void 0;
7
9
  const projection = {
8
- vectorElement,
10
+ vectorElement: (vectorGraph, node) => vectorElement(vectorGraph, node, booleanPath),
9
11
  includeLayerNames: options.layerNames ?? true,
10
12
  includeSourceIds: options.layerIds ?? false
11
13
  };
@@ -15,8 +17,8 @@ function designDocument(graph, nodeIds, options) {
15
17
  function assetBasePath(fileName) {
16
18
  return `${fileName && filename(fileName) || "export"}.assets`;
17
19
  }
18
- async function renderNodesToHTML(graph, nodeIds, options = {}, fileName) {
19
- const bundle = await exportHTMLBundle(designDocument(graph, nodeIds, options), {
20
+ async function renderNodesToHTML(graph, nodeIds, options = {}, fileName, context) {
21
+ const bundle = await exportHTMLBundle(await designDocument(graph, nodeIds, options, context), {
20
22
  html: options.html,
21
23
  style: options.style,
22
24
  assets: options.assets,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../src/io/formats/html/index.ts"],"sourcesContent":["import { filename } from 'pathe/utils'\n\nimport {\n exportHTMLBundle,\n sceneNodesToDesignDocument,\n type DesignDocument\n} from '@pairdraw/dom-css/export'\nimport type { SceneGraph } from '@pairdraw/scene-graph'\n\nimport type { ExportAsset, HTMLExportOptions } from '#core/io/types'\nimport { exportWebFontFaceAssets } from '#core/text/web-font/assets'\n\nimport { vectorElement } from './vectors'\n\nfunction designDocument(\n graph: SceneGraph,\n nodeIds: string[],\n options: HTMLExportOptions\n): DesignDocument {\n // Layer names help find a layer in the markup; IDs only matter to tools that link back.\n const projection = {\n vectorElement,\n includeLayerNames: options.layerNames ?? true,\n includeSourceIds: options.layerIds ?? false\n }\n return sceneNodesToDesignDocument(graph, nodeIds, projection)\n}\n\n/** `card.html` keeps its external files in `card.assets/` next to it, whatever the path style. */\nfunction assetBasePath(fileName: string | undefined): string {\n const name = fileName && filename(fileName)\n return `${name || 'export'}.assets`\n}\n\nexport async function renderNodesToHTML(\n graph: SceneGraph,\n nodeIds: string[],\n options: HTMLExportOptions = {},\n fileName?: string\n): Promise<{ html: string; assets: ExportAsset[] }> {\n const bundle = await exportHTMLBundle(designDocument(graph, nodeIds, options), {\n html: options.html,\n style: options.style,\n assets: options.assets,\n fonts:\n options.fonts === 'assets'\n ? async (fonts, basePath) =>\n (await exportWebFontFaceAssets({ fonts, assetBasePath: basePath })).assets\n : 'none',\n assetBasePath: assetBasePath(fileName),\n loadTailwindStylesheet: options.loadTailwindStylesheet\n })\n const page = bundle.files.find((file) => file.path === bundle.entrypoint)\n if (typeof page?.content !== 'string') throw new Error('HTML export produced no page')\n return { html: page.content, assets: bundle.files.filter((file) => file !== page) }\n}\n"],"mappings":";;;;;AAcA,SAAS,eACP,OACA,SACA,SACgB;CAEhB,MAAM,aAAa;EACjB;EACA,mBAAmB,QAAQ,cAAc;EACzC,kBAAkB,QAAQ,YAAY;CACxC;CACA,OAAO,2BAA2B,OAAO,SAAS,UAAU;AAC9D;;AAGA,SAAS,cAAc,UAAsC;CAE3D,OAAO,GADM,YAAY,SAAS,QAAQ,KACxB,SAAS;AAC7B;AAEA,eAAsB,kBACpB,OACA,SACA,UAA6B,CAAC,GAC9B,UACkD;CAClD,MAAM,SAAS,MAAM,iBAAiB,eAAe,OAAO,SAAS,OAAO,GAAG;EAC7E,MAAM,QAAQ;EACd,OAAO,QAAQ;EACf,QAAQ,QAAQ;EAChB,OACE,QAAQ,UAAU,WACd,OAAO,OAAO,cACX,MAAM,wBAAwB;GAAE;GAAO,eAAe;EAAS,CAAC,EAAA,CAAG,SACtE;EACN,eAAe,cAAc,QAAQ;EACrC,wBAAwB,QAAQ;CAClC,CAAC;CACD,MAAM,OAAO,OAAO,MAAM,MAAM,SAAS,KAAK,SAAS,OAAO,UAAU;CACxE,IAAI,OAAO,MAAM,YAAY,UAAU,MAAM,IAAI,MAAM,8BAA8B;CACrF,OAAO;EAAE,MAAM,KAAK;EAAS,QAAQ,OAAO,MAAM,QAAQ,SAAS,SAAS,IAAI;CAAE;AACpF"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../src/io/formats/html/index.ts"],"sourcesContent":["import { filename } from 'pathe/utils'\n\nimport {\n exportHTMLBundle,\n sceneNodesToDesignDocument,\n type DesignDocument\n} from '@pairdraw/dom-css/export'\nimport type { SceneGraph } from '@pairdraw/scene-graph'\n\nimport type { ExportAsset, HTMLExportOptions, IOContext } from '#core/io/types'\nimport { exportWebFontFaceAssets } from '#core/text/web-font/assets'\n\nimport { vectorElement } from './vectors'\n\nasync function designDocument(\n graph: SceneGraph,\n nodeIds: string[],\n options: HTMLExportOptions,\n context?: IOContext\n): Promise<DesignDocument> {\n const { booleanPathResolver, needsBooleanPaths } = await import('#core/io/formats/boolean-path')\n const booleanPath = needsBooleanPaths(graph)\n ? await booleanPathResolver(context?.canvasKit, context?.renderer)\n : undefined\n // Layer names help find a layer in the markup; IDs only matter to tools that link back.\n const projection = {\n vectorElement: (vectorGraph: SceneGraph, node: Parameters<typeof vectorElement>[1]) =>\n vectorElement(vectorGraph, node, booleanPath),\n includeLayerNames: options.layerNames ?? true,\n includeSourceIds: options.layerIds ?? false\n }\n return sceneNodesToDesignDocument(graph, nodeIds, projection)\n}\n\n/** `card.html` keeps its external files in `card.assets/` next to it, whatever the path style. */\nfunction assetBasePath(fileName: string | undefined): string {\n const name = fileName && filename(fileName)\n return `${name || 'export'}.assets`\n}\n\nexport async function renderNodesToHTML(\n graph: SceneGraph,\n nodeIds: string[],\n options: HTMLExportOptions = {},\n fileName?: string,\n context?: IOContext\n): Promise<{ html: string; assets: ExportAsset[] }> {\n const bundle = await exportHTMLBundle(await designDocument(graph, nodeIds, options, context), {\n html: options.html,\n style: options.style,\n assets: options.assets,\n fonts:\n options.fonts === 'assets'\n ? async (fonts, basePath) =>\n (await exportWebFontFaceAssets({ fonts, assetBasePath: basePath })).assets\n : 'none',\n assetBasePath: assetBasePath(fileName),\n loadTailwindStylesheet: options.loadTailwindStylesheet\n })\n const page = bundle.files.find((file) => file.path === bundle.entrypoint)\n if (typeof page?.content !== 'string') throw new Error('HTML export produced no page')\n return { html: page.content, assets: bundle.files.filter((file) => file !== page) }\n}\n"],"mappings":";;;;;AAcA,eAAe,eACb,OACA,SACA,SACA,SACyB;CACzB,MAAM,EAAE,qBAAqB,sBAAsB,MAAM,OAAO;CAChE,MAAM,cAAc,kBAAkB,KAAK,IACvC,MAAM,oBAAoB,SAAS,WAAW,SAAS,QAAQ,IAC/D,KAAA;CAEJ,MAAM,aAAa;EACjB,gBAAgB,aAAyB,SACvC,cAAc,aAAa,MAAM,WAAW;EAC9C,mBAAmB,QAAQ,cAAc;EACzC,kBAAkB,QAAQ,YAAY;CACxC;CACA,OAAO,2BAA2B,OAAO,SAAS,UAAU;AAC9D;;AAGA,SAAS,cAAc,UAAsC;CAE3D,OAAO,GADM,YAAY,SAAS,QAAQ,KACxB,SAAS;AAC7B;AAEA,eAAsB,kBACpB,OACA,SACA,UAA6B,CAAC,GAC9B,UACA,SACkD;CAClD,MAAM,SAAS,MAAM,iBAAiB,MAAM,eAAe,OAAO,SAAS,SAAS,OAAO,GAAG;EAC5F,MAAM,QAAQ;EACd,OAAO,QAAQ;EACf,QAAQ,QAAQ;EAChB,OACE,QAAQ,UAAU,WACd,OAAO,OAAO,cACX,MAAM,wBAAwB;GAAE;GAAO,eAAe;EAAS,CAAC,EAAA,CAAG,SACtE;EACN,eAAe,cAAc,QAAQ;EACrC,wBAAwB,QAAQ;CAClC,CAAC;CACD,MAAM,OAAO,OAAO,MAAM,MAAM,SAAS,KAAK,SAAS,OAAO,UAAU;CACxE,IAAI,OAAO,MAAM,YAAY,UAAU,MAAM,IAAI,MAAM,8BAA8B;CACrF,OAAO;EAAE,MAAM,KAAK;EAAS,QAAQ,OAAO,MAAM,QAAQ,SAAS,SAAS,IAAI;CAAE;AACpF"}
@@ -7,6 +7,11 @@ interface StyleHTMLOptions {
7
7
  /** Compile the Tailwind utilities the markup's classes name into the stylesheet. */
8
8
  tailwind?: boolean;
9
9
  }
10
+ interface SceneGraphFromStyledHTMLOptions {
11
+ pageName?: string;
12
+ /** The family a CSS stack should draw; null keeps its first family. See the dom-css option. */
13
+ resolveFontFamily?: (value: string) => string | null;
14
+ }
10
15
  /**
11
16
  * Styles HTML with the CSS runtime a host has: the browser's in the app, the headless runtime
12
17
  * in the CLI. Hosts hand it to tools, which build the layers with `sceneGraphFromStyledHTML`.
@@ -22,9 +27,7 @@ declare function htmlClassNames(html: string): string[];
22
27
  * belongs to whoever has a CSS runtime, such as a browser or the headless runtime; building and
23
28
  * laying out the layers happens here for every caller. Safe to bundle for the browser.
24
29
  */
25
- declare function sceneGraphFromStyledHTML(styled: DesignDocument, options?: {
26
- pageName?: string;
27
- }): SceneGraph;
30
+ declare function sceneGraphFromStyledHTML(styled: DesignDocument, options?: SceneGraphFromStyledHTMLOptions): SceneGraph;
28
31
  //#endregion
29
- export { HTMLStyler, StyleHTMLOptions, htmlClassNames, sceneGraphFromStyledHTML };
32
+ export { HTMLStyler, SceneGraphFromStyledHTMLOptions, StyleHTMLOptions, htmlClassNames, sceneGraphFromStyledHTML };
30
33
  //# sourceMappingURL=layers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"layers.d.ts","names":[],"sources":["../../../../src/io/formats/html/layers.ts"],"mappings":";;;UAMiB;;EAEf;;EAEA;;;;;;KAOU,cAAc,cAAc,SAAS,qBAAqB,QAAQ;;;;;iBAY9D,eAAe;;;;;;iBAef,yBACd,QAAQ,gBACR;EAAW;IACV"}
1
+ {"version":3,"file":"layers.d.ts","names":[],"sources":["../../../../src/io/formats/html/layers.ts"],"mappings":";;;UAMiB;;EAEf;;EAEA;;UAGe;EACf;;EAEA,qBAAqB;;;;;;KAOX,cAAc,cAAc,SAAS,qBAAqB,QAAQ;;;;;iBAY9D,eAAe;;;;;;iBAef,yBACd,QAAQ,gBACR,UAAS,kCACR"}
@@ -24,7 +24,10 @@ function htmlClassNames(html) {
24
24
  * laying out the layers happens here for every caller. Safe to bundle for the browser.
25
25
  */
26
26
  function sceneGraphFromStyledHTML(styled, options = {}) {
27
- const graph = designDocumentToSceneGraph(styled, { pageName: options.pageName });
27
+ const graph = designDocumentToSceneGraph(styled, {
28
+ pageName: options.pageName,
29
+ resolveFontFamily: options.resolveFontFamily
30
+ });
28
31
  layoutAuthoredNodes(graph, graph.getPages().map((page) => page.id));
29
32
  return graph;
30
33
  }
@@ -1 +1 @@
1
- {"version":3,"file":"layers.js","names":[],"sources":["../../../../src/io/formats/html/layers.ts"],"sourcesContent":["import type { DesignDocument } from '@pairdraw/dom-css'\nimport { designDocumentToSceneGraph } from '@pairdraw/dom-css/scene-graph'\nimport type { SceneGraph } from '@pairdraw/scene-graph'\n\nimport { layoutAuthoredNodes } from '#core/layout'\n\nexport interface StyleHTMLOptions {\n /** A stylesheet applied after the document's own `<style>` blocks. */\n cssText?: string\n /** Compile the Tailwind utilities the markup's classes name into the stylesheet. */\n tailwind?: boolean\n}\n\n/**\n * Styles HTML with the CSS runtime a host has: the browser's in the app, the headless runtime\n * in the CLI. Hosts hand it to tools, which build the layers with `sceneGraphFromStyledHTML`.\n */\nexport type HTMLStyler = (html: string, options: StyleHTMLOptions) => Promise<DesignDocument>\n\n/**\n * A `class` or JSX `className` attribute with a double-quoted, single-quoted, or unquoted value.\n * The name must follow whitespace, so `data-class` and similar attributes do not count.\n */\nconst CLASS_ATTRIBUTE = /(?:^|\\s)class(?:Name)?\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)'|([^\\s\"'=<>`]+))/g\n\n/**\n * The class names `class` attributes in `html` use, as Tailwind candidates, for hosts without a\n * DOM parser; a browser reads them from each element's `classList` instead.\n */\nexport function htmlClassNames(html: string): string[] {\n const names = new Set<string>()\n for (const match of html.matchAll(CLASS_ATTRIBUTE)) {\n // Only one alternative matches; `join` reads the others, which are undefined, as empty.\n const value = match.slice(1).join('')\n for (const name of value.split(/\\s+/)) if (name) names.add(name)\n }\n return [...names]\n}\n\n/**\n * The layers a styled DOM describes, with the sizes and positions its layout implies. Styling\n * belongs to whoever has a CSS runtime, such as a browser or the headless runtime; building and\n * laying out the layers happens here for every caller. Safe to bundle for the browser.\n */\nexport function sceneGraphFromStyledHTML(\n styled: DesignDocument,\n options: { pageName?: string } = {}\n): SceneGraph {\n const graph = designDocumentToSceneGraph(styled, { pageName: options.pageName })\n layoutAuthoredNodes(\n graph,\n graph.getPages().map((page) => page.id)\n )\n return graph\n}\n"],"mappings":";;;;;;;AAuBA,MAAM,kBAAkB;;;;;AAMxB,SAAgB,eAAe,MAAwB;CACrD,MAAM,wBAAQ,IAAI,IAAY;CAC9B,KAAK,MAAM,SAAS,KAAK,SAAS,eAAe,GAAG;EAElD,MAAM,QAAQ,MAAM,MAAM,CAAC,CAAC,CAAC,KAAK,EAAE;EACpC,KAAK,MAAM,QAAQ,MAAM,MAAM,KAAK,GAAG,IAAI,MAAM,MAAM,IAAI,IAAI;CACjE;CACA,OAAO,CAAC,GAAG,KAAK;AAClB;;;;;;AAOA,SAAgB,yBACd,QACA,UAAiC,CAAC,GACtB;CACZ,MAAM,QAAQ,2BAA2B,QAAQ,EAAE,UAAU,QAAQ,SAAS,CAAC;CAC/E,oBACE,OACA,MAAM,SAAS,CAAC,CAAC,KAAK,SAAS,KAAK,EAAE,CACxC;CACA,OAAO;AACT"}
1
+ {"version":3,"file":"layers.js","names":[],"sources":["../../../../src/io/formats/html/layers.ts"],"sourcesContent":["import type { DesignDocument } from '@pairdraw/dom-css'\nimport { designDocumentToSceneGraph } from '@pairdraw/dom-css/scene-graph'\nimport type { SceneGraph } from '@pairdraw/scene-graph'\n\nimport { layoutAuthoredNodes } from '#core/layout'\n\nexport interface StyleHTMLOptions {\n /** A stylesheet applied after the document's own `<style>` blocks. */\n cssText?: string\n /** Compile the Tailwind utilities the markup's classes name into the stylesheet. */\n tailwind?: boolean\n}\n\nexport interface SceneGraphFromStyledHTMLOptions {\n pageName?: string\n /** The family a CSS stack should draw; null keeps its first family. See the dom-css option. */\n resolveFontFamily?: (value: string) => string | null\n}\n\n/**\n * Styles HTML with the CSS runtime a host has: the browser's in the app, the headless runtime\n * in the CLI. Hosts hand it to tools, which build the layers with `sceneGraphFromStyledHTML`.\n */\nexport type HTMLStyler = (html: string, options: StyleHTMLOptions) => Promise<DesignDocument>\n\n/**\n * A `class` or JSX `className` attribute with a double-quoted, single-quoted, or unquoted value.\n * The name must follow whitespace, so `data-class` and similar attributes do not count.\n */\nconst CLASS_ATTRIBUTE = /(?:^|\\s)class(?:Name)?\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)'|([^\\s\"'=<>`]+))/g\n\n/**\n * The class names `class` attributes in `html` use, as Tailwind candidates, for hosts without a\n * DOM parser; a browser reads them from each element's `classList` instead.\n */\nexport function htmlClassNames(html: string): string[] {\n const names = new Set<string>()\n for (const match of html.matchAll(CLASS_ATTRIBUTE)) {\n // Only one alternative matches; `join` reads the others, which are undefined, as empty.\n const value = match.slice(1).join('')\n for (const name of value.split(/\\s+/)) if (name) names.add(name)\n }\n return [...names]\n}\n\n/**\n * The layers a styled DOM describes, with the sizes and positions its layout implies. Styling\n * belongs to whoever has a CSS runtime, such as a browser or the headless runtime; building and\n * laying out the layers happens here for every caller. Safe to bundle for the browser.\n */\nexport function sceneGraphFromStyledHTML(\n styled: DesignDocument,\n options: SceneGraphFromStyledHTMLOptions = {}\n): SceneGraph {\n const graph = designDocumentToSceneGraph(styled, {\n pageName: options.pageName,\n resolveFontFamily: options.resolveFontFamily\n })\n layoutAuthoredNodes(\n graph,\n graph.getPages().map((page) => page.id)\n )\n return graph\n}\n"],"mappings":";;;;;;;AA6BA,MAAM,kBAAkB;;;;;AAMxB,SAAgB,eAAe,MAAwB;CACrD,MAAM,wBAAQ,IAAI,IAAY;CAC9B,KAAK,MAAM,SAAS,KAAK,SAAS,eAAe,GAAG;EAElD,MAAM,QAAQ,MAAM,MAAM,CAAC,CAAC,CAAC,KAAK,EAAE;EACpC,KAAK,MAAM,QAAQ,MAAM,MAAM,KAAK,GAAG,IAAI,MAAM,MAAM,IAAI,IAAI;CACjE;CACA,OAAO,CAAC,GAAG,KAAK;AAClB;;;;;;AAOA,SAAgB,yBACd,QACA,UAA2C,CAAC,GAChC;CACZ,MAAM,QAAQ,2BAA2B,QAAQ;EAC/C,UAAU,QAAQ;EAClB,mBAAmB,QAAQ;CAC7B,CAAC;CACD,oBACE,OACA,MAAM,SAAS,CAAC,CAAC,KAAK,SAAS,KAAK,EAAE,CACxC;CACA,OAAO;AACT"}
@@ -1,3 +1,4 @@
1
+ import { BooleanPathResolver } from "../boolean-path.js";
1
2
  import { VectorElementRenderer } from "@pairdraw/dom-css/export";
2
3
  //#region src/io/formats/html/vectors.d.ts
3
4
  /**
@@ -7,7 +8,7 @@ import { VectorElementRenderer } from "@pairdraw/dom-css/export";
7
8
  * were edited. Def ids start with the layer's id, so several SVGs on one page never pick up each
8
9
  * other's gradients or filters.
9
10
  */
10
- declare const vectorElement: VectorElementRenderer;
11
+ declare const vectorElement: (graph: Parameters<VectorElementRenderer>[0], node: Parameters<VectorElementRenderer>[1], booleanPath?: BooleanPathResolver) => ReturnType<VectorElementRenderer>;
11
12
  //#endregion
12
13
  export { vectorElement };
13
14
  //# sourceMappingURL=vectors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"vectors.d.ts","names":[],"sources":["../../../../src/io/formats/html/vectors.ts"],"mappings":";;;;;;;;;cAmCa,eAAe"}
1
+ {"version":3,"file":"vectors.d.ts","names":[],"sources":["../../../../src/io/formats/html/vectors.ts"],"mappings":";;;;;;;;;;cAoCa,gBACX,OAAO,WAAW,2BAClB,MAAM,WAAW,2BACjB,cAAc,wBACb,WAAW"}
@@ -29,13 +29,14 @@ function idPart(id) {
29
29
  * were edited. Def ids start with the layer's id, so several SVGs on one page never pick up each
30
30
  * other's gradients or filters.
31
31
  */
32
- const vectorElement = (graph, node) => {
32
+ const vectorElement = (graph, node, booleanPath) => {
33
33
  const idPrefix = `${idPart(node.id)}-`;
34
34
  const icon = readIcon(node);
35
35
  const drawn = renderNodeSVGElement(graph, node, {
36
36
  idPrefix,
37
37
  colorSpace: graph.documentColorSpace,
38
- tint: icon ? readIconTint : void 0
38
+ tint: icon ? readIconTint : void 0,
39
+ booleanPath
39
40
  });
40
41
  const element = drawn && designNode(drawn);
41
42
  if (element?.type !== "element") return null;
@@ -1 +1 @@
1
- {"version":3,"file":"vectors.js","names":[],"sources":["../../../../src/io/formats/html/vectors.ts"],"sourcesContent":["import type { DesignElement, DesignNode, VectorElementRenderer } from '@pairdraw/dom-css/export'\nimport { colorToHex } from '@pairdraw/scene-graph/color'\nimport { isIconModified, readIcon, readIconTint } from '@pairdraw/scene-graph/icons'\n\nimport { iconColor } from '#core/icons/render'\nimport { renderNodeSVGElement } from '#core/io/formats/svg/export'\nimport type { SVGNode } from '#core/io/formats/svg/node'\n\nfunction designNode(node: SVGNode | string): DesignNode {\n if (typeof node === 'string') return { type: 'text', text: node }\n return {\n type: 'element',\n tagName: node.tag,\n attrs: Object.fromEntries(\n Object.entries(node.attrs).map(([name, value]) => [name, String(value)])\n ),\n children: node.children.map(designNode)\n }\n}\n\n/**\n * A layer id as an id-safe string, one to one: letters, digits, and `-` stay, and anything\n * else, `_` included, becomes `_<code point>_`, so `a:b` and `a-b` never meet.\n */\nfunction idPart(id: string): string {\n return id.replace(/[^A-Za-z0-9-]/gu, (char) => `_${char.codePointAt(0)?.toString(16) ?? ''}_`)\n}\n\n/**\n * Vector layers and icons in HTML exports as inline SVG from the SVG export, so paths,\n * gradients, and shadows draw as they do there. An icon is one SVG whose tinted paths take\n * `currentColor`, so a page recolors it with CSS `color`, named by `data-icon` unless its paths\n * were edited. Def ids start with the layer's id, so several SVGs on one page never pick up each\n * other's gradients or filters.\n */\nexport const vectorElement: VectorElementRenderer = (graph, node) => {\n const idPrefix = `${idPart(node.id)}-`\n const icon = readIcon(node)\n const drawn = renderNodeSVGElement(graph, node, {\n idPrefix,\n colorSpace: graph.documentColorSpace,\n tint: icon ? readIconTint : undefined\n })\n const element = drawn && designNode(drawn)\n if (element?.type !== 'element') return null\n const color = icon ? iconColor(graph, node) : null\n return {\n ...element,\n // An icon whose paths were edited no longer draws the named icon, so it goes unnamed.\n attrs:\n icon && !isIconModified(graph, node)\n ? { ...element.attrs, 'data-icon': icon.name }\n : element.attrs,\n // Strokes and shadows can reach past the layer's box, which an inline SVG would clip.\n inlineStyle: { overflow: 'visible', ...(color ? { color: colorToHex(color) } : {}) }\n } satisfies DesignElement\n}\n"],"mappings":";;;;;AAQA,SAAS,WAAW,MAAoC;CACtD,IAAI,OAAO,SAAS,UAAU,OAAO;EAAE,MAAM;EAAQ,MAAM;CAAK;CAChE,OAAO;EACL,MAAM;EACN,SAAS,KAAK;EACd,OAAO,OAAO,YACZ,OAAO,QAAQ,KAAK,KAAK,CAAC,CAAC,KAAK,CAAC,MAAM,WAAW,CAAC,MAAM,OAAO,KAAK,CAAC,CAAC,CACzE;EACA,UAAU,KAAK,SAAS,IAAI,UAAU;CACxC;AACF;;;;;AAMA,SAAS,OAAO,IAAoB;CAClC,OAAO,GAAG,QAAQ,oBAAoB,SAAS,IAAI,KAAK,YAAY,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,GAAG,EAAE;AAC/F;;;;;;;;AASA,MAAa,iBAAwC,OAAO,SAAS;CACnE,MAAM,WAAW,GAAG,OAAO,KAAK,EAAE,EAAE;CACpC,MAAM,OAAO,SAAS,IAAI;CAC1B,MAAM,QAAQ,qBAAqB,OAAO,MAAM;EAC9C;EACA,YAAY,MAAM;EAClB,MAAM,OAAO,eAAe,KAAA;CAC9B,CAAC;CACD,MAAM,UAAU,SAAS,WAAW,KAAK;CACzC,IAAI,SAAS,SAAS,WAAW,OAAO;CACxC,MAAM,QAAQ,OAAO,UAAU,OAAO,IAAI,IAAI;CAC9C,OAAO;EACL,GAAG;EAEH,OACE,QAAQ,CAAC,eAAe,OAAO,IAAI,IAC/B;GAAE,GAAG,QAAQ;GAAO,aAAa,KAAK;EAAK,IAC3C,QAAQ;EAEd,aAAa;GAAE,UAAU;GAAW,GAAI,QAAQ,EAAE,OAAO,WAAW,KAAK,EAAE,IAAI,CAAC;EAAG;CACrF;AACF"}
1
+ {"version":3,"file":"vectors.js","names":[],"sources":["../../../../src/io/formats/html/vectors.ts"],"sourcesContent":["import type { DesignElement, DesignNode, VectorElementRenderer } from '@pairdraw/dom-css/export'\nimport { colorToHex } from '@pairdraw/scene-graph/color'\nimport { isIconModified, readIcon, readIconTint } from '@pairdraw/scene-graph/icons'\n\nimport { iconColor } from '#core/icons/render'\nimport type { BooleanPathResolver } from '#core/io/formats/boolean-path'\nimport { renderNodeSVGElement } from '#core/io/formats/svg/export'\nimport type { SVGNode } from '#core/io/formats/svg/node'\n\nfunction designNode(node: SVGNode | string): DesignNode {\n if (typeof node === 'string') return { type: 'text', text: node }\n return {\n type: 'element',\n tagName: node.tag,\n attrs: Object.fromEntries(\n Object.entries(node.attrs).map(([name, value]) => [name, String(value)])\n ),\n children: node.children.map(designNode)\n }\n}\n\n/**\n * A layer id as an id-safe string, one to one: letters, digits, and `-` stay, and anything\n * else, `_` included, becomes `_<code point>_`, so `a:b` and `a-b` never meet.\n */\nfunction idPart(id: string): string {\n return id.replace(/[^A-Za-z0-9-]/gu, (char) => `_${char.codePointAt(0)?.toString(16) ?? ''}_`)\n}\n\n/**\n * Vector layers and icons in HTML exports as inline SVG from the SVG export, so paths,\n * gradients, and shadows draw as they do there. An icon is one SVG whose tinted paths take\n * `currentColor`, so a page recolors it with CSS `color`, named by `data-icon` unless its paths\n * were edited. Def ids start with the layer's id, so several SVGs on one page never pick up each\n * other's gradients or filters.\n */\nexport const vectorElement = (\n graph: Parameters<VectorElementRenderer>[0],\n node: Parameters<VectorElementRenderer>[1],\n booleanPath?: BooleanPathResolver\n): ReturnType<VectorElementRenderer> => {\n const idPrefix = `${idPart(node.id)}-`\n const icon = readIcon(node)\n const drawn = renderNodeSVGElement(graph, node, {\n idPrefix,\n colorSpace: graph.documentColorSpace,\n tint: icon ? readIconTint : undefined,\n booleanPath\n })\n const element = drawn && designNode(drawn)\n if (element?.type !== 'element') return null\n const color = icon ? iconColor(graph, node) : null\n return {\n ...element,\n // An icon whose paths were edited no longer draws the named icon, so it goes unnamed.\n attrs:\n icon && !isIconModified(graph, node)\n ? { ...element.attrs, 'data-icon': icon.name }\n : element.attrs,\n // Strokes and shadows can reach past the layer's box, which an inline SVG would clip.\n inlineStyle: { overflow: 'visible', ...(color ? { color: colorToHex(color) } : {}) }\n } satisfies DesignElement\n}\n"],"mappings":";;;;;AASA,SAAS,WAAW,MAAoC;CACtD,IAAI,OAAO,SAAS,UAAU,OAAO;EAAE,MAAM;EAAQ,MAAM;CAAK;CAChE,OAAO;EACL,MAAM;EACN,SAAS,KAAK;EACd,OAAO,OAAO,YACZ,OAAO,QAAQ,KAAK,KAAK,CAAC,CAAC,KAAK,CAAC,MAAM,WAAW,CAAC,MAAM,OAAO,KAAK,CAAC,CAAC,CACzE;EACA,UAAU,KAAK,SAAS,IAAI,UAAU;CACxC;AACF;;;;;AAMA,SAAS,OAAO,IAAoB;CAClC,OAAO,GAAG,QAAQ,oBAAoB,SAAS,IAAI,KAAK,YAAY,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,GAAG,EAAE;AAC/F;;;;;;;;AASA,MAAa,iBACX,OACA,MACA,gBACsC;CACtC,MAAM,WAAW,GAAG,OAAO,KAAK,EAAE,EAAE;CACpC,MAAM,OAAO,SAAS,IAAI;CAC1B,MAAM,QAAQ,qBAAqB,OAAO,MAAM;EAC9C;EACA,YAAY,MAAM;EAClB,MAAM,OAAO,eAAe,KAAA;EAC5B;CACF,CAAC;CACD,MAAM,UAAU,SAAS,WAAW,KAAK;CACzC,IAAI,SAAS,SAAS,WAAW,OAAO;CACxC,MAAM,QAAQ,OAAO,UAAU,OAAO,IAAI,IAAI;CAC9C,OAAO;EACL,GAAG;EAEH,OACE,QAAQ,CAAC,eAAe,OAAO,IAAI,IAC/B;GAAE,GAAG,QAAQ;GAAO,aAAa,KAAK;EAAK,IAC3C,QAAQ;EAEd,aAAa;GAAE,UAAU;GAAW,GAAI,QAAQ,EAAE,OAAO,WAAW,KAAK,EAAE,IAAI,CAAC;EAAG;CACrF;AACF"}
@@ -1,5 +1,5 @@
1
- import { tryParseColor } from "@pairdraw/scene-graph/color";
2
1
  import { parseCSSNumber } from "@pairdraw/scene-graph/css";
2
+ import { tryParseColor } from "@pairdraw/scene-graph/color";
3
3
  //#region src/io/formats/mermaid/styles.ts
4
4
  function color(value) {
5
5
  if (value === "none" || value === "transparent") return null;
@@ -1,5 +1,7 @@
1
+ import { SkiaRenderer } from "../../../canvas/renderer.js";
1
2
  import { PDFPageSpec } from "./plan.js";
2
3
  import { PDFExportResult } from "./export.js";
4
+ import { CanvasKit } from "canvaskit-wasm";
3
5
  import { SceneGraph } from "@pairdraw/scene-graph";
4
6
  //#region src/io/formats/pdf/document.d.ts
5
7
  interface PDFDocumentOptions {
@@ -13,7 +15,7 @@ interface PDFDocumentOptions {
13
15
  * A PDF of the pages as the canvas draws them: the fonts their text uses loaded, and each
14
16
  * paragraph broken into the lines the canvas breaks it into. Null when no page shows anything.
15
17
  */
16
- declare function exportPDFDocument(graph: SceneGraph, specs: readonly PDFPageSpec[], options: PDFDocumentOptions): Promise<PDFExportResult | null>;
18
+ declare function exportPDFDocument(graph: SceneGraph, specs: readonly PDFPageSpec[], options: PDFDocumentOptions, canvasKit?: CanvasKit, renderer?: SkiaRenderer): Promise<PDFExportResult | null>;
17
19
  //#endregion
18
20
  export { PDFDocumentOptions, exportPDFDocument };
19
21
  //# sourceMappingURL=document.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"document.d.ts","names":[],"sources":["../../../../src/io/formats/pdf/document.ts"],"mappings":";;;;UAQiB;;EAEf;;EAEA;EACA;;;;;;iBAOoB,kBACpB,OAAO,YACP,gBAAgB,eAChB,SAAS,qBACR,QAAQ"}
1
+ {"version":3,"file":"document.d.ts","names":[],"sources":["../../../../src/io/formats/pdf/document.ts"],"mappings":";;;;;;UAYiB;;EAEf;;EAEA;EACA;;;;;;iBAOoB,kBACpB,OAAO,YACP,gBAAgB,eAChB,SAAS,oBACT,YAAY,WACZ,WAAW,eACV,QAAQ"}
@@ -1,15 +1,18 @@
1
1
  import { fontManager } from "../../../text/font/manager.js";
2
2
  import { pdfFontFaces, preparePDFFonts, preparePagesForPDF, withPDFTextLayout } from "./prepare.js";
3
+ import { bakeAdjustedImages, hasAdjustedImagePaints } from "../raster/adjusted-images.js";
3
4
  import { renderPagesToPDFDetailed } from "./export.js";
4
5
  //#region src/io/formats/pdf/document.ts
5
6
  /**
6
7
  * A PDF of the pages as the canvas draws them: the fonts their text uses loaded, and each
7
8
  * paragraph broken into the lines the canvas breaks it into. Null when no page shows anything.
8
9
  */
9
- async function exportPDFDocument(graph, specs, options) {
10
- const status = options.layOutPages ? await preparePagesForPDF(graph, specs) : await preparePDFFonts(graph, specs);
10
+ async function exportPDFDocument(graph, specs, options, canvasKit, renderer) {
11
+ const nodeIds = specs.flatMap((spec) => spec.nodeIds);
12
+ const baked = hasAdjustedImagePaints(graph, nodeIds) ? await bakeAdjustedImages(graph, nodeIds, canvasKit, renderer) : graph;
13
+ const status = options.layOutPages ? await preparePagesForPDF(baked, specs) : await preparePDFFonts(baked, specs);
11
14
  const fonts = options.embedFonts ? pdfFontFaces(status) : void 0;
12
- return withPDFTextLayout((textLayout) => renderPagesToPDFDetailed(graph, specs, {
15
+ return withPDFTextLayout((textLayout) => renderPagesToPDFDetailed(baked, specs, {
13
16
  fonts,
14
17
  textLayout,
15
18
  fallbackFile: (family, style, file) => file === 0 ? fontManager.loadedData(family, style) : fontManager.shardData(family, style)[file - 1] ?? null,
@@ -1 +1 @@
1
- {"version":3,"file":"document.js","names":[],"sources":["../../../../src/io/formats/pdf/document.ts"],"sourcesContent":["import type { SceneGraph } from '@pairdraw/scene-graph'\n\nimport { fontManager } from '#core/text/font/manager'\n\nimport { renderPagesToPDFDetailed, type PDFExportResult } from './export'\nimport type { PDFPageSpec } from './plan'\nimport { pdfFontFaces, preparePagesForPDF, preparePDFFonts, withPDFTextLayout } from './prepare'\n\nexport interface PDFDocumentOptions {\n /** Embed the font files the text uses; without them, text uses standard PDF fonts. */\n embedFonts: boolean\n /** Lay the pages out first, as pages other than the open one have no layout yet. */\n layOutPages?: boolean\n title?: string\n}\n\n/**\n * A PDF of the pages as the canvas draws them: the fonts their text uses loaded, and each\n * paragraph broken into the lines the canvas breaks it into. Null when no page shows anything.\n */\nexport async function exportPDFDocument(\n graph: SceneGraph,\n specs: readonly PDFPageSpec[],\n options: PDFDocumentOptions\n): Promise<PDFExportResult | null> {\n const status = options.layOutPages\n ? await preparePagesForPDF(graph, specs)\n : await preparePDFFonts(graph, specs)\n const fonts = options.embedFonts ? pdfFontFaces(status) : undefined\n return withPDFTextLayout((textLayout) =>\n renderPagesToPDFDetailed(graph, specs, {\n fonts,\n textLayout,\n fallbackFile: (family, style, file) =>\n file === 0\n ? fontManager.loadedData(family, style)\n : (fontManager.shardData(family, style)[file - 1] ?? null),\n title: options.title\n })\n )\n}\n"],"mappings":";;;;;;;;AAoBA,eAAsB,kBACpB,OACA,OACA,SACiC;CACjC,MAAM,SAAS,QAAQ,cACnB,MAAM,mBAAmB,OAAO,KAAK,IACrC,MAAM,gBAAgB,OAAO,KAAK;CACtC,MAAM,QAAQ,QAAQ,aAAa,aAAa,MAAM,IAAI,KAAA;CAC1D,OAAO,mBAAmB,eACxB,yBAAyB,OAAO,OAAO;EACrC;EACA;EACA,eAAe,QAAQ,OAAO,SAC5B,SAAS,IACL,YAAY,WAAW,QAAQ,KAAK,IACnC,YAAY,UAAU,QAAQ,KAAK,CAAC,CAAC,OAAO,MAAM;EACzD,OAAO,QAAQ;CACjB,CAAC,CACH;AACF"}
1
+ {"version":3,"file":"document.js","names":[],"sources":["../../../../src/io/formats/pdf/document.ts"],"sourcesContent":["import type { CanvasKit } from 'canvaskit-wasm'\n\nimport type { SceneGraph } from '@pairdraw/scene-graph'\n\nimport type { SkiaRenderer } from '#core/canvas/renderer'\nimport { bakeAdjustedImages, hasAdjustedImagePaints } from '#core/io/formats/raster/adjusted-images'\nimport { fontManager } from '#core/text/font/manager'\n\nimport { renderPagesToPDFDetailed, type PDFExportResult } from './export'\nimport type { PDFPageSpec } from './plan'\nimport { pdfFontFaces, preparePagesForPDF, preparePDFFonts, withPDFTextLayout } from './prepare'\n\nexport interface PDFDocumentOptions {\n /** Embed the font files the text uses; without them, text uses standard PDF fonts. */\n embedFonts: boolean\n /** Lay the pages out first, as pages other than the open one have no layout yet. */\n layOutPages?: boolean\n title?: string\n}\n\n/**\n * A PDF of the pages as the canvas draws them: the fonts their text uses loaded, and each\n * paragraph broken into the lines the canvas breaks it into. Null when no page shows anything.\n */\nexport async function exportPDFDocument(\n graph: SceneGraph,\n specs: readonly PDFPageSpec[],\n options: PDFDocumentOptions,\n canvasKit?: CanvasKit,\n renderer?: SkiaRenderer\n): Promise<PDFExportResult | null> {\n const nodeIds = specs.flatMap((spec) => spec.nodeIds)\n const baked = hasAdjustedImagePaints(graph, nodeIds)\n ? await bakeAdjustedImages(graph, nodeIds, canvasKit, renderer)\n : graph\n const status = options.layOutPages\n ? await preparePagesForPDF(baked, specs)\n : await preparePDFFonts(baked, specs)\n const fonts = options.embedFonts ? pdfFontFaces(status) : undefined\n return withPDFTextLayout((textLayout) =>\n renderPagesToPDFDetailed(baked, specs, {\n fonts,\n textLayout,\n fallbackFile: (family, style, file) =>\n file === 0\n ? fontManager.loadedData(family, style)\n : (fontManager.shardData(family, style)[file - 1] ?? null),\n title: options.title\n })\n )\n}\n"],"mappings":";;;;;;;;;AAwBA,eAAsB,kBACpB,OACA,OACA,SACA,WACA,UACiC;CACjC,MAAM,UAAU,MAAM,SAAS,SAAS,KAAK,OAAO;CACpD,MAAM,QAAQ,uBAAuB,OAAO,OAAO,IAC/C,MAAM,mBAAmB,OAAO,SAAS,WAAW,QAAQ,IAC5D;CACJ,MAAM,SAAS,QAAQ,cACnB,MAAM,mBAAmB,OAAO,KAAK,IACrC,MAAM,gBAAgB,OAAO,KAAK;CACtC,MAAM,QAAQ,QAAQ,aAAa,aAAa,MAAM,IAAI,KAAA;CAC1D,OAAO,mBAAmB,eACxB,yBAAyB,OAAO,OAAO;EACrC;EACA;EACA,eAAe,QAAQ,OAAO,SAC5B,SAAS,IACL,YAAY,WAAW,QAAQ,KAAK,IACnC,YAAY,UAAU,QAAQ,KAAK,CAAC,CAAC,OAAO,MAAM;EACzD,OAAO,QAAQ;CACjB,CAAC,CACH;AACF"}
@@ -15,7 +15,12 @@ declare function withPDFDOM<T>(draw: (parse: SVGPageParser) => Promise<T>): Prom
15
15
  * The two globals exist only while the import evaluates, and the function the module made keeps
16
16
  * the jsPDF it read, so the rest of the export needs nothing from them.
17
17
  */
18
- declare function loadSVG2PDF(jsPDF: unknown): Promise<typeof svg2pdf>;
18
+ /**
19
+ * svg2pdf.js's `main` is a UMD build in a `"type": "module"` package with no `exports`, so Node
20
+ * loads it as ESM and it throws for want of a global jsPDF. Its ES build, the `module` file
21
+ * bundlers and Bun already pick, loads everywhere.
22
+ */
23
+ declare function loadSVG2PDF(): Promise<typeof svg2pdf>;
19
24
  //#endregion
20
25
  export { SVGPageParser, loadSVG2PDF, withPDFDOM };
21
26
  //# sourceMappingURL=dom.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dom.d.ts","names":[],"sources":["../../../../src/io/formats/pdf/dom.ts"],"mappings":";;;KAOY,iBAAiB,gBAAgB;;;;;;iBAkI7B,WAAW,GAAG,OAAO,OAAO,kBAAkB,QAAQ,KAAK,QAAQ;;;;;;;;iBAkE7D,YAAY,iBAAiB,eAAe"}
1
+ {"version":3,"file":"dom.d.ts","names":[],"sources":["../../../../src/io/formats/pdf/dom.ts"],"mappings":";;;KAOY,iBAAiB,gBAAgB;;;;;;iBAkI7B,WAAW,GAAG,OAAO,OAAO,kBAAkB,QAAQ,KAAK,QAAQ;;;;;;;;;;;;;iBAuE7D,eAAe,eAAe"}
@@ -138,28 +138,15 @@ async function withHappyDOM(draw) {
138
138
  * The two globals exist only while the import evaluates, and the function the module made keeps
139
139
  * the jsPDF it read, so the rest of the export needs nothing from them.
140
140
  */
141
- async function loadSVG2PDF(jsPDF) {
142
- const scope = globalThis;
143
- const previousJSPDF = Object.getOwnPropertyDescriptor(globalThis, "jspdf");
144
- const previousSVG2PDF = Object.getOwnPropertyDescriptor(globalThis, "svg2pdf");
145
- const set = (name, value) => {
146
- Object.defineProperty(globalThis, name, {
147
- value,
148
- configurable: true,
149
- writable: true
150
- });
151
- };
152
- set("jspdf", { jsPDF });
153
- try {
154
- const draw = (await import("svg2pdf.js")).svg2pdf ?? scope.svg2pdf?.svg2pdf;
155
- if (!draw) throw new Error("svg2pdf.js exported no svg2pdf function");
156
- return draw;
157
- } finally {
158
- if (previousJSPDF) Object.defineProperty(globalThis, "jspdf", previousJSPDF);
159
- else delete scope.jspdf;
160
- if (previousSVG2PDF) Object.defineProperty(globalThis, "svg2pdf", previousSVG2PDF);
161
- else delete scope.svg2pdf;
162
- }
141
+ /**
142
+ * svg2pdf.js's `main` is a UMD build in a `"type": "module"` package with no `exports`, so Node
143
+ * loads it as ESM and it throws for want of a global jsPDF. Its ES build, the `module` file
144
+ * bundlers and Bun already pick, loads everywhere.
145
+ */
146
+ async function loadSVG2PDF() {
147
+ const module = await import("svg2pdf.js/dist/svg2pdf.es.min.js");
148
+ if (!module.svg2pdf) throw new Error("svg2pdf.js exported no svg2pdf function");
149
+ return module.svg2pdf;
163
150
  }
164
151
  //#endregion
165
152
  export { loadSVG2PDF, withPDFDOM };
@@ -1 +1 @@
1
- {"version":3,"file":"dom.js","names":[],"sources":["../../../../src/io/formats/pdf/dom.ts"],"sourcesContent":["import type * as HappyDOM from 'happy-dom'\nimport { toUint8Array } from 'js-base64'\nimport type { svg2pdf } from 'svg2pdf.js'\n\nimport { IS_BROWSER } from '#core/constants'\n\n/** A page's SVG markup as the element svg2pdf draws, or null when it does not parse. */\nexport type SVGPageParser = (svg: string) => Element | null\n\ninterface SVGParser {\n parseFromString(\n svg: string,\n type: 'image/svg+xml'\n ): {\n querySelector(selectors: string): unknown\n documentElement: unknown\n }\n}\n\n/** The pixel size a data URI's image holds, as svg2pdf asks an `Image` for it. */\nfunction imageSize(source: string): [number, number] {\n const comma = source.indexOf(',')\n if (comma === -1 || !source.slice(0, comma).includes(';base64')) {\n throw new Error('Not a base64 data URI')\n }\n const bytes = toUint8Array(source.slice(comma + 1))\n const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength)\n const starts = (text: string, at = 0) =>\n Array.from(text, (character, index) => bytes[at + index] === character.charCodeAt(0)).every(\n Boolean\n )\n if (starts('\\x89PNG')) return [view.getUint32(16), view.getUint32(20)]\n if (starts('GIF8')) return [view.getUint16(6, true), view.getUint16(8, true)]\n if (starts('RIFF') && starts('WEBP', 8)) {\n const kind = String.fromCharCode(...bytes.subarray(12, 16))\n if (kind === 'VP8X') {\n return [\n 1 + (bytes[24] | (bytes[25] << 8) | (bytes[26] << 16)),\n 1 + (bytes[27] | (bytes[28] << 8) | (bytes[29] << 16))\n ]\n }\n if (kind === 'VP8 ')\n return [view.getUint16(26, true) & 0x3fff, view.getUint16(28, true) & 0x3fff]\n }\n if (bytes[0] === 0xff && bytes[1] === 0xd8) {\n for (let at = 2; at + 9 < bytes.length;) {\n if (bytes[at] !== 0xff) {\n at++\n continue\n }\n const marker = bytes[at + 1]\n const length = view.getUint16(at + 2)\n // Start-of-frame markers carry the image's size; C4, C8, and CC are other segments.\n if (\n marker >= 0xc0 &&\n marker <= 0xcf &&\n marker !== 0xc4 &&\n marker !== 0xc8 &&\n marker !== 0xcc\n ) {\n return [view.getUint16(at + 7), view.getUint16(at + 5)]\n }\n at += 2 + length\n }\n }\n throw new Error('Unsupported image data')\n}\n\n/**\n * The `Image` svg2pdf asks for an image's size by name, for a host without one: it decodes only a\n * base64 data URI's header, which is all the size needs.\n */\nclass HeadlessImage {\n width = 0\n height = 0\n onload: (() => void) | null = null\n onerror: ((error: unknown) => void) | null = null\n\n set src(value: string) {\n try {\n const [width, height] = imageSize(value)\n this.width = width\n this.height = height\n queueMicrotask(() => this.onload?.())\n } catch (error) {\n queueMicrotask(() => this.onerror?.(error))\n }\n }\n}\n\n/**\n * The globals svg2pdf reads: it parses a page's stylesheets in a document it makes, and keeps the\n * rules that are instances of the CSSOM classes.\n */\ninterface SVG2PDFGlobals {\n document?: unknown\n CSSStyleSheet?: unknown\n CSSStyleRule?: unknown\n Image?: unknown\n}\n\nconst SVG2PDF_GLOBALS = ['document', 'CSSStyleSheet', 'CSSStyleRule'] as const\n\ntype SVG2PDFGlobal = (typeof SVG2PDF_GLOBALS)[number] | 'Image'\n\nfunction removeGlobal(scope: SVG2PDFGlobals, name: SVG2PDFGlobal): void {\n if (name === 'document') delete scope.document\n else if (name === 'CSSStyleSheet') delete scope.CSSStyleSheet\n else if (name === 'Image') delete scope.Image\n else delete scope.CSSStyleRule\n}\n\n/**\n * Kept out of the browser bundle: a browser has a DOM of its own, and happy-dom is only loaded\n * where there is none.\n */\nconst HAPPY_DOM = 'happy-dom'\n\nlet exporting: Promise<unknown> = Promise.resolve()\n\nfunction isElement(value: unknown): value is Element {\n return typeof value === 'object' && value !== null && 'tagName' in value\n}\n\nfunction parseSVGPage(parser: SVGParser): SVGPageParser {\n return (svg) => {\n const parsed = parser.parseFromString(svg, 'image/svg+xml')\n if (parsed.querySelector('parsererror')) return null\n return isElement(parsed.documentElement) ? parsed.documentElement : null\n }\n}\n\n/**\n * Runs `draw` with a parser for page SVG and the DOM svg2pdf draws it through. A browser has both.\n * Elsewhere, as in the CLI, happy-dom stands in: svg2pdf reads its DOM as globals, so they are set\n * only while `draw` runs, one export at a time, and restored after.\n */\nexport function withPDFDOM<T>(draw: (parse: SVGPageParser) => Promise<T>): Promise<T> {\n if (IS_BROWSER) return draw(parseSVGPage(new DOMParser()))\n const run = exporting.then(() => withHappyDOM(draw))\n exporting = run.catch(() => undefined)\n return run\n}\n\nasync function withHappyDOM<T>(draw: (parse: SVGPageParser) => Promise<T>): Promise<T> {\n const { Window } = (await import(/* @vite-ignore */ HAPPY_DOM)) as typeof HappyDOM\n const dom = new Window()\n const scope: SVG2PDFGlobals = globalThis\n const values: Record<SVG2PDFGlobal, unknown> = {\n document: dom.document,\n CSSStyleSheet: dom.CSSStyleSheet,\n CSSStyleRule: dom.CSSStyleRule,\n Image: HeadlessImage\n }\n // Each global replaced, with its descriptor before, so an accessor a host defines comes back as\n // one and a global that could not be replaced is left as it was.\n const replaced: Array<[SVG2PDFGlobal, PropertyDescriptor | undefined]> = []\n let replacedImage: PropertyDescriptor | undefined\n let hadImage = false\n try {\n // svg2pdf reads an image's size through a browser `Image`, which a CLI host lacks.\n if (!('Image' in globalThis)) {\n replacedImage = Object.getOwnPropertyDescriptor(globalThis, 'Image')\n hadImage = false\n Object.defineProperty(globalThis, 'Image', {\n value: HeadlessImage,\n configurable: true,\n writable: true\n })\n } else {\n hadImage = true\n }\n for (const name of SVG2PDF_GLOBALS) {\n const previous = Object.getOwnPropertyDescriptor(globalThis, name)\n Object.defineProperty(globalThis, name, {\n value: values[name],\n configurable: true,\n writable: true\n })\n replaced.push([name, previous])\n }\n return await draw(parseSVGPage(new dom.DOMParser()))\n } finally {\n // What is replaced is configurable, so putting it back does not throw.\n for (const [name, previous] of replaced) {\n if (previous) Object.defineProperty(globalThis, name, previous)\n else removeGlobal(scope, name)\n }\n if (!hadImage) {\n if (replacedImage) Object.defineProperty(globalThis, 'Image', replacedImage)\n else removeGlobal(scope, 'Image')\n }\n await dom.happyDOM.close()\n }\n}\n\n/**\n * Loads `svg2pdf.js`. Its package publishes a UMD build only, whose factory reads jsPDF from the\n * global `jspdf` and, with no CommonJS `exports`, writes the function to the global `svg2pdf`; a\n * bundler supplies both, a bare Node install supplies neither, and the module then fails on load.\n * The two globals exist only while the import evaluates, and the function the module made keeps\n * the jsPDF it read, so the rest of the export needs nothing from them.\n */\nexport async function loadSVG2PDF(jsPDF: unknown): Promise<typeof svg2pdf> {\n const scope = globalThis as { jspdf?: unknown; svg2pdf?: { svg2pdf?: typeof svg2pdf } }\n const previousJSPDF = Object.getOwnPropertyDescriptor(globalThis, 'jspdf')\n const previousSVG2PDF = Object.getOwnPropertyDescriptor(globalThis, 'svg2pdf')\n const set = (name: string, value: unknown): void => {\n Object.defineProperty(globalThis, name, { value, configurable: true, writable: true })\n }\n set('jspdf', { jsPDF })\n try {\n const module = (await import('svg2pdf.js')) as { svg2pdf?: typeof svg2pdf }\n const draw = module.svg2pdf ?? scope.svg2pdf?.svg2pdf\n if (!draw) throw new Error('svg2pdf.js exported no svg2pdf function')\n return draw\n } finally {\n if (previousJSPDF) Object.defineProperty(globalThis, 'jspdf', previousJSPDF)\n else delete scope.jspdf\n if (previousSVG2PDF) Object.defineProperty(globalThis, 'svg2pdf', previousSVG2PDF)\n else delete scope.svg2pdf\n }\n}\n"],"mappings":"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"}
1
+ {"version":3,"file":"dom.js","names":[],"sources":["../../../../src/io/formats/pdf/dom.ts"],"sourcesContent":["import type * as HappyDOM from 'happy-dom'\nimport { toUint8Array } from 'js-base64'\nimport type { svg2pdf } from 'svg2pdf.js'\n\nimport { IS_BROWSER } from '#core/constants'\n\n/** A page's SVG markup as the element svg2pdf draws, or null when it does not parse. */\nexport type SVGPageParser = (svg: string) => Element | null\n\ninterface SVGParser {\n parseFromString(\n svg: string,\n type: 'image/svg+xml'\n ): {\n querySelector(selectors: string): unknown\n documentElement: unknown\n }\n}\n\n/** The pixel size a data URI's image holds, as svg2pdf asks an `Image` for it. */\nfunction imageSize(source: string): [number, number] {\n const comma = source.indexOf(',')\n if (comma === -1 || !source.slice(0, comma).includes(';base64')) {\n throw new Error('Not a base64 data URI')\n }\n const bytes = toUint8Array(source.slice(comma + 1))\n const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength)\n const starts = (text: string, at = 0) =>\n Array.from(text, (character, index) => bytes[at + index] === character.charCodeAt(0)).every(\n Boolean\n )\n if (starts('\\x89PNG')) return [view.getUint32(16), view.getUint32(20)]\n if (starts('GIF8')) return [view.getUint16(6, true), view.getUint16(8, true)]\n if (starts('RIFF') && starts('WEBP', 8)) {\n const kind = String.fromCharCode(...bytes.subarray(12, 16))\n if (kind === 'VP8X') {\n return [\n 1 + (bytes[24] | (bytes[25] << 8) | (bytes[26] << 16)),\n 1 + (bytes[27] | (bytes[28] << 8) | (bytes[29] << 16))\n ]\n }\n if (kind === 'VP8 ')\n return [view.getUint16(26, true) & 0x3fff, view.getUint16(28, true) & 0x3fff]\n }\n if (bytes[0] === 0xff && bytes[1] === 0xd8) {\n for (let at = 2; at + 9 < bytes.length;) {\n if (bytes[at] !== 0xff) {\n at++\n continue\n }\n const marker = bytes[at + 1]\n const length = view.getUint16(at + 2)\n // Start-of-frame markers carry the image's size; C4, C8, and CC are other segments.\n if (\n marker >= 0xc0 &&\n marker <= 0xcf &&\n marker !== 0xc4 &&\n marker !== 0xc8 &&\n marker !== 0xcc\n ) {\n return [view.getUint16(at + 7), view.getUint16(at + 5)]\n }\n at += 2 + length\n }\n }\n throw new Error('Unsupported image data')\n}\n\n/**\n * The `Image` svg2pdf asks for an image's size by name, for a host without one: it decodes only a\n * base64 data URI's header, which is all the size needs.\n */\nclass HeadlessImage {\n width = 0\n height = 0\n onload: (() => void) | null = null\n onerror: ((error: unknown) => void) | null = null\n\n set src(value: string) {\n try {\n const [width, height] = imageSize(value)\n this.width = width\n this.height = height\n queueMicrotask(() => this.onload?.())\n } catch (error) {\n queueMicrotask(() => this.onerror?.(error))\n }\n }\n}\n\n/**\n * The globals svg2pdf reads: it parses a page's stylesheets in a document it makes, and keeps the\n * rules that are instances of the CSSOM classes.\n */\ninterface SVG2PDFGlobals {\n document?: unknown\n CSSStyleSheet?: unknown\n CSSStyleRule?: unknown\n Image?: unknown\n}\n\nconst SVG2PDF_GLOBALS = ['document', 'CSSStyleSheet', 'CSSStyleRule'] as const\n\ntype SVG2PDFGlobal = (typeof SVG2PDF_GLOBALS)[number] | 'Image'\n\nfunction removeGlobal(scope: SVG2PDFGlobals, name: SVG2PDFGlobal): void {\n if (name === 'document') delete scope.document\n else if (name === 'CSSStyleSheet') delete scope.CSSStyleSheet\n else if (name === 'Image') delete scope.Image\n else delete scope.CSSStyleRule\n}\n\n/**\n * Kept out of the browser bundle: a browser has a DOM of its own, and happy-dom is only loaded\n * where there is none.\n */\nconst HAPPY_DOM = 'happy-dom'\n\nlet exporting: Promise<unknown> = Promise.resolve()\n\nfunction isElement(value: unknown): value is Element {\n return typeof value === 'object' && value !== null && 'tagName' in value\n}\n\nfunction parseSVGPage(parser: SVGParser): SVGPageParser {\n return (svg) => {\n const parsed = parser.parseFromString(svg, 'image/svg+xml')\n if (parsed.querySelector('parsererror')) return null\n return isElement(parsed.documentElement) ? parsed.documentElement : null\n }\n}\n\n/**\n * Runs `draw` with a parser for page SVG and the DOM svg2pdf draws it through. A browser has both.\n * Elsewhere, as in the CLI, happy-dom stands in: svg2pdf reads its DOM as globals, so they are set\n * only while `draw` runs, one export at a time, and restored after.\n */\nexport function withPDFDOM<T>(draw: (parse: SVGPageParser) => Promise<T>): Promise<T> {\n if (IS_BROWSER) return draw(parseSVGPage(new DOMParser()))\n const run = exporting.then(() => withHappyDOM(draw))\n exporting = run.catch(() => undefined)\n return run\n}\n\nasync function withHappyDOM<T>(draw: (parse: SVGPageParser) => Promise<T>): Promise<T> {\n const { Window } = (await import(/* @vite-ignore */ HAPPY_DOM)) as typeof HappyDOM\n const dom = new Window()\n const scope: SVG2PDFGlobals = globalThis\n const values: Record<SVG2PDFGlobal, unknown> = {\n document: dom.document,\n CSSStyleSheet: dom.CSSStyleSheet,\n CSSStyleRule: dom.CSSStyleRule,\n Image: HeadlessImage\n }\n // Each global replaced, with its descriptor before, so an accessor a host defines comes back as\n // one and a global that could not be replaced is left as it was.\n const replaced: Array<[SVG2PDFGlobal, PropertyDescriptor | undefined]> = []\n let replacedImage: PropertyDescriptor | undefined\n let hadImage = false\n try {\n // svg2pdf reads an image's size through a browser `Image`, which a CLI host lacks.\n if (!('Image' in globalThis)) {\n replacedImage = Object.getOwnPropertyDescriptor(globalThis, 'Image')\n hadImage = false\n Object.defineProperty(globalThis, 'Image', {\n value: HeadlessImage,\n configurable: true,\n writable: true\n })\n } else {\n hadImage = true\n }\n for (const name of SVG2PDF_GLOBALS) {\n const previous = Object.getOwnPropertyDescriptor(globalThis, name)\n Object.defineProperty(globalThis, name, {\n value: values[name],\n configurable: true,\n writable: true\n })\n replaced.push([name, previous])\n }\n return await draw(parseSVGPage(new dom.DOMParser()))\n } finally {\n // What is replaced is configurable, so putting it back does not throw.\n for (const [name, previous] of replaced) {\n if (previous) Object.defineProperty(globalThis, name, previous)\n else removeGlobal(scope, name)\n }\n if (!hadImage) {\n if (replacedImage) Object.defineProperty(globalThis, 'Image', replacedImage)\n else removeGlobal(scope, 'Image')\n }\n await dom.happyDOM.close()\n }\n}\n\n/**\n * Loads `svg2pdf.js`. Its package publishes a UMD build only, whose factory reads jsPDF from the\n * global `jspdf` and, with no CommonJS `exports`, writes the function to the global `svg2pdf`; a\n * bundler supplies both, a bare Node install supplies neither, and the module then fails on load.\n * The two globals exist only while the import evaluates, and the function the module made keeps\n * the jsPDF it read, so the rest of the export needs nothing from them.\n */\n/**\n * svg2pdf.js's `main` is a UMD build in a `\"type\": \"module\"` package with no `exports`, so Node\n * loads it as ESM and it throws for want of a global jsPDF. Its ES build, the `module` file\n * bundlers and Bun already pick, loads everywhere.\n */\nexport async function loadSVG2PDF(): Promise<typeof svg2pdf> {\n const module = (await import('svg2pdf.js/dist/svg2pdf.es.min.js')) as {\n svg2pdf?: typeof svg2pdf\n }\n if (!module.svg2pdf) throw new Error('svg2pdf.js exported no svg2pdf function')\n return module.svg2pdf\n}\n"],"mappings":"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"}
@@ -40,7 +40,7 @@ async function renderPages(graph, specs, options, parse) {
40
40
  if (prepared.length === 0) return null;
41
41
  const first = prepared[0];
42
42
  const { jsPDF } = await import("jspdf");
43
- const svg2pdf = await loadSVG2PDF(jsPDF);
43
+ const svg2pdf = await loadSVG2PDF();
44
44
  const doc = new jsPDF({
45
45
  orientation: orientationOf(first),
46
46
  unit: "pt",
@@ -1 +1 @@
1
- {"version":3,"file":"export.js","names":[],"sources":["../../../../src/io/formats/pdf/export.ts"],"sourcesContent":["import type { SceneGraph } from '@pairdraw/scene-graph'\n\nimport { computeContentBounds } from '#core/io/formats/raster'\nimport { renderNodesToSVG, type SVGExportOptions, type SVGTextLayout } from '#core/io/formats/svg'\n\nimport { loadSVG2PDF, withPDFDOM, type SVGPageParser } from './dom'\nimport {\n cutFontInstances,\n embeddedFontAlias,\n planFontEmbedding,\n registerEmbeddedFonts,\n type PDFFallbackFontFile,\n type PDFFontFace,\n type PDFFontReport\n} from './fonts'\nimport type { PDFPageSpec } from './plan'\n\nexport interface PDFExportOptions {\n title?: string\n /** The faces the text uses, to embed their files; without them text uses standard PDF fonts. */\n fonts?: readonly PDFFontFace[]\n /** Line breaks of text nodes as the editor laid them out, so paragraphs stay wrapped. */\n textLayout?: SVGTextLayout\n /** The files of fallback faces the text layout draws characters in, to embed them too. */\n fallbackFile?: PDFFallbackFontFile\n}\n\nexport interface PDFExportResult {\n data: Uint8Array\n /** The pages written, in order. Pages with nothing visible are skipped. */\n pages: Array<{ label?: string; width: number; height: number }>\n /** Embedded and fallback faces, when `fonts` was given. */\n fonts?: PDFFontReport\n}\n\ninterface PreparedPage {\n spec: PDFPageSpec\n svgElement: Element\n width: number\n height: number\n}\n\ntype PageSVGOptions = Pick<SVGExportOptions, 'textLayout' | 'fontAlias'>\n\nfunction preparePage(\n graph: SceneGraph,\n spec: PDFPageSpec,\n svgOptions: PageSVGOptions,\n parse: SVGPageParser\n): PreparedPage | null {\n const svg = renderNodesToSVG(graph, spec.pageId, spec.nodeIds, {\n xmlDeclaration: false,\n ...svgOptions\n })\n if (!svg) return null\n\n const bounds = computeContentBounds(graph, spec.nodeIds)\n if (!bounds) return null\n\n const width = bounds.maxX - bounds.minX\n const height = bounds.maxY - bounds.minY\n if (width <= 0 || height <= 0) return null\n\n const svgElement = parse(svg)\n return svgElement ? { spec, svgElement, width, height } : null\n}\n\nconst orientationOf = (page: PreparedPage) => (page.width > page.height ? 'landscape' : 'portrait')\n\n/**\n * A PDF with one page per spec, each sized to its content. Null when no page has anything visible.\n */\nexport function renderPagesToPDFDetailed(\n graph: SceneGraph,\n specs: readonly PDFPageSpec[],\n options: PDFExportOptions = {}\n): Promise<PDFExportResult | null> {\n return withPDFDOM((parse) => renderPages(graph, specs, options, parse))\n}\n\nasync function renderPages(\n graph: SceneGraph,\n specs: readonly PDFPageSpec[],\n options: PDFExportOptions,\n parse: SVGPageParser\n): Promise<PDFExportResult | null> {\n const embedding = options.fonts ? planFontEmbedding(options.fonts, options.fallbackFile) : null\n const svgOptions: PageSVGOptions = {\n textLayout: options.textLayout,\n fontAlias: embedding ? embeddedFontAlias(embedding) : undefined\n }\n const preparePages = () =>\n specs\n .map((spec) => preparePage(graph, spec, svgOptions, parse))\n .filter((page): page is PreparedPage => page !== null)\n let prepared = preparePages()\n if (prepared.length === 0) return null\n const first = prepared[0]\n\n const { jsPDF } = await import('jspdf')\n const svg2pdf = await loadSVG2PDF(jsPDF)\n\n const doc = new jsPDF({\n orientation: orientationOf(first),\n unit: 'pt',\n format: [first.width, first.height],\n compress: true\n })\n\n if (options.title) {\n doc.setProperties({ title: options.title })\n }\n\n // The pages name the variable instances they draw, which are cut now. jsPDF reads a font file\n // when it is registered, so a face it refuses is only known then. Either way, the pages are\n // written again without the names of faces that are not embedded.\n if (embedding) {\n const cut = await cutFontInstances(embedding)\n if (!registerEmbeddedFonts(doc, embedding) || !cut) prepared = preparePages()\n }\n\n for (const [index, page] of prepared.entries()) {\n if (index > 0) doc.addPage([page.width, page.height], orientationOf(page))\n await svg2pdf(page.svgElement, doc, { x: 0, y: 0, width: page.width, height: page.height })\n }\n\n return {\n data: new Uint8Array(doc.output('arraybuffer')),\n pages: prepared.map((page) => ({\n label: page.spec.label,\n width: page.width,\n height: page.height\n })),\n ...(embedding ? { fonts: embedding.report } : {})\n }\n}\n"],"mappings":";;;;;AA4CA,SAAS,YACP,OACA,MACA,YACA,OACqB;CACrB,MAAM,MAAM,iBAAiB,OAAO,KAAK,QAAQ,KAAK,SAAS;EAC7D,gBAAgB;EAChB,GAAG;CACL,CAAC;CACD,IAAI,CAAC,KAAK,OAAO;CAEjB,MAAM,SAAS,qBAAqB,OAAO,KAAK,OAAO;CACvD,IAAI,CAAC,QAAQ,OAAO;CAEpB,MAAM,QAAQ,OAAO,OAAO,OAAO;CACnC,MAAM,SAAS,OAAO,OAAO,OAAO;CACpC,IAAI,SAAS,KAAK,UAAU,GAAG,OAAO;CAEtC,MAAM,aAAa,MAAM,GAAG;CAC5B,OAAO,aAAa;EAAE;EAAM;EAAY;EAAO;CAAO,IAAI;AAC5D;AAEA,MAAM,iBAAiB,SAAwB,KAAK,QAAQ,KAAK,SAAS,cAAc;;;;AAKxF,SAAgB,yBACd,OACA,OACA,UAA4B,CAAC,GACI;CACjC,OAAO,YAAY,UAAU,YAAY,OAAO,OAAO,SAAS,KAAK,CAAC;AACxE;AAEA,eAAe,YACb,OACA,OACA,SACA,OACiC;CACjC,MAAM,YAAY,QAAQ,QAAQ,kBAAkB,QAAQ,OAAO,QAAQ,YAAY,IAAI;CAC3F,MAAM,aAA6B;EACjC,YAAY,QAAQ;EACpB,WAAW,YAAY,kBAAkB,SAAS,IAAI,KAAA;CACxD;CACA,MAAM,qBACJ,MACG,KAAK,SAAS,YAAY,OAAO,MAAM,YAAY,KAAK,CAAC,CAAC,CAC1D,QAAQ,SAA+B,SAAS,IAAI;CACzD,IAAI,WAAW,aAAa;CAC5B,IAAI,SAAS,WAAW,GAAG,OAAO;CAClC,MAAM,QAAQ,SAAS;CAEvB,MAAM,EAAE,UAAU,MAAM,OAAO;CAC/B,MAAM,UAAU,MAAM,YAAY,KAAK;CAEvC,MAAM,MAAM,IAAI,MAAM;EACpB,aAAa,cAAc,KAAK;EAChC,MAAM;EACN,QAAQ,CAAC,MAAM,OAAO,MAAM,MAAM;EAClC,UAAU;CACZ,CAAC;CAED,IAAI,QAAQ,OACV,IAAI,cAAc,EAAE,OAAO,QAAQ,MAAM,CAAC;CAM5C,IAAI,WAAW;EACb,MAAM,MAAM,MAAM,iBAAiB,SAAS;EAC5C,IAAI,CAAC,sBAAsB,KAAK,SAAS,KAAK,CAAC,KAAK,WAAW,aAAa;CAC9E;CAEA,KAAK,MAAM,CAAC,OAAO,SAAS,SAAS,QAAQ,GAAG;EAC9C,IAAI,QAAQ,GAAG,IAAI,QAAQ,CAAC,KAAK,OAAO,KAAK,MAAM,GAAG,cAAc,IAAI,CAAC;EACzE,MAAM,QAAQ,KAAK,YAAY,KAAK;GAAE,GAAG;GAAG,GAAG;GAAG,OAAO,KAAK;GAAO,QAAQ,KAAK;EAAO,CAAC;CAC5F;CAEA,OAAO;EACL,MAAM,IAAI,WAAW,IAAI,OAAO,aAAa,CAAC;EAC9C,OAAO,SAAS,KAAK,UAAU;GAC7B,OAAO,KAAK,KAAK;GACjB,OAAO,KAAK;GACZ,QAAQ,KAAK;EACf,EAAE;EACF,GAAI,YAAY,EAAE,OAAO,UAAU,OAAO,IAAI,CAAC;CACjD;AACF"}
1
+ {"version":3,"file":"export.js","names":[],"sources":["../../../../src/io/formats/pdf/export.ts"],"sourcesContent":["import type { SceneGraph } from '@pairdraw/scene-graph'\n\nimport { computeContentBounds } from '#core/io/formats/raster'\nimport { renderNodesToSVG, type SVGExportOptions, type SVGTextLayout } from '#core/io/formats/svg'\n\nimport { loadSVG2PDF, withPDFDOM, type SVGPageParser } from './dom'\nimport {\n cutFontInstances,\n embeddedFontAlias,\n planFontEmbedding,\n registerEmbeddedFonts,\n type PDFFallbackFontFile,\n type PDFFontFace,\n type PDFFontReport\n} from './fonts'\nimport type { PDFPageSpec } from './plan'\n\nexport interface PDFExportOptions {\n title?: string\n /** The faces the text uses, to embed their files; without them text uses standard PDF fonts. */\n fonts?: readonly PDFFontFace[]\n /** Line breaks of text nodes as the editor laid them out, so paragraphs stay wrapped. */\n textLayout?: SVGTextLayout\n /** The files of fallback faces the text layout draws characters in, to embed them too. */\n fallbackFile?: PDFFallbackFontFile\n}\n\nexport interface PDFExportResult {\n data: Uint8Array\n /** The pages written, in order. Pages with nothing visible are skipped. */\n pages: Array<{ label?: string; width: number; height: number }>\n /** Embedded and fallback faces, when `fonts` was given. */\n fonts?: PDFFontReport\n}\n\ninterface PreparedPage {\n spec: PDFPageSpec\n svgElement: Element\n width: number\n height: number\n}\n\ntype PageSVGOptions = Pick<SVGExportOptions, 'textLayout' | 'fontAlias'>\n\nfunction preparePage(\n graph: SceneGraph,\n spec: PDFPageSpec,\n svgOptions: PageSVGOptions,\n parse: SVGPageParser\n): PreparedPage | null {\n const svg = renderNodesToSVG(graph, spec.pageId, spec.nodeIds, {\n xmlDeclaration: false,\n ...svgOptions\n })\n if (!svg) return null\n\n const bounds = computeContentBounds(graph, spec.nodeIds)\n if (!bounds) return null\n\n const width = bounds.maxX - bounds.minX\n const height = bounds.maxY - bounds.minY\n if (width <= 0 || height <= 0) return null\n\n const svgElement = parse(svg)\n return svgElement ? { spec, svgElement, width, height } : null\n}\n\nconst orientationOf = (page: PreparedPage) => (page.width > page.height ? 'landscape' : 'portrait')\n\n/**\n * A PDF with one page per spec, each sized to its content. Null when no page has anything visible.\n */\nexport function renderPagesToPDFDetailed(\n graph: SceneGraph,\n specs: readonly PDFPageSpec[],\n options: PDFExportOptions = {}\n): Promise<PDFExportResult | null> {\n return withPDFDOM((parse) => renderPages(graph, specs, options, parse))\n}\n\nasync function renderPages(\n graph: SceneGraph,\n specs: readonly PDFPageSpec[],\n options: PDFExportOptions,\n parse: SVGPageParser\n): Promise<PDFExportResult | null> {\n const embedding = options.fonts ? planFontEmbedding(options.fonts, options.fallbackFile) : null\n const svgOptions: PageSVGOptions = {\n textLayout: options.textLayout,\n fontAlias: embedding ? embeddedFontAlias(embedding) : undefined\n }\n const preparePages = () =>\n specs\n .map((spec) => preparePage(graph, spec, svgOptions, parse))\n .filter((page): page is PreparedPage => page !== null)\n let prepared = preparePages()\n if (prepared.length === 0) return null\n const first = prepared[0]\n\n const { jsPDF } = await import('jspdf')\n const svg2pdf = await loadSVG2PDF()\n\n const doc = new jsPDF({\n orientation: orientationOf(first),\n unit: 'pt',\n format: [first.width, first.height],\n compress: true\n })\n\n if (options.title) {\n doc.setProperties({ title: options.title })\n }\n\n // The pages name the variable instances they draw, which are cut now. jsPDF reads a font file\n // when it is registered, so a face it refuses is only known then. Either way, the pages are\n // written again without the names of faces that are not embedded.\n if (embedding) {\n const cut = await cutFontInstances(embedding)\n if (!registerEmbeddedFonts(doc, embedding) || !cut) prepared = preparePages()\n }\n\n for (const [index, page] of prepared.entries()) {\n if (index > 0) doc.addPage([page.width, page.height], orientationOf(page))\n await svg2pdf(page.svgElement, doc, { x: 0, y: 0, width: page.width, height: page.height })\n }\n\n return {\n data: new Uint8Array(doc.output('arraybuffer')),\n pages: prepared.map((page) => ({\n label: page.spec.label,\n width: page.width,\n height: page.height\n })),\n ...(embedding ? { fonts: embedding.report } : {})\n }\n}\n"],"mappings":";;;;;AA4CA,SAAS,YACP,OACA,MACA,YACA,OACqB;CACrB,MAAM,MAAM,iBAAiB,OAAO,KAAK,QAAQ,KAAK,SAAS;EAC7D,gBAAgB;EAChB,GAAG;CACL,CAAC;CACD,IAAI,CAAC,KAAK,OAAO;CAEjB,MAAM,SAAS,qBAAqB,OAAO,KAAK,OAAO;CACvD,IAAI,CAAC,QAAQ,OAAO;CAEpB,MAAM,QAAQ,OAAO,OAAO,OAAO;CACnC,MAAM,SAAS,OAAO,OAAO,OAAO;CACpC,IAAI,SAAS,KAAK,UAAU,GAAG,OAAO;CAEtC,MAAM,aAAa,MAAM,GAAG;CAC5B,OAAO,aAAa;EAAE;EAAM;EAAY;EAAO;CAAO,IAAI;AAC5D;AAEA,MAAM,iBAAiB,SAAwB,KAAK,QAAQ,KAAK,SAAS,cAAc;;;;AAKxF,SAAgB,yBACd,OACA,OACA,UAA4B,CAAC,GACI;CACjC,OAAO,YAAY,UAAU,YAAY,OAAO,OAAO,SAAS,KAAK,CAAC;AACxE;AAEA,eAAe,YACb,OACA,OACA,SACA,OACiC;CACjC,MAAM,YAAY,QAAQ,QAAQ,kBAAkB,QAAQ,OAAO,QAAQ,YAAY,IAAI;CAC3F,MAAM,aAA6B;EACjC,YAAY,QAAQ;EACpB,WAAW,YAAY,kBAAkB,SAAS,IAAI,KAAA;CACxD;CACA,MAAM,qBACJ,MACG,KAAK,SAAS,YAAY,OAAO,MAAM,YAAY,KAAK,CAAC,CAAC,CAC1D,QAAQ,SAA+B,SAAS,IAAI;CACzD,IAAI,WAAW,aAAa;CAC5B,IAAI,SAAS,WAAW,GAAG,OAAO;CAClC,MAAM,QAAQ,SAAS;CAEvB,MAAM,EAAE,UAAU,MAAM,OAAO;CAC/B,MAAM,UAAU,MAAM,YAAY;CAElC,MAAM,MAAM,IAAI,MAAM;EACpB,aAAa,cAAc,KAAK;EAChC,MAAM;EACN,QAAQ,CAAC,MAAM,OAAO,MAAM,MAAM;EAClC,UAAU;CACZ,CAAC;CAED,IAAI,QAAQ,OACV,IAAI,cAAc,EAAE,OAAO,QAAQ,MAAM,CAAC;CAM5C,IAAI,WAAW;EACb,MAAM,MAAM,MAAM,iBAAiB,SAAS;EAC5C,IAAI,CAAC,sBAAsB,KAAK,SAAS,KAAK,CAAC,KAAK,WAAW,aAAa;CAC9E;CAEA,KAAK,MAAM,CAAC,OAAO,SAAS,SAAS,QAAQ,GAAG;EAC9C,IAAI,QAAQ,GAAG,IAAI,QAAQ,CAAC,KAAK,OAAO,KAAK,MAAM,GAAG,cAAc,IAAI,CAAC;EACzE,MAAM,QAAQ,KAAK,YAAY,KAAK;GAAE,GAAG;GAAG,GAAG;GAAG,OAAO,KAAK;GAAO,QAAQ,KAAK;EAAO,CAAC;CAC5F;CAEA,OAAO;EACL,MAAM,IAAI,WAAW,IAAI,OAAO,aAAa,CAAC;EAC9C,OAAO,SAAS,KAAK,UAAU;GAC7B,OAAO,KAAK,KAAK;GACjB,OAAO,KAAK;GACZ,QAAQ,KAAK;EACf,EAAE;EACF,GAAI,YAAY,EAAE,OAAO,UAAU,OAAO,IAAI,CAAC;CACjD;AACF"}
@@ -1,8 +1,8 @@
1
+ import { DocumentFontStatus } from "../../../text/font/status.js";
1
2
  import { SVGTextLayout } from "../svg/text/lines.js";
2
3
  import "../svg/index.js";
3
4
  import { PDFFontFace } from "./fonts.js";
4
5
  import { PDFPageSpec } from "./plan.js";
5
- import { DocumentFontStatus } from "../../../text/font/status.js";
6
6
  import { SceneGraph } from "@pairdraw/scene-graph";
7
7
  //#region src/io/formats/pdf/prepare.d.ts
8
8
  /**
@@ -13,10 +13,13 @@ interface LoadedImports {
13
13
  /** As the host gave them, to read their files with. */
14
14
  opened: Map<string, OpenedImport>;
15
15
  }
16
+ type UnresolvedReason = Extract<ReadDocumentWarning, {
17
+ kind: 'unresolved-imports';
18
+ }>['reason'];
16
19
  /** The imports a document opened without, by why. */
17
20
  declare class UnresolvedImports {
18
21
  #private;
19
- add(reason: ReadDocumentWarning['reason'], path: string): void;
22
+ add(reason: UnresolvedReason, path: string): void;
20
23
  warnings(): ReadDocumentWarning[];
21
24
  }
22
25
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"imports.d.ts","names":[],"sources":["../../../../src/io/formats/pen/imports.ts"],"mappings":";;;;UAgBiB;EACf,OAAO;EACP,SAAS,oBAAoB;;;UAId;;EAEf,SAAS,YAAY;;EAErB,QAAQ,YAAY;;;cAST;;EAMX,IAAI,QAAQ,+BAA+B;EAI3C,YAAY;;;;;;;;;iBA8FE,eACd,KAAK,aACL,OAAO,mBACP,YAAY,oBACX,QAAQ;;;;;iBASW,kBACpB,QAAQ,oBAAoB,eAC5B,cACC,QAAQ"}
1
+ {"version":3,"file":"imports.d.ts","names":[],"sources":["../../../../src/io/formats/pen/imports.ts"],"mappings":";;;;UAgBiB;EACf,OAAO;EACP,SAAS,oBAAoB;;;UAId;;EAEf,SAAS,YAAY;;EAErB,QAAQ,YAAY;;KAGjB,mBAAmB,QAAQ;EAAuB;;;cAK1C;;EAMX,IAAI,QAAQ,kBAAkB;EAI9B,YAAY;;;;;;;;;iBA8FE,eACd,KAAK,aACL,OAAO,mBACP,YAAY,oBACX,QAAQ;;;;;iBASW,kBACpB,QAAQ,oBAAoB,eAC5B,cACC,QAAQ"}
@@ -1 +1 @@
1
- {"version":3,"file":"imports.js","names":["#paths"],"sources":["../../../../src/io/formats/pen/imports.ts"],"sourcesContent":["import { dirname, isAbsolute, join } from 'pathe'\n\nimport {\n importedDocument,\n parseImportedImageURL,\n parsePenDocument,\n type PenDocument,\n type PenImport\n} from '@pairdraw/pen'\n\nimport type { ReadDocumentInput, ReadDocumentWarning } from '#core/io/types'\n\n/** How deep a chain of documents importing one another is read: sixteen documents. */\nconst MAX_IMPORT_DEPTH = 16\n\n/** A document read for another that imports it, with the documents it imports in turn. */\nexport interface OpenedImport {\n input: ReadDocumentInput\n imports: ReadonlyMap<string, OpenedImport>\n}\n\n/** The documents a document imports, read, by the alias it names each one with. */\nexport interface LoadedImports {\n /** As `buildPenGraph` takes them. */\n imports: Map<string, PenImport>\n /** As the host gave them, to read their files with. */\n opened: Map<string, OpenedImport>\n}\n\nconst UNRESOLVED_REASONS: readonly ReadDocumentWarning['reason'][] = [\n 'no-file-access',\n 'unreadable'\n]\n\n/** The imports a document opened without, by why. */\nexport class UnresolvedImports {\n readonly #paths: Record<ReadDocumentWarning['reason'], Set<string>> = {\n 'no-file-access': new Set(),\n unreadable: new Set()\n }\n\n add(reason: ReadDocumentWarning['reason'], path: string): void {\n this.#paths[reason].add(path)\n }\n\n warnings(): ReadDocumentWarning[] {\n return UNRESOLVED_REASONS.flatMap((reason) => {\n const paths = this.#paths[reason]\n return paths.size > 0 ? [{ kind: 'unresolved-imports', reason, paths: [...paths] }] : []\n })\n }\n}\n\n/** A document the host opened, or null for one that is no `.pen` document. */\nfunction parseImported(input: ReadDocumentInput): PenDocument | null {\n try {\n return parsePenDocument(new TextDecoder().decode(input.data))\n } catch {\n return null\n }\n}\n\n/** An import the host opened, or null for one it could not open or that is no `.pen` document. */\ntype OpenedDocument = { input: ReadDocumentInput; doc: PenDocument } | null\n\n/** What one read of a document and its imports shares across every document it reads. */\ninterface ImportRead {\n unresolved: UnresolvedImports\n /** Each import by its path from the document being opened, so the host opens a file once. */\n opened: Map<string, OpenedDocument>\n /** The imports of each document read, by the host's name for it, so each is read once. */\n loaded: Map<string, LoadedImports>\n}\n\n/**\n * The path an import is named by in warnings, from the document being opened: as that document\n * writes it for its own imports, and as the import resolves from there for its imports' imports.\n */\nfunction importPath(at: string, path: string): string {\n return at === '' || isAbsolute(path) ? path : join(dirname(at), path)\n}\n\nasync function openImported(input: ReadDocumentInput, path: string): Promise<OpenedDocument> {\n const opened = await input.openImport?.(path).catch(() => null)\n const doc = opened ? parseImported(opened) : null\n return opened && doc ? { input: opened, doc } : null\n}\n\n/**\n * The documents `doc` imports, opened through `input`, which `doc` was read from, and named as\n * `doc` names them, with the documents they import in turn. `at` is `doc`'s path from the document\n * being opened; `reading` holds the host's names for the documents importing `doc`, so a document\n * importing itself through others, the opened one included, is left out where it comes round.\n * Imports are opened one after another, so a document many import is opened and read once.\n */\nasync function loadImports(\n doc: PenDocument,\n input: ReadDocumentInput,\n read: ImportRead,\n at: string,\n reading: ReadonlySet<string>\n): Promise<LoadedImports> {\n const loaded: LoadedImports = { imports: new Map(), opened: new Map() }\n for (const [alias, path] of Object.entries(doc.imports ?? {})) {\n const shown = importPath(at, path)\n if (!input.openImport) {\n read.unresolved.add('no-file-access', shown)\n continue\n }\n if (reading.size > MAX_IMPORT_DEPTH) continue\n let opened = read.opened.get(shown)\n if (opened === undefined) {\n opened = await openImported(input, path)\n read.opened.set(shown, opened)\n }\n if (!opened) {\n read.unresolved.add('unreadable', shown)\n continue\n }\n const name = opened.input.name ?? shown\n if (reading.has(name)) continue\n let nested = read.loaded.get(name)\n if (!nested) {\n nested = await loadImports(opened.doc, opened.input, read, shown, new Set([...reading, name]))\n read.loaded.set(name, nested)\n }\n loaded.imports.set(alias, importedDocument(alias, path, opened.doc, nested.imports))\n loaded.opened.set(alias, { input: opened.input, imports: nested.opened })\n }\n return loaded\n}\n\n/**\n * The documents `doc` imports, opened through `input`, which `doc` was read from, with the\n * documents they import in turn. An import the host cannot open or that is no `.pen` document is\n * left out and reported to `unresolved`, by its path as `doc` writes it, or for an import's own\n * imports as it resolves from `doc`. The host's name for `doc` is the path its imports resolve\n * to, so an import that leads back to it is recognized.\n */\nexport function loadPenImports(\n doc: PenDocument,\n input: ReadDocumentInput,\n unresolved: UnresolvedImports\n): Promise<LoadedImports> {\n const read: ImportRead = { unresolved, opened: new Map(), loaded: new Map() }\n return loadImports(doc, input, read, '', new Set([input.name ?? '']))\n}\n\n/**\n * The bytes of an image an imported document draws, by the name `buildPenGraph` reads it with,\n * read beside the document that names it; null when no import has it or the host cannot read it.\n */\nexport async function readImportedImage(\n opened: ReadonlyMap<string, OpenedImport>,\n url: string\n): Promise<Uint8Array | null> {\n const parsed = parseImportedImageURL(url)\n const source = parsed ? opened.get(parsed.alias) : undefined\n if (!parsed || !source) return null\n if (parseImportedImageURL(parsed.url)) return readImportedImage(source.imports, parsed.url)\n return (await source.input.readAsset?.(parsed.url).catch(() => null)) ?? null\n}\n"],"mappings":"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"}
1
+ {"version":3,"file":"imports.js","names":["#paths"],"sources":["../../../../src/io/formats/pen/imports.ts"],"sourcesContent":["import { dirname, isAbsolute, join } from 'pathe'\n\nimport {\n importedDocument,\n parseImportedImageURL,\n parsePenDocument,\n type PenDocument,\n type PenImport\n} from '@pairdraw/pen'\n\nimport type { ReadDocumentInput, ReadDocumentWarning } from '#core/io/types'\n\n/** How deep a chain of documents importing one another is read: sixteen documents. */\nconst MAX_IMPORT_DEPTH = 16\n\n/** A document read for another that imports it, with the documents it imports in turn. */\nexport interface OpenedImport {\n input: ReadDocumentInput\n imports: ReadonlyMap<string, OpenedImport>\n}\n\n/** The documents a document imports, read, by the alias it names each one with. */\nexport interface LoadedImports {\n /** As `buildPenGraph` takes them. */\n imports: Map<string, PenImport>\n /** As the host gave them, to read their files with. */\n opened: Map<string, OpenedImport>\n}\n\ntype UnresolvedReason = Extract<ReadDocumentWarning, { kind: 'unresolved-imports' }>['reason']\n\nconst UNRESOLVED_REASONS: readonly UnresolvedReason[] = ['no-file-access', 'unreadable']\n\n/** The imports a document opened without, by why. */\nexport class UnresolvedImports {\n readonly #paths: Record<UnresolvedReason, Set<string>> = {\n 'no-file-access': new Set(),\n unreadable: new Set()\n }\n\n add(reason: UnresolvedReason, path: string): void {\n this.#paths[reason].add(path)\n }\n\n warnings(): ReadDocumentWarning[] {\n return UNRESOLVED_REASONS.flatMap((reason) => {\n const paths = this.#paths[reason]\n return paths.size > 0 ? [{ kind: 'unresolved-imports', reason, paths: [...paths] }] : []\n })\n }\n}\n\n/** A document the host opened, or null for one that is no `.pen` document. */\nfunction parseImported(input: ReadDocumentInput): PenDocument | null {\n try {\n return parsePenDocument(new TextDecoder().decode(input.data))\n } catch {\n return null\n }\n}\n\n/** An import the host opened, or null for one it could not open or that is no `.pen` document. */\ntype OpenedDocument = { input: ReadDocumentInput; doc: PenDocument } | null\n\n/** What one read of a document and its imports shares across every document it reads. */\ninterface ImportRead {\n unresolved: UnresolvedImports\n /** Each import by its path from the document being opened, so the host opens a file once. */\n opened: Map<string, OpenedDocument>\n /** The imports of each document read, by the host's name for it, so each is read once. */\n loaded: Map<string, LoadedImports>\n}\n\n/**\n * The path an import is named by in warnings, from the document being opened: as that document\n * writes it for its own imports, and as the import resolves from there for its imports' imports.\n */\nfunction importPath(at: string, path: string): string {\n return at === '' || isAbsolute(path) ? path : join(dirname(at), path)\n}\n\nasync function openImported(input: ReadDocumentInput, path: string): Promise<OpenedDocument> {\n const opened = await input.openImport?.(path).catch(() => null)\n const doc = opened ? parseImported(opened) : null\n return opened && doc ? { input: opened, doc } : null\n}\n\n/**\n * The documents `doc` imports, opened through `input`, which `doc` was read from, and named as\n * `doc` names them, with the documents they import in turn. `at` is `doc`'s path from the document\n * being opened; `reading` holds the host's names for the documents importing `doc`, so a document\n * importing itself through others, the opened one included, is left out where it comes round.\n * Imports are opened one after another, so a document many import is opened and read once.\n */\nasync function loadImports(\n doc: PenDocument,\n input: ReadDocumentInput,\n read: ImportRead,\n at: string,\n reading: ReadonlySet<string>\n): Promise<LoadedImports> {\n const loaded: LoadedImports = { imports: new Map(), opened: new Map() }\n for (const [alias, path] of Object.entries(doc.imports ?? {})) {\n const shown = importPath(at, path)\n if (!input.openImport) {\n read.unresolved.add('no-file-access', shown)\n continue\n }\n if (reading.size > MAX_IMPORT_DEPTH) continue\n let opened = read.opened.get(shown)\n if (opened === undefined) {\n opened = await openImported(input, path)\n read.opened.set(shown, opened)\n }\n if (!opened) {\n read.unresolved.add('unreadable', shown)\n continue\n }\n const name = opened.input.name ?? shown\n if (reading.has(name)) continue\n let nested = read.loaded.get(name)\n if (!nested) {\n nested = await loadImports(opened.doc, opened.input, read, shown, new Set([...reading, name]))\n read.loaded.set(name, nested)\n }\n loaded.imports.set(alias, importedDocument(alias, path, opened.doc, nested.imports))\n loaded.opened.set(alias, { input: opened.input, imports: nested.opened })\n }\n return loaded\n}\n\n/**\n * The documents `doc` imports, opened through `input`, which `doc` was read from, with the\n * documents they import in turn. An import the host cannot open or that is no `.pen` document is\n * left out and reported to `unresolved`, by its path as `doc` writes it, or for an import's own\n * imports as it resolves from `doc`. The host's name for `doc` is the path its imports resolve\n * to, so an import that leads back to it is recognized.\n */\nexport function loadPenImports(\n doc: PenDocument,\n input: ReadDocumentInput,\n unresolved: UnresolvedImports\n): Promise<LoadedImports> {\n const read: ImportRead = { unresolved, opened: new Map(), loaded: new Map() }\n return loadImports(doc, input, read, '', new Set([input.name ?? '']))\n}\n\n/**\n * The bytes of an image an imported document draws, by the name `buildPenGraph` reads it with,\n * read beside the document that names it; null when no import has it or the host cannot read it.\n */\nexport async function readImportedImage(\n opened: ReadonlyMap<string, OpenedImport>,\n url: string\n): Promise<Uint8Array | null> {\n const parsed = parseImportedImageURL(url)\n const source = parsed ? opened.get(parsed.alias) : undefined\n if (!parsed || !source) return null\n if (parseImportedImageURL(parsed.url)) return readImportedImage(source.imports, parsed.url)\n return (await source.input.readAsset?.(parsed.url).catch(() => null)) ?? null\n}\n"],"mappings":"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"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/io/formats/pen/index.ts"],"mappings":";;cAmIa,WAAW"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/io/formats/pen/index.ts"],"mappings":";;cAoJa,WAAW"}