Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

1.8 KB
Raw Blame
import {
  completePluginAppThemeTokens,
  PLUGIN_APP_THEME_REQUIRED_TOKENS,
  PLUGIN_APP_THEME_TOKENS
} from './plugin-theme-artifact'

const REQUIRED = new Set<string>(PLUGIN_APP_THEME_REQUIRED_TOKENS)

/** What an omitted token becomes, read back from the real derivation with every other token
 *  standing in as `var(<name>)`, so the table cannot drift from what Orca applies. */
function omittedValue(token: string): string {
  const others = Object.fromEntries(
    PLUGIN_APP_THEME_TOKENS.filter((other) => other !== token).map((other) => [
      other,
      `var(${other})`
    ])
  )
  const derived = completePluginAppThemeTokens(others)[token]
  if (derived === undefined) {
    return "Orca's built-in color"
  }
  const mix = /^color-mix\(in srgb, var\((--[\w-]+)\) (\d+)%, var\((--[\w-]+)\)\)$/.exec(derived)
  if (mix) {
    return `\`${mix[1]}\` mixed ${mix[2]}% into \`${mix[3]}\``
  }
  return derived.replace(/^var\((--[\w-]+)\)$/, 'same as `$1`')
}

/** Colour token list for theme authors, rendered from the public token set. */
export function renderPluginThemeTokenReference(): string {
  const lines = [
    '# Orca app theme tokens',
    '',
    '<!-- Generated by `pnpm generate:plugin-schemas` from src/shared/plugins. Do not edit. -->',
    '',
    'Every key an app theme may set in `tokens` (see [plugin themes](plugin-themes.md)). Any other key is refused. An omitted token falls back as listed; when that source is omitted too, it falls back the same way in turn.',
    '',
    '| Token | Required | When omitted |',
    '| --- | --- | --- |',
    ...PLUGIN_APP_THEME_TOKENS.map(
      (token) =>
        `| \`${token}\` | ${REQUIRED.has(token) ? 'yes' : 'no'} | ${REQUIRED.has(token) ? '' : omittedValue(token)} |`
    )
  ]
  return `${lines.join('\n')}\n`
}