eidos-ui 2.1.0 → 3.1.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.
Files changed (56) hide show
  1. package/README.md +66 -16
  2. package/dist/ThemeProvider.types-DgXN0gEH.d.cts +88 -0
  3. package/dist/ThemeProvider.types-DgXN0gEH.d.ts +88 -0
  4. package/dist/chunk-2ZY7M72Q.js +521 -0
  5. package/dist/chunk-2ZY7M72Q.js.map +1 -0
  6. package/dist/{chunk-W6IKHJ76.cjs → chunk-5BX4Q76D.cjs} +134 -126
  7. package/dist/chunk-5BX4Q76D.cjs.map +1 -0
  8. package/dist/{chunk-RAZRQ57B.js → chunk-74MBKLYI.js} +97 -16
  9. package/dist/chunk-74MBKLYI.js.map +1 -0
  10. package/dist/chunk-H5HWFOWZ.js +390 -0
  11. package/dist/chunk-H5HWFOWZ.js.map +1 -0
  12. package/dist/{chunk-VHQTDITV.cjs → chunk-KQD7CQ4Z.cjs} +96 -15
  13. package/dist/chunk-KQD7CQ4Z.cjs.map +1 -0
  14. package/dist/{chunk-JV7Z3D3U.js → chunk-LEMCJW57.js} +134 -126
  15. package/dist/chunk-LEMCJW57.js.map +1 -0
  16. package/dist/chunk-SE7MWOC7.cjs +390 -0
  17. package/dist/chunk-SE7MWOC7.cjs.map +1 -0
  18. package/dist/chunk-U5FHQ73U.cjs +521 -0
  19. package/dist/chunk-U5FHQ73U.cjs.map +1 -0
  20. package/dist/color-picker/index.cjs +2 -2
  21. package/dist/color-picker/index.js +1 -1
  22. package/dist/fonts/JetBrains-Mono-OFL.txt +93 -0
  23. package/dist/fonts/Plus-Jakarta-Sans-OFL.txt +93 -0
  24. package/dist/fonts/jetbrains-mono-latin-ext-wght-normal.woff2 +0 -0
  25. package/dist/fonts/jetbrains-mono-latin-wght-normal.woff2 +0 -0
  26. package/dist/fonts/plus-jakarta-sans-latin-ext-wght-normal.woff2 +0 -0
  27. package/dist/fonts/plus-jakarta-sans-latin-wght-normal.woff2 +0 -0
  28. package/dist/fonts.css +32 -0
  29. package/dist/fonts.css.d.ts +2 -0
  30. package/dist/index.cjs +32 -6
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.css +467 -123
  33. package/dist/index.d.cts +3 -0
  34. package/dist/index.d.ts +3 -0
  35. package/dist/index.js +35 -9
  36. package/dist/tabs/index.cjs +2 -2
  37. package/dist/tabs/index.d.cts +11 -0
  38. package/dist/tabs/index.d.ts +11 -0
  39. package/dist/tabs/index.js +1 -1
  40. package/dist/theme-editor/index.cjs +22 -0
  41. package/dist/theme-editor/index.cjs.map +1 -0
  42. package/dist/theme-editor/index.d.cts +65 -0
  43. package/dist/theme-editor/index.d.ts +65 -0
  44. package/dist/theme-editor/index.js +22 -0
  45. package/dist/theme-editor/index.js.map +1 -0
  46. package/dist/theme-provider/index.cjs +27 -0
  47. package/dist/theme-provider/index.cjs.map +1 -0
  48. package/dist/theme-provider/index.d.cts +123 -0
  49. package/dist/theme-provider/index.d.ts +123 -0
  50. package/dist/theme-provider/index.js +27 -0
  51. package/dist/theme-provider/index.js.map +1 -0
  52. package/package.json +13 -3
  53. package/dist/chunk-JV7Z3D3U.js.map +0 -1
  54. package/dist/chunk-RAZRQ57B.js.map +0 -1
  55. package/dist/chunk-VHQTDITV.cjs.map +0 -1
  56. package/dist/chunk-W6IKHJ76.cjs.map +0 -1
@@ -0,0 +1,521 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+ var _chunkGEHL4LKKcjs = require('./chunk-GEHL4LKK.cjs');
4
+
5
+ // src/components/ThemeProvider/ThemeProvider.component.tsx
6
+ var _react = require('react');
7
+
8
+ // src/components/ThemeProvider/ThemeProvider.context.tsx
9
+
10
+ var ThemeContext = _react.createContext.call(void 0, void 0);
11
+ var useTheme = () => {
12
+ const context = _react.useContext.call(void 0, ThemeContext);
13
+ if (!context) {
14
+ throw new Error("useTheme must be used within a ThemeProvider");
15
+ }
16
+ return context;
17
+ };
18
+
19
+ // src/components/ThemeProvider/ThemeProvider.color.ts
20
+ var srgbToLinear = (v) => v <= 0.04045 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);
21
+ var linearToSrgb = (v) => v <= 31308e-7 ? 12.92 * v : 1.055 * Math.pow(v, 1 / 2.4) - 0.055;
22
+ var clamp01 = (v) => v < 0 ? 0 : v > 1 ? 1 : v;
23
+ var parseHex = (hex) => {
24
+ if (typeof hex !== "string") return null;
25
+ const raw = hex.trim().replace(/^#/, "");
26
+ const full = raw.length === 3 ? raw.split("").map((c) => c + c).join("") : raw;
27
+ if (!/^[0-9a-fA-F]{6}$/.test(full)) return null;
28
+ const n = parseInt(full, 16);
29
+ return [(n >> 16 & 255) / 255, (n >> 8 & 255) / 255, (n & 255) / 255];
30
+ };
31
+ var isValidHex = (hex) => parseHex(hex) !== null;
32
+ var toHex = ([r, g, b]) => "#" + [r, g, b].map(
33
+ (v) => Math.round(clamp01(v) * 255).toString(16).padStart(2, "0")
34
+ ).join("");
35
+ var hexToRgbTriple = (hex) => {
36
+ const rgb = parseHex(hex);
37
+ if (!rgb) return "0, 0, 0";
38
+ return rgb.map((v) => Math.round(v * 255)).join(", ");
39
+ };
40
+ var linearToOklab = ([r, g, b]) => {
41
+ const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
42
+ const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
43
+ const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
44
+ return [
45
+ 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s,
46
+ 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s,
47
+ 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s
48
+ ];
49
+ };
50
+ var oklabToLinear = ([L, A, B]) => {
51
+ const l = (L + 0.3963377774 * A + 0.2158037573 * B) ** 3;
52
+ const m = (L - 0.1055613458 * A - 0.0638541728 * B) ** 3;
53
+ const s = (L - 0.0894841775 * A - 1.291485548 * B) ** 3;
54
+ return [
55
+ 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,
56
+ -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,
57
+ -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s
58
+ ];
59
+ };
60
+ var hexToOklch = (hex) => {
61
+ const rgb = _nullishCoalesce(parseHex(hex), () => ( [0, 0, 0]));
62
+ const [l, a, b] = linearToOklab(rgb.map(srgbToLinear));
63
+ return { l, c: Math.hypot(a, b), h: Math.atan2(b, a) };
64
+ };
65
+ var inGamut = ([r, g, b]) => [r, g, b].every((v) => v >= -1e-4 && v <= 1 + 1e-4);
66
+ var maxChroma = (l, h) => {
67
+ let lo = 0;
68
+ let hi = 0.45;
69
+ for (let i = 0; i < 24; i++) {
70
+ const mid = (lo + hi) / 2;
71
+ if (inGamut(oklabToLinear([l, mid * Math.cos(h), mid * Math.sin(h)]))) lo = mid;
72
+ else hi = mid;
73
+ }
74
+ return lo;
75
+ };
76
+ var oklchToHex = ({ l, c, h }) => {
77
+ const lc = clamp01(l);
78
+ const cc = Math.min(Math.max(c, 0), maxChroma(lc, h));
79
+ return toHex(
80
+ oklabToLinear([lc, cc * Math.cos(h), cc * Math.sin(h)]).map(linearToSrgb)
81
+ );
82
+ };
83
+ var relativeLuminance = (hex) => {
84
+ const [r, g, b] = (_nullishCoalesce(parseHex(hex), () => ( [0, 0, 0]))).map(srgbToLinear);
85
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b;
86
+ };
87
+ var contrastRatio = (a, b) => {
88
+ const [x, y] = [relativeLuminance(a), relativeLuminance(b)];
89
+ return (Math.max(x, y) + 0.05) / (Math.min(x, y) + 0.05);
90
+ };
91
+ var CONTRAST_LIGHT = "#ffffff";
92
+ var CONTRAST_DARK = "#0f172a";
93
+ var pickContrast = (fill) => {
94
+ const onLight = contrastRatio(fill, CONTRAST_LIGHT);
95
+ if (onLight >= 3) return CONTRAST_LIGHT;
96
+ return onLight >= contrastRatio(fill, CONTRAST_DARK) ? CONTRAST_LIGHT : CONTRAST_DARK;
97
+ };
98
+ var RAMP_STEPS = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900];
99
+ var BASE_STEP = 500;
100
+ var RAMP_CURVE = {
101
+ 50: { l: 0.962, chroma: 0.09 },
102
+ 100: { l: 0.93, chroma: 0.16 },
103
+ 200: { l: 0.87, chroma: 0.3 },
104
+ 300: { l: 0.785, chroma: 0.51 },
105
+ 400: { l: 0.68, chroma: 0.77 },
106
+ 500: { l: 0.558, chroma: 1 },
107
+ 600: { l: 0.511, chroma: 1.12 },
108
+ 700: { l: 0.457, chroma: 1.05 },
109
+ 800: { l: 0.398, chroma: 0.87 },
110
+ 900: { l: 0.359, chroma: 0.66 }
111
+ };
112
+ var LIGHT_CEILING = 0.985;
113
+ var DARK_FLOOR = 0.22;
114
+ var MIN_STEP_DELTA = 0.012;
115
+ var buildRamp = (base) => {
116
+ const { l: baseL, c: baseC, h } = hexToOklch(base);
117
+ const anchor = RAMP_CURVE[BASE_STEP].l;
118
+ const lightSpan = RAMP_CURVE[50].l - anchor;
119
+ const darkSpan = anchor - RAMP_CURVE[900].l;
120
+ const lightScale = lightSpan > 0 ? Math.min(1, Math.max(0, LIGHT_CEILING - baseL) / lightSpan) : 0;
121
+ const darkScale = darkSpan > 0 ? Math.min(1, Math.max(0, baseL - DARK_FLOOR) / darkSpan) : 0;
122
+ const out = {};
123
+ for (const step of RAMP_STEPS) {
124
+ if (step === BASE_STEP) {
125
+ out[step] = base;
126
+ continue;
127
+ }
128
+ const { l: curveL, chroma } = RAMP_CURVE[step];
129
+ const offset = curveL - anchor;
130
+ const l = baseL + offset * (offset > 0 ? lightScale : darkScale);
131
+ out[step] = oklchToHex({ l, c: baseC * chroma, h });
132
+ }
133
+ return enforceSeparation(out, h, baseC);
134
+ };
135
+ var enforceSeparation = (ramp, h, baseC) => {
136
+ const baseIndex = RAMP_STEPS.indexOf(BASE_STEP);
137
+ const lightness = RAMP_STEPS.map((s) => hexToOklch(ramp[s]).l);
138
+ for (let i = baseIndex - 1; i >= 0; i--) {
139
+ const limit = lightness[i + 1] + MIN_STEP_DELTA;
140
+ if (lightness[i] < limit) lightness[i] = Math.min(1, limit);
141
+ }
142
+ for (let i = baseIndex + 1; i < RAMP_STEPS.length; i++) {
143
+ const limit = lightness[i - 1] - MIN_STEP_DELTA;
144
+ if (lightness[i] > limit) lightness[i] = Math.max(0, limit);
145
+ }
146
+ const out = {};
147
+ RAMP_STEPS.forEach((step, i) => {
148
+ if (step === BASE_STEP) {
149
+ out[step] = ramp[step];
150
+ return;
151
+ }
152
+ out[step] = oklchToHex({
153
+ l: lightness[i],
154
+ c: baseC * RAMP_CURVE[step].chroma,
155
+ h
156
+ });
157
+ });
158
+ return out;
159
+ };
160
+ var DARK_DELTA = 0.086;
161
+ var LIGHT_DELTA = 0.169;
162
+ var HOVER_INVERT_BELOW = DARK_DELTA * 1.5;
163
+ var deriveDark = (base) => {
164
+ const { l, c, h } = hexToOklch(base);
165
+ const target = l < HOVER_INVERT_BELOW ? l + DARK_DELTA : l - DARK_DELTA;
166
+ return oklchToHex({ l: target, c, h });
167
+ };
168
+ var deriveLight = (base) => {
169
+ const { l, c, h } = hexToOklch(base);
170
+ return oklchToHex({ l: Math.min(LIGHT_CEILING, l + LIGHT_DELTA), c, h });
171
+ };
172
+ var isRampViable = (base) => {
173
+ const { l } = hexToOklch(base);
174
+ return l < 0.95 && l > 0.12;
175
+ };
176
+
177
+ // src/components/ThemeProvider/ThemeProvider.tokens.ts
178
+ var THEME_COLOR_KEYS = [
179
+ "primary",
180
+ "secondary",
181
+ "success",
182
+ "danger",
183
+ "warning",
184
+ "info",
185
+ "hyperlink"
186
+ ];
187
+ var FILL_COLOR_KEYS = [
188
+ "primary",
189
+ "secondary",
190
+ "success",
191
+ "danger",
192
+ "warning",
193
+ "info"
194
+ ];
195
+ var RAMP_COLOR_KEY = "primary";
196
+ var FONT_SIZE_STEPS = [
197
+ ["xs", 0.75],
198
+ ["sm", 0.875],
199
+ ["base", 1],
200
+ ["md", 1.1],
201
+ ["lg", 1.125],
202
+ ["xl", 1.25],
203
+ ["2xl", 1.5],
204
+ ["3xl", 1.875]
205
+ ];
206
+ var defaultTheme = {
207
+ colors: {
208
+ primary: "#5c5de8",
209
+ secondary: "#617087",
210
+ success: "#007f57",
211
+ danger: "#d6272f",
212
+ warning: "#9c6300",
213
+ info: "#007a90",
214
+ hyperlink: "#007b84"
215
+ },
216
+ typography: {
217
+ fontFamily: "'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif",
218
+ monoFamily: "'JetBrains Mono', 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', 'Source Code Pro', monospace",
219
+ fontScale: 1
220
+ }
221
+ };
222
+ var DEFAULT_PRIMARY_RAMP = {
223
+ 50: "#eef2ff",
224
+ 100: "#e0e7ff",
225
+ 200: "#c7d2fe",
226
+ 300: "#a5b4fc",
227
+ 400: "#818cf8",
228
+ 500: "#5c5de8",
229
+ 600: "#4f46e5",
230
+ 700: "#4338ca",
231
+ 800: "#3730a3",
232
+ 900: "#312e81"
233
+ };
234
+ var FONT_SCALE_MIN = 0.875;
235
+ var FONT_SCALE_MAX = 1.25;
236
+ var normalizeColor = (value) => typeof value === "string" ? { base: value } : value;
237
+ var resolveTheme = (theme) => {
238
+ const colors = {};
239
+ for (const key of THEME_COLOR_KEYS) {
240
+ const supplied = _optionalChain([theme, 'access', _ => _.colors, 'optionalAccess', _2 => _2[key]]);
241
+ const fallback = normalizeColor(defaultTheme.colors[key]);
242
+ if (supplied === void 0) {
243
+ colors[key] = fallback;
244
+ continue;
245
+ }
246
+ const { base, contrast } = normalizeColor(supplied);
247
+ if (!isValidHex(base)) {
248
+ _chunkGEHL4LKKcjs.devWarn.call(void 0,
249
+ `theme-color-${key}`,
250
+ `ThemeProvider: colors.${key} is not a valid hex colour (received ${JSON.stringify(base)}). Falling back to the preset.`
251
+ );
252
+ colors[key] = fallback;
253
+ continue;
254
+ }
255
+ if (contrast !== void 0 && !isValidHex(contrast)) {
256
+ _chunkGEHL4LKKcjs.devWarn.call(void 0,
257
+ `theme-contrast-${key}`,
258
+ `ThemeProvider: colors.${key}.contrast is not a valid hex colour (received ${JSON.stringify(contrast)}). It will be computed instead.`
259
+ );
260
+ colors[key] = { base };
261
+ continue;
262
+ }
263
+ colors[key] = contrast === void 0 ? { base } : { base, contrast };
264
+ }
265
+ const scale = _optionalChain([theme, 'access', _3 => _3.typography, 'optionalAccess', _4 => _4.fontScale]);
266
+ let fontScale = defaultTheme.typography.fontScale;
267
+ if (scale !== void 0) {
268
+ if (!Number.isFinite(scale) || scale < FONT_SCALE_MIN || scale > FONT_SCALE_MAX) {
269
+ _chunkGEHL4LKKcjs.devWarn.call(void 0,
270
+ "theme-font-scale",
271
+ `ThemeProvider: typography.fontScale must be between ${FONT_SCALE_MIN} and ${FONT_SCALE_MAX} (received ${String(scale)}). Falling back to ${fontScale}.`
272
+ );
273
+ } else {
274
+ fontScale = scale;
275
+ }
276
+ }
277
+ return {
278
+ colors,
279
+ typography: {
280
+ fontFamily: _optionalChain([theme, 'access', _5 => _5.typography, 'optionalAccess', _6 => _6.fontFamily]) || defaultTheme.typography.fontFamily,
281
+ monoFamily: _optionalChain([theme, 'access', _7 => _7.typography, 'optionalAccess', _8 => _8.monoFamily]) || defaultTheme.typography.monoFamily,
282
+ fontScale
283
+ }
284
+ };
285
+ };
286
+ var buildTokens = (resolved) => {
287
+ const tokens = {};
288
+ for (const key of THEME_COLOR_KEYS) {
289
+ const { base, contrast } = resolved.colors[key];
290
+ tokens[`--${key}-color`] = base;
291
+ tokens[`--${key}-rgb`] = hexToRgbTriple(base);
292
+ tokens[`--${key}-dark`] = deriveDark(base);
293
+ tokens[`--${key}-light`] = deriveLight(base);
294
+ if (FILL_COLOR_KEYS.includes(key)) {
295
+ tokens[`--${key}-contrast`] = _nullishCoalesce(contrast, () => ( pickContrast(base)));
296
+ }
297
+ if (key === RAMP_COLOR_KEY) {
298
+ const isPreset = base === normalizeColor(defaultTheme.colors[key]).base;
299
+ const ramp = isPreset ? DEFAULT_PRIMARY_RAMP : buildRamp(base);
300
+ if (!isPreset && !isRampViable(base)) {
301
+ _chunkGEHL4LKKcjs.devWarn.call(void 0,
302
+ `theme-ramp-${key}`,
303
+ `ThemeProvider: colors.${key} (${base}) is too light or too dark to generate a usable --${key}-50\u2026900 scale; several steps will be identical. Pick a colour with more headroom.`
304
+ );
305
+ }
306
+ for (const step of RAMP_STEPS) {
307
+ tokens[`--${key}-${step}`] = ramp[step];
308
+ }
309
+ }
310
+ }
311
+ const { fontFamily, monoFamily, fontScale } = resolved.typography;
312
+ tokens["--font-family-primary"] = fontFamily;
313
+ tokens["--font-family-mono"] = monoFamily;
314
+ for (const [name, rem] of FONT_SIZE_STEPS) {
315
+ tokens[`--font-size-${name}`] = `${parseFloat((rem * fontScale).toFixed(4))}rem`;
316
+ }
317
+ return tokens;
318
+ };
319
+ var DEFAULT_TOKENS = buildTokens(resolveTheme(defaultTheme));
320
+ var diffFromDefault = (tokens) => {
321
+ const diff = {};
322
+ for (const [name, value] of Object.entries(tokens)) {
323
+ if (DEFAULT_TOKENS[name] !== value) diff[name] = value;
324
+ }
325
+ return diff;
326
+ };
327
+ var themeToCss = (resolved) => {
328
+ const tokens = buildTokens(resolved);
329
+ const body = Object.entries(tokens).map(([name, value]) => ` ${name}: ${value};`).join("\n");
330
+ return `:root {
331
+ ${body}
332
+ }`;
333
+ };
334
+
335
+ // src/components/ThemeProvider/ThemeProvider.component.tsx
336
+ var _jsxruntime = require('react/jsx-runtime');
337
+ var EMPTY_THEME = {};
338
+ var mountedProviders = 0;
339
+ var mergeTheme = (base, patch) => ({
340
+ colors: { ...base.colors, ...patch.colors },
341
+ typography: { ...base.typography, ...patch.typography }
342
+ });
343
+ var ThemeProvider = ({
344
+ children,
345
+ theme: controlledTheme,
346
+ defaultTheme: initialTheme,
347
+ onThemeChange
348
+ }) => {
349
+ const isControlled = controlledTheme !== void 0;
350
+ const [uncontrolledTheme, setUncontrolledTheme] = _react.useState.call(void 0,
351
+ _nullishCoalesce(initialTheme, () => ( EMPTY_THEME))
352
+ );
353
+ const theme = isControlled ? controlledTheme : uncontrolledTheme;
354
+ _react.useEffect.call(void 0, () => {
355
+ mountedProviders += 1;
356
+ if (mountedProviders > 1) {
357
+ _chunkGEHL4LKKcjs.devWarn.call(void 0,
358
+ "theme-multiple-providers",
359
+ `ThemeProvider: ${mountedProviders} providers are mounted at once. They all write to document.documentElement, so the last one to apply each token wins for the whole page - nested or sibling providers cannot theme separate subtrees. Use a single provider at your app root.`
360
+ );
361
+ }
362
+ return () => {
363
+ mountedProviders -= 1;
364
+ };
365
+ }, []);
366
+ const resolvedTheme = _react.useMemo.call(void 0, () => resolveTheme(theme), [theme]);
367
+ const tokens = _react.useMemo.call(void 0, () => diffFromDefault(buildTokens(resolvedTheme)), [resolvedTheme]);
368
+ const appliedRef = _react.useRef.call(void 0, []);
369
+ _react.useLayoutEffect.call(void 0, () => {
370
+ if (typeof document === "undefined") return;
371
+ const root = document.documentElement;
372
+ for (const name of appliedRef.current) {
373
+ if (!(name in tokens)) root.style.removeProperty(name);
374
+ }
375
+ for (const [name, value2] of Object.entries(tokens)) {
376
+ root.style.setProperty(name, value2);
377
+ }
378
+ appliedRef.current = Object.keys(tokens);
379
+ return () => {
380
+ for (const name of appliedRef.current) {
381
+ root.style.removeProperty(name);
382
+ }
383
+ appliedRef.current = [];
384
+ };
385
+ }, [tokens]);
386
+ const commit = _react.useCallback.call(void 0,
387
+ (next) => {
388
+ if (!isControlled) setUncontrolledTheme(next);
389
+ _optionalChain([onThemeChange, 'optionalCall', _9 => _9(next)]);
390
+ },
391
+ [isControlled, onThemeChange]
392
+ );
393
+ const setTheme = _react.useCallback.call(void 0, (next) => commit(next), [commit]);
394
+ const updateTheme = _react.useCallback.call(void 0,
395
+ (patch) => commit(mergeTheme(theme, patch)),
396
+ [commit, theme]
397
+ );
398
+ const resetTheme = _react.useCallback.call(void 0, () => commit(EMPTY_THEME), [commit]);
399
+ const toCss = _react.useCallback.call(void 0, () => themeToCss(resolvedTheme), [resolvedTheme]);
400
+ const value = _react.useMemo.call(void 0,
401
+ () => ({
402
+ theme,
403
+ resolvedTheme,
404
+ setTheme,
405
+ updateTheme,
406
+ resetTheme,
407
+ isDefault: Object.keys(tokens).length === 0,
408
+ toCss
409
+ }),
410
+ [theme, resolvedTheme, setTheme, updateTheme, resetTheme, tokens, toCss]
411
+ );
412
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, ThemeContext.Provider, { value, children });
413
+ };
414
+ ThemeProvider.displayName = "ThemeProvider";
415
+
416
+ // src/components/ThemeProvider/ThemeProvider.fonts.ts
417
+ var familyNameFromFile = (filename) => {
418
+ const base = filename.replace(/\.[^.]+$/, "");
419
+ const cleaned = base.replace(/[-_](regular|normal|book|roman)$/i, "").replace(/[-_]+/g, " ").replace(/["'\\]/g, "").replace(/\s+/g, " ").trim();
420
+ return cleaned || "Custom Font";
421
+ };
422
+ var quoteFamily = (family) => /^[a-zA-Z][a-zA-Z0-9-]*$/.test(family) ? family : `'${family}'`;
423
+ var toFontStack = (family, mono = false) => mono ? `${quoteFamily(family)}, 'SF Mono', Monaco, monospace` : `${quoteFamily(family)}, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif`;
424
+ var FONT_ACCEPT = ".woff2,.woff,.ttf,.otf";
425
+ var SUPPORTED_EXTENSIONS = /\.(woff2|woff|ttf|otf)$/i;
426
+ var isSupportedFontFile = (filename) => SUPPORTED_EXTENSIONS.test(filename);
427
+ var registerFontFace = async (family, data) => {
428
+ if (typeof document === "undefined" || !document.fonts) {
429
+ throw new Error("registerFontFace requires a document with the CSS Font Loading API.");
430
+ }
431
+ const face = new FontFace(family, data);
432
+ await face.load();
433
+ document.fonts.add(face);
434
+ return family;
435
+ };
436
+ var registerFontFile = async (file, family) => {
437
+ if (!isSupportedFontFile(file.name)) {
438
+ throw new Error(`Unsupported font format: ${file.name}. Use ${FONT_ACCEPT}.`);
439
+ }
440
+ const buffer = await file.arrayBuffer();
441
+ return registerFontFace(_nullishCoalesce(family, () => ( familyNameFromFile(file.name))), buffer);
442
+ };
443
+ var GENERIC_FAMILIES = /* @__PURE__ */ new Set([
444
+ "serif",
445
+ "sans-serif",
446
+ "monospace",
447
+ "cursive",
448
+ "fantasy",
449
+ "system-ui",
450
+ "ui-serif",
451
+ "ui-sans-serif",
452
+ "ui-monospace",
453
+ "ui-rounded",
454
+ "math",
455
+ "emoji",
456
+ "fangsong",
457
+ "inherit",
458
+ "initial",
459
+ "unset"
460
+ ]);
461
+ var PROBE_TEXT = "mmmmmmmmmmlliI0OWw@";
462
+ var PROBE_FALLBACKS = ["monospace", "serif"];
463
+ var availabilityCache = /* @__PURE__ */ new Map();
464
+ var subscribeToFontLoads = (onChange) => {
465
+ if (typeof document === "undefined" || !document.fonts) return () => {
466
+ };
467
+ let active = true;
468
+ const handler = () => {
469
+ if (active) onChange();
470
+ };
471
+ document.fonts.addEventListener("loadingdone", handler);
472
+ void document.fonts.ready.then(handler);
473
+ return () => {
474
+ active = false;
475
+ document.fonts.removeEventListener("loadingdone", handler);
476
+ };
477
+ };
478
+ var isFontAvailable = (family) => {
479
+ const name = family.trim().replace(/^['"]|['"]$/g, "");
480
+ if (!name) return true;
481
+ if (GENERIC_FAMILIES.has(name.toLowerCase())) return true;
482
+ if (typeof document === "undefined") return true;
483
+ if (availabilityCache.get(name)) return true;
484
+ try {
485
+ const context = document.createElement("canvas").getContext("2d");
486
+ if (!context) return true;
487
+ const available = PROBE_FALLBACKS.some((fallback) => {
488
+ context.font = `100px ${fallback}`;
489
+ const baseline = context.measureText(PROBE_TEXT).width;
490
+ context.font = `100px ${quoteFamily(name)}, ${fallback}`;
491
+ return Math.abs(context.measureText(PROBE_TEXT).width - baseline) > 0.5;
492
+ });
493
+ if (available) availabilityCache.set(name, true);
494
+ return available;
495
+ } catch (e) {
496
+ return true;
497
+ }
498
+ };
499
+ var isFontStackAvailable = (stack) => isFontAvailable(_nullishCoalesce(stack.split(",")[0], () => ( "")));
500
+
501
+
502
+
503
+
504
+
505
+
506
+
507
+
508
+
509
+
510
+
511
+
512
+
513
+
514
+
515
+
516
+
517
+
518
+
519
+
520
+ exports.useTheme = useTheme; exports.contrastRatio = contrastRatio; exports.CONTRAST_LIGHT = CONTRAST_LIGHT; exports.CONTRAST_DARK = CONTRAST_DARK; exports.pickContrast = pickContrast; exports.THEME_COLOR_KEYS = THEME_COLOR_KEYS; exports.defaultTheme = defaultTheme; exports.FONT_SCALE_MIN = FONT_SCALE_MIN; exports.FONT_SCALE_MAX = FONT_SCALE_MAX; exports.ThemeProvider = ThemeProvider; exports.familyNameFromFile = familyNameFromFile; exports.toFontStack = toFontStack; exports.FONT_ACCEPT = FONT_ACCEPT; exports.registerFontFace = registerFontFace; exports.registerFontFile = registerFontFile; exports.subscribeToFontLoads = subscribeToFontLoads; exports.isFontAvailable = isFontAvailable; exports.isFontStackAvailable = isFontStackAvailable;
521
+ //# sourceMappingURL=chunk-U5FHQ73U.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/eidos-ui/eidos-ui/dist/chunk-U5FHQ73U.cjs","../src/components/ThemeProvider/ThemeProvider.component.tsx","../src/components/ThemeProvider/ThemeProvider.context.tsx","../src/components/ThemeProvider/ThemeProvider.color.ts","../src/components/ThemeProvider/ThemeProvider.tokens.ts","../src/components/ThemeProvider/ThemeProvider.fonts.ts"],"names":["value"],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACA;ACJA,8BAA0F;ADM1F;AACA;AEPA;AAGO,IAAM,aAAA,EAAe,kCAAA,KAA6C,CAAS,CAAA;AAO3E,IAAM,SAAA,EAAW,CAAA,EAAA,GAAyB;AAC/C,EAAA,MAAM,QAAA,EAAU,+BAAA,YAAuB,CAAA;AACvC,EAAA,GAAA,CAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,IAAI,KAAA,CAAM,8CAA8C,CAAA;AAAA,EAChE;AACA,EAAA,OAAO,OAAA;AACT,CAAA;AFCA;AACA;AGQA,IAAM,aAAA,EAAe,CAAC,CAAA,EAAA,GACpB,EAAA,GAAK,QAAA,EAAU,EAAA,EAAI,MAAA,EAAQ,IAAA,CAAK,GAAA,CAAA,CAAK,EAAA,EAAI,KAAA,EAAA,EAAS,KAAA,EAAO,GAAG,CAAA;AAE9D,IAAM,aAAA,EAAe,CAAC,CAAA,EAAA,GACpB,EAAA,GAAK,SAAA,EAAY,MAAA,EAAQ,EAAA,EAAI,MAAA,EAAQ,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,EAAA,EAAI,GAAG,EAAA,EAAI,KAAA;AAE9D,IAAM,QAAA,EAAU,CAAC,CAAA,EAAA,GAAuB,EAAA,EAAI,EAAA,EAAI,EAAA,EAAI,EAAA,EAAI,EAAA,EAAI,EAAA,EAAI,CAAA;AAGzD,IAAM,SAAA,EAAW,CAAC,GAAA,EAAA,GAAiD;AACxE,EAAA,GAAA,CAAI,OAAO,IAAA,IAAQ,QAAA,EAAU,OAAO,IAAA;AACpC,EAAA,MAAM,IAAA,EAAM,GAAA,CAAI,IAAA,CAAK,CAAA,CAAE,OAAA,CAAQ,IAAA,EAAM,EAAE,CAAA;AACvC,EAAA,MAAM,KAAA,EACJ,GA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,EAAA;AACD,EAAA;AACO,EAAA;AAIhB,EAAA;AACT;AAGgC;AACL,EAAA;AACP,IAAA;AAClB,EAAA;AACqB,EAAA;AACG,EAAA;AAC1B;AAOyB;AACvB,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACD;AAMkB;AAGM;AAeC;AAWU;AACV,EAAA;AAA8C,EAAA;AAEzD,EAAA;AACS,EAAA;AACC,IAAA;AACvB,EAAA;AAEe,EAAA;AACK,EAAA;AAEP,EAAA;AACF,IAAA;AACM,IAAA;AACjB,EAAA;AACF;AAkBgC;AACL,EAAA;AACP,EAAA;AACO,EAAA;AACD,EAAA;AAEF,EAAA;AAElB,EAAA;AACc,IAAA;AACK,IAAA;AAEH,IAAA;AACD,MAAA;AACE,MAAA;AACF,MAAA;AAGC,MAAA;AACjB,IAAA;AAEc,IAAA;AACR,IAAA;AACD,EAAA;AAGC,IAAA;AACT,EAAA;AACF;AAGoC;AL+QT;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/eidos-ui/eidos-ui/dist/chunk-U5FHQ73U.cjs","sourcesContent":[null,"import React, { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';\nimport { devWarn } from '../../utils';\nimport { ThemeContext } from './ThemeProvider.context';\nimport { buildTokens, diffFromDefault, resolveTheme, themeToCss } from './ThemeProvider.tokens';\nimport type { ThemeConfig, ThemeContextValue, ThemeProviderProps } from './ThemeProvider.types';\n\nconst EMPTY_THEME: ThemeConfig = {};\n\n/**\n * Number of providers currently mounted.\n *\n * Because tokens are written to `document.documentElement` (see the component\n * comment for why), providers do not compose: two of them target the same\n * element, so whichever applied a given token last wins for the entire page -\n * including for the subtree of the other one. That looks like a broken theme\n * rather than a misuse, so it is worth saying out loud.\n */\nlet mountedProviders = 0;\n\n/** Merges `patch` over `base` one level into `colors`/`typography`. */\nconst mergeTheme = (base: ThemeConfig, patch: ThemeConfig): ThemeConfig => ({\n colors: { ...base.colors, ...patch.colors },\n typography: { ...base.typography, ...patch.typography },\n});\n\n/**\n * Applies a theme by writing CSS custom properties to `document.documentElement`.\n *\n * Two deliberate choices worth knowing:\n *\n * **The target is `documentElement`, not a wrapper element.** Every overlay in\n * this library (`Dropdown`, `Modal`, `Drawer`, `Snackbar`, `Tooltip`, …) portals\n * to `document.body`, so tokens scoped to a wrapper `<div>` would leave every\n * popup rendering the preset instead.\n *\n * **Properties are set through the CSSOM** (`style.setProperty`), which no CSP\n * directive gates - `style-src` and `style-src-attr` only cover the `style`\n * HTML attribute and stylesheet loads. Nothing here needs a nonce, and no\n * `<style>` element is ever created. See `ContentSecurityPolicy.mdx`.\n *\n * Under SSR the server sends the preset from `dist/index.css` and the theme is\n * applied on hydration; use `toCss()` if you need a themed first paint.\n */\nexport const ThemeProvider: React.FC<ThemeProviderProps> = ({\n children,\n theme: controlledTheme,\n defaultTheme: initialTheme,\n onThemeChange,\n}) => {\n const isControlled = controlledTheme !== undefined;\n const [uncontrolledTheme, setUncontrolledTheme] = useState<ThemeConfig>(\n initialTheme ?? EMPTY_THEME,\n );\n const theme = isControlled ? controlledTheme : uncontrolledTheme;\n\n useEffect(() => {\n mountedProviders += 1;\n if (mountedProviders > 1) {\n devWarn(\n 'theme-multiple-providers',\n `ThemeProvider: ${mountedProviders} providers are mounted at once. They all write to document.documentElement, so the last one to apply each token wins for the whole page - nested or sibling providers cannot theme separate subtrees. Use a single provider at your app root.`,\n );\n }\n return () => {\n mountedProviders -= 1;\n };\n }, []);\n\n const resolvedTheme = useMemo(() => resolveTheme(theme), [theme]);\n const tokens = useMemo(() => diffFromDefault(buildTokens(resolvedTheme)), [resolvedTheme]);\n\n // Names written on the previous pass, so properties dropped from the theme\n // are removed rather than left behind at their last value.\n const appliedRef = useRef<string[]>([]);\n\n useLayoutEffect(() => {\n if (typeof document === 'undefined') return;\n const root = document.documentElement;\n\n for (const name of appliedRef.current) {\n if (!(name in tokens)) root.style.removeProperty(name);\n }\n for (const [name, value] of Object.entries(tokens)) {\n root.style.setProperty(name, value);\n }\n appliedRef.current = Object.keys(tokens);\n\n return () => {\n for (const name of appliedRef.current) {\n root.style.removeProperty(name);\n }\n appliedRef.current = [];\n };\n }, [tokens]);\n\n const commit = useCallback(\n (next: ThemeConfig) => {\n if (!isControlled) setUncontrolledTheme(next);\n onThemeChange?.(next);\n },\n [isControlled, onThemeChange],\n );\n\n const setTheme = useCallback((next: ThemeConfig) => commit(next), [commit]);\n\n const updateTheme = useCallback(\n (patch: ThemeConfig) => commit(mergeTheme(theme, patch)),\n [commit, theme],\n );\n\n const resetTheme = useCallback(() => commit(EMPTY_THEME), [commit]);\n\n const toCss = useCallback(() => themeToCss(resolvedTheme), [resolvedTheme]);\n\n const value = useMemo<ThemeContextValue>(\n () => ({\n theme,\n resolvedTheme,\n setTheme,\n updateTheme,\n resetTheme,\n isDefault: Object.keys(tokens).length === 0,\n toCss,\n }),\n [theme, resolvedTheme, setTheme, updateTheme, resetTheme, tokens, toCss],\n );\n\n return <ThemeContext.Provider value={value}>{children}</ThemeContext.Provider>;\n};\n\nThemeProvider.displayName = 'ThemeProvider';\n","import { createContext, useContext } from 'react';\nimport type { ThemeContextValue } from './ThemeProvider.types';\n\nexport const ThemeContext = createContext<ThemeContextValue | undefined>(undefined);\n\n/**\n * Reads the active theme. Throws outside a `ThemeProvider`, matching\n * `useSnackbarContext` - a silent fallback would make a missing provider look\n * like a theme that simply is not applying.\n */\nexport const useTheme = (): ThemeContextValue => {\n const context = useContext(ThemeContext);\n if (!context) {\n throw new Error('useTheme must be used within a ThemeProvider');\n }\n return context;\n};\n","/**\n * Colour maths for the theme system.\n *\n * All conversions are done in JS and emitted as `#rrggbb`, so browser support\n * for `oklch()` is irrelevant here - nothing in the generated CSS uses a modern\n * colour function.\n *\n * OKLab is used rather than HSL for every interpolation. HSL lightness\n * interpolation is ~40 lines shorter but produces muddy, desaturated ramps for\n * exactly the saturated brand hues this feature exists to support, because its\n * \"lightness\" is not perceptual.\n */\n\n// ============================================================================\n// sRGB <-> OKLab\n// ============================================================================\n\nexport interface Oklch {\n /** Perceptual lightness, 0-1. */\n l: number;\n /** Chroma (colourfulness), 0 to ~0.4 in sRGB. */\n c: number;\n /** Hue angle in radians. */\n h: number;\n}\n\nconst srgbToLinear = (v: number): number =>\n v <= 0.04045 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);\n\nconst linearToSrgb = (v: number): number =>\n v <= 0.0031308 ? 12.92 * v : 1.055 * Math.pow(v, 1 / 2.4) - 0.055;\n\nconst clamp01 = (v: number): number => (v < 0 ? 0 : v > 1 ? 1 : v);\n\n/** Parses `#rgb` / `#rrggbb` into 0-1 sRGB channels. Returns null if unparseable. */\nexport const parseHex = (hex: string): [number, number, number] | null => {\n if (typeof hex !== 'string') return null;\n const raw = hex.trim().replace(/^#/, '');\n const full =\n raw.length === 3\n ? raw\n .split('')\n .map((c) => c + c)\n .join('')\n : raw;\n if (!/^[0-9a-fA-F]{6}$/.test(full)) return null;\n const n = parseInt(full, 16);\n return [((n >> 16) & 255) / 255, ((n >> 8) & 255) / 255, (n & 255) / 255];\n};\n\nexport const isValidHex = (hex: string): boolean => parseHex(hex) !== null;\n\nconst toHex = ([r, g, b]: [number, number, number]): string =>\n '#' +\n [r, g, b]\n .map((v) =>\n Math.round(clamp01(v) * 255)\n .toString(16)\n .padStart(2, '0'),\n )\n .join('');\n\n/** `#rrggbb` -> the comma-separated triple the `--x-rgb` tokens use. */\nexport const hexToRgbTriple = (hex: string): string => {\n const rgb = parseHex(hex);\n if (!rgb) return '0, 0, 0';\n return rgb.map((v) => Math.round(v * 255)).join(', ');\n};\n\nconst linearToOklab = ([r, g, b]: [number, number, number]): [number, number, number] => {\n const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);\n const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);\n const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);\n return [\n 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s,\n 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s,\n 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s,\n ];\n};\n\nconst oklabToLinear = ([L, A, B]: [number, number, number]): [number, number, number] => {\n const l = (L + 0.3963377774 * A + 0.2158037573 * B) ** 3;\n const m = (L - 0.1055613458 * A - 0.0638541728 * B) ** 3;\n const s = (L - 0.0894841775 * A - 1.291485548 * B) ** 3;\n return [\n 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,\n -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,\n -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s,\n ];\n};\n\nexport const hexToOklch = (hex: string): Oklch => {\n const rgb = parseHex(hex) ?? [0, 0, 0];\n const [l, a, b] = linearToOklab(rgb.map(srgbToLinear) as [number, number, number]);\n return { l, c: Math.hypot(a, b), h: Math.atan2(b, a) };\n};\n\nconst inGamut = ([r, g, b]: [number, number, number]): boolean =>\n [r, g, b].every((v) => v >= -1e-4 && v <= 1 + 1e-4);\n\n/**\n * Largest chroma that still fits in sRGB at this lightness and hue.\n *\n * Needed because OKLab is a much larger space than sRGB: naively keeping a\n * colour's chroma while changing its lightness frequently lands outside the\n * gamut, where channels clip and the hue visibly shifts.\n */\nconst maxChroma = (l: number, h: number): number => {\n let lo = 0;\n let hi = 0.45;\n for (let i = 0; i < 24; i++) {\n const mid = (lo + hi) / 2;\n if (inGamut(oklabToLinear([l, mid * Math.cos(h), mid * Math.sin(h)]))) lo = mid;\n else hi = mid;\n }\n return lo;\n};\n\nexport const oklchToHex = ({ l, c, h }: Oklch): string => {\n const lc = clamp01(l);\n const cc = Math.min(Math.max(c, 0), maxChroma(lc, h));\n return toHex(\n oklabToLinear([lc, cc * Math.cos(h), cc * Math.sin(h)]).map(linearToSrgb) as [\n number,\n number,\n number,\n ],\n );\n};\n\n// ============================================================================\n// WCAG 2.1 contrast\n// ============================================================================\n\n/**\n * WCAG 2.1 is used rather than APCA. APCA models perception better but is\n * still a draft (targeted at WCAG 3), while WCAG 2 is what consumers are\n * actually audited against. Its known weakness - mis-ranking some mid-tone\n * blues and greens - is accepted for that reason.\n */\nexport const relativeLuminance = (hex: string): number => {\n const [r, g, b] = (parseHex(hex) ?? [0, 0, 0]).map(srgbToLinear);\n return 0.2126 * r + 0.7152 * g + 0.0722 * b;\n};\n\n/** Contrast ratio between two colours, 1 (identical) to 21 (black on white). */\nexport const contrastRatio = (a: string, b: string): number => {\n const [x, y] = [relativeLuminance(a), relativeLuminance(b)];\n return (Math.max(x, y) + 0.05) / (Math.min(x, y) + 0.05);\n};\n\n/** The two foreground candidates, matching `--white` and `--gray-900`. */\nexport const CONTRAST_LIGHT = '#ffffff';\nexport const CONTRAST_DARK = '#0f172a';\n\n/**\n * Foreground to place on `fill`.\n *\n * White wins unless it drops below 3:1, at which point the better of the two\n * candidates is used. The threshold is deliberately 3:1 rather than \"whichever\n * scores higher\": on mid-tone reds the dark candidate often scores marginally\n * better while looking plainly wrong, and every preset base clears 4.5:1\n * against white anyway.\n */\nexport const pickContrast = (fill: string): string => {\n const onLight = contrastRatio(fill, CONTRAST_LIGHT);\n if (onLight >= 3) return CONTRAST_LIGHT;\n return onLight >= contrastRatio(fill, CONTRAST_DARK) ? CONTRAST_LIGHT : CONTRAST_DARK;\n};\n\n// ============================================================================\n// Ramp generation\n// ============================================================================\n\n/** The ramp steps, in the order `--x-50` … `--x-900` are declared. */\nexport const RAMP_STEPS = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900] as const;\n\nexport type RampStep = (typeof RAMP_STEPS)[number];\n\n/** The step the supplied base colour occupies; the ramp is built around it. */\nconst BASE_STEP = 500;\n\n/**\n * Target lightness per step, and how much of the base's chroma to keep.\n *\n * Measured from the preset indigo ramp, so feeding the preset primary through\n * `buildRamp` lands close to the shipped `--primary-*` values rather than\n * something arbitrary. It is deliberately not an exact reproduction - see the\n * note on `buildRamp`.\n */\nconst RAMP_CURVE: Record<RampStep, { l: number; chroma: number }> = {\n 50: { l: 0.962, chroma: 0.09 },\n 100: { l: 0.93, chroma: 0.16 },\n 200: { l: 0.87, chroma: 0.3 },\n 300: { l: 0.785, chroma: 0.51 },\n 400: { l: 0.68, chroma: 0.77 },\n 500: { l: 0.558, chroma: 1.0 },\n 600: { l: 0.511, chroma: 1.12 },\n 700: { l: 0.457, chroma: 1.05 },\n 800: { l: 0.398, chroma: 0.87 },\n 900: { l: 0.359, chroma: 0.66 },\n};\n\n/** Ceiling/floor the generated ends aim for, leaving the base itself untouched. */\nconst LIGHT_CEILING = 0.985;\nconst DARK_FLOOR = 0.22;\n\n/** Minimum lightness gap between adjacent steps, so none can collapse together. */\nconst MIN_STEP_DELTA = 0.012;\n\n/**\n * Generates a 50-900 ramp around `base`, which is placed at the 500 step.\n *\n * The base's own hue is always preserved, and `--x-500` is returned as the base\n * hex verbatim, so the colour a consumer picked is never silently replaced.\n *\n * The curve above is *rescaled* to whatever lightness headroom the base leaves,\n * rather than being applied absolutely or simply shifted:\n *\n * - Applying it absolutely would reassign the base - pick a pale yellow and\n * `--x-500` would come back a mid-olive, contradicting `--x-color`.\n * - Shifting it so 500 sits at the base's lightness pushes the light end past\n * `l = 1`, where it clips and 50/100/200/300 all come out pure white.\n *\n * Rescaling keeps the ends anchored (50 stays near-white, 900 stays dark) and\n * compresses only the side with less room - the scale is capped at 1 so a base\n * sitting where the curve expects it reproduces the curve exactly rather than\n * being stretched past it.\n *\n * Two inputs are genuinely degenerate and are handled rather than solved: a\n * base at or above `LIGHT_CEILING` has no room for tints, and one with zero\n * chroma (pure white, black, any gray) has no saturation to separate them with\n * either. For those the light end converges, and `isRampViable` reports it so\n * the caller can warn. Realistic light picks are fine - `#fde047` still yields\n * five distinct tints.\n */\nexport const buildRamp = (base: string): Record<RampStep, string> => {\n const { l: baseL, c: baseC, h } = hexToOklch(base);\n const anchor = RAMP_CURVE[BASE_STEP].l;\n\n // Headroom available above and below the base, versus what the curve wants.\n // Capped at 1: this may only compress the curve, never stretch it.\n const lightSpan = RAMP_CURVE[50].l - anchor;\n const darkSpan = anchor - RAMP_CURVE[900].l;\n const lightScale =\n lightSpan > 0 ? Math.min(1, Math.max(0, LIGHT_CEILING - baseL) / lightSpan) : 0;\n const darkScale = darkSpan > 0 ? Math.min(1, Math.max(0, baseL - DARK_FLOOR) / darkSpan) : 0;\n\n const out = {} as Record<RampStep, string>;\n for (const step of RAMP_STEPS) {\n if (step === BASE_STEP) {\n out[step] = base;\n continue;\n }\n const { l: curveL, chroma } = RAMP_CURVE[step];\n const offset = curveL - anchor;\n const l = baseL + offset * (offset > 0 ? lightScale : darkScale);\n out[step] = oklchToHex({ l, c: baseC * chroma, h });\n }\n\n return enforceSeparation(out, h, baseC);\n};\n\n/**\n * Walks outward from the base step, pushing any step that ended up too close to\n * its neighbour further away. Only bites for extreme inputs (near-white,\n * near-black, zero-chroma), where the rescale above has almost no room left.\n */\nconst enforceSeparation = (\n ramp: Record<RampStep, string>,\n h: number,\n baseC: number,\n): Record<RampStep, string> => {\n const baseIndex = RAMP_STEPS.indexOf(BASE_STEP);\n const lightness = RAMP_STEPS.map((s) => hexToOklch(ramp[s]).l);\n\n // Lighter steps: walk from the base toward 50, each must be lighter.\n for (let i = baseIndex - 1; i >= 0; i--) {\n const limit = lightness[i + 1] + MIN_STEP_DELTA;\n if (lightness[i] < limit) lightness[i] = Math.min(1, limit);\n }\n // Darker steps: walk from the base toward 900, each must be darker.\n for (let i = baseIndex + 1; i < RAMP_STEPS.length; i++) {\n const limit = lightness[i - 1] - MIN_STEP_DELTA;\n if (lightness[i] > limit) lightness[i] = Math.max(0, limit);\n }\n\n const out = {} as Record<RampStep, string>;\n RAMP_STEPS.forEach((step, i) => {\n if (step === BASE_STEP) {\n out[step] = ramp[step];\n return;\n }\n out[step] = oklchToHex({\n l: lightness[i],\n c: baseC * RAMP_CURVE[step].chroma,\n h,\n });\n });\n return out;\n};\n\n/** How far `--x-dark` / `--x-light` sit from the base, in OKLab lightness. */\nconst DARK_DELTA = 0.086;\nconst LIGHT_DELTA = 0.169;\n\n/** Below this lightness there is no room left to darken, so the hover lightens. */\nconst HOVER_INVERT_BELOW = DARK_DELTA * 1.5;\n\n/**\n * The hover/active colour. Must differ *visibly* from the base and stay legible\n * as text on white, since `--x-dark` is used both as a fill (Button, Chip\n * hovers) and as text (Snackbar, link hover in `global.scss`).\n *\n * A fixed ramp step is not good enough: for a near-white base the 600 step\n * lands barely darker than the base and the hover reads as no change at all.\n * Hence a guaranteed delta.\n *\n * For a base that is already near-black the delta is applied *upwards* instead.\n * Clamping to a floor would return a colour lighter than the base while still\n * being named \"dark\", and returning the base unchanged would leave the control\n * with no hover affordance at all; lightening is what dark-surface design\n * systems do anyway.\n */\nexport const deriveDark = (base: string): string => {\n const { l, c, h } = hexToOklch(base);\n const target = l < HOVER_INVERT_BELOW ? l + DARK_DELTA : l - DARK_DELTA;\n return oklchToHex({ l: target, c, h });\n};\n\n/**\n * The light companion. Lightening has a hard ceiling, so for an already-pale\n * base this lands very close to it - acceptable, as `--x-light` is a public\n * token that nothing inside the library currently consumes.\n */\nexport const deriveLight = (base: string): string => {\n const { l, c, h } = hexToOklch(base);\n return oklchToHex({ l: Math.min(LIGHT_CEILING, l + LIGHT_DELTA), c, h });\n};\n\n/**\n * Whether `base` leaves enough lightness headroom to generate a usable 50-900\n * ramp. False only for near-white and near-black, where the tint or shade end\n * necessarily converges - the caller surfaces that as a developer warning\n * rather than silently shipping identical tokens.\n *\n * Deliberately does not test chroma: an unsaturated gray separates perfectly\n * well by lightness alone, and a saturated light colour like `#fde047` still\n * produces five distinct tints. Only the extremes genuinely fail.\n */\nexport const isRampViable = (base: string): boolean => {\n const { l } = hexToOklch(base);\n return l < 0.95 && l > 0.12;\n};\n","import { devWarn } from '../../utils';\nimport {\n RAMP_STEPS,\n buildRamp,\n deriveDark,\n deriveLight,\n hexToRgbTriple,\n isValidHex,\n isRampViable,\n pickContrast,\n} from './ThemeProvider.color';\nimport type {\n ResolvedTheme,\n ThemeColorKey,\n ThemeColorValue,\n ThemeConfig,\n} from './ThemeProvider.types';\n\nexport const THEME_COLOR_KEYS: readonly ThemeColorKey[] = [\n 'primary',\n 'secondary',\n 'success',\n 'danger',\n 'warning',\n 'info',\n 'hyperlink',\n] as const;\n\n/**\n * `hyperlink` is link text on a surface, never a fill, so it has no\n * `--hyperlink-contrast` token - nothing in the library would read it.\n */\nconst FILL_COLOR_KEYS: readonly ThemeColorKey[] = [\n 'primary',\n 'secondary',\n 'success',\n 'danger',\n 'warning',\n 'info',\n] as const;\n\n/** Only `primary` has a 50-900 ramp in `variables.scss`. */\nconst RAMP_COLOR_KEY: ThemeColorKey = 'primary';\n\n/** The eight preset `--font-size-*` values, in declaration order. */\nconst FONT_SIZE_STEPS: readonly [string, number][] = [\n ['xs', 0.75],\n ['sm', 0.875],\n ['base', 1],\n ['md', 1.1],\n ['lg', 1.125],\n ['xl', 1.25],\n ['2xl', 1.5],\n ['3xl', 1.875],\n] as const;\n\n/**\n * The shipped values from `src/styles/variables.scss`.\n *\n * This is a literal copy, not something derived: the ramp is hand-tuned and no\n * generator reproduces it byte for byte. Keeping it literal means a theme equal\n * to the preset writes no CSS properties at all, so default rendering is\n * identical to `dist/index.css`.\n *\n * Must be kept in sync with `variables.scss` by hand. The bases are all chosen\n * to clear WCAG AA against white text; see the comment at the top of that file.\n */\nexport const defaultTheme: Required<ThemeConfig> = {\n colors: {\n primary: '#5c5de8',\n secondary: '#617087',\n success: '#007f57',\n danger: '#d6272f',\n warning: '#9c6300',\n info: '#007a90',\n hyperlink: '#007b84',\n },\n typography: {\n fontFamily:\n \"'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif\",\n monoFamily:\n \"'JetBrains Mono', 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', 'Source Code Pro', monospace\",\n fontScale: 1,\n },\n};\n\n/** The preset `--primary-*` ramp, needed so an unthemed primary emits nothing. */\nconst DEFAULT_PRIMARY_RAMP: Record<number, string> = {\n 50: '#eef2ff',\n 100: '#e0e7ff',\n 200: '#c7d2fe',\n 300: '#a5b4fc',\n 400: '#818cf8',\n 500: '#5c5de8',\n 600: '#4f46e5',\n 700: '#4338ca',\n 800: '#3730a3',\n 900: '#312e81',\n};\n\nexport const FONT_SCALE_MIN = 0.875;\nexport const FONT_SCALE_MAX = 1.25;\n\nconst normalizeColor = (value: ThemeColorValue): { base: string; contrast?: string } =>\n typeof value === 'string' ? { base: value } : value;\n\n/** Fills every absent field from the preset. */\nexport const resolveTheme = (theme: ThemeConfig): ResolvedTheme => {\n const colors = {} as ResolvedTheme['colors'];\n\n for (const key of THEME_COLOR_KEYS) {\n const supplied = theme.colors?.[key];\n const fallback = normalizeColor(defaultTheme.colors[key]!);\n if (supplied === undefined) {\n colors[key] = fallback;\n continue;\n }\n const { base, contrast } = normalizeColor(supplied);\n if (!isValidHex(base)) {\n devWarn(\n `theme-color-${key}`,\n `ThemeProvider: colors.${key} is not a valid hex colour (received ${JSON.stringify(base)}). Falling back to the preset.`,\n );\n colors[key] = fallback;\n continue;\n }\n if (contrast !== undefined && !isValidHex(contrast)) {\n devWarn(\n `theme-contrast-${key}`,\n `ThemeProvider: colors.${key}.contrast is not a valid hex colour (received ${JSON.stringify(contrast)}). It will be computed instead.`,\n );\n colors[key] = { base };\n continue;\n }\n colors[key] = contrast === undefined ? { base } : { base, contrast };\n }\n\n const scale = theme.typography?.fontScale;\n let fontScale = defaultTheme.typography.fontScale!;\n if (scale !== undefined) {\n if (!Number.isFinite(scale) || scale < FONT_SCALE_MIN || scale > FONT_SCALE_MAX) {\n devWarn(\n 'theme-font-scale',\n `ThemeProvider: typography.fontScale must be between ${FONT_SCALE_MIN} and ${FONT_SCALE_MAX} (received ${String(scale)}). Falling back to ${fontScale}.`,\n );\n } else {\n fontScale = scale;\n }\n }\n\n return {\n colors,\n typography: {\n fontFamily: theme.typography?.fontFamily || defaultTheme.typography.fontFamily!,\n monoFamily: theme.typography?.monoFamily || defaultTheme.typography.monoFamily!,\n fontScale,\n },\n };\n};\n\n/**\n * Expands a resolved theme into the flat `--token: value` map to apply.\n *\n * Every family contributes `--x-color`, `--x-rgb`, `--x-dark` and `--x-light`;\n * the six fill families also get `--x-contrast`, and `primary` additionally\n * gets the full `--primary-50…900` ramp.\n */\nexport const buildTokens = (resolved: ResolvedTheme): Record<string, string> => {\n const tokens: Record<string, string> = {};\n\n for (const key of THEME_COLOR_KEYS) {\n const { base, contrast } = resolved.colors[key];\n tokens[`--${key}-color`] = base;\n tokens[`--${key}-rgb`] = hexToRgbTriple(base);\n tokens[`--${key}-dark`] = deriveDark(base);\n tokens[`--${key}-light`] = deriveLight(base);\n\n if (FILL_COLOR_KEYS.includes(key)) {\n tokens[`--${key}-contrast`] = contrast ?? pickContrast(base);\n }\n\n if (key === RAMP_COLOR_KEY) {\n const isPreset = base === normalizeColor(defaultTheme.colors[key]!).base;\n // The preset ramp is hand-tuned, so reuse it verbatim rather than\n // regenerating a near-identical one.\n const ramp = isPreset ? DEFAULT_PRIMARY_RAMP : buildRamp(base);\n if (!isPreset && !isRampViable(base)) {\n devWarn(\n `theme-ramp-${key}`,\n `ThemeProvider: colors.${key} (${base}) is too light or too dark to generate a usable --${key}-50…900 scale; several steps will be identical. Pick a colour with more headroom.`,\n );\n }\n for (const step of RAMP_STEPS) {\n tokens[`--${key}-${step}`] = ramp[step];\n }\n }\n }\n\n const { fontFamily, monoFamily, fontScale } = resolved.typography;\n tokens['--font-family-primary'] = fontFamily;\n tokens['--font-family-mono'] = monoFamily;\n for (const [name, rem] of FONT_SIZE_STEPS) {\n // Trailing zeros trimmed so 1 * 0.75 reads as `0.75rem`, not `0.750rem`.\n tokens[`--font-size-${name}`] = `${parseFloat((rem * fontScale).toFixed(4))}rem`;\n }\n\n return tokens;\n};\n\n/** Tokens for the preset, used to tell which of them are actually overrides. */\nconst DEFAULT_TOKENS = buildTokens(resolveTheme(defaultTheme));\n\n/**\n * Only the tokens that differ from the preset.\n *\n * This is what makes an unthemed `ThemeProvider` a no-op: it writes nothing, so\n * `dist/index.css` stays authoritative and there is no inline-style churn on\n * `documentElement` for values that already match.\n */\nexport const diffFromDefault = (tokens: Record<string, string>): Record<string, string> => {\n const diff: Record<string, string> = {};\n for (const [name, value] of Object.entries(tokens)) {\n if (DEFAULT_TOKENS[name] !== value) diff[name] = value;\n }\n return diff;\n};\n\n/**\n * The resolved theme as a `:root { … }` block.\n *\n * Paste the output into your own stylesheet to bake a theme in at build time -\n * that avoids the brief flash of the preset that any runtime theme has when the\n * value arrives after first paint, and needs no JavaScript at all.\n */\nexport const themeToCss = (resolved: ResolvedTheme): string => {\n const tokens = buildTokens(resolved);\n const body = Object.entries(tokens)\n .map(([name, value]) => ` ${name}: ${value};`)\n .join('\\n');\n return `:root {\\n${body}\\n}`;\n};\n","/**\n * Runtime font registration for the theme system.\n *\n * `--font-family-primary` only *names* families - it cannot make a font\n * available. Selecting \"Plus Jakarta Sans\" on a machine that doesn't have it\n * installed silently falls through to the next stack entry, which is why a\n * theme needs a way to supply the font data itself.\n *\n * ## Why this is CSP-safe\n *\n * Fonts are registered with the CSS Font Loading API from an `ArrayBuffer`:\n *\n * ```ts\n * document.fonts.add(new FontFace(family, buffer));\n * ```\n *\n * CSP's `font-src` directive governs *fetching* a font resource by URL - it is\n * what gates `@font-face { src: url(...) }` and the string form of the\n * `FontFace` constructor. The binary form performs no fetch at all, so there is\n * no request for `font-src` to check and no allowance to configure. Notably\n * this also avoids `blob:` URLs, which *would* require `font-src blob:`.\n *\n * No `<style>` element is created either, so nothing here needs a nonce - the\n * same position as the rest of the theme system.\n */\n\n/** A font registered at runtime, as listed by the editor. */\nexport interface RegisteredFont {\n /** The family name to reference in a font stack. */\n family: string;\n /** Where it came from, so the UI can distinguish uploads from built-ins. */\n source: 'upload';\n}\n\n/**\n * Turns a filename into a usable CSS family name.\n *\n * Deliberately conservative: the real family name lives in the font's internal\n * `name` table, and parsing SFNT tables to read it would be a disproportionate\n * amount of binary handling for a label. The filename is what the user\n * recognises anyway.\n */\nexport const familyNameFromFile = (filename: string): string => {\n const base = filename.replace(/\\.[^.]+$/, '');\n const cleaned = base\n // Strip the weight/style suffixes font vendors append.\n .replace(/[-_](regular|normal|book|roman)$/i, '')\n .replace(/[-_]+/g, ' ')\n // A quoted family name may contain spaces but not quotes or control chars.\n .replace(/[\"'\\\\]/g, '')\n .replace(/\\s+/g, ' ')\n .trim();\n return cleaned || 'Custom Font';\n};\n\n/** Wraps a family name for use in a CSS font stack if it needs quoting. */\nexport const quoteFamily = (family: string): string =>\n /^[a-zA-Z][a-zA-Z0-9-]*$/.test(family) ? family : `'${family}'`;\n\n/**\n * Builds a full stack from a custom family, keeping sensible fallbacks so the\n * page stays readable if the font is ever unavailable.\n */\nexport const toFontStack = (family: string, mono = false): string =>\n mono\n ? `${quoteFamily(family)}, 'SF Mono', Monaco, monospace`\n : `${quoteFamily(family)}, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif`;\n\n/** Font formats accepted for upload, as an `accept` attribute value. */\nexport const FONT_ACCEPT = '.woff2,.woff,.ttf,.otf';\n\nconst SUPPORTED_EXTENSIONS = /\\.(woff2|woff|ttf|otf)$/i;\n\nexport const isSupportedFontFile = (filename: string): boolean =>\n SUPPORTED_EXTENSIONS.test(filename);\n\n/**\n * Registers font data with the document so a theme can reference its family.\n *\n * Resolves with the family name actually registered. Rejects if the data is not\n * a font the browser can parse, or if the Font Loading API is unavailable\n * (notably during SSR, where there is no `document` to register against).\n */\nexport const registerFontFace = async (family: string, data: ArrayBuffer): Promise<string> => {\n if (typeof document === 'undefined' || !document.fonts) {\n throw new Error('registerFontFace requires a document with the CSS Font Loading API.');\n }\n\n // ArrayBuffer source - no URL is fetched, so CSP's font-src never applies.\n const face = new FontFace(family, data);\n await face.load();\n document.fonts.add(face);\n // No cache invalidation needed: only positive results are cached, and this\n // family could not have been cached positive while it was still unavailable.\n // `document.fonts.add` also fires `loadingdone`, which wakes subscribers.\n return family;\n};\n\n/** Reads a File and registers it, returning the family name it was given. */\nexport const registerFontFile = async (file: File, family?: string): Promise<string> => {\n if (!isSupportedFontFile(file.name)) {\n throw new Error(`Unsupported font format: ${file.name}. Use ${FONT_ACCEPT}.`);\n }\n const buffer = await file.arrayBuffer();\n return registerFontFace(family ?? familyNameFromFile(file.name), buffer);\n};\n\n/**\n * CSS generic families, which always resolve and must never be reported\n * missing. They also cannot be probed by the method below, since asking for\n * `monospace, monospace` measures identically to `monospace` alone.\n */\nconst GENERIC_FAMILIES = new Set([\n 'serif',\n 'sans-serif',\n 'monospace',\n 'cursive',\n 'fantasy',\n 'system-ui',\n 'ui-serif',\n 'ui-sans-serif',\n 'ui-monospace',\n 'ui-rounded',\n 'math',\n 'emoji',\n 'fangsong',\n 'inherit',\n 'initial',\n 'unset',\n]);\n\n/**\n * Mixed-width glyphs, so a real font is very unlikely to measure identically\n * to a fallback by coincidence.\n */\nconst PROBE_TEXT = 'mmmmmmmmmmlliI0OWw@';\n\n/** Two structurally different fallbacks - a font need only differ from one. */\nconst PROBE_FALLBACKS = ['monospace', 'serif'] as const;\n\n/**\n * Cached per family - **positive results only**.\n *\n * A negative answer is not stable: web fonts load asynchronously (always, with\n * `font-display: swap`), so a family probed during the first render is\n * legitimately unavailable and becomes available moments later. Caching that\n * `false` pinned the answer forever, which showed a permanent \"not installed\"\n * warning for fonts that had in fact loaded.\n *\n * A positive answer cannot go stale the same way - a loaded font is not\n * unloaded - so those are worth keeping. Re-probing the misses costs one canvas\n * measurement each.\n */\nconst availabilityCache = new Map<string, true>();\n\n/**\n * Notifies when the set of usable fonts changes, so a caller rendering an\n * availability state can re-check.\n *\n * Both signals are needed: `loadingdone` covers fonts that begin loading after\n * subscription, while `ready` covers those already in flight when the listener\n * was attached - which is the common case for a stylesheet's `@font-face`\n * rules, since they start loading before any component mounts.\n */\nexport const subscribeToFontLoads = (onChange: () => void): (() => void) => {\n if (typeof document === 'undefined' || !document.fonts) return () => {};\n\n let active = true;\n const handler = () => {\n if (active) onChange();\n };\n\n document.fonts.addEventListener('loadingdone', handler);\n void document.fonts.ready.then(handler);\n\n return () => {\n active = false;\n document.fonts.removeEventListener('loadingdone', handler);\n };\n};\n\n/**\n * Whether a font family will actually render, rather than silently falling\n * through to the next entry in the stack.\n *\n * **`document.fonts.check` cannot answer this.** Per spec it reports whether\n * the faces *in the FontFaceSet* matching the query are loaded, so with no\n * matching face it returns `true` vacuously. Verified in a real browser: it\n * answers `true` for `'Totally Not A Real Font 12345'`, and therefore for every\n * uninstalled system font too. Using it here produced a check that could never\n * fail.\n *\n * Instead the family is measured on a canvas against two fallbacks. If it\n * resolves to anything real, the text measures differently from at least one\n * fallback alone; if it does not resolve, the browser renders that fallback and\n * the widths match exactly.\n */\nexport const isFontAvailable = (family: string): boolean => {\n const name = family.trim().replace(/^['\"]|['\"]$/g, '');\n if (!name) return true;\n if (GENERIC_FAMILIES.has(name.toLowerCase())) return true;\n if (typeof document === 'undefined') return true;\n\n if (availabilityCache.get(name)) return true;\n\n try {\n const context = document.createElement('canvas').getContext('2d');\n if (!context) return true;\n\n const available = PROBE_FALLBACKS.some((fallback) => {\n context.font = `100px ${fallback}`;\n const baseline = context.measureText(PROBE_TEXT).width;\n context.font = `100px ${quoteFamily(name)}, ${fallback}`;\n // An invalid font shorthand leaves `font` untouched, which measures as\n // the baseline and correctly reports the family as unavailable.\n return Math.abs(context.measureText(PROBE_TEXT).width - baseline) > 0.5;\n });\n\n if (available) availabilityCache.set(name, true);\n return available;\n } catch {\n // Never report a font missing because probing itself failed - and don't\n // cache a failure, so a later call can still get a real answer.\n return true;\n }\n};\n\n/** Whether the first family in a stack will render. */\nexport const isFontStackAvailable = (stack: string): boolean =>\n isFontAvailable(stack.split(',')[0] ?? '');\n"]}
@@ -1,9 +1,9 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkW6IKHJ76cjs = require('../chunk-W6IKHJ76.cjs');
3
+ var _chunk5BX4Q76Dcjs = require('../chunk-5BX4Q76D.cjs');
4
4
  require('../chunk-FRUOA2QU.cjs');
5
5
  require('../chunk-DZUJEN5N.cjs');
6
6
 
7
7
 
8
- exports.ColorPicker = _chunkW6IKHJ76cjs.ColorPicker;
8
+ exports.ColorPicker = _chunk5BX4Q76Dcjs.ColorPicker;
9
9
  //# sourceMappingURL=index.cjs.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  ColorPicker
3
- } from "../chunk-JV7Z3D3U.js";
3
+ } from "../chunk-LEMCJW57.js";
4
4
  import "../chunk-4BKTBV2I.js";
5
5
  import "../chunk-5WRI5ZAA.js";
6
6
  export {