{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ember-sun",
  "title": "Ember Sun",
  "author": "HorizonX <https://horizonx.so>",
  "description": "A burning sun drawn in one WebGL shader: a ring of fire round a cracked, turning crust that reacts to the pointer.",
  "files": [
    {
      "path": "registry/drops/ember-sun/ember-sun.tsx",
      "content": "'use client';\n\nimport { useEffect, useRef, type CSSProperties } from 'react';\nimport { buildEmberSun, DEFAULT_EMBER_SUN_CONFIG, type EmberSunConfig, type EmberSunHandle } from './ember-sun.engine.js';\n\nexport interface EmberSunProps {\n  /** Radius as a share of the short side, 0.16 to 0.36. */\n  size?: number;\n  /** Flame height, 0.4 to 1.6. */\n  flames?: number;\n  /** Rising embers, 0 to 2. */\n  embers?: number;\n  /** Ripples landing on the rim, 0 to 2. */\n  ripples?: number;\n  background?: string;\n  /** Colour of the core that glows between the crust plates. */\n  core?: string;\n  /** 0.2 to 2. */\n  speed?: number;\n  paused?: boolean;\n  /** The flames lean toward the pointer and a press sends a ripple. */\n  interactive?: boolean;\n  className?: string;\n  style?: CSSProperties;\n}\n\nconst clamp = (value: number | undefined, min: number, max: number, fallback: number) =>\n  typeof value === 'number' && Number.isFinite(value) ? Math.min(max, Math.max(min, value)) : fallback;\n\nfunction toConfig(props: EmberSunProps): Partial<EmberSunConfig> {\n  const d = DEFAULT_EMBER_SUN_CONFIG;\n  return {\n    size: clamp(props.size, 0.16, 0.36, d.size),\n    flames: clamp(props.flames, 0.4, 1.6, d.flames),\n    embers: clamp(props.embers, 0, 2, d.embers),\n    ripples: clamp(props.ripples, 0, 2, d.ripples),\n    background: props.background ?? d.background,\n    core: props.core ?? d.core,\n    speed: clamp(props.speed, 0.2, 2, d.speed),\n    animate: !props.paused,\n    interactive: props.interactive ?? true\n  };\n}\n\nconst CSS = `\n.esn-viewport{position:relative;box-sizing:border-box;width:100%;height:100%;overflow:hidden;isolation:isolate;container-type:size;touch-action:manipulation}\n.esn-stage{position:absolute;inset:0}\n.esn-viewport[data-fallback] .esn-stage::before{content:\"\";position:absolute;left:50%;top:50%;width:60cqmin;height:60cqmin;transform:translate(-50%,-50%);border-radius:50%;background:#0b0809;box-shadow:0 0 0 2px #ffd2a0,0 0 18px 6px #ff5a1f,0 0 90px 24px rgba(255,90,31,.35)}\n.esn-status{position:absolute;inset:0;display:grid;place-items:center;padding:24px;color:#b4b4bc;font:14px/1.5 system-ui,sans-serif;text-align:center;pointer-events:none}\n.esn-status:empty{display:none}\n`;\n\n/** A burning sun drawn per pixel in one WebGL shader: a ring of fire round a cracked, turning crust. Fills its parent. */\nexport function EmberSun({ className, style, ...props }: EmberSunProps) {\n  const root = useRef<HTMLDivElement>(null);\n  const engine = useRef<EmberSunHandle | null>(null);\n  const config = toConfig(props);\n  const latest = useRef(config);\n  const key = JSON.stringify(config);\n\n  // Declared before the mount effect so a remount always starts from the newest props.\n  useEffect(() => {\n    latest.current = config;\n    engine.current?.update(config);\n  }, [key]); // eslint-disable-line react-hooks/exhaustive-deps\n\n  useEffect(() => {\n    const handle = buildEmberSun(root.current!, latest.current);\n    engine.current = handle;\n    return () => { handle(); engine.current = null; };\n  }, []);\n\n  return (\n    <>\n      <style href=\"hx-drops-ember-sun\" precedence=\"default\">{CSS}</style>\n      <div\n        ref={root}\n        className={className ? `esn-viewport ${className}` : 'esn-viewport'}\n        style={{ background: config.background, ...style }}\n      >\n        <div className=\"esn-stage\" />\n        <span className=\"esn-status\" role=\"status\" />\n      </div>\n    </>\n  );\n}\n\nexport default EmberSun;\n",
      "type": "registry:component"
    },
    {
      "path": "registry/drops/ember-sun/ember-sun.engine.js",
      "content": "// HorizonX Drops: this engine is copied unchanged from the HorizonX editor\n// (horizonx-frontend src/lib/tools/emberSun.engine.js at 00b7cec).\n// Licensed under the HorizonX Drops License in this repository's LICENSE file.\n// Do not edit here: change it in horizonx-frontend and run scripts/sync-from-horizonx.mjs.\n// --- end of HorizonX Drops banner ---\n/**\n * Ember Sun: a burning sun drawn per pixel in one WebGL fragment shader.\n * Original HorizonX code, no libraries and no assets, so the editor and the\n * HTML/React/Svelte exports run the same file.\n *\n *   1. A full ring of fire: domain-warped flame tongues burn evenly round a\n *      torn, rippling rim, with heat haze, a white-hot rim line, bloom and\n *      embers drifting up. Ripples land on the rim at random angles.\n *   2. Inside, the ball is a crust of rock plates (a 3D Voronoi pattern on a\n *      turning sphere) split by glowing magma cracks.\n *   3. The pointer leans the flames toward it, turns and lights the ball and\n *      opens the cracks near it. The plates right under it come unstuck and\n *      float above sockets that show a cold core; when it moves on they settle\n *      back and the seams cool to magma.\n *\n * Two builds of the shader are linked: \"calm\" without the floating plates for\n * the usual frame, \"full\" with them while a plate is off the ball.\n */\n\nexport const DEFAULT_EMBER_SUN_CONFIG = {\n  viewportWidth: 1040,\n  viewportHeight: 620,\n  size: 0.3,\n  background: '#07080a',\n  core: '#0d66ff',\n  flames: 1,\n  embers: 1,\n  ripples: 1,\n  speed: 1,\n  animate: true,\n  interactive: true\n};\n\n// The sun's radius in shader units. The fire is drawn at a fixed size in these\n// units (flames reach 0.17), so the whole sun scales together with `size`.\nconst R_UNITS = 0.42;\n\nconst VERT = 'attribute vec2 a; void main(){ gl_Position = vec4(a, 0.0, 1.0); }';\n\nconst FRAG = `\nprecision highp float;\nuniform vec2  uRes;\nuniform vec2  uArc;      // top of the sun's rim, canvas px (y from bottom); the centre is uRadius below\nuniform float uUnit;     // canvas px per unit\nuniform float uRadius;   // sun radius in units\nuniform float uTime;\nuniform float uFlow;     // flame/ember time; runs faster while the wheel spins or the pointer moves\nuniform float uClock;    // wall clock for pointer ripples, so they fade even while paused\nuniform vec2  uMouse;    // pointer in units, same space as p\nuniform float uMouseOn;  // 0..1 pointer influence (fades when idle)\nuniform vec2  uMouseVel; // smoothed pointer velocity, units/s\nuniform vec3  uPR[4];    // pointer ripples: xy position, z start (uClock)\nuniform float uScrollVel;// 0..1.5 smoothed wheel speed\nuniform vec4  uSpot[8];  // hovered points of the crust: xyz = point on the turning sphere, w = seconds since hovered\nuniform float uLeft[8];  // the spot's age when the pointer left it (1e4 while still over it)\nuniform int   uSpotN;    // spots in use; only spots that still hold a plate off the ball are sent\nuniform vec3  uBg;       // background, before the tone map\nuniform vec3  uCore;     // colour of the core under a lifted plate\nuniform float uFlames;   // flame height multiplier\nuniform float uEmbers;   // ember density, 0..2\nuniform float uRipples;  // ripple strength, 0..2\n\nconst float PI = 3.14159265;\n\nfloat hash(vec2 p){ p = fract(p * vec2(123.34, 456.21)); p += dot(p, p + 45.32); return fract(p.x * p.y); }\nfloat noise(vec2 p){\n  vec2 i = floor(p), f = fract(p);\n  vec2 u = f * f * (3.0 - 2.0 * f);\n  return mix(mix(hash(i), hash(i + vec2(1.0, 0.0)), u.x),\n             mix(hash(i + vec2(0.0, 1.0)), hash(i + vec2(1.0, 1.0)), u.x), u.y);\n}\nfloat fbm(vec2 p){\n  float v = 0.0, a = 0.5;\n  mat2 m = mat2(1.6, 1.2, -1.2, 1.6);\n  for (int i = 0; i < 5; i++) { v += a * noise(p); p = m * p; a *= 0.5; }\n  return v;\n}\nvec3 fireRamp(float x){\n  x = clamp(x, 0.0, 1.0);\n  vec3 c = mix(vec3(0.0), vec3(0.38, 0.025, 0.0), smoothstep(0.0, 0.22, x));\n  c = mix(c, vec3(0.95, 0.2, 0.02), smoothstep(0.18, 0.5, x));\n  c = mix(c, vec3(1.0, 0.52, 0.12), smoothstep(0.48, 0.78, x));\n  c = mix(c, vec3(1.0, 0.9, 0.72), smoothstep(0.82, 1.0, x));\n  return c;\n}\n\n// Torn, rippling rim at arc position s = angle * radius\nfloat rimJag(float s, float t){\n  return (fbm(vec2(s * 7.0, t * 0.35)) - 0.5) * 0.026\n       + (noise(vec2(s * 40.0, t * 1.5)) - 0.5) * 0.006;\n}\n// Flame tongues at arc position s: x = noise, yz = domain warp\nvec3 flameField(float s, float h, float lean, float fl){\n  vec2 fp = vec2(s * 3.6 - lean * max(h, 0.0) * 3.6 * 2.4, h * 2.6 - fl * 0.9);\n  vec2 warp = vec2(fbm(fp * 1.25 + vec2(0.0, fl * 0.18)), fbm(fp * 1.25 + vec2(3.7, -fl * 0.14)));\n  float n = fbm(fp * 2.2 + warp * 1.8 - vec2(0.0, fl * 0.6));\n  return vec3(n, warp);\n}\nfloat lavaField(float s, float h, vec2 warp, float t){\n  return fbm(vec2(s * 4.0, h * 5.0 + t * 0.22) + warp);\n}\n\nvec3 hash3(vec3 p){\n  p = vec3(dot(p, vec3(127.1, 311.7, 74.7)), dot(p, vec3(269.5, 183.3, 246.1)), dot(p, vec3(113.5, 271.9, 124.6)));\n  return fract(sin(p) * 43758.5453);\n}\nvec3 cellPoint(vec3 g, float t){\n  vec3 o = hash3(g);\n  return 0.5 + 0.38 * sin(t * 0.25 + 6.2831 * o);   // plates drift slowly\n}\n// Distance to the nearest plate border of a 3D Voronoi pattern (two-pass edge distance),\n// plus a 0..1 id of the plate the point belongs to and its seed point\nvec2 voroEdge(vec3 x, float t, out vec3 seed){\n  vec3 n = floor(x), f = fract(x);\n  vec3 mr = vec3(0.0), mg = vec3(0.0);\n  float md = 8.0;\n  for (int k = -1; k <= 1; k++) for (int j = -1; j <= 1; j++) for (int i = -1; i <= 1; i++) {\n    vec3 g = vec3(float(i), float(j), float(k));\n    vec3 r = g + cellPoint(n + g, t) - f;\n    float d = dot(r, r);\n    if (d < md) { md = d; mr = r; mg = g; }\n  }\n  md = 8.0;\n  for (int k = -1; k <= 1; k++) for (int j = -1; j <= 1; j++) for (int i = -1; i <= 1; i++) {\n    vec3 g = mg + vec3(float(i), float(j), float(k));\n    vec3 r = g + cellPoint(n + g, t) - f;\n    vec3 dr = r - mr;\n    if (dot(dr, dr) > 1e-5) md = min(md, dot(0.5 * (mr + r), normalize(dr)));\n  }\n  seed = x + mr;\n  return vec2(md, hash3(n + mg).x);\n}\n// voroEdge() for a point expected on plate id: gives up after the first pass (x = -1) when it is on another plate\nvec2 voroEdgeOn(vec3 x, float t, float id){\n  vec3 n = floor(x), f = fract(x);\n  vec3 mr = vec3(0.0), mg = vec3(0.0);\n  float md = 8.0;\n  for (int k = -1; k <= 1; k++) for (int j = -1; j <= 1; j++) for (int i = -1; i <= 1; i++) {\n    vec3 g = vec3(float(i), float(j), float(k));\n    vec3 r = g + cellPoint(n + g, t) - f;\n    float d = dot(r, r);\n    if (d < md) { md = d; mr = r; mg = g; }\n  }\n  float pid = hash3(n + mg).x;\n  if (abs(pid - id) > 1e-5) return vec2(-1.0, pid);\n  md = 8.0;\n  for (int k = -1; k <= 1; k++) for (int j = -1; j <= 1; j++) for (int i = -1; i <= 1; i++) {\n    vec3 g = mg + vec3(float(i), float(j), float(k));\n    vec3 r = g + cellPoint(n + g, t) - f;\n    vec3 dr = r - mr;\n    if (dot(dr, dr) > 1e-5) md = min(md, dot(0.5 * (mr + r), normalize(dr)));\n  }\n  return vec2(md, pid);\n}\n// Nearest plate only (first Voronoi pass): x = plate id, yzw = the plate's seed point in crack space\nvec4 voroNear(vec3 x, float t){\n  vec3 n = floor(x), f = fract(x);\n  vec3 mg = vec3(0.0), mp = vec3(0.0);\n  float md = 8.0;\n  for (int k = -1; k <= 1; k++) for (int j = -1; j <= 1; j++) for (int i = -1; i <= 1; i++) {\n    vec3 g = vec3(float(i), float(j), float(k));\n    vec3 o = cellPoint(n + g, t);\n    vec3 r = g + o - f;\n    float d = dot(r, r);\n    if (d < md) { md = d; mg = g; mp = o; }\n  }\n  return vec4(hash3(n + mg).x, n + mg + mp);\n}\nmat2 rot(float a){ return mat2(cos(a), sin(a), -sin(a), cos(a)); }\n// Disc point -> crack space on the turning sphere; N returns the view-space normal\nvec3 crustSpace(vec2 s, float ay, float ax, out vec3 N){\n  N = vec3(s, sqrt(1.0 - min(dot(s, s), 0.998)));\n  vec3 P = N;\n  P.xz = rot(ay) * P.xz;\n  P.yz = rot(ax) * P.yz;\n  vec3 X = P * 2.6;\n  return X + (vec3(fbm(X.xy * 1.7 + 3.1), fbm(X.yz * 1.7 + 7.3), fbm(X.zx * 1.7 + 1.9)) - 0.5) * 0.35;   // rocky edges\n}\n// Crack-space seed point -> where it sits on the disc\nvec2 discOf(vec3 X, float ay, float ax){\n  vec3 P = normalize(X);\n  P.yz = rot(-ax) * P.yz;\n  P.xz = rot(-ay) * P.xz;\n  return P.xy;\n}\n/* How far a plate has lifted off the ball. D = direction of the plate's seed on the turning sphere.\n   x = 0..1 lift (rises while the pointer is over it, settles back once it leaves),\n   y = seconds since that spot was hovered (drives the bobbing), zw = the spot on the disc.\n   Plates right under the pointer lift fully, their neighbours only partly. */\nvec4 plateLift(vec3 D, float ay, float ax, out float back){\n  vec4 r = vec4(0.0);\n  back = 0.0;                                                  // 0 while the pointer holds it, 1 once it is home\n  for (int i = 0; i < 8; i++) {\n    if (i >= uSpotN) break;\n    vec4 sp = uSpot[i];\n    float d = length(D - sp.xyz);\n    if (d > 0.5) continue;                                    // only the plates around the pointer\n    float delay = 0.05 + d * 0.7;                              // the plate under the pointer lets go first\n    float left = uLeft[i];\n    float up = smoothstep(0.0, 0.6, min(sp.w, left) - delay);\n    float down = 1.0 - smoothstep(0.0, 0.8, sp.w - left);       // the pointer left: it settles back in place\n    float l = up * down * (1.0 - smoothstep(0.18, 0.5, d));\n    if (l > r.x) { r = vec4(l, sp.w, discOf(sp.xyz, ay, ax)); back = 1.0 - down; }\n  }\n  return r;\n}\n// Where a lifted plate floats to: pushed away from the pointer, a little smaller (it hangs above the ball),\n// gently bobbing and swaying. Returns the disc point under it that it came from.\nvec2 liftSource(vec2 s, vec2 pc, float pid, vec4 lf){\n  float l = lf.x, b = lf.y;\n  vec2 away = pc - lf.zw;\n  away = dot(away, away) > 1e-4 ? normalize(away) : vec2(cos(pid * 6.283), sin(pid * 6.283));\n  vec2 off = away * 0.1 * l + vec2(sin(b * 1.7 + pid * 6.283), cos(b * 1.3 + pid * 9.42)) * 0.02 * l\n           + vec2(0.0, 0.025) * l;                             // and drifts up a touch, floating\n  float ang = ((pid - 0.5) * 0.3 + 0.06 * sin(b * 1.1 + pid * 12.0)) * l;\n  float sc = 1.0 - 0.16 * l;\n  return pc + rot(-ang) * (s - pc - off) / sc;\n}\n/* Plate pid (seed pseed, lift lf) drawn where its float puts it, if that covers disc point s.\n   rgb = the piece, a = its coverage (0: not over s). */\nvec4 floatingPiece(vec2 s, float pid, vec3 pseed, vec4 lf, float ay, float ax, float t, vec3 L, float flick, float width){\n  if (lf.x < 0.01) return vec4(0.0);\n  vec2 src = liftSource(s, discOf(pseed, ay, ax), pid, lf);\n  if (dot(src, src) > 0.995) return vec4(0.0);\n  vec3 Nf;\n  vec3 Xf = crustSpace(src, ay, ax, Nf);\n  vec2 vf = voroEdgeOn(Xf, t, pid);\n  if (vf.x < 0.0) return vec4(0.0);\n  float gr = fbm(Xf.xy * 6.0 + Xf.z * 2.0);\n  float dl = max(dot(Nf, L), 0.0);\n  vec3 piece = vec3(0.075, 0.062, 0.058) * (0.55 + 0.9 * gr) * (0.3 + 0.95 * dl) * (1.0 + 0.35 * lf.x);  // closer to the light\n  float lip = 1.0 - smoothstep(0.0, 0.08, vf.x);\n  piece += vec3(1.0, 0.4, 0.07) * lip * (0.7 + 0.3 * flick) * (0.6 + 0.7 * lf.x);   // its broken, still molten rim\n  return vec4(piece, max(smoothstep(0.0, 0.5 * width, vf.x) * smoothstep(0.01, 0.04, lf.x), 1e-6));\n}\n/* Cracked crust inside the sun: rock plates split by magma.\n   s = position on the disc (0 at the centre, 1 at the rim); md2 = squared distance to the pointer. */\nvec3 crackedCrust(vec2 s, float t, float fl, float md2){\n  vec2 m = (uMouse - vec2(0.0, -uRadius)) / uRadius;    // pointer relative to the sun's centre\n  vec2 tilt = clamp(m, -1.6, 1.6) * 0.32 * uMouseOn;\n  float ay = t * 0.05 - tilt.x, ax = tilt.y;\n\n  float nearC = exp(-md2 * 14.0) * uMouseOn;\n  float speed = min(length(uMouseVel), 2.0) * uMouseOn;\n  float px = 2.6 / (uRadius * uUnit);                    // one screen pixel in crack space\n  float width = max(0.045, 1.6 * px) * (1.0 + 1.3 * nearC + 0.35 * speed + 0.5 * min(uScrollVel, 1.0));\n  vec3 L = normalize(mix(vec3(-0.45, 0.55, 0.9), vec3(m * 0.9, 0.8), uMouseOn));   // the pointer is the light\n\n  // 1. The crust in place\n  vec3 N, seed;\n  vec3 X = crustSpace(s, ay, ax, N);\n  vec2 vc = voroEdge(X, t, seed);\n  float e = vc.x;\n  float crack = 1.0 - smoothstep(0.0, width, e);\n  float glow = exp(-e * 14.0 / (1.0 + nearC));             // underglow on the plate edges\n  float flick = fbm(X.xy * 3.0 + vec2(0.0, -fl * 0.9));    // magma flowing in the cracks\n  float dif = max(dot(N, L), 0.0);\n  float grain = fbm(X.xy * 6.0 + X.z * 2.0);\n  vec3 rock = vec3(0.075, 0.062, 0.058) * (0.55 + 0.9 * grain) * (0.25 + 0.95 * dif);\n  float heat = crack * (0.62 + 0.38 * flick) * (0.95 + 0.6 * nearC + 0.25 * speed + 0.3 * min(uScrollVel, 1.0));\n\n#if PLATES\n  float back;\n  vec4 own = plateLift(normalize(seed), ay, ax, back);\n  heat += smoothstep(0.0, 0.3, own.x) * exp(-e * 22.0) * 0.4;   // a plate coming loose: its outline flares\n#endif\n  vec3 col = rock + vec3(1.0, 0.36, 0.06) * glow * (0.22 + 0.35 * nearC) + fireRamp(heat);\n\n#if PLATES\n  // 2. Where a plate lifted off: the core, with the floating plate's shadow on it\n  float hole = smoothstep(0.02, 0.15, own.x);\n  if (hole > 0.0) {\n    float pl = fbm(s * 3.2 + vec2(fl * 0.25, -fl * 0.45));\n    vec3 abyss = mix(uCore * uCore * 0.26, uCore, smoothstep(0.2, 0.8, pl))\n               + mix(sqrt(uCore), vec3(1.0), 0.25) * smoothstep(0.58, 0.95, pl) * (0.6 + 0.6 * nearC);\n    abyss *= (0.75 + 0.25 * smoothstep(0.0, 0.08, e)) * (0.85 + 0.3 * (1.0 - dot(s, s)));\n    vec2 sh = s + normalize(L.xy + vec2(1e-3)) * 0.035 * own.x;   // the plate's shadow falls away from the light\n    vec3 Ns2;\n    vec2 vs = voroEdgeOn(crustSpace(liftSource(sh, discOf(seed, ay, ax), vc.y, own), ay, ax, Ns2), t, vc.y);\n    if (vs.x >= 0.0) abyss *= 1.0 - 0.6 * smoothstep(0.0, 0.1, vs.x);\n    // the pointer left: the core cools back to magma as the plate settles, so the seams close orange\n    abyss = mix(abyss, fireRamp(0.55 + 0.3 * flick) * (0.75 + 0.25 * smoothstep(0.0, 0.08, e)), smoothstep(0.0, 0.2, back));\n    col = mix(col, abyss, hole);\n  }\n\n  // 3. The floating plates, drawn over everything. A piece seen here came from a little closer to the\n  //    spot that lifted it: try the plates along the line toward the nearest spot (then the next one),\n  //    undo their float, and keep the pixel if it lands on the same plate.\n  if (uSpotN > 0) {\n    float d1 = 9.0, d2 = 9.0;\n    vec2 a1 = vec2(0.0), a2 = vec2(0.0);\n    for (int i = 0; i < 8; i++) {\n      if (i >= uSpotN) break;\n      vec2 at = discOf(uSpot[i].xyz, ay, ax);\n      float d = length(s - at);\n      if (d < d1) { d2 = d1; a2 = a1; d1 = d; a1 = at; }\n      else if (d < d2) { d2 = d; a2 = at; }\n    }\n    vec4 fp = floatingPiece(s, vc.y, seed, own, ay, ax, t, L, flick, width);   // the plate right here\n    vec4 seen = vec4(vc.y);\n    float bk;\n    for (int k = 0; k < 2; k++) {\n      if (fp.a > 0.0 || (k == 0 ? d1 : d2) > 0.8) break;\n      vec2 toward = s - (k == 0 ? a1 : a2);\n      toward = dot(toward, toward) > 1e-4 ? -normalize(toward) : vec2(0.0, -1.0);\n      vec2 side = vec2(-toward.y, toward.x);\n      for (int j = 1; j < 7; j++) {\n        float fj = float(j);\n        vec2 g = s + (j < 5 ? toward * (0.035 * fj) : side * (fj == 5.0 ? 0.06 : -0.06) + toward * 0.05);\n        vec3 N0;\n        vec4 gs = voroNear(crustSpace(g, ay, ax, N0), t);\n        if (any(lessThan(abs(seen - gs.x), vec4(1e-6)))) continue;\n        seen = vec4(gs.x, seen.xyz);\n        fp = floatingPiece(s, gs.x, gs.yzw, plateLift(normalize(gs.yzw), ay, ax, bk), ay, ax, t, L, flick, width);\n        if (fp.a > 0.0) break;\n      }\n    }\n    col = mix(col, fp.rgb, fp.a);\n  }\n#endif\n  // glass shell: fresnel edge and a highlight that follows the light\n  vec3 Ns = vec3(s, sqrt(1.0 - min(dot(s, s), 0.998)));\n  col += vec3(1.0, 0.8, 0.6) * pow(1.0 - Ns.z, 4.0) * 0.1;\n  col += vec3(1.0, 0.85, 0.7) * pow(max(dot(reflect(-L, Ns), vec3(0.0, 0.0, 1.0)), 0.0), 40.0) * 0.18;\n  return col;\n}\n\nvoid main(){\n  vec2 p0 = (gl_FragCoord.xy - uArc) / uUnit;  // top of the rim = origin\n  vec2 p = p0;\n  float t = uTime;\n  float fl = uFlow;\n  vec2 centre = vec2(0.0, -uRadius);\n\n  // Pointer influence (broad field and a tight core)\n  vec2 dm = p0 - uMouse;\n  float md2 = dot(dm, dm);\n  float near = exp(-md2 * 9.0) * uMouseOn;\n  float core = exp(-md2 * 70.0) * uMouseOn;\n\n  /* 1. Ripple impulses dropped on the rim at seeded angles */\n  vec2 disp = vec2(0.0);\n  float rippleLight = 0.0;\n  for (int i = 0; i < 4; i++) {\n    float fi = float(i);\n    float period = 4.6 + fi * 0.9;\n    float ph = t / period + fi * 0.31;\n    float cyc = floor(ph);\n    float age = fract(ph);\n    float a = hash(vec2(cyc, fi + 1.7)) * 2.0 * PI;\n    float rr = uRadius + (hash(vec2(fi + 4.1, cyc)) - 0.35) * 0.3;\n    vec2 c = centre + rr * vec2(sin(a), cos(a));\n    vec2 dv = p - c;\n    float d = length(dv);\n    float band = d - age * 0.75;\n    float w = sin(band * 52.0) * exp(-band * band * 140.0) * (1.0 - age) * (1.0 - age) * uRipples;\n    disp += dv / (d + 1e-3) * w * 0.011;\n    rippleLight += abs(w) * (1.0 - age);\n  }\n  // Ripples dropped by the pointer as it moves\n  for (int i = 0; i < 4; i++) {\n    vec3 r = uPR[i];\n    float age = (uClock - r.z) / 1.5;\n    if (age > 0.0 && age < 1.0) {\n      vec2 dv = p0 - r.xy;\n      float d = length(dv);\n      float band = d - age * 0.55;\n      float w = sin(band * 46.0) * exp(-band * band * 150.0) * (1.0 - age) * (1.0 - age) * uRipples;\n      disp += dv / (d + 1e-3) * w * 0.017;\n      rippleLight += abs(w) * (1.0 - age) * 1.6;\n    }\n  }\n\n  float flameH = 0.17 * uFlames * (1.0 + 0.9 * near + 0.5 * min(uScrollVel, 1.0));\n\n  /* 2. Rising heat haze, only near the fire (beyond it, it would only nudge the faint glow) */\n  vec2 q = p + disp;\n  bool fire = length(q - centre) - uRadius - 0.05 * exp(-md2 * 6.0) * uMouseOn < flameH * 1.18 + 0.05;\n  if (fire) {\n    vec2 hz = vec2(fbm(p * 3.2 + vec2(0.0, -t * 0.7)),\n                   fbm(p * 3.2 + vec2(5.2, -t * 0.7 + 1.3))) - 0.5;\n    q += hz * 0.012 * (1.0 + uScrollVel * 1.4 + near * 1.6);\n  }\n\n  /* 3. Burning sun */\n  vec2 rel = q - centre;\n  float dist = length(rel);\n  float ang = atan(rel.x, rel.y);              // 0 at the top, ±PI at the bottom\n  float h = dist - uRadius;                    // > 0 outside the disc\n  h -= 0.05 * exp(-md2 * 6.0) * uMouseOn;      // rim is pulled toward the pointer\n\n  // The angle jumps from +PI to -PI at the bottom; blend both sides of that seam\n  // and restore the noise contrast the average would flatten.\n  float s = ang * uRadius;\n  float s2 = s - sign(ang) * 2.0 * PI * uRadius;\n  float seam = 0.5 * smoothstep(PI - 0.45, PI, abs(ang));\n  float keep = inversesqrt((1.0 - seam) * (1.0 - seam) + seam * seam);\n\n  if (fire) {\n    float jag = rimJag(s, t);\n    if (seam > 0.0) jag = mix(jag, rimJag(s2, t), seam) * keep;\n    h += jag;\n  }\n\n  // Flames lean toward the pointer and with its motion, along the rim; higher parts bend more\n  vec2 tng = vec2(cos(ang), -sin(ang));\n  float lean = clamp(dot(uMouse - p0, tng) * 2.2 * near + dot(uMouseVel, tng) * 0.45 * exp(-md2 * 3.0) * uMouseOn, -1.4, 1.4);\n  vec3 ff = vec3(0.0);\n  if (h > -0.1 && h < flameH * 1.18) {\n    ff = flameField(s, h, lean, fl);\n    if (seam > 0.0) {\n      vec3 ff2 = flameField(s2, h, lean, fl);\n      ff = vec3(0.5 + (mix(ff.x, ff2.x, seam) - 0.5) * keep, mix(ff.yz, ff2.yz, seam));\n    }\n  }\n  float n = ff.x;\n  vec2 warp = ff.yz;\n\n  float heat = 0.0;\n  if (h > 0.0) {\n    // Thresholded noise gives separate tongues instead of a uniform haze\n    float tongue = n * 1.15 - h / flameH * 0.85 - 0.12;\n    heat = smoothstep(0.0, 0.75, tongue) * 1.05;\n    heat += exp(-h * 38.0) * 0.3;                 // hot base hugging the rim\n  } else {\n    float lava = 0.0;\n    if (h > -0.1) {\n      lava = lavaField(s, h, warp, t);\n      if (seam > 0.0) lava = mix(lava, lavaField(s2, h, warp, t), seam);\n    }\n    heat = exp(h * 48.0) * 0.8 + exp(h * 7.0) * lava * 0.18;\n  }\n  heat += exp(-abs(h) * 260.0) * 0.6;              // white-hot rim line\n  heat += exp(-md2 * 26.0) * exp(-abs(h) * 9.0) * 0.45 * uMouseOn;   // rim flares under the pointer\n  heat *= 0.9;\n\n  vec3 col = uBg;\n  col += fireRamp(heat);\n\n  // Soft atmospheric bloom around the sun\n  if (h > 0.0) col += vec3(1.0, 0.3, 0.05) * 0.16 * exp(-h * 4.5);\n  // Warm torchlight around the pointer\n  col += vec3(1.0, 0.36, 0.07) * (core * 0.05 + near * 0.025);\n  // Disc interior: cracked crust with a faint ember gradient under the rim\n  if (h < -0.01) col = mix(col, crackedCrust(rel / uRadius, t, fl, md2) + vec3(0.3, 0.07, 0.0) * exp(h * 6.0), smoothstep(-0.01, -0.1, h));\n\n  /* 4. Embers drifting up from the rim */\n  for (int k = 0; k < 2; k++) {\n    float fk = float(k);\n    float sc = 13.0 + fk * 10.0;\n    // embers are pushed away from the pointer and rise faster while the wheel spins\n    vec2 pe = p - dm / (sqrt(md2) + 0.05) * near * 0.04;\n    vec2 sp = pe * sc + vec2(fk * 3.1, -fl * (1.2 + fk * 0.7));\n    vec2 id = floor(sp);\n    vec2 gv = fract(sp) - 0.5;\n    float rnd = hash(id + fk * 13.0);\n    vec2 off = (vec2(hash(id + 1.3), hash(id + 7.1)) - 0.5) * 0.6\n             + vec2(sin(t * 1.7 + rnd * 6.28) * 0.18, 0.0);\n    float sp2 = smoothstep(0.07 - fk * 0.02, 0.0, length(gv - off)) * step(1.0 - 0.13 * uEmbers, rnd);\n    sp2 *= 0.55 + 0.45 * sin(t * 7.0 + rnd * 40.0);\n    float mask = smoothstep(0.5 * uFlames, 0.02, h) * step(0.0, h);\n    col += vec3(1.0, 0.55, 0.18) * sp2 * mask * 1.3;\n  }\n\n  // Ripple rings catch the firelight near the rim\n  col += vec3(1.0, 0.45, 0.12) * rippleLight * 0.12 * exp(-abs(h) * 6.0);\n\n  col += (hash(gl_FragCoord.xy + fract(t) * 100.0) - 0.5) * 0.016;   // film grain\n  col = col / (1.0 + col * 0.1);\n  gl_FragColor = vec4(col, 1.0);\n}`;\n\nconst UNIFORMS = ['uRes', 'uArc', 'uUnit', 'uRadius', 'uTime', 'uFlow', 'uClock', 'uMouse', 'uMouseOn', 'uMouseVel',\n  'uPR', 'uScrollVel', 'uSpot', 'uLeft', 'uSpotN', 'uBg', 'uCore', 'uFlames', 'uEmbers', 'uRipples'];\n\nfunction hexToRgb(hex) {\n  const n = parseInt(String(hex).slice(1, 7), 16) || 0;\n  return [(n >> 16 & 255) / 255, (n >> 8 & 255) / 255, (n & 255) / 255];\n}\n\nconst clamp = (v, a, b) => Math.min(b, Math.max(a, v));\nconst ease = (cur, target, dt, rate) => cur + (target - cur) * (1 - Math.exp(-dt * rate));\n\n/**\n * Mounts the sun into `root` (the element holding `.esn-stage` and\n * `.esn-status`). Returns an idempotent disposer with update(config); updates\n * keep the GPU context.\n */\nexport function buildEmberSun(root, config) {\n  let disposed = false;\n  let values = { ...DEFAULT_EMBER_SUN_CONFIG, ...config };\n  const stage = root.querySelector('.esn-stage');\n  const status = root.querySelector('.esn-status');\n  root.removeAttribute('data-ready');\n  root.removeAttribute('data-fallback');\n  if (status) status.textContent = '';\n\n  const canvas = document.createElement('canvas');\n  // Inline styles survive Svelte scoping.\n  Object.assign(canvas.style, { position: 'absolute', inset: '0', width: '100%', height: '100%', display: 'block' });\n  canvas.setAttribute('role', 'img');\n  canvas.setAttribute('aria-label', 'A burning sun with a cracked, glowing crust.');\n  stage?.append(canvas);\n\n  let gl = null;\n  try {\n    gl = stage ? canvas.getContext('webgl', { antialias: false, alpha: false, premultipliedAlpha: false, powerPreference: 'high-performance' }) : null;\n  } catch {\n    gl = null;\n  }\n\n  let ok = false, parallel = null, calm = null, full = null, current = null;\n  const fail = () => {\n    ok = false;\n    canvas.style.display = 'none';\n    root.removeAttribute('data-ready');\n    root.setAttribute('data-fallback', '');\n    if (status) status.textContent = 'The sun needs WebGL. Enable hardware acceleration and reload to see it.';\n  };\n\n  // Both programs are queued before either is waited on; \"full\" finishes in the background where the\n  // browser compiles in parallel.\n  const program = (plates) => {\n    const sh = (type, src) => { const s = gl.createShader(type); gl.shaderSource(s, src); gl.compileShader(s); return s; };\n    const vs = sh(gl.VERTEX_SHADER, VERT);\n    const fs = sh(gl.FRAGMENT_SHADER, '#define PLATES ' + plates + '\\n' + FRAG);\n    const prog = gl.createProgram();\n    gl.attachShader(prog, vs); gl.attachShader(prog, fs);\n    gl.bindAttribLocation(prog, 0, 'a');\n    gl.linkProgram(prog);\n    return { prog, fs, ready: false, failed: false, u: null };\n  };\n  // true once P is linked; never blocks while a parallel compile is still running unless asked to wait\n  const linked = (P, wait) => {\n    if (P.ready || P.failed) return P.ready;\n    if (!wait && parallel && !gl.getProgramParameter(P.prog, parallel.COMPLETION_STATUS_KHR)) return false;\n    if (!gl.getProgramParameter(P.prog, gl.LINK_STATUS)) {\n      console.warn(gl.getShaderInfoLog(P.fs) || gl.getProgramInfoLog(P.prog));\n      P.failed = true;\n      return false;\n    }\n    P.u = Object.fromEntries(UNIFORMS.map((n) => [n, gl.getUniformLocation(P.prog, n)]));\n    return (P.ready = true);\n  };\n  const init = () => {\n    current = null;\n    parallel = gl.getExtension('KHR_parallel_shader_compile');\n    calm = program(0);\n    full = program(1);\n    if (!linked(calm, true)) { fail(); return; }\n    gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());\n    gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW);\n    gl.enableVertexAttribArray(0);\n    gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);\n    ok = true;\n    canvas.style.display = 'block';\n    root.removeAttribute('data-fallback');\n    if (status) status.textContent = '';\n  };\n  if (gl) init(); else fail();\n\n  const reducedMotion = matchMedia('(prefers-reduced-motion: reduce)');\n  const listen = { passive: true };\n\n  /* Render resolution, in canvas px per css px. It starts at 1, climbs toward the screen's density (at most\n     1.5) while frames keep up, and steps down when they fall behind. A frame cap (a battery saver holding\n     the page at 30 fps) is told apart from real load because a smaller canvas does not speed it up, and\n     then the resolution is put back instead of blurring the fire for nothing. */\n  const MAX_SCALE = Math.min(window.devicePixelRatio || 1, 1.5), MIN_SCALE = 0.5;\n  let scale = Math.min(1, MAX_SCALE);\n  const pace = { avg: 16.7, n: 0, slow: 0, fast: 0, ceiling: MAX_SCALE, ceilingUntil: 0, probe: null, capUntil: 0, capWait: 30000 };\n  const tune = (ms, now) => {                          // true when the canvas has to be resized\n    if (++pace.n < 30) return false;                   // the first frames include shader compiles\n    pace.avg += (Math.min(ms, 100) - pace.avg) * 0.08;\n    if (pace.probe) {                                  // just stepped down: wait, then check it helped\n      if (pace.n - pace.probe.n < 45) return false;\n      const { scale: before, avg } = pace.probe;\n      pace.probe = null;\n      if (pace.avg > avg * 0.88) {                     // no faster: a frame cap, not load. Retry later, less often\n        scale = before; pace.capUntil = now + pace.capWait; pace.capWait = Math.min(pace.capWait * 2, 300000);\n        return true;\n      }\n    }\n    if (pace.avg > 25 && now > pace.capUntil) {        // under ~40 fps\n      pace.fast = 0;\n      if (++pace.slow > 20 && scale > MIN_SCALE) {\n        pace.probe = { scale, avg: pace.avg, n: pace.n };\n        pace.ceiling = scale; pace.ceilingUntil = now + 20000;\n        scale = Math.max(MIN_SCALE, scale * 0.85); pace.slow = 0;\n        return true;\n      }\n      return false;\n    }\n    pace.slow = Math.max(0, pace.slow - 1);\n    if (pace.avg < 18.5) {                             // keeping up with a 60 Hz screen, or faster\n      const up = Math.min(MAX_SCALE, scale * 1.1);\n      if (++pace.fast > 90 && up > scale + 0.01 && (now > pace.ceilingUntil || up < pace.ceiling)) {\n        scale = up; pace.fast = 0; return true;\n      }\n    } else pace.fast = 0;\n    return false;\n  };\n\n  // Sun geometry in css px: the radius is `size` of the stage's short side and the centre sits mid-stage.\n  const geo = { w: 1, h: 1, cx: 0, topYCss: 0, unitCss: 500, arcY: 0 };\n  const layout = () => {\n    const w = Math.max(1, root.clientWidth), h = Math.max(1, root.clientHeight);\n    canvas.width = Math.max(1, Math.round(w * scale));\n    canvas.height = Math.max(1, Math.round(h * scale));\n    const radiusCss = Math.min(w, h) * values.size;\n    const topYCss = h / 2 - radiusCss;\n    Object.assign(geo, { w, h, cx: w / 2, topYCss, unitCss: radiusCss / R_UNITS, arcY: (h - topYCss) * scale });\n  };\n\n  let colors = { bg: [0, 0, 0], core: [0, 0, 1] };\n  const paint = () => {\n    // The shader tone-maps col / (1 + 0.1 col); feed the background through the inverse so the stage\n    // shows exactly the chosen colour and matches the panel around it.\n    colors = { bg: hexToRgb(values.background).map((c) => c / (1 - 0.1 * c)), core: hexToRgb(values.core) };\n  };\n\n  let raf = 0, last = 0, visible = true;\n  let simTime = 8, flow = 8, clock = 0, demoClock = 0;\n\n  /* ---- Pointer: target in sun units, smoothed in the loop so the fire follows with fluid lag ---- */\n  const ptr = { tx: 0, ty: 0, x: 0, y: 0, on: 0, onT: 0, vx: 0, vy: 0, lastMove: -1e9, ex: 1e9, ey: 1e9, et: -1e9, ri: 0, over: false };\n  const ripples = new Float32Array(12).fill(-100);\n  let lastRipple = -1e9, push = 0;\n  const scr = { v: 0 };\n  const live = () => ok && visible && !document.hidden && !reducedMotion.matches;\n  // Editor and gallery stages start without a cursor, so a stand-in one circles the sun until a real\n  // pointer arrives; the marker on the root retires it for good.\n  const demoing = () => (values.pointerless || values.autoDemo) && values.interactive && root.dataset.hxPointer !== 'real' && !reducedMotion.matches;\n\n  const aim = (ux, uy, tap) => {\n    ptr.tx = ux; ptr.ty = uy; ptr.onT = 1; ptr.lastMove = performance.now();\n    ptr.over = Math.hypot(ux, uy + R_UNITS) < R_UNITS;            // over the ball: the plates under it lift off\n    if (ptr.on < 0.05) { ptr.x = ux; ptr.y = uy; }             // no swoop in from the last position\n    const moved = Math.hypot(ux - ptr.ex, uy - ptr.ey);\n    if (tap || (moved > 0.07 && clock - ptr.et > 0.14)) {\n      ripples.set([ux, uy, clock], (ptr.ri++ % 4) * 3);\n      ptr.ex = ux; ptr.ey = uy; ptr.et = clock; lastRipple = clock;\n    }\n  };\n  const release = () => { ptr.onT = 0; ptr.over = false; };\n  const toUnits = (e) => {\n    const r = root.getBoundingClientRect();\n    const x = (e.clientX - r.left) * geo.w / (r.width || 1), y = (e.clientY - r.top) * geo.h / (r.height || 1);\n    return [(x - geo.cx) / geo.unitCss, (geo.topYCss - y) / geo.unitCss];\n  };\n  const onPointer = (e, tap) => {\n    if (e.isTrusted) root.dataset.hxPointer = 'real';\n    if (!values.interactive || !live()) return;\n    const [ux, uy] = toUnits(e);\n    aim(ux, uy, tap);\n    wake();\n  };\n  const onMove = (e) => onPointer(e, false);\n  const onDown = (e) => onPointer(e, true);\n  const onUp = (e) => { if (e.pointerType !== 'mouse') ptr.over = false; };\n  const onLeave = () => { release(); wake(); };\n  const onWheel = (e) => {\n    if (!values.interactive || !live()) return;\n    push += Math.abs(e.deltaY) * (e.deltaMode === 1 ? 16 : e.deltaMode === 2 ? window.innerHeight : 1);\n    wake();\n  };\n\n  /* ---- Hovered spots of the crust. Each is pinned to the turning sphere so it stays on the same plates. ---- */\n  const SPOTS = 8, LIFE = 1.0;                        // a spot is dropped LIFE s after the pointer left\n  const spots = [];                                   // { x, y, z, born, rel }: rel = when the pointer left (-1 still over)\n  const spotBuf = new Float32Array(SPOTS * 4).fill(-1), leftBuf = new Float32Array(SPOTS).fill(1e4);\n  let spotN = 0;\n  const updateSpots = () => {\n    let hov = null;\n    const sx = ptr.tx / R_UNITS, sy = (ptr.ty + R_UNITS) / R_UNITS;\n    if (ptr.over && sx * sx + sy * sy < 0.95) {\n      // same turns as crustSpace() in the shader\n      const tiltX = clamp(ptr.x / R_UNITS, -1.6, 1.6) * 0.32 * ptr.on;\n      const tiltY = clamp((ptr.y + R_UNITS) / R_UNITS, -1.6, 1.6) * 0.32 * ptr.on;\n      const ay = simTime * 0.05 - tiltX, ax = tiltY;\n      let x = sx, y = sy, z = Math.sqrt(1 - sx * sx - sy * sy);\n      [x, z] = [Math.cos(ay) * x - Math.sin(ay) * z, Math.sin(ay) * x + Math.cos(ay) * z];\n      [y, z] = [Math.cos(ax) * y - Math.sin(ax) * z, Math.sin(ax) * y + Math.cos(ax) * z];\n      hov = [x, y, z];\n    }\n    let near = null, nearD = 1e9;\n    for (const sp of spots) {\n      const d = hov ? Math.hypot(sp.x - hov[0], sp.y - hov[1], sp.z - hov[2]) : 1e9;\n      if (d < nearD) { nearD = d; near = sp; }\n      if (d > 0.24 && sp.rel < 0) sp.rel = clock;      // the pointer moved on: these plates settle back\n    }\n    if (hov) {\n      if (near && nearD < 0.2 && near.rel < 0) { /* still over it */ }\n      else if (near && nearD < 0.2 && clock - near.rel < 0.15) near.rel = -1;  // only a jitter: keep it floating\n      else {\n        spots.push({ x: hov[0], y: hov[1], z: hov[2], born: clock, rel: -1 });\n        if (spots.length > SPOTS) {\n          const i = spots.findIndex((sp) => sp.rel >= 0);\n          spots.splice(i >= 0 ? i : 0, 1);\n        }\n      }\n    }\n    for (let i = spots.length - 1; i >= 0; i--) if (spots[i].rel >= 0 && clock - spots[i].rel > LIFE) spots.splice(i, 1);\n    // Only spots that hold a plate off the ball reach the shader (see plateLift).\n    spotBuf.fill(-1); leftBuf.fill(1e4); spotN = 0;\n    for (const sp of spots) {\n      const age = clock - sp.born, left = sp.rel >= 0 ? sp.rel - sp.born : 1e4;\n      if (Math.min(age, left) <= 0.05 || age - left >= 0.8) continue;\n      spotBuf.set([sp.x, sp.y, sp.z, age], spotN * 4);\n      leftBuf[spotN++] = left;\n    }\n  };\n\n  const step = (dt) => {\n    if (demoing()) {\n      // a slow figure of eight that crosses the ball and swings out past the rim\n      demoClock += dt;\n      const ph = demoClock * 0.55;\n      aim(R_UNITS * 1.1 * Math.sin(ph), -R_UNITS + R_UNITS * 0.5 * Math.sin(ph * 1.7 + 0.6), false);\n    }\n    if (performance.now() - ptr.lastMove > 2600) ptr.onT = 0;  // idle: hand control back to the autonomous fire\n    const px = ptr.x, py = ptr.y;\n    ptr.x = ease(ptr.x, ptr.tx, dt, 7); ptr.y = ease(ptr.y, ptr.ty, dt, 7);\n    ptr.on = ease(ptr.on, ptr.onT, dt, ptr.onT > ptr.on ? 5 : 1.6);\n    if (dt > 0) { ptr.vx = ease(ptr.vx, (ptr.x - px) / dt, dt, 6); ptr.vy = ease(ptr.vy, (ptr.y - py) / dt, dt, 6); }\n    const vel = dt > 0 ? Math.min(push / dt / (window.innerHeight || 800), 1.5) : 0;\n    push = 0;\n    scr.v = ease(scr.v, vel, dt, vel > scr.v ? 8 : 2.2);\n    if (values.animate) {\n      const sdt = dt * values.speed;\n      simTime += sdt;\n      flow += sdt * (1 + scr.v * 1.6 + Math.min(Math.hypot(ptr.vx, ptr.vy), 2) * 0.35 * ptr.on);\n    }\n    clock += dt;\n    updateSpots();\n  };\n\n  const draw = () => {\n    if (!ok || gl.isContextLost()) return false;\n    const P = spotN > 0 && linked(full) ? full : calm;\n    if (P !== current) { gl.useProgram(P.prog); current = P; }\n    const u = P.u;\n    gl.viewport(0, 0, canvas.width, canvas.height);\n    gl.uniform2f(u.uRes, canvas.width, canvas.height);\n    gl.uniform2f(u.uArc, canvas.width / 2, geo.arcY);\n    gl.uniform1f(u.uUnit, geo.unitCss * scale);\n    gl.uniform1f(u.uRadius, R_UNITS);\n    gl.uniform1f(u.uTime, simTime);\n    gl.uniform1f(u.uFlow, flow);\n    gl.uniform1f(u.uClock, clock);\n    gl.uniform2f(u.uMouse, ptr.x, ptr.y);\n    gl.uniform1f(u.uMouseOn, ptr.on);\n    gl.uniform2f(u.uMouseVel, ptr.vx, ptr.vy);\n    gl.uniform3fv(u.uPR, ripples);\n    gl.uniform1f(u.uScrollVel, scr.v);\n    gl.uniform4fv(u.uSpot, spotBuf);\n    gl.uniform1fv(u.uLeft, leftBuf);\n    gl.uniform1i(u.uSpotN, spotN);\n    gl.uniform3fv(u.uBg, colors.bg);\n    gl.uniform3fv(u.uCore, colors.core);\n    gl.uniform1f(u.uFlames, values.flames);\n    gl.uniform1f(u.uEmbers, values.embers);\n    gl.uniform1f(u.uRipples, values.ripples);\n    gl.drawArrays(gl.TRIANGLES, 0, 3);\n    root.setAttribute('data-ready', '');\n    return true;\n  };\n\n  // Keeps drawing while the fire plays, the pointer (real or stand-in) is active, or anything it set\n  // in motion is still settling; otherwise the last frame holds.\n  const busy = () => values.animate\n    || (values.interactive && (demoing() || ptr.onT > 0 || ptr.on > 0.002 || spots.length > 0 || scr.v > 0.002 || clock - lastRipple < 1.5));\n\n  function frame(now) {\n    raf = 0;\n    if (disposed || !ok) return;\n    const ms = last ? now - last : 1000 / 60;\n    const run = live();\n    step(run ? Math.min(ms / 1000, 0.05) : 0);\n    // resize before drawing: resizing clears the canvas\n    if (run && tune(ms, now)) layout();\n    draw();\n    // without parallel compiles, finish linking the full shader now rather than on the first hover\n    if (pace.n === 3 && !parallel) linked(full, true);\n    if (run && busy()) { last = now; raf = requestAnimationFrame(frame); }\n    else last = 0;\n  }\n  const wake = () => { if (!disposed && ok && !raf) raf = requestAnimationFrame(frame); };\n\n  const onLost = (e) => {\n    e.preventDefault();\n    if (raf) cancelAnimationFrame(raf);\n    raf = 0;\n    fail();\n  };\n  const onRestored = () => { if (disposed) return; init(); if (ok) { layout(); wake(); } };\n  canvas.addEventListener('webglcontextlost', onLost);\n  canvas.addEventListener('webglcontextrestored', onRestored);\n\n  root.addEventListener('pointermove', onMove, listen);\n  root.addEventListener('pointerdown', onDown, listen);\n  root.addEventListener('pointerup', onUp, listen);\n  root.addEventListener('pointercancel', onLeave, listen);\n  root.addEventListener('pointerleave', onLeave, listen);\n  root.addEventListener('wheel', onWheel, listen);\n  reducedMotion.addEventListener?.('change', wake);\n  document.addEventListener('visibilitychange', wake);\n  // Redraw at once on resize: resizing clears the canvas.\n  const resize = typeof ResizeObserver === 'function' ? new ResizeObserver(() => { layout(); draw(); wake(); }) : null;\n  resize?.observe(root);\n  // Off-screen suns stop drawing.\n  const seen = typeof IntersectionObserver === 'function'\n    ? new IntersectionObserver((entries) => { visible = entries.some((e) => e.isIntersecting); wake(); })\n    : null;\n  seen?.observe(root);\n\n  paint(); layout(); wake();\n\n  const cleanup = () => {\n    if (disposed) return;\n    disposed = true;\n    if (raf) cancelAnimationFrame(raf);\n    raf = 0;\n    canvas.removeEventListener('webglcontextlost', onLost);\n    canvas.removeEventListener('webglcontextrestored', onRestored);\n    root.removeEventListener('pointermove', onMove);\n    root.removeEventListener('pointerdown', onDown);\n    root.removeEventListener('pointerup', onUp);\n    root.removeEventListener('pointercancel', onLeave);\n    root.removeEventListener('pointerleave', onLeave);\n    root.removeEventListener('wheel', onWheel);\n    reducedMotion.removeEventListener?.('change', wake);\n    document.removeEventListener('visibilitychange', wake);\n    resize?.disconnect();\n    seen?.disconnect();\n    gl?.getExtension('WEBGL_lose_context')?.loseContext();\n    canvas.remove();\n    root.removeAttribute('data-ready');\n    root.removeAttribute('data-fallback');\n    if (status) status.textContent = '';\n  };\n  cleanup.update = (next) => {\n    if (disposed) return;\n    const size = values.size;\n    values = { ...values, ...next };\n    if (!values.interactive) release();\n    paint();\n    if (values.size !== size) layout();\n    wake();\n  };\n  return cleanup;\n}\n",
      "type": "registry:component"
    },
    {
      "path": "registry/drops/ember-sun/ember-sun.engine.d.ts",
      "content": "// Types for ember-sun.engine.js (the engine itself is plain JavaScript).\nexport interface EmberSunConfig {\n  viewportWidth: number;\n  viewportHeight: number;\n  size: number;\n  background: string;\n  core: string;\n  flames: number;\n  embers: number;\n  ripples: number;\n  speed: number;\n  animate: boolean;\n  interactive: boolean;\n}\n\nexport interface EmberSunHandle {\n  (): void;\n  update(next: Partial<EmberSunConfig>): void;\n}\n\nexport const DEFAULT_EMBER_SUN_CONFIG: EmberSunConfig;\nexport function buildEmberSun(root: HTMLElement, config: Partial<EmberSunConfig>): EmberSunHandle;\n",
      "type": "registry:component"
    }
  ],
  "meta": {
    "license": "HorizonX Drops License 1.0",
    "page": "https://horizonx.so/tools/ember-sun",
    "source": "https://horizonx.so"
  },
  "docs": "Ember Sun fills its parent, so give the parent a width and height. The full editor, presets and exports are at https://horizonx.so/tools/ember-sun",
  "categories": [
    "webgl",
    "orb"
  ],
  "type": "registry:component"
}