@behavioral-agentic-design-system/core 0.3.2 → 0.5.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/package.json +2 -1
- package/scripts/build-tokens.cjs +29 -6
- package/src/app/layout.tsx +50 -7
- package/src/app/page.tsx +9 -263
- package/src/app/shell.tsx +293 -0
- package/src/components/bads-update-banner.tsx +3 -2
- package/src/components/customize/save-bar.tsx +12 -10
- package/src/components/customize-tab.tsx +2 -2
- package/src/hooks/use-global-design-controls.ts +4 -2
- package/src/hooks/use-global-mono-font.ts +4 -2
- package/src/hooks/use-global-primary-color.ts +15 -4
- package/src/hooks/use-global-sans-font.ts +4 -2
- package/src/hooks/use-global-serif-font.ts +4 -2
- package/src/hooks/use-global-theme.ts +4 -2
- package/src/hooks/use-global-type-scale.ts +4 -2
- package/src/hooks/use-sync-type-scale.ts +2 -1
- package/src/hooks/use-token-overrides.ts +4 -2
- package/src/lib/storage.ts +76 -0
- package/src/lib/theme-editor.ts +13 -4
- package/src/styles.css +31 -13
- package/src/tokens.json +19 -19
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage-key helper. Replaces the hardcoded "BADS." prefix that every
|
|
3
|
+
* shell hook used pre-0.4.0.
|
|
4
|
+
*
|
|
5
|
+
* Why this exists
|
|
6
|
+
* ----------------
|
|
7
|
+
* Before 0.4.0, every hook had `const STORAGE_KEY = "BADS.sansFont"` (and
|
|
8
|
+
* similar) inlined. `scripts/rename.mjs` rewrote those strings at fork time
|
|
9
|
+
* so a renamed fork stored data under "<SLUG_UPPER>.sansFont" instead.
|
|
10
|
+
*
|
|
11
|
+
* Once @core started shipping the hooks via npm (0.3.0), rename.mjs could no
|
|
12
|
+
* longer reach the hook source — it lives in node_modules, not the consumer
|
|
13
|
+
* tree. Forks ended up reading "BADS.sansFont" from localStorage even though
|
|
14
|
+
* their saved customizations were under "<SLUG_UPPER>.sansFont", silently
|
|
15
|
+
* losing every Customize-tab edit they had made.
|
|
16
|
+
*
|
|
17
|
+
* Fix: derive the prefix at runtime from the fork's slug, which the layout
|
|
18
|
+
* exposes on `window.__BADS_SLUG__` (server-rendered from
|
|
19
|
+
* `.client-identity.json` or — for upstream BADS — defaulted to "bads").
|
|
20
|
+
*
|
|
21
|
+
* Module evaluation happens after the inline `<head>` script has set the
|
|
22
|
+
* global, so reading at top level is safe during client hydration. Server
|
|
23
|
+
* evaluations land on "BADS." but never reach localStorage, so the
|
|
24
|
+
* server-side value is harmless.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
declare global {
|
|
28
|
+
interface Window {
|
|
29
|
+
__BADS_SLUG__?: string;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function getPrefix(): string {
|
|
34
|
+
if (typeof window !== "undefined" && typeof window.__BADS_SLUG__ === "string" && window.__BADS_SLUG__) {
|
|
35
|
+
return window.__BADS_SLUG__.toUpperCase();
|
|
36
|
+
}
|
|
37
|
+
return "BADS";
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function storageKey(suffix: string): string {
|
|
41
|
+
return `${getPrefix()}.${suffix}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const MIGRATED = new Set<string>();
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Reads localStorage at the prefixed key. If empty, looks under the legacy
|
|
48
|
+
* "BADS.<suffix>" key one time per suffix per session — if found, copies the
|
|
49
|
+
* value to the new key and removes the old one. Returns the resolved string
|
|
50
|
+
* or null.
|
|
51
|
+
*
|
|
52
|
+
* Use this in place of `localStorage.getItem(STORAGE_KEY)` inside hook
|
|
53
|
+
* `useEffect` blocks so renamed forks pick up data they wrote pre-0.4.0
|
|
54
|
+
* (back when the hook source was workspace-forked and rename.mjs had
|
|
55
|
+
* written "<SLUG>." into the source). After one read, the data is on the
|
|
56
|
+
* new key and the old key is gone — subsequent reads skip the migration.
|
|
57
|
+
*/
|
|
58
|
+
export function readMigrated(suffix: string): string | null {
|
|
59
|
+
if (typeof window === "undefined") return null;
|
|
60
|
+
const newKey = storageKey(suffix);
|
|
61
|
+
const fresh = window.localStorage.getItem(newKey);
|
|
62
|
+
if (fresh !== null) return fresh;
|
|
63
|
+
if (MIGRATED.has(suffix)) return null;
|
|
64
|
+
MIGRATED.add(suffix);
|
|
65
|
+
const legacyKey = `BADS.${suffix}`;
|
|
66
|
+
if (legacyKey === newKey) return null;
|
|
67
|
+
const legacy = window.localStorage.getItem(legacyKey);
|
|
68
|
+
if (legacy === null) return null;
|
|
69
|
+
try {
|
|
70
|
+
window.localStorage.setItem(newKey, legacy);
|
|
71
|
+
window.localStorage.removeItem(legacyKey);
|
|
72
|
+
} catch {
|
|
73
|
+
// Quota or privacy mode — return the value but leave both keys intact.
|
|
74
|
+
}
|
|
75
|
+
return legacy;
|
|
76
|
+
}
|
package/src/lib/theme-editor.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import tokens from "../tokens.json";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import { storageKey, readMigrated } from "@behavioral-agentic-design-system/core/lib/storage";
|
|
3
|
+
|
|
4
|
+
// Both keys derive from the runtime slug so a renamed fork uses
|
|
5
|
+
// "<SLUG>.themeEditorState" / "<slug>-live-theme-editor" without rename.mjs
|
|
6
|
+
// having to rewrite hook source. The legacy "BADS." key gets migrated on
|
|
7
|
+
// first read via readMigrated() inside readStoredThemeEditorState.
|
|
8
|
+
export const THEME_EDITOR_STORAGE_KEY = storageKey("themeEditorState");
|
|
9
|
+
const slugForStyleId =
|
|
10
|
+
typeof window !== "undefined" && typeof window.__BADS_SLUG__ === "string" && window.__BADS_SLUG__
|
|
11
|
+
? window.__BADS_SLUG__
|
|
12
|
+
: "bads";
|
|
13
|
+
export const THEME_EDITOR_STYLE_ID = `${slugForStyleId}-live-theme-editor`;
|
|
5
14
|
|
|
6
15
|
export type ThemeEditorMode = "light" | "dark";
|
|
7
16
|
|
|
@@ -105,7 +114,7 @@ export function readStoredThemeEditorState(): ThemeEditorState {
|
|
|
105
114
|
if (typeof window === "undefined") return DEFAULT_THEME_EDITOR_STATE;
|
|
106
115
|
|
|
107
116
|
try {
|
|
108
|
-
const raw =
|
|
117
|
+
const raw = readMigrated("themeEditorState");
|
|
109
118
|
if (!raw) return DEFAULT_THEME_EDITOR_STATE;
|
|
110
119
|
|
|
111
120
|
const parsed = JSON.parse(raw);
|
package/src/styles.css
CHANGED
|
@@ -14,6 +14,21 @@
|
|
|
14
14
|
|
|
15
15
|
@import url('https://fonts.googleapis.com/css2?family=Atkinson+Hyperlegible:wght@400;700&display=swap');
|
|
16
16
|
|
|
17
|
+
/* Tailwind v4 only generates classes it scans. The shell components, hooks,
|
|
18
|
+
* and app routes shipped in this package use plenty of Tailwind classes that
|
|
19
|
+
* the consumer's own source code never references — Button's variants,
|
|
20
|
+
* Dialog's overlay, the customize tab's grid, etc. Without these @source
|
|
21
|
+
* paths a fresh fork imports styles.css and gets unstyled components because
|
|
22
|
+
* the classes never made it into the consumer's bundle.
|
|
23
|
+
*
|
|
24
|
+
* Paths resolve relative to this file (node_modules/@.../core/src/styles.css),
|
|
25
|
+
* so they cover the package's own source files in node_modules. Consumers
|
|
26
|
+
* don't need to touch their own Tailwind content config to get this working. */
|
|
27
|
+
@source "./components/**/*.{ts,tsx}";
|
|
28
|
+
@source "./app/**/*.{ts,tsx}";
|
|
29
|
+
@source "./hooks/**/*.{ts,tsx}";
|
|
30
|
+
@source "./lib/**/*.{ts,tsx}";
|
|
31
|
+
|
|
17
32
|
@custom-variant dark (&:is(.dark *));
|
|
18
33
|
|
|
19
34
|
:root {
|
|
@@ -44,11 +59,11 @@
|
|
|
44
59
|
--border: oklch(0.6100 0 0);
|
|
45
60
|
--input: oklch(0.6100 0 0);
|
|
46
61
|
--ring: oklch(0.4500 0 0);
|
|
47
|
-
--chart-1: oklch(0.
|
|
48
|
-
--chart-2: oklch(0.
|
|
49
|
-
--chart-3: oklch(0.
|
|
50
|
-
--chart-4: oklch(0.
|
|
51
|
-
--chart-5: oklch(0.
|
|
62
|
+
--chart-1: oklch(0.6200 0.2000 220);
|
|
63
|
+
--chart-2: oklch(0.6200 0.2200 145);
|
|
64
|
+
--chart-3: oklch(0.6500 0.1800 88);
|
|
65
|
+
--chart-4: oklch(0.6000 0.2600 340);
|
|
66
|
+
--chart-5: oklch(0.6200 0.2200 25);
|
|
52
67
|
--sidebar: oklch(0.9850 0 0);
|
|
53
68
|
--sidebar-foreground: oklch(0.1450 0 0);
|
|
54
69
|
--sidebar-primary: oklch(0.2050 0 0);
|
|
@@ -119,11 +134,11 @@
|
|
|
119
134
|
--border: oklch(0.5500 0 0);
|
|
120
135
|
--input: oklch(0.5500 0 0);
|
|
121
136
|
--ring: oklch(0.7000 0 0);
|
|
122
|
-
--chart-1: oklch(0.7800 0.
|
|
123
|
-
--chart-2: oklch(0.
|
|
124
|
-
--chart-3: oklch(0.
|
|
125
|
-
--chart-4: oklch(0.
|
|
126
|
-
--chart-5: oklch(0.
|
|
137
|
+
--chart-1: oklch(0.7800 0.1800 220);
|
|
138
|
+
--chart-2: oklch(0.8000 0.2000 145);
|
|
139
|
+
--chart-3: oklch(0.8500 0.1700 90);
|
|
140
|
+
--chart-4: oklch(0.7600 0.2200 340);
|
|
141
|
+
--chart-5: oklch(0.7800 0.1800 25);
|
|
127
142
|
--sidebar: oklch(0.2050 0 0);
|
|
128
143
|
--sidebar-foreground: oklch(0.9850 0 0);
|
|
129
144
|
--sidebar-primary: oklch(0.4200 0.2000 264.3760);
|
|
@@ -171,9 +186,12 @@
|
|
|
171
186
|
--color-sidebar-border: var(--sidebar-border);
|
|
172
187
|
--color-sidebar-ring: var(--sidebar-ring);
|
|
173
188
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
189
|
+
/* font-sans/serif/mono intentionally NOT mapped here. Tailwind v4
|
|
190
|
+
compiles @theme inline self-references into a :root rule of the
|
|
191
|
+
same shape, which collides with the unlayered :root that sets the
|
|
192
|
+
actual font stack and resolves to an empty circular reference. The
|
|
193
|
+
:root above already defines --font-sans, and Tailwind picks it up
|
|
194
|
+
for the font-sans utility automatically. */
|
|
177
195
|
|
|
178
196
|
--radius-sm: calc(var(--radius) - 4px);
|
|
179
197
|
--radius-md: calc(var(--radius) - 2px);
|
package/src/tokens.json
CHANGED
|
@@ -814,29 +814,29 @@
|
|
|
814
814
|
"$description": "Focus ring base. AAA non-text + 2.4.13: ≥3:1 on every surface. Tracks --primary when brand color changes (luminance-clamped to keep 3:1)."
|
|
815
815
|
},
|
|
816
816
|
"chart-1": {
|
|
817
|
-
"$value": "oklch(0.
|
|
817
|
+
"$value": "oklch(0.6200 0.2000 220)",
|
|
818
818
|
"$type": "color",
|
|
819
|
-
"$description": "Tuned for AAA 3:1 on white card.
|
|
819
|
+
"$description": "Tuned for AAA 3:1 on white card. Electric cyan-blue."
|
|
820
820
|
},
|
|
821
821
|
"chart-2": {
|
|
822
|
-
"$value": "oklch(0.
|
|
822
|
+
"$value": "oklch(0.6200 0.2200 145)",
|
|
823
823
|
"$type": "color",
|
|
824
|
-
"$description": "Tuned for AAA 3:1 on white card.
|
|
824
|
+
"$description": "Tuned for AAA 3:1 on white card. Spring green."
|
|
825
825
|
},
|
|
826
826
|
"chart-3": {
|
|
827
|
-
"$value": "oklch(0.
|
|
827
|
+
"$value": "oklch(0.6500 0.1800 88)",
|
|
828
828
|
"$type": "color",
|
|
829
|
-
"$description": "Tuned for AAA 3:1 on white card.
|
|
829
|
+
"$description": "Tuned for AAA 3:1 on white card. Bright gold."
|
|
830
830
|
},
|
|
831
831
|
"chart-4": {
|
|
832
|
-
"$value": "oklch(0.
|
|
832
|
+
"$value": "oklch(0.6000 0.2600 340)",
|
|
833
833
|
"$type": "color",
|
|
834
|
-
"$description": "Tuned for AAA 3:1 on white card.
|
|
834
|
+
"$description": "Tuned for AAA 3:1 on white card. Hot fuchsia."
|
|
835
835
|
},
|
|
836
836
|
"chart-5": {
|
|
837
|
-
"$value": "oklch(0.
|
|
837
|
+
"$value": "oklch(0.6200 0.2200 25)",
|
|
838
838
|
"$type": "color",
|
|
839
|
-
"$description": "Tuned for AAA 3:1 on white card.
|
|
839
|
+
"$description": "Tuned for AAA 3:1 on white card. Coral."
|
|
840
840
|
},
|
|
841
841
|
"sidebar": {
|
|
842
842
|
"$value": "oklch(0.9850 0 0)",
|
|
@@ -1007,29 +1007,29 @@
|
|
|
1007
1007
|
"$description": "Focus ring base, dark mode. AAA non-text 3:1 on dark."
|
|
1008
1008
|
},
|
|
1009
1009
|
"chart-1": {
|
|
1010
|
-
"$value": "oklch(0.7800 0.
|
|
1010
|
+
"$value": "oklch(0.7800 0.1800 220)",
|
|
1011
1011
|
"$type": "color",
|
|
1012
1012
|
"$description": "Tuned for AAA 3:1 on dark card. Bright cyan-blue."
|
|
1013
1013
|
},
|
|
1014
1014
|
"chart-2": {
|
|
1015
|
-
"$value": "oklch(0.
|
|
1015
|
+
"$value": "oklch(0.8000 0.2000 145)",
|
|
1016
1016
|
"$type": "color",
|
|
1017
|
-
"$description": "Tuned for AAA 3:1 on dark card. Bright green."
|
|
1017
|
+
"$description": "Tuned for AAA 3:1 on dark card. Bright spring green."
|
|
1018
1018
|
},
|
|
1019
1019
|
"chart-3": {
|
|
1020
|
-
"$value": "oklch(0.
|
|
1020
|
+
"$value": "oklch(0.8500 0.1700 90)",
|
|
1021
1021
|
"$type": "color",
|
|
1022
|
-
"$description": "Tuned for AAA 3:1 on dark card.
|
|
1022
|
+
"$description": "Tuned for AAA 3:1 on dark card. Bright gold."
|
|
1023
1023
|
},
|
|
1024
1024
|
"chart-4": {
|
|
1025
|
-
"$value": "oklch(0.
|
|
1025
|
+
"$value": "oklch(0.7600 0.2200 340)",
|
|
1026
1026
|
"$type": "color",
|
|
1027
|
-
"$description": "Tuned for AAA 3:1 on dark card.
|
|
1027
|
+
"$description": "Tuned for AAA 3:1 on dark card. Bright fuchsia."
|
|
1028
1028
|
},
|
|
1029
1029
|
"chart-5": {
|
|
1030
|
-
"$value": "oklch(0.
|
|
1030
|
+
"$value": "oklch(0.7800 0.1800 25)",
|
|
1031
1031
|
"$type": "color",
|
|
1032
|
-
"$description": "Tuned for AAA 3:1 on dark card.
|
|
1032
|
+
"$description": "Tuned for AAA 3:1 on dark card. Bright coral."
|
|
1033
1033
|
},
|
|
1034
1034
|
"sidebar": {
|
|
1035
1035
|
"$value": "oklch(0.2050 0 0)",
|