Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

3.8 KB
Raw Blame
import type { ThemeV0, ThemeV1, ThemeV2, ThemeV3 } from '../types/themeTypes';
import { getThemeColorMode, getThemeColorTokens } from './themeColorTokens';

export function convertThemev0v1(theme: ThemeV0): ThemeV1 {
  return {
    id: theme.id,
    name: theme.name,
    version: 1,
    tokens: {
      a0: {
        l: theme.specification['--accent-l'],
        c: theme.specification['--accent-c'],
        h: (theme.specification['--accent-h'] + 30) % 360,
      },
      a1: {
        l: theme.specification['--accent-l'],
        c: theme.specification['--accent-c'],
        h: (theme.specification['--accent-h'] + 30) % 360,
      },
      a2: {
        l: theme.specification['--accent-l'],
        c: theme.specification['--accent-c'],
        h: (theme.specification['--accent-h'] + 30) % 360,
      },
      a3: {
        l: theme.specification['--accent-l'],
        c: theme.specification['--accent-c'],
        h: (theme.specification['--accent-h'] + 30) % 360,
      },
      a4: {
        l: theme.specification['--accent-l'],
        c: theme.specification['--accent-c'],
        h: (theme.specification['--accent-h'] + 30) % 360,
      },
      b0: {
        l: theme.specification['--surface-l'],
        c: theme.specification['--surface-c'],
        h: theme.specification['--surface-h'],
      },
      b1: {
        l: theme.specification['--surface-l-1'],
        c: theme.specification['--surface-c'],
        h: theme.specification['--surface-h'],
      },
      b2: {
        l: theme.specification['--surface-l-2'],
        c: theme.specification['--surface-c'],
        h: theme.specification['--surface-h'],
      },
      b3: {
        l: theme.specification['--surface-l-3'],
        c: theme.specification['--surface-c'],
        h: theme.specification['--surface-h'],
      },
      b4: {
        l: theme.specification['--surface-l-4'],
        c: theme.specification['--surface-c'],
        h: theme.specification['--surface-h'],
      },
      c0: {
        l: theme.specification['--contrast-l'],
        c: theme.specification['--contrast-c'],
        h: theme.specification['--contrast-h'],
      },
      c1: {
        l: theme.specification['--contrast-l-1'],
        c: theme.specification['--contrast-c'],
        h: theme.specification['--contrast-h'],
      },
      c2: {
        l: theme.specification['--contrast-l-2'],
        c: theme.specification['--contrast-c'],
        h: theme.specification['--contrast-h'],
      },
      c3: {
        l: theme.specification['--contrast-l-3'],
        c: theme.specification['--contrast-c'],
        h: theme.specification['--contrast-h'],
      },
      c4: {
        l: theme.specification['--contrast-l-4'],
        c: theme.specification['--contrast-c'],
        h: theme.specification['--contrast-h'],
      },
    },
  };
}

export function convertThemev1v2(theme: ThemeV1): ThemeV2 {
  const [b0, b1, b2, b3, b4] = [
    theme.tokens.b0,
    theme.tokens.b1,
    theme.tokens.b2,
    theme.tokens.b3,
    theme.tokens.b4,
  ].sort((x, y) => x.l - y.l);

  const [c0, c1, c2, c3, c4] = [
    theme.tokens.c0,
    theme.tokens.c1,
    theme.tokens.c2,
    theme.tokens.c3,
    theme.tokens.c4,
  ].sort((x, y) => (b0.l < 0.5 ? y.l - x.l : x.l - y.l));

  return {
    id: theme.id,
    name: theme.name,
    version: 2,
    depth: 0.15,
    tokens: {
      ...theme.tokens,
      b0,
      b1,
      b2,
      b3,
      b4,
      c0,
      c1,
      c2,
      c3,
      c4,
    },
  };
}

/** Removes the legacy ramps after converting them into the authored VNext
 * registry. The explicit mode replaces light/dark inference from b0/c0. */
export function convertThemev2v3(theme: ThemeV2): ThemeV3 {
  return {
    id: theme.id,
    name: theme.name,
    version: 3,
    mode: getThemeColorMode(theme.tokens),
    colorTokens: getThemeColorTokens(theme),
  };
}