@refraction-ui/react 0.4.1 → 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 +45 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +45 -32
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7225,21 +7225,22 @@ var voicePillTokens = {
|
|
|
7225
7225
|
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";
|
|
7226
7226
|
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))]";
|
|
7227
7227
|
var voicePillPositionVariants = cva({
|
|
7228
|
-
base: "
|
|
7228
|
+
base: "z-50",
|
|
7229
7229
|
variants: {
|
|
7230
7230
|
position: {
|
|
7231
|
-
|
|
7232
|
-
"top-
|
|
7233
|
-
"top-
|
|
7234
|
-
"
|
|
7235
|
-
"bottom-
|
|
7236
|
-
"bottom-
|
|
7237
|
-
"
|
|
7238
|
-
"left-
|
|
7239
|
-
"left-
|
|
7240
|
-
"
|
|
7241
|
-
"right-
|
|
7242
|
-
"right-
|
|
7231
|
+
inline: "relative",
|
|
7232
|
+
"top-start": "fixed top-[calc(env(safe-area-inset-top)+1rem)] left-[calc(env(safe-area-inset-left)+1rem)]",
|
|
7233
|
+
"top-center": "fixed top-[calc(env(safe-area-inset-top)+1rem)] left-1/2 -translate-x-1/2",
|
|
7234
|
+
"top-end": "fixed top-[calc(env(safe-area-inset-top)+1rem)] right-[calc(env(safe-area-inset-right)+1rem)]",
|
|
7235
|
+
"bottom-start": "fixed bottom-[calc(env(safe-area-inset-bottom)+1rem)] left-[calc(env(safe-area-inset-left)+1rem)]",
|
|
7236
|
+
"bottom-center": "fixed bottom-[calc(env(safe-area-inset-bottom)+1rem)] left-1/2 -translate-x-1/2",
|
|
7237
|
+
"bottom-end": "fixed bottom-[calc(env(safe-area-inset-bottom)+1rem)] right-[calc(env(safe-area-inset-right)+1rem)]",
|
|
7238
|
+
"left-start": "fixed left-[calc(env(safe-area-inset-left)+1rem)] top-[calc(env(safe-area-inset-top)+1rem)]",
|
|
7239
|
+
"left-center": "fixed left-[calc(env(safe-area-inset-left)+1rem)] top-1/2 -translate-y-1/2",
|
|
7240
|
+
"left-end": "fixed left-[calc(env(safe-area-inset-left)+1rem)] bottom-[calc(env(safe-area-inset-bottom)+1rem)]",
|
|
7241
|
+
"right-start": "fixed right-[calc(env(safe-area-inset-right)+1rem)] top-[calc(env(safe-area-inset-top)+1rem)]",
|
|
7242
|
+
"right-center": "fixed right-[calc(env(safe-area-inset-right)+1rem)] top-1/2 -translate-y-1/2",
|
|
7243
|
+
"right-end": "fixed right-[calc(env(safe-area-inset-right)+1rem)] bottom-[calc(env(safe-area-inset-bottom)+1rem)]"
|
|
7243
7244
|
}
|
|
7244
7245
|
},
|
|
7245
7246
|
defaultVariants: {
|
|
@@ -7380,6 +7381,7 @@ var DEFAULT_WAVEFORM_BAR_COUNT = 48;
|
|
|
7380
7381
|
var DEFAULT_WAVEFORM_COLOR = "var(--accent-2)";
|
|
7381
7382
|
var DEFAULT_WAVEFORM_HEIGHT = 80;
|
|
7382
7383
|
var DEFAULT_WAVEFORM_INTENSITY = 1;
|
|
7384
|
+
var DEFAULT_WAVEFORM_AMPLITUDE = 1;
|
|
7383
7385
|
var DEFAULT_WAVEFORM_SMOOTHING = 0.8;
|
|
7384
7386
|
var MAX_BAR_COUNT = 1024;
|
|
7385
7387
|
var MAX_INTENSITY = 1;
|
|
@@ -7395,10 +7397,15 @@ function normalizeIntensity(value) {
|
|
|
7395
7397
|
if (value == null || !Number.isFinite(value)) return DEFAULT_WAVEFORM_INTENSITY;
|
|
7396
7398
|
return Math.min(MAX_INTENSITY, Math.max(0, value));
|
|
7397
7399
|
}
|
|
7400
|
+
function normalizeAmplitude(value) {
|
|
7401
|
+
if (value == null || !Number.isFinite(value)) return DEFAULT_WAVEFORM_AMPLITUDE;
|
|
7402
|
+
return Math.min(1, Math.max(0, value));
|
|
7403
|
+
}
|
|
7398
7404
|
function normalizeWaveformConfig(props = {}) {
|
|
7399
7405
|
return {
|
|
7400
7406
|
variant: props.variant ?? "bars",
|
|
7401
7407
|
intensity: normalizeIntensity(props.intensity),
|
|
7408
|
+
amplitude: normalizeAmplitude(props.amplitude),
|
|
7402
7409
|
height: props.height ?? DEFAULT_WAVEFORM_HEIGHT,
|
|
7403
7410
|
width: props.width ?? "100%",
|
|
7404
7411
|
barCount: normalizeBarCount(props.barCount),
|
|
@@ -7413,16 +7420,17 @@ function isWaveformSampleInput(value) {
|
|
|
7413
7420
|
function createSilentSamples(count = DEFAULT_WAVEFORM_BAR_COUNT) {
|
|
7414
7421
|
return new Float32Array(normalizeBarCount(count));
|
|
7415
7422
|
}
|
|
7416
|
-
function createIntensitySamples(intensity = DEFAULT_WAVEFORM_INTENSITY, count = DEFAULT_WAVEFORM_BAR_COUNT) {
|
|
7423
|
+
function createIntensitySamples(intensity = DEFAULT_WAVEFORM_INTENSITY, count = DEFAULT_WAVEFORM_BAR_COUNT, phase = 0) {
|
|
7417
7424
|
const normalizedIntensity = normalizeIntensity(intensity);
|
|
7418
7425
|
const normalizedCount = normalizeBarCount(count);
|
|
7419
7426
|
const samples = new Float32Array(normalizedCount);
|
|
7420
7427
|
if (normalizedIntensity === 0) return samples;
|
|
7428
|
+
const pulse = 0.72 + Math.sin(phase * 1.8) * 0.18;
|
|
7421
7429
|
for (let i = 0; i < normalizedCount; i += 1) {
|
|
7422
7430
|
const progress = normalizedCount <= 1 ? 0.5 : i / (normalizedCount - 1);
|
|
7423
7431
|
const envelope = 0.35 + Math.sin(progress * Math.PI) * 0.65;
|
|
7424
|
-
const carrier = Math.sin(progress * Math.PI * 6);
|
|
7425
|
-
samples[i] = carrier * envelope * normalizedIntensity;
|
|
7432
|
+
const carrier = Math.sin(progress * Math.PI * 6 + phase * 2.8);
|
|
7433
|
+
samples[i] = carrier * envelope * normalizedIntensity * pulse;
|
|
7426
7434
|
}
|
|
7427
7435
|
return samples;
|
|
7428
7436
|
}
|
|
@@ -7546,36 +7554,37 @@ function drawWaveform(context, samples, size, options = {}) {
|
|
|
7546
7554
|
const variant = options.variant ?? "bars";
|
|
7547
7555
|
const color = options.color ?? DEFAULT_WAVEFORM_COLOR;
|
|
7548
7556
|
const intensity = normalizeIntensity(options.intensity ?? DEFAULT_WAVEFORM_INTENSITY);
|
|
7557
|
+
const amplitude = normalizeAmplitude(options.amplitude ?? DEFAULT_WAVEFORM_AMPLITUDE);
|
|
7549
7558
|
const barCount = normalizeBarCount(options.barCount);
|
|
7550
7559
|
context.clearRect(0, 0, width, height);
|
|
7551
7560
|
applyCanvasColor(context, color);
|
|
7552
7561
|
if (variant === "line") {
|
|
7553
|
-
drawLine(context, samples, width, height, intensity);
|
|
7562
|
+
drawLine(context, samples, width, height, intensity, amplitude);
|
|
7554
7563
|
return;
|
|
7555
7564
|
}
|
|
7556
7565
|
if (variant === "rings") {
|
|
7557
|
-
drawRings(context, samples, width, height, intensity);
|
|
7566
|
+
drawRings(context, samples, width, height, intensity, amplitude);
|
|
7558
7567
|
return;
|
|
7559
7568
|
}
|
|
7560
|
-
drawBars(context, samples, width, height, intensity, barCount);
|
|
7569
|
+
drawBars(context, samples, width, height, intensity, amplitude, barCount);
|
|
7561
7570
|
}
|
|
7562
|
-
function drawBars(context, samples, width, height, intensity, barCount) {
|
|
7571
|
+
function drawBars(context, samples, width, height, intensity, amplitude, barCount) {
|
|
7563
7572
|
const bars = scaleWaveformSamples(resampleWaveformSamples(samples, barCount), intensity);
|
|
7564
7573
|
const slotWidth = width / bars.length;
|
|
7565
7574
|
const barWidth = Math.max(1, slotWidth * 0.64);
|
|
7566
7575
|
const center = height / 2;
|
|
7567
7576
|
for (let i = 0; i < bars.length; i += 1) {
|
|
7568
7577
|
const value = Math.abs(bars[i]);
|
|
7569
|
-
const barHeight = Math.max(value * height, value > 0 ? 1 : 0);
|
|
7578
|
+
const barHeight = Math.max(value * height * amplitude, value > 0 ? 1 : 0);
|
|
7570
7579
|
const x = i * slotWidth + (slotWidth - barWidth) / 2;
|
|
7571
7580
|
const y = center - barHeight / 2;
|
|
7572
7581
|
context.fillRect(x, y, barWidth, barHeight);
|
|
7573
7582
|
}
|
|
7574
7583
|
}
|
|
7575
|
-
function drawLine(context, samples, width, height, intensity) {
|
|
7584
|
+
function drawLine(context, samples, width, height, intensity, amplitudeScale) {
|
|
7576
7585
|
const lineSamples = scaleWaveformSamples(samples, intensity);
|
|
7577
7586
|
const center = height / 2;
|
|
7578
|
-
const amplitude = height * 0.45;
|
|
7587
|
+
const amplitude = height * 0.45 * amplitudeScale;
|
|
7579
7588
|
context.beginPath();
|
|
7580
7589
|
for (let i = 0; i < lineSamples.length; i += 1) {
|
|
7581
7590
|
const x = lineSamples.length <= 1 ? width / 2 : i / (lineSamples.length - 1) * width;
|
|
@@ -7591,8 +7600,8 @@ function drawLine(context, samples, width, height, intensity) {
|
|
|
7591
7600
|
context.lineJoin = "round";
|
|
7592
7601
|
context.stroke();
|
|
7593
7602
|
}
|
|
7594
|
-
function drawRings(context, samples, width, height, intensity) {
|
|
7595
|
-
const peak = getWaveformPeak(scaleWaveformSamples(samples, intensity));
|
|
7603
|
+
function drawRings(context, samples, width, height, intensity, amplitude) {
|
|
7604
|
+
const peak = getWaveformPeak(scaleWaveformSamples(samples, intensity)) * amplitude;
|
|
7596
7605
|
const minDimension = Math.min(width, height);
|
|
7597
7606
|
const centerX = width / 2;
|
|
7598
7607
|
const centerY = height / 2;
|
|
@@ -7642,6 +7651,7 @@ var Waveform = React11.forwardRef(
|
|
|
7642
7651
|
source,
|
|
7643
7652
|
samples,
|
|
7644
7653
|
intensity,
|
|
7654
|
+
amplitude,
|
|
7645
7655
|
variant,
|
|
7646
7656
|
height,
|
|
7647
7657
|
width,
|
|
@@ -7664,6 +7674,7 @@ var Waveform = React11.forwardRef(
|
|
|
7664
7674
|
source,
|
|
7665
7675
|
samples,
|
|
7666
7676
|
intensity,
|
|
7677
|
+
amplitude,
|
|
7667
7678
|
variant,
|
|
7668
7679
|
height,
|
|
7669
7680
|
width,
|
|
@@ -7736,7 +7747,7 @@ var Waveform = React11.forwardRef(
|
|
|
7736
7747
|
}
|
|
7737
7748
|
frame = null;
|
|
7738
7749
|
};
|
|
7739
|
-
const readSamples = () => {
|
|
7750
|
+
const readSamples = (phase = 0) => {
|
|
7740
7751
|
if (samples != null) {
|
|
7741
7752
|
return normalizeWaveformSamples(samples, api.config.barCount);
|
|
7742
7753
|
}
|
|
@@ -7747,15 +7758,15 @@ var Waveform = React11.forwardRef(
|
|
|
7747
7758
|
if (analyser) {
|
|
7748
7759
|
return readAnalyserSamples(analyser, api.config.barCount, floatBufferRef, byteBufferRef);
|
|
7749
7760
|
}
|
|
7750
|
-
return createIntensitySamples(api.config.intensity, api.config.barCount);
|
|
7761
|
+
return createIntensitySamples(api.config.intensity, api.config.barCount, phase);
|
|
7751
7762
|
};
|
|
7752
|
-
const draw = () => {
|
|
7763
|
+
const draw = (time = typeof performance === "undefined" ? 0 : performance.now()) => {
|
|
7753
7764
|
const context = prepareWaveformCanvas(canvas, {
|
|
7754
7765
|
...size,
|
|
7755
7766
|
pixelRatio: window.devicePixelRatio || 1
|
|
7756
7767
|
});
|
|
7757
7768
|
if (!context) return;
|
|
7758
|
-
const nextSamples = readSamples();
|
|
7769
|
+
const nextSamples = readSamples(time / 1e3);
|
|
7759
7770
|
const renderedSamples = smoothWaveformSamples(
|
|
7760
7771
|
previousSamplesRef.current ?? void 0,
|
|
7761
7772
|
nextSamples,
|
|
@@ -7766,6 +7777,7 @@ var Waveform = React11.forwardRef(
|
|
|
7766
7777
|
variant: api.config.variant,
|
|
7767
7778
|
color: resolveCanvasColor(root, api.config.color),
|
|
7768
7779
|
intensity: api.config.intensity,
|
|
7780
|
+
amplitude: api.config.amplitude,
|
|
7769
7781
|
barCount: api.config.barCount
|
|
7770
7782
|
});
|
|
7771
7783
|
};
|
|
@@ -7774,11 +7786,11 @@ var Waveform = React11.forwardRef(
|
|
|
7774
7786
|
if (typeof window.requestAnimationFrame === "function") {
|
|
7775
7787
|
frame = window.requestAnimationFrame(tick);
|
|
7776
7788
|
} else {
|
|
7777
|
-
frame = window.setTimeout(() => tick(), 16);
|
|
7789
|
+
frame = window.setTimeout(() => tick(performance.now()), 16);
|
|
7778
7790
|
}
|
|
7779
7791
|
};
|
|
7780
|
-
const tick = () => {
|
|
7781
|
-
draw();
|
|
7792
|
+
const tick = (time) => {
|
|
7793
|
+
draw(time);
|
|
7782
7794
|
schedule();
|
|
7783
7795
|
};
|
|
7784
7796
|
draw();
|
|
@@ -7798,6 +7810,7 @@ var Waveform = React11.forwardRef(
|
|
|
7798
7810
|
api.config.color,
|
|
7799
7811
|
api.config.height,
|
|
7800
7812
|
api.config.intensity,
|
|
7813
|
+
api.config.amplitude,
|
|
7801
7814
|
api.config.paused,
|
|
7802
7815
|
api.config.smoothing,
|
|
7803
7816
|
api.config.variant,
|