{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "sfx",
  "type": "registry:lib",
  "title": "Doto Sfx helper",
  "description": "Shared Doto UI helper (sfx.ts) used by several components.",
  "author": "Ahmad Raza (MrReal) <https://ahmadraza.cv>",
  "registryDependencies": [
    "https://doto-ui.ahmadraza.cv/r/doto-theme.json"
  ],
  "files": [
    {
      "path": "registry/doto-ui/sfx.ts",
      "content": "/* nothing-sfx — synthesised iOS interaction sounds via Web Audio API.\n   No audio files. All nodes route through a shared master gain + low-pass\n   so the whole set reads as one device's speaker. */\n\nlet ctx: AudioContext | null = null;\nlet master: GainNode | null = null;\nlet enabled = true;\nlet volume = 0.85;\n\nfunction ac(): AudioContext {\n  if (!ctx) {\n    ctx = new AudioContext();\n    master = ctx.createGain();\n    master.gain.value = enabled ? volume : 0;\n    const lp = ctx.createBiquadFilter();\n    lp.type = 'lowpass'; lp.frequency.value = 9500; lp.Q.value = 0.4;\n    master.connect(lp).connect(ctx.destination);\n  }\n  if (ctx.state === 'suspended') ctx.resume();\n  return ctx;\n}\n\nconst out = (): AudioNode => master!;\n\nfunction tone(f: number, dur: number, vol: number, type: OscillatorType = 'sine', ramp = 1.8, at = 0) {\n  const c = ac(), t = c.currentTime + at;\n  const o = c.createOscillator(), g = c.createGain();\n  o.type = type;\n  o.frequency.setValueAtTime(f, t);\n  o.frequency.exponentialRampToValueAtTime(Math.max(40, f / ramp), t + dur);\n  g.gain.setValueAtTime(0.0001, t);\n  g.gain.exponentialRampToValueAtTime(vol, t + 0.008);\n  g.gain.exponentialRampToValueAtTime(0.0001, t + dur);\n  o.connect(g).connect(out());\n  o.start(t); o.stop(t + dur + 0.02);\n}\n\nfunction noise(dur: number, vol: number, freq = 4000, q = 1.2, at = 0) {\n  const c = ac(), t = c.currentTime + at;\n  const buf = c.createBuffer(1, Math.ceil(c.sampleRate * dur), c.sampleRate);\n  const d = buf.getChannelData(0);\n  for (let i = 0; i < d.length; i++) d[i] = Math.random() * 2 - 1;\n  const s = c.createBufferSource(); s.buffer = buf;\n  const f = c.createBiquadFilter(); f.type = 'bandpass'; f.frequency.value = freq; f.Q.value = q;\n  const g = c.createGain();\n  g.gain.setValueAtTime(vol, t);\n  g.gain.exponentialRampToValueAtTime(0.0001, t + dur);\n  s.connect(f).connect(g).connect(out());\n  s.start(t); s.stop(t + dur + 0.02);\n}\n\nfunction whooshNoise(dur: number, vol: number, from: number, to: number) {\n  const c = ac(), t = c.currentTime;\n  const buf = c.createBuffer(1, Math.ceil(c.sampleRate * dur), c.sampleRate);\n  const d = buf.getChannelData(0);\n  for (let i = 0; i < d.length; i++) d[i] = Math.random() * 2 - 1;\n  const s = c.createBufferSource(); s.buffer = buf;\n  const f = c.createBiquadFilter(); f.type = 'bandpass'; f.Q.value = 1.6;\n  f.frequency.setValueAtTime(from, t);\n  f.frequency.exponentialRampToValueAtTime(to, t + dur);\n  const g = c.createGain();\n  g.gain.setValueAtTime(0.0001, t);\n  g.gain.exponentialRampToValueAtTime(vol, t + dur * 0.3);\n  g.gain.exponentialRampToValueAtTime(0.0001, t + dur);\n  s.connect(f).connect(g).connect(out());\n  s.start(t); s.stop(t + dur + 0.02);\n}\n\nexport const sfx = {\n  init: () => ac(),\n  setEnabled: (value: boolean) => { enabled = value; if (ctx && master) master.gain.setTargetAtTime(enabled ? volume : 0, ctx.currentTime, 0.025); },\n  setVolume: (value: number) => { volume = Math.max(0, Math.min(1, value)); if (ctx && master && enabled) master.gain.setTargetAtTime(volume, ctx.currentTime, 0.025); },\n  click: (freq = 2400) => { noise(0.012, 0.05, freq * 2.2, 0.8); tone(freq, 0.035, 0.1, 'sine', 2.2); },\n  tap: () => tone(1800, 0.03, 0.07, 'sine', 2.5),\n  slide: () => noise(0.03, 0.045, 2200, 1),\n  tick: () => { noise(0.008, 0.04, 5200, 2); tone(3800, 0.015, 0.03, 'sine', 4); },\n  pop: () => { tone(340, 0.055, 0.11, 'sine', 1.6); noise(0.014, 0.04, 3000, 1); },\n  on: () => { tone(880, 0.07, 0.12); tone(1760, 0.06, 0.07, 'sine', 3, 0.018); },\n  off: () => tone(660, 0.07, 0.09, 'sine', 3.5),\n  success: () => { tone(1175, 0.13, 0.13); tone(1568, 0.16, 0.11, 'sine', 2.2, 0.065); },\n  chime: () => { tone(1046, 0.12, 0.1); tone(1318, 0.12, 0.09, 'sine', 2, 0.07); tone(1568, 0.2, 0.09, 'sine', 2, 0.14); },\n  error: () => { tone(220, 0.12, 0.12); tone(180, 0.1, 0.09, 'sine', 1.2, 0.085); },\n  del: () => tone(320, 0.16, 0.1, 'sine', 4),\n  send: () => { whooshNoise(0.14, 0.05, 700, 2600); tone(620, 0.07, 0.07, 'sine', 0.5); },\n  receive: () => { tone(1320, 0.055, 0.09, 'sine', 2.2); noise(0.01, 0.025, 5000); },\n  hold: () => tone(180, 0.18, 0.08, 'sine', 1.1),\n  bounce: () => { tone(520, 0.05, 0.07); tone(780, 0.04, 0.035, 'sine', 1.5, 0.04); },\n  whoosh: () => whooshNoise(0.26, 0.04, 500, 3200),\n  unlock: () => { tone(523, 0.08, 0.11); tone(659, 0.08, 0.09, 'sine', 1.1, 0.06); tone(784, 0.13, 0.08, 'sine', 1.1, 0.12); },\n  startup: () => { tone(130, 0.5, 0.06, 'sine', 1.4); tone(523, 0.1, 0.08, 'sine', 1.2, 0.12); tone(659, 0.1, 0.07, 'sine', 1.2, 0.2); tone(784, 0.22, 0.08, 'sine', 1.1, 0.28); },\n  /** camera / trigger — two hard transients */\n  shutter: () => { tone(1400, 0.02, 0.09, 'sine', 7); tone(900, 0.03, 0.1, 'sine', 5.6, 0.035); noise(0.018, 0.05, 3400, 1.4, 0.035); },\n\n  /* ─────────── cinematic launch-film layer ─────────── */\n\n  /** 00:00 — deep sub-bass drop + warm dark analog swell */\n  subDrop: () => {\n    const c = ac(), t = c.currentTime;\n    const o = c.createOscillator(), g = c.createGain();\n    o.type = 'sine';\n    o.frequency.setValueAtTime(95, t);\n    o.frequency.exponentialRampToValueAtTime(34, t + 0.9);\n    g.gain.setValueAtTime(0.0001, t);\n    g.gain.exponentialRampToValueAtTime(0.5, t + 0.05);\n    g.gain.exponentialRampToValueAtTime(0.0001, t + 1.0);\n    o.connect(g).connect(out()); o.start(t); o.stop(t + 1.05);\n    /* warm analog swell riding on top */\n    tone(150, 1.5, 0.11, 'triangle', 2.6, 0.03);\n    tone(220, 1.4, 0.06, 'sine', 3, 0.1);\n  },\n\n  /** 00:06 — heavy clean beat drop + LED matrix power-on hum */\n  beatDrop: () => {\n    const c = ac(), t = c.currentTime;\n    const o = c.createOscillator(), g = c.createGain();\n    o.type = 'sine';\n    o.frequency.setValueAtTime(58, t);\n    o.frequency.exponentialRampToValueAtTime(42, t + 0.5);\n    g.gain.setValueAtTime(0.0001, t);\n    g.gain.exponentialRampToValueAtTime(0.62, t + 0.02);\n    g.gain.exponentialRampToValueAtTime(0.0001, t + 0.7);\n    o.connect(g).connect(out()); o.start(t); o.stop(t + 0.75);\n    /* static LED power-on hum */\n    const buf = c.createBuffer(1, Math.ceil(c.sampleRate * 0.7), c.sampleRate);\n    const d = buf.getChannelData(0);\n    for (let i = 0; i < d.length; i++) d[i] = (Math.random() * 2 - 1) * 0.35;\n    const s = c.createBufferSource(); s.buffer = buf;\n    const f = c.createBiquadFilter(); f.type = 'bandpass'; f.frequency.value = 3200; f.Q.value = 1.4;\n    const ng = c.createGain();\n    ng.gain.setValueAtTime(0.0001, t);\n    ng.gain.exponentialRampToValueAtTime(0.11, t + 0.08);\n    ng.gain.exponentialRampToValueAtTime(0.0001, t + 0.7);\n    s.connect(f).connect(ng).connect(out()); s.start(t); s.stop(t + 0.72);\n  },\n\n  /** 00:03 — crisp tactile mechanical switch tick (nav pill slide) */\n  switchTick: (i = 0) => {\n    tone(2100 + i * 260, 0.022, 0.1, 'square', 3.2);\n    noise(0.012, 0.06, 4200, 1.6);\n  },\n\n  /** 00:09 — airy low-end camera whoosh on the 3D tilt */\n  cameraWhoosh: () => {\n    const c = ac(), t = c.currentTime;\n    const buf = c.createBuffer(1, Math.ceil(c.sampleRate * 0.75), c.sampleRate);\n    const d = buf.getChannelData(0);\n    for (let i = 0; i < d.length; i++) d[i] = Math.random() * 2 - 1;\n    const s = c.createBufferSource(); s.buffer = buf;\n    const f = c.createBiquadFilter(); f.type = 'bandpass'; f.Q.value = 2.4;\n    f.frequency.setValueAtTime(180, t);\n    f.frequency.exponentialRampToValueAtTime(1900, t + 0.75);\n    const g = c.createGain();\n    g.gain.setValueAtTime(0.0001, t);\n    g.gain.exponentialRampToValueAtTime(0.16, t + 0.28);\n    g.gain.exponentialRampToValueAtTime(0.0001, t + 0.75);\n    s.connect(f).connect(g).connect(out()); s.start(t); s.stop(t + 0.77);\n    tone(70, 0.6, 0.2, 'sine', 2.2);\n  },\n\n  /** 00:09 — Apple-style haptic tap on button press */\n  hapticTap: () => { tone(165, 0.045, 0.3, 'sine', 1.25); noise(0.02, 0.05, 900, 1.4); },\n\n  /** 00:13 — fast digital rotary counter tick (one per roll frame) */\n  counterTick: (v = 0) => {\n    const step = 1 + (v / 668) * 5;\n    tone(760 + step * 190, 0.016, 0.07, 'square', 2.6);\n  },\n\n  /** 00:13 — magnetic slider zip while dragging */\n  sliderZip: () => noise(0.09, 0.05, 1100, 1.1),\n\n  /** 00:18 — rising synth sweep as layers float up in Z */\n  riseSweep: () => {\n    const c = ac(), t = c.currentTime;\n    const o = c.createOscillator(), g = c.createGain();\n    o.type = 'sawtooth';\n    o.frequency.setValueAtTime(140, t);\n    o.frequency.exponentialRampToValueAtTime(760, t + 1.05);\n    const f = c.createBiquadFilter();\n    f.type = 'lowpass';\n    f.frequency.setValueAtTime(420, t);\n    f.frequency.exponentialRampToValueAtTime(2600, t + 1.05);\n    g.gain.setValueAtTime(0.0001, t);\n    g.gain.exponentialRampToValueAtTime(0.09, t + 0.34);\n    g.gain.exponentialRampToValueAtTime(0.0001, t + 1.05);\n    o.connect(f).connect(g).connect(out()); o.start(t); o.stop(t + 1.08);\n  },\n\n  /** 00:18 — glass pop on the copy chip */\n  glassPop: () => { tone(920, 0.05, 0.1, 'sine', 2.4); noise(0.03, 0.07, 5200, 2); tone(1380, 0.05, 0.05, 'sine', 2.6, 0.01); },\n\n  /** 00:24 — rapid mechanical relay click synced to the slot swaps */\n  relayClick: () => { noise(0.014, 0.09, 3000, 2.2); tone(1200, 0.014, 0.07, 'square', 3.4); },\n\n  /** 00:28 — deep cinematic sub-boom impact + ambient tail */\n  subBoom: () => {\n    const c = ac(), t = c.currentTime;\n    const o = c.createOscillator(), g = c.createGain();\n    o.type = 'sine';\n    o.frequency.setValueAtTime(78, t);\n    o.frequency.exponentialRampToValueAtTime(27, t + 1.9);\n    g.gain.setValueAtTime(0.0001, t);\n    g.gain.exponentialRampToValueAtTime(0.58, t + 0.03);\n    g.gain.exponentialRampToValueAtTime(0.0001, t + 2.0);\n    o.connect(g).connect(out()); o.start(t); o.stop(t + 2.05);\n    tone(196, 1.8, 0.07, 'sine', 2.8, 0.04);\n    tone(294, 1.5, 0.04, 'sine', 3, 0.12);\n  },\n};\nexport type SfxName = Exclude<keyof typeof sfx, 'init'>;\n",
      "type": "registry:lib",
      "target": "@components/doto-ui/sfx.ts"
    }
  ]
}
