@behavioral-agentic-design-system/core 0.5.0 → 0.7.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/LICENSE +21 -0
- package/package.json +39 -7
- package/scripts/bads-sync.mjs +1 -1
- package/scripts/build-fonts.cjs +97 -0
- package/scripts/build-tokens.cjs +202 -10
- package/src/api/brand-fonts.ts +301 -0
- package/src/api/brand-mark.ts +146 -0
- package/src/api/layers/file.ts +8 -5
- package/src/api/layers.ts +27 -4
- package/src/api/site-auth.ts +50 -0
- package/src/app/preview/cards/page.tsx +1 -1
- package/src/app/preview/components/page.tsx +78 -1
- package/src/app/preview/icons/page.tsx +5 -0
- package/src/app/shell.tsx +105 -39
- package/src/app/site-login/page.tsx +82 -0
- package/src/brand-fonts.css +5 -0
- package/src/components/Foundations/Motion.stories.tsx +66 -0
- package/src/components/brand-mark.tsx +64 -0
- package/src/components/customize/brand-mark-section.tsx +265 -0
- package/src/components/customize/font-pickers.tsx +293 -0
- package/src/components/customize/letter-spacing.tsx +3 -2
- package/src/components/customize/save-bar.tsx +11 -5
- package/src/components/customize/type-scale.tsx +3 -2
- package/src/components/customize-tab.tsx +330 -24
- package/src/components/dev-identity-badge.tsx +92 -0
- package/src/components/home-tab.tsx +1291 -380
- package/src/components/layers-tab.tsx +179 -12
- package/src/components/ui/alert.tsx +10 -2
- package/src/components/ui/bottom-sheet.tsx +124 -0
- package/src/components/ui/button.tsx +2 -2
- package/src/components/ui/calendar.tsx +1 -1
- package/src/components/ui/chart.tsx +118 -7
- package/src/components/ui/checkbox.tsx +3 -2
- package/src/components/ui/dialog.tsx +3 -3
- package/src/components/ui/index.ts +1 -0
- package/src/components/ui/radio-group.tsx +4 -3
- package/src/components/ui/sheet.tsx +1 -1
- package/src/components/ui/sidebar.tsx +6 -1
- package/src/components/ui/sonner.tsx +18 -0
- package/src/components/ui/switch.tsx +9 -3
- package/src/components/ui/tabs.tsx +7 -1
- package/src/fonts/HyperlegibleSans-Bold.woff2 +0 -0
- package/src/fonts/HyperlegibleSans-BoldItalic.woff2 +0 -0
- package/src/fonts/HyperlegibleSans-Italic.woff2 +0 -0
- package/src/fonts/HyperlegibleSans-Medium.woff2 +0 -0
- package/src/fonts/HyperlegibleSans-MediumItalic.woff2 +0 -0
- package/src/fonts/HyperlegibleSans-Regular.woff2 +0 -0
- package/src/fonts/InterVariable-Italic.woff2 +0 -0
- package/src/fonts/InterVariable.woff2 +0 -0
- package/src/fonts.css +99 -0
- package/src/hooks/use-global-brand-mark.ts +64 -0
- package/src/hooks/use-global-mono-font.ts +13 -3
- package/src/hooks/use-global-primary-color.ts +192 -9
- package/src/hooks/use-global-sans-font.ts +5 -3
- package/src/hooks/use-global-serif-font.ts +13 -3
- package/src/lib/storage.ts +29 -0
- package/src/lib/svg-sanitize.ts +272 -0
- package/src/styles.css +126 -6
- package/src/tokens.json +100 -9
- package/src/app/preview/mail/page.tsx +0 -4
- package/src/app/preview/pricing/page.tsx +0 -4
|
@@ -214,7 +214,12 @@ const Sidebar = React.forwardRef<
|
|
|
214
214
|
>
|
|
215
215
|
<div
|
|
216
216
|
className={cn(
|
|
217
|
-
|
|
217
|
+
// h-svh forces the sticky container to span the viewport even
|
|
218
|
+
// when the sidebar's contents are shorter than the screen.
|
|
219
|
+
// Without it, the bg-sidebar collapses to content height and the
|
|
220
|
+
// area below the footer reads as empty white space — looks like
|
|
221
|
+
// the sidebar "didn't fill" the panel.
|
|
222
|
+
"sticky top-0 hidden h-svh w-[var(--sidebar-width)] transition-[width,transform] duration-200 ease-linear md:flex",
|
|
218
223
|
side === "left"
|
|
219
224
|
? "group-data-[collapsible=offcanvas]:-translate-x-full"
|
|
220
225
|
: "right-0 group-data-[collapsible=offcanvas]:translate-x-full",
|
|
@@ -32,6 +32,24 @@ const Toaster = ({ ...props }: ToasterProps) => {
|
|
|
32
32
|
"--border-radius": "var(--radius)",
|
|
33
33
|
} as React.CSSProperties
|
|
34
34
|
}
|
|
35
|
+
toastOptions={{
|
|
36
|
+
classNames: {
|
|
37
|
+
// border-foreground/10 + shadow-lg gives the toast a visible edge
|
|
38
|
+
// regardless of where --border lands on the fork's palette. Sonner's
|
|
39
|
+
// default leans on --border, which can be invisible on tonal forks.
|
|
40
|
+
toast:
|
|
41
|
+
"group toast group-[.toaster]:bg-popover group-[.toaster]:text-popover-foreground group-[.toaster]:border group-[.toaster]:border-foreground/10 group-[.toaster]:shadow-lg",
|
|
42
|
+
title: "text-base font-semibold",
|
|
43
|
+
// Sonner sets description opacity low by default — override with an
|
|
44
|
+
// explicit muted-foreground token so it reads at every brightness.
|
|
45
|
+
description:
|
|
46
|
+
"text-sm text-muted-foreground leading-relaxed group-[.toast]:text-muted-foreground",
|
|
47
|
+
actionButton:
|
|
48
|
+
"group-[.toast]:bg-primary group-[.toast]:text-primary-foreground",
|
|
49
|
+
cancelButton:
|
|
50
|
+
"group-[.toast]:bg-muted group-[.toast]:text-muted-foreground",
|
|
51
|
+
},
|
|
52
|
+
}}
|
|
35
53
|
{...props}
|
|
36
54
|
/>
|
|
37
55
|
)
|
|
@@ -18,19 +18,25 @@ function Switch({
|
|
|
18
18
|
data-slot="switch"
|
|
19
19
|
data-size={size}
|
|
20
20
|
className={cn(
|
|
21
|
-
"peer group/switch relative inline-flex shrink-0 items-center rounded-full border border-transparent shadow-xs transition-
|
|
21
|
+
"peer group/switch relative inline-flex shrink-0 items-center rounded-full border border-transparent shadow-xs transition-[background-color] duration-[210ms] ease-in-out outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-[2.3rem] data-[size=default]:w-16 data-[size=sm]:h-7 data-[size=sm]:w-12 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input dark:data-[state=unchecked]:bg-input/80",
|
|
22
22
|
className
|
|
23
23
|
)}
|
|
24
24
|
{...props}
|
|
25
25
|
>
|
|
26
26
|
<CheckIcon
|
|
27
27
|
strokeWidth={3}
|
|
28
|
-
className="pointer-events-none absolute left-2 size-4 text-primary-foreground opacity-0 scale-
|
|
28
|
+
className="pointer-events-none absolute left-2 size-4 text-primary-foreground opacity-0 scale-75 transition-[opacity,transform] duration-[120ms] ease-out group-data-[state=checked]/switch:opacity-100 group-data-[state=checked]/switch:scale-100"
|
|
29
29
|
/>
|
|
30
30
|
<SwitchPrimitive.Thumb
|
|
31
31
|
data-slot="switch-thumb"
|
|
32
32
|
className={cn(
|
|
33
|
-
|
|
33
|
+
// bg-white works against the gray unchecked track in both modes,
|
|
34
|
+
// but fails against the near-white --primary track in dark-mode
|
|
35
|
+
// checked state. Switch to bg-primary-foreground when checked so
|
|
36
|
+
// the thumb always contrasts the track: near-white thumb on
|
|
37
|
+
// near-black track in light, near-black thumb on near-white
|
|
38
|
+
// track in dark.
|
|
39
|
+
"pointer-events-none block rounded-full bg-white data-[state=checked]:bg-primary-foreground ring-0 shadow-sm transition-[translate,background-color] duration-[175ms] ease-[cubic-bezier(0.25,0.46,0.45,0.94)] group-data-[size=default]/switch:size-8 group-data-[size=sm]/switch:size-6 data-[state=checked]:translate-x-[calc(100%-4px)] data-[state=unchecked]:translate-x-[2px]"
|
|
34
40
|
)}
|
|
35
41
|
/>
|
|
36
42
|
</SwitchPrimitive.Root>
|
|
@@ -64,7 +64,13 @@ function TabsTrigger({
|
|
|
64
64
|
<TabsPrimitive.Trigger
|
|
65
65
|
data-slot="tabs-trigger"
|
|
66
66
|
className={cn(
|
|
67
|
-
|
|
67
|
+
// Active-state text uses --foreground rather than --accent-foreground.
|
|
68
|
+
// The runtime brand-picker (use-global-primary-color → pickAccentForeground)
|
|
69
|
+
// already guards --accent-foreground against AAA failures, but
|
|
70
|
+
// --foreground vs --accent is structurally safe in every theme
|
|
71
|
+
// (~13:1 dark, ~20:1 light) and matches the Calendar range-middle
|
|
72
|
+
// pattern, so nested tabs can never regress on brand swaps.
|
|
73
|
+
"inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-xs font-medium text-muted-foreground hover:text-foreground ring-offset-background transition-all focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-accent data-[state=active]:text-foreground data-[state=active]:shadow-xs",
|
|
68
74
|
className
|
|
69
75
|
)}
|
|
70
76
|
{...props}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/src/fonts.css
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/* @behavioral-agentic-design-system/core — canonical brand fonts.
|
|
2
|
+
*
|
|
3
|
+
* Static, hand-maintained @font-face block for the SIL OFL-licensed
|
|
4
|
+
* defaults that ship with the package (currently Hyperlegible Sans, 6
|
|
5
|
+
* weights). The .woff2 binaries live in ./fonts/ inside the published
|
|
6
|
+
* tarball.
|
|
7
|
+
*
|
|
8
|
+
* URLs resolve to /fonts/<file>.woff2 at runtime — the consumer is
|
|
9
|
+
* responsible for copying the binaries from
|
|
10
|
+
* `node_modules/@behavioral-agentic-design-system/core/fonts/` into
|
|
11
|
+
* their own `public/fonts/` so Next.js (or any static host) serves them
|
|
12
|
+
* at the expected path. See CLIENT_ONBOARDING.md → "Shipping fonts" for
|
|
13
|
+
* the canonical postinstall recipe.
|
|
14
|
+
*
|
|
15
|
+
* Styles.css `@import`s this file automatically — consumers don't need
|
|
16
|
+
* to import it themselves. Brand-uploaded faces (Season, custom client
|
|
17
|
+
* fonts) live in the generated companion file `./brand-fonts.css`,
|
|
18
|
+
* also auto-imported.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/* ============================================================
|
|
22
|
+
* Inter — primary sans (SIL OFL 1.1), VARIABLE.
|
|
23
|
+
* A single woff2 per style covers the full 100–900 weight axis, so
|
|
24
|
+
* font-weight resolves continuously and forks can tune the wght/opsz
|
|
25
|
+
* axes via --font-variation-settings (tokens.json → fontVariationSettings)
|
|
26
|
+
* without shipping extra files. Latin subset (wght axis). Source:
|
|
27
|
+
* fontsource Inter VF. font-display: swap to avoid invisible text.
|
|
28
|
+
* https://rsms.me/inter/
|
|
29
|
+
* ============================================================ */
|
|
30
|
+
@font-face {
|
|
31
|
+
font-family: 'Inter';
|
|
32
|
+
src: url('/fonts/InterVariable.woff2') format('woff2');
|
|
33
|
+
font-weight: 100 900;
|
|
34
|
+
font-style: normal;
|
|
35
|
+
font-display: swap;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@font-face {
|
|
39
|
+
font-family: 'Inter';
|
|
40
|
+
src: url('/fonts/InterVariable-Italic.woff2') format('woff2');
|
|
41
|
+
font-weight: 100 900;
|
|
42
|
+
font-style: italic;
|
|
43
|
+
font-display: swap;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/* ============================================================
|
|
47
|
+
* Hyperlegible Sans — accessibility-preserving fallback (SIL OFL 1.1).
|
|
48
|
+
* The Braille Institute's low-vision face. Stays self-hosted and second
|
|
49
|
+
* in the --font-sans stack so a low-vision-heavy fork can reorder
|
|
50
|
+
* tokens.json fontFamily.sans to lead with it. Static weights.
|
|
51
|
+
* https://www.brailleinstitute.org/freefont
|
|
52
|
+
* ============================================================ */
|
|
53
|
+
@font-face {
|
|
54
|
+
font-family: 'Hyperlegible Sans';
|
|
55
|
+
src: url('/fonts/HyperlegibleSans-Regular.woff2') format('woff2');
|
|
56
|
+
font-weight: 400;
|
|
57
|
+
font-style: normal;
|
|
58
|
+
font-display: swap;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@font-face {
|
|
62
|
+
font-family: 'Hyperlegible Sans';
|
|
63
|
+
src: url('/fonts/HyperlegibleSans-Italic.woff2') format('woff2');
|
|
64
|
+
font-weight: 400;
|
|
65
|
+
font-style: italic;
|
|
66
|
+
font-display: swap;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
@font-face {
|
|
70
|
+
font-family: 'Hyperlegible Sans';
|
|
71
|
+
src: url('/fonts/HyperlegibleSans-Medium.woff2') format('woff2');
|
|
72
|
+
font-weight: 500;
|
|
73
|
+
font-style: normal;
|
|
74
|
+
font-display: swap;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
@font-face {
|
|
78
|
+
font-family: 'Hyperlegible Sans';
|
|
79
|
+
src: url('/fonts/HyperlegibleSans-MediumItalic.woff2') format('woff2');
|
|
80
|
+
font-weight: 500;
|
|
81
|
+
font-style: italic;
|
|
82
|
+
font-display: swap;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@font-face {
|
|
86
|
+
font-family: 'Hyperlegible Sans';
|
|
87
|
+
src: url('/fonts/HyperlegibleSans-Bold.woff2') format('woff2');
|
|
88
|
+
font-weight: 700;
|
|
89
|
+
font-style: normal;
|
|
90
|
+
font-display: swap;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
@font-face {
|
|
94
|
+
font-family: 'Hyperlegible Sans';
|
|
95
|
+
src: url('/fonts/HyperlegibleSans-BoldItalic.woff2') format('woff2');
|
|
96
|
+
font-weight: 700;
|
|
97
|
+
font-style: italic;
|
|
98
|
+
font-display: swap;
|
|
99
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useSyncExternalStore } from "react";
|
|
4
|
+
import { brand } from "@/brand.config";
|
|
5
|
+
import { storageKey } from "@behavioral-agentic-design-system/core/lib/storage";
|
|
6
|
+
|
|
7
|
+
const STORAGE_KEY = storageKey("brandMarkSvg");
|
|
8
|
+
const CLEAR_SENTINEL = "__NONE__";
|
|
9
|
+
const CHANGE_EVENT = "bads-brand-mark-change";
|
|
10
|
+
|
|
11
|
+
function readStoredSvg(): string | null {
|
|
12
|
+
if (typeof window === "undefined") {
|
|
13
|
+
return brand.logo?.svg ?? null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const raw = window.localStorage.getItem(STORAGE_KEY);
|
|
17
|
+
if (raw === CLEAR_SENTINEL) return null;
|
|
18
|
+
if (raw !== null) return raw;
|
|
19
|
+
return brand.logo?.svg ?? null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function subscribe(callback: () => void) {
|
|
23
|
+
if (typeof window === "undefined") {
|
|
24
|
+
return () => {};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const onStorage = (event: StorageEvent) => {
|
|
28
|
+
if (event.key === STORAGE_KEY) callback();
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const onChange = () => callback();
|
|
32
|
+
|
|
33
|
+
window.addEventListener("storage", onStorage);
|
|
34
|
+
window.addEventListener(CHANGE_EVENT, onChange);
|
|
35
|
+
|
|
36
|
+
return () => {
|
|
37
|
+
window.removeEventListener("storage", onStorage);
|
|
38
|
+
window.removeEventListener(CHANGE_EVENT, onChange);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function setStoredSvg(value: string | null) {
|
|
43
|
+
if (typeof window === "undefined") return;
|
|
44
|
+
|
|
45
|
+
if (value === null) {
|
|
46
|
+
window.localStorage.setItem(STORAGE_KEY, CLEAR_SENTINEL);
|
|
47
|
+
} else {
|
|
48
|
+
window.localStorage.setItem(STORAGE_KEY, value);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
window.dispatchEvent(new Event(CHANGE_EVENT));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function useGlobalBrandMarkSvg() {
|
|
55
|
+
return useSyncExternalStore(subscribe, readStoredSvg, () => brand.logo?.svg ?? null);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function setGlobalBrandMarkSvg(svg: string | null) {
|
|
59
|
+
setStoredSvg(svg);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function clearGlobalBrandMarkSvg() {
|
|
63
|
+
setStoredSvg(null);
|
|
64
|
+
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import { useCallback, useEffect, useState } from "react";
|
|
4
|
+
import { brand } from "@/brand.config";
|
|
4
5
|
|
|
5
|
-
export
|
|
6
|
+
export type MonoFontOption = { label: string; stack: string };
|
|
7
|
+
|
|
8
|
+
const BASE_MONO_FONTS: Record<string, MonoFontOption> = {
|
|
6
9
|
jetbrains: {
|
|
7
10
|
label: "JetBrains Mono",
|
|
8
11
|
stack: "var(--font-jetbrains), 'JetBrains Mono', ui-monospace, monospace",
|
|
@@ -19,9 +22,16 @@ export const MONO_FONT_OPTIONS = {
|
|
|
19
22
|
label: "System Mono",
|
|
20
23
|
stack: "ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace",
|
|
21
24
|
},
|
|
22
|
-
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// Brand fonts marked `kind: "mono"` come first.
|
|
28
|
+
const MONO_BRAND_FONTS = brand.fonts.filter((f) => f.kind === "mono");
|
|
29
|
+
export const MONO_FONT_OPTIONS: Record<string, MonoFontOption> = {
|
|
30
|
+
...Object.fromEntries(MONO_BRAND_FONTS.map((f) => [f.id, { label: f.label, stack: f.stack }])),
|
|
31
|
+
...BASE_MONO_FONTS,
|
|
32
|
+
};
|
|
23
33
|
|
|
24
|
-
export type MonoFontKey =
|
|
34
|
+
export type MonoFontKey = string;
|
|
25
35
|
|
|
26
36
|
import { storageKey, readMigrated } from "@behavioral-agentic-design-system/core/lib/storage";
|
|
27
37
|
|
|
@@ -163,13 +163,65 @@ const PRIMARY_OVERRIDE_VARIABLES = [
|
|
|
163
163
|
"--sidebar-primary",
|
|
164
164
|
"--sidebar-primary-foreground",
|
|
165
165
|
"--sidebar-ring",
|
|
166
|
-
// Chart vars are
|
|
167
|
-
//
|
|
168
|
-
//
|
|
169
|
-
//
|
|
170
|
-
//
|
|
166
|
+
// Chart vars are written inline by applyColor / writeChartRamp below.
|
|
167
|
+
// The stylesheet rule (oklch(from var(--primary) ...)) emitted by
|
|
168
|
+
// build-tokens.cjs gets precompiled by Next 16's Lightning CSS into a
|
|
169
|
+
// static lab() fallback that wins on every modern browser. Writing
|
|
170
|
+
// inline forces runtime resolution against the live --primary so picker
|
|
171
|
+
// changes actually reach charts.
|
|
172
|
+
"--chart-1",
|
|
173
|
+
"--chart-2",
|
|
174
|
+
"--chart-3",
|
|
175
|
+
"--chart-4",
|
|
176
|
+
"--chart-5",
|
|
171
177
|
];
|
|
172
178
|
|
|
179
|
+
// Chart ramp constants — mirror tokens.json → chart.lightness / hueRotation /
|
|
180
|
+
// chroma2Damping. Update both files together when retuning the chart palette.
|
|
181
|
+
const CHART_LIGHTNESS_LIGHT = 0.58;
|
|
182
|
+
const CHART_LIGHTNESS_DARK = 0.78;
|
|
183
|
+
const CHART_HUE_ROTATIONS = [0, 35, 70, 105, 140] as const;
|
|
184
|
+
const CHART_CHROMA2_DAMPING = 0.65;
|
|
185
|
+
|
|
186
|
+
function readOverriddenChartVars(): Set<string> {
|
|
187
|
+
if (typeof window === "undefined") return new Set();
|
|
188
|
+
try {
|
|
189
|
+
const raw = readMigrated("tokenOverrides");
|
|
190
|
+
if (!raw) return new Set();
|
|
191
|
+
const parsed = JSON.parse(raw) as Record<string, string>;
|
|
192
|
+
if (!parsed || typeof parsed !== "object") return new Set();
|
|
193
|
+
return new Set(Object.keys(parsed).filter((k) => k.startsWith("--chart-")));
|
|
194
|
+
} catch {
|
|
195
|
+
return new Set();
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function writeChartRamp() {
|
|
200
|
+
if (typeof document === "undefined") return;
|
|
201
|
+
const root = document.documentElement;
|
|
202
|
+
const style = root.style;
|
|
203
|
+
const isDark = root.classList.contains("dark");
|
|
204
|
+
const L = isDark ? CHART_LIGHTNESS_DARK : CHART_LIGHTNESS_LIGHT;
|
|
205
|
+
const overridden = readOverriddenChartVars();
|
|
206
|
+
for (let i = 0; i < 5; i++) {
|
|
207
|
+
const name = `--chart-${i + 1}`;
|
|
208
|
+
if (overridden.has(name)) continue;
|
|
209
|
+
const hue = CHART_HUE_ROTATIONS[i];
|
|
210
|
+
const chroma = i === 1 ? `calc(c * ${CHART_CHROMA2_DAMPING})` : "c";
|
|
211
|
+
style.setProperty(name, `oklch(from var(--primary) ${L} ${chroma} calc(h + ${hue}))`);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Re-evaluate the chart ramp against the current --primary and dark-mode
|
|
217
|
+
* state. Called when the user resets a chart-N override so the cleared
|
|
218
|
+
* variable falls back to the brand-derived ramp instead of the frozen
|
|
219
|
+
* build-time lab() value Lightning CSS precomputed.
|
|
220
|
+
*/
|
|
221
|
+
export function reapplyChartRamp(): void {
|
|
222
|
+
writeChartRamp();
|
|
223
|
+
}
|
|
224
|
+
|
|
173
225
|
function buildCustom(hex: string, label?: string): PrimaryColorOption {
|
|
174
226
|
const requested = normalizeHex(hex);
|
|
175
227
|
// No more contrast-adjusting. Apply the color as-is and surface a WCAG
|
|
@@ -232,13 +284,76 @@ function applyColor(opt: PrimaryColorOption) {
|
|
|
232
284
|
root.setProperty("--primary", opt.primary);
|
|
233
285
|
root.setProperty("--primary-foreground", opt.primaryForeground);
|
|
234
286
|
root.setProperty("--ring", opt.primary);
|
|
235
|
-
|
|
287
|
+
|
|
288
|
+
// --accent-foreground used to be set unconditionally to opt.primary. That
|
|
289
|
+
// produced silent contrast failures when the brand color was too close in
|
|
290
|
+
// luminance to the dark-mode accent surface (the wcag-audit script can't
|
|
291
|
+
// see runtime overrides, so this bug stayed hidden). Now we read the live
|
|
292
|
+
// --accent value, compute contrast for both candidates (brand color +
|
|
293
|
+
// brand-foreground), and pick whichever passes AAA. If neither does, we
|
|
294
|
+
// skip the override and let the stylesheet default win — it's already
|
|
295
|
+
// luminance-tuned.
|
|
296
|
+
const accentFg = pickAccentForeground(opt);
|
|
297
|
+
if (accentFg) {
|
|
298
|
+
root.setProperty("--accent-foreground", accentFg);
|
|
299
|
+
} else {
|
|
300
|
+
root.removeProperty("--accent-foreground");
|
|
301
|
+
}
|
|
302
|
+
|
|
236
303
|
root.setProperty("--sidebar-primary", opt.primary);
|
|
237
304
|
root.setProperty("--sidebar-primary-foreground", opt.primaryForeground);
|
|
238
305
|
root.setProperty("--sidebar-ring", opt.primary);
|
|
239
|
-
//
|
|
240
|
-
//
|
|
241
|
-
|
|
306
|
+
// Inline-write the chart ramp so brand picker changes reach charts. The
|
|
307
|
+
// stylesheet rule is precomputed by Lightning CSS into a frozen lab().
|
|
308
|
+
writeChartRamp();
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const ACCENT_TEXT_FLOOR = 4.5; // AA for text — accent surfaces typically host UI labels, not body.
|
|
312
|
+
|
|
313
|
+
function pickAccentForeground(opt: PrimaryColorOption): string | null {
|
|
314
|
+
if (typeof document === "undefined") return null;
|
|
315
|
+
const accentValue = getComputedStyle(document.documentElement)
|
|
316
|
+
.getPropertyValue("--accent")
|
|
317
|
+
.trim();
|
|
318
|
+
if (!accentValue) return null;
|
|
319
|
+
const accentRgb = parseCssColorToRgb(accentValue);
|
|
320
|
+
if (!accentRgb) return null;
|
|
321
|
+
const candidates: string[] = [opt.primary, opt.primaryForeground];
|
|
322
|
+
for (const cand of candidates) {
|
|
323
|
+
const candRgb = rgbFromHex(cand);
|
|
324
|
+
if (contrastRatio(candRgb, accentRgb) >= ACCENT_TEXT_FLOOR) return cand;
|
|
325
|
+
}
|
|
326
|
+
// Both candidates fail — give up and let the stylesheet default ride.
|
|
327
|
+
return null;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// Parses a computed-style color (hex, rgb(), oklch(), lab()) into [r,g,b].
|
|
331
|
+
// Returns null if the browser hasn't resolved the value or the parse fails.
|
|
332
|
+
function parseCssColorToRgb(value: string): [number, number, number] | null {
|
|
333
|
+
if (typeof document === "undefined") return null;
|
|
334
|
+
// Cheapest path: hex literal.
|
|
335
|
+
if (/^#([0-9a-fA-F]{3,8})$/.test(value)) {
|
|
336
|
+
try {
|
|
337
|
+
return rgbFromHex(value);
|
|
338
|
+
} catch {
|
|
339
|
+
return null;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
// Fall through to canvas: every other CSS color string parses uniformly.
|
|
343
|
+
try {
|
|
344
|
+
const canvas = document.createElement("canvas");
|
|
345
|
+
canvas.width = 1;
|
|
346
|
+
canvas.height = 1;
|
|
347
|
+
const ctx = canvas.getContext("2d");
|
|
348
|
+
if (!ctx) return null;
|
|
349
|
+
ctx.fillStyle = "#000";
|
|
350
|
+
ctx.fillStyle = value;
|
|
351
|
+
ctx.fillRect(0, 0, 1, 1);
|
|
352
|
+
const [r, g, b] = ctx.getImageData(0, 0, 1, 1).data;
|
|
353
|
+
return [r / 255, g / 255, b / 255];
|
|
354
|
+
} catch {
|
|
355
|
+
return null;
|
|
356
|
+
}
|
|
242
357
|
}
|
|
243
358
|
|
|
244
359
|
function applySelectedColor(color: string, options: Record<string, PrimaryColorOption>) {
|
|
@@ -321,6 +436,23 @@ function bootstrap() {
|
|
|
321
436
|
applySelectedColor(next, merged);
|
|
322
437
|
}
|
|
323
438
|
});
|
|
439
|
+
|
|
440
|
+
// Dark-mode toggle: re-evaluate the chart ramp at the new mode's L. The
|
|
441
|
+
// shell toggles `.dark` on documentElement; we observe that class attribute
|
|
442
|
+
// and re-run applySelectedColor so writeChartRamp picks up the new mode.
|
|
443
|
+
const themeObserver = new MutationObserver((mutations) => {
|
|
444
|
+
for (const m of mutations) {
|
|
445
|
+
if (m.attributeName === "class") {
|
|
446
|
+
const merged = { ...BUILTIN_PRIMARY_COLORS, ...snapshot.customs };
|
|
447
|
+
applySelectedColor(snapshot.color, merged);
|
|
448
|
+
break;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
themeObserver.observe(document.documentElement, {
|
|
453
|
+
attributes: true,
|
|
454
|
+
attributeFilter: ["class"],
|
|
455
|
+
});
|
|
324
456
|
}
|
|
325
457
|
|
|
326
458
|
/**
|
|
@@ -388,6 +520,43 @@ export function useGlobalPrimaryColor() {
|
|
|
388
520
|
[],
|
|
389
521
|
);
|
|
390
522
|
|
|
523
|
+
/**
|
|
524
|
+
* Library-only sibling of addCustom. Adds the color to the brand palette
|
|
525
|
+
* so it's available to every swatch picker, but does NOT make it the
|
|
526
|
+
* active primary or apply any brand variables. Used by the per-token
|
|
527
|
+
* swatch popover ("+" tile) where the designer wants a one-off color
|
|
528
|
+
* scoped to a single token without taking over the global theme.
|
|
529
|
+
*
|
|
530
|
+
* Dedup matches addCustom: if the hex is already in the palette, returns
|
|
531
|
+
* the existing id without changing selection state.
|
|
532
|
+
*/
|
|
533
|
+
const addCustomSilent = useCallback(
|
|
534
|
+
(hex: string, label?: string): string | null => {
|
|
535
|
+
if (!isValidHex(hex)) return null;
|
|
536
|
+
const normalized = normalizeHex(hex);
|
|
537
|
+
|
|
538
|
+
const merged: Record<string, PrimaryColorOption> = {
|
|
539
|
+
...BUILTIN_PRIMARY_COLORS,
|
|
540
|
+
...snapshot.customs,
|
|
541
|
+
};
|
|
542
|
+
for (const [existingId, opt] of Object.entries(merged)) {
|
|
543
|
+
if (normalizeHex(opt.primary) === normalized) {
|
|
544
|
+
return existingId;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
const id = `custom-${normalized.slice(1).toLowerCase()}`;
|
|
549
|
+
const opt = buildCustom(normalized, label);
|
|
550
|
+
const customs = { ...snapshot.customs, [id]: opt };
|
|
551
|
+
commit({ ...snapshot, customs });
|
|
552
|
+
if (typeof window !== "undefined") {
|
|
553
|
+
window.localStorage.setItem(CUSTOMS_KEY, JSON.stringify(customs));
|
|
554
|
+
}
|
|
555
|
+
return id;
|
|
556
|
+
},
|
|
557
|
+
[],
|
|
558
|
+
);
|
|
559
|
+
|
|
391
560
|
const removeCustom = useCallback(
|
|
392
561
|
(id: string) => {
|
|
393
562
|
if (!(id in snapshot.customs)) return;
|
|
@@ -535,15 +704,29 @@ export function useGlobalPrimaryColor() {
|
|
|
535
704
|
[],
|
|
536
705
|
);
|
|
537
706
|
|
|
707
|
+
const resetToDefaults = useCallback(() => {
|
|
708
|
+
if (typeof window === "undefined") return;
|
|
709
|
+
window.localStorage.removeItem(COLOR_KEY);
|
|
710
|
+
window.localStorage.removeItem(CUSTOMS_KEY);
|
|
711
|
+
commit({ customs: {}, color: DEFAULT });
|
|
712
|
+
applySelectedColor(DEFAULT, BUILTIN_PRIMARY_COLORS);
|
|
713
|
+
window.location.reload();
|
|
714
|
+
}, []);
|
|
715
|
+
|
|
716
|
+
const isCustomized = state.color !== DEFAULT || Object.keys(state.customs).length > 0;
|
|
717
|
+
|
|
538
718
|
return {
|
|
539
719
|
color: state.color,
|
|
540
720
|
setColor,
|
|
541
721
|
addCustom,
|
|
722
|
+
addCustomSilent,
|
|
542
723
|
removeCustom,
|
|
543
724
|
renameCustom,
|
|
544
725
|
pinCustom,
|
|
545
726
|
removeBuiltin,
|
|
546
727
|
renameBuiltin,
|
|
728
|
+
resetToDefaults,
|
|
729
|
+
isCustomized,
|
|
547
730
|
options,
|
|
548
731
|
customs: state.customs,
|
|
549
732
|
builtins: BUILTIN_PRIMARY_COLORS,
|
|
@@ -32,9 +32,11 @@ const BASE_SANS_FONTS: Record<string, SansFontOption> = {
|
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
// Brand fonts (declared in brand.config.ts) come first in the picker so the
|
|
35
|
-
// client's font is the default and most prominent option.
|
|
35
|
+
// client's font is the default and most prominent option. We filter on
|
|
36
|
+
// `kind === "sans"` (default when omitted, for backward-compat).
|
|
37
|
+
const SANS_BRAND_FONTS = brand.fonts.filter((f) => (f.kind ?? "sans") === "sans");
|
|
36
38
|
export const SANS_FONT_OPTIONS: Record<string, SansFontOption> = {
|
|
37
|
-
...Object.fromEntries(
|
|
39
|
+
...Object.fromEntries(SANS_BRAND_FONTS.map((f) => [f.id, { label: f.label, stack: f.stack }])),
|
|
38
40
|
...BASE_SANS_FONTS,
|
|
39
41
|
};
|
|
40
42
|
|
|
@@ -44,7 +46,7 @@ import { storageKey, readMigrated } from "@behavioral-agentic-design-system/core
|
|
|
44
46
|
|
|
45
47
|
const STORAGE_KEY = storageKey("sansFont");
|
|
46
48
|
// First brand font (if any) wins as the default; otherwise Hyperlegible.
|
|
47
|
-
const DEFAULT: SansFontKey =
|
|
49
|
+
const DEFAULT: SansFontKey = SANS_BRAND_FONTS[0]?.id ?? "hyperlegible";
|
|
48
50
|
|
|
49
51
|
function isValidKey(value: string | null): value is SansFontKey {
|
|
50
52
|
return !!value && value in SANS_FONT_OPTIONS;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import { useCallback, useEffect, useState } from "react";
|
|
4
|
+
import { brand } from "@/brand.config";
|
|
4
5
|
|
|
5
|
-
export
|
|
6
|
+
export type SerifFontOption = { label: string; stack: string };
|
|
7
|
+
|
|
8
|
+
const BASE_SERIF_FONTS: Record<string, SerifFontOption> = {
|
|
6
9
|
georgia: {
|
|
7
10
|
label: "Georgia",
|
|
8
11
|
stack: "Georgia, ui-serif, serif",
|
|
@@ -19,9 +22,16 @@ export const SERIF_FONT_OPTIONS = {
|
|
|
19
22
|
label: "System Serif",
|
|
20
23
|
stack: "ui-serif, Georgia, Cambria, 'Times New Roman', Times, serif",
|
|
21
24
|
},
|
|
22
|
-
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// Brand fonts marked `kind: "serif"` come first.
|
|
28
|
+
const SERIF_BRAND_FONTS = brand.fonts.filter((f) => f.kind === "serif");
|
|
29
|
+
export const SERIF_FONT_OPTIONS: Record<string, SerifFontOption> = {
|
|
30
|
+
...Object.fromEntries(SERIF_BRAND_FONTS.map((f) => [f.id, { label: f.label, stack: f.stack }])),
|
|
31
|
+
...BASE_SERIF_FONTS,
|
|
32
|
+
};
|
|
23
33
|
|
|
24
|
-
export type SerifFontKey =
|
|
34
|
+
export type SerifFontKey = string;
|
|
25
35
|
|
|
26
36
|
import { storageKey, readMigrated } from "@behavioral-agentic-design-system/core/lib/storage";
|
|
27
37
|
|
package/src/lib/storage.ts
CHANGED
|
@@ -41,6 +41,35 @@ export function storageKey(suffix: string): string {
|
|
|
41
41
|
return `${getPrefix()}.${suffix}`;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Wipe every customization key under the runtime prefix (e.g. "BADS.*",
|
|
46
|
+
* "CLAP.*"). The Customize tab's "Reset all" button uses this so a fresh
|
|
47
|
+
* hook adding a new storage key doesn't need to be remembered in a
|
|
48
|
+
* hand-maintained list — anything written via `storageKey()` auto-resets.
|
|
49
|
+
*
|
|
50
|
+
* Pass `keep` to preserve specific suffixes (not full keys). Default keeps
|
|
51
|
+
* the light/dark `theme` key because that's a UI preference, not a
|
|
52
|
+
* tokens.json customization — wiping it on "Reset all" would feel wrong.
|
|
53
|
+
*
|
|
54
|
+
* Returns the count of removed keys, mostly for tests/debugging.
|
|
55
|
+
*/
|
|
56
|
+
export function clearAllCustomization(opts: { keep?: string[] } = {}): number {
|
|
57
|
+
if (typeof window === "undefined") return 0;
|
|
58
|
+
const prefix = `${getPrefix()}.`;
|
|
59
|
+
const keepKeys = new Set((opts.keep ?? ["theme"]).map((s) => storageKey(s)));
|
|
60
|
+
const toRemove: string[] = [];
|
|
61
|
+
for (let i = 0; i < window.localStorage.length; i++) {
|
|
62
|
+
const key = window.localStorage.key(i);
|
|
63
|
+
if (key && key.startsWith(prefix) && !keepKeys.has(key)) {
|
|
64
|
+
toRemove.push(key);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
for (const key of toRemove) {
|
|
68
|
+
window.localStorage.removeItem(key);
|
|
69
|
+
}
|
|
70
|
+
return toRemove.length;
|
|
71
|
+
}
|
|
72
|
+
|
|
44
73
|
const MIGRATED = new Set<string>();
|
|
45
74
|
|
|
46
75
|
/**
|