@intentai/react 2.1.2 → 2.3.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/dist/index.js CHANGED
@@ -1,1764 +1,2 @@
1
- "use strict";
2
- "use client";
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
-
21
- // src/index.tsx
22
- var index_exports = {};
23
- __export(index_exports, {
24
- IntentAIWidget: () => IntentAIWidget,
25
- PremiumVoiceWidget: () => PremiumVoiceWidget,
26
- default: () => index_default,
27
- useIntentAI: () => useIntentAI
28
- });
29
- module.exports = __toCommonJS(index_exports);
30
- var import_react2 = require("react");
31
-
32
- // src/components/PremiumVoiceWidget.tsx
33
- var import_react = require("react");
34
- var import_framer_motion = require("framer-motion");
35
- var import_jsx_runtime = require("react/jsx-runtime");
36
- var WidgetContext = (0, import_react.createContext)(null);
37
- var useWidget = () => {
38
- const context = (0, import_react.useContext)(WidgetContext);
39
- if (!context) throw new Error("useWidget must be used within WidgetProvider");
40
- return context;
41
- };
42
- var useReducedMotion = () => {
43
- const [reducedMotion, setReducedMotion] = (0, import_react.useState)(false);
44
- (0, import_react.useEffect)(() => {
45
- const mediaQuery = window.matchMedia("(prefers-reduced-motion: reduce)");
46
- setReducedMotion(mediaQuery.matches);
47
- const handler = (e) => setReducedMotion(e.matches);
48
- mediaQuery.addEventListener("change", handler);
49
- return () => mediaQuery.removeEventListener("change", handler);
50
- }, []);
51
- return reducedMotion;
52
- };
53
- var useScrollAwareness = () => {
54
- const [scrollState, setScrollState] = (0, import_react.useState)("idle");
55
- const scrollTimeout = (0, import_react.useRef)(null);
56
- (0, import_react.useEffect)(() => {
57
- const handleScroll = () => {
58
- setScrollState("scrolling");
59
- if (scrollTimeout.current) {
60
- clearTimeout(scrollTimeout.current);
61
- }
62
- scrollTimeout.current = setTimeout(() => {
63
- setScrollState("stopped");
64
- setTimeout(() => setScrollState("idle"), 300);
65
- }, 150);
66
- };
67
- window.addEventListener("scroll", handleScroll, { passive: true });
68
- return () => window.removeEventListener("scroll", handleScroll);
69
- }, []);
70
- return scrollState;
71
- };
72
- var useFrustrationDetection = () => {
73
- const [frustrationLevel, setFrustrationLevel] = (0, import_react.useState)(0);
74
- const clickTimestamps = (0, import_react.useRef)([]);
75
- const signals = (0, import_react.useRef)([]);
76
- (0, import_react.useEffect)(() => {
77
- const handleClick = () => {
78
- const now = Date.now();
79
- clickTimestamps.current.push(now);
80
- clickTimestamps.current = clickTimestamps.current.filter((t) => now - t < 500);
81
- if (clickTimestamps.current.length >= 4) {
82
- signals.current.push({ weight: 3, timestamp: now });
83
- clickTimestamps.current = [];
84
- }
85
- };
86
- const handleFormError = () => {
87
- signals.current.push({ weight: 2, timestamp: Date.now() });
88
- };
89
- document.addEventListener("click", handleClick);
90
- document.addEventListener("invalid", handleFormError, true);
91
- const decayInterval = setInterval(() => {
92
- const now = Date.now();
93
- signals.current = signals.current.filter((s) => now - s.timestamp < 3e4);
94
- const totalWeight = signals.current.reduce((sum, s) => sum + s.weight, 0);
95
- setFrustrationLevel(Math.min(10, totalWeight));
96
- }, 1e3);
97
- return () => {
98
- document.removeEventListener("click", handleClick);
99
- document.removeEventListener("invalid", handleFormError, true);
100
- clearInterval(decayInterval);
101
- };
102
- }, []);
103
- return frustrationLevel;
104
- };
105
- var useTimeOnPage = () => {
106
- const [timeOnPage, setTimeOnPage] = (0, import_react.useState)(0);
107
- (0, import_react.useEffect)(() => {
108
- const interval = setInterval(() => {
109
- setTimeOnPage((prev) => prev + 1);
110
- }, 1e3);
111
- return () => clearInterval(interval);
112
- }, []);
113
- return timeOnPage;
114
- };
115
- var useAudioLevel = (isRecording) => {
116
- const [audioLevel, setAudioLevel] = (0, import_react.useState)(0);
117
- const analyserRef = (0, import_react.useRef)(null);
118
- const animationRef = (0, import_react.useRef)();
119
- const streamRef = (0, import_react.useRef)(null);
120
- const audioContextRef = (0, import_react.useRef)(null);
121
- (0, import_react.useEffect)(() => {
122
- if (!isRecording) {
123
- setAudioLevel(0);
124
- if (animationRef.current) {
125
- cancelAnimationFrame(animationRef.current);
126
- animationRef.current = void 0;
127
- }
128
- if (streamRef.current) {
129
- streamRef.current.getTracks().forEach((track) => track.stop());
130
- streamRef.current = null;
131
- }
132
- if (audioContextRef.current) {
133
- audioContextRef.current.close();
134
- audioContextRef.current = null;
135
- }
136
- analyserRef.current = null;
137
- return;
138
- }
139
- const initAudio = async () => {
140
- try {
141
- const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
142
- streamRef.current = stream;
143
- const audioContext = new AudioContext();
144
- audioContextRef.current = audioContext;
145
- const source = audioContext.createMediaStreamSource(stream);
146
- const analyser = audioContext.createAnalyser();
147
- analyser.fftSize = 256;
148
- source.connect(analyser);
149
- analyserRef.current = analyser;
150
- const dataArray = new Uint8Array(analyser.frequencyBinCount);
151
- const updateLevel = () => {
152
- if (!analyserRef.current) return;
153
- analyserRef.current.getByteFrequencyData(dataArray);
154
- const average = dataArray.reduce((a, b) => a + b) / dataArray.length;
155
- setAudioLevel(average / 255);
156
- animationRef.current = requestAnimationFrame(updateLevel);
157
- };
158
- updateLevel();
159
- } catch (error) {
160
- console.error("Failed to access microphone:", error);
161
- }
162
- };
163
- initAudio();
164
- return () => {
165
- if (animationRef.current) {
166
- cancelAnimationFrame(animationRef.current);
167
- }
168
- if (streamRef.current) {
169
- streamRef.current.getTracks().forEach((track) => track.stop());
170
- }
171
- if (audioContextRef.current) {
172
- audioContextRef.current.close();
173
- }
174
- };
175
- }, [isRecording]);
176
- return audioLevel;
177
- };
178
- var springPresets = {
179
- snappy: { type: "spring", stiffness: 500, damping: 30 },
180
- bouncy: { type: "spring", stiffness: 400, damping: 15 },
181
- smooth: { type: "spring", stiffness: 300, damping: 30 },
182
- gentle: { type: "spring", stiffness: 200, damping: 25 }
183
- };
184
- var triggerVariants = {
185
- idle: {
186
- scale: 1,
187
- opacity: 1
188
- },
189
- hover: {
190
- scale: 1.08,
191
- transition: springPresets.bouncy
192
- },
193
- tap: {
194
- scale: 0.95,
195
- transition: springPresets.snappy
196
- },
197
- scrolling: {
198
- scale: 0.85,
199
- opacity: 0.3,
200
- transition: { duration: 0.2 }
201
- },
202
- hidden: {
203
- scale: 0,
204
- opacity: 0,
205
- transition: springPresets.smooth
206
- }
207
- };
208
- var containerVariants = {
209
- trigger: {
210
- width: 56,
211
- height: 56,
212
- borderRadius: 28,
213
- transition: springPresets.smooth
214
- },
215
- expanded: {
216
- width: 360,
217
- height: "auto",
218
- borderRadius: 20,
219
- transition: {
220
- ...springPresets.smooth,
221
- staggerChildren: 0.05,
222
- delayChildren: 0.15
223
- }
224
- }
225
- };
226
- var contentVariants = {
227
- hidden: {
228
- opacity: 0,
229
- y: 20,
230
- scale: 0.95
231
- },
232
- visible: {
233
- opacity: 1,
234
- y: 0,
235
- scale: 1,
236
- transition: springPresets.smooth
237
- },
238
- exit: {
239
- opacity: 0,
240
- y: -10,
241
- scale: 0.95,
242
- transition: { duration: 0.2 }
243
- }
244
- };
245
- var BreathingRing = ({ isActive }) => {
246
- const { reducedMotion } = useWidget();
247
- if (reducedMotion) return null;
248
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
249
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
250
- import_framer_motion.motion.div,
251
- {
252
- animate: {
253
- scale: isActive ? [1, 1.3, 1] : 1,
254
- opacity: isActive ? [0.2, 0.4, 0.2] : 0.2
255
- },
256
- transition: {
257
- duration: 2.5,
258
- repeat: Infinity,
259
- ease: "easeInOut"
260
- },
261
- style: {
262
- position: "absolute",
263
- inset: -16,
264
- borderRadius: "50%",
265
- background: "radial-gradient(circle, var(--widget-primary) 0%, transparent 70%)",
266
- pointerEvents: "none",
267
- filter: "blur(8px)"
268
- }
269
- }
270
- ),
271
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
272
- import_framer_motion.motion.div,
273
- {
274
- className: "fiq-breathing-ring",
275
- animate: {
276
- scale: isActive ? [1, 1.08, 1] : 1,
277
- opacity: isActive ? [0.6, 1, 0.6] : 0.6
278
- },
279
- transition: {
280
- duration: 2,
281
- repeat: Infinity,
282
- ease: "easeInOut"
283
- },
284
- style: {
285
- position: "absolute",
286
- inset: -4,
287
- borderRadius: "50%",
288
- border: "2px solid var(--widget-primary)",
289
- pointerEvents: "none",
290
- opacity: 0.5
291
- }
292
- }
293
- )
294
- ] });
295
- };
296
- var AmbientOrb = ({ audioLevel, isRecording }) => {
297
- const { reducedMotion } = useWidget();
298
- const [particles, setParticles] = (0, import_react.useState)([]);
299
- (0, import_react.useEffect)(() => {
300
- if (!isRecording || audioLevel < 0.3 || reducedMotion) return;
301
- const particleCount = Math.floor(audioLevel * 4);
302
- const newParticles = Array.from({ length: particleCount }, () => ({
303
- id: Math.random().toString(36).slice(2, 11),
304
- x: 70,
305
- y: 70,
306
- angle: Math.random() * Math.PI * 2,
307
- speed: 1 + Math.random() * 3,
308
- size: 2 + Math.random() * 3,
309
- color: Math.random() > 0.5 ? "var(--widget-primary-light)" : "var(--widget-accent)"
310
- }));
311
- setParticles((prev) => [...prev, ...newParticles].slice(-40));
312
- }, [audioLevel, isRecording, reducedMotion]);
313
- (0, import_react.useEffect)(() => {
314
- if (particles.length === 0) return;
315
- const timeout = setTimeout(() => {
316
- setParticles((prev) => prev.slice(1));
317
- }, 100);
318
- return () => clearTimeout(timeout);
319
- }, [particles]);
320
- const orbScale = 1 + audioLevel * 0.2;
321
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "fiq-ambient-orb", style: { position: "relative", width: 140, height: 140, margin: "0 auto" }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { width: 140, height: 140, viewBox: "0 0 140 140", children: [
322
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("defs", { children: [
323
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("radialGradient", { id: "orbGradient", cx: "30%", cy: "30%", children: [
324
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("stop", { offset: "0%", stopColor: "var(--widget-accent-light)" }),
325
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("stop", { offset: "40%", stopColor: "var(--widget-primary)" }),
326
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("stop", { offset: "100%", stopColor: "var(--widget-primary-hover)" })
327
- ] }),
328
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("filter", { id: "orbGlow", x: "-50%", y: "-50%", width: "200%", height: "200%", children: [
329
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("feGaussianBlur", { stdDeviation: "8", result: "blur" }),
330
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("feComposite", { in: "SourceGraphic", in2: "blur", operator: "over" })
331
- ] })
332
- ] }),
333
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
334
- import_framer_motion.motion.circle,
335
- {
336
- cx: 70,
337
- cy: 70,
338
- r: 50,
339
- fill: "none",
340
- stroke: "var(--widget-primary-glow)",
341
- strokeWidth: 2,
342
- animate: {
343
- r: isRecording ? [50, 58, 50] : 50,
344
- opacity: isRecording ? [0.3, 0.6, 0.3] : 0.3
345
- },
346
- transition: {
347
- duration: 2,
348
- repeat: Infinity,
349
- ease: "easeInOut"
350
- }
351
- }
352
- ),
353
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
354
- import_framer_motion.motion.circle,
355
- {
356
- cx: 70,
357
- cy: 70,
358
- r: 40,
359
- fill: "url(#orbGradient)",
360
- filter: "url(#orbGlow)",
361
- animate: { scale: reducedMotion ? 1 : orbScale },
362
- transition: springPresets.snappy,
363
- style: { transformOrigin: "center" }
364
- }
365
- ),
366
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("g", { transform: "translate(70, 70)", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
367
- import_framer_motion.motion.g,
368
- {
369
- animate: {
370
- opacity: isRecording ? [1, 0.7, 1] : 1
371
- },
372
- transition: {
373
- duration: 1,
374
- repeat: isRecording ? Infinity : 0
375
- },
376
- children: [
377
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "-8", y: "-20", width: "16", height: "26", rx: "8", fill: "white" }),
378
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
379
- "path",
380
- {
381
- d: "M-14 0 v6 a14 14 0 0 0 28 0 v-6",
382
- fill: "none",
383
- stroke: "white",
384
- strokeWidth: "3",
385
- strokeLinecap: "round"
386
- }
387
- ),
388
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "0", y1: "20", x2: "0", y2: "28", stroke: "white", strokeWidth: "3", strokeLinecap: "round" }),
389
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "-8", y1: "28", x2: "8", y2: "28", stroke: "white", strokeWidth: "3", strokeLinecap: "round" })
390
- ]
391
- }
392
- ) }),
393
- particles.map((particle) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
394
- import_framer_motion.motion.circle,
395
- {
396
- cx: 70,
397
- cy: 70,
398
- r: particle.size,
399
- fill: particle.color,
400
- initial: { opacity: 0.8, scale: 1 },
401
- animate: {
402
- cx: 70 + Math.cos(particle.angle) * 50,
403
- cy: 70 + Math.sin(particle.angle) * 50,
404
- opacity: 0,
405
- scale: 0.5
406
- },
407
- transition: { duration: 1.5, ease: "easeOut" }
408
- },
409
- particle.id
410
- ))
411
- ] }) });
412
- };
413
- var RecordingTimer = ({
414
- seconds,
415
- maxDuration
416
- }) => {
417
- const minutes = Math.floor(seconds / 60);
418
- const secs = seconds % 60;
419
- const progress = seconds / maxDuration;
420
- const isNearLimit = seconds >= maxDuration - 30;
421
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "fiq-timer", style: { textAlign: "center" }, children: [
422
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
423
- import_framer_motion.motion.div,
424
- {
425
- style: {
426
- fontSize: 36,
427
- fontWeight: 700,
428
- fontFamily: "ui-monospace, monospace",
429
- color: isNearLimit ? "var(--widget-recording)" : "var(--widget-text-primary)"
430
- },
431
- animate: isNearLimit ? { scale: [1, 1.05, 1] } : {},
432
- transition: { duration: 0.5, repeat: isNearLimit ? Infinity : 0 },
433
- children: [
434
- String(minutes).padStart(2, "0"),
435
- ":",
436
- String(secs).padStart(2, "0")
437
- ]
438
- }
439
- ),
440
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
441
- "div",
442
- {
443
- style: {
444
- width: 160,
445
- height: 4,
446
- background: "var(--widget-glass-border)",
447
- borderRadius: 2,
448
- margin: "12px auto",
449
- overflow: "hidden"
450
- },
451
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
452
- import_framer_motion.motion.div,
453
- {
454
- style: {
455
- height: "100%",
456
- background: isNearLimit ? "var(--widget-recording)" : "var(--widget-primary)",
457
- borderRadius: 2
458
- },
459
- initial: { width: 0 },
460
- animate: { width: `${progress * 100}%` },
461
- transition: { duration: 0.5 }
462
- }
463
- )
464
- }
465
- )
466
- ] });
467
- };
468
- var TranscriptionDisplay = ({ text, isLive }) => {
469
- const { reducedMotion } = useWidget();
470
- const [displayedText, setDisplayedText] = (0, import_react.useState)("");
471
- const [cursorVisible, setCursorVisible] = (0, import_react.useState)(true);
472
- (0, import_react.useEffect)(() => {
473
- if (reducedMotion) {
474
- setDisplayedText(text);
475
- return;
476
- }
477
- if (text.length > displayedText.length) {
478
- const timeout = setTimeout(() => {
479
- setDisplayedText(text.slice(0, displayedText.length + 1));
480
- }, 30 + Math.random() * 40);
481
- return () => clearTimeout(timeout);
482
- }
483
- }, [text, displayedText, reducedMotion]);
484
- (0, import_react.useEffect)(() => {
485
- if (!isLive) return;
486
- const interval = setInterval(() => setCursorVisible((v) => !v), 530);
487
- return () => clearInterval(interval);
488
- }, [isLive]);
489
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
490
- "div",
491
- {
492
- className: "fiq-transcription",
493
- style: {
494
- padding: 16,
495
- background: "var(--widget-glass-bg)",
496
- borderRadius: 12,
497
- border: "1px solid var(--widget-glass-border)",
498
- minHeight: 80,
499
- maxHeight: 120,
500
- overflow: "auto"
501
- },
502
- children: [
503
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { style: { color: "var(--widget-text-primary)", fontSize: 14, lineHeight: 1.6, margin: 0 }, children: [
504
- displayedText || /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { color: "var(--widget-text-muted)", fontStyle: "italic" }, children: "Start speaking..." }),
505
- isLive && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
506
- import_framer_motion.motion.span,
507
- {
508
- animate: { opacity: cursorVisible ? 1 : 0 },
509
- style: {
510
- display: "inline-block",
511
- width: 2,
512
- height: "1.2em",
513
- background: "var(--widget-primary)",
514
- marginLeft: 2,
515
- verticalAlign: "text-bottom"
516
- }
517
- }
518
- )
519
- ] }),
520
- isLive && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
521
- import_framer_motion.motion.div,
522
- {
523
- initial: { opacity: 0, y: 5 },
524
- animate: { opacity: 1, y: 0 },
525
- style: {
526
- display: "flex",
527
- alignItems: "center",
528
- gap: 8,
529
- marginTop: 12,
530
- color: "var(--widget-text-secondary)",
531
- fontSize: 12
532
- },
533
- children: [
534
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ListeningDots, {}),
535
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "Listening..." })
536
- ]
537
- }
538
- )
539
- ]
540
- }
541
- );
542
- };
543
- var ListeningDots = () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { display: "flex", gap: 4 }, children: [0, 1, 2].map((i) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
544
- import_framer_motion.motion.span,
545
- {
546
- animate: {
547
- scale: [1, 1.4, 1],
548
- opacity: [0.5, 1, 0.5]
549
- },
550
- transition: {
551
- duration: 1,
552
- repeat: Infinity,
553
- delay: i * 0.15
554
- },
555
- style: {
556
- width: 6,
557
- height: 6,
558
- borderRadius: "50%",
559
- background: "var(--widget-primary)"
560
- }
561
- },
562
- i
563
- )) });
564
- var CategorySelector = ({ categories, selected, onSelect }) => {
565
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "fiq-category-selector", children: [
566
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
567
- "label",
568
- {
569
- style: {
570
- display: "block",
571
- fontSize: 12,
572
- fontWeight: 600,
573
- color: "var(--widget-text-muted)",
574
- marginBottom: 12,
575
- textTransform: "uppercase",
576
- letterSpacing: "0.05em"
577
- },
578
- children: "Category"
579
- }
580
- ),
581
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
582
- "div",
583
- {
584
- style: {
585
- display: "flex",
586
- flexWrap: "wrap",
587
- gap: 8
588
- },
589
- children: categories.map((category) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
590
- import_framer_motion.motion.button,
591
- {
592
- whileHover: { scale: 1.04, y: -1 },
593
- whileTap: { scale: 0.96 },
594
- onClick: () => onSelect(category.id),
595
- style: {
596
- padding: "10px 18px",
597
- background: selected === category.id ? "linear-gradient(145deg, var(--widget-primary) 0%, var(--widget-accent) 100%)" : "var(--widget-glass-bg)",
598
- border: `1.5px solid ${selected === category.id ? "transparent" : "var(--widget-glass-border)"}`,
599
- borderRadius: 24,
600
- cursor: "pointer",
601
- transition: "all 0.2s ease",
602
- boxShadow: selected === category.id ? "0 4px 12px -2px var(--widget-primary-glow)" : "0 2px 4px rgba(0,0,0,0.1)",
603
- position: "relative",
604
- overflow: "hidden"
605
- },
606
- children: [
607
- selected === category.id && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
608
- "div",
609
- {
610
- style: {
611
- position: "absolute",
612
- inset: 0,
613
- background: "linear-gradient(180deg, rgba(255,255,255,0.2) 0%, rgba(255,255,255,0) 50%)",
614
- borderRadius: "inherit",
615
- pointerEvents: "none"
616
- }
617
- }
618
- ),
619
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
620
- "span",
621
- {
622
- style: {
623
- fontSize: 13,
624
- fontWeight: 600,
625
- color: selected === category.id ? "white" : "var(--widget-text-primary)",
626
- position: "relative",
627
- zIndex: 1
628
- },
629
- children: category.label
630
- }
631
- )
632
- ]
633
- },
634
- category.id
635
- ))
636
- }
637
- )
638
- ] });
639
- };
640
- var SuccessCelebration = ({ onComplete }) => {
641
- const { reducedMotion } = useWidget();
642
- const confettiParticles = (0, import_react.useMemo)(
643
- () => reducedMotion ? [] : Array.from({ length: 30 }, (_, i) => ({
644
- id: i,
645
- angle: i / 30 * Math.PI * 2,
646
- distance: 100 + Math.random() * 80,
647
- size: 4 + Math.random() * 6,
648
- color: ["#10b981", "#22d3d3", "#fbbf24", "#f472b6"][Math.floor(Math.random() * 4)],
649
- rotation: Math.random() * 360
650
- })),
651
- [reducedMotion]
652
- );
653
- (0, import_react.useEffect)(() => {
654
- const timer = setTimeout(onComplete, 3e3);
655
- return () => clearTimeout(timer);
656
- }, [onComplete]);
657
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
658
- import_framer_motion.motion.div,
659
- {
660
- initial: { opacity: 0, scale: 0.8 },
661
- animate: { opacity: 1, scale: 1 },
662
- exit: { opacity: 0, scale: 0.8 },
663
- style: {
664
- display: "flex",
665
- flexDirection: "column",
666
- alignItems: "center",
667
- justifyContent: "center",
668
- padding: 40,
669
- textAlign: "center",
670
- position: "relative",
671
- overflow: "hidden"
672
- },
673
- children: [
674
- confettiParticles.map((particle) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
675
- import_framer_motion.motion.div,
676
- {
677
- initial: { x: 0, y: 0, scale: 0, rotate: 0 },
678
- animate: {
679
- x: Math.cos(particle.angle) * particle.distance,
680
- y: Math.sin(particle.angle) * particle.distance + 50,
681
- scale: [0, 1, 1, 0],
682
- rotate: particle.rotation
683
- },
684
- transition: { duration: 1.2, ease: [0.22, 1, 0.36, 1] },
685
- style: {
686
- position: "absolute",
687
- top: "50%",
688
- left: "50%",
689
- width: particle.size,
690
- height: particle.size,
691
- background: particle.color,
692
- borderRadius: Math.random() > 0.5 ? "50%" : 2
693
- }
694
- },
695
- particle.id
696
- )),
697
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_framer_motion.motion.div, { style: { marginBottom: 20 }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { width: 80, height: 80, viewBox: "0 0 80 80", children: [
698
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
699
- import_framer_motion.motion.circle,
700
- {
701
- cx: 40,
702
- cy: 40,
703
- r: 36,
704
- fill: "var(--widget-success)",
705
- initial: { scale: 0 },
706
- animate: { scale: 1 },
707
- transition: springPresets.bouncy
708
- }
709
- ),
710
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
711
- import_framer_motion.motion.path,
712
- {
713
- d: "M24 40 L35 51 L56 28",
714
- fill: "none",
715
- stroke: "white",
716
- strokeWidth: 5,
717
- strokeLinecap: "round",
718
- strokeLinejoin: "round",
719
- initial: { pathLength: 0 },
720
- animate: { pathLength: 1 },
721
- transition: { delay: 0.3, duration: 0.5, ease: "easeOut" }
722
- }
723
- )
724
- ] }) }),
725
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
726
- import_framer_motion.motion.h3,
727
- {
728
- initial: { opacity: 0, y: 20 },
729
- animate: { opacity: 1, y: 0 },
730
- transition: { delay: 0.5 },
731
- style: {
732
- fontSize: 24,
733
- fontWeight: 700,
734
- color: "var(--widget-text-primary)",
735
- margin: 0,
736
- marginBottom: 8
737
- },
738
- children: "Thank you!"
739
- }
740
- ),
741
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
742
- import_framer_motion.motion.p,
743
- {
744
- initial: { opacity: 0, y: 20 },
745
- animate: { opacity: 1, y: 0 },
746
- transition: { delay: 0.6 },
747
- style: {
748
- fontSize: 14,
749
- color: "var(--widget-text-secondary)",
750
- margin: 0
751
- },
752
- children: "Your feedback helps us improve"
753
- }
754
- ),
755
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
756
- import_framer_motion.motion.div,
757
- {
758
- style: {
759
- position: "absolute",
760
- bottom: 20,
761
- left: "50%",
762
- transform: "translateX(-50%)",
763
- width: 100,
764
- height: 3,
765
- background: "var(--widget-glass-border)",
766
- borderRadius: 2,
767
- overflow: "hidden"
768
- },
769
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
770
- import_framer_motion.motion.div,
771
- {
772
- initial: { width: "100%" },
773
- animate: { width: 0 },
774
- transition: { duration: 3, ease: "linear" },
775
- style: {
776
- height: "100%",
777
- background: "var(--widget-primary)"
778
- }
779
- }
780
- )
781
- }
782
- )
783
- ]
784
- }
785
- );
786
- };
787
- var MagneticButton = ({ children, onClick, onPressStart, onPressEnd, variant = "primary", disabled, loading }) => {
788
- const buttonRef = (0, import_react.useRef)(null);
789
- const [magnetOffset, setMagnetOffset] = (0, import_react.useState)({ x: 0, y: 0 });
790
- const handleMouseMove = (e) => {
791
- if (!buttonRef.current || disabled) return;
792
- const rect = buttonRef.current.getBoundingClientRect();
793
- const centerX = rect.left + rect.width / 2;
794
- const centerY = rect.top + rect.height / 2;
795
- setMagnetOffset({
796
- x: (e.clientX - centerX) * 0.08,
797
- y: (e.clientY - centerY) * 0.08
798
- });
799
- };
800
- const handleMouseLeave = () => {
801
- setMagnetOffset({ x: 0, y: 0 });
802
- };
803
- const baseStyles = {
804
- width: "100%",
805
- padding: "16px 28px",
806
- fontSize: 15,
807
- fontWeight: 600,
808
- borderRadius: 14,
809
- border: "none",
810
- cursor: disabled ? "not-allowed" : "pointer",
811
- transition: "all 0.2s ease",
812
- display: "flex",
813
- alignItems: "center",
814
- justifyContent: "center",
815
- gap: 10,
816
- letterSpacing: "0.01em",
817
- position: "relative",
818
- overflow: "hidden"
819
- };
820
- const variantStyles = {
821
- primary: {
822
- background: "linear-gradient(145deg, var(--widget-primary) 0%, var(--widget-accent) 100%)",
823
- color: "white",
824
- boxShadow: `
825
- 0 4px 16px -2px var(--widget-primary-glow),
826
- 0 2px 8px -2px rgba(0, 0, 0, 0.3),
827
- inset 0 1px 1px rgba(255, 255, 255, 0.2)
828
- `
829
- },
830
- secondary: {
831
- background: "var(--widget-glass-bg)",
832
- color: "var(--widget-text-primary)",
833
- border: "1px solid var(--widget-glass-border)",
834
- boxShadow: "0 2px 8px rgba(0, 0, 0, 0.15)"
835
- },
836
- ghost: {
837
- background: "transparent",
838
- color: "var(--widget-text-secondary)"
839
- },
840
- recording: {
841
- background: "linear-gradient(145deg, #ef4444 0%, #dc2626 100%)",
842
- color: "white",
843
- boxShadow: `
844
- 0 4px 20px -2px var(--widget-recording-glow),
845
- 0 0 40px -5px var(--widget-recording-glow),
846
- inset 0 1px 1px rgba(255, 255, 255, 0.2)
847
- `
848
- }
849
- };
850
- const handlePressStart = () => {
851
- if (disabled || loading) return;
852
- onPressStart?.();
853
- };
854
- const handlePressEnd = () => {
855
- if (disabled || loading) return;
856
- onPressEnd?.();
857
- };
858
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
859
- import_framer_motion.motion.button,
860
- {
861
- ref: buttonRef,
862
- onClick,
863
- disabled: disabled || loading,
864
- onMouseMove: handleMouseMove,
865
- onMouseLeave: () => {
866
- handleMouseLeave();
867
- if (onPressEnd) handlePressEnd();
868
- },
869
- onMouseDown: onPressStart ? handlePressStart : void 0,
870
- onMouseUp: onPressEnd ? handlePressEnd : void 0,
871
- onTouchStart: onPressStart ? handlePressStart : void 0,
872
- onTouchEnd: onPressEnd ? handlePressEnd : void 0,
873
- animate: {
874
- x: magnetOffset.x,
875
- y: magnetOffset.y,
876
- opacity: disabled ? 0.5 : 1
877
- },
878
- whileHover: { scale: disabled ? 1 : 1.02, y: -1 },
879
- whileTap: { scale: disabled ? 1 : 0.97 },
880
- transition: springPresets.snappy,
881
- style: { ...baseStyles, ...variantStyles[variant] },
882
- children: [
883
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
884
- "div",
885
- {
886
- style: {
887
- position: "absolute",
888
- inset: 0,
889
- background: "linear-gradient(180deg, rgba(255,255,255,0.15) 0%, rgba(255,255,255,0) 50%)",
890
- borderRadius: "inherit",
891
- pointerEvents: "none"
892
- }
893
- }
894
- ),
895
- loading ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
896
- import_framer_motion.motion.div,
897
- {
898
- animate: { rotate: 360 },
899
- transition: { duration: 1, repeat: Infinity, ease: "linear" },
900
- style: {
901
- width: 20,
902
- height: 20,
903
- border: "2.5px solid rgba(255,255,255,0.3)",
904
- borderTopColor: "white",
905
- borderRadius: "50%"
906
- }
907
- }
908
- ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { position: "relative", zIndex: 1, display: "flex", alignItems: "center", gap: 10 }, children })
909
- ]
910
- }
911
- );
912
- };
913
- var DEFAULT_CATEGORIES = [
914
- { id: "bug", label: "Bug", icon: "" },
915
- { id: "feature", label: "Feature", icon: "" },
916
- { id: "improvement", label: "Improve", icon: "" },
917
- { id: "praise", label: "Praise", icon: "" },
918
- { id: "other", label: "Other", icon: "" }
919
- ];
920
- var PremiumVoiceWidget = ({
921
- position = "bottom-right",
922
- primaryColor = "#10b981",
923
- accentColor = "#22d3d3",
924
- theme = "dark",
925
- categories = DEFAULT_CATEGORIES,
926
- allowVoice = true,
927
- allowText = true,
928
- maxRecordingDuration = 180,
929
- onSubmit,
930
- onOpen,
931
- onClose
932
- }) => {
933
- const [state, setState] = (0, import_react.useState)("idle");
934
- const [isExpanded, setIsExpanded] = (0, import_react.useState)(false);
935
- const [activeTab, setActiveTab] = (0, import_react.useState)(allowVoice ? "voice" : "text");
936
- const [selectedCategory, setSelectedCategory] = (0, import_react.useState)(null);
937
- const [isRecording, setIsRecording] = (0, import_react.useState)(false);
938
- const [recordingSeconds, setRecordingSeconds] = (0, import_react.useState)(0);
939
- const [transcription, setTranscription] = (0, import_react.useState)("");
940
- const [textContent, setTextContent] = (0, import_react.useState)("");
941
- const [isSubmitting, setIsSubmitting] = (0, import_react.useState)(false);
942
- const reducedMotion = useReducedMotion();
943
- const scrollState = useScrollAwareness();
944
- const frustrationLevel = useFrustrationDetection();
945
- const timeOnPage = useTimeOnPage();
946
- const audioLevel = useAudioLevel(isRecording);
947
- const triggerRef = (0, import_react.useRef)(null);
948
- const recordingInterval = (0, import_react.useRef)(null);
949
- const positionStyles = {
950
- "bottom-right": { bottom: 24, right: 24 },
951
- "bottom-left": { bottom: 24, left: 24 },
952
- "top-right": { top: 24, right: 24 },
953
- "top-left": { top: 24, left: 24 }
954
- };
955
- const cssVariables = {
956
- "--widget-primary": primaryColor,
957
- "--widget-primary-hover": adjustColor(primaryColor, -20),
958
- "--widget-primary-light": adjustColor(primaryColor, 30),
959
- "--widget-primary-glow": `${primaryColor}66`,
960
- "--widget-accent": accentColor,
961
- "--widget-accent-light": adjustColor(accentColor, 30),
962
- "--widget-accent-glow": `${accentColor}4d`,
963
- "--widget-glass-bg": theme === "dark" ? "rgba(24, 24, 27, 0.85)" : "rgba(255, 255, 255, 0.85)",
964
- "--widget-glass-border": theme === "dark" ? "rgba(63, 63, 70, 0.5)" : "rgba(0, 0, 0, 0.1)",
965
- "--widget-glass-highlight": theme === "dark" ? "rgba(255, 255, 255, 0.05)" : "rgba(0, 0, 0, 0.02)",
966
- "--widget-text-primary": theme === "dark" ? "#fafafa" : "#18181b",
967
- "--widget-text-secondary": theme === "dark" ? "#a1a1aa" : "#71717a",
968
- "--widget-text-muted": theme === "dark" ? "#71717a" : "#a1a1aa",
969
- "--widget-recording": "#ef4444",
970
- "--widget-recording-glow": "rgba(239, 68, 68, 0.4)",
971
- "--widget-success": "#22c55e",
972
- "--widget-success-glow": "rgba(34, 197, 94, 0.4)",
973
- "--widget-frustrated": "#f97316"
974
- };
975
- const handleOpen = (0, import_react.useCallback)(() => {
976
- setIsExpanded(true);
977
- setState("open");
978
- onOpen?.();
979
- }, [onOpen]);
980
- const handleClose = (0, import_react.useCallback)(() => {
981
- setIsExpanded(false);
982
- setState("idle");
983
- setIsRecording(false);
984
- setRecordingSeconds(0);
985
- setTranscription("");
986
- onClose?.();
987
- }, [onClose]);
988
- const handleStartRecording = (0, import_react.useCallback)(() => {
989
- setIsRecording(true);
990
- setState("recording");
991
- setRecordingSeconds(0);
992
- const samplePhrases = [
993
- "I really like the new dashboard design, ",
994
- "but I think the navigation could be improved. ",
995
- "Sometimes I have trouble finding the settings page."
996
- ];
997
- let phraseIndex = 0;
998
- recordingInterval.current = setInterval(() => {
999
- setRecordingSeconds((prev) => {
1000
- if (prev >= maxRecordingDuration) {
1001
- handleStopRecording();
1002
- return prev;
1003
- }
1004
- return prev + 1;
1005
- });
1006
- if (phraseIndex < samplePhrases.length && Math.random() > 0.7) {
1007
- setTranscription((prev) => prev + samplePhrases[phraseIndex]);
1008
- phraseIndex++;
1009
- }
1010
- }, 1e3);
1011
- }, [maxRecordingDuration]);
1012
- const handleStopRecording = (0, import_react.useCallback)(() => {
1013
- setIsRecording(false);
1014
- setState("open");
1015
- if (recordingInterval.current) {
1016
- clearInterval(recordingInterval.current);
1017
- }
1018
- }, []);
1019
- const handleSubmit = (0, import_react.useCallback)(async () => {
1020
- if (!selectedCategory) return;
1021
- setIsSubmitting(true);
1022
- setState("processing");
1023
- try {
1024
- await onSubmit?.({
1025
- type: activeTab,
1026
- content: activeTab === "voice" ? transcription : textContent,
1027
- category: selectedCategory,
1028
- transcription: activeTab === "voice" ? transcription : void 0
1029
- });
1030
- setState("success");
1031
- } catch (error) {
1032
- setState("error");
1033
- } finally {
1034
- setIsSubmitting(false);
1035
- }
1036
- }, [activeTab, selectedCategory, transcription, textContent, onSubmit]);
1037
- const handleSuccessComplete = (0, import_react.useCallback)(() => {
1038
- handleClose();
1039
- setSelectedCategory(null);
1040
- setTextContent("");
1041
- setTranscription("");
1042
- }, [handleClose]);
1043
- const contextValue = {
1044
- state,
1045
- setState,
1046
- audioLevel,
1047
- isRecording,
1048
- transcription,
1049
- selectedCategory,
1050
- setSelectedCategory,
1051
- frustrationLevel,
1052
- reducedMotion
1053
- };
1054
- const triggerState = (0, import_react.useMemo)(() => {
1055
- if (isExpanded) return "hidden";
1056
- if (scrollState === "scrolling") return "scrolling";
1057
- if (state === "hover") return "hover";
1058
- return "idle";
1059
- }, [isExpanded, scrollState, state]);
1060
- const shouldShowAttentionPulse = timeOnPage === 60 && !isExpanded && frustrationLevel < 3;
1061
- const [showPrompt, setShowPrompt] = (0, import_react.useState)(false);
1062
- const promptMessages = [
1063
- "Help us improve!",
1064
- "Got feedback?",
1065
- "Share your thoughts",
1066
- "We'd love to hear from you"
1067
- ];
1068
- const [promptMessage, setPromptMessage] = (0, import_react.useState)(promptMessages[0]);
1069
- (0, import_react.useEffect)(() => {
1070
- if (isExpanded) return;
1071
- const showTimes = [30, 90, 180];
1072
- if (showTimes.includes(timeOnPage)) {
1073
- setPromptMessage(promptMessages[Math.floor(Math.random() * promptMessages.length)]);
1074
- setShowPrompt(true);
1075
- const timer = setTimeout(() => setShowPrompt(false), 4e3);
1076
- return () => clearTimeout(timer);
1077
- }
1078
- }, [timeOnPage, isExpanded]);
1079
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(WidgetContext.Provider, { value: contextValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
1080
- "div",
1081
- {
1082
- className: "fiq-premium-widget",
1083
- style: {
1084
- ...cssVariables,
1085
- position: "fixed",
1086
- ...positionStyles[position],
1087
- zIndex: 2147483640,
1088
- fontFamily: "system-ui, -apple-system, sans-serif"
1089
- },
1090
- children: [
1091
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_framer_motion.AnimatePresence, { mode: "wait", children: [
1092
- !isExpanded && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
1093
- import_framer_motion.motion.button,
1094
- {
1095
- ref: triggerRef,
1096
- variants: triggerVariants,
1097
- initial: "idle",
1098
- animate: triggerState,
1099
- exit: "hidden",
1100
- whileHover: "hover",
1101
- whileTap: "tap",
1102
- onClick: handleOpen,
1103
- onMouseEnter: () => setState("hover"),
1104
- onMouseLeave: () => setState("idle"),
1105
- "aria-label": "Open feedback widget",
1106
- "aria-expanded": isExpanded,
1107
- style: {
1108
- width: 60,
1109
- height: 60,
1110
- borderRadius: "50%",
1111
- border: "none",
1112
- cursor: "pointer",
1113
- position: "relative",
1114
- background: `linear-gradient(145deg, var(--widget-primary) 0%, var(--widget-accent) 100%)`,
1115
- boxShadow: `
1116
- 0 8px 32px -4px var(--widget-primary-glow),
1117
- 0 4px 16px -2px rgba(0, 0, 0, 0.4),
1118
- inset 0 1px 1px rgba(255, 255, 255, 0.3),
1119
- inset 0 -1px 1px rgba(0, 0, 0, 0.2)
1120
- `
1121
- },
1122
- children: [
1123
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BreathingRing, { isActive: !reducedMotion && triggerState === "idle" }),
1124
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1125
- "div",
1126
- {
1127
- style: {
1128
- position: "absolute",
1129
- inset: 0,
1130
- borderRadius: "50%",
1131
- background: "linear-gradient(180deg, rgba(255,255,255,0.25) 0%, rgba(255,255,255,0) 50%, rgba(0,0,0,0.1) 100%)",
1132
- pointerEvents: "none"
1133
- }
1134
- }
1135
- ),
1136
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1137
- "div",
1138
- {
1139
- style: {
1140
- position: "absolute",
1141
- top: "50%",
1142
- left: "50%",
1143
- transform: "translate(-50%, -50%)",
1144
- zIndex: 1,
1145
- display: "flex",
1146
- alignItems: "center",
1147
- justifyContent: "center"
1148
- },
1149
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
1150
- "svg",
1151
- {
1152
- width: 26,
1153
- height: 26,
1154
- viewBox: "0 0 24 24",
1155
- fill: "none",
1156
- style: { filter: "drop-shadow(0 1px 2px rgba(0,0,0,0.2))" },
1157
- children: [
1158
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1159
- "path",
1160
- {
1161
- d: "M20 2H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h4l4 4 4-4h4c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2z",
1162
- fill: "white",
1163
- opacity: "0.15"
1164
- }
1165
- ),
1166
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1167
- "path",
1168
- {
1169
- d: "M12 3a2.5 2.5 0 0 0-2.5 2.5v5a2.5 2.5 0 0 0 5 0v-5A2.5 2.5 0 0 0 12 3z",
1170
- fill: "white"
1171
- }
1172
- ),
1173
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1174
- "path",
1175
- {
1176
- d: "M16.5 10.5v1a4.5 4.5 0 0 1-9 0v-1",
1177
- stroke: "white",
1178
- strokeWidth: "2",
1179
- strokeLinecap: "round",
1180
- fill: "none"
1181
- }
1182
- ),
1183
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1184
- "path",
1185
- {
1186
- d: "M12 15.5v2.5M9.5 18h5",
1187
- stroke: "white",
1188
- strokeWidth: "2",
1189
- strokeLinecap: "round"
1190
- }
1191
- )
1192
- ]
1193
- }
1194
- )
1195
- }
1196
- ),
1197
- shouldShowAttentionPulse && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1198
- import_framer_motion.motion.div,
1199
- {
1200
- initial: { scale: 1, opacity: 1 },
1201
- animate: { scale: 1.6, opacity: 0 },
1202
- transition: { duration: 1.2, repeat: 3 },
1203
- style: {
1204
- position: "absolute",
1205
- inset: -2,
1206
- borderRadius: "50%",
1207
- border: "2px solid var(--widget-primary)",
1208
- pointerEvents: "none"
1209
- }
1210
- }
1211
- ),
1212
- frustrationLevel >= 5 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1213
- import_framer_motion.motion.div,
1214
- {
1215
- initial: { scale: 0 },
1216
- animate: { scale: 1 },
1217
- style: {
1218
- position: "absolute",
1219
- top: -2,
1220
- right: -2,
1221
- width: 18,
1222
- height: 18,
1223
- borderRadius: "50%",
1224
- background: "linear-gradient(135deg, #ff6b6b 0%, #ee5a5a 100%)",
1225
- border: "2px solid white",
1226
- display: "flex",
1227
- alignItems: "center",
1228
- justifyContent: "center",
1229
- fontSize: 11,
1230
- fontWeight: 700,
1231
- color: "white",
1232
- boxShadow: "0 2px 8px rgba(239, 68, 68, 0.5)"
1233
- },
1234
- children: "!"
1235
- }
1236
- )
1237
- ]
1238
- },
1239
- "trigger"
1240
- ),
1241
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_framer_motion.AnimatePresence, { children: showPrompt && !isExpanded && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
1242
- import_framer_motion.motion.div,
1243
- {
1244
- initial: { opacity: 0, x: 10, scale: 0.9 },
1245
- animate: { opacity: 1, x: 0, scale: 1 },
1246
- exit: { opacity: 0, x: 10, scale: 0.9 },
1247
- transition: springPresets.smooth,
1248
- onClick: handleOpen,
1249
- style: {
1250
- position: "absolute",
1251
- right: 70,
1252
- top: "50%",
1253
- transform: "translateY(-50%)",
1254
- background: "var(--widget-glass-bg)",
1255
- backdropFilter: "blur(12px)",
1256
- WebkitBackdropFilter: "blur(12px)",
1257
- border: "1px solid var(--widget-glass-border)",
1258
- borderRadius: 12,
1259
- padding: "10px 16px",
1260
- boxShadow: "0 4px 20px rgba(0,0,0,0.3)",
1261
- cursor: "pointer",
1262
- whiteSpace: "nowrap"
1263
- },
1264
- children: [
1265
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: {
1266
- fontSize: 13,
1267
- fontWeight: 500,
1268
- color: "var(--widget-text-primary)"
1269
- }, children: promptMessage }),
1270
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1271
- "div",
1272
- {
1273
- style: {
1274
- position: "absolute",
1275
- right: -6,
1276
- top: "50%",
1277
- transform: "translateY(-50%) rotate(45deg)",
1278
- width: 12,
1279
- height: 12,
1280
- background: "var(--widget-glass-bg)",
1281
- borderRight: "1px solid var(--widget-glass-border)",
1282
- borderTop: "1px solid var(--widget-glass-border)"
1283
- }
1284
- }
1285
- )
1286
- ]
1287
- }
1288
- ) })
1289
- ] }),
1290
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_framer_motion.AnimatePresence, { mode: "wait", children: isExpanded && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1291
- import_framer_motion.motion.div,
1292
- {
1293
- variants: containerVariants,
1294
- initial: "trigger",
1295
- animate: "expanded",
1296
- exit: "trigger",
1297
- style: {
1298
- background: theme === "dark" ? "linear-gradient(180deg, rgba(28, 28, 32, 0.95) 0%, rgba(20, 20, 24, 0.98) 100%)" : "linear-gradient(180deg, rgba(255, 255, 255, 0.98) 0%, rgba(248, 248, 250, 0.98) 100%)",
1299
- backdropFilter: "blur(24px) saturate(200%)",
1300
- WebkitBackdropFilter: "blur(24px) saturate(200%)",
1301
- border: "1px solid var(--widget-glass-border)",
1302
- boxShadow: `
1303
- 0 24px 80px -12px rgba(0, 0, 0, 0.6),
1304
- 0 0 1px 0 rgba(255, 255, 255, 0.1) inset,
1305
- 0 1px 0 0 rgba(255, 255, 255, 0.05) inset
1306
- `,
1307
- overflow: "hidden",
1308
- display: "flex",
1309
- flexDirection: "column"
1310
- },
1311
- role: "dialog",
1312
- "aria-modal": "true",
1313
- "aria-labelledby": "widget-title",
1314
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_framer_motion.AnimatePresence, { mode: "wait", children: state === "success" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SuccessCelebration, { onComplete: handleSuccessComplete }, "success") : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
1315
- import_framer_motion.motion.div,
1316
- {
1317
- variants: contentVariants,
1318
- initial: "hidden",
1319
- animate: "visible",
1320
- exit: "exit",
1321
- style: { display: "flex", flexDirection: "column", height: "100%" },
1322
- children: [
1323
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
1324
- "div",
1325
- {
1326
- style: {
1327
- display: "flex",
1328
- justifyContent: "space-between",
1329
- alignItems: "center",
1330
- padding: "20px 24px",
1331
- borderBottom: "1px solid var(--widget-glass-border)",
1332
- background: theme === "dark" ? "linear-gradient(180deg, rgba(255,255,255,0.02) 0%, transparent 100%)" : "linear-gradient(180deg, rgba(0,0,0,0.01) 0%, transparent 100%)"
1333
- },
1334
- children: [
1335
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: 12 }, children: [
1336
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1337
- "div",
1338
- {
1339
- style: {
1340
- width: 36,
1341
- height: 36,
1342
- borderRadius: 10,
1343
- background: "linear-gradient(145deg, var(--widget-primary) 0%, var(--widget-accent) 100%)",
1344
- display: "flex",
1345
- alignItems: "center",
1346
- justifyContent: "center",
1347
- boxShadow: "0 2px 8px -2px var(--widget-primary-glow)"
1348
- },
1349
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { width: 18, height: 18, viewBox: "0 0 24 24", fill: "white", children: [
1350
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M12 3a2.5 2.5 0 0 0-2.5 2.5v5a2.5 2.5 0 0 0 5 0v-5A2.5 2.5 0 0 0 12 3z" }),
1351
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M16.5 10.5v1a4.5 4.5 0 0 1-9 0v-1", stroke: "white", strokeWidth: "2", strokeLinecap: "round", fill: "none" }),
1352
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M12 15.5v2.5M9.5 18h5", stroke: "white", strokeWidth: "2", strokeLinecap: "round" })
1353
- ] })
1354
- }
1355
- ),
1356
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1357
- "h2",
1358
- {
1359
- id: "widget-title",
1360
- style: {
1361
- fontSize: 17,
1362
- fontWeight: 700,
1363
- color: "var(--widget-text-primary)",
1364
- margin: 0,
1365
- letterSpacing: "-0.01em"
1366
- },
1367
- children: "Share Feedback"
1368
- }
1369
- )
1370
- ] }),
1371
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1372
- import_framer_motion.motion.button,
1373
- {
1374
- whileHover: { scale: 1.1, backgroundColor: "var(--widget-glass-border)" },
1375
- whileTap: { scale: 0.9 },
1376
- onClick: handleClose,
1377
- "aria-label": "Close widget",
1378
- style: {
1379
- width: 32,
1380
- height: 32,
1381
- borderRadius: 8,
1382
- border: "none",
1383
- background: "transparent",
1384
- color: "var(--widget-text-secondary)",
1385
- cursor: "pointer",
1386
- display: "flex",
1387
- alignItems: "center",
1388
- justifyContent: "center",
1389
- transition: "background 0.15s ease"
1390
- },
1391
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1392
- "svg",
1393
- {
1394
- width: 18,
1395
- height: 18,
1396
- viewBox: "0 0 24 24",
1397
- fill: "none",
1398
- stroke: "currentColor",
1399
- strokeWidth: 2.5,
1400
- strokeLinecap: "round",
1401
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M18 6L6 18M6 6l12 12" })
1402
- }
1403
- )
1404
- }
1405
- )
1406
- ]
1407
- }
1408
- ),
1409
- allowVoice && allowText && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1410
- "div",
1411
- {
1412
- style: {
1413
- display: "flex",
1414
- padding: "8px 12px",
1415
- gap: 4,
1416
- background: "var(--widget-glass-bg)",
1417
- margin: "0 16px",
1418
- marginTop: 16,
1419
- borderRadius: 12,
1420
- border: "1px solid var(--widget-glass-border)"
1421
- },
1422
- children: ["voice", "text"].map((tab) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
1423
- import_framer_motion.motion.button,
1424
- {
1425
- onClick: () => setActiveTab(tab),
1426
- style: {
1427
- flex: 1,
1428
- padding: "10px 0",
1429
- border: "none",
1430
- background: activeTab === tab ? "linear-gradient(145deg, var(--widget-primary) 0%, var(--widget-accent) 100%)" : "transparent",
1431
- fontSize: 13,
1432
- fontWeight: 600,
1433
- color: activeTab === tab ? "white" : "var(--widget-text-secondary)",
1434
- cursor: "pointer",
1435
- position: "relative",
1436
- borderRadius: 8,
1437
- transition: "all 0.2s ease",
1438
- display: "flex",
1439
- alignItems: "center",
1440
- justifyContent: "center",
1441
- gap: 6,
1442
- boxShadow: activeTab === tab ? "0 2px 8px -2px var(--widget-primary-glow)" : "none"
1443
- },
1444
- whileHover: { scale: activeTab === tab ? 1 : 1.02 },
1445
- whileTap: { scale: 0.98 },
1446
- children: [
1447
- tab === "voice" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { width: 14, height: 14, viewBox: "0 0 24 24", fill: "currentColor", children: [
1448
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M12 3a2.5 2.5 0 0 0-2.5 2.5v5a2.5 2.5 0 0 0 5 0v-5A2.5 2.5 0 0 0 12 3z" }),
1449
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M16.5 10.5v1a4.5 4.5 0 0 1-9 0v-1", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", fill: "none" })
1450
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { width: 14, height: 14, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M4 6h16M4 12h16M4 18h10" }) }),
1451
- tab === "voice" ? "Voice" : "Text"
1452
- ]
1453
- },
1454
- tab
1455
- ))
1456
- }
1457
- ),
1458
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { padding: "20px 24px" }, children: [
1459
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { marginBottom: 24 }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1460
- CategorySelector,
1461
- {
1462
- categories,
1463
- selected: selectedCategory,
1464
- onSelect: setSelectedCategory
1465
- }
1466
- ) }),
1467
- activeTab === "voice" && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { textAlign: "center" }, children: [
1468
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
1469
- "div",
1470
- {
1471
- style: {
1472
- background: "var(--widget-glass-bg)",
1473
- borderRadius: 16,
1474
- padding: "24px 16px",
1475
- border: "1px solid var(--widget-glass-border)",
1476
- marginBottom: 16
1477
- },
1478
- children: [
1479
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AmbientOrb, { audioLevel, isRecording }),
1480
- isRecording && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1481
- RecordingTimer,
1482
- {
1483
- seconds: recordingSeconds,
1484
- maxDuration: maxRecordingDuration
1485
- }
1486
- ),
1487
- !isRecording && recordingSeconds === 0 && !transcription && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1488
- "p",
1489
- {
1490
- style: {
1491
- color: "var(--widget-text-muted)",
1492
- fontSize: 13,
1493
- marginTop: 12,
1494
- marginBottom: 0
1495
- },
1496
- children: "Click Record to start"
1497
- }
1498
- )
1499
- ]
1500
- }
1501
- ),
1502
- (isRecording || transcription) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { marginBottom: 16 }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1503
- TranscriptionDisplay,
1504
- {
1505
- text: transcription,
1506
- isLive: isRecording
1507
- }
1508
- ) }),
1509
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1510
- MagneticButton,
1511
- {
1512
- onClick: isRecording ? handleStopRecording : handleStartRecording,
1513
- variant: isRecording ? "recording" : "primary",
1514
- children: isRecording ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
1515
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1516
- import_framer_motion.motion.div,
1517
- {
1518
- animate: { scale: [1, 1.2, 1] },
1519
- transition: { duration: 1, repeat: Infinity },
1520
- style: {
1521
- width: 10,
1522
- height: 10,
1523
- borderRadius: 2,
1524
- background: "white"
1525
- }
1526
- }
1527
- ),
1528
- "Stop Recording"
1529
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
1530
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { width: 16, height: 16, viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M12 3a2.5 2.5 0 0 0-2.5 2.5v5a2.5 2.5 0 0 0 5 0v-5A2.5 2.5 0 0 0 12 3z" }) }),
1531
- transcription ? "Record Again" : "Record"
1532
- ] })
1533
- }
1534
- )
1535
- ] }),
1536
- activeTab === "text" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
1537
- "div",
1538
- {
1539
- style: {
1540
- position: "relative",
1541
- background: "var(--widget-glass-bg)",
1542
- border: "1px solid var(--widget-glass-border)",
1543
- borderRadius: 14,
1544
- overflow: "hidden"
1545
- },
1546
- children: [
1547
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1548
- "textarea",
1549
- {
1550
- value: textContent,
1551
- onChange: (e) => setTextContent(e.target.value),
1552
- placeholder: "Share your thoughts, ideas, or feedback...",
1553
- style: {
1554
- width: "100%",
1555
- minHeight: 140,
1556
- padding: 16,
1557
- fontSize: 14,
1558
- lineHeight: 1.7,
1559
- color: "var(--widget-text-primary)",
1560
- background: "transparent",
1561
- border: "none",
1562
- resize: "none",
1563
- fontFamily: "inherit",
1564
- outline: "none"
1565
- }
1566
- }
1567
- ),
1568
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1569
- "div",
1570
- {
1571
- style: {
1572
- display: "flex",
1573
- justifyContent: "flex-end",
1574
- padding: "8px 12px",
1575
- borderTop: "1px solid var(--widget-glass-border)",
1576
- background: theme === "dark" ? "rgba(0,0,0,0.2)" : "rgba(0,0,0,0.02)"
1577
- },
1578
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
1579
- "span",
1580
- {
1581
- style: {
1582
- fontSize: 11,
1583
- fontWeight: 500,
1584
- color: textContent.length > 4500 ? "var(--widget-recording)" : "var(--widget-text-muted)"
1585
- },
1586
- children: [
1587
- textContent.length.toLocaleString(),
1588
- " / 5,000"
1589
- ]
1590
- }
1591
- )
1592
- }
1593
- )
1594
- ]
1595
- }
1596
- ) })
1597
- ] }),
1598
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1599
- "div",
1600
- {
1601
- style: {
1602
- padding: "16px 24px 20px",
1603
- borderTop: "1px solid var(--widget-glass-border)",
1604
- background: theme === "dark" ? "linear-gradient(180deg, transparent 0%, rgba(0,0,0,0.2) 100%)" : "linear-gradient(180deg, transparent 0%, rgba(0,0,0,0.02) 100%)"
1605
- },
1606
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
1607
- MagneticButton,
1608
- {
1609
- onClick: handleSubmit,
1610
- disabled: !selectedCategory || activeTab === "voice" && !transcription || activeTab === "text" && !textContent.trim(),
1611
- loading: isSubmitting,
1612
- children: [
1613
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { width: 16, height: 16, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.5", strokeLinecap: "round", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z" }) }),
1614
- "Submit Feedback"
1615
- ]
1616
- }
1617
- )
1618
- }
1619
- )
1620
- ]
1621
- },
1622
- "content"
1623
- ) })
1624
- },
1625
- "modal"
1626
- ) }),
1627
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { "aria-live": "polite", className: "sr-only", style: { position: "absolute", width: 1, height: 1, overflow: "hidden" }, children: [
1628
- isRecording && "Recording started. Speak now.",
1629
- !isRecording && transcription && `Transcription complete.`,
1630
- state === "success" && "Feedback submitted successfully."
1631
- ] })
1632
- ]
1633
- }
1634
- ) });
1635
- };
1636
- function adjustColor(color, amount) {
1637
- const hex = color.replace("#", "");
1638
- const num = parseInt(hex, 16);
1639
- const r = Math.min(255, Math.max(0, (num >> 16) + amount));
1640
- const g = Math.min(255, Math.max(0, (num >> 8 & 255) + amount));
1641
- const b = Math.min(255, Math.max(0, (num & 255) + amount));
1642
- return `#${(r << 16 | g << 8 | b).toString(16).padStart(6, "0")}`;
1643
- }
1644
-
1645
- // src/index.tsx
1646
- function IntentAIWidget({
1647
- apiKey,
1648
- apiUrl,
1649
- widgetUrl,
1650
- position = "bottom-right",
1651
- theme = "light",
1652
- primaryColor,
1653
- allowVoice = true,
1654
- allowText = true,
1655
- allowScreenshot = true,
1656
- customMetadata,
1657
- user,
1658
- onOpen: _onOpen,
1659
- onClose: _onClose,
1660
- onFeedbackSubmitted: _onFeedbackSubmitted,
1661
- onError
1662
- }) {
1663
- const widgetRef = (0, import_react2.useRef)(null);
1664
- const scriptLoadedRef = (0, import_react2.useRef)(false);
1665
- const initWidget = (0, import_react2.useCallback)(() => {
1666
- if (!window.FeedbackIQ || widgetRef.current) return;
1667
- try {
1668
- widgetRef.current = new window.FeedbackIQ({
1669
- apiKey,
1670
- apiUrl,
1671
- widgetUrl,
1672
- position,
1673
- theme,
1674
- primaryColor,
1675
- allowVoice,
1676
- allowText,
1677
- allowScreenshot,
1678
- customMetadata,
1679
- user
1680
- });
1681
- } catch (error) {
1682
- onError?.(error instanceof Error ? error : new Error("Failed to initialize widget"));
1683
- }
1684
- void _onOpen;
1685
- void _onClose;
1686
- void _onFeedbackSubmitted;
1687
- }, [apiKey, apiUrl, widgetUrl, position, theme, primaryColor, allowVoice, allowText, allowScreenshot, customMetadata, user, onError]);
1688
- (0, import_react2.useEffect)(() => {
1689
- if (!widgetUrl) {
1690
- onError?.(new Error("widgetUrl is required for IntentAIWidget"));
1691
- return;
1692
- }
1693
- if (window.FeedbackIQ) {
1694
- initWidget();
1695
- return;
1696
- }
1697
- if (scriptLoadedRef.current) return;
1698
- const existingScript = document.querySelector(`script[src="${widgetUrl}"]`);
1699
- if (existingScript) {
1700
- existingScript.addEventListener("load", initWidget);
1701
- return;
1702
- }
1703
- scriptLoadedRef.current = true;
1704
- const script = document.createElement("script");
1705
- script.src = widgetUrl;
1706
- script.async = true;
1707
- script.onload = initWidget;
1708
- script.onerror = () => {
1709
- onError?.(new Error("Failed to load Intent AI widget script"));
1710
- };
1711
- document.head.appendChild(script);
1712
- return () => {
1713
- if (widgetRef.current) {
1714
- widgetRef.current.destroy();
1715
- widgetRef.current = null;
1716
- }
1717
- };
1718
- }, [initWidget, onError, widgetUrl]);
1719
- (0, import_react2.useEffect)(() => {
1720
- if (widgetRef.current && user) {
1721
- widgetRef.current.identify(user);
1722
- }
1723
- }, [user]);
1724
- (0, import_react2.useEffect)(() => {
1725
- if (widgetRef.current && customMetadata) {
1726
- widgetRef.current.setMetadata(customMetadata);
1727
- }
1728
- }, [customMetadata]);
1729
- return null;
1730
- }
1731
- function useIntentAI() {
1732
- const open = (0, import_react2.useCallback)(() => {
1733
- const widget = document.getElementById("feedbackiq-widget");
1734
- if (widget) {
1735
- const trigger = widget.shadowRoot?.querySelector(".fiq-trigger");
1736
- trigger?.click();
1737
- }
1738
- }, []);
1739
- const close = (0, import_react2.useCallback)(() => {
1740
- const widget = document.getElementById("feedbackiq-widget");
1741
- if (widget) {
1742
- const closeBtn = widget.shadowRoot?.querySelector(".fiq-close");
1743
- closeBtn?.click();
1744
- }
1745
- }, []);
1746
- const identify = (0, import_react2.useCallback)((user) => {
1747
- if (window.IntentAI?.widget) {
1748
- window.IntentAI.widget.identify(user);
1749
- }
1750
- }, []);
1751
- const setMetadata = (0, import_react2.useCallback)((metadata) => {
1752
- if (window.IntentAI?.widget) {
1753
- window.IntentAI.widget.setMetadata(metadata);
1754
- }
1755
- }, []);
1756
- return { open, close, identify, setMetadata };
1757
- }
1758
- var index_default = IntentAIWidget;
1759
- // Annotate the CommonJS export names for ESM import in node:
1760
- 0 && (module.exports = {
1761
- IntentAIWidget,
1762
- PremiumVoiceWidget,
1763
- useIntentAI
1764
- });
1
+ 'use strict';var $=require('react'),jsxRuntime=require('react/jsx-runtime');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var $__default=/*#__PURE__*/_interopDefault($);var Y="https://intetnt-ai-v1-web-app-production.up.railway.app/widget/v1.js",k=null,E=false;function H(e){return E&&window.IntentAI?Promise.resolve():k||(k=new Promise((t,r)=>{if(document.querySelector(`script[src^="${Y}"]`)){window.IntentAI?(E=true,t()):window.addEventListener("intentai:ready",()=>{E=true,t();},{once:true});return}let n=document.createElement("script");n.src=Y,n.async=true,n.id="intentai-widget-script",n.setAttribute("data-api-key",e.apiKey),n.onload=()=>{window.addEventListener("intentai:ready",()=>{E=true,t();},{once:true}),setTimeout(()=>{!E&&window.IntentAI&&(E=true,t());},3e3);},n.onerror=()=>{k=null,r(new Error("Failed to load Intent AI widget script"));},document.head.appendChild(n);}),k)}var L={};var G=$.createContext(null),v=typeof window!="undefined";function j(e){if(e)return e;if(typeof process!="undefined"&&process.env){let t=process.env.NEXT_PUBLIC_INTENT_AI_KEY||process.env.REACT_APP_INTENT_AI_KEY||process.env.VITE_INTENT_AI_KEY;if(t)return t}try{if(typeof L!="undefined"&&L.env)return L.env.VITE_INTENT_AI_KEY}catch(t){}}function ee({children:e,apiKey:t,user:r,position:n="bottom-right",theme:p="auto",primaryColor:s,autoShow:a=true,metadata:I,onReady:f,onOpen:x,onClose:m,onSubmit:O,onError:C}){let[b,z]=$.useState(false),[N,F]=$.useState(null),R=$.useRef(r),l=$.useRef({onReady:f,onOpen:x,onClose:m,onSubmit:O,onError:C});l.current={onReady:f,onOpen:x,onClose:m,onSubmit:O,onError:C};let w=$.useMemo(()=>j(t),[t]);$.useEffect(()=>{w&&!w.startsWith("pk_")&&console.error('[IntentAI] Invalid API key format. Public keys should start with "pk_". Never use secret keys (sk_*) in client-side code.');},[w]),$.useEffect(()=>{if(!v)return;if(!w){console.warn("[IntentAI] No API key provided. Set the apiKey prop or NEXT_PUBLIC_INTENT_AI_KEY environment variable.");return}window.IntentAIConfig={apiKey:w,position:n,theme:p,primaryColor:s,autoShow:a,metadata:I};let d=()=>{var i,o,c;z(true),(o=(i=l.current).onReady)==null||o.call(i),R.current&&((c=window.IntentAI)==null||c.identify(R.current));},y=()=>{var i,o;(o=(i=l.current).onOpen)==null||o.call(i);},A=()=>{var i,o;(o=(i=l.current).onClose)==null||o.call(i);},W=i=>{var o,c;(c=(o=l.current).onSubmit)==null||c.call(o,i.detail);},V=i=>{var o,c;F(i.detail),(c=(o=l.current).onError)==null||c.call(o,i.detail);};return window.addEventListener("intentai:ready",d),window.addEventListener("intentai:open",y),window.addEventListener("intentai:close",A),window.addEventListener("intentai:submit",W),window.addEventListener("intentai:error",V),H({apiKey:w}).catch(i=>{var o,c;F(i),(c=(o=l.current).onError)==null||c.call(o,i);}),()=>{window.removeEventListener("intentai:ready",d),window.removeEventListener("intentai:open",y),window.removeEventListener("intentai:close",A),window.removeEventListener("intentai:submit",W),window.removeEventListener("intentai:error",V);}},[w,n,p,s,a,I]),$.useEffect(()=>{R.current=r,v&&b&&r&&window.IntentAI&&window.IntentAI.identify(r);},[r,b]);let M=$.useCallback(d=>{v&&(window.IntentAI?window.IntentAI.open(d):console.warn("[IntentAI] Widget not ready. Call will be ignored."));},[]),U=$.useCallback(()=>{var d;v&&((d=window.IntentAI)==null||d.close());},[]),B=$.useCallback(d=>{v&&(window.IntentAI?window.IntentAI.identify(d):R.current=d);},[]),K=$.useCallback((d,y)=>{var A;v&&((A=window.IntentAI)==null||A.track(d,y));},[]),S=$.useCallback(d=>{var y;v&&((y=window.IntentAI)==null||y.setMetadata(d));},[]),J=$.useMemo(()=>({isReady:b,error:N,open:M,close:U,identify:B,track:K,setMetadata:S}),[b,N,M,U,B,K,S]);return jsxRuntime.jsx(G.Provider,{value:J,children:e})}function u(){let e=$.useContext(G);if(!e)throw new Error('useIntentAI must be used within an IntentAIProvider. Wrap your app with <IntentAIProvider apiKey="pk_...">.');return e}function te(e){let{identify:t,isReady:r}=u();$.useEffect(()=>{r&&(e!=null&&e.id)&&t(e);},[r,e==null?void 0:e.id,e==null?void 0:e.email,e==null?void 0:e.name,t,e]);}var oe=$.forwardRef(function({openOptions:t,children:r="Feedback",onClick:n,disabled:p,...s},a){let{open:I,isReady:f}=u();return jsxRuntime.jsx("button",{ref:a,type:"button",onClick:m=>{n==null||n(m),m.defaultPrevented||I(t);},disabled:p||!f,"aria-label":"Open feedback",...s,children:r})});function ie({children:e,openOptions:t}){let{open:r,isReady:n,error:p}=u(),s=a=>{r(a||t);};return typeof e=="function"?e({open:s,isReady:n,error:p}):$__default.default.cloneElement(e,{onClick:a=>{var I,f;(f=(I=e.props).onClick)==null||f.call(I,a),a.defaultPrevented||s();},disabled:e.props.disabled||!n})}function de({user:e,children:t}){let{identify:r,isReady:n}=u();return $.useEffect(()=>{n&&(e!=null&&e.id)&&r(e);},[n,e,r]),jsxRuntime.jsx(jsxRuntime.Fragment,{children:t})}function ae({metadata:e,children:t}){let{setMetadata:r,isReady:n}=u();return $.useEffect(()=>{n&&e&&r(e);},[n,e,r]),jsxRuntime.jsx(jsxRuntime.Fragment,{children:t})}function se({event:e,properties:t,trigger:r="mount",children:n}){let{track:p,isReady:s}=u(),a=$__default.default.useRef(false);return $.useEffect(()=>{r==="mount"&&s&&!a.current&&(p(e,t),a.current=true);},[s,e,t,p,r]),r==="render"&&s&&p(e,t),jsxRuntime.jsx(jsxRuntime.Fragment,{children:n})}
2
+ exports.FeedbackButton=oe;exports.FeedbackTrigger=ie;exports.IdentifyUser=de;exports.IntentAIProvider=ee;exports.SetMetadata=ae;exports.TrackEvent=se;exports.useIdentify=te;exports.useIntentAI=u;