@xwadex/fesd-next 0.3.2 → 0.3.4-10

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.
@@ -0,0 +1,891 @@
1
+ import * as React2 from 'react';
2
+ import { memo, useRef, useEffectEvent, useEffect, useState, useLayoutEffect, createContext, useMemo, useCallback, use } from 'react';
3
+ import Cookies from 'js-cookie';
4
+ import { useAnimate, motionValue } from 'motion/react';
5
+ import { create } from 'zustand';
6
+ import '@radix-ui/react-accordion';
7
+ import 'lucide-react';
8
+ import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
9
+ import '@radix-ui/react-alert-dialog';
10
+ import { cva } from 'class-variance-authority';
11
+ import '@radix-ui/react-aspect-ratio';
12
+ import '@radix-ui/react-avatar';
13
+ import '@radix-ui/react-slot';
14
+ import 'react-day-picker';
15
+ import useEmblaCarousel from 'embla-carousel-react';
16
+ import 'recharts';
17
+ import '@radix-ui/react-checkbox';
18
+ import '@radix-ui/react-collapsible';
19
+ import 'cmdk';
20
+ import '@radix-ui/react-context-menu';
21
+ import '@radix-ui/react-dialog';
22
+ import 'vaul';
23
+ import '@radix-ui/react-dropdown-menu';
24
+ import 'react-hook-form';
25
+ import '@radix-ui/react-hover-card';
26
+ import 'input-otp';
27
+ import '@radix-ui/react-label';
28
+ import '@radix-ui/react-menubar';
29
+ import '@radix-ui/react-navigation-menu';
30
+ import '@radix-ui/react-popover';
31
+ import '@radix-ui/react-progress';
32
+ import '@radix-ui/react-radio-group';
33
+ import 'react-resizable-panels';
34
+ import '@radix-ui/react-scroll-area';
35
+ import '@radix-ui/react-select';
36
+ import '@radix-ui/react-separator';
37
+ import '@radix-ui/react-slider';
38
+ import 'next-themes';
39
+ import 'sonner';
40
+ import '@radix-ui/react-switch';
41
+ import '@radix-ui/react-tabs';
42
+ import '@radix-ui/react-toggle-group';
43
+ import '@radix-ui/react-toggle';
44
+ import '@radix-ui/react-tooltip';
45
+ import { clsx } from 'clsx';
46
+ import { twMerge } from 'tailwind-merge';
47
+ import Lenis from 'lenis';
48
+ import { useLenis, ReactLenis } from 'lenis/react';
49
+ import { WheelGesturesPlugin } from 'embla-carousel-wheel-gestures';
50
+ import Autoplay from 'embla-carousel-autoplay';
51
+ import AutoScroll from 'embla-carousel-auto-scroll';
52
+ import AutoHeight from 'embla-carousel-auto-height';
53
+ import ClassNames from 'embla-carousel-class-names';
54
+ import Fade from 'embla-carousel-fade';
55
+
56
+ // src/hooks/useDebounce.tsx
57
+ function useDebounce({
58
+ callback,
59
+ dependency = [],
60
+ delay = 500,
61
+ active = true
62
+ }) {
63
+ if (!active || !callback) return;
64
+ const timerRef = useRef(null);
65
+ useEffect(() => {
66
+ if (timerRef.current) clearTimeout(timerRef.current);
67
+ timerRef.current = setTimeout(callback, delay);
68
+ return () => {
69
+ if (timerRef.current) clearTimeout(timerRef.current);
70
+ };
71
+ }, [...dependency]);
72
+ }
73
+ function useDebounceValue(value, delay = 500) {
74
+ const [debounceValue, setDebounceValue] = useState(value);
75
+ const timerRef = useRef(void 0);
76
+ useEffect(() => {
77
+ if (timerRef.current) clearTimeout(timerRef.current);
78
+ timerRef.current = setTimeout(() => setDebounceValue(value), delay);
79
+ return () => {
80
+ if (timerRef.current) clearTimeout(timerRef.current);
81
+ };
82
+ }, [value, delay]);
83
+ return debounceValue;
84
+ }
85
+ function useCookies() {
86
+ const setCookies = (name, value, days = 7) => {
87
+ Cookies.set(name, value, { expires: days, path: "/" });
88
+ };
89
+ const getCookies = (name) => {
90
+ return Cookies.get(name) ?? null;
91
+ };
92
+ const updateCookies = (name, value, days = 7) => {
93
+ if (getCookies(name) !== null) setCookies(name, value, days);
94
+ };
95
+ const deleteCookies = (name) => {
96
+ Cookies.remove(name, { path: "/" });
97
+ };
98
+ return { setCookies, getCookies, updateCookies, deleteCookies };
99
+ }
100
+ function useDragResize({
101
+ active = true,
102
+ direction = "horizontal",
103
+ minWidth,
104
+ maxWidth,
105
+ minHeight,
106
+ maxHeight,
107
+ onInit,
108
+ onResizeStart,
109
+ onResizing,
110
+ onResizeEnd
111
+ }) {
112
+ const dragRef = useRef(null);
113
+ const resizeRef = useRef(null);
114
+ const [resize, setResize] = useState({ width: 0, height: 0 });
115
+ const getResizeSizeValue = () => {
116
+ if (!resizeRef.current) return;
117
+ const { width: w, height: h } = resizeRef.current.style;
118
+ const width = Number(w.replace("px", "")) ?? "inherit";
119
+ Number(h.replace("px", "")) ?? "inherit";
120
+ return { width };
121
+ };
122
+ const setResizeValue = (clientX, clientY) => {
123
+ if (!resizeRef.current) return;
124
+ const rect = resizeRef.current.getBoundingClientRect();
125
+ const resizeWidth = clientX - rect.left;
126
+ const resizeHeight = clientY - rect.top;
127
+ if (direction == "horizontal" && (minWidth && resizeWidth >= minWidth) && (maxWidth && resizeWidth <= maxWidth)) {
128
+ resizeRef.current.style.width = resizeWidth + "px";
129
+ return { width: resizeWidth, height: void 0 };
130
+ }
131
+ if (direction == "vertical" && (minHeight && resizeWidth >= minHeight) && (maxHeight && resizeWidth <= maxHeight)) {
132
+ resizeRef.current.style.height = resizeHeight + "px";
133
+ return { width: void 0, height: resizeHeight };
134
+ }
135
+ };
136
+ const onInitCallback = () => {
137
+ const resizeValue = getResizeSizeValue();
138
+ resizeValue && onInit?.(resizeValue);
139
+ };
140
+ const removeEventListeners = () => {
141
+ document.removeEventListener("mousemove", onMouseMove);
142
+ document.removeEventListener("mouseup", onMouseUp);
143
+ };
144
+ const onMouseMove = (e) => {
145
+ const resizeValue = setResizeValue(e.clientX, e.clientY);
146
+ if (!resizeValue) return;
147
+ setResize(() => ({ ...resizeValue }));
148
+ onResizing?.(resizeValue);
149
+ };
150
+ const onMouseUp = () => {
151
+ const resizeValue = getResizeSizeValue();
152
+ resizeValue && onResizeEnd?.(resizeValue);
153
+ removeEventListeners();
154
+ };
155
+ const onDragRefMouseDown = (e) => {
156
+ e.preventDefault();
157
+ const resizeValue = getResizeSizeValue();
158
+ resizeValue && onResizeStart?.(resizeValue);
159
+ document.addEventListener("mousemove", onMouseMove);
160
+ document.addEventListener("mouseup", onMouseUp);
161
+ };
162
+ useEffect(() => {
163
+ if (active && dragRef.current && resizeRef.current) {
164
+ dragRef.current.onmousedown = onDragRefMouseDown;
165
+ onInit && onInitCallback();
166
+ }
167
+ return () => {
168
+ if (!dragRef?.current) return;
169
+ dragRef.current.onmousedown = null;
170
+ removeEventListeners();
171
+ };
172
+ }, [active]);
173
+ return { dragRef, resizeRef, resize };
174
+ }
175
+ function useAsyncFetcher() {
176
+ const [isPending, setPending] = useState(false);
177
+ const controllerRef = useRef(null);
178
+ const startFetch = useCallback(async ({ url, options }) => {
179
+ if (isPending || !url) return;
180
+ const controller = new AbortController();
181
+ controllerRef.current = controller;
182
+ setPending(true);
183
+ try {
184
+ const response = await fetch(url, {
185
+ signal: controller.signal,
186
+ ...options
187
+ });
188
+ const datas = await response.json();
189
+ return datas;
190
+ } catch (error) {
191
+ console.error("useAsyncFetche startFetch error:", error);
192
+ return { status: false, error };
193
+ } finally {
194
+ setPending(false);
195
+ }
196
+ }, [isPending]);
197
+ const cancelFetch = () => {
198
+ controllerRef.current?.abort();
199
+ setPending(false);
200
+ };
201
+ useEffect(() => {
202
+ return () => controllerRef.current?.abort();
203
+ }, []);
204
+ return {
205
+ pending: isPending,
206
+ cancel: cancelFetch,
207
+ fetcher: startFetch
208
+ };
209
+ }
210
+ function useMounted() {
211
+ const [isMounded, setMounded] = useState(false);
212
+ useEffect(() => {
213
+ setMounded(true);
214
+ }, []);
215
+ return { isMounded };
216
+ }
217
+ function useEffectOne(callback) {
218
+ const callbackRef = useRef(callback);
219
+ callbackRef.current = callback;
220
+ useEffect(() => {
221
+ callbackRef.current?.();
222
+ return () => {
223
+ callbackRef.current = null;
224
+ };
225
+ }, []);
226
+ }
227
+ function useEffectLeave(callback) {
228
+ const callbackRef = useRef(callback);
229
+ callbackRef.current = callback;
230
+ useEffect(() => {
231
+ return () => {
232
+ callbackRef.current?.();
233
+ callbackRef.current = null;
234
+ };
235
+ }, []);
236
+ }
237
+ cva(
238
+ "relative w-full rounded-lg border px-4 py-3 text-sm grid has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] grid-cols-[0_1fr] has-[>svg]:gap-x-3 gap-y-0.5 items-start [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current",
239
+ {
240
+ variants: {
241
+ variant: {
242
+ default: "bg-card text-card-foreground",
243
+ destructive: "text-destructive bg-card [&>svg]:text-current *:data-[slot=alert-description]:text-destructive/90"
244
+ }
245
+ },
246
+ defaultVariants: {
247
+ variant: "default"
248
+ }
249
+ }
250
+ );
251
+ cva(
252
+ "inline-flex items-center justify-center rounded-md border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",
253
+ {
254
+ variants: {
255
+ variant: {
256
+ default: "border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90",
257
+ secondary: "border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",
258
+ destructive: "border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
259
+ outline: "text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground"
260
+ }
261
+ },
262
+ defaultVariants: {
263
+ variant: "default"
264
+ }
265
+ }
266
+ );
267
+ cva(
268
+ "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
269
+ {
270
+ variants: {
271
+ variant: {
272
+ default: "bg-primary text-primary-foreground shadow-xs hover:bg-primary/90",
273
+ destructive: "bg-destructive text-white shadow-xs hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
274
+ outline: "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
275
+ secondary: "bg-secondary text-secondary-foreground shadow-xs hover:bg-secondary/80",
276
+ ghost: "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
277
+ link: "text-primary underline-offset-4 hover:underline"
278
+ },
279
+ size: {
280
+ default: "h-9 px-4 py-2 has-[>svg]:px-3",
281
+ sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
282
+ lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
283
+ icon: "size-9"
284
+ }
285
+ },
286
+ defaultVariants: {
287
+ variant: "default",
288
+ size: "default"
289
+ }
290
+ }
291
+ );
292
+ React2.createContext(null);
293
+ React2.createContext(null);
294
+ React2.createContext({});
295
+ React2.createContext({});
296
+ cva(
297
+ "group inline-flex h-9 w-max items-center justify-center rounded-md bg-background px-4 py-2 text-sm font-medium hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground disabled:pointer-events-none disabled:opacity-50 data-[state=open]:hover:bg-accent data-[state=open]:text-accent-foreground data-[state=open]:focus:bg-accent data-[state=open]:bg-accent/50 focus-visible:ring-ring/50 outline-none transition-[color,box-shadow] focus-visible:ring-[3px] focus-visible:outline-1"
298
+ );
299
+ React2.createContext(null);
300
+ cva(
301
+ "peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-hidden ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 group-has-data-[sidebar=menu-action]/menu-item:pr-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:p-2! [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",
302
+ {
303
+ variants: {
304
+ variant: {
305
+ default: "hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
306
+ outline: "bg-background shadow-[0_0_0_1px_hsl(var(--sidebar-border))] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))]"
307
+ },
308
+ size: {
309
+ default: "h-8 text-sm",
310
+ sm: "h-7 text-xs",
311
+ lg: "h-12 text-sm group-data-[collapsible=icon]:p-0!"
312
+ }
313
+ },
314
+ defaultVariants: {
315
+ variant: "default",
316
+ size: "default"
317
+ }
318
+ }
319
+ );
320
+ React2.createContext({
321
+ size: "default",
322
+ variant: "default"
323
+ });
324
+ cva(
325
+ "inline-flex items-center justify-center gap-2 rounded-md text-sm font-medium hover:bg-muted hover:text-muted-foreground disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 [&_svg]:shrink-0 focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] outline-none transition-[color,box-shadow] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive whitespace-nowrap",
326
+ {
327
+ variants: {
328
+ variant: {
329
+ default: "bg-transparent",
330
+ outline: "border border-input bg-transparent shadow-xs hover:bg-accent hover:text-accent-foreground"
331
+ },
332
+ size: {
333
+ default: "h-9 px-2 min-w-9",
334
+ sm: "h-8 px-1.5 min-w-8",
335
+ lg: "h-10 px-2.5 min-w-10"
336
+ }
337
+ },
338
+ defaultVariants: {
339
+ variant: "default",
340
+ size: "default"
341
+ }
342
+ }
343
+ );
344
+ function cn(...inputs) {
345
+ return twMerge(clsx(...inputs));
346
+ }
347
+ memo((props) => {
348
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
349
+ props?.root == true ? /* @__PURE__ */ jsx(LenisRootScroll, { ...props }) : /* @__PURE__ */ jsx(LenisContainerScroll, { ...props }),
350
+ " "
351
+ ] });
352
+ });
353
+ var LenisRootScroll = memo(({
354
+ root,
355
+ options
356
+ }) => {
357
+ const lenis = useLenis();
358
+ const lenisRef = useRef(null);
359
+ const registerRootLenis = useEffectEvent(() => {
360
+ if (!root == true || !lenis) return;
361
+ setRootLenis(lenis);
362
+ });
363
+ useEffect(() => {
364
+ registerRootLenis();
365
+ }, [lenis]);
366
+ return /* @__PURE__ */ jsx(
367
+ ReactLenis,
368
+ {
369
+ ref: lenisRef,
370
+ root,
371
+ options: {
372
+ autoRaf: true,
373
+ lerp: 5e-4,
374
+ duration: 1.5,
375
+ smoothWheel: true,
376
+ ...options
377
+ }
378
+ }
379
+ );
380
+ });
381
+ var LenisContainerScroll = memo(({
382
+ name,
383
+ className,
384
+ children,
385
+ options,
386
+ ...restProps
387
+ }) => {
388
+ const [containerRef, setContainerRef] = useState();
389
+ const wrapperRef = useRef(null);
390
+ const contentRef = useRef(null);
391
+ const initLenis = useEffectEvent(() => {
392
+ if (!wrapperRef.current || !contentRef.current || !name) return;
393
+ const lenis = new Lenis({
394
+ wrapper: wrapperRef.current,
395
+ content: contentRef.current,
396
+ autoRaf: true,
397
+ ...options
398
+ });
399
+ setContainerRef(contentRef);
400
+ setScrollContainerStore({ name, action: "add", node: lenis });
401
+ return () => {
402
+ setScrollContainerStore({ name, action: "remove" });
403
+ lenis?.destroy?.();
404
+ };
405
+ });
406
+ useLayoutEffect(() => {
407
+ const effect = initLenis();
408
+ return effect;
409
+ }, [name, options]);
410
+ return /* @__PURE__ */ jsx(
411
+ "div",
412
+ {
413
+ ref: wrapperRef,
414
+ "data-lenis-scroll": name,
415
+ className: cn("group overflow-hidden", className),
416
+ ...restProps,
417
+ children: /* @__PURE__ */ jsx(
418
+ "div",
419
+ {
420
+ ref: contentRef,
421
+ className: cn("h-full", "relative", "will-change-transform overscroll-contain"),
422
+ children: /* @__PURE__ */ jsx(ScrollContainerContext, { value: { containerRef }, children })
423
+ }
424
+ )
425
+ }
426
+ );
427
+ });
428
+ var useLenisStores = create()(() => ({
429
+ root: null
430
+ }));
431
+ var setRootLenis = (lenis) => useLenisStores.setState(() => {
432
+ return { root: lenis };
433
+ });
434
+ var getRootLenis = () => useLenisStores.getState();
435
+ var ScrollContainerContext = createContext(null);
436
+ var useScrollContainersStores = create()(() => ({
437
+ containers: /* @__PURE__ */ new Map()
438
+ }));
439
+ var getScrollContainerStores = () => useScrollContainersStores.getState();
440
+ var setScrollContainerStore = (options) => {
441
+ const { action, name, node } = options;
442
+ useScrollContainersStores.setState((stores) => {
443
+ const containerDom = stores.containers?.get(name);
444
+ const isContainerNode = node instanceof Lenis || node instanceof HTMLDivElement;
445
+ if (action == "add" && isContainerNode) {
446
+ if (containerDom == node) return stores;
447
+ stores.containers?.set(name, node);
448
+ } else if (action == "remove" && containerDom) {
449
+ stores.containers?.delete(name);
450
+ }
451
+ return { containers: stores.containers };
452
+ });
453
+ };
454
+ memo(({
455
+ tag: Component = "div",
456
+ name,
457
+ className,
458
+ ...restProps
459
+ }) => {
460
+ const componentRef = useRef(null);
461
+ const [containerRef, setContainerRef] = useState();
462
+ const nativeEffect = useEffectEvent(() => {
463
+ if (!componentRef.current) return;
464
+ setContainerRef(componentRef);
465
+ setScrollContainerStore({ name, action: "add", node: componentRef.current });
466
+ return () => {
467
+ setScrollContainerStore({ name, action: "remove" });
468
+ };
469
+ });
470
+ useEffect(() => {
471
+ const effect = nativeEffect();
472
+ return effect;
473
+ }, [componentRef?.current]);
474
+ return /* @__PURE__ */ jsx(ScrollContainerContext, { value: { containerRef }, children: /* @__PURE__ */ jsx(
475
+ Component,
476
+ {
477
+ ref: componentRef,
478
+ "data-native-scroll": name,
479
+ className: cn(
480
+ "overflow-auto",
481
+ "will-change-transform",
482
+ className
483
+ ),
484
+ ...restProps
485
+ }
486
+ ) });
487
+ });
488
+ function emblaCarouselsHooks({
489
+ options,
490
+ autoplay,
491
+ autoScroll,
492
+ classNames,
493
+ autoHeight,
494
+ fade,
495
+ wheel,
496
+ setApi
497
+ }) {
498
+ const orientation = options?.axis ?? "x";
499
+ const plugins = useMemo(() => [
500
+ autoplay && Autoplay(typeof autoplay == "boolean" ? void 0 : autoplay),
501
+ autoScroll && AutoScroll(typeof autoScroll == "boolean" ? void 0 : autoScroll),
502
+ autoHeight && AutoHeight(typeof autoHeight == "boolean" ? void 0 : autoHeight),
503
+ classNames && ClassNames(typeof classNames == "boolean" ? void 0 : classNames),
504
+ fade && Fade(typeof fade == "boolean" ? void 0 : fade),
505
+ wheel && WheelGesturesPlugin(typeof wheel == "boolean" ? void 0 : wheel)
506
+ ].filter(
507
+ (plugin) => plugin
508
+ ), [
509
+ autoplay,
510
+ autoScroll,
511
+ classNames,
512
+ fade,
513
+ wheel,
514
+ autoHeight
515
+ ]);
516
+ const [emblaRef, emblaApi] = useEmblaCarousel(options, plugins);
517
+ const [currentIndex, setCurrentIndex] = useState(0);
518
+ const [isScrollPrev, setIsScrollPrev] = useState(false);
519
+ const [isScrollNext, setIsScrollNext] = useState(false);
520
+ const scrollPrev = useCallback(() => {
521
+ emblaApi?.scrollPrev();
522
+ }, [emblaApi]);
523
+ const scrollNext = useCallback(() => {
524
+ emblaApi?.scrollNext();
525
+ }, [emblaApi]);
526
+ const onKeyDownCapture = useCallback((event) => {
527
+ console.log("key...");
528
+ if (event.key === "ArrowLeft") {
529
+ event.preventDefault();
530
+ scrollPrev();
531
+ } else if (event.key === "ArrowRight") {
532
+ event.preventDefault();
533
+ scrollNext();
534
+ }
535
+ }, [scrollPrev, scrollNext]);
536
+ const onSelect = useCallback((api) => {
537
+ if (!api) return;
538
+ setCurrentIndex(api?.selectedScrollSnap());
539
+ setIsScrollPrev(api.canScrollPrev());
540
+ setIsScrollNext(api.canScrollNext());
541
+ }, []);
542
+ const initalEffect = useEffectEvent(() => {
543
+ if (!emblaApi || !setApi) return;
544
+ setApi?.(emblaApi);
545
+ onSelect(emblaApi);
546
+ emblaApi.on("reInit", onSelect);
547
+ emblaApi.on("select", onSelect);
548
+ return () => {
549
+ emblaApi?.off("select", onSelect);
550
+ };
551
+ });
552
+ useEffect(() => {
553
+ const events = initalEffect();
554
+ return () => {
555
+ events?.();
556
+ };
557
+ }, [emblaApi]);
558
+ return {
559
+ emblaRef,
560
+ emblaApi,
561
+ orientation,
562
+ currentIndex,
563
+ isScrollPrev,
564
+ isScrollNext,
565
+ scrollPrev,
566
+ scrollNext,
567
+ onKeyDownCapture
568
+ };
569
+ }
570
+ var CarouselsContext = createContext(null);
571
+ var useCarouselsContext = () => {
572
+ const context = use(CarouselsContext);
573
+ if (!context) throw new Error("useCarousel must be used within a <Carousel />");
574
+ return context;
575
+ };
576
+ memo(({
577
+ children,
578
+ className,
579
+ setApi,
580
+ options,
581
+ autoplay,
582
+ autoScroll,
583
+ classNames,
584
+ autoHeight,
585
+ fade,
586
+ wheel,
587
+ ...props
588
+ }) => {
589
+ const {
590
+ emblaRef,
591
+ emblaApi,
592
+ orientation,
593
+ currentIndex,
594
+ isScrollPrev,
595
+ isScrollNext,
596
+ scrollPrev,
597
+ scrollNext,
598
+ onKeyDownCapture
599
+ } = emblaCarouselsHooks({
600
+ setApi,
601
+ options,
602
+ autoplay,
603
+ autoScroll,
604
+ classNames,
605
+ autoHeight,
606
+ fade,
607
+ wheel
608
+ });
609
+ const contextValue = useMemo(() => ({
610
+ emblaRef,
611
+ emblaApi,
612
+ orientation,
613
+ currentIndex,
614
+ isScrollPrev,
615
+ isScrollNext,
616
+ scrollPrev,
617
+ scrollNext
618
+ }), [
619
+ emblaRef,
620
+ emblaApi,
621
+ orientation,
622
+ currentIndex,
623
+ isScrollPrev,
624
+ isScrollNext,
625
+ scrollPrev,
626
+ scrollNext
627
+ ]);
628
+ return /* @__PURE__ */ jsx(CarouselsContext, { value: contextValue, children: /* @__PURE__ */ jsx(
629
+ "div",
630
+ {
631
+ "data-component": "embla-carousels",
632
+ onKeyDownCapture,
633
+ className: cn("relative overflow-hidden", className),
634
+ "aria-roledescription": "embla-carousels",
635
+ role: "region",
636
+ ...props,
637
+ children
638
+ }
639
+ ) });
640
+ });
641
+ memo(({ className, ...props }) => {
642
+ const { emblaRef, orientation } = useCarouselsContext();
643
+ return /* @__PURE__ */ jsx(
644
+ "div",
645
+ {
646
+ ref: emblaRef,
647
+ className: "overflow-hidden",
648
+ "data-component": "embla-carousels-contents",
649
+ children: /* @__PURE__ */ jsx(
650
+ "div",
651
+ {
652
+ className: cn(
653
+ "flex",
654
+ orientation === "x" ? "flex-row" : "flex-col",
655
+ className
656
+ ),
657
+ ...props
658
+ }
659
+ )
660
+ }
661
+ );
662
+ });
663
+ memo(({ className, ...props }) => {
664
+ return /* @__PURE__ */ jsx(
665
+ "div",
666
+ {
667
+ role: "group",
668
+ "aria-roledescription": "slide",
669
+ "data-component": "embla-carousels-slides",
670
+ className: cn(
671
+ "min-w-0 shrink-0 grow-0 basis-full",
672
+ className
673
+ ),
674
+ ...props
675
+ }
676
+ );
677
+ });
678
+ createContext(null);
679
+ var ANCHOR_ATTRIBUTE = "data-anchor";
680
+ var OFFSETER_ATTRIBUTE = "data-anchor-offseter";
681
+ function useAnchors() {
682
+ const [_, animate] = useAnimate();
683
+ const controllerRef = useRef(/* @__PURE__ */ new Map());
684
+ const scrollAnimations = useCallback(({
685
+ controllerKey,
686
+ containerDom,
687
+ anchorScrollValue,
688
+ containerScrollValue,
689
+ direction = "y",
690
+ duration = 1,
691
+ delay = 0,
692
+ ease = [0, 1, 0.5, 0.99],
693
+ onScroll: onPlay,
694
+ onScrolled,
695
+ onScrolling,
696
+ ...props
697
+ }) => {
698
+ if (direction !== "y" && direction !== "x") {
699
+ console.error(`Scroll Direction isn't 'x' or 'y' `);
700
+ return;
701
+ }
702
+ const { left: scrollLeft, top: scrollTop } = containerScrollValue;
703
+ const { left: anchorLeft, top: anchorTop } = anchorScrollValue;
704
+ const isScrollX = direction === "x";
705
+ const isScrollY = direction === "y";
706
+ const startValue = isScrollX ? scrollLeft : scrollTop;
707
+ const endValue = isScrollX ? anchorLeft : anchorTop;
708
+ if (startValue == endValue) {
709
+ controllerRef.current.delete(controllerKey);
710
+ return;
711
+ }
712
+ const motionStartValue = motionValue(startValue);
713
+ const onUpdate = (value) => {
714
+ const left = isScrollX ? value : void 0;
715
+ const top = isScrollY ? value : void 0;
716
+ containerDom.scrollTo({ left, top });
717
+ onScrolling?.(value);
718
+ };
719
+ const onComplete = () => {
720
+ controllerRef.current.delete(controllerKey);
721
+ onScrolled?.();
722
+ };
723
+ const options = {
724
+ duration,
725
+ ease,
726
+ delay,
727
+ onPlay,
728
+ onUpdate,
729
+ onComplete,
730
+ ...props
731
+ };
732
+ controllerRef.current.set(
733
+ controllerKey,
734
+ animate(motionStartValue, endValue, options)
735
+ );
736
+ }, []);
737
+ const scrollToAnchor = useCallback((anchorOptions) => {
738
+ const {
739
+ anchor: anchorName,
740
+ container: containerName,
741
+ offseters,
742
+ align,
743
+ offset = 0,
744
+ direction = "y",
745
+ ...options
746
+ } = anchorOptions;
747
+ const anchorsStores = getAnchorsStores();
748
+ const scrollContainersStores = getScrollContainerStores();
749
+ const isScrolltoAnchor = anchorName !== "#";
750
+ const isScrollContainer = containerName && containerName !== "window";
751
+ const controllerKey = containerName ?? "window";
752
+ if (controllerRef.current.has(controllerKey)) {
753
+ controllerRef.current.get(controllerKey)?.stop();
754
+ controllerRef.current.delete(controllerKey);
755
+ }
756
+ const anchorDom = isScrolltoAnchor ? anchorsStores.anchors.get(anchorName) : void 0;
757
+ if (isScrolltoAnchor && !(anchorDom instanceof HTMLElement)) return;
758
+ const containerDom = isScrollContainer ? scrollContainersStores.containers.get(containerName) : window;
759
+ if (!containerDom) return;
760
+ const getOffseterDomClient = (offseters2) => {
761
+ const offseterDom = anchorsStores.offseters.get(offseters2);
762
+ const { clientWidth, clientHeight } = offseterDom || {};
763
+ return { width: clientWidth ?? 0, height: clientHeight ?? 0 };
764
+ };
765
+ const offsets = Array.isArray(offseters) ? offseters.reduce((init, offseter) => {
766
+ const { width, height } = getOffseterDomClient(offseter);
767
+ return {
768
+ width: (init.width ?? 0) + width,
769
+ height: (init.height ?? 0) + height
770
+ };
771
+ }, {}) : typeof offseters == "string" ? getOffseterDomClient(offseters) : { width: 0, height: 0 };
772
+ const offsetValue = {
773
+ width: direction === "x" ? offsets.width + offset : 0,
774
+ height: direction === "y" ? offsets.height + offset : 0
775
+ };
776
+ const isLenisScroll = containerDom == window && window.document.documentElement.classList.contains("lenis") || containerDom instanceof Lenis;
777
+ if (isLenisScroll) {
778
+ const lenis = isScrollContainer ? containerDom : getRootLenis()?.root;
779
+ if (!lenis) return;
780
+ const directionOffset = direction === "x" ? offsetValue.width + offset : offsetValue.height + offset;
781
+ lenis.scrollTo(
782
+ anchorDom ?? 0,
783
+ {
784
+ offset: directionOffset * -1,
785
+ onStart: (lenis2) => options?.onScroll?.(lenis2),
786
+ onComplete: (lenis2) => options?.onScrolled?.(lenis2)
787
+ }
788
+ );
789
+ return;
790
+ }
791
+ const containerScrollValue = {
792
+ top: Math.round(isScrollContainer ? containerDom.scrollTop : containerDom.pageYOffset),
793
+ left: Math.round(isScrollContainer ? containerDom.scrollLeft : pageXOffset)
794
+ };
795
+ const containerRect = isScrollContainer ? containerDom.getBoundingClientRect() : { top: 0, left: 0 };
796
+ const containerOffsetValue = {
797
+ left: containerScrollValue.left - (isScrollContainer ? containerRect.left : 0),
798
+ top: containerScrollValue.top - (isScrollContainer ? containerRect.top : 0)
799
+ };
800
+ const anchorRect = anchorDom ? anchorDom.getBoundingClientRect() : { left: 0, top: 0 };
801
+ const anchorScrollValue = {
802
+ left: isScrolltoAnchor ? Math.round(anchorRect.left + containerOffsetValue.left - offsetValue.width) : offsetValue.width,
803
+ top: isScrolltoAnchor ? Math.round(anchorRect.top + containerOffsetValue.top - offsetValue.height) : offsetValue.height
804
+ };
805
+ scrollAnimations({
806
+ controllerKey,
807
+ containerDom,
808
+ containerScrollValue,
809
+ anchorScrollValue,
810
+ direction,
811
+ ...options
812
+ });
813
+ }, []);
814
+ const returnsMemo = useMemo(() => ({
815
+ registerAnchors,
816
+ registerOffseters,
817
+ setStores: setAnchorsStore,
818
+ getStores: getAnchorsStores,
819
+ scrollToAnchor
820
+ }), [scrollToAnchor]);
821
+ return returnsMemo;
822
+ }
823
+ function useRegistration({ key, name }) {
824
+ const ref = useRef(null);
825
+ const attribute = key == "anchors" ? ANCHOR_ATTRIBUTE : OFFSETER_ATTRIBUTE;
826
+ useLayoutEffect(() => {
827
+ setAnchorsStore({ key, action: "add", node: ref.current, name });
828
+ return () => {
829
+ setAnchorsStore({ key, action: "remove", node: ref.current, name });
830
+ };
831
+ }, []);
832
+ return { ref, [attribute]: name };
833
+ }
834
+ function registerAnchors(name) {
835
+ return useRegistration({ key: "anchors", name });
836
+ }
837
+ function registerOffseters(name) {
838
+ return useRegistration({ key: "offseters", name });
839
+ }
840
+ var useAnchorsStores = create()(() => ({
841
+ anchors: /* @__PURE__ */ new Map(),
842
+ offseters: /* @__PURE__ */ new Map()
843
+ }));
844
+ var getAnchorsStores = () => useAnchorsStores.getState();
845
+ var setAnchorsStore = (options) => {
846
+ const { key, action, name, node } = options;
847
+ useAnchorsStores.setState((stores) => {
848
+ switch (key) {
849
+ case "anchors":
850
+ const anchorDom = stores.anchors?.get(name);
851
+ if (action == "add" && node instanceof HTMLElement) {
852
+ if (anchorDom == node) return stores;
853
+ stores.anchors?.set(name, node);
854
+ } else if (action == "remove" && anchorDom) {
855
+ stores.anchors?.delete(name);
856
+ }
857
+ return { anchors: stores.anchors };
858
+ case "offseters":
859
+ const offseterDom = stores.offseters?.get(name);
860
+ if (action == "add" && node instanceof HTMLElement) {
861
+ if (offseterDom == node) return stores;
862
+ stores.offseters?.set(name, node);
863
+ } else if (action == "remove" && offseterDom) {
864
+ stores.offseters?.delete(name);
865
+ }
866
+ return { offseters: stores.offseters };
867
+ default:
868
+ return stores;
869
+ }
870
+ });
871
+ };
872
+ function useHash() {
873
+ const [hash, setHash] = useState("");
874
+ const updateHash = () => setHash(window.location.hash);
875
+ const hashchangeEvent = (e) => {
876
+ e.preventDefault?.();
877
+ updateHash();
878
+ };
879
+ useEffect(() => {
880
+ updateHash();
881
+ window.addEventListener("hashchange", hashchangeEvent);
882
+ return () => {
883
+ window.removeEventListener("hashchange", hashchangeEvent);
884
+ };
885
+ }, []);
886
+ return hash;
887
+ }
888
+
889
+ export { getAnchorsStores, registerAnchors, registerOffseters, setAnchorsStore, useAnchors, useAnchorsStores, useAsyncFetcher, useCookies, useDebounce, useDebounceValue, useDragResize, useEffectLeave, useEffectOne, useHash, useMounted, useRegistration };
890
+ //# sourceMappingURL=index.js.map
891
+ //# sourceMappingURL=index.js.map