@vuer-ai/vuer-uikit 0.0.19 → 0.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-2JCULHBM.js +58 -0
- package/dist/chunk-2TRYGIGT.mjs +76 -0
- package/dist/chunk-2YCL2ET2.js +431 -0
- package/dist/chunk-3FR3WKI4.mjs +24 -0
- package/dist/chunk-44KW6PTD.mjs +111 -0
- package/dist/chunk-5OUTEHVX.js +48 -0
- package/dist/chunk-5SR53QBZ.js +143 -0
- package/dist/chunk-5TVG5JK5.js +93 -0
- package/dist/chunk-5ZZC23M7.mjs +60 -0
- package/dist/chunk-6N5422RT.js +110 -0
- package/dist/chunk-AOUGWGQR.js +609 -0
- package/dist/chunk-B2E7AY66.mjs +86 -0
- package/dist/chunk-BOPZFNFS.mjs +54 -0
- package/dist/chunk-CLTLT5XW.js +27 -0
- package/dist/chunk-DDOX4EEM.mjs +46 -0
- package/dist/chunk-DZ4J7I7I.mjs +114 -0
- package/dist/chunk-E33MW663.js +179 -0
- package/dist/chunk-EAZQH4IX.mjs +27 -0
- package/dist/chunk-EFIRD3FN.js +69 -0
- package/dist/chunk-EOFYA6CS.js +53 -0
- package/dist/chunk-EUY74AXP.mjs +341 -0
- package/dist/chunk-EYIFKSU2.mjs +259 -0
- package/dist/chunk-F56ZKT7B.mjs +1 -0
- package/dist/chunk-F776EMXP.mjs +82 -0
- package/dist/chunk-FORVP7XH.js +164 -0
- package/dist/chunk-FP26SRGL.js +377 -0
- package/dist/chunk-FRT225GK.mjs +34 -0
- package/dist/chunk-G5KMD72J.mjs +162 -0
- package/dist/chunk-G6PRZVSE.mjs +71 -0
- package/dist/chunk-H5P4IX7R.js +67 -0
- package/dist/chunk-HLJ7PQA7.mjs +15 -0
- package/dist/chunk-IGBWUFZL.js +79 -0
- package/dist/chunk-IXHMIR5P.js +131 -0
- package/dist/chunk-JAMJUXBY.mjs +45 -0
- package/dist/chunk-JMPVDU2C.mjs +110 -0
- package/dist/chunk-KJ42IGH6.js +2 -0
- package/dist/chunk-KTNZSZ5Y.mjs +23 -0
- package/dist/chunk-LEPXSM36.mjs +46 -0
- package/dist/chunk-LLXRJYQB.mjs +31 -0
- package/dist/chunk-M4IVLZIH.mjs +1 -0
- package/dist/chunk-MRVMXKZO.mjs +106 -0
- package/dist/chunk-MZ4POL3U.js +301 -0
- package/dist/chunk-N7CINZS2.js +2 -0
- package/dist/chunk-NODFVSVC.mjs +39 -0
- package/dist/chunk-OOI3SJDU.mjs +206 -0
- package/dist/chunk-OQ237S4Z.js +94 -0
- package/dist/chunk-OTPUWWEB.js +98 -0
- package/dist/chunk-PIR7EZC6.js +187 -0
- package/dist/chunk-PVRQNCSJ.js +49 -0
- package/dist/chunk-Q5KEB4UK.mjs +51 -0
- package/dist/chunk-QEY7BWIR.js +208 -0
- package/dist/chunk-QJR6MCTR.js +32 -0
- package/dist/chunk-QVUX6LLD.mjs +270 -0
- package/dist/chunk-QYRRQ65X.mjs +115 -0
- package/dist/chunk-SKO72K64.js +118 -0
- package/dist/chunk-T3VSSE2L.mjs +165 -0
- package/dist/chunk-TMBKCIVQ.mjs +148 -0
- package/dist/chunk-U2ZLDPOE.js +261 -0
- package/dist/chunk-U7SNLMJR.js +110 -0
- package/dist/chunk-UFHMEEGL.js +113 -0
- package/dist/chunk-UKFVRXAR.mjs +409 -0
- package/dist/chunk-UPTTGNMB.js +41 -0
- package/dist/chunk-V4KNORQN.js +21 -0
- package/dist/chunk-VAXIFFOT.js +83 -0
- package/dist/chunk-VGCVIHBR.mjs +1 -0
- package/dist/chunk-VXHM7V6F.mjs +92 -0
- package/dist/chunk-WDUTW7HS.mjs +87 -0
- package/dist/chunk-WJ7T7FAH.js +135 -0
- package/dist/chunk-WO3WHXDP.mjs +66 -0
- package/dist/chunk-X55EAYE2.js +94 -0
- package/dist/chunk-XMG3IVGZ.mjs +95 -0
- package/dist/chunk-XWS4SIB5.js +2 -0
- package/dist/chunk-XXWQ4RVP.js +25 -0
- package/dist/chunk-Y5I2GI4V.js +33 -0
- package/dist/chunk-YXDJPCAF.js +99 -0
- package/dist/chunk-ZVG2UKKC.mjs +603 -0
- package/dist/highlight-cursor/cursor-context.d.mts +7 -0
- package/dist/highlight-cursor/cursor-context.d.ts +7 -0
- package/dist/highlight-cursor/cursor-context.js +14 -0
- package/dist/highlight-cursor/cursor-context.mjs +1 -0
- package/dist/highlight-cursor/cursor-provider.d.mts +7 -0
- package/dist/highlight-cursor/cursor-provider.d.ts +7 -0
- package/dist/highlight-cursor/cursor-provider.js +12 -0
- package/dist/highlight-cursor/cursor-provider.mjs +3 -0
- package/dist/highlight-cursor/enhanced-components.d.mts +20 -0
- package/dist/highlight-cursor/enhanced-components.d.ts +20 -0
- package/dist/highlight-cursor/enhanced-components.js +37 -0
- package/dist/highlight-cursor/enhanced-components.mjs +12 -0
- package/dist/highlight-cursor/index.d.mts +16 -0
- package/dist/highlight-cursor/index.d.ts +16 -0
- package/dist/highlight-cursor/index.js +51 -0
- package/dist/highlight-cursor/index.mjs +14 -0
- package/dist/highlight-cursor/tabs-cursor-context.d.mts +14 -0
- package/dist/highlight-cursor/tabs-cursor-context.d.ts +14 -0
- package/dist/highlight-cursor/tabs-cursor-context.js +14 -0
- package/dist/highlight-cursor/tabs-cursor-context.mjs +1 -0
- package/dist/highlight-cursor/types.d.mts +39 -0
- package/dist/highlight-cursor/types.d.ts +39 -0
- package/dist/highlight-cursor/types.js +2 -0
- package/dist/highlight-cursor/types.mjs +1 -0
- package/dist/highlight-cursor/with-cursor.d.mts +7 -0
- package/dist/highlight-cursor/with-cursor.d.ts +7 -0
- package/dist/highlight-cursor/with-cursor.js +11 -0
- package/dist/highlight-cursor/with-cursor.mjs +2 -0
- package/dist/index.css +318 -0
- package/dist/index.d.mts +55 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.js +131 -131
- package/dist/index.mjs +38 -0
- package/dist/styles/theme.css +192 -0
- package/dist/styles/theme.d.mts +2 -0
- package/dist/styles/theme.d.ts +2 -0
- package/dist/styles/toast.css +61 -0
- package/dist/styles/toast.d.mts +2 -0
- package/dist/styles/toast.d.ts +2 -0
- package/dist/styles/variables.css +188 -0
- package/dist/styles/variables.d.mts +2 -0
- package/dist/styles/variables.d.ts +2 -0
- package/dist/ui/avatar.d.mts +16 -0
- package/dist/ui/avatar.d.ts +16 -0
- package/dist/ui/avatar.js +25 -0
- package/dist/ui/avatar.mjs +4 -0
- package/dist/ui/badge.d.mts +14 -0
- package/dist/ui/badge.d.ts +14 -0
- package/dist/ui/badge.js +17 -0
- package/dist/ui/badge.mjs +4 -0
- package/dist/ui/button.d.mts +16 -0
- package/dist/ui/button.d.ts +16 -0
- package/dist/ui/button.js +13 -0
- package/dist/ui/button.mjs +4 -0
- package/dist/ui/card.d.mts +12 -0
- package/dist/ui/card.d.ts +12 -0
- package/dist/ui/card.js +37 -0
- package/dist/ui/card.mjs +4 -0
- package/dist/ui/checkbox.d.mts +11 -0
- package/dist/ui/checkbox.d.ts +11 -0
- package/dist/ui/checkbox.js +13 -0
- package/dist/ui/checkbox.mjs +4 -0
- package/dist/ui/collapsible.d.mts +9 -0
- package/dist/ui/collapsible.d.ts +9 -0
- package/dist/ui/collapsible.js +21 -0
- package/dist/ui/collapsible.mjs +4 -0
- package/dist/ui/dropdown.d.mts +28 -0
- package/dist/ui/dropdown.d.ts +28 -0
- package/dist/ui/dropdown.js +69 -0
- package/dist/ui/dropdown.mjs +4 -0
- package/dist/ui/index.d.mts +47 -0
- package/dist/ui/index.d.ts +47 -0
- package/dist/ui/index.js +414 -0
- package/dist/ui/index.mjs +33 -0
- package/dist/ui/input-numbers.d.mts +15 -0
- package/dist/ui/input-numbers.d.ts +15 -0
- package/dist/ui/input-numbers.js +14 -0
- package/dist/ui/input-numbers.mjs +5 -0
- package/dist/ui/input.d.mts +22 -0
- package/dist/ui/input.d.ts +22 -0
- package/dist/ui/input.js +17 -0
- package/dist/ui/input.mjs +4 -0
- package/dist/ui/layout.d.mts +12 -0
- package/dist/ui/layout.d.ts +12 -0
- package/dist/ui/layout.js +13 -0
- package/dist/ui/layout.mjs +4 -0
- package/dist/ui/modal.d.mts +28 -0
- package/dist/ui/modal.d.ts +28 -0
- package/dist/ui/modal.js +49 -0
- package/dist/ui/modal.mjs +4 -0
- package/dist/ui/popover.d.mts +10 -0
- package/dist/ui/popover.d.ts +10 -0
- package/dist/ui/popover.js +25 -0
- package/dist/ui/popover.mjs +4 -0
- package/dist/ui/radio-group.d.mts +8 -0
- package/dist/ui/radio-group.d.ts +8 -0
- package/dist/ui/radio-group.js +17 -0
- package/dist/ui/radio-group.mjs +4 -0
- package/dist/ui/select.d.mts +28 -0
- package/dist/ui/select.d.ts +28 -0
- package/dist/ui/select.js +49 -0
- package/dist/ui/select.mjs +4 -0
- package/dist/ui/sheet.d.mts +16 -0
- package/dist/ui/sheet.d.ts +16 -0
- package/dist/ui/sheet.js +39 -0
- package/dist/ui/sheet.mjs +2 -0
- package/dist/ui/slider.d.mts +10 -0
- package/dist/ui/slider.d.ts +10 -0
- package/dist/ui/slider.js +13 -0
- package/dist/ui/slider.mjs +4 -0
- package/dist/ui/switch.d.mts +7 -0
- package/dist/ui/switch.d.ts +7 -0
- package/dist/ui/switch.js +13 -0
- package/dist/ui/switch.mjs +4 -0
- package/dist/ui/tabs.d.mts +16 -0
- package/dist/ui/tabs.d.ts +16 -0
- package/dist/ui/tabs.js +26 -0
- package/dist/ui/tabs.mjs +5 -0
- package/dist/ui/textarea.d.mts +16 -0
- package/dist/ui/textarea.d.ts +16 -0
- package/dist/ui/textarea.js +13 -0
- package/dist/ui/textarea.mjs +4 -0
- package/dist/ui/theme-context.d.mts +17 -0
- package/dist/ui/theme-context.d.ts +17 -0
- package/dist/ui/theme-context.js +17 -0
- package/dist/ui/theme-context.mjs +4 -0
- package/dist/ui/timeline.d.mts +23 -0
- package/dist/ui/timeline.d.ts +23 -0
- package/dist/ui/timeline.js +15 -0
- package/dist/ui/timeline.mjs +6 -0
- package/dist/ui/toast.d.mts +7 -0
- package/dist/ui/toast.d.ts +7 -0
- package/dist/ui/toast.js +14 -0
- package/dist/ui/toast.mjs +1 -0
- package/dist/ui/toggle-group.d.mts +12 -0
- package/dist/ui/toggle-group.d.ts +12 -0
- package/dist/ui/toggle-group.js +18 -0
- package/dist/ui/toggle-group.mjs +5 -0
- package/dist/ui/toggle.d.mts +13 -0
- package/dist/ui/toggle.d.ts +13 -0
- package/dist/ui/toggle.js +17 -0
- package/dist/ui/toggle.mjs +4 -0
- package/dist/ui/tooltip.d.mts +10 -0
- package/dist/ui/tooltip.d.ts +10 -0
- package/dist/ui/tooltip.js +25 -0
- package/dist/ui/tooltip.mjs +4 -0
- package/dist/ui/tree-view-v2.d.mts +25 -0
- package/dist/ui/tree-view-v2.d.ts +25 -0
- package/dist/ui/tree-view-v2.js +14 -0
- package/dist/ui/tree-view-v2.mjs +5 -0
- package/dist/ui/tree-view.d.mts +28 -0
- package/dist/ui/tree-view.d.ts +28 -0
- package/dist/ui/tree-view.js +11 -0
- package/dist/ui/tree-view.mjs +2 -0
- package/dist/ui/version-badge.d.mts +26 -0
- package/dist/ui/version-badge.d.ts +26 -0
- package/dist/ui/version-badge.js +14 -0
- package/dist/ui/version-badge.mjs +5 -0
- package/dist/utils/cn.d.mts +5 -0
- package/dist/utils/cn.d.ts +5 -0
- package/dist/utils/cn.js +10 -0
- package/dist/utils/cn.mjs +1 -0
- package/dist/utils/index.d.mts +3 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +16 -0
- package/dist/utils/index.mjs +3 -0
- package/dist/utils/use-local-storage.d.mts +3 -0
- package/dist/utils/use-local-storage.d.ts +3 -0
- package/dist/utils/use-local-storage.js +10 -0
- package/dist/utils/use-local-storage.mjs +1 -0
- package/package.json +3 -2
- package/src/ui/version-badge.tsx +5 -2
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { cn } from './chunk-KTNZSZ5Y.mjs';
|
|
2
|
+
import { CursorContext } from './chunk-3FR3WKI4.mjs';
|
|
3
|
+
import { useState, useRef, useEffect, useCallback, useMemo } from 'react';
|
|
4
|
+
import { createPortal } from 'react-dom';
|
|
5
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
6
|
+
|
|
7
|
+
var CursorProvider = ({
|
|
8
|
+
children,
|
|
9
|
+
maxOffsetX = 5,
|
|
10
|
+
maxOffsetY = 20,
|
|
11
|
+
cursorSize = 20,
|
|
12
|
+
transitionDuration = 100,
|
|
13
|
+
cursorClassName,
|
|
14
|
+
className,
|
|
15
|
+
as: Component = "div",
|
|
16
|
+
...props
|
|
17
|
+
}) => {
|
|
18
|
+
const [isClient, setIsClient] = useState(false);
|
|
19
|
+
const [isMouseInside, setIsMouseInside] = useState(false);
|
|
20
|
+
const [mousePosition, setMousePosition] = useState({ x: 0, y: 0 });
|
|
21
|
+
const [hoveredElementId, setHoveredElementId] = useState(null);
|
|
22
|
+
const [elementDimensions, setElementDimensions] = useState({
|
|
23
|
+
width: 0,
|
|
24
|
+
height: 0,
|
|
25
|
+
x: 0,
|
|
26
|
+
y: 0,
|
|
27
|
+
right: 0,
|
|
28
|
+
bottom: 0
|
|
29
|
+
});
|
|
30
|
+
const hoveredElementRef = useRef(null);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
setIsClient(true);
|
|
33
|
+
}, []);
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (!isClient) return;
|
|
36
|
+
const handleMouseMove = (e) => {
|
|
37
|
+
setMousePosition({ x: e.clientX, y: e.clientY });
|
|
38
|
+
};
|
|
39
|
+
document.addEventListener("mousemove", handleMouseMove);
|
|
40
|
+
return () => document.removeEventListener("mousemove", handleMouseMove);
|
|
41
|
+
}, [isClient]);
|
|
42
|
+
const handleMouseEnter = useCallback(() => {
|
|
43
|
+
setIsMouseInside(true);
|
|
44
|
+
}, []);
|
|
45
|
+
const handleMouseLeave = useCallback(() => {
|
|
46
|
+
setIsMouseInside(false);
|
|
47
|
+
setHoveredElementId(null);
|
|
48
|
+
hoveredElementRef.current = null;
|
|
49
|
+
}, []);
|
|
50
|
+
const checkMouseInElement = useCallback(() => {
|
|
51
|
+
if (!hoveredElementRef.current || !hoveredElementId) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const rect = hoveredElementRef.current.getBoundingClientRect();
|
|
55
|
+
setElementDimensions({
|
|
56
|
+
width: rect.width,
|
|
57
|
+
height: rect.height,
|
|
58
|
+
x: rect.left,
|
|
59
|
+
y: rect.top,
|
|
60
|
+
right: rect.right,
|
|
61
|
+
bottom: rect.bottom
|
|
62
|
+
});
|
|
63
|
+
const isInside = mousePosition.x >= rect.left && mousePosition.x <= rect.right && mousePosition.y >= rect.top && mousePosition.y <= rect.bottom;
|
|
64
|
+
if (!isInside) {
|
|
65
|
+
setHoveredElementId(null);
|
|
66
|
+
hoveredElementRef.current = null;
|
|
67
|
+
}
|
|
68
|
+
}, [mousePosition, hoveredElementId]);
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (!isClient) return;
|
|
71
|
+
const handleScroll = () => {
|
|
72
|
+
checkMouseInElement();
|
|
73
|
+
};
|
|
74
|
+
document.addEventListener("scroll", handleScroll, { passive: true, capture: true });
|
|
75
|
+
return () => {
|
|
76
|
+
document.removeEventListener("scroll", handleScroll, { capture: true });
|
|
77
|
+
};
|
|
78
|
+
}, [checkMouseInElement, isClient]);
|
|
79
|
+
const registerHoveredElement = useCallback(
|
|
80
|
+
(id, dimensions, element) => {
|
|
81
|
+
setHoveredElementId(id);
|
|
82
|
+
setElementDimensions({
|
|
83
|
+
width: dimensions.width,
|
|
84
|
+
height: dimensions.height,
|
|
85
|
+
x: dimensions.left,
|
|
86
|
+
y: dimensions.top,
|
|
87
|
+
right: dimensions.right,
|
|
88
|
+
bottom: dimensions.bottom
|
|
89
|
+
});
|
|
90
|
+
if (element) {
|
|
91
|
+
hoveredElementRef.current = element;
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
[]
|
|
95
|
+
);
|
|
96
|
+
const unregisterHoveredElement = useCallback(() => {
|
|
97
|
+
setHoveredElementId(null);
|
|
98
|
+
hoveredElementRef.current = null;
|
|
99
|
+
}, []);
|
|
100
|
+
const updateElementDimensions = useCallback(
|
|
101
|
+
(dimensions) => {
|
|
102
|
+
if (hoveredElementId) {
|
|
103
|
+
setElementDimensions({
|
|
104
|
+
width: dimensions.width,
|
|
105
|
+
height: dimensions.height,
|
|
106
|
+
x: dimensions.left,
|
|
107
|
+
y: dimensions.top,
|
|
108
|
+
right: dimensions.right,
|
|
109
|
+
bottom: dimensions.bottom
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
[hoveredElementId]
|
|
114
|
+
);
|
|
115
|
+
const getCursorPosition = () => {
|
|
116
|
+
if (!hoveredElementId) {
|
|
117
|
+
return {
|
|
118
|
+
x: mousePosition.x - cursorSize / 2,
|
|
119
|
+
y: mousePosition.y - cursorSize / 2
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
const elementCenterX = elementDimensions.x + elementDimensions.width / 2;
|
|
123
|
+
const elementCenterY = elementDimensions.y + elementDimensions.height / 2;
|
|
124
|
+
const offsetX = (mousePosition.x - elementCenterX) * 0.1;
|
|
125
|
+
const offsetY = (mousePosition.y - elementCenterY) * 0.1;
|
|
126
|
+
const boundedOffsetX = Math.max(-maxOffsetX, Math.min(maxOffsetX, offsetX));
|
|
127
|
+
const boundedOffsetY = Math.max(-maxOffsetY, Math.min(maxOffsetY, offsetY));
|
|
128
|
+
return {
|
|
129
|
+
x: elementDimensions.x + boundedOffsetX,
|
|
130
|
+
y: elementDimensions.y + boundedOffsetY
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
const contextValue = useMemo(
|
|
134
|
+
() => ({
|
|
135
|
+
// State values that change during component lifecycle
|
|
136
|
+
mousePosition,
|
|
137
|
+
hoveredElementId,
|
|
138
|
+
elementDimensions,
|
|
139
|
+
// Callbacks that should be stable references
|
|
140
|
+
registerHoveredElement,
|
|
141
|
+
unregisterHoveredElement,
|
|
142
|
+
updateElementDimensions
|
|
143
|
+
}),
|
|
144
|
+
[
|
|
145
|
+
mousePosition,
|
|
146
|
+
hoveredElementId,
|
|
147
|
+
elementDimensions,
|
|
148
|
+
registerHoveredElement,
|
|
149
|
+
unregisterHoveredElement,
|
|
150
|
+
updateElementDimensions
|
|
151
|
+
]
|
|
152
|
+
);
|
|
153
|
+
const cursorPosition = getCursorPosition();
|
|
154
|
+
const cursorStyleObject = useMemo(
|
|
155
|
+
() => ({
|
|
156
|
+
left: cursorPosition.x,
|
|
157
|
+
top: cursorPosition.y,
|
|
158
|
+
width: hoveredElementId ? elementDimensions.width > 0 ? elementDimensions.width : cursorSize : cursorSize,
|
|
159
|
+
height: hoveredElementId ? elementDimensions.height > 0 ? elementDimensions.height : cursorSize : cursorSize,
|
|
160
|
+
willChange: "transform, width, height"
|
|
161
|
+
}),
|
|
162
|
+
[
|
|
163
|
+
cursorPosition.x,
|
|
164
|
+
cursorPosition.y,
|
|
165
|
+
hoveredElementId,
|
|
166
|
+
elementDimensions.width,
|
|
167
|
+
elementDimensions.height,
|
|
168
|
+
cursorSize
|
|
169
|
+
]
|
|
170
|
+
);
|
|
171
|
+
let styleClass;
|
|
172
|
+
if (hoveredElementId) {
|
|
173
|
+
styleClass = `opacity-[0.05] rounded-md transition-[width,height,left,top] duration-${transitionDuration} ease-out`;
|
|
174
|
+
} else {
|
|
175
|
+
styleClass = `opacity-90 rounded-xl z-10 transition-[width,height,left,top] duration-${transitionDuration} ease-out transition-opacity duration-${transitionDuration}`;
|
|
176
|
+
}
|
|
177
|
+
const cursorElement = isClient && isMouseInside && /* @__PURE__ */ jsx(
|
|
178
|
+
"div",
|
|
179
|
+
{
|
|
180
|
+
className: `pointer-events-none fixed ${styleClass} ${hoveredElementId ? "" : cursorClassName || ""}`,
|
|
181
|
+
style: {
|
|
182
|
+
...cursorStyleObject,
|
|
183
|
+
backgroundColor: "var(--shadow-tertiary)"
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
);
|
|
187
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
188
|
+
isClient && typeof document !== "undefined" && document.body && cursorElement && createPortal(cursorElement, document.body),
|
|
189
|
+
/* @__PURE__ */ jsx(CursorContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(
|
|
190
|
+
Component,
|
|
191
|
+
{
|
|
192
|
+
...props,
|
|
193
|
+
className: cn(className),
|
|
194
|
+
style: {
|
|
195
|
+
cursor: isMouseInside && !hoveredElementId ? "none" : "auto",
|
|
196
|
+
...props.style
|
|
197
|
+
},
|
|
198
|
+
onMouseEnter: handleMouseEnter,
|
|
199
|
+
onMouseLeave: handleMouseLeave,
|
|
200
|
+
children
|
|
201
|
+
}
|
|
202
|
+
) })
|
|
203
|
+
] });
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
export { CursorProvider };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkXXWQ4RVP_js = require('./chunk-XXWQ4RVP.js');
|
|
4
|
+
var reactSlot = require('@radix-ui/react-slot');
|
|
5
|
+
var classVarianceAuthority = require('class-variance-authority');
|
|
6
|
+
var react = require('react');
|
|
7
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
8
|
+
|
|
9
|
+
var buttonVariants = classVarianceAuthority.cva(
|
|
10
|
+
[
|
|
11
|
+
"inline-flex",
|
|
12
|
+
"cursor-pointer",
|
|
13
|
+
"items-center",
|
|
14
|
+
"justify-center",
|
|
15
|
+
"shrink-0",
|
|
16
|
+
"whitespace-nowrap",
|
|
17
|
+
"rounded-uk-sm",
|
|
18
|
+
"font-medium",
|
|
19
|
+
"transition-all",
|
|
20
|
+
"[&_svg]:shrink-0 ",
|
|
21
|
+
"[&_svg]:pointer-events-none",
|
|
22
|
+
"outline-none",
|
|
23
|
+
"disabled:pointer-events-none",
|
|
24
|
+
"disabled:bg-bg-tertiary",
|
|
25
|
+
"disabled:text-text-tertiary",
|
|
26
|
+
"focus-visible:border-ring",
|
|
27
|
+
"focus-visible:ring-ring/50",
|
|
28
|
+
"focus-visible:ring-[3px]",
|
|
29
|
+
"focus-visible:bg-brand-tertiary",
|
|
30
|
+
"aria-invalid:ring-destructive/20",
|
|
31
|
+
"aria-invalid:border-destructive"
|
|
32
|
+
],
|
|
33
|
+
{
|
|
34
|
+
variants: {
|
|
35
|
+
variant: {
|
|
36
|
+
primary: [
|
|
37
|
+
"bg-brand-primary",
|
|
38
|
+
"text-text-withbg",
|
|
39
|
+
"hover:bg-brand-secondary",
|
|
40
|
+
"active:bg-brand-tertiary"
|
|
41
|
+
],
|
|
42
|
+
secondary: [
|
|
43
|
+
"bg-bg-secondary",
|
|
44
|
+
"text-text-highlight",
|
|
45
|
+
"hover:bg-bg-quaternary",
|
|
46
|
+
"active:bg-bg-tertiary"
|
|
47
|
+
],
|
|
48
|
+
destructive: [
|
|
49
|
+
"bg-danger-primary",
|
|
50
|
+
"text-text-withbg",
|
|
51
|
+
"hover:bg-danger-secondary",
|
|
52
|
+
"active:bg-danger-tertiary"
|
|
53
|
+
],
|
|
54
|
+
ghost: [
|
|
55
|
+
"text-text-primary",
|
|
56
|
+
"hover:bg-bg-tertiary",
|
|
57
|
+
"hover:text-text-secondary",
|
|
58
|
+
"active:bg-bg-secondary"
|
|
59
|
+
],
|
|
60
|
+
link: ["text-text-primary", "underline-offset-4", "hover:underline"]
|
|
61
|
+
},
|
|
62
|
+
size: {
|
|
63
|
+
sm: ["text-uk-sm", "h-5.5", "gap-xxs", "px-md", "[&_svg:not([class*='size-'])]:size-3"],
|
|
64
|
+
base: ["text-uk-md", "h-7 ", "gap-xs", " px-lg", "[&_svg:not([class*='size-'])]:size-3.5"],
|
|
65
|
+
lg: ["text-uk-lg", "h-8", " gap-xs", "px-xl", "[&_svg:not([class*='size-'])]:size-4"]
|
|
66
|
+
},
|
|
67
|
+
icon: { false: null, true: null }
|
|
68
|
+
},
|
|
69
|
+
compoundVariants: [
|
|
70
|
+
{ size: "sm", icon: true, class: ["px-xs", "py-xs", " size-5.5"] },
|
|
71
|
+
{ size: "base", icon: true, class: ["px-sm", "py-sm", "size-7"] },
|
|
72
|
+
{ size: "lg", icon: true, class: ["px-md", "py-md", " size-8"] }
|
|
73
|
+
],
|
|
74
|
+
defaultVariants: {
|
|
75
|
+
variant: "primary",
|
|
76
|
+
size: "base",
|
|
77
|
+
icon: false
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
var Button = react.forwardRef(function Button2({ className, variant, size, icon, asChild = false, ...props }, ref) {
|
|
82
|
+
const Comp = asChild ? reactSlot.Slot : "button";
|
|
83
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
84
|
+
Comp,
|
|
85
|
+
{
|
|
86
|
+
ref,
|
|
87
|
+
"data-slot": "button",
|
|
88
|
+
className: chunkXXWQ4RVP_js.cn(buttonVariants({ variant, size, icon, className })),
|
|
89
|
+
...props
|
|
90
|
+
}
|
|
91
|
+
);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
exports.Button = Button;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var framerMotion = require('framer-motion');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var reactDom = require('react-dom');
|
|
6
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
7
|
+
|
|
8
|
+
// src/highlight-cursor/tabs-cursor-context.tsx
|
|
9
|
+
var TabsCursorContext = react.createContext(null);
|
|
10
|
+
var TabsCursorProvider = ({
|
|
11
|
+
children,
|
|
12
|
+
className,
|
|
13
|
+
...props
|
|
14
|
+
}) => {
|
|
15
|
+
const [isClient, setIsClient] = react.useState(false);
|
|
16
|
+
const [cursorTarget, setCursorTarget] = react.useState(null);
|
|
17
|
+
const [targetRect, setTargetRect] = react.useState(null);
|
|
18
|
+
const [mousePosition, setMousePosition] = react.useState({ x: 0, y: 0 });
|
|
19
|
+
const [isMouseInside, setIsMouseInside] = react.useState(false);
|
|
20
|
+
react.useEffect(() => {
|
|
21
|
+
setIsClient(true);
|
|
22
|
+
}, []);
|
|
23
|
+
react.useEffect(() => {
|
|
24
|
+
if (!isClient) return;
|
|
25
|
+
const handleMouseMove = (e) => {
|
|
26
|
+
setMousePosition({ x: e.clientX, y: e.clientY });
|
|
27
|
+
};
|
|
28
|
+
document.addEventListener("mousemove", handleMouseMove);
|
|
29
|
+
return () => document.removeEventListener("mousemove", handleMouseMove);
|
|
30
|
+
}, [isClient]);
|
|
31
|
+
react.useEffect(() => {
|
|
32
|
+
if (cursorTarget) {
|
|
33
|
+
setTargetRect(cursorTarget.getBoundingClientRect());
|
|
34
|
+
} else {
|
|
35
|
+
setTargetRect(null);
|
|
36
|
+
}
|
|
37
|
+
}, [cursorTarget]);
|
|
38
|
+
const handleMouseEnter = react.useCallback(() => {
|
|
39
|
+
setIsMouseInside(true);
|
|
40
|
+
}, []);
|
|
41
|
+
const handleMouseLeave = react.useCallback(() => {
|
|
42
|
+
setIsMouseInside(false);
|
|
43
|
+
setCursorTarget(null);
|
|
44
|
+
}, []);
|
|
45
|
+
const contextValue = { setCursorTarget };
|
|
46
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
47
|
+
"div",
|
|
48
|
+
{
|
|
49
|
+
...props,
|
|
50
|
+
className,
|
|
51
|
+
style: {
|
|
52
|
+
cursor: isMouseInside && !cursorTarget ? "none" : "auto",
|
|
53
|
+
...props.style
|
|
54
|
+
},
|
|
55
|
+
onMouseEnter: handleMouseEnter,
|
|
56
|
+
onMouseLeave: handleMouseLeave,
|
|
57
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(TabsCursorContext.Provider, { value: contextValue, children: [
|
|
58
|
+
children,
|
|
59
|
+
isClient && isMouseInside && typeof document !== "undefined" && document.body && reactDom.createPortal(
|
|
60
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
61
|
+
framerMotion.motion.div,
|
|
62
|
+
{
|
|
63
|
+
className: "pointer-events-none",
|
|
64
|
+
initial: false,
|
|
65
|
+
animate: {
|
|
66
|
+
x: targetRect ? targetRect.left : mousePosition.x - 8,
|
|
67
|
+
y: targetRect ? targetRect.top : mousePosition.y - 8,
|
|
68
|
+
width: targetRect ? targetRect.width : 16,
|
|
69
|
+
height: targetRect ? targetRect.height : 16,
|
|
70
|
+
borderRadius: targetRect && cursorTarget && typeof window !== "undefined" ? getComputedStyle(cursorTarget).borderRadius : "50%"
|
|
71
|
+
},
|
|
72
|
+
transition: { type: "spring", stiffness: 1e3, damping: 60, mass: 1 },
|
|
73
|
+
style: {
|
|
74
|
+
position: "fixed",
|
|
75
|
+
top: 0,
|
|
76
|
+
left: 0,
|
|
77
|
+
backgroundColor: "var(--shadow-tertiary)",
|
|
78
|
+
zIndex: 9999
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
),
|
|
82
|
+
document.body
|
|
83
|
+
)
|
|
84
|
+
] })
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
};
|
|
88
|
+
var useTabsCursor = () => {
|
|
89
|
+
const context = react.useContext(TabsCursorContext);
|
|
90
|
+
if (!context) {
|
|
91
|
+
return { setCursorTarget: () => {
|
|
92
|
+
} };
|
|
93
|
+
}
|
|
94
|
+
return context;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
exports.TabsCursorProvider = TabsCursorProvider;
|
|
98
|
+
exports.useTabsCursor = useTabsCursor;
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkXXWQ4RVP_js = require('./chunk-XXWQ4RVP.js');
|
|
4
|
+
var SliderPrimitive = require('@radix-ui/react-slider');
|
|
5
|
+
var react = require('react');
|
|
6
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
7
|
+
|
|
8
|
+
function _interopNamespace(e) {
|
|
9
|
+
if (e && e.__esModule) return e;
|
|
10
|
+
var n = Object.create(null);
|
|
11
|
+
if (e) {
|
|
12
|
+
Object.keys(e).forEach(function (k) {
|
|
13
|
+
if (k !== 'default') {
|
|
14
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
15
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return e[k]; }
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
n.default = e;
|
|
23
|
+
return Object.freeze(n);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
var SliderPrimitive__namespace = /*#__PURE__*/_interopNamespace(SliderPrimitive);
|
|
27
|
+
|
|
28
|
+
var Slider = react.forwardRef(function Slider2({
|
|
29
|
+
className,
|
|
30
|
+
defaultValue,
|
|
31
|
+
value,
|
|
32
|
+
onValueChange,
|
|
33
|
+
showStep = false,
|
|
34
|
+
step = 1,
|
|
35
|
+
min = 0,
|
|
36
|
+
max = 100,
|
|
37
|
+
...props
|
|
38
|
+
}, ref) {
|
|
39
|
+
const [currentValue, setCurrentValue] = react.useState(value ?? defaultValue ?? [0]);
|
|
40
|
+
const _values = react.useMemo(
|
|
41
|
+
() => Array.isArray(value) ? value : Array.isArray(defaultValue) ? defaultValue : [min, max],
|
|
42
|
+
[value, defaultValue, min, max]
|
|
43
|
+
);
|
|
44
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
45
|
+
SliderPrimitive__namespace.Root,
|
|
46
|
+
{
|
|
47
|
+
"data-slot": "slider",
|
|
48
|
+
value,
|
|
49
|
+
defaultValue,
|
|
50
|
+
onValueChange: (v) => {
|
|
51
|
+
onValueChange == null ? void 0 : onValueChange(v);
|
|
52
|
+
setCurrentValue(v);
|
|
53
|
+
},
|
|
54
|
+
ref,
|
|
55
|
+
min,
|
|
56
|
+
max,
|
|
57
|
+
step,
|
|
58
|
+
className: chunkXXWQ4RVP_js.cn(
|
|
59
|
+
"relative",
|
|
60
|
+
"flex",
|
|
61
|
+
"w-full",
|
|
62
|
+
"touch-none",
|
|
63
|
+
"select-none",
|
|
64
|
+
"items-center",
|
|
65
|
+
"data-[orientation=vertical]:h-full",
|
|
66
|
+
"data-[orientation=vertical]:min-h-44",
|
|
67
|
+
"data-[orientation=vertical]:w-auto",
|
|
68
|
+
"data-[orientation=vertical]:flex-col",
|
|
69
|
+
className
|
|
70
|
+
),
|
|
71
|
+
...props,
|
|
72
|
+
children: [
|
|
73
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
74
|
+
SliderPrimitive__namespace.Track,
|
|
75
|
+
{
|
|
76
|
+
"data-slot": "slider-track",
|
|
77
|
+
className: chunkXXWQ4RVP_js.cn(
|
|
78
|
+
"peer/slider-track",
|
|
79
|
+
"bg-line-primary",
|
|
80
|
+
"relative",
|
|
81
|
+
"grow",
|
|
82
|
+
"overflow-hidden",
|
|
83
|
+
"rounded-full",
|
|
84
|
+
"data-[disabled]:bg-bg-secondary",
|
|
85
|
+
"data-[orientation=vertical]:w-0.5",
|
|
86
|
+
"data-[orientation=vertical]:h-full",
|
|
87
|
+
"data-[orientation=horizontal]:h-0.5",
|
|
88
|
+
"data-[orientation=horizontal]:w-full"
|
|
89
|
+
),
|
|
90
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
91
|
+
SliderPrimitive__namespace.Range,
|
|
92
|
+
{
|
|
93
|
+
"data-slot": "slider-range",
|
|
94
|
+
className: chunkXXWQ4RVP_js.cn(
|
|
95
|
+
"bg-brand-primary",
|
|
96
|
+
"absolute",
|
|
97
|
+
"data-[disabled]:bg-bg-secondary",
|
|
98
|
+
"data-[orientation=vertical]:w-full",
|
|
99
|
+
"data-[orientation=horizontal]:h-full"
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
),
|
|
105
|
+
showStep && /* @__PURE__ */ jsxRuntime.jsx(SliderSteps, { currentValue, max, min, step }),
|
|
106
|
+
Array.from({ length: _values.length }, (_, index) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
107
|
+
SliderPrimitive__namespace.Thumb,
|
|
108
|
+
{
|
|
109
|
+
"data-slot": "slider-thumb",
|
|
110
|
+
className: chunkXXWQ4RVP_js.cn(
|
|
111
|
+
"ring-brand-primary/50",
|
|
112
|
+
"bg-brand-primary",
|
|
113
|
+
"block",
|
|
114
|
+
"h-4",
|
|
115
|
+
"w-[0.6rem]",
|
|
116
|
+
"shrink-0",
|
|
117
|
+
"rounded-[3px]",
|
|
118
|
+
"transition-[color,box-shadow]",
|
|
119
|
+
"hover:ring-4",
|
|
120
|
+
"hover:cursor-ew-resize",
|
|
121
|
+
"focus-visible:ring-4",
|
|
122
|
+
"focus-visible:outline-hidden",
|
|
123
|
+
"data-[disabled]:bg-bg-tertiary",
|
|
124
|
+
"data-[disabled]:pointer-events-none"
|
|
125
|
+
)
|
|
126
|
+
},
|
|
127
|
+
index
|
|
128
|
+
))
|
|
129
|
+
]
|
|
130
|
+
}
|
|
131
|
+
);
|
|
132
|
+
});
|
|
133
|
+
function SliderSteps({ step, min, max, currentValue }) {
|
|
134
|
+
const steps = react.useMemo(() => {
|
|
135
|
+
const value = max - min;
|
|
136
|
+
const stepCount = Math.ceil(value / step);
|
|
137
|
+
return Array.from({ length: stepCount + 1 }, (_, i) => {
|
|
138
|
+
return { position: Math.min(100 / value * (i * step), 100), v: i * step + min };
|
|
139
|
+
});
|
|
140
|
+
}, [max, min, step]);
|
|
141
|
+
const [minRange, maxRange] = react.useMemo(() => {
|
|
142
|
+
if (currentValue.length > 1) {
|
|
143
|
+
return [Math.min(...currentValue), Math.max(...currentValue)];
|
|
144
|
+
} else {
|
|
145
|
+
return [0, ...currentValue];
|
|
146
|
+
}
|
|
147
|
+
}, [currentValue]);
|
|
148
|
+
return steps.map((step2, i) => {
|
|
149
|
+
const thumbInBoundsOffset = getThumbInBoundsOffset(9.6, step2.position, 1);
|
|
150
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
151
|
+
"span",
|
|
152
|
+
{
|
|
153
|
+
"data-slot": "slider-step",
|
|
154
|
+
style: { left: `calc(${step2.position}% + ${thumbInBoundsOffset}px)` },
|
|
155
|
+
className: chunkXXWQ4RVP_js.cn(
|
|
156
|
+
"absolute",
|
|
157
|
+
"top-1/2",
|
|
158
|
+
"translate-y-[-50%]",
|
|
159
|
+
"translate-x-[-50%]",
|
|
160
|
+
"bg-brand-primary",
|
|
161
|
+
"block",
|
|
162
|
+
"h-[5pt]",
|
|
163
|
+
"w-[1pt]",
|
|
164
|
+
"shrink-0",
|
|
165
|
+
"rounded-[1px]",
|
|
166
|
+
"peer-has-data-[disabled]/slider-track:bg-bg-tertiary",
|
|
167
|
+
{ "bg-bg-tertiary": step2.v < minRange || step2.v > maxRange }
|
|
168
|
+
)
|
|
169
|
+
},
|
|
170
|
+
i
|
|
171
|
+
);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
function getThumbInBoundsOffset(width, left, direction) {
|
|
175
|
+
const halfWidth = width / 2;
|
|
176
|
+
const halfPercent = 50;
|
|
177
|
+
const offset = linearScale([0, halfPercent], [0, halfWidth]);
|
|
178
|
+
return (halfWidth - offset(left) * direction) * direction;
|
|
179
|
+
}
|
|
180
|
+
function linearScale(input, output) {
|
|
181
|
+
return (value) => {
|
|
182
|
+
const ratio = (output[1] - output[0]) / (input[1] - input[0]);
|
|
183
|
+
return output[0] + ratio * (value - input[0]);
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
exports.Slider = Slider;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkEOFYA6CS_js = require('./chunk-EOFYA6CS.js');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
|
|
7
|
+
var initialState = {
|
|
8
|
+
theme: "system",
|
|
9
|
+
setTheme: () => null
|
|
10
|
+
};
|
|
11
|
+
var ThemeProviderContext = react.createContext(initialState);
|
|
12
|
+
function ThemeProvider({
|
|
13
|
+
children,
|
|
14
|
+
defaultTheme = "system",
|
|
15
|
+
storageKey = "vuer-theme",
|
|
16
|
+
...props
|
|
17
|
+
}) {
|
|
18
|
+
const [theme, setTheme] = chunkEOFYA6CS_js.useLocalStorage(storageKey, defaultTheme);
|
|
19
|
+
react.useEffect(() => {
|
|
20
|
+
if (typeof window === "undefined") return;
|
|
21
|
+
const root = window.document.documentElement;
|
|
22
|
+
root.classList.remove("light", "dark", "liquidlight", "liquiddark", "system");
|
|
23
|
+
root.removeAttribute("data-theme");
|
|
24
|
+
if (theme === "system") {
|
|
25
|
+
const systemTheme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
26
|
+
root.classList.add(systemTheme);
|
|
27
|
+
root.setAttribute("data-theme", "auto");
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
root.classList.add(theme);
|
|
31
|
+
root.setAttribute("data-theme", theme);
|
|
32
|
+
}, [theme]);
|
|
33
|
+
const value = react.useMemo(
|
|
34
|
+
() => ({
|
|
35
|
+
theme,
|
|
36
|
+
setTheme
|
|
37
|
+
}),
|
|
38
|
+
[theme, setTheme]
|
|
39
|
+
);
|
|
40
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ThemeProviderContext.Provider, { ...props, value, children });
|
|
41
|
+
}
|
|
42
|
+
var useTheme = () => {
|
|
43
|
+
const context = react.useContext(ThemeProviderContext);
|
|
44
|
+
if (context === void 0) throw new Error("useTheme must be used within a ThemeProvider");
|
|
45
|
+
return context;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
exports.ThemeProvider = ThemeProvider;
|
|
49
|
+
exports.useTheme = useTheme;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { useState, useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
// src/utils/use-local-storage.ts
|
|
4
|
+
function useLocalStorage(key, initialValue) {
|
|
5
|
+
const [storedValue, setStoredValue] = useState(() => {
|
|
6
|
+
if (typeof window === "undefined") {
|
|
7
|
+
return initialValue;
|
|
8
|
+
}
|
|
9
|
+
try {
|
|
10
|
+
const item = window.localStorage.getItem(key);
|
|
11
|
+
if (item === null) return initialValue;
|
|
12
|
+
if (typeof initialValue === "string") {
|
|
13
|
+
return item;
|
|
14
|
+
} else if (typeof initialValue === "number") {
|
|
15
|
+
return parseFloat(item) || initialValue;
|
|
16
|
+
} else if (typeof initialValue === "boolean") {
|
|
17
|
+
return item === "true";
|
|
18
|
+
} else {
|
|
19
|
+
return JSON.parse(item);
|
|
20
|
+
}
|
|
21
|
+
} catch (error) {
|
|
22
|
+
console.warn(`Error reading localStorage key "${key}":`, error);
|
|
23
|
+
return initialValue;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
const setValue = useCallback(
|
|
27
|
+
(value) => {
|
|
28
|
+
try {
|
|
29
|
+
const valueToStore = value instanceof Function ? value(storedValue) : value;
|
|
30
|
+
setStoredValue(valueToStore);
|
|
31
|
+
if (typeof window !== "undefined") {
|
|
32
|
+
let stringValue;
|
|
33
|
+
if (typeof valueToStore === "string") {
|
|
34
|
+
stringValue = valueToStore;
|
|
35
|
+
} else if (typeof valueToStore === "number" || typeof valueToStore === "boolean") {
|
|
36
|
+
stringValue = valueToStore.toString();
|
|
37
|
+
} else {
|
|
38
|
+
stringValue = JSON.stringify(valueToStore);
|
|
39
|
+
}
|
|
40
|
+
window.localStorage.setItem(key, stringValue);
|
|
41
|
+
}
|
|
42
|
+
} catch (error) {
|
|
43
|
+
console.warn(`Error setting localStorage key "${key}":`, error);
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
[key, storedValue]
|
|
47
|
+
);
|
|
48
|
+
return [storedValue, setValue];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { useLocalStorage };
|