@vnejs/uis.react.scrollbar 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,14 @@
1
+ import "./Scrollbar.styl";
2
+ export declare const Scrollbar: ({ className, children, width, height, scrollTo, scrollToEnd, hideScrolbars, disableScroll, wrapRef, textSize, }: {
3
+ className?: string;
4
+ children: any;
5
+ width?: number;
6
+ height?: number;
7
+ scrollTo?: number;
8
+ scrollToEnd?: boolean;
9
+ hideScrolbars?: boolean;
10
+ disableScroll?: boolean;
11
+ wrapRef?: any;
12
+ textSize?: any;
13
+ }) => import("react/jsx-runtime").JSX.Element;
14
+ //# sourceMappingURL=Scrollbar.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Scrollbar.d.ts","sourceRoot":"","sources":["../src/Scrollbar.tsx"],"names":[],"mappings":"AASA,OAAO,kBAAkB,CAAC;AAa1B,eAAO,MAAM,SAAS,GAAI;;;;;;;;;;;CAWzB,4CA2DA,CAAC"}
@@ -0,0 +1,48 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useMemo } from "react";
3
+ import { cn, getVneLength } from "@vnejs/uis.utils";
4
+ import { useThumbHook } from "./hooks/thumb.hook";
5
+ import { useScrollHook } from "./hooks/scroll.hook";
6
+ import { useScrollToHook } from "./hooks/scroll-to.hook";
7
+ import { useRefForScrollHook } from "./hooks/ref.hook";
8
+ import "./Scrollbar.styl";
9
+ const b = cn("Scrollbar");
10
+ const renderScroll = (thumbRef, isVisible, isHorizontal, isVertical) => (_jsx("div", { className: b("scroll", { isVisible, isHorizontal, isVertical }), children: _jsx("div", { className: b("thumb", { isHorizontal, isVertical }), ref: thumbRef }) }));
11
+ export const Scrollbar = ({ className = "", children, width = 0, height = 0, scrollTo = 0, scrollToEnd = false, hideScrolbars = false, disableScroll = false, wrapRef = null, textSize = null, }) => {
12
+ const { scrollbarWrapRef, scrollbarChildrenRef, thumbHorizontalRef, thumbVerticalRef } = useRefForScrollHook();
13
+ const { shouldRenderHorizontal, shouldRenderVertical } = useScrollHook(scrollbarWrapRef, scrollbarChildrenRef, width, height, textSize);
14
+ useThumbHook(scrollbarWrapRef, thumbVerticalRef, thumbHorizontalRef);
15
+ useScrollToHook(scrollTo, scrollToEnd, scrollbarWrapRef, scrollbarChildrenRef);
16
+ const style = useMemo(() => {
17
+ const result = {};
18
+ if (width)
19
+ result.width = getVneLength(width);
20
+ if (height)
21
+ result.height = getVneLength(height);
22
+ return result;
23
+ }, [width, height]);
24
+ const styleWrap = useMemo(() => {
25
+ const result = {};
26
+ if (disableScroll) {
27
+ result.overflowX = "hidden";
28
+ result.overflowY = "hidden";
29
+ }
30
+ else {
31
+ if (shouldRenderHorizontal)
32
+ result.overflowX = "auto";
33
+ if (shouldRenderVertical)
34
+ result.overflowY = "auto";
35
+ }
36
+ if (width)
37
+ result.maxWidth = getVneLength(width);
38
+ if (height)
39
+ result.maxHeight = getVneLength(height);
40
+ return result;
41
+ }, [width, height, scrollbarWrapRef.current, shouldRenderHorizontal, shouldRenderVertical, disableScroll]);
42
+ useEffect(() => {
43
+ if (wrapRef)
44
+ wrapRef.current = scrollbarWrapRef.current;
45
+ }, [wrapRef, scrollbarWrapRef.current]);
46
+ return (_jsxs("div", { className: b({}, [className]), style: style, children: [!hideScrolbars && renderScroll(thumbHorizontalRef, shouldRenderHorizontal, true, false), !hideScrolbars && renderScroll(thumbVerticalRef, shouldRenderVertical, false, true), _jsx("div", { className: b("wrap"), ref: scrollbarWrapRef, style: styleWrap, children: _jsx("div", { className: b("children"), ref: scrollbarChildrenRef, children: children }) })] }));
47
+ };
48
+ //# sourceMappingURL=Scrollbar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Scrollbar.js","sourceRoot":"","sources":["../src/Scrollbar.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAE3C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,EAAE,CAAC,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;IAExC,OAAO,CACL,eACE,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,EAC7B,KAAK,EAAE,KAAK,aAEX,CAAC,aAAa,IAAI,YAAY,CAAC,kBAAkB,EAAE,sBAAsB,EAAE,IAAI,EAAE,KAAK,CAAC,EACvF,CAAC,aAAa,IAAI,YAAY,CAAC,gBAAgB,EAAE,oBAAoB,EAAE,KAAK,EAAE,IAAI,CAAC,EAEpF,cACE,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC,EACpB,GAAG,EAAE,gBAAgB,EACrB,KAAK,EAAE,SAAS,YAEhB,cACE,SAAS,EAAE,CAAC,CAAC,UAAU,CAAC,EACxB,GAAG,EAAE,oBAAoB,YAExB,QAAQ,GACL,GACF,IACF,CACP,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,55 @@
1
+ .Scrollbar
2
+ --vne-scrollbar-color-vertical: var(--vne-color-disabled, rgba(255, 255, 255, 30%))
3
+ --vne-scrollbar-color-horizontal: var(--vne-color-disabled, rgba(255, 255, 255, 30%))
4
+ --vne-scrollbar-color-thumb: var(--vne-color-selected, rgba(255, 255, 255, 75%))
5
+
6
+ display: block
7
+ position: relative
8
+
9
+ &-wrap
10
+ scrollbar-width: none
11
+
12
+ &-scroll
13
+ position: absolute
14
+
15
+ transition: 1000ms
16
+
17
+ border-radius: s('round(down, min(calc(8 * 100vw / 3840), calc(8 * 100vh / 2160)), 1px)')
18
+ opacity: 0
19
+
20
+ &-thumb
21
+ position: absolute
22
+
23
+ background: var(--vne-scrollbar-color-thumb)
24
+ border-radius: s('round(down, min(calc(12 * 100vw / 3840), calc(12 * 100vh / 2160)), 1px)')
25
+
26
+ &-scroll_isVertical
27
+ right: s('round(down, min(calc(-24 * 100vw / 3840), calc(-24 * 100vh / 2160)), 1px)')
28
+ top: 0;
29
+ bottom: s('round(down, min(calc(36 * 100vw / 3840), calc(36 * 100vh / 2160)), 1px)')
30
+
31
+ width: s('round(down, min(calc(12 * 100vw / 3840), calc(12 * 100vh / 2160)), 1px)')
32
+
33
+ background: var(--vne-scrollbar-color-vertical)
34
+
35
+ &-thumb_isVertical
36
+ right: s('round(down, min(calc(-6 * 100vw / 3840), calc(-6 * 100vh / 2160)), 1px)')
37
+ width: s('round(down, min(calc(24 * 100vw / 3840), calc(24 * 100vh / 2160)), 1px)')
38
+ height: s('round(down, min(calc(96 * 100vw / 3840), calc(96 * 100vh / 2160)), 1px)')
39
+
40
+ &-scroll_isHorizontal
41
+ bottom: s('round(down, min(calc(-24 * 100vw / 3840), calc(-24 * 100vh / 2160)), 1px)')
42
+ left: 0;
43
+ right: s('round(down, min(calc(36 * 100vw / 3840), calc(36 * 100vh / 2160)), 1px)')
44
+
45
+ height: s('round(down, min(calc(12 * 100vw / 3840), calc(12 * 100vh / 2160)), 1px)')
46
+
47
+ background: var(--vne-scrollbar-color-horizontal)
48
+
49
+ &-thumb_isHorizontal
50
+ top: s('round(down, min(calc(-6 * 100vw / 3840), calc(-6 * 100vh / 2160)), 1px)')
51
+ width: s('round(down, min(calc(96 * 100vw / 3840), calc(96 * 100vh / 2160)), 1px)')
52
+ height: s('round(down, min(calc(24 * 100vw / 3840), calc(24 * 100vh / 2160)), 1px)')
53
+
54
+ &-scroll_isVisible
55
+ opacity: 1
@@ -0,0 +1,7 @@
1
+ export declare const useRefForScrollHook: () => {
2
+ scrollbarWrapRef: import("react").RefObject<any>;
3
+ scrollbarChildrenRef: import("react").RefObject<any>;
4
+ thumbVerticalRef: import("react").RefObject<any>;
5
+ thumbHorizontalRef: import("react").RefObject<any>;
6
+ };
7
+ //# sourceMappingURL=ref.hook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ref.hook.d.ts","sourceRoot":"","sources":["../../src/hooks/ref.hook.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,mBAAmB;;;;;CAQ/B,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { useRef } from "react";
2
+ export const useRefForScrollHook = () => {
3
+ const scrollbarWrapRef = useRef(null);
4
+ const scrollbarChildrenRef = useRef(null);
5
+ const thumbVerticalRef = useRef(null);
6
+ const thumbHorizontalRef = useRef(null);
7
+ return { scrollbarWrapRef, scrollbarChildrenRef, thumbVerticalRef, thumbHorizontalRef };
8
+ };
9
+ //# sourceMappingURL=ref.hook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ref.hook.js","sourceRoot":"","sources":["../../src/hooks/ref.hook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE/B,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,EAAE;IACtC,MAAM,gBAAgB,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IACtC,MAAM,oBAAoB,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAE1C,MAAM,gBAAgB,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IACtC,MAAM,kBAAkB,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAExC,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,CAAC;AAC1F,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const useScrollToHook: (scrollTo: any, scrollToEnd: any, scrollbarWrapRef: any, scrollbarChildrenRef: any) => void;
2
+ //# sourceMappingURL=scroll-to.hook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scroll-to.hook.d.ts","sourceRoot":"","sources":["../../src/hooks/scroll-to.hook.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,eAAe,GAAI,aAAQ,EAAE,gBAAW,EAAE,qBAAgB,EAAE,yBAAoB,SA+B5F,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { useEffect } from "react";
2
+ export const useScrollToHook = (scrollTo, scrollToEnd, scrollbarWrapRef, scrollbarChildrenRef) => {
3
+ useEffect(() => {
4
+ if (!scrollTo)
5
+ return;
6
+ const children = [...scrollbarChildrenRef.current.children];
7
+ if (children[scrollTo]) {
8
+ const element = children[scrollTo];
9
+ if (scrollbarWrapRef.current.scrollTop > element.offsetTop ||
10
+ scrollbarWrapRef.current.scrollTop + scrollbarWrapRef.current.clientHeight < element.offsetTop + element.clientHeight ||
11
+ scrollbarWrapRef.current.scrollLeft > element.offsetleft ||
12
+ scrollbarWrapRef.current.scrollleft + scrollbarWrapRef.current.clientWidth < element.offsetleft + element.clientWidth)
13
+ element.scrollIntoView({ behavior: "smooth" });
14
+ }
15
+ }, [scrollTo, scrollbarWrapRef.current]);
16
+ useEffect(() => {
17
+ if (!scrollToEnd)
18
+ return;
19
+ const scrollToBottom = () => scrollbarChildrenRef?.current?.scrollIntoView({ behavior: "smooth", block: "end" });
20
+ const resizeObserver = new ResizeObserver(() => {
21
+ setTimeout(scrollToBottom, 100);
22
+ });
23
+ resizeObserver.observe(scrollbarChildrenRef.current);
24
+ return () => resizeObserver.disconnect();
25
+ }, [scrollToEnd, scrollbarWrapRef.current]);
26
+ };
27
+ //# sourceMappingURL=scroll-to.hook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scroll-to.hook.js","sourceRoot":"","sources":["../../src/hooks/scroll-to.hook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,QAAQ,EAAE,WAAW,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,EAAE;IAC/F,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,QAAQ;YAAE,OAAO;QAEtB,MAAM,QAAQ,GAAG,CAAC,GAAG,oBAAoB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAE5D,IAAI,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;YACvB,MAAM,OAAO,GAAG,QAAQ,CAAC,QAAQ,CAAC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ean;
3
+ shouldRenderVertical: boolean;
4
+ };
5
+ //# sourceMappingURL=scroll.hook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scroll.hook.d.ts","sourceRoot":"","sources":["../../src/hooks/scroll.hook.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,GAAI,qBAAgB,EAAE,yBAAoB,EAAE,UAAK,EAAE,WAAM,EAAE,aAAQ;;;CAsD5F,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { useCallback, useEffect, useState } from "react";
2
+ export const useScrollHook = (scrollbarWrapRef, scrollbarChildrenRef, width, height, textSize) => {
3
+ const [shouldRenderHorizontal, setShouldRenderHorizontal] = useState(false);
4
+ const [shouldRenderVertical, setShouldRenderVertical] = useState(false);
5
+ const calcShouldRenderVertical = useCallback(() => {
6
+ const raf = requestAnimationFrame(() => scrollbarWrapRef.current && setShouldRenderVertical(scrollbarWrapRef.current.scrollHeight !== scrollbarWrapRef.current.clientHeight));
7
+ return () => cancelAnimationFrame(raf);
8
+ }, [scrollbarWrapRef.current, setShouldRenderVertical, textSize]);
9
+ const calcShouldRenderHorizontal = useCallback(() => {
10
+ const raf = requestAnimationFrame(() => scrollbarWrapRef.current && setShouldRenderHorizontal(scrollbarWrapRef.current.scrollWidth > scrollbarWrapRef.current.clientWidth));
11
+ return () => cancelAnimationFrame(raf);
12
+ }, [scrollbarWrapRef.current, setShouldRenderHorizontal, textSize]);
13
+ useEffect(calcShouldRenderVertical, [height, calcShouldRenderVertical, textSize]);
14
+ useEffect(calcShouldRenderHorizontal, [width, calcShouldRenderHorizontal, textSize]);
15
+ useEffect(() => {
16
+ if (!scrollbarWrapRef.current)
17
+ return;
18
+ const observer = new ResizeObserver(() => {
19
+ if (!scrollbarWrapRef.current)
20
+ return;
21
+ let [oldHeight, oldWidth] = [scrollbarWrapRef.current.scrollHeight, scrollbarWrapRef.current.scrollWidth];
22
+ const rerender = () => {
23
+ calcShouldRenderVertical();
24
+ calcShouldRenderHorizontal();
25
+ if (!scrollbarWrapRef.current)
26
+ return;
27
+ if (oldHeight !== scrollbarWrapRef.current.scrollHeight || oldWidth !== scrollbarWrapRef.current.scrollWidth) {
28
+ oldHeight = scrollbarWrapRef.current.scrollHeight;
29
+ oldWidth = scrollbarWrapRef.current.scrollWidth;
30
+ setTimeout(rerender, 50);
31
+ }
32
+ };
33
+ setTimeout(rerender, 50);
34
+ });
35
+ observer.observe(scrollbarChildrenRef.current);
36
+ return () => observer.disconnect();
37
+ }, [scrollbarWrapRef.current, scrollbarChildrenRef.current, calcShouldRenderVertical, calcShouldRenderHorizontal, textSize]);
38
+ return { shouldRenderHorizontal, shouldRenderVertical };
39
+ };
40
+ //# sourceMappingURL=scroll.hook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scroll.hook.js","sourceRoot":"","sources":["../../src/hooks/scroll.hook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEzD,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,gBAAgB,EAAE,oBAAoB,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE;IAC/F,MAAM,CAAC,sBAAsB,EAAE,yBAAyB,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC5E,MAAM,CAAC,oBAAoB,EAAE,uBAAuB,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAExE,MAAM,wBAAwB,GAAG,WAAW,CAAC,GAAG,EAAE;QAChD,MAAM,GAAG,GAAG,qBAAqB,CAC/B,GAAG,EAAE,CAAC,gBAAgB,CAAC,OAAO,IAAI,uBAAuB,CAAC,gBAAgB,CAAC,OAAO,CAAC,YAAY,KAAK,gBAAgB,CAAC,OAAO,CAAC,YAAY,CAAC,CAC3I,CAAC;QAEF,OAAO,GAAG,EAAE,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC;IACzC,CAAC,EAAE,CAAC,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CAAC;oBAC7G,SAAS,GAAG,gBAAgB,CAAC,OAAO,CAAC,YAAY,CAAC;oBAClD,QAAQ,GAAG,gBAAgB,CAAC,OAAO,CAAC,WAAW,CAAC;oBAEhD,UAAU,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;gBAC3B,CAAC;YACH,CAAC,CAAC;YAEF,UAAU,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QAC3B,CAAC,CAAC,CAAC;QAEH,QAAQ,CAAC,OAAO,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAE/C,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;IACrC,CAAC,EAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE,oBAAoB,CAAC,OAAO,EAAE,wBAAwB,EAAE,0BAA0B,EAAE,QAAQ,CAAC,CAAC,CAAC;IAE7H,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,CAAC;AAC1D,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const useThumbHook: (scrollbarWrapRef: any, thumbVerticalRef: any, thumbHorizontalRef: any) => void;
2
+ //# sourceMappingURL=thumb.hook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"thumb.hook.d.ts","sourceRoot":"","sources":["../../src/hooks/thumb.hook.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,YAAY,GAAI,qBAAgB,EAAE,qBAAgB,EAAE,uBAAkB,SAwBlF,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { useEffect } from "react";
2
+ const getPosition = (scrollPosition, thumbSize) => `calc(${100 * scrollPosition}% - ${scrollPosition * thumbSize}px)`;
3
+ export const useThumbHook = (scrollbarWrapRef, thumbVerticalRef, thumbHorizontalRef) => {
4
+ useEffect(() => {
5
+ const handleScroll = () => {
6
+ if (!scrollbarWrapRef.current)
7
+ return;
8
+ if (thumbHorizontalRef.current) {
9
+ const maxScroll = scrollbarWrapRef.current.scrollWidth - scrollbarWrapRef.current.clientWidth;
10
+ thumbHorizontalRef.current.style.left = getPosition(scrollbarWrapRef.current.scrollLeft / maxScroll, thumbVerticalRef.current.clientWidth);
11
+ }
12
+ if (thumbVerticalRef.current) {
13
+ const maxScroll = scrollbarWrapRef.current.scrollHeight - scrollbarWrapRef.current.clientHeight;
14
+ thumbVerticalRef.current.style.top = getPosition(scrollbarWrapRef.current.scrollTop / maxScroll, thumbVerticalRef.current.clientHeight);
15
+ }
16
+ };
17
+ const ref = scrollbarWrapRef.current;
18
+ ref.addEventListener("scroll", handleScroll);
19
+ handleScroll();
20
+ return () => ref.removeEventListener("scroll", handleScroll);
21
+ }, [scrollbarWrapRef.current, thumbHorizontalRef.current, thumbVerticalRef.current]);
22
+ };
23
+ //# sourceMappingURL=thumb.hook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"thumb.hook.js","sourceRoot":"","sources":["../../src/hooks/thumb.hook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,MAAM,WAAW,GAAG,CAAC,cAAc,EAAE,SAAS,EAAE,EAAE,CAAC,QAAQ,GAAG,GAAG,cAAc,OAAO,cAAc,GAAG,SAAS,KAAK,CAAC;AAEtH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,EAAE;IACrF,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,YAAY,GAAG,GAAG,EAAE;YACxB,IAAI,CAAC,gBAAgB,CAAC,OAAO;gBAAE,OAAO;YACtC,IAAI,kBAAkB,CAAC,OAAO,EAAE,CAAC;gBAC/B,MAAM,SAAS,GAAG,gBAAgB,CAAC,OAAO,CAAC,WAAW,GAAG,gBAAgB,CAAC,OAAO,CAAC,WAAW,CAAC;gBAE9F,kBAAkB,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,GAAG,WAAW,CAAC,gBAAgB,CAAC,OAAO,CAAC,UAAU,GAAG,SAAS,EAAE,gBAAgB,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;YAC7I,CAAC;YACD,IAAI,gBAAgB,CAAC,OAAO,EAAE,CAAC;gBAC7B,MAAM,SAAS,GAAG,gBAAgB,CAAC,OAAO,CAAC,YAAY,GAAG,gBAAgB,CAAC,OAAO,CAAC,YAAY,CAAC;gBAEhG,gBAAgB,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,GAAG,WAAW,CAAC,gBAAgB,CAAC,OAAO,CAAC,SAAS,GAAG,SAAS,EAAE,gBAAgB,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;YAC1I,CAAC;QACH,CAAC,CAAC;QAEF,MAAM,GAAG,GAAG,gBAAgB,CAAC,OAAO,CAAC;QAErC,GAAG,CAAC,gBAAgB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;QAE7C,YAAY,EAAE,CAAC;QAEf,OAAO,GAAG,EAAE,CAAC,GAAG,CAAC,mBAAmB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;IAC/D,CAAC,EAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE,kBAAkB,CAAC,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;AACvF,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./Scrollbar";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./Scrollbar";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@vnejs/uis.react.scrollbar",
3
+ "version": "0.1.2",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "scripts": {
7
+ "build": "node ../../scripts/build-package.mjs",
8
+ "publish:major:plugin": "npm run publish:major",
9
+ "publish:minor:plugin": "npm run publish:minor",
10
+ "publish:patch:plugin": "npm run publish:patch",
11
+ "publish:major": "npm run build && npm version major && npm publish --access public",
12
+ "publish:minor": "npm run build && npm version minor && npm publish --access public",
13
+ "publish:patch": "npm run build && npm version patch && npm publish --access public"
14
+ },
15
+ "peerDependencies": {
16
+ "@bem-react/classname": "1.5.12",
17
+ "@vnejs/uis.utils": "~0.1.0",
18
+ "react": "19.2.4",
19
+ "react-dom": "19.2.4"
20
+ },
21
+ "devDependencies": {
22
+ "@vnejs/uis.react": "~0.1.0",
23
+ "typescript": "^5.7.3",
24
+ "@types/react": "^19.0.10",
25
+ "@types/react-dom": "^19.0.4"
26
+ },
27
+ "files": [
28
+ "dist",
29
+ "package.json"
30
+ ]
31
+ }