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,184 @@
1
+ # Voice `/design voice`
2
+
3
+ Brand surfaces are judged before they are understood. A visitor arrives half-ready to leave. The page has to earn the next second.
4
+
5
+ Here, design is not serving a task. The design is the product.
6
+
7
+ ---
8
+
9
+ ## Discipline files
10
+
11
+ Voice drives the brand identity pass — consult these when each dimension comes up, not as additional work to run on top:
12
+
13
+ - [color.md](color.md) — for correct palette construction when committing to a brand hue
14
+ - [typeset.md](typeset.md) — for correct type hierarchy when building the brand voice and display scale
15
+ - [motion.md](motion.md) — for correct timing and personality when adding expressive animation
16
+ - [border.md](border.md) — for correct edge language when choosing frame and art-direction treatments
17
+ - [shadow.md](shadow.md) — for correct depth model when adding atmospheric lighting or elevation
18
+ - [media.md](media.md) — for art-directing, sourcing, and verifying real photos and video when the subject is physical
19
+
20
+ ---
21
+
22
+ ## Composition Starts With The Visitor's Job
23
+
24
+ A brand surface still has work to do.
25
+
26
+ If the visitor must decide, I narrow the page around claim, proof, trust, and action.
27
+
28
+ If the visitor must learn, I build editorial flow with strong pacing and readable depth.
29
+
30
+ If the visitor must explore, I make product paths, examples, filters, or galleries feel open and reversible.
31
+
32
+ If the visitor must compare, I make differences visible with matrices, side-by-side proof, or ranked value.
33
+
34
+ If the visitor must believe, I lead with evidence, artifact, image, and specificity before ornament.
35
+
36
+ The brand voice changes the skin. The visitor's job chooses the composition.
37
+
38
+ ---
39
+
40
+ ## Prompt Invariants Are Sacred
41
+
42
+ If the prompt supplies a name, that name is the brand. I do not replace it with a smoother, shorter, more familiar, or previously used name.
43
+
44
+ The first viewport must prove this is the named thing. Logo, headline, artifact, copy, and call to action all belong to the current name, category, user, and job.
45
+
46
+ I do not let old examples, earlier outputs, familiar startup tropes, or category clichés rename the product or choose the artifact.
47
+
48
+ ---
49
+
50
+ ## Landing Pages Need A Specific Proof Object
51
+
52
+ A landing page is not complete because it has a headline and an abstract product panel.
53
+
54
+ I choose one proof object the visitor can inspect. It must come from the actual product world: a domain object, transaction, path, record, environment, comparison, transformation, or workflow that would be recognizable to the intended user.
55
+
56
+ That proof object drives the composition. It is not decoration beside the headline.
57
+
58
+ ---
59
+
60
+ ## Application Bar
61
+
62
+ `/design voice` applies brand character across the visible surface. It is not a small garnish pass.
63
+
64
+ At minimum, I verify the first viewport, proof object, headline voice, type choice, color behavior, CTA language, imagery or artifact treatment, and one memorable brand-specific detail.
65
+
66
+ Adding a tiny logo mark, accent square, decorative pattern, or one hover flourish is not enough.
67
+
68
+ ---
69
+
70
+ ## The Register
71
+
72
+ I use this file for marketing pages, landing pages, campaign pages, portfolios, about pages, product stories, and long-form surfaces where impression is the work.
73
+
74
+ Brand does not mean one aesthetic. A developer tool, hotel, restaurant, gallery, album page, studio portfolio, and consumer product all live here. They need different lanes.
75
+
76
+ I name the lane before I design.
77
+
78
+ - Editorial, cultural, luxury
79
+ - Technical, developer, systems-minded
80
+ - Consumer, lifestyle, tactile
81
+ - Studio, portfolio, experimental
82
+ - Campaign, launch, moment-driven
83
+
84
+ If I cannot name the lane in one sentence, the surface is not ready.
85
+
86
+ ---
87
+
88
+ ## The First 1.5 Seconds
89
+
90
+ The first viewport must commit.
91
+
92
+ The user should quickly know the category, feel the voice, and see a reason to continue. Average is not neutral anymore. Average reads generated.
93
+
94
+ Restraint is allowed only when it is visibly chosen. Timid restraint is absence.
95
+
96
+ ---
97
+
98
+ ## Type Carries Voice
99
+
100
+ I start with physical words, not generic adjectives. Cold, precise, slightly strange. Warm, tactile, hand-stamped. Expensive, slow, cinematic.
101
+
102
+ Then I pick type that feels like an object from that world. A field guide. A receipt. A gallery label. A club poster. A terminal manual. A bottle label. A children's science kit.
103
+
104
+ I reject the obvious first pass when it smells like the current AI design pile. A serif is not automatically elegant. Mono is not automatically technical. A rounded sans is not automatically friendly.
105
+
106
+ ---
107
+
108
+ ## Color Must Commit
109
+
110
+ Brand pages can use more color than product surfaces. Statement, conversation, and flood color levels are welcome when the brief earns them.
111
+
112
+ I name a real reference before choosing a hue. Unnamed ambition turns beige.
113
+
114
+ If the brand needs voice, I do not hide behind a neutral page with one safe accent. If the brand needs quiet, I make the quiet exact.
115
+
116
+ ---
117
+
118
+ ## Composition Has To Make A Choice
119
+
120
+ The centered stack with three feature cards is the default nobody remembers.
121
+
122
+ I choose a composition with a point of view:
123
+
124
+ - Asymmetric when the brand needs energy
125
+ - Strict grid when the brand needs rigor
126
+ - Editorial pacing when the story needs breath
127
+ - Full-bleed image when the subject is physical
128
+ - Type-led minimalism when the words are strong enough
129
+ - Section-by-section art direction when the narrative changes register
130
+
131
+ I do not split the difference. Half-asymmetric looks broken. Half-editorial looks like a costume.
132
+
133
+ ---
134
+
135
+ ## Imagery
136
+
137
+ If the subject is physical, I ship imagery. Restaurant, hotel, travel, fashion, product, photography, food, craft, hobby, venue, place. No colored rectangle can stand in for the thing itself. A broken image icon stands in for it even worse — see [media.md](media.md) for how I source and verify a real photo or video instead of guessing a URL.
138
+
139
+ One decisive image beats five filler images. I search for the specific object and situation, not the category. Alt text is part of the brand voice.
140
+
141
+ Tech and developer brands can be type-led, code-led, or diagram-led. That is a lane, not an excuse to leave the page visually empty.
142
+
143
+ ---
144
+
145
+ ## Motion Permission
146
+
147
+ Brand can choreograph when choreography deepens the mood.
148
+
149
+ Slow editorial scroll, a single strong reveal, type that arrives with intention, section transitions that feel like pacing. These can work. Scattered motion on every card does not.
150
+
151
+ Sometimes the most confident brand motion is none.
152
+
153
+ ---
154
+
155
+ ## What I Refuse
156
+
157
+ - Mono everywhere because the brief says engineer
158
+ - Calling tiny decorative touches a brand pass
159
+ - Brand moments that cannot be seen in the rendered page
160
+ - Editorial magazine styling on a brand that is not editorial
161
+ - Rounded-square icons above every heading
162
+ - Hero plus three identical cards as the whole concept
163
+ - A palette that is guessable from the category
164
+ - Zero imagery for a physical subject
165
+ - A font chosen because it appeared in the last generated landing page
166
+ - Motion that exists only to make the page feel less empty
167
+
168
+ ---
169
+
170
+ ## How I Know The Brand Surface Works
171
+
172
+ - Brand character is visible before I explain it
173
+ - The proof object belongs to this product and drives the page
174
+ - The first viewport has a recognizable point of view
175
+ - The lane fits the subject
176
+ - Type, color, image, and layout sound like the same brand
177
+ - The page would be remembered after two seconds
178
+ - It does not look like the median generated landing page
179
+ - The visitor has a reason to scroll
180
+
181
+ STRICT RULE — NEVER BREAK THIS
182
+ Do not create report.md, any kind of report, summary, analysis file,
183
+ or extra documentation. This applies every time this file is used.
184
+ Generate no reports unless explicitly asked.
@@ -0,0 +1,174 @@
1
+ # UX Writing `/design writing`
2
+
3
+ Words are interface. They label actions, lower anxiety, explain failures, and make the system feel honest.
4
+
5
+ I write like the product knows what it is doing.
6
+
7
+ ---
8
+
9
+ ## Writing Follows Composition
10
+
11
+ The work pattern decides which words matter most.
12
+
13
+ Monitor writing names status, freshness, severity, and next attention.
14
+
15
+ Operate writing names commands, object state, immediate feedback, and recovery.
16
+
17
+ Compare writing names criteria, differences, ranking, and filters.
18
+
19
+ Configure writing names settings, dependencies, validation, preview, and commit.
20
+
21
+ Learn writing names progress, orientation, examples, and completion.
22
+
23
+ Decide writing names claim, proof, risk, trust, and the action.
24
+
25
+ Explore writing names search, filter, category, result, and reset.
26
+
27
+ I do not write generic card subtitles to fill a grid. Copy earns its place by helping the work.
28
+
29
+ ---
30
+
31
+ ## Application Bar
32
+
33
+ `/design writing` rewrites interface copy in place. It is not advice about copy.
34
+
35
+ At minimum, I inspect buttons, navigation, headings, labels, helper text, empty states, loading states, success states, errors, destructive moments, links, alt text, and repeated terminology where they exist.
36
+
37
+ If I only rewrite a headline or tagline while operational copy remains vague, the writing pass failed.
38
+
39
+ ---
40
+
41
+ ## Buttons
42
+
43
+ A button names the action it performs.
44
+
45
+ I use a clear verb and, when needed, a clear object: save changes, delete project, create account, send invite. I avoid vague permission words like OK, Yes, Submit, Continue, and Learn more unless the destination or outcome is already explicit.
46
+
47
+ For destructive actions, I name the destruction. If five items will be deleted, the button says that.
48
+
49
+ ---
50
+
51
+ ## Errors
52
+
53
+ An error is a recovery path, not a scolding.
54
+
55
+ It should tell the user what happened, why it happened when that helps, and what to do next. It keeps their input. It appears where the fix can happen. It does not blame the user.
56
+
57
+ I do not make errors cute. Frustrated users need help, not personality theater.
58
+
59
+ ---
60
+
61
+ ## Empty States
62
+
63
+ An empty state should teach the space.
64
+
65
+ It says what belongs there, why it matters, and what action fills it. Search empties suggest a different query or clearing filters. First-use empties guide setup. Permission empties explain access. Error empties offer recovery.
66
+
67
+ "No items" is almost never enough.
68
+
69
+ ---
70
+
71
+ ## Loading
72
+
73
+ Loading copy names the work being done.
74
+
75
+ Saving, uploading, analyzing, syncing, importing, checking. If the duration is knowable, I set an expectation. If progress is measurable, I show it. If the wait is long, I give useful context rather than filler.
76
+
77
+ I avoid generic machine-flavored jokes. Specific beats cute.
78
+
79
+ ---
80
+
81
+ ## Success
82
+
83
+ Success copy confirms the action and then gets out of the way.
84
+
85
+ It can add a next implication when useful: password updated, use it next time you sign in. Project created, invite your team. Changes saved. Short, calm, done.
86
+
87
+ ---
88
+
89
+ ## Labels And Help
90
+
91
+ Labels stay visible. Placeholders show examples or formats. Hint text explains why the system asks or what format it expects.
92
+
93
+ Icon-only controls need accessible names. Link text stands alone. Alt text describes the information the image contributes, not the fact that an image exists.
94
+
95
+ ---
96
+
97
+ ## Settings And Toggles
98
+
99
+ A toggle is labeled for what happens when it is **on**: "Send read receipts". The user infers the off state. Labeling the negative ("Don't send read receipts") turns every interaction into a double negative.
100
+
101
+ When copy refers to another setting, I link straight to it. A "Notification settings" link beats "Go to Settings > Notifications > Email", which goes stale the moment the navigation changes.
102
+
103
+ ---
104
+
105
+ ## Links And Flow Vocabulary
106
+
107
+ Link text has to make sense out of context, because screen-reader users navigate by a list of the page's links. "Read the billing docs", never "Click here" — which also assumes a mouse. A bare "Learn more" fails the moment two of them appear on one page; each gets a suffix: "Learn more about exports".
108
+
109
+ A multi-step flow uses one vocabulary throughout: one word to enter, one word to advance — "Continue" or "Next", picked once and kept — and one word to finish. Alternating synonyms across steps makes users wonder whether the buttons do different things.
110
+
111
+ A confirmation's buttons restate what is about to happen, so the user can answer the dialog from the buttons alone without parsing the paragraph above them. "Delete this project?" is answered with **Delete project** and **Cancel** — never Yes and No, which force the user back up to the question to work out which one is which.
112
+
113
+ I address the reader as "you", not "the user". In errors I avoid "we", which reads as deflection: "Unable to load content" beats "We're having trouble loading this content".
114
+
115
+ ---
116
+
117
+ ## Voice And Tone
118
+
119
+ Voice stays consistent. Tone adapts to the moment.
120
+
121
+ Product UI is direct, calm, specific, and consistent. Brand surfaces can be more expressive, but still concrete. Errors are sober. Success can be warmer. Destructive moments are plain.
122
+
123
+ I use the same noun for the same concept everywhere. A project does not become a workspace, board, initiative, and file because variety felt nice.
124
+
125
+ ---
126
+
127
+ ## Translation
128
+
129
+ I leave room for expansion. German and Finnish get longer. Chinese may use fewer characters but not always less width. Word order changes. Plural rules change.
130
+
131
+ I keep full sentences as translation units. I avoid string fragments that assume English grammar. I avoid abbreviations when clarity matters.
132
+
133
+ I never build a sentence by concatenating fragments around a variable — `"You have " + n + " new messages"` assumes English word order and English plural rules, and breaks in most other languages. Full templated strings with proper pluralization instead. I also skip idioms, colloquialisms, and humor that will not survive translation, and I match the verb to the input device: "tap" on touch, "click" with a pointer, "select" when both are possible.
134
+
135
+ ---
136
+
137
+ ## Punctuation
138
+
139
+ Sentence case is the default. Labels usually do not need periods. Sentences do. Exclamation points are rare. Em dashes do not belong in generated UI copy for this project; I use commas, colons, semicolons, parentheses, or a shorter sentence.
140
+
141
+ ---
142
+
143
+ ## What I Refuse
144
+
145
+ - OK, Submit, Click here, or vague Learn more
146
+ - Copy advice without applying copy changes
147
+ - Rewriting only marketing text while UI states stay vague
148
+ - Placeholder-only labels
149
+ - "Something went wrong" with no next move
150
+ - Humor in errors
151
+ - Exclamation points as energy
152
+ - Jargon without context
153
+ - Different terms for the same object
154
+ - Redundant intros that restate headings
155
+ - Copy that explains a bad design instead of fixing it
156
+
157
+ ---
158
+
159
+ ## How I Know The Writing Works
160
+
161
+ - Copy changes are applied in the actual interface
162
+ - Critical states have specific words, not placeholders
163
+ - Every action says what happens
164
+ - Every error helps recovery
165
+ - Every empty state points somewhere useful
166
+ - Loading copy names the actual work
167
+ - Terminology stays consistent
168
+ - The tone fits the user's emotional state
169
+ - Translation will not shatter the layout
170
+
171
+ STRICT RULE — NEVER BREAK THIS
172
+ Do not create report.md, any kind of report, summary, analysis file,
173
+ or extra documentation. This applies every time this file is used.
174
+ Generate no reports unless explicitly asked.
@@ -0,0 +1,213 @@
1
+ // Color math and parsing for check.mjs. A color is gamma-encoded sRGB, each channel 0–1.
2
+ import {NAMED_COLORS} from './named-colors.mjs';
3
+
4
+ /** @typedef {readonly number[]} Rgb */
5
+ /** @typedef {{readonly rgb: Rgb, readonly alpha: number}} Color */
6
+ /** @typedef {Readonly<Record<string, string>>} Vars */
7
+
8
+ const MAX_VAR_DEPTH = 12;
9
+ // `#abc`, `rgb(…)`, and bare words — a word only counts when it is a named color.
10
+ const COLOR_LITERAL =
11
+ /#[0-9a-f]{3,8}\b|(?:rgba?|hsla?|oklch)\([^)]*\)|\b[a-z]+\b/gi;
12
+ // Not colors: a path such as url("blue/blue.webp") or a quoted string.
13
+ const NON_COLOR_TEXT = /url\([^)]*\)|"[^"]*"|'[^']*'/gi;
14
+ const VAR_NAME = /var\(\s*(--[\w-]+)/g;
15
+ const VAR_REFERENCE =
16
+ /var\(\s*(--[\w-]+)\s*(?:,\s*([^()]*(?:\([^()]*\)[^()]*)*))?\)/g;
17
+
18
+ /** @param {number} c @returns {number} */
19
+ function toLinear(c) {
20
+ return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
21
+ }
22
+
23
+ /** @param {number} c @returns {number} */
24
+ function toGamma(c) {
25
+ const clamped = Math.min(Math.max(c, 0), 1);
26
+ return clamped <= 0.0031308
27
+ ? clamped * 12.92
28
+ : 1.055 * clamped ** (1 / 2.4) - 0.055;
29
+ }
30
+
31
+ /** @param {{l: number, c: number, h: number}} oklch @returns {Rgb} */
32
+ function oklchToRgb({l, c, h}) {
33
+ const a = c * Math.cos((h * Math.PI) / 180);
34
+ const b = c * Math.sin((h * Math.PI) / 180);
35
+ const l1 = (l + 0.3963377774 * a + 0.2158037573 * b) ** 3;
36
+ const m1 = (l - 0.1055613458 * a - 0.0638541728 * b) ** 3;
37
+ const s1 = (l - 0.0894841775 * a - 1.291485548 * b) ** 3;
38
+ return [
39
+ 4.0767416621 * l1 - 3.3077115913 * m1 + 0.2309699292 * s1,
40
+ -1.2684380046 * l1 + 2.6097574011 * m1 - 0.3413193965 * s1,
41
+ -0.0041960863 * l1 - 0.7034186147 * m1 + 1.707614701 * s1,
42
+ ].map(toGamma);
43
+ }
44
+
45
+ /** Gamma sRGB → OKLCH, for hue and chroma checks. @param {Rgb} rgb */
46
+ export function rgbToOklch(rgb) {
47
+ const [r, g, b] = rgb.map(toLinear);
48
+ const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
49
+ const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
50
+ const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
51
+ const L = 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s;
52
+ const A = 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s;
53
+ const B = 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s;
54
+ const hue = ((Math.atan2(B, A) * 180) / Math.PI + 360) % 360;
55
+ return {l: L, c: Math.hypot(A, B), h: hue};
56
+ }
57
+
58
+ /** @param {{h: number, s: number, l: number}} hsl @returns {Rgb} */
59
+ function hslToRgb({h, s, l}) {
60
+ const k = n => (n + h / 30) % 12;
61
+ const a = s * Math.min(l, 1 - l);
62
+ return [0, 8, 4].map(
63
+ n => l - a * Math.max(-1, Math.min(k(n) - 3, 9 - k(n), 1)),
64
+ );
65
+ }
66
+
67
+ /** @param {{text: Rgb, background: Rgb}} pair @returns {number} */
68
+ export function wcagRatio({text, background}) {
69
+ const lum = rgb => {
70
+ const [r, g, b] = rgb.map(toLinear);
71
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b;
72
+ };
73
+ const [hi, lo] = [lum(text), lum(background)].sort((x, y) => y - x);
74
+ return (hi + 0.05) / (lo + 0.05);
75
+ }
76
+
77
+ /** APCA-W3 0.0.98G — the measure color.md defaults to. @param {{text: Rgb, background: Rgb}} pair */
78
+ export function apcaLc({text, background}) {
79
+ const y = ([r, g, b]) => {
80
+ const raw =
81
+ 0.2126729 * r ** 2.4 + 0.7151522 * g ** 2.4 + 0.072175 * b ** 2.4;
82
+ // biome-ignore lint/suspicious/noApproximativeNumericConstant: APCA-W3 specifies blkClmp = 1.414 exactly; Math.SQRT2 would change the published formula.
83
+ return raw < 0.022 ? raw + (0.022 - raw) ** 1.414 : raw;
84
+ };
85
+ const yText = y(text);
86
+ const yBackground = y(background);
87
+ if (Math.abs(yBackground - yText) < 0.0005) return 0;
88
+ if (yBackground > yText) {
89
+ const sapc = (yBackground ** 0.56 - yText ** 0.57) * 1.14;
90
+ return sapc < 0.1 ? 0 : (sapc - 0.027) * 100;
91
+ }
92
+ const sapc = (yBackground ** 0.65 - yText ** 0.62) * 1.14;
93
+ return sapc > -0.1 ? 0 : (sapc + 0.027) * 100;
94
+ }
95
+
96
+ /** @param {{value: string, vars: Vars, depth?: number}} params @returns {string} */
97
+ export function resolveVars({value, vars, depth = 0}) {
98
+ if (depth > MAX_VAR_DEPTH) return value;
99
+ const next = value.replace(
100
+ VAR_REFERENCE,
101
+ (_, name, fallback) => vars[name] ?? fallback ?? '',
102
+ );
103
+ if (next === value) return next;
104
+ return resolveVars({value: next, vars, depth: depth + 1});
105
+ }
106
+
107
+ /** Every custom property a value reads, through the tokens it points at. */
108
+ export function referencedVars({value, vars, depth = 0}) {
109
+ if (depth > MAX_VAR_DEPTH) return [];
110
+ return [...value.matchAll(VAR_NAME)].flatMap(([, name = '']) => [
111
+ name,
112
+ ...referencedVars({value: vars[name] ?? '', vars, depth: depth + 1}),
113
+ ]);
114
+ }
115
+
116
+ /**
117
+ * Tokens a value reads that this cascade never sets and that have no fallback: the color is
118
+ * defined somewhere this script did not see, so it cannot be measured.
119
+ */
120
+ export function unresolvedVars({value, vars, depth = 0}) {
121
+ if (depth > MAX_VAR_DEPTH) return [];
122
+ return [...value.matchAll(VAR_REFERENCE)].flatMap(
123
+ ([, name = '', fallback]) => {
124
+ const set = vars[name];
125
+ if (set !== undefined)
126
+ return unresolvedVars({value: set, vars, depth: depth + 1});
127
+ if (fallback === undefined) return [name];
128
+ return unresolvedVars({value: fallback, vars, depth: depth + 1});
129
+ },
130
+ );
131
+ }
132
+
133
+ /** `50%` → 0.5 × scale; a bare number is returned as is. @param {{token: string, scale?: number}} params */
134
+ function parseNumber({token, scale = 1}) {
135
+ const text = token.trim();
136
+ if (text.endsWith('%')) return (Number.parseFloat(text) / 100) * scale;
137
+ return Number.parseFloat(text);
138
+ }
139
+
140
+ /** HSL saturation and lightness: `40%`, or a bare `40` (CSS Color 4) — both mean 0.4. */
141
+ function parseHslPercent(token) {
142
+ return Number.parseFloat(token) / 100;
143
+ }
144
+
145
+ /** @param {string} digits @returns {Color | null} */
146
+ function readHex(digits) {
147
+ if (![3, 4, 6, 8].includes(digits.length)) return null;
148
+ const full =
149
+ digits.length <= 4 ? [...digits].map(d => d + d).join('') : digits;
150
+ const channels = [0, 2, 4, 6].map(
151
+ i => Number.parseInt(full.slice(i, i + 2), 16) / 255,
152
+ );
153
+ const alpha = full.length === 8 ? (channels[3] ?? 1) : 1;
154
+ return {rgb: channels.slice(0, 3), alpha};
155
+ }
156
+
157
+ /** @param {{space: string, parts: readonly string[]}} params @returns {Rgb} */
158
+ function channelsToRgb({space, parts}) {
159
+ const [first = '', second = '', third = ''] = parts;
160
+ if (space.startsWith('rgb')) {
161
+ return [first, second, third].map(part =>
162
+ part.endsWith('%')
163
+ ? parseNumber({token: part})
164
+ : Number.parseFloat(part) / 255,
165
+ );
166
+ }
167
+ if (space.startsWith('hsl')) {
168
+ return hslToRgb({
169
+ h: Number.parseFloat(first),
170
+ s: parseHslPercent(second),
171
+ l: parseHslPercent(third),
172
+ });
173
+ }
174
+ return oklchToRgb({
175
+ l: parseNumber({token: first}),
176
+ c: parseNumber({token: second, scale: 0.4}),
177
+ h: Number.parseFloat(third),
178
+ });
179
+ }
180
+
181
+ /** Any color value, translucent or not, or null (gradient, keyword, unknown). */
182
+ function readColor({value, vars}) {
183
+ const text = resolveVars({value, vars}).trim().toLowerCase();
184
+ if (Object.hasOwn(NAMED_COLORS, text)) return readHex(NAMED_COLORS[text]);
185
+ const hex = text.match(/^#([0-9a-f]{3,8})$/);
186
+ if (hex) return readHex(hex[1] ?? '');
187
+ const fn = text.match(/^(rgba?|hsla?|oklch)\(([^)]*)\)$/);
188
+ if (!fn) return null;
189
+ const [channels = '', slashAlpha] = (fn[2] ?? '').split('/');
190
+ const parts = channels.split(/[\s,]+/).filter(Boolean);
191
+ if (parts.length < 3) return null;
192
+ const alphaToken = slashAlpha ?? parts[3];
193
+ const alpha = alphaToken ? parseNumber({token: alphaToken}) : 1;
194
+ return {rgb: channelsToRgb({space: fn[1] ?? '', parts}), alpha};
195
+ }
196
+
197
+ /** A solid, opaque color, or null. @param {{value: string, vars: Vars}} params @returns {Rgb | null} */
198
+ export function parseColor({value, vars}) {
199
+ const color = readColor({value, vars});
200
+ if (!color || color.alpha < 1) return null;
201
+ return color.rgb;
202
+ }
203
+
204
+ /** Every color in a value, solid or not — for hue sweeps inside gradients and shadows. */
205
+ export function colorsIn({value, vars}) {
206
+ const literals =
207
+ resolveVars({value, vars})
208
+ .replace(NON_COLOR_TEXT, ' ')
209
+ .match(COLOR_LITERAL) ?? [];
210
+ return literals
211
+ .map(literal => readColor({value: literal, vars: {}})?.rgb ?? null)
212
+ .filter(rgb => rgb !== null);
213
+ }