@nocoo/basalt 2.0.0 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/alert-dialog.js +2 -1
- package/dist/components/alert-dialog.js.map +1 -1
- package/dist/components/button.js +2 -2
- package/dist/components/button.js.map +1 -1
- package/dist/components/chat-bubble.d.ts +17 -0
- package/dist/components/chat-bubble.js +25 -0
- package/dist/components/chat-bubble.js.map +1 -0
- package/dist/components/chat-composer.d.ts +41 -0
- package/dist/components/chat-composer.js +74 -0
- package/dist/components/chat-composer.js.map +1 -0
- package/dist/components/chat-header.d.ts +20 -0
- package/dist/components/chat-header.js +33 -0
- package/dist/components/chat-header.js.map +1 -0
- package/dist/components/chat-inbox.d.ts +28 -0
- package/dist/components/chat-inbox.js +44 -0
- package/dist/components/chat-inbox.js.map +1 -0
- package/dist/components/description-list.d.ts +21 -0
- package/dist/components/description-list.js +35 -0
- package/dist/components/description-list.js.map +1 -0
- package/dist/components/dialog.js +3 -2
- package/dist/components/dialog.js.map +1 -1
- package/dist/components/dock.d.ts +39 -0
- package/dist/components/dock.js +116 -0
- package/dist/components/dock.js.map +1 -0
- package/dist/components/fab.d.ts +23 -0
- package/dist/components/fab.js +25 -0
- package/dist/components/fab.js.map +1 -0
- package/dist/components/layer-card.d.ts +23 -4
- package/dist/components/layer-card.js +83 -50
- package/dist/components/layer-card.js.map +1 -1
- package/dist/components/page-header.d.ts +4 -4
- package/dist/components/page-header.js +20 -23
- package/dist/components/page-header.js.map +1 -1
- package/dist/components/section-rule.d.ts +10 -0
- package/dist/components/section-rule.js +44 -0
- package/dist/components/section-rule.js.map +1 -0
- package/dist/components/sheet.d.ts +4 -4
- package/dist/components/sheet.js +5 -4
- package/dist/components/sheet.js.map +1 -1
- package/dist/components/sidebar.js +1 -0
- package/dist/components/sidebar.js.map +1 -1
- package/dist/components/table.js +6 -5
- package/dist/components/table.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +26 -25
- package/dist/providers/accent.d.ts +3 -2
- package/dist/providers/accent.js +166 -44
- package/dist/providers/accent.js.map +1 -1
- package/dist/styles/standalone.css +378 -92
- package/dist/styles/tailwind.css +1 -0
- package/dist/styles/tokens.css +70 -0
- package/dist/utils/control-surface.d.ts +1 -1
- package/dist/utils/control-surface.js +1 -1
- package/dist/utils/control-surface.js.map +1 -1
- package/package.json +1 -1
package/dist/providers/accent.js
CHANGED
|
@@ -4,107 +4,229 @@ import { jsx as o } from "react/jsx-runtime";
|
|
|
4
4
|
//#region src/providers/accent.tsx
|
|
5
5
|
var s = [
|
|
6
6
|
{
|
|
7
|
-
id: "
|
|
8
|
-
label: "
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
id: "primary",
|
|
8
|
+
label: "Primary",
|
|
9
|
+
token: "--basalt-chart-1",
|
|
10
|
+
light: "217 91% 60%",
|
|
11
|
+
dark: "217 91% 65%"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
id: "sky",
|
|
15
|
+
label: "Sky",
|
|
16
|
+
token: "--basalt-chart-2",
|
|
17
|
+
light: "200 90% 55%",
|
|
18
|
+
dark: "200 90% 60%"
|
|
12
19
|
},
|
|
13
20
|
{
|
|
14
21
|
id: "teal",
|
|
15
22
|
label: "Teal",
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
23
|
+
token: "--basalt-chart-3",
|
|
24
|
+
light: "186 80% 45%",
|
|
25
|
+
dark: "186 80% 50%"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
id: "jade",
|
|
29
|
+
label: "Jade",
|
|
30
|
+
token: "--basalt-chart-4",
|
|
31
|
+
light: "166 72% 44%",
|
|
32
|
+
dark: "166 72% 50%"
|
|
19
33
|
},
|
|
20
34
|
{
|
|
21
35
|
id: "green",
|
|
22
36
|
label: "Green",
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
37
|
+
token: "--basalt-chart-5",
|
|
38
|
+
light: "142 71% 45%",
|
|
39
|
+
dark: "142 71% 50%"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: "lime",
|
|
43
|
+
label: "Lime",
|
|
44
|
+
token: "--basalt-chart-6",
|
|
45
|
+
light: "84 65% 46%",
|
|
46
|
+
dark: "84 65% 52%"
|
|
26
47
|
},
|
|
27
48
|
{
|
|
28
49
|
id: "amber",
|
|
29
50
|
label: "Amber",
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
51
|
+
token: "--basalt-chart-7",
|
|
52
|
+
light: "45 93% 47%",
|
|
53
|
+
dark: "45 93% 52%"
|
|
33
54
|
},
|
|
34
55
|
{
|
|
35
56
|
id: "orange",
|
|
36
57
|
label: "Orange",
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
58
|
+
token: "--basalt-chart-8",
|
|
59
|
+
light: "30 90% 55%",
|
|
60
|
+
dark: "30 90% 60%"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
id: "vermilion",
|
|
64
|
+
label: "Vermilion",
|
|
65
|
+
token: "--basalt-chart-9",
|
|
66
|
+
light: "15 85% 52%",
|
|
67
|
+
dark: "15 85% 57%"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
id: "red",
|
|
71
|
+
label: "Red",
|
|
72
|
+
token: "--basalt-chart-10",
|
|
73
|
+
light: "0 72% 51%",
|
|
74
|
+
dark: "0 72% 56%"
|
|
40
75
|
},
|
|
41
76
|
{
|
|
42
77
|
id: "rose",
|
|
43
78
|
label: "Rose",
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
79
|
+
token: "--basalt-chart-11",
|
|
80
|
+
light: "340 82% 55%",
|
|
81
|
+
dark: "340 82% 60%"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
id: "magenta",
|
|
85
|
+
label: "Magenta",
|
|
86
|
+
token: "--basalt-chart-12",
|
|
87
|
+
light: "320 70% 55%",
|
|
88
|
+
dark: "320 70% 60%"
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
id: "orchid",
|
|
92
|
+
label: "Orchid",
|
|
93
|
+
token: "--basalt-chart-13",
|
|
94
|
+
light: "290 65% 55%",
|
|
95
|
+
dark: "290 65% 60%"
|
|
47
96
|
},
|
|
48
97
|
{
|
|
49
98
|
id: "purple",
|
|
50
99
|
label: "Purple",
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
100
|
+
token: "--basalt-chart-14",
|
|
101
|
+
light: "270 70% 60%",
|
|
102
|
+
dark: "270 70% 65%"
|
|
54
103
|
},
|
|
55
104
|
{
|
|
56
105
|
id: "indigo",
|
|
57
106
|
label: "Indigo",
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
107
|
+
token: "--basalt-chart-15",
|
|
108
|
+
light: "250 65% 58%",
|
|
109
|
+
dark: "250 65% 63%"
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
id: "cobalt",
|
|
113
|
+
label: "Cobalt",
|
|
114
|
+
token: "--basalt-chart-16",
|
|
115
|
+
light: "230 70% 56%",
|
|
116
|
+
dark: "230 70% 61%"
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
id: "steel",
|
|
120
|
+
label: "Steel",
|
|
121
|
+
token: "--basalt-chart-17",
|
|
122
|
+
light: "210 55% 50%",
|
|
123
|
+
dark: "210 55% 56%"
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
id: "cadet",
|
|
127
|
+
label: "Cadet",
|
|
128
|
+
token: "--basalt-chart-18",
|
|
129
|
+
light: "195 45% 55%",
|
|
130
|
+
dark: "195 45% 60%"
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
id: "seafoam",
|
|
134
|
+
label: "Seafoam",
|
|
135
|
+
token: "--basalt-chart-19",
|
|
136
|
+
light: "160 50% 50%",
|
|
137
|
+
dark: "160 50% 55%"
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
id: "olive",
|
|
141
|
+
label: "Olive",
|
|
142
|
+
token: "--basalt-chart-20",
|
|
143
|
+
light: "100 50% 48%",
|
|
144
|
+
dark: "100 50% 53%"
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
id: "gold",
|
|
148
|
+
label: "Gold",
|
|
149
|
+
token: "--basalt-chart-21",
|
|
150
|
+
light: "60 65% 45%",
|
|
151
|
+
dark: "60 65% 50%"
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
id: "tangerine",
|
|
155
|
+
label: "Tangerine",
|
|
156
|
+
token: "--basalt-chart-22",
|
|
157
|
+
light: "22 80% 50%",
|
|
158
|
+
dark: "22 80% 55%"
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
id: "crimson",
|
|
162
|
+
label: "Crimson",
|
|
163
|
+
token: "--basalt-chart-23",
|
|
164
|
+
light: "350 65% 50%",
|
|
165
|
+
dark: "350 65% 55%"
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
id: "gray",
|
|
169
|
+
label: "Gray",
|
|
170
|
+
token: "--basalt-chart-24",
|
|
171
|
+
light: "0 0% 25%",
|
|
172
|
+
dark: "0 0% 65%"
|
|
61
173
|
}
|
|
62
|
-
], c = "
|
|
174
|
+
], c = "primary", l = "basalt-accent", u = e(null);
|
|
63
175
|
function d(e) {
|
|
64
176
|
return s.find((t) => t.id === e) ?? s[0];
|
|
65
177
|
}
|
|
66
|
-
function f(e
|
|
178
|
+
function f(e) {
|
|
179
|
+
return e <= .04045 ? e / 12.92 : ((e + .055) / 1.055) ** 2.4;
|
|
180
|
+
}
|
|
181
|
+
function p(e) {
|
|
182
|
+
let [t, n, r] = e.trim().split(/\s+/), i = Number(t), a = Number(n.replace("%", "")) / 100, o = Number(r.replace("%", "")) / 100, s = a * Math.min(o, 1 - o), c = (e) => {
|
|
183
|
+
let t = (e + i / 30) % 12;
|
|
184
|
+
return o - s * Math.max(Math.min(t - 3, 9 - t, 1), -1);
|
|
185
|
+
};
|
|
186
|
+
return .2126 * f(c(0)) + .7152 * f(c(8)) + .0722 * f(c(4)) > .35 ? "0 0% 10%" : "0 0% 100%";
|
|
187
|
+
}
|
|
188
|
+
function m(e, t = !1) {
|
|
67
189
|
let n = d(e), r = t ? n.dark : n.light, i = document.documentElement;
|
|
68
|
-
i.style.setProperty("--basalt-primary", r), i.style.setProperty("--basalt-primary-foreground",
|
|
190
|
+
i.style.setProperty("--basalt-primary", r), i.style.setProperty("--basalt-primary-foreground", p(r)), i.style.setProperty("--basalt-ring", r), i.dataset.accent = n.id;
|
|
69
191
|
}
|
|
70
|
-
function
|
|
192
|
+
function h() {
|
|
71
193
|
return d(window.localStorage.getItem(l)).id;
|
|
72
194
|
}
|
|
73
|
-
function
|
|
195
|
+
function g(e) {
|
|
74
196
|
return window.addEventListener("storage", e), () => window.removeEventListener("storage", e);
|
|
75
197
|
}
|
|
76
|
-
function
|
|
198
|
+
function _() {
|
|
77
199
|
return document.documentElement.classList.contains("dark");
|
|
78
200
|
}
|
|
79
|
-
function
|
|
80
|
-
let n = a(
|
|
201
|
+
function v({ children: e }) {
|
|
202
|
+
let n = a(g, h, () => c);
|
|
81
203
|
r(() => {
|
|
82
|
-
|
|
83
|
-
let e = new MutationObserver(() =>
|
|
204
|
+
m(n, _());
|
|
205
|
+
let e = new MutationObserver(() => m(n, _()));
|
|
84
206
|
return e.observe(document.documentElement, {
|
|
85
207
|
attributes: !0,
|
|
86
208
|
attributeFilter: ["class"]
|
|
87
209
|
}), () => e.disconnect();
|
|
88
210
|
}, [n]);
|
|
89
|
-
let
|
|
211
|
+
let f = t((e) => {
|
|
90
212
|
let t = d(e).id;
|
|
91
|
-
window.localStorage.setItem(l, t),
|
|
92
|
-
}, []),
|
|
213
|
+
window.localStorage.setItem(l, t), m(t, _()), window.dispatchEvent(new Event("storage"));
|
|
214
|
+
}, []), p = i(() => ({
|
|
93
215
|
accent: n,
|
|
94
|
-
setAccent:
|
|
216
|
+
setAccent: f,
|
|
95
217
|
swatches: s
|
|
96
|
-
}), [n,
|
|
218
|
+
}), [n, f]);
|
|
97
219
|
return /* @__PURE__ */ o(u.Provider, {
|
|
98
|
-
value:
|
|
220
|
+
value: p,
|
|
99
221
|
children: e
|
|
100
222
|
});
|
|
101
223
|
}
|
|
102
|
-
function
|
|
224
|
+
function y() {
|
|
103
225
|
let e = n(u);
|
|
104
226
|
if (!e) throw Error("useAccent must be used within AccentProvider");
|
|
105
227
|
return e;
|
|
106
228
|
}
|
|
107
229
|
//#endregion
|
|
108
|
-
export { s as ACCENT_SWATCHES,
|
|
230
|
+
export { s as ACCENT_SWATCHES, v as AccentProvider, c as DEFAULT_ACCENT_ID, p as accentForeground, d as accentSwatchById, m as applyAccent, y as useAccent };
|
|
109
231
|
|
|
110
232
|
//# sourceMappingURL=accent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accent.js","names":[],"sources":["../../src/providers/accent.tsx"],"sourcesContent":["import {\n\tcreateContext,\n\ttype ReactNode,\n\tuseCallback,\n\tuseContext,\n\tuseEffect,\n\tuseMemo,\n\tuseSyncExternalStore,\n} from \"react\";\n\nexport type AccentSwatch = {\n\tid: string;\n\tlabel: string;\n\tlight: string;\n\tdark: string;\n\tforeground: string;\n};\n\nexport const ACCENT_SWATCHES: readonly AccentSwatch[] = [\n\t{ id: \"blue\", label: \"Blue\", light: \"217 80% 36%\", dark: \"217 80% 38%\", foreground: \"0 0% 100%\" },\n\t{ id: \"teal\", label: \"Teal\", light: \"186 72% 28%\", dark: \"186 72% 32%\", foreground: \"0 0% 100%\" },\n\t{\n\t\tid: \"green\",\n\t\tlabel: \"Green\",\n\t\tlight: \"142 64% 28%\",\n\t\tdark: \"142 64% 32%\",\n\t\tforeground: \"0 0% 100%\",\n\t},\n\t{ id: \"amber\", label: \"Amber\", light: \"38 88% 44%\", dark: \"38 88% 56%\", foreground: \"0 0% 10%\" },\n\t{\n\t\tid: \"orange\",\n\t\tlabel: \"Orange\",\n\t\tlight: \"24 86% 36%\",\n\t\tdark: \"24 86% 38%\",\n\t\tforeground: \"0 0% 100%\",\n\t},\n\t{ id: \"rose\", label: \"Rose\", light: \"340 72% 36%\", dark: \"340 72% 38%\", foreground: \"0 0% 100%\" },\n\t{\n\t\tid: \"purple\",\n\t\tlabel: \"Purple\",\n\t\tlight: \"270 52% 36%\",\n\t\tdark: \"270 52% 38%\",\n\t\tforeground: \"0 0% 100%\",\n\t},\n\t{\n\t\tid: \"indigo\",\n\t\tlabel: \"Indigo\",\n\t\tlight: \"250 52% 36%\",\n\t\tdark: \"250 52% 38%\",\n\t\tforeground: \"0 0% 100%\",\n\t},\n] as const;\n\nexport const DEFAULT_ACCENT_ID = \"blue\";\nconst STORAGE_KEY = \"basalt-accent\";\n\ntype AccentContextValue = {\n\taccent: string;\n\tsetAccent: (id: string) => void;\n\tswatches: readonly AccentSwatch[];\n};\n\nconst AccentContext = createContext<AccentContextValue | null>(null);\n\nexport function accentSwatchById(id: string | null | undefined): AccentSwatch {\n\treturn ACCENT_SWATCHES.find((swatch) => swatch.id === id) ?? ACCENT_SWATCHES[0];\n}\n\nexport function applyAccent(id: string, dark = false) {\n\tconst swatch = accentSwatchById(id);\n\tconst value = dark ? swatch.dark : swatch.light;\n\tconst root = document.documentElement;\n\troot.style.setProperty(\"--basalt-primary\", value);\n\troot.style.setProperty(\"--basalt-primary-foreground\", swatch.foreground);\n\troot.style.setProperty(\"--basalt-ring\", value);\n\troot.style.setProperty(\"--basalt-chart-1\", value);\n\troot.dataset.accent = swatch.id;\n}\n\nfunction readAccent(): string {\n\treturn accentSwatchById(window.localStorage.getItem(STORAGE_KEY)).id;\n}\n\nfunction subscribe(onStoreChange: () => void) {\n\twindow.addEventListener(\"storage\", onStoreChange);\n\treturn () => window.removeEventListener(\"storage\", onStoreChange);\n}\n\nfunction isDarkMode(): boolean {\n\treturn document.documentElement.classList.contains(\"dark\");\n}\n\nexport function AccentProvider({ children }: { children: ReactNode }) {\n\tconst accent = useSyncExternalStore(subscribe, readAccent, () => DEFAULT_ACCENT_ID);\n\tuseEffect(() => {\n\t\tapplyAccent(accent, isDarkMode());\n\t\tconst observer = new MutationObserver(() => applyAccent(accent, isDarkMode()));\n\t\tobserver.observe(document.documentElement, { attributes: true, attributeFilter: [\"class\"] });\n\t\treturn () => observer.disconnect();\n\t}, [accent]);\n\tconst setAccent = useCallback((id: string) => {\n\t\tconst next = accentSwatchById(id).id;\n\t\twindow.localStorage.setItem(STORAGE_KEY, next);\n\t\tapplyAccent(next, isDarkMode());\n\t\twindow.dispatchEvent(new Event(\"storage\"));\n\t}, []);\n\tconst value = useMemo(\n\t\t() => ({ accent, setAccent, swatches: ACCENT_SWATCHES }),\n\t\t[accent, setAccent],\n\t);\n\treturn <AccentContext.Provider value={value}>{children}</AccentContext.Provider>;\n}\n\nexport function useAccent() {\n\tconst ctx = useContext(AccentContext);\n\tif (!ctx) {\n\t\tthrow new Error(\"useAccent must be used within AccentProvider\");\n\t}\n\treturn ctx;\n}\n"],"mappings":";;;;AAkBA,IAAa,IAA2C;CACvD;EAAE,IAAI;EAAQ,OAAO;EAAQ,OAAO;EAAe,MAAM;EAAe,YAAY;CAAY;CAChG;EAAE,IAAI;EAAQ,OAAO;EAAQ,OAAO;EAAe,MAAM;EAAe,YAAY;CAAY;CAChG;EACC,IAAI;EACJ,OAAO;EACP,OAAO;EACP,MAAM;EACN,YAAY;CACb;CACA;EAAE,IAAI;EAAS,OAAO;EAAS,OAAO;EAAc,MAAM;EAAc,YAAY;CAAW;CAC/F;EACC,IAAI;EACJ,OAAO;EACP,OAAO;EACP,MAAM;EACN,YAAY;CACb;CACA;EAAE,IAAI;EAAQ,OAAO;EAAQ,OAAO;EAAe,MAAM;EAAe,YAAY;CAAY;CAChG;EACC,IAAI;EACJ,OAAO;EACP,OAAO;EACP,MAAM;EACN,YAAY;CACb;CACA;EACC,IAAI;EACJ,OAAO;EACP,OAAO;EACP,MAAM;EACN,YAAY;CACb;AACD,GAEa,IAAoB,QAC3B,IAAc,iBAQd,IAAgB,EAAy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G,CAAC,CAAC,GACC,IAAQ,SACN;EAAE;EAAQ;EAAW,UAAU;CAAgB,IACtD,CAAC,GAAQ,CAAS,CACnB;CACA,OAAO,kBAAC,EAAc,UAAf;EAA+B;EAAQ;CAAiC,CAAA;AAChF;AAEA,SAAgB,IAAY;CAC3B,IAAM,IAAM,EAAW,CAAa;CACpC,IAAI,CAAC,GACJ,MAAU,MAAM,8CAA8C;CAE/D,OAAO;AACR"}
|
|
1
|
+
{"version":3,"file":"accent.js","names":[],"sources":["../../src/providers/accent.tsx"],"sourcesContent":["import {\n\tcreateContext,\n\ttype ReactNode,\n\tuseCallback,\n\tuseContext,\n\tuseEffect,\n\tuseMemo,\n\tuseSyncExternalStore,\n} from \"react\";\n\nexport type AccentSwatch = {\n\tid: string;\n\tlabel: string;\n\ttoken: string;\n\tlight: string;\n\tdark: string;\n};\n\nexport const ACCENT_SWATCHES: readonly AccentSwatch[] = [\n\t{\n\t\tid: \"primary\",\n\t\tlabel: \"Primary\",\n\t\ttoken: \"--basalt-chart-1\",\n\t\tlight: \"217 91% 60%\",\n\t\tdark: \"217 91% 65%\",\n\t},\n\t{ id: \"sky\", label: \"Sky\", token: \"--basalt-chart-2\", light: \"200 90% 55%\", dark: \"200 90% 60%\" },\n\t{\n\t\tid: \"teal\",\n\t\tlabel: \"Teal\",\n\t\ttoken: \"--basalt-chart-3\",\n\t\tlight: \"186 80% 45%\",\n\t\tdark: \"186 80% 50%\",\n\t},\n\t{\n\t\tid: \"jade\",\n\t\tlabel: \"Jade\",\n\t\ttoken: \"--basalt-chart-4\",\n\t\tlight: \"166 72% 44%\",\n\t\tdark: \"166 72% 50%\",\n\t},\n\t{\n\t\tid: \"green\",\n\t\tlabel: \"Green\",\n\t\ttoken: \"--basalt-chart-5\",\n\t\tlight: \"142 71% 45%\",\n\t\tdark: \"142 71% 50%\",\n\t},\n\t{ id: \"lime\", label: \"Lime\", token: \"--basalt-chart-6\", light: \"84 65% 46%\", dark: \"84 65% 52%\" },\n\t{\n\t\tid: \"amber\",\n\t\tlabel: \"Amber\",\n\t\ttoken: \"--basalt-chart-7\",\n\t\tlight: \"45 93% 47%\",\n\t\tdark: \"45 93% 52%\",\n\t},\n\t{\n\t\tid: \"orange\",\n\t\tlabel: \"Orange\",\n\t\ttoken: \"--basalt-chart-8\",\n\t\tlight: \"30 90% 55%\",\n\t\tdark: \"30 90% 60%\",\n\t},\n\t{\n\t\tid: \"vermilion\",\n\t\tlabel: \"Vermilion\",\n\t\ttoken: \"--basalt-chart-9\",\n\t\tlight: \"15 85% 52%\",\n\t\tdark: \"15 85% 57%\",\n\t},\n\t{ id: \"red\", label: \"Red\", token: \"--basalt-chart-10\", light: \"0 72% 51%\", dark: \"0 72% 56%\" },\n\t{\n\t\tid: \"rose\",\n\t\tlabel: \"Rose\",\n\t\ttoken: \"--basalt-chart-11\",\n\t\tlight: \"340 82% 55%\",\n\t\tdark: \"340 82% 60%\",\n\t},\n\t{\n\t\tid: \"magenta\",\n\t\tlabel: \"Magenta\",\n\t\ttoken: \"--basalt-chart-12\",\n\t\tlight: \"320 70% 55%\",\n\t\tdark: \"320 70% 60%\",\n\t},\n\t{\n\t\tid: \"orchid\",\n\t\tlabel: \"Orchid\",\n\t\ttoken: \"--basalt-chart-13\",\n\t\tlight: \"290 65% 55%\",\n\t\tdark: \"290 65% 60%\",\n\t},\n\t{\n\t\tid: \"purple\",\n\t\tlabel: \"Purple\",\n\t\ttoken: \"--basalt-chart-14\",\n\t\tlight: \"270 70% 60%\",\n\t\tdark: \"270 70% 65%\",\n\t},\n\t{\n\t\tid: \"indigo\",\n\t\tlabel: \"Indigo\",\n\t\ttoken: \"--basalt-chart-15\",\n\t\tlight: \"250 65% 58%\",\n\t\tdark: \"250 65% 63%\",\n\t},\n\t{\n\t\tid: \"cobalt\",\n\t\tlabel: \"Cobalt\",\n\t\ttoken: \"--basalt-chart-16\",\n\t\tlight: \"230 70% 56%\",\n\t\tdark: \"230 70% 61%\",\n\t},\n\t{\n\t\tid: \"steel\",\n\t\tlabel: \"Steel\",\n\t\ttoken: \"--basalt-chart-17\",\n\t\tlight: \"210 55% 50%\",\n\t\tdark: \"210 55% 56%\",\n\t},\n\t{\n\t\tid: \"cadet\",\n\t\tlabel: \"Cadet\",\n\t\ttoken: \"--basalt-chart-18\",\n\t\tlight: \"195 45% 55%\",\n\t\tdark: \"195 45% 60%\",\n\t},\n\t{\n\t\tid: \"seafoam\",\n\t\tlabel: \"Seafoam\",\n\t\ttoken: \"--basalt-chart-19\",\n\t\tlight: \"160 50% 50%\",\n\t\tdark: \"160 50% 55%\",\n\t},\n\t{\n\t\tid: \"olive\",\n\t\tlabel: \"Olive\",\n\t\ttoken: \"--basalt-chart-20\",\n\t\tlight: \"100 50% 48%\",\n\t\tdark: \"100 50% 53%\",\n\t},\n\t{\n\t\tid: \"gold\",\n\t\tlabel: \"Gold\",\n\t\ttoken: \"--basalt-chart-21\",\n\t\tlight: \"60 65% 45%\",\n\t\tdark: \"60 65% 50%\",\n\t},\n\t{\n\t\tid: \"tangerine\",\n\t\tlabel: \"Tangerine\",\n\t\ttoken: \"--basalt-chart-22\",\n\t\tlight: \"22 80% 50%\",\n\t\tdark: \"22 80% 55%\",\n\t},\n\t{\n\t\tid: \"crimson\",\n\t\tlabel: \"Crimson\",\n\t\ttoken: \"--basalt-chart-23\",\n\t\tlight: \"350 65% 50%\",\n\t\tdark: \"350 65% 55%\",\n\t},\n\t{ id: \"gray\", label: \"Gray\", token: \"--basalt-chart-24\", light: \"0 0% 25%\", dark: \"0 0% 65%\" },\n] as const;\n\nexport const DEFAULT_ACCENT_ID = \"primary\";\nconst STORAGE_KEY = \"basalt-accent\";\n\ntype AccentContextValue = {\n\taccent: string;\n\tsetAccent: (id: string) => void;\n\tswatches: readonly AccentSwatch[];\n};\n\nconst AccentContext = createContext<AccentContextValue | null>(null);\n\nexport function accentSwatchById(id: string | null | undefined): AccentSwatch {\n\treturn ACCENT_SWATCHES.find((swatch) => swatch.id === id) ?? ACCENT_SWATCHES[0];\n}\n\nfunction channel(c: number) {\n\treturn c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;\n}\n\nexport function accentForeground(hsl: string) {\n\tconst [hue, sat, light] = hsl.trim().split(/\\s+/);\n\tconst h = Number(hue);\n\tconst s = Number(sat.replace(\"%\", \"\")) / 100;\n\tconst l = Number(light.replace(\"%\", \"\")) / 100;\n\tconst a = s * Math.min(l, 1 - l);\n\tconst f = (n: number) => {\n\t\tconst k = (n + h / 30) % 12;\n\t\treturn l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);\n\t};\n\tconst luminance = 0.2126 * channel(f(0)) + 0.7152 * channel(f(8)) + 0.0722 * channel(f(4));\n\treturn luminance > 0.35 ? \"0 0% 10%\" : \"0 0% 100%\";\n}\n\nexport function applyAccent(id: string, dark = false) {\n\tconst swatch = accentSwatchById(id);\n\tconst value = dark ? swatch.dark : swatch.light;\n\tconst root = document.documentElement;\n\troot.style.setProperty(\"--basalt-primary\", value);\n\troot.style.setProperty(\"--basalt-primary-foreground\", accentForeground(value));\n\troot.style.setProperty(\"--basalt-ring\", value);\n\troot.dataset.accent = swatch.id;\n}\n\nfunction readAccent(): string {\n\treturn accentSwatchById(window.localStorage.getItem(STORAGE_KEY)).id;\n}\n\nfunction subscribe(onStoreChange: () => void) {\n\twindow.addEventListener(\"storage\", onStoreChange);\n\treturn () => window.removeEventListener(\"storage\", onStoreChange);\n}\n\nfunction isDarkMode(): boolean {\n\treturn document.documentElement.classList.contains(\"dark\");\n}\n\nexport function AccentProvider({ children }: { children: ReactNode }) {\n\tconst accent = useSyncExternalStore(subscribe, readAccent, () => DEFAULT_ACCENT_ID);\n\tuseEffect(() => {\n\t\tapplyAccent(accent, isDarkMode());\n\t\tconst observer = new MutationObserver(() => applyAccent(accent, isDarkMode()));\n\t\tobserver.observe(document.documentElement, { attributes: true, attributeFilter: [\"class\"] });\n\t\treturn () => observer.disconnect();\n\t}, [accent]);\n\tconst setAccent = useCallback((id: string) => {\n\t\tconst next = accentSwatchById(id).id;\n\t\twindow.localStorage.setItem(STORAGE_KEY, next);\n\t\tapplyAccent(next, isDarkMode());\n\t\twindow.dispatchEvent(new Event(\"storage\"));\n\t}, []);\n\tconst value = useMemo(\n\t\t() => ({ accent, setAccent, swatches: ACCENT_SWATCHES }),\n\t\t[accent, setAccent],\n\t);\n\treturn <AccentContext.Provider value={value}>{children}</AccentContext.Provider>;\n}\n\nexport function useAccent() {\n\tconst ctx = useContext(AccentContext);\n\tif (!ctx) {\n\t\tthrow new Error(\"useAccent must be used within AccentProvider\");\n\t}\n\treturn ctx;\n}\n"],"mappings":";;;;AAkBA,IAAa,IAA2C;CACvD;EACC,IAAI;EACJ,OAAO;EACP,OAAO;EACP,OAAO;EACP,MAAM;CACP;CACA;EAAE,IAAI;EAAO,OAAO;EAAO,OAAO;EAAoB,OAAO;EAAe,MAAM;CAAc;CAChG;EACC,IAAI;EACJ,OAAO;EACP,OAAO;EACP,OAAO;EACP,MAAM;CACP;CACA;EACC,IAAI;EACJ,OAAO;EACP,OAAO;EACP,OAAO;EACP,MAAM;CACP;CACA;EACC,IAAI;EACJ,OAAO;EACP,OAAO;EACP,OAAO;EACP,MAAM;CACP;CACA;EAAE,IAAI;EAAQ,OAAO;EAAQ,OAAO;EAAoB,OAAO;EAAc,MAAM;CAAa;CAChG;EACC,IAAI;EACJ,OAAO;EACP,OAAO;EACP,OAAO;EACP,MAAM;CACP;CACA;EACC,IAAI;EACJ,OAAO;EACP,OAAO;EACP,OAAO;EACP,MAAM;CACP;CACA;EACC,IAAI;EACJ,OAAO;EACP,OAAO;EACP,OAAO;EACP,MAAM;CACP;CACA;EAAE,IAAI;EAAO,OAAO;EAAO,OAAO;EAAqB,OAAO;EAAa,MAAM;CAAY;CAC7F;EACC,IAAI;EACJ,OAAO;EACP,OAAO;EACP,OAAO;EACP,MAAM;CACP;CACA;EACC,IAAI;EACJ,OAAO;EACP,OAAO;EACP,OAAO;EACP,MAAM;CACP;CACA;EACC,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