{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "gsh",
  "title": "Gradient Ground",
  "description": "Animated gradient grounds for Remotion: the free gradients.sh engine (WebGL2) with 39 presets, driven by the current frame.",
  "dependencies": ["remotion"],
  "files": [
    {
      "path": "registry/remocn/gsh/gradient-engine/backend.ts",
      "content": "/**\n * The seam between live gradients (mount.ts, scheduler.ts) and the GPU API\n * that draws them. A backend hands out leases: a renderer drawing into an\n * offscreen canvas that the mount copies onto its own 2D canvas. Because the\n * visible canvas only ever holds a 2D context, switching backends (or losing\n * one mid-session) never touches the DOM, and the last frame stays on screen.\n *\n * Two backends: WebGPU (webgpu.ts), chosen per kind when the page passed\n * its adapter checks and the kind has a WGSL twin that compiled, and WebGL2\n * (pool.ts) for everything else. A WebGPU kind still compiling, or a page\n * still probing, gets no lease yet; the scheduler retries when WebGPU\n * reports a change.\n *\n * Exports do not go through a backend; they use export.ts (WebGL) directly.\n */\nimport { acquireContext, releaseContext, webglUnsupported } from \"./pool\";\nimport type { AnyCanvas, ColorResolver } from \"./renderer\";\nimport type {\n  FrameInput,\n  GradientKind,\n  GradientParams,\n  RenderTarget,\n} from \"./types\";\nimport {\n  acquireSurface,\n  releaseSurface,\n  webgpuStatus,\n  webgpuUnsupported,\n} from \"./webgpu\";\n\nexport type BackendName = \"webgl2\" | \"webgpu\";\n\n/** One leased renderer. Stays with its backend between leases, so `loaded` survives. */\nexport interface BackendLease {\n  /** Where frames land; the mount copies from it with drawImage. */\n  readonly canvas: AnyCanvas;\n  /** First row of the frame in `canvas` (a WebGPU lease may draw a spare row above it). */\n  readonly sourceY: number;\n  /** Colour resolver used by the renderer; set by the current leaseholder. */\n  resolver: ColorResolver;\n  /** Which params (owner and version) the renderer was last loaded with. */\n  loaded: { owner: object; version: number } | null;\n  setParams(params: GradientParams): void;\n  renderFrame(frame: FrameInput, target: RenderTarget): void;\n  /** True once the GPU resources are gone; the canvas then holds no new frame. */\n  isLost(): boolean;\n}\n\nexport interface GradientBackend {\n  readonly name: BackendName;\n  /** Whether this backend can draw the kind right now; mounts check it before acquiring. */\n  supports(kind: GradientKind): boolean;\n  /**\n   * Leases a renderer, or null when the budget is used up or the backend\n   * cannot run. `onLost` runs if the lease is lost; it has ended by then.\n   * `pixels` is the size the lease will render at, for memory caps.\n   */\n  acquire(onLost?: (() => void) | null, pixels?: number): BackendLease | null;\n  release(lease: BackendLease): void;\n  /** True once this backend has failed for good on this page. */\n  unsupported(): boolean;\n}\n\nexport const webglBackend: GradientBackend = {\n  acquire: (onLost = null) => acquireContext(onLost),\n  name: \"webgl2\",\n  // Only ever handed its own pooled contexts back.\n  release: releaseContext,\n  supports: () => true,\n  unsupported: webglUnsupported,\n};\n\nexport const webgpuBackend: GradientBackend = {\n  acquire: (onLost = null, pixels = 0) => acquireSurface(onLost, pixels),\n  name: \"webgpu\",\n  release: releaseSurface,\n  // Ready to draw now: probed, and the kind's pipeline compiled.\n  supports: (kind) => webgpuStatus(kind) === \"ready\",\n  unsupported: webgpuUnsupported,\n};\n\n/**\n * The backend that draws `kind` on this page: WebGPU unless the\n * preference, the adapter, the probes, the kind (no WGSL, or it failed to\n * compile) or a device loss rule it out.\n */\nexport function backendFor(kind: GradientKind): GradientBackend {\n  return webgpuStatus(kind) === \"unavailable\" ? webglBackend : webgpuBackend;\n}\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/backend.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/color.ts",
      "content": "export type Rgb = readonly [number, number, number];\nexport type Oklab = readonly [number, number, number];\n\nconst FALLBACK_RGB: Rgb = [0.5, 0.5, 0.5];\n\nfunction srgbToLinear(c: number): number {\n  return c <= 0.040_45 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;\n}\n\nfunction linearToSrgb(c: number): number {\n  return c <= 0.003_130_8 ? 12.92 * c : 1.055 * c ** (1 / 2.4) - 0.055;\n}\n\n/** sRGB (0-1, gamma encoded) to OKLab. */\nexport function srgbToOklab(rgb: Rgb): Oklab {\n  const r = srgbToLinear(rgb[0]);\n  const g = srgbToLinear(rgb[1]);\n  const b = srgbToLinear(rgb[2]);\n  const l = Math.cbrt(\n    0.412_221_470_8 * r + 0.536_332_536_3 * g + 0.051_445_992_9 * b,\n  );\n  const m = Math.cbrt(\n    0.211_903_498_2 * r + 0.680_699_545_1 * g + 0.107_396_956_6 * b,\n  );\n  const s = Math.cbrt(\n    0.088_302_461_9 * r + 0.281_718_837_6 * g + 0.629_978_700_5 * b,\n  );\n  return [\n    0.210_454_255_3 * l + 0.793_617_785 * m - 0.004_072_046_8 * s,\n    1.977_998_495_1 * l - 2.428_592_205 * m + 0.450_593_709_9 * s,\n    0.025_904_037_1 * l + 0.782_771_766_2 * m - 0.808_675_766 * s,\n  ];\n}\n\n/** OKLab to sRGB (0-1, gamma encoded, clamped). */\nexport function oklabToSrgb(lab: Oklab): Rgb {\n  const l = (lab[0] + 0.396_337_777_4 * lab[1] + 0.215_803_757_3 * lab[2]) ** 3;\n  const m = (lab[0] - 0.105_561_345_8 * lab[1] - 0.063_854_172_8 * lab[2]) ** 3;\n  const s = (lab[0] - 0.089_484_177_5 * lab[1] - 1.291_485_548 * lab[2]) ** 3;\n  const out = [\n    4.076_741_662_1 * l - 3.307_711_591_3 * m + 0.230_969_929_2 * s,\n    -1.268_438_004_6 * l + 2.609_757_401_1 * m - 0.341_319_396_5 * s,\n    -0.004_196_086_3 * l - 0.703_418_614_7 * m + 1.707_614_701 * s,\n  ].map((c) => Math.min(1, Math.max(0, linearToSrgb(c))));\n  return [out[0] ?? 0, out[1] ?? 0, out[2] ?? 0];\n}\n\nconst HEX_RE = /^#([0-9a-f]{3,8})$/i;\nconst RGB_RE = /^rgba?\\(\\s*([^)]+)\\)$/i;\n\nfunction parseChannel(token: string): number | null {\n  const value = Number.parseFloat(token);\n  if (Number.isNaN(value)) {\n    return null;\n  }\n  return token.endsWith(\"%\") ? value / 100 : value / 255;\n}\n\n/** Parses hex and rgb() colours without a DOM. Returns null for anything else. */\nexport function parseColorLiteral(value: string): Rgb | null {\n  const input = value.trim();\n  const hex = HEX_RE.exec(input)?.[1];\n  if (hex) {\n    const full = hex.length <= 4 ? [...hex].map((ch) => ch + ch).join(\"\") : hex;\n    if (full.length !== 6 && full.length !== 8) {\n      return null;\n    }\n    return [\n      Number.parseInt(full.slice(0, 2), 16) / 255,\n      Number.parseInt(full.slice(2, 4), 16) / 255,\n      Number.parseInt(full.slice(4, 6), 16) / 255,\n    ];\n  }\n  const body = RGB_RE.exec(input)?.[1];\n  if (body) {\n    const parts = body\n      .split(/[\\s,/]+/)\n      .filter(Boolean)\n      .slice(0, 3);\n    const channels = parts.map(parseChannel);\n    const [r, g, b] = channels;\n    if (channels.length === 3 && r != null && g != null && b != null) {\n      return [r, g, b];\n    }\n  }\n  return null;\n}\n\ntype Probe = CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D;\nlet probe: Probe | null | undefined;\n\nfunction getProbe(): Probe | null {\n  if (probe !== undefined) {\n    return probe;\n  }\n  probe = null;\n  // OffscreenCanvas first: it works in Workers and never touches document.\n  if (typeof OffscreenCanvas !== \"undefined\") {\n    probe = new OffscreenCanvas(1, 1).getContext(\"2d\", {\n      willReadFrequently: true,\n    });\n  } else if (typeof document !== \"undefined\") {\n    const canvas = document.createElement(\"canvas\");\n    canvas.width = 1;\n    canvas.height = 1;\n    probe = canvas.getContext(\"2d\", { willReadFrequently: true });\n  }\n  return probe;\n}\n\n/** Lets the browser parse any CSS colour (oklch, hsl, names...) by painting one pixel. */\nfunction probeColor(value: string): Rgb | null {\n  const ctx = getProbe();\n  if (!ctx) {\n    return null;\n  }\n  const sentinel = \"#010203\";\n  ctx.fillStyle = sentinel;\n  ctx.fillStyle = value;\n  if (ctx.fillStyle === sentinel && value.trim().toLowerCase() !== sentinel) {\n    return null;\n  }\n  ctx.clearRect(0, 0, 1, 1);\n  ctx.fillRect(0, 0, 1, 1);\n  const [r = 0, g = 0, b = 0] = ctx.getImageData(0, 0, 1, 1).data;\n  return [r / 255, g / 255, b / 255];\n}\n\nconst VAR_RE = /^var\\(\\s*(--[\\w-]+)\\s*(?:,\\s*([\\s\\S]+))?\\)$/;\n\n/** Expands var(--x) (with fallbacks, nested) against an element's computed style. */\nexport function resolveCssVariables(\n  value: string,\n  scope: Element | null,\n  depth = 0,\n): string {\n  const match = VAR_RE.exec(value.trim());\n  if (!match || depth > 8) {\n    return value.trim();\n  }\n  const [, name = \"\", fallback] = match;\n  const resolved =\n    scope && typeof getComputedStyle !== \"undefined\"\n      ? getComputedStyle(scope).getPropertyValue(name).trim()\n      : \"\";\n  if (resolved) {\n    return resolveCssVariables(resolved, scope, depth + 1);\n  }\n  return fallback ? resolveCssVariables(fallback, scope, depth + 1) : \"\";\n}\n\nconst literalCache = new Map<string, Rgb>();\n\n/** Resolves any CSS colour, including var(--x), to sRGB. Unknown colours become mid grey. */\nexport function resolveColor(value: string, scope: Element | null): Rgb {\n  const literal = resolveCssVariables(value, scope);\n  const cached = literalCache.get(literal);\n  if (cached) {\n    return cached;\n  }\n  const rgb = parseColorLiteral(literal) ?? probeColor(literal) ?? FALLBACK_RGB;\n  if (literalCache.size > 256) {\n    literalCache.clear();\n  }\n  literalCache.set(literal, rgb);\n  return rgb;\n}\n\nexport function hasCssVariable(values: readonly string[]): boolean {\n  return values.some((value) => value.includes(\"var(\"));\n}\n\nfunction toHex(rgb: Rgb): string {\n  return `#${rgb\n    .map((channel) =>\n      Math.round(Math.min(1, Math.max(0, channel)) * 255)\n        .toString(16)\n        .padStart(2, \"0\"),\n    )\n    .join(\"\")}`;\n}\n\n/** Resolves any CSS colour (var(), oklch, names...) to a concrete #rrggbb. */\nexport function resolveColorToHex(\n  value: string,\n  scope: Element | null,\n): string {\n  return toHex(resolveColor(value, scope));\n}\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/color.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/export.ts",
      "content": "import {\n  hasCssVariable,\n  resolveColor,\n  resolveColorToHex,\n  srgbToOklab,\n} from \"./color\";\nimport { normalizeParams } from \"./params\";\nimport type { AnyCanvas, ColorResolver } from \"./renderer\";\nimport { createWebGLRenderer, getWebGL2 } from \"./renderer\";\nimport type { GradientParams, GradientRenderer } from \"./types\";\n\n/** What the GPU allows for one export tile. Every tile edge must be at most `maxTileSize`. */\nexport interface ExportLimits {\n  /** Largest square tile this renderer can draw: the smallest of the limits below (and the requested size). */\n  maxTileSize: number;\n  maxTextureSize: number;\n  maxRenderbufferSize: number;\n  maxViewportDims: readonly [number, number];\n}\n\nexport interface ExportRenderer extends GradientRenderer {\n  readonly limits: ExportLimits;\n}\n\nfunction queryLimits(\n  gl: WebGL2RenderingContext,\n): Omit<ExportLimits, \"maxTileSize\"> {\n  const viewport: unknown = gl.getParameter(gl.MAX_VIEWPORT_DIMS);\n  const dims =\n    viewport instanceof Int32Array && viewport.length >= 2\n      ? ([viewport[0] ?? 0, viewport[1] ?? 0] as const)\n      : ([0, 0] as const);\n  return {\n    maxRenderbufferSize: Number(gl.getParameter(gl.MAX_RENDERBUFFER_SIZE)) || 0,\n    maxTextureSize: Number(gl.getParameter(gl.MAX_TEXTURE_SIZE)) || 0,\n    maxViewportDims: dims,\n  };\n}\n\nfunction tileLimit(\n  limits: Omit<ExportLimits, \"maxTileSize\">,\n  requested: number,\n): number {\n  return Math.max(\n    1,\n    Math.min(\n      Math.floor(requested),\n      limits.maxTextureSize,\n      limits.maxRenderbufferSize,\n      limits.maxViewportDims[0],\n      limits.maxViewportDims[1],\n    ),\n  );\n}\n\nfunction createExportCanvas(): AnyCanvas {\n  // Start at 1x1: a huge requested size can fail before limits are known.\n  if (typeof OffscreenCanvas !== \"undefined\") {\n    return new OffscreenCanvas(1, 1);\n  }\n  if (typeof document !== \"undefined\") {\n    return document.createElement(\"canvas\");\n  }\n  throw new Error(\"Export needs OffscreenCanvas or a document\");\n}\n\nlet cachedLimits: Omit<ExportLimits, \"maxTileSize\"> | null = null;\n\n/**\n * The GPU's export limits, so an export UI can offer only tile and image\n * sizes that will work. Probes once with a throwaway context, then caches.\n * Pass the tile size you want; `maxTileSize` comes back clamped.\n */\nexport function getExportLimits(requestedTileSize = 2048): ExportLimits {\n  if (!cachedLimits) {\n    const canvas = createExportCanvas();\n    const gl = getWebGL2(canvas, { preserveDrawingBuffer: false });\n    if (!gl) {\n      throw new Error(\"WebGL2 is not available for export\");\n    }\n    cachedLimits = queryLimits(gl);\n    gl.getExtension(\"WEBGL_lose_context\")?.loseContext();\n  }\n  return {\n    ...cachedLimits,\n    maxTileSize: tileLimit(cachedLimits, requestedTileSize),\n  };\n}\n\n/**\n * Returns params whose colours are concrete #rrggbb values. Run it on the\n * main thread before handing params to a Worker: var(--x) needs\n * getComputedStyle, which Workers don't have. `element` scopes the\n * variables (default <html>).\n */\nexport function resolveParamsColors(\n  params: GradientParams,\n  element?: Element,\n): GradientParams {\n  const scope =\n    element ??\n    (typeof document === \"undefined\" ? null : document.documentElement);\n  if (!scope && hasCssVariable([...params.colors, params.background])) {\n    throw new Error(\n      \"resolveParamsColors: var() colours need a document; call it on the main thread\",\n    );\n  }\n  return {\n    ...params,\n    background: resolveColorToHex(params.background, scope),\n    colors: params.colors.map((color) => resolveColorToHex(color, scope)),\n  };\n}\n\n/**\n * Concrete colours never touch document or getComputedStyle. var() colours\n * are resolved against <html> when a document exists, and are an error in a\n * Worker.\n */\nconst exportColorResolver: ColorResolver = (value) => {\n  if (hasCssVariable([value])) {\n    if (typeof document === \"undefined\") {\n      throw new Error(\n        `createExportRenderer: unresolved colour \"${value}\" and no document. Call resolveParamsColors(params) on the main thread first.`,\n      );\n    }\n    return srgbToOklab(resolveColor(value, document.documentElement));\n  }\n  return srgbToOklab(resolveColor(value, null));\n};\n\n/**\n * Offscreen renderer for exports: preserveDrawingBuffer on, no listeners, no\n * DPR logic. Works in a Worker when params have concrete colours (see\n * resolveParamsColors). The tile size is clamped to the GPU's texture,\n * renderbuffer and viewport limits; read the result from `limits`.\n */\nexport function createExportRenderer(\n  params: GradientParams,\n  maxTileSize = 2048,\n): ExportRenderer {\n  // New pinned paths must complete an integer number of laps over the export\n  // loop. Legacy params omit drift and retain their exact historical frames.\n  const normalized = normalizeParams(params);\n  const exportParams =\n    normalized.drift === undefined\n      ? normalized\n      : { ...normalized, speed: Math.round(normalized.speed) };\n  const canvas = createExportCanvas();\n  const gl = getWebGL2(canvas, { preserveDrawingBuffer: true });\n  if (!gl) {\n    throw new Error(\"WebGL2 is not available for export\");\n  }\n  const queried = queryLimits(gl);\n  cachedLimits ??= queried;\n  const limits: ExportLimits = {\n    ...queried,\n    maxTileSize: tileLimit(queried, maxTileSize),\n  };\n  const size = limits.maxTileSize;\n  canvas.width = size;\n  canvas.height = size;\n  let renderer: ReturnType<typeof createWebGLRenderer>;\n  try {\n    renderer = createWebGLRenderer({\n      canvas,\n      gl,\n      params: exportParams,\n      resolveColor: exportColorResolver,\n    });\n  } catch (error) {\n    gl.getExtension(\"WEBGL_lose_context\")?.loseContext();\n    throw error;\n  }\n  const live = renderer;\n  return {\n    canvas,\n    destroy() {\n      live.destroy();\n      gl.getExtension(\"WEBGL_lose_context\")?.loseContext();\n    },\n    limits,\n    renderFrame(frame, target) {\n      if (target && (target.width > size || target.height > size)) {\n        throw new RangeError(\n          `Tile ${target.width}x${target.height} exceeds the export tile limit ${size} (GPU max texture ${limits.maxTextureSize}, renderbuffer ${limits.maxRenderbufferSize}, viewport ${limits.maxViewportDims.join(\"x\")})`,\n        );\n      }\n      live.renderFrame(\n        {\n          frameIndex: frame.frameIndex,\n          timeSeconds: frame.timeSeconds,\n          frameRate: frame.frameRate,\n        },\n        target,\n      );\n    },\n    setParams: (patch) => live.setParams(patch),\n  };\n}\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/export.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/fallback.ts",
      "content": "import { getKind } from \"./kinds\";\nimport type { GradientParams } from \"./types\";\n\nfunction grainLayer(amount: number): string {\n  const opacity = (0.06 + amount * 0.16).toFixed(3);\n  const svg = `<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 ${opacity}'/></filter><rect width='100%' height='100%' filter='url(#n)'/></svg>`;\n  return `url(\"data:image/svg+xml,${encodeURIComponent(svg)}\") 0 0 / 180px 180px repeat`;\n}\n\n/**\n * A CSS `background` value that resembles the gradient: layered radial and\n * linear gradients built from the same colours, so pages never show a blank\n * box. var(--x) colours are kept as-is and follow the theme natively.\n */\nexport function staticFallbackCss(p: GradientParams): string {\n  const layers = getKind(p.kind).fallbackLayers(p.colors, p.background);\n  if (p.grain >= 0.2) {\n    layers.unshift(grainLayer(p.grain));\n  }\n  return [...layers, p.background].join(\", \");\n}\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/fallback.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/index.ts",
      "content": "export type { ExportLimits, ExportRenderer } from \"./export\";\nexport {\n  createExportRenderer,\n  getExportLimits,\n  resolveParamsColors,\n} from \"./export\";\nexport { staticFallbackCss } from \"./fallback\";\nexport type { GradientKindDefinition } from \"./kind\";\nexport { getKind, kindDefaults, listKinds, registerKind } from \"./kinds\";\nexport {\n  LOOP_RADIUS,\n  loopPhase,\n  loopVector,\n  loopVectorAtPhase,\n  splitTiles,\n  videoFrameTimes,\n} from \"./loop\";\nexport type { MountedGradient, MountOptions } from \"./mount\";\nexport { mountGradient } from \"./mount\";\nexport {\n  defaultParams,\n  mergeParams,\n  normalizeParams,\n  parseParams,\n  serializeParams,\n} from \"./params\";\nexport {\n  contextStats,\n  MAX_LIVE_CONTEXTS,\n  PIXEL_BUDGET,\n  PRIMARY_PIXEL_BUDGET,\n  paceStats,\n  resetPace,\n  setPixelBudget,\n  takePaintStats,\n} from \"./scheduler\";\nexport type {\n  FrameInput,\n  GradientKind,\n  GradientParams,\n  GradientRenderer,\n  RenderTarget,\n} from \"./types\";\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/index.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/kind.ts",
      "content": "import type { GradientParams } from \"./types\";\n\n/**\n * One gradient kind. `glsl` defines `vec3 kindColor(vec2 p, vec2 uv)` and\n * returns OKLab. `p` is centred, y up, with the short side spanning -0.5..0.5;\n * `uv` is 0..1 from the top left. Use loopNoise/fbm/u_loop for motion, never\n * raw time, so the loop stays seamless.\n */\nexport interface GradientKindDefinition {\n  readonly name: string;\n  readonly label: string;\n  readonly description: string;\n  /** Hand-tuned params for this kind. */\n  readonly defaults: Omit<GradientParams, \"kind\">;\n  readonly glsl: string;\n  /**\n   * Optional WGSL twin of `glsl`: `fn kindColor(p: vec2f, uv: vec2f) -> vec3f`,\n   * same maths, against shaders/wgsl-common.ts. Kinds with it can render on\n   * WebGPU (and in Node); kinds without it always render with WebGL.\n   *\n   * A loader, not the source: keep the WGSL in its own module and return\n   * `import(\"./wgsl/<kind>\").then((module) => module.wgsl)`, so bundlers\n   * split it out and only pages that pick WebGPU download it.\n   */\n  readonly wgsl?: () => Promise<string>;\n  /**\n   * Set when `wgsl` uses fwidth/dpdx/dpdy. Screen-space derivatives come\n   * from 2x2 quads whose choice of row is driver-defined, so such a kind is\n   * near-exact against WebGL in the browser (checked with a tolerance in\n   * the engine lab tests) rather than bit-exact, and Node keeps rendering\n   * it through Chrome.\n   */\n  readonly wgslUsesDerivatives?: true;\n  /** CSS background layers (without the base colour) that resemble the kind. */\n  readonly fallbackLayers: (\n    colors: readonly string[],\n    background: string,\n  ) => string[];\n}\n\n/** Picks colour i, cycling when the palette is shorter. */\nexport function pick(colors: readonly string[], i: number): string {\n  return colors[i % colors.length] ?? \"transparent\";\n}\n\n/** Evenly spaced colour stops for CSS gradients. */\nexport function stops(colors: readonly string[], from = 0, to = 100): string {\n  const last = Math.max(1, colors.length - 1);\n  return colors\n    .map(\n      (color, i) => `${color} ${(from + ((to - from) * i) / last).toFixed(1)}%`,\n    )\n    .join(\", \");\n}\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/kind.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/kinds.ts",
      "content": "import type { GradientKindDefinition } from \"./kind\";\nimport { aurora } from \"./shaders/aurora\";\nimport { beam } from \"./shaders/beam\";\nimport { chrome } from \"./shaders/chrome\";\nimport { ditherBurst } from \"./shaders/dither-burst\";\nimport { ditherField } from \"./shaders/dither-field\";\nimport { fluted } from \"./shaders/fluted\";\nimport { grain } from \"./shaders/grain\";\nimport { halo } from \"./shaders/halo\";\nimport { horizon } from \"./shaders/horizon\";\nimport { limb } from \"./shaders/limb\";\nimport { linearFlow } from \"./shaders/linear-flow\";\nimport { mesh } from \"./shaders/mesh\";\nimport { mist } from \"./shaders/mist\";\nimport { pixelGlass } from \"./shaders/pixel-glass\";\nimport { radialGlow } from \"./shaders/radial-glow\";\nimport { ribbon } from \"./shaders/ribbon\";\nimport { rise } from \"./shaders/rise\";\nimport { silk } from \"./shaders/silk\";\nimport { smear } from \"./shaders/smear\";\nimport { spectrum } from \"./shaders/spectrum\";\nimport { swirl } from \"./shaders/swirl\";\nimport { voidKind } from \"./shaders/void\";\nimport { waves } from \"./shaders/waves\";\nimport type { GradientKind, GradientParams } from \"./types\";\n\nexport type { GradientKindDefinition } from \"./kind\";\n\nconst registry = new Map<string, GradientKindDefinition>();\n\n/** Adds a kind. Re-registering a name replaces it. */\nexport function registerKind(definition: GradientKindDefinition): void {\n  registry.set(definition.name, definition);\n}\n\nfor (const definition of [\n  mesh,\n  grain,\n  aurora,\n  waves,\n  radialGlow,\n  linearFlow,\n  horizon,\n  ditherField,\n  halo,\n  beam,\n  voidKind,\n  limb,\n  ditherBurst,\n  pixelGlass,\n  fluted,\n  spectrum,\n  silk,\n  ribbon,\n  chrome,\n  rise,\n  mist,\n  smear,\n  swirl,\n]) {\n  registerKind(definition);\n}\n\n/** The kind's definition, or mesh when the name is unknown. */\nexport function getKind(kind: GradientKind): GradientKindDefinition {\n  return registry.get(kind) ?? mesh;\n}\n\nexport function listKinds(): GradientKindDefinition[] {\n  return [...registry.values()];\n}\n\n/** Full params tuned for a kind. */\nexport function kindDefaults(kind: GradientKind): GradientParams {\n  const definition = getKind(kind);\n  return { ...definition.defaults, kind: definition.name };\n}\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/kinds.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/loop.ts",
      "content": "import type { RenderTarget } from \"./types\";\n\n/** Radius of the time circle in noise space at speed 1. */\nexport const LOOP_RADIUS = 0.6;\n/** Frame rate the live loop uses to derive `frameIndex`. */\nexport const LIVE_FPS = 60;\n\n/** Position along one loop, 0 to 2π. Endpoint input always wraps to zero. */\nexport function loopPhase(timeSeconds: number, loopSeconds: number): number {\n  const wrapped = ((timeSeconds % loopSeconds) + loopSeconds) % loopSeconds;\n  return (2 * Math.PI * wrapped) / loopSeconds;\n}\n\n/**\n * Noise-space time input. Without an explicit drift, retain the original\n * speed-scaled radius and one lap per loop for saved params. With drift, speed\n * changes pace around the pinned path.\n */\nexport function loopVector(\n  timeSeconds: number,\n  loopSeconds: number,\n  speed: number,\n  drift?: number,\n): readonly [number, number] {\n  const legacy = drift === undefined;\n  const phase = loopPhase(timeSeconds, loopSeconds) * (legacy ? 1 : speed);\n  const radius = legacy ? speed * LOOP_RADIUS : drift;\n  return [Math.cos(phase) * radius, Math.sin(phase) * radius];\n}\n\n/** Evaluates the fixed path at an already accumulated runtime phase. */\nexport function loopVectorAtPhase(\n  phase: number,\n  drift = LOOP_RADIUS,\n): readonly [number, number] {\n  return [Math.cos(phase) * drift, Math.sin(phase) * drift];\n}\n\n/**\n * Grain seed for a frame. It wraps at the live loop length so the grain\n * pattern repeats with the loop too.\n */\nexport function grainFrame(\n  frameIndex: number,\n  loopSeconds: number,\n  frameRate = LIVE_FPS,\n): number {\n  const period = Math.max(1, Math.round(loopSeconds * frameRate));\n  return ((Math.floor(frameIndex) % period) + period) % period;\n}\n\n/** Video frame rule: N = round(loopSeconds * fps) frames at i / fps; the endpoint is omitted. */\nexport function videoFrameTimes(loopSeconds: number, fps: number): number[] {\n  const count = Math.round(loopSeconds * fps);\n  return Array.from({ length: count }, (_, i) => i / fps);\n}\n\nexport function fullTarget(width: number, height: number): RenderTarget {\n  return { fullHeight: height, fullWidth: width, height, width, x: 0, y: 0 };\n}\n\n/**\n * Splits an image into tiles no larger than maxTile, row by row from the\n * top left. Tiles are quad-aligned so a tiled render equals the full one\n * even for kinds that use screen-space derivatives (fwidth), which the GPU\n * computes over 2x2 pixel quads: every tile starts at an even x, and every\n * tile's bottom edge sits an even number of rows above the image's bottom\n * (WebGL pairs rows from the bottom). The step is maxTile rounded down to\n * even, and any odd remainder goes to the top row of tiles.\n */\nexport function splitTiles(\n  fullWidth: number,\n  fullHeight: number,\n  maxTile: number,\n): RenderTarget[] {\n  const step = Math.max(2, Math.floor(maxTile / 2) * 2);\n  const rows: { y: number; height: number }[] = [];\n  for (let bottom = fullHeight; bottom > 0; bottom -= step) {\n    const y = Math.max(0, bottom - step);\n    rows.unshift({ height: bottom - y, y });\n  }\n  const tiles: RenderTarget[] = [];\n  for (const { y, height } of rows) {\n    for (let x = 0; x < fullWidth; x += step) {\n      tiles.push({\n        fullHeight,\n        fullWidth,\n        height,\n        width: Math.min(step, fullWidth - x),\n        x,\n        y,\n      });\n    }\n  }\n  return tiles;\n}\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/loop.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/mount.ts",
      "content": "import type { BackendLease, GradientBackend } from \"./backend\";\nimport { backendFor } from \"./backend\";\nimport { hasCssVariable, resolveColor, srgbToOklab } from \"./color\";\nimport { staticFallbackCss } from \"./fallback\";\nimport { fullTarget, LIVE_FPS, LOOP_RADIUS, loopPhase } from \"./loop\";\nimport { mergeParams, normalizeParams } from \"./params\";\nimport type { ContextSlot, FrameQuality } from \"./scheduler\";\nimport {\n  GRAIN_CRISP,\n  MIN_RENDER_SCALE,\n  noteFrame,\n  recordPaint,\n  registerSlot,\n  relearnDisplayRate,\n  scheduleContexts,\n  slotLostContext,\n  unregisterSlot,\n} from \"./scheduler\";\nimport type { FrameInput, GradientParams } from \"./types\";\n\nexport interface MountOptions {\n  /** Device pixel ratio cap. Default 1.5. */\n  maxDpr?: number;\n  /** \"respect\" renders one still frame when the user prefers reduced motion. Default \"respect\". */\n  reducedMotion?: \"respect\" | \"ignore\";\n  /** The page's one hero canvas: renders from PRIMARY_PIXEL_BUDGET, not the shared one. Default false. */\n  primary?: boolean;\n}\n\nexport interface MountedGradient {\n  setParams(p: Partial<GradientParams>): void;\n  unmount(): void;\n}\n\n/**\n * Live, on-page gradient. Owns canvas sizing (ResizeObserver, DPR capped at\n * maxDpr), rAF, pausing offscreen or when the document is hidden, smoothed\n * pointer and scroll-velocity influence, reduced motion, theme colour\n * re-resolution and its share of the page's WebGL context budget.\n *\n * The canvas gets a 2D context. Frames are rendered in a leased GPU\n * surface (WebGPU, or a WebGL context from the shared pool; see backend.ts)\n * and copied over, so a suspended gradient\n * keeps its last frame and never shows the browser's lost-context box.\n * Behind it, the canvas background is `staticFallbackCss`, which is what\n * shows when WebGL2 is unavailable.\n */\nexport function mountGradient(\n  canvas: HTMLCanvasElement,\n  params: GradientParams,\n  options: MountOptions = {},\n): MountedGradient {\n  const maxDpr = options.maxDpr ?? 1.5;\n  let current = normalizeParams(params);\n  let lease: BackendLease | null = null;\n  /** The backend `lease` came from; picked per kind when a lease is taken. */\n  let leaseBackend: GradientBackend = backendFor(current.kind);\n  /** The 2D canvas shows a frame that matches the current params and theme. */\n  let fresh = false;\n  let visible = false;\n  let raf = 0;\n  let lastNow: number | null = null;\n  let time = 0;\n  let phase = 0;\n  /** Bumped whenever params or resolved colours change. */\n  let version = 0;\n  /** Render scale and frame rate from the shared pixel budget. */\n  let quality: FrameQuality = { halfRate: false, scale: 1 };\n  let skipNext = false;\n\n  const display = canvas.getContext(\"2d\");\n  /** Pixels a frame renders at, at this render scale. */\n  const renderPixels = (scale: number) =>\n    Math.max(1, Math.round(canvas.width * scale)) *\n    Math.max(1, Math.round(canvas.height * scale));\n  const initialBackground = canvas.style.background;\n  const motionQuery = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n  const reduced = () =>\n    options.reducedMotion !== \"ignore\" && motionQuery.matches;\n\n  // Pointer and scroll targets, eased toward in the frame loop.\n  const pointerTarget = { strength: 0, x: 0.5, y: 0.5 };\n  const pointer = { strength: 0, x: 0.5, y: 0.5 };\n  let scrollImpulse = 0;\n  let scrollVelocity = 0;\n  let lastScroll = { t: performance.now(), y: window.scrollY };\n\n  const resolver = (value: string) =>\n    srgbToOklab(resolveColor(value, canvas.isConnected ? canvas : null));\n\n  const applyBackground = () => {\n    canvas.style.background = staticFallbackCss(current);\n  };\n\n  const frameInput = (): FrameInput => {\n    if (reduced()) {\n      return { frameIndex: 0, timeSeconds: 0 };\n    }\n    const input: FrameInput = {\n      frameIndex: Math.floor(time * LIVE_FPS),\n      timeSeconds: time,\n    };\n    if (current.drift !== undefined) {\n      input.phase = phase;\n    }\n    if (pointer.strength > 0.001) {\n      input.pointer = { ...pointer };\n    }\n    if (Math.abs(scrollVelocity) > 0.001) {\n      input.scroll = { velocity: scrollVelocity };\n    }\n    return input;\n  };\n\n  /** Renders one frame with a pooled context and copies it onto the canvas. */\n  const paintWith = (context: BackendLease, frame: FrameInput, scale = 1) => {\n    if (!display || context.isLost() || canvas.width === 0) {\n      return;\n    }\n    if (context.loaded?.owner !== slot || context.loaded.version !== version) {\n      context.resolver = resolver;\n      context.setParams(current);\n      context.loaded = { owner: slot, version };\n    }\n    // Over the pixel budget, render smaller and let drawImage upscale.\n    const width = Math.max(1, Math.round(canvas.width * scale));\n    const height = Math.max(1, Math.round(canvas.height * scale));\n    context.renderFrame(frame, fullTarget(width, height));\n    if (context.isLost()) {\n      return;\n    }\n    display.clearRect(0, 0, canvas.width, canvas.height);\n    // Upscaling smooths pixel-cell kinds into blur; keep their cells crisp.\n    display.imageSmoothingEnabled = !(\n      current.kind === \"dither-field\" || current.dither.enabled\n    );\n    // Copying right after queue.submit() is safe: reading a WebGPU canvas\n    // (drawImage included) runs \"get a copy of the image contents of a\n    // context\", which first ensures all submitted work has finished writing the\n    // current texture (https://gpuweb.github.io/gpuweb/#abstract-opdef-get-a-copy-of-the-image-contents-of-a-context,\n    // via #canvas-hooks). The engine lab checks it: heavy kinds at 2560x1440,\n    // each frame copied the moment it is submitted, never stale or blank.\n    display.drawImage(\n      context.canvas,\n      0,\n      context.sourceY,\n      width,\n      height,\n      0,\n      0,\n      canvas.width,\n      canvas.height,\n    );\n    fresh = true;\n  };\n\n  const draw = () => {\n    if (lease) {\n      const start = performance.now();\n      paintWith(lease, frameInput(), quality.scale);\n      recordPaint(performance.now() - start);\n    }\n  };\n\n  /** Drops a stale frame so the theme-aware CSS fallback shows instead. */\n  const invalidate = () => {\n    version += 1;\n    fresh = false;\n    if (!lease) {\n      display?.clearRect(0, 0, canvas.width, canvas.height);\n      scheduleContexts();\n    }\n  };\n\n  const shouldAnimate = () =>\n    lease !== null && visible && !document.hidden && !reduced();\n\n  const tick = (now: number) => {\n    raf = 0;\n    noteFrame(now);\n    const dt = lastNow === null ? 0 : Math.min(0.1, (now - lastNow) / 1000);\n    lastNow = now;\n    time += dt;\n    if (current.drift !== undefined) {\n      phase += (dt * current.speed * 2 * Math.PI) / current.loopSeconds;\n      phase %= 2 * Math.PI;\n    }\n    const ease = 1 - Math.exp(-dt * 6);\n    pointer.x += (pointerTarget.x - pointer.x) * ease;\n    pointer.y += (pointerTarget.y - pointer.y) * ease;\n    pointer.strength += (pointerTarget.strength - pointer.strength) * ease;\n    scrollImpulse *= Math.exp(-dt * 7);\n    scrollVelocity +=\n      (scrollImpulse - scrollVelocity) * (1 - Math.exp(-dt * 5));\n    // At half rate, time still advances every frame; only drawing skips.\n    skipNext = quality.halfRate && !skipNext;\n    if (!skipNext) {\n      draw();\n    }\n    if (shouldAnimate()) {\n      raf = window.requestAnimationFrame(tick);\n    }\n  };\n\n  /** Starts or stops the frame loop to match the current state. */\n  const sync = () => {\n    if (shouldAnimate()) {\n      if (raf === 0) {\n        lastNow = null;\n        raf = window.requestAnimationFrame(tick);\n      }\n      return;\n    }\n    if (raf !== 0) {\n      window.cancelAnimationFrame(raf);\n      raf = 0;\n    }\n    draw();\n  };\n\n  const slot: ContextSlot = {\n    element: canvas,\n    grant() {\n      if (lease) {\n        return true;\n      }\n      if (!display) {\n        return false;\n      }\n      leaseBackend = backendFor(current.kind);\n      // Still probing or compiling: no lease yet; the scheduler re-runs when ready.\n      lease = leaseBackend.supports(current.kind)\n        ? leaseBackend.acquire(onLost, renderPixels(quality.scale))\n        : null;\n      if (!lease) {\n        if (leaseBackend.unsupported()) {\n          unregisterSlot(slot);\n        }\n        return false;\n      }\n      draw();\n      sync();\n      return true;\n    },\n    primary() {\n      return options.primary === true;\n    },\n    minScale() {\n      if (current.dither.enabled) {\n        return 1;\n      }\n      return current.grain >= GRAIN_CRISP ? 0.8 : MIN_RENDER_SCALE;\n    },\n    pixels() {\n      return canvas.width * canvas.height;\n    },\n    backend() {\n      return backendFor(current.kind).name;\n    },\n    setQuality(next) {\n      quality = next;\n      // Readable in devtools and by the engine lab's checks.\n      canvas.dataset.renderScale = next.scale.toFixed(3);\n    },\n    paintStill() {\n      if (lease || fresh || !display) {\n        return;\n      }\n      const backend = backendFor(current.kind);\n      const painter = backend.supports(current.kind)\n        ? backend.acquire(null, renderPixels(1))\n        : null;\n      if (!painter) {\n        return;\n      }\n      paintWith(painter, frameInput());\n      backend.release(painter);\n    },\n    revoke() {\n      if (raf !== 0) {\n        window.cancelAnimationFrame(raf);\n        raf = 0;\n      }\n      if (lease) {\n        leaseBackend.release(lease);\n        lease = null;\n      }\n    },\n    setVisible(next) {\n      visible = next;\n      sync();\n    },\n  };\n\n  /**\n   * The pool lost our context and already ended the lease. Keep the last\n   * frame on screen and let the scheduler find another context; it re-runs\n   * again when the lost one is restored.\n   */\n  function onLost() {\n    lease = null;\n    if (raf !== 0) {\n      window.cancelAnimationFrame(raf);\n      raf = 0;\n    }\n    slotLostContext(slot);\n  }\n\n  const resize = () => {\n    const dpr = Math.min(maxDpr, window.devicePixelRatio || 1);\n    const width = Math.max(1, Math.round(canvas.clientWidth * dpr));\n    const height = Math.max(1, Math.round(canvas.clientHeight * dpr));\n    if (canvas.width !== width || canvas.height !== height) {\n      canvas.width = width;\n      canvas.height = height;\n      // Resizing clears the canvas.\n      fresh = false;\n      draw();\n      relearnDisplayRate();\n    }\n    scheduleContexts();\n  };\n\n  const onPointerMove = (event: PointerEvent) => {\n    if (current.interaction.pointer <= 0) {\n      return;\n    }\n    const rect = canvas.getBoundingClientRect();\n    if (rect.width === 0 || rect.height === 0) {\n      return;\n    }\n    const x = (event.clientX - rect.left) / rect.width;\n    const y = (event.clientY - rect.top) / rect.height;\n    const inside = x >= -0.1 && x <= 1.1 && y >= -0.1 && y <= 1.1;\n    pointerTarget.strength = inside ? 1 : 0;\n    if (inside) {\n      pointerTarget.x = x;\n      pointerTarget.y = y;\n    }\n  };\n  const onPointerLeave = () => {\n    pointerTarget.strength = 0;\n  };\n  const onScroll = () => {\n    const now = performance.now();\n    const dt = Math.max(1, now - lastScroll.t) / 1000;\n    const dy = window.scrollY - lastScroll.y;\n    lastScroll = { t: now, y: window.scrollY };\n    if (current.interaction.scroll <= 0) {\n      return;\n    }\n    // Viewport heights per second, so the feel is the same on every screen.\n    const velocity = dy / Math.max(1, window.innerHeight) / dt;\n    scrollImpulse = Math.max(-6, Math.min(6, velocity));\n  };\n  const onVisibility = () => {\n    relearnDisplayRate();\n    sync();\n  };\n  const onMotionChange = () => {\n    time = 0;\n    phase = 0;\n    invalidate();\n    sync();\n  };\n  const themeObserver = new MutationObserver(() => {\n    if (!hasCssVariable([...current.colors, current.background])) {\n      return;\n    }\n    invalidate();\n    draw();\n  });\n  const resizeObserver = new ResizeObserver(resize);\n\n  window.addEventListener(\"pointermove\", onPointerMove, { passive: true });\n  document.documentElement.addEventListener(\"pointerleave\", onPointerLeave);\n  window.addEventListener(\"scroll\", onScroll, { passive: true });\n  document.addEventListener(\"visibilitychange\", onVisibility);\n  motionQuery.addEventListener(\"change\", onMotionChange);\n  themeObserver.observe(document.documentElement, {\n    attributeFilter: [\"class\", \"style\"],\n    attributes: true,\n  });\n  resizeObserver.observe(canvas);\n\n  applyBackground();\n  canvas.dataset.renderScale = quality.scale.toFixed(3);\n  resize();\n  if (display) {\n    registerSlot(slot);\n  }\n\n  return {\n    setParams(patch) {\n      const speedChanged =\n        patch.speed !== undefined && patch.speed !== current.speed;\n      const enteringPinnedPath = speedChanged && current.drift === undefined;\n      const fullParamsPatch =\n        \"kind\" in patch && \"colors\" in patch && \"speed\" in patch;\n      const nextPatch: Partial<GradientParams> = enteringPinnedPath\n        ? { ...patch, drift: current.speed * LOOP_RADIUS }\n        : current.drift !== undefined &&\n            patch.drift === undefined &&\n            !fullParamsPatch\n          ? { ...patch, drift: current.drift }\n          : patch;\n      if (enteringPinnedPath) {\n        // Legacy frames use the angle once around the loop. Keep that angle\n        // while switching to the pinned path so the first edit cannot jump.\n        phase = loopPhase(time, current.loopSeconds);\n      }\n      current = mergeParams(current, nextPatch);\n      applyBackground();\n      if (lease && backendFor(current.kind) !== leaseBackend) {\n        // The new kind draws with the other backend: give the lease back and\n        // let the scheduler grant one from the right backend.\n        slot.revoke();\n        slotLostContext(slot);\n      }\n      invalidate();\n      draw();\n    },\n    unmount() {\n      slot.revoke();\n      unregisterSlot(slot);\n      resizeObserver.disconnect();\n      themeObserver.disconnect();\n      window.removeEventListener(\"pointermove\", onPointerMove);\n      document.documentElement.removeEventListener(\n        \"pointerleave\",\n        onPointerLeave,\n      );\n      window.removeEventListener(\"scroll\", onScroll);\n      document.removeEventListener(\"visibilitychange\", onVisibility);\n      motionQuery.removeEventListener(\"change\", onMotionChange);\n      display?.clearRect(0, 0, canvas.width, canvas.height);\n      canvas.style.background = initialBackground;\n      delete canvas.dataset.renderScale;\n    },\n  };\n}\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/mount.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/params.ts",
      "content": "import { mesh } from \"./shaders/mesh\";\nimport type { GradientParams } from \"./types\";\n\n/** The mesh kind with its tuned defaults. */\nexport const defaultParams: GradientParams = { ...mesh.defaults, kind: \"mesh\" };\n\nconst clamp = (n: number, min: number, max: number) =>\n  Math.min(max, Math.max(min, n));\n\nfunction record(input: unknown): Record<string, unknown> {\n  if (typeof input !== \"object\" || input === null || Array.isArray(input)) {\n    throw new TypeError(\"Expected an object\");\n  }\n  // Own enumerable fields are intentional: unlike zod, inherited properties are rejected.\n  return Object.fromEntries(Object.entries(input));\n}\n\nfunction number(value: unknown, name: string): number {\n  if (typeof value !== \"number\" || !Number.isFinite(value)) {\n    throw new TypeError(`${name} must be a number`);\n  }\n  return value;\n}\n\nfunction integer(value: unknown, name: string): number {\n  const parsed = number(value, name);\n  if (!Number.isInteger(parsed)) {\n    throw new TypeError(`${name} must be an integer`);\n  }\n  return parsed;\n}\n\nfunction string(value: unknown, name: string): string {\n  if (typeof value !== \"string\") {\n    throw new TypeError(`${name} must be a string`);\n  }\n  return value;\n}\n\nfunction fullParams(input: unknown): GradientParams {\n  const value = record(input);\n  const colors = value.colors;\n  if (!Array.isArray(colors) || colors.length < 2 || colors.length > 6) {\n    throw new TypeError(\"colors must contain 2 to 6 entries\");\n  }\n  const dither = record(value.dither);\n  const interaction = record(value.interaction);\n  const parsed = {\n    background: string(value.background, \"background\"),\n    blur: number(value.blur, \"blur\"),\n    colors: colors.map((color) => string(color, \"colors\")),\n    dither: {\n      cell: number(dither.cell, \"dither.cell\"),\n      enabled: boolean(dither.enabled, \"dither.enabled\"),\n      levels: number(dither.levels, \"dither.levels\"),\n    },\n    grain: number(value.grain, \"grain\"),\n    interaction: {\n      pointer: number(interaction.pointer, \"interaction.pointer\"),\n      scroll: number(interaction.scroll, \"interaction.scroll\"),\n    },\n    kind: string(value.kind, \"kind\"),\n    loopSeconds: number(value.loopSeconds, \"loopSeconds\"),\n    scale: number(value.scale, \"scale\"),\n    seed: integer(value.seed, \"seed\"),\n    speed: number(value.speed, \"speed\"),\n    warp: number(value.warp, \"warp\"),\n  };\n  return value.drift === undefined\n    ? parsed\n    : { ...parsed, drift: number(value.drift, \"drift\") };\n}\n\nfunction boolean(value: unknown, name: string): boolean {\n  if (typeof value !== \"boolean\") {\n    throw new TypeError(`${name} must be a boolean`);\n  }\n  return value;\n}\n\nfunction partialParams(input: unknown): Partial<GradientParams> {\n  const value = record(input);\n  const output: Partial<GradientParams> = {};\n  if (\"background\" in value)\n    output.background = string(value.background, \"background\");\n  if (\"blur\" in value) output.blur = number(value.blur, \"blur\");\n  if (\"colors\" in value) {\n    if (\n      !Array.isArray(value.colors) ||\n      value.colors.length < 2 ||\n      value.colors.length > 6\n    )\n      throw new TypeError(\"colors must contain 2 to 6 entries\");\n    output.colors = value.colors.map((color) => string(color, \"colors\"));\n  }\n  if (\"grain\" in value) output.grain = number(value.grain, \"grain\");\n  if (\"kind\" in value) output.kind = string(value.kind, \"kind\");\n  if (\"drift\" in value) output.drift = number(value.drift, \"drift\");\n  if (\"loopSeconds\" in value)\n    output.loopSeconds = number(value.loopSeconds, \"loopSeconds\");\n  if (\"scale\" in value) output.scale = number(value.scale, \"scale\");\n  if (\"seed\" in value) output.seed = integer(value.seed, \"seed\");\n  if (\"speed\" in value) output.speed = number(value.speed, \"speed\");\n  if (\"warp\" in value) output.warp = number(value.warp, \"warp\");\n  if (\"dither\" in value) {\n    const dither = partialDither(value.dither);\n    output.dither = {\n      ...defaultParams.dither,\n      ...dither,\n    };\n  }\n  if (\"interaction\" in value) {\n    const interaction = partialInteraction(value.interaction);\n    output.interaction = {\n      ...defaultParams.interaction,\n      ...interaction,\n    };\n  }\n  return output;\n}\n\nfunction partialDither(input: unknown): Partial<GradientParams[\"dither\"]> {\n  const value = record(input);\n  const output: Partial<GradientParams[\"dither\"]> = {};\n  if (\"cell\" in value) output.cell = number(value.cell, \"dither.cell\");\n  if (\"levels\" in value) output.levels = number(value.levels, \"dither.levels\");\n  if (\"enabled\" in value) {\n    output.enabled = boolean(value.enabled, \"dither.enabled\");\n  }\n  return output;\n}\n\nfunction partialInteraction(\n  input: unknown,\n): Partial<GradientParams[\"interaction\"]> {\n  const value = record(input);\n  const output: Partial<GradientParams[\"interaction\"]> = {};\n  if (\"pointer\" in value)\n    output.pointer = number(value.pointer, \"interaction.pointer\");\n  if (\"scroll\" in value)\n    output.scroll = number(value.scroll, \"interaction.scroll\");\n  return output;\n}\n\n/** Validates and clamps a full params object. Throws on a malformed shape. */\nexport function normalizeParams(input: GradientParams): GradientParams {\n  const parsed = fullParams(input);\n  const normalized = {\n    ...parsed,\n    blur: clamp(parsed.blur, 0, 1),\n    colors: parsed.colors.slice(0, 6),\n    dither: {\n      cell: Math.round(clamp(parsed.dither.cell, 1, 32)),\n      enabled: parsed.dither.enabled,\n      levels: Math.round(clamp(parsed.dither.levels, 2, 32)),\n    },\n    grain: clamp(parsed.grain, 0, 1),\n    interaction: {\n      pointer: clamp(parsed.interaction.pointer, 0, 1),\n      scroll: clamp(parsed.interaction.scroll, 0, 1),\n    },\n    loopSeconds: clamp(parsed.loopSeconds, 4, 30),\n    scale: clamp(parsed.scale, 0.25, 4),\n    speed: clamp(parsed.speed, 0, 2),\n    warp: clamp(parsed.warp, 0, 1),\n  };\n  if (parsed.drift !== undefined) {\n    normalized.drift = clamp(parsed.drift, 0, 2);\n  }\n  return normalized;\n}\n\n/** Merges a partial update into full params, keeping nested objects whole. */\nexport function mergeParams(\n  base: GradientParams,\n  patch: Partial<GradientParams>,\n): GradientParams {\n  return normalizeParams({\n    ...base,\n    ...patch,\n    dither: { ...base.dither, ...patch.dither },\n    interaction: { ...base.interaction, ...patch.interaction },\n  });\n}\n\nexport function serializeParams(p: GradientParams): string {\n  return encodeURIComponent(JSON.stringify(normalizeParams(p)));\n}\n\nexport function parseParams(s: string): GradientParams {\n  try {\n    const raw: unknown = JSON.parse(decodeURIComponent(s));\n    const parsed = partialParams(raw);\n    return normalizeParams({\n      ...defaultParams,\n      ...parsed,\n      dither: { ...defaultParams.dither, ...parsed.dither },\n      interaction: { ...defaultParams.interaction, ...parsed.interaction },\n    });\n  } catch {\n    return defaultParams;\n  }\n}\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/params.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/pool.ts",
      "content": "/**\n * The page's WebGL contexts. Gradients never hold a context on their own\n * canvas; they lease one of at most MAX_LIVE_CONTEXTS offscreen contexts,\n * render into it and copy the frame onto their 2D canvas. Returning a lease\n * keeps the last frame on screen, and contexts are reused instead of being\n * lost and restored.\n *\n * When the browser loses a context, its lease ends at once: the holder is\n * told (it keeps its last frame), the context stays unavailable, and the\n * scheduler re-runs so the gradient can lease another one. When the context\n * is restored it becomes available again and the scheduler re-runs.\n */\nimport type { BackendLease } from \"./backend\";\nimport { defaultParams } from \"./params\";\nimport type { AnyCanvas, WebGLRenderer } from \"./renderer\";\nimport {\n  createWebGLRenderer,\n  documentColorResolver,\n  getWebGL2,\n} from \"./renderer\";\n\nexport const MAX_LIVE_CONTEXTS = 8;\n\nexport interface PooledContext extends BackendLease {\n  readonly canvas: AnyCanvas;\n  readonly gl: WebGL2RenderingContext;\n  readonly renderer: WebGLRenderer;\n  leased: boolean;\n  lost: boolean;\n  /** Called once if the context is lost while leased. */\n  onLost: (() => void) | null;\n}\n\nconst contexts = new Set<PooledContext>();\nlet unsupported = false;\nconst changeListeners = new Set<() => void>();\n\n/** Runs `listener` whenever a context is lost or restored. */\nexport function onPoolChange(listener: () => void): () => void {\n  changeListeners.add(listener);\n  return () => changeListeners.delete(listener);\n}\n\nfunction notifyChange() {\n  for (const listener of changeListeners) {\n    listener();\n  }\n}\n\nfunction createCanvas(): AnyCanvas {\n  if (typeof OffscreenCanvas !== \"undefined\") {\n    return new OffscreenCanvas(1, 1);\n  }\n  return document.createElement(\"canvas\");\n}\n\nfunction create(): PooledContext | null {\n  if (unsupported) {\n    return null;\n  }\n  let canvas = createCanvas();\n  let gl = getWebGL2(canvas, { preserveDrawingBuffer: false });\n  if (\n    !gl &&\n    typeof document !== \"undefined\" &&\n    !(canvas instanceof HTMLCanvasElement)\n  ) {\n    // Some browsers have OffscreenCanvas without WebGL2 on it.\n    canvas = document.createElement(\"canvas\");\n    gl = getWebGL2(canvas, { preserveDrawingBuffer: false });\n  }\n  if (!gl) {\n    unsupported = true;\n    return null;\n  }\n  const holder = { resolver: documentColorResolver };\n  const renderer = createWebGLRenderer({\n    canvas,\n    gl,\n    params: defaultParams,\n    resolveColor: (value) => holder.resolver(value),\n  });\n  const context: PooledContext = {\n    canvas,\n    gl,\n    isLost: () => context.lost || gl.isContextLost(),\n    leased: false,\n    loaded: null,\n    sourceY: 0,\n    lost: false,\n    onLost: null,\n    renderFrame: (frame, target) => renderer.renderFrame(frame, target),\n    renderer,\n    setParams: (next) => renderer.setParams(next),\n    get resolver() {\n      return holder.resolver;\n    },\n    set resolver(next) {\n      holder.resolver = next;\n    },\n  };\n  canvas.addEventListener(\"webglcontextlost\", (event) => {\n    event.preventDefault();\n    context.lost = true;\n    context.loaded = null;\n    const holder = context.onLost;\n    context.onLost = null;\n    context.leased = false;\n    holder?.();\n    notifyChange();\n  });\n  canvas.addEventListener(\"webglcontextrestored\", () => {\n    if (!contexts.has(context)) {\n      // Trimmed while lost: don't keep a restored context outside the budget.\n      gl.getExtension(\"WEBGL_lose_context\")?.loseContext();\n      return;\n    }\n    context.lost = false;\n    context.loaded = null;\n    try {\n      context.renderer.restore();\n    } catch {\n      destroy(context);\n    }\n    notifyChange();\n  });\n  contexts.add(context);\n  return context;\n}\n\n/** True once creating a WebGL2 context has failed on this page. */\nexport function webglUnsupported(): boolean {\n  return unsupported;\n}\n\n/**\n * Leases an idle context, creating one if the budget allows. `onLost` runs if\n * the browser loses the context during the lease; the lease is already over\n * by then.\n */\nexport function acquireContext(\n  onLost: (() => void) | null = null,\n): PooledContext | null {\n  for (const context of contexts) {\n    if (!context.leased && !context.lost) {\n      context.leased = true;\n      context.onLost = onLost;\n      return context;\n    }\n  }\n  if (contexts.size >= MAX_LIVE_CONTEXTS) {\n    return null;\n  }\n  try {\n    const context = create();\n    if (context) {\n      context.leased = true;\n      context.onLost = onLost;\n    }\n    return context;\n  } catch {\n    // A shader that fails to compile means this engine cannot run here.\n    unsupported = true;\n    return null;\n  }\n}\n\nexport function releaseContext(context: PooledContext): void {\n  context.leased = false;\n  context.onLost = null;\n}\n\nfunction destroy(context: PooledContext) {\n  context.renderer.destroy();\n  context.gl.getExtension(\"WEBGL_lose_context\")?.loseContext();\n  contexts.delete(context);\n}\n\n/** Frees idle contexts until at most `keep` contexts remain. */\nexport function trimContexts(keep: number): void {\n  for (const context of [...contexts]) {\n    if (contexts.size <= keep) {\n      return;\n    }\n    if (!context.leased) {\n      destroy(context);\n    }\n  }\n}\n\nexport function liveContextCount(): number {\n  return contexts.size;\n}\n\n/** The pool's contexts. For tests and the engine lab only. */\nexport function pooledContexts(): readonly PooledContext[] {\n  return [...contexts];\n}\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/pool.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/renderer.ts",
      "content": "import type { Oklab } from \"./color\";\nimport { resolveColor, srgbToOklab } from \"./color\";\nimport { getKind } from \"./kinds\";\nimport { fullTarget } from \"./loop\";\nimport { mergeParams, normalizeParams } from \"./params\";\nimport {\n  fragmentPostlude,\n  fragmentPrelude,\n  vertexShader,\n} from \"./shaders/common\";\nimport type {\n  FrameInput,\n  GradientParams,\n  GradientRenderer,\n  RenderTarget,\n} from \"./types\";\nimport { frameUniforms } from \"./uniforms\";\n\nexport type AnyCanvas = HTMLCanvasElement | OffscreenCanvas;\n\nexport interface ContextOptions {\n  preserveDrawingBuffer: boolean;\n}\n\nconst UNIFORMS = [\n  \"u_full\",\n  \"u_tile\",\n  \"u_loop\",\n  \"u_seed\",\n  \"u_scale\",\n  \"u_warp\",\n  \"u_blur\",\n  \"u_grain\",\n  \"u_frame\",\n  \"u_dither\",\n  \"u_colors\",\n  \"u_count\",\n  \"u_bg\",\n  \"u_pointer\",\n  \"u_scroll\",\n] as const;\ntype UniformName = (typeof UNIFORMS)[number];\n\ninterface ProgramInfo {\n  program: WebGLProgram;\n  uniforms: Record<UniformName, WebGLUniformLocation | null>;\n}\n\nexport class ShaderError extends Error {\n  override name = \"ShaderError\";\n}\n\nfunction isOffscreen(canvas: AnyCanvas): canvas is OffscreenCanvas {\n  return (\n    typeof OffscreenCanvas !== \"undefined\" && canvas instanceof OffscreenCanvas\n  );\n}\n\n/** Gets (or returns the existing) WebGL2 context. Null when WebGL2 is unavailable. */\nexport function getWebGL2(\n  canvas: AnyCanvas,\n  options: ContextOptions,\n): WebGL2RenderingContext | null {\n  const attributes: WebGLContextAttributes = {\n    alpha: true,\n    antialias: false,\n    depth: false,\n    powerPreference: \"low-power\",\n    premultipliedAlpha: true,\n    preserveDrawingBuffer: options.preserveDrawingBuffer,\n    stencil: false,\n  };\n  try {\n    return isOffscreen(canvas)\n      ? canvas.getContext(\"webgl2\", attributes)\n      : canvas.getContext(\"webgl2\", attributes);\n  } catch {\n    return null;\n  }\n}\n\nfunction compile(\n  gl: WebGL2RenderingContext,\n  type: number,\n  source: string,\n): WebGLShader {\n  const shader = gl.createShader(type);\n  if (!shader) {\n    throw new ShaderError(\"Unable to create shader\");\n  }\n  gl.shaderSource(shader, source);\n  gl.compileShader(shader);\n  if (\n    !gl.getShaderParameter(shader, gl.COMPILE_STATUS) &&\n    !gl.isContextLost()\n  ) {\n    const log = gl.getShaderInfoLog(shader) ?? \"\";\n    gl.deleteShader(shader);\n    throw new ShaderError(`Shader compile failed: ${log}`);\n  }\n  return shader;\n}\n\nexport type ColorResolver = (value: string) => Oklab;\n\nexport const documentColorResolver: ColorResolver = (value) =>\n  srgbToOklab(\n    resolveColor(\n      value,\n      typeof document === \"undefined\" ? null : document.documentElement,\n    ),\n  );\n\nexport interface WebGLRenderer extends GradientRenderer {\n  readonly gl: WebGL2RenderingContext;\n  readonly params: GradientParams;\n  /** Rebuilds GPU resources after `webglcontextrestored`. */\n  restore(): void;\n  /** Re-resolves colours, for example after a theme change. */\n  refreshColors(): void;\n}\n\n/**\n * Pure renderer over an existing WebGL2 context. No rAF, listeners or CSS.\n * Throws ShaderError when a kind's shader cannot compile.\n */\nexport function createWebGLRenderer(options: {\n  canvas: AnyCanvas;\n  gl: WebGL2RenderingContext;\n  params: GradientParams;\n  resolveColor?: ColorResolver;\n}): WebGLRenderer {\n  const { canvas, gl } = options;\n  const resolve = options.resolveColor ?? documentColorResolver;\n  let params = normalizeParams(options.params);\n  let colors: Oklab[] = [];\n  let background: Oklab = [0, 0, 0];\n  let programs = new Map<string, ProgramInfo>();\n  let buffer: WebGLBuffer | null = null;\n  let vao: WebGLVertexArrayObject | null = null;\n\n  const refreshColors = () => {\n    colors = params.colors.map((value) => resolve(value));\n    background = resolve(params.background);\n  };\n\n  const buildGeometry = () => {\n    buffer = gl.createBuffer();\n    vao = gl.createVertexArray();\n    gl.bindVertexArray(vao);\n    gl.bindBuffer(gl.ARRAY_BUFFER, buffer);\n    gl.bufferData(\n      gl.ARRAY_BUFFER,\n      new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]),\n      gl.STATIC_DRAW,\n    );\n    gl.enableVertexAttribArray(0);\n    gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);\n    gl.bindVertexArray(null);\n  };\n\n  const programFor = (kindName: string): ProgramInfo => {\n    const kind = getKind(kindName);\n    const cached = programs.get(kind.name);\n    if (cached) {\n      return cached;\n    }\n    const vs = compile(gl, gl.VERTEX_SHADER, vertexShader);\n    const fs = compile(\n      gl,\n      gl.FRAGMENT_SHADER,\n      `${fragmentPrelude}\\n${kind.glsl}\\n${fragmentPostlude}`,\n    );\n    const program = gl.createProgram();\n    if (!program) {\n      throw new ShaderError(\"Unable to create program\");\n    }\n    gl.attachShader(program, vs);\n    gl.attachShader(program, fs);\n    gl.bindAttribLocation(program, 0, \"a_position\");\n    gl.linkProgram(program);\n    gl.deleteShader(vs);\n    gl.deleteShader(fs);\n    if (\n      !gl.getProgramParameter(program, gl.LINK_STATUS) &&\n      !gl.isContextLost()\n    ) {\n      const log = gl.getProgramInfoLog(program) ?? \"\";\n      gl.deleteProgram(program);\n      throw new ShaderError(`Program link failed: ${log}`);\n    }\n    const uniforms = Object.fromEntries(\n      UNIFORMS.map((name) => [name, gl.getUniformLocation(program, name)]),\n    ) as Record<UniformName, WebGLUniformLocation | null>;\n    const info = { program, uniforms };\n    programs.set(kind.name, info);\n    return info;\n  };\n\n  const restore = () => {\n    programs = new Map();\n    buildGeometry();\n    programFor(params.kind);\n  };\n\n  refreshColors();\n  restore();\n\n  return {\n    get canvas() {\n      return canvas;\n    },\n    destroy() {\n      if (!gl.isContextLost()) {\n        for (const { program } of programs.values()) {\n          gl.deleteProgram(program);\n        }\n        gl.deleteBuffer(buffer);\n        gl.deleteVertexArray(vao);\n      }\n      programs = new Map();\n    },\n    gl,\n    get params() {\n      return params;\n    },\n    refreshColors,\n    renderFrame(frame: FrameInput, target?: RenderTarget) {\n      if (gl.isContextLost()) {\n        return;\n      }\n      const t = target ?? fullTarget(canvas.width, canvas.height);\n      if (canvas.width !== t.width || canvas.height !== t.height) {\n        canvas.width = t.width;\n        canvas.height = t.height;\n      }\n      const { program, uniforms: u } = programFor(params.kind);\n      const f = frameUniforms(params, colors, background, frame, t);\n      const palette = new Float32Array(18);\n      f.colors.forEach(([l, a, b], i) => {\n        palette.set([l, a, b], i * 3);\n      });\n\n      gl.viewport(0, 0, t.width, t.height);\n      // biome-ignore lint/correctness/useHookAtTopLevel: WebGL call, not a React hook\n      gl.useProgram(program);\n      gl.bindVertexArray(vao);\n      gl.uniform2f(u.u_full, f.full[0], f.full[1]);\n      gl.uniform4f(u.u_tile, f.tile[0], f.tile[1], f.tile[2], f.tile[3]);\n      gl.uniform2f(u.u_loop, f.loopv[0], f.loopv[1]);\n      gl.uniform2f(u.u_seed, f.seed[0], f.seed[1]);\n      gl.uniform1f(u.u_scale, f.scale);\n      gl.uniform1f(u.u_warp, f.warp);\n      gl.uniform1f(u.u_blur, f.blur);\n      gl.uniform1f(u.u_grain, f.grain);\n      gl.uniform1f(u.u_frame, f.frame);\n      gl.uniform3f(u.u_dither, f.dither[0], f.dither[1], f.dither[2]);\n      gl.uniform3fv(u.u_colors, palette);\n      gl.uniform1i(u.u_count, f.count);\n      gl.uniform3f(u.u_bg, f.bg[0], f.bg[1], f.bg[2]);\n      gl.uniform3f(u.u_pointer, f.pointer[0], f.pointer[1], f.pointer[2]);\n      gl.uniform1f(u.u_scroll, f.scroll);\n      gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);\n      gl.bindVertexArray(null);\n    },\n    restore,\n    setParams(patch: Partial<GradientParams>) {\n      const colorsChanged =\n        patch.colors !== undefined || patch.background !== undefined;\n      params = mergeParams(params, patch);\n      if (colorsChanged) {\n        refreshColors();\n      }\n    },\n  };\n}\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/renderer.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/scheduler.ts",
      "content": "/**\n * Module-level GPU budget: at most MAX_LIVE_CONTEXTS WebGL contexts and\n * MAX_WEBGPU_SURFACES WebGPU surfaces per page, each gradient counting\n * against its own kind's backend. Gradients near the viewport lease one, nearest first; the rest are\n * suspended and keep their last frame (or the CSS fallback) until they come\n * close again. When more gradients are near than the budget allows, one\n * context is kept back to paint still frames for the ones left over, so they\n * never fall back to the rougher CSS approximation.\n *\n * Pixel budget: every animating gradient copies its frame onto its canvas,\n * so the cost per frame grows with the total pixel count, not the number of\n * gradients. Animating gradients share PIXEL_BUDGET drawing-buffer pixels per\n * frame (about one 1440x900 viewport at DPR 1.25). Over budget, every\n * animating gradient renders at the same lower internal scale and is\n * upscaled when copied; the soft kinds hide this well. Grain and dither are\n * per-pixel detail, so params with grain >= GRAIN_CRISP or dither on are\n * never scaled below their floor (0.8 and 1). If the floors still leave the\n * total over budget, all animating gradients drop to half the display rate.\n *\n * A primary gradient (a page's one hero canvas) has its own\n * PRIMARY_PIXEL_BUDGET. A frame-time governor (judgePace) caps the pixels\n * per frame, for every gradient alike, when frames fall behind the display rate.\n */\nimport type { BackendName } from \"./backend\";\nimport {\n  liveContextCount,\n  MAX_LIVE_CONTEXTS,\n  onPoolChange,\n  trimContexts,\n} from \"./pool\";\nimport {\n  MAX_WEBGPU_SURFACES,\n  onWebGPUChange,\n  trimSurfaces,\n  webgpuStats,\n} from \"./webgpu\";\n\nexport interface EngineStats {\n  renderedPixels: number;\n  animatingMounts: number;\n  mounted: number;\n  renderScale: number;\n  fpsTier: \"full\" | \"half\";\n  scrolling: boolean;\n  paceCap: number;\n  rafIntervals: number[];\n  gpuTimeMs: number | null;\n}\n\ndeclare global {\n  interface Window {\n    __gcnEngineStats?: () => EngineStats;\n  }\n}\n\nexport { MAX_LIVE_CONTEXTS } from \"./pool\";\n\n/** Drawing-buffer pixels per frame shared by all animating gradients. */\nexport const PIXEL_BUDGET = 2_000_000;\n/**\n * Drawing-buffer pixels per frame for primary gradients, on top of\n * PIXEL_BUDGET: a 1230x760 studio stage at DPR 2 (3.7 MP) fits whole.\n */\nexport const PRIMARY_PIXEL_BUDGET = 4_500_000;\n/** Lowest internal render scale for soft gradients. */\nexport const MIN_RENDER_SCALE = 0.5;\n/** Grain at or above this keeps a render scale of at least 0.8. */\nexport const GRAIN_CRISP = 0.3;\n\n/** How far outside the viewport (as a fraction of its height) a gradient still counts as near. */\nconst APPROACH_MARGIN = 0.5;\n\nexport interface FrameQuality {\n  /** Internal render scale, 0-1, applied to both axes. */\n  scale: number;\n  /** Render every other display frame (half the display refresh rate). */\n  halfRate: boolean;\n}\n\nexport interface ContextSlot {\n  readonly element: Element;\n  /** Give this gradient a context. Returns false when none could be leased. */\n  grant(): boolean;\n  /** Take its context away. */\n  revoke(): void;\n  /** Whether any part of it is inside the viewport. */\n  setVisible(visible: boolean): void;\n  /** Near the viewport but over budget: show a still frame. */\n  paintStill(): void;\n  /** Drawing-buffer pixels at full scale. */\n  pixels(): number;\n  /** Lowest render scale these params tolerate. */\n  minScale(): number;\n  /** Draws from PRIMARY_PIXEL_BUDGET instead of the shared budget. */\n  primary(): boolean;\n  setQuality(quality: FrameQuality): void;\n  /** The backend this gradient's kind draws with on this page. */\n  backend(): BackendName;\n}\n\ninterface SlotState {\n  live: boolean;\n  visible: boolean;\n  quality: FrameQuality;\n}\n\nconst slots = new Map<ContextSlot, SlotState>();\nlet wantedSlots = new Set<ContextSlot>();\nlet frame = 0;\nlet listening = false;\nlet observer: IntersectionObserver | null = null;\nlet pixelBudget = PIXEL_BUDGET;\n\nfunction distanceToViewport(rect: DOMRect, width: number, height: number) {\n  const dx = Math.max(0, rect.left - width, -rect.right);\n  const dy = Math.max(0, rect.top - height, -rect.bottom);\n  return Math.hypot(dx, dy);\n}\n\n/** The 60 Hz default until rAF gives us a display measurement. */\nconst DEFAULT_FRAME_MS = 1000 / 60;\n/** Display intervals used by the rolling estimator (60-240 Hz range). */\nconst MIN_DISPLAY_MS = 4;\nconst MAX_DISPLAY_MS = DEFAULT_FRAME_MS * 1.25;\nconst DISPLAY_SAMPLES = 24;\n/**\n * Safe primary ceiling: 8.3M RGBA pixels are about 32 MB for one buffer and\n * 96 MB for WebGPU's three-buffer swap-chain cap. WebGL has no memory guard,\n * so the same conservative limit protects both backends.\n */\nconst MAX_PRIMARY_PIXEL_BUDGET = 8_300_000;\n/** rAF intervals per governor decision. */\nconst PACE_WINDOW = 10;\n/** Steady windows in a row before the cap rises. */\nconst STEADY_WINDOWS = 5;\n/** Gaps longer than this are pauses or hitches, not frame time. */\nconst MAX_INTERVAL_MS = 250;\n/** Ticks ignored after the animating set or its quality changes (compiles, hydration). */\nconst WARMUP_TICKS = 30;\n/** Steady windows at the ceiling (~10s) before it lifts a step. */\nconst CEILING_WINDOWS = 60;\n\ninterface Pace {\n  /** Most drawing-buffer pixels per frame, over every animating gradient. */\n  cap: number;\n  /** Pixels per frame that were too slow; the cap never rises back to it. */\n  ceiling: number;\n  lastTick: number | null;\n  intervals: number[];\n  /** Ticks left to ignore; see WARMUP_TICKS. */\n  warmup: number;\n  slowWindows: number;\n  steadyWindows: number;\n  /** Steady windows in a row spent at the ceiling. */\n  ceilingWindows: number;\n  /** Learned display interval; starts at the historical 60 Hz target. */\n  targetMs: number;\n  /** Rolling valid rAF intervals used to learn targetMs. */\n  displaySamples: number[];\n  /** Quality changes suppress display-rate learning during warm-up. */\n  suppressDisplayLearning: boolean;\n}\n\nconst pace: Pace = {\n  cap: Number.POSITIVE_INFINITY,\n  ceiling: Number.POSITIVE_INFINITY,\n  ceilingWindows: 0,\n  intervals: [],\n  lastTick: null,\n  slowWindows: 0,\n  steadyWindows: 0,\n  warmup: WARMUP_TICKS,\n  targetMs: DEFAULT_FRAME_MS,\n  displaySamples: [],\n  suppressDisplayLearning: false,\n};\n/** Pixels rendered per frame at the current quality, for the governor. */\nlet renderedPixels = 0;\n/** Slots animating at the last assignQuality, to notice a change. */\nlet animatingCount = 0;\nlet primaryBudget = PRIMARY_PIXEL_BUDGET;\nlet scrolling = false;\nlet scrollIdleTimer = 0;\nconst SCROLL_PIXEL_FACTOR = 0.65;\nconst SCROLL_IDLE_MS = 150;\n\n/** Starts a fresh measurement after the work per frame changed. */\nfunction restartPace() {\n  if (pace.lastTick !== null) pace.suppressDisplayLearning = true;\n  pace.warmup = WARMUP_TICKS;\n  pace.intervals = [];\n  pace.slowWindows = 0;\n  pace.steadyWindows = 0;\n}\n\ninterface QualityGroup {\n  slots: [ContextSlot, SlotState][];\n  budget: number;\n}\n\n/** Shared render scale for one budget group, then each slot's floor. */\nfunction groupScales({ slots: group, budget }: QualityGroup) {\n  const total = group.reduce((sum, [slot]) => sum + slot.pixels(), 0);\n  const shared =\n    total > budget ? Math.max(MIN_RENDER_SCALE, Math.sqrt(budget / total)) : 1;\n  let rendered = 0;\n  const scales = group.map(([slot]) => {\n    const scale = Math.min(1, Math.max(shared, slot.minScale()));\n    rendered += slot.pixels() * scale * scale;\n    return scale;\n  });\n  // Small tolerance: the shared scale lands exactly on the budget.\n  return { halfRate: rendered > budget * 1.01, rendered, scales };\n}\n\n/** Reserve every other live WebGPU lease before growing a primary surface. */\nfunction primarySurfaceBudget() {\n  let webgpuPrimary = false;\n  let reserved = 0;\n  for (const [slot, state] of slots) {\n    if ((!state.live && !wantedSlots.has(slot)) || slot.backend() !== \"webgpu\")\n      continue;\n    if (slot.primary()) webgpuPrimary = true;\n    // Reserve full-size needs, including near but invisible leases. This also\n    // allows thumbnails to regain quality without evicting the primary.\n    else reserved += slot.pixels();\n  }\n  return webgpuPrimary\n    ? Math.max(0, MAX_PRIMARY_PIXEL_BUDGET - reserved)\n    : MAX_PRIMARY_PIXEL_BUDGET;\n}\n\n/** Splits the pixel budgets across the gradients that are animating. */\nfunction assignQuality() {\n  const animating = [...slots].filter(\n    ([slot, state]) => (state.live || wantedSlots.has(slot)) && state.visible,\n  );\n  const groups: QualityGroup[] = [\n    {\n      budget:\n        Math.min(primaryBudget, primarySurfaceBudget()) *\n        (scrolling ? SCROLL_PIXEL_FACTOR : 1),\n      slots: animating.filter(([slot]) => slot.primary()),\n    },\n    {\n      budget: pixelBudget * (scrolling ? SCROLL_PIXEL_FACTOR : 1),\n      slots: animating.filter(([slot]) => !slot.primary()),\n    },\n  ];\n  let results = groups.map(groupScales);\n  const rendered = results.reduce((sum, result) => sum + result.rendered, 0);\n  if (rendered > pace.cap) {\n    // The governor's cap: shrink each group's budget to its share of it.\n    const share = pace.cap / rendered;\n    results = groups.map((group, i) =>\n      groupScales({\n        budget: Math.min(group.budget, results[i]?.rendered ?? 0) * share,\n        slots: group.slots,\n      }),\n    );\n  }\n  renderedPixels = 0;\n  let changed = animating.length !== animatingCount;\n  animatingCount = animating.length;\n  groups.forEach((group, g) => {\n    const result = results[g];\n    if (!result) {\n      return;\n    }\n    renderedPixels += result.rendered;\n    group.slots.forEach(([slot, state], i) => {\n      const scale = result.scales[i] ?? 1;\n      const { halfRate } = result;\n      if (\n        state.quality.scale !== scale ||\n        state.quality.halfRate !== halfRate\n      ) {\n        // Paused primaries may never paint the smaller buffer. Release the\n        // old allocation before admission; grant() paints at the new scale.\n        if (\n          state.live &&\n          slot.primary() &&\n          slot.backend() === \"webgpu\" &&\n          scale < state.quality.scale\n        ) {\n          state.live = false;\n          slot.revoke();\n          scheduleContexts();\n        }\n        state.quality = { halfRate, scale };\n        slot.setQuality(state.quality);\n        changed = true;\n      }\n    });\n  });\n  if (changed) {\n    restartPace();\n  }\n}\n\n/** Temporarily lowers render work while a scroll is actively moving. */\nexport function noteScroll(): void {\n  if (!scrolling) {\n    scrolling = true;\n    assignQuality();\n  }\n  if (\n    typeof window !== \"undefined\" &&\n    typeof window.setTimeout === \"function\"\n  ) {\n    window.clearTimeout(scrollIdleTimer);\n    scrollIdleTimer = window.setTimeout(() => {\n      scrolling = false;\n      assignQuality();\n    }, SCROLL_IDLE_MS);\n  }\n}\n\n/**\n * One decision from a window's mean rAF interval. Not the median: a\n * pipelining browser keeps most ticks on time and drops whole frames.\n */\nfunction judgePace(meanMs: number) {\n  const slow = meanMs > pace.targetMs * 1.12;\n  pace.slowWindows = slow ? pace.slowWindows + 1 : 0;\n  pace.steadyWindows =\n    meanMs <= pace.targetMs * 1.05 ? pace.steadyWindows + 1 : 0;\n  // Far too slow acts at once; a little slow must repeat, to skip hitches.\n  if (slow && (meanMs > pace.targetMs * 2 || pace.slowWindows >= 2)) {\n    pace.slowWindows = 0;\n    pace.ceilingWindows = 0;\n    pace.ceiling = Math.min(pace.ceiling, renderedPixels);\n    // Pixel cost is about linear, so aim a little under the target.\n    const factor = Math.min(0.9, Math.max(0.5, (pace.targetMs / meanMs) * 0.9));\n    pace.cap = Math.min(pace.cap, renderedPixels) * factor;\n    scheduleContexts();\n    return;\n  }\n  if (\n    pace.steadyWindows < STEADY_WINDOWS ||\n    (Number.isFinite(pace.cap) && renderedPixels < pace.cap * 0.98)\n  ) {\n    return;\n  }\n  if (!Number.isFinite(pace.cap)) {\n    // Keep grids on their existing shared budget. Only the primary group's\n    // budget grows, and only while the governor has sustained headroom.\n    primaryBudget = Math.min(primarySurfaceBudget(), primaryBudget * 1.2);\n    pace.steadyWindows = 0;\n    scheduleContexts();\n    return;\n  }\n  pace.steadyWindows = 0;\n  const limit = pace.ceiling * 0.9;\n  if (pace.cap >= limit) {\n    // Held steady at the ceiling for a long while: it may have been set by\n    // a passing slowdown, so lift it a step and try again.\n    pace.ceilingWindows += STEADY_WINDOWS;\n    if (pace.ceilingWindows < CEILING_WINDOWS) {\n      return;\n    }\n    pace.ceilingWindows = 0;\n    pace.ceiling *= 1.15;\n  }\n  pace.cap = Math.min(pace.cap * 1.2, pace.ceiling * 0.9);\n  scheduleContexts();\n}\n\nfunction observeDisplayInterval(interval: number) {\n  if (interval < MIN_DISPLAY_MS || interval > MAX_DISPLAY_MS) {\n    return;\n  }\n  pace.displaySamples.push(interval);\n  if (pace.displaySamples.length > DISPLAY_SAMPLES) {\n    pace.displaySamples.shift();\n  }\n  if (pace.displaySamples.length >= DISPLAY_SAMPLES / 2) {\n    // The low quartile tracks the fastest cadence while rejecting a dropped\n    // frame, and the rolling window relearns after a monitor/VRR change.\n    const sorted = [...pace.displaySamples].sort((a, b) => a - b);\n    pace.targetMs =\n      sorted[Math.floor((sorted.length - 1) * 0.25)] ?? DEFAULT_FRAME_MS;\n  }\n}\n\n/** Mounts call this on every animated rAF tick; a shared tick counts once. */\nexport function noteFrame(now: number): void {\n  const last = pace.lastTick;\n  if (now === last) {\n    return;\n  }\n  pace.lastTick = now;\n  if (last === null) {\n    return;\n  }\n  const interval = now - last;\n  const framePaintMs = pendingFramePaintMs;\n  pendingFramePaintMs = 0;\n  if (interval > MAX_INTERVAL_MS) {\n    pace.intervals = [];\n    pace.displaySamples = [];\n    pace.targetMs = DEFAULT_FRAME_MS;\n    return;\n  }\n  if (!pace.suppressDisplayLearning) observeDisplayInterval(interval);\n  if (pace.warmup > 0) {\n    pace.warmup -= 1;\n    if (pace.warmup === 0) pace.suppressDisplayLearning = false;\n    return;\n  }\n  // A visible animation can be throttled to a low VRR cadence while its\n  // paint work is idle. Do not call that a slowdown; heavy paint is judged.\n  if (\n    interval > pace.targetMs * 2 &&\n    framePaintMs > 0 &&\n    framePaintMs < pace.targetMs * 0.75\n  ) {\n    pace.intervals = [];\n    return;\n  }\n  pace.intervals.push(interval);\n  if (pace.intervals.length >= PACE_WINDOW) {\n    const total = pace.intervals.reduce((sum, ms) => sum + ms, 0);\n    judgePace(total / pace.intervals.length);\n    pace.intervals = [];\n  }\n}\n\nfunction run() {\n  frame = 0;\n  const width = window.innerWidth;\n  const height = window.innerHeight;\n  const margin = height * APPROACH_MARGIN;\n  const ranked: { slot: ContextSlot; distance: number }[] = [];\n  for (const [slot, state] of slots) {\n    const rect = slot.element.getBoundingClientRect();\n    const distance = distanceToViewport(rect, width, height);\n    const hasArea = rect.width > 0 && rect.height > 0;\n    const visible = hasArea && distance === 0;\n    if (visible !== state.visible) {\n      state.visible = visible;\n      slot.setVisible(visible);\n    }\n    // An invisible primary cannot paint a smaller surface to make room for\n    // new thumbnails. Release its large WebGPU lease until it is visible.\n    const invisiblePrimary =\n      !visible && slot.primary() && slot.backend() === \"webgpu\";\n    if (hasArea && distance <= margin && !invisiblePrimary) {\n      ranked.push({ distance, slot });\n    }\n  }\n  ranked.sort((a, b) => a.distance - b.distance);\n  // Each backend has its own budget (WebGL contexts, WebGPU surfaces), so on\n  // a mixed page neither starves the other; nearest first within each. A\n  // backend with more near gradients than its budget keeps one back to paint\n  // still frames for the rest. The pixel budget below is shared by both.\n  const limits: Record<BackendName, number> = {\n    webgl2: MAX_LIVE_CONTEXTS,\n    webgpu: MAX_WEBGPU_SURFACES,\n  };\n  const near: Record<BackendName, number> = { webgl2: 0, webgpu: 0 };\n  const backends = new Map(ranked.map(({ slot }) => [slot, slot.backend()]));\n  for (const name of backends.values()) {\n    near[name] += 1;\n  }\n  const budget = (name: BackendName) =>\n    near[name] > limits[name] ? limits[name] - 1 : limits[name];\n  const granted: Record<BackendName, number> = { webgl2: 0, webgpu: 0 };\n  const wanted = new Set<ContextSlot>();\n  const leftover: ContextSlot[] = [];\n  for (const { slot } of ranked) {\n    const name = backends.get(slot) ?? \"webgl2\";\n    if (granted[name] < budget(name)) {\n      granted[name] += 1;\n      wanted.add(slot);\n    } else {\n      leftover.push(slot);\n    }\n  }\n  // Release first so the budget is free before granting.\n  for (const [slot, state] of slots) {\n    if (state.live && !wanted.has(slot)) {\n      state.live = false;\n      slot.revoke();\n    }\n  }\n  wantedSlots = wanted;\n  // Apply the reservation before admission, so a full-size pending surface\n  // does not get denied forever beside an already-grown primary.\n  assignQuality();\n  for (const slot of wanted) {\n    const state = slots.get(slot);\n    if (state && !state.live) {\n      state.live = slot.grant();\n    }\n  }\n  for (const slot of leftover) {\n    slot.paintStill();\n  }\n  trimContexts(granted.webgl2 + (near.webgl2 > limits.webgl2 ? 1 : 0));\n  trimSurfaces(granted.webgpu + (near.webgpu > limits.webgpu ? 1 : 0));\n  assignQuality();\n}\n\n/** Re-ranks on the next animation frame. Cheap to call often. */\nexport function scheduleContexts(): void {\n  if (frame === 0 && typeof window !== \"undefined\") {\n    frame = window.requestAnimationFrame(run);\n  }\n}\n\n/** Relearns the display cadence after a visibility, resize, or display change. */\nexport function relearnDisplayRate(): void {\n  pace.displaySamples = [];\n  pace.targetMs = DEFAULT_FRAME_MS;\n  pace.intervals = [];\n}\n\nfunction onWindowResize() {\n  relearnDisplayRate();\n  pendingFramePaintMs = 0;\n  scheduleContexts();\n}\n\nonPoolChange(scheduleContexts);\nonWebGPUChange(scheduleContexts);\n\n/** A gradient lost its context (the pool already ended the lease). */\nexport function slotLostContext(slot: ContextSlot): void {\n  const state = slots.get(slot);\n  if (state) {\n    state.live = false;\n  }\n  scheduleContexts();\n}\n\nfunction listen(on: boolean) {\n  if (on === listening) {\n    return;\n  }\n  listening = on;\n  if (on) {\n    window.addEventListener(\"scroll\", scheduleContexts, {\n      capture: true,\n      passive: true,\n    });\n    window.addEventListener(\"scroll\", noteScroll, {\n      capture: true,\n      passive: true,\n    });\n    window.addEventListener(\"resize\", onWindowResize, { passive: true });\n    observer = new IntersectionObserver(scheduleContexts, {\n      rootMargin: `${APPROACH_MARGIN * 100}% 0px`,\n    });\n    for (const slot of slots.keys()) {\n      observer.observe(slot.element);\n    }\n  } else {\n    window.removeEventListener(\"scroll\", scheduleContexts, { capture: true });\n    window.removeEventListener(\"scroll\", noteScroll, { capture: true });\n    window.removeEventListener(\"resize\", onWindowResize);\n    observer?.disconnect();\n    observer = null;\n    window.cancelAnimationFrame(frame);\n    frame = 0;\n  }\n}\n\nexport function registerSlot(slot: ContextSlot): void {\n  slots.set(slot, {\n    live: false,\n    quality: { halfRate: false, scale: 1 },\n    visible: false,\n  });\n  listen(true);\n  observer?.observe(slot.element);\n  scheduleContexts();\n}\n\nexport function unregisterSlot(slot: ContextSlot): void {\n  if (!slots.delete(slot)) {\n    return;\n  }\n  observer?.unobserve(slot.element);\n  if (slots.size === 0) {\n    listen(false);\n    trimContexts(0);\n    trimSurfaces(0);\n  } else {\n    scheduleContexts();\n  }\n}\n\n/** Changes the per-frame pixel budget (Infinity turns it off). For tuning and the engine lab. */\nexport function setPixelBudget(pixels: number): void {\n  pixelBudget = pixels > 0 ? pixels : PIXEL_BUDGET;\n  scheduleContexts();\n}\n\n/** The governor's state. For tests and the engine lab. */\nexport function paceStats(): {\n  /** Most pixels per frame; Infinity until frames have been slow. */\n  cap: number;\n  /** Current rolling display interval estimate in milliseconds. */\n  targetMs: number;\n  /** Ignoring ticks after the animating set or its quality changed. */\n  warmingUp: boolean;\n} {\n  return { cap: pace.cap, targetMs: pace.targetMs, warmingUp: pace.warmup > 0 };\n}\n\n/** Forgets what the governor learned. For tests and the engine lab. */\nexport function resetPace(): void {\n  pace.cap = Number.POSITIVE_INFINITY;\n  pace.ceiling = Number.POSITIVE_INFINITY;\n  pace.ceilingWindows = 0;\n  pace.lastTick = null;\n  pace.suppressDisplayLearning = false;\n  relearnDisplayRate();\n  primaryBudget = PRIMARY_PIXEL_BUDGET;\n  scrolling = false;\n  if (\n    typeof window !== \"undefined\" &&\n    typeof window.clearTimeout === \"function\"\n  ) {\n    window.clearTimeout(scrollIdleTimer);\n  }\n  restartPace();\n  scheduleContexts();\n}\n\n/** Counts for tests and the engine lab. */\nexport function contextStats(): {\n  /** WebGL contexts that exist right now, never more than MAX_LIVE_CONTEXTS. */\n  contexts: number;\n  /** WebGPU surfaces that exist right now, never more than MAX_WEBGPU_SURFACES. */\n  surfaces: number;\n  /** Animating gradients per backend. */\n  liveByBackend: Record<BackendName, number>;\n  /** Gradients currently animating with a leased context. */\n  live: number;\n  mounted: number;\n  /** Drawing-buffer pixels rendered per frame by animating gradients. */\n  pixelsPerFrame: number;\n  halfRate: boolean;\n} {\n  let live = 0;\n  let pixelsPerFrame = 0;\n  let halfRate = false;\n  const liveByBackend: Record<BackendName, number> = { webgl2: 0, webgpu: 0 };\n  for (const [slot, state] of slots) {\n    if (state.live) {\n      live += 1;\n      liveByBackend[slot.backend()] += 1;\n    }\n    if (state.live && state.visible) {\n      pixelsPerFrame += slot.pixels() * state.quality.scale ** 2;\n      halfRate ||= state.quality.halfRate;\n    }\n  }\n  return {\n    contexts: liveContextCount(),\n    halfRate,\n    live,\n    liveByBackend,\n    mounted: slots.size,\n    pixelsPerFrame: Math.round(pixelsPerFrame),\n    surfaces: webgpuStats().surfaces,\n  };\n}\n\nlet paintMs = 0;\nlet pendingFramePaintMs = 0;\nlet paintCount = 0;\n\n/** Called by mounts with the time one animated frame took to render and copy. */\nexport function recordPaint(ms: number): void {\n  paintMs += ms;\n  pendingFramePaintMs += ms;\n  paintCount += 1;\n}\n\n/** Paint time totals since the last call, then resets them. For the engine lab. */\nexport function takePaintStats(): { paints: number; ms: number } {\n  const stats = { ms: paintMs, paints: paintCount };\n  paintMs = 0;\n  paintCount = 0;\n  return stats;\n}\n\nfunction engineStats(): EngineStats {\n  let scaleTotal = 0;\n  let scaleCount = 0;\n  let halfRate = false;\n  for (const [, state] of slots) {\n    if (state.live && state.visible) {\n      scaleTotal += state.quality.scale;\n      scaleCount += 1;\n      halfRate ||= state.quality.halfRate;\n    }\n  }\n  return {\n    animatingMounts: animatingCount,\n    fpsTier: halfRate ? \"half\" : \"full\",\n    gpuTimeMs: null,\n    mounted: slots.size,\n    paceCap: pace.cap,\n    rafIntervals: pace.intervals.slice(),\n    renderScale: scaleCount === 0 ? 1 : scaleTotal / scaleCount,\n    renderedPixels: Math.round(renderedPixels),\n    scrolling,\n  };\n}\n\nif (typeof globalThis.window !== \"undefined\") {\n  globalThis.window.__gcnEngineStats = engineStats;\n}\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/scheduler.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/aurora.ts",
      "content": "import type { GradientKindDefinition } from \"../kind\";\nimport { pick } from \"../kind\";\n\nexport const aurora: GradientKindDefinition = {\n  defaults: {\n    background: \"#03050b\",\n    blur: 0.35,\n    colors: [\"#a0f0c8\", \"#3fb5a3\", \"#5147b6\", \"#b25c9c\"],\n    dither: { cell: 3, enabled: false, levels: 8 },\n    grain: 0.1,\n    interaction: { pointer: 0.2, scroll: 0.2 },\n    loopSeconds: 18,\n    scale: 1,\n    seed: 3,\n    speed: 0.7,\n    warp: 0.5,\n  },\n  description: \"Folded curtains of light hanging over a night sky.\",\n  fallbackLayers: (colors) => [\n    ...colors.map(\n      (_, i) =>\n        `radial-gradient(30% 55% at ${15 + (70 * i) / Math.max(1, colors.length - 1)}% 30%, color-mix(in oklab, ${pick(colors, i)} 75%, transparent) 0%, transparent 70%)`,\n    ),\n    `linear-gradient(180deg, transparent 35%, color-mix(in oklab, ${pick(colors, 0)} 45%, transparent) 58%, transparent 80%)`,\n  ],\n  glsl: `\n// One curtain sheet. Returns its intensity and the height above its hem (0..1).\nvec2 auroraSheet(vec2 p, float layer, float hem0, bool detail) {\n  float x = p.x * u_scale;\n  // Folds sway the sheet sideways, more so higher up.\n  float fold = flowNoise(vec2(x * 0.5, p.y * 0.25 + layer), layer);\n  float xf = x + (0.1 + 0.3 * u_warp) * fold;\n  float hem = hem0 + 0.24 * flowNoise(vec2(xf * 0.6, layer * 3.1), layer + 1.0)\n    + 0.1 * sin(x * 1.2 + layer) + 0.06 * fold + 0.08 * x * x;\n  float rise = p.y - hem;\n  float up = exp(-max(rise, 0.0) * (2.8 - 1.0 * u_blur));\n  float down = exp(min(rise, 0.0) * (9.0 - 5.0 * u_blur));\n  // Rays: fine across the sheet, stretched along it.\n  float n = 0.65 * flowNoise(vec2(xf * 4.0, p.y * 0.15), layer + 2.0);\n  if (detail) {\n    n += 0.35 * flowNoise(vec2(xf * 11.0, p.y * 0.3), layer + 3.0);\n  }\n  float rays = mix(1.0, 0.6 + 0.55 * n, 0.85 - 0.45 * u_blur);\n  // The sheet thins where it folds edge-on.\n  float density = 0.45 + 0.55 * smoothstep(-0.6, 0.6, fold);\n  return vec2(up * down * rays * density, clamp(rise / 0.75, 0.0, 1.0));\n}\n\nvec3 kindColor(vec2 p, vec2 uv) {\n  vec2 h = frameHalf();\n  vec3 lab = u_bg;\n  lab.x += 0.035 * smoothstep(0.3, -h.y, p.y);\n  vec2 back = auroraSheet(p * vec2(0.75, 1.0) + vec2(0.9, 0.0), 11.0, -0.02, false);\n  vec2 front = auroraSheet(p, 13.0, -0.3, true);\n  lab = labMix(lab, ramp(0.3 + 0.7 * back.y), clamp(back.x * 0.35, 0.0, 1.0));\n  lab = labMix(lab, ramp(front.y), clamp(front.x * 1.45, 0.0, 1.0));\n  // A bright hem, and the light it throws onto the horizon.\n  lab.x += 0.12 * front.x * (1.0 - front.y);\n  float horizon = exp(-(p.y + h.y) * 5.0) * (0.5 + 0.5 * front.x);\n  lab = labMix(lab, paletteColor(1), clamp(horizon * 0.2, 0.0, 1.0));\n  lab.x *= vignette(p, 0.3);\n  return filmGrade(lab);\n}\n`,\n  wgsl: () => import(\"./wgsl/aurora\").then((module) => module.wgsl),\n  label: \"Aurora\",\n  name: \"aurora\",\n};\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/aurora.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/beam.ts",
      "content": "import type { GradientKindDefinition } from \"../kind\";\nimport { pick } from \"../kind\";\n\nexport const beam: GradientKindDefinition = {\n  defaults: {\n    background: \"#02030a\",\n    blur: 0.35,\n    colors: [\"#f4f7ff\", \"#8fb4ff\", \"#3d5bff\", \"#1a1660\"],\n    dither: { cell: 3, enabled: false, levels: 8 },\n    grain: 0.2,\n    interaction: { pointer: 0.15, scroll: 0.1 },\n    loopSeconds: 14,\n    scale: 1,\n    seed: 2,\n    speed: 0.6,\n    warp: 0.6,\n  },\n  description:\n    \"A cone of streaked light thrown from a source on the edge of the frame.\",\n  fallbackLayers: (colors) => [\n    `radial-gradient(60% 90% at 50% 100%, color-mix(in oklab, ${pick(colors, 0)} 80%, transparent) 0%, color-mix(in oklab, ${pick(colors, 1)} 55%, transparent) 18%, color-mix(in oklab, ${pick(colors, 2)} 30%, transparent) 45%, transparent 75%)`,\n    `conic-gradient(from 315deg at 50% 100%, transparent 0deg, color-mix(in oklab, ${pick(colors, 3)} 25%, transparent) 45deg, transparent 90deg)`,\n  ],\n  glsl: `\n// Light from a point on or beyond the frame edge, spread into a cone of\n// rays. The rays are noise sampled across the cone's angle, so they are\n// fine across and long along the beam. scale widens the cone; warp sets\n// ray contrast.\n\n// One beam. Returns glow, the palette position, and how much of the light\n// is the white-hot core and needle.\nvec3 beamLight(vec2 p, vec2 source, float aim, float width, float reach, float layer, float omni) {\n  vec2 axis = vec2(sin(aim), cos(aim));\n  vec2 v = p - source;\n  float dist = length(v);\n  float along = dot(v, axis);\n  float across = axis.x * v.y - axis.y * v.x;\n  float ang = atan(across, max(along, 1e-3));\n  float u = ang / width;\n  float forward = smoothstep(-0.02, 0.06, along);\n  float cone = exp(-u * u) * forward;\n\n  // Rays: two scales of noise across the cone, stretched along it. A flare\n  // rays out all round, so it samples on the unit circle instead, which\n  // has no seam behind the source.\n  vec2 dir = v / max(dist, 1e-4);\n  vec2 coarseAt = omni > 0.5 ? dir * 3.2 + vec2(dist * 0.35, 0.0) : vec2(u * 2.2, dist * 0.35);\n  vec2 fineAt = omni > 0.5 ? dir * 9.0 + vec2(13.0, dist * 0.9) : vec2(u * 6.0 + 13.0, dist * 0.9);\n  float coarse = flowNoise(coarseAt, layer);\n  float fine = flowNoise(fineAt, layer + 1.0);\n  cone = mix(cone, 0.55 + 0.45 * exp(-u * u), omni);\n  forward = mix(forward, 1.0, omni);\n  float fineAmount = 0.55 * (1.0 - 0.6 * u_blur);\n  float rays = 0.5 + 0.5 * (coarse + fineAmount * fine) / (1.0 + fineAmount);\n  rays = mix(1.0, smoothstep(0.1, 0.95, rays) * 1.5, u_warp);\n\n  float fall = exp(-dist / reach);\n  float core = exp(-dist / (0.05 + 0.05 * u_blur));\n  // A hairline down the axis, the brightest ray.\n  float needle = exp(-pow(across / (0.0035 + 0.01 * u_blur), 2.0)) * exp(-dist / (0.6 * reach)) * smoothstep(0.0, 0.03, along) * u_warp * (1.0 - 0.5 * omni);\n  float haze = exp(-dist / (0.4 + 0.5 * u_blur));\n  // A broad, soft fill under the rays gives the beam volume.\n  float fill = mix(exp(-u * u * 0.35), 1.0, omni) * forward * fall;\n\n  float glow = cone * fall * (0.2 + 0.8 * rays) + 0.22 * fill + 0.85 * core + 0.55 * needle + 0.08 * haze;\n  // Near the source the light is colour 0; colour takes over along the\n  // beam and at the cone's edges.\n  float t = clamp(dist / (reach * 1.4) + 0.35 * abs(u) * (1.0 - omni) - 0.25 * core, 0.0, 1.0);\n  return vec3(glow, t, clamp(core + needle, 0.0, 1.0));\n}\n\nvec3 kindColor(vec2 p, vec2 uv) {\n  float lightBg = smoothstep(0.55, 0.85, u_bg.x);\n  vec2 h = frameHalf();\n  // The seed picks the source: bottom centre, a bottom corner, the top\n  // edge, a top corner, a side edge, two crossing beams from the bottom\n  // corners, a source far below or above the frame, so only its rays\n  // reach in, or a flare inside the frame raying out all round.\n  float framing = floor(fract(u_seed.x * 0.0731 + 0.5) * 9.0);\n  float side = sign(u_seed.y + 0.01);\n  vec2 source = vec2(0.0, -h.y - 0.02);\n  float aim = 0.0;\n  float width = 0.3 * u_scale;\n  float reach = 0.55 + 0.6 * u_scale;\n  if (framing == 1.0) {\n    source = vec2(-side * (h.x - 0.06), -h.y - 0.02);\n    aim = side * 0.62;\n  } else if (framing == 2.0) {\n    source = vec2(0.0, h.y + 0.02);\n    aim = 3.14159265;\n  } else if (framing == 3.0) {\n    source = vec2(-side * (h.x - 0.1), h.y + 0.02);\n    aim = 3.14159265 - side * 0.5;\n  } else if (framing == 4.0) {\n    source = vec2(-side * (h.x + 0.02), -0.12);\n    aim = side * 1.32;\n  } else if (framing == 5.0) {\n    source = vec2(-(h.x - 0.12), -h.y - 0.02);\n    aim = 0.42;\n    width *= 0.7;\n  } else if (framing == 6.0) {\n    source = vec2(0.3 * h.x * side, -h.y - 1.0);\n    aim = -side * 0.12;\n    width *= 0.45;\n    reach *= 2.4;\n  } else if (framing == 7.0) {\n    source = vec2(0.3 * h.x * side, h.y + 1.0);\n    aim = 3.14159265 + side * 0.15;\n    width *= 0.45;\n    reach *= 2.4;\n  } else if (framing == 8.0) {\n    source = vec2(0.22 * h.x * side, 0.04);\n    aim = seedAngle();\n    width = 0.6 * u_scale;\n    reach = 0.3 + 0.3 * u_scale;\n  }\n  // The cone sways a little through the loop.\n  float sway = 0.22 * u_loop.y;\n  vec3 light = beamLight(p, source, aim + sway, width, reach, 1.0, framing == 8.0 ? 1.0 : 0.0);\n  if (framing == 5.0) {\n    // The second beam mirrors the first and sways the other way.\n    vec3 twin = beamLight(p, vec2(-source.x, source.y), -aim - sway, width, reach, 4.0, 0.0);\n    float total = max(light.x + twin.x, 1e-4);\n    light = vec3(light.x + twin.x, (light.x * light.y + twin.x * twin.y) / total, max(light.z, twin.z));\n  }\n  float glow = light.x;\n\n  vec3 col = ramp(light.y);\n  col = labMix(col, paletteColor(0), light.z);\n  vec3 lab = labMix(u_bg, col, clamp(glow, 0.0, 1.0));\n  lab.x += 0.08 * max(glow - 0.9, 0.0) * (1.0 - lightBg);\n  return filmGrade(lab);\n}\n`,\n  wgsl: () => import(\"./wgsl/beam\").then((module) => module.wgsl),\n  label: \"Beam\",\n  name: \"beam\",\n};\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/beam.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/chrome.ts",
      "content": "import type { GradientKindDefinition } from \"../kind\";\nimport { pick } from \"../kind\";\n\n/**\n * Liquid chrome filling the frame. A slow, flowing surface reflects a\n * studio of soft light bands, so highlights run along the folds and the\n * troughs fall to black. Colour 1 is the studio light the metal mostly\n * shows, colour 2 the hot highlight, colour 3 an optional cool rim seen at\n * grazing angles. `scale` sets the size of the swells, `warp` how much the\n * surface folds, `blur` softens the reflections.\n */\nexport const chrome: GradientKindDefinition = {\n  defaults: {\n    background: \"#050203\",\n    blur: 0.2,\n    colors: [\"#e0202e\", \"#ffd6b8\", \"#4fe3f0\"],\n    dither: { cell: 3, enabled: false, levels: 8 },\n    grain: 0.06,\n    interaction: { pointer: 0.2, scroll: 0.2 },\n    loopSeconds: 24,\n    scale: 1,\n    seed: 6,\n    speed: 0.5,\n    warp: 0.5,\n  },\n  description: \"Liquid metal folding slowly under studio light.\",\n  fallbackLayers: (colors) => [\n    `radial-gradient(60% 30% at 40% 38%, color-mix(in oklab, ${pick(colors, 1)} 70%, transparent), transparent 70%)`,\n    `linear-gradient(160deg, transparent 20%, ${pick(colors, 0)} 45%, transparent 60%, color-mix(in oklab, ${pick(colors, 0)} 60%, transparent) 75%, transparent 90%)`,\n    `linear-gradient(20deg, transparent 60%, color-mix(in oklab, ${pick(colors, 2)} 35%, transparent) 70%, transparent 78%)`,\n  ],\n  glsl: `\n// Height of the metal: long folds running one way, their crests bent by a\n// slow noise field so they curve and bunch like draped cloth, with a faint\n// cross fold. Ridges rather than domes, so reflections stream along the\n// folds instead of ringing. The folds roll a whole wavelength each loop.\nfloat chromeHeight(vec2 q, vec2 t1, vec2 t2) {\n  float bendBy = (0.9 + 1.6 * u_warp) * flowNoise(q * vec2(0.35, 0.55), 2.0);\n  float a = 2.1 * q.y + bendBy;\n  float c = 1.3 * q.x + 0.4 * bendBy + 1.3;\n  return sin(a) * t1.x - cos(a) * t1.y\n    + 0.2 * (sin(2.0 * a + 0.9) * t2.x - cos(2.0 * a + 0.9) * t2.y) * (1.0 - 0.6 * u_blur)\n    + 0.15 * (sin(c) * t2.x - cos(c) * t2.y);\n}\n\n// The studio as seen in a reflection direction: a dark floor with a soft\n// bounce and a light behind the camera, a dark horizon line, a bright sky with a cool band and a hot key, and darker ceiling.\nvec3 chromeStudio(vec3 r, float sa) {\n  float t = r.y * 0.9 + 0.3 * r.x * cos(sa);\n  float soft = 0.04 + 0.12 * u_blur;\n  vec3 floorC = labMix(u_bg, paletteColor(0), 0.08 + 0.5 * smoothstep(0.9, 1.0, r.z));\n  // A broad, dimmer bounce off the floor, so downward slopes still read as metal.\n  floorC = labMix(floorC, paletteColor(0), 0.7 * exp(-pow((t + 0.5) / (0.18 + soft), 2.0)));\n  vec3 env = labMix(floorC, paletteColor(0), smoothstep(0.1, 0.3, t));\n  float horizon = exp(-pow((t - 0.12) / (soft * 1.3), 2.0));\n  env = labMix(env, u_bg, 0.92 * horizon);\n  float cool = exp(-pow((t - 0.4) / (soft * 0.9), 2.0));\n  env = labMix(env, paletteColor(u_count > 2 ? 2 : 1), 0.55 * cool);\n  float key = exp(-pow((t - 0.58) / soft, 2.0));\n  env = labMix(env, paletteColor(1), key);\n  env.x += 0.16 * key * key;\n  env = labMix(env, u_bg, 0.6 * smoothstep(0.75, 1.0, t));\n  return env;\n}\n\nvec3 kindColor(vec2 p, vec2 uv) {\n  float sa = seedAngle();\n  vec2 t1 = loopTurn();\n  vec2 t2 = vec2(t1.x * t1.x - t1.y * t1.y, 2.0 * t1.x * t1.y);\n  vec2 q = rot2(0.6 * sin(sa) + 0.3) * p * 1.75 * u_scale + vec2(1.7, -0.9) * cos(sa);\n\n  float e = 0.004;\n  float h = chromeHeight(q, t1, t2);\n  vec2 g = vec2(chromeHeight(q + vec2(e, 0.0), t1, t2) - h, chromeHeight(q + vec2(0.0, e), t1, t2) - h) / e;\n  vec3 n = normalize(vec3(-g * 0.6 / sqrt(u_scale), 1.0));\n  vec3 r = reflect(vec3(0.0, 0.0, -1.0), n);\n\n  vec3 lab = chromeStudio(r, sa);\n  // Low ground sits in shadow.\n  lab = labMix(lab, u_bg, 0.3 * (1.0 - smoothstep(-1.8, -0.6, h)));\n  lab.x *= vignette(p, 0.35);\n  return filmGrade(lab);\n}\n`,\n  label: \"Chrome\",\n  name: \"chrome\",\n  wgsl: () => import(\"./wgsl/chrome\").then((module) => module.wgsl),\n};\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/chrome.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/common.ts",
      "content": "/**\n * Shared GLSL for every kind. A kind supplies `vec3 kindColor(vec2 p, vec2 uv)`\n * returning OKLab; the prelude gives it noise, palette helpers and coordinates,\n * and the postlude converts to sRGB and applies grain and dither.\n *\n * Coordinates are always derived from the full image (u_full) plus the tile\n * origin (u_tile), so a tiled render matches a full render pixel for pixel.\n * Motion only ever reads u_loop, a point on a circle, so frames repeat exactly\n * every loop.\n */\n\nexport const vertexShader = `#version 300 es\nin vec2 a_position;\nvoid main() {\n  gl_Position = vec4(a_position, 0.0, 1.0);\n}\n`;\n\nexport const fragmentPrelude = `#version 300 es\nprecision highp float;\nprecision highp int;\n\nuniform vec2 u_full;       // full image size in pixels\nuniform vec4 u_tile;       // tile x, y (top-left origin), width, height\nuniform vec2 u_loop;       // (cos, sin)(phase) * speed * radius\nuniform vec2 u_seed;       // seed offset in noise space\nuniform float u_scale;\nuniform float u_warp;\nuniform float u_blur;\nuniform float u_grain;\nuniform float u_frame;     // grain seed\nuniform vec3 u_dither;     // enabled, cell, levels\nuniform vec3 u_colors[6];  // OKLab\nuniform int u_count;\nuniform vec3 u_bg;         // OKLab\nuniform vec3 u_pointer;    // x, y in image uv (top-left origin), influence\nuniform float u_scroll;    // smoothed scroll velocity * influence\n\nout vec4 outColor;\n\n// 4D simplex noise. Ian McEwan, Stefan Gustavson, Ashima Arts (MIT).\nvec4 mod289(vec4 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }\nfloat mod289(float x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }\nvec4 permute(vec4 x) { return mod289(((x * 34.0) + 10.0) * x); }\nfloat permute(float x) { return mod289(((x * 34.0) + 10.0) * x); }\nvec4 taylorInvSqrt(vec4 r) { return 1.79284291400159 - 0.85373472095314 * r; }\nfloat taylorInvSqrt(float r) { return 1.79284291400159 - 0.85373472095314 * r; }\nvec4 grad4(float j, vec4 ip) {\n  const vec4 ones = vec4(1.0, 1.0, 1.0, -1.0);\n  vec4 p, s;\n  p.xyz = floor(fract(vec3(j) * ip.xyz) * 7.0) * ip.z - 1.0;\n  p.w = 1.5 - dot(abs(p.xyz), ones.xyz);\n  s = vec4(lessThan(p, vec4(0.0)));\n  p.xyz = p.xyz + (s.xyz * 2.0 - 1.0) * s.www;\n  return p;\n}\nfloat snoise(vec4 v) {\n  const vec4 C = vec4(0.138196601125011, 0.276393202250021, 0.414589803375032, -0.447213595499958);\n  vec4 i = floor(v + dot(v, vec4(0.309016994374947451)));\n  vec4 x0 = v - i + dot(i, C.xxxx);\n  vec4 i0;\n  vec3 isX = step(x0.yzw, x0.xxx);\n  vec3 isYZ = step(x0.zww, x0.yyz);\n  i0.x = isX.x + isX.y + isX.z;\n  i0.yzw = 1.0 - isX;\n  i0.y += isYZ.x + isYZ.y;\n  i0.zw += 1.0 - isYZ.xy;\n  i0.z += isYZ.z;\n  i0.w += 1.0 - isYZ.z;\n  vec4 i3 = clamp(i0, 0.0, 1.0);\n  vec4 i2 = clamp(i0 - 1.0, 0.0, 1.0);\n  vec4 i1 = clamp(i0 - 2.0, 0.0, 1.0);\n  vec4 x1 = x0 - i1 + C.xxxx;\n  vec4 x2 = x0 - i2 + C.yyyy;\n  vec4 x3 = x0 - i3 + C.zzzz;\n  vec4 x4 = x0 + C.wwww;\n  i = mod289(i);\n  float j0 = permute(permute(permute(permute(i.w) + i.z) + i.y) + i.x);\n  vec4 j1 = permute(permute(permute(permute(\n      i.w + vec4(i1.w, i2.w, i3.w, 1.0))\n    + i.z + vec4(i1.z, i2.z, i3.z, 1.0))\n    + i.y + vec4(i1.y, i2.y, i3.y, 1.0))\n    + i.x + vec4(i1.x, i2.x, i3.x, 1.0));\n  vec4 ip = vec4(1.0 / 294.0, 1.0 / 49.0, 1.0 / 7.0, 0.0);\n  vec4 p0 = grad4(j0, ip);\n  vec4 p1 = grad4(j1.x, ip);\n  vec4 p2 = grad4(j1.y, ip);\n  vec4 p3 = grad4(j1.z, ip);\n  vec4 p4 = grad4(j1.w, ip);\n  vec4 norm = taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));\n  p0 *= norm.x;\n  p1 *= norm.y;\n  p2 *= norm.z;\n  p3 *= norm.w;\n  p4 *= taylorInvSqrt(dot(p4, p4));\n  vec3 m0 = max(0.6 - vec3(dot(x0, x0), dot(x1, x1), dot(x2, x2)), 0.0);\n  vec2 m1 = max(0.6 - vec2(dot(x3, x3), dot(x4, x4)), 0.0);\n  m0 = m0 * m0;\n  m1 = m1 * m1;\n  return 49.0 * (dot(m0 * m0, vec3(dot(p0, x0), dot(p1, x1), dot(p2, x2)))\n    + dot(m1 * m1, vec2(dot(p3, x3), dot(p4, x4))));\n}\n\n// 2D simplex noise, same authors and licence. About a third of the cost of\n// snoise(vec4), so kinds use it for structure and keep the 4D noise for the\n// few places that need the field itself to morph.\nvec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }\nvec2 mod289(vec2 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }\nvec3 permute(vec3 x) { return mod289(((x * 34.0) + 10.0) * x); }\nfloat snoise2(vec2 v) {\n  const vec4 C = vec4(0.211324865405187, 0.366025403784439, -0.577350269189626, 0.024390243902439);\n  vec2 i = floor(v + dot(v, C.yy));\n  vec2 x0 = v - i + dot(i, C.xx);\n  vec2 i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);\n  vec4 x12 = x0.xyxy + C.xxzz;\n  x12.xy -= i1;\n  i = mod289(i);\n  vec3 p = permute(permute(i.y + vec3(0.0, i1.y, 1.0)) + i.x + vec3(0.0, i1.x, 1.0));\n  vec3 m = max(0.5 - vec3(dot(x0, x0), dot(x12.xy, x12.xy), dot(x12.zw, x12.zw)), 0.0);\n  m = m * m;\n  m = m * m;\n  vec3 x = 2.0 * fract(p * C.www) - 1.0;\n  vec3 h = abs(x) - 0.5;\n  vec3 ox = floor(x + 0.5);\n  vec3 a0 = x - ox;\n  m *= 1.79284291400159 - 0.85373472095314 * (a0 * a0 + h * h);\n  vec3 g;\n  g.x = a0.x * x0.x + h.x * x0.y;\n  g.yz = a0.yz * x12.xz + h.yz * x12.yw;\n  return 130.0 * dot(m, g);\n}\n\n// Time coordinates for a noise layer. Every layer moves on its own circle.\nvec2 loopAt(float layer) {\n  return u_loop + vec2(layer * 1.71, layer * -2.37);\n}\n\n// Looping noise: spatial position plus a point on the time circle.\nfloat loopNoise(vec2 p, float layer) {\n  return snoise(vec4(p + u_seed, loopAt(layer)));\n}\n\n// Three octaves; blur fades out the fine ones.\nfloat fbm(vec2 p, float layer) {\n  float fine = 1.0 - 0.85 * u_blur;\n  float sum = loopNoise(p, layer);\n  sum += 0.5 * fine * loopNoise(p * 2.03 + 17.1, layer + 0.5);\n  sum += 0.25 * fine * fine * loopNoise(p * 4.07 - 9.7, layer + 1.0);\n  return sum / (1.0 + 0.5 * fine + 0.25 * fine * fine);\n}\n\n// The loop point rotated per layer. Translating a field by it is seamless,\n// and layers drifting in different directions read as slow morphing.\nvec2 drift(float layer) {\n  float a = layer * 2.39996;\n  float c = cos(a);\n  float s = sin(a);\n  return mat2(c, s, -s, c) * u_loop;\n}\n\n// Cheap looping noise: a 2D field translated around the loop circle.\nfloat flowNoise(vec2 p, float layer) {\n  return snoise2(p + u_seed + drift(layer) + vec2(layer * 7.13, layer * 3.71));\n}\n\n// The loop angle as a unit vector, so waves can travel a whole period per\n// loop. Frozen when speed is 0.\nvec2 loopTurn() {\n  float r = length(u_loop);\n  return r > 1e-6 ? u_loop / r : vec2(1.0, 0.0);\n}\n\n// sin(a - angle), where cs = (cos, sin)(angle).\nfloat turnSin(float a, vec2 cs) {\n  return sin(a) * cs.x - cos(a) * cs.y;\n}\n\nmat2 rot2(float a) {\n  float c = cos(a);\n  float s = sin(a);\n  return mat2(c, s, -s, c);\n}\n\n// tanh that stays finite: some GPUs evaluate tanh(x) as a ratio of exps,\n// which is inf/inf = NaN for large x.\nfloat safeTanh(float x) {\n  return tanh(clamp(x, -9.0, 9.0));\n}\n\n// The brightest lightness and strongest chroma among the supplied colours.\nvec2 paletteRange() {\n  float l = u_bg.x;\n  float c = length(u_bg.yz);\n  for (int i = 0; i < 6; i++) {\n    if (i >= u_count) break;\n    l = max(l, u_colors[i].x);\n    c = max(c, length(u_colors[i].yz));\n  }\n  return vec2(l, c);\n}\n\n// Filmic grade in OKLab for the light a kind adds. It is an identity map for\n// anything inside the palette's own range, so supplied colours and theme\n// tokens render as chosen. Only highlights pushed past the brightest colour\n// get a soft shoulder, and only chroma pushed past both the most saturated\n// colour and a film-like cap (which eases off toward black and white) rolls off.\nvec3 filmGrade(vec3 lab) {\n  vec2 range = paletteRange();\n  float l = max(lab.x, 0.0);\n  float shoulder = max(range.x, 0.8);\n  if (l > shoulder) {\n    float room = max(1.0 - shoulder, 1e-3);\n    l = shoulder + room * safeTanh((l - shoulder) / room);\n  }\n  float c = length(lab.yz);\n  float cap = 0.05 + 0.9 * l * (1.0 - l) * (0.5 + 0.5 * l);\n  float knee = max(range.y, 0.6 * cap);\n  float top = max(cap, knee + 0.02);\n  float soft = c <= knee ? c : knee + (top - knee) * safeTanh((c - knee) / (top - knee));\n  float k = c > 1e-5 ? soft / c : 1.0;\n  return vec3(l, lab.yz * k);\n}\n\n// Darkens the corners in OKLab lightness; amount 0..1.\nfloat vignette(vec2 p, float amount) {\n  vec2 q = p / (0.5 * u_full / min(u_full.x, u_full.y));\n  return 1.0 - amount * smoothstep(0.35, 1.45, dot(q, q) * 0.55);\n}\n\n// Half the frame size in p units; the short side spans -0.5..0.5.\nvec2 frameHalf() {\n  return 0.5 * u_full / min(u_full.x, u_full.y);\n}\n\nfloat seedAngle() {\n  return fract(u_seed.x * 0.1371 + u_seed.y * 0.0713) * 6.28318530718;\n}\n\n// Mix in OKLab, then pull chroma back toward the endpoints so midpoints stay vivid.\nvec3 labMix(vec3 a, vec3 b, float t) {\n  vec3 m = mix(a, b, t);\n  float target = mix(length(a.yz), length(b.yz), t);\n  float current = length(m.yz);\n  if (current > 1e-4) {\n    m.yz *= mix(1.0, target / current, 0.75);\n  }\n  return m;\n}\n\nvec3 paletteColor(int i) {\n  return u_colors[clamp(i, 0, u_count - 1)];\n}\n\n// Smooth ramp through the palette, t in 0..1.\nvec3 ramp(float t) {\n  float x = clamp(t, 0.0, 1.0) * float(u_count - 1);\n  int i = int(floor(x));\n  float f = x - float(i);\n  f = f * f * (3.0 - 2.0 * f);\n  return labMix(paletteColor(i), paletteColor(i + 1), f);\n}\n\n// Pointer: a soft lens that pulls the field toward the cursor.\n// Scroll: velocity shears the field vertically.\nvec2 interact(vec2 p) {\n  vec2 half_ = frameHalf();\n  vec2 ptr = (u_pointer.xy - 0.5) * 2.0 * half_;\n  ptr.y = -ptr.y;\n  vec2 d = p - ptr;\n  float f = exp(-dot(d, d) * 5.0) * u_pointer.z;\n  p -= d * f * 0.45;\n  p.y += u_scroll * 0.08 * (0.6 + 0.4 * sin(p.x * 3.0));\n  return p;\n}\n`;\n\nexport const fragmentPostlude = `\nvec3 oklabToLinear(vec3 lab) {\n  float l = lab.x + 0.3963377774 * lab.y + 0.2158037573 * lab.z;\n  float m = lab.x - 0.1055613458 * lab.y - 0.0638541728 * lab.z;\n  float s = lab.x - 0.0894841775 * lab.y - 1.2914855480 * lab.z;\n  l = l * l * l;\n  m = m * m * m;\n  s = s * s * s;\n  return vec3(\n    4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,\n    -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,\n    -0.0041960863 * l - 0.7034186147 * m + 1.7076147010 * s\n  );\n}\n\nvec3 linearToSrgb(vec3 c) {\n  c = clamp(c, 0.0, 1.0);\n  vec3 lo = c * 12.92;\n  vec3 hi = 1.055 * pow(c, vec3(1.0 / 2.4)) - 0.055;\n  return mix(hi, lo, vec3(lessThanEqual(c, vec3(0.0031308))));\n}\n\nuint hashU(uint x) {\n  x ^= x >> 16;\n  x *= 0x7feb352du;\n  x ^= x >> 15;\n  x *= 0x846ca68bu;\n  x ^= x >> 16;\n  return x;\n}\n\nfloat hash01(uvec2 p, uint s) {\n  return float(hashU(p.x ^ hashU(p.y ^ hashU(s)))) / 4294967295.0;\n}\n\nconst float BAYER[16] = float[16](\n  0.0, 8.0, 2.0, 10.0,\n  12.0, 4.0, 14.0, 6.0,\n  3.0, 11.0, 1.0, 9.0,\n  15.0, 7.0, 13.0, 5.0\n);\n\nvoid main() {\n  vec2 px = vec2(u_tile.x + gl_FragCoord.x, u_tile.y + (u_tile.w - gl_FragCoord.y));\n  bool dither = u_dither.x > 0.5;\n  vec2 cell = floor(px / u_dither.y);\n  vec2 samplePx = dither ? (cell + 0.5) * u_dither.y : px;\n\n  vec2 uv = samplePx / u_full;\n  vec2 p = (samplePx - 0.5 * u_full) / min(u_full.x, u_full.y);\n  p.y = -p.y;\n  p = interact(p);\n\n  vec3 rgb = linearToSrgb(oklabToLinear(kindColor(p, uv)));\n\n  // Triangular, deterministic grain seeded by the frame. A trace stays on even\n  // at grain 0 to break up 8-bit banding.\n  uvec2 ip = uvec2(px);\n  uint frame = uint(u_frame);\n  float n = hash01(ip, frame * 2u + 1u) + hash01(ip, frame * 2u + 2u) - 1.0;\n  float lum = dot(rgb, vec3(0.2126, 0.7152, 0.0722));\n  float amp = u_grain * 0.2 * (0.55 + 0.9 * lum * (1.0 - lum)) + (dither ? 0.0 : 1.0 / 255.0);\n  rgb += n * amp;\n\n  if (dither) {\n    ivec2 b = ivec2(mod(cell, 4.0));\n    float threshold = (BAYER[b.y * 4 + b.x] + 0.5) / 16.0;\n    float steps = u_dither.z - 1.0;\n    rgb = floor(clamp(rgb, 0.0, 1.0) * steps + threshold) / steps;\n  }\n\n  outColor = vec4(clamp(rgb, 0.0, 1.0), 1.0);\n}\n`;\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/common.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/dither-burst.ts",
      "content": "import type { GradientKindDefinition } from \"../kind\";\nimport { stops } from \"../kind\";\n\n/**\n * One soft light drawn through ordered dither. The light is a single\n * structure (rays bursting from an edge, a horizon glowing up out of the\n * dark, a diagonal beam, or a bloom from a corner), and it is quantised per\n * sRGB channel in square cells, so ramps keep every hue in between and\n * mid-tones fizz with neighbouring colours. That is the difference from\n * dither-field and the Pro dither-gradient, which pick whole palette stops.\n *\n * The seed picks the structure, the side the light comes from, and the\n * threshold matrix (Bayer 8x8 or interleaved gradient noise, which reads\n * like blue noise). Colours run from the light's outer edge (first) to its\n * core (last); the background is the dark (or paper) it falls into.\n *\n * The dither is the kind's own look, always on: 3px cells and 12 steps per\n * channel. Switch the engine's dither on and it replaces this one, with its\n * own cell and levels, on the same soft light. `scale` sizes the light,\n * `warp` sets ray and edge contrast, `blur` its softness.\n *\n * Helpers are prefixed `db` and only depend on the prelude.\n */\nexport const ditherBurst: GradientKindDefinition = {\n  defaults: {\n    background: \"#030305\",\n    blur: 0.5,\n    colors: [\"#1b2cc1\", \"#3d7bff\", \"#bcd3ff\", \"#f6f4ef\"],\n    dither: { cell: 3, enabled: false, levels: 8 },\n    grain: 0,\n    interaction: { pointer: 0.15, scroll: 0 },\n    loopSeconds: 18,\n    scale: 1,\n    seed: 2,\n    speed: 0.5,\n    warp: 0.55,\n  },\n  description:\n    \"A soft burst of light resolved into crisp dither cells, every hue kept.\",\n  // The light rising from below, core colour at the bottom edge.\n  fallbackLayers: (colors) => [\n    `radial-gradient(90% 80% at 50% 108%, ${stops([...colors].reverse(), 6, 62)}, transparent 76%)`,\n  ],\n  glsl: `\nfloat dbBayer2(vec2 a) {\n  a = floor(a);\n  return fract(dot(a, vec2(0.5, a.y * 0.75)));\n}\n\nfloat dbBayer8(vec2 a) {\n  return dbBayer2(0.25 * a) * 0.0625 + dbBayer2(0.5 * a) * 0.25 + dbBayer2(a);\n}\n\n// Interleaved gradient noise (Jimenez 2014): ordered, but with no visible\n// period, so it reads like blue noise.\nfloat dbIgn(vec2 a) {\n  return fract(52.9829189 * fract(dot(floor(a), vec2(0.06711056, 0.00583715))));\n}\n\nvec3 dbLabToSrgb(vec3 lab) {\n  float l = lab.x + 0.3963377774 * lab.y + 0.2158037573 * lab.z;\n  float m = lab.x - 0.1055613458 * lab.y - 0.0638541728 * lab.z;\n  float s = lab.x - 0.0894841775 * lab.y - 1.2914855480 * lab.z;\n  vec3 lin = vec3(\n    4.0767416621 * l * l * l - 3.3077115913 * m * m * m + 0.2309699292 * s * s * s,\n    -1.2684380046 * l * l * l + 2.6097574011 * m * m * m - 0.3413193965 * s * s * s,\n    -0.0041960863 * l * l * l - 0.7034186147 * m * m * m + 1.7076147010 * s * s * s\n  );\n  lin = clamp(lin, 0.0, 1.0);\n  return mix(1.055 * pow(lin, vec3(1.0 / 2.4)) - 0.055, lin * 12.92, vec3(lessThanEqual(lin, vec3(0.0031308))));\n}\n\nvec3 dbSrgbToLab(vec3 c) {\n  vec3 lin = mix(pow((c + 0.055) / 1.055, vec3(2.4)), c / 12.92, vec3(lessThanEqual(c, vec3(0.04045))));\n  float l = 0.4122214708 * lin.r + 0.5363325363 * lin.g + 0.0514459929 * lin.b;\n  float m = 0.2119034982 * lin.r + 0.6806995451 * lin.g + 0.1073969566 * lin.b;\n  float s = 0.0883024619 * lin.r + 0.2817188376 * lin.g + 0.6299787005 * lin.b;\n  vec3 lms = pow(max(vec3(l, m, s), 0.0), vec3(1.0 / 3.0));\n  return vec3(\n    0.2104542553 * lms.x + 0.7936177850 * lms.y - 0.0040720468 * lms.z,\n    1.9779984951 * lms.x - 2.4285922050 * lms.y + 0.4505937099 * lms.z,\n    0.0259040371 * lms.x + 0.7827717662 * lms.y - 0.8086757660 * lms.z\n  );\n}\n\n// How far the palette strays from the background. A flat palette has\n// nothing to dither between, so it renders flat.\nfloat dbSpread() {\n  float d = 0.0;\n  for (int i = 0; i < 6; i++) {\n    if (i >= u_count) break;\n    d = max(d, length(u_colors[i] - u_bg));\n  }\n  return smoothstep(0.0, 0.04, d);\n}\n\n// The light's intensity at q: 0 is the background, 1 the core.\nfloat dbLight(vec2 q, vec2 h, float mode, float side) {\n  float s = 1.0 / u_scale;\n  float soft = 0.6 + 0.8 * u_blur;\n  if (mode < 1.0) {\n    // Burst: broad, blurred rays from a point just past one edge.\n    float a = 1.5708 + (side - 0.5) * 2.4;\n    vec2 src = vec2(cos(a), -abs(sin(a))) * h * vec2(1.0, 1.4) + 0.3 * drift(1.0);\n    vec2 d = q - src;\n    float r = length(d);\n    vec2 dir = d / max(r, 1e-4);\n    // Rays are noise on the unit circle, low in angle so they stay broad;\n    // they fade in away from the source so it never reads as a star.\n    float rays = 0.5 + 0.5 * flowNoise(dir * (1.6 + 1.4 * u_warp), 2.0);\n    rays = mix(rays, 0.5 + 0.5 * flowNoise(dir * 4.0 + 7.0, 3.0), 0.3);\n    float ray = mix(1.0, 0.25 + 1.2 * rays * rays, (0.35 + 0.55 * u_warp) * smoothstep(0.05, 0.7, r));\n    float body = exp(-r / (0.62 * s * soft));\n    return 1.15 * body * ray + 0.3 * exp(-r / (0.2 * s * soft));\n  }\n  if (mode < 2.0) {\n    // Horizon: a huge disc rising from below, glowing into the dark.\n    float tilt = (side - 0.5) * 0.5;\n    vec2 t = rot2(tilt) * q;\n    float radius = 1.7 * s;\n    float lift = (0.12 + 0.18 * u_scale) * h.y + 0.1 * flowNoise(vec2(0.4, 0.9), 1.0);\n    vec2 centre = vec2(0.45 * drift(2.0).x, -h.y - radius + lift);\n    float x = length(t - centre) - radius;\n    // The edge undulates, and with warp it drips into vertical streaks.\n    x += 0.035 * u_warp * flowNoise(vec2(t.x * 2.2, 0.3), 3.0);\n    x += 0.06 * u_warp * u_warp * flowNoise(vec2(t.x * 9.0, t.y * 0.6), 4.0) * (1.0 - smoothstep(-0.05, 0.25, x));\n    float above = exp(-max(x, 0.0) / (0.14 * soft));\n    float below = mix(1.0, 0.72, (1.0 - smoothstep(-0.6, 0.0, x)));\n    return x > 0.0 ? 0.92 * above : 0.92 + 0.3 * below * (1.0 - smoothstep(-0.08, 0.0, x));\n  }\n  if (mode < 3.0) {\n    // Beam: a long diagonal band, a thin hot core in a wide soft halo.\n    float a = 0.45 + (side - 0.5) * 1.1;\n    vec2 dir = vec2(cos(a), sin(a));\n    vec2 n = vec2(-dir.y, dir.x);\n    float u = dot(q, dir);\n    float v = dot(q, n) + 0.08 * h.y + 0.14 * u_loop.y + 0.07 * u_warp * flowNoise(vec2(u * 0.9, 0.5), 2.0) - 0.12 * u * u;\n    float w = 0.05 * s * soft;\n    float core = exp(-v * v / (w * w));\n    float halo = exp(-abs(v) / (4.0 * w));\n    float along = smoothstep(-1.4 * h.x, 0.3 * h.x, u) * (0.85 + 0.15 * flowNoise(vec2(u * 1.2, 1.7), 3.0));\n    return (0.75 * core + 0.6 * halo) * along;\n  }\n  // Bloom: light leaning in from a lower corner, with a hard-ish shoulder\n  // where it meets the dark, bent by the flow.\n  vec2 corner = vec2(side < 0.5 ? -1.0 : 1.0, -1.0) * h;\n  vec2 c = corner * 0.92 + 0.3 * drift(3.0);\n  vec2 w = q + 0.1 * u_warp * vec2(flowNoise(q * 1.1, 4.0), flowNoise(q * 1.1 + 3.3, 5.0));\n  vec2 d = rot2((side - 0.5) * 1.4) * (w - c);\n  float r = length(d * vec2(0.75, 1.0));\n  // The light spills out of the lobe in a long, uneven tail.\n  float tail = exp(-r / (0.55 * s * soft)) * (0.7 + 0.3 * flowNoise(d * 1.6 + 2.0, 7.0));\n  float edge = 1.0 - smoothstep((1.0 - 0.6 * soft) * s, s, r);\n  return 0.95 * edge * exp(-r / (1.1 * s * soft)) + 0.45 * tail;\n}\n\nvec3 kindColor(vec2 p, vec2 uv) {\n  vec2 h = frameHalf();\n  // The built-in dither; the engine's, when on, replaces it.\n  bool own = u_dither.x < 0.5;\n  float cell = own ? 3.0 : 1.0;\n  vec2 px = uv * u_full;\n  vec2 id = floor(px / cell);\n  vec2 centre = (id + 0.5) * cell;\n  vec2 q = (centre - 0.5 * u_full) / min(u_full.x, u_full.y);\n  q.y = -q.y;\n  q = interact(q);\n\n  float pick8 = floor(fract(u_seed.x * 0.0731 + 0.5) * 8.0);\n  float mode = mod(pick8, 4.0);\n  float side = fract(u_seed.y * 0.0917 + 0.5);\n\n  float light = dbLight(q, h, mode, side);\n  float t = clamp(pow(max(light, 0.0), 1.25), 0.0, 1.0);\n  vec3 lab = labMix(u_bg, ramp(t), smoothstep(0.0, 0.4, t));\n  // Past the core the light bleaches toward the palette's brightest.\n  vec3 hot = paletteColor(u_count - 1);\n  lab = labMix(lab, vec3(min(hot.x + 0.04, 1.0), hot.yz * 0.7), clamp((light - 1.0) * 1.5, 0.0, 1.0));\n  float lightBg = smoothstep(0.55, 0.85, u_bg.x);\n  lab.x *= vignette(q, 0.25 * (1.0 - lightBg));\n  lab = filmGrade(lab);\n  if (!own) return lab;\n\n  // Ordered dither per sRGB channel, one threshold per cell.\n  float spread = dbSpread();\n  float threshold = pick8 < 4.0 ? dbBayer8(id) : dbIgn(id);\n  float steps = 11.0;\n  vec3 rgb = dbLabToSrgb(lab);\n  vec3 dithered = floor(rgb * steps + threshold) / steps;\n  rgb = mix(rgb, dithered, spread);\n  // The cells read as a display: a faint seam on two edges.\n  vec2 local = px - id * cell;\n  if (local.x >= cell - 1.0 || local.y >= cell - 1.0) {\n    rgb *= 1.0 - 0.1 * spread;\n  }\n  return dbSrgbToLab(clamp(rgb, 0.0, 1.0));\n}\n`,\n  wgsl: () => import(\"./wgsl/dither-burst\").then((module) => module.wgsl),\n  label: \"Dither burst\",\n  name: \"dither-burst\",\n};\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/dither-burst.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/dither-field.ts",
      "content": "import type { GradientKindDefinition } from \"../kind\";\nimport { pick } from \"../kind\";\n\n/**\n * A gradient map drawn through ordered dither. A slow glowing body is mapped\n * onto the ramp background → colour 0 → colour 1 → …, and every pixel picks\n * one ramp stop with a 4x4 Bayer threshold, so the field is made of solid\n * cells in palette colours only.\n *\n * Cells form a quadtree around a focus: coarse cells far away, halving twice\n * toward it, and smooth colour at its centre. The focus idles on a small loop\n * and follows the pointer when one is over the canvas.\n *\n * Params: `scale` sets the coarse cell, 16px at 1 (4px steps from 8 to 64);\n * `warp` bends the body; `blur` widens the smooth core. Scroll has no\n * effect. Cells are measured in\n * canvas pixels, so mount it with `maxDpr: 1` and `image-rendering: pixelated`\n * for cells in CSS pixels.\n *\n * The kind dithers by itself, so params keep the engine's dither off: its\n * cells would resample this field and its levels would shift the palette.\n *\n * Helpers are prefixed `df` and only depend on the prelude.\n */\nexport const ditherField: GradientKindDefinition = {\n  defaults: {\n    background: \"#050505\",\n    blur: 0.4,\n    colors: [\"#2b3dd8\", \"#ff6a3d\", \"#ffd9a8\"],\n    dither: { cell: 4, enabled: false, levels: 4 },\n    grain: 0,\n    interaction: { pointer: 1, scroll: 0 },\n    loopSeconds: 20,\n    scale: 1,\n    seed: 3,\n    speed: 0.5,\n    warp: 0.5,\n  },\n  description:\n    \"A gradient map in ordered-dither cells that resolves to smooth colour around the pointer.\",\n  // Stepped rings, the CSS version of the quantised ramp.\n  fallbackLayers: (colors, background) => {\n    const ring = (i: number) => pick(colors, i);\n    return [\n      `radial-gradient(70% 85% at 72% 55%, ${ring(2)} 0 14%, ${ring(1)} 14% 30%, ${ring(0)} 30% 52%, color-mix(in oklab, ${ring(0)} 45%, ${background}) 52% 66%, transparent 66%)`,\n    ];\n  },\n  glsl: `\nconst float BAYER_DF[16] = float[16](\n  0.0, 8.0, 2.0, 10.0,\n  12.0, 4.0, 14.0, 6.0,\n  3.0, 11.0, 1.0, 9.0,\n  15.0, 7.0, 13.0, 5.0\n);\n\n// Ramp stop i: 0 is the background, then the palette.\nvec3 dfStop(int i) {\n  return i <= 0 ? u_bg : u_colors[min(i - 1, u_count - 1)];\n}\n\n// The body's height, 0..1, at q (p units). It sits right of centre, or low\n// in portrait frames, and falls to 0 well before the opposite side.\nfloat dfField(vec2 q, vec2 h) {\n  float portrait = clamp((h.y / h.x - 0.8) / 0.6, 0.0, 1.0);\n  vec2 centre = mix(vec2(0.52 * h.x, -0.02), vec2(0.04, -0.62 * h.y), portrait);\n  float reach = mix(0.56, 0.5, portrait);\n  vec2 w = q + u_warp * 0.2 * vec2(flowNoise(q * 1.1, 1.0), flowNoise(q * 1.1 + 4.1, 2.0));\n  vec2 d = (w - centre) * vec2(0.9, 1.0);\n  float body = pow(clamp(1.0 - length(d) / reach, 0.0, 1.0), 0.75);\n  // A second, smaller lobe circling the first.\n  vec2 orbit = centre + 0.3 * normalize(drift(3.0) + vec2(1e-4)) * vec2(1.2, 0.7);\n  float lobe = pow(clamp(1.0 - length(w - orbit) / 0.24, 0.0, 1.0), 1.4);\n  body = max(body, 0.55 * lobe) + 0.25 * body * lobe;\n  body += 0.06 * flowNoise(w * 2.4, 4.0) * smoothstep(0.0, 0.2, body);\n  // Keep clear of the opposite side, where a hero puts its copy.\n  float side = mix(q.x / h.x, -q.y / h.y, portrait);\n  body *= smoothstep(mix(-0.18, 0.1, portrait), mix(0.25, 0.42, portrait), side);\n  return clamp(body, 0.0, 1.0);\n}\n\nvec3 kindColor(vec2 p, vec2 uv) {\n  vec2 h = frameHalf();\n  float minSide = min(u_full.x, u_full.y);\n  vec2 px = floor(uv * u_full);\n  float coarse = 4.0 * clamp(floor(u_scale * 4.0 + 0.5), 2.0, 16.0);\n\n  // The focus: an idle drift, eased toward the pointer while it is near.\n  vec2 idle = mix(vec2(0.46 * h.x, 0.04), vec2(0.0, -0.6 * h.y), clamp((h.y / h.x - 0.8) / 0.6, 0.0, 1.0)) + 0.12 * drift(1.5);\n  vec2 ptr = (u_pointer.xy - 0.5) * 2.0 * h;\n  ptr.y = -ptr.y;\n  vec2 focus = mix(idle, ptr, clamp(u_pointer.z, 0.0, 1.0));\n\n  // Quadtree: a cell splits while its centre is inside the next radius.\n  float core = 0.07 + 0.08 * u_blur;\n  float radii[3] = float[3](core * 3.6, core * 2.2, core);\n  float size = coarse;\n  vec2 id = floor(px / size);\n  int tier = 0;\n  for (int k = 0; k < 3; k++) {\n    vec2 centre = (id + 0.5) * size;\n    vec2 cq = (centre - 0.5 * u_full) / minSide;\n    cq.y = -cq.y;\n    vec2 dq = abs(cq - focus);\n    if (max(dq.x, dq.y) >= radii[k]) break;\n    tier = k + 1;\n    if (k < 2) {\n      size *= 0.5;\n      id = floor(px / size);\n    }\n  }\n\n  // Viewfinder brackets around the smooth square, in the ramp's last stop,\n  // shown only while the square sits on the body.\n  float fine = coarse * 0.25;\n  vec2 fpx = vec2(focus.x, -focus.y) * minSide + 0.5 * u_full;\n  float corePx = radii[2] * minSide;\n  vec2 lo = (ceil((fpx - corePx) / fine - 0.5)) * fine;\n  vec2 hi = (floor((fpx + corePx) / fine - 0.5) + 1.0) * fine;\n  float gap = 3.0;\n  float arm = max(10.0, fine * 3.0);\n  bool inBox = all(greaterThan(px, lo - gap - 3.0)) && all(lessThan(px, hi + gap + 3.0));\n  bool inner = all(greaterThan(px, lo - gap - 1.0)) && all(lessThan(px, hi + gap + 1.0));\n  bool nearCorner = (min(abs(px.x - lo.x), abs(px.x - hi.x)) < arm) && (min(abs(px.y - lo.y), abs(px.y - hi.y)) < arm);\n  if (hi.x > lo.x && inBox && !inner && nearCorner && dfField(focus, h) > 0.2) {\n    return dfStop(u_count);\n  }\n\n  float stops = float(u_count);\n  if (tier == 3) {\n    // Sampled from the pixel itself: the prelude's pointer lens bends p,\n    // which would tear the core away from the cells around it.\n    vec2 sq = (px + 0.5 - 0.5 * u_full) / minSide;\n    sq.y = -sq.y;\n    float x = dfField(sq, h) * stops;\n    int i = int(floor(x));\n    float f = smoothstep(0.0, 1.0, fract(x));\n    return labMix(dfStop(i), dfStop(i + 1), f);\n  }\n\n  vec2 cellPx = (id + 0.5) * size;\n  vec2 q = (cellPx - 0.5 * u_full) / minSide;\n  q.y = -q.y;\n  float x = dfField(q, h) * stops;\n  ivec2 b = ivec2(mod(id, 4.0));\n  float threshold = (BAYER_DF[b.y * 4 + b.x] + 0.5) / 16.0;\n  int i = int(floor(x)) + (fract(x) > threshold ? 1 : 0);\n  // Coarse cells read as a display: a hairline gap between lit cells, and a\n  // faint unlit pixel at the centre of every empty one.\n  vec2 local = px - id * size;\n  if (i == 0) {\n    vec2 dot_ = abs(local - (size * 0.5 - 1.0));\n    bool lit = tier == 0 && max(dot_.x, dot_.y) < 1.0;\n    return lit ? mix(u_bg, dfStop(1), 0.4) : u_bg;\n  }\n  if (tier == 0 && (local.x >= size - 1.0 || local.y >= size - 1.0)) {\n    return mix(dfStop(i), u_bg, 0.35);\n  }\n  return dfStop(i);\n}\n`,\n  wgsl: () => import(\"./wgsl/dither-field\").then((module) => module.wgsl),\n  label: \"Dither field\",\n  name: \"dither-field\",\n};\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/dither-field.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/fluted.ts",
      "content": "import type { GradientKindDefinition } from \"../kind\";\nimport { stops } from \"../kind\";\n\n/**\n * Flowing light seen through a wall of vertical flutes. Behind the glass is\n * one soft structure: a ribbon of light sweeping across the frame, an arch\n * of light rising from below, or a ribbon crossed by a column of light. Each flute shifts the image sideways by\n * an amount that grows across its width, so every bright edge breaks into a\n * fine sawtooth, and flutes vary in width like hand-drawn glass.\n *\n * Unlike the Pro reeded glass (lamps seen through mirrored flutes), the\n * light here is a single swept form and the refraction is progressive.\n *\n * The seed picks ribbon, arch or ribbon and column, and where they sit.\n * Colours run from the light's outer edge (first) to its hot core (last);\n * the column takes the last colour. `scale` sets flute width (about 36\n * flutes across the long side at 1), `warp` the refraction, `blur` the\n * softness.\n *\n * Helpers are prefixed `fl` and only depend on the prelude.\n */\nexport const fluted: GradientKindDefinition = {\n  defaults: {\n    background: \"#050507\",\n    blur: 0.5,\n    colors: [\"#1d2a8f\", \"#2f7bff\", \"#ff7a3d\", \"#ffe2c4\"],\n    dither: { cell: 3, enabled: false, levels: 8 },\n    grain: 0.16,\n    interaction: { pointer: 0.15, scroll: 0.1 },\n    loopSeconds: 20,\n    scale: 1,\n    seed: 5,\n    speed: 0.5,\n    warp: 0.5,\n  },\n  description:\n    \"A sweep of light behind fluted glass, every edge broken into fine teeth.\",\n  fallbackLayers: (colors) => [\n    `repeating-linear-gradient(90deg, rgb(255 255 255 / 0.05) 0 1px, transparent 1px 4.5%)`,\n    `linear-gradient(155deg, transparent 30%, ${stops(colors, 40, 60)}, transparent 72%)`,\n  ],\n  glsl: `\n// The light behind the glass at q: intensity (x) and the column's core (y).\nvec2 flLight(vec2 q, vec2 h, float mode, float side) {\n  float soft = 0.5 + 0.9 * u_blur;\n  float ribbon = 0.0;\n  if (mode != 1.0) {\n    // A ribbon sweeping corner to corner, bending with the flow.\n    float a = -0.6 + (side - 0.5) * 0.9;\n    vec2 dir = vec2(cos(a), sin(a));\n    vec2 n = vec2(-dir.y, dir.x);\n    float u = dot(q, dir);\n    float v = dot(q, n) - 0.18 * sin(u * 2.2 + 1.3 * side) * h.y;\n    v += 0.1 * flowNoise(vec2(u * 0.8, 0.2), 1.0);\n    // Lit from above: a crisp bright lip, then a long fall into the dark.\n    float w = 0.13 * soft;\n    float lip = v > 0.0 ? exp(-v * v / (0.5 * w * w)) : exp(v / (1.4 * w));\n    float glow = exp(-abs(v) / (5.0 * w));\n    // A second, fainter fold under the first.\n    float v2 = v + 0.3 + 0.06 * flowNoise(vec2(u * 0.7, 2.1), 2.0);\n    float fold = 0.3 * (v2 > 0.0 ? exp(-v2 * v2 / (0.2 * w * w)) : exp(v2 / (2.0 * w)));\n    ribbon = (0.95 * lip + 0.15 * glow + 0.75 * fold) * (0.8 + 0.2 * flowNoise(vec2(u * 1.5, 3.0), 3.0));\n  }\n  float column = 0.0;\n  float core = 0.0;\n  if (mode == 1.0) {\n    // An arch: the top of a big soft disc rising from below, its rim lit\n    // hardest at the crown and its body falling away into the dark.\n    vec2 c = vec2((side - 0.5) * 1.1 * h.x, -1.35 * h.y) + vec2(0.06, 0.03) * drift(4.0);\n    float radius = 1.05 * h.y + 0.3 * h.x * abs(side - 0.5);\n    vec2 d = (q - c) * vec2(0.8, 1.0);\n    float r = length(d);\n    float x = r - radius + 0.03 * flowNoise(d * 1.4, 5.0);\n    float crown = 0.45 + 0.55 * smoothstep(-0.2, 1.0, d.y / max(r, 1e-3));\n    float w = 0.08 * soft;\n    float rim = exp(-x * x / (w * w));\n    float body = x < 0.0 ? exp(x / (0.3 * soft)) : exp(-x / (0.22 * soft));\n    column = 0.85 * (0.5 * rim + 0.75 * body) * crown;\n  } else if (mode == 2.0) {\n    float x0 = (side - 0.5) * 0.9 * h.x + 0.04 * drift(4.0).x + 0.025 * flowNoise(vec2(0.5, q.y * 1.2), 7.0);\n    float dx = q.x - x0;\n    float tall = smoothstep(-1.2 * h.y, 0.3 * h.y, q.y + 0.15 * flowNoise(vec2(0.3, q.y), 5.0));\n    core = exp(-dx * dx / (0.006 * soft)) * mix(0.6, 1.0, tall);\n    column = 0.85 * core + 0.35 * exp(-abs(dx) / (0.16 * soft)) * mix(0.55, 1.0, tall);\n  }\n  return vec2(ribbon + column, core);\n}\n\nvec3 kindColor(vec2 p, vec2 uv) {\n  vec2 h = frameHalf();\n  float minSide = min(u_full.x, u_full.y);\n  float mode = floor(fract(u_seed.x * 0.0731 + 0.5) * 3.0);\n  float side = fract(u_seed.y * 0.0917 + 0.5);\n\n  // Flutes: an uneven but monotonic stretch of x, so widths vary.\n  float w = (2.0 * h.x) / (36.0 * u_scale);\n  float x = p.x / w;\n  float xf = x + 0.32 * sin(x * 0.61 + 1.7) + 0.18 * sin(x * 1.37 + 0.4);\n  float u = fract(xf);\n  float idx = floor(xf);\n  // Progressive refraction: the image slides across each flute.\n  float shift = (0.3 + 1.6 * u_warp) * w;\n  vec2 q = p;\n  q.x += (u - 0.5) * shift;\n  // Each flute leans the image a touch, so diagonal edges turn into teeth.\n  q.y += (u - 0.5) * shift * 0.35 * sin(idx * 2.3);\n\n  vec2 light = flLight(q, h, mode, side);\n  float t = clamp(pow(light.x, 1.15), 0.0, 1.0);\n  vec3 col = ramp(t);\n  col = labMix(col, paletteColor(u_count - 1), light.y * 0.85);\n  vec3 lab = labMix(u_bg, col, smoothstep(0.0, 0.45, t));\n\n  // Glass: the curve catches a thin highlight near one side of each flute\n  // and darkens toward the seams.\n  float seen = clamp(length(lab - u_bg) * 4.0, 0.0, 1.0);\n  // Hand-made glass: each flute is a touch brighter or darker.\n  lab.x *= 1.0 + 0.07 * seen * (fract(sin(idx * 12.9898) * 43758.5453) - 0.5);\n  float curve = sin(u * 3.14159265);\n  lab.x += (0.05 * exp(-pow((u - 0.28) / 0.07, 2.0)) - 0.04 * (1.0 - curve)) * mix(0.35, 1.0, seen);\n  float seamPx = min(u, 1.0 - u) * w * minSide;\n  lab.x -= 0.05 * (1.0 - smoothstep(0.0, 1.2, seamPx)) * seen;\n  float lightBg = smoothstep(0.55, 0.85, u_bg.x);\n  lab.x *= vignette(p, 0.3 * (1.0 - lightBg));\n  return filmGrade(lab);\n}\n`,\n  wgsl: () => import(\"./wgsl/fluted\").then((module) => module.wgsl),\n  label: \"Fluted\",\n  name: \"fluted\",\n};\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/fluted.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/grain.ts",
      "content": "import type { GradientKindDefinition } from \"../kind\";\nimport { pick, stops } from \"../kind\";\n\nexport const grain: GradientKindDefinition = {\n  defaults: {\n    background: \"#070505\",\n    blur: 0.55,\n    colors: [\"#ffd8b4\", \"#e0703b\", \"#8a2c1d\", \"#2b1015\"],\n    dither: { cell: 3, enabled: false, levels: 8 },\n    grain: 0.5,\n    interaction: { pointer: 0.25, scroll: 0.15 },\n    loopSeconds: 16,\n    scale: 1,\n    seed: 7,\n    speed: 0.6,\n    warp: 0.55,\n  },\n  description: \"A grainy beam of light from one corner, brushed into the dark.\",\n  fallbackLayers: (colors) => [\n    `radial-gradient(60% 45% at 18% 20%, ${pick(colors, 0)} 0%, transparent 60%)`,\n    `linear-gradient(150deg, ${stops(colors, 0, 70)}, transparent 85%)`,\n  ],\n  glsl: `\nvec3 kindColor(vec2 p, vec2 uv) {\n  vec2 h = frameHalf();\n  // The light sits just outside the frame and throws a beam across it.\n  float a = seedAngle();\n  vec2 dir = vec2(cos(a), sin(a));\n  vec2 across = vec2(-dir.y, dir.x);\n  vec2 src = -dir * (abs(dir.x) * h.x + abs(dir.y) * h.y + 0.12);\n  vec2 q = p - src;\n  float u = dot(q, dir);\n  float v = dot(q, across);\n\n  float bend = 0.06 * sin(u * 1.4 + 0.6 * u_loop.x + a)\n    + 0.12 * u_warp * flowNoise(vec2(u * 0.7, 1.3) * u_scale, 1.0);\n  float width = (0.1 + 0.18 * u_blur) * (0.45 + 0.7 * u);\n  float vb = v - bend;\n  float beam = exp(-vb * vb / (width * width));\n  // Brushed streaks: long along the beam, short across it.\n  float streak = flowNoise(vec2(u * 0.8, vb * 9.0 / (0.45 + u_blur)) * u_scale, 2.0);\n  // A wider, dimmer sheet behind it for depth.\n  float vb2 = v + 0.3 - 0.5 * bend;\n  float beam2 = exp(-vb2 * vb2 / (width * width * 4.0));\n  float fall = exp(-u * 0.75);\n  float source = exp(-dot(q, q) * 2.2);\n\n  float intensity = (beam * (0.88 + 0.3 * streak) + 0.35 * beam2 * (0.8 + 0.3 * streak)) * fall * 1.5\n    + 0.55 * source;\n  float ti = 1.0 - exp(-1.6 * intensity);\n  vec3 col = ramp(1.0 - ti);\n  vec3 lab = labMix(u_bg, col, smoothstep(0.0, 0.75, ti));\n  lab.x += 0.08 * max(intensity - 1.0, 0.0);\n  lab.x *= vignette(p, 0.35);\n  return filmGrade(lab);\n}\n`,\n  wgsl: () => import(\"./wgsl/grain\").then((module) => module.wgsl),\n  label: \"Grain\",\n  name: \"grain\",\n};\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/grain.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/halo.ts",
      "content": "import type { GradientKindDefinition } from \"../kind\";\nimport { pick } from \"../kind\";\n\nexport const halo: GradientKindDefinition = {\n  defaults: {\n    background: \"#030306\",\n    blur: 0.4,\n    colors: [\"#fff4ec\", \"#ffb36b\", \"#e2457a\", \"#3d4dff\"],\n    dither: { cell: 3, enabled: false, levels: 8 },\n    grain: 0.16,\n    interaction: { pointer: 0.15, scroll: 0.1 },\n    loopSeconds: 16,\n    scale: 1,\n    seed: 3,\n    speed: 0.6,\n    warp: 0.55,\n  },\n  description:\n    \"A ring of light round a dark core, with a sharp inner rim and colour running round it.\",\n  fallbackLayers: (colors) => [\n    `radial-gradient(circle at 50% 50%, transparent 24%, color-mix(in oklab, ${pick(colors, 0)} 85%, transparent) 25%, color-mix(in oklab, ${pick(colors, 1)} 60%, transparent) 30%, color-mix(in oklab, ${pick(colors, 2)} 30%, transparent) 37%, transparent 52%)`,\n    `radial-gradient(circle at 50% 50%, transparent 30%, color-mix(in oklab, ${pick(colors, 3)} 22%, transparent) 40%, transparent 70%)`,\n  ],\n  glsl: `\n// A thick torus of light: the inner edge is crisp, the body holds its\n// brightness then rolls off into a wide haze. warp sets how lopsided the\n// light is and how far the hue wanders round the ring; blur softens the\n// rim and widens the haze.\nfloat haloBody(float x, float soft, float width) {\n  float edge = smoothstep(-soft, soft, x);\n  float xo = max(x, 0.0) / width;\n  float x4 = xo * xo * xo * xo;\n  return edge / (1.0 + x4 * x4);\n}\n\nvec3 kindColor(vec2 p, vec2 uv) {\n  float lightBg = smoothstep(0.55, 0.85, u_bg.x);\n  vec2 h = frameHalf();\n  // The seed picks a framing: centred, rising from the bottom edge, off to\n  // one side, hanging in a top corner and cropped by the frame, or tilted\n  // into an ellipse, as if seen at an angle, centred or low like a portal.\n  float framing = floor(fract(u_seed.x * 0.0731 + 0.5) * 6.0);\n  float side = sign(u_seed.y + 0.01);\n  vec2 centre = vec2(0.0, 0.0);\n  float radius = 0.19;\n  float tilt = 0.0;\n  float squash = 1.0;\n  if (framing == 1.0) {\n    centre = vec2(0.0, -0.56);\n    radius = 0.3;\n  } else if (framing == 2.0) {\n    centre = vec2(0.34 * h.x * side, -0.02);\n    radius = 0.2;\n  } else if (framing == 3.0) {\n    centre = vec2(-side * (h.x - 0.12), h.y - 0.1);\n    radius = 0.3;\n  } else if (framing == 4.0) {\n    radius = 0.3;\n    tilt = 0.22 * side;\n    squash = 0.4;\n  } else if (framing == 5.0) {\n    centre = vec2(0.0, -0.3);\n    radius = 0.44;\n    tilt = 0.08 * side;\n    squash = 0.28;\n  }\n  radius *= u_scale;\n\n  // The hot side sways slowly round the ring.\n  float swing = seedAngle() + 2.4 * u_loop.x;\n  vec2 hotDir = vec2(sin(swing), cos(swing));\n\n  vec2 d = rot2(tilt) * (p - centre);\n  d.y /= squash;\n  float r = length(d);\n  vec2 dir = d / max(r, 1e-4);\n  float x = r / radius - 1.0;\n\n  float soft = 0.01 + 0.06 * u_blur;\n  float width = 0.42 + 0.2 * u_blur;\n  float hot = 0.5 + 0.5 * dot(dir, hotDir);\n  float key = mix(1.0, 0.22 + 0.78 * hot * hot, 0.3 + 0.6 * u_warp);\n\n  // Noise sampled on the unit circle (so it has no seam) drifts the hue\n  // and, a little, the thickness round the ring.\n  float around = flowNoise(dir * 0.8 + vec2(3.1, 0.0), 2.0);\n  float body = haloBody(x, soft, width * (1.0 + 0.07 * u_warp * flowNoise(dir * 0.7, 1.0)));\n  // A ghost exposure, nudged toward the hot side: a doubled, glassy rim.\n  vec2 dg = d - hotDir * radius * 0.08;\n  float xg = length(dg) / radius - 1.06;\n  float ghost = smoothstep(-soft, soft, xg) * exp(-max(xg, 0.0) / (0.05 + 0.08 * u_blur));\n  float haze = exp(-max(x, 0.0) / (0.6 + 0.8 * u_blur)) * smoothstep(0.0, width, x);\n  // Faint tinted fog inside the core, so the dark has depth.\n  float fog = (1.0 - smoothstep(-soft, soft, x)) * exp(x / 0.25);\n\n  float glow = 0.95 * body * key + 0.3 * ghost * (0.3 + 0.7 * hot) + 0.12 * haze * (0.4 + 0.6 * key) + 0.12 * fog * (0.3 + 0.7 * hot);\n\n  // Colour: the inner rim runs hot (colour 0), the body moves through the\n  // palette outward, and the hue drifts round the ring.\n  float depth = clamp(max(x, 0.0) / (width * 1.6), 0.0, 1.0);\n  float t = clamp(0.12 + 0.45 * depth + 0.5 * u_warp * (0.5 + 0.5 * around) + 0.35 * (1.0 - hot), 0.0, 1.0);\n  vec3 col = ramp(t);\n  float rimLine = smoothstep(-soft, soft, x) * exp(-max(x, 0.0) / (0.06 + 0.1 * u_blur));\n  col = labMix(col, paletteColor(0), rimLine * hot * 0.8);\n  col = labMix(col, paletteColor(u_count - 1), fog * 0.6);\n\n  vec3 lab = labMix(u_bg, col, clamp(glow, 0.0, 1.0));\n  lab.x += 0.08 * max(glow - 0.85, 0.0) * (1.0 - lightBg);\n  return filmGrade(lab);\n}\n`,\n  wgsl: () => import(\"./wgsl/halo\").then((module) => module.wgsl),\n  label: \"Halo\",\n  name: \"halo\",\n};\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/halo.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/horizon.ts",
      "content": "import type { GradientKindDefinition } from \"../kind\";\nimport { pick } from \"../kind\";\n\n/**\n * A black-hole horizon: a void with a curved lower edge, faint ripple rings\n * just inside it, and layered, lensed light streaks converging on a vanishing\n * point below the frame, finished with star flares and a vignette.\n *\n * Palette roles: 0 core streak, 1 secondary streak, 2 rim (cool edge),\n * 3 deep shadow, 4 highlight. Shorter palettes reuse the last colour.\n *\n * Horizon is a scene kind: its colours drive the palette, but the scene adds\n * its own lighting (void, haze, rings, highlights, vignette), so a flat\n * palette does not render as that flat colour. It is exempt from the ΔE 0.02\n * flat-colour fidelity check the other kinds meet.\n *\n * Helpers are prefixed `hz` and self-contained so the kind only depends on\n * the prelude's uniforms.\n */\nexport const horizon: GradientKindDefinition = {\n  defaults: {\n    background: \"#000000\",\n    blur: 0.35,\n    colors: [\"#b4553a\", \"#c98f8a\", \"#6f8fb0\", \"#3a1f33\", \"#dfe8ff\"],\n    dither: { cell: 3, enabled: false, levels: 8 },\n    grain: 0.12,\n    interaction: { pointer: 0.15, scroll: 0.2 },\n    loopSeconds: 24,\n    scale: 1,\n    seed: 7,\n    speed: 0.6,\n    warp: 0.5,\n  },\n  description:\n    \"An event horizon over a void, with lensed light streaks and star flares.\",\n  // Static horizon for CSS: a curved void edge with a thin cool rim, flat\n  // streak ellipses in the band, a soft well at the bottom and a plum base.\n  fallbackLayers: (colors, background) => {\n    const mix = (i: number, amount: number) =>\n      `color-mix(in oklab, ${pick(colors, i)} ${amount}%, transparent)`;\n    return [\n      `radial-gradient(1000px 79% at 46% 0%, ${background} 95%, transparent 100%)`,\n      `radial-gradient(1030px 82% at 46% 0%, transparent 93%, ${mix(2, 45)} 96.5%, transparent 100%)`,\n      `radial-gradient(14% 6% at 47% 98%, ${background} 0%, transparent 100%)`,\n      `radial-gradient(20% 3% at 40% 90%, ${mix(4, 45)} 0%, transparent 100%)`,\n      `radial-gradient(42% 8% at 16% 76%, ${mix(0, 75)} 0%, transparent 100%)`,\n      `radial-gradient(38% 6% at 20% 86%, ${mix(1, 50)} 0%, transparent 100%)`,\n      `radial-gradient(34% 12% at 86% 66%, ${mix(1, 70)} 0%, transparent 100%)`,\n      `radial-gradient(30% 7% at 80% 84%, ${mix(0, 65)} 0%, transparent 100%)`,\n      `linear-gradient(180deg, transparent 55%, ${mix(3, 70)} 100%)`,\n    ];\n  },\n  glsl: `\nvec3 hzCol(int i) { return u_colors[min(i, u_count - 1)]; }\n\n// Sin-free lattice hash (Dave Hoskins), -1..1.\nvec2 hzHash(vec2 p) {\n  vec3 p3 = fract(vec3(p.xyx) * vec3(0.1031, 0.103, 0.0973));\n  p3 += dot(p3, p3.yzx + 33.33);\n  return fract((p3.xx + p3.yz) * p3.zy) * 2.0 - 1.0;\n}\n\n// 2D gradient noise, roughly -0.7..0.7.\nfloat hzNoise(vec2 p) {\n  vec2 i = floor(p);\n  vec2 f = fract(p);\n  vec2 u = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);\n  float a = dot(hzHash(i), f);\n  float b = dot(hzHash(i + vec2(1.0, 0.0)), f - vec2(1.0, 0.0));\n  float c = dot(hzHash(i + vec2(0.0, 1.0)), f - vec2(0.0, 1.0));\n  float d = dot(hzHash(i + vec2(1.0, 1.0)), f - vec2(1.0, 1.0));\n  return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);\n}\n\n// Gradient noise with its analytic derivative: (value, d/dx, d/dy).\nvec3 hzNoiseD(vec2 p) {\n  vec2 i = floor(p);\n  vec2 f = fract(p);\n  vec2 u = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);\n  vec2 du = 30.0 * f * f * (f * (f - 2.0) + 1.0);\n  vec2 ga = hzHash(i);\n  vec2 gb = hzHash(i + vec2(1.0, 0.0));\n  vec2 gc = hzHash(i + vec2(0.0, 1.0));\n  vec2 gd = hzHash(i + vec2(1.0, 1.0));\n  float va = dot(ga, f);\n  float vb = dot(gb, f - vec2(1.0, 0.0));\n  float vc = dot(gc, f - vec2(0.0, 1.0));\n  float vd = dot(gd, f - vec2(1.0, 1.0));\n  float k = va - vb - vc + vd;\n  float v = va + u.x * (vb - va) + u.y * (vc - va) + u.x * u.y * k;\n  vec2 d = ga + u.x * (gb - ga) + u.y * (gc - ga) + u.x * u.y * (ga - gb - gc + gd)\n    + du * (u.yx * k + vec2(vb, vc) - va);\n  return vec3(v, d);\n}\n\n// The loop point rotated by a per-layer angle: still periodic, out of phase.\nvec2 hzLoop(float a) {\n  float c = cos(a);\n  float s = sin(a);\n  return vec2(c * u_loop.x - s * u_loop.y, s * u_loop.x + c * u_loop.y);\n}\n\n// Sheet coordinates: stretched, drifting on the loop circle, seeded.\nvec2 hzSheet(vec2 sp, vec2 freq, float layer) {\n  return sp * freq + hzLoop(layer * 2.1) * vec2(0.9, 0.5) + u_seed * 0.37 + layer * 13.7;\n}\n\n// Height of the horizon at x, measured against grainient's hero: a wide well\n// just right of centre, a gentle shelf on the left and a late climb on the\n// right. Portrait frames sit the horizon lower.\nfloat hzRim(float x, float portrait, float breathe) {\n  float well = exp(-(x - 0.08) * (x - 0.08) * 4.5);\n  float r = max(x - 0.4, 0.0);\n  float shelf = -0.145 - 0.035 * (1.0 - smoothstep(-0.6, 0.0, x));\n  return shelf - (0.19 + breathe) * well * (1.0 - 0.75 * portrait) + 0.65 * r * r - 0.11 * portrait;\n}\n\n// The void: black, with a cool haze bleeding up from the horizon and faint\n// ripple rings inside it.\nvec3 hzVoid(float inside, float sideGlow) {\n  float haze = (exp(-inside * 30.0) * 0.2 + exp(-inside * 10.0) * 0.06) * sideGlow;\n  float rings = sin(inside * 210.0 - 0.8 * hzLoop(2.5).y) * exp(-inside * 6.0);\n  return vec3(haze * (1.0 + 0.22 * rings) + 0.005 * rings, hzCol(2).yz * haze * 0.55);\n}\n\n// Star flares: x in half-widths, y in half-heights, size.\nconst vec3 HZ_STARS[5] = vec3[5](\n  vec3(-0.29, -0.71, 1.2),\n  vec3(0.31, -0.88, 1.0),\n  vec3(0.79, -0.8, 0.7),\n  vec3(-0.53, -0.55, 0.5),\n  vec3(0.15, -0.94, 0.45)\n);\n\nvec3 kindColor(vec2 p, vec2 uv) {\n  vec2 h = frameHalf();\n  float portrait = clamp((h.y / h.x - 0.65) / 1.2, 0.0, 1.0);\n  float tilt = (fract(u_seed.x * 0.0193) - 0.5) * 0.1;\n  float x = p.x - tilt;\n\n  float breathe = 0.01 * hzLoop(0.7).x;\n  float rimY = hzRim(x, portrait, breathe);\n  float slope = (hzRim(x + 0.01, portrait, breathe) - rimY) * 100.0;\n  float out_ = (rimY - p.y) / sqrt(1.0 + slope * slope); // > 0 in the light\n  float sideGlow = 0.55 + 0.7 * smoothstep(0.15, 0.85, abs(p.x) / h.x);\n\n  vec2 vq = (uv - 0.5) * vec2(1.0, 1.1);\n  float vignette = 1.0 - 0.6 * dot(vq, vq);\n  // Most of the frame is void: skip the light entirely there.\n  if (out_ < -0.012) {\n    vec3 lab = hzVoid(-out_, sideGlow);\n    lab.x *= vignette;\n    return lab + u_bg;\n  }\n\n  // The well: a dark funnel at the bottom centre.\n  vec2 vp = vec2(-0.03 + tilt * 0.5, -0.91 * h.y);\n  vec2 hq = (p - vp) / vec2(0.19, 0.068);\n  float hd = length(hq);\n  float landscape = 1.0 - portrait;\n\n  // Deeper bands flatten toward the horizontal, like a ground plane.\n  float rimMin = -0.32 - 0.11 * portrait;\n  float yRef = mix(rimY, rimMin + (rimY - rimMin) * 0.3, smoothstep(0.0, 0.3, out_));\n  float depth = max(yRef - p.y, 0.0);\n  // Perspective: bands crowd toward the horizon and widen toward the viewer.\n  float across = log(1.0 + depth * 7.0) * 0.32;\n  float along = p.x;\n  across += 0.035 * u_warp * sin(along * 3.1 + across * 9.0 + hzLoop(4.0).x * 2.0);\n\n  // Near the well the bands dip and dive into it, like light bent by a\n  // black hole.\n  float wrap = (1.0 - smoothstep(0.9, 2.6, hd)) * landscape;\n  across = max(across - 0.09 * wrap * smoothstep(0.0, 0.15, across), 0.0);\n  along = mix(along, along * (1.0 + 0.8 * wrap), wrap);\n\n  float sc = u_scale;\n  vec2 f0 = vec2(1.0, 6.0) * sc;\n  vec2 f1 = vec2(1.7, 14.0) * sc;\n  float s0 = hzNoise(hzSheet(vec2(along, across), f0, 0.0));\n  vec3 n1 = hzNoiseD(hzSheet(vec2(along + s0 * 0.45, across + s0 * 0.012), f1, 1.0));\n  float s1 = n1.x;\n  // Turbulence: slanted wisps that cross the bands and fray them, strongest\n  // where the streaks climb on the right.\n  float rise = smoothstep(0.1, 0.75, p.x / h.x);\n  vec2 q2 = vec2(along, across + along * (0.08 + 0.3 * rise));\n  float s2 = hzNoise(hzSheet(q2, vec2(2.0, 15.0) * sc, 2.0));\n\n  float env = smoothstep(-0.012, 0.05, out_) * (0.75 + 0.25 * exp(-out_ * 3.0));\n  // The well fades from the surrounding light into black over a wide falloff.\n  float hole = mix(pow(1.0 - exp(-hd * hd * 0.38), 1.6), 1.0, portrait);\n  float nearWell = (1.0 - smoothstep(1.0, 2.6, hd)) * landscape;\n  // The band is quieter and darker just under the hero copy.\n  float quiet = exp(-p.x * p.x * 9.0) * (1.0 - smoothstep(0.04, 0.16, out_)) * landscape;\n  // The hottest light arches over the well and runs down its flanks.\n  float flank = smoothstep(-0.7, 0.1, hq.y / max(hd, 1e-3));\n  float ring = exp(-max(hd - 1.7, 0.0) * 1.3) * smoothstep(0.9, 2.0, hd) * flank * landscape;\n  float side = 0.8 + 0.45 * smoothstep(0.1, 0.8, abs(p.x) / h.x);\n  // The bottom corners fall away to teal-black.\n  float corner = (1.0 - smoothstep(-h.y, -0.55 * h.y, p.y)) * smoothstep(0.35, 0.9, abs(p.x) / h.x) * landscape;\n  side *= 1.0 - 0.55 * corner;\n\n  float glow = clamp(0.5 + 0.9 * s0, 0.0, 1.0);\n  float fray = (0.16 + 0.12 * rise) * (1.0 - 0.8 * portrait);\n  float v = mix(s1 + 0.4 * s0 + fray * s2 + 0.08 * rise, 0.2 + 0.3 * s0, portrait * 0.85);\n  // Long-exposure softness: a wide transfer, and the dark gaps between bands\n  // are lifted so few near-black stripes remain inside the band.\n  float streak = smoothstep(-0.4 - 0.3 * u_blur, 0.55 + 0.2 * u_blur, v);\n  streak = mix(0.18, 1.0, streak);\n  // Near the well the streaks smooth out so its outline stays a clean ellipse.\n  streak = mix(streak, 0.7, nearWell * 0.25);\n  // Where a streak brightens going down, its upper edge catches cool light\n  // and the lower edge stays warm.\n  float grad = n1.z * f1.y * 0.01;\n  float coolEdge = smoothstep(0.02, 0.18, grad) * streak;\n  float warmEdge = smoothstep(0.02, 0.18, -grad) * streak;\n\n  // Colour: teal-black gaps, rust and rose bodies, steel-blue upper edges and\n  // rim, pale blue-white on the brightest edges.\n  vec3 gap = mix(hzCol(3), vec3(hzCol(2).x * 0.45, hzCol(2).yz * 0.7), 0.55 + 0.35 * s0);\n  float warmPick = smoothstep(-0.05, 0.5, s1 - 0.5 * s0);\n  vec3 body = mix(hzCol(0), hzCol(1), warmPick);\n  body = mix(body, hzCol(0), warmEdge * 0.5);\n  // Glow, not paint: part of the body falls to desaturated mauve and grey-blue.\n  vec3 mauve = mix(body, hzCol(2), 0.25 + 0.25 * (1.0 - smoothstep(-0.3, 0.3, s0)));\n  body = mix(body, vec3(mauve.x, mauve.yz * 0.7), (0.1 + 0.12 * rise) * landscape);\n  vec3 col = mix(gap, body, smoothstep(0.2, 0.75, streak));\n  // Portrait frames grade softly from steel at the edge through rose to rust.\n  vec3 tall = mix(hzCol(2), mix(hzCol(1), hzCol(0), 0.6 * smoothstep(0.15, 0.55, out_)), smoothstep(0.03, 0.22, out_));\n  col = mix(col, tall, portrait * 0.7);\n  float rimness = exp(-max(out_, 0.0) * mix(24.0, 5.0, portrait));\n  col = mix(col, hzCol(2), clamp(coolEdge * 0.6 + rimness * 0.9 + ring * 0.5, 0.0, 1.0));\n  col = mix(col, gap, 0.65 * corner);\n  col = mix(col, hzCol(4), clamp(coolEdge * coolEdge * 0.7 + ring * streak * 0.6 + rimness * glow * 0.25, 0.0, 1.0));\n\n  // A broad bloom where the coarse sheet peaks.\n  float bloom = smoothstep(0.2, 0.75, s0) * exp(-out_ * 2.5);\n  float energy = env * hole * side * (1.0 - 0.45 * quiet) * (0.12 + 0.1 * rise + glow * glow * 0.3 + streak * 0.8 + coolEdge * 0.45 + bloom * 0.35)\n    + env * ring * (0.45 + 1.35 * streak)\n    + exp(-abs(out_ - 0.018) * 30.0) * (0.25 + 0.6 * glow) * env;\n  energy = mix(energy, env * (0.75 + 0.35 * glow) * (1.0 - 0.5 * smoothstep(0.25, 0.8, out_)), portrait * 0.6);\n\n  // Filmic tone: soft shoulder on lightness, chroma follows the light and\n  // rolls off in the highlights.\n  float lum = 1.0 - exp(-energy * 1.7);\n  float L = col.x * lum * 1.22;\n  // Darks desaturate toward black, like a film toe.\n  float chroma = smoothstep(0.0, 0.45, lum) * mix(0.5, 1.0, smoothstep(0.25, 0.7, lum));\n  vec3 lab = vec3(L, col.yz * chroma * mix(0.87, 1.0, portrait) * (1.0 - 0.45 * smoothstep(0.7, 1.0, L)));\n\n  // Chromatic fringing: a thin cyan line on upper edges, red on lower edges.\n  float mid = 4.0 * streak * (1.0 - streak);\n  float fringe = mid * mid * mid * clamp(grad * 6.0, -1.0, 1.0) * lum * landscape;\n  lab.yz -= fringe * (fringe > 0.0 ? vec2(0.045, 0.034) : vec2(0.03, 0.018));\n\n  // The very peaks run to near-white, over tiny areas.\n  float hot = smoothstep(1.2, 2.3, energy);\n  lab = mix(lab, vec3(0.965, -0.004, -0.014), hot * 0.85);\n\n  // The haze runs continuously across the edge and fades into the band.\n  lab += hzVoid(max(-out_, 0.0), sideGlow) * exp(-max(out_, 0.0) * 30.0);\n\n  // Star flares: a soft glow and core, long hair-fine horizontal flare and a\n  // shorter vertical one. Pixels outside a star's reach skip it.\n  for (int i = 0; i < 5; i++) {\n    vec3 st = HZ_STARS[i];\n    vec2 sd = p - vec2(st.x * h.x + tilt, st.y * h.y);\n    float size = st.z;\n    if (abs(sd.x) > 0.42 * size || abs(sd.y) > 0.22 * size) continue;\n    float tw = clamp(0.7 + 0.5 * hzLoop(float(i) * 1.9 + 0.4).x, 0.15, 1.2);\n    float r2 = dot(sd, sd);\n    float core = exp(-r2 * 45000.0);\n    float halo = exp(-r2 * 1800.0 / (size * size)) * 0.1 * smoothstep(0.6, 1.2, size);\n    float fx = exp(-abs(sd.y) * 2200.0) * exp(-abs(sd.x) * 6.0 / size)\n      * (1.0 - smoothstep(0.25, 0.42, abs(sd.x) / size));\n    float fy = exp(-abs(sd.x) * 2200.0) * exp(-abs(sd.y) * 12.0 / size)\n      * (1.0 - smoothstep(0.12, 0.22, abs(sd.y) / size));\n    float star = (core * 1.4 + halo + (fx + fy) * 0.55) * size * tw * smoothstep(0.0, 0.08, out_);\n    lab.x += star * 0.7;\n    vec3 tint = i == 1 || i == 2 ? hzCol(4) : hzCol(1);\n    lab.yz = mix(lab.yz, tint.yz * 0.6, clamp(star, 0.0, 1.0));\n  }\n\n  lab.x *= vignette;\n  return lab + u_bg;\n}\n`,\n  wgsl: () => import(\"./wgsl/horizon\").then((module) => module.wgsl),\n  label: \"Horizon\",\n  name: \"horizon\",\n};\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/horizon.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/limb.ts",
      "content": "import type { GradientKindDefinition } from \"../kind\";\nimport { pick } from \"../kind\";\n\nexport const limb: GradientKindDefinition = {\n  defaults: {\n    background: \"#030308\",\n    blur: 0.35,\n    colors: [\"#e9ecff\", \"#8a8bff\", \"#4b2bd6\", \"#160c3a\"],\n    dither: { cell: 3, enabled: false, levels: 8 },\n    grain: 0.16,\n    interaction: { pointer: 0.15, scroll: 0.1 },\n    loopSeconds: 20,\n    scale: 1,\n    seed: 1,\n    speed: 0.5,\n    warp: 0.5,\n  },\n  description:\n    \"The lit edge of a planet or moon against the dark: a thin bright crest over a soft atmosphere.\",\n  fallbackLayers: (colors) => [\n    `radial-gradient(120% 120% at 50% 130%, transparent 58%, color-mix(in oklab, ${pick(colors, 3)} 50%, transparent) 61%, color-mix(in oklab, ${pick(colors, 2)} 70%, transparent) 64%, color-mix(in oklab, ${pick(colors, 1)} 75%, transparent) 66%, color-mix(in oklab, ${pick(colors, 0)} 80%, transparent) 67%, transparent 70%)`,\n  ],\n  glsl: `\n// A planet much larger than the frame, or a moon inside it, lit from one\n// side. The light is three layers: a thin crest at the edge, a saturated\n// band just inside it, and atmosphere glowing just outside. warp sets how\n// far the light wraps round; blur softens every layer.\nvec3 kindColor(vec2 p, vec2 uv) {\n  vec2 h = frameHalf();\n  // The seed picks the body: a planet whose top arc crosses the frame, a\n  // horizon tilted across the frame, a moon lit from the side, a planet\n  // hanging from the top edge, a planet filling one side, a planet crossing\n  // the frame on a diagonal, or a small moon lit from behind, ringed in light.\n  float framing = floor(fract(u_seed.x * 0.0731 + 0.5) * 7.0);\n  float side = sign(u_seed.y + 0.01);\n  float tilt = sin(seedAngle());\n  float radius = 0.95;\n  vec2 centre = vec2(0.0, -1.02 + (1.0 - u_scale) * 0.3);\n  // Arcs are lit from a little off overhead, so one end of the arc fades.\n  float lightAngle = 0.5 * tilt;\n  float backlit = 0.0;\n  if (framing == 1.0) {\n    radius = 2.6;\n    centre = vec2(0.9 * side, -2.62);\n    lightAngle = side * 0.35 + 0.2 * tilt;\n  } else if (framing == 2.0) {\n    radius = 0.3;\n    centre = vec2(0.18 * h.x * side, 0.0);\n    lightAngle = side * 1.9 + 0.2 * tilt;\n  } else if (framing == 3.0) {\n    radius = 1.1;\n    centre = vec2(0.2 * side, 1.38);\n    lightAngle = 3.14159265 + 0.4 * tilt;\n  } else if (framing == 4.0) {\n    radius = 1.3;\n    centre = vec2(-side * (h.x + 0.98), -0.15);\n    lightAngle = side * (1.45 + 0.2 * tilt);\n  } else if (framing == 5.0) {\n    radius = 1.25;\n    centre = vec2(-side * (h.x + 0.5), -h.y - 0.62);\n    lightAngle = side * 0.78;\n  } else if (framing == 6.0) {\n    radius = 0.2;\n    centre = vec2(0.0, 0.02);\n    lightAngle = 0.4 * tilt;\n    backlit = 1.0;\n  }\n  radius *= u_scale;\n  lightAngle += 0.9 * u_loop.y;\n  vec2 light = vec2(sin(lightAngle), cos(lightAngle));\n\n  vec2 d = p - centre;\n  float r = length(d);\n  vec2 dir = d / max(r, 1e-4);\n  float x = r - radius;\n\n  // How squarely each point of the rim faces the light. warp lets the\n  // light wrap further round the body.\n  float facing = dot(dir, light);\n  float lit = smoothstep(-0.15 - 0.6 * u_warp, 0.95, facing);\n  lit *= lit;\n  // A body lit from behind glows all the way round.\n  lit = mix(lit, 0.45 + 0.55 * lit, backlit);\n\n  // The atmosphere breathes and drifts along the arc.\n  float shimmer = 0.7 + 0.3 * flowNoise(dir * 2.4 + vec2(x * 3.0, 0.0), 1.0);\n  // A small backlit moon shows its whole rim, so keep its outline round.\n  shimmer = mix(shimmer, 1.0, 0.7 * backlit);\n\n  float b = 0.6 + 0.8 * u_blur;\n  float inside = 1.0 - smoothstep(-0.006 * b, 0.004 * b, x);\n  // Outside the edge: a pale atmosphere band that holds, then fades.\n  // The atmosphere breathes with the loop phase: the same depth at any\n  // speed above 0.5, fading out toward a still frame at speed 0, and never\n  // thinner than 0.5x, so the falloff below never divides by zero.\n  float loopR = length(u_loop);\n  float breath = loopR > 1e-4 ? (u_loop.x / loopR) * min(loopR / 0.3, 1.0) : 0.0;\n  float atmosW = 0.07 * b * (0.7 + 0.6 * u_warp) * (1.0 + 0.5 * breath);\n  float xa = max(x, 0.0) / atmosW;\n  float atmos = smoothstep(-0.02 * b, 0.0, x) / (1.0 + xa * xa * xa * xa);\n  // The edge itself, in the saturated colour, then the body falling away.\n  float edgeBand = exp(-pow(x / (0.03 * b), 2.0));\n  float band = inside * exp(x / (0.09 * b));\n  float deep = inside * exp(x / (0.35 * b));\n  float halo = exp(-max(x, 0.0) / (0.18 * b));\n\n  float glow = (0.6 * atmos * shimmer + 0.8 * edgeBand + 0.6 * band + 0.25 * deep + 0.12 * halo) * lit;\n\n  // The atmosphere in colour 0, the edge in 1, the body through 2 to the last.\n  vec3 col = labMix(paletteColor(2), paletteColor(u_count - 1), clamp(1.0 - band, 0.0, 1.0));\n  col = labMix(col, paletteColor(1), clamp(edgeBand * 1.1 + 0.5 * band, 0.0, 1.0));\n  col = labMix(col, paletteColor(0), clamp(0.8 * atmos * (0.75 + 0.25 * shimmer) * smoothstep(-0.004, 0.025 * b, x), 0.0, 1.0));\n\n  vec3 lab = labMix(u_bg, col, clamp(glow, 0.0, 1.0));\n  return filmGrade(lab);\n}\n`,\n  wgsl: () => import(\"./wgsl/limb\").then((module) => module.wgsl),\n  label: \"Limb\",\n  name: \"limb\",\n};\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/limb.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/linear-flow.ts",
      "content": "import type { GradientKindDefinition } from \"../kind\";\nimport { stops } from \"../kind\";\n\nexport const linearFlow: GradientKindDefinition = {\n  defaults: {\n    background: \"#06070c\",\n    blur: 0.5,\n    colors: [\"#c13b3b\", \"#140a0e\", \"#2c55c5\", \"#eef2ff\"],\n    dither: { cell: 3, enabled: false, levels: 8 },\n    grain: 0.08,\n    interaction: { pointer: 0.15, scroll: 0.15 },\n    loopSeconds: 18,\n    scale: 1,\n    seed: 21,\n    speed: 0.5,\n    warp: 0.22,\n  },\n  description:\n    \"A directional blend with bowed light lines and a soft light leak.\",\n  fallbackLayers: (colors) => [`linear-gradient(120deg, ${stops(colors)})`],\n  glsl: `\nvec3 kindColor(vec2 p, vec2 uv) {\n  vec2 h = frameHalf();\n  float angle = 0.6 + 1.2 * (fract(u_seed.y * 0.137) - 0.5) + 0.3 * u_loop.y;\n  vec2 dir = vec2(cos(angle), sin(angle));\n  vec2 perp = vec2(-dir.y, dir.x);\n  float extent = abs(dir.x) * h.x + abs(dir.y) * h.y;\n  float a = dot(p, dir) / extent;\n  float b = dot(p, perp) / extent;\n  // Iso-lines bow, as if the light wraps round a curved surface.\n  float s = a + 0.16 * b * b - 0.05;\n  s += u_warp * 0.18 * flowNoise(p * 0.6 * u_scale, 1.0);\n  float t = clamp(0.5 + 0.5 * s * u_scale, 0.0, 1.0);\n  vec3 lab = ramp(t * t * (3.0 - 2.0 * t));\n\n  // Light leak: a soft streak along the iso-lines toward the bright end.\n  float w = 0.1 + 0.18 * u_blur;\n  float sd = (s - 0.5 + 0.08 * flowNoise(vec2(b * 1.1, 3.0), 2.0)) / w;\n  float streak = exp(-sd * sd) * (0.65 + 0.35 * flowNoise(vec2(b * 2.2, 7.0), 3.0));\n  lab.x += 0.12 * streak;\n  lab.yz *= 1.0 - 0.3 * streak;\n\n  // The dark end falls into shadow and the corners sink toward the base colour.\n  float dark = 1.0 - smoothstep(0.55, 0.85, u_bg.x);\n  lab.x *= mix(1.0, mix(0.72, 1.0, smoothstep(-1.2, 0.1, s)), dark);\n  float corner = smoothstep(0.45, 1.15, length(p / h) * 0.75);\n  lab = labMix(lab, u_bg, corner * 0.3);\n  lab.x *= vignette(p, 0.2 * dark);\n  return filmGrade(lab);\n}\n`,\n  wgsl: () => import(\"./wgsl/linear-flow\").then((module) => module.wgsl),\n  label: \"Linear flow\",\n  name: \"linear-flow\",\n};\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/linear-flow.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/mesh.ts",
      "content": "import type { GradientKindDefinition } from \"../kind\";\nimport { pick } from \"../kind\";\n\nconst BLOBS = [\n  [16, 20],\n  [84, 26],\n  [72, 86],\n  [22, 80],\n  [52, 48],\n  [92, 62],\n] as const;\n\nexport const mesh: GradientKindDefinition = {\n  defaults: {\n    background: \"#0a0d24\",\n    blur: 0.45,\n    colors: [\"#ecdcf2\", \"#8796ee\", \"#2e45b7\", \"#0e1645\"],\n    dither: { cell: 3, enabled: false, levels: 8 },\n    grain: 0.1,\n    interaction: { pointer: 0.2, scroll: 0.1 },\n    loopSeconds: 14,\n    scale: 1,\n    seed: 42,\n    speed: 0.6,\n    warp: 0.4,\n  },\n  description: \"Soft, lit colour fields drifting through each other.\",\n  fallbackLayers: (colors) =>\n    colors.map((_, i) => {\n      const [x, y] = BLOBS[i % BLOBS.length] ?? [50, 50];\n      return `radial-gradient(85% 95% at ${x}% ${y}%, ${pick(colors, i)} 0%, transparent 68%)`;\n    }),\n  glsl: `\nvec3 kindColor(vec2 p, vec2 uv) {\n  vec2 h = frameHalf();\n  // The palette marches from a lit corner to the far one: colour 0 sits in\n  // the light, the last colour in the shadow.\n  float theta = seedAngle();\n  vec2 axis = vec2(cos(theta), sin(theta));\n  vec2 side = vec2(-axis.y, axis.x);\n  float span = abs(axis.x) * h.x + abs(axis.y) * h.y;\n  vec2 q = p + u_warp * 0.14 * vec2(\n    flowNoise(p * 1.2 * u_scale, 1.0),\n    flowNoise(p * 1.2 * u_scale + 4.1, 2.0)\n  );\n  float sigma = (0.22 + 0.2 * u_blur) / u_scale;\n  float inv = 1.0 / (sigma * sigma);\n  float count = float(u_count);\n  float wb = 0.06;\n  vec3 lab = u_bg * wb;\n  float chroma = length(u_bg.yz) * wb;\n  float total = wb;\n  for (int i = 0; i < 6; i++) {\n    if (i >= u_count) break;\n    float fi = float(i);\n    float k = fi / max(1.0, count - 1.0);\n    float zig = (mod(fi, 2.0) * 2.0 - 1.0) * (0.25 + 0.5 * fract(fi * 0.618 + 0.3));\n    vec2 c = axis * span * (0.9 - 1.8 * k) + side * span * 0.5 * zig\n      + 0.25 * h * (rot2(fi * 1.7) * u_loop);\n    vec2 d = q - c;\n    // Fields are wider across the axis than along it: soft bands of light.\n    d = vec2(dot(d, axis) * 1.2, dot(d, side) * 0.65);\n    float w = exp(-dot(d, d) * inv);\n    lab += u_colors[i] * w;\n    chroma += length(u_colors[i].yz) * w;\n    total += w;\n  }\n  lab /= total;\n  chroma /= total;\n  float current = length(lab.yz);\n  if (current > 1e-4) {\n    lab.yz *= mix(1.0, chroma / current, 0.85);\n  }\n  lab.x += 0.05 * dot(p, axis) / span;\n  // One long silk fold across the frame: a lit crest, then the cloth turns\n  // into shadow behind it.\n  float along = dot(q, side);\n  float crest = 0.16 * sin(along * 1.6 + 0.8 * dot(u_loop, vec2(0.6, 0.8)) + theta)\n    + 0.08 * flowNoise(vec2(along * 0.6, 2.0), 3.0);\n  float acrossFold = dot(q, axis) - crest;\n  float fw = 0.05 + 0.08 * u_blur;\n  lab.x += 0.06 * exp(-acrossFold * acrossFold / (fw * fw)) - 0.07 * smoothstep(0.0, 0.5, -acrossFold);\n  lab.x *= vignette(p, 0.18);\n  return filmGrade(lab);\n}\n`,\n  label: \"Mesh\",\n  name: \"mesh\",\n  wgsl: () => import(\"./wgsl/mesh\").then((module) => module.wgsl),\n};\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/mesh.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/mist.ts",
      "content": "import type { GradientKindDefinition } from \"../kind\";\nimport { pick, stops } from \"../kind\";\n\nexport const mist: GradientKindDefinition = {\n  defaults: {\n    background: \"#040407\",\n    blur: 0.55,\n    colors: [\"#f4d9ff\", \"#a77bff\", \"#3b2a9e\", \"#120d33\"],\n    dither: { cell: 3, enabled: false, levels: 8 },\n    grain: 0.14,\n    interaction: { pointer: 0.2, scroll: 0.15 },\n    loopSeconds: 18,\n    scale: 1,\n    seed: 2,\n    speed: 0.5,\n    warp: 0.45,\n  },\n  description:\n    \"Out-of-focus folds of light: a curved edge glowing against the dark.\",\n  fallbackLayers: (colors) => [\n    `radial-gradient(120% 70% at 70% 100%, ${stops(colors, 0, 80)}, transparent 100%)`,\n    `linear-gradient(160deg, transparent 40%, color-mix(in oklab, ${pick(colors, 1)} 40%, transparent) 70%, transparent 95%)`,\n  ],\n  glsl: `\n// Signed distance-ish to one fold: a broad S-curve across the frame.\n// Negative on the lit side.\nfloat mistFold(vec2 q, float layer, float amp) {\n  float bend = amp * sin(q.x * 1.6 * u_scale + 0.9 * layer + 0.35 * u_loop.y)\n    + (0.08 + 0.22 * u_warp) * flowNoise(vec2(q.x * 0.55 * u_scale, layer * 2.3), layer);\n  return q.y - bend - 0.12 * q.x;\n}\n\nvec3 kindColor(vec2 p, vec2 uv) {\n  vec2 h = frameHalf();\n  float lightBg = smoothstep(0.55, 0.85, u_bg.x);\n  float a = seedAngle();\n  // Mostly near-horizontal folds; the seed tilts and flips them.\n  float tilt = 0.55 * sin(a) + (cos(a) < 0.0 ? 3.14159265 : 0.0);\n  vec2 q = rot2(tilt) * p;\n  float x = q.x / max(h.x, 1e-3);\n\n  // The fold drifts slowly up and down through the loop.\n  float lift = 0.05 * flowNoise(vec2(0.21, 0.67), 7.0);\n  float s = mistFold(q + vec2(0.0, lift), 1.0, 0.16);\n  // Along-fold shading: long, soft streaks like light on satin.\n  float sheen = flowNoise(vec2(q.x * 0.9 * u_scale, s * 4.0 / (0.5 + u_blur)), 2.0);\n\n  // Lit side: the palette runs from the hot lip into its deep colours.\n  float span = 0.45 + 0.35 * u_blur;\n  float lit = clamp(-s / span, 0.0, 1.0);\n  vec3 col = ramp(0.12 + 0.88 * pow(lit, 0.8));\n  // Light spilling past the fold takes the second colour, not white.\n  col = labMix(col, paletteColor(1), smoothstep(0.0, 0.2, s) * 0.8);\n  float soft = 0.02 + 0.09 * u_blur;\n  float side = 1.0 - smoothstep(-soft, soft, s);\n  // Light falls off into the far side and fades deep into the lit side.\n  float spill = exp(-max(s, 0.0) / (0.05 + 0.18 * u_blur));\n  float depth = exp(-max(-s - 0.1, 0.0) / (0.35 + 0.45 * u_blur));\n  float amount = max(side * mix(0.3, 1.0, depth), spill * 0.7);\n  amount *= 0.86 + 0.18 * sheen;\n  // Depth of field: the fold sharpens near the middle of the frame.\n  amount *= 1.0 - 0.25 * smoothstep(0.6, 1.2, abs(x));\n\n  vec3 lab = labMix(u_bg, col, clamp(amount, 0.0, 1.0));\n  // The lip: bright on dark grounds, an ink crease on light ones.\n  float lipW = 0.02 + 0.06 * u_blur;\n  // The lip sits just inside the lit side, so it reads as light catching the\n  // fold rather than a line drawn on it.\n  float sl = s + 0.6 * lipW;\n  float lip = exp(-sl * sl / (lipW * lipW)) * (0.75 + 0.25 * sheen);\n  vec3 hot = vec3(min(1.0, paletteColor(0).x + 0.05), paletteColor(0).yz * 0.85);\n  vec3 ink = vec3(paletteColor(u_count - 1).x * 0.6, paletteColor(u_count - 1).yz);\n  lab = labMix(lab, mix(hot, ink, lightBg), clamp(lip * (0.22 + 0.05 * lightBg), 0.0, 1.0));\n\n  // A second, fainter fold behind, offset so the frame has depth.\n  float s2 = mistFold(q * vec2(0.8, 1.0) + vec2(0.7, -0.32 + lift), 4.0, 0.22);\n  float back = (1.0 - smoothstep(-0.25, 0.08 + 0.1 * u_blur, s2)) * exp(-max(-s2, 0.0) / 0.5);\n  back *= 1.0 - side;\n  lab = labMix(lab, ramp(0.55), clamp(back * 0.35 * (0.8 + 0.2 * sheen), 0.0, 1.0));\n\n  lab.x *= vignette(p, 0.25 * (1.0 - lightBg));\n  return filmGrade(lab);\n}\n`,\n  wgsl: () => import(\"./wgsl/mist\").then((module) => module.wgsl),\n  label: \"Mist\",\n  name: \"mist\",\n};\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/mist.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/pixel-glass.ts",
      "content": "import type { GradientKindDefinition } from \"../kind\";\n\n/**\n * Light seen through a wall of square glass blocks. Behind the glass, one\n * soft blob per colour drifts on its own path. Each block takes one clear\n * tone from the light behind its centre and refracts the patch around it\n * like a small lens, then catches the light on a bevelled edge that faces\n * the brightest neighbour, with a pressed inner face and a dark grout seam.\n * The brightest cells bloom over the grout. The glass stays put and only\n * the light behind it moves.\n *\n * Params: `scale` sets the block size (about 14 blocks across the short side\n * at 1), `warp` the lens strength (0 is flat glass, 1 flips each block's\n * image), `blur` the softness of the blobs. The seed lays the blobs out.\n * Pale backgrounds read as frosted glass on paper, dark ones as a lit wall\n * at night.\n *\n * Helpers are prefixed `pg` and only depend on the prelude.\n */\nexport const pixelGlass: GradientKindDefinition = {\n  defaults: {\n    background: \"#f4f3f1\",\n    blur: 0.55,\n    colors: [\"#7a3cff\", \"#ff4fb8\", \"#3d6bff\"],\n    dither: { cell: 3, enabled: false, levels: 8 },\n    grain: 0.05,\n    interaction: { pointer: 0.2, scroll: 0 },\n    loopSeconds: 20,\n    scale: 1,\n    seed: 4,\n    speed: 0.5,\n    warp: 0.5,\n  },\n  description:\n    \"Soft colour drifting behind a wall of square glass blocks, each a small lens.\",\n  // One soft blob per colour, along a loose arc.\n  fallbackLayers: (colors) =>\n    colors.map(\n      (color, i) =>\n        `radial-gradient(${24 - 3 * i}% ${30 - 3 * i}% at ${34 + 16 * i}% ${50 - 8 * (i % 2)}%, ${color}, transparent 72%)`,\n    ),\n  glsl: `\n// The light behind the glass: one soft, elongated blob per colour.\nvec3 pgScene(vec2 q, vec2 h) {\n  vec3 lab = u_bg;\n  float lightBg = smoothstep(0.55, 0.85, u_bg.x);\n  float a0 = seedAngle();\n  float size = (0.17 + 0.1 * u_blur);\n  // The cluster leans off centre, toward an edge picked by the seed.\n  vec2 lean = vec2(cos(a0 + 1.3), sin(a0 + 1.3)) * vec2(0.32, 0.3) * h;\n  for (int i = 0; i < 6; i++) {\n    if (i >= u_count) break;\n    float fi = float(i);\n    // A loose arc of blobs, big first, each drifting on its own circle.\n    float a = a0 + fi * 2.1;\n    vec2 base = vec2(cos(a) * 0.42 * h.x, sin(a) * 0.3 * h.y) * min(fi, 1.0) * (0.8 + 0.25 * fi);\n    vec2 c = lean + base + vec2(0.55, 0.38) * drift(fi + 1.0);\n    float r = size * (1.0 - 0.5 * min(fi, 1.0) / (1.0 + 0.4 * fi)) * mix(1.0, 1.15, lightBg);\n    vec2 d = rot2(a * 0.5 + 0.4 * fi) * (q - c);\n    d *= vec2(0.62, 1.0);\n    float k = dot(d, d) / (r * r);\n    float w = exp(-k * (1.3 - 0.6 * u_blur));\n    // A brighter, shifted rim, the way colour pools at a blob's edge.\n    vec3 col = paletteColor(i);\n    vec3 rim = labMix(col, paletteColor(i + 1), 0.55);\n    col = labMix(col, rim, smoothstep(0.15, 0.9, k) * 0.7);\n    lab = labMix(lab, col, clamp(w * 1.15, 0.0, 1.0));\n  }\n  return lab;\n}\n\n// How far the palette stands from the background. Clear glass over a plain\n// ground is invisible, so with nothing to bend the wall disappears and a\n// flat palette renders flat.\nfloat pgGlass() {\n  float most = 0.0;\n  for (int i = 0; i < 6; i++) {\n    if (i >= u_count) break;\n    most = max(most, length(u_colors[i] - u_bg));\n  }\n  return clamp(most * 7.0, 0.0, 1.0);\n}\n\n// Lightness of the light behind the glass, for a block's shading to face.\nfloat pgLight(vec2 q, vec2 h) {\n  return pgScene(q, h).x;\n}\n\nvec3 kindColor(vec2 p, vec2 uv) {\n  vec2 h = frameHalf();\n  float minSide = min(u_full.x, u_full.y);\n  float lightBg = smoothstep(0.55, 0.85, u_bg.x);\n  // Whole pixels per block, so the grid is crisp at any size.\n  float block = max(8.0, floor(minSide * 0.072 / u_scale + 0.5));\n  vec2 px = uv * u_full;\n  // Centre the grid on the frame.\n  vec2 g = px - 0.5 * u_full;\n  vec2 id = floor(g / block);\n  vec2 inPx = g - id * block;\n  vec2 lp = inPx / block - 0.5;\n  lp.y = -lp.y;\n  vec2 c = (id + 0.5) * block / minSide;\n  c.y = -c.y;\n  vec2 ci = interact(c);\n  float cell = block / minSide;\n\n  // Each block holds one clear tone, the light behind its centre, so the\n  // wall reads as crisp cells rather than a smudge. Inside, the block is a\n  // small lens: it shows the patch behind it squeezed (warp 0.5) or flipped\n  // (warp 1), which keeps every cell's edge distinct from its neighbour's.\n  vec3 tone = pgScene(ci, h);\n  float lens = mix(0.6, -0.9, u_warp);\n  vec3 seenThrough = pgScene(ci + 1.6 * cell * lens * lp, h);\n  vec3 lab = labMix(tone, seenThrough, 0.55);\n\n  // Which way the light brightens across this block: the side facing it\n  // catches the bevel, the far side falls into shade.\n  float e = 0.75 * cell;\n  vec2 grad = vec2(\n    pgLight(ci + vec2(e, 0.0), h) - pgLight(ci - vec2(e, 0.0), h),\n    pgLight(ci + vec2(0.0, e), h) - pgLight(ci - vec2(0.0, e), h)\n  );\n  float slope = length(grad);\n  vec2 toLight = normalize(mix(vec2(-0.7071, 0.7071), grad / max(slope, 1e-4), smoothstep(0.002, 0.03, slope)));\n\n  // How much light this block passes, against the bare background.\n  float glow = clamp((tone.x - u_bg.x) * mix(3.0, -3.0, lightBg), 0.0, 1.0);\n  // Unlit blocks still show as faint glass, so the wall reads edge to edge.\n  float glass = pgGlass();\n  float lit = max(glow, mix(0.18, 0.35, lightBg) * glass);\n\n  // A convex block: brighter toward the light, falling off to its rim.\n  float r = max(abs(lp.x), abs(lp.y));\n  float facing = dot(lp, toLight) / 0.5;\n  lab.x += lit * (0.05 * facing - 0.07 * smoothstep(0.22, 0.5, r)) * mix(1.0, 0.5, lightBg);\n  // A broad sheen where the lens focuses the light, toward its source.\n  vec2 spot = lp - 0.18 * toLight;\n  lab.x += glow * 0.05 * exp(-dot(spot, spot) * 9.0) * mix(1.0, 0.4, lightBg);\n\n  // Bevel: a bright lip on the edges that face the light, shade opposite.\n  vec2 fromEdge = min(inPx, block - inPx);\n  float edgePx = min(fromEdge.x, fromEdge.y);\n  float lipWidth = max(1.5, block * 0.07);\n  float lip = 1.0 - smoothstep(0.0, lipWidth, edgePx);\n  vec2 side = abs(lp.x) > abs(lp.y) ? vec2(sign(lp.x), 0.0) : vec2(0.0, sign(lp.y));\n  float toward = dot(side, toLight);\n  lab.x += lip * lit * (toward > 0.0 ? 0.11 * toward : 0.06 * toward) * mix(1.0, 0.45, lightBg);\n\n  // Glass blocks are pressed with a recessed inner face: a thin ring a\n  // third of the way in, shaded on the side toward the light.\n  float ringPx = abs(r - 0.32) * block;\n  float ring = 1.0 - smoothstep(0.0, max(1.0, block * 0.022), ringPx);\n  float inner = dot(side, toLight);\n  lab.x += ring * lit * (0.03 - 0.07 * inner) * mix(1.0, 0.5, lightBg);\n\n  // Grout: a dark seam between blocks, a little wider on big blocks.\n  float grout = max(1.0, block * 0.03);\n  float seam = 1.0 - smoothstep(grout - 0.5, grout + 0.5, edgePx);\n  lab = labMix(lab, u_bg * vec3(mix(0.55, 0.9, lightBg), 1.0, 1.0), seam * glass * mix(0.85, 0.5, lightBg));\n\n  // Where the light is strongest it blooms past the glass and over the\n  // grout, so the bright cells glow instead of sitting flat.\n  vec2 q = interact(vec2(g.x, -g.y) / minSide);\n  vec3 halo = pgScene(q, h);\n  float bloom = clamp((halo.x - u_bg.x) * mix(1.0, -1.0, lightBg), 0.0, 1.0);\n  lab = labMix(lab, halo, 0.32 * bloom * bloom * (1.0 - lightBg));\n  return filmGrade(lab);\n}\n`,\n  label: \"Pixel glass\",\n  name: \"pixel-glass\",\n  wgsl: () => import(\"./wgsl/pixel-glass\").then((module) => module.wgsl),\n};\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/pixel-glass.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/radial-glow.ts",
      "content": "import type { GradientKindDefinition } from \"../kind\";\nimport { pick } from \"../kind\";\n\nfunction haze(colors: readonly string[]): string {\n  const last = Math.max(1, colors.length - 1);\n  return colors\n    .map(\n      (color, i) =>\n        `color-mix(in oklab, ${color} ${Math.round(45 - (30 * i) / last)}%, transparent) ${(29 + (40 * i) / last).toFixed(1)}%`,\n    )\n    .join(\", \");\n}\n\nexport const radialGlow: GradientKindDefinition = {\n  defaults: {\n    background: \"#020204\",\n    blur: 0.45,\n    colors: [\"#f3f1ff\", \"#9db4ff\", \"#5a46cb\", \"#1d1240\"],\n    dither: { cell: 3, enabled: false, levels: 8 },\n    grain: 0.14,\n    interaction: { pointer: 0.2, scroll: 0.1 },\n    loopSeconds: 14,\n    scale: 1,\n    seed: 11,\n    speed: 0.6,\n    warp: 0.5,\n  },\n  description:\n    \"An eclipse: light spilling round a dark disc, with a corona and god rays.\",\n  fallbackLayers: (colors) => [\n    `radial-gradient(42% 58% at 50% 82%, transparent 54%, color-mix(in oklab, ${pick(colors, 0)} 80%, transparent) 58%, color-mix(in oklab, ${pick(colors, 1)} 45%, transparent) 64%, transparent 82%)`,\n    // Haze outside the ring only, so the disc keeps the background colour.\n    `radial-gradient(84% 116% at 50% 82%, transparent 27%, ${haze(colors)}, transparent 85%)`,\n  ],\n  glsl: `\nvec3 kindColor(vec2 p, vec2 uv) {\n  // Light-mode backgrounds get a glowing halo instead of a dark disc.\n  float lightBg = smoothstep(0.55, 0.85, u_bg.x);\n  // The seed picks a layout: a disc rising from the bottom edge, a full ring\n  // in the frame, or the rim of a planet low and off to one side.\n  vec2 h = frameHalf();\n  float framing = fract(u_seed.x * 0.0731 + 0.5);\n  float radius = 0.34;\n  vec2 centre = vec2(0.0, -0.3);\n  float spread = 0.28;\n  if (framing > 0.7) {\n    radius = 0.75;\n    centre = vec2(0.35 * h.x * sign(u_seed.y), -0.95);\n    spread = 0.1;\n  } else if (framing > 0.4) {\n    radius = 0.26;\n    centre = vec2(0.0, -0.04);\n    spread = 0.6;\n  }\n  radius /= u_scale;\n  centre.y -= 0.04 * flowNoise(vec2(0.3, 0.7), 1.0);\n  vec2 d = p - centre;\n  float r = length(d);\n  vec2 dir = d / max(r, 1e-4);\n  float x = r - radius;\n  float xo = max(x, 0.0);\n  float soft = (0.01 + 0.045 * u_blur) * (1.0 + 5.0 * lightBg);\n\n  // The source sits behind the disc, so the top of the rim is lit hardest.\n  // The source drifts round behind the disc, so the hot side wanders.\n  float sweep = 1.3 * u_loop.x;\n  vec2 up = vec2(sin(sweep), cos(sweep));\n  float facing = 0.5 + 0.5 * dot(dir, up) * smoothstep(0.0, radius, r);\n  float key = mix(spread, 1.0, facing * facing);\n\n  // God rays: noise sampled on the unit circle, so they radiate with no seam,\n  // fine in angle and drifting slowly outward in radius.\n  float rays = 0.5 + 0.5 * flowNoise(dir * 2.6 - vec2(0.0, r * 0.35), 2.0);\n  rays = mix(rays, 0.5 + 0.5 * flowNoise(dir * 6.0 - vec2(r * 0.5, 0.0), 3.0), 0.35);\n  rays = mix(1.0, 0.25 + 1.3 * rays * rays, u_warp);\n\n  float rim = exp(-xo / soft);\n  float corona = exp(-xo / (0.05 + 0.1 * u_blur));\n  float haze = exp(-xo / (0.3 + 0.3 * u_blur));\n  // A thin halo ring just outside the rim, in the palette's middle colour.\n  float ringD = (x - 0.05 - 0.04 * u_blur) / ((0.018 + 0.03 * u_blur) * (1.0 + 2.0 * lightBg));\n  float ring = exp(-ringD * ringD);\n  float glow = (rim + 0.5 * corona * (0.6 + 0.4 * rays) + (0.4 + 0.35 * lightBg) * haze * mix(1.0, rays, 0.8) + 0.35 * ring) * key;\n\n  // Inside: the occluder, with a hairline of light just inside its edge.\n  float inside = 1.0 - smoothstep(-soft * 0.5, soft * 0.5, x);\n  float innerRim = exp(min(x, 0.0) / (0.01 + 0.12 * lightBg));\n  glow = mix(glow, (0.3 * innerRim + 0.06) * key, inside * (1.0 - 0.85 * lightBg));\n\n  // Palette runs outward from the rim; the hottest light bleaches toward white.\n  // A dark disc hides the rim, so colour can rise sharply there; a light\n  // glow has no disc edge to hide behind, so it eases in.\n  float reach = clamp(xo / (0.6 + 0.3 * u_blur), 0.0, 1.0);\n  float t = mix(sqrt(reach), smoothstep(0.0, 0.7, reach), lightBg);\n  vec3 col = ramp(t);\n  vec3 hot = vec3(min(1.0, paletteColor(0).x + 0.06), paletteColor(0).yz * 0.4);\n  col = labMix(col, hot, rim * (1.0 - inside) * (0.45 + 0.5 * lightBg));\n  col = labMix(col, paletteColor(2), ring * (0.6 - 0.35 * lightBg) * (1.0 - rim));\n\n  vec3 base = u_bg;\n  base.x *= mix(1.0, mix(0.35, 1.0, lightBg), inside);\n  vec3 lab = labMix(base, col, clamp(glow, 0.0, 1.0));\n  lab.x += 0.1 * max(glow - 0.9, 0.0);\n  lab.x *= vignette(p, 0.3 * (1.0 - lightBg));\n  return filmGrade(lab);\n}\n`,\n  wgsl: () => import(\"./wgsl/radial-glow\").then((module) => module.wgsl),\n  label: \"Radial glow\",\n  name: \"radial-glow\",\n};\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/radial-glow.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/ribbon.ts",
      "content": "import type { GradientKindDefinition } from \"../kind\";\nimport { pick, stops } from \"../kind\";\n\n/**\n * Two twisting ribbons crossing the frame. The palette runs across each\n * ribbon's width, so it reads as stripes printed on a strip; as a ribbon\n * turns edge-on it narrows to a bright crease and shows its back. Edges go\n * from crisp to soft along the length, like a shallow depth of field, and\n * fine threads run parallel to the edges. Works on light and dark grounds.\n *\n * `scale` zooms in or out, `warp` adds twist and swing, `blur` softens the\n * edges and the far ribbon.\n */\nexport const ribbon: GradientKindDefinition = {\n  defaults: {\n    background: \"#ffffff\",\n    blur: 0.35,\n    colors: [\"#ff3d9a\", \"#ff8a3d\", \"#ffc83d\", \"#7a5cff\"],\n    dither: { cell: 3, enabled: false, levels: 8 },\n    grain: 0.06,\n    interaction: { pointer: 0.15, scroll: 0.25 },\n    loopSeconds: 22,\n    scale: 1,\n    seed: 2,\n    speed: 0.6,\n    warp: 0.45,\n  },\n  description: \"Twisting ribbons with stripes of colour across their width.\",\n  fallbackLayers: (colors) => [\n    `linear-gradient(155deg, transparent 30%, ${stops(colors, 32, 52)}, transparent 54%)`,\n    `linear-gradient(28deg, transparent 52%, color-mix(in oklab, ${pick(colors, 1)} 60%, transparent) 58%, transparent 66%)`,\n  ],\n  glsl: `\n// cos(a - angle), where cs = (cos, sin)(angle); turnSin is its sine twin.\nfloat ribbonCos(float a, vec2 cs) {\n  return cos(a) * cs.x + sin(a) * cs.y;\n}\n\n// Draws one ribbon over lab. far is 0 for the near ribbon, 1 for the far one.\nvec3 ribbonLayer(vec3 lab, vec2 p, float angle, float offset, float layer, float far, float ph, vec2 t1, vec2 t2, float lightBg) {\n  vec2 q = rot2(angle) * p * u_scale;\n  float s = q.x;\n  float amp = 0.1 + 0.12 * u_warp;\n  float a1 = 1.5 * s + layer + 2.0 * ph;\n  float a2 = 2.9 * s + 2.0 * layer - ph;\n  float wobble = 0.03 * flowNoise(vec2(s * 0.6, layer), layer);\n  float centre = offset + amp * turnSin(a1, t1) + 0.04 * turnSin(a2, t2) + wobble;\n  float dc = amp * 1.5 * ribbonCos(a1, t1) + 0.116 * ribbonCos(a2, t2);\n  float dist = (q.y - centre) / sqrt(1.0 + dc * dc);\n\n  // Twist: the strip turns about its centre line as it travels.\n  float twist = (0.6 + 1.1 * u_warp) * s + 1.7 * layer + 0.6 + 1.3 * ph;\n  float turn = ribbonCos(twist, t1);\n  float facing = abs(turn);\n  float width = (0.23 - 0.08 * far) * (0.12 + 0.88 * facing) + 0.002;\n  float u = dist / width;\n  // Which face we see, softened so the flip at edge-on has no seam.\n  float side = turn / (facing + 0.12);\n\n  // Focus drifts along the ribbon: crisp in places, soft in others.\n  float focus = smoothstep(-0.4, 0.8, sin(0.9 * s + 1.3 * layer + 0.5 - ph));\n  float px = u_scale / min(u_full.x, u_full.y);\n  float soft = 1.5 * px + (0.004 + 0.05 * u_blur) * (1.0 - focus) + 0.04 * far * (0.4 + u_blur);\n  float alpha = 1.0 - smoothstep(width - soft, width + soft, abs(dist));\n\n  // Colour runs across the width; the back of the strip reads the other way.\n  float slide = 0.22 * sin(0.8 * s + 2.3 * layer + ph);\n  float across = clamp(0.5 + 0.5 * u * side + slide, 0.0, 1.0);\n  vec3 col = ramp(across);\n  col = labMix(col, u_bg, 0.18 * (1.0 - smoothstep(-0.6, 0.0, side)) + 0.25 * far);\n  // A soft highlight across the slight curl of the strip, stronger face-on.\n  float curl = exp(-pow((u * side - 0.25) / 0.45, 2.0)) * facing;\n  col.x += (0.07 - 0.05 * lightBg) * curl;\n  // The strip's face turns toward and away from a light above the viewer.\n  float lit = abs(0.85 * turn - 0.5 * turnSin(twist, t1));\n  col.x *= mix(mix(0.62, 0.84, lightBg), 1.04, lit);\n  // Threads parallel to the edges, only where the ribbon is in focus.\n  col.x += 0.024 * (1.0 - u_blur) * focus * facing * sin(u * 120.0) * (1.0 - far);\n  // Bright edges, as on a thin sheet of glass.\n  float edge = smoothstep(0.7, 1.0, abs(u)) * facing;\n  col = labMix(col, labMix(ramp(1.0 - across), vec3(1.0, 0.0, 0.0), 0.5 - 0.5 * lightBg), 0.35 * edge);\n\n  float opacity = mix(0.97, 0.88, lightBg) - 0.3 * far;\n  // On a dark ground the ribbon lights the air around it.\n  float halo = exp(-max(abs(dist) - width, 0.0) / (0.03 + 0.08 * u_blur)) * (1.0 - lightBg);\n  lab = labMix(lab, col, 0.22 * halo * opacity);\n  lab = labMix(lab, col, alpha * opacity);\n  // Edge-on, the strip collapses to a bright crease.\n  float crease = exp(-pow(dist / (0.003 + soft), 2.0)) * pow(1.0 - facing, 6.0);\n  vec3 hot = labMix(ramp(0.5), vec3(1.0, 0.0, 0.0), 0.6 - 0.6 * lightBg);\n  lab = labMix(lab, hot, clamp(crease * opacity, 0.0, 1.0));\n  return lab;\n}\n\nvec3 kindColor(vec2 p, vec2 uv) {\n  float sa = seedAngle();\n  vec2 t1 = loopTurn();\n  vec2 t2 = vec2(t1.x * t1.x - t1.y * t1.y, 2.0 * t1.x * t1.y);\n  float lightBg = smoothstep(0.55, 0.75, u_bg.x);\n  float a0 = 0.5 * sin(sa) + 0.25;\n  float a1 = a0 - (0.85 + 0.35 * cos(sa * 1.3));\n  vec3 lab = u_bg;\n  lab = ribbonLayer(lab, p, a1, -0.08 * sin(sa * 1.7), 3.0, 1.0, sa * 1.7, t1, t2, lightBg);\n  lab = ribbonLayer(lab, p, a0, 0.06 * cos(sa * 2.1), 1.0, 0.0, sa * 1.7, t1, t2, lightBg);\n  return filmGrade(lab);\n}\n`,\n  wgsl: () => import(\"./wgsl/ribbon\").then((module) => module.wgsl),\n  label: \"Ribbon\",\n  name: \"ribbon\",\n};\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/ribbon.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/rise.ts",
      "content": "import type { GradientKindDefinition } from \"../kind\";\nimport { pick, stops } from \"../kind\";\n\nexport const rise: GradientKindDefinition = {\n  defaults: {\n    background: \"#030306\",\n    blur: 0.5,\n    colors: [\"#fff1e2\", \"#ff8a3d\", \"#a3301a\", \"#2a0d0a\"],\n    dither: { cell: 3, enabled: false, levels: 8 },\n    grain: 0.12,\n    interaction: { pointer: 0.15, scroll: 0.15 },\n    loopSeconds: 16,\n    scale: 1,\n    seed: 4,\n    speed: 0.6,\n    warp: 0.3,\n  },\n  description:\n    \"A glow rising from past the edge of the frame, like light over a horizon.\",\n  fallbackLayers: (colors, background) => [\n    `radial-gradient(90% 70% at 50% 108%, ${pick(colors, 0)} 0%, ${stops(colors, 22, 70)}, ${background} 100%)`,\n  ],\n  glsl: `\nvec3 kindColor(vec2 p, vec2 uv) {\n  vec2 h = frameHalf();\n  float lightBg = smoothstep(0.55, 0.85, u_bg.x);\n  // The seed picks where the light sits: below the frame (most seeds),\n  // above it, or past a lower corner. A second digit stacks one or two\n  // brighter lips inside the dome, like light caught on layered haze.\n  float placement = fract(u_seed.x * 0.0619 + 0.13);\n  float angle = 0.0;\n  if (placement > 0.85) {\n    angle = 3.14159265;\n  } else if (placement > 0.7) {\n    angle = 0.62;\n  } else if (placement > 0.55) {\n    angle = -0.62;\n  }\n  float lips = floor(fract(u_seed.y * 0.0377 + 0.31) * 3.0);\n  vec2 q = rot2(angle) * p;\n  float reach = abs(cos(angle)) * h.y + abs(sin(angle)) * h.x;\n\n  // A wide dome whose crest sits inside the frame. Small scales make it so\n  // large that only its upper ramp shows: a whole-frame sky.\n  float radius = 0.62 / u_scale;\n  radius *= 1.0 + 0.14 * flowNoise(vec2(0.37, 0.91), 1.0);\n  vec2 centre = vec2(0.5 * flowNoise(vec2(1.7, 0.3), 2.0), -reach - 0.3 * radius + 0.1 * u_loop.y);\n  vec2 d2 = (q - centre) * vec2(0.62, 1.0);\n  float r = length(d2);\n  float x = q.x / max(h.x, 1e-3);\n\n  // The horizon undulates; warp sets how much.\n  float ripple = 0.06 * flowNoise(vec2(q.x * 0.9, 0.5), 3.0)\n    + 0.015 * flowNoise(vec2(q.x * 2.0, 4.5), 4.0);\n  float d = r - radius + u_warp * ripple;\n\n  // Falloff: soft at the crest, softer still toward the sides, like a lens\n  // that loses focus away from the centre.\n  float fall = (0.07 + 0.32 * u_blur) * (1.0 + 0.7 * x * x) * (0.7 + 0.3 * radius);\n  float outside = max(d, 0.0);\n  float glow = exp(-outside / fall);\n  // Inside the dome the light heats toward its source past the edge.\n  float inner = (0.12 + 0.2 * u_blur) * max(1.0, radius);\n  float t = d < 0.0 ? 0.4 * exp(d / inner) : 0.4 + 0.6 * (1.0 - exp(-outside / (1.8 * fall)));\n  vec3 col = ramp(t);\n\n  // A bright lip on the horizon, then stacked lips inside it.\n  float lipW = 0.025 + 0.07 * u_blur;\n  float lip = exp(-d * d / (lipW * lipW));\n  float stack = 0.0;\n  for (int i = 1; i < 3; i++) {\n    if (float(i) > lips) break;\n    float off = d + float(i) * (0.06 + 0.05 * u_blur) * (0.8 + 0.4 * radius);\n    off += 0.02 * u_warp * flowNoise(vec2(q.x * 1.4, float(i) * 3.1), 5.0 + float(i));\n    stack += exp(-off * off / (lipW * lipW * 0.8)) * (1.0 - 0.25 * float(i));\n  }\n  vec3 hot = vec3(min(1.0, paletteColor(0).x + 0.05), paletteColor(0).yz * 0.6);\n  col = labMix(col, hot, clamp((lip * 0.28 + stack * 0.45) * (1.0 - 0.6 * lightBg), 0.0, 1.0));\n  // Each stacked lip is a thin band of brighter haze over the dome.\n  col.x += 0.05 * stack * (1.0 - lightBg);\n\n  vec3 lab = labMix(u_bg, col, glow);\n  // Faint haze over the dark half so it never reads as flat black.\n  float haze = exp(-outside / (0.7 + 0.7 * u_blur)) * (1.0 - glow);\n  lab = labMix(lab, ramp(0.8), 0.24 * haze * (1.0 - lightBg));\n  lab.x *= vignette(p, 0.25 * (1.0 - lightBg));\n  return filmGrade(lab);\n}\n`,\n  wgsl: () => import(\"./wgsl/rise\").then((module) => module.wgsl),\n  label: \"Rise\",\n  name: \"rise\",\n};\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/rise.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/silk.ts",
      "content": "import type { GradientKindDefinition } from \"../kind\";\nimport { pick } from \"../kind\";\n\n/**\n * A draped sheet of silk seen edge-on. Parallel folds run along the sheet,\n * bunching and spreading as a slow wave travels through it; a fake normal\n * from the folds gives deep troughs, thin specular crests and a sheen that\n * shifts colour with the facing direction. The top hem follows one fold, so\n * the edge is a crisp line of light, and the sheet falls off into the\n * background below it.\n *\n * Colour 1 is the body, colour 2 the sheen and hem, colour 3 an optional\n * second sheen for folds facing the other way. `scale` sets the fold\n * density, `warp` how much the folds twist, `blur` softens the light.\n */\nexport const silk: GradientKindDefinition = {\n  defaults: {\n    background: \"#030308\",\n    blur: 0.3,\n    colors: [\"#3b3fd8\", \"#f3d6c0\", \"#8a7bff\"],\n    dither: { cell: 3, enabled: false, levels: 8 },\n    grain: 0.08,\n    interaction: { pointer: 0.15, scroll: 0.2 },\n    loopSeconds: 24,\n    scale: 1,\n    seed: 4,\n    speed: 0.6,\n    warp: 0.4,\n  },\n  description: \"A draped sheet of silk with lit folds and a bright hem.\",\n  fallbackLayers: (colors) => [\n    `linear-gradient(172deg, transparent 30%, color-mix(in oklab, ${pick(colors, 1)} 60%, transparent) 36%, color-mix(in oklab, ${pick(colors, 0)} 70%, transparent) 44%, transparent 85%)`,\n    `radial-gradient(70% 40% at 45% 45%, color-mix(in oklab, ${pick(colors, 2)} 35%, transparent), transparent 70%)`,\n  ],\n  glsl: `\n// Distance across the sheet, in fold units: constant along each fold.\nfloat silkPhase(vec2 q, vec2 t1, vec2 t2, float ph) {\n  float x = q.x;\n  float centre = 0.075 * turnSin(1.25 * x + 0.7 + ph, t1) + 0.05 * turnSin(2.7 * x - 1.9 + 2.0 * ph, t2);\n  float spread = 1.0 + 0.22 * turnSin(1.6 * x + 2.1 - ph, t1) + 0.3 * sin(0.9 * x + 4.0 + 3.0 * ph);\n  float twist = flowNoise(vec2(x * 0.5, q.y * 0.8), 2.0);\n  return (q.y - centre) * spread + (0.02 + 0.07 * u_warp) * twist;\n}\n\nvec3 kindColor(vec2 p, vec2 uv) {\n  float sa = seedAngle();\n  // The seed picks the drape: its tilt, height, fold size, and whether it\n  // hangs from above or rises from below.\n  float tilt = 0.4 * sin(sa);\n  vec2 q = rot2(tilt) * p;\n  q.y -= 0.04 + 0.16 * cos(sa * 1.7);\n  q.y *= fract(sa * 0.91) > 0.66 ? -1.0 : 1.0;\n  float ph = sa * 2.3;\n  vec2 t1 = loopTurn();\n  vec2 t2 = vec2(t1.x * t1.x - t1.y * t1.y, 2.0 * t1.x * t1.y);\n\n  float e = 0.0025;\n  float v = silkPhase(q, t1, t2, ph);\n  vec2 grad = vec2(silkPhase(q + vec2(e, 0.0), t1, t2, ph) - v, silkPhase(q + vec2(0.0, e), t1, t2, ph) - v) / e;\n\n  // Two scales of fold: a broad swell of the whole sheet, and fine strands\n  // that gather into bundles along it.\n  float x = q.x;\n  float bend = 0.45 * turnSin(1.1 * x + 0.4 + ph, t1) + 0.2 * sin(2.3 * x + 1.0 - ph);\n  float f1 = 5.5 * u_scale * (0.8 + 0.45 * fract(sa * 1.37));\n  float phi1 = v * f1 + bend;\n  vec2 slope = 0.7 * cos(phi1) * grad * f1;\n  vec3 n = normalize(vec3(-slope, 1.0));\n\n  // Lit like a studio shot: the folds reflect a sharp key, a broad fill and a\n  // dimmer bounce below, plus a little diffuse light.\n  vec3 light = normalize(vec3(0.3 * cos(sa * 2.3), 0.85, 0.4));\n  float diffuse = 0.5 + 0.5 * dot(n, light);\n  diffuse *= diffuse;\n  vec2 r = 2.0 * n.z * n.xy;\n  float w = mix(0.07, 0.3, u_blur);\n  float key = exp(-pow((r.y - 0.42) / w, 2.0));\n  float bounce = exp(-pow((r.y + 0.35) / (1.6 * w), 2.0));\n  // A broad, softer fill band, so the body between the crests has sheen too.\n  float fill = exp(-pow((r.y - 0.12) / (2.4 * w), 2.0));\n  float spec = key * (0.75 + 0.25 * diffuse) + 0.38 * fill;\n\n  // On a dark ground the folds are lit out of the dark; on a light ground the\n  // body is the light and the folds shade toward colour 1.\n  float lightBg = smoothstep(0.55, 0.75, u_bg.x);\n  vec3 body = mix(\n    labMix(u_bg, paletteColor(0), smoothstep(0.12, 0.9, diffuse)),\n    labMix(paletteColor(0), u_bg, 0.15 + 0.85 * diffuse),\n    lightBg\n  );\n  float facing = smoothstep(-0.25, 0.25, n.x);\n  vec3 tint = labMix(paletteColor(1), paletteColor(u_count > 2 ? 2 : 1), facing);\n  // Fine strands gathered into bundles: thin lines along the folds.\n  float f2 = 40.0 * u_scale;\n  float v2 = v * f2 + 1.5 * sin(v * f1 * 1.7 + 1.0);\n  float thread = exp(-pow((fract(v2) - 0.5) / mix(0.08, 0.22, u_blur), 2.0));\n  float bundle = smoothstep(0.1, 0.9, sin(phi1 * 0.5 + 2.0)) * (0.4 + 0.6 * u_warp);\n  // Strands only show where their fold catches the light.\n  float shine = spec + 0.55 * thread * bundle * clamp(key + fill, 0.0, 1.0);\n  vec3 lab = labMix(body, paletteColor(u_count > 2 ? 2 : 0), 0.3 * bounce * (1.0 - lightBg));\n  lab = labMix(lab, tint, clamp(shine, 0.0, 1.0));\n  lab.x += (0.32 - 0.25 * lightBg) * spec * spec + 0.05 * thread * bundle * diffuse;\n\n  // The sheet: everything below the hem fold, fading with depth.\n  float top = 0.16;\n  float px = length(grad) / min(u_full.x, u_full.y);\n  float soft = max(px * 1.5, 1e-4) + 0.03 * u_blur;\n  float below = top - v;\n  float mask = smoothstep(-soft, soft, below);\n  float fade = exp(-max(below, 0.0) * mix(1.8, 1.2, u_blur));\n  float rim = exp(-pow(below / (soft + 0.006), 2.0));\n\n  // The top fold rolls toward the light, so the body is brightest just under the hem.\n  lab = labMix(lab, labMix(paletteColor(0), tint, 0.35), 0.7 * exp(-max(below, 0.0) * mix(16.0, 8.0, u_blur)) * (1.0 - lightBg));\n  vec3 back = labMix(u_bg, paletteColor(0), 0.14 * exp(-abs(below) * 5.0));\n  vec3 outLab = labMix(back, lab, mask * fade);\n  // The hem catches the light unevenly along its length.\n  float catchLight = 0.45 + 0.55 * smoothstep(-0.6, 0.8, flowNoise(vec2(q.x * 0.9, 3.0), 5.0));\n  outLab = labMix(outLab, paletteColor(1), 0.9 * rim * catchLight);\n  outLab.x += 0.12 * rim * catchLight;\n  return filmGrade(outLab);\n}\n`,\n  wgsl: () => import(\"./wgsl/silk\").then((module) => module.wgsl),\n  label: \"Silk\",\n  name: \"silk\",\n};\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/silk.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/smear.ts",
      "content": "import type { GradientKindDefinition } from \"../kind\";\nimport { pick } from \"../kind\";\n\nexport const smear: GradientKindDefinition = {\n  defaults: {\n    background: \"#efe8dc\",\n    blur: 0.55,\n    colors: [\"#f2552c\", \"#f7b23b\", \"#e889b5\", \"#2f6b3f\"],\n    dither: { cell: 3, enabled: false, levels: 8 },\n    grain: 0.4,\n    interaction: { pointer: 0.25, scroll: 0.3 },\n    loopSeconds: 14,\n    scale: 1,\n    seed: 9,\n    speed: 0.7,\n    warp: 0.4,\n  },\n  description:\n    \"A long exposure of colour: soft blooms dragged into streaks across the frame.\",\n  fallbackLayers: (colors) => [\n    `radial-gradient(45% 22% at 30% 40%, color-mix(in oklab, ${pick(colors, 0)} 85%, transparent) 0%, transparent 100%)`,\n    `radial-gradient(40% 20% at 68% 62%, color-mix(in oklab, ${pick(colors, 1)} 80%, transparent) 0%, transparent 100%)`,\n    `radial-gradient(35% 18% at 55% 25%, color-mix(in oklab, ${pick(colors, 2)} 70%, transparent) 0%, transparent 100%)`,\n    `linear-gradient(160deg, transparent 30%, color-mix(in oklab, ${pick(colors, 3)} 18%, transparent) 100%)`,\n  ],\n  glsl: `\n// flowNoise with a third of the travel: blooms this stretched would otherwise\n// sweep a whole bloom-width each loop.\nfloat smearNoise(vec2 p, float layer) {\n  return snoise2(p + u_seed + 0.35 * drift(layer) + vec2(layer * 7.13, layer * 3.71));\n}\n\nvec3 kindColor(vec2 p, vec2 uv) {\n  float lightBg = smoothstep(0.55, 0.85, u_bg.x);\n  // The camera moved along one direction; the seed picks it.\n  float a = 0.5 * sin(seedAngle()) + (fract(u_seed.y * 0.071) > 0.5 ? 0.0 : 1.5708) * 0.35;\n  vec2 q = rot2(a) * p * u_scale;\n  // Streaks bend a little where the hand wobbled.\n  q.y += (0.05 + 0.2 * u_warp) * smearNoise(vec2(q.x * 0.45, 0.3), 1.0);\n  float stretch = 0.3 + 0.35 * (1.0 - u_blur);\n  vec2 s = vec2(q.x * stretch, q.y * 1.5) * 1.6;\n\n  // Blooms: where they are, and which colour each one is.\n  float bloom = smearNoise(s, 2.0) + 0.5 * smearNoise(s * vec2(1.7, 2.3) + 3.3, 3.0);\n  float hue = 0.5 + 0.5 * smearNoise(s * 0.7 + 11.0, 4.0);\n  float edge = 0.04 + 0.32 * u_blur;\n  float m = smoothstep(0.12 - edge, 0.12 + edge, bloom);\n  // Streaks inside the smear: fine across, long along.\n  float streak = smearNoise(vec2(q.x * 0.5, q.y * 12.0 / (0.6 + u_blur)), 5.0);\n  vec3 col = ramp(clamp(hue + 0.08 * streak, 0.0, 1.0));\n  col.x += 0.045 * streak;\n\n  // The ground is not flat: a faint smear of the deepest colour runs through it.\n  vec3 ground = u_bg;\n  float shade = 0.5 + 0.5 * smearNoise(s * 0.6 - 7.0, 6.0);\n  ground = labMix(ground, paletteColor(u_count - 1), 0.12 * shade);\n  ground.x += 0.01 * streak;\n\n  vec3 lab = labMix(ground, col, m * (0.82 + 0.18 * shade));\n  // Hot cores where blooms are densest.\n  // Dense blooms get a darker heart, like the centre of a flower.\n  float core = smoothstep(0.75, 1.25, bloom + 0.2 * streak);\n  lab = labMix(lab, paletteColor(u_count - 1), 0.3 * core);\n  lab.x *= vignette(p, 0.18 * (1.0 - lightBg));\n  return filmGrade(lab);\n}\n`,\n  wgsl: () => import(\"./wgsl/smear\").then((module) => module.wgsl),\n  label: \"Smear\",\n  name: \"smear\",\n};\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/smear.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/spectrum.ts",
      "content": "import type { GradientKindDefinition } from \"../kind\";\nimport { stops } from \"../kind\";\n\n/**\n * Light dispersed along a curved filament. A few thin strands of light arc\n * across the frame; each splits into a fringe of colours that widens along\n * its length, the way an edge of glass throws a spectrum. The palette is\n * the spectrum, in order across the fringe, so it can be a full rainbow or\n * two close hues. Strands keep a white-hot core on dark backgrounds and\n * read as tinted ink lines on pale ones.\n *\n * Unlike the Pro prism (a fan from one point), the light here is a sheet\n * of filaments with no source in frame.\n *\n * Params: `scale` sets the arc size, `warp` the dispersion (how far the\n * fringe fans out), `blur` the halo. The seed picks the sweep and how many\n * strands follow the first.\n *\n * Helpers are prefixed `sp` and only depend on the prelude.\n */\nexport const spectrum: GradientKindDefinition = {\n  defaults: {\n    background: \"#030304\",\n    blur: 0.45,\n    colors: [\"#6a3cff\", \"#2f8bff\", \"#2fe0c8\", \"#ffd23f\", \"#ff4a3d\"],\n    dither: { cell: 3, enabled: false, levels: 8 },\n    grain: 0.08,\n    interaction: { pointer: 0.15, scroll: 0.1 },\n    loopSeconds: 20,\n    scale: 1,\n    seed: 3,\n    speed: 0.5,\n    warp: 0.5,\n  },\n  description:\n    \"Thin arcs of light splitting into their spectrum across the dark.\",\n  fallbackLayers: (colors) => [\n    `radial-gradient(120% 90% at 30% 120%, transparent 58%, ${stops(colors, 60, 66)}, transparent 70%)`,\n  ],\n  glsl: `\n// Signed distance (approx) from q to strand k, and the position along it.\nvec2 spStrand(vec2 q, vec2 h, float k, float side) {\n  float s = 1.0 / u_scale;\n  // A wide arc: part of a big ellipse leaning across the frame.\n  float a = -0.35 + (side - 0.5) * 0.8 + 0.12 * k;\n  vec2 r = rot2(a) * q;\n  float bend = (0.55 + 0.1 * k) / s;\n  float y0 = -0.08 * h.y + 0.11 * k + 0.12 * flowNoise(vec2(0.2, k), 1.0 + k);\n  float x = r.x;\n  float wave = 0.09 * flowNoise(vec2(x * 0.9, 0.4 + k), 2.0 + k);\n  float curve = y0 + bend * 0.5 * x * x + wave;\n  // Slope from the analytic part keeps the width even along the arc.\n  float slope = bend * x;\n  float d = (r.y - curve) / sqrt(1.0 + slope * slope);\n  return vec2(d, x / max(h.x, 1e-3));\n}\n\nvec3 kindColor(vec2 p, vec2 uv) {\n  vec2 h = frameHalf();\n  float lightBg = smoothstep(0.55, 0.85, u_bg.x);\n  float side = fract(u_seed.y * 0.0917 + 0.5);\n  float strands = 1.0 + floor(fract(u_seed.x * 0.0731 + 0.5) * 3.0);\n  // Odd layouts mirror, so arcs sweep either way.\n  vec2 q = p;\n  if (fract(u_seed.x * 0.31 + u_seed.y * 0.17) > 0.5) q.x = -q.x;\n  float halo = 0.02 + 0.06 * u_blur;\n  vec3 lab = u_bg;\n  float n = float(u_count);\n  float hotSum = 0.0;\n  for (int k = 0; k < 3; k++) {\n    float fk = float(k);\n    if (fk >= strands) break;\n    vec2 st = spStrand(q, h, fk, side);\n    float along = st.y;\n    float fade = smoothstep(-1.15, -0.4, along) * (1.0 - 0.35 * fk);\n    // The fringe widens along the strand, from a line to a fan.\n    float fan = (0.004 + 0.1 * u_warp * smoothstep(-0.9, 1.0, along)) * (1.0 + 0.4 * fk);\n    float core = 0.0018 + 0.004 * u_blur;\n    // The strand is the lit edge of a ribbon: its surface trails off on\n    // one side as a soft body in the palette's middle colour.\n    float bodyW = (0.05 + 0.08 * u_blur) * (1.0 + 0.5 * fk);\n    float body = st.x < 0.0 ? exp(st.x / bodyW) * smoothstep(-0.006, 0.0, st.x) : 0.0;\n    body *= fade * (0.35 + 0.15 * flowNoise(vec2(along * 1.4, fk), 8.0 + fk));\n    lab = labMix(lab, ramp(0.35 + 0.15 * fk), clamp(body * mix(0.9, 0.5, lightBg), 0.0, 1.0));\n    for (int i = 0; i < 6; i++) {\n      if (i >= u_count) break;\n      float fi = float(i);\n      float off = (fi / max(n - 1.0, 1.0) - 0.5) * fan;\n      float dd = st.x - off;\n      float band = exp(-dd * dd / ((fan / n + core) * (fan / n + core)));\n      float glow = exp(-abs(dd) / halo) * mix(0.35, 0.12, lightBg);\n      float wgt = (band + glow) * fade;\n      lab = labMix(lab, paletteColor(i), clamp(wgt * mix(0.9, 0.75, lightBg), 0.0, 1.0));\n    }\n    float hot = exp(-st.x * st.x / (core * core)) * fade;\n    hotSum += hot * (1.0 - 0.4 * fk);\n  }\n  // Where the fringe converges the light burns white on dark grounds.\n  vec3 white = vec3(min(1.0, paletteRange().x + 0.05), 0.0, 0.0);\n  lab = labMix(lab, white, clamp(hotSum * 0.8 * (1.0 - lightBg), 0.0, 1.0));\n  lab.x *= vignette(p, 0.25 * (1.0 - lightBg));\n  return filmGrade(lab);\n}\n`,\n  wgsl: () => import(\"./wgsl/spectrum\").then((module) => module.wgsl),\n  label: \"Spectrum\",\n  name: \"spectrum\",\n};\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/spectrum.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/swirl.ts",
      "content": "import type { GradientKindDefinition } from \"../kind\";\nimport { stops } from \"../kind\";\n\nexport const swirl: GradientKindDefinition = {\n  defaults: {\n    background: \"#07060a\",\n    blur: 0.6,\n    colors: [\"#ffe2c4\", \"#ff9a4d\", \"#d2456b\", \"#3a1f6b\"],\n    dither: { cell: 3, enabled: false, levels: 8 },\n    grain: 0.16,\n    interaction: { pointer: 0.25, scroll: 0.2 },\n    loopSeconds: 20,\n    scale: 1,\n    seed: 5,\n    speed: 0.6,\n    warp: 0.55,\n  },\n  description:\n    \"Colour stirred into a slow, blurred vortex around an off-centre eye.\",\n  fallbackLayers: (colors) => [\n    `radial-gradient(70% 80% at 58% 46%, ${stops(colors, 0, 75)}, transparent 100%)`,\n  ],\n  glsl: `\nvec3 kindColor(vec2 p, vec2 uv) {\n  vec2 h = frameHalf();\n  float lightBg = smoothstep(0.55, 0.85, u_bg.x);\n  float a = seedAngle();\n  // The eye sits off centre and wanders a little.\n  vec2 eye = vec2(0.32 * h.x * cos(a), 0.22 * h.y * sin(a * 1.7));\n  eye += 0.05 * vec2(flowNoise(vec2(0.2, 0.8), 1.0), flowNoise(vec2(0.9, 0.1), 2.0));\n  vec2 d = p - eye;\n  float r = length(d);\n  // Twist: strongest near the eye, easing out with distance. It breathes\n  // with the loop, so the arms wind and unwind.\n  float reach = 0.55 / u_scale;\n  float twist = (2.2 + 2.8 * u_warp) * exp(-r / reach) + 0.9 * u_loop.x;\n  float dir = fract(u_seed.y * 0.113) > 0.5 ? 1.0 : -1.0;\n  vec2 q = rot2(dir * twist) * d;\n\n  vec2 s = q * 1.25 * u_scale;\n  float fine = 1.0 - 0.8 * u_blur;\n  float n = flowNoise(s, 3.0) + 0.4 * fine * flowNoise(s * 2.3 + 5.1, 4.0);\n  n /= 1.0 + 0.4 * fine;\n  float t = clamp(0.45 + 0.5 * n, 0.0, 1.0);\n  // Arms: a soft spiral band the palette rides along.\n  float arm = 0.5 + 0.5 * sin(atan(q.y, q.x + 1e-6) * 2.0 + r * 3.0 + 2.0 * n);\n  // The arms converge to a point at the eye; let them dissolve there.\n  arm = mix(0.5, arm, smoothstep(0.0, 0.2, r));\n  t = mix(t, 0.15 + 0.7 * arm, 0.3);\n  vec3 col = ramp(t);\n\n  // The eye is the brightest, calmest point; light thins with distance.\n  float lit = exp(-r / ((0.35 + 0.35 * u_blur) * max(0.6, 1.0 / u_scale)));\n  // Away from the eye the colour thins into the ground along the arms.\n  float amount = lit * (0.7 + 0.3 * arm) + (1.0 - lit) * 0.55 * arm * smoothstep(-0.2, 0.6, n);\n  // As the light thins it deepens toward the last colour instead of\n  // greying out, the way a glow falls off on film.\n  col = labMix(col, ramp(1.0), (1.0 - clamp(amount, 0.0, 1.0)) * 0.55 * (1.0 - lightBg));\n  vec3 lab = labMix(u_bg, col, clamp(amount, 0.0, 1.0));\n  vec3 hot = vec3(min(1.0, paletteColor(0).x + 0.05), paletteColor(0).yz * 0.6);\n  lab = labMix(lab, hot, 0.5 * exp(-r * r / (0.02 + 0.04 * u_blur)) * (1.0 - lightBg));\n  lab.x *= vignette(p, 0.3 * (1.0 - lightBg));\n  return filmGrade(lab);\n}\n`,\n  wgsl: () => import(\"./wgsl/swirl\").then((module) => module.wgsl),\n  label: \"Swirl\",\n  name: \"swirl\",\n};\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/swirl.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/void.ts",
      "content": "import type { GradientKindDefinition } from \"../kind\";\nimport { pick } from \"../kind\";\n\nexport const voidKind: GradientKindDefinition = {\n  defaults: {\n    background: \"#020203\",\n    blur: 0.3,\n    colors: [\"#c9b6ff\", \"#7b4dff\", \"#2c1670\"],\n    dither: { cell: 3, enabled: false, levels: 8 },\n    grain: 0.22,\n    interaction: { pointer: 0.15, scroll: 0.1 },\n    loopSeconds: 18,\n    scale: 1,\n    seed: 4,\n    speed: 0.6,\n    warp: 0.6,\n  },\n  description:\n    \"A dark core inside a field of radial streaks, brightest toward the frame edge.\",\n  fallbackLayers: (colors) => [\n    `radial-gradient(circle at 50% 50%, transparent 30%, color-mix(in oklab, ${pick(colors, 2)} 55%, transparent) 48%, color-mix(in oklab, ${pick(colors, 1)} 65%, transparent) 70%, color-mix(in oklab, ${pick(colors, 0)} 55%, transparent) 100%)`,\n  ],\n  glsl: `\n// Colour streaks radiate from a dark core, like a zoom blur. The streaks\n// are noise sampled on circles round the centre: fine in angle, smooth in\n// radius, and with no seam. scale sets the core; warp the streak contrast.\nvec3 kindColor(vec2 p, vec2 uv) {\n  vec2 h = frameHalf();\n  // The seed picks where the core sits: near the centre, pushed to one\n  // side, sunk below the bottom edge so the streaks fan up from it, or\n  // tucked into a top corner so they fan down across the frame.\n  float framing = floor(fract(u_seed.x * 0.0731 + 0.5) * 4.0);\n  float side = sign(u_seed.y + 0.01);\n  vec2 centre = vec2(0.06 * h.x * sin(u_seed.y), 0.03 * cos(u_seed.x));\n  float radius = 0.25;\n  if (framing == 1.0) {\n    centre = vec2(0.5 * h.x * side, 0.04);\n    radius = 0.22;\n  } else if (framing == 2.0) {\n    centre = vec2(0.12 * h.x * side, -h.y - 0.08);\n    radius = 0.36;\n  } else if (framing == 3.0) {\n    centre = vec2(-side * (h.x - 0.05), h.y - 0.05);\n    radius = 0.3;\n  }\n  float breathe = 1.0 + 0.035 * flowNoise(vec2(0.37, 0.71), 1.0);\n  radius *= u_scale * breathe;\n\n  vec2 d = p - centre;\n  float r = length(d);\n  vec2 dir = d / max(r, 1e-4);\n\n  // Fine streaks over a broad angular swell. Blur smears the fine ones.\n  float fineAmount = 1.0 - 0.75 * u_blur;\n  float broad = flowNoise(dir * 2.2 + vec2(0.0, r * 0.4), 1.5);\n  float s1 = flowNoise(dir * 16.0 + vec2(r * 0.5, 0.0), 2.0);\n  float s2 = flowNoise(dir * 41.0 - vec2(0.0, r * 0.9), 3.0);\n  float fine = (s1 + 0.7 * s2) / 1.7;\n  float streak = 1.0 + u_warp * (0.3 * broad + 0.32 * fineAmount * fine);\n\n  // One brighter sector, which drifts slowly round the core.\n  float swing = seedAngle() + 1.6 * u_loop.y;\n  float sector = 0.5 + 0.5 * dot(dir, vec2(sin(swing), -cos(swing)));\n\n  // Dark inside the core, rising through the streaks to the frame edge.\n  float soft = 0.5 + 0.6 * u_blur;\n  float rise = smoothstep(radius * (1.0 - 0.25 * soft), radius * (1.0 + 1.8 * soft), r);\n  float edge = clamp((r - radius) / max(length(h) + length(centre) - radius, 0.2), 0.0, 1.0);\n  float glow = rise * (0.28 + 0.42 * edge) * streak * (0.35 + 0.65 * sector * sector);\n\n  // colour 0 is the brightest light, the last the deepest.\n  float t = clamp(1.0 - glow * 1.1 - 0.1 * sector, 0.0, 1.0);\n  vec3 col = ramp(t);\n  vec3 lab = labMix(u_bg, col, clamp(glow * 1.25, 0.0, 1.0));\n  return filmGrade(lab);\n}\n`,\n  wgsl: () => import(\"./wgsl/void\").then((module) => module.wgsl),\n  label: \"Void\",\n  name: \"void\",\n};\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/void.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/waves.ts",
      "content": "import type { GradientKindDefinition } from \"../kind\";\nimport { stops } from \"../kind\";\n\nexport const waves: GradientKindDefinition = {\n  defaults: {\n    background: \"#05070d\",\n    blur: 0.35,\n    colors: [\"#a9c1df\", \"#5479b0\", \"#24467e\", \"#0f1c38\"],\n    dither: { cell: 3, enabled: false, levels: 8 },\n    grain: 0.08,\n    interaction: { pointer: 0.15, scroll: 0.25 },\n    loopSeconds: 16,\n    scale: 1,\n    seed: 11,\n    speed: 0.6,\n    warp: 0.4,\n  },\n  description: \"Satin bands folding over each other, lit from above.\",\n  fallbackLayers: (colors, background) => [\n    `linear-gradient(172deg, ${background} 0%, ${stops(colors, 28, 100)})`,\n  ],\n  glsl: `\nvec3 kindColor(vec2 p, vec2 uv) {\n  vec2 h = frameHalf();\n  float tilt = -0.42 + 0.3 * (fract(u_seed.x * 0.173) - 0.5);\n  vec2 normal = vec2(sin(tilt), cos(tilt));\n  vec2 tangent = vec2(normal.y, -normal.x);\n  float y = dot(p, normal) / (2.0 * h.y);\n  float along = dot(p, tangent);\n  float x = along * u_scale;\n  float count = float(u_count);\n  // Depth of field: crisp in the middle, softer toward the sides.\n  float focus = 0.35 + 0.65 * min(1.0, abs(along) / h.x);\n  vec3 lab = u_bg;\n  lab.x += 0.05 * smoothstep(-0.2, 0.6, y);\n  for (int i = 0; i < 6; i++) {\n    if (i >= u_count) break;\n    float fi = float(i);\n    float base = 0.46 - 0.9 * (fi + 0.25) / count;\n    float phase = fi * 1.9 + dot(u_loop, vec2(cos(fi * 1.3), sin(fi * 1.3))) * 1.8;\n    float wave = 0.1 * sin(x * (1.3 + 0.3 * fi) + phase)\n      + 0.04 * sin(x * (2.7 - 0.2 * fi) - 1.3 * phase + 1.0)\n      + u_warp * 0.08 * flowNoise(vec2(x * 0.65, fi * 3.7), 60.0 + fi);\n    float edge = base + wave * (0.6 + 0.4 * fi / count);\n    float dd = edge - y;\n    float soft = 0.002 + (0.01 + 0.06 * u_blur) * focus;\n    float m = smoothstep(-soft, soft, dd);\n    // The band casts a soft shadow on the one behind it.\n    float shadow = exp(-max(-dd, 0.0) / (0.035 + 0.05 * u_blur)) * (1.0 - m);\n    lab.x -= 0.08 * shadow * (0.3 + lab.x);\n    // Satin: a bright lip at the crest, then the band turns away from the light.\n    vec3 c = u_colors[i];\n    float body = max(dd, 0.0);\n    // Centred on the band's own colour, so a flat palette keeps its value.\n    c.x += 0.1 * exp(-body / (0.012 + 0.03 * u_blur)) + 0.09 * (0.38 - smoothstep(0.0, 0.3, body))\n      + 0.06 * along / h.x;\n    lab = labMix(lab, c, m);\n  }\n  lab.x *= vignette(p, 0.22);\n  return filmGrade(lab);\n}\n`,\n  wgsl: () => import(\"./wgsl/waves\").then((module) => module.wgsl),\n  label: \"Waves\",\n  name: \"waves\",\n};\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/waves.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/wgsl-common.ts",
      "content": "/**\n * WGSL twin of common.ts. A kind supplies\n * `fn kindColor(p: vec2f, uv: vec2f) -> vec3f` returning OKLab, exactly as in\n * GLSL. The maths is a line-for-line port so frame N matches the WebGL\n * engine; the differences are WGSL's, not ours:\n *\n * - No overloading, so mod289/permute/taylorInvSqrt carry a size suffix.\n * - GLSL `mod` floors; WGSL `%` truncates. `gmod` is GLSL's `mod`.\n * - No swizzle assignment and immutable parameters, so a few helpers rebuild\n *   vectors instead of writing `v.yz *= k`.\n * - `@builtin(position)` is top-left origin, so the tile maths loses its flip.\n * - `loop` is a WGSL keyword: the uniform is `u.loopv`.\n */\n\nexport const wgslPrelude = /* wgsl */ `\nstruct Uniforms {\n  full: vec2f,\n  loopv: vec2f,\n  tile: vec4f,\n  seed: vec2f,\n  scale: f32,\n  warp: f32,\n  blur: f32,\n  grain: f32,\n  frame: f32,\n  count: i32,\n  dither: vec3f,\n  scroll: f32,\n  bg: vec3f,\n  pointer: vec3f,\n  colors: array<vec4f, 6>,\n}\n\n@group(0) @binding(0) var<uniform> u: Uniforms;\n\nfn gmod1(x: f32, y: f32) -> f32 { return x - y * floor(x / y); }\nfn gmod2(x: vec2f, y: f32) -> vec2f { return x - y * floor(x / y); }\n\n// 4D simplex noise. Ian McEwan, Stefan Gustavson, Ashima Arts (MIT).\nfn mod289_4(x: vec4f) -> vec4f { return x - floor(x * (1.0 / 289.0)) * 289.0; }\nfn mod289_1(x: f32) -> f32 { return x - floor(x * (1.0 / 289.0)) * 289.0; }\nfn permute4(x: vec4f) -> vec4f { return mod289_4(((x * 34.0) + 10.0) * x); }\nfn permute1(x: f32) -> f32 { return mod289_1(((x * 34.0) + 10.0) * x); }\nfn taylorInvSqrt4(r: vec4f) -> vec4f { return 1.79284291400159 - 0.85373472095314 * r; }\nfn taylorInvSqrt1(r: f32) -> f32 { return 1.79284291400159 - 0.85373472095314 * r; }\nfn grad4(j: f32, ip: vec4f) -> vec4f {\n  let ones = vec4f(1.0, 1.0, 1.0, -1.0);\n  var p: vec4f;\n  let pxyz = floor(fract(vec3f(j) * ip.xyz) * 7.0) * ip.z - 1.0;\n  p = vec4f(pxyz, 1.5 - dot(abs(pxyz), ones.xyz));\n  let s = select(vec4f(0.0), vec4f(1.0), p < vec4f(0.0));\n  p = vec4f(p.xyz + (s.xyz * 2.0 - 1.0) * s.www, p.w);\n  return p;\n}\nfn snoise(v: vec4f) -> f32 {\n  let C = vec4f(0.138196601125011, 0.276393202250021, 0.414589803375032, -0.447213595499958);\n  var i = floor(v + dot(v, vec4f(0.309016994374947451)));\n  let x0 = v - i + dot(i, C.xxxx);\n  let isX = step(x0.yzw, x0.xxx);\n  let isYZ = step(x0.zww, x0.yyz);\n  var i0 = vec4f(isX.x + isX.y + isX.z, 1.0 - isX);\n  i0.y += isYZ.x + isYZ.y;\n  i0.z += 1.0 - isYZ.x;\n  i0.w += 1.0 - isYZ.y;\n  i0.z += isYZ.z;\n  i0.w += 1.0 - isYZ.z;\n  let i3 = clamp(i0, vec4f(0.0), vec4f(1.0));\n  let i2 = clamp(i0 - 1.0, vec4f(0.0), vec4f(1.0));\n  let i1 = clamp(i0 - 2.0, vec4f(0.0), vec4f(1.0));\n  let x1 = x0 - i1 + C.xxxx;\n  let x2 = x0 - i2 + C.yyyy;\n  let x3 = x0 - i3 + C.zzzz;\n  let x4 = x0 + C.wwww;\n  i = mod289_4(i);\n  let j0 = permute1(permute1(permute1(permute1(i.w) + i.z) + i.y) + i.x);\n  let j1 = permute4(permute4(permute4(permute4(\n      i.w + vec4f(i1.w, i2.w, i3.w, 1.0))\n    + i.z + vec4f(i1.z, i2.z, i3.z, 1.0))\n    + i.y + vec4f(i1.y, i2.y, i3.y, 1.0))\n    + i.x + vec4f(i1.x, i2.x, i3.x, 1.0));\n  let ip = vec4f(1.0 / 294.0, 1.0 / 49.0, 1.0 / 7.0, 0.0);\n  var p0 = grad4(j0, ip);\n  var p1 = grad4(j1.x, ip);\n  var p2 = grad4(j1.y, ip);\n  var p3 = grad4(j1.z, ip);\n  var p4 = grad4(j1.w, ip);\n  let norm = taylorInvSqrt4(vec4f(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));\n  p0 *= norm.x;\n  p1 *= norm.y;\n  p2 *= norm.z;\n  p3 *= norm.w;\n  p4 *= taylorInvSqrt1(dot(p4, p4));\n  var m0 = max(0.6 - vec3f(dot(x0, x0), dot(x1, x1), dot(x2, x2)), vec3f(0.0));\n  var m1 = max(0.6 - vec2f(dot(x3, x3), dot(x4, x4)), vec2f(0.0));\n  m0 = m0 * m0;\n  m1 = m1 * m1;\n  return 49.0 * (dot(m0 * m0, vec3f(dot(p0, x0), dot(p1, x1), dot(p2, x2)))\n    + dot(m1 * m1, vec2f(dot(p3, x3), dot(p4, x4))));\n}\n\nfn mod289_3(x: vec3f) -> vec3f { return x - floor(x * (1.0 / 289.0)) * 289.0; }\nfn mod289_2(x: vec2f) -> vec2f { return x - floor(x * (1.0 / 289.0)) * 289.0; }\nfn permute3(x: vec3f) -> vec3f { return mod289_3(((x * 34.0) + 10.0) * x); }\nfn snoise2(v: vec2f) -> f32 {\n  let C = vec4f(0.211324865405187, 0.366025403784439, -0.577350269189626, 0.024390243902439);\n  var i = floor(v + dot(v, C.yy));\n  let x0 = v - i + dot(i, C.xx);\n  let i1 = select(vec2f(0.0, 1.0), vec2f(1.0, 0.0), x0.x > x0.y);\n  var x12 = x0.xyxy + C.xxzz;\n  x12 = vec4f(x12.xy - i1, x12.zw);\n  i = mod289_2(i);\n  let p = permute3(permute3(i.y + vec3f(0.0, i1.y, 1.0)) + i.x + vec3f(0.0, i1.x, 1.0));\n  var m = max(0.5 - vec3f(dot(x0, x0), dot(x12.xy, x12.xy), dot(x12.zw, x12.zw)), vec3f(0.0));\n  m = m * m;\n  m = m * m;\n  let x = 2.0 * fract(p * C.www) - 1.0;\n  let h = abs(x) - 0.5;\n  let ox = floor(x + 0.5);\n  let a0 = x - ox;\n  m *= 1.79284291400159 - 0.85373472095314 * (a0 * a0 + h * h);\n  let g = vec3f(a0.x * x0.x + h.x * x0.y, a0.yz * x12.xz + h.yz * x12.yw);\n  return 130.0 * dot(m, g);\n}\n\nfn loopAt(layer: f32) -> vec2f {\n  return u.loopv + vec2f(layer * 1.71, layer * -2.37);\n}\n\nfn loopNoise(p: vec2f, layer: f32) -> f32 {\n  return snoise(vec4f(p + u.seed, loopAt(layer)));\n}\n\nfn fbm(p: vec2f, layer: f32) -> f32 {\n  let fine = 1.0 - 0.85 * u.blur;\n  var sum = loopNoise(p, layer);\n  sum += 0.5 * fine * loopNoise(p * 2.03 + 17.1, layer + 0.5);\n  sum += 0.25 * fine * fine * loopNoise(p * 4.07 - 9.7, layer + 1.0);\n  return sum / (1.0 + 0.5 * fine + 0.25 * fine * fine);\n}\n\n// The loop angle as a unit vector, so waves can travel a whole period per\n// loop. Frozen when speed is 0.\nfn loopTurn() -> vec2f {\n  let r = length(u.loopv);\n  return select(vec2f(1.0, 0.0), u.loopv / r, r > 1e-6);\n}\n\n// sin(a - angle), where cs = (cos, sin)(angle).\nfn turnSin(a: f32, cs: vec2f) -> f32 {\n  return sin(a) * cs.x - cos(a) * cs.y;\n}\n\nfn rot2(a: f32) -> mat2x2f {\n  let c = cos(a);\n  let s = sin(a);\n  return mat2x2f(c, s, -s, c);\n}\n\nfn drift(layer: f32) -> vec2f {\n  return rot2(layer * 2.39996) * u.loopv;\n}\n\nfn flowNoise(p: vec2f, layer: f32) -> f32 {\n  return snoise2(p + u.seed + drift(layer) + vec2f(layer * 7.13, layer * 3.71));\n}\n\nfn safeTanh(x: f32) -> f32 {\n  return tanh(clamp(x, -9.0, 9.0));\n}\n\nfn paletteRange() -> vec2f {\n  var l = u.bg.x;\n  var c = length(u.bg.yz);\n  for (var i = 0; i < 6; i++) {\n    if (i >= u.count) { break; }\n    l = max(l, u.colors[i].x);\n    c = max(c, length(u.colors[i].yz));\n  }\n  return vec2f(l, c);\n}\n\nfn filmGrade(lab: vec3f) -> vec3f {\n  let range = paletteRange();\n  var l = max(lab.x, 0.0);\n  let shoulder = max(range.x, 0.8);\n  if (l > shoulder) {\n    let room = max(1.0 - shoulder, 1e-3);\n    l = shoulder + room * safeTanh((l - shoulder) / room);\n  }\n  let c = length(lab.yz);\n  let cap = 0.05 + 0.9 * l * (1.0 - l) * (0.5 + 0.5 * l);\n  let knee = max(range.y, 0.6 * cap);\n  let top = max(cap, knee + 0.02);\n  var soft = c;\n  if (c > knee) { soft = knee + (top - knee) * safeTanh((c - knee) / (top - knee)); }\n  var k = 1.0;\n  if (c > 1e-5) { k = soft / c; }\n  return vec3f(l, lab.yz * k);\n}\n\nfn vignette(p: vec2f, amount: f32) -> f32 {\n  let q = p / (0.5 * u.full / min(u.full.x, u.full.y));\n  return 1.0 - amount * smoothstep(0.35, 1.45, dot(q, q) * 0.55);\n}\n\nfn frameHalf() -> vec2f {\n  return 0.5 * u.full / min(u.full.x, u.full.y);\n}\n\nfn seedAngle() -> f32 {\n  return fract(u.seed.x * 0.1371 + u.seed.y * 0.0713) * 6.28318530718;\n}\n\nfn labMix(a: vec3f, b: vec3f, t: f32) -> vec3f {\n  var m = mix(a, b, t);\n  let target_ = mix(length(a.yz), length(b.yz), t);\n  let current = length(m.yz);\n  if (current > 1e-4) {\n    m = vec3f(m.x, m.yz * mix(1.0, target_ / current, 0.75));\n  }\n  return m;\n}\n\nfn paletteColor(i: i32) -> vec3f {\n  return u.colors[clamp(i, 0, u.count - 1)].xyz;\n}\n\nfn ramp(t: f32) -> vec3f {\n  let x = clamp(t, 0.0, 1.0) * f32(u.count - 1);\n  let i = i32(floor(x));\n  var f = x - f32(i);\n  f = f * f * (3.0 - 2.0 * f);\n  return labMix(paletteColor(i), paletteColor(i + 1), f);\n}\n\nfn interact(p0: vec2f) -> vec2f {\n  var p = p0;\n  let half_ = frameHalf();\n  var ptr = (u.pointer.xy - 0.5) * 2.0 * half_;\n  ptr.y = -ptr.y;\n  let d = p - ptr;\n  let f = exp(-dot(d, d) * 5.0) * u.pointer.z;\n  p -= d * f * 0.45;\n  p.y += u.scroll * 0.08 * (0.6 + 0.4 * sin(p.x * 3.0));\n  return p;\n}\n`;\n\nexport const wgslPostlude = /* wgsl */ `\nfn oklabToLinear(lab: vec3f) -> vec3f {\n  var l = lab.x + 0.3963377774 * lab.y + 0.2158037573 * lab.z;\n  var m = lab.x - 0.1055613458 * lab.y - 0.0638541728 * lab.z;\n  var s = lab.x - 0.0894841775 * lab.y - 1.2914855480 * lab.z;\n  l = l * l * l;\n  m = m * m * m;\n  s = s * s * s;\n  return vec3f(\n    4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,\n    -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,\n    -0.0041960863 * l - 0.7034186147 * m + 1.7076147010 * s\n  );\n}\n\nfn linearToSrgb(c0: vec3f) -> vec3f {\n  let c = clamp(c0, vec3f(0.0), vec3f(1.0));\n  let lo = c * 12.92;\n  let hi = 1.055 * pow(c, vec3f(1.0 / 2.4)) - 0.055;\n  return select(hi, lo, c <= vec3f(0.0031308));\n}\n\nfn hashU(x0: u32) -> u32 {\n  var x = x0;\n  x ^= x >> 16u;\n  x *= 0x7feb352du;\n  x ^= x >> 15u;\n  x *= 0x846ca68bu;\n  x ^= x >> 16u;\n  return x;\n}\n\nfn hash01(p: vec2u, s: u32) -> f32 {\n  return f32(hashU(p.x ^ hashU(p.y ^ hashU(s)))) / 4294967295.0;\n}\n\nconst BAYER = array<f32, 16>(\n  0.0, 8.0, 2.0, 10.0,\n  12.0, 4.0, 14.0, 6.0,\n  3.0, 11.0, 1.0, 9.0,\n  15.0, 7.0, 13.0, 5.0\n);\n\n@fragment\nfn fs_main(@builtin(position) fragCoord: vec4f) -> @location(0) vec4f {\n  // Top-left origin already, so no flip: GL's (tile.w - fragCoord.y) is this y.\n  let px = vec2f(u.tile.x + fragCoord.x, u.tile.y + fragCoord.y);\n  let dither = u.dither.x > 0.5;\n  let cell = floor(px / u.dither.y);\n  let samplePx = select(px, (cell + 0.5) * u.dither.y, dither);\n\n  let uv = samplePx / u.full;\n  var p = (samplePx - 0.5 * u.full) / min(u.full.x, u.full.y);\n  p.y = -p.y;\n  p = interact(p);\n\n  var rgb = linearToSrgb(oklabToLinear(kindColor(p, uv)));\n\n  let ip = vec2u(px);\n  let frame = u32(u.frame);\n  let n = hash01(ip, frame * 2u + 1u) + hash01(ip, frame * 2u + 2u) - 1.0;\n  let lum = dot(rgb, vec3f(0.2126, 0.7152, 0.0722));\n  let amp = u.grain * 0.2 * (0.55 + 0.9 * lum * (1.0 - lum)) + select(1.0 / 255.0, 0.0, dither);\n  rgb += n * amp;\n\n  if (dither) {\n    let b = vec2i(gmod2(cell, 4.0));\n    let threshold = (BAYER[b.y * 4 + b.x] + 0.5) / 16.0;\n    let steps = u.dither.z - 1.0;\n    rgb = floor(clamp(rgb, vec3f(0.0), vec3f(1.0)) * steps + threshold) / steps;\n  }\n\n  return vec4f(clamp(rgb, vec3f(0.0), vec3f(1.0)), 1.0);\n}\n`;\n\n/** The full fragment shader for a kind's `wgsl`, the twin of renderer.ts's GLSL assembly. */\nexport function composeWgsl(kindWgsl: string): string {\n  return `${wgslPrelude}\\n${kindWgsl}\\n${wgslPostlude}`;\n}\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/wgsl-common.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/wgsl/aurora.ts",
      "content": "/**\n * WGSL twin of the aurora kind's GLSL (aurora.ts): same maths, line\n * for line, against shaders/wgsl-common.ts. Imported only when the WebGPU\n * backend draws this kind, so WebGL-only pages never download it.\n */\nexport const wgsl = /* wgsl */ `\n// One curtain sheet. Returns its intensity and the height above its hem (0..1).\nfn auroraSheet(p: vec2f, layer: f32, hem0: f32, detail: bool) -> vec2f {\n  var x = p.x * u.scale;\n  // Folds sway the sheet sideways, more so higher up.\n  var fold = flowNoise(vec2f(x * 0.5, p.y * 0.25 + layer), layer);\n  var xf = x + (0.1 + 0.3 * u.warp) * fold;\n  var hem = hem0 + 0.24 * flowNoise(vec2f(xf * 0.6, layer * 3.1), layer + 1.0)\n    + 0.1 * sin(x * 1.2 + layer) + 0.06 * fold + 0.08 * x * x;\n  var rise = p.y - hem;\n  var up = exp(-max(rise, 0.0) * (2.8 - 1.0 * u.blur));\n  var down = exp(min(rise, 0.0) * (9.0 - 5.0 * u.blur));\n  // Rays: fine across the sheet, stretched along it.\n  var n = 0.65 * flowNoise(vec2f(xf * 4.0, p.y * 0.15), layer + 2.0);\n  if (detail) {\n    n += 0.35 * flowNoise(vec2f(xf * 11.0, p.y * 0.3), layer + 3.0);\n  }\n  var rays = mix(1.0, 0.6 + 0.55 * n, 0.85 - 0.45 * u.blur);\n  // The sheet thins where it folds edge-on.\n  var density = 0.45 + 0.55 * smoothstep(-0.6, 0.6, fold);\n  return vec2f(up * down * rays * density, clamp(rise / 0.75, 0.0, 1.0));\n}\n\nfn kindColor(p: vec2f, uv: vec2f) -> vec3f {\n  var h = frameHalf();\n  var lab = u.bg;\n  lab.x += 0.035 * smoothstep(0.3, -h.y, p.y);\n  var back = auroraSheet(p * vec2f(0.75, 1.0) + vec2f(0.9, 0.0), 11.0, -0.02, false);\n  var front = auroraSheet(p, 13.0, -0.3, true);\n  lab = labMix(lab, ramp(0.3 + 0.7 * back.y), clamp(back.x * 0.35, 0.0, 1.0));\n  lab = labMix(lab, ramp(front.y), clamp(front.x * 1.45, 0.0, 1.0));\n  // A bright hem, and the light it throws onto the horizon.\n  lab.x += 0.12 * front.x * (1.0 - front.y);\n  var horizon = exp(-(p.y + h.y) * 5.0) * (0.5 + 0.5 * front.x);\n  lab = labMix(lab, paletteColor(1), clamp(horizon * 0.2, 0.0, 1.0));\n  lab.x *= vignette(p, 0.3);\n  return filmGrade(lab);\n}\n`;\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/wgsl/aurora.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/wgsl/beam.ts",
      "content": "/**\n * WGSL twin of the beam kind's GLSL (beam.ts): same maths, line\n * for line, against shaders/wgsl-common.ts. Imported only when the WebGPU\n * backend draws this kind, so WebGL-only pages never download it.\n */\nexport const wgsl = /* wgsl */ `\n// Light from a point on or beyond the frame edge, spread into a cone of\n// rays. The rays are noise sampled across the cone's angle, so they are\n// fine across and long along the beam. scale widens the cone; warp sets\n// ray contrast.\n\n// One beam. Returns glow, the palette position, and how much of the light\n// is the white-hot core and needle.\nfn beamLight(p: vec2f, source: vec2f, aim: f32, width: f32, reach: f32, layer: f32, omni: f32) -> vec3f {\n  var axis = vec2f(sin(aim), cos(aim));\n  var v = p - source;\n  var dist = length(v);\n  var along = dot(v, axis);\n  var across = axis.x * v.y - axis.y * v.x;\n  var ang = atan2(across, max(along, 1e-3));\n  // GLSL calls this u, which would shadow the uniform block here.\n  var cu = ang / width;\n  var forward = smoothstep(-0.02, 0.06, along);\n  var cone = exp(-cu * cu) * forward;\n\n  // Rays: two scales of noise across the cone, stretched along it. A flare\n  // rays out all round, so it samples on the unit circle instead, which\n  // has no seam behind the source.\n  var dir = v / max(dist, 1e-4);\n  var coarseAt = select(vec2f(cu * 2.2, dist * 0.35), dir * 3.2 + vec2f(dist * 0.35, 0.0), omni > 0.5);\n  var fineAt = select(vec2f(cu * 6.0 + 13.0, dist * 0.9), dir * 9.0 + vec2f(13.0, dist * 0.9), omni > 0.5);\n  var coarse = flowNoise(coarseAt, layer);\n  var fine = flowNoise(fineAt, layer + 1.0);\n  cone = mix(cone, 0.55 + 0.45 * exp(-cu * cu), omni);\n  forward = mix(forward, 1.0, omni);\n  var fineAmount = 0.55 * (1.0 - 0.6 * u.blur);\n  var rays = 0.5 + 0.5 * (coarse + fineAmount * fine) / (1.0 + fineAmount);\n  rays = mix(1.0, smoothstep(0.1, 0.95, rays) * 1.5, u.warp);\n\n  var fall = exp(-dist / reach);\n  var core = exp(-dist / (0.05 + 0.05 * u.blur));\n  // A hairline down the axis, the brightest ray.\n  var needle = exp(-pow(across / (0.0035 + 0.01 * u.blur), 2.0)) * exp(-dist / (0.6 * reach)) * smoothstep(0.0, 0.03, along) * u.warp * (1.0 - 0.5 * omni);\n  var haze = exp(-dist / (0.4 + 0.5 * u.blur));\n  // A broad, soft fill under the rays gives the beam volume.\n  var fill = mix(exp(-cu * cu * 0.35), 1.0, omni) * forward * fall;\n\n  var glow = cone * fall * (0.2 + 0.8 * rays) + 0.22 * fill + 0.85 * core + 0.55 * needle + 0.08 * haze;\n  // Near the source the light is colour 0; colour takes over along the\n  // beam and at the cone's edges.\n  var t = clamp(dist / (reach * 1.4) + 0.35 * abs(cu) * (1.0 - omni) - 0.25 * core, 0.0, 1.0);\n  return vec3f(glow, t, clamp(core + needle, 0.0, 1.0));\n}\n\nfn kindColor(p: vec2f, uv: vec2f) -> vec3f {\n  var lightBg = smoothstep(0.55, 0.85, u.bg.x);\n  var h = frameHalf();\n  // The seed picks the source: bottom centre, a bottom corner, the top\n  // edge, a top corner, a side edge, two crossing beams from the bottom\n  // corners, a source far below or above the frame, so only its rays\n  // reach in, or a flare inside the frame raying out all round.\n  var framing = floor(fract(u.seed.x * 0.0731 + 0.5) * 9.0);\n  var side = sign(u.seed.y + 0.01);\n  var source = vec2f(0.0, -h.y - 0.02);\n  var aim = 0.0;\n  var width = 0.3 * u.scale;\n  var reach = 0.55 + 0.6 * u.scale;\n  if (framing == 1.0) {\n    source = vec2f(-side * (h.x - 0.06), -h.y - 0.02);\n    aim = side * 0.62;\n  } else if (framing == 2.0) {\n    source = vec2f(0.0, h.y + 0.02);\n    aim = 3.14159265;\n  } else if (framing == 3.0) {\n    source = vec2f(-side * (h.x - 0.1), h.y + 0.02);\n    aim = 3.14159265 - side * 0.5;\n  } else if (framing == 4.0) {\n    source = vec2f(-side * (h.x + 0.02), -0.12);\n    aim = side * 1.32;\n  } else if (framing == 5.0) {\n    source = vec2f(-(h.x - 0.12), -h.y - 0.02);\n    aim = 0.42;\n    width *= 0.7;\n  } else if (framing == 6.0) {\n    source = vec2f(0.3 * h.x * side, -h.y - 1.0);\n    aim = -side * 0.12;\n    width *= 0.45;\n    reach *= 2.4;\n  } else if (framing == 7.0) {\n    source = vec2f(0.3 * h.x * side, h.y + 1.0);\n    aim = 3.14159265 + side * 0.15;\n    width *= 0.45;\n    reach *= 2.4;\n  } else if (framing == 8.0) {\n    source = vec2f(0.22 * h.x * side, 0.04);\n    aim = seedAngle();\n    width = 0.6 * u.scale;\n    reach = 0.3 + 0.3 * u.scale;\n  }\n  // The cone sways a little through the loop.\n  var sway = 0.22 * u.loopv.y;\n  var light = beamLight(p, source, aim + sway, width, reach, 1.0, select(0.0, 1.0, framing == 8.0));\n  if (framing == 5.0) {\n    // The second beam mirrors the first and sways the other way.\n    var twin = beamLight(p, vec2f(-source.x, source.y), -aim - sway, width, reach, 4.0, 0.0);\n    var total = max(light.x + twin.x, 1e-4);\n    light = vec3f(light.x + twin.x, (light.x * light.y + twin.x * twin.y) / total, max(light.z, twin.z));\n  }\n  var glow = light.x;\n\n  var col = ramp(light.y);\n  col = labMix(col, paletteColor(0), light.z);\n  var lab = labMix(u.bg, col, clamp(glow, 0.0, 1.0));\n  lab.x += 0.08 * max(glow - 0.9, 0.0) * (1.0 - lightBg);\n  return filmGrade(lab);\n}\n`;\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/wgsl/beam.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/wgsl/chrome.ts",
      "content": "/**\n * WGSL twin of the chrome kind's GLSL (chrome.ts): same maths, line\n * for line, against shaders/wgsl-common.ts. Imported only when the WebGPU\n * backend draws this kind, so WebGL-only pages never download it.\n */\nexport const wgsl = /* wgsl */ `\nfn chromeHeight(q: vec2f, t1: vec2f, t2: vec2f) -> f32 {\n  let bendBy = (0.9 + 1.6 * u.warp) * flowNoise(q * vec2f(0.35, 0.55), 2.0);\n  let a = 2.1 * q.y + bendBy;\n  let c = 1.3 * q.x + 0.4 * bendBy + 1.3;\n  return sin(a) * t1.x - cos(a) * t1.y\n    + 0.2 * (sin(2.0 * a + 0.9) * t2.x - cos(2.0 * a + 0.9) * t2.y) * (1.0 - 0.6 * u.blur)\n    + 0.15 * (sin(c) * t2.x - cos(c) * t2.y);\n}\n\nfn chromeStudio(r: vec3f, sa: f32) -> vec3f {\n  let t = r.y * 0.9 + 0.3 * r.x * cos(sa);\n  let soft = 0.04 + 0.12 * u.blur;\n  var floorC = labMix(u.bg, paletteColor(0), 0.08 + 0.5 * smoothstep(0.9, 1.0, r.z));\n  floorC = labMix(floorC, paletteColor(0), 0.7 * exp(-pow((t + 0.5) / (0.18 + soft), 2.0)));\n  var env = labMix(floorC, paletteColor(0), smoothstep(0.1, 0.3, t));\n  let horizon = exp(-pow((t - 0.12) / (soft * 1.3), 2.0));\n  env = labMix(env, u.bg, 0.92 * horizon);\n  let cool = exp(-pow((t - 0.4) / (soft * 0.9), 2.0));\n  env = labMix(env, paletteColor(select(1, 2, u.count > 2)), 0.55 * cool);\n  let key = exp(-pow((t - 0.58) / soft, 2.0));\n  env = labMix(env, paletteColor(1), key);\n  env.x += 0.16 * key * key;\n  env = labMix(env, u.bg, 0.6 * smoothstep(0.75, 1.0, t));\n  return env;\n}\n\nfn kindColor(p: vec2f, uv: vec2f) -> vec3f {\n  let sa = seedAngle();\n  let t1 = loopTurn();\n  let t2 = vec2f(t1.x * t1.x - t1.y * t1.y, 2.0 * t1.x * t1.y);\n  let q = rot2(0.6 * sin(sa) + 0.3) * p * 1.75 * u.scale + vec2f(1.7, -0.9) * cos(sa);\n\n  let e = 0.004;\n  let h = chromeHeight(q, t1, t2);\n  let g = vec2f(chromeHeight(q + vec2f(e, 0.0), t1, t2) - h, chromeHeight(q + vec2f(0.0, e), t1, t2) - h) / e;\n  let n = normalize(vec3f(-g * 0.6 / sqrt(u.scale), 1.0));\n  let r = reflect(vec3f(0.0, 0.0, -1.0), n);\n\n  var lab = chromeStudio(r, sa);\n  lab = labMix(lab, u.bg, 0.3 * (1.0 - smoothstep(-1.8, -0.6, h)));\n  lab.x *= vignette(p, 0.35);\n  return filmGrade(lab);\n}\n`;\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/wgsl/chrome.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/wgsl/dither-burst.ts",
      "content": "/**\n * WGSL twin of the dither-burst kind's GLSL (dither-burst.ts): same maths, line\n * for line, against shaders/wgsl-common.ts. Imported only when the WebGPU\n * backend draws this kind, so WebGL-only pages never download it.\n */\nexport const wgsl = /* wgsl */ `\nfn dbBayer2(a0: vec2f) -> f32 {\n  let a = floor(a0);\n  return fract(dot(a, vec2f(0.5, a.y * 0.75)));\n}\n\nfn dbBayer8(a: vec2f) -> f32 {\n  return dbBayer2(0.25 * a) * 0.0625 + dbBayer2(0.5 * a) * 0.25 + dbBayer2(a);\n}\n\n// Interleaved gradient noise (Jimenez 2014): ordered, but with no visible\n// period, so it reads like blue noise.\nfn dbIgn(a: vec2f) -> f32 {\n  return fract(52.9829189 * fract(dot(floor(a), vec2f(0.06711056, 0.00583715))));\n}\n\n// GLSL's vec3(bvec3): 1.0 where true.\nfn dbMask(b: vec3<bool>) -> vec3f {\n  return select(vec3f(0.0), vec3f(1.0), b);\n}\n\nfn dbLabToSrgb(lab: vec3f) -> vec3f {\n  var l = lab.x + 0.3963377774 * lab.y + 0.2158037573 * lab.z;\n  var m = lab.x - 0.1055613458 * lab.y - 0.0638541728 * lab.z;\n  var s = lab.x - 0.0894841775 * lab.y - 1.2914855480 * lab.z;\n  var lin = vec3f(\n    4.0767416621 * l * l * l - 3.3077115913 * m * m * m + 0.2309699292 * s * s * s,\n    -1.2684380046 * l * l * l + 2.6097574011 * m * m * m - 0.3413193965 * s * s * s,\n    -0.0041960863 * l * l * l - 0.7034186147 * m * m * m + 1.7076147010 * s * s * s\n  );\n  lin = clamp(lin, vec3f(0.0), vec3f(1.0));\n  return mix(1.055 * pow(lin, vec3f(1.0 / 2.4)) - 0.055, lin * 12.92, dbMask(lin <= vec3f(0.0031308)));\n}\n\nfn dbSrgbToLab(c: vec3f) -> vec3f {\n  var lin = mix(pow((c + 0.055) / 1.055, vec3f(2.4)), c / 12.92, dbMask(c <= vec3f(0.04045)));\n  var l = 0.4122214708 * lin.r + 0.5363325363 * lin.g + 0.0514459929 * lin.b;\n  var m = 0.2119034982 * lin.r + 0.6806995451 * lin.g + 0.1073969566 * lin.b;\n  var s = 0.0883024619 * lin.r + 0.2817188376 * lin.g + 0.6299787005 * lin.b;\n  var lms = pow(max(vec3f(l, m, s), vec3f(0.0)), vec3f(1.0 / 3.0));\n  return vec3f(\n    0.2104542553 * lms.x + 0.7936177850 * lms.y - 0.0040720468 * lms.z,\n    1.9779984951 * lms.x - 2.4285922050 * lms.y + 0.4505937099 * lms.z,\n    0.0259040371 * lms.x + 0.7827717662 * lms.y - 0.8086757660 * lms.z\n  );\n}\n\n// How far the palette strays from the background. A flat palette has\n// nothing to dither between, so it renders flat.\nfn dbSpread() -> f32 {\n  var d = 0.0;\n  for (var i = 0; i < 6; i++) {\n    if (i >= u.count) { break; }\n    d = max(d, length(u.colors[i].xyz - u.bg));\n  }\n  return smoothstep(0.0, 0.04, d);\n}\n\n// The light's intensity at q: 0 is the background, 1 the core.\nfn dbLight(q: vec2f, h: vec2f, mode: f32, side: f32) -> f32 {\n  var s = 1.0 / u.scale;\n  var soft = 0.6 + 0.8 * u.blur;\n  if (mode < 1.0) {\n    // Burst: broad, blurred rays from a point just past one edge.\n    var a = 1.5708 + (side - 0.5) * 2.4;\n    var src = vec2f(cos(a), -abs(sin(a))) * h * vec2f(1.0, 1.4) + 0.3 * drift(1.0);\n    var d = q - src;\n    var r = length(d);\n    var dir = d / max(r, 1e-4);\n    // Rays are noise on the unit circle, low in angle so they stay broad;\n    // they fade in away from the source so it never reads as a star.\n    var rays = 0.5 + 0.5 * flowNoise(dir * (1.6 + 1.4 * u.warp), 2.0);\n    rays = mix(rays, 0.5 + 0.5 * flowNoise(dir * 4.0 + 7.0, 3.0), 0.3);\n    var ray = mix(1.0, 0.25 + 1.2 * rays * rays, (0.35 + 0.55 * u.warp) * smoothstep(0.05, 0.7, r));\n    var body = exp(-r / (0.62 * s * soft));\n    return 1.15 * body * ray + 0.3 * exp(-r / (0.2 * s * soft));\n  }\n  if (mode < 2.0) {\n    // Horizon: a huge disc rising from below, glowing into the dark.\n    var tilt = (side - 0.5) * 0.5;\n    var t = rot2(tilt) * q;\n    var radius = 1.7 * s;\n    var lift = (0.12 + 0.18 * u.scale) * h.y + 0.1 * flowNoise(vec2f(0.4, 0.9), 1.0);\n    var centre = vec2f(0.45 * drift(2.0).x, -h.y - radius + lift);\n    var x = length(t - centre) - radius;\n    // The edge undulates, and with warp it drips into vertical streaks.\n    x += 0.035 * u.warp * flowNoise(vec2f(t.x * 2.2, 0.3), 3.0);\n    x += 0.06 * u.warp * u.warp * flowNoise(vec2f(t.x * 9.0, t.y * 0.6), 4.0) * (1.0 - smoothstep(-0.05, 0.25, x));\n    var above = exp(-max(x, 0.0) / (0.14 * soft));\n    var below = mix(1.0, 0.72, (1.0 - smoothstep(-0.6, 0.0, x)));\n    if (x > 0.0) { return 0.92 * above; }\n    return 0.92 + 0.3 * below * (1.0 - smoothstep(-0.08, 0.0, x));\n  }\n  if (mode < 3.0) {\n    // Beam: a long diagonal band, a thin hot core in a wide soft halo.\n    var a = 0.45 + (side - 0.5) * 1.1;\n    var dir = vec2f(cos(a), sin(a));\n    var n = vec2f(-dir.y, dir.x);\n    // GLSL calls this u, which would shadow the uniform block here.\n    var bu = dot(q, dir);\n    var v = dot(q, n) + 0.08 * h.y + 0.14 * u.loopv.y + 0.07 * u.warp * flowNoise(vec2f(bu * 0.9, 0.5), 2.0) - 0.12 * bu * bu;\n    var w = 0.05 * s * soft;\n    var core = exp(-v * v / (w * w));\n    var halo = exp(-abs(v) / (4.0 * w));\n    var along = smoothstep(-1.4 * h.x, 0.3 * h.x, bu) * (0.85 + 0.15 * flowNoise(vec2f(bu * 1.2, 1.7), 3.0));\n    return (0.75 * core + 0.6 * halo) * along;\n  }\n  // Bloom: light leaning in from a lower corner, with a hard-ish shoulder\n  // where it meets the dark, bent by the flow.\n  var corner = vec2f(select(1.0, -1.0, side < 0.5), -1.0) * h;\n  var c = corner * 0.92 + 0.3 * drift(3.0);\n  var w = q + 0.1 * u.warp * vec2f(flowNoise(q * 1.1, 4.0), flowNoise(q * 1.1 + 3.3, 5.0));\n  var d = rot2((side - 0.5) * 1.4) * (w - c);\n  var r = length(d * vec2f(0.75, 1.0));\n  // The light spills out of the lobe in a long, uneven tail.\n  var tail = exp(-r / (0.55 * s * soft)) * (0.7 + 0.3 * flowNoise(d * 1.6 + 2.0, 7.0));\n  var edge = 1.0 - smoothstep((1.0 - 0.6 * soft) * s, s, r);\n  return 0.95 * edge * exp(-r / (1.1 * s * soft)) + 0.45 * tail;\n}\n\nfn kindColor(p: vec2f, uv: vec2f) -> vec3f {\n  var h = frameHalf();\n  // The built-in dither; the engine's, when on, replaces it.\n  var own = u.dither.x < 0.5;\n  var cell = select(1.0, 3.0, own);\n  var px = uv * u.full;\n  var id = floor(px / cell);\n  var centre = (id + 0.5) * cell;\n  var q = (centre - 0.5 * u.full) / min(u.full.x, u.full.y);\n  q.y = -q.y;\n  q = interact(q);\n\n  var pick8 = floor(fract(u.seed.x * 0.0731 + 0.5) * 8.0);\n  var mode = gmod1(pick8, 4.0);\n  var side = fract(u.seed.y * 0.0917 + 0.5);\n\n  var light = dbLight(q, h, mode, side);\n  var t = clamp(pow(max(light, 0.0), 1.25), 0.0, 1.0);\n  var lab = labMix(u.bg, ramp(t), smoothstep(0.0, 0.4, t));\n  // Past the core the light bleaches toward the palette's brightest.\n  var hot = paletteColor(u.count - 1);\n  lab = labMix(lab, vec3f(min(hot.x + 0.04, 1.0), hot.yz * 0.7), clamp((light - 1.0) * 1.5, 0.0, 1.0));\n  var lightBg = smoothstep(0.55, 0.85, u.bg.x);\n  lab.x *= vignette(q, 0.25 * (1.0 - lightBg));\n  lab = filmGrade(lab);\n  if (!own) { return lab; }\n\n  // Ordered dither per sRGB channel, one threshold per cell.\n  var spread = dbSpread();\n  var threshold = select(dbIgn(id), dbBayer8(id), pick8 < 4.0);\n  var steps = 11.0;\n  var rgb = dbLabToSrgb(lab);\n  var dithered = floor(rgb * steps + threshold) / steps;\n  rgb = mix(rgb, dithered, vec3f(spread));\n  // The cells read as a display: a faint seam on two edges.\n  var local = px - id * cell;\n  if (local.x >= cell - 1.0 || local.y >= cell - 1.0) {\n    rgb *= 1.0 - 0.1 * spread;\n  }\n  return dbSrgbToLab(clamp(rgb, vec3f(0.0), vec3f(1.0)));\n}\n`;\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/wgsl/dither-burst.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/wgsl/dither-field.ts",
      "content": "/**\n * WGSL twin of the dither-field kind's GLSL (dither-field.ts): same maths, line\n * for line, against shaders/wgsl-common.ts. Imported only when the WebGPU\n * backend draws this kind, so WebGL-only pages never download it.\n */\nexport const wgsl = /* wgsl */ `\nconst BAYER_DF = array<f32, 16>(\n  0.0, 8.0, 2.0, 10.0,\n  12.0, 4.0, 14.0, 6.0,\n  3.0, 11.0, 1.0, 9.0,\n  15.0, 7.0, 13.0, 5.0\n);\n\n// Ramp stop i: 0 is the background, then the palette. An if, not a select,\n// so i <= 0 never indexes the palette at -1.\nfn dfStop(i: i32) -> vec3f {\n  if (i <= 0) { return u.bg; }\n  return u.colors[min(i - 1, u.count - 1)].xyz;\n}\n\n// The body's height, 0..1, at q (p units). It sits right of centre, or low\n// in portrait frames, and falls to 0 well before the opposite side.\nfn dfField(q: vec2f, h: vec2f) -> f32 {\n  var portrait = clamp((h.y / h.x - 0.8) / 0.6, 0.0, 1.0);\n  var centre = mix(vec2f(0.52 * h.x, -0.02), vec2f(0.04, -0.62 * h.y), portrait);\n  var reach = mix(0.56, 0.5, portrait);\n  var w = q + u.warp * 0.2 * vec2f(flowNoise(q * 1.1, 1.0), flowNoise(q * 1.1 + 4.1, 2.0));\n  var d = (w - centre) * vec2f(0.9, 1.0);\n  var body = pow(clamp(1.0 - length(d) / reach, 0.0, 1.0), 0.75);\n  // A second, smaller lobe circling the first.\n  var orbit = centre + 0.3 * normalize(drift(3.0) + vec2f(1e-4)) * vec2f(1.2, 0.7);\n  var lobe = pow(clamp(1.0 - length(w - orbit) / 0.24, 0.0, 1.0), 1.4);\n  body = max(body, 0.55 * lobe) + 0.25 * body * lobe;\n  body += 0.06 * flowNoise(w * 2.4, 4.0) * smoothstep(0.0, 0.2, body);\n  // Keep clear of the opposite side, where a hero puts its copy.\n  var side = mix(q.x / h.x, -q.y / h.y, portrait);\n  body *= smoothstep(mix(-0.18, 0.1, portrait), mix(0.25, 0.42, portrait), side);\n  return clamp(body, 0.0, 1.0);\n}\n\nfn kindColor(p: vec2f, uv: vec2f) -> vec3f {\n  var h = frameHalf();\n  var minSide = min(u.full.x, u.full.y);\n  var px = floor(uv * u.full);\n  var coarse = 4.0 * clamp(floor(u.scale * 4.0 + 0.5), 2.0, 16.0);\n\n  // The focus: an idle drift, eased toward the pointer while it is near.\n  var idle = mix(vec2f(0.46 * h.x, 0.04), vec2f(0.0, -0.6 * h.y), clamp((h.y / h.x - 0.8) / 0.6, 0.0, 1.0)) + 0.12 * drift(1.5);\n  var ptr = (u.pointer.xy - 0.5) * 2.0 * h;\n  ptr.y = -ptr.y;\n  var focus = mix(idle, ptr, clamp(u.pointer.z, 0.0, 1.0));\n\n  // Quadtree: a cell splits while its centre is inside the next radius.\n  var core = 0.07 + 0.08 * u.blur;\n  var radii = array<f32, 3>(core * 3.6, core * 2.2, core);\n  var size = coarse;\n  var id = floor(px / size);\n  var tier = 0;\n  for (var k = 0; k < 3; k++) {\n    var centre = (id + 0.5) * size;\n    var cq = (centre - 0.5 * u.full) / minSide;\n    cq.y = -cq.y;\n    var dq = abs(cq - focus);\n    if (max(dq.x, dq.y) >= radii[k]) { break; }\n    tier = k + 1;\n    if (k < 2) {\n      size *= 0.5;\n      id = floor(px / size);\n    }\n  }\n\n  // Viewfinder brackets around the smooth square, in the ramp's last stop,\n  // shown only while the square sits on the body.\n  var fine = coarse * 0.25;\n  var fpx = vec2f(focus.x, -focus.y) * minSide + 0.5 * u.full;\n  var corePx = radii[2] * minSide;\n  var lo = (ceil((fpx - corePx) / fine - 0.5)) * fine;\n  var hi = (floor((fpx + corePx) / fine - 0.5) + 1.0) * fine;\n  var gap = 3.0;\n  var arm = max(10.0, fine * 3.0);\n  var inBox = all(px > lo - gap - 3.0) && all(px < hi + gap + 3.0);\n  var inner = all(px > lo - gap - 1.0) && all(px < hi + gap + 1.0);\n  var nearCorner = (min(abs(px.x - lo.x), abs(px.x - hi.x)) < arm) && (min(abs(px.y - lo.y), abs(px.y - hi.y)) < arm);\n  if (hi.x > lo.x && inBox && !inner && nearCorner && dfField(focus, h) > 0.2) {\n    return dfStop(u.count);\n  }\n\n  var stops = f32(u.count);\n  if (tier == 3) {\n    // Sampled from the pixel itself: the prelude's pointer lens bends p,\n    // which would tear the core away from the cells around it.\n    var sq = (px + 0.5 - 0.5 * u.full) / minSide;\n    sq.y = -sq.y;\n    var x = dfField(sq, h) * stops;\n    var i = i32(floor(x));\n    var f = smoothstep(0.0, 1.0, fract(x));\n    return labMix(dfStop(i), dfStop(i + 1), f);\n  }\n\n  var cellPx = (id + 0.5) * size;\n  var q = (cellPx - 0.5 * u.full) / minSide;\n  q.y = -q.y;\n  var x = dfField(q, h) * stops;\n  var b = vec2i(gmod2(id, 4.0));\n  var threshold = (BAYER_DF[b.y * 4 + b.x] + 0.5) / 16.0;\n  var i = i32(floor(x)) + select(0, 1, fract(x) > threshold);\n  // Coarse cells read as a display: a hairline gap between lit cells, and a\n  // faint unlit pixel at the centre of every empty one.\n  var local = px - id * size;\n  if (i == 0) {\n    var dot_ = abs(local - (size * 0.5 - 1.0));\n    var lit = tier == 0 && max(dot_.x, dot_.y) < 1.0;\n    if (lit) { return mix(u.bg, dfStop(1), 0.4); }\n    return u.bg;\n  }\n  if (tier == 0 && (local.x >= size - 1.0 || local.y >= size - 1.0)) {\n    return mix(dfStop(i), u.bg, 0.35);\n  }\n  return dfStop(i);\n}\n`;\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/wgsl/dither-field.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/wgsl/fluted.ts",
      "content": "/**\n * WGSL twin of the fluted kind's GLSL (fluted.ts): same maths, line\n * for line, against shaders/wgsl-common.ts. Imported only when the WebGPU\n * backend draws this kind, so WebGL-only pages never download it.\n */\nexport const wgsl = /* wgsl */ `\n// The light behind the glass at q: intensity (x) and the column's core (y).\nfn flLight(q: vec2f, h: vec2f, mode: f32, side: f32) -> vec2f {\n  var soft = 0.5 + 0.9 * u.blur;\n  var ribbon = 0.0;\n  if (mode != 1.0) {\n    // A ribbon sweeping corner to corner, bending with the flow.\n    var a = -0.6 + (side - 0.5) * 0.9;\n    var dir = vec2f(cos(a), sin(a));\n    var n = vec2f(-dir.y, dir.x);\n    // GLSL calls this u, which would shadow the uniform block here.\n    var ru = dot(q, dir);\n    var v = dot(q, n) - 0.18 * sin(ru * 2.2 + 1.3 * side) * h.y;\n    v += 0.1 * flowNoise(vec2f(ru * 0.8, 0.2), 1.0);\n    // Lit from above: a crisp bright lip, then a long fall into the dark.\n    var w = 0.13 * soft;\n    var lip = select(exp(v / (1.4 * w)), exp(-v * v / (0.5 * w * w)), v > 0.0);\n    var glow = exp(-abs(v) / (5.0 * w));\n    // A second, fainter fold under the first.\n    var v2 = v + 0.3 + 0.06 * flowNoise(vec2f(ru * 0.7, 2.1), 2.0);\n    var fold = 0.3 * select(exp(v2 / (2.0 * w)), exp(-v2 * v2 / (0.2 * w * w)), v2 > 0.0);\n    ribbon = (0.95 * lip + 0.15 * glow + 0.75 * fold) * (0.8 + 0.2 * flowNoise(vec2f(ru * 1.5, 3.0), 3.0));\n  }\n  var column = 0.0;\n  var core = 0.0;\n  if (mode == 1.0) {\n    // An arch: the top of a big soft disc rising from below, its rim lit\n    // hardest at the crown and its body falling away into the dark.\n    var c = vec2f((side - 0.5) * 1.1 * h.x, -1.35 * h.y) + vec2f(0.06, 0.03) * drift(4.0);\n    var radius = 1.05 * h.y + 0.3 * h.x * abs(side - 0.5);\n    var d = (q - c) * vec2f(0.8, 1.0);\n    var r = length(d);\n    var x = r - radius + 0.03 * flowNoise(d * 1.4, 5.0);\n    var crown = 0.45 + 0.55 * smoothstep(-0.2, 1.0, d.y / max(r, 1e-3));\n    var w = 0.08 * soft;\n    var rim = exp(-x * x / (w * w));\n    var body = select(exp(-x / (0.22 * soft)), exp(x / (0.3 * soft)), x < 0.0);\n    column = 0.85 * (0.5 * rim + 0.75 * body) * crown;\n  } else if (mode == 2.0) {\n    var x0 = (side - 0.5) * 0.9 * h.x + 0.04 * drift(4.0).x + 0.025 * flowNoise(vec2f(0.5, q.y * 1.2), 7.0);\n    var dx = q.x - x0;\n    var tall = smoothstep(-1.2 * h.y, 0.3 * h.y, q.y + 0.15 * flowNoise(vec2f(0.3, q.y), 5.0));\n    core = exp(-dx * dx / (0.006 * soft)) * mix(0.6, 1.0, tall);\n    column = 0.85 * core + 0.35 * exp(-abs(dx) / (0.16 * soft)) * mix(0.55, 1.0, tall);\n  }\n  return vec2f(ribbon + column, core);\n}\n\nfn kindColor(p: vec2f, uv: vec2f) -> vec3f {\n  var h = frameHalf();\n  var minSide = min(u.full.x, u.full.y);\n  var mode = floor(fract(u.seed.x * 0.0731 + 0.5) * 3.0);\n  var side = fract(u.seed.y * 0.0917 + 0.5);\n\n  // Flutes: an uneven but monotonic stretch of x, so widths vary.\n  var w = (2.0 * h.x) / (36.0 * u.scale);\n  var x = p.x / w;\n  var xf = x + 0.32 * sin(x * 0.61 + 1.7) + 0.18 * sin(x * 1.37 + 0.4);\n  // GLSL calls this u, which would shadow the uniform block here.\n  var fu = fract(xf);\n  var idx = floor(xf);\n  // Progressive refraction: the image slides across each flute.\n  var shift = (0.3 + 1.6 * u.warp) * w;\n  var q = p;\n  q.x += (fu - 0.5) * shift;\n  // Each flute leans the image a touch, so diagonal edges turn into teeth.\n  q.y += (fu - 0.5) * shift * 0.35 * sin(idx * 2.3);\n\n  var light = flLight(q, h, mode, side);\n  var t = clamp(pow(light.x, 1.15), 0.0, 1.0);\n  var col = ramp(t);\n  col = labMix(col, paletteColor(u.count - 1), light.y * 0.85);\n  var lab = labMix(u.bg, col, smoothstep(0.0, 0.45, t));\n\n  // Glass: the curve catches a thin highlight near one side of each flute\n  // and darkens toward the seams.\n  var seen = clamp(length(lab - u.bg) * 4.0, 0.0, 1.0);\n  // Hand-made glass: each flute is a touch brighter or darker.\n  lab.x *= 1.0 + 0.07 * seen * (fract(sin(idx * 12.9898) * 43758.5453) - 0.5);\n  var curve = sin(fu * 3.14159265);\n  lab.x += (0.05 * exp(-pow((fu - 0.28) / 0.07, 2.0)) - 0.04 * (1.0 - curve)) * mix(0.35, 1.0, seen);\n  var seamPx = min(fu, 1.0 - fu) * w * minSide;\n  lab.x -= 0.05 * (1.0 - smoothstep(0.0, 1.2, seamPx)) * seen;\n  var lightBg = smoothstep(0.55, 0.85, u.bg.x);\n  lab.x *= vignette(p, 0.3 * (1.0 - lightBg));\n  return filmGrade(lab);\n}\n`;\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/wgsl/fluted.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/wgsl/grain.ts",
      "content": "/**\n * WGSL twin of the grain kind's GLSL (grain.ts): same maths, line\n * for line, against shaders/wgsl-common.ts. Imported only when the WebGPU\n * backend draws this kind, so WebGL-only pages never download it.\n */\nexport const wgsl = /* wgsl */ `\nfn kindColor(p: vec2f, uv: vec2f) -> vec3f {\n  var h = frameHalf();\n  // The light sits just outside the frame and throws a beam across it.\n  var a = seedAngle();\n  var dir = vec2f(cos(a), sin(a));\n  var across = vec2f(-dir.y, dir.x);\n  var src = -dir * (abs(dir.x) * h.x + abs(dir.y) * h.y + 0.12);\n  var q = p - src;\n  // GLSL calls this u, which would shadow the uniform block here.\n  var bu = dot(q, dir);\n  var v = dot(q, across);\n\n  var bend = 0.06 * sin(bu * 1.4 + 0.6 * u.loopv.x + a)\n    + 0.12 * u.warp * flowNoise(vec2f(bu * 0.7, 1.3) * u.scale, 1.0);\n  var width = (0.1 + 0.18 * u.blur) * (0.45 + 0.7 * bu);\n  var vb = v - bend;\n  var beam = exp(-vb * vb / (width * width));\n  // Brushed streaks: long along the beam, short across it.\n  var streak = flowNoise(vec2f(bu * 0.8, vb * 9.0 / (0.45 + u.blur)) * u.scale, 2.0);\n  // A wider, dimmer sheet behind it for depth.\n  var vb2 = v + 0.3 - 0.5 * bend;\n  var beam2 = exp(-vb2 * vb2 / (width * width * 4.0));\n  var fall = exp(-bu * 0.75);\n  var source = exp(-dot(q, q) * 2.2);\n\n  var intensity = (beam * (0.88 + 0.3 * streak) + 0.35 * beam2 * (0.8 + 0.3 * streak)) * fall * 1.5\n    + 0.55 * source;\n  var ti = 1.0 - exp(-1.6 * intensity);\n  var col = ramp(1.0 - ti);\n  var lab = labMix(u.bg, col, smoothstep(0.0, 0.75, ti));\n  lab.x += 0.08 * max(intensity - 1.0, 0.0);\n  lab.x *= vignette(p, 0.35);\n  return filmGrade(lab);\n}\n`;\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/wgsl/grain.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/wgsl/halo.ts",
      "content": "/**\n * WGSL twin of the halo kind's GLSL (halo.ts): same maths, line\n * for line, against shaders/wgsl-common.ts. Imported only when the WebGPU\n * backend draws this kind, so WebGL-only pages never download it.\n */\nexport const wgsl = /* wgsl */ `\n// A thick torus of light: the inner edge is crisp, the body holds its\n// brightness then rolls off into a wide haze. warp sets how lopsided the\n// light is and how far the hue wanders round the ring; blur softens the\n// rim and widens the haze.\nfn haloBody(x: f32, soft: f32, width: f32) -> f32 {\n  var edge = smoothstep(-soft, soft, x);\n  var xo = max(x, 0.0) / width;\n  var x4 = xo * xo * xo * xo;\n  return edge / (1.0 + x4 * x4);\n}\n\nfn kindColor(p: vec2f, uv: vec2f) -> vec3f {\n  var lightBg = smoothstep(0.55, 0.85, u.bg.x);\n  var h = frameHalf();\n  // The seed picks a framing: centred, rising from the bottom edge, off to\n  // one side, hanging in a top corner and cropped by the frame, or tilted\n  // into an ellipse, as if seen at an angle, centred or low like a portal.\n  var framing = floor(fract(u.seed.x * 0.0731 + 0.5) * 6.0);\n  var side = sign(u.seed.y + 0.01);\n  var centre = vec2f(0.0, 0.0);\n  var radius = 0.19;\n  var tilt = 0.0;\n  var squash = 1.0;\n  if (framing == 1.0) {\n    centre = vec2f(0.0, -0.56);\n    radius = 0.3;\n  } else if (framing == 2.0) {\n    centre = vec2f(0.34 * h.x * side, -0.02);\n    radius = 0.2;\n  } else if (framing == 3.0) {\n    centre = vec2f(-side * (h.x - 0.12), h.y - 0.1);\n    radius = 0.3;\n  } else if (framing == 4.0) {\n    radius = 0.3;\n    tilt = 0.22 * side;\n    squash = 0.4;\n  } else if (framing == 5.0) {\n    centre = vec2f(0.0, -0.3);\n    radius = 0.44;\n    tilt = 0.08 * side;\n    squash = 0.28;\n  }\n  radius *= u.scale;\n\n  // The hot side sways slowly round the ring.\n  var swing = seedAngle() + 2.4 * u.loopv.x;\n  var hotDir = vec2f(sin(swing), cos(swing));\n\n  var d = rot2(tilt) * (p - centre);\n  d.y /= squash;\n  var r = length(d);\n  var dir = d / max(r, 1e-4);\n  var x = r / radius - 1.0;\n\n  var soft = 0.01 + 0.06 * u.blur;\n  var width = 0.42 + 0.2 * u.blur;\n  var hot = 0.5 + 0.5 * dot(dir, hotDir);\n  var key = mix(1.0, 0.22 + 0.78 * hot * hot, 0.3 + 0.6 * u.warp);\n\n  // Noise sampled on the unit circle (so it has no seam) drifts the hue\n  // and, a little, the thickness round the ring.\n  var around = flowNoise(dir * 0.8 + vec2f(3.1, 0.0), 2.0);\n  var body = haloBody(x, soft, width * (1.0 + 0.07 * u.warp * flowNoise(dir * 0.7, 1.0)));\n  // A ghost exposure, nudged toward the hot side: a doubled, glassy rim.\n  var dg = d - hotDir * radius * 0.08;\n  var xg = length(dg) / radius - 1.06;\n  var ghost = smoothstep(-soft, soft, xg) * exp(-max(xg, 0.0) / (0.05 + 0.08 * u.blur));\n  var haze = exp(-max(x, 0.0) / (0.6 + 0.8 * u.blur)) * smoothstep(0.0, width, x);\n  // Faint tinted fog inside the core, so the dark has depth.\n  var fog = (1.0 - smoothstep(-soft, soft, x)) * exp(x / 0.25);\n\n  var glow = 0.95 * body * key + 0.3 * ghost * (0.3 + 0.7 * hot) + 0.12 * haze * (0.4 + 0.6 * key) + 0.12 * fog * (0.3 + 0.7 * hot);\n\n  // Colour: the inner rim runs hot (colour 0), the body moves through the\n  // palette outward, and the hue drifts round the ring.\n  var depth = clamp(max(x, 0.0) / (width * 1.6), 0.0, 1.0);\n  var t = clamp(0.12 + 0.45 * depth + 0.5 * u.warp * (0.5 + 0.5 * around) + 0.35 * (1.0 - hot), 0.0, 1.0);\n  var col = ramp(t);\n  var rimLine = smoothstep(-soft, soft, x) * exp(-max(x, 0.0) / (0.06 + 0.1 * u.blur));\n  col = labMix(col, paletteColor(0), rimLine * hot * 0.8);\n  col = labMix(col, paletteColor(u.count - 1), fog * 0.6);\n\n  var lab = labMix(u.bg, col, clamp(glow, 0.0, 1.0));\n  lab.x += 0.08 * max(glow - 0.85, 0.0) * (1.0 - lightBg);\n  return filmGrade(lab);\n}\n`;\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/wgsl/halo.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/wgsl/horizon.ts",
      "content": "/**\n * WGSL twin of the horizon kind's GLSL (horizon.ts): same maths, line\n * for line, against shaders/wgsl-common.ts. Imported only when the WebGPU\n * backend draws this kind, so WebGL-only pages never download it.\n */\nexport const wgsl = /* wgsl */ `\nfn hzCol(i: i32) -> vec3f { return u.colors[min(i, u.count - 1)].xyz; }\n\n// Sin-free lattice hash (Dave Hoskins), -1..1.\nfn hzHash(p: vec2f) -> vec2f {\n  var p3 = fract(vec3f(p.xyx) * vec3f(0.1031, 0.103, 0.0973));\n  p3 += dot(p3, p3.yzx + 33.33);\n  return fract((p3.xx + p3.yz) * p3.zy) * 2.0 - 1.0;\n}\n\n// 2D gradient noise, roughly -0.7..0.7.\nfn hzNoise(p: vec2f) -> f32 {\n  var i = floor(p);\n  var f = fract(p);\n  var fu = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);\n  var a = dot(hzHash(i), f);\n  var b = dot(hzHash(i + vec2f(1.0, 0.0)), f - vec2f(1.0, 0.0));\n  var c = dot(hzHash(i + vec2f(0.0, 1.0)), f - vec2f(0.0, 1.0));\n  var d = dot(hzHash(i + vec2f(1.0, 1.0)), f - vec2f(1.0, 1.0));\n  return mix(mix(a, b, fu.x), mix(c, d, fu.x), fu.y);\n}\n\n// Gradient noise with its analytic derivative: (value, d/dx, d/dy).\nfn hzNoiseD(p: vec2f) -> vec3f {\n  var i = floor(p);\n  var f = fract(p);\n  var fu = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);\n  var du = 30.0 * f * f * (f * (f - 2.0) + 1.0);\n  var ga = hzHash(i);\n  var gb = hzHash(i + vec2f(1.0, 0.0));\n  var gc = hzHash(i + vec2f(0.0, 1.0));\n  var gd = hzHash(i + vec2f(1.0, 1.0));\n  var va = dot(ga, f);\n  var vb = dot(gb, f - vec2f(1.0, 0.0));\n  var vc = dot(gc, f - vec2f(0.0, 1.0));\n  var vd = dot(gd, f - vec2f(1.0, 1.0));\n  var k = va - vb - vc + vd;\n  var v = va + fu.x * (vb - va) + fu.y * (vc - va) + fu.x * fu.y * k;\n  var d = ga + fu.x * (gb - ga) + fu.y * (gc - ga) + fu.x * fu.y * (ga - gb - gc + gd)\n    + du * (fu.yx * k + vec2f(vb, vc) - va);\n  return vec3f(v, d);\n}\n\n// The loop point rotated by a per-layer angle: still periodic, out of phase.\nfn hzLoop(a: f32) -> vec2f {\n  var c = cos(a);\n  var s = sin(a);\n  return vec2f(c * u.loopv.x - s * u.loopv.y, s * u.loopv.x + c * u.loopv.y);\n}\n\n// Sheet coordinates: stretched, drifting on the loop circle, seeded.\nfn hzSheet(sp: vec2f, freq: vec2f, layer: f32) -> vec2f {\n  return sp * freq + hzLoop(layer * 2.1) * vec2f(0.9, 0.5) + u.seed * 0.37 + layer * 13.7;\n}\n\n// Height of the horizon at x, measured against grainient's hero: a wide well\n// just right of centre, a gentle shelf on the left and a late climb on the\n// right. Portrait frames sit the horizon lower.\nfn hzRim(x: f32, portrait: f32, breathe: f32) -> f32 {\n  var well = exp(-(x - 0.08) * (x - 0.08) * 4.5);\n  var r = max(x - 0.4, 0.0);\n  var shelf = -0.145 - 0.035 * (1.0 - smoothstep(-0.6, 0.0, x));\n  return shelf - (0.19 + breathe) * well * (1.0 - 0.75 * portrait) + 0.65 * r * r - 0.11 * portrait;\n}\n\n// The void: black, with a cool haze bleeding up from the horizon and faint\n// ripple rings inside it.\nfn hzVoid(inside: f32, sideGlow: f32) -> vec3f {\n  var haze = (exp(-inside * 30.0) * 0.2 + exp(-inside * 10.0) * 0.06) * sideGlow;\n  var rings = sin(inside * 210.0 - 0.8 * hzLoop(2.5).y) * exp(-inside * 6.0);\n  return vec3f(haze * (1.0 + 0.22 * rings) + 0.005 * rings, hzCol(2).yz * haze * 0.55);\n}\n\n// Star flares: x in half-widths, y in half-heights, size.\nconst HZ_STARS = array<vec3f, 5>(\n  vec3f(-0.29, -0.71, 1.2),\n  vec3f(0.31, -0.88, 1.0),\n  vec3f(0.79, -0.8, 0.7),\n  vec3f(-0.53, -0.55, 0.5),\n  vec3f(0.15, -0.94, 0.45)\n);\n\nfn kindColor(p: vec2f, uv: vec2f) -> vec3f {\n  var h = frameHalf();\n  var portrait = clamp((h.y / h.x - 0.65) / 1.2, 0.0, 1.0);\n  var tilt = (fract(u.seed.x * 0.0193) - 0.5) * 0.1;\n  var x = p.x - tilt;\n\n  var breathe = 0.01 * hzLoop(0.7).x;\n  var rimY = hzRim(x, portrait, breathe);\n  var slope = (hzRim(x + 0.01, portrait, breathe) - rimY) * 100.0;\n  var out_ = (rimY - p.y) / sqrt(1.0 + slope * slope); // > 0 in the light\n  var sideGlow = 0.55 + 0.7 * smoothstep(0.15, 0.85, abs(p.x) / h.x);\n\n  var vq = (uv - 0.5) * vec2f(1.0, 1.1);\n  var vig = 1.0 - 0.6 * dot(vq, vq);\n  // Most of the frame is void: skip the light entirely there.\n  if (out_ < -0.012) {\n    var lab = hzVoid(-out_, sideGlow);\n    lab.x *= vig;\n    return lab + u.bg;\n  }\n\n  // The well: a dark funnel at the bottom centre.\n  var vp = vec2f(-0.03 + tilt * 0.5, -0.91 * h.y);\n  var hq = (p - vp) / vec2f(0.19, 0.068);\n  var hd = length(hq);\n  var landscape = 1.0 - portrait;\n\n  // Deeper bands flatten toward the horizontal, like a ground plane.\n  var rimMin = -0.32 - 0.11 * portrait;\n  var yRef = mix(rimY, rimMin + (rimY - rimMin) * 0.3, smoothstep(0.0, 0.3, out_));\n  var depth = max(yRef - p.y, 0.0);\n  // Perspective: bands crowd toward the horizon and widen toward the viewer.\n  var across = log(1.0 + depth * 7.0) * 0.32;\n  var along = p.x;\n  across += 0.035 * u.warp * sin(along * 3.1 + across * 9.0 + hzLoop(4.0).x * 2.0);\n\n  // Near the well the bands dip and dive into it, like light bent by a\n  // black hole.\n  var wrap = (1.0 - smoothstep(0.9, 2.6, hd)) * landscape;\n  across = max(across - 0.09 * wrap * smoothstep(0.0, 0.15, across), 0.0);\n  along = mix(along, along * (1.0 + 0.8 * wrap), wrap);\n\n  var sc = u.scale;\n  var f0 = vec2f(1.0, 6.0) * sc;\n  var f1 = vec2f(1.7, 14.0) * sc;\n  var s0 = hzNoise(hzSheet(vec2f(along, across), f0, 0.0));\n  var n1 = hzNoiseD(hzSheet(vec2f(along + s0 * 0.45, across + s0 * 0.012), f1, 1.0));\n  var s1 = n1.x;\n  // Turbulence: slanted wisps that cross the bands and fray them, strongest\n  // where the streaks climb on the right.\n  var rise = smoothstep(0.1, 0.75, p.x / h.x);\n  var q2 = vec2f(along, across + along * (0.08 + 0.3 * rise));\n  var s2 = hzNoise(hzSheet(q2, vec2f(2.0, 15.0) * sc, 2.0));\n\n  var env = smoothstep(-0.012, 0.05, out_) * (0.75 + 0.25 * exp(-out_ * 3.0));\n  // The well fades from the surrounding light into black over a wide falloff.\n  var hole = mix(pow(1.0 - exp(-hd * hd * 0.38), 1.6), 1.0, portrait);\n  var nearWell = (1.0 - smoothstep(1.0, 2.6, hd)) * landscape;\n  // The band is quieter and darker just under the hero copy.\n  var quiet = exp(-p.x * p.x * 9.0) * (1.0 - smoothstep(0.04, 0.16, out_)) * landscape;\n  // The hottest light arches over the well and runs down its flanks.\n  var flank = smoothstep(-0.7, 0.1, hq.y / max(hd, 1e-3));\n  var ring = exp(-max(hd - 1.7, 0.0) * 1.3) * smoothstep(0.9, 2.0, hd) * flank * landscape;\n  var side = 0.8 + 0.45 * smoothstep(0.1, 0.8, abs(p.x) / h.x);\n  // The bottom corners fall away to teal-black.\n  var corner = (1.0 - smoothstep(-h.y, -0.55 * h.y, p.y)) * smoothstep(0.35, 0.9, abs(p.x) / h.x) * landscape;\n  side *= 1.0 - 0.55 * corner;\n\n  var glow = clamp(0.5 + 0.9 * s0, 0.0, 1.0);\n  var fray = (0.16 + 0.12 * rise) * (1.0 - 0.8 * portrait);\n  var v = mix(s1 + 0.4 * s0 + fray * s2 + 0.08 * rise, 0.2 + 0.3 * s0, portrait * 0.85);\n  // Long-exposure softness: a wide transfer, and the dark gaps between bands\n  // are lifted so few near-black stripes remain inside the band.\n  var streak = smoothstep(-0.4 - 0.3 * u.blur, 0.55 + 0.2 * u.blur, v);\n  streak = mix(0.18, 1.0, streak);\n  // Near the well the streaks smooth out so its outline stays a clean ellipse.\n  streak = mix(streak, 0.7, nearWell * 0.25);\n  // Where a streak brightens going down, its upper edge catches cool light\n  // and the lower edge stays warm.\n  var grad = n1.z * f1.y * 0.01;\n  var coolEdge = smoothstep(0.02, 0.18, grad) * streak;\n  var warmEdge = smoothstep(0.02, 0.18, -grad) * streak;\n\n  // Colour: teal-black gaps, rust and rose bodies, steel-blue upper edges and\n  // rim, pale blue-white on the brightest edges.\n  var gap = mix(hzCol(3), vec3f(hzCol(2).x * 0.45, hzCol(2).yz * 0.7), 0.55 + 0.35 * s0);\n  var warmPick = smoothstep(-0.05, 0.5, s1 - 0.5 * s0);\n  var body = mix(hzCol(0), hzCol(1), warmPick);\n  body = mix(body, hzCol(0), warmEdge * 0.5);\n  // Glow, not paint: part of the body falls to desaturated mauve and grey-blue.\n  var mauve = mix(body, hzCol(2), 0.25 + 0.25 * (1.0 - smoothstep(-0.3, 0.3, s0)));\n  body = mix(body, vec3f(mauve.x, mauve.yz * 0.7), (0.1 + 0.12 * rise) * landscape);\n  var col = mix(gap, body, smoothstep(0.2, 0.75, streak));\n  // Portrait frames grade softly from steel at the edge through rose to rust.\n  var tall = mix(hzCol(2), mix(hzCol(1), hzCol(0), 0.6 * smoothstep(0.15, 0.55, out_)), smoothstep(0.03, 0.22, out_));\n  col = mix(col, tall, portrait * 0.7);\n  var rimness = exp(-max(out_, 0.0) * mix(24.0, 5.0, portrait));\n  col = mix(col, hzCol(2), clamp(coolEdge * 0.6 + rimness * 0.9 + ring * 0.5, 0.0, 1.0));\n  col = mix(col, gap, 0.65 * corner);\n  col = mix(col, hzCol(4), clamp(coolEdge * coolEdge * 0.7 + ring * streak * 0.6 + rimness * glow * 0.25, 0.0, 1.0));\n\n  // A broad bloom where the coarse sheet peaks.\n  var bloom = smoothstep(0.2, 0.75, s0) * exp(-out_ * 2.5);\n  var energy = env * hole * side * (1.0 - 0.45 * quiet) * (0.12 + 0.1 * rise + glow * glow * 0.3 + streak * 0.8 + coolEdge * 0.45 + bloom * 0.35)\n    + env * ring * (0.45 + 1.35 * streak)\n    + exp(-abs(out_ - 0.018) * 30.0) * (0.25 + 0.6 * glow) * env;\n  energy = mix(energy, env * (0.75 + 0.35 * glow) * (1.0 - 0.5 * smoothstep(0.25, 0.8, out_)), portrait * 0.6);\n\n  // Filmic tone: soft shoulder on lightness, chroma follows the light and\n  // rolls off in the highlights.\n  var lum = 1.0 - exp(-energy * 1.7);\n  var L = col.x * lum * 1.22;\n  // Darks desaturate toward black, like a film toe.\n  var chroma = smoothstep(0.0, 0.45, lum) * mix(0.5, 1.0, smoothstep(0.25, 0.7, lum));\n  var lab = vec3f(L, col.yz * chroma * mix(0.87, 1.0, portrait) * (1.0 - 0.45 * smoothstep(0.7, 1.0, L)));\n\n  // Chromatic fringing: a thin cyan line on upper edges, red on lower edges.\n  var mid = 4.0 * streak * (1.0 - streak);\n  var fringe = mid * mid * mid * clamp(grad * 6.0, -1.0, 1.0) * lum * landscape;\n  lab = vec3f(lab.x, lab.yz - fringe * select(vec2f(0.03, 0.018), vec2f(0.045, 0.034), fringe > 0.0));\n\n  // The very peaks run to near-white, over tiny areas.\n  var hot = smoothstep(1.2, 2.3, energy);\n  lab = mix(lab, vec3f(0.965, -0.004, -0.014), hot * 0.85);\n\n  // The haze runs continuously across the edge and fades into the band.\n  lab += hzVoid(max(-out_, 0.0), sideGlow) * exp(-max(out_, 0.0) * 30.0);\n\n  // Star flares: a soft glow and core, long hair-fine horizontal flare and a\n  // shorter vertical one. Pixels outside a star's reach skip it.\n  for (var i = 0; i < 5; i++) {\n    var st = HZ_STARS[i];\n    var sd = p - vec2f(st.x * h.x + tilt, st.y * h.y);\n    var size = st.z;\n    if (abs(sd.x) > 0.42 * size || abs(sd.y) > 0.22 * size) { continue; }\n    var tw = clamp(0.7 + 0.5 * hzLoop(f32(i) * 1.9 + 0.4).x, 0.15, 1.2);\n    var r2 = dot(sd, sd);\n    var core = exp(-r2 * 45000.0);\n    var halo = exp(-r2 * 1800.0 / (size * size)) * 0.1 * smoothstep(0.6, 1.2, size);\n    var fx = exp(-abs(sd.y) * 2200.0) * exp(-abs(sd.x) * 6.0 / size)\n      * (1.0 - smoothstep(0.25, 0.42, abs(sd.x) / size));\n    var fy = exp(-abs(sd.x) * 2200.0) * exp(-abs(sd.y) * 12.0 / size)\n      * (1.0 - smoothstep(0.12, 0.22, abs(sd.y) / size));\n    var star = (core * 1.4 + halo + (fx + fy) * 0.55) * size * tw * smoothstep(0.0, 0.08, out_);\n    lab.x += star * 0.7;\n    var tint = hzCol(1);\n    if (i == 1 || i == 2) { tint = hzCol(4); }\n    lab = vec3f(lab.x, mix(lab.yz, tint.yz * 0.6, clamp(star, 0.0, 1.0)));\n  }\n\n  lab.x *= vig;\n  return lab + u.bg;\n}\n`;\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/wgsl/horizon.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/wgsl/limb.ts",
      "content": "/**\n * WGSL twin of the limb kind's GLSL (limb.ts): same maths, line\n * for line, against shaders/wgsl-common.ts. Imported only when the WebGPU\n * backend draws this kind, so WebGL-only pages never download it.\n */\nexport const wgsl = /* wgsl */ `\n// A planet much larger than the frame, or a moon inside it, lit from one\n// side. The light is three layers: a thin crest at the edge, a saturated\n// band just inside it, and atmosphere glowing just outside. warp sets how\n// far the light wraps round; blur softens every layer.\nfn kindColor(p: vec2f, uv: vec2f) -> vec3f {\n  var h = frameHalf();\n  // The seed picks the body: a planet whose top arc crosses the frame, a\n  // horizon tilted across the frame, a moon lit from the side, a planet\n  // hanging from the top edge, a planet filling one side, a planet crossing\n  // the frame on a diagonal, or a small moon lit from behind, ringed in light.\n  var framing = floor(fract(u.seed.x * 0.0731 + 0.5) * 7.0);\n  var side = sign(u.seed.y + 0.01);\n  var tilt = sin(seedAngle());\n  var radius = 0.95;\n  var centre = vec2f(0.0, -1.02 + (1.0 - u.scale) * 0.3);\n  // Arcs are lit from a little off overhead, so one end of the arc fades.\n  var lightAngle = 0.5 * tilt;\n  var backlit = 0.0;\n  if (framing == 1.0) {\n    radius = 2.6;\n    centre = vec2f(0.9 * side, -2.62);\n    lightAngle = side * 0.35 + 0.2 * tilt;\n  } else if (framing == 2.0) {\n    radius = 0.3;\n    centre = vec2f(0.18 * h.x * side, 0.0);\n    lightAngle = side * 1.9 + 0.2 * tilt;\n  } else if (framing == 3.0) {\n    radius = 1.1;\n    centre = vec2f(0.2 * side, 1.38);\n    lightAngle = 3.14159265 + 0.4 * tilt;\n  } else if (framing == 4.0) {\n    radius = 1.3;\n    centre = vec2f(-side * (h.x + 0.98), -0.15);\n    lightAngle = side * (1.45 + 0.2 * tilt);\n  } else if (framing == 5.0) {\n    radius = 1.25;\n    centre = vec2f(-side * (h.x + 0.5), -h.y - 0.62);\n    lightAngle = side * 0.78;\n  } else if (framing == 6.0) {\n    radius = 0.2;\n    centre = vec2f(0.0, 0.02);\n    lightAngle = 0.4 * tilt;\n    backlit = 1.0;\n  }\n  radius *= u.scale;\n  lightAngle += 0.9 * u.loopv.y;\n  var light = vec2f(sin(lightAngle), cos(lightAngle));\n\n  var d = p - centre;\n  var r = length(d);\n  var dir = d / max(r, 1e-4);\n  var x = r - radius;\n\n  // How squarely each point of the rim faces the light. warp lets the\n  // light wrap further round the body.\n  var facing = dot(dir, light);\n  var lit = smoothstep(-0.15 - 0.6 * u.warp, 0.95, facing);\n  lit *= lit;\n  // A body lit from behind glows all the way round.\n  lit = mix(lit, 0.45 + 0.55 * lit, backlit);\n\n  // The atmosphere breathes and drifts along the arc.\n  var shimmer = 0.7 + 0.3 * flowNoise(dir * 2.4 + vec2f(x * 3.0, 0.0), 1.0);\n  // A small backlit moon shows its whole rim, so keep its outline round.\n  shimmer = mix(shimmer, 1.0, 0.7 * backlit);\n\n  var b = 0.6 + 0.8 * u.blur;\n  var inside = 1.0 - smoothstep(-0.006 * b, 0.004 * b, x);\n  // Outside the edge: a pale atmosphere band that holds, then fades.\n  // The atmosphere breathes with the loop phase: the same depth at any\n  // speed above 0.5, fading out toward a still frame at speed 0, and never\n  // thinner than 0.5x, so the falloff below never divides by zero.\n  var loopR = length(u.loopv);\n  var breath = 0.0;\n  if (loopR > 1e-4) { breath = (u.loopv.x / loopR) * min(loopR / 0.3, 1.0); }\n  var atmosW = 0.07 * b * (0.7 + 0.6 * u.warp) * (1.0 + 0.5 * breath);\n  var xa = max(x, 0.0) / atmosW;\n  var atmos = smoothstep(-0.02 * b, 0.0, x) / (1.0 + xa * xa * xa * xa);\n  // The edge itself, in the saturated colour, then the body falling away.\n  var edgeBand = exp(-pow(x / (0.03 * b), 2.0));\n  var band = inside * exp(x / (0.09 * b));\n  var deep = inside * exp(x / (0.35 * b));\n  var halo = exp(-max(x, 0.0) / (0.18 * b));\n\n  var glow = (0.6 * atmos * shimmer + 0.8 * edgeBand + 0.6 * band + 0.25 * deep + 0.12 * halo) * lit;\n\n  // The atmosphere in colour 0, the edge in 1, the body through 2 to the last.\n  var col = labMix(paletteColor(2), paletteColor(u.count - 1), clamp(1.0 - band, 0.0, 1.0));\n  col = labMix(col, paletteColor(1), clamp(edgeBand * 1.1 + 0.5 * band, 0.0, 1.0));\n  col = labMix(col, paletteColor(0), clamp(0.8 * atmos * (0.75 + 0.25 * shimmer) * smoothstep(-0.004, 0.025 * b, x), 0.0, 1.0));\n\n  var lab = labMix(u.bg, col, clamp(glow, 0.0, 1.0));\n  return filmGrade(lab);\n}\n`;\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/wgsl/limb.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/wgsl/linear-flow.ts",
      "content": "/**\n * WGSL twin of the linear-flow kind's GLSL (linear-flow.ts): same maths, line\n * for line, against shaders/wgsl-common.ts. Imported only when the WebGPU\n * backend draws this kind, so WebGL-only pages never download it.\n */\nexport const wgsl = /* wgsl */ `\nfn kindColor(p: vec2f, uv: vec2f) -> vec3f {\n  var h = frameHalf();\n  var angle = 0.6 + 1.2 * (fract(u.seed.y * 0.137) - 0.5) + 0.3 * u.loopv.y;\n  var dir = vec2f(cos(angle), sin(angle));\n  var perp = vec2f(-dir.y, dir.x);\n  var extent = abs(dir.x) * h.x + abs(dir.y) * h.y;\n  var a = dot(p, dir) / extent;\n  var b = dot(p, perp) / extent;\n  // Iso-lines bow, as if the light wraps round a curved surface.\n  var s = a + 0.16 * b * b - 0.05;\n  s += u.warp * 0.18 * flowNoise(p * 0.6 * u.scale, 1.0);\n  var t = clamp(0.5 + 0.5 * s * u.scale, 0.0, 1.0);\n  var lab = ramp(t * t * (3.0 - 2.0 * t));\n\n  // Light leak: a soft streak along the iso-lines toward the bright end.\n  var w = 0.1 + 0.18 * u.blur;\n  var sd = (s - 0.5 + 0.08 * flowNoise(vec2f(b * 1.1, 3.0), 2.0)) / w;\n  var streak = exp(-sd * sd) * (0.65 + 0.35 * flowNoise(vec2f(b * 2.2, 7.0), 3.0));\n  lab.x += 0.12 * streak;\n  lab = vec3f(lab.x, lab.yz * (1.0 - 0.3 * streak));\n\n  // The dark end falls into shadow and the corners sink toward the base colour.\n  var dark = 1.0 - smoothstep(0.55, 0.85, u.bg.x);\n  lab.x *= mix(1.0, mix(0.72, 1.0, smoothstep(-1.2, 0.1, s)), dark);\n  var corner = smoothstep(0.45, 1.15, length(p / h) * 0.75);\n  lab = labMix(lab, u.bg, corner * 0.3);\n  lab.x *= vignette(p, 0.2 * dark);\n  return filmGrade(lab);\n}\n`;\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/wgsl/linear-flow.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/wgsl/mesh.ts",
      "content": "/**\n * WGSL twin of the mesh kind's GLSL (mesh.ts): same maths, line\n * for line, against shaders/wgsl-common.ts. Imported only when the WebGPU\n * backend draws this kind, so WebGL-only pages never download it.\n */\nexport const wgsl = /* wgsl */ `\nfn kindColor(p: vec2f, uv: vec2f) -> vec3f {\n  let h = frameHalf();\n  let theta = seedAngle();\n  let axis = vec2f(cos(theta), sin(theta));\n  let side = vec2f(-axis.y, axis.x);\n  let span = abs(axis.x) * h.x + abs(axis.y) * h.y;\n  let q = p + u.warp * 0.14 * vec2f(\n    flowNoise(p * 1.2 * u.scale, 1.0),\n    flowNoise(p * 1.2 * u.scale + 4.1, 2.0)\n  );\n  let sigma = (0.22 + 0.2 * u.blur) / u.scale;\n  let inv = 1.0 / (sigma * sigma);\n  let count = f32(u.count);\n  let wb = 0.06;\n  var lab = u.bg * wb;\n  var chroma = length(u.bg.yz) * wb;\n  var total = wb;\n  for (var i = 0; i < 6; i++) {\n    if (i >= u.count) { break; }\n    let fi = f32(i);\n    let k = fi / max(1.0, count - 1.0);\n    let zig = (gmod1(fi, 2.0) * 2.0 - 1.0) * (0.25 + 0.5 * fract(fi * 0.618 + 0.3));\n    let c = axis * span * (0.9 - 1.8 * k) + side * span * 0.5 * zig\n      + 0.25 * h * (rot2(fi * 1.7) * u.loopv);\n    var d = q - c;\n    d = vec2f(dot(d, axis) * 1.2, dot(d, side) * 0.65);\n    let w = exp(-dot(d, d) * inv);\n    lab += u.colors[i].xyz * w;\n    chroma += length(u.colors[i].yz) * w;\n    total += w;\n  }\n  lab /= total;\n  chroma /= total;\n  let current = length(lab.yz);\n  if (current > 1e-4) {\n    lab = vec3f(lab.x, lab.yz * mix(1.0, chroma / current, 0.85));\n  }\n  lab.x += 0.05 * dot(p, axis) / span;\n  let along = dot(q, side);\n  let crest = 0.16 * sin(along * 1.6 + 0.8 * dot(u.loopv, vec2f(0.6, 0.8)) + theta)\n    + 0.08 * flowNoise(vec2f(along * 0.6, 2.0), 3.0);\n  let acrossFold = dot(q, axis) - crest;\n  let fw = 0.05 + 0.08 * u.blur;\n  lab.x += 0.06 * exp(-acrossFold * acrossFold / (fw * fw)) - 0.07 * smoothstep(0.0, 0.5, -acrossFold);\n  lab.x *= vignette(p, 0.18);\n  return filmGrade(lab);\n}\n`;\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/wgsl/mesh.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/wgsl/mist.ts",
      "content": "/**\n * WGSL twin of the mist kind's GLSL (mist.ts): same maths, line\n * for line, against shaders/wgsl-common.ts. Imported only when the WebGPU\n * backend draws this kind, so WebGL-only pages never download it.\n */\nexport const wgsl = /* wgsl */ `\nfn mistFold(q: vec2f, layer: f32, amp: f32) -> f32 {\n  let bend = amp * sin(q.x * 1.6 * u.scale + 0.9 * layer + 0.35 * u.loopv.y)\n    + (0.08 + 0.22 * u.warp) * flowNoise(vec2f(q.x * 0.55 * u.scale, layer * 2.3), layer);\n  return q.y - bend - 0.12 * q.x;\n}\n\nfn kindColor(p: vec2f, uv: vec2f) -> vec3f {\n  let h = frameHalf();\n  let lightBg = smoothstep(0.55, 0.85, u.bg.x);\n  let a = seedAngle();\n  let tilt = 0.55 * sin(a) + select(0.0, 3.14159265, cos(a) < 0.0);\n  let q = rot2(tilt) * p;\n  let x = q.x / max(h.x, 1e-3);\n\n  let lift = 0.05 * flowNoise(vec2f(0.21, 0.67), 7.0);\n  let s = mistFold(q + vec2f(0.0, lift), 1.0, 0.16);\n  let sheen = flowNoise(vec2f(q.x * 0.9 * u.scale, s * 4.0 / (0.5 + u.blur)), 2.0);\n\n  let span = 0.45 + 0.35 * u.blur;\n  let lit = clamp(-s / span, 0.0, 1.0);\n  var col = ramp(0.12 + 0.88 * pow(lit, 0.8));\n  col = labMix(col, paletteColor(1), smoothstep(0.0, 0.2, s) * 0.8);\n  let soft = 0.02 + 0.09 * u.blur;\n  let side = 1.0 - smoothstep(-soft, soft, s);\n  let spill = exp(-max(s, 0.0) / (0.05 + 0.18 * u.blur));\n  let depth = exp(-max(-s - 0.1, 0.0) / (0.35 + 0.45 * u.blur));\n  var amount = max(side * mix(0.3, 1.0, depth), spill * 0.7);\n  amount *= 0.86 + 0.18 * sheen;\n  amount *= 1.0 - 0.25 * smoothstep(0.6, 1.2, abs(x));\n\n  var lab = labMix(u.bg, col, clamp(amount, 0.0, 1.0));\n  let lipW = 0.02 + 0.06 * u.blur;\n  let sl = s + 0.6 * lipW;\n  let lip = exp(-sl * sl / (lipW * lipW)) * (0.75 + 0.25 * sheen);\n  let hot = vec3f(min(1.0, paletteColor(0).x + 0.05), paletteColor(0).yz * 0.85);\n  let ink = vec3f(paletteColor(u.count - 1).x * 0.6, paletteColor(u.count - 1).yz);\n  lab = labMix(lab, mix(hot, ink, lightBg), clamp(lip * (0.22 + 0.05 * lightBg), 0.0, 1.0));\n\n  let s2 = mistFold(q * vec2f(0.8, 1.0) + vec2f(0.7, -0.32 + lift), 4.0, 0.22);\n  var back = (1.0 - smoothstep(-0.25, 0.08 + 0.1 * u.blur, s2)) * exp(-max(-s2, 0.0) / 0.5);\n  back *= 1.0 - side;\n  lab = labMix(lab, ramp(0.55), clamp(back * 0.35 * (0.8 + 0.2 * sheen), 0.0, 1.0));\n\n  lab.x *= vignette(p, 0.25 * (1.0 - lightBg));\n  return filmGrade(lab);\n}\n`;\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/wgsl/mist.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/wgsl/pixel-glass.ts",
      "content": "/**\n * WGSL twin of the pixel-glass kind's GLSL (pixel-glass.ts): same maths, line\n * for line, against shaders/wgsl-common.ts. Imported only when the WebGPU\n * backend draws this kind, so WebGL-only pages never download it.\n */\nexport const wgsl = /* wgsl */ `\nfn pgScene(q: vec2f, h: vec2f) -> vec3f {\n  var lab = u.bg;\n  let lightBg = smoothstep(0.55, 0.85, u.bg.x);\n  let a0 = seedAngle();\n  let size = (0.17 + 0.1 * u.blur);\n  let lean = vec2f(cos(a0 + 1.3), sin(a0 + 1.3)) * vec2f(0.32, 0.3) * h;\n  for (var i = 0; i < 6; i++) {\n    if (i >= u.count) { break; }\n    let fi = f32(i);\n    let a = a0 + fi * 2.1;\n    let base = vec2f(cos(a) * 0.42 * h.x, sin(a) * 0.3 * h.y) * min(fi, 1.0) * (0.8 + 0.25 * fi);\n    let c = lean + base + vec2f(0.55, 0.38) * drift(fi + 1.0);\n    let r = size * (1.0 - 0.5 * min(fi, 1.0) / (1.0 + 0.4 * fi)) * mix(1.0, 1.15, lightBg);\n    var d = rot2(a * 0.5 + 0.4 * fi) * (q - c);\n    d *= vec2f(0.62, 1.0);\n    let k = dot(d, d) / (r * r);\n    let w = exp(-k * (1.3 - 0.6 * u.blur));\n    var col = paletteColor(i);\n    let rim = labMix(col, paletteColor(i + 1), 0.55);\n    col = labMix(col, rim, smoothstep(0.15, 0.9, k) * 0.7);\n    lab = labMix(lab, col, clamp(w * 1.15, 0.0, 1.0));\n  }\n  return lab;\n}\n\nfn pgGlass() -> f32 {\n  var most = 0.0;\n  for (var i = 0; i < 6; i++) {\n    if (i >= u.count) { break; }\n    most = max(most, length(u.colors[i].xyz - u.bg));\n  }\n  return clamp(most * 7.0, 0.0, 1.0);\n}\n\nfn pgLight(q: vec2f, h: vec2f) -> f32 {\n  return pgScene(q, h).x;\n}\n\nfn kindColor(p: vec2f, uv: vec2f) -> vec3f {\n  let h = frameHalf();\n  let minSide = min(u.full.x, u.full.y);\n  let lightBg = smoothstep(0.55, 0.85, u.bg.x);\n  let block = max(8.0, floor(minSide * 0.072 / u.scale + 0.5));\n  let px = uv * u.full;\n  let g = px - 0.5 * u.full;\n  let id = floor(g / block);\n  let inPx = g - id * block;\n  var lp = inPx / block - 0.5;\n  lp.y = -lp.y;\n  var c = (id + 0.5) * block / minSide;\n  c.y = -c.y;\n  let ci = interact(c);\n  let cell = block / minSide;\n\n  let tone = pgScene(ci, h);\n  let lens = mix(0.6, -0.9, u.warp);\n  let seenThrough = pgScene(ci + 1.6 * cell * lens * lp, h);\n  var lab = labMix(tone, seenThrough, 0.55);\n\n  let e = 0.75 * cell;\n  let grad = vec2f(\n    pgLight(ci + vec2f(e, 0.0), h) - pgLight(ci - vec2f(e, 0.0), h),\n    pgLight(ci + vec2f(0.0, e), h) - pgLight(ci - vec2f(0.0, e), h)\n  );\n  let slope = length(grad);\n  let toLight = normalize(mix(vec2f(-0.7071, 0.7071), grad / max(slope, 1e-4), smoothstep(0.002, 0.03, slope)));\n\n  let glow = clamp((tone.x - u.bg.x) * mix(3.0, -3.0, lightBg), 0.0, 1.0);\n  let glass = pgGlass();\n  let lit = max(glow, mix(0.18, 0.35, lightBg) * glass);\n\n  let r = max(abs(lp.x), abs(lp.y));\n  let facing = dot(lp, toLight) / 0.5;\n  lab.x += lit * (0.05 * facing - 0.07 * smoothstep(0.22, 0.5, r)) * mix(1.0, 0.5, lightBg);\n  let spot = lp - 0.18 * toLight;\n  lab.x += glow * 0.05 * exp(-dot(spot, spot) * 9.0) * mix(1.0, 0.4, lightBg);\n\n  let fromEdge = min(inPx, block - inPx);\n  let edgePx = min(fromEdge.x, fromEdge.y);\n  let lipWidth = max(1.5, block * 0.07);\n  let lip = 1.0 - smoothstep(0.0, lipWidth, edgePx);\n  let side = select(vec2f(0.0, sign(lp.y)), vec2f(sign(lp.x), 0.0), abs(lp.x) > abs(lp.y));\n  let toward = dot(side, toLight);\n  lab.x += lip * lit * select(0.06 * toward, 0.11 * toward, toward > 0.0) * mix(1.0, 0.45, lightBg);\n\n  let ringPx = abs(r - 0.32) * block;\n  let ring = 1.0 - smoothstep(0.0, max(1.0, block * 0.022), ringPx);\n  let inner = dot(side, toLight);\n  lab.x += ring * lit * (0.03 - 0.07 * inner) * mix(1.0, 0.5, lightBg);\n\n  let grout = max(1.0, block * 0.03);\n  let seam = 1.0 - smoothstep(grout - 0.5, grout + 0.5, edgePx);\n  lab = labMix(lab, u.bg * vec3f(mix(0.55, 0.9, lightBg), 1.0, 1.0), seam * glass * mix(0.85, 0.5, lightBg));\n\n  let q = interact(vec2f(g.x, -g.y) / minSide);\n  let halo = pgScene(q, h);\n  let bloom = clamp((halo.x - u.bg.x) * mix(1.0, -1.0, lightBg), 0.0, 1.0);\n  lab = labMix(lab, halo, 0.32 * bloom * bloom * (1.0 - lightBg));\n  return filmGrade(lab);\n}\n`;\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/wgsl/pixel-glass.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/wgsl/radial-glow.ts",
      "content": "/**\n * WGSL twin of the radial-glow kind's GLSL (radial-glow.ts): same maths, line\n * for line, against shaders/wgsl-common.ts. Imported only when the WebGPU\n * backend draws this kind, so WebGL-only pages never download it.\n */\nexport const wgsl = /* wgsl */ `\nfn kindColor(p: vec2f, uv: vec2f) -> vec3f {\n  let lightBg = smoothstep(0.55, 0.85, u.bg.x);\n  let h = frameHalf();\n  let framing = fract(u.seed.x * 0.0731 + 0.5);\n  var radius = 0.34;\n  var centre = vec2f(0.0, -0.3);\n  var spread = 0.28;\n  if (framing > 0.7) {\n    radius = 0.75;\n    centre = vec2f(0.35 * h.x * sign(u.seed.y), -0.95);\n    spread = 0.1;\n  } else if (framing > 0.4) {\n    radius = 0.26;\n    centre = vec2f(0.0, -0.04);\n    spread = 0.6;\n  }\n  radius /= u.scale;\n  centre.y -= 0.04 * flowNoise(vec2f(0.3, 0.7), 1.0);\n  let d = p - centre;\n  let r = length(d);\n  let dir = d / max(r, 1e-4);\n  let x = r - radius;\n  let xo = max(x, 0.0);\n  let soft = (0.01 + 0.045 * u.blur) * (1.0 + 5.0 * lightBg);\n\n  let sweep = 1.3 * u.loopv.x;\n  let up = vec2f(sin(sweep), cos(sweep));\n  let facing = 0.5 + 0.5 * dot(dir, up) * smoothstep(0.0, radius, r);\n  let key = mix(spread, 1.0, facing * facing);\n\n  var rays = 0.5 + 0.5 * flowNoise(dir * 2.6 - vec2f(0.0, r * 0.35), 2.0);\n  rays = mix(rays, 0.5 + 0.5 * flowNoise(dir * 6.0 - vec2f(r * 0.5, 0.0), 3.0), 0.35);\n  rays = mix(1.0, 0.25 + 1.3 * rays * rays, u.warp);\n\n  let rim = exp(-xo / soft);\n  let corona = exp(-xo / (0.05 + 0.1 * u.blur));\n  let haze = exp(-xo / (0.3 + 0.3 * u.blur));\n  let ringD = (x - 0.05 - 0.04 * u.blur) / ((0.018 + 0.03 * u.blur) * (1.0 + 2.0 * lightBg));\n  let ring = exp(-ringD * ringD);\n  var glow = (rim + 0.5 * corona * (0.6 + 0.4 * rays) + (0.4 + 0.35 * lightBg) * haze * mix(1.0, rays, 0.8) + 0.35 * ring) * key;\n\n  let inside = 1.0 - smoothstep(-soft * 0.5, soft * 0.5, x);\n  let innerRim = exp(min(x, 0.0) / (0.01 + 0.12 * lightBg));\n  glow = mix(glow, (0.3 * innerRim + 0.06) * key, inside * (1.0 - 0.85 * lightBg));\n\n  let reach = clamp(xo / (0.6 + 0.3 * u.blur), 0.0, 1.0);\n  let t = mix(sqrt(reach), smoothstep(0.0, 0.7, reach), lightBg);\n  var col = ramp(t);\n  let hot = vec3f(min(1.0, paletteColor(0).x + 0.06), paletteColor(0).yz * 0.4);\n  col = labMix(col, hot, rim * (1.0 - inside) * (0.45 + 0.5 * lightBg));\n  col = labMix(col, paletteColor(2), ring * (0.6 - 0.35 * lightBg) * (1.0 - rim));\n\n  var base = u.bg;\n  base.x *= mix(1.0, mix(0.35, 1.0, lightBg), inside);\n  var lab = labMix(base, col, clamp(glow, 0.0, 1.0));\n  lab.x += 0.1 * max(glow - 0.9, 0.0);\n  lab.x *= vignette(p, 0.3 * (1.0 - lightBg));\n  return filmGrade(lab);\n}\n`;\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/wgsl/radial-glow.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/wgsl/ribbon.ts",
      "content": "/**\n * WGSL twin of the ribbon kind's GLSL (ribbon.ts): same maths, line\n * for line, against shaders/wgsl-common.ts. Imported only when the WebGPU\n * backend draws this kind, so WebGL-only pages never download it.\n */\nexport const wgsl = /* wgsl */ `\n// cos(a - angle), where cs = (cos, sin)(angle); turnSin is its sine twin.\nfn ribbonCos(a: f32, cs: vec2f) -> f32 {\n  return cos(a) * cs.x + sin(a) * cs.y;\n}\n\n// GLSL's local \"u\" is \"w\" here: u is the uniform block in WGSL.\nfn ribbonLayer(lab0: vec3f, p: vec2f, angle: f32, offset: f32, layer: f32, far: f32, ph: f32, t1: vec2f, t2: vec2f, lightBg: f32) -> vec3f {\n  var lab = lab0;\n  let q = rot2(angle) * p * u.scale;\n  let s = q.x;\n  let amp = 0.1 + 0.12 * u.warp;\n  let a1 = 1.5 * s + layer + 2.0 * ph;\n  let a2 = 2.9 * s + 2.0 * layer - ph;\n  let wobble = 0.03 * flowNoise(vec2f(s * 0.6, layer), layer);\n  let centre = offset + amp * turnSin(a1, t1) + 0.04 * turnSin(a2, t2) + wobble;\n  let dc = amp * 1.5 * ribbonCos(a1, t1) + 0.116 * ribbonCos(a2, t2);\n  let dist = (q.y - centre) / sqrt(1.0 + dc * dc);\n\n  let twist = (0.6 + 1.1 * u.warp) * s + 1.7 * layer + 0.6 + 1.3 * ph;\n  let turn = ribbonCos(twist, t1);\n  let facing = abs(turn);\n  let width = (0.23 - 0.08 * far) * (0.12 + 0.88 * facing) + 0.002;\n  let w = dist / width;\n  let side = turn / (facing + 0.12);\n\n  let focus = smoothstep(-0.4, 0.8, sin(0.9 * s + 1.3 * layer + 0.5 - ph));\n  let px = u.scale / min(u.full.x, u.full.y);\n  let soft = 1.5 * px + (0.004 + 0.05 * u.blur) * (1.0 - focus) + 0.04 * far * (0.4 + u.blur);\n  let alpha = 1.0 - smoothstep(width - soft, width + soft, abs(dist));\n\n  let slide = 0.22 * sin(0.8 * s + 2.3 * layer + ph);\n  let across = clamp(0.5 + 0.5 * w * side + slide, 0.0, 1.0);\n  var col = ramp(across);\n  col = labMix(col, u.bg, 0.18 * (1.0 - smoothstep(-0.6, 0.0, side)) + 0.25 * far);\n  let curl = exp(-pow((w * side - 0.25) / 0.45, 2.0)) * facing;\n  col.x += (0.07 - 0.05 * lightBg) * curl;\n  let lit = abs(0.85 * turn - 0.5 * turnSin(twist, t1));\n  col.x *= mix(mix(0.62, 0.84, lightBg), 1.04, lit);\n  col.x += 0.024 * (1.0 - u.blur) * focus * facing * sin(w * 120.0) * (1.0 - far);\n  let edge = smoothstep(0.7, 1.0, abs(w)) * facing;\n  col = labMix(col, labMix(ramp(1.0 - across), vec3f(1.0, 0.0, 0.0), 0.5 - 0.5 * lightBg), 0.35 * edge);\n\n  let opacity = mix(0.97, 0.88, lightBg) - 0.3 * far;\n  let halo = exp(-max(abs(dist) - width, 0.0) / (0.03 + 0.08 * u.blur)) * (1.0 - lightBg);\n  lab = labMix(lab, col, 0.22 * halo * opacity);\n  lab = labMix(lab, col, alpha * opacity);\n  let crease = exp(-pow(dist / (0.003 + soft), 2.0)) * pow(1.0 - facing, 6.0);\n  let hot = labMix(ramp(0.5), vec3f(1.0, 0.0, 0.0), 0.6 - 0.6 * lightBg);\n  lab = labMix(lab, hot, clamp(crease * opacity, 0.0, 1.0));\n  return lab;\n}\n\nfn kindColor(p: vec2f, uv: vec2f) -> vec3f {\n  let sa = seedAngle();\n  let t1 = loopTurn();\n  let t2 = vec2f(t1.x * t1.x - t1.y * t1.y, 2.0 * t1.x * t1.y);\n  let lightBg = smoothstep(0.55, 0.75, u.bg.x);\n  let a0 = 0.5 * sin(sa) + 0.25;\n  let a1 = a0 - (0.85 + 0.35 * cos(sa * 1.3));\n  var lab = u.bg;\n  lab = ribbonLayer(lab, p, a1, -0.08 * sin(sa * 1.7), 3.0, 1.0, sa * 1.7, t1, t2, lightBg);\n  lab = ribbonLayer(lab, p, a0, 0.06 * cos(sa * 2.1), 1.0, 0.0, sa * 1.7, t1, t2, lightBg);\n  return filmGrade(lab);\n}\n`;\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/wgsl/ribbon.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/wgsl/rise.ts",
      "content": "/**\n * WGSL twin of the rise kind's GLSL (rise.ts): same maths, line\n * for line, against shaders/wgsl-common.ts. Imported only when the WebGPU\n * backend draws this kind, so WebGL-only pages never download it.\n */\nexport const wgsl = /* wgsl */ `\nfn kindColor(p: vec2f, uv: vec2f) -> vec3f {\n  let h = frameHalf();\n  let lightBg = smoothstep(0.55, 0.85, u.bg.x);\n  let placement = fract(u.seed.x * 0.0619 + 0.13);\n  var angle = 0.0;\n  if (placement > 0.85) {\n    angle = 3.14159265;\n  } else if (placement > 0.7) {\n    angle = 0.62;\n  } else if (placement > 0.55) {\n    angle = -0.62;\n  }\n  let lips = floor(fract(u.seed.y * 0.0377 + 0.31) * 3.0);\n  let q = rot2(angle) * p;\n  let reach = abs(cos(angle)) * h.y + abs(sin(angle)) * h.x;\n\n  var radius = 0.62 / u.scale;\n  radius *= 1.0 + 0.14 * flowNoise(vec2f(0.37, 0.91), 1.0);\n  let centre = vec2f(0.5 * flowNoise(vec2f(1.7, 0.3), 2.0), -reach - 0.3 * radius + 0.1 * u.loopv.y);\n  let d2 = (q - centre) * vec2f(0.62, 1.0);\n  let r = length(d2);\n  let x = q.x / max(h.x, 1e-3);\n\n  let ripple = 0.06 * flowNoise(vec2f(q.x * 0.9, 0.5), 3.0)\n    + 0.015 * flowNoise(vec2f(q.x * 2.0, 4.5), 4.0);\n  let d = r - radius + u.warp * ripple;\n\n  let fall = (0.07 + 0.32 * u.blur) * (1.0 + 0.7 * x * x) * (0.7 + 0.3 * radius);\n  let outside = max(d, 0.0);\n  let glow = exp(-outside / fall);\n  let inner = (0.12 + 0.2 * u.blur) * max(1.0, radius);\n  let t = select(0.4 + 0.6 * (1.0 - exp(-outside / (1.8 * fall))), 0.4 * exp(d / inner), d < 0.0);\n  var col = ramp(t);\n\n  let lipW = 0.025 + 0.07 * u.blur;\n  let lip = exp(-d * d / (lipW * lipW));\n  var stack = 0.0;\n  for (var i = 1; i < 3; i++) {\n    if (f32(i) > lips) { break; }\n    var off = d + f32(i) * (0.06 + 0.05 * u.blur) * (0.8 + 0.4 * radius);\n    off += 0.02 * u.warp * flowNoise(vec2f(q.x * 1.4, f32(i) * 3.1), 5.0 + f32(i));\n    stack += exp(-off * off / (lipW * lipW * 0.8)) * (1.0 - 0.25 * f32(i));\n  }\n  let hot = vec3f(min(1.0, paletteColor(0).x + 0.05), paletteColor(0).yz * 0.6);\n  col = labMix(col, hot, clamp((lip * 0.28 + stack * 0.45) * (1.0 - 0.6 * lightBg), 0.0, 1.0));\n  col.x += 0.05 * stack * (1.0 - lightBg);\n\n  var lab = labMix(u.bg, col, glow);\n  let haze = exp(-outside / (0.7 + 0.7 * u.blur)) * (1.0 - glow);\n  lab = labMix(lab, ramp(0.8), 0.24 * haze * (1.0 - lightBg));\n  lab.x *= vignette(p, 0.25 * (1.0 - lightBg));\n  return filmGrade(lab);\n}\n`;\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/wgsl/rise.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/wgsl/silk.ts",
      "content": "/**\n * WGSL twin of the silk kind's GLSL (silk.ts): same maths, line\n * for line, against shaders/wgsl-common.ts. Imported only when the WebGPU\n * backend draws this kind, so WebGL-only pages never download it.\n */\nexport const wgsl = /* wgsl */ `\nfn silkPhase(q: vec2f, t1: vec2f, t2: vec2f, ph: f32) -> f32 {\n  let x = q.x;\n  let centre = 0.075 * turnSin(1.25 * x + 0.7 + ph, t1) + 0.05 * turnSin(2.7 * x - 1.9 + 2.0 * ph, t2);\n  let spread = 1.0 + 0.22 * turnSin(1.6 * x + 2.1 - ph, t1) + 0.3 * sin(0.9 * x + 4.0 + 3.0 * ph);\n  let twist = flowNoise(vec2f(x * 0.5, q.y * 0.8), 2.0);\n  return (q.y - centre) * spread + (0.02 + 0.07 * u.warp) * twist;\n}\n\nfn kindColor(p: vec2f, uv: vec2f) -> vec3f {\n  let sa = seedAngle();\n  let tilt = 0.4 * sin(sa);\n  var q = rot2(tilt) * p;\n  q.y -= 0.04 + 0.16 * cos(sa * 1.7);\n  q.y *= select(1.0, -1.0, fract(sa * 0.91) > 0.66);\n  let ph = sa * 2.3;\n  let t1 = loopTurn();\n  let t2 = vec2f(t1.x * t1.x - t1.y * t1.y, 2.0 * t1.x * t1.y);\n\n  let e = 0.0025;\n  let v = silkPhase(q, t1, t2, ph);\n  let grad = vec2f(silkPhase(q + vec2f(e, 0.0), t1, t2, ph) - v, silkPhase(q + vec2f(0.0, e), t1, t2, ph) - v) / e;\n\n  let x = q.x;\n  let bend = 0.45 * turnSin(1.1 * x + 0.4 + ph, t1) + 0.2 * sin(2.3 * x + 1.0 - ph);\n  let f1 = 5.5 * u.scale * (0.8 + 0.45 * fract(sa * 1.37));\n  let phi1 = v * f1 + bend;\n  let slope = 0.7 * cos(phi1) * grad * f1;\n  let n = normalize(vec3f(-slope, 1.0));\n\n  let light = normalize(vec3f(0.3 * cos(sa * 2.3), 0.85, 0.4));\n  var diffuse = 0.5 + 0.5 * dot(n, light);\n  diffuse *= diffuse;\n  let r = 2.0 * n.z * n.xy;\n  let w = mix(0.07, 0.3, u.blur);\n  let key = exp(-pow((r.y - 0.42) / w, 2.0));\n  let bounce = exp(-pow((r.y + 0.35) / (1.6 * w), 2.0));\n  let fill = exp(-pow((r.y - 0.12) / (2.4 * w), 2.0));\n  let spec = key * (0.75 + 0.25 * diffuse) + 0.38 * fill;\n\n  let lightBg = smoothstep(0.55, 0.75, u.bg.x);\n  let body = mix(\n    labMix(u.bg, paletteColor(0), smoothstep(0.12, 0.9, diffuse)),\n    labMix(paletteColor(0), u.bg, 0.15 + 0.85 * diffuse),\n    lightBg\n  );\n  let facing = smoothstep(-0.25, 0.25, n.x);\n  let tint = labMix(paletteColor(1), paletteColor(select(1, 2, u.count > 2)), facing);\n  let f2 = 40.0 * u.scale;\n  let v2 = v * f2 + 1.5 * sin(v * f1 * 1.7 + 1.0);\n  let thread = exp(-pow((fract(v2) - 0.5) / mix(0.08, 0.22, u.blur), 2.0));\n  let bundle = smoothstep(0.1, 0.9, sin(phi1 * 0.5 + 2.0)) * (0.4 + 0.6 * u.warp);\n  let shine = spec + 0.55 * thread * bundle * clamp(key + fill, 0.0, 1.0);\n  var lab = labMix(body, paletteColor(select(0, 2, u.count > 2)), 0.3 * bounce * (1.0 - lightBg));\n  lab = labMix(lab, tint, clamp(shine, 0.0, 1.0));\n  lab.x += (0.32 - 0.25 * lightBg) * spec * spec + 0.05 * thread * bundle * diffuse;\n\n  let top = 0.16;\n  let px = length(grad) / min(u.full.x, u.full.y);\n  let soft = max(px * 1.5, 1e-4) + 0.03 * u.blur;\n  let below = top - v;\n  let mask = smoothstep(-soft, soft, below);\n  let fade = exp(-max(below, 0.0) * mix(1.8, 1.2, u.blur));\n  let rim = exp(-pow(below / (soft + 0.006), 2.0));\n\n  lab = labMix(lab, labMix(paletteColor(0), tint, 0.35), 0.7 * exp(-max(below, 0.0) * mix(16.0, 8.0, u.blur)) * (1.0 - lightBg));\n  let back = labMix(u.bg, paletteColor(0), 0.14 * exp(-abs(below) * 5.0));\n  var outLab = labMix(back, lab, mask * fade);\n  let catchLight = 0.45 + 0.55 * smoothstep(-0.6, 0.8, flowNoise(vec2f(q.x * 0.9, 3.0), 5.0));\n  outLab = labMix(outLab, paletteColor(1), 0.9 * rim * catchLight);\n  outLab.x += 0.12 * rim * catchLight;\n  return filmGrade(outLab);\n}\n`;\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/wgsl/silk.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/wgsl/smear.ts",
      "content": "/**\n * WGSL twin of the smear kind's GLSL (smear.ts): same maths, line\n * for line, against shaders/wgsl-common.ts. Imported only when the WebGPU\n * backend draws this kind, so WebGL-only pages never download it.\n */\nexport const wgsl = /* wgsl */ `\nfn smearNoise(p: vec2f, layer: f32) -> f32 { return snoise2(p + u.seed + 0.35 * drift(layer) + vec2f(layer * 7.13, layer * 3.71)); }\nfn kindColor(p: vec2f, uv: vec2f) -> vec3f {\n  let lightBg = smoothstep(0.55, 0.85, u.bg.x);\n  let a = 0.5 * sin(seedAngle()) + select(0.0, 1.5708, fract(u.seed.y * 0.071) <= 0.5) * 0.35;\n  var q = rot2(a) * p * u.scale;\n  q.y = q.y + (0.05 + 0.2 * u.warp) * smearNoise(vec2f(q.x * 0.45, 0.3), 1.0);\n  let stretch = 0.3 + 0.35 * (1.0 - u.blur);\n  let ss = vec2f(q.x * stretch, q.y * 1.5) * 1.6;\n  let bloom = smearNoise(ss, 2.0) + 0.5 * smearNoise(ss * vec2f(1.7, 2.3) + 3.3, 3.0);\n  let hue = 0.5 + 0.5 * smearNoise(ss * 0.7 + 11.0, 4.0);\n  let edge = 0.04 + 0.32 * u.blur;\n  let m = smoothstep(0.12 - edge, 0.12 + edge, bloom);\n  let streak = smearNoise(vec2f(q.x * 0.5, q.y * 12.0 / (0.6 + u.blur)), 5.0);\n  var col = ramp(clamp(hue + 0.08 * streak, 0.0, 1.0)); col.x = col.x + 0.045 * streak;\n  var ground = u.bg;\n  let shade = 0.5 + 0.5 * smearNoise(ss * 0.6 - 7.0, 6.0);\n  ground = labMix(ground, paletteColor(u.count - 1), 0.12 * shade); ground.x = ground.x + 0.01 * streak;\n  var lab = labMix(ground, col, m * (0.82 + 0.18 * shade));\n  let core = smoothstep(0.75, 1.25, bloom + 0.2 * streak);\n  lab = labMix(lab, paletteColor(u.count - 1), 0.3 * core);\n  lab.x = lab.x * vignette(p, 0.18 * (1.0 - lightBg));\n  return filmGrade(lab);\n}\n`;\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/wgsl/smear.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/wgsl/spectrum.ts",
      "content": "/**\n * WGSL twin of the spectrum kind's GLSL (spectrum.ts): same maths, line\n * for line, against shaders/wgsl-common.ts. Imported only when the WebGPU\n * backend draws this kind, so WebGL-only pages never download it.\n */\nexport const wgsl = /* wgsl */ `\nfn spStrand(q: vec2f, h: vec2f, k: f32, side: f32) -> vec2f {\n  let s = 1.0 / u.scale;\n  let a = -0.35 + (side - 0.5) * 0.8 + 0.12 * k;\n  let r = rot2(a) * q;\n  let bend = (0.55 + 0.1 * k) / s;\n  let y0 = -0.08 * h.y + 0.11 * k + 0.12 * flowNoise(vec2f(0.2, k), 1.0 + k);\n  let x = r.x;\n  let wave = 0.09 * flowNoise(vec2f(x * 0.9, 0.4 + k), 2.0 + k);\n  let curve = y0 + bend * 0.5 * x * x + wave;\n  let slope = bend * x;\n  let d = (r.y - curve) / sqrt(1.0 + slope * slope);\n  return vec2f(d, x / max(h.x, 1e-3));\n}\n\nfn kindColor(p: vec2f, uv: vec2f) -> vec3f {\n  let h = frameHalf();\n  let lightBg = smoothstep(0.55, 0.85, u.bg.x);\n  let side = fract(u.seed.y * 0.0917 + 0.5);\n  let strands = 1.0 + floor(fract(u.seed.x * 0.0731 + 0.5) * 3.0);\n  var q = p;\n  if (fract(u.seed.x * 0.31 + u.seed.y * 0.17) > 0.5) { q.x = -q.x; }\n  let halo = 0.02 + 0.06 * u.blur;\n  var lab = u.bg;\n  let n = f32(u.count);\n  var hotSum = 0.0;\n  for (var k = 0; k < 3; k++) {\n    let fk = f32(k);\n    if (fk >= strands) { break; }\n    let st = spStrand(q, h, fk, side);\n    let along = st.y;\n    let fade = smoothstep(-1.15, -0.4, along) * (1.0 - 0.35 * fk);\n    let fan = (0.004 + 0.1 * u.warp * smoothstep(-0.9, 1.0, along)) * (1.0 + 0.4 * fk);\n    let core = 0.0018 + 0.004 * u.blur;\n    let bodyW = (0.05 + 0.08 * u.blur) * (1.0 + 0.5 * fk);\n    var body = select(0.0, exp(st.x / bodyW) * smoothstep(-0.006, 0.0, st.x), st.x < 0.0);\n    body *= fade * (0.35 + 0.15 * flowNoise(vec2f(along * 1.4, fk), 8.0 + fk));\n    lab = labMix(lab, ramp(0.35 + 0.15 * fk), clamp(body * mix(0.9, 0.5, lightBg), 0.0, 1.0));\n    for (var i = 0; i < 6; i++) {\n      if (i >= u.count) { break; }\n      let fi = f32(i);\n      let off = (fi / max(n - 1.0, 1.0) - 0.5) * fan;\n      let dd = st.x - off;\n      let band = exp(-dd * dd / ((fan / n + core) * (fan / n + core)));\n      let glow = exp(-abs(dd) / halo) * mix(0.35, 0.12, lightBg);\n      let wgt = (band + glow) * fade;\n      lab = labMix(lab, paletteColor(i), clamp(wgt * mix(0.9, 0.75, lightBg), 0.0, 1.0));\n    }\n    let hot = exp(-st.x * st.x / (core * core)) * fade;\n    hotSum += hot * (1.0 - 0.4 * fk);\n  }\n  let white = vec3f(min(1.0, paletteRange().x + 0.05), 0.0, 0.0);\n  lab = labMix(lab, white, clamp(hotSum * 0.8 * (1.0 - lightBg), 0.0, 1.0));\n  lab.x *= vignette(p, 0.25 * (1.0 - lightBg));\n  return filmGrade(lab);\n}\n`;\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/wgsl/spectrum.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/wgsl/swirl.ts",
      "content": "/**\n * WGSL twin of the swirl kind's GLSL (swirl.ts): same maths, line\n * for line, against shaders/wgsl-common.ts. Imported only when the WebGPU\n * backend draws this kind, so WebGL-only pages never download it.\n */\nexport const wgsl = /* wgsl */ `\nfn kindColor(p: vec2f, uv: vec2f) -> vec3f {\n  let h = frameHalf(); let lightBg = smoothstep(0.55, 0.85, u.bg.x); let a = seedAngle();\n  var eye = vec2f(0.32 * h.x * cos(a), 0.22 * h.y * sin(a * 1.7)); eye = eye + 0.05 * vec2f(flowNoise(vec2f(0.2,0.8),1.0), flowNoise(vec2f(0.9,0.1),2.0));\n  let d = p - eye; let r = length(d); let reach = 0.55 / u.scale; let twist = (2.2 + 2.8 * u.warp) * exp(-r / reach) + 0.9 * u.loopv.x;\n  let dir = select(-1.0, 1.0, fract(u.seed.y * 0.113) > 0.5); let q = rot2(dir * twist) * d;\n  let ss = q * 1.25 * u.scale; let fine = 1.0 - 0.8 * u.blur; var n = flowNoise(ss,3.0) + 0.4 * fine * flowNoise(ss * 2.3 + 5.1,4.0); n = n / (1.0 + 0.4 * fine);\n  let t0 = clamp(0.45 + 0.5 * n,0.0,1.0); let arm0 = 0.5 + 0.5 * sin(atan2(q.y, q.x + 1e-6) * 2.0 + r * 3.0 + 2.0 * n); let arm = mix(0.5, arm0, smoothstep(0.0,0.2,r)); let t = mix(t0, 0.15 + 0.7 * arm, 0.3);\n  var col = ramp(t); let lit = exp(-r / ((0.35 + 0.35 * u.blur) * max(0.6, 1.0 / u.scale))); let amount = lit * (0.7 + 0.3 * arm) + (1.0 - lit) * 0.55 * arm * smoothstep(-0.2,0.6,n);\n  col = labMix(col, ramp(1.0), (1.0 - clamp(amount,0.0,1.0)) * 0.55 * (1.0-lightBg)); var lab = labMix(u.bg,col,clamp(amount,0.0,1.0)); let hot = vec3f(min(1.0,paletteColor(0).x+0.05),paletteColor(0).yz*0.6); lab = labMix(lab,hot,0.5*exp(-r*r/(0.02+0.04*u.blur))*(1.0-lightBg)); lab.x = lab.x * vignette(p,0.3*(1.0-lightBg)); return filmGrade(lab);\n}\n`;\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/wgsl/swirl.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/wgsl/void.ts",
      "content": "/**\n * WGSL twin of the void kind's GLSL (void.ts): same maths, line\n * for line, against shaders/wgsl-common.ts. Imported only when the WebGPU\n * backend draws this kind, so WebGL-only pages never download it.\n */\nexport const wgsl = /* wgsl */ `\nfn kindColor(p: vec2f, uv: vec2f) -> vec3f {\n  let h = frameHalf();\n  let framing = floor(fract(u.seed.x * 0.0731 + 0.5) * 4.0);\n  let side = select(-1.0, 1.0, u.seed.y + 0.01 >= 0.0);\n  var centre = vec2f(0.06 * h.x * sin(u.seed.y), 0.03 * cos(u.seed.x));\n  var radius = 0.25;\n  if (framing == 1.0) { centre = vec2f(0.5 * h.x * side, 0.04); radius = 0.22; }\n  else if (framing == 2.0) { centre = vec2f(0.12 * h.x * side, -h.y - 0.08); radius = 0.36; }\n  else if (framing == 3.0) { centre = vec2f(-side * (h.x - 0.05), h.y - 0.05); radius = 0.3; }\n  let breathe = 1.0 + 0.035 * flowNoise(vec2f(0.37, 0.71), 1.0);\n  radius *= u.scale * breathe;\n  let d = p - centre;\n  let r = length(d);\n  let dir = d / max(r, 1e-4);\n  let fineAmount = 1.0 - 0.75 * u.blur;\n  let broad = flowNoise(dir * 2.2 + vec2f(0.0, r * 0.4), 1.5);\n  let s1 = flowNoise(dir * 16.0 + vec2f(r * 0.5, 0.0), 2.0);\n  let s2 = flowNoise(dir * 41.0 - vec2f(0.0, r * 0.9), 3.0);\n  let fine = (s1 + 0.7 * s2) / 1.7;\n  let streak = 1.0 + u.warp * (0.3 * broad + 0.32 * fineAmount * fine);\n  let swing = seedAngle() + 1.6 * u.loopv.y;\n  let sector = 0.5 + 0.5 * dot(dir, vec2f(sin(swing), -cos(swing)));\n  let soft = 0.5 + 0.6 * u.blur;\n  let rise = smoothstep(radius * (1.0 - 0.25 * soft), radius * (1.0 + 1.8 * soft), r);\n  let edge = clamp((r - radius) / max(length(h) + length(centre) - radius, 0.2), 0.0, 1.0);\n  let glow = rise * (0.28 + 0.42 * edge) * streak * (0.35 + 0.65 * sector * sector);\n  let t = clamp(1.0 - glow * 1.1 - 0.1 * sector, 0.0, 1.0);\n  let col = ramp(t);\n  let lab = labMix(u.bg, col, clamp(glow * 1.25, 0.0, 1.0));\n  return filmGrade(lab);\n}\n`;\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/wgsl/void.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/shaders/wgsl/waves.ts",
      "content": "/**\n * WGSL twin of the waves kind's GLSL (waves.ts): same maths, line\n * for line, against shaders/wgsl-common.ts. Imported only when the WebGPU\n * backend draws this kind, so WebGL-only pages never download it.\n */\nexport const wgsl = /* wgsl */ `\nfn kindColor(p: vec2f, uv: vec2f) -> vec3f {\n  let h = frameHalf();\n  let tilt = -0.42 + 0.3 * (fract(u.seed.x * 0.173) - 0.5);\n  let normal = vec2f(sin(tilt), cos(tilt));\n  let tangent = vec2f(normal.y, -normal.x);\n  let y = dot(p, normal) / (2.0 * h.y);\n  let along = dot(p, tangent);\n  let x = along * u.scale;\n  let count = f32(u.count);\n  let focus = 0.35 + 0.65 * min(1.0, abs(along) / h.x);\n  var lab = u.bg;\n  lab.x += 0.05 * smoothstep(-0.2, 0.6, y);\n  for (var i = 0; i < 6; i++) {\n    if (i >= u.count) { break; }\n    let fi = f32(i);\n    let base = 0.46 - 0.9 * (fi + 0.25) / count;\n    let phase = fi * 1.9 + dot(u.loopv, vec2f(cos(fi * 1.3), sin(fi * 1.3))) * 1.8;\n    let wave = 0.1 * sin(x * (1.3 + 0.3 * fi) + phase)\n      + 0.04 * sin(x * (2.7 - 0.2 * fi) - 1.3 * phase + 1.0)\n      + u.warp * 0.08 * flowNoise(vec2f(x * 0.65, fi * 3.7), 60.0 + fi);\n    let edge = base + wave * (0.6 + 0.4 * fi / count);\n    let dd = edge - y;\n    let soft = 0.002 + (0.01 + 0.06 * u.blur) * focus;\n    let m = smoothstep(-soft, soft, dd);\n    let shadow = exp(-max(-dd, 0.0) / (0.035 + 0.05 * u.blur)) * (1.0 - m);\n    lab.x -= 0.08 * shadow * (0.3 + lab.x);\n    var c = u.colors[i].xyz;\n    let body = max(dd, 0.0);\n    c.x += 0.1 * exp(-body / (0.012 + 0.03 * u.blur)) + 0.09 * (0.38 - smoothstep(0.0, 0.3, body))\n      + 0.06 * along / h.x;\n    lab = labMix(lab, c, m);\n  }\n  lab.x *= vignette(p, 0.22);\n  return filmGrade(lab);\n}\n`;\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/shaders/wgsl/waves.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/types.ts",
      "content": "export type GradientKind =\n  | \"mesh\"\n  | \"grain\"\n  | \"aurora\"\n  | \"waves\"\n  | \"radial-glow\"\n  | \"linear-flow\"\n  | \"horizon\"\n  | \"dither-field\"\n  | (string & {});\nexport interface GradientParams {\n  kind: GradientKind;\n  colors: string[];\n  background: string;\n  /** Legacy noise-space radius, retained so saved presets keep their shape. */\n  drift?: number;\n  speed: number;\n  loopSeconds: number;\n  scale: number;\n  warp: number;\n  grain: number;\n  dither: { enabled: boolean; cell: number; levels: number };\n  blur: number;\n  seed: number;\n  interaction: { pointer: number; scroll: number };\n}\nexport interface FrameInput {\n  timeSeconds: number;\n  frameIndex: number;\n  /** Sampling rate for deterministic grain wrapping; live frames use the display rate. */\n  frameRate?: number;\n  /** Runtime phase in radians. When supplied, speed changes cannot move the path. */\n  phase?: number;\n  pointer?: { x: number; y: number; strength: number };\n  scroll?: { velocity: number };\n}\nexport interface RenderTarget {\n  fullWidth: number;\n  fullHeight: number;\n  x: number;\n  y: number;\n  width: number;\n  height: number;\n}\nexport interface GradientRenderer {\n  setParams(p: Partial<GradientParams>): void;\n  renderFrame(frame: FrameInput, target?: RenderTarget): void;\n  readonly canvas: HTMLCanvasElement | OffscreenCanvas;\n  destroy(): void;\n}\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/types.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/uniforms.ts",
      "content": "import type { Oklab } from \"./color\";\nimport { grainFrame, loopVector, loopVectorAtPhase } from \"./loop\";\nimport type { FrameInput, GradientParams, RenderTarget } from \"./types\";\n\n/**\n * Everything a kind's shader reads, for one frame. Every backend uploads\n * exactly these values (WebGL as separate `u_*` uniforms, WebGPU as one\n * uniform struct with these member names), so frame N matches across them.\n */\nexport interface FrameUniforms {\n  /** Full image size in pixels. */\n  full: [number, number];\n  /** (cos, sin)(phase) multiplied by the gradient's fixed path radius. */\n  loopv: [number, number];\n  /** Tile x, y (top-left origin), width, height. */\n  tile: [number, number, number, number];\n  /** Seed offset in noise space. */\n  seed: [number, number];\n  scale: number;\n  warp: number;\n  blur: number;\n  grain: number;\n  /** Grain seed. */\n  frame: number;\n  /** Number of palette colours, 1-6. */\n  count: number;\n  /** Enabled (0/1), cell, levels. */\n  dither: [number, number, number];\n  /** Smoothed scroll velocity times influence. */\n  scroll: number;\n  /** Background, OKLab. */\n  bg: [number, number, number];\n  /** x, y in image uv (top-left origin), influence. */\n  pointer: [number, number, number];\n  /** Palette, OKLab, padded to six; the fourth component is unused. */\n  colors: [number, number, number, number][];\n}\n\n/** Integer hash of the seed to a stable offset in noise space. */\nexport function seedOffset(seed: number): readonly [number, number] {\n  let h = Math.imul(seed ^ 0x9e_37_79_b9, 0x85_eb_ca_6b);\n  h = Math.imul(h ^ (h >>> 13), 0xc2_b2_ae_35);\n  h ^= h >>> 16;\n  const x = (h & 0xff_ff) / 0xff_ff;\n  const y = ((h >>> 16) & 0xff_ff) / 0xff_ff;\n  return [x * 97 - 48.5, y * 97 - 48.5];\n}\n\nexport function frameUniforms(\n  params: GradientParams,\n  colors: readonly Oklab[],\n  background: Oklab,\n  frame: FrameInput,\n  target: RenderTarget,\n): FrameUniforms {\n  const [lx, ly] =\n    frame.phase !== undefined && params.drift !== undefined\n      ? loopVectorAtPhase(frame.phase, params.drift)\n      : loopVector(\n          frame.timeSeconds,\n          params.loopSeconds,\n          params.speed,\n          params.drift,\n        );\n  const [sx, sy] = seedOffset(params.seed);\n  const scroll =\n    Math.tanh((frame.scroll?.velocity ?? 0) * params.interaction.scroll) * 1.2;\n  const pointer = frame.pointer;\n  return {\n    bg: [background[0], background[1], background[2]],\n    blur: params.blur,\n    colors: Array.from({ length: 6 }, (_, i) => {\n      const c = colors[i] ?? [0, 0, 0];\n      return [c[0], c[1], c[2], 0];\n    }),\n    count: params.colors.length,\n    dither: [\n      params.dither.enabled ? 1 : 0,\n      params.dither.cell,\n      params.dither.levels,\n    ],\n    frame: grainFrame(frame.frameIndex, params.loopSeconds, frame.frameRate),\n    full: [target.fullWidth, target.fullHeight],\n    grain: params.grain,\n    loopv: [lx, ly],\n    pointer: [\n      pointer?.x ?? 0.5,\n      pointer?.y ?? 0.5,\n      (pointer?.strength ?? 0) * params.interaction.pointer,\n    ],\n    scale: params.scale,\n    scroll,\n    seed: [sx, sy],\n    tile: [target.x, target.y, target.width, target.height],\n    warp: Math.min(1.6, params.warp + Math.abs(scroll) * 0.5),\n  };\n}\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/uniforms.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/webgpu-device.ts",
      "content": "/**\n * The WebGPU backend's device half: probe, leases, pipelines and uniform\n * packing. Bare WebGPU, no library. webgpu.ts imports this module only when\n * a gradient with a WGSL twin is near the viewport, the browser has WebGPU,\n * and WebGL is not preferred, so WebGL-only pages never download it.\n *\n * One device per page; each lease is an OffscreenCanvas with a `webgpu`\n * context that the mount copies onto its own 2D canvas, exactly like a\n * pooled WebGL context, so falling back never changes a visible canvas's\n * context type and the last frame stays on screen.\n *\n * Selection (see docs/engine/webgpu-plan.md, slice 5):\n * - The adapter must say it is hardware. A missing `isFallbackAdapter`, or\n *   empty vendor and architecture (Safari often reports both), counts as\n *   unknown, and unknown is not hardware. Preference \"webgpu\" skips this.\n * - Before any lease, a probe checks OffscreenCanvas WebGPU, a configured\n *   context, a 1x1 frame copied onto a 2D canvas and read back (the copy\n *   path and CanvasImageSource support), and `device.lost`.\n * - Any failure selects WebGL for the page, before anything is allocated\n *   for leases.\n *\n * Device loss: every lease ends at once (mounts keep their last frame). An\n * unexpected loss gets one re-init, tagged with a generation so a stale one\n * is cancelled; a second loss, a failed or slow re-init, or a \"destroyed\"\n * loss moves the page to WebGL for the session.\n *\n * Shader compile failures demote just that kind to WebGL.\n */\nimport type { BackendLease } from \"./backend\";\nimport type { Oklab } from \"./color\";\nimport { getKind } from \"./kinds\";\nimport { normalizeParams } from \"./params\";\nimport type { AnyCanvas, ColorResolver } from \"./renderer\";\nimport { documentColorResolver } from \"./renderer\";\nimport type {\n  FrameInput,\n  GradientKind,\n  GradientParams,\n  RenderTarget,\n} from \"./types\";\nimport { frameUniforms } from \"./uniforms\";\nimport type { BackendPreference, WebGPUStats } from \"./webgpu\";\nimport {\n  getBackendPreference,\n  MAX_WEBGPU_SURFACES,\n  notifyWebGPUChange as notify,\n  WEBGPU_MEMORY_CAP,\n} from \"./webgpu\";\n\n// Minimal structural WebGPU types. TypeScript's DOM lib has none, and\n// registry users may not install @webgpu/types, so the engine declares just\n// what it calls, under its own names.\ninterface WgpuAdapterInfo {\n  readonly vendor?: string;\n  readonly architecture?: string;\n  readonly device?: string;\n  readonly description?: string;\n  readonly isFallbackAdapter?: boolean;\n}\ninterface WgpuAdapter {\n  readonly info?: WgpuAdapterInfo;\n  readonly isFallbackAdapter?: boolean;\n  requestDevice(): Promise<WgpuDevice>;\n}\ninterface WgpuGpu {\n  requestAdapter(options?: {\n    powerPreference?: \"low-power\" | \"high-performance\";\n  }): Promise<WgpuAdapter | null>;\n  getPreferredCanvasFormat(): string;\n}\ninterface WgpuBuffer {\n  destroy(): void;\n}\ninterface WgpuPipeline {\n  getBindGroupLayout(index: number): unknown;\n}\ninterface WgpuPass {\n  setPipeline(pipeline: WgpuPipeline): void;\n  setBindGroup(index: number, group: unknown): void;\n  draw(vertices: number): void;\n  end(): void;\n}\ninterface WgpuEncoder {\n  beginRenderPass(descriptor: {\n    colorAttachments: {\n      view: unknown;\n      loadOp: \"clear\";\n      storeOp: \"store\";\n      clearValue: { r: number; g: number; b: number; a: number };\n    }[];\n  }): WgpuPass;\n  finish(): unknown;\n}\ninterface WgpuDevice {\n  readonly lost: Promise<{ reason: string; message: string }>;\n  readonly queue: {\n    writeBuffer(buffer: WgpuBuffer, offset: number, data: ArrayBuffer): void;\n    submit(commands: unknown[]): void;\n  };\n  createShaderModule(descriptor: { code: string }): unknown;\n  createRenderPipelineAsync(descriptor: {\n    layout: \"auto\";\n    vertex: { module: unknown; entryPoint: string };\n    fragment: {\n      module: unknown;\n      entryPoint: string;\n      targets: { format: string }[];\n    };\n    primitive: { topology: \"triangle-list\" };\n  }): Promise<WgpuPipeline>;\n  createBuffer(descriptor: { size: number; usage: number }): WgpuBuffer;\n  createBindGroup(descriptor: {\n    layout: unknown;\n    entries: { binding: number; resource: { buffer: WgpuBuffer } }[];\n  }): unknown;\n  createCommandEncoder(): WgpuEncoder;\n  destroy(): void;\n}\ninterface WgpuCanvasContext {\n  configure(options: {\n    device: WgpuDevice;\n    format: string;\n    alphaMode: \"opaque\";\n  }): void;\n  unconfigure(): void;\n  getCurrentTexture(): { createView(): unknown };\n}\n\nconst BUFFER_USAGE_UNIFORM = 0x40;\nconst BUFFER_USAGE_COPY_DST = 0x08;\n/**\n * Byte offsets of the WGSL `Uniforms` struct members (shaders/wgsl-common.ts,\n * WGSL host-shareable layout). scripts/gpu/vgpu.test.ts checks them against\n * the reflected layout of every kind.\n */\nexport const UNIFORM_OFFSETS = {\n  bg: 80,\n  blur: 48,\n  colors: 112,\n  count: 60,\n  dither: 64,\n  frame: 56,\n  full: 0,\n  grain: 52,\n  loopv: 8,\n  pointer: 96,\n  scale: 40,\n  scroll: 76,\n  seed: 32,\n  tile: 16,\n  warp: 44,\n} as const;\n/** Bytes in the WGSL `Uniforms` struct. */\nexport const UNIFORM_BYTES = 208;\n\nlet memoryCap = WEBGPU_MEMORY_CAP;\nconst SWAP_BYTES_PER_PIXEL = 4 * 3;\n/** A re-init after device loss that takes longer gives up on WebGPU. */\nconst REINIT_TIMEOUT_MS = 2000;\n/** The first probe gets longer: some drivers are slow to hand out a device. */\nconst PROBE_TIMEOUT_MS = 5000;\n\nconst VERTEX_WGSL = /* wgsl */ `\n@vertex\nfn vs(@builtin(vertex_index) i: u32) -> @builtin(position) vec4f {\n  let p = vec2f(f32((i << 1u) & 2u), f32(i & 2u));\n  return vec4f(p * 2.0 - 1.0, 0.0, 1.0);\n}\n`;\n\ntype State =\n  | { kind: \"idle\" }\n  | { kind: \"probing\"; generation: number }\n  | {\n      kind: \"ready\";\n      generation: number;\n      device: WgpuDevice;\n      format: string;\n      adapter: string;\n    }\n  | { kind: \"failed\"; reason: string };\n\nlet state: State = { kind: \"idle\" };\nlet generation = 0;\nlet losses = 0;\n\ninterface Surface {\n  canvas: OffscreenCanvas;\n  context: WgpuCanvasContext;\n  lease: WebGPULease;\n}\nconst surfaces = new Set<Surface>();\n/** Uniform buffers created minus destroyed; equals live leases' count. For tests. */\nlet liveUniformBuffers = 0;\nconst pipelines = new Map<string, WgpuPipeline | \"pending\" | \"failed\">();\n\nfunction isWgpuGpu(value: unknown): value is WgpuGpu {\n  return (\n    typeof value === \"object\" &&\n    value !== null &&\n    \"requestAdapter\" in value &&\n    \"getPreferredCanvasFormat\" in value\n  );\n}\n\nfunction navigatorGpu(): WgpuGpu | null {\n  if (typeof navigator === \"undefined\") {\n    return null;\n  }\n  const gpu: unknown = Reflect.get(navigator, \"gpu\");\n  return isWgpuGpu(gpu) ? gpu : null;\n}\n\nfunction isWgpuContext(value: unknown): value is WgpuCanvasContext {\n  return (\n    typeof value === \"object\" &&\n    value !== null &&\n    \"configure\" in value &&\n    \"getCurrentTexture\" in value\n  );\n}\n\nfunction webgpuContext(canvas: OffscreenCanvas): WgpuCanvasContext | null {\n  const context: unknown = canvas.getContext(\"webgpu\");\n  return isWgpuContext(context) ? context : null;\n}\n\nconst SOFTWARE = /swiftshader|llvmpipe|lavapipe|software/i;\n\n/** Why the adapter is not trusted as hardware, or null when it is. */\nexport function adapterRefusal(adapter: WgpuAdapter): string | null {\n  const info = adapter.info;\n  const fallback = info?.isFallbackAdapter ?? adapter.isFallbackAdapter;\n  if (fallback === true) {\n    return \"fallback (software) adapter\";\n  }\n  if (fallback !== false) {\n    return \"adapter does not say whether it is a fallback adapter\";\n  }\n  const named = `${info?.vendor ?? \"\"} ${info?.architecture ?? \"\"}`.trim();\n  if (named === \"\") {\n    return \"adapter reports no vendor or architecture\";\n  }\n  if (SOFTWARE.test(`${named} ${info?.description ?? \"\"}`)) {\n    return `software adapter (${named})`;\n  }\n  return null;\n}\n\nfunction describe(adapter: WgpuAdapter): string {\n  const info = adapter.info;\n  return (\n    [info?.vendor, info?.architecture, info?.description]\n      .filter((part) => part && part.length > 0)\n      .join(\" \") || \"unknown adapter\"\n  );\n}\n\nfunction timeout(ms: number): Promise<\"timeout\"> {\n  return new Promise((resolve) => setTimeout(() => resolve(\"timeout\"), ms));\n}\n\n/** Draws a 1x1 clear colour through WebGPU and reads it back through a 2D canvas. */\nfunction probeCopyPath(device: WgpuDevice, format: string): string | null {\n  if (typeof OffscreenCanvas === \"undefined\") {\n    return \"no OffscreenCanvas\";\n  }\n  const canvas = new OffscreenCanvas(1, 1);\n  const context = webgpuContext(canvas);\n  if (!context) {\n    return \"OffscreenCanvas has no webgpu context\";\n  }\n  context.configure({ alphaMode: \"opaque\", device, format });\n  const encoder = device.createCommandEncoder();\n  encoder\n    .beginRenderPass({\n      colorAttachments: [\n        {\n          clearValue: { a: 1, b: 0.4, g: 0.6, r: 0.2 },\n          loadOp: \"clear\",\n          storeOp: \"store\",\n          view: context.getCurrentTexture().createView(),\n        },\n      ],\n    })\n    .end();\n  device.queue.submit([encoder.finish()]);\n  const out = new OffscreenCanvas(1, 1);\n  const ctx = out.getContext(\"2d\", { willReadFrequently: true });\n  if (!ctx) {\n    return \"no 2D canvas\";\n  }\n  try {\n    // Copying right after queue.submit() is safe: reading a WebGPU canvas\n    // (drawImage included) runs \"get a copy of the image contents of a\n    // context\", which first ensures all submitted work has finished writing the\n    // current texture (https://gpuweb.github.io/gpuweb/#abstract-opdef-get-a-copy-of-the-image-contents-of-a-context,\n    // via #canvas-hooks). The engine lab checks it: heavy kinds at 2560x1440,\n    // each frame copied the moment it is submitted, never stale or blank.\n    ctx.drawImage(canvas, 0, 0);\n  } catch (error) {\n    return `drawImage from a WebGPU canvas threw: ${String(error)}`;\n  }\n  const [r = 0, g = 0, b = 0] = ctx.getImageData(0, 0, 1, 1).data;\n  context.unconfigure();\n  const close = (v: number, want: number) => Math.abs(v - want) <= 3;\n  return close(r, 51) && close(g, 153) && close(b, 102)\n    ? null\n    : `copy read back rgb(${r},${g},${b}), wanted rgb(51,153,102)`;\n}\n\nfunction fail(reason: string) {\n  state = { kind: \"failed\", reason };\n  pipelines.clear();\n  notify();\n}\n\nasync function probe(gen: number, limitMs: number): Promise<void> {\n  const gpu = navigatorGpu();\n  if (!gpu) {\n    fail(\"navigator.gpu is missing\");\n    return;\n  }\n  const attempt = async (): Promise<\n    { device: WgpuDevice; format: string; adapter: string } | { error: string }\n  > => {\n    const adapter = await gpu.requestAdapter({ powerPreference: \"low-power\" });\n    if (!adapter) {\n      return { error: \"no WebGPU adapter\" };\n    }\n    const refusal =\n      getBackendPreference() === \"webgpu\" ? null : adapterRefusal(adapter);\n    if (refusal) {\n      return { error: refusal };\n    }\n    const device = await adapter.requestDevice();\n    // From here every failure, thrown or returned, destroys the device.\n    try {\n      if (!(device.lost instanceof Promise)) {\n        throw new Error(\"device.lost is not a promise\");\n      }\n      const format = gpu.getPreferredCanvasFormat();\n      const copy = probeCopyPath(device, format);\n      if (copy) {\n        throw new Error(copy);\n      }\n      return { adapter: describe(adapter), device, format };\n    } catch (error) {\n      device.destroy();\n      return { error: error instanceof Error ? error.message : String(error) };\n    }\n  };\n  const pending = attempt().catch(\n    (error: unknown) => ({ error: String(error) }) as const,\n  );\n  const result = await Promise.race([pending, timeout(limitMs)]);\n  if (gen !== generation) {\n    // A newer probe or a failure replaced this one: drop what it made.\n    void pending.then((late) => \"device\" in late && late.device.destroy());\n    return;\n  }\n  if (result === \"timeout\") {\n    void pending.then((late) => \"device\" in late && late.device.destroy());\n    fail(`no device within ${limitMs}ms`);\n    return;\n  }\n  if (\"error\" in result) {\n    fail(result.error);\n    return;\n  }\n  const { device } = result;\n  state = { ...result, generation: gen, kind: \"ready\" };\n  void device.lost.then((info) => deviceLost(gen, info.reason));\n  notify();\n}\n\nfunction startProbe(limitMs: number) {\n  generation += 1;\n  state = { generation, kind: \"probing\" };\n  void probe(generation, limitMs);\n}\n\nfunction deviceLost(gen: number, reason: string) {\n  if (state.kind !== \"ready\" || state.generation !== gen) {\n    return;\n  }\n  const lost = state.device;\n  losses += 1;\n  generation += 1;\n  pipelines.clear();\n  for (const surface of [...surfaces]) {\n    surfaces.delete(surface);\n    surface.lease.end();\n  }\n  if (reason !== \"destroyed\" && losses === 1) {\n    startProbe(REINIT_TIMEOUT_MS);\n  } else {\n    fail(`device lost (${reason}); using WebGL for this session`);\n  }\n  lost.destroy();\n  notify();\n}\n\nfunction compile(kind: GradientKind, device: WgpuDevice, format: string) {\n  const definition = getKind(kind);\n  const gen = generation;\n  pipelines.set(definition.name, \"pending\");\n  const load = definition.wgsl;\n  // The WGSL prelude and the kind's twin load on demand, so pages that never\n  // pick WebGPU never download them.\n  Promise.all([\n    import(\"./shaders/wgsl-common\"),\n    load ? load() : Promise.reject(new Error(\"no WGSL twin\")),\n  ])\n    .then(([common, source]) =>\n      device.createRenderPipelineAsync({\n        fragment: {\n          entryPoint: \"fs_main\",\n          module: device.createShaderModule({\n            code: common.composeWgsl(source),\n          }),\n          targets: [{ format }],\n        },\n        layout: \"auto\",\n        primitive: { topology: \"triangle-list\" },\n        vertex: {\n          entryPoint: \"vs\",\n          module: device.createShaderModule({ code: VERTEX_WGSL }),\n        },\n      }),\n    )\n    .then(\n      (pipeline) => {\n        if (gen === generation) pipelines.set(definition.name, pipeline);\n      },\n      () => {\n        if (gen === generation) pipelines.set(definition.name, \"failed\");\n      },\n    )\n    .finally(notify);\n}\n\n/**\n * Whether WebGPU can draw `kind` now: \"ready\", \"pending\" (probing or\n * compiling; ask again on the next change), or \"unavailable\" (use WebGL).\n * Starts the probe and the kind's compile on first use.\n */\nexport function webgpuStatus(\n  kind: GradientKind,\n): \"ready\" | \"pending\" | \"unavailable\" {\n  if (state.kind === \"idle\") {\n    startProbe(PROBE_TIMEOUT_MS);\n    return \"pending\";\n  }\n  if (state.kind === \"failed\") {\n    return \"unavailable\";\n  }\n  if (state.kind === \"probing\") {\n    return \"pending\";\n  }\n  const name = getKind(kind).name;\n  const pipeline = pipelines.get(name);\n  if (pipeline === undefined) {\n    compile(name, state.device, state.format);\n    return \"pending\";\n  }\n  if (pipeline === \"failed\") {\n    return \"unavailable\";\n  }\n  return pipeline === \"pending\" ? \"pending\" : \"ready\";\n}\n\nfunction leasedBytes(): number {\n  let total = 0;\n  for (const surface of surfaces) {\n    if (surface.lease.leased) {\n      total +=\n        surface.canvas.width * surface.canvas.height * SWAP_BYTES_PER_PIXEL;\n    }\n  }\n  return total;\n}\n\nfunction packUniforms(\n  params: GradientParams,\n  colors: readonly Oklab[],\n  background: Oklab,\n  frame: FrameInput,\n  target: RenderTarget,\n): ArrayBuffer {\n  const u = frameUniforms(params, colors, background, frame, target);\n  const buffer = new ArrayBuffer(UNIFORM_BYTES);\n  const f = new Float32Array(buffer);\n  const at = (member: keyof typeof UNIFORM_OFFSETS) =>\n    UNIFORM_OFFSETS[member] / 4;\n  f.set(u.full, at(\"full\"));\n  f.set(u.loopv, at(\"loopv\"));\n  f.set(u.tile, at(\"tile\"));\n  f.set(u.seed, at(\"seed\"));\n  f[at(\"scale\")] = u.scale;\n  f[at(\"warp\")] = u.warp;\n  f[at(\"blur\")] = u.blur;\n  f[at(\"grain\")] = u.grain;\n  f[at(\"frame\")] = u.frame;\n  new Int32Array(buffer)[at(\"count\")] = u.count;\n  f.set(u.dither, at(\"dither\"));\n  f[at(\"scroll\")] = u.scroll;\n  f.set(u.bg, at(\"bg\"));\n  f.set(u.pointer, at(\"pointer\"));\n  u.colors.forEach((color, k) => {\n    f.set(color, at(\"colors\") + k * 4);\n  });\n  return buffer;\n}\n\nclass WebGPULease implements BackendLease {\n  readonly canvas: AnyCanvas;\n  resolver: ColorResolver = documentColorResolver;\n  loaded: { owner: object; version: number } | null = null;\n  sourceY = 0;\n  leased = false;\n  onLost: (() => void) | null = null;\n  private lost = false;\n  private params: GradientParams | null = null;\n  private colors: Oklab[] = [];\n  private background: Oklab = [0, 0, 0];\n  private readonly uniforms: WgpuBuffer;\n  private freed = false;\n  private readonly groups = new Map<WgpuPipeline, unknown>();\n  private readonly surface: OffscreenCanvas;\n  private readonly context: WgpuCanvasContext;\n  private readonly device: WgpuDevice;\n  private readonly gen: number;\n\n  constructor(\n    surface: OffscreenCanvas,\n    context: WgpuCanvasContext,\n    device: WgpuDevice,\n    gen: number,\n  ) {\n    this.surface = surface;\n    this.context = context;\n    this.device = device;\n    this.gen = gen;\n    this.canvas = surface;\n    liveUniformBuffers += 1;\n    this.uniforms = device.createBuffer({\n      size: UNIFORM_BYTES,\n      usage: BUFFER_USAGE_UNIFORM | BUFFER_USAGE_COPY_DST,\n    });\n  }\n\n  isLost(): boolean {\n    return this.lost || this.gen !== generation || state.kind !== \"ready\";\n  }\n\n  setParams(params: GradientParams): void {\n    this.params = normalizeParams(params);\n    this.colors = this.params.colors.map((value) => this.resolver(value));\n    this.background = this.resolver(this.params.background);\n  }\n\n  renderFrame(frame: FrameInput, target: RenderTarget): void {\n    const params = this.params;\n    if (!params || this.isLost()) {\n      return;\n    }\n    const pipeline = pipelines.get(getKind(params.kind).name);\n    if (!pipeline || typeof pipeline === \"string\") {\n      // The kind is not compiled here; hand the slot back to the scheduler.\n      this.drop();\n      return;\n    }\n    // WebGL rasterises bottom-up, WebGPU top-down, and derivatives come\n    // from 2x2 quads. At odd heights the two group different rows, so draw\n    // one spare row above the image: quads then line up with WebGL's and\n    // fwidth() matches. The frame sits from row `sourceY` down.\n    const pad = target.height % 2;\n    const height = target.height + pad;\n    if (this.surface.width !== target.width || this.surface.height !== height) {\n      const grow =\n        (target.width * height - this.surface.width * this.surface.height) *\n        SWAP_BYTES_PER_PIXEL;\n      if (grow > 0 && leasedBytes() + grow > memoryCap) {\n        // Over the memory cap: evict this lease; the mount keeps its frame.\n        this.drop();\n        return;\n      }\n      this.surface.width = target.width;\n      this.surface.height = height;\n    }\n    this.sourceY = pad;\n    this.device.queue.writeBuffer(\n      this.uniforms,\n      0,\n      packUniforms(params, this.colors, this.background, frame, {\n        ...target,\n        height,\n        y: target.y - pad,\n      }),\n    );\n    let group = this.groups.get(pipeline);\n    if (!group) {\n      group = this.device.createBindGroup({\n        entries: [{ binding: 0, resource: { buffer: this.uniforms } }],\n        layout: pipeline.getBindGroupLayout(0),\n      });\n      this.groups.set(pipeline, group);\n    }\n    const encoder = this.device.createCommandEncoder();\n    const pass = encoder.beginRenderPass({\n      colorAttachments: [\n        {\n          clearValue: { a: 1, b: 0, g: 0, r: 0 },\n          loadOp: \"clear\",\n          storeOp: \"store\",\n          view: this.context.getCurrentTexture().createView(),\n        },\n      ],\n    });\n    pass.setPipeline(pipeline);\n    pass.setBindGroup(0, group);\n    pass.draw(3);\n    pass.end();\n    this.device.queue.submit([encoder.finish()]);\n  }\n\n  /** Ends the lease from inside (eviction, missing pipeline): isLost() turns true, onLost runs next task. */\n  private drop() {\n    removeSurface(this);\n    this.free();\n    this.lost = true;\n    const holder = this.onLost;\n    this.onLost = null;\n    this.leased = false;\n    if (holder) {\n      queueMicrotask(holder);\n    }\n  }\n\n  /** Device loss: the lease is over for good. */\n  end() {\n    this.drop();\n  }\n\n  /** Releases the uniform buffer and the context configuration, once. */\n  private free() {\n    if (this.freed) {\n      return;\n    }\n    this.freed = true;\n    liveUniformBuffers -= 1;\n    this.uniforms.destroy();\n    if (state.kind === \"ready\" && state.device === this.device) {\n      this.context.unconfigure();\n    }\n  }\n\n  /** Back to the pool: shrink to 1x1 so the swap chain's memory goes. */\n  release() {\n    this.leased = false;\n    this.onLost = null;\n    this.surface.width = 1;\n    this.surface.height = 1;\n  }\n\n  /** Trimmed from the pool while idle. */\n  retire() {\n    this.free();\n  }\n\n  reusable(): boolean {\n    return !this.leased && !this.lost && this.gen === generation;\n  }\n}\n\n/** Takes a lease's surface out of the pool and frees it. */\nfunction removeSurface(lease: WebGPULease) {\n  for (const surface of surfaces) {\n    if (surface.lease === lease) {\n      surfaces.delete(surface);\n    }\n  }\n}\n\n/** Leases a surface, or null when WebGPU is not ready or a cap is reached. */\nexport function acquireSurface(\n  onLost: (() => void) | null,\n  pixels = 0,\n): WebGPULease | null {\n  if (state.kind !== \"ready\") {\n    return null;\n  }\n  // Refuse up front what would only be evicted on the first frame.\n  if (leasedBytes() + pixels * SWAP_BYTES_PER_PIXEL > memoryCap) {\n    return null;\n  }\n  for (const surface of surfaces) {\n    if (surface.lease.reusable()) {\n      surface.lease.leased = true;\n      surface.lease.onLost = onLost;\n      return surface.lease;\n    }\n  }\n  if (surfaces.size >= MAX_WEBGPU_SURFACES || leasedBytes() >= memoryCap) {\n    return null;\n  }\n  const canvas = new OffscreenCanvas(1, 1);\n  const context = webgpuContext(canvas);\n  if (!context) {\n    fail(\"OffscreenCanvas lost its webgpu context\");\n    return null;\n  }\n  context.configure({\n    alphaMode: \"opaque\",\n    device: state.device,\n    format: state.format,\n  });\n  const lease = new WebGPULease(canvas, context, state.device, generation);\n  lease.leased = true;\n  lease.onLost = onLost;\n  surfaces.add({ canvas, context, lease });\n  return lease;\n}\n\nexport function releaseSurface(lease: BackendLease): void {\n  for (const surface of surfaces) {\n    if (surface.lease === lease) {\n      surface.lease.release();\n    }\n  }\n}\n\n/** Frees idle surfaces until at most `keep` remain. */\nexport function trimSurfaces(keep: number): void {\n  for (const surface of [...surfaces]) {\n    if (surfaces.size <= keep) {\n      return;\n    }\n    if (!surface.lease.leased) {\n      surface.lease.retire();\n      surfaces.delete(surface);\n    }\n  }\n}\n\n/** Changes the swap-chain memory cap (0 restores the default). For tuning and tests. */\nexport function setWebGPUMemoryCap(bytes: number): void {\n  memoryCap = bytes > 0 ? bytes : WEBGPU_MEMORY_CAP;\n  notify();\n}\n\nexport function webgpuUnsupported(): boolean {\n  return state.kind === \"failed\";\n}\n\n/** The preference changed (webgpu.ts already stored it). */\nexport function preferenceChanged(next: BackendPreference): void {\n  // Forcing WebGPU retries a page that only failed the adapter policy.\n  if (next === \"webgpu\" && state.kind === \"failed\" && losses === 0) {\n    state = { kind: \"idle\" };\n  }\n}\n\n/** Counts and state for tests and the engine lab. */\nexport function webgpuStats(): WebGPUStats {\n  return {\n    adapter: state.kind === \"ready\" ? state.adapter : null,\n    leased: [...surfaces].filter((s) => s.lease.leased).length,\n    leasedBytes: leasedBytes(),\n    losses,\n    reason: state.kind === \"failed\" ? state.reason : null,\n    state: state.kind,\n    surfaces: surfaces.size,\n    uniformBuffers: liveUniformBuffers,\n  };\n}\n\n/**\n * Loses the device as a driver would (\"unknown\" reason, so the one re-init\n * runs), then destroys it. For the engine lab and tests.\n */\nexport function loseWebGPUDevice(reason = \"unknown\"): boolean {\n  if (state.kind !== \"ready\") {\n    return false;\n  }\n  deviceLost(state.generation, reason);\n  return true;\n}\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/webgpu-device.ts"
    },
    {
      "path": "registry/remocn/gsh/gradient-engine/webgpu.ts",
      "content": "/**\n * The WebGPU backend's always-loaded half: the renderer preference, change\n * notifications and synchronous answers for the scheduler and mounts. The\n * device code (probe, leases, pipelines) lives in webgpu-device.ts and is\n * imported on demand: only when a gradient with a WGSL twin is near the\n * viewport, the browser has `navigator.gpu`, and WebGL2 is not preferred.\n * Each kind's WGSL loads the same way, so WebGL-only pages never download\n * any WebGPU code or shader text.\n */\nimport type { BackendLease } from \"./backend\";\nimport { getKind } from \"./kinds\";\nimport type { GradientKind } from \"./types\";\n\ntype Device = typeof import(\"./webgpu-device\");\n\nexport type BackendPreference = \"auto\" | \"webgpu\" | \"webgl2\";\n\n/** Most WebGPU surfaces alive at once; the scheduler's WebGPU budget. */\nexport const MAX_WEBGPU_SURFACES = 16;\n/** Swap-chain memory cap across leased surfaces: width x height x 4 bytes x 3 buffers. */\nexport const WEBGPU_MEMORY_CAP = 96 * 1024 * 1024;\n\nexport interface WebGPUStats {\n  state: \"idle\" | \"probing\" | \"ready\" | \"failed\";\n  adapter: string | null;\n  reason: string | null;\n  losses: number;\n  surfaces: number;\n  leased: number;\n  leasedBytes: number;\n  /** Per-lease uniform buffers still alive; always equals `surfaces`. */\n  uniformBuffers: number;\n}\n\nconst PREFERENCE_KEY = \"gradients:gradient-backend\";\nconst LEGACY_PREFERENCE_KEY = \"gcn:gradient-backend\";\n\nfunction isPreference(value: unknown): value is BackendPreference {\n  return value === \"auto\" || value === \"webgpu\" || value === \"webgl2\";\n}\n\n/** `?gradient-backend=` wins over localStorage[\"gradients:gradient-backend\"]; default \"auto\". */\nfunction storedPreference(): BackendPreference {\n  if (typeof window === \"undefined\") {\n    return \"auto\";\n  }\n  try {\n    const query = new URLSearchParams(window.location.search).get(\n      \"gradient-backend\",\n    );\n    if (isPreference(query)) {\n      return query;\n    }\n    const current = window.localStorage.getItem(PREFERENCE_KEY);\n    const stored =\n      current ?? window.localStorage.getItem(LEGACY_PREFERENCE_KEY);\n    if (current === null && isPreference(stored)) {\n      window.localStorage.setItem(PREFERENCE_KEY, stored);\n      window.localStorage.removeItem(LEGACY_PREFERENCE_KEY);\n    }\n    return isPreference(stored) ? stored : \"auto\";\n  } catch {\n    return \"auto\";\n  }\n}\n\nlet preference: BackendPreference = storedPreference();\nlet device: Device | null = null;\nlet loading = false;\n/** Why WebGPU will not load on this page (no navigator.gpu, or the import failed). */\nlet unavailable: string | null = null;\nlet pendingMemoryCap = 0;\nconst changeListeners = new Set<() => void>();\n\n/** Runs `listener` when WebGPU loads, becomes ready, fails, loses its device, or a kind finishes compiling. */\nexport function onWebGPUChange(listener: () => void): () => void {\n  changeListeners.add(listener);\n  return () => changeListeners.delete(listener);\n}\n\n/** For webgpu-device.ts: tell listeners something changed. */\nexport function notifyWebGPUChange(): void {\n  for (const listener of changeListeners) {\n    listener();\n  }\n}\n\nfunction hasWebGPU(): boolean {\n  return (\n    typeof navigator !== \"undefined\" &&\n    Reflect.get(navigator, \"gpu\") !== undefined\n  );\n}\n\nfunction load() {\n  loading = true;\n  import(\"./webgpu-device\").then(\n    (module) => {\n      device = module;\n      if (pendingMemoryCap > 0) {\n        module.setWebGPUMemoryCap(pendingMemoryCap);\n      }\n      notifyWebGPUChange();\n    },\n    (error: unknown) => {\n      unavailable = `could not load the WebGPU backend: ${String(error)}`;\n      notifyWebGPUChange();\n    },\n  );\n}\n\n/**\n * Whether WebGPU can draw `kind` now: \"ready\", \"pending\" (loading, probing\n * or compiling; ask again on the next change), or \"unavailable\" (use WebGL).\n * Loads the device code, starts the probe and the kind's compile on first use.\n */\nexport function webgpuStatus(\n  kind: GradientKind,\n): \"ready\" | \"pending\" | \"unavailable\" {\n  if (preference === \"webgl2\" || getKind(kind).wgsl === undefined) {\n    return \"unavailable\";\n  }\n  if (device) {\n    return device.webgpuStatus(kind);\n  }\n  if (unavailable !== null) {\n    return \"unavailable\";\n  }\n  if (!hasWebGPU()) {\n    unavailable = \"navigator.gpu is missing\";\n    return \"unavailable\";\n  }\n  if (!loading) {\n    load();\n  }\n  return \"pending\";\n}\n\n/** Leases a surface, or null when WebGPU is not ready or a cap is reached. */\nexport function acquireSurface(\n  onLost: (() => void) | null,\n  pixels = 0,\n): BackendLease | null {\n  return device?.acquireSurface(onLost, pixels) ?? null;\n}\n\nexport function releaseSurface(lease: BackendLease): void {\n  device?.releaseSurface(lease);\n}\n\n/** Frees idle surfaces until at most `keep` remain. */\nexport function trimSurfaces(keep: number): void {\n  device?.trimSurfaces(keep);\n}\n\n/** Changes the swap-chain memory cap (0 restores the default). For tuning and tests. */\nexport function setWebGPUMemoryCap(bytes: number): void {\n  if (device) {\n    device.setWebGPUMemoryCap(bytes);\n  } else {\n    pendingMemoryCap = bytes;\n  }\n}\n\nexport function webgpuUnsupported(): boolean {\n  return unavailable !== null || (device?.webgpuUnsupported() ?? false);\n}\n\nexport function getBackendPreference(): BackendPreference {\n  return preference;\n}\n\n/**\n * Chooses the backend for new leases: \"auto\" (WebGPU when the adapter and\n * probes pass), \"webgpu\" (skip the hardware check, keep the probes) or\n * \"webgl2\". Live gradients keep their lease until it is next granted;\n * reload for a clean switch.\n */\nexport function setBackendPreference(\n  next: BackendPreference,\n  options: { persist?: boolean } = {},\n): void {\n  preference = next;\n  if (options.persist && typeof window !== \"undefined\") {\n    try {\n      window.localStorage.setItem(PREFERENCE_KEY, next);\n    } catch {\n      // Storage can be off; the preference still holds for this page.\n    }\n  }\n  device?.preferenceChanged(next);\n  notifyWebGPUChange();\n}\n\n/** Counts and state for tests and the engine lab. */\nexport function webgpuStats(): WebGPUStats {\n  return (\n    device?.webgpuStats() ?? {\n      adapter: null,\n      leased: 0,\n      leasedBytes: 0,\n      losses: 0,\n      reason: unavailable,\n      state: unavailable === null ? \"idle\" : \"failed\",\n      surfaces: 0,\n      uniformBuffers: 0,\n    }\n  );\n}\n\n/**\n * Loses the device as a driver would (\"unknown\" reason, so the one re-init\n * runs), then destroys it. For the engine lab and tests.\n */\nexport function loseWebGPUDevice(reason = \"unknown\"): boolean {\n  return device?.loseWebGPUDevice(reason) ?? false;\n}\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gradient-engine/webgpu.ts"
    },
    {
      "path": "registry/remocn/gsh/gsh-ground.tsx",
      "content": "import { type CSSProperties, useLayoutEffect, useMemo, useRef } from \"react\";\nimport { AbsoluteFill, useCurrentFrame, useVideoConfig } from \"remotion\";\nimport {\n  type GradientParams,\n  kindDefaults,\n  mergeParams,\n} from \"./gradient-engine\";\nimport {\n  createWebGLRenderer,\n  getWebGL2,\n  type WebGLRenderer,\n} from \"./gradient-engine/renderer\";\nimport { GSH_PRESETS, type GshPresetId } from \"./presets\";\n\nexport type GshGroundProps = {\n  preset?: GshPresetId;\n  params?: Partial<GradientParams>;\n  timeOffset?: number;\n  timeScale?: number;\n  resolution?: number;\n  style?: CSSProperties;\n};\n\nexport const gshParams = (\n  preset: GshPresetId | undefined,\n  params?: Partial<GradientParams>,\n): GradientParams => {\n  const base = preset ? GSH_PRESETS[preset] : {};\n  const kind = params?.kind ?? base.kind ?? \"mesh\";\n  return mergeParams(kindDefaults(kind), {\n    ...base,\n    ...params,\n    interaction: { pointer: 0, scroll: 0 },\n  });\n};\n\nexport function GshGround({\n  preset,\n  params,\n  timeOffset = 0,\n  timeScale = 1,\n  resolution = 0.5,\n  style,\n}: GshGroundProps) {\n  const frame = useCurrentFrame();\n  const { width, height, fps } = useVideoConfig();\n  const canvasRef = useRef<HTMLCanvasElement>(null);\n  const rendererRef = useRef<WebGLRenderer | null>(null);\n  const resolved = useMemo(() => gshParams(preset, params), [preset, params]);\n  const key = JSON.stringify(resolved);\n  const w = Math.max(2, Math.round((width * resolution) / 2) * 2);\n  const h = Math.max(2, Math.round((height * resolution) / 2) * 2);\n\n  useLayoutEffect(() => {\n    const canvas = canvasRef.current;\n    if (!canvas) return;\n    canvas.width = w;\n    canvas.height = h;\n    const gl = getWebGL2(canvas, { preserveDrawingBuffer: true });\n    if (!gl) return;\n    const renderer = createWebGLRenderer({\n      canvas,\n      gl,\n      params: JSON.parse(key),\n    });\n    rendererRef.current = renderer;\n    return () => {\n      renderer.destroy();\n      rendererRef.current = null;\n    };\n  }, [key, w, h]);\n\n  useLayoutEffect(() => {\n    const t = timeOffset + (frame / fps) * timeScale;\n    rendererRef.current?.renderFrame({\n      timeSeconds: t,\n      frameIndex: Math.round(t * fps),\n      frameRate: fps,\n    });\n  }, [frame, fps, timeOffset, timeScale]);\n\n  return (\n    <AbsoluteFill style={{ backgroundColor: resolved.background, ...style }}>\n      <canvas\n        ref={canvasRef}\n        style={{ width: \"100%\", height: \"100%\", display: \"block\" }}\n      />\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/gsh-ground.tsx"
    },
    {
      "path": "registry/remocn/gsh/presets.ts",
      "content": "import type { GradientParams } from \"./gradient-engine\";\n\nexport type GshPresetId =\n  | \"afterhours\"\n  | \"blue-hour\"\n  | \"charcoal-satin\"\n  | \"cobalt-rise\"\n  | \"coldlight\"\n  | \"comet\"\n  | \"copper\"\n  | \"corona\"\n  | \"cyan-drift\"\n  | \"earthshine\"\n  | \"ember\"\n  | \"europa\"\n  | \"film-blue\"\n  | \"flood\"\n  | \"garnet\"\n  | \"glasswork\"\n  | \"greenhouse\"\n  | \"hearth\"\n  | \"iris\"\n  | \"kiln\"\n  | \"kiruna\"\n  | \"lantern\"\n  | \"low-orbit\"\n  | \"lunar\"\n  | \"mercury\"\n  | \"nightfold\"\n  | \"nova\"\n  | \"paper-crease\"\n  | \"petal-arc\"\n  | \"polar\"\n  | \"projector\"\n  | \"refraction\"\n  | \"riptide\"\n  | \"solar-wind\"\n  | \"solstice\"\n  | \"spectral-sea\"\n  | \"spotlight\"\n  | \"static-sunset\"\n  | \"velvet-hour\";\n\nexport const GSH_PRESETS: Record<GshPresetId, Partial<GradientParams>> = {\n  afterhours: {\n    kind: \"ribbon\",\n    colors: [\"#ff2e88\", \"#7a5cff\", \"#2ee6ff\"],\n    background: \"#050308\",\n    loopSeconds: 28,\n    warp: 0.4,\n    blur: 0.3,\n    grain: 0.08,\n    seed: 7,\n  },\n  \"blue-hour\": {\n    kind: \"radial-glow\",\n    colors: [\"#eef8ff\", \"#8fd0f5\", \"#3d6fd0\", \"#1b1846\"],\n    background: \"#010309\",\n    speed: 0.9,\n    loopSeconds: 10,\n    warp: 0.35,\n    blur: 0.4,\n    grain: 0.16,\n    seed: 31,\n  },\n  \"charcoal-satin\": {\n    kind: \"silk\",\n    colors: [\"#5c6270\", \"#ffffff\", \"#a9b0bd\"],\n    background: \"#050506\",\n    loopSeconds: 28,\n    scale: 2,\n    warp: 0.9,\n    blur: 0.25,\n    seed: 2,\n  },\n  \"cobalt-rise\": {\n    kind: \"dither-burst\",\n    colors: [\"#14208f\", \"#2e5bff\", \"#9fbcff\", \"#f4f6ff\"],\n    background: \"#020309\",\n    speed: 1.16,\n    loopSeconds: 14,\n    warp: 0.25,\n    seed: 12,\n  },\n  coldlight: {\n    kind: \"dither-burst\",\n    colors: [\"#0b3a52\", \"#1aa3c8\", \"#a7ecff\", \"#f2fdff\"],\n    background: \"#020406\",\n    speed: 1.02,\n    loopSeconds: 14,\n    warp: 0.45,\n    blur: 0.6,\n    seed: 44,\n  },\n  comet: {\n    kind: \"beam\",\n    colors: [\"#e8fffb\", \"#4fe0d0\", \"#0d6f8a\"],\n    background: \"#02060a\",\n    speed: 0.88,\n    loopSeconds: 12,\n  },\n  copper: {\n    kind: \"chrome\",\n    colors: [\"#b8562a\", \"#ffd9bf\", \"#ffb070\"],\n    background: \"#060302\",\n    speed: 0.27,\n    loopSeconds: 30,\n    scale: 0.6,\n    warp: 0.2,\n    blur: 0.3,\n    seed: 30,\n  },\n  corona: {\n    kind: \"radial-glow\",\n    colors: [\"#fff6e6\", \"#ffc47b\", \"#c9543a\", \"#2a1430\"],\n    background: \"#020101\",\n    speed: 0.78,\n    loopSeconds: 10,\n    warp: 0.35,\n    blur: 0.35,\n    grain: 0.18,\n    seed: 8,\n  },\n  \"cyan-drift\": {\n    kind: \"grain\",\n    colors: [\"#e9fffd\", \"#7ff5e8\", \"#22b8d8\", \"#0b2a4a\"],\n    background: \"#010509\",\n    speed: 1.24,\n    loopSeconds: 12,\n    scale: 0.9,\n    warp: 0.6,\n    blur: 0.7,\n    seed: 143,\n  },\n  earthshine: {\n    kind: \"limb\",\n    colors: [\"#e8f4ff\", \"#4aa3ff\", \"#1d4fd6\", \"#06143a\"],\n    background: \"#02040a\",\n    speed: 2,\n    loopSeconds: 10,\n    seed: 3,\n  },\n  ember: {\n    kind: \"radial-glow\",\n    colors: [\"#ffe9cc\", \"#fe9e50\", \"#d6472e\", \"#5a0d22\"],\n    background: \"#0a0302\",\n    speed: 0.97,\n    loopSeconds: 10,\n    warp: 0.6,\n    blur: 0.6,\n    grain: 0.16,\n    seed: 14,\n  },\n  europa: {\n    kind: \"limb\",\n    colors: [\"#f0fbff\", \"#a6e4ff\", \"#3d9bd6\", \"#0a2a40\"],\n    background: \"#01040a\",\n    speed: 2,\n    loopSeconds: 8,\n    seed: 9,\n  },\n  \"film-blue\": {\n    kind: \"grain\",\n    colors: [\"#d9f1ff\", \"#5fb4e6\", \"#2b5fbe\", \"#14204a\"],\n    background: \"#03070f\",\n    speed: 1.35,\n    loopSeconds: 11,\n    scale: 0.9,\n    warp: 0.35,\n    blur: 0.6,\n    seed: 22,\n  },\n  flood: {\n    kind: \"beam\",\n    colors: [\"#e8f2ff\", \"#7fb2ff\", \"#2457e6\", \"#081a4a\"],\n    background: \"#01030b\",\n    speed: 0.79,\n    loopSeconds: 12,\n    seed: 5,\n  },\n  garnet: {\n    kind: \"silk\",\n    colors: [\"#b0102a\", \"#ffc2a8\", \"#ff4d7a\"],\n    background: \"#080203\",\n    loopSeconds: 28,\n    scale: 0.55,\n    warp: 0.3,\n    blur: 0.4,\n    seed: 2,\n  },\n  glasswork: {\n    kind: \"spectrum\",\n    colors: [\"#9fb2ff\", \"#3552ff\", \"#1a2a9e\", \"#b08cff\"],\n    background: \"#eef0f6\",\n    speed: 0.37,\n    loopSeconds: 16,\n    warp: 0.45,\n    blur: 0.4,\n    seed: 20,\n  },\n  greenhouse: {\n    kind: \"pixel-glass\",\n    colors: [\"#dcfff4\", \"#55e6bd\", \"#0e9a7e\"],\n    background: \"#010605\",\n    speed: 0.94,\n    loopSeconds: 16,\n    scale: 0.8,\n    warp: 0.7,\n    grain: 0.08,\n    seed: 27,\n  },\n  hearth: {\n    kind: \"rise\",\n    colors: [\"#fff0dc\", \"#ff8a3a\", \"#9c2f14\", \"#2a0c07\"],\n    background: \"#050303\",\n    speed: 1.07,\n    loopSeconds: 13,\n    scale: 1.35,\n    warp: 0.25,\n    grain: 0.1,\n    seed: 10,\n  },\n  iris: {\n    kind: \"halo\",\n    colors: [\"#fff6e8\", \"#ffc66b\", \"#ef4f86\", \"#4058ff\"],\n    speed: 1.53,\n    loopSeconds: 12,\n    warp: 0.7,\n    blur: 0.35,\n  },\n  kiln: {\n    kind: \"dither-burst\",\n    colors: [\"#5c0a02\", \"#e2340c\", \"#ff9a3a\", \"#ffe9c7\"],\n    background: \"#060201\",\n    speed: 1.21,\n    loopSeconds: 13,\n    warp: 0.35,\n    blur: 0.45,\n    seed: 13,\n  },\n  kiruna: {\n    kind: \"aurora\",\n    colors: [\"#dcfff4\", \"#55e6bd\", \"#0e9a7e\", \"#04332b\"],\n    background: \"#010605\",\n    speed: 0.8,\n    loopSeconds: 16,\n    scale: 0.75,\n    warp: 0.45,\n    grain: 0.16,\n    seed: 106,\n  },\n  lantern: {\n    kind: \"fluted\",\n    colors: [\"#3d2304\", \"#b8650c\", \"#ffb340\", \"#fff1c9\"],\n    background: \"#060401\",\n    speed: 2,\n    loopSeconds: 12,\n    warp: 0.4,\n    seed: 23,\n  },\n  \"low-orbit\": {\n    kind: \"limb\",\n    colors: [\"#effffb\", \"#56e3d6\", \"#0f8c9c\", \"#04242e\"],\n    background: \"#010405\",\n    speed: 1.86,\n    loopSeconds: 13,\n    warp: 0.6,\n    seed: 8,\n  },\n  lunar: {\n    kind: \"limb\",\n    colors: [\"#ffffff\", \"#c9d3e6\", \"#5a6b8c\", \"#141b2b\"],\n    background: \"#030407\",\n    speed: 2,\n    loopSeconds: 8,\n    warp: 0.3,\n    seed: 5,\n  },\n  mercury: {\n    kind: \"chrome\",\n    colors: [\"#8c929c\", \"#ffffff\", \"#4a5060\"],\n    background: \"#040506\",\n    speed: 0.2,\n    loopSeconds: 30,\n    scale: 0.6,\n    warp: 0.9,\n    seed: 30,\n  },\n  nightfold: {\n    kind: \"mist\",\n    colors: [\"#f1dcff\", \"#a77bff\", \"#3d2aa6\", \"#120d33\"],\n    background: \"#040309\",\n    speed: 0.9,\n    loopSeconds: 16,\n    scale: 0.8,\n    warp: 0.4,\n    blur: 0.7,\n  },\n  nova: {\n    kind: \"beam\",\n    colors: [\"#fffaf2\", \"#ffd07a\", \"#ff6a3d\", \"#3a0a1a\"],\n    background: \"#050203\",\n    speed: 1.6,\n    loopSeconds: 12,\n    scale: 0.7,\n    warp: 0.65,\n    seed: 14,\n  },\n  \"paper-crease\": {\n    kind: \"mist\",\n    colors: [\"#6e8dff\", \"#a9b9ff\", \"#d9defa\", \"#1a1f4a\"],\n    background: \"#eeece8\",\n    speed: 0.8,\n    loopSeconds: 14,\n    scale: 0.8,\n    warp: 0.4,\n    blur: 0.65,\n    grain: 0.3,\n    seed: 4,\n  },\n  \"petal-arc\": {\n    kind: \"spectrum\",\n    colors: [\"#8a3cff\", \"#ff4fb8\", \"#2fd8d0\"],\n    background: \"#050208\",\n    warp: 0.6,\n    blur: 0.55,\n    seed: 9,\n  },\n  polar: {\n    kind: \"aurora\",\n    colors: [\"#dcffee\", \"#43d9a8\", \"#12685d\", \"#0a1d30\"],\n    background: \"#010307\",\n    loopSeconds: 16,\n    scale: 0.7,\n    warp: 0.45,\n    blur: 0.45,\n    grain: 0.16,\n  },\n  projector: { kind: \"beam\", speed: 0.91, loopSeconds: 12, seed: 3 },\n  refraction: { kind: \"spectrum\", speed: 0.38 },\n  riptide: {\n    kind: \"mist\",\n    colors: [\"#e6fffb\", \"#43e0cf\", \"#0b6f74\", \"#032224\"],\n    background: \"#020607\",\n    speed: 0.7,\n    loopSeconds: 16,\n    scale: 0.9,\n    warp: 0.6,\n    blur: 0.6,\n    grain: 0.4,\n    seed: 43,\n  },\n  \"solar-wind\": {\n    kind: \"aurora\",\n    colors: [\"#ffe2f2\", \"#e879c9\", \"#5b309b\", \"#120a2a\"],\n    background: \"#040208\",\n    speed: 0.71,\n    loopSeconds: 16,\n    scale: 0.7,\n    warp: 0.55,\n    blur: 0.45,\n    grain: 0.16,\n    seed: 17,\n  },\n  solstice: {\n    kind: \"halo\",\n    colors: [\"#fff6dc\", \"#ffc85a\", \"#e0782a\", \"#5a2410\"],\n    background: \"#050302\",\n    speed: 1.75,\n    loopSeconds: 13,\n    scale: 2.2,\n    warp: 0.5,\n    seed: 25,\n  },\n  \"spectral-sea\": {\n    kind: \"grain\",\n    colors: [\"#c8f5ec\", \"#33b5b5\", \"#0a5f94\", \"#132a5a\"],\n    background: \"#00060c\",\n    speed: 1.28,\n    loopSeconds: 11,\n    scale: 0.9,\n    warp: 0.6,\n    blur: 0.7,\n    grain: 0.6,\n    seed: 88,\n  },\n  spotlight: {\n    kind: \"beam\",\n    colors: [\"#ffffff\", \"#b7c3d9\", \"#3a4766\"],\n    background: \"#04040a\",\n    speed: 1.12,\n    loopSeconds: 12,\n    warp: 0.55,\n    seed: 29,\n  },\n  \"static-sunset\": {\n    kind: \"grain\",\n    colors: [\"#ffd9a8\", \"#f58c3d\", \"#d23e4c\", \"#6a1f6e\"],\n    background: \"#0a0510\",\n    speed: 1.06,\n    loopSeconds: 12,\n    scale: 0.9,\n    warp: 0.6,\n    blur: 0.7,\n    grain: 0.6,\n  },\n  \"velvet-hour\": { kind: \"silk\", loopSeconds: 28, seed: 7 },\n};\n\nexport const GSH_LIGHT_PRESETS: GshPresetId[] = [\"glasswork\", \"paper-crease\"];\n",
      "type": "registry:lib",
      "target": "lib/remocn/gsh/presets.ts"
    }
  ],
  "type": "registry:lib"
}
