@pairdraw/core 0.21.1 → 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 (590) 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/clipboard/pairdraw.d.ts.map +1 -1
  81. package/dist/clipboard/pairdraw.js +1 -0
  82. package/dist/clipboard/pairdraw.js.map +1 -1
  83. package/dist/editor/bridges/clipboard.d.ts +2 -0
  84. package/dist/editor/bridges/clipboard.d.ts.map +1 -1
  85. package/dist/editor/bridges/clipboard.js +1 -0
  86. package/dist/editor/bridges/clipboard.js.map +1 -1
  87. package/dist/editor/bridges/components.d.ts +14 -7
  88. package/dist/editor/bridges/components.d.ts.map +1 -1
  89. package/dist/editor/bridges/components.js +6 -0
  90. package/dist/editor/bridges/components.js.map +1 -1
  91. package/dist/editor/bridges/structure.d.ts +1 -1
  92. package/dist/editor/bridges/structure.d.ts.map +1 -1
  93. package/dist/editor/clipboard/code.d.ts +32 -0
  94. package/dist/editor/clipboard/code.d.ts.map +1 -0
  95. package/dist/editor/clipboard/code.js +30 -0
  96. package/dist/editor/clipboard/code.js.map +1 -0
  97. package/dist/editor/clipboard/paste/dependencies.d.ts +14 -0
  98. package/dist/editor/clipboard/paste/dependencies.d.ts.map +1 -0
  99. package/dist/editor/clipboard/paste/dependencies.js +0 -0
  100. package/dist/editor/clipboard/paste/run.d.ts +14 -0
  101. package/dist/editor/clipboard/paste/run.d.ts.map +1 -0
  102. package/dist/editor/clipboard/paste/run.js +47 -0
  103. package/dist/editor/clipboard/paste/run.js.map +1 -0
  104. package/dist/editor/clipboard/styled.d.ts +2 -8
  105. package/dist/editor/clipboard/styled.d.ts.map +1 -1
  106. package/dist/editor/clipboard/styled.js +2 -32
  107. package/dist/editor/clipboard/styled.js.map +1 -1
  108. package/dist/editor/clipboard.d.ts +2 -0
  109. package/dist/editor/clipboard.d.ts.map +1 -1
  110. package/dist/editor/clipboard.js +34 -0
  111. package/dist/editor/clipboard.js.map +1 -1
  112. package/dist/editor/components/instances.d.ts +5 -0
  113. package/dist/editor/components/instances.d.ts.map +1 -1
  114. package/dist/editor/components/instances.js +69 -4
  115. package/dist/editor/components/instances.js.map +1 -1
  116. package/dist/editor/components/slots/index.d.ts.map +1 -1
  117. package/dist/editor/components/slots/index.js +7 -0
  118. package/dist/editor/components/slots/index.js.map +1 -1
  119. package/dist/editor/components.d.ts +6 -0
  120. package/dist/editor/components.d.ts.map +1 -1
  121. package/dist/editor/components.js +14 -2
  122. package/dist/editor/components.js.map +1 -1
  123. package/dist/editor/create.d.ts +29 -2
  124. package/dist/editor/create.d.ts.map +1 -1
  125. package/dist/editor/create.js +11 -2
  126. package/dist/editor/create.js.map +1 -1
  127. package/dist/editor/design-tokens.d.ts +1 -1
  128. package/dist/editor/design-tokens.d.ts.map +1 -1
  129. package/dist/editor/design-tokens.js +4 -18
  130. package/dist/editor/design-tokens.js.map +1 -1
  131. package/dist/editor/image-edit.d.ts.map +1 -1
  132. package/dist/editor/image-edit.js +1 -2
  133. package/dist/editor/image-edit.js.map +1 -1
  134. package/dist/editor/index.d.ts +4 -4
  135. package/dist/editor/index.js +1 -1
  136. package/dist/editor/layout-mode.d.ts +3 -1
  137. package/dist/editor/layout-mode.d.ts.map +1 -1
  138. package/dist/editor/layout-mode.js +97 -2
  139. package/dist/editor/layout-mode.js.map +1 -1
  140. package/dist/editor/nodes.d.ts +2 -0
  141. package/dist/editor/nodes.d.ts.map +1 -1
  142. package/dist/editor/nodes.js +22 -7
  143. package/dist/editor/nodes.js.map +1 -1
  144. package/dist/editor/read-only/actions.js +6 -0
  145. package/dist/editor/read-only/actions.js.map +1 -1
  146. package/dist/editor/selection/overlays.d.ts +1 -0
  147. package/dist/editor/selection/overlays.d.ts.map +1 -1
  148. package/dist/editor/selection/overlays.js +7 -0
  149. package/dist/editor/selection/overlays.js.map +1 -1
  150. package/dist/editor/selection/read.d.ts +8 -0
  151. package/dist/editor/selection.d.ts +9 -0
  152. package/dist/editor/selection.d.ts.map +1 -1
  153. package/dist/editor/state/shared.js +1 -0
  154. package/dist/editor/state/shared.js.map +1 -1
  155. package/dist/editor/state/view.d.ts.map +1 -1
  156. package/dist/editor/state/view.js +2 -0
  157. package/dist/editor/state/view.js.map +1 -1
  158. package/dist/editor/structure/boolean.d.ts +1 -1
  159. package/dist/editor/structure/boolean.d.ts.map +1 -1
  160. package/dist/editor/structure/boolean.js +20 -1
  161. package/dist/editor/structure/boolean.js.map +1 -1
  162. package/dist/editor/structure/container-wrap.d.ts +8 -2
  163. package/dist/editor/structure/container-wrap.d.ts.map +1 -1
  164. package/dist/editor/structure/container-wrap.js +17 -5
  165. package/dist/editor/structure/container-wrap.js.map +1 -1
  166. package/dist/editor/structure/flatten.d.ts.map +1 -1
  167. package/dist/editor/structure/flatten.js +8 -7
  168. package/dist/editor/structure/flatten.js.map +1 -1
  169. package/dist/editor/structure/group/ungroup.d.ts.map +1 -1
  170. package/dist/editor/structure/group/ungroup.js +2 -0
  171. package/dist/editor/structure/group/ungroup.js.map +1 -1
  172. package/dist/editor/structure/outline-stroke.d.ts.map +1 -1
  173. package/dist/editor/structure/outline-stroke.js +5 -0
  174. package/dist/editor/structure/outline-stroke.js.map +1 -1
  175. package/dist/editor/structure.d.ts +1 -1
  176. package/dist/editor/structure.d.ts.map +1 -1
  177. package/dist/editor/styles.d.ts +26 -0
  178. package/dist/editor/styles.d.ts.map +1 -0
  179. package/dist/editor/styles.js +127 -0
  180. package/dist/editor/styles.js.map +1 -0
  181. package/dist/editor/text/selection-style.d.ts +1 -0
  182. package/dist/editor/text/selection-style.d.ts.map +1 -1
  183. package/dist/editor/text/selection-style.js +10 -2
  184. package/dist/editor/text/selection-style.js.map +1 -1
  185. package/dist/editor/tool-registry.d.ts.map +1 -1
  186. package/dist/editor/tool-registry.js +6 -0
  187. package/dist/editor/tool-registry.js.map +1 -1
  188. package/dist/editor/types.d.ts +14 -2
  189. package/dist/editor/types.d.ts.map +1 -1
  190. package/dist/editor/variable-bindings.d.ts.map +1 -1
  191. package/dist/editor/variable-bindings.js +6 -1
  192. package/dist/editor/variable-bindings.js.map +1 -1
  193. package/dist/figma-api/accessors/basic.d.ts.map +1 -1
  194. package/dist/figma-api/accessors/basic.js +22 -1
  195. package/dist/figma-api/accessors/basic.js.map +1 -1
  196. package/dist/figma-api/accessors/shape.js +1 -1
  197. package/dist/figma-api/accessors/text/index.js +1 -1
  198. package/dist/figma-api/accessors/text/ranges.js +1 -1
  199. package/dist/figma-api/accessors/text/references.js +1 -1
  200. package/dist/figma-api/accessors/variables.js +1 -1
  201. package/dist/figma-api/accessors/vector.d.ts.map +1 -1
  202. package/dist/figma-api/accessors/vector.js +8 -22
  203. package/dist/figma-api/accessors/vector.js.map +1 -1
  204. package/dist/figma-api/accessors/visual.js +1 -1
  205. package/dist/figma-api/compatibility.d.ts +1 -1
  206. package/dist/figma-api/compatibility.d.ts.map +1 -1
  207. package/dist/figma-api/component-scope.d.ts +14 -0
  208. package/dist/figma-api/component-scope.d.ts.map +1 -0
  209. package/dist/figma-api/component-scope.js +28 -0
  210. package/dist/figma-api/component-scope.js.map +1 -0
  211. package/dist/figma-api/components.d.ts.map +1 -1
  212. package/dist/figma-api/components.js +26 -2
  213. package/dist/figma-api/components.js.map +1 -1
  214. package/dist/figma-api/flatten.js +3 -3
  215. package/dist/figma-api/flatten.js.map +1 -1
  216. package/dist/figma-api/index.d.ts +77 -6
  217. package/dist/figma-api/index.d.ts.map +1 -1
  218. package/dist/figma-api/index.js +188 -2
  219. package/dist/figma-api/index.js.map +1 -1
  220. package/dist/figma-api/node-types.d.ts +2 -1
  221. package/dist/figma-api/node-types.d.ts.map +1 -1
  222. package/dist/figma-api/overrides.d.ts +26 -1
  223. package/dist/figma-api/overrides.d.ts.map +1 -1
  224. package/dist/figma-api/overrides.js +157 -10
  225. package/dist/figma-api/overrides.js.map +1 -1
  226. package/dist/figma-api/proxy.d.ts +2 -0
  227. package/dist/figma-api/proxy.d.ts.map +1 -1
  228. package/dist/figma-api/proxy.js +10 -2
  229. package/dist/figma-api/proxy.js.map +1 -1
  230. package/dist/figma-api/reactions.d.ts +61 -5
  231. package/dist/figma-api/reactions.d.ts.map +1 -1
  232. package/dist/figma-api/reactions.js +144 -11
  233. package/dist/figma-api/reactions.js.map +1 -1
  234. package/dist/figma-api/shape-with-text.js +1 -1
  235. package/dist/figma-api/slots.d.ts +3 -1
  236. package/dist/figma-api/slots.d.ts.map +1 -1
  237. package/dist/figma-api/slots.js +9 -8
  238. package/dist/figma-api/slots.js.map +1 -1
  239. package/dist/index.d.ts +4 -4
  240. package/dist/index.js +1 -1
  241. package/dist/io/formats/code/detect.d.ts +23 -0
  242. package/dist/io/formats/code/detect.d.ts.map +1 -0
  243. package/dist/io/formats/code/detect.js +46 -0
  244. package/dist/io/formats/code/detect.js.map +1 -0
  245. package/dist/io/formats/code/index.d.ts +5 -0
  246. package/dist/io/formats/code/index.js +5 -0
  247. package/dist/io/formats/code/read.d.ts +45 -0
  248. package/dist/io/formats/code/read.d.ts.map +1 -0
  249. package/dist/io/formats/code/read.js +86 -0
  250. package/dist/io/formats/code/read.js.map +1 -0
  251. package/dist/io/formats/code/stylesheet.d.ts +13 -0
  252. package/dist/io/formats/code/stylesheet.d.ts.map +1 -0
  253. package/dist/io/formats/code/stylesheet.js +21 -0
  254. package/dist/io/formats/code/stylesheet.js.map +1 -0
  255. package/dist/io/formats/code/tokens.d.ts +18 -0
  256. package/dist/io/formats/code/tokens.d.ts.map +1 -0
  257. package/dist/io/formats/code/tokens.js +135 -0
  258. package/dist/io/formats/code/tokens.js.map +1 -0
  259. package/dist/io/formats/design-tokens/apply.d.ts +7 -3
  260. package/dist/io/formats/design-tokens/apply.d.ts.map +1 -1
  261. package/dist/io/formats/design-tokens/apply.js.map +1 -1
  262. package/dist/io/formats/fig/export/patch/fields.js +5 -0
  263. package/dist/io/formats/fig/export/patch/fields.js.map +1 -1
  264. package/dist/io/formats/fig/export/patch/index.d.ts.map +1 -1
  265. package/dist/io/formats/fig/export/patch/index.js +20 -20
  266. package/dist/io/formats/fig/export/patch/index.js.map +1 -1
  267. package/dist/io/formats/fig/export/setup.d.ts.map +1 -1
  268. package/dist/io/formats/fig/export/setup.js +5 -1
  269. package/dist/io/formats/fig/export/setup.js.map +1 -1
  270. package/dist/io/formats/fig/index.d.ts +3 -2
  271. package/dist/io/formats/fig/index.js +2 -2
  272. package/dist/io/formats/fig/read.d.ts.map +1 -1
  273. package/dist/io/formats/fig/read.js +5 -2
  274. package/dist/io/formats/fig/read.js.map +1 -1
  275. package/dist/io/formats/html/layers.d.ts +3 -1
  276. package/dist/io/formats/html/layers.d.ts.map +1 -1
  277. package/dist/io/formats/html/layers.js +6 -1
  278. package/dist/io/formats/html/layers.js.map +1 -1
  279. package/dist/io/formats/pdf/export.d.ts.map +1 -1
  280. package/dist/io/formats/pdf/export.js +7 -3
  281. package/dist/io/formats/pdf/export.js.map +1 -1
  282. package/dist/io/formats/pdf/plan.d.ts +3 -0
  283. package/dist/io/formats/pdf/plan.d.ts.map +1 -1
  284. package/dist/io/formats/pdf/plan.js +60 -36
  285. package/dist/io/formats/pdf/plan.js.map +1 -1
  286. package/dist/io/formats/raster/headless.d.ts.map +1 -1
  287. package/dist/io/formats/raster/headless.js +3 -2
  288. package/dist/io/formats/raster/headless.js.map +1 -1
  289. package/dist/io/formats/raster/index.d.ts +2 -2
  290. package/dist/io/formats/raster/index.js +2 -2
  291. package/dist/io/formats/raster/render.d.ts +10 -2
  292. package/dist/io/formats/raster/render.d.ts.map +1 -1
  293. package/dist/io/formats/raster/render.js +35 -9
  294. package/dist/io/formats/raster/render.js.map +1 -1
  295. package/dist/io/formats/svg/defs.d.ts.map +1 -1
  296. package/dist/io/formats/svg/defs.js +19 -1
  297. package/dist/io/formats/svg/defs.js.map +1 -1
  298. package/dist/io/formats/svg/export.d.ts +5 -2
  299. package/dist/io/formats/svg/export.d.ts.map +1 -1
  300. package/dist/io/formats/svg/export.js +59 -10
  301. package/dist/io/formats/svg/export.js.map +1 -1
  302. package/dist/io/formats/svg/index.d.ts +2 -2
  303. package/dist/io/formats/svg/index.js +2 -2
  304. package/dist/io/formats/svg/text/layout.d.ts.map +1 -1
  305. package/dist/io/formats/svg/text/layout.js +4 -2
  306. package/dist/io/formats/svg/text/layout.js.map +1 -1
  307. package/dist/io/formats/video/record.d.ts.map +1 -1
  308. package/dist/io/formats/video/record.js +24 -9
  309. package/dist/io/formats/video/record.js.map +1 -1
  310. package/dist/io/formats.d.ts.map +1 -1
  311. package/dist/io/formats.js +20 -13
  312. package/dist/io/formats.js.map +1 -1
  313. package/dist/kiwi/fig/population/client.d.ts.map +1 -1
  314. package/dist/kiwi/fig/population/client.js +2 -1
  315. package/dist/kiwi/fig/population/client.js.map +1 -1
  316. package/dist/kiwi/fig/session/document-state.d.ts +46 -2
  317. package/dist/kiwi/fig/session/document-state.d.ts.map +1 -1
  318. package/dist/kiwi/fig/session/document-state.js +113 -5
  319. package/dist/kiwi/fig/session/document-state.js.map +1 -1
  320. package/dist/kiwi/fig/session/options.d.ts +4 -0
  321. package/dist/kiwi/fig/session/options.d.ts.map +1 -1
  322. package/dist/kiwi/fig/session/options.js.map +1 -1
  323. package/dist/layout/apply.d.ts.map +1 -1
  324. package/dist/layout/apply.js +8 -4
  325. package/dist/layout/apply.js.map +1 -1
  326. package/dist/layout/auto-layout-handles.js +1 -1
  327. package/dist/layout/auto-layout-handles.js.map +1 -1
  328. package/dist/layout/axis-sizing.d.ts.map +1 -1
  329. package/dist/layout/axis-sizing.js +1 -1
  330. package/dist/layout/axis-sizing.js.map +1 -1
  331. package/dist/layout/derived.d.ts.map +1 -1
  332. package/dist/layout/derived.js +1 -1
  333. package/dist/layout/derived.js.map +1 -1
  334. package/dist/layout/effective-generated-text.js +1 -1
  335. package/dist/layout/effective-generated-text.js.map +1 -1
  336. package/dist/layout/grid.d.ts +3 -1
  337. package/dist/layout/grid.d.ts.map +1 -1
  338. package/dist/layout/grid.js +57 -16
  339. package/dist/layout/grid.js.map +1 -1
  340. package/dist/layout.d.ts +1 -1
  341. package/dist/layout.js +6 -5
  342. package/dist/layout.js.map +1 -1
  343. package/dist/node/fs.d.ts.map +1 -1
  344. package/dist/node/fs.js +28 -7
  345. package/dist/node/fs.js.map +1 -1
  346. package/dist/prototype/easing.d.ts +13 -5
  347. package/dist/prototype/easing.d.ts.map +1 -1
  348. package/dist/prototype/easing.js +46 -6
  349. package/dist/prototype/easing.js.map +1 -1
  350. package/dist/prototype/scenes.d.ts +31 -0
  351. package/dist/prototype/scenes.d.ts.map +1 -1
  352. package/dist/prototype/scenes.js +220 -31
  353. package/dist/prototype/scenes.js.map +1 -1
  354. package/dist/prototype/session.d.ts.map +1 -1
  355. package/dist/prototype/session.js +1 -0
  356. package/dist/prototype/session.js.map +1 -1
  357. package/dist/prototype/smart-animate/animation.d.ts +2 -1
  358. package/dist/prototype/smart-animate/animation.d.ts.map +1 -1
  359. package/dist/prototype/smart-animate/animation.js +2 -2
  360. package/dist/prototype/smart-animate/animation.js.map +1 -1
  361. package/dist/prototype/timeline.d.ts +10 -1
  362. package/dist/prototype/timeline.d.ts.map +1 -1
  363. package/dist/prototype/timeline.js +69 -23
  364. package/dist/prototype/timeline.js.map +1 -1
  365. package/dist/prototype/variables.d.ts +23 -0
  366. package/dist/prototype/variables.d.ts.map +1 -0
  367. package/dist/prototype/variables.js +237 -0
  368. package/dist/prototype/variables.js.map +1 -0
  369. package/dist/rpc/read-commands.d.ts +5 -0
  370. package/dist/rpc/read-commands.d.ts.map +1 -1
  371. package/dist/rpc/read-commands.js +4 -1
  372. package/dist/rpc/read-commands.js.map +1 -1
  373. package/dist/text/character-style.d.ts +8 -1
  374. package/dist/text/character-style.d.ts.map +1 -1
  375. package/dist/text/character-style.js +39 -1
  376. package/dist/text/character-style.js.map +1 -1
  377. package/dist/text/index.d.ts +2 -2
  378. package/dist/text/index.js +2 -2
  379. package/dist/tools/create/basic.js +3 -4
  380. package/dist/tools/create/basic.js.map +1 -1
  381. package/dist/tools/create/behaviours.js +1 -1
  382. package/dist/tools/create/code.d.ts +6 -0
  383. package/dist/tools/create/code.d.ts.map +1 -0
  384. package/dist/tools/create/code.js +68 -0
  385. package/dist/tools/create/code.js.map +1 -0
  386. package/dist/tools/create/html.d.ts.map +1 -1
  387. package/dist/tools/create/html.js +9 -57
  388. package/dist/tools/create/html.js.map +1 -1
  389. package/dist/tools/create/icons.js +1 -1
  390. package/dist/tools/create/inputs.d.ts +11 -0
  391. package/dist/tools/create/inputs.d.ts.map +1 -0
  392. package/dist/tools/create/inputs.js +15 -0
  393. package/dist/tools/create/inputs.js.map +1 -0
  394. package/dist/tools/create/mermaid.d.ts.map +1 -1
  395. package/dist/tools/create/mermaid.js +5 -6
  396. package/dist/tools/create/mermaid.js.map +1 -1
  397. package/dist/tools/create/place.d.ts +30 -0
  398. package/dist/tools/create/place.d.ts.map +1 -0
  399. package/dist/tools/create/place.js +70 -0
  400. package/dist/tools/create/place.js.map +1 -0
  401. package/dist/tools/create/render.js +1 -1
  402. package/dist/tools/create/svg.js +1 -1
  403. package/dist/tools/create/vector.js +1 -1
  404. package/dist/tools/create.d.ts +2 -1
  405. package/dist/tools/create.js +2 -1
  406. package/dist/tools/css/gradient.d.ts +28 -0
  407. package/dist/tools/css/gradient.d.ts.map +1 -0
  408. package/dist/tools/css/gradient.js +118 -0
  409. package/dist/tools/css/gradient.js.map +1 -0
  410. package/dist/tools/image-ai/generate.js +1 -1
  411. package/dist/tools/modify/geometry.js +5 -5
  412. package/dist/tools/modify/geometry.js.map +1 -1
  413. package/dist/tools/modify/layout.d.ts.map +1 -1
  414. package/dist/tools/modify/layout.js +7 -1
  415. package/dist/tools/modify/layout.js.map +1 -1
  416. package/dist/tools/modify/matching.js +1 -1
  417. package/dist/tools/modify/overrides.d.ts +6 -0
  418. package/dist/tools/modify/overrides.d.ts.map +1 -0
  419. package/dist/tools/modify/overrides.js +27 -0
  420. package/dist/tools/modify/overrides.js.map +1 -0
  421. package/dist/tools/modify/paint.d.ts.map +1 -1
  422. package/dist/tools/modify/paint.js +84 -39
  423. package/dist/tools/modify/paint.js.map +1 -1
  424. package/dist/tools/modify/text.d.ts +2 -1
  425. package/dist/tools/modify/text.d.ts.map +1 -1
  426. package/dist/tools/modify/text.js +79 -8
  427. package/dist/tools/modify/text.js.map +1 -1
  428. package/dist/tools/modify/update.d.ts.map +1 -1
  429. package/dist/tools/modify/update.js +18 -2
  430. package/dist/tools/modify/update.js.map +1 -1
  431. package/dist/tools/modify.d.ts +3 -2
  432. package/dist/tools/modify.js +3 -2
  433. package/dist/tools/read/css.d.ts.map +1 -1
  434. package/dist/tools/read/css.js +29 -12
  435. package/dist/tools/read/css.js.map +1 -1
  436. package/dist/tools/read/libraries.js +1 -1
  437. package/dist/tools/read/nodes.d.ts.map +1 -1
  438. package/dist/tools/read/nodes.js +19 -5
  439. package/dist/tools/read/nodes.js.map +1 -1
  440. package/dist/tools/registry/extended.d.ts.map +1 -1
  441. package/dist/tools/registry/extended.js +6 -1
  442. package/dist/tools/registry/extended.js.map +1 -1
  443. package/dist/tools/text-range.d.ts +11 -0
  444. package/dist/tools/text-range.d.ts.map +1 -0
  445. package/dist/tools/text-range.js +26 -0
  446. package/dist/tools/text-range.js.map +1 -0
  447. package/dist/tools/variables/bindings.js +1 -1
  448. package/dist/tools/variables/bindings.js.map +1 -1
  449. package/dist/tools/variables/unbind.js +1 -1
  450. package/dist/tools/variables/unbind.js.map +1 -1
  451. package/dist/tools/vector/path.d.ts.map +1 -1
  452. package/dist/tools/vector/path.js +7 -21
  453. package/dist/tools/vector/path.js.map +1 -1
  454. package/dist/vector/rebase.d.ts +17 -0
  455. package/dist/vector/rebase.d.ts.map +1 -0
  456. package/dist/vector/rebase.js +32 -0
  457. package/dist/vector/rebase.js.map +1 -0
  458. package/package.json +14 -9
  459. package/src/canvas/boolean.ts +12 -1
  460. package/src/canvas/color-space.ts +73 -0
  461. package/src/canvas/fills.ts +130 -83
  462. package/src/canvas/flatten.ts +92 -7
  463. package/src/canvas/index.ts +9 -0
  464. package/src/canvas/layout-grids.ts +15 -2
  465. package/src/canvas/noise/render.ts +35 -7
  466. package/src/canvas/noise/shader.ts +8 -10
  467. package/src/canvas/overlays/annotations.ts +117 -0
  468. package/src/canvas/overlays/auto-layout-hover.ts +41 -1
  469. package/src/canvas/overlays/feedback.ts +7 -2
  470. package/src/canvas/overlays/index.ts +1 -1
  471. package/src/canvas/overlays/measurement.ts +49 -3
  472. package/src/canvas/overlays/presence.ts +35 -32
  473. package/src/canvas/renderer/colors.ts +14 -0
  474. package/src/canvas/renderer/document-surface.ts +16 -6
  475. package/src/canvas/renderer/lifecycle.ts +2 -2
  476. package/src/canvas/renderer/methods.ts +4 -0
  477. package/src/canvas/renderer/overlay-pass.ts +4 -0
  478. package/src/canvas/renderer/pipeline.ts +8 -0
  479. package/src/canvas/renderer/types.ts +8 -0
  480. package/src/canvas/renderer.ts +21 -2
  481. package/src/canvas/scene.ts +15 -7
  482. package/src/clipboard/pairdraw.ts +1 -0
  483. package/src/editor/bridges/clipboard.ts +1 -0
  484. package/src/editor/bridges/components.ts +10 -0
  485. package/src/editor/clipboard/code.ts +50 -0
  486. package/src/editor/clipboard/paste/dependencies.ts +18 -0
  487. package/src/editor/clipboard/paste/run.ts +64 -0
  488. package/src/editor/clipboard/styled.ts +4 -52
  489. package/src/editor/clipboard.ts +40 -0
  490. package/src/editor/components/instances.ts +92 -4
  491. package/src/editor/components/slots/index.ts +7 -0
  492. package/src/editor/components.ts +16 -2
  493. package/src/editor/create.ts +15 -1
  494. package/src/editor/design-tokens.ts +3 -23
  495. package/src/editor/image-edit.ts +5 -2
  496. package/src/editor/index.ts +1 -0
  497. package/src/editor/layout-mode.ts +131 -3
  498. package/src/editor/nodes.ts +30 -5
  499. package/src/editor/read-only/actions.ts +6 -0
  500. package/src/editor/selection/overlays.ts +8 -0
  501. package/src/editor/state/shared.ts +1 -0
  502. package/src/editor/state/view.ts +2 -0
  503. package/src/editor/structure/boolean.ts +29 -1
  504. package/src/editor/structure/container-wrap.ts +20 -4
  505. package/src/editor/structure/flatten.ts +15 -8
  506. package/src/editor/structure/group/ungroup.ts +2 -0
  507. package/src/editor/structure/outline-stroke.ts +5 -0
  508. package/src/editor/styles.ts +203 -0
  509. package/src/editor/text/selection-style.ts +18 -1
  510. package/src/editor/tool-registry.ts +2 -0
  511. package/src/editor/types.ts +14 -0
  512. package/src/editor/variable-bindings.ts +11 -0
  513. package/src/figma-api/accessors/basic.ts +33 -1
  514. package/src/figma-api/accessors/vector.ts +6 -13
  515. package/src/figma-api/compatibility.ts +1 -0
  516. package/src/figma-api/component-scope.ts +36 -0
  517. package/src/figma-api/components.ts +24 -0
  518. package/src/figma-api/flatten.ts +7 -3
  519. package/src/figma-api/index.ts +302 -6
  520. package/src/figma-api/node-types.ts +1 -0
  521. package/src/figma-api/overrides.ts +192 -5
  522. package/src/figma-api/proxy.ts +16 -1
  523. package/src/figma-api/reactions.ts +163 -12
  524. package/src/figma-api/slots.ts +10 -9
  525. package/src/io/formats/code/detect.ts +67 -0
  526. package/src/io/formats/code/index.ts +17 -0
  527. package/src/io/formats/code/read.ts +143 -0
  528. package/src/io/formats/code/stylesheet.ts +24 -0
  529. package/src/io/formats/code/tokens.ts +159 -0
  530. package/src/io/formats/design-tokens/apply.ts +3 -2
  531. package/src/io/formats/fig/export/patch/fields.ts +11 -0
  532. package/src/io/formats/fig/export/patch/index.ts +23 -19
  533. package/src/io/formats/fig/export/setup.ts +8 -1
  534. package/src/io/formats/fig/index.ts +6 -0
  535. package/src/io/formats/fig/read.ts +11 -2
  536. package/src/io/formats/html/layers.ts +7 -0
  537. package/src/io/formats/pdf/export.ts +19 -7
  538. package/src/io/formats/pdf/plan.ts +71 -32
  539. package/src/io/formats/raster/headless.ts +3 -1
  540. package/src/io/formats/raster/index.ts +2 -0
  541. package/src/io/formats/raster/render.ts +49 -9
  542. package/src/io/formats/svg/defs.ts +27 -1
  543. package/src/io/formats/svg/export.ts +75 -13
  544. package/src/io/formats/svg/index.ts +1 -0
  545. package/src/io/formats/svg/text/layout.ts +5 -3
  546. package/src/io/formats/video/record.ts +33 -9
  547. package/src/io/formats.ts +35 -15
  548. package/src/kiwi/fig/population/client.ts +6 -1
  549. package/src/kiwi/fig/session/document-state.ts +195 -5
  550. package/src/kiwi/fig/session/options.ts +2 -0
  551. package/src/layout/apply.ts +12 -4
  552. package/src/layout/auto-layout-handles.ts +1 -1
  553. package/src/layout/axis-sizing.ts +3 -1
  554. package/src/layout/derived.ts +3 -1
  555. package/src/layout/effective-generated-text.ts +1 -1
  556. package/src/layout/grid.ts +91 -21
  557. package/src/layout.ts +16 -3
  558. package/src/node/fs.ts +32 -7
  559. package/src/prototype/easing.ts +79 -7
  560. package/src/prototype/scenes.ts +244 -15
  561. package/src/prototype/session.ts +1 -0
  562. package/src/prototype/smart-animate/animation.ts +4 -3
  563. package/src/prototype/timeline.ts +118 -26
  564. package/src/prototype/variables.ts +189 -0
  565. package/src/rpc/read-commands.ts +19 -1
  566. package/src/text/character-style.ts +47 -0
  567. package/src/text/index.ts +1 -1
  568. package/src/tools/create/basic.ts +2 -3
  569. package/src/tools/create/code.ts +85 -0
  570. package/src/tools/create/html.ts +9 -46
  571. package/src/tools/create/inputs.ts +12 -0
  572. package/src/tools/create/mermaid.ts +6 -6
  573. package/src/tools/create/place.ts +80 -0
  574. package/src/tools/create.ts +1 -0
  575. package/src/tools/css/gradient.ts +147 -0
  576. package/src/tools/modify/geometry.ts +5 -5
  577. package/src/tools/modify/layout.ts +19 -0
  578. package/src/tools/modify/overrides.ts +35 -0
  579. package/src/tools/modify/paint.ts +124 -54
  580. package/src/tools/modify/text.ts +91 -7
  581. package/src/tools/modify/update.ts +23 -2
  582. package/src/tools/modify.ts +9 -1
  583. package/src/tools/read/css.ts +46 -12
  584. package/src/tools/read/nodes.ts +26 -4
  585. package/src/tools/registry/extended.ts +6 -0
  586. package/src/tools/text-range.ts +29 -0
  587. package/src/tools/variables/bindings.ts +4 -1
  588. package/src/tools/variables/unbind.ts +4 -1
  589. package/src/tools/vector/path.ts +11 -13
  590. package/src/vector/rebase.ts +33 -0
@@ -48,6 +48,12 @@ function overflowDirectionInput() {
48
48
  function scrollBehaviorInput() {
49
49
  return v.pipe(v.picklist(SCROLL_BEHAVIORS), v.description("Scroll behavior in prototype play: SCROLLS moves with the content, FIXED stays in the frame, STICKY_SCROLLS scrolls until it reaches the frame's top or left edge."));
50
50
  }
51
+ /** Why this edit cannot run, before anything is written. */
52
+ function editRefusal(node, args) {
53
+ if (args.overflow_direction !== void 0) return scrollRefusal(node);
54
+ if (args.boolean_operation !== void 0 && node.type !== "BOOLEAN_OPERATION") return `Only a boolean operation has boolean_operation; ${node.type} "${node.name}" does not.`;
55
+ return null;
56
+ }
51
57
  const updateNode = defineTool({
52
58
  name: "update_node",
53
59
  description: "Update properties of an existing node: position, size, opacity, corner radius, visibility, text, font, overflow scrolling.",
@@ -79,13 +85,19 @@ const updateNode = defineTool({
79
85
  font_weight: v.optional(toolNumber(v.pipe(v.number(), v.minValue(100), v.maxValue(900), v.description("Font weight (100-900)")))),
80
86
  name: v.optional(v.pipe(v.string(), v.description("Layer name"))),
81
87
  overflow_direction: v.optional(overflowDirectionInput()),
82
- scroll_behavior: v.optional(scrollBehaviorInput())
88
+ scroll_behavior: v.optional(scrollBehaviorInput()),
89
+ boolean_operation: v.optional(v.pipe(v.picklist([
90
+ "UNION",
91
+ "SUBTRACT",
92
+ "INTERSECT",
93
+ "EXCLUDE"
94
+ ]), v.description("How a BOOLEAN_OPERATION combines its children")))
83
95
  }),
84
96
  execute: (figma, args) => {
85
97
  const node = figma.getNodeById(args.id);
86
98
  if (!node) return nodeNotFound(args.id);
87
99
  assertNodeEditable(figma.graph, args.id);
88
- const refusal = args.overflow_direction === void 0 ? null : scrollRefusal(node);
100
+ const refusal = editRefusal(node, args);
89
101
  if (refusal) return { error: refusal };
90
102
  const editTypography = (changes) => {
91
103
  const scene = figma.graph.getNode(args.id);
@@ -145,6 +157,10 @@ const updateNode = defineTool({
145
157
  node.scrollBehavior = args.scroll_behavior;
146
158
  updated.push("scrollBehavior");
147
159
  }
160
+ if (args.boolean_operation !== void 0) {
161
+ node.booleanOperation = args.boolean_operation;
162
+ updated.push("booleanOperation");
163
+ }
148
164
  return {
149
165
  id: args.id,
150
166
  updated
@@ -1 +1 @@
1
- {"version":3,"file":"update.js","names":[],"sources":["../../../src/tools/modify/update.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport type { SceneNode } from '@pairdraw/scene-graph'\nimport { OVERFLOW_DIRECTIONS, SCROLL_BEHAVIORS } from '@pairdraw/scene-graph/constants'\nimport { styleDetachmentChanges } from '@pairdraw/scene-graph/shared-styles'\n\nimport { assertNodeEditable } from '#core/editor/capabilities'\nimport type { FigmaNodeProxy } from '#core/figma-api'\nimport { toolNumber, nodeIdInputSchema, defineTool, nodeNotFound } from '#core/tools/schema'\n\n/** The size of a layer and how auto layout or its text sizes it, which a resize may change. */\nfunction sizing(node: FigmaNodeProxy) {\n return {\n width: node.width,\n height: node.height,\n layoutSizingHorizontal: node.layoutSizingHorizontal,\n layoutSizingVertical: node.layoutSizingVertical,\n textAutoResize: node.textAutoResize\n }\n}\n\n/**\n * Resizes a layer and names what the resize changed: a layer inside an instance keeps its size,\n * as in Figma, while an auto layout frame or a text given its own size stops sizing itself.\n */\nfunction resized(node: FigmaNodeProxy, width = node.width, height = node.height): string[] {\n const before = sizing(node)\n node.resize(width, height)\n const after = sizing(node)\n const changed = after.width !== before.width || after.height !== before.height ? ['size'] : []\n for (const key of ['layoutSizingHorizontal', 'layoutSizingVertical', 'textAutoResize'] as const)\n if (after[key] !== before[key]) changed.push(key)\n return changed\n}\n\nconst SCROLLING_TYPES: ReadonlySet<string> = new Set(['FRAME', 'COMPONENT', 'INSTANCE'])\n\n/** Why a layer cannot take overflow scrolling, or null when it can, as Figma's frames take it. */\nexport function scrollRefusal(node: FigmaNodeProxy): string | null {\n if (SCROLLING_TYPES.has(node.type)) return null\n return `Only a frame, component or instance scrolls; ${node.type} \"${node.name}\" cannot.`\n}\n\n/** Overflow scrolling in play, as Figma's `overflowDirection`. */\nexport function overflowDirectionInput() {\n return v.pipe(\n v.picklist(OVERFLOW_DIRECTIONS),\n v.description(\n 'Overflow scrolling in prototype play (FRAME, COMPONENT, INSTANCE). A nested frame scrolls ' +\n 'only while it clips its content.'\n )\n )\n}\n\n/** How a layer moves while its parent frame scrolls in prototype play. */\nexport function scrollBehaviorInput() {\n return v.pipe(\n v.picklist(SCROLL_BEHAVIORS),\n v.description(\n 'Scroll behavior in prototype play: SCROLLS moves with the content, FIXED stays in the ' +\n \"frame, STICKY_SCROLLS scrolls until it reaches the frame's top or left edge.\"\n )\n )\n}\n\nexport const updateNode = defineTool({\n name: 'update_node',\n\n description:\n 'Update properties of an existing node: position, size, opacity, corner radius, visibility, text, font, overflow scrolling.',\n execution: { kind: 'sync', mutation: 'properties' },\n input: v.strictObject({\n id: nodeIdInputSchema,\n x: v.optional(toolNumber(v.pipe(v.number(), v.description('X position')))),\n y: v.optional(toolNumber(v.pipe(v.number(), v.description('Y position')))),\n width: v.optional(toolNumber(v.pipe(v.number(), v.minValue(1), v.description('Width')))),\n height: v.optional(toolNumber(v.pipe(v.number(), v.minValue(1), v.description('Height')))),\n opacity: v.optional(\n toolNumber(v.pipe(v.number(), v.minValue(0), v.maxValue(1), v.description('Opacity (0-1)')))\n ),\n corner_radius: v.optional(\n toolNumber(v.pipe(v.number(), v.minValue(0), v.description('Corner radius')))\n ),\n visible: v.optional(v.pipe(v.boolean(), v.description('Visibility'))),\n text: v.optional(v.pipe(v.string(), v.description('Text content (TEXT nodes)'))),\n text_direction: v.optional(\n v.pipe(v.picklist(['AUTO', 'LTR', 'RTL']), v.description('Text direction for TEXT nodes'))\n ),\n flow_direction: v.optional(\n v.pipe(\n v.picklist(['AUTO', 'LTR', 'RTL']),\n v.description('Auto-layout flow direction for FRAME nodes')\n )\n ),\n font_size: v.optional(\n toolNumber(v.pipe(v.number(), v.minValue(1), v.description('Font size')))\n ),\n font_weight: v.optional(\n toolNumber(\n v.pipe(v.number(), v.minValue(100), v.maxValue(900), v.description('Font weight (100-900)'))\n )\n ),\n name: v.optional(v.pipe(v.string(), v.description('Layer name'))),\n overflow_direction: v.optional(overflowDirectionInput()),\n scroll_behavior: v.optional(scrollBehaviorInput())\n }),\n execute: (figma, args) => {\n const node = figma.getNodeById(args.id)\n if (!node) return nodeNotFound(args.id)\n assertNodeEditable(figma.graph, args.id)\n // Refused before anything is written, so the call changes all or nothing.\n const refusal = args.overflow_direction === undefined ? null : scrollRefusal(node)\n if (refusal) return { error: refusal }\n // Written to the layer directly, since the plugin setters need a loaded font; an edit to a\n // text style's field leaves the style, as the editor's updates do.\n const editTypography = (changes: Partial<SceneNode>) => {\n const scene = figma.graph.getNode(args.id)\n if (scene) figma.graph.updateNode(args.id, styleDetachmentChanges(scene, changes))\n }\n const updated: string[] = []\n if (args.x !== undefined) {\n node.x = args.x\n updated.push('x')\n }\n if (args.y !== undefined) {\n node.y = args.y\n updated.push('y')\n }\n if (args.width !== undefined || args.height !== undefined)\n updated.push(...resized(node, args.width, args.height))\n if (args.opacity !== undefined) {\n node.opacity = args.opacity\n updated.push('opacity')\n }\n if (args.corner_radius !== undefined) {\n node.cornerRadius = args.corner_radius\n updated.push('cornerRadius')\n }\n if (args.visible !== undefined) {\n node.visible = args.visible\n updated.push('visible')\n }\n if (args.name !== undefined) {\n node.name = args.name\n updated.push('name')\n }\n if (args.text !== undefined) {\n figma.graph.updateNode(node.id, { text: args.text })\n updated.push('text')\n }\n if (args.text_direction !== undefined) {\n figma.graph.updateNode(node.id, {\n textDirection: args.text_direction\n })\n updated.push('textDirection')\n }\n if (args.flow_direction !== undefined) {\n figma.graph.updateNode(node.id, {\n layoutDirection: args.flow_direction\n })\n updated.push('layoutDirection')\n }\n if (args.font_size !== undefined) {\n editTypography({ fontSize: args.font_size })\n updated.push('fontSize')\n }\n if (args.font_weight !== undefined) {\n editTypography({ fontWeight: args.font_weight })\n updated.push('fontWeight')\n }\n if (args.overflow_direction !== undefined) {\n node.overflowDirection = args.overflow_direction\n updated.push('overflowDirection')\n }\n if (args.scroll_behavior !== undefined) {\n node.scrollBehavior = args.scroll_behavior\n updated.push('scrollBehavior')\n }\n return { id: args.id, updated }\n }\n})\n"],"mappings":";;;;;;;AAWA,SAAS,OAAO,MAAsB;CACpC,OAAO;EACL,OAAO,KAAK;EACZ,QAAQ,KAAK;EACb,wBAAwB,KAAK;EAC7B,sBAAsB,KAAK;EAC3B,gBAAgB,KAAK;CACvB;AACF;;;;;AAMA,SAAS,QAAQ,MAAsB,QAAQ,KAAK,OAAO,SAAS,KAAK,QAAkB;CACzF,MAAM,SAAS,OAAO,IAAI;CAC1B,KAAK,OAAO,OAAO,MAAM;CACzB,MAAM,QAAQ,OAAO,IAAI;CACzB,MAAM,UAAU,MAAM,UAAU,OAAO,SAAS,MAAM,WAAW,OAAO,SAAS,CAAC,MAAM,IAAI,CAAC;CAC7F,KAAK,MAAM,OAAO;EAAC;EAA0B;EAAwB;CAAgB,GACnF,IAAI,MAAM,SAAS,OAAO,MAAM,QAAQ,KAAK,GAAG;CAClD,OAAO;AACT;AAEA,MAAM,kCAAuC,IAAI,IAAI;CAAC;CAAS;CAAa;AAAU,CAAC;;AAGvF,SAAgB,cAAc,MAAqC;CACjE,IAAI,gBAAgB,IAAI,KAAK,IAAI,GAAG,OAAO;CAC3C,OAAO,gDAAgD,KAAK,KAAK,IAAI,KAAK,KAAK;AACjF;;AAGA,SAAgB,yBAAyB;CACvC,OAAO,EAAE,KACP,EAAE,SAAS,mBAAmB,GAC9B,EAAE,YACA,4HAEF,CACF;AACF;;AAGA,SAAgB,sBAAsB;CACpC,O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OAAO;GAAE,IAAI,KAAK;GAAI;EAAQ;CAChC;AACF,CAAC"}
1
+ {"version":3,"file":"update.js","names":[],"sources":["../../../src/tools/modify/update.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport type { SceneNode } from '@pairdraw/scene-graph'\nimport { OVERFLOW_DIRECTIONS, SCROLL_BEHAVIORS } from '@pairdraw/scene-graph/constants'\nimport { styleDetachmentChanges } from '@pairdraw/scene-graph/shared-styles'\n\nimport { assertNodeEditable } from '#core/editor/capabilities'\nimport type { FigmaNodeProxy } from '#core/figma-api'\nimport { toolNumber, nodeIdInputSchema, defineTool, nodeNotFound } from '#core/tools/schema'\n\n/** The size of a layer and how auto layout or its text sizes it, which a resize may change. */\nfunction sizing(node: FigmaNodeProxy) {\n return {\n width: node.width,\n height: node.height,\n layoutSizingHorizontal: node.layoutSizingHorizontal,\n layoutSizingVertical: node.layoutSizingVertical,\n textAutoResize: node.textAutoResize\n }\n}\n\n/**\n * Resizes a layer and names what the resize changed: a layer inside an instance keeps its size,\n * as in Figma, while an auto layout frame or a text given its own size stops sizing itself.\n */\nfunction resized(node: FigmaNodeProxy, width = node.width, height = node.height): string[] {\n const before = sizing(node)\n node.resize(width, height)\n const after = sizing(node)\n const changed = after.width !== before.width || after.height !== before.height ? ['size'] : []\n for (const key of ['layoutSizingHorizontal', 'layoutSizingVertical', 'textAutoResize'] as const)\n if (after[key] !== before[key]) changed.push(key)\n return changed\n}\n\nconst SCROLLING_TYPES: ReadonlySet<string> = new Set(['FRAME', 'COMPONENT', 'INSTANCE'])\n\n/** Why a layer cannot take overflow scrolling, or null when it can, as Figma's frames take it. */\nexport function scrollRefusal(node: FigmaNodeProxy): string | null {\n if (SCROLLING_TYPES.has(node.type)) return null\n return `Only a frame, component or instance scrolls; ${node.type} \"${node.name}\" cannot.`\n}\n\n/** Overflow scrolling in play, as Figma's `overflowDirection`. */\nexport function overflowDirectionInput() {\n return v.pipe(\n v.picklist(OVERFLOW_DIRECTIONS),\n v.description(\n 'Overflow scrolling in prototype play (FRAME, COMPONENT, INSTANCE). A nested frame scrolls ' +\n 'only while it clips its content.'\n )\n )\n}\n\n/** How a layer moves while its parent frame scrolls in prototype play. */\nexport function scrollBehaviorInput() {\n return v.pipe(\n v.picklist(SCROLL_BEHAVIORS),\n v.description(\n 'Scroll behavior in prototype play: SCROLLS moves with the content, FIXED stays in the ' +\n \"frame, STICKY_SCROLLS scrolls until it reaches the frame's top or left edge.\"\n )\n )\n}\n\n/** Why this edit cannot run, before anything is written. */\nfunction editRefusal(\n node: FigmaNodeProxy,\n args: { overflow_direction?: string; boolean_operation?: string }\n): string | null {\n if (args.overflow_direction !== undefined) return scrollRefusal(node)\n if (args.boolean_operation !== undefined && node.type !== 'BOOLEAN_OPERATION')\n return `Only a boolean operation has boolean_operation; ${node.type} \"${node.name}\" does not.`\n return null\n}\n\nexport const updateNode = defineTool({\n name: 'update_node',\n\n description:\n 'Update properties of an existing node: position, size, opacity, corner radius, visibility, text, font, overflow scrolling.',\n execution: { kind: 'sync', mutation: 'properties' },\n input: v.strictObject({\n id: nodeIdInputSchema,\n x: v.optional(toolNumber(v.pipe(v.number(), v.description('X position')))),\n y: v.optional(toolNumber(v.pipe(v.number(), v.description('Y position')))),\n width: v.optional(toolNumber(v.pipe(v.number(), v.minValue(1), v.description('Width')))),\n height: v.optional(toolNumber(v.pipe(v.number(), v.minValue(1), v.description('Height')))),\n opacity: v.optional(\n toolNumber(v.pipe(v.number(), v.minValue(0), v.maxValue(1), v.description('Opacity (0-1)')))\n ),\n corner_radius: v.optional(\n toolNumber(v.pipe(v.number(), v.minValue(0), v.description('Corner radius')))\n ),\n visible: v.optional(v.pipe(v.boolean(), v.description('Visibility'))),\n text: v.optional(v.pipe(v.string(), v.description('Text content (TEXT nodes)'))),\n text_direction: v.optional(\n v.pipe(v.picklist(['AUTO', 'LTR', 'RTL']), v.description('Text direction for TEXT nodes'))\n ),\n flow_direction: v.optional(\n v.pipe(\n v.picklist(['AUTO', 'LTR', 'RTL']),\n v.description('Auto-layout flow direction for FRAME nodes')\n )\n ),\n font_size: v.optional(\n toolNumber(v.pipe(v.number(), v.minValue(1), v.description('Font size')))\n ),\n font_weight: v.optional(\n toolNumber(\n v.pipe(v.number(), v.minValue(100), v.maxValue(900), v.description('Font weight (100-900)'))\n )\n ),\n name: v.optional(v.pipe(v.string(), v.description('Layer name'))),\n overflow_direction: v.optional(overflowDirectionInput()),\n scroll_behavior: v.optional(scrollBehaviorInput()),\n boolean_operation: v.optional(\n v.pipe(\n v.picklist(['UNION', 'SUBTRACT', 'INTERSECT', 'EXCLUDE']),\n v.description('How a BOOLEAN_OPERATION combines its children')\n )\n )\n }),\n execute: (figma, args) => {\n const node = figma.getNodeById(args.id)\n if (!node) return nodeNotFound(args.id)\n assertNodeEditable(figma.graph, args.id)\n // Refused before anything is written, so the call changes all or nothing.\n const refusal = editRefusal(node, args)\n if (refusal) return { error: refusal }\n // Written to the layer directly, since the plugin setters need a loaded font; an edit to a\n // text style's field leaves the style, as the editor's updates do.\n const editTypography = (changes: Partial<SceneNode>) => {\n const scene = figma.graph.getNode(args.id)\n if (scene) figma.graph.updateNode(args.id, styleDetachmentChanges(scene, changes))\n }\n const updated: string[] = []\n if (args.x !== undefined) {\n node.x = args.x\n updated.push('x')\n }\n if (args.y !== undefined) {\n node.y = args.y\n updated.push('y')\n }\n if (args.width !== undefined || args.height !== undefined)\n updated.push(...resized(node, args.width, args.height))\n if (args.opacity !== undefined) {\n node.opacity = args.opacity\n updated.push('opacity')\n }\n if (args.corner_radius !== undefined) {\n node.cornerRadius = args.corner_radius\n updated.push('cornerRadius')\n }\n if (args.visible !== undefined) {\n node.visible = args.visible\n updated.push('visible')\n }\n if (args.name !== undefined) {\n node.name = args.name\n updated.push('name')\n }\n if (args.text !== undefined) {\n figma.graph.updateNode(node.id, { text: args.text })\n updated.push('text')\n }\n if (args.text_direction !== undefined) {\n figma.graph.updateNode(node.id, {\n textDirection: args.text_direction\n })\n updated.push('textDirection')\n }\n if (args.flow_direction !== undefined) {\n figma.graph.updateNode(node.id, {\n layoutDirection: args.flow_direction\n })\n updated.push('layoutDirection')\n }\n if (args.font_size !== undefined) {\n editTypography({ fontSize: args.font_size })\n updated.push('fontSize')\n }\n if (args.font_weight !== undefined) {\n editTypography({ fontWeight: args.font_weight })\n updated.push('fontWeight')\n }\n if (args.overflow_direction !== undefined) {\n node.overflowDirection = args.overflow_direction\n updated.push('overflowDirection')\n }\n if (args.scroll_behavior !== undefined) {\n node.scrollBehavior = args.scroll_behavior\n updated.push('scrollBehavior')\n }\n if (args.boolean_operation !== undefined) {\n node.booleanOperation = args.boolean_operation\n updated.push('booleanOperation')\n }\n return { id: args.id, updated }\n }\n})\n"],"mappings":";;;;;;;AAWA,SAAS,OAAO,MAAsB;CACpC,OAAO;EACL,OAAO,KAAK;EACZ,QAAQ,KAAK;EACb,wBAAwB,KAAK;EAC7B,sBAAsB,KAAK;EAC3B,gBAAgB,KAAK;CACvB;AACF;;;;;AAMA,SAAS,QAAQ,MAAsB,QAAQ,KAAK,OAAO,SAAS,KAAK,QAAkB;CACzF,MAAM,SAAS,OAAO,IAAI;CAC1B,KAAK,OAAO,OAAO,MAAM;CACzB,MAAM,QAAQ,OAAO,IAAI;CACzB,MAAM,UAAU,MAAM,UAAU,OAAO,SAAS,MAAM,WAAW,OAAO,SAAS,CAAC,MAAM,IAAI,CAAC;CAC7F,KAAK,MAAM,OAAO;EAAC;EAA0B;EAAwB;CAAgB,GACnF,IAAI,MAAM,SAAS,OAAO,MAAM,QAAQ,KAAK,GAAG;CAClD,OAAO;AACT;AAEA,MAAM,kCAAuC,IAAI,IAAI;CAAC;CAAS;CAAa;AAAU,CAAC;;AAGvF,SAAgB,cAAc,MAAqC;CACjE,IAAI,gBAAgB,IAAI,KAAK,IAAI,GAAG,OAAO;CAC3C,OAAO,gDAAgD,KAAK,KAAK,IAAI,KAAK,KAAK;AACjF;;AAGA,SAAgB,yBAAyB;CACvC,OAAO,EAAE,KACP,EAAE,SA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E,UAAU,KAAK,UAAU,CAAC;GAC3C,QAAQ,KAAK,UAAU;EACzB;EACA,IAAI,KAAK,gBAAgB,KAAA,GAAW;GAClC,eAAe,EAAE,YAAY,KAAK,YAAY,CAAC;GAC/C,QAAQ,KAAK,YAAY;EAC3B;EACA,IAAI,KAAK,uBAAuB,KAAA,GAAW;GACzC,KAAK,oBAAoB,KAAK;GAC9B,QAAQ,KAAK,mBAAmB;EAClC;EACA,IAAI,KAAK,oBAAoB,KAAA,GAAW;GACtC,KAAK,iBAAiB,KAAK;GAC3B,QAAQ,KAAK,gBAAgB;EAC/B;EACA,IAAI,KAAK,sBAAsB,KAAA,GAAW;GACxC,KAAK,mBAAmB,KAAK;GAC7B,QAAQ,KAAK,kBAAkB;EACjC;EACA,OAAO;GAAE,IAAI,KAAK;GAAI;EAAQ;CAChC;AACF,CAAC"}
@@ -3,9 +3,10 @@ import { replaceFonts } from "./modify/fonts.js";
3
3
  import { rescale, setMinMax, setOpacity, setRadius, setRotation } from "./modify/geometry.js";
4
4
  import { setConstraints, setLayout, setLayoutChild } from "./modify/layout.js";
5
5
  import { replaceMatchingProperties } from "./modify/matching.js";
6
+ import { resetOverrideFields } from "./modify/overrides.js";
6
7
  import { setFill, setImageFill, setStroke } from "./modify/paint.js";
7
8
  import { setReactions } from "./modify/reactions.js";
8
9
  import { setBlend, setLocked, setStrokeAlign, setVisible } from "./modify/state.js";
9
- import { setFont, setFontRange, setText, setTextProperties, setTextResize } from "./modify/text.js";
10
+ import { setFont, setFontRange, setText, setTextProperties, setTextRangeStyle, setTextResize } from "./modify/text.js";
10
11
  import { updateNode } from "./modify/update.js";
11
- export { replaceFonts, replaceMatchingProperties, rescale, setBlend, setConstraints, setEffects, setFill, setFont, setFontRange, setImageFill, setLayout, setLayoutChild, setLocked, setMinMax, setOpacity, setRadius, setReactions, setRotation, setStroke, setStrokeAlign, setText, setTextProperties, setTextResize, setVisible, updateNode };
12
+ export { replaceFonts, replaceMatchingProperties, rescale, resetOverrideFields, setBlend, setConstraints, setEffects, setFill, setFont, setFontRange, setImageFill, setLayout, setLayoutChild, setLocked, setMinMax, setOpacity, setRadius, setReactions, setRotation, setStroke, setStrokeAlign, setText, setTextProperties, setTextRangeStyle, setTextResize, setVisible, updateNode };
@@ -2,10 +2,11 @@ import { setEffects } from "./modify/effects.js";
2
2
  import { replaceFonts } from "./modify/fonts.js";
3
3
  import { rescale, setMinMax, setOpacity, setRadius, setRotation } from "./modify/geometry.js";
4
4
  import { setConstraints, setLayout, setLayoutChild } from "./modify/layout.js";
5
- import { setFont, setFontRange, setText, setTextProperties, setTextResize } from "./modify/text.js";
5
+ import { setFont, setFontRange, setText, setTextProperties, setTextRangeStyle, setTextResize } from "./modify/text.js";
6
6
  import { replaceMatchingProperties } from "./modify/matching.js";
7
+ import { resetOverrideFields } from "./modify/overrides.js";
7
8
  import { setFill, setImageFill, setStroke } from "./modify/paint.js";
8
9
  import { setReactions } from "./modify/reactions.js";
9
10
  import { setBlend, setLocked, setStrokeAlign, setVisible } from "./modify/state.js";
10
11
  import { updateNode } from "./modify/update.js";
11
- export { replaceFonts, replaceMatchingProperties, rescale, setBlend, setConstraints, setEffects, setFill, setFont, setFontRange, setImageFill, setLayout, setLayoutChild, setLocked, setMinMax, setOpacity, setRadius, setReactions, setRotation, setStroke, setStrokeAlign, setText, setTextProperties, setTextResize, setVisible, updateNode };
12
+ export { replaceFonts, replaceMatchingProperties, rescale, resetOverrideFields, setBlend, setConstraints, setEffects, setFill, setFont, setFontRange, setImageFill, setLayout, setLayoutChild, setLocked, setMinMax, setOpacity, setRadius, setReactions, setRotation, setStroke, setStrokeAlign, setText, setTextProperties, setTextRangeStyle, setTextResize, setVisible, updateNode };
@@ -1 +1 @@
1
- {"version":3,"file":"css.d.ts","names":[],"sources":["../../../src/tools/read/css.ts"],"mappings":";;;;;;;;cAca;cACA;cAmSA,QAAA"}
1
+ {"version":3,"file":"css.d.ts","names":[],"sources":["../../../src/tools/read/css.ts"],"mappings":";;;;;;;;cAea;cACA;cAoUA,QAAA"}
@@ -1,6 +1,7 @@
1
1
  import { defineTool, nodeIdsField, toolNumber } from "../schema.js";
2
2
  import { colorToDocumentCSS } from "@pairdraw/scene-graph/color";
3
3
  import * as v from "valibot";
4
+ import { diamondFillToCSS, gradientFillToCSS } from "@pairdraw/dom-css/export";
4
5
  //#region src/tools/read/css.ts
5
6
  /**
6
7
  * A subtree as CSS-shaped lines: one line per node, lengths in px, colours in the document's
@@ -66,37 +67,53 @@ function boundName(graph, node, field) {
66
67
  }
67
68
  /**
68
69
  * A stored colour as the shorthand writes it: `#RRGGBB` in an sRGB document, `color(display-p3 …)`
69
- * in a Display P3 one, where hex would name a different colour. The shorthand carries no alpha, as
70
- * it never has, so the paint's opacity is left to `opacity`.
70
+ * in a Display P3 one, where hex would name a different colour, and `rgba()` or `color(… / a)` when
71
+ * the paint is translucent. What paints is the colour's alpha times the paint's `opacity`, so both
72
+ * are folded into the shorthand; the setters store that product the same way.
71
73
  */
72
- function cssColor(color, profile) {
74
+ function cssColor(color, opacity, profile) {
73
75
  return colorToDocumentCSS({
74
76
  ...color,
75
- a: 1
77
+ a: color.a * opacity
76
78
  }, profile);
77
79
  }
80
+ /** The first visible solid fill and its index, which a text colour or a background can name. */
81
+ function solidFill(node) {
82
+ const index = node.fills.findIndex((candidate) => candidate.type === "SOLID" && candidate.visible);
83
+ const fill = index === -1 ? void 0 : node.fills[index];
84
+ return fill?.type === "SOLID" ? {
85
+ index,
86
+ fill
87
+ } : null;
88
+ }
78
89
  /** A colour in the document's profile, or `var(--token, …)` when a variable paints it. */
79
90
  function paintOf(node, graph, field, paint) {
80
91
  const name = boundName(graph, node, field);
81
92
  return name ? `var(--${name}, ${paint})` : paint;
82
93
  }
83
94
  function background(node, graph) {
84
- const index = node.fills.findIndex((candidate) => candidate.type === "SOLID" && candidate.visible);
85
- const solid = index === -1 ? void 0 : node.fills[index];
95
+ const solid = solidFill(node);
86
96
  if (solid) {
87
- const paint = cssColor(solid.color, graph.documentColorSpace);
88
- return paintOf(node, graph, `fills/${index}/color`, paint);
97
+ const paint = cssColor(solid.fill.color, solid.fill.opacity, graph.documentColorSpace);
98
+ return paintOf(node, graph, `fills/${solid.index}/color`, paint);
89
99
  }
90
100
  const otherIndex = node.fills.findIndex((candidate) => candidate.visible);
91
101
  const other = otherIndex === -1 ? void 0 : node.fills[otherIndex];
92
102
  if (!other) return null;
93
- return other.type.startsWith("GRADIENT") ? "gradient" : "image";
103
+ switch (other.type) {
104
+ case "GRADIENT_DIAMOND": return diamondFillToCSS(other, graph.documentColorSpace) ?? "gradient";
105
+ case "GRADIENT_LINEAR":
106
+ case "GRADIENT_RADIAL":
107
+ case "GRADIENT_ANGULAR": return gradientFillToCSS(other, node.width, node.height, graph.documentColorSpace) ?? "gradient";
108
+ case "IMAGE": return `image(${other.imageScaleMode ?? "FILL"})`;
109
+ default: return "image";
110
+ }
94
111
  }
95
112
  function border(node, graph) {
96
113
  const index = node.strokes.findIndex((candidate) => candidate.visible);
97
114
  const stroke = index === -1 ? void 0 : node.strokes[index];
98
115
  if (!stroke) return null;
99
- const paint = cssColor(stroke.color, graph.documentColorSpace);
116
+ const paint = cssColor(stroke.color, stroke.opacity, graph.documentColorSpace);
100
117
  return `${px(stroke.weight)} ${paintOf(node, graph, `strokes/${index}/color`, paint)}`;
101
118
  }
102
119
  /** Padding in CSS order, compressed to the fewest values that say the same thing. */
@@ -111,7 +128,7 @@ function padding(node) {
111
128
  return `${px(top)} ${px(right)} ${px(bottom)} ${px(left)}`;
112
129
  }
113
130
  function shadowOf(prefix, effect, profile) {
114
- return `${prefix}:${px(effect.offset.x)} ${px(effect.offset.y)} ${px(effect.radius)} ${cssColor(effect.color, profile)}`;
131
+ return `${prefix}:${px(effect.offset.x)} ${px(effect.offset.y)} ${px(effect.radius)} ${cssColor(effect.color, 1, profile)}`;
115
132
  }
116
133
  function effects(node, profile) {
117
134
  const out = [];
@@ -166,7 +183,7 @@ function lineHeightOf(node) {
166
183
  function textDecls(node, graph) {
167
184
  const out = [`font:${node.fontWeight} ${px(node.fontSize)}/${lineHeightOf(node)} ${node.fontFamily}`];
168
185
  const bg = background(node, graph);
169
- if (bg) out.push(`color:${bg}`);
186
+ if (bg && solidFill(node)) out.push(`color:${bg}`);
170
187
  if (node.textAlignHorizontal !== "LEFT") out.push(`text-align:${node.textAlignHorizontal.toLowerCase()}`);
171
188
  if (node.maxLines !== null && node.maxLines > 0) out.push(`max-lines:${node.maxLines}`);
172
189
  if (node.textAutoResize === "NONE") out.push("fixed");
@@ -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;E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KAAK;IAAK;IAAK,WAAW;IAAM;GAAQ;EACxD;EAEA,IAAI,CAAC,KAAK,IAAI,OAAO,EAAE,OAAO,wCAAwC;EACtE,IAAI,CAAC,MAAM,MAAM,QAAQ,KAAK,EAAE,GAAG,OAAO,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,Q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K,WAAW;IAAM;GAAQ;EACxD;EAEA,IAAI,CAAC,KAAK,IAAI,OAAO,EAAE,OAAO,wCAAwC;EACtE,IAAI,CAAC,MAAM,MAAM,QAAQ,KAAK,EAAE,GAAG,OAAO,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,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,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;CAC5C,IAAI,SAAS,SAAS,GAAG,MAAM,WAAW;CAC1C,OAAO;AACT;;AAGA,SAAS,gBACP,OACA,OACA,YACA;CACA,MAAM,OAAO,MAAM;CACnB,MAAM,WAAwB,CAAC;CAC/B,KAAK,MAAM,SAAS,KAAK,UAAU;EACjC,MAAM,QAAQ,gBAAgB,OAAO,GAAG,OAAO,UAAU;EACzD,IAAI,OAAO,SAAS,KAAK,KAAK;CAChC;CACA,OAAO;EAAE,MAAM,KAAK;EAAM;CAAS;AACrC;AAEA,SAAS,aAAa,WAAmE;CACvF,OAAO,aAAa,UAAU,SAAS,IAAI,IAAI,IAAI,SAAS,IAAI,KAAA;AAClE;AAEA,MAAa,cAAc,WAAW;CACpC,MAAM;CACN,aACE;CACF,WAAW;EAAE,MAAM;EAAS,UAAU;CAAO;CAC7C,OAAO,EAAE,aAAa;EACpB,OAAO,EAAE,SACP,WACE,EAAE,KACA,EAAE,OAAO,GACT,EAAE,SAAS,CAAC,GACZ,EAAE,YACA,gFAC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ACE,EAAE,KACA,EAAE,OAAO,GACT,EAAE,YAAY,wEAAwE,CACxF,CACF,CACF;CACF,CAAC;CACD,cAAc,OAAO,EAAE,IAAI,YAAY;EACrC,MAAM,OAAO,MAAM,YAAY,EAAE;EACjC,OAAO,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;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M,OAAO,KAAA;EAClB,MAAM,SAAS,aAAa,MAAM,KAAK;EACvC,OAAO,oBAAoB,aAAa,OAAO,IAAI,MAAM,IAAI;CAC/D;CACA,SAAS,OAAO,OAAO,EAAE,IAAI,OAAO,wBAAwB;EAG1D,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"