opencode/packages/plugin/script/icon-name.ts
Luke Parker 22377659a8
feat(plugin): let GUI plugins declare their own icons (#64577)
A plugin declares SVG artwork in Plugin.define({ icons }) and names it with ctx.icons.<name> in every SDK icon field and ctx.ui.Icon. The host registers the artwork in the app's icon component before setup, so any part of the app draws it by name, in the size and color of its place, and withdraws it with the plugin.

Artwork may move with SVG animation elements. It stays in place while its host renders again, and the host holds it on its first frame under reduced motion.

Pairing and goal now ship the artwork only they show, which leaves the app's icon catalog.
2026-11-18 03:27:56 -06:00

22 lines
956 B
TypeScript

#!/usr/bin/env bun
// Writes src/gui/icon-name.ts: the names of the app's own icons that GUI SDK fields accept, from the app's icon catalog
// in packages/ui. The published SDK cannot depend on @opencode/ui, so it carries the names; packages/gui-plugins fails
// its typecheck when they drift (src/icon-name.typecheck.ts). A plugin's own icons are not listed here: it declares
// them in `Plugin.define({ icons })`.
import { fileURLToPath } from "node:url"
import { iconNames } from "../../ui/src/icons/catalog"
const names = iconNames().toSorted()
await Bun.write(
fileURLToPath(new URL("../src/gui/icon-name.ts", import.meta.url)),
[
"// Generated by `bun run generate` (script/icon-name.ts) from the app's icon catalog. Do not edit.",
"",
"/** One of the app's own icons, by its name in the app's icon catalog. */",
"export type AppIconName =",
...names.map((name) => ` | ${JSON.stringify(name)}`),
"",
].join("\n"),
)