@xwadex/fesd-next 0.3.4-7.0 → 0.3.4-7.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.
Files changed (125) hide show
  1. package/dist/components/anchors/anchors.d.ts +16 -0
  2. package/dist/components/anchors/anchors.js +26 -0
  3. package/dist/components/anchors/index.d.ts +1 -0
  4. package/dist/components/anchors/index.js +1 -0
  5. package/dist/components/index.d.ts +2 -2
  6. package/dist/components/index.js +2 -2
  7. package/dist/components/tests/index.d.ts +1 -0
  8. package/dist/components/tests/index.js +1 -0
  9. package/dist/components/tests/tests.d.ts +4 -0
  10. package/dist/components/tests/tests.js +10 -0
  11. package/dist/hooks/index.d.ts +3 -0
  12. package/dist/hooks/index.js +3 -0
  13. package/dist/hooks/useAnchors.d.ts +41 -27
  14. package/dist/hooks/useAnchors.js +146 -97
  15. package/dist/hooks/useHash.d.ts +1 -0
  16. package/dist/hooks/useHash.js +19 -0
  17. package/dist/hooks/useScrollContainers.d.ts +27 -0
  18. package/dist/hooks/useScrollContainers.js +53 -0
  19. package/dist/index.d.ts +1 -0
  20. package/dist/index.js +1 -0
  21. package/dist/shadcns/components/ui/accordion.d.ts +7 -0
  22. package/dist/shadcns/components/ui/accordion.js +18 -0
  23. package/dist/shadcns/components/ui/alert-dialog.d.ts +14 -0
  24. package/dist/shadcns/components/ui/alert-dialog.js +38 -0
  25. package/dist/shadcns/components/ui/alert.d.ts +9 -0
  26. package/dist/shadcns/components/ui/alert.js +25 -0
  27. package/dist/shadcns/components/ui/aspect-ratio.d.ts +3 -0
  28. package/dist/shadcns/components/ui/aspect-ratio.js +7 -0
  29. package/dist/shadcns/components/ui/avatar.d.ts +6 -0
  30. package/dist/shadcns/components/ui/avatar.js +14 -0
  31. package/dist/shadcns/components/ui/badge.d.ts +9 -0
  32. package/dist/shadcns/components/ui/badge.js +23 -0
  33. package/dist/shadcns/components/ui/breadcrumb.d.ts +11 -0
  34. package/dist/shadcns/components/ui/breadcrumb.js +27 -0
  35. package/dist/shadcns/components/ui/button.d.ts +10 -0
  36. package/dist/shadcns/components/ui/button.js +32 -0
  37. package/dist/shadcns/components/ui/calendar.d.ts +8 -0
  38. package/dist/shadcns/components/ui/calendar.js +73 -0
  39. package/dist/shadcns/components/ui/card.d.ts +9 -0
  40. package/dist/shadcns/components/ui/card.js +25 -0
  41. package/dist/shadcns/components/ui/carousel.d.ts +19 -0
  42. package/dist/shadcns/components/ui/carousel.js +91 -0
  43. package/dist/shadcns/components/ui/chart.d.ts +40 -0
  44. package/dist/shadcns/components/ui/chart.js +114 -0
  45. package/dist/shadcns/components/ui/checkbox.d.ts +4 -0
  46. package/dist/shadcns/components/ui/checkbox.js +9 -0
  47. package/dist/shadcns/components/ui/collapsible.d.ts +5 -0
  48. package/dist/shadcns/components/ui/collapsible.js +13 -0
  49. package/dist/shadcns/components/ui/command.d.ts +18 -0
  50. package/dist/shadcns/components/ui/command.js +33 -0
  51. package/dist/shadcns/components/ui/context-menu.d.ts +25 -0
  52. package/dist/shadcns/components/ui/context-menu.js +51 -0
  53. package/dist/shadcns/components/ui/dialog.d.ts +15 -0
  54. package/dist/shadcns/components/ui/dialog.js +36 -0
  55. package/dist/shadcns/components/ui/drawer.d.ts +13 -0
  56. package/dist/shadcns/components/ui/drawer.js +35 -0
  57. package/dist/shadcns/components/ui/dropdown-menu.d.ts +25 -0
  58. package/dist/shadcns/components/ui/dropdown-menu.js +51 -0
  59. package/dist/shadcns/components/ui/form.d.ts +24 -0
  60. package/dist/shadcns/components/ui/form.js +56 -0
  61. package/dist/shadcns/components/ui/hover-card.d.ts +6 -0
  62. package/dist/shadcns/components/ui/hover-card.js +14 -0
  63. package/dist/shadcns/components/ui/input-otp.d.ts +11 -0
  64. package/dist/shadcns/components/ui/input-otp.js +21 -0
  65. package/dist/shadcns/components/ui/input.d.ts +3 -0
  66. package/dist/shadcns/components/ui/input.js +6 -0
  67. package/dist/shadcns/components/ui/label.d.ts +4 -0
  68. package/dist/shadcns/components/ui/label.js +8 -0
  69. package/dist/shadcns/components/ui/menubar.d.ts +26 -0
  70. package/dist/shadcns/components/ui/menubar.js +54 -0
  71. package/dist/shadcns/components/ui/navigation-menu.d.ts +14 -0
  72. package/dist/shadcns/components/ui/navigation-menu.js +32 -0
  73. package/dist/shadcns/components/ui/pagination.d.ts +13 -0
  74. package/dist/shadcns/components/ui/pagination.js +28 -0
  75. package/dist/shadcns/components/ui/popover.d.ts +7 -0
  76. package/dist/shadcns/components/ui/popover.js +17 -0
  77. package/dist/shadcns/components/ui/progress.d.ts +4 -0
  78. package/dist/shadcns/components/ui/progress.js +8 -0
  79. package/dist/shadcns/components/ui/radio-group.d.ts +5 -0
  80. package/dist/shadcns/components/ui/radio-group.js +12 -0
  81. package/dist/shadcns/components/ui/resizable.d.ts +8 -0
  82. package/dist/shadcns/components/ui/resizable.js +15 -0
  83. package/dist/shadcns/components/ui/scroll-area.d.ts +5 -0
  84. package/dist/shadcns/components/ui/scroll-area.js +11 -0
  85. package/dist/shadcns/components/ui/select.d.ts +15 -0
  86. package/dist/shadcns/components/ui/select.js +38 -0
  87. package/dist/shadcns/components/ui/separator.d.ts +4 -0
  88. package/dist/shadcns/components/ui/separator.js +8 -0
  89. package/dist/shadcns/components/ui/sheet.d.ts +13 -0
  90. package/dist/shadcns/components/ui/sheet.js +40 -0
  91. package/dist/shadcns/components/ui/sidebar.d.ts +66 -0
  92. package/dist/shadcns/components/ui/sidebar.js +204 -0
  93. package/dist/shadcns/components/ui/skeleton.d.ts +2 -0
  94. package/dist/shadcns/components/ui/skeleton.js +6 -0
  95. package/dist/shadcns/components/ui/slider.d.ts +4 -0
  96. package/dist/shadcns/components/ui/slider.js +10 -0
  97. package/dist/shadcns/components/ui/sonner.d.ts +3 -0
  98. package/dist/shadcns/components/ui/sonner.js +13 -0
  99. package/dist/shadcns/components/ui/switch.d.ts +4 -0
  100. package/dist/shadcns/components/ui/switch.js +8 -0
  101. package/dist/shadcns/components/ui/table.d.ts +10 -0
  102. package/dist/shadcns/components/ui/table.js +28 -0
  103. package/dist/shadcns/components/ui/tabs.d.ts +7 -0
  104. package/dist/shadcns/components/ui/tabs.js +17 -0
  105. package/dist/shadcns/components/ui/textarea.d.ts +3 -0
  106. package/dist/shadcns/components/ui/textarea.js +7 -0
  107. package/dist/shadcns/components/ui/toggle-group.d.ts +7 -0
  108. package/dist/shadcns/components/ui/toggle-group.js +20 -0
  109. package/dist/shadcns/components/ui/toggle.d.ts +9 -0
  110. package/dist/shadcns/components/ui/toggle.js +26 -0
  111. package/dist/shadcns/components/ui/tooltip.d.ts +7 -0
  112. package/dist/shadcns/components/ui/tooltip.js +17 -0
  113. package/dist/{hooks/useIsMobile.js → shadcns/hooks/use-mobile.js} +5 -6
  114. package/dist/shadcns/index.d.ts +48 -0
  115. package/dist/shadcns/index.js +48 -0
  116. package/dist/shadcns/lib/utils.d.ts +2 -0
  117. package/dist/shadcns/lib/utils.js +5 -0
  118. package/dist/types/shadcns.type.d.ts +0 -1
  119. package/dist/types/shadcns.type.js +1 -0
  120. package/dist/utils/index.d.ts +0 -2
  121. package/dist/utils/index.js +0 -5
  122. package/package.json +5 -1
  123. package/dist/components/TestComponent.d.ts +0 -4
  124. package/dist/components/TestComponent.js +0 -10
  125. /package/dist/{hooks/useIsMobile.d.ts → shadcns/hooks/use-mobile.d.ts} +0 -0
@@ -0,0 +1,16 @@
1
+ import type { AnchorOptions } from "../../hooks/index.js";
2
+ interface PropsType extends React.ComponentProps<"div"> {
3
+ name: string;
4
+ }
5
+ export declare const AnchorTarget: React.FC<PropsType>;
6
+ export declare const AnchorContainer: React.FC<PropsType>;
7
+ export declare const AnchorOffseter: React.FC<PropsType>;
8
+ type TriggerProps = AnchorOptions & React.ComponentProps<"div"> & {};
9
+ export declare const AnchorTrigger: React.FC<TriggerProps>;
10
+ export declare const Anchors: {
11
+ Trigger: import("react").FC<TriggerProps>;
12
+ Target: import("react").FC<PropsType>;
13
+ Container: import("react").FC<PropsType>;
14
+ Offseter: import("react").FC<PropsType>;
15
+ };
16
+ export {};
@@ -0,0 +1,26 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useAnchors } from "../../hooks/index.js";
4
+ import { cn } from "../../shadcns/index.js";
5
+ export const AnchorTarget = ({ children, className, name }) => {
6
+ const { registerAnchors } = useAnchors();
7
+ return (_jsx("div", { className: cn(className), ...registerAnchors(name), children: children }));
8
+ };
9
+ export const AnchorContainer = ({ children, className, name }) => {
10
+ const { registerContainers } = useAnchors();
11
+ return (_jsx("div", { className: cn(className), ...registerContainers(name), children: children }));
12
+ };
13
+ export const AnchorOffseter = ({ children, className, name }) => {
14
+ const { registerOffseters } = useAnchors();
15
+ return (_jsx("div", { className: cn(className), ...registerOffseters(name), children: children }));
16
+ };
17
+ export const AnchorTrigger = ({ children, className, ...options }) => {
18
+ const { scrollToAnchor } = useAnchors();
19
+ return (_jsx("div", { className: cn(className), onClick: () => scrollToAnchor(options), children: children }));
20
+ };
21
+ export const Anchors = {
22
+ Trigger: AnchorTrigger,
23
+ Target: AnchorTarget,
24
+ Container: AnchorContainer,
25
+ Offseter: AnchorOffseter
26
+ };
@@ -0,0 +1 @@
1
+ export * from "./anchors";
@@ -0,0 +1 @@
1
+ export * from "./anchors";
@@ -1,2 +1,2 @@
1
- export declare const test = "wade";
2
- export { default as TestComponent } from "./TestComponent";
1
+ export * from "./anchors";
2
+ export * from "./tests";
@@ -1,2 +1,2 @@
1
- export const test = "wade";
2
- export { default as TestComponent } from "./TestComponent";
1
+ export * from "./anchors";
2
+ export * from "./tests";
@@ -0,0 +1 @@
1
+ export { default as Tests } from "./tests";
@@ -0,0 +1 @@
1
+ export { default as Tests } from "./tests";
@@ -0,0 +1,4 @@
1
+ export interface PropsTypes {
2
+ }
3
+ declare const Tests: React.FC<PropsTypes>;
4
+ export default Tests;
@@ -0,0 +1,10 @@
1
+ "use client";
2
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Button } from "../../shadcns/index.js";
4
+ import { CarouselPrevious } from "../../shadcns/index.js";
5
+ import { Carousel } from "../../shadcns/index.js";
6
+ const Tests = () => {
7
+ return (_jsxs(_Fragment, { children: [_jsx(Carousel, { children: _jsx(CarouselPrevious, {}) }), _jsx(Button, { children: "test123133232" })] }));
8
+ };
9
+ Tests.displayName = "Tests";
10
+ export default Tests;
@@ -6,3 +6,6 @@ export * from "./useAsyncFetcher";
6
6
  export * from "./useMounted";
7
7
  export * from "./useEffectOne";
8
8
  export * from "./useEffectLeave";
9
+ export * from "./useAnchors";
10
+ export * from "./useHash";
11
+ export * from "./useScrollContainers";
@@ -6,3 +6,6 @@ export * from "./useAsyncFetcher";
6
6
  export * from "./useMounted";
7
7
  export * from "./useEffectOne";
8
8
  export * from "./useEffectLeave";
9
+ export * from "./useAnchors";
10
+ export * from "./useHash";
11
+ export * from "./useScrollContainers";
@@ -1,29 +1,50 @@
1
- import { Easing } from "motion/react";
2
- export interface PropsTypes {
3
- }
4
- export interface AnchorActionsOptions {
5
- anchor?: string;
6
- container: string;
7
- offseters?: string | string[];
8
- direction?: "horizontal" | "vertical";
1
+ import { animate } from "motion/react";
2
+ import type { Easing } from "motion/react";
3
+ import { registerContainers } from "./useScrollContainers";
4
+ export interface AnimateOptions {
9
5
  duration?: number;
10
- offset?: number;
11
6
  delay?: number;
12
7
  ease?: Easing | Easing[] | undefined;
13
8
  onScroll?: () => void;
14
9
  onScrolling?: (value: number) => void;
15
10
  onScrolled?: () => void;
16
11
  }
12
+ export interface AnchorOptions extends AnimateOptions {
13
+ anchor: string;
14
+ container?: string;
15
+ offseters?: string | string[];
16
+ direction?: "x" | "y";
17
+ align?: "start" | "center" | "end";
18
+ offset?: number;
19
+ }
20
+ export interface ScrollOptions extends AnimateOptions {
21
+ controllerKey: string;
22
+ containerDom: HTMLElement | Window;
23
+ anchorScrollValue: {
24
+ left: number;
25
+ top: number;
26
+ };
27
+ containerScrollValue: {
28
+ left: number;
29
+ top: number;
30
+ };
31
+ direction?: AnchorOptions["direction"];
32
+ }
33
+ export type AnimateController = ReturnType<typeof animate>;
17
34
  export declare function useAnchors(): {
18
35
  registerAnchors: typeof registerAnchors;
19
- registerContainers: typeof registerContainers;
20
36
  registerOffseters: typeof registerOffseters;
37
+ registerContainers: typeof registerContainers;
38
+ setStores: (options: AnchorStoreOptions) => void;
21
39
  getStores: () => AnchorsStores;
22
- removeAnchor: (name: string) => void;
23
- removeOffseter: (name: string) => void;
24
- removeContainer: (name: string) => void;
25
- scrollToAnchor: ({ anchor: anchorName, container: containerName, ...options }: AnchorActionsOptions) => void;
40
+ scrollToAnchor: (anchorOptions: AnchorOptions) => void;
26
41
  };
42
+ export interface RegistrationDatas {
43
+ key: keyof AnchorsStores;
44
+ name: string;
45
+ node: HTMLDivElement | null;
46
+ }
47
+ export declare function registration({ name, key, node }: RegistrationDatas): void;
27
48
  export declare function registerAnchors(name: string): {
28
49
  ref: (node: HTMLDivElement | null) => void;
29
50
  "data-anchor": string;
@@ -32,20 +53,13 @@ export declare function registerOffseters(name: string): {
32
53
  ref: (node: HTMLDivElement | null) => void;
33
54
  "data-anchor-offseter": string;
34
55
  };
35
- export declare function registerContainers(name: string): {
36
- ref: (node: HTMLDivElement | null) => void;
37
- "data-anchor-container": string;
38
- };
39
- export type AnchorsStores = {
56
+ export interface AnchorsStores {
40
57
  anchors: Map<string, HTMLElement | null>;
41
- containers: Map<string, HTMLElement | null>;
42
58
  offseters: Map<string, HTMLElement | null>;
43
- };
59
+ }
44
60
  export declare const useAnchorsStores: import("zustand").UseBoundStore<import("zustand").StoreApi<AnchorsStores>>;
45
61
  export declare const getAnchorsStores: () => AnchorsStores;
46
- export declare const addAnchor: (name: string, anchorNode: HTMLElement | null) => void;
47
- export declare const removeAnchor: (name: string) => void;
48
- export declare const addContainer: (name: string, containerNode: HTMLElement | null) => void;
49
- export declare const removeContainer: (name: string) => void;
50
- export declare const addOffseter: (name: string, containerNode: HTMLElement | null) => void;
51
- export declare const removeOffseter: (name: string) => void;
62
+ export interface AnchorStoreOptions extends RegistrationDatas {
63
+ action: "add" | "remove";
64
+ }
65
+ export declare const setAnchorsStore: (options: AnchorStoreOptions) => void;
@@ -1,121 +1,170 @@
1
1
  "use client";
2
+ // update: 2025.11.07
3
+ // version: 0.0.2.bate
4
+ // dev: wade
2
5
  import { useCallback, useMemo, useRef } from "react";
3
- import { animate, useMotionValue } from "motion/react";
6
+ import { animate, motionValue } from "motion/react";
4
7
  import { create } from "zustand";
8
+ import { getScrollContainersStores, registerContainers } from "./useScrollContainers";
9
+ const ANCHOR_ATTRIBUTE = "data-anchor";
10
+ const OFFSETER_ATTRIBUTE = "data-anchor-offseter";
5
11
  export function useAnchors() {
6
- const motionValue = useMotionValue(0);
7
- const controlsRef = useRef(null);
8
- const scrollToAnchor = useCallback(({ anchor: anchorName, container: containerName, ...options }) => {
9
- const { offseters, direction = "vertical", duration = 0.5, offset = 0, delay = 0, ease = [0.215, 0.61, 0.355, 1.0], onScroll, onScrolling, onScrolled, } = options;
10
- if (!anchorName || !containerName)
12
+ const controllerRef = useRef(new Map());
13
+ const scrollAnimations = useCallback(({ controllerKey, containerDom, anchorScrollValue, containerScrollValue, direction = "y", duration = 0.5, delay = 0, ease = [0.215, 0.61, 0.355, 1.0], onScroll: onPlay, onScrolled, onScrolling }) => {
14
+ if (direction !== "y" && direction !== "x") {
15
+ console.error(`Scroll Direction isn't 'x' or 'y' `);
11
16
  return;
12
- const stores = getAnchorsStores();
13
- if (!stores?.anchors || !stores?.containers)
17
+ }
18
+ const { left: scrollLeft, top: scrollTop } = containerScrollValue;
19
+ const { left: anchorLeft, top: anchorTop } = anchorScrollValue;
20
+ const isScrollX = direction === "x";
21
+ const isScrollY = direction === "y";
22
+ const startValue = isScrollX ? scrollLeft : scrollTop;
23
+ const endValue = isScrollX ? anchorLeft : anchorTop;
24
+ if (startValue == endValue) {
25
+ controllerRef.current.delete(controllerKey);
14
26
  return;
15
- const anchorDom = stores.anchors.get(anchorName);
16
- const containerDom = stores.containers.get(containerName);
17
- if (!anchorDom || !containerDom)
27
+ }
28
+ const motionStartValue = motionValue(startValue);
29
+ const onUpdate = (value) => {
30
+ const left = isScrollX ? value : undefined;
31
+ const top = isScrollY ? value : undefined;
32
+ containerDom.scrollTo({ left, top });
33
+ onScrolling?.(value);
34
+ };
35
+ const onComplete = () => {
36
+ controllerRef.current.delete(controllerKey);
37
+ onScrolled?.();
38
+ };
39
+ const options = { duration, ease, delay, onPlay, onUpdate, onComplete };
40
+ controllerRef.current.set(controllerKey, animate(motionStartValue, endValue, options));
41
+ }, []);
42
+ const scrollToAnchor = useCallback((anchorOptions) => {
43
+ const { anchor: anchorName, container: containerName, offseters, align, offset = 0, ...options } = anchorOptions;
44
+ const anchorsStores = getAnchorsStores();
45
+ const scrollContainersStores = getScrollContainersStores();
46
+ const isScrolltoAnchor = anchorName !== "#";
47
+ const isScrollContainer = containerName && containerName !== "window";
48
+ const controllerKey = containerName ?? "window";
49
+ if (controllerRef.current.has(controllerKey)) {
50
+ controllerRef.current.get(controllerKey)?.stop();
51
+ controllerRef.current.delete(controllerKey);
52
+ }
53
+ const anchorDom = isScrolltoAnchor
54
+ ? anchorsStores.anchors.get(anchorName)
55
+ : undefined;
56
+ if (isScrolltoAnchor && !(anchorDom instanceof HTMLElement))
18
57
  return;
19
- const { top: targetTop } = anchorDom.getBoundingClientRect();
20
- const { top: containerTop } = containerDom.getBoundingClientRect();
21
- const containerScrollTop = Math.round(containerDom.scrollTop);
22
- const scrollOffset = Math.round(targetTop - containerTop + containerScrollTop);
23
- if (scrollOffset == containerScrollTop)
58
+ const containerDom = isScrollContainer
59
+ ? scrollContainersStores.containers.get(containerName)
60
+ : window;
61
+ if (!containerDom)
24
62
  return;
25
- if (controlsRef.current)
26
- controlsRef.current?.stop();
27
- // console.log("scrollOffset", scrollOffset);
28
- // console.log("containerScrollTop", containerScrollTop);
29
- // console.log(scrollOffset == containerScrollTop);
30
- motionValue.set(containerScrollTop);
31
- controlsRef.current = animate(motionValue, scrollOffset, {
32
- duration: 0.5,
33
- delay: 5,
34
- ease: [0.215, 0.61, 0.355, 1.0],
35
- onPlay: onScroll,
36
- onComplete: onScrolled,
37
- onUpdate: (value) => {
38
- containerDom.scrollTop = value;
39
- onScrolling?.(value);
40
- },
63
+ const containerScrollValue = {
64
+ top: Math.round(isScrollContainer
65
+ ? containerDom.scrollTop
66
+ : containerDom.pageYOffset),
67
+ left: Math.round(isScrollContainer
68
+ ? containerDom.scrollLeft
69
+ : pageXOffset)
70
+ };
71
+ const containerRect = isScrollContainer
72
+ ? containerDom.getBoundingClientRect()
73
+ : { top: 0, left: 0 };
74
+ const containerOffsetValue = {
75
+ left: containerScrollValue.left - (isScrollContainer ? containerRect.left : 0),
76
+ top: containerScrollValue.top - (isScrollContainer ? containerRect.top : 0)
77
+ };
78
+ const offsetsValue = Array.isArray(offseters)
79
+ ? offseters.reduce((init, offseter) => {
80
+ const offseterDom = anchorsStores.offseters.get(offseter);
81
+ const width = (init.width ?? 0) + (offseterDom ? offseterDom.clientWidth : 0);
82
+ const height = (init.height ?? 0) + (offseterDom ? offseterDom.clientHeight : 0);
83
+ return { width, height };
84
+ }, {})
85
+ : { width: 0, height: 0 };
86
+ const offsetsSumValue = {
87
+ width: options.direction === "x" ? offsetsValue.width + offset : 0,
88
+ height: options.direction === "y" ? offsetsValue.height + offset : 0,
89
+ };
90
+ const anchorRect = anchorDom ? anchorDom.getBoundingClientRect() : { left: 0, top: 0 };
91
+ const anchorScrollValue = {
92
+ left: isScrolltoAnchor
93
+ ? Math.round(anchorRect.left + containerOffsetValue.left - offsetsSumValue.width)
94
+ : offsetsSumValue.width,
95
+ top: isScrolltoAnchor
96
+ ? Math.round(anchorRect.top + containerOffsetValue.top - offsetsSumValue.height)
97
+ : offsetsSumValue.height
98
+ };
99
+ scrollAnimations({
100
+ controllerKey,
101
+ containerDom,
102
+ containerScrollValue,
103
+ anchorScrollValue,
104
+ ...options
41
105
  });
42
- }, [motionValue]);
106
+ }, []);
43
107
  const returnsMemo = useMemo(() => ({
44
108
  registerAnchors,
45
- registerContainers,
46
109
  registerOffseters,
110
+ registerContainers: registerContainers,
111
+ setStores: setAnchorsStore,
47
112
  getStores: getAnchorsStores,
48
- removeAnchor: removeAnchor,
49
- removeOffseter: removeOffseter,
50
- removeContainer: removeContainer,
51
113
  scrollToAnchor
52
114
  }), [scrollToAnchor]);
53
115
  return returnsMemo;
54
116
  }
117
+ export function registration({ name, key, node }) {
118
+ if (!node)
119
+ return;
120
+ if (name == "#") {
121
+ console.error(`Cannot register ${key} name '#'`);
122
+ return;
123
+ }
124
+ setAnchorsStore({ key, name, node, action: node ? "add" : "remove" });
125
+ }
55
126
  export function registerAnchors(name) {
56
- const register = (node) => {
57
- if (node)
58
- addAnchor(name, node);
59
- else
60
- removeAnchor(name);
61
- };
62
- return {
63
- ref: register,
64
- "data-anchor": name
65
- };
127
+ const register = useCallback((node) => registration({ key: "anchors", name, node }), [name]);
128
+ return { ref: register, [ANCHOR_ATTRIBUTE]: name };
66
129
  }
67
130
  export function registerOffseters(name) {
68
- const register = (node) => {
69
- if (node)
70
- addOffseter(name, node);
71
- else
72
- removeOffseter(name);
73
- };
74
- return {
75
- ref: register,
76
- "data-anchor-offseter": name
77
- };
78
- }
79
- export function registerContainers(name) {
80
- const register = (node) => {
81
- if (node)
82
- addContainer(name, node);
83
- else
84
- removeContainer(name);
85
- };
86
- return {
87
- ref: register,
88
- "data-anchor-container": name
89
- };
131
+ const register = useCallback((node) => registration({ key: "offseters", name, node }), [name]);
132
+ return { ref: register, [OFFSETER_ATTRIBUTE]: name };
90
133
  }
91
- const anchorsStores = {
134
+ export const useAnchorsStores = create()(() => ({
92
135
  anchors: new Map(),
93
- containers: new Map(),
136
+ // containers: new Map(),
94
137
  offseters: new Map(),
95
- };
96
- export const useAnchorsStores = create()(() => anchorsStores);
138
+ }));
97
139
  export const getAnchorsStores = () => useAnchorsStores.getState();
98
- export const addAnchor = (name, anchorNode) => useAnchorsStores.setState(stores => {
99
- stores.anchors?.set(name, anchorNode);
100
- return { anchors: stores.anchors };
101
- });
102
- export const removeAnchor = (name) => useAnchorsStores.setState(stores => {
103
- stores.anchors?.delete(name);
104
- return { anchors: stores.anchors };
105
- });
106
- export const addContainer = (name, containerNode) => useAnchorsStores.setState(stores => {
107
- stores.containers?.set(name, containerNode);
108
- return { containers: stores.containers };
109
- });
110
- export const removeContainer = (name) => useAnchorsStores.setState(stores => {
111
- stores.containers?.delete(name);
112
- return { containers: stores.containers };
113
- });
114
- export const addOffseter = (name, containerNode) => useAnchorsStores.setState(stores => {
115
- stores.offseters?.set(name, containerNode);
116
- return { offseters: stores.offseters };
117
- });
118
- export const removeOffseter = (name) => useAnchorsStores.setState(stores => {
119
- stores.offseters?.delete(name);
120
- return { offseters: stores.offseters };
121
- });
140
+ export const setAnchorsStore = (options) => {
141
+ const { key, action, name, node } = options;
142
+ useAnchorsStores.setState(stores => {
143
+ switch (key) {
144
+ case "anchors":
145
+ const anchorDom = stores.anchors?.get(name);
146
+ if (action == "add" && node instanceof HTMLElement) {
147
+ if (anchorDom == node)
148
+ return stores;
149
+ stores.anchors?.set(name, node);
150
+ }
151
+ else if (action == "remove" && anchorDom) {
152
+ stores.anchors?.delete(name);
153
+ }
154
+ return { anchors: stores.anchors };
155
+ case "offseters":
156
+ const offseterDom = stores.offseters?.get(name);
157
+ if (action == "add" && node instanceof HTMLElement) {
158
+ if (offseterDom == node)
159
+ return stores;
160
+ stores.offseters?.set(name, node);
161
+ }
162
+ else if (action == "remove" && offseterDom) {
163
+ stores.offseters?.delete(name);
164
+ }
165
+ return { offseters: stores.offseters };
166
+ default:
167
+ return stores;
168
+ }
169
+ });
170
+ };
@@ -0,0 +1 @@
1
+ export declare function useHash(): string;
@@ -0,0 +1,19 @@
1
+ "use client";
2
+ import { useEffect, useState } from "react";
3
+ export function useHash() {
4
+ const [hash, setHash] = useState("");
5
+ const updateHash = () => setHash(window.location.hash);
6
+ const hashchangeEvent = (e) => {
7
+ e.preventDefault?.();
8
+ updateHash();
9
+ };
10
+ // 初始化
11
+ useEffect(() => {
12
+ updateHash();
13
+ window.addEventListener("hashchange", hashchangeEvent);
14
+ return () => {
15
+ window.removeEventListener("hashchange", hashchangeEvent);
16
+ };
17
+ }, []);
18
+ return hash;
19
+ }
@@ -0,0 +1,27 @@
1
+ export interface UseScrollContainers {
2
+ container?: string;
3
+ }
4
+ export declare function useScrollContainers(options?: UseScrollContainers): {
5
+ container: HTMLElement | (Window & typeof globalThis);
6
+ setStores: (options: ScrollContainersStoreOptions) => void;
7
+ getStores: () => ScrollContainersStores;
8
+ registerContainers: typeof registerContainers;
9
+ };
10
+ export declare function scrollContainerRegistration({ name, node }: ContainerRegistrationDatas): void;
11
+ export declare function registerContainers(name: string): {
12
+ ref: (node: HTMLDivElement | null) => void;
13
+ "data-scroll-container": string;
14
+ };
15
+ export interface ScrollContainersStores {
16
+ containers: Map<string, HTMLElement | null>;
17
+ }
18
+ export declare const useScrollContainersStores: import("zustand").UseBoundStore<import("zustand").StoreApi<ScrollContainersStores>>;
19
+ export declare const getScrollContainersStores: () => ScrollContainersStores;
20
+ export interface ContainerRegistrationDatas {
21
+ name: string;
22
+ node: HTMLDivElement | null;
23
+ }
24
+ export interface ScrollContainersStoreOptions extends ContainerRegistrationDatas {
25
+ action: "add" | "remove";
26
+ }
27
+ export declare const setScrollContainerStore: (options: ScrollContainersStoreOptions) => void;
@@ -0,0 +1,53 @@
1
+ "use client";
2
+ // update: 2025.11.07
3
+ // version: 0.0.1.bate
4
+ // dev: wade
5
+ import { useCallback } from "react";
6
+ import { create } from "zustand";
7
+ const CONTAINER_ATTRIBUTE = "data-scroll-container";
8
+ export function useScrollContainers(options) {
9
+ const { container: containerName } = options || {};
10
+ const stores = getScrollContainersStores();
11
+ const isScrollContainer = containerName && containerName !== "window";
12
+ const containerDom = isScrollContainer
13
+ ? stores.containers.get(containerName)
14
+ : window;
15
+ return {
16
+ container: containerDom,
17
+ setStores: setScrollContainerStore,
18
+ getStores: getScrollContainersStores,
19
+ registerContainers
20
+ };
21
+ }
22
+ export function scrollContainerRegistration({ name, node }) {
23
+ if (!node)
24
+ return;
25
+ if (node instanceof Window || node.tagName === "BODY" || node.tagName === "HTML") {
26
+ console.error(`Cannot register scroll container 'body' or 'html' `);
27
+ return;
28
+ }
29
+ setScrollContainerStore({ name, node, action: node ? "add" : "remove" });
30
+ }
31
+ export function registerContainers(name) {
32
+ const register = useCallback((node) => scrollContainerRegistration({ name, node }), [name]);
33
+ return { ref: register, [CONTAINER_ATTRIBUTE]: name };
34
+ }
35
+ export const useScrollContainersStores = create()(() => ({
36
+ containers: new Map(),
37
+ }));
38
+ export const getScrollContainersStores = () => useScrollContainersStores.getState();
39
+ export const setScrollContainerStore = (options) => {
40
+ const { action, name, node } = options;
41
+ useScrollContainersStores.setState(stores => {
42
+ const containerDom = stores.containers?.get(name);
43
+ if (action == "add" && node instanceof HTMLElement) {
44
+ if (containerDom == node)
45
+ return stores;
46
+ stores.containers?.set(name, node);
47
+ }
48
+ else if (action == "remove" && containerDom) {
49
+ stores.containers?.delete(name);
50
+ }
51
+ return { containers: stores.containers };
52
+ });
53
+ };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./components";
2
2
  export * from "./hooks";
3
3
  export * from "./utils";
4
+ export * from "./shadcns";
4
5
  export * from "./types";
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./components";
2
2
  export * from "./hooks";
3
3
  export * from "./utils";
4
+ export * from "./shadcns";
4
5
  export * from "./types";
@@ -0,0 +1,7 @@
1
+ import * as React from 'react';
2
+ import * as AccordionPrimitive from '@radix-ui/react-accordion';
3
+ declare function Accordion({ ...props }: React.ComponentProps<typeof AccordionPrimitive.Root>): import("react/jsx-runtime").JSX.Element;
4
+ declare function AccordionItem({ className, ...props }: React.ComponentProps<typeof AccordionPrimitive.Item>): import("react/jsx-runtime").JSX.Element;
5
+ declare function AccordionTrigger({ className, children, ...props }: React.ComponentProps<typeof AccordionPrimitive.Trigger>): import("react/jsx-runtime").JSX.Element;
6
+ declare function AccordionContent({ className, children, ...props }: React.ComponentProps<typeof AccordionPrimitive.Content>): import("react/jsx-runtime").JSX.Element;
7
+ export { Accordion, AccordionItem, AccordionTrigger, AccordionContent };
@@ -0,0 +1,18 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import * as AccordionPrimitive from '@radix-ui/react-accordion';
4
+ import { ChevronDownIcon } from 'lucide-react';
5
+ import { cn } from '../../index.js';
6
+ function Accordion({ ...props }) {
7
+ return _jsx(AccordionPrimitive.Root, { "data-slot": "accordion", ...props });
8
+ }
9
+ function AccordionItem({ className, ...props }) {
10
+ return (_jsx(AccordionPrimitive.Item, { "data-slot": "accordion-item", className: cn('border-b last:border-b-0', className), ...props }));
11
+ }
12
+ function AccordionTrigger({ className, children, ...props }) {
13
+ return (_jsx(AccordionPrimitive.Header, { className: "flex", children: _jsxs(AccordionPrimitive.Trigger, { "data-slot": "accordion-trigger", className: cn('focus-visible:border-ring focus-visible:ring-ring/50 flex flex-1 items-start justify-between gap-4 rounded-md py-4 text-left text-sm font-medium transition-all outline-none hover:underline focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-50 [&[data-state=open]>svg]:rotate-180', className), ...props, children: [children, _jsx(ChevronDownIcon, { className: "text-muted-foreground pointer-events-none size-4 shrink-0 translate-y-0.5 transition-transform duration-200" })] }) }));
14
+ }
15
+ function AccordionContent({ className, children, ...props }) {
16
+ return (_jsx(AccordionPrimitive.Content, { "data-slot": "accordion-content", className: "data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down overflow-hidden text-sm", ...props, children: _jsx("div", { className: cn('pt-0 pb-4', className), children: children }) }));
17
+ }
18
+ export { Accordion, AccordionItem, AccordionTrigger, AccordionContent };
@@ -0,0 +1,14 @@
1
+ import * as React from 'react';
2
+ import * as AlertDialogPrimitive from '@radix-ui/react-alert-dialog';
3
+ declare function AlertDialog({ ...props }: React.ComponentProps<typeof AlertDialogPrimitive.Root>): import("react/jsx-runtime").JSX.Element;
4
+ declare function AlertDialogTrigger({ ...props }: React.ComponentProps<typeof AlertDialogPrimitive.Trigger>): import("react/jsx-runtime").JSX.Element;
5
+ declare function AlertDialogPortal({ ...props }: React.ComponentProps<typeof AlertDialogPrimitive.Portal>): import("react/jsx-runtime").JSX.Element;
6
+ declare function AlertDialogOverlay({ className, ...props }: React.ComponentProps<typeof AlertDialogPrimitive.Overlay>): import("react/jsx-runtime").JSX.Element;
7
+ declare function AlertDialogContent({ className, ...props }: React.ComponentProps<typeof AlertDialogPrimitive.Content>): import("react/jsx-runtime").JSX.Element;
8
+ declare function AlertDialogHeader({ className, ...props }: React.ComponentProps<'div'>): import("react/jsx-runtime").JSX.Element;
9
+ declare function AlertDialogFooter({ className, ...props }: React.ComponentProps<'div'>): import("react/jsx-runtime").JSX.Element;
10
+ declare function AlertDialogTitle({ className, ...props }: React.ComponentProps<typeof AlertDialogPrimitive.Title>): import("react/jsx-runtime").JSX.Element;
11
+ declare function AlertDialogDescription({ className, ...props }: React.ComponentProps<typeof AlertDialogPrimitive.Description>): import("react/jsx-runtime").JSX.Element;
12
+ declare function AlertDialogAction({ className, ...props }: React.ComponentProps<typeof AlertDialogPrimitive.Action>): import("react/jsx-runtime").JSX.Element;
13
+ declare function AlertDialogCancel({ className, ...props }: React.ComponentProps<typeof AlertDialogPrimitive.Cancel>): import("react/jsx-runtime").JSX.Element;
14
+ export { AlertDialog, AlertDialogPortal, AlertDialogOverlay, AlertDialogTrigger, AlertDialogContent, AlertDialogHeader, AlertDialogFooter, AlertDialogTitle, AlertDialogDescription, AlertDialogAction, AlertDialogCancel, };