{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "glass-toggle",
  "title": "Glass Toggle",
  "description": "An on/off switch with a thumb of thick frosted glass. Flip it and the thumb springs across, a pixel moon scatters and reassembles as a pixel sun, and a rim light runs round the glass from cool lilac to warm amber.",
  "dependencies": [
    "@rexa-developer/tiks",
    "motion",
    "web-haptics"
  ],
  "files": [
    {
      "path": "src/registry/components/glass-toggle/glass-toggle.tsx",
      "content": "\"use client\";\n\nimport { useTiks } from \"@rexa-developer/tiks/react\";\nimport {\n\ttype AnimationPlaybackControls,\n\tanimate,\n\tcancelFrame,\n\tframe,\n\tuseMotionValue,\n\tuseReducedMotion,\n\tuseSpring,\n} from \"motion/react\";\nimport {\n\ttype ComponentProps,\n\ttype CSSProperties,\n\ttype KeyboardEvent,\n\ttype PointerEvent,\n\tuseCallback,\n\tuseEffect,\n\tuseId,\n\tuseLayoutEffect,\n\tuseReducer,\n\tuseRef,\n\tuseState,\n} from \"react\";\nimport { useWebHaptics } from \"web-haptics/react\";\nimport { cn } from \"@/lib/utils\";\n\n// Layout, in px at `md`. Every length is drawn off one CSS unit, so `sm` is\n// the same switch scaled down and nothing is tuned twice.\nconst TRACK_WIDTH = 84;\nconst TRACK_HEIGHT = 44;\nconst TRACK_RADIUS = 14;\n/** Gap between the thumb and the track, all round. */\nconst INSET = 3;\nconst THUMB_WIDTH = 40;\nconst THUMB_HEIGHT = 38;\n/** Concentric with the track: track radius = thumb radius + inset. */\nconst THUMB_RADIUS = TRACK_RADIUS - INSET;\nconst TRAVEL = TRACK_WIDTH - INSET * 2 - THUMB_WIDTH;\n/** `sm` draws the 44 px tall track 34 px tall. */\nconst SIZE_SCALE = { sm: 34 / TRACK_HEIGHT, md: 1 } as const;\n\n// Motion. Progress runs from 0 (off) to 1 (on) and drives everything.\nconst thumbSpring = { type: \"spring\", stiffness: 560, damping: 32 } as const;\n/**\n * The rim light follows the thumb on a looser spring, so it lands about 100 ms\n * after it. Damped so it overshoots by under half a pixel and never visibly\n * runs backwards.\n */\nconst rimSpring = { stiffness: 300, damping: 30 } as const;\n/** Furthest the thumb is drawn past either end, in px. */\nconst MAX_OVERSHOOT = 2;\n/** Furthest a drag rubber-bands past either end, in px. */\nconst MAX_BAND = 2;\n/** Pointer travel, in px, before a press becomes a drag. */\nconst DRAG_SLOP = 3;\n/** Release speed, in px/s, that flips the switch whatever its position. */\nconst FLICK_SPEED = 300;\n/** Cuts the bevel band out of the glass as a ring just inside its edge. */\nconst BEVEL_MASK = {\n\tmaskImage: \"linear-gradient(#000 0 0), linear-gradient(#000 0 0)\",\n\tmaskClip: \"content-box, border-box\",\n\tmaskComposite: \"exclude\",\n} satisfies CSSProperties;\n/** Ms of pointer samples used for the release speed. */\nconst VELOCITY_WINDOW = 100;\n/** Thumb speed, in px/s, that gets the full squash and pixel lag. */\nconst FULL_SPEED = 420;\n/** Width the thumb stretches to at full speed; it loses 0.4 of that in height. */\nconst MAX_STRETCH = 0.07;\n/** Furthest the pixels trail the thumb, in px. */\nconst MAX_LAG = 2;\n/** Light level at rest, as a share of the hover level. */\nconst REST_GLOW = 0.7;\n/** The bloom when off, as a share of the bloom when on. */\nconst OFF_BLOOM = 0.6;\n/** Peak of the bloom's warm-up pulse when the thumb lands. */\nconst PULSE_PEAK = 1.3;\nconst PULSE_DURATION = 0.5;\n\n// The rim light: a line that floats a hairline outside the thumb.\nconst RIM_OFFSET = 1.5;\nconst RIM_RADIUS = THUMB_RADIUS + RIM_OFFSET;\nconst RIM_LEFT = -RIM_OFFSET;\nconst RIM_TOP = -RIM_OFFSET;\nconst RIM_RIGHT = THUMB_WIDTH + RIM_OFFSET;\nconst RIM_BOTTOM = THUMB_HEIGHT + RIM_OFFSET;\nconst RIM_FLAT_X = RIM_RIGHT - RIM_LEFT - RIM_RADIUS * 2;\nconst RIM_FLAT_Y = RIM_BOTTOM - RIM_TOP - RIM_RADIUS * 2;\nconst RIM_CORNER = (Math.PI * RIM_RADIUS) / 2;\nconst RIM_PERIMETER = (RIM_FLAT_X + RIM_FLAT_Y) * 2 + RIM_CORNER * 4;\n/**\n * The outline, counterclockwise on screen from the bottom-left end of the\n * bottom edge: along the bottom, up the right, back along the top, and down\n * the left. A flip moves the light half a lap along it, always forward.\n */\nconst RIM_PATH = [\n\t`M${RIM_LEFT + RIM_RADIUS} ${RIM_BOTTOM}`,\n\t`H${RIM_RIGHT - RIM_RADIUS}`,\n\t`A${RIM_RADIUS} ${RIM_RADIUS} 0 0 0 ${RIM_RIGHT} ${RIM_BOTTOM - RIM_RADIUS}`,\n\t`V${RIM_TOP + RIM_RADIUS}`,\n\t`A${RIM_RADIUS} ${RIM_RADIUS} 0 0 0 ${RIM_RIGHT - RIM_RADIUS} ${RIM_TOP}`,\n\t`H${RIM_LEFT + RIM_RADIUS}`,\n\t`A${RIM_RADIUS} ${RIM_RADIUS} 0 0 0 ${RIM_LEFT} ${RIM_TOP + RIM_RADIUS}`,\n\t`V${RIM_BOTTOM - RIM_RADIUS}`,\n\t`A${RIM_RADIUS} ${RIM_RADIUS} 0 0 0 ${RIM_LEFT + RIM_RADIUS} ${RIM_BOTTOM}Z`,\n].join(\"\");\n/**\n * Where the light rests when off, as a share of the outline: on the bottom\n * edge, 30% in from the left. On rests half a lap on, on the top edge 70% in.\n */\nconst RIM_OFF_AT =\n\t(THUMB_WIDTH * 0.3 - (RIM_LEFT + RIM_RADIUS)) / RIM_PERIMETER;\n/** Length of the light, as a share of the outline, at rest and lit. */\nconst ARC_REST = 0.36;\nconst ARC_LIT = 0.42;\n/**\n * The line is stacked strokes, each shorter and wider than the last, so its\n * ends taper over their last 15%.\n */\nconst RIM_LINE = [0.4, 0.6, 0.8, 1, 1.15, 1.25].map((width, index, all) => ({\n\tshare: 1 - (0.3 * index) / (all.length - 1),\n\twidth,\n}));\n/** The white-hot core, shorter than the line so it fades in from the tips. */\nconst RIM_CORE_SHARE = 0.62;\n\n// Glyphs: two bitmaps on the same 13 × 13 grid with the same number of cells,\n// so every moon pixel has a sun pixel to fly to. `#` is lit, `+` a twinkle,\n// `:` a dimmer dither pixel, and `,` an unlit one that only pads the count.\nconst MOON = [\n\t\".......+.....\",\n\t\"..........#..\",\n\t\".........###.\",\n\t\"...##.:.:.#..\",\n\t\"..##.:.:.....\",\n\t\".###:.:.:...+\",\n\t\".###.:.:.:...\",\n\t\".####.:.:....\",\n\t\".####:.:.:...\",\n\t\".######.:....\",\n\t\"..#######....\",\n\t\"...#####...+.\",\n\t\".............\",\n];\nconst SUN = [\n\t\".............\",\n\t\".#.....#....#\",\n\t\"..#.,..#.,.#.\",\n\t\".............\",\n\t\"..,.:####:.,.\",\n\t\"....######...\",\n\t\".##.######...\",\n\t\"....######.##\",\n\t\"....######...\",\n\t\"..,.:####:.,.\",\n\t\".............\",\n\t\"..#.,.#..,.#.\",\n\t\".#....#.....#\",\n];\nconst CELL_OPACITY: Record<string, number> = {\n\t\"#\": 1,\n\t\"+\": 0.7,\n\t\":\": 0.35,\n\t\",\": 0,\n};\n/** Distance between pixel centers, in px. */\nconst PIXEL_PITCH = 1.5;\nconst PIXEL_SIZE = 1.1;\n/** How far the pixels fly apart mid-flip, in px. */\nconst SCATTER_MIN = 2;\nconst SCATTER_MAX = 6.5;\n\n// A fingernail on a thick tumbler: a bright tick of band-passed noise over a\n// short, faint ring. On is a touch higher and brighter than off.\nconst TAP_ON_SOUND = {\n\tname: \"glass-toggle-tap-on\",\n\tbaseFreq: 880,\n\tnoiseColor: \"white\",\n\toscType: \"sine\",\n\tfilterFreq: 6400,\n\tfilterQ: 3,\n\tattack: 0.001,\n\tdecay: 0.7,\n\tbrightness: 6000,\n} as const;\nconst TAP_OFF_SOUND = {\n\t...TAP_ON_SOUND,\n\tname: \"glass-toggle-tap-off\",\n\tfilterFreq: 5200,\n\tdecay: 0.6,\n} as const;\n/** A narrow band of noise rings like struck glass, about 12 dB under the tap. */\nconst RING_ON_SOUND = {\n\tname: \"glass-toggle-ring-on\",\n\tbaseFreq: 880,\n\tnoiseColor: \"white\",\n\toscType: \"sine\",\n\tfilterFreq: 3150,\n\tfilterQ: 22,\n\tattack: 0.002,\n\tdecay: 5,\n\tbrightness: 6000,\n} as const;\nconst RING_OFF_SOUND = {\n\t...RING_ON_SOUND,\n\tname: \"glass-toggle-ring-off\",\n\tfilterFreq: 2650,\n\tdecay: 4.2,\n} as const;\n\ninterface Pixel {\n\tfromX: number;\n\tfromY: number;\n\ttoX: number;\n\ttoY: number;\n\tfromOpacity: number;\n\ttoOpacity: number;\n\tscatterX: number;\n\tscatterY: number;\n\t/** How much this pixel trails the thumb, from 0.55 to 1. */\n\tmass: number;\n\t/** Dither and twinkle pixels fade out as they travel. */\n\tfaint: boolean;\n}\n\ninterface Cell {\n\tx: number;\n\ty: number;\n\topacity: number;\n}\n\n/** Reads a bitmap into cells, in px from its center. */\nfunction readGlyph(rows: string[]) {\n\tconst cells: Cell[] = [];\n\tlet minX = Number.POSITIVE_INFINITY;\n\tlet maxX = Number.NEGATIVE_INFINITY;\n\tlet minY = Number.POSITIVE_INFINITY;\n\tlet maxY = Number.NEGATIVE_INFINITY;\n\trows.forEach((row, y) => {\n\t\t[...row].forEach((char, x) => {\n\t\t\tconst opacity = CELL_OPACITY[char];\n\t\t\tif (opacity === undefined) return;\n\t\t\tcells.push({ x, y, opacity });\n\t\t\tminX = Math.min(minX, x);\n\t\t\tmaxX = Math.max(maxX, x);\n\t\t\tminY = Math.min(minY, y);\n\t\t\tmaxY = Math.max(maxY, y);\n\t\t});\n\t});\n\tconst centerX = (minX + maxX) / 2;\n\tconst centerY = (minY + maxY) / 2;\n\treturn cells\n\t\t.map((cell) => ({\n\t\t\tx: (cell.x - centerX) * PIXEL_PITCH,\n\t\t\ty: (cell.y - centerY) * PIXEL_PITCH,\n\t\t\topacity: cell.opacity,\n\t\t}))\n\t\t.sort((a, b) => Math.atan2(a.y, a.x) - Math.atan2(b.y, b.x));\n}\n\n/** A seeded random number in [0, 1), the same on the server and the client. */\nfunction seeded(seed: number) {\n\tlet t = (seed * 0x9e3779b9 + 0x6d2b79f5) | 0;\n\tt = Math.imul(t ^ (t >>> 15), t | 1);\n\tt ^= t + Math.imul(t ^ (t >>> 7), t | 61);\n\treturn ((t ^ (t >>> 14)) >>> 0) / 4294967296;\n}\n\n/**\n * Pairs moon and sun pixels by their angle round the center, turning the sun\n * to whichever offset keeps the paths shortest, so they don't cross wildly.\n */\nfunction pairPixels(): Pixel[] {\n\tconst moon = readGlyph(MOON);\n\tconst sun = readGlyph(SUN);\n\tconst count = moon.length;\n\tlet bestShift = 0;\n\tlet bestCost = Number.POSITIVE_INFINITY;\n\tfor (let shift = 0; shift < count; shift++) {\n\t\tlet cost = 0;\n\t\tfor (let index = 0; index < count; index++) {\n\t\t\tconst to = sun[(index + shift) % count];\n\t\t\tcost += (moon[index].x - to.x) ** 2 + (moon[index].y - to.y) ** 2;\n\t\t}\n\t\tif (cost < bestCost) {\n\t\t\tbestCost = cost;\n\t\t\tbestShift = shift;\n\t\t}\n\t}\n\treturn moon.map((from, index) => {\n\t\tconst to = sun[(index + bestShift) % count];\n\t\tconst angle =\n\t\t\tMath.atan2(from.y + to.y, from.x + to.x) +\n\t\t\t(seeded(index * 3 + 1) - 0.5) * 1.8;\n\t\tconst distance =\n\t\t\tSCATTER_MIN + seeded(index * 3 + 2) * (SCATTER_MAX - SCATTER_MIN);\n\t\treturn {\n\t\t\tfromX: from.x,\n\t\t\tfromY: from.y,\n\t\t\ttoX: to.x,\n\t\t\ttoY: to.y,\n\t\t\tfromOpacity: from.opacity,\n\t\t\ttoOpacity: to.opacity,\n\t\t\tscatterX: Math.cos(angle) * distance,\n\t\t\tscatterY: Math.sin(angle) * distance,\n\t\t\tmass: 0.55 + seeded(index * 3 + 3) * 0.45,\n\t\t\tfaint: from.opacity < 1 || to.opacity < 1,\n\t\t};\n\t});\n}\n\nconst PIXELS = pairPixels();\n\nfunction clamp(value: number, min: number, max: number) {\n\treturn Math.min(Math.max(value, min), max);\n}\n\nfunction round(value: number) {\n\treturn Math.round(value * 1000) / 1000;\n}\n\n/** Eases `over` toward `limit`, never reaching it. */\nfunction band(over: number, limit: number) {\n\treturn (over * limit) / (over + limit);\n}\n\nfunction smoothstep(t: number) {\n\treturn t * t * (3 - 2 * t);\n}\n\n/** A length in px at `md`, scaled with the size. */\nfunction u(px: number) {\n\treturn `calc(var(--gt-u) * ${px})`;\n}\n\n/** Where a pixel sits, and how bright it is, at `progress`. */\nfunction pixelAt(pixel: Pixel, progress: number, lag: number) {\n\tconst t = smoothstep(progress);\n\tconst spread = Math.sin(Math.PI * progress);\n\tconst opacity =\n\t\t(pixel.fromOpacity + (pixel.toOpacity - pixel.fromOpacity) * t) *\n\t\t(1 - (pixel.faint ? 0.65 : 0.15) * spread);\n\treturn {\n\t\tx: round(\n\t\t\tTHUMB_WIDTH / 2 +\n\t\t\t\tpixel.fromX +\n\t\t\t\t(pixel.toX - pixel.fromX) * t +\n\t\t\t\tpixel.scatterX * spread +\n\t\t\t\tlag * pixel.mass -\n\t\t\t\tPIXEL_SIZE / 2,\n\t\t),\n\t\ty: round(\n\t\t\tTHUMB_HEIGHT / 2 +\n\t\t\t\tpixel.fromY +\n\t\t\t\t(pixel.toY - pixel.fromY) * t +\n\t\t\t\tpixel.scatterY * spread -\n\t\t\t\tPIXEL_SIZE / 2,\n\t\t),\n\t\topacity: round(opacity),\n\t};\n}\n\n/** A point on the rim's outline, `at` a share of the way round it. */\nfunction rimPoint(at: number) {\n\tlet along = (((at % 1) + 1) % 1) * RIM_PERIMETER;\n\tconst corner = (cx: number, cy: number, from: number) => {\n\t\tconst angle = from - (along / RIM_CORNER) * (Math.PI / 2);\n\t\treturn {\n\t\t\tx: cx + Math.cos(angle) * RIM_RADIUS,\n\t\t\ty: cy + Math.sin(angle) * RIM_RADIUS,\n\t\t};\n\t};\n\tconst runs = [\n\t\tRIM_FLAT_X,\n\t\tRIM_CORNER,\n\t\tRIM_FLAT_Y,\n\t\tRIM_CORNER,\n\t\tRIM_FLAT_X,\n\t\tRIM_CORNER,\n\t\tRIM_FLAT_Y,\n\t\tRIM_CORNER,\n\t];\n\tlet run = 0;\n\twhile (run < runs.length - 1 && along > runs[run]) {\n\t\talong -= runs[run];\n\t\trun++;\n\t}\n\tswitch (run) {\n\t\tcase 0:\n\t\t\treturn { x: RIM_LEFT + RIM_RADIUS + along, y: RIM_BOTTOM };\n\t\tcase 1:\n\t\t\treturn corner(\n\t\t\t\tRIM_RIGHT - RIM_RADIUS,\n\t\t\t\tRIM_BOTTOM - RIM_RADIUS,\n\t\t\t\tMath.PI / 2,\n\t\t\t);\n\t\tcase 2:\n\t\t\treturn { x: RIM_RIGHT, y: RIM_BOTTOM - RIM_RADIUS - along };\n\t\tcase 3:\n\t\t\treturn corner(RIM_RIGHT - RIM_RADIUS, RIM_TOP + RIM_RADIUS, 0);\n\t\tcase 4:\n\t\t\treturn { x: RIM_RIGHT - RIM_RADIUS - along, y: RIM_TOP };\n\t\tcase 5:\n\t\t\treturn corner(RIM_LEFT + RIM_RADIUS, RIM_TOP + RIM_RADIUS, -Math.PI / 2);\n\t\tcase 6:\n\t\t\treturn { x: RIM_LEFT, y: RIM_TOP + RIM_RADIUS + along };\n\t\tdefault:\n\t\t\treturn corner(RIM_LEFT + RIM_RADIUS, RIM_BOTTOM - RIM_RADIUS, Math.PI);\n\t}\n}\n\n/** Dash for a stroke `length` long centered `at` a share of the outline. */\nfunction rimDash(at: number, length: number) {\n\treturn {\n\t\tarray: `${round(length)} ${round(1 - length)}`,\n\t\toffset: String(round(length / 2 - at)),\n\t};\n}\n\n/**\n * Where the light sits for a half-lap count `lap`: even counts rest off, odd\n * counts rest on, and the count only ever grows between flips.\n */\nfunction rimAt(lap: number) {\n\treturn RIM_OFF_AT + (((lap % 2) + 2) % 2) / 2;\n}\n\n/** The CSS variables that carry the state to the static layers. */\nfunction stateVars(progress: number, lap: number, glow: number, pulse: number) {\n\tconst lit = clamp(progress, 0, 1);\n\tconst wash = rimPoint(rimAt(lap));\n\treturn {\n\t\t\"--gt-mix\": `${round(lit * 100)}%`,\n\t\t\"--gt-lit\": String(round(lit)),\n\t\t\"--gt-off-amount\": String(round(Math.min(1, 2 * (1 - lit)))),\n\t\t\"--gt-on-amount\": String(round(Math.min(1, 2 * lit))),\n\t\t\"--gt-glow\": String(round(glow)),\n\t\t\"--gt-bloom\": String(\n\t\t\tround(((OFF_BLOOM + (1 - OFF_BLOOM) * lit) * glow * pulse) / PULSE_PEAK),\n\t\t),\n\t\t\"--gt-x\": String(\n\t\t\tround(\n\t\t\t\tclamp(progress, -MAX_OVERSHOOT / TRAVEL, 1 + MAX_OVERSHOOT / TRAVEL) *\n\t\t\t\t\tTRAVEL,\n\t\t\t),\n\t\t),\n\t\t\"--gt-wash-x\": `${round((wash.x / THUMB_WIDTH) * 100)}%`,\n\t\t\"--gt-wash-y\": `${round((wash.y / THUMB_HEIGHT) * 100)}%`,\n\t};\n}\n\nfunction arcLength(glow: number) {\n\treturn (\n\t\tARC_REST + ((ARC_LIT - ARC_REST) * (glow - REST_GLOW)) / (1 - REST_GLOW)\n\t);\n}\n\nexport interface GlassToggleProps\n\textends Omit<\n\t\tComponentProps<\"div\">,\n\t\t\"children\" | \"defaultChecked\" | \"onChange\" | \"ref\"\n\t> {\n\t/** Controlled on/off state. */\n\tchecked?: boolean;\n\t/** Initial state when uncontrolled. */\n\tdefaultChecked?: boolean;\n\t/** Called when a click, key press, or drag flips the switch. */\n\tonCheckedChange?: (checked: boolean) => void;\n\t/** Accessible name of the switch. Ignored when `aria-label` or `aria-labelledby` is set. */\n\tlabel?: string;\n\tdisabled?: boolean;\n\t/** Submits `\"on\"` or `\"off\"` with a native form through a hidden input. */\n\tname?: string;\n\t/** `sm` is the same switch drawn at about three quarters of the size. */\n\tsize?: \"sm\" | \"md\";\n\t/** Play a glass tap when the switch flips. */\n\tsound?: boolean;\n\t/** Trigger haptics on supported devices. */\n\thaptics?: boolean;\n}\n\nexport function GlassToggle({\n\tchecked: checkedProp,\n\tdefaultChecked = false,\n\tonCheckedChange,\n\tlabel = \"Toggle\",\n\tdisabled = false,\n\tname,\n\tsize = \"md\",\n\tsound = true,\n\thaptics = true,\n\tclassName,\n\tstyle,\n\t\"aria-label\": ariaLabel,\n\t\"aria-labelledby\": ariaLabelledBy,\n\t\"aria-describedby\": ariaDescribedBy,\n\t...props\n}: GlassToggleProps) {\n\tconst [internalChecked, setInternalChecked] = useState(defaultChecked);\n\tconst controlled = checkedProp !== undefined;\n\tconst checked = controlled ? checkedProp : internalChecked;\n\tconst [pressed, setPressed] = useState(false);\n\tconst [hovered, setHovered] = useState(false);\n\tconst [dragging, setDragging] = useState(false);\n\tconst [, rerender] = useReducer((count: number) => count + 1, 0);\n\t// The first paint, rendered on the server too. Later frames are written\n\t// straight to the DOM, so React never re-renders while the switch moves.\n\tconst [initial] = useState(() => {\n\t\tconst progress = checked ? 1 : 0;\n\t\tconst lap = progress;\n\t\treturn {\n\t\t\tprogress,\n\t\t\tlap,\n\t\t\tvars: stateVars(progress, lap, REST_GLOW, 1),\n\t\t\tpixels: PIXELS.map((pixel) => pixelAt(pixel, progress, 0)),\n\t\t};\n\t});\n\n\tconst reducedMotion = useReducedMotion() ?? false;\n\tconst { trigger: haptic } = useWebHaptics();\n\t// Sound stays on under reduced motion; only movement is reduced.\n\tconst { click: playTap, setTheme: setTapSound } = useTiks({\n\t\ttheme: TAP_ON_SOUND,\n\t\trespectReducedMotion: false,\n\t});\n\tconst { click: playRing, setTheme: setRingSound } = useTiks({\n\t\ttheme: RING_ON_SOUND,\n\t\trespectReducedMotion: false,\n\t});\n\n\tconst ids = useId().replace(/[^\\w-]/g, \"\");\n\tconst filterId = (part: string) => `glass-toggle-${ids}-${part}`;\n\n\tconst progress = useMotionValue(initial.progress);\n\tconst rimTarget = useMotionValue(initial.lap);\n\tconst rim = useSpring(rimTarget, rimSpring);\n\tconst glow = useMotionValue(REST_GLOW);\n\tconst pulse = useMotionValue(1);\n\tconst sheenX = useSpring(0, { stiffness: 170, damping: 26 });\n\tconst sheenY = useSpring(0, { stiffness: 170, damping: 26 });\n\n\tconst rootRef = useRef<HTMLDivElement>(null);\n\tconst thumbRef = useRef<HTMLSpanElement>(null);\n\tconst squashRef = useRef<HTMLSpanElement>(null);\n\tconst pixelRefs = useRef<Array<SVGRectElement | null>>([]);\n\tconst rimRefs = useRef<Array<{ element: SVGPathElement; share: number }>>([]);\n\tconst animationRef = useRef<AnimationPlaybackControls | null>(null);\n\tconst pulseRef = useRef<AnimationPlaybackControls | null>(null);\n\t/** Where the thumb is heading: the state it last flipped to. */\n\tconst targetRef = useRef(checked);\n\t/**\n\t * The half lap the light is on: `base` counts finished half laps, and\n\t * `from` is the state the current one started from.\n\t */\n\tconst lapRef = useRef({ base: initial.lap, from: checked });\n\tconst paintedRef = useRef({ lit: initial.progress, lag: 0 });\n\tconst dragVelocityRef = useRef(0);\n\tconst stillTimerRef = useRef<ReturnType<typeof setTimeout> | undefined>(\n\t\tundefined,\n\t);\n\tconst suppressClickRef = useRef(false);\n\tconst dragRef = useRef<{\n\t\tpointerId: number;\n\t\toriginX: number;\n\t\toriginY: number;\n\t\tstart: number;\n\t\t/** Md px per screen px, so zoom, transforms, and `sm` all work. */\n\t\tscale: number;\n\t\tmoved: boolean;\n\t\tsamples: Array<{ time: number; x: number }>;\n\t} | null>(null);\n\n\t// Event handlers and the render loop read the latest props through refs.\n\tconst latest = useRef({\n\t\tchecked,\n\t\tcontrolled,\n\t\tonCheckedChange,\n\t\tsound,\n\t\thaptics,\n\t\treducedMotion,\n\t});\n\tuseLayoutEffect(() => {\n\t\tlatest.current = {\n\t\t\tchecked,\n\t\t\tcontrolled,\n\t\t\tonCheckedChange,\n\t\t\tsound,\n\t\t\thaptics,\n\t\t\treducedMotion,\n\t\t};\n\t});\n\n\tconst paint = () => {\n\t\tconst root = rootRef.current;\n\t\tif (!root) return;\n\t\tconst value = progress.get();\n\t\tconst lit = clamp(value, 0, 1);\n\t\tconst moving = dragRef.current?.moved ?? false;\n\t\tconst reduced = latest.current.reducedMotion;\n\t\tconst lap = reduced ? rimTarget.get() : rim.get();\n\t\tconst level = glow.get();\n\n\t\tconst vars = stateVars(value, lap, level, pulse.get());\n\t\tfor (const key in vars) {\n\t\t\troot.style.setProperty(key, vars[key as keyof typeof vars]);\n\t\t}\n\t\troot.style.setProperty(\"--gt-sx\", `${round(sheenX.get())}%`);\n\t\troot.style.setProperty(\"--gt-sy\", `${round(sheenY.get())}%`);\n\n\t\t// Squash and stretch from speed, anchored on the trailing edge.\n\t\tconst speed = moving\n\t\t\t? dragVelocityRef.current\n\t\t\t: progress.getVelocity() * TRAVEL;\n\t\tconst pace = reduced ? 0 : clamp(speed / FULL_SPEED, -1, 1);\n\t\tconst stretch = MAX_STRETCH * Math.abs(pace);\n\t\tconst thumb = thumbRef.current;\n\t\tconst squash = squashRef.current;\n\t\tif (thumb)\n\t\t\tthumb.style.transform = `translateX(${u(Number(vars[\"--gt-x\"]))})`;\n\t\tif (squash) {\n\t\t\tsquash.style.transform = stretch\n\t\t\t\t? `scale(${round(1 + stretch)}, ${round(1 - stretch * 0.4)})`\n\t\t\t\t: \"\";\n\t\t\tsquash.style.transformOrigin = pace < 0 ? \"100% 50%\" : \"0% 50%\";\n\t\t}\n\n\t\tconst at = rimAt(lap);\n\t\tconst length = arcLength(level);\n\t\tfor (const { element, share } of rimRefs.current) {\n\t\t\tconst dash = rimDash(at, length * share);\n\t\t\telement.setAttribute(\"stroke-dasharray\", dash.array);\n\t\t\telement.setAttribute(\"stroke-dashoffset\", dash.offset);\n\t\t}\n\n\t\t// The pixels only move when the thumb does.\n\t\tconst lag = round(-pace * MAX_LAG);\n\t\tconst painted = paintedRef.current;\n\t\tif (painted.lit !== lit || painted.lag !== lag) {\n\t\t\tpainted.lit = lit;\n\t\t\tpainted.lag = lag;\n\t\t\tconst morph = reduced ? Math.round(lit) : lit;\n\t\t\tPIXELS.forEach((pixel, index) => {\n\t\t\t\tconst rect = pixelRefs.current[index];\n\t\t\t\tif (!rect) return;\n\t\t\t\tconst next = pixelAt(pixel, morph, reduced ? 0 : lag);\n\t\t\t\trect.setAttribute(\"x\", String(next.x));\n\t\t\t\trect.setAttribute(\"y\", String(next.y));\n\t\t\t\trect.setAttribute(\"opacity\", String(next.opacity));\n\t\t\t});\n\t\t}\n\n\t\tconst idle =\n\t\t\t!moving &&\n\t\t\t!progress.isAnimating() &&\n\t\t\t(reduced || !rim.isAnimating()) &&\n\t\t\t!stretch;\n\t\tif (thumb) thumb.style.willChange = idle ? \"\" : \"transform\";\n\t};\n\n\t// One render per frame, however many values changed in it.\n\tconst paintRef = useRef(paint);\n\tuseLayoutEffect(() => {\n\t\tpaintRef.current = paint;\n\t});\n\tconst scheduledRef = useRef(false);\n\tconst renderRef = useRef(() => {\n\t\tscheduledRef.current = false;\n\t\tpaintRef.current();\n\t});\n\tconst schedule = useCallback(() => {\n\t\tif (scheduledRef.current) return;\n\t\tscheduledRef.current = true;\n\t\tframe.render(renderRef.current);\n\t}, []);\n\n\t/** Warms the bloom up past its rest level and lets it settle. */\n\tconst warm = () => {\n\t\tif (latest.current.reducedMotion) return;\n\t\tpulseRef.current?.stop();\n\t\tpulseRef.current = animate(pulse, [pulse.get(), PULSE_PEAK, 1], {\n\t\t\tduration: PULSE_DURATION,\n\t\t\ttimes: [0, 0.16, 1],\n\t\t\tease: [\"easeOut\", \"easeInOut\"],\n\t\t});\n\t};\n\n\t/**\n\t * Moves the light along its half lap. When the thumb lands on the far end\n\t * of a flip, the lap is finished and the next flip carries on forward.\n\t */\n\tconst followThumb = (value: number) => {\n\t\tconst lap = lapRef.current;\n\t\tconst heading = targetRef.current;\n\t\tconst dragged = dragRef.current?.moved ?? false;\n\t\tif (\n\t\t\t!dragged &&\n\t\t\theading !== lap.from &&\n\t\t\t(heading ? value >= 1 : value <= 0)\n\t\t) {\n\t\t\tlap.base += 1;\n\t\t\tlap.from = heading;\n\t\t\twarm();\n\t\t}\n\t\tconst lit = clamp(value, 0, 1);\n\t\tconst next = lap.base + (lap.from ? 1 - lit : lit);\n\t\tif (latest.current.reducedMotion) rim.jump(next);\n\t\trimTarget.set(next);\n\t};\n\n\tconst followRef = useRef(followThumb);\n\tuseLayoutEffect(() => {\n\t\tfollowRef.current = followThumb;\n\t});\n\n\tuseEffect(() => {\n\t\tconst repaint = () => schedule();\n\t\tconst unsubscribe = [\n\t\t\tprogress.on(\"change\", (value) => {\n\t\t\t\tfollowRef.current(value);\n\t\t\t\trepaint();\n\t\t\t}),\n\t\t\trim.on(\"change\", repaint),\n\t\t\trim.on(\"animationComplete\", repaint),\n\t\t\tglow.on(\"change\", repaint),\n\t\t\tpulse.on(\"change\", repaint),\n\t\t\tsheenX.on(\"change\", repaint),\n\t\t\tsheenY.on(\"change\", repaint),\n\t\t];\n\t\treturn () => {\n\t\t\tfor (const stop of unsubscribe) stop();\n\t\t\tcancelFrame(renderRef.current);\n\t\t\tscheduledRef.current = false;\n\t\t\tanimationRef.current?.stop();\n\t\t\tpulseRef.current?.stop();\n\t\t\tclearTimeout(stillTimerRef.current);\n\t\t};\n\t}, [glow, progress, pulse, rim, schedule, sheenX, sheenY]);\n\n\t/** Springs the thumb to `next`, carrying `velocity` in progress per second. */\n\tconst go = (next: boolean, velocity?: number) => {\n\t\ttargetRef.current = next;\n\t\tconst to = next ? 1 : 0;\n\t\tanimationRef.current?.stop();\n\t\tif (thumbRef.current) thumbRef.current.style.willChange = \"transform\";\n\t\tif (latest.current.reducedMotion) {\n\t\t\tprogress.jump(to);\n\t\t\tfollowRef.current(to);\n\t\t\treturn;\n\t\t}\n\t\tanimationRef.current = animate(progress, to, {\n\t\t\t...thumbSpring,\n\t\t\tvelocity: velocity ?? progress.getVelocity(),\n\t\t\trestDelta: 0.001,\n\t\t\trestSpeed: 0.02,\n\t\t\tonComplete: schedule,\n\t\t});\n\t\t// A thumb already at the end finishes its lap without moving.\n\t\tfollowRef.current(progress.get());\n\t};\n\n\tconst silent = () =>\n\t\ttypeof document !== \"undefined\" && document.visibilityState === \"hidden\";\n\n\t// Called only for user input, so the first render and prop changes stay quiet.\n\tconst flipTo = (next: boolean, velocity?: number) => {\n\t\tif (next !== latest.current.checked) {\n\t\t\tlatest.current.checked = next;\n\t\t\t// When controlled, re-render anyway, so a parent that keeps the old\n\t\t\t// state sends the thumb back.\n\t\t\tif (latest.current.controlled) rerender();\n\t\t\telse setInternalChecked(next);\n\t\t\tlatest.current.onCheckedChange?.(next);\n\t\t\tif (!silent()) {\n\t\t\t\tif (latest.current.sound) {\n\t\t\t\t\tsetTapSound(next ? TAP_ON_SOUND : TAP_OFF_SOUND);\n\t\t\t\t\tsetRingSound(next ? RING_ON_SOUND : RING_OFF_SOUND);\n\t\t\t\t\tplayTap();\n\t\t\t\t\tplayRing();\n\t\t\t\t}\n\t\t\t\tif (latest.current.haptics) void haptic(\"light\");\n\t\t\t}\n\t\t}\n\t\tgo(next, velocity);\n\t};\n\n\t// A parent changing `checked` moves the thumb exactly like a flip, silently.\n\tuseLayoutEffect(() => {\n\t\tif (dragRef.current?.moved || checked === targetRef.current) return;\n\t\tgo(checked);\n\t});\n\n\t// Hover and press turn the light up.\n\tuseEffect(() => {\n\t\tconst level = !disabled && (hovered || pressed) ? 1 : REST_GLOW;\n\t\tconst controls = animate(glow, level, {\n\t\t\tduration: pressed ? 0.08 : 0.2,\n\t\t\tease: \"easeOut\",\n\t\t});\n\t\treturn () => controls.stop();\n\t}, [disabled, glow, hovered, pressed]);\n\n\tconst scaleOf = () => {\n\t\tconst root = rootRef.current;\n\t\tif (!root) return 1;\n\t\treturn TRACK_WIDTH / (root.getBoundingClientRect().width || TRACK_WIDTH);\n\t};\n\n\tconst handlePointerDown = (event: PointerEvent<HTMLButtonElement>) => {\n\t\tsuppressClickRef.current = false;\n\t\tif (disabled || event.button !== 0 || dragRef.current) return;\n\t\tevent.currentTarget.setPointerCapture(event.pointerId);\n\t\tdragRef.current = {\n\t\t\tpointerId: event.pointerId,\n\t\t\toriginX: event.clientX,\n\t\t\toriginY: event.clientY,\n\t\t\tstart: progress.get(),\n\t\t\tscale: scaleOf(),\n\t\t\tmoved: false,\n\t\t\tsamples: [{ time: event.timeStamp, x: event.clientX }],\n\t\t};\n\t\tsetPressed(true);\n\t};\n\n\tconst handlePointerMove = (event: PointerEvent<HTMLButtonElement>) => {\n\t\tif (event.pointerType !== \"touch\" && !dragRef.current) {\n\t\t\t// The pointer is the light: the sheen leans a little toward it.\n\t\t\tconst thumb = thumbRef.current?.getBoundingClientRect();\n\t\t\tif (thumb?.width) {\n\t\t\t\tconst x =\n\t\t\t\t\t(event.clientX - (thumb.left + thumb.width / 2)) / thumb.width;\n\t\t\t\tconst y =\n\t\t\t\t\t(event.clientY - (thumb.top + thumb.height / 2)) / thumb.height;\n\t\t\t\tsheenX.set(clamp(x, -1, 1) * 8);\n\t\t\t\tsheenY.set(clamp(y, -1, 1) * 5);\n\t\t\t}\n\t\t}\n\t\tconst drag = dragRef.current;\n\t\tif (!drag || drag.pointerId !== event.pointerId) return;\n\t\tconst dx = event.clientX - drag.originX;\n\t\tconst dy = event.clientY - drag.originY;\n\t\tif (!drag.moved) {\n\t\t\tif (Math.abs(dx) < DRAG_SLOP || Math.abs(dx) < Math.abs(dy)) return;\n\t\t\tdrag.moved = true;\n\t\t\tanimationRef.current?.stop();\n\t\t\t// Pick the thumb up where it is, mid-flight or not.\n\t\t\tdrag.start = progress.get();\n\t\t\tdrag.originX = event.clientX;\n\t\t\tsetDragging(true);\n\t\t}\n\t\tdrag.samples.push({ time: event.timeStamp, x: event.clientX });\n\t\twhile (\n\t\t\tdrag.samples.length > 2 &&\n\t\t\tevent.timeStamp - drag.samples[0].time > VELOCITY_WINDOW\n\t\t) {\n\t\t\tdrag.samples.shift();\n\t\t}\n\t\tconst first = drag.samples[0];\n\t\tconst elapsed = (event.timeStamp - first.time) / 1000;\n\t\tdragVelocityRef.current =\n\t\t\telapsed > 0 ? ((event.clientX - first.x) * drag.scale) / elapsed : 0;\n\t\t// A held pointer has no speed, so the thumb unsquashes.\n\t\tclearTimeout(stillTimerRef.current);\n\t\tstillTimerRef.current = setTimeout(() => {\n\t\t\tdragVelocityRef.current = 0;\n\t\t\tschedule();\n\t\t}, 60);\n\n\t\tconst raw =\n\t\t\tdrag.start * TRAVEL + (event.clientX - drag.originX) * drag.scale;\n\t\tconst position =\n\t\t\traw < 0\n\t\t\t\t? -band(-raw, MAX_BAND)\n\t\t\t\t: raw > TRAVEL\n\t\t\t\t\t? TRAVEL + band(raw - TRAVEL, MAX_BAND)\n\t\t\t\t\t: raw;\n\t\tprogress.set(position / TRAVEL);\n\t};\n\n\tconst endDrag = (pointerId: number | undefined, commit: boolean) => {\n\t\tconst drag = dragRef.current;\n\t\tif (!drag || (pointerId !== undefined && drag.pointerId !== pointerId)) {\n\t\t\treturn;\n\t\t}\n\t\tdragRef.current = null;\n\t\tsetPressed(false);\n\t\tconst button = rootRef.current?.querySelector(\"button\");\n\t\tif (button?.hasPointerCapture(drag.pointerId)) {\n\t\t\tbutton.releasePointerCapture(drag.pointerId);\n\t\t}\n\t\tif (!drag.moved) return;\n\t\tsetDragging(false);\n\t\tclearTimeout(stillTimerRef.current);\n\t\t// The click that follows a drag isn't a flip, even when the drag was\n\t\t// cancelled before the pointer came up.\n\t\tsuppressClickRef.current = true;\n\n\t\tconst first = drag.samples[0];\n\t\tconst last = drag.samples[drag.samples.length - 1];\n\t\tconst elapsed = (last.time - first.time) / 1000;\n\t\tconst recent =\n\t\t\tperformance.now() - last.time < VELOCITY_WINDOW && elapsed > 0;\n\t\tconst speed = recent ? (last.x - first.x) / elapsed : 0;\n\t\tconst velocity = (speed * drag.scale) / TRAVEL;\n\t\tdragVelocityRef.current = 0;\n\t\tif (!commit) {\n\t\t\tgo(latest.current.checked, 0);\n\t\t\treturn;\n\t\t}\n\t\tconst next =\n\t\t\tMath.abs(speed) > FLICK_SPEED ? speed > 0 : progress.get() > 0.5;\n\t\tflipTo(next, velocity);\n\t};\n\n\tconst handleClick = () => {\n\t\tif (suppressClickRef.current) {\n\t\t\tsuppressClickRef.current = false;\n\t\t\treturn;\n\t\t}\n\t\tif (disabled) return;\n\t\tflipTo(!latest.current.checked);\n\t};\n\n\tconst handleKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {\n\t\tsuppressClickRef.current = false;\n\t\t// Holding a key shouldn't flicker the switch.\n\t\tif (event.repeat && (event.key === \"Enter\" || event.key === \" \")) {\n\t\t\tevent.preventDefault();\n\t\t}\n\t};\n\n\tconst handlePointerEnter = (event: PointerEvent<HTMLButtonElement>) => {\n\t\tif (event.pointerType !== \"touch\") setHovered(true);\n\t};\n\n\tconst handlePointerLeave = () => {\n\t\tsetHovered(false);\n\t\tsheenX.set(0);\n\t\tsheenY.set(0);\n\t};\n\n\t// Losing the window or the tab mid-drag lets go without flipping.\n\tconst cancelRef = useRef(() => endDrag(undefined, false));\n\tuseLayoutEffect(() => {\n\t\tcancelRef.current = () => endDrag(undefined, false);\n\t});\n\n\tuseEffect(() => {\n\t\tif (!pressed) return;\n\t\tconst cancel = () => cancelRef.current();\n\t\tconst onVisibilityChange = () => {\n\t\t\tif (document.visibilityState === \"hidden\") cancel();\n\t\t};\n\t\twindow.addEventListener(\"blur\", cancel);\n\t\tdocument.addEventListener(\"visibilitychange\", onVisibilityChange);\n\t\treturn () => {\n\t\t\twindow.removeEventListener(\"blur\", cancel);\n\t\t\tdocument.removeEventListener(\"visibilitychange\", onVisibilityChange);\n\t\t};\n\t}, [pressed]);\n\n\tuseEffect(() => {\n\t\tif (disabled) cancelRef.current();\n\t}, [disabled]);\n\n\t// iOS can still scroll the page under a captured pointer; block it mid-drag.\n\tuseEffect(() => {\n\t\tconst button = rootRef.current?.querySelector(\"button\");\n\t\tif (!button) return;\n\t\tconst onTouchMove = (event: TouchEvent) => {\n\t\t\tif (dragRef.current?.moved) event.preventDefault();\n\t\t};\n\t\tbutton.addEventListener(\"touchmove\", onTouchMove, { passive: false });\n\t\treturn () => button.removeEventListener(\"touchmove\", onTouchMove);\n\t}, []);\n\n\tconst state = checked ? \"on\" : \"off\";\n\tconst initialDash = (share: number) =>\n\t\trimDash(rimAt(initial.lap), ARC_REST * share);\n\tconst rimRef =\n\t\t(index: number, share: number) => (element: SVGPathElement | null) => {\n\t\t\tif (element) rimRefs.current[index] = { element, share };\n\t\t};\n\n\tconst rimStroke = (\n\t\tindex: number,\n\t\tshare: number,\n\t\tprops: Omit<ComponentProps<\"path\">, \"ref\">,\n\t) => {\n\t\tconst dash = initialDash(share);\n\t\treturn (\n\t\t\t<path\n\t\t\t\tkey={index}\n\t\t\t\tref={rimRef(index, share)}\n\t\t\t\td={RIM_PATH}\n\t\t\t\tpathLength={1}\n\t\t\t\tfill=\"none\"\n\t\t\t\tstrokeLinecap=\"round\"\n\t\t\t\tstrokeDasharray={dash.array}\n\t\t\t\tstrokeDashoffset={dash.offset}\n\t\t\t\t{...props}\n\t\t\t/>\n\t\t);\n\t};\n\n\treturn (\n\t\t<div\n\t\t\tref={rootRef}\n\t\t\tdata-slot=\"glass-toggle\"\n\t\t\tdata-state={state}\n\t\t\tdata-size={size}\n\t\t\tdata-pressed={pressed || undefined}\n\t\t\tdata-dragging={dragging || undefined}\n\t\t\tdata-disabled={disabled || undefined}\n\t\t\t{...props}\n\t\t\tclassName={cn(\n\t\t\t\t\"group/glass-toggle relative inline-block shrink-0 select-none align-middle data-disabled:cursor-not-allowed data-disabled:opacity-50\",\n\t\t\t\t// The light colors. Set `--glass-toggle-off` and `--glass-toggle-on`\n\t\t\t\t// on this element or any parent to retheme them.\n\t\t\t\t\"[--gt-light-off:var(--glass-toggle-off,oklch(0.72_0.14_285))] [--gt-light-on:var(--glass-toggle-on,#ffb224)] dark:[--gt-light-off:var(--glass-toggle-off,#9aa2ff)] dark:[--gt-light-on:var(--glass-toggle-on,#ffc04d)]\",\n\t\t\t\t\"[--gt-light:color-mix(in_oklab,var(--gt-light-off),var(--gt-light-on)_var(--gt-mix))]\",\n\t\t\t\t// Pixels are ink on a light surface and lit on a dark one.\n\t\t\t\t\"[--gt-ink-off:color-mix(in_oklab,var(--foreground)_88%,transparent)] [--gt-ink-on:color-mix(in_oklab,color-mix(in_oklab,var(--foreground),#8a4a0c_24%)_88%,transparent)] dark:[--gt-ink-off:#e8eaff] dark:[--gt-ink-on:#fff2dc]\",\n\t\t\t\tclassName,\n\t\t\t)}\n\t\t\tstyle={\n\t\t\t\t{\n\t\t\t\t\t\"--gt-u\": size === \"sm\" ? `calc(1px * ${SIZE_SCALE.sm})` : \"1px\",\n\t\t\t\t\t\"--gt-sx\": \"0%\",\n\t\t\t\t\t\"--gt-sy\": \"0%\",\n\t\t\t\t\t...initial.vars,\n\t\t\t\t\twidth: u(TRACK_WIDTH),\n\t\t\t\t\theight: u(TRACK_HEIGHT),\n\t\t\t\t\t...style,\n\t\t\t\t} as CSSProperties\n\t\t\t}\n\t\t>\n\t\t\t<button\n\t\t\t\ttype=\"button\"\n\t\t\t\trole=\"switch\"\n\t\t\t\taria-checked={checked}\n\t\t\t\taria-label={ariaLabelledBy ? ariaLabel : (ariaLabel ?? label)}\n\t\t\t\taria-labelledby={ariaLabelledBy}\n\t\t\t\taria-describedby={ariaDescribedBy}\n\t\t\t\tdisabled={disabled}\n\t\t\t\tdata-slot=\"glass-toggle-switch\"\n\t\t\t\tonPointerDown={handlePointerDown}\n\t\t\t\tonPointerMove={handlePointerMove}\n\t\t\t\tonPointerUp={(event) => endDrag(event.pointerId, true)}\n\t\t\t\tonPointerCancel={(event) => endDrag(event.pointerId, false)}\n\t\t\t\tonLostPointerCapture={(event) => endDrag(event.pointerId, false)}\n\t\t\t\tonPointerEnter={handlePointerEnter}\n\t\t\t\tonPointerLeave={handlePointerLeave}\n\t\t\t\tonClick={handleClick}\n\t\t\t\tonKeyDown={handleKeyDown}\n\t\t\t\tonContextMenu={(event) => event.preventDefault()}\n\t\t\t\tclassName=\"group/switch absolute inset-0 block cursor-pointer touch-pan-y outline-none [-webkit-tap-highlight-color:transparent] [-webkit-touch-callout:none] before:absolute before:inset-x-0 before:top-1/2 before:h-11 before:-translate-y-1/2 disabled:cursor-not-allowed group-data-dragging/glass-toggle:cursor-grabbing\"\n\t\t\t>\n\t\t\t\t{/* The tray: a recessed slab a step darker than the page. */}\n\t\t\t\t<span\n\t\t\t\t\taria-hidden\n\t\t\t\t\tdata-slot=\"glass-toggle-track\"\n\t\t\t\t\tclassName=\"absolute inset-0 overflow-hidden bg-[linear-gradient(to_bottom,#e9e9ec,#f1f1f3)] [--gt-tray-inset:rgb(0_0_0/0.1)] [--gt-tray-line:rgb(0_0_0/0.06)] [--gt-tray-lip:#fff] dark:bg-[linear-gradient(to_bottom,#0b0b0d,#141416)] dark:[--gt-tray-inset:rgb(0_0_0/0.7)] dark:[--gt-tray-line:rgb(255_255_255/0.05)] dark:[--gt-tray-lip:rgb(255_255_255/0.06)]\"\n\t\t\t\t\tstyle={{\n\t\t\t\t\t\tborderRadius: u(TRACK_RADIUS),\n\t\t\t\t\t\tboxShadow: `inset 0 ${u(1)} ${u(2)} var(--gt-tray-inset), inset 0 0 0 ${u(0.5)} var(--gt-tray-line), 0 ${u(1)} 0 var(--gt-tray-lip)`,\n\t\t\t\t\t}}\n\t\t\t\t>\n\t\t\t\t\t{/* Light from the thumb on the tray: cool when off, warm when on. */}\n\t\t\t\t\t<span\n\t\t\t\t\t\tclassName=\"absolute inset-0 opacity-[calc(1-var(--gt-lit))] [--gt-wash-strength:5%] dark:[--gt-wash-strength:9%]\"\n\t\t\t\t\t\tstyle={{\n\t\t\t\t\t\t\tbackground: `radial-gradient(${u(36)} ${u(26)} at calc(var(--gt-u) * (${INSET + THUMB_WIDTH / 2} + var(--gt-x))) 50%, color-mix(in oklab, var(--gt-light-off) var(--gt-wash-strength), transparent), transparent)`,\n\t\t\t\t\t\t}}\n\t\t\t\t\t/>\n\t\t\t\t\t<span\n\t\t\t\t\t\tclassName=\"absolute inset-0 opacity-[var(--gt-lit)] [--gt-wash-strength:8%] dark:[--gt-wash-strength:8%]\"\n\t\t\t\t\t\tstyle={{\n\t\t\t\t\t\t\tbackground: `radial-gradient(${u(40)} ${u(28)} at calc(var(--gt-u) * (${INSET + THUMB_WIDTH / 2} + var(--gt-x))) 50%, color-mix(in oklab, var(--gt-light-on) var(--gt-wash-strength), transparent), transparent)`,\n\t\t\t\t\t\t}}\n\t\t\t\t\t/>\n\t\t\t\t</span>\n\t\t\t\t{/* Keyboard focus only, so pointer use never shows a ring. */}\n\t\t\t\t<span\n\t\t\t\t\taria-hidden\n\t\t\t\t\tclassName=\"pointer-events-none absolute inset-0 group-focus-visible/switch:ring-3 group-focus-visible/switch:ring-ring/50 group-focus-visible/switch:ring-offset-2 group-focus-visible/switch:ring-offset-background\"\n\t\t\t\t\tstyle={{ borderRadius: u(TRACK_RADIUS) }}\n\t\t\t\t/>\n\n\t\t\t\t<span\n\t\t\t\t\tref={thumbRef}\n\t\t\t\t\taria-hidden\n\t\t\t\t\tdata-slot=\"glass-toggle-thumb\"\n\t\t\t\t\tclassName=\"pointer-events-none absolute\"\n\t\t\t\t\tstyle={{\n\t\t\t\t\t\tleft: u(INSET),\n\t\t\t\t\t\ttop: u(INSET),\n\t\t\t\t\t\twidth: u(THUMB_WIDTH),\n\t\t\t\t\t\theight: u(THUMB_HEIGHT),\n\t\t\t\t\t\ttransform: `translateX(${u(Number(initial.vars[\"--gt-x\"]))})`,\n\t\t\t\t\t}}\n\t\t\t\t>\n\t\t\t\t\t<span className=\"absolute inset-0 transition-transform duration-[80ms] ease-out group-data-pressed/glass-toggle:scale-[0.97] motion-reduce:transition-none\">\n\t\t\t\t\t\t<span ref={squashRef} className=\"absolute inset-0\">\n\t\t\t\t\t\t\t{/* Contact shadow and a soft drop; tighter while pressed. */}\n\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\tclassName=\"absolute inset-0 transition-opacity duration-[80ms] [--gt-contact:rgb(0_0_0/0.12)] [--gt-drop:rgb(0_0_0/0.14)] group-data-pressed/glass-toggle:opacity-0 dark:[--gt-contact:rgb(0_0_0/0.5)] dark:[--gt-drop:rgb(0_0_0/0.55)]\"\n\t\t\t\t\t\t\t\tstyle={{\n\t\t\t\t\t\t\t\t\tborderRadius: u(THUMB_RADIUS),\n\t\t\t\t\t\t\t\t\tboxShadow: `0 ${u(0.5)} ${u(1)} var(--gt-contact), 0 ${u(4)} ${u(8)} ${u(-2)} var(--gt-drop)`,\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\tclassName=\"absolute inset-0 opacity-0 transition-opacity duration-[80ms] [--gt-contact:rgb(0_0_0/0.16)] [--gt-drop:rgb(0_0_0/0.12)] group-data-pressed/glass-toggle:opacity-100 dark:[--gt-contact:rgb(0_0_0/0.6)] dark:[--gt-drop:rgb(0_0_0/0.5)]\"\n\t\t\t\t\t\t\t\tstyle={{\n\t\t\t\t\t\t\t\t\tborderRadius: u(THUMB_RADIUS),\n\t\t\t\t\t\t\t\t\tboxShadow: `0 ${u(0.5)} ${u(0.75)} var(--gt-contact), 0 ${u(2)} ${u(4)} ${u(-1)} var(--gt-drop)`,\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t{/* Caustic: light focused through the glass onto the tray. */}\n\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\tclassName=\"absolute [--gt-caustic:color-mix(in_oklab,#fff_80%,var(--gt-light))] dark:[--gt-caustic:color-mix(in_oklab,var(--gt-light)_45%,transparent)]\"\n\t\t\t\t\t\t\t\tstyle={{\n\t\t\t\t\t\t\t\t\tleft: u(9),\n\t\t\t\t\t\t\t\t\twidth: u(THUMB_WIDTH - 18),\n\t\t\t\t\t\t\t\t\ttop: u(THUMB_HEIGHT - 0.5),\n\t\t\t\t\t\t\t\t\theight: u(3),\n\t\t\t\t\t\t\t\t\tbackground:\n\t\t\t\t\t\t\t\t\t\t\"radial-gradient(50% 100% at 50% 0%, var(--gt-caustic), transparent)\",\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t/>\n\n\t\t\t\t\t\t\t{/* The glass. */}\n\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\tdata-slot=\"glass-toggle-glass\"\n\t\t\t\t\t\t\t\tclassName=\"absolute inset-0 overflow-hidden bg-[linear-gradient(to_bottom,rgb(255_255_255/0.92),rgb(244_244_246/0.78))] [--gt-glass-line:rgb(0_0_0/0.05)] dark:bg-[linear-gradient(to_bottom,rgb(255_255_255/0.1),rgb(255_255_255/0.05))] dark:[--gt-glass-line:rgb(255_255_255/0.14)]\"\n\t\t\t\t\t\t\t\tstyle={{\n\t\t\t\t\t\t\t\t\tborderRadius: u(THUMB_RADIUS),\n\t\t\t\t\t\t\t\t\tboxShadow: `inset 0 0 0 ${u(0.5)} var(--gt-glass-line)`,\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{/* The lamp inside the glass, on the side nearest the rim light. */}\n\t\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\t\tclassName=\"absolute inset-0 opacity-[var(--gt-off-amount)] [--gt-tint:50%] dark:[--gt-tint:48%]\"\n\t\t\t\t\t\t\t\t\tstyle={{\n\t\t\t\t\t\t\t\t\t\tbackground: `radial-gradient(circle ${u(30)} at var(--gt-wash-x) var(--gt-wash-y), color-mix(in oklab, var(--gt-light-off) var(--gt-tint), transparent), color-mix(in oklab, var(--gt-light-off) calc(var(--gt-tint) * 0.4), transparent) 45%, transparent)`,\n\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\t\tclassName=\"absolute inset-0 opacity-[var(--gt-on-amount)] [--gt-tint:88%] dark:[--gt-tint:55%]\"\n\t\t\t\t\t\t\t\t\tstyle={{\n\t\t\t\t\t\t\t\t\t\tbackground: `radial-gradient(circle ${u(30)} at var(--gt-wash-x) var(--gt-wash-y), color-mix(in oklab, var(--gt-light-on) var(--gt-tint), transparent), color-mix(in oklab, var(--gt-light-on) calc(var(--gt-tint) * 0.4), transparent) 45%, transparent)`,\n\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t/>\n\n\t\t\t\t\t\t\t\t<svg\n\t\t\t\t\t\t\t\t\taria-hidden\n\t\t\t\t\t\t\t\t\tdata-slot=\"glass-toggle-glyph\"\n\t\t\t\t\t\t\t\t\tviewBox={`0 0 ${THUMB_WIDTH} ${THUMB_HEIGHT}`}\n\t\t\t\t\t\t\t\t\tclassName=\"absolute inset-0 size-full overflow-visible [fill:color-mix(in_oklab,var(--gt-ink-off),var(--gt-ink-on)_var(--gt-mix))] dark:[filter:drop-shadow(0_0_calc(var(--gt-u)*2)_color-mix(in_oklab,var(--gt-light)_75%,transparent))]\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{PIXELS.map((_, index) => {\n\t\t\t\t\t\t\t\t\t\tconst pixel = initial.pixels[index];\n\t\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t\t<rect\n\t\t\t\t\t\t\t\t\t\t\t\tkey={index}\n\t\t\t\t\t\t\t\t\t\t\t\tref={(element) => {\n\t\t\t\t\t\t\t\t\t\t\t\t\tpixelRefs.current[index] = element;\n\t\t\t\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t\t\t\t\tx={pixel.x}\n\t\t\t\t\t\t\t\t\t\t\t\ty={pixel.y}\n\t\t\t\t\t\t\t\t\t\t\t\twidth={PIXEL_SIZE}\n\t\t\t\t\t\t\t\t\t\t\t\theight={PIXEL_SIZE}\n\t\t\t\t\t\t\t\t\t\t\t\trx={0.22}\n\t\t\t\t\t\t\t\t\t\t\t\topacity={pixel.opacity}\n\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t})}\n\t\t\t\t\t\t\t\t</svg>\n\n\t\t\t\t\t\t\t\t{/* Soft sheen over the top; the pointer is the light. */}\n\t\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\t\tclassName=\"absolute inset-0 [--gt-sheen:rgb(255_255_255/0.7)] dark:[--gt-sheen:rgb(255_255_255/0.13)]\"\n\t\t\t\t\t\t\t\t\tstyle={{\n\t\t\t\t\t\t\t\t\t\tbackground:\n\t\t\t\t\t\t\t\t\t\t\t\"radial-gradient(90% 48% at calc(50% + var(--gt-sx)) calc(0% + var(--gt-sy)), var(--gt-sheen), transparent)\",\n\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t{/* Thickness: a bevel band lit from the top-left, with an exit glint. */}\n\t\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\t\tclassName=\"absolute inset-0 blur-[calc(var(--gt-u)*1.4)] dark:hidden\"\n\t\t\t\t\t\t\t\t\tstyle={{\n\t\t\t\t\t\t\t\t\t\tborderRadius: u(THUMB_RADIUS),\n\t\t\t\t\t\t\t\t\t\tpadding: u(3),\n\t\t\t\t\t\t\t\t\t\tbackground:\n\t\t\t\t\t\t\t\t\t\t\t\"conic-gradient(from 0deg, #fff, rgb(255 255 255/0.5) 50deg, rgb(96 96 112/0.08) 95deg, rgb(96 96 112/0.12) 124deg, #fff 136deg, rgb(96 96 112/0.14) 150deg, rgb(96 96 112/0.11) 200deg, rgb(96 96 112/0.04) 245deg, rgb(255 255 255/0.6) 290deg, #fff 318deg)\",\n\t\t\t\t\t\t\t\t\t\t...BEVEL_MASK,\n\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\t\tclassName=\"absolute inset-0 hidden blur-[calc(var(--gt-u)*1.4)] dark:block\"\n\t\t\t\t\t\t\t\t\tstyle={{\n\t\t\t\t\t\t\t\t\t\tborderRadius: u(THUMB_RADIUS),\n\t\t\t\t\t\t\t\t\t\tpadding: u(3),\n\t\t\t\t\t\t\t\t\t\tbackground:\n\t\t\t\t\t\t\t\t\t\t\t\"conic-gradient(from 0deg, rgb(255 255 255/0.22), rgb(255 255 255/0.12) 50deg, rgb(255 255 255/0.03) 95deg, rgb(255 255 255/0.04) 124deg, rgb(255 255 255/0.42) 136deg, rgb(255 255 255/0.03) 150deg, rgb(255 255 255/0.03) 200deg, rgb(255 255 255/0.06) 245deg, rgb(255 255 255/0.15) 290deg, rgb(255 255 255/0.26) 318deg, rgb(255 255 255/0.22))\",\n\t\t\t\t\t\t\t\t\t\t...BEVEL_MASK,\n\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t{/* Specular: a crisp line along the top rim. */}\n\t\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\t\tclassName=\"absolute inset-0 [--gt-specular:rgb(255_255_255/0.9)] dark:[--gt-specular:rgb(255_255_255/0.35)]\"\n\t\t\t\t\t\t\t\t\tstyle={{\n\t\t\t\t\t\t\t\t\t\tborderRadius: u(THUMB_RADIUS),\n\t\t\t\t\t\t\t\t\t\tboxShadow: `inset 0 ${u(1)} 0 var(--gt-specular), inset 0 ${u(-1)} ${u(1.5)} rgb(0 0 0 / 0.04)`,\n\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</span>\n\n\t\t\t\t\t\t\t{/* The rim light, its bloom, and a white-hot core. */}\n\t\t\t\t\t\t\t<svg\n\t\t\t\t\t\t\t\taria-hidden\n\t\t\t\t\t\t\t\tdata-slot=\"glass-toggle-light\"\n\t\t\t\t\t\t\t\tviewBox={`0 0 ${THUMB_WIDTH} ${THUMB_HEIGHT}`}\n\t\t\t\t\t\t\t\tclassName=\"absolute inset-0 size-full overflow-visible\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<defs>\n\t\t\t\t\t\t\t\t\t<filter\n\t\t\t\t\t\t\t\t\t\tid={filterId(\"bloom\")}\n\t\t\t\t\t\t\t\t\t\tfilterUnits=\"userSpaceOnUse\"\n\t\t\t\t\t\t\t\t\t\tx={-30}\n\t\t\t\t\t\t\t\t\t\ty={-30}\n\t\t\t\t\t\t\t\t\t\twidth={THUMB_WIDTH + 60}\n\t\t\t\t\t\t\t\t\t\theight={THUMB_HEIGHT + 60}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<feGaussianBlur stdDeviation={5.5} />\n\t\t\t\t\t\t\t\t\t</filter>\n\t\t\t\t\t\t\t\t\t<filter\n\t\t\t\t\t\t\t\t\t\tid={filterId(\"halo\")}\n\t\t\t\t\t\t\t\t\t\tfilterUnits=\"userSpaceOnUse\"\n\t\t\t\t\t\t\t\t\t\tx={-12}\n\t\t\t\t\t\t\t\t\t\ty={-12}\n\t\t\t\t\t\t\t\t\t\twidth={THUMB_WIDTH + 24}\n\t\t\t\t\t\t\t\t\t\theight={THUMB_HEIGHT + 24}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<feGaussianBlur stdDeviation={1.5} />\n\t\t\t\t\t\t\t\t\t</filter>\n\t\t\t\t\t\t\t\t</defs>\n\t\t\t\t\t\t\t\t<g\n\t\t\t\t\t\t\t\t\tdata-slot=\"glass-toggle-bloom\"\n\t\t\t\t\t\t\t\t\tclassName=\"group-data-disabled/glass-toggle:hidden\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<g\n\t\t\t\t\t\t\t\t\t\tfilter={`url(#${filterId(\"bloom\")})`}\n\t\t\t\t\t\t\t\t\t\tclassName=\"opacity-[var(--gt-bloom)]\"\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{rimStroke(0, 1, {\n\t\t\t\t\t\t\t\t\t\t\tstrokeWidth: 10,\n\t\t\t\t\t\t\t\t\t\t\tclassName:\n\t\t\t\t\t\t\t\t\t\t\t\t\"[stroke:var(--gt-light-off)] opacity-[var(--gt-off-amount)]\",\n\t\t\t\t\t\t\t\t\t\t})}\n\t\t\t\t\t\t\t\t\t\t{rimStroke(1, 1, {\n\t\t\t\t\t\t\t\t\t\t\tstrokeWidth: 10,\n\t\t\t\t\t\t\t\t\t\t\tclassName:\n\t\t\t\t\t\t\t\t\t\t\t\t\"[stroke:var(--gt-light-on)] opacity-[var(--gt-on-amount)] mix-blend-screen\",\n\t\t\t\t\t\t\t\t\t\t})}\n\t\t\t\t\t\t\t\t\t</g>\n\t\t\t\t\t\t\t\t\t<g\n\t\t\t\t\t\t\t\t\t\tfilter={`url(#${filterId(\"halo\")})`}\n\t\t\t\t\t\t\t\t\t\tclassName=\"opacity-[var(--gt-glow)]\"\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{rimStroke(2, 1, {\n\t\t\t\t\t\t\t\t\t\t\tstrokeWidth: 3,\n\t\t\t\t\t\t\t\t\t\t\tclassName:\n\t\t\t\t\t\t\t\t\t\t\t\t\"[stroke:var(--gt-light-off)] opacity-[var(--gt-off-amount)]\",\n\t\t\t\t\t\t\t\t\t\t})}\n\t\t\t\t\t\t\t\t\t\t{rimStroke(3, 1, {\n\t\t\t\t\t\t\t\t\t\t\tstrokeWidth: 3,\n\t\t\t\t\t\t\t\t\t\t\tclassName:\n\t\t\t\t\t\t\t\t\t\t\t\t\"[stroke:var(--gt-light-on)] opacity-[var(--gt-on-amount)] mix-blend-screen\",\n\t\t\t\t\t\t\t\t\t\t})}\n\t\t\t\t\t\t\t\t\t</g>\n\t\t\t\t\t\t\t\t</g>\n\t\t\t\t\t\t\t\t<g className=\"isolate\">\n\t\t\t\t\t\t\t\t\t{RIM_LINE.map((line, index) =>\n\t\t\t\t\t\t\t\t\t\trimStroke(4 + index, line.share, {\n\t\t\t\t\t\t\t\t\t\t\tstrokeWidth: line.width,\n\t\t\t\t\t\t\t\t\t\t\tclassName:\n\t\t\t\t\t\t\t\t\t\t\t\t\"[stroke:var(--gt-light-off)] opacity-[var(--gt-off-amount)]\",\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\t\t{RIM_LINE.map((line, index) =>\n\t\t\t\t\t\t\t\t\t\trimStroke(4 + RIM_LINE.length + index, line.share, {\n\t\t\t\t\t\t\t\t\t\t\tstrokeWidth: line.width,\n\t\t\t\t\t\t\t\t\t\t\tclassName:\n\t\t\t\t\t\t\t\t\t\t\t\t\"[stroke:var(--gt-light-on)] opacity-[var(--gt-on-amount)] mix-blend-screen\",\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\t</g>\n\t\t\t\t\t\t\t\t{rimStroke(4 + RIM_LINE.length * 2, RIM_CORE_SHARE, {\n\t\t\t\t\t\t\t\t\tstrokeWidth: 0.5,\n\t\t\t\t\t\t\t\t\tstroke: \"#fff\",\n\t\t\t\t\t\t\t\t\tstrokeOpacity: 0.7,\n\t\t\t\t\t\t\t\t})}\n\t\t\t\t\t\t\t</svg>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</span>\n\t\t\t\t</span>\n\t\t\t</button>\n\n\t\t\t{name ? (\n\t\t\t\t<input type=\"hidden\" name={name} value={state} disabled={disabled} />\n\t\t\t) : null}\n\t\t</div>\n\t);\n}\n\nexport default GlassToggle;\n",
      "type": "registry:component",
      "target": "@components/glass-toggle.tsx"
    }
  ],
  "meta": {
    "createdAt": "2026-11-11",
    "image": "https://cdn.tentui.com/images/components/glass-toggle?v=1",
    "video": "https://cdn.tentui.com/videos/components/glass-toggle?v=1"
  },
  "docs": "https://tentui.com/components/glass-toggle",
  "categories": [
    "inputs"
  ],
  "type": "registry:component"
}