@it-compiles/anima 0.1.0 → 0.1.2
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/core/define-animation.d.ts +1 -1
- package/dist/index.js +4 -1969
- package/dist/index.js.map +1 -1
- package/dist/react/RenderDialog.d.ts +10 -0
- package/dist/react/TimelineControls.d.ts +12 -0
- package/dist/react/index.d.ts +4 -0
- package/dist/react.js +2590 -7
- package/dist/react.js.map +1 -1
- package/dist/video-renderer-Buv1c43x.js +3424 -0
- package/dist/video-renderer-Buv1c43x.js.map +1 -0
- package/dist/vite/plugin.d.ts +1 -1
- package/dist/vite.js.map +1 -1
- package/package.json +11 -3
- package/dist/player-MRRNy8I9.js +0 -1458
- package/dist/player-MRRNy8I9.js.map +0 -1
package/dist/react.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
1
|
+
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { forwardRef, useRef, useState, useImperativeHandle, useEffect, useCallback, createElement } from "react";
|
|
4
|
+
import { m as makePlayer, c as createVideoRenderer, e as downloadBlob, d as isWebCodecsSupported } from "./video-renderer-Buv1c43x.js";
|
|
5
|
+
import * as ReactDOM from "react-dom";
|
|
6
|
+
import ReactDOM__default from "react-dom";
|
|
4
7
|
const DEFAULT_WIDTH = 1280;
|
|
5
8
|
const DEFAULT_HEIGHT = 720;
|
|
6
|
-
function formatTime(ms) {
|
|
9
|
+
function formatTime$1(ms) {
|
|
7
10
|
const seconds = ms / 1e3;
|
|
8
11
|
return seconds.toFixed(2) + "s";
|
|
9
12
|
}
|
|
@@ -384,9 +387,9 @@ const AnimaPlayer = forwardRef(
|
|
|
384
387
|
textAlign: "right"
|
|
385
388
|
},
|
|
386
389
|
children: [
|
|
387
|
-
formatTime(currentTime),
|
|
390
|
+
formatTime$1(currentTime),
|
|
388
391
|
" / ",
|
|
389
|
-
formatTime(duration)
|
|
392
|
+
formatTime$1(duration)
|
|
390
393
|
]
|
|
391
394
|
}
|
|
392
395
|
)
|
|
@@ -419,7 +422,2587 @@ const AnimaPlayer = forwardRef(
|
|
|
419
422
|
);
|
|
420
423
|
}
|
|
421
424
|
);
|
|
425
|
+
const toKebabCase = (string) => string.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
426
|
+
const toCamelCase = (string) => string.replace(
|
|
427
|
+
/^([A-Z])|[\s-_]+(\w)/g,
|
|
428
|
+
(match, p1, p2) => p2 ? p2.toUpperCase() : p1.toLowerCase()
|
|
429
|
+
);
|
|
430
|
+
const toPascalCase = (string) => {
|
|
431
|
+
const camelCase = toCamelCase(string);
|
|
432
|
+
return camelCase.charAt(0).toUpperCase() + camelCase.slice(1);
|
|
433
|
+
};
|
|
434
|
+
const mergeClasses = (...classes) => classes.filter((className, index, array) => {
|
|
435
|
+
return Boolean(className) && className.trim() !== "" && array.indexOf(className) === index;
|
|
436
|
+
}).join(" ").trim();
|
|
437
|
+
const hasA11yProp = (props) => {
|
|
438
|
+
for (const prop in props) {
|
|
439
|
+
if (prop.startsWith("aria-") || prop === "role" || prop === "title") {
|
|
440
|
+
return true;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
};
|
|
444
|
+
var defaultAttributes = {
|
|
445
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
446
|
+
width: 24,
|
|
447
|
+
height: 24,
|
|
448
|
+
viewBox: "0 0 24 24",
|
|
449
|
+
fill: "none",
|
|
450
|
+
stroke: "currentColor",
|
|
451
|
+
strokeWidth: 2,
|
|
452
|
+
strokeLinecap: "round",
|
|
453
|
+
strokeLinejoin: "round"
|
|
454
|
+
};
|
|
455
|
+
const Icon = forwardRef(
|
|
456
|
+
({
|
|
457
|
+
color = "currentColor",
|
|
458
|
+
size = 24,
|
|
459
|
+
strokeWidth = 2,
|
|
460
|
+
absoluteStrokeWidth,
|
|
461
|
+
className = "",
|
|
462
|
+
children,
|
|
463
|
+
iconNode,
|
|
464
|
+
...rest
|
|
465
|
+
}, ref) => createElement(
|
|
466
|
+
"svg",
|
|
467
|
+
{
|
|
468
|
+
ref,
|
|
469
|
+
...defaultAttributes,
|
|
470
|
+
width: size,
|
|
471
|
+
height: size,
|
|
472
|
+
stroke: color,
|
|
473
|
+
strokeWidth: absoluteStrokeWidth ? Number(strokeWidth) * 24 / Number(size) : strokeWidth,
|
|
474
|
+
className: mergeClasses("lucide", className),
|
|
475
|
+
...!children && !hasA11yProp(rest) && { "aria-hidden": "true" },
|
|
476
|
+
...rest
|
|
477
|
+
},
|
|
478
|
+
[
|
|
479
|
+
...iconNode.map(([tag, attrs]) => createElement(tag, attrs)),
|
|
480
|
+
...Array.isArray(children) ? children : [children]
|
|
481
|
+
]
|
|
482
|
+
)
|
|
483
|
+
);
|
|
484
|
+
const createLucideIcon = (iconName, iconNode) => {
|
|
485
|
+
const Component = forwardRef(
|
|
486
|
+
({ className, ...props }, ref) => createElement(Icon, {
|
|
487
|
+
ref,
|
|
488
|
+
iconNode,
|
|
489
|
+
className: mergeClasses(
|
|
490
|
+
`lucide-${toKebabCase(toPascalCase(iconName))}`,
|
|
491
|
+
`lucide-${iconName}`,
|
|
492
|
+
className
|
|
493
|
+
),
|
|
494
|
+
...props
|
|
495
|
+
})
|
|
496
|
+
);
|
|
497
|
+
Component.displayName = toPascalCase(iconName);
|
|
498
|
+
return Component;
|
|
499
|
+
};
|
|
500
|
+
const __iconNode$7 = [
|
|
501
|
+
["path", { d: "M12 20v-9", key: "1qisl0" }],
|
|
502
|
+
["path", { d: "M14 7a4 4 0 0 1 4 4v3a6 6 0 0 1-12 0v-3a4 4 0 0 1 4-4z", key: "uouzyp" }],
|
|
503
|
+
["path", { d: "M14.12 3.88 16 2", key: "qol33r" }],
|
|
504
|
+
["path", { d: "M21 21a4 4 0 0 0-3.81-4", key: "1b0z45" }],
|
|
505
|
+
["path", { d: "M21 5a4 4 0 0 1-3.55 3.97", key: "5cxbf6" }],
|
|
506
|
+
["path", { d: "M22 13h-4", key: "1jl80f" }],
|
|
507
|
+
["path", { d: "M3 21a4 4 0 0 1 3.81-4", key: "1fjd4g" }],
|
|
508
|
+
["path", { d: "M3 5a4 4 0 0 0 3.55 3.97", key: "1d7oge" }],
|
|
509
|
+
["path", { d: "M6 13H2", key: "82j7cp" }],
|
|
510
|
+
["path", { d: "m8 2 1.88 1.88", key: "fmnt4t" }],
|
|
511
|
+
["path", { d: "M9 7.13V6a3 3 0 1 1 6 0v1.13", key: "1vgav8" }]
|
|
512
|
+
];
|
|
513
|
+
const Bug = createLucideIcon("bug", __iconNode$7);
|
|
514
|
+
const __iconNode$6 = [
|
|
515
|
+
["circle", { cx: "12", cy: "12", r: "10", key: "1mglay" }],
|
|
516
|
+
["line", { x1: "12", x2: "12", y1: "8", y2: "12", key: "1pkeuh" }],
|
|
517
|
+
["line", { x1: "12", x2: "12.01", y1: "16", y2: "16", key: "4dfq90" }]
|
|
518
|
+
];
|
|
519
|
+
const CircleAlert = createLucideIcon("circle-alert", __iconNode$6);
|
|
520
|
+
const __iconNode$5 = [
|
|
521
|
+
["path", { d: "M12 15V3", key: "m9g1x1" }],
|
|
522
|
+
["path", { d: "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4", key: "ih7n3h" }],
|
|
523
|
+
["path", { d: "m7 10 5 5 5-5", key: "brsn70" }]
|
|
524
|
+
];
|
|
525
|
+
const Download = createLucideIcon("download", __iconNode$5);
|
|
526
|
+
const __iconNode$4 = [["path", { d: "M21 12a9 9 0 1 1-6.219-8.56", key: "13zald" }]];
|
|
527
|
+
const LoaderCircle = createLucideIcon("loader-circle", __iconNode$4);
|
|
528
|
+
const __iconNode$3 = [
|
|
529
|
+
["rect", { x: "14", y: "3", width: "5", height: "18", rx: "1", key: "kaeet6" }],
|
|
530
|
+
["rect", { x: "5", y: "3", width: "5", height: "18", rx: "1", key: "1wsw3u" }]
|
|
531
|
+
];
|
|
532
|
+
const Pause = createLucideIcon("pause", __iconNode$3);
|
|
533
|
+
const __iconNode$2 = [
|
|
534
|
+
[
|
|
535
|
+
"path",
|
|
536
|
+
{
|
|
537
|
+
d: "M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z",
|
|
538
|
+
key: "10ikf1"
|
|
539
|
+
}
|
|
540
|
+
]
|
|
541
|
+
];
|
|
542
|
+
const Play = createLucideIcon("play", __iconNode$2);
|
|
543
|
+
const __iconNode$1 = [
|
|
544
|
+
["path", { d: "M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8", key: "1357e3" }],
|
|
545
|
+
["path", { d: "M3 3v5h5", key: "1xhq8a" }]
|
|
546
|
+
];
|
|
547
|
+
const RotateCcw = createLucideIcon("rotate-ccw", __iconNode$1);
|
|
548
|
+
const __iconNode = [
|
|
549
|
+
["path", { d: "M18 6 6 18", key: "1bl5f8" }],
|
|
550
|
+
["path", { d: "m6 6 12 12", key: "d8bk6v" }]
|
|
551
|
+
];
|
|
552
|
+
const X = createLucideIcon("x", __iconNode);
|
|
553
|
+
function formatTime(ms) {
|
|
554
|
+
const seconds = ms / 1e3;
|
|
555
|
+
return seconds.toFixed(2) + "s";
|
|
556
|
+
}
|
|
557
|
+
function TimelineControls({
|
|
558
|
+
isPlaying,
|
|
559
|
+
currentTime,
|
|
560
|
+
duration,
|
|
561
|
+
debugMode = false,
|
|
562
|
+
onPlayPause,
|
|
563
|
+
onSeek,
|
|
564
|
+
onReset,
|
|
565
|
+
onDebugToggle,
|
|
566
|
+
className = ""
|
|
567
|
+
}) {
|
|
568
|
+
const progress = duration > 0 ? currentTime / duration * 100 : 0;
|
|
569
|
+
return /* @__PURE__ */ jsxs("div", { className: `flex items-center gap-3 p-3 bg-neutral-800 border-t border-neutral-700 ${className}`, children: [
|
|
570
|
+
/* @__PURE__ */ jsx(
|
|
571
|
+
"button",
|
|
572
|
+
{
|
|
573
|
+
onClick: onReset,
|
|
574
|
+
className: "p-2 rounded hover:bg-neutral-700 text-neutral-300 hover:text-white transition-colors",
|
|
575
|
+
title: "Reset",
|
|
576
|
+
children: /* @__PURE__ */ jsx(RotateCcw, { size: 18 })
|
|
577
|
+
}
|
|
578
|
+
),
|
|
579
|
+
/* @__PURE__ */ jsx(
|
|
580
|
+
"button",
|
|
581
|
+
{
|
|
582
|
+
onClick: onPlayPause,
|
|
583
|
+
className: "p-2 rounded hover:bg-neutral-700 text-neutral-300 hover:text-white transition-colors",
|
|
584
|
+
title: isPlaying ? "Pause" : "Play",
|
|
585
|
+
children: isPlaying ? /* @__PURE__ */ jsx(Pause, { size: 18 }) : /* @__PURE__ */ jsx(Play, { size: 18 })
|
|
586
|
+
}
|
|
587
|
+
),
|
|
588
|
+
/* @__PURE__ */ jsxs("div", { className: "flex-1 flex items-center gap-3", children: [
|
|
589
|
+
/* @__PURE__ */ jsx(
|
|
590
|
+
"input",
|
|
591
|
+
{
|
|
592
|
+
type: "range",
|
|
593
|
+
min: 0,
|
|
594
|
+
max: duration,
|
|
595
|
+
value: currentTime,
|
|
596
|
+
onChange: (e) => onSeek(Number(e.target.value)),
|
|
597
|
+
className: "flex-1 h-1 bg-neutral-600 rounded-lg appearance-none cursor-pointer\n [&::-webkit-slider-thumb]:appearance-none\n [&::-webkit-slider-thumb]:w-3\n [&::-webkit-slider-thumb]:h-3\n [&::-webkit-slider-thumb]:bg-blue-500\n [&::-webkit-slider-thumb]:rounded-full\n [&::-webkit-slider-thumb]:cursor-pointer",
|
|
598
|
+
style: {
|
|
599
|
+
background: `linear-gradient(to right, #3b82f6 0%, #3b82f6 ${progress}%, #525252 ${progress}%, #525252 100%)`
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
),
|
|
603
|
+
/* @__PURE__ */ jsxs("span", { className: "text-neutral-400 text-sm font-mono min-w-[80px] text-right", children: [
|
|
604
|
+
formatTime(currentTime),
|
|
605
|
+
" / ",
|
|
606
|
+
formatTime(duration)
|
|
607
|
+
] })
|
|
608
|
+
] }),
|
|
609
|
+
onDebugToggle && /* @__PURE__ */ jsx(
|
|
610
|
+
"button",
|
|
611
|
+
{
|
|
612
|
+
onClick: onDebugToggle,
|
|
613
|
+
className: `p-2 rounded transition-colors ${debugMode ? "bg-cyan-600 text-white" : "hover:bg-neutral-700 text-neutral-300 hover:text-white"}`,
|
|
614
|
+
title: "Toggle debug overlay",
|
|
615
|
+
children: /* @__PURE__ */ jsx(Bug, { size: 18 })
|
|
616
|
+
}
|
|
617
|
+
)
|
|
618
|
+
] });
|
|
619
|
+
}
|
|
620
|
+
function composeEventHandlers(originalEventHandler, ourEventHandler, { checkForDefaultPrevented = true } = {}) {
|
|
621
|
+
return function handleEvent(event) {
|
|
622
|
+
originalEventHandler?.(event);
|
|
623
|
+
if (checkForDefaultPrevented === false || !event.defaultPrevented) {
|
|
624
|
+
return ourEventHandler?.(event);
|
|
625
|
+
}
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
function setRef(ref, value) {
|
|
629
|
+
if (typeof ref === "function") {
|
|
630
|
+
return ref(value);
|
|
631
|
+
} else if (ref !== null && ref !== void 0) {
|
|
632
|
+
ref.current = value;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
function composeRefs(...refs) {
|
|
636
|
+
return (node) => {
|
|
637
|
+
let hasCleanup = false;
|
|
638
|
+
const cleanups = refs.map((ref) => {
|
|
639
|
+
const cleanup = setRef(ref, node);
|
|
640
|
+
if (!hasCleanup && typeof cleanup == "function") {
|
|
641
|
+
hasCleanup = true;
|
|
642
|
+
}
|
|
643
|
+
return cleanup;
|
|
644
|
+
});
|
|
645
|
+
if (hasCleanup) {
|
|
646
|
+
return () => {
|
|
647
|
+
for (let i = 0; i < cleanups.length; i++) {
|
|
648
|
+
const cleanup = cleanups[i];
|
|
649
|
+
if (typeof cleanup == "function") {
|
|
650
|
+
cleanup();
|
|
651
|
+
} else {
|
|
652
|
+
setRef(refs[i], null);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
function useComposedRefs(...refs) {
|
|
660
|
+
return React.useCallback(composeRefs(...refs), refs);
|
|
661
|
+
}
|
|
662
|
+
function createContext2(rootComponentName, defaultContext) {
|
|
663
|
+
const Context = React.createContext(defaultContext);
|
|
664
|
+
const Provider = (props) => {
|
|
665
|
+
const { children, ...context } = props;
|
|
666
|
+
const value = React.useMemo(() => context, Object.values(context));
|
|
667
|
+
return /* @__PURE__ */ jsx(Context.Provider, { value, children });
|
|
668
|
+
};
|
|
669
|
+
Provider.displayName = rootComponentName + "Provider";
|
|
670
|
+
function useContext2(consumerName) {
|
|
671
|
+
const context = React.useContext(Context);
|
|
672
|
+
if (context) return context;
|
|
673
|
+
if (defaultContext !== void 0) return defaultContext;
|
|
674
|
+
throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
|
|
675
|
+
}
|
|
676
|
+
return [Provider, useContext2];
|
|
677
|
+
}
|
|
678
|
+
function createContextScope(scopeName, createContextScopeDeps = []) {
|
|
679
|
+
let defaultContexts = [];
|
|
680
|
+
function createContext3(rootComponentName, defaultContext) {
|
|
681
|
+
const BaseContext = React.createContext(defaultContext);
|
|
682
|
+
const index = defaultContexts.length;
|
|
683
|
+
defaultContexts = [...defaultContexts, defaultContext];
|
|
684
|
+
const Provider = (props) => {
|
|
685
|
+
const { scope, children, ...context } = props;
|
|
686
|
+
const Context = scope?.[scopeName]?.[index] || BaseContext;
|
|
687
|
+
const value = React.useMemo(() => context, Object.values(context));
|
|
688
|
+
return /* @__PURE__ */ jsx(Context.Provider, { value, children });
|
|
689
|
+
};
|
|
690
|
+
Provider.displayName = rootComponentName + "Provider";
|
|
691
|
+
function useContext2(consumerName, scope) {
|
|
692
|
+
const Context = scope?.[scopeName]?.[index] || BaseContext;
|
|
693
|
+
const context = React.useContext(Context);
|
|
694
|
+
if (context) return context;
|
|
695
|
+
if (defaultContext !== void 0) return defaultContext;
|
|
696
|
+
throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
|
|
697
|
+
}
|
|
698
|
+
return [Provider, useContext2];
|
|
699
|
+
}
|
|
700
|
+
const createScope = () => {
|
|
701
|
+
const scopeContexts = defaultContexts.map((defaultContext) => {
|
|
702
|
+
return React.createContext(defaultContext);
|
|
703
|
+
});
|
|
704
|
+
return function useScope(scope) {
|
|
705
|
+
const contexts = scope?.[scopeName] || scopeContexts;
|
|
706
|
+
return React.useMemo(
|
|
707
|
+
() => ({ [`__scope${scopeName}`]: { ...scope, [scopeName]: contexts } }),
|
|
708
|
+
[scope, contexts]
|
|
709
|
+
);
|
|
710
|
+
};
|
|
711
|
+
};
|
|
712
|
+
createScope.scopeName = scopeName;
|
|
713
|
+
return [createContext3, composeContextScopes(createScope, ...createContextScopeDeps)];
|
|
714
|
+
}
|
|
715
|
+
function composeContextScopes(...scopes) {
|
|
716
|
+
const baseScope = scopes[0];
|
|
717
|
+
if (scopes.length === 1) return baseScope;
|
|
718
|
+
const createScope = () => {
|
|
719
|
+
const scopeHooks = scopes.map((createScope2) => ({
|
|
720
|
+
useScope: createScope2(),
|
|
721
|
+
scopeName: createScope2.scopeName
|
|
722
|
+
}));
|
|
723
|
+
return function useComposedScopes(overrideScopes) {
|
|
724
|
+
const nextScopes = scopeHooks.reduce((nextScopes2, { useScope, scopeName }) => {
|
|
725
|
+
const scopeProps = useScope(overrideScopes);
|
|
726
|
+
const currentScope = scopeProps[`__scope${scopeName}`];
|
|
727
|
+
return { ...nextScopes2, ...currentScope };
|
|
728
|
+
}, {});
|
|
729
|
+
return React.useMemo(() => ({ [`__scope${baseScope.scopeName}`]: nextScopes }), [nextScopes]);
|
|
730
|
+
};
|
|
731
|
+
};
|
|
732
|
+
createScope.scopeName = baseScope.scopeName;
|
|
733
|
+
return createScope;
|
|
734
|
+
}
|
|
735
|
+
var useLayoutEffect2 = globalThis?.document ? React.useLayoutEffect : () => {
|
|
736
|
+
};
|
|
737
|
+
var useReactId = React[" useId ".trim().toString()] || (() => void 0);
|
|
738
|
+
var count$1 = 0;
|
|
739
|
+
function useId(deterministicId) {
|
|
740
|
+
const [id, setId] = React.useState(useReactId());
|
|
741
|
+
useLayoutEffect2(() => {
|
|
742
|
+
setId((reactId) => reactId ?? String(count$1++));
|
|
743
|
+
}, [deterministicId]);
|
|
744
|
+
return deterministicId || (id ? `radix-${id}` : "");
|
|
745
|
+
}
|
|
746
|
+
var useInsertionEffect = React[" useInsertionEffect ".trim().toString()] || useLayoutEffect2;
|
|
747
|
+
function useControllableState({
|
|
748
|
+
prop,
|
|
749
|
+
defaultProp,
|
|
750
|
+
onChange = () => {
|
|
751
|
+
},
|
|
752
|
+
caller
|
|
753
|
+
}) {
|
|
754
|
+
const [uncontrolledProp, setUncontrolledProp, onChangeRef] = useUncontrolledState({
|
|
755
|
+
defaultProp,
|
|
756
|
+
onChange
|
|
757
|
+
});
|
|
758
|
+
const isControlled = prop !== void 0;
|
|
759
|
+
const value = isControlled ? prop : uncontrolledProp;
|
|
760
|
+
{
|
|
761
|
+
const isControlledRef = React.useRef(prop !== void 0);
|
|
762
|
+
React.useEffect(() => {
|
|
763
|
+
const wasControlled = isControlledRef.current;
|
|
764
|
+
if (wasControlled !== isControlled) {
|
|
765
|
+
const from = wasControlled ? "controlled" : "uncontrolled";
|
|
766
|
+
const to = isControlled ? "controlled" : "uncontrolled";
|
|
767
|
+
console.warn(
|
|
768
|
+
`${caller} is changing from ${from} to ${to}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`
|
|
769
|
+
);
|
|
770
|
+
}
|
|
771
|
+
isControlledRef.current = isControlled;
|
|
772
|
+
}, [isControlled, caller]);
|
|
773
|
+
}
|
|
774
|
+
const setValue = React.useCallback(
|
|
775
|
+
(nextValue) => {
|
|
776
|
+
if (isControlled) {
|
|
777
|
+
const value2 = isFunction(nextValue) ? nextValue(prop) : nextValue;
|
|
778
|
+
if (value2 !== prop) {
|
|
779
|
+
onChangeRef.current?.(value2);
|
|
780
|
+
}
|
|
781
|
+
} else {
|
|
782
|
+
setUncontrolledProp(nextValue);
|
|
783
|
+
}
|
|
784
|
+
},
|
|
785
|
+
[isControlled, prop, setUncontrolledProp, onChangeRef]
|
|
786
|
+
);
|
|
787
|
+
return [value, setValue];
|
|
788
|
+
}
|
|
789
|
+
function useUncontrolledState({
|
|
790
|
+
defaultProp,
|
|
791
|
+
onChange
|
|
792
|
+
}) {
|
|
793
|
+
const [value, setValue] = React.useState(defaultProp);
|
|
794
|
+
const prevValueRef = React.useRef(value);
|
|
795
|
+
const onChangeRef = React.useRef(onChange);
|
|
796
|
+
useInsertionEffect(() => {
|
|
797
|
+
onChangeRef.current = onChange;
|
|
798
|
+
}, [onChange]);
|
|
799
|
+
React.useEffect(() => {
|
|
800
|
+
if (prevValueRef.current !== value) {
|
|
801
|
+
onChangeRef.current?.(value);
|
|
802
|
+
prevValueRef.current = value;
|
|
803
|
+
}
|
|
804
|
+
}, [value, prevValueRef]);
|
|
805
|
+
return [value, setValue, onChangeRef];
|
|
806
|
+
}
|
|
807
|
+
function isFunction(value) {
|
|
808
|
+
return typeof value === "function";
|
|
809
|
+
}
|
|
810
|
+
// @__NO_SIDE_EFFECTS__
|
|
811
|
+
function createSlot(ownerName) {
|
|
812
|
+
const SlotClone = /* @__PURE__ */ createSlotClone(ownerName);
|
|
813
|
+
const Slot2 = React.forwardRef((props, forwardedRef) => {
|
|
814
|
+
const { children, ...slotProps } = props;
|
|
815
|
+
const childrenArray = React.Children.toArray(children);
|
|
816
|
+
const slottable = childrenArray.find(isSlottable);
|
|
817
|
+
if (slottable) {
|
|
818
|
+
const newElement = slottable.props.children;
|
|
819
|
+
const newChildren = childrenArray.map((child) => {
|
|
820
|
+
if (child === slottable) {
|
|
821
|
+
if (React.Children.count(newElement) > 1) return React.Children.only(null);
|
|
822
|
+
return React.isValidElement(newElement) ? newElement.props.children : null;
|
|
823
|
+
} else {
|
|
824
|
+
return child;
|
|
825
|
+
}
|
|
826
|
+
});
|
|
827
|
+
return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children: React.isValidElement(newElement) ? React.cloneElement(newElement, void 0, newChildren) : null });
|
|
828
|
+
}
|
|
829
|
+
return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children });
|
|
830
|
+
});
|
|
831
|
+
Slot2.displayName = `${ownerName}.Slot`;
|
|
832
|
+
return Slot2;
|
|
833
|
+
}
|
|
834
|
+
// @__NO_SIDE_EFFECTS__
|
|
835
|
+
function createSlotClone(ownerName) {
|
|
836
|
+
const SlotClone = React.forwardRef((props, forwardedRef) => {
|
|
837
|
+
const { children, ...slotProps } = props;
|
|
838
|
+
if (React.isValidElement(children)) {
|
|
839
|
+
const childrenRef = getElementRef$1(children);
|
|
840
|
+
const props2 = mergeProps(slotProps, children.props);
|
|
841
|
+
if (children.type !== React.Fragment) {
|
|
842
|
+
props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
|
|
843
|
+
}
|
|
844
|
+
return React.cloneElement(children, props2);
|
|
845
|
+
}
|
|
846
|
+
return React.Children.count(children) > 1 ? React.Children.only(null) : null;
|
|
847
|
+
});
|
|
848
|
+
SlotClone.displayName = `${ownerName}.SlotClone`;
|
|
849
|
+
return SlotClone;
|
|
850
|
+
}
|
|
851
|
+
var SLOTTABLE_IDENTIFIER = /* @__PURE__ */ Symbol("radix.slottable");
|
|
852
|
+
function isSlottable(child) {
|
|
853
|
+
return React.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER;
|
|
854
|
+
}
|
|
855
|
+
function mergeProps(slotProps, childProps) {
|
|
856
|
+
const overrideProps = { ...childProps };
|
|
857
|
+
for (const propName in childProps) {
|
|
858
|
+
const slotPropValue = slotProps[propName];
|
|
859
|
+
const childPropValue = childProps[propName];
|
|
860
|
+
const isHandler = /^on[A-Z]/.test(propName);
|
|
861
|
+
if (isHandler) {
|
|
862
|
+
if (slotPropValue && childPropValue) {
|
|
863
|
+
overrideProps[propName] = (...args) => {
|
|
864
|
+
const result = childPropValue(...args);
|
|
865
|
+
slotPropValue(...args);
|
|
866
|
+
return result;
|
|
867
|
+
};
|
|
868
|
+
} else if (slotPropValue) {
|
|
869
|
+
overrideProps[propName] = slotPropValue;
|
|
870
|
+
}
|
|
871
|
+
} else if (propName === "style") {
|
|
872
|
+
overrideProps[propName] = { ...slotPropValue, ...childPropValue };
|
|
873
|
+
} else if (propName === "className") {
|
|
874
|
+
overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
return { ...slotProps, ...overrideProps };
|
|
878
|
+
}
|
|
879
|
+
function getElementRef$1(element) {
|
|
880
|
+
let getter = Object.getOwnPropertyDescriptor(element.props, "ref")?.get;
|
|
881
|
+
let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
|
|
882
|
+
if (mayWarn) {
|
|
883
|
+
return element.ref;
|
|
884
|
+
}
|
|
885
|
+
getter = Object.getOwnPropertyDescriptor(element, "ref")?.get;
|
|
886
|
+
mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
|
|
887
|
+
if (mayWarn) {
|
|
888
|
+
return element.props.ref;
|
|
889
|
+
}
|
|
890
|
+
return element.props.ref || element.ref;
|
|
891
|
+
}
|
|
892
|
+
var NODES = [
|
|
893
|
+
"a",
|
|
894
|
+
"button",
|
|
895
|
+
"div",
|
|
896
|
+
"form",
|
|
897
|
+
"h2",
|
|
898
|
+
"h3",
|
|
899
|
+
"img",
|
|
900
|
+
"input",
|
|
901
|
+
"label",
|
|
902
|
+
"li",
|
|
903
|
+
"nav",
|
|
904
|
+
"ol",
|
|
905
|
+
"p",
|
|
906
|
+
"select",
|
|
907
|
+
"span",
|
|
908
|
+
"svg",
|
|
909
|
+
"ul"
|
|
910
|
+
];
|
|
911
|
+
var Primitive = NODES.reduce((primitive, node) => {
|
|
912
|
+
const Slot2 = /* @__PURE__ */ createSlot(`Primitive.${node}`);
|
|
913
|
+
const Node2 = React.forwardRef((props, forwardedRef) => {
|
|
914
|
+
const { asChild, ...primitiveProps } = props;
|
|
915
|
+
const Comp = asChild ? Slot2 : node;
|
|
916
|
+
if (typeof window !== "undefined") {
|
|
917
|
+
window[/* @__PURE__ */ Symbol.for("radix-ui")] = true;
|
|
918
|
+
}
|
|
919
|
+
return /* @__PURE__ */ jsx(Comp, { ...primitiveProps, ref: forwardedRef });
|
|
920
|
+
});
|
|
921
|
+
Node2.displayName = `Primitive.${node}`;
|
|
922
|
+
return { ...primitive, [node]: Node2 };
|
|
923
|
+
}, {});
|
|
924
|
+
function dispatchDiscreteCustomEvent(target, event) {
|
|
925
|
+
if (target) ReactDOM.flushSync(() => target.dispatchEvent(event));
|
|
926
|
+
}
|
|
927
|
+
function useCallbackRef$1(callback) {
|
|
928
|
+
const callbackRef = React.useRef(callback);
|
|
929
|
+
React.useEffect(() => {
|
|
930
|
+
callbackRef.current = callback;
|
|
931
|
+
});
|
|
932
|
+
return React.useMemo(() => (...args) => callbackRef.current?.(...args), []);
|
|
933
|
+
}
|
|
934
|
+
function useEscapeKeydown(onEscapeKeyDownProp, ownerDocument = globalThis?.document) {
|
|
935
|
+
const onEscapeKeyDown = useCallbackRef$1(onEscapeKeyDownProp);
|
|
936
|
+
React.useEffect(() => {
|
|
937
|
+
const handleKeyDown = (event) => {
|
|
938
|
+
if (event.key === "Escape") {
|
|
939
|
+
onEscapeKeyDown(event);
|
|
940
|
+
}
|
|
941
|
+
};
|
|
942
|
+
ownerDocument.addEventListener("keydown", handleKeyDown, { capture: true });
|
|
943
|
+
return () => ownerDocument.removeEventListener("keydown", handleKeyDown, { capture: true });
|
|
944
|
+
}, [onEscapeKeyDown, ownerDocument]);
|
|
945
|
+
}
|
|
946
|
+
var DISMISSABLE_LAYER_NAME = "DismissableLayer";
|
|
947
|
+
var CONTEXT_UPDATE = "dismissableLayer.update";
|
|
948
|
+
var POINTER_DOWN_OUTSIDE = "dismissableLayer.pointerDownOutside";
|
|
949
|
+
var FOCUS_OUTSIDE = "dismissableLayer.focusOutside";
|
|
950
|
+
var originalBodyPointerEvents;
|
|
951
|
+
var DismissableLayerContext = React.createContext({
|
|
952
|
+
layers: /* @__PURE__ */ new Set(),
|
|
953
|
+
layersWithOutsidePointerEventsDisabled: /* @__PURE__ */ new Set(),
|
|
954
|
+
branches: /* @__PURE__ */ new Set()
|
|
955
|
+
});
|
|
956
|
+
var DismissableLayer = React.forwardRef(
|
|
957
|
+
(props, forwardedRef) => {
|
|
958
|
+
const {
|
|
959
|
+
disableOutsidePointerEvents = false,
|
|
960
|
+
onEscapeKeyDown,
|
|
961
|
+
onPointerDownOutside,
|
|
962
|
+
onFocusOutside,
|
|
963
|
+
onInteractOutside,
|
|
964
|
+
onDismiss,
|
|
965
|
+
...layerProps
|
|
966
|
+
} = props;
|
|
967
|
+
const context = React.useContext(DismissableLayerContext);
|
|
968
|
+
const [node, setNode] = React.useState(null);
|
|
969
|
+
const ownerDocument = node?.ownerDocument ?? globalThis?.document;
|
|
970
|
+
const [, force] = React.useState({});
|
|
971
|
+
const composedRefs = useComposedRefs(forwardedRef, (node2) => setNode(node2));
|
|
972
|
+
const layers = Array.from(context.layers);
|
|
973
|
+
const [highestLayerWithOutsidePointerEventsDisabled] = [...context.layersWithOutsidePointerEventsDisabled].slice(-1);
|
|
974
|
+
const highestLayerWithOutsidePointerEventsDisabledIndex = layers.indexOf(highestLayerWithOutsidePointerEventsDisabled);
|
|
975
|
+
const index = node ? layers.indexOf(node) : -1;
|
|
976
|
+
const isBodyPointerEventsDisabled = context.layersWithOutsidePointerEventsDisabled.size > 0;
|
|
977
|
+
const isPointerEventsEnabled = index >= highestLayerWithOutsidePointerEventsDisabledIndex;
|
|
978
|
+
const pointerDownOutside = usePointerDownOutside((event) => {
|
|
979
|
+
const target = event.target;
|
|
980
|
+
const isPointerDownOnBranch = [...context.branches].some((branch) => branch.contains(target));
|
|
981
|
+
if (!isPointerEventsEnabled || isPointerDownOnBranch) return;
|
|
982
|
+
onPointerDownOutside?.(event);
|
|
983
|
+
onInteractOutside?.(event);
|
|
984
|
+
if (!event.defaultPrevented) onDismiss?.();
|
|
985
|
+
}, ownerDocument);
|
|
986
|
+
const focusOutside = useFocusOutside((event) => {
|
|
987
|
+
const target = event.target;
|
|
988
|
+
const isFocusInBranch = [...context.branches].some((branch) => branch.contains(target));
|
|
989
|
+
if (isFocusInBranch) return;
|
|
990
|
+
onFocusOutside?.(event);
|
|
991
|
+
onInteractOutside?.(event);
|
|
992
|
+
if (!event.defaultPrevented) onDismiss?.();
|
|
993
|
+
}, ownerDocument);
|
|
994
|
+
useEscapeKeydown((event) => {
|
|
995
|
+
const isHighestLayer = index === context.layers.size - 1;
|
|
996
|
+
if (!isHighestLayer) return;
|
|
997
|
+
onEscapeKeyDown?.(event);
|
|
998
|
+
if (!event.defaultPrevented && onDismiss) {
|
|
999
|
+
event.preventDefault();
|
|
1000
|
+
onDismiss();
|
|
1001
|
+
}
|
|
1002
|
+
}, ownerDocument);
|
|
1003
|
+
React.useEffect(() => {
|
|
1004
|
+
if (!node) return;
|
|
1005
|
+
if (disableOutsidePointerEvents) {
|
|
1006
|
+
if (context.layersWithOutsidePointerEventsDisabled.size === 0) {
|
|
1007
|
+
originalBodyPointerEvents = ownerDocument.body.style.pointerEvents;
|
|
1008
|
+
ownerDocument.body.style.pointerEvents = "none";
|
|
1009
|
+
}
|
|
1010
|
+
context.layersWithOutsidePointerEventsDisabled.add(node);
|
|
1011
|
+
}
|
|
1012
|
+
context.layers.add(node);
|
|
1013
|
+
dispatchUpdate();
|
|
1014
|
+
return () => {
|
|
1015
|
+
if (disableOutsidePointerEvents && context.layersWithOutsidePointerEventsDisabled.size === 1) {
|
|
1016
|
+
ownerDocument.body.style.pointerEvents = originalBodyPointerEvents;
|
|
1017
|
+
}
|
|
1018
|
+
};
|
|
1019
|
+
}, [node, ownerDocument, disableOutsidePointerEvents, context]);
|
|
1020
|
+
React.useEffect(() => {
|
|
1021
|
+
return () => {
|
|
1022
|
+
if (!node) return;
|
|
1023
|
+
context.layers.delete(node);
|
|
1024
|
+
context.layersWithOutsidePointerEventsDisabled.delete(node);
|
|
1025
|
+
dispatchUpdate();
|
|
1026
|
+
};
|
|
1027
|
+
}, [node, context]);
|
|
1028
|
+
React.useEffect(() => {
|
|
1029
|
+
const handleUpdate = () => force({});
|
|
1030
|
+
document.addEventListener(CONTEXT_UPDATE, handleUpdate);
|
|
1031
|
+
return () => document.removeEventListener(CONTEXT_UPDATE, handleUpdate);
|
|
1032
|
+
}, []);
|
|
1033
|
+
return /* @__PURE__ */ jsx(
|
|
1034
|
+
Primitive.div,
|
|
1035
|
+
{
|
|
1036
|
+
...layerProps,
|
|
1037
|
+
ref: composedRefs,
|
|
1038
|
+
style: {
|
|
1039
|
+
pointerEvents: isBodyPointerEventsDisabled ? isPointerEventsEnabled ? "auto" : "none" : void 0,
|
|
1040
|
+
...props.style
|
|
1041
|
+
},
|
|
1042
|
+
onFocusCapture: composeEventHandlers(props.onFocusCapture, focusOutside.onFocusCapture),
|
|
1043
|
+
onBlurCapture: composeEventHandlers(props.onBlurCapture, focusOutside.onBlurCapture),
|
|
1044
|
+
onPointerDownCapture: composeEventHandlers(
|
|
1045
|
+
props.onPointerDownCapture,
|
|
1046
|
+
pointerDownOutside.onPointerDownCapture
|
|
1047
|
+
)
|
|
1048
|
+
}
|
|
1049
|
+
);
|
|
1050
|
+
}
|
|
1051
|
+
);
|
|
1052
|
+
DismissableLayer.displayName = DISMISSABLE_LAYER_NAME;
|
|
1053
|
+
var BRANCH_NAME = "DismissableLayerBranch";
|
|
1054
|
+
var DismissableLayerBranch = React.forwardRef((props, forwardedRef) => {
|
|
1055
|
+
const context = React.useContext(DismissableLayerContext);
|
|
1056
|
+
const ref = React.useRef(null);
|
|
1057
|
+
const composedRefs = useComposedRefs(forwardedRef, ref);
|
|
1058
|
+
React.useEffect(() => {
|
|
1059
|
+
const node = ref.current;
|
|
1060
|
+
if (node) {
|
|
1061
|
+
context.branches.add(node);
|
|
1062
|
+
return () => {
|
|
1063
|
+
context.branches.delete(node);
|
|
1064
|
+
};
|
|
1065
|
+
}
|
|
1066
|
+
}, [context.branches]);
|
|
1067
|
+
return /* @__PURE__ */ jsx(Primitive.div, { ...props, ref: composedRefs });
|
|
1068
|
+
});
|
|
1069
|
+
DismissableLayerBranch.displayName = BRANCH_NAME;
|
|
1070
|
+
function usePointerDownOutside(onPointerDownOutside, ownerDocument = globalThis?.document) {
|
|
1071
|
+
const handlePointerDownOutside = useCallbackRef$1(onPointerDownOutside);
|
|
1072
|
+
const isPointerInsideReactTreeRef = React.useRef(false);
|
|
1073
|
+
const handleClickRef = React.useRef(() => {
|
|
1074
|
+
});
|
|
1075
|
+
React.useEffect(() => {
|
|
1076
|
+
const handlePointerDown = (event) => {
|
|
1077
|
+
if (event.target && !isPointerInsideReactTreeRef.current) {
|
|
1078
|
+
let handleAndDispatchPointerDownOutsideEvent2 = function() {
|
|
1079
|
+
handleAndDispatchCustomEvent(
|
|
1080
|
+
POINTER_DOWN_OUTSIDE,
|
|
1081
|
+
handlePointerDownOutside,
|
|
1082
|
+
eventDetail,
|
|
1083
|
+
{ discrete: true }
|
|
1084
|
+
);
|
|
1085
|
+
};
|
|
1086
|
+
const eventDetail = { originalEvent: event };
|
|
1087
|
+
if (event.pointerType === "touch") {
|
|
1088
|
+
ownerDocument.removeEventListener("click", handleClickRef.current);
|
|
1089
|
+
handleClickRef.current = handleAndDispatchPointerDownOutsideEvent2;
|
|
1090
|
+
ownerDocument.addEventListener("click", handleClickRef.current, { once: true });
|
|
1091
|
+
} else {
|
|
1092
|
+
handleAndDispatchPointerDownOutsideEvent2();
|
|
1093
|
+
}
|
|
1094
|
+
} else {
|
|
1095
|
+
ownerDocument.removeEventListener("click", handleClickRef.current);
|
|
1096
|
+
}
|
|
1097
|
+
isPointerInsideReactTreeRef.current = false;
|
|
1098
|
+
};
|
|
1099
|
+
const timerId = window.setTimeout(() => {
|
|
1100
|
+
ownerDocument.addEventListener("pointerdown", handlePointerDown);
|
|
1101
|
+
}, 0);
|
|
1102
|
+
return () => {
|
|
1103
|
+
window.clearTimeout(timerId);
|
|
1104
|
+
ownerDocument.removeEventListener("pointerdown", handlePointerDown);
|
|
1105
|
+
ownerDocument.removeEventListener("click", handleClickRef.current);
|
|
1106
|
+
};
|
|
1107
|
+
}, [ownerDocument, handlePointerDownOutside]);
|
|
1108
|
+
return {
|
|
1109
|
+
// ensures we check React component tree (not just DOM tree)
|
|
1110
|
+
onPointerDownCapture: () => isPointerInsideReactTreeRef.current = true
|
|
1111
|
+
};
|
|
1112
|
+
}
|
|
1113
|
+
function useFocusOutside(onFocusOutside, ownerDocument = globalThis?.document) {
|
|
1114
|
+
const handleFocusOutside = useCallbackRef$1(onFocusOutside);
|
|
1115
|
+
const isFocusInsideReactTreeRef = React.useRef(false);
|
|
1116
|
+
React.useEffect(() => {
|
|
1117
|
+
const handleFocus = (event) => {
|
|
1118
|
+
if (event.target && !isFocusInsideReactTreeRef.current) {
|
|
1119
|
+
const eventDetail = { originalEvent: event };
|
|
1120
|
+
handleAndDispatchCustomEvent(FOCUS_OUTSIDE, handleFocusOutside, eventDetail, {
|
|
1121
|
+
discrete: false
|
|
1122
|
+
});
|
|
1123
|
+
}
|
|
1124
|
+
};
|
|
1125
|
+
ownerDocument.addEventListener("focusin", handleFocus);
|
|
1126
|
+
return () => ownerDocument.removeEventListener("focusin", handleFocus);
|
|
1127
|
+
}, [ownerDocument, handleFocusOutside]);
|
|
1128
|
+
return {
|
|
1129
|
+
onFocusCapture: () => isFocusInsideReactTreeRef.current = true,
|
|
1130
|
+
onBlurCapture: () => isFocusInsideReactTreeRef.current = false
|
|
1131
|
+
};
|
|
1132
|
+
}
|
|
1133
|
+
function dispatchUpdate() {
|
|
1134
|
+
const event = new CustomEvent(CONTEXT_UPDATE);
|
|
1135
|
+
document.dispatchEvent(event);
|
|
1136
|
+
}
|
|
1137
|
+
function handleAndDispatchCustomEvent(name, handler, detail, { discrete }) {
|
|
1138
|
+
const target = detail.originalEvent.target;
|
|
1139
|
+
const event = new CustomEvent(name, { bubbles: false, cancelable: true, detail });
|
|
1140
|
+
if (handler) target.addEventListener(name, handler, { once: true });
|
|
1141
|
+
if (discrete) {
|
|
1142
|
+
dispatchDiscreteCustomEvent(target, event);
|
|
1143
|
+
} else {
|
|
1144
|
+
target.dispatchEvent(event);
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
var AUTOFOCUS_ON_MOUNT = "focusScope.autoFocusOnMount";
|
|
1148
|
+
var AUTOFOCUS_ON_UNMOUNT = "focusScope.autoFocusOnUnmount";
|
|
1149
|
+
var EVENT_OPTIONS = { bubbles: false, cancelable: true };
|
|
1150
|
+
var FOCUS_SCOPE_NAME = "FocusScope";
|
|
1151
|
+
var FocusScope = React.forwardRef((props, forwardedRef) => {
|
|
1152
|
+
const {
|
|
1153
|
+
loop = false,
|
|
1154
|
+
trapped = false,
|
|
1155
|
+
onMountAutoFocus: onMountAutoFocusProp,
|
|
1156
|
+
onUnmountAutoFocus: onUnmountAutoFocusProp,
|
|
1157
|
+
...scopeProps
|
|
1158
|
+
} = props;
|
|
1159
|
+
const [container, setContainer] = React.useState(null);
|
|
1160
|
+
const onMountAutoFocus = useCallbackRef$1(onMountAutoFocusProp);
|
|
1161
|
+
const onUnmountAutoFocus = useCallbackRef$1(onUnmountAutoFocusProp);
|
|
1162
|
+
const lastFocusedElementRef = React.useRef(null);
|
|
1163
|
+
const composedRefs = useComposedRefs(forwardedRef, (node) => setContainer(node));
|
|
1164
|
+
const focusScope = React.useRef({
|
|
1165
|
+
paused: false,
|
|
1166
|
+
pause() {
|
|
1167
|
+
this.paused = true;
|
|
1168
|
+
},
|
|
1169
|
+
resume() {
|
|
1170
|
+
this.paused = false;
|
|
1171
|
+
}
|
|
1172
|
+
}).current;
|
|
1173
|
+
React.useEffect(() => {
|
|
1174
|
+
if (trapped) {
|
|
1175
|
+
let handleFocusIn2 = function(event) {
|
|
1176
|
+
if (focusScope.paused || !container) return;
|
|
1177
|
+
const target = event.target;
|
|
1178
|
+
if (container.contains(target)) {
|
|
1179
|
+
lastFocusedElementRef.current = target;
|
|
1180
|
+
} else {
|
|
1181
|
+
focus(lastFocusedElementRef.current, { select: true });
|
|
1182
|
+
}
|
|
1183
|
+
}, handleFocusOut2 = function(event) {
|
|
1184
|
+
if (focusScope.paused || !container) return;
|
|
1185
|
+
const relatedTarget = event.relatedTarget;
|
|
1186
|
+
if (relatedTarget === null) return;
|
|
1187
|
+
if (!container.contains(relatedTarget)) {
|
|
1188
|
+
focus(lastFocusedElementRef.current, { select: true });
|
|
1189
|
+
}
|
|
1190
|
+
}, handleMutations2 = function(mutations) {
|
|
1191
|
+
const focusedElement = document.activeElement;
|
|
1192
|
+
if (focusedElement !== document.body) return;
|
|
1193
|
+
for (const mutation of mutations) {
|
|
1194
|
+
if (mutation.removedNodes.length > 0) focus(container);
|
|
1195
|
+
}
|
|
1196
|
+
};
|
|
1197
|
+
document.addEventListener("focusin", handleFocusIn2);
|
|
1198
|
+
document.addEventListener("focusout", handleFocusOut2);
|
|
1199
|
+
const mutationObserver = new MutationObserver(handleMutations2);
|
|
1200
|
+
if (container) mutationObserver.observe(container, { childList: true, subtree: true });
|
|
1201
|
+
return () => {
|
|
1202
|
+
document.removeEventListener("focusin", handleFocusIn2);
|
|
1203
|
+
document.removeEventListener("focusout", handleFocusOut2);
|
|
1204
|
+
mutationObserver.disconnect();
|
|
1205
|
+
};
|
|
1206
|
+
}
|
|
1207
|
+
}, [trapped, container, focusScope.paused]);
|
|
1208
|
+
React.useEffect(() => {
|
|
1209
|
+
if (container) {
|
|
1210
|
+
focusScopesStack.add(focusScope);
|
|
1211
|
+
const previouslyFocusedElement = document.activeElement;
|
|
1212
|
+
const hasFocusedCandidate = container.contains(previouslyFocusedElement);
|
|
1213
|
+
if (!hasFocusedCandidate) {
|
|
1214
|
+
const mountEvent = new CustomEvent(AUTOFOCUS_ON_MOUNT, EVENT_OPTIONS);
|
|
1215
|
+
container.addEventListener(AUTOFOCUS_ON_MOUNT, onMountAutoFocus);
|
|
1216
|
+
container.dispatchEvent(mountEvent);
|
|
1217
|
+
if (!mountEvent.defaultPrevented) {
|
|
1218
|
+
focusFirst(removeLinks(getTabbableCandidates(container)), { select: true });
|
|
1219
|
+
if (document.activeElement === previouslyFocusedElement) {
|
|
1220
|
+
focus(container);
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
return () => {
|
|
1225
|
+
container.removeEventListener(AUTOFOCUS_ON_MOUNT, onMountAutoFocus);
|
|
1226
|
+
setTimeout(() => {
|
|
1227
|
+
const unmountEvent = new CustomEvent(AUTOFOCUS_ON_UNMOUNT, EVENT_OPTIONS);
|
|
1228
|
+
container.addEventListener(AUTOFOCUS_ON_UNMOUNT, onUnmountAutoFocus);
|
|
1229
|
+
container.dispatchEvent(unmountEvent);
|
|
1230
|
+
if (!unmountEvent.defaultPrevented) {
|
|
1231
|
+
focus(previouslyFocusedElement ?? document.body, { select: true });
|
|
1232
|
+
}
|
|
1233
|
+
container.removeEventListener(AUTOFOCUS_ON_UNMOUNT, onUnmountAutoFocus);
|
|
1234
|
+
focusScopesStack.remove(focusScope);
|
|
1235
|
+
}, 0);
|
|
1236
|
+
};
|
|
1237
|
+
}
|
|
1238
|
+
}, [container, onMountAutoFocus, onUnmountAutoFocus, focusScope]);
|
|
1239
|
+
const handleKeyDown = React.useCallback(
|
|
1240
|
+
(event) => {
|
|
1241
|
+
if (!loop && !trapped) return;
|
|
1242
|
+
if (focusScope.paused) return;
|
|
1243
|
+
const isTabKey = event.key === "Tab" && !event.altKey && !event.ctrlKey && !event.metaKey;
|
|
1244
|
+
const focusedElement = document.activeElement;
|
|
1245
|
+
if (isTabKey && focusedElement) {
|
|
1246
|
+
const container2 = event.currentTarget;
|
|
1247
|
+
const [first, last] = getTabbableEdges(container2);
|
|
1248
|
+
const hasTabbableElementsInside = first && last;
|
|
1249
|
+
if (!hasTabbableElementsInside) {
|
|
1250
|
+
if (focusedElement === container2) event.preventDefault();
|
|
1251
|
+
} else {
|
|
1252
|
+
if (!event.shiftKey && focusedElement === last) {
|
|
1253
|
+
event.preventDefault();
|
|
1254
|
+
if (loop) focus(first, { select: true });
|
|
1255
|
+
} else if (event.shiftKey && focusedElement === first) {
|
|
1256
|
+
event.preventDefault();
|
|
1257
|
+
if (loop) focus(last, { select: true });
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
},
|
|
1262
|
+
[loop, trapped, focusScope.paused]
|
|
1263
|
+
);
|
|
1264
|
+
return /* @__PURE__ */ jsx(Primitive.div, { tabIndex: -1, ...scopeProps, ref: composedRefs, onKeyDown: handleKeyDown });
|
|
1265
|
+
});
|
|
1266
|
+
FocusScope.displayName = FOCUS_SCOPE_NAME;
|
|
1267
|
+
function focusFirst(candidates, { select = false } = {}) {
|
|
1268
|
+
const previouslyFocusedElement = document.activeElement;
|
|
1269
|
+
for (const candidate of candidates) {
|
|
1270
|
+
focus(candidate, { select });
|
|
1271
|
+
if (document.activeElement !== previouslyFocusedElement) return;
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
function getTabbableEdges(container) {
|
|
1275
|
+
const candidates = getTabbableCandidates(container);
|
|
1276
|
+
const first = findVisible(candidates, container);
|
|
1277
|
+
const last = findVisible(candidates.reverse(), container);
|
|
1278
|
+
return [first, last];
|
|
1279
|
+
}
|
|
1280
|
+
function getTabbableCandidates(container) {
|
|
1281
|
+
const nodes = [];
|
|
1282
|
+
const walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
|
|
1283
|
+
acceptNode: (node) => {
|
|
1284
|
+
const isHiddenInput = node.tagName === "INPUT" && node.type === "hidden";
|
|
1285
|
+
if (node.disabled || node.hidden || isHiddenInput) return NodeFilter.FILTER_SKIP;
|
|
1286
|
+
return node.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
|
1287
|
+
}
|
|
1288
|
+
});
|
|
1289
|
+
while (walker.nextNode()) nodes.push(walker.currentNode);
|
|
1290
|
+
return nodes;
|
|
1291
|
+
}
|
|
1292
|
+
function findVisible(elements, container) {
|
|
1293
|
+
for (const element of elements) {
|
|
1294
|
+
if (!isHidden(element, { upTo: container })) return element;
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
function isHidden(node, { upTo }) {
|
|
1298
|
+
if (getComputedStyle(node).visibility === "hidden") return true;
|
|
1299
|
+
while (node) {
|
|
1300
|
+
if (upTo !== void 0 && node === upTo) return false;
|
|
1301
|
+
if (getComputedStyle(node).display === "none") return true;
|
|
1302
|
+
node = node.parentElement;
|
|
1303
|
+
}
|
|
1304
|
+
return false;
|
|
1305
|
+
}
|
|
1306
|
+
function isSelectableInput(element) {
|
|
1307
|
+
return element instanceof HTMLInputElement && "select" in element;
|
|
1308
|
+
}
|
|
1309
|
+
function focus(element, { select = false } = {}) {
|
|
1310
|
+
if (element && element.focus) {
|
|
1311
|
+
const previouslyFocusedElement = document.activeElement;
|
|
1312
|
+
element.focus({ preventScroll: true });
|
|
1313
|
+
if (element !== previouslyFocusedElement && isSelectableInput(element) && select)
|
|
1314
|
+
element.select();
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
var focusScopesStack = createFocusScopesStack();
|
|
1318
|
+
function createFocusScopesStack() {
|
|
1319
|
+
let stack = [];
|
|
1320
|
+
return {
|
|
1321
|
+
add(focusScope) {
|
|
1322
|
+
const activeFocusScope = stack[0];
|
|
1323
|
+
if (focusScope !== activeFocusScope) {
|
|
1324
|
+
activeFocusScope?.pause();
|
|
1325
|
+
}
|
|
1326
|
+
stack = arrayRemove(stack, focusScope);
|
|
1327
|
+
stack.unshift(focusScope);
|
|
1328
|
+
},
|
|
1329
|
+
remove(focusScope) {
|
|
1330
|
+
stack = arrayRemove(stack, focusScope);
|
|
1331
|
+
stack[0]?.resume();
|
|
1332
|
+
}
|
|
1333
|
+
};
|
|
1334
|
+
}
|
|
1335
|
+
function arrayRemove(array, item) {
|
|
1336
|
+
const updatedArray = [...array];
|
|
1337
|
+
const index = updatedArray.indexOf(item);
|
|
1338
|
+
if (index !== -1) {
|
|
1339
|
+
updatedArray.splice(index, 1);
|
|
1340
|
+
}
|
|
1341
|
+
return updatedArray;
|
|
1342
|
+
}
|
|
1343
|
+
function removeLinks(items) {
|
|
1344
|
+
return items.filter((item) => item.tagName !== "A");
|
|
1345
|
+
}
|
|
1346
|
+
var PORTAL_NAME$1 = "Portal";
|
|
1347
|
+
var Portal$1 = React.forwardRef((props, forwardedRef) => {
|
|
1348
|
+
const { container: containerProp, ...portalProps } = props;
|
|
1349
|
+
const [mounted, setMounted] = React.useState(false);
|
|
1350
|
+
useLayoutEffect2(() => setMounted(true), []);
|
|
1351
|
+
const container = containerProp || mounted && globalThis?.document?.body;
|
|
1352
|
+
return container ? ReactDOM__default.createPortal(/* @__PURE__ */ jsx(Primitive.div, { ...portalProps, ref: forwardedRef }), container) : null;
|
|
1353
|
+
});
|
|
1354
|
+
Portal$1.displayName = PORTAL_NAME$1;
|
|
1355
|
+
function useStateMachine(initialState, machine) {
|
|
1356
|
+
return React.useReducer((state, event) => {
|
|
1357
|
+
const nextState = machine[state][event];
|
|
1358
|
+
return nextState ?? state;
|
|
1359
|
+
}, initialState);
|
|
1360
|
+
}
|
|
1361
|
+
var Presence = (props) => {
|
|
1362
|
+
const { present, children } = props;
|
|
1363
|
+
const presence = usePresence(present);
|
|
1364
|
+
const child = typeof children === "function" ? children({ present: presence.isPresent }) : React.Children.only(children);
|
|
1365
|
+
const ref = useComposedRefs(presence.ref, getElementRef(child));
|
|
1366
|
+
const forceMount = typeof children === "function";
|
|
1367
|
+
return forceMount || presence.isPresent ? React.cloneElement(child, { ref }) : null;
|
|
1368
|
+
};
|
|
1369
|
+
Presence.displayName = "Presence";
|
|
1370
|
+
function usePresence(present) {
|
|
1371
|
+
const [node, setNode] = React.useState();
|
|
1372
|
+
const stylesRef = React.useRef(null);
|
|
1373
|
+
const prevPresentRef = React.useRef(present);
|
|
1374
|
+
const prevAnimationNameRef = React.useRef("none");
|
|
1375
|
+
const initialState = present ? "mounted" : "unmounted";
|
|
1376
|
+
const [state, send] = useStateMachine(initialState, {
|
|
1377
|
+
mounted: {
|
|
1378
|
+
UNMOUNT: "unmounted",
|
|
1379
|
+
ANIMATION_OUT: "unmountSuspended"
|
|
1380
|
+
},
|
|
1381
|
+
unmountSuspended: {
|
|
1382
|
+
MOUNT: "mounted",
|
|
1383
|
+
ANIMATION_END: "unmounted"
|
|
1384
|
+
},
|
|
1385
|
+
unmounted: {
|
|
1386
|
+
MOUNT: "mounted"
|
|
1387
|
+
}
|
|
1388
|
+
});
|
|
1389
|
+
React.useEffect(() => {
|
|
1390
|
+
const currentAnimationName = getAnimationName(stylesRef.current);
|
|
1391
|
+
prevAnimationNameRef.current = state === "mounted" ? currentAnimationName : "none";
|
|
1392
|
+
}, [state]);
|
|
1393
|
+
useLayoutEffect2(() => {
|
|
1394
|
+
const styles2 = stylesRef.current;
|
|
1395
|
+
const wasPresent = prevPresentRef.current;
|
|
1396
|
+
const hasPresentChanged = wasPresent !== present;
|
|
1397
|
+
if (hasPresentChanged) {
|
|
1398
|
+
const prevAnimationName = prevAnimationNameRef.current;
|
|
1399
|
+
const currentAnimationName = getAnimationName(styles2);
|
|
1400
|
+
if (present) {
|
|
1401
|
+
send("MOUNT");
|
|
1402
|
+
} else if (currentAnimationName === "none" || styles2?.display === "none") {
|
|
1403
|
+
send("UNMOUNT");
|
|
1404
|
+
} else {
|
|
1405
|
+
const isAnimating = prevAnimationName !== currentAnimationName;
|
|
1406
|
+
if (wasPresent && isAnimating) {
|
|
1407
|
+
send("ANIMATION_OUT");
|
|
1408
|
+
} else {
|
|
1409
|
+
send("UNMOUNT");
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
prevPresentRef.current = present;
|
|
1413
|
+
}
|
|
1414
|
+
}, [present, send]);
|
|
1415
|
+
useLayoutEffect2(() => {
|
|
1416
|
+
if (node) {
|
|
1417
|
+
let timeoutId;
|
|
1418
|
+
const ownerWindow = node.ownerDocument.defaultView ?? window;
|
|
1419
|
+
const handleAnimationEnd = (event) => {
|
|
1420
|
+
const currentAnimationName = getAnimationName(stylesRef.current);
|
|
1421
|
+
const isCurrentAnimation = currentAnimationName.includes(CSS.escape(event.animationName));
|
|
1422
|
+
if (event.target === node && isCurrentAnimation) {
|
|
1423
|
+
send("ANIMATION_END");
|
|
1424
|
+
if (!prevPresentRef.current) {
|
|
1425
|
+
const currentFillMode = node.style.animationFillMode;
|
|
1426
|
+
node.style.animationFillMode = "forwards";
|
|
1427
|
+
timeoutId = ownerWindow.setTimeout(() => {
|
|
1428
|
+
if (node.style.animationFillMode === "forwards") {
|
|
1429
|
+
node.style.animationFillMode = currentFillMode;
|
|
1430
|
+
}
|
|
1431
|
+
});
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
};
|
|
1435
|
+
const handleAnimationStart = (event) => {
|
|
1436
|
+
if (event.target === node) {
|
|
1437
|
+
prevAnimationNameRef.current = getAnimationName(stylesRef.current);
|
|
1438
|
+
}
|
|
1439
|
+
};
|
|
1440
|
+
node.addEventListener("animationstart", handleAnimationStart);
|
|
1441
|
+
node.addEventListener("animationcancel", handleAnimationEnd);
|
|
1442
|
+
node.addEventListener("animationend", handleAnimationEnd);
|
|
1443
|
+
return () => {
|
|
1444
|
+
ownerWindow.clearTimeout(timeoutId);
|
|
1445
|
+
node.removeEventListener("animationstart", handleAnimationStart);
|
|
1446
|
+
node.removeEventListener("animationcancel", handleAnimationEnd);
|
|
1447
|
+
node.removeEventListener("animationend", handleAnimationEnd);
|
|
1448
|
+
};
|
|
1449
|
+
} else {
|
|
1450
|
+
send("ANIMATION_END");
|
|
1451
|
+
}
|
|
1452
|
+
}, [node, send]);
|
|
1453
|
+
return {
|
|
1454
|
+
isPresent: ["mounted", "unmountSuspended"].includes(state),
|
|
1455
|
+
ref: React.useCallback((node2) => {
|
|
1456
|
+
stylesRef.current = node2 ? getComputedStyle(node2) : null;
|
|
1457
|
+
setNode(node2);
|
|
1458
|
+
}, [])
|
|
1459
|
+
};
|
|
1460
|
+
}
|
|
1461
|
+
function getAnimationName(styles2) {
|
|
1462
|
+
return styles2?.animationName || "none";
|
|
1463
|
+
}
|
|
1464
|
+
function getElementRef(element) {
|
|
1465
|
+
let getter = Object.getOwnPropertyDescriptor(element.props, "ref")?.get;
|
|
1466
|
+
let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
|
|
1467
|
+
if (mayWarn) {
|
|
1468
|
+
return element.ref;
|
|
1469
|
+
}
|
|
1470
|
+
getter = Object.getOwnPropertyDescriptor(element, "ref")?.get;
|
|
1471
|
+
mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
|
|
1472
|
+
if (mayWarn) {
|
|
1473
|
+
return element.props.ref;
|
|
1474
|
+
}
|
|
1475
|
+
return element.props.ref || element.ref;
|
|
1476
|
+
}
|
|
1477
|
+
var count = 0;
|
|
1478
|
+
function useFocusGuards() {
|
|
1479
|
+
React.useEffect(() => {
|
|
1480
|
+
const edgeGuards = document.querySelectorAll("[data-radix-focus-guard]");
|
|
1481
|
+
document.body.insertAdjacentElement("afterbegin", edgeGuards[0] ?? createFocusGuard());
|
|
1482
|
+
document.body.insertAdjacentElement("beforeend", edgeGuards[1] ?? createFocusGuard());
|
|
1483
|
+
count++;
|
|
1484
|
+
return () => {
|
|
1485
|
+
if (count === 1) {
|
|
1486
|
+
document.querySelectorAll("[data-radix-focus-guard]").forEach((node) => node.remove());
|
|
1487
|
+
}
|
|
1488
|
+
count--;
|
|
1489
|
+
};
|
|
1490
|
+
}, []);
|
|
1491
|
+
}
|
|
1492
|
+
function createFocusGuard() {
|
|
1493
|
+
const element = document.createElement("span");
|
|
1494
|
+
element.setAttribute("data-radix-focus-guard", "");
|
|
1495
|
+
element.tabIndex = 0;
|
|
1496
|
+
element.style.outline = "none";
|
|
1497
|
+
element.style.opacity = "0";
|
|
1498
|
+
element.style.position = "fixed";
|
|
1499
|
+
element.style.pointerEvents = "none";
|
|
1500
|
+
return element;
|
|
1501
|
+
}
|
|
1502
|
+
var __assign = function() {
|
|
1503
|
+
__assign = Object.assign || function __assign2(t) {
|
|
1504
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
1505
|
+
s = arguments[i];
|
|
1506
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
1507
|
+
}
|
|
1508
|
+
return t;
|
|
1509
|
+
};
|
|
1510
|
+
return __assign.apply(this, arguments);
|
|
1511
|
+
};
|
|
1512
|
+
function __rest(s, e) {
|
|
1513
|
+
var t = {};
|
|
1514
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
1515
|
+
t[p] = s[p];
|
|
1516
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
1517
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
1518
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
1519
|
+
t[p[i]] = s[p[i]];
|
|
1520
|
+
}
|
|
1521
|
+
return t;
|
|
1522
|
+
}
|
|
1523
|
+
function __spreadArray(to, from, pack) {
|
|
1524
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
1525
|
+
if (ar || !(i in from)) {
|
|
1526
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
1527
|
+
ar[i] = from[i];
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
1531
|
+
}
|
|
1532
|
+
typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
1533
|
+
var e = new Error(message);
|
|
1534
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
1535
|
+
};
|
|
1536
|
+
var zeroRightClassName = "right-scroll-bar-position";
|
|
1537
|
+
var fullWidthClassName = "width-before-scroll-bar";
|
|
1538
|
+
var noScrollbarsClassName = "with-scroll-bars-hidden";
|
|
1539
|
+
var removedBarSizeVariable = "--removed-body-scroll-bar-size";
|
|
1540
|
+
function assignRef(ref, value) {
|
|
1541
|
+
if (typeof ref === "function") {
|
|
1542
|
+
ref(value);
|
|
1543
|
+
} else if (ref) {
|
|
1544
|
+
ref.current = value;
|
|
1545
|
+
}
|
|
1546
|
+
return ref;
|
|
1547
|
+
}
|
|
1548
|
+
function useCallbackRef(initialValue, callback) {
|
|
1549
|
+
var ref = useState(function() {
|
|
1550
|
+
return {
|
|
1551
|
+
// value
|
|
1552
|
+
value: initialValue,
|
|
1553
|
+
// last callback
|
|
1554
|
+
callback,
|
|
1555
|
+
// "memoized" public interface
|
|
1556
|
+
facade: {
|
|
1557
|
+
get current() {
|
|
1558
|
+
return ref.value;
|
|
1559
|
+
},
|
|
1560
|
+
set current(value) {
|
|
1561
|
+
var last = ref.value;
|
|
1562
|
+
if (last !== value) {
|
|
1563
|
+
ref.value = value;
|
|
1564
|
+
ref.callback(value, last);
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
};
|
|
1569
|
+
})[0];
|
|
1570
|
+
ref.callback = callback;
|
|
1571
|
+
return ref.facade;
|
|
1572
|
+
}
|
|
1573
|
+
var useIsomorphicLayoutEffect = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect;
|
|
1574
|
+
var currentValues = /* @__PURE__ */ new WeakMap();
|
|
1575
|
+
function useMergeRefs(refs, defaultValue) {
|
|
1576
|
+
var callbackRef = useCallbackRef(null, function(newValue) {
|
|
1577
|
+
return refs.forEach(function(ref) {
|
|
1578
|
+
return assignRef(ref, newValue);
|
|
1579
|
+
});
|
|
1580
|
+
});
|
|
1581
|
+
useIsomorphicLayoutEffect(function() {
|
|
1582
|
+
var oldValue = currentValues.get(callbackRef);
|
|
1583
|
+
if (oldValue) {
|
|
1584
|
+
var prevRefs_1 = new Set(oldValue);
|
|
1585
|
+
var nextRefs_1 = new Set(refs);
|
|
1586
|
+
var current_1 = callbackRef.current;
|
|
1587
|
+
prevRefs_1.forEach(function(ref) {
|
|
1588
|
+
if (!nextRefs_1.has(ref)) {
|
|
1589
|
+
assignRef(ref, null);
|
|
1590
|
+
}
|
|
1591
|
+
});
|
|
1592
|
+
nextRefs_1.forEach(function(ref) {
|
|
1593
|
+
if (!prevRefs_1.has(ref)) {
|
|
1594
|
+
assignRef(ref, current_1);
|
|
1595
|
+
}
|
|
1596
|
+
});
|
|
1597
|
+
}
|
|
1598
|
+
currentValues.set(callbackRef, refs);
|
|
1599
|
+
}, [refs]);
|
|
1600
|
+
return callbackRef;
|
|
1601
|
+
}
|
|
1602
|
+
function ItoI(a) {
|
|
1603
|
+
return a;
|
|
1604
|
+
}
|
|
1605
|
+
function innerCreateMedium(defaults, middleware) {
|
|
1606
|
+
if (middleware === void 0) {
|
|
1607
|
+
middleware = ItoI;
|
|
1608
|
+
}
|
|
1609
|
+
var buffer = [];
|
|
1610
|
+
var assigned = false;
|
|
1611
|
+
var medium = {
|
|
1612
|
+
read: function() {
|
|
1613
|
+
if (assigned) {
|
|
1614
|
+
throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");
|
|
1615
|
+
}
|
|
1616
|
+
if (buffer.length) {
|
|
1617
|
+
return buffer[buffer.length - 1];
|
|
1618
|
+
}
|
|
1619
|
+
return defaults;
|
|
1620
|
+
},
|
|
1621
|
+
useMedium: function(data) {
|
|
1622
|
+
var item = middleware(data, assigned);
|
|
1623
|
+
buffer.push(item);
|
|
1624
|
+
return function() {
|
|
1625
|
+
buffer = buffer.filter(function(x) {
|
|
1626
|
+
return x !== item;
|
|
1627
|
+
});
|
|
1628
|
+
};
|
|
1629
|
+
},
|
|
1630
|
+
assignSyncMedium: function(cb) {
|
|
1631
|
+
assigned = true;
|
|
1632
|
+
while (buffer.length) {
|
|
1633
|
+
var cbs = buffer;
|
|
1634
|
+
buffer = [];
|
|
1635
|
+
cbs.forEach(cb);
|
|
1636
|
+
}
|
|
1637
|
+
buffer = {
|
|
1638
|
+
push: function(x) {
|
|
1639
|
+
return cb(x);
|
|
1640
|
+
},
|
|
1641
|
+
filter: function() {
|
|
1642
|
+
return buffer;
|
|
1643
|
+
}
|
|
1644
|
+
};
|
|
1645
|
+
},
|
|
1646
|
+
assignMedium: function(cb) {
|
|
1647
|
+
assigned = true;
|
|
1648
|
+
var pendingQueue = [];
|
|
1649
|
+
if (buffer.length) {
|
|
1650
|
+
var cbs = buffer;
|
|
1651
|
+
buffer = [];
|
|
1652
|
+
cbs.forEach(cb);
|
|
1653
|
+
pendingQueue = buffer;
|
|
1654
|
+
}
|
|
1655
|
+
var executeQueue = function() {
|
|
1656
|
+
var cbs2 = pendingQueue;
|
|
1657
|
+
pendingQueue = [];
|
|
1658
|
+
cbs2.forEach(cb);
|
|
1659
|
+
};
|
|
1660
|
+
var cycle = function() {
|
|
1661
|
+
return Promise.resolve().then(executeQueue);
|
|
1662
|
+
};
|
|
1663
|
+
cycle();
|
|
1664
|
+
buffer = {
|
|
1665
|
+
push: function(x) {
|
|
1666
|
+
pendingQueue.push(x);
|
|
1667
|
+
cycle();
|
|
1668
|
+
},
|
|
1669
|
+
filter: function(filter) {
|
|
1670
|
+
pendingQueue = pendingQueue.filter(filter);
|
|
1671
|
+
return buffer;
|
|
1672
|
+
}
|
|
1673
|
+
};
|
|
1674
|
+
}
|
|
1675
|
+
};
|
|
1676
|
+
return medium;
|
|
1677
|
+
}
|
|
1678
|
+
function createSidecarMedium(options) {
|
|
1679
|
+
if (options === void 0) {
|
|
1680
|
+
options = {};
|
|
1681
|
+
}
|
|
1682
|
+
var medium = innerCreateMedium(null);
|
|
1683
|
+
medium.options = __assign({ async: true, ssr: false }, options);
|
|
1684
|
+
return medium;
|
|
1685
|
+
}
|
|
1686
|
+
var SideCar$1 = function(_a) {
|
|
1687
|
+
var sideCar = _a.sideCar, rest = __rest(_a, ["sideCar"]);
|
|
1688
|
+
if (!sideCar) {
|
|
1689
|
+
throw new Error("Sidecar: please provide `sideCar` property to import the right car");
|
|
1690
|
+
}
|
|
1691
|
+
var Target = sideCar.read();
|
|
1692
|
+
if (!Target) {
|
|
1693
|
+
throw new Error("Sidecar medium not found");
|
|
1694
|
+
}
|
|
1695
|
+
return React.createElement(Target, __assign({}, rest));
|
|
1696
|
+
};
|
|
1697
|
+
SideCar$1.isSideCarExport = true;
|
|
1698
|
+
function exportSidecar(medium, exported) {
|
|
1699
|
+
medium.useMedium(exported);
|
|
1700
|
+
return SideCar$1;
|
|
1701
|
+
}
|
|
1702
|
+
var effectCar = createSidecarMedium();
|
|
1703
|
+
var nothing = function() {
|
|
1704
|
+
return;
|
|
1705
|
+
};
|
|
1706
|
+
var RemoveScroll = React.forwardRef(function(props, parentRef) {
|
|
1707
|
+
var ref = React.useRef(null);
|
|
1708
|
+
var _a = React.useState({
|
|
1709
|
+
onScrollCapture: nothing,
|
|
1710
|
+
onWheelCapture: nothing,
|
|
1711
|
+
onTouchMoveCapture: nothing
|
|
1712
|
+
}), callbacks = _a[0], setCallbacks = _a[1];
|
|
1713
|
+
var forwardProps = props.forwardProps, children = props.children, className = props.className, removeScrollBar = props.removeScrollBar, enabled = props.enabled, shards = props.shards, sideCar = props.sideCar, noRelative = props.noRelative, noIsolation = props.noIsolation, inert = props.inert, allowPinchZoom = props.allowPinchZoom, _b = props.as, Container = _b === void 0 ? "div" : _b, gapMode = props.gapMode, rest = __rest(props, ["forwardProps", "children", "className", "removeScrollBar", "enabled", "shards", "sideCar", "noRelative", "noIsolation", "inert", "allowPinchZoom", "as", "gapMode"]);
|
|
1714
|
+
var SideCar2 = sideCar;
|
|
1715
|
+
var containerRef = useMergeRefs([ref, parentRef]);
|
|
1716
|
+
var containerProps = __assign(__assign({}, rest), callbacks);
|
|
1717
|
+
return React.createElement(
|
|
1718
|
+
React.Fragment,
|
|
1719
|
+
null,
|
|
1720
|
+
enabled && React.createElement(SideCar2, { sideCar: effectCar, removeScrollBar, shards, noRelative, noIsolation, inert, setCallbacks, allowPinchZoom: !!allowPinchZoom, lockRef: ref, gapMode }),
|
|
1721
|
+
forwardProps ? React.cloneElement(React.Children.only(children), __assign(__assign({}, containerProps), { ref: containerRef })) : React.createElement(Container, __assign({}, containerProps, { className, ref: containerRef }), children)
|
|
1722
|
+
);
|
|
1723
|
+
});
|
|
1724
|
+
RemoveScroll.defaultProps = {
|
|
1725
|
+
enabled: true,
|
|
1726
|
+
removeScrollBar: true,
|
|
1727
|
+
inert: false
|
|
1728
|
+
};
|
|
1729
|
+
RemoveScroll.classNames = {
|
|
1730
|
+
fullWidth: fullWidthClassName,
|
|
1731
|
+
zeroRight: zeroRightClassName
|
|
1732
|
+
};
|
|
1733
|
+
var getNonce = function() {
|
|
1734
|
+
if (typeof __webpack_nonce__ !== "undefined") {
|
|
1735
|
+
return __webpack_nonce__;
|
|
1736
|
+
}
|
|
1737
|
+
return void 0;
|
|
1738
|
+
};
|
|
1739
|
+
function makeStyleTag() {
|
|
1740
|
+
if (!document)
|
|
1741
|
+
return null;
|
|
1742
|
+
var tag = document.createElement("style");
|
|
1743
|
+
tag.type = "text/css";
|
|
1744
|
+
var nonce = getNonce();
|
|
1745
|
+
if (nonce) {
|
|
1746
|
+
tag.setAttribute("nonce", nonce);
|
|
1747
|
+
}
|
|
1748
|
+
return tag;
|
|
1749
|
+
}
|
|
1750
|
+
function injectStyles(tag, css) {
|
|
1751
|
+
if (tag.styleSheet) {
|
|
1752
|
+
tag.styleSheet.cssText = css;
|
|
1753
|
+
} else {
|
|
1754
|
+
tag.appendChild(document.createTextNode(css));
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
function insertStyleTag(tag) {
|
|
1758
|
+
var head = document.head || document.getElementsByTagName("head")[0];
|
|
1759
|
+
head.appendChild(tag);
|
|
1760
|
+
}
|
|
1761
|
+
var stylesheetSingleton = function() {
|
|
1762
|
+
var counter = 0;
|
|
1763
|
+
var stylesheet = null;
|
|
1764
|
+
return {
|
|
1765
|
+
add: function(style) {
|
|
1766
|
+
if (counter == 0) {
|
|
1767
|
+
if (stylesheet = makeStyleTag()) {
|
|
1768
|
+
injectStyles(stylesheet, style);
|
|
1769
|
+
insertStyleTag(stylesheet);
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1772
|
+
counter++;
|
|
1773
|
+
},
|
|
1774
|
+
remove: function() {
|
|
1775
|
+
counter--;
|
|
1776
|
+
if (!counter && stylesheet) {
|
|
1777
|
+
stylesheet.parentNode && stylesheet.parentNode.removeChild(stylesheet);
|
|
1778
|
+
stylesheet = null;
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
};
|
|
1782
|
+
};
|
|
1783
|
+
var styleHookSingleton = function() {
|
|
1784
|
+
var sheet = stylesheetSingleton();
|
|
1785
|
+
return function(styles2, isDynamic) {
|
|
1786
|
+
React.useEffect(function() {
|
|
1787
|
+
sheet.add(styles2);
|
|
1788
|
+
return function() {
|
|
1789
|
+
sheet.remove();
|
|
1790
|
+
};
|
|
1791
|
+
}, [styles2 && isDynamic]);
|
|
1792
|
+
};
|
|
1793
|
+
};
|
|
1794
|
+
var styleSingleton = function() {
|
|
1795
|
+
var useStyle = styleHookSingleton();
|
|
1796
|
+
var Sheet = function(_a) {
|
|
1797
|
+
var styles2 = _a.styles, dynamic = _a.dynamic;
|
|
1798
|
+
useStyle(styles2, dynamic);
|
|
1799
|
+
return null;
|
|
1800
|
+
};
|
|
1801
|
+
return Sheet;
|
|
1802
|
+
};
|
|
1803
|
+
var zeroGap = {
|
|
1804
|
+
left: 0,
|
|
1805
|
+
top: 0,
|
|
1806
|
+
right: 0,
|
|
1807
|
+
gap: 0
|
|
1808
|
+
};
|
|
1809
|
+
var parse = function(x) {
|
|
1810
|
+
return parseInt(x || "", 10) || 0;
|
|
1811
|
+
};
|
|
1812
|
+
var getOffset = function(gapMode) {
|
|
1813
|
+
var cs = window.getComputedStyle(document.body);
|
|
1814
|
+
var left = cs[gapMode === "padding" ? "paddingLeft" : "marginLeft"];
|
|
1815
|
+
var top = cs[gapMode === "padding" ? "paddingTop" : "marginTop"];
|
|
1816
|
+
var right = cs[gapMode === "padding" ? "paddingRight" : "marginRight"];
|
|
1817
|
+
return [parse(left), parse(top), parse(right)];
|
|
1818
|
+
};
|
|
1819
|
+
var getGapWidth = function(gapMode) {
|
|
1820
|
+
if (gapMode === void 0) {
|
|
1821
|
+
gapMode = "margin";
|
|
1822
|
+
}
|
|
1823
|
+
if (typeof window === "undefined") {
|
|
1824
|
+
return zeroGap;
|
|
1825
|
+
}
|
|
1826
|
+
var offsets = getOffset(gapMode);
|
|
1827
|
+
var documentWidth = document.documentElement.clientWidth;
|
|
1828
|
+
var windowWidth = window.innerWidth;
|
|
1829
|
+
return {
|
|
1830
|
+
left: offsets[0],
|
|
1831
|
+
top: offsets[1],
|
|
1832
|
+
right: offsets[2],
|
|
1833
|
+
gap: Math.max(0, windowWidth - documentWidth + offsets[2] - offsets[0])
|
|
1834
|
+
};
|
|
1835
|
+
};
|
|
1836
|
+
var Style = styleSingleton();
|
|
1837
|
+
var lockAttribute = "data-scroll-locked";
|
|
1838
|
+
var getStyles = function(_a, allowRelative, gapMode, important) {
|
|
1839
|
+
var left = _a.left, top = _a.top, right = _a.right, gap = _a.gap;
|
|
1840
|
+
if (gapMode === void 0) {
|
|
1841
|
+
gapMode = "margin";
|
|
1842
|
+
}
|
|
1843
|
+
return "\n .".concat(noScrollbarsClassName, " {\n overflow: hidden ").concat(important, ";\n padding-right: ").concat(gap, "px ").concat(important, ";\n }\n body[").concat(lockAttribute, "] {\n overflow: hidden ").concat(important, ";\n overscroll-behavior: contain;\n ").concat([
|
|
1844
|
+
allowRelative && "position: relative ".concat(important, ";"),
|
|
1845
|
+
gapMode === "margin" && "\n padding-left: ".concat(left, "px;\n padding-top: ").concat(top, "px;\n padding-right: ").concat(right, "px;\n margin-left:0;\n margin-top:0;\n margin-right: ").concat(gap, "px ").concat(important, ";\n "),
|
|
1846
|
+
gapMode === "padding" && "padding-right: ".concat(gap, "px ").concat(important, ";")
|
|
1847
|
+
].filter(Boolean).join(""), "\n }\n \n .").concat(zeroRightClassName, " {\n right: ").concat(gap, "px ").concat(important, ";\n }\n \n .").concat(fullWidthClassName, " {\n margin-right: ").concat(gap, "px ").concat(important, ";\n }\n \n .").concat(zeroRightClassName, " .").concat(zeroRightClassName, " {\n right: 0 ").concat(important, ";\n }\n \n .").concat(fullWidthClassName, " .").concat(fullWidthClassName, " {\n margin-right: 0 ").concat(important, ";\n }\n \n body[").concat(lockAttribute, "] {\n ").concat(removedBarSizeVariable, ": ").concat(gap, "px;\n }\n");
|
|
1848
|
+
};
|
|
1849
|
+
var getCurrentUseCounter = function() {
|
|
1850
|
+
var counter = parseInt(document.body.getAttribute(lockAttribute) || "0", 10);
|
|
1851
|
+
return isFinite(counter) ? counter : 0;
|
|
1852
|
+
};
|
|
1853
|
+
var useLockAttribute = function() {
|
|
1854
|
+
React.useEffect(function() {
|
|
1855
|
+
document.body.setAttribute(lockAttribute, (getCurrentUseCounter() + 1).toString());
|
|
1856
|
+
return function() {
|
|
1857
|
+
var newCounter = getCurrentUseCounter() - 1;
|
|
1858
|
+
if (newCounter <= 0) {
|
|
1859
|
+
document.body.removeAttribute(lockAttribute);
|
|
1860
|
+
} else {
|
|
1861
|
+
document.body.setAttribute(lockAttribute, newCounter.toString());
|
|
1862
|
+
}
|
|
1863
|
+
};
|
|
1864
|
+
}, []);
|
|
1865
|
+
};
|
|
1866
|
+
var RemoveScrollBar = function(_a) {
|
|
1867
|
+
var noRelative = _a.noRelative, noImportant = _a.noImportant, _b = _a.gapMode, gapMode = _b === void 0 ? "margin" : _b;
|
|
1868
|
+
useLockAttribute();
|
|
1869
|
+
var gap = React.useMemo(function() {
|
|
1870
|
+
return getGapWidth(gapMode);
|
|
1871
|
+
}, [gapMode]);
|
|
1872
|
+
return React.createElement(Style, { styles: getStyles(gap, !noRelative, gapMode, !noImportant ? "!important" : "") });
|
|
1873
|
+
};
|
|
1874
|
+
var passiveSupported = false;
|
|
1875
|
+
if (typeof window !== "undefined") {
|
|
1876
|
+
try {
|
|
1877
|
+
var options = Object.defineProperty({}, "passive", {
|
|
1878
|
+
get: function() {
|
|
1879
|
+
passiveSupported = true;
|
|
1880
|
+
return true;
|
|
1881
|
+
}
|
|
1882
|
+
});
|
|
1883
|
+
window.addEventListener("test", options, options);
|
|
1884
|
+
window.removeEventListener("test", options, options);
|
|
1885
|
+
} catch (err) {
|
|
1886
|
+
passiveSupported = false;
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
var nonPassive = passiveSupported ? { passive: false } : false;
|
|
1890
|
+
var alwaysContainsScroll = function(node) {
|
|
1891
|
+
return node.tagName === "TEXTAREA";
|
|
1892
|
+
};
|
|
1893
|
+
var elementCanBeScrolled = function(node, overflow) {
|
|
1894
|
+
if (!(node instanceof Element)) {
|
|
1895
|
+
return false;
|
|
1896
|
+
}
|
|
1897
|
+
var styles2 = window.getComputedStyle(node);
|
|
1898
|
+
return (
|
|
1899
|
+
// not-not-scrollable
|
|
1900
|
+
styles2[overflow] !== "hidden" && // contains scroll inside self
|
|
1901
|
+
!(styles2.overflowY === styles2.overflowX && !alwaysContainsScroll(node) && styles2[overflow] === "visible")
|
|
1902
|
+
);
|
|
1903
|
+
};
|
|
1904
|
+
var elementCouldBeVScrolled = function(node) {
|
|
1905
|
+
return elementCanBeScrolled(node, "overflowY");
|
|
1906
|
+
};
|
|
1907
|
+
var elementCouldBeHScrolled = function(node) {
|
|
1908
|
+
return elementCanBeScrolled(node, "overflowX");
|
|
1909
|
+
};
|
|
1910
|
+
var locationCouldBeScrolled = function(axis, node) {
|
|
1911
|
+
var ownerDocument = node.ownerDocument;
|
|
1912
|
+
var current = node;
|
|
1913
|
+
do {
|
|
1914
|
+
if (typeof ShadowRoot !== "undefined" && current instanceof ShadowRoot) {
|
|
1915
|
+
current = current.host;
|
|
1916
|
+
}
|
|
1917
|
+
var isScrollable = elementCouldBeScrolled(axis, current);
|
|
1918
|
+
if (isScrollable) {
|
|
1919
|
+
var _a = getScrollVariables(axis, current), scrollHeight = _a[1], clientHeight = _a[2];
|
|
1920
|
+
if (scrollHeight > clientHeight) {
|
|
1921
|
+
return true;
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1924
|
+
current = current.parentNode;
|
|
1925
|
+
} while (current && current !== ownerDocument.body);
|
|
1926
|
+
return false;
|
|
1927
|
+
};
|
|
1928
|
+
var getVScrollVariables = function(_a) {
|
|
1929
|
+
var scrollTop = _a.scrollTop, scrollHeight = _a.scrollHeight, clientHeight = _a.clientHeight;
|
|
1930
|
+
return [
|
|
1931
|
+
scrollTop,
|
|
1932
|
+
scrollHeight,
|
|
1933
|
+
clientHeight
|
|
1934
|
+
];
|
|
1935
|
+
};
|
|
1936
|
+
var getHScrollVariables = function(_a) {
|
|
1937
|
+
var scrollLeft = _a.scrollLeft, scrollWidth = _a.scrollWidth, clientWidth = _a.clientWidth;
|
|
1938
|
+
return [
|
|
1939
|
+
scrollLeft,
|
|
1940
|
+
scrollWidth,
|
|
1941
|
+
clientWidth
|
|
1942
|
+
];
|
|
1943
|
+
};
|
|
1944
|
+
var elementCouldBeScrolled = function(axis, node) {
|
|
1945
|
+
return axis === "v" ? elementCouldBeVScrolled(node) : elementCouldBeHScrolled(node);
|
|
1946
|
+
};
|
|
1947
|
+
var getScrollVariables = function(axis, node) {
|
|
1948
|
+
return axis === "v" ? getVScrollVariables(node) : getHScrollVariables(node);
|
|
1949
|
+
};
|
|
1950
|
+
var getDirectionFactor = function(axis, direction) {
|
|
1951
|
+
return axis === "h" && direction === "rtl" ? -1 : 1;
|
|
1952
|
+
};
|
|
1953
|
+
var handleScroll = function(axis, endTarget, event, sourceDelta, noOverscroll) {
|
|
1954
|
+
var directionFactor = getDirectionFactor(axis, window.getComputedStyle(endTarget).direction);
|
|
1955
|
+
var delta = directionFactor * sourceDelta;
|
|
1956
|
+
var target = event.target;
|
|
1957
|
+
var targetInLock = endTarget.contains(target);
|
|
1958
|
+
var shouldCancelScroll = false;
|
|
1959
|
+
var isDeltaPositive = delta > 0;
|
|
1960
|
+
var availableScroll = 0;
|
|
1961
|
+
var availableScrollTop = 0;
|
|
1962
|
+
do {
|
|
1963
|
+
if (!target) {
|
|
1964
|
+
break;
|
|
1965
|
+
}
|
|
1966
|
+
var _a = getScrollVariables(axis, target), position = _a[0], scroll_1 = _a[1], capacity = _a[2];
|
|
1967
|
+
var elementScroll = scroll_1 - capacity - directionFactor * position;
|
|
1968
|
+
if (position || elementScroll) {
|
|
1969
|
+
if (elementCouldBeScrolled(axis, target)) {
|
|
1970
|
+
availableScroll += elementScroll;
|
|
1971
|
+
availableScrollTop += position;
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
var parent_1 = target.parentNode;
|
|
1975
|
+
target = parent_1 && parent_1.nodeType === Node.DOCUMENT_FRAGMENT_NODE ? parent_1.host : parent_1;
|
|
1976
|
+
} while (
|
|
1977
|
+
// portaled content
|
|
1978
|
+
!targetInLock && target !== document.body || // self content
|
|
1979
|
+
targetInLock && (endTarget.contains(target) || endTarget === target)
|
|
1980
|
+
);
|
|
1981
|
+
if (isDeltaPositive && (Math.abs(availableScroll) < 1 || false)) {
|
|
1982
|
+
shouldCancelScroll = true;
|
|
1983
|
+
} else if (!isDeltaPositive && (Math.abs(availableScrollTop) < 1 || false)) {
|
|
1984
|
+
shouldCancelScroll = true;
|
|
1985
|
+
}
|
|
1986
|
+
return shouldCancelScroll;
|
|
1987
|
+
};
|
|
1988
|
+
var getTouchXY = function(event) {
|
|
1989
|
+
return "changedTouches" in event ? [event.changedTouches[0].clientX, event.changedTouches[0].clientY] : [0, 0];
|
|
1990
|
+
};
|
|
1991
|
+
var getDeltaXY = function(event) {
|
|
1992
|
+
return [event.deltaX, event.deltaY];
|
|
1993
|
+
};
|
|
1994
|
+
var extractRef = function(ref) {
|
|
1995
|
+
return ref && "current" in ref ? ref.current : ref;
|
|
1996
|
+
};
|
|
1997
|
+
var deltaCompare = function(x, y) {
|
|
1998
|
+
return x[0] === y[0] && x[1] === y[1];
|
|
1999
|
+
};
|
|
2000
|
+
var generateStyle = function(id) {
|
|
2001
|
+
return "\n .block-interactivity-".concat(id, " {pointer-events: none;}\n .allow-interactivity-").concat(id, " {pointer-events: all;}\n");
|
|
2002
|
+
};
|
|
2003
|
+
var idCounter = 0;
|
|
2004
|
+
var lockStack = [];
|
|
2005
|
+
function RemoveScrollSideCar(props) {
|
|
2006
|
+
var shouldPreventQueue = React.useRef([]);
|
|
2007
|
+
var touchStartRef = React.useRef([0, 0]);
|
|
2008
|
+
var activeAxis = React.useRef();
|
|
2009
|
+
var id = React.useState(idCounter++)[0];
|
|
2010
|
+
var Style2 = React.useState(styleSingleton)[0];
|
|
2011
|
+
var lastProps = React.useRef(props);
|
|
2012
|
+
React.useEffect(function() {
|
|
2013
|
+
lastProps.current = props;
|
|
2014
|
+
}, [props]);
|
|
2015
|
+
React.useEffect(function() {
|
|
2016
|
+
if (props.inert) {
|
|
2017
|
+
document.body.classList.add("block-interactivity-".concat(id));
|
|
2018
|
+
var allow_1 = __spreadArray([props.lockRef.current], (props.shards || []).map(extractRef), true).filter(Boolean);
|
|
2019
|
+
allow_1.forEach(function(el) {
|
|
2020
|
+
return el.classList.add("allow-interactivity-".concat(id));
|
|
2021
|
+
});
|
|
2022
|
+
return function() {
|
|
2023
|
+
document.body.classList.remove("block-interactivity-".concat(id));
|
|
2024
|
+
allow_1.forEach(function(el) {
|
|
2025
|
+
return el.classList.remove("allow-interactivity-".concat(id));
|
|
2026
|
+
});
|
|
2027
|
+
};
|
|
2028
|
+
}
|
|
2029
|
+
return;
|
|
2030
|
+
}, [props.inert, props.lockRef.current, props.shards]);
|
|
2031
|
+
var shouldCancelEvent = React.useCallback(function(event, parent) {
|
|
2032
|
+
if ("touches" in event && event.touches.length === 2 || event.type === "wheel" && event.ctrlKey) {
|
|
2033
|
+
return !lastProps.current.allowPinchZoom;
|
|
2034
|
+
}
|
|
2035
|
+
var touch = getTouchXY(event);
|
|
2036
|
+
var touchStart = touchStartRef.current;
|
|
2037
|
+
var deltaX = "deltaX" in event ? event.deltaX : touchStart[0] - touch[0];
|
|
2038
|
+
var deltaY = "deltaY" in event ? event.deltaY : touchStart[1] - touch[1];
|
|
2039
|
+
var currentAxis;
|
|
2040
|
+
var target = event.target;
|
|
2041
|
+
var moveDirection = Math.abs(deltaX) > Math.abs(deltaY) ? "h" : "v";
|
|
2042
|
+
if ("touches" in event && moveDirection === "h" && target.type === "range") {
|
|
2043
|
+
return false;
|
|
2044
|
+
}
|
|
2045
|
+
var selection = window.getSelection();
|
|
2046
|
+
var anchorNode = selection && selection.anchorNode;
|
|
2047
|
+
var isTouchingSelection = anchorNode ? anchorNode === target || anchorNode.contains(target) : false;
|
|
2048
|
+
if (isTouchingSelection) {
|
|
2049
|
+
return false;
|
|
2050
|
+
}
|
|
2051
|
+
var canBeScrolledInMainDirection = locationCouldBeScrolled(moveDirection, target);
|
|
2052
|
+
if (!canBeScrolledInMainDirection) {
|
|
2053
|
+
return true;
|
|
2054
|
+
}
|
|
2055
|
+
if (canBeScrolledInMainDirection) {
|
|
2056
|
+
currentAxis = moveDirection;
|
|
2057
|
+
} else {
|
|
2058
|
+
currentAxis = moveDirection === "v" ? "h" : "v";
|
|
2059
|
+
canBeScrolledInMainDirection = locationCouldBeScrolled(moveDirection, target);
|
|
2060
|
+
}
|
|
2061
|
+
if (!canBeScrolledInMainDirection) {
|
|
2062
|
+
return false;
|
|
2063
|
+
}
|
|
2064
|
+
if (!activeAxis.current && "changedTouches" in event && (deltaX || deltaY)) {
|
|
2065
|
+
activeAxis.current = currentAxis;
|
|
2066
|
+
}
|
|
2067
|
+
if (!currentAxis) {
|
|
2068
|
+
return true;
|
|
2069
|
+
}
|
|
2070
|
+
var cancelingAxis = activeAxis.current || currentAxis;
|
|
2071
|
+
return handleScroll(cancelingAxis, parent, event, cancelingAxis === "h" ? deltaX : deltaY);
|
|
2072
|
+
}, []);
|
|
2073
|
+
var shouldPrevent = React.useCallback(function(_event) {
|
|
2074
|
+
var event = _event;
|
|
2075
|
+
if (!lockStack.length || lockStack[lockStack.length - 1] !== Style2) {
|
|
2076
|
+
return;
|
|
2077
|
+
}
|
|
2078
|
+
var delta = "deltaY" in event ? getDeltaXY(event) : getTouchXY(event);
|
|
2079
|
+
var sourceEvent = shouldPreventQueue.current.filter(function(e) {
|
|
2080
|
+
return e.name === event.type && (e.target === event.target || event.target === e.shadowParent) && deltaCompare(e.delta, delta);
|
|
2081
|
+
})[0];
|
|
2082
|
+
if (sourceEvent && sourceEvent.should) {
|
|
2083
|
+
if (event.cancelable) {
|
|
2084
|
+
event.preventDefault();
|
|
2085
|
+
}
|
|
2086
|
+
return;
|
|
2087
|
+
}
|
|
2088
|
+
if (!sourceEvent) {
|
|
2089
|
+
var shardNodes = (lastProps.current.shards || []).map(extractRef).filter(Boolean).filter(function(node) {
|
|
2090
|
+
return node.contains(event.target);
|
|
2091
|
+
});
|
|
2092
|
+
var shouldStop = shardNodes.length > 0 ? shouldCancelEvent(event, shardNodes[0]) : !lastProps.current.noIsolation;
|
|
2093
|
+
if (shouldStop) {
|
|
2094
|
+
if (event.cancelable) {
|
|
2095
|
+
event.preventDefault();
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2098
|
+
}
|
|
2099
|
+
}, []);
|
|
2100
|
+
var shouldCancel = React.useCallback(function(name, delta, target, should) {
|
|
2101
|
+
var event = { name, delta, target, should, shadowParent: getOutermostShadowParent(target) };
|
|
2102
|
+
shouldPreventQueue.current.push(event);
|
|
2103
|
+
setTimeout(function() {
|
|
2104
|
+
shouldPreventQueue.current = shouldPreventQueue.current.filter(function(e) {
|
|
2105
|
+
return e !== event;
|
|
2106
|
+
});
|
|
2107
|
+
}, 1);
|
|
2108
|
+
}, []);
|
|
2109
|
+
var scrollTouchStart = React.useCallback(function(event) {
|
|
2110
|
+
touchStartRef.current = getTouchXY(event);
|
|
2111
|
+
activeAxis.current = void 0;
|
|
2112
|
+
}, []);
|
|
2113
|
+
var scrollWheel = React.useCallback(function(event) {
|
|
2114
|
+
shouldCancel(event.type, getDeltaXY(event), event.target, shouldCancelEvent(event, props.lockRef.current));
|
|
2115
|
+
}, []);
|
|
2116
|
+
var scrollTouchMove = React.useCallback(function(event) {
|
|
2117
|
+
shouldCancel(event.type, getTouchXY(event), event.target, shouldCancelEvent(event, props.lockRef.current));
|
|
2118
|
+
}, []);
|
|
2119
|
+
React.useEffect(function() {
|
|
2120
|
+
lockStack.push(Style2);
|
|
2121
|
+
props.setCallbacks({
|
|
2122
|
+
onScrollCapture: scrollWheel,
|
|
2123
|
+
onWheelCapture: scrollWheel,
|
|
2124
|
+
onTouchMoveCapture: scrollTouchMove
|
|
2125
|
+
});
|
|
2126
|
+
document.addEventListener("wheel", shouldPrevent, nonPassive);
|
|
2127
|
+
document.addEventListener("touchmove", shouldPrevent, nonPassive);
|
|
2128
|
+
document.addEventListener("touchstart", scrollTouchStart, nonPassive);
|
|
2129
|
+
return function() {
|
|
2130
|
+
lockStack = lockStack.filter(function(inst) {
|
|
2131
|
+
return inst !== Style2;
|
|
2132
|
+
});
|
|
2133
|
+
document.removeEventListener("wheel", shouldPrevent, nonPassive);
|
|
2134
|
+
document.removeEventListener("touchmove", shouldPrevent, nonPassive);
|
|
2135
|
+
document.removeEventListener("touchstart", scrollTouchStart, nonPassive);
|
|
2136
|
+
};
|
|
2137
|
+
}, []);
|
|
2138
|
+
var removeScrollBar = props.removeScrollBar, inert = props.inert;
|
|
2139
|
+
return React.createElement(
|
|
2140
|
+
React.Fragment,
|
|
2141
|
+
null,
|
|
2142
|
+
inert ? React.createElement(Style2, { styles: generateStyle(id) }) : null,
|
|
2143
|
+
removeScrollBar ? React.createElement(RemoveScrollBar, { noRelative: props.noRelative, gapMode: props.gapMode }) : null
|
|
2144
|
+
);
|
|
2145
|
+
}
|
|
2146
|
+
function getOutermostShadowParent(node) {
|
|
2147
|
+
var shadowParent = null;
|
|
2148
|
+
while (node !== null) {
|
|
2149
|
+
if (node instanceof ShadowRoot) {
|
|
2150
|
+
shadowParent = node.host;
|
|
2151
|
+
node = node.host;
|
|
2152
|
+
}
|
|
2153
|
+
node = node.parentNode;
|
|
2154
|
+
}
|
|
2155
|
+
return shadowParent;
|
|
2156
|
+
}
|
|
2157
|
+
const SideCar = exportSidecar(effectCar, RemoveScrollSideCar);
|
|
2158
|
+
var ReactRemoveScroll = React.forwardRef(function(props, ref) {
|
|
2159
|
+
return React.createElement(RemoveScroll, __assign({}, props, { ref, sideCar: SideCar }));
|
|
2160
|
+
});
|
|
2161
|
+
ReactRemoveScroll.classNames = RemoveScroll.classNames;
|
|
2162
|
+
var getDefaultParent = function(originalTarget) {
|
|
2163
|
+
if (typeof document === "undefined") {
|
|
2164
|
+
return null;
|
|
2165
|
+
}
|
|
2166
|
+
var sampleTarget = Array.isArray(originalTarget) ? originalTarget[0] : originalTarget;
|
|
2167
|
+
return sampleTarget.ownerDocument.body;
|
|
2168
|
+
};
|
|
2169
|
+
var counterMap = /* @__PURE__ */ new WeakMap();
|
|
2170
|
+
var uncontrolledNodes = /* @__PURE__ */ new WeakMap();
|
|
2171
|
+
var markerMap = {};
|
|
2172
|
+
var lockCount = 0;
|
|
2173
|
+
var unwrapHost = function(node) {
|
|
2174
|
+
return node && (node.host || unwrapHost(node.parentNode));
|
|
2175
|
+
};
|
|
2176
|
+
var correctTargets = function(parent, targets) {
|
|
2177
|
+
return targets.map(function(target) {
|
|
2178
|
+
if (parent.contains(target)) {
|
|
2179
|
+
return target;
|
|
2180
|
+
}
|
|
2181
|
+
var correctedTarget = unwrapHost(target);
|
|
2182
|
+
if (correctedTarget && parent.contains(correctedTarget)) {
|
|
2183
|
+
return correctedTarget;
|
|
2184
|
+
}
|
|
2185
|
+
console.error("aria-hidden", target, "in not contained inside", parent, ". Doing nothing");
|
|
2186
|
+
return null;
|
|
2187
|
+
}).filter(function(x) {
|
|
2188
|
+
return Boolean(x);
|
|
2189
|
+
});
|
|
2190
|
+
};
|
|
2191
|
+
var applyAttributeToOthers = function(originalTarget, parentNode, markerName, controlAttribute) {
|
|
2192
|
+
var targets = correctTargets(parentNode, Array.isArray(originalTarget) ? originalTarget : [originalTarget]);
|
|
2193
|
+
if (!markerMap[markerName]) {
|
|
2194
|
+
markerMap[markerName] = /* @__PURE__ */ new WeakMap();
|
|
2195
|
+
}
|
|
2196
|
+
var markerCounter = markerMap[markerName];
|
|
2197
|
+
var hiddenNodes = [];
|
|
2198
|
+
var elementsToKeep = /* @__PURE__ */ new Set();
|
|
2199
|
+
var elementsToStop = new Set(targets);
|
|
2200
|
+
var keep = function(el) {
|
|
2201
|
+
if (!el || elementsToKeep.has(el)) {
|
|
2202
|
+
return;
|
|
2203
|
+
}
|
|
2204
|
+
elementsToKeep.add(el);
|
|
2205
|
+
keep(el.parentNode);
|
|
2206
|
+
};
|
|
2207
|
+
targets.forEach(keep);
|
|
2208
|
+
var deep = function(parent) {
|
|
2209
|
+
if (!parent || elementsToStop.has(parent)) {
|
|
2210
|
+
return;
|
|
2211
|
+
}
|
|
2212
|
+
Array.prototype.forEach.call(parent.children, function(node) {
|
|
2213
|
+
if (elementsToKeep.has(node)) {
|
|
2214
|
+
deep(node);
|
|
2215
|
+
} else {
|
|
2216
|
+
try {
|
|
2217
|
+
var attr = node.getAttribute(controlAttribute);
|
|
2218
|
+
var alreadyHidden = attr !== null && attr !== "false";
|
|
2219
|
+
var counterValue = (counterMap.get(node) || 0) + 1;
|
|
2220
|
+
var markerValue = (markerCounter.get(node) || 0) + 1;
|
|
2221
|
+
counterMap.set(node, counterValue);
|
|
2222
|
+
markerCounter.set(node, markerValue);
|
|
2223
|
+
hiddenNodes.push(node);
|
|
2224
|
+
if (counterValue === 1 && alreadyHidden) {
|
|
2225
|
+
uncontrolledNodes.set(node, true);
|
|
2226
|
+
}
|
|
2227
|
+
if (markerValue === 1) {
|
|
2228
|
+
node.setAttribute(markerName, "true");
|
|
2229
|
+
}
|
|
2230
|
+
if (!alreadyHidden) {
|
|
2231
|
+
node.setAttribute(controlAttribute, "true");
|
|
2232
|
+
}
|
|
2233
|
+
} catch (e) {
|
|
2234
|
+
console.error("aria-hidden: cannot operate on ", node, e);
|
|
2235
|
+
}
|
|
2236
|
+
}
|
|
2237
|
+
});
|
|
2238
|
+
};
|
|
2239
|
+
deep(parentNode);
|
|
2240
|
+
elementsToKeep.clear();
|
|
2241
|
+
lockCount++;
|
|
2242
|
+
return function() {
|
|
2243
|
+
hiddenNodes.forEach(function(node) {
|
|
2244
|
+
var counterValue = counterMap.get(node) - 1;
|
|
2245
|
+
var markerValue = markerCounter.get(node) - 1;
|
|
2246
|
+
counterMap.set(node, counterValue);
|
|
2247
|
+
markerCounter.set(node, markerValue);
|
|
2248
|
+
if (!counterValue) {
|
|
2249
|
+
if (!uncontrolledNodes.has(node)) {
|
|
2250
|
+
node.removeAttribute(controlAttribute);
|
|
2251
|
+
}
|
|
2252
|
+
uncontrolledNodes.delete(node);
|
|
2253
|
+
}
|
|
2254
|
+
if (!markerValue) {
|
|
2255
|
+
node.removeAttribute(markerName);
|
|
2256
|
+
}
|
|
2257
|
+
});
|
|
2258
|
+
lockCount--;
|
|
2259
|
+
if (!lockCount) {
|
|
2260
|
+
counterMap = /* @__PURE__ */ new WeakMap();
|
|
2261
|
+
counterMap = /* @__PURE__ */ new WeakMap();
|
|
2262
|
+
uncontrolledNodes = /* @__PURE__ */ new WeakMap();
|
|
2263
|
+
markerMap = {};
|
|
2264
|
+
}
|
|
2265
|
+
};
|
|
2266
|
+
};
|
|
2267
|
+
var hideOthers = function(originalTarget, parentNode, markerName) {
|
|
2268
|
+
if (markerName === void 0) {
|
|
2269
|
+
markerName = "data-aria-hidden";
|
|
2270
|
+
}
|
|
2271
|
+
var targets = Array.from(Array.isArray(originalTarget) ? originalTarget : [originalTarget]);
|
|
2272
|
+
var activeParentNode = getDefaultParent(originalTarget);
|
|
2273
|
+
if (!activeParentNode) {
|
|
2274
|
+
return function() {
|
|
2275
|
+
return null;
|
|
2276
|
+
};
|
|
2277
|
+
}
|
|
2278
|
+
targets.push.apply(targets, Array.from(activeParentNode.querySelectorAll("[aria-live], script")));
|
|
2279
|
+
return applyAttributeToOthers(targets, activeParentNode, markerName, "aria-hidden");
|
|
2280
|
+
};
|
|
2281
|
+
var DIALOG_NAME = "Dialog";
|
|
2282
|
+
var [createDialogContext] = createContextScope(DIALOG_NAME);
|
|
2283
|
+
var [DialogProvider, useDialogContext] = createDialogContext(DIALOG_NAME);
|
|
2284
|
+
var Dialog = (props) => {
|
|
2285
|
+
const {
|
|
2286
|
+
__scopeDialog,
|
|
2287
|
+
children,
|
|
2288
|
+
open: openProp,
|
|
2289
|
+
defaultOpen,
|
|
2290
|
+
onOpenChange,
|
|
2291
|
+
modal = true
|
|
2292
|
+
} = props;
|
|
2293
|
+
const triggerRef = React.useRef(null);
|
|
2294
|
+
const contentRef = React.useRef(null);
|
|
2295
|
+
const [open, setOpen] = useControllableState({
|
|
2296
|
+
prop: openProp,
|
|
2297
|
+
defaultProp: defaultOpen ?? false,
|
|
2298
|
+
onChange: onOpenChange,
|
|
2299
|
+
caller: DIALOG_NAME
|
|
2300
|
+
});
|
|
2301
|
+
return /* @__PURE__ */ jsx(
|
|
2302
|
+
DialogProvider,
|
|
2303
|
+
{
|
|
2304
|
+
scope: __scopeDialog,
|
|
2305
|
+
triggerRef,
|
|
2306
|
+
contentRef,
|
|
2307
|
+
contentId: useId(),
|
|
2308
|
+
titleId: useId(),
|
|
2309
|
+
descriptionId: useId(),
|
|
2310
|
+
open,
|
|
2311
|
+
onOpenChange: setOpen,
|
|
2312
|
+
onOpenToggle: React.useCallback(() => setOpen((prevOpen) => !prevOpen), [setOpen]),
|
|
2313
|
+
modal,
|
|
2314
|
+
children
|
|
2315
|
+
}
|
|
2316
|
+
);
|
|
2317
|
+
};
|
|
2318
|
+
Dialog.displayName = DIALOG_NAME;
|
|
2319
|
+
var TRIGGER_NAME = "DialogTrigger";
|
|
2320
|
+
var DialogTrigger = React.forwardRef(
|
|
2321
|
+
(props, forwardedRef) => {
|
|
2322
|
+
const { __scopeDialog, ...triggerProps } = props;
|
|
2323
|
+
const context = useDialogContext(TRIGGER_NAME, __scopeDialog);
|
|
2324
|
+
const composedTriggerRef = useComposedRefs(forwardedRef, context.triggerRef);
|
|
2325
|
+
return /* @__PURE__ */ jsx(
|
|
2326
|
+
Primitive.button,
|
|
2327
|
+
{
|
|
2328
|
+
type: "button",
|
|
2329
|
+
"aria-haspopup": "dialog",
|
|
2330
|
+
"aria-expanded": context.open,
|
|
2331
|
+
"aria-controls": context.contentId,
|
|
2332
|
+
"data-state": getState(context.open),
|
|
2333
|
+
...triggerProps,
|
|
2334
|
+
ref: composedTriggerRef,
|
|
2335
|
+
onClick: composeEventHandlers(props.onClick, context.onOpenToggle)
|
|
2336
|
+
}
|
|
2337
|
+
);
|
|
2338
|
+
}
|
|
2339
|
+
);
|
|
2340
|
+
DialogTrigger.displayName = TRIGGER_NAME;
|
|
2341
|
+
var PORTAL_NAME = "DialogPortal";
|
|
2342
|
+
var [PortalProvider, usePortalContext] = createDialogContext(PORTAL_NAME, {
|
|
2343
|
+
forceMount: void 0
|
|
2344
|
+
});
|
|
2345
|
+
var DialogPortal = (props) => {
|
|
2346
|
+
const { __scopeDialog, forceMount, children, container } = props;
|
|
2347
|
+
const context = useDialogContext(PORTAL_NAME, __scopeDialog);
|
|
2348
|
+
return /* @__PURE__ */ jsx(PortalProvider, { scope: __scopeDialog, forceMount, children: React.Children.map(children, (child) => /* @__PURE__ */ jsx(Presence, { present: forceMount || context.open, children: /* @__PURE__ */ jsx(Portal$1, { asChild: true, container, children: child }) })) });
|
|
2349
|
+
};
|
|
2350
|
+
DialogPortal.displayName = PORTAL_NAME;
|
|
2351
|
+
var OVERLAY_NAME = "DialogOverlay";
|
|
2352
|
+
var DialogOverlay = React.forwardRef(
|
|
2353
|
+
(props, forwardedRef) => {
|
|
2354
|
+
const portalContext = usePortalContext(OVERLAY_NAME, props.__scopeDialog);
|
|
2355
|
+
const { forceMount = portalContext.forceMount, ...overlayProps } = props;
|
|
2356
|
+
const context = useDialogContext(OVERLAY_NAME, props.__scopeDialog);
|
|
2357
|
+
return context.modal ? /* @__PURE__ */ jsx(Presence, { present: forceMount || context.open, children: /* @__PURE__ */ jsx(DialogOverlayImpl, { ...overlayProps, ref: forwardedRef }) }) : null;
|
|
2358
|
+
}
|
|
2359
|
+
);
|
|
2360
|
+
DialogOverlay.displayName = OVERLAY_NAME;
|
|
2361
|
+
var Slot = /* @__PURE__ */ createSlot("DialogOverlay.RemoveScroll");
|
|
2362
|
+
var DialogOverlayImpl = React.forwardRef(
|
|
2363
|
+
(props, forwardedRef) => {
|
|
2364
|
+
const { __scopeDialog, ...overlayProps } = props;
|
|
2365
|
+
const context = useDialogContext(OVERLAY_NAME, __scopeDialog);
|
|
2366
|
+
return (
|
|
2367
|
+
// Make sure `Content` is scrollable even when it doesn't live inside `RemoveScroll`
|
|
2368
|
+
// ie. when `Overlay` and `Content` are siblings
|
|
2369
|
+
/* @__PURE__ */ jsx(ReactRemoveScroll, { as: Slot, allowPinchZoom: true, shards: [context.contentRef], children: /* @__PURE__ */ jsx(
|
|
2370
|
+
Primitive.div,
|
|
2371
|
+
{
|
|
2372
|
+
"data-state": getState(context.open),
|
|
2373
|
+
...overlayProps,
|
|
2374
|
+
ref: forwardedRef,
|
|
2375
|
+
style: { pointerEvents: "auto", ...overlayProps.style }
|
|
2376
|
+
}
|
|
2377
|
+
) })
|
|
2378
|
+
);
|
|
2379
|
+
}
|
|
2380
|
+
);
|
|
2381
|
+
var CONTENT_NAME = "DialogContent";
|
|
2382
|
+
var DialogContent = React.forwardRef(
|
|
2383
|
+
(props, forwardedRef) => {
|
|
2384
|
+
const portalContext = usePortalContext(CONTENT_NAME, props.__scopeDialog);
|
|
2385
|
+
const { forceMount = portalContext.forceMount, ...contentProps } = props;
|
|
2386
|
+
const context = useDialogContext(CONTENT_NAME, props.__scopeDialog);
|
|
2387
|
+
return /* @__PURE__ */ jsx(Presence, { present: forceMount || context.open, children: context.modal ? /* @__PURE__ */ jsx(DialogContentModal, { ...contentProps, ref: forwardedRef }) : /* @__PURE__ */ jsx(DialogContentNonModal, { ...contentProps, ref: forwardedRef }) });
|
|
2388
|
+
}
|
|
2389
|
+
);
|
|
2390
|
+
DialogContent.displayName = CONTENT_NAME;
|
|
2391
|
+
var DialogContentModal = React.forwardRef(
|
|
2392
|
+
(props, forwardedRef) => {
|
|
2393
|
+
const context = useDialogContext(CONTENT_NAME, props.__scopeDialog);
|
|
2394
|
+
const contentRef = React.useRef(null);
|
|
2395
|
+
const composedRefs = useComposedRefs(forwardedRef, context.contentRef, contentRef);
|
|
2396
|
+
React.useEffect(() => {
|
|
2397
|
+
const content = contentRef.current;
|
|
2398
|
+
if (content) return hideOthers(content);
|
|
2399
|
+
}, []);
|
|
2400
|
+
return /* @__PURE__ */ jsx(
|
|
2401
|
+
DialogContentImpl,
|
|
2402
|
+
{
|
|
2403
|
+
...props,
|
|
2404
|
+
ref: composedRefs,
|
|
2405
|
+
trapFocus: context.open,
|
|
2406
|
+
disableOutsidePointerEvents: true,
|
|
2407
|
+
onCloseAutoFocus: composeEventHandlers(props.onCloseAutoFocus, (event) => {
|
|
2408
|
+
event.preventDefault();
|
|
2409
|
+
context.triggerRef.current?.focus();
|
|
2410
|
+
}),
|
|
2411
|
+
onPointerDownOutside: composeEventHandlers(props.onPointerDownOutside, (event) => {
|
|
2412
|
+
const originalEvent = event.detail.originalEvent;
|
|
2413
|
+
const ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;
|
|
2414
|
+
const isRightClick = originalEvent.button === 2 || ctrlLeftClick;
|
|
2415
|
+
if (isRightClick) event.preventDefault();
|
|
2416
|
+
}),
|
|
2417
|
+
onFocusOutside: composeEventHandlers(
|
|
2418
|
+
props.onFocusOutside,
|
|
2419
|
+
(event) => event.preventDefault()
|
|
2420
|
+
)
|
|
2421
|
+
}
|
|
2422
|
+
);
|
|
2423
|
+
}
|
|
2424
|
+
);
|
|
2425
|
+
var DialogContentNonModal = React.forwardRef(
|
|
2426
|
+
(props, forwardedRef) => {
|
|
2427
|
+
const context = useDialogContext(CONTENT_NAME, props.__scopeDialog);
|
|
2428
|
+
const hasInteractedOutsideRef = React.useRef(false);
|
|
2429
|
+
const hasPointerDownOutsideRef = React.useRef(false);
|
|
2430
|
+
return /* @__PURE__ */ jsx(
|
|
2431
|
+
DialogContentImpl,
|
|
2432
|
+
{
|
|
2433
|
+
...props,
|
|
2434
|
+
ref: forwardedRef,
|
|
2435
|
+
trapFocus: false,
|
|
2436
|
+
disableOutsidePointerEvents: false,
|
|
2437
|
+
onCloseAutoFocus: (event) => {
|
|
2438
|
+
props.onCloseAutoFocus?.(event);
|
|
2439
|
+
if (!event.defaultPrevented) {
|
|
2440
|
+
if (!hasInteractedOutsideRef.current) context.triggerRef.current?.focus();
|
|
2441
|
+
event.preventDefault();
|
|
2442
|
+
}
|
|
2443
|
+
hasInteractedOutsideRef.current = false;
|
|
2444
|
+
hasPointerDownOutsideRef.current = false;
|
|
2445
|
+
},
|
|
2446
|
+
onInteractOutside: (event) => {
|
|
2447
|
+
props.onInteractOutside?.(event);
|
|
2448
|
+
if (!event.defaultPrevented) {
|
|
2449
|
+
hasInteractedOutsideRef.current = true;
|
|
2450
|
+
if (event.detail.originalEvent.type === "pointerdown") {
|
|
2451
|
+
hasPointerDownOutsideRef.current = true;
|
|
2452
|
+
}
|
|
2453
|
+
}
|
|
2454
|
+
const target = event.target;
|
|
2455
|
+
const targetIsTrigger = context.triggerRef.current?.contains(target);
|
|
2456
|
+
if (targetIsTrigger) event.preventDefault();
|
|
2457
|
+
if (event.detail.originalEvent.type === "focusin" && hasPointerDownOutsideRef.current) {
|
|
2458
|
+
event.preventDefault();
|
|
2459
|
+
}
|
|
2460
|
+
}
|
|
2461
|
+
}
|
|
2462
|
+
);
|
|
2463
|
+
}
|
|
2464
|
+
);
|
|
2465
|
+
var DialogContentImpl = React.forwardRef(
|
|
2466
|
+
(props, forwardedRef) => {
|
|
2467
|
+
const { __scopeDialog, trapFocus, onOpenAutoFocus, onCloseAutoFocus, ...contentProps } = props;
|
|
2468
|
+
const context = useDialogContext(CONTENT_NAME, __scopeDialog);
|
|
2469
|
+
const contentRef = React.useRef(null);
|
|
2470
|
+
const composedRefs = useComposedRefs(forwardedRef, contentRef);
|
|
2471
|
+
useFocusGuards();
|
|
2472
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2473
|
+
/* @__PURE__ */ jsx(
|
|
2474
|
+
FocusScope,
|
|
2475
|
+
{
|
|
2476
|
+
asChild: true,
|
|
2477
|
+
loop: true,
|
|
2478
|
+
trapped: trapFocus,
|
|
2479
|
+
onMountAutoFocus: onOpenAutoFocus,
|
|
2480
|
+
onUnmountAutoFocus: onCloseAutoFocus,
|
|
2481
|
+
children: /* @__PURE__ */ jsx(
|
|
2482
|
+
DismissableLayer,
|
|
2483
|
+
{
|
|
2484
|
+
role: "dialog",
|
|
2485
|
+
id: context.contentId,
|
|
2486
|
+
"aria-describedby": context.descriptionId,
|
|
2487
|
+
"aria-labelledby": context.titleId,
|
|
2488
|
+
"data-state": getState(context.open),
|
|
2489
|
+
...contentProps,
|
|
2490
|
+
ref: composedRefs,
|
|
2491
|
+
onDismiss: () => context.onOpenChange(false)
|
|
2492
|
+
}
|
|
2493
|
+
)
|
|
2494
|
+
}
|
|
2495
|
+
),
|
|
2496
|
+
/* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2497
|
+
/* @__PURE__ */ jsx(TitleWarning, { titleId: context.titleId }),
|
|
2498
|
+
/* @__PURE__ */ jsx(DescriptionWarning, { contentRef, descriptionId: context.descriptionId })
|
|
2499
|
+
] })
|
|
2500
|
+
] });
|
|
2501
|
+
}
|
|
2502
|
+
);
|
|
2503
|
+
var TITLE_NAME = "DialogTitle";
|
|
2504
|
+
var DialogTitle = React.forwardRef(
|
|
2505
|
+
(props, forwardedRef) => {
|
|
2506
|
+
const { __scopeDialog, ...titleProps } = props;
|
|
2507
|
+
const context = useDialogContext(TITLE_NAME, __scopeDialog);
|
|
2508
|
+
return /* @__PURE__ */ jsx(Primitive.h2, { id: context.titleId, ...titleProps, ref: forwardedRef });
|
|
2509
|
+
}
|
|
2510
|
+
);
|
|
2511
|
+
DialogTitle.displayName = TITLE_NAME;
|
|
2512
|
+
var DESCRIPTION_NAME = "DialogDescription";
|
|
2513
|
+
var DialogDescription = React.forwardRef(
|
|
2514
|
+
(props, forwardedRef) => {
|
|
2515
|
+
const { __scopeDialog, ...descriptionProps } = props;
|
|
2516
|
+
const context = useDialogContext(DESCRIPTION_NAME, __scopeDialog);
|
|
2517
|
+
return /* @__PURE__ */ jsx(Primitive.p, { id: context.descriptionId, ...descriptionProps, ref: forwardedRef });
|
|
2518
|
+
}
|
|
2519
|
+
);
|
|
2520
|
+
DialogDescription.displayName = DESCRIPTION_NAME;
|
|
2521
|
+
var CLOSE_NAME = "DialogClose";
|
|
2522
|
+
var DialogClose = React.forwardRef(
|
|
2523
|
+
(props, forwardedRef) => {
|
|
2524
|
+
const { __scopeDialog, ...closeProps } = props;
|
|
2525
|
+
const context = useDialogContext(CLOSE_NAME, __scopeDialog);
|
|
2526
|
+
return /* @__PURE__ */ jsx(
|
|
2527
|
+
Primitive.button,
|
|
2528
|
+
{
|
|
2529
|
+
type: "button",
|
|
2530
|
+
...closeProps,
|
|
2531
|
+
ref: forwardedRef,
|
|
2532
|
+
onClick: composeEventHandlers(props.onClick, () => context.onOpenChange(false))
|
|
2533
|
+
}
|
|
2534
|
+
);
|
|
2535
|
+
}
|
|
2536
|
+
);
|
|
2537
|
+
DialogClose.displayName = CLOSE_NAME;
|
|
2538
|
+
function getState(open) {
|
|
2539
|
+
return open ? "open" : "closed";
|
|
2540
|
+
}
|
|
2541
|
+
var TITLE_WARNING_NAME = "DialogTitleWarning";
|
|
2542
|
+
var [WarningProvider, useWarningContext] = createContext2(TITLE_WARNING_NAME, {
|
|
2543
|
+
contentName: CONTENT_NAME,
|
|
2544
|
+
titleName: TITLE_NAME,
|
|
2545
|
+
docsSlug: "dialog"
|
|
2546
|
+
});
|
|
2547
|
+
var TitleWarning = ({ titleId }) => {
|
|
2548
|
+
const titleWarningContext = useWarningContext(TITLE_WARNING_NAME);
|
|
2549
|
+
const MESSAGE = `\`${titleWarningContext.contentName}\` requires a \`${titleWarningContext.titleName}\` for the component to be accessible for screen reader users.
|
|
2550
|
+
|
|
2551
|
+
If you want to hide the \`${titleWarningContext.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
2552
|
+
|
|
2553
|
+
For more information, see https://radix-ui.com/primitives/docs/components/${titleWarningContext.docsSlug}`;
|
|
2554
|
+
React.useEffect(() => {
|
|
2555
|
+
if (titleId) {
|
|
2556
|
+
const hasTitle = document.getElementById(titleId);
|
|
2557
|
+
if (!hasTitle) console.error(MESSAGE);
|
|
2558
|
+
}
|
|
2559
|
+
}, [MESSAGE, titleId]);
|
|
2560
|
+
return null;
|
|
2561
|
+
};
|
|
2562
|
+
var DESCRIPTION_WARNING_NAME = "DialogDescriptionWarning";
|
|
2563
|
+
var DescriptionWarning = ({ contentRef, descriptionId }) => {
|
|
2564
|
+
const descriptionWarningContext = useWarningContext(DESCRIPTION_WARNING_NAME);
|
|
2565
|
+
const MESSAGE = `Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${descriptionWarningContext.contentName}}.`;
|
|
2566
|
+
React.useEffect(() => {
|
|
2567
|
+
const describedById = contentRef.current?.getAttribute("aria-describedby");
|
|
2568
|
+
if (descriptionId && describedById) {
|
|
2569
|
+
const hasDescription = document.getElementById(descriptionId);
|
|
2570
|
+
if (!hasDescription) console.warn(MESSAGE);
|
|
2571
|
+
}
|
|
2572
|
+
}, [MESSAGE, contentRef, descriptionId]);
|
|
2573
|
+
return null;
|
|
2574
|
+
};
|
|
2575
|
+
var Root = Dialog;
|
|
2576
|
+
var Portal = DialogPortal;
|
|
2577
|
+
var Overlay = DialogOverlay;
|
|
2578
|
+
var Content = DialogContent;
|
|
2579
|
+
var Title = DialogTitle;
|
|
2580
|
+
var Close = DialogClose;
|
|
2581
|
+
const FPS_OPTIONS = [24, 30, 60];
|
|
2582
|
+
const SCALE_OPTIONS = [
|
|
2583
|
+
{ label: "720p", value: 1, resolution: "1280 × 720" },
|
|
2584
|
+
{ label: "1080p", value: 1.5, resolution: "1920 × 1080" },
|
|
2585
|
+
{ label: "1440p", value: 2, resolution: "2560 × 1440" }
|
|
2586
|
+
];
|
|
2587
|
+
const BITRATE_OPTIONS = [
|
|
2588
|
+
{ label: "2 Mbps (Small)", value: 2e6 },
|
|
2589
|
+
{ label: "5 Mbps (Medium)", value: 5e6 },
|
|
2590
|
+
{ label: "10 Mbps (Large)", value: 1e7 },
|
|
2591
|
+
{ label: "20 Mbps (High Quality)", value: 2e7 }
|
|
2592
|
+
];
|
|
2593
|
+
const styles = {
|
|
2594
|
+
overlay: {
|
|
2595
|
+
position: "fixed",
|
|
2596
|
+
inset: 0,
|
|
2597
|
+
backgroundColor: "rgba(0, 0, 0, 0.6)",
|
|
2598
|
+
zIndex: 40
|
|
2599
|
+
},
|
|
2600
|
+
content: {
|
|
2601
|
+
position: "fixed",
|
|
2602
|
+
left: "50%",
|
|
2603
|
+
top: "50%",
|
|
2604
|
+
transform: "translate(-50%, -50%)",
|
|
2605
|
+
backgroundColor: "#262626",
|
|
2606
|
+
borderRadius: "8px",
|
|
2607
|
+
boxShadow: "0 25px 50px -12px rgba(0, 0, 0, 0.5)",
|
|
2608
|
+
border: "1px solid #404040",
|
|
2609
|
+
width: "420px",
|
|
2610
|
+
zIndex: 50,
|
|
2611
|
+
outline: "none"
|
|
2612
|
+
},
|
|
2613
|
+
header: {
|
|
2614
|
+
display: "flex",
|
|
2615
|
+
alignItems: "center",
|
|
2616
|
+
justifyContent: "space-between",
|
|
2617
|
+
padding: "16px",
|
|
2618
|
+
borderBottom: "1px solid #404040"
|
|
2619
|
+
},
|
|
2620
|
+
title: {
|
|
2621
|
+
fontSize: "18px",
|
|
2622
|
+
fontWeight: 500,
|
|
2623
|
+
color: "#fff",
|
|
2624
|
+
margin: 0
|
|
2625
|
+
},
|
|
2626
|
+
closeButton: {
|
|
2627
|
+
color: "#a3a3a3",
|
|
2628
|
+
padding: "4px",
|
|
2629
|
+
borderRadius: "4px",
|
|
2630
|
+
border: "none",
|
|
2631
|
+
background: "transparent",
|
|
2632
|
+
cursor: "pointer"
|
|
2633
|
+
},
|
|
2634
|
+
body: {
|
|
2635
|
+
padding: "16px"
|
|
2636
|
+
},
|
|
2637
|
+
label: {
|
|
2638
|
+
display: "block",
|
|
2639
|
+
fontSize: "14px",
|
|
2640
|
+
color: "#d4d4d4",
|
|
2641
|
+
marginBottom: "8px"
|
|
2642
|
+
},
|
|
2643
|
+
buttonGroup: {
|
|
2644
|
+
display: "flex",
|
|
2645
|
+
gap: "8px",
|
|
2646
|
+
marginBottom: "16px"
|
|
2647
|
+
},
|
|
2648
|
+
optionButton: (selected) => ({
|
|
2649
|
+
padding: "8px 16px",
|
|
2650
|
+
borderRadius: "4px",
|
|
2651
|
+
fontSize: "14px",
|
|
2652
|
+
fontWeight: 500,
|
|
2653
|
+
border: "none",
|
|
2654
|
+
cursor: "pointer",
|
|
2655
|
+
transition: "background-color 0.15s",
|
|
2656
|
+
backgroundColor: selected ? "#2563eb" : "#404040",
|
|
2657
|
+
color: selected ? "#fff" : "#d4d4d4"
|
|
2658
|
+
}),
|
|
2659
|
+
select: {
|
|
2660
|
+
width: "100%",
|
|
2661
|
+
padding: "8px 12px",
|
|
2662
|
+
backgroundColor: "#404040",
|
|
2663
|
+
border: "1px solid #525252",
|
|
2664
|
+
borderRadius: "4px",
|
|
2665
|
+
color: "#e5e5e5",
|
|
2666
|
+
fontSize: "14px",
|
|
2667
|
+
outline: "none",
|
|
2668
|
+
marginBottom: "16px"
|
|
2669
|
+
},
|
|
2670
|
+
info: {
|
|
2671
|
+
fontSize: "14px",
|
|
2672
|
+
color: "#a3a3a3",
|
|
2673
|
+
marginBottom: "16px"
|
|
2674
|
+
},
|
|
2675
|
+
infoLine: {
|
|
2676
|
+
margin: "4px 0"
|
|
2677
|
+
},
|
|
2678
|
+
primaryButton: (disabled) => ({
|
|
2679
|
+
width: "100%",
|
|
2680
|
+
padding: "10px 16px",
|
|
2681
|
+
backgroundColor: disabled ? "#525252" : "#2563eb",
|
|
2682
|
+
color: "#fff",
|
|
2683
|
+
fontWeight: 500,
|
|
2684
|
+
borderRadius: "4px",
|
|
2685
|
+
border: "none",
|
|
2686
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
2687
|
+
transition: "background-color 0.15s",
|
|
2688
|
+
display: "flex",
|
|
2689
|
+
alignItems: "center",
|
|
2690
|
+
justifyContent: "center",
|
|
2691
|
+
gap: "8px"
|
|
2692
|
+
}),
|
|
2693
|
+
secondaryButton: {
|
|
2694
|
+
width: "100%",
|
|
2695
|
+
padding: "10px 16px",
|
|
2696
|
+
backgroundColor: "#404040",
|
|
2697
|
+
color: "#fff",
|
|
2698
|
+
fontWeight: 500,
|
|
2699
|
+
borderRadius: "4px",
|
|
2700
|
+
border: "none",
|
|
2701
|
+
cursor: "pointer",
|
|
2702
|
+
transition: "background-color 0.15s",
|
|
2703
|
+
marginTop: "8px",
|
|
2704
|
+
display: "flex",
|
|
2705
|
+
alignItems: "center",
|
|
2706
|
+
justifyContent: "center",
|
|
2707
|
+
gap: "8px"
|
|
2708
|
+
},
|
|
2709
|
+
warning: {
|
|
2710
|
+
display: "flex",
|
|
2711
|
+
alignItems: "flex-start",
|
|
2712
|
+
gap: "12px",
|
|
2713
|
+
padding: "12px",
|
|
2714
|
+
backgroundColor: "rgba(180, 83, 9, 0.2)",
|
|
2715
|
+
border: "1px solid rgba(180, 83, 9, 0.5)",
|
|
2716
|
+
borderRadius: "8px",
|
|
2717
|
+
marginBottom: "16px"
|
|
2718
|
+
},
|
|
2719
|
+
warningIcon: {
|
|
2720
|
+
color: "#f59e0b",
|
|
2721
|
+
marginTop: "2px",
|
|
2722
|
+
flexShrink: 0
|
|
2723
|
+
},
|
|
2724
|
+
warningText: {
|
|
2725
|
+
fontSize: "14px",
|
|
2726
|
+
color: "#fcd34d"
|
|
2727
|
+
},
|
|
2728
|
+
error: {
|
|
2729
|
+
display: "flex",
|
|
2730
|
+
alignItems: "flex-start",
|
|
2731
|
+
gap: "12px",
|
|
2732
|
+
padding: "12px",
|
|
2733
|
+
backgroundColor: "rgba(127, 29, 29, 0.3)",
|
|
2734
|
+
border: "1px solid rgba(185, 28, 28, 0.5)",
|
|
2735
|
+
borderRadius: "8px",
|
|
2736
|
+
marginBottom: "16px"
|
|
2737
|
+
},
|
|
2738
|
+
errorIcon: {
|
|
2739
|
+
color: "#ef4444",
|
|
2740
|
+
marginTop: "2px",
|
|
2741
|
+
flexShrink: 0
|
|
2742
|
+
},
|
|
2743
|
+
errorText: {
|
|
2744
|
+
fontSize: "14px",
|
|
2745
|
+
color: "#fecaca"
|
|
2746
|
+
},
|
|
2747
|
+
progressContainer: {
|
|
2748
|
+
marginBottom: "16px"
|
|
2749
|
+
},
|
|
2750
|
+
progressHeader: {
|
|
2751
|
+
display: "flex",
|
|
2752
|
+
alignItems: "center",
|
|
2753
|
+
justifyContent: "space-between",
|
|
2754
|
+
marginBottom: "8px"
|
|
2755
|
+
},
|
|
2756
|
+
progressLabel: {
|
|
2757
|
+
fontSize: "14px",
|
|
2758
|
+
color: "#d4d4d4"
|
|
2759
|
+
},
|
|
2760
|
+
progressPercent: {
|
|
2761
|
+
fontSize: "14px",
|
|
2762
|
+
color: "#a3a3a3"
|
|
2763
|
+
},
|
|
2764
|
+
progressBar: {
|
|
2765
|
+
width: "100%",
|
|
2766
|
+
height: "8px",
|
|
2767
|
+
backgroundColor: "#404040",
|
|
2768
|
+
borderRadius: "4px",
|
|
2769
|
+
overflow: "hidden"
|
|
2770
|
+
},
|
|
2771
|
+
progressFill: (progress) => ({
|
|
2772
|
+
height: "100%",
|
|
2773
|
+
backgroundColor: "#3b82f6",
|
|
2774
|
+
transition: "width 0.1s",
|
|
2775
|
+
width: `${progress * 100}%`
|
|
2776
|
+
}),
|
|
2777
|
+
progressFrame: {
|
|
2778
|
+
fontSize: "12px",
|
|
2779
|
+
color: "#737373",
|
|
2780
|
+
marginTop: "8px"
|
|
2781
|
+
},
|
|
2782
|
+
successContainer: {
|
|
2783
|
+
textAlign: "center",
|
|
2784
|
+
marginBottom: "16px"
|
|
2785
|
+
},
|
|
2786
|
+
successIcon: {
|
|
2787
|
+
width: "48px",
|
|
2788
|
+
height: "48px",
|
|
2789
|
+
backgroundColor: "rgba(37, 99, 235, 0.2)",
|
|
2790
|
+
borderRadius: "50%",
|
|
2791
|
+
display: "flex",
|
|
2792
|
+
alignItems: "center",
|
|
2793
|
+
justifyContent: "center",
|
|
2794
|
+
margin: "0 auto 12px"
|
|
2795
|
+
},
|
|
2796
|
+
successTitle: {
|
|
2797
|
+
color: "#fff",
|
|
2798
|
+
fontWeight: 500,
|
|
2799
|
+
margin: "0 0 4px"
|
|
2800
|
+
},
|
|
2801
|
+
successInfo: {
|
|
2802
|
+
fontSize: "14px",
|
|
2803
|
+
color: "#a3a3a3",
|
|
2804
|
+
margin: "4px 0"
|
|
2805
|
+
}
|
|
2806
|
+
};
|
|
2807
|
+
function RenderDialog({ open, onOpenChange, animation }) {
|
|
2808
|
+
const [state, setState] = useState("idle");
|
|
2809
|
+
const [fps, setFps] = useState(30);
|
|
2810
|
+
const [scale, setScale] = useState(2);
|
|
2811
|
+
const [bitrate, setBitrate] = useState(1e7);
|
|
2812
|
+
const [progress, setProgress] = useState(0);
|
|
2813
|
+
const [currentFrame, setCurrentFrame] = useState(0);
|
|
2814
|
+
const [totalFrames, setTotalFrames] = useState(0);
|
|
2815
|
+
const [errorMessage, setErrorMessage] = useState("");
|
|
2816
|
+
const [result, setResult] = useState(null);
|
|
2817
|
+
const rendererRef = useRef(null);
|
|
2818
|
+
const webCodecsSupported = isWebCodecsSupported();
|
|
2819
|
+
useEffect(() => {
|
|
2820
|
+
if (open) {
|
|
2821
|
+
setState("idle");
|
|
2822
|
+
setProgress(0);
|
|
2823
|
+
setCurrentFrame(0);
|
|
2824
|
+
setTotalFrames(0);
|
|
2825
|
+
setErrorMessage("");
|
|
2826
|
+
setResult(null);
|
|
2827
|
+
}
|
|
2828
|
+
}, [open]);
|
|
2829
|
+
const handleStartRender = useCallback(async () => {
|
|
2830
|
+
if (!animation) return;
|
|
2831
|
+
setState("rendering");
|
|
2832
|
+
setProgress(0);
|
|
2833
|
+
setErrorMessage("");
|
|
2834
|
+
const renderer = createVideoRenderer({
|
|
2835
|
+
scene: animation.scene,
|
|
2836
|
+
timeline: animation.timeline,
|
|
2837
|
+
fps,
|
|
2838
|
+
bitrate,
|
|
2839
|
+
scale,
|
|
2840
|
+
onProgress: (p, frame, total) => {
|
|
2841
|
+
setProgress(p);
|
|
2842
|
+
setCurrentFrame(frame);
|
|
2843
|
+
setTotalFrames(total);
|
|
2844
|
+
}
|
|
2845
|
+
});
|
|
2846
|
+
rendererRef.current = renderer;
|
|
2847
|
+
try {
|
|
2848
|
+
const renderResult = await renderer.start();
|
|
2849
|
+
setResult(renderResult);
|
|
2850
|
+
setState("complete");
|
|
2851
|
+
} catch (e) {
|
|
2852
|
+
if (e.message !== "Rendering cancelled") {
|
|
2853
|
+
setErrorMessage(e.message);
|
|
2854
|
+
setState("error");
|
|
2855
|
+
}
|
|
2856
|
+
}
|
|
2857
|
+
rendererRef.current = null;
|
|
2858
|
+
}, [animation, fps, bitrate, scale]);
|
|
2859
|
+
const handleCancel = useCallback(() => {
|
|
2860
|
+
if (rendererRef.current) {
|
|
2861
|
+
rendererRef.current.cancel();
|
|
2862
|
+
}
|
|
2863
|
+
setState("idle");
|
|
2864
|
+
}, []);
|
|
2865
|
+
const handleDownload = useCallback(() => {
|
|
2866
|
+
if (result) {
|
|
2867
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString().slice(0, 19).replace(/[:-]/g, "");
|
|
2868
|
+
downloadBlob(result.blob, `animation-${timestamp}.mp4`);
|
|
2869
|
+
}
|
|
2870
|
+
}, [result]);
|
|
2871
|
+
const handleClose = useCallback(() => {
|
|
2872
|
+
if (state === "rendering") {
|
|
2873
|
+
handleCancel();
|
|
2874
|
+
}
|
|
2875
|
+
onOpenChange(false);
|
|
2876
|
+
}, [state, handleCancel, onOpenChange]);
|
|
2877
|
+
const estimatedDuration = animation ? Math.ceil(animation.timeline.duration / 1e3 * fps) : 0;
|
|
2878
|
+
return /* @__PURE__ */ jsx(Root, { open, onOpenChange: handleClose, children: /* @__PURE__ */ jsxs(Portal, { children: [
|
|
2879
|
+
/* @__PURE__ */ jsx(Overlay, { style: styles.overlay }),
|
|
2880
|
+
/* @__PURE__ */ jsxs(Content, { style: styles.content, children: [
|
|
2881
|
+
/* @__PURE__ */ jsxs("div", { style: styles.header, children: [
|
|
2882
|
+
/* @__PURE__ */ jsx(Title, { style: styles.title, children: "Render Video" }),
|
|
2883
|
+
/* @__PURE__ */ jsx(Close, { asChild: true, children: /* @__PURE__ */ jsx("button", { style: styles.closeButton, "aria-label": "Close", children: /* @__PURE__ */ jsx(X, { size: 18 }) }) })
|
|
2884
|
+
] }),
|
|
2885
|
+
/* @__PURE__ */ jsxs("div", { style: styles.body, children: [
|
|
2886
|
+
!webCodecsSupported && /* @__PURE__ */ jsxs("div", { style: styles.warning, children: [
|
|
2887
|
+
/* @__PURE__ */ jsx(CircleAlert, { size: 18, style: styles.warningIcon }),
|
|
2888
|
+
/* @__PURE__ */ jsx("div", { style: styles.warningText, children: "WebCodecs is not supported in this browser. Please use Chrome, Edge, or Opera to render videos." })
|
|
2889
|
+
] }),
|
|
2890
|
+
state === "idle" && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2891
|
+
/* @__PURE__ */ jsx("label", { style: styles.label, children: "Resolution" }),
|
|
2892
|
+
/* @__PURE__ */ jsx("div", { style: styles.buttonGroup, children: SCALE_OPTIONS.map((option) => /* @__PURE__ */ jsx(
|
|
2893
|
+
"button",
|
|
2894
|
+
{
|
|
2895
|
+
onClick: () => setScale(option.value),
|
|
2896
|
+
style: styles.optionButton(scale === option.value),
|
|
2897
|
+
children: option.label
|
|
2898
|
+
},
|
|
2899
|
+
option.value
|
|
2900
|
+
)) }),
|
|
2901
|
+
/* @__PURE__ */ jsx("label", { style: styles.label, children: "Frame Rate" }),
|
|
2902
|
+
/* @__PURE__ */ jsx("div", { style: styles.buttonGroup, children: FPS_OPTIONS.map((option) => /* @__PURE__ */ jsxs(
|
|
2903
|
+
"button",
|
|
2904
|
+
{
|
|
2905
|
+
onClick: () => setFps(option),
|
|
2906
|
+
style: styles.optionButton(fps === option),
|
|
2907
|
+
children: [
|
|
2908
|
+
option,
|
|
2909
|
+
" fps"
|
|
2910
|
+
]
|
|
2911
|
+
},
|
|
2912
|
+
option
|
|
2913
|
+
)) }),
|
|
2914
|
+
/* @__PURE__ */ jsx("label", { style: styles.label, children: "Quality / Bitrate" }),
|
|
2915
|
+
/* @__PURE__ */ jsx(
|
|
2916
|
+
"select",
|
|
2917
|
+
{
|
|
2918
|
+
value: bitrate,
|
|
2919
|
+
onChange: (e) => setBitrate(Number(e.target.value)),
|
|
2920
|
+
style: styles.select,
|
|
2921
|
+
children: BITRATE_OPTIONS.map((option) => /* @__PURE__ */ jsx("option", { value: option.value, children: option.label }, option.value))
|
|
2922
|
+
}
|
|
2923
|
+
),
|
|
2924
|
+
/* @__PURE__ */ jsxs("div", { style: styles.info, children: [
|
|
2925
|
+
/* @__PURE__ */ jsxs("p", { style: styles.infoLine, children: [
|
|
2926
|
+
"Resolution: ",
|
|
2927
|
+
SCALE_OPTIONS.find((o) => o.value === scale)?.resolution
|
|
2928
|
+
] }),
|
|
2929
|
+
/* @__PURE__ */ jsxs("p", { style: styles.infoLine, children: [
|
|
2930
|
+
"Duration: ",
|
|
2931
|
+
(animation?.timeline.duration ?? 0) / 1e3,
|
|
2932
|
+
"s"
|
|
2933
|
+
] }),
|
|
2934
|
+
/* @__PURE__ */ jsxs("p", { style: styles.infoLine, children: [
|
|
2935
|
+
"Estimated frames: ",
|
|
2936
|
+
estimatedDuration
|
|
2937
|
+
] })
|
|
2938
|
+
] }),
|
|
2939
|
+
/* @__PURE__ */ jsx(
|
|
2940
|
+
"button",
|
|
2941
|
+
{
|
|
2942
|
+
onClick: handleStartRender,
|
|
2943
|
+
disabled: !animation || !webCodecsSupported,
|
|
2944
|
+
style: styles.primaryButton(!animation || !webCodecsSupported),
|
|
2945
|
+
children: "Start Render"
|
|
2946
|
+
}
|
|
2947
|
+
)
|
|
2948
|
+
] }),
|
|
2949
|
+
state === "rendering" && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2950
|
+
/* @__PURE__ */ jsxs("div", { style: styles.progressContainer, children: [
|
|
2951
|
+
/* @__PURE__ */ jsxs("div", { style: styles.progressHeader, children: [
|
|
2952
|
+
/* @__PURE__ */ jsx("span", { style: styles.progressLabel, children: "Rendering..." }),
|
|
2953
|
+
/* @__PURE__ */ jsxs("span", { style: styles.progressPercent, children: [
|
|
2954
|
+
Math.round(progress * 100),
|
|
2955
|
+
"%"
|
|
2956
|
+
] })
|
|
2957
|
+
] }),
|
|
2958
|
+
/* @__PURE__ */ jsx("div", { style: styles.progressBar, children: /* @__PURE__ */ jsx("div", { style: styles.progressFill(progress) }) }),
|
|
2959
|
+
/* @__PURE__ */ jsxs("p", { style: styles.progressFrame, children: [
|
|
2960
|
+
"Frame ",
|
|
2961
|
+
currentFrame,
|
|
2962
|
+
" of ",
|
|
2963
|
+
totalFrames
|
|
2964
|
+
] })
|
|
2965
|
+
] }),
|
|
2966
|
+
/* @__PURE__ */ jsxs("button", { onClick: handleCancel, style: styles.secondaryButton, children: [
|
|
2967
|
+
/* @__PURE__ */ jsx(LoaderCircle, { size: 16, style: { animation: "spin 1s linear infinite" } }),
|
|
2968
|
+
"Cancel"
|
|
2969
|
+
] }),
|
|
2970
|
+
/* @__PURE__ */ jsx("style", { children: `@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }` })
|
|
2971
|
+
] }),
|
|
2972
|
+
state === "complete" && result && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2973
|
+
/* @__PURE__ */ jsxs("div", { style: styles.successContainer, children: [
|
|
2974
|
+
/* @__PURE__ */ jsx("div", { style: styles.successIcon, children: /* @__PURE__ */ jsx(Download, { size: 24, style: { color: "#3b82f6" } }) }),
|
|
2975
|
+
/* @__PURE__ */ jsx("p", { style: styles.successTitle, children: "Render Complete!" }),
|
|
2976
|
+
/* @__PURE__ */ jsxs("p", { style: styles.successInfo, children: [
|
|
2977
|
+
result.frames,
|
|
2978
|
+
" frames rendered"
|
|
2979
|
+
] }),
|
|
2980
|
+
/* @__PURE__ */ jsxs("p", { style: styles.successInfo, children: [
|
|
2981
|
+
"File size: ",
|
|
2982
|
+
(result.blob.size / 1024 / 1024).toFixed(2),
|
|
2983
|
+
" MB"
|
|
2984
|
+
] })
|
|
2985
|
+
] }),
|
|
2986
|
+
/* @__PURE__ */ jsxs("button", { onClick: handleDownload, style: styles.primaryButton(false), children: [
|
|
2987
|
+
/* @__PURE__ */ jsx(Download, { size: 16 }),
|
|
2988
|
+
"Download MP4"
|
|
2989
|
+
] }),
|
|
2990
|
+
/* @__PURE__ */ jsx("button", { onClick: () => setState("idle"), style: styles.secondaryButton, children: "Render Another" })
|
|
2991
|
+
] }),
|
|
2992
|
+
state === "error" && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2993
|
+
/* @__PURE__ */ jsxs("div", { style: styles.error, children: [
|
|
2994
|
+
/* @__PURE__ */ jsx(CircleAlert, { size: 18, style: styles.errorIcon }),
|
|
2995
|
+
/* @__PURE__ */ jsx("div", { style: styles.errorText, children: errorMessage })
|
|
2996
|
+
] }),
|
|
2997
|
+
/* @__PURE__ */ jsx("button", { onClick: () => setState("idle"), style: styles.secondaryButton, children: "Try Again" })
|
|
2998
|
+
] })
|
|
2999
|
+
] })
|
|
3000
|
+
] })
|
|
3001
|
+
] }) });
|
|
3002
|
+
}
|
|
422
3003
|
export {
|
|
423
|
-
AnimaPlayer
|
|
3004
|
+
AnimaPlayer,
|
|
3005
|
+
RenderDialog,
|
|
3006
|
+
TimelineControls
|
|
424
3007
|
};
|
|
425
3008
|
//# sourceMappingURL=react.js.map
|