@appica/ui-react 1.3.0 → 1.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.
Files changed (78) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/agent-rules.md +3 -0
  3. package/appica.css +1 -1
  4. package/dist/components/autocomplete/autocomplete.d.ts.map +1 -1
  5. package/dist/components/autocomplete/autocomplete.js +1 -5
  6. package/dist/components/autocomplete/autocomplete.js.map +1 -1
  7. package/dist/components/breadcrumb/breadcrumb.js +1 -1
  8. package/dist/components/breadcrumb/breadcrumb.js.map +1 -1
  9. package/dist/components/carousel/carousel.d.ts +25 -4
  10. package/dist/components/carousel/carousel.d.ts.map +1 -1
  11. package/dist/components/carousel/carousel.js +277 -48
  12. package/dist/components/carousel/carousel.js.map +1 -1
  13. package/dist/components/combobox/combobox.d.ts.map +1 -1
  14. package/dist/components/combobox/combobox.js +1 -5
  15. package/dist/components/combobox/combobox.js.map +1 -1
  16. package/dist/components/copy-button/copy-button.d.ts +2 -2
  17. package/dist/components/copy-button/copy-button.d.ts.map +1 -1
  18. package/dist/components/copy-button/copy-button.js +49 -46
  19. package/dist/components/copy-button/copy-button.js.map +1 -1
  20. package/dist/components/date-field/date-field.d.ts.map +1 -1
  21. package/dist/components/date-field/date-field.js +7 -0
  22. package/dist/components/date-field/date-field.js.map +1 -1
  23. package/dist/components/date-picker/date-picker.d.ts +10 -0
  24. package/dist/components/date-picker/date-picker.d.ts.map +1 -1
  25. package/dist/components/date-picker/date-picker.js +14 -0
  26. package/dist/components/date-picker/date-picker.js.map +1 -1
  27. package/dist/components/field/field.d.ts.map +1 -1
  28. package/dist/components/field/field.js +1 -0
  29. package/dist/components/field/field.js.map +1 -1
  30. package/dist/components/loader/loader.d.ts +1 -1
  31. package/dist/components/loader/loader.d.ts.map +1 -1
  32. package/dist/components/loader/loader.js +7 -5
  33. package/dist/components/loader/loader.js.map +1 -1
  34. package/dist/components/number-field/number-field.d.ts +1 -1
  35. package/dist/components/number-field/number-field.d.ts.map +1 -1
  36. package/dist/components/number-field/number-field.js +7 -0
  37. package/dist/components/number-field/number-field.js.map +1 -1
  38. package/dist/components/pagination/pagination.d.ts.map +1 -1
  39. package/dist/components/pagination/pagination.js +1 -2
  40. package/dist/components/pagination/pagination.js.map +1 -1
  41. package/dist/components/spinner/spinner.d.ts +1 -1
  42. package/dist/components/spinner/spinner.d.ts.map +1 -1
  43. package/dist/components/spinner/spinner.js +7 -5
  44. package/dist/components/spinner/spinner.js.map +1 -1
  45. package/dist/components/time-field/time-field.d.ts.map +1 -1
  46. package/dist/components/time-field/time-field.js +7 -0
  47. package/dist/components/time-field/time-field.js.map +1 -1
  48. package/dist/index.js +1 -1
  49. package/package.json +11 -11
  50. package/src/components/autocomplete/autocomplete.test.tsx +33 -0
  51. package/src/components/autocomplete/autocomplete.tsx +1 -5
  52. package/src/components/breadcrumb/breadcrumb.test.tsx +57 -2
  53. package/src/components/breadcrumb/breadcrumb.tsx +1 -1
  54. package/src/components/carousel/carousel.test.tsx +918 -13
  55. package/src/components/carousel/carousel.tsx +338 -54
  56. package/src/components/chip/chip.test.tsx +4 -5
  57. package/src/components/combobox/combobox.test.tsx +33 -0
  58. package/src/components/combobox/combobox.tsx +1 -5
  59. package/src/components/context-menu/context-menu.test.tsx +2 -1
  60. package/src/components/copy-button/copy-button.test.tsx +68 -3
  61. package/src/components/copy-button/copy-button.tsx +49 -43
  62. package/src/components/date-field/date-field.test.tsx +82 -0
  63. package/src/components/date-field/date-field.tsx +7 -0
  64. package/src/components/date-picker/date-picker.test.tsx +70 -0
  65. package/src/components/date-picker/date-picker.tsx +26 -0
  66. package/src/components/dropdown-menu/dropdown-menu.test.tsx +2 -1
  67. package/src/components/field/field.test.tsx +34 -0
  68. package/src/components/field/field.tsx +1 -0
  69. package/src/components/loader/loader.test.tsx +17 -4
  70. package/src/components/loader/loader.tsx +2 -2
  71. package/src/components/number-field/number-field.test.tsx +59 -0
  72. package/src/components/number-field/number-field.tsx +8 -0
  73. package/src/components/pagination/pagination.test.tsx +83 -0
  74. package/src/components/pagination/pagination.tsx +1 -2
  75. package/src/components/spinner/spinner.test.tsx +17 -4
  76. package/src/components/spinner/spinner.tsx +2 -2
  77. package/src/components/time-field/time-field.test.tsx +64 -0
  78. package/src/components/time-field/time-field.tsx +7 -0
@@ -12,11 +12,12 @@ import AutoHeight from 'embla-carousel-auto-height';
12
12
  import ClassNames from 'embla-carousel-class-names';
13
13
  import Fade from 'embla-carousel-fade';
14
14
  import { WheelGesturesPlugin } from 'embla-carousel-wheel-gestures';
15
- import { cn } from '../../internal/utils.js';
15
+ import { cn, useComposedRefs } from '../../internal/utils.js';
16
16
  import { useReducedMotion } from '../../hooks/use-reduced-motion.js';
17
17
  import { useDirection } from '@base-ui/react/direction-provider';
18
18
 
19
19
  const CarouselContext = React.createContext(null);
20
+ const CarouselRotationContext = React.createContext(false);
20
21
  function useCarousel() {
21
22
  const ctx = React.useContext(CarouselContext);
22
23
  if (!ctx) {
@@ -24,6 +25,71 @@ function useCarousel() {
24
25
  }
25
26
  return ctx;
26
27
  }
28
+ const CAROUSEL_ACCESSIBILITY_VIEWPORT = {
29
+ carouselRole: "",
30
+ carouselAriaLabel: "",
31
+ carouselAriaRoleDescription: ""
32
+ };
33
+ function hasKeyboardFocus(node) {
34
+ return node instanceof Element && node.matches(":focus-visible");
35
+ }
36
+ function getShownSlides(api) {
37
+ const { options, scrollSnapList } = api.internalEngine();
38
+ if (!options.active) return new Set(api.slideNodes().keys());
39
+ const inView = api.plugins().fade ? [] : api.slidesInView();
40
+ return new Set(inView.length ? inView : scrollSnapList.slidesBySnap[api.selectedSnap()] ?? []);
41
+ }
42
+ function useSlideVisibility(api, enabled) {
43
+ React.useEffect(() => {
44
+ if (!api || !enabled) return;
45
+ const inert = /* @__PURE__ */ new Set();
46
+ const labels = /* @__PURE__ */ new Map();
47
+ const release = (node) => {
48
+ if (inert.delete(node)) node.removeAttribute("inert");
49
+ if (labels.has(node) && node.getAttribute("aria-label") === labels.get(node)) node.removeAttribute("aria-label");
50
+ labels.delete(node);
51
+ };
52
+ const sync = (focused) => {
53
+ const slides = api.slideNodes();
54
+ const shown = getShownSlides(api);
55
+ (/* @__PURE__ */ new Set([...inert, ...labels.keys()])).forEach((node) => {
56
+ if (!slides.includes(node)) release(node);
57
+ });
58
+ slides.forEach((node, index) => {
59
+ const hidden = !shown.has(index) && !(focused instanceof Node && node.contains(focused));
60
+ if (hidden && !inert.has(node)) {
61
+ node.setAttribute("inert", "");
62
+ inert.add(node);
63
+ } else if (!hidden && inert.delete(node)) {
64
+ node.removeAttribute("inert");
65
+ }
66
+ const ownLabel = node.getAttribute("aria-label");
67
+ if (node.hasAttribute("aria-labelledby") || ownLabel !== null && ownLabel !== labels.get(node)) {
68
+ labels.delete(node);
69
+ return;
70
+ }
71
+ const label = `${index + 1} of ${slides.length}`;
72
+ if (ownLabel !== label) node.setAttribute("aria-label", label);
73
+ labels.set(node, label);
74
+ });
75
+ };
76
+ const onChange = () => sync(document.activeElement);
77
+ const onFocusOut = (event) => sync(event.relatedTarget);
78
+ const viewport = api.rootNode();
79
+ onChange();
80
+ api.on("select", onChange);
81
+ api.on("reinit", onChange);
82
+ api.on("slidesinview", onChange);
83
+ viewport?.addEventListener("focusout", onFocusOut);
84
+ return () => {
85
+ api.off("select", onChange);
86
+ api.off("reinit", onChange);
87
+ api.off("slidesinview", onChange);
88
+ viewport?.removeEventListener("focusout", onFocusOut);
89
+ (/* @__PURE__ */ new Set([...inert, ...labels.keys()])).forEach(release);
90
+ };
91
+ }, [api, enabled]);
92
+ }
27
93
  function Carousel({
28
94
  orientation = "horizontal",
29
95
  loop = false,
@@ -65,17 +131,19 @@ function Carousel({
65
131
  }
66
132
  }, [autoplayEnabled, autoScrollEnabled]);
67
133
  const resumeAfterMs = typeof autoplay === "object" && typeof autoplay.resumeAfter === "number" && autoplay.resumeAfter || typeof autoScroll === "object" && typeof autoScroll.resumeAfter === "number" && autoScroll.resumeAfter || 0;
134
+ const pauseOnHover = typeof autoplay !== "object" || autoplay.pauseOnHover !== false;
135
+ const pauseOnFocus = typeof autoplay !== "object" || autoplay.pauseOnFocus !== false;
68
136
  const plugins = React.useMemo(() => {
69
137
  const list = [];
70
- if (accessibility !== false) {
71
- list.push(Accessibility(typeof accessibility === "object" ? accessibility : void 0));
138
+ if (typeof accessibility === "object") {
139
+ list.push(Accessibility({ ...CAROUSEL_ACCESSIBILITY_VIEWPORT, ...accessibility }));
72
140
  }
73
141
  if (wheelGestures !== false) {
74
142
  list.push(WheelGesturesPlugin(typeof wheelGestures === "object" ? wheelGestures : void 0));
75
143
  }
76
144
  if (autoplay) {
77
145
  const opts = typeof autoplay === "object" ? autoplay : void 0;
78
- const { resumeAfter, ...emblaOpts } = opts ?? {};
146
+ const { resumeAfter, pauseOnHover: _pauseOnHover, pauseOnFocus: _pauseOnFocus, ...emblaOpts } = opts ?? {};
79
147
  const autoResume = typeof resumeAfter === "number" && resumeAfter > 0;
80
148
  list.push(Autoplay(autoResume ? { ...emblaOpts, defaultInteraction: false } : emblaOpts));
81
149
  } else if (autoScroll && !reducedMotion) {
@@ -128,6 +196,10 @@ function Carousel({
128
196
  reducedMotion
129
197
  ]);
130
198
  const [viewportRef, emblaApi] = useEmblaCarousel(emblaOptions, plugins);
199
+ useSlideVisibility(emblaApi, accessibility === true);
200
+ const { ref: forwardedRef, ...rootProps } = rest;
201
+ const rootRef = React.useRef(null);
202
+ const composedRootRef = useComposedRefs(rootRef, forwardedRef);
131
203
  const setApiRef = React.useRef(setApi);
132
204
  const onReInitRef = React.useRef(onReInit);
133
205
  const onSelectRef = React.useRef(onSelect);
@@ -163,6 +235,21 @@ function Carousel({
163
235
  canScrollNext: false
164
236
  });
165
237
  const [autoplayState, setAutoplayState] = React.useState(null);
238
+ const [paused, setPausedState] = React.useState(false);
239
+ const pausedRef = React.useRef(false);
240
+ const setPaused = React.useCallback((next) => {
241
+ pausedRef.current = next;
242
+ setPausedState(next);
243
+ }, []);
244
+ const rotationRef = React.useRef(null);
245
+ const pause = React.useCallback(() => {
246
+ setPaused(true);
247
+ rotationRef.current?.pause();
248
+ }, [setPaused]);
249
+ const play = React.useCallback(() => {
250
+ setPaused(false);
251
+ rotationRef.current?.play();
252
+ }, [setPaused]);
166
253
  const scrollProgressRef = React.useRef(0);
167
254
  const scrollListenersRef = React.useRef(/* @__PURE__ */ new Set());
168
255
  const subscribeScrollProgress = React.useCallback((onChange) => {
@@ -198,8 +285,6 @@ function Carousel({
198
285
  const syncScroll = () => {
199
286
  notifyScroll();
200
287
  };
201
- const syncInView = () => {
202
- };
203
288
  syncFull();
204
289
  setApiRef.current?.(emblaApi);
205
290
  onReInitRef.current?.(emblaApi);
@@ -222,7 +307,6 @@ function Carousel({
222
307
  emblaApi.on("reinit", handleReInit);
223
308
  emblaApi.on("select", handleSelect);
224
309
  emblaApi.on("scroll", handleScroll);
225
- emblaApi.on("slidesinview", syncInView);
226
310
  emblaApi.on("slideschanged", syncFull);
227
311
  const autoplayPlugin = emblaApi.plugins().autoplay;
228
312
  const autoScrollPlugin = emblaApi.plugins().autoScroll;
@@ -234,14 +318,36 @@ function Carousel({
234
318
  resumeTimer = void 0;
235
319
  }
236
320
  };
237
- const scheduleResume = (play) => {
238
- if (resumeAfter <= 0) return;
321
+ const scheduleResume = (restart) => {
239
322
  clearResumeTimer();
240
323
  resumeTimer = setTimeout(() => {
241
324
  resumeTimer = void 0;
242
- play();
325
+ restart();
243
326
  }, resumeAfter);
244
327
  };
328
+ const root = rootRef.current;
329
+ let hovered = false;
330
+ let focused = false;
331
+ let held = false;
332
+ const playAutoplay = () => {
333
+ if (pausedRef.current) return;
334
+ if (hovered || focused) held = true;
335
+ else emblaApi.plugins().autoplay?.play();
336
+ };
337
+ const interruptAutoplay = () => {
338
+ held = false;
339
+ emblaApi.plugins().autoplay?.stop();
340
+ if (resumeAfter > 0) scheduleResume(playAutoplay);
341
+ else setPaused(true);
342
+ };
343
+ const playAutoScroll = () => {
344
+ if (!pausedRef.current) emblaApi.plugins().autoScroll?.play();
345
+ };
346
+ const interruptAutoScroll = () => {
347
+ emblaApi.plugins().autoScroll?.stop();
348
+ if (resumeAfter > 0) scheduleResume(playAutoScroll);
349
+ else setPaused(true);
350
+ };
245
351
  let cleanupAutoplay;
246
352
  if (autoplayPlugin) {
247
353
  const rawDelay = autoplayPlugin.options.delay;
@@ -252,50 +358,138 @@ function Carousel({
252
358
  isPlaying: autoplayPlugin.isPlaying()
253
359
  });
254
360
  const onPlay = () => {
361
+ held = false;
255
362
  clearResumeTimer();
363
+ if (pausedRef.current) setPaused(false);
256
364
  setAutoplayState((s) => s ? { ...s, isPlaying: true } : s);
257
365
  };
258
366
  const onStop = () => setAutoplayState((s) => s ? { ...s, isPlaying: false } : s);
259
367
  const onTimerSet = () => setAutoplayState((s) => s ? { ...s, cycleId: s.cycleId + 1, isPlaying: true } : s);
260
368
  const onTimerStopped = () => setAutoplayState((s) => s ? { ...s, isPlaying: false } : s);
261
369
  const resetOnSelect = () => autoplayPlugin.reset();
370
+ const stopsOnPress = autoplayPlugin.options.defaultInteraction !== false;
371
+ const onUserStop = () => {
372
+ held = false;
373
+ if (stopsOnPress && !reducedMotion) setPaused(true);
374
+ };
262
375
  const onInteraction = (_api, event) => {
263
376
  if (event.detail.interaction === "pointerdown" || event.detail.interaction === "slidefocus") {
264
- autoplayPlugin.stop();
265
- scheduleResume(() => emblaApi.plugins().autoplay?.play());
377
+ interruptAutoplay();
266
378
  }
267
379
  };
380
+ const hold = () => {
381
+ if (!emblaApi.plugins().autoplay?.isPlaying()) return;
382
+ held = true;
383
+ emblaApi.plugins().autoplay?.stop();
384
+ };
385
+ const release = () => {
386
+ if (held) playAutoplay();
387
+ };
388
+ const onPointerEnter = () => {
389
+ hovered = true;
390
+ hold();
391
+ };
392
+ const onPointerLeave = () => {
393
+ hovered = false;
394
+ release();
395
+ };
396
+ const onFocusIn = (event) => {
397
+ focused = hasKeyboardFocus(event.target);
398
+ if (focused) hold();
399
+ else release();
400
+ };
401
+ const onFocusOut = (event) => {
402
+ if (event.relatedTarget instanceof Node && root?.contains(event.relatedTarget)) return;
403
+ focused = false;
404
+ release();
405
+ };
268
406
  emblaApi.on("autoplay:play", onPlay);
269
407
  emblaApi.on("autoplay:stop", onStop);
270
408
  emblaApi.on("autoplay:timerset", onTimerSet);
271
409
  emblaApi.on("autoplay:timerstopped", onTimerStopped);
272
410
  emblaApi.on("select", resetOnSelect);
411
+ emblaApi.on("pointerdown", onUserStop);
412
+ emblaApi.on("slidefocus", onUserStop);
273
413
  if (resumeAfter > 0) emblaApi.on("autoplay:interaction", onInteraction);
274
- if (autoplayEnabled) autoplayPlugin.play();
414
+ if (pauseOnHover) {
415
+ root?.addEventListener("pointerenter", onPointerEnter);
416
+ root?.addEventListener("pointerleave", onPointerLeave);
417
+ }
418
+ if (pauseOnFocus) {
419
+ root?.addEventListener("focusin", onFocusIn);
420
+ root?.addEventListener("focusout", onFocusOut);
421
+ }
422
+ if (autoplayEnabled && !reducedMotion) {
423
+ hovered = pauseOnHover && !!root?.matches(":hover");
424
+ focused = pauseOnFocus && !!root?.contains(document.activeElement) && hasKeyboardFocus(document.activeElement);
425
+ playAutoplay();
426
+ } else {
427
+ autoplayPlugin.stop();
428
+ }
429
+ rotationRef.current = {
430
+ pause: () => {
431
+ held = false;
432
+ clearResumeTimer();
433
+ emblaApi.plugins().autoplay?.stop();
434
+ },
435
+ play: () => {
436
+ held = false;
437
+ clearResumeTimer();
438
+ if (!reducedMotion) emblaApi.plugins().autoplay?.play();
439
+ }
440
+ };
275
441
  cleanupAutoplay = () => {
276
442
  emblaApi.off("autoplay:play", onPlay);
277
443
  emblaApi.off("autoplay:stop", onStop);
278
444
  emblaApi.off("autoplay:timerset", onTimerSet);
279
445
  emblaApi.off("autoplay:timerstopped", onTimerStopped);
280
446
  emblaApi.off("select", resetOnSelect);
447
+ emblaApi.off("pointerdown", onUserStop);
448
+ emblaApi.off("slidefocus", onUserStop);
281
449
  if (resumeAfter > 0) emblaApi.off("autoplay:interaction", onInteraction);
450
+ root?.removeEventListener("pointerenter", onPointerEnter);
451
+ root?.removeEventListener("pointerleave", onPointerLeave);
452
+ root?.removeEventListener("focusin", onFocusIn);
453
+ root?.removeEventListener("focusout", onFocusOut);
282
454
  };
283
455
  } else {
284
456
  setAutoplayState(null);
285
457
  }
286
458
  let cleanupAutoScroll;
287
459
  if (autoScrollPlugin && autoScrollEnabled && !autoplayEnabled) {
288
- autoScrollPlugin.play();
460
+ playAutoScroll();
461
+ const onPlay = () => {
462
+ if (pausedRef.current) setPaused(false);
463
+ };
464
+ const stopsOnPress = autoScrollPlugin.options.defaultInteraction !== false;
465
+ const onUserStop = () => {
466
+ if (stopsOnPress) setPaused(true);
467
+ };
289
468
  const onInteraction = (_api, event) => {
290
469
  if (event.detail.interaction === "pointerdown" || event.detail.interaction === "slidefocus") {
291
- autoScrollPlugin.stop();
292
- scheduleResume(() => emblaApi.plugins().autoScroll?.play());
470
+ interruptAutoScroll();
293
471
  }
294
472
  };
295
- if (resumeAfter > 0) {
296
- emblaApi.on("autoscroll:interaction", onInteraction);
297
- cleanupAutoScroll = () => emblaApi.off("autoscroll:interaction", onInteraction);
298
- }
473
+ emblaApi.on("autoscroll:play", onPlay);
474
+ emblaApi.on("pointerdown", onUserStop);
475
+ emblaApi.on("slidefocus", onUserStop);
476
+ if (resumeAfter > 0) emblaApi.on("autoscroll:interaction", onInteraction);
477
+ rotationRef.current = {
478
+ pause: () => {
479
+ clearResumeTimer();
480
+ emblaApi.plugins().autoScroll?.stop();
481
+ },
482
+ play: () => {
483
+ clearResumeTimer();
484
+ emblaApi.plugins().autoScroll?.play();
485
+ }
486
+ };
487
+ cleanupAutoScroll = () => {
488
+ emblaApi.off("autoscroll:play", onPlay);
489
+ emblaApi.off("pointerdown", onUserStop);
490
+ emblaApi.off("slidefocus", onUserStop);
491
+ if (resumeAfter > 0) emblaApi.off("autoscroll:interaction", onInteraction);
492
+ };
299
493
  }
300
494
  let cleanupWheel;
301
495
  if (emblaApi.plugins().wheelGestures && (autoplayPlugin || autoScrollPlugin)) {
@@ -305,12 +499,10 @@ function Carousel({
305
499
  const along = Math.abs(vertical ? event.deltaY : event.deltaX);
306
500
  const across = Math.abs(vertical ? event.deltaX : event.deltaY);
307
501
  if (along <= across) return;
308
- if (autoplayPlugin?.isPlaying()) {
309
- autoplayPlugin.stop();
310
- scheduleResume(() => emblaApi.plugins().autoplay?.play());
502
+ if (autoplayPlugin?.isPlaying() || held) {
503
+ interruptAutoplay();
311
504
  } else if (autoScrollPlugin?.isPlaying()) {
312
- autoScrollPlugin.stop();
313
- scheduleResume(() => emblaApi.plugins().autoScroll?.play());
505
+ interruptAutoScroll();
314
506
  }
315
507
  };
316
508
  viewport.addEventListener("wheel", onWheel, { passive: true });
@@ -320,14 +512,23 @@ function Carousel({
320
512
  emblaApi.off("reinit", handleReInit);
321
513
  emblaApi.off("select", handleSelect);
322
514
  emblaApi.off("scroll", handleScroll);
323
- emblaApi.off("slidesinview", syncInView);
324
515
  emblaApi.off("slideschanged", syncFull);
325
516
  cleanupAutoplay?.();
326
517
  cleanupAutoScroll?.();
327
518
  cleanupWheel?.();
328
519
  clearResumeTimer();
520
+ rotationRef.current = null;
329
521
  };
330
- }, [emblaApi, autoplayEnabled, autoScrollEnabled, resumeAfterMs]);
522
+ }, [
523
+ emblaApi,
524
+ autoplayEnabled,
525
+ autoScrollEnabled,
526
+ resumeAfterMs,
527
+ reducedMotion,
528
+ pauseOnHover,
529
+ pauseOnFocus,
530
+ setPaused
531
+ ]);
331
532
  const scrollPrev = React.useCallback(() => emblaApi?.goToPrev(), [emblaApi]);
332
533
  const scrollNext = React.useCallback(() => emblaApi?.goToNext(), [emblaApi]);
333
534
  const scrollTo = React.useCallback((i) => emblaApi?.goTo(i), [emblaApi]);
@@ -349,6 +550,9 @@ function Carousel({
349
550
  subscribeScrollProgress,
350
551
  getScrollProgress,
351
552
  autoplay: autoplayState,
553
+ paused,
554
+ pause,
555
+ play,
352
556
  scrollPrev,
353
557
  scrollNext,
354
558
  scrollTo
@@ -366,24 +570,27 @@ function Carousel({
366
570
  subscribeScrollProgress,
367
571
  getScrollProgress,
368
572
  autoplayState,
573
+ paused,
574
+ pause,
575
+ play,
369
576
  scrollPrev,
370
577
  scrollNext,
371
578
  scrollTo
372
579
  ]
373
580
  );
374
- return /* @__PURE__ */ jsx(CarouselContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(
581
+ return /* @__PURE__ */ jsx(CarouselContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(CarouselRotationContext.Provider, { value: autoplayEnabled || autoScrollEnabled, children: /* @__PURE__ */ jsx(
375
582
  "div",
376
583
  {
377
584
  "data-slot": "carousel",
378
585
  "data-orientation": orientation,
379
- role: "region",
586
+ role: rootProps["aria-label"] || rootProps["aria-labelledby"] ? "region" : "group",
380
587
  "aria-roledescription": "carousel",
381
- "aria-label": "Carousel",
382
588
  className: cn("relative", className),
383
- ...rest,
589
+ ...rootProps,
590
+ ref: composedRootRef,
384
591
  children
385
592
  }
386
- ) });
593
+ ) }) });
387
594
  }
388
595
  function CarouselContent({ className, children, viewportProps, ...rest }) {
389
596
  const { viewportRef, orientation, autoHeight } = useCarousel();
@@ -507,6 +714,7 @@ function CarouselThumbs({
507
714
  align: "start",
508
715
  containScroll: "keepSnaps",
509
716
  options: CAROUSEL_THUMB_OPTIONS,
717
+ accessibility: false,
510
718
  setApi,
511
719
  light,
512
720
  role: "group",
@@ -637,9 +845,9 @@ function CarouselPrev({ className, position = "inside", disabled: disabledProp,
637
845
  type: "button",
638
846
  "data-slot": "carousel-prev",
639
847
  "data-disabled": disabled || void 0,
848
+ "aria-disabled": disabled || void 0,
640
849
  "aria-label": "Previous slide",
641
- disabled,
642
- onClick: scrollPrev,
850
+ onClick: disabled ? void 0 : scrollPrev,
643
851
  suppressHydrationWarning: true
644
852
  },
645
853
  props
@@ -669,9 +877,9 @@ function CarouselNext({ className, position = "inside", disabled: disabledProp,
669
877
  type: "button",
670
878
  "data-slot": "carousel-next",
671
879
  "data-disabled": disabled || void 0,
880
+ "aria-disabled": disabled || void 0,
672
881
  "aria-label": "Next slide",
673
- disabled,
674
- onClick: scrollNext,
882
+ onClick: disabled ? void 0 : scrollNext,
675
883
  suppressHydrationWarning: true
676
884
  },
677
885
  props
@@ -688,6 +896,29 @@ function CarouselNext({ className, position = "inside", disabled: disabledProp,
688
896
  }
689
897
  );
690
898
  }
899
+ function CarouselPlayToggle({ className, render, ...props }) {
900
+ const { reducedMotion, paused, pause, play } = useCarousel();
901
+ const rotates = React.useContext(CarouselRotationContext);
902
+ const state = { paused };
903
+ const trigger = useRender({
904
+ defaultTagName: "button",
905
+ render,
906
+ state,
907
+ props: mergeProps(
908
+ {
909
+ type: "button",
910
+ "data-slot": "carousel-play-toggle",
911
+ "data-paused": paused || void 0,
912
+ "aria-pressed": paused,
913
+ "aria-label": "Pause slides",
914
+ onClick: paused ? play : pause
915
+ },
916
+ props
917
+ )
918
+ });
919
+ if (!rotates || reducedMotion) return null;
920
+ return /* @__PURE__ */ jsx("div", { "data-slot": "carousel-play-toggle-positioner", className: cn("motion-reduce:hidden", className), children: trigger });
921
+ }
691
922
  function CarouselPagination({
692
923
  className,
693
924
  orientation = "horizontal",
@@ -751,6 +982,10 @@ function CarouselPagination({
751
982
  }
752
983
  );
753
984
  }
985
+ const AUTOPLAY_INDICATOR_TRAVEL = {
986
+ horizontal: { start: "-translate-x-full rtl:translate-x-full", end: "translate-x-0" },
987
+ vertical: { start: "-translate-y-full", end: "translate-y-0" }
988
+ };
754
989
  function CarouselAutoplayIndicator({ delay, isPlaying, light, orientation }) {
755
990
  const [armed, setArmed] = React.useState(false);
756
991
  React.useEffect(() => {
@@ -763,8 +998,7 @@ function CarouselAutoplayIndicator({ delay, isPlaying, light, orientation }) {
763
998
  cancelAnimationFrame(raf2);
764
999
  };
765
1000
  }, []);
766
- const isHorizontal = orientation === "horizontal";
767
- const fillValue = armed && isPlaying ? "100%" : "0%";
1001
+ const travel = AUTOPLAY_INDICATOR_TRAVEL[orientation];
768
1002
  return /* @__PURE__ */ jsx(
769
1003
  "span",
770
1004
  {
@@ -773,17 +1007,12 @@ function CarouselAutoplayIndicator({ delay, isPlaying, light, orientation }) {
773
1007
  "data-orientation": orientation,
774
1008
  "data-playing": isPlaying || void 0,
775
1009
  className: cn(
776
- "absolute rounded-full",
777
- isHorizontal ? "inset-y-0 inset-s-0" : "inset-x-0 top-0",
778
- isHorizontal ? "motion-safe:transition-[width]" : "motion-safe:transition-[height]",
779
- "motion-safe:ease-linear",
1010
+ "absolute inset-0 rounded-full",
1011
+ "motion-safe:transition-[translate] motion-safe:ease-linear",
1012
+ armed && isPlaying ? travel.end : travel.start,
780
1013
  light ? "bg-white" : "bg-primary"
781
1014
  ),
782
- style: {
783
- transitionDuration: `${delay}ms`,
784
- width: isHorizontal ? fillValue : void 0,
785
- height: isHorizontal ? void 0 : fillValue
786
- }
1015
+ style: { transitionDuration: `${delay}ms` }
787
1016
  }
788
1017
  );
789
1018
  }
@@ -967,5 +1196,5 @@ function useLinkedCarousels(mainApi, thumbsApi) {
967
1196
  }, [mainApi, thumbsApi]);
968
1197
  }
969
1198
 
970
- export { Carousel, CarouselContent, CarouselNext, CarouselPagination, CarouselPrev, CarouselProgress, CarouselSlide, CarouselThumb, CarouselThumbs, useCarousel, useLinkedCarousels };
1199
+ export { Carousel, CarouselContent, CarouselNext, CarouselPagination, CarouselPlayToggle, CarouselPrev, CarouselProgress, CarouselSlide, CarouselThumb, CarouselThumbs, useCarousel, useLinkedCarousels };
971
1200
  //# sourceMappingURL=carousel.js.map