@pairdraw/core 0.20.0 → 0.21.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (539) hide show
  1. package/dist/canvas/noise/render.js +1 -1
  2. package/dist/canvas/noise/render.js.map +1 -1
  3. package/dist/canvas/noise/shader.d.ts +6 -3
  4. package/dist/canvas/noise/shader.d.ts.map +1 -1
  5. package/dist/canvas/noise/shader.js +12 -7
  6. package/dist/canvas/noise/shader.js.map +1 -1
  7. package/dist/canvas/noise/tile.d.ts.map +1 -1
  8. package/dist/canvas/noise/tile.js +2 -1
  9. package/dist/canvas/noise/tile.js.map +1 -1
  10. package/dist/canvas/renderer/colors.d.ts +20 -5
  11. package/dist/canvas/renderer/colors.d.ts.map +1 -1
  12. package/dist/canvas/renderer/colors.js +48 -42
  13. package/dist/canvas/renderer/colors.js.map +1 -1
  14. package/dist/canvas/renderer/document-surface.d.ts +25 -0
  15. package/dist/canvas/renderer/document-surface.d.ts.map +1 -0
  16. package/dist/canvas/renderer/document-surface.js +46 -0
  17. package/dist/canvas/renderer/document-surface.js.map +1 -0
  18. package/dist/canvas/renderer/fonts.d.ts.map +1 -1
  19. package/dist/canvas/renderer/fonts.js +6 -4
  20. package/dist/canvas/renderer/fonts.js.map +1 -1
  21. package/dist/canvas/renderer/lifecycle.js +4 -3
  22. package/dist/canvas/renderer/lifecycle.js.map +1 -1
  23. package/dist/canvas/renderer/methods.d.ts.map +1 -1
  24. package/dist/canvas/renderer/methods.js +1 -0
  25. package/dist/canvas/renderer/methods.js.map +1 -1
  26. package/dist/canvas/renderer/pipeline.d.ts.map +1 -1
  27. package/dist/canvas/renderer/pipeline.js +23 -2
  28. package/dist/canvas/renderer/pipeline.js.map +1 -1
  29. package/dist/canvas/renderer/retained-backing.d.ts.map +1 -1
  30. package/dist/canvas/renderer/retained-backing.js +2 -1
  31. package/dist/canvas/renderer/retained-backing.js.map +1 -1
  32. package/dist/canvas/renderer/tiles/surface-pool.d.ts.map +1 -1
  33. package/dist/canvas/renderer/tiles/surface-pool.js +2 -7
  34. package/dist/canvas/renderer/tiles/surface-pool.js.map +1 -1
  35. package/dist/canvas/renderer.d.ts +20 -2
  36. package/dist/canvas/renderer.d.ts.map +1 -1
  37. package/dist/canvas/renderer.js +28 -4
  38. package/dist/canvas/renderer.js.map +1 -1
  39. package/dist/canvas/scene.d.ts.map +1 -1
  40. package/dist/canvas/scene.js +4 -3
  41. package/dist/canvas/scene.js.map +1 -1
  42. package/dist/canvas/shaders/compile.d.ts +3 -1
  43. package/dist/canvas/shaders/compile.d.ts.map +1 -1
  44. package/dist/canvas/shaders/compile.js +12 -3
  45. package/dist/canvas/shaders/compile.js.map +1 -1
  46. package/dist/canvas/shaders/draw.d.ts.map +1 -1
  47. package/dist/canvas/shaders/draw.js +10 -3
  48. package/dist/canvas/shaders/draw.js.map +1 -1
  49. package/dist/canvas/shaders/effect.d.ts.map +1 -1
  50. package/dist/canvas/shaders/effect.js +8 -17
  51. package/dist/canvas/shaders/effect.js.map +1 -1
  52. package/dist/canvas/shadows/shape.d.ts.map +1 -1
  53. package/dist/canvas/shadows/shape.js +4 -2
  54. package/dist/canvas/shadows/shape.js.map +1 -1
  55. package/dist/canvas/shadows.d.ts.map +1 -1
  56. package/dist/canvas/shadows.js +4 -2
  57. package/dist/canvas/shadows.js.map +1 -1
  58. package/dist/canvas/text/decorations.d.ts +2 -2
  59. package/dist/canvas/text/decorations.d.ts.map +1 -1
  60. package/dist/canvas/text/decorations.js +5 -5
  61. package/dist/canvas/text/decorations.js.map +1 -1
  62. package/dist/canvas/text/index.js +1 -1
  63. package/dist/canvas/text/index.js.map +1 -1
  64. package/dist/canvas/text/paragraph/index.d.ts +2 -2
  65. package/dist/canvas/text/paragraph/index.d.ts.map +1 -1
  66. package/dist/canvas/text/paragraph/index.js +16 -5
  67. package/dist/canvas/text/paragraph/index.js.map +1 -1
  68. package/dist/canvas/text/renderer.d.ts +2 -1
  69. package/dist/canvas/text/renderer.d.ts.map +1 -1
  70. package/dist/canvas/text/shape.js +4 -4
  71. package/dist/canvas/text/shape.js.map +1 -1
  72. package/dist/canvas/texture.d.ts.map +1 -1
  73. package/dist/canvas/texture.js +2 -1
  74. package/dist/canvas/texture.js.map +1 -1
  75. package/dist/design-memory/rules.js +1 -1
  76. package/dist/editor/clipboard/assets.d.ts.map +1 -1
  77. package/dist/editor/clipboard/assets.js +2 -2
  78. package/dist/editor/clipboard/assets.js.map +1 -1
  79. package/dist/editor/clipboard/component-matches.d.ts +13 -0
  80. package/dist/editor/clipboard/component-matches.d.ts.map +1 -0
  81. package/dist/editor/clipboard/component-matches.js +50 -0
  82. package/dist/editor/clipboard/component-matches.js.map +1 -0
  83. package/dist/editor/clipboard/dependencies.d.ts +7 -0
  84. package/dist/editor/clipboard/dependencies.d.ts.map +1 -1
  85. package/dist/editor/clipboard/dependencies.js +5 -0
  86. package/dist/editor/clipboard/dependencies.js.map +1 -1
  87. package/dist/editor/clipboard/export.js +2 -2
  88. package/dist/editor/clipboard/export.js.map +1 -1
  89. package/dist/editor/clipboard.d.ts.map +1 -1
  90. package/dist/editor/clipboard.js +48 -19
  91. package/dist/editor/clipboard.js.map +1 -1
  92. package/dist/editor/components/properties.d.ts.map +1 -1
  93. package/dist/editor/components/properties.js +3 -3
  94. package/dist/editor/components/properties.js.map +1 -1
  95. package/dist/editor/eyedropper.d.ts +1 -1
  96. package/dist/editor/eyedropper.d.ts.map +1 -1
  97. package/dist/editor/eyedropper.js +6 -3
  98. package/dist/editor/eyedropper.js.map +1 -1
  99. package/dist/editor/history/atomic-tool.d.ts.map +1 -1
  100. package/dist/editor/history/atomic-tool.js +3 -2
  101. package/dist/editor/history/atomic-tool.js.map +1 -1
  102. package/dist/editor/shapes/pencil.js +1 -1
  103. package/dist/editor/structure/state.d.ts.map +1 -1
  104. package/dist/editor/structure/state.js +2 -2
  105. package/dist/editor/structure/state.js.map +1 -1
  106. package/dist/editor/text.d.ts.map +1 -1
  107. package/dist/editor/text.js +2 -2
  108. package/dist/editor/text.js.map +1 -1
  109. package/dist/editor/variables.js +3 -3
  110. package/dist/editor/variables.js.map +1 -1
  111. package/dist/figma-api/fresh-read.d.ts +15 -0
  112. package/dist/figma-api/fresh-read.d.ts.map +1 -0
  113. package/dist/figma-api/fresh-read.js +54 -0
  114. package/dist/figma-api/fresh-read.js.map +1 -0
  115. package/dist/figma-api/graph-ref.d.ts +9 -0
  116. package/dist/figma-api/graph-ref.d.ts.map +1 -0
  117. package/dist/figma-api/graph-ref.js +14 -0
  118. package/dist/figma-api/graph-ref.js.map +1 -0
  119. package/dist/figma-api/index.d.ts +6 -1
  120. package/dist/figma-api/index.d.ts.map +1 -1
  121. package/dist/figma-api/index.js +12 -5
  122. package/dist/figma-api/index.js.map +1 -1
  123. package/dist/figma-api/pending-layout.d.ts +3 -3
  124. package/dist/figma-api/pending-layout.d.ts.map +1 -1
  125. package/dist/figma-api/pending-layout.js +7 -3
  126. package/dist/figma-api/pending-layout.js.map +1 -1
  127. package/dist/figma-api/pending-sync.d.ts +1 -1
  128. package/dist/figma-api/pending-sync.d.ts.map +1 -1
  129. package/dist/figma-api/pending-sync.js +3 -1
  130. package/dist/figma-api/pending-sync.js.map +1 -1
  131. package/dist/figma-api/proxy.d.ts.map +1 -1
  132. package/dist/figma-api/proxy.js +3 -2
  133. package/dist/figma-api/proxy.js.map +1 -1
  134. package/dist/figma-api/reactions.d.ts +20 -4
  135. package/dist/figma-api/reactions.d.ts.map +1 -1
  136. package/dist/figma-api/reactions.js +49 -3
  137. package/dist/figma-api/reactions.js.map +1 -1
  138. package/dist/figma-api/variables/index.d.ts.map +1 -1
  139. package/dist/figma-api/variables/index.js +2 -2
  140. package/dist/figma-api/variables/index.js.map +1 -1
  141. package/dist/io/formats/design-tokens/css/known.js +1 -1
  142. package/dist/io/formats/design-tokens/css/known.js.map +1 -1
  143. package/dist/io/formats/design-tokens/css/read.d.ts +3 -1
  144. package/dist/io/formats/design-tokens/css/read.d.ts.map +1 -1
  145. package/dist/io/formats/design-tokens/css/read.js +11 -5
  146. package/dist/io/formats/design-tokens/css/read.js.map +1 -1
  147. package/dist/io/formats/design-tokens/css/sync.d.ts.map +1 -1
  148. package/dist/io/formats/design-tokens/css/sync.js +17 -4
  149. package/dist/io/formats/design-tokens/css/sync.js.map +1 -1
  150. package/dist/io/formats/design-tokens/css/values.d.ts +6 -5
  151. package/dist/io/formats/design-tokens/css/values.d.ts.map +1 -1
  152. package/dist/io/formats/design-tokens/css/values.js +24 -8
  153. package/dist/io/formats/design-tokens/css/values.js.map +1 -1
  154. package/dist/io/formats/design-tokens/decode.d.ts +7 -6
  155. package/dist/io/formats/design-tokens/decode.d.ts.map +1 -1
  156. package/dist/io/formats/design-tokens/decode.js +13 -12
  157. package/dist/io/formats/design-tokens/decode.js.map +1 -1
  158. package/dist/io/formats/design-tokens/export.js +3 -3
  159. package/dist/io/formats/design-tokens/export.js.map +1 -1
  160. package/dist/io/formats/design-tokens/plan/index.d.ts.map +1 -1
  161. package/dist/io/formats/design-tokens/plan/index.js +4 -3
  162. package/dist/io/formats/design-tokens/plan/index.js.map +1 -1
  163. package/dist/io/formats/design-tokens/plan/styles.d.ts.map +1 -1
  164. package/dist/io/formats/design-tokens/plan/styles.js +9 -9
  165. package/dist/io/formats/design-tokens/plan/styles.js.map +1 -1
  166. package/dist/io/formats/design-tokens/styles.d.ts +4 -4
  167. package/dist/io/formats/design-tokens/styles.d.ts.map +1 -1
  168. package/dist/io/formats/design-tokens/styles.js +7 -7
  169. package/dist/io/formats/design-tokens/styles.js.map +1 -1
  170. package/dist/io/formats/design-tokens/sync/drift.js +2 -2
  171. package/dist/io/formats/design-tokens/sync/drift.js.map +1 -1
  172. package/dist/io/formats/design-tokens/values.d.ts +10 -5
  173. package/dist/io/formats/design-tokens/values.d.ts.map +1 -1
  174. package/dist/io/formats/design-tokens/values.js +13 -7
  175. package/dist/io/formats/design-tokens/values.js.map +1 -1
  176. package/dist/io/formats/drawio/label.js +1 -1
  177. package/dist/io/formats/drawio/paint.js +1 -1
  178. package/dist/io/formats/drawio/warnings.d.ts +17 -2
  179. package/dist/io/formats/drawio/warnings.d.ts.map +1 -1
  180. package/dist/io/formats/drawio/warnings.js +15 -8
  181. package/dist/io/formats/drawio/warnings.js.map +1 -1
  182. package/dist/io/formats/fig/export/index.d.ts.map +1 -1
  183. package/dist/io/formats/fig/export/index.js +15 -3
  184. package/dist/io/formats/fig/export/index.js.map +1 -1
  185. package/dist/io/formats/fig/export/patch/index.d.ts.map +1 -1
  186. package/dist/io/formats/fig/export/patch/index.js +2 -1
  187. package/dist/io/formats/fig/export/patch/index.js.map +1 -1
  188. package/dist/io/formats/fig/export/setup.d.ts +7 -2
  189. package/dist/io/formats/fig/export/setup.d.ts.map +1 -1
  190. package/dist/io/formats/fig/export/setup.js +12 -13
  191. package/dist/io/formats/fig/export/setup.js.map +1 -1
  192. package/dist/io/formats/fig/export/variables.d.ts.map +1 -1
  193. package/dist/io/formats/fig/export/variables.js +9 -7
  194. package/dist/io/formats/fig/export/variables.js.map +1 -1
  195. package/dist/io/formats/html/index.d.ts +1 -0
  196. package/dist/io/formats/html/index.d.ts.map +1 -1
  197. package/dist/io/formats/html/index.js +5 -3
  198. package/dist/io/formats/html/index.js.map +1 -1
  199. package/dist/io/formats/html/vectors.js +1 -0
  200. package/dist/io/formats/html/vectors.js.map +1 -1
  201. package/dist/io/formats/mermaid/layers.js +2 -2
  202. package/dist/io/formats/mermaid/layers.js.map +1 -1
  203. package/dist/io/formats/mermaid/styles.js +1 -1
  204. package/dist/io/formats/pdf/export.d.ts.map +1 -1
  205. package/dist/io/formats/pdf/export.js +1 -0
  206. package/dist/io/formats/pdf/export.js.map +1 -1
  207. package/dist/io/formats/pdf/prepare.d.ts +4 -4
  208. package/dist/io/formats/pdf/prepare.d.ts.map +1 -1
  209. package/dist/io/formats/pdf/prepare.js +2 -2
  210. package/dist/io/formats/pdf/prepare.js.map +1 -1
  211. package/dist/io/formats/pen/index.d.ts.map +1 -1
  212. package/dist/io/formats/pen/index.js +13 -2
  213. package/dist/io/formats/pen/index.js.map +1 -1
  214. package/dist/io/formats/pptx/style.js +1 -1
  215. package/dist/io/formats/raster/render.d.ts +1 -1
  216. package/dist/io/formats/raster/render.d.ts.map +1 -1
  217. package/dist/io/formats/raster/render.js +9 -4
  218. package/dist/io/formats/raster/render.js.map +1 -1
  219. package/dist/io/formats/svg/defs.d.ts +6 -3
  220. package/dist/io/formats/svg/defs.d.ts.map +1 -1
  221. package/dist/io/formats/svg/defs.js +12 -11
  222. package/dist/io/formats/svg/defs.js.map +1 -1
  223. package/dist/io/formats/svg/effects.js +2 -2
  224. package/dist/io/formats/svg/effects.js.map +1 -1
  225. package/dist/io/formats/svg/export.d.ts +5 -2
  226. package/dist/io/formats/svg/export.d.ts.map +1 -1
  227. package/dist/io/formats/svg/export.js +4 -2
  228. package/dist/io/formats/svg/export.js.map +1 -1
  229. package/dist/io/formats/svg/filter.d.ts +4 -1
  230. package/dist/io/formats/svg/filter.d.ts.map +1 -1
  231. package/dist/io/formats/svg/filter.js +6 -2
  232. package/dist/io/formats/svg/filter.js.map +1 -1
  233. package/dist/io/formats/svg/grain.js +1 -1
  234. package/dist/io/formats/svg/grain.js.map +1 -1
  235. package/dist/io/formats/svg/import.d.ts +4 -2
  236. package/dist/io/formats/svg/import.d.ts.map +1 -1
  237. package/dist/io/formats/svg/import.js +2 -1
  238. package/dist/io/formats/svg/import.js.map +1 -1
  239. package/dist/io/formats/svg/text/export.d.ts.map +1 -1
  240. package/dist/io/formats/svg/text/export.js +8 -8
  241. package/dist/io/formats/svg/text/export.js.map +1 -1
  242. package/dist/io/formats/svg/text/layout.js +2 -2
  243. package/dist/io/formats/svg/text/layout.js.map +1 -1
  244. package/dist/io/formats.d.ts.map +1 -1
  245. package/dist/io/formats.js +11 -4
  246. package/dist/io/formats.js.map +1 -1
  247. package/dist/io/index.d.ts +2 -2
  248. package/dist/io/subgraph.d.ts.map +1 -1
  249. package/dist/io/subgraph.js +1 -1
  250. package/dist/io/subgraph.js.map +1 -1
  251. package/dist/io/types.d.ts +12 -3
  252. package/dist/io/types.d.ts.map +1 -1
  253. package/dist/kiwi/fig/session/options.d.ts +3 -0
  254. package/dist/kiwi/fig/session/options.d.ts.map +1 -1
  255. package/dist/kiwi/fig/session/options.js +4 -0
  256. package/dist/kiwi/fig/session/options.js.map +1 -1
  257. package/dist/layout/yoga-helpers.d.ts +2 -1
  258. package/dist/layout/yoga-helpers.d.ts.map +1 -1
  259. package/dist/layout/yoga-helpers.js +7 -1
  260. package/dist/layout/yoga-helpers.js.map +1 -1
  261. package/dist/layout.js +24 -1
  262. package/dist/layout.js.map +1 -1
  263. package/dist/lint/fixes.js +1 -1
  264. package/dist/lint/linter.js +2 -2
  265. package/dist/lint/linter.js.map +1 -1
  266. package/dist/pairdraw-api/comments.d.ts +4 -1
  267. package/dist/pairdraw-api/comments.d.ts.map +1 -1
  268. package/dist/pairdraw-api/comments.js +5 -0
  269. package/dist/pairdraw-api/comments.js.map +1 -1
  270. package/dist/pairdraw-api/index.d.ts +3 -3
  271. package/dist/pairdraw-api/index.d.ts.map +1 -1
  272. package/dist/pairdraw-api/index.js +5 -5
  273. package/dist/pairdraw-api/index.js.map +1 -1
  274. package/dist/pairdraw-api/nodes.d.ts +1 -1
  275. package/dist/prototype/scene.js +1 -1
  276. package/dist/rpc/analyze-commands.js +1 -1
  277. package/dist/rpc/read-commands.d.ts +2 -2
  278. package/dist/rpc/read-commands.js +3 -3
  279. package/dist/rpc/read-commands.js.map +1 -1
  280. package/dist/rpc/variables-command.js +2 -2
  281. package/dist/rpc/variables-command.js.map +1 -1
  282. package/dist/text/font/provider.d.ts +15 -0
  283. package/dist/text/font/provider.d.ts.map +1 -0
  284. package/dist/text/font/provider.js +18 -0
  285. package/dist/text/font/provider.js.map +1 -0
  286. package/dist/text/font/readiness.d.ts +32 -0
  287. package/dist/text/font/readiness.d.ts.map +1 -0
  288. package/dist/text/font/{status.js → readiness.js} +8 -4
  289. package/dist/text/font/readiness.js.map +1 -0
  290. package/dist/text/index.d.ts +4 -3
  291. package/dist/text/index.js +4 -3
  292. package/dist/text/prepare.d.ts +9 -4
  293. package/dist/text/prepare.d.ts.map +1 -1
  294. package/dist/text/prepare.js +9 -4
  295. package/dist/text/prepare.js.map +1 -1
  296. package/dist/tools/analyze/colors.js +1 -1
  297. package/dist/tools/analyze/responsive/index.js +7 -18
  298. package/dist/tools/analyze/responsive/index.js.map +1 -1
  299. package/dist/tools/analyze/responsive/widths.d.ts +27 -0
  300. package/dist/tools/analyze/responsive/widths.d.ts.map +1 -0
  301. package/dist/tools/analyze/responsive/widths.js +49 -0
  302. package/dist/tools/analyze/responsive/widths.js.map +1 -0
  303. package/dist/tools/analyze.d.ts +2 -1
  304. package/dist/tools/analyze.js +2 -1
  305. package/dist/tools/codegen/tokens.d.ts.map +1 -1
  306. package/dist/tools/codegen/tokens.js +2 -2
  307. package/dist/tools/codegen/tokens.js.map +1 -1
  308. package/dist/tools/comments.d.ts.map +1 -1
  309. package/dist/tools/comments.js +2 -2
  310. package/dist/tools/comments.js.map +1 -1
  311. package/dist/tools/component-catalog.d.ts.map +1 -1
  312. package/dist/tools/component-catalog.js +5 -3
  313. package/dist/tools/component-catalog.js.map +1 -1
  314. package/dist/tools/create/basic.js +1 -1
  315. package/dist/tools/create/behaviours.js +1 -1
  316. package/dist/tools/create/html.d.ts.map +1 -1
  317. package/dist/tools/create/html.js +1 -3
  318. package/dist/tools/create/html.js.map +1 -1
  319. package/dist/tools/create/icons.js +2 -2
  320. package/dist/tools/create/icons.js.map +1 -1
  321. package/dist/tools/create/mermaid.js +1 -1
  322. package/dist/tools/create/render.js +1 -1
  323. package/dist/tools/create/svg.js +5 -2
  324. package/dist/tools/create/svg.js.map +1 -1
  325. package/dist/tools/create/vector.js +3 -3
  326. package/dist/tools/create/vector.js.map +1 -1
  327. package/dist/tools/css/shorthand.d.ts +20 -0
  328. package/dist/tools/css/shorthand.d.ts.map +1 -0
  329. package/dist/tools/css/shorthand.js +54 -0
  330. package/dist/tools/css/shorthand.js.map +1 -0
  331. package/dist/tools/describe/index.js +2 -2
  332. package/dist/tools/describe/index.js.map +1 -1
  333. package/dist/tools/describe/issues.js +1 -1
  334. package/dist/tools/html-host.d.ts.map +1 -1
  335. package/dist/tools/html-host.js +5 -3
  336. package/dist/tools/html-host.js.map +1 -1
  337. package/dist/tools/image-ai/apply.d.ts.map +1 -1
  338. package/dist/tools/image-ai/apply.js +1 -3
  339. package/dist/tools/image-ai/apply.js.map +1 -1
  340. package/dist/tools/image-ai/generate.js +1 -1
  341. package/dist/tools/image-ai/service.d.ts.map +1 -1
  342. package/dist/tools/image-ai/service.js +5 -3
  343. package/dist/tools/image-ai/service.js.map +1 -1
  344. package/dist/tools/index.d.ts +2 -1
  345. package/dist/tools/index.js +2 -1
  346. package/dist/tools/modify/effects.js +1 -1
  347. package/dist/tools/modify/effects.js.map +1 -1
  348. package/dist/tools/modify/geometry.d.ts.map +1 -1
  349. package/dist/tools/modify/geometry.js +14 -3
  350. package/dist/tools/modify/geometry.js.map +1 -1
  351. package/dist/tools/modify/layout.d.ts.map +1 -1
  352. package/dist/tools/modify/layout.js +35 -8
  353. package/dist/tools/modify/layout.js.map +1 -1
  354. package/dist/tools/modify/matching.d.ts.map +1 -1
  355. package/dist/tools/modify/matching.js +10 -10
  356. package/dist/tools/modify/matching.js.map +1 -1
  357. package/dist/tools/modify/paint.d.ts.map +1 -1
  358. package/dist/tools/modify/paint.js +57 -5
  359. package/dist/tools/modify/paint.js.map +1 -1
  360. package/dist/tools/modify/reactions.d.ts.map +1 -1
  361. package/dist/tools/modify/reactions.js +2 -2
  362. package/dist/tools/modify/reactions.js.map +1 -1
  363. package/dist/tools/modify/text.d.ts.map +1 -1
  364. package/dist/tools/modify/text.js +3 -3
  365. package/dist/tools/modify/text.js.map +1 -1
  366. package/dist/tools/prompts/codegen.js +1 -1
  367. package/dist/tools/prompts/codegen.js.map +1 -1
  368. package/dist/tools/read/css.d.ts +14 -0
  369. package/dist/tools/read/css.d.ts.map +1 -0
  370. package/dist/tools/read/css.js +306 -0
  371. package/dist/tools/read/css.js.map +1 -0
  372. package/dist/tools/read/libraries.js +1 -1
  373. package/dist/tools/read/reactions.js +1 -1
  374. package/dist/tools/read/reactions.js.map +1 -1
  375. package/dist/tools/read/space.d.ts.map +1 -1
  376. package/dist/tools/read/space.js +0 -2
  377. package/dist/tools/read/space.js.map +1 -1
  378. package/dist/tools/read.d.ts +2 -1
  379. package/dist/tools/read.js +2 -1
  380. package/dist/tools/registry/core.d.ts +1 -1
  381. package/dist/tools/registry/core.js +3 -1
  382. package/dist/tools/registry/core.js.map +1 -1
  383. package/dist/tools/schema.d.ts +6 -4
  384. package/dist/tools/schema.d.ts.map +1 -1
  385. package/dist/tools/schema.js +9 -5
  386. package/dist/tools/schema.js.map +1 -1
  387. package/dist/tools/script/host.d.ts.map +1 -1
  388. package/dist/tools/script/host.js +5 -3
  389. package/dist/tools/script/host.js.map +1 -1
  390. package/dist/tools/variables/collections.js +1 -1
  391. package/dist/tools/variables/collections.js.map +1 -1
  392. package/dist/tools/variables/values.d.ts.map +1 -1
  393. package/dist/tools/variables/values.js +4 -4
  394. package/dist/tools/variables/values.js.map +1 -1
  395. package/dist/tools/vector/vectorize.d.ts.map +1 -1
  396. package/dist/tools/vector/vectorize.js +6 -4
  397. package/dist/tools/vector/vectorize.js.map +1 -1
  398. package/dist/tools/video-host.d.ts.map +1 -1
  399. package/dist/tools/video-host.js +5 -3
  400. package/dist/tools/video-host.js.map +1 -1
  401. package/dist/vector/vectorize/svg/gradients.d.ts +2 -2
  402. package/dist/vector/vectorize/svg/gradients.d.ts.map +1 -1
  403. package/dist/vector/vectorize/svg/gradients.js +5 -5
  404. package/dist/vector/vectorize/svg/gradients.js.map +1 -1
  405. package/dist/vector/vectorize/svg/to-vectors.d.ts +3 -1
  406. package/dist/vector/vectorize/svg/to-vectors.d.ts.map +1 -1
  407. package/dist/vector/vectorize/svg/to-vectors.js +13 -12
  408. package/dist/vector/vectorize/svg/to-vectors.js.map +1 -1
  409. package/package.json +9 -9
  410. package/src/canvas/noise/render.ts +1 -1
  411. package/src/canvas/noise/shader.ts +13 -5
  412. package/src/canvas/noise/tile.ts +2 -1
  413. package/src/canvas/renderer/colors.ts +76 -50
  414. package/src/canvas/renderer/document-surface.ts +53 -0
  415. package/src/canvas/renderer/fonts.ts +6 -4
  416. package/src/canvas/renderer/lifecycle.ts +4 -4
  417. package/src/canvas/renderer/methods.ts +1 -0
  418. package/src/canvas/renderer/pipeline.ts +21 -3
  419. package/src/canvas/renderer/retained-backing.ts +2 -1
  420. package/src/canvas/renderer/tiles/surface-pool.ts +9 -7
  421. package/src/canvas/renderer.ts +36 -11
  422. package/src/canvas/scene.ts +4 -3
  423. package/src/canvas/shaders/compile.ts +14 -3
  424. package/src/canvas/shaders/draw.ts +11 -4
  425. package/src/canvas/shaders/effect.ts +8 -19
  426. package/src/canvas/shadows/shape.ts +4 -2
  427. package/src/canvas/shadows.ts +5 -2
  428. package/src/canvas/text/decorations.ts +15 -5
  429. package/src/canvas/text/index.ts +9 -1
  430. package/src/canvas/text/paragraph/index.ts +16 -6
  431. package/src/canvas/text/renderer.ts +2 -1
  432. package/src/canvas/text/shape.ts +4 -4
  433. package/src/canvas/texture.ts +2 -1
  434. package/src/editor/clipboard/assets.ts +6 -2
  435. package/src/editor/clipboard/component-matches.ts +65 -0
  436. package/src/editor/clipboard/dependencies.ts +22 -1
  437. package/src/editor/clipboard/export.ts +2 -2
  438. package/src/editor/clipboard.ts +74 -20
  439. package/src/editor/components/properties.ts +3 -2
  440. package/src/editor/eyedropper.ts +14 -4
  441. package/src/editor/history/atomic-tool.ts +3 -2
  442. package/src/editor/structure/state.ts +2 -1
  443. package/src/editor/text.ts +2 -1
  444. package/src/editor/variables.ts +3 -3
  445. package/src/figma-api/fresh-read.ts +57 -0
  446. package/src/figma-api/graph-ref.ts +13 -0
  447. package/src/figma-api/index.ts +12 -4
  448. package/src/figma-api/pending-layout.ts +7 -3
  449. package/src/figma-api/pending-sync.ts +4 -1
  450. package/src/figma-api/proxy.ts +2 -1
  451. package/src/figma-api/reactions.ts +91 -10
  452. package/src/figma-api/variables/index.ts +5 -4
  453. package/src/io/formats/design-tokens/css/known.ts +1 -1
  454. package/src/io/formats/design-tokens/css/read.ts +20 -7
  455. package/src/io/formats/design-tokens/css/sync.ts +9 -4
  456. package/src/io/formats/design-tokens/css/values.ts +37 -9
  457. package/src/io/formats/design-tokens/decode.ts +17 -12
  458. package/src/io/formats/design-tokens/export.ts +3 -3
  459. package/src/io/formats/design-tokens/plan/index.ts +6 -5
  460. package/src/io/formats/design-tokens/plan/styles.ts +37 -10
  461. package/src/io/formats/design-tokens/styles.ts +10 -7
  462. package/src/io/formats/design-tokens/sync/drift.ts +6 -4
  463. package/src/io/formats/design-tokens/values.ts +15 -8
  464. package/src/io/formats/drawio/warnings.ts +28 -9
  465. package/src/io/formats/fig/export/index.ts +36 -3
  466. package/src/io/formats/fig/export/patch/index.ts +4 -1
  467. package/src/io/formats/fig/export/setup.ts +25 -15
  468. package/src/io/formats/fig/export/variables.ts +17 -6
  469. package/src/io/formats/html/index.ts +9 -3
  470. package/src/io/formats/html/vectors.ts +1 -0
  471. package/src/io/formats/mermaid/layers.ts +2 -2
  472. package/src/io/formats/pdf/export.ts +1 -0
  473. package/src/io/formats/pdf/prepare.ts +6 -6
  474. package/src/io/formats/pen/index.ts +15 -4
  475. package/src/io/formats/raster/render.ts +12 -4
  476. package/src/io/formats/svg/defs.ts +26 -14
  477. package/src/io/formats/svg/effects.ts +2 -2
  478. package/src/io/formats/svg/export.ts +17 -3
  479. package/src/io/formats/svg/filter.ts +12 -2
  480. package/src/io/formats/svg/grain.ts +1 -1
  481. package/src/io/formats/svg/import.ts +6 -3
  482. package/src/io/formats/svg/text/export.ts +10 -8
  483. package/src/io/formats/svg/text/layout.ts +2 -2
  484. package/src/io/formats.ts +18 -5
  485. package/src/io/index.ts +1 -0
  486. package/src/io/subgraph.ts +4 -1
  487. package/src/io/types.ts +10 -0
  488. package/src/kiwi/fig/session/options.ts +4 -1
  489. package/src/layout/yoga-helpers.ts +8 -0
  490. package/src/layout.ts +47 -1
  491. package/src/lint/linter.ts +1 -1
  492. package/src/pairdraw-api/comments.ts +6 -0
  493. package/src/pairdraw-api/index.ts +7 -9
  494. package/src/rpc/read-commands.ts +4 -4
  495. package/src/rpc/variables-command.ts +2 -2
  496. package/src/text/font/provider.ts +26 -0
  497. package/src/text/font/{status.ts → readiness.ts} +13 -9
  498. package/src/text/index.ts +2 -1
  499. package/src/text/prepare.ts +9 -4
  500. package/src/tools/analyze/responsive/index.ts +8 -15
  501. package/src/tools/analyze/responsive/widths.ts +63 -0
  502. package/src/tools/analyze.ts +2 -0
  503. package/src/tools/codegen/tokens.ts +4 -2
  504. package/src/tools/comments.ts +6 -4
  505. package/src/tools/component-catalog.ts +5 -3
  506. package/src/tools/create/html.ts +0 -3
  507. package/src/tools/create/icons.ts +1 -1
  508. package/src/tools/create/svg.ts +4 -1
  509. package/src/tools/create/vector.ts +2 -2
  510. package/src/tools/css/shorthand.ts +64 -0
  511. package/src/tools/describe/index.ts +2 -8
  512. package/src/tools/html-host.ts +5 -3
  513. package/src/tools/image-ai/apply.ts +0 -2
  514. package/src/tools/image-ai/service.ts +5 -3
  515. package/src/tools/index.ts +2 -0
  516. package/src/tools/modify/effects.ts +1 -1
  517. package/src/tools/modify/geometry.ts +16 -3
  518. package/src/tools/modify/layout.ts +47 -13
  519. package/src/tools/modify/matching.ts +14 -11
  520. package/src/tools/modify/paint.ts +85 -5
  521. package/src/tools/modify/reactions.ts +3 -2
  522. package/src/tools/modify/text.ts +15 -11
  523. package/src/tools/prompts/codegen.md +2 -1
  524. package/src/tools/read/css.ts +365 -0
  525. package/src/tools/read/reactions.ts +3 -2
  526. package/src/tools/read/space.ts +0 -2
  527. package/src/tools/read.ts +1 -0
  528. package/src/tools/registry/core.ts +3 -2
  529. package/src/tools/schema.ts +14 -5
  530. package/src/tools/script/host.ts +6 -3
  531. package/src/tools/variables/collections.ts +1 -1
  532. package/src/tools/variables/values.ts +16 -5
  533. package/src/tools/vector/vectorize.ts +10 -4
  534. package/src/tools/video-host.ts +5 -3
  535. package/src/vector/vectorize/svg/gradients.ts +8 -5
  536. package/src/vector/vectorize/svg/to-vectors.ts +48 -14
  537. package/dist/text/font/status.d.ts +0 -28
  538. package/dist/text/font/status.d.ts.map +0 -1
  539. package/dist/text/font/status.js.map +0 -1
@@ -1,7 +1,7 @@
1
- import { documentFontStatus } from "../text/font/status.js";
1
+ import { readFontReadiness } from "../text/font/readiness.js";
2
+ import { describeDesignMemory } from "../design-memory/describe.js";
2
3
  import { exposeInstanceSwap } from "../figma-api/components.js";
3
4
  import { writeVariableValue } from "../figma-api/variables/variable.js";
4
- import { describeDesignMemory } from "../design-memory/describe.js";
5
5
  import { BehaviourHandle, getBehaviour, makeSlot, nodeOf, setBehaviour } from "./behaviours.js";
6
6
  import { CommentHandle, DEFAULT_COMMENT_AUTHOR, addComment, getComment, getComments } from "./comments.js";
7
7
  import { checkProposedDesignValues, recordDesignDecision } from "./design-memory.js";
@@ -31,10 +31,10 @@ var PairdrawAPI = class {
31
31
  */
32
32
  setVariableFormula(collectionName, variableName, source, modeName) {
33
33
  const graph = this.figma.graph;
34
- const collections = [...graph.variableCollections.values()].filter((item) => item.name === collectionName);
34
+ const collections = graph.getLiveCollections().filter((item) => item.name === collectionName);
35
35
  const collection = collections.at(0);
36
36
  if (!collection || collections.length !== 1) throw new Error(`Unknown or ambiguous collection: ${collectionName}`);
37
- const variables = [...graph.variables.values()].filter((item) => item.collectionId === collection.id && item.name === variableName);
37
+ const variables = graph.getLiveVariables().filter((item) => item.collectionId === collection.id && item.name === variableName);
38
38
  const variable = variables.at(0);
39
39
  if (!variable || variables.length !== 1) throw new Error(`Unknown or ambiguous variable: ${variableName}`);
40
40
  const modes = collection.modes.filter((mode) => modeName ? mode.name === modeName : mode.modeId === collection.defaultModeId);
@@ -171,7 +171,7 @@ var PairdrawAPI = class {
171
171
  * loaded from, substitutions, why an installed face could not load, and the layers affected.
172
172
  */
173
173
  getFontStatus() {
174
- return documentFontStatus(this.figma.graph, this.figma.currentPageId);
174
+ return readFontReadiness(this.figma.graph, this.figma.currentPageId);
175
175
  }
176
176
  /** A fill's OkHCL color, which the color picker keeps beside its RGB, or null. */
177
177
  getFillOkHCL(node, index = 0) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/pairdraw-api/index.ts"],"sourcesContent":["import type { VariableLiteral } from '@pairdraw/scene-graph'\nimport {\n BEHAVIOUR_CONTRACTS,\n BEHAVIOUR_KINDS,\n type BehaviourKind,\n type BehaviourSpec\n} from '@pairdraw/scene-graph/behaviours'\nimport type { OkHCLColor, OkHCLPayload } from '@pairdraw/scene-graph/color'\nimport type { DesignMemoryGroup } from '@pairdraw/scene-graph/design-memory'\nimport { parseVariableFormula } from '@pairdraw/scene-graph/variables'\n\nimport {\n describeDesignMemory,\n type DesignMemoryReport,\n type DesignValueVerdict\n} from '#core/design-memory'\nimport { exposeInstanceSwap } from '#core/figma-api/components'\nimport type { FigmaAPI, FigmaNodeProxy } from '#core/figma-api/index'\nimport { writeVariableValue } from '#core/figma-api/variables'\nimport { documentFontStatus, type DocumentFontStatus } from '#core/text/font/status'\n\nimport {\n getBehaviour,\n makeSlot,\n nodeOf,\n setBehaviour,\n type BehaviourHandle,\n type NodeRef\n} from './behaviours'\nimport {\n addComment,\n getComment,\n getComments,\n type CommentFilter,\n type CommentHandle,\n type NewComment\n} from './comments'\nimport { checkProposedDesignValues, recordDesignDecision } from './design-memory'\nimport {\n readFillOkHCL,\n readLayoutDirection,\n readStrokeOkHCL,\n readTextDirection,\n writeFillOkHCL,\n writeFontFeatures,\n writeLayoutDirection,\n writeRangeFontFeatures,\n writeStrokeOkHCL,\n writeTextDirection\n} from './nodes'\nimport { getStatus, listStatuses, setStatus, type StatusInfo } from './statuses'\nimport { bindVariable, unbindVariable, type VariableRef } from './variables'\nimport {\n createVariationSet,\n getVariationSet,\n listVariationSets,\n type VariationSetHandle\n} from './variations'\n\nexport { BehaviourHandle, type NodeRef } from './behaviours'\nexport type { StatusInfo } from './statuses'\nexport type { VariableRef } from './variables'\nexport { VariationSetHandle, type VariationSetInfo } from './variations'\nexport {\n CommentHandle,\n DEFAULT_COMMENT_AUTHOR,\n type CommentFilter,\n type NewComment\n} from './comments'\n\n/**\n * What Pairdraw adds to the Figma Plugin API for scripts, as the `pairdraw` global next to\n * `figma`: features Figma has no API for, in the same style. It edits the same document as the\n * `figma` it is made for.\n */\nexport class PairdrawAPI {\n constructor(private readonly figma: FigmaAPI) {}\n\n /**\n * Set a token formula by collection, variable and optional mode names. References use\n * `{variable/name}` or `{Collection::variable/name}` and persist by ID; a true/false formula\n * can compare numbers, as in `{width} > 600 and not {loading}`, and `if()`, `text()` and\n * `truthy()` pick values, write text, and test text or numbers, as in\n * `if({compact}, \"Hi\", \"Hello, \" + {name})`.\n */\n setVariableFormula(\n collectionName: string,\n variableName: string,\n source: string,\n modeName?: string\n ): VariableLiteral {\n const graph = this.figma.graph\n const collections = [...graph.variableCollections.values()].filter(\n (item) => item.name === collectionName\n )\n const collection = collections.at(0)\n if (!collection || collections.length !== 1)\n throw new Error(`Unknown or ambiguous collection: ${collectionName}`)\n const variables = [...graph.variables.values()].filter(\n (item) => item.collectionId === collection.id && item.name === variableName\n )\n const variable = variables.at(0)\n if (!variable || variables.length !== 1)\n throw new Error(`Unknown or ambiguous variable: ${variableName}`)\n const modes = collection.modes.filter((mode) =>\n modeName ? mode.name === modeName : mode.modeId === collection.defaultModeId\n )\n const mode = modes.at(0)\n if (!mode || modes.length !== 1) throw new Error(`Unknown or ambiguous mode: ${modeName}`)\n const { value, resolved } = parseVariableFormula(graph, variable.id, mode.modeId, source)\n writeVariableValue(graph, variable, mode.modeId, value)\n return resolved\n }\n\n /**\n * Bind a layer field to a variable from `figma.variables`, as the layer panel does:\n * fields by Pairdraw's names, such as `'text'`, `'visible'`, `'opacity'` or `'fills/0/color'`.\n * Text content takes a text or number variable, a number shown as text; visibility takes a\n * boolean, or text that shows the layer unless it is empty or reads false, no or off.\n */\n bindVariable(node: NodeRef, field: string, variable: VariableRef): void {\n bindVariable(this.figma.graph, node, field, variable)\n }\n\n /** Let a layer field go of its variable, keeping the value the variable last gave it. */\n unbindVariable(node: NodeRef, field: string): void {\n unbindVariable(this.figma.graph, node, field)\n }\n\n /** The behaviour kinds, after Reka UI's primitives, with the values and parts each binds. */\n get behaviourKinds() {\n return BEHAVIOUR_KINDS.map((kind) => ({ kind, ...structuredClone(BEHAVIOUR_CONTRACTS[kind]) }))\n }\n\n /** The behaviour a node's main component keeps, or null; a variant reads its set's. */\n getBehaviour(node: NodeRef): BehaviourHandle | null {\n return getBehaviour(this.figma.graph, node)\n }\n\n /**\n * Give a main component or component set a behaviour, replacing any it has: a kind alone, or\n * a spec naming its properties and slots, such as\n * `{ kind: 'switch', values: { value: 'State' }, parts: { thumb: 'Thumb' }, states: 'Interaction' }`.\n */\n setBehaviour(node: NodeRef, spec: BehaviourKind | BehaviourSpec): BehaviourHandle {\n return setBehaviour(this.figma.graph, node, spec)\n }\n\n /** Make a frame of a main component a slot, as Create slot does; returns the slot's name. */\n createSlot(frame: NodeRef): string {\n return makeSlot(this.figma.graph, frame)\n }\n\n /**\n * The document's comment threads, oldest first: all of them, or only resolved or open ones,\n * one page's, or those a person started or replied to, such as `{ resolved: false }`.\n */\n getComments(filter?: CommentFilter): CommentHandle[] {\n return getComments(this.figma.graph, filter)\n }\n\n getComment(id: string): CommentHandle | null {\n return getComment(this.figma.graph, id)\n }\n\n /**\n * Leave a comment pinned on a layer, `{ node }`, which it then follows, or at a point of a\n * page, `{ page, x, y }`; the current page by default. `author` names who wrote it.\n */\n addComment(text: string, options?: NewComment): CommentHandle {\n return addComment(this.figma.graph, this.figma.currentPageId, text, options)\n }\n\n /**\n * The document's statuses, such as Ready for dev or the team's own Approved, with each one's\n * color and the status Figma shows for it, if any.\n */\n get statuses(): StatusInfo[] {\n return listStatuses(this.figma.graph)\n }\n\n /** The name of the status a section, frame, component, set or instance shows, or null. */\n getStatus(node: NodeRef): string | null {\n return getStatus(this.figma.graph, node)\n }\n\n /**\n * Give a layer one of the document's statuses by name, or clear it with null. Only sections,\n * frames, components, sets and instances directly on a page or in a section take one.\n */\n setStatus(node: NodeRef, status: string | null): void {\n setStatus(this.figma.graph, node, status)\n }\n\n /**\n * The document's design memory: the colors, fonts, sizes, spacing and radii agents may use,\n * whether an off-system value is refused or warned about, the decisions written down, and the\n * layers pinned as examples. Null when the document has none.\n */\n get designMemory(): DesignMemoryReport | null {\n return describeDesignMemory(this.figma.graph)\n }\n\n /**\n * Judge values before using them, such as `{ colors: ['#FF00AA'], spacing: [13] }`: each comes\n * back `ok`, `warn`, `refuse` or `invalid`, with the nearest allowed value.\n */\n checkDesignValues(\n proposal: Partial<Record<DesignMemoryGroup, readonly (string | number)[]>>\n ): DesignValueVerdict[] {\n return checkProposedDesignValues(this.figma.graph, proposal)\n }\n\n /**\n * Write a decision down in the design memory, optionally pinning a layer that shows it as an\n * example. The memory's allowed values stay as the person set them.\n */\n recordDesignDecision(text: string, example?: NodeRef): { decisions: number; examples: number } {\n return recordDesignDecision(this.figma.graph, text, example)\n }\n\n /**\n * Copy a layer `count` times (1 to 8) into a section of variations beside it, made the first\n * time; `labels` name what each version tries, as in `V2 · Calmer palette`. On a version, it\n * copies that version into its set. The original does not change.\n */\n createVariations(\n node: NodeRef,\n options: { count: number; labels?: readonly string[] }\n ): { set: VariationSetHandle; versions: FigmaNodeProxy[] } {\n const { set, created } = createVariationSet(this.figma, node, options)\n return { set, versions: created }\n }\n\n /** The set of variations a layer belongs to, from its section, a version or a layer inside one. */\n getVariations(node: NodeRef): VariationSetHandle | null {\n return getVariationSet(this.figma, node)\n }\n\n /** The sets of variations on the current page. */\n get variations(): VariationSetHandle[] {\n return listVariationSets(this.figma, this.figma.currentPageId)\n }\n\n /**\n * Expose a swap on instances as one INSTANCE_SWAP property, offering the candidate components;\n * returns the layer that holds the property.\n */\n exposeInstanceSwap(\n instances: readonly NodeRef[],\n candidates: readonly NodeRef[],\n propertyName = 'Instance'\n ): FigmaNodeProxy {\n const proxies = (refs: readonly NodeRef[]) =>\n refs.map((ref) => this.figma.wrapNode(nodeOf(this.figma.graph, ref).id))\n const host = exposeInstanceSwap(\n this.figma.graph,\n proxies(instances),\n proxies(candidates),\n propertyName\n )\n return this.figma.wrapNode(host.id)\n }\n\n /**\n * Whether the current page's fonts are faithfully available: requested faces, where each\n * loaded from, substitutions, why an installed face could not load, and the layers affected.\n */\n getFontStatus(): DocumentFontStatus {\n return documentFontStatus(this.figma.graph, this.figma.currentPageId)\n }\n\n /** A fill's OkHCL color, which the color picker keeps beside its RGB, or null. */\n getFillOkHCL(node: NodeRef, index = 0): OkHCLPayload | null {\n return readFillOkHCL(this.figma.graph, node, index)\n }\n\n /** Set a fill's color in OkHCL; its RGB follows in the document's color space. */\n setFillOkHCL(node: NodeRef, color: OkHCLColor, index = 0): void {\n writeFillOkHCL(this.figma.graph, node, color, index)\n }\n\n getStrokeOkHCL(node: NodeRef, index = 0): OkHCLPayload | null {\n return readStrokeOkHCL(this.figma.graph, node, index)\n }\n\n setStrokeOkHCL(node: NodeRef, color: OkHCLColor, index = 0): void {\n writeStrokeOkHCL(this.figma.graph, node, color, index)\n }\n\n /** Which way a frame's auto layout runs: `AUTO`, `LTR` or `RTL`. */\n getLayoutDirection(node: NodeRef): string {\n return readLayoutDirection(this.figma.graph, node)\n }\n\n setLayoutDirection(node: NodeRef, direction: string): void {\n writeLayoutDirection(this.figma.graph, node, direction)\n }\n\n /** Which way a text runs: `AUTO`, `LTR` or `RTL`. */\n getTextDirection(node: NodeRef): string {\n return readTextDirection(this.figma.graph, node)\n }\n\n setTextDirection(node: NodeRef, direction: string): void {\n writeTextDirection(this.figma.graph, node, direction)\n }\n\n /** Merges OpenType feature toggles into the text's own, keeping the tags it does not name. */\n setFontFeatures(node: NodeRef, features: Record<string, boolean>): void {\n writeFontFeatures(this.figma.graph, node, features)\n }\n\n /** Merges OpenType feature toggles into a text range's own, keeping its other features. */\n setRangeFontFeatures(\n node: NodeRef,\n start: number,\n end: number,\n features: Record<string, boolean>\n ): void {\n writeRangeFontFeatures(this.figma.graph, node, start, end, features)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA2EA,IAAa,cAAb,MAAyB;CACM;CAA7B,YAAY,OAAkC;EAAjB,KAAA,QAAA;CAAkB;;;;;;;;CAS/C,mBACE,gBACA,cACA,QACA,UACiB;EACjB,MAAM,QAAQ,KAAK,MAAM;EACzB,MAAM,cAAc,CAAC,GAAG,MAAM,oBAAoB,OAAO,CAAC,CAAC,CAAC,QACzD,SAAS,KAAK,SAAS,cAC1B;EACA,MAAM,aAAa,YAAY,GAAG,CAAC;EACnC,IAAI,CAAC,cAAc,YAAY,WAAW,GACxC,MAAM,IAAI,MAAM,oCAAoC,gBAAgB;EACtE,MAAM,YAAY,CAAC,GAAG,MAAM,UAAU,OAAO,CAAC,CAAC,CAAC,QAC7C,SAAS,KAAK,iBAAiB,WAAW,MAAM,KAAK,SAAS,YACjE;EACA,MAAM,WAAW,UAAU,GAAG,CAAC;EAC/B,IAAI,CAAC,YAAY,UAAU,WAAW,GACpC,MAAM,IAAI,MAAM,kCAAkC,cAAc;EAClE,MAAM,QAAQ,WAAW,MAAM,QAAQ,SACrC,WAAW,KAAK,SAAS,WAAW,KAAK,WAAW,WAAW,aACjE;EACA,MAAM,OAAO,MAAM,GAAG,CAAC;EACvB,IAAI,CAAC,QAAQ,MAAM,WAAW,GAAG,MAAM,IAAI,MAAM,8BAA8B,UAAU;EACzF,MAAM,EAAE,OAAO,aAAa,qBAAqB,OAAO,SAAS,IAAI,KAAK,QAAQ,MAAM;EACxF,mBAAmB,OAAO,UAAU,KAAK,QAAQ,KAAK;EACtD,OAAO;CACT;;;;;;;CAQA,aAAa,MAAe,OAAe,UAA6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AAO,MAAM,SAAS;CACtD;;CAGA,gBAAgB,MAAe,UAAyC;EACtE,kBAAkB,KAAK,MAAM,OAAO,MAAM,QAAQ;CACpD;;CAGA,qBACE,MACA,OACA,KACA,UACM;EACN,uBAAuB,KAAK,MAAM,OAAO,MAAM,OAAO,KAAK,QAAQ;CACrE;AACF"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/pairdraw-api/index.ts"],"sourcesContent":["import type { VariableLiteral } from '@pairdraw/scene-graph'\nimport {\n BEHAVIOUR_CONTRACTS,\n BEHAVIOUR_KINDS,\n type BehaviourKind,\n type BehaviourSpec\n} from '@pairdraw/scene-graph/behaviours'\nimport type { OkHCLColor, OkHCLPayload } from '@pairdraw/scene-graph/color'\nimport type { DesignMemoryGroup } from '@pairdraw/scene-graph/design-memory'\nimport { parseVariableFormula } from '@pairdraw/scene-graph/variables'\n\nimport {\n describeDesignMemory,\n type DesignMemoryReport,\n type DesignValueVerdict\n} from '#core/design-memory'\nimport { exposeInstanceSwap } from '#core/figma-api/components'\nimport type { FigmaAPI, FigmaNodeProxy } from '#core/figma-api/index'\nimport { writeVariableValue } from '#core/figma-api/variables'\nimport { readFontReadiness, type FontReadiness } from '#core/text/font/readiness'\n\nimport {\n getBehaviour,\n makeSlot,\n nodeOf,\n setBehaviour,\n type BehaviourHandle,\n type NodeRef\n} from './behaviours'\nimport {\n addComment,\n getComment,\n getComments,\n type CommentFilter,\n type CommentHandle,\n type NewComment\n} from './comments'\nimport { checkProposedDesignValues, recordDesignDecision } from './design-memory'\nimport {\n readFillOkHCL,\n readLayoutDirection,\n readStrokeOkHCL,\n readTextDirection,\n writeFillOkHCL,\n writeFontFeatures,\n writeLayoutDirection,\n writeRangeFontFeatures,\n writeStrokeOkHCL,\n writeTextDirection\n} from './nodes'\nimport { getStatus, listStatuses, setStatus, type StatusInfo } from './statuses'\nimport { bindVariable, unbindVariable, type VariableRef } from './variables'\nimport {\n createVariationSet,\n getVariationSet,\n listVariationSets,\n type VariationSetHandle\n} from './variations'\n\nexport { BehaviourHandle, type NodeRef } from './behaviours'\nexport type { StatusInfo } from './statuses'\nexport type { VariableRef } from './variables'\nexport { VariationSetHandle, type VariationSetInfo } from './variations'\nexport {\n CommentHandle,\n DEFAULT_COMMENT_AUTHOR,\n type CommentFilter,\n type NewComment\n} from './comments'\n\n/**\n * What Pairdraw adds to the Figma Plugin API for scripts, as the `pairdraw` global next to\n * `figma`: features Figma has no API for, in the same style. It edits the same document as the\n * `figma` it is made for.\n */\nexport class PairdrawAPI {\n constructor(private readonly figma: FigmaAPI) {}\n\n /**\n * Set a token formula by collection, variable and optional mode names. References use\n * `{variable/name}` or `{Collection::variable/name}` and persist by ID; a true/false formula\n * can compare numbers, as in `{width} > 600 and not {loading}`, and `if()`, `text()` and\n * `truthy()` pick values, write text, and test text or numbers, as in\n * `if({compact}, \"Hi\", \"Hello, \" + {name})`.\n */\n setVariableFormula(\n collectionName: string,\n variableName: string,\n source: string,\n modeName?: string\n ): VariableLiteral {\n const graph = this.figma.graph\n const collections = graph.getLiveCollections().filter((item) => item.name === collectionName)\n const collection = collections.at(0)\n if (!collection || collections.length !== 1)\n throw new Error(`Unknown or ambiguous collection: ${collectionName}`)\n const variables = graph\n .getLiveVariables()\n .filter((item) => item.collectionId === collection.id && item.name === variableName)\n const variable = variables.at(0)\n if (!variable || variables.length !== 1)\n throw new Error(`Unknown or ambiguous variable: ${variableName}`)\n const modes = collection.modes.filter((mode) =>\n modeName ? mode.name === modeName : mode.modeId === collection.defaultModeId\n )\n const mode = modes.at(0)\n if (!mode || modes.length !== 1) throw new Error(`Unknown or ambiguous mode: ${modeName}`)\n const { value, resolved } = parseVariableFormula(graph, variable.id, mode.modeId, source)\n writeVariableValue(graph, variable, mode.modeId, value)\n return resolved\n }\n\n /**\n * Bind a layer field to a variable from `figma.variables`, as the layer panel does:\n * fields by Pairdraw's names, such as `'text'`, `'visible'`, `'opacity'` or `'fills/0/color'`.\n * Text content takes a text or number variable, a number shown as text; visibility takes a\n * boolean, or text that shows the layer unless it is empty or reads false, no or off.\n */\n bindVariable(node: NodeRef, field: string, variable: VariableRef): void {\n bindVariable(this.figma.graph, node, field, variable)\n }\n\n /** Let a layer field go of its variable, keeping the value the variable last gave it. */\n unbindVariable(node: NodeRef, field: string): void {\n unbindVariable(this.figma.graph, node, field)\n }\n\n /** The behaviour kinds, after Reka UI's primitives, with the values and parts each binds. */\n get behaviourKinds() {\n return BEHAVIOUR_KINDS.map((kind) => ({ kind, ...structuredClone(BEHAVIOUR_CONTRACTS[kind]) }))\n }\n\n /** The behaviour a node's main component keeps, or null; a variant reads its set's. */\n getBehaviour(node: NodeRef): BehaviourHandle | null {\n return getBehaviour(this.figma.graph, node)\n }\n\n /**\n * Give a main component or component set a behaviour, replacing any it has: a kind alone, or\n * a spec naming its properties and slots, such as\n * `{ kind: 'switch', values: { value: 'State' }, parts: { thumb: 'Thumb' }, states: 'Interaction' }`.\n */\n setBehaviour(node: NodeRef, spec: BehaviourKind | BehaviourSpec): BehaviourHandle {\n return setBehaviour(this.figma.graph, node, spec)\n }\n\n /** Make a frame of a main component a slot, as Create slot does; returns the slot's name. */\n createSlot(frame: NodeRef): string {\n return makeSlot(this.figma.graph, frame)\n }\n\n /**\n * The document's comment threads, oldest first: all of them, or only resolved or open ones,\n * one page's, or those a person started or replied to, such as `{ resolved: false }`.\n */\n getComments(filter?: CommentFilter): CommentHandle[] {\n return getComments(this.figma.graph, filter)\n }\n\n getComment(id: string): CommentHandle | null {\n return getComment(this.figma.graph, id)\n }\n\n /**\n * Leave a comment pinned on a layer, `{ node }`, which it then follows, or at a point of a\n * page, `{ page, x, y }`; the current page by default. `author` names who wrote it.\n */\n addComment(text: string, options?: NewComment): CommentHandle {\n return addComment(this.figma.graph, this.figma.currentPageId, text, options)\n }\n\n /**\n * The document's statuses, such as Ready for dev or the team's own Approved, with each one's\n * color and the status Figma shows for it, if any.\n */\n get statuses(): StatusInfo[] {\n return listStatuses(this.figma.graph)\n }\n\n /** The name of the status a section, frame, component, set or instance shows, or null. */\n getStatus(node: NodeRef): string | null {\n return getStatus(this.figma.graph, node)\n }\n\n /**\n * Give a layer one of the document's statuses by name, or clear it with null. Only sections,\n * frames, components, sets and instances directly on a page or in a section take one.\n */\n setStatus(node: NodeRef, status: string | null): void {\n setStatus(this.figma.graph, node, status)\n }\n\n /**\n * The document's design memory: the colors, fonts, sizes, spacing and radii agents may use,\n * whether an off-system value is refused or warned about, the decisions written down, and the\n * layers pinned as examples. Null when the document has none.\n */\n get designMemory(): DesignMemoryReport | null {\n return describeDesignMemory(this.figma.graph)\n }\n\n /**\n * Judge values before using them, such as `{ colors: ['#FF00AA'], spacing: [13] }`: each comes\n * back `ok`, `warn`, `refuse` or `invalid`, with the nearest allowed value.\n */\n checkDesignValues(\n proposal: Partial<Record<DesignMemoryGroup, readonly (string | number)[]>>\n ): DesignValueVerdict[] {\n return checkProposedDesignValues(this.figma.graph, proposal)\n }\n\n /**\n * Write a decision down in the design memory, optionally pinning a layer that shows it as an\n * example. The memory's allowed values stay as the person set them.\n */\n recordDesignDecision(text: string, example?: NodeRef): { decisions: number; examples: number } {\n return recordDesignDecision(this.figma.graph, text, example)\n }\n\n /**\n * Copy a layer `count` times (1 to 8) into a section of variations beside it, made the first\n * time; `labels` name what each version tries, as in `V2 · Calmer palette`. On a version, it\n * copies that version into its set. The original does not change.\n */\n createVariations(\n node: NodeRef,\n options: { count: number; labels?: readonly string[] }\n ): { set: VariationSetHandle; versions: FigmaNodeProxy[] } {\n const { set, created } = createVariationSet(this.figma, node, options)\n return { set, versions: created }\n }\n\n /** The set of variations a layer belongs to, from its section, a version or a layer inside one. */\n getVariations(node: NodeRef): VariationSetHandle | null {\n return getVariationSet(this.figma, node)\n }\n\n /** The sets of variations on the current page. */\n get variations(): VariationSetHandle[] {\n return listVariationSets(this.figma, this.figma.currentPageId)\n }\n\n /**\n * Expose a swap on instances as one INSTANCE_SWAP property, offering the candidate components;\n * returns the layer that holds the property.\n */\n exposeInstanceSwap(\n instances: readonly NodeRef[],\n candidates: readonly NodeRef[],\n propertyName = 'Instance'\n ): FigmaNodeProxy {\n const proxies = (refs: readonly NodeRef[]) =>\n refs.map((ref) => this.figma.wrapNode(nodeOf(this.figma.graph, ref).id))\n const host = exposeInstanceSwap(\n this.figma.graph,\n proxies(instances),\n proxies(candidates),\n propertyName\n )\n return this.figma.wrapNode(host.id)\n }\n\n /**\n * Whether the current page's fonts are faithfully available: requested faces, where each\n * loaded from, substitutions, why an installed face could not load, and the layers affected.\n */\n getFontStatus(): FontReadiness {\n return readFontReadiness(this.figma.graph, this.figma.currentPageId)\n }\n\n /** A fill's OkHCL color, which the color picker keeps beside its RGB, or null. */\n getFillOkHCL(node: NodeRef, index = 0): OkHCLPayload | null {\n return readFillOkHCL(this.figma.graph, node, index)\n }\n\n /** Set a fill's color in OkHCL; its RGB follows in the document's color space. */\n setFillOkHCL(node: NodeRef, color: OkHCLColor, index = 0): void {\n writeFillOkHCL(this.figma.graph, node, color, index)\n }\n\n getStrokeOkHCL(node: NodeRef, index = 0): OkHCLPayload | null {\n return readStrokeOkHCL(this.figma.graph, node, index)\n }\n\n setStrokeOkHCL(node: NodeRef, color: OkHCLColor, index = 0): void {\n writeStrokeOkHCL(this.figma.graph, node, color, index)\n }\n\n /** Which way a frame's auto layout runs: `AUTO`, `LTR` or `RTL`. */\n getLayoutDirection(node: NodeRef): string {\n return readLayoutDirection(this.figma.graph, node)\n }\n\n setLayoutDirection(node: NodeRef, direction: string): void {\n writeLayoutDirection(this.figma.graph, node, direction)\n }\n\n /** Which way a text runs: `AUTO`, `LTR` or `RTL`. */\n getTextDirection(node: NodeRef): string {\n return readTextDirection(this.figma.graph, node)\n }\n\n setTextDirection(node: NodeRef, direction: string): void {\n writeTextDirection(this.figma.graph, node, direction)\n }\n\n /** Merges OpenType feature toggles into the text's own, keeping the tags it does not name. */\n setFontFeatures(node: NodeRef, features: Record<string, boolean>): void {\n writeFontFeatures(this.figma.graph, node, features)\n }\n\n /** Merges OpenType feature toggles into a text range's own, keeping its other features. */\n setRangeFontFeatures(\n node: NodeRef,\n start: number,\n end: number,\n features: Record<string, boolean>\n ): void {\n writeRangeFontFeatures(this.figma.graph, node, start, end, features)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA2EA,IAAa,cAAb,MAAyB;CACM;CAA7B,YAAY,OAAkC;EAAjB,KAAA,QAAA;CAAkB;;;;;;;;CAS/C,mBACE,gBACA,cACA,QACA,UACiB;EACjB,MAAM,QAAQ,KAAK,MAAM;EACzB,MAAM,cAAc,MAAM,mBAAmB,CAAC,CAAC,QAAQ,SAAS,KAAK,SAAS,cAAc;EAC5F,MAAM,aAAa,YAAY,GAAG,CAAC;EACnC,IAAI,CAAC,cAAc,YAAY,WAAW,GACxC,MAAM,IAAI,MAAM,oCAAoC,gBAAgB;EACtE,MAAM,YAAY,MACf,iBAAiB,CAAC,CAClB,QAAQ,SAAS,KAAK,iBAAiB,WAAW,MAAM,KAAK,SAAS,YAAY;EACrF,MAAM,WAAW,UAAU,GAAG,CAAC;EAC/B,IAAI,CAAC,YAAY,UAAU,WAAW,GACpC,MAAM,IAAI,MAAM,kCAAkC,cAAc;EAClE,MAAM,QAAQ,WAAW,MAAM,QAAQ,SACrC,WAAW,KAAK,SAAS,WAAW,KAAK,WAAW,WAAW,aACjE;EACA,MAAM,OAAO,MAAM,GAAG,CAAC;EACvB,IAAI,CAAC,QAAQ,MAAM,WAAW,GAAG,MAAM,IAAI,MAAM,8BAA8B,UAAU;EACzF,MAAM,EAAE,OAAO,aAAa,qBAAqB,OAAO,SAAS,IAAI,KAAK,QAAQ,MAAM;EACxF,mBAAmB,OAAO,UAAU,KAAK,QAAQ,KAAK;EACtD,OAAO;CACT;;;;;;;CAQA,aAAa,MAAe,OAAe,UAA6B;EACtE,aAAa,KAAK,MAAM,OAAO,MAAM,OAAO,QAAQ;CACtD;;CAGA,eAAe,MAAe,OAAqB;EACjD,eAAe,KAAK,MAAM,OAAO,MAAM,KAAK;C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KACA,UACM;EACN,uBAAuB,KAAK,MAAM,OAAO,MAAM,OAAO,KAAK,QAAQ;CACrE;AACF"}
@@ -1,6 +1,6 @@
1
1
  import { NodeRef } from "./behaviours.js";
2
- import { LayoutDirection, SceneGraph, TextDirection } from "@pairdraw/scene-graph";
3
2
  import { OkHCLColor, OkHCLPayload } from "@pairdraw/scene-graph/color";
3
+ import { LayoutDirection, SceneGraph, TextDirection } from "@pairdraw/scene-graph";
4
4
  //#region src/pairdraw-api/nodes.d.ts
5
5
  declare function readFillOkHCL(graph: SceneGraph, ref: NodeRef, index: number): OkHCLPayload | null;
6
6
  declare function writeFillOkHCL(graph: SceneGraph, ref: NodeRef, color: OkHCLColor, index: number): void;
@@ -1,7 +1,7 @@
1
1
  import { extractPageContext, findPageId } from "../io/subgraph.js";
2
2
  import { computeAllLayouts, computeLayout } from "../layout.js";
3
- import { withoutInheritedCopies } from "./reactions.js";
4
3
  import { reflow } from "../editor/play/states.js";
4
+ import { withoutInheritedCopies } from "./reactions.js";
5
5
  import { instanceMainComponent } from "@pairdraw/scene-graph/instances";
6
6
  import { variantInstanceFor } from "@pairdraw/scene-graph/components";
7
7
  //#region src/prototype/scene.ts
@@ -1,7 +1,7 @@
1
1
  import { computeOverlaps } from "../tools/analyze/overlaps/index.js";
2
+ import { colorDistance, colorToHex } from "@pairdraw/scene-graph/color";
2
3
  import { formatTextLength } from "@pairdraw/scene-graph/text";
3
4
  import { orderBy, sortBy } from "es-toolkit/array";
4
- import { colorDistance, colorToHex } from "@pairdraw/scene-graph/color";
5
5
  //#region src/rpc/analyze-commands.ts
6
6
  function clusterColors(colors, threshold) {
7
7
  const clusters = [];
@@ -1,4 +1,4 @@
1
- import { DocumentFontStatus } from "../text/font/status.js";
1
+ import { FontReadiness } from "../text/font/readiness.js";
2
2
  import { RPCCommand } from "./types.js";
3
3
  import { BooleanOperation, MaskType } from "@pairdraw/scene-graph";
4
4
  //#region src/rpc/read-commands.d.ts
@@ -15,7 +15,7 @@ interface InfoResult {
15
15
  pageCounts: Record<string, number>;
16
16
  }
17
17
  declare const infoCommand: RPCCommand<void, InfoResult>;
18
- declare const fontStatusCommand: RPCCommand<void, DocumentFontStatus>;
18
+ declare const fontStatusCommand: RPCCommand<void, FontReadiness>;
19
19
  interface PageItem {
20
20
  id: string;
21
21
  name: string;
@@ -1,7 +1,7 @@
1
1
  import "../text/ellipsis.js";
2
- import { prepareGraphFonts } from "../text/prepare.js";
3
- import { shapeDetailFields } from "../figma-api/shape-details.js";
2
+ import { resolveFontReadiness } from "../text/prepare.js";
4
3
  import { queryByXPath } from "../xpath.js";
4
+ import { shapeDetailFields } from "../figma-api/shape-details.js";
5
5
  import { sumBy } from "es-toolkit";
6
6
  //#region src/rpc/read-commands.ts
7
7
  /** Walk descendants. Callback returns `false` to stop traversal. */
@@ -76,7 +76,7 @@ const fontStatusCommand = {
76
76
  name: "font-status",
77
77
  execute: async (graph) => {
78
78
  const pageIds = graph.getPages().map((page) => page.id);
79
- return prepareGraphFonts(graph, pageIds.length > 0 ? pageIds : [graph.rootId]);
79
+ return resolveFontReadiness(graph, pageIds.length > 0 ? pageIds : [graph.rootId]);
80
80
  }
81
81
  };
82
82
  const pagesCommand = {
@@ -1 +1 @@
1
- {"version":3,"file":"read-commands.js","names":[],"sources":["../../src/rpc/read-commands.ts"],"sourcesContent":["import { sumBy } from 'es-toolkit'\n\nimport type { BooleanOperation, MaskType, SceneGraph, SceneNode } from '@pairdraw/scene-graph'\n\nimport { shapeDetailFields } from '#core/figma-api/shape-details'\nimport { ELLIPSIS } from '#core/text/ellipsis'\nimport type { DocumentFontStatus } from '#core/text/font/status'\nimport { prepareGraphFonts } from '#core/text/prepare'\nimport { queryByXPath } from '#core/xpath'\n\nimport type { RPCCommand } from './types'\n\n/** Walk descendants. Callback returns `false` to stop traversal. */\nfunction walkNodes(graph: SceneGraph, rootId: string, fn: (node: SceneNode) => boolean): boolean {\n const node = graph.getNode(rootId)\n if (!node) return true\n if (!fn(node)) return false\n for (const childId of node.childIds) {\n if (!walkNodes(graph, childId, fn)) return false\n }\n return true\n}\n\n/** A page picked by its ID, `page_id`, or by its name, `page`; the ID wins when both are given. */\nexport interface PageArgs {\n page?: string\n page_id?: string\n}\n\n/** The pages `args` picks: the one it names, none when it names a missing page, else `fallback`. */\nfunction pickedPages(graph: SceneGraph, args: PageArgs, fallback: SceneNode[]): SceneNode[] {\n const pages = graph.getPages()\n if (args.page_id) return pages.filter((page) => page.id === args.page_id)\n if (args.page) return pages.filter((page) => page.name === args.page).slice(0, 1)\n return fallback\n}\n\nfunction missingPageError(graph: SceneGraph, args: PageArgs): string {\n const pages = graph.getPages()\n const [label, available] = args.page_id\n ? [args.page_id, pages.map((page) => page.id)]\n : [args.page ?? '', pages.map((page) => page.name)]\n return `Page \"${label}\" not found. Available: ${available.join(', ')}`\n}\n\nfunction countDescendants(graph: SceneGraph, rootId: string): number {\n let count = 0\n walkNodes(graph, rootId, () => {\n count++\n return true\n })\n return count\n}\n\nfunction countNodes(graph: SceneGraph, pageId: string): number {\n const page = graph.getNode(pageId)\n return page ? sumBy(page.childIds, (id) => countDescendants(graph, id)) : 0\n}\n\nfunction nodeFrame(node: SceneNode) {\n return {\n x: Math.round(node.x),\n y: Math.round(node.y),\n width: Math.round(node.width),\n height: Math.round(node.height)\n }\n}\n\n// ── info ──\n\nexport interface InfoResult {\n pages: number\n totalNodes: number\n types: Record<string, number>\n fonts: string[]\n pageCounts: Record<string, number>\n}\n\nexport const infoCommand: RPCCommand<void, InfoResult> = {\n name: 'info',\n execute: (graph) => {\n const pages = graph.getPages()\n let totalNodes = 0\n const types: Record<string, number> = {}\n const fonts = new Set<string>()\n const pageCounts: Record<string, number> = {}\n\n const countNode = (node: SceneNode) => {\n totalNodes++\n types[node.type] = (types[node.type] ?? 0) + 1\n if (node.fontFamily) fonts.add(node.fontFamily)\n return true\n }\n\n for (const page of pages) {\n const beforePage = totalNodes\n for (const cid of page.childIds) {\n walkNodes(graph, cid, countNode)\n }\n pageCounts[page.name] = totalNodes - beforePage\n }\n\n return { pages: pages.length, totalNodes, types, fonts: [...fonts].sort(), pageCounts }\n }\n}\n\nexport const fontStatusCommand: RPCCommand<void, DocumentFontStatus> = {\n name: 'font-status',\n execute: async (graph) => {\n const pageIds = graph.getPages().map((page) => page.id)\n return prepareGraphFonts(graph, pageIds.length > 0 ? pageIds : [graph.rootId])\n }\n}\n\n// ── pages ──\n\nexport interface PageItem {\n id: string\n name: string\n nodes: number\n}\n\nexport const pagesCommand: RPCCommand<void, PageItem[]> = {\n name: 'pages',\n execute: (graph) => {\n return graph.getPages().map((p) => ({ id: p.id, name: p.name, nodes: countNodes(graph, p.id) }))\n }\n}\n\n// ── tree ──\n\nexport interface TreeArgs extends PageArgs {\n depth?: number\n}\n\nexport interface TreeNodeResult {\n id: string\n name: string\n type: string\n x: number\n y: number\n width: number\n height: number\n children?: TreeNodeResult[]\n}\n\nfunction buildTreeNode(\n graph: SceneGraph,\n id: string,\n depth: number,\n maxDepth: number\n): TreeNodeResult | null {\n const node = graph.getNode(id)\n if (!node) return null\n const result: TreeNodeResult = {\n id: node.id,\n name: node.name,\n type: node.type,\n ...nodeFrame(node)\n }\n if (node.childIds.length > 0 && depth < maxDepth) {\n result.children = node.childIds\n .map((cid) => buildTreeNode(graph, cid, depth + 1, maxDepth))\n .filter((n): n is TreeNodeResult => n !== null)\n }\n return result\n}\n\nexport interface TreeResult {\n page: { id: string; name: string; type: string }\n children: TreeNodeResult[]\n}\n\nexport const treeCommand: RPCCommand<TreeArgs, TreeResult | { error: string }> = {\n name: 'tree',\n execute: (graph, args) => {\n const maxDepth = args.depth ?? Infinity\n const page = pickedPages(graph, args, graph.getPages().slice(0, 1)).at(0)\n if (!page) return { error: missingPageError(graph, args) }\n\n return {\n page: { id: page.id, name: page.name, type: page.type },\n children: page.childIds\n .map((cid) => buildTreeNode(graph, cid, 0, maxDepth))\n .filter((n): n is TreeNodeResult => n !== null)\n }\n }\n}\n\n// ── find ──\n\nexport interface FindArgs extends PageArgs {\n name?: string\n type?: string\n limit?: number\n}\n\nexport interface FindNodeResult {\n id: string\n name: string\n type: string\n width: number\n height: number\n}\n\nexport const findCommand: RPCCommand<FindArgs, FindNodeResult[]> = {\n name: 'find',\n execute: (graph, args) => {\n const max = args.limit ?? 100\n const namePattern = args.name?.toLowerCase()\n const typeFilter = args.type?.toUpperCase()\n const results: FindNodeResult[] = []\n\n const searchPage = (page: SceneNode) => {\n for (const cid of page.childIds) {\n const cont = walkNodes(graph, cid, (node) => {\n if (results.length >= max) return false\n const matchesName = !namePattern || node.name.toLowerCase().includes(namePattern)\n const matchesType = !typeFilter || node.type === typeFilter\n if (matchesName && matchesType) {\n results.push({\n id: node.id,\n name: node.name,\n type: node.type,\n width: Math.round(node.width),\n height: Math.round(node.height)\n })\n }\n return true\n })\n if (!cont) break\n }\n }\n\n for (const page of pickedPages(graph, args, graph.getPages())) searchPage(page)\n\n return results\n }\n}\n\n// ── query (xpath) ──\n\nexport interface QueryArgs extends PageArgs {\n selector: string\n limit?: number\n}\n\nexport interface QueryNodeResult {\n id: string\n name: string\n type: string\n x: number\n y: number\n width: number\n height: number\n}\n\nexport const queryCommand: RPCCommand<QueryArgs, QueryNodeResult[] | { error: string }> = {\n name: 'query',\n execute: async (graph, args) => {\n try {\n const nodes = await queryByXPath(graph, args.selector, {\n page: args.page,\n pageId: args.page_id,\n limit: args.limit\n })\n return nodes.map((n) => ({\n id: n.id,\n name: n.name,\n type: n.type,\n x: Math.round(n.x),\n y: Math.round(n.y),\n width: Math.round(n.width),\n height: Math.round(n.height)\n }))\n } catch (err) {\n return { error: `XPath error: ${err instanceof Error ? err.message : String(err)}` }\n }\n }\n}\n\n// ── node ──\n\nexport interface NodeArgs {\n id: string\n}\n\nexport interface NodeResult {\n id: string\n name: string\n type: string\n x: number\n y: number\n width: number\n height: number\n visible: boolean\n locked: boolean\n opacity: number\n rotation: number\n fills: unknown[]\n strokes: unknown[]\n effects: unknown[]\n cornerRadius?: number\n topLeftRadius?: number\n topRightRadius?: number\n bottomRightRadius?: number\n bottomLeftRadius?: number\n isMask?: boolean\n maskType?: MaskType\n booleanOperation?: BooleanOperation\n blendMode: string\n layoutMode: string\n layoutDirection: string\n fontFamily: string\n fontSize: number\n fontWeight: number\n textDirection: string\n text: string | null\n parent: { id: string; name: string; type: string } | null\n children: number\n boundVariables: Record<string, string>\n}\n\nexport const nodeCommand: RPCCommand<NodeArgs, NodeResult | { error: string }> = {\n name: 'node',\n execute: (graph, args) => {\n const node = graph.getNode(args.id)\n if (!node) return { error: `Node \"${args.id}\" not found` }\n\n const parent = node.parentId ? graph.getNode(node.parentId) : undefined\n const boundVars: Record<string, string> = {}\n for (const [field, varId] of Object.entries(node.boundVariables)) {\n const variable = graph.variables.get(varId)\n boundVars[field] = variable?.name ?? varId\n }\n return {\n id: node.id,\n name: node.name,\n type: node.type,\n ...nodeFrame(node),\n visible: node.visible,\n locked: node.locked,\n opacity: node.opacity,\n rotation: node.rotation,\n fills: node.fills,\n strokes: node.strokes,\n effects: node.effects,\n ...shapeDetailFields(node),\n blendMode: node.blendMode,\n layoutMode: node.layoutMode,\n layoutDirection: node.layoutDirection,\n fontFamily: node.fontFamily,\n fontSize: node.fontSize,\n fontWeight: node.fontWeight,\n textDirection: node.textDirection,\n text: (() => {\n if (!node.text.length) return null\n if (node.text.length > 200) return node.text.slice(0, 200) + ELLIPSIS\n return node.text\n })(),\n parent: parent ? { id: parent.id, name: parent.name, type: parent.type } : null,\n children: node.childIds.length,\n boundVariables: boundVars\n }\n }\n}\n"],"mappings":";;;;;;;AAaA,SAAS,UAAU,OAAmB,QAAgB,IAA2C;CAC/F,MAAM,OAAO,MAAM,QAAQ,MAAM;CACjC,IAAI,CAAC,MAAM,OAAO;CAClB,IAAI,CAAC,GAAG,IAAI,GAAG,OAAO;CACtB,KAAK,MAAM,WAAW,KAAK,UACzB,IAAI,CAAC,UAAU,OAAO,SAAS,EAAE,GAAG,OAAO;CAE7C,OAAO;AACT;;AASA,SAAS,YAA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AAK,QAAQ,OAAO;IAC9B,IAAI,KAAK,KAAK,SAAS,KAAK,OAAO,KAAK,KAAK,MAAM,GAAG,GAAG,IAAA;IACzD,OAAO,KAAK;GACd,EAAA,CAAG;GACH,QAAQ,SAAS;IAAE,IAAI,OAAO;IAAI,MAAM,OAAO;IAAM,MAAM,OAAO;GAAK,IAAI;GAC3E,UAAU,KAAK,SAAS;GACxB,gBAAgB;EAClB;CACF;AACF"}
1
+ {"version":3,"file":"read-commands.js","names":[],"sources":["../../src/rpc/read-commands.ts"],"sourcesContent":["import { sumBy } from 'es-toolkit'\n\nimport type { BooleanOperation, MaskType, SceneGraph, SceneNode } from '@pairdraw/scene-graph'\n\nimport { shapeDetailFields } from '#core/figma-api/shape-details'\nimport { ELLIPSIS } from '#core/text/ellipsis'\nimport type { FontReadiness } from '#core/text/font/readiness'\nimport { resolveFontReadiness } from '#core/text/prepare'\nimport { queryByXPath } from '#core/xpath'\n\nimport type { RPCCommand } from './types'\n\n/** Walk descendants. Callback returns `false` to stop traversal. */\nfunction walkNodes(graph: SceneGraph, rootId: string, fn: (node: SceneNode) => boolean): boolean {\n const node = graph.getNode(rootId)\n if (!node) return true\n if (!fn(node)) return false\n for (const childId of node.childIds) {\n if (!walkNodes(graph, childId, fn)) return false\n }\n return true\n}\n\n/** A page picked by its ID, `page_id`, or by its name, `page`; the ID wins when both are given. */\nexport interface PageArgs {\n page?: string\n page_id?: string\n}\n\n/** The pages `args` picks: the one it names, none when it names a missing page, else `fallback`. */\nfunction pickedPages(graph: SceneGraph, args: PageArgs, fallback: SceneNode[]): SceneNode[] {\n const pages = graph.getPages()\n if (args.page_id) return pages.filter((page) => page.id === args.page_id)\n if (args.page) return pages.filter((page) => page.name === args.page).slice(0, 1)\n return fallback\n}\n\nfunction missingPageError(graph: SceneGraph, args: PageArgs): string {\n const pages = graph.getPages()\n const [label, available] = args.page_id\n ? [args.page_id, pages.map((page) => page.id)]\n : [args.page ?? '', pages.map((page) => page.name)]\n return `Page \"${label}\" not found. Available: ${available.join(', ')}`\n}\n\nfunction countDescendants(graph: SceneGraph, rootId: string): number {\n let count = 0\n walkNodes(graph, rootId, () => {\n count++\n return true\n })\n return count\n}\n\nfunction countNodes(graph: SceneGraph, pageId: string): number {\n const page = graph.getNode(pageId)\n return page ? sumBy(page.childIds, (id) => countDescendants(graph, id)) : 0\n}\n\nfunction nodeFrame(node: SceneNode) {\n return {\n x: Math.round(node.x),\n y: Math.round(node.y),\n width: Math.round(node.width),\n height: Math.round(node.height)\n }\n}\n\n// ── info ──\n\nexport interface InfoResult {\n pages: number\n totalNodes: number\n types: Record<string, number>\n fonts: string[]\n pageCounts: Record<string, number>\n}\n\nexport const infoCommand: RPCCommand<void, InfoResult> = {\n name: 'info',\n execute: (graph) => {\n const pages = graph.getPages()\n let totalNodes = 0\n const types: Record<string, number> = {}\n const fonts = new Set<string>()\n const pageCounts: Record<string, number> = {}\n\n const countNode = (node: SceneNode) => {\n totalNodes++\n types[node.type] = (types[node.type] ?? 0) + 1\n if (node.fontFamily) fonts.add(node.fontFamily)\n return true\n }\n\n for (const page of pages) {\n const beforePage = totalNodes\n for (const cid of page.childIds) {\n walkNodes(graph, cid, countNode)\n }\n pageCounts[page.name] = totalNodes - beforePage\n }\n\n return { pages: pages.length, totalNodes, types, fonts: [...fonts].sort(), pageCounts }\n }\n}\n\nexport const fontStatusCommand: RPCCommand<void, FontReadiness> = {\n name: 'font-status',\n execute: async (graph) => {\n const pageIds = graph.getPages().map((page) => page.id)\n return resolveFontReadiness(graph, pageIds.length > 0 ? pageIds : [graph.rootId])\n }\n}\n\n// ── pages ──\n\nexport interface PageItem {\n id: string\n name: string\n nodes: number\n}\n\nexport const pagesCommand: RPCCommand<void, PageItem[]> = {\n name: 'pages',\n execute: (graph) => {\n return graph.getPages().map((p) => ({ id: p.id, name: p.name, nodes: countNodes(graph, p.id) }))\n }\n}\n\n// ── tree ──\n\nexport interface TreeArgs extends PageArgs {\n depth?: number\n}\n\nexport interface TreeNodeResult {\n id: string\n name: string\n type: string\n x: number\n y: number\n width: number\n height: number\n children?: TreeNodeResult[]\n}\n\nfunction buildTreeNode(\n graph: SceneGraph,\n id: string,\n depth: number,\n maxDepth: number\n): TreeNodeResult | null {\n const node = graph.getNode(id)\n if (!node) return null\n const result: TreeNodeResult = {\n id: node.id,\n name: node.name,\n type: node.type,\n ...nodeFrame(node)\n }\n if (node.childIds.length > 0 && depth < maxDepth) {\n result.children = node.childIds\n .map((cid) => buildTreeNode(graph, cid, depth + 1, maxDepth))\n .filter((n): n is TreeNodeResult => n !== null)\n }\n return result\n}\n\nexport interface TreeResult {\n page: { id: string; name: string; type: string }\n children: TreeNodeResult[]\n}\n\nexport const treeCommand: RPCCommand<TreeArgs, TreeResult | { error: string }> = {\n name: 'tree',\n execute: (graph, args) => {\n const maxDepth = args.depth ?? Infinity\n const page = pickedPages(graph, args, graph.getPages().slice(0, 1)).at(0)\n if (!page) return { error: missingPageError(graph, args) }\n\n return {\n page: { id: page.id, name: page.name, type: page.type },\n children: page.childIds\n .map((cid) => buildTreeNode(graph, cid, 0, maxDepth))\n .filter((n): n is TreeNodeResult => n !== null)\n }\n }\n}\n\n// ── find ──\n\nexport interface FindArgs extends PageArgs {\n name?: string\n type?: string\n limit?: number\n}\n\nexport interface FindNodeResult {\n id: string\n name: string\n type: string\n width: number\n height: number\n}\n\nexport const findCommand: RPCCommand<FindArgs, FindNodeResult[]> = {\n name: 'find',\n execute: (graph, args) => {\n const max = args.limit ?? 100\n const namePattern = args.name?.toLowerCase()\n const typeFilter = args.type?.toUpperCase()\n const results: FindNodeResult[] = []\n\n const searchPage = (page: SceneNode) => {\n for (const cid of page.childIds) {\n const cont = walkNodes(graph, cid, (node) => {\n if (results.length >= max) return false\n const matchesName = !namePattern || node.name.toLowerCase().includes(namePattern)\n const matchesType = !typeFilter || node.type === typeFilter\n if (matchesName && matchesType) {\n results.push({\n id: node.id,\n name: node.name,\n type: node.type,\n width: Math.round(node.width),\n height: Math.round(node.height)\n })\n }\n return true\n })\n if (!cont) break\n }\n }\n\n for (const page of pickedPages(graph, args, graph.getPages())) searchPage(page)\n\n return results\n }\n}\n\n// ── query (xpath) ──\n\nexport interface QueryArgs extends PageArgs {\n selector: string\n limit?: number\n}\n\nexport interface QueryNodeResult {\n id: string\n name: string\n type: string\n x: number\n y: number\n width: number\n height: number\n}\n\nexport const queryCommand: RPCCommand<QueryArgs, QueryNodeResult[] | { error: string }> = {\n name: 'query',\n execute: async (graph, args) => {\n try {\n const nodes = await queryByXPath(graph, args.selector, {\n page: args.page,\n pageId: args.page_id,\n limit: args.limit\n })\n return nodes.map((n) => ({\n id: n.id,\n name: n.name,\n type: n.type,\n x: Math.round(n.x),\n y: Math.round(n.y),\n width: Math.round(n.width),\n height: Math.round(n.height)\n }))\n } catch (err) {\n return { error: `XPath error: ${err instanceof Error ? err.message : String(err)}` }\n }\n }\n}\n\n// ── node ──\n\nexport interface NodeArgs {\n id: string\n}\n\nexport interface NodeResult {\n id: string\n name: string\n type: string\n x: number\n y: number\n width: number\n height: number\n visible: boolean\n locked: boolean\n opacity: number\n rotation: number\n fills: unknown[]\n strokes: unknown[]\n effects: unknown[]\n cornerRadius?: number\n topLeftRadius?: number\n topRightRadius?: number\n bottomRightRadius?: number\n bottomLeftRadius?: number\n isMask?: boolean\n maskType?: MaskType\n booleanOperation?: BooleanOperation\n blendMode: string\n layoutMode: string\n layoutDirection: string\n fontFamily: string\n fontSize: number\n fontWeight: number\n textDirection: string\n text: string | null\n parent: { id: string; name: string; type: string } | null\n children: number\n boundVariables: Record<string, string>\n}\n\nexport const nodeCommand: RPCCommand<NodeArgs, NodeResult | { error: string }> = {\n name: 'node',\n execute: (graph, args) => {\n const node = graph.getNode(args.id)\n if (!node) return { error: `Node \"${args.id}\" not found` }\n\n const parent = node.parentId ? graph.getNode(node.parentId) : undefined\n const boundVars: Record<string, string> = {}\n for (const [field, varId] of Object.entries(node.boundVariables)) {\n const variable = graph.variables.get(varId)\n boundVars[field] = variable?.name ?? varId\n }\n return {\n id: node.id,\n name: node.name,\n type: node.type,\n ...nodeFrame(node),\n visible: node.visible,\n locked: node.locked,\n opacity: node.opacity,\n rotation: node.rotation,\n fills: node.fills,\n strokes: node.strokes,\n effects: node.effects,\n ...shapeDetailFields(node),\n blendMode: node.blendMode,\n layoutMode: node.layoutMode,\n layoutDirection: node.layoutDirection,\n fontFamily: node.fontFamily,\n fontSize: node.fontSize,\n fontWeight: node.fontWeight,\n textDirection: node.textDirection,\n text: (() => {\n if (!node.text.length) return null\n if (node.text.length > 200) return node.text.slice(0, 200) + ELLIPSIS\n return node.text\n })(),\n parent: parent ? { id: parent.id, name: parent.name, type: parent.type } : null,\n children: node.childIds.length,\n boundVariables: boundVars\n }\n }\n}\n"],"mappings":";;;;;;;AAaA,SAAS,UAAU,OAAmB,QAAgB,IAA2C;CAC/F,MAAM,OAAO,MAAM,QAAQ,MAAM;CACjC,IAAI,CAAC,MAAM,OAAO;CAClB,IAAI,CAAC,GAAG,IAAI,GAAG,OAAO;CACtB,KAAK,MAAM,WAAW,KAAK,UACzB,IAAI,CAAC,UAAU,OAAO,SAAS,EAAE,GAAG,OAAO;CAE7C,OAAO;AACT;;AASA,SAAS,YAAY,OAAmB,MAAgB,UAAoC;CAC1F,MAAM,QAAQ,MAAM,SAAS;CAC7B,IAAI,KAAK,SAAS,OAAO,MAAM,QAAQ,SAAS,KAAK,OAAO,KAAK,OAAO;CACxE,IAAI,KAAK,MAAM,OAAO,MAAM,QAAQ,SAAS,KAAK,SAAS,KAAK,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC;CAChF,OAAO;AACT;AAEA,SAAS,iBAAiB,OAAmB,MAAwB;CACnE,MAAM,QAAQ,MAAM,SAAS;CAC7B,MAAM,CAAC,OAAO,aAAa,KAAK,UAC5B,CAAC,KAAK,SAAS,MAAM,KAAK,SAAS,KAAK,EAAE,CAAC,IAC3C,CAAC,KAAK,QAAQ,IAAI,MAAM,KAAK,SAAS,KAAK,IAAI,CAAC;CACp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AAU,OAAO,SAAS;EACxB,MAAM,OAAO,MAAM,QAAQ,KAAK,EAAE;EAClC,IAAI,CAAC,MAAM,OAAO,EAAE,OAAO,SAAS,KAAK,GAAG,aAAa;EAEzD,MAAM,SAAS,KAAK,WAAW,MAAM,QAAQ,KAAK,QAAQ,IAAI,KAAA;EAC9D,MAAM,YAAoC,CAAC;EAC3C,KAAK,MAAM,CAAC,OAAO,UAAU,OAAO,QAAQ,KAAK,cAAc,GAE7D,UAAU,SADO,MAAM,UAAU,IAAI,KACX,CAAC,EAAE,QAAQ;EAEvC,OAAO;GACL,IAAI,KAAK;GACT,MAAM,KAAK;GACX,MAAM,KAAK;GACX,GAAG,UAAU,IAAI;GACjB,SAAS,KAAK;GACd,QAAQ,KAAK;GACb,SAAS,KAAK;GACd,UAAU,KAAK;GACf,OAAO,KAAK;GACZ,SAAS,KAAK;GACd,SAAS,KAAK;GACd,GAAG,kBAAkB,IAAI;GACzB,WAAW,KAAK;GAChB,YAAY,KAAK;GACjB,iBAAiB,KAAK;GACtB,YAAY,KAAK;GACjB,UAAU,KAAK;GACf,YAAY,KAAK;GACjB,eAAe,KAAK;GACpB,aAAa;IACX,IAAI,CAAC,KAAK,KAAK,QAAQ,OAAO;IAC9B,IAAI,KAAK,KAAK,SAAS,KAAK,OAAO,KAAK,KAAK,MAAM,GAAG,GAAG,IAAA;IACzD,OAAO,KAAK;GACd,EAAA,CAAG;GACH,QAAQ,SAAS;IAAE,IAAI,OAAO;IAAI,MAAM,OAAO;IAAM,MAAM,OAAO;GAAK,IAAI;GAC3E,UAAU,KAAK,SAAS;GACxB,gBAAgB;EAClB;CACF;AACF"}
@@ -29,7 +29,7 @@ const variablesCommand = {
29
29
  totalVariables: 0,
30
30
  totalCollections: 0
31
31
  };
32
- for (const coll of graph.variableCollections.values()) {
32
+ for (const coll of graph.getLiveCollections()) {
33
33
  if (collFilter && !coll.name.toLowerCase().includes(collFilter)) continue;
34
34
  const collVars = graph.getVariablesForCollection(coll.id).filter((v) => !typeFilter || v.type === typeFilter);
35
35
  if (collVars.length === 0) continue;
@@ -68,7 +68,7 @@ async function designTokenFiles(graph) {
68
68
  const { files, issues } = exportDesignTokens(graph);
69
69
  return {
70
70
  css: "",
71
- tokenCount: graph.variables.size,
71
+ tokenCount: graph.getLiveVariables().length,
72
72
  issues: issues.map(designTokenIssueMessage),
73
73
  files
74
74
  };
@@ -1 +1 @@
1
- {"version":3,"file":"variables-command.js","names":[],"sources":["../../src/rpc/variables-command.ts"],"sourcesContent":["import type { SceneGraph, Variable, VariableType } from '@pairdraw/scene-graph'\nimport { colorToHex } from '@pairdraw/scene-graph/color'\nimport { formatVariableFormula } from '@pairdraw/scene-graph/variables'\n\nimport { exportTokenStylesheet, type TokenExport } from '#core/tools/codegen/tokens'\n\nimport type { RPCCommand } from './types'\n\n// ── variables ──\n\nexport interface VariablesArgs {\n collection?: string\n type?: string\n}\n\nfunction formatVariableValue(variable: Variable, graph: SceneGraph): string {\n const modeId = graph.getActiveModeId(variable.collectionId)\n const raw = variable.valuesByMode[modeId]\n\n if (typeof raw === 'object' && 'aliasId' in raw) {\n const alias = graph.variables.get(raw.aliasId)\n return alias ? `→ ${alias.name}` : `→ ${raw.aliasId}`\n }\n\n if (typeof raw === 'object' && 'r' in raw) {\n return colorToHex(raw).toLowerCase()\n }\n if (typeof raw === 'object' && 'expression' in raw) {\n // A formula reads as written, with what it gives now; a composed color by its result.\n const resolved = graph.resolveVariable(variable.id, modeId)\n let result = '—'\n if (typeof resolved === 'object') result = colorToHex(resolved).toLowerCase()\n else if (resolved !== undefined) result = String(resolved)\n return raw.expression === 'FORMULA'\n ? `${formatVariableFormula(graph, raw)} = ${result}`\n : result\n }\n\n return String(raw)\n}\n\nexport interface VariablesResult {\n collections: Array<{\n id: string\n name: string\n modes: string[]\n variables: Array<{\n id: string\n name: string\n type: string\n value: string\n }>\n }>\n totalVariables: number\n totalCollections: number\n}\n\nexport const variablesCommand: RPCCommand<VariablesArgs, VariablesResult> = {\n name: 'variables',\n execute: (graph, args) => {\n const typeFilter = args.type?.toUpperCase()\n const collFilter = args.collection?.toLowerCase()\n\n const result: VariablesResult = { collections: [], totalVariables: 0, totalCollections: 0 }\n\n for (const coll of graph.variableCollections.values()) {\n if (collFilter && !coll.name.toLowerCase().includes(collFilter)) continue\n\n const collVars = graph\n .getVariablesForCollection(coll.id)\n .filter((v) => !typeFilter || v.type === typeFilter)\n\n if (collVars.length === 0) continue\n\n result.collections.push({\n id: coll.id,\n name: coll.name,\n modes: coll.modes.map((m) => m.name),\n variables: collVars.map((v) => ({\n id: v.id,\n name: v.name,\n type: v.type,\n value: formatVariableValue(v, graph)\n }))\n })\n }\n\n result.totalVariables = result.collections.reduce(\n (count, collection) => count + collection.variables.length,\n 0\n )\n result.totalCollections = result.collections.length\n return result\n }\n}\n\n// ── tokens ──\n\nexport interface TokensArgs {\n format?: string\n collection?: string\n type?: string\n}\n\nexport type TokensResult = TokenExport\n\nconst VARIABLE_TYPES: readonly VariableType[] = ['COLOR', 'FLOAT', 'STRING', 'BOOLEAN']\n\nfunction variableType(value: string | undefined): VariableType | undefined {\n if (!value) return undefined\n const type = VARIABLE_TYPES.find((candidate) => candidate === value.toUpperCase())\n if (!type) throw new Error(`Unknown variable type: ${value}. Use ${VARIABLE_TYPES.join(', ')}.`)\n return type\n}\n\n/** W3C design token files instead of a stylesheet, for `--format dtcg`. */\nasync function designTokenFiles(graph: SceneGraph): Promise<TokensResult> {\n const { designTokenIssueMessage, exportDesignTokens } =\n await import('#core/io/formats/design-tokens')\n const { files, issues } = exportDesignTokens(graph)\n return {\n css: '',\n tokenCount: graph.variables.size,\n issues: issues.map(designTokenIssueMessage),\n files\n }\n}\n\nexport const tokensCommand: RPCCommand<TokensArgs, TokensResult> = {\n name: 'tokens',\n execute: (graph, args) => {\n if (args.format === 'dtcg') return designTokenFiles(graph)\n if (args.format && args.format !== 'css' && args.format !== 'tailwind')\n throw new Error(`Unknown token format: ${args.format}. Use css, tailwind, or dtcg.`)\n return exportTokenStylesheet(graph, {\n format: args.format === 'tailwind' ? 'tailwind' : 'css',\n collection: args.collection,\n type: variableType(args.type)\n })\n }\n}\n"],"mappings":";;;;AAeA,SAAS,oBAAoB,UAAoB,OAA2B;CAC1E,MAAM,SAAS,MAAM,gBAAgB,SAAS,YAAY;CAC1D,MAAM,MAAM,SAAS,aAAa;CAElC,IAAI,OAAO,QAAQ,YAAY,aAAa,KAAK;EAC/C,MAAM,QAAQ,MAAM,UAAU,IAAI,IAAI,OAAO;EAC7C,OAAO,QAAQ,KAAK,MAAM,SAAS,KAAK,IAAI;CAC9C;CAEA,IAAI,OAAO,QAAQ,YAAY,OAAO,KACpC,OAAO,WAAW,GAAG,CAAC,CAAC,YAAY;CAErC,IAAI,OAAO,QAAQ,YAAY,gBAAgB,KAAK;EAElD,MAAM,WAAW,MAAM,gBAAgB,SAAS,IAAI,MAAM;EAC1D,IAAI,SAAS;EACb,IAAI,OAAO,aAAa,UAAU,SAAS,WAAW,QAAQ,CAAC,CAAC,YAAY;OACvE,IAAI,aAAa,KAAA,GAAW,SAAS,OAAO,QAAQ;EACzD,OAAO,IAAI,eAAe,YACtB,GAAG,sBAAsB,OAAO,GAAG,EAAE,KAAK,WAC1C;CACN;CAEA,OAAO,OAAO,GAAG;AACnB;AAkBA,MAAa,mBAA+D;CAC1E,MAAM;CACN,UAAU,OAAO,SAAS;EACxB,MAAM,aAAa,KAAK,MAAM,YAAY;EAC1C,MAAM,aAAa,KAAK,YAAY,YAAY;EAEhD,MAAM,SAA0B;GAAE,aAAa,CAAC;GAAG,gBAAgB;GAAG,kBAAkB;EAAE;EAE1F,KAAK,MAAM,QAAQ,MAAM,oBAAoB,OAAO,GAAG;GACrD,IAAI,cAAc,CAAC,KAAK,KAAK,YAAY,CAAC,CAAC,SAAS,UAAU,GAAG;GAEjE,MAAM,WAAW,MACd,0BAA0B,KAAK,EAAE,CAAC,CAClC,QAAQ,MAAM,CAAC,cAAc,EAAE,SAAS,UAAU;GAErD,IAAI,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EAC9B,CAAC;CACH;AACF"}
1
+ {"version":3,"file":"variables-command.js","names":[],"sources":["../../src/rpc/variables-command.ts"],"sourcesContent":["import type { SceneGraph, Variable, VariableType } from '@pairdraw/scene-graph'\nimport { colorToHex } from '@pairdraw/scene-graph/color'\nimport { formatVariableFormula } from '@pairdraw/scene-graph/variables'\n\nimport { exportTokenStylesheet, type TokenExport } from '#core/tools/codegen/tokens'\n\nimport type { RPCCommand } from './types'\n\n// ── variables ──\n\nexport interface VariablesArgs {\n collection?: string\n type?: string\n}\n\nfunction formatVariableValue(variable: Variable, graph: SceneGraph): string {\n const modeId = graph.getActiveModeId(variable.collectionId)\n const raw = variable.valuesByMode[modeId]\n\n if (typeof raw === 'object' && 'aliasId' in raw) {\n const alias = graph.variables.get(raw.aliasId)\n return alias ? `→ ${alias.name}` : `→ ${raw.aliasId}`\n }\n\n if (typeof raw === 'object' && 'r' in raw) {\n return colorToHex(raw).toLowerCase()\n }\n if (typeof raw === 'object' && 'expression' in raw) {\n // A formula reads as written, with what it gives now; a composed color by its result.\n const resolved = graph.resolveVariable(variable.id, modeId)\n let result = '—'\n if (typeof resolved === 'object') result = colorToHex(resolved).toLowerCase()\n else if (resolved !== undefined) result = String(resolved)\n return raw.expression === 'FORMULA'\n ? `${formatVariableFormula(graph, raw)} = ${result}`\n : result\n }\n\n return String(raw)\n}\n\nexport interface VariablesResult {\n collections: Array<{\n id: string\n name: string\n modes: string[]\n variables: Array<{\n id: string\n name: string\n type: string\n value: string\n }>\n }>\n totalVariables: number\n totalCollections: number\n}\n\nexport const variablesCommand: RPCCommand<VariablesArgs, VariablesResult> = {\n name: 'variables',\n execute: (graph, args) => {\n const typeFilter = args.type?.toUpperCase()\n const collFilter = args.collection?.toLowerCase()\n\n const result: VariablesResult = { collections: [], totalVariables: 0, totalCollections: 0 }\n\n for (const coll of graph.getLiveCollections()) {\n if (collFilter && !coll.name.toLowerCase().includes(collFilter)) continue\n\n const collVars = graph\n .getVariablesForCollection(coll.id)\n .filter((v) => !typeFilter || v.type === typeFilter)\n\n if (collVars.length === 0) continue\n\n result.collections.push({\n id: coll.id,\n name: coll.name,\n modes: coll.modes.map((m) => m.name),\n variables: collVars.map((v) => ({\n id: v.id,\n name: v.name,\n type: v.type,\n value: formatVariableValue(v, graph)\n }))\n })\n }\n\n result.totalVariables = result.collections.reduce(\n (count, collection) => count + collection.variables.length,\n 0\n )\n result.totalCollections = result.collections.length\n return result\n }\n}\n\n// ── tokens ──\n\nexport interface TokensArgs {\n format?: string\n collection?: string\n type?: string\n}\n\nexport type TokensResult = TokenExport\n\nconst VARIABLE_TYPES: readonly VariableType[] = ['COLOR', 'FLOAT', 'STRING', 'BOOLEAN']\n\nfunction variableType(value: string | undefined): VariableType | undefined {\n if (!value) return undefined\n const type = VARIABLE_TYPES.find((candidate) => candidate === value.toUpperCase())\n if (!type) throw new Error(`Unknown variable type: ${value}. Use ${VARIABLE_TYPES.join(', ')}.`)\n return type\n}\n\n/** W3C design token files instead of a stylesheet, for `--format dtcg`. */\nasync function designTokenFiles(graph: SceneGraph): Promise<TokensResult> {\n const { designTokenIssueMessage, exportDesignTokens } =\n await import('#core/io/formats/design-tokens')\n const { files, issues } = exportDesignTokens(graph)\n return {\n css: '',\n tokenCount: graph.getLiveVariables().length,\n issues: issues.map(designTokenIssueMessage),\n files\n }\n}\n\nexport const tokensCommand: RPCCommand<TokensArgs, TokensResult> = {\n name: 'tokens',\n execute: (graph, args) => {\n if (args.format === 'dtcg') return designTokenFiles(graph)\n if (args.format && args.format !== 'css' && args.format !== 'tailwind')\n throw new Error(`Unknown token format: ${args.format}. Use css, tailwind, or dtcg.`)\n return exportTokenStylesheet(graph, {\n format: args.format === 'tailwind' ? 'tailwind' : 'css',\n collection: args.collection,\n type: variableType(args.type)\n })\n }\n}\n"],"mappings":";;;;AAeA,SAAS,oBAAoB,UAAoB,OAA2B;CAC1E,MAAM,SAAS,MAAM,gBAAgB,SAAS,YAAY;CAC1D,MAAM,MAAM,SAAS,aAAa;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AoB,GAAG,KAAK;IACrC,EAAE;GACJ,CAAC;EACH;EAEA,OAAO,iBAAiB,OAAO,YAAY,QACxC,OAAO,eAAe,QAAQ,WAAW,UAAU,QACpD,CACF;EACA,OAAO,mBAAmB,OAAO,YAAY;EAC7C,OAAO;CACT;AACF;AAYA,MAAM,iBAA0C;CAAC;CAAS;CAAS;CAAU;AAAS;AAEtF,SAAS,aAAa,OAAqD;CACzE,IAAI,CAAC,OAAO,OAAO,KAAA;CACnB,MAAM,OAAO,eAAe,MAAM,cAAc,cAAc,MAAM,YAAY,CAAC;CACjF,IAAI,CAAC,MAAM,MAAM,IAAI,MAAM,0BAA0B,MAAM,QAAQ,eAAe,KAAK,IAAI,EAAE,EAAE;CAC/F,OAAO;AACT;;AAGA,eAAe,iBAAiB,OAA0C;CACxE,MAAM,EAAE,yBAAyB,uBAC/B,MAAM,OAAO;CACf,MAAM,EAAE,OAAO,WAAW,mBAAmB,KAAK;CAClD,OAAO;EACL,KAAK;EACL,YAAY,MAAM,iBAAiB,CAAC,CAAC;EACrC,QAAQ,OAAO,IAAI,uBAAuB;EAC1C;CACF;AACF;AAEA,MAAa,gBAAsD;CACjE,MAAM;CACN,UAAU,OAAO,SAAS;EACxB,IAAI,KAAK,WAAW,QAAQ,OAAO,iBAAiB,KAAK;EACzD,IAAI,KAAK,UAAU,KAAK,WAAW,SAAS,KAAK,WAAW,YAC1D,MAAM,IAAI,MAAM,yBAAyB,KAAK,OAAO,8BAA8B;EACrF,OAAO,sBAAsB,OAAO;GAClC,QAAQ,KAAK,WAAW,aAAa,aAAa;GAClD,YAAY,KAAK;GACjB,MAAM,aAAa,KAAK,IAAI;EAC9B,CAAC;CACH;AACF"}
@@ -0,0 +1,15 @@
1
+ import { CanvasKit, TypefaceFontProvider } from "canvaskit-wasm";
2
+ //#region src/text/font/provider.d.ts
3
+ /**
4
+ * A share of the font provider `canvasKit` draws from. Every renderer and shaper holds one for as
5
+ * long as it reads text, so a face registered by one is shaped by all of them, and the last share
6
+ * given back deletes the provider. Releasing twice is safe and does nothing the second time.
7
+ */
8
+ interface FontProviderLease {
9
+ readonly provider: TypefaceFontProvider;
10
+ release(): void;
11
+ }
12
+ declare function leaseFontProvider(canvasKit: CanvasKit): FontProviderLease;
13
+ //#endregion
14
+ export { FontProviderLease, leaseFontProvider };
15
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","names":[],"sources":["../../../src/text/font/provider.ts"],"mappings":";;;;;;;UASiB;WACN,UAAU;EACnB;;iBAGc,kBAAkB,WAAW,YAAY"}
@@ -0,0 +1,18 @@
1
+ import { fontManager } from "./manager.js";
2
+ //#region src/text/font/provider.ts
3
+ function leaseFontProvider(canvasKit) {
4
+ const provider = fontManager.acquireProvider(canvasKit);
5
+ let held = true;
6
+ return {
7
+ provider,
8
+ release() {
9
+ if (!held) return;
10
+ held = false;
11
+ fontManager.releaseProvider(provider);
12
+ }
13
+ };
14
+ }
15
+ //#endregion
16
+ export { leaseFontProvider };
17
+
18
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.js","names":[],"sources":["../../../src/text/font/provider.ts"],"sourcesContent":["import type { CanvasKit, TypefaceFontProvider } from 'canvaskit-wasm'\n\nimport { fontManager } from './manager'\n\n/**\n * A share of the font provider `canvasKit` draws from. Every renderer and shaper holds one for as\n * long as it reads text, so a face registered by one is shaped by all of them, and the last share\n * given back deletes the provider. Releasing twice is safe and does nothing the second time.\n */\nexport interface FontProviderLease {\n readonly provider: TypefaceFontProvider\n release(): void\n}\n\nexport function leaseFontProvider(canvasKit: CanvasKit): FontProviderLease {\n const provider = fontManager.acquireProvider(canvasKit)\n let held = true\n return {\n provider,\n release() {\n if (!held) return\n held = false\n fontManager.releaseProvider(provider)\n }\n }\n}\n"],"mappings":";;AAcA,SAAgB,kBAAkB,WAAyC;CACzE,MAAM,WAAW,YAAY,gBAAgB,SAAS;CACtD,IAAI,OAAO;CACX,OAAO;EACL;EACA,UAAU;GACR,IAAI,CAAC,MAAM;GACX,OAAO;GACP,YAAY,gBAAgB,QAAQ;EACtC;CACF;AACF"}
@@ -0,0 +1,32 @@
1
+ import { FontLoadedSource, FontUnavailableReason } from "./sources.js";
2
+ import { FontManager } from "./manager.js";
3
+ import { SceneGraph } from "@pairdraw/scene-graph";
4
+ //#region src/text/font/readiness.d.ts
5
+ type FontReadinessStatus = 'available' | 'substituted' | 'unresolved';
6
+ interface FontFaceReadiness {
7
+ family: string;
8
+ /** The style the font manager loads the face as. */
9
+ style: string;
10
+ /** The face's name, as its text names it ("Book", "Semi Bold"). */
11
+ name: string;
12
+ status: FontReadinessStatus;
13
+ source: FontLoadedSource | null;
14
+ substituteFamily: string | null;
15
+ /** Why the requested face could not be loaded, when the host reported a reason. */
16
+ reason: FontUnavailableReason | null;
17
+ nodeIds: string[];
18
+ nodeNames: string[];
19
+ }
20
+ interface FontReadiness {
21
+ faithful: boolean;
22
+ faces: FontFaceReadiness[];
23
+ issues: FontFaceReadiness[];
24
+ }
25
+ /**
26
+ * What the fonts loaded now can draw: a face reads `unresolved` until something loads it, so a
27
+ * caller that needs the truth for a document asks {@link resolveFontReadiness} instead.
28
+ */
29
+ declare function readFontReadiness(graph: SceneGraph, rootIds: string | readonly string[], manager?: FontManager): FontReadiness;
30
+ //#endregion
31
+ export { FontFaceReadiness, FontReadiness, FontReadinessStatus, readFontReadiness };
32
+ //# sourceMappingURL=readiness.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readiness.d.ts","names":[],"sources":["../../../src/text/font/readiness.ts"],"mappings":";;;;KAOY;UAEK;EACf;;EAEA;;EAEA;EACA,QAAQ;EACR,QAAQ;EACR;;EAEA,QAAQ;EACR;EACA;;UAGe;EACf;EACA,OAAO;EACP,QAAQ;;;;;;iBA+FM,kBACd,OAAO,YACP,qCACA,UAAS,cACR"}
@@ -1,7 +1,7 @@
1
1
  import { DEFAULT_FONT_FAMILY } from "../../constants.js";
2
2
  import { fontManager } from "./manager.js";
3
3
  import { collectNamedNodeFontFaces } from "./names.js";
4
- //#region src/text/font/status.ts
4
+ //#region src/text/font/readiness.ts
5
5
  /** A face by its name and the style it loads as; one name may load as two styles. */
6
6
  function faceKey(family, style, name) {
7
7
  return `${family}\0${style}\0${name}`;
@@ -68,7 +68,11 @@ function faceStatus(use, manager) {
68
68
  nodeNames: [...use.nodeNames]
69
69
  };
70
70
  }
71
- function documentFontStatus(graph, rootIds, manager = fontManager) {
71
+ /**
72
+ * What the fonts loaded now can draw: a face reads `unresolved` until something loads it, so a
73
+ * caller that needs the truth for a document asks {@link resolveFontReadiness} instead.
74
+ */
75
+ function readFontReadiness(graph, rootIds, manager = fontManager) {
72
76
  const faces = collectFaceUses(graph, typeof rootIds === "string" ? [rootIds] : rootIds).map((use) => faceStatus(use, manager)).sort((a, b) => a.family.localeCompare(b.family) || a.name.localeCompare(b.name));
73
77
  const issues = faces.filter((face) => face.status !== "available");
74
78
  return {
@@ -78,6 +82,6 @@ function documentFontStatus(graph, rootIds, manager = fontManager) {
78
82
  };
79
83
  }
80
84
  //#endregion
81
- export { documentFontStatus };
85
+ export { readFontReadiness };
82
86
 
83
- //# sourceMappingURL=status.js.map
87
+ //# sourceMappingURL=readiness.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readiness.js","names":[],"sources":["../../../src/text/font/readiness.ts"],"sourcesContent":["import type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\n\nimport { DEFAULT_FONT_FAMILY } from '#core/constants'\nimport { fontManager, type FontManager } from '#core/text/font/manager'\nimport { collectNamedNodeFontFaces } from '#core/text/font/names'\nimport type { FontLoadedSource, FontUnavailableReason } from '#core/text/font/sources'\n\nexport type FontReadinessStatus = 'available' | 'substituted' | 'unresolved'\n\nexport interface FontFaceReadiness {\n family: string\n /** The style the font manager loads the face as. */\n style: string\n /** The face's name, as its text names it (\"Book\", \"Semi Bold\"). */\n name: string\n status: FontReadinessStatus\n source: FontLoadedSource | null\n substituteFamily: string | null\n /** Why the requested face could not be loaded, when the host reported a reason. */\n reason: FontUnavailableReason | null\n nodeIds: string[]\n nodeNames: string[]\n}\n\nexport interface FontReadiness {\n faithful: boolean\n faces: FontFaceReadiness[]\n issues: FontFaceReadiness[]\n}\n\ninterface MutableFontFaceUse {\n family: string\n style: string\n name: string\n nodeIds: Set<string>\n nodeNames: Set<string>\n}\n\n/** A face by its name and the style it loads as; one name may load as two styles. */\nfunction faceKey(family: string, style: string, name: string): string {\n return `${family}\\0${style}\\0${name}`\n}\n\n/** The text nodes under each root, and each root that is itself text. */\nfunction rootTextNodes(graph: SceneGraph, rootIds: readonly string[]): SceneNode[] {\n return rootIds.flatMap((rootId) => {\n const root = graph.getNode(rootId)\n if (!root) return []\n const nodes = [root, ...graph.flattenTree(rootId).map(({ node }) => node)]\n return nodes.filter((node) => node.type === 'TEXT')\n })\n}\n\nfunction collectFaceUses(graph: SceneGraph, rootIds: readonly string[]): MutableFontFaceUse[] {\n const uses = new Map<string, MutableFontFaceUse>()\n for (const node of rootTextNodes(graph, rootIds)) {\n // Faces that load as one style (\"Book\" and \"Roman\" at 400) are still faces of their own.\n for (const { family, style, name } of collectNamedNodeFontFaces(node)) {\n const key = faceKey(family, style, name)\n const use = uses.get(key) ?? {\n family,\n style,\n name,\n nodeIds: new Set<string>(),\n nodeNames: new Set<string>()\n }\n use.nodeIds.add(node.id)\n use.nodeNames.add(node.name)\n uses.set(key, use)\n }\n }\n return [...uses.values()]\n}\n\nfunction faceStatus(use: MutableFontFaceUse, manager: FontManager): FontFaceReadiness {\n const exactSource = manager.loadedFontSource(use.family, use.style)\n if (exactSource) {\n return {\n family: use.family,\n style: use.style,\n name: use.name,\n status: 'available',\n source: exactSource,\n substituteFamily: null,\n reason: null,\n nodeIds: [...use.nodeIds],\n nodeNames: [...use.nodeNames]\n }\n }\n\n if (manager.isLoaded(use.family)) {\n return {\n family: use.family,\n style: use.style,\n name: use.name,\n status: 'substituted',\n source: null,\n substituteFamily: use.family,\n reason: manager.unavailableReason(use.family, use.style),\n nodeIds: [...use.nodeIds],\n nodeNames: [...use.nodeNames]\n }\n }\n\n const defaultSource = manager.loadedFontSource(DEFAULT_FONT_FAMILY, 'Regular')\n return {\n family: use.family,\n style: use.style,\n name: use.name,\n status: defaultSource ? 'substituted' : 'unresolved',\n source: null,\n substituteFamily: defaultSource ? DEFAULT_FONT_FAMILY : null,\n reason: manager.unavailableReason(use.family, use.style),\n nodeIds: [...use.nodeIds],\n nodeNames: [...use.nodeNames]\n }\n}\n\n/**\n * What the fonts loaded now can draw: a face reads `unresolved` until something loads it, so a\n * caller that needs the truth for a document asks {@link resolveFontReadiness} instead.\n */\nexport function readFontReadiness(\n graph: SceneGraph,\n rootIds: string | readonly string[],\n manager: FontManager = fontManager\n): FontReadiness {\n const roots = typeof rootIds === 'string' ? [rootIds] : rootIds\n const faces = collectFaceUses(graph, roots)\n .map((use) => faceStatus(use, manager))\n .sort((a, b) => a.family.localeCompare(b.family) || a.name.localeCompare(b.name))\n const issues = faces.filter((face) => face.status !== 'available')\n return { faithful: issues.length === 0, faces, issues }\n}\n"],"mappings":";;;;;AAuCA,SAAS,QAAQ,QAAgB,OAAe,MAAsB;CACpE,OAAO,GAAG,OAAO,IAAI,MAAM,IAAI;AACjC;;AAGA,SAAS,cAAc,OAAmB,SAAyC;CACjF,OAAO,QAAQ,SAAS,WAAW;EACjC,MAAM,OAAO,MAAM,QAAQ,MAAM;EACjC,IAAI,CAAC,MAAM,OAAO,CAAC;EAEnB,OAAO,CADQ,MAAM,GAAG,MAAM,YAAY,MAAM,CAAC,CAAC,KAAK,EAAE,WAAW,IAAI,CAC7D,CAAC,CAAC,QAAQ,SAAS,KAAK,SAAS,MAAM;CACpD,CAAC;AACH;AAEA,SAAS,gBAAgB,OAAmB,SAAkD;CAC5F,MAAM,uBAAO,IAAI,IAAgC;CACjD,KAAK,MAAM,QAAQ,cAAc,OAAO,OAAO,GAE7C,KAAK,MAAM,EAAE,QAAQ,OAAO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SAAS;CAC9B;AACF;;;;;AAMA,SAAgB,kBACd,OACA,SACA,UAAuB,aACR;CAEf,MAAM,QAAQ,gBAAgB,OADhB,OAAO,YAAY,WAAW,CAAC,OAAO,IAAI,OACd,CAAC,CACxC,KAAK,QAAQ,WAAW,KAAK,OAAO,CAAC,CAAC,CACtC,MAAM,GAAG,MAAM,EAAE,OAAO,cAAc,EAAE,MAAM,KAAK,EAAE,KAAK,cAAc,EAAE,IAAI,CAAC;CAClF,MAAM,SAAS,MAAM,QAAQ,SAAS,KAAK,WAAW,WAAW;CACjE,OAAO;EAAE,UAAU,OAAO,WAAW;EAAG;EAAO;CAAO;AACxD"}
@@ -11,6 +11,7 @@ import { fontCoverageDemand, fontFaceDemand, fontRemoteCoverageDemand, fontResol
11
11
  import { BrowserFaceDescriptors, FaceWeight, FamilyFace, FontFaceRef, browserFaceDescriptors, facesFromStyles, fontFaceFromFigmaFontName, fontFaceRenderFamily, hasFamilyFace, nearestFamilyFace, standardFace, standardFaces } from "./font/faces.js";
12
12
  import { FontAxis, NamedInstance, fontAxes, fontTableView, hasNamedInstance, hasTrueTypeOutlines, isVariableFont, namedInstanceVariations, namedInstances, sfntFamilyNames, sfntFontName } from "./font/variation.js";
13
13
  import { TextCaret, TextEditor, TextEditorState } from "./editor.js";
14
+ import { FontProviderLease, leaseFontProvider } from "./font/provider.js";
14
15
  import { HarfBuzzSubsetLocator, OutlineCommand, setHarfBuzzSubsetLocator } from "./font/harfbuzz.js";
15
16
  import { GlyphOutlineProbe, probeGlyphOutlineCommands } from "./font/glyphs.js";
16
17
  import { InsertStyleSource, adjustRunsForDelete, applyStyleToRange, getStyleAt, insertRunsWithStyle, insertedStyleAt, removeStyleFromRange, runsAfterTyping, selectionHasStyle, toggleBoldInRange, toggleDecorationInRange, toggleItalicInRange } from "./style-runs.js";
@@ -24,13 +25,13 @@ import { HostFontFamily } from "./font/catalog.js";
24
25
  import { FontManager, fontManager } from "./font/manager.js";
25
26
  import { NamedLocalFont, chooseLocalFontMatch, findLocalFont, fontWeightMatchOrder } from "./font/style.js";
26
27
  import { isWOFF2, sfntFont } from "./font/woff2.js";
27
- import { DocumentFontFaceStatus, DocumentFontStatus, FontFaceStatus, documentFontStatus } from "./font/status.js";
28
+ import { FontFaceReadiness, FontReadiness, FontReadinessStatus, readFontReadiness } from "./font/readiness.js";
28
29
  import { DocumentFontEntry, DocumentFontInput, documentFontData, documentFontsOf, isDocumentFontFileName, mergeArchiveFonts, prepareDocumentFonts, registerDocumentFonts } from "./font/document.js";
29
30
  import { GraphFontRequirements, collectGraphFontKeys, collectGraphFontRequirements, collectNodeFontFaces, textFontFace } from "./requirements/collect.js";
30
31
  import { MissingGraphFontScriptsOptions, missingGraphFontScripts } from "./requirements/resolved.js";
31
32
  import { HyperlinkRunOptions, HyperlinkSpan, hyperlinkInRange, hyperlinkSpanAt, hyperlinkSpans, isOpenableLinkURL, normalizeLinkURL, styleRunsWithHyperlink } from "./hyperlink.js";
32
- import { prepareGraphFonts } from "./prepare.js";
33
+ import { resolveFontReadiness } from "./prepare.js";
33
34
  import { TextFace, collectNamedNodeFontFaces, faceForStyle, faceStyleName, textFaceName, textStyleName } from "./font/names.js";
34
35
  import { DocumentFont, FontFaceReference, FontReplacement, FontReplacementCounts, listDocumentFonts, replaceDocumentFonts } from "./replace-fonts.js";
35
36
  import { layerTextStyleChanges, shownTextStyle } from "./character-style.js";
36
- export { ARABIC_CHARACTER, ARABIC_LOCAL_FALLBACK_FAMILIES, ARABIC_REMOTE_FALLBACK_FAMILIES, BrowserFaceDescriptors, type BundledFontLocator, CJK_CHARACTER, CJK_FALLBACK_CHARACTER, DEFAULT_WEB_FONT_PROVIDER_SETTINGS, DEVANAGARI_CHARACTER, DocumentFont, DocumentFontEntry, DocumentFontFaceStatus, DocumentFontInput, DocumentFontStatus, DownloadedFontCache, FaceWeight, FamilyFace, FontAxis, FontCandidateSource, FontFaceRef, FontFaceReference, FontFaceStatus, FontFallbackManifestEntry, FontFallbackScript, FontFamilyOption, FontFamilySource, FontInfo, FontLoadedSource, FontManager, FontReplacement, FontReplacementCounts, FontResolutionCandidate, FontResolutionDemand, FontResolutionEvent, FontResolutionListener, FontResolutionLoader, FontResolutionSettled, FontResolutionSnapshot, FontResolutionState, FontResolver, FontUnavailableReason, type GlyphOutlineProbe, GraphFontRequirements, HANGUL_CHARACTER, HAN_CHARACTER, HEBREW_CHARACTER, type HarfBuzzSubsetLocator, type HostFontFamily, HostFontLoader, HyperlinkRunOptions, HyperlinkSpan, InsertStyleSource, KANA_CHARACTER, LETTER_FALLBACK_SCRIPTS, LetterFallbackScript, LocalFontAccessState, MissingGlyphOccurrence, MissingGraphFontScriptsOptions, NamedInstance, NamedLocalFont, ObservedShapedLine, type OutlineCommand, PathPoint, PathTextCaret, PathTextLayout, PathTextLineMetrics, ResolvedWebFont, SampledPath, THAI_CHARACTER, TextCaret, TextCaseSegment, TextEditor, TextEditorState, TextFace, UnsupportedFontFormatError, WEB_FONT_PROVIDER_IDS, WEB_FONT_PROVIDER_LABELS, WebFontFetch, WebFontProviderId, WebFontResolver, adjustRunsForDelete, applyStyleToRange, browserFaceDescriptors, calibratePathTextLayout, chooseLocalFontMatch, cjkFallbackScriptForLanguage, cjkLocalFallbackFamilies, collectGraphFontKeys, collectGraphFontRequirements, collectNamedNodeFontFaces, collectNodeFontFaces, documentFontData, documentFontStatus, documentFontsOf, faceForStyle, faceStyleName, facesFromStyles, fallbackDrawsCharacter, findLocalFont, fitTextPathBoxToGlyphs, fontAxes, fontCoverageDemand, fontFaceDemand, fontFaceFromFigmaFontName, fontFaceRenderFamily, fontFallbackEntry, fontFallbackManifest, fontFallbackScriptForCharacter, fontFeatureTags, fontManager, fontRemoteCoverageDemand, fontResolver, fontTableView, fontWeightMatchOrder, getStyleAt, getTextPathData, hasFamilyFace, hasNamedInstance, hasTrueTypeOutlines, hyperlinkInRange, hyperlinkSpanAt, hyperlinkSpans, insertRunsWithStyle, insertedStyleAt, isDocumentFontFileName, isOpenableLinkURL, isTraditionalOnlyHan, isVariableFont, isWOFF2, layerTextStyleChanges, layoutPathTextFromAdvances, listDocumentFonts, mergeArchiveFonts, missingGlyphCharacters, missingGlyphOccurrences, missingGlyphScripts, missingGlyphsByScript, missingGraphFontScripts, namedInstanceVariations, namedInstances, nearestArcPoint, nearestFamilyFace, normalizeLinkURL, normalizedCoverageText, pathTextCaret, pathTextIndexAt, pathTextSelectionQuads, pointAtArc, prepareDocumentFonts, prepareGraphFonts, probeGlyphOutlineCommands, reflowPathTextGlyphs, registerDocumentFonts, removeStyleFromRange, replaceDocumentFonts, runsAfterTyping, sampleTextPath, selectionHasStyle, setHarfBuzzSubsetLocator, sfntFamilyNames, sfntFont, sfntFontName, shownCharacters, shownText, shownTextSlice, shownTextStyle, standardFace, standardFaces, styleRunsWithHyperlink, textCaseSegments, textFaceName, textFallbackScriptsWithoutCoverage, textFontFace, textHasFallbackScript, textNeededFallbackScripts, textNeedsFallbackScript, textPathStartArc, textPathStartDistance, textStyleName, toggleBoldInRange, toggleDecorationInRange, toggleItalicInRange, transformTextCase, webFontSubsetsForText };
37
+ export { ARABIC_CHARACTER, ARABIC_LOCAL_FALLBACK_FAMILIES, ARABIC_REMOTE_FALLBACK_FAMILIES, BrowserFaceDescriptors, type BundledFontLocator, CJK_CHARACTER, CJK_FALLBACK_CHARACTER, DEFAULT_WEB_FONT_PROVIDER_SETTINGS, DEVANAGARI_CHARACTER, DocumentFont, DocumentFontEntry, DocumentFontInput, DownloadedFontCache, FaceWeight, FamilyFace, FontAxis, FontCandidateSource, FontFaceReadiness, FontFaceRef, FontFaceReference, FontFallbackManifestEntry, FontFallbackScript, FontFamilyOption, FontFamilySource, FontInfo, FontLoadedSource, FontManager, FontProviderLease, FontReadiness, FontReadinessStatus, FontReplacement, FontReplacementCounts, FontResolutionCandidate, FontResolutionDemand, FontResolutionEvent, FontResolutionListener, FontResolutionLoader, FontResolutionSettled, FontResolutionSnapshot, FontResolutionState, FontResolver, FontUnavailableReason, type GlyphOutlineProbe, GraphFontRequirements, HANGUL_CHARACTER, HAN_CHARACTER, HEBREW_CHARACTER, type HarfBuzzSubsetLocator, type HostFontFamily, HostFontLoader, HyperlinkRunOptions, HyperlinkSpan, InsertStyleSource, KANA_CHARACTER, LETTER_FALLBACK_SCRIPTS, LetterFallbackScript, LocalFontAccessState, MissingGlyphOccurrence, MissingGraphFontScriptsOptions, NamedInstance, NamedLocalFont, ObservedShapedLine, type OutlineCommand, PathPoint, PathTextCaret, PathTextLayout, PathTextLineMetrics, ResolvedWebFont, SampledPath, THAI_CHARACTER, TextCaret, TextCaseSegment, TextEditor, TextEditorState, TextFace, UnsupportedFontFormatError, WEB_FONT_PROVIDER_IDS, WEB_FONT_PROVIDER_LABELS, WebFontFetch, WebFontProviderId, WebFontResolver, adjustRunsForDelete, applyStyleToRange, browserFaceDescriptors, calibratePathTextLayout, chooseLocalFontMatch, cjkFallbackScriptForLanguage, cjkLocalFallbackFamilies, collectGraphFontKeys, collectGraphFontRequirements, collectNamedNodeFontFaces, collectNodeFontFaces, documentFontData, documentFontsOf, faceForStyle, faceStyleName, facesFromStyles, fallbackDrawsCharacter, findLocalFont, fitTextPathBoxToGlyphs, fontAxes, fontCoverageDemand, fontFaceDemand, fontFaceFromFigmaFontName, fontFaceRenderFamily, fontFallbackEntry, fontFallbackManifest, fontFallbackScriptForCharacter, fontFeatureTags, fontManager, fontRemoteCoverageDemand, fontResolver, fontTableView, fontWeightMatchOrder, getStyleAt, getTextPathData, hasFamilyFace, hasNamedInstance, hasTrueTypeOutlines, hyperlinkInRange, hyperlinkSpanAt, hyperlinkSpans, insertRunsWithStyle, insertedStyleAt, isDocumentFontFileName, isOpenableLinkURL, isTraditionalOnlyHan, isVariableFont, isWOFF2, layerTextStyleChanges, layoutPathTextFromAdvances, leaseFontProvider, listDocumentFonts, mergeArchiveFonts, missingGlyphCharacters, missingGlyphOccurrences, missingGlyphScripts, missingGlyphsByScript, missingGraphFontScripts, namedInstanceVariations, namedInstances, nearestArcPoint, nearestFamilyFace, normalizeLinkURL, normalizedCoverageText, pathTextCaret, pathTextIndexAt, pathTextSelectionQuads, pointAtArc, prepareDocumentFonts, probeGlyphOutlineCommands, readFontReadiness, reflowPathTextGlyphs, registerDocumentFonts, removeStyleFromRange, replaceDocumentFonts, resolveFontReadiness, runsAfterTyping, sampleTextPath, selectionHasStyle, setHarfBuzzSubsetLocator, sfntFamilyNames, sfntFont, sfntFontName, shownCharacters, shownText, shownTextSlice, shownTextStyle, standardFace, standardFaces, styleRunsWithHyperlink, textCaseSegments, textFaceName, textFallbackScriptsWithoutCoverage, textFontFace, textHasFallbackScript, textNeededFallbackScripts, textNeedsFallbackScript, textPathStartArc, textPathStartDistance, textStyleName, toggleBoldInRange, toggleDecorationInRange, toggleItalicInRange, transformTextCase, webFontSubsetsForText };
@@ -21,13 +21,14 @@ import { missingGlyphCharacters, missingGlyphOccurrences, missingGlyphScripts, m
21
21
  import { fontCoverageDemand, fontFaceDemand, fontRemoteCoverageDemand, fontResolver } from "./resolver/index.js";
22
22
  import { layerTextStyleChanges, shownTextStyle } from "./character-style.js";
23
23
  import { collectNamedNodeFontFaces, faceForStyle, faceStyleName, textFaceName, textStyleName } from "./font/names.js";
24
+ import { leaseFontProvider } from "./font/provider.js";
24
25
  import { textFallbackScriptsWithoutCoverage, textHasFallbackScript, textNeededFallbackScripts, textNeedsFallbackScript } from "./coverage.js";
25
26
  import { missingGraphFontScripts } from "./requirements/resolved.js";
26
- import { documentFontStatus } from "./font/status.js";
27
- import { prepareGraphFonts } from "./prepare.js";
27
+ import { readFontReadiness } from "./font/readiness.js";
28
+ import { resolveFontReadiness } from "./prepare.js";
28
29
  import { documentFontData, documentFontsOf, isDocumentFontFileName, mergeArchiveFonts, prepareDocumentFonts, registerDocumentFonts } from "./font/document.js";
29
30
  import { TextEditor } from "./editor.js";
30
31
  import { adjustRunsForDelete, applyStyleToRange, getStyleAt, insertRunsWithStyle, insertedStyleAt, removeStyleFromRange, runsAfterTyping, selectionHasStyle, toggleBoldInRange, toggleDecorationInRange, toggleItalicInRange } from "./style-runs.js";
31
32
  import { listDocumentFonts, replaceDocumentFonts } from "./replace-fonts.js";
32
33
  import { hyperlinkInRange, hyperlinkSpanAt, hyperlinkSpans, isOpenableLinkURL, normalizeLinkURL, styleRunsWithHyperlink } from "./hyperlink.js";
33
- export { ARABIC_CHARACTER, ARABIC_LOCAL_FALLBACK_FAMILIES, ARABIC_REMOTE_FALLBACK_FAMILIES, CJK_CHARACTER, CJK_FALLBACK_CHARACTER, DEFAULT_WEB_FONT_PROVIDER_SETTINGS, DEVANAGARI_CHARACTER, FontManager, FontResolver, HANGUL_CHARACTER, HAN_CHARACTER, HEBREW_CHARACTER, KANA_CHARACTER, LETTER_FALLBACK_SCRIPTS, THAI_CHARACTER, TextEditor, UnsupportedFontFormatError, WEB_FONT_PROVIDER_IDS, WEB_FONT_PROVIDER_LABELS, WebFontResolver, adjustRunsForDelete, applyStyleToRange, browserFaceDescriptors, calibratePathTextLayout, chooseLocalFontMatch, cjkFallbackScriptForLanguage, cjkLocalFallbackFamilies, collectGraphFontKeys, collectGraphFontRequirements, collectNamedNodeFontFaces, collectNodeFontFaces, documentFontData, documentFontStatus, documentFontsOf, faceForStyle, faceStyleName, facesFromStyles, fallbackDrawsCharacter, findLocalFont, fitTextPathBoxToGlyphs, fontAxes, fontCoverageDemand, fontFaceDemand, fontFaceFromFigmaFontName, fontFaceRenderFamily, fontFallbackEntry, fontFallbackManifest, fontFallbackScriptForCharacter, fontFeatureTags, fontManager, fontRemoteCoverageDemand, fontResolver, fontTableView, fontWeightMatchOrder, getStyleAt, getTextPathData, hasFamilyFace, hasNamedInstance, hasTrueTypeOutlines, hyperlinkInRange, hyperlinkSpanAt, hyperlinkSpans, insertRunsWithStyle, insertedStyleAt, isDocumentFontFileName, isOpenableLinkURL, isTraditionalOnlyHan, isVariableFont, isWOFF2, layerTextStyleChanges, layoutPathTextFromAdvances, listDocumentFonts, mergeArchiveFonts, missingGlyphCharacters, missingGlyphOccurrences, missingGlyphScripts, missingGlyphsByScript, missingGraphFontScripts, namedInstanceVariations, namedInstances, nearestArcPoint, nearestFamilyFace, normalizeLinkURL, normalizedCoverageText, pathTextCaret, pathTextIndexAt, pathTextSelectionQuads, pointAtArc, prepareDocumentFonts, prepareGraphFonts, probeGlyphOutlineCommands, reflowPathTextGlyphs, registerDocumentFonts, removeStyleFromRange, replaceDocumentFonts, runsAfterTyping, sampleTextPath, selectionHasStyle, setHarfBuzzSubsetLocator, sfntFamilyNames, sfntFont, sfntFontName, shownCharacters, shownText, shownTextSlice, shownTextStyle, standardFace, standardFaces, styleRunsWithHyperlink, textCaseSegments, textFaceName, textFallbackScriptsWithoutCoverage, textFontFace, textHasFallbackScript, textNeededFallbackScripts, textNeedsFallbackScript, textPathStartArc, textPathStartDistance, textStyleName, toggleBoldInRange, toggleDecorationInRange, toggleItalicInRange, transformTextCase, webFontSubsetsForText };
34
+ export { ARABIC_CHARACTER, ARABIC_LOCAL_FALLBACK_FAMILIES, ARABIC_REMOTE_FALLBACK_FAMILIES, CJK_CHARACTER, CJK_FALLBACK_CHARACTER, DEFAULT_WEB_FONT_PROVIDER_SETTINGS, DEVANAGARI_CHARACTER, FontManager, FontResolver, HANGUL_CHARACTER, HAN_CHARACTER, HEBREW_CHARACTER, KANA_CHARACTER, LETTER_FALLBACK_SCRIPTS, THAI_CHARACTER, TextEditor, UnsupportedFontFormatError, WEB_FONT_PROVIDER_IDS, WEB_FONT_PROVIDER_LABELS, WebFontResolver, adjustRunsForDelete, applyStyleToRange, browserFaceDescriptors, calibratePathTextLayout, chooseLocalFontMatch, cjkFallbackScriptForLanguage, cjkLocalFallbackFamilies, collectGraphFontKeys, collectGraphFontRequirements, collectNamedNodeFontFaces, collectNodeFontFaces, documentFontData, documentFontsOf, faceForStyle, faceStyleName, facesFromStyles, fallbackDrawsCharacter, findLocalFont, fitTextPathBoxToGlyphs, fontAxes, fontCoverageDemand, fontFaceDemand, fontFaceFromFigmaFontName, fontFaceRenderFamily, fontFallbackEntry, fontFallbackManifest, fontFallbackScriptForCharacter, fontFeatureTags, fontManager, fontRemoteCoverageDemand, fontResolver, fontTableView, fontWeightMatchOrder, getStyleAt, getTextPathData, hasFamilyFace, hasNamedInstance, hasTrueTypeOutlines, hyperlinkInRange, hyperlinkSpanAt, hyperlinkSpans, insertRunsWithStyle, insertedStyleAt, isDocumentFontFileName, isOpenableLinkURL, isTraditionalOnlyHan, isVariableFont, isWOFF2, layerTextStyleChanges, layoutPathTextFromAdvances, leaseFontProvider, listDocumentFonts, mergeArchiveFonts, missingGlyphCharacters, missingGlyphOccurrences, missingGlyphScripts, missingGlyphsByScript, missingGraphFontScripts, namedInstanceVariations, namedInstances, nearestArcPoint, nearestFamilyFace, normalizeLinkURL, normalizedCoverageText, pathTextCaret, pathTextIndexAt, pathTextSelectionQuads, pointAtArc, prepareDocumentFonts, probeGlyphOutlineCommands, readFontReadiness, reflowPathTextGlyphs, registerDocumentFonts, removeStyleFromRange, replaceDocumentFonts, resolveFontReadiness, runsAfterTyping, sampleTextPath, selectionHasStyle, setHarfBuzzSubsetLocator, sfntFamilyNames, sfntFont, sfntFontName, shownCharacters, shownText, shownTextSlice, shownTextStyle, standardFace, standardFaces, styleRunsWithHyperlink, textCaseSegments, textFaceName, textFallbackScriptsWithoutCoverage, textFontFace, textHasFallbackScript, textNeededFallbackScripts, textNeedsFallbackScript, textPathStartArc, textPathStartDistance, textStyleName, toggleBoldInRange, toggleDecorationInRange, toggleItalicInRange, transformTextCase, webFontSubsetsForText };
@@ -1,13 +1,18 @@
1
- import { DocumentFontStatus } from "./font/status.js";
1
+ import { FontReadiness } from "./font/readiness.js";
2
2
  import { SceneGraph } from "@pairdraw/scene-graph";
3
3
  //#region src/text/prepare.d.ts
4
- declare function prepareGraphFonts(graph: SceneGraph, nodeIds: readonly string[],
4
+ /**
5
+ * The one readiness read a caller needs: loads every face the document under `nodeIds` asks for,
6
+ * then reports what it can draw with. {@link readFontReadiness} reports the loaded state without
7
+ * loading, for a caller that only mirrors it in the UI.
8
+ */
9
+ declare function resolveFontReadiness(graph: SceneGraph, nodeIds: readonly string[],
5
10
  /** Characters a writer draws besides the text's own, which the fonts must map too. */
6
11
  extraCharacters?: string,
7
12
  /** An output that draws once and cannot wait for a face to arrive; see `settleUnavailableFonts`. */
8
13
  { settleUnavailable }?: {
9
14
  settleUnavailable?: boolean;
10
- }): Promise<DocumentFontStatus>;
15
+ }): Promise<FontReadiness>;
11
16
  //#endregion
12
- export { prepareGraphFonts };
17
+ export { resolveFontReadiness };
13
18
  //# sourceMappingURL=prepare.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"prepare.d.ts","names":[],"sources":["../../src/text/prepare.ts"],"mappings":";;;iBA6DsB,kBACpB,OAAO,YACP,4BAEA;;AAAA;;EAEE;EAA+B;IAChC,QAAQ"}
1
+ {"version":3,"file":"prepare.d.ts","names":[],"sources":["../../src/text/prepare.ts"],"mappings":";;;;;;;;iBAkEsB,qBACpB,OAAO,YACP,4BAEA;;AAAA;;EAEE;EAA+B;IAChC,QAAQ"}
@@ -5,7 +5,7 @@ import { fontManager } from "./font/manager.js";
5
5
  import { fontGlyphCoverageSync } from "./font/glyphs.js";
6
6
  import { fontFaceDemand, fontResolver } from "./resolver/index.js";
7
7
  import { missingGraphFontScripts } from "./requirements/resolved.js";
8
- import { documentFontStatus } from "./font/status.js";
8
+ import { readFontReadiness } from "./font/readiness.js";
9
9
  import { faceLoadKey, parseFontStyle } from "@pairdraw/scene-graph/font-style";
10
10
  import { uniq } from "es-toolkit";
11
11
  //#region src/text/prepare.ts
@@ -44,7 +44,12 @@ async function settleUnavailableFonts(faces, characters) {
44
44
  await fontManager.loadFont(DEFAULT_FONT_FAMILY, "Regular", characters);
45
45
  for (const { family, style } of unavailable) fontResolver.exhaust(fontFaceDemand(family, style, characters));
46
46
  }
47
- async function prepareGraphFonts(graph, nodeIds, extraCharacters = "", { settleUnavailable = false } = {}) {
47
+ /**
48
+ * The one readiness read a caller needs: loads every face the document under `nodeIds` asks for,
49
+ * then reports what it can draw with. {@link readFontReadiness} reports the loaded state without
50
+ * loading, for a caller that only mirrors it in the UI.
51
+ */
52
+ async function resolveFontReadiness(graph, nodeIds, extraCharacters = "", { settleUnavailable = false } = {}) {
48
53
  const collected = collectGraphFontRequirements(graph, nodeIds);
49
54
  const requirements = extraCharacters ? {
50
55
  ...collected,
@@ -66,9 +71,9 @@ async function prepareGraphFonts(graph, nodeIds, extraCharacters = "", { settleU
66
71
  }
67
72
  const emoji = requirements.nodes.map(savedEmojiCharacters).join("") + requirements.nodes.map(laidOutEmojiCharacters).join("");
68
73
  if (emoji && !canDrawPlatformEmoji()) await fontManager.loadRemoteFont(NOTO_COLOR_EMOJI_FAMILY, "Regular", emoji);
69
- return documentFontStatus(graph, nodeIds);
74
+ return readFontReadiness(graph, nodeIds);
70
75
  }
71
76
  //#endregion
72
- export { prepareGraphFonts };
77
+ export { resolveFontReadiness };
73
78
 
74
79
  //# sourceMappingURL=prepare.js.map