@adea-ai/ui 0.124.0 → 0.127.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 (82) hide show
  1. package/dist/NOTICE +58 -0
  2. package/dist/components/theme/index.d.ts +1 -1
  3. package/dist/components/theme/index.d.ts.map +1 -1
  4. package/dist/components/theme/index.js +4 -3
  5. package/dist/components/theme/theme-document.d.ts +31 -1
  6. package/dist/components/theme/theme-document.d.ts.map +1 -1
  7. package/dist/components/theme/theme-document.js +25 -5
  8. package/dist/components/theme/theme-document.js.map +1 -1
  9. package/dist/components/theme/theme-persistence.d.ts +87 -0
  10. package/dist/components/theme/theme-persistence.d.ts.map +1 -1
  11. package/dist/components/theme/theme-persistence.js +65 -3
  12. package/dist/components/theme/theme-persistence.js.map +1 -1
  13. package/dist/components/theme/theme-provider.d.ts +49 -40
  14. package/dist/components/theme/theme-provider.d.ts.map +1 -1
  15. package/dist/components/theme/theme-provider.js +67 -52
  16. package/dist/components/theme/theme-provider.js.map +1 -1
  17. package/dist/components/theme/theme-script.d.ts +100 -0
  18. package/dist/components/theme/theme-script.d.ts.map +1 -0
  19. package/dist/components/theme/theme-script.js +57 -0
  20. package/dist/components/theme/theme-script.js.map +1 -0
  21. package/dist/components/theme/theme-state.d.ts +85 -2
  22. package/dist/components/theme/theme-state.d.ts.map +1 -1
  23. package/dist/components/theme/theme-state.js +41 -2
  24. package/dist/components/theme/theme-state.js.map +1 -1
  25. package/dist/index.d.ts +5 -1
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +9 -4
  28. package/dist/lib/accent-roles.d.ts +124 -0
  29. package/dist/lib/accent-roles.d.ts.map +1 -0
  30. package/dist/lib/accent-roles.js +163 -0
  31. package/dist/lib/accent-roles.js.map +1 -0
  32. package/dist/lib/font-zoom.d.ts +25 -0
  33. package/dist/lib/font-zoom.d.ts.map +1 -0
  34. package/dist/lib/font-zoom.js +45 -0
  35. package/dist/lib/font-zoom.js.map +1 -0
  36. package/dist/lib/preference-store.d.ts +126 -0
  37. package/dist/lib/preference-store.d.ts.map +1 -0
  38. package/dist/lib/preference-store.js +126 -0
  39. package/dist/lib/preference-store.js.map +1 -0
  40. package/dist/lib/theme-surface.d.ts +71 -0
  41. package/dist/lib/theme-surface.d.ts.map +1 -0
  42. package/dist/lib/theme-surface.js +62 -0
  43. package/dist/lib/theme-surface.js.map +1 -0
  44. package/dist/lib/themes.d.ts +32 -1
  45. package/dist/lib/themes.d.ts.map +1 -1
  46. package/dist/lib/themes.js +34 -13
  47. package/dist/lib/themes.js.map +1 -1
  48. package/dist/lib/tokens.d.ts.map +1 -1
  49. package/dist/lib/tokens.js +15 -0
  50. package/dist/lib/tokens.js.map +1 -1
  51. package/dist/r/lib.json +20 -0
  52. package/dist/r/registry.json +25 -0
  53. package/dist/r/src/components/theme/index.ts +6 -0
  54. package/dist/r/src/components/theme/theme-document.ts +69 -4
  55. package/dist/r/src/components/theme/theme-persistence.ts +172 -2
  56. package/dist/r/src/components/theme/theme-provider.tsx +137 -51
  57. package/dist/r/src/components/theme/theme-script.ts +201 -0
  58. package/dist/r/src/components/theme/theme-state.ts +124 -3
  59. package/dist/r/src/lib/accent-roles.ts +338 -0
  60. package/dist/r/src/lib/font-zoom.ts +74 -0
  61. package/dist/r/src/lib/preference-store.ts +216 -0
  62. package/dist/r/src/lib/theme-surface.ts +110 -0
  63. package/dist/r/src/lib/themes.ts +58 -19
  64. package/dist/r/src/lib/tokens.ts +17 -0
  65. package/dist/r/src/styles/theme.css +38 -0
  66. package/dist/r/theming.json +5 -0
  67. package/package.json +1 -1
  68. package/registry.json +25 -0
  69. package/src/components/theme/index.ts +6 -0
  70. package/src/components/theme/theme-document.ts +69 -4
  71. package/src/components/theme/theme-persistence.ts +172 -2
  72. package/src/components/theme/theme-provider.tsx +137 -51
  73. package/src/components/theme/theme-script.ts +201 -0
  74. package/src/components/theme/theme-state.ts +124 -3
  75. package/src/index.ts +34 -0
  76. package/src/lib/accent-roles.ts +338 -0
  77. package/src/lib/font-zoom.ts +74 -0
  78. package/src/lib/preference-store.ts +216 -0
  79. package/src/lib/theme-surface.ts +110 -0
  80. package/src/lib/themes.ts +58 -19
  81. package/src/lib/tokens.ts +17 -0
  82. package/src/styles/theme.css +38 -0
@@ -0,0 +1,216 @@
1
+ /*
2
+ * Copyright (c) 2026 Wing
3
+ * Licensed under the MIT License.
4
+ *
5
+ * The recovery behaviour here (quarantine before any write, the envelope shape, the
6
+ * legacy key that is read once and never deleted) is Adea's accepted port of Zeron's
7
+ * preference store (https://github.com/zeronsh/zeron),
8
+ * `packages/ui/src/components/appearance.ts`, moved here so the shared provider and
9
+ * Adea run one implementation. See NOTICE.
10
+ */
11
+
12
+ /**
13
+ * A versioned preference store: read one JSON document, refuse to guess about what
14
+ * it cannot read, and keep what it refused.
15
+ *
16
+ * Nothing here knows what a preference *is*. A host hands the engine a key, a
17
+ * version and (through `createVersionedPersistence`) a codec; the engine owns only
18
+ * the part every versioned store gets wrong the same way, which is what happens to
19
+ * a document that is not the one the code expects:
20
+ *
21
+ * - A document that is not JSON, or not a record, or carries a version the code
22
+ * does not know (usually a newer build's) is **quarantined, byte for byte, into a
23
+ * recovery key** before anything else happens. The store then answers as if
24
+ * nothing were stored. Because the quarantine runs at read time, ahead of any
25
+ * write, saving valid preferences later cannot destroy the unread original.
26
+ * - A legacy key is consulted only when the main key is *absent*, never when it is
27
+ * unreadable: a corrupt main document is not "no preference", and falling back to
28
+ * an older, staler key would quietly restore a choice the user has since changed.
29
+ * The legacy key is never deleted.
30
+ * - Blocked storage (a sandboxed iframe, a privacy mode) throws on the mere access
31
+ * of the `localStorage` global. Every path here treats that as "nothing stored".
32
+ *
33
+ * The reads and writes are against a {@link PreferenceStorage}, so the rules run in a
34
+ * test without a DOM.
35
+ */
36
+
37
+ /** The part of `Storage` the engine uses. */
38
+ export type PreferenceStorage = Pick<Storage, 'getItem' | 'setItem'>
39
+
40
+ /** Why an unread document was quarantined. */
41
+ export type RecoveryReason = 'corrupt_json' | 'unsupported_record'
42
+
43
+ /**
44
+ * What is written to the recovery key.
45
+ *
46
+ * The shape is a compatibility surface: Adea's stored envelopes already have it, and
47
+ * a tool that inspects a user's storage reads it. Do not rename a field.
48
+ */
49
+ export type RecoveryEnvelope = Readonly<{
50
+ schemaVersion: 1
51
+ reason: RecoveryReason
52
+ /** An ISO-8601 timestamp of the capture; refreshed by each read of the same bytes. */
53
+ capturedAt: string
54
+ /** The document exactly as it was stored. */
55
+ raw: string
56
+ }>
57
+
58
+ /**
59
+ * The preference store, or nothing.
60
+ *
61
+ * The `typeof` guard sits inside the `try` for a reason: where storage is blocked,
62
+ * merely *reading* the `localStorage` global throws, so a guard in front of the `try`
63
+ * is itself the crash.
64
+ */
65
+ export function defaultPreferenceStorage(): PreferenceStorage | undefined {
66
+ try {
67
+ return typeof localStorage === 'undefined' ? undefined : localStorage
68
+ } catch {
69
+ return undefined
70
+ }
71
+ }
72
+
73
+ /** The envelope for a document, stamped with `now`. */
74
+ export function recoveryEnvelope(
75
+ raw: string,
76
+ reason: RecoveryReason,
77
+ now: Date = new Date()
78
+ ): RecoveryEnvelope {
79
+ return { schemaVersion: 1, reason, capturedAt: now.toISOString(), raw }
80
+ }
81
+
82
+ /**
83
+ * Quarantine an unread document into `recoveryKey`.
84
+ *
85
+ * Idempotent, so re-reading the same unread value refreshes the capture without
86
+ * losing it. Best effort: a store that cannot be written leaves the caller to fail
87
+ * closed on the defaults, which is the same outcome as not having a recovery key at
88
+ * all. Never throws.
89
+ *
90
+ * Exported so a host quarantines its *other* documents (a theme library, say) with
91
+ * the same envelope. Give each document its own `recoveryKey`: two documents that
92
+ * share one overwrite each other's capture.
93
+ */
94
+ export function quarantineRecord(
95
+ storage: PreferenceStorage,
96
+ recoveryKey: string,
97
+ raw: string,
98
+ reason: RecoveryReason,
99
+ now: () => Date = () => new Date()
100
+ ): void {
101
+ try {
102
+ storage.setItem(recoveryKey, JSON.stringify(recoveryEnvelope(raw, reason, now())))
103
+ } catch {
104
+ // Quarantine is best effort; the active preference still fails closed.
105
+ }
106
+ }
107
+
108
+ /** Where a versioned document lives and which version the code understands. */
109
+ export type VersionedRecordSchema = {
110
+ /** The storage key of the document. */
111
+ key: string
112
+ /**
113
+ * The only `version` the code reads. Absent, the document is unversioned and any
114
+ * JSON object is accepted; present, a record whose top-level `version` is not
115
+ * exactly this number is unsupported (newer or older), not "close enough".
116
+ */
117
+ version?: number
118
+ /** Where an unread document is kept. Default `${key}.recovery`. */
119
+ recoveryKey?: string
120
+ }
121
+
122
+ /**
123
+ * What reading the document found.
124
+ *
125
+ * - `absent`: nothing is stored under the key.
126
+ * - `record`: a JSON object this code can read; `raw` is the stored text.
127
+ * - `quarantined`: something was stored and cannot be read. It has already been
128
+ * written to the recovery key.
129
+ * - `unavailable`: the store itself could not be read.
130
+ */
131
+ export type VersionedRead =
132
+ | { status: 'absent' }
133
+ | { status: 'record'; record: Readonly<Record<string, unknown>>; raw: string }
134
+ | { status: 'quarantined'; reason: RecoveryReason; raw: string }
135
+ | { status: 'unavailable' }
136
+
137
+ /** The default recovery key for a document key. */
138
+ export function recoveryKeyFor(schema: VersionedRecordSchema): string {
139
+ return schema.recoveryKey ?? `${schema.key}.recovery`
140
+ }
141
+
142
+ /**
143
+ * Read the document under `schema.key`.
144
+ *
145
+ * The classification is the contract: a value that is not valid JSON, or is JSON but
146
+ * not an object (`null`, a number, a string), is `corrupt_json`; an object (or array)
147
+ * that is not a record of the supported version is `unsupported_record`. Both are
148
+ * quarantined before this returns. An empty string is a stored value, so it is
149
+ * corrupt rather than absent.
150
+ */
151
+ export function readVersionedRecord(
152
+ storage: PreferenceStorage,
153
+ schema: VersionedRecordSchema,
154
+ now?: () => Date
155
+ ): VersionedRead {
156
+ let raw: string | null
157
+ try {
158
+ raw = storage.getItem(schema.key)
159
+ } catch {
160
+ return { status: 'unavailable' }
161
+ }
162
+ if (raw === null) return { status: 'absent' }
163
+
164
+ const recoveryKey = recoveryKeyFor(schema)
165
+ let parsed: unknown
166
+ try {
167
+ parsed = JSON.parse(raw)
168
+ } catch {
169
+ quarantineRecord(storage, recoveryKey, raw, 'corrupt_json', now)
170
+ return { status: 'quarantined', reason: 'corrupt_json', raw }
171
+ }
172
+ if (typeof parsed !== 'object' || parsed === null) {
173
+ quarantineRecord(storage, recoveryKey, raw, 'corrupt_json', now)
174
+ return { status: 'quarantined', reason: 'corrupt_json', raw }
175
+ }
176
+ if (
177
+ Array.isArray(parsed) ||
178
+ (schema.version !== undefined && (parsed as { version?: unknown }).version !== schema.version)
179
+ ) {
180
+ quarantineRecord(storage, recoveryKey, raw, 'unsupported_record', now)
181
+ return { status: 'quarantined', reason: 'unsupported_record', raw }
182
+ }
183
+ return { status: 'record', record: parsed as Record<string, unknown>, raw }
184
+ }
185
+
186
+ /**
187
+ * The legacy single-key value, or `null`.
188
+ *
189
+ * Only the caller decides whether to look: the engine's rule is to ask when the main
190
+ * key is `absent`, not when it was quarantined.
191
+ */
192
+ export function readLegacyValue(storage: PreferenceStorage, legacyKey: string): string | null {
193
+ try {
194
+ return storage.getItem(legacyKey)
195
+ } catch {
196
+ return null
197
+ }
198
+ }
199
+
200
+ /**
201
+ * Write `document` to `key` as JSON. Returns whether it was stored; a full or blocked
202
+ * store returns `false` and never throws, because losing a preference must not break
203
+ * the switch that tried to save it.
204
+ */
205
+ export function writeVersionedRecord(
206
+ storage: PreferenceStorage,
207
+ key: string,
208
+ document: unknown
209
+ ): boolean {
210
+ try {
211
+ storage.setItem(key, JSON.stringify(document))
212
+ return true
213
+ } catch {
214
+ return false
215
+ }
216
+ }
@@ -0,0 +1,110 @@
1
+ /*
2
+ * Copyright (c) 2026 Wing
3
+ * Licensed under the MIT License.
4
+ *
5
+ * `resolveSurface` is Zeron's `SurfacePreference.resolve` (https://github.com/zeronsh/zeron),
6
+ * extended by Adea's accepted port of it (`packages/ui/src/components/appearance.ts`)
7
+ * with the translucent capability gate and the reduced-transparency policy. Moved
8
+ * here so the shared provider and Adea run one implementation. See NOTICE.
9
+ */
10
+
11
+ /**
12
+ * The surface axis, and the policy that decides what it paints.
13
+ *
14
+ * A surface is how opaque the window's elevated panels are: `opaque` is the plain
15
+ * canvas, `frosted` is a tokenized translucent fill over a blur (works everywhere,
16
+ * in CSS alone), and `translucent` asks for the host window's own vibrancy, which only
17
+ * a desktop shell can honour.
18
+ *
19
+ * Nothing here touches the document or a signal. The provider reads the operating
20
+ * system and the host's capability, calls {@link resolveSurface}, and
21
+ * `theme-document.ts` writes the answer; the rule itself is a function of its four
22
+ * inputs, which is what makes it testable.
23
+ */
24
+ export type ThemeSurface = 'opaque' | 'frosted' | 'translucent'
25
+
26
+ /** Every surface, in the order a picker offers them. */
27
+ export const themeSurfaces: readonly ThemeSurface[] = ['opaque', 'frosted', 'translucent']
28
+
29
+ /** The media query the operating system's Reduce Transparency setting answers. */
30
+ export const REDUCED_TRANSPARENCY_QUERY = '(prefers-reduced-transparency: reduce)'
31
+
32
+ /**
33
+ * What the world says about transparency, as opposed to what the user prefers.
34
+ */
35
+ export type SurfaceEnvironment = Readonly<{
36
+ /** The operating system asks for less transparency. */
37
+ osReducedTransparency: boolean
38
+ /** The user turned reduced transparency on inside the application. */
39
+ userReducedTransparency: boolean
40
+ /** The host window can render OS translucency (vibrancy, acrylic). */
41
+ nativeTranslucency: boolean
42
+ }>
43
+
44
+ /**
45
+ * A stored value as a surface, or nothing.
46
+ *
47
+ * `undefined` rather than `opaque` for an unreadable value: the selection field is
48
+ * optional, and an absent field is how a store that never chose a surface stays
49
+ * byte-identical to what it was before the axis existed.
50
+ */
51
+ export function normalizeSurface(value: unknown): ThemeSurface | undefined {
52
+ return value === 'opaque' || value === 'frosted' || value === 'translucent' ? value : undefined
53
+ }
54
+
55
+ /**
56
+ * The surface to paint: the preference, after the accessibility override and the
57
+ * host's capability.
58
+ *
59
+ * The OS setting or the user's own flag forces an accessible opaque fallback. A
60
+ * translucent request on a host without native translucency renders the tokenized
61
+ * frosted surface instead of pretending to OS vibrancy.
62
+ */
63
+ export function resolveSurface(
64
+ preference: ThemeSurface,
65
+ environment: SurfaceEnvironment
66
+ ): ThemeSurface {
67
+ if (environment.osReducedTransparency || environment.userReducedTransparency) return 'opaque'
68
+ if (preference === 'translucent' && !environment.nativeTranslucency) return 'frosted'
69
+ return preference
70
+ }
71
+
72
+ /**
73
+ * The fill opacity each surface paints, written as `--surface-alpha`.
74
+ *
75
+ * These are the values `--surface-frost` and `--surface-translucent` declare in
76
+ * `theme.css` (the stylesheet is the readable copy; `tests/theme-surface.test.ts`
77
+ * fails when the two disagree). They are numbers rather than `var()` references so
78
+ * the property reads the same to a script, a test and the stylesheet, whichever
79
+ * wrote it.
80
+ */
81
+ export const surfaceAlpha: Readonly<Record<ThemeSurface, string>> = {
82
+ opaque: '1',
83
+ frosted: '0.92',
84
+ translucent: '0.8',
85
+ }
86
+
87
+ /** What a selection paints for the surface axis. */
88
+ export type SurfaceState = Readonly<{
89
+ /** The surface after the accessibility override and capability gate. */
90
+ surface: ThemeSurface
91
+ /** True while the OS or the user forces opaque surfaces. */
92
+ reduceTransparencyActive: boolean
93
+ }>
94
+
95
+ /**
96
+ * The surface state for a preference and an environment.
97
+ *
98
+ * A preference of `undefined` is `opaque`: the axis is optional on a selection, and
99
+ * a host that never set it gets the plain canvas.
100
+ */
101
+ export function resolveSurfaceState(
102
+ preference: ThemeSurface | undefined,
103
+ environment: SurfaceEnvironment
104
+ ): SurfaceState {
105
+ return {
106
+ surface: resolveSurface(preference ?? 'opaque', environment),
107
+ reduceTransparencyActive:
108
+ environment.osReducedTransparency || environment.userReducedTransparency,
109
+ }
110
+ }
package/src/lib/themes.ts CHANGED
@@ -36,7 +36,6 @@
36
36
  import {
37
37
  ACCENTS,
38
38
  accentForeground,
39
- accentRoles,
40
39
  chartSeries,
41
40
  getAccent,
42
41
  getTheme,
@@ -58,6 +57,7 @@ import {
58
57
  } from '@adea-ai/themes'
59
58
  import { shadcnVariables } from '@adea-ai/themes/adapters/shadcn'
60
59
  import { oklchToHex, parseColor } from '@adea-ai/themes/oklch'
60
+ import { accentOverrideVariables, resolveAccentRoles, type AccentRoles } from './accent-roles'
61
61
  import { isThemeAccentId } from './theme-accents'
62
62
 
63
63
  export { isThemeAccentId } from './theme-accents'
@@ -566,26 +566,51 @@ export function accentVariables(
566
566
  pair: { lightThemeId: string; darkThemeId: string } = {
567
567
  lightThemeId: defaultLightThemeId,
568
568
  darkThemeId: defaultDarkThemeId,
569
- }
569
+ },
570
+ options: AccentVariableOptions = {}
570
571
  ): Record<string, string> | undefined {
572
+ const roles = accentRolesForSelection(accentId, appearance, pair, options)
573
+ return roles ? accentOverrideVariables(roles) : undefined
574
+ }
575
+
576
+ /** What an accent is held to when it is resolved against a surface. */
577
+ export type AccentVariableOptions = {
578
+ /** The surface the accent must read on: the variant's `colors.background`. */
579
+ background?: string
580
+ /**
581
+ * The contrast floor against `background`. Absent, a preset is painted verbatim
582
+ * and only a custom `#rrggbb` is held to the default floor.
583
+ */
584
+ floor?: number
585
+ /** The variant the accent is applied to, so the tint takes its measured strength. */
586
+ variantId?: string
587
+ }
588
+
589
+ /**
590
+ * An accent selection resolved to the full {@link AccentRoles}, against a theme
591
+ * pair. {@link accentVariables} is the document half of this; an element-scoped
592
+ * paint (`paintAccentRoles`) wants all of it, including the tint.
593
+ */
594
+ export function accentRolesForSelection(
595
+ accentId: string,
596
+ appearance: ThemeAppearance,
597
+ pair: { lightThemeId: string; darkThemeId: string } = {
598
+ lightThemeId: defaultLightThemeId,
599
+ darkThemeId: defaultDarkThemeId,
600
+ },
601
+ options: AccentVariableOptions = {}
602
+ ): AccentRoles | undefined {
571
603
  if (accentId === 'theme') return undefined
572
- const { light, dark } = recordPair(pair.lightThemeId, pair.darkThemeId)
573
- const preset = resolveAccentPreset(accentId, light, dark)
574
- if (!preset) return undefined
575
-
576
- // `--primary-subtle` is deliberately not here. It is a `color-mix()` over
577
- // `var(--primary)`, so the theme's own declaration (`themeCssVariables`, or the
578
- // default block in `theme.css`) already follows the accent; and its strength is the
579
- // *theme's*, measured by `primarySubtleAlpha` to hold body text at 4.5:1 for every
580
- // accent the theme offers. Writing one here would replace that measured strength
581
- // with whatever this function was given, which is how an accent used to undo it.
582
- const roles = accentRoles(preset, appearance)
583
- return {
584
- '--primary': roles.primary,
585
- '--primary-foreground': roles.primaryForeground,
586
- '--primary-hover': roles.primaryHover,
587
- '--ring': roles.ring,
588
- }
604
+ const record = options.variantId ? getTheme(options.variantId) : undefined
605
+ return resolveAccentRoles(accentId, {
606
+ target: record ?? appearance,
607
+ background: options.background,
608
+ floor: options.floor,
609
+ // Only an `ansi-*` id needs the pair's offering, and measuring it is not free.
610
+ themeAccents: isThemeAccentId(accentId)
611
+ ? themeAccentsFor(pair.lightThemeId, pair.darkThemeId)
612
+ : undefined,
613
+ })
589
614
  }
590
615
 
591
616
  /**
@@ -708,6 +733,20 @@ export function themeCssVariables(theme: ThemeVariant): Record<string, string> {
708
733
  return theme.tokens ? { ...derived, ...theme.tokens } : derived
709
734
  }
710
735
 
736
+ /**
737
+ * The `--terminal-*` properties of a variant: the palette a terminal paints.
738
+ *
739
+ * What a pinned terminal theme writes over the interface variant's own. Taken from
740
+ * {@link themeCssVariables} rather than rebuilt, so the names, and a custom
741
+ * variant's verbatim `tokens`, can never drift from what the interface variant
742
+ * would have written for the same palette.
743
+ */
744
+ export function terminalCssVariables(theme: ThemeVariant): Record<string, string> {
745
+ return Object.fromEntries(
746
+ Object.entries(themeCssVariables(theme)).filter(([name]) => name.startsWith('--terminal-'))
747
+ )
748
+ }
749
+
711
750
  /**
712
751
  * Token values with every `oklch()` colour written as `#rrggbb`.
713
752
  *
package/src/lib/tokens.ts CHANGED
@@ -122,6 +122,23 @@ export const colorTokens: TokenDefinition[] = [
122
122
  themed: true,
123
123
  description: 'Opacity of the chrome fill behind a blur.',
124
124
  },
125
+ {
126
+ name: 'surface-alpha',
127
+ kind: 'number',
128
+ description:
129
+ "The opacity a frosted dialog's fill keeps, written by the provider's surface axis. 1 is opaque and never matches the frost rule.",
130
+ },
131
+ {
132
+ name: 'surface-frost',
133
+ kind: 'number',
134
+ description: 'The fill opacity `--surface-alpha` takes for the frosted surface: 0.92.',
135
+ },
136
+ {
137
+ name: 'surface-translucent',
138
+ kind: 'number',
139
+ description:
140
+ 'The fill opacity `--surface-alpha` takes for the translucent surface: 0.8. A host without native translucency paints frosted instead.',
141
+ },
125
142
 
126
143
  // The brand action
127
144
  {
@@ -637,6 +637,15 @@
637
637
  --z-menu: 140;
638
638
  --z-tooltip: 160;
639
639
  --z-toast: 180;
640
+
641
+ /* Surface glass. `--surface-alpha` is what the provider's surface axis writes: the
642
+ opacity a frosted dialog's fill keeps (1 = opaque, so the default never matches
643
+ the frost rule's blur). `--surface-frost` and `--surface-translucent` are the two
644
+ amounts it chooses between; `lib/theme-surface.ts` writes the same numbers, and
645
+ `tests/theme-surface.test.ts` fails when they disagree. */
646
+ --surface-alpha: 1;
647
+ --surface-frost: 0.92;
648
+ --surface-translucent: 0.8;
640
649
  }
641
650
 
642
651
  /* Compact density: the standard control ladder one rung tighter.
@@ -687,6 +696,35 @@
687
696
  --shadow-xl: 0 20px 44px oklch(0 0 0 / 0.45);
688
697
  }
689
698
 
699
+ /* The OS-level backstop for the surface axis. The provider resolves the effective
700
+ surface and the reduced-transparency policy and writes `--surface-alpha` inline,
701
+ which outranks this rule; this is what keeps a frost amount from outliving the
702
+ system's Reduce Transparency setting for a document the provider has not
703
+ reached yet (a server-rendered one, before hydration). */
704
+ @media (prefers-reduced-transparency: reduce) {
705
+ :root {
706
+ --surface-alpha: 1;
707
+ }
708
+ }
709
+
710
+ /* Tokenized frost: while the resolved surface asks for glass, a modal dialog goes
711
+ translucent and blurs the content behind it. The opaque default and both
712
+ reduced-transparency paths resolve `--surface-alpha` to 1 and never write
713
+ `data-surface='frosted'`, so frost only ever applies when the user chose it and
714
+ the platform can honour it. Native window vibrancy (a desktop shell's translucent
715
+ surface) remains the shell's work; this is the frost the surface preference
716
+ promises everywhere else.
717
+
718
+ Modal dialogs only: a sheet carries `data-variant` and keeps its own bands. */
719
+ [data-surface='frosted'] [role='dialog']:not([data-variant]) {
720
+ background-color: color-mix(
721
+ in srgb,
722
+ var(--background) calc(var(--surface-alpha) * 100%),
723
+ transparent
724
+ );
725
+ backdrop-filter: blur(1.25rem) saturate(140%);
726
+ }
727
+
690
728
  /* ---------------------------------------------------------------------------
691
729
  * 4b. Named CSS hooks
692
730
  *