anvilui 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -10,7 +10,10 @@ function cx(...parts) {
10
10
  return parts.filter(Boolean).join(" ");
11
11
  }
12
12
  function withClass(base, className) {
13
- return (state) => cx(base, typeof className === "function" ? className(state) : className);
13
+ return (state) => cx(
14
+ typeof base === "function" ? base(state) : base,
15
+ typeof className === "function" ? className(state) : className
16
+ );
14
17
  }
15
18
  function splitControlProps(props) {
16
19
  const control = {};
@@ -177,13 +180,15 @@ import 'anvilui/styles.css'
177
180
  "setup.md"
178
181
  );
179
182
  }
180
- function checkName(props, component, example, doc) {
183
+ var NO_TEXT = "It shows no text, so screen readers need an `aria-label`.";
184
+ var UNNAMED_GROUP = "Screen readers announce the group without saying what it's for: give it an `aria-label`.";
185
+ var UNNAMED_NAV = 'Screen readers list it as just "navigation": give it an `aria-label` to tell it apart from other navigation.';
186
+ function inNamedFieldset(el) {
187
+ return !!el?.closest("fieldset")?.querySelector(":scope > legend");
188
+ }
189
+ function checkName(props, component, example, doc, reason = NO_TEXT) {
181
190
  if (props["aria-label"] || props["aria-labelledby"]) return;
182
- devError(
183
- `<${component}> has no accessible name. It shows no text, so screen readers need an \`aria-label\`.`,
184
- example,
185
- doc
186
- );
191
+ devError(`<${component}> has no accessible name. ${reason}`, example, doc);
187
192
  }
188
193
 
189
194
  // src/components/Typography/Typography.tsx
@@ -319,12 +324,13 @@ function Avatar({
319
324
  const groupSize = useContext3(AvatarGroupContext);
320
325
  const size = sizeProp ?? groupSize ?? "normal";
321
326
  const letters = name ? initials(name) : "";
327
+ const named = !!(name || props["aria-label"] || props["aria-labelledby"]);
322
328
  return /* @__PURE__ */ jsxs3(
323
329
  BaseAvatar.Root,
324
330
  {
325
- role: name ? "img" : void 0,
331
+ role: named ? "img" : void 0,
326
332
  "aria-label": name,
327
- "aria-hidden": name ? void 0 : true,
333
+ "aria-hidden": named ? void 0 : true,
328
334
  ...props,
329
335
  className: withClass(
330
336
  cx(
@@ -368,6 +374,15 @@ function AvatarGroup({
368
374
  children,
369
375
  ...props
370
376
  }) {
377
+ if (process.env.NODE_ENV !== "production") {
378
+ checkName(
379
+ props,
380
+ "AvatarGroup",
381
+ '<AvatarGroup aria-label="Project members">...</AvatarGroup>',
382
+ "avatar-group.md",
383
+ UNNAMED_GROUP
384
+ );
385
+ }
371
386
  const avatars = Children.toArray(children);
372
387
  const overflow = max !== void 0 && avatars.length > max;
373
388
  const shown = overflow ? avatars.slice(0, Math.max(0, max - 1)) : avatars;
@@ -680,10 +695,9 @@ function HoldButton({
680
695
  "aria-description": "Press and hold to confirm",
681
696
  "data-hold": state === "idle" ? void 0 : state,
682
697
  "data-nudge": nudges % 2 === 0 ? "even" : "odd",
683
- className: (buttonState) => cx(
684
- "avl-hold-button",
685
- nudges > 0 && "avl-hold-button-nudged",
686
- typeof className === "function" ? className(buttonState) : className
698
+ className: withClass(
699
+ cx("avl-hold-button", nudges > 0 && "avl-hold-button-nudged"),
700
+ className
687
701
  ),
688
702
  style: (buttonState) => ({
689
703
  "--avl-hold-duration": `${holdDuration}ms`,
@@ -952,6 +966,12 @@ function Calendar({
952
966
  const now = /* @__PURE__ */ new Date();
953
967
  return selected ?? new Date(now.getFullYear(), now.getMonth(), now.getDate());
954
968
  });
969
+ const selectedIso = selected && toIso(selected);
970
+ const [shownSelection, setShownSelection] = useState3(selectedIso);
971
+ if (selectedIso !== shownSelection) {
972
+ setShownSelection(selectedIso);
973
+ if (selected) setFocused(selected);
974
+ }
955
975
  const [weekStart] = useState3(localeWeekStart);
956
976
  const dayRef = useRef4(null);
957
977
  const moveFocus = useRef4(false);
@@ -984,7 +1004,6 @@ function Calendar({
984
1004
  onValueChange?.(iso);
985
1005
  };
986
1006
  const today = toIso(/* @__PURE__ */ new Date());
987
- const selectedIso = selected && toIso(selected);
988
1007
  const focusedIso = toIso(focused);
989
1008
  const offset = (new Date(year, month, 1).getDay() - weekStart + 7) % 7;
990
1009
  const daysInMonth = new Date(year, month + 1, 0).getDate();
@@ -2200,6 +2219,7 @@ function FABMenu({
2200
2219
  align = "end",
2201
2220
  sticky = true,
2202
2221
  className,
2222
+ ref,
2203
2223
  children,
2204
2224
  ...props
2205
2225
  }) {
@@ -2223,7 +2243,7 @@ function FABMenu({
2223
2243
  /* @__PURE__ */ jsxs14(
2224
2244
  BaseMenu.Trigger,
2225
2245
  {
2226
- ref: trigger,
2246
+ ref: mergeRefs(trigger, ref),
2227
2247
  "aria-label": ariaLabel,
2228
2248
  className: cx(
2229
2249
  "avl-fab avl-fab-size-normal avl-fab-menu-trigger",
@@ -2991,7 +3011,13 @@ function loadingSpan(width, gap, now) {
2991
3011
  }
2992
3012
 
2993
3013
  // src/components/ToggleGroup/ToggleGroup.tsx
2994
- import { createContext as createContext6, useContext as useContext15, useLayoutEffect as useLayoutEffect3, useRef as useRef11 } from "react";
3014
+ import {
3015
+ createContext as createContext6,
3016
+ useContext as useContext15,
3017
+ useEffect as useEffect7,
3018
+ useLayoutEffect as useLayoutEffect3,
3019
+ useRef as useRef11
3020
+ } from "react";
2995
3021
  import { Radio as BaseRadio } from "@base-ui/react/radio";
2996
3022
  import { RadioGroup as BaseRadioGroup } from "@base-ui/react/radio-group";
2997
3023
  import { Toggle as BaseToggle } from "@base-ui/react/toggle";
@@ -3010,6 +3036,17 @@ function ToggleGroup({
3010
3036
  }) {
3011
3037
  const groupRef = useRef11(null);
3012
3038
  const indicatorRef = useRef11(null);
3039
+ useEffect7(() => {
3040
+ if (process.env.NODE_ENV === "production") return;
3041
+ if (inNamedFieldset(groupRef.current)) return;
3042
+ checkName(
3043
+ props,
3044
+ "ToggleGroup",
3045
+ '<ToggleGroup aria-label="View" defaultValue="list">...</ToggleGroup>',
3046
+ "toggle-group.md",
3047
+ UNNAMED_GROUP
3048
+ );
3049
+ }, []);
3013
3050
  useLayoutEffect3(() => {
3014
3051
  const group = groupRef.current;
3015
3052
  const indicator = indicatorRef.current;
@@ -3057,7 +3094,7 @@ function ToggleGroup({
3057
3094
  {
3058
3095
  ...props,
3059
3096
  multiple: true,
3060
- ref,
3097
+ ref: mergeRefs(groupRef, ref),
3061
3098
  className: classes,
3062
3099
  children
3063
3100
  }
@@ -3137,15 +3174,30 @@ function ToggleGroupItem({
3137
3174
  // src/components/RadioGroup/RadioGroup.tsx
3138
3175
  import { Radio as BaseRadio2 } from "@base-ui/react/radio";
3139
3176
  import { RadioGroup as BaseRadioGroup2 } from "@base-ui/react/radio-group";
3177
+ import { useEffect as useEffect8, useRef as useRef12 } from "react";
3140
3178
  import { jsx as jsx35 } from "react/jsx-runtime";
3141
3179
  function RadioGroup({
3142
3180
  className,
3181
+ ref,
3143
3182
  ...props
3144
3183
  }) {
3184
+ const local = useRef12(null);
3185
+ useEffect8(() => {
3186
+ if (process.env.NODE_ENV === "production") return;
3187
+ if (inNamedFieldset(local.current)) return;
3188
+ checkName(
3189
+ props,
3190
+ "RadioGroup",
3191
+ '<RadioGroup aria-label="Plan" defaultValue="free">...</RadioGroup>\n// or inside <fieldset><legend>Plan</legend>...</fieldset>',
3192
+ "radio-group.md",
3193
+ UNNAMED_GROUP
3194
+ );
3195
+ }, []);
3145
3196
  return /* @__PURE__ */ jsx35(
3146
3197
  BaseRadioGroup2,
3147
3198
  {
3148
3199
  ...props,
3200
+ ref: mergeRefs(local, ref),
3149
3201
  className: withClass("avl-radio-group", className)
3150
3202
  }
3151
3203
  );
@@ -3252,7 +3304,12 @@ function SelectItem({ className, children, ...props }) {
3252
3304
  }
3253
3305
 
3254
3306
  // src/components/TimePicker/TimePicker.tsx
3255
- import { useId as useId2, useRef as useRef12, useState as useState9 } from "react";
3307
+ import {
3308
+ useEffect as useEffect9,
3309
+ useId as useId2,
3310
+ useRef as useRef13,
3311
+ useState as useState9
3312
+ } from "react";
3256
3313
  import { Fragment as Fragment4, jsx as jsx37, jsxs as jsxs22 } from "react/jsx-runtime";
3257
3314
  var pad2 = (n) => String(n).padStart(2, "0");
3258
3315
  function localeHourCycle() {
@@ -3288,6 +3345,16 @@ function TimePicker({
3288
3345
  const cycle = hourCycle ?? localeHourCycle();
3289
3346
  const labelId = useId2();
3290
3347
  const valueId = useId2();
3348
+ const trigger = useRef13(null);
3349
+ useEffect9(() => {
3350
+ if (process.env.NODE_ENV === "production") return;
3351
+ if (trigger.current?.closest(".avl-field"))
3352
+ devError(
3353
+ "<TimePicker> is inside a <Field>, but it doesn't take the Field's `name`, `disabled` or validation.",
3354
+ '<TimePicker label="Alarm" name="alarm" disabled={locked} /> // outside any Field',
3355
+ "time-picker.md"
3356
+ );
3357
+ }, []);
3291
3358
  const setTime = (t) => {
3292
3359
  const next = t && `${pad2(t.h)}:${pad2(t.m)}`;
3293
3360
  setInternal(next);
@@ -3322,7 +3389,7 @@ function TimePicker({
3322
3389
  PopoverTrigger,
3323
3390
  {
3324
3391
  ...control,
3325
- ref,
3392
+ ref: mergeRefs(trigger, ref),
3326
3393
  id,
3327
3394
  disabled,
3328
3395
  className: "avl-input-field avl-select-trigger",
@@ -3516,7 +3583,7 @@ function Dial(props) {
3516
3583
  ).flat();
3517
3584
  const radius = isHour && cycle === 24 && h >= 12 ? INNER : OUTER;
3518
3585
  const target = isHour ? h % 12 * 30 : m * 6;
3519
- const angleRef = useRef12(null);
3586
+ const angleRef = useRef13(null);
3520
3587
  const prev = angleRef.current;
3521
3588
  const angle = prev == null ? target : prev + ((target - prev) % 360 + 540) % 360 - 180;
3522
3589
  angleRef.current = angle;
@@ -3666,9 +3733,9 @@ function Dial(props) {
3666
3733
 
3667
3734
  // src/components/DateInput/DateInput.tsx
3668
3735
  import {
3669
- useEffect as useEffect7,
3736
+ useEffect as useEffect10,
3670
3737
  useId as useId3,
3671
- useRef as useRef13,
3738
+ useRef as useRef14,
3672
3739
  useState as useState10
3673
3740
  } from "react";
3674
3741
  import { Input as BaseInput2 } from "@base-ui/react/input";
@@ -3686,6 +3753,7 @@ function DateInput({
3686
3753
  size = "normal",
3687
3754
  disabled,
3688
3755
  id,
3756
+ onChange,
3689
3757
  onBlur,
3690
3758
  className,
3691
3759
  style,
@@ -3697,14 +3765,14 @@ function DateInput({
3697
3765
  const date = fromIso(value);
3698
3766
  const [draft, setDraft] = useState10(null);
3699
3767
  const [open, setOpen] = useState10(false);
3700
- const fieldRef = useRef13(null);
3701
- const popupRef = useRef13(null);
3768
+ const fieldRef = useRef14(null);
3769
+ const popupRef = useRef14(null);
3702
3770
  const generatedId = useId3();
3703
3771
  const inputId = id ?? generatedId;
3704
- const inputRef = useRef13(null);
3705
- const iso = useRef13("");
3772
+ const inputRef = useRef14(null);
3773
+ const iso = useRef14("");
3706
3774
  iso.current = date ? toIso(date) : "";
3707
- useEffect7(() => {
3775
+ useEffect10(() => {
3708
3776
  const form = inputRef.current?.form;
3709
3777
  if (!form) return;
3710
3778
  const onFormData = (event) => {
@@ -3758,6 +3826,7 @@ function DateInput({
3758
3826
  const typed = parseTyped(text, order);
3759
3827
  if (typed) commit(typed);
3760
3828
  }
3829
+ onChange?.(e);
3761
3830
  },
3762
3831
  onBlur: (e) => {
3763
3832
  if (!invalid) setDraft(null);
@@ -4013,11 +4082,13 @@ function Toggle2({
4013
4082
  BaseToggle2,
4014
4083
  {
4015
4084
  ...props,
4016
- className: (state) => cx(
4017
- "avl-toggle",
4018
- icon ? `avl-icon-button avl-icon-button-size-${size}` : `avl-button avl-button-size-${size}`,
4019
- state.pressed ? colorClass(color, "filled") : colorClass("container", fillType),
4020
- typeof className === "function" ? className(state) : className
4085
+ className: withClass(
4086
+ (state) => cx(
4087
+ "avl-toggle",
4088
+ icon ? `avl-icon-button avl-icon-button-size-${size}` : `avl-button avl-button-size-${size}`,
4089
+ state.pressed ? colorClass(color, "filled") : colorClass("container", fillType)
4090
+ ),
4091
+ className
4021
4092
  ),
4022
4093
  children: icon ? /* @__PURE__ */ jsx41(Icon, { name: icon }) : /* @__PURE__ */ jsxs26(Fragment5, { children: [
4023
4094
  startIcon && /* @__PURE__ */ jsx41(Icon, { name: startIcon }),
@@ -4144,11 +4215,21 @@ function SearchItem({
4144
4215
  // src/components/Skeleton/Skeleton.tsx
4145
4216
  import { jsx as jsx43 } from "react/jsx-runtime";
4146
4217
  function Skeleton({
4147
- variant = "text",
4218
+ type = "text",
4148
4219
  animation = "pulse",
4149
4220
  className,
4150
4221
  ...props
4151
4222
  }) {
4223
+ if (process.env.NODE_ENV !== "production") {
4224
+ checkProp(
4225
+ props,
4226
+ "variant",
4227
+ "Skeleton",
4228
+ "The shape is `type`, as on Progress and Typography.",
4229
+ '<Skeleton type="circular" style={{ width: 40, height: 40 }} />\n// type: text | circular | rectangular',
4230
+ "skeleton.md"
4231
+ );
4232
+ }
4152
4233
  return /* @__PURE__ */ jsx43(
4153
4234
  "span",
4154
4235
  {
@@ -4156,7 +4237,7 @@ function Skeleton({
4156
4237
  ...props,
4157
4238
  className: cx(
4158
4239
  "avl-skeleton",
4159
- `avl-skeleton-${variant}`,
4240
+ `avl-skeleton-${type}`,
4160
4241
  animation === "pulse" && "avl-skeleton-pulse",
4161
4242
  className
4162
4243
  )
@@ -4172,19 +4253,31 @@ function Slider({
4172
4253
  "aria-label": ariaLabel,
4173
4254
  showValue = true,
4174
4255
  squiggly = false,
4256
+ getAriaLabel,
4175
4257
  className,
4176
4258
  ...props
4177
4259
  }) {
4178
- if (process.env.NODE_ENV !== "production" && label == null) {
4179
- checkName(
4180
- { "aria-label": ariaLabel, ...props },
4181
- "Slider",
4182
- '<Slider label="Volume" /> // or <Slider aria-label="Volume" />',
4183
- "slider.md"
4184
- );
4185
- }
4186
4260
  const initial = props.value ?? props.defaultValue;
4187
4261
  const thumbCount = Array.isArray(initial) ? initial.length : 1;
4262
+ if (process.env.NODE_ENV !== "production") {
4263
+ if (label == null)
4264
+ checkName(
4265
+ { "aria-label": ariaLabel, ...props },
4266
+ "Slider",
4267
+ '<Slider label="Volume" /> // or <Slider aria-label="Volume" />',
4268
+ "slider.md"
4269
+ );
4270
+ if (thumbCount > 1 && !getAriaLabel)
4271
+ devError(
4272
+ "<Slider> has several handles but no `getAriaLabel`, so screen readers give every handle the same name.",
4273
+ `<Slider
4274
+ label="Price"
4275
+ defaultValue={[20, 80]}
4276
+ getAriaLabel={(i) => (i === 0 ? 'Minimum price' : 'Maximum price')}
4277
+ />`,
4278
+ "slider.md"
4279
+ );
4280
+ }
4188
4281
  const wavy = squiggly && props.orientation !== "vertical";
4189
4282
  const morph2 = useWaveMorph(wavy);
4190
4283
  return /* @__PURE__ */ jsxs28(
@@ -4215,6 +4308,7 @@ function Slider({
4215
4308
  {
4216
4309
  index: i,
4217
4310
  "aria-label": ariaLabel,
4311
+ getAriaLabel,
4218
4312
  className: "avl-slider-thumb",
4219
4313
  render: (thumbProps, state) => /* @__PURE__ */ jsx44(
4220
4314
  "div",
@@ -4257,7 +4351,7 @@ function handleSpan(width, gap, svg) {
4257
4351
  }
4258
4352
 
4259
4353
  // src/components/Snackbar/Snackbar.tsx
4260
- import { useContext as useContext19, useEffect as useEffect8, useRef as useRef14, useState as useState11 } from "react";
4354
+ import { useContext as useContext19, useEffect as useEffect11, useRef as useRef15, useState as useState11 } from "react";
4261
4355
  import { Toast } from "@base-ui/react/toast";
4262
4356
  import { jsx as jsx45, jsxs as jsxs29 } from "react/jsx-runtime";
4263
4357
  function useSnackbar() {
@@ -4284,17 +4378,17 @@ function useSnackbar() {
4284
4378
  }
4285
4379
  function SnackbarViewport() {
4286
4380
  const { toasts } = Toast.useToastManager();
4287
- const viewportRef = useRef14(null);
4381
+ const viewportRef = useRef15(null);
4288
4382
  const [expanded, setExpanded] = useState11(false);
4289
4383
  const [hovered, setHovered] = useState11(false);
4290
4384
  const visibleCount = toasts.filter(
4291
4385
  (toast) => toast.transitionStatus !== "ending"
4292
4386
  ).length;
4293
4387
  const collapsed = visibleCount > 1 && !expanded && !hovered;
4294
- useEffect8(() => {
4388
+ useEffect11(() => {
4295
4389
  if (visibleCount <= 1) setExpanded(false);
4296
4390
  }, [visibleCount]);
4297
- useEffect8(() => {
4391
+ useEffect11(() => {
4298
4392
  if (!expanded) return;
4299
4393
  const viewport = viewportRef.current;
4300
4394
  const close = (event) => {
@@ -4540,6 +4634,15 @@ function FloatingToolbar({
4540
4634
  className,
4541
4635
  ...props
4542
4636
  }) {
4637
+ if (process.env.NODE_ENV !== "production") {
4638
+ checkName(
4639
+ props,
4640
+ "FloatingToolbar",
4641
+ '<FloatingToolbar aria-label="Formatting">...</FloatingToolbar>',
4642
+ "floating-toolbar.md",
4643
+ UNNAMED_GROUP
4644
+ );
4645
+ }
4543
4646
  return /* @__PURE__ */ jsx51(
4544
4647
  BaseToolbar.Root,
4545
4648
  {
@@ -4664,6 +4767,15 @@ import { useRender as useRender2 } from "@base-ui/react/use-render";
4664
4767
  import { mergeProps as mergeProps2 } from "@base-ui/react/merge-props";
4665
4768
  import { Fragment as Fragment6, jsx as jsx53, jsxs as jsxs34 } from "react/jsx-runtime";
4666
4769
  function NavigationBar({ className, ...props }) {
4770
+ if (process.env.NODE_ENV !== "production") {
4771
+ checkName(
4772
+ props,
4773
+ "NavigationBar",
4774
+ '<NavigationBar aria-label="Main">...</NavigationBar>',
4775
+ "navigation-bar.md",
4776
+ UNNAMED_NAV
4777
+ );
4778
+ }
4667
4779
  return /* @__PURE__ */ jsx53("nav", { ...props, className: cx("avl-navigation-bar", className) });
4668
4780
  }
4669
4781
  function NavigationBarItem({
@@ -4709,6 +4821,15 @@ function NavigationRail({
4709
4821
  className,
4710
4822
  ...props
4711
4823
  }) {
4824
+ if (process.env.NODE_ENV !== "production") {
4825
+ checkName(
4826
+ props,
4827
+ "NavigationRail",
4828
+ '<NavigationRail aria-label="Main">...</NavigationRail>',
4829
+ "navigation-rail.md",
4830
+ UNNAMED_NAV
4831
+ );
4832
+ }
4712
4833
  const [internal, setInternal] = useState12(defaultExpanded);
4713
4834
  const expanded = expandedProp ?? internal;
4714
4835
  const setExpanded = (next) => {
@@ -4788,6 +4909,15 @@ import { useRender as useRender4 } from "@base-ui/react/use-render";
4788
4909
  import { mergeProps as mergeProps4 } from "@base-ui/react/merge-props";
4789
4910
  import { jsx as jsx55 } from "react/jsx-runtime";
4790
4911
  function NavigationList({ className, ...props }) {
4912
+ if (process.env.NODE_ENV !== "production") {
4913
+ checkName(
4914
+ props,
4915
+ "NavigationList",
4916
+ '<NavigationList aria-label="Settings">...</NavigationList>',
4917
+ "navigation-list.md",
4918
+ UNNAMED_NAV
4919
+ );
4920
+ }
4791
4921
  return /* @__PURE__ */ jsx55("nav", { ...props, className: cx("avl-navigation-list", className) });
4792
4922
  }
4793
4923
  function NavigationListItem({
@@ -5246,10 +5376,10 @@ var monochromeDarkTheme = {
5246
5376
 
5247
5377
  // src/components/AnvilRoot/AnvilRoot.tsx
5248
5378
  import {
5249
- useEffect as useEffect9,
5379
+ useEffect as useEffect12,
5250
5380
  useId as useId6,
5251
5381
  useLayoutEffect as useLayoutEffect4,
5252
- useRef as useRef15,
5382
+ useRef as useRef16,
5253
5383
  useState as useState13,
5254
5384
  useSyncExternalStore
5255
5385
  } from "react";
@@ -5315,43 +5445,56 @@ function subscribeToOs(onChange) {
5315
5445
  var getOsMode = () => matchMedia(darkQuery).matches ? "dark" : "light";
5316
5446
  var declarations = (vars) => Object.entries(vars).map(([name, value]) => `${name}:${value};`).join("");
5317
5447
  function AnvilRoot(props) {
5448
+ const {
5449
+ children,
5450
+ className,
5451
+ colorMode: colorModeProp,
5452
+ defaultColorMode,
5453
+ onColorModeChange,
5454
+ storageKey,
5455
+ lightTheme: lightThemeProp,
5456
+ darkTheme: darkThemeProp,
5457
+ tokens: tokensProp,
5458
+ ref,
5459
+ ...divProps
5460
+ } = props;
5318
5461
  const [internalSetting, setInternalSetting] = useState13(
5319
- props.defaultColorMode ?? "system"
5462
+ defaultColorMode ?? "system"
5320
5463
  );
5321
- const setting = props.colorMode ?? internalSetting;
5464
+ const setting = colorModeProp ?? internalSetting;
5322
5465
  const osMode = useSyncExternalStore(
5323
5466
  subscribeToOs,
5324
5467
  getOsMode,
5325
5468
  () => "light"
5326
5469
  );
5327
5470
  const colorMode = setting === "system" ? osMode : setting;
5328
- const latestSetting = useRef15(setting);
5471
+ const latestSetting = useRef16(setting);
5329
5472
  latestSetting.current = setting;
5330
5473
  useLayoutEffect4(() => {
5331
- if (!props.storageKey) return;
5332
- const stored = readStored(props.storageKey);
5474
+ if (!storageKey) return;
5475
+ const stored = readStored(storageKey);
5333
5476
  if (stored) {
5334
5477
  latestSetting.current = stored;
5335
5478
  setInternalSetting(stored);
5336
5479
  }
5337
- }, [props.storageKey]);
5480
+ }, [storageKey]);
5338
5481
  const setColorMode = (next) => {
5339
5482
  const value = typeof next === "function" ? next(latestSetting.current) : next;
5340
5483
  latestSetting.current = value;
5341
5484
  setInternalSetting(value);
5342
- props.onColorModeChange?.(value);
5343
- if (props.storageKey) {
5485
+ onColorModeChange?.(value);
5486
+ if (storageKey) {
5344
5487
  try {
5345
- localStorage.setItem(props.storageKey, value);
5488
+ localStorage.setItem(storageKey, value);
5346
5489
  } catch {
5347
5490
  }
5348
5491
  }
5349
5492
  };
5350
- const tokens = { ...baseDesignTokens, ...props.tokens };
5351
- const lightTheme = props.lightTheme || baseLightTheme;
5352
- const darkTheme = props.darkTheme || baseDarkTheme;
5353
- const rootRef = useRef15(null);
5354
- useEffect9(() => {
5493
+ const tokens = { ...baseDesignTokens, ...tokensProp };
5494
+ const lightTheme = lightThemeProp || baseLightTheme;
5495
+ const darkTheme = darkThemeProp || baseDarkTheme;
5496
+ const rootRef = useRef16(null);
5497
+ useEffect12(() => {
5355
5498
  if (process.env.NODE_ENV === "production") return;
5356
5499
  const timer = setTimeout(() => {
5357
5500
  const root2 = rootRef.current;
@@ -5371,7 +5514,7 @@ function AnvilRoot(props) {
5371
5514
  const light = `color-scheme:light;${declarations(themeToCssVariables(lightTheme))}`;
5372
5515
  const dark = `color-scheme:dark;${declarations(themeToCssVariables(darkTheme))}`;
5373
5516
  const css = `${root}{${declarations(tokensToCssVariables(tokens))}${light}}${root}[data-color-mode="dark"]{${dark}}@media ${darkQuery}{${root}[data-color-mode="system"]{${dark}}}`;
5374
- const restoreScript = props.storageKey && props.colorMode === void 0 ? `try{var m=localStorage.getItem(${JSON.stringify(props.storageKey)});if(m==='light'||m==='dark'||m==='system')document.currentScript.parentElement.dataset.colorMode=m}catch(e){}` : void 0;
5517
+ const restoreScript = storageKey && colorModeProp === void 0 ? `try{var m=localStorage.getItem(${JSON.stringify(storageKey)});if(m==='light'||m==='dark'||m==='system')document.currentScript.parentElement.dataset.colorMode=m}catch(e){}` : void 0;
5375
5518
  return /* @__PURE__ */ jsx57(
5376
5519
  AnvilContext,
5377
5520
  {
@@ -5387,8 +5530,9 @@ function AnvilRoot(props) {
5387
5530
  children: /* @__PURE__ */ jsxs37(
5388
5531
  "div",
5389
5532
  {
5390
- ref: rootRef,
5391
- className: cx("avl-root", props.className),
5533
+ ...divProps,
5534
+ ref: mergeRefs(rootRef, ref),
5535
+ className: cx("avl-root", className),
5392
5536
  "data-avl-root": id,
5393
5537
  "data-color-mode": setting,
5394
5538
  suppressHydrationWarning: true,
@@ -5403,7 +5547,7 @@ function AnvilRoot(props) {
5403
5547
  ),
5404
5548
  /* @__PURE__ */ jsx57("style", { children: css }),
5405
5549
  /* @__PURE__ */ jsx57(Tooltip2.Provider, { children: /* @__PURE__ */ jsxs37(Toast2.Provider, { limit: 3, children: [
5406
- props.children,
5550
+ children,
5407
5551
  /* @__PURE__ */ jsx57(SnackbarViewport, {})
5408
5552
  ] }) })
5409
5553
  ]