@pairdraw/core 0.16.2 → 0.18.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 (257) hide show
  1. package/dist/canvas/outline-stroke.d.ts.map +1 -1
  2. package/dist/canvas/outline-stroke.js.map +1 -1
  3. package/dist/canvas/overlays/prototype.d.ts +2 -5
  4. package/dist/canvas/overlays/prototype.d.ts.map +1 -1
  5. package/dist/canvas/overlays/prototype.js +3 -19
  6. package/dist/canvas/overlays/prototype.js.map +1 -1
  7. package/dist/canvas/renderer/fonts.js +2 -1
  8. package/dist/canvas/renderer/fonts.js.map +1 -1
  9. package/dist/canvas/renderer.d.ts +4 -0
  10. package/dist/canvas/renderer.d.ts.map +1 -1
  11. package/dist/canvas/renderer.js +4 -0
  12. package/dist/canvas/renderer.js.map +1 -1
  13. package/dist/canvas/rulers.js +1 -1
  14. package/dist/canvas/rulers.js.map +1 -1
  15. package/dist/canvas/scene.d.ts.map +1 -1
  16. package/dist/canvas/scene.js +61 -37
  17. package/dist/canvas/scene.js.map +1 -1
  18. package/dist/canvas/text/font-families.d.ts +4 -3
  19. package/dist/canvas/text/font-families.d.ts.map +1 -1
  20. package/dist/canvas/text/font-families.js +8 -7
  21. package/dist/canvas/text/font-families.js.map +1 -1
  22. package/dist/canvas/text/index.d.ts.map +1 -1
  23. package/dist/canvas/text/index.js +1 -1
  24. package/dist/canvas/text/index.js.map +1 -1
  25. package/dist/canvas/text/paragraph/index.js +2 -2
  26. package/dist/canvas/text/paragraph/index.js.map +1 -1
  27. package/dist/canvas/text/placed.js +2 -2
  28. package/dist/canvas/text/placed.js.map +1 -1
  29. package/dist/canvas/text/renderer.d.ts +2 -0
  30. package/dist/canvas/text/renderer.d.ts.map +1 -1
  31. package/dist/clipboard/pairdraw.d.ts.map +1 -1
  32. package/dist/clipboard/pairdraw.js +53 -7
  33. package/dist/clipboard/pairdraw.js.map +1 -1
  34. package/dist/design-jsx/preview/picture.js +6 -1
  35. package/dist/design-jsx/preview/picture.js.map +1 -1
  36. package/dist/design-jsx/renderer.d.ts.map +1 -1
  37. package/dist/editor/alignment.d.ts.map +1 -1
  38. package/dist/editor/alignment.js +35 -27
  39. package/dist/editor/alignment.js.map +1 -1
  40. package/dist/editor/bridges/undo.d.ts +1 -1
  41. package/dist/editor/clipboard/detach.d.ts.map +1 -1
  42. package/dist/editor/clipboard/detach.js +3 -3
  43. package/dist/editor/clipboard/detach.js.map +1 -1
  44. package/dist/editor/clipboard/paste/properties.d.ts.map +1 -1
  45. package/dist/editor/clipboard/paste/properties.js +3 -1
  46. package/dist/editor/clipboard/paste/properties.js.map +1 -1
  47. package/dist/editor/create.d.ts +1 -1
  48. package/dist/editor/structure.d.ts.map +1 -1
  49. package/dist/editor/structure.js +3 -1
  50. package/dist/editor/structure.js.map +1 -1
  51. package/dist/editor/viewport.js +2 -2
  52. package/dist/editor/viewport.js.map +1 -1
  53. package/dist/figma-api/index.d.ts +43 -8
  54. package/dist/figma-api/index.d.ts.map +1 -1
  55. package/dist/figma-api/index.js +48 -6
  56. package/dist/figma-api/index.js.map +1 -1
  57. package/dist/figma-api/serialization.js +10 -0
  58. package/dist/figma-api/serialization.js.map +1 -1
  59. package/dist/figma-api/text/bindings.d.ts.map +1 -1
  60. package/dist/figma-api/text/bindings.js +20 -8
  61. package/dist/figma-api/text/bindings.js.map +1 -1
  62. package/dist/figma-api/text/index.js +1 -1
  63. package/dist/geometry/connectors.js +2 -14
  64. package/dist/geometry/connectors.js.map +1 -1
  65. package/dist/geometry/index.d.ts +2 -2
  66. package/dist/geometry/scene.d.ts +3 -1
  67. package/dist/geometry/scene.d.ts.map +1 -1
  68. package/dist/geometry/scene.js +16 -1
  69. package/dist/geometry/scene.js.map +1 -1
  70. package/dist/geometry/types.d.ts +7 -1
  71. package/dist/geometry/types.d.ts.map +1 -1
  72. package/dist/io/formats/drawio/export.d.ts.map +1 -1
  73. package/dist/io/formats/drawio/export.js +10 -0
  74. package/dist/io/formats/drawio/export.js.map +1 -1
  75. package/dist/io/formats/drawio/index.d.ts.map +1 -1
  76. package/dist/io/formats/drawio/index.js +32 -1
  77. package/dist/io/formats/drawio/index.js.map +1 -1
  78. package/dist/io/formats/drawio/shapes.d.ts +10 -5
  79. package/dist/io/formats/drawio/shapes.d.ts.map +1 -1
  80. package/dist/io/formats/drawio/shapes.js +10 -6
  81. package/dist/io/formats/drawio/shapes.js.map +1 -1
  82. package/dist/io/formats/drawio/warnings.d.ts +11 -0
  83. package/dist/io/formats/drawio/warnings.d.ts.map +1 -0
  84. package/dist/io/formats/drawio/warnings.js +23 -0
  85. package/dist/io/formats/drawio/warnings.js.map +1 -0
  86. package/dist/io/formats/pdf/dom.d.ts +10 -1
  87. package/dist/io/formats/pdf/dom.d.ts.map +1 -1
  88. package/dist/io/formats/pdf/dom.js +31 -1
  89. package/dist/io/formats/pdf/dom.js.map +1 -1
  90. package/dist/io/formats/pdf/export.js +3 -2
  91. package/dist/io/formats/pdf/export.js.map +1 -1
  92. package/dist/io/formats/raster/headless.d.ts +2 -2
  93. package/dist/io/formats/raster/headless.d.ts.map +1 -1
  94. package/dist/io/formats/raster/headless.js +2 -2
  95. package/dist/io/formats/raster/headless.js.map +1 -1
  96. package/dist/io/formats/raster/render.d.ts +1 -1
  97. package/dist/io/formats/raster/render.d.ts.map +1 -1
  98. package/dist/io/formats/raster/render.js +2 -2
  99. package/dist/io/formats/raster/render.js.map +1 -1
  100. package/dist/io/formats.d.ts.map +1 -1
  101. package/dist/io/formats.js +6 -6
  102. package/dist/io/formats.js.map +1 -1
  103. package/dist/io/registry.d.ts +2 -0
  104. package/dist/io/registry.d.ts.map +1 -1
  105. package/dist/io/registry.js +5 -0
  106. package/dist/io/registry.js.map +1 -1
  107. package/dist/io/types.d.ts +2 -0
  108. package/dist/io/types.d.ts.map +1 -1
  109. package/dist/library/snapshot.d.ts.map +1 -1
  110. package/dist/library/snapshot.js +1 -0
  111. package/dist/library/snapshot.js.map +1 -1
  112. package/dist/lint/linter.d.ts.map +1 -1
  113. package/dist/lint/linter.js +11 -2
  114. package/dist/lint/linter.js.map +1 -1
  115. package/dist/rpc/variables-command.d.ts.map +1 -1
  116. package/dist/rpc/variables-command.js +4 -2
  117. package/dist/rpc/variables-command.js.map +1 -1
  118. package/dist/text/character-style.d.ts.map +1 -1
  119. package/dist/text/character-style.js +2 -1
  120. package/dist/text/character-style.js.map +1 -1
  121. package/dist/text/coverage.d.ts.map +1 -1
  122. package/dist/text/coverage.js +6 -3
  123. package/dist/text/coverage.js.map +1 -1
  124. package/dist/text/fallbacks.d.ts +8 -2
  125. package/dist/text/fallbacks.d.ts.map +1 -1
  126. package/dist/text/fallbacks.js +73 -7
  127. package/dist/text/fallbacks.js.map +1 -1
  128. package/dist/text/font/manager.d.ts +14 -6
  129. package/dist/text/font/manager.d.ts.map +1 -1
  130. package/dist/text/font/manager.js +40 -14
  131. package/dist/text/font/manager.js.map +1 -1
  132. package/dist/text/index.d.ts +2 -2
  133. package/dist/text/index.js +3 -3
  134. package/dist/text/outlines.js +1 -1
  135. package/dist/text/outlines.js.map +1 -1
  136. package/dist/text/path/caret.d.ts +2 -4
  137. package/dist/text/path/caret.d.ts.map +1 -1
  138. package/dist/text/path/caret.js.map +1 -1
  139. package/dist/text/prepare.d.ts +5 -1
  140. package/dist/text/prepare.d.ts.map +1 -1
  141. package/dist/text/prepare.js +19 -2
  142. package/dist/text/prepare.js.map +1 -1
  143. package/dist/text/web-font/assets.d.ts.map +1 -1
  144. package/dist/text/web-font/assets.js +13 -21
  145. package/dist/text/web-font/assets.js.map +1 -1
  146. package/dist/text/web-font/resolver.d.ts.map +1 -1
  147. package/dist/text/web-font/resolver.js +4 -1
  148. package/dist/text/web-font/resolver.js.map +1 -1
  149. package/dist/tools/create/components.d.ts +2 -1
  150. package/dist/tools/create/components.d.ts.map +1 -1
  151. package/dist/tools/create/components.js +27 -1
  152. package/dist/tools/create/components.js.map +1 -1
  153. package/dist/tools/create/icons.d.ts.map +1 -1
  154. package/dist/tools/create/icons.js +11 -5
  155. package/dist/tools/create/icons.js.map +1 -1
  156. package/dist/tools/create/vector.d.ts.map +1 -1
  157. package/dist/tools/create/vector.js +9 -6
  158. package/dist/tools/create/vector.js.map +1 -1
  159. package/dist/tools/create.d.ts +2 -2
  160. package/dist/tools/create.js +2 -2
  161. package/dist/tools/modify/effects.d.ts.map +1 -1
  162. package/dist/tools/modify/effects.js +5 -3
  163. package/dist/tools/modify/effects.js.map +1 -1
  164. package/dist/tools/modify/matching.d.ts.map +1 -1
  165. package/dist/tools/modify/matching.js +9 -6
  166. package/dist/tools/modify/matching.js.map +1 -1
  167. package/dist/tools/modify/paint.d.ts.map +1 -1
  168. package/dist/tools/modify/paint.js +7 -5
  169. package/dist/tools/modify/paint.js.map +1 -1
  170. package/dist/tools/modify/text.d.ts.map +1 -1
  171. package/dist/tools/modify/text.js +28 -8
  172. package/dist/tools/modify/text.js.map +1 -1
  173. package/dist/tools/read/libraries.d.ts.map +1 -1
  174. package/dist/tools/read/libraries.js +20 -8
  175. package/dist/tools/read/libraries.js.map +1 -1
  176. package/dist/tools/read/pages.d.ts.map +1 -1
  177. package/dist/tools/read/pages.js.map +1 -1
  178. package/dist/tools/registry/extended.d.ts.map +1 -1
  179. package/dist/tools/registry/extended.js +2 -1
  180. package/dist/tools/registry/extended.js.map +1 -1
  181. package/dist/tools/schema.d.ts +24 -5
  182. package/dist/tools/schema.d.ts.map +1 -1
  183. package/dist/tools/schema.js +80 -6
  184. package/dist/tools/schema.js.map +1 -1
  185. package/dist/tools/structure/batch.d.ts.map +1 -1
  186. package/dist/tools/structure/batch.js +4 -3
  187. package/dist/tools/structure/batch.js.map +1 -1
  188. package/dist/tools/variables/values.d.ts.map +1 -1
  189. package/dist/tools/variables/values.js +4 -2
  190. package/dist/tools/variables/values.js.map +1 -1
  191. package/dist/tools/vector/export.d.ts.map +1 -1
  192. package/dist/tools/vector/export.js +5 -2
  193. package/dist/tools/vector/export.js.map +1 -1
  194. package/package.json +9 -9
  195. package/src/canvas/outline-stroke.ts +2 -6
  196. package/src/canvas/overlays/prototype.ts +5 -27
  197. package/src/canvas/renderer/fonts.ts +2 -1
  198. package/src/canvas/renderer.ts +4 -0
  199. package/src/canvas/rulers.ts +1 -1
  200. package/src/canvas/scene.ts +92 -63
  201. package/src/canvas/text/font-families.ts +8 -7
  202. package/src/canvas/text/index.ts +3 -1
  203. package/src/canvas/text/paragraph/index.ts +2 -2
  204. package/src/canvas/text/placed.ts +2 -2
  205. package/src/canvas/text/renderer.ts +2 -0
  206. package/src/clipboard/pairdraw.ts +51 -7
  207. package/src/design-jsx/preview/picture.ts +8 -2
  208. package/src/editor/alignment.ts +33 -29
  209. package/src/editor/clipboard/detach.ts +9 -3
  210. package/src/editor/clipboard/paste/properties.ts +3 -1
  211. package/src/editor/structure.ts +3 -1
  212. package/src/editor/viewport.ts +2 -2
  213. package/src/figma-api/index.ts +90 -9
  214. package/src/figma-api/serialization.ts +14 -0
  215. package/src/figma-api/text/bindings.ts +26 -8
  216. package/src/geometry/connectors.ts +2 -12
  217. package/src/geometry/index.ts +1 -1
  218. package/src/geometry/scene.ts +19 -0
  219. package/src/geometry/types.ts +8 -0
  220. package/src/io/formats/drawio/export.ts +11 -0
  221. package/src/io/formats/drawio/index.ts +36 -1
  222. package/src/io/formats/drawio/shapes.ts +13 -9
  223. package/src/io/formats/drawio/warnings.ts +27 -0
  224. package/src/io/formats/pdf/dom.ts +29 -0
  225. package/src/io/formats/pdf/export.ts +3 -2
  226. package/src/io/formats/raster/headless.ts +10 -3
  227. package/src/io/formats/raster/render.ts +4 -2
  228. package/src/io/formats.ts +8 -10
  229. package/src/io/registry.ts +12 -0
  230. package/src/io/types.ts +2 -0
  231. package/src/library/snapshot.ts +1 -0
  232. package/src/lint/linter.ts +12 -2
  233. package/src/rpc/variables-command.ts +6 -5
  234. package/src/text/character-style.ts +8 -4
  235. package/src/text/coverage.ts +17 -2
  236. package/src/text/fallbacks.ts +81 -7
  237. package/src/text/font/manager.ts +50 -17
  238. package/src/text/outlines.ts +1 -1
  239. package/src/text/path/caret.ts +3 -4
  240. package/src/text/prepare.ts +34 -2
  241. package/src/text/web-font/assets.ts +11 -15
  242. package/src/text/web-font/resolver.ts +7 -1
  243. package/src/tools/create/components.ts +33 -0
  244. package/src/tools/create/icons.ts +13 -5
  245. package/src/tools/create/vector.ts +16 -6
  246. package/src/tools/create.ts +1 -0
  247. package/src/tools/modify/effects.ts +11 -4
  248. package/src/tools/modify/matching.ts +10 -6
  249. package/src/tools/modify/paint.ts +13 -5
  250. package/src/tools/modify/text.ts +53 -20
  251. package/src/tools/read/libraries.ts +35 -11
  252. package/src/tools/read/pages.ts +1 -0
  253. package/src/tools/registry/extended.ts +2 -0
  254. package/src/tools/schema.ts +109 -5
  255. package/src/tools/structure/batch.ts +10 -5
  256. package/src/tools/variables/values.ts +6 -3
  257. package/src/tools/vector/export.ts +5 -1
@@ -1 +1 @@
1
- {"version":3,"file":"text.js","names":[],"sources":["../../../src/tools/modify/text.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport { parseColor } from '@pairdraw/scene-graph/color'\n\nimport type { FigmaAPI, FigmaNodeProxy } from '#core/figma-api'\nimport type { FigmaFontName, FigmaFontNameInput } from '#core/figma-api/fonts/names'\nimport type { FigmaVariationSettings } from '#core/figma-api/fonts/variations'\nimport { PairdrawAPI } from '#core/pairdraw-api'\nimport { normalizeLinkURL } from '#core/text/hyperlink'\nimport { collectNodeFontFaces } from '#core/text/requirements/collect'\nimport {\n toolNumber,\n nodeIdInputSchema,\n defineTool,\n nodeNotFound,\n toolFailure\n} from '#core/tools/schema'\n\n/**\n * A link a text tool sets, as the editor's link field takes it: a web or mail address, with\n * `https:` or `mailto:` added when typed without a scheme. Null or blank removes the link.\n */\nconst hyperlinkInputSchema = v.optional(\n v.pipe(\n v.nullable(v.string()),\n v.description(\n 'Link the text opens: an http(s) or mailto address (\"example.com\" becomes https://example.com, \"hi@example.com\" becomes mailto:). null or \"\" removes the link. Links are not underlined automatically; set text_decoration for that.'\n )\n )\n)\n\n/**\n * A scheme at the start of a typed link, even with a digit after its colon (`tel:123`), unless it\n * reads as a host and port (`localhost:3000`, `example.com:8080`), which gets `https://`.\n */\nconst TYPED_SCHEME = /^([a-z][a-z\\d+.-]*):/i\n\n/** A web address in the form the Figma API's link setter takes: `http(s)://host…`. */\nconst WEB_URL = /^https?:\\/\\/[^\\s/?#]+\\S*$/\n\n/** Whether a typed link names a scheme other than the http, https, and mailto links take. */\nfunction hasForeignScheme(typed: string): boolean {\n const scheme = TYPED_SCHEME.exec(typed)?.[1]?.toLowerCase()\n if (!scheme || scheme.includes('.') || scheme === 'localhost') return false\n return !['http', 'https', 'mailto'].includes(scheme)\n}\n\n/** What setting `hyperlink` asks for: no change, a removal, a URL, or an address it refuses. */\nfunction requestedHyperlink(\n hyperlink: string | null | undefined\n): { link: { type: 'URL'; value: string } | null } | { error: string } | null {\n if (hyperlink === undefined) return null\n if (hyperlink === null || hyperlink.trim() === '') return { link: null }\n const url = hasForeignScheme(hyperlink.trim()) ? null : normalizeLinkURL(hyperlink)\n if (!url) {\n return {\n error: `\"${hyperlink}\" is not a link the editor opens: use an http, https, or mailto address`\n }\n }\n // Figma keeps schemes in lower case and web addresses as `scheme://host`, so a loosely typed\n // `http:example.com` is written as the URL it parses to.\n const lowered = url.replace(TYPED_SCHEME, (scheme) => scheme.toLowerCase())\n const value =\n lowered.startsWith('mailto:') || WEB_URL.test(lowered) ? lowered : new URL(lowered).href\n return { link: { type: 'URL', value } }\n}\n\n/** The fonts a text layer uses, which an edit that lays it out again needs loaded. */\nexport function textFonts(figma: FigmaAPI, id: string): FigmaFontNameInput[] {\n const node = figma.graph.getNode(id)\n return node ? collectNodeFontFaces(node) : []\n}\n\nexport const setText = defineTool({\n name: 'set_text',\n\n description: 'Set text content of a text node.',\n execution: { kind: 'sync', mutation: 'properties' },\n input: v.strictObject({\n id: nodeIdInputSchema,\n text: v.pipe(v.string(), v.description('Text content'))\n }),\n fonts: (figma, { id }) => textFonts(figma, id),\n execute: (figma, { id, text }) => {\n const node = figma.getNodeById(id)\n if (!node) return { error: `Node \"${id}\" not found` }\n node.characters = text\n return { id, text }\n }\n})\n\n/** Variable font axes a font tool can set, as Figma's `variationSettings`. */\nconst variationsInputSchema = v.optional(\n v.pipe(\n v.record(v.pipe(v.string(), v.length(4)), v.number()),\n v.description(\n 'Variable font axis values by OpenType tag (e.g. {\"wght\": 550, \"wdth\": 75}); axes left out keep the style\\'s values. Without a style, the nearest named style is picked.'\n )\n )\n)\n\n/**\n * The font a font tool gives text: what it names, the rest from `current`. Axes without a style\n * leave the style out, for the nearest named style to be picked.\n */\nfunction fontNameInput(\n args: { family?: string; style?: string; variations?: FigmaVariationSettings },\n current: FigmaFontName | null\n): FigmaFontNameInput {\n return {\n family: args.family ?? current?.family ?? '',\n style: args.style ?? (args.variations ? undefined : (current?.style ?? 'Regular')),\n variationSettings: args.variations\n }\n}\n\n/**\n * The font `set_font` gives the text, or null when it keeps the text's. Text set in several fonts\n * takes the given family or style for all of it, keeping the rest from its first character. Axes\n * without a style are set per range, each range taking its nearest named style, as in Figma.\n */\nfunction requestedFont(\n node: FigmaNodeProxy,\n args: { family?: string; style?: string; variations?: FigmaVariationSettings }\n): { whole: FigmaFontName } | { perRange: FigmaFontNameInput } | null {\n if (!args.family && !args.style && !args.variations) return null\n const fontName =\n typeof node.fontName === 'symbol' && node.characters.length > 0\n ? node.getRangeFontName(0, 1)\n : node.fontName\n const current = typeof fontName === 'symbol' ? null : fontName\n const family = args.family ?? current?.family ?? ''\n if (args.variations && !args.style && node.characters.length > 0) {\n return { perRange: { family, variationSettings: args.variations } }\n }\n const style = args.style ?? current?.style ?? 'Regular'\n return { whole: { family, style, variationSettings: args.variations } }\n}\n\nexport const setFont = defineTool({\n name: 'set_font',\n\n description: 'Set font properties of a text node.',\n execution: { kind: 'sync', mutation: 'properties' },\n input: v.strictObject({\n id: nodeIdInputSchema,\n family: v.optional(v.pipe(v.string(), v.description('Font family name'))),\n size: v.optional(toolNumber(v.pipe(v.number(), v.minValue(1), v.description('Font size')))),\n style: v.optional(\n v.pipe(v.string(), v.description('Font style (e.g. \"Bold\", \"Regular\", \"Bold Italic\")'))\n ),\n variations: variationsInputSchema\n }),\n // A new font replaces the text's, which then need not be loaded, so a missing font can be\n // replaced; a size or per-range axes lay out the text in its own fonts.\n fonts: (figma, args) => {\n const node = figma.getNodeById(args.id)\n const font = node && requestedFont(node, args)\n if (font && 'whole' in font) return [font.whole]\n return [...(font ? [font.perRange] : []), ...textFonts(figma, args.id)]\n },\n execute: (figma, args) => {\n const node = figma.getNodeById(args.id)\n if (!node) return nodeNotFound(args.id)\n const font = requestedFont(node, args)\n try {\n if (font && 'whole' in font) node.fontName = font.whole\n else if (font) node.setRangeFontName(0, node.characters.length, font.perRange)\n // The size comes after the font, so it lays the text out in the font it ends up in.\n if (args.size !== undefined) node.fontSize = args.size\n } catch (error) {\n return toolFailure(error)\n }\n return { id: args.id, fontName: node.fontName, fontSize: node.fontSize }\n }\n})\n\n/** The font `set_font_range` gives its range: what it names, the rest from the range's start. */\nfunction rangeFont(\n node: FigmaNodeProxy,\n args: { start: number; family?: string; style?: string; variations?: FigmaVariationSettings }\n): FigmaFontNameInput {\n const inText = args.start < node.characters.length\n const current = inText ? node.getRangeFontName(args.start, args.start + 1) : node.fontName\n return fontNameInput(args, typeof current === 'symbol' ? null : current)\n}\n\nexport const setFontRange = defineTool({\n name: 'set_font_range',\n\n description: 'Set font properties, color, or a link for a text range.',\n execution: { kind: 'sync', mutation: 'properties' },\n input: v.strictObject({\n id: nodeIdInputSchema,\n start: toolNumber(v.pipe(v.number(), v.minValue(0), v.description('Start character index'))),\n end: toolNumber(v.pipe(v.number(), v.minValue(0), v.description('End character index'))),\n family: v.optional(v.pipe(v.string(), v.description('Font family name'))),\n size: v.optional(toolNumber(v.pipe(v.number(), v.minValue(1), v.description('Font size')))),\n style: v.optional(v.pipe(v.string(), v.description('Font style'))),\n variations: variationsInputSchema,\n color: v.optional(v.pipe(v.string(), v.description('Text color (hex)'))),\n hyperlink: hyperlinkInputSchema\n }),\n fonts: (figma, args) => {\n const node = figma.getNodeById(args.id)\n if (!node) return []\n const font = args.family || args.style || args.variations ? rangeFont(node, args) : null\n // A colour alone is a paint and lays nothing out, so text in a missing font can still take it.\n const laysOut = font !== null || args.size !== undefined\n return [...(font ? [font] : []), ...(laysOut ? textFonts(figma, args.id) : [])]\n },\n execute: (figma, args) => {\n const node = figma.getNodeById(args.id)\n if (!node) return nodeNotFound(args.id)\n const { start, end } = args\n if (\n !args.family &&\n !args.size &&\n !args.style &&\n !args.variations &&\n !args.color &&\n args.hyperlink === undefined\n ) {\n return {\n error:\n 'set_font_range needs at least one of family, size, style, variations, color, or hyperlink'\n }\n }\n const hyperlink = requestedHyperlink(args.hyperlink)\n if (hyperlink && 'error' in hyperlink) return hyperlink\n // The range methods reject an empty range or one past the text, before changing anything.\n try {\n if (args.size) node.setRangeFontSize(start, end, args.size)\n if (args.family || args.style || args.variations) {\n node.setRangeFontName(start, end, rangeFont(node, args))\n }\n if (args.color) {\n node.setRangeFills(start, end, [{ type: 'SOLID', color: parseColor(args.color) }])\n }\n if (hyperlink) node.setRangeHyperlink(start, end, hyperlink.link)\n } catch (error) {\n return toolFailure(error)\n }\n return {\n id: args.id,\n range: { start, end },\n ...(hyperlink ? { hyperlink: hyperlink.link?.value ?? null } : {})\n }\n }\n})\n\nexport const setTextResize = defineTool({\n name: 'set_text_resize',\n\n description: 'Set text auto-resize mode.',\n execution: { kind: 'sync', mutation: 'properties' },\n input: v.strictObject({\n id: nodeIdInputSchema,\n mode: v.pipe(\n v.picklist(['NONE', 'WIDTH_AND_HEIGHT', 'HEIGHT', 'TRUNCATE']),\n v.description('Resize mode')\n )\n }),\n fonts: (figma, { id }) => textFonts(figma, id),\n execute: (figma, { id, mode }) => {\n const node = figma.getNodeById(id)\n if (!node) return { error: `Node \"${id}\" not found` }\n node.textAutoResize = mode\n return { id, textAutoResize: mode }\n }\n})\n\nexport const setTextProperties = defineTool({\n name: 'set_text_properties',\n\n description:\n 'Set text layout properties: alignment, auto-resize, text case, decoration, truncation, and a link for the whole text.',\n execution: { kind: 'sync', mutation: 'properties' },\n input: v.strictObject({\n id: v.pipe(v.string(), v.description('Text node ID')),\n align_horizontal: v.optional(\n v.pipe(\n v.picklist(['LEFT', 'CENTER', 'RIGHT', 'JUSTIFIED']),\n v.description('Horizontal text alignment')\n )\n ),\n align_vertical: v.optional(\n v.pipe(v.picklist(['TOP', 'CENTER', 'BOTTOM']), v.description('Vertical text alignment'))\n ),\n auto_resize: v.optional(\n v.pipe(\n v.picklist(['NONE', 'WIDTH_AND_HEIGHT', 'HEIGHT', 'TRUNCATE']),\n v.description('Text auto-resize mode')\n )\n ),\n direction: v.optional(\n v.pipe(v.picklist(['AUTO', 'LTR', 'RTL']), v.description('Text direction'))\n ),\n text_decoration: v.optional(\n v.pipe(v.picklist(['NONE', 'UNDERLINE', 'STRIKETHROUGH']), v.description('Text decoration'))\n ),\n hyperlink: hyperlinkInputSchema\n }),\n fonts: (figma, { id }) => textFonts(figma, id),\n execute: (figma, args) => {\n const node = figma.getNodeById(args.id)\n if (!node) return nodeNotFound(args.id)\n if (node.type !== 'TEXT') return { error: `Node \"${args.id}\" is not a TEXT node` }\n // Refused before anything changes, so a bad address leaves the text as it was.\n const hyperlink = requestedHyperlink(args.hyperlink)\n if (hyperlink && 'error' in hyperlink) return hyperlink\n const updated: string[] = []\n if (args.align_horizontal !== undefined) {\n node.textAlignHorizontal = args.align_horizontal\n updated.push('textAlignHorizontal')\n }\n if (args.align_vertical !== undefined) {\n node.textAlignVertical = args.align_vertical\n updated.push('textAlignVertical')\n }\n if (args.auto_resize !== undefined) {\n node.textAutoResize = args.auto_resize\n updated.push('textAutoResize')\n }\n if (args.direction !== undefined) {\n new PairdrawAPI(figma).setTextDirection(node, args.direction)\n updated.push('textDirection')\n }\n if (args.text_decoration !== undefined) {\n node.textDecoration = args.text_decoration\n updated.push('textDecoration')\n }\n if (hyperlink) {\n try {\n node.hyperlink = hyperlink.link\n } catch (error) {\n return toolFailure(error)\n }\n updated.push('hyperlink')\n }\n return { id: args.id, updated }\n }\n})\n"],"mappings":";;;;;;;;;;;AAsBA,MAAM,uBAAuB,EAAE,SAC7B,EAAE,KACA,EAAE,SAAS,EAAE,OAAO,CAAC,GACrB,EAAE,YACA,2OACF,CACF,CACF;;;;;AAMA,MAAM,eAAe;;AAGrB,MAAM,UAAU;;AAGhB,SAAS,iBAAiB,OAAwB;CAChD,MAAM,SAAS,aAAa,KAAK,KAAK,CAAC,GAAG,EAAE,EAAE,YAAY;CAC1D,IAAI,CAAC,UAAU,OAAO,SAAS,GAAG,KAAK,WAAW,aAAa,OAAO;CACtE,OAAO,CAAC;EAAC;EAAQ;EAAS;CAAQ,CAAC,CAAC,SAAS,MAAM;AACrD;;AAGA,SAAS,mBACP,WAC4E;CAC5E,IAAI,cAAc,KAAA,GAAW,OAAO;CACpC,IAAI,cAAc,QAAQ,UAAU,KAAK,MAAM,IAAI,OAAO,EAAE,MAAM,KAAK;CACvE,MAAM,MAAM,iBAAiB,UAAU,KAAK,CAAC,IAAI,OAAO,iBAAiB,SAAS;CAClF,IAAI,CAAC,KACH,OAAO,EACL,OAAO,IAAI,UAAU,yEACvB;CAIF,MAAM,UAAU,IAAI,QAAQ,eAAe,WAAW,OAAO,YAAY,CAAC;CAG1E,OAAO,EAAE,MAAM;EAAE,MAAM;EAAO,OAD5B,QAAQ,WAAW,SAAS,KAAK,QAAQ,KAAK,OAAO,IAAI,UAAU,IAAI,IAAI,OAAO,CAAC,CAAC;CAClD,EAAE;AACxC;;AAGA,SAAgB,UAAU,OAAiB,IAAkC;CAC3E,MAAM,OAAO,MAAM,MAAM,QAAQ,EAAE;CACnC,OAAO,OAAO,qBAAqB,IAAI,IAAI,CAAC;AAC9C;AAEA,MAAa,UAAU,WAAW;CAChC,MAAM;CAEN,aAAa;CACb,WAAW;EAAE,MAAM;EAAQ,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,SAAS,KAAK,GAAG,sBAAsB;EAEjF,MAAM,YAAY,mBAAmB,KAAK,SAAS;EACnD,IAAI,aAAa,WAAW,WAAW,OAAO;EAC9C,MAAM,UAAoB,CAAC;EAC3B,IAAI,KAAK,qBAAqB,KAAA,GAAW;GACvC,KAAK,sBAAsB,KAAK;GAChC,QAAQ,KAAK,qBAAqB;EACpC;EACA,IAAI,KAAK,mBAAmB,KAAA,GAAW;GACrC,KAAK,oBAAoB,KAAK;GAC9B,QAAQ,KAAK,mBAAmB;EAClC;EACA,IAAI,KAAK,gBAAgB,KAAA,GAAW;GAClC,KAAK,iBAAiB,KAAK;GAC3B,QAAQ,KAAK,gBAAgB;EAC/B;EACA,IAAI,KAAK,cAAc,KAAA,GAAW;GAChC,IAAI,YAAY,KAAK,CAAC,CAAC,iBAAiB,MAAM,KAAK,SAAS;GAC5D,QAAQ,KAAK,eAAe;EAC9B;EACA,IAAI,KAAK,oBAAoB,KAAA,GAAW;GACtC,KAAK,iBAAiB,KAAK;GAC3B,QAAQ,KAAK,gBAAgB;EAC/B;EACA,IAAI,WAAW;GACb,IAAI;IACF,KAAK,YAAY,UAAU;GAC7B,SAAS,OAAO;IACd,OAAO,YAAY,KAAK;GAC1B;GACA,QAAQ,KAAK,WAAW;EAC1B;EACA,OAAO;GAAE,IAAI,KAAK;GAAI;EAAQ;CAChC;AACF,CAAC"}
1
+ {"version":3,"file":"text.js","names":[],"sources":["../../../src/tools/modify/text.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport type { Color } from '@pairdraw/scene-graph/primitives'\n\nimport type { FigmaAPI, FigmaNodeProxy } from '#core/figma-api'\nimport type { FigmaFontName, FigmaFontNameInput } from '#core/figma-api/fonts/names'\nimport type { FigmaVariationSettings } from '#core/figma-api/fonts/variations'\nimport { PairdrawAPI } from '#core/pairdraw-api'\nimport { normalizeLinkURL } from '#core/text/hyperlink'\nimport { collectNodeFontFaces } from '#core/text/requirements/collect'\nimport {\n parseOptionalToolColor,\n toolNumber,\n nodeIdInputSchema,\n defineTool,\n nodeNotFound,\n toolFailure\n} from '#core/tools/schema'\n\n/**\n * A link a text tool sets, as the editor's link field takes it: a web or mail address, with\n * `https:` or `mailto:` added when typed without a scheme. Null or blank removes the link.\n */\nconst hyperlinkInputSchema = v.optional(\n v.pipe(\n v.nullable(v.string()),\n v.description(\n 'Link the text opens: an http(s) or mailto address (\"example.com\" becomes https://example.com, \"hi@example.com\" becomes mailto:). null or \"\" removes the link. Links are not underlined automatically; set text_decoration for that.'\n )\n )\n)\n\n/**\n * A scheme at the start of a typed link, even with a digit after its colon (`tel:123`), unless it\n * reads as a host and port (`localhost:3000`, `example.com:8080`), which gets `https://`.\n */\nconst TYPED_SCHEME = /^([a-z][a-z\\d+.-]*):/i\n\n/** A web address in the form the Figma API's link setter takes: `http(s)://host…`. */\nconst WEB_URL = /^https?:\\/\\/[^\\s/?#]+\\S*$/\n\n/** Whether a typed link names a scheme other than the http, https, and mailto links take. */\nfunction hasForeignScheme(typed: string): boolean {\n const scheme = TYPED_SCHEME.exec(typed)?.[1]?.toLowerCase()\n if (!scheme || scheme.includes('.') || scheme === 'localhost') return false\n return !['http', 'https', 'mailto'].includes(scheme)\n}\n\n/** What setting `hyperlink` asks for: no change, a removal, a URL, or an address it refuses. */\nfunction requestedHyperlink(\n hyperlink: string | null | undefined\n): { link: { type: 'URL'; value: string } | null } | { error: string } | null {\n if (hyperlink === undefined) return null\n if (hyperlink === null || hyperlink.trim() === '') return { link: null }\n const url = hasForeignScheme(hyperlink.trim()) ? null : normalizeLinkURL(hyperlink)\n if (!url) {\n return {\n error: `\"${hyperlink}\" is not a link the editor opens: use an http, https, or mailto address`\n }\n }\n // Figma keeps schemes in lower case and web addresses as `scheme://host`, so a loosely typed\n // `http:example.com` is written as the URL it parses to.\n const lowered = url.replace(TYPED_SCHEME, (scheme) => scheme.toLowerCase())\n const value =\n lowered.startsWith('mailto:') || WEB_URL.test(lowered) ? lowered : new URL(lowered).href\n return { link: { type: 'URL', value } }\n}\n\n/** The fonts a text layer uses, which an edit that lays it out again needs loaded. */\nexport function textFonts(figma: FigmaAPI, id: string): FigmaFontNameInput[] {\n const node = figma.graph.getNode(id)\n return node ? collectNodeFontFaces(node) : []\n}\n\nexport const setText = defineTool({\n name: 'set_text',\n\n description: 'Set text content of a text node.',\n execution: { kind: 'sync', mutation: 'properties' },\n input: v.strictObject({\n id: nodeIdInputSchema,\n text: v.pipe(v.string(), v.description('Text content'))\n }),\n fonts: (figma, { id }) => textFonts(figma, id),\n execute: (figma, { id, text }) => {\n const node = figma.getNodeById(id)\n if (!node) return { error: `Node \"${id}\" not found` }\n node.characters = text\n return { id, text }\n }\n})\n\n/** Variable font axes a font tool can set, as Figma's `variationSettings`. */\n// An object with a value for every key rather than a record: a record publishes `propertyNames`,\n// which OpenAI refuses, and a JSON object's keys are strings anyway.\nconst variationsInputSchema = v.optional(\n v.pipe(\n v.objectWithRest({}, v.number()),\n v.description(\n 'Variable font axis values by OpenType tag (e.g. {\"wght\": 550, \"wdth\": 75}); axes left out keep the style\\'s values. Without a style, the nearest named style is picked.'\n )\n )\n)\n\n/**\n * The font a font tool gives text: what it names, the rest from `current`. Axes without a style\n * leave the style out, for the nearest named style to be picked.\n */\nfunction fontNameInput(\n args: { family?: string; style?: string; variations?: FigmaVariationSettings },\n current: FigmaFontName | null\n): FigmaFontNameInput {\n return {\n family: args.family ?? current?.family ?? '',\n style: args.style ?? (args.variations ? undefined : (current?.style ?? 'Regular')),\n variationSettings: args.variations\n }\n}\n\n/**\n * The font `set_font` gives the text, or null when it keeps the text's. Text set in several fonts\n * takes the given family or style for all of it, keeping the rest from its first character. Axes\n * without a style are set per range, each range taking its nearest named style, as in Figma.\n */\nfunction requestedFont(\n node: FigmaNodeProxy,\n args: { family?: string; style?: string; variations?: FigmaVariationSettings }\n): { whole: FigmaFontName } | { perRange: FigmaFontNameInput } | null {\n if (!args.family && !args.style && !args.variations) return null\n const fontName =\n typeof node.fontName === 'symbol' && node.characters.length > 0\n ? node.getRangeFontName(0, 1)\n : node.fontName\n const current = typeof fontName === 'symbol' ? null : fontName\n const family = args.family ?? current?.family ?? ''\n if (args.variations && !args.style && node.characters.length > 0) {\n return { perRange: { family, variationSettings: args.variations } }\n }\n const style = args.style ?? current?.style ?? 'Regular'\n return { whole: { family, style, variationSettings: args.variations } }\n}\n\nexport const setFont = defineTool({\n name: 'set_font',\n\n description: 'Set font properties of a text node.',\n execution: { kind: 'sync', mutation: 'properties' },\n input: v.strictObject({\n id: nodeIdInputSchema,\n family: v.optional(v.pipe(v.string(), v.description('Font family name'))),\n size: v.optional(toolNumber(v.pipe(v.number(), v.minValue(1), v.description('Font size')))),\n style: v.optional(\n v.pipe(v.string(), v.description('Font style (e.g. \"Bold\", \"Regular\", \"Bold Italic\")'))\n ),\n variations: variationsInputSchema\n }),\n // A new font replaces the text's, which then need not be loaded, so a missing font can be\n // replaced; a size or per-range axes lay out the text in its own fonts.\n fonts: (figma, args) => {\n const node = figma.getNodeById(args.id)\n const font = node && requestedFont(node, args)\n if (font && 'whole' in font) return [font.whole]\n return [...(font ? [font.perRange] : []), ...textFonts(figma, args.id)]\n },\n execute: (figma, args) => {\n const node = figma.getNodeById(args.id)\n if (!node) return nodeNotFound(args.id)\n const badTag = badVariationTag(args.variations)\n if (badTag) return badTag\n const font = requestedFont(node, args)\n try {\n if (font && 'whole' in font) node.fontName = font.whole\n else if (font) node.setRangeFontName(0, node.characters.length, font.perRange)\n // The size comes after the font, so it lays the text out in the font it ends up in.\n if (args.size !== undefined) node.fontSize = args.size\n } catch (error) {\n return toolFailure(error)\n }\n return { id: args.id, fontName: node.fontName, fontSize: node.fontSize }\n }\n})\n\n/** The font `set_font_range` gives its range: what it names, the rest from the range's start. */\nfunction rangeFont(\n node: FigmaNodeProxy,\n args: { start: number; family?: string; style?: string; variations?: FigmaVariationSettings }\n): FigmaFontNameInput {\n const inText = args.start < node.characters.length\n const current = inText ? node.getRangeFontName(args.start, args.start + 1) : node.fontName\n return fontNameInput(args, typeof current === 'symbol' ? null : current)\n}\n\ntype RangeEdit = {\n hyperlink: { link: { type: 'URL'; value: string } | null } | null\n color: Color | undefined\n}\n\n/** Why a variation setting cannot apply: an axis tag is not four letters. */\nfunction badVariationTag(variations: FigmaVariationSettings | undefined): { error: string } | null {\n const tag = Object.keys(variations ?? {}).find((key) => key.length !== 4)\n return tag === undefined ? null : { error: `\"${tag}\" is not a four-letter OpenType axis tag` }\n}\n\n/** What a range edit sets, or why it cannot run: nothing named, a bad colour, or a bad link. */\nfunction rangeEdit(args: {\n family?: string\n size?: number\n style?: string\n variations?: unknown\n color?: string\n hyperlink?: string | null\n}): RangeEdit | { error: string } {\n if (\n !args.family &&\n !args.size &&\n !args.style &&\n !args.variations &&\n !args.color &&\n args.hyperlink === undefined\n ) {\n return {\n error:\n 'set_font_range needs at least one of family, size, style, variations, color, or hyperlink'\n }\n }\n const hyperlink = requestedHyperlink(args.hyperlink)\n if (hyperlink && 'error' in hyperlink) return hyperlink\n const color = parseOptionalToolColor(args.color)\n if ('error' in color) return color\n return { hyperlink: hyperlink ?? null, color: color.color }\n}\n\nexport const setFontRange = defineTool({\n name: 'set_font_range',\n\n description: 'Set font properties, color, or a link for a text range.',\n execution: { kind: 'sync', mutation: 'properties' },\n input: v.strictObject({\n id: nodeIdInputSchema,\n start: toolNumber(v.pipe(v.number(), v.minValue(0), v.description('Start character index'))),\n end: toolNumber(v.pipe(v.number(), v.minValue(0), v.description('End character index'))),\n family: v.optional(v.pipe(v.string(), v.description('Font family name'))),\n size: v.optional(toolNumber(v.pipe(v.number(), v.minValue(1), v.description('Font size')))),\n style: v.optional(v.pipe(v.string(), v.description('Font style'))),\n variations: variationsInputSchema,\n color: v.optional(v.pipe(v.string(), v.description('Text color (hex)'))),\n hyperlink: hyperlinkInputSchema\n }),\n fonts: (figma, args) => {\n const node = figma.getNodeById(args.id)\n if (!node) return []\n const font = args.family || args.style || args.variations ? rangeFont(node, args) : null\n // A colour alone is a paint and lays nothing out, so text in a missing font can still take it.\n const laysOut = font !== null || args.size !== undefined\n return [...(font ? [font] : []), ...(laysOut ? textFonts(figma, args.id) : [])]\n },\n execute: (figma, args) => {\n const node = figma.getNodeById(args.id)\n if (!node) return nodeNotFound(args.id)\n const { start, end } = args\n const badTag = badVariationTag(args.variations)\n if (badTag) return badTag\n const edit = rangeEdit(args)\n if ('error' in edit) return edit\n const { hyperlink, color } = edit\n // The range methods reject an empty range or one past the text, before changing anything.\n try {\n if (args.size) node.setRangeFontSize(start, end, args.size)\n if (args.family || args.style || args.variations) {\n node.setRangeFontName(start, end, rangeFont(node, args))\n }\n if (color) node.setRangeFills(start, end, [{ type: 'SOLID', color }])\n if (hyperlink) node.setRangeHyperlink(start, end, hyperlink.link)\n } catch (error) {\n return toolFailure(error)\n }\n return {\n id: args.id,\n range: { start, end },\n ...(hyperlink ? { hyperlink: hyperlink.link?.value ?? null } : {})\n }\n }\n})\n\nexport const setTextResize = defineTool({\n name: 'set_text_resize',\n\n description: 'Set text auto-resize mode.',\n execution: { kind: 'sync', mutation: 'properties' },\n input: v.strictObject({\n id: nodeIdInputSchema,\n mode: v.pipe(\n v.picklist(['NONE', 'WIDTH_AND_HEIGHT', 'HEIGHT', 'TRUNCATE']),\n v.description('Resize mode')\n )\n }),\n fonts: (figma, { id }) => textFonts(figma, id),\n execute: (figma, { id, mode }) => {\n const node = figma.getNodeById(id)\n if (!node) return { error: `Node \"${id}\" not found` }\n node.textAutoResize = mode\n return { id, textAutoResize: mode }\n }\n})\n\nexport const setTextProperties = defineTool({\n name: 'set_text_properties',\n\n description:\n 'Set text layout properties: alignment, auto-resize, text case, decoration, truncation, and a link for the whole text.',\n execution: { kind: 'sync', mutation: 'properties' },\n input: v.strictObject({\n id: v.pipe(v.string(), v.description('Text node ID')),\n align_horizontal: v.optional(\n v.pipe(\n v.picklist(['LEFT', 'CENTER', 'RIGHT', 'JUSTIFIED']),\n v.description('Horizontal text alignment')\n )\n ),\n align_vertical: v.optional(\n v.pipe(v.picklist(['TOP', 'CENTER', 'BOTTOM']), v.description('Vertical text alignment'))\n ),\n auto_resize: v.optional(\n v.pipe(\n v.picklist(['NONE', 'WIDTH_AND_HEIGHT', 'HEIGHT', 'TRUNCATE']),\n v.description('Text auto-resize mode')\n )\n ),\n direction: v.optional(\n v.pipe(v.picklist(['AUTO', 'LTR', 'RTL']), v.description('Text direction'))\n ),\n text_decoration: v.optional(\n v.pipe(v.picklist(['NONE', 'UNDERLINE', 'STRIKETHROUGH']), v.description('Text decoration'))\n ),\n hyperlink: hyperlinkInputSchema\n }),\n fonts: (figma, { id }) => textFonts(figma, id),\n execute: (figma, args) => {\n const node = figma.getNodeById(args.id)\n if (!node) return nodeNotFound(args.id)\n if (node.type !== 'TEXT') return { error: `Node \"${args.id}\" is not a TEXT node` }\n // Refused before anything changes, so a bad address leaves the text as it was.\n const hyperlink = requestedHyperlink(args.hyperlink)\n if (hyperlink && 'error' in hyperlink) return hyperlink\n const updated: string[] = []\n if (args.align_horizontal !== undefined) {\n node.textAlignHorizontal = args.align_horizontal\n updated.push('textAlignHorizontal')\n }\n if (args.align_vertical !== undefined) {\n node.textAlignVertical = args.align_vertical\n updated.push('textAlignVertical')\n }\n if (args.auto_resize !== undefined) {\n node.textAutoResize = args.auto_resize\n updated.push('textAutoResize')\n }\n if (args.direction !== undefined) {\n new PairdrawAPI(figma).setTextDirection(node, args.direction)\n updated.push('textDirection')\n }\n if (args.text_decoration !== undefined) {\n node.textDecoration = args.text_decoration\n updated.push('textDecoration')\n }\n if (hyperlink) {\n try {\n node.hyperlink = hyperlink.link\n } catch (error) {\n return toolFailure(error)\n }\n updated.push('hyperlink')\n }\n return { id: args.id, updated }\n }\n})\n"],"mappings":";;;;;;;;;;AAuBA,MAAM,uBAAuB,EAAE,SAC7B,EAAE,KACA,EAAE,SAAS,EAAE,OAAO,CAAC,GACrB,EAAE,YACA,2OACF,CACF,CACF;;;;;AAMA,MAAM,eAAe;;AAGrB,MAAM,UAAU;;AAGhB,SAAS,iBAA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,UAAU,OAAO,EAAE;CAC7C,UAAU,OAAO,SAAS;EACxB,MAAM,OAAO,MAAM,YAAY,KAAK,EAAE;EACtC,IAAI,CAAC,MAAM,OAAO,aAAa,KAAK,EAAE;EACtC,IAAI,KAAK,SAAS,QAAQ,OAAO,EAAE,OAAO,SAAS,KAAK,GAAG,sBAAsB;EAEjF,MAAM,YAAY,mBAAmB,KAAK,SAAS;EACnD,IAAI,aAAa,WAAW,WAAW,OAAO;EAC9C,MAAM,UAAoB,CAAC;EAC3B,IAAI,KAAK,qBAAqB,KAAA,GAAW;GACvC,KAAK,sBAAsB,KAAK;GAChC,QAAQ,KAAK,qBAAqB;EACpC;EACA,IAAI,KAAK,mBAAmB,KAAA,GAAW;GACrC,KAAK,oBAAoB,KAAK;GAC9B,QAAQ,KAAK,mBAAmB;EAClC;EACA,IAAI,KAAK,gBAAgB,KAAA,GAAW;GAClC,KAAK,iBAAiB,KAAK;GAC3B,QAAQ,KAAK,gBAAgB;EAC/B;EACA,IAAI,KAAK,cAAc,KAAA,GAAW;GAChC,IAAI,YAAY,KAAK,CAAC,CAAC,iBAAiB,MAAM,KAAK,SAAS;GAC5D,QAAQ,KAAK,eAAe;EAC9B;EACA,IAAI,KAAK,oBAAoB,KAAA,GAAW;GACtC,KAAK,iBAAiB,KAAK;GAC3B,QAAQ,KAAK,gBAAgB;EAC/B;EACA,IAAI,WAAW;GACb,IAAI;IACF,KAAK,YAAY,UAAU;GAC7B,SAAS,OAAO;IACd,OAAO,YAAY,KAAK;GAC1B;GACA,QAAQ,KAAK,WAAW;EAC1B;EACA,OAAO;GAAE,IAAI,KAAK;GAAI;EAAQ;CAChC;AACF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"libraries.d.ts","names":[],"sources":["../../../src/tools/read/libraries.ts"],"mappings":";;cAKa,eAAA;cAaA,wBAAA"}
1
+ {"version":3,"file":"libraries.d.ts","names":[],"sources":["../../../src/tools/read/libraries.ts"],"mappings":";;cAca,eAAA;cA8BA,wBAAA"}
@@ -1,10 +1,12 @@
1
1
  import { defineTool, toolNumber } from "../schema.js";
2
2
  import { getComponentCatalog } from "../component-catalog.js";
3
+ import { groupBy, isPlainObject } from "es-toolkit";
3
4
  import * as v from "valibot";
4
5
  //#region src/tools/read/libraries.ts
6
+ const variantValuesSchema = v.pipe(v.string(), v.parseJson(), v.check(isPlainObject, "Expected a JSON object"), v.record(v.string(), v.string()));
5
7
  const listLibraries = defineTool({
6
8
  name: "list_libraries",
7
- description: "List available published component libraries.",
9
+ description: "List available published component libraries and each component asset key, name, and type. Pass a key to insert_library_component. A library does not have to be enabled to be listed.",
8
10
  execution: {
9
11
  kind: "async",
10
12
  mutation: "none"
@@ -13,10 +15,22 @@ const listLibraries = defineTool({
13
15
  input: v.strictObject({}),
14
16
  execute: async (figma) => {
15
17
  const catalog = getComponentCatalog(figma.graph);
16
- const libraries = catalog ? await catalog.listLibraries() : [];
18
+ if (!catalog) return {
19
+ count: 0,
20
+ libraries: []
21
+ };
22
+ const [libraries, components] = await Promise.all([catalog.listLibraries(), catalog.listComponents({ enabledOnly: false })]);
23
+ const byLibrary = groupBy(components, (component) => component.libraryId);
17
24
  return {
18
25
  count: libraries.length,
19
- libraries
26
+ libraries: libraries.map((library) => ({
27
+ ...library,
28
+ assets: (byLibrary[library.libraryId] ?? []).map((component) => ({
29
+ key: component.asset.key,
30
+ name: component.asset.name,
31
+ type: component.asset.type
32
+ }))
33
+ }))
20
34
  };
21
35
  }
22
36
  });
@@ -41,11 +55,9 @@ const insertLibraryComponent = defineTool({
41
55
  if (!catalog) throw new Error("No component library catalog is configured");
42
56
  let variantValues;
43
57
  if (args.variant_values) {
44
- const parsed = JSON.parse(args.variant_values);
45
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new TypeError("variant_values must be a JSON object");
46
- const entries = Object.entries(parsed);
47
- if (entries.some(([, value]) => typeof value !== "string")) throw new TypeError("variant_values values must be strings");
48
- variantValues = Object.fromEntries(entries);
58
+ const parsed = v.safeParse(variantValuesSchema, args.variant_values);
59
+ if (!parsed.success) throw new TypeError(`variant_values must be a JSON object of strings: ${v.summarize(parsed.issues)}`);
60
+ variantValues = parsed.output;
49
61
  }
50
62
  return catalog.insertComponent({
51
63
  libraryId: args.library_id,
@@ -1 +1 @@
1
- {"version":3,"file":"libraries.js","names":[],"sources":["../../../src/tools/read/libraries.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport { getComponentCatalog } from '#core/tools/component-catalog'\nimport { toolNumber, defineTool } from '#core/tools/schema'\n\nexport const listLibraries = defineTool({\n name: 'list_libraries',\n description: 'List available published component libraries.',\n execution: { kind: 'async', mutation: 'none' },\n exposure: { webmcp: false },\n input: v.strictObject({}),\n execute: async (figma) => {\n const catalog = getComponentCatalog(figma.graph)\n const libraries = catalog ? await catalog.listLibraries() : []\n return { count: libraries.length, libraries }\n }\n})\n\nexport const insertLibraryComponent = defineTool({\n name: 'insert_library_component',\n description:\n 'Insert a reusable component from an enabled library by stable library and asset identity.',\n\n execution: { kind: 'async', mutation: 'document' },\n input: v.strictObject({\n library_id: v.pipe(v.string(), v.description('Library ID')),\n revision_id: v.optional(v.pipe(v.string(), v.description('Pinned revision ID'))),\n asset_key: v.pipe(v.string(), v.description('Stable asset key')),\n parent_id: v.optional(v.pipe(v.string(), v.description('Optional parent node ID'))),\n x: v.optional(toolNumber(v.pipe(v.number(), v.description('X position')))),\n y: v.optional(toolNumber(v.pipe(v.number(), v.description('Y position')))),\n variant_values: v.optional(\n v.pipe(v.string(), v.description('Optional JSON object of variant property values'))\n )\n }),\n execute: async (figma, args) => {\n const catalog = getComponentCatalog(figma.graph)\n if (!catalog) throw new Error('No component library catalog is configured')\n let variantValues: Record<string, string> | undefined\n if (args.variant_values) {\n const parsed: unknown = JSON.parse(args.variant_values)\n if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {\n throw new TypeError('variant_values must be a JSON object')\n }\n const entries = Object.entries(parsed)\n if (entries.some(([, value]) => typeof value !== 'string')) {\n throw new TypeError('variant_values values must be strings')\n }\n variantValues = Object.fromEntries(entries)\n }\n return catalog.insertComponent({\n libraryId: args.library_id,\n revisionId: args.revision_id,\n assetKey: args.asset_key,\n parentId: args.parent_id,\n x: args.x,\n y: args.y,\n variantValues\n })\n }\n})\n"],"mappings":";;;;AAKA,MAAa,gBAAgB,WAAW;CACtC,MAAM;CACN,aAAa;CACb,WAAW;EAAE,MAAM;EAAS,UAAU;CAAO;CAC7C,UAAU,EAAE,QAAQ,MAAM;CAC1B,OAAO,EAAE,aAAa,CAAC,CAAC;CACxB,SAAS,OAAO,UAAU;EACxB,MAAM,UAAU,oBAAoB,MAAM,KAAK;EAC/C,MAAM,YAAY,UAAU,MAAM,QAAQ,cAAc,IAAI,CAAC;EAC7D,OAAO;GAAE,OAAO,UAAU;GAAQ;EAAU;CAC9C;AACF,CAAC;AAED,MAAa,yBAAyB,WAAW;CAC/C,MAAM;CACN,aACE;CAEF,WAAW;EAAE,MAAM;EAAS,UAAU;CAAW;CACjD,OAAO,EAAE,aAAa;EACpB,YAAY,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,YAAY,YAAY,CAAC;EAC1D,aAAa,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,YAAY,oBAAoB,CAAC,CAAC;EAC/E,WAAW,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,YAAY,kBAAkB,CAAC;EAC/D,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,YAAY,yBAAyB,CAAC,CAAC;EAClF,GAAG,EAAE,SAAS,WAAW,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,YAAY,YAAY,CAAC,CAAC,CAAC;EACzE,GAAG,EAAE,SAAS,WAAW,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,YAAY,YAAY,CAAC,CAAC,CAAC;EACzE,gBAAgB,EAAE,SAChB,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,YAAY,iDAAiD,CAAC,CACrF;CACF,CAAC;CACD,SAAS,OAAO,OAAO,SAAS;EAC9B,MAAM,UAAU,oBAAoB,MAAM,KAAK;EAC/C,IAAI,CAAC,SAAS,MAAM,IAAI,MAAM,4CAA4C;EAC1E,IAAI;EACJ,IAAI,KAAK,gBAAgB;GACvB,MAAM,SAAkB,KAAK,MAAM,KAAK,cAAc;GACtD,IAAI,CAAC,UAAU,OAAO,WAAW,YAAY,MAAM,QAAQ,MAAM,GAC/D,MAAM,IAAI,UAAU,sCAAsC;GAE5D,MAAM,UAAU,OAAO,QAAQ,MAAM;GACrC,IAAI,QAAQ,MAAM,GAAG,WAAW,OAAO,UAAU,QAAQ,GACvD,MAAM,IAAI,UAAU,uCAAuC;GAE7D,gBAAgB,OAAO,YAAY,OAAO;EAC5C;EACA,OAAO,QAAQ,gBAAgB;GAC7B,WAAW,KAAK;GAChB,YAAY,KAAK;GACjB,UAAU,KAAK;GACf,UAAU,KAAK;GACf,GAAG,KAAK;GACR,GAAG,KAAK;GACR;EACF,CAAC;CACH;AACF,CAAC"}
1
+ {"version":3,"file":"libraries.js","names":[],"sources":["../../../src/tools/read/libraries.ts"],"sourcesContent":["import { groupBy, isPlainObject } from 'es-toolkit'\nimport * as v from 'valibot'\n\nimport { getComponentCatalog } from '#core/tools/component-catalog'\nimport { toolNumber, defineTool } from '#core/tools/schema'\n\nconst variantValuesSchema = v.pipe(\n v.string(),\n v.parseJson(),\n // A record also takes an array, as its indices.\n v.check(isPlainObject, 'Expected a JSON object'),\n v.record(v.string(), v.string())\n)\n\nexport const listLibraries = defineTool({\n name: 'list_libraries',\n description:\n 'List available published component libraries and each component asset key, name, and type. Pass a key to insert_library_component. A library does not have to be enabled to be listed.',\n execution: { kind: 'async', mutation: 'none' },\n exposure: { webmcp: false },\n input: v.strictObject({}),\n execute: async (figma) => {\n const catalog = getComponentCatalog(figma.graph)\n if (!catalog) return { count: 0, libraries: [] }\n const [libraries, components] = await Promise.all([\n catalog.listLibraries(),\n // Enabled-only would hide the keys of a library the document has not turned on.\n catalog.listComponents({ enabledOnly: false })\n ])\n const byLibrary = groupBy(components, (component) => component.libraryId)\n return {\n count: libraries.length,\n libraries: libraries.map((library) => ({\n ...library,\n assets: (byLibrary[library.libraryId] ?? []).map((component) => ({\n key: component.asset.key,\n name: component.asset.name,\n type: component.asset.type\n }))\n }))\n }\n }\n})\n\nexport const insertLibraryComponent = defineTool({\n name: 'insert_library_component',\n description:\n 'Insert a reusable component from an enabled library by stable library and asset identity.',\n\n execution: { kind: 'async', mutation: 'document' },\n input: v.strictObject({\n library_id: v.pipe(v.string(), v.description('Library ID')),\n revision_id: v.optional(v.pipe(v.string(), v.description('Pinned revision ID'))),\n asset_key: v.pipe(v.string(), v.description('Stable asset key')),\n parent_id: v.optional(v.pipe(v.string(), v.description('Optional parent node ID'))),\n x: v.optional(toolNumber(v.pipe(v.number(), v.description('X position')))),\n y: v.optional(toolNumber(v.pipe(v.number(), v.description('Y position')))),\n variant_values: v.optional(\n v.pipe(v.string(), v.description('Optional JSON object of variant property values'))\n )\n }),\n execute: async (figma, args) => {\n const catalog = getComponentCatalog(figma.graph)\n if (!catalog) throw new Error('No component library catalog is configured')\n let variantValues: Record<string, string> | undefined\n if (args.variant_values) {\n const parsed = v.safeParse(variantValuesSchema, args.variant_values)\n if (!parsed.success) {\n throw new TypeError(\n `variant_values must be a JSON object of strings: ${v.summarize(parsed.issues)}`\n )\n }\n variantValues = parsed.output\n }\n return catalog.insertComponent({\n libraryId: args.library_id,\n revisionId: args.revision_id,\n assetKey: args.asset_key,\n parentId: args.parent_id,\n x: args.x,\n y: args.y,\n variantValues\n })\n }\n})\n"],"mappings":";;;;;AAMA,MAAM,sBAAsB,EAAE,KAC5B,EAAE,OAAO,GACT,EAAE,UAAU,GAEZ,EAAE,MAAM,eAAe,wBAAwB,GAC/C,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC,CACjC;AAEA,MAAa,gBAAgB,WAAW;CACtC,MAAM;CACN,aACE;CACF,W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AAO,GAAG,EAAE,YAAY,YAAY,CAAC,CAAC,CAAC;EACzE,gBAAgB,EAAE,SAChB,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,YAAY,iDAAiD,CAAC,CACrF;CACF,CAAC;CACD,SAAS,OAAO,OAAO,SAAS;EAC9B,MAAM,UAAU,oBAAoB,MAAM,KAAK;EAC/C,IAAI,CAAC,SAAS,MAAM,IAAI,MAAM,4CAA4C;EAC1E,IAAI;EACJ,IAAI,KAAK,gBAAgB;GACvB,MAAM,SAAS,EAAE,UAAU,qBAAqB,KAAK,cAAc;GACnE,IAAI,CAAC,OAAO,SACV,MAAM,IAAI,UACR,oDAAoD,EAAE,UAAU,OAAO,MAAM,GAC/E;GAEF,gBAAgB,OAAO;EACzB;EACA,OAAO,QAAQ,gBAAgB;GAC7B,WAAW,KAAK;GAChB,YAAY,KAAK;GACjB,UAAU,KAAK;GACf,UAAU,KAAK;GACf,GAAG,KAAK;GACR,GAAG,KAAK;GACR;EACF,CAAC;CACH;AACF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"pages.d.ts","names":[],"sources":["../../../src/tools/read/pages.ts"],"mappings":";;cAMa,WAAA;cAcA,YAAA;cAiBA,gBAAA;cAUA,YAAA"}
1
+ {"version":3,"file":"pages.d.ts","names":[],"sources":["../../../src/tools/read/pages.ts"],"mappings":";;cAMa,WAAA;cAcA,YAAA;cAkBA,gBAAA;cAUA,YAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"pages.js","names":[],"sources":["../../../src/tools/read/pages.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport { computeBounds } from '@pairdraw/scene-graph/geometry'\n\nimport { defineTool } from '#core/tools/schema'\n\nexport const listPages = defineTool({\n name: 'list_pages',\n description: 'List all pages in the document.',\n execution: { kind: 'sync', mutation: 'none' },\n input: v.strictObject({}),\n execute: (figma) => {\n const pages = figma.root.children\n return {\n current: figma.currentPage.name,\n pages: pages.map((page) => ({ id: page.id, name: page.name }))\n }\n }\n})\n\nexport const switchPage = defineTool({\n name: 'switch_page',\n\n description: 'Switch to a different page by name or ID.',\n execution: { kind: 'sync', mutation: 'view' },\n input: v.strictObject({\n page: v.pipe(v.string(), v.description('Page name or ID'))\n }),\n execute: (figma, { page }) => {\n const target =\n figma.root.children.find((candidate) => candidate.name === page) ?? figma.getNodeById(page)\n if (!target) return { error: `Page \"${page}\" not found` }\n figma.currentPage = target\n return { page: target.name, id: target.id }\n }\n})\n\nexport const getCurrentPage = defineTool({\n name: 'get_current_page',\n description: 'Get the current page name and ID.',\n execution: { kind: 'sync', mutation: 'none' },\n input: v.strictObject({}),\n execute: (figma) => {\n return { id: figma.currentPage.id, name: figma.currentPage.name }\n }\n})\n\nexport const pageBounds = defineTool({\n name: 'page_bounds',\n description: 'Get bounding box of all objects on the current page.',\n execution: { kind: 'sync', mutation: 'none' },\n exposure: { webmcp: false },\n input: v.strictObject({}),\n execute: (figma) => {\n return computeBounds(figma.currentPage.children.map((child) => child.absoluteBoundingBox))\n }\n})\n"],"mappings":";;;;AAMA,MAAa,YAAY,WAAW;CAClC,MAAM;CACN,aAAa;CACb,WAAW;EAAE,MAAM;EAAQ,UAAU;CAAO;CAC5C,OAAO,EAAE,aAAa,CAAC,CAAC;CACxB,UAAU,UAAU;EAClB,MAAM,QAAQ,MAAM,KAAK;EACzB,OAAO;GACL,SAAS,MAAM,YAAY;GAC3B,OAAO,MAAM,KAAK,UAAU;IAAE,IAAI,KAAK;IAAI,MAAM,KAAK;GAAK,EAAE;EAC/D;CACF;AACF,CAAC;AAED,MAAa,aAAa,WAAW;CACnC,MAAM;CAEN,aAAa;CACb,WAAW;EAAE,MAAM;EAAQ,UAAU;CAAO;CAC5C,OAAO,EAAE,aAAa,EACpB,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,YAAY,iBAAiB,CAAC,EAC3D,CAAC;CACD,UAAU,OAAO,EAAE,WAAW;EAC5B,MAAM,SACJ,MAAM,KAAK,SAAS,MAAM,cAAc,UAAU,SAAS,IAAI,KAAK,MAAM,YAAY,IAAI;EAC5F,IAAI,CAAC,QAAQ,OAAO,EAAE,OAAO,SAAS,KAAK,aAAa;EACxD,MAAM,cAAc;EACpB,OAAO;GAAE,MAAM,OAAO;GAAM,IAAI,OAAO;EAAG;CAC5C;AACF,CAAC;AAED,MAAa,iBAAiB,WAAW;CACvC,MAAM;CACN,aAAa;CACb,WAAW;EAAE,MAAM;EAAQ,UAAU;CAAO;CAC5C,OAAO,EAAE,aAAa,CAAC,CAAC;CACxB,UAAU,UAAU;EAClB,OAAO;GAAE,IAAI,MAAM,YAAY;GAAI,MAAM,MAAM,YAAY;EAAK;CAClE;AACF,CAAC;AAED,MAAa,aAAa,WAAW;CACnC,MAAM;CACN,aAAa;CACb,WAAW;EAAE,MAAM;EAAQ,UAAU;CAAO;CAC5C,UAAU,EAAE,QAAQ,MAAM;CAC1B,OAAO,EAAE,aAAa,CAAC,CAAC;CACxB,UAAU,UAAU;EAClB,OAAO,cAAc,MAAM,YAAY,SAAS,KAAK,UAAU,MAAM,mBAAmB,CAAC;CAC3F;AACF,CAAC"}
1
+ {"version":3,"file":"pages.js","names":[],"sources":["../../../src/tools/read/pages.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport { computeBounds } from '@pairdraw/scene-graph/geometry'\n\nimport { defineTool } from '#core/tools/schema'\n\nexport const listPages = defineTool({\n name: 'list_pages',\n description: 'List all pages in the document.',\n execution: { kind: 'sync', mutation: 'none' },\n input: v.strictObject({}),\n execute: (figma) => {\n const pages = figma.root.children\n return {\n current: figma.currentPage.name,\n pages: pages.map((page) => ({ id: page.id, name: page.name }))\n }\n }\n})\n\nexport const switchPage = defineTool({\n name: 'switch_page',\n\n description: 'Switch to a different page by name or ID.',\n execution: { kind: 'sync', mutation: 'view' },\n input: v.strictObject({\n page: v.pipe(v.string(), v.description('Page name or ID'))\n }),\n execute: (figma, { page }) => {\n const target =\n figma.root.children.find((candidate) => candidate.name === page) ?? figma.getNodeById(page)\n if (!target) return { error: `Page \"${page}\" not found` }\n // The host shows the page from here, and reads it back on the next call.\n figma.currentPage = target\n return { page: target.name, id: target.id }\n }\n})\n\nexport const getCurrentPage = defineTool({\n name: 'get_current_page',\n description: 'Get the current page name and ID.',\n execution: { kind: 'sync', mutation: 'none' },\n input: v.strictObject({}),\n execute: (figma) => {\n return { id: figma.currentPage.id, name: figma.currentPage.name }\n }\n})\n\nexport const pageBounds = defineTool({\n name: 'page_bounds',\n description: 'Get bounding box of all objects on the current page.',\n execution: { kind: 'sync', mutation: 'none' },\n exposure: { webmcp: false },\n input: v.strictObject({}),\n execute: (figma) => {\n return computeBounds(figma.currentPage.children.map((child) => child.absoluteBoundingBox))\n }\n})\n"],"mappings":";;;;AAMA,MAAa,YAAY,WAAW;CAClC,MAAM;CACN,aAAa;CACb,WAAW;EAAE,MAAM;EAAQ,UAAU;CAAO;CAC5C,OAAO,EAAE,aAAa,CAAC,CAAC;CACxB,UAAU,UAAU;EAClB,MAAM,QAAQ,MAAM,KAAK;EACzB,OAAO;GACL,SAAS,MAAM,YAAY;GAC3B,OAAO,MAAM,KAAK,UAAU;IAAE,IAAI,KAAK;IAAI,MAAM,KAAK;GAAK,EAAE;EAC/D;CACF;AACF,CAAC;AAED,MAAa,aAAa,WAAW;CACnC,MAAM;CAEN,aAAa;CACb,WAAW;EAAE,MAAM;EAAQ,UAAU;CAAO;CAC5C,OAAO,EAAE,aAAa,EACpB,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,YAAY,iBAAiB,CAAC,EAC3D,CAAC;CACD,UAAU,OAAO,EAAE,WAAW;EAC5B,MAAM,SACJ,MAAM,KAAK,SAAS,MAAM,cAAc,UAAU,SAAS,IAAI,KAAK,MAAM,YAAY,IAAI;EAC5F,IAAI,CAAC,QAAQ,OAAO,EAAE,OAAO,SAAS,KAAK,aAAa;EAExD,MAAM,cAAc;EACpB,OAAO;GAAE,MAAM,OAAO;GAAM,IAAI,OAAO;EAAG;CAC5C;AACF,CAAC;AAED,MAAa,iBAAiB,WAAW;CACvC,MAAM;CACN,aAAa;CACb,WAAW;EAAE,MAAM;EAAQ,UAAU;CAAO;CAC5C,OAAO,EAAE,aAAa,CAAC,CAAC;CACxB,UAAU,UAAU;EAClB,OAAO;GAAE,IAAI,MAAM,YAAY;GAAI,MAAM,MAAM,YAAY;EAAK;CAClE;AACF,CAAC;AAED,MAAa,aAAa,WAAW;CACnC,MAAM;CACN,aAAa;CACb,WAAW;EAAE,MAAM;EAAQ,UAAU;CAAO;CAC5C,UAAU,EAAE,QAAQ,MAAM;CAC1B,OAAO,EAAE,aAAa,CAAC,CAAC;CACxB,UAAU,UAAU;EAClB,OAAO,cAAc,MAAM,YAAY,SAAS,KAAK,UAAU,MAAM,mBAAmB,CAAC;CAC3F;AACF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"extended.d.ts","names":[],"sources":["../../../src/tools/registry/extended.ts"],"mappings":";;;;;;cAiIa,gBAAgB"}
1
+ {"version":3,"file":"extended.d.ts","names":[],"sources":["../../../src/tools/registry/extended.ts"],"mappings":";;;;;;cAkIa,gBAAgB"}
@@ -11,7 +11,7 @@ import { designToComponentMap } from "../codegen/component-map.js";
11
11
  import { addComment, getComments, replyToComment, resolveComment } from "../comments.js";
12
12
  import { createPage, createShape, createSlice } from "../create/basic.js";
13
13
  import { createSlot, getBehaviour, setBehaviour } from "../create/behaviours.js";
14
- import { combineAsVariants, createComponent, createInstance, exposeInstanceSwap } from "../create/components.js";
14
+ import { combineAsVariants, createComponent, createInstance, detachInstance, exposeInstanceSwap } from "../create/components.js";
15
15
  import { fetchIconsTool, insertIcon, searchIconsTool } from "../create/icons.js";
16
16
  import { script } from "../create/script.js";
17
17
  import { importMermaid } from "../create/mermaid.js";
@@ -86,6 +86,7 @@ const EXTENDED_TOOLS = [
86
86
  combineAsVariants,
87
87
  createComponent,
88
88
  createInstance,
89
+ detachInstance,
89
90
  exposeInstanceSwap,
90
91
  createSlot,
91
92
  getBehaviour,
@@ -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 { designToComponentMap, designToTokens, importDesignTokens } 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 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 generateImage,\n generateSVG,\n removeBackground,\n replaceBackground\n} from '#core/tools/image-ai'\nimport {\n setBlend,\n setConstraints,\n setEffects,\n setFont,\n setFontRange,\n setImageFill,\n setLocked,\n setMinMax,\n replaceMatchingProperties,\n rescale,\n setOpacity,\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 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 flattenNodes,\n groupNodes,\n nodeAncestors,\n nodeBindings,\n nodeBounds,\n nodeChildren,\n nodeMove,\n nodeReplaceWith,\n nodeToComponent,\n nodeTree,\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 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 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 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 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 setOpacity,\n setFont,\n setVisible,\n setConstraints,\n setRotation,\n setMinMax,\n setFontRange,\n setTextResize,\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 // 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 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 designToComponentMap\n]\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiIA,MAAa,iBAA4B;CAEvC;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;CAEA;CACA;CACA;CACA;CAEA;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;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;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CAEA;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 { designToComponentMap, designToTokens, importDesignTokens } 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 generateImage,\n generateSVG,\n removeBackground,\n replaceBackground\n} from '#core/tools/image-ai'\nimport {\n setBlend,\n setConstraints,\n setEffects,\n setFont,\n setFontRange,\n setImageFill,\n setLocked,\n setMinMax,\n replaceMatchingProperties,\n rescale,\n setOpacity,\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 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 flattenNodes,\n groupNodes,\n nodeAncestors,\n nodeBindings,\n nodeBounds,\n nodeChildren,\n nodeMove,\n nodeReplaceWith,\n nodeToComponent,\n nodeTree,\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 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 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 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 setOpacity,\n setFont,\n setVisible,\n setConstraints,\n setRotation,\n setMinMax,\n setFontRange,\n setTextResize,\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 // 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 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 designToComponentMap\n]\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkIA,MAAa,iBAA4B;CAEvC;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;CAEA;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;CAEA;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;AACF"}
@@ -3,6 +3,7 @@ import { FigmaNodeProxy } from "../figma-api/proxy.js";
3
3
  import { FigmaAPI } from "../figma-api/index.js";
4
4
  import { SceneNode } from "@pairdraw/scene-graph";
5
5
  import * as v from "valibot";
6
+ import { Color } from "@pairdraw/scene-graph/primitives";
6
7
  //#region src/tools/schema.d.ts
7
8
  type ToolCapability = 'document:read' | 'document:write' | 'filesystem:read' | 'filesystem:write' | 'network:access' | 'code:execute' | 'settings:read' | 'settings:write';
8
9
  type ToolExecution = {
@@ -46,10 +47,11 @@ declare function defineTool<P extends v.ObjectEntries, R>(def: ToolDefinitionMet
46
47
  execute: (figma: FigmaAPI, args: v.InferOutput<v.StrictObjectSchema<P, undefined>>) => R;
47
48
  }): ToolDef;
48
49
  /**
49
- * Every tool run goes through here, so a wrong call from AI chat, the CLI, or WebMCP names the
50
- * tool and lists each problem with its argument, as `v.summarize` formats them. MCP clients get
51
- * the MCP SDK's own report, which validates the same schema before the handler runs. Inputs are
52
- * strict objects, so a misspelled or mis-nested argument fails here instead of being dropped.
50
+ * Every tool run goes through here, so a wrong call from AI chat, the CLI, WebMCP, and MCP names
51
+ * the tool and lists each problem with its argument. An unknown or missing argument names the
52
+ * arguments the tool takes, and a picklist names the values it accepts, read from the schema, so
53
+ * the caller does not have to guess. Inputs are strict objects, so a misspelled or mis-nested
54
+ * argument fails here instead of being dropped.
53
55
  */
54
56
  declare function parseToolArgs<S extends v.GenericSchema>(name: string, schema: S, args: unknown): v.InferOutput<S>;
55
57
  declare function toolChangesDocument(def: Pick<ToolDef, 'execution'>): boolean;
@@ -78,6 +80,23 @@ declare function nodeSummary(node: FigmaNodeProxy): {
78
80
  name: string;
79
81
  type: string;
80
82
  };
83
+ /**
84
+ * A tool colour, refusing text that would otherwise land as black: `set_fill { color: "#GGG" }`
85
+ * used to paint black and report success. Read through `tryParseColor`, since a published schema
86
+ * cannot express what the parser accepts.
87
+ */
88
+ declare function parseToolColor(value: string): Color | {
89
+ error: string;
90
+ };
91
+ /**
92
+ * A colour the caller may leave out. Missing stays missing; text that is not a colour is the
93
+ * same refusal `parseToolColor` gives, so each tool does not repeat that check.
94
+ */
95
+ declare function parseOptionalToolColor(value: string | undefined): {
96
+ color: Color | undefined;
97
+ } | {
98
+ error: string;
99
+ };
81
100
  declare const nodeIdInputSchema: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.DescriptionAction<string, "Node ID">]>;
82
101
  declare const nodeInputSchema: v.StrictObjectSchema<{
83
102
  readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.DescriptionAction<string, "Node ID">]>;
@@ -97,5 +116,5 @@ declare const positionInputs: {
97
116
  /** Reuse a native number schema for both numeric and numeric-string agent inputs. */
98
117
  declare function toolNumber(schema?: v.GenericSchema<number, number>): v.UnionSchema<[v.SchemaWithPipe<readonly [v.GenericSchema<number, number>, v.MinValueAction<number, number, undefined>, v.MaxValueAction<number, number, undefined>]>, v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "Expected a nonblank numeric string">, v.DescriptionAction<string, string>, v.TransformAction<any, number>, v.SchemaWithPipe<readonly [v.GenericSchema<number, number>, v.MinValueAction<number, number, undefined>, v.MaxValueAction<number, number, undefined>]>]>], undefined>;
99
118
  //#endregion
100
- export { NodeNotFoundError, ToolCapability, ToolDef, ToolExecution, ToolExposure, ToolInterface, defineTool, getRawNodeOrError, isAtomicTool, isToolExposed, nodeComparisonInputSchema, nodeIdInputSchema, nodeInputSchema, nodeNotFound, nodeSummary, nodeToResult, nodeTraversalInput, parseToolArgs, positionInputs, requireNode, requireNodes, toolChangesDocument, toolFailure, toolNumber };
119
+ export { NodeNotFoundError, ToolCapability, ToolDef, ToolExecution, ToolExposure, ToolInterface, defineTool, getRawNodeOrError, isAtomicTool, isToolExposed, nodeComparisonInputSchema, nodeIdInputSchema, nodeInputSchema, nodeNotFound, nodeSummary, nodeToResult, nodeTraversalInput, parseOptionalToolColor, parseToolArgs, parseToolColor, positionInputs, requireNode, requireNodes, toolChangesDocument, toolFailure, toolNumber };
101
120
  //# sourceMappingURL=schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","names":[],"sources":["../../src/tools/schema.ts"],"mappings":";;;;;;KAcY;KAUA;EACN;EAAc;;EACd;EAAe;;KAET;KACA,eAAe,QAAQ,OAAO;UAEhC;EACR;EACA;EACA,WAAW;;EAEX,UAAU;EACV,uBAAuB;EACvB;;UAGe,gBAAgB;EAC/B,OAAO,EAAE,mBAAmB,EAAE;;WAErB;;;;;;EAMT,YAAY,OAAO,UAAU,MAAM,4BAA4B;EAC/D,UAAU,OAAO,UAAU,MAAM;;KAG9B,yBAAyB,KAAK,8DACjC,QAAQ,KAA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,EAAA,yBAAA,EAAA,+BAAA,EAAA,2CAAA,EAAA"}
@@ -1,3 +1,4 @@
1
+ import { tryParseColor } from "@pairdraw/scene-graph/color";
1
2
  import * as v from "valibot";
2
3
  //#region src/tools/schema.ts
3
4
  /**
@@ -26,15 +27,70 @@ function defineTool(def) {
26
27
  };
27
28
  }
28
29
  /**
29
- * Every tool run goes through here, so a wrong call from AI chat, the CLI, or WebMCP names the
30
- * tool and lists each problem with its argument, as `v.summarize` formats them. MCP clients get
31
- * the MCP SDK's own report, which validates the same schema before the handler runs. Inputs are
32
- * strict objects, so a misspelled or mis-nested argument fails here instead of being dropped.
30
+ * Every tool run goes through here, so a wrong call from AI chat, the CLI, WebMCP, and MCP names
31
+ * the tool and lists each problem with its argument. An unknown or missing argument names the
32
+ * arguments the tool takes, and a picklist names the values it accepts, read from the schema, so
33
+ * the caller does not have to guess. Inputs are strict objects, so a misspelled or mis-nested
34
+ * argument fails here instead of being dropped.
33
35
  */
34
36
  function parseToolArgs(name, schema, args) {
35
37
  const result = v.safeParse(schema, args);
36
38
  if (result.success) return result.output;
37
- throw new Error(`Invalid arguments for ${name}:\n${v.summarize(result.issues)}`);
39
+ throw new Error(formatToolArgumentError(name, schema, result.issues));
40
+ }
41
+ /** One refusal for every surface: the tool, then each problem with where it is. */
42
+ function formatToolArgumentError(name, schema, issues) {
43
+ return `Invalid arguments for ${name}:\n${issues.map((issue) => {
44
+ const keys = issueKeys(issue);
45
+ const place = keys.length > 0 ? `\n → at ${keys.join(".")}` : "";
46
+ return `× ${formatToolArgIssue(schema, issue)}${place}`;
47
+ }).join("\n")}`;
48
+ }
49
+ function schemaParts(schema) {
50
+ return typeof schema === "object" && schema !== null ? schema : {};
51
+ }
52
+ /** The schema a wrapper such as `optional` or `pipe` holds, down to the one with the rules. */
53
+ function unwrappedSchema(schema) {
54
+ let current = schema;
55
+ for (;;) {
56
+ const wrapped = schemaParts(current).wrapped;
57
+ if (!wrapped) return current;
58
+ current = wrapped;
59
+ }
60
+ }
61
+ function issueKeys(issue) {
62
+ return (issue.path ?? []).flatMap((item) => "key" in item ? [String(item.key)] : []);
63
+ }
64
+ function schemaAtPath(root, keys) {
65
+ let current = unwrappedSchema(root);
66
+ for (const key of keys) {
67
+ const parts = schemaParts(current);
68
+ const next = parts.entries && key in parts.entries ? parts.entries[key] : parts.item;
69
+ if (!next) return null;
70
+ current = unwrappedSchema(next);
71
+ }
72
+ return current;
73
+ }
74
+ function formatToolArgIssue(schema, issue) {
75
+ const keys = issueKeys(issue);
76
+ const key = keys.at(-1);
77
+ if (key !== void 0 && (issue.type === "object" || issue.type === "strict_object")) {
78
+ if (issue.expected === "never") {
79
+ const parent = schemaAtPath(schema, keys.slice(0, -1));
80
+ const accepted = parent ? Object.keys(schemaParts(parent).entries ?? {}) : [];
81
+ return accepted.length > 0 ? `Unknown argument "${key}". Accepted: ${accepted.join(", ")}` : `Unknown argument "${key}"`;
82
+ }
83
+ if (issue.received === "undefined") return `Missing required argument "${key}"`;
84
+ }
85
+ if (issue.type === "picklist" && key !== void 0) {
86
+ const resolved = schemaAtPath(schema, keys);
87
+ const options = resolved ? schemaParts(resolved).options : void 0;
88
+ if (options && options.length > 0) {
89
+ const accepted = options.map((option) => JSON.stringify(option)).join(", ");
90
+ return `Invalid value ${issue.received} for argument "${key}". Accepted: ${accepted}`;
91
+ }
92
+ }
93
+ return issue.message;
38
94
  }
39
95
  function toolChangesDocument(def) {
40
96
  return def.execution.mutation === "properties" || def.execution.mutation === "document";
@@ -86,6 +142,24 @@ function nodeSummary(node) {
86
142
  type: node.type
87
143
  };
88
144
  }
145
+ /**
146
+ * A tool colour, refusing text that would otherwise land as black: `set_fill { color: "#GGG" }`
147
+ * used to paint black and report success. Read through `tryParseColor`, since a published schema
148
+ * cannot express what the parser accepts.
149
+ */
150
+ function parseToolColor(value) {
151
+ return tryParseColor(value) ?? { error: `"${value}" is not a color; use a hex value, a color name, or a color function` };
152
+ }
153
+ /**
154
+ * A colour the caller may leave out. Missing stays missing; text that is not a colour is the
155
+ * same refusal `parseToolColor` gives, so each tool does not repeat that check.
156
+ */
157
+ function parseOptionalToolColor(value) {
158
+ if (value === void 0) return { color: void 0 };
159
+ const parsed = parseToolColor(value);
160
+ if ("error" in parsed) return parsed;
161
+ return { color: parsed };
162
+ }
89
163
  const nodeIdInputSchema = v.pipe(v.string(), v.description("Node ID"));
90
164
  const nodeInputSchema = v.strictObject({ id: nodeIdInputSchema });
91
165
  const nodeComparisonInputSchema = v.strictObject({
@@ -108,6 +182,6 @@ function toolNumber(schema = v.number()) {
108
182
  return v.union([finite, v.pipe(v.string(), v.regex(/\S/, "Expected a nonblank numeric string"), v.description(v.getDescription(schema) ?? "Numeric value"), v.transform(Number), finite)]);
109
183
  }
110
184
  //#endregion
111
- export { NodeNotFoundError, defineTool, getRawNodeOrError, isAtomicTool, isToolExposed, nodeComparisonInputSchema, nodeIdInputSchema, nodeInputSchema, nodeNotFound, nodeSummary, nodeToResult, nodeTraversalInput, parseToolArgs, positionInputs, requireNode, requireNodes, toolChangesDocument, toolFailure, toolNumber };
185
+ export { NodeNotFoundError, defineTool, getRawNodeOrError, isAtomicTool, isToolExposed, nodeComparisonInputSchema, nodeIdInputSchema, nodeInputSchema, nodeNotFound, nodeSummary, nodeToResult, nodeTraversalInput, parseOptionalToolColor, parseToolArgs, parseToolColor, positionInputs, requireNode, requireNodes, toolChangesDocument, toolFailure, toolNumber };
112
186
 
113
187
  //# sourceMappingURL=schema.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","names":[],"sources":["../../src/tools/schema.ts"],"sourcesContent":["/**\n * Tool definition schema.\n *\n * Native Valibot inputs and execution capabilities are owned by each tool.\n * Adapters consume these contracts rather than maintaining transport-specific schemas.\n */\n\nimport * as v from 'valibot'\n\nimport type { SceneNode } from '@pairdraw/scene-graph'\n\nimport type { FigmaAPI, FigmaNodeProxy } from '#core/figma-api'\nimport type { FigmaFontNameInput } from '#core/figma-api/fonts/names'\n\nexport type ToolCapability =\n | 'document:read'\n | 'document:write'\n | 'filesystem:read'\n | 'filesystem:write'\n | 'network:access'\n | 'code:execute'\n | 'settings:read'\n | 'settings:write'\n\nexport type ToolExecution =\n | { kind: 'sync'; mutation: 'none' | 'view' | 'properties' | 'document' }\n | { kind: 'async'; mutation: 'none' | 'view' | 'document' }\n\nexport type ToolInterface = 'mcp' | 'ai' | 'webmcp'\nexport type ToolExposure = Partial<Record<ToolInterface, boolean>>\n\ninterface ToolMetadata {\n name: string\n description: string\n execution: ToolExecution\n /** Interface inclusion defaults to true; execution support and user permissions remain separate. */\n exposure: ToolExposure\n capabilities: readonly ToolCapability[]\n availability: 'default' | 'eval'\n}\n\nexport interface ToolDef extends ToolMetadata {\n input: v.StrictObjectSchema<v.ObjectEntries, undefined>\n /** Derived from execution metadata, never declared independently by a tool. */\n readonly mutates: boolean\n /**\n * Loads the fonts the call's text edits need, as a Figma plugin loads them before it edits\n * text; rejects when one cannot load. Every executor awaits it before `execute`, so a\n * synchronous tool still edits in one step.\n */\n loadFonts: (figma: FigmaAPI, args: Record<string, unknown>) => Promise<void>\n execute: (figma: FigmaAPI, args: Record<string, unknown>) => unknown\n}\n\ntype ToolDefinitionMetadata = Omit<ToolMetadata, 'exposure' | 'capabilities' | 'availability'> &\n Partial<Pick<ToolMetadata, 'exposure' | 'capabilities' | 'availability'>>\n\nexport function defineTool<P extends v.ObjectEntries, R>(\n def: ToolDefinitionMetadata & {\n input: v.StrictObjectSchema<P, undefined>\n execution: ToolExecution & (R extends PromiseLike<unknown> ? { kind: 'async' } : unknown)\n /** The fonts a call's text edits need loaded first; text edits refuse unloaded fonts. */\n fonts?: (\n figma: FigmaAPI,\n args: v.InferOutput<v.StrictObjectSchema<P, undefined>>\n ) => FigmaFontNameInput[]\n execute: (figma: FigmaAPI, args: v.InferOutput<v.StrictObjectSchema<P, undefined>>) => R\n }\n): ToolDef {\n const { fonts } = def\n return {\n ...def,\n exposure: def.exposure ?? {},\n capabilities: def.capabilities ?? [\n toolChangesDocument(def) ? 'document:write' : 'document:read'\n ],\n availability: def.availability ?? 'default',\n get mutates() {\n return def.execution.mutation !== 'none'\n },\n async loadFonts(figma, args) {\n if (!fonts) return\n // Wrong arguments are for `execute` to report.\n const parsed = v.safeParse(def.input, args)\n if (!parsed.success) return\n for (const font of fonts(figma, parsed.output)) await figma.loadFontAsync(font)\n },\n execute: (figma, args) => def.execute(figma, parseToolArgs(def.name, def.input, args))\n }\n}\n\n/**\n * Every tool run goes through here, so a wrong call from AI chat, the CLI, or WebMCP names the\n * tool and lists each problem with its argument, as `v.summarize` formats them. MCP clients get\n * the MCP SDK's own report, which validates the same schema before the handler runs. Inputs are\n * strict objects, so a misspelled or mis-nested argument fails here instead of being dropped.\n */\nexport function parseToolArgs<S extends v.GenericSchema>(\n name: string,\n schema: S,\n args: unknown\n): v.InferOutput<S> {\n const result = v.safeParse(schema, args)\n if (result.success) return result.output\n throw new Error(`Invalid arguments for ${name}:\\n${v.summarize(result.issues)}`)\n}\n\nexport function toolChangesDocument(def: Pick<ToolDef, 'execution'>): boolean {\n return def.execution.mutation === 'properties' || def.execution.mutation === 'document'\n}\n\nexport function isToolExposed(def: Pick<ToolDef, 'exposure'>, target: ToolInterface): boolean {\n return def.exposure[target] !== false\n}\n\nexport function isAtomicTool(def: ToolDef): boolean {\n return def.execution.kind === 'sync' && def.execution.mutation === 'properties'\n}\n\nexport class NodeNotFoundError extends Error {\n constructor(id: string) {\n super(`Node not found: ${id}`)\n this.name = 'NodeNotFoundError'\n }\n}\n\nexport function requireNode(figma: FigmaAPI, id: string): ReturnType<FigmaAPI['getNodeById']> {\n const node = figma.getNodeById(id)\n if (!node) throw new NodeNotFoundError(id)\n return node\n}\n\nexport function requireNodes(figma: FigmaAPI, ids: ReadonlyArray<string>): FigmaNodeProxy[] | null {\n const nodes: FigmaNodeProxy[] = []\n for (const id of ids) {\n const node = figma.getNodeById(id)\n if (!node) return null\n nodes.push(node)\n }\n return nodes\n}\n\n/** A tool's answer when the operation it wraps throws: the error's message for the caller. */\nexport function toolFailure(error: unknown): { error: string } {\n return { error: error instanceof Error ? error.message : String(error) }\n}\n\nexport function nodeNotFound(id: string): { error: string } {\n return { error: `Node \"${id}\" not found` }\n}\n\nexport function getRawNodeOrError(\n figma: FigmaAPI,\n id: string\n): { node: SceneNode } | { error: string } {\n const node = figma.graph.getNode(id)\n return node ? { node } : nodeNotFound(id)\n}\n\nexport function nodeToResult(node: FigmaNodeProxy, maxDepth?: number): Record<string, unknown> {\n return node.toJSON(maxDepth)\n}\n\nexport function nodeSummary(node: FigmaNodeProxy): { id: string; name: string; type: string } {\n return { id: node.id, name: node.name, type: node.type }\n}\n\nexport const nodeIdInputSchema = v.pipe(v.string(), v.description('Node ID'))\nexport const nodeInputSchema = v.strictObject({ id: nodeIdInputSchema })\nexport const nodeComparisonInputSchema = v.strictObject({\n from: v.pipe(v.string(), v.description('Source node ID')),\n to: v.pipe(v.string(), v.description('Target node ID'))\n})\n\nexport function nodeTraversalInput(depthDescription: string) {\n return v.strictObject({\n id: nodeIdInputSchema,\n depth: v.optional(toolNumber(v.pipe(v.number(), v.description(depthDescription))))\n })\n}\nexport const positionInputs = {\n x: toolNumber(v.pipe(v.number(), v.description('X position in the parent, or on the page'))),\n y: toolNumber(v.pipe(v.number(), v.description('Y position in the parent, or on the page')))\n}\n\n/** Reuse a native number schema for both numeric and numeric-string agent inputs. */\nexport function toolNumber(schema: v.GenericSchema<number, number> = v.number()) {\n // JSON Schema numbers are finite. Express that with representable bounds as well as at runtime.\n const finite = v.pipe(schema, v.minValue(-Number.MAX_VALUE), v.maxValue(Number.MAX_VALUE))\n return v.union([\n finite,\n v.pipe(\n v.string(),\n v.regex(/\\S/, 'Expected a nonblank numeric string'),\n v.description(v.getDescription(schema) ?? 'Numeric value'),\n v.transform(Number),\n finite\n )\n ])\n}\n"],"mappings":";;;;;;;;AAyDA,SAAgB,WACd,KAUS;CACT,MAAM,EAAE,UAAU;CAClB,OAAO;EACL,GAAG;EACH,UAAU,IAA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;CAC3F,GAAG,WAAW,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,YAAY,0CAA0C,CAAC,CAAC;AAC7F;;AAGA,SAAgB,WAAW,SAA0C,EAAE,OAAO,GAAG;CAE/E,MAAM,SAAS,EAAE,KAAK,QAAQ,EAAE,SAAS,CAAC,OAAO,SAAS,GAAG,EAAE,SAAS,OAAO,SAAS,CAAC;CACzF,OAAO,EAAE,MAAM,CACb,QACA,EAAE,KACA,EAAE,OAAO,GACT,EAAE,MAAM,MAAM,oCAAoC,GAClD,EAAE,YAAY,EAAE,eAAe,MAAM,KAAK,eAAe,GACzD,EAAE,UAAU,MAAM,GAClB,MACF,CACF,CAAC;AACH"}
1
+ {"version":3,"file":"schema.js","names":[],"sources":["../../src/tools/schema.ts"],"sourcesContent":["/**\n * Tool definition schema.\n *\n * Native Valibot inputs and execution capabilities are owned by each tool.\n * Adapters consume these contracts rather than maintaining transport-specific schemas.\n */\n\nimport * as v from 'valibot'\n\nimport type { SceneNode } from '@pairdraw/scene-graph'\nimport { tryParseColor } from '@pairdraw/scene-graph/color'\nimport type { Color } from '@pairdraw/scene-graph/primitives'\n\nimport type { FigmaAPI, FigmaNodeProxy } from '#core/figma-api'\nimport type { FigmaFontNameInput } from '#core/figma-api/fonts/names'\n\nexport type ToolCapability =\n | 'document:read'\n | 'document:write'\n | 'filesystem:read'\n | 'filesystem:write'\n | 'network:access'\n | 'code:execute'\n | 'settings:read'\n | 'settings:write'\n\nexport type ToolExecution =\n | { kind: 'sync'; mutation: 'none' | 'view' | 'properties' | 'document' }\n | { kind: 'async'; mutation: 'none' | 'view' | 'document' }\n\nexport type ToolInterface = 'mcp' | 'ai' | 'webmcp'\nexport type ToolExposure = Partial<Record<ToolInterface, boolean>>\n\ninterface ToolMetadata {\n name: string\n description: string\n execution: ToolExecution\n /** Interface inclusion defaults to true; execution support and user permissions remain separate. */\n exposure: ToolExposure\n capabilities: readonly ToolCapability[]\n availability: 'default' | 'eval'\n}\n\nexport interface ToolDef extends ToolMetadata {\n input: v.StrictObjectSchema<v.ObjectEntries, undefined>\n /** Derived from execution metadata, never declared independently by a tool. */\n readonly mutates: boolean\n /**\n * Loads the fonts the call's text edits need, as a Figma plugin loads them before it edits\n * text; rejects when one cannot load. Every executor awaits it before `execute`, so a\n * synchronous tool still edits in one step.\n */\n loadFonts: (figma: FigmaAPI, args: Record<string, unknown>) => Promise<void>\n execute: (figma: FigmaAPI, args: Record<string, unknown>) => unknown\n}\n\ntype ToolDefinitionMetadata = Omit<ToolMetadata, 'exposure' | 'capabilities' | 'availability'> &\n Partial<Pick<ToolMetadata, 'exposure' | 'capabilities' | 'availability'>>\n\nexport function defineTool<P extends v.ObjectEntries, R>(\n def: ToolDefinitionMetadata & {\n input: v.StrictObjectSchema<P, undefined>\n execution: ToolExecution & (R extends PromiseLike<unknown> ? { kind: 'async' } : unknown)\n /** The fonts a call's text edits need loaded first; text edits refuse unloaded fonts. */\n fonts?: (\n figma: FigmaAPI,\n args: v.InferOutput<v.StrictObjectSchema<P, undefined>>\n ) => FigmaFontNameInput[]\n execute: (figma: FigmaAPI, args: v.InferOutput<v.StrictObjectSchema<P, undefined>>) => R\n }\n): ToolDef {\n const { fonts } = def\n return {\n ...def,\n exposure: def.exposure ?? {},\n capabilities: def.capabilities ?? [\n toolChangesDocument(def) ? 'document:write' : 'document:read'\n ],\n availability: def.availability ?? 'default',\n get mutates() {\n return def.execution.mutation !== 'none'\n },\n async loadFonts(figma, args) {\n if (!fonts) return\n // Wrong arguments are for `execute` to report.\n const parsed = v.safeParse(def.input, args)\n if (!parsed.success) return\n for (const font of fonts(figma, parsed.output)) await figma.loadFontAsync(font)\n },\n execute: (figma, args) => def.execute(figma, parseToolArgs(def.name, def.input, args))\n }\n}\n\n/**\n * Every tool run goes through here, so a wrong call from AI chat, the CLI, WebMCP, and MCP names\n * the tool and lists each problem with its argument. An unknown or missing argument names the\n * arguments the tool takes, and a picklist names the values it accepts, read from the schema, so\n * the caller does not have to guess. Inputs are strict objects, so a misspelled or mis-nested\n * argument fails here instead of being dropped.\n */\nexport function parseToolArgs<S extends v.GenericSchema>(\n name: string,\n schema: S,\n args: unknown\n): v.InferOutput<S> {\n const result = v.safeParse(schema, args)\n if (result.success) return result.output\n throw new Error(formatToolArgumentError(name, schema, result.issues))\n}\n\n/** One refusal for every surface: the tool, then each problem with where it is. */\nfunction formatToolArgumentError(\n name: string,\n schema: v.GenericSchema,\n issues: readonly v.BaseIssue<unknown>[]\n): string {\n const problems = issues.map((issue) => {\n const keys = issueKeys(issue)\n const place = keys.length > 0 ? `\\n → at ${keys.join('.')}` : ''\n return `× ${formatToolArgIssue(schema, issue)}${place}`\n })\n return `Invalid arguments for ${name}:\\n${problems.join('\\n')}`\n}\n\n/** The parts of a Valibot schema this module reads to name what a call should have sent. */\ntype SchemaParts = {\n readonly entries?: v.ObjectEntries\n readonly item?: v.GenericSchema\n readonly wrapped?: v.GenericSchema\n readonly options?: readonly unknown[]\n}\n\nfunction schemaParts(schema: unknown): SchemaParts {\n return typeof schema === 'object' && schema !== null ? schema : {}\n}\n\n/** The schema a wrapper such as `optional` or `pipe` holds, down to the one with the rules. */\nfunction unwrappedSchema(schema: v.GenericSchema): v.GenericSchema {\n let current = schema\n for (;;) {\n const wrapped = schemaParts(current).wrapped\n if (!wrapped) return current\n current = wrapped\n }\n}\n\nfunction issueKeys(issue: v.BaseIssue<unknown>): string[] {\n return (issue.path ?? []).flatMap((item) => ('key' in item ? [String(item.key)] : []))\n}\n\nfunction schemaAtPath(root: v.GenericSchema, keys: readonly string[]): v.GenericSchema | null {\n let current = unwrappedSchema(root)\n for (const key of keys) {\n const parts = schemaParts(current)\n const next = parts.entries && key in parts.entries ? parts.entries[key] : parts.item\n if (!next) return null\n current = unwrappedSchema(next)\n }\n return current\n}\n\nfunction formatToolArgIssue(schema: v.GenericSchema, issue: v.BaseIssue<unknown>): string {\n const keys = issueKeys(issue)\n const key = keys.at(-1)\n if (key !== undefined && (issue.type === 'object' || issue.type === 'strict_object')) {\n if (issue.expected === 'never') {\n const parent = schemaAtPath(schema, keys.slice(0, -1))\n const accepted = parent ? Object.keys(schemaParts(parent).entries ?? {}) : []\n return accepted.length > 0\n ? `Unknown argument \"${key}\". Accepted: ${accepted.join(', ')}`\n : `Unknown argument \"${key}\"`\n }\n if (issue.received === 'undefined') return `Missing required argument \"${key}\"`\n }\n if (issue.type === 'picklist' && key !== undefined) {\n const resolved = schemaAtPath(schema, keys)\n const options = resolved ? schemaParts(resolved).options : undefined\n if (options && options.length > 0) {\n const accepted = options.map((option) => JSON.stringify(option)).join(', ')\n return `Invalid value ${issue.received} for argument \"${key}\". Accepted: ${accepted}`\n }\n }\n return issue.message\n}\n\nexport function toolChangesDocument(def: Pick<ToolDef, 'execution'>): boolean {\n return def.execution.mutation === 'properties' || def.execution.mutation === 'document'\n}\n\nexport function isToolExposed(def: Pick<ToolDef, 'exposure'>, target: ToolInterface): boolean {\n return def.exposure[target] !== false\n}\n\nexport function isAtomicTool(def: ToolDef): boolean {\n return def.execution.kind === 'sync' && def.execution.mutation === 'properties'\n}\n\nexport class NodeNotFoundError extends Error {\n constructor(id: string) {\n super(`Node not found: ${id}`)\n this.name = 'NodeNotFoundError'\n }\n}\n\nexport function requireNode(figma: FigmaAPI, id: string): ReturnType<FigmaAPI['getNodeById']> {\n const node = figma.getNodeById(id)\n if (!node) throw new NodeNotFoundError(id)\n return node\n}\n\nexport function requireNodes(figma: FigmaAPI, ids: ReadonlyArray<string>): FigmaNodeProxy[] | null {\n const nodes: FigmaNodeProxy[] = []\n for (const id of ids) {\n const node = figma.getNodeById(id)\n if (!node) return null\n nodes.push(node)\n }\n return nodes\n}\n\n/** A tool's answer when the operation it wraps throws: the error's message for the caller. */\nexport function toolFailure(error: unknown): { error: string } {\n return { error: error instanceof Error ? error.message : String(error) }\n}\n\nexport function nodeNotFound(id: string): { error: string } {\n return { error: `Node \"${id}\" not found` }\n}\n\nexport function getRawNodeOrError(\n figma: FigmaAPI,\n id: string\n): { node: SceneNode } | { error: string } {\n const node = figma.graph.getNode(id)\n return node ? { node } : nodeNotFound(id)\n}\n\nexport function nodeToResult(node: FigmaNodeProxy, maxDepth?: number): Record<string, unknown> {\n return node.toJSON(maxDepth)\n}\n\nexport function nodeSummary(node: FigmaNodeProxy): { id: string; name: string; type: string } {\n return { id: node.id, name: node.name, type: node.type }\n}\n\n/**\n * A tool colour, refusing text that would otherwise land as black: `set_fill { color: \"#GGG\" }`\n * used to paint black and report success. Read through `tryParseColor`, since a published schema\n * cannot express what the parser accepts.\n */\nexport function parseToolColor(value: string): Color | { error: string } {\n return (\n tryParseColor(value) ?? {\n error: `\"${value}\" is not a color; use a hex value, a color name, or a color function`\n }\n )\n}\n\n/**\n * A colour the caller may leave out. Missing stays missing; text that is not a colour is the\n * same refusal `parseToolColor` gives, so each tool does not repeat that check.\n */\nexport function parseOptionalToolColor(\n value: string | undefined\n): { color: Color | undefined } | { error: string } {\n if (value === undefined) return { color: undefined }\n const parsed = parseToolColor(value)\n if ('error' in parsed) return parsed\n return { color: parsed }\n}\n\nexport const nodeIdInputSchema = v.pipe(v.string(), v.description('Node ID'))\nexport const nodeInputSchema = v.strictObject({ id: nodeIdInputSchema })\nexport const nodeComparisonInputSchema = v.strictObject({\n from: v.pipe(v.string(), v.description('Source node ID')),\n to: v.pipe(v.string(), v.description('Target node ID'))\n})\n\nexport function nodeTraversalInput(depthDescription: string) {\n return v.strictObject({\n id: nodeIdInputSchema,\n depth: v.optional(toolNumber(v.pipe(v.number(), v.description(depthDescription))))\n })\n}\nexport const positionInputs = {\n x: toolNumber(v.pipe(v.number(), v.description('X position in the parent, or on the page'))),\n y: toolNumber(v.pipe(v.number(), v.description('Y position in the parent, or on the page')))\n}\n\n/** Reuse a native number schema for both numeric and numeric-string agent inputs. */\nexport function toolNumber(schema: v.GenericSchema<number, number> = v.number()) {\n // JSON Schema numbers are finite. Express that with representable bounds as well as at runtime.\n const finite = v.pipe(schema, v.minValue(-Number.MAX_VALUE), v.maxValue(Number.MAX_VALUE))\n return v.union([\n finite,\n v.pipe(\n v.string(),\n v.regex(/\\S/, 'Expected a nonblank numeric string'),\n v.description(v.getDescription(schema) ?? 'Numeric value'),\n v.transform(Number),\n finite\n )\n ])\n}\n"],"mappings":";;;;;;;;;AA2DA,SAAgB,WACd,KAUS;CACT,MAAM,EAAE,UAAU;CAClB,OAAO;EACL,GAAG;EACH,UAAU,IAAI,YAAY,CAAC;EAC3B,cAAc,IAAI,gBAAgB,CAChC,oBAAoB,GAAG,IAAI,mBAAmB,eAChD;EACA,cAAc,IAAI,gBAAgB;EAClC,IAAI,UAAU;GACZ,OAAO,IAAI,UAAU,aAAa;EACpC;EACA,MAAM,UAAU,OAAO,MAAM;GAC3B,IAAI,CAAC,OAAO;GAEZ,MAAM,SAAS,EAAE,UAAU,IAAI,OAAO,IAAI;GAC1C,IAAI,CAAC,OAAO,SAAS;GACrB,KAAK,MAAM,QAAQ,MAAM,OAAO,OAAO,MAAM,GAAG,MAAM,MAAM,cAAc,IAAI;EAChF;EACA,UAAU,OAAO,SAAS,IAAI,QAAQ,OAAO,cAAc,IAAI,MAAM,IAAI,OAAO,IAAI,CAAC;CACvF;AACF;;;;;;;;AASA,SAAgB,cACd,MACA,QACA,MACkB;CAClB,MAAM,SAAS,EAAE,UAAU,QAAQ,IAAI;CACvC,IAAI,OAAO,SAAS,OAAO,OAAO;CAClC,MAAM,IAAI,MAAM,wBAAwB,MAAM,QAAQ,OAAO,MAAM,CAAC;AACtE;;AAGA,SAAS,wBACP,MACA,QACA,QACQ;CAMR,OAAO,yBAAyB,KAAK,KALpB,OAAO,KAAK,UAAU;EACrC,MAAM,OAAO,UAAU,KAAK;EAC5B,MAAM,QAAQ,KAAK,SAAS,IAAI,YAAY,KAAK,KAAK,GAAG,MAAM;EAC/D,OAAO,KAAK,mBAAmB,QAAQ,KAAK,IAAI;CAClD,CACiD,CAAC,CAAC,KAAK,IAAI;AAC9D;AAUA,SAAS,YAAY,QAA8B;CACjD,OAAO,OA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O,GAAG;CAE/E,MAAM,SAAS,EAAE,KAAK,QAAQ,EAAE,SAAS,CAAC,OAAO,SAAS,GAAG,EAAE,SAAS,OAAO,SAAS,CAAC;CACzF,OAAO,EAAE,MAAM,CACb,QACA,EAAE,KACA,EAAE,OAAO,GACT,EAAE,MAAM,MAAM,oCAAoC,GAClD,EAAE,YAAY,EAAE,eAAe,MAAM,KAAK,eAAe,GACzD,EAAE,UAAU,MAAM,GAClB,MACF,CACF,CAAC;AACH"}
@@ -1 +1 @@
1
- {"version":3,"file":"batch.d.ts","names":[],"sources":["../../../src/tools/structure/batch.ts"],"mappings":";;cAqGa,aAAA"}
1
+ {"version":3,"file":"batch.d.ts","names":[],"sources":["../../../src/tools/structure/batch.ts"],"mappings":";;cA0Ga,aAAA"}
@@ -4,10 +4,11 @@ import * as v from "valibot";
4
4
  //#region src/tools/structure/batch.ts
5
5
  const batchOpsSchema = v.array(v.object({
6
6
  id: v.string(),
7
- props: v.record(v.string(), v.unknown())
7
+ props: v.objectWithRest({}, v.unknown())
8
8
  }));
9
- /** The operations a call names, or why they cannot be read. */
9
+ /** The operations a call names, as an array or as the JSON string a client may send. */
10
10
  function parseOperations(operations) {
11
+ if (Array.isArray(operations)) return v.safeParse(batchOpsSchema, operations).success ? operations : { error: "operations must be an array of {id, props}" };
11
12
  const json = v.safeParse(v.pipe(v.string(), v.parseJson()), operations);
12
13
  if (!json.success) return { error: "Invalid JSON in operations" };
13
14
  const ops = v.safeParse(batchOpsSchema, json.output);
@@ -97,7 +98,7 @@ const batchUpdate = defineTool({
97
98
  kind: "sync",
98
99
  mutation: "document"
99
100
  },
100
- input: v.strictObject({ operations: v.pipe(v.string(), v.description("JSON array: [{\"id\":\"0:5\",\"props\":{\"spacing\":8}},{\"id\":\"0:6\",\"props\":{\"sizing_horizontal\":\"FILL\",\"grow\":1}}]")) }),
101
+ input: v.strictObject({ operations: v.pipe(v.union([batchOpsSchema, v.string()]), v.description("Array of {\"id\",\"props\"}, or the same array as a JSON string: [{\"id\":\"0:5\",\"props\":{\"spacing\":8}},{\"id\":\"0:6\",\"props\":{\"sizing_horizontal\":\"FILL\",\"grow\":1}}]")) }),
101
102
  fonts: (figma, { operations }) => {
102
103
  const ops = parseOperations(operations);
103
104
  if (!Array.isArray(ops)) return [];
@@ -1 +1 @@
1
- {"version":3,"file":"batch.js","names":[],"sources":["../../../src/tools/structure/batch.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport type { FigmaNodeProxy } from '#core/figma-api'\nimport { textFonts } from '#core/tools/modify/text'\nimport { defineTool } from '#core/tools/schema'\n\nconst batchOpsSchema = v.array(\n v.object({ id: v.string(), props: v.record(v.string(), v.unknown()) })\n)\ntype BatchOp = v.InferOutput<typeof batchOpsSchema>[number]\n\n/** The operations a call names, or why they cannot be read. */\nfunction parseOperations(operations: string): BatchOp[] | { error: string } {\n const json = v.safeParse(v.pipe(v.string(), v.parseJson()), operations)\n if (!json.success) return { error: 'Invalid JSON in operations' }\n const ops = v.safeParse(batchOpsSchema, json.output)\n if (!ops.success) return { error: 'operations must be a JSON array of {id, props}' }\n return ops.output\n}\n\nfunction str(value: unknown): string {\n return typeof value === 'string' ? value : ''\n}\n\nfunction num(value: unknown): number {\n return typeof value === 'number' ? value : 0\n}\n\nfunction applyBatchProps(node: FigmaNodeProxy, props: Record<string, unknown>): string[] {\n const updated: string[] = []\n\n if (props.spacing !== undefined) {\n node.itemSpacing = num(props.spacing)\n updated.push('spacing')\n }\n if (props.padding !== undefined) {\n const value = num(props.padding)\n node.paddingTop = value\n node.paddingRight = value\n node.paddingBottom = value\n node.paddingLeft = value\n updated.push('padding')\n }\n if (props.padding_horizontal !== undefined) {\n node.paddingLeft = num(props.padding_horizontal)\n node.paddingRight = num(props.padding_horizontal)\n updated.push('padding_horizontal')\n }\n if (props.padding_vertical !== undefined) {\n node.paddingTop = num(props.padding_vertical)\n node.paddingBottom = num(props.padding_vertical)\n updated.push('padding_vertical')\n }\n if (props.counter_align !== undefined) {\n node.counterAxisAlignItems = str(props.counter_align)\n updated.push('counter_align')\n }\n if (props.align !== undefined) {\n node.primaryAxisAlignItems = str(props.align)\n updated.push('align')\n }\n if (props.sizing_horizontal !== undefined) {\n node.layoutSizingHorizontal = str(props.sizing_horizontal)\n updated.push('sizing_horizontal')\n }\n if (props.sizing_vertical !== undefined) {\n node.layoutSizingVertical = str(props.sizing_vertical)\n updated.push('sizing_vertical')\n }\n if (props.grow !== undefined) {\n node.layoutGrow = num(props.grow)\n updated.push('grow')\n }\n if (props.name !== undefined) {\n node.name = str(props.name)\n updated.push('name')\n }\n if (props.visible !== undefined) {\n node.visible = Boolean(props.visible)\n updated.push('visible')\n }\n if (props.corner_radius !== undefined) {\n node.cornerRadius = num(props.corner_radius)\n updated.push('corner_radius')\n }\n if (props.opacity !== undefined) {\n node.opacity = num(props.opacity)\n updated.push('opacity')\n }\n if (props.auto_resize !== undefined) {\n node.textAutoResize = str(props.auto_resize)\n updated.push('auto_resize')\n }\n if (props.direction !== undefined) {\n node.layoutMode = str(props.direction) as 'HORIZONTAL' | 'VERTICAL'\n updated.push('direction')\n }\n\n return updated\n}\n\nexport const batchUpdate = defineTool({\n name: 'batch_update',\n\n description:\n 'Execute multiple modifications in one call. Each operation is {id, props} where props can include: spacing, padding, padding_horizontal, padding_vertical, counter_align, sizing_horizontal, sizing_vertical, grow, name, visible, corner_radius, auto_resize (for text), direction. Runs all updates with one layout recompute.',\n execution: { kind: 'sync', mutation: 'document' },\n input: v.strictObject({\n operations: v.pipe(\n v.string(),\n v.description(\n 'JSON array: [{\"id\":\"0:5\",\"props\":{\"spacing\":8}},{\"id\":\"0:6\",\"props\":{\"sizing_horizontal\":\"FILL\",\"grow\":1}}]'\n )\n )\n }),\n // Text that resizes itself lays out again, so its fonts load first.\n fonts: (figma, { operations }) => {\n const ops = parseOperations(operations)\n if (!Array.isArray(ops)) return []\n return ops.flatMap((op) => (op.props.auto_resize === undefined ? [] : textFonts(figma, op.id)))\n },\n execute: (figma, { operations }) => {\n const ops = parseOperations(operations)\n if (!Array.isArray(ops)) return ops\n\n const results: Array<{ id: string; updated: string[] }> = []\n const errors: string[] = []\n\n for (const op of ops) {\n const node = figma.getNodeById(op.id)\n if (!node) {\n errors.push(`Node \"${op.id}\" not found`)\n continue\n }\n const updated = applyBatchProps(node, op.props)\n if (updated.length > 0) results.push({ id: op.id, updated })\n }\n\n const out: Record<string, unknown> = { updated: results.length }\n if (results.length > 0) out.results = results\n if (errors.length > 0) out.errors = errors\n return out\n }\n})\n"],"mappings":";;;;AAMA,MAAM,iBAAiB,EAAE,MACvB,EAAE,OAAO;CAAE,IAAI,EAAE,OAAO;CAAG,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC;AAAE,CAAC,CACvE;;AAIA,SAAS,gBAAgB,YAAmD;CAC1E,MAAM,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,UAAU,CAAC,GAAG,UAAU;CACtE,IAAI,CAAC,KAAK,SAAS,OAAO,EAAE,OAAO,6BAA6B;CAChE,MAAM,MAAM,EAAE,UAAU,gBAAgB,KAAK,MAAM;CACnD,IAAI,CAAC,IAAI,SAAS,OAAO,EAAE,OAAO,iDAAiD;CACnF,OAAO,IAAI;AACb;AAEA,SAAS,IAAI,OAAwB;CACnC,OAAO,OAAO,UAAU,WAAW,QAAQ;AAC7C;AAEA,SAAS,IAAI,OAAwB;CACnC,OAAO,OAAO,UAAU,WAAW,QAAQ;AAC7C;AAEA,SAAS,gBAAgB,MAAsB,OAA0C;CACvF,MAAM,UAAoB,CAAC;CAE3B,IAAI,MAAM,YAAY,KAAA,GAAW;EAC/B,KAAK,cAAc,IAAI,MAAM,OAAO;EACpC,QAAQ,KAAK,SAAS;CACxB;CACA,IAAI,MAAM,YAAY,KAAA,GAAW;EAC/B,MAAM,QAAQ,IAAI,MAAM,OAAO;EAC/B,KAAK,aAAa;EAClB,KAAK,eAAe;EACpB,KAAK,gBAAgB;EACrB,KAAK,cAAc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GAAG,IAAI,UAAU;EACtC,IAAI,OAAO,SAAS,GAAG,IAAI,SAAS;EACpC,OAAO;CACT;AACF,CAAC"}
1
+ {"version":3,"file":"batch.js","names":[],"sources":["../../../src/tools/structure/batch.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport type { FigmaNodeProxy } from '#core/figma-api'\nimport { textFonts } from '#core/tools/modify/text'\nimport { defineTool } from '#core/tools/schema'\n\nconst batchOpsSchema = v.array(\n v.object({ id: v.string(), props: v.objectWithRest({}, v.unknown()) })\n)\ntype BatchOp = v.InferOutput<typeof batchOpsSchema>[number]\n\n/** The operations a call names, as an array or as the JSON string a client may send. */\nfunction parseOperations(operations: BatchOp[] | string): BatchOp[] | { error: string } {\n if (Array.isArray(operations)) {\n return v.safeParse(batchOpsSchema, operations).success\n ? operations\n : { error: 'operations must be an array of {id, props}' }\n }\n const json = v.safeParse(v.pipe(v.string(), v.parseJson()), operations)\n if (!json.success) return { error: 'Invalid JSON in operations' }\n const ops = v.safeParse(batchOpsSchema, json.output)\n if (!ops.success) return { error: 'operations must be a JSON array of {id, props}' }\n return ops.output\n}\n\nfunction str(value: unknown): string {\n return typeof value === 'string' ? value : ''\n}\n\nfunction num(value: unknown): number {\n return typeof value === 'number' ? value : 0\n}\n\nfunction applyBatchProps(node: FigmaNodeProxy, props: Record<string, unknown>): string[] {\n const updated: string[] = []\n\n if (props.spacing !== undefined) {\n node.itemSpacing = num(props.spacing)\n updated.push('spacing')\n }\n if (props.padding !== undefined) {\n const value = num(props.padding)\n node.paddingTop = value\n node.paddingRight = value\n node.paddingBottom = value\n node.paddingLeft = value\n updated.push('padding')\n }\n if (props.padding_horizontal !== undefined) {\n node.paddingLeft = num(props.padding_horizontal)\n node.paddingRight = num(props.padding_horizontal)\n updated.push('padding_horizontal')\n }\n if (props.padding_vertical !== undefined) {\n node.paddingTop = num(props.padding_vertical)\n node.paddingBottom = num(props.padding_vertical)\n updated.push('padding_vertical')\n }\n if (props.counter_align !== undefined) {\n node.counterAxisAlignItems = str(props.counter_align)\n updated.push('counter_align')\n }\n if (props.align !== undefined) {\n node.primaryAxisAlignItems = str(props.align)\n updated.push('align')\n }\n if (props.sizing_horizontal !== undefined) {\n node.layoutSizingHorizontal = str(props.sizing_horizontal)\n updated.push('sizing_horizontal')\n }\n if (props.sizing_vertical !== undefined) {\n node.layoutSizingVertical = str(props.sizing_vertical)\n updated.push('sizing_vertical')\n }\n if (props.grow !== undefined) {\n node.layoutGrow = num(props.grow)\n updated.push('grow')\n }\n if (props.name !== undefined) {\n node.name = str(props.name)\n updated.push('name')\n }\n if (props.visible !== undefined) {\n node.visible = Boolean(props.visible)\n updated.push('visible')\n }\n if (props.corner_radius !== undefined) {\n node.cornerRadius = num(props.corner_radius)\n updated.push('corner_radius')\n }\n if (props.opacity !== undefined) {\n node.opacity = num(props.opacity)\n updated.push('opacity')\n }\n if (props.auto_resize !== undefined) {\n node.textAutoResize = str(props.auto_resize)\n updated.push('auto_resize')\n }\n if (props.direction !== undefined) {\n node.layoutMode = str(props.direction) as 'HORIZONTAL' | 'VERTICAL'\n updated.push('direction')\n }\n\n return updated\n}\n\nexport const batchUpdate = defineTool({\n name: 'batch_update',\n\n description:\n 'Execute multiple modifications in one call. Each operation is {id, props} where props can include: spacing, padding, padding_horizontal, padding_vertical, counter_align, sizing_horizontal, sizing_vertical, grow, name, visible, corner_radius, auto_resize (for text), direction. Runs all updates with one layout recompute.',\n execution: { kind: 'sync', mutation: 'document' },\n input: v.strictObject({\n operations: v.pipe(\n v.union([batchOpsSchema, v.string()]),\n v.description(\n 'Array of {\"id\",\"props\"}, or the same array as a JSON string: [{\"id\":\"0:5\",\"props\":{\"spacing\":8}},{\"id\":\"0:6\",\"props\":{\"sizing_horizontal\":\"FILL\",\"grow\":1}}]'\n )\n )\n }),\n // Text that resizes itself lays out again, so its fonts load first.\n fonts: (figma, { operations }) => {\n const ops = parseOperations(operations)\n if (!Array.isArray(ops)) return []\n return ops.flatMap((op) => (op.props.auto_resize === undefined ? [] : textFonts(figma, op.id)))\n },\n execute: (figma, { operations }) => {\n const ops = parseOperations(operations)\n if (!Array.isArray(ops)) return ops\n\n const results: Array<{ id: string; updated: string[] }> = []\n const errors: string[] = []\n\n for (const op of ops) {\n const node = figma.getNodeById(op.id)\n if (!node) {\n errors.push(`Node \"${op.id}\" not found`)\n continue\n }\n const updated = applyBatchProps(node, op.props)\n if (updated.length > 0) results.push({ id: op.id, updated })\n }\n\n const out: Record<string, unknown> = { updated: results.length }\n if (results.length > 0) out.results = results\n if (errors.length > 0) out.errors = errors\n return out\n }\n})\n"],"mappings":";;;;AAMA,MAAM,iBAAiB,EAAE,MACvB,EAAE,OAAO;CAAE,IAAI,EAAE,OAAO;CAAG,OAAO,EAAE,eAAe,CAAC,GAAG,EAAE,QAAQ,CAAC;AAAE,CAAC,CACvE;;AAIA,SAAS,gBAAgB,YAA+D;CACtF,IAAI,MAAM,QAAQ,UAAU,GAC1B,OAAO,EAAE,UAAU,gBAAgB,UAAU,CAAC,CAAC,UAC3C,aACA,EAAE,OAAO,6CAA6C;CAE5D,MAAM,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,UAAU,CAAC,GAAG,UAAU;CACtE,IAAI,CAAC,KAAK,SAAS,OAAO,EAAE,OAAO,6BAA6B;CAChE,MAAM,MAAM,EAAE,UAAU,gBAAgB,KAAK,MAAM;CACnD,IAAI,CAAC,IAAI,SAAS,OAAO,EAAE,OAAO,iDAAiD;CACnF,OAAO,IAAI;AACb;AAEA,SAAS,IAAI,OAAwB;CACnC,OAAO,OAAO,UAAU,WAAW,QAAQ;AAC7C;AAEA,SAAS,IAAI,OAAwB;CACnC,OAAO,OAAO,UAAU,WAAW,QAAQ;AAC7C;AAEA,SAAS,gBAAgB,MAAsB,OAA0C;CACvF,MAAM,UAAoB,CAAC;CAE3B,IAAI,MAAM,YAAY,KAAA,GAAW;EAC/B,KAAK,cAAc,IAAI,MAAM,OAAO;EACpC,QAAQ,KAAK,SAA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M,UAAU,gBAAgB,MAAM,GAAG,KAAK;GAC9C,IAAI,QAAQ,SAAS,GAAG,QAAQ,KAAK;IAAE,IAAI,GAAG;IAAI;GAAQ,CAAC;EAC7D;EAEA,MAAM,MAA+B,EAAE,SAAS,QAAQ,OAAO;EAC/D,IAAI,QAAQ,SAAS,GAAG,IAAI,UAAU;EACtC,IAAI,OAAO,SAAS,GAAG,IAAI,SAAS;EACpC,OAAO;CACT;AACF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"values.d.ts","names":[],"sources":["../../../src/tools/variables/values.ts"],"mappings":";;cAuBa,gBAAA;cA+BA,aAAA;cAmBA,gBAAA"}
1
+ {"version":3,"file":"values.d.ts","names":[],"sources":["../../../src/tools/variables/values.ts"],"mappings":";;cAuBa,gBAAA;cAgCA,aAAA;cAqBA,gBAAA"}