@behavioral-agentic-design-system/core 0.2.1 → 0.3.1
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 +37 -4
- package/scripts/bads-sync.mjs +81 -0
- package/scripts/build-tokens.cjs +487 -0
- package/src/api/bads-update-check.ts +151 -0
- package/src/api/brand-colors.ts +180 -0
- package/src/api/layers/file.ts +71 -0
- package/src/api/layers.ts +49 -0
- package/src/api/save-tokens.ts +280 -0
- package/src/app/font-ready.tsx +51 -0
- package/src/app/layout.tsx +152 -0
- package/src/app/page.tsx +267 -0
- package/src/app/preview/cards/page.tsx +8 -0
- package/src/app/preview/components/page.tsx +232 -0
- package/src/app/preview/dark-mode-client.tsx +24 -0
- package/src/app/preview/dashboard/page.tsx +4 -0
- package/src/app/preview/global-font-client.tsx +36 -0
- package/src/app/preview/layout.tsx +13 -0
- package/src/app/preview/mail/page.tsx +4 -0
- package/src/app/preview/pricing/page.tsx +4 -0
- package/src/app/preview/typography/page.tsx +11 -0
- package/src/app/providers.tsx +49 -0
- package/src/components/Foundations/Colors.stories.tsx +85 -0
- package/src/components/Foundations/Motion.stories.tsx +169 -0
- package/src/components/Foundations/Radius.stories.tsx +36 -0
- package/src/components/Foundations/Shadows.stories.tsx +30 -0
- package/src/components/Foundations/Spacing.stories.tsx +35 -0
- package/src/components/Foundations/Typography.stories.tsx +68 -0
- package/src/components/bads-update-banner.tsx +120 -0
- package/src/components/customize/design-controls.tsx +165 -0
- package/src/components/customize/font-pickers.tsx +118 -0
- package/src/components/customize/letter-spacing.tsx +105 -0
- package/src/components/customize/save-bar.tsx +379 -0
- package/src/components/customize/theme-io.tsx +245 -0
- package/src/components/customize/type-scale.tsx +134 -0
- package/src/components/customize-tab.tsx +502 -0
- package/src/components/home-tab.tsx +1227 -0
- package/src/components/layers-tab.tsx +225 -0
- package/src/components/ui/alert.tsx +5 -1
- package/src/hooks/use-global-design-controls.ts +117 -0
- package/src/hooks/use-global-mono-font.ts +73 -0
- package/src/hooks/use-global-primary-color.ts +544 -0
- package/src/hooks/use-global-sans-font.ts +98 -0
- package/src/hooks/use-global-serif-font.ts +77 -0
- package/src/hooks/use-global-theme.ts +259 -0
- package/src/hooks/use-global-type-scale.ts +141 -0
- package/src/hooks/use-sync-type-scale.ts +51 -0
- package/src/hooks/use-token-overrides.ts +98 -0
- package/src/styles.css +40 -6
- package/src/tokens.json +86 -5
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { exec } from "node:child_process";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { promisify } from "node:util";
|
|
5
|
+
import { NextResponse } from "next/server";
|
|
6
|
+
|
|
7
|
+
const execAsync = promisify(exec);
|
|
8
|
+
const TOKENS_PATH = path.join(process.cwd(), "packages/core/src/tokens.json");
|
|
9
|
+
const BRAND_COLORS_PATH = path.join(process.cwd(), "brand-colors.json");
|
|
10
|
+
|
|
11
|
+
type SavePayload = {
|
|
12
|
+
brandColor?: {
|
|
13
|
+
primary: string;
|
|
14
|
+
primaryHover?: string;
|
|
15
|
+
primaryForeground: string;
|
|
16
|
+
} | null;
|
|
17
|
+
/**
|
|
18
|
+
* When the active color is a localStorage custom, the Save Bar piggybacks
|
|
19
|
+
* a pinAsBuiltin entry so we promote the swatch to brand-colors.json in
|
|
20
|
+
* the same write. Keeps the chain to "one click = full persistence":
|
|
21
|
+
*
|
|
22
|
+
* active custom → tokens.json (system primary) AND brand-colors.json
|
|
23
|
+
* (picker option for every future clone).
|
|
24
|
+
*/
|
|
25
|
+
pinAsBuiltin?: {
|
|
26
|
+
id: string;
|
|
27
|
+
label: string;
|
|
28
|
+
primary: string;
|
|
29
|
+
primaryForeground?: string;
|
|
30
|
+
note?: string | null;
|
|
31
|
+
replaceCustomId?: string;
|
|
32
|
+
} | null;
|
|
33
|
+
fonts?: {
|
|
34
|
+
sans?: string;
|
|
35
|
+
serif?: string;
|
|
36
|
+
mono?: string;
|
|
37
|
+
} | null;
|
|
38
|
+
fontSizes?: Record<string, number> | null;
|
|
39
|
+
radius?: number | null;
|
|
40
|
+
reset?: boolean;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
type BrandColorEntry = {
|
|
44
|
+
id: string;
|
|
45
|
+
label: string;
|
|
46
|
+
primary: string;
|
|
47
|
+
primaryForeground?: string;
|
|
48
|
+
note?: string | null;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
type BrandColorsFile = {
|
|
52
|
+
$comment?: string;
|
|
53
|
+
colors: BrandColorEntry[];
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
function isValidId(id: string) {
|
|
57
|
+
return /^[a-z][a-z0-9-]{0,63}$/.test(id);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function isValidHex(hex: string) {
|
|
61
|
+
return /^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(hex.trim());
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function setLeaf(
|
|
65
|
+
node: Record<string, unknown>,
|
|
66
|
+
dotPath: string,
|
|
67
|
+
mutator: (leaf: Record<string, unknown>) => void,
|
|
68
|
+
) {
|
|
69
|
+
const parts = dotPath.split(".");
|
|
70
|
+
let current: Record<string, unknown> = node;
|
|
71
|
+
for (let i = 0; i < parts.length; i++) {
|
|
72
|
+
const key = parts[i];
|
|
73
|
+
const next = current[key];
|
|
74
|
+
if (i === parts.length - 1) {
|
|
75
|
+
if (next && typeof next === "object") {
|
|
76
|
+
mutator(next as Record<string, unknown>);
|
|
77
|
+
}
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (!next || typeof next !== "object") return;
|
|
81
|
+
current = next as Record<string, unknown>;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export async function POST(request: Request) {
|
|
86
|
+
if (process.env.NODE_ENV !== "development") {
|
|
87
|
+
return NextResponse.json(
|
|
88
|
+
{ ok: false, error: "Saving requires a local dev environment." },
|
|
89
|
+
{ status: 403 },
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
let payload: SavePayload;
|
|
94
|
+
try {
|
|
95
|
+
payload = await request.json();
|
|
96
|
+
} catch {
|
|
97
|
+
return NextResponse.json({ ok: false, error: "Invalid JSON" }, { status: 400 });
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (payload.reset) {
|
|
101
|
+
const defaultPath = path.join(process.cwd(), "packages/core/src/tokens.default.json");
|
|
102
|
+
try {
|
|
103
|
+
await fs.access(defaultPath);
|
|
104
|
+
} catch {
|
|
105
|
+
return NextResponse.json(
|
|
106
|
+
{ ok: false, error: "tokens.default.json missing" },
|
|
107
|
+
{ status: 500 },
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
await fs.copyFile(defaultPath, TOKENS_PATH);
|
|
111
|
+
await execAsync("pnpm build:tokens", { cwd: process.cwd() });
|
|
112
|
+
return NextResponse.json({ ok: true, updates: ["reset"], note: "Reset to baseline" });
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
let raw: string;
|
|
116
|
+
try {
|
|
117
|
+
raw = await fs.readFile(TOKENS_PATH, "utf8");
|
|
118
|
+
} catch (err) {
|
|
119
|
+
return NextResponse.json(
|
|
120
|
+
{ ok: false, error: `Could not read tokens.json: ${(err as Error).message}` },
|
|
121
|
+
{ status: 500 },
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
let tokens: Record<string, unknown>;
|
|
126
|
+
try {
|
|
127
|
+
tokens = JSON.parse(raw);
|
|
128
|
+
} catch (err) {
|
|
129
|
+
return NextResponse.json(
|
|
130
|
+
{ ok: false, error: `tokens.json is malformed: ${(err as Error).message}` },
|
|
131
|
+
{ status: 500 },
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const updates: string[] = [];
|
|
136
|
+
|
|
137
|
+
if (payload.brandColor) {
|
|
138
|
+
// Only write the primary to the LIGHT theme. Writing both to the same hex
|
|
139
|
+
// breaks dark-mode contrast — a near-black primary on a near-black page
|
|
140
|
+
// background fails WCAG 1.4.11 (3:1 non-text). Dark mode keeps its own
|
|
141
|
+
// inverted primary (near-white surface, near-black text). If a designer
|
|
142
|
+
// wants to override dark too, they can edit tokens.json directly or send
|
|
143
|
+
// a separate payload (future: { brandColorDark: { ... } }).
|
|
144
|
+
const { primary, primaryForeground } = payload.brandColor;
|
|
145
|
+
setLeaf(tokens, "theme.light.primary", (leaf) => {
|
|
146
|
+
leaf.$value = primary;
|
|
147
|
+
updates.push("theme.light.primary");
|
|
148
|
+
});
|
|
149
|
+
setLeaf(tokens, "theme.light.primary-foreground", (leaf) => {
|
|
150
|
+
leaf.$value = primaryForeground;
|
|
151
|
+
updates.push("theme.light.primary-foreground");
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Promote the active custom color to a built-in entry in brand-colors.json
|
|
156
|
+
// alongside the tokens.json write, so a Save fully persists the swatch
|
|
157
|
+
// (everyone on the repo sees it as a picker option) and the system primary
|
|
158
|
+
// in one round-trip. Validation matches /api/brand-colors so a malformed
|
|
159
|
+
// entry is rejected without corrupting the file.
|
|
160
|
+
let pinnedBuiltinId: string | null = null;
|
|
161
|
+
if (payload.pinAsBuiltin) {
|
|
162
|
+
const e = payload.pinAsBuiltin;
|
|
163
|
+
if (!isValidId(e.id) || !isValidHex(e.primary) || !e.label?.trim()) {
|
|
164
|
+
return NextResponse.json(
|
|
165
|
+
{ ok: false, error: "pinAsBuiltin: need valid id, label, primary hex" },
|
|
166
|
+
{ status: 400 },
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
if (e.primaryForeground && !isValidHex(e.primaryForeground)) {
|
|
170
|
+
return NextResponse.json(
|
|
171
|
+
{ ok: false, error: "pinAsBuiltin: invalid primaryForeground hex" },
|
|
172
|
+
{ status: 400 },
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
try {
|
|
176
|
+
const raw = await fs.readFile(BRAND_COLORS_PATH, "utf8");
|
|
177
|
+
const file = JSON.parse(raw) as BrandColorsFile;
|
|
178
|
+
if (!Array.isArray(file.colors)) file.colors = [];
|
|
179
|
+
const cleaned: BrandColorEntry = {
|
|
180
|
+
id: e.id,
|
|
181
|
+
label: e.label.trim(),
|
|
182
|
+
primary: e.primary,
|
|
183
|
+
...(e.primaryForeground ? { primaryForeground: e.primaryForeground } : {}),
|
|
184
|
+
...(e.note ? { note: e.note } : {}),
|
|
185
|
+
};
|
|
186
|
+
const existing = file.colors.findIndex((c) => c.id === cleaned.id);
|
|
187
|
+
if (existing >= 0) file.colors[existing] = cleaned;
|
|
188
|
+
else file.colors.push(cleaned);
|
|
189
|
+
await fs.writeFile(BRAND_COLORS_PATH, JSON.stringify(file, null, 2) + "\n", "utf8");
|
|
190
|
+
pinnedBuiltinId = cleaned.id;
|
|
191
|
+
updates.push(`brand-colors.json:${cleaned.id}`);
|
|
192
|
+
} catch (err) {
|
|
193
|
+
return NextResponse.json(
|
|
194
|
+
{ ok: false, error: `Failed to write brand-colors.json: ${(err as Error).message}` },
|
|
195
|
+
{ status: 500 },
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (payload.fonts) {
|
|
201
|
+
if (payload.fonts.sans) {
|
|
202
|
+
setLeaf(tokens, "fontFamily.sans", (leaf) => {
|
|
203
|
+
leaf.$value = payload.fonts!.sans;
|
|
204
|
+
updates.push("fontFamily.sans");
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
if (payload.fonts.serif) {
|
|
208
|
+
setLeaf(tokens, "fontFamily.serif", (leaf) => {
|
|
209
|
+
leaf.$value = payload.fonts!.serif;
|
|
210
|
+
updates.push("fontFamily.serif");
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
if (payload.fonts.mono) {
|
|
214
|
+
setLeaf(tokens, "fontFamily.mono", (leaf) => {
|
|
215
|
+
leaf.$value = payload.fonts!.mono;
|
|
216
|
+
updates.push("fontFamily.mono");
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (payload.fontSizes) {
|
|
222
|
+
// Floor-clamp every step so the type-scale slider can't drift below the
|
|
223
|
+
// 14px AAA accessibility floor (SC 1.4.4). The Customize tab can show
|
|
224
|
+
// smaller previews live if the user really wants, but persisting them
|
|
225
|
+
// to tokens.json would break the system's a11y guarantee for everyone
|
|
226
|
+
// pulling the repo.
|
|
227
|
+
const FONT_SIZE_FLOOR_PX = 14;
|
|
228
|
+
const stepKeys = ["xs", "sm", "base", "lg", "xl", "2xl", "3xl"];
|
|
229
|
+
for (const step of stepKeys) {
|
|
230
|
+
const px = payload.fontSizes[`text-${step}`];
|
|
231
|
+
if (typeof px === "number") {
|
|
232
|
+
const clamped = Math.max(FONT_SIZE_FLOOR_PX, px);
|
|
233
|
+
setLeaf(tokens, `fontSize.${step}`, (leaf) => {
|
|
234
|
+
leaf.$value = `${Math.round(clamped * 100) / 100}px`;
|
|
235
|
+
updates.push(`fontSize.${step}${clamped !== px ? " (clamped to floor)" : ""}`);
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (typeof payload.radius === "number") {
|
|
242
|
+
setLeaf(tokens, "borderRadius.lg", (leaf) => {
|
|
243
|
+
leaf.$value = `${payload.radius}rem`;
|
|
244
|
+
updates.push("borderRadius.lg");
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (updates.length === 0) {
|
|
249
|
+
return NextResponse.json({ ok: true, updates: [], note: "No changes to save." });
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
try {
|
|
253
|
+
const output = JSON.stringify(tokens, null, 2) + "\n";
|
|
254
|
+
await fs.writeFile(TOKENS_PATH, output, "utf8");
|
|
255
|
+
} catch (err) {
|
|
256
|
+
return NextResponse.json(
|
|
257
|
+
{ ok: false, error: `Failed to write tokens.json: ${(err as Error).message}` },
|
|
258
|
+
{ status: 500 },
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
try {
|
|
263
|
+
await execAsync("pnpm build:tokens", { cwd: process.cwd() });
|
|
264
|
+
} catch (err) {
|
|
265
|
+
return NextResponse.json({
|
|
266
|
+
ok: true,
|
|
267
|
+
updates,
|
|
268
|
+
warning: `Saved tokens.json but build:tokens failed: ${(err as Error).message}`,
|
|
269
|
+
pinnedBuiltinId,
|
|
270
|
+
replaceCustomId: payload.pinAsBuiltin?.replaceCustomId ?? null,
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return NextResponse.json({
|
|
275
|
+
ok: true,
|
|
276
|
+
updates,
|
|
277
|
+
pinnedBuiltinId,
|
|
278
|
+
replaceCustomId: payload.pinAsBuiltin?.replaceCustomId ?? null,
|
|
279
|
+
});
|
|
280
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useEffect } from "react";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Removes the `fonts-loading` class on <html> once web fonts are ready.
|
|
7
|
+
*
|
|
8
|
+
* RootLayout renders `<html className="fonts-loading ...">` so the body is
|
|
9
|
+
* hidden from the very first paint (CSS rule in the base layer:
|
|
10
|
+
* `html.fonts-loading body { opacity: 0 }`). This component runs after
|
|
11
|
+
* hydration, awaits `document.fonts.ready`, then swaps to `fonts-loaded` —
|
|
12
|
+
* CSS transitions the body back in over 200ms.
|
|
13
|
+
*
|
|
14
|
+
* Cached loads: fonts.check() returns true immediately, so the class is
|
|
15
|
+
* removed within a few ms of hydration — barely perceptible.
|
|
16
|
+
*
|
|
17
|
+
* Slow / failed loads: a 1500ms safety timeout releases the gate so the
|
|
18
|
+
* page never stays blank, even if a font 404s or hangs.
|
|
19
|
+
*/
|
|
20
|
+
export function FontReady() {
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
const root = document.documentElement;
|
|
23
|
+
const reveal = () => {
|
|
24
|
+
root.classList.remove("fonts-loading");
|
|
25
|
+
root.classList.add("fonts-loaded");
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
let alreadyReady = false;
|
|
29
|
+
try {
|
|
30
|
+
alreadyReady = document.fonts.check("1em 'Hyperlegible Sans'");
|
|
31
|
+
} catch {
|
|
32
|
+
// fonts.check throws if the font name is unknown — treat as not ready.
|
|
33
|
+
}
|
|
34
|
+
if (alreadyReady) {
|
|
35
|
+
reveal();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let cancelled = false;
|
|
40
|
+
document.fonts.ready.then(() => {
|
|
41
|
+
if (!cancelled) reveal();
|
|
42
|
+
});
|
|
43
|
+
const safety = window.setTimeout(reveal, 1500);
|
|
44
|
+
return () => {
|
|
45
|
+
cancelled = true;
|
|
46
|
+
window.clearTimeout(safety);
|
|
47
|
+
};
|
|
48
|
+
}, []);
|
|
49
|
+
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import type { Metadata } from "next";
|
|
2
|
+
import { Atkinson_Hyperlegible, Inter, JetBrains_Mono, Lora, Source_Serif_4 } from "next/font/google";
|
|
3
|
+
import "@/styles/globals.css";
|
|
4
|
+
import Providers from "./providers";
|
|
5
|
+
import { FontReady } from "./font-ready";
|
|
6
|
+
|
|
7
|
+
// next/font self-hosts these and emits preload links automatically, so the
|
|
8
|
+
// browser has the woff2 in hand before first paint — kills FOUT on the
|
|
9
|
+
// showcase app. The published @import in packages/core/src/styles.css stays
|
|
10
|
+
// untouched so npm consumers still get the canonical theme out of the box.
|
|
11
|
+
const atkinson = Atkinson_Hyperlegible({
|
|
12
|
+
subsets: ["latin"],
|
|
13
|
+
weight: ["400", "700"],
|
|
14
|
+
display: "swap",
|
|
15
|
+
variable: "--font-atkinson",
|
|
16
|
+
});
|
|
17
|
+
const inter = Inter({
|
|
18
|
+
subsets: ["latin"],
|
|
19
|
+
display: "swap",
|
|
20
|
+
variable: "--font-inter",
|
|
21
|
+
});
|
|
22
|
+
const jetbrainsMono = JetBrains_Mono({
|
|
23
|
+
subsets: ["latin"],
|
|
24
|
+
display: "swap",
|
|
25
|
+
variable: "--font-jetbrains",
|
|
26
|
+
});
|
|
27
|
+
const lora = Lora({
|
|
28
|
+
subsets: ["latin"],
|
|
29
|
+
display: "swap",
|
|
30
|
+
variable: "--font-lora",
|
|
31
|
+
});
|
|
32
|
+
const sourceSerif = Source_Serif_4({
|
|
33
|
+
subsets: ["latin"],
|
|
34
|
+
display: "swap",
|
|
35
|
+
variable: "--font-source-serif",
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export const metadata: Metadata = {
|
|
39
|
+
title: "BADS Design System",
|
|
40
|
+
description: "Interactive design system and component dashboard",
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export default function RootLayout({
|
|
44
|
+
children,
|
|
45
|
+
}: {
|
|
46
|
+
children: React.ReactNode;
|
|
47
|
+
}) {
|
|
48
|
+
return (
|
|
49
|
+
<html
|
|
50
|
+
lang="en"
|
|
51
|
+
suppressHydrationWarning
|
|
52
|
+
// `fonts-loading` is removed by <FontReady /> on mount once
|
|
53
|
+
// document.fonts.ready resolves. CSS keeps body opacity 0 until then,
|
|
54
|
+
// killing the FOUT "jump" when web fonts swap in over system-ui.
|
|
55
|
+
className={`fonts-loading ${atkinson.variable} ${inter.variable} ${jetbrainsMono.variable} ${lora.variable} ${sourceSerif.variable}`}
|
|
56
|
+
>
|
|
57
|
+
<head>
|
|
58
|
+
<link
|
|
59
|
+
rel="preload"
|
|
60
|
+
href="/fonts/HyperlegibleSans-Regular.woff2"
|
|
61
|
+
as="font"
|
|
62
|
+
type="font/woff2"
|
|
63
|
+
crossOrigin=""
|
|
64
|
+
/>
|
|
65
|
+
<link
|
|
66
|
+
rel="preload"
|
|
67
|
+
href="/fonts/HyperlegibleSans-Bold.woff2"
|
|
68
|
+
as="font"
|
|
69
|
+
type="font/woff2"
|
|
70
|
+
crossOrigin=""
|
|
71
|
+
/>
|
|
72
|
+
<script
|
|
73
|
+
dangerouslySetInnerHTML={{
|
|
74
|
+
__html: `
|
|
75
|
+
(function() {
|
|
76
|
+
try {
|
|
77
|
+
// Reference next/font's preloaded variables (--font-atkinson etc.)
|
|
78
|
+
// first so the browser uses the already-fetched woff2 from the
|
|
79
|
+
// very first paint. Fall back to system-ui if next/font hasn't
|
|
80
|
+
// initialized yet.
|
|
81
|
+
var SANS = {
|
|
82
|
+
hyperlegible: "'Hyperlegible Sans', ui-sans-serif, sans-serif, system-ui",
|
|
83
|
+
atkinson: "var(--font-atkinson), 'Atkinson Hyperlegible', ui-sans-serif, sans-serif, system-ui",
|
|
84
|
+
inter: "var(--font-inter), 'Inter', ui-sans-serif, sans-serif, system-ui",
|
|
85
|
+
system: "ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif"
|
|
86
|
+
};
|
|
87
|
+
var SERIF = {
|
|
88
|
+
georgia: "Georgia, ui-serif, serif",
|
|
89
|
+
lora: "var(--font-lora), 'Lora', Georgia, ui-serif, serif",
|
|
90
|
+
"source-serif": "var(--font-source-serif), 'Source Serif 4', Georgia, ui-serif, serif",
|
|
91
|
+
system: "ui-serif, Georgia, Cambria, 'Times New Roman', Times, serif"
|
|
92
|
+
};
|
|
93
|
+
var MONO = {
|
|
94
|
+
jetbrains: "var(--font-jetbrains), 'JetBrains Mono', ui-monospace, monospace",
|
|
95
|
+
"ibm-plex": "'IBM Plex Mono', ui-monospace, monospace",
|
|
96
|
+
"fira-code": "'Fira Code', ui-monospace, monospace",
|
|
97
|
+
system: "ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace"
|
|
98
|
+
};
|
|
99
|
+
var STEPS = {
|
|
100
|
+
"text-xs": -2,
|
|
101
|
+
"text-sm": -1,
|
|
102
|
+
"text-base": 0,
|
|
103
|
+
"text-lg": 1,
|
|
104
|
+
"text-xl": 2,
|
|
105
|
+
"text-2xl": 3,
|
|
106
|
+
"text-3xl": 4
|
|
107
|
+
};
|
|
108
|
+
var s = document.documentElement.style;
|
|
109
|
+
var sans = localStorage.getItem("BADS.sansFont");
|
|
110
|
+
if (sans && SANS[sans]) s.setProperty("--font-sans", SANS[sans]);
|
|
111
|
+
var serif = localStorage.getItem("BADS.serifFont");
|
|
112
|
+
if (serif && SERIF[serif]) s.setProperty("--font-serif", SERIF[serif]);
|
|
113
|
+
var mono = localStorage.getItem("BADS.monoFont");
|
|
114
|
+
if (mono && MONO[mono]) s.setProperty("--font-mono", MONO[mono]);
|
|
115
|
+
var dc = localStorage.getItem("BADS.designControls");
|
|
116
|
+
if (dc) {
|
|
117
|
+
try {
|
|
118
|
+
var d = JSON.parse(dc);
|
|
119
|
+
if (typeof d.radius === "number") s.setProperty("--radius", d.radius + "rem");
|
|
120
|
+
if (typeof d.spacing === "number") s.setProperty("--spacing", d.spacing + "rem");
|
|
121
|
+
if (typeof d.letterSpacing === "number") s.setProperty("--tracking-offset", d.letterSpacing + "em");
|
|
122
|
+
if (typeof d.shadowOpacity === "number") s.setProperty("--shadow-opacity", d.shadowOpacity.toFixed(2));
|
|
123
|
+
} catch (e) {}
|
|
124
|
+
}
|
|
125
|
+
var ts = localStorage.getItem("BADS.typeScale");
|
|
126
|
+
var base = 18;
|
|
127
|
+
var ratio = 1.125;
|
|
128
|
+
if (ts) {
|
|
129
|
+
try {
|
|
130
|
+
var t = JSON.parse(ts);
|
|
131
|
+
if (typeof t.base === "number") base = t.base;
|
|
132
|
+
if (typeof t.ratio === "number") ratio = t.ratio;
|
|
133
|
+
} catch (e) {}
|
|
134
|
+
}
|
|
135
|
+
for (var name in STEPS) {
|
|
136
|
+
var step = STEPS[name];
|
|
137
|
+
var size = base * Math.pow(ratio, step);
|
|
138
|
+
s.setProperty("--" + name + "-size", size.toFixed(2) + "px");
|
|
139
|
+
}
|
|
140
|
+
} catch (e) {}
|
|
141
|
+
})();
|
|
142
|
+
`,
|
|
143
|
+
}}
|
|
144
|
+
/>
|
|
145
|
+
</head>
|
|
146
|
+
<body>
|
|
147
|
+
<FontReady />
|
|
148
|
+
<Providers>{children}</Providers>
|
|
149
|
+
</body>
|
|
150
|
+
</html>
|
|
151
|
+
);
|
|
152
|
+
}
|