@atom63/ui-react 0.2.0-beta.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 (92) hide show
  1. package/README.md +121 -0
  2. package/dist/button-sktq-nvV.d.ts +13 -0
  3. package/dist/chunk-7VSPECOH.js +73 -0
  4. package/dist/chunk-7VSPECOH.js.map +1 -0
  5. package/dist/chunk-AJLHJRK6.js +11 -0
  6. package/dist/chunk-AJLHJRK6.js.map +1 -0
  7. package/dist/chunk-MXNO63TC.js +2745 -0
  8. package/dist/chunk-MXNO63TC.js.map +1 -0
  9. package/dist/chunk-STCXERLM.js +354 -0
  10. package/dist/chunk-STCXERLM.js.map +1 -0
  11. package/dist/destination-link-C9NKeKLe.d.ts +34 -0
  12. package/dist/index.d.ts +1605 -0
  13. package/dist/index.js +7337 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/layout/index.d.ts +196 -0
  16. package/dist/layout/index.js +500 -0
  17. package/dist/layout/index.js.map +1 -0
  18. package/dist/media/index.d.ts +208 -0
  19. package/dist/media/index.js +1498 -0
  20. package/dist/media/index.js.map +1 -0
  21. package/dist/media/media-lightbox/parts/index.d.ts +284 -0
  22. package/dist/media/media-lightbox/parts/index.js +5 -0
  23. package/dist/media/media-lightbox/parts/index.js.map +1 -0
  24. package/dist/theme/index.d.ts +350 -0
  25. package/dist/theme/index.js +1173 -0
  26. package/dist/theme/index.js.map +1 -0
  27. package/dist/types-Dxe5IzjE.d.ts +145 -0
  28. package/package.json +188 -0
  29. package/src/components/accordion/accordion.css +196 -0
  30. package/src/components/alert/alert.css +189 -0
  31. package/src/components/alert-dialog/alert-dialog.css +205 -0
  32. package/src/components/autocomplete/autocomplete.css +240 -0
  33. package/src/components/avatar/avatar.css +147 -0
  34. package/src/components/badge/badge.css +223 -0
  35. package/src/components/breadcrumb/breadcrumb.css +99 -0
  36. package/src/components/button/button.css +594 -0
  37. package/src/components/button-group/button-group.css +412 -0
  38. package/src/components/calendar/calendar.css +271 -0
  39. package/src/components/card/card.css +421 -0
  40. package/src/components/carousel/carousel.css +163 -0
  41. package/src/components/checkbox/checkbox.css +113 -0
  42. package/src/components/collapsible/collapsible.css +59 -0
  43. package/src/components/command/command.css +226 -0
  44. package/src/components/connected-panel/connected-panel.css +437 -0
  45. package/src/components/copy-button/copy-button.css +57 -0
  46. package/src/components/dialog/dialog.css +221 -0
  47. package/src/components/drawer/drawer.css +265 -0
  48. package/src/components/empty/empty.css +145 -0
  49. package/src/components/feedback-state/feedback-state.css +141 -0
  50. package/src/components/field/field.css +260 -0
  51. package/src/components/form/form.css +32 -0
  52. package/src/components/frame/frame.css +115 -0
  53. package/src/components/hover-card/hover-card.css +80 -0
  54. package/src/components/input/input.css +291 -0
  55. package/src/components/input-otp/input-otp.css +145 -0
  56. package/src/components/item/item.css +216 -0
  57. package/src/components/kbd/kbd.css +72 -0
  58. package/src/components/label/label.css +37 -0
  59. package/src/components/load-more-trigger/load-more-trigger.css +109 -0
  60. package/src/components/marquee/marquee.css +79 -0
  61. package/src/components/menu/menu.css +216 -0
  62. package/src/components/menubar/menubar.css +67 -0
  63. package/src/components/navigation-menu/navigation-menu.css +275 -0
  64. package/src/components/pagination/pagination.css +86 -0
  65. package/src/components/panel-setting-button/panel-setting-button.css +76 -0
  66. package/src/components/popover/popover.css +89 -0
  67. package/src/components/preview-card/preview-card.css +69 -0
  68. package/src/components/progress/progress.css +70 -0
  69. package/src/components/radio/radio.css +115 -0
  70. package/src/components/resizable/resizable.css +99 -0
  71. package/src/components/scroll-area/scroll-area.css +130 -0
  72. package/src/components/scrollable-list/scrollable-list.css +144 -0
  73. package/src/components/segmented-control/segmented-control.css +235 -0
  74. package/src/components/select/select.css +261 -0
  75. package/src/components/separator/separator.css +43 -0
  76. package/src/components/sheet/sheet.css +209 -0
  77. package/src/components/sidebar/sidebar.css +728 -0
  78. package/src/components/sidebar-nav-tree/sidebar-nav-tree.css +179 -0
  79. package/src/components/skeleton/skeleton.css +42 -0
  80. package/src/components/slider/slider.css +124 -0
  81. package/src/components/switch/switch.css +149 -0
  82. package/src/components/table/table.css +183 -0
  83. package/src/components/tabs/tabs.css +416 -0
  84. package/src/components/text-ticker/text-ticker.css +139 -0
  85. package/src/components/textarea/textarea.css +122 -0
  86. package/src/components/toggle/toggle.css +185 -0
  87. package/src/components/toggle-group/toggle-group.css +102 -0
  88. package/src/components/tooltip/tooltip.css +133 -0
  89. package/src/media/media-lightbox/media-lightbox.css +171 -0
  90. package/src/styles/index.css +3 -0
  91. package/src/styles/recipes.css +70 -0
  92. package/src/styles/reset.css +22 -0
@@ -0,0 +1,1173 @@
1
+ import { Slider, SegmentedControl, ATOM63_FLYOUT_TRANSITION_CSS, Frame, FramePanel, Button, ScrollArea, FrameFooter } from '../chunk-STCXERLM.js';
2
+ import { cn } from '../chunk-AJLHJRK6.js';
3
+ import { useId, useRef, useState, useCallback, useEffect, createContext, useMemo, useContext } from 'react';
4
+ import { createPortal } from 'react-dom';
5
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
6
+
7
+ var MODE_WINDOW = {
8
+ chromeHeight: 18,
9
+ height: 70,
10
+ rx: 10,
11
+ splitX: 56,
12
+ width: 102,
13
+ x: 5,
14
+ y: 5
15
+ };
16
+ var MODE_PREVIEW_PALETTE = {
17
+ dark: {
18
+ chrome: "var(--surface-dark-3)",
19
+ dot: "var(--surface-dark-9)",
20
+ line: "var(--surface-dark-8)",
21
+ lineStrong: "var(--surface-dark-11)",
22
+ surface: "var(--surface-dark-2)"
23
+ },
24
+ light: {
25
+ chrome: "var(--surface-light-3)",
26
+ dot: "var(--surface-light-9)",
27
+ line: "var(--surface-light-8)",
28
+ lineStrong: "var(--surface-light-11)",
29
+ surface: "var(--surface-light-2)"
30
+ }
31
+ };
32
+ function ModeWindowContent({
33
+ palette
34
+ }) {
35
+ const { x, y, width, height, chromeHeight } = MODE_WINDOW;
36
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
37
+ /* @__PURE__ */ jsx("rect", { fill: palette.surface, height, width, x, y }),
38
+ /* @__PURE__ */ jsx("rect", { fill: palette.chrome, height: chromeHeight, width, x, y }),
39
+ /* @__PURE__ */ jsx("circle", { cx: x + 12, cy: y + 9, fill: palette.dot, r: 3 }),
40
+ /* @__PURE__ */ jsx("circle", { cx: x + 23, cy: y + 9, fill: palette.dot, r: 3 }),
41
+ /* @__PURE__ */ jsx("rect", { fill: palette.lineStrong, height: 5, rx: 2.5, width: 42, x: x + 13, y: y + 29 }),
42
+ /* @__PURE__ */ jsx("rect", { fill: palette.line, height: 5, rx: 2.5, width: 62, x: x + 13, y: y + 42 }),
43
+ /* @__PURE__ */ jsx("rect", { fill: "var(--a63-action-primary)", height: 9, rx: 4.5, width: 30, x: x + 13, y: y + 54 })
44
+ ] });
45
+ }
46
+ function ModeWindowOutline({ selected }) {
47
+ return /* @__PURE__ */ jsx(
48
+ "rect",
49
+ {
50
+ className: selected ? "stroke-[color-mix(in_oklch,var(--a63-action-primary)_80%,transparent)]" : "stroke-[var(--a63-border-subtle)]",
51
+ fill: "none",
52
+ height: MODE_WINDOW.height,
53
+ rx: MODE_WINDOW.rx,
54
+ strokeWidth: "1.5",
55
+ width: MODE_WINDOW.width,
56
+ x: MODE_WINDOW.x,
57
+ y: MODE_WINDOW.y
58
+ }
59
+ );
60
+ }
61
+ function ModePreview({ mode, selected }) {
62
+ const id = useId().replaceAll(":", "");
63
+ const windowClipId = `${id}-window`;
64
+ const leftClipId = `${id}-left`;
65
+ const rightClipId = `${id}-right`;
66
+ const modeLabel = mode === "system" ? "Auto mode preview" : `${mode} mode preview`;
67
+ return /* @__PURE__ */ jsxs(
68
+ "svg",
69
+ {
70
+ "aria-hidden": "true",
71
+ className: "h-[4.25rem] w-full shrink-0 px-2 drop-shadow-sm",
72
+ "data-slot": "appearance-mode-preview",
73
+ fill: "none",
74
+ viewBox: "0 0 112 80",
75
+ children: [
76
+ /* @__PURE__ */ jsx("title", { children: modeLabel }),
77
+ /* @__PURE__ */ jsxs("defs", { children: [
78
+ /* @__PURE__ */ jsx("clipPath", { id: windowClipId, children: /* @__PURE__ */ jsx(
79
+ "rect",
80
+ {
81
+ height: MODE_WINDOW.height,
82
+ rx: MODE_WINDOW.rx,
83
+ width: MODE_WINDOW.width,
84
+ x: MODE_WINDOW.x,
85
+ y: MODE_WINDOW.y
86
+ }
87
+ ) }),
88
+ mode === "system" ? /* @__PURE__ */ jsxs(Fragment, { children: [
89
+ /* @__PURE__ */ jsx("clipPath", { id: leftClipId, children: /* @__PURE__ */ jsx(
90
+ "rect",
91
+ {
92
+ height: MODE_WINDOW.height,
93
+ width: MODE_WINDOW.splitX - MODE_WINDOW.x,
94
+ x: MODE_WINDOW.x,
95
+ y: MODE_WINDOW.y
96
+ }
97
+ ) }),
98
+ /* @__PURE__ */ jsx("clipPath", { id: rightClipId, children: /* @__PURE__ */ jsx(
99
+ "rect",
100
+ {
101
+ height: MODE_WINDOW.height,
102
+ width: MODE_WINDOW.x + MODE_WINDOW.width - MODE_WINDOW.splitX,
103
+ x: MODE_WINDOW.splitX,
104
+ y: MODE_WINDOW.y
105
+ }
106
+ ) })
107
+ ] }) : null
108
+ ] }),
109
+ /* @__PURE__ */ jsx("g", { clipPath: `url(#${windowClipId})`, children: mode === "system" ? /* @__PURE__ */ jsxs(Fragment, { children: [
110
+ /* @__PURE__ */ jsx("g", { clipPath: `url(#${leftClipId})`, children: /* @__PURE__ */ jsx(ModeWindowContent, { palette: MODE_PREVIEW_PALETTE.light }) }),
111
+ /* @__PURE__ */ jsx("g", { clipPath: `url(#${rightClipId})`, children: /* @__PURE__ */ jsx(ModeWindowContent, { palette: MODE_PREVIEW_PALETTE.dark }) }),
112
+ /* @__PURE__ */ jsx(
113
+ "line",
114
+ {
115
+ stroke: "var(--a63-border-subtle)",
116
+ strokeDasharray: "2 2",
117
+ strokeOpacity: "0.85",
118
+ strokeWidth: "0.75",
119
+ x1: MODE_WINDOW.splitX,
120
+ x2: MODE_WINDOW.splitX,
121
+ y1: MODE_WINDOW.y + 3,
122
+ y2: MODE_WINDOW.y + MODE_WINDOW.height - 3
123
+ }
124
+ )
125
+ ] }) : /* @__PURE__ */ jsx(
126
+ ModeWindowContent,
127
+ {
128
+ palette: mode === "dark" ? MODE_PREVIEW_PALETTE.dark : MODE_PREVIEW_PALETTE.light
129
+ }
130
+ ) }),
131
+ /* @__PURE__ */ jsx(ModeWindowOutline, { selected })
132
+ ]
133
+ }
134
+ );
135
+ }
136
+ var FONT_FAMILY_VAR = {
137
+ sans: "var(--font-family-sans)",
138
+ serif: "var(--font-family-serif)",
139
+ mono: "var(--font-family-mono)",
140
+ pixel: "var(--font-family-pixel)"
141
+ };
142
+ function FontPreview({ font, selected }) {
143
+ const style = { fontFamily: FONT_FAMILY_VAR[font] };
144
+ return /* @__PURE__ */ jsx(
145
+ "span",
146
+ {
147
+ "aria-hidden": "true",
148
+ className: cn(
149
+ "flex h-12 w-full items-center justify-center text-2xl leading-none transition-colors",
150
+ selected ? "text-[var(--a63-action-primary)]" : "text-[var(--a63-text-primary)]"
151
+ ),
152
+ "data-slot": "appearance-font-preview",
153
+ style,
154
+ children: "Aa"
155
+ }
156
+ );
157
+ }
158
+ function TypeScalePreview({ scale, selected }) {
159
+ const previewClassName = {
160
+ compact: "text-sm",
161
+ comfortable: "text-lg",
162
+ large: "text-xl",
163
+ normal: "text-base"
164
+ }[scale];
165
+ return /* @__PURE__ */ jsxs(
166
+ "span",
167
+ {
168
+ "aria-hidden": "true",
169
+ className: cn(
170
+ "flex h-12 w-full items-center justify-center gap-1",
171
+ selected ? "text-[var(--a63-action-primary)]" : "text-[var(--a63-text-primary)]"
172
+ ),
173
+ "data-slot": "appearance-type-scale-preview",
174
+ children: [
175
+ /* @__PURE__ */ jsx("span", { className: cn("leading-none font-semibold", previewClassName), children: "Aa" }),
176
+ /* @__PURE__ */ jsxs("span", { className: "grid gap-0.5", children: [
177
+ /* @__PURE__ */ jsx("span", { className: "block h-0.5 w-5 rounded-full bg-current opacity-50" }),
178
+ /* @__PURE__ */ jsx("span", { className: "block h-0.5 w-3 rounded-full bg-current opacity-30" })
179
+ ] })
180
+ ]
181
+ }
182
+ );
183
+ }
184
+ function RadiusPreview({ radius, selected }) {
185
+ const previewRadius = {
186
+ none: "0px",
187
+ subtle: "3px",
188
+ default: "6px",
189
+ round: "9999px"
190
+ }[radius];
191
+ const style = {
192
+ border: "2px solid currentColor",
193
+ borderRadius: previewRadius
194
+ };
195
+ return /* @__PURE__ */ jsx(
196
+ "span",
197
+ {
198
+ className: cn(
199
+ "flex h-12 w-full items-center justify-center",
200
+ selected ? "text-[var(--a63-action-primary)]" : "text-[var(--a63-text-primary)]"
201
+ ),
202
+ "data-slot": "appearance-radius-preview",
203
+ children: /* @__PURE__ */ jsx("span", { className: "block h-4 w-12", style })
204
+ }
205
+ );
206
+ }
207
+ function AppearanceSection({ children, title }) {
208
+ return /* @__PURE__ */ jsxs("section", { className: "min-w-0 space-y-2", "data-slot": "appearance-section", children: [
209
+ /* @__PURE__ */ jsx("span", { className: "block text-sm font-medium text-[var(--a63-text-primary)]", children: title }),
210
+ children
211
+ ] });
212
+ }
213
+
214
+ // src/theme/core/options.ts
215
+ var MODE_OPTIONS = [
216
+ { id: "light", name: "Light" },
217
+ { id: "dark", name: "Dark" },
218
+ { id: "system", name: "Auto" }
219
+ ];
220
+ var THEME_OPTIONS = [
221
+ { id: "modern", name: "Modern" },
222
+ { id: "aqua", name: "Aqua" },
223
+ { id: "retro", name: "Retro" },
224
+ { id: "terminal", name: "Terminal" }
225
+ ];
226
+ var BRAND_OPTIONS = [
227
+ { id: "auto", name: "Auto" },
228
+ { id: "b1", name: "b1" },
229
+ { id: "b2", name: "b2" },
230
+ { id: "b3", name: "b3" },
231
+ { id: "b4", name: "b4" },
232
+ { id: "b5", name: "b5" },
233
+ { id: "b6", name: "b6" }
234
+ ];
235
+ var SURFACE_OPTIONS = [
236
+ { id: "n1", name: "n1" },
237
+ { id: "n2", name: "n2" },
238
+ { id: "n3", name: "n3" },
239
+ { id: "n4", name: "n4" },
240
+ { id: "n5", name: "n5" },
241
+ { id: "n6", name: "n6" }
242
+ ];
243
+ var TYPE_SCALE_OPTIONS = [
244
+ { id: "compact", name: "Compact" },
245
+ { id: "normal", name: "Normal" },
246
+ { id: "comfortable", name: "Comfortable" },
247
+ { id: "large", name: "Large" }
248
+ ];
249
+ var RADIUS_OPTIONS = [
250
+ { id: "none", name: "None" },
251
+ { id: "subtle", name: "Subtle" },
252
+ { id: "default", name: "Default" },
253
+ { id: "round", name: "Round" }
254
+ ];
255
+ var FONT_OPTIONS = [
256
+ { id: "sans", name: "Sans" },
257
+ { id: "serif", name: "Serif" },
258
+ { id: "mono", name: "Mono" },
259
+ { id: "pixel", name: "Pixel" }
260
+ ];
261
+ var OS_OPTIONS = [
262
+ { id: "macos", name: "macOS" },
263
+ { id: "windows", name: "Windows" }
264
+ ];
265
+ var ICON_THEME_OPTIONS = [
266
+ { id: "realistic", name: "HD" },
267
+ { id: "color", name: "Color" },
268
+ { id: "neutral", name: "Mono" },
269
+ { id: "primary", name: "Primary" }
270
+ ];
271
+ function RangeTokenControl({
272
+ label,
273
+ max = 100,
274
+ min = 0,
275
+ onChange,
276
+ value
277
+ }) {
278
+ const valueLabel = value === min ? "Off" : `${value}%`;
279
+ return /* @__PURE__ */ jsxs("div", { className: "grid gap-2.5", "data-slot": "range-token-control", children: [
280
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-3", children: [
281
+ /* @__PURE__ */ jsx("span", { className: "text-sm font-medium text-[var(--a63-text-primary)]", children: label }),
282
+ /* @__PURE__ */ jsx("span", { className: "min-w-10 text-right text-xs font-medium text-[var(--a63-text-secondary)] tabular-nums", children: valueLabel })
283
+ ] }),
284
+ /* @__PURE__ */ jsx(Slider, { "aria-label": label, max, min, onValueChange: onChange, value })
285
+ ] });
286
+ }
287
+ function SegmentedTokenControl({
288
+ className,
289
+ onChange,
290
+ options,
291
+ value
292
+ }) {
293
+ const items = options.map((option) => ({
294
+ label: option.name,
295
+ value: option.id
296
+ }));
297
+ return /* @__PURE__ */ jsx(
298
+ SegmentedControl,
299
+ {
300
+ className: cn("w-full", className),
301
+ fullWidth: true,
302
+ items,
303
+ onValueChange: (next) => onChange(next),
304
+ size: "lg",
305
+ value,
306
+ variant: "label"
307
+ }
308
+ );
309
+ }
310
+ function SwatchTokenControl({
311
+ className,
312
+ onChange,
313
+ options,
314
+ swatch,
315
+ value
316
+ }) {
317
+ const items = options.map((option) => ({
318
+ icon: /* @__PURE__ */ jsx(
319
+ "span",
320
+ {
321
+ "aria-hidden": "true",
322
+ className: "block size-4 rounded-full shadow-[inset_0_1px_0_rgb(255_255_255/0.28)] ring-1 ring-black/10 ring-inset dark:ring-white/15",
323
+ "data-slot": "swatch",
324
+ style: { background: swatch(option.id) }
325
+ }
326
+ ),
327
+ label: option.name,
328
+ value: option.id
329
+ }));
330
+ return /* @__PURE__ */ jsx(
331
+ SegmentedControl,
332
+ {
333
+ className: cn("w-full", className),
334
+ fullWidth: true,
335
+ items,
336
+ onValueChange: (next) => onChange(next),
337
+ size: "lg",
338
+ value,
339
+ variant: "icon"
340
+ }
341
+ );
342
+ }
343
+ var VISUAL_CHOICE_BUTTON_CLASS = "group relative flex min-h-[5.5rem] flex-col items-center justify-center gap-2.5 overflow-hidden rounded-[calc(var(--radius-lg)+2px)] border border-[var(--a63-border-subtle)] bg-[var(--a63-surface-panel)] px-3 py-3 text-center text-[var(--a63-text-secondary)] transition-[background-color,border-color,box-shadow,color,transform] duration-150 ease-out motion-reduce:transition-none hover:-translate-y-px hover:border-[var(--a63-border-control)] hover:text-[var(--a63-text-primary)] hover:shadow-sm motion-reduce:hover:translate-y-0 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--a63-focus-ring)] active:translate-y-0 active:scale-[0.99] motion-reduce:active:scale-100 data-[state=checked]:border-[var(--a63-action-primary)] data-[state=checked]:bg-[color-mix(in_oklch,var(--a63-action-primary)_8%,transparent)] data-[state=checked]:text-[var(--a63-text-primary)] data-[state=checked]:shadow-[0_0_0_1px_var(--a63-action-primary)]";
344
+ var COLUMN_CLASS = {
345
+ 3: "grid-cols-[repeat(auto-fit,minmax(min(4.5rem,100%),1fr))]",
346
+ 4: "grid-cols-[repeat(auto-fit,minmax(min(4.5rem,100%),1fr))]"
347
+ };
348
+ function VisualChoiceControl({
349
+ className,
350
+ columns = 4,
351
+ label,
352
+ onChange,
353
+ options,
354
+ value
355
+ }) {
356
+ return /* @__PURE__ */ jsxs(
357
+ "fieldset",
358
+ {
359
+ className: cn("grid min-w-0 gap-2 border-0 p-0", COLUMN_CLASS[columns], className),
360
+ "data-slot": "visual-choice-control",
361
+ children: [
362
+ /* @__PURE__ */ jsx("legend", { className: "sr-only", children: label }),
363
+ options.map((option) => {
364
+ const selected = option.id === value;
365
+ return /* @__PURE__ */ jsxs(
366
+ "button",
367
+ {
368
+ "aria-pressed": selected,
369
+ className: VISUAL_CHOICE_BUTTON_CLASS,
370
+ "data-slot": "visual-choice-option",
371
+ "data-state": selected ? "checked" : "unchecked",
372
+ onClick: () => onChange(option.id),
373
+ type: "button",
374
+ children: [
375
+ option.renderVisual(selected),
376
+ /* @__PURE__ */ jsx("span", { className: "max-w-full truncate text-xs leading-none font-medium", children: option.name })
377
+ ]
378
+ },
379
+ option.id
380
+ );
381
+ })
382
+ ]
383
+ }
384
+ );
385
+ }
386
+ var DEFAULT_SECTIONS = [
387
+ "mode",
388
+ "theme",
389
+ "brand",
390
+ "surface",
391
+ "surfaceTint",
392
+ "typeScale",
393
+ "radius",
394
+ "font"
395
+ ];
396
+ var brandSwatch = (id) => id === "auto" ? "linear-gradient(135deg, var(--color-b1-500), var(--color-b4-500), var(--color-b2-500))" : `var(--color-${id}-500)`;
397
+ var surfaceSwatch = (id) => `var(--color-${id}-light-11)`;
398
+ function AppearancePanel({
399
+ controller,
400
+ sections = DEFAULT_SECTIONS,
401
+ className
402
+ }) {
403
+ const { state } = controller;
404
+ const has = (id) => sections.includes(id);
405
+ return /* @__PURE__ */ jsx("div", { className: cn("min-w-0", className), "data-slot": "appearance-panel", children: /* @__PURE__ */ jsxs("div", { className: "grid min-w-0 gap-5", children: [
406
+ has("mode") && /* @__PURE__ */ jsx(AppearanceSection, { title: "Mode", children: /* @__PURE__ */ jsx(
407
+ VisualChoiceControl,
408
+ {
409
+ columns: 3,
410
+ label: "Mode",
411
+ onChange: controller.setMode,
412
+ options: MODE_OPTIONS.map((o) => ({
413
+ id: o.id,
414
+ name: o.name,
415
+ renderVisual: (s) => /* @__PURE__ */ jsx(ModePreview, { mode: o.id, selected: s })
416
+ })),
417
+ value: state.mode
418
+ }
419
+ ) }),
420
+ has("theme") && /* @__PURE__ */ jsx(AppearanceSection, { title: "Theme", children: /* @__PURE__ */ jsx(
421
+ SegmentedTokenControl,
422
+ {
423
+ onChange: controller.setTheme,
424
+ options: THEME_OPTIONS,
425
+ value: state.theme
426
+ }
427
+ ) }),
428
+ has("brand") && /* @__PURE__ */ jsx(AppearanceSection, { title: "Primary", children: /* @__PURE__ */ jsx(
429
+ SwatchTokenControl,
430
+ {
431
+ onChange: controller.setBrand,
432
+ options: BRAND_OPTIONS,
433
+ swatch: brandSwatch,
434
+ value: state.brand
435
+ }
436
+ ) }),
437
+ has("surface") && /* @__PURE__ */ jsx(AppearanceSection, { title: "Surface", children: /* @__PURE__ */ jsx(
438
+ SwatchTokenControl,
439
+ {
440
+ onChange: controller.setSurface,
441
+ options: SURFACE_OPTIONS,
442
+ swatch: surfaceSwatch,
443
+ value: state.surface
444
+ }
445
+ ) }),
446
+ has("surfaceTint") && /* @__PURE__ */ jsx(
447
+ RangeTokenControl,
448
+ {
449
+ label: "Surface tint",
450
+ onChange: controller.setSurfaceTint,
451
+ value: state.surfaceTint
452
+ }
453
+ ),
454
+ has("typeScale") && /* @__PURE__ */ jsx(AppearanceSection, { title: "Type scale", children: /* @__PURE__ */ jsx(
455
+ VisualChoiceControl,
456
+ {
457
+ columns: 4,
458
+ label: "Type scale",
459
+ onChange: controller.setTypeScale,
460
+ options: TYPE_SCALE_OPTIONS.map((o) => ({
461
+ id: o.id,
462
+ name: o.name,
463
+ renderVisual: (s) => /* @__PURE__ */ jsx(TypeScalePreview, { scale: o.id, selected: s })
464
+ })),
465
+ value: state.typeScale
466
+ }
467
+ ) }),
468
+ has("radius") && /* @__PURE__ */ jsx(AppearanceSection, { title: "Radius", children: /* @__PURE__ */ jsx(
469
+ VisualChoiceControl,
470
+ {
471
+ columns: 4,
472
+ label: "Radius",
473
+ onChange: controller.setRadius,
474
+ options: RADIUS_OPTIONS.map((o) => ({
475
+ id: o.id,
476
+ name: o.name,
477
+ renderVisual: (s) => /* @__PURE__ */ jsx(RadiusPreview, { radius: o.id, selected: s })
478
+ })),
479
+ value: state.radius
480
+ }
481
+ ) }),
482
+ has("font") && /* @__PURE__ */ jsx(AppearanceSection, { title: "Font", children: /* @__PURE__ */ jsx(
483
+ VisualChoiceControl,
484
+ {
485
+ columns: 4,
486
+ label: "Font",
487
+ onChange: controller.setFont,
488
+ options: FONT_OPTIONS.map((o) => ({
489
+ id: o.id,
490
+ name: o.name,
491
+ renderVisual: (s) => /* @__PURE__ */ jsx(FontPreview, { font: o.id, selected: s })
492
+ })),
493
+ value: state.font
494
+ }
495
+ ) }),
496
+ has("os") && /* @__PURE__ */ jsx(AppearanceSection, { title: "System", children: /* @__PURE__ */ jsx(
497
+ SegmentedTokenControl,
498
+ {
499
+ onChange: controller.setOs,
500
+ options: OS_OPTIONS,
501
+ value: state.os
502
+ }
503
+ ) }),
504
+ has("iconTheme") && /* @__PURE__ */ jsx(AppearanceSection, { title: "Icons", children: /* @__PURE__ */ jsx(
505
+ SegmentedTokenControl,
506
+ {
507
+ onChange: controller.setIconTheme,
508
+ options: ICON_THEME_OPTIONS,
509
+ value: state.iconTheme
510
+ }
511
+ ) })
512
+ ] }) });
513
+ }
514
+ var DEFAULT_SHORTCUT_LABEL = "Cmd+,";
515
+ var FLYOUT_CLOSED_TRANSFORM = "translate3d(0, calc(100% + 0.75rem), 0)";
516
+ function getMenuMotionStyle(open, reduceMotion) {
517
+ if (reduceMotion) {
518
+ return { opacity: open ? 1 : 0, transform: "translate3d(0, 0, 0)" };
519
+ }
520
+ return {
521
+ opacity: open ? 1 : 0,
522
+ transform: open ? "translate3d(0, 0, 0)" : FLYOUT_CLOSED_TRANSFORM,
523
+ transition: [
524
+ `transform ${ATOM63_FLYOUT_TRANSITION_CSS.duration} ${ATOM63_FLYOUT_TRANSITION_CSS.easing}`,
525
+ `opacity ${ATOM63_FLYOUT_TRANSITION_CSS.duration} ${ATOM63_FLYOUT_TRANSITION_CSS.easing}`,
526
+ `filter ${ATOM63_FLYOUT_TRANSITION_CSS.duration} ${ATOM63_FLYOUT_TRANSITION_CSS.easing}`
527
+ ].join(", "),
528
+ willChange: "transform, opacity, filter"
529
+ };
530
+ }
531
+ function AppearanceMenu({
532
+ className,
533
+ closeLabel = "Close preferences",
534
+ controller,
535
+ defaultOpen = false,
536
+ description = "Tune the interface without leaving the page.",
537
+ enableShortcut = true,
538
+ ignoreOutsideSelector,
539
+ onOpenChange,
540
+ open,
541
+ panelClassName,
542
+ resetLabel = "Reset all",
543
+ sections,
544
+ shortcutLabel = DEFAULT_SHORTCUT_LABEL,
545
+ showTrigger = true,
546
+ title = "Preferences",
547
+ triggerLabel = "Preferences"
548
+ }) {
549
+ const titleId = useId();
550
+ const panelRef = useRef(null);
551
+ const triggerRef = useRef(null);
552
+ const [internalOpen, setInternalOpen] = useState(defaultOpen);
553
+ const [renderOpen, setRenderOpen] = useState(defaultOpen);
554
+ const [visible, setVisible] = useState(defaultOpen);
555
+ const [reduceMotion, setReduceMotion] = useState(false);
556
+ const isControlled = open !== void 0;
557
+ const isOpen = open ?? internalOpen;
558
+ const setOpen = useCallback(
559
+ (nextOpen) => {
560
+ if (!isControlled) {
561
+ setInternalOpen(nextOpen);
562
+ }
563
+ onOpenChange?.(nextOpen);
564
+ },
565
+ [isControlled, onOpenChange]
566
+ );
567
+ useEffect(() => {
568
+ if (typeof window === "undefined" || typeof window.matchMedia !== "function") {
569
+ return;
570
+ }
571
+ const query = window.matchMedia("(prefers-reduced-motion: reduce)");
572
+ const handleChange = () => setReduceMotion(query.matches);
573
+ handleChange();
574
+ query.addEventListener("change", handleChange);
575
+ return () => query.removeEventListener("change", handleChange);
576
+ }, []);
577
+ useEffect(() => {
578
+ if (isOpen) {
579
+ setRenderOpen(true);
580
+ const frame = window.requestAnimationFrame(() => setVisible(true));
581
+ return () => window.cancelAnimationFrame(frame);
582
+ }
583
+ setVisible(false);
584
+ if (reduceMotion) {
585
+ setRenderOpen(false);
586
+ return;
587
+ }
588
+ const timeout = window.setTimeout(
589
+ () => setRenderOpen(false),
590
+ ATOM63_FLYOUT_TRANSITION_CSS.durationMs
591
+ );
592
+ return () => window.clearTimeout(timeout);
593
+ }, [isOpen, reduceMotion]);
594
+ useEffect(() => {
595
+ if (!(enableShortcut && typeof window !== "undefined")) {
596
+ return;
597
+ }
598
+ const handleKeyDown = (event) => {
599
+ if ((event.metaKey || event.ctrlKey) && event.key === ",") {
600
+ event.preventDefault();
601
+ setOpen(!isOpen);
602
+ return;
603
+ }
604
+ if (event.key === "Escape" && isOpen) {
605
+ setOpen(false);
606
+ }
607
+ };
608
+ window.addEventListener("keydown", handleKeyDown);
609
+ return () => window.removeEventListener("keydown", handleKeyDown);
610
+ }, [enableShortcut, isOpen, setOpen]);
611
+ useEffect(() => {
612
+ if (!(isOpen && typeof document !== "undefined")) {
613
+ return;
614
+ }
615
+ const handlePointerDown = (event) => {
616
+ const target = event.target;
617
+ if (!(target instanceof Node)) {
618
+ return;
619
+ }
620
+ if (panelRef.current?.contains(target) || triggerRef.current?.contains(target) || ignoreOutsideSelector && target instanceof Element && target.closest(ignoreOutsideSelector)) {
621
+ return;
622
+ }
623
+ setOpen(false);
624
+ };
625
+ document.addEventListener("pointerdown", handlePointerDown);
626
+ return () => document.removeEventListener("pointerdown", handlePointerDown);
627
+ }, [ignoreOutsideSelector, isOpen, setOpen]);
628
+ const menu = (isOpen || renderOpen) && typeof document !== "undefined" ? createPortal(
629
+ /* @__PURE__ */ jsx(
630
+ "div",
631
+ {
632
+ "aria-labelledby": titleId,
633
+ className: "fixed inset-x-3 bottom-3 z-200 w-auto rounded-2xl backdrop-blur-2xl sm:right-4 sm:bottom-4 sm:left-auto sm:w-[24rem]",
634
+ "data-slot": "appearance-menu-popover",
635
+ "data-state": visible ? "open" : "closed",
636
+ ref: panelRef,
637
+ role: "dialog",
638
+ style: getMenuMotionStyle(visible, reduceMotion),
639
+ children: /* @__PURE__ */ jsxs(
640
+ Frame,
641
+ {
642
+ className: `bg-muted/78 shadow-xl backdrop-blur-2xl ${panelClassName ?? ""}`,
643
+ style: { maxHeight: "min(86svh, 42rem)" },
644
+ children: [
645
+ /* @__PURE__ */ jsxs(FramePanel, { className: "bg-background/84 flex min-h-0 flex-1 flex-col overflow-hidden p-0 backdrop-blur-xl", children: [
646
+ /* @__PURE__ */ jsxs("header", { className: "border-border/80 flex items-start justify-between gap-3 border-b px-4 py-3", children: [
647
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
648
+ /* @__PURE__ */ jsx("h2", { className: "text-sm font-semibold", id: titleId, children: title }),
649
+ description ? /* @__PURE__ */ jsx("p", { className: "text-muted-foreground mt-0.5 text-xs", children: description }) : null
650
+ ] }),
651
+ /* @__PURE__ */ jsx(
652
+ Button,
653
+ {
654
+ "aria-label": closeLabel,
655
+ className: "-me-1 -mt-1 shrink-0",
656
+ onClick: () => setOpen(false),
657
+ size: "icon-sm",
658
+ type: "button",
659
+ variant: "ghost",
660
+ children: /* @__PURE__ */ jsx(
661
+ "svg",
662
+ {
663
+ "aria-hidden": true,
664
+ fill: "none",
665
+ height: "16",
666
+ stroke: "currentColor",
667
+ strokeLinecap: "round",
668
+ strokeWidth: "2",
669
+ viewBox: "0 0 24 24",
670
+ width: "16",
671
+ children: /* @__PURE__ */ jsx("path", { d: "M18 6 6 18M6 6l12 12" })
672
+ }
673
+ )
674
+ }
675
+ )
676
+ ] }),
677
+ /* @__PURE__ */ jsx(
678
+ ScrollArea,
679
+ {
680
+ className: "overflow-hidden",
681
+ scrollFade: true,
682
+ showScrollbarOnHover: true,
683
+ style: { height: "min(60svh, 32rem)" },
684
+ children: /* @__PURE__ */ jsx("div", { className: "p-4", children: /* @__PURE__ */ jsx(AppearancePanel, { controller, sections }) })
685
+ }
686
+ )
687
+ ] }),
688
+ /* @__PURE__ */ jsxs(FrameFooter, { className: "flex items-center justify-between gap-3 px-4 py-3", children: [
689
+ /* @__PURE__ */ jsx("kbd", { className: "border-border/70 bg-background text-muted-foreground rounded border px-1.5 py-0.5 text-[11px] font-medium", children: shortcutLabel }),
690
+ /* @__PURE__ */ jsx(Button, { onClick: controller.reset, size: "sm", type: "button", variant: "secondary", children: resetLabel })
691
+ ] })
692
+ ]
693
+ }
694
+ )
695
+ }
696
+ ),
697
+ document.body
698
+ ) : null;
699
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
700
+ showTrigger ? /* @__PURE__ */ jsx(
701
+ AppearanceMenuTrigger,
702
+ {
703
+ className,
704
+ label: triggerLabel,
705
+ onOpenChange: setOpen,
706
+ open: isOpen,
707
+ ref: triggerRef,
708
+ shortcutLabel
709
+ }
710
+ ) : null,
711
+ menu
712
+ ] });
713
+ }
714
+ function AppearanceMenuTrigger({
715
+ label = "Preferences",
716
+ onKeyDown,
717
+ onOpenChange,
718
+ open,
719
+ shortcutLabel = DEFAULT_SHORTCUT_LABEL,
720
+ ...props
721
+ }) {
722
+ const handleKeyDown = (event) => {
723
+ onKeyDown?.(event);
724
+ if (event.defaultPrevented) {
725
+ return;
726
+ }
727
+ if (event.key === "ArrowDown") {
728
+ event.preventDefault();
729
+ onOpenChange(true);
730
+ }
731
+ };
732
+ return /* @__PURE__ */ jsxs(
733
+ Button,
734
+ {
735
+ "aria-expanded": open,
736
+ "aria-haspopup": "dialog",
737
+ "data-slot": "appearance-menu-trigger",
738
+ onClick: () => onOpenChange(!open),
739
+ onKeyDown: handleKeyDown,
740
+ size: "sm",
741
+ type: "button",
742
+ variant: "ghost",
743
+ ...props,
744
+ children: [
745
+ /* @__PURE__ */ jsx("span", { children: label }),
746
+ /* @__PURE__ */ jsx("kbd", { className: "border-border/70 bg-background/70 text-muted-foreground hidden rounded border px-1.5 py-0.5 text-[10px] font-medium sm:inline", children: shortcutLabel })
747
+ ]
748
+ }
749
+ );
750
+ }
751
+
752
+ // src/theme/core/apply-personalization.ts
753
+ function resolveIsDark(mode) {
754
+ if (mode === "dark") {
755
+ return true;
756
+ }
757
+ if (mode === "light") {
758
+ return false;
759
+ }
760
+ if (typeof window === "undefined" || !window.matchMedia) {
761
+ return false;
762
+ }
763
+ return window.matchMedia("(prefers-color-scheme: dark)").matches;
764
+ }
765
+ function clampTint(tint) {
766
+ if (!Number.isFinite(tint)) {
767
+ return 0;
768
+ }
769
+ return Math.max(0, Math.min(100, tint));
770
+ }
771
+ function applyPersonalization(state, root = document.documentElement) {
772
+ const isDark = resolveIsDark(state.mode);
773
+ root.classList.toggle("dark", isDark);
774
+ root.classList.toggle("light", !isDark);
775
+ root.setAttribute("data-a63-mode", isDark ? "dark" : "light");
776
+ root.setAttribute("data-a63-theme", state.theme);
777
+ root.setAttribute("data-a63-brand", state.brand);
778
+ root.setAttribute("data-a63-surface", state.surface);
779
+ root.style.setProperty("--a63-surface-tint", `${clampTint(state.surfaceTint)}%`);
780
+ root.setAttribute("data-a63-type-scale", state.typeScale);
781
+ root.setAttribute("data-a63-radius", state.radius);
782
+ root.setAttribute("data-a63-font", state.font);
783
+ root.setAttribute("data-a63-os", state.os);
784
+ root.setAttribute("data-a63-icon-theme", state.iconTheme);
785
+ }
786
+
787
+ // src/theme/core/auto-contrast.ts
788
+ var AUTO_CONTRAST_WCAG_Y_THRESHOLD = 0.3;
789
+ function relativeLuminance(r, g, b) {
790
+ const toLinear = (c) => {
791
+ const s = c / 255;
792
+ return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
793
+ };
794
+ return 0.2126 * toLinear(r) + 0.7152 * toLinear(g) + 0.0722 * toLinear(b);
795
+ }
796
+ function shouldUseLightForeground(r, g, b) {
797
+ return relativeLuminance(r, g, b) < AUTO_CONTRAST_WCAG_Y_THRESHOLD;
798
+ }
799
+
800
+ // src/theme/core/auto-primary.ts
801
+ var AUTO_PRIMARY_ID = "auto";
802
+ function isAutoPrimary(primary) {
803
+ return primary === AUTO_PRIMARY_ID;
804
+ }
805
+ function rgbToHsl(r, g, b) {
806
+ r /= 255;
807
+ g /= 255;
808
+ b /= 255;
809
+ const max = Math.max(r, g, b);
810
+ const min = Math.min(r, g, b);
811
+ const l = (max + min) / 2;
812
+ if (max === min) return [0, 0, l];
813
+ const d = max - min;
814
+ const s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
815
+ let h = 0;
816
+ if (max === r) h = ((g - b) / d + (g < b ? 6 : 0)) / 6;
817
+ else if (max === g) h = ((b - r) / d + 2) / 6;
818
+ else h = ((r - g) / d + 4) / 6;
819
+ return [h * 360, s, l];
820
+ }
821
+ function hslToRgb(h, s, l) {
822
+ h = (h % 360 + 360) % 360 / 360;
823
+ if (s === 0) {
824
+ const v = Math.round(l * 255);
825
+ return [v, v, v];
826
+ }
827
+ const hue2rgb = (p2, q2, t) => {
828
+ if (t < 0) t += 1;
829
+ if (t > 1) t -= 1;
830
+ if (t < 1 / 6) return p2 + (q2 - p2) * 6 * t;
831
+ if (t < 1 / 2) return q2;
832
+ if (t < 2 / 3) return p2 + (q2 - p2) * (2 / 3 - t) * 6;
833
+ return p2;
834
+ };
835
+ const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
836
+ const p = 2 * l - q;
837
+ return [
838
+ Math.round(hue2rgb(p, q, h + 1 / 3) * 255),
839
+ Math.round(hue2rgb(p, q, h) * 255),
840
+ Math.round(hue2rgb(p, q, h - 1 / 3) * 255)
841
+ ];
842
+ }
843
+ var RAMP_STEPS = [
844
+ { step: 50, l: 0.97, sFactor: 0.25 },
845
+ { step: 100, l: 0.93, sFactor: 0.35 },
846
+ { step: 200, l: 0.87, sFactor: 0.5 },
847
+ { step: 300, l: 0.78, sFactor: 0.65 },
848
+ { step: 400, l: 0.68, sFactor: 0.82 },
849
+ { step: 500, l: 0.52, sFactor: 1 },
850
+ { step: 600, l: 0.43, sFactor: 0.92 },
851
+ { step: 700, l: 0.34, sFactor: 0.8 },
852
+ { step: 800, l: 0.24, sFactor: 0.65 },
853
+ { step: 900, l: 0.15, sFactor: 0.45 },
854
+ { step: 950, l: 0.08, sFactor: 0.25 }
855
+ ];
856
+ var AUTO_FALLBACK_COLOR = { hue: 217, saturation: 0.9 };
857
+ function applyAutoColorRamp(root, color) {
858
+ let primaryRgb = [0, 0, 0];
859
+ for (const { step, l, sFactor } of RAMP_STEPS) {
860
+ const s = Math.min(1, color.saturation * sFactor);
861
+ const rgb = hslToRgb(color.hue, s, l);
862
+ root.style.setProperty(`--color-auto-${step}`, `rgba(${rgb[0]}, ${rgb[1]}, ${rgb[2]}, 1)`);
863
+ if (step === 500) primaryRgb = rgb;
864
+ }
865
+ const useLight = shouldUseLightForeground(...primaryRgb);
866
+ const fgStep = useLight ? RAMP_STEPS[0] : RAMP_STEPS[RAMP_STEPS.length - 1];
867
+ const fgS = Math.min(1, color.saturation * fgStep.sFactor);
868
+ const fgRgb = hslToRgb(color.hue, fgS, fgStep.l);
869
+ root.style.setProperty(
870
+ "--color-auto-foreground",
871
+ `rgba(${fgRgb[0]}, ${fgRgb[1]}, ${fgRgb[2]}, 1)`
872
+ );
873
+ }
874
+ function clearAutoColorRamp(root) {
875
+ for (const { step } of RAMP_STEPS) {
876
+ root.style.removeProperty(`--color-auto-${step}`);
877
+ }
878
+ root.style.removeProperty("--color-auto-foreground");
879
+ }
880
+ async function extractDominantColor(imageSrc) {
881
+ try {
882
+ const img = new Image();
883
+ img.crossOrigin = "anonymous";
884
+ await new Promise((resolve, reject) => {
885
+ img.onload = () => resolve();
886
+ img.onerror = reject;
887
+ img.src = imageSrc;
888
+ });
889
+ if (img.naturalWidth === 0 || img.naturalHeight === 0) return null;
890
+ const scale = Math.min(1, 100 / img.naturalWidth);
891
+ const w = Math.round(img.naturalWidth * scale);
892
+ const h = Math.round(img.naturalHeight * scale);
893
+ if (w === 0 || h === 0) return null;
894
+ const canvas = document.createElement("canvas");
895
+ canvas.width = w;
896
+ canvas.height = h;
897
+ const ctx = canvas.getContext("2d");
898
+ if (!ctx) return null;
899
+ ctx.drawImage(img, 0, 0, w, h);
900
+ img.src = "";
901
+ const { data } = ctx.getImageData(0, 0, w, h);
902
+ const buckets = new Float64Array(36);
903
+ const bucketSat = new Float64Array(36);
904
+ const bucketCount = new Float64Array(36);
905
+ const stride = w * h > 2500 ? 16 : 4;
906
+ for (let i = 0; i < data.length; i += stride) {
907
+ const r = data[i];
908
+ const g = data[i + 1];
909
+ const b = data[i + 2];
910
+ const [hue, s, l] = rgbToHsl(r, g, b);
911
+ if (s < 0.15 || l < 0.1 || l > 0.9) continue;
912
+ const bucket = Math.floor(hue / 10) % 36;
913
+ buckets[bucket] += s;
914
+ bucketSat[bucket] += s;
915
+ bucketCount[bucket] += 1;
916
+ }
917
+ let maxBucket = 0;
918
+ let maxVal = buckets[0];
919
+ for (let i = 1; i < 36; i++) {
920
+ if (buckets[i] > maxVal) {
921
+ maxVal = buckets[i];
922
+ maxBucket = i;
923
+ }
924
+ }
925
+ if (maxVal === 0) return null;
926
+ const dominantHue = maxBucket * 10 + 5;
927
+ const avgSat = bucketCount[maxBucket] > 0 ? bucketSat[maxBucket] / bucketCount[maxBucket] : 0.6;
928
+ return { hue: dominantHue, saturation: Math.max(0.4, Math.min(1, avgSat * 1.2)) };
929
+ } catch {
930
+ return null;
931
+ }
932
+ }
933
+ function readStoredState(storageKey, defaultState) {
934
+ if (typeof window === "undefined") {
935
+ return defaultState;
936
+ }
937
+ try {
938
+ const stored = window.localStorage.getItem(storageKey);
939
+ if (!stored) {
940
+ return defaultState;
941
+ }
942
+ return { ...defaultState, ...JSON.parse(stored) };
943
+ } catch {
944
+ return defaultState;
945
+ }
946
+ }
947
+ function createPersonalizationController({
948
+ storageKey,
949
+ defaultState,
950
+ resolveWallpaperSrc
951
+ }) {
952
+ const Context = createContext(void 0);
953
+ function PersonalizationProvider({ children }) {
954
+ const [state, setState] = useState(() => readStoredState(storageKey, defaultState));
955
+ const autoGeneration = useRef(0);
956
+ useEffect(() => {
957
+ try {
958
+ window.localStorage.setItem(storageKey, JSON.stringify(state));
959
+ } catch {
960
+ }
961
+ applyPersonalization(state);
962
+ }, [state]);
963
+ useEffect(() => {
964
+ const root = document.documentElement;
965
+ if (state.brand !== "auto") {
966
+ clearAutoColorRamp(root);
967
+ return;
968
+ }
969
+ const generation = ++autoGeneration.current;
970
+ const isDark = root.classList.contains("dark");
971
+ const src = resolveWallpaperSrc?.(state.wallpaper, isDark);
972
+ if (!src) {
973
+ applyAutoColorRamp(root, AUTO_FALLBACK_COLOR);
974
+ return;
975
+ }
976
+ void extractDominantColor(src).then((color) => {
977
+ if (generation !== autoGeneration.current) {
978
+ return;
979
+ }
980
+ applyAutoColorRamp(root, color ?? AUTO_FALLBACK_COLOR);
981
+ });
982
+ }, [state.brand, state.wallpaper]);
983
+ useEffect(() => {
984
+ if (state.mode !== "system" || typeof window === "undefined" || !window.matchMedia) {
985
+ return;
986
+ }
987
+ const mq = window.matchMedia("(prefers-color-scheme: dark)");
988
+ const onChange = () => applyPersonalization(state);
989
+ mq.addEventListener("change", onChange);
990
+ return () => mq.removeEventListener("change", onChange);
991
+ }, [state]);
992
+ const update = useCallback((partial) => {
993
+ setState((current) => ({ ...current, ...partial }));
994
+ }, []);
995
+ const reset = useCallback(() => setState(defaultState), []);
996
+ const value = useMemo(
997
+ () => ({
998
+ state,
999
+ update,
1000
+ reset,
1001
+ setMode: (mode) => update({ mode }),
1002
+ setTheme: (theme) => update({ theme }),
1003
+ setBrand: (brand) => update({ brand }),
1004
+ setSurface: (surface) => update({ surface }),
1005
+ setSurfaceTint: (surfaceTint) => update({ surfaceTint }),
1006
+ setTypeScale: (typeScale) => update({ typeScale }),
1007
+ setRadius: (radius) => update({ radius }),
1008
+ setFont: (font) => update({ font }),
1009
+ setOs: (os) => update({ os }),
1010
+ setIconTheme: (iconTheme) => update({ iconTheme }),
1011
+ setWallpaper: (wallpaper) => update({ wallpaper })
1012
+ }),
1013
+ [state, update, reset]
1014
+ );
1015
+ return /* @__PURE__ */ jsx(Context.Provider, { value, children });
1016
+ }
1017
+ function usePersonalization() {
1018
+ const context = useContext(Context);
1019
+ if (!context) {
1020
+ throw new Error("usePersonalization must be used within PersonalizationProvider");
1021
+ }
1022
+ return context;
1023
+ }
1024
+ return { PersonalizationProvider, usePersonalization };
1025
+ }
1026
+ var DEFAULT_MODES = ["light", "dark", "system"];
1027
+ function resolveIsDark2(theme) {
1028
+ if (theme === "dark") {
1029
+ return true;
1030
+ }
1031
+ if (theme === "light") {
1032
+ return false;
1033
+ }
1034
+ if (typeof window === "undefined") {
1035
+ return true;
1036
+ }
1037
+ return window.matchMedia("(prefers-color-scheme: dark)").matches;
1038
+ }
1039
+ function applyHtmlTheme(theme) {
1040
+ const root = window.document.documentElement;
1041
+ root.classList.remove("light", "dark");
1042
+ if (theme === "system") {
1043
+ const systemTheme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
1044
+ root.classList.add(systemTheme);
1045
+ return;
1046
+ }
1047
+ root.classList.add(theme);
1048
+ }
1049
+ function readStoredTheme(storageKey, defaultTheme, modes) {
1050
+ if (typeof window === "undefined") {
1051
+ return defaultTheme;
1052
+ }
1053
+ try {
1054
+ const stored = localStorage.getItem(storageKey);
1055
+ if (stored && modes.includes(stored)) {
1056
+ return stored;
1057
+ }
1058
+ } catch {
1059
+ }
1060
+ return defaultTheme;
1061
+ }
1062
+ function createThemeProvider(options) {
1063
+ const {
1064
+ storageKey,
1065
+ defaultTheme = "dark",
1066
+ modes = DEFAULT_MODES,
1067
+ viewTransition = false
1068
+ } = options;
1069
+ const allowedModes = modes;
1070
+ const ThemeContext = createContext(void 0);
1071
+ function ThemeProvider({ children }) {
1072
+ const [theme, setThemeState] = useState(
1073
+ () => readStoredTheme(storageKey, defaultTheme, allowedModes)
1074
+ );
1075
+ const [isDark, setIsDark] = useState(() => resolveIsDark2(defaultTheme));
1076
+ const [isChanging, setIsChanging] = useState(false);
1077
+ useEffect(() => {
1078
+ applyHtmlTheme(theme);
1079
+ setIsDark(resolveIsDark2(theme));
1080
+ }, [theme]);
1081
+ useEffect(() => {
1082
+ if (theme !== "system") {
1083
+ return;
1084
+ }
1085
+ const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
1086
+ const handleChange = () => {
1087
+ setIsDark(mediaQuery.matches);
1088
+ applyHtmlTheme("system");
1089
+ };
1090
+ mediaQuery.addEventListener("change", handleChange);
1091
+ return () => mediaQuery.removeEventListener("change", handleChange);
1092
+ }, [theme]);
1093
+ const disableTransitions = useCallback(() => {
1094
+ setIsChanging(true);
1095
+ window.setTimeout(() => {
1096
+ setIsChanging(false);
1097
+ }, 100);
1098
+ }, []);
1099
+ const persistTheme = useCallback((newTheme) => {
1100
+ if (!allowedModes.includes(newTheme)) {
1101
+ return;
1102
+ }
1103
+ setThemeState(newTheme);
1104
+ try {
1105
+ localStorage.setItem(storageKey, newTheme);
1106
+ } catch {
1107
+ }
1108
+ }, []);
1109
+ const setTheme = useCallback(
1110
+ (newTheme) => {
1111
+ if (!allowedModes.includes(newTheme) || newTheme === theme) {
1112
+ return;
1113
+ }
1114
+ const switchTheme = () => {
1115
+ persistTheme(newTheme);
1116
+ };
1117
+ if (!viewTransition) {
1118
+ switchTheme();
1119
+ return;
1120
+ }
1121
+ setIsChanging(true);
1122
+ const html = document.documentElement;
1123
+ html.setAttribute("data-theme-transitioning", "true");
1124
+ const cleanup = () => {
1125
+ html.removeAttribute("data-theme-transitioning");
1126
+ setIsChanging(false);
1127
+ };
1128
+ const doc = document;
1129
+ if (doc.startViewTransition) {
1130
+ const transition = doc.startViewTransition({
1131
+ update: switchTheme,
1132
+ types: ["theme"]
1133
+ });
1134
+ void transition.finished.then(cleanup, cleanup);
1135
+ } else {
1136
+ switchTheme();
1137
+ window.setTimeout(cleanup, 100);
1138
+ }
1139
+ },
1140
+ [persistTheme, theme]
1141
+ );
1142
+ const toggleTheme = useCallback(() => {
1143
+ setTheme(isDark ? "light" : "dark");
1144
+ }, [isDark, setTheme]);
1145
+ const value = useMemo(
1146
+ () => ({
1147
+ theme,
1148
+ setTheme,
1149
+ toggleTheme,
1150
+ toggle: toggleTheme,
1151
+ isDark,
1152
+ isLight: !isDark,
1153
+ isSystem: theme === "system",
1154
+ isChanging,
1155
+ disableTransitions
1156
+ }),
1157
+ [theme, setTheme, toggleTheme, isDark, isChanging, disableTransitions]
1158
+ );
1159
+ return /* @__PURE__ */ jsx(ThemeContext.Provider, { value, children });
1160
+ }
1161
+ function useTheme() {
1162
+ const context = useContext(ThemeContext);
1163
+ if (context === void 0) {
1164
+ throw new Error("useTheme must be used within ThemeProvider");
1165
+ }
1166
+ return context;
1167
+ }
1168
+ return { ThemeProvider, useTheme };
1169
+ }
1170
+
1171
+ export { AUTO_FALLBACK_COLOR, AUTO_PRIMARY_ID, AppearanceMenu, AppearanceMenuTrigger, AppearancePanel, AppearanceSection, BRAND_OPTIONS, FONT_OPTIONS, ICON_THEME_OPTIONS, MODE_OPTIONS, OS_OPTIONS, RADIUS_OPTIONS, RangeTokenControl, SURFACE_OPTIONS, SegmentedTokenControl, SwatchTokenControl, THEME_OPTIONS, TYPE_SCALE_OPTIONS, VisualChoiceControl, applyAutoColorRamp, applyPersonalization, clearAutoColorRamp, createPersonalizationController, createThemeProvider, extractDominantColor, isAutoPrimary };
1172
+ //# sourceMappingURL=index.js.map
1173
+ //# sourceMappingURL=index.js.map