@pairdraw/core 0.21.0 → 0.22.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 (626) hide show
  1. package/dist/canvas/boolean.d.ts +6 -1
  2. package/dist/canvas/boolean.d.ts.map +1 -1
  3. package/dist/canvas/boolean.js +10 -2
  4. package/dist/canvas/boolean.js.map +1 -1
  5. package/dist/canvas/color-space.d.ts +45 -0
  6. package/dist/canvas/color-space.d.ts.map +1 -0
  7. package/dist/canvas/color-space.js +39 -0
  8. package/dist/canvas/color-space.js.map +1 -0
  9. package/dist/canvas/fills.d.ts +10 -10
  10. package/dist/canvas/fills.d.ts.map +1 -1
  11. package/dist/canvas/fills.js +116 -62
  12. package/dist/canvas/fills.js.map +1 -1
  13. package/dist/canvas/flatten.d.ts +11 -3
  14. package/dist/canvas/flatten.d.ts.map +1 -1
  15. package/dist/canvas/flatten.js +62 -4
  16. package/dist/canvas/flatten.js.map +1 -1
  17. package/dist/canvas/index.d.ts +2 -1
  18. package/dist/canvas/index.js +2 -1
  19. package/dist/canvas/layout-grids.d.ts +5 -2
  20. package/dist/canvas/layout-grids.d.ts.map +1 -1
  21. package/dist/canvas/layout-grids.js +7 -2
  22. package/dist/canvas/layout-grids.js.map +1 -1
  23. package/dist/canvas/noise/render.d.ts +17 -4
  24. package/dist/canvas/noise/render.d.ts.map +1 -1
  25. package/dist/canvas/noise/render.js +21 -6
  26. package/dist/canvas/noise/render.js.map +1 -1
  27. package/dist/canvas/noise/shader.d.ts +4 -4
  28. package/dist/canvas/noise/shader.d.ts.map +1 -1
  29. package/dist/canvas/noise/shader.js +5 -6
  30. package/dist/canvas/noise/shader.js.map +1 -1
  31. package/dist/canvas/overlays/annotations.d.ts +19 -0
  32. package/dist/canvas/overlays/annotations.d.ts.map +1 -0
  33. package/dist/canvas/overlays/annotations.js +110 -0
  34. package/dist/canvas/overlays/annotations.js.map +1 -0
  35. package/dist/canvas/overlays/auto-layout-hover.d.ts +11 -1
  36. package/dist/canvas/overlays/auto-layout-hover.d.ts.map +1 -1
  37. package/dist/canvas/overlays/auto-layout-hover.js +25 -1
  38. package/dist/canvas/overlays/auto-layout-hover.js.map +1 -1
  39. package/dist/canvas/overlays/feedback.js +1 -1
  40. package/dist/canvas/overlays/feedback.js.map +1 -1
  41. package/dist/canvas/overlays/index.d.ts +2 -2
  42. package/dist/canvas/overlays/index.js +2 -2
  43. package/dist/canvas/overlays/measurement.d.ts +7 -1
  44. package/dist/canvas/overlays/measurement.d.ts.map +1 -1
  45. package/dist/canvas/overlays/measurement.js +42 -4
  46. package/dist/canvas/overlays/measurement.js.map +1 -1
  47. package/dist/canvas/overlays/presence.d.ts.map +1 -1
  48. package/dist/canvas/overlays/presence.js +21 -24
  49. package/dist/canvas/overlays/presence.js.map +1 -1
  50. package/dist/canvas/renderer/colors.d.ts +7 -1
  51. package/dist/canvas/renderer/colors.d.ts.map +1 -1
  52. package/dist/canvas/renderer/colors.js +9 -1
  53. package/dist/canvas/renderer/colors.js.map +1 -1
  54. package/dist/canvas/renderer/document-surface.d.ts +15 -6
  55. package/dist/canvas/renderer/document-surface.d.ts.map +1 -1
  56. package/dist/canvas/renderer/document-surface.js +1 -0
  57. package/dist/canvas/renderer/document-surface.js.map +1 -1
  58. package/dist/canvas/renderer/lifecycle.d.ts.map +1 -1
  59. package/dist/canvas/renderer/lifecycle.js +2 -2
  60. package/dist/canvas/renderer/lifecycle.js.map +1 -1
  61. package/dist/canvas/renderer/methods.d.ts +1 -0
  62. package/dist/canvas/renderer/methods.d.ts.map +1 -1
  63. package/dist/canvas/renderer/methods.js +4 -1
  64. package/dist/canvas/renderer/methods.js.map +1 -1
  65. package/dist/canvas/renderer/overlay-pass.d.ts.map +1 -1
  66. package/dist/canvas/renderer/overlay-pass.js +6 -1
  67. package/dist/canvas/renderer/overlay-pass.js.map +1 -1
  68. package/dist/canvas/renderer/pipeline.d.ts.map +1 -1
  69. package/dist/canvas/renderer/pipeline.js +7 -0
  70. package/dist/canvas/renderer/pipeline.js.map +1 -1
  71. package/dist/canvas/renderer/types.d.ts +10 -0
  72. package/dist/canvas/renderer/types.d.ts.map +1 -1
  73. package/dist/canvas/renderer.d.ts +10 -2
  74. package/dist/canvas/renderer.d.ts.map +1 -1
  75. package/dist/canvas/renderer.js +15 -3
  76. package/dist/canvas/renderer.js.map +1 -1
  77. package/dist/canvas/scene.d.ts.map +1 -1
  78. package/dist/canvas/scene.js +9 -9
  79. package/dist/canvas/scene.js.map +1 -1
  80. package/dist/canvas/shaders/compile.d.ts +3 -1
  81. package/dist/canvas/shaders/compile.d.ts.map +1 -1
  82. package/dist/canvas/shaders/compile.js +12 -3
  83. package/dist/canvas/shaders/compile.js.map +1 -1
  84. package/dist/canvas/shaders/draw.d.ts.map +1 -1
  85. package/dist/canvas/shaders/draw.js +10 -3
  86. package/dist/canvas/shaders/draw.js.map +1 -1
  87. package/dist/canvas/shaders/effect.d.ts.map +1 -1
  88. package/dist/canvas/shaders/effect.js +6 -16
  89. package/dist/canvas/shaders/effect.js.map +1 -1
  90. package/dist/clipboard/pairdraw.d.ts.map +1 -1
  91. package/dist/clipboard/pairdraw.js +1 -0
  92. package/dist/clipboard/pairdraw.js.map +1 -1
  93. package/dist/editor/bridges/clipboard.d.ts +2 -0
  94. package/dist/editor/bridges/clipboard.d.ts.map +1 -1
  95. package/dist/editor/bridges/clipboard.js +1 -0
  96. package/dist/editor/bridges/clipboard.js.map +1 -1
  97. package/dist/editor/bridges/components.d.ts +14 -7
  98. package/dist/editor/bridges/components.d.ts.map +1 -1
  99. package/dist/editor/bridges/components.js +6 -0
  100. package/dist/editor/bridges/components.js.map +1 -1
  101. package/dist/editor/bridges/structure.d.ts +1 -1
  102. package/dist/editor/bridges/structure.d.ts.map +1 -1
  103. package/dist/editor/bridges/undo.d.ts +1 -1
  104. package/dist/editor/clipboard/code.d.ts +32 -0
  105. package/dist/editor/clipboard/code.d.ts.map +1 -0
  106. package/dist/editor/clipboard/code.js +30 -0
  107. package/dist/editor/clipboard/code.js.map +1 -0
  108. package/dist/editor/clipboard/export.js +2 -2
  109. package/dist/editor/clipboard/export.js.map +1 -1
  110. package/dist/editor/clipboard/paste/dependencies.d.ts +14 -0
  111. package/dist/editor/clipboard/paste/dependencies.d.ts.map +1 -0
  112. package/dist/editor/clipboard/paste/dependencies.js +0 -0
  113. package/dist/editor/clipboard/paste/run.d.ts +14 -0
  114. package/dist/editor/clipboard/paste/run.d.ts.map +1 -0
  115. package/dist/editor/clipboard/paste/run.js +47 -0
  116. package/dist/editor/clipboard/paste/run.js.map +1 -0
  117. package/dist/editor/clipboard/styled.d.ts +2 -8
  118. package/dist/editor/clipboard/styled.d.ts.map +1 -1
  119. package/dist/editor/clipboard/styled.js +2 -32
  120. package/dist/editor/clipboard/styled.js.map +1 -1
  121. package/dist/editor/clipboard.d.ts +2 -0
  122. package/dist/editor/clipboard.d.ts.map +1 -1
  123. package/dist/editor/clipboard.js +34 -0
  124. package/dist/editor/clipboard.js.map +1 -1
  125. package/dist/editor/components/instances.d.ts +5 -0
  126. package/dist/editor/components/instances.d.ts.map +1 -1
  127. package/dist/editor/components/instances.js +69 -4
  128. package/dist/editor/components/instances.js.map +1 -1
  129. package/dist/editor/components/slots/index.d.ts.map +1 -1
  130. package/dist/editor/components/slots/index.js +7 -0
  131. package/dist/editor/components/slots/index.js.map +1 -1
  132. package/dist/editor/components.d.ts +6 -0
  133. package/dist/editor/components.d.ts.map +1 -1
  134. package/dist/editor/components.js +14 -2
  135. package/dist/editor/components.js.map +1 -1
  136. package/dist/editor/create.d.ts +30 -3
  137. package/dist/editor/create.d.ts.map +1 -1
  138. package/dist/editor/create.js +11 -2
  139. package/dist/editor/create.js.map +1 -1
  140. package/dist/editor/design-tokens.d.ts +1 -1
  141. package/dist/editor/design-tokens.d.ts.map +1 -1
  142. package/dist/editor/design-tokens.js +4 -18
  143. package/dist/editor/design-tokens.js.map +1 -1
  144. package/dist/editor/image-edit.d.ts.map +1 -1
  145. package/dist/editor/image-edit.js +1 -2
  146. package/dist/editor/image-edit.js.map +1 -1
  147. package/dist/editor/index.d.ts +4 -4
  148. package/dist/editor/index.js +1 -1
  149. package/dist/editor/layout-mode.d.ts +3 -1
  150. package/dist/editor/layout-mode.d.ts.map +1 -1
  151. package/dist/editor/layout-mode.js +97 -2
  152. package/dist/editor/layout-mode.js.map +1 -1
  153. package/dist/editor/nodes.d.ts +2 -0
  154. package/dist/editor/nodes.d.ts.map +1 -1
  155. package/dist/editor/nodes.js +22 -7
  156. package/dist/editor/nodes.js.map +1 -1
  157. package/dist/editor/read-only/actions.js +6 -0
  158. package/dist/editor/read-only/actions.js.map +1 -1
  159. package/dist/editor/selection/overlays.d.ts +1 -0
  160. package/dist/editor/selection/overlays.d.ts.map +1 -1
  161. package/dist/editor/selection/overlays.js +7 -0
  162. package/dist/editor/selection/overlays.js.map +1 -1
  163. package/dist/editor/selection/read.d.ts +8 -0
  164. package/dist/editor/selection.d.ts +9 -0
  165. package/dist/editor/selection.d.ts.map +1 -1
  166. package/dist/editor/state/shared.js +1 -0
  167. package/dist/editor/state/shared.js.map +1 -1
  168. package/dist/editor/state/view.d.ts.map +1 -1
  169. package/dist/editor/state/view.js +2 -0
  170. package/dist/editor/state/view.js.map +1 -1
  171. package/dist/editor/structure/boolean.d.ts +1 -1
  172. package/dist/editor/structure/boolean.d.ts.map +1 -1
  173. package/dist/editor/structure/boolean.js +20 -1
  174. package/dist/editor/structure/boolean.js.map +1 -1
  175. package/dist/editor/structure/container-wrap.d.ts +8 -2
  176. package/dist/editor/structure/container-wrap.d.ts.map +1 -1
  177. package/dist/editor/structure/container-wrap.js +17 -5
  178. package/dist/editor/structure/container-wrap.js.map +1 -1
  179. package/dist/editor/structure/flatten.d.ts.map +1 -1
  180. package/dist/editor/structure/flatten.js +8 -7
  181. package/dist/editor/structure/flatten.js.map +1 -1
  182. package/dist/editor/structure/group/ungroup.d.ts.map +1 -1
  183. package/dist/editor/structure/group/ungroup.js +2 -0
  184. package/dist/editor/structure/group/ungroup.js.map +1 -1
  185. package/dist/editor/structure/outline-stroke.d.ts.map +1 -1
  186. package/dist/editor/structure/outline-stroke.js +5 -0
  187. package/dist/editor/structure/outline-stroke.js.map +1 -1
  188. package/dist/editor/structure.d.ts +1 -1
  189. package/dist/editor/structure.d.ts.map +1 -1
  190. package/dist/editor/styles.d.ts +26 -0
  191. package/dist/editor/styles.d.ts.map +1 -0
  192. package/dist/editor/styles.js +127 -0
  193. package/dist/editor/styles.js.map +1 -0
  194. package/dist/editor/text/selection-style.d.ts +1 -0
  195. package/dist/editor/text/selection-style.d.ts.map +1 -1
  196. package/dist/editor/text/selection-style.js +10 -2
  197. package/dist/editor/text/selection-style.js.map +1 -1
  198. package/dist/editor/tool-registry.d.ts.map +1 -1
  199. package/dist/editor/tool-registry.js +6 -0
  200. package/dist/editor/tool-registry.js.map +1 -1
  201. package/dist/editor/types.d.ts +14 -2
  202. package/dist/editor/types.d.ts.map +1 -1
  203. package/dist/editor/variable-bindings.d.ts.map +1 -1
  204. package/dist/editor/variable-bindings.js +6 -1
  205. package/dist/editor/variable-bindings.js.map +1 -1
  206. package/dist/figma-api/accessors/basic.d.ts.map +1 -1
  207. package/dist/figma-api/accessors/basic.js +22 -1
  208. package/dist/figma-api/accessors/basic.js.map +1 -1
  209. package/dist/figma-api/accessors/shape.js +1 -1
  210. package/dist/figma-api/accessors/text/index.js +1 -1
  211. package/dist/figma-api/accessors/text/ranges.js +1 -1
  212. package/dist/figma-api/accessors/text/references.js +1 -1
  213. package/dist/figma-api/accessors/variables.js +1 -1
  214. package/dist/figma-api/accessors/vector.d.ts.map +1 -1
  215. package/dist/figma-api/accessors/vector.js +8 -22
  216. package/dist/figma-api/accessors/vector.js.map +1 -1
  217. package/dist/figma-api/accessors/visual.js +1 -1
  218. package/dist/figma-api/compatibility.d.ts +1 -1
  219. package/dist/figma-api/compatibility.d.ts.map +1 -1
  220. package/dist/figma-api/component-scope.d.ts +14 -0
  221. package/dist/figma-api/component-scope.d.ts.map +1 -0
  222. package/dist/figma-api/component-scope.js +28 -0
  223. package/dist/figma-api/component-scope.js.map +1 -0
  224. package/dist/figma-api/components.d.ts.map +1 -1
  225. package/dist/figma-api/components.js +26 -2
  226. package/dist/figma-api/components.js.map +1 -1
  227. package/dist/figma-api/flatten.js +3 -3
  228. package/dist/figma-api/flatten.js.map +1 -1
  229. package/dist/figma-api/index.d.ts +77 -6
  230. package/dist/figma-api/index.d.ts.map +1 -1
  231. package/dist/figma-api/index.js +188 -2
  232. package/dist/figma-api/index.js.map +1 -1
  233. package/dist/figma-api/node-types.d.ts +2 -1
  234. package/dist/figma-api/node-types.d.ts.map +1 -1
  235. package/dist/figma-api/overrides.d.ts +26 -1
  236. package/dist/figma-api/overrides.d.ts.map +1 -1
  237. package/dist/figma-api/overrides.js +157 -10
  238. package/dist/figma-api/overrides.js.map +1 -1
  239. package/dist/figma-api/proxy.d.ts +2 -0
  240. package/dist/figma-api/proxy.d.ts.map +1 -1
  241. package/dist/figma-api/proxy.js +10 -2
  242. package/dist/figma-api/proxy.js.map +1 -1
  243. package/dist/figma-api/reactions.d.ts +61 -5
  244. package/dist/figma-api/reactions.d.ts.map +1 -1
  245. package/dist/figma-api/reactions.js +144 -11
  246. package/dist/figma-api/reactions.js.map +1 -1
  247. package/dist/figma-api/shape-with-text.js +1 -1
  248. package/dist/figma-api/slots.d.ts +3 -1
  249. package/dist/figma-api/slots.d.ts.map +1 -1
  250. package/dist/figma-api/slots.js +9 -8
  251. package/dist/figma-api/slots.js.map +1 -1
  252. package/dist/index.d.ts +4 -4
  253. package/dist/index.js +1 -1
  254. package/dist/io/formats/code/detect.d.ts +23 -0
  255. package/dist/io/formats/code/detect.d.ts.map +1 -0
  256. package/dist/io/formats/code/detect.js +46 -0
  257. package/dist/io/formats/code/detect.js.map +1 -0
  258. package/dist/io/formats/code/index.d.ts +5 -0
  259. package/dist/io/formats/code/index.js +5 -0
  260. package/dist/io/formats/code/read.d.ts +45 -0
  261. package/dist/io/formats/code/read.d.ts.map +1 -0
  262. package/dist/io/formats/code/read.js +86 -0
  263. package/dist/io/formats/code/read.js.map +1 -0
  264. package/dist/io/formats/code/stylesheet.d.ts +13 -0
  265. package/dist/io/formats/code/stylesheet.d.ts.map +1 -0
  266. package/dist/io/formats/code/stylesheet.js +21 -0
  267. package/dist/io/formats/code/stylesheet.js.map +1 -0
  268. package/dist/io/formats/code/tokens.d.ts +18 -0
  269. package/dist/io/formats/code/tokens.d.ts.map +1 -0
  270. package/dist/io/formats/code/tokens.js +135 -0
  271. package/dist/io/formats/code/tokens.js.map +1 -0
  272. package/dist/io/formats/design-tokens/apply.d.ts +7 -3
  273. package/dist/io/formats/design-tokens/apply.d.ts.map +1 -1
  274. package/dist/io/formats/design-tokens/apply.js.map +1 -1
  275. package/dist/io/formats/drawio/warnings.d.ts +17 -2
  276. package/dist/io/formats/drawio/warnings.d.ts.map +1 -1
  277. package/dist/io/formats/drawio/warnings.js +14 -7
  278. package/dist/io/formats/drawio/warnings.js.map +1 -1
  279. package/dist/io/formats/fig/export/patch/fields.js +5 -0
  280. package/dist/io/formats/fig/export/patch/fields.js.map +1 -1
  281. package/dist/io/formats/fig/export/patch/index.d.ts.map +1 -1
  282. package/dist/io/formats/fig/export/patch/index.js +20 -20
  283. package/dist/io/formats/fig/export/patch/index.js.map +1 -1
  284. package/dist/io/formats/fig/export/setup.d.ts.map +1 -1
  285. package/dist/io/formats/fig/export/setup.js +5 -1
  286. package/dist/io/formats/fig/export/setup.js.map +1 -1
  287. package/dist/io/formats/fig/index.d.ts +3 -2
  288. package/dist/io/formats/fig/index.js +2 -2
  289. package/dist/io/formats/fig/read.d.ts.map +1 -1
  290. package/dist/io/formats/fig/read.js +5 -2
  291. package/dist/io/formats/fig/read.js.map +1 -1
  292. package/dist/io/formats/html/index.d.ts +1 -0
  293. package/dist/io/formats/html/index.d.ts.map +1 -1
  294. package/dist/io/formats/html/index.js +5 -3
  295. package/dist/io/formats/html/index.js.map +1 -1
  296. package/dist/io/formats/html/layers.d.ts +3 -1
  297. package/dist/io/formats/html/layers.d.ts.map +1 -1
  298. package/dist/io/formats/html/layers.js +6 -1
  299. package/dist/io/formats/html/layers.js.map +1 -1
  300. package/dist/io/formats/pdf/export.d.ts.map +1 -1
  301. package/dist/io/formats/pdf/export.js +7 -3
  302. package/dist/io/formats/pdf/export.js.map +1 -1
  303. package/dist/io/formats/pdf/plan.d.ts +3 -0
  304. package/dist/io/formats/pdf/plan.d.ts.map +1 -1
  305. package/dist/io/formats/pdf/plan.js +60 -36
  306. package/dist/io/formats/pdf/plan.js.map +1 -1
  307. package/dist/io/formats/pen/index.d.ts.map +1 -1
  308. package/dist/io/formats/pen/index.js +13 -4
  309. package/dist/io/formats/pen/index.js.map +1 -1
  310. package/dist/io/formats/raster/headless.d.ts.map +1 -1
  311. package/dist/io/formats/raster/headless.js +3 -2
  312. package/dist/io/formats/raster/headless.js.map +1 -1
  313. package/dist/io/formats/raster/index.d.ts +2 -2
  314. package/dist/io/formats/raster/index.js +2 -2
  315. package/dist/io/formats/raster/render.d.ts +10 -2
  316. package/dist/io/formats/raster/render.d.ts.map +1 -1
  317. package/dist/io/formats/raster/render.js +35 -9
  318. package/dist/io/formats/raster/render.js.map +1 -1
  319. package/dist/io/formats/svg/defs.d.ts.map +1 -1
  320. package/dist/io/formats/svg/defs.js +19 -1
  321. package/dist/io/formats/svg/defs.js.map +1 -1
  322. package/dist/io/formats/svg/export.d.ts +5 -2
  323. package/dist/io/formats/svg/export.d.ts.map +1 -1
  324. package/dist/io/formats/svg/export.js +59 -10
  325. package/dist/io/formats/svg/export.js.map +1 -1
  326. package/dist/io/formats/svg/index.d.ts +2 -2
  327. package/dist/io/formats/svg/index.js +2 -2
  328. package/dist/io/formats/svg/text/layout.d.ts.map +1 -1
  329. package/dist/io/formats/svg/text/layout.js +4 -2
  330. package/dist/io/formats/svg/text/layout.js.map +1 -1
  331. package/dist/io/formats/video/record.d.ts.map +1 -1
  332. package/dist/io/formats/video/record.js +24 -9
  333. package/dist/io/formats/video/record.js.map +1 -1
  334. package/dist/io/formats.d.ts.map +1 -1
  335. package/dist/io/formats.js +30 -17
  336. package/dist/io/formats.js.map +1 -1
  337. package/dist/io/index.d.ts +2 -2
  338. package/dist/io/types.d.ts +11 -2
  339. package/dist/io/types.d.ts.map +1 -1
  340. package/dist/kiwi/fig/population/client.d.ts.map +1 -1
  341. package/dist/kiwi/fig/population/client.js +2 -1
  342. package/dist/kiwi/fig/population/client.js.map +1 -1
  343. package/dist/kiwi/fig/session/document-state.d.ts +46 -2
  344. package/dist/kiwi/fig/session/document-state.d.ts.map +1 -1
  345. package/dist/kiwi/fig/session/document-state.js +113 -5
  346. package/dist/kiwi/fig/session/document-state.js.map +1 -1
  347. package/dist/kiwi/fig/session/options.d.ts +4 -0
  348. package/dist/kiwi/fig/session/options.d.ts.map +1 -1
  349. package/dist/kiwi/fig/session/options.js.map +1 -1
  350. package/dist/layout/apply.d.ts.map +1 -1
  351. package/dist/layout/apply.js +8 -4
  352. package/dist/layout/apply.js.map +1 -1
  353. package/dist/layout/auto-layout-handles.js +1 -1
  354. package/dist/layout/auto-layout-handles.js.map +1 -1
  355. package/dist/layout/axis-sizing.d.ts.map +1 -1
  356. package/dist/layout/axis-sizing.js +1 -1
  357. package/dist/layout/axis-sizing.js.map +1 -1
  358. package/dist/layout/derived.d.ts.map +1 -1
  359. package/dist/layout/derived.js +1 -1
  360. package/dist/layout/derived.js.map +1 -1
  361. package/dist/layout/effective-generated-text.js +1 -1
  362. package/dist/layout/effective-generated-text.js.map +1 -1
  363. package/dist/layout/grid.d.ts +3 -1
  364. package/dist/layout/grid.d.ts.map +1 -1
  365. package/dist/layout/grid.js +57 -16
  366. package/dist/layout/grid.js.map +1 -1
  367. package/dist/layout.d.ts +1 -1
  368. package/dist/layout.js +6 -5
  369. package/dist/layout.js.map +1 -1
  370. package/dist/node/fs.d.ts.map +1 -1
  371. package/dist/node/fs.js +28 -7
  372. package/dist/node/fs.js.map +1 -1
  373. package/dist/prototype/easing.d.ts +13 -5
  374. package/dist/prototype/easing.d.ts.map +1 -1
  375. package/dist/prototype/easing.js +46 -6
  376. package/dist/prototype/easing.js.map +1 -1
  377. package/dist/prototype/scenes.d.ts +31 -0
  378. package/dist/prototype/scenes.d.ts.map +1 -1
  379. package/dist/prototype/scenes.js +220 -31
  380. package/dist/prototype/scenes.js.map +1 -1
  381. package/dist/prototype/session.d.ts.map +1 -1
  382. package/dist/prototype/session.js +1 -0
  383. package/dist/prototype/session.js.map +1 -1
  384. package/dist/prototype/smart-animate/animation.d.ts +2 -1
  385. package/dist/prototype/smart-animate/animation.d.ts.map +1 -1
  386. package/dist/prototype/smart-animate/animation.js +2 -2
  387. package/dist/prototype/smart-animate/animation.js.map +1 -1
  388. package/dist/prototype/timeline.d.ts +10 -1
  389. package/dist/prototype/timeline.d.ts.map +1 -1
  390. package/dist/prototype/timeline.js +69 -23
  391. package/dist/prototype/timeline.js.map +1 -1
  392. package/dist/prototype/variables.d.ts +23 -0
  393. package/dist/prototype/variables.d.ts.map +1 -0
  394. package/dist/prototype/variables.js +237 -0
  395. package/dist/prototype/variables.js.map +1 -0
  396. package/dist/rpc/read-commands.d.ts +5 -0
  397. package/dist/rpc/read-commands.d.ts.map +1 -1
  398. package/dist/rpc/read-commands.js +4 -1
  399. package/dist/rpc/read-commands.js.map +1 -1
  400. package/dist/text/character-style.d.ts +8 -1
  401. package/dist/text/character-style.d.ts.map +1 -1
  402. package/dist/text/character-style.js +39 -1
  403. package/dist/text/character-style.js.map +1 -1
  404. package/dist/text/index.d.ts +2 -2
  405. package/dist/text/index.js +2 -2
  406. package/dist/tools/create/basic.js +3 -4
  407. package/dist/tools/create/basic.js.map +1 -1
  408. package/dist/tools/create/behaviours.js +1 -1
  409. package/dist/tools/create/code.d.ts +6 -0
  410. package/dist/tools/create/code.d.ts.map +1 -0
  411. package/dist/tools/create/code.js +68 -0
  412. package/dist/tools/create/code.js.map +1 -0
  413. package/dist/tools/create/html.d.ts.map +1 -1
  414. package/dist/tools/create/html.js +9 -57
  415. package/dist/tools/create/html.js.map +1 -1
  416. package/dist/tools/create/icons.js +1 -1
  417. package/dist/tools/create/inputs.d.ts +11 -0
  418. package/dist/tools/create/inputs.d.ts.map +1 -0
  419. package/dist/tools/create/inputs.js +15 -0
  420. package/dist/tools/create/inputs.js.map +1 -0
  421. package/dist/tools/create/mermaid.d.ts.map +1 -1
  422. package/dist/tools/create/mermaid.js +5 -6
  423. package/dist/tools/create/mermaid.js.map +1 -1
  424. package/dist/tools/create/place.d.ts +30 -0
  425. package/dist/tools/create/place.d.ts.map +1 -0
  426. package/dist/tools/create/place.js +70 -0
  427. package/dist/tools/create/place.js.map +1 -0
  428. package/dist/tools/create/render.js +1 -1
  429. package/dist/tools/create/svg.js +1 -1
  430. package/dist/tools/create/vector.js +1 -1
  431. package/dist/tools/create.d.ts +2 -1
  432. package/dist/tools/create.js +2 -1
  433. package/dist/tools/css/gradient.d.ts +28 -0
  434. package/dist/tools/css/gradient.d.ts.map +1 -0
  435. package/dist/tools/css/gradient.js +118 -0
  436. package/dist/tools/css/gradient.js.map +1 -0
  437. package/dist/tools/image-ai/generate.js +1 -1
  438. package/dist/tools/modify/geometry.js +5 -5
  439. package/dist/tools/modify/geometry.js.map +1 -1
  440. package/dist/tools/modify/layout.d.ts.map +1 -1
  441. package/dist/tools/modify/layout.js +7 -1
  442. package/dist/tools/modify/layout.js.map +1 -1
  443. package/dist/tools/modify/matching.js +1 -1
  444. package/dist/tools/modify/overrides.d.ts +6 -0
  445. package/dist/tools/modify/overrides.d.ts.map +1 -0
  446. package/dist/tools/modify/overrides.js +27 -0
  447. package/dist/tools/modify/overrides.js.map +1 -0
  448. package/dist/tools/modify/paint.d.ts.map +1 -1
  449. package/dist/tools/modify/paint.js +84 -39
  450. package/dist/tools/modify/paint.js.map +1 -1
  451. package/dist/tools/modify/text.d.ts +2 -1
  452. package/dist/tools/modify/text.d.ts.map +1 -1
  453. package/dist/tools/modify/text.js +79 -8
  454. package/dist/tools/modify/text.js.map +1 -1
  455. package/dist/tools/modify/update.d.ts.map +1 -1
  456. package/dist/tools/modify/update.js +18 -2
  457. package/dist/tools/modify/update.js.map +1 -1
  458. package/dist/tools/modify.d.ts +3 -2
  459. package/dist/tools/modify.js +3 -2
  460. package/dist/tools/read/css.d.ts.map +1 -1
  461. package/dist/tools/read/css.js +29 -12
  462. package/dist/tools/read/css.js.map +1 -1
  463. package/dist/tools/read/libraries.js +1 -1
  464. package/dist/tools/read/nodes.d.ts.map +1 -1
  465. package/dist/tools/read/nodes.js +19 -5
  466. package/dist/tools/read/nodes.js.map +1 -1
  467. package/dist/tools/registry/extended.d.ts.map +1 -1
  468. package/dist/tools/registry/extended.js +6 -1
  469. package/dist/tools/registry/extended.js.map +1 -1
  470. package/dist/tools/text-range.d.ts +11 -0
  471. package/dist/tools/text-range.d.ts.map +1 -0
  472. package/dist/tools/text-range.js +26 -0
  473. package/dist/tools/text-range.js.map +1 -0
  474. package/dist/tools/variables/bindings.js +1 -1
  475. package/dist/tools/variables/bindings.js.map +1 -1
  476. package/dist/tools/variables/unbind.js +1 -1
  477. package/dist/tools/variables/unbind.js.map +1 -1
  478. package/dist/tools/vector/path.d.ts.map +1 -1
  479. package/dist/tools/vector/path.js +7 -21
  480. package/dist/tools/vector/path.js.map +1 -1
  481. package/dist/vector/rebase.d.ts +17 -0
  482. package/dist/vector/rebase.d.ts.map +1 -0
  483. package/dist/vector/rebase.js +32 -0
  484. package/dist/vector/rebase.js.map +1 -0
  485. package/package.json +14 -9
  486. package/src/canvas/boolean.ts +12 -1
  487. package/src/canvas/color-space.ts +73 -0
  488. package/src/canvas/fills.ts +130 -83
  489. package/src/canvas/flatten.ts +92 -7
  490. package/src/canvas/index.ts +9 -0
  491. package/src/canvas/layout-grids.ts +15 -2
  492. package/src/canvas/noise/render.ts +35 -7
  493. package/src/canvas/noise/shader.ts +8 -10
  494. package/src/canvas/overlays/annotations.ts +117 -0
  495. package/src/canvas/overlays/auto-layout-hover.ts +41 -1
  496. package/src/canvas/overlays/feedback.ts +7 -2
  497. package/src/canvas/overlays/index.ts +1 -1
  498. package/src/canvas/overlays/measurement.ts +49 -3
  499. package/src/canvas/overlays/presence.ts +35 -32
  500. package/src/canvas/renderer/colors.ts +14 -0
  501. package/src/canvas/renderer/document-surface.ts +16 -6
  502. package/src/canvas/renderer/lifecycle.ts +2 -2
  503. package/src/canvas/renderer/methods.ts +4 -0
  504. package/src/canvas/renderer/overlay-pass.ts +4 -0
  505. package/src/canvas/renderer/pipeline.ts +8 -0
  506. package/src/canvas/renderer/types.ts +8 -0
  507. package/src/canvas/renderer.ts +21 -2
  508. package/src/canvas/scene.ts +15 -7
  509. package/src/canvas/shaders/compile.ts +14 -3
  510. package/src/canvas/shaders/draw.ts +11 -4
  511. package/src/canvas/shaders/effect.ts +6 -18
  512. package/src/clipboard/pairdraw.ts +1 -0
  513. package/src/editor/bridges/clipboard.ts +1 -0
  514. package/src/editor/bridges/components.ts +10 -0
  515. package/src/editor/clipboard/code.ts +50 -0
  516. package/src/editor/clipboard/export.ts +2 -2
  517. package/src/editor/clipboard/paste/dependencies.ts +18 -0
  518. package/src/editor/clipboard/paste/run.ts +64 -0
  519. package/src/editor/clipboard/styled.ts +4 -52
  520. package/src/editor/clipboard.ts +40 -0
  521. package/src/editor/components/instances.ts +92 -4
  522. package/src/editor/components/slots/index.ts +7 -0
  523. package/src/editor/components.ts +16 -2
  524. package/src/editor/create.ts +15 -1
  525. package/src/editor/design-tokens.ts +3 -23
  526. package/src/editor/image-edit.ts +5 -2
  527. package/src/editor/index.ts +1 -0
  528. package/src/editor/layout-mode.ts +131 -3
  529. package/src/editor/nodes.ts +30 -5
  530. package/src/editor/read-only/actions.ts +6 -0
  531. package/src/editor/selection/overlays.ts +8 -0
  532. package/src/editor/state/shared.ts +1 -0
  533. package/src/editor/state/view.ts +2 -0
  534. package/src/editor/structure/boolean.ts +29 -1
  535. package/src/editor/structure/container-wrap.ts +20 -4
  536. package/src/editor/structure/flatten.ts +15 -8
  537. package/src/editor/structure/group/ungroup.ts +2 -0
  538. package/src/editor/structure/outline-stroke.ts +5 -0
  539. package/src/editor/styles.ts +203 -0
  540. package/src/editor/text/selection-style.ts +18 -1
  541. package/src/editor/tool-registry.ts +2 -0
  542. package/src/editor/types.ts +14 -0
  543. package/src/editor/variable-bindings.ts +11 -0
  544. package/src/figma-api/accessors/basic.ts +33 -1
  545. package/src/figma-api/accessors/vector.ts +6 -13
  546. package/src/figma-api/compatibility.ts +1 -0
  547. package/src/figma-api/component-scope.ts +36 -0
  548. package/src/figma-api/components.ts +24 -0
  549. package/src/figma-api/flatten.ts +7 -3
  550. package/src/figma-api/index.ts +302 -6
  551. package/src/figma-api/node-types.ts +1 -0
  552. package/src/figma-api/overrides.ts +192 -5
  553. package/src/figma-api/proxy.ts +16 -1
  554. package/src/figma-api/reactions.ts +163 -12
  555. package/src/figma-api/slots.ts +10 -9
  556. package/src/io/formats/code/detect.ts +67 -0
  557. package/src/io/formats/code/index.ts +17 -0
  558. package/src/io/formats/code/read.ts +143 -0
  559. package/src/io/formats/code/stylesheet.ts +24 -0
  560. package/src/io/formats/code/tokens.ts +159 -0
  561. package/src/io/formats/design-tokens/apply.ts +3 -2
  562. package/src/io/formats/drawio/warnings.ts +27 -8
  563. package/src/io/formats/fig/export/patch/fields.ts +11 -0
  564. package/src/io/formats/fig/export/patch/index.ts +23 -19
  565. package/src/io/formats/fig/export/setup.ts +8 -1
  566. package/src/io/formats/fig/index.ts +6 -0
  567. package/src/io/formats/fig/read.ts +11 -2
  568. package/src/io/formats/html/index.ts +9 -3
  569. package/src/io/formats/html/layers.ts +7 -0
  570. package/src/io/formats/pdf/export.ts +19 -7
  571. package/src/io/formats/pdf/plan.ts +71 -32
  572. package/src/io/formats/pen/index.ts +14 -6
  573. package/src/io/formats/raster/headless.ts +3 -1
  574. package/src/io/formats/raster/index.ts +2 -0
  575. package/src/io/formats/raster/render.ts +49 -9
  576. package/src/io/formats/svg/defs.ts +27 -1
  577. package/src/io/formats/svg/export.ts +75 -13
  578. package/src/io/formats/svg/index.ts +1 -0
  579. package/src/io/formats/svg/text/layout.ts +5 -3
  580. package/src/io/formats/video/record.ts +33 -9
  581. package/src/io/formats.ts +45 -19
  582. package/src/io/index.ts +1 -0
  583. package/src/io/types.ts +10 -0
  584. package/src/kiwi/fig/population/client.ts +6 -1
  585. package/src/kiwi/fig/session/document-state.ts +195 -5
  586. package/src/kiwi/fig/session/options.ts +2 -0
  587. package/src/layout/apply.ts +12 -4
  588. package/src/layout/auto-layout-handles.ts +1 -1
  589. package/src/layout/axis-sizing.ts +3 -1
  590. package/src/layout/derived.ts +3 -1
  591. package/src/layout/effective-generated-text.ts +1 -1
  592. package/src/layout/grid.ts +91 -21
  593. package/src/layout.ts +16 -3
  594. package/src/node/fs.ts +32 -7
  595. package/src/prototype/easing.ts +79 -7
  596. package/src/prototype/scenes.ts +244 -15
  597. package/src/prototype/session.ts +1 -0
  598. package/src/prototype/smart-animate/animation.ts +4 -3
  599. package/src/prototype/timeline.ts +118 -26
  600. package/src/prototype/variables.ts +189 -0
  601. package/src/rpc/read-commands.ts +19 -1
  602. package/src/text/character-style.ts +47 -0
  603. package/src/text/index.ts +1 -1
  604. package/src/tools/create/basic.ts +2 -3
  605. package/src/tools/create/code.ts +85 -0
  606. package/src/tools/create/html.ts +9 -46
  607. package/src/tools/create/inputs.ts +12 -0
  608. package/src/tools/create/mermaid.ts +6 -6
  609. package/src/tools/create/place.ts +80 -0
  610. package/src/tools/create.ts +1 -0
  611. package/src/tools/css/gradient.ts +147 -0
  612. package/src/tools/modify/geometry.ts +5 -5
  613. package/src/tools/modify/layout.ts +19 -0
  614. package/src/tools/modify/overrides.ts +35 -0
  615. package/src/tools/modify/paint.ts +124 -54
  616. package/src/tools/modify/text.ts +91 -7
  617. package/src/tools/modify/update.ts +23 -2
  618. package/src/tools/modify.ts +9 -1
  619. package/src/tools/read/css.ts +46 -12
  620. package/src/tools/read/nodes.ts +26 -4
  621. package/src/tools/registry/extended.ts +6 -0
  622. package/src/tools/text-range.ts +29 -0
  623. package/src/tools/variables/bindings.ts +4 -1
  624. package/src/tools/variables/unbind.ts +4 -1
  625. package/src/tools/vector/path.ts +11 -13
  626. package/src/vector/rebase.ts +33 -0
@@ -1 +1 @@
1
- {"version":3,"file":"css.js","names":[],"sources":["../../../src/tools/read/css.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport type { ColorProfile, SceneGraph, SceneNode, ShadowEffect } from '@pairdraw/scene-graph'\nimport { colorToDocumentCSS } from '@pairdraw/scene-graph/color'\nimport type { Color } from '@pairdraw/scene-graph/primitives'\n\nimport { defineTool, nodeIdsField, toolNumber } from '#core/tools/schema'\n\n/**\n * A subtree as CSS-shaped lines: one line per node, lengths in px, colours in the document's\n * profile with the token that binds them in `var(--name, …)` form: hex in an sRGB document,\n * `color(display-p3 …)` in a Display P3 one. This is the read side of the CSS shorthand the\n * setters accept, so a value read here can be written back unchanged.\n */\nexport const DEFAULT_MAX_BYTES = 6000\nexport const HARD_MAX_BYTES = 20_000\n\nconst AXIS_JUSTIFY: Record<string, string> = {\n CENTER: 'center',\n MAX: 'end',\n SPACE_BETWEEN: 'space-between',\n SPACE_AROUND: 'space-around'\n}\n\nconst AXIS_ITEMS: Record<string, string> = {\n CENTER: 'center',\n MAX: 'end',\n STRETCH: 'stretch',\n BASELINE: 'baseline'\n}\n\n/** A length as CSS writes it: whole px where it is whole, up to two decimals otherwise. */\nfunction px(value: number): string {\n return `${Math.round(value * 100) / 100}px`\n}\n\n/**\n * The radius line, read the way `shape-details` reads corners: the per-corner fields while\n * `independentCorners` is set (the uniform field is stale then), four values in CSS order when\n * they differ, one otherwise. The four values write back through `set_radius`'s shorthand.\n */\nfunction radiusOf(node: SceneNode): string | null {\n if (node.independentCorners) {\n const corners = [\n node.topLeftRadius,\n node.topRightRadius,\n node.bottomRightRadius,\n node.bottomLeftRadius\n ]\n if (corners.every((value) => value === corners[0])) {\n return corners[0] > 0 ? px(corners[0]) : null\n }\n return corners.map((value) => (value === 0 ? '0' : px(value))).join(' ')\n }\n return node.cornerRadius > 0 ? px(node.cornerRadius) : null\n}\n\nfunction box(value: number): string {\n return String(Math.round(value))\n}\n\n/** UTF-8 bytes without a Node Buffer, so the tool runs in the app as well as headless. */\nfunction utf8Length(text: string): number {\n let bytes = 0\n for (let index = 0; index < text.length; index++) {\n const code = text.charCodeAt(index)\n if (code < 0x80) bytes += 1\n else if (code < 0x800) bytes += 2\n else if (code < 0xd800 || code >= 0xe000) bytes += 3\n else bytes += 4\n }\n return bytes\n}\n\nfunction boundName(graph: SceneGraph, node: SceneNode, field: string): string | null {\n const variableId = node.boundVariables[field]\n if (!variableId) return null\n return graph.variables.get(variableId)?.name ?? null\n}\n\n/**\n * A stored colour as the shorthand writes it: `#RRGGBB` in an sRGB document, `color(display-p3 …)`\n * in a Display P3 one, where hex would name a different colour. The shorthand carries no alpha, as\n * it never has, so the paint's opacity is left to `opacity`.\n */\nfunction cssColor(color: Color, profile: ColorProfile): string {\n return colorToDocumentCSS({ ...color, a: 1 }, profile)\n}\n\n/** A colour in the document's profile, or `var(--token, …)` when a variable paints it. */\nfunction paintOf(node: SceneNode, graph: SceneGraph, field: string, paint: string): string {\n const name = boundName(graph, node, field)\n return name ? `var(--${name}, ${paint})` : paint\n}\n\nfunction background(node: SceneNode, graph: SceneGraph): string | null {\n const index = node.fills.findIndex((candidate) => candidate.type === 'SOLID' && candidate.visible)\n const solid = index === -1 ? undefined : node.fills[index]\n if (solid) {\n const paint = cssColor(solid.color, graph.documentColorSpace)\n return paintOf(node, graph, `fills/${index}/color`, paint)\n }\n const otherIndex = node.fills.findIndex((candidate) => candidate.visible)\n const other = otherIndex === -1 ? undefined : node.fills[otherIndex]\n if (!other) return null\n return other.type.startsWith('GRADIENT') ? 'gradient' : 'image'\n}\n\nfunction border(node: SceneNode, graph: SceneGraph): string | null {\n const index = node.strokes.findIndex((candidate) => candidate.visible)\n const stroke = index === -1 ? undefined : node.strokes[index]\n if (!stroke) return null\n const paint = cssColor(stroke.color, graph.documentColorSpace)\n return `${px(stroke.weight)} ${paintOf(node, graph, `strokes/${index}/color`, paint)}`\n}\n\n/** Padding in CSS order, compressed to the fewest values that say the same thing. */\nfunction padding(node: SceneNode): string | null {\n const top = node.paddingTop\n const right = node.paddingRight\n const bottom = node.paddingBottom\n const left = node.paddingLeft\n if (top === 0 && right === 0 && bottom === 0 && left === 0) return null\n if (top === right && right === bottom && bottom === left) return px(top)\n if (top === bottom && right === left) return `${px(top)} ${px(right)}`\n return `${px(top)} ${px(right)} ${px(bottom)} ${px(left)}`\n}\n\nfunction shadowOf(prefix: string, effect: ShadowEffect, profile: ColorProfile): string {\n return `${prefix}:${px(effect.offset.x)} ${px(effect.offset.y)} ${px(effect.radius)} ${cssColor(effect.color, profile)}`\n}\n\nfunction effects(node: SceneNode, profile: ColorProfile): string[] {\n const out: string[] = []\n for (const effect of node.effects) {\n if (!effect.visible) continue\n if (effect.type === 'DROP_SHADOW') out.push(shadowOf('shadow', effect, profile))\n else if (effect.type === 'INNER_SHADOW') out.push(shadowOf('inner-shadow', effect, profile))\n else if (effect.type === 'LAYER_BLUR' || effect.type === 'FOREGROUND_BLUR')\n out.push(`blur:${px(effect.radius)}`)\n else out.push('backdrop-blur')\n }\n return out\n}\n\nfunction layoutDecls(node: SceneNode): string[] {\n if (node.layoutMode === 'NONE') return []\n const out = [node.layoutMode === 'HORIZONTAL' ? 'flex:row' : 'flex:column']\n if (node.itemSpacing > 0) {\n out.push(\n node.layoutWrap === 'WRAP' && node.counterAxisSpacing > 0\n ? `gap:${px(node.itemSpacing)} ${px(node.counterAxisSpacing)}`\n : `gap:${px(node.itemSpacing)}`\n )\n }\n const paddingValue = padding(node)\n if (paddingValue) out.push(`padding:${paddingValue}`)\n const justify = AXIS_JUSTIFY[node.primaryAxisAlign]\n if (justify) out.push(`justify:${justify}`)\n const items = AXIS_ITEMS[node.counterAxisAlign]\n if (items) out.push(`items:${items}`)\n if (node.layoutWrap === 'WRAP') out.push('wrap')\n if (node.primaryAxisSizing === 'HUG') out.push('hug:main')\n if (node.counterAxisSizing === 'HUG') out.push('hug:cross')\n return out\n}\n\nfunction boxDecls(node: SceneNode, graph: SceneGraph): string[] {\n const out: string[] = []\n if (node.layoutAlignSelf === 'STRETCH') out.push('stretch')\n if (node.layoutGrow > 0) out.push(`grow:${Math.round(node.layoutGrow * 100) / 100}`)\n const bg = background(node, graph)\n if (bg) out.push(`bg:${bg}`)\n const stroke = border(node, graph)\n if (stroke) out.push(`border:${stroke}`)\n const radius = radiusOf(node)\n if (radius) out.push(`radius:${radius}`)\n if (node.minWidth !== null) out.push(`min-w:${px(node.minWidth)}`)\n if (node.maxWidth !== null) out.push(`max-w:${px(node.maxWidth)}`)\n if (node.minHeight !== null) out.push(`min-h:${px(node.minHeight)}`)\n if (node.maxHeight !== null) out.push(`max-h:${px(node.maxHeight)}`)\n out.push(...effects(node, graph.documentColorSpace))\n if (node.opacity !== 1) out.push(`opacity:${Math.round(node.opacity * 100) / 100}`)\n if (node.clipsContent) out.push('clip')\n return out\n}\n\nfunction lineHeightOf(node: SceneNode): string {\n const lineHeight = node.lineHeight\n if (!lineHeight) return 'auto'\n return lineHeight.unit === 'PERCENT'\n ? `${Math.round(lineHeight.value * 100) / 100}%`\n : px(lineHeight.value)\n}\n\nfunction textDecls(node: SceneNode, graph: SceneGraph): string[] {\n const out = [\n `font:${node.fontWeight} ${px(node.fontSize)}/${lineHeightOf(node)} ${node.fontFamily}`\n ]\n const bg = background(node, graph)\n if (bg) out.push(`color:${bg}`)\n if (node.textAlignHorizontal !== 'LEFT') {\n out.push(`text-align:${node.textAlignHorizontal.toLowerCase()}`)\n }\n if (node.maxLines !== null && node.maxLines > 0) out.push(`max-lines:${node.maxLines}`)\n if (node.textAutoResize === 'NONE') out.push('fixed')\n return out\n}\n\nfunction lineOf(node: SceneNode, graph: SceneGraph): string {\n const decls =\n node.type === 'TEXT' ? textDecls(node, graph) : [...layoutDecls(node), ...boxDecls(node, graph)]\n const label =\n node.type === 'TEXT'\n ? `\"${node.text.slice(0, 40).replaceAll('\\\\', '\\\\\\\\').replaceAll('\"', '\\\\\"').replaceAll('\\n', '\\\\n')}\"`\n : node.name\n const body = decls.length > 0 ? ` {${decls.join(';')}}` : ''\n return `${label}#${node.id} ${box(node.width)}×${box(node.height)}${body}`\n}\n\ninterface Budget {\n bytes: number\n limit: number\n truncated: boolean\n}\n\n/** What a cut-off walk left out, counted through the same visible-node rule as the lines. */\nfunction countVisible(graph: SceneGraph, nodeId: string): number {\n const node = graph.getNode(nodeId)\n if (!node || !node.visible) return 0\n let count = 1\n for (const childId of node.childIds) count += countVisible(graph, childId)\n return count\n}\n\nfunction truncationTail(omitted: number): string {\n return `… +${omitted} node${omitted === 1 ? '' : 's'} (raise max_bytes or narrow with depth)`\n}\n\n/**\n * Depth-first lines until the budget is spent. A line that does not fit ends the walk; the kept\n * lines never exceed the limit on their own, so the reply can always stay within `max_bytes`.\n */\nfunction collect(\n graph: SceneGraph,\n nodeId: string,\n depth: number,\n indent: string,\n lines: string[],\n budget: Budget\n): void {\n const node = graph.getNode(nodeId)\n if (!node || !node.visible) return\n if (budget.truncated) return\n const line = `${indent}${lineOf(node, graph)}`\n const fits = budget.bytes + utf8Length(line) + 1 <= budget.limit\n if (!fits) {\n budget.truncated = true\n return\n }\n budget.bytes += utf8Length(line) + 1\n lines.push(line)\n if (depth > 0) {\n for (const childId of node.childIds) {\n collect(graph, childId, depth - 1, `${indent} `, lines, budget)\n }\n }\n}\n\n/**\n * A subtree within `maxBytes`. The truncation tail is charged to the same budget: trailing lines\n * give way first, then the tail is left out when only the kept lines fit. A block whose first line\n * does not fit returns no CSS at all; the reply's `truncated`/`omitted` fields report the cut.\n */\nfunction blockFor(\n graph: SceneGraph,\n nodeId: string,\n depth: number,\n maxBytes: number\n): { css: string; truncated?: true; omitted?: number } {\n const lines: string[] = []\n const budget: Budget = { bytes: 0, limit: maxBytes, truncated: false }\n collect(graph, nodeId, depth, '', lines, budget)\n if (!budget.truncated) return { css: lines.join('\\n') }\n // Every visible node either has a line or is left out, so the omitted count follows from the\n // node total. Each dropped line's byte count includes the newline collect charged for it.\n let omitted = countVisible(graph, nodeId) - lines.length\n while (\n lines.length > 1 &&\n budget.bytes + 1 + utf8Length(truncationTail(omitted)) > budget.limit\n ) {\n const last = lines.pop()\n if (last === undefined) break\n budget.bytes -= utf8Length(last) + 1\n omitted = countVisible(graph, nodeId) - lines.length\n }\n if (lines.length === 0) {\n return { css: '', truncated: true, omitted: countVisible(graph, nodeId) }\n }\n const head = lines.join('\\n')\n if (budget.bytes + 1 + utf8Length(truncationTail(omitted)) > budget.limit) {\n return { css: head, truncated: true, omitted }\n }\n return { css: `${head}\\n${truncationTail(omitted)}`, truncated: true, omitted }\n}\n\nexport const getCSS = defineTool({\n name: 'get_css',\n description:\n 'Read a node subtree as compact CSS-like lines: `Name#id W×H {flex:row;gap:12px;padding:16px 24px;bg:var(--color/brand, #4F46E5);radius:8px}`. ' +\n 'Lengths are px; short names: flex (implies display:flex), gap, padding, justify, items, wrap, hug, stretch, grow, bg, border, radius, min/max-w/h, shadow, blur, opacity, clip; text: `font:600 14px/20px Inter`, color, text-align, max-lines. ' +\n \"Colours follow the document's profile, as get_jsx writes them: `#RRGGBB` in an sRGB document, `color(display-p3 r g b)` in a Display P3 one, and either inside the `var()` fallback. \" +\n 'Use it for geometry and style; describe gives roles and design issues. The setters accept the same shorthand (padding/gap/radius strings, `var(--token)` colours).',\n execution: { kind: 'sync', mutation: 'none' },\n input: v.strictObject({\n id: v.optional(v.pipe(v.string(), v.description('Node ID (single node)'))),\n ids: nodeIdsField('Node IDs (several nodes in one call)'),\n depth: v.optional(\n toolNumber(\n v.pipe(\n v.number(),\n v.description('Child levels to include (default: as many as the budget holds)')\n )\n )\n ),\n max_bytes: v.optional(\n toolNumber(\n v.pipe(v.number(), v.description('Byte budget for the reply (default 6000, max 20000)'))\n )\n )\n }),\n execute: (figma, args) => {\n const maxBytes = Math.min(args.max_bytes ?? DEFAULT_MAX_BYTES, HARD_MAX_BYTES)\n const depth = args.depth ?? 100\n\n if (args.ids && Array.isArray(args.ids)) {\n const blocks: string[] = []\n let omitted = 0\n let truncated = false\n let used = 0\n for (const nodeId of args.ids) {\n if (!figma.graph.getNode(nodeId)) return { error: `Node \"${nodeId}\" not found` }\n const separator = blocks.length === 0 ? 0 : 1\n const block = blockFor(figma.graph, nodeId, depth, maxBytes - used - separator)\n if (block.css === '') {\n omitted += block.omitted ?? 0\n truncated = truncated || block.truncated === true\n continue\n }\n blocks.push(block.css)\n used += utf8Length(block.css) + separator\n omitted += block.omitted ?? 0\n truncated = truncated || block.truncated === true\n }\n const css = blocks.join('\\n')\n if (!truncated) return { ids: args.ids, css }\n return { ids: args.ids, css, truncated: true, omitted }\n }\n\n if (!args.id) return { error: 'Provide id (string) or ids (string[])' }\n if (!figma.graph.getNode(args.id)) return { error: `Node \"${args.id}\" not found` }\n const block = blockFor(figma.graph, args.id, depth, maxBytes)\n return { id: args.id, ...block }\n }\n})\n"],"mappings":";;;;;;;;;;AAcA,MAAa,oBAAoB;AACjC,MAAa,iBAAiB;AAE9B,MAAM,eAAuC;CAC3C,QAAQ;CACR,KAAK;CACL,eAAe;CACf,cAAc;AAChB;AAEA,MAAM,aAAqC;CACzC,QAAQ;CACR,KAAK;CACL,SAAS;CACT,UAAU;AACZ;;AAGA,SAAS,GAAG,OAAuB;CACjC,OAAO,GAAG,KAAK,MAAM,QAAQ,GAAG,IAAI,IAAI;AAC1C;;;;;;AAOA,SAAS,SAAS,MAAgC;CAChD,IAAI,KAAK,oBAAoB;EAC3B,MAAM,UAAU;GACd,KAAK;GACL,KAAK;GACL,KAAK;GACL,KAAK;EACP;EACA,IAAI,QAAQ,OAAO,UAAU,UAAU,QAAQ,EAAE,GAC/C,OAAO,QAAQ,KAAK,IAAI,GAAG,QAAQ,EAAE,IAAI;EAE3C,OAAO,QAAQ,KAAK,UAAW,UAAU,IAAI,MAA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O,EAAE,OAAO,SAAS,KAAK,GAAG,aAAa;EACjF,MAAM,QAAQ,SAAS,MAAM,OAAO,KAAK,IAAI,OAAO,QAAQ;EAC5D,OAAO;GAAE,IAAI,KAAK;GAAI,GAAG;EAAM;CACjC;AACF,CAAC"}
1
+ {"version":3,"file":"css.js","names":[],"sources":["../../../src/tools/read/css.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport { diamondFillToCSS, gradientFillToCSS } from '@pairdraw/dom-css/export'\nimport type { ColorProfile, SceneGraph, SceneNode, ShadowEffect } from '@pairdraw/scene-graph'\nimport { colorToDocumentCSS } from '@pairdraw/scene-graph/color'\nimport type { Color } from '@pairdraw/scene-graph/primitives'\n\nimport { defineTool, nodeIdsField, toolNumber } from '#core/tools/schema'\n\n/**\n * A subtree as CSS-shaped lines: one line per node, lengths in px, colours in the document's\n * profile with the token that binds them in `var(--name, …)` form: hex in an sRGB document,\n * `color(display-p3 …)` in a Display P3 one. This is the read side of the CSS shorthand the\n * setters accept, so a value read here can be written back unchanged.\n */\nexport const DEFAULT_MAX_BYTES = 6000\nexport const HARD_MAX_BYTES = 20_000\n\nconst AXIS_JUSTIFY: Record<string, string> = {\n CENTER: 'center',\n MAX: 'end',\n SPACE_BETWEEN: 'space-between',\n SPACE_AROUND: 'space-around'\n}\n\nconst AXIS_ITEMS: Record<string, string> = {\n CENTER: 'center',\n MAX: 'end',\n STRETCH: 'stretch',\n BASELINE: 'baseline'\n}\n\n/** A length as CSS writes it: whole px where it is whole, up to two decimals otherwise. */\nfunction px(value: number): string {\n return `${Math.round(value * 100) / 100}px`\n}\n\n/**\n * The radius line, read the way `shape-details` reads corners: the per-corner fields while\n * `independentCorners` is set (the uniform field is stale then), four values in CSS order when\n * they differ, one otherwise. The four values write back through `set_radius`'s shorthand.\n */\nfunction radiusOf(node: SceneNode): string | null {\n if (node.independentCorners) {\n const corners = [\n node.topLeftRadius,\n node.topRightRadius,\n node.bottomRightRadius,\n node.bottomLeftRadius\n ]\n if (corners.every((value) => value === corners[0])) {\n return corners[0] > 0 ? px(corners[0]) : null\n }\n return corners.map((value) => (value === 0 ? '0' : px(value))).join(' ')\n }\n return node.cornerRadius > 0 ? px(node.cornerRadius) : null\n}\n\nfunction box(value: number): string {\n return String(Math.round(value))\n}\n\n/** UTF-8 bytes without a Node Buffer, so the tool runs in the app as well as headless. */\nfunction utf8Length(text: string): number {\n let bytes = 0\n for (let index = 0; index < text.length; index++) {\n const code = text.charCodeAt(index)\n if (code < 0x80) bytes += 1\n else if (code < 0x800) bytes += 2\n else if (code < 0xd800 || code >= 0xe000) bytes += 3\n else bytes += 4\n }\n return bytes\n}\n\nfunction boundName(graph: SceneGraph, node: SceneNode, field: string): string | null {\n const variableId = node.boundVariables[field]\n if (!variableId) return null\n return graph.variables.get(variableId)?.name ?? null\n}\n\n/**\n * A stored colour as the shorthand writes it: `#RRGGBB` in an sRGB document, `color(display-p3 …)`\n * in a Display P3 one, where hex would name a different colour, and `rgba()` or `color(… / a)` when\n * the paint is translucent. What paints is the colour's alpha times the paint's `opacity`, so both\n * are folded into the shorthand; the setters store that product the same way.\n */\nfunction cssColor(color: Color, opacity: number, profile: ColorProfile): string {\n return colorToDocumentCSS({ ...color, a: color.a * opacity }, profile)\n}\n\n/** A solid paint's colour and opacity, which the shorthand folds into one colour. */\ninterface SolidFill {\n color: Color\n opacity: number\n}\n\n/** The first visible solid fill and its index, which a text colour or a background can name. */\nfunction solidFill(node: SceneNode): { index: number; fill: SolidFill } | null {\n const index = node.fills.findIndex((candidate) => candidate.type === 'SOLID' && candidate.visible)\n const fill = index === -1 ? undefined : node.fills[index]\n return fill?.type === 'SOLID' ? { index, fill } : null\n}\n\n/** A colour in the document's profile, or `var(--token, …)` when a variable paints it. */\nfunction paintOf(node: SceneNode, graph: SceneGraph, field: string, paint: string): string {\n const name = boundName(graph, node, field)\n return name ? `var(--${name}, ${paint})` : paint\n}\n\nfunction background(node: SceneNode, graph: SceneGraph): string | null {\n const solid = solidFill(node)\n if (solid) {\n const paint = cssColor(solid.fill.color, solid.fill.opacity, graph.documentColorSpace)\n return paintOf(node, graph, `fills/${solid.index}/color`, paint)\n }\n const otherIndex = node.fills.findIndex((candidate) => candidate.visible)\n const other = otherIndex === -1 ? undefined : node.fills[otherIndex]\n if (!other) return null\n switch (other.type) {\n case 'GRADIENT_DIAMOND':\n // CSS has no diamond; the Pairdraw spelling carries the same stops so set_fill can close the\n // round trip instead of losing them behind a word.\n return diamondFillToCSS(other, graph.documentColorSpace) ?? 'gradient'\n case 'GRADIENT_LINEAR':\n case 'GRADIENT_RADIAL':\n case 'GRADIENT_ANGULAR':\n return (\n gradientFillToCSS(other, node.width, node.height, graph.documentColorSpace) ?? 'gradient'\n )\n case 'IMAGE':\n return `image(${other.imageScaleMode ?? 'FILL'})`\n default:\n // A paint CSS has neither a gradient nor an image for keeps the image word, as §3.3's table\n // says, rather than claiming a gradient it would not draw.\n return 'image'\n }\n}\n\nfunction border(node: SceneNode, graph: SceneGraph): string | null {\n const index = node.strokes.findIndex((candidate) => candidate.visible)\n const stroke = index === -1 ? undefined : node.strokes[index]\n if (!stroke) return null\n const paint = cssColor(stroke.color, stroke.opacity, graph.documentColorSpace)\n return `${px(stroke.weight)} ${paintOf(node, graph, `strokes/${index}/color`, paint)}`\n}\n\n/** Padding in CSS order, compressed to the fewest values that say the same thing. */\nfunction padding(node: SceneNode): string | null {\n const top = node.paddingTop\n const right = node.paddingRight\n const bottom = node.paddingBottom\n const left = node.paddingLeft\n if (top === 0 && right === 0 && bottom === 0 && left === 0) return null\n if (top === right && right === bottom && bottom === left) return px(top)\n if (top === bottom && right === left) return `${px(top)} ${px(right)}`\n return `${px(top)} ${px(right)} ${px(bottom)} ${px(left)}`\n}\n\nfunction shadowOf(prefix: string, effect: ShadowEffect, profile: ColorProfile): string {\n // A shadow's colour carries its whole alpha; the effect has no separate opacity.\n return `${prefix}:${px(effect.offset.x)} ${px(effect.offset.y)} ${px(effect.radius)} ${cssColor(effect.color, 1, profile)}`\n}\n\nfunction effects(node: SceneNode, profile: ColorProfile): string[] {\n const out: string[] = []\n for (const effect of node.effects) {\n if (!effect.visible) continue\n if (effect.type === 'DROP_SHADOW') out.push(shadowOf('shadow', effect, profile))\n else if (effect.type === 'INNER_SHADOW') out.push(shadowOf('inner-shadow', effect, profile))\n else if (effect.type === 'LAYER_BLUR' || effect.type === 'FOREGROUND_BLUR')\n out.push(`blur:${px(effect.radius)}`)\n else out.push('backdrop-blur')\n }\n return out\n}\n\nfunction layoutDecls(node: SceneNode): string[] {\n if (node.layoutMode === 'NONE') return []\n const out = [node.layoutMode === 'HORIZONTAL' ? 'flex:row' : 'flex:column']\n if (node.itemSpacing > 0) {\n out.push(\n node.layoutWrap === 'WRAP' && node.counterAxisSpacing > 0\n ? `gap:${px(node.itemSpacing)} ${px(node.counterAxisSpacing)}`\n : `gap:${px(node.itemSpacing)}`\n )\n }\n const paddingValue = padding(node)\n if (paddingValue) out.push(`padding:${paddingValue}`)\n const justify = AXIS_JUSTIFY[node.primaryAxisAlign]\n if (justify) out.push(`justify:${justify}`)\n const items = AXIS_ITEMS[node.counterAxisAlign]\n if (items) out.push(`items:${items}`)\n if (node.layoutWrap === 'WRAP') out.push('wrap')\n if (node.primaryAxisSizing === 'HUG') out.push('hug:main')\n if (node.counterAxisSizing === 'HUG') out.push('hug:cross')\n return out\n}\n\nfunction boxDecls(node: SceneNode, graph: SceneGraph): string[] {\n const out: string[] = []\n if (node.layoutAlignSelf === 'STRETCH') out.push('stretch')\n if (node.layoutGrow > 0) out.push(`grow:${Math.round(node.layoutGrow * 100) / 100}`)\n const bg = background(node, graph)\n if (bg) out.push(`bg:${bg}`)\n const stroke = border(node, graph)\n if (stroke) out.push(`border:${stroke}`)\n const radius = radiusOf(node)\n if (radius) out.push(`radius:${radius}`)\n if (node.minWidth !== null) out.push(`min-w:${px(node.minWidth)}`)\n if (node.maxWidth !== null) out.push(`max-w:${px(node.maxWidth)}`)\n if (node.minHeight !== null) out.push(`min-h:${px(node.minHeight)}`)\n if (node.maxHeight !== null) out.push(`max-h:${px(node.maxHeight)}`)\n out.push(...effects(node, graph.documentColorSpace))\n if (node.opacity !== 1) out.push(`opacity:${Math.round(node.opacity * 100) / 100}`)\n if (node.clipsContent) out.push('clip')\n return out\n}\n\nfunction lineHeightOf(node: SceneNode): string {\n const lineHeight = node.lineHeight\n if (!lineHeight) return 'auto'\n return lineHeight.unit === 'PERCENT'\n ? `${Math.round(lineHeight.value * 100) / 100}%`\n : px(lineHeight.value)\n}\n\nfunction textDecls(node: SceneNode, graph: SceneGraph): string[] {\n const out = [\n `font:${node.fontWeight} ${px(node.fontSize)}/${lineHeightOf(node)} ${node.fontFamily}`\n ]\n // `color:` takes a colour; a gradient or an image fill is not one, and no setter writes a text\n // paint, so text with such a fill prints no colour line at all.\n const bg = background(node, graph)\n if (bg && solidFill(node)) out.push(`color:${bg}`)\n if (node.textAlignHorizontal !== 'LEFT') {\n out.push(`text-align:${node.textAlignHorizontal.toLowerCase()}`)\n }\n if (node.maxLines !== null && node.maxLines > 0) out.push(`max-lines:${node.maxLines}`)\n if (node.textAutoResize === 'NONE') out.push('fixed')\n return out\n}\n\nfunction lineOf(node: SceneNode, graph: SceneGraph): string {\n const decls =\n node.type === 'TEXT' ? textDecls(node, graph) : [...layoutDecls(node), ...boxDecls(node, graph)]\n const label =\n node.type === 'TEXT'\n ? `\"${node.text.slice(0, 40).replaceAll('\\\\', '\\\\\\\\').replaceAll('\"', '\\\\\"').replaceAll('\\n', '\\\\n')}\"`\n : node.name\n const body = decls.length > 0 ? ` {${decls.join(';')}}` : ''\n return `${label}#${node.id} ${box(node.width)}×${box(node.height)}${body}`\n}\n\ninterface Budget {\n bytes: number\n limit: number\n truncated: boolean\n}\n\n/** What a cut-off walk left out, counted through the same visible-node rule as the lines. */\nfunction countVisible(graph: SceneGraph, nodeId: string): number {\n const node = graph.getNode(nodeId)\n if (!node || !node.visible) return 0\n let count = 1\n for (const childId of node.childIds) count += countVisible(graph, childId)\n return count\n}\n\nfunction truncationTail(omitted: number): string {\n return `… +${omitted} node${omitted === 1 ? '' : 's'} (raise max_bytes or narrow with depth)`\n}\n\n/**\n * Depth-first lines until the budget is spent. A line that does not fit ends the walk; the kept\n * lines never exceed the limit on their own, so the reply can always stay within `max_bytes`.\n */\nfunction collect(\n graph: SceneGraph,\n nodeId: string,\n depth: number,\n indent: string,\n lines: string[],\n budget: Budget\n): void {\n const node = graph.getNode(nodeId)\n if (!node || !node.visible) return\n if (budget.truncated) return\n const line = `${indent}${lineOf(node, graph)}`\n const fits = budget.bytes + utf8Length(line) + 1 <= budget.limit\n if (!fits) {\n budget.truncated = true\n return\n }\n budget.bytes += utf8Length(line) + 1\n lines.push(line)\n if (depth > 0) {\n for (const childId of node.childIds) {\n collect(graph, childId, depth - 1, `${indent} `, lines, budget)\n }\n }\n}\n\n/**\n * A subtree within `maxBytes`. The truncation tail is charged to the same budget: trailing lines\n * give way first, then the tail is left out when only the kept lines fit. A block whose first line\n * does not fit returns no CSS at all; the reply's `truncated`/`omitted` fields report the cut.\n */\nfunction blockFor(\n graph: SceneGraph,\n nodeId: string,\n depth: number,\n maxBytes: number\n): { css: string; truncated?: true; omitted?: number } {\n const lines: string[] = []\n const budget: Budget = { bytes: 0, limit: maxBytes, truncated: false }\n collect(graph, nodeId, depth, '', lines, budget)\n if (!budget.truncated) return { css: lines.join('\\n') }\n // Every visible node either has a line or is left out, so the omitted count follows from the\n // node total. Each dropped line's byte count includes the newline collect charged for it.\n let omitted = countVisible(graph, nodeId) - lines.length\n while (\n lines.length > 1 &&\n budget.bytes + 1 + utf8Length(truncationTail(omitted)) > budget.limit\n ) {\n const last = lines.pop()\n if (last === undefined) break\n budget.bytes -= utf8Length(last) + 1\n omitted = countVisible(graph, nodeId) - lines.length\n }\n if (lines.length === 0) {\n return { css: '', truncated: true, omitted: countVisible(graph, nodeId) }\n }\n const head = lines.join('\\n')\n if (budget.bytes + 1 + utf8Length(truncationTail(omitted)) > budget.limit) {\n return { css: head, truncated: true, omitted }\n }\n return { css: `${head}\\n${truncationTail(omitted)}`, truncated: true, omitted }\n}\n\nexport const getCSS = defineTool({\n name: 'get_css',\n description:\n 'Read a node subtree as compact CSS-like lines: `Name#id W×H {flex:row;gap:12px;padding:16px 24px;bg:var(--color/brand, #4F46E5);radius:8px}`. ' +\n 'Lengths are px; short names: flex (implies display:flex), gap, padding, justify, items, wrap, hug, stretch, grow, bg, border, radius, min/max-w/h, shadow, blur, opacity, clip; text: `font:600 14px/20px Inter`, color, text-align, max-lines. ' +\n \"Colours follow the document's profile, as get_jsx writes them: `#RRGGBB` in an sRGB document, `color(display-p3 r g b)` in a Display P3 one, and either inside the `var()` fallback. \" +\n 'Use it for geometry and style; describe gives roles and design issues. The setters accept the same shorthand (padding/gap/radius strings, `var(--token)` colours).',\n execution: { kind: 'sync', mutation: 'none' },\n input: v.strictObject({\n id: v.optional(v.pipe(v.string(), v.description('Node ID (single node)'))),\n ids: nodeIdsField('Node IDs (several nodes in one call)'),\n depth: v.optional(\n toolNumber(\n v.pipe(\n v.number(),\n v.description('Child levels to include (default: as many as the budget holds)')\n )\n )\n ),\n max_bytes: v.optional(\n toolNumber(\n v.pipe(v.number(), v.description('Byte budget for the reply (default 6000, max 20000)'))\n )\n )\n }),\n execute: (figma, args) => {\n const maxBytes = Math.min(args.max_bytes ?? DEFAULT_MAX_BYTES, HARD_MAX_BYTES)\n const depth = args.depth ?? 100\n\n if (args.ids && Array.isArray(args.ids)) {\n const blocks: string[] = []\n let omitted = 0\n let truncated = false\n let used = 0\n for (const nodeId of args.ids) {\n if (!figma.graph.getNode(nodeId)) return { error: `Node \"${nodeId}\" not found` }\n const separator = blocks.length === 0 ? 0 : 1\n const block = blockFor(figma.graph, nodeId, depth, maxBytes - used - separator)\n if (block.css === '') {\n omitted += block.omitted ?? 0\n truncated = truncated || block.truncated === true\n continue\n }\n blocks.push(block.css)\n used += utf8Length(block.css) + separator\n omitted += block.omitted ?? 0\n truncated = truncated || block.truncated === true\n }\n const css = blocks.join('\\n')\n if (!truncated) return { ids: args.ids, css }\n return { ids: args.ids, css, truncated: true, omitted }\n }\n\n if (!args.id) return { error: 'Provide id (string) or ids (string[])' }\n if (!figma.graph.getNode(args.id)) return { error: `Node \"${args.id}\" not found` }\n const block = blockFor(figma.graph, args.id, depth, maxBytes)\n return { id: args.id, ...block }\n }\n})\n"],"mappings":";;;;;;;;;;;AAeA,MAAa,oBAAoB;AACjC,MAAa,iBAAiB;AAE9B,MAAM,eAAuC;CAC3C,QAAQ;CACR,KAAK;CACL,eAAe;CACf,cAAc;AAChB;AAEA,MAAM,aAAqC;CACzC,QAAQ;CACR,KAAK;CACL,SAAS;CACT,UAAU;AACZ;;AAGA,SAAS,GAAG,OAAuB;CACjC,OAAO,GAAG,KAAK,MAAM,QAAQ,GAAG,IAAI,IAAI;AAC1C;;;;;;AAOA,SAAS,SAAS,MAAgC;CAChD,IAAI,KAAK,oBAAoB;EAC3B,MAAM,UAAU;GACd,KAAK;GACL,KAAK;GACL,KAAK;GACL,KAAK;EACP;EACA,IAAI,QAAQ,OAAO,UAAU,UAAU,QAAQ,EAAE,GAC/C,OAAO,QAAQ,KAAK,IAAI,GAAG,QAAQ,EAAE,IAAI;EAE3C,OAAO,QAAQ,KAAK,UAAW,UAAU,IAAI,MAAM,GAAG,KAAK,CAAE,CAAC,CAAC,KAAK,GAAG;CACzE;CACA,OAAO,KAAK,eAAe,IAAI,GAAG,KAAK,YAAY,IAAI;AACzD;AAEA,SAAS,IAAI,OAAuB;CAClC,OAAO,OAAO,KAAK,MAAM,KAAK,CAAC;AACjC;;AAGA,SAAS,WAAW,MAAsB;CACxC,IAAI,QAAQ;CACZ,KAAK,IAAI,QAAQ,GAAG,QAAQ,KAAK,QAAQ,SAAS;EAChD,MAAM,OAAO,KAAK,WAAW,KAAK;EAClC,IAAI,OAAO,KAAM,SAAS;OACrB,IAAI,OAAO,MAAO,SAAS;OAC3B,IAAI,OAAO,SAAU,QAAQ,OAAQ,SAAS;OAC9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AAS,KAAK,GAAG,aAAa;EACjF,MAAM,QAAQ,SAAS,MAAM,OAAO,KAAK,IAAI,OAAO,QAAQ;EAC5D,OAAO;GAAE,IAAI,KAAK;GAAI,GAAG;EAAM;CACjC;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";
@@ -1 +1 @@
1
- {"version":3,"file":"nodes.d.ts","names":[],"sources":["../../../src/tools/read/nodes.ts"],"mappings":";;cAqEa,aAAA;cAuDA,SAAA;cA4BA,WAAA"}
1
+ {"version":3,"file":"nodes.d.ts","names":[],"sources":["../../../src/tools/read/nodes.ts"],"mappings":";;cAqEa,aAAA;cAiEA,SAAA;cAwCA,WAAA"}
@@ -72,6 +72,15 @@ const getPageTree = defineTool({
72
72
  };
73
73
  }
74
74
  });
75
+ function withTextRuns(figma, id, result) {
76
+ const node = figma.graph.getNode(id);
77
+ if (node?.type !== "TEXT") return result;
78
+ return {
79
+ ...result,
80
+ styleRuns: node.styleRuns,
81
+ textParagraphs: node.textParagraphs
82
+ };
83
+ }
75
84
  const getNode = defineTool({
76
85
  name: "get_node",
77
86
  description: "Get detailed properties of a node by ID. Use depth to limit child recursion (0 = node only, 1 = direct children, etc). Default: unlimited.",
@@ -81,15 +90,20 @@ const getNode = defineTool({
81
90
  },
82
91
  input: v.strictObject({
83
92
  id: nodeIdInputSchema,
84
- depth: v.optional(toolNumber(v.pipe(v.number(), v.description("Max depth of children to include (0 = no children). Default: unlimited"))))
93
+ depth: v.optional(toolNumber(v.pipe(v.number(), v.description("Max depth of children to include (0 = no children). Default: unlimited")))),
94
+ include_text_runs: v.optional(v.pipe(v.boolean(), v.description("Include character style runs and paragraph styles, so mixed text can be read")))
85
95
  }),
86
- executeSync: (figma, { id, depth }) => {
96
+ executeSync: (figma, { id, depth, include_text_runs }) => {
87
97
  const node = figma.getNodeById(id);
88
- return node ? nodeToResult(node, depth) : void 0;
98
+ if (!node) return void 0;
99
+ const result = nodeToResult(node, depth);
100
+ return include_text_runs ? withTextRuns(figma, id, result) : result;
89
101
  },
90
- execute: async (figma, { id, depth }) => {
102
+ execute: async (figma, { id, depth, include_text_runs }) => {
91
103
  const loaded = figma.getNodeById(id) ?? await figma.getNodeByIdAsync(id);
92
- return loaded ? nodeToResult(loaded, depth) : { error: `Node "${id}" not found` };
104
+ if (!loaded) return { error: `Node "${id}" not found` };
105
+ const result = nodeToResult(loaded, depth);
106
+ return include_text_runs ? withTextRuns(figma, id, result) : result;
93
107
  }
94
108
  });
95
109
  const findNodes = defineTool({
@@ -1 +1 @@
1
- {"version":3,"file":"nodes.js","names":[],"sources":["../../../src/tools/read/nodes.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport type { FigmaAPI, FigmaNodeProxy } from '#core/figma-api'\nimport {\n toolNumber,\n nodeIdInputSchema,\n defineTool,\n nodeSummary,\n nodeToResult\n} from '#core/tools/schema'\n\ninterface TreeEntry {\n id: string\n type: string\n name: string\n w: number\n h: number\n text?: string\n children?: TreeEntry[]\n}\n\nfunction nodeToTreeEntry(\n node: FigmaNodeProxy,\n level: number,\n maxDepth?: number,\n typeFilter?: Set<string>\n): TreeEntry | null {\n const children: TreeEntry[] = []\n if ((maxDepth === undefined || level < maxDepth) && node.children.length > 0) {\n for (const child of node.children) {\n const entry = nodeToTreeEntry(child, level + 1, maxDepth, typeFilter)\n if (entry) children.push(entry)\n }\n }\n\n const matches = !typeFilter || typeFilter.has(node.type)\n if (!matches && children.length === 0) return null\n\n const entry: TreeEntry = {\n id: node.id,\n type: node.type,\n name: node.name,\n w: node.width,\n h: node.height\n }\n if (node.type === 'TEXT') entry.text = node.characters\n if (children.length > 0) entry.children = children\n return entry\n}\n\n/** The current page's tree; the answer that never needs a page load. */\nfunction currentPageTree(\n figma: FigmaAPI,\n depth: number | undefined,\n typeFilter: Set<string> | undefined\n) {\n const page = figma.currentPage\n const children: TreeEntry[] = []\n for (const child of page.children) {\n const entry = nodeToTreeEntry(child, 1, depth, typeFilter)\n if (entry) children.push(entry)\n }\n return { page: page.name, children }\n}\n\nfunction typeFilterOf(nodeTypes: readonly string[] | undefined): Set<string> | undefined {\n return nodeTypes && nodeTypes.length > 0 ? new Set(nodeTypes) : undefined\n}\n\nexport const getPageTree = defineTool({\n name: 'get_page_tree',\n description:\n 'Get the node tree of the current page. Returns lightweight hierarchy: id, type, name, size, and text for TEXT nodes. Use depth, root_id, or node_types to keep large pages small. Use get_node for full properties of a specific node.',\n execution: { kind: 'async', mutation: 'none' },\n input: v.strictObject({\n depth: v.optional(\n toolNumber(\n v.pipe(\n v.number(),\n v.minValue(1),\n v.description(\n 'Max nesting depth to return (1 = returned root nodes only). Default: unlimited'\n )\n )\n )\n ),\n root_id: v.optional(\n v.pipe(\n v.string(),\n v.description('Return only this node subtree instead of the whole current page')\n )\n ),\n node_types: v.optional(\n v.pipe(\n v.array(v.string()),\n v.minLength(1),\n v.description('Keep only these node types and their ancestors, for example FRAME or TEXT')\n )\n )\n }),\n executeSync: (figma, { depth, root_id, node_types }) => {\n const typeFilter = typeFilterOf(node_types)\n if (root_id !== undefined) {\n const root = figma.getNodeById(root_id)\n if (!root) return undefined\n // A page root exists before its layers load; only the async path can answer it.\n if (figma.graph.getNode(root.id)?.type === 'CANVAS') return undefined\n return { root: root.id, tree: nodeToTreeEntry(root, 1, depth, typeFilter) }\n }\n return currentPageTree(figma, depth, typeFilter)\n },\n execute: async (figma, { depth, root_id, node_types }) => {\n const typeFilter = typeFilterOf(node_types)\n if (root_id === undefined) return currentPageTree(figma, depth, typeFilter)\n const root = figma.getNodeById(root_id)\n // A layer on a page not yet visited loads that page, as in Figma's dynamic-page mode.\n const loaded = root ?? (await figma.getNodeByIdAsync(root_id))\n if (!loaded) return { error: `Node \"${root_id}\" not found` }\n // A page root exists before its layers load; read them first.\n if (figma.graph.getNode(loaded.id)?.type === 'CANVAS') await loaded.loadAsync()\n return { root: loaded.id, tree: nodeToTreeEntry(loaded, 1, depth, typeFilter) }\n }\n})\n\nexport const getNode = defineTool({\n name: 'get_node',\n description:\n 'Get detailed properties of a node by ID. Use depth to limit child recursion (0 = node only, 1 = direct children, etc). Default: unlimited.',\n execution: { kind: 'async', mutation: 'none' },\n input: v.strictObject({\n id: nodeIdInputSchema,\n depth: v.optional(\n toolNumber(\n v.pipe(\n v.number(),\n v.description('Max depth of children to include (0 = no children). Default: unlimited')\n )\n )\n )\n }),\n executeSync: (figma, { id, depth }) => {\n const node = figma.getNodeById(id)\n return node ? nodeToResult(node, depth) : undefined\n },\n execute: async (figma, { id, depth }) => {\n const node = figma.getNodeById(id)\n // A layer on a page not yet visited loads that page, as in Figma's dynamic-page mode.\n const loaded = node ?? (await figma.getNodeByIdAsync(id))\n return loaded ? nodeToResult(loaded, depth) : { error: `Node \"${id}\" not found` }\n }\n})\n\nexport const findNodes = defineTool({\n name: 'find_nodes',\n description: 'Find nodes by name pattern and/or type.',\n execution: { kind: 'sync', mutation: 'none' },\n input: v.strictObject({\n name: v.optional(\n v.pipe(v.string(), v.description('Name substring to match (case-insensitive)'))\n ),\n type: v.optional(\n v.pipe(\n v.picklist([\n 'FRAME',\n 'RECTANGLE',\n 'ELLIPSE',\n 'TEXT',\n 'LINE',\n 'STAR',\n 'POLYGON',\n 'SECTION',\n 'GROUP',\n 'COMPONENT',\n 'INSTANCE',\n 'VECTOR'\n ]),\n v.description('Node type filter')\n )\n )\n }),\n execute: (figma, args) => {\n const page = figma.currentPage\n const matches = page.findAll((node) => {\n if (args.type && node.type !== args.type) return false\n if (args.name && !node.name.toLowerCase().includes(args.name.toLowerCase())) return false\n return true\n })\n return { count: matches.length, nodes: matches.map(nodeSummary) }\n }\n})\n"],"mappings":";;;AAqBA,SAAS,gBACP,MACA,OACA,UACA,YACkB;CAClB,MAAM,WAAwB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O,OAAO,aAAa,MAAM,KAAK,IAAI,KAAA;CAC5C;CACA,SAAS,OAAO,OAAO,EAAE,IAAI,YAAY;EAGvC,MAAM,SAFO,MAAM,YAAY,EAEb,KAAM,MAAM,MAAM,iBAAiB,EAAE;EACvD,OAAO,SAAS,aAAa,QAAQ,KAAK,IAAI,EAAE,OAAO,SAAS,GAAG,aAAa;CAClF;AACF,CAAC;AAED,MAAa,YAAY,WAAW;CAClC,MAAM;CACN,aAAa;CACb,WAAW;EAAE,MAAM;EAAQ,UAAU;CAAO;CAC5C,OAAO,EAAE,aAAa;EACpB,MAAM,EAAE,SACN,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,YAAY,4CAA4C,CAAC,CAChF;EACA,MAAM,EAAE,SACN,EAAE,KACA,EAAE,SAAS;GACT;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACF,CAAC,GACD,EAAE,YAAY,kBAAkB,CAClC,CACF;CACF,CAAC;CACD,UAAU,OAAO,SAAS;EAExB,MAAM,UADO,MAAM,YACE,SAAS,SAAS;GACrC,IAAI,KAAK,QAAQ,KAAK,SAAS,KAAK,MAAM,OAAO;GACjD,IAAI,KAAK,QAAQ,CAAC,KAAK,KAAK,YAAY,CAAC,CAAC,SAAS,KAAK,KAAK,YAAY,CAAC,GAAG,OAAO;GACpF,OAAO;EACT,CAAC;EACD,OAAO;GAAE,OAAO,QAAQ;GAAQ,OAAO,QAAQ,IAAI,WAAW;EAAE;CAClE;AACF,CAAC"}
1
+ {"version":3,"file":"nodes.js","names":[],"sources":["../../../src/tools/read/nodes.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport type { FigmaAPI, FigmaNodeProxy } from '#core/figma-api'\nimport {\n toolNumber,\n nodeIdInputSchema,\n defineTool,\n nodeSummary,\n nodeToResult\n} from '#core/tools/schema'\n\ninterface TreeEntry {\n id: string\n type: string\n name: string\n w: number\n h: number\n text?: string\n children?: TreeEntry[]\n}\n\nfunction nodeToTreeEntry(\n node: FigmaNodeProxy,\n level: number,\n maxDepth?: number,\n typeFilter?: Set<string>\n): TreeEntry | null {\n const children: TreeEntry[] = []\n if ((maxDepth === undefined || level < maxDepth) && node.children.length > 0) {\n for (const child of node.children) {\n const entry = nodeToTreeEntry(child, level + 1, maxDepth, typeFilter)\n if (entry) children.push(entry)\n }\n }\n\n const matches = !typeFilter || typeFilter.has(node.type)\n if (!matches && children.length === 0) return null\n\n const entry: TreeEntry = {\n id: node.id,\n type: node.type,\n name: node.name,\n w: node.width,\n h: node.height\n }\n if (node.type === 'TEXT') entry.text = node.characters\n if (children.length > 0) entry.children = children\n return entry\n}\n\n/** The current page's tree; the answer that never needs a page load. */\nfunction currentPageTree(\n figma: FigmaAPI,\n depth: number | undefined,\n typeFilter: Set<string> | undefined\n) {\n const page = figma.currentPage\n const children: TreeEntry[] = []\n for (const child of page.children) {\n const entry = nodeToTreeEntry(child, 1, depth, typeFilter)\n if (entry) children.push(entry)\n }\n return { page: page.name, children }\n}\n\nfunction typeFilterOf(nodeTypes: readonly string[] | undefined): Set<string> | undefined {\n return nodeTypes && nodeTypes.length > 0 ? new Set(nodeTypes) : undefined\n}\n\nexport const getPageTree = defineTool({\n name: 'get_page_tree',\n description:\n 'Get the node tree of the current page. Returns lightweight hierarchy: id, type, name, size, and text for TEXT nodes. Use depth, root_id, or node_types to keep large pages small. Use get_node for full properties of a specific node.',\n execution: { kind: 'async', mutation: 'none' },\n input: v.strictObject({\n depth: v.optional(\n toolNumber(\n v.pipe(\n v.number(),\n v.minValue(1),\n v.description(\n 'Max nesting depth to return (1 = returned root nodes only). Default: unlimited'\n )\n )\n )\n ),\n root_id: v.optional(\n v.pipe(\n v.string(),\n v.description('Return only this node subtree instead of the whole current page')\n )\n ),\n node_types: v.optional(\n v.pipe(\n v.array(v.string()),\n v.minLength(1),\n v.description('Keep only these node types and their ancestors, for example FRAME or TEXT')\n )\n )\n }),\n executeSync: (figma, { depth, root_id, node_types }) => {\n const typeFilter = typeFilterOf(node_types)\n if (root_id !== undefined) {\n const root = figma.getNodeById(root_id)\n if (!root) return undefined\n // A page root exists before its layers load; only the async path can answer it.\n if (figma.graph.getNode(root.id)?.type === 'CANVAS') return undefined\n return { root: root.id, tree: nodeToTreeEntry(root, 1, depth, typeFilter) }\n }\n return currentPageTree(figma, depth, typeFilter)\n },\n execute: async (figma, { depth, root_id, node_types }) => {\n const typeFilter = typeFilterOf(node_types)\n if (root_id === undefined) return currentPageTree(figma, depth, typeFilter)\n const root = figma.getNodeById(root_id)\n // A layer on a page not yet visited loads that page, as in Figma's dynamic-page mode.\n const loaded = root ?? (await figma.getNodeByIdAsync(root_id))\n if (!loaded) return { error: `Node \"${root_id}\" not found` }\n // A page root exists before its layers load; read them first.\n if (figma.graph.getNode(loaded.id)?.type === 'CANVAS') await loaded.loadAsync()\n return { root: loaded.id, tree: nodeToTreeEntry(loaded, 1, depth, typeFilter) }\n }\n})\n\nfunction withTextRuns(\n figma: FigmaAPI,\n id: string,\n result: Record<string, unknown>\n): Record<string, unknown> {\n const node = figma.graph.getNode(id)\n if (node?.type !== 'TEXT') return result\n return { ...result, styleRuns: node.styleRuns, textParagraphs: node.textParagraphs }\n}\n\nexport const getNode = defineTool({\n name: 'get_node',\n description:\n 'Get detailed properties of a node by ID. Use depth to limit child recursion (0 = node only, 1 = direct children, etc). Default: unlimited.',\n execution: { kind: 'async', mutation: 'none' },\n input: v.strictObject({\n id: nodeIdInputSchema,\n depth: v.optional(\n toolNumber(\n v.pipe(\n v.number(),\n v.description('Max depth of children to include (0 = no children). Default: unlimited')\n )\n )\n ),\n include_text_runs: v.optional(\n v.pipe(\n v.boolean(),\n v.description(\n 'Include character style runs and paragraph styles, so mixed text can be read'\n )\n )\n )\n }),\n executeSync: (figma, { id, depth, include_text_runs }) => {\n const node = figma.getNodeById(id)\n if (!node) return undefined\n const result = nodeToResult(node, depth)\n return include_text_runs ? withTextRuns(figma, id, result) : result\n },\n execute: async (figma, { id, depth, include_text_runs }) => {\n const node = figma.getNodeById(id)\n // A layer on a page not yet visited loads that page, as in Figma's dynamic-page mode.\n const loaded = node ?? (await figma.getNodeByIdAsync(id))\n if (!loaded) return { error: `Node \"${id}\" not found` }\n const result = nodeToResult(loaded, depth)\n return include_text_runs ? withTextRuns(figma, id, result) : result\n }\n})\n\nexport const findNodes = defineTool({\n name: 'find_nodes',\n description: 'Find nodes by name pattern and/or type.',\n execution: { kind: 'sync', mutation: 'none' },\n input: v.strictObject({\n name: v.optional(\n v.pipe(v.string(), v.description('Name substring to match (case-insensitive)'))\n ),\n type: v.optional(\n v.pipe(\n v.picklist([\n 'FRAME',\n 'RECTANGLE',\n 'ELLIPSE',\n 'TEXT',\n 'LINE',\n 'STAR',\n 'POLYGON',\n 'SECTION',\n 'GROUP',\n 'COMPONENT',\n 'INSTANCE',\n 'VECTOR'\n ]),\n v.description('Node type filter')\n )\n )\n }),\n execute: (figma, args) => {\n const page = figma.currentPage\n const matches = page.findAll((node) => {\n if (args.type && node.type !== args.type) return false\n if (args.name && !node.name.toLowerCase().includes(args.name.toLowerCase())) return false\n return true\n })\n return { count: matches.length, nodes: matches.map(nodeSummary) }\n }\n})\n"],"mappings":";;;AAqBA,SAAS,gBACP,MACA,OACA,UACA,YACkB;CAClB,MAAM,WAAwB,CAAC;CAC/B,KAAK,aAAa,KAAA,KAAa,QAAQ,aAAa,KAAK,SAAS,SAAS,GACzE,KAAK,MAAM,SAAS,KAAK,UAAU;EACjC,MAAM,QAAQ,gBAAgB,OAAO,QAAQ,GAAG,UAAU,UAAU;EACpE,IAAI,OAAO,SAAS,KAAK,KAAK;CAChC;CAIF,IAAI,EADY,CAAC,cAAc,WAAW,IAAI,KAAK,IAAI,MACvC,SAAS,WAAW,GAAG,OAAO;CAE9C,MAAM,QAAmB;EACvB,IAAI,KAAK;EACT,MAAM,KAAK;EACX,MAAM,KAAK;EACX,GAAG,KAAK;EACR,GAAG,KAAK;CACV;CACA,IAAI,KAAK,SAAS,QAAQ,MAAM,OAAO,KAAK;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AG1D,MAAM,SAFO,MAAM,YAAY,EAEb,KAAM,MAAM,MAAM,iBAAiB,EAAE;EACvD,IAAI,CAAC,QAAQ,OAAO,EAAE,OAAO,SAAS,GAAG,aAAa;EACtD,MAAM,SAAS,aAAa,QAAQ,KAAK;EACzC,OAAO,oBAAoB,aAAa,OAAO,IAAI,MAAM,IAAI;CAC/D;AACF,CAAC;AAED,MAAa,YAAY,WAAW;CAClC,MAAM;CACN,aAAa;CACb,WAAW;EAAE,MAAM;EAAQ,UAAU;CAAO;CAC5C,OAAO,EAAE,aAAa;EACpB,MAAM,EAAE,SACN,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,YAAY,4CAA4C,CAAC,CAChF;EACA,MAAM,EAAE,SACN,EAAE,KACA,EAAE,SAAS;GACT;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACF,CAAC,GACD,EAAE,YAAY,kBAAkB,CAClC,CACF;CACF,CAAC;CACD,UAAU,OAAO,SAAS;EAExB,MAAM,UADO,MAAM,YACE,SAAS,SAAS;GACrC,IAAI,KAAK,QAAQ,KAAK,SAAS,KAAK,MAAM,OAAO;GACjD,IAAI,KAAK,QAAQ,CAAC,KAAK,KAAK,YAAY,CAAC,CAAC,SAAS,KAAK,KAAK,YAAY,CAAC,GAAG,OAAO;GACpF,OAAO;EACT,CAAC;EACD,OAAO;GAAE,OAAO,QAAQ;GAAQ,OAAO,QAAQ,IAAI,WAAW;EAAE;CAClE;AACF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"extended.d.ts","names":[],"sources":["../../../src/tools/registry/extended.ts"],"mappings":";;;;;;cAoJa,gBAAgB"}
1
+ {"version":3,"file":"extended.d.ts","names":[],"sources":["../../../src/tools/registry/extended.ts"],"mappings":";;;;;;cAuJa,gBAAgB"}
@@ -19,6 +19,7 @@ import { script } from "../create/script.js";
19
19
  import { importMermaid } from "../create/mermaid.js";
20
20
  import { importSVG } from "../create/svg.js";
21
21
  import { importHTML } from "../create/html.js";
22
+ import { importCode } from "../create/code.js";
22
23
  import { createVector } from "../create/vector.js";
23
24
  import { createConnectorTool } from "../create/connector.js";
24
25
  import { checkDesignValuesTool, getDesignMemory, recordDesignDecisionTool } from "../design-memory.js";
@@ -28,8 +29,9 @@ import { setEffects } from "../modify/effects.js";
28
29
  import { replaceFonts } from "../modify/fonts.js";
29
30
  import { rescale, setMinMax, setOpacity, setRotation } from "../modify/geometry.js";
30
31
  import { setConstraints } from "../modify/layout.js";
31
- import { setFont, setFontRange, setTextResize } from "../modify/text.js";
32
+ import { setFont, setFontRange, setTextRangeStyle, setTextResize } from "../modify/text.js";
32
33
  import { replaceMatchingProperties } from "../modify/matching.js";
34
+ import { resetOverrideFields } from "../modify/overrides.js";
33
35
  import { setImageFill } from "../modify/paint.js";
34
36
  import { setReactions } from "../modify/reactions.js";
35
37
  import { setBlend, setLocked, setStrokeAlign, setVisible } from "../modify/state.js";
@@ -98,6 +100,7 @@ const EXTENDED_TOOLS = [
98
100
  createComponent,
99
101
  createInstance,
100
102
  detachInstance,
103
+ resetOverrideFields,
101
104
  exposeInstanceSwap,
102
105
  createSlot,
103
106
  getBehaviour,
@@ -108,6 +111,7 @@ const EXTENDED_TOOLS = [
108
111
  createConnectorTool,
109
112
  importSVG,
110
113
  importMermaid,
114
+ importCode,
111
115
  importHTML,
112
116
  generateImage,
113
117
  generateSVG,
@@ -122,6 +126,7 @@ const EXTENDED_TOOLS = [
122
126
  setRotation,
123
127
  setMinMax,
124
128
  setFontRange,
129
+ setTextRangeStyle,
125
130
  setTextResize,
126
131
  replaceFonts,
127
132
  setBlend,
@@ -1 +1 @@
1
- {"version":3,"file":"extended.js","names":[],"sources":["../../../src/tools/registry/extended.ts"],"sourcesContent":["import {\n analyzeClusters,\n analyzeColors,\n analyzeOverlaps,\n analyzeSpacing,\n analyzeTypography,\n diffApply,\n diffShow,\n lint,\n lintFix\n} from '#core/tools/analyze'\nimport {\n designToComponentMap,\n designToTokens,\n importDesignTokens,\n syncTokens,\n tokenDrift\n} from '#core/tools/codegen'\nimport { addComment, getComments, replyToComment, resolveComment } from '#core/tools/comments'\nimport {\n createComponent,\n createInstance,\n createPage,\n createConnectorTool,\n createShape,\n createSlice,\n createVector,\n detachInstance,\n exposeInstanceSwap,\n combineAsVariants,\n createSlot,\n fetchIconsTool,\n getBehaviour,\n importHTML,\n importMermaid,\n importSVG,\n insertIcon,\n script,\n searchIconsTool,\n setBehaviour\n} from '#core/tools/create'\nimport {\n checkDesignValuesTool,\n getDesignMemory,\n recordDesignDecisionTool\n} from '#core/tools/design-memory'\nimport {\n generateImage,\n generateSVG,\n removeBackground,\n replaceBackground\n} from '#core/tools/image-ai'\nimport {\n replaceFonts,\n setBlend,\n setConstraints,\n setEffects,\n setFont,\n setFontRange,\n setImageFill,\n setLocked,\n setMinMax,\n replaceMatchingProperties,\n rescale,\n setOpacity,\n setReactions,\n setRotation,\n setStrokeAlign,\n setTextResize,\n setVisible\n} from '#core/tools/modify'\nimport {\n findEmptySpaceTool,\n getComponents,\n getCurrentPage,\n getFontStatus,\n getPageTree,\n getReactions,\n insertLibraryComponent,\n listAvailableFonts,\n listFonts,\n listLibraries,\n listPages,\n pageBounds,\n queryNodes,\n selectNodes,\n switchPage\n} from '#core/tools/read'\nimport type { ToolDef } from '#core/tools/schema'\nimport { getStatuses, setStatus } from '#core/tools/statuses'\nimport {\n arrangeNodes,\n cloneNode,\n createVariationsTool,\n flattenNodes,\n groupNodes,\n listVariations,\n nodeAncestors,\n nodeBindings,\n nodeBounds,\n nodeChildren,\n nodeMove,\n nodeReplaceWith,\n nodeToComponent,\n nodeTree,\n pickVariation,\n renameNode,\n ungroupNode\n} from '#core/tools/structure'\nimport { getStyle } from '#core/tools/styles'\nimport {\n bindVariable,\n createCollection,\n createVariable,\n deleteCollection,\n deleteVariable,\n findVariables,\n getCollection,\n getVariable,\n listCollections,\n listVariables,\n setVariable,\n unbindVariable\n} from '#core/tools/variables'\nimport {\n booleanExclude,\n booleanIntersect,\n booleanSubtract,\n booleanUnion,\n exportHTML,\n exportImage,\n exportPDF,\n exportSVG,\n exportVideo,\n pathFlip,\n pathGet,\n pathMove,\n pathScale,\n pathSet,\n vectorizeImage,\n viewportGet,\n viewportSet\n} from '#core/tools/vector'\n\n/**\n * Extended tools not in CORE_TOOLS — variables, vector ops, analysis,\n * codegen, advanced structure, path manipulation, etc.\n */\nexport const EXTENDED_TOOLS: ToolDef[] = [\n // Read (advanced)\n getPageTree,\n getReactions,\n getCurrentPage,\n listPages,\n selectNodes,\n queryNodes,\n getComponents,\n listLibraries,\n insertLibraryComponent,\n switchPage,\n pageBounds,\n findEmptySpaceTool,\n getComments,\n addComment,\n replyToComment,\n resolveComment,\n getStatuses,\n setStatus,\n getDesignMemory,\n checkDesignValuesTool,\n recordDesignDecisionTool,\n getFontStatus,\n listFonts,\n listAvailableFonts,\n // Style directions\n getStyle,\n // Create (advanced)\n createShape,\n searchIconsTool,\n insertIcon,\n fetchIconsTool,\n combineAsVariants,\n createComponent,\n createInstance,\n detachInstance,\n exposeInstanceSwap,\n createSlot,\n getBehaviour,\n setBehaviour,\n createPage,\n createVector,\n createSlice,\n createConnectorTool,\n importSVG,\n importMermaid,\n importHTML,\n // Image AI, run on the services the user set up in the app\n generateImage,\n generateSVG,\n removeBackground,\n replaceBackground,\n // Modify (advanced)\n setEffects,\n setReactions,\n setOpacity,\n setFont,\n setVisible,\n setConstraints,\n setRotation,\n setMinMax,\n setFontRange,\n setTextResize,\n replaceFonts,\n setBlend,\n setLocked,\n setStrokeAlign,\n setImageFill,\n replaceMatchingProperties,\n rescale,\n // Structure (advanced)\n cloneNode,\n nodeMove,\n renameNode,\n groupNodes,\n ungroupNode,\n flattenNodes,\n nodeToComponent,\n nodeBounds,\n nodeAncestors,\n nodeChildren,\n nodeTree,\n nodeBindings,\n nodeReplaceWith,\n arrangeNodes,\n // Variations: versions of a layer side by side, one of which can replace it\n createVariationsTool,\n listVariations,\n pickVariation,\n // Variables\n listVariables,\n listCollections,\n getVariable,\n findVariables,\n createVariable,\n setVariable,\n deleteVariable,\n bindVariable,\n unbindVariable,\n getCollection,\n createCollection,\n deleteCollection,\n // Vector & export\n booleanUnion,\n booleanSubtract,\n booleanIntersect,\n booleanExclude,\n pathGet,\n pathSet,\n pathScale,\n pathFlip,\n pathMove,\n vectorizeImage,\n viewportGet,\n viewportSet,\n exportSVG,\n exportPDF,\n exportImage,\n exportVideo,\n exportHTML,\n // Analyze & diff\n analyzeColors,\n analyzeTypography,\n lint,\n lintFix,\n analyzeSpacing,\n analyzeClusters,\n analyzeOverlaps,\n diffShow,\n diffApply,\n // Code on canvas\n script,\n // Codegen\n designToTokens,\n importDesignTokens,\n tokenDrift,\n syncTokens,\n designToComponentMap\n]\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoJA,MAAa,iBAA4B;CAEvC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CAEA;CACA;CACA;CACA;CACA;AACF"}
1
+ {"version":3,"file":"extended.js","names":[],"sources":["../../../src/tools/registry/extended.ts"],"sourcesContent":["import {\n analyzeClusters,\n analyzeColors,\n analyzeOverlaps,\n analyzeSpacing,\n analyzeTypography,\n diffApply,\n diffShow,\n lint,\n lintFix\n} from '#core/tools/analyze'\nimport {\n designToComponentMap,\n designToTokens,\n importDesignTokens,\n syncTokens,\n tokenDrift\n} from '#core/tools/codegen'\nimport { addComment, getComments, replyToComment, resolveComment } from '#core/tools/comments'\nimport {\n createComponent,\n createInstance,\n createPage,\n createConnectorTool,\n createShape,\n createSlice,\n createVector,\n detachInstance,\n exposeInstanceSwap,\n combineAsVariants,\n createSlot,\n fetchIconsTool,\n getBehaviour,\n importCode,\n importHTML,\n importMermaid,\n importSVG,\n insertIcon,\n script,\n searchIconsTool,\n setBehaviour\n} from '#core/tools/create'\nimport {\n checkDesignValuesTool,\n getDesignMemory,\n recordDesignDecisionTool\n} from '#core/tools/design-memory'\nimport {\n generateImage,\n generateSVG,\n removeBackground,\n replaceBackground\n} from '#core/tools/image-ai'\nimport {\n replaceFonts,\n setBlend,\n setConstraints,\n setEffects,\n setFont,\n setFontRange,\n setTextRangeStyle,\n setImageFill,\n setLocked,\n resetOverrideFields,\n setMinMax,\n replaceMatchingProperties,\n rescale,\n setOpacity,\n setReactions,\n setRotation,\n setStrokeAlign,\n setTextResize,\n setVisible\n} from '#core/tools/modify'\nimport {\n findEmptySpaceTool,\n getComponents,\n getCurrentPage,\n getFontStatus,\n getPageTree,\n getReactions,\n insertLibraryComponent,\n listAvailableFonts,\n listFonts,\n listLibraries,\n listPages,\n pageBounds,\n queryNodes,\n selectNodes,\n switchPage\n} from '#core/tools/read'\nimport type { ToolDef } from '#core/tools/schema'\nimport { getStatuses, setStatus } from '#core/tools/statuses'\nimport {\n arrangeNodes,\n cloneNode,\n createVariationsTool,\n flattenNodes,\n groupNodes,\n listVariations,\n nodeAncestors,\n nodeBindings,\n nodeBounds,\n nodeChildren,\n nodeMove,\n nodeReplaceWith,\n nodeToComponent,\n nodeTree,\n pickVariation,\n renameNode,\n ungroupNode\n} from '#core/tools/structure'\nimport { getStyle } from '#core/tools/styles'\nimport {\n bindVariable,\n createCollection,\n createVariable,\n deleteCollection,\n deleteVariable,\n findVariables,\n getCollection,\n getVariable,\n listCollections,\n listVariables,\n setVariable,\n unbindVariable\n} from '#core/tools/variables'\nimport {\n booleanExclude,\n booleanIntersect,\n booleanSubtract,\n booleanUnion,\n exportHTML,\n exportImage,\n exportPDF,\n exportSVG,\n exportVideo,\n pathFlip,\n pathGet,\n pathMove,\n pathScale,\n pathSet,\n vectorizeImage,\n viewportGet,\n viewportSet\n} from '#core/tools/vector'\n\n/**\n * Extended tools not in CORE_TOOLS — variables, vector ops, analysis,\n * codegen, advanced structure, path manipulation, etc.\n */\nexport const EXTENDED_TOOLS: ToolDef[] = [\n // Read (advanced)\n getPageTree,\n getReactions,\n getCurrentPage,\n listPages,\n selectNodes,\n queryNodes,\n getComponents,\n listLibraries,\n insertLibraryComponent,\n switchPage,\n pageBounds,\n findEmptySpaceTool,\n getComments,\n addComment,\n replyToComment,\n resolveComment,\n getStatuses,\n setStatus,\n getDesignMemory,\n checkDesignValuesTool,\n recordDesignDecisionTool,\n getFontStatus,\n listFonts,\n listAvailableFonts,\n // Style directions\n getStyle,\n // Create (advanced)\n createShape,\n searchIconsTool,\n insertIcon,\n fetchIconsTool,\n combineAsVariants,\n createComponent,\n createInstance,\n detachInstance,\n resetOverrideFields,\n exposeInstanceSwap,\n createSlot,\n getBehaviour,\n setBehaviour,\n createPage,\n createVector,\n createSlice,\n createConnectorTool,\n importSVG,\n importMermaid,\n importCode,\n importHTML,\n // Image AI, run on the services the user set up in the app\n generateImage,\n generateSVG,\n removeBackground,\n replaceBackground,\n // Modify (advanced)\n setEffects,\n setReactions,\n setOpacity,\n setFont,\n setVisible,\n setConstraints,\n setRotation,\n setMinMax,\n setFontRange,\n setTextRangeStyle,\n setTextResize,\n replaceFonts,\n setBlend,\n setLocked,\n setStrokeAlign,\n setImageFill,\n replaceMatchingProperties,\n rescale,\n // Structure (advanced)\n cloneNode,\n nodeMove,\n renameNode,\n groupNodes,\n ungroupNode,\n flattenNodes,\n nodeToComponent,\n nodeBounds,\n nodeAncestors,\n nodeChildren,\n nodeTree,\n nodeBindings,\n nodeReplaceWith,\n arrangeNodes,\n // Variations: versions of a layer side by side, one of which can replace it\n createVariationsTool,\n listVariations,\n pickVariation,\n // Variables\n listVariables,\n listCollections,\n getVariable,\n findVariables,\n createVariable,\n setVariable,\n deleteVariable,\n bindVariable,\n unbindVariable,\n getCollection,\n createCollection,\n deleteCollection,\n // Vector & export\n booleanUnion,\n booleanSubtract,\n booleanIntersect,\n booleanExclude,\n pathGet,\n pathSet,\n pathScale,\n pathFlip,\n pathMove,\n vectorizeImage,\n viewportGet,\n viewportSet,\n exportSVG,\n exportPDF,\n exportImage,\n exportVideo,\n exportHTML,\n // Analyze & diff\n analyzeColors,\n analyzeTypography,\n lint,\n lintFix,\n analyzeSpacing,\n analyzeClusters,\n analyzeOverlaps,\n diffShow,\n diffApply,\n // Code on canvas\n script,\n // Codegen\n designToTokens,\n importDesignTokens,\n tokenDrift,\n syncTokens,\n designToComponentMap\n]\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuJA,MAAa,iBAA4B;CAEvC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CAEA;CACA;CACA;CACA;CACA;AACF"}
@@ -0,0 +1,11 @@
1
+ //#region src/tools/text-range.d.ts
2
+ /**
3
+ * Why `start..end` is not a range a person could select, or null. Indices are UTF-16 code units,
4
+ * and an edge inside one user-perceived character (a surrogate pair, a join emoji, a combining
5
+ * mark) is refused rather than snapped, so a caller learns the index to use; the message names the
6
+ * character's own edges.
7
+ */
8
+ declare function textRangeError(text: string, start: number, end: number): string | null;
9
+ //#endregion
10
+ export { textRangeError };
11
+ //# sourceMappingURL=text-range.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-range.d.ts","names":[],"sources":["../../src/tools/text-range.ts"],"mappings":";;;;;;;iBAQgB,eAAe,cAAc,eAAe"}
@@ -0,0 +1,26 @@
1
+ import { nextGraphemeBoundary, previousGraphemeBoundary } from "../text/graphemes.js";
2
+ //#region src/tools/text-range.ts
3
+ /**
4
+ * Why `start..end` is not a range a person could select, or null. Indices are UTF-16 code units,
5
+ * and an edge inside one user-perceived character (a surrogate pair, a join emoji, a combining
6
+ * mark) is refused rather than snapped, so a caller learns the index to use; the message names the
7
+ * character's own edges.
8
+ */
9
+ function textRangeError(text, start, end) {
10
+ if (!Number.isInteger(start) || !Number.isInteger(end)) return `start and end must be whole UTF-16 indices (got ${start} and ${end})`;
11
+ if (start < 0) return "start must not be negative";
12
+ if (start >= end) return "start must be before end";
13
+ if (end > text.length) return `end ${end} is past the text's ${text.length} characters`;
14
+ for (const [label, index] of [["start", start], ["end", end]]) {
15
+ if (index === 0 || index === text.length) continue;
16
+ if (nextGraphemeBoundary(text, index - 1) === index) continue;
17
+ const before = previousGraphemeBoundary(text, index);
18
+ const after = nextGraphemeBoundary(text, index - 1);
19
+ return `${label} ${index} is inside the character from ${before} to ${after}; use ${before} or ${after}`;
20
+ }
21
+ return null;
22
+ }
23
+ //#endregion
24
+ export { textRangeError };
25
+
26
+ //# sourceMappingURL=text-range.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-range.js","names":[],"sources":["../../src/tools/text-range.ts"],"sourcesContent":["import { nextGraphemeBoundary, previousGraphemeBoundary } from '#core/text/graphemes'\n\n/**\n * Why `start..end` is not a range a person could select, or null. Indices are UTF-16 code units,\n * and an edge inside one user-perceived character (a surrogate pair, a join emoji, a combining\n * mark) is refused rather than snapped, so a caller learns the index to use; the message names the\n * character's own edges.\n */\nexport function textRangeError(text: string, start: number, end: number): string | null {\n if (!Number.isInteger(start) || !Number.isInteger(end)) {\n return `start and end must be whole UTF-16 indices (got ${start} and ${end})`\n }\n if (start < 0) return 'start must not be negative'\n if (start >= end) return 'start must be before end'\n if (end > text.length) {\n return `end ${end} is past the text's ${text.length} characters`\n }\n for (const [label, index] of [\n ['start', start],\n ['end', end]\n ] as const) {\n if (index === 0 || index === text.length) continue\n if (nextGraphemeBoundary(text, index - 1) === index) continue\n const before = previousGraphemeBoundary(text, index)\n const after = nextGraphemeBoundary(text, index - 1)\n return `${label} ${index} is inside the character from ${before} to ${after}; use ${before} or ${after}`\n }\n return null\n}\n"],"mappings":";;;;;;;;AAQA,SAAgB,eAAe,MAAc,OAAe,KAA4B;CACtF,IAAI,CAAC,OAAO,UAAU,KAAK,KAAK,CAAC,OAAO,UAAU,GAAG,GACnD,OAAO,mDAAmD,MAAM,OAAO,IAAI;CAE7E,IAAI,QAAQ,GAAG,OAAO;CACtB,IAAI,SAAS,KAAK,OAAO;CACzB,IAAI,MAAM,KAAK,QACb,OAAO,OAAO,IAAI,sBAAsB,KAAK,OAAO;CAEtD,KAAK,MAAM,CAAC,OAAO,UAAU,CAC3B,CAAC,SAAS,KAAK,GACf,CAAC,OAAO,GAAG,CACb,GAAY;EACV,IAAI,UAAU,KAAK,UAAU,KAAK,QAAQ;EAC1C,IAAI,qBAAqB,MAAM,QAAQ,CAAC,MAAM,OAAO;EACrD,MAAM,SAAS,yBAAyB,MAAM,KAAK;EACnD,MAAM,QAAQ,qBAAqB,MAAM,QAAQ,CAAC;EAClD,OAAO,GAAG,MAAM,GAAG,MAAM,gCAAgC,OAAO,MAAM,MAAM,QAAQ,OAAO,MAAM;CACnG;CACA,OAAO;AACT"}
@@ -4,7 +4,7 @@ import * as v from "valibot";
4
4
  //#region src/tools/variables/bindings.ts
5
5
  const bindVariable = defineTool({
6
6
  name: "bind_variable",
7
- description: "Bind a variable to a node property. For fills/strokes color bindings use indexed format like \"fills/0/color\".",
7
+ description: "Bind a variable to a node property. For fills/strokes color bindings use indexed format like \"fills/0/color\". Effects: \"effects/<i>/radius\", \"effects/<i>/spread\", \"effects/<i>/x\", \"effects/<i>/y\", \"effects/<i>/color\". Layout grids: \"layoutGrids/<i>/numSections\", \"layoutGrids/<i>/offset\", \"layoutGrids/<i>/sectionSize\", \"layoutGrids/<i>/gutterSize\".",
8
8
  execution: {
9
9
  kind: "sync",
10
10
  mutation: "properties"
@@ -1 +1 @@
1
- {"version":3,"file":"bindings.js","names":[],"sources":["../../../src/tools/variables/bindings.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport { PairdrawAPI } from '#core/pairdraw-api'\nimport { nodeIdInputSchema, defineTool } from '#core/tools/schema'\n\nexport const bindVariable = defineTool({\n name: 'bind_variable',\n\n description:\n 'Bind a variable to a node property. For fills/strokes color bindings use indexed format like \"fills/0/color\".',\n execution: { kind: 'sync', mutation: 'properties' },\n input: v.strictObject({\n node_id: nodeIdInputSchema,\n field: v.pipe(\n v.string(),\n v.description(\n 'Property field path. For fills/strokes use indexed format: \"fills/0/color\", \"strokes/0/color\". ' +\n 'For FLOAT scalars: \"opacity\", \"width\", \"height\", \"cornerRadius\", \"fontSize\", \"letterSpacing\", ' +\n '\"lineHeight\", \"itemSpacing\", \"strokeWeight\", \"paddingLeft/Right/Top/Bottom\", \"counterAxisSpacing\", ' +\n '\"rotation\", \"x\", \"y\", \"minWidth\", \"maxWidth\", \"minHeight\", \"maxHeight\", ' +\n '\"topLeftRadius\", \"topRightRadius\", \"bottomLeftRadius\", \"bottomRightRadius\", ' +\n '\"borderTopWeight\", \"borderBottomWeight\", \"borderLeftWeight\", \"borderRightWeight\", ' +\n '\"gridRowGap\", \"gridColumnGap\". ' +\n 'For STRING: \"fontFamily\". For STRING or FLOAT: \"text\", a number shown as text. ' +\n 'For BOOLEAN or STRING: \"visible\", text showing the layer unless empty or \"false\", \"no\", \"off\".'\n )\n ),\n variable_id: v.pipe(v.string(), v.description('Variable ID'))\n }),\n execute: (figma, args) => {\n const node = figma.getNodeById(args.node_id)\n if (!node) return { error: `Node \"${args.node_id}\" not found` }\n const variable = figma.variables.getVariableById(args.variable_id)\n if (!variable) return { error: `Variable \"${args.variable_id}\" not found` }\n try {\n new PairdrawAPI(figma).bindVariable(args.node_id, args.field, variable)\n } catch (err) {\n return { error: err instanceof Error ? err.message : String(err) }\n }\n return { node_id: args.node_id, field: args.field, variable_id: args.variable_id }\n }\n})\n"],"mappings":";;;;AAKA,MAAa,eAAe,WAAW;CACrC,MAAM;CAEN,aACE;CACF,WAAW;EAAE,MAAM;EAAQ,UAAU;CAAa;CAClD,OAAO,EAAE,aAAa;EACpB,SAAS;EACT,OAAO,EAAE,KACP,EAAE,OAAO,GACT,EAAE,YACA,4xBASF,CACF;EACA,aAAa,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,YAAY,aAAa,CAAC;CAC9D,CAAC;CACD,UAAU,OAAO,SAAS;EAExB,IAAI,CADS,MAAM,YAAY,KAAK,OAC5B,GAAG,OAAO,EAAE,OAAO,SAAS,KAAK,QAAQ,aAAa;EAC9D,MAAM,WAAW,MAAM,UAAU,gBAAgB,KAAK,WAAW;EACjE,IAAI,CAAC,UAAU,OAAO,EAAE,OAAO,aAAa,KAAK,YAAY,aAAa;EAC1E,IAAI;GACF,IAAI,YAAY,KAAK,CAAC,CAAC,aAAa,KAAK,SAAS,KAAK,OAAO,QAAQ;EACxE,SAAS,KAAK;GACZ,OAAO,EAAE,OAAO,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG,EAAE;EACnE;EACA,OAAO;GAAE,SAAS,KAAK;GAAS,OAAO,KAAK;GAAO,aAAa,KAAK;EAAY;CACnF;AACF,CAAC"}
1
+ {"version":3,"file":"bindings.js","names":[],"sources":["../../../src/tools/variables/bindings.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport { PairdrawAPI } from '#core/pairdraw-api'\nimport { nodeIdInputSchema, defineTool } from '#core/tools/schema'\n\nexport const bindVariable = defineTool({\n name: 'bind_variable',\n\n description:\n 'Bind a variable to a node property. For fills/strokes color bindings use indexed format like \"fills/0/color\". ' +\n 'Effects: \"effects/<i>/radius\", \"effects/<i>/spread\", \"effects/<i>/x\", \"effects/<i>/y\", \"effects/<i>/color\". ' +\n 'Layout grids: \"layoutGrids/<i>/numSections\", \"layoutGrids/<i>/offset\", \"layoutGrids/<i>/sectionSize\", ' +\n '\"layoutGrids/<i>/gutterSize\".',\n execution: { kind: 'sync', mutation: 'properties' },\n input: v.strictObject({\n node_id: nodeIdInputSchema,\n field: v.pipe(\n v.string(),\n v.description(\n 'Property field path. For fills/strokes use indexed format: \"fills/0/color\", \"strokes/0/color\". ' +\n 'For FLOAT scalars: \"opacity\", \"width\", \"height\", \"cornerRadius\", \"fontSize\", \"letterSpacing\", ' +\n '\"lineHeight\", \"itemSpacing\", \"strokeWeight\", \"paddingLeft/Right/Top/Bottom\", \"counterAxisSpacing\", ' +\n '\"rotation\", \"x\", \"y\", \"minWidth\", \"maxWidth\", \"minHeight\", \"maxHeight\", ' +\n '\"topLeftRadius\", \"topRightRadius\", \"bottomLeftRadius\", \"bottomRightRadius\", ' +\n '\"borderTopWeight\", \"borderBottomWeight\", \"borderLeftWeight\", \"borderRightWeight\", ' +\n '\"gridRowGap\", \"gridColumnGap\". ' +\n 'For STRING: \"fontFamily\". For STRING or FLOAT: \"text\", a number shown as text. ' +\n 'For BOOLEAN or STRING: \"visible\", text showing the layer unless empty or \"false\", \"no\", \"off\".'\n )\n ),\n variable_id: v.pipe(v.string(), v.description('Variable ID'))\n }),\n execute: (figma, args) => {\n const node = figma.getNodeById(args.node_id)\n if (!node) return { error: `Node \"${args.node_id}\" not found` }\n const variable = figma.variables.getVariableById(args.variable_id)\n if (!variable) return { error: `Variable \"${args.variable_id}\" not found` }\n try {\n new PairdrawAPI(figma).bindVariable(args.node_id, args.field, variable)\n } catch (err) {\n return { error: err instanceof Error ? err.message : String(err) }\n }\n return { node_id: args.node_id, field: args.field, variable_id: args.variable_id }\n }\n})\n"],"mappings":";;;;AAKA,MAAa,eAAe,WAAW;CACrC,MAAM;CAEN,aACE;CAIF,WAAW;EAAE,MAAM;EAAQ,UAAU;CAAa;CAClD,OAAO,EAAE,aAAa;EACpB,SAAS;EACT,OAAO,EAAE,KACP,EAAE,OAAO,GACT,EAAE,YACA,4xBASF,CACF;EACA,aAAa,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,YAAY,aAAa,CAAC;CAC9D,CAAC;CACD,UAAU,OAAO,SAAS;EAExB,IAAI,CADS,MAAM,YAAY,KAAK,OAC5B,GAAG,OAAO,EAAE,OAAO,SAAS,KAAK,QAAQ,aAAa;EAC9D,MAAM,WAAW,MAAM,UAAU,gBAAgB,KAAK,WAAW;EACjE,IAAI,CAAC,UAAU,OAAO,EAAE,OAAO,aAAa,KAAK,YAAY,aAAa;EAC1E,IAAI;GACF,IAAI,YAAY,KAAK,CAAC,CAAC,aAAa,KAAK,SAAS,KAAK,OAAO,QAAQ;EACxE,SAAS,KAAK;GACZ,OAAO,EAAE,OAAO,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG,EAAE;EACnE;EACA,OAAO;GAAE,SAAS,KAAK;GAAS,OAAO,KAAK;GAAO,aAAa,KAAK;EAAY;CACnF;AACF,CAAC"}
@@ -11,7 +11,7 @@ const unbindVariable = defineTool({
11
11
  },
12
12
  input: v.strictObject({
13
13
  node_id: nodeIdInputSchema,
14
- field: v.pipe(v.string(), v.description("Property field path to unbind. For fills/strokes use indexed format: \"fills/0/color\", \"strokes/0/color\". For FLOAT scalars: \"opacity\", \"width\", \"height\", \"cornerRadius\", \"fontSize\", \"letterSpacing\", \"lineHeight\", \"itemSpacing\", \"strokeWeight\", \"paddingLeft/Right/Top/Bottom\", \"counterAxisSpacing\", \"rotation\", \"x\", \"y\", \"minWidth\", \"maxWidth\", \"minHeight\", \"maxHeight\", \"topLeftRadius\", \"topRightRadius\", \"bottomLeftRadius\", \"bottomRightRadius\", \"borderTopWeight\", \"borderBottomWeight\", \"borderLeftWeight\", \"borderRightWeight\", \"gridRowGap\", \"gridColumnGap\". Text: \"text\", \"fontFamily\". Visibility: \"visible\"."))
14
+ field: v.pipe(v.string(), v.description("Property field path to unbind. For fills/strokes use indexed format: \"fills/0/color\", \"strokes/0/color\". For FLOAT scalars: \"opacity\", \"width\", \"height\", \"cornerRadius\", \"fontSize\", \"letterSpacing\", \"lineHeight\", \"itemSpacing\", \"strokeWeight\", \"paddingLeft/Right/Top/Bottom\", \"counterAxisSpacing\", \"rotation\", \"x\", \"y\", \"minWidth\", \"maxWidth\", \"minHeight\", \"maxHeight\", \"topLeftRadius\", \"topRightRadius\", \"bottomLeftRadius\", \"bottomRightRadius\", \"borderTopWeight\", \"borderBottomWeight\", \"borderLeftWeight\", \"borderRightWeight\", \"gridRowGap\", \"gridColumnGap\", \"effects/<i>/radius\", \"effects/<i>/spread\", \"effects/<i>/x\", \"effects/<i>/y\", \"effects/<i>/color\", \"layoutGrids/<i>/numSections\", \"layoutGrids/<i>/offset\", \"layoutGrids/<i>/sectionSize\", \"layoutGrids/<i>/gutterSize\". Text: \"text\", \"fontFamily\". Visibility: \"visible\"."))
15
15
  }),
16
16
  execute: (figma, args) => {
17
17
  const rawNode = figma.graph.getNode(args.node_id);
@@ -1 +1 @@
1
- {"version":3,"file":"unbind.js","names":[],"sources":["../../../src/tools/variables/unbind.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport { PairdrawAPI } from '#core/pairdraw-api'\nimport { nodeIdInputSchema, defineTool } from '#core/tools/schema'\n\nexport const unbindVariable = defineTool({\n name: 'unbind_variable',\n\n description: 'Remove a variable binding from a node property.',\n execution: { kind: 'sync', mutation: 'properties' },\n input: v.strictObject({\n node_id: nodeIdInputSchema,\n field: v.pipe(\n v.string(),\n v.description(\n 'Property field path to unbind. For fills/strokes use indexed format: \"fills/0/color\", \"strokes/0/color\". ' +\n 'For FLOAT scalars: \"opacity\", \"width\", \"height\", \"cornerRadius\", \"fontSize\", \"letterSpacing\", ' +\n '\"lineHeight\", \"itemSpacing\", \"strokeWeight\", \"paddingLeft/Right/Top/Bottom\", \"counterAxisSpacing\", ' +\n '\"rotation\", \"x\", \"y\", \"minWidth\", \"maxWidth\", \"minHeight\", \"maxHeight\", ' +\n '\"topLeftRadius\", \"topRightRadius\", \"bottomLeftRadius\", \"bottomRightRadius\", ' +\n '\"borderTopWeight\", \"borderBottomWeight\", \"borderLeftWeight\", \"borderRightWeight\", ' +\n '\"gridRowGap\", \"gridColumnGap\". ' +\n 'Text: \"text\", \"fontFamily\". Visibility: \"visible\".'\n )\n )\n }),\n execute: (figma, args) => {\n // Access raw scene node for boundVariables (not exposed on the proxy)\n const rawNode = figma.graph.getNode(args.node_id)\n if (!rawNode) return { error: `Node \"${args.node_id}\" not found` }\n const boundValue = rawNode.boundVariables[args.field]\n if (!boundValue) {\n return { error: `No binding found for field \"${args.field}\" on node \"${args.node_id}\"` }\n }\n new PairdrawAPI(figma).unbindVariable(args.node_id, args.field)\n return { unbound: true, node_id: args.node_id, field: args.field }\n }\n})\n"],"mappings":";;;;AAKA,MAAa,iBAAiB,WAAW;CACvC,MAAM;CAEN,aAAa;CACb,WAAW;EAAE,MAAM;EAAQ,UAAU;CAAa;CAClD,OAAO,EAAE,aAAa;EACpB,SAAS;EACT,OAAO,EAAE,KACP,EAAE,OAAO,GACT,EAAE,YACA,qqBAQF,CACF;CACF,CAAC;CACD,UAAU,OAAO,SAAS;EAExB,MAAM,UAAU,MAAM,MAAM,QAAQ,KAAK,OAAO;EAChD,IAAI,CAAC,SAAS,OAAO,EAAE,OAAO,SAAS,KAAK,QAAQ,aAAa;EAEjE,IAAI,CADe,QAAQ,eAAe,KAAK,QAE7C,OAAO,EAAE,OAAO,+BAA+B,KAAK,MAAM,aAAa,KAAK,QAAQ,GAAG;EAEzF,IAAI,YAAY,KAAK,CAAC,CAAC,eAAe,KAAK,SAAS,KAAK,KAAK;EAC9D,OAAO;GAAE,SAAS;GAAM,SAAS,KAAK;GAAS,OAAO,KAAK;EAAM;CACnE;AACF,CAAC"}
1
+ {"version":3,"file":"unbind.js","names":[],"sources":["../../../src/tools/variables/unbind.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport { PairdrawAPI } from '#core/pairdraw-api'\nimport { nodeIdInputSchema, defineTool } from '#core/tools/schema'\n\nexport const unbindVariable = defineTool({\n name: 'unbind_variable',\n\n description: 'Remove a variable binding from a node property.',\n execution: { kind: 'sync', mutation: 'properties' },\n input: v.strictObject({\n node_id: nodeIdInputSchema,\n field: v.pipe(\n v.string(),\n v.description(\n 'Property field path to unbind. For fills/strokes use indexed format: \"fills/0/color\", \"strokes/0/color\". ' +\n 'For FLOAT scalars: \"opacity\", \"width\", \"height\", \"cornerRadius\", \"fontSize\", \"letterSpacing\", ' +\n '\"lineHeight\", \"itemSpacing\", \"strokeWeight\", \"paddingLeft/Right/Top/Bottom\", \"counterAxisSpacing\", ' +\n '\"rotation\", \"x\", \"y\", \"minWidth\", \"maxWidth\", \"minHeight\", \"maxHeight\", ' +\n '\"topLeftRadius\", \"topRightRadius\", \"bottomLeftRadius\", \"bottomRightRadius\", ' +\n '\"borderTopWeight\", \"borderBottomWeight\", \"borderLeftWeight\", \"borderRightWeight\", ' +\n '\"gridRowGap\", \"gridColumnGap\", \"effects/<i>/radius\", \"effects/<i>/spread\", ' +\n '\"effects/<i>/x\", \"effects/<i>/y\", \"effects/<i>/color\", ' +\n '\"layoutGrids/<i>/numSections\", \"layoutGrids/<i>/offset\", ' +\n '\"layoutGrids/<i>/sectionSize\", \"layoutGrids/<i>/gutterSize\". ' +\n 'Text: \"text\", \"fontFamily\". Visibility: \"visible\".'\n )\n )\n }),\n execute: (figma, args) => {\n // Access raw scene node for boundVariables (not exposed on the proxy)\n const rawNode = figma.graph.getNode(args.node_id)\n if (!rawNode) return { error: `Node \"${args.node_id}\" not found` }\n const boundValue = rawNode.boundVariables[args.field]\n if (!boundValue) {\n return { error: `No binding found for field \"${args.field}\" on node \"${args.node_id}\"` }\n }\n new PairdrawAPI(figma).unbindVariable(args.node_id, args.field)\n return { unbound: true, node_id: args.node_id, field: args.field }\n }\n})\n"],"mappings":";;;;AAKA,MAAa,iBAAiB,WAAW;CACvC,MAAM;CAEN,aAAa;CACb,WAAW;EAAE,MAAM;EAAQ,UAAU;CAAa;CAClD,OAAO,EAAE,aAAa;EACpB,SAAS;EACT,OAAO,EAAE,KACP,EAAE,OAAO,GACT,EAAE,YACA,g5BAWF,CACF;CACF,CAAC;CACD,UAAU,OAAO,SAAS;EAExB,MAAM,UAAU,MAAM,MAAM,QAAQ,KAAK,OAAO;EAChD,IAAI,CAAC,SAAS,OAAO,EAAE,OAAO,SAAS,KAAK,QAAQ,aAAa;EAEjE,IAAI,CADe,QAAQ,eAAe,KAAK,QAE7C,OAAO,EAAE,OAAO,+BAA+B,KAAK,MAAM,aAAa,KAAK,QAAQ,GAAG;EAEzF,IAAI,YAAY,KAAK,CAAC,CAAC,eAAe,KAAK,SAAS,KAAK,KAAK;EAC9D,OAAO;GAAE,SAAS;GAAM,SAAS,KAAK;GAAS,OAAO,KAAK;EAAM;CACnE;AACF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"path.d.ts","names":[],"sources":["../../../src/tools/vector/path.ts"],"mappings":";;cA2Ca,SAAA;cAcA,SAAA;cAmBA,WAAA;cA+BA,UAAA;cA+BA,UAAA"}
1
+ {"version":3,"file":"path.d.ts","names":[],"sources":["../../../src/tools/vector/path.ts"],"mappings":";;cAyCa,SAAA;cAcA,SAAA;cAmBA,WAAA;cA+BA,UAAA;cA+BA,UAAA"}
@@ -1,8 +1,8 @@
1
- import { computeAccurateBounds } from "../../vector/curve-math.js";
2
1
  import { regenerateFillGeometry } from "../../vector/fill-geometry.js";
3
2
  import { defineTool, nodeIdInputSchema, nodeInputSchema, toolNumber } from "../schema.js";
3
+ import { rebaseVectorNetwork } from "../../vector/rebase.js";
4
4
  import { parseVectorNetworkJSON } from "./network.js";
5
- import { cloneVectorNetwork, transformVectorNetwork } from "@pairdraw/scene-graph/vector-network";
5
+ import { cloneVectorNetwork } from "@pairdraw/scene-graph/vector-network";
6
6
  import * as v from "valibot";
7
7
  //#region src/tools/vector/path.ts
8
8
  function getVectorNode(figma, id) {
@@ -20,26 +20,12 @@ function getVectorNode(figma, id) {
20
20
  * follow the edit instead of drawing the old shape.
21
21
  */
22
22
  function writePath(figma, node, network) {
23
- const bounds = computeAccurateBounds(network);
24
- const hasGeometry = network.vertices.length > 0;
25
- const rebased = hasGeometry ? transformVectorNetwork([
26
- 1,
27
- 0,
28
- -bounds.x,
29
- 0,
30
- 1,
31
- -bounds.y,
32
- 0,
33
- 0,
34
- 1
35
- ], network) : network;
23
+ const rebased = rebaseVectorNetwork(network);
36
24
  figma.graph.updateNode(node.id, {
37
- x: hasGeometry ? node.x + bounds.x : node.x,
38
- y: hasGeometry ? node.y + bounds.y : node.y,
39
- width: hasGeometry ? bounds.width : 0,
40
- height: hasGeometry ? bounds.height : 0,
41
- vectorNetwork: rebased,
42
- fillGeometry: regenerateFillGeometry(rebased, node.fillGeometry, node.cornerRadius),
25
+ ...rebased,
26
+ x: node.x + rebased.x,
27
+ y: node.y + rebased.y,
28
+ fillGeometry: regenerateFillGeometry(rebased.vectorNetwork, node.fillGeometry, node.cornerRadius),
43
29
  strokeGeometry: []
44
30
  });
45
31
  }
@@ -1 +1 @@
1
- {"version":3,"file":"path.js","names":[],"sources":["../../../src/tools/vector/path.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport type { SceneNode, VectorNetwork } from '@pairdraw/scene-graph'\nimport { cloneVectorNetwork, transformVectorNetwork } from '@pairdraw/scene-graph/vector-network'\n\nimport type { FigmaAPI } from '#core/figma-api'\nimport { defineTool, nodeIdInputSchema, nodeInputSchema, toolNumber } from '#core/tools/schema'\nimport { parseVectorNetworkJSON } from '#core/tools/vector/network'\nimport { computeAccurateBounds } from '#core/vector/curve-math'\nimport { regenerateFillGeometry } from '#core/vector/fill-geometry'\n\nfunction getVectorNode(\n figma: FigmaAPI,\n id: string\n): { node: SceneNode; vn: VectorNetwork } | { error: string } {\n const node = figma.graph.getNode(id)\n if (!node) return { error: `Node \"${id}\" not found` }\n if (!node.vectorNetwork) return { error: `Node \"${id}\" has no vector data` }\n return { node, vn: cloneVectorNetwork(node.vectorNetwork) }\n}\n\n/**\n * Writes an edited path as the plugin API's vectorNetwork setter does: the layer's box fits the\n * path, the vertices rebase to it, and imported fillGeometry rebuilds from the new path so fills\n * follow the edit instead of drawing the old shape.\n */\nfunction writePath(figma: FigmaAPI, node: SceneNode, network: VectorNetwork): void {\n const bounds = computeAccurateBounds(network)\n const hasGeometry = network.vertices.length > 0\n const rebased = hasGeometry\n ? transformVectorNetwork([1, 0, -bounds.x, 0, 1, -bounds.y, 0, 0, 1], network)\n : network\n figma.graph.updateNode(node.id, {\n x: hasGeometry ? node.x + bounds.x : node.x,\n y: hasGeometry ? node.y + bounds.y : node.y,\n width: hasGeometry ? bounds.width : 0,\n height: hasGeometry ? bounds.height : 0,\n vectorNetwork: rebased,\n fillGeometry: regenerateFillGeometry(rebased, node.fillGeometry, node.cornerRadius),\n strokeGeometry: []\n })\n}\n\nexport const pathGet = defineTool({\n name: 'path_get',\n description: 'Get vector path data of a node.',\n execution: { kind: 'sync', mutation: 'none' },\n exposure: { webmcp: false },\n input: nodeInputSchema,\n execute: (figma, { id }) => {\n const raw = figma.graph.getNode(id)\n if (!raw) return { error: `Node \"${id}\" not found` }\n const vectorNetwork = raw.vectorNetwork\n return vectorNetwork ? { id, vectorNetwork } : { error: `Node \"${id}\" has no vector data` }\n }\n})\n\nexport const pathSet = defineTool({\n name: 'path_set',\n\n description: 'Set vector path data on a node. Provide a VectorNetwork JSON.',\n execution: { kind: 'sync', mutation: 'document' },\n input: v.strictObject({\n id: nodeIdInputSchema,\n path: v.pipe(v.string(), v.description('VectorNetwork JSON'))\n }),\n execute: (figma, args) => {\n const raw = figma.graph.getNode(args.id)\n if (!raw) return { error: `Node \"${args.id}\" not found` }\n const parsed = parseVectorNetworkJSON(args.path)\n if ('error' in parsed) return parsed\n writePath(figma, raw, parsed.network)\n return { id: args.id }\n }\n})\n\nexport const pathScale = defineTool({\n name: 'path_scale',\n\n description: 'Scale vector path from center.',\n execution: { kind: 'sync', mutation: 'document' },\n input: v.strictObject({\n id: nodeIdInputSchema,\n factor: toolNumber(v.pipe(v.number(), v.description('Scale factor (e.g. 2 for double)')))\n }),\n execute: (figma, { id, factor }) => {\n const result = getVectorNode(figma, id)\n if ('error' in result) return result\n const { node: raw, vn } = result\n const centerX = raw.width / 2\n const centerY = raw.height / 2\n for (const vertex of vn.vertices) {\n vertex.x = centerX + (vertex.x - centerX) * factor\n vertex.y = centerY + (vertex.y - centerY) * factor\n }\n for (const segment of vn.segments) {\n segment.tangentStart.x *= factor\n segment.tangentStart.y *= factor\n segment.tangentEnd.x *= factor\n segment.tangentEnd.y *= factor\n }\n\n writePath(figma, raw, vn)\n return { id, factor }\n }\n})\n\nexport const pathFlip = defineTool({\n name: 'path_flip',\n\n description: 'Flip vector path horizontally or vertically.',\n execution: { kind: 'sync', mutation: 'document' },\n input: v.strictObject({\n id: nodeIdInputSchema,\n axis: v.pipe(v.picklist(['horizontal', 'vertical']), v.description('Flip axis'))\n }),\n execute: (figma, { id, axis }) => {\n const result = getVectorNode(figma, id)\n if ('error' in result) return result\n const { node: raw, vn } = result\n const width = raw.width\n const height = raw.height\n for (const vertex of vn.vertices) {\n if (axis === 'horizontal') vertex.x = width - vertex.x\n else vertex.y = height - vertex.y\n }\n for (const segment of vn.segments) {\n if (axis === 'horizontal') segment.tangentStart.x = -segment.tangentStart.x\n else segment.tangentStart.y = -segment.tangentStart.y\n if (axis === 'horizontal') segment.tangentEnd.x = -segment.tangentEnd.x\n else segment.tangentEnd.y = -segment.tangentEnd.y\n }\n\n writePath(figma, raw, vn)\n return { id, axis }\n }\n})\n\nexport const pathMove = defineTool({\n name: 'path_move',\n\n description: 'Move all path points by an offset.',\n execution: { kind: 'sync', mutation: 'document' },\n input: v.strictObject({\n id: nodeIdInputSchema,\n dx: toolNumber(v.pipe(v.number(), v.description('X offset'))),\n dy: toolNumber(v.pipe(v.number(), v.description('Y offset')))\n }),\n execute: (figma, { id, dx, dy }) => {\n const result = getVectorNode(figma, id)\n if ('error' in result) return result\n const { node: raw, vn } = result\n for (const vertex of vn.vertices) {\n vertex.x += dx\n vertex.y += dy\n }\n\n writePath(figma, raw, vn)\n return { id, dx, dy }\n }\n})\n"],"mappings":";;;;;;;AAWA,SAAS,cACP,OACA,IAC4D;CAC5D,MAAM,OAAO,MAAM,MAAM,QAAQ,EAAE;CACnC,IAAI,CAAC,MAAM,OAAO,EAAE,OAAO,SAAS,GAAG,aAAa;CACpD,IAAI,CAAC,KAAK,eAAe,OAAO,EAAE,OAAO,SAAS,GAAG,sBAAsB;CAC3E,OAAO;EAAE;EAAM,IAAI,mBAAmB,KAAK,aAAa;CAAE;AAC5D;;;;;;AAOA,SAAS,UAAU,OAAiB,MAAiB,SAA8B;CACjF,MAAM,SAAS,sBAAsB,OAAO;CAC5C,MAAM,cAAc,QAAQ,SAAS,SAAS;CAC9C,MAAM,UAAU,cACZ,uBAAuB;EAAC;EAAG;EAAG,CAAC,OAAO;EAAG;EAAG;EAAG,CAAC,OAAO;EAAG;EAAG;E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S,cAAc,OAAO,IAAI,QAAQ,OAAO;OAChD,OAAO,IAAI,SAAS,OAAO;EAElC,KAAK,MAAM,WAAW,GAAG,UAAU;GACjC,IAAI,SAAS,cAAc,QAAQ,aAAa,IAAI,CAAC,QAAQ,aAAa;QACrE,QAAQ,aAAa,IAAI,CAAC,QAAQ,aAAa;GACpD,IAAI,SAAS,cAAc,QAAQ,WAAW,IAAI,CAAC,QAAQ,WAAW;QACjE,QAAQ,WAAW,IAAI,CAAC,QAAQ,WAAW;EAClD;EAEA,UAAU,OAAO,KAAK,EAAE;EACxB,OAAO;GAAE;GAAI;EAAK;CACpB;AACF,CAAC;AAED,MAAa,WAAW,WAAW;CACjC,MAAM;CAEN,aAAa;CACb,WAAW;EAAE,MAAM;EAAQ,UAAU;CAAW;CAChD,OAAO,EAAE,aAAa;EACpB,IAAI;EACJ,IAAI,WAAW,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,YAAY,UAAU,CAAC,CAAC;EAC5D,IAAI,WAAW,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,YAAY,UAAU,CAAC,CAAC;CAC9D,CAAC;CACD,UAAU,OAAO,EAAE,IAAI,IAAI,SAAS;EAClC,MAAM,SAAS,cAAc,OAAO,EAAE;EACtC,IAAI,WAAW,QAAQ,OAAO;EAC9B,MAAM,EAAE,MAAM,KAAK,OAAO;EAC1B,KAAK,MAAM,UAAU,GAAG,UAAU;GAChC,OAAO,KAAK;GACZ,OAAO,KAAK;EACd;EAEA,UAAU,OAAO,KAAK,EAAE;EACxB,OAAO;GAAE;GAAI;GAAI;EAAG;CACtB;AACF,CAAC"}
1
+ {"version":3,"file":"path.js","names":[],"sources":["../../../src/tools/vector/path.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport type { SceneNode, VectorNetwork } from '@pairdraw/scene-graph'\nimport { cloneVectorNetwork } from '@pairdraw/scene-graph/vector-network'\n\nimport type { FigmaAPI } from '#core/figma-api'\nimport { defineTool, nodeIdInputSchema, nodeInputSchema, toolNumber } from '#core/tools/schema'\nimport { parseVectorNetworkJSON } from '#core/tools/vector/network'\nimport { regenerateFillGeometry } from '#core/vector/fill-geometry'\nimport { rebaseVectorNetwork } from '#core/vector/rebase'\n\nfunction getVectorNode(\n figma: FigmaAPI,\n id: string\n): { node: SceneNode; vn: VectorNetwork } | { error: string } {\n const node = figma.graph.getNode(id)\n if (!node) return { error: `Node \"${id}\" not found` }\n if (!node.vectorNetwork) return { error: `Node \"${id}\" has no vector data` }\n return { node, vn: cloneVectorNetwork(node.vectorNetwork) }\n}\n\n/**\n * Writes an edited path as the plugin API's vectorNetwork setter does: the layer's box fits the\n * path, the vertices rebase to it, and imported fillGeometry rebuilds from the new path so fills\n * follow the edit instead of drawing the old shape.\n */\nfunction writePath(figma: FigmaAPI, node: SceneNode, network: VectorNetwork): void {\n const rebased = rebaseVectorNetwork(network)\n figma.graph.updateNode(node.id, {\n ...rebased,\n x: node.x + rebased.x,\n y: node.y + rebased.y,\n fillGeometry: regenerateFillGeometry(\n rebased.vectorNetwork,\n node.fillGeometry,\n node.cornerRadius\n ),\n strokeGeometry: []\n })\n}\n\nexport const pathGet = defineTool({\n name: 'path_get',\n description: 'Get vector path data of a node.',\n execution: { kind: 'sync', mutation: 'none' },\n exposure: { webmcp: false },\n input: nodeInputSchema,\n execute: (figma, { id }) => {\n const raw = figma.graph.getNode(id)\n if (!raw) return { error: `Node \"${id}\" not found` }\n const vectorNetwork = raw.vectorNetwork\n return vectorNetwork ? { id, vectorNetwork } : { error: `Node \"${id}\" has no vector data` }\n }\n})\n\nexport const pathSet = defineTool({\n name: 'path_set',\n\n description: 'Set vector path data on a node. Provide a VectorNetwork JSON.',\n execution: { kind: 'sync', mutation: 'document' },\n input: v.strictObject({\n id: nodeIdInputSchema,\n path: v.pipe(v.string(), v.description('VectorNetwork JSON'))\n }),\n execute: (figma, args) => {\n const raw = figma.graph.getNode(args.id)\n if (!raw) return { error: `Node \"${args.id}\" not found` }\n const parsed = parseVectorNetworkJSON(args.path)\n if ('error' in parsed) return parsed\n writePath(figma, raw, parsed.network)\n return { id: args.id }\n }\n})\n\nexport const pathScale = defineTool({\n name: 'path_scale',\n\n description: 'Scale vector path from center.',\n execution: { kind: 'sync', mutation: 'document' },\n input: v.strictObject({\n id: nodeIdInputSchema,\n factor: toolNumber(v.pipe(v.number(), v.description('Scale factor (e.g. 2 for double)')))\n }),\n execute: (figma, { id, factor }) => {\n const result = getVectorNode(figma, id)\n if ('error' in result) return result\n const { node: raw, vn } = result\n const centerX = raw.width / 2\n const centerY = raw.height / 2\n for (const vertex of vn.vertices) {\n vertex.x = centerX + (vertex.x - centerX) * factor\n vertex.y = centerY + (vertex.y - centerY) * factor\n }\n for (const segment of vn.segments) {\n segment.tangentStart.x *= factor\n segment.tangentStart.y *= factor\n segment.tangentEnd.x *= factor\n segment.tangentEnd.y *= factor\n }\n\n writePath(figma, raw, vn)\n return { id, factor }\n }\n})\n\nexport const pathFlip = defineTool({\n name: 'path_flip',\n\n description: 'Flip vector path horizontally or vertically.',\n execution: { kind: 'sync', mutation: 'document' },\n input: v.strictObject({\n id: nodeIdInputSchema,\n axis: v.pipe(v.picklist(['horizontal', 'vertical']), v.description('Flip axis'))\n }),\n execute: (figma, { id, axis }) => {\n const result = getVectorNode(figma, id)\n if ('error' in result) return result\n const { node: raw, vn } = result\n const width = raw.width\n const height = raw.height\n for (const vertex of vn.vertices) {\n if (axis === 'horizontal') vertex.x = width - vertex.x\n else vertex.y = height - vertex.y\n }\n for (const segment of vn.segments) {\n if (axis === 'horizontal') segment.tangentStart.x = -segment.tangentStart.x\n else segment.tangentStart.y = -segment.tangentStart.y\n if (axis === 'horizontal') segment.tangentEnd.x = -segment.tangentEnd.x\n else segment.tangentEnd.y = -segment.tangentEnd.y\n }\n\n writePath(figma, raw, vn)\n return { id, axis }\n }\n})\n\nexport const pathMove = defineTool({\n name: 'path_move',\n\n description: 'Move all path points by an offset.',\n execution: { kind: 'sync', mutation: 'document' },\n input: v.strictObject({\n id: nodeIdInputSchema,\n dx: toolNumber(v.pipe(v.number(), v.description('X offset'))),\n dy: toolNumber(v.pipe(v.number(), v.description('Y offset')))\n }),\n execute: (figma, { id, dx, dy }) => {\n const result = getVectorNode(figma, id)\n if ('error' in result) return result\n const { node: raw, vn } = result\n for (const vertex of vn.vertices) {\n vertex.x += dx\n vertex.y += dy\n }\n\n writePath(figma, raw, vn)\n return { id, dx, dy }\n }\n})\n"],"mappings":";;;;;;;AAWA,SAAS,cACP,OACA,IAC4D;CAC5D,MAAM,OAAO,MAAM,MAAM,QAAQ,EAAE;CACnC,IAAI,CAAC,MAAM,OAAO,EAAE,OAAO,SAAS,GAAG,aAAa;CACpD,IAAI,CAAC,KAAK,eAAe,OAAO,EAAE,OAAO,SAAS,GAAG,sBAAsB;CAC3E,OAAO;EAAE;EAAM,IAAI,mBAAmB,KAAK,aAAa;CAAE;AAC5D;;;;;;AAOA,SAAS,UAAU,OAAiB,MAAiB,SAA8B;CACjF,MAAM,UAAU,oBAAoB,OAAO;CAC3C,MAAM,MAAM,WAAW,KAAK,IAAI;EAC9B,GAAG;EACH,GAAG,KAAK,IAAI,QAAQ;EACpB,GAAG,KAAK,IAAI,QAAQ;EACpB,cAAc,uBACZ,QAAQ,eACR,KAAK,cACL,KAAK,YACP;EACA,gBAAgB,CAAC;CACnB,CAAC;AACH;AAEA,MAAa,UAAU,WAAW;CAChC,MAAM;CACN,aAAa;CACb,WAAW;EAAE,MAAM;EAAQ,UAAU;CAAO;CAC5C,UAAU,EAAE,QAAQ,MAAM;CAC1B,OAAO;CACP,UAAU,OAAO,EAAE,SAAS;EAC1B,MAAM,MAAM,MAAM,MAAM,QAAQ,EAAE;EAClC,IAAI,CAAC,KAAK,OAAO,EAAE,OAAO,SAAS,GAAG,aAAa;EACnD,MAAM,gBAAgB,IAAI;EAC1B,OAAO,gBAAgB;GAAE;GAAI;EAAc,IAAI,EAAE,OAAO,SAAS,GAAG,sBAAsB;CAC5F;AACF,CAAC;AAED,MAAa,UA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S;EAClC,MAAM,SAAS,cAAc,OAAO,EAAE;EACtC,IAAI,WAAW,QAAQ,OAAO;EAC9B,MAAM,EAAE,MAAM,KAAK,OAAO;EAC1B,KAAK,MAAM,UAAU,GAAG,UAAU;GAChC,OAAO,KAAK;GACZ,OAAO,KAAK;EACd;EAEA,UAAU,OAAO,KAAK,EAAE;EACxB,OAAO;GAAE;GAAI;GAAI;EAAG;CACtB;AACF,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { VectorNetwork } from "@pairdraw/scene-graph";
2
+ //#region src/vector/rebase.d.ts
3
+ interface RebasedVector {
4
+ x: number;
5
+ y: number;
6
+ width: number;
7
+ height: number;
8
+ vectorNetwork: VectorNetwork;
9
+ }
10
+ /**
11
+ * A vector network moved onto its own bounds, as the plugin API's vectorNetwork setter does.
12
+ * `empty` is the value to use when the network has no vertices; it defaults to the network itself.
13
+ */
14
+ declare function rebaseVectorNetwork(network: VectorNetwork, empty?: VectorNetwork): RebasedVector;
15
+ //#endregion
16
+ export { RebasedVector, rebaseVectorNetwork };
17
+ //# sourceMappingURL=rebase.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rebase.d.ts","names":[],"sources":["../../src/vector/rebase.ts"],"mappings":";;UAKiB;EACf;EACA;EACA;EACA;EACA,eAAe;;;;;;iBAOD,oBACd,SAAS,eACT,QAAO,gBACN"}
@@ -0,0 +1,32 @@
1
+ import { computeAccurateBounds } from "./curve-math.js";
2
+ import { transformVectorNetwork } from "@pairdraw/scene-graph/vector-network";
3
+ //#region src/vector/rebase.ts
4
+ /**
5
+ * A vector network moved onto its own bounds, as the plugin API's vectorNetwork setter does.
6
+ * `empty` is the value to use when the network has no vertices; it defaults to the network itself.
7
+ */
8
+ function rebaseVectorNetwork(network, empty = network) {
9
+ const bounds = computeAccurateBounds(network);
10
+ const hasGeometry = network.vertices.length > 0;
11
+ return {
12
+ x: hasGeometry ? bounds.x : 0,
13
+ y: hasGeometry ? bounds.y : 0,
14
+ width: hasGeometry ? bounds.width : 0,
15
+ height: hasGeometry ? bounds.height : 0,
16
+ vectorNetwork: hasGeometry ? transformVectorNetwork([
17
+ 1,
18
+ 0,
19
+ -bounds.x,
20
+ 0,
21
+ 1,
22
+ -bounds.y,
23
+ 0,
24
+ 0,
25
+ 1
26
+ ], network) : empty
27
+ };
28
+ }
29
+ //#endregion
30
+ export { rebaseVectorNetwork };
31
+
32
+ //# sourceMappingURL=rebase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rebase.js","names":[],"sources":["../../src/vector/rebase.ts"],"sourcesContent":["import type { VectorNetwork } from '@pairdraw/scene-graph'\nimport { transformVectorNetwork } from '@pairdraw/scene-graph/vector-network'\n\nimport { computeAccurateBounds } from '#core/vector/curve-math'\n\nexport interface RebasedVector {\n x: number\n y: number\n width: number\n height: number\n vectorNetwork: VectorNetwork\n}\n\n/**\n * A vector network moved onto its own bounds, as the plugin API's vectorNetwork setter does.\n * `empty` is the value to use when the network has no vertices; it defaults to the network itself.\n */\nexport function rebaseVectorNetwork(\n network: VectorNetwork,\n empty: VectorNetwork = network\n): RebasedVector {\n const bounds = computeAccurateBounds(network)\n const hasGeometry = network.vertices.length > 0\n return {\n x: hasGeometry ? bounds.x : 0,\n y: hasGeometry ? bounds.y : 0,\n width: hasGeometry ? bounds.width : 0,\n height: hasGeometry ? bounds.height : 0,\n vectorNetwork: hasGeometry\n ? transformVectorNetwork([1, 0, -bounds.x, 0, 1, -bounds.y, 0, 0, 1], network)\n : empty\n }\n}\n"],"mappings":";;;;;;;AAiBA,SAAgB,oBACd,SACA,QAAuB,SACR;CACf,MAAM,SAAS,sBAAsB,OAAO;CAC5C,MAAM,cAAc,QAAQ,SAAS,SAAS;CAC9C,OAAO;EACL,GAAG,cAAc,OAAO,IAAI;EAC5B,GAAG,cAAc,OAAO,IAAI;EAC5B,OAAO,cAAc,OAAO,QAAQ;EACpC,QAAQ,cAAc,OAAO,SAAS;EACtC,eAAe,cACX,uBAAuB;GAAC;GAAG;GAAG,CAAC,OAAO;GAAG;GAAG;GAAG,CAAC,OAAO;GAAG;GAAG;GAAG;EAAC,GAAG,OAAO,IAC3E;CACN;AACF"}