@adea-ai/ui 0.124.0 → 0.125.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.
Files changed (44) hide show
  1. package/dist/NOTICE +18 -0
  2. package/dist/components/theme/theme-document.d.ts +6 -0
  3. package/dist/components/theme/theme-document.d.ts.map +1 -1
  4. package/dist/components/theme/theme-document.js +7 -2
  5. package/dist/components/theme/theme-document.js.map +1 -1
  6. package/dist/components/theme/theme-persistence.d.ts.map +1 -1
  7. package/dist/components/theme/theme-persistence.js +2 -1
  8. package/dist/components/theme/theme-persistence.js.map +1 -1
  9. package/dist/components/theme/theme-provider.d.ts +9 -0
  10. package/dist/components/theme/theme-provider.d.ts.map +1 -1
  11. package/dist/components/theme/theme-provider.js +13 -3
  12. package/dist/components/theme/theme-provider.js.map +1 -1
  13. package/dist/components/theme/theme-state.d.ts +27 -2
  14. package/dist/components/theme/theme-state.d.ts.map +1 -1
  15. package/dist/components/theme/theme-state.js +20 -2
  16. package/dist/components/theme/theme-state.js.map +1 -1
  17. package/dist/index.d.ts +1 -0
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +2 -1
  20. package/dist/lib/accent-roles.d.ts +124 -0
  21. package/dist/lib/accent-roles.d.ts.map +1 -0
  22. package/dist/lib/accent-roles.js +163 -0
  23. package/dist/lib/accent-roles.js.map +1 -0
  24. package/dist/lib/themes.d.ts +23 -1
  25. package/dist/lib/themes.d.ts.map +1 -1
  26. package/dist/lib/themes.js +23 -13
  27. package/dist/lib/themes.js.map +1 -1
  28. package/dist/r/lib.json +5 -0
  29. package/dist/r/registry.json +5 -0
  30. package/dist/r/src/components/theme/theme-document.ts +18 -2
  31. package/dist/r/src/components/theme/theme-persistence.ts +5 -2
  32. package/dist/r/src/components/theme/theme-provider.tsx +22 -1
  33. package/dist/r/src/components/theme/theme-state.ts +52 -3
  34. package/dist/r/src/lib/accent-roles.ts +338 -0
  35. package/dist/r/src/lib/themes.ts +44 -19
  36. package/package.json +1 -1
  37. package/registry.json +5 -0
  38. package/src/components/theme/theme-document.ts +18 -2
  39. package/src/components/theme/theme-persistence.ts +5 -2
  40. package/src/components/theme/theme-provider.tsx +22 -1
  41. package/src/components/theme/theme-state.ts +52 -3
  42. package/src/index.ts +8 -0
  43. package/src/lib/accent-roles.ts +338 -0
  44. package/src/lib/themes.ts +44 -19
@@ -0,0 +1,124 @@
1
+ import { accentRoles, type AccentPreset, type AccentRoles as CatalogueAccentRoles } from '@adea-ai/themes';
2
+ /**
3
+ * Accent colour maths and the roles an accent paints.
4
+ *
5
+ * Three questions live here, and none of them touches the document or a signal:
6
+ *
7
+ * - **What colour is this?** `parseColor`, `colorToHex`, `contrastRatio` and
8
+ * `ensureContrast` are the hex helpers a host needs around an accent (an
9
+ * imported theme's colours, a colour field). Hex is the host preference format;
10
+ * the catalogue's colour engine does the maths.
11
+ * - **Is this accent readable on this surface?** The *contrast floor*. A preset is
12
+ * curated, so the catalogue already measured it against its own themes and the
13
+ * floor is the identity for it; a custom `#rrggbb` is anyone's choice, so it is
14
+ * raised until it clears the floor and can never ship unreadable. A host that
15
+ * imports themes (whose backgrounds the catalogue never saw) turns the floor on
16
+ * for presets too.
17
+ * - **Which custom properties does an accent own?** `AccentRoles`, written on
18
+ * `<html>` by the provider and onto one element by {@link paintAccentRoles}.
19
+ */
20
+ export type RgbColor = Readonly<{
21
+ r: number;
22
+ g: number;
23
+ b: number;
24
+ a: number;
25
+ }>;
26
+ /** Parse a hex colour (`#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`). `undefined` for anything else. */
27
+ export declare function parseColor(value: string): RgbColor | undefined;
28
+ /** `#rrggbb`, or `#rrggbbaa` when the colour is not opaque. */
29
+ export declare function colorToHex(color: RgbColor): string;
30
+ /** WCAG contrast ratio between two colours. Alpha composites over the background first. */
31
+ export declare function contrastRatio(foreground: RgbColor | string, background: RgbColor | string): number;
32
+ /** Preserve the host hex shape while delegating contrast repair to the catalogue. */
33
+ export declare function ensureContrast(color: RgbColor, background: RgbColor, minimum: number): RgbColor;
34
+ /** The contrast an accent is held to against its surface unless the host sets another. */
35
+ export declare const DEFAULT_ACCENT_CONTRAST_FLOOR = 3;
36
+ /**
37
+ * Normalise a custom accent against a surface: unparseable input is rejected
38
+ * (`undefined`), and any accepted colour is raised to `minimum` so an accent can
39
+ * never ship unreadable. Accepts every CSS hex length; for the stored grammar use
40
+ * {@link normalizeCustomAccent}.
41
+ */
42
+ export declare function normalizeAccentValue(value: string, background: string, minimum?: number): string | undefined;
43
+ /**
44
+ * The stored form of a custom accent: `#rrggbb`, six digits, opaque, lower case.
45
+ *
46
+ * Deliberately narrower than {@link parseColor}. A stored accent is compared,
47
+ * deduplicated and used as an attribute, so it has one spelling; a host that
48
+ * accepts `#abc` in a field expands it before storing. Anything else — a name, an
49
+ * `rgb()`, a short or alpha form, a non-string — is not an accent and returns
50
+ * `undefined`.
51
+ */
52
+ export declare function normalizeCustomAccent(value: unknown): string | undefined;
53
+ /** Whether a selection's accent is the custom `#rrggbb` form (any letter case). */
54
+ export declare function isCustomAccent(value: unknown): boolean;
55
+ /**
56
+ * The roles an accent paints, as CSS values: the catalogue's `AccentRoles`, so the
57
+ * provider, the generated stylesheet and a host's own paint cannot disagree about
58
+ * what a role is. `primarySubtle` is an expression over `var(--primary)`; the
59
+ * document writer never sets it (see {@link accentOverrideVariables}), an element
60
+ * paint must.
61
+ */
62
+ export type AccentRoles = CatalogueAccentRoles;
63
+ /** What an accent resolves against: the surface it sits on and the theme it sits in. */
64
+ export type AccentTarget = {
65
+ /** The theme, or only its appearance. A theme gives the tint its measured strength. */
66
+ target: Parameters<typeof accentRoles>[1];
67
+ /** The surface the accent must read on. Without it nothing can be measured or repaired. */
68
+ background: string | undefined;
69
+ /**
70
+ * The contrast to hold the accent to against `background`. Absent, a preset is
71
+ * painted verbatim and a custom colour is held to {@link DEFAULT_ACCENT_CONTRAST_FLOOR}.
72
+ */
73
+ floor?: number;
74
+ /**
75
+ * The accents the selected theme pair carries (`ansi-blue`…), for an id that is
76
+ * neither a preset nor a colour.
77
+ */
78
+ themeAccents?: readonly AccentPreset[];
79
+ };
80
+ /**
81
+ * The roles for a preset (or a custom colour made into one), held to the floor.
82
+ *
83
+ * A preset that clears the floor keeps the catalogue's roles untouched. One that
84
+ * does not is repaired to the nearest passing colour and the whole role set is
85
+ * rebuilt from the repaired value, so the label, hover and ring follow it instead
86
+ * of describing a colour that is no longer on screen.
87
+ */
88
+ export declare function accentRolesForPreset(preset: AccentPreset, context: AccentTarget): AccentRoles | undefined;
89
+ /**
90
+ * Resolve an accent selection to its roles, or `undefined` when it overrides nothing.
91
+ *
92
+ * `undefined` is "use the theme's own primary": the literal `theme`, an id that is
93
+ * neither a preset, an offered theme accent nor a colour, and a colour that does not
94
+ * parse. A host that wants one of those to mean something else decides before
95
+ * asking (Adea's codec maps a stored `theme` to its default preset when it reads).
96
+ */
97
+ export declare function resolveAccentRoles(accent: string, context: AccentTarget): AccentRoles | undefined;
98
+ /**
99
+ * The custom properties an accent override owns on `<html>`.
100
+ *
101
+ * `--primary-subtle` is deliberately not among them. It is a `color-mix()` over
102
+ * `var(--primary)`, so on the same element it follows an accent by itself, and its
103
+ * strength is the theme's, measured to keep body text at 4.5:1 on the tint.
104
+ * Writing one here would replace that measurement with the argument's.
105
+ */
106
+ export declare function accentOverrideVariables(roles: AccentRoles): Record<string, string>;
107
+ /** The custom properties {@link paintAccentRoles} writes and clears. */
108
+ export declare const ACCENT_PAINT_PROPERTIES: readonly ["--primary", "--primary-foreground", "--primary-hover", "--primary-subtle", "--ring"];
109
+ /**
110
+ * Scope an accent to one element and its descendants.
111
+ *
112
+ * Unlike the document, an element must write `--primary-subtle` too. A custom
113
+ * property that uses `var()` is resolved where it is declared, so the tint inherited
114
+ * from `<html>` is already a mix over *`<html>`'s* primary and an element that only
115
+ * overrides `--primary` would keep the old tint. Declared here, the same expression
116
+ * resolves against this element's primary.
117
+ *
118
+ * `undefined` clears every property, and the element inherits the document's accent
119
+ * again.
120
+ */
121
+ export declare function paintAccentRoles(element: {
122
+ style: Pick<CSSStyleDeclaration, 'setProperty' | 'removeProperty'>;
123
+ }, roles: AccentRoles | undefined): void;
124
+ //# sourceMappingURL=accent-roles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accent-roles.d.ts","sourceRoot":"","sources":["../../src/lib/accent-roles.ts"],"names":[],"mappings":"AAaA,OAAO,EAEL,WAAW,EAGX,KAAK,YAAY,EACjB,KAAK,WAAW,IAAI,oBAAoB,EACzC,MAAM,iBAAiB,CAAA;AAUxB;;;;;;;;;;;;;;;;;GAiBG;AAIH,MAAM,MAAM,QAAQ,GAAG,QAAQ,CAAC;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAAA;AAI/E,mGAAmG;AACnG,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAc9D;AAMD,+DAA+D;AAC/D,wBAAgB,UAAU,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM,CAGlD;AAiBD,2FAA2F;AAC3F,wBAAgB,aAAa,CAC3B,UAAU,EAAE,QAAQ,GAAG,MAAM,EAC7B,UAAU,EAAE,QAAQ,GAAG,MAAM,GAC5B,MAAM,CASR;AAyBD,qFAAqF;AACrF,wBAAgB,cAAc,CAAC,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,GAAG,QAAQ,CAQ/F;AAED,0FAA0F;AAC1F,eAAO,MAAM,6BAA6B,IAAI,CAAA;AAE9C;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,MAAsC,GAC9C,MAAM,GAAG,SAAS,CAKpB;AAED;;;;;;;;GAQG;AACH,wBAA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seColor, repairContrast } from "@adea-ai/themes/oklch";
3
+ //#region src/lib/accent-roles.ts
4
+ var WHITE_OKLCH = {
5
+ l: 1,
6
+ c: 0,
7
+ h: 0
8
+ };
9
+ /**
10
+ * The nearest colour to `source` that reaches `minimum` against `canvas`, as hex.
11
+ *
12
+ * The catalogue's `repairContrast` is asked for a little more than the floor, in
13
+ * 0.001 steps up to 0.05, because the result is rounded to 8-bit hex and the
14
+ * rounded colour is what is measured: asking for exactly the floor can land a hair
15
+ * under it after rounding. If nothing in that range survives the rounding, white or
16
+ * black stands in, whichever clears the floor.
17
+ */
18
+ function repairedHex(source, canvas, minimum) {
19
+ for (let margin = 0; margin <= .05; margin = Number((margin + .001).toFixed(3))) {
20
+ const repaired = repairContrast(source, canvas, minimum + margin);
21
+ if (!repaired.satisfied) continue;
22
+ const hex = oklchToHex(repaired.color);
23
+ const rounded = parseColor(hex);
24
+ if (rounded && contrastRatio(rounded, canvas) >= minimum) return hex;
25
+ }
26
+ return contrastRatio(WHITE_OKLCH, canvas) >= minimum ? "#ffffff" : "#000000";
27
+ }
28
+ /**
29
+ * The stored form of a custom accent: `#rrggbb`, six digits, opaque, lower case.
30
+ *
31
+ * Deliberately narrower than {@link parseColor}. A stored accent is compared,
32
+ * deduplicated and used as an attribute, so it has one spelling; a host that
33
+ * accepts `#abc` in a field expands it before storing. Anything else — a name, an
34
+ * `rgb()`, a short or alpha form, a non-string — is not an accent and returns
35
+ * `undefined`.
36
+ */
37
+ function normalizeCustomAccent(value) {
38
+ return typeof value === "string" && /^#[0-9a-fA-F]{6}$/.test(value) ? value.toLowerCase() : void 0;
39
+ }
40
+ /** Whether a selection's accent is the custom `#rrggbb` form (any letter case). */
41
+ function isCustomAccent(value) {
42
+ return normalizeCustomAccent(value) !== void 0;
43
+ }
44
+ function appearanceOf(target) {
45
+ return typeof target === "string" ? target : target.appearance;
46
+ }
47
+ /**
48
+ * `value` raised to `floor` against `background` as hex, or `value` itself when it
49
+ * already clears the floor, is not a colour, or there is no surface to measure it on.
50
+ *
51
+ * Returning the argument itself is what makes the floor the identity for a preset
52
+ * that already reads: the caller compares and keeps the catalogue's own roles.
53
+ */
54
+ function gateColor(value, background, floor) {
55
+ const source = parseColor(value);
56
+ const canvas = background ? parseColor(background) : void 0;
57
+ if (!source || !canvas) return value;
58
+ if (contrastRatio(source, canvas) >= floor) return value;
59
+ return repairedHex(source, canvas, floor);
60
+ }
61
+ /**
62
+ * The roles for a preset (or a custom colour made into one), held to the floor.
63
+ *
64
+ * A preset that clears the floor keeps the catalogue's roles untouched. One that
65
+ * does not is repaired to the nearest passing colour and the whole role set is
66
+ * rebuilt from the repaired value, so the label, hover and ring follow it instead
67
+ * of describing a colour that is no longer on screen.
68
+ */
69
+ function accentRolesForPreset(preset, context) {
70
+ const appearance = appearanceOf(context.target);
71
+ const requested = accentValue(preset, appearance);
72
+ if (!parseColor(requested)) return void 0;
73
+ const floor = context.floor;
74
+ if (floor === void 0) return accentRoles(preset, context.target);
75
+ const gated = gateColor(requested, context.background, floor);
76
+ if (gated === requested) return accentRoles(preset, context.target);
77
+ return {
78
+ ...accentRoles({
79
+ ...preset,
80
+ light: gated,
81
+ dark: gated
82
+ }, context.target),
83
+ primarySubtle: primarySubtleCss(context.target, "--primary", [gated])
84
+ };
85
+ }
86
+ /**
87
+ * Resolve an accent selection to its roles, or `undefined` when it overrides nothing.
88
+ *
89
+ * `undefined` is "use the theme's own primary": the literal `theme`, an id that is
90
+ * neither a preset, an offered theme accent nor a colour, and a colour that does not
91
+ * parse. A host that wants one of those to mean something else decides before
92
+ * asking (Adea's codec maps a stored `theme` to its default preset when it reads).
93
+ */
94
+ function resolveAccentRoles(accent, context) {
95
+ if (accent === "theme") return void 0;
96
+ const custom = normalizeCustomAccent(accent);
97
+ if (custom) {
98
+ const floor = context.floor ?? 3;
99
+ return accentRolesForPreset({
100
+ id: "custom",
101
+ label: "Custom",
102
+ description: "",
103
+ light: custom,
104
+ dark: custom
105
+ }, {
106
+ ...context,
107
+ floor
108
+ });
109
+ }
110
+ const preset = ACCENTS.find((candidate) => candidate.id === accent) ?? context.themeAccents?.find((candidate) => candidate.id === accent);
111
+ return preset ? accentRolesForPreset(preset, context) : void 0;
112
+ }
113
+ /**
114
+ * The custom properties an accent override owns on `<html>`.
115
+ *
116
+ * `--primary-subtle` is deliberately not among them. It is a `color-mix()` over
117
+ * `var(--primary)`, so on the same element it follows an accent by itself, and its
118
+ * strength is the theme's, measured to keep body text at 4.5:1 on the tint.
119
+ * Writing one here would replace that measurement with the argument's.
120
+ */
121
+ function accentOverrideVariables(roles) {
122
+ return {
123
+ "--primary": roles.primary,
124
+ "--primary-foreground": roles.primaryForeground,
125
+ "--primary-hover": roles.primaryHover,
126
+ "--ring": roles.ring
127
+ };
128
+ }
129
+ /** The custom properties {@link paintAccentRoles} writes and clears. */
130
+ var ACCENT_PAINT_PROPERTIES = [
131
+ "--primary",
132
+ "--primary-foreground",
133
+ "--primary-hover",
134
+ "--primary-subtle",
135
+ "--ring"
136
+ ];
137
+ /**
138
+ * Scope an accent to one element and its descendants.
139
+ *
140
+ * Unlike the document, an element must write `--primary-subtle` too. A custom
141
+ * property that uses `var()` is resolved where it is declared, so the tint inherited
142
+ * from `<html>` is already a mix over *`<html>`'s* primary and an element that only
143
+ * overrides `--primary` would keep the old tint. Declared here, the same expression
144
+ * resolves against this element's primary.
145
+ *
146
+ * `undefined` clears every property, and the element inherits the document's accent
147
+ * again.
148
+ */
149
+ function paintAccentRoles(element, roles) {
150
+ if (!roles) {
151
+ for (const property of ACCENT_PAINT_PROPERTIES) element.style.removeProperty(property);
152
+ return;
153
+ }
154
+ element.style.setProperty("--primary", roles.primary);
155
+ element.style.setProperty("--primary-foreground", roles.primaryForeground);
156
+ element.style.setProperty("--primary-hover", roles.primaryHover);
157
+ element.style.setProperty("--primary-subtle", roles.primarySubtle);
158
+ element.style.setProperty("--ring", roles.ring);
159
+ }
160
+ //#endregion
161
+ export { ACCENT_PAINT_PROPERTIES, accentOverrideVariables, accentRolesForPreset, isCustomAccent, normalizeCustomAccent, paintAccentRoles, resolveAccentRoles };
162
+
163
+ //# sourceMappingURL=accent-roles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accent-roles.js","names":["parseCanonicalColor","canonicalContrastRatio"],"sources":["../../src/lib/accent-roles.ts"],"sourcesContent":["/*\n * Copyright (c) 2026 Wing\n * SPDX-License-Identifier: MIT\n *\n * The colour helpers, the contrast gate and the custom-accent grammar are\n * substantially translated from Zeron's `Color` and `AccentRoles`\n * (https://github.com/zeronsh/zeron), as Adea's accepted port of them in\n * `packages/ui/src/components/appearance.ts` expresses it. Extracted here so the\n * shared provider and Adea run one implementation; `@adea-ai/themes` owns the\n * colour engine (parsing, contrast, repair, the preset values and their roles).\n * See NOTICE.\n */\n\nimport {\n ACCENTS,\n accentRoles,\n accentValue,\n primarySubtleCss,\n type AccentPreset,\n type AccentRoles as CatalogueAccentRoles,\n} from '@adea-ai/themes'\nimport {\n contrastRatio as canonicalContrastRatio,\n oklchToHex,\n parseColor as parseCanonicalColor,\n repairContrast,\n type Oklch,\n} from '@adea-ai/themes/oklch'\nimport type { ThemeAppearance } from './themes'\n\n/**\n * Accent colour maths and the roles an accent paints.\n *\n * Three questions live here, and none of them touches the document or a signal:\n *\n * - **What colour is this?** `parseColor`, `colorToHex`, `contrastRatio` and\n * `ensureContrast` are the hex helpers a host needs around an accent (an\n * imported theme's colours, a colour field). Hex is the host preference format;\n * the catalogue's colour engine does the maths.\n * - **Is this accent readable on this surface?** The *contrast floor*. A preset is\n * curated, so the catalogue already measured it against its own themes and the\n * floor is the identity for it; a custom `#rrggbb` is anyone's choice, so it is\n * raised until it clears the floor and can never ship unreadable. A host that\n * imports themes (whose backgrounds the catalogue never saw) turns the floor on\n * for presets too.\n * - **Which custom properties does an accent own?** `AccentRoles`, written on\n * `<html>` by the provider and onto one element by {@link paintAccentRoles}.\n */\n\n/* Hex is the host preference format; the shared Themes package owns colour maths. */\n\nexport type RgbColor = Readonly<{ r: number; g: number; b: number; a: number }>\n\nconst HEX = /^#([0-9a-fA-F]+)$/\n\n/** Parse a hex colour (`#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`). `undefined` for anything else. */\nexport function parseColor(value: string): RgbColor | undefined {\n const match = HEX.exec(value.trim())\n const digits = match?.[1]\n if (!digits) return undefined\n if (digits.length === 3 || digits.length === 4) {\n // Each nibble is doubled: `#abc` is `#aabbcc`.\n const [r, g, b, a] = [...digits].map((digit) => Number.parseInt(digit + digit, 16))\n return { r: r!, g: g!, b: b!, a: a ?? 255 }\n }\n if (digits.length === 6 || digits.length === 8) {\n const byte = (index: number) => Number.parseInt(digits.slice(index, index + 2), 16)\n return { r: byte(0), g: byte(2), b: byte(4), a: digits.length === 8 ? byte(6) : 255 }\n }\n return undefined\n}\n\nfunction toHexByte(value: number): string {\n return value.toString(16).padStart(2, '0')\n}\n\n/** `#rrggbb`, or `#rrggbbaa` when the colour is not opaque. */\nexport function colorToHex(color: RgbColor): string {\n const opaque = `#${toHexByte(color.r)}${toHexByte(color.g)}${toHexByte(color.b)}`\n return color.a === 255 ? opaque : `${opaque}${toHexByte(color.a)}`\n}\n\nfunction blendOver(foreground: RgbColor, background: RgbColor): RgbColor {\n const alpha = foreground.a / 255\n const blend = (front: number, back: number) => Math.round(front * alpha + back * (1 - alpha))\n return {\n r: blend(foreground.r, background.r),\n g: blend(foreground.g, background.g),\n b: blend(foreground.b, background.b),\n a: 255,\n }\n}\n\nfunction toCanonicalColor(color: RgbColor): Oklch | undefined {\n return parseCanonicalColor(colorToHex({ ...color, a: 255 }))\n}\n\n/** WCAG contrast ratio between two colours. Alpha composites over the background first. */\nexport function contrastRatio(\n foreground: RgbColor | string,\n background: RgbColor | string\n): number {\n const front = typeof foreground === 'string' ? parseColor(foreground) : foreground\n const back = typeof background === 'string' ? parseColor(background) : background\n if (!front || !back) return 0\n const opaqueFront = front.a === 255 ? front : blendOver(front, back)\n const foregroundColor = toCanonicalColor(opaqueFront)\n const backgroundColor = toCanonicalColor(back)\n if (!foregroundColor || !backgroundColor) return 0\n return canonicalContrastRatio(foregroundColor, backgroundColor)\n}\n\nconst WHITE: RgbColor = { r: 255, g: 255, b: 255, a: 255 }\nconst WHITE_OKLCH: Oklch = { l: 1, c: 0, h: 0 }\n\n/**\n * The nearest colour to `source` that reaches `minimum` against `canvas`, as hex.\n *\n * The catalogue's `repairContrast` is asked for a little more than the floor, in\n * 0.001 steps up to 0.05, because the result is rounded to 8-bit hex and the\n * rounded colour is what is measured: asking for exactly the floor can land a hair\n * under it after rounding. If nothing in that range survives the rounding, white or\n * black stands in, whichever clears the floor.\n */\nfunction repairedHex(source: Oklch, canvas: Oklch, minimum: number): string {\n for (let margin = 0; margin <= 0.05; margin = Number((margin + 0.001).toFixed(3))) {\n const repaired = repairContrast(source, canvas, minimum + margin)\n if (!repaired.satisfied) continue\n const hex = oklchToHex(repaired.color)\n const rounded = parseCanonicalColor(hex)\n if (rounded && canonicalContrastRatio(rounded, canvas) >= minimum) return hex\n }\n return canonicalContrastRatio(WHITE_OKLCH, canvas) >= minimum ? '#ffffff' : '#000000'\n}\n\n/** Preserve the host hex shape while delegating contrast repair to the catalogue. */\nexport function ensureContrast(color: RgbColor, background: RgbColor, minimum: number): RgbColor {\n if (contrastRatio(color, background) >= minimum) return color\n\n const renderedColor = color.a === 255 ? color : blendOver(color, background)\n const source = toCanonicalColor(renderedColor)\n const canvas = toCanonicalColor(background)\n if (!source || !canvas) return color\n return parseColor(repairedHex(source, canvas, minimum))!\n}\n\n/** The contrast an accent is held to against its surface unless the host sets another. */\nexport const DEFAULT_ACCENT_CONTRAST_FLOOR = 3\n\n/**\n * Normalise a custom accent against a surface: unparseable input is rejected\n * (`undefined`), and any accepted colour is raised to `minimum` so an accent can\n * never ship unreadable. Accepts every CSS hex length; for the stored grammar use\n * {@link normalizeCustomAccent}.\n */\nexport function normalizeAccentValue(\n value: string,\n background: string,\n minimum: number = DEFAULT_ACCENT_CONTRAST_FLOOR\n): string | undefined {\n const parsed = parseColor(value)\n if (!parsed) return undefined\n const backdrop = parseColor(background) ?? WHITE\n return colorToHex(ensureContrast(parsed, backdrop, minimum))\n}\n\n/**\n * The stored form of a custom accent: `#rrggbb`, six digits, opaque, lower case.\n *\n * Deliberately narrower than {@link parseColor}. A stored accent is compared,\n * deduplicated and used as an attribute, so it has one spelling; a host that\n * accepts `#abc` in a field expands it before storing. Anything else — a name, an\n * `rgb()`, a short or alpha form, a non-string — is not an accent and returns\n * `undefined`.\n */\nexport function normalizeCustomAccent(value: unknown): string | undefined {\n return typeof value === 'string' && /^#[0-9a-fA-F]{6}$/.test(value)\n ? value.toLowerCase()\n : undefined\n}\n\n/** Whether a selection's accent is the custom `#rrggbb` form (any letter case). */\nexport function isCustomAccent(value: unknown): boolean {\n return normalizeCustomAccent(value) !== undefined\n}\n\n/**\n * The roles an accent paints, as CSS values: the catalogue's `AccentRoles`, so the\n * provider, the generated stylesheet and a host's own paint cannot disagree about\n * what a role is. `primarySubtle` is an expression over `var(--primary)`; the\n * document writer never sets it (see {@link accentOverrideVariables}), an element\n * paint must.\n */\nexport type AccentRoles = CatalogueAccentRoles\n\n/** What an accent resolves against: the surface it sits on and the theme it sits in. */\nexport type AccentTarget = {\n /** The theme, or only its appearance. A theme gives the tint its measured strength. */\n target: Parameters<typeof accentRoles>[1]\n /** The surface the accent must read on. Without it nothing can be measured or repaired. */\n background: string | undefined\n /**\n * The contrast to hold the accent to against `background`. Absent, a preset is\n * painted verbatim and a custom colour is held to {@link DEFAULT_ACCENT_CONTRAST_FLOOR}.\n */\n floor?: number\n /**\n * The accents the selected theme pair carries (`ansi-blue`…), for an id that is\n * neither a preset nor a colour.\n */\n themeAccents?: readonly AccentPreset[]\n}\n\nfunction appearanceOf(target: AccentTarget['target']): ThemeAppearance {\n return typeof target === 'string' ? target : target.appearance\n}\n\n/**\n * `value` raised to `floor` against `background` as hex, or `value` itself when it\n * already clears the floor, is not a colour, or there is no surface to measure it on.\n *\n * Returning the argument itself is what makes the floor the identity for a preset\n * that already reads: the caller compares and keeps the catalogue's own roles.\n */\nfunction gateColor(value: string, background: string | undefined, floor: number): string {\n const source = parseCanonicalColor(value)\n const canvas = background ? parseCanonicalColor(background) : undefined\n if (!source || !canvas) return value\n if (canonicalContrastRatio(source, canvas) >= floor) return value\n return repairedHex(source, canvas, floor)\n}\n\n/**\n * The roles for a preset (or a custom colour made into one), held to the floor.\n *\n * A preset that clears the floor keeps the catalogue's roles untouched. One that\n * does not is repaired to the nearest passing colour and the whole role set is\n * rebuilt from the repaired value, so the label, hover and ring follow it instead\n * of describing a colour that is no longer on screen.\n */\nexport function accentRolesForPreset(\n preset: AccentPreset,\n context: AccentTarget\n): AccentRoles | undefined {\n const appearance = appearanceOf(context.target)\n const requested = accentValue(preset, appearance)\n if (!parseCanonicalColor(requested)) return undefined\n\n const floor = context.floor\n if (floor === undefined) return accentRoles(preset, context.target)\n\n const gated = gateColor(requested, context.background, floor)\n if (gated === requested) return accentRoles(preset, context.target)\n\n const roles = accentRoles({ ...preset, light: gated, dark: gated }, context.target)\n // The tint's strength is measured against the primary it will sit over, and the\n // repaired primary is not one the theme's own measurement saw.\n return { ...roles, primarySubtle: primarySubtleCss(context.target, '--primary', [gated]) }\n}\n\n/**\n * Resolve an accent selection to its roles, or `undefined` when it overrides nothing.\n *\n * `undefined` is \"use the theme's own primary\": the literal `theme`, an id that is\n * neither a preset, an offered theme accent nor a colour, and a colour that does not\n * parse. A host that wants one of those to mean something else decides before\n * asking (Adea's codec maps a stored `theme` to its default preset when it reads).\n */\nexport function resolveAccentRoles(accent: string, context: AccentTarget): AccentRoles | undefined {\n if (accent === 'theme') return undefined\n\n const custom = normalizeCustomAccent(accent)\n if (custom) {\n const floor = context.floor ?? DEFAULT_ACCENT_CONTRAST_FLOOR\n return accentRolesForPreset(\n { id: 'custom', label: 'Custom', description: '', light: custom, dark: custom },\n { ...context, floor }\n )\n }\n\n const preset =\n ACCENTS.find((candidate) => candidate.id === accent) ??\n context.themeAccents?.find((candidate) => candidate.id === accent)\n return preset ? accentRolesForPreset(preset, context) : undefined\n}\n\n/**\n * The custom properties an accent override owns on `<html>`.\n *\n * `--primary-subtle` is deliberately not among them. It is a `color-mix()` over\n * `var(--primary)`, so on the same element it follows an accent by itself, and its\n * strength is the theme's, measured to keep body text at 4.5:1 on the tint.\n * Writing one here would replace that measurement with the argument's.\n */\nexport function accentOverrideVariables(roles: AccentRoles): Record<string, string> {\n return {\n '--primary': roles.primary,\n '--primary-foreground': roles.primaryForeground,\n '--primary-hover': roles.primaryHover,\n '--ring': roles.ring,\n }\n}\n\n/** The custom properties {@link paintAccentRoles} writes and clears. */\nexport const ACCENT_PAINT_PROPERTIES = [\n '--primary',\n '--primary-foreground',\n '--primary-hover',\n '--primary-subtle',\n '--ring',\n] as const\n\n/**\n * Scope an accent to one element and its descendants.\n *\n * Unlike the document, an element must write `--primary-subtle` too. A custom\n * property that uses `var()` is resolved where it is declared, so the tint inherited\n * from `<html>` is already a mix over *`<html>`'s* primary and an element that only\n * overrides `--primary` would keep the old tint. Declared here, the same expression\n * resolves against this element's primary.\n *\n * `undefined` clears every property, and the element inherits the document's accent\n * again.\n */\nexport function paintAccentRoles(\n element: { style: Pick<CSSStyleDeclaration, 'setProperty' | 'removeProperty'> },\n roles: AccentRoles | undefined\n): void {\n if (!roles) {\n for (const property of ACCENT_PAINT_PROPERTIES) element.style.removeProperty(property)\n return\n }\n element.style.setProperty('--primary', roles.primary)\n element.style.setProperty('--primary-foreground', roles.primaryForeground)\n element.style.setProperty('--primary-hover', roles.primaryHover)\n element.style.setProperty('--primary-subtle', roles.primarySubtle)\n element.style.setProperty('--ring', roles.ring)\n}\n"],"mappings":";;;AAiHA,IAAM,cAAqB;CAAE,GAAG;CAAG,GAAG;CAAG,GAAG;AAAE;;;;;;;;;;AAW9C,SAAS,YAAY,QAAe,QAAe,SAAyB;CAC1E,KAAK,IAAI,SAAS,GAAG,UAAU,KAAM,SAAS,QAAQ,SAAS,KAAA,CAAO,QA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entPreset, type AdeaTheme, type AdeaThemeRecord } from '@adea-ai/themes';
36
+ import { type AccentRoles } from './accent-roles';
36
37
  export { isThemeAccentId } from './theme-accents';
37
38
  export type ThemeAppearance = 'light' | 'dark';
38
39
  /**
@@ -289,7 +290,28 @@ export declare function appearancePreviewThemes(selection: {
289
290
  export declare function accentVariables(accentId: string, appearance: ThemeAppearance, pair?: {
290
291
  lightThemeId: string;
291
292
  darkThemeId: string;
292
- }): Record<string, string> | undefined;
293
+ }, options?: AccentVariableOptions): Record<string, string> | undefined;
294
+ /** What an accent is held to when it is resolved against a surface. */
295
+ export type AccentVariableOptions = {
296
+ /** The surface the accent must read on: the variant's `colors.background`. */
297
+ background?: string;
298
+ /**
299
+ * The contrast floor against `background`. Absent, a preset is painted verbatim
300
+ * and only a custom `#rrggbb` is held to the default floor.
301
+ */
302
+ floor?: number;
303
+ /** The variant the accent is applied to, so the tint takes its measured strength. */
304
+ variantId?: string;
305
+ };
306
+ /**
307
+ * An accent selection resolved to the full {@link AccentRoles}, against a theme
308
+ * pair. {@link accentVariables} is the document half of this; an element-scoped
309
+ * paint (`paintAccentRoles`) wants all of it, including the tint.
310
+ */
311
+ export declare function accentRolesForSelection(accentId: string, appearance: ThemeAppearance, pair?: {
312
+ lightThemeId: string;
313
+ darkThemeId: string;
314
+ }, options?: AccentVariableOptions): AccentRoles | undefined;
293
315
  /**
294
316
  * The roles a variant sets, as CSS custom properties.
295
317
  *
@@ -1 +1 @@
1
- {"version":3,"file":"themes.d.ts","sourceRoot":"","sources":["../../src/lib/themes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,EAkBL,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,eAAe,EAErB,MAAM,iBAAiB,CAAA;AAKxB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,MAAM,CAAA;AAE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AA8E;IAC9E,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,qFAAqF;IACrF,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,eAAe,EAC3B,IAAI,GAAE;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAGhD,EACD,OAAO,GAAE,qBAA0B,GAClC,WAAW,GAAG,SAAS,CAYzB;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA8G7E;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAU5F;AAUD,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAMD,+FAA+F;AAC/F,wBAAgB,aAAa,CAAC,KAAK,EAAE,YAAY,GAAG,YAAY,EAAE,CAMjE;AAED,8EAA8E;AAC9E,wBAAgB,qBAAqB,CACnC,MAAM,GAAE,SAAS,YAAY,EAAkB,GAC9C,YAAY,EAAE,CAchB;AAED,eAAO,MAAM,mBAAmB,eAAe,CAAA;AAC/C,eAAO,MAAM,kBAAkB,cAAc,CAAA;AAE7C,kFAAkF;AAClF,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA"}
@@ -1,5 +1,6 @@
1
+ import { accentOverrideVariables, resolveAccentRoles } from "./accent-roles.js";
1
2
  import { isThemeAccentId } from "./theme-accents.js";
2
- import { accentForeground, accentRoles, chartSeries, contrastRatio, getAccent, getTheme, hasTheme, primaryHover, primarySubtleCss, shadcnDestructiveProjection, statusForeground, syntaxRoles, themeAccentPresets, themes, themesByAppearance, tint, validateCatalogue } from "@adea-ai/themes";
3
+ import { accentForeground, chartSeries, contrastRatio as contrastRatio$1, getAccent, getTheme, hasTheme, primaryHover, primarySubtleCss, shadcnDestructiveProjection, statusForeground, syntaxRoles, themeAccentPresets, themes, themesByAppearance, tint, validateCatalogue } from "@adea-ai/themes";
3
4
  import { shadcnVariables } from "@adea-ai/themes/adapters/shadcn";
4
5
  import { oklchToHex, parseColor } from "@adea-ai/themes/oklch";
5
6
  //#region src/lib/themes.ts
@@ -364,18 +365,27 @@ function appearancePreviewThemes(selection) {
364
365
  function accentVariables(accentId, appearance, pair = {
365
366
  lightThemeId: defaultLightThemeId,
366
367
  darkThemeId: defaultDarkThemeId
367
- }) {
368
+ }, options = {}) {
369
+ const roles = accentRolesForSelection(accentId, appearance, pair, options);
370
+ return roles ? accentOverrideVariables(roles) : void 0;
371
+ }
372
+ /**
373
+ * An accent selection resolved to the full {@link AccentRoles}, against a theme
374
+ * pair. {@link accentVariables} is the document half of this; an element-scoped
375
+ * paint (`paintAccentRoles`) wants all of it, including the tint.
376
+ */
377
+ function accentRolesForSelection(accentId, appearance, pair = {
378
+ lightThemeId: defaultLightThemeId,
379
+ darkThemeId: defaultDarkThemeId
380
+ }, options = {}) {
368
381
  if (accentId === "theme") return void 0;
369
- const { light, dark } = recordPair(pair.lightThemeId, pair.darkThemeId);
370
- const preset = resolveAccentPreset(accentId, light, dark);
371
- if (!preset) return void 0;
372
- const roles = accentRoles(preset, appearance);
373
- return {
374
- "--primary": roles.primary,
375
- "--primary-foreground": roles.primaryForeground,
376
- "--primary-hover": roles.primaryHover,
377
- "--ring": roles.ring
378
- };
382
+ const record = options.variantId ? getTheme(options.variantId) : void 0;
383
+ return resolveAccentRoles(accentId, {
384
+ target: record ?? appearance,
385
+ background: options.background,
386
+ floor: options.floor,
387
+ themeAccents: isThemeAccentId(accentId) ? themeAccentsFor(pair.lightThemeId, pair.darkThemeId) : void 0
388
+ });
379
389
  }
380
390
  /**
381
391
  * The roles a variant sets, as CSS custom properties.
@@ -531,6 +541,6 @@ function validateThemeRegistry(themes$1 = builtinThemes) {
531
541
  var defaultLightThemeId = "adea-light";
532
542
  var defaultDarkThemeId = "adea-dark";
533
543
  //#endregion
534
- export { accentVariables, appearancePreviewThemes, builtinThemes, contrastRatio, defaultDarkThemeId, defaultLightThemeId, isThemeAccentId, primarySubtleFor, resolveAccentPreset, resolveVariant, themeAccentsFor, themeById, themeCssVariables, themeFamilies, themeRecordById, themeRecords, themesForAppearance, tokensAsHex, validateTheme, validateThemeRegistry, variantFromRecord, withAccent };
544
+ export { accentRolesForSelection, accentVariables, appearancePreviewThemes, builtinThemes, contrastRatio$1 as contrastRatio, defaultDarkThemeId, defaultLightThemeId, isThemeAccentId, primarySubtleFor, resolveAccentPreset, resolveVariant, themeAccentsFor, themeById, themeCssVariables, themeFamilies, themeRecordById, themeRecords, themesForAppearance, tokensAsHex, validateTheme, validateThemeRegistry, variantFromRecord, withAccent };
535
545
 
536
546
  //# sourceMappingURL=themes.js.map