{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "spring-editor",
  "title": "Spring editor",
  "description": "a spring in time (duration, bounce) or physics (stiffness, damping, mass) · the switch converts · graph and preview",
  "dependencies": [
    "cn@^0.5.2"
  ],
  "registryDependencies": [
    "@halftone-web/control-segmented",
    "@halftone-web/curve-editor",
    "@halftone-web/kit-setup",
    "@halftone-web/lib-controls-spring",
    "@halftone-web/number-field"
  ],
  "files": [
    {
      "path": "components/controls/spring-editor.tsx",
      "content": "'use client';\nimport { cn } from 'cn';\nimport * as React from 'react';\nimport { MotionPreview } from '@/components/controls/curve-editor';\nimport { NumberField } from '@/components/controls/number-field';\nimport { ControlSegmented } from '@/components/controls/segmented';\nimport { convertSpring, sampleSpring, settleTime, SPRING_RANGES, springToCss, type Spring, type SpringMode } from '@/lib/controls/spring';\n\nconst W = 200;\nconst H = 96;\n/** Room above the target line for the overshoot. */\nconst TOP = 24;\n\n/**\n * A spring, tuned in either of the two ways people think of one:\n * - **Time:** how long it looks and how much it bounces (Motion's `visualDuration` and `bounce`);\n * - **Physics:** stiffness, damping and mass.\n *\n * The switch converts between them, so the motion stays the same. The graph shows the spring from release to rest\n * (the dashed line is where it's heading), with how long it takes to settle, and the preview plays it.\n */\nexport function SpringEditor({ label, value, onChange, className }: { label: string; value: Spring; onChange: (value: Spring) => void; className?: string }) {\n  const samples = React.useMemo(() => sampleSpring(value, { points: 80 }), [value]);\n  const settle = React.useMemo(() => settleTime(value), [value]);\n  const css = React.useMemo(() => springToCss(value), [value]);\n  const peak = Math.max(1, ...samples.map((s) => s.value));\n  const scaleY = (H - TOP) / Math.max(peak, 1.0001);\n  const points = samples.map((s, i) => `${((i / (samples.length - 1)) * W).toFixed(1)},${(H - s.value * scaleY).toFixed(1)}`).join(' ');\n  const target = H - scaleY;\n  // Overshoot as a whole percent; under 1% reads as none.\n  const overshoot = Math.round((peak - 1) * 100);\n  const set = (patch: Partial<Record<string, number>>) => onChange({ ...value, ...patch } as Spring);\n\n  return (\n    <div className={cn('flex min-w-0 flex-col gap-2', className)}>\n      <ControlSegmented<SpringMode>\n        label={`${label}: tune by`}\n        value={value.mode}\n        options={[\n          { value: 'time', label: 'Time', title: 'Duration and bounce' },\n          { value: 'physics', label: 'Physics', title: 'Stiffness, damping and mass' },\n        ]}\n        onChange={(mode) => onChange(convertSpring(value, mode))}\n      />\n      <svg viewBox={`0 0 ${W} ${H}`} role=\"img\" aria-label={`${label}: settles in ${settle.toFixed(2)} seconds${overshoot >= 1 ? `, overshooting by ${overshoot}%` : ''}`} className=\"bg-muted-subtle border-border w-full rounded-md border\">\n        <line x1={0} x2={W} y1={target} y2={target} className=\"stroke-border\" strokeDasharray=\"3 3\" />\n        <polyline points={points} fill=\"none\" className=\"stroke-foreground\" strokeWidth={2} strokeLinejoin=\"round\" />\n      </svg>\n      <p className=\"text-muted-foreground text-xs tabular-nums\">\n        Settles in {settle.toFixed(2)} s{overshoot >= 1 ? ` · overshoots ${overshoot}%` : ''}\n      </p>\n      {value.mode === 'time' ? (\n        <>\n          <NumberField label=\"Duration\" unit=\"s\" {...SPRING_RANGES.visualDuration} value={value.visualDuration} onChange={(v) => set({ visualDuration: v })} />\n          <NumberField label=\"Bounce\" {...SPRING_RANGES.bounce} value={value.bounce} onChange={(v) => set({ bounce: v })} />\n        </>\n      ) : (\n        <>\n          <NumberField label=\"Stiffness\" {...SPRING_RANGES.stiffness} value={value.stiffness} onChange={(v) => set({ stiffness: v })} />\n          <NumberField label=\"Damping\" {...SPRING_RANGES.damping} value={value.damping} onChange={(v) => set({ damping: v })} />\n          <NumberField label=\"Mass\" {...SPRING_RANGES.mass} value={value.mass} onChange={(v) => set({ mass: v })} />\n        </>\n      )}\n      <MotionPreview easing={css.easing} duration={css.duration} label={label} />\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/controls/spring-editor.tsx"
    }
  ],
  "meta": {
    "exports": [
      "SpringEditor"
    ],
    "api": "<SpringEditor label value={{ mode: 'time', visualDuration, bounce }} onChange />"
  },
  "categories": [
    "controls"
  ],
  "type": "registry:component"
}