@whzxc/agent-design-gallery 0.6.0 → 0.7.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.
@@ -1,23 +1,24 @@
1
+ import { CliError } from '../cli-output.mjs';
1
2
  export function parseTokens(css) {
2
3
  const source = css.replace(/\/\*[\s\S]*?\*\//g, '');
3
4
  const blocks = [...source.matchAll(/([^{}]+)\{([^{}]*)\}/g)];
4
5
  if (blocks.length !== 2 || source.replace(/[^{}]+\{[^{}]*\}/g, '').trim() ||
5
6
  blocks[0][1].trim() !== ':root' || blocks[1][1].trim() !== ':root[data-theme="dark"]') {
6
- throw new Error('tokens.css needs exactly :root and :root[data-theme="dark"] blocks; fix the token source');
7
+ throw new CliError('TOKENS_INVALID', 'tokens.css needs exactly :root and :root[data-theme="dark"] blocks; fix the token source');
7
8
  }
8
9
  const maps = blocks.map(([, , body]) => {
9
10
  const map = new Map();
10
11
  for (const line of body.split('\n').map(line => line.trim()).filter(Boolean)) {
11
12
  const match = line.match(/^(--[\w-]+)\s*:\s*([^;]+);$/);
12
- if (!match || map.has(match[1])) throw new Error(`Invalid token declaration ${line}; put each unique token on its own line`);
13
+ if (!match || map.has(match[1])) throw new CliError('TOKENS_INVALID', `Invalid token declaration ${line}; put each unique token on its own line`);
13
14
  map.set(match[1], match[2].trim());
14
15
  }
15
16
  return map;
16
17
  });
17
18
  for (const key of ['--font-ui', '--font-mono', '--canvas', '--text']) {
18
- if (!maps[0].has(key)) throw new Error(`tokens.css is missing ${key}; add it to :root`);
19
+ if (!maps[0].has(key)) throw new CliError('TOKENS_INVALID', `tokens.css is missing ${key}; add it to :root`);
19
20
  }
20
- for (const key of maps[1].keys()) if (!maps[0].has(key)) throw new Error(`Dark token ${key} has no light value; add it to :root`);
21
+ for (const key of maps[1].keys()) if (!maps[0].has(key)) throw new CliError('TOKENS_INVALID', `Dark token ${key} has no light value; add it to :root`);
21
22
  return { light: maps[0], dark: maps[1] };
22
23
  }
23
24