{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"bell-breath-loader","type":"registry:component","title":"Bell Breath Loader","description":"A progress loader drawn as one translucent jellyfish. Progress is light: it rises through the bell from the rim, lights the ring of organs and lets the tentacles grow. With no value it breathes on a five second cycle, and at 100 it exhales, lifts 24 px and fades.","dependencies":[],"registryDependencies":[],"files":[{"path":"components/viberdy/bell-breath-loader.tsx","content":"\"use client\";\n\nimport { useEffect, useId, useRef, useSyncExternalStore } from \"react\";\nimport type { CSSProperties } from \"react\";\n\n/**\n * BellBreathLoader: a progress indicator drawn as one jellyfish. The bell is\n * near-clear glass, almost transparent at the apex and denser toward a flared,\n * scalloped margin, with a ring of four dim horseshoe gonads inside. The\n * colour lives in two places only: the organs and the progress light. The light\n * rises through the bell from the rim, the organs glow when it reaches them,\n * and the tentacles grow as the number grows. With no value it breathes on a\n * 5 second cycle: one quick contraction, a slow release, the lappets flexing\n * and the tentacles trailing the bell with a real delay. At 100 it does one\n * exhale, lifts 24 px and fades over 600 ms, and is gone.\n *\n * HOW IT IS MADE. Inline SVG plus one small requestAnimationFrame loop, no\n * dependencies and no React render per frame:\n *   - the bell is a tall dome that flares into a margin of 12 lappets, rebuilt\n *     every frame so the lappets flex with the breath. Layers, bottom to top:\n *     a glass body gradient (clear above, denser at the margin), a dark cavity,\n *     the light (a soft-edged gradient slid up from the rim), the gonads, three\n *     faint layered edge strokes that fade toward the apex (a fresnel edge, not\n *     an outline), the lit margin and two glints;\n *   - 12 marginal tentacles and 4 oral arms are rebuilt every frame. A\n *     tentacle is a filled shape that tapers to a point (it fades by length),\n *     riding a travelling wave: the bell's contraction reaches a point a moment\n *     after it reaches the margin (the follow-through), on top of a lateral\n *     sway whose period differs per tentacle. The oral arms are soft frilled\n *     curtains of two overlapping layers;\n *   - progress is chased with a 0.35 s time constant, so a jump in the value\n *     is a ramp, never a flash. Nothing changes faster than the bell's own\n *     contraction (about 0.2 s) and the area involved is small, far under any\n *     flash threshold;\n *   - below 72 px wide the canals, the inner dome and the bead dots are left\n *     out on purpose (a simplified level of detail), so nothing goes sub-pixel;\n *   - the loop sleeps when the loader is off screen, the tab is hidden, or the\n *     exhale has finished.\n *\n * It is a real progressbar: role, aria-valuemin/max/now (the value is omitted\n * while indeterminate), an aria-label from the label prop and a visually\n * hidden text. Under prefers-reduced-motion it is one still frame (the bell\n * relaxed, lit to the current value) with a numeric readout, and the exhale is\n * replaced by the finished frame.\n *\n * Use it for an upload, a route change, an image, a long form submit. It is\n * never a page-gating splash. Hues: Medusa (pink core, violet bell, ice rim),\n * Ice, Ember, Abyss. Ink is #eaf1f6; set style.color for a light ground. The\n * exhale lifts the figure 24 px, so do not clip it with overflow: hidden.\n *\n * Part of the Attention kit: a style of anomalies, familiar things made wrong\n * (fish in dry air, a stone that breaks upward, a shadow that runs toward its\n * lamp). One subject, one motivated light, one broken rule, and everything\n * else calm. Cut byte for byte from the kit's one site (AttentionSite, a\n * demo studio called Aerium). Paste it as its own file: it carries its own\n * copy of every helper it uses and has no dependencies.\n */\n\nfunction clamp(v: number, lo: number, hi: number, fallback: number) {\n  return Number.isFinite(v) ? Math.min(hi, Math.max(lo, v)) : fallback;\n}\n\nconst TAU = Math.PI * 2;\n\nexport type BellBreathLoaderHue = \"Medusa\" | \"Ice\" | \"Ember\" | \"Abyss\";\n\nexport type BellBreathLoaderProps = {\n  /** 0 to 100. Leave it out (or pass null) for the indeterminate breath. */\n  progress?: number | null;\n  /** The accessible name, and the readout while indeterminate. */\n  label?: string;\n  /** Width in px, 32 to 320. The figure is 1.65 times as tall. */\n  size?: number;\n  /** The specimen colour. */\n  hue?: BellBreathLoaderHue;\n  /** Show the percentage (or the label when indeterminate) under the bell. */\n  showValue?: boolean;\n  /** Called once when progress reaches 100 (when the exhale begins). */\n  onComplete?: () => void;\n  className?: string;\n  style?: CSSProperties;\n};\n\nconst BELL_PALETTES: Record<BellBreathLoaderHue, { core: string; bell: string; rim: string }> = {\n  Medusa: { core: \"#ff5aa5\", bell: \"#6c4dff\", rim: \"#7fd8ff\" },\n  Ice: { core: \"#d9ecf8\", bell: \"#4e7fc4\", rim: \"#a9dcff\" },\n  Ember: { core: \"#ff7f1e\", bell: \"#b8452c\", rim: \"#ffd3a1\" },\n  Abyss: { core: \"#2b63ff\", bell: \"#2a2fa0\", rim: \"#8fb0ff\" },\n};\n\n/** The glass is near-neutral in every hue. */\nconst GLASS = \"#cfe3f2\";\n\nconst PERIOD = 5;\n\nconst LMAX = 108;\n\nfunction subscribeReduced(cb: () => void) {\n  const m = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n  m.addEventListener(\"change\", cb);\n  return () => m.removeEventListener(\"change\", cb);\n}\n\nfunction getReduced() {\n  return window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n}\n\nfunction getReducedServer() {\n  return false;\n}\n\n/* ---- geometry (viewBox 0 0 100 165, bell centred on x = 50) ---------------- */\n\n/** The dome, left rim tip to right rim tip: widest about 65% of the way down, then curling inward to a narrower rim. */\nconst DOME_LINE = \"M21 50C15 47 12 42 12 35C12 18 28 5 50 5C72 5 88 18 88 35C88 42 85 47 79 50\";\n\nconst INNER = \"M22 47C16 38 18 11 50 11C82 11 84 38 78 47\";\n\nconst RIM_L = 21;\n\nconst RIM_R = 79;\n\nconst RIM_Y = 50;\n\nconst SAG = 3.2;\n\n/** The rim is a slight ellipse seen 3/4 on: the front edge sags below the tips. */\nconst rimAt = (x: number) => RIM_Y + SAG * Math.sin((Math.PI * (RIM_R - x)) / (RIM_R - RIM_L));\n\n/** Fourteen small lappets along the front edge, right to left. c is the contraction 0..1: they curl a little deeper. */\nfunction scallops(c: number) {\n  let s = \"\";\n  const w = (RIM_R - RIM_L) / 14;\n  for (let k = 0; k < 14; k++) {\n    const x1 = RIM_R - w * k;\n    const xm = x1 - w / 2;\n    const x2 = x1 - w;\n    const depth = 1 + c * (0.9 + 0.5 * Math.sin(k * 2.1));\n    s += \"Q\" + xm.toFixed(2) + \" \" + (rimAt(xm) + depth).toFixed(2) + \" \" + x2.toFixed(2) + \" \" + rimAt(x2).toFixed(2);\n  }\n  return s;\n}\n\nconst MOUTH = \"M21 50Q50 45.4 79 50Q50 56.2 21 50Z\";\n\nconst CANALS = [\n  \"M50 12C34 14 22 24 20.5 38\",\n  \"M50 12C42 18 35 32 31 49\",\n  \"M50 12V51\",\n  \"M50 12C58 18 65 32 69 49\",\n  \"M50 12C66 14 78 24 79.5 38\",\n];\n\nconst GLINT_A = \"M20.5 36C20 23 29 12 43 9\";\n\nconst GLINT_B = \"M63 9C70 10.5 77 16 79.5 24\";\n\n/* Four soft kidney-shaped gonads in a cross, seen through the glass and blurred: a glow, not a shape. */\nconst KIDNEY = \"M-4.6 0C-4.6 -2.7 -1.5 -3.3 0 -2.2C1.5 -3.3 4.6 -2.7 4.6 0C4.6 2.7 1.8 3.1 0 1.5C-1.8 3.1 -4.6 2.7 -4.6 0Z\";\n\nconst GONADS = [\n  { x: 50, y: 29.5, r: 180, s: 0.8 },\n  { x: 50, y: 38.5, r: 0, s: 1 },\n  { x: 41, y: 34, r: -80, s: 0.9 },\n  { x: 59, y: 34, r: 80, s: 0.9 },\n];\n\n/* Marginal tentacles hang from the lappet junctions (x = 50 + rel). A few run\n   much longer than the rest. */\nconst THIN = [-27.5, -22.5, -17.5, -12.5, -7.5, -3, 3, 7.5, 12.5, 17.5, 22.5, 27.5].map((rel, i) => ({\n  rel,\n  len: [60, 84, 70, 106, 64, 96, 102, 66, 108, 76, 88, 58][i] ?? 70,\n  per: 4.2 + ((i * 7) % 5) * 0.62,\n  ph: i * 1.9,\n  amp: 4 + ((i * 3) % 4) * 0.8,\n  freq: 1.35 + ((i * 5) % 4) * 0.16,\n  drift: (((i * 5) % 7) - 3) * 1.5,\n  slow: ((i * 37) % 10) / 10,\n  w: 0.6 + ((i * 5) % 4) * 0.1,\n}));\n\nconst ORAL = [\n  { rel: -5, y: 33, len: 82, per: 5.3, ph: 0.4, amp: 4.4 },\n  { rel: -1.8, y: 34, len: 100, per: 6.1, ph: 2.1, amp: 5 },\n  { rel: 1.8, y: 34, len: 92, per: 4.7, ph: 3.7, amp: 4.8 },\n  { rel: 5, y: 33, len: 72, per: 5.9, ph: 5, amp: 4.2 },\n];\n\n/* ---- motion maths ---------------------------------------------------------- */\n\nconst clamp01 = (x: number) => (x < 0 ? 0 : x > 1 ? 1 : x);\n\nfunction bellSmooth(a: number, b: number, x: number) {\n  const t = clamp01((x - a) / (b - a));\n  return t * t * (3 - 2 * t);\n}\n\n/** One breath: a quick contraction (peak at 31% of the cycle), a slow release. */\nfunction pulse(u: number) {\n  const s = Math.sin(Math.PI * Math.pow(clamp01(u), 0.62));\n  return s * s;\n}\n\nfunction cyc(tau: number) {\n  const u = (tau / PERIOD) % 1;\n  return u < 0 ? u + 1 : u;\n}\n\n/** A closed shape around a centre line, half-width hw(s), left side down and right side back up. */\nfunction ribbon(xs: number[], ys: number[], hw: (s: number) => number) {\n  const n = xs.length - 1;\n  let left = \"\";\n  let right = \"\";\n  for (let k = 0; k <= n; k++) {\n    const ax = (xs[Math.min(k + 1, n)] ?? 0) - (xs[Math.max(k - 1, 0)] ?? 0);\n    const ay = (ys[Math.min(k + 1, n)] ?? 0) - (ys[Math.max(k - 1, 0)] ?? 0);\n    const len = Math.hypot(ax, ay) || 1;\n    const h = hw(k / n);\n    const x = xs[k] ?? 0;\n    const y = ys[k] ?? 0;\n    const nx = (-ay / len) * h;\n    const ny = (ax / len) * h;\n    left += (k === 0 ? \"M\" : \"L\") + (x + nx).toFixed(2) + \" \" + (y + ny).toFixed(2);\n    right = \"L\" + (x - nx).toFixed(2) + \" \" + (y - ny).toFixed(2) + right;\n  }\n  return left + right + \"Z\";\n}\n\ntype Tent = { halo: SVGPathElement | null; body: SVGPathElement | null; line: SVGPathElement | null };\n\ntype Els = {\n  svg: SVGSVGElement;\n  fig: SVGGElement;\n  bell: SVGGElement;\n  light: SVGGElement;\n  glow: SVGEllipseElement;\n  organ: SVGGElement;\n  rim: SVGPathElement;\n  aura: SVGEllipseElement;\n  thinG: SVGGElement;\n  oralG: SVGGElement;\n  shape: SVGPathElement[];\n  thin: Tent[];\n  oral: SVGPathElement[][];\n};\n\n/** Writes one frame: p is the smoothed light level 0..1, cFn(a) the contraction\n *  that has reached distance a (0..1) down a tentacle, calm scales the sway,\n *  wk widens the hairlines at small sizes. */\nfunction draw(E: Els, tau: number, p: number, cFn: (a: number) => number, calm: number, wk: number) {\n  const c0 = cFn(0);\n  const sx = 1 - 0.075 * c0;\n  const sy = 1 + 0.05 * c0;\n  E.bell.setAttribute(\"transform\", \"translate(50 5) scale(\" + sx.toFixed(4) + \" \" + sy.toFixed(4) + \") translate(-50 -5)\");\n  const sc = scallops(c0);\n  const shape = DOME_LINE + sc + \"Z\";\n  for (const el of E.shape) el.setAttribute(\"d\", shape);\n  E.rim.setAttribute(\"d\", \"M79 50\" + sc);\n  const bob = -2.4 * c0 + 0.8 * Math.sin((TAU * tau) / 9.3) * calm;\n  const tilt = 1.1 * Math.sin((TAU * tau) / 11.1 + 1) * calm;\n  const dx = 0.5 * Math.sin((TAU * tau) / 13.7) * calm;\n  E.fig.setAttribute(\"transform\", \"translate(\" + dx.toFixed(2) + \" \" + bob.toFixed(2) + \") rotate(\" + tilt.toFixed(2) + \" 50 30)\");\n\n  const front = 60 - 86 * p;\n  E.light.setAttribute(\"transform\", \"translate(0 \" + front.toFixed(2) + \")\");\n  E.glow.setAttribute(\"opacity\", (bellSmooth(0.15, 0.8, p) * (0.92 + 0.08 * c0)).toFixed(3));\n  E.organ.setAttribute(\"opacity\", (0.3 + 0.7 * clamp01((41 - front) / 20)).toFixed(3));\n  E.rim.setAttribute(\"opacity\", (0.45 + 0.55 * clamp01(p * 5)).toFixed(3));\n  E.aura.setAttribute(\"opacity\", (0.3 + 0.7 * p).toFixed(3));\n  E.thinG.setAttribute(\"opacity\", (0.7 + 0.3 * bellSmooth(0, 0.7, p)).toFixed(3));\n  E.oralG.setAttribute(\"opacity\", (0.6 + 0.4 * bellSmooth(0.05, 0.8, p)).toFixed(3));\n  const tintO = (0.25 + 0.75 * bellSmooth(0.1, 0.9, p)).toFixed(3);\n\n  const N = 20;\n\n  THIN.forEach((g, i) => {\n    const T = E.thin[i];\n    if (!T) return;\n    const t = 0.14 + 0.86 * clamp01(p / (0.7 + 0.3 * g.slow));\n    const Lt = g.len * t;\n    const rimY = 5 + (rimAt(50 + g.rel) - 5) * sy;\n    const xs: number[] = [];\n    const ys: number[] = [];\n    for (let k = 0; k <= N; k++) {\n      const s = k / N;\n      const a = (s * Lt) / LMAX;\n      const cl = cFn(a);\n      const rel = g.rel * (1 - 0.075 * cl) * (1 + 0.28 * Math.sin(Math.PI * Math.min(1, a * 1.3)) - 0.25 * a);\n      const wave = g.amp * calm * a * (0.4 + 0.6 * a) * Math.sin(TAU * (tau / g.per - g.freq * a) + g.ph) + g.drift * Math.sin(Math.PI * a * 0.85);\n      xs.push(50 + rel + wave);\n      ys.push(rimY + s * Lt * (1 - 0.1 * cl));\n    }\n    const w0 = (g.w * wk) / 2;\n    const taper = (s: number) => w0 * Math.pow(1 - s, 1.25) + 0.03;\n    if (T.body) T.body.setAttribute(\"d\", ribbon(xs, ys, taper));\n    if (T.halo) T.halo.setAttribute(\"d\", ribbon(xs, ys, (s) => taper(s) * 3.2));\n    if (T.line) {\n      let d = \"M\" + (xs[0] ?? 0).toFixed(2) + \" \" + (ys[0] ?? 0).toFixed(2);\n      for (let k = 1; k < N; k++) {\n        const x0 = xs[k] ?? 0;\n        const y0 = ys[k] ?? 0;\n        d += \"Q\" + x0.toFixed(2) + \" \" + y0.toFixed(2) + \" \" + ((x0 + (xs[k + 1] ?? 0)) / 2).toFixed(2) + \" \" + ((y0 + (ys[k + 1] ?? 0)) / 2).toFixed(2);\n      }\n      T.line.setAttribute(\"d\", d + \"L\" + (xs[N] ?? 0).toFixed(2) + \" \" + (ys[N] ?? 0).toFixed(2));\n    }\n  });\n\n  const M = 26;\n  ORAL.forEach((g, j) => {\n    const pair = E.oral[j];\n    if (!pair) return;\n    const t = 0.3 + 0.7 * clamp01(p / (0.8 + 0.05 * j));\n    const Lt = g.len * t;\n    const yRoot = 5 + (g.y - 5) * sy;\n    const xs: number[] = [];\n    const ys: number[] = [];\n    const fa: number[] = [];\n    for (let k = 0; k <= M; k++) {\n      const s = k / M;\n      const a = (s * Lt) / LMAX;\n      const cl = cFn(a * 0.9 + 0.1);\n      xs.push(50 + g.rel * (1 - 0.075 * cl) * (1 - 0.25 * a) + g.amp * calm * t * s * (0.35 + 0.65 * s) * Math.sin(TAU * (tau / g.per - 1.15 * s) + g.ph));\n      ys.push(yRoot + s * Lt * (1 - 0.08 * cl));\n      fa.push(1 + 0.22 * Math.sin(6 * s + g.ph + tau * 0.45 * calm));\n    }\n    const body = (s: number) => (0.55 + 1.5 * Math.pow(1 - s, 0.8)) * (0.45 + 0.55 * bellSmooth(0, 0.12, s)) * (1 - 0.8 * bellSmooth(0.7, 1, s));\n    // A soft back curtain, a little wider and frilled; a finer front curtain over it.\n    const back = pair[0];\n    const front2 = pair[1];\n    if (back) {\n      back.setAttribute(\"d\", ribbon(xs, ys, (s) => body(s) * 1.5 * (fa[Math.round(s * M)] ?? 1)));\n      back.setAttribute(\"opacity\", tintO);\n    }\n    if (front2) front2.setAttribute(\"d\", ribbon(xs, ys, (s) => body(s) * 0.7 * (2 - (fa[Math.round(s * M)] ?? 1))));\n  });\n}\n\ntype Opts = { target: number | null; reduced: boolean; onComplete: (() => void) | undefined; wk: number };\n\nexport function BellBreathLoader({ progress, label = \"Loading\", size = 96, hue = \"Medusa\", showValue = false, onComplete, className = \"\", style }: BellBreathLoaderProps) {\n  const reduced = useSyncExternalStore(subscribeReduced, getReduced, getReducedServer);\n  const uid = useId().replace(/[^a-zA-Z0-9]/g, \"\");\n  const det = typeof progress === \"number\" && Number.isFinite(progress);\n  const value = det ? clamp(progress, 0, 100, 0) : 0;\n  const shown = Math.round(value);\n  const sz = clamp(size, 32, 320, 96);\n  const pal = BELL_PALETTES[hue] ?? BELL_PALETTES.Medusa;\n  const name = typeof label === \"string\" && label.trim() ? label.trim().slice(0, 80) : \"Loading\";\n  const k = Math.min(1.9, Math.max(1, 96 / sz));\n  const full = sz >= 72;\n\n  const rootRef = useRef<HTMLDivElement>(null);\n  const opts = useRef<Opts>({ target: det ? value / 100 : null, reduced, onComplete, wk: k });\n  const refresh = useRef<() => void>(() => {});\n\n  useEffect(() => {\n    const root = rootRef.current;\n    if (!root) return;\n    const one = <T extends Element>(sel: string) => root.querySelector(sel) as T | null;\n    const svg = one<SVGSVGElement>(\"[data-bb=svg]\");\n    const fig = one<SVGGElement>(\"[data-bb=fig]\");\n    const bell = one<SVGGElement>(\"[data-bb=bell]\");\n    const light = one<SVGGElement>(\"[data-bb=light]\");\n    const glow = one<SVGEllipseElement>(\"[data-bb=glow]\");\n    const organ = one<SVGGElement>(\"[data-bb=organ]\");\n    const rim = one<SVGPathElement>(\"[data-bb=rim]\");\n    const aura = one<SVGEllipseElement>(\"[data-bb=aura]\");\n    const thinG = one<SVGGElement>(\"[data-bb=thin]\");\n    const oralG = one<SVGGElement>(\"[data-bb=oral]\");\n    if (!svg || !fig || !bell || !light || !glow || !organ || !rim || !aura || !thinG || !oralG) return;\n    const pick = (g: Element, sel: string) => g.querySelector<SVGPathElement>(sel);\n    const E: Els = {\n      svg,\n      fig,\n      bell,\n      light,\n      glow,\n      organ,\n      rim,\n      aura,\n      thinG,\n      oralG,\n      shape: Array.from(root.querySelectorAll<SVGPathElement>(\"[data-bb=bs]\")),\n      thin: Array.from(root.querySelectorAll(\"[data-bb=tg]\")).map((g) => ({ halo: pick(g, \"[data-bb=th]\"), body: pick(g, \"[data-bb=tb]\"), line: pick(g, \"[data-bb=tc]\") })),\n      oral: Array.from(root.querySelectorAll(\"[data-bb=og]\")).map((g) => Array.from(g.querySelectorAll(\"path\"))),\n    };\n\n    let alive = true;\n    let raf = 0;\n    let onScreen = true;\n    let tabShown = !document.hidden;\n    const t0 = performance.now();\n    const st = { last: t0, p: 0, born: t0, reappear: -1e9, done: false, doneAt: 0, finished: false, first: true };\n\n    const still = () => {\n      const o = opts.current;\n      const p = o.target == null ? 0.58 : o.target;\n      draw(E, 1.9, p, () => 0.14, 0.7, o.wk);\n      svg.style.opacity = \"1\";\n      svg.style.transform = \"none\";\n    };\n\n    /** One frame. Returns false when the loop may sleep. */\n    const step = (now: number) => {\n      const o = opts.current;\n      const tau = (now - t0) / 1000;\n      const dt = Math.min(0.1, Math.max(0, (now - st.last) / 1000));\n      st.last = now;\n      const glowBreath = 0.5 + 0.5 * Math.cos(TAU * (cyc(tau) - 0.55));\n      const pT = o.target == null ? 0.34 + 0.34 * glowBreath : o.target;\n      const isDone = o.target != null && o.target >= 1;\n      if (isDone && !st.done) {\n        st.done = true;\n        st.doneAt = now;\n        if (st.first) st.finished = true;\n        else o.onComplete?.();\n      } else if (!isDone && st.done) {\n        st.done = false;\n        st.finished = false;\n        st.reappear = now;\n        st.p = pT;\n      }\n      st.first = false;\n      st.p += (pT - st.p) * (1 - Math.exp(-dt / 0.35));\n\n      let vis = 1;\n      let lift = 0;\n      let cFn = (a: number) => pulse(cyc(tau - a * 1.15));\n      if (st.done) {\n        const u = clamp01((now - st.doneAt) / 600);\n        if (st.finished) {\n          vis = 0;\n        } else {\n          vis = 1 - bellSmooth(0.12, 1, u);\n          lift = -24 * (1 - Math.pow(1 - u, 3.5));\n          cFn = (a: number) => pulse(u - a * 0.22);\n          if (u >= 1) st.finished = true;\n        }\n      } else {\n        const ent = Math.min(bellSmooth(0, 1, (now - st.born) / 700), bellSmooth(0, 1, (now - st.reappear) / 700));\n        vis = ent;\n        lift = 8 * (1 - ent);\n      }\n      draw(E, tau, st.p, cFn, 1, o.wk);\n      svg.style.opacity = vis.toFixed(3);\n      svg.style.transform = \"translateY(\" + lift.toFixed(2) + \"px)\";\n      return !(st.done && st.finished);\n    };\n\n    const loop = (now: number) => {\n      raf = 0;\n      if (!alive) return;\n      if (opts.current.reduced) {\n        still();\n        return;\n      }\n      if (step(now) && onScreen && tabShown) raf = requestAnimationFrame(loop);\n    };\n    const wake = () => {\n      if (!alive) return;\n      if (opts.current.reduced) {\n        if (raf) cancelAnimationFrame(raf);\n        raf = 0;\n        still();\n        return;\n      }\n      if (raf || !onScreen || !tabShown) return;\n      st.last = performance.now();\n      raf = requestAnimationFrame(loop);\n    };\n    refresh.current = wake;\n\n    const io = new IntersectionObserver((entries) => {\n      const e = entries[entries.length - 1];\n      if (!e) return;\n      onScreen = e.isIntersecting;\n      if (onScreen) wake();\n      else if (raf) {\n        cancelAnimationFrame(raf);\n        raf = 0;\n      }\n    });\n    io.observe(root);\n    const onVis = () => {\n      tabShown = !document.hidden;\n      if (tabShown) wake();\n      else if (raf) {\n        cancelAnimationFrame(raf);\n        raf = 0;\n      }\n    };\n    document.addEventListener(\"visibilitychange\", onVis);\n    wake();\n    return () => {\n      alive = false;\n      if (raf) cancelAnimationFrame(raf);\n      raf = 0;\n      io.disconnect();\n      document.removeEventListener(\"visibilitychange\", onVis);\n    };\n  }, []);\n\n  useEffect(() => {\n    opts.current = { target: det ? value / 100 : null, reduced, onComplete, wk: k };\n    refresh.current();\n  });\n\n  const v = (n: number) => n * k;\n  const sr: CSSProperties = { position: \"absolute\", width: 1, height: 1, margin: -1, padding: 0, overflow: \"hidden\", clip: \"rect(0 0 0 0)\", whiteSpace: \"nowrap\", border: 0 };\n  const stop = (c: string, o: number, at: string) => <stop offset={at} style={{ stopColor: c.charAt(0) === \"#\" ? c : \"var(--bb-\" + c + \")\", stopOpacity: o }} />;\n  const rootStyle = {\n    position: \"relative\",\n    display: \"inline-flex\",\n    flexDirection: \"column\",\n    alignItems: \"center\",\n    width: sz,\n    color: \"#eaf1f6\",\n    \"--bb-core\": pal.core,\n    \"--bb-bell\": pal.bell,\n    \"--bb-rim\": pal.rim,\n    ...style,\n  } as CSSProperties;\n  const shape0 = DOME_LINE + scallops(0.1) + \"Z\";\n  const tg = \"url(#\" + uid + \"t)\";\n\n  return (\n    <div\n      ref={rootRef}\n      role=\"progressbar\"\n      aria-label={name}\n      aria-valuemin={0}\n      aria-valuemax={100}\n      aria-valuenow={det ? shown : undefined}\n      aria-valuetext={det ? (shown >= 100 ? \"Complete\" : shown + \" percent\") : undefined}\n      className={className}\n      style={rootStyle}\n    >\n      <span style={sr}>{det ? name + \", \" + shown + \" percent\" : name}</span>\n      <svg data-bb=\"svg\" aria-hidden=\"true\" width={sz} height={sz * 1.65} viewBox=\"0 0 100 165\" fill=\"none\" style={{ display: \"block\", overflow: \"visible\", opacity: 0 }}>\n        <defs>\n          <linearGradient id={uid + \"b\"} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n            {stop(GLASS, 0.02, \"0\")}\n            {stop(GLASS, 0.05, \"0.5\")}\n            {stop(GLASS, 0.15, \"1\")}\n          </linearGradient>\n          <linearGradient id={uid + \"l\"} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n            {stop(\"core\", 0, \"0\")}\n            {stop(\"core\", 0.26, \"0.09\")}\n            {stop(\"bell\", 0.14, \"0.26\")}\n            {stop(\"core\", 0.11, \"0.6\")}\n            {stop(\"core\", 0.08, \"1\")}\n          </linearGradient>\n          <radialGradient id={uid + \"m\"} cx=\"0.5\" cy=\"0.5\" r=\"0.5\">\n            {stop(\"rim\", 0.24, \"0\")}\n            {stop(\"rim\", 0.1, \"0.55\")}\n            {stop(\"rim\", 0, \"1\")}\n          </radialGradient>\n          <radialGradient id={uid + \"g\"} cx=\"0.5\" cy=\"0.5\" r=\"0.5\">\n            {stop(\"core\", 0.32, \"0\")}\n            {stop(\"core\", 0.1, \"0.55\")}\n            {stop(\"core\", 0, \"1\")}\n          </radialGradient>\n          <radialGradient id={uid + \"a\"} cx=\"0.5\" cy=\"0.5\" r=\"0.5\">\n            {stop(\"bell\", 0.1, \"0\")}\n            {stop(\"bell\", 0.035, \"0.6\")}\n            {stop(\"bell\", 0, \"1\")}\n          </radialGradient>\n          <linearGradient id={uid + \"e\"} gradientUnits=\"userSpaceOnUse\" x1=\"0\" y1=\"5\" x2=\"0\" y2=\"52\">\n            {stop(GLASS, 0.1, \"0\")}\n            {stop(GLASS, 0.4, \"0.55\")}\n            {stop(GLASS, 0.9, \"1\")}\n          </linearGradient>\n          <linearGradient id={uid + \"t\"} gradientUnits=\"userSpaceOnUse\" x1=\"0\" y1=\"50\" x2=\"0\" y2=\"160\">\n            {stop(GLASS, 0.5, \"0\")}\n            {stop(\"bell\", 0.46, \"0.3\")}\n            {stop(\"bell\", 0.36, \"0.7\")}\n            {stop(\"bell\", 0.28, \"1\")}\n          </linearGradient>\n          <linearGradient id={uid + \"o\"} gradientUnits=\"userSpaceOnUse\" x1=\"0\" y1=\"33\" x2=\"0\" y2=\"118\">\n            {stop(\"core\", 0.16, \"0\")}\n            {stop(\"core\", 0.07, \"0.45\")}\n            {stop(\"core\", 0, \"1\")}\n          </linearGradient>\n          <linearGradient id={uid + \"w\"} gradientUnits=\"userSpaceOnUse\" x1=\"0\" y1=\"33\" x2=\"0\" y2=\"118\">\n            {stop(\"#eaf1f6\", 0.2, \"0\")}\n            {stop(\"#eaf1f6\", 0.08, \"0.45\")}\n            {stop(\"#eaf1f6\", 0, \"1\")}\n          </linearGradient>\n          <filter id={uid + \"f\"} filterUnits=\"userSpaceOnUse\" x=\"26\" y=\"18\" width=\"48\" height=\"30\">\n            <feGaussianBlur stdDeviation=\"2\" />\n          </filter>\n          <clipPath id={uid + \"c\"}>\n            <path data-bb=\"bs\" d={shape0} />\n          </clipPath>\n        </defs>\n        <g data-bb=\"fig\">\n          <ellipse data-bb=\"aura\" cx=\"50\" cy=\"32\" rx=\"48\" ry=\"40\" fill={\"url(#\" + uid + \"a)\"} />\n          <g data-bb=\"thin\">\n            {THIN.map((g, i) => (\n              <g key={i} data-bb=\"tg\">\n                <path data-bb=\"th\" fill={tg} fillOpacity=\"0.07\" />\n                <path data-bb=\"tb\" fill={tg} />\n                {full && <path data-bb=\"tc\" fill=\"none\" stroke={tg} strokeWidth=\"0.9\" strokeLinecap=\"round\" strokeOpacity=\"0.3\" strokeDasharray=\"0 7.5\" />}\n              </g>\n            ))}\n          </g>\n          <g data-bb=\"oral\">\n            {ORAL.map((g, i) => (\n              <g key={i} data-bb=\"og\">\n                <path fill={\"url(#\" + uid + \"o)\"} />\n                <path fill={\"url(#\" + uid + \"w)\"} strokeWidth={v(0.25)} strokeLinejoin=\"round\" stroke=\"#eaf1f6\" strokeOpacity=\"0.1\" />\n              </g>\n            ))}\n          </g>\n          <g data-bb=\"bell\">\n            <path data-bb=\"bs\" d={shape0} fill={\"url(#\" + uid + \"b)\"} />\n            <g clipPath={\"url(#\" + uid + \"c)\"}>\n              <ellipse cx=\"50\" cy=\"42\" rx=\"24\" ry=\"8\" fill=\"#000\" fillOpacity=\"0.12\" />\n              <path d={MOUTH} fill=\"#000\" fillOpacity=\"0.2\" />\n              <g data-bb=\"light\" transform=\"translate(0 60)\">\n                <rect x=\"-5\" y=\"0\" width=\"110\" height=\"84\" fill={\"url(#\" + uid + \"l)\"} />\n                <ellipse cx=\"50\" cy=\"1.5\" rx=\"52\" ry=\"6\" fill={\"url(#\" + uid + \"m)\"} />\n              </g>\n              <ellipse data-bb=\"glow\" cx=\"50\" cy=\"35\" rx=\"30\" ry=\"22\" fill={\"url(#\" + uid + \"g)\"} opacity=\"0\" />\n              {full && <path d={INNER} strokeWidth={v(0.5)} stroke={GLASS} strokeOpacity=\"0.1\" />}\n              {full && CANALS.map((d, i) => <path key={i} d={d} strokeWidth={v(0.35)} stroke={GLASS} strokeOpacity=\"0.07\" />)}\n            </g>\n            <g data-bb=\"organ\" opacity=\"0.3\" filter={\"url(#\" + uid + \"f)\"}>\n              {GONADS.map((o, i) => (\n                <path key={i} d={KIDNEY} transform={\"translate(\" + o.x + \" \" + o.y + \") rotate(\" + o.r + \") scale(\" + o.s + \")\"} style={{ fill: \"var(--bb-core)\", fillOpacity: 0.5 }} />\n              ))}\n            </g>\n            <path d={DOME_LINE} strokeWidth={v(3.2)} strokeLinecap=\"round\" stroke={\"url(#\" + uid + \"e)\"} strokeOpacity=\"0.1\" />\n            <path d={DOME_LINE} strokeWidth={v(1.5)} strokeLinecap=\"round\" stroke={\"url(#\" + uid + \"e)\"} strokeOpacity=\"0.22\" />\n            <path d={DOME_LINE} strokeWidth={v(0.5)} strokeLinecap=\"round\" stroke={\"url(#\" + uid + \"e)\"} strokeOpacity=\"0.6\" />\n            <path d=\"M21 50Q50 45.4 79 50\" strokeWidth={v(0.4)} stroke={GLASS} strokeOpacity=\"0.14\" />\n            <path data-bb=\"rim\" d={\"M79 50\" + scallops(0.1)} strokeWidth={v(0.5)} strokeLinecap=\"round\" strokeLinejoin=\"round\" style={{ stroke: \"var(--bb-rim)\", strokeOpacity: 0.4 }} />\n            <path d={GLINT_A} strokeWidth={v(0.9)} strokeLinecap=\"round\" stroke=\"#d9ecf8\" strokeOpacity=\"0.42\" />\n            <path d={GLINT_B} strokeWidth={v(0.7)} strokeLinecap=\"round\" stroke=\"#d9ecf8\" strokeOpacity=\"0.22\" />\n          </g>\n        </g>\n      </svg>\n      {(showValue || reduced) && (\n        <div\n          aria-hidden=\"true\"\n          style={{\n            marginTop: 4,\n            fontFamily: 'ui-monospace, \"Geist Mono\", SFMono-Regular, Menlo, Consolas, monospace',\n            fontSize: 10,\n            lineHeight: 1.4,\n            letterSpacing: \"0.14em\",\n            textTransform: \"uppercase\",\n            fontVariantNumeric: \"tabular-nums\",\n            whiteSpace: \"nowrap\",\n            opacity: 0.62,\n          }}\n        >\n          {det ? shown + \"%\" : name}\n        </div>\n      )}\n    </div>\n  );\n}\n","type":"registry:component","target":"components/viberdy/bell-breath-loader.tsx"}],"meta":{"tier":"free","tags":["loader","progress","progressbar","spinner","jellyfish","medusa","svg","breathing","upload","dark","anomaly","attention"],"href":"https://viberdy.dev/library/bell-breath-loader","aiPrompt":"Build a React + Tailwind progress loader, `BellBreathLoader`, as one self-contained \"use client\" file with no dependencies and no WebGL. The anomaly: progress is measured in light, inside a single translucent jellyfish drawn in SVG. It is calm and delicate, never neon, and it must look premium at 48 to 160 px wide.\n\nProps (all live, no re-init): `progress` (0 to 100; null or undefined means indeterminate), `label` (default \"Loading\"), `size` (width in px, 32 to 320, default 96; the figure is 1.65 times as tall), `hue` (\"Medusa\" | \"Ice\" | \"Ember\" | \"Abyss\"), `showValue` (a mono readout under the bell), `onComplete`, `className`, `style`. Export `BellBreathLoader` and `BellBreathLoaderProps`. Clamp every number with a NaN fallback; an invalid hue falls back to Medusa. No template literals anywhere in the file.\n\nPalettes (core / bell / rim, set as CSS variables --bb-core, --bb-bell, --bb-rim on the root so the SVG gradients inherit them): Medusa #ff5aa5 / #6c4dff / #7fd8ff; Ice #d9ecf8 / #4e7fc4 / #a9dcff; Ember #ff7f1e / #b8452c / #ffd3a1; Abyss #2b63ff / #2a2fa0 / #8fb0ff. Glints are always cool white #d9ecf8. Ink is #eaf1f6. Colours are used as light, at low alpha, never as flat fills.\n\nThe SVG (viewBox 0 0 100 165, height = 1.65 x size, aria-hidden, overflow visible, bell centred on x = 50). The glass is near-neutral (#cfe3f2) in every hue; colour lives only in the organs and the progress light. Layers, back to front:\n1. A faint aura ellipse (bell colour, alpha .1 fading out), opacity 0.3 + 0.7 x progress.\n2. Twelve marginal tentacles hanging from the front rim at x = 50 + rel, rel = -27.5, -22.5, -17.5, -12.5, -7.5, -3, 3, 7.5, 12.5, 17.5, 22.5, 27.5 (y follows the rim ellipse), splaying outward as they fall; lengths 60, 84, 70, 106, 64, 96, 102, 66, 108, 76, 88, 58 (a few run much longer). Each is a filled ribbon that tapers to a point (half-width = w0/2 x (1 - s)^1.25 + .03, w0 = 0.6 to 0.9 x the small-size multiplier min(1.9, max(1, 96 / size))), so it fades by length and has no round cap, plus a halo ribbon 3.2 x wider at fill opacity .07 and, at sizes of 72 px and up only, a bead path (dasharray \"0 7.5\", round caps, width .9, alpha .3). All use one vertical userSpace gradient (y 50 to 160): glass .5 at the root, bell colour .46 at 30%, .36 at 70%, .28 at the end.\n3. Four oral arms, thin, long and only slightly frilled (rel -5, -1.8, 1.8, 5; roots y 33 to 34; lengths 82, 100, 92, 72), hanging from the centre and fading out by y = 118 (about 60% of the tentacle length). Two overlapping ribbons per arm: a back one 1.5 x wide (+-22% frill) filled with a core-colour gradient (.16 to .07 to 0) whose opacity is 0.25 + 0.75 x smoothstep(.1, .9, p), so the progress light tints it faintly, and a finer front one filled pale white (#eaf1f6, .2 to .08 to 0). Half-width = (0.55 + 1.5 (1 - s)^0.8) x (a short root ramp) x (a tip taper).\n4. The bell group. A glass dome that is widest (x 12 to 88) about 65% of the way down, then curls inward to a narrower rim: \"M21 50C15 47 12 42 12 35C12 18 28 5 50 5C72 5 88 18 88 35C88 42 85 47 79 50\". The rim is a slight ellipse seen 3/4 on: the front edge sags 3.2 below the tips (y = 50 + 3.2 sin(PI x (79 - x) / 58)) and the back edge is a faint arc (control y 45.4) with a dark mouth between them. Fourteen small lappets are notches along the front edge, each a \"Q\" whose control sits 1 + c x (0.9 + .5 sin(2.1k)) below the edge (c is the contraction, so they flex with the breath; the body, the clip and the margin edge are rebuilt every frame). Fill: vertical glass gradient, alpha .02 at the apex, .05 mid, .15 at the margin. Inside a clipPath of the bell shape: a dark cavity ellipse (cx 50, cy 42, rx 24, ry 8, black .12), the mouth, the light group, the glow ellipse, and (72 px and up only) an inner dome stroke and five radial canals from (50, 12) in glass at alpha .1 and .07. The light group is a rectangle 110 x 84 with a vertical gradient (core 0, core .26 at 9%, bell .14 at 26%, core .11 at 60%, core .08 at 100%) plus a soft crest ellipse (cx 50, cy 1.5, rx 52, ry 6, radial rim gradient .24), translated to y = 60 - 86 x p. The glow ellipse (cx 50, cy 35, rx 30, ry 22, core radial .32) has opacity smoothstep(.15, .8, p). The organs are four soft filled kidney-shaped gonads in a cross at (50, 29.5), (50, 38.5), (41, 34), (59, 34) (core fill .5, no outline), in one group with an feGaussianBlur of stdDeviation 2 (filter region x 26, y 18, w 48, h 30), so they read as a dim glow; the group opacity is 0.3 + 0.7 x clamp((41 - front) / 20). The edge is not an outline but three layered strokes of the open dome line (widths 3.2, 1.5, .5; alphas .1, .22, .6) all using a vertical glass gradient that fades toward the apex (.1 at the top, .4 at 55%, .9 at the margin). The lappet edge is a rim-colour stroke (alpha .4, width .5, opacity .45 + .55 x clamp(5p)). Two glints in #d9ecf8 (.42 and .22).\n\nMotion: one requestAnimationFrame loop, written imperatively (setAttribute on the paths and groups, no React render per frame). State is in a closure; props are held in an `opts` ref synced from an effect without deps that also calls a `refresh` ref, and the main effect has [] deps. The loop runs only while the root intersects (IntersectionObserver, read the last entry) and the tab is visible, and sleeps once the exhale has finished.\n- Breath: period 5 s. pulse(u) = sin(PI x u^0.62)^2: a quick contraction peaking at 31% of the cycle and a slow release. Contraction c scales the bell about (50, 5): scaleX = 1 - .075c, scaleY = 1 + .05c; the whole figure bobs by -2.4c plus slow sways (0.8 over 9.3 s, tilt 1.1 degrees over 11.1 s, 0.5 sideways over 13.7 s).\n- Follow-through: the contraction reaches a point at distance a (0..1 down a tentacle) after a delay of 1.15 x a seconds, i.e. cFn(a) = pulse(cyc(tau - 1.15a)). Each tentacle is 21 samples. Its x is 50 + rel x (1 - .075 c(a)) x (1 - .3a) + a bow, plus a travelling wave amp x a x (0.4 + 0.6a) x sin(2 PI (tau / period - freq x a) + phase) and a static drift x sin(PI x .85a); its y stretches by (1 - .1 c(a)). Periods are 4.2 to 6.7 s per tentacle (incommensurate), amp 4 to 6.4, freq 1.35 to 1.83, divided by the longest length (108). Oral arms use 27 samples with the same wave scaled by their own length (amp 4.2 to 5).\n- Growth: tentacle length t = 0.14 + 0.86 x clamp(p / (0.7 + 0.3 x stagger)), so stubs at 0 and full length by p = 1, with a different stagger per tentacle. Oral arms 0.3 + 0.7 x clamp(p / .8).\n- Progress p is chased with a 0.35 s time constant (a jump is a ramp, never a flash). Indeterminate target: p = 0.34 + 0.34 x (0.5 + 0.5 cos(2 PI (u - 0.55))), so the light breathes with the bell.\n- Entrance: opacity ramps over 700 ms with an 8 px rise.\n- Completion (target reaches 100, not on mount): one exhale over 600 ms, driven by time: the contraction is pulse(u) with the tentacle delay 0.22a, lift is translateY(-24 x (1 - (1 - u)^3.5)) px on the svg element, opacity is 1 - smoothstep(.12, 1, u). Call onComplete once at the start. Then draw nothing and stop the loop. If the value drops below 100 again the bell re-enters (700 ms fade, 8 px rise) and p resets to the new value. If it mounts at 100 it stays hidden with no exhale.\n\nAccessibility: the root is role=\"progressbar\" with aria-label from `label`, aria-valuemin 0, aria-valuemax 100, aria-valuenow (omitted when indeterminate), aria-valuetext (\"64 percent\", \"Complete\"), plus a visually hidden span repeating the name and percentage. The readout (mono 10 px, 0.14em, uppercase, tabular numbers, 62% ink; the percentage, or the label when indeterminate) is aria-hidden and shown when showValue is true or when reduced motion is on. Reduced motion (matchMedia through useSyncExternalStore, live): no loop, one still frame (tau 1.9, contraction .14, sway x .7) lit to the current value, no exhale, plus the readout. Nothing flashes. It is a live-process indicator, never a page-gating splash. The exhale lifts 24 px, so the parent must not clip it.\n\nPreview wrapper: a void ground #04060a, @container root, with a small Aerium card (width min(100%, 760px), background #080c11, 2 px radius, inset hairline rgba(214,232,245,.10)) titled \"Sending your commission\". A mono header (\"Aerium / Commissions\", \"Fig. 06 / Loader\"), a left plate (17.5 rem) with the loader (default size 152) and a placard \"Unit: light, from the rim\", and a right column: placard, the title in Instrument Sans 450 with -0.035em tracking, one line of body copy, four hairline rows (Brief, References, Light plan, Confirmation) whose status (Done, Working, Queued) follows the same number in quarters, and a Cancel button. At 100 the title becomes \"Commission received\" and the Cancel becomes a single #d9ecf8 primary button with ink #0a0e12. Panel props: Progress (0 to 100, default 64), Indeterminate, Replay completion (a toggle that runs the value from 12 to 100 over 4.4 s, holds the finished card until 7.4 s, then hands back to the slider), Specimen (hue), Size (48 to 160), Show the value, Label, Show sample card.","license":"https://viberdy.dev/license"}}