@egen-civitas/esm-styleguide 1.2.0 → 1.4.0
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/CHANGELOG.md +16 -0
- package/dist/assistant/assistant-modes.d.ts +29 -0
- package/dist/assistant/assistant-modes.d.ts.map +1 -0
- package/dist/assistant/assistant-modes.js +143 -0
- package/dist/assistant/index.d.ts +9 -0
- package/dist/assistant/index.d.ts.map +1 -0
- package/dist/assistant/index.js +7 -0
- package/dist/assistant/live-orb.component.d.ts +63 -0
- package/dist/assistant/live-orb.component.d.ts.map +1 -0
- package/dist/assistant/live-orb.component.js +485 -0
- package/dist/assistant/prompt-input.component.d.ts +19 -0
- package/dist/assistant/prompt-input.component.d.ts.map +1 -0
- package/dist/assistant/prompt-input.component.js +1021 -0
- package/dist/assistant/recursive-erosion/recursive-erosion-background.component.d.ts +19 -0
- package/dist/assistant/recursive-erosion/recursive-erosion-background.component.d.ts.map +1 -0
- package/dist/assistant/recursive-erosion/recursive-erosion-background.component.js +127 -0
- package/dist/assistant/recursive-erosion/recursive-erosion-source.d.ts +2 -0
- package/dist/assistant/recursive-erosion/recursive-erosion-source.d.ts.map +1 -0
- package/dist/assistant/recursive-erosion/recursive-erosion-source.js +340 -0
- package/dist/assistant/spline-scene.component.d.ts +9 -0
- package/dist/assistant/spline-scene.component.d.ts.map +1 -0
- package/dist/assistant/spline-scene.component.js +51 -0
- package/dist/assistant/water-glass-modal.component.d.ts +26 -0
- package/dist/assistant/water-glass-modal.component.d.ts.map +1 -0
- package/dist/assistant/water-glass-modal.component.js +46 -0
- package/dist/assistant/xbox-audio.d.ts +88 -0
- package/dist/assistant/xbox-audio.d.ts.map +1 -0
- package/dist/assistant/xbox-audio.js +756 -0
- package/dist/components/_general.scss +52 -15
- package/dist/components/_panel-overrides.scss +5 -7
- package/dist/internal.d.ts +1 -0
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +1 -0
- package/dist/public.d.ts +1 -0
- package/dist/public.d.ts.map +1 -1
- package/dist/public.js +1 -0
- package/package.json +3 -1
|
@@ -0,0 +1,1021 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { useRef, useState, useEffect, useCallback } from "react";
|
|
5
|
+
import { cn } from "../page-background/page-background.utils.js";
|
|
6
|
+
// ----------------------------------------------------------------------
|
|
7
|
+
// Transition Physics
|
|
8
|
+
// ----------------------------------------------------------------------
|
|
9
|
+
const SPRING_TRANSITION = "max-width 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), height 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275)";
|
|
10
|
+
const SMOOTH_HEIGHT_TRANSITION = "max-width 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), height 0.15s ease-out";
|
|
11
|
+
// ----------------------------------------------------------------------
|
|
12
|
+
// Sub-components
|
|
13
|
+
// ----------------------------------------------------------------------
|
|
14
|
+
function MorphingText({ text }) {
|
|
15
|
+
const [width, setWidth] = useState("auto");
|
|
16
|
+
const spanRef = useRef(null);
|
|
17
|
+
useEffect(()=>{
|
|
18
|
+
if (spanRef.current) {
|
|
19
|
+
setWidth(spanRef.current.offsetWidth);
|
|
20
|
+
}
|
|
21
|
+
}, [
|
|
22
|
+
text
|
|
23
|
+
]);
|
|
24
|
+
return /*#__PURE__*/ _jsxs("span", {
|
|
25
|
+
className: "relative inline-flex items-center justify-center overflow-hidden transition-all duration-300 ease-[cubic-bezier(0.175,0.885,0.32,1.275)]",
|
|
26
|
+
style: {
|
|
27
|
+
width
|
|
28
|
+
},
|
|
29
|
+
children: [
|
|
30
|
+
/*#__PURE__*/ _jsx("span", {
|
|
31
|
+
ref: spanRef,
|
|
32
|
+
className: "invisible whitespace-nowrap px-1",
|
|
33
|
+
children: text
|
|
34
|
+
}),
|
|
35
|
+
/*#__PURE__*/ _jsx("span", {
|
|
36
|
+
className: "absolute inset-0 flex items-center justify-center whitespace-nowrap animate-in fade-in zoom-in-95 duration-300",
|
|
37
|
+
children: text
|
|
38
|
+
}, text)
|
|
39
|
+
]
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
function ModelIcon({ model, className }) {
|
|
43
|
+
const icons = {
|
|
44
|
+
"Composer 2.5": "https://cdn.21st.dev/assets/mirror/7d/7dc00bc09f225fcda46cbc9c6b669c69c025a231877d6c17baa6a003f04f02b2.svg",
|
|
45
|
+
"Gemini 3.5 Flash": "https://cdn.21st.dev/assets/mirror/cd/cda2df6631d5fa227de3fa04ed78cf354f910ba92a9f086e7455655c10ad9d09.svg",
|
|
46
|
+
"GPT 5.5": "https://cdn.21st.dev/assets/mirror/b9/b93fa7942be639a1dae60194ff12141145d7d9fd59581582d6ff23335755f19c.svg",
|
|
47
|
+
"Opus 4.8": "https://cdn.21st.dev/assets/mirror/5d/5de1221c77cc91e748066fd642ad0eee1c1fa65328814f5178166f901e599709.svg",
|
|
48
|
+
"GLM 5.2": "https://cdn.21st.dev/assets/mirror/b2/b2a6c0ff63efd8a555edf8a174ea6fcfeca120ac1595a2d461ca11d3ae89276c.svg"
|
|
49
|
+
};
|
|
50
|
+
const filters = {
|
|
51
|
+
"GPT 5.5": "dark:invert"
|
|
52
|
+
};
|
|
53
|
+
return /*#__PURE__*/ _jsx("img", {
|
|
54
|
+
src: icons[model] || icons["GPT 5.5"],
|
|
55
|
+
alt: model,
|
|
56
|
+
className: cn("object-contain", filters[model], className)
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function ArrowUpIcon() {
|
|
60
|
+
return /*#__PURE__*/ _jsx("svg", {
|
|
61
|
+
width: "12",
|
|
62
|
+
height: "12",
|
|
63
|
+
viewBox: "0 0 14 14",
|
|
64
|
+
fill: "none",
|
|
65
|
+
"aria-hidden": "true",
|
|
66
|
+
children: /*#__PURE__*/ _jsx("path", {
|
|
67
|
+
d: "M7 12V2M7 2L2.5 6.5M7 2L11.5 6.5",
|
|
68
|
+
stroke: "currentColor",
|
|
69
|
+
strokeWidth: "1.75",
|
|
70
|
+
strokeLinecap: "round",
|
|
71
|
+
strokeLinejoin: "round"
|
|
72
|
+
})
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
function MicIcon() {
|
|
76
|
+
return /*#__PURE__*/ _jsxs("svg", {
|
|
77
|
+
width: "13",
|
|
78
|
+
height: "13",
|
|
79
|
+
viewBox: "0 0 14 14",
|
|
80
|
+
fill: "none",
|
|
81
|
+
"aria-hidden": "true",
|
|
82
|
+
children: [
|
|
83
|
+
/*#__PURE__*/ _jsx("rect", {
|
|
84
|
+
x: "5",
|
|
85
|
+
y: "1",
|
|
86
|
+
width: "4",
|
|
87
|
+
height: "7",
|
|
88
|
+
rx: "2",
|
|
89
|
+
stroke: "currentColor",
|
|
90
|
+
strokeWidth: "1.5"
|
|
91
|
+
}),
|
|
92
|
+
/*#__PURE__*/ _jsx("path", {
|
|
93
|
+
d: "M2.75 6.5V7a4.25 4.25 0 0 0 8.5 0v-.5M7 11.25V13",
|
|
94
|
+
stroke: "currentColor",
|
|
95
|
+
strokeWidth: "1.5",
|
|
96
|
+
strokeLinecap: "round"
|
|
97
|
+
})
|
|
98
|
+
]
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
function StopIcon() {
|
|
102
|
+
return /*#__PURE__*/ _jsx("svg", {
|
|
103
|
+
width: "14",
|
|
104
|
+
height: "14",
|
|
105
|
+
viewBox: "0 0 14 14",
|
|
106
|
+
fill: "none",
|
|
107
|
+
"aria-hidden": "true",
|
|
108
|
+
children: /*#__PURE__*/ _jsx("rect", {
|
|
109
|
+
x: "3.5",
|
|
110
|
+
y: "3.5",
|
|
111
|
+
width: "7",
|
|
112
|
+
height: "7",
|
|
113
|
+
rx: "1.5",
|
|
114
|
+
fill: "currentColor"
|
|
115
|
+
})
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
function PlusIcon() {
|
|
119
|
+
return /*#__PURE__*/ _jsx("svg", {
|
|
120
|
+
width: "14",
|
|
121
|
+
height: "14",
|
|
122
|
+
viewBox: "0 0 14 14",
|
|
123
|
+
fill: "none",
|
|
124
|
+
"aria-hidden": "true",
|
|
125
|
+
children: /*#__PURE__*/ _jsx("path", {
|
|
126
|
+
d: "M7 2.5V11.5M2.5 7H11.5",
|
|
127
|
+
stroke: "currentColor",
|
|
128
|
+
strokeWidth: "1.5",
|
|
129
|
+
strokeLinecap: "round"
|
|
130
|
+
})
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
function CloseIcon() {
|
|
134
|
+
return /*#__PURE__*/ _jsx("svg", {
|
|
135
|
+
width: "9",
|
|
136
|
+
height: "9",
|
|
137
|
+
viewBox: "0 0 14 14",
|
|
138
|
+
fill: "none",
|
|
139
|
+
"aria-hidden": "true",
|
|
140
|
+
children: /*#__PURE__*/ _jsx("path", {
|
|
141
|
+
d: "M2.5 2.5L11.5 11.5M11.5 2.5L2.5 11.5",
|
|
142
|
+
stroke: "currentColor",
|
|
143
|
+
strokeWidth: "2",
|
|
144
|
+
strokeLinecap: "round"
|
|
145
|
+
})
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
function DynamicBarsIcon({ level }) {
|
|
149
|
+
const isMediumOrHigh = level === "Medium" || level === "Max Effort";
|
|
150
|
+
const isHigh = level === "Max Effort";
|
|
151
|
+
return /*#__PURE__*/ _jsxs("svg", {
|
|
152
|
+
width: "14",
|
|
153
|
+
height: "14",
|
|
154
|
+
viewBox: "0 0 14 14",
|
|
155
|
+
fill: "none",
|
|
156
|
+
"aria-hidden": "true",
|
|
157
|
+
children: [
|
|
158
|
+
/*#__PURE__*/ _jsx("rect", {
|
|
159
|
+
x: "1.5",
|
|
160
|
+
y: "8",
|
|
161
|
+
width: "2.5",
|
|
162
|
+
height: "4.5",
|
|
163
|
+
rx: "1",
|
|
164
|
+
fill: "currentColor",
|
|
165
|
+
className: "transition-opacity duration-300",
|
|
166
|
+
opacity: 1
|
|
167
|
+
}),
|
|
168
|
+
/*#__PURE__*/ _jsx("rect", {
|
|
169
|
+
x: "5.75",
|
|
170
|
+
y: "5",
|
|
171
|
+
width: "2.5",
|
|
172
|
+
height: "7.5",
|
|
173
|
+
rx: "1",
|
|
174
|
+
fill: "currentColor",
|
|
175
|
+
className: "transition-opacity duration-300",
|
|
176
|
+
opacity: isMediumOrHigh ? 1 : 0.3
|
|
177
|
+
}),
|
|
178
|
+
/*#__PURE__*/ _jsx("rect", {
|
|
179
|
+
x: "10",
|
|
180
|
+
y: "2",
|
|
181
|
+
width: "2.5",
|
|
182
|
+
height: "10.5",
|
|
183
|
+
rx: "1",
|
|
184
|
+
fill: "currentColor",
|
|
185
|
+
className: "transition-opacity duration-300",
|
|
186
|
+
opacity: isHigh ? 1 : 0.3
|
|
187
|
+
})
|
|
188
|
+
]
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
// ----------------------------------------------------------------------
|
|
192
|
+
// Attachment Thumbnail
|
|
193
|
+
// ----------------------------------------------------------------------
|
|
194
|
+
function AttachmentThumb({ attachment, index, onRemove, onOpen, registerRef }) {
|
|
195
|
+
const [isHovered, setIsHovered] = useState(false);
|
|
196
|
+
const btnRef = useRef(null);
|
|
197
|
+
return /*#__PURE__*/ _jsxs("button", {
|
|
198
|
+
ref: (el)=>{
|
|
199
|
+
btnRef.current = el;
|
|
200
|
+
registerRef(attachment.id, el);
|
|
201
|
+
},
|
|
202
|
+
type: "button",
|
|
203
|
+
onMouseDown: (e)=>e.preventDefault(),
|
|
204
|
+
onMouseEnter: ()=>setIsHovered(true),
|
|
205
|
+
onMouseLeave: ()=>setIsHovered(false),
|
|
206
|
+
onClick: (e)=>{
|
|
207
|
+
e.stopPropagation();
|
|
208
|
+
if (btnRef.current) {
|
|
209
|
+
onOpen(attachment, btnRef.current.getBoundingClientRect());
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
style: {
|
|
213
|
+
animationDelay: `${index * 35}ms`,
|
|
214
|
+
animationFillMode: "backwards"
|
|
215
|
+
},
|
|
216
|
+
className: cn("group relative size-12 shrink-0 overflow-hidden rounded-xl border border-border bg-muted outline-none", "transition-transform duration-200 ease-[cubic-bezier(0.175,0.885,0.32,1.275)] hover:scale-[1.04] active:scale-[0.96]", "animate-in fade-in slide-in-from-top-3 zoom-in-90 duration-400"),
|
|
217
|
+
"aria-label": `Open preview of ${attachment.name}`,
|
|
218
|
+
children: [
|
|
219
|
+
/*#__PURE__*/ _jsx("img", {
|
|
220
|
+
src: attachment.url,
|
|
221
|
+
alt: attachment.name,
|
|
222
|
+
className: "size-full object-cover",
|
|
223
|
+
draggable: false
|
|
224
|
+
}),
|
|
225
|
+
/*#__PURE__*/ _jsx("span", {
|
|
226
|
+
className: cn("absolute inset-0 flex items-start justify-end bg-black/0 transition-colors duration-200", isHovered && "bg-black/25"),
|
|
227
|
+
children: /*#__PURE__*/ _jsx("span", {
|
|
228
|
+
role: "button",
|
|
229
|
+
tabIndex: -1,
|
|
230
|
+
onMouseDown: (e)=>{
|
|
231
|
+
e.preventDefault();
|
|
232
|
+
e.stopPropagation();
|
|
233
|
+
},
|
|
234
|
+
onClick: (e)=>{
|
|
235
|
+
e.stopPropagation();
|
|
236
|
+
onRemove(attachment.id);
|
|
237
|
+
},
|
|
238
|
+
className: cn("m-1 flex size-4 items-center justify-center rounded-full bg-background/90 text-foreground/70 shadow-sm transition-all duration-200 ease-[cubic-bezier(0.175,0.885,0.32,1.275)] hover:bg-background hover:text-foreground hover:scale-110", isHovered ? "opacity-100 scale-100" : "opacity-0 scale-50 pointer-events-none"),
|
|
239
|
+
"aria-label": `Remove ${attachment.name}`,
|
|
240
|
+
children: /*#__PURE__*/ _jsx(CloseIcon, {})
|
|
241
|
+
})
|
|
242
|
+
})
|
|
243
|
+
]
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
// ----------------------------------------------------------------------
|
|
247
|
+
// Shared-Element Gallery Modal
|
|
248
|
+
// ----------------------------------------------------------------------
|
|
249
|
+
function AttachmentGalleryModal({ attachment, originRect, onClose }) {
|
|
250
|
+
const [phase, setPhase] = useState("opening");
|
|
251
|
+
const [targetRect, setTargetRect] = useState(null);
|
|
252
|
+
const imgRef = useRef(null);
|
|
253
|
+
useEffect(()=>{
|
|
254
|
+
const maxW = Math.min(window.innerWidth * 0.86, 560);
|
|
255
|
+
const maxH = Math.min(window.innerHeight * 0.78, 720);
|
|
256
|
+
const naturalW = attachment.width || 800;
|
|
257
|
+
const naturalH = attachment.height || 600;
|
|
258
|
+
const scale = Math.min(maxW / naturalW, maxH / naturalH, 1.6);
|
|
259
|
+
const width = naturalW * scale;
|
|
260
|
+
const height = naturalH * scale;
|
|
261
|
+
setTargetRect({
|
|
262
|
+
top: (window.innerHeight - height) / 2,
|
|
263
|
+
left: (window.innerWidth - width) / 2,
|
|
264
|
+
width,
|
|
265
|
+
height,
|
|
266
|
+
radius: 20
|
|
267
|
+
});
|
|
268
|
+
const raf = requestAnimationFrame(()=>setPhase("open"));
|
|
269
|
+
return ()=>cancelAnimationFrame(raf);
|
|
270
|
+
}, [
|
|
271
|
+
attachment
|
|
272
|
+
]);
|
|
273
|
+
const handleClose = useCallback(()=>setPhase("closing"), []);
|
|
274
|
+
useEffect(()=>{
|
|
275
|
+
const onKey = (e)=>{
|
|
276
|
+
if (e.key === "Escape") handleClose();
|
|
277
|
+
};
|
|
278
|
+
document.addEventListener("keydown", onKey);
|
|
279
|
+
return ()=>document.removeEventListener("keydown", onKey);
|
|
280
|
+
}, [
|
|
281
|
+
handleClose
|
|
282
|
+
]);
|
|
283
|
+
const isOpen = phase === "open";
|
|
284
|
+
const isClosing = phase === "closing";
|
|
285
|
+
const geometry = isOpen && targetRect ? targetRect : {
|
|
286
|
+
top: originRect.top,
|
|
287
|
+
left: originRect.left,
|
|
288
|
+
width: originRect.width,
|
|
289
|
+
height: originRect.height,
|
|
290
|
+
radius: 12
|
|
291
|
+
};
|
|
292
|
+
const animEasing = isClosing ? "ease-out" : "cubic-bezier(0.175, 0.885, 0.32, 1.275)";
|
|
293
|
+
const animDur = isClosing ? "0.3s" : "0.45s";
|
|
294
|
+
const flipTransition = `top ${animDur} ${animEasing}, left ${animDur} ${animEasing}, width ${animDur} ${animEasing}, height ${animDur} ${animEasing}, border-radius ${animDur} ${animEasing}`;
|
|
295
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
296
|
+
className: "fixed inset-0 z-[100]",
|
|
297
|
+
onClick: handleClose,
|
|
298
|
+
role: "dialog",
|
|
299
|
+
"aria-modal": "true",
|
|
300
|
+
children: [
|
|
301
|
+
/*#__PURE__*/ _jsx("div", {
|
|
302
|
+
className: "absolute inset-0 bg-background/70 backdrop-blur-md transition-opacity duration-400",
|
|
303
|
+
style: {
|
|
304
|
+
opacity: isOpen ? 1 : 0
|
|
305
|
+
}
|
|
306
|
+
}),
|
|
307
|
+
/*#__PURE__*/ _jsx("div", {
|
|
308
|
+
style: {
|
|
309
|
+
position: "fixed",
|
|
310
|
+
top: geometry.top,
|
|
311
|
+
left: geometry.left,
|
|
312
|
+
width: geometry.width,
|
|
313
|
+
height: geometry.height,
|
|
314
|
+
borderRadius: geometry.radius,
|
|
315
|
+
transition: flipTransition,
|
|
316
|
+
overflow: "hidden",
|
|
317
|
+
boxShadow: isOpen ? "0 24px 60px -12px rgb(0 0 0 / 0.35)" : "0 0px 0px 0px rgb(0 0 0 / 0)"
|
|
318
|
+
},
|
|
319
|
+
className: "bg-muted",
|
|
320
|
+
onTransitionEnd: ()=>{
|
|
321
|
+
if (phase === "closing") onClose();
|
|
322
|
+
},
|
|
323
|
+
onClick: (e)=>e.stopPropagation(),
|
|
324
|
+
children: /*#__PURE__*/ _jsx("img", {
|
|
325
|
+
ref: imgRef,
|
|
326
|
+
src: attachment.url,
|
|
327
|
+
alt: attachment.name,
|
|
328
|
+
className: "size-full object-cover",
|
|
329
|
+
draggable: false
|
|
330
|
+
})
|
|
331
|
+
}),
|
|
332
|
+
/*#__PURE__*/ _jsx("button", {
|
|
333
|
+
type: "button",
|
|
334
|
+
onClick: handleClose,
|
|
335
|
+
style: {
|
|
336
|
+
opacity: isOpen ? 1 : 0,
|
|
337
|
+
transform: isOpen ? "scale(1)" : "scale(0.7)"
|
|
338
|
+
},
|
|
339
|
+
className: cn("fixed right-4 top-4 flex size-9 items-center justify-center rounded-full bg-card/90 text-foreground/70 shadow-md backdrop-blur-sm", "transition-all duration-300 ease-[cubic-bezier(0.175,0.885,0.32,1.275)] hover:bg-card hover:text-foreground", !isOpen && "pointer-events-none"),
|
|
340
|
+
children: /*#__PURE__*/ _jsx("span", {
|
|
341
|
+
className: "scale-150",
|
|
342
|
+
children: /*#__PURE__*/ _jsx(CloseIcon, {})
|
|
343
|
+
})
|
|
344
|
+
})
|
|
345
|
+
]
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
export const PromptInput = /*#__PURE__*/ React.forwardRef(({ onSubmit, placeholder = "Ask anything", className, models = [
|
|
349
|
+
"GPT 5.5",
|
|
350
|
+
"Opus 4.8",
|
|
351
|
+
"Gemini 3.5 Flash",
|
|
352
|
+
"Composer 2.5",
|
|
353
|
+
"GLM 5.2"
|
|
354
|
+
], efforts = [
|
|
355
|
+
"Low",
|
|
356
|
+
"Medium",
|
|
357
|
+
"Max Effort"
|
|
358
|
+
], defaultValue = "", value: controlledValue, onChange, maxAttachments = 6 }, ref)=>{
|
|
359
|
+
const [expanded, setExpanded] = useState(false);
|
|
360
|
+
const [isSmoothResize, setIsSmoothResize] = useState(false);
|
|
361
|
+
const [localValue, setLocalValue] = useState(defaultValue);
|
|
362
|
+
const [selectedModel, setSelectedModel] = useState(models[0]);
|
|
363
|
+
const [effortIndex, setEffortIndex] = useState(1);
|
|
364
|
+
const [isModelSelectOpen, setIsModelSelectOpen] = useState(false);
|
|
365
|
+
const [attachments, setAttachments] = useState([]);
|
|
366
|
+
const [activeAttachment, setActiveAttachment] = useState(null);
|
|
367
|
+
// Audio/Voice recording states
|
|
368
|
+
const [isRecording, setIsRecording] = useState(false);
|
|
369
|
+
const [audioData, setAudioData] = useState(new Array(5).fill(0));
|
|
370
|
+
const valueRef = useRef(controlledValue !== undefined ? controlledValue : localValue);
|
|
371
|
+
// Refs for Web Audio & Speech Recognition cleanup
|
|
372
|
+
const streamRef = useRef(null);
|
|
373
|
+
const audioContextRef = useRef(null);
|
|
374
|
+
const rafRef = useRef(null);
|
|
375
|
+
const recognitionRef = useRef(null);
|
|
376
|
+
const demoIntervalRef = useRef(null);
|
|
377
|
+
const demoTextIntervalRef = useRef(null);
|
|
378
|
+
const [hoverStyle, setHoverStyle] = useState({
|
|
379
|
+
opacity: 0,
|
|
380
|
+
transform: "translateY(0px) scale(0.95)",
|
|
381
|
+
transition: "none"
|
|
382
|
+
});
|
|
383
|
+
const [containerHeight, setContainerHeight] = useState(116);
|
|
384
|
+
const [textareaHeight, setTextareaHeight] = useState(68);
|
|
385
|
+
const [isScrolling, setIsScrolling] = useState(false);
|
|
386
|
+
const isControlled = controlledValue !== undefined;
|
|
387
|
+
const value = isControlled ? controlledValue : localValue;
|
|
388
|
+
const hasValue = value.trim() !== "" || attachments.length > 0;
|
|
389
|
+
const hasAttachments = attachments.length > 0;
|
|
390
|
+
const textareaRef = useRef(null);
|
|
391
|
+
const internalContainerRef = useRef(null);
|
|
392
|
+
const topFadeRef = useRef(null);
|
|
393
|
+
const bottomFadeRef = useRef(null);
|
|
394
|
+
const fileInputRef = useRef(null);
|
|
395
|
+
const thumbRefs = useRef(new Map());
|
|
396
|
+
// Sync value ref for audio callback closure
|
|
397
|
+
useEffect(()=>{
|
|
398
|
+
valueRef.current = value;
|
|
399
|
+
}, [
|
|
400
|
+
value
|
|
401
|
+
]);
|
|
402
|
+
const updateFades = ()=>{
|
|
403
|
+
const el = textareaRef.current;
|
|
404
|
+
if (!el) return;
|
|
405
|
+
const { scrollTop, scrollHeight, clientHeight } = el;
|
|
406
|
+
if (topFadeRef.current) {
|
|
407
|
+
topFadeRef.current.style.opacity = Math.min(scrollTop / 20, 1).toString();
|
|
408
|
+
}
|
|
409
|
+
if (bottomFadeRef.current) {
|
|
410
|
+
const bottomScroll = scrollHeight - clientHeight - scrollTop;
|
|
411
|
+
bottomFadeRef.current.style.opacity = Math.min(Math.max(bottomScroll - 16, 0) / 10, 1).toString();
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
const handleValueChange = useCallback((val)=>{
|
|
415
|
+
setIsSmoothResize(true);
|
|
416
|
+
if (!isControlled) setLocalValue(val);
|
|
417
|
+
onChange?.(val);
|
|
418
|
+
}, [
|
|
419
|
+
isControlled,
|
|
420
|
+
onChange
|
|
421
|
+
]);
|
|
422
|
+
const expand = ()=>{
|
|
423
|
+
setIsSmoothResize(false);
|
|
424
|
+
setExpanded(true);
|
|
425
|
+
};
|
|
426
|
+
// --- Voice Recording Logic ---
|
|
427
|
+
const stopRecording = useCallback(()=>{
|
|
428
|
+
if (recognitionRef.current) {
|
|
429
|
+
recognitionRef.current.stop();
|
|
430
|
+
recognitionRef.current = null;
|
|
431
|
+
}
|
|
432
|
+
if (rafRef.current) {
|
|
433
|
+
cancelAnimationFrame(rafRef.current);
|
|
434
|
+
rafRef.current = null;
|
|
435
|
+
}
|
|
436
|
+
if (streamRef.current) {
|
|
437
|
+
streamRef.current.getTracks().forEach((track)=>track.stop());
|
|
438
|
+
streamRef.current = null;
|
|
439
|
+
}
|
|
440
|
+
if (audioContextRef.current) {
|
|
441
|
+
audioContextRef.current.close();
|
|
442
|
+
audioContextRef.current = null;
|
|
443
|
+
}
|
|
444
|
+
if (demoIntervalRef.current) {
|
|
445
|
+
window.clearInterval(demoIntervalRef.current);
|
|
446
|
+
demoIntervalRef.current = null;
|
|
447
|
+
}
|
|
448
|
+
if (demoTextIntervalRef.current) {
|
|
449
|
+
window.clearInterval(demoTextIntervalRef.current);
|
|
450
|
+
demoTextIntervalRef.current = null;
|
|
451
|
+
}
|
|
452
|
+
setIsRecording(false);
|
|
453
|
+
setAudioData(new Array(5).fill(0));
|
|
454
|
+
}, []);
|
|
455
|
+
const startRecording = useCallback(async ()=>{
|
|
456
|
+
setIsSmoothResize(false);
|
|
457
|
+
setExpanded(true);
|
|
458
|
+
let stream = null;
|
|
459
|
+
try {
|
|
460
|
+
if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
|
|
461
|
+
stream = await navigator.mediaDevices.getUserMedia({
|
|
462
|
+
audio: true
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
} catch (err) {
|
|
466
|
+
console.warn("Microphone access denied or unavailable. Falling back to simulated voice mode for demo.");
|
|
467
|
+
}
|
|
468
|
+
setIsRecording(true);
|
|
469
|
+
// Simulation function for tight sandbox environments
|
|
470
|
+
function simulateText() {
|
|
471
|
+
const fakeText = "Can you build a high fidelity Framer Motion layout animation for a dark mode dashboard?";
|
|
472
|
+
const words = fakeText.split(" ");
|
|
473
|
+
let i = 0;
|
|
474
|
+
let currentBase = valueRef.current;
|
|
475
|
+
demoTextIntervalRef.current = window.setInterval(()=>{
|
|
476
|
+
if (i < words.length) {
|
|
477
|
+
currentBase = (currentBase ? currentBase + " " : "") + words[i];
|
|
478
|
+
handleValueChange(currentBase);
|
|
479
|
+
i++;
|
|
480
|
+
} else {
|
|
481
|
+
stopRecording();
|
|
482
|
+
}
|
|
483
|
+
}, 300);
|
|
484
|
+
}
|
|
485
|
+
if (stream) {
|
|
486
|
+
streamRef.current = stream;
|
|
487
|
+
// Setup Web Audio API for visualizer
|
|
488
|
+
const AudioCtx = window.AudioContext || window.webkitAudioContext;
|
|
489
|
+
const audioCtx = new AudioCtx();
|
|
490
|
+
audioContextRef.current = audioCtx;
|
|
491
|
+
const analyser = audioCtx.createAnalyser();
|
|
492
|
+
analyser.fftSize = 64;
|
|
493
|
+
const source = audioCtx.createMediaStreamSource(stream);
|
|
494
|
+
source.connect(analyser);
|
|
495
|
+
const dataArray = new Uint8Array(analyser.frequencyBinCount);
|
|
496
|
+
const updateVisualizer = ()=>{
|
|
497
|
+
analyser.getByteFrequencyData(dataArray);
|
|
498
|
+
const bands = new Array(5).fill(0);
|
|
499
|
+
const step = Math.floor(dataArray.length / 5);
|
|
500
|
+
for(let i = 0; i < 5; i++){
|
|
501
|
+
let sum = 0;
|
|
502
|
+
for(let j = 0; j < step; j++){
|
|
503
|
+
sum += dataArray[i * step + j];
|
|
504
|
+
}
|
|
505
|
+
bands[i] = sum / step / 255; // normalize to 0-1
|
|
506
|
+
}
|
|
507
|
+
setAudioData(bands);
|
|
508
|
+
rafRef.current = requestAnimationFrame(updateVisualizer);
|
|
509
|
+
};
|
|
510
|
+
updateVisualizer();
|
|
511
|
+
// Setup Speech Recognition
|
|
512
|
+
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
|
|
513
|
+
if (SpeechRecognition) {
|
|
514
|
+
const recognition = new SpeechRecognition();
|
|
515
|
+
recognition.continuous = true;
|
|
516
|
+
recognition.interimResults = true;
|
|
517
|
+
let baseline = valueRef.current;
|
|
518
|
+
recognition.onresult = (event)=>{
|
|
519
|
+
let interimTranscript = "";
|
|
520
|
+
let finalTranscript = "";
|
|
521
|
+
for(let i = event.resultIndex; i < event.results.length; ++i){
|
|
522
|
+
if (event.results[i].isFinal) {
|
|
523
|
+
finalTranscript += event.results[i][0].transcript;
|
|
524
|
+
} else {
|
|
525
|
+
interimTranscript += event.results[i][0].transcript;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
if (finalTranscript) {
|
|
529
|
+
baseline += (baseline ? " " : "") + finalTranscript;
|
|
530
|
+
}
|
|
531
|
+
handleValueChange((baseline + (interimTranscript ? " " + interimTranscript : "")).trim());
|
|
532
|
+
};
|
|
533
|
+
recognition.onerror = (e)=>{
|
|
534
|
+
console.error("Speech recognition error", e);
|
|
535
|
+
stopRecording();
|
|
536
|
+
};
|
|
537
|
+
recognition.onend = ()=>{
|
|
538
|
+
stopRecording();
|
|
539
|
+
};
|
|
540
|
+
recognitionRef.current = recognition;
|
|
541
|
+
recognition.start();
|
|
542
|
+
} else {
|
|
543
|
+
console.warn("Speech Recognition API not supported in this browser. Using simulated text.");
|
|
544
|
+
simulateText();
|
|
545
|
+
}
|
|
546
|
+
} else {
|
|
547
|
+
// Fallback simulated visualizer
|
|
548
|
+
demoIntervalRef.current = window.setInterval(()=>{
|
|
549
|
+
setAudioData(Array.from({
|
|
550
|
+
length: 5
|
|
551
|
+
}, ()=>Math.random() * 0.8 + 0.1));
|
|
552
|
+
}, 100);
|
|
553
|
+
simulateText();
|
|
554
|
+
}
|
|
555
|
+
}, [
|
|
556
|
+
handleValueChange,
|
|
557
|
+
stopRecording
|
|
558
|
+
]);
|
|
559
|
+
// Keep textarea auto-scrolled to bottom while recording
|
|
560
|
+
useEffect(()=>{
|
|
561
|
+
if (isRecording && textareaRef.current) {
|
|
562
|
+
textareaRef.current.scrollTop = textareaRef.current.scrollHeight;
|
|
563
|
+
}
|
|
564
|
+
}, [
|
|
565
|
+
value,
|
|
566
|
+
isRecording
|
|
567
|
+
]);
|
|
568
|
+
// Ensure cleanup of mic/streams on unmount
|
|
569
|
+
useEffect(()=>{
|
|
570
|
+
return ()=>{
|
|
571
|
+
stopRecording();
|
|
572
|
+
attachments.forEach((a)=>URL.revokeObjectURL(a.url));
|
|
573
|
+
};
|
|
574
|
+
}, [
|
|
575
|
+
stopRecording,
|
|
576
|
+
attachments
|
|
577
|
+
]);
|
|
578
|
+
useEffect(()=>{
|
|
579
|
+
if ((value.trim() !== "" || hasAttachments) && !expanded) {
|
|
580
|
+
setIsSmoothResize(false);
|
|
581
|
+
setExpanded(true);
|
|
582
|
+
}
|
|
583
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
584
|
+
}, [
|
|
585
|
+
value,
|
|
586
|
+
expanded,
|
|
587
|
+
hasAttachments
|
|
588
|
+
]);
|
|
589
|
+
useEffect(()=>{
|
|
590
|
+
if (expanded && !isRecording) {
|
|
591
|
+
const timer = setTimeout(()=>{
|
|
592
|
+
if (textareaRef.current) {
|
|
593
|
+
textareaRef.current.focus();
|
|
594
|
+
const length = textareaRef.current.value.length;
|
|
595
|
+
textareaRef.current.setSelectionRange(length, length);
|
|
596
|
+
}
|
|
597
|
+
}, 50);
|
|
598
|
+
return ()=>clearTimeout(timer);
|
|
599
|
+
}
|
|
600
|
+
}, [
|
|
601
|
+
expanded,
|
|
602
|
+
isRecording
|
|
603
|
+
]);
|
|
604
|
+
// ONLY updates height on value/text change. Adding attachments leaves this completely isolated.
|
|
605
|
+
useEffect(()=>{
|
|
606
|
+
if (!textareaRef.current) return;
|
|
607
|
+
const el = textareaRef.current;
|
|
608
|
+
const currentHeight = el.style.height;
|
|
609
|
+
el.style.transition = 'none';
|
|
610
|
+
el.style.height = "0px";
|
|
611
|
+
const scrollHeight = el.scrollHeight;
|
|
612
|
+
el.style.height = currentHeight;
|
|
613
|
+
void el.offsetHeight;
|
|
614
|
+
el.style.transition = '';
|
|
615
|
+
const newHeight = Math.max(68, Math.min(scrollHeight, 160));
|
|
616
|
+
el.style.height = `${newHeight}px`;
|
|
617
|
+
setTextareaHeight(newHeight);
|
|
618
|
+
setIsScrolling(scrollHeight > 160);
|
|
619
|
+
setTimeout(updateFades, 0);
|
|
620
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
621
|
+
}, [
|
|
622
|
+
value,
|
|
623
|
+
expanded
|
|
624
|
+
]);
|
|
625
|
+
useEffect(()=>{
|
|
626
|
+
setContainerHeight(Math.max(116, textareaHeight + 48));
|
|
627
|
+
setTimeout(updateFades, 0);
|
|
628
|
+
}, [
|
|
629
|
+
textareaHeight
|
|
630
|
+
]);
|
|
631
|
+
useEffect(()=>{
|
|
632
|
+
if (!isModelSelectOpen) return;
|
|
633
|
+
const handleOutsideClick = (e)=>{
|
|
634
|
+
if (internalContainerRef.current && !internalContainerRef.current.contains(e.target)) {
|
|
635
|
+
setIsModelSelectOpen(false);
|
|
636
|
+
}
|
|
637
|
+
};
|
|
638
|
+
document.addEventListener("mousedown", handleOutsideClick);
|
|
639
|
+
return ()=>document.removeEventListener("mousedown", handleOutsideClick);
|
|
640
|
+
}, [
|
|
641
|
+
isModelSelectOpen
|
|
642
|
+
]);
|
|
643
|
+
const handleBlur = (e)=>{
|
|
644
|
+
if (internalContainerRef.current && internalContainerRef.current.contains(e.relatedTarget)) return;
|
|
645
|
+
if (value.trim() === "" && !hasAttachments && !isRecording) {
|
|
646
|
+
setIsSmoothResize(false);
|
|
647
|
+
setExpanded(false);
|
|
648
|
+
setIsModelSelectOpen(false);
|
|
649
|
+
}
|
|
650
|
+
};
|
|
651
|
+
const handleSubmit = ()=>{
|
|
652
|
+
if (value.trim() === "" && !hasAttachments) return;
|
|
653
|
+
setIsSmoothResize(false);
|
|
654
|
+
onSubmit?.(value, {
|
|
655
|
+
model: selectedModel,
|
|
656
|
+
effort: efforts[effortIndex],
|
|
657
|
+
attachments: attachments.map((a)=>a.file)
|
|
658
|
+
});
|
|
659
|
+
handleValueChange("");
|
|
660
|
+
attachments.forEach((a)=>URL.revokeObjectURL(a.url));
|
|
661
|
+
setAttachments([]);
|
|
662
|
+
setExpanded(false);
|
|
663
|
+
setIsModelSelectOpen(false);
|
|
664
|
+
};
|
|
665
|
+
const cycleEffort = (e)=>{
|
|
666
|
+
e.stopPropagation();
|
|
667
|
+
setEffortIndex((prev)=>(prev + 1) % efforts.length);
|
|
668
|
+
};
|
|
669
|
+
const openFileChooser = (e)=>{
|
|
670
|
+
e.stopPropagation();
|
|
671
|
+
fileInputRef.current?.click();
|
|
672
|
+
};
|
|
673
|
+
const handleFilesChosen = async (e)=>{
|
|
674
|
+
const fileList = e.target.files;
|
|
675
|
+
if (!fileList) return;
|
|
676
|
+
const files = Array.from(fileList).filter((f)=>f.type.startsWith("image/"));
|
|
677
|
+
e.target.value = "";
|
|
678
|
+
if (files.length === 0) return;
|
|
679
|
+
const room = Math.max(0, maxAttachments - attachments.length);
|
|
680
|
+
const accepted = files.slice(0, room);
|
|
681
|
+
if (!expanded) {
|
|
682
|
+
setIsSmoothResize(false);
|
|
683
|
+
setExpanded(true);
|
|
684
|
+
} else {
|
|
685
|
+
setIsSmoothResize(true);
|
|
686
|
+
}
|
|
687
|
+
for (const file of accepted){
|
|
688
|
+
const url = URL.createObjectURL(file);
|
|
689
|
+
const img = new Image();
|
|
690
|
+
img.onload = ()=>addAttachment(file, url, img.naturalWidth, img.naturalHeight);
|
|
691
|
+
img.onerror = ()=>addAttachment(file, url, 800, 600);
|
|
692
|
+
img.src = url;
|
|
693
|
+
}
|
|
694
|
+
};
|
|
695
|
+
const addAttachment = (file, url, width, height)=>{
|
|
696
|
+
const id = `${file.name}-${file.lastModified}-${Math.random().toString(36).slice(2, 8)}`;
|
|
697
|
+
setAttachments((prev)=>[
|
|
698
|
+
...prev,
|
|
699
|
+
{
|
|
700
|
+
id,
|
|
701
|
+
file,
|
|
702
|
+
url,
|
|
703
|
+
name: file.name,
|
|
704
|
+
width,
|
|
705
|
+
height
|
|
706
|
+
}
|
|
707
|
+
]);
|
|
708
|
+
};
|
|
709
|
+
const removeAttachment = (id)=>{
|
|
710
|
+
setIsSmoothResize(true);
|
|
711
|
+
setAttachments((prev)=>{
|
|
712
|
+
const target = prev.find((a)=>a.id === id);
|
|
713
|
+
if (target) URL.revokeObjectURL(target.url);
|
|
714
|
+
return prev.filter((a)=>a.id !== id);
|
|
715
|
+
});
|
|
716
|
+
thumbRefs.current.delete(id);
|
|
717
|
+
};
|
|
718
|
+
// Calculate action button states
|
|
719
|
+
const showArrow = hasValue && !isRecording;
|
|
720
|
+
const showStop = isRecording;
|
|
721
|
+
const showMic = !hasValue && !isRecording;
|
|
722
|
+
const onActionButtonClick = (e)=>{
|
|
723
|
+
e.preventDefault();
|
|
724
|
+
if (isRecording) {
|
|
725
|
+
stopRecording();
|
|
726
|
+
} else if (hasValue) {
|
|
727
|
+
handleSubmit();
|
|
728
|
+
} else {
|
|
729
|
+
startRecording();
|
|
730
|
+
}
|
|
731
|
+
};
|
|
732
|
+
return /*#__PURE__*/ _jsxs(_Fragment, {
|
|
733
|
+
children: [
|
|
734
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
735
|
+
ref: (node)=>{
|
|
736
|
+
if (typeof ref === "function") ref(node);
|
|
737
|
+
else if (ref) ref.current = node;
|
|
738
|
+
// @ts-ignore
|
|
739
|
+
internalContainerRef.current = node;
|
|
740
|
+
},
|
|
741
|
+
onBlur: handleBlur,
|
|
742
|
+
className: cn("relative flex flex-col w-full", className),
|
|
743
|
+
style: {
|
|
744
|
+
maxWidth: expanded ? "100%" : "100%",
|
|
745
|
+
transition: isSmoothResize ? "max-width 0.15s ease-out" : "max-width 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275)"
|
|
746
|
+
},
|
|
747
|
+
children: [
|
|
748
|
+
/*#__PURE__*/ _jsx("input", {
|
|
749
|
+
ref: fileInputRef,
|
|
750
|
+
type: "file",
|
|
751
|
+
accept: "image/*",
|
|
752
|
+
multiple: true,
|
|
753
|
+
onChange: handleFilesChosen,
|
|
754
|
+
className: "hidden",
|
|
755
|
+
tabIndex: -1,
|
|
756
|
+
"aria-hidden": "true"
|
|
757
|
+
}),
|
|
758
|
+
/*#__PURE__*/ _jsx("div", {
|
|
759
|
+
"aria-hidden": !hasAttachments,
|
|
760
|
+
style: {
|
|
761
|
+
height: hasAttachments && expanded ? 68 : 0,
|
|
762
|
+
transition: isSmoothResize ? "height 0.15s ease-out" : "height 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275)"
|
|
763
|
+
},
|
|
764
|
+
className: "w-full relative z-0 overflow-hidden",
|
|
765
|
+
children: /*#__PURE__*/ _jsx("div", {
|
|
766
|
+
style: {
|
|
767
|
+
position: "absolute",
|
|
768
|
+
bottom: -8,
|
|
769
|
+
left: 20,
|
|
770
|
+
right: 20,
|
|
771
|
+
height: 68,
|
|
772
|
+
transform: hasAttachments && expanded ? "translateY(0)" : "translateY(100%)",
|
|
773
|
+
opacity: hasAttachments && expanded ? 1 : 0,
|
|
774
|
+
transition: isSmoothResize ? "transform 0.15s ease-out, opacity 0.15s ease-out" : "transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s ease-out"
|
|
775
|
+
},
|
|
776
|
+
className: "border border-border border-b-0 bg-muted rounded-t-2xl px-2 pt-2 pb-1 flex items-start gap-2 overflow-x-auto prompt-scrollbar",
|
|
777
|
+
children: attachments.map((attachment, index)=>/*#__PURE__*/ _jsx(AttachmentThumb, {
|
|
778
|
+
attachment: attachment,
|
|
779
|
+
index: index,
|
|
780
|
+
onRemove: removeAttachment,
|
|
781
|
+
onOpen: (a, rect)=>setActiveAttachment({
|
|
782
|
+
attachment: a,
|
|
783
|
+
rect
|
|
784
|
+
}),
|
|
785
|
+
registerRef: (id, el)=>thumbRefs.current.set(id, el)
|
|
786
|
+
}, attachment.id))
|
|
787
|
+
})
|
|
788
|
+
}),
|
|
789
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
790
|
+
onMouseDown: (e)=>{
|
|
791
|
+
const isTextarea = e.target === textareaRef.current;
|
|
792
|
+
if (expanded && !isTextarea && !isRecording) {
|
|
793
|
+
e.preventDefault();
|
|
794
|
+
textareaRef.current?.focus();
|
|
795
|
+
}
|
|
796
|
+
},
|
|
797
|
+
style: {
|
|
798
|
+
borderRadius: 24,
|
|
799
|
+
height: expanded ? containerHeight : 48,
|
|
800
|
+
transition: isSmoothResize ? SMOOTH_HEIGHT_TRANSITION : SPRING_TRANSITION,
|
|
801
|
+
overflow: expanded ? "visible" : "hidden"
|
|
802
|
+
},
|
|
803
|
+
className: cn("relative w-full border border-border bg-card shadow-sm focus-within:border-ring/40 focus-within:ring-1 focus-within:ring-ring/20 hover:border-border/80 z-10", expanded ? "cursor-text" : "cursor-default"),
|
|
804
|
+
children: [
|
|
805
|
+
/*#__PURE__*/ _jsx("style", {
|
|
806
|
+
dangerouslySetInnerHTML: {
|
|
807
|
+
__html: `
|
|
808
|
+
.prompt-scrollbar::-webkit-scrollbar { width: 4px; height: 4px; background: transparent; }
|
|
809
|
+
.prompt-scrollbar::-webkit-scrollbar-track { background: transparent; }
|
|
810
|
+
.prompt-scrollbar::-webkit-scrollbar-thumb { background: transparent; border-radius: 4px; }
|
|
811
|
+
.prompt-scrollbar:hover::-webkit-scrollbar-thumb { background: hsl(var(--muted-foreground) / 0.3); }
|
|
812
|
+
`
|
|
813
|
+
}
|
|
814
|
+
}),
|
|
815
|
+
/*#__PURE__*/ _jsx("textarea", {
|
|
816
|
+
ref: textareaRef,
|
|
817
|
+
value: value,
|
|
818
|
+
onChange: (e)=>handleValueChange(e.target.value),
|
|
819
|
+
onScroll: updateFades,
|
|
820
|
+
onKeyDown: (e)=>{
|
|
821
|
+
if (e.key === "Enter" && !e.shiftKey) {
|
|
822
|
+
e.preventDefault();
|
|
823
|
+
handleSubmit();
|
|
824
|
+
}
|
|
825
|
+
if (e.key === "Escape" && value.trim() === "" && !hasAttachments) {
|
|
826
|
+
setIsSmoothResize(false);
|
|
827
|
+
setExpanded(false);
|
|
828
|
+
setIsModelSelectOpen(false);
|
|
829
|
+
}
|
|
830
|
+
},
|
|
831
|
+
placeholder: placeholder,
|
|
832
|
+
"aria-label": "Prompt",
|
|
833
|
+
disabled: isRecording,
|
|
834
|
+
style: {
|
|
835
|
+
transition: isSmoothResize ? "height 0.15s ease-out" : "opacity 0.3s ease-out, transform 0.3s ease-out, height 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275)"
|
|
836
|
+
},
|
|
837
|
+
className: cn("prompt-scrollbar absolute top-0 inset-x-0 z-[1] w-full resize-none bg-transparent pl-4 pr-12 py-3.5 text-sm leading-[22px] text-foreground outline-none placeholder:font-medium placeholder:text-muted-foreground/80 cursor-text", expanded ? "opacity-100 scale-100 translate-y-0" : "opacity-0 scale-95 -translate-y-1 pointer-events-none", isScrolling ? "overflow-y-auto" : "overflow-y-hidden", isRecording && "pointer-events-none")
|
|
838
|
+
}),
|
|
839
|
+
/*#__PURE__*/ _jsx("div", {
|
|
840
|
+
ref: topFadeRef,
|
|
841
|
+
className: "absolute left-4 right-12 top-0 z-[2] h-8 bg-gradient-to-b from-card via-card/90 to-transparent pointer-events-none"
|
|
842
|
+
}),
|
|
843
|
+
/*#__PURE__*/ _jsx("div", {
|
|
844
|
+
ref: bottomFadeRef,
|
|
845
|
+
className: "absolute left-4 right-12 z-[2] h-8 bg-gradient-to-t from-card via-card/90 to-transparent pointer-events-none",
|
|
846
|
+
style: {
|
|
847
|
+
opacity: 0,
|
|
848
|
+
top: `${textareaHeight - 32}px`,
|
|
849
|
+
transition: isSmoothResize ? "top 0.15s ease-out" : "top 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275)"
|
|
850
|
+
}
|
|
851
|
+
}),
|
|
852
|
+
/*#__PURE__*/ _jsx("button", {
|
|
853
|
+
type: "button",
|
|
854
|
+
onClick: expand,
|
|
855
|
+
style: {
|
|
856
|
+
transition: isSmoothResize ? "none" : "all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275)"
|
|
857
|
+
},
|
|
858
|
+
className: cn("absolute inset-x-0 top-0 z-[1] cursor-text pl-4 pr-12 py-[15px] text-left text-sm font-medium leading-[17px] text-muted-foreground/80 outline-none truncate", !expanded ? "opacity-100 scale-100 translate-y-0" : "opacity-0 scale-105 translate-y-1 pointer-events-none"),
|
|
859
|
+
"aria-label": "Open prompt input",
|
|
860
|
+
children: placeholder
|
|
861
|
+
}),
|
|
862
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
863
|
+
className: cn("absolute bottom-2 left-3 right-12 z-[10] flex items-center gap-0 transition-all duration-300 ease-[cubic-bezier(0.175,0.885,0.32,1.275)]", expanded && !isRecording ? "opacity-100 blur-0 translate-y-0 pointer-events-auto" : "opacity-0 blur-sm translate-y-2 pointer-events-none"),
|
|
864
|
+
children: [
|
|
865
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
866
|
+
className: "relative",
|
|
867
|
+
children: [
|
|
868
|
+
/*#__PURE__*/ _jsxs("button", {
|
|
869
|
+
type: "button",
|
|
870
|
+
onMouseDown: (e)=>e.preventDefault(),
|
|
871
|
+
onClick: (e)=>{
|
|
872
|
+
e.stopPropagation();
|
|
873
|
+
setIsModelSelectOpen((prev)=>!prev);
|
|
874
|
+
},
|
|
875
|
+
className: cn("group flex items-center gap-1 rounded-full px-2 py-1 text-foreground/50 transition-all duration-200 outline-none hover:bg-accent/60 hover:text-foreground cursor-default", isModelSelectOpen ? "bg-accent/60 text-foreground" : ""),
|
|
876
|
+
"aria-label": `Select model. Current: ${selectedModel}`,
|
|
877
|
+
children: [
|
|
878
|
+
/*#__PURE__*/ _jsx(ModelIcon, {
|
|
879
|
+
model: selectedModel,
|
|
880
|
+
className: "size-3.5 opacity-70 group-hover:opacity-100 transition-opacity"
|
|
881
|
+
}),
|
|
882
|
+
/*#__PURE__*/ _jsx("span", {
|
|
883
|
+
className: "text-xs font-semibold select-none transition-colors",
|
|
884
|
+
children: /*#__PURE__*/ _jsx(MorphingText, {
|
|
885
|
+
text: selectedModel
|
|
886
|
+
})
|
|
887
|
+
})
|
|
888
|
+
]
|
|
889
|
+
}),
|
|
890
|
+
/*#__PURE__*/ _jsx("div", {
|
|
891
|
+
style: {
|
|
892
|
+
transformOrigin: "bottom left"
|
|
893
|
+
},
|
|
894
|
+
onMouseLeave: ()=>{
|
|
895
|
+
setHoverStyle((prev)=>({
|
|
896
|
+
...prev,
|
|
897
|
+
opacity: 0,
|
|
898
|
+
transform: prev.transform.replace("scale(1)", "scale(0.95)"),
|
|
899
|
+
transition: "opacity 0.2s ease-in, transform 0.2s ease-out"
|
|
900
|
+
}));
|
|
901
|
+
},
|
|
902
|
+
className: cn("absolute bottom-full left-0 mb-2.5 z-50 w-44 rounded-2xl border border-border bg-card/95 p-1 shadow-xl backdrop-blur-md flex flex-col gap-0.5 transition-all duration-400 cursor-default", isModelSelectOpen ? "opacity-100 scale-100 translate-y-0 pointer-events-auto ease-[cubic-bezier(0.34,1.56,0.64,1)]" : "opacity-0 scale-95 translate-y-3 pointer-events-none ease-[cubic-bezier(0.175,0.885,0.32,1.275)]"),
|
|
903
|
+
children: /*#__PURE__*/ _jsxs("div", {
|
|
904
|
+
className: "relative flex flex-col gap-0.5",
|
|
905
|
+
children: [
|
|
906
|
+
/*#__PURE__*/ _jsx("div", {
|
|
907
|
+
style: hoverStyle,
|
|
908
|
+
className: "absolute left-0 right-0 top-0 h-8 -z-10 rounded-xl bg-accent pointer-events-none"
|
|
909
|
+
}),
|
|
910
|
+
models.map((model, idx)=>/*#__PURE__*/ _jsx("button", {
|
|
911
|
+
type: "button",
|
|
912
|
+
onMouseDown: (e)=>e.preventDefault(),
|
|
913
|
+
onMouseEnter: ()=>{
|
|
914
|
+
setHoverStyle((prev)=>({
|
|
915
|
+
opacity: 1,
|
|
916
|
+
transform: `translateY(${idx * 34}px) scale(1)`,
|
|
917
|
+
transition: prev.opacity === 0 ? "opacity 0.15s ease-out" : "transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.15s ease"
|
|
918
|
+
}));
|
|
919
|
+
},
|
|
920
|
+
onClick: (e)=>{
|
|
921
|
+
e.stopPropagation();
|
|
922
|
+
setSelectedModel(model);
|
|
923
|
+
setIsModelSelectOpen(false);
|
|
924
|
+
},
|
|
925
|
+
className: "group relative flex h-8 w-full items-center justify-between rounded-xl px-2.5 py-1.5 text-left text-xs font-medium text-foreground/80 outline-none active:scale-[0.98] cursor-default",
|
|
926
|
+
children: /*#__PURE__*/ _jsxs("span", {
|
|
927
|
+
className: "flex items-center gap-2",
|
|
928
|
+
children: [
|
|
929
|
+
/*#__PURE__*/ _jsx(ModelIcon, {
|
|
930
|
+
model: model,
|
|
931
|
+
className: "size-3.5 opacity-85 group-hover:opacity-100 transition-opacity"
|
|
932
|
+
}),
|
|
933
|
+
model
|
|
934
|
+
]
|
|
935
|
+
})
|
|
936
|
+
}, model))
|
|
937
|
+
]
|
|
938
|
+
})
|
|
939
|
+
})
|
|
940
|
+
]
|
|
941
|
+
}),
|
|
942
|
+
/*#__PURE__*/ _jsxs("button", {
|
|
943
|
+
type: "button",
|
|
944
|
+
onMouseDown: (e)=>e.preventDefault(),
|
|
945
|
+
onClick: cycleEffort,
|
|
946
|
+
className: "group flex items-center gap-1 rounded-full px-2 py-1 text-foreground/50 transition-all duration-200 hover:bg-accent/60 hover:text-foreground outline-none cursor-default",
|
|
947
|
+
children: [
|
|
948
|
+
/*#__PURE__*/ _jsx(DynamicBarsIcon, {
|
|
949
|
+
level: efforts[effortIndex]
|
|
950
|
+
}),
|
|
951
|
+
/*#__PURE__*/ _jsx("span", {
|
|
952
|
+
className: "text-xs font-semibold select-none transition-colors",
|
|
953
|
+
children: /*#__PURE__*/ _jsx(MorphingText, {
|
|
954
|
+
text: efforts[effortIndex]
|
|
955
|
+
})
|
|
956
|
+
})
|
|
957
|
+
]
|
|
958
|
+
}),
|
|
959
|
+
/*#__PURE__*/ _jsx("button", {
|
|
960
|
+
type: "button",
|
|
961
|
+
onMouseDown: (e)=>e.preventDefault(),
|
|
962
|
+
onClick: openFileChooser,
|
|
963
|
+
disabled: attachments.length >= maxAttachments,
|
|
964
|
+
className: "ml-auto flex size-7 items-center justify-center rounded-full text-foreground/50 transition-all duration-200 hover:bg-accent/60 hover:text-foreground outline-none cursor-default disabled:opacity-40 disabled:pointer-events-none",
|
|
965
|
+
children: /*#__PURE__*/ _jsx(PlusIcon, {})
|
|
966
|
+
})
|
|
967
|
+
]
|
|
968
|
+
}),
|
|
969
|
+
/*#__PURE__*/ _jsx("div", {
|
|
970
|
+
className: cn("absolute right-12 bottom-2 z-[10] flex h-8 items-center justify-end gap-[3px] transition-all duration-400 ease-[cubic-bezier(0.175,0.885,0.32,1.275)]", isRecording ? "w-16 opacity-100 translate-x-0" : "w-0 opacity-0 translate-x-4 pointer-events-none"),
|
|
971
|
+
children: audioData.map((val, i)=>/*#__PURE__*/ _jsx("div", {
|
|
972
|
+
className: "w-1 rounded-full bg-primary transition-[height] duration-75 ease-out",
|
|
973
|
+
style: {
|
|
974
|
+
height: `${Math.max(4, val * 24)}px`
|
|
975
|
+
}
|
|
976
|
+
}, i))
|
|
977
|
+
}),
|
|
978
|
+
/*#__PURE__*/ _jsx("button", {
|
|
979
|
+
type: "button",
|
|
980
|
+
onMouseDown: (e)=>{
|
|
981
|
+
e.preventDefault();
|
|
982
|
+
e.stopPropagation();
|
|
983
|
+
},
|
|
984
|
+
onClick: onActionButtonClick,
|
|
985
|
+
"aria-label": showArrow ? "Send prompt" : showStop ? "Stop recording" : "Use voice input",
|
|
986
|
+
style: {
|
|
987
|
+
borderRadius: 9999
|
|
988
|
+
},
|
|
989
|
+
className: "absolute right-2 bottom-2 z-[10] flex h-8 w-8 items-center justify-center bg-primary text-primary-foreground transition-all duration-300 hover:opacity-90 outline-none focus-visible:ring-2 focus-visible:ring-ring cursor-default",
|
|
990
|
+
children: /*#__PURE__*/ _jsxs("span", {
|
|
991
|
+
className: "relative flex h-full w-full items-center justify-center",
|
|
992
|
+
children: [
|
|
993
|
+
/*#__PURE__*/ _jsx("span", {
|
|
994
|
+
className: cn("absolute inset-0 flex items-center justify-center transition-all duration-300 ease-[cubic-bezier(0.175,0.885,0.32,1.275)]", showArrow ? "opacity-100 scale-100 rotate-0 blur-none" : "opacity-0 scale-50 rotate-45 blur-[1px] pointer-events-none"),
|
|
995
|
+
children: /*#__PURE__*/ _jsx(ArrowUpIcon, {})
|
|
996
|
+
}),
|
|
997
|
+
/*#__PURE__*/ _jsx("span", {
|
|
998
|
+
className: cn("absolute inset-0 flex items-center justify-center transition-all duration-300 ease-[cubic-bezier(0.175,0.885,0.32,1.275)]", showMic ? "opacity-100 scale-100 rotate-0 blur-none" : "opacity-0 scale-50 -rotate-45 blur-[1px] pointer-events-none"),
|
|
999
|
+
children: /*#__PURE__*/ _jsx(MicIcon, {})
|
|
1000
|
+
}),
|
|
1001
|
+
/*#__PURE__*/ _jsx("span", {
|
|
1002
|
+
className: cn("absolute inset-0 flex items-center justify-center transition-all duration-300 ease-[cubic-bezier(0.175,0.885,0.32,1.275)]", showStop ? "opacity-100 scale-100 rotate-0 blur-none" : "opacity-0 scale-50 rotate-45 blur-[1px] pointer-events-none"),
|
|
1003
|
+
children: /*#__PURE__*/ _jsx(StopIcon, {})
|
|
1004
|
+
})
|
|
1005
|
+
]
|
|
1006
|
+
})
|
|
1007
|
+
})
|
|
1008
|
+
]
|
|
1009
|
+
})
|
|
1010
|
+
]
|
|
1011
|
+
}),
|
|
1012
|
+
activeAttachment && /*#__PURE__*/ _jsx(AttachmentGalleryModal, {
|
|
1013
|
+
attachment: activeAttachment.attachment,
|
|
1014
|
+
originRect: activeAttachment.rect,
|
|
1015
|
+
onClose: ()=>setActiveAttachment(null)
|
|
1016
|
+
})
|
|
1017
|
+
]
|
|
1018
|
+
});
|
|
1019
|
+
});
|
|
1020
|
+
PromptInput.displayName = "PromptInput";
|
|
1021
|
+
export default PromptInput;
|