{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "pull-cord",
  "title": "Pull Cord",
  "description": "A ball-chain pull switch for a light. Drag the handle down and the chain feeds out bead by bead with a tick each, then flips with a click on release and swings back to rest.",
  "dependencies": [
    "@rexa-developer/tiks",
    "web-haptics"
  ],
  "files": [
    {
      "path": "src/registry/components/pull-cord/pull-cord.tsx",
      "content": "\"use client\";\n\nimport { useTiks } from \"@rexa-developer/tiks/react\";\nimport {\n\ttype ComponentProps,\n\ttype KeyboardEvent,\n\ttype PointerEvent,\n\tuseEffect,\n\tuseId,\n\tuseLayoutEffect,\n\tuseRef,\n\tuseState,\n\tuseSyncExternalStore,\n} from \"react\";\nimport { useWebHaptics } from \"web-haptics/react\";\nimport { cn } from \"@/lib/utils\";\n\n// Layout, in px. The chain hangs from the fixture at the top-center of the box.\nconst WIDTH = 200;\nconst HEIGHT = 304;\nconst CENTER_X = WIDTH / 2;\n/** Where the chain leaves the fixture. */\nconst ANCHOR_Y = 49;\n/** Center-to-center distance between beads. */\nconst BEAD_PITCH = 7;\nconst BEAD_RADIUS = 2.6;\n/** Beads hanging below the fixture at rest. */\nconst REST_BEADS = 20;\nconst REST_LENGTH = REST_BEADS * BEAD_PITCH;\n/** The handle's pivot, where the last bead is crimped in, at rest. */\nconst REST_PIVOT_Y = ANCHOR_Y + REST_LENGTH;\n/** From the handle's pivot to its center of mass. */\nconst HANDLE_ARM = 30;\n/** The pivot's spot inside the handle button. */\nconst PIVOT_IN_BUTTON = { x: 24, y: 3 } as const;\n\n// Pulling, in px of chain fed out of the fixture.\n/** Pull before the chain starts to rubber-band. */\nconst TRAVEL = 44;\n/** Pull that flips the switch on release. */\nconst THRESHOLD = 28;\n/** Furthest the chain rubber-bands past `TRAVEL`. */\nconst MAX_BAND = 14;\n/** Furthest the handle follows the pointer sideways. */\nconst MAX_SWAY = 24;\n/** Sideways pointer travel the handle follows, as a fraction. */\nconst SWAY_FACTOR = 0.6;\n/** Pointer travel before a press becomes a pull. */\nconst DRAG_SLOP = 3;\n/** How far a click or key press pulls the chain. */\nconst TUG_DEPTH = 38;\n/** Tug speed in px/s: one bead per 47 ms, so each bead keeps its own tick. */\nconst TUG_SPEED = 150;\n/** Seconds a tug rests at the bottom before letting go. */\nconst TUG_HOLD = 0.06;\n/** A tug leans this far sideways, alternating sides, so the chain swings. */\nconst TUG_SWAY = 12;\n/** Seconds the handle eases home with reduced motion. */\nconst RETURN_DURATION = 0.22;\n/** Minimum ms between bead ticks. Two 60 Hz frames still fit. */\nconst CUE_THROTTLE_MS = 32;\n\n// Physics, in px and seconds. A verlet rope with a two-node rigid handle.\nconst SEGMENTS = 20;\nconst PIVOT = SEGMENTS;\nconst WEIGHT = SEGMENTS + 1;\nconst NODES = SEGMENTS + 2;\nconst GRAVITY = 9000;\n/** Fixed timestep: the same motion at 60 Hz and 120 Hz. */\nconst STEP = 1 / 240;\n/** Longest frame simulated, so a stalled tab doesn't jump. */\nconst MAX_FRAME = 1 / 20;\nconst ITERATIONS = 8;\n/** The handle outweighs each chain node three to one. */\nconst HANDLE_MASS = 3;\n/** Air drag on the chain and handle, per second. */\nconst CHAIN_DAMPING = 6;\nconst HANDLE_DAMPING = 4;\n/**\n * Friction that ramps in after a release, like a real chain losing its last\n * sway, so the rope rests within about 1.5 s instead of shivering.\n */\nconst SETTLE_FRICTION = 14;\nconst SETTLE_FRICTION_AFTER = 0.9;\nconst SETTLE_FRICTION_RAMP = 0.5;\n/** Velocity correction from the follow-the-leader pass, which keeps the rope from buzzing. */\nconst LEADER_DAMPING = 0.5;\n/** How quickly a held handle catches up with the pointer, per second. */\nconst PIN_RATE = 40;\nconst PIN_BLEND = 1 - Math.exp(-PIN_RATE * STEP);\n/** The switch's return spring, which reels the chain back in. */\nconst RECOIL_STIFFNESS = 520;\nconst RECOIL_DAMPING = 2 * 0.42 * Math.sqrt(RECOIL_STIFFNESS);\n/** Settled once every node stays this close to rest for `SETTLE_FRAMES`. */\nconst SETTLE_DISTANCE = 0.25;\nconst SETTLE_FRAMES = 12;\n\nconst MAX_BEADS =\n\tMath.ceil((REST_LENGTH + TRAVEL + MAX_BAND + 8) / BEAD_PITCH) + 2;\n\n// One soft metallic tick per bead, a firm clack on the flip, and a low thunk\n// when the chain hits the end of its travel.\nconst BEAD_SOUND = {\n\tname: \"pull-cord-bead\",\n\tbaseFreq: 660,\n\tnoiseColor: \"white\",\n\toscType: \"sine\",\n\tfilterFreq: 5200,\n\tfilterQ: 7,\n\tattack: 0.001,\n\tdecay: 0.8,\n\tbrightness: 6000,\n} as const;\nconst SWITCH_ON_SOUND = {\n\tname: \"pull-cord-on\",\n\tbaseFreq: 300,\n\tnoiseColor: \"pink\",\n\toscType: \"sine\",\n\tfilterFreq: 1400,\n\tfilterQ: 2.5,\n\tattack: 0.001,\n\tdecay: 1.6,\n\tbrightness: 3000,\n} as const;\n/** A touch higher than on. */\nconst SWITCH_OFF_SOUND = {\n\t...SWITCH_ON_SOUND,\n\tname: \"pull-cord-off\",\n\tbaseFreq: 360,\n\tfilterFreq: 1800,\n} as const;\nconst STOP_SOUND = {\n\tname: \"pull-cord-stop\",\n\tbaseFreq: 220,\n\tnoiseColor: \"pink\",\n\toscType: \"sine\",\n\tfilterFreq: 900,\n\tfilterQ: 1,\n\tattack: 0.002,\n\tdecay: 1.6,\n\tbrightness: 1500,\n} as const;\n\ntype Mode = \"idle\" | \"drag\" | \"tug\" | \"free\" | \"return\";\n\ninterface Sim {\n\tx: Float64Array;\n\ty: Float64Array;\n\tpx: Float64Array;\n\tpy: Float64Array;\n\t/** Arc length along the rope at each node, reused by `layoutBeads`. */\n\tlengths: Float64Array;\n\t/** Chain fed out past its resting length. */\n\tfeed: number;\n\tfeedVelocity: number;\n\tmode: Mode;\n\t/** Pointer offset from the resting pivot, before rubber banding. */\n\tpullX: number;\n\tpullY: number;\n\t/** Pull, in px, where the current tug or return started. */\n\tfromX: number;\n\tfromY: number;\n\telapsed: number;\n\t/** Seconds since the handle was let go. */\n\tfreeTime: number;\n\t/** Side the next tug leans to. */\n\ttugSide: 1 | -1;\n\taccumulator: number;\n\tlastTime: number | null;\n\tlastBead: number;\n\tatStop: boolean;\n\tcalmFrames: number;\n}\n\nfunction restY(node: number) {\n\treturn node === WEIGHT\n\t\t? REST_PIVOT_Y + HANDLE_ARM\n\t\t: ANCHOR_Y + (node * REST_LENGTH) / SEGMENTS;\n}\n\nfunction createSim(): Sim {\n\tconst sim: Sim = {\n\t\tx: new Float64Array(NODES),\n\t\ty: new Float64Array(NODES),\n\t\tpx: new Float64Array(NODES),\n\t\tpy: new Float64Array(NODES),\n\t\tlengths: new Float64Array(SEGMENTS + 1),\n\t\tfeed: 0,\n\t\tfeedVelocity: 0,\n\t\tmode: \"idle\",\n\t\tpullX: 0,\n\t\tpullY: 0,\n\t\tfromX: 0,\n\t\tfromY: 0,\n\t\telapsed: 0,\n\t\tfreeTime: 0,\n\t\ttugSide: 1,\n\t\taccumulator: 0,\n\t\tlastTime: null,\n\t\tlastBead: 0,\n\t\tatStop: false,\n\t\tcalmFrames: 0,\n\t};\n\tsettle(sim);\n\treturn sim;\n}\n\n/** Puts the rope back at rest, hanging straight down. */\nfunction settle(sim: Sim) {\n\tfor (let node = 0; node < NODES; node++) {\n\t\tsim.x[node] = sim.px[node] = CENTER_X;\n\t\tsim.y[node] = sim.py[node] = restY(node);\n\t}\n\tsim.feed = 0;\n\tsim.feedVelocity = 0;\n\tsim.lastBead = 0;\n\tsim.calmFrames = 0;\n}\n\n/** Eases `over` toward `limit`, never reaching it. */\nfunction band(over: number, limit: number) {\n\treturn (over * limit) / (over + limit);\n}\n\n/** Where a pull puts the handle's pivot. */\nfunction pullTarget(pullX: number, pullY: number) {\n\tconst down = Math.max(pullY, 0);\n\treturn {\n\t\tx: CENTER_X + MAX_SWAY * Math.tanh((pullX * SWAY_FACTOR) / MAX_SWAY),\n\t\ty:\n\t\t\tREST_PIVOT_Y +\n\t\t\t(down > TRAVEL ? TRAVEL + band(down - TRAVEL, MAX_BAND) : down),\n\t};\n}\n\n/** Chain fed out when the pivot sits at `x`, `y` with the chain taut. */\nfunction feedAt(x: number, y: number) {\n\treturn Math.max(0, Math.hypot(x - CENTER_X, y - ANCHOR_Y) - REST_LENGTH);\n}\n\n/** Advances the rope by one fixed step. A `pin` holds the handle's pivot. */\nfunction stepSim(sim: Sim, pin: { x: number; y: number } | null) {\n\tconst { x, y, px, py } = sim;\n\n\tif (pin) {\n\t\tpx[PIVOT] = x[PIVOT];\n\t\tpy[PIVOT] = y[PIVOT];\n\t\tx[PIVOT] += (pin.x - x[PIVOT]) * PIN_BLEND;\n\t\ty[PIVOT] += (pin.y - y[PIVOT]) * PIN_BLEND;\n\t\tconst feed = feedAt(x[PIVOT], y[PIVOT]);\n\t\tsim.feedVelocity = (feed - sim.feed) / STEP;\n\t\tsim.feed = feed;\n\t} else {\n\t\t// The return spring reels the chain in until the stop bead hits the fixture.\n\t\tsim.feedVelocity +=\n\t\t\t(-RECOIL_STIFFNESS * sim.feed - RECOIL_DAMPING * sim.feedVelocity) * STEP;\n\t\tsim.feed += sim.feedVelocity * STEP;\n\t\tif (sim.feed <= 0) {\n\t\t\tsim.feed = 0;\n\t\t\tsim.feedVelocity = 0;\n\t\t}\n\t}\n\n\tlet friction = 0;\n\tif (!pin) {\n\t\tsim.freeTime += STEP;\n\t\tfriction =\n\t\t\tSETTLE_FRICTION *\n\t\t\tMath.min(\n\t\t\t\tMath.max(\n\t\t\t\t\t(sim.freeTime - SETTLE_FRICTION_AFTER) / SETTLE_FRICTION_RAMP,\n\t\t\t\t\t0,\n\t\t\t\t),\n\t\t\t\t1,\n\t\t\t);\n\t}\n\tconst chainKeep = Math.exp(-(CHAIN_DAMPING + friction) * STEP);\n\tconst handleKeep = Math.exp(-(HANDLE_DAMPING + friction) * STEP);\n\tconst fall = GRAVITY * STEP * STEP;\n\tfor (let node = 1; node < NODES; node++) {\n\t\tif (pin && node === PIVOT) continue;\n\t\tconst keep = node >= PIVOT ? handleKeep : chainKeep;\n\t\tconst vx = (x[node] - px[node]) * keep;\n\t\tconst vy = (y[node] - py[node]) * keep;\n\t\tpx[node] = x[node];\n\t\tpy[node] = y[node];\n\t\tx[node] += vx;\n\t\ty[node] += vy + fall;\n\t}\n\n\tconst segment = (REST_LENGTH + sim.feed) / SEGMENTS;\n\tconst weightOf = (node: number) => {\n\t\tif (node === 0 || (pin && node === PIVOT)) return 0;\n\t\treturn node >= PIVOT ? 1 / HANDLE_MASS : 1;\n\t};\n\tfor (let pass = 0; pass < ITERATIONS; pass++) {\n\t\tfor (let node = 0; node < NODES - 1; node++) {\n\t\t\tconst wa = weightOf(node);\n\t\t\tconst wb = weightOf(node + 1);\n\t\t\tconst total = wa + wb;\n\t\t\tif (!total) continue;\n\t\t\tconst dx = x[node + 1] - x[node];\n\t\t\tconst dy = y[node + 1] - y[node];\n\t\t\tconst distance = Math.hypot(dx, dy) || 1e-6;\n\t\t\tconst rest = node < SEGMENTS ? segment : HANDLE_ARM;\n\t\t\tconst push = (distance - rest) / distance / total;\n\t\t\tx[node] += dx * push * wa;\n\t\t\ty[node] += dy * push * wa;\n\t\t\tx[node + 1] -= dx * push * wb;\n\t\t\ty[node + 1] -= dy * push * wb;\n\t\t}\n\t}\n\n\t// Follow the leader from the fixture down, so the chain never stretches\n\t// and the handle stays rigid. A chain can still go slack.\n\tfor (let node = 1; node < NODES; node++) {\n\t\tif (pin && node === PIVOT) continue;\n\t\tconst rest = node <= SEGMENTS ? segment : HANDLE_ARM;\n\t\tconst dx = x[node] - x[node - 1];\n\t\tconst dy = y[node] - y[node - 1];\n\t\tconst distance = Math.hypot(dx, dy) || 1e-6;\n\t\tif (node <= SEGMENTS && distance <= rest) continue;\n\t\tconst nextX = x[node - 1] + (dx / distance) * rest;\n\t\tconst nextY = y[node - 1] + (dy / distance) * rest;\n\t\tif (node > 1 && !(pin && node - 1 === PIVOT)) {\n\t\t\tpx[node - 1] += (nextX - x[node]) * LEADER_DAMPING;\n\t\t\tpy[node - 1] += (nextY - y[node]) * LEADER_DAMPING;\n\t\t}\n\t\tx[node] = nextX;\n\t\ty[node] = nextY;\n\t}\n}\n\n/** Lays the rope out straight from the fixture to `pivotX`, `pivotY`. */\nfunction poseStraight(sim: Sim, pivotX: number, pivotY: number) {\n\tfor (let node = 0; node <= SEGMENTS; node++) {\n\t\tconst t = node / SEGMENTS;\n\t\tsim.x[node] = sim.px[node] = CENTER_X + (pivotX - CENTER_X) * t;\n\t\tsim.y[node] = sim.py[node] = ANCHOR_Y + (pivotY - ANCHOR_Y) * t;\n\t}\n\tsim.x[WEIGHT] = sim.px[WEIGHT] = pivotX;\n\tsim.y[WEIGHT] = sim.py[WEIGHT] = pivotY + HANDLE_ARM;\n\tsim.feed = feedAt(pivotX, pivotY);\n\tsim.feedVelocity = 0;\n}\n\n/**\n * Places the beads along the rope, counting up from the handle, and returns\n * how many there are. Beads above the fixture's mouth are tucked inside it,\n * so a pull feeds them out one by one.\n */\nfunction layoutBeads(sim: Sim, out: Float64Array) {\n\tconst { x, y, lengths } = sim;\n\tlengths[0] = 0;\n\tfor (let node = 1; node <= SEGMENTS; node++) {\n\t\tlengths[node] =\n\t\t\tlengths[node - 1] +\n\t\t\tMath.hypot(x[node] - x[node - 1], y[node] - y[node - 1]);\n\t}\n\tconst ropeLength = lengths[SEGMENTS];\n\tconst span = REST_LENGTH + sim.feed;\n\tconst last = Math.min(MAX_BEADS - 1, Math.floor(span / BEAD_PITCH) + 1);\n\tlet segment = 1;\n\t// From the fixture down, so the segment only ever moves forward.\n\tfor (let bead = last; bead >= 0; bead--) {\n\t\tconst along = span - bead * BEAD_PITCH;\n\t\tif (along <= 0) {\n\t\t\tout[bead * 2] = x[0];\n\t\t\tout[bead * 2 + 1] = y[0] + along;\n\t\t\tcontinue;\n\t\t}\n\t\tconst at = (along / span) * ropeLength;\n\t\twhile (segment < SEGMENTS && lengths[segment] < at) segment++;\n\t\tconst from = lengths[segment - 1];\n\t\tconst t = (at - from) / (lengths[segment] - from || 1);\n\t\tout[bead * 2] = x[segment - 1] + (x[segment] - x[segment - 1]) * t;\n\t\tout[bead * 2 + 1] = y[segment - 1] + (y[segment] - y[segment - 1]) * t;\n\t}\n\treturn last + 1;\n}\n\nfunction round(value: number) {\n\treturn Math.round(value * 100) / 100;\n}\n\nfunction chainPath(points: Float64Array, count: number) {\n\tlet path = \"\";\n\tfor (let bead = 0; bead < count; bead++) {\n\t\tpath += `${bead ? \"L\" : \"M\"}${round(points[bead * 2])} ${round(points[bead * 2 + 1])}`;\n\t}\n\treturn path;\n}\n\nfunction handleTransform(sim: Sim) {\n\tconst pivotX = sim.x[PIVOT];\n\tconst pivotY = sim.y[PIVOT];\n\tconst tilt = Math.atan2(sim.x[WEIGHT] - pivotX, sim.y[WEIGHT] - pivotY);\n\treturn `translate(${round(pivotX - PIVOT_IN_BUTTON.x)}px, ${round(pivotY - PIVOT_IN_BUTTON.y)}px) rotate(${round((-tilt * 180) / Math.PI)}deg)`;\n}\n\n// The resting pose, rendered on the server and on first paint.\nconst restSim = createSim();\nconst restBeads = new Float64Array(MAX_BEADS * 2);\nconst restCount = layoutBeads(restSim, restBeads);\nconst restPath = chainPath(restBeads, restCount);\nconst restTransform = handleTransform(restSim);\n\nconst REDUCED_MOTION_QUERY = \"(prefers-reduced-motion: reduce)\";\n\nfunction subscribeToReducedMotion(onStoreChange: () => void) {\n\tconst query = window.matchMedia(REDUCED_MOTION_QUERY);\n\tquery.addEventListener(\"change\", onStoreChange);\n\treturn () => query.removeEventListener(\"change\", onStoreChange);\n}\n\nfunction usePrefersReducedMotion() {\n\treturn useSyncExternalStore(\n\t\tsubscribeToReducedMotion,\n\t\t() => window.matchMedia(REDUCED_MOTION_QUERY).matches,\n\t\t() => false,\n\t);\n}\n\nfunction easeOutCubic(t: number) {\n\treturn 1 - (1 - t) ** 3;\n}\n\nexport interface PullCordProps\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 pull, click, or key press 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/** Play a tick per bead, a click on the flip, and a thunk at the end of the pull. */\n\tsound?: boolean;\n\t/** Trigger haptics on supported devices. */\n\thaptics?: boolean;\n}\n\nexport function PullCord({\n\tchecked: checkedProp,\n\tdefaultChecked = false,\n\tonCheckedChange,\n\tlabel = \"Light\",\n\tdisabled = false,\n\tname,\n\tsound = true,\n\thaptics = true,\n\tclassName,\n\t\"aria-label\": ariaLabel,\n\t\"aria-labelledby\": ariaLabelledBy,\n\t\"aria-describedby\": ariaDescribedBy,\n\t...props\n}: PullCordProps) {\n\tconst [internalChecked, setInternalChecked] = useState(defaultChecked);\n\tconst controlled = checkedProp !== undefined;\n\tconst checked = controlled ? checkedProp : internalChecked;\n\tconst [pulling, setPulling] = useState(false);\n\n\tconst reducedMotion = usePrefersReducedMotion();\n\tconst { trigger: haptic } = useWebHaptics();\n\t// Sound stays on under reduced motion; only movement is reduced.\n\tconst { click: playBead } = useTiks({\n\t\ttheme: BEAD_SOUND,\n\t\trespectReducedMotion: false,\n\t});\n\tconst {\n\t\tclick: playSwitchClick,\n\t\ttoggle: playSwitchClunk,\n\t\tsetTheme: setSwitchSound,\n\t} = useTiks({ theme: SWITCH_ON_SOUND, respectReducedMotion: false });\n\tconst { toggle: playStop } = useTiks({\n\t\ttheme: STOP_SOUND,\n\t\trespectReducedMotion: false,\n\t});\n\n\tconst ids = useId().replace(/[^\\w-]/g, \"\");\n\tconst url = (part: string) => `url(#pull-cord-${ids}-${part})`;\n\tconst gradientId = (part: string) => `pull-cord-${ids}-${part}`;\n\n\tconst rootRef = useRef<HTMLDivElement>(null);\n\tconst handleRef = useRef<HTMLButtonElement>(null);\n\tconst chainRef = useRef<SVGPathElement>(null);\n\tconst beadRefs = useRef<Array<SVGCircleElement | null>>([]);\n\tconst simRef = useRef<Sim | null>(null);\n\tconst beadsRef = useRef<Float64Array | null>(null);\n\tconst shownRef = useRef(restCount);\n\tconst frameRef = useRef(0);\n\tconst lastCueAtRef = useRef(Number.NEGATIVE_INFINITY);\n\tconst suppressClickRef = useRef(false);\n\tconst dragRef = useRef<{\n\t\tpointerId: number;\n\t\toriginX: number;\n\t\toriginY: number;\n\t\tstartX: number;\n\t\tstartY: number;\n\t\tscale: number;\n\t\tmoved: boolean;\n\t} | null>(null);\n\n\t// Event handlers and the frame 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 getSim = () => {\n\t\tsimRef.current ??= createSim();\n\t\treturn simRef.current;\n\t};\n\n\tconst silent = () =>\n\t\ttypeof document !== \"undefined\" && document.visibilityState === \"hidden\";\n\n\tconst tick = (now: number) => {\n\t\tif (now - lastCueAtRef.current < CUE_THROTTLE_MS) return;\n\t\tlastCueAtRef.current = now;\n\t\tif (silent()) return;\n\t\tif (latest.current.sound) playBead();\n\t\tif (latest.current.haptics) void haptic(\"selection\");\n\t};\n\n\tconst thunk = () => {\n\t\tlastCueAtRef.current = performance.now();\n\t\tif (silent()) return;\n\t\tif (latest.current.sound) playStop(false);\n\t\tif (latest.current.haptics) void haptic(\"soft\");\n\t};\n\n\t// Called only for user input, so the first render and prop changes stay quiet.\n\tconst flip = () => {\n\t\tconst next = !latest.current.checked;\n\t\tlatest.current.checked = next;\n\t\tif (!latest.current.controlled) setInternalChecked(next);\n\t\tlatest.current.onCheckedChange?.(next);\n\t\tlastCueAtRef.current = performance.now();\n\t\tif (silent()) return;\n\t\tif (latest.current.sound) {\n\t\t\t// The same falling clunk for both, pitched a little lower for on.\n\t\t\tsetSwitchSound(next ? SWITCH_ON_SOUND : SWITCH_OFF_SOUND);\n\t\t\tplaySwitchClick();\n\t\t\tplaySwitchClunk(false);\n\t\t}\n\t\tif (latest.current.haptics) void haptic(\"medium\");\n\t};\n\n\tconst paint = () => {\n\t\tconst sim = getSim();\n\t\tbeadsRef.current ??= new Float64Array(MAX_BEADS * 2);\n\t\tconst beads = beadsRef.current;\n\t\tconst count = layoutBeads(sim, beads);\n\t\tconst shown = shownRef.current;\n\t\tfor (let bead = 0; bead < Math.max(count, shown); bead++) {\n\t\t\tconst circle = beadRefs.current[bead];\n\t\t\tif (!circle) continue;\n\t\t\tif (bead >= count) {\n\t\t\t\tcircle.setAttribute(\"display\", \"none\");\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (bead >= shown) circle.removeAttribute(\"display\");\n\t\t\tcircle.setAttribute(\"cx\", String(round(beads[bead * 2])));\n\t\t\tcircle.setAttribute(\"cy\", String(round(beads[bead * 2 + 1])));\n\t\t}\n\t\tshownRef.current = count;\n\t\tchainRef.current?.setAttribute(\"d\", chainPath(beads, count));\n\t\tif (handleRef.current) {\n\t\t\thandleRef.current.style.transform = handleTransform(sim);\n\t\t}\n\t};\n\n\t/** Lets go of the handle; `commit` flips the switch if it was pulled far enough. */\n\tconst release = (commit: boolean) => {\n\t\tconst sim = getSim();\n\t\tconst target = pullTarget(sim.pullX, sim.pullY);\n\t\tconst pulled = feedAt(target.x, target.y);\n\t\tif (sim.mode === \"tug\" || (commit && pulled >= THRESHOLD)) flip();\n\t\tif (latest.current.reducedMotion) {\n\t\t\tsim.mode = \"return\";\n\t\t\tsim.fromX = sim.x[PIVOT] - CENTER_X;\n\t\t\tsim.fromY = sim.y[PIVOT] - REST_PIVOT_Y;\n\t\t\tsim.elapsed = 0;\n\t\t} else {\n\t\t\tsim.mode = \"free\";\n\t\t\tsim.freeTime = 0;\n\t\t}\n\t\tsim.atStop = false;\n\t\twake();\n\t};\n\n\tconst frame = (now: number) => {\n\t\tframeRef.current = 0;\n\t\tconst sim = getSim();\n\t\tconst elapsed =\n\t\t\tsim.lastTime === null\n\t\t\t\t? 1 / 60\n\t\t\t\t: Math.min((now - sim.lastTime) / 1000, MAX_FRAME);\n\t\tsim.lastTime = now;\n\t\tsim.elapsed += elapsed;\n\n\t\tif (sim.mode === \"tug\") {\n\t\t\tsim.pullY = Math.min(TUG_DEPTH, sim.fromY + sim.elapsed * TUG_SPEED);\n\t\t\tconst progress = (sim.pullY - sim.fromY) / (TUG_DEPTH - sim.fromY || 1);\n\t\t\tsim.pullX = sim.tugSide * TUG_SWAY * progress;\n\t\t}\n\t\tconst held = sim.mode === \"drag\" || sim.mode === \"tug\";\n\t\tconst target = pullTarget(sim.pullX, sim.pullY);\n\n\t\tif (latest.current.reducedMotion) {\n\t\t\tif (held) {\n\t\t\t\tposeStraight(sim, target.x, target.y);\n\t\t\t} else if (sim.mode === \"return\") {\n\t\t\t\tconst t = Math.min(sim.elapsed / RETURN_DURATION, 1);\n\t\t\t\tconst left = 1 - easeOutCubic(t);\n\t\t\t\tposeStraight(\n\t\t\t\t\tsim,\n\t\t\t\t\tCENTER_X + sim.fromX * left,\n\t\t\t\t\tREST_PIVOT_Y + sim.fromY * left,\n\t\t\t\t);\n\t\t\t\tif (t >= 1) sim.mode = \"idle\";\n\t\t\t} else {\n\t\t\t\tsettle(sim);\n\t\t\t\tsim.mode = \"idle\";\n\t\t\t}\n\t\t} else {\n\t\t\tsim.accumulator += elapsed;\n\t\t\twhile (sim.accumulator >= STEP) {\n\t\t\t\tstepSim(sim, held ? target : null);\n\t\t\t\tsim.accumulator -= STEP;\n\t\t\t}\n\t\t}\n\n\t\t// Each bead that passes the fixture's mouth ticks while the chain is held.\n\t\tconst bead = Math.floor(sim.feed / BEAD_PITCH);\n\t\tif (bead !== sim.lastBead) {\n\t\t\tif (held) tick(now);\n\t\t\tsim.lastBead = bead;\n\t\t}\n\t\tif (sim.mode === \"drag\") {\n\t\t\tif (!sim.atStop && sim.pullY >= TRAVEL) {\n\t\t\t\tsim.atStop = true;\n\t\t\t\tthunk();\n\t\t\t} else if (sim.atStop && sim.pullY < TRAVEL - 6) {\n\t\t\t\tsim.atStop = false;\n\t\t\t}\n\t\t}\n\t\tif (\n\t\t\tsim.mode === \"tug\" &&\n\t\t\tsim.elapsed >= (TUG_DEPTH - sim.fromY) / TUG_SPEED + TUG_HOLD\n\t\t) {\n\t\t\trelease(true);\n\t\t}\n\n\t\tif (sim.mode === \"free\" && sim.feed === 0) {\n\t\t\tlet farthest = 0;\n\t\t\tfor (let node = 1; node < NODES; node++) {\n\t\t\t\tfarthest = Math.max(\n\t\t\t\t\tfarthest,\n\t\t\t\t\tMath.abs(sim.x[node] - CENTER_X),\n\t\t\t\t\tMath.abs(sim.y[node] - restY(node)),\n\t\t\t\t);\n\t\t\t}\n\t\t\tsim.calmFrames = farthest < SETTLE_DISTANCE ? sim.calmFrames + 1 : 0;\n\t\t\t// Snap the last fraction of a pixel so the chain rests perfectly still.\n\t\t\tif (sim.calmFrames >= SETTLE_FRAMES) {\n\t\t\t\tsettle(sim);\n\t\t\t\tsim.mode = \"idle\";\n\t\t\t}\n\t\t}\n\n\t\tpaint();\n\t\tif (sim.mode !== \"idle\") wake();\n\t\telse sim.lastTime = null;\n\t};\n\n\tconst frameHandlerRef = useRef(frame);\n\tuseLayoutEffect(() => {\n\t\tframeHandlerRef.current = frame;\n\t});\n\n\tfunction wake() {\n\t\tif (frameRef.current) return;\n\t\tframeRef.current = requestAnimationFrame((now) =>\n\t\t\tframeHandlerRef.current(now),\n\t\t);\n\t}\n\n\tuseEffect(() => () => cancelAnimationFrame(frameRef.current), []);\n\n\tconst tug = () => {\n\t\tconst sim = getSim();\n\t\tif (sim.mode === \"drag\" || sim.mode === \"tug\") return;\n\t\tif (latest.current.reducedMotion) {\n\t\t\tflip();\n\t\t\treturn;\n\t\t}\n\t\tsim.mode = \"tug\";\n\t\tsim.fromY = Math.max(0, sim.y[PIVOT] - REST_PIVOT_Y);\n\t\tsim.pullY = sim.fromY;\n\t\tsim.pullX = 0;\n\t\tsim.tugSide = sim.tugSide > 0 ? -1 : 1;\n\t\tsim.elapsed = 0;\n\t\tsim.lastBead = Math.floor(sim.feed / BEAD_PITCH);\n\t\twake();\n\t};\n\n\tconst scaleOf = () => {\n\t\tconst root = rootRef.current;\n\t\tif (!root) return 1;\n\t\t// CSS zoom and transforms scale client coordinates; work in local px.\n\t\treturn root.getBoundingClientRect().width / (root.offsetWidth || 1) || 1;\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\tconst sim = getSim();\n\t\tif (sim.mode === \"tug\") 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\t// Grabbing a swinging handle picks it up where it is.\n\t\t\tstartX: (sim.x[PIVOT] - CENTER_X) / SWAY_FACTOR,\n\t\t\tstartY: Math.max(0, sim.y[PIVOT] - REST_PIVOT_Y),\n\t\t\tscale: scaleOf(),\n\t\t\tmoved: false,\n\t\t};\n\t};\n\n\tconst handlePointerMove = (event: PointerEvent<HTMLButtonElement>) => {\n\t\tconst drag = dragRef.current;\n\t\tif (!drag || drag.pointerId !== event.pointerId) return;\n\t\tconst dx = (event.clientX - drag.originX) / drag.scale;\n\t\tconst dy = (event.clientY - drag.originY) / drag.scale;\n\t\tconst sim = getSim();\n\t\tif (!drag.moved) {\n\t\t\tif (Math.hypot(dx, dy) < DRAG_SLOP) return;\n\t\t\tdrag.moved = true;\n\t\t\tsim.mode = \"drag\";\n\t\t\tsim.atStop = false;\n\t\t\tsim.lastBead = Math.floor(sim.feed / BEAD_PITCH);\n\t\t\tsetPulling(true);\n\t\t}\n\t\tsim.pullX = drag.startX + dx;\n\t\tsim.pullY = drag.startY + dy;\n\t\twake();\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\tconst handle = handleRef.current;\n\t\tif (handle?.hasPointerCapture(drag.pointerId)) {\n\t\t\thandle.releasePointerCapture(drag.pointerId);\n\t\t}\n\t\tif (!drag.moved) return;\n\t\t// The click that follows a pull isn't a tug.\n\t\tsuppressClickRef.current = commit;\n\t\tsetPulling(false);\n\t\trelease(commit);\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\ttug();\n\t};\n\n\tconst handleKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {\n\t\t// Holding a key shouldn't flicker the light.\n\t\tif (event.repeat && (event.key === \"Enter\" || event.key === \" \")) {\n\t\t\tevent.preventDefault();\n\t\t}\n\t};\n\n\t// Losing the window or the tab mid-pull 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 (!pulling) 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}, [pulling]);\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-pull.\n\tuseEffect(() => {\n\t\tconst handle = handleRef.current;\n\t\tif (!handle) return;\n\t\tconst onTouchMove = (event: TouchEvent) => {\n\t\t\tif (dragRef.current) event.preventDefault();\n\t\t};\n\t\thandle.addEventListener(\"touchmove\", onTouchMove, { passive: false });\n\t\treturn () => handle.removeEventListener(\"touchmove\", onTouchMove);\n\t}, []);\n\n\tconst state = checked ? \"on\" : \"off\";\n\n\treturn (\n\t\t<div\n\t\t\tref={rootRef}\n\t\t\tdata-slot=\"pull-cord\"\n\t\t\tdata-state={state}\n\t\t\tdata-pulling={pulling || undefined}\n\t\t\tdata-disabled={disabled || undefined}\n\t\t\t{...props}\n\t\t\tclassName={cn(\n\t\t\t\t\"group/pull-cord relative h-[304px] w-[200px] shrink-0 select-none data-disabled:cursor-not-allowed data-disabled:opacity-50\",\n\t\t\t\tclassName,\n\t\t\t)}\n\t\t>\n\t\t\t{/* Warm light cast under the fixture. */}\n\t\t\t<div\n\t\t\t\taria-hidden\n\t\t\t\tdata-slot=\"pull-cord-light\"\n\t\t\t\tclassName=\"pointer-events-none absolute inset-x-0 top-0 h-[260px] opacity-0 transition-opacity duration-200 ease-out group-data-[state=on]/pull-cord:opacity-100 motion-reduce:transition-none dark:group-data-[state=on]/pull-cord:opacity-80\"\n\t\t\t\tstyle={{\n\t\t\t\t\tbackground:\n\t\t\t\t\t\t\"radial-gradient(60px 15px at 50% 41px, rgb(255 184 92 / 0.6), rgb(255 184 92 / 0)), radial-gradient(92px 210px at 50% 36px, rgb(255 196 120 / 0.3), rgb(255 196 120 / 0.1) 50%, rgb(255 196 120 / 0) 100%)\",\n\t\t\t\t\t// No light above the fixture's rim.\n\t\t\t\t\tmaskImage: \"linear-gradient(to bottom, transparent 24px, #000 40px)\",\n\t\t\t\t}}\n\t\t\t/>\n\n\t\t\t<svg\n\t\t\t\taria-hidden\n\t\t\t\tdata-slot=\"pull-cord-chain\"\n\t\t\t\twidth={WIDTH}\n\t\t\t\theight={HEIGHT}\n\t\t\t\tviewBox={`0 0 ${WIDTH} ${HEIGHT}`}\n\t\t\t\tclassName=\"pointer-events-none absolute inset-0 overflow-visible\"\n\t\t\t>\n\t\t\t\t<defs>\n\t\t\t\t\t<radialGradient\n\t\t\t\t\t\tid={gradientId(\"bead\")}\n\t\t\t\t\t\tcx=\"0.5\"\n\t\t\t\t\t\tcy=\"0.5\"\n\t\t\t\t\t\tr=\"0.5\"\n\t\t\t\t\t\tfx=\"0.36\"\n\t\t\t\t\t\tfy=\"0.3\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<stop\n\t\t\t\t\t\t\toffset=\"0\"\n\t\t\t\t\t\t\tclassName=\"[stop-color:#fff] dark:[stop-color:#fff]\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<stop\n\t\t\t\t\t\t\toffset=\"0.24\"\n\t\t\t\t\t\t\tclassName=\"[stop-color:#eceef1] dark:[stop-color:#f4f5f7]\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<stop\n\t\t\t\t\t\t\toffset=\"0.64\"\n\t\t\t\t\t\t\tclassName=\"[stop-color:#9ba1aa] dark:[stop-color:#b8bec7]\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<stop\n\t\t\t\t\t\t\toffset=\"1\"\n\t\t\t\t\t\t\tclassName=\"[stop-color:#575d66] dark:[stop-color:#7a818c]\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t</radialGradient>\n\t\t\t\t</defs>\n\t\t\t\t{/* The tiny links between beads. */}\n\t\t\t\t<path\n\t\t\t\t\tref={chainRef}\n\t\t\t\t\td={restPath}\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstrokeWidth={1.1}\n\t\t\t\t\tstrokeLinecap=\"round\"\n\t\t\t\t\tstrokeLinejoin=\"round\"\n\t\t\t\t\tclassName=\"stroke-[#8b919a] dark:stroke-[#a6acb5]\"\n\t\t\t\t/>\n\t\t\t\t{Array.from({ length: MAX_BEADS }, (_, bead) => (\n\t\t\t\t\t<circle\n\t\t\t\t\t\tkey={bead}\n\t\t\t\t\t\tref={(element) => {\n\t\t\t\t\t\t\tbeadRefs.current[bead] = element;\n\t\t\t\t\t\t}}\n\t\t\t\t\t\tcx={bead < restCount ? round(restBeads[bead * 2]) : CENTER_X}\n\t\t\t\t\t\tcy={bead < restCount ? round(restBeads[bead * 2 + 1]) : ANCHOR_Y}\n\t\t\t\t\t\tr={BEAD_RADIUS}\n\t\t\t\t\t\tfill={url(\"bead\")}\n\t\t\t\t\t\tdisplay={bead < restCount ? undefined : \"none\"}\n\t\t\t\t\t/>\n\t\t\t\t))}\n\t\t\t</svg>\n\n\t\t\t<svg\n\t\t\t\taria-hidden\n\t\t\t\tdata-slot=\"pull-cord-fixture\"\n\t\t\t\twidth={WIDTH}\n\t\t\t\theight={52}\n\t\t\t\tviewBox={`0 0 ${WIDTH} 52`}\n\t\t\t\tclassName=\"pointer-events-none absolute top-0 left-0 overflow-visible drop-shadow-[0_6px_10px_rgb(0_0_0/0.07)] dark:drop-shadow-[0_6px_12px_rgb(0_0_0/0.5)]\"\n\t\t\t>\n\t\t\t\t<defs>\n\t\t\t\t\t<linearGradient\n\t\t\t\t\t\tid={gradientId(\"housing\")}\n\t\t\t\t\t\tx1=\"0\"\n\t\t\t\t\t\ty1=\"0\"\n\t\t\t\t\t\tx2=\"0\"\n\t\t\t\t\t\ty2=\"1\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<stop\n\t\t\t\t\t\t\toffset=\"0\"\n\t\t\t\t\t\t\tclassName=\"[stop-color:#ffffff] dark:[stop-color:#4a4a52]\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<stop\n\t\t\t\t\t\t\toffset=\"0.45\"\n\t\t\t\t\t\t\tclassName=\"[stop-color:#f4f4f5] dark:[stop-color:#36363d]\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<stop\n\t\t\t\t\t\t\toffset=\"1\"\n\t\t\t\t\t\t\tclassName=\"[stop-color:#dcdce1] dark:[stop-color:#232327]\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t</linearGradient>\n\t\t\t\t\t{/* Turns the dish's sides away from the light. Each fade keeps its\n\t\t\t\t\t    own color, since SVG blends black into white through grey. */}\n\t\t\t\t\t<linearGradient id={gradientId(\"sheen\")} x1=\"0\" y1=\"0\" x2=\"1\" y2=\"0\">\n\t\t\t\t\t\t<stop\n\t\t\t\t\t\t\toffset=\"0\"\n\t\t\t\t\t\t\tclassName=\"[stop-color:#000] [stop-opacity:0.08] dark:[stop-opacity:0.4]\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<stop offset=\"0.24\" stopColor=\"#000\" stopOpacity={0} />\n\t\t\t\t\t\t<stop offset=\"0.24\" stopColor=\"#fff\" stopOpacity={0} />\n\t\t\t\t\t\t<stop\n\t\t\t\t\t\t\toffset=\"0.4\"\n\t\t\t\t\t\t\tclassName=\"[stop-color:#fff] [stop-opacity:0.5] dark:[stop-opacity:0.06]\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<stop offset=\"0.62\" stopColor=\"#fff\" stopOpacity={0} />\n\t\t\t\t\t\t<stop offset=\"0.62\" stopColor=\"#000\" stopOpacity={0} />\n\t\t\t\t\t\t<stop\n\t\t\t\t\t\t\toffset=\"1\"\n\t\t\t\t\t\t\tclassName=\"[stop-color:#000] [stop-opacity:0.1] dark:[stop-opacity:0.45]\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t</linearGradient>\n\t\t\t\t\t<linearGradient id={gradientId(\"warm\")} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n\t\t\t\t\t\t<stop offset=\"0.5\" stopColor=\"#ffc778\" stopOpacity={0} />\n\t\t\t\t\t\t<stop\n\t\t\t\t\t\t\toffset=\"1\"\n\t\t\t\t\t\t\tclassName=\"[stop-color:#ffc778] [stop-opacity:0.28] dark:[stop-opacity:0.5]\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t</linearGradient>\n\t\t\t\t\t<linearGradient id={gradientId(\"lens\")} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n\t\t\t\t\t\t<stop\n\t\t\t\t\t\t\toffset=\"0\"\n\t\t\t\t\t\t\tclassName=\"[stop-color:#ececef] dark:[stop-color:#2e2e33]\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<stop\n\t\t\t\t\t\t\toffset=\"1\"\n\t\t\t\t\t\t\tclassName=\"[stop-color:#d2d2d8] dark:[stop-color:#1c1c20]\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t</linearGradient>\n\t\t\t\t\t<linearGradient\n\t\t\t\t\t\tid={gradientId(\"lens-on\")}\n\t\t\t\t\t\tx1=\"0\"\n\t\t\t\t\t\ty1=\"0\"\n\t\t\t\t\t\tx2=\"0\"\n\t\t\t\t\t\ty2=\"1\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<stop offset=\"0\" stopColor=\"#fff6e2\" />\n\t\t\t\t\t\t<stop offset=\"0.5\" stopColor=\"#ffe3a8\" />\n\t\t\t\t\t\t<stop offset=\"1\" stopColor=\"#ffc56b\" />\n\t\t\t\t\t</linearGradient>\n\t\t\t\t\t<radialGradient\n\t\t\t\t\t\tid={gradientId(\"lens-core\")}\n\t\t\t\t\t\tcx=\"0.5\"\n\t\t\t\t\t\tcy=\"0.35\"\n\t\t\t\t\t\tr=\"0.5\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<stop offset=\"0\" stopColor=\"#fffdf8\" />\n\t\t\t\t\t\t<stop offset=\"1\" stopColor=\"#fffdf8\" stopOpacity={0} />\n\t\t\t\t\t</radialGradient>\n\t\t\t\t\t<linearGradient id={gradientId(\"steel\")} x1=\"0\" y1=\"0\" x2=\"1\" y2=\"0\">\n\t\t\t\t\t\t<stop\n\t\t\t\t\t\t\toffset=\"0\"\n\t\t\t\t\t\t\tclassName=\"[stop-color:#6f747d] dark:[stop-color:#80868f]\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<stop\n\t\t\t\t\t\t\toffset=\"0.32\"\n\t\t\t\t\t\t\tclassName=\"[stop-color:#eef0f2] dark:[stop-color:#f4f5f7]\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<stop\n\t\t\t\t\t\t\toffset=\"0.55\"\n\t\t\t\t\t\t\tclassName=\"[stop-color:#bfc3c9] dark:[stop-color:#c9cdd3]\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<stop\n\t\t\t\t\t\t\toffset=\"1\"\n\t\t\t\t\t\t\tclassName=\"[stop-color:#5f646c] dark:[stop-color:#737983]\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t</linearGradient>\n\t\t\t\t</defs>\n\n\t\t\t\t{/* Housing: a soft ceramic dish with a lit lip when on. */}\n\t\t\t\t<path\n\t\t\t\t\td=\"M48 2H152Q158 2 158 8C158 21 151 31.5 137 34H63C49 31.5 42 21 42 8Q42 2 48 2Z\"\n\t\t\t\t\tfill={url(\"housing\")}\n\t\t\t\t/>\n\t\t\t\t<path\n\t\t\t\t\td=\"M48 2H152Q158 2 158 8C158 21 151 31.5 137 34H63C49 31.5 42 21 42 8Q42 2 48 2Z\"\n\t\t\t\t\tfill={url(\"sheen\")}\n\t\t\t\t/>\n\t\t\t\t<path\n\t\t\t\t\td=\"M48 2H152Q158 2 158 8C158 21 151 31.5 137 34H63C49 31.5 42 21 42 8Q42 2 48 2Z\"\n\t\t\t\t\tfill={url(\"warm\")}\n\t\t\t\t\tclassName=\"opacity-0 transition-opacity duration-200 ease-out group-data-[state=on]/pull-cord:opacity-100 motion-reduce:transition-none\"\n\t\t\t\t/>\n\t\t\t\t<path\n\t\t\t\t\td=\"M48 2H152Q158 2 158 8C158 21 151 31.5 137 34H63C49 31.5 42 21 42 8Q42 2 48 2Z\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstrokeWidth={0.75}\n\t\t\t\t\tclassName=\"stroke-foreground/12 dark:stroke-white/8\"\n\t\t\t\t/>\n\t\t\t\t{/* Top highlight. */}\n\t\t\t\t<path\n\t\t\t\t\td=\"M49 2.6H151\"\n\t\t\t\t\tstrokeWidth={0.8}\n\t\t\t\t\tstrokeLinecap=\"round\"\n\t\t\t\t\tclassName=\"stroke-white/90 dark:stroke-white/20\"\n\t\t\t\t/>\n\n\t\t\t\t{/* Diffuser lens. */}\n\t\t\t\t<path\n\t\t\t\t\td=\"M64 33.5H136C134 39.5 124 42.5 100 42.5C76 42.5 66 39.5 64 33.5Z\"\n\t\t\t\t\tfill={url(\"lens\")}\n\t\t\t\t/>\n\t\t\t\t<g className=\"opacity-0 transition-opacity duration-200 ease-out group-data-[state=on]/pull-cord:opacity-100 motion-reduce:transition-none\">\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M64 33.5H136C134 39.5 124 42.5 100 42.5C76 42.5 66 39.5 64 33.5Z\"\n\t\t\t\t\t\tfill={url(\"lens-on\")}\n\t\t\t\t\t/>\n\t\t\t\t\t<ellipse cx={100} cy={37.5} rx={28} ry={4} fill={url(\"lens-core\")} />\n\t\t\t\t</g>\n\t\t\t\t<path\n\t\t\t\t\td=\"M64 33.5H136\"\n\t\t\t\t\tstrokeWidth={0.75}\n\t\t\t\t\tclassName=\"stroke-black/12 dark:stroke-black/50\"\n\t\t\t\t/>\n\n\t\t\t\t{/* The bushing the chain runs through. */}\n\t\t\t\t<rect\n\t\t\t\t\tx={95}\n\t\t\t\t\ty={40.5}\n\t\t\t\t\twidth={10}\n\t\t\t\t\theight={2.5}\n\t\t\t\t\trx={1}\n\t\t\t\t\tfill={url(\"steel\")}\n\t\t\t\t/>\n\t\t\t\t<rect x={96} y={42} width={8} height={7} rx={1.6} fill={url(\"steel\")} />\n\t\t\t\t<rect\n\t\t\t\t\tx={96}\n\t\t\t\t\ty={42}\n\t\t\t\t\twidth={8}\n\t\t\t\t\theight={7}\n\t\t\t\t\trx={1.6}\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstrokeWidth={0.5}\n\t\t\t\t\tclassName=\"stroke-black/15 dark:stroke-black/40\"\n\t\t\t\t/>\n\t\t\t</svg>\n\n\t\t\t<button\n\t\t\t\tref={handleRef}\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=\"pull-cord-handle\"\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\tonClick={handleClick}\n\t\t\t\tonKeyDown={handleKeyDown}\n\t\t\t\tonContextMenu={(event) => event.preventDefault()}\n\t\t\t\tclassName=\"group/handle absolute top-0 left-0 h-16 w-12 cursor-grab touch-none outline-none will-change-transform [-webkit-tap-highlight-color:transparent] [-webkit-touch-callout:none] disabled:cursor-not-allowed group-data-pulling/pull-cord:cursor-grabbing\"\n\t\t\t\tstyle={{\n\t\t\t\t\ttransform: restTransform,\n\t\t\t\t\ttransformOrigin: `${PIVOT_IN_BUTTON.x}px ${PIVOT_IN_BUTTON.y}px`,\n\t\t\t\t}}\n\t\t\t>\n\t\t\t\t<span\n\t\t\t\t\taria-hidden\n\t\t\t\t\tclassName=\"absolute top-[5px] left-2.5 h-[58px] w-7 rounded-full group-focus-visible/handle:ring-3 group-focus-visible/handle:ring-ring/50 group-focus-visible/handle:ring-offset-2 group-focus-visible/handle:ring-offset-background\"\n\t\t\t\t/>\n\t\t\t\t<svg\n\t\t\t\t\taria-hidden\n\t\t\t\t\twidth={24}\n\t\t\t\t\theight={58}\n\t\t\t\t\tviewBox=\"0 0 24 58\"\n\t\t\t\t\tclassName=\"absolute top-0 left-3 overflow-visible drop-shadow-[0_5px_5px_rgb(0_0_0/0.16)] dark:drop-shadow-[0_5px_6px_rgb(0_0_0/0.55)]\"\n\t\t\t\t>\n\t\t\t\t\t<defs>\n\t\t\t\t\t\t<linearGradient id={gradientId(\"wood\")} x1=\"0\" y1=\"0\" x2=\"1\" y2=\"0\">\n\t\t\t\t\t\t\t<stop offset=\"0\" stopColor=\"#8a5a30\" />\n\t\t\t\t\t\t\t<stop offset=\"0.16\" stopColor=\"#b7824f\" />\n\t\t\t\t\t\t\t<stop offset=\"0.36\" stopColor=\"#e3bd8f\" />\n\t\t\t\t\t\t\t<stop offset=\"0.52\" stopColor=\"#d5a774\" />\n\t\t\t\t\t\t\t<stop offset=\"0.8\" stopColor=\"#a6713f\" />\n\t\t\t\t\t\t\t<stop offset=\"1\" stopColor=\"#7a4c25\" />\n\t\t\t\t\t\t</linearGradient>\n\t\t\t\t\t\t<linearGradient\n\t\t\t\t\t\t\tid={gradientId(\"wood-shade\")}\n\t\t\t\t\t\t\tx1=\"0\"\n\t\t\t\t\t\t\ty1=\"0\"\n\t\t\t\t\t\t\tx2=\"0\"\n\t\t\t\t\t\t\ty2=\"1\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<stop offset=\"0\" stopColor=\"#2b1a0c\" stopOpacity={0.35} />\n\t\t\t\t\t\t\t<stop offset=\"0.16\" stopColor=\"#2b1a0c\" stopOpacity={0} />\n\t\t\t\t\t\t\t<stop offset=\"0.72\" stopColor=\"#2b1a0c\" stopOpacity={0} />\n\t\t\t\t\t\t\t<stop offset=\"1\" stopColor=\"#2b1a0c\" stopOpacity={0.3} />\n\t\t\t\t\t\t</linearGradient>\n\t\t\t\t\t\t<linearGradient\n\t\t\t\t\t\t\tid={gradientId(\"wood-glint\")}\n\t\t\t\t\t\t\tx1=\"0\"\n\t\t\t\t\t\t\ty1=\"12\"\n\t\t\t\t\t\t\tx2=\"0\"\n\t\t\t\t\t\t\ty2=\"52\"\n\t\t\t\t\t\t\tgradientUnits=\"userSpaceOnUse\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<stop offset=\"0\" stopColor=\"#fff\" stopOpacity={0} />\n\t\t\t\t\t\t\t<stop offset=\"0.55\" stopColor=\"#fff\" stopOpacity={0.5} />\n\t\t\t\t\t\t\t<stop offset=\"1\" stopColor=\"#fff\" stopOpacity={0} />\n\t\t\t\t\t\t</linearGradient>\n\t\t\t\t\t</defs>\n\t\t\t\t\t{/* Turned oak drop. */}\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M9 8.5H15C15.6 18 22 28 22 41C22 49.6 17.6 55 12 55C6.4 55 2 49.6 2 41C2 28 8.4 18 9 8.5Z\"\n\t\t\t\t\t\tfill={url(\"wood\")}\n\t\t\t\t\t/>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M9 8.5H15C15.6 18 22 28 22 41C22 49.6 17.6 55 12 55C6.4 55 2 49.6 2 41C2 28 8.4 18 9 8.5Z\"\n\t\t\t\t\t\tfill={url(\"wood-shade\")}\n\t\t\t\t\t/>\n\t\t\t\t\t{/* Grain, following the turn. */}\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M11.4 11C11.8 22 16.2 30 16.4 41C16.5 47.5 14.6 51.5 12.6 53.6M10.2 13C9.4 24 6.4 32 6.6 42C6.7 46.5 7.6 49.5 8.8 51.5\"\n\t\t\t\t\t\tfill=\"none\"\n\t\t\t\t\t\tstroke=\"#5a3415\"\n\t\t\t\t\t\tstrokeOpacity={0.09}\n\t\t\t\t\t\tstrokeWidth={0.5}\n\t\t\t\t\t\tstrokeLinecap=\"round\"\n\t\t\t\t\t/>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M9.7 13C9 24 5.2 31 5.1 41C5 46 6.2 49.6 8 51.6\"\n\t\t\t\t\t\tfill=\"none\"\n\t\t\t\t\t\tstroke={url(\"wood-glint\")}\n\t\t\t\t\t\tstrokeWidth={1.4}\n\t\t\t\t\t\tstrokeLinecap=\"round\"\n\t\t\t\t\t/>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M9 8.5H15C15.6 18 22 28 22 41C22 49.6 17.6 55 12 55C6.4 55 2 49.6 2 41C2 28 8.4 18 9 8.5Z\"\n\t\t\t\t\t\tfill=\"none\"\n\t\t\t\t\t\tstroke=\"#4a2a10\"\n\t\t\t\t\t\tstrokeOpacity={0.22}\n\t\t\t\t\t\tstrokeWidth={0.5}\n\t\t\t\t\t/>\n\t\t\t\t\t{/* Steel ferrule the chain is crimped into. */}\n\t\t\t\t\t<rect\n\t\t\t\t\t\tx={9.5}\n\t\t\t\t\t\ty={0}\n\t\t\t\t\t\twidth={5}\n\t\t\t\t\t\theight={9.5}\n\t\t\t\t\t\trx={1.4}\n\t\t\t\t\t\tfill={url(\"steel\")}\n\t\t\t\t\t/>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M9.6 3.4H14.4M9.6 6H14.4\"\n\t\t\t\t\t\tstrokeWidth={0.45}\n\t\t\t\t\t\tclassName=\"stroke-black/20\"\n\t\t\t\t\t/>\n\t\t\t\t</svg>\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 PullCord;\n",
      "type": "registry:component",
      "target": "@components/pull-cord.tsx"
    }
  ],
  "meta": {
    "createdAt": "2026-11-03",
    "image": "https://cdn.tentui.com/images/components/pull-cord",
    "video": "https://cdn.tentui.com/videos/components/pull-cord"
  },
  "docs": "https://tentui.com/components/pull-cord",
  "categories": [
    "inputs"
  ],
  "type": "registry:component"
}