{"version":3,"file":"pluginThemes.cjs","names":["BUILTIN_THEMES","parseThemeConfig","PALETTE_TOKENS"],"sources":["../../../src/web/lib/pluginThemes.ts"],"sourcesContent":["import type { WebPluginDefinition } from '@agimon-ai/po-core/web';\nimport { BUILTIN_THEMES, PALETTE_TOKENS, parseThemeConfig, type ThemeConfig } from '@agimon-ai/po-web-components/theme';\n\nimport type { InstallDiagnostic } from './pluginRegistry';\n\n/** A theme a global plugin contributes, validated and published under its owner's name. */\nexport interface InstalledPluginTheme {\n  pluginId: string;\n  theme: ThemeConfig;\n}\n\n/**\n * The themes the person's global plugins contribute to Appearance.\n *\n * Each is validated like a theme file and published as `<pluginId>-<name>`, so two packages\n * never collide and none can shadow a shipped theme. A theme that fails is reported, never\n * thrown: one bad colour must not keep the cockpit from starting.\n */\nexport function collectPluginThemes(plugins: readonly WebPluginDefinition[]): {\n  themes: InstalledPluginTheme[];\n  diagnostics: InstallDiagnostic[];\n} {\n  const taken = new Set(BUILTIN_THEMES.map((theme) => theme.name));\n  const themes: InstalledPluginTheme[] = [];\n  const diagnostics: InstallDiagnostic[] = [];\n  for (const plugin of plugins) {\n    for (const contribution of plugin.host?.themes ?? []) {\n      const theme = parseThemeConfig({ ...contribution, name: `${plugin.id}-${contribution.name}` });\n      if (theme === null) {\n        diagnostics.push({\n          pluginId: plugin.id,\n          kind: 'rejected-theme',\n          message: `Web plugin '${plugin.id}' theme '${contribution.name}' is not a valid theme; Appearance leaves it out.`,\n        });\n        continue;\n      }\n      if (taken.has(theme.name)) {\n        diagnostics.push({\n          pluginId: plugin.id,\n          kind: 'duplicate-theme',\n          message: `Web plugin '${plugin.id}' theme '${theme.name}' is already taken; the first one stays.`,\n        });\n        continue;\n      }\n      taken.add(theme.name);\n      themes.push({ pluginId: plugin.id, theme });\n    }\n  }\n  return { themes, diagnostics };\n}\n\n/** Whether the phone can show a theme: it derives the rest from the palette, which must be hex. */\nexport function isHexTheme(theme: ThemeConfig): boolean {\n  return PALETTE_TOKENS.every((token) => /^#[0-9a-f]{3,8}$/i.test(theme.tokens[token]));\n}\n"],"mappings":";;;;;;;;;AAkBA,SAAgB,oBAAoB,SAGlC;CACA,MAAM,QAAQ,IAAI,IAAIA,mCAAAA,eAAe,KAAK,UAAU,MAAM,IAAI,CAAC;CAC/D,MAAM,SAAiC,CAAC;CACxC,MAAM,cAAmC,CAAC;CAC1C,KAAK,MAAM,UAAU,SACnB,KAAK,MAAM,gBAAgB,OAAO,MAAM,UAAU,CAAC,GAAG;EACpD,MAAM,SAAA,GAAQC,mCAAAA,iBAAAA,CAAiB;GAAE,GAAG;GAAc,MAAM,GAAG,OAAO,GAAG,GAAG,aAAa;EAAO,CAAC;EAC7F,IAAI,UAAU,MAAM;GAClB,YAAY,KAAK;IACf,UAAU,OAAO;IACjB,MAAM;IACN,SAAS,eAAe,OAAO,GAAG,WAAW,aAAa,KAAK;GACjE,CAAC;GACD;EACF;EACA,IAAI,MAAM,IAAI,MAAM,IAAI,GAAG;GACzB,YAAY,KAAK;IACf,UAAU,OAAO;IACjB,MAAM;IACN,SAAS,eAAe,OAAO,GAAG,WAAW,MAAM,KAAK;GAC1D,CAAC;GACD;EACF;EACA,MAAM,IAAI,MAAM,IAAI;EACpB,OAAO,KAAK;GAAE,UAAU,OAAO;GAAI;EAAM,CAAC;CAC5C;CAEF,OAAO;EAAE;EAAQ;CAAY;AAC/B;;AAGA,SAAgB,WAAW,OAA6B;CACtD,OAAOC,mCAAAA,eAAe,OAAO,UAAU,oBAAoB,KAAK,MAAM,OAAO,MAAM,CAAC;AACtF"}