@pairdraw/core 0.19.2 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (847) hide show
  1. package/dist/ai/providers.d.ts +6 -0
  2. package/dist/ai/providers.d.ts.map +1 -1
  3. package/dist/ai/providers.js.map +1 -1
  4. package/dist/cache/resource.d.ts +8 -1
  5. package/dist/cache/resource.d.ts.map +1 -1
  6. package/dist/cache/resource.js +18 -0
  7. package/dist/cache/resource.js.map +1 -1
  8. package/dist/canvas/effects.d.ts +6 -4
  9. package/dist/canvas/effects.d.ts.map +1 -1
  10. package/dist/canvas/effects.js +37 -34
  11. package/dist/canvas/effects.js.map +1 -1
  12. package/dist/canvas/fills.d.ts.map +1 -1
  13. package/dist/canvas/fills.js +12 -8
  14. package/dist/canvas/fills.js.map +1 -1
  15. package/dist/canvas/images/adjustments.d.ts +18 -0
  16. package/dist/canvas/images/adjustments.d.ts.map +1 -0
  17. package/dist/canvas/images/adjustments.js +184 -0
  18. package/dist/canvas/images/adjustments.js.map +1 -0
  19. package/dist/canvas/images/sampling.d.ts +13 -0
  20. package/dist/canvas/images/sampling.d.ts.map +1 -0
  21. package/dist/canvas/images/sampling.js +49 -0
  22. package/dist/canvas/images/sampling.js.map +1 -0
  23. package/dist/canvas/index.d.ts +2 -2
  24. package/dist/canvas/masks.d.ts +1 -1
  25. package/dist/canvas/masks.d.ts.map +1 -1
  26. package/dist/canvas/masks.js.map +1 -1
  27. package/dist/canvas/noise/render.d.ts +15 -0
  28. package/dist/canvas/noise/render.d.ts.map +1 -0
  29. package/dist/canvas/noise/render.js +56 -0
  30. package/dist/canvas/noise/render.js.map +1 -0
  31. package/dist/canvas/noise/shader.d.ts +43 -0
  32. package/dist/canvas/noise/shader.d.ts.map +1 -0
  33. package/dist/canvas/noise/shader.js +161 -0
  34. package/dist/canvas/noise/shader.js.map +1 -0
  35. package/dist/canvas/noise/table.d.ts +13 -0
  36. package/dist/canvas/noise/table.d.ts.map +1 -0
  37. package/dist/canvas/noise/table.js +408 -0
  38. package/dist/canvas/noise/table.js.map +1 -0
  39. package/dist/canvas/noise/tile.d.ts +22 -0
  40. package/dist/canvas/noise/tile.d.ts.map +1 -0
  41. package/dist/canvas/noise/tile.js +73 -0
  42. package/dist/canvas/noise/tile.js.map +1 -0
  43. package/dist/canvas/outline-stroke.js +1 -1
  44. package/dist/canvas/overlays/auto-layout-hover.d.ts.map +1 -1
  45. package/dist/canvas/overlays/auto-layout-hover.js +31 -71
  46. package/dist/canvas/overlays/auto-layout-hover.js.map +1 -1
  47. package/dist/canvas/renderer/chunks/index.d.ts +1 -1
  48. package/dist/canvas/renderer/lifecycle.d.ts.map +1 -1
  49. package/dist/canvas/renderer/lifecycle.js +6 -0
  50. package/dist/canvas/renderer/lifecycle.js.map +1 -1
  51. package/dist/canvas/renderer/pipeline.d.ts.map +1 -1
  52. package/dist/canvas/renderer/pipeline.js +13 -1
  53. package/dist/canvas/renderer/pipeline.js.map +1 -1
  54. package/dist/canvas/renderer/play-scenes.d.ts +13 -0
  55. package/dist/canvas/renderer/play-scenes.d.ts.map +1 -0
  56. package/dist/canvas/renderer/play-scenes.js +40 -0
  57. package/dist/canvas/renderer/play-scenes.js.map +1 -0
  58. package/dist/canvas/renderer/tiles/cache.d.ts +19 -1
  59. package/dist/canvas/renderer/tiles/cache.d.ts.map +1 -1
  60. package/dist/canvas/renderer/tiles/cache.js +32 -1
  61. package/dist/canvas/renderer/tiles/cache.js.map +1 -1
  62. package/dist/canvas/renderer/tiles/controller.d.ts +11 -0
  63. package/dist/canvas/renderer/tiles/controller.d.ts.map +1 -1
  64. package/dist/canvas/renderer/tiles/controller.js +18 -1
  65. package/dist/canvas/renderer/tiles/controller.js.map +1 -1
  66. package/dist/canvas/renderer/tiles/index.d.ts +2 -2
  67. package/dist/canvas/renderer/tiles/planner.d.ts +1 -1
  68. package/dist/canvas/renderer/types.d.ts +18 -3
  69. package/dist/canvas/renderer/types.d.ts.map +1 -1
  70. package/dist/canvas/renderer/visual-bounds.d.ts +1 -1
  71. package/dist/canvas/renderer/visual-bounds.js +1 -1
  72. package/dist/canvas/renderer.d.ts +22 -2
  73. package/dist/canvas/renderer.d.ts.map +1 -1
  74. package/dist/canvas/renderer.js +29 -1
  75. package/dist/canvas/renderer.js.map +1 -1
  76. package/dist/canvas/scene.d.ts +2 -1
  77. package/dist/canvas/scene.d.ts.map +1 -1
  78. package/dist/canvas/scene.js +41 -9
  79. package/dist/canvas/scene.js.map +1 -1
  80. package/dist/canvas/shadows/silhouette.js +1 -1
  81. package/dist/canvas/texture.d.ts +20 -0
  82. package/dist/canvas/texture.d.ts.map +1 -0
  83. package/dist/canvas/texture.js +100 -0
  84. package/dist/canvas/texture.js.map +1 -0
  85. package/dist/clipboard.js +16 -5
  86. package/dist/clipboard.js.map +1 -1
  87. package/dist/constants.d.ts +5 -1
  88. package/dist/constants.d.ts.map +1 -1
  89. package/dist/constants.js +5 -1
  90. package/dist/constants.js.map +1 -1
  91. package/dist/design-jsx/renderer.d.ts.map +1 -1
  92. package/dist/design-memory/check.d.ts +90 -0
  93. package/dist/design-memory/check.d.ts.map +1 -0
  94. package/dist/design-memory/check.js +281 -0
  95. package/dist/design-memory/check.js.map +1 -0
  96. package/dist/design-memory/describe.d.ts +37 -0
  97. package/dist/design-memory/describe.d.ts.map +1 -0
  98. package/dist/design-memory/describe.js +52 -0
  99. package/dist/design-memory/describe.js.map +1 -0
  100. package/dist/design-memory/distil.d.ts +22 -0
  101. package/dist/design-memory/distil.d.ts.map +1 -0
  102. package/dist/design-memory/distil.js +54 -0
  103. package/dist/design-memory/distil.js.map +1 -0
  104. package/dist/design-memory/document.d.ts +12 -0
  105. package/dist/design-memory/document.d.ts.map +1 -0
  106. package/dist/design-memory/document.js +64 -0
  107. package/dist/design-memory/document.js.map +1 -0
  108. package/dist/design-memory/guard.d.ts +48 -0
  109. package/dist/design-memory/guard.d.ts.map +1 -0
  110. package/dist/design-memory/guard.js +105 -0
  111. package/dist/design-memory/guard.js.map +1 -0
  112. package/dist/design-memory/index.d.ts +9 -0
  113. package/dist/design-memory/index.js +9 -0
  114. package/dist/design-memory/refusal.d.ts +32 -0
  115. package/dist/design-memory/refusal.d.ts.map +1 -0
  116. package/dist/design-memory/refusal.js +68 -0
  117. package/dist/design-memory/refusal.js.map +1 -0
  118. package/dist/design-memory/rules.d.ts +63 -0
  119. package/dist/design-memory/rules.d.ts.map +1 -0
  120. package/dist/design-memory/rules.js +224 -0
  121. package/dist/design-memory/rules.js.map +1 -0
  122. package/dist/design-memory/values.d.ts +28 -0
  123. package/dist/design-memory/values.d.ts.map +1 -0
  124. package/dist/design-memory/values.js +160 -0
  125. package/dist/design-memory/values.js.map +1 -0
  126. package/dist/editor/alignment.js +1 -1
  127. package/dist/editor/bridges/components.d.ts +2 -0
  128. package/dist/editor/bridges/components.d.ts.map +1 -1
  129. package/dist/editor/bridges/components.js +2 -0
  130. package/dist/editor/bridges/components.js.map +1 -1
  131. package/dist/editor/bridges/undo.d.ts +1 -1
  132. package/dist/editor/clipboard/assets.js +1 -1
  133. package/dist/editor/clipboard/export.d.ts.map +1 -1
  134. package/dist/editor/clipboard/export.js +16 -2
  135. package/dist/editor/clipboard/export.js.map +1 -1
  136. package/dist/editor/clipboard/placement.d.ts +1 -1
  137. package/dist/editor/clipboard/placement.js +1 -1
  138. package/dist/editor/components/instances.d.ts +2 -0
  139. package/dist/editor/components/instances.d.ts.map +1 -1
  140. package/dist/editor/components/instances.js +22 -1
  141. package/dist/editor/components/instances.js.map +1 -1
  142. package/dist/editor/components.d.ts +2 -0
  143. package/dist/editor/components.d.ts.map +1 -1
  144. package/dist/editor/connectors/attach.js +1 -1
  145. package/dist/editor/create.d.ts +27 -3
  146. package/dist/editor/create.d.ts.map +1 -1
  147. package/dist/editor/create.js +16 -60
  148. package/dist/editor/create.js.map +1 -1
  149. package/dist/editor/design-memory.d.ts +11 -0
  150. package/dist/editor/design-memory.d.ts.map +1 -0
  151. package/dist/editor/design-memory.js +40 -0
  152. package/dist/editor/design-memory.js.map +1 -0
  153. package/dist/editor/design-tokens.d.ts +4 -0
  154. package/dist/editor/design-tokens.d.ts.map +1 -1
  155. package/dist/editor/design-tokens.js +30 -1
  156. package/dist/editor/design-tokens.js.map +1 -1
  157. package/dist/editor/document-colors.d.ts +23 -0
  158. package/dist/editor/document-colors.d.ts.map +1 -0
  159. package/dist/editor/document-colors.js +53 -0
  160. package/dist/editor/document-colors.js.map +1 -0
  161. package/dist/editor/eyedropper.d.ts +47 -0
  162. package/dist/editor/eyedropper.d.ts.map +1 -0
  163. package/dist/editor/eyedropper.js +168 -0
  164. package/dist/editor/eyedropper.js.map +1 -0
  165. package/dist/editor/fonts.d.ts +9 -0
  166. package/dist/editor/fonts.d.ts.map +1 -0
  167. package/dist/editor/fonts.js +14 -0
  168. package/dist/editor/fonts.js.map +1 -0
  169. package/dist/editor/history/atomic-tool.d.ts +9 -2
  170. package/dist/editor/history/atomic-tool.d.ts.map +1 -1
  171. package/dist/editor/history/atomic-tool.js +6 -0
  172. package/dist/editor/history/atomic-tool.js.map +1 -1
  173. package/dist/editor/history/capture.d.ts +13 -0
  174. package/dist/editor/history/capture.d.ts.map +1 -0
  175. package/dist/editor/history/capture.js +28 -0
  176. package/dist/editor/history/capture.js.map +1 -0
  177. package/dist/editor/history/document-change.d.ts.map +1 -1
  178. package/dist/editor/history/document-change.js +2 -22
  179. package/dist/editor/history/document-change.js.map +1 -1
  180. package/dist/editor/history/edit.d.ts +7 -0
  181. package/dist/editor/history/edit.d.ts.map +1 -1
  182. package/dist/editor/history/edit.js +4 -2
  183. package/dist/editor/history/edit.js.map +1 -1
  184. package/dist/editor/history/subtree.d.ts +9 -0
  185. package/dist/editor/history/subtree.d.ts.map +1 -1
  186. package/dist/editor/history/subtree.js +12 -2
  187. package/dist/editor/history/subtree.js.map +1 -1
  188. package/dist/editor/index.d.ts +4 -2
  189. package/dist/editor/index.js +4 -2
  190. package/dist/editor/pages.d.ts +7 -5
  191. package/dist/editor/pages.d.ts.map +1 -1
  192. package/dist/editor/pages.js +35 -25
  193. package/dist/editor/pages.js.map +1 -1
  194. package/dist/editor/play/states.d.ts +3 -1
  195. package/dist/editor/play/states.d.ts.map +1 -1
  196. package/dist/editor/play/states.js +1 -1
  197. package/dist/editor/play/states.js.map +1 -1
  198. package/dist/editor/read-only/actions.js +4 -0
  199. package/dist/editor/read-only/actions.js.map +1 -1
  200. package/dist/editor/render-requests.d.ts +18 -0
  201. package/dist/editor/render-requests.d.ts.map +1 -0
  202. package/dist/editor/render-requests.js +76 -0
  203. package/dist/editor/render-requests.js.map +1 -0
  204. package/dist/editor/scale/rescale.d.ts +1 -1
  205. package/dist/editor/selection/overlays.d.ts.map +1 -1
  206. package/dist/editor/selection/overlays.js +1 -1
  207. package/dist/editor/selection/overlays.js.map +1 -1
  208. package/dist/editor/selection/read.d.ts +4 -0
  209. package/dist/editor/selection.d.ts +5 -0
  210. package/dist/editor/selection.d.ts.map +1 -1
  211. package/dist/editor/tool-registry.d.ts.map +1 -1
  212. package/dist/editor/tool-registry.js +2 -1
  213. package/dist/editor/tool-registry.js.map +1 -1
  214. package/dist/editor/types.d.ts +5 -1
  215. package/dist/editor/types.d.ts.map +1 -1
  216. package/dist/editor/variations/create.d.ts +28 -0
  217. package/dist/editor/variations/create.d.ts.map +1 -0
  218. package/dist/editor/variations/create.js +176 -0
  219. package/dist/editor/variations/create.js.map +1 -0
  220. package/dist/editor/variations/pick.d.ts +16 -0
  221. package/dist/editor/variations/pick.d.ts.map +1 -0
  222. package/dist/editor/variations/pick.js +23 -0
  223. package/dist/editor/variations/pick.js.map +1 -0
  224. package/dist/editor/variations.d.ts +28 -0
  225. package/dist/editor/variations.d.ts.map +1 -0
  226. package/dist/editor/variations.js +88 -0
  227. package/dist/editor/variations.js.map +1 -0
  228. package/dist/figma-api/accessors/reactions.d.ts.map +1 -1
  229. package/dist/figma-api/accessors/reactions.js +4 -1
  230. package/dist/figma-api/accessors/reactions.js.map +1 -1
  231. package/dist/figma-api/accessors/text/index.js +3 -0
  232. package/dist/figma-api/accessors/text/index.js.map +1 -1
  233. package/dist/figma-api/accessors/text/opentype.d.ts +17 -0
  234. package/dist/figma-api/accessors/text/opentype.d.ts.map +1 -0
  235. package/dist/figma-api/accessors/text/opentype.js +28 -0
  236. package/dist/figma-api/accessors/text/opentype.js.map +1 -0
  237. package/dist/figma-api/accessors/visual.d.ts.map +1 -1
  238. package/dist/figma-api/accessors/visual.js +33 -0
  239. package/dist/figma-api/accessors/visual.js.map +1 -1
  240. package/dist/figma-api/effects.d.ts +79 -3
  241. package/dist/figma-api/effects.d.ts.map +1 -1
  242. package/dist/figma-api/effects.js +150 -9
  243. package/dist/figma-api/effects.js.map +1 -1
  244. package/dist/figma-api/index.d.ts +5 -0
  245. package/dist/figma-api/index.d.ts.map +1 -1
  246. package/dist/figma-api/index.js +6 -1
  247. package/dist/figma-api/index.js.map +1 -1
  248. package/dist/figma-api/overrides.d.ts +13 -1
  249. package/dist/figma-api/overrides.d.ts.map +1 -1
  250. package/dist/figma-api/overrides.js +196 -4
  251. package/dist/figma-api/overrides.js.map +1 -1
  252. package/dist/figma-api/paints.d.ts +3 -3
  253. package/dist/figma-api/paints.d.ts.map +1 -1
  254. package/dist/figma-api/paints.js +14 -4
  255. package/dist/figma-api/paints.js.map +1 -1
  256. package/dist/figma-api/proxy.d.ts +4 -1
  257. package/dist/figma-api/proxy.d.ts.map +1 -1
  258. package/dist/figma-api/proxy.js +1 -1
  259. package/dist/figma-api/proxy.js.map +1 -1
  260. package/dist/figma-api/reactions.d.ts +41 -13
  261. package/dist/figma-api/reactions.d.ts.map +1 -1
  262. package/dist/figma-api/reactions.js +113 -31
  263. package/dist/figma-api/reactions.js.map +1 -1
  264. package/dist/figma-api/render-bounds.js +1 -1
  265. package/dist/figma-api/surface.d.ts +6 -3
  266. package/dist/figma-api/surface.d.ts.map +1 -1
  267. package/dist/figma-api/surface.js +6 -2
  268. package/dist/figma-api/surface.js.map +1 -1
  269. package/dist/figma-api/transform.d.ts +1 -1
  270. package/dist/geometry/figma.d.ts +1 -1
  271. package/dist/geometry/image-crop.d.ts +1 -1
  272. package/dist/geometry/image-crop.js +1 -1
  273. package/dist/index.d.ts +4 -2
  274. package/dist/index.js +4 -2
  275. package/dist/io/formats/boolean-path.d.ts +19 -0
  276. package/dist/io/formats/boolean-path.d.ts.map +1 -0
  277. package/dist/io/formats/boolean-path.js +47 -0
  278. package/dist/io/formats/boolean-path.js.map +1 -0
  279. package/dist/io/formats/design-tokens/decode.js +1 -1
  280. package/dist/io/formats/design-tokens/index.d.ts +4 -1
  281. package/dist/io/formats/design-tokens/index.js +4 -1
  282. package/dist/io/formats/design-tokens/plan/changes.d.ts +5 -3
  283. package/dist/io/formats/design-tokens/plan/changes.d.ts.map +1 -1
  284. package/dist/io/formats/design-tokens/plan/changes.js +1 -1
  285. package/dist/io/formats/design-tokens/plan/changes.js.map +1 -1
  286. package/dist/io/formats/design-tokens/project.d.ts +17 -2
  287. package/dist/io/formats/design-tokens/project.d.ts.map +1 -1
  288. package/dist/io/formats/design-tokens/project.js +29 -8
  289. package/dist/io/formats/design-tokens/project.js.map +1 -1
  290. package/dist/io/formats/design-tokens/styles.d.ts.map +1 -1
  291. package/dist/io/formats/design-tokens/styles.js.map +1 -1
  292. package/dist/io/formats/design-tokens/sync/apply.d.ts +42 -0
  293. package/dist/io/formats/design-tokens/sync/apply.d.ts.map +1 -0
  294. package/dist/io/formats/design-tokens/sync/apply.js +73 -0
  295. package/dist/io/formats/design-tokens/sync/apply.js.map +1 -0
  296. package/dist/io/formats/design-tokens/sync/drift.d.ts +77 -0
  297. package/dist/io/formats/design-tokens/sync/drift.d.ts.map +1 -0
  298. package/dist/io/formats/design-tokens/sync/drift.js +391 -0
  299. package/dist/io/formats/design-tokens/sync/drift.js.map +1 -0
  300. package/dist/io/formats/design-tokens/sync/files.d.ts +15 -0
  301. package/dist/io/formats/design-tokens/sync/files.d.ts.map +1 -0
  302. package/dist/io/formats/design-tokens/sync/files.js +35 -0
  303. package/dist/io/formats/design-tokens/sync/files.js.map +1 -0
  304. package/dist/io/formats/drawio/edges.d.ts +7 -1
  305. package/dist/io/formats/drawio/edges.d.ts.map +1 -1
  306. package/dist/io/formats/drawio/edges.js +54 -1
  307. package/dist/io/formats/drawio/edges.js.map +1 -1
  308. package/dist/io/formats/drawio/export.d.ts.map +1 -1
  309. package/dist/io/formats/drawio/export.js +19 -2
  310. package/dist/io/formats/drawio/export.js.map +1 -1
  311. package/dist/io/formats/drawio/index.js +1 -0
  312. package/dist/io/formats/drawio/index.js.map +1 -1
  313. package/dist/io/formats/drawio/label.js +1 -1
  314. package/dist/io/formats/drawio/paint.js +1 -1
  315. package/dist/io/formats/drawio/placement.d.ts +1 -1
  316. package/dist/io/formats/fig/export/patch/index.d.ts.map +1 -1
  317. package/dist/io/formats/fig/export/patch/index.js +5 -0
  318. package/dist/io/formats/fig/export/patch/index.js.map +1 -1
  319. package/dist/io/formats/fig/thumbnail-page.d.ts +3 -4
  320. package/dist/io/formats/fig/thumbnail-page.d.ts.map +1 -1
  321. package/dist/io/formats/fig/thumbnail-page.js.map +1 -1
  322. package/dist/io/formats/html/import.d.ts.map +1 -1
  323. package/dist/io/formats/html/import.js +3 -1
  324. package/dist/io/formats/html/import.js.map +1 -1
  325. package/dist/io/formats/html/index.d.ts +2 -2
  326. package/dist/io/formats/html/index.d.ts.map +1 -1
  327. package/dist/io/formats/html/index.js +6 -4
  328. package/dist/io/formats/html/index.js.map +1 -1
  329. package/dist/io/formats/html/vectors.d.ts +2 -1
  330. package/dist/io/formats/html/vectors.d.ts.map +1 -1
  331. package/dist/io/formats/html/vectors.js +3 -2
  332. package/dist/io/formats/html/vectors.js.map +1 -1
  333. package/dist/io/formats/mermaid/styles.js +1 -1
  334. package/dist/io/formats/pdf/document.d.ts +3 -1
  335. package/dist/io/formats/pdf/document.d.ts.map +1 -1
  336. package/dist/io/formats/pdf/document.js +6 -3
  337. package/dist/io/formats/pdf/document.js.map +1 -1
  338. package/dist/io/formats/pdf/prepare.d.ts +1 -1
  339. package/dist/io/formats/pen/imports.d.ts +4 -1
  340. package/dist/io/formats/pen/imports.d.ts.map +1 -1
  341. package/dist/io/formats/pen/imports.js.map +1 -1
  342. package/dist/io/formats/pen/index.d.ts.map +1 -1
  343. package/dist/io/formats/pen/index.js +31 -3
  344. package/dist/io/formats/pen/index.js.map +1 -1
  345. package/dist/io/formats/pptx/export.js +1 -1
  346. package/dist/io/formats/pptx/geometry.d.ts +1 -1
  347. package/dist/io/formats/raster/adjusted-images.d.ts +15 -0
  348. package/dist/io/formats/raster/adjusted-images.d.ts.map +1 -0
  349. package/dist/io/formats/raster/adjusted-images.js +118 -0
  350. package/dist/io/formats/raster/adjusted-images.js.map +1 -0
  351. package/dist/io/formats/raster/headless.d.ts +11 -1
  352. package/dist/io/formats/raster/headless.d.ts.map +1 -1
  353. package/dist/io/formats/raster/headless.js +4 -4
  354. package/dist/io/formats/raster/headless.js.map +1 -1
  355. package/dist/io/formats/raster/index.d.ts +2 -2
  356. package/dist/io/formats/raster/pixels.d.ts +7 -1
  357. package/dist/io/formats/raster/pixels.d.ts.map +1 -1
  358. package/dist/io/formats/raster/pixels.js.map +1 -1
  359. package/dist/io/formats/raster/render.d.ts.map +1 -1
  360. package/dist/io/formats/raster/render.js +4 -0
  361. package/dist/io/formats/raster/render.js.map +1 -1
  362. package/dist/io/formats/svg/defs.d.ts +5 -6
  363. package/dist/io/formats/svg/defs.d.ts.map +1 -1
  364. package/dist/io/formats/svg/defs.js +1 -53
  365. package/dist/io/formats/svg/defs.js.map +1 -1
  366. package/dist/io/formats/svg/effects.d.ts +16 -0
  367. package/dist/io/formats/svg/effects.d.ts.map +1 -0
  368. package/dist/io/formats/svg/effects.js +126 -0
  369. package/dist/io/formats/svg/effects.js.map +1 -0
  370. package/dist/io/formats/svg/export.d.ts +7 -1
  371. package/dist/io/formats/svg/export.d.ts.map +1 -1
  372. package/dist/io/formats/svg/export.js +174 -36
  373. package/dist/io/formats/svg/export.js.map +1 -1
  374. package/dist/io/formats/svg/filter.d.ts +27 -0
  375. package/dist/io/formats/svg/filter.d.ts.map +1 -0
  376. package/dist/io/formats/svg/filter.js +44 -0
  377. package/dist/io/formats/svg/filter.js.map +1 -0
  378. package/dist/io/formats/svg/grain.d.ts +26 -0
  379. package/dist/io/formats/svg/grain.d.ts.map +1 -0
  380. package/dist/io/formats/svg/grain.js +298 -0
  381. package/dist/io/formats/svg/grain.js.map +1 -0
  382. package/dist/io/formats/svg/strokes.d.ts +1 -1
  383. package/dist/io/formats/svg/strokes.d.ts.map +1 -1
  384. package/dist/io/formats/svg/strokes.js +1 -2
  385. package/dist/io/formats/svg/strokes.js.map +1 -1
  386. package/dist/io/formats/svg/text/import.js +1 -1
  387. package/dist/io/formats/svg/text/layout.d.ts +5 -2
  388. package/dist/io/formats/svg/text/layout.d.ts.map +1 -1
  389. package/dist/io/formats/svg/text/layout.js +6 -3
  390. package/dist/io/formats/svg/text/layout.js.map +1 -1
  391. package/dist/io/formats/video/composite.d.ts +18 -0
  392. package/dist/io/formats/video/composite.d.ts.map +1 -0
  393. package/dist/io/formats/video/composite.js +79 -0
  394. package/dist/io/formats/video/composite.js.map +1 -0
  395. package/dist/io/formats/video/formats.d.ts +29 -0
  396. package/dist/io/formats/video/formats.d.ts.map +1 -0
  397. package/dist/io/formats/video/formats.js +43 -0
  398. package/dist/io/formats/video/formats.js.map +1 -0
  399. package/dist/io/formats/video/gif.d.ts +13 -0
  400. package/dist/io/formats/video/gif.d.ts.map +1 -0
  401. package/dist/io/formats/video/gif.js +56 -0
  402. package/dist/io/formats/video/gif.js.map +1 -0
  403. package/dist/io/formats/video/index.d.ts +9 -0
  404. package/dist/io/formats/video/index.js +9 -0
  405. package/dist/io/formats/video/plan.d.ts +64 -0
  406. package/dist/io/formats/video/plan.d.ts.map +1 -0
  407. package/dist/io/formats/video/plan.js +90 -0
  408. package/dist/io/formats/video/plan.js.map +1 -0
  409. package/dist/io/formats/video/record.d.ts +36 -0
  410. package/dist/io/formats/video/record.d.ts.map +1 -0
  411. package/dist/io/formats/video/record.js +154 -0
  412. package/dist/io/formats/video/record.js.map +1 -0
  413. package/dist/io/formats/video/sink.d.ts +29 -0
  414. package/dist/io/formats/video/sink.d.ts.map +1 -0
  415. package/dist/io/formats/video/sink.js +16 -0
  416. package/dist/io/formats/video/sink.js.map +1 -0
  417. package/dist/io/formats/video/size.d.ts +19 -0
  418. package/dist/io/formats/video/size.d.ts.map +1 -0
  419. package/dist/io/formats/video/size.js +26 -0
  420. package/dist/io/formats/video/size.js.map +1 -0
  421. package/dist/io/formats/video/webcodecs.d.ts +18 -0
  422. package/dist/io/formats/video/webcodecs.d.ts.map +1 -0
  423. package/dist/io/formats/video/webcodecs.js +74 -0
  424. package/dist/io/formats/video/webcodecs.js.map +1 -0
  425. package/dist/io/formats.d.ts.map +1 -1
  426. package/dist/io/formats.js +40 -11
  427. package/dist/io/formats.js.map +1 -1
  428. package/dist/io/types.d.ts +19 -4
  429. package/dist/io/types.d.ts.map +1 -1
  430. package/dist/kiwi/fig/parse/transfer.d.ts +1 -1
  431. package/dist/layout/auto-layout-handles.d.ts +66 -0
  432. package/dist/layout/auto-layout-handles.d.ts.map +1 -0
  433. package/dist/layout/auto-layout-handles.js +291 -0
  434. package/dist/layout/auto-layout-handles.js.map +1 -0
  435. package/dist/layout.d.ts +3 -2
  436. package/dist/layout.d.ts.map +1 -1
  437. package/dist/layout.js +2 -1
  438. package/dist/layout.js.map +1 -1
  439. package/dist/lint/fixes.d.ts.map +1 -1
  440. package/dist/lint/fixes.js +9 -3
  441. package/dist/lint/fixes.js.map +1 -1
  442. package/dist/lint/index.d.ts +3 -2
  443. package/dist/lint/index.js +2 -1
  444. package/dist/lint/linter.d.ts +12 -0
  445. package/dist/lint/linter.d.ts.map +1 -1
  446. package/dist/lint/linter.js +110 -8
  447. package/dist/lint/linter.js.map +1 -1
  448. package/dist/lint/presets.d.ts.map +1 -1
  449. package/dist/lint/presets.js +2 -0
  450. package/dist/lint/presets.js.map +1 -1
  451. package/dist/lint/rules/design-memory.d.ts +15 -0
  452. package/dist/lint/rules/design-memory.d.ts.map +1 -0
  453. package/dist/lint/rules/design-memory.js +90 -0
  454. package/dist/lint/rules/design-memory.js.map +1 -0
  455. package/dist/lint/rules/index.d.ts +6 -5
  456. package/dist/lint/rules/index.d.ts.map +1 -1
  457. package/dist/lint/rules/index.js +6 -2
  458. package/dist/lint/rules/index.js.map +1 -1
  459. package/dist/lint/rules/no-unbound-token-values.d.ts +6 -0
  460. package/dist/lint/rules/no-unbound-token-values.d.ts.map +1 -0
  461. package/dist/lint/rules/no-unbound-token-values.js +79 -0
  462. package/dist/lint/rules/no-unbound-token-values.js.map +1 -0
  463. package/dist/lint/types.d.ts +25 -2
  464. package/dist/lint/types.d.ts.map +1 -1
  465. package/dist/node/video.d.ts +12 -0
  466. package/dist/node/video.d.ts.map +1 -0
  467. package/dist/node/video.js +206 -0
  468. package/dist/node/video.js.map +1 -0
  469. package/dist/pairdraw-api/design-memory.d.ts +19 -0
  470. package/dist/pairdraw-api/design-memory.d.ts.map +1 -0
  471. package/dist/pairdraw-api/design-memory.js +39 -0
  472. package/dist/pairdraw-api/design-memory.js.map +1 -0
  473. package/dist/pairdraw-api/index.d.ts +45 -1
  474. package/dist/pairdraw-api/index.d.ts.map +1 -1
  475. package/dist/pairdraw-api/index.js +55 -2
  476. package/dist/pairdraw-api/index.js.map +1 -1
  477. package/dist/pairdraw-api/nodes.d.ts +12 -1
  478. package/dist/pairdraw-api/nodes.d.ts.map +1 -1
  479. package/dist/pairdraw-api/nodes.js +28 -1
  480. package/dist/pairdraw-api/nodes.js.map +1 -1
  481. package/dist/pairdraw-api/variations.d.ts +48 -0
  482. package/dist/pairdraw-api/variations.d.ts.map +1 -0
  483. package/dist/pairdraw-api/variations.js +76 -0
  484. package/dist/pairdraw-api/variations.js.map +1 -0
  485. package/dist/prototype/easing.d.ts +13 -0
  486. package/dist/prototype/easing.d.ts.map +1 -0
  487. package/dist/prototype/easing.js +36 -0
  488. package/dist/prototype/easing.js.map +1 -0
  489. package/dist/prototype/frames.d.ts +10 -0
  490. package/dist/prototype/frames.d.ts.map +1 -0
  491. package/dist/prototype/frames.js +12 -0
  492. package/dist/prototype/frames.js.map +1 -0
  493. package/dist/prototype/hit.d.ts +17 -0
  494. package/dist/prototype/hit.d.ts.map +1 -0
  495. package/dist/prototype/hit.js +45 -0
  496. package/dist/prototype/hit.js.map +1 -0
  497. package/dist/prototype/index.d.ts +14 -0
  498. package/dist/prototype/index.js +14 -0
  499. package/dist/prototype/pointer.d.ts +63 -0
  500. package/dist/prototype/pointer.d.ts.map +1 -0
  501. package/dist/prototype/pointer.js +104 -0
  502. package/dist/prototype/pointer.js.map +1 -0
  503. package/dist/prototype/reactions.d.ts +45 -0
  504. package/dist/prototype/reactions.d.ts.map +1 -0
  505. package/dist/prototype/reactions.js +122 -0
  506. package/dist/prototype/reactions.js.map +1 -0
  507. package/dist/prototype/scene.d.ts +35 -0
  508. package/dist/prototype/scene.d.ts.map +1 -0
  509. package/dist/prototype/scene.js +86 -0
  510. package/dist/prototype/scene.js.map +1 -0
  511. package/dist/prototype/scenes.d.ts +81 -0
  512. package/dist/prototype/scenes.d.ts.map +1 -0
  513. package/dist/prototype/scenes.js +175 -0
  514. package/dist/prototype/scenes.js.map +1 -0
  515. package/dist/prototype/scroll.d.ts +48 -0
  516. package/dist/prototype/scroll.d.ts.map +1 -0
  517. package/dist/prototype/scroll.js +159 -0
  518. package/dist/prototype/scroll.js.map +1 -0
  519. package/dist/prototype/session.d.ts +71 -0
  520. package/dist/prototype/session.d.ts.map +1 -0
  521. package/dist/prototype/session.js +135 -0
  522. package/dist/prototype/session.js.map +1 -0
  523. package/dist/prototype/smart-animate/animation.d.ts +34 -0
  524. package/dist/prototype/smart-animate/animation.d.ts.map +1 -0
  525. package/dist/prototype/smart-animate/animation.js +212 -0
  526. package/dist/prototype/smart-animate/animation.js.map +1 -0
  527. package/dist/prototype/smart-animate/match.d.ts +24 -0
  528. package/dist/prototype/smart-animate/match.d.ts.map +1 -0
  529. package/dist/prototype/smart-animate/match.js +72 -0
  530. package/dist/prototype/smart-animate/match.js.map +1 -0
  531. package/dist/prototype/snapshot.d.ts +19 -0
  532. package/dist/prototype/snapshot.d.ts.map +1 -0
  533. package/dist/prototype/snapshot.js +56 -0
  534. package/dist/prototype/snapshot.js.map +1 -0
  535. package/dist/prototype/timeline.d.ts +132 -0
  536. package/dist/prototype/timeline.d.ts.map +1 -0
  537. package/dist/prototype/timeline.js +260 -0
  538. package/dist/prototype/timeline.js.map +1 -0
  539. package/dist/rpc/read-commands.js +1 -1
  540. package/dist/text/font/features.d.ts +9 -0
  541. package/dist/text/font/features.d.ts.map +1 -0
  542. package/dist/text/font/features.js +27 -0
  543. package/dist/text/font/features.js.map +1 -0
  544. package/dist/text/font/manager.d.ts +12 -0
  545. package/dist/text/font/manager.d.ts.map +1 -1
  546. package/dist/text/font/manager.js +60 -1
  547. package/dist/text/font/manager.js.map +1 -1
  548. package/dist/text/index.d.ts +10 -8
  549. package/dist/text/index.js +3 -1
  550. package/dist/text/replace-fonts.d.ts +41 -0
  551. package/dist/text/replace-fonts.d.ts.map +1 -0
  552. package/dist/text/replace-fonts.js +121 -0
  553. package/dist/text/replace-fonts.js.map +1 -0
  554. package/dist/tools/analyze/responsive/index.d.ts +15 -0
  555. package/dist/tools/analyze/responsive/index.d.ts.map +1 -0
  556. package/dist/tools/analyze/responsive/index.js +203 -0
  557. package/dist/tools/analyze/responsive/index.js.map +1 -0
  558. package/dist/tools/analyze.d.ts +2 -1
  559. package/dist/tools/analyze.js +2 -1
  560. package/dist/tools/codegen/token-sync.d.ts +7 -0
  561. package/dist/tools/codegen/token-sync.d.ts.map +1 -0
  562. package/dist/tools/codegen/token-sync.js +85 -0
  563. package/dist/tools/codegen/token-sync.js.map +1 -0
  564. package/dist/tools/codegen/tokens.d.ts +1 -1
  565. package/dist/tools/codegen.d.ts +2 -1
  566. package/dist/tools/codegen.js +2 -1
  567. package/dist/tools/create/basic.js +1 -1
  568. package/dist/tools/create/behaviours.js +1 -1
  569. package/dist/tools/create/components.d.ts.map +1 -1
  570. package/dist/tools/create/components.js +4 -0
  571. package/dist/tools/create/components.js.map +1 -1
  572. package/dist/tools/create/html.js +3 -2
  573. package/dist/tools/create/html.js.map +1 -1
  574. package/dist/tools/create/icons.d.ts.map +1 -1
  575. package/dist/tools/create/icons.js +2 -1
  576. package/dist/tools/create/icons.js.map +1 -1
  577. package/dist/tools/create/mermaid.js +2 -1
  578. package/dist/tools/create/mermaid.js.map +1 -1
  579. package/dist/tools/create/render.js +1 -1
  580. package/dist/tools/create/svg.js +2 -1
  581. package/dist/tools/create/svg.js.map +1 -1
  582. package/dist/tools/create/vector.js +1 -1
  583. package/dist/tools/design-memory.d.ts +8 -0
  584. package/dist/tools/design-memory.d.ts.map +1 -0
  585. package/dist/tools/design-memory.js +68 -0
  586. package/dist/tools/design-memory.js.map +1 -0
  587. package/dist/tools/image-ai/generate.d.ts.map +1 -1
  588. package/dist/tools/image-ai/generate.js +3 -1
  589. package/dist/tools/image-ai/generate.js.map +1 -1
  590. package/dist/tools/index.d.ts +2 -1
  591. package/dist/tools/index.js +2 -1
  592. package/dist/tools/modify/fonts.d.ts +6 -0
  593. package/dist/tools/modify/fonts.d.ts.map +1 -0
  594. package/dist/tools/modify/fonts.js +27 -0
  595. package/dist/tools/modify/fonts.js.map +1 -0
  596. package/dist/tools/modify/paint.js +1 -1
  597. package/dist/tools/modify/reactions.d.ts.map +1 -1
  598. package/dist/tools/modify/reactions.js +3 -3
  599. package/dist/tools/modify/reactions.js.map +1 -1
  600. package/dist/tools/modify/text.d.ts.map +1 -1
  601. package/dist/tools/modify/text.js +26 -5
  602. package/dist/tools/modify/text.js.map +1 -1
  603. package/dist/tools/modify/update.d.ts +10 -1
  604. package/dist/tools/modify/update.d.ts.map +1 -1
  605. package/dist/tools/modify/update.js +34 -3
  606. package/dist/tools/modify/update.js.map +1 -1
  607. package/dist/tools/modify.d.ts +2 -1
  608. package/dist/tools/modify.js +2 -1
  609. package/dist/tools/read/fonts.d.ts.map +1 -1
  610. package/dist/tools/read/fonts.js +17 -2
  611. package/dist/tools/read/fonts.js.map +1 -1
  612. package/dist/tools/read/libraries.js +2 -1
  613. package/dist/tools/read/libraries.js.map +1 -1
  614. package/dist/tools/read/space.d.ts +3 -1
  615. package/dist/tools/read/space.d.ts.map +1 -1
  616. package/dist/tools/read/space.js +4 -3
  617. package/dist/tools/read/space.js.map +1 -1
  618. package/dist/tools/registry/core.d.ts +1 -1
  619. package/dist/tools/registry/core.d.ts.map +1 -1
  620. package/dist/tools/registry/core.js +3 -1
  621. package/dist/tools/registry/core.js.map +1 -1
  622. package/dist/tools/registry/extended.d.ts.map +1 -1
  623. package/dist/tools/registry/extended.js +16 -1
  624. package/dist/tools/registry/extended.js.map +1 -1
  625. package/dist/tools/schema.d.ts +18 -2
  626. package/dist/tools/schema.d.ts.map +1 -1
  627. package/dist/tools/schema.js +1 -1
  628. package/dist/tools/schema.js.map +1 -1
  629. package/dist/tools/stock-photo.js +1 -0
  630. package/dist/tools/stock-photo.js.map +1 -1
  631. package/dist/tools/structure/basic.d.ts.map +1 -1
  632. package/dist/tools/structure/basic.js +1 -0
  633. package/dist/tools/structure/basic.js.map +1 -1
  634. package/dist/tools/structure/batch.d.ts.map +1 -1
  635. package/dist/tools/structure/batch.js +8 -1
  636. package/dist/tools/structure/batch.js.map +1 -1
  637. package/dist/tools/structure/hierarchy.d.ts.map +1 -1
  638. package/dist/tools/structure/hierarchy.js +4 -0
  639. package/dist/tools/structure/hierarchy.js.map +1 -1
  640. package/dist/tools/structure/variations.d.ts +8 -0
  641. package/dist/tools/structure/variations.d.ts.map +1 -0
  642. package/dist/tools/structure/variations.js +106 -0
  643. package/dist/tools/structure/variations.js.map +1 -0
  644. package/dist/tools/structure.d.ts +2 -1
  645. package/dist/tools/structure.js +2 -1
  646. package/dist/tools/styles/types.d.ts +2 -4
  647. package/dist/tools/styles/types.d.ts.map +1 -1
  648. package/dist/tools/styles/types.js.map +1 -1
  649. package/dist/tools/vector/boolean.d.ts.map +1 -1
  650. package/dist/tools/vector/boolean.js +4 -0
  651. package/dist/tools/vector/boolean.js.map +1 -1
  652. package/dist/tools/vector/vectorize.js +1 -0
  653. package/dist/tools/vector/vectorize.js.map +1 -1
  654. package/dist/tools/vector/video.d.ts +6 -0
  655. package/dist/tools/vector/video.d.ts.map +1 -0
  656. package/dist/tools/vector/video.js +133 -0
  657. package/dist/tools/vector/video.js.map +1 -0
  658. package/dist/tools/vector.d.ts +2 -1
  659. package/dist/tools/vector.js +2 -1
  660. package/dist/tools/video-host.d.ts +12 -0
  661. package/dist/tools/video-host.d.ts.map +1 -0
  662. package/dist/tools/video-host.js +19 -0
  663. package/dist/tools/video-host.js.map +1 -0
  664. package/dist/vector/point-transform.d.ts +1 -1
  665. package/dist/vector/vectorize/svg/to-vectors.d.ts +1 -1
  666. package/package.json +31 -9
  667. package/src/ai/providers.ts +2 -0
  668. package/src/cache/resource.ts +24 -1
  669. package/src/canvas/effects.ts +47 -50
  670. package/src/canvas/fills.ts +19 -15
  671. package/src/canvas/images/adjustments.ts +203 -0
  672. package/src/canvas/images/sampling.ts +88 -0
  673. package/src/canvas/index.ts +1 -0
  674. package/src/canvas/masks.ts +1 -1
  675. package/src/canvas/noise/render.ts +75 -0
  676. package/src/canvas/noise/shader.ts +161 -0
  677. package/src/canvas/noise/table.ts +91 -0
  678. package/src/canvas/noise/tile.ts +94 -0
  679. package/src/canvas/overlays/auto-layout-hover.ts +47 -65
  680. package/src/canvas/renderer/lifecycle.ts +6 -0
  681. package/src/canvas/renderer/pipeline.ts +19 -1
  682. package/src/canvas/renderer/play-scenes.ts +51 -0
  683. package/src/canvas/renderer/tiles/cache.ts +54 -1
  684. package/src/canvas/renderer/tiles/controller.ts +30 -1
  685. package/src/canvas/renderer/types.ts +18 -2
  686. package/src/canvas/renderer.ts +40 -3
  687. package/src/canvas/scene.ts +65 -9
  688. package/src/canvas/texture.ts +136 -0
  689. package/src/clipboard.ts +23 -10
  690. package/src/constants.ts +6 -0
  691. package/src/design-memory/check.ts +376 -0
  692. package/src/design-memory/describe.ts +77 -0
  693. package/src/design-memory/distil.ts +69 -0
  694. package/src/design-memory/document.ts +80 -0
  695. package/src/design-memory/guard.ts +157 -0
  696. package/src/design-memory/index.ts +8 -0
  697. package/src/design-memory/refusal.ts +90 -0
  698. package/src/design-memory/rules.ts +274 -0
  699. package/src/design-memory/values.ts +179 -0
  700. package/src/editor/bridges/components.ts +2 -0
  701. package/src/editor/clipboard/export.ts +24 -7
  702. package/src/editor/components/instances.ts +31 -0
  703. package/src/editor/create.ts +25 -69
  704. package/src/editor/design-memory.ts +39 -0
  705. package/src/editor/design-tokens.ts +41 -2
  706. package/src/editor/document-colors.ts +65 -0
  707. package/src/editor/eyedropper.ts +198 -0
  708. package/src/editor/fonts.ts +19 -0
  709. package/src/editor/history/atomic-tool.ts +29 -1
  710. package/src/editor/history/capture.ts +19 -0
  711. package/src/editor/history/document-change.ts +5 -17
  712. package/src/editor/history/edit.ts +11 -1
  713. package/src/editor/history/subtree.ts +13 -2
  714. package/src/editor/index.ts +11 -0
  715. package/src/editor/pages.ts +40 -29
  716. package/src/editor/play/states.ts +1 -1
  717. package/src/editor/read-only/actions.ts +4 -0
  718. package/src/editor/render-requests.ts +83 -0
  719. package/src/editor/selection/overlays.ts +1 -0
  720. package/src/editor/tool-registry.ts +2 -1
  721. package/src/editor/types.ts +4 -0
  722. package/src/editor/variations/create.ts +235 -0
  723. package/src/editor/variations/pick.ts +35 -0
  724. package/src/editor/variations.ts +110 -0
  725. package/src/figma-api/accessors/reactions.ts +11 -1
  726. package/src/figma-api/accessors/text/index.ts +7 -0
  727. package/src/figma-api/accessors/text/opentype.ts +33 -0
  728. package/src/figma-api/accessors/visual.ts +55 -2
  729. package/src/figma-api/compatibility.ts +5 -2
  730. package/src/figma-api/effects.ts +143 -5
  731. package/src/figma-api/index.ts +10 -0
  732. package/src/figma-api/overrides.ts +295 -3
  733. package/src/figma-api/paints.ts +24 -9
  734. package/src/figma-api/proxy.ts +6 -1
  735. package/src/figma-api/reactions.ts +130 -32
  736. package/src/figma-api/surface.ts +6 -2
  737. package/src/global.d.ts +26 -0
  738. package/src/io/formats/boolean-path.ts +60 -0
  739. package/src/io/formats/design-tokens/index.ts +21 -0
  740. package/src/io/formats/design-tokens/plan/changes.ts +4 -1
  741. package/src/io/formats/design-tokens/project.ts +40 -9
  742. package/src/io/formats/design-tokens/styles.ts +10 -2
  743. package/src/io/formats/design-tokens/sync/apply.ts +130 -0
  744. package/src/io/formats/design-tokens/sync/drift.ts +587 -0
  745. package/src/io/formats/design-tokens/sync/files.ts +40 -0
  746. package/src/io/formats/drawio/edges.ts +65 -0
  747. package/src/io/formats/drawio/export.ts +37 -14
  748. package/src/io/formats/drawio/index.ts +2 -0
  749. package/src/io/formats/fig/export/patch/index.ts +8 -0
  750. package/src/io/formats/fig/thumbnail-page.ts +4 -4
  751. package/src/io/formats/html/import.ts +9 -1
  752. package/src/io/formats/html/index.ts +14 -7
  753. package/src/io/formats/html/vectors.ts +8 -2
  754. package/src/io/formats/pdf/document.ts +14 -4
  755. package/src/io/formats/pen/imports.ts +5 -6
  756. package/src/io/formats/pen/index.ts +36 -5
  757. package/src/io/formats/raster/adjusted-images.ts +125 -0
  758. package/src/io/formats/raster/headless.ts +3 -3
  759. package/src/io/formats/raster/index.ts +6 -1
  760. package/src/io/formats/raster/pixels.ts +7 -0
  761. package/src/io/formats/raster/render.ts +12 -1
  762. package/src/io/formats/svg/defs.ts +4 -72
  763. package/src/io/formats/svg/effects.ts +131 -0
  764. package/src/io/formats/svg/export.ts +278 -46
  765. package/src/io/formats/svg/filter.ts +47 -0
  766. package/src/io/formats/svg/grain.ts +249 -0
  767. package/src/io/formats/svg/strokes.ts +2 -2
  768. package/src/io/formats/svg/text/layout.ts +13 -3
  769. package/src/io/formats/video/composite.ts +79 -0
  770. package/src/io/formats/video/formats.ts +77 -0
  771. package/src/io/formats/video/gif.ts +65 -0
  772. package/src/io/formats/video/index.ts +30 -0
  773. package/src/io/formats/video/plan.ts +116 -0
  774. package/src/io/formats/video/record.ts +227 -0
  775. package/src/io/formats/video/sink.ts +32 -0
  776. package/src/io/formats/video/size.ts +25 -0
  777. package/src/io/formats/video/webcodecs.ts +89 -0
  778. package/src/io/formats.ts +59 -11
  779. package/src/io/types.ts +29 -10
  780. package/src/layout/auto-layout-handles.ts +396 -0
  781. package/src/layout.ts +2 -0
  782. package/src/lint/fixes.ts +12 -3
  783. package/src/lint/index.ts +3 -1
  784. package/src/lint/linter.ts +107 -10
  785. package/src/lint/presets.ts +2 -0
  786. package/src/lint/rules/design-memory.ts +97 -0
  787. package/src/lint/rules/index.ts +6 -1
  788. package/src/lint/rules/no-unbound-token-values.ts +73 -0
  789. package/src/lint/types.ts +32 -0
  790. package/src/node/video.ts +196 -0
  791. package/src/pairdraw-api/design-memory.ts +61 -0
  792. package/src/pairdraw-api/index.ts +81 -0
  793. package/src/pairdraw-api/nodes.ts +38 -0
  794. package/src/pairdraw-api/variations.ts +109 -0
  795. package/src/prototype/easing.ts +37 -0
  796. package/src/prototype/frames.ts +9 -0
  797. package/src/prototype/hit.ts +70 -0
  798. package/src/prototype/index.ts +69 -0
  799. package/src/prototype/pointer.ts +146 -0
  800. package/src/prototype/reactions.ts +178 -0
  801. package/src/prototype/scene.ts +116 -0
  802. package/src/prototype/scenes.ts +256 -0
  803. package/src/prototype/scroll.ts +190 -0
  804. package/src/prototype/session.ts +188 -0
  805. package/src/prototype/smart-animate/animation.ts +267 -0
  806. package/src/prototype/smart-animate/match.ts +85 -0
  807. package/src/prototype/snapshot.ts +60 -0
  808. package/src/prototype/timeline.ts +400 -0
  809. package/src/text/font/features.ts +27 -0
  810. package/src/text/font/manager.ts +79 -1
  811. package/src/text/index.ts +2 -0
  812. package/src/text/replace-fonts.ts +171 -0
  813. package/src/tools/analyze/responsive/index.ts +264 -0
  814. package/src/tools/analyze.ts +2 -0
  815. package/src/tools/codegen/token-sync.ts +98 -0
  816. package/src/tools/codegen.ts +1 -0
  817. package/src/tools/create/components.ts +4 -0
  818. package/src/tools/create/html.ts +1 -0
  819. package/src/tools/create/icons.ts +1 -0
  820. package/src/tools/create/mermaid.ts +1 -0
  821. package/src/tools/create/svg.ts +1 -0
  822. package/src/tools/design-memory.ts +72 -0
  823. package/src/tools/image-ai/generate.ts +2 -0
  824. package/src/tools/index.ts +1 -0
  825. package/src/tools/modify/fonts.ts +34 -0
  826. package/src/tools/modify/reactions.ts +15 -8
  827. package/src/tools/modify/text.ts +42 -5
  828. package/src/tools/modify/update.ts +46 -2
  829. package/src/tools/modify.ts +1 -0
  830. package/src/tools/read/fonts.ts +24 -2
  831. package/src/tools/read/libraries.ts +1 -0
  832. package/src/tools/read/space.ts +3 -2
  833. package/src/tools/registry/core.ts +3 -1
  834. package/src/tools/registry/extended.ts +28 -1
  835. package/src/tools/schema.ts +28 -4
  836. package/src/tools/stock-photo.ts +1 -0
  837. package/src/tools/structure/basic.ts +1 -0
  838. package/src/tools/structure/batch.ts +12 -1
  839. package/src/tools/structure/hierarchy.ts +4 -0
  840. package/src/tools/structure/variations.ts +118 -0
  841. package/src/tools/structure.ts +2 -0
  842. package/src/tools/styles/types.ts +3 -4
  843. package/src/tools/vector/boolean.ts +4 -0
  844. package/src/tools/vector/vectorize.ts +1 -0
  845. package/src/tools/vector/video.ts +228 -0
  846. package/src/tools/vector.ts +1 -0
  847. package/src/tools/video-host.ts +18 -0
@@ -1 +1 @@
1
- {"version":3,"file":"text.js","names":[],"sources":["../../../src/tools/modify/text.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport type { Color } from '@pairdraw/scene-graph/primitives'\n\nimport type { FigmaAPI, FigmaNodeProxy } from '#core/figma-api'\nimport type { FigmaFontName, FigmaFontNameInput } from '#core/figma-api/fonts/names'\nimport type { FigmaVariationSettings } from '#core/figma-api/fonts/variations'\nimport { PairdrawAPI } from '#core/pairdraw-api'\nimport { normalizeLinkURL } from '#core/text/hyperlink'\nimport { collectNodeFontFaces } from '#core/text/requirements/collect'\nimport {\n parseOptionalToolColor,\n toolNumber,\n nodeIdInputSchema,\n defineTool,\n nodeNotFound,\n toolFailure\n} from '#core/tools/schema'\n\n/**\n * A link a text tool sets, as the editor's link field takes it: a web or mail address, with\n * `https:` or `mailto:` added when typed without a scheme. Null or blank removes the link.\n */\nconst hyperlinkInputSchema = v.optional(\n v.pipe(\n v.nullable(v.string()),\n v.description(\n 'Link the text opens: an http(s) or mailto address (\"example.com\" becomes https://example.com, \"hi@example.com\" becomes mailto:). null or \"\" removes the link. Links are not underlined automatically; set text_decoration for that.'\n )\n )\n)\n\n/**\n * A scheme at the start of a typed link, even with a digit after its colon (`tel:123`), unless it\n * reads as a host and port (`localhost:3000`, `example.com:8080`), which gets `https://`.\n */\nconst TYPED_SCHEME = /^([a-z][a-z\\d+.-]*):/i\n\n/** A web address in the form the Figma API's link setter takes: `http(s)://host…`. */\nconst WEB_URL = /^https?:\\/\\/[^\\s/?#]+\\S*$/\n\n/** Whether a typed link names a scheme other than the http, https, and mailto links take. */\nfunction hasForeignScheme(typed: string): boolean {\n const scheme = TYPED_SCHEME.exec(typed)?.[1]?.toLowerCase()\n if (!scheme || scheme.includes('.') || scheme === 'localhost') return false\n return !['http', 'https', 'mailto'].includes(scheme)\n}\n\n/** What setting `hyperlink` asks for: no change, a removal, a URL, or an address it refuses. */\nfunction requestedHyperlink(\n hyperlink: string | null | undefined\n): { link: { type: 'URL'; value: string } | null } | { error: string } | null {\n if (hyperlink === undefined) return null\n if (hyperlink === null || hyperlink.trim() === '') return { link: null }\n const url = hasForeignScheme(hyperlink.trim()) ? null : normalizeLinkURL(hyperlink)\n if (!url) {\n return {\n error: `\"${hyperlink}\" is not a link the editor opens: use an http, https, or mailto address`\n }\n }\n // Figma keeps schemes in lower case and web addresses as `scheme://host`, so a loosely typed\n // `http:example.com` is written as the URL it parses to.\n const lowered = url.replace(TYPED_SCHEME, (scheme) => scheme.toLowerCase())\n const value =\n lowered.startsWith('mailto:') || WEB_URL.test(lowered) ? lowered : new URL(lowered).href\n return { link: { type: 'URL', value } }\n}\n\n/** The fonts a text layer uses, which an edit that lays it out again needs loaded. */\nexport function textFonts(figma: FigmaAPI, id: string): FigmaFontNameInput[] {\n const node = figma.graph.getNode(id)\n return node ? collectNodeFontFaces(node) : []\n}\n\nexport const setText = defineTool({\n name: 'set_text',\n\n description: 'Set text content of a text node.',\n execution: { kind: 'sync', mutation: 'properties' },\n input: v.strictObject({\n id: nodeIdInputSchema,\n text: v.pipe(v.string(), v.description('Text content'))\n }),\n fonts: (figma, { id }) => textFonts(figma, id),\n execute: (figma, { id, text }) => {\n const node = figma.getNodeById(id)\n if (!node) return { error: `Node \"${id}\" not found` }\n node.characters = text\n return { id, text }\n }\n})\n\n/** Variable font axes a font tool can set, as Figma's `variationSettings`. */\n// An object with a value for every key rather than a record: a record publishes `propertyNames`,\n// which OpenAI refuses, and a JSON object's keys are strings anyway.\nconst variationsInputSchema = v.optional(\n v.pipe(\n v.objectWithRest({}, v.number()),\n v.description(\n 'Variable font axis values by OpenType tag (e.g. {\"wght\": 550, \"wdth\": 75}); axes left out keep the style\\'s values. Without a style, the nearest named style is picked.'\n )\n )\n)\n\n/**\n * The font a font tool gives text: what it names, the rest from `current`. Axes without a style\n * leave the style out, for the nearest named style to be picked.\n */\nfunction fontNameInput(\n args: { family?: string; style?: string; variations?: FigmaVariationSettings },\n current: FigmaFontName | null\n): FigmaFontNameInput {\n return {\n family: args.family ?? current?.family ?? '',\n style: args.style ?? (args.variations ? undefined : (current?.style ?? 'Regular')),\n variationSettings: args.variations\n }\n}\n\n/**\n * The font `set_font` gives the text, or null when it keeps the text's. Text set in several fonts\n * takes the given family or style for all of it, keeping the rest from its first character. Axes\n * without a style are set per range, each range taking its nearest named style, as in Figma.\n */\nfunction requestedFont(\n node: FigmaNodeProxy,\n args: { family?: string; style?: string; variations?: FigmaVariationSettings }\n): { whole: FigmaFontName } | { perRange: FigmaFontNameInput } | null {\n if (!args.family && !args.style && !args.variations) return null\n const fontName =\n typeof node.fontName === 'symbol' && node.characters.length > 0\n ? node.getRangeFontName(0, 1)\n : node.fontName\n const current = typeof fontName === 'symbol' ? null : fontName\n const family = args.family ?? current?.family ?? ''\n if (args.variations && !args.style && node.characters.length > 0) {\n return { perRange: { family, variationSettings: args.variations } }\n }\n const style = args.style ?? current?.style ?? 'Regular'\n return { whole: { family, style, variationSettings: args.variations } }\n}\n\nexport const setFont = defineTool({\n name: 'set_font',\n\n description: 'Set font properties of a text node.',\n execution: { kind: 'sync', mutation: 'properties' },\n input: v.strictObject({\n id: nodeIdInputSchema,\n family: v.optional(v.pipe(v.string(), v.description('Font family name'))),\n size: v.optional(toolNumber(v.pipe(v.number(), v.minValue(1), v.description('Font size')))),\n style: v.optional(\n v.pipe(v.string(), v.description('Font style (e.g. \"Bold\", \"Regular\", \"Bold Italic\")'))\n ),\n variations: variationsInputSchema\n }),\n // A new font replaces the text's, which then need not be loaded, so a missing font can be\n // replaced; a size or per-range axes lay out the text in its own fonts.\n fonts: (figma, args) => {\n const node = figma.getNodeById(args.id)\n const font = node && requestedFont(node, args)\n if (font && 'whole' in font) return [font.whole]\n return [...(font ? [font.perRange] : []), ...textFonts(figma, args.id)]\n },\n execute: (figma, args) => {\n const node = figma.getNodeById(args.id)\n if (!node) return nodeNotFound(args.id)\n const badTag = badVariationTag(args.variations)\n if (badTag) return badTag\n const font = requestedFont(node, args)\n try {\n if (font && 'whole' in font) node.fontName = font.whole\n else if (font) node.setRangeFontName(0, node.characters.length, font.perRange)\n // The size comes after the font, so it lays the text out in the font it ends up in.\n if (args.size !== undefined) node.fontSize = args.size\n } catch (error) {\n return toolFailure(error)\n }\n return { id: args.id, fontName: node.fontName, fontSize: node.fontSize }\n }\n})\n\n/** The font `set_font_range` gives its range: what it names, the rest from the range's start. */\nfunction rangeFont(\n node: FigmaNodeProxy,\n args: { start: number; family?: string; style?: string; variations?: FigmaVariationSettings }\n): FigmaFontNameInput {\n const inText = args.start < node.characters.length\n const current = inText ? node.getRangeFontName(args.start, args.start + 1) : node.fontName\n return fontNameInput(args, typeof current === 'symbol' ? null : current)\n}\n\ntype RangeEdit = {\n hyperlink: { link: { type: 'URL'; value: string } | null } | null\n color: Color | undefined\n}\n\n/** Why a variation setting cannot apply: an axis tag is not four letters. */\nfunction badVariationTag(variations: FigmaVariationSettings | undefined): { error: string } | null {\n const tag = Object.keys(variations ?? {}).find((key) => key.length !== 4)\n return tag === undefined ? null : { error: `\"${tag}\" is not a four-letter OpenType axis tag` }\n}\n\n/** What a range edit sets, or why it cannot run: nothing named, a bad colour, or a bad link. */\nfunction rangeEdit(args: {\n family?: string\n size?: number\n style?: string\n variations?: unknown\n color?: string\n hyperlink?: string | null\n}): RangeEdit | { error: string } {\n if (\n !args.family &&\n !args.size &&\n !args.style &&\n !args.variations &&\n !args.color &&\n args.hyperlink === undefined\n ) {\n return {\n error:\n 'set_font_range needs at least one of family, size, style, variations, color, or hyperlink'\n }\n }\n const hyperlink = requestedHyperlink(args.hyperlink)\n if (hyperlink && 'error' in hyperlink) return hyperlink\n const color = parseOptionalToolColor(args.color)\n if ('error' in color) return color\n return { hyperlink: hyperlink ?? null, color: color.color }\n}\n\nexport const setFontRange = defineTool({\n name: 'set_font_range',\n\n description: 'Set font properties, color, or a link for a text range.',\n execution: { kind: 'sync', mutation: 'properties' },\n input: v.strictObject({\n id: nodeIdInputSchema,\n start: toolNumber(v.pipe(v.number(), v.minValue(0), v.description('Start character index'))),\n end: toolNumber(v.pipe(v.number(), v.minValue(0), v.description('End character index'))),\n family: v.optional(v.pipe(v.string(), v.description('Font family name'))),\n size: v.optional(toolNumber(v.pipe(v.number(), v.minValue(1), v.description('Font size')))),\n style: v.optional(v.pipe(v.string(), v.description('Font style'))),\n variations: variationsInputSchema,\n color: v.optional(v.pipe(v.string(), v.description('Text color (hex)'))),\n hyperlink: hyperlinkInputSchema\n }),\n fonts: (figma, args) => {\n const node = figma.getNodeById(args.id)\n if (!node) return []\n const font = args.family || args.style || args.variations ? rangeFont(node, args) : null\n // A colour alone is a paint and lays nothing out, so text in a missing font can still take it.\n const laysOut = font !== null || args.size !== undefined\n return [...(font ? [font] : []), ...(laysOut ? textFonts(figma, args.id) : [])]\n },\n execute: (figma, args) => {\n const node = figma.getNodeById(args.id)\n if (!node) return nodeNotFound(args.id)\n const { start, end } = args\n const badTag = badVariationTag(args.variations)\n if (badTag) return badTag\n const edit = rangeEdit(args)\n if ('error' in edit) return edit\n const { hyperlink, color } = edit\n // The range methods reject an empty range or one past the text, before changing anything.\n try {\n if (args.size) node.setRangeFontSize(start, end, args.size)\n if (args.family || args.style || args.variations) {\n node.setRangeFontName(start, end, rangeFont(node, args))\n }\n if (color) node.setRangeFills(start, end, [{ type: 'SOLID', color }])\n if (hyperlink) node.setRangeHyperlink(start, end, hyperlink.link)\n } catch (error) {\n return toolFailure(error)\n }\n return {\n id: args.id,\n range: { start, end },\n ...(hyperlink ? { hyperlink: hyperlink.link?.value ?? null } : {})\n }\n }\n})\n\nexport const setTextResize = defineTool({\n name: 'set_text_resize',\n\n description: 'Set text auto-resize mode.',\n execution: { kind: 'sync', mutation: 'properties' },\n input: v.strictObject({\n id: nodeIdInputSchema,\n mode: v.pipe(\n v.picklist(['NONE', 'WIDTH_AND_HEIGHT', 'HEIGHT', 'TRUNCATE']),\n v.description('Resize mode')\n )\n }),\n fonts: (figma, { id }) => textFonts(figma, id),\n execute: (figma, { id, mode }) => {\n const node = figma.getNodeById(id)\n if (!node) return { error: `Node \"${id}\" not found` }\n node.textAutoResize = mode\n return { id, textAutoResize: mode }\n }\n})\n\nexport const setTextProperties = defineTool({\n name: 'set_text_properties',\n\n description:\n 'Set text layout properties: alignment, auto-resize, text case, decoration, truncation, and a link for the whole text.',\n execution: { kind: 'sync', mutation: 'properties' },\n input: v.strictObject({\n id: v.pipe(v.string(), v.description('Text node ID')),\n align_horizontal: v.optional(\n v.pipe(\n v.picklist(['LEFT', 'CENTER', 'RIGHT', 'JUSTIFIED']),\n v.description('Horizontal text alignment')\n )\n ),\n align_vertical: v.optional(\n v.pipe(v.picklist(['TOP', 'CENTER', 'BOTTOM']), v.description('Vertical text alignment'))\n ),\n auto_resize: v.optional(\n v.pipe(\n v.picklist(['NONE', 'WIDTH_AND_HEIGHT', 'HEIGHT', 'TRUNCATE']),\n v.description('Text auto-resize mode')\n )\n ),\n direction: v.optional(\n v.pipe(v.picklist(['AUTO', 'LTR', 'RTL']), v.description('Text direction'))\n ),\n text_decoration: v.optional(\n v.pipe(v.picklist(['NONE', 'UNDERLINE', 'STRIKETHROUGH']), v.description('Text decoration'))\n ),\n hyperlink: hyperlinkInputSchema\n }),\n fonts: (figma, { id }) => textFonts(figma, id),\n execute: (figma, args) => {\n const node = figma.getNodeById(args.id)\n if (!node) return nodeNotFound(args.id)\n if (node.type !== 'TEXT') return { error: `Node \"${args.id}\" is not a TEXT node` }\n // Refused before anything changes, so a bad address leaves the text as it was.\n const hyperlink = requestedHyperlink(args.hyperlink)\n if (hyperlink && 'error' in hyperlink) return hyperlink\n const updated: string[] = []\n if (args.align_horizontal !== undefined) {\n node.textAlignHorizontal = args.align_horizontal\n updated.push('textAlignHorizontal')\n }\n if (args.align_vertical !== undefined) {\n node.textAlignVertical = args.align_vertical\n updated.push('textAlignVertical')\n }\n if (args.auto_resize !== undefined) {\n node.textAutoResize = args.auto_resize\n updated.push('textAutoResize')\n }\n if (args.direction !== undefined) {\n new PairdrawAPI(figma).setTextDirection(node, args.direction)\n updated.push('textDirection')\n }\n if (args.text_decoration !== undefined) {\n node.textDecoration = args.text_decoration\n updated.push('textDecoration')\n }\n if (hyperlink) {\n try {\n node.hyperlink = hyperlink.link\n } catch (error) {\n return toolFailure(error)\n }\n updated.push('hyperlink')\n }\n return { id: args.id, updated }\n }\n})\n"],"mappings":";;;;;;;;;;AAuBA,MAAM,uBAAuB,EAAE,SAC7B,E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["import * as v from 'valibot'\n\nimport type { Color } from '@pairdraw/scene-graph/primitives'\n\nimport type { FigmaAPI, FigmaNodeProxy } from '#core/figma-api'\nimport type { FigmaFontName, FigmaFontNameInput } from '#core/figma-api/fonts/names'\nimport type { FigmaVariationSettings } from '#core/figma-api/fonts/variations'\nimport { PairdrawAPI } from '#core/pairdraw-api'\nimport { normalizeLinkURL } from '#core/text/hyperlink'\nimport { collectNodeFontFaces } from '#core/text/requirements/collect'\nimport {\n parseOptionalToolColor,\n toolNumber,\n nodeIdInputSchema,\n defineTool,\n nodeNotFound,\n toolFailure\n} from '#core/tools/schema'\n\n/**\n * A link a text tool sets, as the editor's link field takes it: a web or mail address, with\n * `https:` or `mailto:` added when typed without a scheme. Null or blank removes the link.\n */\nconst hyperlinkInputSchema = v.optional(\n v.pipe(\n v.nullable(v.string()),\n v.description(\n 'Link the text opens: an http(s) or mailto address (\"example.com\" becomes https://example.com, \"hi@example.com\" becomes mailto:). null or \"\" removes the link. Links are not underlined automatically; set text_decoration for that.'\n )\n )\n)\n\n/**\n * A scheme at the start of a typed link, even with a digit after its colon (`tel:123`), unless it\n * reads as a host and port (`localhost:3000`, `example.com:8080`), which gets `https://`.\n */\nconst TYPED_SCHEME = /^([a-z][a-z\\d+.-]*):/i\n\n/** A web address in the form the Figma API's link setter takes: `http(s)://host…`. */\nconst WEB_URL = /^https?:\\/\\/[^\\s/?#]+\\S*$/\n\n/** Whether a typed link names a scheme other than the http, https, and mailto links take. */\nfunction hasForeignScheme(typed: string): boolean {\n const scheme = TYPED_SCHEME.exec(typed)?.[1]?.toLowerCase()\n if (!scheme || scheme.includes('.') || scheme === 'localhost') return false\n return !['http', 'https', 'mailto'].includes(scheme)\n}\n\n/** What setting `hyperlink` asks for: no change, a removal, a URL, or an address it refuses. */\nfunction requestedHyperlink(\n hyperlink: string | null | undefined\n): { link: { type: 'URL'; value: string } | null } | { error: string } | null {\n if (hyperlink === undefined) return null\n if (hyperlink === null || hyperlink.trim() === '') return { link: null }\n const url = hasForeignScheme(hyperlink.trim()) ? null : normalizeLinkURL(hyperlink)\n if (!url) {\n return {\n error: `\"${hyperlink}\" is not a link the editor opens: use an http, https, or mailto address`\n }\n }\n // Figma keeps schemes in lower case and web addresses as `scheme://host`, so a loosely typed\n // `http:example.com` is written as the URL it parses to.\n const lowered = url.replace(TYPED_SCHEME, (scheme) => scheme.toLowerCase())\n const value =\n lowered.startsWith('mailto:') || WEB_URL.test(lowered) ? lowered : new URL(lowered).href\n return { link: { type: 'URL', value } }\n}\n\n/** The fonts a text layer uses, which an edit that lays it out again needs loaded. */\nexport function textFonts(figma: FigmaAPI, id: string): FigmaFontNameInput[] {\n const node = figma.graph.getNode(id)\n return node ? collectNodeFontFaces(node) : []\n}\n\nexport const setText = defineTool({\n name: 'set_text',\n\n description: 'Set text content of a text node.',\n execution: { kind: 'sync', mutation: 'properties' },\n input: v.strictObject({\n id: nodeIdInputSchema,\n text: v.pipe(v.string(), v.description('Text content'))\n }),\n fonts: (figma, { id }) => textFonts(figma, id),\n execute: (figma, { id, text }) => {\n const node = figma.getNodeById(id)\n if (!node) return { error: `Node \"${id}\" not found` }\n node.characters = text\n return { id, text }\n }\n})\n\n/** Variable font axes a font tool can set, as Figma's `variationSettings`. */\n// An object with a value for every key rather than a record: a record publishes `propertyNames`,\n// which OpenAI refuses, and a JSON object's keys are strings anyway.\nconst variationsInputSchema = v.optional(\n v.pipe(\n v.objectWithRest({}, v.number()),\n v.description(\n 'Variable font axis values by OpenType tag (e.g. {\"wght\": 550, \"wdth\": 75}); axes left out keep the style\\'s values. Without a style, the nearest named style is picked.'\n )\n )\n)\n\n/** OpenType features a text tool sets, by tag; tags left out keep their state. */\nconst fontFeaturesInputSchema = v.optional(\n v.pipe(\n v.objectWithRest({}, v.boolean()),\n v.description(\n 'OpenType feature toggles by four-letter tag (e.g. {\"TNUM\": true, \"LIGA\": false, \"SS02\": true}); tags left out keep their state. Only features the font has take effect.'\n )\n )\n)\n\n/** Why a feature map cannot apply: a tag is not four letters, or a value is not a boolean. */\nfunction badFeatureEntry(features: Record<string, boolean> | undefined): { error: string } | null {\n for (const [tag, enabled] of Object.entries(features ?? {})) {\n if (tag.length !== 4) return { error: `\"${tag}\" is not a four-letter OpenType feature tag` }\n if (typeof enabled !== 'boolean') {\n return { error: `Feature \"${tag}\" needs a boolean value, received ${typeof enabled}` }\n }\n }\n return null\n}\n\n/**\n * The font a font tool gives text: what it names, the rest from `current`. Axes without a style\n * leave the style out, for the nearest named style to be picked.\n */\nfunction fontNameInput(\n args: { family?: string; style?: string; variations?: FigmaVariationSettings },\n current: FigmaFontName | null\n): FigmaFontNameInput {\n return {\n family: args.family ?? current?.family ?? '',\n style: args.style ?? (args.variations ? undefined : (current?.style ?? 'Regular')),\n variationSettings: args.variations\n }\n}\n\n/**\n * The font `set_font` gives the text, or null when it keeps the text's. Text set in several fonts\n * takes the given family or style for all of it, keeping the rest from its first character. Axes\n * without a style are set per range, each range taking its nearest named style, as in Figma.\n */\nfunction requestedFont(\n node: FigmaNodeProxy,\n args: { family?: string; style?: string; variations?: FigmaVariationSettings }\n): { whole: FigmaFontName } | { perRange: FigmaFontNameInput } | null {\n if (!args.family && !args.style && !args.variations) return null\n const fontName =\n typeof node.fontName === 'symbol' && node.characters.length > 0\n ? node.getRangeFontName(0, 1)\n : node.fontName\n const current = typeof fontName === 'symbol' ? null : fontName\n const family = args.family ?? current?.family ?? ''\n if (args.variations && !args.style && node.characters.length > 0) {\n return { perRange: { family, variationSettings: args.variations } }\n }\n const style = args.style ?? current?.style ?? 'Regular'\n return { whole: { family, style, variationSettings: args.variations } }\n}\n\nexport const setFont = defineTool({\n name: 'set_font',\n\n description: 'Set font properties of a text node.',\n execution: { kind: 'sync', mutation: 'properties' },\n input: v.strictObject({\n id: nodeIdInputSchema,\n family: v.optional(v.pipe(v.string(), v.description('Font family name'))),\n size: v.optional(toolNumber(v.pipe(v.number(), v.minValue(1), v.description('Font size')))),\n style: v.optional(\n v.pipe(v.string(), v.description('Font style (e.g. \"Bold\", \"Regular\", \"Bold Italic\")'))\n ),\n variations: variationsInputSchema\n }),\n // A new font replaces the text's, which then need not be loaded, so a missing font can be\n // replaced; a size or per-range axes lay out the text in its own fonts.\n fonts: (figma, args) => {\n const node = figma.getNodeById(args.id)\n const font = node && requestedFont(node, args)\n if (font && 'whole' in font) return [font.whole]\n return [...(font ? [font.perRange] : []), ...textFonts(figma, args.id)]\n },\n execute: (figma, args) => {\n const node = figma.getNodeById(args.id)\n if (!node) return nodeNotFound(args.id)\n const badTag = badVariationTag(args.variations)\n if (badTag) return badTag\n const font = requestedFont(node, args)\n try {\n if (font && 'whole' in font) node.fontName = font.whole\n else if (font) node.setRangeFontName(0, node.characters.length, font.perRange)\n // The size comes after the font, so it lays the text out in the font it ends up in.\n if (args.size !== undefined) node.fontSize = args.size\n } catch (error) {\n return toolFailure(error)\n }\n return { id: args.id, fontName: node.fontName, fontSize: node.fontSize }\n }\n})\n\n/** The font `set_font_range` gives its range: what it names, the rest from the range's start. */\nfunction rangeFont(\n node: FigmaNodeProxy,\n args: { start: number; family?: string; style?: string; variations?: FigmaVariationSettings }\n): FigmaFontNameInput {\n const inText = args.start < node.characters.length\n const current = inText ? node.getRangeFontName(args.start, args.start + 1) : node.fontName\n return fontNameInput(args, typeof current === 'symbol' ? null : current)\n}\n\ntype RangeEdit = {\n hyperlink: { link: { type: 'URL'; value: string } | null } | null\n color: Color | undefined\n}\n\n/** Why a variation setting cannot apply: an axis tag is not four letters. */\nfunction badVariationTag(variations: FigmaVariationSettings | undefined): { error: string } | null {\n const tag = Object.keys(variations ?? {}).find((key) => key.length !== 4)\n return tag === undefined ? null : { error: `\"${tag}\" is not a four-letter OpenType axis tag` }\n}\n\n/** What a range edit sets, or why it cannot run: nothing named, a bad colour, or a bad link. */\nfunction rangeEdit(args: {\n family?: string\n size?: number\n style?: string\n variations?: unknown\n font_features?: Record<string, boolean>\n color?: string\n hyperlink?: string | null\n}): RangeEdit | { error: string } {\n if (\n !args.family &&\n !args.size &&\n !args.style &&\n !args.variations &&\n !args.font_features &&\n !args.color &&\n args.hyperlink === undefined\n ) {\n return {\n error:\n 'set_font_range needs at least one of family, size, style, variations, font_features, color, or hyperlink'\n }\n }\n const hyperlink = requestedHyperlink(args.hyperlink)\n if (hyperlink && 'error' in hyperlink) return hyperlink\n const color = parseOptionalToolColor(args.color)\n if ('error' in color) return color\n return { hyperlink: hyperlink ?? null, color: color.color }\n}\n\nexport const setFontRange = defineTool({\n name: 'set_font_range',\n\n description: 'Set font properties, OpenType features, color, or a link for a text range.',\n execution: { kind: 'sync', mutation: 'properties' },\n input: v.strictObject({\n id: nodeIdInputSchema,\n start: toolNumber(v.pipe(v.number(), v.minValue(0), v.description('Start character index'))),\n end: toolNumber(v.pipe(v.number(), v.minValue(0), v.description('End character index'))),\n family: v.optional(v.pipe(v.string(), v.description('Font family name'))),\n size: v.optional(toolNumber(v.pipe(v.number(), v.minValue(1), v.description('Font size')))),\n style: v.optional(v.pipe(v.string(), v.description('Font style'))),\n variations: variationsInputSchema,\n font_features: fontFeaturesInputSchema,\n color: v.optional(v.pipe(v.string(), v.description('Text color (hex)'))),\n hyperlink: hyperlinkInputSchema\n }),\n fonts: (figma, args) => {\n const node = figma.getNodeById(args.id)\n if (!node) return []\n const font = args.family || args.style || args.variations ? rangeFont(node, args) : null\n // A colour alone is a paint and lays nothing out, so text in a missing font can still take it.\n // Features reshape glyphs, so they need the text's fonts as a size change does.\n const laysOut = font !== null || args.size !== undefined || args.font_features !== undefined\n return [...(font ? [font] : []), ...(laysOut ? textFonts(figma, args.id) : [])]\n },\n execute: (figma, args) => {\n const node = figma.getNodeById(args.id)\n if (!node) return nodeNotFound(args.id)\n const { start, end } = args\n const badTag = badVariationTag(args.variations)\n if (badTag) return badTag\n const badFeature = badFeatureEntry(args.font_features)\n if (badFeature) return badFeature\n const edit = rangeEdit(args)\n if ('error' in edit) return edit\n const { hyperlink, color } = edit\n // The range methods reject an empty range or one past the text, before changing anything.\n try {\n if (args.size) node.setRangeFontSize(start, end, args.size)\n if (args.family || args.style || args.variations) {\n node.setRangeFontName(start, end, rangeFont(node, args))\n }\n if (color) node.setRangeFills(start, end, [{ type: 'SOLID', color }])\n if (hyperlink) node.setRangeHyperlink(start, end, hyperlink.link)\n if (args.font_features) {\n new PairdrawAPI(figma).setRangeFontFeatures(node, start, end, args.font_features)\n }\n } catch (error) {\n return toolFailure(error)\n }\n return {\n id: args.id,\n range: { start, end },\n ...(hyperlink ? { hyperlink: hyperlink.link?.value ?? null } : {})\n }\n }\n})\n\nexport const setTextResize = defineTool({\n name: 'set_text_resize',\n\n description: 'Set text auto-resize mode.',\n execution: { kind: 'sync', mutation: 'properties' },\n input: v.strictObject({\n id: nodeIdInputSchema,\n mode: v.pipe(\n v.picklist(['NONE', 'WIDTH_AND_HEIGHT', 'HEIGHT', 'TRUNCATE']),\n v.description('Resize mode')\n )\n }),\n fonts: (figma, { id }) => textFonts(figma, id),\n execute: (figma, { id, mode }) => {\n const node = figma.getNodeById(id)\n if (!node) return { error: `Node \"${id}\" not found` }\n node.textAutoResize = mode\n return { id, textAutoResize: mode }\n }\n})\n\nexport const setTextProperties = defineTool({\n name: 'set_text_properties',\n\n description:\n 'Set text layout properties: alignment, auto-resize, text case, decoration, truncation, OpenType features, and a link for the whole text.',\n execution: { kind: 'sync', mutation: 'properties' },\n input: v.strictObject({\n id: v.pipe(v.string(), v.description('Text node ID')),\n align_horizontal: v.optional(\n v.pipe(\n v.picklist(['LEFT', 'CENTER', 'RIGHT', 'JUSTIFIED']),\n v.description('Horizontal text alignment')\n )\n ),\n align_vertical: v.optional(\n v.pipe(v.picklist(['TOP', 'CENTER', 'BOTTOM']), v.description('Vertical text alignment'))\n ),\n auto_resize: v.optional(\n v.pipe(\n v.picklist(['NONE', 'WIDTH_AND_HEIGHT', 'HEIGHT', 'TRUNCATE']),\n v.description('Text auto-resize mode')\n )\n ),\n direction: v.optional(\n v.pipe(v.picklist(['AUTO', 'LTR', 'RTL']), v.description('Text direction'))\n ),\n text_decoration: v.optional(\n v.pipe(v.picklist(['NONE', 'UNDERLINE', 'STRIKETHROUGH']), v.description('Text decoration'))\n ),\n hyperlink: hyperlinkInputSchema,\n font_features: fontFeaturesInputSchema\n }),\n fonts: (figma, { id }) => textFonts(figma, id),\n execute: (figma, args) => {\n const node = figma.getNodeById(args.id)\n if (!node) return nodeNotFound(args.id)\n if (node.type !== 'TEXT') return { error: `Node \"${args.id}\" is not a TEXT node` }\n // Refused before anything changes, so a bad address leaves the text as it was.\n const hyperlink = requestedHyperlink(args.hyperlink)\n if (hyperlink && 'error' in hyperlink) return hyperlink\n const badFeature = badFeatureEntry(args.font_features)\n if (badFeature) return badFeature\n const updated: string[] = []\n if (args.align_horizontal !== undefined) {\n node.textAlignHorizontal = args.align_horizontal\n updated.push('textAlignHorizontal')\n }\n if (args.align_vertical !== undefined) {\n node.textAlignVertical = args.align_vertical\n updated.push('textAlignVertical')\n }\n if (args.auto_resize !== undefined) {\n node.textAutoResize = args.auto_resize\n updated.push('textAutoResize')\n }\n if (args.direction !== undefined) {\n new PairdrawAPI(figma).setTextDirection(node, args.direction)\n updated.push('textDirection')\n }\n if (args.text_decoration !== undefined) {\n node.textDecoration = args.text_decoration\n updated.push('textDecoration')\n }\n if (args.font_features) {\n new PairdrawAPI(figma).setFontFeatures(node, args.font_features)\n updated.push('fontFeatures')\n }\n if (hyperlink) {\n try {\n node.hyperlink = hyperlink.link\n } catch (error) {\n return toolFailure(error)\n }\n updated.push('hyperlink')\n }\n return { id: args.id, updated }\n }\n})\n"],"mappings":";;;;;;;;;;AAuBA,MAAM,uBAAuB,EAAE,SAC7B,EAAE,KACA,EAAE,SAAS,EAAE,OAAO,CAAC,GACrB,EAAE,YACA,2OACF,CACF,CACF;;;;;AAMA,MAAM,eAAe;;AAGrB,MAAM,UAAU;;AAGhB,SAAS,iBAAiB,OAAwB;CAChD,MAAM,SAAS,aAAa,KAAK,KAAK,CAAC,GAAG,EAAE,EAAE,YAAY;CA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Ac,KAAA,GAAW;GAChC,IAAI,YAAY,KAAK,CAAC,CAAC,iBAAiB,MAAM,KAAK,SAAS;GAC5D,QAAQ,KAAK,eAAe;EAC9B;EACA,IAAI,KAAK,oBAAoB,KAAA,GAAW;GACtC,KAAK,iBAAiB,KAAK;GAC3B,QAAQ,KAAK,gBAAgB;EAC/B;EACA,IAAI,KAAK,eAAe;GACtB,IAAI,YAAY,KAAK,CAAC,CAAC,gBAAgB,MAAM,KAAK,aAAa;GAC/D,QAAQ,KAAK,cAAc;EAC7B;EACA,IAAI,WAAW;GACb,IAAI;IACF,KAAK,YAAY,UAAU;GAC7B,SAAS,OAAO;IACd,OAAO,YAAY,KAAK;GAC1B;GACA,QAAQ,KAAK,WAAW;EAC1B;EACA,OAAO;GAAE,IAAI,KAAK;GAAI;EAAQ;CAChC;AACF,CAAC"}
@@ -1,6 +1,15 @@
1
+ import { FigmaNodeProxy } from "../../figma-api/proxy.js";
2
+ import "../../figma-api/index.js";
1
3
  import { ToolDef } from "../schema.js";
4
+ import * as v from "valibot";
2
5
  //#region src/tools/modify/update.d.ts
6
+ /** Why a layer cannot take overflow scrolling, or null when it can, as Figma's frames take it. */
7
+ declare function scrollRefusal(node: FigmaNodeProxy): string | null;
8
+ /** Overflow scrolling in play, as Figma's `overflowDirection`. */
9
+ declare function overflowDirectionInput(): v.SchemaWithPipe<readonly [v.PicklistSchema<readonly ["NONE", "HORIZONTAL", "VERTICAL", "BOTH"], undefined>, v.DescriptionAction<"NONE" | "HORIZONTAL" | "VERTICAL" | "BOTH", string>]>;
10
+ /** How a layer moves while its parent frame scrolls in prototype play. */
11
+ declare function scrollBehaviorInput(): v.SchemaWithPipe<readonly [v.PicklistSchema<readonly ["SCROLLS", "FIXED", "STICKY_SCROLLS"], undefined>, v.DescriptionAction<"SCROLLS" | "FIXED" | "STICKY_SCROLLS", string>]>;
3
12
  declare const updateNode: ToolDef;
4
13
  //#endregion
5
- export { updateNode };
14
+ export { overflowDirectionInput, scrollBehaviorInput, scrollRefusal, updateNode };
6
15
  //# sourceMappingURL=update.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"update.d.ts","names":[],"sources":["../../../src/tools/modify/update.ts"],"mappings":";;cAkCa,YAAA"}
1
+ {"version":3,"file":"update.d.ts","names":[],"sources":["../../../src/tools/modify/update.ts"],"mappings":";;;;;;iBAsCgB,cAAc,MAAM;;iBAMpB,0BAAsB,EAAA,yBAAA,EAAA,gFAAA,EAAA;;iBAWtB,uBAAmB,EAAA,yBAAA,EAAA,4EAAA,EAAA;cAUtB,YAAA"}
@@ -1,5 +1,6 @@
1
1
  import { assertNodeEditable } from "../../editor/capabilities.js";
2
2
  import { defineTool, nodeIdInputSchema, nodeNotFound, toolNumber } from "../schema.js";
3
+ import { OVERFLOW_DIRECTIONS, SCROLL_BEHAVIORS } from "@pairdraw/scene-graph/constants";
3
4
  import { styleDetachmentChanges } from "@pairdraw/scene-graph/shared-styles";
4
5
  import * as v from "valibot";
5
6
  //#region src/tools/modify/update.ts
@@ -29,9 +30,27 @@ function resized(node, width = node.width, height = node.height) {
29
30
  ]) if (after[key] !== before[key]) changed.push(key);
30
31
  return changed;
31
32
  }
33
+ const SCROLLING_TYPES = /* @__PURE__ */ new Set([
34
+ "FRAME",
35
+ "COMPONENT",
36
+ "INSTANCE"
37
+ ]);
38
+ /** Why a layer cannot take overflow scrolling, or null when it can, as Figma's frames take it. */
39
+ function scrollRefusal(node) {
40
+ if (SCROLLING_TYPES.has(node.type)) return null;
41
+ return `Only a frame, component or instance scrolls; ${node.type} "${node.name}" cannot.`;
42
+ }
43
+ /** Overflow scrolling in play, as Figma's `overflowDirection`. */
44
+ function overflowDirectionInput() {
45
+ return v.pipe(v.picklist(OVERFLOW_DIRECTIONS), v.description("Overflow scrolling in prototype play (FRAME, COMPONENT, INSTANCE). A nested frame scrolls only while it clips its content."));
46
+ }
47
+ /** How a layer moves while its parent frame scrolls in prototype play. */
48
+ function scrollBehaviorInput() {
49
+ return v.pipe(v.picklist(SCROLL_BEHAVIORS), v.description("Scroll behavior in prototype play: SCROLLS moves with the content, FIXED stays in the frame, STICKY_SCROLLS scrolls until it reaches the frame's top or left edge."));
50
+ }
32
51
  const updateNode = defineTool({
33
52
  name: "update_node",
34
- description: "Update properties of an existing node: position, size, opacity, corner radius, visibility, text, font.",
53
+ description: "Update properties of an existing node: position, size, opacity, corner radius, visibility, text, font, overflow scrolling.",
35
54
  execution: {
36
55
  kind: "sync",
37
56
  mutation: "properties"
@@ -58,12 +77,16 @@ const updateNode = defineTool({
58
77
  ]), v.description("Auto-layout flow direction for FRAME nodes"))),
59
78
  font_size: v.optional(toolNumber(v.pipe(v.number(), v.minValue(1), v.description("Font size")))),
60
79
  font_weight: v.optional(toolNumber(v.pipe(v.number(), v.minValue(100), v.maxValue(900), v.description("Font weight (100-900)")))),
61
- name: v.optional(v.pipe(v.string(), v.description("Layer name")))
80
+ name: v.optional(v.pipe(v.string(), v.description("Layer name"))),
81
+ overflow_direction: v.optional(overflowDirectionInput()),
82
+ scroll_behavior: v.optional(scrollBehaviorInput())
62
83
  }),
63
84
  execute: (figma, args) => {
64
85
  const node = figma.getNodeById(args.id);
65
86
  if (!node) return nodeNotFound(args.id);
66
87
  assertNodeEditable(figma.graph, args.id);
88
+ const refusal = args.overflow_direction === void 0 ? null : scrollRefusal(node);
89
+ if (refusal) return { error: refusal };
67
90
  const editTypography = (changes) => {
68
91
  const scene = figma.graph.getNode(args.id);
69
92
  if (scene) figma.graph.updateNode(args.id, styleDetachmentChanges(scene, changes));
@@ -114,6 +137,14 @@ const updateNode = defineTool({
114
137
  editTypography({ fontWeight: args.font_weight });
115
138
  updated.push("fontWeight");
116
139
  }
140
+ if (args.overflow_direction !== void 0) {
141
+ node.overflowDirection = args.overflow_direction;
142
+ updated.push("overflowDirection");
143
+ }
144
+ if (args.scroll_behavior !== void 0) {
145
+ node.scrollBehavior = args.scroll_behavior;
146
+ updated.push("scrollBehavior");
147
+ }
117
148
  return {
118
149
  id: args.id,
119
150
  updated
@@ -121,6 +152,6 @@ const updateNode = defineTool({
121
152
  }
122
153
  });
123
154
  //#endregion
124
- export { updateNode };
155
+ export { overflowDirectionInput, scrollBehaviorInput, scrollRefusal, updateNode };
125
156
 
126
157
  //# sourceMappingURL=update.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"update.js","names":[],"sources":["../../../src/tools/modify/update.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport type { SceneNode } from '@pairdraw/scene-graph'\nimport { styleDetachmentChanges } from '@pairdraw/scene-graph/shared-styles'\n\nimport { assertNodeEditable } from '#core/editor/capabilities'\nimport type { FigmaNodeProxy } from '#core/figma-api'\nimport { toolNumber, nodeIdInputSchema, defineTool, nodeNotFound } from '#core/tools/schema'\n\n/** The size of a layer and how auto layout or its text sizes it, which a resize may change. */\nfunction sizing(node: FigmaNodeProxy) {\n return {\n width: node.width,\n height: node.height,\n layoutSizingHorizontal: node.layoutSizingHorizontal,\n layoutSizingVertical: node.layoutSizingVertical,\n textAutoResize: node.textAutoResize\n }\n}\n\n/**\n * Resizes a layer and names what the resize changed: a layer inside an instance keeps its size,\n * as in Figma, while an auto layout frame or a text given its own size stops sizing itself.\n */\nfunction resized(node: FigmaNodeProxy, width = node.width, height = node.height): string[] {\n const before = sizing(node)\n node.resize(width, height)\n const after = sizing(node)\n const changed = after.width !== before.width || after.height !== before.height ? ['size'] : []\n for (const key of ['layoutSizingHorizontal', 'layoutSizingVertical', 'textAutoResize'] as const)\n if (after[key] !== before[key]) changed.push(key)\n return changed\n}\n\nexport const updateNode = defineTool({\n name: 'update_node',\n\n description:\n 'Update properties of an existing node: position, size, opacity, corner radius, visibility, text, font.',\n execution: { kind: 'sync', mutation: 'properties' },\n input: v.strictObject({\n id: nodeIdInputSchema,\n x: v.optional(toolNumber(v.pipe(v.number(), v.description('X position')))),\n y: v.optional(toolNumber(v.pipe(v.number(), v.description('Y position')))),\n width: v.optional(toolNumber(v.pipe(v.number(), v.minValue(1), v.description('Width')))),\n height: v.optional(toolNumber(v.pipe(v.number(), v.minValue(1), v.description('Height')))),\n opacity: v.optional(\n toolNumber(v.pipe(v.number(), v.minValue(0), v.maxValue(1), v.description('Opacity (0-1)')))\n ),\n corner_radius: v.optional(\n toolNumber(v.pipe(v.number(), v.minValue(0), v.description('Corner radius')))\n ),\n visible: v.optional(v.pipe(v.boolean(), v.description('Visibility'))),\n text: v.optional(v.pipe(v.string(), v.description('Text content (TEXT nodes)'))),\n text_direction: v.optional(\n v.pipe(v.picklist(['AUTO', 'LTR', 'RTL']), v.description('Text direction for TEXT nodes'))\n ),\n flow_direction: v.optional(\n v.pipe(\n v.picklist(['AUTO', 'LTR', 'RTL']),\n v.description('Auto-layout flow direction for FRAME nodes')\n )\n ),\n font_size: v.optional(\n toolNumber(v.pipe(v.number(), v.minValue(1), v.description('Font size')))\n ),\n font_weight: v.optional(\n toolNumber(\n v.pipe(v.number(), v.minValue(100), v.maxValue(900), v.description('Font weight (100-900)'))\n )\n ),\n name: v.optional(v.pipe(v.string(), v.description('Layer name')))\n }),\n execute: (figma, args) => {\n const node = figma.getNodeById(args.id)\n if (!node) return nodeNotFound(args.id)\n assertNodeEditable(figma.graph, args.id)\n // Written to the layer directly, since the plugin setters need a loaded font; an edit to a\n // text style's field leaves the style, as the editor's updates do.\n const editTypography = (changes: Partial<SceneNode>) => {\n const scene = figma.graph.getNode(args.id)\n if (scene) figma.graph.updateNode(args.id, styleDetachmentChanges(scene, changes))\n }\n const updated: string[] = []\n if (args.x !== undefined) {\n node.x = args.x\n updated.push('x')\n }\n if (args.y !== undefined) {\n node.y = args.y\n updated.push('y')\n }\n if (args.width !== undefined || args.height !== undefined)\n updated.push(...resized(node, args.width, args.height))\n if (args.opacity !== undefined) {\n node.opacity = args.opacity\n updated.push('opacity')\n }\n if (args.corner_radius !== undefined) {\n node.cornerRadius = args.corner_radius\n updated.push('cornerRadius')\n }\n if (args.visible !== undefined) {\n node.visible = args.visible\n updated.push('visible')\n }\n if (args.name !== undefined) {\n node.name = args.name\n updated.push('name')\n }\n if (args.text !== undefined) {\n figma.graph.updateNode(node.id, { text: args.text })\n updated.push('text')\n }\n if (args.text_direction !== undefined) {\n figma.graph.updateNode(node.id, {\n textDirection: args.text_direction\n })\n updated.push('textDirection')\n }\n if (args.flow_direction !== undefined) {\n figma.graph.updateNode(node.id, {\n layoutDirection: args.flow_direction\n })\n updated.push('layoutDirection')\n }\n if (args.font_size !== undefined) {\n editTypography({ fontSize: args.font_size })\n updated.push('fontSize')\n }\n if (args.font_weight !== undefined) {\n editTypography({ fontWeight: args.font_weight })\n updated.push('fontWeight')\n }\n return { id: args.id, updated }\n }\n})\n"],"mappings":";;;;;;AAUA,SAAS,OAAO,MAAsB;CACpC,OAAO;EACL,OAAO,KAAK;EACZ,QAAQ,KAAK;EACb,wBAAwB,KAAK;EAC7B,sBAAsB,KAAK;EAC3B,gBAAgB,KAAK;CACvB;AACF;;;;;AAMA,SAAS,QAAQ,MAAsB,QAAQ,KAAK,OAAO,SAAS,KAAK,QAAkB;CACzF,MAAM,SAAS,OAAO,IAAI;CAC1B,KAAK,OAAO,OAAO,MAAM;CACzB,MAAM,QAAQ,OAAO,IAAI;CACzB,MAAM,UAAU,MAAM,UAAU,OAAO,SAAS,MAAM,WAAW,OAAO,SAAS,CAAC,MAAM,IAAI,CAAC;CAC7F,KAAK,MAAM,OAAO;EAAC;EAA0B;EAAwB;CAAgB,GACnF,IAAI,MAAM,SAAS,OAAO,MAAM,QAAQ,KAAK,GAAG;CAClD,OAAO;AACT;AAEA,MAAa,aAAa,WAAW;CACnC,MAAM;CAEN,aACE;CACF,WAAW;EAAE,MAAM;EAAQ,UAAU;CAAa;CAClD,OAAO,EAAE,aAAa;EACpB,IAAI;EACJ,GAAG,EAAE,SAAS,WAAW,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,YAAY,YAAY,CAAC,CAAC,CAAC;EACzE,GAAG,EAAE,SAAS,WAAW,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,YAAY,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B,KAAA,GAAW;GACrC,MAAM,MAAM,WAAW,KAAK,IAAI,EAC9B,eAAe,KAAK,eACtB,CAAC;GACD,QAAQ,KAAK,eAAe;EAC9B;EACA,IAAI,KAAK,mBAAmB,KAAA,GAAW;GACrC,MAAM,MAAM,WAAW,KAAK,IAAI,EAC9B,iBAAiB,KAAK,eACxB,CAAC;GACD,QAAQ,KAAK,iBAAiB;EAChC;EACA,IAAI,KAAK,cAAc,KAAA,GAAW;GAChC,eAAe,EAAE,UAAU,KAAK,UAAU,CAAC;GAC3C,QAAQ,KAAK,UAAU;EACzB;EACA,IAAI,KAAK,gBAAgB,KAAA,GAAW;GAClC,eAAe,EAAE,YAAY,KAAK,YAAY,CAAC;GAC/C,QAAQ,KAAK,YAAY;EAC3B;EACA,OAAO;GAAE,IAAI,KAAK;GAAI;EAAQ;CAChC;AACF,CAAC"}
1
+ {"version":3,"file":"update.js","names":[],"sources":["../../../src/tools/modify/update.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport type { SceneNode } from '@pairdraw/scene-graph'\nimport { OVERFLOW_DIRECTIONS, SCROLL_BEHAVIORS } from '@pairdraw/scene-graph/constants'\nimport { styleDetachmentChanges } from '@pairdraw/scene-graph/shared-styles'\n\nimport { assertNodeEditable } from '#core/editor/capabilities'\nimport type { FigmaNodeProxy } from '#core/figma-api'\nimport { toolNumber, nodeIdInputSchema, defineTool, nodeNotFound } from '#core/tools/schema'\n\n/** The size of a layer and how auto layout or its text sizes it, which a resize may change. */\nfunction sizing(node: FigmaNodeProxy) {\n return {\n width: node.width,\n height: node.height,\n layoutSizingHorizontal: node.layoutSizingHorizontal,\n layoutSizingVertical: node.layoutSizingVertical,\n textAutoResize: node.textAutoResize\n }\n}\n\n/**\n * Resizes a layer and names what the resize changed: a layer inside an instance keeps its size,\n * as in Figma, while an auto layout frame or a text given its own size stops sizing itself.\n */\nfunction resized(node: FigmaNodeProxy, width = node.width, height = node.height): string[] {\n const before = sizing(node)\n node.resize(width, height)\n const after = sizing(node)\n const changed = after.width !== before.width || after.height !== before.height ? ['size'] : []\n for (const key of ['layoutSizingHorizontal', 'layoutSizingVertical', 'textAutoResize'] as const)\n if (after[key] !== before[key]) changed.push(key)\n return changed\n}\n\nconst SCROLLING_TYPES: ReadonlySet<string> = new Set(['FRAME', 'COMPONENT', 'INSTANCE'])\n\n/** Why a layer cannot take overflow scrolling, or null when it can, as Figma's frames take it. */\nexport function scrollRefusal(node: FigmaNodeProxy): string | null {\n if (SCROLLING_TYPES.has(node.type)) return null\n return `Only a frame, component or instance scrolls; ${node.type} \"${node.name}\" cannot.`\n}\n\n/** Overflow scrolling in play, as Figma's `overflowDirection`. */\nexport function overflowDirectionInput() {\n return v.pipe(\n v.picklist(OVERFLOW_DIRECTIONS),\n v.description(\n 'Overflow scrolling in prototype play (FRAME, COMPONENT, INSTANCE). A nested frame scrolls ' +\n 'only while it clips its content.'\n )\n )\n}\n\n/** How a layer moves while its parent frame scrolls in prototype play. */\nexport function scrollBehaviorInput() {\n return v.pipe(\n v.picklist(SCROLL_BEHAVIORS),\n v.description(\n 'Scroll behavior in prototype play: SCROLLS moves with the content, FIXED stays in the ' +\n \"frame, STICKY_SCROLLS scrolls until it reaches the frame's top or left edge.\"\n )\n )\n}\n\nexport const updateNode = defineTool({\n name: 'update_node',\n\n description:\n 'Update properties of an existing node: position, size, opacity, corner radius, visibility, text, font, overflow scrolling.',\n execution: { kind: 'sync', mutation: 'properties' },\n input: v.strictObject({\n id: nodeIdInputSchema,\n x: v.optional(toolNumber(v.pipe(v.number(), v.description('X position')))),\n y: v.optional(toolNumber(v.pipe(v.number(), v.description('Y position')))),\n width: v.optional(toolNumber(v.pipe(v.number(), v.minValue(1), v.description('Width')))),\n height: v.optional(toolNumber(v.pipe(v.number(), v.minValue(1), v.description('Height')))),\n opacity: v.optional(\n toolNumber(v.pipe(v.number(), v.minValue(0), v.maxValue(1), v.description('Opacity (0-1)')))\n ),\n corner_radius: v.optional(\n toolNumber(v.pipe(v.number(), v.minValue(0), v.description('Corner radius')))\n ),\n visible: v.optional(v.pipe(v.boolean(), v.description('Visibility'))),\n text: v.optional(v.pipe(v.string(), v.description('Text content (TEXT nodes)'))),\n text_direction: v.optional(\n v.pipe(v.picklist(['AUTO', 'LTR', 'RTL']), v.description('Text direction for TEXT nodes'))\n ),\n flow_direction: v.optional(\n v.pipe(\n v.picklist(['AUTO', 'LTR', 'RTL']),\n v.description('Auto-layout flow direction for FRAME nodes')\n )\n ),\n font_size: v.optional(\n toolNumber(v.pipe(v.number(), v.minValue(1), v.description('Font size')))\n ),\n font_weight: v.optional(\n toolNumber(\n v.pipe(v.number(), v.minValue(100), v.maxValue(900), v.description('Font weight (100-900)'))\n )\n ),\n name: v.optional(v.pipe(v.string(), v.description('Layer name'))),\n overflow_direction: v.optional(overflowDirectionInput()),\n scroll_behavior: v.optional(scrollBehaviorInput())\n }),\n execute: (figma, args) => {\n const node = figma.getNodeById(args.id)\n if (!node) return nodeNotFound(args.id)\n assertNodeEditable(figma.graph, args.id)\n // Refused before anything is written, so the call changes all or nothing.\n const refusal = args.overflow_direction === undefined ? null : scrollRefusal(node)\n if (refusal) return { error: refusal }\n // Written to the layer directly, since the plugin setters need a loaded font; an edit to a\n // text style's field leaves the style, as the editor's updates do.\n const editTypography = (changes: Partial<SceneNode>) => {\n const scene = figma.graph.getNode(args.id)\n if (scene) figma.graph.updateNode(args.id, styleDetachmentChanges(scene, changes))\n }\n const updated: string[] = []\n if (args.x !== undefined) {\n node.x = args.x\n updated.push('x')\n }\n if (args.y !== undefined) {\n node.y = args.y\n updated.push('y')\n }\n if (args.width !== undefined || args.height !== undefined)\n updated.push(...resized(node, args.width, args.height))\n if (args.opacity !== undefined) {\n node.opacity = args.opacity\n updated.push('opacity')\n }\n if (args.corner_radius !== undefined) {\n node.cornerRadius = args.corner_radius\n updated.push('cornerRadius')\n }\n if (args.visible !== undefined) {\n node.visible = args.visible\n updated.push('visible')\n }\n if (args.name !== undefined) {\n node.name = args.name\n updated.push('name')\n }\n if (args.text !== undefined) {\n figma.graph.updateNode(node.id, { text: args.text })\n updated.push('text')\n }\n if (args.text_direction !== undefined) {\n figma.graph.updateNode(node.id, {\n textDirection: args.text_direction\n })\n updated.push('textDirection')\n }\n if (args.flow_direction !== undefined) {\n figma.graph.updateNode(node.id, {\n layoutDirection: args.flow_direction\n })\n updated.push('layoutDirection')\n }\n if (args.font_size !== undefined) {\n editTypography({ fontSize: args.font_size })\n updated.push('fontSize')\n }\n if (args.font_weight !== undefined) {\n editTypography({ fontWeight: args.font_weight })\n updated.push('fontWeight')\n }\n if (args.overflow_direction !== undefined) {\n node.overflowDirection = args.overflow_direction\n updated.push('overflowDirection')\n }\n if (args.scroll_behavior !== undefined) {\n node.scrollBehavior = args.scroll_behavior\n updated.push('scrollBehavior')\n }\n return { id: args.id, updated }\n }\n})\n"],"mappings":";;;;;;;AAWA,SAAS,OAAO,MAAsB;CACpC,OAAO;EACL,OAAO,KAAK;EACZ,QAAQ,KAAK;EACb,wBAAwB,KAAK;EAC7B,sBAAsB,KAAK;EAC3B,gBAAgB,KAAK;CACvB;AACF;;;;;AAMA,SAAS,QAAQ,MAAsB,QAAQ,KAAK,OAAO,SAAS,KAAK,QAAkB;CACzF,MAAM,SAAS,OAAO,IAAI;CAC1B,KAAK,OAAO,OAAO,MAAM;CACzB,MAAM,QAAQ,OAAO,IAAI;CACzB,MAAM,UAAU,MAAM,UAAU,OAAO,SAAS,MAAM,WAAW,OAAO,SAAS,CAAC,MAAM,IAAI,CAAC;CAC7F,KAAK,MAAM,OAAO;EAAC;EAA0B;EAAwB;CAAgB,GACnF,IAAI,MAAM,SAAS,OAAO,MAAM,QAAQ,KAAK,GAAG;CAClD,OAAO;AACT;AAEA,MAAM,kCAAuC,IAAI,IAAI;CAAC;CAAS;CAAa;AAAU,CAAC;;AAGvF,SAAgB,cAAc,MAAqC;CACjE,IAAI,gBAAgB,IAAI,KAAK,IAAI,GAAG,OAAO;CAC3C,OAAO,gDAAgD,KAAK,KAA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AK,oBAAoB,KAAK;GAC9B,QAAQ,KAAK,mBAAmB;EAClC;EACA,IAAI,KAAK,oBAAoB,KAAA,GAAW;GACtC,KAAK,iBAAiB,KAAK;GAC3B,QAAQ,KAAK,gBAAgB;EAC/B;EACA,OAAO;GAAE,IAAI,KAAK;GAAI;EAAQ;CAChC;AACF,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import { setEffects } from "./modify/effects.js";
2
+ import { replaceFonts } from "./modify/fonts.js";
2
3
  import { rescale, setMinMax, setOpacity, setRadius, setRotation } from "./modify/geometry.js";
3
4
  import { setConstraints, setLayout, setLayoutChild } from "./modify/layout.js";
4
5
  import { replaceMatchingProperties } from "./modify/matching.js";
@@ -7,4 +8,4 @@ import { setReactions } from "./modify/reactions.js";
7
8
  import { setBlend, setLocked, setStrokeAlign, setVisible } from "./modify/state.js";
8
9
  import { setFont, setFontRange, setText, setTextProperties, setTextResize } from "./modify/text.js";
9
10
  import { updateNode } from "./modify/update.js";
10
- export { replaceMatchingProperties, rescale, setBlend, setConstraints, setEffects, setFill, setFont, setFontRange, setImageFill, setLayout, setLayoutChild, setLocked, setMinMax, setOpacity, setRadius, setReactions, setRotation, setStroke, setStrokeAlign, setText, setTextProperties, setTextResize, setVisible, updateNode };
11
+ export { replaceFonts, replaceMatchingProperties, rescale, setBlend, setConstraints, setEffects, setFill, setFont, setFontRange, setImageFill, setLayout, setLayoutChild, setLocked, setMinMax, setOpacity, setRadius, setReactions, setRotation, setStroke, setStrokeAlign, setText, setTextProperties, setTextResize, setVisible, updateNode };
@@ -1,4 +1,5 @@
1
1
  import { setEffects } from "./modify/effects.js";
2
+ import { replaceFonts } from "./modify/fonts.js";
2
3
  import { rescale, setMinMax, setOpacity, setRadius, setRotation } from "./modify/geometry.js";
3
4
  import { setConstraints, setLayout, setLayoutChild } from "./modify/layout.js";
4
5
  import { setFont, setFontRange, setText, setTextProperties, setTextResize } from "./modify/text.js";
@@ -7,4 +8,4 @@ import { setFill, setImageFill, setStroke } from "./modify/paint.js";
7
8
  import { setReactions } from "./modify/reactions.js";
8
9
  import { setBlend, setLocked, setStrokeAlign, setVisible } from "./modify/state.js";
9
10
  import { updateNode } from "./modify/update.js";
10
- export { replaceMatchingProperties, rescale, setBlend, setConstraints, setEffects, setFill, setFont, setFontRange, setImageFill, setLayout, setLayoutChild, setLocked, setMinMax, setOpacity, setRadius, setReactions, setRotation, setStroke, setStrokeAlign, setText, setTextProperties, setTextResize, setVisible, updateNode };
11
+ export { replaceFonts, replaceMatchingProperties, rescale, setBlend, setConstraints, setEffects, setFill, setFont, setFontRange, setImageFill, setLayout, setLayoutChild, setLocked, setMinMax, setOpacity, setRadius, setReactions, setRotation, setStroke, setStrokeAlign, setText, setTextProperties, setTextResize, setVisible, updateNode };
@@ -1 +1 @@
1
- {"version":3,"file":"fonts.d.ts","names":[],"sources":["../../../src/tools/read/fonts.ts"],"mappings":";;cAMa,eAAA;cAYA,WAAA;cAkCA,oBAAA"}
1
+ {"version":3,"file":"fonts.d.ts","names":[],"sources":["../../../src/tools/read/fonts.ts"],"mappings":";;cAOa,eAAA;cAYA,WAAA;cAuDA,oBAAA"}
@@ -1,3 +1,4 @@
1
+ import { listDocumentFonts } from "../../text/replace-fonts.js";
1
2
  import { defineTool } from "../schema.js";
2
3
  import { PairdrawAPI } from "../../pairdraw-api/index.js";
3
4
  import { uniq } from "es-toolkit/array";
@@ -16,14 +17,28 @@ const getFontStatus = defineTool({
16
17
  });
17
18
  const listFonts = defineTool({
18
19
  name: "list_fonts",
19
- description: "List fonts used in the current page.",
20
+ description: "List fonts used in the current page as families with their weights. Pass scope \"document\" for every face used anywhere in the document, with whether the host has it and how many text layers use it, missing faces first; use replace_fonts to swap one for an available face.",
20
21
  execution: {
21
22
  kind: "sync",
22
23
  mutation: "none"
23
24
  },
24
25
  exposure: { webmcp: false },
25
- input: v.strictObject({ family: v.optional(v.pipe(v.string(), v.description("Filter by family name (substring)"))) }),
26
+ input: v.strictObject({
27
+ family: v.optional(v.pipe(v.string(), v.description("Filter by family name (substring)"))),
28
+ scope: v.optional(v.pipe(v.picklist(["page", "document"]), v.description("page (default): families and weights of the current page. document: every face across the document with missing and layerCount")))
29
+ }),
26
30
  execute: (figma, args) => {
31
+ if (args.scope === "document") {
32
+ let fonts = listDocumentFonts(figma.graph);
33
+ if (args.family) {
34
+ const query = args.family.toLocaleLowerCase();
35
+ fonts = fonts.filter((font) => font.family.toLocaleLowerCase().includes(query));
36
+ }
37
+ return {
38
+ count: fonts.length,
39
+ fonts
40
+ };
41
+ }
27
42
  const fonts = /* @__PURE__ */ new Map();
28
43
  figma.currentPage.findAll((node) => {
29
44
  if (node.type === "TEXT") {
@@ -1 +1 @@
1
- {"version":3,"file":"fonts.js","names":[],"sources":["../../../src/tools/read/fonts.ts"],"sourcesContent":["import { uniq } from 'es-toolkit/array'\nimport * as v from 'valibot'\n\nimport { PairdrawAPI } from '#core/pairdraw-api'\nimport { defineTool } from '#core/tools/schema'\n\nexport const getFontStatus = defineTool({\n name: 'get_font_status',\n description:\n 'Report whether fonts used on the current page are faithfully available. Returns requested ' +\n 'faces, their loaded source, active substitutions, why an installed face could not be ' +\n 'loaded, and affected nodes.',\n execution: { kind: 'sync', mutation: 'none' },\n exposure: { webmcp: false },\n input: v.strictObject({}),\n execute: (figma) => new PairdrawAPI(figma).getFontStatus()\n})\n\nexport const listFonts = defineTool({\n name: 'list_fonts',\n description: 'List fonts used in the current page.',\n execution: { kind: 'sync', mutation: 'none' },\n exposure: { webmcp: false },\n input: v.strictObject({\n family: v.optional(v.pipe(v.string(), v.description('Filter by family name (substring)')))\n }),\n execute: (figma, args) => {\n const fonts = new Map<string, Set<number>>()\n const page = figma.currentPage\n page.findAll((node) => {\n if (node.type === 'TEXT') {\n const raw = figma.graph.getNode(node.id)\n if (raw) {\n const key = raw.fontFamily\n if (!fonts.has(key)) fonts.set(key, new Set())\n fonts.get(key)?.add(raw.fontWeight)\n }\n }\n return false\n })\n let result = [...fonts.entries()].map(([family, weights]) => ({\n family,\n weights: [...weights].sort((a, b) => a - b)\n }))\n if (args.family) {\n const q = args.family.toLowerCase()\n result = result.filter((font) => font.family.toLowerCase().includes(q))\n }\n return { count: result.length, fonts: result }\n }\n})\n\nexport const listAvailableFonts = defineTool({\n name: 'list_available_fonts',\n description:\n 'List font families the host can render: installed, bundled, and online families. ' +\n 'Use this to discover what fonts are available to set on a text node — distinct from list_fonts ' +\n 'which only reports families currently used in the page.',\n execution: { kind: 'async', mutation: 'none' },\n exposure: { webmcp: false },\n input: v.strictObject({\n family: v.optional(\n v.pipe(v.string(), v.description('Filter by family name (substring, case-insensitive)'))\n )\n }),\n execute: async (figma, args) => {\n const fonts = await figma.listAvailableFontsAsync()\n let families = uniq(fonts.map((font) => font.fontName.family))\n if (args.family) {\n const q = args.family.toLowerCase()\n families = families.filter((family) => family.toLowerCase().includes(q))\n }\n families.sort((a, b) => a.localeCompare(b))\n return { count: families.length, fonts: families }\n }\n})\n"],"mappings":";;;;;AAMA,MAAa,gBAAgB,WAAW;CACtC,MAAM;CACN,aACE;CAGF,WAAW;EAAE,MAAM;EAAQ,UAAU;CAAO;CAC5C,UAAU,EAAE,QAAQ,MAAM;CAC1B,OAAO,EAAE,aAAa,CAAC,CAAC;CACxB,UAAU,UAAU,IAAI,YAAY,KAAK,CAAC,CAAC,cAAc;AAC3D,CAAC;AAED,MAAa,YAAY,WAAW;CAClC,MAAM;CACN,aAAa;CACb,WAAW;EAAE,MAAM;EAAQ,UAAU;CAAO;CAC5C,UAAU,EAAE,QAAQ,MAAM;CAC1B,OAAO,EAAE,aAAa,EACpB,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,YAAY,mCAAmC,CAAC,CAAC,EAC3F,CAAC;CACD,UAAU,OAAO,SAAS;EACxB,MAAM,wBAAQ,IAAI,IAAyB;EAE3C,MADmB,YACd,SAAS,SAAS;GACrB,IAAI,KAAK,SAAS,QAAQ;IACxB,MAAM,MAAM,MAAM,MAAM,QAAQ,KA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ACnD;AACF,CAAC"}
1
+ {"version":3,"file":"fonts.js","names":[],"sources":["../../../src/tools/read/fonts.ts"],"sourcesContent":["import { uniq } from 'es-toolkit/array'\nimport * as v from 'valibot'\n\nimport { PairdrawAPI } from '#core/pairdraw-api'\nimport { listDocumentFonts } from '#core/text/replace-fonts'\nimport { defineTool } from '#core/tools/schema'\n\nexport const getFontStatus = defineTool({\n name: 'get_font_status',\n description:\n 'Report whether fonts used on the current page are faithfully available. Returns requested ' +\n 'faces, their loaded source, active substitutions, why an installed face could not be ' +\n 'loaded, and affected nodes.',\n execution: { kind: 'sync', mutation: 'none' },\n exposure: { webmcp: false },\n input: v.strictObject({}),\n execute: (figma) => new PairdrawAPI(figma).getFontStatus()\n})\n\nexport const listFonts = defineTool({\n name: 'list_fonts',\n description:\n 'List fonts used in the current page as families with their weights. Pass scope ' +\n '\"document\" for every face used anywhere in the document, with whether the host has it ' +\n 'and how many text layers use it, missing faces first; use replace_fonts to swap one for ' +\n 'an available face.',\n execution: { kind: 'sync', mutation: 'none' },\n exposure: { webmcp: false },\n input: v.strictObject({\n family: v.optional(v.pipe(v.string(), v.description('Filter by family name (substring)'))),\n scope: v.optional(\n v.pipe(\n v.picklist(['page', 'document']),\n v.description(\n 'page (default): families and weights of the current page. document: every face ' +\n 'across the document with missing and layerCount'\n )\n )\n )\n }),\n execute: (figma, args) => {\n if (args.scope === 'document') {\n let fonts = listDocumentFonts(figma.graph)\n if (args.family) {\n const query = args.family.toLocaleLowerCase()\n fonts = fonts.filter((font) => font.family.toLocaleLowerCase().includes(query))\n }\n return { count: fonts.length, fonts }\n }\n const fonts = new Map<string, Set<number>>()\n const page = figma.currentPage\n page.findAll((node) => {\n if (node.type === 'TEXT') {\n const raw = figma.graph.getNode(node.id)\n if (raw) {\n const key = raw.fontFamily\n if (!fonts.has(key)) fonts.set(key, new Set())\n fonts.get(key)?.add(raw.fontWeight)\n }\n }\n return false\n })\n let result = [...fonts.entries()].map(([family, weights]) => ({\n family,\n weights: [...weights].sort((a, b) => a - b)\n }))\n if (args.family) {\n const q = args.family.toLowerCase()\n result = result.filter((font) => font.family.toLowerCase().includes(q))\n }\n return { count: result.length, fonts: result }\n }\n})\n\nexport const listAvailableFonts = defineTool({\n name: 'list_available_fonts',\n description:\n 'List font families the host can render: installed, bundled, and online families. ' +\n 'Use this to discover what fonts are available to set on a text node — distinct from list_fonts ' +\n 'which only reports families currently used in the page.',\n execution: { kind: 'async', mutation: 'none' },\n exposure: { webmcp: false },\n input: v.strictObject({\n family: v.optional(\n v.pipe(v.string(), v.description('Filter by family name (substring, case-insensitive)'))\n )\n }),\n execute: async (figma, args) => {\n const fonts = await figma.listAvailableFontsAsync()\n let families = uniq(fonts.map((font) => font.fontName.family))\n if (args.family) {\n const q = args.family.toLowerCase()\n families = families.filter((family) => family.toLowerCase().includes(q))\n }\n families.sort((a, b) => a.localeCompare(b))\n return { count: families.length, fonts: families }\n }\n})\n"],"mappings":";;;;;;AAOA,MAAa,gBAAgB,WAAW;CACtC,MAAM;CACN,aACE;CAGF,WAAW;EAAE,MAAM;EAAQ,UAAU;CAAO;CAC5C,UAAU,EAAE,QAAQ,MAAM;CAC1B,OAAO,EAAE,aAAa,CAAC,CAAC;CACxB,UAAU,UAAU,IAAI,YAAY,KAAK,CAAC,CAAC,cAAc;AAC3D,CAAC;AAED,MAAa,YAAY,WAAW;CAClC,MAAM;CACN,aACE;CAIF,WAAW;EAAE,MAAM;EAAQ,UAAU;CAAO;CAC5C,UAAU,EAAE,QAAQ,MAAM;CAC1B,OAAO,EAAE,aAAa;EACpB,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,YAAY,mCAAmC,CAAC,CAAC;EACzF,OAAO,EAAE,SACP,EAAE,KACA,EAAE,SAAS,CAAC,QAAQ,UAAU,CAAC,GAC/B,EAAE,YACA,gIAEF,CACF,CACF;CACF,CAAC;CACD,UAAU,OAAO,SAAS;EACxB,IAAI,KAAK,UAAU,YAAY;GAC7B,IAA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,OAAO,SAAS;EAC9B,MAAM,QAAQ,MAAM,MAAM,wBAAwB;EAClD,IAAI,WAAW,KAAK,MAAM,KAAK,SAAS,KAAK,SAAS,MAAM,CAAC;EAC7D,IAAI,KAAK,QAAQ;GACf,MAAM,IAAI,KAAK,OAAO,YAAY;GAClC,WAAW,SAAS,QAAQ,WAAW,OAAO,YAAY,CAAC,CAAC,SAAS,CAAC,CAAC;EACzE;EACA,SAAS,MAAM,GAAG,MAAM,EAAE,cAAc,CAAC,CAAC;EAC1C,OAAO;GAAE,OAAO,SAAS;GAAQ,OAAO;EAAS;CACnD;AACF,CAAC"}
@@ -1,5 +1,5 @@
1
- import { defineTool, toolNumber } from "../schema.js";
2
1
  import { prepareSlotInsertion } from "../../figma-api/slots.js";
2
+ import { defineTool, toolNumber } from "../schema.js";
3
3
  import { getComponentCatalog } from "../component-catalog.js";
4
4
  import { groupBy, isPlainObject } from "es-toolkit";
5
5
  import * as v from "valibot";
@@ -42,6 +42,7 @@ const insertLibraryComponent = defineTool({
42
42
  kind: "async",
43
43
  mutation: "document"
44
44
  },
45
+ content: "imported",
45
46
  input: v.strictObject({
46
47
  library_id: v.pipe(v.string(), v.description("Library ID")),
47
48
  revision_id: v.optional(v.pipe(v.string(), v.description("Pinned revision ID"))),
@@ -1 +1 @@
1
- {"version":3,"file":"libraries.js","names":[],"sources":["../../../src/tools/read/libraries.ts"],"sourcesContent":["import { groupBy, isPlainObject } from 'es-toolkit'\nimport * as v from 'valibot'\n\nimport { prepareSlotInsertion } from '#core/figma-api/slots'\nimport { getComponentCatalog } from '#core/tools/component-catalog'\nimport { toolNumber, defineTool } from '#core/tools/schema'\n\nconst variantValuesSchema = v.pipe(\n v.string(),\n v.parseJson(),\n // A record also takes an array, as its indices.\n v.check(isPlainObject, 'Expected a JSON object'),\n v.record(v.string(), v.string())\n)\n\nexport const listLibraries = defineTool({\n name: 'list_libraries',\n description:\n 'List available published component libraries and each component asset key, name, and type. Pass a key to insert_library_component. A library does not have to be enabled to be listed.',\n execution: { kind: 'async', mutation: 'none' },\n exposure: { webmcp: false },\n input: v.strictObject({}),\n execute: async (figma) => {\n const catalog = getComponentCatalog(figma.graph)\n if (!catalog) return { count: 0, libraries: [] }\n const [libraries, components] = await Promise.all([\n catalog.listLibraries(),\n // Enabled-only would hide the keys of a library the document has not turned on.\n catalog.listComponents({ enabledOnly: false })\n ])\n const byLibrary = groupBy(components, (component) => component.libraryId)\n return {\n count: libraries.length,\n libraries: libraries.map((library) => ({\n ...library,\n assets: (byLibrary[library.libraryId] ?? []).map((component) => ({\n key: component.asset.key,\n name: component.asset.name,\n type: component.asset.type\n }))\n }))\n }\n }\n})\n\nexport const insertLibraryComponent = defineTool({\n name: 'insert_library_component',\n description:\n 'Insert a reusable component from an enabled library by stable library and asset identity.',\n\n execution: { kind: 'async', mutation: 'document' },\n input: v.strictObject({\n library_id: v.pipe(v.string(), v.description('Library ID')),\n revision_id: v.optional(v.pipe(v.string(), v.description('Pinned revision ID'))),\n asset_key: v.pipe(v.string(), v.description('Stable asset key')),\n parent_id: v.optional(v.pipe(v.string(), v.description('Optional parent node ID'))),\n x: v.optional(toolNumber(v.pipe(v.number(), v.description('X position')))),\n y: v.optional(toolNumber(v.pipe(v.number(), v.description('Y position')))),\n variant_values: v.optional(\n v.pipe(v.string(), v.description('Optional JSON object of variant property values'))\n )\n }),\n execute: async (figma, args) => {\n if (args.parent_id)\n prepareSlotInsertion(figma.graph, args.parent_id, 'insert_library_component')\n const catalog = getComponentCatalog(figma.graph)\n if (!catalog) throw new Error('No component library catalog is configured')\n let variantValues: Record<string, string> | undefined\n if (args.variant_values) {\n const parsed = v.safeParse(variantValuesSchema, args.variant_values)\n if (!parsed.success) {\n throw new TypeError(\n `variant_values must be a JSON object of strings: ${v.summarize(parsed.issues)}`\n )\n }\n variantValues = parsed.output\n }\n return catalog.insertComponent({\n libraryId: args.library_id,\n revisionId: args.revision_id,\n assetKey: args.asset_key,\n parentId: args.parent_id,\n x: args.x,\n y: args.y,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kBAAkB,CAAC;EAC/D,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,YAAY,yBAAyB,CAAC,CAAC;EAClF,GAAG,EAAE,SAAS,WAAW,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,YAAY,YAAY,CAAC,CAAC,CAAC;EACzE,GAAG,EAAE,SAAS,WAAW,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,YAAY,YAAY,CAAC,CAAC,CAAC;EACzE,gBAAgB,EAAE,SAChB,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,YAAY,iDAAiD,CAAC,CACrF;CACF,CAAC;CACD,SAAS,OAAO,OAAO,SAAS;EAC9B,IAAI,KAAK,WACP,qBAAqB,MAAM,OAAO,KAAK,WAAW,0BAA0B;EAC9E,MAAM,UAAU,oBAAoB,MAAM,KAAK;EAC/C,IAAI,CAAC,SAAS,MAAM,IAAI,MAAM,4CAA4C;EAC1E,IAAI;EACJ,IAAI,KAAK,gBAAgB;GACvB,MAAM,SAAS,EAAE,UAAU,qBAAqB,KAAK,cAAc;GACnE,IAAI,CAAC,OAAO,SACV,MAAM,IAAI,UACR,oDAAoD,EAAE,UAAU,OAAO,MAAM,GAC/E;GAEF,gBAAgB,OAAO;EACzB;EACA,OAAO,QAAQ,gBAAgB;GAC7B,WAAW,KAAK;GAChB,YAAY,KAAK;GACjB,UAAU,KAAK;GACf,UAAU,KAAK;GACf,GAAG,KAAK;GACR,GAAG,KAAK;GACR;EACF,CAAC;CACH;AACF,CAAC"}
1
+ {"version":3,"file":"libraries.js","names":[],"sources":["../../../src/tools/read/libraries.ts"],"sourcesContent":["import { groupBy, isPlainObject } from 'es-toolkit'\nimport * as v from 'valibot'\n\nimport { prepareSlotInsertion } from '#core/figma-api/slots'\nimport { getComponentCatalog } from '#core/tools/component-catalog'\nimport { toolNumber, defineTool } from '#core/tools/schema'\n\nconst variantValuesSchema = v.pipe(\n v.string(),\n v.parseJson(),\n // A record also takes an array, as its indices.\n v.check(isPlainObject, 'Expected a JSON object'),\n v.record(v.string(), v.string())\n)\n\nexport const listLibraries = defineTool({\n name: 'list_libraries',\n description:\n 'List available published component libraries and each component asset key, name, and type. Pass a key to insert_library_component. A library does not have to be enabled to be listed.',\n execution: { kind: 'async', mutation: 'none' },\n exposure: { webmcp: false },\n input: v.strictObject({}),\n execute: async (figma) => {\n const catalog = getComponentCatalog(figma.graph)\n if (!catalog) return { count: 0, libraries: [] }\n const [libraries, components] = await Promise.all([\n catalog.listLibraries(),\n // Enabled-only would hide the keys of a library the document has not turned on.\n catalog.listComponents({ enabledOnly: false })\n ])\n const byLibrary = groupBy(components, (component) => component.libraryId)\n return {\n count: libraries.length,\n libraries: libraries.map((library) => ({\n ...library,\n assets: (byLibrary[library.libraryId] ?? []).map((component) => ({\n key: component.asset.key,\n name: component.asset.name,\n type: component.asset.type\n }))\n }))\n }\n }\n})\n\nexport const insertLibraryComponent = defineTool({\n name: 'insert_library_component',\n description:\n 'Insert a reusable component from an enabled library by stable library and asset identity.',\n\n execution: { kind: 'async', mutation: 'document' },\n content: 'imported',\n input: v.strictObject({\n library_id: v.pipe(v.string(), v.description('Library ID')),\n revision_id: v.optional(v.pipe(v.string(), v.description('Pinned revision ID'))),\n asset_key: v.pipe(v.string(), v.description('Stable asset key')),\n parent_id: v.optional(v.pipe(v.string(), v.description('Optional parent node ID'))),\n x: v.optional(toolNumber(v.pipe(v.number(), v.description('X position')))),\n y: v.optional(toolNumber(v.pipe(v.number(), v.description('Y position')))),\n variant_values: v.optional(\n v.pipe(v.string(), v.description('Optional JSON object of variant property values'))\n )\n }),\n execute: async (figma, args) => {\n if (args.parent_id)\n prepareSlotInsertion(figma.graph, args.parent_id, 'insert_library_component')\n const catalog = getComponentCatalog(figma.graph)\n if (!catalog) throw new Error('No component library catalog is configured')\n let variantValues: Record<string, string> | undefined\n if (args.variant_values) {\n const parsed = v.safeParse(variantValuesSchema, args.variant_values)\n if (!parsed.success) {\n throw new TypeError(\n `variant_values must be a JSON object of strings: ${v.summarize(parsed.issues)}`\n )\n }\n variantValues = parsed.output\n }\n return catalog.insertComponent({\n libraryId: args.library_id,\n revisionId: args.revision_id,\n assetKey: args.asset_key,\n parentId: args.parent_id,\n x: args.x,\n y: args.y,\n variantValues\n })\n }\n})\n"],"mappings":";;;;;;AAOA,MAAM,sBAAsB,EAAE,KAC5B,EAAE,OAAO,GACT,EAAE,UAAU,GAEZ,EAAE,MAAM,eAAe,wBAAwB,GAC/C,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC,CACjC;AAEA,MAAa,gBAAgB,WAAW;CACtC,MAAM;CACN,aACE;CACF,WAAW;EAAE,MAAM;EAAS,UAAU;CAAO;CAC7C,UAAU,EAAE,QAAQ,MAAM;CAC1B,OAAO,EAAE,aAAa,CAAC,CAAC;CACxB,SAAS,OAAO,UAAU;EACxB,MAAM,UAAU,oBAAoB,MAAM,KAAK;EAC/C,IAAI,CAAC,SAAS,OAAO;GAAE,OAAO;GAAG,WAAW,CAAC;EAAE;EAC/C,MAAM,CAAC,WAAW,cAAc,MAAM,QAAQ,IAAI,CAChD,QAAQ,cAAc,GAEtB,QAAQ,eAAe,EAAE,aAAa,MAAM,CAAC,CAC/C,CAAC;EACD,MAAM,YAAY,QAAQ,aAAa,cAAc,UAAU,SAAS;EACxE,OAAO;GACL,OAAO,UAAU;GACjB,WAAW,UAAU,KAAK,aAAa;IACrC,GAAG;IACH,SAAS,UAAU,QAAQ,cAAc,CAAC,EAAA,CAAG,KAAK,eAAe;KAC/D,KAAK,UAAU,MAAM;KACrB,MAAM,UAAU,MAAM;KACtB,MAAM,UAAU,MAAM;IACxB,EAAE;GACJ,EAAE;EACJ;CACF;AACF,CAAC;AAED,MAAa,yBAAyB,WAAW;CAC/C,MAAM;CACN,aACE;CAEF,WAAW;EAAE,MAAM;EAAS,UAAU;CAAW;CACjD,SAAS;CACT,OAAO,EAAE,aAAa;EACpB,YAAY,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,YAAY,YAAY,CAAC;EAC1D,aAAa,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,YAAY,oBAAoB,CAAC,CAAC;EAC/E,WAAW,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,YAAY,kBAAkB,CAAC;EAC/D,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,YAAY,yBAAyB,CAAC,CAAC;EAClF,GAAG,EAAE,SAAS,WAAW,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,YAAY,YAAY,CAAC,CAAC,CAAC;EACzE,GAAG,EAAE,SAAS,WAAW,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,YAAY,YAAY,CAAC,CAAC,CAAC;EACzE,gBAAgB,EAAE,SAChB,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,YAAY,iDAAiD,CAAC,CACrF;CACF,CAAC;CACD,SAAS,OAAO,OAAO,SAAS;EAC9B,IAAI,KAAK,WACP,qBAAqB,MAAM,OAAO,KAAK,WAAW,0BAA0B;EAC9E,MAAM,UAAU,oBAAoB,MAAM,KAAK;EAC/C,IAAI,CAAC,SAAS,MAAM,IAAI,MAAM,4CAA4C;EAC1E,IAAI;EACJ,IAAI,KAAK,gBAAgB;GACvB,MAAM,SAAS,EAAE,UAAU,qBAAqB,KAAK,cAAc;GACnE,IAAI,CAAC,OAAO,SACV,MAAM,IAAI,UACR,oDAAoD,EAAE,UAAU,OAAO,MAAM,GAC/E;GAEF,gBAAgB,OAAO;EACzB;EACA,OAAO,QAAQ,gBAAgB;GAC7B,WAAW,KAAK;GAChB,YAAY,KAAK;GACjB,UAAU,KAAK;GACf,UAAU,KAAK;GACf,GAAG,KAAK;GACR,GAAG,KAAK;GACR;EACF,CAAC;CACH;AACF,CAAC"}
@@ -19,6 +19,8 @@ interface EmptySpaceRequest {
19
19
  interface EmptySpace extends Rect {
20
20
  direction: SpaceDirection | null;
21
21
  }
22
+ /** Whether `rect` comes within `gap` of `obstacle`, or covers part of it when `gap` is 0. */
23
+ declare function rectsOverlap(rect: Rect, obstacle: Rect, gap: number): boolean;
22
24
  /**
23
25
  * A free region of `width` × `height` that keeps `gap` from every obstacle, as close to the
24
26
  * anchor as the directions allow; the first direction wins a tie.
@@ -33,5 +35,5 @@ declare function spaceBesideContent(graph: SceneGraph, parentId: string, size: {
33
35
  }, gap?: number): EmptySpace;
34
36
  declare const findEmptySpaceTool: ToolDef;
35
37
  //#endregion
36
- export { DEFAULT_SPACE_GAP, EmptySpace, EmptySpaceRequest, childBoxes, findEmptySpace, findEmptySpaceTool, spaceBesideContent };
38
+ export { DEFAULT_SPACE_GAP, EmptySpace, EmptySpaceRequest, childBoxes, findEmptySpace, findEmptySpaceTool, rectsOverlap, spaceBesideContent };
37
39
  //# sourceMappingURL=space.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"space.d.ts","names":[],"sources":["../../../src/tools/read/space.ts"],"mappings":";;;;cAWM;KACD,yBAAyB;;cAGjB;UAEI;;EAEf,oBAAoB;EACpB;EACA;;EAEA,QAAQ;EACR;EACA,qBAAqB;;UAGN,mBAAmB;EAClC,WAAW;;;;;;iBAyDG,eAAe,SAAS,oBAAoB;;iBAe5C,WAAW,OAAO,YAAY,mBAAmB;;iBAUjD,mBACd,OAAO,YACP,kBACA;EAAQ;EAAe;GACvB,eACC;cAcU,oBAAA"}
1
+ {"version":3,"file":"space.d.ts","names":[],"sources":["../../../src/tools/read/space.ts"],"mappings":";;;;cAWM;KACD,yBAAyB;;cAGjB;UAEI;;EAEf,oBAAoB;EACpB;EACA;;EAEA,QAAQ;EACR;EACA,qBAAqB;;UAGN,mBAAmB;EAClC,WAAW;;;iBAIG,aAAa,MAAM,MAAM,UAAU,MAAM;;;;;iBAsDzC,eAAe,SAAS,oBAAoB;;iBAe5C,WAAW,OAAO,YAAY,mBAAmB;;iBAUjD,mBACd,OAAO,YACP,kBACA;EAAQ;EAAe;GACvB,eACC;cAcU,oBAAA"}
@@ -13,7 +13,8 @@ const SPACE_DIRECTIONS = [
13
13
  ];
14
14
  /** Room kept between a found space and the layers around it, as `import_mermaid` keeps. */
15
15
  const DEFAULT_SPACE_GAP = 100;
16
- function overlaps(rect, obstacle, gap) {
16
+ /** Whether `rect` comes within `gap` of `obstacle`, or covers part of it when `gap` is 0. */
17
+ function rectsOverlap(rect, obstacle, gap) {
17
18
  return rect.x < obstacle.x + obstacle.width + gap && rect.x + rect.width + gap > obstacle.x && rect.y < obstacle.y + obstacle.height + gap && rect.y + rect.height + gap > obstacle.y;
18
19
  }
19
20
  /**
@@ -50,7 +51,7 @@ function spaceToward(request, anchor, direction) {
50
51
  };
51
52
  for (const offset of candidates) {
52
53
  const rect = place(offset);
53
- if (!obstacles.some((obstacle) => overlaps(rect, obstacle, gap))) return rect;
54
+ if (!obstacles.some((obstacle) => rectsOverlap(rect, obstacle, gap))) return rect;
54
55
  }
55
56
  return place(candidates[candidates.length - 1] ?? start);
56
57
  }
@@ -161,6 +162,6 @@ const findEmptySpaceTool = defineTool({
161
162
  }
162
163
  });
163
164
  //#endregion
164
- export { DEFAULT_SPACE_GAP, childBoxes, findEmptySpace, findEmptySpaceTool, spaceBesideContent };
165
+ export { DEFAULT_SPACE_GAP, childBoxes, findEmptySpace, findEmptySpaceTool, rectsOverlap, spaceBesideContent };
165
166
 
166
167
  //# sourceMappingURL=space.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"space.js","names":[],"sources":["../../../src/tools/read/space.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport type { SceneGraph } from '@pairdraw/scene-graph'\nimport { getAxisAlignedBoundsInParent } from '@pairdraw/scene-graph/coordinate'\nimport { computeBounds } from '@pairdraw/scene-graph/geometry'\nimport type { Rect } from '@pairdraw/scene-graph/primitives'\n\nimport { flushPendingLayout } from '#core/figma-api'\nimport { findPageId } from '#core/io/subgraph'\nimport { defineTool, toolNumber } from '#core/tools/schema'\n\nconst SPACE_DIRECTIONS = ['right', 'below', 'left', 'above'] as const\ntype SpaceDirection = (typeof SPACE_DIRECTIONS)[number]\n\n/** Room kept between a found space and the layers around it, as `import_mermaid` keeps. */\nexport const DEFAULT_SPACE_GAP = 100\n\nexport interface EmptySpaceRequest {\n /** What is already there, in the parent's coordinates. */\n obstacles: readonly Rect[]\n width: number\n height: number\n /** The region to stay close to; null when the parent is empty. */\n anchor: Rect | null\n gap: number\n directions: readonly SpaceDirection[]\n}\n\nexport interface EmptySpace extends Rect {\n direction: SpaceDirection | null\n}\n\nfunction overlaps(rect: Rect, obstacle: Rect, gap: number): boolean {\n return (\n rect.x < obstacle.x + obstacle.width + gap &&\n rect.x + rect.width + gap > obstacle.x &&\n rect.y < obstacle.y + obstacle.height + gap &&\n rect.y + rect.height + gap > obstacle.y\n )\n}\n\n/**\n * The first free position going one way from the anchor, keeping the anchor's row or column.\n * Each candidate sits just past an obstacle's far edge, so the last one clears them all.\n */\nfunction spaceToward(request: EmptySpaceRequest, anchor: Rect, direction: SpaceDirection): Rect {\n const { obstacles, width, height, gap } = request\n const horizontal = direction === 'right' || direction === 'left'\n const forward = direction === 'right' || direction === 'below'\n const start = {\n right: anchor.x + anchor.width + gap,\n left: anchor.x - gap - width,\n below: anchor.y + anchor.height + gap,\n above: anchor.y - gap - height\n }[direction]\n const edges = obstacles.map((obstacle) => {\n if (direction === 'right') return obstacle.x + obstacle.width + gap\n if (direction === 'left') return obstacle.x - gap - width\n if (direction === 'below') return obstacle.y + obstacle.height + gap\n return obstacle.y - gap - height\n })\n const candidates = [start, ...edges.filter((edge) => (forward ? edge > start : edge < start))]\n candidates.sort((a, b) => (forward ? a - b : b - a))\n const place = (offset: number): Rect =>\n horizontal\n ? { x: offset, y: anchor.y, width, height }\n : { x: anchor.x, y: offset, width, height }\n for (const offset of candidates) {\n const rect = place(offset)\n if (!obstacles.some((obstacle) => overlaps(rect, obstacle, gap))) return rect\n }\n // Unreachable: the farthest candidate clears every obstacle along this axis.\n return place(candidates[candidates.length - 1] ?? start)\n}\n\nfunction distance(anchor: Rect, rect: Rect, direction: SpaceDirection, gap: number): number {\n if (direction === 'right') return rect.x - (anchor.x + anchor.width + gap)\n if (direction === 'left') return anchor.x - gap - (rect.x + rect.width)\n if (direction === 'below') return rect.y - (anchor.y + anchor.height + gap)\n return anchor.y - gap - (rect.y + rect.height)\n}\n\n/**\n * A free region of `width` × `height` that keeps `gap` from every obstacle, as close to the\n * anchor as the directions allow; the first direction wins a tie.\n */\nexport function findEmptySpace(request: EmptySpaceRequest): EmptySpace {\n const { anchor, width, height, gap } = request\n if (!anchor) return { x: 0, y: 0, width, height, direction: null }\n let best: { rect: Rect; direction: SpaceDirection; distance: number } | null = null\n for (const direction of request.directions) {\n const rect = spaceToward(request, anchor, direction)\n const away = distance(anchor, rect, direction, gap)\n if (!best || away < best.distance) best = { rect, direction, distance: away }\n }\n return best\n ? { ...best.rect, direction: best.direction }\n : { ...spaceToward(request, anchor, 'right'), direction: 'right' }\n}\n\n/** Each child of `parentId` as an axis-aligned box in the parent's coordinates. */\nexport function childBoxes(graph: SceneGraph, parentId: string): Rect[] {\n const parent = graph.getNode(parentId)\n if (!parent) return []\n return parent.childIds.flatMap((id) => {\n const node = graph.getNode(id)\n return node ? [getAxisAlignedBoundsInParent([node], parentId, graph)] : []\n })\n}\n\n/** Where content of a size goes beside what `parentId` already holds. */\nexport function spaceBesideContent(\n graph: SceneGraph,\n parentId: string,\n size: { width: number; height: number },\n gap = DEFAULT_SPACE_GAP\n): EmptySpace {\n const obstacles = childBoxes(graph, parentId)\n return findEmptySpace({\n obstacles,\n ...size,\n anchor: obstacles.length > 0 ? computeBounds(obstacles) : null,\n gap,\n directions: ['right']\n })\n}\n\nconst sizeInput = (description: string) =>\n toolNumber(v.pipe(v.number(), v.minValue(0), v.description(description)))\n\nexport const findEmptySpaceTool = defineTool({\n name: 'find_empty_space',\n description:\n 'Find a free region of the canvas for new content of a given size, so it overlaps nothing. Without near_id it looks beside everything the parent holds; with near_id it looks next to that layer. direction \"any\" (default) takes the nearest free spot to the right, below, left, or above. Returns x and y in the parent’s coordinates, ready for render or create tools.',\n execution: { kind: 'sync', mutation: 'none' },\n input: v.strictObject({\n width: sizeInput('Width of the content to place'),\n height: sizeInput('Height of the content to place'),\n near_id: v.optional(\n v.pipe(v.string(), v.description('Layer to place the content next to (default: all content)'))\n ),\n parent_id: v.optional(\n v.pipe(v.string(), v.description('Parent to search (default: the current page)'))\n ),\n direction: v.optional(\n v.pipe(\n v.picklist(['any', ...SPACE_DIRECTIONS]),\n v.description('Which side of the anchor to search (default: any)')\n ),\n 'any'\n ),\n gap: v.optional(\n toolNumber(\n v.pipe(\n v.number(),\n v.minValue(0),\n v.description(`Room to keep around other layers (default: ${DEFAULT_SPACE_GAP})`)\n )\n ),\n DEFAULT_SPACE_GAP\n )\n }),\n execute: (figma, args) => {\n const graph = figma.graph\n const nearParentId = args.near_id ? graph.getNode(args.near_id)?.parentId : undefined\n if (args.near_id && !nearParentId) return { error: `Node \"${args.near_id}\" not found` }\n const parentId = args.parent_id ?? nearParentId ?? figma.currentPage.id\n const parent = graph.getNode(parentId)\n if (!parent || (parent.type !== 'CANVAS' && !findPageId(graph, parentId))) {\n return { error: `Parent \"${parentId}\" not found` }\n }\n if (parent.layoutMode !== 'NONE' && parent.type !== 'CANVAS') {\n return { error: `${parent.name} places its children with auto layout; append to it instead` }\n }\n if (args.near_id && nearParentId !== parentId) {\n return { error: `Node \"${args.near_id}\" is not a child of \"${parentId}\"` }\n }\n flushPendingLayout(graph)\n const obstacles = childBoxes(graph, parentId)\n const near = args.near_id ? graph.getNode(args.near_id) : undefined\n let anchor = obstacles.length > 0 ? computeBounds(obstacles) : null\n if (near) anchor = getAxisAlignedBoundsInParent([near], parentId, graph)\n const space = findEmptySpace({\n obstacles,\n width: args.width,\n height: args.height,\n anchor,\n gap: args.gap,\n directions: args.direction === 'any' ? SPACE_DIRECTIONS : [args.direction]\n })\n // Whole pixels, rounded away from what the space was found beside.\n const round = (value: number, away: SpaceDirection) =>\n space.direction === away ? Math.floor(value) : Math.ceil(value)\n return {\n parent_id: parentId,\n x: round(space.x, 'left'),\n y: round(space.y, 'above'),\n width: args.width,\n height: args.height,\n ...(space.direction ? { direction: space.direction } : {})\n }\n }\n})\n"],"mappings":";;;;;;;AAWA,MAAM,mBAAmB;CAAC;CAAS;CAAS;CAAQ;AAAO;;AAI3D,MAAa,oBAAoB;AAiBjC,SAAS,SAAS,MAAY,UAAgB,KAAsB;CAClE,OACE,KAAK,IAAI,SAAS,IAAI,SAAS,QAAQ,OACvC,KAAK,IAAI,KAAK,QAAQ,MAAM,SAAS,KACrC,KAAK,IAAI,SAAS,IAAI,SAAS,SAAS,OACxC,KAAK,IAAI,KAAK,SAAS,MAAM,SAAS;AAE1C;;;;;AAMA,SAAS,YAAY,SAA4B,QAAc,WAAiC;CAC9F,MAAM,EAAE,WAAW,OAAO,QAAQ,QAAQ;CAC1C,MAAM,aAAa,cAAc,WAAW,cAAc;CAC1D,MAAM,UAAU,cAAc,WAAW,cAAc;CACvD,MAAM,QAAQ;EACZ,OAAO,OAAO,IAAI,OAAO,QAAQ;EACjC,MAAM,OAAO,IAAI,MAAM;EACvB,OAAO,OAAO,IAAI,OAAO,SAAS;EAClC,OAAO,OAAO,IAAI,MAAM;CAC1B,EAAE;CAOF,MAAM,aAAa,CAAC,OAAO,GANb,UAAU,KAAK,aAAa;EACxC,IAAI,cAAc,SAAS,OAAO,SAAS,IAAI,SAAS,QAAQ;EAChE,IAAI,cAAc,QAAQ,OAAO,SAAS,IAAI,MAAM;EACpD,IAAI,cAAc,SAAS,OAAO,SAAS,IAAI,SAAS,SAAS;EACjE,OAAO,SAAS,IAAI,MAAM;CAC5B,CACkC,CAAC,CAAC,QAAQ,SAAU,UAAU,OAAO,QAAQ,OAAO,KAAM,CAAC;CAC7F,WAAW,MAAM,GAAG,MAAO,UAAU,IAAI,IAAI,IAAI,CAAE;CACnD,MAAM,SAAS,WACb,aACI;EAAE,GAAG;EAAQ,GAAG,OAAO;EAAG;EAAO;CAA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neGraph } from '@pairdraw/scene-graph'\nimport { getAxisAlignedBoundsInParent } from '@pairdraw/scene-graph/coordinate'\nimport { computeBounds } from '@pairdraw/scene-graph/geometry'\nimport type { Rect } from '@pairdraw/scene-graph/primitives'\n\nimport { flushPendingLayout } from '#core/figma-api'\nimport { findPageId } from '#core/io/subgraph'\nimport { defineTool, toolNumber } from '#core/tools/schema'\n\nconst SPACE_DIRECTIONS = ['right', 'below', 'left', 'above'] as const\ntype SpaceDirection = (typeof SPACE_DIRECTIONS)[number]\n\n/** Room kept between a found space and the layers around it, as `import_mermaid` keeps. */\nexport const DEFAULT_SPACE_GAP = 100\n\nexport interface EmptySpaceRequest {\n /** What is already there, in the parent's coordinates. */\n obstacles: readonly Rect[]\n width: number\n height: number\n /** The region to stay close to; null when the parent is empty. */\n anchor: Rect | null\n gap: number\n directions: readonly SpaceDirection[]\n}\n\nexport interface EmptySpace extends Rect {\n direction: SpaceDirection | null\n}\n\n/** Whether `rect` comes within `gap` of `obstacle`, or covers part of it when `gap` is 0. */\nexport function rectsOverlap(rect: Rect, obstacle: Rect, gap: number): boolean {\n return (\n rect.x < obstacle.x + obstacle.width + gap &&\n rect.x + rect.width + gap > obstacle.x &&\n rect.y < obstacle.y + obstacle.height + gap &&\n rect.y + rect.height + gap > obstacle.y\n )\n}\n\n/**\n * The first free position going one way from the anchor, keeping the anchor's row or column.\n * Each candidate sits just past an obstacle's far edge, so the last one clears them all.\n */\nfunction spaceToward(request: EmptySpaceRequest, anchor: Rect, direction: SpaceDirection): Rect {\n const { obstacles, width, height, gap } = request\n const horizontal = direction === 'right' || direction === 'left'\n const forward = direction === 'right' || direction === 'below'\n const start = {\n right: anchor.x + anchor.width + gap,\n left: anchor.x - gap - width,\n below: anchor.y + anchor.height + gap,\n above: anchor.y - gap - height\n }[direction]\n const edges = obstacles.map((obstacle) => {\n if (direction === 'right') return obstacle.x + obstacle.width + gap\n if (direction === 'left') return obstacle.x - gap - width\n if (direction === 'below') return obstacle.y + obstacle.height + gap\n return obstacle.y - gap - height\n })\n const candidates = [start, ...edges.filter((edge) => (forward ? edge > start : edge < start))]\n candidates.sort((a, b) => (forward ? a - b : b - a))\n const place = (offset: number): Rect =>\n horizontal\n ? { x: offset, y: anchor.y, width, height }\n : { x: anchor.x, y: offset, width, height }\n for (const offset of candidates) {\n const rect = place(offset)\n if (!obstacles.some((obstacle) => rectsOverlap(rect, obstacle, gap))) return rect\n }\n // Unreachable: the farthest candidate clears every obstacle along this axis.\n return place(candidates[candidates.length - 1] ?? start)\n}\n\nfunction distance(anchor: Rect, rect: Rect, direction: SpaceDirection, gap: number): number {\n if (direction === 'right') return rect.x - (anchor.x + anchor.width + gap)\n if (direction === 'left') return anchor.x - gap - (rect.x + rect.width)\n if (direction === 'below') return rect.y - (anchor.y + anchor.height + gap)\n return anchor.y - gap - (rect.y + rect.height)\n}\n\n/**\n * A free region of `width` × `height` that keeps `gap` from every obstacle, as close to the\n * anchor as the directions allow; the first direction wins a tie.\n */\nexport function findEmptySpace(request: EmptySpaceRequest): EmptySpace {\n const { anchor, width, height, gap } = request\n if (!anchor) return { x: 0, y: 0, width, height, direction: null }\n let best: { rect: Rect; direction: SpaceDirection; distance: number } | null = null\n for (const direction of request.directions) {\n const rect = spaceToward(request, anchor, direction)\n const away = distance(anchor, rect, direction, gap)\n if (!best || away < best.distance) best = { rect, direction, distance: away }\n }\n return best\n ? { ...best.rect, direction: best.direction }\n : { ...spaceToward(request, anchor, 'right'), direction: 'right' }\n}\n\n/** Each child of `parentId` as an axis-aligned box in the parent's coordinates. */\nexport function childBoxes(graph: SceneGraph, parentId: string): Rect[] {\n const parent = graph.getNode(parentId)\n if (!parent) return []\n return parent.childIds.flatMap((id) => {\n const node = graph.getNode(id)\n return node ? [getAxisAlignedBoundsInParent([node], parentId, graph)] : []\n })\n}\n\n/** Where content of a size goes beside what `parentId` already holds. */\nexport function spaceBesideContent(\n graph: SceneGraph,\n parentId: string,\n size: { width: number; height: number },\n gap = DEFAULT_SPACE_GAP\n): EmptySpace {\n const obstacles = childBoxes(graph, parentId)\n return findEmptySpace({\n obstacles,\n ...size,\n anchor: obstacles.length > 0 ? computeBounds(obstacles) : null,\n gap,\n directions: ['right']\n })\n}\n\nconst sizeInput = (description: string) =>\n toolNumber(v.pipe(v.number(), v.minValue(0), v.description(description)))\n\nexport const findEmptySpaceTool = defineTool({\n name: 'find_empty_space',\n description:\n 'Find a free region of the canvas for new content of a given size, so it overlaps nothing. Without near_id it looks beside everything the parent holds; with near_id it looks next to that layer. direction \"any\" (default) takes the nearest free spot to the right, below, left, or above. Returns x and y in the parent’s coordinates, ready for render or create tools.',\n execution: { kind: 'sync', mutation: 'none' },\n input: v.strictObject({\n width: sizeInput('Width of the content to place'),\n height: sizeInput('Height of the content to place'),\n near_id: v.optional(\n v.pipe(v.string(), v.description('Layer to place the content next to (default: all content)'))\n ),\n parent_id: v.optional(\n v.pipe(v.string(), v.description('Parent to search (default: the current page)'))\n ),\n direction: v.optional(\n v.pipe(\n v.picklist(['any', ...SPACE_DIRECTIONS]),\n v.description('Which side of the anchor to search (default: any)')\n ),\n 'any'\n ),\n gap: v.optional(\n toolNumber(\n v.pipe(\n v.number(),\n v.minValue(0),\n v.description(`Room to keep around other layers (default: ${DEFAULT_SPACE_GAP})`)\n )\n ),\n DEFAULT_SPACE_GAP\n )\n }),\n execute: (figma, args) => {\n const graph = figma.graph\n const nearParentId = args.near_id ? graph.getNode(args.near_id)?.parentId : undefined\n if (args.near_id && !nearParentId) return { error: `Node \"${args.near_id}\" not found` }\n const parentId = args.parent_id ?? nearParentId ?? figma.currentPage.id\n const parent = graph.getNode(parentId)\n if (!parent || (parent.type !== 'CANVAS' && !findPageId(graph, parentId))) {\n return { error: `Parent \"${parentId}\" not found` }\n }\n if (parent.layoutMode !== 'NONE' && parent.type !== 'CANVAS') {\n return { error: `${parent.name} places its children with auto layout; append to it instead` }\n }\n if (args.near_id && nearParentId !== parentId) {\n return { error: `Node \"${args.near_id}\" is not a child of \"${parentId}\"` }\n }\n flushPendingLayout(graph)\n const obstacles = childBoxes(graph, parentId)\n const near = args.near_id ? graph.getNode(args.near_id) : undefined\n let anchor = obstacles.length > 0 ? computeBounds(obstacles) : null\n if (near) anchor = getAxisAlignedBoundsInParent([near], parentId, graph)\n const space = findEmptySpace({\n obstacles,\n width: args.width,\n height: args.height,\n anchor,\n gap: args.gap,\n directions: args.direction === 'any' ? SPACE_DIRECTIONS : [args.direction]\n })\n // Whole pixels, rounded away from what the space was found beside.\n const round = (value: number, away: SpaceDirection) =>\n space.direction === away ? Math.floor(value) : Math.ceil(value)\n return {\n parent_id: parentId,\n x: round(space.x, 'left'),\n y: round(space.y, 'above'),\n width: args.width,\n height: args.height,\n ...(space.direction ? { direction: space.direction } : {})\n }\n }\n})\n"],"mappings":";;;;;;;AAWA,MAAM,mBAAmB;CAAC;CAAS;CAAS;CAAQ;AAAO;;AAI3D,MAAa,oBAAoB;;AAkBjC,SAAgB,aAAa,MAAY,UAAgB,KAAsB;CAC7E,OACE,KAAK,IAAI,SAAS,IAAI,SAAS,QAAQ,OACvC,KAAK,IAAI,KAAK,QAAQ,MAAM,SAAS,KACrC,KAAK,IAAI,SAAS,IAAI,SAAS,SAAS,OACxC,KAAK,IAAI,KAAK,SAAS,MAAM,SAAS;AAE1C;;;;;AAMA,SAAS,YAAY,SAA4B,QAAc,WAAiC;CAC9F,MAAM,EAAE,WAAW,OAAO,QAAQ,QAAQ;CAC1C,MAAM,aAAa,cAAc,WAAW,cAAc;CAC1D,MAAM,UAAU,cAAc,WAAW,cAAc;CACvD,MAAM,QAAQ;EACZ,OAAO,OAAO,IAAI,OAAO,QAAQ;EACjC,MAAM,OAAO,IAAI,MAAM;EACvB,OAAO,OAAO,IAAI,OAAO,SAAS;EAClC,OAAO,OAAO,IAAI,MAAM;CAC1B,EAAE;CAOF,MAAM,aAAa,CAAC,OAAO,GANb,UAAU,KAAK,aAAa;EACxC,IAAI,cAAc,SAAS,OAAO,SAAS,IAAI,SAAS,QAAQ;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KAAK,MAAM,KAAK,IAAI,KAAK,KAAK,KAAK;EAChE,OAAO;GACL,WAAW;GACX,GAAG,MAAM,MAAM,GAAG,MAAM;GACxB,GAAG,MAAM,MAAM,GAAG,OAAO;GACzB,OAAO,KAAK;GACZ,QAAQ,KAAK;GACb,GAAI,MAAM,YAAY,EAAE,WAAW,MAAM,UAAU,IAAI,CAAC;EAC1D;CACF;AACF,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { ToolDef } from "../schema.js";
2
2
  //#region src/tools/registry/core.d.ts
3
3
  /**
4
- * Core tools registered by default in AI chat (26 tools, ~5K schema tokens).
4
+ * Core tools registered by default in AI chat (27 tools, ~5K schema tokens).
5
5
  * Covers 90%+ of design sessions: render, describe, modify, structure, and diff checks.
6
6
  */
7
7
  declare const CORE_TOOLS: ToolDef[];
@@ -1 +1 @@
1
- {"version":3,"file":"core.d.ts","names":[],"sources":["../../../src/tools/registry/core.ts"],"mappings":";;;;;;cAwBa,YAAY"}
1
+ {"version":3,"file":"core.d.ts","names":[],"sources":["../../../src/tools/registry/core.ts"],"mappings":";;;;;;cAyBa,YAAY"}
@@ -2,6 +2,7 @@ import { diffChanges } from "../analyze/diff/changes.js";
2
2
  import { diffCreate } from "../analyze/diff/tools.js";
3
3
  import { diffVisual } from "../analyze/diff/visual.js";
4
4
  import { evalCode } from "../analyze/eval/index.js";
5
+ import { checkResponsive } from "../analyze/responsive/index.js";
5
6
  import { calc } from "../calc.js";
6
7
  import { render } from "../create/render.js";
7
8
  import { describe } from "../describe/index.js";
@@ -20,7 +21,7 @@ import { batchUpdate } from "../structure/batch.js";
20
21
  import { viewportZoomToFit } from "../vector/viewport.js";
21
22
  //#region src/tools/registry/core.ts
22
23
  /**
23
- * Core tools registered by default in AI chat (26 tools, ~5K schema tokens).
24
+ * Core tools registered by default in AI chat (27 tools, ~5K schema tokens).
24
25
  * Covers 90%+ of design sessions: render, describe, modify, structure, and diff checks.
25
26
  */
26
27
  const CORE_TOOLS = [
@@ -47,6 +48,7 @@ const CORE_TOOLS = [
47
48
  diffCreate,
48
49
  diffJSX,
49
50
  diffVisual,
51
+ checkResponsive,
50
52
  calc,
51
53
  evalCode,
52
54
  viewportZoomToFit
@@ -1 +1 @@
1
- {"version":3,"file":"core.js","names":[],"sources":["../../../src/tools/registry/core.ts"],"sourcesContent":["import { diffChanges, diffCreate, diffVisual, evalCode } from '#core/tools/analyze'\nimport { calc } from '#core/tools/calc'\nimport { render } from '#core/tools/create'\nimport { describe } from '#core/tools/describe'\nimport {\n setFill,\n setLayout,\n setLayoutChild,\n setRadius,\n setStroke,\n setText,\n setTextProperties,\n updateNode\n} from '#core/tools/modify'\nimport { diffJSX, findNodes, getJSX, getNode, getSelection } from '#core/tools/read'\nimport type { ToolDef } from '#core/tools/schema'\nimport { stockPhoto } from '#core/tools/stock-photo'\nimport { batchUpdate, deleteNode, nodeResize, reparentNode } from '#core/tools/structure'\nimport { viewportZoomToFit } from '#core/tools/vector'\n\n/**\n * Core tools registered by default in AI chat (26 tools, ~5K schema tokens).\n * Covers 90%+ of design sessions: render, describe, modify, structure, and diff checks.\n */\nexport const CORE_TOOLS: ToolDef[] = [\n // Read\n getSelection,\n getNode,\n findNodes,\n getJSX,\n // Create\n render,\n // Modify\n updateNode,\n setLayout,\n setLayoutChild,\n setRadius,\n setFill,\n setStroke,\n setText,\n setTextProperties,\n // Structure\n deleteNode,\n reparentNode,\n nodeResize,\n batchUpdate,\n // Stock photos\n stockPhoto,\n // Inspect & utility\n describe,\n diffChanges,\n diffCreate,\n diffJSX,\n diffVisual,\n calc,\n evalCode,\n viewportZoomToFit\n]\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAa,aAAwB;CAEnC;CACA;CACA;CACA;CAEA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CAEA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
1
+ {"version":3,"file":"core.js","names":[],"sources":["../../../src/tools/registry/core.ts"],"sourcesContent":["import { diffChanges, diffCreate, diffVisual, evalCode } from '#core/tools/analyze'\nimport { checkResponsive } from '#core/tools/analyze/responsive'\nimport { calc } from '#core/tools/calc'\nimport { render } from '#core/tools/create'\nimport { describe } from '#core/tools/describe'\nimport {\n setFill,\n setLayout,\n setLayoutChild,\n setRadius,\n setStroke,\n setText,\n setTextProperties,\n updateNode\n} from '#core/tools/modify'\nimport { diffJSX, findNodes, getJSX, getNode, getSelection } from '#core/tools/read'\nimport type { ToolDef } from '#core/tools/schema'\nimport { stockPhoto } from '#core/tools/stock-photo'\nimport { batchUpdate, deleteNode, nodeResize, reparentNode } from '#core/tools/structure'\nimport { viewportZoomToFit } from '#core/tools/vector'\n\n/**\n * Core tools registered by default in AI chat (27 tools, ~5K schema tokens).\n * Covers 90%+ of design sessions: render, describe, modify, structure, and diff checks.\n */\nexport const CORE_TOOLS: ToolDef[] = [\n // Read\n getSelection,\n getNode,\n findNodes,\n getJSX,\n // Create\n render,\n // Modify\n updateNode,\n setLayout,\n setLayoutChild,\n setRadius,\n setFill,\n setStroke,\n setText,\n setTextProperties,\n // Structure\n deleteNode,\n reparentNode,\n nodeResize,\n batchUpdate,\n // Stock photos\n stockPhoto,\n // Inspect & utility\n describe,\n diffChanges,\n diffCreate,\n diffJSX,\n diffVisual,\n checkResponsive,\n calc,\n evalCode,\n viewportZoomToFit\n]\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,MAAa,aAAwB;CAEnC;CACA;CACA;CACA;CAEA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CAEA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"extended.d.ts","names":[],"sources":["../../../src/tools/registry/extended.ts"],"mappings":";;;;;;cAoIa,gBAAgB"}
1
+ {"version":3,"file":"extended.d.ts","names":[],"sources":["../../../src/tools/registry/extended.ts"],"mappings":";;;;;;cAoJa,gBAAgB"}