@refraction-ui/react 0.4.0 → 0.4.2
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.cjs +854 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +809 -4
- package/dist/index.js.map +1 -1
- package/package.json +3 -1
package/dist/index.cjs
CHANGED
|
@@ -7114,6 +7114,811 @@ var VideoPlayer = React11__namespace.forwardRef(
|
|
|
7114
7114
|
);
|
|
7115
7115
|
VideoPlayer.displayName = "VideoPlayer";
|
|
7116
7116
|
|
|
7117
|
+
// ../voice-pill/dist/index.js
|
|
7118
|
+
var DEFAULT_VOICE_PILL_SPEAKER = "ai";
|
|
7119
|
+
var DEFAULT_VOICE_PILL_POSITION = "bottom-center";
|
|
7120
|
+
function formatNumber(value) {
|
|
7121
|
+
return Number(value.toFixed(3)).toString();
|
|
7122
|
+
}
|
|
7123
|
+
function getRawSpeaker(speaker) {
|
|
7124
|
+
const value = String(speaker ?? DEFAULT_VOICE_PILL_SPEAKER).trim();
|
|
7125
|
+
return value.length > 0 ? value : DEFAULT_VOICE_PILL_SPEAKER;
|
|
7126
|
+
}
|
|
7127
|
+
function clampVoicePillIntensity(intensity = 0) {
|
|
7128
|
+
const value = Number(intensity);
|
|
7129
|
+
if (!Number.isFinite(value)) {
|
|
7130
|
+
return 0;
|
|
7131
|
+
}
|
|
7132
|
+
return Math.min(1, Math.max(0, value));
|
|
7133
|
+
}
|
|
7134
|
+
function getVoicePillSpeakerKey(speaker) {
|
|
7135
|
+
const normalized = getRawSpeaker(speaker).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
7136
|
+
return normalized.length > 0 ? normalized : DEFAULT_VOICE_PILL_SPEAKER;
|
|
7137
|
+
}
|
|
7138
|
+
function getVoicePillSpeakerLabel(speaker) {
|
|
7139
|
+
const raw = getRawSpeaker(speaker);
|
|
7140
|
+
const key = getVoicePillSpeakerKey(raw);
|
|
7141
|
+
if (key === "ai") return "AI";
|
|
7142
|
+
if (key === "user") return "User";
|
|
7143
|
+
return raw;
|
|
7144
|
+
}
|
|
7145
|
+
function getVoicePillInitials(speaker) {
|
|
7146
|
+
const key = getVoicePillSpeakerKey(speaker);
|
|
7147
|
+
if (key === "ai") return "AI";
|
|
7148
|
+
if (key === "user") return "U";
|
|
7149
|
+
const initials = getVoicePillSpeakerLabel(speaker).split(/[\s_-]+/).map((part) => part.charAt(0)).filter(Boolean).join("").slice(0, 2).toUpperCase();
|
|
7150
|
+
return initials.length > 0 ? initials : "V";
|
|
7151
|
+
}
|
|
7152
|
+
function getVoicePillPosition(position) {
|
|
7153
|
+
return position ?? DEFAULT_VOICE_PILL_POSITION;
|
|
7154
|
+
}
|
|
7155
|
+
function getVoicePillAriaLabel(props) {
|
|
7156
|
+
const parts = [`${getVoicePillSpeakerLabel(props.speaker)}: ${props.label}`];
|
|
7157
|
+
if (props.sub) {
|
|
7158
|
+
parts.push(props.sub);
|
|
7159
|
+
}
|
|
7160
|
+
if (props.muted) {
|
|
7161
|
+
parts.push("muted");
|
|
7162
|
+
}
|
|
7163
|
+
return parts.join(", ");
|
|
7164
|
+
}
|
|
7165
|
+
function getVoicePillPulseStyle(intensity, muted = false) {
|
|
7166
|
+
const clamped = clampVoicePillIntensity(intensity);
|
|
7167
|
+
const visualIntensity = muted ? 0 : clamped;
|
|
7168
|
+
const ringOpacity = visualIntensity === 0 ? 0 : 0.12 + visualIntensity * 0.42;
|
|
7169
|
+
const ringScale = 1 + visualIntensity * 0.35;
|
|
7170
|
+
const duration = visualIntensity === 0 ? 1800 : Math.round(1700 - visualIntensity * 700);
|
|
7171
|
+
return {
|
|
7172
|
+
"--rfr-voice-pill-intensity": formatNumber(clamped),
|
|
7173
|
+
"--rfr-voice-pill-visual-intensity": formatNumber(visualIntensity),
|
|
7174
|
+
"--rfr-voice-pill-ring-opacity": formatNumber(ringOpacity),
|
|
7175
|
+
"--rfr-voice-pill-ring-scale": formatNumber(ringScale),
|
|
7176
|
+
"--rfr-voice-pill-pulse-duration": `${duration}ms`,
|
|
7177
|
+
"--rfr-voice-pill-pulse-delay": `-${Math.round(duration / 2)}ms`
|
|
7178
|
+
};
|
|
7179
|
+
}
|
|
7180
|
+
function createVoicePill(props) {
|
|
7181
|
+
const {
|
|
7182
|
+
speaker: speakerProp,
|
|
7183
|
+
label,
|
|
7184
|
+
sub,
|
|
7185
|
+
intensity: intensityProp,
|
|
7186
|
+
muted: mutedProp = false,
|
|
7187
|
+
onToggleMute,
|
|
7188
|
+
position: positionProp
|
|
7189
|
+
} = props;
|
|
7190
|
+
const speaker = getVoicePillSpeakerLabel(speakerProp);
|
|
7191
|
+
const speakerKey = getVoicePillSpeakerKey(speakerProp);
|
|
7192
|
+
const intensity = clampVoicePillIntensity(intensityProp);
|
|
7193
|
+
const muted = Boolean(mutedProp);
|
|
7194
|
+
const visualIntensity = muted ? 0 : intensity;
|
|
7195
|
+
const position = getVoicePillPosition(positionProp);
|
|
7196
|
+
function toggleMute() {
|
|
7197
|
+
onToggleMute?.();
|
|
7198
|
+
}
|
|
7199
|
+
const ariaProps = {
|
|
7200
|
+
role: "status",
|
|
7201
|
+
"aria-live": "polite",
|
|
7202
|
+
"aria-atomic": true,
|
|
7203
|
+
"aria-label": getVoicePillAriaLabel({ speaker: speakerProp, label, sub, muted })
|
|
7204
|
+
};
|
|
7205
|
+
const toggleMuteAriaProps = {
|
|
7206
|
+
"aria-label": muted ? "Unmute voice" : "Mute voice",
|
|
7207
|
+
"aria-pressed": muted
|
|
7208
|
+
};
|
|
7209
|
+
const dataAttributes = {
|
|
7210
|
+
"data-speaker": speakerKey,
|
|
7211
|
+
"data-muted": String(muted),
|
|
7212
|
+
"data-position": position,
|
|
7213
|
+
"data-intensity": formatNumber(intensity),
|
|
7214
|
+
"data-active": String(visualIntensity > 0)
|
|
7215
|
+
};
|
|
7216
|
+
return {
|
|
7217
|
+
speaker,
|
|
7218
|
+
speakerKey,
|
|
7219
|
+
label,
|
|
7220
|
+
sub,
|
|
7221
|
+
intensity,
|
|
7222
|
+
visualIntensity,
|
|
7223
|
+
muted,
|
|
7224
|
+
position,
|
|
7225
|
+
initials: getVoicePillInitials(speakerProp),
|
|
7226
|
+
toggleMute,
|
|
7227
|
+
ariaProps,
|
|
7228
|
+
toggleMuteAriaProps,
|
|
7229
|
+
dataAttributes,
|
|
7230
|
+
style: getVoicePillPulseStyle(intensity, muted)
|
|
7231
|
+
};
|
|
7232
|
+
}
|
|
7233
|
+
var voicePillTokens = {
|
|
7234
|
+
name: "voice-pill",
|
|
7235
|
+
tokens: {
|
|
7236
|
+
bg: { variable: "--rfr-voice-pill-bg", fallback: "hsl(var(--background))" },
|
|
7237
|
+
fg: { variable: "--rfr-voice-pill-fg", fallback: "hsl(var(--foreground))" },
|
|
7238
|
+
border: { variable: "--rfr-voice-pill-border", fallback: "hsl(var(--border))" },
|
|
7239
|
+
accent: { variable: "--rfr-voice-pill-accent", fallback: "hsl(var(--primary))" },
|
|
7240
|
+
accentFg: {
|
|
7241
|
+
variable: "--rfr-voice-pill-accent-foreground",
|
|
7242
|
+
fallback: "hsl(var(--primary-foreground))"
|
|
7243
|
+
}
|
|
7244
|
+
}
|
|
7245
|
+
};
|
|
7246
|
+
var voicePillRootStyles = "inline-flex min-w-0 max-w-[min(calc(100vw-2rem),22rem)] items-center gap-3 rounded-full border border-border bg-background px-3 py-2 text-foreground shadow-lg ring-1 ring-border/50 transition-opacity data-[muted=true]:opacity-80";
|
|
7247
|
+
var voicePillSpeakerStyles = "[--rfr-voice-pill-accent:hsl(var(--primary))] [--rfr-voice-pill-accent-foreground:hsl(var(--primary-foreground))] data-[speaker=user]:[--rfr-voice-pill-accent:hsl(var(--accent-foreground))] data-[speaker=user]:[--rfr-voice-pill-accent-foreground:hsl(var(--accent))] data-[muted=true]:[--rfr-voice-pill-accent:hsl(var(--muted-foreground))]";
|
|
7248
|
+
var voicePillPositionVariants = cva({
|
|
7249
|
+
base: "z-50",
|
|
7250
|
+
variants: {
|
|
7251
|
+
position: {
|
|
7252
|
+
inline: "relative",
|
|
7253
|
+
"top-start": "fixed top-[calc(env(safe-area-inset-top)+1rem)] left-[calc(env(safe-area-inset-left)+1rem)]",
|
|
7254
|
+
"top-center": "fixed top-[calc(env(safe-area-inset-top)+1rem)] left-1/2 -translate-x-1/2",
|
|
7255
|
+
"top-end": "fixed top-[calc(env(safe-area-inset-top)+1rem)] right-[calc(env(safe-area-inset-right)+1rem)]",
|
|
7256
|
+
"bottom-start": "fixed bottom-[calc(env(safe-area-inset-bottom)+1rem)] left-[calc(env(safe-area-inset-left)+1rem)]",
|
|
7257
|
+
"bottom-center": "fixed bottom-[calc(env(safe-area-inset-bottom)+1rem)] left-1/2 -translate-x-1/2",
|
|
7258
|
+
"bottom-end": "fixed bottom-[calc(env(safe-area-inset-bottom)+1rem)] right-[calc(env(safe-area-inset-right)+1rem)]",
|
|
7259
|
+
"left-start": "fixed left-[calc(env(safe-area-inset-left)+1rem)] top-[calc(env(safe-area-inset-top)+1rem)]",
|
|
7260
|
+
"left-center": "fixed left-[calc(env(safe-area-inset-left)+1rem)] top-1/2 -translate-y-1/2",
|
|
7261
|
+
"left-end": "fixed left-[calc(env(safe-area-inset-left)+1rem)] bottom-[calc(env(safe-area-inset-bottom)+1rem)]",
|
|
7262
|
+
"right-start": "fixed right-[calc(env(safe-area-inset-right)+1rem)] top-[calc(env(safe-area-inset-top)+1rem)]",
|
|
7263
|
+
"right-center": "fixed right-[calc(env(safe-area-inset-right)+1rem)] top-1/2 -translate-y-1/2",
|
|
7264
|
+
"right-end": "fixed right-[calc(env(safe-area-inset-right)+1rem)] bottom-[calc(env(safe-area-inset-bottom)+1rem)]"
|
|
7265
|
+
}
|
|
7266
|
+
},
|
|
7267
|
+
defaultVariants: {
|
|
7268
|
+
position: "bottom-center"
|
|
7269
|
+
}
|
|
7270
|
+
});
|
|
7271
|
+
var voicePillAvatarWrapStyles = "relative flex h-10 w-10 shrink-0 items-center justify-center";
|
|
7272
|
+
var voicePillPulseRingStyles = "pointer-events-none absolute inset-0 rounded-full border border-[var(--rfr-voice-pill-accent)] opacity-[var(--rfr-voice-pill-ring-opacity)] motion-safe:animate-ping motion-reduce:animate-none";
|
|
7273
|
+
var voicePillAvatarStyles = "relative z-10 flex h-10 w-10 items-center justify-center overflow-hidden rounded-full bg-[var(--rfr-voice-pill-accent)] text-[var(--rfr-voice-pill-accent-foreground)] text-xs font-semibold uppercase";
|
|
7274
|
+
var voicePillTextStyles = "min-w-0 flex-1";
|
|
7275
|
+
var voicePillLabelStyles = "block truncate text-sm font-medium leading-tight";
|
|
7276
|
+
var voicePillSubStyles = "block truncate text-xs leading-tight text-muted-foreground";
|
|
7277
|
+
var voicePillMuteButtonStyles = "inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-full border border-border text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring";
|
|
7278
|
+
|
|
7279
|
+
// ../react-voice-pill/dist/index.js
|
|
7280
|
+
var VoicePill = React11__namespace.forwardRef(
|
|
7281
|
+
({
|
|
7282
|
+
speaker,
|
|
7283
|
+
label,
|
|
7284
|
+
sub,
|
|
7285
|
+
intensity,
|
|
7286
|
+
muted,
|
|
7287
|
+
onToggleMute,
|
|
7288
|
+
position,
|
|
7289
|
+
avatar,
|
|
7290
|
+
className,
|
|
7291
|
+
style,
|
|
7292
|
+
...props
|
|
7293
|
+
}, ref) => {
|
|
7294
|
+
const api = createVoicePill({
|
|
7295
|
+
speaker,
|
|
7296
|
+
label,
|
|
7297
|
+
sub,
|
|
7298
|
+
intensity,
|
|
7299
|
+
muted,
|
|
7300
|
+
onToggleMute,
|
|
7301
|
+
position
|
|
7302
|
+
});
|
|
7303
|
+
const mergedStyle = {
|
|
7304
|
+
...api.style,
|
|
7305
|
+
...style
|
|
7306
|
+
};
|
|
7307
|
+
const pulseStyle = {
|
|
7308
|
+
animationDuration: "var(--rfr-voice-pill-pulse-duration)",
|
|
7309
|
+
transform: "scale(var(--rfr-voice-pill-ring-scale))"
|
|
7310
|
+
};
|
|
7311
|
+
const delayedPulseStyle = {
|
|
7312
|
+
...pulseStyle,
|
|
7313
|
+
animationDelay: "var(--rfr-voice-pill-pulse-delay)"
|
|
7314
|
+
};
|
|
7315
|
+
return React11__namespace.createElement(
|
|
7316
|
+
"div",
|
|
7317
|
+
{
|
|
7318
|
+
...props,
|
|
7319
|
+
...api.ariaProps,
|
|
7320
|
+
...api.dataAttributes,
|
|
7321
|
+
ref,
|
|
7322
|
+
className: cn(
|
|
7323
|
+
voicePillPositionVariants({ position: api.position }),
|
|
7324
|
+
voicePillRootStyles,
|
|
7325
|
+
voicePillSpeakerStyles,
|
|
7326
|
+
className
|
|
7327
|
+
),
|
|
7328
|
+
style: mergedStyle
|
|
7329
|
+
},
|
|
7330
|
+
React11__namespace.createElement(
|
|
7331
|
+
"span",
|
|
7332
|
+
{
|
|
7333
|
+
className: voicePillAvatarWrapStyles,
|
|
7334
|
+
"aria-hidden": true
|
|
7335
|
+
},
|
|
7336
|
+
api.visualIntensity > 0 && React11__namespace.createElement("span", {
|
|
7337
|
+
className: voicePillPulseRingStyles,
|
|
7338
|
+
style: pulseStyle
|
|
7339
|
+
}),
|
|
7340
|
+
api.visualIntensity > 0 && React11__namespace.createElement("span", {
|
|
7341
|
+
className: voicePillPulseRingStyles,
|
|
7342
|
+
style: delayedPulseStyle
|
|
7343
|
+
}),
|
|
7344
|
+
React11__namespace.createElement(
|
|
7345
|
+
"span",
|
|
7346
|
+
{ className: voicePillAvatarStyles },
|
|
7347
|
+
avatar ?? api.initials
|
|
7348
|
+
)
|
|
7349
|
+
),
|
|
7350
|
+
React11__namespace.createElement(
|
|
7351
|
+
"span",
|
|
7352
|
+
{ className: voicePillTextStyles },
|
|
7353
|
+
React11__namespace.createElement("span", { className: voicePillLabelStyles }, api.label),
|
|
7354
|
+
api.sub && React11__namespace.createElement("span", { className: voicePillSubStyles }, api.sub)
|
|
7355
|
+
),
|
|
7356
|
+
onToggleMute && React11__namespace.createElement(
|
|
7357
|
+
"button",
|
|
7358
|
+
{
|
|
7359
|
+
type: "button",
|
|
7360
|
+
className: voicePillMuteButtonStyles,
|
|
7361
|
+
onClick: api.toggleMute,
|
|
7362
|
+
...api.toggleMuteAriaProps
|
|
7363
|
+
},
|
|
7364
|
+
renderMuteIcon(api.muted)
|
|
7365
|
+
)
|
|
7366
|
+
);
|
|
7367
|
+
}
|
|
7368
|
+
);
|
|
7369
|
+
VoicePill.displayName = "VoicePill";
|
|
7370
|
+
function renderMuteIcon(muted) {
|
|
7371
|
+
return React11__namespace.createElement(
|
|
7372
|
+
"svg",
|
|
7373
|
+
{
|
|
7374
|
+
"aria-hidden": true,
|
|
7375
|
+
className: "h-4 w-4",
|
|
7376
|
+
fill: "none",
|
|
7377
|
+
stroke: "currentColor",
|
|
7378
|
+
strokeLinecap: "round",
|
|
7379
|
+
strokeLinejoin: "round",
|
|
7380
|
+
strokeWidth: 2,
|
|
7381
|
+
viewBox: "0 0 24 24"
|
|
7382
|
+
},
|
|
7383
|
+
React11__namespace.createElement("path", {
|
|
7384
|
+
d: "M4 9v6h4l5 4V5L8 9H4Z"
|
|
7385
|
+
}),
|
|
7386
|
+
muted ? React11__namespace.createElement(
|
|
7387
|
+
React11__namespace.Fragment,
|
|
7388
|
+
null,
|
|
7389
|
+
React11__namespace.createElement("path", { d: "m19 9-4 4" }),
|
|
7390
|
+
React11__namespace.createElement("path", { d: "m15 9 4 4" })
|
|
7391
|
+
) : React11__namespace.createElement(
|
|
7392
|
+
React11__namespace.Fragment,
|
|
7393
|
+
null,
|
|
7394
|
+
React11__namespace.createElement("path", { d: "M16 8.5a4 4 0 0 1 0 7" }),
|
|
7395
|
+
React11__namespace.createElement("path", { d: "M18.5 6a7 7 0 0 1 0 12" })
|
|
7396
|
+
)
|
|
7397
|
+
);
|
|
7398
|
+
}
|
|
7399
|
+
|
|
7400
|
+
// ../waveform/dist/index.js
|
|
7401
|
+
var DEFAULT_WAVEFORM_BAR_COUNT = 48;
|
|
7402
|
+
var DEFAULT_WAVEFORM_COLOR = "var(--accent-2)";
|
|
7403
|
+
var DEFAULT_WAVEFORM_HEIGHT = 80;
|
|
7404
|
+
var DEFAULT_WAVEFORM_INTENSITY = 1;
|
|
7405
|
+
var DEFAULT_WAVEFORM_AMPLITUDE = 1;
|
|
7406
|
+
var DEFAULT_WAVEFORM_SMOOTHING = 0.8;
|
|
7407
|
+
var MAX_BAR_COUNT = 1024;
|
|
7408
|
+
var MAX_INTENSITY = 1;
|
|
7409
|
+
function normalizeBarCount(value) {
|
|
7410
|
+
if (value == null || !Number.isFinite(value)) return DEFAULT_WAVEFORM_BAR_COUNT;
|
|
7411
|
+
return Math.min(MAX_BAR_COUNT, Math.max(1, Math.round(value)));
|
|
7412
|
+
}
|
|
7413
|
+
function normalizeSmoothing(value) {
|
|
7414
|
+
if (value == null || !Number.isFinite(value)) return DEFAULT_WAVEFORM_SMOOTHING;
|
|
7415
|
+
return Math.min(0.99, Math.max(0, value));
|
|
7416
|
+
}
|
|
7417
|
+
function normalizeIntensity(value) {
|
|
7418
|
+
if (value == null || !Number.isFinite(value)) return DEFAULT_WAVEFORM_INTENSITY;
|
|
7419
|
+
return Math.min(MAX_INTENSITY, Math.max(0, value));
|
|
7420
|
+
}
|
|
7421
|
+
function normalizeAmplitude(value) {
|
|
7422
|
+
if (value == null || !Number.isFinite(value)) return DEFAULT_WAVEFORM_AMPLITUDE;
|
|
7423
|
+
return Math.min(1, Math.max(0, value));
|
|
7424
|
+
}
|
|
7425
|
+
function normalizeWaveformConfig(props = {}) {
|
|
7426
|
+
return {
|
|
7427
|
+
variant: props.variant ?? "bars",
|
|
7428
|
+
intensity: normalizeIntensity(props.intensity),
|
|
7429
|
+
amplitude: normalizeAmplitude(props.amplitude),
|
|
7430
|
+
height: props.height ?? DEFAULT_WAVEFORM_HEIGHT,
|
|
7431
|
+
width: props.width ?? "100%",
|
|
7432
|
+
barCount: normalizeBarCount(props.barCount),
|
|
7433
|
+
smoothing: normalizeSmoothing(props.smoothing),
|
|
7434
|
+
color: props.color ?? DEFAULT_WAVEFORM_COLOR,
|
|
7435
|
+
paused: props.paused ?? false
|
|
7436
|
+
};
|
|
7437
|
+
}
|
|
7438
|
+
function isWaveformSampleInput(value) {
|
|
7439
|
+
return value instanceof Float32Array || Array.isArray(value);
|
|
7440
|
+
}
|
|
7441
|
+
function createSilentSamples(count = DEFAULT_WAVEFORM_BAR_COUNT) {
|
|
7442
|
+
return new Float32Array(normalizeBarCount(count));
|
|
7443
|
+
}
|
|
7444
|
+
function createIntensitySamples(intensity = DEFAULT_WAVEFORM_INTENSITY, count = DEFAULT_WAVEFORM_BAR_COUNT, phase = 0) {
|
|
7445
|
+
const normalizedIntensity = normalizeIntensity(intensity);
|
|
7446
|
+
const normalizedCount = normalizeBarCount(count);
|
|
7447
|
+
const samples = new Float32Array(normalizedCount);
|
|
7448
|
+
if (normalizedIntensity === 0) return samples;
|
|
7449
|
+
const pulse = 0.72 + Math.sin(phase * 1.8) * 0.18;
|
|
7450
|
+
for (let i = 0; i < normalizedCount; i += 1) {
|
|
7451
|
+
const progress = normalizedCount <= 1 ? 0.5 : i / (normalizedCount - 1);
|
|
7452
|
+
const envelope = 0.35 + Math.sin(progress * Math.PI) * 0.65;
|
|
7453
|
+
const carrier = Math.sin(progress * Math.PI * 6 + phase * 2.8);
|
|
7454
|
+
samples[i] = carrier * envelope * normalizedIntensity * pulse;
|
|
7455
|
+
}
|
|
7456
|
+
return samples;
|
|
7457
|
+
}
|
|
7458
|
+
function normalizeWaveformSamples(input, targetCount) {
|
|
7459
|
+
const sourceLength = input?.length ?? 0;
|
|
7460
|
+
if (sourceLength === 0) {
|
|
7461
|
+
return targetCount == null ? new Float32Array() : createSilentSamples(targetCount);
|
|
7462
|
+
}
|
|
7463
|
+
const normalized = new Float32Array(sourceLength);
|
|
7464
|
+
let maxAbs = 0;
|
|
7465
|
+
for (let i = 0; i < sourceLength; i += 1) {
|
|
7466
|
+
const value = Number(input?.[i]);
|
|
7467
|
+
const sample = Number.isFinite(value) ? value : 0;
|
|
7468
|
+
normalized[i] = sample;
|
|
7469
|
+
maxAbs = Math.max(maxAbs, Math.abs(sample));
|
|
7470
|
+
}
|
|
7471
|
+
const divisor = maxAbs > 1 ? maxAbs : 1;
|
|
7472
|
+
for (let i = 0; i < normalized.length; i += 1) {
|
|
7473
|
+
normalized[i] = clamp(normalized[i] / divisor, -1, 1);
|
|
7474
|
+
}
|
|
7475
|
+
if (targetCount == null || targetCount === normalized.length) {
|
|
7476
|
+
return normalized;
|
|
7477
|
+
}
|
|
7478
|
+
return resampleWaveformSamples(normalized, targetCount);
|
|
7479
|
+
}
|
|
7480
|
+
function resampleWaveformSamples(samples, targetCount) {
|
|
7481
|
+
const count = normalizeBarCount(targetCount);
|
|
7482
|
+
const sourceLength = samples.length;
|
|
7483
|
+
if (sourceLength === 0) return createSilentSamples(count);
|
|
7484
|
+
if (sourceLength === count) return Float32Array.from(samples);
|
|
7485
|
+
const output = new Float32Array(count);
|
|
7486
|
+
for (let i = 0; i < count; i += 1) {
|
|
7487
|
+
const start = i * sourceLength / count;
|
|
7488
|
+
const end = (i + 1) * sourceLength / count;
|
|
7489
|
+
const firstIndex = Math.floor(start);
|
|
7490
|
+
const lastIndex = Math.max(firstIndex + 1, Math.ceil(end));
|
|
7491
|
+
let total = 0;
|
|
7492
|
+
let values = 0;
|
|
7493
|
+
for (let j = firstIndex; j < lastIndex && j < sourceLength; j += 1) {
|
|
7494
|
+
total += Number(samples[j]);
|
|
7495
|
+
values += 1;
|
|
7496
|
+
}
|
|
7497
|
+
output[i] = values > 0 ? total / values : Number(samples[Math.min(firstIndex, sourceLength - 1)]);
|
|
7498
|
+
}
|
|
7499
|
+
return output;
|
|
7500
|
+
}
|
|
7501
|
+
function smoothWaveformSamples(previous, next, smoothing = DEFAULT_WAVEFORM_SMOOTHING) {
|
|
7502
|
+
if (previous == null || previous.length === 0) {
|
|
7503
|
+
return Float32Array.from(next);
|
|
7504
|
+
}
|
|
7505
|
+
const amount = normalizeSmoothing(smoothing);
|
|
7506
|
+
const output = new Float32Array(next.length);
|
|
7507
|
+
for (let i = 0; i < next.length; i += 1) {
|
|
7508
|
+
const previousValue = Number(previous[i] ?? next[i]);
|
|
7509
|
+
output[i] = previousValue * amount + Number(next[i]) * (1 - amount);
|
|
7510
|
+
}
|
|
7511
|
+
return output;
|
|
7512
|
+
}
|
|
7513
|
+
function scaleWaveformSamples(samples, intensity = DEFAULT_WAVEFORM_INTENSITY) {
|
|
7514
|
+
const amount = normalizeIntensity(intensity);
|
|
7515
|
+
const output = new Float32Array(samples.length);
|
|
7516
|
+
for (let i = 0; i < samples.length; i += 1) {
|
|
7517
|
+
output[i] = clamp(Number(samples[i]) * amount, -1, 1);
|
|
7518
|
+
}
|
|
7519
|
+
return output;
|
|
7520
|
+
}
|
|
7521
|
+
function getWaveformPeak(samples) {
|
|
7522
|
+
let peak = 0;
|
|
7523
|
+
for (let i = 0; i < samples.length; i += 1) {
|
|
7524
|
+
peak = Math.max(peak, Math.abs(Number(samples[i]) || 0));
|
|
7525
|
+
}
|
|
7526
|
+
return Math.min(1, peak);
|
|
7527
|
+
}
|
|
7528
|
+
function toCssDimension(value) {
|
|
7529
|
+
if (value == null) return void 0;
|
|
7530
|
+
return typeof value === "number" ? `${value}px` : value;
|
|
7531
|
+
}
|
|
7532
|
+
function createWaveform(props = {}) {
|
|
7533
|
+
const config = normalizeWaveformConfig(props);
|
|
7534
|
+
const inputSamples = props.samples ?? (isWaveformSampleInput(props.source) ? props.source : void 0);
|
|
7535
|
+
const samples = inputSamples == null ? createIntensitySamples(config.intensity, config.barCount) : normalizeWaveformSamples(inputSamples, config.barCount);
|
|
7536
|
+
return {
|
|
7537
|
+
config,
|
|
7538
|
+
samples,
|
|
7539
|
+
ariaProps: {
|
|
7540
|
+
role: "img",
|
|
7541
|
+
"aria-label": "Audio waveform"
|
|
7542
|
+
},
|
|
7543
|
+
dataAttributes: {
|
|
7544
|
+
"data-variant": config.variant,
|
|
7545
|
+
"data-paused": String(config.paused)
|
|
7546
|
+
},
|
|
7547
|
+
getSamples(barCount = config.barCount) {
|
|
7548
|
+
return inputSamples == null ? createIntensitySamples(config.intensity, barCount) : normalizeWaveformSamples(inputSamples, barCount);
|
|
7549
|
+
}
|
|
7550
|
+
};
|
|
7551
|
+
}
|
|
7552
|
+
function clamp(value, min, max) {
|
|
7553
|
+
return Math.min(max, Math.max(min, value));
|
|
7554
|
+
}
|
|
7555
|
+
function prepareWaveformCanvas(canvas, size) {
|
|
7556
|
+
const width = Math.max(1, Math.floor(size.width));
|
|
7557
|
+
const height = Math.max(1, Math.floor(size.height));
|
|
7558
|
+
const pixelRatio = Math.max(1, size.pixelRatio ?? 1);
|
|
7559
|
+
const pixelWidth = Math.floor(width * pixelRatio);
|
|
7560
|
+
const pixelHeight = Math.floor(height * pixelRatio);
|
|
7561
|
+
if (canvas.width !== pixelWidth) {
|
|
7562
|
+
canvas.width = pixelWidth;
|
|
7563
|
+
}
|
|
7564
|
+
if (canvas.height !== pixelHeight) {
|
|
7565
|
+
canvas.height = pixelHeight;
|
|
7566
|
+
}
|
|
7567
|
+
const context = canvas.getContext("2d");
|
|
7568
|
+
if (!context) return null;
|
|
7569
|
+
context.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0);
|
|
7570
|
+
return context;
|
|
7571
|
+
}
|
|
7572
|
+
function drawWaveform(context, samples, size, options = {}) {
|
|
7573
|
+
const width = Math.max(1, Math.floor(size.width));
|
|
7574
|
+
const height = Math.max(1, Math.floor(size.height));
|
|
7575
|
+
const variant = options.variant ?? "bars";
|
|
7576
|
+
const color = options.color ?? DEFAULT_WAVEFORM_COLOR;
|
|
7577
|
+
const intensity = normalizeIntensity(options.intensity ?? DEFAULT_WAVEFORM_INTENSITY);
|
|
7578
|
+
const amplitude = normalizeAmplitude(options.amplitude ?? DEFAULT_WAVEFORM_AMPLITUDE);
|
|
7579
|
+
const barCount = normalizeBarCount(options.barCount);
|
|
7580
|
+
context.clearRect(0, 0, width, height);
|
|
7581
|
+
applyCanvasColor(context, color);
|
|
7582
|
+
if (variant === "line") {
|
|
7583
|
+
drawLine(context, samples, width, height, intensity, amplitude);
|
|
7584
|
+
return;
|
|
7585
|
+
}
|
|
7586
|
+
if (variant === "rings") {
|
|
7587
|
+
drawRings(context, samples, width, height, intensity, amplitude);
|
|
7588
|
+
return;
|
|
7589
|
+
}
|
|
7590
|
+
drawBars(context, samples, width, height, intensity, amplitude, barCount);
|
|
7591
|
+
}
|
|
7592
|
+
function drawBars(context, samples, width, height, intensity, amplitude, barCount) {
|
|
7593
|
+
const bars = scaleWaveformSamples(resampleWaveformSamples(samples, barCount), intensity);
|
|
7594
|
+
const slotWidth = width / bars.length;
|
|
7595
|
+
const barWidth = Math.max(1, slotWidth * 0.64);
|
|
7596
|
+
const center = height / 2;
|
|
7597
|
+
for (let i = 0; i < bars.length; i += 1) {
|
|
7598
|
+
const value = Math.abs(bars[i]);
|
|
7599
|
+
const barHeight = Math.max(value * height * amplitude, value > 0 ? 1 : 0);
|
|
7600
|
+
const x = i * slotWidth + (slotWidth - barWidth) / 2;
|
|
7601
|
+
const y = center - barHeight / 2;
|
|
7602
|
+
context.fillRect(x, y, barWidth, barHeight);
|
|
7603
|
+
}
|
|
7604
|
+
}
|
|
7605
|
+
function drawLine(context, samples, width, height, intensity, amplitudeScale) {
|
|
7606
|
+
const lineSamples = scaleWaveformSamples(samples, intensity);
|
|
7607
|
+
const center = height / 2;
|
|
7608
|
+
const amplitude = height * 0.45 * amplitudeScale;
|
|
7609
|
+
context.beginPath();
|
|
7610
|
+
for (let i = 0; i < lineSamples.length; i += 1) {
|
|
7611
|
+
const x = lineSamples.length <= 1 ? width / 2 : i / (lineSamples.length - 1) * width;
|
|
7612
|
+
const y = center - Number(lineSamples[i]) * amplitude;
|
|
7613
|
+
if (i === 0) {
|
|
7614
|
+
context.moveTo(x, y);
|
|
7615
|
+
} else {
|
|
7616
|
+
context.lineTo(x, y);
|
|
7617
|
+
}
|
|
7618
|
+
}
|
|
7619
|
+
context.lineWidth = Math.max(1.5, Math.min(width, height) * 0.025);
|
|
7620
|
+
context.lineCap = "round";
|
|
7621
|
+
context.lineJoin = "round";
|
|
7622
|
+
context.stroke();
|
|
7623
|
+
}
|
|
7624
|
+
function drawRings(context, samples, width, height, intensity, amplitude) {
|
|
7625
|
+
const peak = getWaveformPeak(scaleWaveformSamples(samples, intensity)) * amplitude;
|
|
7626
|
+
const minDimension = Math.min(width, height);
|
|
7627
|
+
const centerX = width / 2;
|
|
7628
|
+
const centerY = height / 2;
|
|
7629
|
+
const ringCount = 3;
|
|
7630
|
+
const baseRadius = minDimension * 0.16;
|
|
7631
|
+
const radiusStep = minDimension * 0.13;
|
|
7632
|
+
context.save();
|
|
7633
|
+
context.lineWidth = Math.max(1.5, minDimension * 0.018);
|
|
7634
|
+
for (let i = 0; i < ringCount; i += 1) {
|
|
7635
|
+
const progress = (i + 1) / ringCount;
|
|
7636
|
+
const pulse = peak * minDimension * 0.1 * progress;
|
|
7637
|
+
const radius = baseRadius + radiusStep * i + pulse;
|
|
7638
|
+
context.globalAlpha = 0.28 + progress * 0.34;
|
|
7639
|
+
context.beginPath();
|
|
7640
|
+
context.arc(centerX, centerY, radius, 0, Math.PI * 2);
|
|
7641
|
+
context.stroke();
|
|
7642
|
+
}
|
|
7643
|
+
context.restore();
|
|
7644
|
+
}
|
|
7645
|
+
function applyCanvasColor(context, color) {
|
|
7646
|
+
try {
|
|
7647
|
+
context.fillStyle = color;
|
|
7648
|
+
context.strokeStyle = color;
|
|
7649
|
+
} catch {
|
|
7650
|
+
context.fillStyle = "#000";
|
|
7651
|
+
context.strokeStyle = "#000";
|
|
7652
|
+
}
|
|
7653
|
+
}
|
|
7654
|
+
var waveformVariants = cva({
|
|
7655
|
+
base: "relative block overflow-hidden",
|
|
7656
|
+
variants: {
|
|
7657
|
+
variant: {
|
|
7658
|
+
bars: "",
|
|
7659
|
+
line: "",
|
|
7660
|
+
rings: ""
|
|
7661
|
+
}
|
|
7662
|
+
},
|
|
7663
|
+
defaultVariants: {
|
|
7664
|
+
variant: "bars"
|
|
7665
|
+
}
|
|
7666
|
+
});
|
|
7667
|
+
var waveformCanvasVariants = cva({
|
|
7668
|
+
base: "block h-full w-full"
|
|
7669
|
+
});
|
|
7670
|
+
var Waveform = React11__namespace.forwardRef(
|
|
7671
|
+
({
|
|
7672
|
+
source,
|
|
7673
|
+
samples,
|
|
7674
|
+
intensity,
|
|
7675
|
+
amplitude,
|
|
7676
|
+
variant,
|
|
7677
|
+
height,
|
|
7678
|
+
width,
|
|
7679
|
+
barCount,
|
|
7680
|
+
smoothing,
|
|
7681
|
+
color,
|
|
7682
|
+
paused,
|
|
7683
|
+
className,
|
|
7684
|
+
style,
|
|
7685
|
+
...props
|
|
7686
|
+
}, ref) => {
|
|
7687
|
+
const rootRef = React11__namespace.useRef(null);
|
|
7688
|
+
const canvasRef = React11__namespace.useRef(null);
|
|
7689
|
+
const previousSamplesRef = React11__namespace.useRef(null);
|
|
7690
|
+
const mediaAnalyserRef = React11__namespace.useRef(null);
|
|
7691
|
+
const floatBufferRef = React11__namespace.useRef(null);
|
|
7692
|
+
const byteBufferRef = React11__namespace.useRef(null);
|
|
7693
|
+
const prefersReducedMotion = usePrefersReducedMotion();
|
|
7694
|
+
const api = createWaveform({
|
|
7695
|
+
source,
|
|
7696
|
+
samples,
|
|
7697
|
+
intensity,
|
|
7698
|
+
amplitude,
|
|
7699
|
+
variant,
|
|
7700
|
+
height,
|
|
7701
|
+
width,
|
|
7702
|
+
barCount,
|
|
7703
|
+
smoothing,
|
|
7704
|
+
color,
|
|
7705
|
+
paused
|
|
7706
|
+
});
|
|
7707
|
+
const rootStyle = React11__namespace.useMemo(
|
|
7708
|
+
() => ({
|
|
7709
|
+
...style,
|
|
7710
|
+
width: toCssDimension(width) ?? style?.width ?? "100%",
|
|
7711
|
+
height: toCssDimension(height) ?? style?.height ?? `${api.config.height}px`,
|
|
7712
|
+
"--waveform-color": api.config.color
|
|
7713
|
+
}),
|
|
7714
|
+
[api.config.color, api.config.height, height, style, width]
|
|
7715
|
+
);
|
|
7716
|
+
const setRootRef = React11__namespace.useCallback(
|
|
7717
|
+
(node) => {
|
|
7718
|
+
rootRef.current = node;
|
|
7719
|
+
if (typeof ref === "function") {
|
|
7720
|
+
ref(node);
|
|
7721
|
+
} else if (ref) {
|
|
7722
|
+
ref.current = node;
|
|
7723
|
+
}
|
|
7724
|
+
},
|
|
7725
|
+
[ref]
|
|
7726
|
+
);
|
|
7727
|
+
React11__namespace.useEffect(() => {
|
|
7728
|
+
if (!isMediaStreamSource(source)) {
|
|
7729
|
+
mediaAnalyserRef.current = null;
|
|
7730
|
+
return;
|
|
7731
|
+
}
|
|
7732
|
+
if (typeof window === "undefined") return;
|
|
7733
|
+
const AudioContextClass = window.AudioContext ?? window.webkitAudioContext;
|
|
7734
|
+
if (!AudioContextClass) return;
|
|
7735
|
+
const audioContext = new AudioContextClass();
|
|
7736
|
+
const analyser = audioContext.createAnalyser();
|
|
7737
|
+
const streamSource = audioContext.createMediaStreamSource(source);
|
|
7738
|
+
analyser.smoothingTimeConstant = normalizeSmoothing(api.config.smoothing);
|
|
7739
|
+
streamSource.connect(analyser);
|
|
7740
|
+
mediaAnalyserRef.current = analyser;
|
|
7741
|
+
return () => {
|
|
7742
|
+
mediaAnalyserRef.current = null;
|
|
7743
|
+
streamSource.disconnect();
|
|
7744
|
+
analyser.disconnect();
|
|
7745
|
+
if (audioContext.state !== "closed") {
|
|
7746
|
+
void audioContext.close();
|
|
7747
|
+
}
|
|
7748
|
+
};
|
|
7749
|
+
}, [api.config.smoothing, source]);
|
|
7750
|
+
React11__namespace.useEffect(() => {
|
|
7751
|
+
if (isAnalyserSource(source)) {
|
|
7752
|
+
source.smoothingTimeConstant = normalizeSmoothing(api.config.smoothing);
|
|
7753
|
+
}
|
|
7754
|
+
}, [api.config.smoothing, source]);
|
|
7755
|
+
React11__namespace.useEffect(() => {
|
|
7756
|
+
const root = rootRef.current;
|
|
7757
|
+
const canvas = canvasRef.current;
|
|
7758
|
+
if (!root || !canvas) return;
|
|
7759
|
+
let size = measureWaveform(root, api.config.width, api.config.height);
|
|
7760
|
+
let frame = null;
|
|
7761
|
+
let disposed = false;
|
|
7762
|
+
const cancelFrame = () => {
|
|
7763
|
+
if (frame == null) return;
|
|
7764
|
+
if (typeof window.requestAnimationFrame === "function") {
|
|
7765
|
+
window.cancelAnimationFrame(frame);
|
|
7766
|
+
} else {
|
|
7767
|
+
clearTimeout(frame);
|
|
7768
|
+
}
|
|
7769
|
+
frame = null;
|
|
7770
|
+
};
|
|
7771
|
+
const readSamples = (phase = 0) => {
|
|
7772
|
+
if (samples != null) {
|
|
7773
|
+
return normalizeWaveformSamples(samples, api.config.barCount);
|
|
7774
|
+
}
|
|
7775
|
+
if (isWaveformSampleInput(source)) {
|
|
7776
|
+
return normalizeWaveformSamples(source, api.config.barCount);
|
|
7777
|
+
}
|
|
7778
|
+
const analyser = isAnalyserSource(source) ? source : mediaAnalyserRef.current;
|
|
7779
|
+
if (analyser) {
|
|
7780
|
+
return readAnalyserSamples(analyser, api.config.barCount, floatBufferRef, byteBufferRef);
|
|
7781
|
+
}
|
|
7782
|
+
return createIntensitySamples(api.config.intensity, api.config.barCount, phase);
|
|
7783
|
+
};
|
|
7784
|
+
const draw = (time = typeof performance === "undefined" ? 0 : performance.now()) => {
|
|
7785
|
+
const context = prepareWaveformCanvas(canvas, {
|
|
7786
|
+
...size,
|
|
7787
|
+
pixelRatio: window.devicePixelRatio || 1
|
|
7788
|
+
});
|
|
7789
|
+
if (!context) return;
|
|
7790
|
+
const nextSamples = readSamples(time / 1e3);
|
|
7791
|
+
const renderedSamples = smoothWaveformSamples(
|
|
7792
|
+
previousSamplesRef.current ?? void 0,
|
|
7793
|
+
nextSamples,
|
|
7794
|
+
api.config.smoothing
|
|
7795
|
+
);
|
|
7796
|
+
previousSamplesRef.current = renderedSamples;
|
|
7797
|
+
drawWaveform(context, renderedSamples, size, {
|
|
7798
|
+
variant: api.config.variant,
|
|
7799
|
+
color: resolveCanvasColor(root, api.config.color),
|
|
7800
|
+
intensity: api.config.intensity,
|
|
7801
|
+
amplitude: api.config.amplitude,
|
|
7802
|
+
barCount: api.config.barCount
|
|
7803
|
+
});
|
|
7804
|
+
};
|
|
7805
|
+
const schedule = () => {
|
|
7806
|
+
if (disposed || api.config.paused || prefersReducedMotion) return;
|
|
7807
|
+
if (typeof window.requestAnimationFrame === "function") {
|
|
7808
|
+
frame = window.requestAnimationFrame(tick);
|
|
7809
|
+
} else {
|
|
7810
|
+
frame = window.setTimeout(() => tick(performance.now()), 16);
|
|
7811
|
+
}
|
|
7812
|
+
};
|
|
7813
|
+
const tick = (time) => {
|
|
7814
|
+
draw(time);
|
|
7815
|
+
schedule();
|
|
7816
|
+
};
|
|
7817
|
+
draw();
|
|
7818
|
+
schedule();
|
|
7819
|
+
const observer = typeof ResizeObserver === "function" ? new ResizeObserver(() => {
|
|
7820
|
+
size = measureWaveform(root, api.config.width, api.config.height);
|
|
7821
|
+
draw();
|
|
7822
|
+
}) : null;
|
|
7823
|
+
observer?.observe(root);
|
|
7824
|
+
return () => {
|
|
7825
|
+
disposed = true;
|
|
7826
|
+
cancelFrame();
|
|
7827
|
+
observer?.disconnect();
|
|
7828
|
+
};
|
|
7829
|
+
}, [
|
|
7830
|
+
api.config.barCount,
|
|
7831
|
+
api.config.color,
|
|
7832
|
+
api.config.height,
|
|
7833
|
+
api.config.intensity,
|
|
7834
|
+
api.config.amplitude,
|
|
7835
|
+
api.config.paused,
|
|
7836
|
+
api.config.smoothing,
|
|
7837
|
+
api.config.variant,
|
|
7838
|
+
api.config.width,
|
|
7839
|
+
prefersReducedMotion,
|
|
7840
|
+
samples,
|
|
7841
|
+
source
|
|
7842
|
+
]);
|
|
7843
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
7844
|
+
"div",
|
|
7845
|
+
{
|
|
7846
|
+
ref: setRootRef,
|
|
7847
|
+
className: cn(waveformVariants({ variant: api.config.variant }), className),
|
|
7848
|
+
style: rootStyle,
|
|
7849
|
+
...api.ariaProps,
|
|
7850
|
+
...api.dataAttributes,
|
|
7851
|
+
...props,
|
|
7852
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
7853
|
+
"canvas",
|
|
7854
|
+
{
|
|
7855
|
+
ref: canvasRef,
|
|
7856
|
+
className: waveformCanvasVariants(),
|
|
7857
|
+
"aria-hidden": "true",
|
|
7858
|
+
"data-waveform-canvas": ""
|
|
7859
|
+
}
|
|
7860
|
+
)
|
|
7861
|
+
}
|
|
7862
|
+
);
|
|
7863
|
+
}
|
|
7864
|
+
);
|
|
7865
|
+
Waveform.displayName = "Waveform";
|
|
7866
|
+
function usePrefersReducedMotion() {
|
|
7867
|
+
const [prefersReducedMotion, setPrefersReducedMotion] = React11__namespace.useState(false);
|
|
7868
|
+
React11__namespace.useEffect(() => {
|
|
7869
|
+
if (typeof window === "undefined" || typeof window.matchMedia !== "function") {
|
|
7870
|
+
return;
|
|
7871
|
+
}
|
|
7872
|
+
const media = window.matchMedia("(prefers-reduced-motion: reduce)");
|
|
7873
|
+
const update = () => setPrefersReducedMotion(media.matches);
|
|
7874
|
+
update();
|
|
7875
|
+
media.addEventListener?.("change", update);
|
|
7876
|
+
return () => {
|
|
7877
|
+
media.removeEventListener?.("change", update);
|
|
7878
|
+
};
|
|
7879
|
+
}, []);
|
|
7880
|
+
return prefersReducedMotion;
|
|
7881
|
+
}
|
|
7882
|
+
function readAnalyserSamples(analyser, barCount, floatBufferRef, byteBufferRef) {
|
|
7883
|
+
if (typeof analyser.getFloatTimeDomainData === "function") {
|
|
7884
|
+
const length2 = Math.max(1, analyser.fftSize || analyser.frequencyBinCount || barCount);
|
|
7885
|
+
if (floatBufferRef.current?.length !== length2) {
|
|
7886
|
+
floatBufferRef.current = new Float32Array(length2);
|
|
7887
|
+
}
|
|
7888
|
+
analyser.getFloatTimeDomainData(floatBufferRef.current);
|
|
7889
|
+
return normalizeWaveformSamples(floatBufferRef.current, barCount);
|
|
7890
|
+
}
|
|
7891
|
+
const length = Math.max(1, analyser.frequencyBinCount || barCount);
|
|
7892
|
+
if (byteBufferRef.current?.length !== length) {
|
|
7893
|
+
byteBufferRef.current = new Uint8Array(length);
|
|
7894
|
+
}
|
|
7895
|
+
analyser.getByteFrequencyData(byteBufferRef.current);
|
|
7896
|
+
return normalizeWaveformSamples(Array.from(byteBufferRef.current), barCount);
|
|
7897
|
+
}
|
|
7898
|
+
function measureWaveform(element, width, height) {
|
|
7899
|
+
const rect = element.getBoundingClientRect();
|
|
7900
|
+
const fallbackWidth = typeof width === "number" ? width : 300;
|
|
7901
|
+
const fallbackHeight = typeof height === "number" ? height : 80;
|
|
7902
|
+
return {
|
|
7903
|
+
width: Math.max(1, Math.round(rect.width || element.clientWidth || fallbackWidth)),
|
|
7904
|
+
height: Math.max(1, Math.round(rect.height || element.clientHeight || fallbackHeight))
|
|
7905
|
+
};
|
|
7906
|
+
}
|
|
7907
|
+
function resolveCanvasColor(element, color) {
|
|
7908
|
+
const variableMatch = color.match(/^var\((--[^),\s]+)(?:,[^)]+)?\)$/);
|
|
7909
|
+
if (!variableMatch || typeof window.getComputedStyle !== "function") {
|
|
7910
|
+
return color;
|
|
7911
|
+
}
|
|
7912
|
+
const value = window.getComputedStyle(element).getPropertyValue(variableMatch[1]).trim();
|
|
7913
|
+
return value || color;
|
|
7914
|
+
}
|
|
7915
|
+
function isAnalyserSource(value) {
|
|
7916
|
+
return value != null && typeof value.frequencyBinCount === "number" && (typeof value.getFloatTimeDomainData === "function" || typeof value.getByteFrequencyData === "function");
|
|
7917
|
+
}
|
|
7918
|
+
function isMediaStreamSource(value) {
|
|
7919
|
+
return value != null && typeof value.getTracks === "function";
|
|
7920
|
+
}
|
|
7921
|
+
|
|
7117
7922
|
// ../progress-display/dist/index.js
|
|
7118
7923
|
function createProgressDisplay(props) {
|
|
7119
7924
|
const { stats, badges } = props;
|
|
@@ -8067,7 +8872,7 @@ function VersionSelector({
|
|
|
8067
8872
|
VersionSelector.displayName = "VersionSelector";
|
|
8068
8873
|
|
|
8069
8874
|
// ../resizable-layout/dist/index.js
|
|
8070
|
-
function
|
|
8875
|
+
function clamp2(value, min, max) {
|
|
8071
8876
|
return Math.min(Math.max(value, min), max);
|
|
8072
8877
|
}
|
|
8073
8878
|
function createResizableLayout(props = {}) {
|
|
@@ -8122,9 +8927,9 @@ function createResizableLayout(props = {}) {
|
|
|
8122
8927
|
if (j >= sizes.length) return;
|
|
8123
8928
|
const totalAvailable = sizesBeforeResize[i] + sizesBeforeResize[j];
|
|
8124
8929
|
let newSizeI = sizesBeforeResize[i] + delta;
|
|
8125
|
-
newSizeI =
|
|
8930
|
+
newSizeI = clamp2(newSizeI, getMinSize(i), getMaxSize(i));
|
|
8126
8931
|
let newSizeJ = totalAvailable - newSizeI;
|
|
8127
|
-
newSizeJ =
|
|
8932
|
+
newSizeJ = clamp2(newSizeJ, getMinSize(j), getMaxSize(j));
|
|
8128
8933
|
newSizeI = totalAvailable - newSizeJ;
|
|
8129
8934
|
sizes[i] = newSizeI;
|
|
8130
8935
|
sizes[j] = newSizeJ;
|
|
@@ -12928,6 +13733,13 @@ exports.CommandItem = CommandItem;
|
|
|
12928
13733
|
exports.CommandList = CommandList;
|
|
12929
13734
|
exports.CommandSeparator = CommandSeparator;
|
|
12930
13735
|
exports.ContentProtection = ContentProtection;
|
|
13736
|
+
exports.DEFAULT_VOICE_PILL_POSITION = DEFAULT_VOICE_PILL_POSITION;
|
|
13737
|
+
exports.DEFAULT_VOICE_PILL_SPEAKER = DEFAULT_VOICE_PILL_SPEAKER;
|
|
13738
|
+
exports.DEFAULT_WAVEFORM_BAR_COUNT = DEFAULT_WAVEFORM_BAR_COUNT;
|
|
13739
|
+
exports.DEFAULT_WAVEFORM_COLOR = DEFAULT_WAVEFORM_COLOR;
|
|
13740
|
+
exports.DEFAULT_WAVEFORM_HEIGHT = DEFAULT_WAVEFORM_HEIGHT;
|
|
13741
|
+
exports.DEFAULT_WAVEFORM_INTENSITY = DEFAULT_WAVEFORM_INTENSITY;
|
|
13742
|
+
exports.DEFAULT_WAVEFORM_SMOOTHING = DEFAULT_WAVEFORM_SMOOTHING;
|
|
12931
13743
|
exports.DataTable = DataTable;
|
|
12932
13744
|
exports.DatePicker = DatePicker;
|
|
12933
13745
|
exports.DeviceFrame = DeviceFrame;
|
|
@@ -13050,6 +13862,8 @@ exports.TooltipTrigger = TooltipTrigger;
|
|
|
13050
13862
|
exports.TypewriterText = TypewriterText;
|
|
13051
13863
|
exports.VersionSelector = VersionSelector;
|
|
13052
13864
|
exports.VideoPlayer = VideoPlayer;
|
|
13865
|
+
exports.VoicePill = VoicePill;
|
|
13866
|
+
exports.Waveform = Waveform;
|
|
13053
13867
|
exports.altHintState = altHintState;
|
|
13054
13868
|
exports.animatedTextVariants = animatedTextVariants;
|
|
13055
13869
|
exports.avatarFallbackVariants = avatarFallbackVariants;
|
|
@@ -13080,6 +13894,7 @@ exports.cellVariants = cellVariants;
|
|
|
13080
13894
|
exports.checkIconPath = checkIconPath;
|
|
13081
13895
|
exports.checkboxTokens = checkboxTokens;
|
|
13082
13896
|
exports.checkboxVariants = checkboxVariants;
|
|
13897
|
+
exports.clampVoicePillIntensity = clampVoicePillIntensity;
|
|
13083
13898
|
exports.codeEditorTokens = codeEditorTokens;
|
|
13084
13899
|
exports.codeEditorVariants = codeEditorVariants;
|
|
13085
13900
|
exports.collapsibleContentVariants = collapsibleContentVariants;
|
|
@@ -13095,9 +13910,14 @@ exports.commandItemVariants = commandItemVariants;
|
|
|
13095
13910
|
exports.commandVariants = commandVariants;
|
|
13096
13911
|
exports.contentProtectionVariants = contentProtectionVariants;
|
|
13097
13912
|
exports.controlsVariants = controlsVariants;
|
|
13913
|
+
exports.createIntensitySamples = createIntensitySamples;
|
|
13914
|
+
exports.createSilentSamples = createSilentSamples;
|
|
13915
|
+
exports.createVoicePill = createVoicePill;
|
|
13916
|
+
exports.createWaveform = createWaveform;
|
|
13098
13917
|
exports.dayVariants = dayVariants;
|
|
13099
13918
|
exports.deviceFrameVariants = deviceFrameVariants;
|
|
13100
13919
|
exports.dialogContentVariants = dialogContentVariants;
|
|
13920
|
+
exports.drawWaveform = drawWaveform;
|
|
13101
13921
|
exports.editorVariants = editorVariants;
|
|
13102
13922
|
exports.emojiPickerContainerStyles = emojiPickerContainerStyles;
|
|
13103
13923
|
exports.emojiPickerEmojiButtonStyles = emojiPickerEmojiButtonStyles;
|
|
@@ -13116,6 +13936,13 @@ exports.formatTimestamp = formatTimestamp;
|
|
|
13116
13936
|
exports.getAssignableRoles = getAssignableRoles;
|
|
13117
13937
|
exports.getDefaultPortal = getDefaultPortal;
|
|
13118
13938
|
exports.getInitials = getInitials;
|
|
13939
|
+
exports.getVoicePillAriaLabel = getVoicePillAriaLabel;
|
|
13940
|
+
exports.getVoicePillInitials = getVoicePillInitials;
|
|
13941
|
+
exports.getVoicePillPosition = getVoicePillPosition;
|
|
13942
|
+
exports.getVoicePillPulseStyle = getVoicePillPulseStyle;
|
|
13943
|
+
exports.getVoicePillSpeakerKey = getVoicePillSpeakerKey;
|
|
13944
|
+
exports.getVoicePillSpeakerLabel = getVoicePillSpeakerLabel;
|
|
13945
|
+
exports.getWaveformPeak = getWaveformPeak;
|
|
13119
13946
|
exports.globalShortcutRegistry = globalShortcutRegistry;
|
|
13120
13947
|
exports.hasAllRoles = hasAllRoles;
|
|
13121
13948
|
exports.hasAnyRole = hasAnyRole;
|
|
@@ -13128,6 +13955,7 @@ exports.inputGroupTokens = inputGroupTokens;
|
|
|
13128
13955
|
exports.inputGroupVariants = inputGroupVariants;
|
|
13129
13956
|
exports.inputVariants = inputVariants;
|
|
13130
13957
|
exports.installPromptVariants = installPromptVariants;
|
|
13958
|
+
exports.isWaveformSampleInput = isWaveformSampleInput;
|
|
13131
13959
|
exports.latestBadgeVariants = latestBadgeVariants;
|
|
13132
13960
|
exports.markdownRendererTokens = markdownRendererTokens;
|
|
13133
13961
|
exports.menuContentVariants = menuContentVariants;
|
|
@@ -13139,6 +13967,11 @@ exports.mobileNavTriggerVariants = mobileNavTriggerVariants;
|
|
|
13139
13967
|
exports.mobileNavVariants = mobileNavVariants;
|
|
13140
13968
|
exports.navLinkVariants = navLinkVariants;
|
|
13141
13969
|
exports.navbarVariants = navbarVariants;
|
|
13970
|
+
exports.normalizeBarCount = normalizeBarCount;
|
|
13971
|
+
exports.normalizeIntensity = normalizeIntensity;
|
|
13972
|
+
exports.normalizeSmoothing = normalizeSmoothing;
|
|
13973
|
+
exports.normalizeWaveformConfig = normalizeWaveformConfig;
|
|
13974
|
+
exports.normalizeWaveformSamples = normalizeWaveformSamples;
|
|
13142
13975
|
exports.optionVariants = optionVariants;
|
|
13143
13976
|
exports.otpInputContainerVariants = otpInputContainerVariants;
|
|
13144
13977
|
exports.otpInputSlotVariants = otpInputSlotVariants;
|
|
@@ -13147,6 +13980,7 @@ exports.overlayStyles = overlayStyles;
|
|
|
13147
13980
|
exports.overlayVariants = overlayVariants;
|
|
13148
13981
|
exports.playerVariants = playerVariants;
|
|
13149
13982
|
exports.popoverContentVariants = popoverContentVariants;
|
|
13983
|
+
exports.prepareWaveformCanvas = prepareWaveformCanvas;
|
|
13150
13984
|
exports.previewVariants = previewVariants;
|
|
13151
13985
|
exports.progressBarVariants = progressBarVariants;
|
|
13152
13986
|
exports.proseVariants = proseVariants;
|
|
@@ -13158,11 +13992,13 @@ exports.reactionBarStyles = reactionBarStyles;
|
|
|
13158
13992
|
exports.reactionCountStyles = reactionCountStyles;
|
|
13159
13993
|
exports.reactionEmojiStyles = reactionEmojiStyles;
|
|
13160
13994
|
exports.reactionPillVariants = reactionPillVariants;
|
|
13995
|
+
exports.resampleWaveformSamples = resampleWaveformSamples;
|
|
13161
13996
|
exports.resizableDividerVariants = resizableDividerVariants;
|
|
13162
13997
|
exports.resizableLayoutTokens = resizableLayoutTokens;
|
|
13163
13998
|
exports.resizableLayoutVariants = resizableLayoutVariants;
|
|
13164
13999
|
exports.resizablePaneVariants = resizablePaneVariants;
|
|
13165
14000
|
exports.rowVariants = rowVariants;
|
|
14001
|
+
exports.scaleWaveformSamples = scaleWaveformSamples;
|
|
13166
14002
|
exports.searchBarVariants = searchBarVariants;
|
|
13167
14003
|
exports.searchResultVariants = searchResultVariants;
|
|
13168
14004
|
exports.selectContentVariants = selectContentVariants;
|
|
@@ -13182,6 +14018,7 @@ exports.slideTypeBadgeVariants = slideTypeBadgeVariants;
|
|
|
13182
14018
|
exports.slideViewerProgressBarVariants = slideViewerProgressBarVariants;
|
|
13183
14019
|
exports.slideViewerTokens = slideViewerTokens;
|
|
13184
14020
|
exports.slideViewerVariants = slideViewerVariants;
|
|
14021
|
+
exports.smoothWaveformSamples = smoothWaveformSamples;
|
|
13185
14022
|
exports.statCardVariants = statCardVariants;
|
|
13186
14023
|
exports.statsGridVariants = statsGridVariants;
|
|
13187
14024
|
exports.statusContainerStyles = statusContainerStyles;
|
|
@@ -13203,6 +14040,7 @@ exports.threadContentStyles = threadContentStyles;
|
|
|
13203
14040
|
exports.threadMessageStyles = threadMessageStyles;
|
|
13204
14041
|
exports.threadReactionsStyles = threadReactionsStyles;
|
|
13205
14042
|
exports.threadTimestampStyles = threadTimestampStyles;
|
|
14043
|
+
exports.toCssDimension = toCssDimension;
|
|
13206
14044
|
exports.toastVariants = toastVariants;
|
|
13207
14045
|
exports.toolbarVariants = toolbarVariants;
|
|
13208
14046
|
exports.tooltipContentVariants = tooltipContentVariants;
|
|
@@ -13213,6 +14051,19 @@ exports.useShortcut = useShortcut;
|
|
|
13213
14051
|
exports.useToast = useToast;
|
|
13214
14052
|
exports.versionSelectorOptionVariants = versionSelectorOptionVariants;
|
|
13215
14053
|
exports.versionSelectorVariants = versionSelectorVariants;
|
|
14054
|
+
exports.voicePillAvatarStyles = voicePillAvatarStyles;
|
|
14055
|
+
exports.voicePillAvatarWrapStyles = voicePillAvatarWrapStyles;
|
|
14056
|
+
exports.voicePillLabelStyles = voicePillLabelStyles;
|
|
14057
|
+
exports.voicePillMuteButtonStyles = voicePillMuteButtonStyles;
|
|
14058
|
+
exports.voicePillPositionVariants = voicePillPositionVariants;
|
|
14059
|
+
exports.voicePillPulseRingStyles = voicePillPulseRingStyles;
|
|
14060
|
+
exports.voicePillRootStyles = voicePillRootStyles;
|
|
14061
|
+
exports.voicePillSpeakerStyles = voicePillSpeakerStyles;
|
|
14062
|
+
exports.voicePillSubStyles = voicePillSubStyles;
|
|
14063
|
+
exports.voicePillTextStyles = voicePillTextStyles;
|
|
14064
|
+
exports.voicePillTokens = voicePillTokens;
|
|
13216
14065
|
exports.watermarkVariants = watermarkVariants;
|
|
14066
|
+
exports.waveformCanvasVariants = waveformCanvasVariants;
|
|
14067
|
+
exports.waveformVariants = waveformVariants;
|
|
13217
14068
|
//# sourceMappingURL=index.cjs.map
|
|
13218
14069
|
//# sourceMappingURL=index.cjs.map
|