{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "effort-slider",
  "title": "Ultracode slider",
  "description": "Six-level effort slider whose last stop, Ultracode, grows a pulsing pixel trail from the thumb and fires a burst when the thumb lands.",
  "registryDependencies": [
    "https://elements.lumesec.ai/r/lumesec-theme.json",
    "https://elements.lumesec.ai/r/lumesec-canvas.json",
    "https://elements.lumesec.ai/r/lumesec-color.json",
    "https://elements.lumesec.ai/r/lumesec-math.json",
    "https://elements.lumesec.ai/r/lumesec-motion.json",
    "https://elements.lumesec.ai/r/lumesec-roll-text.json",
    "https://elements.lumesec.ai/r/lumesec-use-controllable-state.json",
    "utils"
  ],
  "files": [
    {
      "path": "registry/components/lumesec/effort-slider.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nimport { useCanvas, type CanvasSurface } from \"@/lib/lumesec/canvas\";\nimport { usePalette, type ColorToken, type Palette } from \"@/lib/lumesec/color\";\nimport { clamp, easeOutCubic, hash, mixRgb, rgba, smoothstep, TAU, type RGB } from \"@/lib/lumesec/math\";\nimport { prefersReducedMotion, springStep, useAnimationLoop, useLazyRef, useReducedMotion } from \"@/lib/lumesec/motion\";\nimport { ROLL_TIMING } from \"@/lib/lumesec/roll-text\";\nimport { useControllableState } from \"@/lib/lumesec/use-controllable-state\";\nimport { cn } from \"@/lib/utils\";\n\n/** Id of an effort level, from fastest to smartest. */\nexport type EffortLevel = \"low\" | \"medium\" | \"high\" | \"xhigh\" | \"max\" | \"ultracode\";\n\n/** One effort level: its id and its name in English and German. */\nexport interface EffortLevelInfo {\n  readonly id: EffortLevel;\n  readonly en: string;\n  readonly de: string;\n}\n\n/** The six levels, in slider order. `xhigh` is labelled \"Extra\". */\nexport const EFFORT_LEVELS: readonly EffortLevelInfo[] = [\n  { id: \"low\", en: \"Low\", de: \"Niedrig\" },\n  { id: \"medium\", en: \"Medium\", de: \"Mittel\" },\n  { id: \"high\", en: \"High\", de: \"Hoch\" },\n  { id: \"xhigh\", en: \"Extra\", de: \"Extra\" },\n  { id: \"max\", en: \"Max\", de: \"Max\" },\n  { id: \"ultracode\", en: \"Ultracode\", de: \"Ultracode\" },\n];\n\nexport interface EffortSliderProps extends Omit<React.ComponentProps<\"div\">, \"defaultValue\"> {\n  /** The committed level (controlled). Use with `onValueChange`. */\n  value?: EffortLevel;\n  /** The level the slider starts at when uncontrolled. */\n  defaultValue?: EffortLevel;\n  /** Called when the user commits a new level: on pointer release, or on each key press that changes the level. */\n  onValueChange?: (value: EffortLevel) => void;\n  /** Called on press and while dragging, each time the level under the pointer changes. */\n  onValueInput?: (value: EffortLevel) => void;\n  /** The level that gets the taller tick and the \"Recommended\" caption. */\n  recommended?: EffortLevel;\n  /**\n   * Language of the built-in text (title, end labels, caption, help note, level names): `de` or any `de-*`\n   * tag for German, anything else for English. Also set as the root's `lang` attribute.\n   */\n  lang?: string;\n  /** Dims the slider and blocks pointer and keyboard changes. The track and the help button leave the tab order. */\n  disabled?: boolean;\n}\n\n/**\n * Six-level effort slider. Every level is a plain slider stop until the last one: at Ultracode a pixel trail\n * grows out of the thumb toward the left, light pulses run along it and a burst fires when the thumb lands.\n * The level name rolls like a picker wheel in the direction of the change, and the thumb snaps on a slightly\n * under-damped spring.\n *\n * @example\n * <EffortSlider defaultValue=\"ultracode\" recommended=\"medium\" onValueChange={(level) => save(level)} />\n */\nexport function EffortSlider({\n  value,\n  defaultValue = \"ultracode\",\n  onValueChange,\n  onValueInput,\n  recommended = \"medium\",\n  lang,\n  disabled = false,\n  className,\n  ...props\n}: EffortSliderProps) {\n  const [committed, setCommitted] = useControllableState<EffortLevel>({ value, defaultValue, onChange: onValueChange });\n  const committedIndex = levelIndex(committed, LAST);\n  const recommendedIndex = levelIndex(recommended, 1);\n  const language = languageOf(lang);\n  const strings = STRINGS[language];\n  const reducedMotion = useReducedMotion();\n\n  /** The level under the pointer while dragging, else null. */\n  const [liveIndex, setLiveIndex] = React.useState<number | null>(null);\n  /** Ultracode styling (glowing thumb, dimmed ticks): on while the trail is out. */\n  const [lit, setLit] = React.useState(committedIndex === LAST);\n  const [noteOpen, setNoteOpen] = React.useState(false);\n  const noteId = React.useId();\n  const [captionHalfWidth, setCaptionHalfWidth] = React.useState(30);\n  // The server markup places the thumb with `left`; the loop moves it from there with a transform.\n  const [thumbOrigin] = React.useState(committedIndex / LAST);\n  const dragging = liveIndex !== null;\n  const shownIndex = liveIndex ?? committedIndex;\n\n  const panelRef = React.useRef<HTMLDivElement>(null);\n  const dotsRef = React.useRef<HTMLCanvasElement>(null);\n  const effectsRef = React.useRef<HTMLCanvasElement>(null);\n  const thumbRef = React.useRef<HTMLDivElement>(null);\n  const knobRef = React.useRef<HTMLDivElement>(null);\n  const flashRef = React.useRef<HTMLDivElement>(null);\n  const ringRefs = React.useRef<(HTMLDivElement | null)[]>([]);\n  const levelRef = React.useRef<HTMLSpanElement>(null);\n  const captionRef = React.useRef<HTMLSpanElement>(null);\n\n  const motionRef = useLazyRef(() => createMotion(committedIndex));\n  const track = React.useRef<TrackLayout>({ width: 0, height: 0, dots: [] });\n  const arrival = React.useRef<Animation[]>([]);\n  const glow = React.useRef<Animation | null>(null);\n\n  function measureCaption() {\n    const half = (captionRef.current?.offsetWidth ?? 0) / 2;\n    if (half) setCaptionHalfWidth(half);\n  }\n\n  const loop = useAnimationLoop(panelRef, step);\n  const colors = usePalette(panelRef, SLIDER_COLORS, () => loop.kick());\n  const dots = useCanvas(dotsRef, (surface) => {\n    track.current = { width: surface.width, height: surface.height, dots: buildLattice(surface.width, surface.height) };\n    measureCaption();\n    loop.kick();\n  });\n  const effects = useCanvas(effectsRef, () => loop.kick());\n\n  const stopGlow = React.useCallback(() => {\n    glow.current?.cancel();\n    glow.current = null;\n  }, []);\n  const startGlow = React.useCallback((delay: number) => {\n    glow.current?.cancel();\n    const knob = knobRef.current;\n    glow.current =\n      knob && typeof knob.animate === \"function\"\n        ? knob.animate(GLOW_KEYFRAMES, { duration: 2600, iterations: Infinity, delay })\n        : null;\n  }, []);\n\n  // A committed level that changes from outside (or is refused by a controlled parent) moves the thumb.\n  React.useEffect(() => {\n    const state = motionRef.current;\n    if (state.dragging || state.index === committedIndex) return;\n    state.index = committedIndex;\n    state.target = committedIndex;\n    if (prefersReducedMotion()) {\n      state.position = committedIndex;\n      state.velocity = 0;\n    }\n    loop.kick();\n  }, [committedIndex, dragging, motionRef, loop]);\n\n  // The thumb breathes while Ultracode is lit. The arrival burst may already have started it with a delay.\n  React.useEffect(() => {\n    if (!lit || reducedMotion) return;\n    if (!glow.current) startGlow(0);\n    return stopGlow;\n  }, [lit, reducedMotion, startGlow, stopGlow]);\n\n  // The ambient trail animation stops with reduced motion; restart the loop when that changes.\n  React.useEffect(() => {\n    loop.kick();\n  }, [reducedMotion, loop]);\n\n  React.useLayoutEffect(() => {\n    measureCaption();\n  }, [strings.recommended]);\n\n  function step(time: number, delta: number) {\n    const state = motionRef.current;\n    const { width } = track.current;\n    const now = time * 1000;\n    const reduced = prefersReducedMotion();\n\n    if (!state.dragging || state.grabGlide) {\n      if (reduced) {\n        state.position = state.target;\n        state.velocity = 0;\n      } else {\n        // under-damped spring: a small, quick overshoot on snap\n        springStep(state, state.target, delta);\n        state.position = clamp(state.position, -0.15, LAST + 0.15);\n      }\n    }\n\n    // Ultracode trail: grows out of the thumb toward the left, retracts faster\n    const ultraOn = state.dragging ? Math.round(clamp(state.position, 0, LAST)) === LAST : state.index === LAST;\n    const thumbX = xFor(clamp(state.position, 0, LAST), width);\n    if (!ultraOn) state.ultraLive = false;\n    else if (!state.ultraLive && state.position >= LAST - 0.12) fireArrival(now, thumbX); // the thumb has landed\n    const goal = ultraOn && state.ultraLive ? 1 : 0;\n    if (reduced) state.ultra = goal;\n    else if (state.ultra < goal) state.ultra = Math.min(goal, state.ultra + delta / GROW_SECONDS);\n    else if (state.ultra > goal) state.ultra = Math.max(goal, state.ultra - delta / RETRACT_SECONDS);\n    state.growing = ultraOn;\n    if (state.lit !== (goal === 1)) {\n      state.lit = goal === 1;\n      // stop the glow right away: the arrival burst may have started it before React rendered `lit`\n      if (!state.lit) stopGlow();\n      setLit(state.lit);\n    }\n\n    const thumb = thumbRef.current;\n    if (thumb && width) {\n      const offset = (clamp(state.position, 0, LAST) / LAST - thumbOrigin) * (width - THUMB_WIDTH);\n      thumb.style.transform = `translate3d(${offset.toFixed(2)}px,0,0)`;\n    }\n\n    const palette = colors.current;\n    const trail = palette ? trailColors(palette) : null;\n    const dotsSurface = dots.current;\n    if (trail && dotsSurface) drawTrail(dotsSurface.context, track.current, trail, state, thumbX, now, reduced);\n    const effectsSurface = effects.current;\n    const sparksLive =\n      trail && effectsSurface ? drawEffects(effectsSurface, track.current, trail, state, thumbX, now, delta) : false;\n\n    const bursting = sparksLive || (state.burstStart > 0 && now - state.burstStart < 1300);\n    const settled =\n      !state.dragging &&\n      Math.abs(state.position - state.target) < 0.0005 &&\n      Math.abs(state.velocity) < 0.001 &&\n      state.ultra === goal;\n    const ambient = !reduced && state.ultra > 0;\n    return !settled || ambient || bursting;\n  }\n\n  /** The thumb landed on Ultracode: let the trail out, and play the burst unless motion is reduced. */\n  function fireArrival(now: number, thumbX: number) {\n    const state = motionRef.current;\n    state.ultraLive = true;\n    if (prefersReducedMotion()) return;\n    state.burstStart = now;\n\n    for (const animation of arrival.current) animation.cancel();\n    const played: Animation[] = [];\n    const play = (element: Element | null | undefined, keyframes: Keyframe[], options: KeyframeAnimationOptions) => {\n      if (element && typeof element.animate === \"function\") played.push(element.animate(keyframes, options));\n    };\n    play(flashRef.current, FLASH_KEYFRAMES, { duration: 550, easing: \"cubic-bezier(.1,.8,.3,1)\" });\n    RING_TIMINGS.forEach((timing, i) =>\n      play(ringRefs.current[i], RING_KEYFRAMES, { ...timing, easing: \"cubic-bezier(.1,.75,.3,1)\" }),\n    );\n    play(knobRef.current, POP_KEYFRAMES, { duration: 550 });\n    play(panelRef.current, PANEL_KEYFRAMES, { duration: 1000, easing: \"cubic-bezier(.2,.8,.2,1)\" });\n    const word = levelRef.current?.lastElementChild;\n    if (word instanceof HTMLElement) {\n      word.style.transformOrigin = \"left center\";\n      play(word, LEVEL_POP_KEYFRAMES, { duration: 560, easing: \"cubic-bezier(.2,.8,.2,1)\" });\n    }\n    arrival.current = played;\n    startGlow(550);\n\n    const { height } = track.current;\n    state.sparks.push(...arrivalSparks(thumbX + FX_X, height / 2 + FX_Y));\n  }\n\n  function dragTo(trackElement: HTMLElement, clientX: number, first: boolean) {\n    const state = motionRef.current;\n    const position = positionOnTrack(trackElement, clientX);\n    if (first && !prefersReducedMotion()) {\n      // glide to the press point instead of jumping\n      state.target = position;\n      state.grabGlide = true;\n    } else {\n      state.grabGlide = false;\n      state.position = position;\n      state.velocity = 0;\n    }\n    const nearest = Math.round(position);\n    if (nearest !== state.lastInput) {\n      state.lastInput = nearest;\n      state.index = nearest;\n      setLiveIndex(nearest);\n      onValueInput?.(EFFORT_LEVELS[nearest].id);\n    }\n    loop.kick();\n  }\n\n  function handlePointerDown(event: React.PointerEvent<HTMLDivElement>) {\n    if (event.button !== 0 || disabled) return;\n    event.preventDefault();\n    const trackElement = event.currentTarget;\n    trackElement.focus({ preventScroll: true });\n    trackElement.setPointerCapture(event.pointerId);\n    const state = motionRef.current;\n    state.dragging = true;\n    state.lastInput = state.index;\n    setLiveIndex(state.index);\n    dragTo(trackElement, event.clientX, true);\n  }\n\n  function handlePointerMove(event: React.PointerEvent<HTMLDivElement>) {\n    if (motionRef.current.dragging) dragTo(event.currentTarget, event.clientX, false);\n  }\n\n  function handlePointerUp(event: React.PointerEvent<HTMLDivElement>) {\n    const state = motionRef.current;\n    if (!state.dragging) return;\n    const glide = state.grabGlide;\n    state.dragging = false;\n    state.grabGlide = false;\n    const trackElement = event.currentTarget;\n    if (trackElement.hasPointerCapture(event.pointerId)) trackElement.releasePointerCapture(event.pointerId);\n    // the burst already played during the drag when the thumb entered the last stop\n    const index = clamp(Math.round(glide ? state.target : state.position), 0, LAST);\n    state.index = index;\n    state.target = index;\n    setLiveIndex(null);\n    setCommitted(EFFORT_LEVELS[index].id);\n    loop.kick();\n  }\n\n  function handleKeyDown(event: React.KeyboardEvent<HTMLDivElement>) {\n    const { key } = event;\n    if (disabled || keyTarget(key, 0) === null) return;\n    event.preventDefault();\n    // from the latest committed level, so presses that arrive before a re-render still add up\n    setCommitted((previous) => EFFORT_LEVELS[clamp(keyTarget(key, levelIndex(previous, LAST)) ?? 0, 0, LAST)].id);\n  }\n\n  return (\n    <div\n      data-slot=\"effort-slider\"\n      data-disabled={disabled ? \"\" : undefined}\n      lang={lang}\n      className={cn(\n        \"inline-block w-[248px] max-w-full [-webkit-tap-highlight-color:transparent] data-[disabled]:pointer-events-none data-[disabled]:opacity-50\",\n        className,\n      )}\n      {...props}\n    >\n      <div\n        ref={panelRef}\n        className=\"grid gap-2.5 rounded-xl border border-border bg-card px-3 pt-3 pb-2.5 text-[13px] leading-[1.3] text-foreground shadow-[0_10px_30px_-10px_rgba(20,18,30,.25),0_2px_6px_-2px_rgba(20,18,30,.12)]\"\n      >\n        <div className=\"flex min-h-[22px] items-center gap-1.5\">\n          <span className=\"text-muted-foreground\">{strings.effort}</span>\n          <LevelName\n            ref={levelRef}\n            index={shownIndex}\n            text={levelLabel(shownIndex, language)}\n            reducedMotion={reducedMotion}\n          />\n          <button\n            type=\"button\"\n            aria-label={strings.help}\n            aria-expanded={noteOpen}\n            aria-controls={noteId}\n            disabled={disabled}\n            onClick={() => setNoteOpen((open) => !open)}\n            className=\"ml-auto grid size-[22px] cursor-pointer place-items-center rounded-md border-0 bg-transparent p-0 text-muted-foreground outline-none hover:bg-foreground/8 hover:text-foreground focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-lumesec focus-visible:outline-solid aria-expanded:bg-foreground/8 aria-expanded:text-foreground\"\n          >\n            <svg\n              viewBox=\"0 0 16 16\"\n              fill=\"none\"\n              stroke=\"currentColor\"\n              strokeWidth={1.3}\n              strokeLinecap=\"round\"\n              aria-hidden=\"true\"\n              className=\"size-3.5\"\n            >\n              <circle cx=\"8\" cy=\"8\" r=\"6.4\" />\n              <path d=\"M6.3 6.2a1.8 1.8 0 0 1 3.5.5c0 1.2-1.8 1.5-1.8 2.6\" />\n              <circle cx=\"8\" cy=\"11.4\" r=\".5\" fill=\"currentColor\" stroke=\"none\" />\n            </svg>\n          </button>\n        </div>\n        <p id={noteId} hidden={!noteOpen} className=\"-mt-1 mb-0 text-[12px] leading-[1.45] text-muted-foreground\">\n          {strings.note}\n        </p>\n        <div aria-hidden=\"true\" className=\"flex justify-between text-[12px] text-muted-foreground\">\n          <span>{strings.faster}</span>\n          <span>{strings.smarter}</span>\n        </div>\n        <div\n          role=\"slider\"\n          tabIndex={disabled ? -1 : 0}\n          aria-label={strings.effort}\n          aria-valuemin={0}\n          aria-valuemax={LAST}\n          aria-valuenow={shownIndex}\n          aria-valuetext={levelLabel(shownIndex, language)}\n          aria-disabled={disabled || undefined}\n          data-dragging={dragging ? \"\" : undefined}\n          data-ultra={lit ? \"\" : undefined}\n          onPointerDown={handlePointerDown}\n          onPointerMove={handlePointerMove}\n          onPointerUp={handlePointerUp}\n          onPointerCancel={handlePointerUp}\n          onKeyDown={handleKeyDown}\n          className=\"group/track relative h-[22px] cursor-pointer touch-none rounded-lg bg-muted outline-none focus-visible:shadow-[0_0_0_2px_var(--card),0_0_0_4px_var(--lumesec)] data-[dragging]:cursor-grabbing\"\n        >\n          <canvas ref={dotsRef} aria-hidden=\"true\" className=\"absolute inset-0 block size-full rounded-lg\" />\n          <div className=\"pointer-events-none absolute inset-0\">\n            {EFFORT_LEVELS.map((level, i) => (\n              <div\n                key={level.id}\n                className={cn(\n                  \"absolute top-2 -ml-px h-1.5 w-0.5 rounded-[1px] bg-foreground/24 [transition:opacity_.3s_ease,background-color_.3s_ease] group-data-[ultra]/track:opacity-45\",\n                  i === recommendedIndex && \"top-1.5 h-2.5 bg-foreground/48\",\n                )}\n                style={{ left: stopOffset(i) }}\n              />\n            ))}\n          </div>\n          <canvas\n            ref={effectsRef}\n            aria-hidden=\"true\"\n            className=\"pointer-events-none absolute -top-10 -left-8 z-[1] block h-[calc(100%+80px)] w-[calc(100%+64px)]\"\n          />\n          <div\n            ref={thumbRef}\n            className=\"pointer-events-none absolute top-0 z-[2] h-[22px] w-4 will-change-transform\"\n            style={{ left: `calc((100% - ${THUMB_WIDTH}px) * ${thumbOrigin})` }}\n          >\n            <div\n              ref={flashRef}\n              className=\"absolute top-1/2 left-1/2 -mt-8 -ml-8 size-16 rounded-full bg-[radial-gradient(circle,var(--lumesec-glint)_0%,color-mix(in_srgb,var(--lumesec)_70%,transparent)_30%,transparent_68%)] opacity-0\"\n            />\n            {RING_TIMINGS.map((timing, i) => (\n              <div\n                key={timing.duration}\n                ref={(node) => {\n                  ringRefs.current[i] = node;\n                }}\n                className=\"absolute inset-0 rounded-[7px] border-2 border-lumesec opacity-0\"\n              />\n            ))}\n            <div\n              ref={knobRef}\n              className=\"absolute inset-0 rounded-md bg-white shadow-[0_1px_2px_rgba(0,0,0,.28),0_0_0_.5px_rgba(0,0,0,.18)] [transition:transform_.18s_cubic-bezier(.2,.8,.2,1),box-shadow_.4s_ease] group-data-[dragging]/track:[transform:scale(.9,.94)] group-data-[ultra]/track:shadow-[0_1px_2px_rgba(0,0,0,.28),0_0_0_1px_color-mix(in_srgb,var(--lumesec)_55%,transparent),0_0_14px_2px_color-mix(in_srgb,var(--lumesec)_50%,transparent)] motion-reduce:transition-none\"\n            />\n          </div>\n        </div>\n        <div aria-hidden=\"true\" className=\"relative h-[15px]\">\n          <span\n            ref={captionRef}\n            className=\"absolute top-0 -translate-x-1/2 text-[11.5px] whitespace-nowrap text-muted-foreground\"\n            style={{\n              left: `clamp(${captionHalfWidth}px, ${stopOffset(recommendedIndex)}, calc(100% - ${captionHalfWidth}px))`,\n            }}\n          >\n            {strings.recommended}\n          </span>\n        </div>\n      </div>\n    </div>\n  );\n}\n\n/* Level name ---------------------------------------------------------------------------------------- */\n\ninterface WordMotion {\n  /** 1: toward \"Smarter\", the wheel scrolls up and the new name rolls in from below. -1: the other way. */\n  direction: number;\n  animate: boolean;\n}\n\ninterface LevelWord {\n  key: number;\n  text: string;\n  ultra: boolean;\n  enter: WordMotion;\n  /** Set once a newer name replaces this one. */\n  exit: WordMotion | null;\n}\n\nconst STILL: WordMotion = { direction: 1, animate: false };\n\n/** Masks the top and bottom 6px so the rolling names fade at the edges, like a scroll wheel window. */\nconst LEVEL_MASK = \"linear-gradient(to bottom, transparent 0, #000 6px, #000 calc(100% - 6px), transparent 100%)\";\n\n/**\n * Picker-wheel label: names roll on a small drum. Ultracode does not roll; it materialises, shimmers, and pops\n * when the thumb lands. The current name is always the last child (the arrival burst animates it).\n */\nfunction LevelName({\n  index,\n  text,\n  reducedMotion,\n  ref,\n}: {\n  index: number;\n  text: string;\n  reducedMotion: boolean;\n  ref: React.Ref<HTMLSpanElement>;\n}) {\n  const [state, setState] = React.useState<{ index: number; text: string; words: LevelWord[] }>(() => ({\n    index,\n    text,\n    words: [{ key: 0, text, ultra: index === LAST, enter: STILL, exit: null }],\n  }));\n\n  // Derive the word list during render, so the new name is in the first paint after the change.\n  if (state.text !== text) {\n    const current = state.words[state.words.length - 1];\n    // a language change swaps the name in place; reduced motion swaps it too\n    const change: WordMotion = {\n      direction: index > state.index ? 1 : -1,\n      animate: index !== state.index && !reducedMotion,\n    };\n    const next: LevelWord = { key: current.key + 1, text, ultra: index === LAST, enter: change, exit: null };\n    // keep at most two outgoing names when the level changes faster than the animation\n    const words = change.animate ? [...state.words.slice(-2, -1), { ...current, exit: change }, next] : [next];\n    setState({ index, text, words });\n  }\n\n  const removeWord = React.useCallback((key: number) => {\n    setState((value) => ({ ...value, words: value.words.filter((word) => word.key !== key) }));\n  }, []);\n\n  return (\n    <span\n      ref={ref}\n      aria-hidden=\"true\"\n      className=\"relative -my-1.5 inline-grid justify-items-start py-1.5 font-semibold tracking-[.005em] [perspective:180px]\"\n      style={{ maskImage: LEVEL_MASK, WebkitMaskImage: LEVEL_MASK }}\n    >\n      {state.words.map((word) => (\n        <LevelNameWord key={word.key} word={word} reducedMotion={reducedMotion} onExited={removeWord} />\n      ))}\n    </span>\n  );\n}\n\nfunction LevelNameWord({\n  word,\n  reducedMotion,\n  onExited,\n}: {\n  word: LevelWord;\n  reducedMotion: boolean;\n  onExited: (key: number) => void;\n}) {\n  const node = React.useRef<HTMLSpanElement>(null);\n  const { key, ultra, enter, exit } = word;\n\n  React.useLayoutEffect(() => {\n    const element = node.current;\n    if (!element || !enter.animate || typeof element.animate !== \"function\") return;\n    const animation = ultra\n      ? element.animate(ULTRA_ENTER_KEYFRAMES, { duration: 220, easing: \"cubic-bezier(.2,.8,.2,1)\" })\n      : element.animate(rollInKeyframes(enter.direction), ROLL_TIMING);\n    return () => animation.cancel();\n  }, [enter, ultra]);\n\n  React.useLayoutEffect(() => {\n    if (!exit) return;\n    const element = node.current;\n    if (!element || typeof element.animate !== \"function\") {\n      onExited(key);\n      return;\n    }\n    // same timing as the incoming name so both ride the drum together\n    const animation = ultra\n      ? element.animate(ULTRA_EXIT_KEYFRAMES, { duration: 200, easing: \"ease-out\", fill: \"forwards\" })\n      : element.animate(rollOutKeyframes(exit.direction), { ...ROLL_TIMING, fill: \"forwards\" });\n    animation.onfinish = () => onExited(key);\n    return () => {\n      animation.onfinish = null;\n      animation.cancel();\n    };\n  }, [exit, ultra, key, onExited]);\n\n  React.useEffect(() => {\n    const element = node.current;\n    if (!ultra || reducedMotion || !element || typeof element.animate !== \"function\") return;\n    const animation = element.animate(SHIMMER_KEYFRAMES, { duration: 2600, iterations: Infinity });\n    return () => animation.cancel();\n  }, [ultra, reducedMotion]);\n\n  return (\n    <span\n      ref={node}\n      className={cn(\n        \"col-start-1 row-start-1 inline-block [transform-origin:50%_50%_-11px] whitespace-nowrap will-change-[transform,opacity] [backface-visibility:hidden]\",\n        ultra &&\n          \"bg-[linear-gradient(100deg,var(--lumesec)_0%,var(--lumesec)_38%,var(--lumesec-glint)_50%,var(--lumesec)_62%,var(--lumesec)_100%)] [background-size:260%_100%] bg-clip-text [background-position:100%_0] text-transparent\",\n      )}\n    >\n      {word.text}\n    </span>\n  );\n}\n\n/* Constants ------------------------------------------------------------------------------------------ */\n\nconst LAST = EFFORT_LEVELS.length - 1;\n\n// Geometry in CSS pixels\nconst THUMB_WIDTH = 16;\nconst TRACK_PAD = THUMB_WIDTH / 2;\nconst DOT_PITCH = 3.5;\nconst DOT_SIZE = 1.5;\n/** The trail covers three quarters of the track. */\nconst TRAIL_LENGTH = 0.75;\n/** Seconds for the trail to shoot out. */\nconst GROW_SECONDS = 0.6;\n/** Seconds to pull back into the thumb. */\nconst RETRACT_SECONDS = 0.35;\n/** How far burst sparks may fly past the track. */\nconst FX_X = 32;\nconst FX_Y = 40;\n\ninterface SliderStrings {\n  effort: string;\n  faster: string;\n  smarter: string;\n  recommended: string;\n  help: string;\n  note: string;\n}\n\nconst STRINGS: Record<\"en\" | \"de\", SliderStrings> = {\n  en: {\n    effort: \"Effort\",\n    faster: \"Faster\",\n    smarter: \"Smarter\",\n    recommended: \"Recommended\",\n    help: \"About effort\",\n    note: \"Higher effort thinks longer before answering. Ultracode also lets the agent plan multi-agent workflows on its own.\",\n  },\n  de: {\n    effort: \"Aufwand\",\n    faster: \"Schneller\",\n    smarter: \"Intelligenter\",\n    recommended: \"Empfohlen\",\n    help: \"Über Aufwand\",\n    note: \"Mehr Aufwand heißt längeres Nachdenken vor der Antwort. Ultracode lässt den Agenten zusätzlich eigenständig Multi-Agent-Workflows planen.\",\n  },\n};\n\nconst SLIDER_COLORS = {\n  accent: [\"--lumesec\", \"#6219f3\"],\n  glint: [\"--lumesec-glint\", \"#c9bdff\"],\n  muted: [\"--muted-foreground\", \"#71717b\"],\n  card: [\"--card\", \"#ffffff\"],\n} as const satisfies Record<string, ColorToken>;\n\nconst PANEL_SHADOW = \"0 10px 30px -10px rgba(20,18,30,.25), 0 2px 6px -2px rgba(20,18,30,.12)\";\nconst KNOB_DROP = \"0 1px 2px rgba(0,0,0,.28)\";\nconst accentMix = (percent: number) => `color-mix(in srgb, var(--lumesec) ${percent}%, transparent)`;\n\nconst GLOW_KEYFRAMES: Keyframe[] = [\n  { boxShadow: `${KNOB_DROP}, 0 0 0 1px ${accentMix(55)}, 0 0 10px 1px ${accentMix(40)}`, easing: \"ease-in-out\" },\n  {\n    boxShadow: `${KNOB_DROP}, 0 0 0 1px ${accentMix(75)}, 0 0 18px 4px ${accentMix(60)}`,\n    easing: \"ease-in-out\",\n    offset: 0.5,\n  },\n  { boxShadow: `${KNOB_DROP}, 0 0 0 1px ${accentMix(55)}, 0 0 10px 1px ${accentMix(40)}` },\n];\n\nconst POP_EASING = \"cubic-bezier(.2,1.5,.4,1)\";\nconst POP_KEYFRAMES: Keyframe[] = [\n  { transform: \"scale(.82)\", easing: POP_EASING },\n  { transform: \"scale(1.28, 1.16)\", easing: POP_EASING, offset: 0.4 },\n  { transform: \"scale(1)\" },\n];\n\n/** Three rings ripple out of the thumb, the later ones slower (in DOM order, bottom to top). */\nconst RING_TIMINGS = [\n  { duration: 900, delay: 80 },\n  { duration: 1050, delay: 180 },\n  { duration: 750, delay: 0 },\n];\nconst RING_KEYFRAMES: Keyframe[] = [\n  { opacity: 1, transform: \"scale(1)\" },\n  { opacity: 0, transform: \"scale(4.2, 2.8)\" },\n];\nconst FLASH_KEYFRAMES: Keyframe[] = [\n  { opacity: 1, transform: \"scale(.3)\" },\n  { opacity: 0, transform: \"scale(1.9)\" },\n];\nconst PANEL_KEYFRAMES: Keyframe[] = [\n  {\n    borderColor: \"var(--lumesec)\",\n    boxShadow: `${PANEL_SHADOW}, 0 0 0 1px ${accentMix(60)}, 0 0 48px 6px ${accentMix(38)}`,\n  },\n  { borderColor: \"var(--border)\", boxShadow: `${PANEL_SHADOW}, 0 0 0 0 transparent, 0 0 0 0 transparent` },\n];\nconst LEVEL_POP_KEYFRAMES: Keyframe[] = [\n  { transform: \"scale(.75)\", opacity: 0, filter: \"blur(3px)\" },\n  { transform: \"scale(1.16)\", opacity: 1, filter: \"blur(0) brightness(1.7)\", offset: 0.45 },\n  { transform: \"scale(1)\", opacity: 1, filter: \"blur(0) brightness(1)\" },\n];\nconst SHIMMER_KEYFRAMES: Keyframe[] = [\n  { backgroundPosition: \"100% 0\", easing: \"cubic-bezier(.45,0,.25,1)\" },\n  { backgroundPosition: \"0% 0\", offset: 0.7 },\n  { backgroundPosition: \"0% 0\" },\n];\nconst ULTRA_ENTER_KEYFRAMES: Keyframe[] = [\n  { opacity: 0, transform: \"scale(.8)\", filter: \"blur(3px)\" },\n  { opacity: 1, transform: \"scale(1)\", filter: \"blur(0)\" },\n];\nconst ULTRA_EXIT_KEYFRAMES: Keyframe[] = [\n  { opacity: 1, transform: \"scale(1)\", filter: \"blur(0)\" },\n  { opacity: 0, transform: \"scale(.85)\", filter: \"blur(3px)\" },\n];\n\nconst rollInKeyframes = (direction: number): Keyframe[] => [\n  { opacity: 0, transform: `rotateX(${-direction * 88}deg)`, filter: \"blur(1.2px)\", offset: 0 },\n  { opacity: 1, filter: \"blur(0)\", offset: 0.55 },\n  { opacity: 1, transform: \"rotateX(0deg)\", filter: \"blur(0)\", offset: 1 },\n];\n\nconst rollOutKeyframes = (direction: number): Keyframe[] => [\n  { opacity: 1, transform: \"rotateX(0deg)\", filter: \"blur(0)\", offset: 0 },\n  { opacity: 0.35, offset: 0.45 },\n  { opacity: 0, transform: `rotateX(${direction * 88}deg)`, filter: \"blur(1.2px)\", offset: 1 },\n];\n\n/* Motion state and drawing --------------------------------------------------------------------------- */\n\n/** A dot of the lattice the trail lights up. */\ninterface Dot {\n  x: number;\n  y: number;\n  /** Random threshold: the dot shows where the trail's density exceeds it. */\n  density: number;\n  /** Offsets the reveal so the growing front looks organic. */\n  jitter: number;\n  /** Twinkle phase and speed. */\n  phase: number;\n  speed: number;\n}\n\ninterface TrackLayout {\n  width: number;\n  height: number;\n  dots: Dot[];\n}\n\ninterface TrailSpark {\n  x: number;\n  y: number;\n  vx: number;\n  vy: number;\n  age: number;\n  life: number;\n  size: number;\n  /** How far toward the glint this spark is tinted. */\n  mix: number;\n}\n\ninterface TrailColors {\n  dot: RGB;\n  accent: RGB;\n  glint: RGB;\n}\n\n/** Everything the animation loop mutates. Lives in a ref, never in React state. */\ninterface SliderMotion {\n  /** Thumb position in levels: 0 to 5, overshooting slightly on the spring. */\n  position: number;\n  velocity: number;\n  /** Where the spring pulls the thumb. */\n  target: number;\n  /** The level the slider shows: the one under the pointer while dragging, else the committed one. */\n  index: number;\n  /** Trail growth, 0 (hidden) to 1 (full length). */\n  ultra: number;\n  /** Whether the trail may be out: true once the arrival burst fired, or when the slider starts at Ultracode. */\n  ultraLive: boolean;\n  /** Whether the trail is growing (eased) rather than retracting (linear). */\n  growing: boolean;\n  /** Time of the last arrival burst in ms, or -1. */\n  burstStart: number;\n  dragging: boolean;\n  /** A press glides the thumb to the press point; moving the pointer then drags it directly. */\n  grabGlide: boolean;\n  /** The level `onValueInput` last reported. */\n  lastInput: number;\n  /** Mirrors the `lit` state, so the loop sets it only when it changes. */\n  lit: boolean;\n  sparks: TrailSpark[];\n  /** Whether the effects canvas has something on it that needs clearing. */\n  fxDirty: boolean;\n}\n\nfunction createMotion(index: number): SliderMotion {\n  // the trail is already out (no burst) when the slider starts at Ultracode\n  const atUltracode = index === LAST;\n  return {\n    position: index,\n    velocity: 0,\n    target: index,\n    index,\n    ultra: atUltracode ? 1 : 0,\n    ultraLive: atUltracode,\n    growing: atUltracode,\n    burstStart: -1,\n    dragging: false,\n    grabGlide: false,\n    lastInput: index,\n    lit: atUltracode,\n    sparks: [],\n    fxDirty: false,\n  };\n}\n\nfunction levelIndex(id: string, fallback: number) {\n  const index = EFFORT_LEVELS.findIndex((level) => level.id === id);\n  return index >= 0 ? index : fallback;\n}\n\n/** The level a key moves to from `index` (unclamped), or null for keys the slider ignores. */\nfunction keyTarget(key: string, index: number) {\n  switch (key) {\n    case \"ArrowRight\":\n    case \"ArrowUp\":\n      return index + 1;\n    case \"ArrowLeft\":\n    case \"ArrowDown\":\n      return index - 1;\n    case \"Home\":\n    case \"PageDown\":\n      return 0;\n    case \"End\":\n    case \"PageUp\":\n      return LAST;\n    default:\n      return null;\n  }\n}\n\n/** German for `de` and any `de-*` tag (case-insensitive, as language tags are), English otherwise. */\nfunction languageOf(lang: string | undefined): \"en\" | \"de\" {\n  return lang && /^de(-|$)/i.test(lang) ? \"de\" : \"en\";\n}\n\nconst levelLabel = (index: number, language: \"en\" | \"de\") => EFFORT_LEVELS[index][language];\n\n/** CSS `left` of a stop on the track: the thumb's centre never leaves the track. */\nconst stopOffset = (index: number) => `calc(${TRACK_PAD}px + (100% - ${TRACK_PAD * 2}px) * ${index / LAST})`;\n\nconst xFor = (position: number, width: number) => TRACK_PAD + (position / LAST) * (width - 2 * TRACK_PAD);\n\nfunction positionOnTrack(trackElement: HTMLElement, clientX: number) {\n  const rect = trackElement.getBoundingClientRect();\n  return clamp((clientX - rect.left - TRACK_PAD) / (rect.width - 2 * TRACK_PAD), 0, 1) * LAST;\n}\n\n/** The lattice grey sits a third of the way from the muted text colour to the card, in both themes. */\nconst trailColors = (palette: Palette<keyof typeof SLIDER_COLORS>): TrailColors => ({\n  dot: mixRgb(palette.muted, palette.card, 1 / 3),\n  accent: palette.accent,\n  glint: palette.glint,\n});\n\nfunction buildLattice(width: number, height: number) {\n  const columns = Math.floor((width - 4) / DOT_PITCH);\n  const rows = Math.floor((height - 4) / DOT_PITCH);\n  const left = (width - (columns - 1) * DOT_PITCH) / 2;\n  const top = (height - (rows - 1) * DOT_PITCH) / 2;\n  const dots: Dot[] = [];\n  for (let column = 0; column < columns; column++) {\n    for (let row = 0; row < rows; row++) {\n      const seed = column * 31 + row * 7 + 1;\n      dots.push({\n        x: left + column * DOT_PITCH,\n        y: top + row * DOT_PITCH,\n        density: hash(seed),\n        jitter: hash(seed + 1.13),\n        phase: hash(seed + 0.37) * TAU,\n        speed: 2 + hash(seed + 0.71) * 5,\n      });\n    }\n  }\n  return dots;\n}\n\n/** Pixel sparks for the arrival burst: most shoot left along the trail, some spray all around. */\nfunction arrivalSparks(x: number, y: number): TrailSpark[] {\n  return Array.from({ length: 110 }, (_, i) => {\n    const alongTrail = i < 78;\n    const angle = alongTrail ? Math.PI + (Math.random() - 0.5) * 1.3 : Math.random() * TAU;\n    const speed = alongTrail ? 160 + Math.random() * 520 : 70 + Math.random() * 230;\n    return {\n      x: x + (Math.random() - 0.5) * 6,\n      y: y + (Math.random() - 0.5) * 14,\n      vx: Math.cos(angle) * speed,\n      vy: Math.sin(angle) * speed * (alongTrail ? 0.75 : 1),\n      age: 0,\n      life: 0.45 + Math.random() * 0.75,\n      size: Math.random() < 0.25 ? 2.5 : 1.5,\n      mix: Math.random(),\n    };\n  });\n}\n\n/** The Ultracode trail on the track's dot lattice. Every other level leaves the track plain. */\nfunction drawTrail(\n  context: CanvasRenderingContext2D,\n  track: TrackLayout,\n  colors: TrailColors,\n  state: SliderMotion,\n  thumbX: number,\n  now: number,\n  reduced: boolean,\n) {\n  const { width, height } = track;\n  if (!width) return;\n  context.clearRect(0, 0, width, height);\n  if (state.ultra <= 0) return;\n  const growth = state.growing ? easeOutCubic(state.ultra) : state.ultra; // shoots out, then settles\n  const { dot, accent, glint } = colors;\n  const t = now / 1000;\n  const start = thumbX - THUMB_WIDTH / 2; // the trail starts at the thumb's left edge\n  const length = width * TRAIL_LENGTH; // and reaches three quarters of the track\n\n  // soft violet bloom behind the trail, strongest at the thumb\n  const bloom = context.createLinearGradient(start, 0, start - length, 0);\n  bloom.addColorStop(0, rgba(accent, 0.26 * smoothstep(0, 0.35, growth)));\n  bloom.addColorStop(1, rgba(accent, 0));\n  context.fillStyle = bloom;\n  context.fillRect(Math.max(0, start - length), 0, Math.min(length, start), height);\n\n  // light pulses, travelling right to left (0 = thumb, 1 = end of trail)\n  const pulses = reduced ? [] : [(t * 0.48) % 1.3, (t * 0.48 + 0.62) % 1.3];\n  const pulseStrength = reduced ? 0 : smoothstep(0.55, 1, growth);\n  const flashWindow = state.growing && !reduced ? 1 - smoothstep(0.9, 1, growth) : 0;\n  const since = now - state.burstStart;\n  const burstGlow = state.burstStart > 0 && since < 1500 && !reduced ? Math.exp(-since / 280) : 0;\n\n  for (const d of track.dots) {\n    const n = (start - d.x) / length;\n    if (n < 0 || n > 1) continue;\n\n    // procedural reveal: near dots first, with jitter so the front looks organic\n    const threshold = n * 0.82 + d.jitter * 0.18;\n    const appear = clamp((growth - threshold) / 0.07, 0, 1);\n    if (appear <= 0) continue;\n\n    let pulse = 0;\n    for (const p of pulses) {\n      const distance = n - p;\n      pulse += Math.exp(-(distance * distance) / (2 * 0.045 * 0.045));\n    }\n    pulse = Math.min(1, pulse) * pulseStrength * (1 - n * 0.35);\n\n    const density = 0.9 - 0.8 * Math.pow(n, 0.85) + pulse * 0.25 + burstGlow * 0.75;\n    if (d.density > density) continue;\n\n    let alpha = 0.95 - 0.68 * n;\n    let tint = 1 - smoothstep(0.2, 1, n) * 0.85;\n    let white = 0;\n\n    if (flashWindow > 0) {\n      const flash = Math.exp(-(growth - threshold) / 0.05) * flashWindow;\n      alpha += flash * 0.5;\n      white += flash * 0.7;\n    }\n    if (!reduced) alpha *= 0.66 + 0.34 * Math.sin(t * d.speed + d.phase);\n    alpha += pulse * 0.6 + burstGlow * 0.7;\n    white += pulse * 0.55 + burstGlow * 0.55;\n    alpha *= appear * (1 - smoothstep(0.82, 1, n) * 0.6);\n\n    alpha = clamp(alpha, 0, 1);\n    if (alpha < 0.02) continue;\n    tint = clamp(tint, 0, 1);\n    white = clamp(white, 0, 1);\n    // lattice grey toward the accent along the trail, then toward the glint where it flashes (inlined: hot loop)\n    const red = (dot[0] + (accent[0] - dot[0]) * tint) * (1 - white) + glint[0] * white;\n    const green = (dot[1] + (accent[1] - dot[1]) * tint) * (1 - white) + glint[1] * white;\n    const blue = (dot[2] + (accent[2] - dot[2]) * tint) * (1 - white) + glint[2] * white;\n    context.globalAlpha = alpha;\n    context.fillStyle = `rgb(${red | 0},${green | 0},${blue | 0})`;\n    context.fillRect(d.x - DOT_SIZE / 2, d.y - DOT_SIZE / 2, DOT_SIZE, DOT_SIZE);\n  }\n  context.globalAlpha = 1;\n}\n\n/** The arrival shock streak and sparks, on the canvas that extends past the track. Returns whether anything is alive. */\nfunction drawEffects(\n  surface: CanvasSurface,\n  track: TrackLayout,\n  colors: TrailColors,\n  state: SliderMotion,\n  thumbX: number,\n  now: number,\n  delta: number,\n) {\n  const { context, width, height } = surface;\n  const since = now - state.burstStart;\n  const shock = state.burstStart > 0 && since < 420;\n  if (!state.sparks.length && !shock) {\n    if (state.fxDirty) {\n      context.clearRect(0, 0, width, height);\n      state.fxDirty = false;\n    }\n    return false;\n  }\n  state.fxDirty = true;\n  const { accent, glint } = colors;\n  context.clearRect(0, 0, width, height);\n  const cx = thumbX + FX_X;\n  const cy = track.height / 2 + FX_Y;\n\n  // shock streak: a light beam fired left along the track\n  if (shock) {\n    const k = since / 420;\n    const reach = easeOutCubic(k * 1.6) * track.width * 0.9;\n    const alpha = 0.55 * (1 - k);\n    const beam = context.createLinearGradient(cx, 0, cx - reach, 0);\n    beam.addColorStop(0, rgba(glint, alpha));\n    beam.addColorStop(0.25, rgba(accent, alpha * 0.8));\n    beam.addColorStop(1, rgba(accent, 0));\n    context.fillStyle = beam;\n    const thickness = 3 + 8 * (1 - k);\n    context.fillRect(cx - reach, cy - thickness / 2, reach, thickness);\n  }\n\n  const drag = Math.exp(-delta * 3.4);\n  const alive: TrailSpark[] = [];\n  for (const spark of state.sparks) {\n    spark.age += delta;\n    if (spark.age >= spark.life) continue;\n    spark.vx *= drag;\n    spark.vy *= drag;\n    spark.x += spark.vx * delta;\n    spark.y += spark.vy * delta;\n    const life = 1 - spark.age / spark.life;\n    const hot = Math.max(0, 1 - spark.age / 0.12);\n    const color = mixRgb(accent, glint, Math.min(1, spark.mix * 0.6 + hot));\n    context.globalAlpha = Math.pow(life, 1.3);\n    context.fillStyle = `rgb(${color[0] | 0},${color[1] | 0},${color[2] | 0})`;\n    // snap to the pixel lattice feel: square sparks\n    context.fillRect(Math.round(spark.x * 2) / 2, Math.round(spark.y * 2) / 2, spark.size, spark.size);\n    alive.push(spark);\n  }\n  context.globalAlpha = 1;\n  state.sparks = alive;\n  return alive.length > 0 || shock;\n}\n",
      "type": "registry:component",
      "target": "@components/lumesec/effort-slider.tsx"
    }
  ],
  "meta": {
    "tag": "effort-slider",
    "collection": "interaction",
    "react": "EffortSlider",
    "kind": "react"
  },
  "docs": "Ultracode slider docs: https://elements.lumesec.ai/components/interaction/ultracode-slider",
  "categories": [
    "interaction",
    "controls"
  ],
  "type": "registry:component"
}