@titan-design/react-ui 0.9.2 → 0.10.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.
- package/dist/bodymap.js +78 -24
- package/dist/bodymap.js.map +1 -1
- package/dist/bodymap.mjs +78 -24
- package/dist/bodymap.mjs.map +1 -1
- package/dist/index.d.mts +215 -123
- package/dist/index.d.ts +215 -123
- package/dist/index.js +408 -259
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +258 -121
- package/dist/index.mjs.map +1 -1
- package/dist/pages.js +214 -157
- package/dist/pages.js.map +1 -1
- package/dist/pages.mjs +214 -157
- package/dist/pages.mjs.map +1 -1
- package/dist/theme/index.d.mts +895 -795
- package/dist/theme/index.d.ts +895 -795
- package/dist/theme/index.js +101 -20
- package/dist/theme/index.js.map +1 -1
- package/dist/theme/index.mjs +99 -22
- package/dist/theme/index.mjs.map +1 -1
- package/dist/theme/tokens-css.js +88 -24
- package/dist/theme/tokens-css.js.map +1 -1
- package/dist/theme/tokens-css.mjs +88 -24
- package/dist/theme/tokens-css.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/custom/Workout/BaseBadge.tsx +5 -5
- package/src/components/custom/Workout/RowInventory.stories.tsx +5 -2
- package/src/components/custom/Workout/S3FullRail.stories.tsx +13 -1
- package/src/components/custom/Workout/SessionHeader.tsx +11 -13
- package/src/components/custom/Workout/SessionRail.stories.tsx +4 -1
- package/src/components/custom/Workout/SessionRail.tsx +16 -14
- package/src/components/custom/Workout/SupersetWrapper.stories.tsx +16 -25
- package/src/components/custom/Workout/SupersetWrapper.tsx +1 -1
- package/src/components/custom/Workout/TempoDisplay.tsx +3 -7
- package/src/components/custom/Workout/VolumeLandmarkBar.stories.tsx +4 -1
- package/src/components/custom/Workout/WorkoutPill.tsx +2 -2
- package/src/components/shell/DashboardShell.tsx +6 -3
- package/src/components/ui/surface/Surface.stories.tsx +244 -1
- package/src/components/ui/surface/Surface.test.tsx +244 -1
- package/src/components/ui/surface/Surface.tsx +98 -20
- package/src/components/ui/surface/SurfaceContext.ts +126 -0
- package/src/components/ui/surface/index.ts +13 -0
- package/src/components/ui/surface/surface.contract.test.ts +283 -0
- package/src/test/nativewind-stub.ts +13 -0
- package/src/theme/ColorSystem.stories.tsx +232 -47
- package/src/theme/ThemeProvider.test.tsx +24 -0
- package/src/theme/ThemeProvider.tsx +23 -6
- package/src/theme/config.ts +12 -0
- package/src/theme/elevation.ts +90 -67
- package/src/theme/global.css +35 -9
- package/src/theme/tokens/primitives.ts +40 -0
- package/src/theme/tokens/semantic.ts +63 -14
- package/tailwind.config.js +8 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// On-surface colour context (TD-05.12).
|
|
2
|
+
//
|
|
3
|
+
// A <Surface> owns a background from a small elevation scale AND publishes the
|
|
4
|
+
// current theme mode so descendant text/icons resolve their colour from "what
|
|
5
|
+
// surface am I on" instead of a `text-*` className. Those classNames silently
|
|
6
|
+
// fail to black when the tree renders as raw RN in the standalone wall SPA
|
|
7
|
+
// (no global.css, no nativewind) — the bug class this primitive retires.
|
|
8
|
+
import { createContext, useContext } from 'react'
|
|
9
|
+
import { getSemanticColors, type ThemeMode } from '../../../theme/tokens/semantic'
|
|
10
|
+
import { surfaceRampDark } from '../../../theme/tokens/primitives'
|
|
11
|
+
|
|
12
|
+
type ColorToken = keyof ReturnType<typeof getSemanticColors>
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A Surface's depth on the dark surface ramp. Each addressable level maps to an
|
|
16
|
+
* EXISTING semantic surface/background token (already grounded in the derived
|
|
17
|
+
* surface ramp — TD-surface-tokens S-1 — and theme-aware) — Surface introduces
|
|
18
|
+
* no new hexes. Darkest → lightest:
|
|
19
|
+
* inset (#13100D) < background (#1C1916) < base (#252321) < elevated (#2A2827) < raised (#2D2C2B) < overlay (#302F2E)
|
|
20
|
+
*
|
|
21
|
+
* `inset` is the ramp's deepest pit — the sub-shell well. It's the floor a
|
|
22
|
+
* `<Surface pressed>` clamps at (see {@link pressedLevel}); it has no shipped
|
|
23
|
+
* semantic token yet, so {@link surfaceBackground} resolves it from the
|
|
24
|
+
* `surface-inset` token when present, else the `surfaceRampDark.inset` primitive.
|
|
25
|
+
*/
|
|
26
|
+
export type SurfaceLevel = 'inset' | 'background' | 'base' | 'elevated' | 'raised' | 'overlay'
|
|
27
|
+
|
|
28
|
+
/** On-surface neutral text roles, resolved for the current surface + theme. */
|
|
29
|
+
export type OnSurfaceRole = 'primary' | 'secondary' | 'tertiary'
|
|
30
|
+
|
|
31
|
+
// Which semantic token backs each ADDRESSABLE level. Values live in `semantic.ts`
|
|
32
|
+
// and stay in sync with the charcoal ramp — this map never carries literal hexes.
|
|
33
|
+
// `inset` is intentionally absent: it has no shipped semantic token yet, so it's
|
|
34
|
+
// resolved separately (token-or-primitive) in `surfaceBackground`.
|
|
35
|
+
export const SURFACE_LEVEL_TOKEN = {
|
|
36
|
+
background: 'background-base',
|
|
37
|
+
base: 'surface-base',
|
|
38
|
+
elevated: 'surface-elevated',
|
|
39
|
+
raised: 'surface-raised',
|
|
40
|
+
overlay: 'surface-overlay',
|
|
41
|
+
} as const satisfies Record<Exclude<SurfaceLevel, 'inset'>, ColorToken>
|
|
42
|
+
|
|
43
|
+
// Darkest → lightest, INCLUDING the inset floor. A `<Surface pressed>` renders
|
|
44
|
+
// one index DOWN from its parent's level and clamps at `inset` (index 0). Kept
|
|
45
|
+
// in lockstep with the derived ramp and the surface.contract.test PLANE_ORDER.
|
|
46
|
+
const PRESSED_RAMP = ['inset', 'background', 'base', 'elevated', 'raised', 'overlay'] as const
|
|
47
|
+
|
|
48
|
+
const ON_SURFACE_TOKEN = {
|
|
49
|
+
primary: 'text-primary',
|
|
50
|
+
secondary: 'text-secondary',
|
|
51
|
+
tertiary: 'text-tertiary',
|
|
52
|
+
} as const satisfies Record<OnSurfaceRole, ColorToken>
|
|
53
|
+
|
|
54
|
+
export interface SurfaceContextValue {
|
|
55
|
+
/** Active theme mode. Defaults to dark (the wall). */
|
|
56
|
+
mode: ThemeMode
|
|
57
|
+
/** Depth of the nearest enclosing Surface. */
|
|
58
|
+
level: SurfaceLevel
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Default context: dark 'base' plane, so descendants OUTSIDE any Surface still
|
|
62
|
+
// resolve to real dark colours (never black) on the dark-only wall.
|
|
63
|
+
const DEFAULT_CONTEXT: SurfaceContextValue = { mode: 'dark', level: 'base' }
|
|
64
|
+
|
|
65
|
+
export const SurfaceContext = createContext<SurfaceContextValue>(DEFAULT_CONTEXT)
|
|
66
|
+
|
|
67
|
+
/** The nearest surface context ({ mode, level }); default dark 'base'. */
|
|
68
|
+
export function useSurface(): SurfaceContextValue {
|
|
69
|
+
return useContext(SurfaceContext)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** The active theme mode from the nearest Surface/provider (default dark). */
|
|
73
|
+
export function useSurfaceMode(): ThemeMode {
|
|
74
|
+
return useContext(SurfaceContext).mode
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Literal-hex on-surface neutral text colours for a theme mode. Uses
|
|
79
|
+
* `getSemanticColors` (literal hex — the TempoBar pattern), never `resolveColor`
|
|
80
|
+
* (which returns `var()` under the RNW vitest alias), so values stay real in
|
|
81
|
+
* tested component code and on raw-RN surfaces alike.
|
|
82
|
+
*/
|
|
83
|
+
export function onSurfaceColors(mode: ThemeMode): Record<OnSurfaceRole, string> {
|
|
84
|
+
const c = getSemanticColors(mode)
|
|
85
|
+
return {
|
|
86
|
+
primary: c[ON_SURFACE_TOKEN.primary],
|
|
87
|
+
secondary: c[ON_SURFACE_TOKEN.secondary],
|
|
88
|
+
tertiary: c[ON_SURFACE_TOKEN.tertiary],
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Resolve one on-surface text colour for descendants of a Surface. */
|
|
93
|
+
export function useOnSurfaceColor(role: OnSurfaceRole = 'primary'): string {
|
|
94
|
+
return getSemanticColors(useSurfaceMode())[ON_SURFACE_TOKEN[role]]
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* The inset floor hex — the ramp's deepest pit that a pressed surface clamps at.
|
|
99
|
+
* Prefers the `surface-inset` semantic token (theme-aware; being promoted in a
|
|
100
|
+
* parallel token change) and falls back to the `surfaceRampDark.inset` primitive
|
|
101
|
+
* (#13100D, dark-ramp only) until that token ships.
|
|
102
|
+
*/
|
|
103
|
+
function insetFloor(mode: ThemeMode): string {
|
|
104
|
+
const colors = getSemanticColors(mode) as Record<string, string>
|
|
105
|
+
return colors['surface-inset'] ?? surfaceRampDark.inset
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** The background hex for a surface level under a theme mode (literal hex). */
|
|
109
|
+
export function surfaceBackground(level: SurfaceLevel, mode: ThemeMode): string {
|
|
110
|
+
if (level === 'inset') return insetFloor(mode)
|
|
111
|
+
return getSemanticColors(mode)[SURFACE_LEVEL_TOKEN[level]]
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* The level a `<Surface pressed>` resolves to: its parent's level stepped one
|
|
116
|
+
* index DOWN the ramp — the symmetric twin of a raised surface stepping up —
|
|
117
|
+
* clamped at the `inset` floor so a pressed surface never underflows the pit.
|
|
118
|
+
* overlay→raised, raised→elevated, elevated→base, base→background,
|
|
119
|
+
* background→inset, inset→inset (clamped).
|
|
120
|
+
* Pressed exposes ONE level of depth only (no pressed-2).
|
|
121
|
+
*/
|
|
122
|
+
export function pressedLevel(parent: SurfaceLevel): SurfaceLevel {
|
|
123
|
+
const index = PRESSED_RAMP.indexOf(parent)
|
|
124
|
+
const down = Math.max(0, index - 1)
|
|
125
|
+
return PRESSED_RAMP[down]
|
|
126
|
+
}
|
|
@@ -1 +1,14 @@
|
|
|
1
1
|
export { Surface, type SurfaceProps } from './Surface'
|
|
2
|
+
export {
|
|
3
|
+
SurfaceContext,
|
|
4
|
+
useSurface,
|
|
5
|
+
useSurfaceMode,
|
|
6
|
+
useOnSurfaceColor,
|
|
7
|
+
onSurfaceColors,
|
|
8
|
+
surfaceBackground,
|
|
9
|
+
pressedLevel,
|
|
10
|
+
SURFACE_LEVEL_TOKEN,
|
|
11
|
+
type SurfaceLevel,
|
|
12
|
+
type OnSurfaceRole,
|
|
13
|
+
type SurfaceContextValue,
|
|
14
|
+
} from './SurfaceContext'
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { getSemanticColors } from '../../../theme/tokens/semantic'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Token-value contract for the dark surface ramp (TD-surface-tokens, S-1).
|
|
6
|
+
* Mirrors `config.completeness.test.ts`'s role — this fails CI on the raw
|
|
7
|
+
* token VALUES, independent of any component, the same way the categorical
|
|
8
|
+
* palette locks its eligibility mask with a value-level test.
|
|
9
|
+
*
|
|
10
|
+
* Scope: DARK mode only. The north-star diagnosis
|
|
11
|
+
* (coordination/design-explorations/surface-system-north-star.md) measured and
|
|
12
|
+
* fixed the dark ramp specifically; light mode has its own latent collisions
|
|
13
|
+
* (e.g. `surface-overlay` === `surface-base`, both `#FFFFFF`) that were never
|
|
14
|
+
* part of this investigation — flagged as a follow-up, not silently patched
|
|
15
|
+
* here (see the report / open item list).
|
|
16
|
+
*
|
|
17
|
+
* ── R1 note — why this does NOT assert a flat ΔL* >= 4 on every step ──
|
|
18
|
+
* An earlier draft of the north-star doc (§3) proposed 5 EVEN steps at
|
|
19
|
+
* ΔL*≈4. The LOCKED derivation that ships here (§ "Surface-ramp SYSTEM —
|
|
20
|
+
* derived, not hand-picked") deliberately supersedes that with DIMINISHING
|
|
21
|
+
* steps — the frame->content jump is biggest, each plane above adds less.
|
|
22
|
+
* As of S-3 (this re-space) the steps are 4.5 / 4.5 / 3.5 / 3 / 2.5
|
|
23
|
+
* (inset->background / background->base / base->elevated / elevated->raised /
|
|
24
|
+
* raised->overlay) — the top three widened from the original 2.5/2/1.5 taper
|
|
25
|
+
* so the content planes read as distinct without leaning on the hairline
|
|
26
|
+
* alone (R3 still carries the rest, per "lightness is a *secondary* cue").
|
|
27
|
+
* So R1 here asserts what the locked design actually guarantees: strict
|
|
28
|
+
* monotonicity, a >=4 L* foundational jump at the frame/shell boundary, and
|
|
29
|
+
* a >=2.5 L* floor on each of the three re-spaced upper steps — not a flat
|
|
30
|
+
* "always diminishing" rule (quantizing to whole hex bytes can make two
|
|
31
|
+
* adjacent re-spaced steps land within ~0.02 L* of each other; the floor is
|
|
32
|
+
* the guarantee that matters, not strict ordering between them).
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
// --- CIELAB L* (perceptual lightness), matching the calculation in
|
|
36
|
+
// surface-lab-shared.tsx's `lstar()` (the derivation source) verbatim, so
|
|
37
|
+
// this test measures the SAME metric the ramp was designed against. ---
|
|
38
|
+
function channels(hex: string): [number, number, number] {
|
|
39
|
+
const h = hex.replace('#', '')
|
|
40
|
+
return [0, 2, 4].map((i) => parseInt(h.slice(i, i + 2), 16)) as [number, number, number]
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function lstar(hex: string): number {
|
|
44
|
+
const lin = channels(hex)
|
|
45
|
+
.map((c) => c / 255)
|
|
46
|
+
.map((c) => (c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4))
|
|
47
|
+
const y = 0.2126 * lin[0] + 0.7152 * lin[1] + 0.0722 * lin[2]
|
|
48
|
+
return y <= 0.008856 ? y * 903.3 : 116 * Math.cbrt(y) - 16
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Flatten an rgba(...) alpha color over an opaque hex background -> opaque hex. */
|
|
52
|
+
function compositeOver(baseHex: string, overlay: string): string {
|
|
53
|
+
const match = overlay.match(
|
|
54
|
+
/rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*(?:,\s*([\d.]+)\s*)?\)/
|
|
55
|
+
)
|
|
56
|
+
if (!match) throw new Error(`not an rgba() color: ${overlay}`)
|
|
57
|
+
const [, r, g, b, a = '1'] = match
|
|
58
|
+
const alpha = parseFloat(a)
|
|
59
|
+
const base = channels(baseHex)
|
|
60
|
+
const tint = [parseFloat(r), parseFloat(g), parseFloat(b)]
|
|
61
|
+
const mixed = base.map((c, i) => c * (1 - alpha) + tint[i] * alpha)
|
|
62
|
+
return (
|
|
63
|
+
'#' +
|
|
64
|
+
mixed
|
|
65
|
+
.map((v) =>
|
|
66
|
+
Math.max(0, Math.min(255, Math.round(v)))
|
|
67
|
+
.toString(16)
|
|
68
|
+
.padStart(2, '0')
|
|
69
|
+
)
|
|
70
|
+
.join('')
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const dark = getSemanticColors('dark')
|
|
75
|
+
|
|
76
|
+
// The 6-plane derivation, in darkest -> lightest order. `inset` is now a real
|
|
77
|
+
// shipped token (`surface-inset`, promoted at S-3 — see semantic.ts comment).
|
|
78
|
+
const RAMP_HEX = {
|
|
79
|
+
inset: dark['surface-inset'],
|
|
80
|
+
background: dark['background-base'],
|
|
81
|
+
base: dark['surface-base'],
|
|
82
|
+
elevated: dark['surface-elevated'],
|
|
83
|
+
raised: dark['surface-raised'],
|
|
84
|
+
overlay: dark['surface-overlay'],
|
|
85
|
+
} as const
|
|
86
|
+
|
|
87
|
+
const PLANE_ORDER = ['inset', 'background', 'base', 'elevated', 'raised', 'overlay'] as const
|
|
88
|
+
|
|
89
|
+
describe('surface ramp contract (dark) — token-value guardrails', () => {
|
|
90
|
+
it('ships the deriveSurfaceRamp() output verbatim for the addressable planes', () => {
|
|
91
|
+
// Locked values from surface-system-north-star.md (re-spaced S-3) — see
|
|
92
|
+
// surfaceRampDark in primitives.ts for the derivation this must match
|
|
93
|
+
// byte-for-byte. background/base/inset are unchanged by the re-space.
|
|
94
|
+
expect(dark['surface-inset']).toBe('#13100D')
|
|
95
|
+
expect(dark['background-base']).toBe('#1C1916')
|
|
96
|
+
expect(dark['surface-base']).toBe('#252321')
|
|
97
|
+
expect(dark['surface-elevated']).toBe('#2C2A28')
|
|
98
|
+
expect(dark['surface-raised']).toBe('#31302F')
|
|
99
|
+
expect(dark['surface-overlay']).toBe('#373635')
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
describe('R1 — monotonic ramp with a real foundational jump', () => {
|
|
103
|
+
it('is strictly increasing in L* across all 6 planes', () => {
|
|
104
|
+
const Ls = PLANE_ORDER.map((name) => lstar(RAMP_HEX[name]))
|
|
105
|
+
for (let i = 1; i < Ls.length; i++) {
|
|
106
|
+
expect(
|
|
107
|
+
Ls[i],
|
|
108
|
+
`${PLANE_ORDER[i]} should be lighter than ${PLANE_ORDER[i - 1]}`
|
|
109
|
+
).toBeGreaterThan(Ls[i - 1])
|
|
110
|
+
}
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
it('clears ΔL* >= 4 at the two foundational steps (inset->background, background->base)', () => {
|
|
114
|
+
const dL_insetToBackground = lstar(RAMP_HEX.background) - lstar(RAMP_HEX.inset)
|
|
115
|
+
const dL_backgroundToBase = lstar(RAMP_HEX.base) - lstar(RAMP_HEX.background)
|
|
116
|
+
expect(dL_insetToBackground).toBeGreaterThanOrEqual(4)
|
|
117
|
+
expect(dL_backgroundToBase).toBeGreaterThanOrEqual(4)
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
it('each re-spaced upper step (base->elevated->raised->overlay) clears ΔL* >= 2.5', () => {
|
|
121
|
+
// S-3 widened the top three steps to 3.5/3/2.5 specifically so they no
|
|
122
|
+
// longer need to lean on the "keep diminishing" clause the old 2.5/2/1.5
|
|
123
|
+
// taper required — each step now stands on its own >=2.5 L* floor.
|
|
124
|
+
// (Quantizing to whole hex bytes can make two of these land within
|
|
125
|
+
// ~0.02 L* of strict diminishing order; that's expected and not asserted.)
|
|
126
|
+
const upperSteps = ['base', 'elevated', 'raised', 'overlay'] as const
|
|
127
|
+
for (let i = 1; i < upperSteps.length; i++) {
|
|
128
|
+
const d = lstar(RAMP_HEX[upperSteps[i]]) - lstar(RAMP_HEX[upperSteps[i - 1]])
|
|
129
|
+
expect(d, `${upperSteps[i - 1]} -> ${upperSteps[i]}`).toBeGreaterThanOrEqual(2.5)
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
describe('R2 — no footgun collisions', () => {
|
|
135
|
+
it('surface-elevated and surface-overlay are distinct (previously both #191919)', () => {
|
|
136
|
+
expect(dark['surface-elevated']).not.toBe(dark['surface-overlay'])
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
it('the 5 addressable surface-family hexes are pairwise distinct', () => {
|
|
140
|
+
const family = [
|
|
141
|
+
'surface-base',
|
|
142
|
+
'surface-elevated',
|
|
143
|
+
'surface-raised',
|
|
144
|
+
'surface-overlay',
|
|
145
|
+
] as const
|
|
146
|
+
const values = family.map((k) => dark[k])
|
|
147
|
+
expect(new Set(values).size).toBe(values.length)
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
it('no solid border token equals any surface/background fill hex', () => {
|
|
151
|
+
const surfaceHexes = new Set([
|
|
152
|
+
dark['background-base'],
|
|
153
|
+
dark['background-default'],
|
|
154
|
+
dark['background-subtle'],
|
|
155
|
+
dark['background-frame'],
|
|
156
|
+
dark['surface-base'],
|
|
157
|
+
dark['surface-elevated'],
|
|
158
|
+
dark['surface-raised'],
|
|
159
|
+
dark['surface-overlay'],
|
|
160
|
+
dark['surface-input'],
|
|
161
|
+
dark['surface-inset'],
|
|
162
|
+
])
|
|
163
|
+
const solidBorders = [
|
|
164
|
+
'border-default',
|
|
165
|
+
'border-subtle',
|
|
166
|
+
'border-strong',
|
|
167
|
+
'border-prominent',
|
|
168
|
+
] as const
|
|
169
|
+
for (const token of solidBorders) {
|
|
170
|
+
expect(
|
|
171
|
+
surfaceHexes.has(dark[token]),
|
|
172
|
+
`${token} (${dark[token]}) collides with a surface hex`
|
|
173
|
+
).toBe(false)
|
|
174
|
+
}
|
|
175
|
+
})
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
describe('R3 — alpha hairline clears its ΔL* floor on every plane', () => {
|
|
179
|
+
// Doc floors (subtle>=6/default>=9/strong>=13) were calibrated on the OLD,
|
|
180
|
+
// much darker ramp (L* 4.7-10.3). The S-1 ramp compressed into a narrower,
|
|
181
|
+
// lighter band (L* 9-19.5); S-3's re-space widens it further still
|
|
182
|
+
// (L* 4.5-22.5) — the wider top steps push `overlay` even lighter, so the
|
|
183
|
+
// SAME alpha values composite to a slightly smaller (but still solid,
|
|
184
|
+
// still near-constant) ΔL* there. Floors below are re-measured against
|
|
185
|
+
// the S-3 ramp (default dropped 8->7 — the `overlay` plane now measures
|
|
186
|
+
// ~7.97, just under the old floor); a wall-display calibration pass (S-6)
|
|
187
|
+
// may retune the alpha values themselves.
|
|
188
|
+
const HAIRLINES = {
|
|
189
|
+
subtle: { token: 'hairline-subtle', floor: 5 },
|
|
190
|
+
default: { token: 'hairline-default', floor: 7 },
|
|
191
|
+
strong: { token: 'hairline-strong', floor: 12 },
|
|
192
|
+
} as const
|
|
193
|
+
|
|
194
|
+
for (const [name, { token, floor }] of Object.entries(HAIRLINES)) {
|
|
195
|
+
it(`${name} (${token}) clears ΔL* >= ${floor} on every ramp plane`, () => {
|
|
196
|
+
const hairlineColor = dark[token as keyof typeof dark]
|
|
197
|
+
for (const plane of PLANE_ORDER) {
|
|
198
|
+
const planeHex = RAMP_HEX[plane]
|
|
199
|
+
const composited = compositeOver(planeHex, hairlineColor)
|
|
200
|
+
const dL = lstar(composited) - lstar(planeHex)
|
|
201
|
+
expect(dL, `${name} on ${plane}`).toBeGreaterThanOrEqual(floor)
|
|
202
|
+
}
|
|
203
|
+
})
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
it('is near-constant (self-normalizing) across all planes: spread < 4 L* per tier', () => {
|
|
207
|
+
// Measured spread (inset..overlay): subtle ~1.6, default ~2.2, strong ~3.2 —
|
|
208
|
+
// still far tighter than a solid border token (which swings ~5.6 -> 0
|
|
209
|
+
// across this same ramp, see R4). "Near-constant" is relative to that,
|
|
210
|
+
// not perfectly flat — alpha-over-white is sublinear in L* as the base
|
|
211
|
+
// lightens, which is exactly the R3 floor-vs-doc discrepancy noted above.
|
|
212
|
+
for (const { token } of Object.values(HAIRLINES)) {
|
|
213
|
+
const hairlineColor = dark[token as keyof typeof dark]
|
|
214
|
+
const deltas = PLANE_ORDER.map((plane) => {
|
|
215
|
+
const planeHex = RAMP_HEX[plane]
|
|
216
|
+
return lstar(compositeOver(planeHex, hairlineColor)) - lstar(planeHex)
|
|
217
|
+
})
|
|
218
|
+
expect(Math.max(...deltas) - Math.min(...deltas)).toBeLessThan(4)
|
|
219
|
+
}
|
|
220
|
+
})
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
describe('R4 — border-on-surface clears ΔL* >= 3 (fixes the invisible-hairline collision)', () => {
|
|
224
|
+
it('border-subtle is no longer invisible on surface-raised (the original bug)', () => {
|
|
225
|
+
const dL = Math.abs(lstar(dark['border-subtle']) - lstar(dark['surface-raised']))
|
|
226
|
+
expect(dL).toBeGreaterThanOrEqual(3)
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
it('border-subtle clears ΔL* >= 3 against base/elevated/raised/overlay', () => {
|
|
230
|
+
const planes = [
|
|
231
|
+
'surface-base',
|
|
232
|
+
'surface-elevated',
|
|
233
|
+
'surface-raised',
|
|
234
|
+
'surface-overlay',
|
|
235
|
+
] as const
|
|
236
|
+
for (const plane of planes) {
|
|
237
|
+
const dL = Math.abs(lstar(dark['border-subtle']) - lstar(dark[plane]))
|
|
238
|
+
expect(dL, `border-subtle vs ${plane}`).toBeGreaterThanOrEqual(3)
|
|
239
|
+
}
|
|
240
|
+
})
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
describe('R5 — background-frame and surface-inset (S-3 new tokens)', () => {
|
|
244
|
+
it('background-frame is darker than background-base', () => {
|
|
245
|
+
expect(lstar(dark['background-frame'])).toBeLessThan(lstar(dark['background-base']))
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
it('background-frame is distinct from every surface/background token', () => {
|
|
249
|
+
const otherTokens = [
|
|
250
|
+
'background-base',
|
|
251
|
+
'background-default',
|
|
252
|
+
'background-subtle',
|
|
253
|
+
'surface-base',
|
|
254
|
+
'surface-elevated',
|
|
255
|
+
'surface-raised',
|
|
256
|
+
'surface-overlay',
|
|
257
|
+
'surface-input',
|
|
258
|
+
'surface-inset',
|
|
259
|
+
] as const
|
|
260
|
+
for (const token of otherTokens) {
|
|
261
|
+
expect(dark['background-frame'], `background-frame vs ${token}`).not.toBe(dark[token])
|
|
262
|
+
}
|
|
263
|
+
})
|
|
264
|
+
|
|
265
|
+
it('surface-inset is the darkest surface-family token', () => {
|
|
266
|
+
const surfaceFamily = [
|
|
267
|
+
'surface-base',
|
|
268
|
+
'surface-elevated',
|
|
269
|
+
'surface-raised',
|
|
270
|
+
'surface-overlay',
|
|
271
|
+
'surface-input',
|
|
272
|
+
] as const
|
|
273
|
+
const insetL = lstar(dark['surface-inset'])
|
|
274
|
+
for (const token of surfaceFamily) {
|
|
275
|
+
expect(insetL, `surface-inset vs ${token}`).toBeLessThan(lstar(dark[token]))
|
|
276
|
+
}
|
|
277
|
+
})
|
|
278
|
+
|
|
279
|
+
it('surface-inset is distinct from background-frame', () => {
|
|
280
|
+
expect(dark['surface-inset']).not.toBe(dark['background-frame'])
|
|
281
|
+
})
|
|
282
|
+
})
|
|
283
|
+
})
|
|
@@ -11,3 +11,16 @@
|
|
|
11
11
|
export function vars(values: Record<string, string>): Record<string, string> {
|
|
12
12
|
return values
|
|
13
13
|
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Stand-in for nativewind's `useColorScheme()`. Under the web test env there is
|
|
17
|
+
* no nativewind theme applied, so it reports `undefined` (the "no explicit
|
|
18
|
+
* scheme" signal) — matching ThemeProvider's dark fallback for `mode="system"`.
|
|
19
|
+
*/
|
|
20
|
+
export function useColorScheme(): {
|
|
21
|
+
colorScheme: 'light' | 'dark' | undefined
|
|
22
|
+
setColorScheme: (scheme: 'light' | 'dark' | 'system') => void
|
|
23
|
+
toggleColorScheme: () => void
|
|
24
|
+
} {
|
|
25
|
+
return { colorScheme: undefined, setColorScheme: () => {}, toggleColorScheme: () => {} }
|
|
26
|
+
}
|