@xwadex/fesd-next 0.3.3 → 0.3.4-11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +1 -26
  2. package/dist/components/index.d.mts +2 -0
  3. package/dist/components/index.mjs +2 -0
  4. package/dist/components-DMsIAeFi.mjs +975 -0
  5. package/dist/components-DMsIAeFi.mjs.map +1 -0
  6. package/dist/hooks/index.d.mts +2 -0
  7. package/dist/hooks/index.mjs +2 -0
  8. package/dist/index-1SzidEVJ.d.mts +213 -0
  9. package/dist/index-OVM4Yt0j.d.mts +169 -0
  10. package/dist/index.d.mts +6 -0
  11. package/dist/index.mjs +5 -0
  12. package/dist/shadcns/index.d.mts +1332 -0
  13. package/dist/shadcns/index.mjs +2607 -0
  14. package/dist/shadcns/index.mjs.map +1 -0
  15. package/dist/types/index.d.mts +20 -0
  16. package/dist/utils/index.d.mts +17 -0
  17. package/dist/utils/index.mjs +60 -0
  18. package/dist/utils/index.mjs.map +1 -0
  19. package/package.json +59 -47
  20. package/dist/components/index.d.ts +0 -1
  21. package/dist/components/index.js +0 -1
  22. package/dist/components/myComponents/MyComponent.d.ts +0 -2
  23. package/dist/components/myComponents/MyComponent.js +0 -4
  24. package/dist/components/myComponents/MyComponent.module.scss +0 -3
  25. package/dist/components/myComponents/index.d.ts +0 -1
  26. package/dist/components/myComponents/index.js +0 -1
  27. package/dist/hooks/index.d.ts +0 -1
  28. package/dist/hooks/index.js +0 -1
  29. package/dist/hooks/useHooks.d.ts +0 -1
  30. package/dist/hooks/useHooks.js +0 -3
  31. package/dist/index.d.ts +0 -4
  32. package/dist/index.js +0 -4
  33. package/dist/types/index.d.ts +0 -4
  34. package/dist/utils/index.d.ts +0 -1
  35. package/dist/utils/index.js +0 -1
  36. package/dist/utils/someUtil.d.ts +0 -1
  37. package/dist/utils/someUtil.js +0 -3
  38. /package/dist/types/{index.js → index.mjs} +0 -0
@@ -0,0 +1,975 @@
1
+ import { Button, Carousel, CarouselPrevious, cn } from "./shadcns/index.mjs";
2
+ import React, { createContext, memo, use, useCallback, useEffect, useEffectEvent, useLayoutEffect, useMemo, useRef, useState } from "react";
3
+ import Cookies from "js-cookie";
4
+ import { motionValue, useAnimate } from "motion/react";
5
+ import { create } from "zustand";
6
+ import Lenis from "lenis";
7
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
8
+ import useEmblaCarousel from "embla-carousel-react";
9
+ import { ReactLenis, useLenis } from "lenis/react";
10
+ import { WheelGesturesPlugin } from "embla-carousel-wheel-gestures";
11
+ import Autoplay from "embla-carousel-autoplay";
12
+ import AutoScroll from "embla-carousel-auto-scroll";
13
+ import AutoHeight from "embla-carousel-auto-height";
14
+ import ClassNames from "embla-carousel-class-names";
15
+ import Fade from "embla-carousel-fade";
16
+ //#region src/hooks/useDebounce.tsx
17
+ function useDebounce({ callback, dependency = [], delay = 500, active = true }) {
18
+ if (!active || !callback) return;
19
+ const timerRef = useRef(null);
20
+ useEffect(() => {
21
+ if (timerRef.current) clearTimeout(timerRef.current);
22
+ timerRef.current = setTimeout(callback, delay);
23
+ return () => {
24
+ if (timerRef.current) clearTimeout(timerRef.current);
25
+ };
26
+ }, [...dependency]);
27
+ }
28
+ //#endregion
29
+ //#region src/hooks/useDebounceValue.tsx
30
+ function useDebounceValue(value, delay = 500) {
31
+ const [debounceValue, setDebounceValue] = useState(value);
32
+ const timerRef = useRef(void 0);
33
+ useEffect(() => {
34
+ if (timerRef.current) clearTimeout(timerRef.current);
35
+ timerRef.current = setTimeout(() => setDebounceValue(value), delay);
36
+ return () => {
37
+ if (timerRef.current) clearTimeout(timerRef.current);
38
+ };
39
+ }, [value, delay]);
40
+ return debounceValue;
41
+ }
42
+ //#endregion
43
+ //#region src/hooks/useCookies.tsx
44
+ function useCookies() {
45
+ const setCookies = (name, value, days = 7) => {
46
+ Cookies.set(name, value, {
47
+ expires: days,
48
+ path: "/"
49
+ });
50
+ };
51
+ const getCookies = (name) => {
52
+ return Cookies.get(name) ?? null;
53
+ };
54
+ const updateCookies = (name, value, days = 7) => {
55
+ if (getCookies(name) !== null) setCookies(name, value, days);
56
+ };
57
+ const deleteCookies = (name) => {
58
+ Cookies.remove(name, { path: "/" });
59
+ };
60
+ return {
61
+ setCookies,
62
+ getCookies,
63
+ updateCookies,
64
+ deleteCookies
65
+ };
66
+ }
67
+ //#endregion
68
+ //#region src/hooks/useDragResize.tsx
69
+ function useDragResize({ active = true, direction = "horizontal", minWidth, maxWidth, minHeight, maxHeight, onInit, onResizeStart, onResizing, onResizeEnd }) {
70
+ const dragRef = useRef(null);
71
+ const resizeRef = useRef(null);
72
+ const [resize, setResize] = useState({
73
+ width: 0,
74
+ height: 0
75
+ });
76
+ const getResizeSizeValue = () => {
77
+ if (!resizeRef.current) return;
78
+ const { width: w, height: h } = resizeRef.current.style;
79
+ const width = Number(w.replace("px", "")) ?? "inherit";
80
+ Number(h.replace("px", ""));
81
+ return { width };
82
+ };
83
+ const setResizeValue = (clientX, clientY) => {
84
+ if (!resizeRef.current) return;
85
+ const rect = resizeRef.current.getBoundingClientRect();
86
+ const resizeWidth = clientX - rect.left;
87
+ const resizeHeight = clientY - rect.top;
88
+ if (direction == "horizontal" && minWidth && resizeWidth >= minWidth && maxWidth && resizeWidth <= maxWidth) {
89
+ resizeRef.current.style.width = resizeWidth + "px";
90
+ return {
91
+ width: resizeWidth,
92
+ height: void 0
93
+ };
94
+ }
95
+ if (direction == "vertical" && minHeight && resizeWidth >= minHeight && maxHeight && resizeWidth <= maxHeight) {
96
+ resizeRef.current.style.height = resizeHeight + "px";
97
+ return {
98
+ width: void 0,
99
+ height: resizeHeight
100
+ };
101
+ }
102
+ };
103
+ const onInitCallback = () => {
104
+ const resizeValue = getResizeSizeValue();
105
+ resizeValue && onInit?.(resizeValue);
106
+ };
107
+ const removeEventListeners = () => {
108
+ document.removeEventListener("mousemove", onMouseMove);
109
+ document.removeEventListener("mouseup", onMouseUp);
110
+ };
111
+ const onMouseMove = (e) => {
112
+ const resizeValue = setResizeValue(e.clientX, e.clientY);
113
+ if (!resizeValue) return;
114
+ setResize(() => ({ ...resizeValue }));
115
+ onResizing?.(resizeValue);
116
+ };
117
+ const onMouseUp = () => {
118
+ const resizeValue = getResizeSizeValue();
119
+ resizeValue && onResizeEnd?.(resizeValue);
120
+ removeEventListeners();
121
+ };
122
+ const onDragRefMouseDown = (e) => {
123
+ e.preventDefault();
124
+ const resizeValue = getResizeSizeValue();
125
+ resizeValue && onResizeStart?.(resizeValue);
126
+ document.addEventListener("mousemove", onMouseMove);
127
+ document.addEventListener("mouseup", onMouseUp);
128
+ };
129
+ useEffect(() => {
130
+ if (active && dragRef.current && resizeRef.current) {
131
+ dragRef.current.onmousedown = onDragRefMouseDown;
132
+ onInit && onInitCallback();
133
+ }
134
+ return () => {
135
+ if (!dragRef?.current) return;
136
+ dragRef.current.onmousedown = null;
137
+ removeEventListeners();
138
+ };
139
+ }, [active]);
140
+ return {
141
+ dragRef,
142
+ resizeRef,
143
+ resize
144
+ };
145
+ }
146
+ //#endregion
147
+ //#region src/hooks/useAsyncFetcher.tsx
148
+ function useAsyncFetcher() {
149
+ const [isPending, setPending] = useState(false);
150
+ const controllerRef = useRef(null);
151
+ const startFetch = useCallback(async ({ url, options }) => {
152
+ if (isPending || !url) return;
153
+ const controller = new AbortController();
154
+ controllerRef.current = controller;
155
+ setPending(true);
156
+ try {
157
+ return await (await fetch(url, {
158
+ signal: controller.signal,
159
+ ...options
160
+ })).json();
161
+ } catch (error) {
162
+ console.error("useAsyncFetche startFetch error:", error);
163
+ return {
164
+ status: false,
165
+ error
166
+ };
167
+ } finally {
168
+ setPending(false);
169
+ }
170
+ }, [isPending]);
171
+ const cancelFetch = () => {
172
+ controllerRef.current?.abort();
173
+ setPending(false);
174
+ };
175
+ useEffect(() => {
176
+ return () => controllerRef.current?.abort();
177
+ }, []);
178
+ return {
179
+ pending: isPending,
180
+ cancel: cancelFetch,
181
+ fetcher: startFetch
182
+ };
183
+ }
184
+ //#endregion
185
+ //#region src/hooks/useMounted.tsx
186
+ function useMounted() {
187
+ const [isMounded, setMounded] = useState(false);
188
+ useEffect(() => {
189
+ setMounded(true);
190
+ }, []);
191
+ return { isMounded };
192
+ }
193
+ //#endregion
194
+ //#region src/hooks/useEffectOne.tsx
195
+ function useEffectOne(callback) {
196
+ const callbackRef = useRef(callback);
197
+ callbackRef.current = callback;
198
+ useEffect(() => {
199
+ callbackRef.current?.();
200
+ return () => {
201
+ callbackRef.current = null;
202
+ };
203
+ }, []);
204
+ }
205
+ //#endregion
206
+ //#region src/hooks/useEffectLeave.tsx
207
+ function useEffectLeave(callback) {
208
+ const callbackRef = useRef(callback);
209
+ callbackRef.current = callback;
210
+ useEffect(() => {
211
+ return () => {
212
+ callbackRef.current?.();
213
+ callbackRef.current = null;
214
+ };
215
+ }, []);
216
+ }
217
+ //#endregion
218
+ //#region src/hooks/useAnchors.tsx
219
+ const ANCHOR_ATTRIBUTE = "data-anchor";
220
+ const OFFSETER_ATTRIBUTE = "data-anchor-offseter";
221
+ function useAnchors() {
222
+ const [_, animate] = useAnimate();
223
+ const controllerRef = useRef(/* @__PURE__ */ new Map());
224
+ const scrollAnimations = useCallback(({ controllerKey, containerDom, anchorScrollValue, containerScrollValue, direction = "y", duration = 1, delay = 0, ease = [
225
+ 0,
226
+ 1,
227
+ .5,
228
+ .99
229
+ ], onScroll: onPlay, onScrolled, onScrolling, ...props }) => {
230
+ if (direction !== "y" && direction !== "x") {
231
+ console.error(`Scroll Direction isn't 'x' or 'y' `);
232
+ return;
233
+ }
234
+ const { left: scrollLeft, top: scrollTop } = containerScrollValue;
235
+ const { left: anchorLeft, top: anchorTop } = anchorScrollValue;
236
+ const isScrollX = direction === "x";
237
+ const isScrollY = direction === "y";
238
+ const startValue = isScrollX ? scrollLeft : scrollTop;
239
+ const endValue = isScrollX ? anchorLeft : anchorTop;
240
+ if (startValue == endValue) {
241
+ controllerRef.current.delete(controllerKey);
242
+ return;
243
+ }
244
+ const motionStartValue = motionValue(startValue);
245
+ const onUpdate = (value) => {
246
+ const left = isScrollX ? value : void 0;
247
+ const top = isScrollY ? value : void 0;
248
+ containerDom.scrollTo({
249
+ left,
250
+ top
251
+ });
252
+ onScrolling?.(value);
253
+ };
254
+ const onComplete = () => {
255
+ controllerRef.current.delete(controllerKey);
256
+ onScrolled?.();
257
+ };
258
+ const options = {
259
+ duration,
260
+ ease,
261
+ delay,
262
+ onPlay,
263
+ onUpdate,
264
+ onComplete,
265
+ ...props
266
+ };
267
+ controllerRef.current.set(controllerKey, animate(motionStartValue, endValue, options));
268
+ }, []);
269
+ const scrollToAnchor = useCallback((anchorOptions) => {
270
+ const { anchor: anchorName, container: containerName, offseters, align, offset = 0, direction = "y", ...options } = anchorOptions;
271
+ const anchorsStores = getAnchorsStores();
272
+ const scrollContainersStores = getScrollContainerStores();
273
+ const isScrolltoAnchor = anchorName !== "#";
274
+ const isScrollContainer = containerName && containerName !== "window";
275
+ const controllerKey = containerName ?? "window";
276
+ if (controllerRef.current.has(controllerKey)) {
277
+ controllerRef.current.get(controllerKey)?.stop();
278
+ controllerRef.current.delete(controllerKey);
279
+ }
280
+ const anchorDom = isScrolltoAnchor ? anchorsStores.anchors.get(anchorName) : void 0;
281
+ if (isScrolltoAnchor && !(anchorDom instanceof HTMLElement)) return;
282
+ const containerDom = isScrollContainer ? scrollContainersStores.containers.get(containerName) : window;
283
+ if (!containerDom) return;
284
+ const getOffseterDomClient = (offseters) => {
285
+ const { clientWidth, clientHeight } = anchorsStores.offseters.get(offseters) || {};
286
+ return {
287
+ width: clientWidth ?? 0,
288
+ height: clientHeight ?? 0
289
+ };
290
+ };
291
+ const offsets = Array.isArray(offseters) ? offseters.reduce((init, offseter) => {
292
+ const { width, height } = getOffseterDomClient(offseter);
293
+ return {
294
+ width: (init.width ?? 0) + width,
295
+ height: (init.height ?? 0) + height
296
+ };
297
+ }, {}) : typeof offseters == "string" ? getOffseterDomClient(offseters) : {
298
+ width: 0,
299
+ height: 0
300
+ };
301
+ const offsetValue = {
302
+ width: direction === "x" ? offsets.width + offset : 0,
303
+ height: direction === "y" ? offsets.height + offset : 0
304
+ };
305
+ if (containerDom == window && window.document.documentElement.classList.contains("lenis") || containerDom instanceof Lenis) {
306
+ const lenis = isScrollContainer ? containerDom : getRootLenis()?.root;
307
+ if (!lenis) return;
308
+ const directionOffset = direction === "x" ? offsetValue.width + offset : offsetValue.height + offset;
309
+ lenis.scrollTo(anchorDom ?? 0, {
310
+ offset: directionOffset * -1,
311
+ onStart: (lenis) => options?.onScroll?.(lenis),
312
+ onComplete: (lenis) => options?.onScrolled?.(lenis)
313
+ });
314
+ return;
315
+ }
316
+ const containerScrollValue = {
317
+ top: Math.round(isScrollContainer ? containerDom.scrollTop : containerDom.pageYOffset),
318
+ left: Math.round(isScrollContainer ? containerDom.scrollLeft : pageXOffset)
319
+ };
320
+ const containerRect = isScrollContainer ? containerDom.getBoundingClientRect() : {
321
+ top: 0,
322
+ left: 0
323
+ };
324
+ const containerOffsetValue = {
325
+ left: containerScrollValue.left - (isScrollContainer ? containerRect.left : 0),
326
+ top: containerScrollValue.top - (isScrollContainer ? containerRect.top : 0)
327
+ };
328
+ const anchorRect = anchorDom ? anchorDom.getBoundingClientRect() : {
329
+ left: 0,
330
+ top: 0
331
+ };
332
+ scrollAnimations({
333
+ controllerKey,
334
+ containerDom,
335
+ containerScrollValue,
336
+ anchorScrollValue: {
337
+ left: isScrolltoAnchor ? Math.round(anchorRect.left + containerOffsetValue.left - offsetValue.width) : offsetValue.width,
338
+ top: isScrolltoAnchor ? Math.round(anchorRect.top + containerOffsetValue.top - offsetValue.height) : offsetValue.height
339
+ },
340
+ direction,
341
+ ...options
342
+ });
343
+ }, []);
344
+ return useMemo(() => ({
345
+ registerAnchors,
346
+ registerOffseters,
347
+ setStores: setAnchorsStore,
348
+ getStores: getAnchorsStores,
349
+ scrollToAnchor
350
+ }), [scrollToAnchor]);
351
+ }
352
+ function useRegistration({ key, name }) {
353
+ const ref = useRef(null);
354
+ const attribute = key == "anchors" ? ANCHOR_ATTRIBUTE : OFFSETER_ATTRIBUTE;
355
+ useLayoutEffect(() => {
356
+ setAnchorsStore({
357
+ key,
358
+ action: "add",
359
+ node: ref.current,
360
+ name
361
+ });
362
+ return () => {
363
+ setAnchorsStore({
364
+ key,
365
+ action: "remove",
366
+ node: ref.current,
367
+ name
368
+ });
369
+ };
370
+ }, []);
371
+ return {
372
+ ref,
373
+ [attribute]: name
374
+ };
375
+ }
376
+ function registerAnchors(name) {
377
+ return useRegistration({
378
+ key: "anchors",
379
+ name
380
+ });
381
+ }
382
+ function registerOffseters(name) {
383
+ return useRegistration({
384
+ key: "offseters",
385
+ name
386
+ });
387
+ }
388
+ const useAnchorsStores = create()(() => ({
389
+ anchors: /* @__PURE__ */ new Map(),
390
+ offseters: /* @__PURE__ */ new Map()
391
+ }));
392
+ const getAnchorsStores = () => useAnchorsStores.getState();
393
+ const setAnchorsStore = (options) => {
394
+ const { key, action, name, node } = options;
395
+ useAnchorsStores.setState((stores) => {
396
+ switch (key) {
397
+ case "anchors":
398
+ const anchorDom = stores.anchors?.get(name);
399
+ if (action == "add" && node instanceof HTMLElement) {
400
+ if (anchorDom == node) return stores;
401
+ stores.anchors?.set(name, node);
402
+ } else if (action == "remove" && anchorDom) stores.anchors?.delete(name);
403
+ return { anchors: stores.anchors };
404
+ case "offseters":
405
+ const offseterDom = stores.offseters?.get(name);
406
+ if (action == "add" && node instanceof HTMLElement) {
407
+ if (offseterDom == node) return stores;
408
+ stores.offseters?.set(name, node);
409
+ } else if (action == "remove" && offseterDom) stores.offseters?.delete(name);
410
+ return { offseters: stores.offseters };
411
+ default: return stores;
412
+ }
413
+ });
414
+ };
415
+ //#endregion
416
+ //#region src/hooks/useHash.tsx
417
+ function useHash() {
418
+ const [hash, setHash] = useState("");
419
+ const updateHash = () => setHash(window.location.hash);
420
+ const hashchangeEvent = (e) => {
421
+ e.preventDefault?.();
422
+ updateHash();
423
+ };
424
+ useEffect(() => {
425
+ updateHash();
426
+ window.addEventListener("hashchange", hashchangeEvent);
427
+ return () => {
428
+ window.removeEventListener("hashchange", hashchangeEvent);
429
+ };
430
+ }, []);
431
+ return hash;
432
+ }
433
+ //#endregion
434
+ //#region src/components/anchors/anchors.tsx
435
+ const AnchorTarget = ({ name, ...props }) => {
436
+ const { registerAnchors } = useAnchors();
437
+ return /* @__PURE__ */ jsx("div", {
438
+ ...props,
439
+ ...registerAnchors(name)
440
+ });
441
+ };
442
+ const AnchorOffseter = ({ name, ...props }) => {
443
+ const { registerOffseters } = useAnchors();
444
+ return /* @__PURE__ */ jsx("div", {
445
+ ...props,
446
+ ...registerOffseters(name)
447
+ });
448
+ };
449
+ const AnchorTrigger = ({ children, className, ...options }) => {
450
+ const { scrollToAnchor } = useAnchors();
451
+ return /* @__PURE__ */ jsx("div", {
452
+ className: cn(className),
453
+ onClick: () => scrollToAnchor(options),
454
+ children
455
+ });
456
+ };
457
+ const Anchors = {
458
+ Trigger: AnchorTrigger,
459
+ Target: AnchorTarget,
460
+ Offseter: AnchorOffseter
461
+ };
462
+ //#endregion
463
+ //#region src/components/scroll-containers/lenis-scroll.tsx
464
+ const LenisScroll = memo((props) => {
465
+ return /* @__PURE__ */ jsxs(Fragment, { children: [props?.root == true ? /* @__PURE__ */ jsx(LenisRootScroll, { ...props }) : /* @__PURE__ */ jsx(LenisContainerScroll, { ...props }), " "] });
466
+ });
467
+ const LenisRootScroll = memo(({ root, options }) => {
468
+ const lenis = useLenis();
469
+ const lenisRef = useRef(null);
470
+ const registerRootLenis = useEffectEvent(() => {
471
+ if (!root == true || !lenis) return;
472
+ setRootLenis(lenis);
473
+ });
474
+ useEffect(() => {
475
+ registerRootLenis();
476
+ }, [lenis]);
477
+ return /* @__PURE__ */ jsx(ReactLenis, {
478
+ ref: lenisRef,
479
+ root,
480
+ options: {
481
+ autoRaf: true,
482
+ lerp: 5e-4,
483
+ duration: 1.5,
484
+ smoothWheel: true,
485
+ ...options
486
+ }
487
+ });
488
+ });
489
+ const LenisContainerScroll = memo(({ name, className, children, options, ...restProps }) => {
490
+ const [containerRef, setContainerRef] = useState();
491
+ const wrapperRef = useRef(null);
492
+ const contentRef = useRef(null);
493
+ const initLenis = useEffectEvent(() => {
494
+ if (!wrapperRef.current || !contentRef.current || !name) return;
495
+ const lenis = new Lenis({
496
+ wrapper: wrapperRef.current,
497
+ content: contentRef.current,
498
+ autoRaf: true,
499
+ ...options
500
+ });
501
+ setContainerRef(contentRef);
502
+ setScrollContainerStore({
503
+ name,
504
+ action: "add",
505
+ node: lenis
506
+ });
507
+ return () => {
508
+ setScrollContainerStore({
509
+ name,
510
+ action: "remove"
511
+ });
512
+ lenis?.destroy?.();
513
+ };
514
+ });
515
+ useLayoutEffect(() => {
516
+ return initLenis();
517
+ }, [name, options]);
518
+ return /* @__PURE__ */ jsx("div", {
519
+ ref: wrapperRef,
520
+ "data-lenis-scroll": name,
521
+ className: cn("group overflow-hidden", className),
522
+ ...restProps,
523
+ children: /* @__PURE__ */ jsx("div", {
524
+ ref: contentRef,
525
+ className: cn("h-full", "relative", "will-change-transform overscroll-contain"),
526
+ children: /* @__PURE__ */ jsx(ScrollContainerContext, {
527
+ value: { containerRef },
528
+ children
529
+ })
530
+ })
531
+ });
532
+ });
533
+ const useLenisStores = create()(() => ({ root: null }));
534
+ const setRootLenis = (lenis) => useLenisStores.setState(() => {
535
+ return { root: lenis };
536
+ });
537
+ const getRootLenis = () => useLenisStores.getState();
538
+ //#endregion
539
+ //#region src/components/scroll-containers/scroll-containers.tsx
540
+ const ScrollContainer = ({ name, lenis = false, ...props }) => {
541
+ return /* @__PURE__ */ jsx(Fragment, { children: lenis ? /* @__PURE__ */ jsx(LenisScroll, {
542
+ name,
543
+ ...props
544
+ }) : /* @__PURE__ */ jsx(NativeScroll, {
545
+ name,
546
+ ...props
547
+ }) });
548
+ };
549
+ const ScrollContainerContext = createContext(null);
550
+ const useScrollContainerContext = () => {
551
+ const context = use(ScrollContainerContext);
552
+ if (!context) throw new Error("useScrollContainerContext must be used inside ScrollContainerProvider");
553
+ return context;
554
+ };
555
+ const useScrollContainersStores = create()(() => ({ containers: /* @__PURE__ */ new Map() }));
556
+ const getScrollContainer = (name) => {
557
+ return useScrollContainersStores.getState().containers?.get(name);
558
+ };
559
+ const getScrollContainerStores = () => useScrollContainersStores.getState();
560
+ const setScrollContainerStore = (options) => {
561
+ const { action, name, node } = options;
562
+ useScrollContainersStores.setState((stores) => {
563
+ const containerDom = stores.containers?.get(name);
564
+ const isContainerNode = node instanceof Lenis || node instanceof HTMLDivElement;
565
+ if (action == "add" && isContainerNode) {
566
+ if (containerDom == node) return stores;
567
+ stores.containers?.set(name, node);
568
+ } else if (action == "remove" && containerDom) stores.containers?.delete(name);
569
+ return { containers: stores.containers };
570
+ });
571
+ };
572
+ //#endregion
573
+ //#region src/components/scroll-containers/native-scroll.tsx
574
+ const NativeScroll = memo(({ tag: Component = "div", name, className, ...restProps }) => {
575
+ const componentRef = useRef(null);
576
+ const [containerRef, setContainerRef] = useState();
577
+ const nativeEffect = useEffectEvent(() => {
578
+ if (!componentRef.current) return;
579
+ setContainerRef(componentRef);
580
+ setScrollContainerStore({
581
+ name,
582
+ action: "add",
583
+ node: componentRef.current
584
+ });
585
+ return () => {
586
+ setScrollContainerStore({
587
+ name,
588
+ action: "remove"
589
+ });
590
+ };
591
+ });
592
+ useEffect(() => {
593
+ return nativeEffect();
594
+ }, [componentRef?.current]);
595
+ return /* @__PURE__ */ jsx(ScrollContainerContext, {
596
+ value: { containerRef },
597
+ children: /* @__PURE__ */ jsx(Component, {
598
+ ref: componentRef,
599
+ "data-native-scroll": name,
600
+ className: cn("overflow-auto", "will-change-transform", className),
601
+ ...restProps
602
+ })
603
+ });
604
+ });
605
+ //#endregion
606
+ //#region src/components/embla-carousels/embla-carousels-hooks.tsx
607
+ function emblaCarouselsHooks({ options, autoplay, autoScroll, classNames, autoHeight, fade, wheel, setApi }) {
608
+ const orientation = options?.axis ?? "x";
609
+ const [emblaRef, emblaApi] = useEmblaCarousel(options, useMemo(() => [
610
+ autoplay && Autoplay(typeof autoplay == "boolean" ? void 0 : autoplay),
611
+ autoScroll && AutoScroll(typeof autoScroll == "boolean" ? void 0 : autoScroll),
612
+ autoHeight && AutoHeight(typeof autoHeight == "boolean" ? void 0 : autoHeight),
613
+ classNames && ClassNames(typeof classNames == "boolean" ? void 0 : classNames),
614
+ fade && Fade(typeof fade == "boolean" ? void 0 : fade),
615
+ wheel && WheelGesturesPlugin(typeof wheel == "boolean" ? void 0 : wheel)
616
+ ].filter((plugin) => plugin), [
617
+ autoplay,
618
+ autoScroll,
619
+ classNames,
620
+ fade,
621
+ wheel,
622
+ autoHeight
623
+ ]));
624
+ const [currentIndex, setCurrentIndex] = useState(0);
625
+ const [isScrollPrev, setIsScrollPrev] = useState(false);
626
+ const [isScrollNext, setIsScrollNext] = useState(false);
627
+ const scrollPrev = useCallback(() => {
628
+ emblaApi?.scrollPrev();
629
+ }, [emblaApi]);
630
+ const scrollNext = useCallback(() => {
631
+ emblaApi?.scrollNext();
632
+ }, [emblaApi]);
633
+ const onKeyDownCapture = useCallback((event) => {
634
+ console.log("key...");
635
+ if (event.key === "ArrowLeft") {
636
+ event.preventDefault();
637
+ scrollPrev();
638
+ } else if (event.key === "ArrowRight") {
639
+ event.preventDefault();
640
+ scrollNext();
641
+ }
642
+ }, [scrollPrev, scrollNext]);
643
+ const onSelect = useCallback((api) => {
644
+ if (!api) return;
645
+ setCurrentIndex(api?.selectedScrollSnap());
646
+ setIsScrollPrev(api.canScrollPrev());
647
+ setIsScrollNext(api.canScrollNext());
648
+ }, []);
649
+ const initalEffect = useEffectEvent(() => {
650
+ if (!emblaApi || !setApi) return;
651
+ setApi?.(emblaApi);
652
+ onSelect(emblaApi);
653
+ emblaApi.on("reInit", onSelect);
654
+ emblaApi.on("select", onSelect);
655
+ return () => {
656
+ emblaApi?.off("select", onSelect);
657
+ };
658
+ });
659
+ useEffect(() => {
660
+ const events = initalEffect();
661
+ return () => {
662
+ events?.();
663
+ };
664
+ }, [emblaApi]);
665
+ return {
666
+ emblaRef,
667
+ emblaApi,
668
+ orientation,
669
+ currentIndex,
670
+ isScrollPrev,
671
+ isScrollNext,
672
+ scrollPrev,
673
+ scrollNext,
674
+ onKeyDownCapture
675
+ };
676
+ }
677
+ //#endregion
678
+ //#region src/components/embla-carousels/embla-carousels.tsx
679
+ const CarouselsContext = createContext(null);
680
+ const useCarouselsContext = () => {
681
+ const context = use(CarouselsContext);
682
+ if (!context) throw new Error("useCarousel must be used within a <Carousel />");
683
+ return context;
684
+ };
685
+ const EmblaCarouselsRoots = memo(({ children, className, setApi, options, autoplay, autoScroll, classNames, autoHeight, fade, wheel, ...props }) => {
686
+ const { emblaRef, emblaApi, orientation, currentIndex, isScrollPrev, isScrollNext, scrollPrev, scrollNext, onKeyDownCapture } = emblaCarouselsHooks({
687
+ setApi,
688
+ options,
689
+ autoplay,
690
+ autoScroll,
691
+ classNames,
692
+ autoHeight,
693
+ fade,
694
+ wheel
695
+ });
696
+ return /* @__PURE__ */ jsx(CarouselsContext, {
697
+ value: useMemo(() => ({
698
+ emblaRef,
699
+ emblaApi,
700
+ orientation,
701
+ currentIndex,
702
+ isScrollPrev,
703
+ isScrollNext,
704
+ scrollPrev,
705
+ scrollNext
706
+ }), [
707
+ emblaRef,
708
+ emblaApi,
709
+ orientation,
710
+ currentIndex,
711
+ isScrollPrev,
712
+ isScrollNext,
713
+ scrollPrev,
714
+ scrollNext
715
+ ]),
716
+ children: /* @__PURE__ */ jsx("div", {
717
+ "data-component": "embla-carousels",
718
+ onKeyDownCapture,
719
+ className: cn("relative overflow-hidden", className),
720
+ "aria-roledescription": "embla-carousels",
721
+ role: "region",
722
+ ...props,
723
+ children
724
+ })
725
+ });
726
+ });
727
+ const EmblaCarouselsContents = memo(({ className, ...props }) => {
728
+ const { emblaRef, orientation } = useCarouselsContext();
729
+ return /* @__PURE__ */ jsx("div", {
730
+ ref: emblaRef,
731
+ className: "overflow-hidden",
732
+ "data-component": "embla-carousels-contents",
733
+ children: /* @__PURE__ */ jsx("div", {
734
+ className: cn("flex", orientation === "x" ? "flex-row" : "flex-col", className),
735
+ ...props
736
+ })
737
+ });
738
+ });
739
+ const EmblaCarouselsSlides = memo(({ className, ...props }) => {
740
+ return /* @__PURE__ */ jsx("div", {
741
+ role: "group",
742
+ "aria-roledescription": "slide",
743
+ "data-component": "embla-carousels-slides",
744
+ className: cn("min-w-0 shrink-0 grow-0 basis-full", className),
745
+ ...props
746
+ });
747
+ });
748
+ const EmblaCarousels = {
749
+ Roots: EmblaCarouselsRoots,
750
+ Contents: EmblaCarouselsContents,
751
+ Slides: EmblaCarouselsSlides
752
+ };
753
+ //#endregion
754
+ //#region src/components/emblas/embla-context.tsx
755
+ const CarouselContext = createContext(null);
756
+ const CarouselContextProvider = (props) => {
757
+ return /* @__PURE__ */ jsx(CarouselContext, { ...props });
758
+ };
759
+ const useCarouselContext = () => {
760
+ const context = use(CarouselContext);
761
+ if (!context) throw new Error("useCMSData must be used inside CMSProvider");
762
+ return context;
763
+ };
764
+ //#endregion
765
+ //#region src/components/emblas/embla.tsx
766
+ const Embla = ({ children, className, options, datas, autoplayEnabled = true, autoplayOptions, setApi, setMethods, setRef, style, controls, onScrolled }) => {
767
+ const { loop, duration = 40 } = options || {};
768
+ const autoplaySetting = useMemo(() => {
769
+ if (!autoplayEnabled) return;
770
+ return [Autoplay({
771
+ playOnInit: true,
772
+ delay: 5e3,
773
+ stopOnInteraction: false,
774
+ ...autoplayOptions
775
+ })];
776
+ }, [autoplayEnabled, autoplayOptions]);
777
+ const [emblaRef, emblaApi] = useEmblaCarousel({
778
+ ...options,
779
+ loop,
780
+ duration
781
+ }, autoplaySetting);
782
+ const [selectIndex, setSelectIndex] = useState(0);
783
+ const [scrollSnaps, setScrollSnaps] = useState([]);
784
+ const nextScroll = useCallback(() => {
785
+ if (!emblaApi) return;
786
+ const { canScrollNext, scrollNext } = emblaApi;
787
+ canScrollNext() && scrollNext() && autoPlayReset();
788
+ }, [emblaApi]);
789
+ const prevScroll = useCallback(() => {
790
+ if (!emblaApi) return;
791
+ const { canScrollPrev, scrollPrev } = emblaApi;
792
+ canScrollPrev() && scrollPrev() && autoPlayReset();
793
+ }, [emblaApi]);
794
+ const scrollToIndex = useCallback((index) => {
795
+ if (!emblaApi || typeof index !== "number") return;
796
+ emblaApi.scrollTo(index);
797
+ }, [emblaApi]);
798
+ const autoPlayReset = useCallback(() => {
799
+ if (!emblaApi) return;
800
+ const autoplay = emblaApi?.plugins()?.autoplay;
801
+ autoplay && autoplay.reset();
802
+ }, [emblaApi]);
803
+ const autoPlayPlay = useCallback(() => {
804
+ if (!emblaApi) return;
805
+ if (!emblaApi.canScrollNext()) return;
806
+ const autoplay = emblaApi?.plugins()?.autoplay;
807
+ autoplay && autoplay.play();
808
+ }, [emblaApi]);
809
+ const autoPlayStop = useCallback(() => {
810
+ if (!emblaApi) return;
811
+ const autoplay = emblaApi?.plugins()?.autoplay;
812
+ autoplay && autoplay.stop();
813
+ }, [emblaApi]);
814
+ const contextValue = useMemo(() => ({
815
+ datas,
816
+ emblaRef,
817
+ emblaApi,
818
+ selectIndex,
819
+ scrollSnaps,
820
+ nextScroll,
821
+ prevScroll,
822
+ scrollToIndex,
823
+ autoPlayReset,
824
+ autoPlayStop,
825
+ autoPlayPlay
826
+ }), [
827
+ datas,
828
+ emblaRef,
829
+ emblaApi,
830
+ selectIndex,
831
+ scrollSnaps,
832
+ nextScroll,
833
+ prevScroll,
834
+ scrollToIndex,
835
+ autoPlayReset,
836
+ autoPlayStop,
837
+ autoPlayPlay
838
+ ]);
839
+ const onInit = useCallback((emblaApi) => {
840
+ setScrollSnaps(emblaApi.scrollSnapList());
841
+ }, []);
842
+ const onSelectEvent = (emblaApi) => {
843
+ emblaApi.on("select", () => {
844
+ onScrolled?.(emblaApi.selectedScrollSnap());
845
+ setSelectIndex(emblaApi.selectedScrollSnap());
846
+ });
847
+ };
848
+ useEffect(() => {
849
+ if (!emblaApi) return;
850
+ setRef?.(emblaRef);
851
+ setApi?.(emblaApi);
852
+ setMethods?.({});
853
+ onInit(emblaApi);
854
+ onSelectEvent(emblaApi);
855
+ }, [emblaApi]);
856
+ return /* @__PURE__ */ jsx(CarouselContextProvider, {
857
+ value: contextValue,
858
+ children: /* @__PURE__ */ jsxs("div", {
859
+ "data-component": "embla-root",
860
+ className: cn("relative w-full"),
861
+ children: [/* @__PURE__ */ jsx("div", {
862
+ className: cn("overflow-hidden", "w-full", className),
863
+ ref: emblaRef,
864
+ style,
865
+ children
866
+ }), Array.isArray(controls) ? controls.map((ctrl, i) => /* @__PURE__ */ jsx(React.Fragment, { children: ctrl }, i)) : controls]
867
+ })
868
+ });
869
+ };
870
+ Embla.displayName = "Embla";
871
+ //#endregion
872
+ //#region src/components/emblas/embla-container.tsx
873
+ const EmblaContainer = ({ slide: SlideComponent, className, children, style, ...props }) => {
874
+ const { datas, emblaApi } = useCarouselContext();
875
+ return /* @__PURE__ */ jsxs("div", {
876
+ "data-component": "embla-container",
877
+ className: cn("flex", className, !emblaApi?.canScrollNext() && !emblaApi?.canScrollPrev() && ["transform-[unset!important]"]),
878
+ style: { ...style },
879
+ children: [SlideComponent && datas?.map((item, index) => /* @__PURE__ */ jsx(SlideComponent, {
880
+ ...item,
881
+ index,
882
+ ...props
883
+ }, item?.multipurpose?.key ?? item?.id ?? index)), children]
884
+ });
885
+ };
886
+ EmblaContainer.displayName = "EmblaContainer";
887
+ //#endregion
888
+ //#region src/components/emblas/emblas-pagination.tsx
889
+ const EmblaPagination = ({ color = "black", align, className, maxDots = 5, dynamic = true, swiperNumber = true }) => {
890
+ const { selectIndex, scrollToIndex, scrollSnaps, autoPlayReset, emblaApi } = useCarouselContext();
891
+ const total = scrollSnaps?.length ?? 0;
892
+ const active = Math.max(0, Math.min(selectIndex ?? 0, Math.max(0, total - 1)));
893
+ const paginationNumber = `${Number(active + 1) < 10 ? "0" + Number(active + 1) : Number(active + 1)}`;
894
+ const isWhite = color === "white";
895
+ const clickEvent = (index) => {
896
+ scrollToIndex(index);
897
+ autoPlayReset();
898
+ };
899
+ const isSelected = (index) => {
900
+ return index === selectIndex;
901
+ };
902
+ const [selectedIndex, setSelectedIndex] = useState(0);
903
+ const [slideCount, setSlideCount] = useState(0);
904
+ useEffect(() => {
905
+ if (!emblaApi || !dynamic) return;
906
+ const update = () => {
907
+ setSelectedIndex(emblaApi.selectedScrollSnap());
908
+ setSlideCount(emblaApi.scrollSnapList().length);
909
+ };
910
+ emblaApi.on("select", update);
911
+ emblaApi.on("reInit", update);
912
+ update();
913
+ return () => {
914
+ emblaApi.off("select", update);
915
+ emblaApi.off("reInit", update);
916
+ };
917
+ }, [emblaApi, dynamic]);
918
+ const getVisibleBullets = () => {
919
+ const total = slideCount ?? 0;
920
+ if (total === 0) return [];
921
+ const limit = Math.max(1, Number(maxDots));
922
+ const windowSize = Math.min(total, limit);
923
+ const left = Math.floor((windowSize - 1) / 2);
924
+ const right = windowSize - left - 1;
925
+ let start = selectedIndex - left;
926
+ let end = selectedIndex + right;
927
+ if (start < 0) {
928
+ end = Math.min(end - start, total - 1);
929
+ start = 0;
930
+ }
931
+ if (end > total - 1) {
932
+ start = Math.max(0, start - (end - (total - 1)));
933
+ end = total - 1;
934
+ }
935
+ return Array.from({ length: end - start + 1 }, (_, i) => start + i);
936
+ };
937
+ const visibleRange = getVisibleBullets();
938
+ const dots = dynamic ? visibleRange : scrollSnaps?.map((_, i) => i) ?? [];
939
+ const swiperSnap = [
940
+ "text-[16px]",
941
+ "font-semibold",
942
+ " leading-[1.4]"
943
+ ];
944
+ const paginationColorStyle2 = { "--pagination-color": {
945
+ "black": "#000",
946
+ "white": "#fff"
947
+ }[color] || `${color}` };
948
+ return /* @__PURE__ */ jsxs("div", {
949
+ "data-compoents": "emblas-pagination",
950
+ className: cn("flex", "items-center", "gap-7.25", align === "center" && ["justify-center"], className),
951
+ style: paginationColorStyle2,
952
+ children: [swiperNumber && /* @__PURE__ */ jsx("div", {
953
+ className: cn(swiperSnap, "relative", "after:absolute", "after:top-1/2", "after:right-[-15px]", "after:-translate-y-1/2", "after:block", "after:bg-(--pagination-color)", "after:w-0.5", "after:h-3.75", "after:opacity-20", isWhite && ["after:bg-white"]),
954
+ children: paginationNumber
955
+ }), /* @__PURE__ */ jsx("div", {
956
+ className: cn("flex", "flex-wrap", "justify-end", "items-center", "gap-y-0", "gap-x-2.5", "**:data-[component='emblas-pagination-dots']:bg-(--pagination-color)", isWhite && ["**:data-[component='emblas-pagination-dots']:bg-white"]),
957
+ children: dots.map((index) => /* @__PURE__ */ jsx("div", {
958
+ "data-component": "emblas-pagination-dots",
959
+ onClick: () => clickEvent(index),
960
+ className: cn("w-1.5", "h-1.5", "rounded-full", "cursor-pointer", "opacity-30", isSelected(index) && "opacity-100")
961
+ }, index))
962
+ })]
963
+ });
964
+ };
965
+ EmblaPagination.displayName = "EmblaPagination";
966
+ //#endregion
967
+ //#region src/components/tests/tests.tsx
968
+ const Tests = () => {
969
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Carousel, { children: /* @__PURE__ */ jsx(CarouselPrevious, {}) }), /* @__PURE__ */ jsx(Button, { children: "test123133232" })] });
970
+ };
971
+ Tests.displayName = "Tests";
972
+ //#endregion
973
+ export { Anchors as A, useEffectOne as B, LenisScroll as C, AnchorOffseter as D, useLenisStores as E, setAnchorsStore as F, useDebounceValue as G, useAsyncFetcher as H, useAnchors as I, useDebounce as K, useAnchorsStores as L, getAnchorsStores as M, registerAnchors as N, AnchorTarget as O, registerOffseters as P, useRegistration as R, LenisRootScroll as S, setRootLenis as T, useDragResize as U, useMounted as V, useCookies as W, getScrollContainerStores as _, CarouselContextProvider as a, useScrollContainersStores as b, EmblaCarouselsContents as c, useCarouselsContext as d, emblaCarouselsHooks as f, getScrollContainer as g, ScrollContainerContext as h, Embla as i, useHash as j, AnchorTrigger as k, EmblaCarouselsRoots as l, ScrollContainer as m, EmblaPagination as n, useCarouselContext as o, NativeScroll as p, EmblaContainer as r, EmblaCarousels as s, Tests as t, EmblaCarouselsSlides as u, setScrollContainerStore as v, getRootLenis as w, LenisContainerScroll as x, useScrollContainerContext as y, useEffectLeave as z };
974
+
975
+ //# sourceMappingURL=components-DMsIAeFi.mjs.map