@lettuceai/crisp 1.3.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/dist/components/Composer.d.ts +4 -1
- package/dist/index.js +41 -40
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -10,6 +10,8 @@ export interface ComposerMic {
|
|
|
10
10
|
transcribing?: boolean;
|
|
11
11
|
elapsedMs: number;
|
|
12
12
|
analyser: AnalyserNode | null;
|
|
13
|
+
/** The input level from 0 to 1, for a recorder that has no `analyser` in the page. */
|
|
14
|
+
level?: number;
|
|
13
15
|
onStart: () => void;
|
|
14
16
|
onStop: () => void;
|
|
15
17
|
onCancel: () => void;
|
|
@@ -42,8 +44,9 @@ export interface ComposerProps {
|
|
|
42
44
|
}
|
|
43
45
|
export declare function Composer({ value, onChange, onSend, onStop, onContinue, onSendAsSystem, onAttach, attachments, onRemoveAttachment, mic, sending, disabled, placeholder, enterSends, notice, topSlot, className, }: ComposerProps): import("react").JSX.Element;
|
|
44
46
|
/** Live waveform while recording. Same sampling as the app; drawn in tokens. */
|
|
45
|
-
export declare function RecordingWave({ elapsedMs, analyser, frozen }: {
|
|
47
|
+
export declare function RecordingWave({ elapsedMs, analyser, level, frozen }: {
|
|
46
48
|
elapsedMs: number;
|
|
47
49
|
analyser: AnalyserNode | null;
|
|
50
|
+
level?: number;
|
|
48
51
|
frozen?: boolean;
|
|
49
52
|
}): import("react").JSX.Element;
|
package/dist/index.js
CHANGED
|
@@ -3172,6 +3172,7 @@ function hr({ value: e, onChange: t, onSend: n, onStop: r, onContinue: i, onSend
|
|
|
3172
3172
|
w && u ? /* @__PURE__ */ U(_r, {
|
|
3173
3173
|
elapsedMs: u.elapsedMs,
|
|
3174
3174
|
analyser: u.analyser,
|
|
3175
|
+
level: u.level,
|
|
3175
3176
|
frozen: u.transcribing
|
|
3176
3177
|
}) : /* @__PURE__ */ U("textarea", {
|
|
3177
3178
|
ref: S,
|
|
@@ -3254,72 +3255,72 @@ function gr(e) {
|
|
|
3254
3255
|
let t = Math.max(0, Math.floor(e / 1e3));
|
|
3255
3256
|
return `${Math.floor(t / 60)}:${String(t % 60).padStart(2, "0")}`;
|
|
3256
3257
|
}
|
|
3257
|
-
function _r({ elapsedMs: e, analyser: t,
|
|
3258
|
-
let { strings:
|
|
3258
|
+
function _r({ elapsedMs: e, analyser: t, level: n, frozen: r = !1 }) {
|
|
3259
|
+
let { strings: i } = q(), a = p(null), o = p(null), s = p([]), c = p(null), [u, d] = m({
|
|
3259
3260
|
w: 0,
|
|
3260
3261
|
h: 0
|
|
3261
|
-
});
|
|
3262
|
-
return l(() => {
|
|
3263
|
-
let e =
|
|
3262
|
+
}), f = p(n);
|
|
3263
|
+
return f.current = n, l(() => {
|
|
3264
|
+
let e = a.current;
|
|
3264
3265
|
if (!e) return;
|
|
3265
3266
|
let t = () => {
|
|
3266
3267
|
let t = e.getBoundingClientRect();
|
|
3267
|
-
|
|
3268
|
+
d({
|
|
3268
3269
|
w: Math.floor(t.width),
|
|
3269
3270
|
h: Math.floor(t.height)
|
|
3270
3271
|
});
|
|
3271
3272
|
}, n = new ResizeObserver(t);
|
|
3272
3273
|
return n.observe(e), t(), () => n.disconnect();
|
|
3273
3274
|
}, []), l(() => {
|
|
3274
|
-
|
|
3275
|
+
s.current = [], c.current = t ? new Uint8Array(new ArrayBuffer(t.fftSize)) : null;
|
|
3275
3276
|
}, [t]), l(() => {
|
|
3276
|
-
let e =
|
|
3277
|
-
if (!e ||
|
|
3278
|
-
let
|
|
3279
|
-
e.width = Math.floor(
|
|
3280
|
-
let
|
|
3281
|
-
if (!
|
|
3282
|
-
|
|
3283
|
-
let
|
|
3284
|
-
if (!
|
|
3285
|
-
t.getByteTimeDomainData(
|
|
3277
|
+
let e = o.current;
|
|
3278
|
+
if (!e || u.w <= 0) return;
|
|
3279
|
+
let n = window.devicePixelRatio || 1, i = u.h || 20;
|
|
3280
|
+
e.width = Math.floor(u.w * n), e.height = Math.floor(i * n);
|
|
3281
|
+
let a = e.getContext("2d");
|
|
3282
|
+
if (!a) return;
|
|
3283
|
+
a.scale(n, n);
|
|
3284
|
+
let l = getComputedStyle(e).color, d = Math.ceil(u.w / 4) + 4, p = 0, m = 0, h = (e) => {
|
|
3285
|
+
if (!r && t && c.current && e - p >= 50) {
|
|
3286
|
+
t.getByteTimeDomainData(c.current);
|
|
3286
3287
|
let n = 0;
|
|
3287
|
-
for (let e of
|
|
3288
|
+
for (let e of c.current) {
|
|
3288
3289
|
let t = (e - 128) / 128;
|
|
3289
3290
|
n += t * t;
|
|
3290
3291
|
}
|
|
3291
|
-
let r = Math.sqrt(n /
|
|
3292
|
-
|
|
3292
|
+
let r = Math.sqrt(n / c.current.length);
|
|
3293
|
+
s.current.push(Math.min(1, (r * 18) ** .5)), s.current.length > d && s.current.splice(0, s.current.length - d), p = e;
|
|
3294
|
+
} else !r && !t && f.current !== void 0 && e - p >= 50 && (s.current.push(Math.min(1, Math.max(0, f.current ** .5))), s.current.length > d && s.current.splice(0, s.current.length - d), p = e);
|
|
3295
|
+
a.clearRect(0, 0, u.w, i);
|
|
3296
|
+
let n = s.current;
|
|
3297
|
+
for (let e = Math.max(0, n.length - d); e < n.length; e++) {
|
|
3298
|
+
let t = n.length - 1 - e, r = u.w - 2 - t * 4;
|
|
3299
|
+
if (r + 2 < 0) break;
|
|
3300
|
+
let o = Math.max(3, n[e] * (i - 2));
|
|
3301
|
+
a.globalAlpha = .95 - t / Math.max(1, d - 1) * .35, a.fillStyle = l, a.fillRect(r, i / 2 - o / 2, 2, o);
|
|
3293
3302
|
}
|
|
3294
|
-
|
|
3295
|
-
let r = o.current;
|
|
3296
|
-
for (let e = Math.max(0, r.length - d); e < r.length; e++) {
|
|
3297
|
-
let t = r.length - 1 - e, n = c.w - 2 - t * 4;
|
|
3298
|
-
if (n + 2 < 0) break;
|
|
3299
|
-
let a = Math.max(3, r[e] * (i - 2));
|
|
3300
|
-
l.globalAlpha = .95 - t / Math.max(1, d - 1) * .35, l.fillStyle = u, l.fillRect(n, i / 2 - a / 2, 2, a);
|
|
3301
|
-
}
|
|
3302
|
-
p = window.requestAnimationFrame(m);
|
|
3303
|
+
m = window.requestAnimationFrame(h);
|
|
3303
3304
|
};
|
|
3304
|
-
return
|
|
3305
|
+
return m = window.requestAnimationFrame(h), () => window.cancelAnimationFrame(m);
|
|
3305
3306
|
}, [
|
|
3306
3307
|
t,
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3308
|
+
u.w,
|
|
3309
|
+
u.h,
|
|
3310
|
+
r
|
|
3310
3311
|
]), /* @__PURE__ */ W("div", {
|
|
3311
3312
|
className: "flex min-h-[var(--composer-row)] min-w-0 flex-1 items-center gap-2.5 px-2",
|
|
3312
3313
|
role: "status",
|
|
3313
3314
|
"aria-live": "polite",
|
|
3314
|
-
"aria-label":
|
|
3315
|
+
"aria-label": r ? i.composerTranscribing : i.composerRecording(gr(e)),
|
|
3315
3316
|
children: [
|
|
3316
3317
|
/* @__PURE__ */ W("span", {
|
|
3317
3318
|
className: "relative flex h-2 w-2 shrink-0",
|
|
3318
3319
|
"aria-hidden": "true",
|
|
3319
|
-
children: [!
|
|
3320
|
+
children: [!r && /* @__PURE__ */ U("span", { className: "absolute inline-flex h-full w-full animate-ping rounded-full bg-danger opacity-60" }), /* @__PURE__ */ U("span", { className: G("relative inline-flex h-2 w-2 rounded-full", r ? "bg-fg-3" : "bg-danger") })]
|
|
3320
3321
|
}),
|
|
3321
3322
|
/* @__PURE__ */ W("div", {
|
|
3322
|
-
ref:
|
|
3323
|
+
ref: a,
|
|
3323
3324
|
className: "relative h-5 min-w-0 flex-1 overflow-hidden text-fg",
|
|
3324
3325
|
style: {
|
|
3325
3326
|
maskImage: "linear-gradient(to right, transparent, black 40px)",
|
|
@@ -3329,9 +3330,9 @@ function _r({ elapsedMs: e, analyser: t, frozen: n = !1 }) {
|
|
|
3329
3330
|
"aria-hidden": "true",
|
|
3330
3331
|
className: "absolute inset-x-0 top-1/2 h-px -translate-y-1/2 bg-line-2"
|
|
3331
3332
|
}), /* @__PURE__ */ U("canvas", {
|
|
3332
|
-
ref:
|
|
3333
|
+
ref: o,
|
|
3333
3334
|
className: "relative block h-full w-full",
|
|
3334
|
-
style: { width:
|
|
3335
|
+
style: { width: u.w || void 0 }
|
|
3335
3336
|
})]
|
|
3336
3337
|
}),
|
|
3337
3338
|
/* @__PURE__ */ U("span", {
|
|
@@ -3483,10 +3484,10 @@ function Tr({ open: e, onClose: t, title: n, description: r, leftAction: i, righ
|
|
|
3483
3484
|
})
|
|
3484
3485
|
}),
|
|
3485
3486
|
/* @__PURE__ */ W("div", {
|
|
3486
|
-
className: G("flex items-
|
|
3487
|
+
className: G("flex items-center gap-2 px-4", I ? "pb-3 pt-1.5" : "py-4"),
|
|
3487
3488
|
children: [
|
|
3488
3489
|
i && /* @__PURE__ */ U("div", {
|
|
3489
|
-
className: "shrink-0
|
|
3490
|
+
className: "shrink-0",
|
|
3490
3491
|
children: i
|
|
3491
3492
|
}),
|
|
3492
3493
|
/* @__PURE__ */ W("div", {
|