@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 CHANGED
@@ -7246,21 +7246,22 @@ var voicePillTokens = {
7246
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
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
7248
  var voicePillPositionVariants = cva({
7249
- base: "fixed z-50",
7249
+ base: "z-50",
7250
7250
  variants: {
7251
7251
  position: {
7252
- "top-start": "top-[calc(env(safe-area-inset-top)+1rem)] left-[calc(env(safe-area-inset-left)+1rem)]",
7253
- "top-center": "top-[calc(env(safe-area-inset-top)+1rem)] left-1/2 -translate-x-1/2",
7254
- "top-end": "top-[calc(env(safe-area-inset-top)+1rem)] right-[calc(env(safe-area-inset-right)+1rem)]",
7255
- "bottom-start": "bottom-[calc(env(safe-area-inset-bottom)+1rem)] left-[calc(env(safe-area-inset-left)+1rem)]",
7256
- "bottom-center": "bottom-[calc(env(safe-area-inset-bottom)+1rem)] left-1/2 -translate-x-1/2",
7257
- "bottom-end": "bottom-[calc(env(safe-area-inset-bottom)+1rem)] right-[calc(env(safe-area-inset-right)+1rem)]",
7258
- "left-start": "left-[calc(env(safe-area-inset-left)+1rem)] top-[calc(env(safe-area-inset-top)+1rem)]",
7259
- "left-center": "left-[calc(env(safe-area-inset-left)+1rem)] top-1/2 -translate-y-1/2",
7260
- "left-end": "left-[calc(env(safe-area-inset-left)+1rem)] bottom-[calc(env(safe-area-inset-bottom)+1rem)]",
7261
- "right-start": "right-[calc(env(safe-area-inset-right)+1rem)] top-[calc(env(safe-area-inset-top)+1rem)]",
7262
- "right-center": "right-[calc(env(safe-area-inset-right)+1rem)] top-1/2 -translate-y-1/2",
7263
- "right-end": "right-[calc(env(safe-area-inset-right)+1rem)] bottom-[calc(env(safe-area-inset-bottom)+1rem)]"
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)]"
7264
7265
  }
7265
7266
  },
7266
7267
  defaultVariants: {
@@ -7401,6 +7402,7 @@ var DEFAULT_WAVEFORM_BAR_COUNT = 48;
7401
7402
  var DEFAULT_WAVEFORM_COLOR = "var(--accent-2)";
7402
7403
  var DEFAULT_WAVEFORM_HEIGHT = 80;
7403
7404
  var DEFAULT_WAVEFORM_INTENSITY = 1;
7405
+ var DEFAULT_WAVEFORM_AMPLITUDE = 1;
7404
7406
  var DEFAULT_WAVEFORM_SMOOTHING = 0.8;
7405
7407
  var MAX_BAR_COUNT = 1024;
7406
7408
  var MAX_INTENSITY = 1;
@@ -7416,10 +7418,15 @@ function normalizeIntensity(value) {
7416
7418
  if (value == null || !Number.isFinite(value)) return DEFAULT_WAVEFORM_INTENSITY;
7417
7419
  return Math.min(MAX_INTENSITY, Math.max(0, value));
7418
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
+ }
7419
7425
  function normalizeWaveformConfig(props = {}) {
7420
7426
  return {
7421
7427
  variant: props.variant ?? "bars",
7422
7428
  intensity: normalizeIntensity(props.intensity),
7429
+ amplitude: normalizeAmplitude(props.amplitude),
7423
7430
  height: props.height ?? DEFAULT_WAVEFORM_HEIGHT,
7424
7431
  width: props.width ?? "100%",
7425
7432
  barCount: normalizeBarCount(props.barCount),
@@ -7434,16 +7441,17 @@ function isWaveformSampleInput(value) {
7434
7441
  function createSilentSamples(count = DEFAULT_WAVEFORM_BAR_COUNT) {
7435
7442
  return new Float32Array(normalizeBarCount(count));
7436
7443
  }
7437
- function createIntensitySamples(intensity = DEFAULT_WAVEFORM_INTENSITY, count = DEFAULT_WAVEFORM_BAR_COUNT) {
7444
+ function createIntensitySamples(intensity = DEFAULT_WAVEFORM_INTENSITY, count = DEFAULT_WAVEFORM_BAR_COUNT, phase = 0) {
7438
7445
  const normalizedIntensity = normalizeIntensity(intensity);
7439
7446
  const normalizedCount = normalizeBarCount(count);
7440
7447
  const samples = new Float32Array(normalizedCount);
7441
7448
  if (normalizedIntensity === 0) return samples;
7449
+ const pulse = 0.72 + Math.sin(phase * 1.8) * 0.18;
7442
7450
  for (let i = 0; i < normalizedCount; i += 1) {
7443
7451
  const progress = normalizedCount <= 1 ? 0.5 : i / (normalizedCount - 1);
7444
7452
  const envelope = 0.35 + Math.sin(progress * Math.PI) * 0.65;
7445
- const carrier = Math.sin(progress * Math.PI * 6);
7446
- samples[i] = carrier * envelope * normalizedIntensity;
7453
+ const carrier = Math.sin(progress * Math.PI * 6 + phase * 2.8);
7454
+ samples[i] = carrier * envelope * normalizedIntensity * pulse;
7447
7455
  }
7448
7456
  return samples;
7449
7457
  }
@@ -7567,36 +7575,37 @@ function drawWaveform(context, samples, size, options = {}) {
7567
7575
  const variant = options.variant ?? "bars";
7568
7576
  const color = options.color ?? DEFAULT_WAVEFORM_COLOR;
7569
7577
  const intensity = normalizeIntensity(options.intensity ?? DEFAULT_WAVEFORM_INTENSITY);
7578
+ const amplitude = normalizeAmplitude(options.amplitude ?? DEFAULT_WAVEFORM_AMPLITUDE);
7570
7579
  const barCount = normalizeBarCount(options.barCount);
7571
7580
  context.clearRect(0, 0, width, height);
7572
7581
  applyCanvasColor(context, color);
7573
7582
  if (variant === "line") {
7574
- drawLine(context, samples, width, height, intensity);
7583
+ drawLine(context, samples, width, height, intensity, amplitude);
7575
7584
  return;
7576
7585
  }
7577
7586
  if (variant === "rings") {
7578
- drawRings(context, samples, width, height, intensity);
7587
+ drawRings(context, samples, width, height, intensity, amplitude);
7579
7588
  return;
7580
7589
  }
7581
- drawBars(context, samples, width, height, intensity, barCount);
7590
+ drawBars(context, samples, width, height, intensity, amplitude, barCount);
7582
7591
  }
7583
- function drawBars(context, samples, width, height, intensity, barCount) {
7592
+ function drawBars(context, samples, width, height, intensity, amplitude, barCount) {
7584
7593
  const bars = scaleWaveformSamples(resampleWaveformSamples(samples, barCount), intensity);
7585
7594
  const slotWidth = width / bars.length;
7586
7595
  const barWidth = Math.max(1, slotWidth * 0.64);
7587
7596
  const center = height / 2;
7588
7597
  for (let i = 0; i < bars.length; i += 1) {
7589
7598
  const value = Math.abs(bars[i]);
7590
- const barHeight = Math.max(value * height, value > 0 ? 1 : 0);
7599
+ const barHeight = Math.max(value * height * amplitude, value > 0 ? 1 : 0);
7591
7600
  const x = i * slotWidth + (slotWidth - barWidth) / 2;
7592
7601
  const y = center - barHeight / 2;
7593
7602
  context.fillRect(x, y, barWidth, barHeight);
7594
7603
  }
7595
7604
  }
7596
- function drawLine(context, samples, width, height, intensity) {
7605
+ function drawLine(context, samples, width, height, intensity, amplitudeScale) {
7597
7606
  const lineSamples = scaleWaveformSamples(samples, intensity);
7598
7607
  const center = height / 2;
7599
- const amplitude = height * 0.45;
7608
+ const amplitude = height * 0.45 * amplitudeScale;
7600
7609
  context.beginPath();
7601
7610
  for (let i = 0; i < lineSamples.length; i += 1) {
7602
7611
  const x = lineSamples.length <= 1 ? width / 2 : i / (lineSamples.length - 1) * width;
@@ -7612,8 +7621,8 @@ function drawLine(context, samples, width, height, intensity) {
7612
7621
  context.lineJoin = "round";
7613
7622
  context.stroke();
7614
7623
  }
7615
- function drawRings(context, samples, width, height, intensity) {
7616
- const peak = getWaveformPeak(scaleWaveformSamples(samples, intensity));
7624
+ function drawRings(context, samples, width, height, intensity, amplitude) {
7625
+ const peak = getWaveformPeak(scaleWaveformSamples(samples, intensity)) * amplitude;
7617
7626
  const minDimension = Math.min(width, height);
7618
7627
  const centerX = width / 2;
7619
7628
  const centerY = height / 2;
@@ -7663,6 +7672,7 @@ var Waveform = React11__namespace.forwardRef(
7663
7672
  source,
7664
7673
  samples,
7665
7674
  intensity,
7675
+ amplitude,
7666
7676
  variant,
7667
7677
  height,
7668
7678
  width,
@@ -7685,6 +7695,7 @@ var Waveform = React11__namespace.forwardRef(
7685
7695
  source,
7686
7696
  samples,
7687
7697
  intensity,
7698
+ amplitude,
7688
7699
  variant,
7689
7700
  height,
7690
7701
  width,
@@ -7757,7 +7768,7 @@ var Waveform = React11__namespace.forwardRef(
7757
7768
  }
7758
7769
  frame = null;
7759
7770
  };
7760
- const readSamples = () => {
7771
+ const readSamples = (phase = 0) => {
7761
7772
  if (samples != null) {
7762
7773
  return normalizeWaveformSamples(samples, api.config.barCount);
7763
7774
  }
@@ -7768,15 +7779,15 @@ var Waveform = React11__namespace.forwardRef(
7768
7779
  if (analyser) {
7769
7780
  return readAnalyserSamples(analyser, api.config.barCount, floatBufferRef, byteBufferRef);
7770
7781
  }
7771
- return createIntensitySamples(api.config.intensity, api.config.barCount);
7782
+ return createIntensitySamples(api.config.intensity, api.config.barCount, phase);
7772
7783
  };
7773
- const draw = () => {
7784
+ const draw = (time = typeof performance === "undefined" ? 0 : performance.now()) => {
7774
7785
  const context = prepareWaveformCanvas(canvas, {
7775
7786
  ...size,
7776
7787
  pixelRatio: window.devicePixelRatio || 1
7777
7788
  });
7778
7789
  if (!context) return;
7779
- const nextSamples = readSamples();
7790
+ const nextSamples = readSamples(time / 1e3);
7780
7791
  const renderedSamples = smoothWaveformSamples(
7781
7792
  previousSamplesRef.current ?? void 0,
7782
7793
  nextSamples,
@@ -7787,6 +7798,7 @@ var Waveform = React11__namespace.forwardRef(
7787
7798
  variant: api.config.variant,
7788
7799
  color: resolveCanvasColor(root, api.config.color),
7789
7800
  intensity: api.config.intensity,
7801
+ amplitude: api.config.amplitude,
7790
7802
  barCount: api.config.barCount
7791
7803
  });
7792
7804
  };
@@ -7795,11 +7807,11 @@ var Waveform = React11__namespace.forwardRef(
7795
7807
  if (typeof window.requestAnimationFrame === "function") {
7796
7808
  frame = window.requestAnimationFrame(tick);
7797
7809
  } else {
7798
- frame = window.setTimeout(() => tick(), 16);
7810
+ frame = window.setTimeout(() => tick(performance.now()), 16);
7799
7811
  }
7800
7812
  };
7801
- const tick = () => {
7802
- draw();
7813
+ const tick = (time) => {
7814
+ draw(time);
7803
7815
  schedule();
7804
7816
  };
7805
7817
  draw();
@@ -7819,6 +7831,7 @@ var Waveform = React11__namespace.forwardRef(
7819
7831
  api.config.color,
7820
7832
  api.config.height,
7821
7833
  api.config.intensity,
7834
+ api.config.amplitude,
7822
7835
  api.config.paused,
7823
7836
  api.config.smoothing,
7824
7837
  api.config.variant,