command-code 1.93.1 → 1.93.2

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.
Files changed (102) hide show
  1. package/CHANGELOG.md +7 -1
  2. package/dist/bundled/agent-browser/SKILL.md +73 -0
  3. package/dist/bundled/command-code-knowledge/SKILL.md +68 -0
  4. package/dist/bundled/command-code-knowledge/live-models.ts +284 -0
  5. package/dist/bundled/command-code-knowledge/reference/byok.md +389 -0
  6. package/dist/bundled/command-code-knowledge/reference/custom-agents.md +341 -0
  7. package/dist/bundled/command-code-knowledge/reference/custom-slash-commands.md +423 -0
  8. package/dist/bundled/command-code-knowledge/reference/headless.md +381 -0
  9. package/dist/bundled/command-code-knowledge/reference/hooks.md +1107 -0
  10. package/dist/bundled/command-code-knowledge/reference/mcp.md +648 -0
  11. package/dist/bundled/command-code-knowledge/reference/memory.md +137 -0
  12. package/dist/bundled/command-code-knowledge/reference/models.md +145 -0
  13. package/dist/bundled/command-code-knowledge/reference/permissions.md +486 -0
  14. package/dist/bundled/command-code-knowledge/reference/plan-mode.md +283 -0
  15. package/dist/bundled/command-code-knowledge/reference/plans.md +16 -0
  16. package/dist/bundled/command-code-knowledge/reference/product-help.md +490 -0
  17. package/dist/bundled/command-code-knowledge/reference/sessions.md +377 -0
  18. package/dist/bundled/command-code-knowledge/reference/skills.md +1009 -0
  19. package/dist/bundled/command-code-knowledge/reference/tools.md +522 -0
  20. package/dist/bundled/config/SKILL.md +18 -0
  21. package/dist/bundled/config/references/permissions.md +27 -0
  22. package/dist/bundled/config/references/settings.md +50 -0
  23. package/dist/bundled/design/SKILL.md +448 -0
  24. package/dist/bundled/design/references/accessibility.md +404 -0
  25. package/dist/bundled/design/references/border.md +161 -0
  26. package/dist/bundled/design/references/button.md +192 -0
  27. package/dist/bundled/design/references/checkup.md +164 -0
  28. package/dist/bundled/design/references/color.md +245 -0
  29. package/dist/bundled/design/references/create.md +291 -0
  30. package/dist/bundled/design/references/design-html.md +227 -0
  31. package/dist/bundled/design/references/deslop.md +285 -0
  32. package/dist/bundled/design/references/finish.md +156 -0
  33. package/dist/bundled/design/references/interaction.md +186 -0
  34. package/dist/bundled/design/references/layout.md +216 -0
  35. package/dist/bundled/design/references/media.md +112 -0
  36. package/dist/bundled/design/references/motion.md +237 -0
  37. package/dist/bundled/design/references/redesign.md +197 -0
  38. package/dist/bundled/design/references/refine.md +193 -0
  39. package/dist/bundled/design/references/reflexes.md +132 -0
  40. package/dist/bundled/design/references/relayout.md +207 -0
  41. package/dist/bundled/design/references/report-html.md +235 -0
  42. package/dist/bundled/design/references/responsive.md +233 -0
  43. package/dist/bundled/design/references/review.md +164 -0
  44. package/dist/bundled/design/references/setup.md +119 -0
  45. package/dist/bundled/design/references/severity.md +111 -0
  46. package/dist/bundled/design/references/shadow.md +164 -0
  47. package/dist/bundled/design/references/smell.md +213 -0
  48. package/dist/bundled/design/references/style-3d.md +23 -0
  49. package/dist/bundled/design/references/style-bento.md +21 -0
  50. package/dist/bundled/design/references/style-editorial.md +23 -0
  51. package/dist/bundled/design/references/style-futuristic.md +21 -0
  52. package/dist/bundled/design/references/style-glassmorphism.md +52 -0
  53. package/dist/bundled/design/references/style-maximalism.md +20 -0
  54. package/dist/bundled/design/references/style-minimalism.md +21 -0
  55. package/dist/bundled/design/references/style-neo-brutalism.md +21 -0
  56. package/dist/bundled/design/references/style-retro-futurism.md +21 -0
  57. package/dist/bundled/design/references/style-swiss.md +20 -0
  58. package/dist/bundled/design/references/style.md +77 -0
  59. package/dist/bundled/design/references/surface.md +163 -0
  60. package/dist/bundled/design/references/system.md +73 -0
  61. package/dist/bundled/design/references/typeset.md +210 -0
  62. package/dist/bundled/design/references/variants.md +193 -0
  63. package/dist/bundled/design/references/voice.md +184 -0
  64. package/dist/bundled/design/references/writing.md +174 -0
  65. package/dist/bundled/design/scripts/check/color.mjs +213 -0
  66. package/dist/bundled/design/scripts/check/contrast.mjs +141 -0
  67. package/dist/bundled/design/scripts/check/css.mjs +223 -0
  68. package/dist/bundled/design/scripts/check/named-colors.mjs +152 -0
  69. package/dist/bundled/design/scripts/check/pair.mjs +61 -0
  70. package/dist/bundled/design/scripts/check/preview.mjs +27 -0
  71. package/dist/bundled/design/scripts/check/reflexes.mjs +257 -0
  72. package/dist/bundled/design/scripts/check/sources.mjs +237 -0
  73. package/dist/bundled/design/scripts/check.mjs +165 -0
  74. package/dist/bundled/loop/SKILL.md +16 -0
  75. package/dist/bundled/mod-builder/SKILL.md +135 -0
  76. package/dist/bundled/mod-builder/examples/block-dangerous-commands.ts +41 -0
  77. package/dist/bundled/mod-builder/examples/custom-entry-renderer.ts +32 -0
  78. package/dist/bundled/mod-builder/examples/custom-tool.ts +53 -0
  79. package/dist/bundled/mod-builder/examples/flags-and-options.ts +29 -0
  80. package/dist/bundled/mod-builder/examples/input-shortcuts.ts +41 -0
  81. package/dist/bundled/mod-builder/examples/kitchen-sink.ts +129 -0
  82. package/dist/bundled/mod-builder/examples/lifecycle-hooks.ts +64 -0
  83. package/dist/bundled/mod-builder/examples/model-router.ts +43 -0
  84. package/dist/bundled/mod-builder/examples/observe-events.ts +30 -0
  85. package/dist/bundled/mod-builder/examples/pane-and-buttons.ts +60 -0
  86. package/dist/bundled/mod-builder/examples/pane-form.ts +68 -0
  87. package/dist/bundled/mod-builder/examples/permission-policy.ts +34 -0
  88. package/dist/bundled/mod-builder/examples/redact-secrets.ts +46 -0
  89. package/dist/bundled/mod-builder/examples/slash-command.ts +33 -0
  90. package/dist/bundled/mod-builder/examples/spinner-count.ts +47 -0
  91. package/dist/bundled/mod-builder/examples/stream-filter.ts +70 -0
  92. package/dist/bundled/mod-builder/reference/api.md +140 -0
  93. package/dist/bundled/mod-builder/reference/hooks-and-events.md +347 -0
  94. package/dist/bundled/mod-builder/reference/overview.md +271 -0
  95. package/dist/bundled/mod-builder/reference/packaging.md +187 -0
  96. package/dist/bundled/mod-builder/reference/ui.md +253 -0
  97. package/dist/bundled/mod-builder/reference/verify.md +67 -0
  98. package/dist/bundled/skill-builder/SKILL.md +104 -0
  99. package/dist/cli.mjs +16 -0
  100. package/dist/index.mjs +2 -0
  101. package/package.json +1 -1
  102. package/vsix/commandcode-vscode.vsix +0 -0
@@ -0,0 +1,141 @@
1
+ // Contrast for check.mjs: WCAG 2 AA on rules that set a text color, APCA as the second read.
2
+ import {
3
+ apcaLc,
4
+ parseColor,
5
+ referencedVars,
6
+ unresolvedVars,
7
+ wcagRatio,
8
+ } from './color.mjs';
9
+ import {
10
+ backgroundColor,
11
+ declarations,
12
+ hasBackground,
13
+ textSize,
14
+ } from './css.mjs';
15
+
16
+ export const NORMAL_RATIO = 4.5;
17
+ export const LARGE_RATIO = 3;
18
+ export const NORMAL_APCA = 60;
19
+ export const LARGE_APCA = 45;
20
+ // Text measured only against the page background: below 2:1 it almost certainly sits on its own
21
+ // section backdrop (light text in a dark band), so reporting it is noise. Muted text on the page
22
+ // itself — the real failure — lands between 2:1 and the threshold.
23
+ const PAGE_PAIR_FLOOR = 2;
24
+ const UNMEASURED_STATE = /disabled|::?placeholder|::selection/i;
25
+
26
+ /** @typedef {import('./css.mjs').Rule} Rule */
27
+ /** @typedef {{level: 'FAIL' | 'WARN', check: string, source: string, selector: string, detail: string}} Finding */
28
+
29
+ /** @typedef {{readonly rgb: readonly number[], readonly value: string}} Page */
30
+
31
+ /**
32
+ * Why a value's color is unknowable here: a token set differently in sheets of unknown order, or
33
+ * a token this cascade never sets (an @import or link this script could not follow, a sheet only a
34
+ * component imports). @returns {string | null}
35
+ */
36
+ function unknowable({value, vars, uncertain}) {
37
+ const conflicting = referencedVars({value, vars}).find(name =>
38
+ uncertain.has(name),
39
+ );
40
+ if (conflicting)
41
+ return `${conflicting} is set to different values in stylesheets whose load order is unknown`;
42
+ const missing = unresolvedVars({value, vars})[0];
43
+ if (missing)
44
+ return `${missing} is not set in any stylesheet this check could tie to the rule`;
45
+ return null;
46
+ }
47
+
48
+ /**
49
+ * A pair read through a token whose value is unknown is not measured at all: a pass and a fail
50
+ * are equally unfounded, and skipping it once hid a real 2.85:1 FAIL behind a clean report. Text
51
+ * with no background of its own is measured against the page, so the page's tokens count too.
52
+ * @param {{rule: Rule, decl: Readonly<Record<string, string>>, vars: Readonly<Record<string, string>>, uncertain: ReadonlySet<string>, page: Page}} params
53
+ * @returns {Finding | null}
54
+ */
55
+ function unverifiedFinding({rule, decl, vars, uncertain, page}) {
56
+ const own = [decl.color, decl['background-color'], decl.background].join(
57
+ ' ',
58
+ );
59
+ const value = hasBackground(decl) ? own : `${own} ${page.value}`;
60
+ const reason = unknowable({value, vars, uncertain});
61
+ if (!reason) return null;
62
+ return {
63
+ level: 'WARN',
64
+ check: 'contrast',
65
+ source: rule.source,
66
+ selector: rule.selector,
67
+ detail: `unverified — ${reason}; measure the rendered page`,
68
+ };
69
+ }
70
+
71
+ /**
72
+ * @param {{rule: Rule, vars: Readonly<Record<string, string>>, uncertain: ReadonlySet<string>, page: Page, rootPx: number}} params
73
+ * @returns {Finding | null}
74
+ */
75
+ function contrastFinding({rule, vars, uncertain, page, rootPx}) {
76
+ if (UNMEASURED_STATE.test(rule.selector)) return null;
77
+ const decl = declarations(rule.body);
78
+ if (!decl.color) return null;
79
+ const unverified = unverifiedFinding({rule, decl, vars, uncertain, page});
80
+ if (unverified) return unverified;
81
+ const text = parseColor({value: decl.color, vars});
82
+ if (!text) return null;
83
+ const own = backgroundColor({decl, vars});
84
+ // A background this script cannot measure (gradient, image, translucent) is still the text's
85
+ // real backdrop — comparing against the page instead would be noise.
86
+ if (!own && hasBackground(decl)) return null;
87
+
88
+ const pair = {text, background: own ?? page.rgb};
89
+ const ratio = wcagRatio(pair);
90
+ if (!own && ratio < PAGE_PAIR_FLOOR) return null;
91
+ const size = textSize({decl, rootPx});
92
+ const needed = size === 'large' ? LARGE_RATIO : NORMAL_RATIO;
93
+ const shown = `${ratio.toFixed(2)}:1`;
94
+ const where = {source: rule.source, selector: rule.selector};
95
+ const largeNote = size === 'large' ? ' (large text)' : '';
96
+
97
+ if (own && size === 'unknown' && ratio >= LARGE_RATIO && ratio < needed) {
98
+ return {
99
+ level: 'WARN',
100
+ check: 'contrast',
101
+ ...where,
102
+ detail: `${shown} on its own background passes only as large text, and font-size ${decl['font-size']} depends on the parent — measure the rendered size`,
103
+ };
104
+ }
105
+ if (own && ratio < needed) {
106
+ return {
107
+ level: 'FAIL',
108
+ check: 'contrast',
109
+ ...where,
110
+ detail: `${shown} on its own background, needs ${needed}:1${largeNote}`,
111
+ };
112
+ }
113
+ if (ratio < needed) {
114
+ return {
115
+ level: 'WARN',
116
+ check: 'contrast',
117
+ ...where,
118
+ detail: `${shown} against the page background, needs ${needed}:1 — measure against the real parent`,
119
+ };
120
+ }
121
+ const lc = Math.abs(apcaLc(pair));
122
+ const apcaMin = size === 'large' ? LARGE_APCA : NORMAL_APCA;
123
+ if (lc >= apcaMin) return null;
124
+ return {
125
+ level: 'WARN',
126
+ check: 'apca',
127
+ ...where,
128
+ detail: `Lc ${lc.toFixed(0)}, color.md minimum Lc ${apcaMin}${largeNote}`,
129
+ };
130
+ }
131
+
132
+ /**
133
+ * @param {{rules: readonly Rule[], vars: Readonly<Record<string, string>>, uncertain: ReadonlySet<string>, page: Page, rootPx: number}} params
134
+ * @returns {readonly Finding[]}
135
+ */
136
+ export function checkContrast({rules, vars, uncertain, page, rootPx}) {
137
+ return rules.flatMap(rule => {
138
+ const finding = contrastFinding({rule, vars, uncertain, page, rootPx});
139
+ return finding ? [finding] : [];
140
+ });
141
+ }
@@ -0,0 +1,223 @@
1
+ // CSS reading for check.mjs: rules, declarations, tokens, and text size. A brace reader, not a CSS
2
+ // engine — it sees what each rule declares, not what cascades onto an element.
3
+ import {parseColor, resolveVars} from './color.mjs';
4
+
5
+ /** @typedef {{readonly selector: string, readonly body: string, readonly source: string}} Rule */
6
+
7
+ const BROWSER_ROOT_PX = 16;
8
+ const LARGE_TEXT_PX = 24;
9
+ const LARGE_BOLD_TEXT_PX = 18.66;
10
+ const BOLD_WEIGHT = 700;
11
+ // Where design tokens live: plain :root/html, and Tailwind v4's @theme block.
12
+ const TOKEN_SELECTORS = new Set([':root', 'html', '@theme']);
13
+ const PAGE_SELECTORS = new Set(['body', 'html', ':root']);
14
+ const IMPORTANT = /!important\s*$/i;
15
+
16
+ /** @param {string} css @returns {string} */
17
+ export function stripComments(css) {
18
+ return css.replace(/\/\*[\s\S]*?\*\//g, '');
19
+ }
20
+
21
+ /**
22
+ * Depth-0 `prelude { body }` blocks. A `;` at depth 0 ends a statement at-rule (`@import …;`,
23
+ * `@layer a, b;`) — without that, the statement became the next rule's prelude and swallowed it.
24
+ * Quoted strings are skipped: a `}` in `content: "}"` once ended its rule early.
25
+ */
26
+ function topLevelBlocks(css) {
27
+ const blocks = [];
28
+ let depth = 0;
29
+ let start = 0;
30
+ let bodyStart = 0;
31
+ let prelude = '';
32
+ let quote = '';
33
+ for (let index = 0; index < css.length; index++) {
34
+ const char = css[index];
35
+ if (quote) {
36
+ if (char === '\\') index++;
37
+ if (char === quote) quote = '';
38
+ continue;
39
+ }
40
+ if (char === '"' || char === "'") {
41
+ quote = char;
42
+ continue;
43
+ }
44
+ if (char === ';' && depth === 0) start = index + 1;
45
+ if (char === '{' && depth === 0) {
46
+ prelude = css.slice(start, index).trim();
47
+ bodyStart = index + 1;
48
+ }
49
+ if (char === '{') depth++;
50
+ if (char !== '}' || depth === 0) continue;
51
+ depth--;
52
+ if (depth !== 0) continue;
53
+ blocks.push({prelude, body: css.slice(bodyStart, index)});
54
+ start = index + 1;
55
+ }
56
+ return blocks;
57
+ }
58
+
59
+ /**
60
+ * `@layer` is read through and `@theme` kept as a token block. `@media`, `@supports`,
61
+ * `@container`, and keyframes are dropped with their contents: a conditional rule is not what
62
+ * the page shows by default.
63
+ */
64
+ function rulesFromBlock({prelude, body}) {
65
+ if (!prelude.startsWith('@')) return [{selector: prelude, body}];
66
+ if (/^@layer\b/i.test(prelude)) return parseRules(body);
67
+ if (/^@theme\b/i.test(prelude)) return [{selector: '@theme', body}];
68
+ return [];
69
+ }
70
+
71
+ /** Style rules in source order, without a source label. @param {string} css */
72
+ export function parseRules(css) {
73
+ return topLevelBlocks(css).flatMap(rulesFromBlock);
74
+ }
75
+
76
+ /** @typedef {{readonly name: string, readonly value: string, readonly important: boolean}} Declaration */
77
+
78
+ /** @param {string} body @returns {readonly Declaration[]} */
79
+ function declarationList(body) {
80
+ return body.split(';').flatMap(part => {
81
+ const colon = part.indexOf(':');
82
+ if (colon === -1) return [];
83
+ const raw = part.slice(colon + 1);
84
+ return [
85
+ {
86
+ name: part.slice(0, colon).trim().toLowerCase(),
87
+ value: raw.replace(IMPORTANT, '').trim(),
88
+ important: IMPORTANT.test(raw),
89
+ },
90
+ ];
91
+ });
92
+ }
93
+
94
+ /** @param {string} body @returns {Readonly<Record<string, string>>} */
95
+ export function declarations(body) {
96
+ return Object.fromEntries(
97
+ declarationList(body).map(({name, value}) => [name, value]),
98
+ );
99
+ }
100
+
101
+ /** @param {Rule} rule @returns {readonly string[]} */
102
+ function selectorsOf(rule) {
103
+ return rule.selector.split(',').map(selector => selector.trim());
104
+ }
105
+
106
+ /**
107
+ * Root tokens as the cascade resolves them: a later value wins unless an earlier one was
108
+ * `!important` and it is not. @param {readonly Rule[]} rules
109
+ */
110
+ export function rootVars(rules) {
111
+ const vars = {};
112
+ const important = new Set();
113
+ for (const rule of rules) {
114
+ if (!selectorsOf(rule).some(selector => TOKEN_SELECTORS.has(selector)))
115
+ continue;
116
+ for (const decl of declarationList(rule.body)) {
117
+ if (!decl.name.startsWith('--')) continue;
118
+ if (important.has(decl.name) && !decl.important) continue;
119
+ if (decl.important) important.add(decl.name);
120
+ vars[decl.name] = decl.value;
121
+ }
122
+ }
123
+ return vars;
124
+ }
125
+
126
+ /** A root font-size in px; `%`, `em`, and `rem` there resolve against the browser's 16px. */
127
+ function rootSizePx(value) {
128
+ const match = value.match(/^([\d.]+)(px|%|r?em)$/);
129
+ if (!match) return null;
130
+ const size = Number.parseFloat(match[1] ?? '');
131
+ if (match[2] === 'px') return size;
132
+ if (match[2] === '%') return (BROWSER_ROOT_PX * size) / 100;
133
+ return BROWSER_ROOT_PX * size;
134
+ }
135
+
136
+ /** The root font size `rem` resolves against: the last html/:root font-size, else 16px. */
137
+ export function rootFontSize(rules) {
138
+ let px = BROWSER_ROOT_PX;
139
+ for (const rule of rules) {
140
+ if (
141
+ !selectorsOf(rule).some(selector => /^(html|:root)$/.test(selector))
142
+ )
143
+ continue;
144
+ px = rootSizePx(declarations(rule.body)['font-size'] ?? '') ?? px;
145
+ }
146
+ return px;
147
+ }
148
+
149
+ /** @param {{decl: Readonly<Record<string, string>>, vars: Readonly<Record<string, string>>}} params */
150
+ export function backgroundColor({decl, vars}) {
151
+ const value = decl['background-color'] ?? decl.background;
152
+ if (!value || /gradient|url\(/i.test(resolveVars({value, vars})))
153
+ return null;
154
+ return parseColor({value: value.split(/\s+(?![^(]*\))/)[0] ?? '', vars});
155
+ }
156
+
157
+ /** @param {Readonly<Record<string, string>>} decl */
158
+ export function hasBackground(decl) {
159
+ const value =
160
+ decl['background-color'] ?? decl.background ?? decl['background-image'];
161
+ if (!value) return false;
162
+ return !/^(transparent|none|inherit|initial|unset)$/i.test(value.trim());
163
+ }
164
+
165
+ /**
166
+ * The last body/html/:root background, as the cascade resolves it, else white. `value` is what it
167
+ * was written as, so a page color read through an unknowable token can be reported as unverified.
168
+ * @returns {{readonly rgb: readonly number[], readonly value: string}}
169
+ */
170
+ export function pageBackground({rules, vars}) {
171
+ let page = {rgb: [1, 1, 1], value: ''};
172
+ for (const rule of rules) {
173
+ if (!selectorsOf(rule).some(selector => PAGE_SELECTORS.has(selector)))
174
+ continue;
175
+ const decl = declarations(rule.body);
176
+ const value = decl['background-color'] ?? decl.background ?? '';
177
+ if (!value) continue;
178
+ const rgb = backgroundColor({decl, vars});
179
+ if (rgb) page = {rgb, value};
180
+ if (!rgb && /var\(/.test(value)) page = {...page, value};
181
+ }
182
+ return page;
183
+ }
184
+
185
+ /**
186
+ * Tokens that sheets of unknown load order set to different values: which one wins is unknowable,
187
+ * so a pair measured through one is unverified. @param {readonly (readonly Rule[])[]} sheetRules
188
+ */
189
+ export function conflictingVars(sheetRules) {
190
+ const values = new Map();
191
+ for (const rules of sheetRules) {
192
+ for (const [name, value] of Object.entries(rootVars(rules))) {
193
+ values.set(name, new Set([...(values.get(name) ?? []), value]));
194
+ }
195
+ }
196
+ return new Set(
197
+ [...values].filter(([, set]) => set.size > 1).map(([name]) => name),
198
+ );
199
+ }
200
+
201
+ /** @param {string | undefined} value @returns {number} */
202
+ function fontWeight(value) {
203
+ if (value === 'bold' || value === 'bolder') return BOLD_WEIGHT;
204
+ return Number.parseInt(value ?? '', 10) || 400;
205
+ }
206
+
207
+ /**
208
+ * WCAG text size: 'large' (24px, or 18.66px bold), 'normal', or 'unknown' when the size depends on
209
+ * the parent (`em`, `%`, keywords, `clamp()`). No font-size at all is body text: 'normal'.
210
+ * @param {{decl: Readonly<Record<string, string>>, rootPx: number}} params
211
+ * @returns {'large' | 'normal' | 'unknown'}
212
+ */
213
+ export function textSize({decl, rootPx}) {
214
+ const value = decl['font-size'];
215
+ if (!value) return 'normal';
216
+ const match = value.match(/^([\d.]+)(px|rem)$/);
217
+ if (!match) return 'unknown';
218
+ const size = Number.parseFloat(match[1] ?? '');
219
+ const px = match[2] === 'px' ? size : size * rootPx;
220
+ if (px >= LARGE_TEXT_PX) return 'large';
221
+ const bold = fontWeight(decl['font-weight']) >= BOLD_WEIGHT;
222
+ return px >= LARGE_BOLD_TEXT_PX && bold ? 'large' : 'normal';
223
+ }
@@ -0,0 +1,152 @@
1
+ // The CSS named colors (CSS Color 4), as hex digits. `transparent` and `currentcolor` are left
2
+ // out on purpose: neither is a solid color this script can measure.
3
+ export const NAMED_COLORS = Object.freeze({
4
+ aliceblue: 'f0f8ff',
5
+ antiquewhite: 'faebd7',
6
+ aqua: '00ffff',
7
+ aquamarine: '7fffd4',
8
+ azure: 'f0ffff',
9
+ beige: 'f5f5dc',
10
+ bisque: 'ffe4c4',
11
+ black: '000000',
12
+ blanchedalmond: 'ffebcd',
13
+ blue: '0000ff',
14
+ blueviolet: '8a2be2',
15
+ brown: 'a52a2a',
16
+ burlywood: 'deb887',
17
+ cadetblue: '5f9ea0',
18
+ chartreuse: '7fff00',
19
+ chocolate: 'd2691e',
20
+ coral: 'ff7f50',
21
+ cornflowerblue: '6495ed',
22
+ cornsilk: 'fff8dc',
23
+ crimson: 'dc143c',
24
+ cyan: '00ffff',
25
+ darkblue: '00008b',
26
+ darkcyan: '008b8b',
27
+ darkgoldenrod: 'b8860b',
28
+ darkgray: 'a9a9a9',
29
+ darkgreen: '006400',
30
+ darkgrey: 'a9a9a9',
31
+ darkkhaki: 'bdb76b',
32
+ darkmagenta: '8b008b',
33
+ darkolivegreen: '556b2f',
34
+ darkorange: 'ff8c00',
35
+ darkorchid: '9932cc',
36
+ darkred: '8b0000',
37
+ darksalmon: 'e9967a',
38
+ darkseagreen: '8fbc8f',
39
+ darkslateblue: '483d8b',
40
+ darkslategray: '2f4f4f',
41
+ darkslategrey: '2f4f4f',
42
+ darkturquoise: '00ced1',
43
+ darkviolet: '9400d3',
44
+ deeppink: 'ff1493',
45
+ deepskyblue: '00bfff',
46
+ dimgray: '696969',
47
+ dimgrey: '696969',
48
+ dodgerblue: '1e90ff',
49
+ firebrick: 'b22222',
50
+ floralwhite: 'fffaf0',
51
+ forestgreen: '228b22',
52
+ fuchsia: 'ff00ff',
53
+ gainsboro: 'dcdcdc',
54
+ ghostwhite: 'f8f8ff',
55
+ gold: 'ffd700',
56
+ goldenrod: 'daa520',
57
+ gray: '808080',
58
+ green: '008000',
59
+ greenyellow: 'adff2f',
60
+ grey: '808080',
61
+ honeydew: 'f0fff0',
62
+ hotpink: 'ff69b4',
63
+ indianred: 'cd5c5c',
64
+ indigo: '4b0082',
65
+ ivory: 'fffff0',
66
+ khaki: 'f0e68c',
67
+ lavender: 'e6e6fa',
68
+ lavenderblush: 'fff0f5',
69
+ lawngreen: '7cfc00',
70
+ lemonchiffon: 'fffacd',
71
+ lightblue: 'add8e6',
72
+ lightcoral: 'f08080',
73
+ lightcyan: 'e0ffff',
74
+ lightgoldenrodyellow: 'fafad2',
75
+ lightgray: 'd3d3d3',
76
+ lightgreen: '90ee90',
77
+ lightgrey: 'd3d3d3',
78
+ lightpink: 'ffb6c1',
79
+ lightsalmon: 'ffa07a',
80
+ lightseagreen: '20b2aa',
81
+ lightskyblue: '87cefa',
82
+ lightslategray: '778899',
83
+ lightslategrey: '778899',
84
+ lightsteelblue: 'b0c4de',
85
+ lightyellow: 'ffffe0',
86
+ lime: '00ff00',
87
+ limegreen: '32cd32',
88
+ linen: 'faf0e6',
89
+ magenta: 'ff00ff',
90
+ maroon: '800000',
91
+ mediumaquamarine: '66cdaa',
92
+ mediumblue: '0000cd',
93
+ mediumorchid: 'ba55d3',
94
+ mediumpurple: '9370db',
95
+ mediumseagreen: '3cb371',
96
+ mediumslateblue: '7b68ee',
97
+ mediumspringgreen: '00fa9a',
98
+ mediumturquoise: '48d1cc',
99
+ mediumvioletred: 'c71585',
100
+ midnightblue: '191970',
101
+ mintcream: 'f5fffa',
102
+ mistyrose: 'ffe4e1',
103
+ moccasin: 'ffe4b5',
104
+ navajowhite: 'ffdead',
105
+ navy: '000080',
106
+ oldlace: 'fdf5e6',
107
+ olive: '808000',
108
+ olivedrab: '6b8e23',
109
+ orange: 'ffa500',
110
+ orangered: 'ff4500',
111
+ orchid: 'da70d6',
112
+ palegoldenrod: 'eee8aa',
113
+ palegreen: '98fb98',
114
+ paleturquoise: 'afeeee',
115
+ palevioletred: 'db7093',
116
+ papayawhip: 'ffefd5',
117
+ peachpuff: 'ffdab9',
118
+ peru: 'cd853f',
119
+ pink: 'ffc0cb',
120
+ plum: 'dda0dd',
121
+ powderblue: 'b0e0e6',
122
+ purple: '800080',
123
+ rebeccapurple: '663399',
124
+ red: 'ff0000',
125
+ rosybrown: 'bc8f8f',
126
+ royalblue: '4169e1',
127
+ saddlebrown: '8b4513',
128
+ salmon: 'fa8072',
129
+ sandybrown: 'f4a460',
130
+ seagreen: '2e8b57',
131
+ seashell: 'fff5ee',
132
+ sienna: 'a0522d',
133
+ silver: 'c0c0c0',
134
+ skyblue: '87ceeb',
135
+ slateblue: '6a5acd',
136
+ slategray: '708090',
137
+ slategrey: '708090',
138
+ snow: 'fffafa',
139
+ springgreen: '00ff7f',
140
+ steelblue: '4682b4',
141
+ tan: 'd2b48c',
142
+ teal: '008080',
143
+ thistle: 'd8bfd8',
144
+ tomato: 'ff6347',
145
+ turquoise: '40e0d0',
146
+ violet: 'ee82ee',
147
+ wheat: 'f5deb3',
148
+ white: 'ffffff',
149
+ whitesmoke: 'f5f5f5',
150
+ yellow: 'ffff00',
151
+ yellowgreen: '9acd32',
152
+ });
@@ -0,0 +1,61 @@
1
+ // `check.mjs --pair <text> <background> …`: contrast for candidate colors before they are written.
2
+ // Live recolor runs wrote their own OKLCH and APCA math to try palettes, spent several calls on it,
3
+ // and got APCA numbers that disagreed with this script's. This is the same math the check uses.
4
+ import {apcaLc, parseColor, wcagRatio} from './color.mjs';
5
+ import {
6
+ LARGE_APCA,
7
+ LARGE_RATIO,
8
+ NORMAL_APCA,
9
+ NORMAL_RATIO,
10
+ } from './contrast.mjs';
11
+
12
+ /** @typedef {{readonly text: string, readonly background: string}} PairInput */
13
+
14
+ /** @param {readonly string[]} values text, background, text, background, … */
15
+ export function pairsFrom(values) {
16
+ return values.flatMap((text, index) => {
17
+ const background = values[index + 1];
18
+ if (index % 2 !== 0 || background === undefined) return [];
19
+ return [{text, background}];
20
+ });
21
+ }
22
+
23
+ /**
24
+ * Same levels as the full check: a WCAG miss is a FAIL, an APCA-only miss a WARN.
25
+ * @param {{label: string, ratio: number, lc: number, minRatio: number, minLc: number}} params
26
+ */
27
+ function verdict({label, ratio, lc, minRatio, minLc}) {
28
+ if (ratio < minRatio) return `${label} FAIL (needs ${minRatio}:1)`;
29
+ if (lc < minLc) return `${label} WARN (APCA needs Lc ${minLc})`;
30
+ return `${label} pass`;
31
+ }
32
+
33
+ /** @param {PairInput} pair @returns {string} */
34
+ export function describePair({text, background}) {
35
+ const textRgb = parseColor({value: text, vars: {}});
36
+ const backgroundRgb = parseColor({value: background, vars: {}});
37
+ const name = `${text} on ${background}`;
38
+ if (!textRgb || !backgroundRgb) {
39
+ return `${name}: not measured — use an opaque hex, rgb(), hsl(), oklch(), or named color`;
40
+ }
41
+ const pair = {text: textRgb, background: backgroundRgb};
42
+ const ratio = wcagRatio(pair);
43
+ const lc = Math.abs(apcaLc(pair));
44
+ return [
45
+ `${name}: ${ratio.toFixed(2)}:1, APCA Lc ${lc.toFixed(0)}`,
46
+ verdict({
47
+ label: 'body text',
48
+ ratio,
49
+ lc,
50
+ minRatio: NORMAL_RATIO,
51
+ minLc: NORMAL_APCA,
52
+ }),
53
+ verdict({
54
+ label: 'large text',
55
+ ratio,
56
+ lc,
57
+ minRatio: LARGE_RATIO,
58
+ minLc: LARGE_APCA,
59
+ }),
60
+ ].join(' · ');
61
+ }
@@ -0,0 +1,27 @@
1
+ // design-system.html must render from the project's own stylesheet (system.md). A wrong relative
2
+ // link renders it unstyled, and live runs found that only by screenshotting the preview: a
3
+ // browser round-trip and a vision call per fix. A missing local stylesheet is checked directly.
4
+ import {existsSync, readFileSync} from 'node:fs';
5
+ import {dirname, join, resolve} from 'node:path';
6
+
7
+ const PREVIEW = join('.commandcode', 'design', 'design-system.html');
8
+ const LINKED_CSS = /<link\b[^>]*href=["']([^"']+\.css)["']/gi;
9
+
10
+ /** @typedef {import('./contrast.mjs').Finding} Finding */
11
+
12
+ /** @param {string} root the project directory @returns {readonly Finding[]} */
13
+ export function checkPreviewLinks(root) {
14
+ const preview = join(root, PREVIEW);
15
+ if (!existsSync(preview)) return [];
16
+ return [...readFileSync(preview, 'utf8').matchAll(LINKED_CSS)]
17
+ .map(([, href = '']) => href)
18
+ .filter(href => !/^(https?:)?\/\//.test(href))
19
+ .filter(href => !existsSync(resolve(dirname(preview), href)))
20
+ .map(href => ({
21
+ level: 'FAIL',
22
+ check: 'preview',
23
+ source: preview,
24
+ selector: `<link href="${href}">`,
25
+ detail: `links ${href}, which does not exist from .commandcode/design/ — the preview renders without the project's stylesheet`,
26
+ }));
27
+ }