@videojs/react 0.1.0-preview.6 → 0.1.0-preview.8

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.
@@ -2,9 +2,9 @@ import { a as useMediaStore, i as useMediaSelector } from "./store-hGO5HE2A.js";
2
2
  import { currentTimeDisplayStateDefinition, durationDisplayStateDefinition, fullscreenButtonStateDefinition, muteButtonStateDefinition, playButtonStateDefinition, previewTimeDisplayStateDefinition, timeSliderStateDefinition, volumeSliderStateDefinition } from "@videojs/core/store";
3
3
  import { formatDisplayTime, shallowEqual } from "@videojs/utils";
4
4
  import * as React$1 from "react";
5
- import { Children, cloneElement, createContext, forwardRef, useCallback, useContext, useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
6
- import { jsx, jsxs } from "react/jsx-runtime";
7
- import { FloatingFocusManager, FloatingPortal, arrow, autoUpdate, flip, offset, safePolygon, shift, useClientPoint, useDismiss, useFloating, useFocus, useHover, useInteractions, useRole, useTransitionStatus } from "@floating-ui/react";
5
+ import { Children, cloneElement, createContext, forwardRef, useCallback, useContext, useEffect, useId, useMemo, useRef, useState, useSyncExternalStore } from "react";
6
+ import { Fragment, jsx } from "react/jsx-runtime";
7
+ import { contains, getBoundingClientRectWithoutTransform, getInBoundsAdjustments, safePolygon } from "@videojs/utils/dom";
8
8
  import { TimeSlider, VolumeSlider } from "@videojs/core";
9
9
 
10
10
  //#region src/utils/component-factory.tsx
@@ -237,26 +237,21 @@ function useMediaContainerRef() {
237
237
  * </MediaContainer>
238
238
  * );
239
239
  */
240
- const MediaContainer = forwardRef(({ children, portalId = "@default_portal_id",...props }, ref) => {
240
+ const MediaContainer = forwardRef(({ children,...props }, ref) => {
241
241
  const composedRef = useComposedRefs(ref, useMediaContainerRef());
242
242
  const mediaStore = useMediaStore();
243
243
  const mediaState = useMediaSelector(playButtonStateDefinition.stateTransform, shallowEqual);
244
244
  const methods = useMemo(() => playButtonStateDefinition.createRequestMethods(mediaStore.dispatch), [mediaStore]);
245
- return /* @__PURE__ */ jsxs("div", {
245
+ return /* @__PURE__ */ jsx("div", {
246
246
  ref: composedRef,
247
247
  onClick: useCallback((event) => {
248
248
  if (!["video", "audio"].includes(event.target.localName || "")) return;
249
249
  if (mediaState.paused) methods.requestPlay();
250
250
  else methods.requestPause();
251
251
  }, [mediaState.paused, methods]),
252
+ "data-media-container": true,
252
253
  ...props,
253
- children: [children, /* @__PURE__ */ jsx("div", {
254
- id: portalId,
255
- style: {
256
- position: "absolute",
257
- zIndex: 10
258
- }
259
- })]
254
+ children
260
255
  });
261
256
  });
262
257
 
@@ -348,62 +343,134 @@ function PopoverRoot({ openOnHover = false, delay = 0, closeDelay = 0, children
348
343
  const [open, setOpen] = useState(false);
349
344
  const [placement, setPlacement] = useState("top");
350
345
  const [sideOffset, setSideOffset] = useState(5);
351
- const [openReason, setOpenReason] = useState(null);
352
- const { refs, floatingStyles, context } = useFloating({
353
- open,
354
- onOpenChange: (open$1, _event, reason) => {
355
- setOpen(open$1);
356
- setOpenReason(reason || null);
357
- },
358
- placement,
359
- middleware: [
360
- offset(sideOffset),
361
- flip(),
362
- shift()
363
- ],
364
- whileElementsMounted: autoUpdate
365
- });
366
- const { status: transitionStatus } = useTransitionStatus(context);
367
- const { getReferenceProps, getFloatingProps } = useInteractions([
368
- useHover(context, {
369
- enabled: openOnHover,
370
- mouseOnly: true,
371
- move: false,
372
- delay: {
373
- open: delay,
374
- close: closeDelay
375
- },
376
- handleClose: safePolygon({ blockPointerEvents: true })
377
- }),
378
- useFocus(context),
379
- useDismiss(context),
380
- useRole(context)
381
- ]);
346
+ const [transitionStatus, setTransitionStatus] = useState("initial");
347
+ const popupRef = useRef(null);
348
+ const triggerRef = useRef(null);
349
+ const hoverTimeoutRef = useRef(null);
350
+ const pointerMoveHandlerRef = useRef(null);
351
+ const clearHoverTimeout = useCallback(() => {
352
+ if (hoverTimeoutRef.current) {
353
+ clearTimeout(hoverTimeoutRef.current);
354
+ hoverTimeoutRef.current = null;
355
+ }
356
+ }, []);
357
+ const setOpenState = useCallback((newOpen) => {
358
+ if (open === newOpen) return;
359
+ setOpen(newOpen);
360
+ if (newOpen) {
361
+ setTransitionStatus("initial");
362
+ if (popupRef.current) popupRef.current.showPopover();
363
+ requestAnimationFrame(() => {
364
+ setTransitionStatus("open");
365
+ });
366
+ } else setTransitionStatus("close");
367
+ }, [open]);
368
+ useEffect(() => {
369
+ if (!popupRef.current || open) return;
370
+ const transitions = popupRef.current.getAnimations().filter((anim) => anim instanceof CSSTransition);
371
+ if (transitions.length > 0) Promise.all(transitions.map((t) => t.finished)).then(() => popupRef.current?.hidePopover()).catch(() => popupRef.current?.hidePopover());
372
+ else popupRef.current.hidePopover();
373
+ }, [open, transitionStatus]);
382
374
  const updatePositioning = useCallback((newPlacement, newSideOffset) => {
383
375
  setPlacement(newPlacement);
384
376
  setSideOffset(newSideOffset);
385
377
  }, []);
378
+ useEffect(() => {
379
+ const trigger = triggerRef.current;
380
+ const popup = popupRef.current;
381
+ if (!trigger || !popup) return;
382
+ const abortController = new AbortController();
383
+ const { signal } = abortController;
384
+ const addPointerMoveListener = () => {
385
+ if (!globalThis.matchMedia?.("(hover: hover)")?.matches) return;
386
+ if (!pointerMoveHandlerRef.current) pointerMoveHandlerRef.current = safePolygon({ blockPointerEvents: true })({
387
+ placement,
388
+ elements: {
389
+ domReference: trigger,
390
+ floating: popup
391
+ },
392
+ x: 0,
393
+ y: 0,
394
+ onClose: () => {
395
+ if (pointerMoveHandlerRef.current) document.documentElement.removeEventListener("pointermove", pointerMoveHandlerRef.current);
396
+ clearHoverTimeout();
397
+ hoverTimeoutRef.current = setTimeout(() => {
398
+ setOpenState(false);
399
+ }, closeDelay);
400
+ }
401
+ });
402
+ document.documentElement.addEventListener("pointermove", pointerMoveHandlerRef.current, { signal });
403
+ };
404
+ const handlePointerEnter = (event) => {
405
+ if (!openOnHover) return;
406
+ clearHoverTimeout();
407
+ if (event.currentTarget === popup) addPointerMoveListener();
408
+ if (open) return;
409
+ hoverTimeoutRef.current = setTimeout(() => {
410
+ setOpenState(true);
411
+ }, delay);
412
+ };
413
+ const handlePointerLeave = () => {
414
+ if (!openOnHover) return;
415
+ addPointerMoveListener();
416
+ };
417
+ if (globalThis.matchMedia?.("(hover: hover)")?.matches) {
418
+ trigger.addEventListener("pointerenter", handlePointerEnter, { signal });
419
+ trigger.addEventListener("pointerleave", handlePointerLeave, { signal });
420
+ popup.addEventListener("pointerenter", handlePointerEnter, { signal });
421
+ }
422
+ const handleFocusIn = () => {
423
+ setOpenState(true);
424
+ };
425
+ const handleFocusOut = (event) => {
426
+ const relatedTarget = event.relatedTarget;
427
+ if (relatedTarget && popup && contains(popup, relatedTarget)) return;
428
+ setOpenState(false);
429
+ };
430
+ trigger.addEventListener("focusin", handleFocusIn, { signal });
431
+ trigger.addEventListener("focusout", handleFocusOut, { signal });
432
+ popup.addEventListener("focusout", handleFocusOut, { signal });
433
+ return () => {
434
+ abortController.abort();
435
+ clearHoverTimeout();
436
+ if (pointerMoveHandlerRef.current) document.documentElement.removeEventListener("pointermove", pointerMoveHandlerRef.current);
437
+ pointerMoveHandlerRef.current = null;
438
+ };
439
+ }, [
440
+ openOnHover,
441
+ delay,
442
+ closeDelay,
443
+ open,
444
+ placement,
445
+ setOpenState,
446
+ clearHoverTimeout
447
+ ]);
448
+ useEffect(() => {
449
+ if (!popupRef.current || !triggerRef.current) return;
450
+ const popup = popupRef.current;
451
+ const popupId = popup.id;
452
+ if (popupId) popup.style.setProperty("position-anchor", `--${popupId}`);
453
+ const [side, alignment] = placement.split("-");
454
+ popup.style.setProperty("top", `calc(anchor(${side}) - ${sideOffset}px)`);
455
+ popup.style.setProperty("translate", `0 -100%`);
456
+ popup.style.setProperty("justify-self", alignment === "start" ? "anchor-start" : alignment === "end" ? "anchor-end" : "anchor-center");
457
+ }, [placement, sideOffset]);
386
458
  const value = useMemo(() => ({
387
459
  open,
388
- setOpen,
389
- openReason,
390
- refs,
391
- floatingStyles,
392
- getReferenceProps,
393
- getFloatingProps,
394
- context,
460
+ setOpen: setOpenState,
461
+ popupRef,
462
+ triggerRef,
395
463
  updatePositioning,
396
- transitionStatus
464
+ transitionStatus,
465
+ placement,
466
+ sideOffset
397
467
  }), [
398
468
  open,
399
- openReason,
400
- refs,
401
- floatingStyles,
402
- getReferenceProps,
403
- getFloatingProps,
404
- context,
469
+ setOpenState,
405
470
  updatePositioning,
406
- transitionStatus
471
+ transitionStatus,
472
+ placement,
473
+ sideOffset
407
474
  ]);
408
475
  return /* @__PURE__ */ jsx(PopoverContext.Provider, {
409
476
  value,
@@ -411,15 +478,14 @@ function PopoverRoot({ openOnHover = false, delay = 0, closeDelay = 0, children
411
478
  });
412
479
  }
413
480
  function PopoverTrigger({ children }) {
414
- const { refs, getReferenceProps, open } = usePopoverContext();
481
+ const { triggerRef, open } = usePopoverContext();
415
482
  return cloneElement(Children.only(children), {
416
- ref: refs.setReference,
417
- ...getReferenceProps(),
483
+ ref: triggerRef,
418
484
  "data-popup-open": open ? "" : void 0
419
485
  });
420
486
  }
421
487
  function PopoverPositioner({ side = "top", sideOffset = 5, children }) {
422
- const { refs, floatingStyles, updatePositioning } = usePopoverContext();
488
+ const { updatePositioning } = usePopoverContext();
423
489
  useEffect(() => {
424
490
  updatePositioning(side, sideOffset);
425
491
  }, [
@@ -427,39 +493,38 @@ function PopoverPositioner({ side = "top", sideOffset = 5, children }) {
427
493
  sideOffset,
428
494
  updatePositioning
429
495
  ]);
430
- return /* @__PURE__ */ jsx("div", {
431
- ref: refs.setFloating,
432
- style: floatingStyles,
433
- children
434
- });
435
- }
436
- function PopoverPopup({ className, children }) {
437
- const { getFloatingProps, context, transitionStatus } = usePopoverContext();
438
- const { refs, placement } = context;
439
- const triggerElement = refs.reference.current;
440
- const dataAttributes = triggerElement?.attributes ? Object.fromEntries(Array.from(triggerElement.attributes).filter((attr) => attr.name.startsWith("data-")).map((attr) => [attr.name, attr.value])) : {};
441
- return /* @__PURE__ */ jsx(FloatingFocusManager, {
442
- context,
443
- modal: false,
444
- initialFocus: -1,
445
- returnFocus: false,
446
- children: /* @__PURE__ */ jsx("div", {
447
- className,
448
- ...getFloatingProps(),
449
- ...dataAttributes,
450
- "data-side": placement,
451
- "data-starting-style": transitionStatus === "initial" ? "" : void 0,
452
- "data-open": transitionStatus === "initial" || transitionStatus === "open" ? "" : void 0,
453
- "data-ending-style": transitionStatus === "close" || transitionStatus === "unmounted" ? "" : void 0,
454
- "data-closed": transitionStatus === "close" || transitionStatus === "unmounted" ? "" : void 0,
455
- children
456
- })
457
- });
496
+ return /* @__PURE__ */ jsx(Fragment, { children });
458
497
  }
459
- function PopoverPortal({ children, root, rootId = "@default_portal_id" }) {
460
- return /* @__PURE__ */ jsx(FloatingPortal, {
461
- root,
462
- id: rootId,
498
+ function PopoverPopup({ id, className, children }) {
499
+ const { popupRef, triggerRef, transitionStatus, placement } = usePopoverContext();
500
+ const triggerElement = triggerRef.current;
501
+ const uniqueId = useId();
502
+ const popupId = id ?? uniqueId;
503
+ useEffect(() => {
504
+ if (!popupRef.current || !triggerRef.current) return;
505
+ const popup = popupRef.current;
506
+ const trigger = triggerRef.current;
507
+ popup.setAttribute("popover", "manual");
508
+ trigger.setAttribute("commandfor", popupId);
509
+ trigger.style.setProperty("anchor-name", `--${popupId}`);
510
+ }, [
511
+ popupId,
512
+ popupRef,
513
+ triggerRef
514
+ ]);
515
+ return /* @__PURE__ */ jsx("div", {
516
+ ref: popupRef,
517
+ id: popupId,
518
+ className,
519
+ ...useMemo(() => {
520
+ if (!triggerElement?.attributes) return {};
521
+ return Object.fromEntries(Array.from(triggerElement.attributes).filter((attr) => attr.name.startsWith("data-")).map((attr) => [attr.name, attr.value]));
522
+ }, [triggerElement]),
523
+ "data-side": placement,
524
+ "data-starting-style": transitionStatus === "initial" ? "" : void 0,
525
+ "data-open": transitionStatus === "initial" || transitionStatus === "open" ? "" : void 0,
526
+ "data-ending-style": transitionStatus === "close" || transitionStatus === "unmounted" ? "" : void 0,
527
+ "data-closed": transitionStatus === "close" || transitionStatus === "unmounted" ? "" : void 0,
463
528
  children
464
529
  });
465
530
  }
@@ -467,8 +532,7 @@ const Popover = {
467
532
  Root: PopoverRoot,
468
533
  Trigger: PopoverTrigger,
469
534
  Positioner: PopoverPositioner,
470
- Popup: PopoverPopup,
471
- Portal: PopoverPortal
535
+ Popup: PopoverPopup
472
536
  };
473
537
  var Popover_default = Popover;
474
538
 
@@ -621,79 +685,177 @@ const TimeSlider$1 = Object.assign({}, {
621
685
  //#endregion
622
686
  //#region src/components/Tooltip.tsx
623
687
  const TooltipContext = createContext(null);
624
- const TooltipPositionerContext = createContext(null);
625
688
  function useTooltipContext() {
626
689
  const context = useContext(TooltipContext);
627
690
  if (!context) throw new Error("Tooltip components must be used within TooltipRoot");
628
691
  return context;
629
692
  }
630
- function useTooltipPositionerContext() {
631
- const context = useContext(TooltipPositionerContext);
632
- if (!context) throw new Error("TooltipArrow must be used within TooltipPositioner");
633
- return context;
634
- }
635
693
  function TooltipRoot({ delay = 0, closeDelay = 0, trackCursorAxis, children }) {
636
694
  const [open, setOpen] = useState(false);
637
695
  const [placement, setPlacement] = useState("top");
638
696
  const [sideOffset, setSideOffset] = useState(0);
639
697
  const [collisionPadding, setCollisionPadding] = useState(0);
640
- const arrowRef = useRef(null);
641
- const { context } = useFloating({
642
- open,
643
- onOpenChange: setOpen,
644
- placement,
645
- middleware: [
646
- offset(sideOffset),
647
- flip(),
648
- shift({ padding: collisionPadding }),
649
- arrow({ element: arrowRef })
650
- ],
651
- whileElementsMounted: autoUpdate
652
- });
653
- const { status: transitionStatus } = useTransitionStatus(context);
654
- const hover = useHover(context, { delay: {
655
- open: delay,
656
- close: closeDelay
657
- } });
658
- const focus = useFocus(context);
659
- const dismiss = useDismiss(context);
660
- const role = useRole(context, { role: "tooltip" });
661
- const clientPoint = useClientPoint(context, {
662
- axis: trackCursorAxis || "both",
663
- enabled: !!trackCursorAxis
698
+ const [transitionStatus, setTransitionStatus] = useState("initial");
699
+ const popupRef = useRef(null);
700
+ const triggerRef = useRef(null);
701
+ const hoverTimeoutRef = useRef(null);
702
+ const pointerPositionRef = useRef({
703
+ x: 0,
704
+ y: 0
664
705
  });
665
- const { getReferenceProps, getFloatingProps } = useInteractions(trackCursorAxis ? [
666
- hover,
667
- focus,
668
- dismiss,
669
- role,
670
- clientPoint
671
- ] : [
672
- hover,
673
- focus,
674
- dismiss,
675
- role
676
- ]);
677
706
  const updatePositioning = useCallback(({ side, sideOffset: sideOffset$1, collisionPadding: collisionPadding$1 }) => {
678
707
  setPlacement(side);
679
708
  setSideOffset(sideOffset$1);
680
709
  setCollisionPadding(collisionPadding$1);
681
710
  }, []);
711
+ const clearHoverTimeout = useCallback(() => {
712
+ if (hoverTimeoutRef.current) {
713
+ clearTimeout(hoverTimeoutRef.current);
714
+ hoverTimeoutRef.current = null;
715
+ }
716
+ }, []);
717
+ const checkCollision = useCallback(() => {
718
+ if (!popupRef.current || !triggerRef.current || !open) return;
719
+ const mediaContainer = popupRef.current.closest("[data-media-container]");
720
+ if (!mediaContainer) return;
721
+ const { x } = getInBoundsAdjustments(getBoundingClientRectWithoutTransform(popupRef.current), getBoundingClientRectWithoutTransform(mediaContainer), collisionPadding);
722
+ if (x !== 0) if (trackCursorAxis) {
723
+ const currentLeft = Number.parseFloat(popupRef.current.style.left || "0");
724
+ popupRef.current.style.setProperty("left", `${currentLeft + x}px`);
725
+ } else popupRef.current.style.setProperty("translate", `${x}px -100%`);
726
+ else if (trackCursorAxis) popupRef.current.style.setProperty("translate", "-50% -100%");
727
+ else popupRef.current.style.setProperty("translate", "0 -100%");
728
+ }, [
729
+ open,
730
+ collisionPadding,
731
+ trackCursorAxis
732
+ ]);
733
+ const updatePosition = useCallback(() => {
734
+ if (open && trackCursorAxis && popupRef.current) {
735
+ popupRef.current.style.setProperty("left", `${pointerPositionRef.current.x}px`);
736
+ checkCollision();
737
+ }
738
+ }, [
739
+ open,
740
+ trackCursorAxis,
741
+ checkCollision
742
+ ]);
743
+ const setOpenState = useCallback((newOpen) => {
744
+ if (open === newOpen) return;
745
+ setOpen(newOpen);
746
+ if (newOpen) {
747
+ setTransitionStatus("initial");
748
+ if (popupRef.current) popupRef.current.showPopover();
749
+ requestAnimationFrame(() => {
750
+ setTransitionStatus("open");
751
+ checkCollision();
752
+ });
753
+ } else setTransitionStatus("close");
754
+ }, [open, checkCollision]);
755
+ useEffect(() => {
756
+ if (!popupRef.current || open) return;
757
+ const transitions = popupRef.current.getAnimations().filter((anim) => anim instanceof CSSTransition);
758
+ if (transitions.length > 0) Promise.all(transitions.map((t) => t.finished)).then(() => popupRef.current?.hidePopover()).catch(() => popupRef.current?.hidePopover());
759
+ else popupRef.current.hidePopover();
760
+ }, [open, transitionStatus]);
761
+ useEffect(() => {
762
+ const trigger = triggerRef.current;
763
+ const popup = popupRef.current;
764
+ if (!trigger || !popup) return;
765
+ const abortController = new AbortController();
766
+ const { signal } = abortController;
767
+ const handlePointerEnter = () => {
768
+ clearHoverTimeout();
769
+ hoverTimeoutRef.current = setTimeout(() => {
770
+ setOpenState(true);
771
+ }, delay);
772
+ };
773
+ const handlePointerLeave = () => {
774
+ clearHoverTimeout();
775
+ hoverTimeoutRef.current = setTimeout(() => {
776
+ setOpenState(false);
777
+ }, closeDelay);
778
+ };
779
+ const handlePointerMove = (event) => {
780
+ if (trackCursorAxis) {
781
+ pointerPositionRef.current = {
782
+ x: event.clientX,
783
+ y: event.clientY
784
+ };
785
+ if (open) updatePosition();
786
+ }
787
+ };
788
+ const handleFocusIn = () => {
789
+ setOpenState(true);
790
+ };
791
+ const handleFocusOut = (event) => {
792
+ const relatedTarget = event.relatedTarget;
793
+ if (relatedTarget && popup && contains(popup, relatedTarget)) return;
794
+ setOpenState(false);
795
+ };
796
+ if (globalThis.matchMedia?.("(hover: hover)")?.matches) {
797
+ trigger.addEventListener("pointerenter", handlePointerEnter, { signal });
798
+ trigger.addEventListener("pointerleave", handlePointerLeave, { signal });
799
+ if (trackCursorAxis) trigger.addEventListener("pointermove", handlePointerMove, { signal });
800
+ }
801
+ trigger.addEventListener("focusin", handleFocusIn, { signal });
802
+ trigger.addEventListener("focusout", handleFocusOut, { signal });
803
+ return () => {
804
+ abortController.abort();
805
+ clearHoverTimeout();
806
+ };
807
+ }, [
808
+ delay,
809
+ closeDelay,
810
+ trackCursorAxis,
811
+ open,
812
+ setOpenState,
813
+ clearHoverTimeout,
814
+ updatePosition
815
+ ]);
816
+ useEffect(() => {
817
+ if (!popupRef.current || !triggerRef.current) return;
818
+ const popup = popupRef.current;
819
+ const popupId = popup.id;
820
+ if (popupId) popup.style.setProperty("position-anchor", `--${popupId}`);
821
+ const [side, alignment] = placement.split("-");
822
+ popup.style.setProperty("top", `calc(anchor(${side}) - ${sideOffset}px)`);
823
+ if (trackCursorAxis) popup.style.setProperty("translate", `-50% -100%`);
824
+ else {
825
+ popup.style.setProperty("translate", `0 -100%`);
826
+ popup.style.setProperty("justify-self", alignment === "start" ? "anchor-start" : alignment === "end" ? "anchor-end" : "anchor-center");
827
+ }
828
+ }, [
829
+ placement,
830
+ sideOffset,
831
+ trackCursorAxis
832
+ ]);
833
+ useEffect(() => {
834
+ if (!popupRef.current) return;
835
+ const resizeObserver = new ResizeObserver(checkCollision);
836
+ resizeObserver.observe(popupRef.current);
837
+ return () => {
838
+ resizeObserver.disconnect();
839
+ };
840
+ }, [checkCollision]);
682
841
  const value = useMemo(() => ({
683
- getReferenceProps,
684
- getFloatingProps,
685
- context,
686
- updatePositioning,
687
- arrowRef,
842
+ popupRef,
843
+ triggerRef,
844
+ open,
688
845
  transitionStatus,
689
- trackCursorAxis
690
- }), [
691
- getReferenceProps,
692
- getFloatingProps,
693
- context,
694
846
  updatePositioning,
847
+ trackCursorAxis,
848
+ placement,
849
+ sideOffset,
850
+ collisionPadding
851
+ }), [
852
+ open,
695
853
  transitionStatus,
696
- trackCursorAxis
854
+ updatePositioning,
855
+ trackCursorAxis,
856
+ placement,
857
+ sideOffset,
858
+ collisionPadding
697
859
  ]);
698
860
  return /* @__PURE__ */ jsx(TooltipContext.Provider, {
699
861
  value,
@@ -701,17 +863,14 @@ function TooltipRoot({ delay = 0, closeDelay = 0, trackCursorAxis, children }) {
701
863
  });
702
864
  }
703
865
  function TooltipTrigger({ children }) {
704
- const { context, getReferenceProps } = useTooltipContext();
705
- const { refs, open } = context;
866
+ const { triggerRef, open } = useTooltipContext();
706
867
  return cloneElement(Children.only(children), {
707
- ref: refs.setReference,
708
- ...getReferenceProps(),
868
+ ref: triggerRef,
709
869
  "data-popup-open": open ? "" : void 0
710
870
  });
711
871
  }
712
872
  function TooltipPositioner({ side = "top", sideOffset = 0, collisionPadding = 0, children }) {
713
- const { context, updatePositioning, trackCursorAxis } = useTooltipContext();
714
- const { refs, floatingStyles } = context;
873
+ const { updatePositioning } = useTooltipContext();
715
874
  useEffect(() => {
716
875
  updatePositioning({
717
876
  side,
@@ -724,28 +883,34 @@ function TooltipPositioner({ side = "top", sideOffset = 0, collisionPadding = 0,
724
883
  collisionPadding,
725
884
  updatePositioning
726
885
  ]);
727
- const positionerContextValue = useMemo(() => ({ side }), [side]);
728
- return /* @__PURE__ */ jsx(TooltipPositionerContext.Provider, {
729
- value: positionerContextValue,
730
- children: /* @__PURE__ */ jsx("div", {
731
- ref: refs.setFloating,
732
- style: {
733
- ...floatingStyles,
734
- pointerEvents: trackCursorAxis ? "none" : void 0
735
- },
736
- children
737
- })
738
- });
886
+ return /* @__PURE__ */ jsx(Fragment, { children });
739
887
  }
740
- function TooltipPopup({ className = "", children }) {
741
- const { context, getFloatingProps, transitionStatus } = useTooltipContext();
742
- const { refs, placement } = context;
743
- const triggerElement = refs.reference.current;
744
- const dataAttributes = triggerElement?.attributes ? Object.fromEntries(Array.from(triggerElement.attributes).filter((attr) => attr.name.startsWith("data-")).map((attr) => [attr.name, attr.value])) : {};
888
+ function TooltipPopup({ id, className = "", children }) {
889
+ const { popupRef, triggerRef, transitionStatus, placement } = useTooltipContext();
890
+ const triggerElement = triggerRef.current;
891
+ const uniqueId = useId();
892
+ const popupId = id ?? uniqueId;
893
+ useEffect(() => {
894
+ if (!popupRef.current || !triggerRef.current) return;
895
+ const popup = popupRef.current;
896
+ const trigger = triggerRef.current;
897
+ popup.setAttribute("popover", "manual");
898
+ trigger.setAttribute("commandfor", popupId);
899
+ trigger.style.setProperty("anchor-name", `--${popupId}`);
900
+ }, [
901
+ popupId,
902
+ popupRef,
903
+ triggerRef
904
+ ]);
745
905
  return /* @__PURE__ */ jsx("div", {
906
+ ref: popupRef,
907
+ id: popupId,
746
908
  className,
747
- ...getFloatingProps(),
748
- ...dataAttributes,
909
+ role: "tooltip",
910
+ ...useMemo(() => {
911
+ if (!triggerElement?.attributes) return {};
912
+ return Object.fromEntries(Array.from(triggerElement.attributes).filter((attr) => attr.name.startsWith("data-")).map((attr) => [attr.name, attr.value]));
913
+ }, [triggerElement]),
749
914
  "data-side": placement,
750
915
  "data-starting-style": transitionStatus === "initial" ? "" : void 0,
751
916
  "data-open": transitionStatus === "initial" || transitionStatus === "open" ? "" : void 0,
@@ -754,39 +919,11 @@ function TooltipPopup({ className = "", children }) {
754
919
  children
755
920
  });
756
921
  }
757
- function TooltipArrow({ className = "", children }) {
758
- const { arrowRef, context } = useTooltipContext();
759
- const { side } = useTooltipPositionerContext();
760
- const { x: arrowX, y: arrowY } = context.middlewareData.arrow || {
761
- x: 0,
762
- y: 0
763
- };
764
- return /* @__PURE__ */ jsx("div", {
765
- ref: arrowRef,
766
- className,
767
- "aria-hidden": "true",
768
- "data-side": side,
769
- style: {
770
- left: arrowX != null ? `${arrowX}px` : void 0,
771
- top: arrowY != null ? `${arrowY}px` : void 0
772
- },
773
- children
774
- });
775
- }
776
- function TooltipPortal({ children, root, rootId = "@default_portal_id" }) {
777
- return /* @__PURE__ */ jsx(FloatingPortal, {
778
- root,
779
- id: rootId,
780
- children
781
- });
782
- }
783
922
  const Tooltip = {
784
923
  Root: TooltipRoot,
785
924
  Trigger: TooltipTrigger,
786
925
  Positioner: TooltipPositioner,
787
- Popup: TooltipPopup,
788
- Arrow: TooltipArrow,
789
- Portal: TooltipPortal
926
+ Popup: TooltipPopup
790
927
  };
791
928
  var Tooltip_default = Tooltip;
792
929
 
@@ -902,4 +1039,4 @@ var VolumeSlider_default = VolumeSlider$1;
902
1039
 
903
1040
  //#endregion
904
1041
  export { DurationDisplay as _, TimeSlider$1 as a, Popover as c, PlayButton_default as d, MuteButton as f, FullscreenButton as g, useMediaContainerRef as h, Tooltip_default as i, Popover_default as l, MediaContainer as m, VolumeSlider_default as n, PreviewTimeDisplay as o, MuteButton_default as p, Tooltip as r, PreviewTimeDisplay_default as s, VolumeSlider$1 as t, PlayButton as u, CurrentTimeDisplay as v };
905
- //# sourceMappingURL=VolumeSlider-CWpLFzdJ.js.map
1042
+ //# sourceMappingURL=VolumeSlider-DmlupkvF.js.map