@eifi1/ui-kit 0.35.0 → 0.36.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/README.md +35 -5
- package/dist/admin/role-select.d.ts +3 -2
- package/dist/admin/role-select.js +2 -0
- package/dist/admin/role-select.js.map +1 -1
- package/dist/components/amount-input.d.ts +2 -2
- package/dist/components/amount-input.js.map +1 -1
- package/dist/components/autocomplete.d.ts +2 -2
- package/dist/components/autocomplete.js +2 -1
- package/dist/components/autocomplete.js.map +1 -1
- package/dist/components/button-look.d.ts +1 -1
- package/dist/components/button-look.js +9 -4
- package/dist/components/button-look.js.map +1 -1
- package/dist/components/checkbox-group.d.ts +5 -2
- package/dist/components/checkbox-group.js +15 -4
- package/dist/components/checkbox-group.js.map +1 -1
- package/dist/components/column-mapper.d.ts +5 -3
- package/dist/components/column-mapper.js +2 -0
- package/dist/components/column-mapper.js.map +1 -1
- package/dist/components/combobox.d.ts +2 -2
- package/dist/components/combobox.js +2 -1
- package/dist/components/combobox.js.map +1 -1
- package/dist/components/country-select.d.ts +3 -3
- package/dist/components/country-select.js +3 -0
- package/dist/components/country-select.js.map +1 -1
- package/dist/components/currency-select.d.ts +3 -2
- package/dist/components/currency-select.js +10 -1
- package/dist/components/currency-select.js.map +1 -1
- package/dist/components/date-field.d.ts +2 -1
- package/dist/components/date-field.js.map +1 -1
- package/dist/components/date-picker.js +3 -0
- package/dist/components/date-picker.js.map +1 -1
- package/dist/components/date-range-picker.js +3 -0
- package/dist/components/date-range-picker.js.map +1 -1
- package/dist/components/entity-combobox.d.ts +2 -2
- package/dist/components/entity-combobox.js +2 -1
- package/dist/components/entity-combobox.js.map +1 -1
- package/dist/components/field-parts.d.ts +66 -11
- package/dist/components/field-parts.js +32 -10
- package/dist/components/field-parts.js.map +1 -1
- package/dist/components/field-strip.d.ts +3 -2
- package/dist/components/field-strip.js +2 -1
- package/dist/components/field-strip.js.map +1 -1
- package/dist/components/field.d.ts +3 -2
- package/dist/components/field.js +24 -15
- package/dist/components/field.js.map +1 -1
- package/dist/components/help-popover.d.ts +9 -7
- package/dist/components/help-popover.js.map +1 -1
- package/dist/components/icon-picker.d.ts +3 -2
- package/dist/components/icon-picker.js +3 -0
- package/dist/components/icon-picker.js.map +1 -1
- package/dist/components/inline-entity-combobox.d.ts +2 -2
- package/dist/components/inline-entity-combobox.js +2 -1
- package/dist/components/inline-entity-combobox.js.map +1 -1
- package/dist/components/input.d.ts +2 -2
- package/dist/components/input.js +2 -1
- package/dist/components/input.js.map +1 -1
- package/dist/components/month-picker.d.ts +2 -1
- package/dist/components/month-picker.js +8 -1
- package/dist/components/month-picker.js.map +1 -1
- package/dist/components/multi-entity-combobox.d.ts +2 -2
- package/dist/components/multi-entity-combobox.js +2 -1
- package/dist/components/multi-entity-combobox.js.map +1 -1
- package/dist/components/multi-select.d.ts +2 -2
- package/dist/components/multi-select.js +3 -0
- package/dist/components/multi-select.js.map +1 -1
- package/dist/components/number-input.d.ts +2 -2
- package/dist/components/number-input.js.map +1 -1
- package/dist/components/numeric-field.d.ts +5 -2
- package/dist/components/numeric-field.js +4 -1
- package/dist/components/numeric-field.js.map +1 -1
- package/dist/components/one-time-code-input.d.ts +2 -1
- package/dist/components/one-time-code-input.js +2 -1
- package/dist/components/one-time-code-input.js.map +1 -1
- package/dist/components/phone-input.d.ts +1 -1
- package/dist/components/phone-input.js +4 -0
- package/dist/components/phone-input.js.map +1 -1
- package/dist/components/popover.js +1 -1
- package/dist/components/popover.js.map +1 -1
- package/dist/components/select.d.ts +4 -3
- package/dist/components/select.js +2 -1
- package/dist/components/select.js.map +1 -1
- package/dist/components/slider.d.ts +3 -2
- package/dist/components/slider.js +7 -1
- package/dist/components/slider.js.map +1 -1
- package/dist/components/stat-tile.js +2 -11
- package/dist/components/stat-tile.js.map +1 -1
- package/dist/components/swatch-picker.d.ts +3 -2
- package/dist/components/swatch-picker.js +3 -0
- package/dist/components/swatch-picker.js.map +1 -1
- package/dist/components/text-link.js +3 -1
- package/dist/components/text-link.js.map +1 -1
- package/dist/components/textarea.d.ts +2 -1
- package/dist/components/textarea.js +9 -3
- package/dist/components/textarea.js.map +1 -1
- package/dist/components/toggle-group.d.ts +2 -2
- package/dist/components/toggle-group.js +7 -3
- package/dist/components/toggle-group.js.map +1 -1
- package/dist/eslint/index.js +1 -1
- package/dist/i18n/defaults.js +5 -1
- package/dist/i18n/defaults.js.map +1 -1
- package/dist/i18n/german.js +97 -1
- package/dist/i18n/german.js.map +1 -1
- package/dist/i18n/kit-labels.d.ts +15 -0
- package/dist/i18n/kit-labels.js +21 -1
- package/dist/i18n/kit-labels.js.map +1 -1
- package/dist/i18n/locales/en.js +103 -2
- package/dist/i18n/locales/en.js.map +3 -3
- package/dist/i18n/locales/es.js +95 -1
- package/dist/i18n/locales/es.js.map +1 -1
- package/dist/i18n/locales/fr.js +96 -1
- package/dist/i18n/locales/fr.js.map +1 -1
- package/dist/i18n/locales/hu.js +95 -1
- package/dist/i18n/locales/hu.js.map +1 -1
- package/dist/i18n/locales/it.js +96 -1
- package/dist/i18n/locales/it.js.map +1 -1
- package/dist/i18n/locales/zh.js +95 -1
- package/dist/i18n/locales/zh.js.map +1 -1
- package/dist/i18n/review.js +13 -0
- package/dist/i18n/review.js.map +1 -1
- package/dist/i18n/shared-labels.js +3 -1
- package/dist/i18n/shared-labels.js.map +1 -1
- package/dist/index.d.ts +21 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/device-settings.d.ts +72 -0
- package/dist/lib/device-settings.js +64 -0
- package/dist/lib/device-settings.js.map +1 -0
- package/dist/lib/plain-text.d.ts +11 -0
- package/dist/lib/plain-text.js +16 -0
- package/dist/lib/plain-text.js.map +1 -0
- package/dist/lib/safe-storage.d.ts +6 -0
- package/dist/lib/safe-storage.js +11 -0
- package/dist/lib/safe-storage.js.map +1 -1
- package/dist/notifications/notification-parts.d.ts +39 -0
- package/dist/notifications/notification-parts.js +47 -0
- package/dist/notifications/notification-parts.js.map +1 -0
- package/dist/notifications/notification-types-setting.d.ts +62 -0
- package/dist/notifications/notification-types-setting.js +192 -0
- package/dist/notifications/notification-types-setting.js.map +1 -0
- package/dist/notifications/notification-types.d.ts +75 -0
- package/dist/notifications/notification-types.js +2 -0
- package/dist/notifications/notification-types.js.map +1 -0
- package/dist/notifications/notifications-labels.d.ts +131 -0
- package/dist/notifications/notifications-labels.js +83 -0
- package/dist/notifications/notifications-labels.js.map +1 -0
- package/dist/notifications/push-device-setting.d.ts +37 -0
- package/dist/notifications/push-device-setting.js +164 -0
- package/dist/notifications/push-device-setting.js.map +1 -0
- package/dist/notifications/push-devices-setting.d.ts +44 -0
- package/dist/notifications/push-devices-setting.js +203 -0
- package/dist/notifications/push-devices-setting.js.map +1 -0
- package/dist/notifications/quiet-hours-setting.d.ts +47 -0
- package/dist/notifications/quiet-hours-setting.js +131 -0
- package/dist/notifications/quiet-hours-setting.js.map +1 -0
- package/dist/notifications/time-zone-select.d.ts +50 -0
- package/dist/notifications/time-zone-select.js +76 -0
- package/dist/notifications/time-zone-select.js.map +1 -0
- package/dist/notifications/unsubscribe-panel.d.ts +53 -0
- package/dist/notifications/unsubscribe-panel.js +139 -0
- package/dist/notifications/unsubscribe-panel.js.map +1 -0
- package/dist/notifications/use-push-device.d.ts +122 -0
- package/dist/notifications/use-push-device.js +230 -0
- package/dist/notifications/use-push-device.js.map +1 -0
- package/dist/rhf/fields.d.ts +26 -19
- package/dist/rhf/fields.js +51 -22
- package/dist/rhf/fields.js.map +1 -1
- package/dist/settings/device-reset-setting-labels.d.ts +3 -0
- package/dist/settings/device-reset-setting-labels.js +15 -0
- package/dist/settings/device-reset-setting-labels.js.map +1 -0
- package/dist/settings/device-reset-setting.d.ts +58 -0
- package/dist/settings/device-reset-setting.js +51 -0
- package/dist/settings/device-reset-setting.js.map +1 -0
- package/dist/shell/app-shell.js +5 -0
- package/dist/shell/app-shell.js.map +1 -1
- package/dist/theme/contrast-tokens.d.ts +42 -4
- package/dist/theme/contrast-tokens.js +56 -9
- package/dist/theme/contrast-tokens.js.map +1 -1
- package/dist/theme/contrast.d.ts +4 -2
- package/dist/theme/contrast.js +13 -0
- package/dist/theme/contrast.js.map +1 -1
- package/dist/theme/palette-derive.d.ts +15 -1
- package/dist/theme/palette-derive.js +37 -8
- package/dist/theme/palette-derive.js.map +1 -1
- package/dist/theme/palette-presets.d.ts +2 -1
- package/dist/theme/palette-presets.js +5 -5
- package/dist/theme/palette-presets.js.map +1 -1
- package/dist/theme/palette-store.js +6 -0
- package/dist/theme/palette-store.js.map +1 -1
- package/dist/theme/text-size.js +6 -0
- package/dist/theme/text-size.js.map +1 -1
- package/dist/theme/theme-store.js +6 -0
- package/dist/theme/theme-store.js.map +1 -1
- package/package.json +1 -1
- package/src/admin/role-select.tsx +4 -1
- package/src/components/amount-input.tsx +2 -1
- package/src/components/autocomplete.tsx +5 -2
- package/src/components/button-look.ts +15 -5
- package/src/components/checkbox-group.tsx +22 -4
- package/src/components/column-mapper.tsx +6 -2
- package/src/components/combobox.tsx +5 -2
- package/src/components/country-select.tsx +6 -1
- package/src/components/currency-select.tsx +12 -3
- package/src/components/date-field.tsx +2 -2
- package/src/components/date-picker.tsx +3 -0
- package/src/components/date-range-picker.tsx +3 -0
- package/src/components/entity-combobox.tsx +5 -2
- package/src/components/field-parts.tsx +107 -19
- package/src/components/field-strip.tsx +4 -3
- package/src/components/field.tsx +28 -15
- package/src/components/help-popover.tsx +9 -7
- package/src/components/icon-picker.tsx +8 -3
- package/src/components/inline-entity-combobox.tsx +5 -2
- package/src/components/input.tsx +4 -2
- package/src/components/month-picker.tsx +10 -3
- package/src/components/multi-entity-combobox.tsx +5 -2
- package/src/components/multi-select.tsx +6 -1
- package/src/components/number-input.tsx +2 -2
- package/src/components/numeric-field.ts +10 -2
- package/src/components/one-time-code-input.tsx +5 -3
- package/src/components/phone-input.tsx +4 -0
- package/src/components/popover.tsx +3 -1
- package/src/components/select.tsx +6 -3
- package/src/components/slider.tsx +10 -3
- package/src/components/stat-tile.tsx +3 -18
- package/src/components/swatch-picker.tsx +9 -4
- package/src/components/text-link.tsx +3 -1
- package/src/components/textarea.tsx +11 -4
- package/src/components/toggle-group.tsx +21 -5
- package/src/i18n/defaults.ts +4 -0
- package/src/i18n/german.ts +113 -0
- package/src/i18n/kit-labels.tsx +51 -1
- package/src/i18n/locales/en.ts +6 -0
- package/src/i18n/locales/es.ts +106 -0
- package/src/i18n/locales/fr.ts +106 -0
- package/src/i18n/locales/hu.ts +104 -0
- package/src/i18n/locales/it.ts +105 -0
- package/src/i18n/locales/zh.ts +96 -0
- package/src/i18n/review.ts +13 -0
- package/src/i18n/shared-labels.ts +2 -0
- package/src/index.ts +50 -0
- package/src/lib/device-settings.ts +146 -0
- package/src/lib/plain-text.ts +22 -0
- package/src/lib/safe-storage.ts +16 -0
- package/src/notifications/notification-parts.tsx +83 -0
- package/src/notifications/notification-types-setting.tsx +309 -0
- package/src/notifications/notification-types.ts +80 -0
- package/src/notifications/notifications-labels.ts +238 -0
- package/src/notifications/push-device-setting.tsx +224 -0
- package/src/notifications/push-devices-setting.tsx +306 -0
- package/src/notifications/quiet-hours-setting.tsx +185 -0
- package/src/notifications/time-zone-select.tsx +126 -0
- package/src/notifications/unsubscribe-panel.tsx +203 -0
- package/src/notifications/use-push-device.ts +392 -0
- package/src/rhf/fields.tsx +77 -29
- package/src/settings/device-reset-setting-labels.ts +20 -0
- package/src/settings/device-reset-setting.tsx +119 -0
- package/src/shell/app-shell.tsx +8 -0
- package/src/theme/contrast-tokens.ts +106 -12
- package/src/theme/contrast.ts +30 -4
- package/src/theme/palette-derive.ts +68 -7
- package/src/theme/palette-presets.ts +9 -6
- package/src/theme/palette-store.ts +12 -0
- package/src/theme/text-size.ts +8 -0
- package/src/theme/theme-store.ts +10 -0
- package/tokens.css +38 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/theme/palette-derive.ts"],"sourcesContent":["import type { ThemeMode } from \"./theme-store\";\nimport type { TokenSet } from \"./palette-presets\";\nimport type { HeatStops } from \"./chart-palette\";\nimport {\n contrast,\n deltaE,\n toHex,\n hexToOklch,\n oklchToHex,\n parseHex,\n rgbToOklch,\n simulateCvd,\n solveLightness,\n} from \"./color\";\nimport type { CvdType, Oklch } from \"./color\";\nimport { brandSoft, hoverFill } from \"./contrast-tokens\";\n\n/**\n * Build a whole palette from one brand colour, plus any number of colours pinned by\n * hand, with every contrast ratio SOLVED rather than chosen and then hoped for.\n *\n * The presets this package shipped were assembled by eye and annotated with the ratios\n * they were believed to hold — `tokens.css` records \"7.0:1 and 4.8:1\", and\n * `palette-presets.ts` records \"2.67:1 … lifted they clear it at 3.30:1\". Nothing\n * computed any of them, and the audit found four of the nine default light chart hues\n * below the 3:1 that WCAG 1.4.11 requires of a graphical object. A comment is not a\n * test. Everything here is derived to a target and then measured, and\n * {@link auditPalette} returns the measurements so a caller can refuse a palette that\n * does not hold up.\n *\n * WHAT IS DERIVED AND WHAT IS NOT. The UI palette and the CATEGORICAL CHART RAMP solve\n * different problems and are deliberately kept apart. A UI colour needs contrast against\n * one known surface and carries a fixed meaning; a chart colour needs to stay separable\n * from eight unknown siblings, at roughly equal salience, with no implied order.\n * Optimising a set for one makes it worse at the other, which is why `deriveTokenSet`\n * leaves `chart` alone unless you explicitly ask for {@link deriveChartRamp}.\n */\n\n/* ── Inputs ───────────────────────────────────────────────────────────────── */\n\n/** A role whose hue may be pinned by the caller instead of chosen by the deriver. */\nexport type AnchorRole = \"brand\" | \"accent\" | \"danger\" | \"warning\" | \"success\" | \"info\";\n\nexport type PaletteAnchors = { brand: string } & Partial<Record<Exclude<AnchorRole, \"brand\">, string>>;\n\nexport interface DeriveOptions {\n anchors: PaletteAnchors;\n mode: ThemeMode;\n /**\n * How strongly the surfaces carry the brand's hue, 0–1 of the maximum useful tint.\n * 0 gives neutral greys; the shipped default is a visible warmth, because a page that\n * is very slightly the brand's hue reads as considered where a pure grey reads as\n * unstyled. Above ~0.5 the surfaces start competing with the content.\n */\n surfaceTint?: number;\n /** Contrast targets for the three text roles against the WORST surface. */\n textContrast?: { primary?: number; secondary?: number; muted?: number };\n}\n\n/* ── Outputs ──────────────────────────────────────────────────────────────── */\n\n/** The semantic layer, which lives in tokens.css rather than in `TokenSet`. */\nexport interface SemanticTokens {\n danger: string;\n dangerHover: string;\n dangerContrast: string;\n dangerBorder: string;\n /** The error line (invalid field, danger banner, destructive focus ring): as loud as\n * `dangerBorder` was before 0.15.5, so it keeps 3:1 against the surface. */\n dangerBorderStrong: string;\n dangerBg: string;\n warning: string;\n warningBorder: string;\n warningBg: string;\n info: string;\n infoBorder: string;\n infoBg: string;\n success: string;\n successBorder: string;\n successBg: string;\n /** Present only when a `accent` (secondary brand) anchor was supplied. */\n accent?: string;\n accentContrast?: string;\n accentBg?: string;\n}\n\nexport interface ContrastCheck {\n /** e.g. \"textMuted on bgPage\". */\n pair: string;\n ratio: number;\n /** What WCAG asks of this pair. */\n required: number;\n /** Which rule the requirement comes from, for a reader who wants to argue with it. */\n rule: string;\n passes: boolean;\n}\n\nexport interface ContrastReport {\n checks: ContrastCheck[];\n failures: ContrastCheck[];\n passes: boolean;\n}\n\nexport interface DerivedPalette {\n tokens: TokenSet;\n semantic: SemanticTokens;\n audit: ContrastReport;\n /** Compromises the deriver had to make, in plain words. Never silent. */\n warnings: string[];\n}\n\n/* ── The hue homes ────────────────────────────────────────────────────────── */\n\n/**\n * Where each semantic role wants to sit, and how far it may be pushed.\n *\n * A semantic colour is a convention before it is an aesthetic: danger is red because\n * every other interface the user has ever used made it red, and a \"danger\" button in\n * the brand's teal is a worse button however well it matches. So each role has a home\n * hue and a narrow licence to move — enough to get out of the brand's way when the\n * brand happens to live in the same neighbourhood, not enough to stop meaning what it\n * means. If it cannot get far enough, that is a warning, not a silent compromise.\n */\nconst HUE_HOME: Record<Exclude<AnchorRole, \"brand\" | \"accent\">, { hue: number; slack: number }> = {\n danger: { hue: 27, slack: 14 },\n warning: { hue: 75, slack: 16 },\n success: { hue: 150, slack: 20 },\n info: { hue: 240, slack: 22 },\n};\n\n/** Circular distance between two hue angles, 0–180. */\nfunction hueGap(a: number, b: number): number {\n const d = Math.abs(((a - b) % 360) + 360) % 360;\n return d > 180 ? 360 - d : d;\n}\n\n/**\n * Nudge `home` within `slack` to maximise the distance from every taken hue.\n *\n * Sampled rather than solved: the objective is a min-of-distances over a handful of\n * points on a short arc, which is piecewise-linear with kinks wherever the nearest\n * neighbour changes. Gradient methods stall on those kinks; 2° steps over a ±22° arc is\n * 23 evaluations of some trigonometry and cannot stall.\n */\nfunction placeHue(home: number, slack: number, taken: number[]): number {\n let best = home;\n let bestGap = Math.min(...taken.map((t) => hueGap(home, t)), 360);\n for (let d = -slack; d <= slack; d += 2) {\n const h = (home + d + 360) % 360;\n const gap = Math.min(...taken.map((t) => hueGap(h, t)), 360);\n // Ties go to the hue nearest home: a role should move only as far as it must.\n if (gap > bestGap + 1e-9) {\n best = h;\n bestGap = gap;\n }\n }\n return best;\n}\n\n/* ── Derivation ───────────────────────────────────────────────────────────── */\n\nconst SURFACE_L = {\n // Light: the PAGE is slightly darker than the cards on it, so a card reads as raised\n // without needing a shadow to say so. Matches the shipped presets' relationship.\n //\n // The light WELL is the page itself (0.33, docs/colour-roles-harmonization.md §5.3,\n // k26). Between the card and the page it sat 1.02–1.05:1 from the card it is inset\n // in, which is no well at all; at the page's lightness it stands out from the card\n // exactly as far as the card does from the page, and nothing re-solves, because the\n // page is already the surface every text role is solved against. Dark keeps its\n // well a step lighter than the card (1.11–1.13:1).\n light: { page: 0.912, surface: 0.945, surface2: 0.912 },\n dark: { page: 0.158, surface: 0.206, surface2: 0.249 },\n} as const;\n\n/**\n * What a hairline has to clear against the surface it divides.\n *\n * WCAG has nothing to say here — a decorative border is not a graphical object that\n * conveys information — so this is a house rule, and it is deliberately low. A border\n * that clears 3:1 is a RULE, not a hairline: it draws the eye to the box instead of to\n * what is in it. 1.5:1 is the point at which the edge is reliably findable without\n * becoming part of the composition.\n */\nconst BORDER_CONTRAST = 1.5;\n\n/** The most tint a surface can carry before it stops reading as a neutral ground. */\nconst MAX_SURFACE_CHROMA = 0.034;\n\n/**\n * The brand chroma from which the surfaces and the greys carry the brand's hue in full;\n * below it they carry it in proportion, down to none for a grey (round 0.34 BUG-8). A\n * grey has no hue — OKLCH reports 0, which is pink — and at full tint #808080 painted\n * every surface #eddde1.\n */\nconst FULL_HUE_CHROMA = 0.06;\n\n/** How much of the brand's hue the neutrals may carry: 0 for a grey, 1 from {@link FULL_HUE_CHROMA}. */\nfunction hueWeight(brand: Oklch): number {\n return Math.min(1, brand.c / FULL_HUE_CHROMA);\n}\n\nfunction surfaceSet(hue: number, mode: ThemeMode, tint: number, weight: number) {\n const c = MAX_SURFACE_CHROMA * Math.max(0, Math.min(1, tint)) * weight;\n const L = SURFACE_L[mode];\n const bgPage = oklchToHex({ l: L.page, c, h: hue });\n const bgSurface = oklchToHex({ l: L.surface, c, h: hue });\n const bgSurface2 = oklchToHex({ l: L.surface2, c, h: hue });\n // Solved, not guessed: a fixed lightness that looks right against a pale warm ground\n // disappears against a deep cold one, and both are reachable from the same `hue`\n // input. The border carries a little more chroma than the surfaces because at these\n // lightnesses a perfectly neutral hairline on a tinted ground reads as a wrong grey.\n const borderChroma = c * 1.6;\n // Solved against the surface the hairline is HARDEST to see on, not against one of\n // the three. Solving against `bgSurface` alone left it at 1.36:1 on `bgPage`, so the\n // target and the audit disagreed about the same border.\n const hardest = [bgPage, bgSurface, bgSurface2].reduce((a, b) =>\n contrast(a, mode === \"light\" ? \"#000000\" : \"#ffffff\") <\n contrast(b, mode === \"light\" ? \"#000000\" : \"#ffffff\")\n ? a\n : b,\n );\n const borderL = solveLightness(\n BORDER_CONTRAST,\n parseHex(hardest)!,\n hue,\n borderChroma,\n mode === \"light\" ? \"darker\" : \"lighter\",\n );\n return {\n bgPage,\n bgSurface,\n bgSurface2,\n border: oklchToHex({ l: borderL, c: borderChroma, h: hue }),\n };\n}\n\n/** Solve a colour at this hue that clears `target` against `against`, keeping chroma. */\nfunction solveAgainst(hue: number, chroma: number, target: number, against: string, mode: ThemeMode): string {\n const bg = parseHex(against)!;\n const l = solveLightness(target, bg, hue, chroma, mode === \"light\" ? \"darker\" : \"lighter\");\n return oklchToHex({ l, c: chroma, h: hue });\n}\n\n/** Whichever of near-white / near-black reads better ON `fill`. */\nfunction contrastOn(fill: string): string {\n const light = \"#ffffff\";\n const dark = \"#12100e\";\n return contrast(fill, light) >= contrast(fill, dark) ? light : dark;\n}\n\n/** A soft tint of `hue` sitting on the surface — a badge fill, not a button fill. */\nfunction tintOn(hue: number, chroma: number, surface: string, mode: ThemeMode): string {\n const s = hexToOklch(surface)!;\n // Toward the colour, but only far enough to be seen: these back TEXT of the same hue,\n // and a strong tint leaves the text nowhere to go.\n const l = mode === \"light\" ? s.l - 0.055 : s.l + 0.055;\n return oklchToHex({ l, c: Math.min(chroma * 0.45, 0.06), h: hue });\n}\n\nexport function derivePalette({\n anchors,\n mode,\n surfaceTint = 0.55,\n textContrast,\n}: DeriveOptions): DerivedPalette {\n const warnings: string[] = [];\n const brand = hexToOklch(anchors.brand);\n if (!brand) {\n throw new Error(\n `derivePalette: brand \"${anchors.brand}\" is not a #rgb or #rrggbb colour. ` +\n `Anchors must be hex — a named colour or an rgba() string cannot be converted.`,\n );\n }\n\n const targets = { primary: 10, secondary: 7, muted: 4.6, ...textContrast };\n\n // ── Surfaces, from the brand's hue.\n const weight = hueWeight(brand);\n const surfaces = surfaceSet(brand.h, mode, surfaceTint, weight);\n // Every text role is solved against the WORST of the three, so a token is legible\n // wherever it lands. Solving against `bgSurface` alone is the mistake that makes a\n // muted label fail on the page background it also sits on.\n const worstSurface = [surfaces.bgPage, surfaces.bgSurface, surfaces.bgSurface2].reduce((a, b) =>\n contrast(a, mode === \"light\" ? \"#000000\" : \"#ffffff\") <\n contrast(b, mode === \"light\" ? \"#000000\" : \"#ffffff\")\n ? a\n : b,\n );\n\n // ── Text. A trace of the brand hue keeps the greys from reading cold on a warm page.\n const textChroma = 0.014 * weight;\n const textPrimary = solveAgainst(brand.h, textChroma, targets.primary, worstSurface, mode);\n const textSecondary = solveAgainst(brand.h, textChroma, targets.secondary, worstSurface, mode);\n const textMuted = solveAgainst(brand.h, textChroma, targets.muted, worstSurface, mode);\n\n // The darkest fill text sits on (the lightest, in dark): the worst surface, or a\n // hovered row on the card (`--bg-hover`), which in light is a shade darker than the\n // page. The colours that are solved exactly to 4.5:1 — money, the semantic text — are\n // solved against this, so they hold on a hovered row too (0.33, §12.10). The text\n // roles above keep their margin (4.6:1 and up) and need no second solve.\n const hover = hoverFill({ textPrimary, bgSurface: surfaces.bgSurface });\n const worstText = [worstSurface, hover].reduce((a, b) =>\n contrast(a, mode === \"light\" ? \"#000000\" : \"#ffffff\") <\n contrast(b, mode === \"light\" ? \"#000000\" : \"#ffffff\")\n ? a\n : b,\n );\n\n // ── Brand. Keep the hue the caller asked for; move only the lightness, and only as\n // far as 3:1 against the worst surface — WCAG 1.4.11, since a brand-filled control is\n // a graphical object whose boundary has to be perceivable.\n const brandChroma = Math.max(brand.c, 0.06);\n const brandRatio = contrast(anchors.brand, worstSurface);\n // NORMALISED, never the caller's raw string. `parseHex` accepts \"4f46e5\" and \"#abc\",\n // and passing either through unchanged put a value in the TokenSet that is not a CSS\n // colour — it then fails silently at paint time, three layers from here.\n let brandHex =\n brandRatio >= 3\n ? toHex(parseHex(anchors.brand)!)\n : solveAgainst(brand.h, brandChroma, 3, worstSurface, mode);\n if (brandRatio < 3) {\n warnings.push(\n `brand ${anchors.brand} sits at ${brandRatio.toFixed(2)}:1 against the ${mode} surfaces, ` +\n `below the 3:1 WCAG 1.4.11 asks of a control boundary. Lightness was adjusted to ` +\n `${brandHex}; hue and chroma are unchanged.`,\n );\n }\n // `--brand-muted` is the brand AS TEXT — a soft brand chip's label, an outline chip, a\n // current link — and tokens.css derives it: 62 % brand into the ink. A brand solved\n // to 3:1 left it at 4.43–4.51:1 in three dark presets (0.33, §5.5), so it gets the\n // text floor here: the brand moves away from the surfaces, a step at a time, until its\n // muted form clears 4.5:1 on the worst fill and on its own soft chip, at rest\n // (`--brand-bg`) and hovered (`--brand-bg-hover`, the harder of the two: §12.11).\n const brandMutedWorst = (hex: string) => {\n const soft = brandSoft({ brand: hex, textPrimary, bgSurface: surfaces.bgSurface });\n return Math.min(\n contrast(soft.brandMuted, worstText),\n contrast(soft.brandMuted, soft.brandBg),\n contrast(soft.brandMuted, soft.brandBgHover),\n );\n };\n for (let i = 0; i < 40 && brandMutedWorst(brandHex) < 4.5; i++) {\n const lch = hexToOklch(brandHex)!;\n brandHex = oklchToHex({ ...lch, l: mode === \"light\" ? lch.l - 0.005 : lch.l + 0.005 });\n }\n if (brandMutedWorst(brandHex) < 4.5) {\n warnings.push(\n `the brand as text (--brand-muted) reaches only ${brandMutedWorst(brandHex).toFixed(2)}:1 ` +\n `against the ${mode} surfaces (needs 4.5:1).`,\n );\n }\n const brandLch = hexToOklch(brandHex)!;\n const brandContrast = contrastOn(brandHex);\n const brandHover = oklchToHex({\n ...brandLch,\n // Hover moves AWAY from the colour of the text on it (0.33, §5.5): darker under\n // white, lighter under a dark ink. It used to move away from the page, which in dark\n // lightened a fill that carries WHITE text, toward its own label: 4.07:1.\n l: brandContrast === \"#ffffff\" ? brandLch.l - 0.06 : brandLch.l + 0.06,\n });\n const onBrand = contrast(brandHex, brandContrast);\n if (onBrand < 4.5) {\n warnings.push(\n `text on the brand fill reaches only ${onBrand.toFixed(2)}:1 (needs 4.5:1). ` +\n `A mid-lightness, high-chroma brand cannot carry legible text at any ink; ` +\n `use it as an accent and keep primary buttons on a darker or lighter variant.`,\n );\n }\n\n // ── Semantic roles. Anchors are honoured exactly; the rest are placed away from the\n // brand and from each other, within each role's licence to move.\n const taken: number[] = [brandLch.h];\n const accentLch = anchors.accent ? hexToOklch(anchors.accent) : null;\n if (anchors.accent && !accentLch) {\n warnings.push(`accent \"${anchors.accent}\" is not a hex colour and was ignored.`);\n }\n if (accentLch) taken.push(accentLch.h);\n\n const semanticHue = {} as Record<Exclude<AnchorRole, \"brand\" | \"accent\">, number>;\n const semanticChroma = {} as Record<Exclude<AnchorRole, \"brand\" | \"accent\">, number>;\n for (const role of [\"danger\", \"warning\", \"success\", \"info\"] as const) {\n const pinned = anchors[role] ? hexToOklch(anchors[role]!) : null;\n if (anchors[role] && !pinned) {\n warnings.push(`${role} \"${anchors[role]}\" is not a hex colour and was ignored.`);\n }\n const home = HUE_HOME[role];\n const hue = pinned ? pinned.h : placeHue(home.hue, home.slack, taken);\n if (!pinned) {\n const gap = Math.min(...taken.map((t) => hueGap(hue, t)));\n if (gap < 20) {\n warnings.push(\n `${role} could only reach ${gap.toFixed(0)}° from the nearest pinned hue, which is ` +\n `too close to tell apart at a glance. Pin ${role} explicitly, or move the brand.`,\n );\n }\n }\n semanticHue[role] = hue;\n semanticChroma[role] = pinned ? Math.max(pinned.c, 0.08) : 0.13;\n taken.push(hue);\n }\n\n /**\n * A semantic colour has two jobs and therefore two backgrounds: plain text on the\n * page, and the label inside its own tinted badge. The badge is the harder of the\n * two — it is a step toward the colour — so solving only against the surface produced\n * a badge at 4.1:1 while the loose text passed, which is the failure mode that is\n * hardest to notice because nine tenths of the uses look fine.\n */\n const sem = (role: Exclude<AnchorRole, \"brand\" | \"accent\">) => {\n const hue = semanticHue[role];\n const chroma = semanticChroma[role];\n const bg = tintOn(hue, chroma, surfaces.bgSurface, mode);\n const onSurface = solveLightness(\n 4.5,\n parseHex(worstText)!,\n hue,\n chroma,\n mode === \"light\" ? \"darker\" : \"lighter\",\n );\n const onTint = solveLightness(\n 4.5,\n parseHex(bg)!,\n hue,\n chroma,\n mode === \"light\" ? \"darker\" : \"lighter\",\n );\n const l = mode === \"light\" ? Math.min(onSurface, onTint) : Math.max(onSurface, onTint);\n return oklchToHex({ l, c: chroma, h: hue });\n };\n\n const danger = sem(\"danger\");\n const dangerLch = hexToOklch(danger)!;\n const semantic: SemanticTokens = {\n danger,\n dangerHover: oklchToHex({\n ...dangerLch,\n l: mode === \"light\" ? dangerLch.l - 0.06 : dangerLch.l + 0.06,\n }),\n dangerContrast: contrastOn(danger),\n // The tone border follows its siblings' lightness in dark mode (warning 0.44, info\n // and success 0.45) — a soft frame; the strong line keeps the old, louder recipe.\n dangerBorder: oklchToHex({\n l: mode === \"light\" ? dangerLch.l + 0.22 : 0.45,\n c: semanticChroma.danger,\n h: semanticHue.danger,\n }),\n dangerBorderStrong: oklchToHex({\n l: mode === \"light\" ? dangerLch.l + 0.22 : dangerLch.l - 0.22,\n c: semanticChroma.danger,\n h: semanticHue.danger,\n }),\n dangerBg: tintOn(semanticHue.danger, semanticChroma.danger, surfaces.bgSurface, mode),\n warning: sem(\"warning\"),\n warningBorder: oklchToHex({\n l: mode === \"light\" ? 0.82 : 0.44,\n c: semanticChroma.warning,\n h: semanticHue.warning,\n }),\n warningBg: tintOn(semanticHue.warning, semanticChroma.warning, surfaces.bgSurface, mode),\n info: sem(\"info\"),\n infoBorder: oklchToHex({\n l: mode === \"light\" ? 0.8 : 0.45,\n c: semanticChroma.info,\n h: semanticHue.info,\n }),\n infoBg: tintOn(semanticHue.info, semanticChroma.info, surfaces.bgSurface, mode),\n success: sem(\"success\"),\n successBorder: oklchToHex({\n l: mode === \"light\" ? 0.81 : 0.45,\n c: semanticChroma.success,\n h: semanticHue.success,\n }),\n successBg: tintOn(semanticHue.success, semanticChroma.success, surfaces.bgSurface, mode),\n };\n\n if (accentLch) {\n const accent = solveAgainst(accentLch.h, Math.max(accentLch.c, 0.06), 3, worstSurface, mode);\n semantic.accent = accent;\n semantic.accentContrast = contrastOn(accent);\n semantic.accentBg = tintOn(accentLch.h, Math.max(accentLch.c, 0.06), surfaces.bgSurface, mode);\n }\n\n // ── Money. A THIRD system again: these are data colours with fixed meanings, and the\n // one rule that outranks everything is that income and expense must never be the\n // red/green pair — which is why the shipped presets use teal/amber/violet. Derived\n // here at fixed hues rather than from the brand, for the same reason `--danger` is:\n // a consumer who rebrands does not thereby change what \"money out\" looks like.\n const money = (hue: number, target: number) => solveAgainst(hue, 0.12, target, worstText, mode);\n const moneyIncome = money(175, 4.5);\n const moneyExpense = money(70, 4.5);\n const moneyNet = money(300, 4.5);\n // \"No money has moved\": a quiet grey at a fixed lightness, but printed as TEXT (the\n // numpad's sign, a future row's figure), so it gets the text floor too (0.33). The\n // fixed lightness left it at 4.24:1 on four light pages.\n const neutralChroma = 0.012 * weight;\n const neutralFloor = solveLightness(4.5, parseHex(worstText)!, brand.h, neutralChroma, mode === \"light\" ? \"darker\" : \"lighter\");\n const moneyNeutral = oklchToHex({\n l: mode === \"light\" ? Math.min(0.52, neutralFloor) : Math.max(0.72, neutralFloor),\n c: neutralChroma,\n h: brand.h,\n });\n\n const tokens: TokenSet = {\n ...surfaces,\n textPrimary,\n textSecondary,\n textMuted,\n brand: brandHex,\n brandHover,\n brandContrast,\n moneyIncome,\n moneyExpense,\n moneyNet,\n moneyNeutral,\n // Left alone. See the note at the top of this file about why the categorical ramp is\n // not derived from the brand unless the caller asks.\n //\n // ⚠️ EMPTY, not absent: a caller who hands this straight to `applyTokenSet` keeps\n // whatever `--chart-1…9` were already on the element. That is deliberate — the ramp\n // is a separate decision and clearing it would leave charts unpainted — but it means\n // a derived palette applied over another preset is a MIX until you also supply a\n // ramp. `deriveChartRamp` is how you supply one.\n chart: [],\n heat: deriveHeat(moneyIncome, moneyExpense, surfaces, mode),\n };\n\n return { tokens, semantic, audit: auditPalette(tokens, semantic), warnings };\n}\n\n/**\n * Heatmap stops, reusing the money pair.\n *\n * `under` is the good direction and `over` the bad one, at the SAME hues as\n * `moneyIncome`/`moneyExpense` — so a heatmap cell and the figure printed beside it\n * agree about which way is which, rather than each inventing its own convention.\n */\nfunction deriveHeat(\n income: string,\n expense: string,\n surfaces: { bgSurface2: string },\n mode: ThemeMode,\n): HeatStops {\n const exp = hexToOklch(expense)!;\n return {\n neutral: surfaces.bgSurface2,\n under: income,\n over: expense,\n seqLow: oklchToHex({ l: mode === \"light\" ? 0.93 : 0.26, c: 0.05, h: exp.h }),\n seqHigh: expense,\n empty: mode === \"light\" ? \"rgba(120,110,95,0.14)\" : \"rgba(160,170,190,0.10)\",\n };\n}\n\n/* ── Audit ────────────────────────────────────────────────────────────────── */\n\n/**\n * Measure every pair that has a requirement, and say which ones fail.\n *\n * This is the part the shipped presets were missing. `derivePalette` runs it on the way\n * out, and the preset test runs it over everything the package ships, so a palette that\n * does not hold up cannot be merged with a comment claiming that it does.\n */\nexport function auditPalette(t: TokenSet, semantic?: SemanticTokens): ContrastReport {\n const checks: ContrastCheck[] = [];\n const surfaces: Array<[string, string]> = [\n [\"bgPage\", t.bgPage],\n [\"bgSurface\", t.bgSurface],\n [\"bgSurface2\", t.bgSurface2],\n ];\n // A hovered row on the card (`--bg-hover`) carries the same text as the card, and in\n // light it is the darkest fill that text sits on (0.33, §12.10). Text is measured on\n // it; the brand fill and the hairline, which are not text, are not.\n const hover = hoverFill(t);\n const textGrounds: Array<[string, string]> = [...surfaces, [\"bgHover\", hover]];\n // `--brand-muted`, `--brand-bg` and `--brand-bg-hover`, mixed as tokens.css mixes them.\n const { brandMuted, brandBg, brandBgHover } = brandSoft(t);\n\n // The 0.05 of slack is for a pair with a color-mix on one side, and only for that: the\n // browser mixes in float and paints the result, where this mixes and rounds to hex, so\n // the two can differ by a hair. Hex against hex is what the page paints, measured\n // exactly — the slack used to cover those too, and passed the Contrast preset's dark\n // brand fill at 2.998:1 (round 0.34 BUG-8).\n const MIXED = /\\b(bgHover|brandMuted|brandBg|brandBgHover)\\b/;\n const add = (pair: string, fg: string, bg: string, required: number, rule: string) => {\n const ratio = contrast(fg, bg);\n const slack = MIXED.test(pair) ? 0.05 : 0;\n checks.push({ pair, ratio, required, rule, passes: ratio >= required - slack });\n };\n\n for (const [name, bg] of surfaces) {\n add(`brand on ${name}`, t.brand, bg, 3, \"WCAG 1.4.11 graphical object\");\n add(`border on ${name}`, t.border, bg, 1.1, \"house rule: a hairline must be findable\");\n }\n for (const [name, bg] of textGrounds) {\n add(`textPrimary on ${name}`, t.textPrimary, bg, 7, \"WCAG 1.4.6 AAA body text\");\n add(`textSecondary on ${name}`, t.textSecondary, bg, 4.5, \"WCAG 1.4.3 AA body text\");\n add(`textMuted on ${name}`, t.textMuted, bg, 4.5, \"WCAG 1.4.3 AA body text\");\n add(`brandMuted on ${name}`, brandMuted, bg, 4.5, \"WCAG 1.4.3 — the brand as text\");\n for (const [key, hex] of [\n [\"moneyIncome\", t.moneyIncome],\n [\"moneyExpense\", t.moneyExpense],\n [\"moneyNet\", t.moneyNet],\n // Not a figure's colour but still printed as one (the numpad's sign, a future\n // row's amount) — measured since 0.33, when it was found at 4.24:1.\n [\"moneyNeutral\", t.moneyNeutral],\n ] as const) {\n add(`${key} on ${name}`, hex, bg, 4.5, \"WCAG 1.4.3 — these are rendered as TEXT\");\n }\n }\n\n add(\"brandContrast on brand\", t.brandContrast, t.brand, 4.5, \"WCAG 1.4.3 AA body text\");\n // A hovered brand button carries the same label (0.33): the derived dark presets\n // lightened the hover toward their white label and left it at 4.07:1.\n add(\"brandContrast on brandHover\", t.brandContrast, t.brandHover, 4.5, \"WCAG 1.4.3 AA body text\");\n add(\"brandMuted on brandBg\", brandMuted, brandBg, 4.5, \"WCAG 1.4.3 — a soft brand chip's label\");\n // The same label on the chip hovered (§12.11): a current link, a selected day. At 70 %\n // brand the muted text read 4.08–4.42:1 here (Default and Moss light; Ink, Moss, Plum\n // and Contrast dark).\n add(\"brandMuted on brandBgHover\", brandMuted, brandBgHover, 4.5, \"WCAG 1.4.3 — a hovered soft brand chip's label\");\n\n if (semantic) {\n for (const [name, fg] of [\n [\"danger\", semantic.danger],\n [\"warning\", semantic.warning],\n [\"info\", semantic.info],\n [\"success\", semantic.success],\n ] as const) {\n add(`${name} on bgSurface`, fg, t.bgSurface, 4.5, \"WCAG 1.4.3 — rendered as text\");\n add(`${name} on bgHover`, fg, hover, 4.5, \"WCAG 1.4.3 — rendered as text, on a hovered row\");\n }\n add(\"danger on dangerBg\", semantic.danger, semantic.dangerBg, 4.5, \"WCAG 1.4.3 — badge text\");\n add(\"warning on warningBg\", semantic.warning, semantic.warningBg, 4.5, \"WCAG 1.4.3 — badge text\");\n add(\"info on infoBg\", semantic.info, semantic.infoBg, 4.5, \"WCAG 1.4.3 — badge text\");\n add(\"success on successBg\", semantic.success, semantic.successBg, 4.5, \"WCAG 1.4.3 — badge text\");\n add(\n \"dangerContrast on danger\",\n semantic.dangerContrast,\n semantic.danger,\n 4.5,\n \"WCAG 1.4.3 AA body text\",\n );\n }\n\n const failures = checks.filter((c) => !c.passes);\n return { checks, failures, passes: failures.length === 0 };\n}\n\n/* ── Categorical chart ramp ───────────────────────────────────────────────── */\n\nexport interface ChartRampReport {\n colors: string[];\n /** Series pairs that are too close under normal vision or any simulated CVD. */\n collisions: Array<{ a: number; b: number; under: \"normal\" | CvdType; distance: number }>;\n /** Series that do not clear 3:1 against a surface they may be drawn on. */\n lowContrast: Array<{ index: number; surface: string; ratio: number }>;\n /** The worst pairwise separation, across normal vision and all three dichromacies. */\n minSeparation: number;\n /** The worst contrast any series reaches against any surface it was measured on. */\n minContrast: number;\n passes: boolean;\n}\n\n/**\n * The floor for pairwise separation in OKLab, across normal vision and each dichromacy.\n *\n * CALIBRATED, not chosen. Paul Tol's \"Muted\" set — which this package ships and which is\n * a well-regarded CVD-safe palette — bottoms out at 0.059 in its light variant and 0.032\n * in the lightened dark one. A threshold above 0.059 would fail a palette that is known\n * to work, which is worse than having no check at all: an audit that cries wolf gets\n * switched off. 0.05 sits just under the known-good case.\n */\nconst MIN_SEPARATION = 0.05;\n\n/**\n * **The categorical trade-off, measured.** At a SINGLE lightness, the most series that\n * can satisfy both the 3:1 fill contrast of WCAG 1.4.11 and {@link MIN_SEPARATION} under\n * dichromacy is FOUR. Searched exhaustively over starting hue and lightness:\n *\n * n=4 best separation 0.065 — both satisfiable\n * n=5 best separation 0.041 — not satisfiable\n * n=9 best separation 0.015 — not satisfiable\n *\n * The reason is structural: dichromacy collapses the red-green axis, so hue alone stops\n * distinguishing colours once you need more than a handful, and the remaining channel is\n * LIGHTNESS — the very thing a uniform-contrast ramp holds constant. Paul Tol's set\n * varies lightness deliberately and pays for it in contrast; that is not an oversight in\n * their palette, it is the only currency left.\n *\n * So above four series this deriver varies lightness too, and reports what it gave up\n * rather than pretending both constraints were met.\n *\n * NOTE ON WHAT THIS BOUND IS. It describes the PROBLEM, not a guarantee about\n * {@link deriveChartRamp}. That function fixes lightness and starts the hue wheel at the\n * brand's own hue rather than searching for the best start, so it reaches the bound only\n * where the brand happens to sit well: sweeping 72 brand hues against the default light\n * surfaces, 7 of 72 produced a passing 4-series ramp (12 of 72 on dark), and none passed\n * at 5 or 9. Read the report it returns; do not assume a pass.\n */\nconst SINGLE_LIGHTNESS_MAX_SERIES = 4;\n\n/**\n * A categorical ramp of `count` hues, evenly spaced and equal in perceived lightness,\n * then MEASURED for separability — including under each dichromacy.\n *\n * Offered but not used by default, and the distinction matters. Evenly spaced hues at\n * one lightness are a reasonable generic answer; Paul Tol's \"Muted\" set, which this\n * package ships, is a better specific one, because it was optimised against real\n * confusion lines rather than derived from a formula. So this exists for a consumer who\n * wants their charts to follow their brand and is willing to read the report — not as\n * a silent upgrade to the default.\n */\nexport function deriveChartRamp(\n brandHex: string,\n mode: ThemeMode,\n surfaces: string[],\n count = 9,\n): ChartRampReport {\n const brand = hexToOklch(brandHex) ?? { l: 0.6, c: 0.12, h: 264 };\n const base = mode === \"light\" ? 0.58 : 0.74;\n const c = Math.max(0.09, Math.min(brand.c, 0.15));\n // Up to four series, one lightness: a scale that varies lightness implies rank, and a\n // categorical one must not. Beyond four, lightness is the only channel left that\n // survives dichromacy — see SINGLE_LIGHTNESS_MAX_SERIES — so it alternates in a\n // three-step cycle, which keeps ADJACENT series (the ones a legend puts side by side)\n // at different lightnesses as well as different hues.\n const vary = count > SINGLE_LIGHTNESS_MAX_SERIES;\n const offsets = [0, mode === \"light\" ? -0.1 : 0.1, mode === \"light\" ? 0.08 : -0.08];\n const colors = Array.from({ length: count }, (_, i) =>\n oklchToHex({\n l: vary ? base + offsets[i % offsets.length] : base,\n c,\n h: (brand.h + (360 / count) * i) % 360,\n }),\n );\n\n return measureRamp(colors, surfaces);\n}\n\n/** Audit a ramp somebody else chose — the shipped Paul Tol set, say. */\nexport function auditChartRamp(colors: string[], surfaces: string[]): ChartRampReport {\n return measureRamp(colors, surfaces);\n}\n\nfunction measureRamp(colors: string[], surfaces: string[]): ChartRampReport {\n const collisions: ChartRampReport[\"collisions\"] = [];\n const rgbs = colors.map((hex) => parseHex(hex)).filter((v): v is NonNullable<typeof v> => !!v);\n let minSeparation = Infinity;\n for (let i = 0; i < rgbs.length; i++) {\n for (let j = i + 1; j < rgbs.length; j++) {\n const normal = deltaE(rgbs[i], rgbs[j]);\n minSeparation = Math.min(minSeparation, normal);\n if (normal < MIN_SEPARATION) {\n collisions.push({ a: i, b: j, under: \"normal\", distance: normal });\n }\n for (const type of [\"protanopia\", \"deuteranopia\", \"tritanopia\"] as const) {\n const d = deltaE(simulateCvd(rgbs[i], type), simulateCvd(rgbs[j], type));\n minSeparation = Math.min(minSeparation, d);\n if (d < MIN_SEPARATION) collisions.push({ a: i, b: j, under: type, distance: d });\n }\n }\n }\n\n const lowContrast: ChartRampReport[\"lowContrast\"] = [];\n let minContrast = Infinity;\n colors.forEach((hex, index) => {\n for (const surface of surfaces) {\n const ratio = contrast(hex, surface);\n minContrast = Math.min(minContrast, ratio);\n // WCAG 1.4.11: a graphical object carrying meaning needs 3:1 against what is\n // adjacent to it. A bar the same value as the card behind it has no boundary.\n if (ratio < 3) lowContrast.push({ index, surface, ratio });\n }\n });\n\n return {\n colors,\n collisions,\n lowContrast,\n minSeparation: Number.isFinite(minSeparation) ? minSeparation : 0,\n minContrast: Number.isFinite(minContrast) ? minContrast : 0,\n passes: collisions.length === 0 && lowContrast.length === 0,\n };\n}\n\n/** Convenience: the OKLCH of a hex, for a caller inspecting an anchor. */\nexport function describe(hex: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,KAAK,IAAI,aAAa,KAAK;AAGzC,UAAI,QAAQ,EAAG,aAAY,KAAK,EAAE,OAAO,SAAS,MAAM,CAAC;AAAA,IAC3D;AAAA,EACF,CAAC;AAED,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,eAAe,OAAO,SAAS,aAAa,IAAI,gBAAgB;AAAA,IAChE,aAAa,OAAO,SAAS,WAAW,IAAI,cAAc;AAAA,IAC1D,QAAQ,WAAW,WAAW,KAAK,YAAY,WAAW;AAAA,EAC5D;AACF;AAGO,SAAS,SAAS,KAA2B;AAClD,QAAM,MAAM,SAAS,GAAG;AACxB,SAAO,MAAM,WAAW,GAAG,IAAI;AACjC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/theme/palette-derive.ts"],"sourcesContent":["import type { ThemeMode } from \"./theme-store\";\nimport type { TokenSet } from \"./palette-presets\";\nimport type { HeatStops } from \"./chart-palette\";\nimport {\n contrast,\n deltaE,\n toHex,\n hexToOklch,\n oklchToHex,\n parseHex,\n rgbToOklch,\n simulateCvd,\n solveLightness,\n} from \"./color\";\nimport type { CvdType, Oklch } from \"./color\";\nimport type { ContrastLevel } from \"./contrast\";\nimport { brandSoft, contrastStep, hoverFill, steppedWellFill, WELL_STEP_MIN } from \"./contrast-tokens\";\n\n/**\n * Build a whole palette from one brand colour, plus any number of colours pinned by\n * hand, with every contrast ratio SOLVED rather than chosen and then hoped for.\n *\n * The presets this package shipped were assembled by eye and annotated with the ratios\n * they were believed to hold — `tokens.css` records \"7.0:1 and 4.8:1\", and\n * `palette-presets.ts` records \"2.67:1 … lifted they clear it at 3.30:1\". Nothing\n * computed any of them, and the audit found four of the nine default light chart hues\n * below the 3:1 that WCAG 1.4.11 requires of a graphical object. A comment is not a\n * test. Everything here is derived to a target and then measured, and\n * {@link auditPalette} returns the measurements so a caller can refuse a palette that\n * does not hold up.\n *\n * WHAT IS DERIVED AND WHAT IS NOT. The UI palette and the CATEGORICAL CHART RAMP solve\n * different problems and are deliberately kept apart. A UI colour needs contrast against\n * one known surface and carries a fixed meaning; a chart colour needs to stay separable\n * from eight unknown siblings, at roughly equal salience, with no implied order.\n * Optimising a set for one makes it worse at the other, which is why `deriveTokenSet`\n * leaves `chart` alone unless you explicitly ask for {@link deriveChartRamp}.\n */\n\n/* ── Inputs ───────────────────────────────────────────────────────────────── */\n\n/** A role whose hue may be pinned by the caller instead of chosen by the deriver. */\nexport type AnchorRole = \"brand\" | \"accent\" | \"danger\" | \"warning\" | \"success\" | \"info\";\n\nexport type PaletteAnchors = { brand: string } & Partial<Record<Exclude<AnchorRole, \"brand\">, string>>;\n\nexport interface DeriveOptions {\n anchors: PaletteAnchors;\n mode: ThemeMode;\n /**\n * How strongly the surfaces carry the brand's hue, 0–1 of the maximum useful tint.\n * 0 gives neutral greys; the shipped default is a visible warmth, because a page that\n * is very slightly the brand's hue reads as considered where a pure grey reads as\n * unstyled. Above ~0.5 the surfaces start competing with the content.\n */\n surfaceTint?: number;\n /** Contrast targets for the three text roles against the WORST surface. */\n textContrast?: { primary?: number; secondary?: number; muted?: number };\n}\n\n/* ── Outputs ──────────────────────────────────────────────────────────────── */\n\n/** The semantic layer, which lives in tokens.css rather than in `TokenSet`. */\nexport interface SemanticTokens {\n danger: string;\n dangerHover: string;\n dangerContrast: string;\n dangerBorder: string;\n /** The error line (invalid field, danger banner, destructive focus ring): as loud as\n * `dangerBorder` was before 0.15.5, so it keeps 3:1 against the surface. */\n dangerBorderStrong: string;\n dangerBg: string;\n warning: string;\n warningBorder: string;\n warningBg: string;\n info: string;\n infoBorder: string;\n infoBg: string;\n success: string;\n successBorder: string;\n successBg: string;\n /** Present only when a `accent` (secondary brand) anchor was supplied. */\n accent?: string;\n accentContrast?: string;\n accentBg?: string;\n}\n\nexport interface ContrastCheck {\n /** e.g. \"textMuted on bgPage\". */\n pair: string;\n ratio: number;\n /** What WCAG asks of this pair. */\n required: number;\n /** Which rule the requirement comes from, for a reader who wants to argue with it. */\n rule: string;\n passes: boolean;\n}\n\nexport interface ContrastReport {\n checks: ContrastCheck[];\n failures: ContrastCheck[];\n passes: boolean;\n}\n\nexport interface DerivedPalette {\n tokens: TokenSet;\n semantic: SemanticTokens;\n /** {@link auditPalette} at both contrast levels: the More-contrast checks carry a\n * \" (More contrast)\" suffix (0.36). */\n audit: ContrastReport;\n /** Compromises the deriver had to make, in plain words. Never silent. */\n warnings: string[];\n}\n\n/* ── The hue homes ────────────────────────────────────────────────────────── */\n\n/**\n * Where each semantic role wants to sit, and how far it may be pushed.\n *\n * A semantic colour is a convention before it is an aesthetic: danger is red because\n * every other interface the user has ever used made it red, and a \"danger\" button in\n * the brand's teal is a worse button however well it matches. So each role has a home\n * hue and a narrow licence to move — enough to get out of the brand's way when the\n * brand happens to live in the same neighbourhood, not enough to stop meaning what it\n * means. If it cannot get far enough, that is a warning, not a silent compromise.\n */\nconst HUE_HOME: Record<Exclude<AnchorRole, \"brand\" | \"accent\">, { hue: number; slack: number }> = {\n danger: { hue: 27, slack: 14 },\n warning: { hue: 75, slack: 16 },\n success: { hue: 150, slack: 20 },\n info: { hue: 240, slack: 22 },\n};\n\n/** Circular distance between two hue angles, 0–180. */\nfunction hueGap(a: number, b: number): number {\n const d = Math.abs(((a - b) % 360) + 360) % 360;\n return d > 180 ? 360 - d : d;\n}\n\n/**\n * Nudge `home` within `slack` to maximise the distance from every taken hue.\n *\n * Sampled rather than solved: the objective is a min-of-distances over a handful of\n * points on a short arc, which is piecewise-linear with kinks wherever the nearest\n * neighbour changes. Gradient methods stall on those kinks; 2° steps over a ±22° arc is\n * 23 evaluations of some trigonometry and cannot stall.\n */\nfunction placeHue(home: number, slack: number, taken: number[]): number {\n let best = home;\n let bestGap = Math.min(...taken.map((t) => hueGap(home, t)), 360);\n for (let d = -slack; d <= slack; d += 2) {\n const h = (home + d + 360) % 360;\n const gap = Math.min(...taken.map((t) => hueGap(h, t)), 360);\n // Ties go to the hue nearest home: a role should move only as far as it must.\n if (gap > bestGap + 1e-9) {\n best = h;\n bestGap = gap;\n }\n }\n return best;\n}\n\n/* ── Derivation ───────────────────────────────────────────────────────────── */\n\nconst SURFACE_L = {\n // Light: the PAGE is slightly darker than the cards on it, so a card reads as raised\n // without needing a shadow to say so. Matches the shipped presets' relationship.\n //\n // The light WELL is the page itself (0.33, docs/colour-roles-harmonization.md §5.3,\n // k26). Between the card and the page it sat 1.02–1.05:1 from the card it is inset\n // in, which is no well at all; at the page's lightness it stands out from the card\n // exactly as far as the card does from the page, and nothing re-solves, because the\n // page is already the surface every text role is solved against. Dark keeps its\n // well a step lighter than the card (1.11–1.13:1).\n light: { page: 0.912, surface: 0.945, surface2: 0.912 },\n dark: { page: 0.158, surface: 0.206, surface2: 0.249 },\n} as const;\n\n/**\n * What a hairline has to clear against the surface it divides.\n *\n * WCAG has nothing to say here — a decorative border is not a graphical object that\n * conveys information — so this is a house rule, and it is deliberately low. A border\n * that clears 3:1 is a RULE, not a hairline: it draws the eye to the box instead of to\n * what is in it. 1.5:1 is the point at which the edge is reliably findable without\n * becoming part of the composition.\n */\nconst BORDER_CONTRAST = 1.5;\n\n/** The most tint a surface can carry before it stops reading as a neutral ground. */\nconst MAX_SURFACE_CHROMA = 0.034;\n\n/**\n * The brand chroma from which the surfaces and the greys carry the brand's hue in full;\n * below it they carry it in proportion, down to none for a grey (round 0.34 BUG-8). A\n * grey has no hue — OKLCH reports 0, which is pink — and at full tint #808080 painted\n * every surface #eddde1.\n */\nconst FULL_HUE_CHROMA = 0.06;\n\n/** How much of the brand's hue the neutrals may carry: 0 for a grey, 1 from {@link FULL_HUE_CHROMA}. */\nfunction hueWeight(brand: Oklch): number {\n return Math.min(1, brand.c / FULL_HUE_CHROMA);\n}\n\nfunction surfaceSet(hue: number, mode: ThemeMode, tint: number, weight: number) {\n const c = MAX_SURFACE_CHROMA * Math.max(0, Math.min(1, tint)) * weight;\n const L = SURFACE_L[mode];\n const bgPage = oklchToHex({ l: L.page, c, h: hue });\n const bgSurface = oklchToHex({ l: L.surface, c, h: hue });\n const bgSurface2 = oklchToHex({ l: L.surface2, c, h: hue });\n // Solved, not guessed: a fixed lightness that looks right against a pale warm ground\n // disappears against a deep cold one, and both are reachable from the same `hue`\n // input. The border carries a little more chroma than the surfaces because at these\n // lightnesses a perfectly neutral hairline on a tinted ground reads as a wrong grey.\n const borderChroma = c * 1.6;\n // Solved against the surface the hairline is HARDEST to see on, not against one of\n // the three. Solving against `bgSurface` alone left it at 1.36:1 on `bgPage`, so the\n // target and the audit disagreed about the same border.\n const hardest = [bgPage, bgSurface, bgSurface2].reduce((a, b) =>\n contrast(a, mode === \"light\" ? \"#000000\" : \"#ffffff\") <\n contrast(b, mode === \"light\" ? \"#000000\" : \"#ffffff\")\n ? a\n : b,\n );\n const borderL = solveLightness(\n BORDER_CONTRAST,\n parseHex(hardest)!,\n hue,\n borderChroma,\n mode === \"light\" ? \"darker\" : \"lighter\",\n );\n return {\n bgPage,\n bgSurface,\n bgSurface2,\n border: oklchToHex({ l: borderL, c: borderChroma, h: hue }),\n };\n}\n\n/** Solve a colour at this hue that clears `target` against `against`, keeping chroma. */\nfunction solveAgainst(hue: number, chroma: number, target: number, against: string, mode: ThemeMode): string {\n const bg = parseHex(against)!;\n const l = solveLightness(target, bg, hue, chroma, mode === \"light\" ? \"darker\" : \"lighter\");\n return oklchToHex({ l, c: chroma, h: hue });\n}\n\n/** Whichever of near-white / near-black reads better ON `fill`. */\nfunction contrastOn(fill: string): string {\n const light = \"#ffffff\";\n const dark = \"#12100e\";\n return contrast(fill, light) >= contrast(fill, dark) ? light : dark;\n}\n\n/** A soft tint of `hue` sitting on the surface — a badge fill, not a button fill. */\nfunction tintOn(hue: number, chroma: number, surface: string, mode: ThemeMode): string {\n const s = hexToOklch(surface)!;\n // Toward the colour, but only far enough to be seen: these back TEXT of the same hue,\n // and a strong tint leaves the text nowhere to go.\n const l = mode === \"light\" ? s.l - 0.055 : s.l + 0.055;\n return oklchToHex({ l, c: Math.min(chroma * 0.45, 0.06), h: hue });\n}\n\nexport function derivePalette({\n anchors,\n mode,\n surfaceTint = 0.55,\n textContrast,\n}: DeriveOptions): DerivedPalette {\n const warnings: string[] = [];\n const brand = hexToOklch(anchors.brand);\n if (!brand) {\n throw new Error(\n `derivePalette: brand \"${anchors.brand}\" is not a #rgb or #rrggbb colour. ` +\n `Anchors must be hex — a named colour or an rgba() string cannot be converted.`,\n );\n }\n\n const targets = { primary: 10, secondary: 7, muted: 4.6, ...textContrast };\n\n // ── Surfaces, from the brand's hue.\n const weight = hueWeight(brand);\n const surfaces = surfaceSet(brand.h, mode, surfaceTint, weight);\n // Every text role is solved against the WORST of the three, so a token is legible\n // wherever it lands. Solving against `bgSurface` alone is the mistake that makes a\n // muted label fail on the page background it also sits on.\n const worstSurface = [surfaces.bgPage, surfaces.bgSurface, surfaces.bgSurface2].reduce((a, b) =>\n contrast(a, mode === \"light\" ? \"#000000\" : \"#ffffff\") <\n contrast(b, mode === \"light\" ? \"#000000\" : \"#ffffff\")\n ? a\n : b,\n );\n\n // ── Text. A trace of the brand hue keeps the greys from reading cold on a warm page.\n const textChroma = 0.014 * weight;\n const textPrimary = solveAgainst(brand.h, textChroma, targets.primary, worstSurface, mode);\n const textSecondary = solveAgainst(brand.h, textChroma, targets.secondary, worstSurface, mode);\n const textMuted = solveAgainst(brand.h, textChroma, targets.muted, worstSurface, mode);\n\n // The darkest fill text sits on (the lightest, in dark): the worst surface, or a\n // hovered row on the card (`--bg-hover`), which in light is a shade darker than the\n // page. The colours that are solved exactly to 4.5:1 — money, the semantic text — are\n // solved against this, so they hold on a hovered row too (0.33, §12.10). The text\n // roles above keep their margin (4.6:1 and up) and need no second solve.\n const hover = hoverFill({ textPrimary, bgSurface: surfaces.bgSurface });\n const worstText = [worstSurface, hover].reduce((a, b) =>\n contrast(a, mode === \"light\" ? \"#000000\" : \"#ffffff\") <\n contrast(b, mode === \"light\" ? \"#000000\" : \"#ffffff\")\n ? a\n : b,\n );\n\n // ── Brand. Keep the hue the caller asked for; move only the lightness, and only as\n // far as 3:1 against the worst surface — WCAG 1.4.11, since a brand-filled control is\n // a graphical object whose boundary has to be perceivable.\n //\n // In light the worst surface includes More contrast's well (0.36, colour-roles §13.4):\n // 10 % ink into the card, darker than the page. The step is applied, not derived, but\n // the brand is not stepped, so both brand solves measure there too and a derived\n // palette holds at both levels.\n const moreWell = steppedWellFill({ textPrimary, bgSurface: surfaces.bgSurface });\n const brandGround = moreWell\n ? [worstSurface, moreWell].reduce((a, b) => (contrast(a, \"#000000\") < contrast(b, \"#000000\") ? a : b))\n : worstSurface;\n const brandChroma = Math.max(brand.c, 0.06);\n const brandRatio = contrast(anchors.brand, brandGround);\n // NORMALISED, never the caller's raw string. `parseHex` accepts \"4f46e5\" and \"#abc\",\n // and passing either through unchanged put a value in the TokenSet that is not a CSS\n // colour — it then fails silently at paint time, three layers from here.\n let brandHex =\n brandRatio >= 3\n ? toHex(parseHex(anchors.brand)!)\n : solveAgainst(brand.h, brandChroma, 3, brandGround, mode);\n if (brandRatio < 3) {\n warnings.push(\n `brand ${anchors.brand} sits at ${brandRatio.toFixed(2)}:1 against the ${mode} surfaces, ` +\n `below the 3:1 WCAG 1.4.11 asks of a control boundary. Lightness was adjusted to ` +\n `${brandHex}; hue and chroma are unchanged.`,\n );\n }\n // `--brand-muted` is the brand AS TEXT — a soft brand chip's label, an outline chip, a\n // current link — and tokens.css derives it: 62 % brand into the ink. A brand solved\n // to 3:1 left it at 4.43–4.51:1 in three dark presets (0.33, §5.5), so it gets the\n // text floor here: the brand moves away from the surfaces, a step at a time, until its\n // muted form clears 4.5:1 on the worst fill and on its own soft chip, at rest\n // (`--brand-bg`) and hovered (`--brand-bg-hover`, the harder of the two: §12.11).\n const brandMutedWorst = (hex: string) => {\n const soft = brandSoft({ brand: hex, textPrimary, bgSurface: surfaces.bgSurface });\n return Math.min(\n contrast(soft.brandMuted, worstText),\n contrast(soft.brandMuted, soft.brandBg),\n contrast(soft.brandMuted, soft.brandBgHover),\n // …and on More contrast's light well, where a link button reads it (§13.3).\n moreWell ? contrast(soft.brandMuted, moreWell) : Infinity,\n );\n };\n for (let i = 0; i < 40 && brandMutedWorst(brandHex) < 4.5; i++) {\n const lch = hexToOklch(brandHex)!;\n brandHex = oklchToHex({ ...lch, l: mode === \"light\" ? lch.l - 0.005 : lch.l + 0.005 });\n }\n if (brandMutedWorst(brandHex) < 4.5) {\n warnings.push(\n `the brand as text (--brand-muted) reaches only ${brandMutedWorst(brandHex).toFixed(2)}:1 ` +\n `against the ${mode} surfaces (needs 4.5:1).`,\n );\n }\n const brandLch = hexToOklch(brandHex)!;\n const brandContrast = contrastOn(brandHex);\n const brandHover = oklchToHex({\n ...brandLch,\n // Hover moves AWAY from the colour of the text on it (0.33, §5.5): darker under\n // white, lighter under a dark ink. It used to move away from the page, which in dark\n // lightened a fill that carries WHITE text, toward its own label: 4.07:1.\n l: brandContrast === \"#ffffff\" ? brandLch.l - 0.06 : brandLch.l + 0.06,\n });\n const onBrand = contrast(brandHex, brandContrast);\n if (onBrand < 4.5) {\n warnings.push(\n `text on the brand fill reaches only ${onBrand.toFixed(2)}:1 (needs 4.5:1). ` +\n `A mid-lightness, high-chroma brand cannot carry legible text at any ink; ` +\n `use it as an accent and keep primary buttons on a darker or lighter variant.`,\n );\n }\n\n // ── Semantic roles. Anchors are honoured exactly; the rest are placed away from the\n // brand and from each other, within each role's licence to move.\n const taken: number[] = [brandLch.h];\n const accentLch = anchors.accent ? hexToOklch(anchors.accent) : null;\n if (anchors.accent && !accentLch) {\n warnings.push(`accent \"${anchors.accent}\" is not a hex colour and was ignored.`);\n }\n if (accentLch) taken.push(accentLch.h);\n\n const semanticHue = {} as Record<Exclude<AnchorRole, \"brand\" | \"accent\">, number>;\n const semanticChroma = {} as Record<Exclude<AnchorRole, \"brand\" | \"accent\">, number>;\n for (const role of [\"danger\", \"warning\", \"success\", \"info\"] as const) {\n const pinned = anchors[role] ? hexToOklch(anchors[role]!) : null;\n if (anchors[role] && !pinned) {\n warnings.push(`${role} \"${anchors[role]}\" is not a hex colour and was ignored.`);\n }\n const home = HUE_HOME[role];\n const hue = pinned ? pinned.h : placeHue(home.hue, home.slack, taken);\n if (!pinned) {\n const gap = Math.min(...taken.map((t) => hueGap(hue, t)));\n if (gap < 20) {\n warnings.push(\n `${role} could only reach ${gap.toFixed(0)}° from the nearest pinned hue, which is ` +\n `too close to tell apart at a glance. Pin ${role} explicitly, or move the brand.`,\n );\n }\n }\n semanticHue[role] = hue;\n semanticChroma[role] = pinned ? Math.max(pinned.c, 0.08) : 0.13;\n taken.push(hue);\n }\n\n /**\n * A semantic colour has two jobs and therefore two backgrounds: plain text on the\n * page, and the label inside its own tinted badge. The badge is the harder of the\n * two — it is a step toward the colour — so solving only against the surface produced\n * a badge at 4.1:1 while the loose text passed, which is the failure mode that is\n * hardest to notice because nine tenths of the uses look fine.\n */\n const sem = (role: Exclude<AnchorRole, \"brand\" | \"accent\">) => {\n const hue = semanticHue[role];\n const chroma = semanticChroma[role];\n const bg = tintOn(hue, chroma, surfaces.bgSurface, mode);\n const onSurface = solveLightness(\n 4.5,\n parseHex(worstText)!,\n hue,\n chroma,\n mode === \"light\" ? \"darker\" : \"lighter\",\n );\n const onTint = solveLightness(\n 4.5,\n parseHex(bg)!,\n hue,\n chroma,\n mode === \"light\" ? \"darker\" : \"lighter\",\n );\n const l = mode === \"light\" ? Math.min(onSurface, onTint) : Math.max(onSurface, onTint);\n return oklchToHex({ l, c: chroma, h: hue });\n };\n\n const danger = sem(\"danger\");\n const dangerLch = hexToOklch(danger)!;\n const semantic: SemanticTokens = {\n danger,\n dangerHover: oklchToHex({\n ...dangerLch,\n l: mode === \"light\" ? dangerLch.l - 0.06 : dangerLch.l + 0.06,\n }),\n dangerContrast: contrastOn(danger),\n // The tone border follows its siblings' lightness in dark mode (warning 0.44, info\n // and success 0.45) — a soft frame; the strong line keeps the old, louder recipe.\n dangerBorder: oklchToHex({\n l: mode === \"light\" ? dangerLch.l + 0.22 : 0.45,\n c: semanticChroma.danger,\n h: semanticHue.danger,\n }),\n dangerBorderStrong: oklchToHex({\n l: mode === \"light\" ? dangerLch.l + 0.22 : dangerLch.l - 0.22,\n c: semanticChroma.danger,\n h: semanticHue.danger,\n }),\n dangerBg: tintOn(semanticHue.danger, semanticChroma.danger, surfaces.bgSurface, mode),\n warning: sem(\"warning\"),\n warningBorder: oklchToHex({\n l: mode === \"light\" ? 0.82 : 0.44,\n c: semanticChroma.warning,\n h: semanticHue.warning,\n }),\n warningBg: tintOn(semanticHue.warning, semanticChroma.warning, surfaces.bgSurface, mode),\n info: sem(\"info\"),\n infoBorder: oklchToHex({\n l: mode === \"light\" ? 0.8 : 0.45,\n c: semanticChroma.info,\n h: semanticHue.info,\n }),\n infoBg: tintOn(semanticHue.info, semanticChroma.info, surfaces.bgSurface, mode),\n success: sem(\"success\"),\n successBorder: oklchToHex({\n l: mode === \"light\" ? 0.81 : 0.45,\n c: semanticChroma.success,\n h: semanticHue.success,\n }),\n successBg: tintOn(semanticHue.success, semanticChroma.success, surfaces.bgSurface, mode),\n };\n\n if (accentLch) {\n const accent = solveAgainst(accentLch.h, Math.max(accentLch.c, 0.06), 3, worstSurface, mode);\n semantic.accent = accent;\n semantic.accentContrast = contrastOn(accent);\n semantic.accentBg = tintOn(accentLch.h, Math.max(accentLch.c, 0.06), surfaces.bgSurface, mode);\n }\n\n // ── Money. A THIRD system again: these are data colours with fixed meanings, and the\n // one rule that outranks everything is that income and expense must never be the\n // red/green pair — which is why the shipped presets use teal/amber/violet. Derived\n // here at fixed hues rather than from the brand, for the same reason `--danger` is:\n // a consumer who rebrands does not thereby change what \"money out\" looks like.\n const money = (hue: number, target: number) => solveAgainst(hue, 0.12, target, worstText, mode);\n const moneyIncome = money(175, 4.5);\n const moneyExpense = money(70, 4.5);\n const moneyNet = money(300, 4.5);\n // \"No money has moved\": a quiet grey at a fixed lightness, but printed as TEXT (the\n // numpad's sign, a future row's figure), so it gets the text floor too (0.33). The\n // fixed lightness left it at 4.24:1 on four light pages.\n const neutralChroma = 0.012 * weight;\n const neutralFloor = solveLightness(4.5, parseHex(worstText)!, brand.h, neutralChroma, mode === \"light\" ? \"darker\" : \"lighter\");\n const moneyNeutral = oklchToHex({\n l: mode === \"light\" ? Math.min(0.52, neutralFloor) : Math.max(0.72, neutralFloor),\n c: neutralChroma,\n h: brand.h,\n });\n\n const tokens: TokenSet = {\n ...surfaces,\n textPrimary,\n textSecondary,\n textMuted,\n brand: brandHex,\n brandHover,\n brandContrast,\n moneyIncome,\n moneyExpense,\n moneyNet,\n moneyNeutral,\n // Left alone. See the note at the top of this file about why the categorical ramp is\n // not derived from the brand unless the caller asks.\n //\n // ⚠️ EMPTY, not absent: a caller who hands this straight to `applyTokenSet` keeps\n // whatever `--chart-1…9` were already on the element. That is deliberate — the ramp\n // is a separate decision and clearing it would leave charts unpainted — but it means\n // a derived palette applied over another preset is a MIX until you also supply a\n // ramp. `deriveChartRamp` is how you supply one.\n chart: [],\n heat: deriveHeat(moneyIncome, moneyExpense, surfaces, mode),\n };\n\n // Audited at both contrast levels (0.36, colour-roles §13.5): More contrast steps the\n // text, the border and, in light, the well and money of this set. The derived semantic\n // colours are audited at Standard only: they are solved for the standard grounds, and\n // only tokens.css's shipped literals step for the darker well.\n const standard = auditPalette(tokens, semantic);\n const more = auditPalette(tokens, undefined, { level: \"more\" });\n const checks = [...standard.checks, ...more.checks];\n const failures = checks.filter((c) => !c.passes);\n return { tokens, semantic, audit: { checks, failures, passes: failures.length === 0 }, warnings };\n}\n\n/**\n * Heatmap stops, reusing the money pair.\n *\n * `under` is the good direction and `over` the bad one, at the SAME hues as\n * `moneyIncome`/`moneyExpense` — so a heatmap cell and the figure printed beside it\n * agree about which way is which, rather than each inventing its own convention.\n */\nfunction deriveHeat(\n income: string,\n expense: string,\n surfaces: { bgSurface2: string },\n mode: ThemeMode,\n): HeatStops {\n const exp = hexToOklch(expense)!;\n return {\n neutral: surfaces.bgSurface2,\n under: income,\n over: expense,\n seqLow: oklchToHex({ l: mode === \"light\" ? 0.93 : 0.26, c: 0.05, h: exp.h }),\n seqHigh: expense,\n empty: mode === \"light\" ? \"rgba(120,110,95,0.14)\" : \"rgba(160,170,190,0.10)\",\n };\n}\n\n/* ── Audit ────────────────────────────────────────────────────────────────── */\n\n/**\n * Measure every pair that has a requirement, and say which ones fail.\n *\n * This is the part the shipped presets were missing. `derivePalette` runs it on the way\n * out, and the preset test runs it over everything the package ships, so a palette that\n * does not hold up cannot be merged with a comment claiming that it does.\n *\n * **`level: \"more\"`** (0.36, docs/colour-roles-harmonization.md §13.5) measures the set as\n * More contrast paints it: the stepped secondary, muted and border, and in a light set the\n * stepped well (as `bgSurface2`) and money — the same pairs, named with a \" (More\n * contrast)\" suffix. Two things change with the level: the border is a field's boundary\n * there, held to WCAG 1.4.11's 3:1 rather than the hairline's 1.1, and a light set's well\n * must stand {@link WELL_STEP_MIN}:1 from the card. Pass `semantic` with tokens.css's More\n * literals for a light set (the status colours step there); the status text is then\n * measured on the stepped well too.\n */\nexport function auditPalette(\n set: TokenSet,\n semantic?: SemanticTokens,\n options: { level?: ContrastLevel } = {},\n): ContrastReport {\n const more = options.level === \"more\";\n const step = more ? contrastStep(set) : null;\n // The set as it paints at this level: what `applyTokenSet` writes for it.\n const t: TokenSet = step\n ? {\n ...set,\n textSecondary: step.textSecondary,\n textMuted: step.textMuted,\n border: step.border,\n ...(step.well && {\n bgSurface2: step.well.bgSurface2,\n moneyIncome: step.well.moneyIncome,\n moneyExpense: step.well.moneyExpense,\n moneyNet: step.well.moneyNet,\n moneyNeutral: step.well.moneyNeutral,\n }),\n }\n : set;\n const suffix = more ? \" (More contrast)\" : \"\";\n const checks: ContrastCheck[] = [];\n const surfaces: Array<[string, string]> = [\n [\"bgPage\", t.bgPage],\n [\"bgSurface\", t.bgSurface],\n [\"bgSurface2\", t.bgSurface2],\n ];\n // A hovered row on the card (`--bg-hover`) carries the same text as the card, and in\n // light it is the darkest fill that text sits on (0.33, §12.10). Text is measured on\n // it; the brand fill and the hairline, which are not text, are not.\n const hover = hoverFill(t);\n const textGrounds: Array<[string, string]> = [...surfaces, [\"bgHover\", hover]];\n // `--brand-muted`, `--brand-bg` and `--brand-bg-hover`, mixed as tokens.css mixes them.\n const { brandMuted, brandBg, brandBgHover } = brandSoft(t);\n\n // The 0.05 of slack is for a pair with a color-mix on one side, and only for that: the\n // browser mixes in float and paints the result, where this mixes and rounds to hex, so\n // the two can differ by a hair. Hex against hex is what the page paints, measured\n // exactly — the slack used to cover those too, and passed the Contrast preset's dark\n // brand fill at 2.998:1 (round 0.34 BUG-8).\n const MIXED = /\\b(bgHover|brandMuted|brandBg|brandBgHover)\\b/;\n const add = (pair: string, fg: string, bg: string, required: number, rule: string) => {\n const ratio = contrast(fg, bg);\n const slack = MIXED.test(pair) ? 0.05 : 0;\n checks.push({ pair: pair + suffix, ratio, required, rule, passes: ratio >= required - slack });\n };\n\n for (const [name, bg] of surfaces) {\n add(`brand on ${name}`, t.brand, bg, 3, \"WCAG 1.4.11 graphical object\");\n if (more) add(`border on ${name}`, t.border, bg, 3, \"WCAG 1.4.11 — under More contrast a border bounds a field\");\n else add(`border on ${name}`, t.border, bg, 1.1, \"house rule: a hairline must be findable\");\n }\n // The stepped light well, a hex `applyTokenSet` writes (§13.3, decision 2).\n if (step?.well) {\n add(\"bgSurface2 on bgSurface\", t.bgSurface2, t.bgSurface, WELL_STEP_MIN, \"house rule: the well stands two hover steps from the card\");\n }\n for (const [name, bg] of textGrounds) {\n add(`textPrimary on ${name}`, t.textPrimary, bg, 7, \"WCAG 1.4.6 AAA body text\");\n add(`textSecondary on ${name}`, t.textSecondary, bg, 4.5, \"WCAG 1.4.3 AA body text\");\n add(`textMuted on ${name}`, t.textMuted, bg, 4.5, \"WCAG 1.4.3 AA body text\");\n add(`brandMuted on ${name}`, brandMuted, bg, 4.5, \"WCAG 1.4.3 — the brand as text\");\n for (const [key, hex] of [\n [\"moneyIncome\", t.moneyIncome],\n [\"moneyExpense\", t.moneyExpense],\n [\"moneyNet\", t.moneyNet],\n // Not a figure's colour but still printed as one (the numpad's sign, a future\n // row's amount) — measured since 0.33, when it was found at 4.24:1.\n [\"moneyNeutral\", t.moneyNeutral],\n ] as const) {\n add(`${key} on ${name}`, hex, bg, 4.5, \"WCAG 1.4.3 — these are rendered as TEXT\");\n }\n }\n\n add(\"brandContrast on brand\", t.brandContrast, t.brand, 4.5, \"WCAG 1.4.3 AA body text\");\n // A hovered brand button carries the same label (0.33): the derived dark presets\n // lightened the hover toward their white label and left it at 4.07:1.\n add(\"brandContrast on brandHover\", t.brandContrast, t.brandHover, 4.5, \"WCAG 1.4.3 AA body text\");\n add(\"brandMuted on brandBg\", brandMuted, brandBg, 4.5, \"WCAG 1.4.3 — a soft brand chip's label\");\n // The same label on the chip hovered (§12.11): a current link, a selected day. At 70 %\n // brand the muted text read 4.08–4.42:1 here (Default and Moss light; Ink, Moss, Plum\n // and Contrast dark).\n add(\"brandMuted on brandBgHover\", brandMuted, brandBgHover, 4.5, \"WCAG 1.4.3 — a hovered soft brand chip's label\");\n\n if (semantic) {\n for (const [name, fg] of [\n [\"danger\", semantic.danger],\n [\"warning\", semantic.warning],\n [\"info\", semantic.info],\n [\"success\", semantic.success],\n ] as const) {\n add(`${name} on bgSurface`, fg, t.bgSurface, 4.5, \"WCAG 1.4.3 — rendered as text\");\n add(`${name} on bgHover`, fg, hover, 4.5, \"WCAG 1.4.3 — rendered as text, on a hovered row\");\n // The darker light well the More literals were solved for (§13.3).\n if (step?.well) add(`${name} on bgSurface2`, fg, t.bgSurface2, 4.5, \"WCAG 1.4.3 — rendered as text, on the well\");\n }\n add(\"danger on dangerBg\", semantic.danger, semantic.dangerBg, 4.5, \"WCAG 1.4.3 — badge text\");\n add(\"warning on warningBg\", semantic.warning, semantic.warningBg, 4.5, \"WCAG 1.4.3 — badge text\");\n add(\"info on infoBg\", semantic.info, semantic.infoBg, 4.5, \"WCAG 1.4.3 — badge text\");\n add(\"success on successBg\", semantic.success, semantic.successBg, 4.5, \"WCAG 1.4.3 — badge text\");\n add(\n \"dangerContrast on danger\",\n semantic.dangerContrast,\n semantic.danger,\n 4.5,\n \"WCAG 1.4.3 AA body text\",\n );\n }\n\n const failures = checks.filter((c) => !c.passes);\n return { checks, failures, passes: failures.length === 0 };\n}\n\n/* ── Categorical chart ramp ───────────────────────────────────────────────── */\n\nexport interface ChartRampReport {\n colors: string[];\n /** Series pairs that are too close under normal vision or any simulated CVD. */\n collisions: Array<{ a: number; b: number; under: \"normal\" | CvdType; distance: number }>;\n /** Series that do not clear 3:1 against a surface they may be drawn on. */\n lowContrast: Array<{ index: number; surface: string; ratio: number }>;\n /** The worst pairwise separation, across normal vision and all three dichromacies. */\n minSeparation: number;\n /** The worst contrast any series reaches against any surface it was measured on. */\n minContrast: number;\n passes: boolean;\n}\n\n/**\n * The floor for pairwise separation in OKLab, across normal vision and each dichromacy.\n *\n * CALIBRATED, not chosen. Paul Tol's \"Muted\" set — which this package ships and which is\n * a well-regarded CVD-safe palette — bottoms out at 0.059 in its light variant and 0.032\n * in the lightened dark one. A threshold above 0.059 would fail a palette that is known\n * to work, which is worse than having no check at all: an audit that cries wolf gets\n * switched off. 0.05 sits just under the known-good case.\n */\nconst MIN_SEPARATION = 0.05;\n\n/**\n * **The categorical trade-off, measured.** At a SINGLE lightness, the most series that\n * can satisfy both the 3:1 fill contrast of WCAG 1.4.11 and {@link MIN_SEPARATION} under\n * dichromacy is FOUR. Searched exhaustively over starting hue and lightness:\n *\n * n=4 best separation 0.065 — both satisfiable\n * n=5 best separation 0.041 — not satisfiable\n * n=9 best separation 0.015 — not satisfiable\n *\n * The reason is structural: dichromacy collapses the red-green axis, so hue alone stops\n * distinguishing colours once you need more than a handful, and the remaining channel is\n * LIGHTNESS — the very thing a uniform-contrast ramp holds constant. Paul Tol's set\n * varies lightness deliberately and pays for it in contrast; that is not an oversight in\n * their palette, it is the only currency left.\n *\n * So above four series this deriver varies lightness too, and reports what it gave up\n * rather than pretending both constraints were met.\n *\n * NOTE ON WHAT THIS BOUND IS. It describes the PROBLEM, not a guarantee about\n * {@link deriveChartRamp}. That function fixes lightness and starts the hue wheel at the\n * brand's own hue rather than searching for the best start, so it reaches the bound only\n * where the brand happens to sit well: sweeping 72 brand hues against the default light\n * surfaces, 7 of 72 produced a passing 4-series ramp (12 of 72 on dark), and none passed\n * at 5 or 9. Read the report it returns; do not assume a pass.\n */\nconst SINGLE_LIGHTNESS_MAX_SERIES = 4;\n\n/**\n * A categorical ramp of `count` hues, evenly spaced and equal in perceived lightness,\n * then MEASURED for separability — including under each dichromacy.\n *\n * Offered but not used by default, and the distinction matters. Evenly spaced hues at\n * one lightness are a reasonable generic answer; Paul Tol's \"Muted\" set, which this\n * package ships, is a better specific one, because it was optimised against real\n * confusion lines rather than derived from a formula. So this exists for a consumer who\n * wants their charts to follow their brand and is willing to read the report — not as\n * a silent upgrade to the default.\n */\nexport function deriveChartRamp(\n brandHex: string,\n mode: ThemeMode,\n surfaces: string[],\n count = 9,\n): ChartRampReport {\n const brand = hexToOklch(brandHex) ?? { l: 0.6, c: 0.12, h: 264 };\n const base = mode === \"light\" ? 0.58 : 0.74;\n const c = Math.max(0.09, Math.min(brand.c, 0.15));\n // Up to four series, one lightness: a scale that varies lightness implies rank, and a\n // categorical one must not. Beyond four, lightness is the only channel left that\n // survives dichromacy — see SINGLE_LIGHTNESS_MAX_SERIES — so it alternates in a\n // three-step cycle, which keeps ADJACENT series (the ones a legend puts side by side)\n // at different lightnesses as well as different hues.\n const vary = count > SINGLE_LIGHTNESS_MAX_SERIES;\n const offsets = [0, mode === \"light\" ? -0.1 : 0.1, mode === \"light\" ? 0.08 : -0.08];\n const colors = Array.from({ length: count }, (_, i) =>\n oklchToHex({\n l: vary ? base + offsets[i % offsets.length] : base,\n c,\n h: (brand.h + (360 / count) * i) % 360,\n }),\n );\n\n return measureRamp(colors, surfaces);\n}\n\n/** Audit a ramp somebody else chose — the shipped Paul Tol set, say. */\nexport function auditChartRamp(colors: string[], surfaces: string[]): ChartRampReport {\n return measureRamp(colors, surfaces);\n}\n\nfunction measureRamp(colors: string[], surfaces: string[]): ChartRampReport {\n const collisions: ChartRampReport[\"collisions\"] = [];\n const rgbs = colors.map((hex) => parseHex(hex)).filter((v): v is NonNullable<typeof v> => !!v);\n let minSeparation = Infinity;\n for (let i = 0; i < rgbs.length; i++) {\n for (let j = i + 1; j < rgbs.length; j++) {\n const normal = deltaE(rgbs[i], rgbs[j]);\n minSeparation = Math.min(minSeparation, normal);\n if (normal < MIN_SEPARATION) {\n collisions.push({ a: i, b: j, under: \"normal\", distance: normal });\n }\n for (const type of [\"protanopia\", \"deuteranopia\", \"tritanopia\"] as const) {\n const d = deltaE(simulateCvd(rgbs[i], type), simulateCvd(rgbs[j], type));\n minSeparation = Math.min(minSeparation, d);\n if (d < MIN_SEPARATION) collisions.push({ a: i, b: j, under: type, distance: d });\n }\n }\n }\n\n const lowContrast: ChartRampReport[\"lowContrast\"] = [];\n let minContrast = Infinity;\n colors.forEach((hex, index) => {\n for (const surface of surfaces) {\n const ratio = contrast(hex, surface);\n minContrast = Math.min(minContrast, ratio);\n // WCAG 1.4.11: a graphical object carrying meaning needs 3:1 against what is\n // adjacent to it. A bar the same value as the card behind it has no boundary.\n if (ratio < 3) lowContrast.push({ index, surface, ratio });\n }\n });\n\n return {\n colors,\n collisions,\n lowContrast,\n minSeparation: Number.isFinite(minSeparation) ? minSeparation : 0,\n minContrast: Number.isFinite(minContrast) ? minContrast : 0,\n passes: collisions.length === 0 && lowContrast.length === 0,\n };\n}\n\n/** Convenience: the OKLCH of a hex, for a caller inspecting an anchor. */\nexport function describe(hex: string): Oklch | null {\n const rgb = parseHex(hex);\n return rgb ? rgbToOklch(rgb) : null;\n}\n"],"mappings":";AAGA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,SAAS,WAAW,cAAc,WAAW,iBAAiB,qBAAqB;AA8GnF,MA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AAa,OAAO,SAAS,WAAW,IAAI,cAAc;AAAA,IAC1D,QAAQ,WAAW,WAAW,KAAK,YAAY,WAAW;AAAA,EAC5D;AACF;AAGO,SAAS,SAAS,KAA2B;AAClD,QAAM,MAAM,SAAS,GAAG;AACxB,SAAO,MAAM,WAAW,GAAG,IAAI;AACjC;","names":[]}
|
|
@@ -62,7 +62,8 @@ export declare function presetById(id: string): PalettePreset;
|
|
|
62
62
|
* element, which is what that list was standing in for.
|
|
63
63
|
*
|
|
64
64
|
* **More contrast (0.32, docs/text-size-harmonization.md §5, §10.5).** With `contrast`
|
|
65
|
-
* the text and border tokens are written one step stronger
|
|
65
|
+
* the text and border tokens are written one step stronger — in a light set the well and
|
|
66
|
+
* the four money colours too (0.36, docs/colour-roles-harmonization.md §13) — and `--text-placeholder` —
|
|
66
67
|
* otherwise derived in tokens.css — is written inline too; without it that inline
|
|
67
68
|
* placeholder is removed again, so the stylesheet's formula applies. The step is made
|
|
68
69
|
* HERE because these tokens are inline: no `[data-contrast=more]` rule could beat them.
|
|
@@ -339,7 +339,7 @@ function applyTokenSet(el, t, contrast = el.getAttribute("data-contrast") === "m
|
|
|
339
339
|
const step = contrast ? contrastStep(t) : null;
|
|
340
340
|
el.style.setProperty("--bg-page", t.bgPage);
|
|
341
341
|
el.style.setProperty("--bg-surface", t.bgSurface);
|
|
342
|
-
el.style.setProperty("--bg-surface-2", t.bgSurface2);
|
|
342
|
+
el.style.setProperty("--bg-surface-2", step?.well?.bgSurface2 ?? t.bgSurface2);
|
|
343
343
|
el.style.setProperty("--border", step?.border ?? t.border);
|
|
344
344
|
el.style.setProperty("--text-primary", t.textPrimary);
|
|
345
345
|
el.style.setProperty("--text-secondary", step?.textSecondary ?? t.textSecondary);
|
|
@@ -349,10 +349,10 @@ function applyTokenSet(el, t, contrast = el.getAttribute("data-contrast") === "m
|
|
|
349
349
|
el.style.setProperty("--brand", t.brand);
|
|
350
350
|
el.style.setProperty("--brand-hover", t.brandHover);
|
|
351
351
|
el.style.setProperty("--brand-contrast", t.brandContrast);
|
|
352
|
-
el.style.setProperty("--money-income", t.moneyIncome);
|
|
353
|
-
el.style.setProperty("--money-expense", t.moneyExpense);
|
|
354
|
-
el.style.setProperty("--money-net", t.moneyNet);
|
|
355
|
-
el.style.setProperty("--money-neutral", t.moneyNeutral);
|
|
352
|
+
el.style.setProperty("--money-income", step?.well?.moneyIncome ?? t.moneyIncome);
|
|
353
|
+
el.style.setProperty("--money-expense", step?.well?.moneyExpense ?? t.moneyExpense);
|
|
354
|
+
el.style.setProperty("--money-net", step?.well?.moneyNet ?? t.moneyNet);
|
|
355
|
+
el.style.setProperty("--money-neutral", step?.well?.moneyNeutral ?? t.moneyNeutral);
|
|
356
356
|
t.chart.forEach((c, i) => el.style.setProperty(`--chart-${i + 1}`, c));
|
|
357
357
|
}
|
|
358
358
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/theme/palette-presets.ts"],"sourcesContent":["// Appearance presets — the single source of truth for the \"palette switcher\"\n// (feedback #307). Each preset is a full set of design-token values for BOTH\n// light and dark, covering the page/surface backgrounds, the brand accent, the\n// semantic money trio and the 9-colour categorical chart palette, plus the\n// heatmap stops. A preset is applied at runtime by writing these as CSS custom\n// properties onto <html> (see palette-store.ts), which instantly re-skins every\n// token-driven surface and chart. The two heatmaps and the treemap interpolate\n// concrete hex in JS, so they read the same values from here via the hooks in\n// palette-store.\n//\n// The default preset here mirrors the :root/.dark blocks in tokens.css exactly. The\n// five hand-picked alternatives of #307 (`ALTERNATIVE_PRESETS`, a reference bank that\n// `presetById` never resolved) were removed in 0.35 (refactor audit 2026-10, API-6c;\n// deprecated in 0.34): `PALETTES` is what an app offers, and `derivePalette` makes a\n// palette of its own.\n\nimport type { HeatStops } from \"./chart-palette\";\nimport { contrastStep, rememberTokenSet } from \"./contrast-tokens\";\n\nexport interface TokenSet {\n // Backgrounds & chrome\n bgPage: string;\n bgSurface: string;\n bgSurface2: string;\n border: string;\n textPrimary: string;\n // The two quieter text roles. Derived per preset by blending `textPrimary` toward\n // that preset's own surfaces until the contrast against the WORST of bgPage /\n // bgSurface / bgSurface2 hits 7:1 and 4.8:1 — so both clear WCAG AA for normal text\n // (4.5:1) on every surface they can land on, and both inherit the preset's warmth\n // instead of importing a cool grey from Tailwind's palette.\n textSecondary: string;\n textMuted: string;\n // Interactive brand accent\n brand: string;\n brandHover: string;\n brandContrast: string;\n // Semantic money (never red/green — CVD-safe, paired with +/- cues elsewhere)\n moneyIncome: string;\n moneyExpense: string;\n moneyNet: string;\n moneyNeutral: string;\n // Categorical chart series (Paul Tol \"Muted\" by default — CVD-safe), exactly 9\n chart: string[];\n // Heatmap interpolation stops (variance diverging + spending sequential)\n heat: HeatStops;\n}\n\nexport interface PalettePreset {\n id: string;\n name: string;\n blurb: string;\n light: TokenSet;\n dark: TokenSet;\n}\n\n// The shipped default (feedback #328): SOLAR-DUSK warm light + INDIGO-NOIR deep\n// dark surfaces — the two curated presets the user picked per mode — but with a\n// SINGLE unified brand accent (indigo) across both modes rather than each\n// preset's own accent (the user asked for the brand accent to stay the same).\n// So the light block is Solar Dusk with its teal brand overridden to indigo, and\n// the dark block is Indigo Noir (already indigo). The money trio\n// (income/expense/net) drives the chart bars and stays palette-driven so those\n// semantic colours adapt to each mode's contrast (best practice — feedback #328).\nexport const DEFAULT_PRESET: PalettePreset = {\n id: \"default\",\n name: \"Default\",\n blurb: \"Solar-dusk light · indigo-noir dark\",\n light: {\n // Solar Dusk (light) surfaces, with the brand unified to indigo (see above).\n bgPage: \"#ede3cf\",\n bgSurface: \"#f6ecd9\",\n // The well is the page in light (0.33, k26): #f3ead6 stood 1.02:1 from the card it\n // is inset in. Every light preset does the same; see SURFACE_L in palette-derive.ts.\n bgSurface2: \"#ede3cf\",\n border: \"#e2d6bd\",\n textPrimary: \"#463f33\",\n textSecondary: \"#50493c\",\n textMuted: \"#696153\",\n brand: \"#4f46e5\",\n brandHover: \"#4338ca\",\n brandContrast: \"#ffffff\",\n moneyIncome: \"#0b6650\",\n moneyExpense: \"#905902\",\n moneyNet: \"#7a4fa3\",\n moneyNeutral: \"#6b6453\",\n chart: [\"#332288\", \"#88ccee\", \"#44aa99\", \"#117733\", \"#999933\", \"#ddcc77\", \"#cc6677\", \"#882255\", \"#aa4499\"],\n heat: {\n neutral: \"#f1e7d2\",\n under: \"#0b6650\",\n over: \"#9c6418\",\n seqLow: \"#f6ecd0\",\n seqHigh: \"#9c6418\",\n empty: \"rgba(148,163,184,0.14)\",\n },\n },\n dark: {\n // Indigo Noir (dark)\n bgPage: \"#0e0f1c\",\n bgSurface: \"#181a2c\",\n bgSurface2: \"#21243a\",\n border: \"#2e3252\",\n textPrimary: \"#e6e8f4\",\n textSecondary: \"#adafbe\",\n textMuted: \"#8d90a0\",\n brand: \"#8b93f8\",\n brandHover: \"#aab1fb\",\n brandContrast: \"#16182b\",\n moneyIncome: \"#22c3b6\",\n // Amber-400 (#fbbf24) sat at OKLab L 0.84 while every other dark token lives\n // at 0.68–0.74, so outflows outshouted the inflows they are paired with. Same\n // hue and chroma, pulled to L 0.785 (dev#434). The heat stops below keep the\n // brighter amber on purpose: a gradient endpoint is meant to be the loudest\n // thing in its scale, and it is a fill, not a figure.\n moneyExpense: \"#e4b035\",\n moneyNet: \"#b39aef\",\n moneyNeutral: \"#9aa1bd\",\n chart: [\"#7e72d6\", \"#9fd8f2\", \"#5fc4b0\", \"#3fa45f\", \"#bfbf5e\", \"#e8dda0\", \"#e08c9a\", \"#c25a78\", \"#cc78be\"],\n heat: {\n neutral: \"#363a5a\",\n under: \"#22c3b6\",\n over: \"#fbbf24\",\n seqLow: \"#3a2c14\",\n seqHigh: \"#fbbf24\",\n empty: \"rgba(148,163,184,0.10)\",\n },\n },\n};\n\n// ── \"Imprint\" chart hues (feedback #119) ──────────────────────────────────────\n// anyplot's categorical palette (https://anyplot.ai/palette), by a colleague of\n// Marcel's. 8 hues + an amber semantic anchor, derived from Wong 2011 by a\n// Petroff-style max-min ΔE search in CAM02-UCS with Machado 2009 CVD simulation —\n// the same lineage as our default Paul Tol \"Muted\", one generation on, and tuned\n// for exactly the warm cream paper our light theme uses.\n//\n// This preset is DEFAULT_PRESET with ONLY the 9 categorical chart hues swapped;\n// surfaces, brand and the semantic money trio stay put, because those were their\n// own deliberate decisions (#307/#328) and are not what the palette is for. The\n// heatmap stops likewise stay teal/amber: they encode under/over, and imprint's\n// own diverging ramp is red↔blue, which would fight the money semantics.\n//\n// Measured on our surfaces (CIEDE2000, Machado severity-100, 8 like-for-like\n// slots on the cream light surface #f6ecd9) — neither palette dominates:\n// Paul Tol Muted min-contrast 1.38 · worst-CVD ΔE00 11.8 · normal ΔE00 16.1\n// imprint min-contrast 1.95 · worst-CVD ΔE00 7.2 · normal ΔE00 22.2\n// i.e. imprint is punchier and has no near-invisible pale slot (Tol's #88ccee\n// sits at 1.5:1 on cream), while Tol separates better under colour-vision\n// deficiency. So this ships as a CHOICE, not as a new default.\n//\n// The dark set keeps imprint's hues verbatim except matte-red and rose, whose\n// lightness is lifted (oklch L 0.50→0.55) because verbatim they land at 2.67:1\n// and 2.76:1 on our deep-indigo dark surface — under WCAG 2.1 SC 1.4.11's 3:1\n// non-text minimum. Lifted they clear it at 3.30:1 / 3.28:1. anyplot documents\n// the same shortfall on their own dark ground and answers it with a stroke halo;\n// lifting keeps the fix in the token layer instead of every chart component.\nconst IMPRINT_HUES_LIGHT = [\n \"#009E73\", // brand green — first series\n \"#C475FD\", // lavender — creative\n \"#4467A3\", // blue — cool / info\n \"#BD8233\", // ochre — earth / commodity\n \"#AE3030\", // matte red — bad / loss / error\n \"#2ABCCD\", // cyan — sky / tech-cool\n \"#954477\", // rose — wellness / health\n \"#99B314\", // lime — growth / nature\n \"#DDCC77\", // amber — anyplot's semantic anchor, used here as slot 9\n];\nconst IMPRINT_HUES_DARK = [\n \"#009E73\",\n \"#C475FD\",\n \"#4467A3\",\n \"#BD8233\",\n \"#BF413E\", // matte red, L-lifted for our dark surface\n \"#2ABCCD\",\n \"#A25083\", // rose, L-lifted for our dark surface\n \"#99B314\",\n \"#DDCC77\",\n];\n\nexport const IMPRINT_PRESET: PalettePreset = {\n id: \"imprint\",\n name: \"Imprint\",\n blurb: \"Colourblind-safe chart hues by anyplot.ai\",\n light: { ...DEFAULT_PRESET.light, chart: IMPRINT_HUES_LIGHT },\n dark: { ...DEFAULT_PRESET.dark, chart: IMPRINT_HUES_DARK },\n};\n\n// The full-theme switcher from #307 stayed retired (feedback #328) — the default\n// is still the single source of truth for surfaces, brand and money (its five\n// alternatives are gone, see the header). What IS selectable is\n// the categorical chart ramp (feedback #119), so these two presets are the live\n// set; presetById falls back to the default for any stale persisted id.\n/**\n * The categorical chart ramp, shared by every derived preset below.\n *\n * Paul Tol's \"Muted\" set, unchanged, and deliberately NOT re-derived per preset. A\n * categorical ramp solves a different problem from a UI palette — separability among\n * nine unknown siblings, rather than contrast against one known surface — and a set\n * optimised against real dichromat confusion lines beats one spaced evenly by formula.\n * `auditChartRamp` in palette-derive.ts measures it: 0.059 minimum separation in the\n * light variant, which is the number MIN_SEPARATION was calibrated under.\n *\n * It pays for that in contrast: four of the nine light hues sit below the 3:1 WCAG\n * 1.4.11 asks of a filled shape. That is not fixable by darkening them — see\n * SINGLE_LIGHTNESS_MAX_SERIES — so a chart with more than four series must carry a\n * second channel (a direct label, a pattern, a legend adjacent to the mark).\n */\nconst PAUL_TOL = {\n light: DEFAULT_PRESET.light.chart,\n dark: DEFAULT_PRESET.dark.chart,\n} as const;\n\n/**\n * Presets DERIVED rather than picked, by `derivePalette` from one brand colour each.\n *\n * Every text role here was solved to a contrast target against the worst of the three\n * surfaces it can land on, every semantic colour against both the page and its own badge\n * tint, and the whole set is re-checked by `__tests__/palette-audit.test.ts` (\"derived\n * presets\") — which re-runs the deriver and fails if these committed values drift from\n * what it now produces.\n *\n * They are committed rather than derived at import because deriving eight token sets\n * costs ~34ms, and charging every consumer that at startup for palettes most of them\n * will never select is the wrong trade. The test is what keeps the two in agreement.\n *\n * Regenerated in 0.34 (round 0.34 BUG-8): the solve now measures the hex it ships rather\n * than the float before rounding, and the audit no longer lets a hex pair pass 0.05 under\n * its threshold. 52 values moved one step (66 counting the heat stops that repeat them);\n * Contrast's neutrals lost half their slate tint, its brand having half the chroma at\n * which the neutrals carry a hue in full.\n */\nexport const DERIVED_PRESETS: PalettePreset[] = [\n {\n id: \"ink\",\n name: \"Ink\",\n blurb: \"Cool blue-grey ground · solved for AAA body text\",\n light: {\n bgPage: \"#dce2ef\",\n bgSurface: \"#e6edfa\",\n bgSurface2: \"#dce2ef\",\n border: \"#b0bace\",\n textPrimary: \"#2e3139\",\n textSecondary: \"#454850\",\n textMuted: \"#5f636c\",\n brand: \"#2f5fd0\",\n brandHover: \"#1f4cbc\",\n brandContrast: \"#ffffff\",\n moneyIncome: \"#00725f\",\n moneyExpense: \"#8e5900\",\n moneyNet: \"#7356a2\",\n moneyNeutral: \"#61646c\",\n chart: PAUL_TOL.light,\n heat: {\n neutral: \"#dce2ef\",\n under: \"#00725f\",\n over: \"#8e5900\",\n seqLow: \"#fee3c5\",\n seqHigh: \"#8e5900\",\n empty: \"rgba(120,110,95,0.14)\",\n },\n },\n dark: {\n bgPage: \"#090d15\",\n bgSurface: \"#131720\",\n bgSurface2: \"#1d212b\",\n border: \"#363e4f\",\n textPrimary: \"#c8ccd6\",\n textSecondary: \"#a7abb5\",\n textMuted: \"#858a92\",\n brand: \"#3466d7\",\n brandHover: \"#2353c3\",\n brandContrast: \"#ffffff\",\n moneyIncome: \"#009a80\",\n moneyExpense: \"#b77b29\",\n moneyNet: \"#9679c9\",\n moneyNeutral: \"#a1a5ac\",\n chart: PAUL_TOL.dark,\n heat: {\n neutral: \"#1d212b\",\n under: \"#009a80\",\n over: \"#b77b29\",\n seqLow: \"#331f05\",\n seqHigh: \"#b77b29\",\n empty: \"rgba(160,170,190,0.10)\",\n },\n },\n },\n {\n id: \"moss\",\n name: \"Moss\",\n blurb: \"Green ground · solved for AAA body text\",\n light: {\n bgPage: \"#d8e6dd\",\n bgSurface: \"#e3f1e8\",\n bgSurface2: \"#d8e6dd\",\n border: \"#abbfb2\",\n textPrimary: \"#2c332e\",\n textSecondary: \"#424b45\",\n textMuted: \"#5d6660\",\n brand: \"#2f7a52\",\n brandHover: \"#196842\",\n brandContrast: \"#ffffff\",\n moneyIncome: \"#00725f\",\n moneyExpense: \"#8e5900\",\n moneyNet: \"#7356a2\",\n moneyNeutral: \"#5f6662\",\n chart: PAUL_TOL.light,\n heat: {\n neutral: \"#d8e6dd\",\n under: \"#00725f\",\n over: \"#8e5900\",\n seqLow: \"#fee3c5\",\n seqHigh: \"#8e5900\",\n empty: \"rgba(120,110,95,0.14)\",\n },\n },\n dark: {\n bgPage: \"#060f0a\",\n bgSurface: \"#101a14\",\n bgSurface2: \"#1a241e\",\n border: \"#314337\",\n textPrimary: \"#c6cfc9\",\n textSecondary: \"#a5aea8\",\n textMuted: \"#838c86\",\n brand: \"#317b53\",\n brandHover: \"#1c6943\",\n brandContrast: \"#ffffff\",\n moneyIncome: \"#009a80\",\n moneyExpense: \"#b87c2a\",\n moneyNet: \"#977ac9\",\n moneyNeutral: \"#9fa7a2\",\n chart: PAUL_TOL.dark,\n heat: {\n neutral: \"#1a241e\",\n under: \"#009a80\",\n over: \"#b87c2a\",\n seqLow: \"#331f05\",\n seqHigh: \"#b87c2a\",\n empty: \"rgba(160,170,190,0.10)\",\n },\n },\n },\n {\n id: \"plum\",\n name: \"Plum\",\n blurb: \"Violet ground · solved for AAA body text\",\n light: {\n bgPage: \"#e7dfea\",\n bgSurface: \"#f2e9f5\",\n bgSurface2: \"#e7dfea\",\n border: \"#c2b5c6\",\n textPrimary: \"#352f36\",\n textSecondary: \"#4c464e\",\n textMuted: \"#676169\",\n brand: \"#7b3f8f\",\n brandHover: \"#692d7d\",\n brandContrast: \"#ffffff\",\n moneyIncome: \"#00715e\",\n moneyExpense: \"#8d5800\",\n moneyNet: \"#7355a2\",\n moneyNeutral: \"#676269\",\n chart: PAUL_TOL.light,\n heat: {\n neutral: \"#e7dfea\",\n under: \"#00715e\",\n over: \"#8d5800\",\n seqLow: \"#fee3c5\",\n seqHigh: \"#8d5800\",\n empty: \"rgba(120,110,95,0.14)\",\n },\n },\n dark: {\n bgPage: \"#100b12\",\n bgSurface: \"#1b151d\",\n bgSurface2: \"#251f27\",\n border: \"#453b48\",\n textPrimary: \"#d0cad2\",\n textSecondary: \"#afa9b1\",\n textMuted: \"#8d8790\",\n brand: \"#9154a6\",\n brandHover: \"#7f4293\",\n brandContrast: \"#ffffff\",\n moneyIncome: \"#009980\",\n moneyExpense: \"#b77b29\",\n moneyNet: \"#9679c9\",\n moneyNeutral: \"#a8a2aa\",\n chart: PAUL_TOL.dark,\n heat: {\n neutral: \"#251f27\",\n under: \"#009980\",\n over: \"#b77b29\",\n seqLow: \"#331f05\",\n seqHigh: \"#b77b29\",\n empty: \"rgba(160,170,190,0.10)\",\n },\n },\n },\n {\n id: \"contrast\",\n name: \"High contrast\",\n blurb: \"Near-neutral ground · text solved to 13:1 / 8.5:1 / 5.5:1\",\n light: {\n bgPage: \"#e1e2e3\",\n bgSurface: \"#ecedee\",\n bgSurface2: \"#e1e2e3\",\n border: \"#b8babc\",\n textPrimary: \"#1b1d21\",\n textSecondary: \"#3a3c40\",\n textMuted: \"#55585c\",\n brand: \"#1f2937\",\n brandHover: \"#111b28\",\n brandContrast: \"#ffffff\",\n moneyIncome: \"#00715e\",\n moneyExpense: \"#8d5800\",\n moneyNet: \"#7255a1\",\n moneyNeutral: \"#616467\",\n chart: PAUL_TOL.light,\n heat: {\n neutral: \"#e1e2e3\",\n under: \"#00715e\",\n over: \"#8d5800\",\n seqLow: \"#fee3c5\",\n seqHigh: \"#8d5800\",\n empty: \"rgba(120,110,95,0.14)\",\n },\n },\n dark: {\n bgPage: \"#0c0d0e\",\n bgSurface: \"#171718\",\n bgSurface2: \"#212122\",\n border: \"#3d3e3f\",\n textPrimary: \"#e4e8ec\",\n textSecondary: \"#b9bdc1\",\n textMuted: \"#95979c\",\n brand: \"#556c8e\",\n brandHover: \"#455b7c\",\n brandContrast: \"#ffffff\",\n moneyIncome: \"#009a80\",\n moneyExpense: \"#b77b29\",\n moneyNet: \"#9679c9\",\n moneyNeutral: \"#a2a5a8\",\n chart: PAUL_TOL.dark,\n heat: {\n neutral: \"#212122\",\n under: \"#009a80\",\n over: \"#b77b29\",\n seqLow: \"#331f05\",\n seqHigh: \"#b77b29\",\n empty: \"rgba(160,170,190,0.10)\",\n },\n },\n },\n];\n\nexport const PALETTES: PalettePreset[] = [DEFAULT_PRESET, IMPRINT_PRESET, ...DERIVED_PRESETS];\n\nexport function presetById(id: string): PalettePreset {\n return PALETTES.find((p) => p.id === id) ?? DEFAULT_PRESET;\n}\n\n/**\n * Write a token set onto an element's inline style as CSS custom properties.\n *\n * This is the only writer, and there is no un-writer: `presetById` falls back to\n * `DEFAULT_PRESET` and this then writes the full set, so returning to the default\n * APPLIES it rather than clearing anything. A `clearTokenSet` and the hand-kept\n * 24-name `TOKEN_VARS` list it looped over used to live here, both exported, both\n * called by nobody in either consumer — a second copy of these property names with\n * nothing comparing the two, so adding a token here and forgetting it there would\n * have been silent and only a dead function would have noticed. The list is gone;\n * the test beside this asserts instead that every field of a `TokenSet` reaches the\n * element, which is what that list was standing in for.\n *\n * **More contrast (0.32, docs/text-size-harmonization.md §5, §10.5).** With `contrast`\n * the text and border tokens are written one step stronger, and `--text-placeholder` —\n * otherwise derived in tokens.css — is written inline too; without it that inline\n * placeholder is removed again, so the stylesheet's formula applies. The step is made\n * HERE because these tokens are inline: no `[data-contrast=more]` rule could beat them.\n *\n * `contrast` defaults to the element's own `data-contrast=\"more\"`, which the contrast\n * layer (`applyContrast`, `useApplyContrast`) sets first. That is how the palette and the\n * contrast cooperate without knowing each other: a palette change re-applies through\n * here and keeps the contrast, and a contrast change re-applies the set remembered here.\n */\nexport function applyTokenSet(\n el: HTMLElement,\n t: TokenSet,\n contrast: boolean = el.getAttribute(\"data-contrast\") === \"more\",\n): void {\n rememberTokenSet(el, t);\n const step = contrast ? contrastStep(t) : null;\n el.style.setProperty(\"--bg-page\", t.bgPage);\n el.style.setProperty(\"--bg-surface\", t.bgSurface);\n el.style.setProperty(\"--bg-surface-2\", t.bgSurface2);\n el.style.setProperty(\"--border\", step?.border ?? t.border);\n el.style.setProperty(\"--text-primary\", t.textPrimary);\n el.style.setProperty(\"--text-secondary\", step?.textSecondary ?? t.textSecondary);\n el.style.setProperty(\"--text-muted\", step?.textMuted ?? t.textMuted);\n if (step) el.style.setProperty(\"--text-placeholder\", step.textPlaceholder);\n else el.style.removeProperty(\"--text-placeholder\");\n el.style.setProperty(\"--brand\", t.brand);\n el.style.setProperty(\"--brand-hover\", t.brandHover);\n el.style.setProperty(\"--brand-contrast\", t.brandContrast);\n el.style.setProperty(\"--money-income\", t.moneyIncome);\n el.style.setProperty(\"--money-expense\", t.moneyExpense);\n el.style.setProperty(\"--money-net\", t.moneyNet);\n el.style.setProperty(\"--money-neutral\", t.moneyNeutral);\n t.chart.forEach((c, i) => el.style.setProperty(`--chart-${i + 1}`, c));\n}\n"],"mappings":";AAiBA,SAAS,cAAc,wBAAwB;AA+CxC,MAAM,iBAAgC;AAAA,EAC3C,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,OAAO;AAAA,EACP,OAAO;AAAA;AAAA,IAEL,QAAQ;AAAA,IACR,WAAW;AAAA;AAAA;AAAA,IAGX,YAAY;AAAA,IACZ,QAAQ;AAAA,IACR,aAAa;AAAA,IACb,eAAe;AAAA,IACf,WAAW;AAAA,IACX,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,eAAe;AAAA,IACf,aAAa;AAAA,IACb,cAAc;AAAA,IACd,UAAU;AAAA,IACV,cAAc;AAAA,IACd,OAAO,CAAC,WAAW,WAAW,WAAW,WAAW,WAAW,WAAW,WAAW,WAAW,SAAS;AAAA,IACzG,MAAM;AAAA,MACJ,SAAS;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,MACN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B,gBAAgB,GAAG,eAAe;AAErF,SAAS,WAAW,IAA2B;AACpD,SAAO,SAAS,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK;AAC9C;AA0BO,SAAS,cACd,IACA,GACA,WAAoB,GAAG,aAAa,eAAe,MAAM,QACnD;AACN,mBAAiB,IAAI,CAAC;AACtB,QAAM,OAAO,WAAW,aAAa,CAAC,IAAI;AAC1C,KAAG,MAAM,YAAY,aAAa,EAAE,MAAM;AAC1C,KAAG,MAAM,YAAY,gBAAgB,EAAE,SAAS;AAChD,KAAG,MAAM,YAAY,kBAAkB,EAAE,UAAU;AACnD,KAAG,MAAM,YAAY,YAAY,MAAM,UAAU,EAAE,MAAM;AACzD,KAAG,MAAM,YAAY,kBAAkB,EAAE,WAAW;AACpD,KAAG,MAAM,YAAY,oBAAoB,MAAM,iBAAiB,EAAE,aAAa;AAC/E,KAAG,MAAM,YAAY,gBAAgB,MAAM,aAAa,EAAE,SAAS;AACnE,MAAI,KAAM,IAAG,MAAM,YAAY,sBAAsB,KAAK,eAAe;AAAA,MACpE,IAAG,MAAM,eAAe,oBAAoB;AACjD,KAAG,MAAM,YAAY,WAAW,EAAE,KAAK;AACvC,KAAG,MAAM,YAAY,iBAAiB,EAAE,UAAU;AAClD,KAAG,MAAM,YAAY,oBAAoB,EAAE,aAAa;AACxD,KAAG,MAAM,YAAY,kBAAkB,EAAE,WAAW;AACpD,KAAG,MAAM,YAAY,mBAAmB,EAAE,YAAY;AACtD,KAAG,MAAM,YAAY,eAAe,EAAE,QAAQ;AAC9C,KAAG,MAAM,YAAY,mBAAmB,EAAE,YAAY;AACtD,IAAE,MAAM,QAAQ,CAAC,GAAG,MAAM,GAAG,MAAM,YAAY,WAAW,IAAI,CAAC,IAAI,CAAC,CAAC;AACvE;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/theme/palette-presets.ts"],"sourcesContent":["// Appearance presets — the single source of truth for the \"palette switcher\"\n// (feedback #307). Each preset is a full set of design-token values for BOTH\n// light and dark, covering the page/surface backgrounds, the brand accent, the\n// semantic money trio and the 9-colour categorical chart palette, plus the\n// heatmap stops. A preset is applied at runtime by writing these as CSS custom\n// properties onto <html> (see palette-store.ts), which instantly re-skins every\n// token-driven surface and chart. The two heatmaps and the treemap interpolate\n// concrete hex in JS, so they read the same values from here via the hooks in\n// palette-store.\n//\n// The default preset here mirrors the :root/.dark blocks in tokens.css exactly. The\n// five hand-picked alternatives of #307 (`ALTERNATIVE_PRESETS`, a reference bank that\n// `presetById` never resolved) were removed in 0.35 (refactor audit 2026-10, API-6c;\n// deprecated in 0.34): `PALETTES` is what an app offers, and `derivePalette` makes a\n// palette of its own.\n\nimport type { HeatStops } from \"./chart-palette\";\nimport { contrastStep, rememberTokenSet } from \"./contrast-tokens\";\n\nexport interface TokenSet {\n // Backgrounds & chrome\n bgPage: string;\n bgSurface: string;\n bgSurface2: string;\n border: string;\n textPrimary: string;\n // The two quieter text roles. Derived per preset by blending `textPrimary` toward\n // that preset's own surfaces until the contrast against the WORST of bgPage /\n // bgSurface / bgSurface2 hits 7:1 and 4.8:1 — so both clear WCAG AA for normal text\n // (4.5:1) on every surface they can land on, and both inherit the preset's warmth\n // instead of importing a cool grey from Tailwind's palette.\n textSecondary: string;\n textMuted: string;\n // Interactive brand accent\n brand: string;\n brandHover: string;\n brandContrast: string;\n // Semantic money (never red/green — CVD-safe, paired with +/- cues elsewhere)\n moneyIncome: string;\n moneyExpense: string;\n moneyNet: string;\n moneyNeutral: string;\n // Categorical chart series (Paul Tol \"Muted\" by default — CVD-safe), exactly 9\n chart: string[];\n // Heatmap interpolation stops (variance diverging + spending sequential)\n heat: HeatStops;\n}\n\nexport interface PalettePreset {\n id: string;\n name: string;\n blurb: string;\n light: TokenSet;\n dark: TokenSet;\n}\n\n// The shipped default (feedback #328): SOLAR-DUSK warm light + INDIGO-NOIR deep\n// dark surfaces — the two curated presets the user picked per mode — but with a\n// SINGLE unified brand accent (indigo) across both modes rather than each\n// preset's own accent (the user asked for the brand accent to stay the same).\n// So the light block is Solar Dusk with its teal brand overridden to indigo, and\n// the dark block is Indigo Noir (already indigo). The money trio\n// (income/expense/net) drives the chart bars and stays palette-driven so those\n// semantic colours adapt to each mode's contrast (best practice — feedback #328).\nexport const DEFAULT_PRESET: PalettePreset = {\n id: \"default\",\n name: \"Default\",\n blurb: \"Solar-dusk light · indigo-noir dark\",\n light: {\n // Solar Dusk (light) surfaces, with the brand unified to indigo (see above).\n bgPage: \"#ede3cf\",\n bgSurface: \"#f6ecd9\",\n // The well is the page in light (0.33, k26): #f3ead6 stood 1.02:1 from the card it\n // is inset in. Every light preset does the same; see SURFACE_L in palette-derive.ts.\n bgSurface2: \"#ede3cf\",\n border: \"#e2d6bd\",\n textPrimary: \"#463f33\",\n textSecondary: \"#50493c\",\n textMuted: \"#696153\",\n brand: \"#4f46e5\",\n brandHover: \"#4338ca\",\n brandContrast: \"#ffffff\",\n moneyIncome: \"#0b6650\",\n moneyExpense: \"#905902\",\n moneyNet: \"#7a4fa3\",\n moneyNeutral: \"#6b6453\",\n chart: [\"#332288\", \"#88ccee\", \"#44aa99\", \"#117733\", \"#999933\", \"#ddcc77\", \"#cc6677\", \"#882255\", \"#aa4499\"],\n heat: {\n neutral: \"#f1e7d2\",\n under: \"#0b6650\",\n over: \"#9c6418\",\n seqLow: \"#f6ecd0\",\n seqHigh: \"#9c6418\",\n empty: \"rgba(148,163,184,0.14)\",\n },\n },\n dark: {\n // Indigo Noir (dark)\n bgPage: \"#0e0f1c\",\n bgSurface: \"#181a2c\",\n bgSurface2: \"#21243a\",\n border: \"#2e3252\",\n textPrimary: \"#e6e8f4\",\n textSecondary: \"#adafbe\",\n textMuted: \"#8d90a0\",\n brand: \"#8b93f8\",\n brandHover: \"#aab1fb\",\n brandContrast: \"#16182b\",\n moneyIncome: \"#22c3b6\",\n // Amber-400 (#fbbf24) sat at OKLab L 0.84 while every other dark token lives\n // at 0.68–0.74, so outflows outshouted the inflows they are paired with. Same\n // hue and chroma, pulled to L 0.785 (dev#434). The heat stops below keep the\n // brighter amber on purpose: a gradient endpoint is meant to be the loudest\n // thing in its scale, and it is a fill, not a figure.\n moneyExpense: \"#e4b035\",\n moneyNet: \"#b39aef\",\n moneyNeutral: \"#9aa1bd\",\n chart: [\"#7e72d6\", \"#9fd8f2\", \"#5fc4b0\", \"#3fa45f\", \"#bfbf5e\", \"#e8dda0\", \"#e08c9a\", \"#c25a78\", \"#cc78be\"],\n heat: {\n neutral: \"#363a5a\",\n under: \"#22c3b6\",\n over: \"#fbbf24\",\n seqLow: \"#3a2c14\",\n seqHigh: \"#fbbf24\",\n empty: \"rgba(148,163,184,0.10)\",\n },\n },\n};\n\n// ── \"Imprint\" chart hues (feedback #119) ──────────────────────────────────────\n// anyplot's categorical palette (https://anyplot.ai/palette), by a colleague of\n// Marcel's. 8 hues + an amber semantic anchor, derived from Wong 2011 by a\n// Petroff-style max-min ΔE search in CAM02-UCS with Machado 2009 CVD simulation —\n// the same lineage as our default Paul Tol \"Muted\", one generation on, and tuned\n// for exactly the warm cream paper our light theme uses.\n//\n// This preset is DEFAULT_PRESET with ONLY the 9 categorical chart hues swapped;\n// surfaces, brand and the semantic money trio stay put, because those were their\n// own deliberate decisions (#307/#328) and are not what the palette is for. The\n// heatmap stops likewise stay teal/amber: they encode under/over, and imprint's\n// own diverging ramp is red↔blue, which would fight the money semantics.\n//\n// Measured on our surfaces (CIEDE2000, Machado severity-100, 8 like-for-like\n// slots on the cream light surface #f6ecd9) — neither palette dominates:\n// Paul Tol Muted min-contrast 1.38 · worst-CVD ΔE00 11.8 · normal ΔE00 16.1\n// imprint min-contrast 1.95 · worst-CVD ΔE00 7.2 · normal ΔE00 22.2\n// i.e. imprint is punchier and has no near-invisible pale slot (Tol's #88ccee\n// sits at 1.5:1 on cream), while Tol separates better under colour-vision\n// deficiency. So this ships as a CHOICE, not as a new default.\n//\n// The dark set keeps imprint's hues verbatim except matte-red and rose, whose\n// lightness is lifted (oklch L 0.50→0.55) because verbatim they land at 2.67:1\n// and 2.76:1 on our deep-indigo dark surface — under WCAG 2.1 SC 1.4.11's 3:1\n// non-text minimum. Lifted they clear it at 3.30:1 / 3.28:1. anyplot documents\n// the same shortfall on their own dark ground and answers it with a stroke halo;\n// lifting keeps the fix in the token layer instead of every chart component.\nconst IMPRINT_HUES_LIGHT = [\n \"#009E73\", // brand green — first series\n \"#C475FD\", // lavender — creative\n \"#4467A3\", // blue — cool / info\n \"#BD8233\", // ochre — earth / commodity\n \"#AE3030\", // matte red — bad / loss / error\n \"#2ABCCD\", // cyan — sky / tech-cool\n \"#954477\", // rose — wellness / health\n \"#99B314\", // lime — growth / nature\n \"#DDCC77\", // amber — anyplot's semantic anchor, used here as slot 9\n];\nconst IMPRINT_HUES_DARK = [\n \"#009E73\",\n \"#C475FD\",\n \"#4467A3\",\n \"#BD8233\",\n \"#BF413E\", // matte red, L-lifted for our dark surface\n \"#2ABCCD\",\n \"#A25083\", // rose, L-lifted for our dark surface\n \"#99B314\",\n \"#DDCC77\",\n];\n\nexport const IMPRINT_PRESET: PalettePreset = {\n id: \"imprint\",\n name: \"Imprint\",\n blurb: \"Colourblind-safe chart hues by anyplot.ai\",\n light: { ...DEFAULT_PRESET.light, chart: IMPRINT_HUES_LIGHT },\n dark: { ...DEFAULT_PRESET.dark, chart: IMPRINT_HUES_DARK },\n};\n\n// The full-theme switcher from #307 stayed retired (feedback #328) — the default\n// is still the single source of truth for surfaces, brand and money (its five\n// alternatives are gone, see the header). What IS selectable is\n// the categorical chart ramp (feedback #119), so these two presets are the live\n// set; presetById falls back to the default for any stale persisted id.\n/**\n * The categorical chart ramp, shared by every derived preset below.\n *\n * Paul Tol's \"Muted\" set, unchanged, and deliberately NOT re-derived per preset. A\n * categorical ramp solves a different problem from a UI palette — separability among\n * nine unknown siblings, rather than contrast against one known surface — and a set\n * optimised against real dichromat confusion lines beats one spaced evenly by formula.\n * `auditChartRamp` in palette-derive.ts measures it: 0.059 minimum separation in the\n * light variant, which is the number MIN_SEPARATION was calibrated under.\n *\n * It pays for that in contrast: four of the nine light hues sit below the 3:1 WCAG\n * 1.4.11 asks of a filled shape. That is not fixable by darkening them — see\n * SINGLE_LIGHTNESS_MAX_SERIES — so a chart with more than four series must carry a\n * second channel (a direct label, a pattern, a legend adjacent to the mark).\n */\nconst PAUL_TOL = {\n light: DEFAULT_PRESET.light.chart,\n dark: DEFAULT_PRESET.dark.chart,\n} as const;\n\n/**\n * Presets DERIVED rather than picked, by `derivePalette` from one brand colour each.\n *\n * Every text role here was solved to a contrast target against the worst of the three\n * surfaces it can land on, every semantic colour against both the page and its own badge\n * tint, and the whole set is re-checked by `__tests__/palette-audit.test.ts` (\"derived\n * presets\") — which re-runs the deriver and fails if these committed values drift from\n * what it now produces.\n *\n * They are committed rather than derived at import because deriving eight token sets\n * costs ~34ms, and charging every consumer that at startup for palettes most of them\n * will never select is the wrong trade. The test is what keeps the two in agreement.\n *\n * Regenerated in 0.34 (round 0.34 BUG-8): the solve now measures the hex it ships rather\n * than the float before rounding, and the audit no longer lets a hex pair pass 0.05 under\n * its threshold. 52 values moved one step (66 counting the heat stops that repeat them);\n * Contrast's neutrals lost half their slate tint, its brand having half the chroma at\n * which the neutrals carry a hue in full.\n */\nexport const DERIVED_PRESETS: PalettePreset[] = [\n {\n id: \"ink\",\n name: \"Ink\",\n blurb: \"Cool blue-grey ground · solved for AAA body text\",\n light: {\n bgPage: \"#dce2ef\",\n bgSurface: \"#e6edfa\",\n bgSurface2: \"#dce2ef\",\n border: \"#b0bace\",\n textPrimary: \"#2e3139\",\n textSecondary: \"#454850\",\n textMuted: \"#5f636c\",\n brand: \"#2f5fd0\",\n brandHover: \"#1f4cbc\",\n brandContrast: \"#ffffff\",\n moneyIncome: \"#00725f\",\n moneyExpense: \"#8e5900\",\n moneyNet: \"#7356a2\",\n moneyNeutral: \"#61646c\",\n chart: PAUL_TOL.light,\n heat: {\n neutral: \"#dce2ef\",\n under: \"#00725f\",\n over: \"#8e5900\",\n seqLow: \"#fee3c5\",\n seqHigh: \"#8e5900\",\n empty: \"rgba(120,110,95,0.14)\",\n },\n },\n dark: {\n bgPage: \"#090d15\",\n bgSurface: \"#131720\",\n bgSurface2: \"#1d212b\",\n border: \"#363e4f\",\n textPrimary: \"#c8ccd6\",\n textSecondary: \"#a7abb5\",\n textMuted: \"#858a92\",\n brand: \"#3466d7\",\n brandHover: \"#2353c3\",\n brandContrast: \"#ffffff\",\n moneyIncome: \"#009a80\",\n moneyExpense: \"#b77b29\",\n moneyNet: \"#9679c9\",\n moneyNeutral: \"#a1a5ac\",\n chart: PAUL_TOL.dark,\n heat: {\n neutral: \"#1d212b\",\n under: \"#009a80\",\n over: \"#b77b29\",\n seqLow: \"#331f05\",\n seqHigh: \"#b77b29\",\n empty: \"rgba(160,170,190,0.10)\",\n },\n },\n },\n {\n id: \"moss\",\n name: \"Moss\",\n blurb: \"Green ground · solved for AAA body text\",\n light: {\n bgPage: \"#d8e6dd\",\n bgSurface: \"#e3f1e8\",\n bgSurface2: \"#d8e6dd\",\n border: \"#abbfb2\",\n textPrimary: \"#2c332e\",\n textSecondary: \"#424b45\",\n textMuted: \"#5d6660\",\n brand: \"#2f7a52\",\n brandHover: \"#196842\",\n brandContrast: \"#ffffff\",\n moneyIncome: \"#00725f\",\n moneyExpense: \"#8e5900\",\n moneyNet: \"#7356a2\",\n moneyNeutral: \"#5f6662\",\n chart: PAUL_TOL.light,\n heat: {\n neutral: \"#d8e6dd\",\n under: \"#00725f\",\n over: \"#8e5900\",\n seqLow: \"#fee3c5\",\n seqHigh: \"#8e5900\",\n empty: \"rgba(120,110,95,0.14)\",\n },\n },\n dark: {\n bgPage: \"#060f0a\",\n bgSurface: \"#101a14\",\n bgSurface2: \"#1a241e\",\n border: \"#314337\",\n textPrimary: \"#c6cfc9\",\n textSecondary: \"#a5aea8\",\n textMuted: \"#838c86\",\n brand: \"#317b53\",\n brandHover: \"#1c6943\",\n brandContrast: \"#ffffff\",\n moneyIncome: \"#009a80\",\n moneyExpense: \"#b87c2a\",\n moneyNet: \"#977ac9\",\n moneyNeutral: \"#9fa7a2\",\n chart: PAUL_TOL.dark,\n heat: {\n neutral: \"#1a241e\",\n under: \"#009a80\",\n over: \"#b87c2a\",\n seqLow: \"#331f05\",\n seqHigh: \"#b87c2a\",\n empty: \"rgba(160,170,190,0.10)\",\n },\n },\n },\n {\n id: \"plum\",\n name: \"Plum\",\n blurb: \"Violet ground · solved for AAA body text\",\n light: {\n bgPage: \"#e7dfea\",\n bgSurface: \"#f2e9f5\",\n bgSurface2: \"#e7dfea\",\n border: \"#c2b5c6\",\n textPrimary: \"#352f36\",\n textSecondary: \"#4c464e\",\n textMuted: \"#676169\",\n brand: \"#7b3f8f\",\n brandHover: \"#692d7d\",\n brandContrast: \"#ffffff\",\n moneyIncome: \"#00715e\",\n moneyExpense: \"#8d5800\",\n moneyNet: \"#7355a2\",\n moneyNeutral: \"#676269\",\n chart: PAUL_TOL.light,\n heat: {\n neutral: \"#e7dfea\",\n under: \"#00715e\",\n over: \"#8d5800\",\n seqLow: \"#fee3c5\",\n seqHigh: \"#8d5800\",\n empty: \"rgba(120,110,95,0.14)\",\n },\n },\n dark: {\n bgPage: \"#100b12\",\n bgSurface: \"#1b151d\",\n bgSurface2: \"#251f27\",\n border: \"#453b48\",\n textPrimary: \"#d0cad2\",\n textSecondary: \"#afa9b1\",\n textMuted: \"#8d8790\",\n brand: \"#9154a6\",\n brandHover: \"#7f4293\",\n brandContrast: \"#ffffff\",\n moneyIncome: \"#009980\",\n moneyExpense: \"#b77b29\",\n moneyNet: \"#9679c9\",\n moneyNeutral: \"#a8a2aa\",\n chart: PAUL_TOL.dark,\n heat: {\n neutral: \"#251f27\",\n under: \"#009980\",\n over: \"#b77b29\",\n seqLow: \"#331f05\",\n seqHigh: \"#b77b29\",\n empty: \"rgba(160,170,190,0.10)\",\n },\n },\n },\n {\n id: \"contrast\",\n name: \"High contrast\",\n blurb: \"Near-neutral ground · text solved to 13:1 / 8.5:1 / 5.5:1\",\n light: {\n bgPage: \"#e1e2e3\",\n bgSurface: \"#ecedee\",\n bgSurface2: \"#e1e2e3\",\n border: \"#b8babc\",\n textPrimary: \"#1b1d21\",\n textSecondary: \"#3a3c40\",\n textMuted: \"#55585c\",\n brand: \"#1f2937\",\n brandHover: \"#111b28\",\n brandContrast: \"#ffffff\",\n moneyIncome: \"#00715e\",\n moneyExpense: \"#8d5800\",\n moneyNet: \"#7255a1\",\n moneyNeutral: \"#616467\",\n chart: PAUL_TOL.light,\n heat: {\n neutral: \"#e1e2e3\",\n under: \"#00715e\",\n over: \"#8d5800\",\n seqLow: \"#fee3c5\",\n seqHigh: \"#8d5800\",\n empty: \"rgba(120,110,95,0.14)\",\n },\n },\n dark: {\n bgPage: \"#0c0d0e\",\n bgSurface: \"#171718\",\n bgSurface2: \"#212122\",\n border: \"#3d3e3f\",\n textPrimary: \"#e4e8ec\",\n textSecondary: \"#b9bdc1\",\n textMuted: \"#95979c\",\n brand: \"#556c8e\",\n brandHover: \"#455b7c\",\n brandContrast: \"#ffffff\",\n moneyIncome: \"#009a80\",\n moneyExpense: \"#b77b29\",\n moneyNet: \"#9679c9\",\n moneyNeutral: \"#a2a5a8\",\n chart: PAUL_TOL.dark,\n heat: {\n neutral: \"#212122\",\n under: \"#009a80\",\n over: \"#b77b29\",\n seqLow: \"#331f05\",\n seqHigh: \"#b77b29\",\n empty: \"rgba(160,170,190,0.10)\",\n },\n },\n },\n];\n\nexport const PALETTES: PalettePreset[] = [DEFAULT_PRESET, IMPRINT_PRESET, ...DERIVED_PRESETS];\n\nexport function presetById(id: string): PalettePreset {\n return PALETTES.find((p) => p.id === id) ?? DEFAULT_PRESET;\n}\n\n/**\n * Write a token set onto an element's inline style as CSS custom properties.\n *\n * This is the only writer, and there is no un-writer: `presetById` falls back to\n * `DEFAULT_PRESET` and this then writes the full set, so returning to the default\n * APPLIES it rather than clearing anything. A `clearTokenSet` and the hand-kept\n * 24-name `TOKEN_VARS` list it looped over used to live here, both exported, both\n * called by nobody in either consumer — a second copy of these property names with\n * nothing comparing the two, so adding a token here and forgetting it there would\n * have been silent and only a dead function would have noticed. The list is gone;\n * the test beside this asserts instead that every field of a `TokenSet` reaches the\n * element, which is what that list was standing in for.\n *\n * **More contrast (0.32, docs/text-size-harmonization.md §5, §10.5).** With `contrast`\n * the text and border tokens are written one step stronger — in a light set the well and\n * the four money colours too (0.36, docs/colour-roles-harmonization.md §13) — and `--text-placeholder` —\n * otherwise derived in tokens.css — is written inline too; without it that inline\n * placeholder is removed again, so the stylesheet's formula applies. The step is made\n * HERE because these tokens are inline: no `[data-contrast=more]` rule could beat them.\n *\n * `contrast` defaults to the element's own `data-contrast=\"more\"`, which the contrast\n * layer (`applyContrast`, `useApplyContrast`) sets first. That is how the palette and the\n * contrast cooperate without knowing each other: a palette change re-applies through\n * here and keeps the contrast, and a contrast change re-applies the set remembered here.\n */\nexport function applyTokenSet(\n el: HTMLElement,\n t: TokenSet,\n contrast: boolean = el.getAttribute(\"data-contrast\") === \"more\",\n): void {\n rememberTokenSet(el, t);\n const step = contrast ? contrastStep(t) : null;\n el.style.setProperty(\"--bg-page\", t.bgPage);\n el.style.setProperty(\"--bg-surface\", t.bgSurface);\n // The light well and money step under More contrast (0.36, colour-roles §13); in dark\n // and at Standard `well` is null and the set's own are written.\n el.style.setProperty(\"--bg-surface-2\", step?.well?.bgSurface2 ?? t.bgSurface2);\n el.style.setProperty(\"--border\", step?.border ?? t.border);\n el.style.setProperty(\"--text-primary\", t.textPrimary);\n el.style.setProperty(\"--text-secondary\", step?.textSecondary ?? t.textSecondary);\n el.style.setProperty(\"--text-muted\", step?.textMuted ?? t.textMuted);\n if (step) el.style.setProperty(\"--text-placeholder\", step.textPlaceholder);\n else el.style.removeProperty(\"--text-placeholder\");\n el.style.setProperty(\"--brand\", t.brand);\n el.style.setProperty(\"--brand-hover\", t.brandHover);\n el.style.setProperty(\"--brand-contrast\", t.brandContrast);\n el.style.setProperty(\"--money-income\", step?.well?.moneyIncome ?? t.moneyIncome);\n el.style.setProperty(\"--money-expense\", step?.well?.moneyExpense ?? t.moneyExpense);\n el.style.setProperty(\"--money-net\", step?.well?.moneyNet ?? t.moneyNet);\n el.style.setProperty(\"--money-neutral\", step?.well?.moneyNeutral ?? t.moneyNeutral);\n t.chart.forEach((c, i) => el.style.setProperty(`--chart-${i + 1}`, c));\n}\n"],"mappings":";AAiBA,SAAS,cAAc,wBAAwB;AA+CxC,MAAM,iBAAgC;AAAA,EAC3C,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,OAAO;AAAA,EACP,OAAO;AAAA;AAAA,IAEL,QAAQ;AAAA,IACR,WAAW;AAAA;AAAA;AAAA,IAGX,YAAY;AAAA,IACZ,QAAQ;AAAA,IACR,aAAa;AAAA,IACb,eAAe;AAAA,IACf,WAAW;AAAA,IACX,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,eAAe;AAAA,IACf,aAAa;AAAA,IACb,cAAc;AAAA,IACd,UAAU;AAAA,IACV,cAAc;AAAA,IACd,OAAO,CAAC,WAAW,WAAW,WAAW,WAAW,WAAW,WAAW,WAAW,WAAW,SAAS;AAAA,IACzG,MAAM;AAAA,MACJ,SAAS;AAAA,MACT,OAAO;AAAA,MACP,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,SAAS;AAAA,MACT,OAAO;AAAA,IACT;AAAA,EACF;AAAA,EACA,MAAM;AAAA;AAAA,IAEJ,QAAQ;AAAA,IACR,WAAW;AAAA,IACX,YAAY;AAAA,IACZ,QAAQ;AAAA,IACR,aAAa;AAAA,IACb,eAAe;AAAA,IACf,WAAW;AAAA,IACX,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,eAAe;AAAA,IACf,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAMb,cAAc;AAAA,IACd,UAAU;AAAA,IACV,cAAc;AAAA,IACd,OAAO,CAAC,WAAW,WAAW,WAAW,WAAW,WAAW,WAAW,WAAW,WAAW,SAAS;AAAA,IACzG,MAAM;AAAA,MACJ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,MAAM,YAAY,kBAAkB,EAAE,WAAW;AACpD,KAAG,MAAM,YAAY,oBAAoB,MAAM,iBAAiB,EAAE,aAAa;AAC/E,KAAG,MAAM,YAAY,gBAAgB,MAAM,aAAa,EAAE,SAAS;AACnE,MAAI,KAAM,IAAG,MAAM,YAAY,sBAAsB,KAAK,eAAe;AAAA,MACpE,IAAG,MAAM,eAAe,oBAAoB;AACjD,KAAG,MAAM,YAAY,WAAW,EAAE,KAAK;AACvC,KAAG,MAAM,YAAY,iBAAiB,EAAE,UAAU;AAClD,KAAG,MAAM,YAAY,oBAAoB,EAAE,aAAa;AACxD,KAAG,MAAM,YAAY,kBAAkB,MAAM,MAAM,eAAe,EAAE,WAAW;AAC/E,KAAG,MAAM,YAAY,mBAAmB,MAAM,MAAM,gBAAgB,EAAE,YAAY;AAClF,KAAG,MAAM,YAAY,eAAe,MAAM,MAAM,YAAY,EAAE,QAAQ;AACtE,KAAG,MAAM,YAAY,mBAAmB,MAAM,MAAM,gBAAgB,EAAE,YAAY;AAClF,IAAE,MAAM,QAAQ,CAAC,GAAG,MAAM,GAAG,MAAM,YAAY,WAAW,IAAI,CAAC,IAAI,CAAC,CAAC;AACvE;","names":[]}
|
|
@@ -3,6 +3,7 @@ import { useEffect } from "react";
|
|
|
3
3
|
import { create } from "zustand";
|
|
4
4
|
import { persist } from "zustand/middleware";
|
|
5
5
|
import { logger } from "../lib/logger.js";
|
|
6
|
+
import { registerDeviceSetting } from "../lib/device-settings.js";
|
|
6
7
|
import { applyTokenSet, DEFAULT_PRESET, presetById } from "./palette-presets.js";
|
|
7
8
|
function applyPersistedPalette(storageKey, mode) {
|
|
8
9
|
let id = DEFAULT_PRESET.id;
|
|
@@ -26,6 +27,11 @@ function createPaletteStore(storageKey, useTheme) {
|
|
|
26
27
|
"palette"
|
|
27
28
|
)
|
|
28
29
|
);
|
|
30
|
+
registerDeviceSetting({
|
|
31
|
+
key: storageKey,
|
|
32
|
+
kind: "appearance",
|
|
33
|
+
reset: () => usePalette.getState().setId(DEFAULT_PRESET.id)
|
|
34
|
+
});
|
|
29
35
|
function useApplyPalette() {
|
|
30
36
|
const id = usePalette((s) => s.id);
|
|
31
37
|
const mode = useTheme((s) => s.mode);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/theme/palette-store.ts"],"sourcesContent":["import { useEffect } from \"react\";\nimport { create } from \"zustand\";\nimport { persist } from \"zustand/middleware\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport { logger } from \"../lib/logger\";\nimport type { HeatStops } from \"./chart-palette\";\nimport { applyTokenSet, DEFAULT_PRESET, presetById, type TokenSet } from \"./palette-presets\";\nimport type { ThemeState, ThemeMode } from \"./theme-store\";\n\n/**\n * Pre-hydration counterpart to `applyPersistedTheme`: read the palette id\n * persisted under `storageKey` straight from localStorage and apply that preset's\n * tokens for the given resolved `mode` to <html>, BEFORE React mounts (no flash of\n * the default palette). Falls back to the default preset for missing/malformed\n * state, so an app entrypoint never re-types the persist envelope.\n */\nexport function applyPersistedPalette(storageKey: string, mode: ThemeMode): void {\n let id = DEFAULT_PRESET.id;\n try {\n const blob = JSON.parse(localStorage.getItem(storageKey) ?? \"{}\") as {\n state?: { id?: string };\n };\n if (blob.state?.id) id = blob.state.id;\n } catch {\n /* malformed storage → default preset */\n }\n applyTokenSet(document.documentElement, presetById(id)[mode]);\n}\n\n// The palette layer flips the whole app between candidate appearance presets at\n// runtime (feedback #307), re-skinning every token-driven surface and chart.\n// Persisted like the theme so a reload keeps the selection.\ninterface PaletteState {\n id: string;\n setId: (id: string) => void;\n}\n\n/**\n * Build a palette store bound to a consumer-supplied localStorage key, wired to\n * that app's theme store (for the active light/dark mode). Returns the palette\n * hook plus the effect + selector hooks that read the active preset's tokens.\n */\nexport function createPaletteStore(\n storageKey: string,\n useTheme: UseBoundStore<StoreApi<ThemeState>>,\n) {\n const usePalette = create<PaletteState>()(\n logger(\n persist(\n (set) => ({\n id: DEFAULT_PRESET.id,\n setId: (id) => set({ id }),\n }),\n { name: storageKey, version: 1 },\n ),\n \"palette\",\n ),\n );\n\n /** Apply the active preset's tokens to <html> as inline CSS custom properties,\n * re-applying when the preset or the light/dark theme changes. Tailwind v4\n * strips a bare root token block from the bundle, so this inline write from\n * the TS source of truth is what actually drives the colours.\n *\n * 0.32: keeps More contrast. `applyTokenSet` reads `<html data-contrast>`, which the\n * contrast store sets, and steps the tokens itself; the contrast store re-applies\n * the set written here when the contrast changes (docs/text-size-harmonization.md\n * §10.5). Neither store needs the other. */\n function useApplyPalette(): void {\n const id = usePalette((s) => s.id);\n const mode = useTheme((s) => s.mode);\n useEffect(() => {\n applyTokenSet(document.documentElement, presetById(id)[mode]);\n }, [id, mode]);\n }\n\n /** The active preset's token set for the current theme — the source for the\n * JS-interpolated charts (treemap fills, heatmap stops) that can't read CSS\n * vars. */\n function useActiveTokenSet(): TokenSet {\n const id = usePalette((s) => s.id);\n const mode = useTheme((s) => s.mode);\n return presetById(id)[mode];\n }\n\n /** The 9 categorical chart hues for the active preset/theme (treemap cells). */\n function useChartHex(): string[] {\n return useActiveTokenSet().chart;\n }\n\n /** The active preset/theme heatmap interpolation stops. */\n function useHeatStops(): HeatStops {\n return useActiveTokenSet().heat;\n }\n\n return { usePalette, useApplyPalette, useActiveTokenSet, useChartHex, useHeatStops };\n}\n\nexport type PaletteStore = ReturnType<typeof createPaletteStore>;\n"],"mappings":";AAAA,SAAS,iBAAiB;AAC1B,SAAS,cAAc;AACvB,SAAS,eAAe;AAExB,SAAS,cAAc;
|
|
1
|
+
{"version":3,"sources":["../../src/theme/palette-store.ts"],"sourcesContent":["import { useEffect } from \"react\";\nimport { create } from \"zustand\";\nimport { persist } from \"zustand/middleware\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport { logger } from \"../lib/logger\";\nimport { registerDeviceSetting } from \"../lib/device-settings\";\nimport type { HeatStops } from \"./chart-palette\";\nimport { applyTokenSet, DEFAULT_PRESET, presetById, type TokenSet } from \"./palette-presets\";\nimport type { ThemeState, ThemeMode } from \"./theme-store\";\n\n/**\n * Pre-hydration counterpart to `applyPersistedTheme`: read the palette id\n * persisted under `storageKey` straight from localStorage and apply that preset's\n * tokens for the given resolved `mode` to <html>, BEFORE React mounts (no flash of\n * the default palette). Falls back to the default preset for missing/malformed\n * state, so an app entrypoint never re-types the persist envelope.\n */\nexport function applyPersistedPalette(storageKey: string, mode: ThemeMode): void {\n let id = DEFAULT_PRESET.id;\n try {\n const blob = JSON.parse(localStorage.getItem(storageKey) ?? \"{}\") as {\n state?: { id?: string };\n };\n if (blob.state?.id) id = blob.state.id;\n } catch {\n /* malformed storage → default preset */\n }\n applyTokenSet(document.documentElement, presetById(id)[mode]);\n}\n\n// The palette layer flips the whole app between candidate appearance presets at\n// runtime (feedback #307), re-skinning every token-driven surface and chart.\n// Persisted like the theme so a reload keeps the selection.\ninterface PaletteState {\n id: string;\n setId: (id: string) => void;\n}\n\n/**\n * Build a palette store bound to a consumer-supplied localStorage key, wired to\n * that app's theme store (for the active light/dark mode). Returns the palette\n * hook plus the effect + selector hooks that read the active preset's tokens.\n */\nexport function createPaletteStore(\n storageKey: string,\n useTheme: UseBoundStore<StoreApi<ThemeState>>,\n) {\n const usePalette = create<PaletteState>()(\n logger(\n persist(\n (set) => ({\n id: DEFAULT_PRESET.id,\n setId: (id) => set({ id }),\n }),\n { name: storageKey, version: 1 },\n ),\n \"palette\",\n ),\n );\n // Reset this device's settings (docs/settings-harmonization.md §11.4): the Default\n // palette, STATE ONLY. `useApplyPalette`, where the app mounts it, re-applies through\n // its effect. Never an imperative `applyTokenSet` here: it would remember a token set\n // on <html>, and an app without a palette layer (Kurvenschmiede) would then take the\n // contrast store's palette branch, where a theme switch no longer re-writes the stepped\n // tokens (KS 3.3).\n registerDeviceSetting({\n key: storageKey,\n kind: \"appearance\",\n reset: () => usePalette.getState().setId(DEFAULT_PRESET.id),\n });\n\n /** Apply the active preset's tokens to <html> as inline CSS custom properties,\n * re-applying when the preset or the light/dark theme changes. Tailwind v4\n * strips a bare root token block from the bundle, so this inline write from\n * the TS source of truth is what actually drives the colours.\n *\n * 0.32: keeps More contrast. `applyTokenSet` reads `<html data-contrast>`, which the\n * contrast store sets, and steps the tokens itself; the contrast store re-applies\n * the set written here when the contrast changes (docs/text-size-harmonization.md\n * §10.5). Neither store needs the other. */\n function useApplyPalette(): void {\n const id = usePalette((s) => s.id);\n const mode = useTheme((s) => s.mode);\n useEffect(() => {\n applyTokenSet(document.documentElement, presetById(id)[mode]);\n }, [id, mode]);\n }\n\n /** The active preset's token set for the current theme — the source for the\n * JS-interpolated charts (treemap fills, heatmap stops) that can't read CSS\n * vars. */\n function useActiveTokenSet(): TokenSet {\n const id = usePalette((s) => s.id);\n const mode = useTheme((s) => s.mode);\n return presetById(id)[mode];\n }\n\n /** The 9 categorical chart hues for the active preset/theme (treemap cells). */\n function useChartHex(): string[] {\n return useActiveTokenSet().chart;\n }\n\n /** The active preset/theme heatmap interpolation stops. */\n function useHeatStops(): HeatStops {\n return useActiveTokenSet().heat;\n }\n\n return { usePalette, useApplyPalette, useActiveTokenSet, useChartHex, useHeatStops };\n}\n\nexport type PaletteStore = ReturnType<typeof createPaletteStore>;\n"],"mappings":";AAAA,SAAS,iBAAiB;AAC1B,SAAS,cAAc;AACvB,SAAS,eAAe;AAExB,SAAS,cAAc;AACvB,SAAS,6BAA6B;AAEtC,SAAS,eAAe,gBAAgB,kBAAiC;AAUlE,SAAS,sBAAsB,YAAoB,MAAuB;AAC/E,MAAI,KAAK,eAAe;AACxB,MAAI;AACF,UAAM,OAAO,KAAK,MAAM,aAAa,QAAQ,UAAU,KAAK,IAAI;AAGhE,QAAI,KAAK,OAAO,GAAI,MAAK,KAAK,MAAM;AAAA,EACtC,QAAQ;AAAA,EAER;AACA,gBAAc,SAAS,iBAAiB,WAAW,EAAE,EAAE,IAAI,CAAC;AAC9D;AAeO,SAAS,mBACd,YACA,UACA;AACA,QAAM,aAAa,OAAqB;AAAA,IACtC;AAAA,MACE;AAAA,QACE,CAAC,SAAS;AAAA,UACR,IAAI,eAAe;AAAA,UACnB,OAAO,CAAC,OAAO,IAAI,EAAE,GAAG,CAAC;AAAA,QAC3B;AAAA,QACA,EAAE,MAAM,YAAY,SAAS,EAAE;AAAA,MACjC;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAOA,wBAAsB;AAAA,IACpB,KAAK;AAAA,IACL,MAAM;AAAA,IACN,OAAO,MAAM,WAAW,SAAS,EAAE,MAAM,eAAe,EAAE;AAAA,EAC5D,CAAC;AAWD,WAAS,kBAAwB;AAC/B,UAAM,KAAK,WAAW,CAAC,MAAM,EAAE,EAAE;AACjC,UAAM,OAAO,SAAS,CAAC,MAAM,EAAE,IAAI;AACnC,cAAU,MAAM;AACd,oBAAc,SAAS,iBAAiB,WAAW,EAAE,EAAE,IAAI,CAAC;AAAA,IAC9D,GAAG,CAAC,IAAI,IAAI,CAAC;AAAA,EACf;AAKA,WAAS,oBAA8B;AACrC,UAAM,KAAK,WAAW,CAAC,MAAM,EAAE,EAAE;AACjC,UAAM,OAAO,SAAS,CAAC,MAAM,EAAE,IAAI;AACnC,WAAO,WAAW,EAAE,EAAE,IAAI;AAAA,EAC5B;AAGA,WAAS,cAAwB;AAC/B,WAAO,kBAAkB,EAAE;AAAA,EAC7B;AAGA,WAAS,eAA0B;AACjC,WAAO,kBAAkB,EAAE;AAAA,EAC7B;AAEA,SAAO,EAAE,YAAY,iBAAiB,mBAAmB,aAAa,aAAa;AACrF;","names":[]}
|
package/dist/theme/text-size.js
CHANGED
|
@@ -4,6 +4,7 @@ import { create } from "zustand";
|
|
|
4
4
|
import { persist } from "zustand/middleware";
|
|
5
5
|
import { logger } from "../lib/logger.js";
|
|
6
6
|
import { readStored } from "../lib/safe-storage.js";
|
|
7
|
+
import { registerDeviceSetting } from "../lib/device-settings.js";
|
|
7
8
|
const TEXT_SIZES = ["normal", "large", "xlarge"];
|
|
8
9
|
const TEXT_SCALE = { normal: 1, large: 1.25, xlarge: 1.5 };
|
|
9
10
|
const TEXT_SIZE_ATTRIBUTE = "data-text-size";
|
|
@@ -95,6 +96,11 @@ function createTextSizeStore(storageKey) {
|
|
|
95
96
|
"text-size"
|
|
96
97
|
)
|
|
97
98
|
);
|
|
99
|
+
registerDeviceSetting({
|
|
100
|
+
key: storageKey,
|
|
101
|
+
kind: "appearance",
|
|
102
|
+
reset: () => useTextSizeStore.getState().setSize(null)
|
|
103
|
+
});
|
|
98
104
|
function useApplyTextSize({ account } = {}) {
|
|
99
105
|
const device = useTextSizeStore((s) => s.size);
|
|
100
106
|
const size = resolveTextSize(device, account);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/theme/text-size.ts"],"sourcesContent":["import { useEffect, useMemo, useSyncExternalStore } from \"react\";\nimport { create } from \"zustand\";\nimport { persist } from \"zustand/middleware\";\nimport { logger } from \"../lib/logger\";\nimport { readStored } from \"../lib/safe-storage\";\n\n/**\n * The text size (docs/text-size-harmonization.md §2.1, §3.1, §10.3, §10.6).\n *\n * ONE scale on `<html>`: `data-text-size=\"normal|large|xlarge\"`, and `tokens.css` turns\n * it into `font-size: 100% / 125% / 150%` — percent, never px, so \"Normal\" keeps\n * whatever size the person set in the browser. Tailwind's spacing and type are rem, so\n * about 90 % of every screen grows with that one declaration; the breakpoints follow too\n * (tokens.css redefines `sm:` … `3xl:` per size, {@link useBreakpoint} answers the same\n * in JS).\n *\n * The names below are the mechanism's public vocabulary and are FROZEN: an app's\n * storage, its `/auth/me` column (server-kit's `TEXT_SIZES`) and the inline boot snippet\n * all spell them this way.\n */\n\n/** The three steps, in order (§2.1, §10.6): server-kit's `TEXT_SIZES`, value for value. */\nexport const TEXT_SIZES = [\"normal\", \"large\", \"xlarge\"] as const;\n\nexport type TextSize = (typeof TEXT_SIZES)[number];\n\n/** The root font size each step sets, as a factor of the browser's own (tokens.css). For\n * what CSS cannot reach: a canvas or SVG chart's px constants, a windowed list's row\n * estimate, a popover width in px (§3.2). */\nexport const TEXT_SCALE: Readonly<Record<TextSize, number>> = { normal: 1, large: 1.25, xlarge: 1.5 };\n\n/** The attribute on `<html>` that carries the size. */\nconst TEXT_SIZE_ATTRIBUTE = \"data-text-size\";\n\nexport function isTextSize(value: unknown): value is TextSize {\n return value === \"normal\" || value === \"large\" || value === \"xlarge\";\n}\n\n/**\n * The size in force: **this device's own choice → the account's → Normal** (§2.2, §2.6).\n * Each is taken only when it is one of {@link TEXT_SIZES}; anything else (a stale value,\n * `null` = never chosen) falls through to the next. The one order the pre-paint call, the\n * apply hook and `useAccountAppearance` all use, so the three can never disagree.\n */\nexport function resolveTextSize(device: unknown, account?: unknown): TextSize {\n if (isTextSize(device)) return device;\n if (isTextSize(account)) return account;\n return \"normal\";\n}\n\n/* ── <html data-text-size> and the subscribers that read it ─────────────── */\n\nconst listeners = new Set<() => void>();\nlet observer: MutationObserver | null = null;\n\nfunction notify(): void {\n for (const listener of listeners) listener();\n}\n\nfunction subscribe(listener: () => void): () => void {\n listeners.add(listener);\n // Also catches writers that are not this module — the inline boot snippet, an app\n // setting the attribute by hand, a test.\n if (!observer && typeof MutationObserver !== \"undefined\" && typeof document !== \"undefined\") {\n observer = new MutationObserver(notify);\n observer.observe(document.documentElement, { attributes: true, attributeFilter: [TEXT_SIZE_ATTRIBUTE] });\n }\n return () => {\n listeners.delete(listener);\n if (listeners.size === 0) {\n observer?.disconnect();\n observer = null;\n }\n };\n}\n\n/** The size `<html>` carries now; Normal without one (or outside a browser). */\nexport function readTextSize(): TextSize {\n if (typeof document === \"undefined\") return \"normal\";\n const value = document.documentElement.getAttribute(TEXT_SIZE_ATTRIBUTE);\n return isTextSize(value) ? value : \"normal\";\n}\n\n/** Put `size` on `<html>`. Every {@link useTextSize} re-renders with it. */\nexport function applyTextSize(size: TextSize): void {\n if (typeof document === \"undefined\") return;\n const root = document.documentElement;\n if (root.getAttribute(TEXT_SIZE_ATTRIBUTE) === size) return;\n root.setAttribute(TEXT_SIZE_ATTRIBUTE, size);\n notify();\n}\n\nexport interface TextSizeInfo {\n size: TextSize;\n /** {@link TEXT_SCALE} for `size`: 1, 1.25 or 1.5. */\n scale: number;\n}\n\n/**\n * The size in force on this page, and its scale (§3.1) — read from `<html>`, so it needs\n * no store and works in every kit component: whoever applied the size (the app's store,\n * the pre-paint call, the inline snippet), this follows it.\n *\n * Only for what CSS cannot do. A class that should differ at Large is a `large:`\n * variant; a layout switch is a breakpoint, which already scales.\n */\nexport function useTextSize(): TextSizeInfo {\n const size = useSyncExternalStore(subscribe, readTextSize, () => \"normal\" as const);\n return useMemo(() => ({ size, scale: TEXT_SCALE[size] }), [size]);\n}\n\n/* ── Storage: the frozen format, the pre-paint call ─────────────────────── */\n\n/**\n * What a text-size store persists under its key — zustand's persist envelope, and FROZEN\n * (§10.3) because an app's inline `<head>` snippet reads it before any module loads:\n *\n * {\"state\":{\"size\":\"large\"},\"version\":1}\n *\n * `size` is one of {@link TEXT_SIZES}, or `null` / absent when this device never chose.\n * A future change adds a key; it never renames `state.size` or changes its values.\n *\n * A hand-written seed (a test, a screenshot script) must carry `\"version\":1`: the store\n * drops a stored state of another version as a migration it doesn't know, silently\n * (keksdose's 0.32 report). The inline snippet reads `state.size` whatever the version,\n * so the two would disagree. In the kit's showcase, `?text-size=` needs no seed.\n */\nexport interface PersistedTextSize {\n state?: { size?: TextSize | null };\n version?: number;\n}\n\n/** This device's own choice under `storageKey`, or `null` when it never chose (or the\n * storage is blocked, malformed, or holds a value that is not a size). */\nexport function readPersistedTextSize(storageKey: string): TextSize | null {\n try {\n const blob = JSON.parse(readStored(storageKey) ?? \"null\") as PersistedTextSize | null;\n const size = blob?.state?.size;\n return isTextSize(size) ? size : null;\n } catch {\n return null;\n }\n}\n\nexport interface PersistedAppearanceOptions {\n /**\n * The account's last known value, for a device without a choice of its own (§10.3):\n * what the app persisted with its user (keksdose keeps `/auth/me` in localStorage), so\n * a cold boot paints the account's size instead of Normal and then jumping — offline\n * too. Called once, guarded: a throw counts as \"no account value\".\n */\n account?: () => string | null | undefined;\n}\n\nfunction readAccount(account: PersistedAppearanceOptions[\"account\"]): unknown {\n if (!account) return undefined;\n try {\n return account();\n } catch {\n return undefined;\n }\n}\n\n/**\n * Pre-paint (§3.1, §10.3): read this device's choice under `storageKey` — else the\n * account's last known value — and put it on `<html>` BEFORE `createRoot`, next to\n * `applyPersistedTheme`, so the first paint already has the right size. Returns the size\n * applied.\n *\n * ```ts\n * applyPersistedTextSize(\"keksdose-text-size\", {\n * account: () => readPersistedUser()?.text_size,\n * });\n * ```\n */\nexport function applyPersistedTextSize(storageKey: string, options: PersistedAppearanceOptions = {}): TextSize {\n const size = resolveTextSize(readPersistedTextSize(storageKey), readAccount(options.account));\n applyTextSize(size);\n return size;\n}\n\n/**\n * The same pre-paint as {@link applyPersistedTextSize}, as an inline `<head>` script for\n * a boot splash painted from `index.html` before any module runs (§10.3). A function\n * EXPRESSION: call it with the storage key and, optionally, a function returning the\n * account's last known value.\n *\n * ```html\n * <script>\n * (function(k,a){…})(\"keksdose-text-size\", function () {\n * return JSON.parse(localStorage.getItem(\"keksdose-auth\")).state.user.text_size;\n * });\n * </script>\n * ```\n *\n * Paste the constant's value in place of `(function(k,a){…})`. It reads the frozen\n * {@link PersistedTextSize} format, never throws, and sets only `data-text-size`.\n *\n * The splash sizes in rem, and needs the root rules inline beside it, since the app's\n * stylesheet is a separate request and arrives after the splash paints (0.32.1,\n * keksdose's 0.32 report: that is every app, not an edge case):\n *\n * ```html\n * <style>html[data-text-size=large]{font-size:125%}html[data-text-size=xlarge]{font-size:150%}</style>\n * ```\n *\n * Under a hash-based Content Security Policy (`script-src 'sha256-…'`) this is a second\n * inline script with its own hash: add it to the policy, and recompute it whenever the\n * storage key or the account function in the call changes (keksdose added it to both\n * its Caddyfiles, and its guard test hashes every inline script).\n */\nexport const TEXT_SIZE_INLINE_SCRIPT =\n \"(function(k,a){function ok(v){return v==='normal'||v==='large'||v==='xlarge'}\" +\n \"var v=null;try{var s=JSON.parse(localStorage.getItem(k)||'null');v=s&&s.state&&s.state.size}catch(e){}\" +\n \"if(!ok(v)){v=null;try{v=a?a():null}catch(e){}}\" +\n \"try{document.documentElement.setAttribute('data-text-size',ok(v)?v:'normal')}catch(e){}})\";\n\n/* ── The store ──────────────────────────────────────────────────────────── */\n\nexport interface TextSizeState {\n /** This device's own choice (persisted), or `null` when it never chose — then the\n * account's value applies (§2.2). */\n size: TextSize | null;\n /** Store this device's choice; `null` forgets it, so the account's applies again. */\n setSize: (size: TextSize | null) => void;\n}\n\nexport interface ApplyTextSizeOptions {\n /** The account's value (`/auth/me`'s `text_size`): it applies while this device has no\n * choice of its own. Leave it out where there is no account. */\n account?: string | null;\n}\n\n/**\n * Build a text-size store bound to a consumer-supplied localStorage key, shaped like\n * `createThemeStore` (§6). It holds the DEVICE's choice only; the account's value comes\n * in through `useApplyTextSize({ account })` and `useAccountAppearance`, and the size in\n * force is always {@link resolveTextSize} of the two.\n *\n * - `useTextSizeStore` — the zustand hook: `size` (device choice or null) and `setSize`.\n * - `useApplyTextSize({ account })` — the effect that puts the size in force on `<html>`.\n * Mount it once near the root, beside `useApplyTheme`.\n *\n * The persisted format is {@link PersistedTextSize}, and frozen.\n */\nexport function createTextSizeStore(storageKey: string) {\n const useTextSizeStore = create<TextSizeState>()(\n logger(\n persist(\n (set) => ({\n size: null,\n setSize: (size) => set({ size: isTextSize(size) ? size : null }),\n }),\n {\n name: storageKey,\n version: 1,\n partialize: (s) => ({ size: s.size }),\n // A hand-edited or future value must not reach <html> as an unknown size.\n merge: (persisted, current) => ({\n ...current,\n size: isTextSize((persisted as { size?: unknown } | null)?.size)\n ? ((persisted as { size: TextSize }).size)\n : null,\n }),\n },\n ),\n \"text-size\",\n ),\n );\n\n function useApplyTextSize({ account }: ApplyTextSizeOptions = {}): TextSize {\n const device = useTextSizeStore((s) => s.size);\n const size = resolveTextSize(device, account);\n useEffect(() => {\n applyTextSize(size);\n }, [size]);\n return size;\n }\n\n return { useTextSizeStore, useApplyTextSize };\n}\n\nexport type TextSiz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AAEA,WAAS,iBAAiB,EAAE,QAAQ,IAA0B,CAAC,GAAa;AAC1E,UAAM,SAAS,iBAAiB,CAAC,MAAM,EAAE,IAAI;AAC7C,UAAM,OAAO,gBAAgB,QAAQ,OAAO;AAC5C,cAAU,MAAM;AACd,oBAAc,IAAI;AAAA,IACpB,GAAG,CAAC,IAAI,CAAC;AACT,WAAO;AAAA,EACT;AAEA,SAAO,EAAE,kBAAkB,iBAAiB;AAC9C;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/theme/text-size.ts"],"sourcesContent":["import { useEffect, useMemo, useSyncExternalStore } from \"react\";\nimport { create } from \"zustand\";\nimport { persist } from \"zustand/middleware\";\nimport { logger } from \"../lib/logger\";\nimport { readStored } from \"../lib/safe-storage\";\nimport { registerDeviceSetting } from \"../lib/device-settings\";\n\n/**\n * The text size (docs/text-size-harmonization.md §2.1, §3.1, §10.3, §10.6).\n *\n * ONE scale on `<html>`: `data-text-size=\"normal|large|xlarge\"`, and `tokens.css` turns\n * it into `font-size: 100% / 125% / 150%` — percent, never px, so \"Normal\" keeps\n * whatever size the person set in the browser. Tailwind's spacing and type are rem, so\n * about 90 % of every screen grows with that one declaration; the breakpoints follow too\n * (tokens.css redefines `sm:` … `3xl:` per size, {@link useBreakpoint} answers the same\n * in JS).\n *\n * The names below are the mechanism's public vocabulary and are FROZEN: an app's\n * storage, its `/auth/me` column (server-kit's `TEXT_SIZES`) and the inline boot snippet\n * all spell them this way.\n */\n\n/** The three steps, in order (§2.1, §10.6): server-kit's `TEXT_SIZES`, value for value. */\nexport const TEXT_SIZES = [\"normal\", \"large\", \"xlarge\"] as const;\n\nexport type TextSize = (typeof TEXT_SIZES)[number];\n\n/** The root font size each step sets, as a factor of the browser's own (tokens.css). For\n * what CSS cannot reach: a canvas or SVG chart's px constants, a windowed list's row\n * estimate, a popover width in px (§3.2). */\nexport const TEXT_SCALE: Readonly<Record<TextSize, number>> = { normal: 1, large: 1.25, xlarge: 1.5 };\n\n/** The attribute on `<html>` that carries the size. */\nconst TEXT_SIZE_ATTRIBUTE = \"data-text-size\";\n\nexport function isTextSize(value: unknown): value is TextSize {\n return value === \"normal\" || value === \"large\" || value === \"xlarge\";\n}\n\n/**\n * The size in force: **this device's own choice → the account's → Normal** (§2.2, §2.6).\n * Each is taken only when it is one of {@link TEXT_SIZES}; anything else (a stale value,\n * `null` = never chosen) falls through to the next. The one order the pre-paint call, the\n * apply hook and `useAccountAppearance` all use, so the three can never disagree.\n */\nexport function resolveTextSize(device: unknown, account?: unknown): TextSize {\n if (isTextSize(device)) return device;\n if (isTextSize(account)) return account;\n return \"normal\";\n}\n\n/* ── <html data-text-size> and the subscribers that read it ─────────────── */\n\nconst listeners = new Set<() => void>();\nlet observer: MutationObserver | null = null;\n\nfunction notify(): void {\n for (const listener of listeners) listener();\n}\n\nfunction subscribe(listener: () => void): () => void {\n listeners.add(listener);\n // Also catches writers that are not this module — the inline boot snippet, an app\n // setting the attribute by hand, a test.\n if (!observer && typeof MutationObserver !== \"undefined\" && typeof document !== \"undefined\") {\n observer = new MutationObserver(notify);\n observer.observe(document.documentElement, { attributes: true, attributeFilter: [TEXT_SIZE_ATTRIBUTE] });\n }\n return () => {\n listeners.delete(listener);\n if (listeners.size === 0) {\n observer?.disconnect();\n observer = null;\n }\n };\n}\n\n/** The size `<html>` carries now; Normal without one (or outside a browser). */\nexport function readTextSize(): TextSize {\n if (typeof document === \"undefined\") return \"normal\";\n const value = document.documentElement.getAttribute(TEXT_SIZE_ATTRIBUTE);\n return isTextSize(value) ? value : \"normal\";\n}\n\n/** Put `size` on `<html>`. Every {@link useTextSize} re-renders with it. */\nexport function applyTextSize(size: TextSize): void {\n if (typeof document === \"undefined\") return;\n const root = document.documentElement;\n if (root.getAttribute(TEXT_SIZE_ATTRIBUTE) === size) return;\n root.setAttribute(TEXT_SIZE_ATTRIBUTE, size);\n notify();\n}\n\nexport interface TextSizeInfo {\n size: TextSize;\n /** {@link TEXT_SCALE} for `size`: 1, 1.25 or 1.5. */\n scale: number;\n}\n\n/**\n * The size in force on this page, and its scale (§3.1) — read from `<html>`, so it needs\n * no store and works in every kit component: whoever applied the size (the app's store,\n * the pre-paint call, the inline snippet), this follows it.\n *\n * Only for what CSS cannot do. A class that should differ at Large is a `large:`\n * variant; a layout switch is a breakpoint, which already scales.\n */\nexport function useTextSize(): TextSizeInfo {\n const size = useSyncExternalStore(subscribe, readTextSize, () => \"normal\" as const);\n return useMemo(() => ({ size, scale: TEXT_SCALE[size] }), [size]);\n}\n\n/* ── Storage: the frozen format, the pre-paint call ─────────────────────── */\n\n/**\n * What a text-size store persists under its key — zustand's persist envelope, and FROZEN\n * (§10.3) because an app's inline `<head>` snippet reads it before any module loads:\n *\n * {\"state\":{\"size\":\"large\"},\"version\":1}\n *\n * `size` is one of {@link TEXT_SIZES}, or `null` / absent when this device never chose.\n * A future change adds a key; it never renames `state.size` or changes its values.\n *\n * A hand-written seed (a test, a screenshot script) must carry `\"version\":1`: the store\n * drops a stored state of another version as a migration it doesn't know, silently\n * (keksdose's 0.32 report). The inline snippet reads `state.size` whatever the version,\n * so the two would disagree. In the kit's showcase, `?text-size=` needs no seed.\n */\nexport interface PersistedTextSize {\n state?: { size?: TextSize | null };\n version?: number;\n}\n\n/** This device's own choice under `storageKey`, or `null` when it never chose (or the\n * storage is blocked, malformed, or holds a value that is not a size). */\nexport function readPersistedTextSize(storageKey: string): TextSize | null {\n try {\n const blob = JSON.parse(readStored(storageKey) ?? \"null\") as PersistedTextSize | null;\n const size = blob?.state?.size;\n return isTextSize(size) ? size : null;\n } catch {\n return null;\n }\n}\n\nexport interface PersistedAppearanceOptions {\n /**\n * The account's last known value, for a device without a choice of its own (§10.3):\n * what the app persisted with its user (keksdose keeps `/auth/me` in localStorage), so\n * a cold boot paints the account's size instead of Normal and then jumping — offline\n * too. Called once, guarded: a throw counts as \"no account value\".\n */\n account?: () => string | null | undefined;\n}\n\nfunction readAccount(account: PersistedAppearanceOptions[\"account\"]): unknown {\n if (!account) return undefined;\n try {\n return account();\n } catch {\n return undefined;\n }\n}\n\n/**\n * Pre-paint (§3.1, §10.3): read this device's choice under `storageKey` — else the\n * account's last known value — and put it on `<html>` BEFORE `createRoot`, next to\n * `applyPersistedTheme`, so the first paint already has the right size. Returns the size\n * applied.\n *\n * ```ts\n * applyPersistedTextSize(\"keksdose-text-size\", {\n * account: () => readPersistedUser()?.text_size,\n * });\n * ```\n */\nexport function applyPersistedTextSize(storageKey: string, options: PersistedAppearanceOptions = {}): TextSize {\n const size = resolveTextSize(readPersistedTextSize(storageKey), readAccount(options.account));\n applyTextSize(size);\n return size;\n}\n\n/**\n * The same pre-paint as {@link applyPersistedTextSize}, as an inline `<head>` script for\n * a boot splash painted from `index.html` before any module runs (§10.3). A function\n * EXPRESSION: call it with the storage key and, optionally, a function returning the\n * account's last known value.\n *\n * ```html\n * <script>\n * (function(k,a){…})(\"keksdose-text-size\", function () {\n * return JSON.parse(localStorage.getItem(\"keksdose-auth\")).state.user.text_size;\n * });\n * </script>\n * ```\n *\n * Paste the constant's value in place of `(function(k,a){…})`. It reads the frozen\n * {@link PersistedTextSize} format, never throws, and sets only `data-text-size`.\n *\n * The splash sizes in rem, and needs the root rules inline beside it, since the app's\n * stylesheet is a separate request and arrives after the splash paints (0.32.1,\n * keksdose's 0.32 report: that is every app, not an edge case):\n *\n * ```html\n * <style>html[data-text-size=large]{font-size:125%}html[data-text-size=xlarge]{font-size:150%}</style>\n * ```\n *\n * Under a hash-based Content Security Policy (`script-src 'sha256-…'`) this is a second\n * inline script with its own hash: add it to the policy, and recompute it whenever the\n * storage key or the account function in the call changes (keksdose added it to both\n * its Caddyfiles, and its guard test hashes every inline script).\n */\nexport const TEXT_SIZE_INLINE_SCRIPT =\n \"(function(k,a){function ok(v){return v==='normal'||v==='large'||v==='xlarge'}\" +\n \"var v=null;try{var s=JSON.parse(localStorage.getItem(k)||'null');v=s&&s.state&&s.state.size}catch(e){}\" +\n \"if(!ok(v)){v=null;try{v=a?a():null}catch(e){}}\" +\n \"try{document.documentElement.setAttribute('data-text-size',ok(v)?v:'normal')}catch(e){}})\";\n\n/* ── The store ──────────────────────────────────────────────────────────── */\n\nexport interface TextSizeState {\n /** This device's own choice (persisted), or `null` when it never chose — then the\n * account's value applies (§2.2). */\n size: TextSize | null;\n /** Store this device's choice; `null` forgets it, so the account's applies again. */\n setSize: (size: TextSize | null) => void;\n}\n\nexport interface ApplyTextSizeOptions {\n /** The account's value (`/auth/me`'s `text_size`): it applies while this device has no\n * choice of its own. Leave it out where there is no account. */\n account?: string | null;\n}\n\n/**\n * Build a text-size store bound to a consumer-supplied localStorage key, shaped like\n * `createThemeStore` (§6). It holds the DEVICE's choice only; the account's value comes\n * in through `useApplyTextSize({ account })` and `useAccountAppearance`, and the size in\n * force is always {@link resolveTextSize} of the two.\n *\n * - `useTextSizeStore` — the zustand hook: `size` (device choice or null) and `setSize`.\n * - `useApplyTextSize({ account })` — the effect that puts the size in force on `<html>`.\n * Mount it once near the root, beside `useApplyTheme`.\n *\n * The persisted format is {@link PersistedTextSize}, and frozen.\n */\nexport function createTextSizeStore(storageKey: string) {\n const useTextSizeStore = create<TextSizeState>()(\n logger(\n persist(\n (set) => ({\n size: null,\n setSize: (size) => set({ size: isTextSize(size) ? size : null }),\n }),\n {\n name: storageKey,\n version: 1,\n partialize: (s) => ({ size: s.size }),\n // A hand-edited or future value must not reach <html> as an unknown size.\n merge: (persisted, current) => ({\n ...current,\n size: isTextSize((persisted as { size?: unknown } | null)?.size)\n ? ((persisted as { size: TextSize }).size)\n : null,\n }),\n },\n ),\n \"text-size\",\n ),\n );\n // Reset this device's settings (docs/settings-harmonization.md §11.4): no choice on\n // this device, so `useApplyTextSize` re-resolves to the account's size, else Normal.\n registerDeviceSetting({\n key: storageKey,\n kind: \"appearance\",\n reset: () => useTextSizeStore.getState().setSize(null),\n });\n\n function useApplyTextSize({ account }: ApplyTextSizeOptions = {}): TextSize {\n const device = useTextSizeStore((s) => s.size);\n const size = resolveTextSize(device, account);\n useEffect(() => {\n applyTextSize(size);\n }, [size]);\n return size;\n }\n\n return { useTextSizeStore, useApplyTextSize };\n}\n\nexport type TextSizeStore = ReturnType<typeof createTextSizeStore>;\n"],"mappings":";AAAA,SAAS,WAAW,SAAS,4BAA4B;AACzD,SAAS,cAAc;AACvB,SAAS,eAAe;AACxB,SAAS,cAAc;AACvB,SAAS,kBAAkB;AAC3B,SAAS,6BAA6B;AAkB/B,MAAM,aAAa,CAAC,UAAU,SAAS,QAAQ;AAO/C,MAAM,aAAiD,EAAE,QAAQ,GAAG,OAAO,MAAM,QAAQ,IAAI;AAGpG,MAAM,sBAAsB;AAErB,SAAS,WAAW,OAAmC;AAC5D,SAAO,UAAU,YAAY,UAAU,WAAW,UAAU;AAC9D;AAQO,SAAS,gBAAgB,QAAiB,SAA6B;AAC5E,MAAI,WAAW,MAAM,EAAG,QAAO;AAC/B,MAAI,WAAW,OAAO,EAAG,QAAO;AAChC,SAAO;AACT;AAIA,MAAM,YAAY,oBAAI,IAAgB;AACtC,IAAI,WAAoC;AAExC,SAAS,SAAe;AACtB,aAAW,YAAY,UAAW,UAAS;AAC7C;AAEA,SAAS,UAAU,UAAkC;AACnD,YAAU,IAAI,QAAQ;AAGtB,MAAI,CAAC,YAAY,OAAO,qBAAqB,eAAe,OAAO,aAAa,aAAa;AAC3F,eAAW,IAAI,iBAAiB,MAAM;AACtC,aAAS,QAAQ,SAAS,iBAAiB,EAAE,YAAY,MAAM,iBAAiB,CAAC,mBAAmB,EAAE,CAAC;AAAA,EACzG;AACA,SAAO,MAAM;AACX,cAAU,OAAO,QAAQ;AACzB,QAAI,UAAU,SAAS,GAAG;AACxB,gBAAU,WAAW;AACrB,iBAAW;AAAA,IACb;AAAA,EACF;AACF;AAGO,SAAS,eAAyB;AACvC,MAAI,OAAO,aAAa,YAAa,QAAO;AAC5C,QAAM,QAAQ,SAAS,gBAAgB,aAAa,mBAAmB;AACvE,SAAO,WAAW,KAAK,IAAI,QAAQ;AACrC;AAGO,SAA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MAAM,WAAY,WAAyC,IAAI,IACzD,UAAiC,OACnC;AAAA,UACN;AAAA,QACF;AAAA,MACF;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAGA,wBAAsB;AAAA,IACpB,KAAK;AAAA,IACL,MAAM;AAAA,IACN,OAAO,MAAM,iBAAiB,SAAS,EAAE,QAAQ,IAAI;AAAA,EACvD,CAAC;AAED,WAAS,iBAAiB,EAAE,QAAQ,IAA0B,CAAC,GAAa;AAC1E,UAAM,SAAS,iBAAiB,CAAC,MAAM,EAAE,IAAI;AAC7C,UAAM,OAAO,gBAAgB,QAAQ,OAAO;AAC5C,cAAU,MAAM;AACd,oBAAc,IAAI;AAAA,IACpB,GAAG,CAAC,IAAI,CAAC;AACT,WAAO;AAAA,EACT;AAEA,SAAO,EAAE,kBAAkB,iBAAiB;AAC9C;","names":[]}
|
|
@@ -3,6 +3,7 @@ import { useEffect } from "react";
|
|
|
3
3
|
import { create } from "zustand";
|
|
4
4
|
import { persist } from "zustand/middleware";
|
|
5
5
|
import { logger } from "../lib/logger.js";
|
|
6
|
+
import { registerDeviceSetting } from "../lib/device-settings.js";
|
|
6
7
|
function systemPreference() {
|
|
7
8
|
try {
|
|
8
9
|
return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
@@ -68,6 +69,11 @@ function createThemeStore(storageKey) {
|
|
|
68
69
|
"theme"
|
|
69
70
|
)
|
|
70
71
|
);
|
|
72
|
+
registerDeviceSetting({
|
|
73
|
+
key: storageKey,
|
|
74
|
+
kind: "appearance",
|
|
75
|
+
reset: () => useTheme.getState().setPreference("system")
|
|
76
|
+
});
|
|
71
77
|
function useApplyTheme() {
|
|
72
78
|
const mode = useTheme((s) => s.mode);
|
|
73
79
|
const preference = useTheme((s) => s.preference);
|