@videojs/react 0.1.0-preview.5 → 0.1.0-preview.7

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/README.md CHANGED
@@ -24,5 +24,5 @@ members:
24
24
 
25
25
  [package]: https://www.npmjs.com/package/@videojs/react
26
26
  [package-badge]: https://img.shields.io/npm/v/@videojs/react/next?label=@videojs/react@next
27
- [discord]: https://discord.gg/zdrCwByt
27
+ [discord]: https://discord.gg/JBqHh485uF
28
28
  [gh-discussions]: https://github.com/videojs/v10/discussions
@@ -1,10 +1,10 @@
1
- import { a as useMediaStore, i as useMediaSelector } from "./store-DpQF8Ges.js";
1
+ 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
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";
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,37 @@ 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 popupId = useMemo(() => id ?? `popover-${Math.random().toString(36).substring(2, 9)}`, [id]);
502
+ useEffect(() => {
503
+ if (!popupRef.current || !triggerRef.current) return;
504
+ const popup = popupRef.current;
505
+ const trigger = triggerRef.current;
506
+ popup.setAttribute("popover", "manual");
507
+ trigger.setAttribute("commandfor", popupId);
508
+ trigger.style.setProperty("anchor-name", `--${popupId}`);
509
+ }, [
510
+ popupId,
511
+ popupRef,
512
+ triggerRef
513
+ ]);
514
+ return /* @__PURE__ */ jsx("div", {
515
+ ref: popupRef,
516
+ id: popupId,
517
+ className,
518
+ ...useMemo(() => {
519
+ if (!triggerElement?.attributes) return {};
520
+ return Object.fromEntries(Array.from(triggerElement.attributes).filter((attr) => attr.name.startsWith("data-")).map((attr) => [attr.name, attr.value]));
521
+ }, [triggerElement]),
522
+ "data-side": placement,
523
+ "data-starting-style": transitionStatus === "initial" ? "" : void 0,
524
+ "data-open": transitionStatus === "initial" || transitionStatus === "open" ? "" : void 0,
525
+ "data-ending-style": transitionStatus === "close" || transitionStatus === "unmounted" ? "" : void 0,
526
+ "data-closed": transitionStatus === "close" || transitionStatus === "unmounted" ? "" : void 0,
463
527
  children
464
528
  });
465
529
  }
@@ -467,8 +531,7 @@ const Popover = {
467
531
  Root: PopoverRoot,
468
532
  Trigger: PopoverTrigger,
469
533
  Positioner: PopoverPositioner,
470
- Popup: PopoverPopup,
471
- Portal: PopoverPortal
534
+ Popup: PopoverPopup
472
535
  };
473
536
  var Popover_default = Popover;
474
537
 
@@ -621,79 +684,177 @@ const TimeSlider$1 = Object.assign({}, {
621
684
  //#endregion
622
685
  //#region src/components/Tooltip.tsx
623
686
  const TooltipContext = createContext(null);
624
- const TooltipPositionerContext = createContext(null);
625
687
  function useTooltipContext() {
626
688
  const context = useContext(TooltipContext);
627
689
  if (!context) throw new Error("Tooltip components must be used within TooltipRoot");
628
690
  return context;
629
691
  }
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
692
  function TooltipRoot({ delay = 0, closeDelay = 0, trackCursorAxis, children }) {
636
693
  const [open, setOpen] = useState(false);
637
694
  const [placement, setPlacement] = useState("top");
638
695
  const [sideOffset, setSideOffset] = useState(0);
639
696
  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
697
+ const [transitionStatus, setTransitionStatus] = useState("initial");
698
+ const popupRef = useRef(null);
699
+ const triggerRef = useRef(null);
700
+ const hoverTimeoutRef = useRef(null);
701
+ const pointerPositionRef = useRef({
702
+ x: 0,
703
+ y: 0
664
704
  });
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
705
  const updatePositioning = useCallback(({ side, sideOffset: sideOffset$1, collisionPadding: collisionPadding$1 }) => {
678
706
  setPlacement(side);
679
707
  setSideOffset(sideOffset$1);
680
708
  setCollisionPadding(collisionPadding$1);
681
709
  }, []);
710
+ const clearHoverTimeout = useCallback(() => {
711
+ if (hoverTimeoutRef.current) {
712
+ clearTimeout(hoverTimeoutRef.current);
713
+ hoverTimeoutRef.current = null;
714
+ }
715
+ }, []);
716
+ const checkCollision = useCallback(() => {
717
+ if (!popupRef.current || !triggerRef.current || !open) return;
718
+ const mediaContainer = popupRef.current.closest("[data-media-container]");
719
+ if (!mediaContainer) return;
720
+ const { x } = getInBoundsAdjustments(getBoundingClientRectWithoutTransform(popupRef.current), getBoundingClientRectWithoutTransform(mediaContainer), collisionPadding);
721
+ if (x !== 0) if (trackCursorAxis) {
722
+ const currentLeft = Number.parseFloat(popupRef.current.style.left || "0");
723
+ popupRef.current.style.setProperty("left", `${currentLeft + x}px`);
724
+ } else popupRef.current.style.setProperty("translate", `${x}px -100%`);
725
+ else if (trackCursorAxis) popupRef.current.style.setProperty("translate", "-50% -100%");
726
+ else popupRef.current.style.setProperty("translate", "0 -100%");
727
+ }, [
728
+ open,
729
+ collisionPadding,
730
+ trackCursorAxis
731
+ ]);
732
+ const updatePosition = useCallback(() => {
733
+ if (open && trackCursorAxis && popupRef.current) {
734
+ popupRef.current.style.setProperty("left", `${pointerPositionRef.current.x}px`);
735
+ checkCollision();
736
+ }
737
+ }, [
738
+ open,
739
+ trackCursorAxis,
740
+ checkCollision
741
+ ]);
742
+ const setOpenState = useCallback((newOpen) => {
743
+ if (open === newOpen) return;
744
+ setOpen(newOpen);
745
+ if (newOpen) {
746
+ setTransitionStatus("initial");
747
+ if (popupRef.current) popupRef.current.showPopover();
748
+ requestAnimationFrame(() => {
749
+ setTransitionStatus("open");
750
+ checkCollision();
751
+ });
752
+ } else setTransitionStatus("close");
753
+ }, [open, checkCollision]);
754
+ useEffect(() => {
755
+ if (!popupRef.current || open) return;
756
+ const transitions = popupRef.current.getAnimations().filter((anim) => anim instanceof CSSTransition);
757
+ if (transitions.length > 0) Promise.all(transitions.map((t) => t.finished)).then(() => popupRef.current?.hidePopover()).catch(() => popupRef.current?.hidePopover());
758
+ else popupRef.current.hidePopover();
759
+ }, [open, transitionStatus]);
760
+ useEffect(() => {
761
+ const trigger = triggerRef.current;
762
+ const popup = popupRef.current;
763
+ if (!trigger || !popup) return;
764
+ const abortController = new AbortController();
765
+ const { signal } = abortController;
766
+ const handlePointerEnter = () => {
767
+ clearHoverTimeout();
768
+ hoverTimeoutRef.current = setTimeout(() => {
769
+ setOpenState(true);
770
+ }, delay);
771
+ };
772
+ const handlePointerLeave = () => {
773
+ clearHoverTimeout();
774
+ hoverTimeoutRef.current = setTimeout(() => {
775
+ setOpenState(false);
776
+ }, closeDelay);
777
+ };
778
+ const handlePointerMove = (event) => {
779
+ if (trackCursorAxis) {
780
+ pointerPositionRef.current = {
781
+ x: event.clientX,
782
+ y: event.clientY
783
+ };
784
+ if (open) updatePosition();
785
+ }
786
+ };
787
+ const handleFocusIn = () => {
788
+ setOpenState(true);
789
+ };
790
+ const handleFocusOut = (event) => {
791
+ const relatedTarget = event.relatedTarget;
792
+ if (relatedTarget && popup && contains(popup, relatedTarget)) return;
793
+ setOpenState(false);
794
+ };
795
+ if (globalThis.matchMedia?.("(hover: hover)")?.matches) {
796
+ trigger.addEventListener("pointerenter", handlePointerEnter, { signal });
797
+ trigger.addEventListener("pointerleave", handlePointerLeave, { signal });
798
+ if (trackCursorAxis) trigger.addEventListener("pointermove", handlePointerMove, { signal });
799
+ }
800
+ trigger.addEventListener("focusin", handleFocusIn, { signal });
801
+ trigger.addEventListener("focusout", handleFocusOut, { signal });
802
+ return () => {
803
+ abortController.abort();
804
+ clearHoverTimeout();
805
+ };
806
+ }, [
807
+ delay,
808
+ closeDelay,
809
+ trackCursorAxis,
810
+ open,
811
+ setOpenState,
812
+ clearHoverTimeout,
813
+ updatePosition
814
+ ]);
815
+ useEffect(() => {
816
+ if (!popupRef.current || !triggerRef.current) return;
817
+ const popup = popupRef.current;
818
+ const popupId = popup.id;
819
+ if (popupId) popup.style.setProperty("position-anchor", `--${popupId}`);
820
+ const [side, alignment] = placement.split("-");
821
+ popup.style.setProperty("top", `calc(anchor(${side}) - ${sideOffset}px)`);
822
+ if (trackCursorAxis) popup.style.setProperty("translate", `-50% -100%`);
823
+ else {
824
+ popup.style.setProperty("translate", `0 -100%`);
825
+ popup.style.setProperty("justify-self", alignment === "start" ? "anchor-start" : alignment === "end" ? "anchor-end" : "anchor-center");
826
+ }
827
+ }, [
828
+ placement,
829
+ sideOffset,
830
+ trackCursorAxis
831
+ ]);
832
+ useEffect(() => {
833
+ if (!popupRef.current) return;
834
+ const resizeObserver = new ResizeObserver(checkCollision);
835
+ resizeObserver.observe(popupRef.current);
836
+ return () => {
837
+ resizeObserver.disconnect();
838
+ };
839
+ }, [checkCollision]);
682
840
  const value = useMemo(() => ({
683
- getReferenceProps,
684
- getFloatingProps,
685
- context,
686
- updatePositioning,
687
- arrowRef,
841
+ popupRef,
842
+ triggerRef,
843
+ open,
688
844
  transitionStatus,
689
- trackCursorAxis
690
- }), [
691
- getReferenceProps,
692
- getFloatingProps,
693
- context,
694
845
  updatePositioning,
846
+ trackCursorAxis,
847
+ placement,
848
+ sideOffset,
849
+ collisionPadding
850
+ }), [
851
+ open,
695
852
  transitionStatus,
696
- trackCursorAxis
853
+ updatePositioning,
854
+ trackCursorAxis,
855
+ placement,
856
+ sideOffset,
857
+ collisionPadding
697
858
  ]);
698
859
  return /* @__PURE__ */ jsx(TooltipContext.Provider, {
699
860
  value,
@@ -701,17 +862,14 @@ function TooltipRoot({ delay = 0, closeDelay = 0, trackCursorAxis, children }) {
701
862
  });
702
863
  }
703
864
  function TooltipTrigger({ children }) {
704
- const { context, getReferenceProps } = useTooltipContext();
705
- const { refs, open } = context;
865
+ const { triggerRef, open } = useTooltipContext();
706
866
  return cloneElement(Children.only(children), {
707
- ref: refs.setReference,
708
- ...getReferenceProps(),
867
+ ref: triggerRef,
709
868
  "data-popup-open": open ? "" : void 0
710
869
  });
711
870
  }
712
871
  function TooltipPositioner({ side = "top", sideOffset = 0, collisionPadding = 0, children }) {
713
- const { context, updatePositioning, trackCursorAxis } = useTooltipContext();
714
- const { refs, floatingStyles } = context;
872
+ const { updatePositioning } = useTooltipContext();
715
873
  useEffect(() => {
716
874
  updatePositioning({
717
875
  side,
@@ -724,28 +882,33 @@ function TooltipPositioner({ side = "top", sideOffset = 0, collisionPadding = 0,
724
882
  collisionPadding,
725
883
  updatePositioning
726
884
  ]);
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
- });
885
+ return /* @__PURE__ */ jsx(Fragment, { children });
739
886
  }
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])) : {};
887
+ function TooltipPopup({ id, className = "", children }) {
888
+ const { popupRef, triggerRef, transitionStatus, placement } = useTooltipContext();
889
+ const triggerElement = triggerRef.current;
890
+ const popupId = useMemo(() => id ?? `tooltip-${Math.random().toString(36).substring(2, 9)}`, [id]);
891
+ useEffect(() => {
892
+ if (!popupRef.current || !triggerRef.current) return;
893
+ const popup = popupRef.current;
894
+ const trigger = triggerRef.current;
895
+ popup.setAttribute("popover", "manual");
896
+ trigger.setAttribute("commandfor", popupId);
897
+ trigger.style.setProperty("anchor-name", `--${popupId}`);
898
+ }, [
899
+ popupId,
900
+ popupRef,
901
+ triggerRef
902
+ ]);
745
903
  return /* @__PURE__ */ jsx("div", {
904
+ ref: popupRef,
905
+ id: popupId,
746
906
  className,
747
- ...getFloatingProps(),
748
- ...dataAttributes,
907
+ role: "tooltip",
908
+ ...useMemo(() => {
909
+ if (!triggerElement?.attributes) return {};
910
+ return Object.fromEntries(Array.from(triggerElement.attributes).filter((attr) => attr.name.startsWith("data-")).map((attr) => [attr.name, attr.value]));
911
+ }, [triggerElement]),
749
912
  "data-side": placement,
750
913
  "data-starting-style": transitionStatus === "initial" ? "" : void 0,
751
914
  "data-open": transitionStatus === "initial" || transitionStatus === "open" ? "" : void 0,
@@ -754,39 +917,11 @@ function TooltipPopup({ className = "", children }) {
754
917
  children
755
918
  });
756
919
  }
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
920
  const Tooltip = {
784
921
  Root: TooltipRoot,
785
922
  Trigger: TooltipTrigger,
786
923
  Positioner: TooltipPositioner,
787
- Popup: TooltipPopup,
788
- Arrow: TooltipArrow,
789
- Portal: TooltipPortal
924
+ Popup: TooltipPopup
790
925
  };
791
926
  var Tooltip_default = Tooltip;
792
927
 
@@ -902,4 +1037,4 @@ var VolumeSlider_default = VolumeSlider$1;
902
1037
 
903
1038
  //#endregion
904
1039
  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-DoR6idnJ.js.map
1040
+ //# sourceMappingURL=VolumeSlider-B8x0_k2f.js.map