@vllnt/ui 0.4.0-canary.sha4d4d033 → 0.4.0-canary.sha818a399
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/components/atoms/cursor/cursor.js +48 -9
- package/dist/components/atoms/dock/dock.js +75 -17
- package/dist/components/atoms/magnetic/magnetic.js +61 -14
- package/dist/components/atoms/magnetic-button/magnetic-button.js +61 -14
- package/dist/components/atoms/order-book/order-book.js +10 -4
- package/dist/components/atoms/qr-code/qr-code.js +27 -3
- package/dist/components/atoms/reasoning/reasoning.js +7 -5
- package/dist/components/atoms/scroll-progress/scroll-progress.js +10 -2
- package/dist/components/atoms/spotlight-card/spotlight-card.js +35 -11
- package/dist/components/atoms/text-reveal/text-reveal.js +10 -2
- package/dist/components/atoms/thinking-block/thinking-block.js +7 -5
- package/dist/components/atoms/tilt-card/tilt-card.js +63 -18
- package/dist/components/atoms/toast/sonner-toast.js +4 -0
- package/dist/components/atoms/watchlist/watchlist.js +5 -4
- package/dist/components/index.js +5 -3
- package/dist/components/molecules/copy-button/copy-button.js +4 -44
- package/dist/components/molecules/copy-button/use-copy-to-clipboard.js +42 -0
- package/dist/components/molecules/progress-card/progress-card.js +8 -6
- package/dist/components/molecules/search-bar/search-bar.js +9 -5
- package/dist/components/molecules/tutorial-card/tutorial-card.js +8 -6
- package/dist/components/organisms/code-block/code-block.js +8 -7
- package/dist/components/organisms/code-playground/code-playground.js +1 -1
- package/dist/components/organisms/flow-diagram/use-flow-diagram.js +25 -11
- package/dist/components/organisms/geography-quiz-map/geography-quiz-map.js +40 -19
- package/dist/components/organisms/model-selector/model-selector.js +17 -5
- package/dist/components/organisms/share-dialog/share-dialog.js +1 -1
- package/dist/components/organisms/slideshow/slideshow.js +13 -1
- package/dist/components/organisms/static-code/static-code-copy.js +1 -1
- package/dist/components/organisms/terminal/terminal.js +1 -1
- package/dist/components/organisms/tutorial-mdx/tutorial-mdx.js +6 -5
- package/dist/index.d.ts +36 -35
- package/package.json +5 -2
|
@@ -2,21 +2,34 @@
|
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import { cn } from "../../../lib/utils.js";
|
|
5
|
-
function
|
|
6
|
-
const [
|
|
5
|
+
function usePointerFollower(follower, enabled) {
|
|
6
|
+
const [visible, setVisible] = React.useState(false);
|
|
7
7
|
React.useEffect(() => {
|
|
8
8
|
if (typeof window === "undefined") {
|
|
9
9
|
return;
|
|
10
10
|
}
|
|
11
|
+
let frame = null;
|
|
12
|
+
let point = { x: 0, y: 0 };
|
|
13
|
+
const follow = () => {
|
|
14
|
+
frame = null;
|
|
15
|
+
setVisible(true);
|
|
16
|
+
if (enabled && follower.current) {
|
|
17
|
+
follower.current.style.transform = `translate(${point.x}px, ${point.y}px) translate(-50%, -50%)`;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
11
20
|
const onMove = (event) => {
|
|
12
|
-
|
|
21
|
+
point = { x: event.clientX, y: event.clientY };
|
|
22
|
+
frame ?? (frame = requestAnimationFrame(follow));
|
|
13
23
|
};
|
|
14
24
|
window.addEventListener("pointermove", onMove, { passive: true });
|
|
15
25
|
return () => {
|
|
16
26
|
window.removeEventListener("pointermove", onMove);
|
|
27
|
+
if (frame !== null) {
|
|
28
|
+
cancelAnimationFrame(frame);
|
|
29
|
+
}
|
|
17
30
|
};
|
|
18
|
-
}, []);
|
|
19
|
-
return
|
|
31
|
+
}, [enabled, follower]);
|
|
32
|
+
return visible;
|
|
20
33
|
}
|
|
21
34
|
const Cursor = ({
|
|
22
35
|
className,
|
|
@@ -25,20 +38,46 @@ const Cursor = ({
|
|
|
25
38
|
style,
|
|
26
39
|
...props
|
|
27
40
|
}) => {
|
|
28
|
-
const
|
|
41
|
+
const follower = React.useRef(null);
|
|
42
|
+
const visible = usePointerFollower(follower, style?.transform === void 0);
|
|
43
|
+
const setReferences = React.useCallback(
|
|
44
|
+
(node) => {
|
|
45
|
+
follower.current = node;
|
|
46
|
+
if (typeof ref === "function") {
|
|
47
|
+
const cleanup = ref(node);
|
|
48
|
+
return () => {
|
|
49
|
+
follower.current = null;
|
|
50
|
+
if (typeof cleanup === "function") {
|
|
51
|
+
cleanup();
|
|
52
|
+
} else {
|
|
53
|
+
ref(null);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
if (ref) {
|
|
58
|
+
ref.current = node;
|
|
59
|
+
}
|
|
60
|
+
return () => {
|
|
61
|
+
follower.current = null;
|
|
62
|
+
if (ref) {
|
|
63
|
+
ref.current = null;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
[ref]
|
|
68
|
+
);
|
|
29
69
|
return /* @__PURE__ */ jsx(
|
|
30
70
|
"div",
|
|
31
71
|
{
|
|
32
72
|
"aria-hidden": "true",
|
|
33
73
|
className: cn(
|
|
34
74
|
"pointer-events-none fixed left-0 top-0 z-50 -translate-x-1/2 -translate-y-1/2 rounded-full border border-foreground bg-foreground/20 backdrop-invert transition-transform duration-100 ease-out motion-reduce:transition-none",
|
|
35
|
-
|
|
75
|
+
visible ? "opacity-100" : "opacity-0",
|
|
36
76
|
className
|
|
37
77
|
),
|
|
38
|
-
ref,
|
|
78
|
+
ref: setReferences,
|
|
39
79
|
style: {
|
|
40
80
|
height: `${size}px`,
|
|
41
|
-
transform: point ? `translate(${point.x}px, ${point.y}px) translate(-50%, -50%)` : void 0,
|
|
42
81
|
width: `${size}px`,
|
|
43
82
|
...style
|
|
44
83
|
},
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import { cn } from "../../../lib/utils.js";
|
|
5
|
-
const
|
|
5
|
+
const DockMagnifierContext = React.createContext(null);
|
|
6
6
|
function assignRef(ref, node) {
|
|
7
7
|
if (typeof ref === "function") {
|
|
8
8
|
ref(node);
|
|
@@ -35,14 +35,74 @@ function magnify(distance) {
|
|
|
35
35
|
const clamped = Math.min(Math.abs(distance), range);
|
|
36
36
|
return 1 + 0.5 * (1 - clamped / range);
|
|
37
37
|
}
|
|
38
|
+
function iconScale(icon, pointerX) {
|
|
39
|
+
if (pointerX === null) {
|
|
40
|
+
return 1;
|
|
41
|
+
}
|
|
42
|
+
const bounds = icon.getBoundingClientRect();
|
|
43
|
+
return magnify(pointerX - (bounds.left + bounds.width / 2));
|
|
44
|
+
}
|
|
45
|
+
function useDockMagnifier() {
|
|
46
|
+
const reduced = usePrefersReducedMotion();
|
|
47
|
+
const [icons] = React.useState(() => /* @__PURE__ */ new Set());
|
|
48
|
+
const pointerX = React.useRef(null);
|
|
49
|
+
const reducedReference = React.useRef(reduced);
|
|
50
|
+
const frame = React.useRef(null);
|
|
51
|
+
const scheduleUpdate = React.useCallback(() => {
|
|
52
|
+
if (frame.current !== null) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
frame.current = requestAnimationFrame(() => {
|
|
56
|
+
frame.current = null;
|
|
57
|
+
const x = reducedReference.current ? null : pointerX.current;
|
|
58
|
+
const targets = [...icons];
|
|
59
|
+
const scales = targets.map((icon) => iconScale(icon, x));
|
|
60
|
+
targets.forEach((icon, index) => {
|
|
61
|
+
icon.style.transform = `scale(${scales[index] ?? 1})`;
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
}, [icons]);
|
|
65
|
+
React.useEffect(() => {
|
|
66
|
+
reducedReference.current = reduced;
|
|
67
|
+
scheduleUpdate();
|
|
68
|
+
}, [reduced, scheduleUpdate]);
|
|
69
|
+
React.useEffect(() => {
|
|
70
|
+
return () => {
|
|
71
|
+
if (frame.current !== null) {
|
|
72
|
+
cancelAnimationFrame(frame.current);
|
|
73
|
+
frame.current = null;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}, []);
|
|
77
|
+
const magnifier = React.useMemo(
|
|
78
|
+
() => ({
|
|
79
|
+
register: (icon) => {
|
|
80
|
+
icons.add(icon);
|
|
81
|
+
scheduleUpdate();
|
|
82
|
+
return () => {
|
|
83
|
+
icons.delete(icon);
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}),
|
|
87
|
+
[icons, scheduleUpdate]
|
|
88
|
+
);
|
|
89
|
+
const trackPointer = React.useCallback(
|
|
90
|
+
(nextPointerX) => {
|
|
91
|
+
pointerX.current = nextPointerX;
|
|
92
|
+
scheduleUpdate();
|
|
93
|
+
},
|
|
94
|
+
[scheduleUpdate]
|
|
95
|
+
);
|
|
96
|
+
return { magnifier, trackPointer };
|
|
97
|
+
}
|
|
38
98
|
const Dock = ({
|
|
39
99
|
children,
|
|
40
100
|
className,
|
|
41
101
|
ref,
|
|
42
102
|
...props
|
|
43
103
|
}) => {
|
|
44
|
-
const
|
|
45
|
-
return /* @__PURE__ */ jsx(
|
|
104
|
+
const { magnifier, trackPointer } = useDockMagnifier();
|
|
105
|
+
return /* @__PURE__ */ jsx(DockMagnifierContext.Provider, { value: magnifier, children: /* @__PURE__ */ jsx(
|
|
46
106
|
"div",
|
|
47
107
|
{
|
|
48
108
|
className: cn(
|
|
@@ -50,10 +110,10 @@ const Dock = ({
|
|
|
50
110
|
className
|
|
51
111
|
),
|
|
52
112
|
onPointerLeave: () => {
|
|
53
|
-
|
|
113
|
+
trackPointer(null);
|
|
54
114
|
},
|
|
55
115
|
onPointerMove: (event) => {
|
|
56
|
-
|
|
116
|
+
trackPointer(event.clientX);
|
|
57
117
|
},
|
|
58
118
|
ref,
|
|
59
119
|
...props,
|
|
@@ -62,14 +122,6 @@ const Dock = ({
|
|
|
62
122
|
) });
|
|
63
123
|
};
|
|
64
124
|
Dock.displayName = "Dock";
|
|
65
|
-
function useDockScale(reference, pointerX, reduced) {
|
|
66
|
-
if (reduced || pointerX === null || reference.current === null) {
|
|
67
|
-
return 1;
|
|
68
|
-
}
|
|
69
|
-
const bounds = reference.current.getBoundingClientRect();
|
|
70
|
-
const center = bounds.left + bounds.width / 2;
|
|
71
|
-
return magnify(pointerX - center);
|
|
72
|
-
}
|
|
73
125
|
const DockIcon = ({
|
|
74
126
|
children,
|
|
75
127
|
className,
|
|
@@ -77,10 +129,16 @@ const DockIcon = ({
|
|
|
77
129
|
style,
|
|
78
130
|
...props
|
|
79
131
|
}) => {
|
|
80
|
-
const
|
|
81
|
-
const reduced = usePrefersReducedMotion();
|
|
132
|
+
const magnifier = React.use(DockMagnifierContext);
|
|
82
133
|
const reference = React.useRef(null);
|
|
83
|
-
const
|
|
134
|
+
const hasCustomTransform = style?.transform !== void 0;
|
|
135
|
+
React.useEffect(() => {
|
|
136
|
+
const icon = reference.current;
|
|
137
|
+
if (!magnifier || !icon || hasCustomTransform) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
return magnifier.register(icon);
|
|
141
|
+
}, [hasCustomTransform, magnifier]);
|
|
84
142
|
const setReferences = React.useCallback(
|
|
85
143
|
(node) => {
|
|
86
144
|
reference.current = node;
|
|
@@ -96,7 +154,7 @@ const DockIcon = ({
|
|
|
96
154
|
className
|
|
97
155
|
),
|
|
98
156
|
ref: setReferences,
|
|
99
|
-
style: { transform:
|
|
157
|
+
style: { transform: "scale(1)", ...style },
|
|
100
158
|
...props,
|
|
101
159
|
children
|
|
102
160
|
}
|
|
@@ -20,6 +20,56 @@ function usePrefersReducedMotion() {
|
|
|
20
20
|
}, []);
|
|
21
21
|
return reduced;
|
|
22
22
|
}
|
|
23
|
+
function usePointerTransform({
|
|
24
|
+
compute,
|
|
25
|
+
enabled,
|
|
26
|
+
keepTransform
|
|
27
|
+
}) {
|
|
28
|
+
const element = React.useRef(null);
|
|
29
|
+
const pointer = React.useRef({ x: 0, y: 0 });
|
|
30
|
+
const frame = React.useRef(null);
|
|
31
|
+
React.useEffect(() => {
|
|
32
|
+
return () => {
|
|
33
|
+
if (frame.current !== null) {
|
|
34
|
+
cancelAnimationFrame(frame.current);
|
|
35
|
+
frame.current = null;
|
|
36
|
+
}
|
|
37
|
+
element.current = null;
|
|
38
|
+
};
|
|
39
|
+
}, []);
|
|
40
|
+
const writeTransform = (target, transform) => {
|
|
41
|
+
if (target && !keepTransform) {
|
|
42
|
+
target.style.transform = transform;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const applyFrame = () => {
|
|
46
|
+
frame.current = null;
|
|
47
|
+
const target = element.current;
|
|
48
|
+
if (target) {
|
|
49
|
+
writeTransform(
|
|
50
|
+
target,
|
|
51
|
+
compute(pointer.current, target.getBoundingClientRect())
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
return {
|
|
56
|
+
handlePointerLeave: (event) => {
|
|
57
|
+
if (frame.current !== null) {
|
|
58
|
+
cancelAnimationFrame(frame.current);
|
|
59
|
+
frame.current = null;
|
|
60
|
+
}
|
|
61
|
+
writeTransform(event.currentTarget, "");
|
|
62
|
+
},
|
|
63
|
+
handlePointerMove: (event) => {
|
|
64
|
+
if (!enabled) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
element.current = event.currentTarget;
|
|
68
|
+
pointer.current = { x: event.clientX, y: event.clientY };
|
|
69
|
+
frame.current ?? (frame.current = requestAnimationFrame(applyFrame));
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
23
73
|
const Magnetic = ({
|
|
24
74
|
children,
|
|
25
75
|
className,
|
|
@@ -29,16 +79,15 @@ const Magnetic = ({
|
|
|
29
79
|
...props
|
|
30
80
|
}) => {
|
|
31
81
|
const reduced = usePrefersReducedMotion();
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
};
|
|
82
|
+
const { handlePointerLeave, handlePointerMove } = usePointerTransform({
|
|
83
|
+
compute: (pointer, bounds) => {
|
|
84
|
+
const offsetX = (pointer.x - bounds.left - bounds.width / 2) * strength;
|
|
85
|
+
const offsetY = (pointer.y - bounds.top - bounds.height / 2) * strength;
|
|
86
|
+
return `translate(${offsetX}px, ${offsetY}px)`;
|
|
87
|
+
},
|
|
88
|
+
enabled: !reduced,
|
|
89
|
+
keepTransform: style?.transform !== void 0
|
|
90
|
+
});
|
|
42
91
|
return /* @__PURE__ */ jsx(
|
|
43
92
|
"div",
|
|
44
93
|
{
|
|
@@ -46,12 +95,10 @@ const Magnetic = ({
|
|
|
46
95
|
"transition-transform duration-200 ease-out will-change-transform",
|
|
47
96
|
className
|
|
48
97
|
),
|
|
49
|
-
onPointerLeave:
|
|
50
|
-
setTransform(void 0);
|
|
51
|
-
},
|
|
98
|
+
onPointerLeave: handlePointerLeave,
|
|
52
99
|
onPointerMove: handlePointerMove,
|
|
53
100
|
ref,
|
|
54
|
-
style
|
|
101
|
+
style,
|
|
55
102
|
...props,
|
|
56
103
|
children
|
|
57
104
|
}
|
|
@@ -20,6 +20,56 @@ function usePrefersReducedMotion() {
|
|
|
20
20
|
}, []);
|
|
21
21
|
return reduced;
|
|
22
22
|
}
|
|
23
|
+
function usePointerTransform({
|
|
24
|
+
compute,
|
|
25
|
+
enabled,
|
|
26
|
+
keepTransform
|
|
27
|
+
}) {
|
|
28
|
+
const element = React.useRef(null);
|
|
29
|
+
const pointer = React.useRef({ x: 0, y: 0 });
|
|
30
|
+
const frame = React.useRef(null);
|
|
31
|
+
React.useEffect(() => {
|
|
32
|
+
return () => {
|
|
33
|
+
if (frame.current !== null) {
|
|
34
|
+
cancelAnimationFrame(frame.current);
|
|
35
|
+
frame.current = null;
|
|
36
|
+
}
|
|
37
|
+
element.current = null;
|
|
38
|
+
};
|
|
39
|
+
}, []);
|
|
40
|
+
const writeTransform = (target, transform) => {
|
|
41
|
+
if (target && !keepTransform) {
|
|
42
|
+
target.style.transform = transform;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const applyFrame = () => {
|
|
46
|
+
frame.current = null;
|
|
47
|
+
const target = element.current;
|
|
48
|
+
if (target) {
|
|
49
|
+
writeTransform(
|
|
50
|
+
target,
|
|
51
|
+
compute(pointer.current, target.getBoundingClientRect())
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
return {
|
|
56
|
+
handlePointerLeave: (event) => {
|
|
57
|
+
if (frame.current !== null) {
|
|
58
|
+
cancelAnimationFrame(frame.current);
|
|
59
|
+
frame.current = null;
|
|
60
|
+
}
|
|
61
|
+
writeTransform(event.currentTarget, "");
|
|
62
|
+
},
|
|
63
|
+
handlePointerMove: (event) => {
|
|
64
|
+
if (!enabled) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
element.current = event.currentTarget;
|
|
68
|
+
pointer.current = { x: event.clientX, y: event.clientY };
|
|
69
|
+
frame.current ?? (frame.current = requestAnimationFrame(applyFrame));
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
23
73
|
const MagneticButton = ({
|
|
24
74
|
children,
|
|
25
75
|
className,
|
|
@@ -29,16 +79,15 @@ const MagneticButton = ({
|
|
|
29
79
|
...props
|
|
30
80
|
}) => {
|
|
31
81
|
const reduced = usePrefersReducedMotion();
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
};
|
|
82
|
+
const { handlePointerLeave, handlePointerMove } = usePointerTransform({
|
|
83
|
+
compute: (pointer, bounds) => {
|
|
84
|
+
const offsetX = (pointer.x - bounds.left - bounds.width / 2) * strength;
|
|
85
|
+
const offsetY = (pointer.y - bounds.top - bounds.height / 2) * strength;
|
|
86
|
+
return `translate(${offsetX}px, ${offsetY}px)`;
|
|
87
|
+
},
|
|
88
|
+
enabled: !reduced,
|
|
89
|
+
keepTransform: style?.transform !== void 0
|
|
90
|
+
});
|
|
42
91
|
return /* @__PURE__ */ jsx(
|
|
43
92
|
"button",
|
|
44
93
|
{
|
|
@@ -46,12 +95,10 @@ const MagneticButton = ({
|
|
|
46
95
|
"transition-transform duration-200 ease-out will-change-transform",
|
|
47
96
|
className
|
|
48
97
|
),
|
|
49
|
-
onPointerLeave:
|
|
50
|
-
setTransform(void 0);
|
|
51
|
-
},
|
|
98
|
+
onPointerLeave: handlePointerLeave,
|
|
52
99
|
onPointerMove: handlePointerMove,
|
|
53
100
|
ref,
|
|
54
|
-
style
|
|
101
|
+
style,
|
|
55
102
|
type: "button",
|
|
56
103
|
...props,
|
|
57
104
|
children
|
|
@@ -10,11 +10,17 @@ function withCumulativeTotal(levels) {
|
|
|
10
10
|
};
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
|
+
const numberFormatters = /* @__PURE__ */ new Map();
|
|
13
14
|
function formatNumber(value, precision = 2) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
let formatter = numberFormatters.get(precision);
|
|
16
|
+
if (!formatter) {
|
|
17
|
+
formatter = new Intl.NumberFormat(void 0, {
|
|
18
|
+
maximumFractionDigits: precision,
|
|
19
|
+
minimumFractionDigits: precision
|
|
20
|
+
});
|
|
21
|
+
numberFormatters.set(precision, formatter);
|
|
22
|
+
}
|
|
23
|
+
return formatter.format(value);
|
|
18
24
|
}
|
|
19
25
|
function BookSide({
|
|
20
26
|
accent,
|
|
@@ -12,6 +12,32 @@ function buildPath(data, count, margin) {
|
|
|
12
12
|
""
|
|
13
13
|
);
|
|
14
14
|
}
|
|
15
|
+
const ENCODING_CACHE_LIMIT = 32;
|
|
16
|
+
const encodingCache = /* @__PURE__ */ new Map();
|
|
17
|
+
function encodeQrCode(value, level, margin) {
|
|
18
|
+
const cacheable = typeof window !== "undefined";
|
|
19
|
+
const key = `${level}|${margin}|${value}`;
|
|
20
|
+
const cached = cacheable ? encodingCache.get(key) : void 0;
|
|
21
|
+
if (cached) {
|
|
22
|
+
return cached;
|
|
23
|
+
}
|
|
24
|
+
const { modules } = create(value, { errorCorrectionLevel: level });
|
|
25
|
+
const encoding = {
|
|
26
|
+
count: modules.size,
|
|
27
|
+
path: buildPath(modules.data, modules.size, margin)
|
|
28
|
+
};
|
|
29
|
+
if (!cacheable) {
|
|
30
|
+
return encoding;
|
|
31
|
+
}
|
|
32
|
+
encodingCache.set(key, encoding);
|
|
33
|
+
if (encodingCache.size > ENCODING_CACHE_LIMIT) {
|
|
34
|
+
const oldest = encodingCache.keys().next().value;
|
|
35
|
+
if (oldest !== void 0) {
|
|
36
|
+
encodingCache.delete(oldest);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return encoding;
|
|
40
|
+
}
|
|
15
41
|
const QrCode = ({
|
|
16
42
|
className,
|
|
17
43
|
level = "M",
|
|
@@ -22,10 +48,8 @@ const QrCode = ({
|
|
|
22
48
|
value,
|
|
23
49
|
...props
|
|
24
50
|
}) => {
|
|
25
|
-
const
|
|
26
|
-
const count = modules?.size ?? 0;
|
|
51
|
+
const { count, path } = value ? encodeQrCode(value, level, margin) : { count: 0, path: "" };
|
|
27
52
|
const dimension = count + margin * 2;
|
|
28
|
-
const path = modules ? buildPath(modules.data, count, margin) : "";
|
|
29
53
|
return /* @__PURE__ */ jsx(
|
|
30
54
|
"svg",
|
|
31
55
|
{
|
|
@@ -76,11 +76,13 @@ const Reasoning = ({
|
|
|
76
76
|
const [isOpen, setIsOpen] = useState(isStreaming);
|
|
77
77
|
const contentId = useId();
|
|
78
78
|
useEffect(() => {
|
|
79
|
-
if (isStreaming)
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
79
|
+
if (!isStreaming) return;
|
|
80
|
+
const frame = requestAnimationFrame(() => {
|
|
81
|
+
setIsOpen(true);
|
|
82
|
+
});
|
|
83
|
+
return () => {
|
|
84
|
+
cancelAnimationFrame(frame);
|
|
85
|
+
};
|
|
84
86
|
}, [isStreaming]);
|
|
85
87
|
const handleToggle = useCallback(() => {
|
|
86
88
|
setIsOpen((previous) => {
|
|
@@ -18,13 +18,21 @@ const ScrollProgress = ({
|
|
|
18
18
|
}) => {
|
|
19
19
|
const [progress, setProgress] = React.useState(0);
|
|
20
20
|
React.useEffect(() => {
|
|
21
|
-
|
|
21
|
+
let frame = null;
|
|
22
|
+
const update = () => {
|
|
23
|
+
frame = null;
|
|
22
24
|
setProgress(computeProgress());
|
|
23
25
|
};
|
|
24
|
-
onScroll()
|
|
26
|
+
const onScroll = () => {
|
|
27
|
+
frame ?? (frame = requestAnimationFrame(update));
|
|
28
|
+
};
|
|
29
|
+
update();
|
|
25
30
|
window.addEventListener("scroll", onScroll, { passive: true });
|
|
26
31
|
return () => {
|
|
27
32
|
window.removeEventListener("scroll", onScroll);
|
|
33
|
+
if (frame !== null) {
|
|
34
|
+
cancelAnimationFrame(frame);
|
|
35
|
+
}
|
|
28
36
|
};
|
|
29
37
|
}, []);
|
|
30
38
|
return /* @__PURE__ */ jsx(
|
|
@@ -8,16 +8,42 @@ const SpotlightCard = ({
|
|
|
8
8
|
ref,
|
|
9
9
|
...props
|
|
10
10
|
}) => {
|
|
11
|
-
const
|
|
11
|
+
const spotlight = React.useRef(null);
|
|
12
|
+
const pointer = React.useRef({ x: 0, y: 0 });
|
|
13
|
+
const frame = React.useRef(null);
|
|
14
|
+
React.useEffect(() => {
|
|
15
|
+
return () => {
|
|
16
|
+
if (frame.current !== null) {
|
|
17
|
+
cancelAnimationFrame(frame.current);
|
|
18
|
+
frame.current = null;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}, []);
|
|
22
|
+
const moveSpotlight = () => {
|
|
23
|
+
frame.current = null;
|
|
24
|
+
const node = spotlight.current;
|
|
25
|
+
if (!node?.parentElement) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const bounds = node.parentElement.getBoundingClientRect();
|
|
29
|
+
const x = pointer.current.x - bounds.left;
|
|
30
|
+
const y = pointer.current.y - bounds.top;
|
|
31
|
+
node.style.background = `radial-gradient(180px circle at ${x}px ${y}px, oklch(var(--foreground) / 0.10), transparent 65%)`;
|
|
32
|
+
node.style.opacity = "1";
|
|
33
|
+
};
|
|
12
34
|
const handlePointerMove = (event) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
x: event.clientX - bounds.left,
|
|
16
|
-
y: event.clientY - bounds.top
|
|
17
|
-
});
|
|
35
|
+
pointer.current = { x: event.clientX, y: event.clientY };
|
|
36
|
+
frame.current ?? (frame.current = requestAnimationFrame(moveSpotlight));
|
|
18
37
|
};
|
|
19
38
|
const handlePointerLeave = () => {
|
|
20
|
-
|
|
39
|
+
if (frame.current !== null) {
|
|
40
|
+
cancelAnimationFrame(frame.current);
|
|
41
|
+
frame.current = null;
|
|
42
|
+
}
|
|
43
|
+
if (spotlight.current) {
|
|
44
|
+
spotlight.current.style.background = "";
|
|
45
|
+
spotlight.current.style.opacity = "0";
|
|
46
|
+
}
|
|
21
47
|
};
|
|
22
48
|
return /* @__PURE__ */ jsxs(
|
|
23
49
|
"div",
|
|
@@ -36,10 +62,8 @@ const SpotlightCard = ({
|
|
|
36
62
|
{
|
|
37
63
|
"aria-hidden": "true",
|
|
38
64
|
className: "pointer-events-none absolute inset-0 transition-opacity duration-300",
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
opacity: point ? 1 : 0
|
|
42
|
-
}
|
|
65
|
+
ref: spotlight,
|
|
66
|
+
style: { opacity: 0 }
|
|
43
67
|
}
|
|
44
68
|
),
|
|
45
69
|
/* @__PURE__ */ jsx("div", { className: "relative z-10", children })
|
|
@@ -31,15 +31,23 @@ function useScrollProgress(nodeRef, enabled) {
|
|
|
31
31
|
setProgress(1);
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
let frame = null;
|
|
35
|
+
const update = () => {
|
|
36
|
+
frame = null;
|
|
35
37
|
const bounds = node.getBoundingClientRect();
|
|
36
38
|
const span = bounds.height + window.innerHeight;
|
|
37
39
|
setProgress(clamp((window.innerHeight - bounds.top) / span));
|
|
38
40
|
};
|
|
39
|
-
onScroll()
|
|
41
|
+
const onScroll = () => {
|
|
42
|
+
frame ?? (frame = requestAnimationFrame(update));
|
|
43
|
+
};
|
|
44
|
+
update();
|
|
40
45
|
window.addEventListener("scroll", onScroll, { passive: true });
|
|
41
46
|
return () => {
|
|
42
47
|
window.removeEventListener("scroll", onScroll);
|
|
48
|
+
if (frame !== null) {
|
|
49
|
+
cancelAnimationFrame(frame);
|
|
50
|
+
}
|
|
43
51
|
};
|
|
44
52
|
}, [enabled, nodeRef]);
|
|
45
53
|
return progress;
|
|
@@ -11,11 +11,13 @@ function ThinkingBlock({
|
|
|
11
11
|
const [isExpanded, setIsExpanded] = useState(() => isStreaming);
|
|
12
12
|
const contentId = useId();
|
|
13
13
|
useEffect(() => {
|
|
14
|
-
if (isStreaming)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
if (!isStreaming) return;
|
|
15
|
+
const frame = requestAnimationFrame(() => {
|
|
16
|
+
setIsExpanded(true);
|
|
17
|
+
});
|
|
18
|
+
return () => {
|
|
19
|
+
cancelAnimationFrame(frame);
|
|
20
|
+
};
|
|
19
21
|
}, [isStreaming]);
|
|
20
22
|
const toggleExpanded = useCallback(() => {
|
|
21
23
|
setIsExpanded((previous) => !previous);
|