import{r as I}from"./position-CFNQy3J6.js";const _=`
// Cubic bezier easing (no closure allocation for hot-path performance)
function ease(x1, y1, x2, y2, t) {
  if (t <= 0) return 0;
  if (t >= 1) return 1;
  var lo = 0, hi = 1, s, u;
  for (var i = 0; i < 16; i++) {
    s = (lo + hi) * 0.5;
    u = 1 - s;
    if (3 * s * u * (u * x1 + s * x2) + s * s * s < t) lo = s; else hi = s;
  }
  s = (lo + hi) * 0.5;
  u = 1 - s;
  return 3 * s * u * (u * y1 + s * y2) + s * s * s;
}

// Evaluate cubic bezier path at parameter t in [0,1]
function bp(p, t) {
  var u = 1 - t, uu = u * u, tt = t * t;
  return [
    uu * u * p[0][0] + 3 * uu * t * p[1][0] + 3 * u * tt * p[2][0] + tt * t * p[3][0],
    uu * u * p[0][1] + 3 * uu * t * p[1][1] + 3 * u * tt * p[2][1] + tt * t * p[3][1]
  ];
}

// Keyframe interpolation with per-segment easing
// Frame format: [time, value] or [time, value, bezX1, bezY1, bezX2, bezY2]
// Easing on a keyframe affects transition FROM that keyframe to the next
function kf(f, t) {
  var n = f.length;
  if (t <= f[0][0]) return f[0][1];
  if (t >= f[n - 1][0]) return f[n - 1][1];
  for (var i = 0; i < n - 1; i++) {
    if (t < f[i + 1][0]) {
      var k = f[i];
      var st = (t - k[0]) / (f[i + 1][0] - k[0]);
      if (k.length > 2) st = ease(k[2], k[3], k[4], k[5], st);
      return k[1] + (f[i + 1][1] - k[1]) * st;
    }
  }
  return f[n - 1][1];
}

// Parse hex color to [r, g, b]
function hr(h) {
  return [parseInt(h.slice(1, 3), 16), parseInt(h.slice(3, 5), 16), parseInt(h.slice(5, 7), 16)];
}

// Color keyframe interpolation: [[time, hexColor], ...]
function ckf(f, t) {
  var n = f.length;
  if (t <= f[0][0]) return f[0][1];
  if (t >= f[n - 1][0]) return f[n - 1][1];
  for (var i = 0; i < n - 1; i++) {
    if (t < f[i + 1][0]) {
      var st = (t - f[i][0]) / (f[i + 1][0] - f[i][0]);
      var a = hr(f[i][1]), b = hr(f[i + 1][1]);
      return 'rgb(' + (a[0] + (b[0] - a[0]) * st + 0.5 | 0) + ','
                     + (a[1] + (b[1] - a[1]) * st + 0.5 | 0) + ','
                     + (a[2] + (b[2] - a[2]) * st + 0.5 | 0) + ')';
    }
  }
  return f[n - 1][1];
}

// 9 particles from the celebrate SVG animation
// All coordinates relative to center (0,0) in 300x300 viewBox space
// t: 0=fill, 1=stroke | p: bezier path | pe: path end fraction
// pz: path easing | r: radius | sw: strokeWidth | d: dashArray | df: dashOffset
// sk: scale keyframes | ok: opacity keyframes | rot: rotation | ck: color keyframes
var P = [
  // 0: red stroked circle — arcs up-left
  {t:1, c:'#ed0606',
   p:[[0,0],[1.487,-51.277],[-51.575,-66.84],[-65.964,-18.489]],
   pe:0.375, pz:[0.165,0.84,0.44,1], r:4.445, sw:2,
   sk:[[0,0.967,0,0,0.58,1],[0.25,2.193,0,0,0.58,1],[0.375,1.552]],
   ok:[[0,1],[0.25,1,0.25,0.46,0.45,0.94],[0.375,0]]},

  // 1: purple stroked dashed — arcs up-right with 306deg rotation
  {t:1, c:'#670bf4',
   p:[[0,0],[20.853,-64.502],[65.913,-61.322],[90,0]],
   pe:0.5, pz:[0.165,0.84,0.44,1], r:10.645, sw:6, d:[3,3], df:280,
   sk:[[0,0.44],[0.375,1]],
   ok:[[0,1],[0.375,1,0.25,0.46,0.45,0.94],[0.5,0]],
   rot:{dg:305.83, e:0.5, z:[0.165,0.84,0.44,1]}},

  // 2: blue stroked dashed — arcs down-left with -414deg rotation
  {t:1, c:'#1f0bf4',
   p:[[0,0],[-38.368,-28.607],[-73.478,-4.437],[-74,48]],
   pe:0.5, pz:[0.165,0.84,0.44,1], r:10.645, sw:6, d:[8,8], df:45,
   sk:[[0,0.44],[0.3625,0.75],[0.5,1]],
   ok:[[0,1],[0.25,1,0.25,0.46,0.45,0.94],[0.5,0]],
   rot:{dg:-414.17, e:0.5, z:[0.165,0.84,0.44,1]}},

  // 3: yellow filled dot — drifts down-right
  {t:0, c:'#fff400',
   p:[[0,0],[9.107,13.174],[30.909,57.87],[29.358,63.363]],
   pe:0.5, pz:[0.165,0.84,0.44,1], r:4.68,
   sk:[[0,1]],
   ok:[[0,1],[0.375,1,0.25,0.46,0.45,0.94],[0.5,0]]},

  // 4: gold dot — quick burst to the right
  {t:0, c:'#ffcc00',
   p:[[0,0],[16.67,6.67],[33.33,13.33],[50,20]],
   pe:0.25, pz:[0.165,0.84,0.44,1], r:2.82,
   sk:[[0,1]],
   ok:[[0,1],[0.125,1,0.25,0.46,0.45,0.94],[0.25,0]]},

  // 5: gold dot — drifts up-right
  {t:0, c:'#ffcc00',
   p:[[0,0],[20,-16.67],[40,-33.33],[60,-50]],
   pe:0.5, pz:[0.165,0.84,0.44,1], r:2.09,
   sk:[[0,1]],
   ok:[[0,1],[0.25,1,0.25,0.46,0.45,0.94],[0.5,0]]},

  // 6: center flash — expanding warm glow that shifts to white
  {t:0, c:'#ffcba0',
   p:[[0,0],[0,0],[0,0],[0,0]],
   pe:1, pz:[0,0,1,1], r:7.86,
   sk:[[0,0.2,0.165,0.84,0.44,1],[0.1625,4]],
   ok:[[0,0.75],[0.2125,0]],
   ck:[[0,'#ffcba0'],[0.1125,'#fdf900'],[0.2,'#fafafa']]},

  // 7: violet dot — shoots up-left
  {t:0, c:'#5800ff',
   p:[[0,0],[-12.962,-27.904],[-29.908,-68.431],[-44,-76]],
   pe:0.5, pz:[0.165,0.84,0.44,1], r:2.09,
   sk:[[0,1]],
   ok:[[0,1],[0.25,1,0.25,0.46,0.45,0.94],[0.5,0]]},

  // 8: red dot — sweeps far left
  {t:0, c:'#ff2100',
   p:[[2,3],[-21.955,-36.447],[-80.263,-28.558],[-110.541,-27.335]],
   pe:0.5, pz:[0.25,0.46,0.45,0.94], r:1.2,
   sk:[[0,1]],
   ok:[[0,1],[0.25,1],[0.5,0]]}
];

class BtuSparkle {
  static get inputProperties() {
    return ['--sparkle-progress', '--sparkle-cx', '--sparkle-cy', '--sparkle-size'];
  }

  paint(ctx, geom, props) {
    var progress = parseFloat(String(props.get('--sparkle-progress'))) || 0;
    if (progress <= 0) return;

    var cx = parseFloat(String(props.get('--sparkle-cx'))) || 0;
    var cy = parseFloat(String(props.get('--sparkle-cy'))) || 0;
    var size = parseFloat(String(props.get('--sparkle-size'))) || 300;
    var sc = size / 300;

    for (var i = 0; i < P.length; i++) {
      var p = P[i];

      // Skip invisible particles
      var alpha = kf(p.ok, progress);
      if (alpha <= 0.01) continue;

      // Position along bezier path
      var pt = p.pe < 1 ? Math.min(progress / p.pe, 1) : progress;
      var et = ease(p.pz[0], p.pz[1], p.pz[2], p.pz[3], pt);
      var pos = bp(p.p, et);

      // Per-particle scale
      var s = kf(p.sk, progress);
      if (s <= 0) continue;

      ctx.save();
      ctx.translate(cx + pos[0] * sc, cy + pos[1] * sc);

      // Rotation (particles 1 and 2)
      if (p.rot) {
        var rt = Math.min(progress / p.rot.e, 1);
        var er = ease(p.rot.z[0], p.rot.z[1], p.rot.z[2], p.rot.z[3], rt);
        ctx.rotate(p.rot.dg * er * Math.PI / 180);
      }

      ctx.scale(s * sc, s * sc);
      ctx.globalAlpha = alpha;
      ctx.beginPath();
      ctx.arc(0, 0, p.r, 0, 6.2832);

      if (p.t) {
        // Stroked circle
        ctx.strokeStyle = p.c;
        ctx.lineWidth = p.sw;
        if (p.d) {
          ctx.setLineDash(p.d);
          ctx.lineDashOffset = p.df || 0;
        }
        ctx.stroke();
      } else {
        // Filled circle (with optional color animation)
        ctx.fillStyle = p.ck ? ckf(p.ck, progress) : p.c;
        ctx.fill();
      }

      ctx.restore();
    }
  }
}

registerPaint('btu-sparkle', BtuSparkle);
`;let h=!1,k=null,$=!1,i=null;function A(){if($)return;$=!0;const e=[["--sparkle-progress","<number>","0"],["--sparkle-cx","<number>","0"],["--sparkle-cy","<number>","0"],["--sparkle-size","<number>","300"]];for(const[r,t,s]of e)try{CSS.registerProperty({name:r,syntax:t,inherits:!1,initialValue:s})}catch{}}function H(){if(h)return Promise.resolve();if(k)return k;const e=CSS.paintWorklet;if(!e)return Promise.resolve();const r=new Blob([_],{type:"text/javascript"}),t=URL.createObjectURL(r),s=e.addModule(t).then(()=>{h=!0}).catch(()=>{}).finally(()=>{URL.revokeObjectURL(t)});return k=s,s}function K(){i||(i=document.createElement("div"),i.style.cssText="position:fixed;inset:0;pointer-events:none;background:transparent;z-index:2147483647;",document.body.appendChild(i)),i.style.viewTransitionName="sparkle-overlay"}function N(e,r,t,s){return`
    ::view-transition-group(sparkle-overlay) {
      z-index: 2147483647;
      background-image: paint(btu-sparkle);
      animation: btu-sparkle-anim ${s}ms linear forwards;
      --sparkle-cx: ${e};
      --sparkle-cy: ${r};
      --sparkle-size: ${t};
      --sparkle-progress: 0;
    }
    ::view-transition-image-pair(sparkle-overlay) {
      display: none;
    }
    @keyframes btu-sparkle-anim {
      from { --sparkle-progress: 0; }
      to { --sparkle-progress: 1; }
    }
  `}function X(){i&&(i.style.viewTransitionName="")}function Y(){return!!CSS.paintWorklet}function q(){return h}A();H();const E="btu-effect-ripple",G={"--btu-theme-primary-hue":264,"--btu-theme-error-hue":27,"--btu-theme-success-hue":157};let m={},l,R=!1;function J(){if(!R){try{CSS.registerProperty({name:"--ripple-r",syntax:"<length>",inherits:!1,initialValue:"0px"})}catch{}R=!0}}const L={ready:Promise.resolve(),finished:Promise.resolve()};function g(e){if(window.matchMedia("(prefers-reduced-motion: reduce)").matches)return L;const r=document;if(!r.startViewTransition)return L;J();const{duration:t=1200,ringWidth:s=40,feather:n=75,hueShift:T=0,contrast:v=1.8,saturate:C=1.5,hueProperties:b=G}={...m,...e},y=document.documentElement.classList.contains("dark")||window.matchMedia("(prefers-color-scheme: dark)").matches,O=y?Math.min(v,1.3):v,M=y?1.4:1;l&&clearTimeout(l);const{x:o,y:p}=I(e.position),W=Math.hypot(Math.max(o,innerWidth-o),Math.max(p,innerHeight-p)),a=s/2,F=W+n+a,c=document.documentElement,f=!!e.sparkle&&Y()&&q(),x=typeof e.sparkle=="object"?e.sparkle:{},U=x.size??300,B=x.duration??t;f&&K(),c.style.setProperty("view-transition-name","root");const u=document.createElement("style");let z=`
    ::view-transition-old(root) {
      animation: none;
    }
    ::view-transition-new(root) {
      mix-blend-mode: normal;
      filter: contrast(${O}) saturate(${C}) brightness(${M});
      animation: btu-ripple-ring ${t}ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
      mask-image: radial-gradient(
        circle at ${o}px ${p}px,
        transparent 0,
        transparent calc(var(--ripple-r) - ${n+a}px),
        black calc(var(--ripple-r) - ${a}px),
        black calc(var(--ripple-r) + ${a}px),
        transparent calc(var(--ripple-r) + ${n+a}px)
      );
      -webkit-mask-image: radial-gradient(
        circle at ${o}px ${p}px,
        transparent 0,
        transparent calc(var(--ripple-r) - ${n+a}px),
        black calc(var(--ripple-r) - ${a}px),
        black calc(var(--ripple-r) + ${a}px),
        transparent calc(var(--ripple-r) + ${n+a}px)
      );
    }
    @keyframes btu-ripple-ring {
      from { --ripple-r: 0px; }
      to { --ripple-r: ${F}px; }
    }
  `;f&&(z+=N(o,p,U,B)),u.textContent=z,document.head.appendChild(u);const w=r.startViewTransition(()=>{for(const[d,j]of Object.entries(b))c.style.setProperty(d,`${j+T}`)}),S=()=>{for(const d of Object.keys(b))c.style.removeProperty(d)},P=()=>{l&&clearTimeout(l),S(),u.remove(),c.style.removeProperty("view-transition-name"),f&&X()},D=w.ready.then(()=>{l=setTimeout(S,Math.max(0,t-100))}).catch(()=>{}),V=w.finished.then(P).catch(P);return{ready:D,finished:V}}g.setDefaults=e=>{m={...m,...e}};g.listen=()=>{const e=r=>{const t=r.detail;t?.position&&g(t)};return document.addEventListener(E,e),()=>document.removeEventListener(E,e)};export{g as b};
