{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"infinite-canvas","type":"registry:component","title":"Infinite canvas","description":"Pan, pinch and zoom around a board of notes.","author":"Yash Bavadiya <https://xevrion.dev>","dependencies":["motion"],"registryDependencies":["utils"],"files":[{"path":"components/infinite-canvas.tsx","type":"registry:component","content":"\"use client\";\n\nimport { useEffect, useId, useRef } from \"react\";\nimport { animate, type AnimationPlaybackControls } from \"motion/react\";\nimport { useReducedMotion } from \"@/hooks/use-reduced-motion\";\nimport { cn } from \"@/lib/utils\";\n\nexport type CanvasNote = {\n  id: string;\n  x: number;\n  y: number;\n  title: string;\n  text: string;\n  rotate?: number;\n  accent?: boolean;\n};\n\ntype View = { x: number; y: number; s: number };\ntype Point = { x: number; y: number };\n\nconst MIN_SCALE = 0.25;\nconst MAX_SCALE = 3;\n// World units between grid dots at 100%.\nconst GRID = 24;\n// Critically damped and about 300ms: view changes are navigation, and a\n// camera that overshoots its target makes people feel seasick.\nconst VIEW_SPRING = { type: \"spring\", visualDuration: 0.3, bounce: 0 } as const;\n// Velocity kept per millisecond of coasting. 0.995 gives a time constant of\n// about 200ms, so a flick glides a short way and settles, like Figma rather\n// than a long iOS scroll list.\nconst FRICTION = 0.995;\n// Below this (px per ms) a release is a placement, not a throw.\nconst MIN_FLICK = 0.05;\n// A pause this long before lifting the finger cancels the throw.\nconst STALE_RELEASE = 50;\n// Velocity is averaged over the last 100ms, smoothing jittery final events.\nconst VELOCITY_WINDOW = 100;\nconst BUTTON_ZOOM = 1.5;\nconst KEY_PAN = 80;\nconst FIT_PADDING = 32;\n// Tuned so one trackpad pinch gesture covers roughly the full zoom range and\n// one ctrl + mouse wheel notch (about 100px) zooms by ~16%.\nconst PINCH_SPEED = 0.01;\nconst WHEEL_SPEED = 0.0015;\n// How recently the page must have scrolled for a wheel over the canvas to\n// count as the same page scroll: longer than the gap between wheel events.\nconst PAGE_SCROLL_GRACE = 250;\n// Pixels per line when the browser reports wheel deltas in lines.\nconst LINE_HEIGHT = 33;\n\nconst clampScale = (s: number) => Math.min(Math.max(s, MIN_SCALE), MAX_SCALE);\n\n// Keeps `anchor` (a point in the viewport) pinned while the scale changes.\nfunction zoomAround(view: View, s: number, anchor: Point): View {\n  const k = s / view.s;\n  return {\n    s,\n    x: anchor.x - (anchor.x - view.x) * k,\n    y: anchor.y - (anchor.y - view.y) * k,\n  };\n}\n\nfunction centeredOn(\n  point: Point,\n  s: number,\n  width: number,\n  height: number,\n): View {\n  return { s, x: width / 2 - point.x * s, y: height / 2 - point.y * s };\n}\n\n// Two dot layers: a minor grid that fades out as its dots crowd together when\n// zoomed out, and a major grid every four cells that stays, so there is\n// always a sense of scale and movement.\nfunction gridImage(minorAlpha: number) {\n  return [\n    `radial-gradient(circle, color-mix(in oklch, var(--foreground) ${minorAlpha}%, transparent) 1px, transparent 1.5px)`,\n    \"radial-gradient(circle, color-mix(in oklch, var(--foreground) 24%, transparent) 1.25px, transparent 1.75px)\",\n  ].join(\", \");\n}\n\nfunction gridState(view: View) {\n  const minor = GRID * view.s;\n  const major = minor * 4;\n  // Fully visible from 18px spacing, gone by 8px.\n  const alpha = Math.round(Math.min(Math.max((minor - 8) / 10, 0), 1) * 16);\n  return {\n    alpha,\n    size: `${minor}px ${minor}px, ${major}px ${major}px`,\n    // Offset by half a cell so dots land on world grid points, not between.\n    position: `${view.x - minor / 2}px ${view.y - minor / 2}px, ${view.x - major / 2}px ${view.y - major / 2}px`,\n  };\n}\n\n// No will-change here on purpose: a permanently promoted layer keeps the\n// notes rasterized at their old scale, so text goes soft after zooming.\nfunction worldTransform(view: View) {\n  return `translate(${view.x}px, ${view.y}px) scale(${view.s})`;\n}\n\n// Rendered before measuring, so the server markup already shows the notes in\n// place at the canvas's full size.\nconst DEFAULT_WIDTH = 560;\nconst DEFAULT_HEIGHT = 380;\n\ntype Api = {\n  zoomBy: (factor: number) => void;\n  fit: () => void;\n  reset: () => void;\n};\n\nexport function InfiniteCanvas({\n  notes,\n  home,\n  label,\n  className,\n}: {\n  notes: CanvasNote[];\n  // The world point shown centered at 100% on load and on reset.\n  home: Point;\n  label: string;\n  className?: string;\n}) {\n  const reduceMotion = useReducedMotion();\n  const reduceRef = useRef(reduceMotion);\n  const viewport = useRef<HTMLDivElement>(null);\n  const world = useRef<HTMLDivElement>(null);\n  const zoomLabel = useRef<HTMLSpanElement>(null);\n  const api = useRef<Api>(null);\n  const hintId = useId();\n\n  useEffect(() => {\n    reduceRef.current = reduceMotion;\n  }, [reduceMotion]);\n\n  useEffect(() => {\n    const vp = viewport.current;\n    const layer = world.current;\n    const zoomText = zoomLabel.current;\n    if (!vp || !layer || !zoomText) return;\n\n    let width = vp.clientWidth;\n    let height = vp.clientHeight;\n    let view = centeredOn(home, 1, width, height);\n    let gridAlpha = -1;\n    let percent = -1;\n\n    const paint = () => {\n      layer.style.transform = worldTransform(view);\n      const grid = gridState(view);\n      // Rebuilding the gradient is the one costly write, so only when the\n      // minor dots' opacity actually changes.\n      if (grid.alpha !== gridAlpha) {\n        vp.style.backgroundImage = gridImage(grid.alpha);\n        gridAlpha = grid.alpha;\n      }\n      vp.style.backgroundSize = grid.size;\n      vp.style.backgroundPosition = grid.position;\n      const next = Math.round(view.s * 100);\n      if (next !== percent) {\n        zoomText.textContent = `${next}%`;\n        percent = next;\n      }\n    };\n\n    // Camera animations. Every one starts from the live view, so a new\n    // action mid-flight redirects it instead of waiting for it to finish.\n    let flight: { controls: AnimationPlaybackControls; target: View } | null =\n      null;\n\n    const stopFlight = () => {\n      flight?.controls.stop();\n      flight = null;\n    };\n\n    const flyTo = (target: View, anchor?: Point) => {\n      stopMomentum();\n      stopFlight();\n      if (reduceRef.current) {\n        view = target;\n        paint();\n        return;\n      }\n      const from = view;\n      // Interpolate scale geometrically: 50% to 100% should feel like the\n      // same step as 100% to 200%.\n      const scaleAt = (p: number) => from.s * (target.s / from.s) ** p;\n      const fromCenter = {\n        x: (width / 2 - from.x) / from.s,\n        y: (height / 2 - from.y) / from.s,\n      };\n      const toCenter = {\n        x: (width / 2 - target.x) / target.s,\n        y: (height / 2 - target.y) / target.s,\n      };\n      const controls = animate(0, 1, {\n        ...VIEW_SPRING,\n        onUpdate: (p) => {\n          const s = scaleAt(p);\n          // Zooms keep their anchor pinned the whole way; moves glide the\n          // center point across, so the path never swings wide.\n          view = anchor\n            ? zoomAround(from, s, anchor)\n            : centeredOn(\n                {\n                  x: fromCenter.x + (toCenter.x - fromCenter.x) * p,\n                  y: fromCenter.y + (toCenter.y - fromCenter.y) * p,\n                },\n                s,\n                width,\n                height,\n              );\n          paint();\n        },\n        onComplete: () => {\n          view = target;\n          paint();\n          flight = null;\n        },\n      });\n      flight = { controls, target };\n    };\n\n    // Repeated zooms stack on where the camera is heading, so three quick\n    // clicks land on three steps even while the first is still animating.\n    const zoomTo = (factor: number, anchor: Point) => {\n      const base = flight?.target ?? view;\n      const s = clampScale(base.s * factor);\n      if (s === view.s && !flight) return;\n      flyTo(zoomAround(view, s, anchor), anchor);\n    };\n\n    const center = () => ({ x: width / 2, y: height / 2 });\n\n    const fit = () => {\n      let minX = Infinity;\n      let minY = Infinity;\n      let maxX = -Infinity;\n      let maxY = -Infinity;\n      // Layout offsets ignore the world transform, so these are world units.\n      for (const child of layer.children) {\n        const el = child as HTMLElement;\n        minX = Math.min(minX, el.offsetLeft);\n        minY = Math.min(minY, el.offsetTop);\n        maxX = Math.max(maxX, el.offsetLeft + el.offsetWidth);\n        maxY = Math.max(maxY, el.offsetTop + el.offsetHeight);\n      }\n      if (minX === Infinity) return;\n      // Never zooms in past 100%: fitting two notes shouldn't blow them up.\n      const s = clampScale(\n        Math.min(\n          (width - FIT_PADDING * 2) / (maxX - minX),\n          (height - FIT_PADDING * 2) / (maxY - minY),\n          1,\n        ),\n      );\n      flyTo(\n        centeredOn(\n          { x: (minX + maxX) / 2, y: (minY + maxY) / 2 },\n          s,\n          width,\n          height,\n        ),\n      );\n    };\n\n    const reset = () => flyTo(centeredOn(home, 1, width, height));\n\n    const panBy = (dx: number, dy: number) => {\n      const base = flight?.target ?? view;\n      flyTo({ ...base, x: base.x + dx, y: base.y + dy });\n    };\n\n    api.current = {\n      zoomBy: (factor) => zoomTo(factor, center()),\n      fit,\n      reset,\n    };\n\n    // Momentum after a throw: exponential decay, the same shape as native\n    // scroll deceleration, so it eases out instead of braking at the end.\n    let coast = 0;\n    const stopMomentum = () => {\n      cancelAnimationFrame(coast);\n      coast = 0;\n    };\n    const startMomentum = (vx: number, vy: number) => {\n      let last = performance.now();\n      const step = (now: number) => {\n        const dt = Math.min(now - last, 32);\n        last = now;\n        view = { ...view, x: view.x + vx * dt, y: view.y + vy * dt };\n        paint();\n        const decay = FRICTION ** dt;\n        vx *= decay;\n        vy *= decay;\n        coast = Math.hypot(vx, vy) > 0.01 ? requestAnimationFrame(step) : 0;\n      };\n      coast = requestAnimationFrame(step);\n    };\n\n    // Pointer tracking. Two pointers pinch; one pans.\n    const pointers = new Map<number, Point>();\n    let samples: { t: number; x: number; y: number }[] = [];\n    let pinched = false;\n    let travel = 0;\n    let lastPanEnd = -Infinity;\n    let origin: Point = { x: 0, y: 0 };\n\n    const local = (e: { clientX: number; clientY: number }) => ({\n      x: e.clientX - origin.x,\n      y: e.clientY - origin.y,\n    });\n\n    const onPointerDown = (e: PointerEvent) => {\n      if (e.pointerType === \"mouse\" && e.button !== 0) return;\n      if ((e.target as Element).closest(\"[data-canvas-toolbar]\")) return;\n      // Grabbing the canvas catches it mid-glide, like a hand on a spinning\n      // globe.\n      stopMomentum();\n      stopFlight();\n      if (pointers.size === 0) {\n        // One layout read per gesture, not per move.\n        const rect = vp.getBoundingClientRect();\n        origin = { x: rect.left, y: rect.top };\n        pinched = false;\n        travel = 0;\n      }\n      vp.setPointerCapture(e.pointerId);\n      const p = local(e);\n      pointers.set(e.pointerId, p);\n      if (pointers.size > 1) pinched = true;\n      samples = [{ t: e.timeStamp, ...p }];\n      vp.dataset.dragging = \"\";\n    };\n\n    const onPointerMove = (e: PointerEvent) => {\n      const prev = pointers.get(e.pointerId);\n      if (!prev) return;\n      const next = local(e);\n      travel += Math.abs(next.x - prev.x) + Math.abs(next.y - prev.y);\n      if (pointers.size === 1) {\n        view = {\n          ...view,\n          x: view.x + next.x - prev.x,\n          y: view.y + next.y - prev.y,\n        };\n        samples.push({ t: e.timeStamp, ...next });\n        while (\n          samples.length > 2 &&\n          e.timeStamp - samples[0].t > VELOCITY_WINDOW\n        ) {\n          samples.shift();\n        }\n      } else {\n        // Pinch against whichever other finger is down; a third is ignored.\n        let other = prev;\n        for (const [id, p] of pointers) {\n          if (id !== e.pointerId) {\n            other = p;\n            break;\n          }\n        }\n        const before = Math.hypot(prev.x - other.x, prev.y - other.y);\n        const after = Math.hypot(next.x - other.x, next.y - other.y);\n        const midBefore = {\n          x: (prev.x + other.x) / 2,\n          y: (prev.y + other.y) / 2,\n        };\n        const midAfter = {\n          x: (next.x + other.x) / 2,\n          y: (next.y + other.y) / 2,\n        };\n        const s = clampScale(view.s * (before > 0 ? after / before : 1));\n        // Zoom around the fingers' midpoint, then follow it as it moves.\n        const zoomed = zoomAround(view, s, midBefore);\n        view = {\n          s,\n          x: zoomed.x + midAfter.x - midBefore.x,\n          y: zoomed.y + midAfter.y - midBefore.y,\n        };\n      }\n      pointers.set(e.pointerId, next);\n      paint();\n    };\n\n    const onPointerEnd = (e: PointerEvent) => {\n      if (!pointers.delete(e.pointerId)) return;\n      if (pointers.size > 0) {\n        // Lifting one finger of a pinch hands panning to the other without\n        // a jump.\n        const [remaining] = pointers.values();\n        samples = [{ t: e.timeStamp, ...remaining }];\n        return;\n      }\n      delete vp.dataset.dragging;\n      // Slop for a trembling click, so only a real drag counts as one.\n      if (travel > 4) lastPanEnd = e.timeStamp;\n      if (pinched || reduceRef.current || e.type === \"pointercancel\") return;\n      const first = samples[0];\n      const last = samples[samples.length - 1];\n      if (!first || !last || e.timeStamp - last.t > STALE_RELEASE) return;\n      const dt = last.t - first.t;\n      if (dt <= 0) return;\n      const vx = (last.x - first.x) / dt;\n      const vy = (last.y - first.y) / dt;\n      if (Math.hypot(vx, vy) > MIN_FLICK) startMomentum(vx, vy);\n    };\n\n    // A page scroll that carries the pointer over the canvas keeps scrolling\n    // the page, instead of the canvas suddenly swallowing the wheel.\n    let pageScrolledAt = -Infinity;\n    const onPageScroll = () => {\n      pageScrolledAt = performance.now();\n    };\n\n    const onWheel = (e: WheelEvent) => {\n      const zoom = e.ctrlKey || e.metaKey;\n      if (!zoom && performance.now() - pageScrolledAt < PAGE_SCROLL_GRACE) {\n        return;\n      }\n      e.preventDefault();\n      stopMomentum();\n      const rect = vp.getBoundingClientRect();\n      const anchor = { x: e.clientX - rect.left, y: e.clientY - rect.top };\n      const unit = e.deltaMode === 1 ? LINE_HEIGHT : 1;\n      let dx = e.deltaX * unit;\n      let dy = e.deltaY * unit;\n      // A mouse wheel moves in whole notches on one axis; a trackpad scrolls\n      // in small, often fractional steps on both. Notches are big jumps, so\n      // they animate; trackpad deltas apply directly for 1:1 tracking.\n      const notch =\n        e.deltaMode === 1 ||\n        (dx === 0 && Math.abs(dy) >= 40 && Number.isInteger(dy));\n      if (zoom) {\n        // Browsers report a trackpad pinch as ctrl + wheel, so ctrl or cmd\n        // with any wheel always zooms.\n        if (notch) {\n          zoomTo(Math.exp(-dy * WHEEL_SPEED), anchor);\n          return;\n        }\n        stopFlight();\n        view = zoomAround(\n          view,\n          clampScale(view.s * Math.exp(-dy * PINCH_SPEED)),\n          anchor,\n        );\n        paint();\n        return;\n      }\n      // Shift + wheel pans sideways, as it scrolls sideways on a page.\n      if (e.shiftKey && dx === 0) [dx, dy] = [dy, 0];\n      if (notch) {\n        panBy(-dx, -dy);\n        return;\n      }\n      stopFlight();\n      view = { ...view, x: view.x - dx, y: view.y - dy };\n      paint();\n    };\n\n    const onDoubleClick = (e: MouseEvent) => {\n      if ((e.target as Element).closest(\"[data-canvas-toolbar]\")) return;\n      // A drag followed by a quick click also fires dblclick; that was\n      // panning, not a request to zoom.\n      if (e.timeStamp - lastPanEnd < 400) return;\n      const rect = vp.getBoundingClientRect();\n      zoomTo(e.shiftKey ? 0.5 : 2, {\n        x: e.clientX - rect.left,\n        y: e.clientY - rect.top,\n      });\n    };\n\n    const onKeyDown = (e: KeyboardEvent) => {\n      if (e.target !== vp || e.metaKey || e.ctrlKey || e.altKey) return;\n      const pan = e.shiftKey ? KEY_PAN * 3 : KEY_PAN;\n      const actions: Record<string, () => void> = {\n        ArrowLeft: () => panBy(pan, 0),\n        ArrowRight: () => panBy(-pan, 0),\n        ArrowUp: () => panBy(0, pan),\n        ArrowDown: () => panBy(0, -pan),\n        \"+\": () => zoomTo(BUTTON_ZOOM, center()),\n        \"=\": () => zoomTo(BUTTON_ZOOM, center()),\n        \"-\": () => zoomTo(1 / BUTTON_ZOOM, center()),\n        _: () => zoomTo(1 / BUTTON_ZOOM, center()),\n        \"0\": reset,\n      };\n      const action = actions[e.key];\n      if (!action) return;\n      e.preventDefault();\n      action();\n    };\n\n    // Keeps the same world point centered when the canvas resizes.\n    const resize = new ResizeObserver(() => {\n      const w = vp.clientWidth;\n      const h = vp.clientHeight;\n      if (w === width && h === height) return;\n      view = {\n        ...view,\n        x: view.x + (w - width) / 2,\n        y: view.y + (h - height) / 2,\n      };\n      width = w;\n      height = h;\n      paint();\n    });\n\n    paint();\n    resize.observe(vp);\n    vp.addEventListener(\"pointerdown\", onPointerDown);\n    vp.addEventListener(\"pointermove\", onPointerMove);\n    vp.addEventListener(\"pointerup\", onPointerEnd);\n    vp.addEventListener(\"pointercancel\", onPointerEnd);\n    vp.addEventListener(\"wheel\", onWheel, { passive: false });\n    vp.addEventListener(\"dblclick\", onDoubleClick);\n    vp.addEventListener(\"keydown\", onKeyDown);\n    window.addEventListener(\"scroll\", onPageScroll, { passive: true, capture: true });\n    return () => {\n      window.removeEventListener(\"scroll\", onPageScroll, { capture: true });\n      resize.disconnect();\n      stopMomentum();\n      stopFlight();\n      api.current = null;\n      vp.removeEventListener(\"pointerdown\", onPointerDown);\n      vp.removeEventListener(\"pointermove\", onPointerMove);\n      vp.removeEventListener(\"pointerup\", onPointerEnd);\n      vp.removeEventListener(\"pointercancel\", onPointerEnd);\n      vp.removeEventListener(\"wheel\", onWheel);\n      vp.removeEventListener(\"dblclick\", onDoubleClick);\n      vp.removeEventListener(\"keydown\", onKeyDown);\n    };\n  }, [home]);\n\n  const initial = centeredOn(home, 1, DEFAULT_WIDTH, DEFAULT_HEIGHT);\n  const initialGrid = gridState(initial);\n\n  const toolButton =\n    \"flex h-9 touch-manipulation items-center justify-center rounded-full text-sm font-medium text-foreground outline-hidden transition-[scale,background-color] duration-150 ease-out select-none hover:bg-muted focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-foreground active:scale-[0.96] motion-reduce:transition-[background-color]\";\n\n  return (\n    <div\n      ref={viewport}\n      role=\"region\"\n      aria-roledescription=\"canvas\"\n      aria-label={label}\n      aria-describedby={hintId}\n      tabIndex={0}\n      className={cn(\n        \"relative isolate h-[380px] w-[min(560px,100%)] cursor-grab touch-none overflow-clip rounded-3xl bg-muted shadow-wheel outline-hidden select-none focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-offset-2 focus-visible:outline-foreground data-dragging:cursor-grabbing\",\n        className,\n      )}\n      style={{\n        backgroundImage: gridImage(initialGrid.alpha),\n        backgroundSize: initialGrid.size,\n        backgroundPosition: initialGrid.position,\n      }}\n    >\n      <div\n        ref={world}\n        className=\"absolute top-0 left-0 origin-top-left\"\n        style={{ transform: worldTransform(initial) }}\n      >\n        {notes.map((note) => (\n          <div\n            key={note.id}\n            className={cn(\n              \"absolute flex w-44 flex-col gap-1.5 rounded-xl p-4 shadow-raised\",\n              note.accent\n                ? \"bg-foreground text-background\"\n                : \"bg-background text-foreground\",\n            )}\n            style={{\n              left: note.x,\n              top: note.y,\n              rotate: `${note.rotate ?? 0}deg`,\n            }}\n          >\n            <span className=\"text-sm font-semibold tracking-tight\">\n              {note.title}\n            </span>\n            <p\n              className={cn(\n                \"text-sm leading-snug text-pretty\",\n                note.accent ? \"opacity-70\" : \"text-muted-foreground\",\n              )}\n            >\n              {note.text}\n            </p>\n          </div>\n        ))}\n      </div>\n\n      {/* Centered on the toolbar's midline: 12px inset + half of 44px, less\n          half of the 16px line. */}\n      <p\n        id={hintId}\n        className=\"pointer-events-none absolute bottom-[26px] left-4 text-xs text-muted-foreground max-sm:sr-only\"\n      >\n        Drag or scroll to pan, pinch to zoom\n        <span className=\"sr-only\">\n          . Ctrl and scroll also zooms. Arrow keys pan, plus and minus zoom, 0 resets.\n        </span>\n      </p>\n\n      <div\n        data-canvas-toolbar\n        className=\"absolute right-3 bottom-3 flex h-11 cursor-default items-center gap-0.5 rounded-full bg-background p-1 shadow-raised\"\n      >\n        <button\n          type=\"button\"\n          aria-label=\"Zoom out\"\n          onClick={() => api.current?.zoomBy(1 / BUTTON_ZOOM)}\n          className={cn(toolButton, \"w-9\")}\n        >\n          <ToolIcon d=\"M5 12h14\" />\n        </button>\n        <button\n          type=\"button\"\n          aria-label=\"Reset zoom\"\n          onClick={() => api.current?.reset()}\n          className={cn(toolButton, \"w-14 tabular-nums\")}\n        >\n          <span ref={zoomLabel}>100%</span>\n        </button>\n        <button\n          type=\"button\"\n          aria-label=\"Zoom in\"\n          onClick={() => api.current?.zoomBy(BUTTON_ZOOM)}\n          className={cn(toolButton, \"w-9\")}\n        >\n          <ToolIcon d=\"M5 12h14M12 5v14\" />\n        </button>\n        <span aria-hidden className=\"mx-1 h-5 w-px bg-border\" />\n        <button\n          type=\"button\"\n          onClick={() => api.current?.fit()}\n          className={cn(toolButton, \"px-3.5\")}\n        >\n          Fit\n        </button>\n      </div>\n    </div>\n  );\n}\n\nfunction ToolIcon({ d }: { d: string }) {\n  return (\n    <svg\n      viewBox=\"0 0 24 24\"\n      className=\"size-[18px]\"\n      fill=\"none\"\n      stroke=\"currentColor\"\n      strokeWidth={1.75}\n      strokeLinecap=\"round\"\n      aria-hidden\n    >\n      <path d={d} />\n    </svg>\n  );\n}\n\nconst NOTES: CanvasNote[] = [\n  {\n    id: \"launch\",\n    x: -240,\n    y: -150,\n    rotate: -1.5,\n    title: \"Launch checklist\",\n    text: \"Pricing page, changelog, and the email to the waitlist.\",\n  },\n  {\n    id: \"question\",\n    x: -30,\n    y: -170,\n    rotate: 1,\n    title: \"Open question\",\n    text: \"Ship dark mode first, or keyboard shortcuts?\",\n  },\n  {\n    id: \"idea\",\n    x: 80,\n    y: -20,\n    rotate: -1,\n    title: \"Idea\",\n    text: \"Let people pin their favourite components to the top.\",\n  },\n  {\n    id: \"done\",\n    x: -210,\n    y: 10,\n    rotate: 1.5,\n    accent: true,\n    title: \"Done this week\",\n    text: \"Spring presets and the new docs sidebar.\",\n  },\n  {\n    id: \"far\",\n    x: 440,\n    y: 260,\n    rotate: -1,\n    title: \"You found it\",\n    text: \"Press 0 to head home, or Fit to see everything.\",\n  },\n];\n\n// Centered on the four nearby notes; the fifth waits off to the side.\nconst HOME = { x: 8, y: -25 };\n\nexport default function InfiniteCanvasDemo() {\n  return <InfiniteCanvas notes={NOTES} home={HOME} label=\"Planning board\" />;\n}\n"},{"path":"hooks/use-reduced-motion.ts","type":"registry:hook","target":"hooks/use-reduced-motion.ts","content":"\"use client\";\n\nimport { useSyncExternalStore } from \"react\";\n\n// Motion's useReducedMotion reads the media query on the very first client\n// render, but the server can't know it, so every component that renders\n// differently under reduced motion broke hydration for those users. This\n// reports false during hydration, matching the server HTML, then the real\n// preference straight after, and follows it if it changes.\nconst query = \"(prefers-reduced-motion: reduce)\";\n\nfunction subscribe(onChange: () => void) {\n  const media = window.matchMedia(query);\n  media.addEventListener(\"change\", onChange);\n  return () => media.removeEventListener(\"change\", onChange);\n}\n\nexport function useReducedMotion() {\n  return useSyncExternalStore(\n    subscribe,\n    () => window.matchMedia(query).matches,\n    () => false,\n  );\n}\n"}],"cssVars":{"light":{"shadow-raised":"0 0 0 1px oklch(0 0 0 / 0.06), 0 1px 2px oklch(0 0 0 / 0.06), 0 6px 16px -6px oklch(0 0 0 / 0.12)","shadow-wheel":"inset 0 1px 2px oklch(0 0 0 / 0.08), inset 0 0 0 1px oklch(0 0 0 / 0.04)"},"dark":{"shadow-raised":"0 0 0 1px oklch(1 0 0 / 0.08), 0 1px 2px oklch(0 0 0 / 0.4), 0 6px 16px -6px oklch(0 0 0 / 0.6)","shadow-wheel":"inset 0 1px 2px oklch(0 0 0 / 0.5), inset 0 0 0 1px oklch(1 0 0 / 0.04)"},"theme":{"shadow-raised":"var(--shadow-raised)","shadow-wheel":"var(--shadow-wheel)"}},"categories":["playground"],"docs":"From ui lab: https://lab.xevrion.dev/lab/infinite-canvas"}