{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "image-ken-burns",
  "type": "registry:component",
  "title": "Image Ken Burns",
  "description": "A story-style slideshow with slow zoom and pan on every photo, crossfades, segmented progress bars and tap zones for previous and next.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "transitions",
    "image",
    "ken-burns",
    "stories",
    "zoom",
    "slideshow",
    "progress"
  ],
  "docs": "https://hyperblur.dev/effects/image-ken-burns",
  "files": [
    {
      "path": "registry/hyperblur/image-ken-burns.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/image-ken-burns.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nconst SCENE_COUNT = 4;\n\nconst SCENE_NAMES = [\"Alpine dusk\", \"Neon district\", \"Tidal lines\", \"Studio light\"];\n\ntype SceneLayer = \"all\" | \"back\" | \"mid\" | \"front\";\n\nfunction mod(n: number, m: number) {\n  return ((n % m) + m) % m;\n}\n\nfunction hash(n: number) {\n  let x = Math.imul(n + 1, 2654435761) >>> 0;\n  x = Math.imul(x ^ (x >>> 15), 2246822519) >>> 0;\n  x = Math.imul(x ^ (x >>> 13), 3266489917) >>> 0;\n  return (x ^ (x >>> 16)) >>> 0;\n}\n\nconst sceneCache = new Map<string, string>();\n\nfunction sceneSvg(k: number, layer: SceneLayer) {\n  const on = (name: string) => layer === \"all\" || layer === name;\n  let s = '<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 320 200\" width=\"320\" height=\"200\">';\n  if (k === 0) {\n    if (on(\"back\")) {\n      s +=\n        '<defs><linearGradient id=\"g\" x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\"><stop offset=\"0\" stop-color=\"#ffb36b\"/><stop offset=\"0.5\" stop-color=\"#ff6f91\"/><stop offset=\"1\" stop-color=\"#4b3b8f\"/></linearGradient></defs><rect width=\"320\" height=\"200\" fill=\"url(#g)\"/><circle cx=\"220\" cy=\"96\" r=\"46\" fill=\"#ffe3a8\" opacity=\"0.22\"/><circle cx=\"220\" cy=\"96\" r=\"26\" fill=\"#ffe9bd\"/>';\n    }\n    if (on(\"mid\")) {\n      s +=\n        '<polygon points=\"0,140 50,92 90,122 140,70 200,128 250,96 320,138 320,200 0,200\" fill=\"#6a4a98\"/><polygon points=\"0,158 70,118 130,148 190,110 260,150 320,128 320,200 0,200\" fill=\"#3d2c70\"/>';\n    }\n    if (on(\"front\")) {\n      s += '<path d=\"M0 178 Q80 150 160 172 T320 166 L320 200 L0 200Z\" fill=\"#1b1640\"/>';\n      for (let i = 0; i < 9; i += 1) {\n        const x = 12 + i * 36 + (hash(i + 3) % 14);\n        const h = 26 + (hash(i + 9) % 18);\n        s += `<polygon points=\"${x},${200 - h - 6} ${x - 8},${206 - 6} ${x + 8},${206 - 6}\" fill=\"#120e30\"/><rect x=\"${x - 1}\" y=\"${200 - 8}\" width=\"2\" height=\"8\" fill=\"#120e30\"/>`;\n      }\n    }\n  } else if (k === 1) {\n    if (on(\"back\")) {\n      s +=\n        '<defs><linearGradient id=\"g\" x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\"><stop offset=\"0\" stop-color=\"#14183f\"/><stop offset=\"0.55\" stop-color=\"#6a3d8f\"/><stop offset=\"1\" stop-color=\"#ff8a7a\"/></linearGradient></defs><rect width=\"320\" height=\"200\" fill=\"url(#g)\"/><circle cx=\"252\" cy=\"46\" r=\"16\" fill=\"#fff1d6\"/><circle cx=\"259\" cy=\"41\" r=\"14\" fill=\"#3a2f78\" opacity=\"0.4\"/>';\n      for (let i = 0; i < 22; i += 1) {\n        const h = hash(i + 11);\n        s += `<circle cx=\"${h % 320}\" cy=\"${hash(i + 71) % 80}\" r=\"${(0.5 + (h % 5) / 6).toFixed(2)}\" fill=\"#fff\" opacity=\"0.${5 + (h % 4)}\"/>`;\n      }\n    }\n    if (on(\"mid\")) {\n      const fx = [0, 28, 64, 98, 132, 170, 208, 246, 284];\n      const fw = [32, 40, 38, 40, 42, 42, 42, 42, 40];\n      const fh = [96, 120, 88, 130, 104, 126, 92, 118, 100];\n      fx.forEach((x, i) => {\n        s += `<rect x=\"${x}\" y=\"${200 - fh[i]}\" width=\"${fw[i]}\" height=\"${fh[i]}\" fill=\"#3b3182\" opacity=\"0.92\"/>`;\n      });\n    }\n    if (on(\"front\")) {\n      const nx = [-6, 40, 86, 136, 190, 236, 282];\n      const nw = [50, 50, 54, 60, 52, 52, 50];\n      const nh = [74, 100, 64, 92, 110, 70, 90];\n      nx.forEach((x, b) => {\n        s += `<rect x=\"${x}\" y=\"${200 - nh[b]}\" width=\"${nw[b]}\" height=\"${nh[b]}\" fill=\"#16132f\"/>`;\n        const cols = Math.floor((nw[b] - 10) / 11);\n        const rows = Math.floor((nh[b] - 10) / 13);\n        for (let r = 0; r < rows; r += 1) {\n          for (let c = 0; c < cols; c += 1) {\n            const h = hash(b * 100 + r * 10 + c);\n            if (h % 3 !== 0) {\n              s += `<rect x=\"${x + 6 + c * 11}\" y=\"${200 - nh[b] + 8 + r * 13}\" width=\"5\" height=\"7\" fill=\"${h % 4 === 0 ? \"#ff9f80\" : \"#ffd37a\"}\"/>`;\n            }\n          }\n        }\n      });\n    }\n  } else if (k === 2) {\n    if (on(\"back\")) {\n      s +=\n        '<defs><linearGradient id=\"g\" x1=\"0\" y1=\"0\" x2=\"1\" y2=\"1\"><stop offset=\"0\" stop-color=\"#0b1f5c\"/><stop offset=\"0.55\" stop-color=\"#1c7ed6\"/><stop offset=\"1\" stop-color=\"#5ee0c8\"/></linearGradient></defs><rect width=\"320\" height=\"200\" fill=\"url(#g)\"/><circle cx=\"72\" cy=\"52\" r=\"20\" fill=\"#fff\" opacity=\"0.25\"/>';\n    }\n    if (on(\"mid\")) {\n      s +=\n        '<path d=\"M0 110 C60 80 120 140 180 108 S280 90 320 112 V200 H0Z\" fill=\"#fff\" opacity=\"0.16\"/><path d=\"M0 130 C70 100 130 160 200 128 S290 112 320 134 V200 H0Z\" fill=\"#7ee8d3\" opacity=\"0.32\"/>';\n    }\n    if (on(\"front\")) {\n      s +=\n        '<path d=\"M0 156 C80 130 140 184 210 154 S290 142 320 160 V200 H0Z\" fill=\"#0a2f6a\" opacity=\"0.88\"/><path d=\"M0 178 C90 160 160 196 240 176 S300 170 320 182 V200 H0Z\" fill=\"#061a42\"/>';\n    }\n  } else {\n    if (on(\"back\")) {\n      s +=\n        '<defs><radialGradient id=\"g\" cx=\"0.5\" cy=\"0.38\" r=\"0.8\"><stop offset=\"0\" stop-color=\"#ffd9b0\"/><stop offset=\"0.55\" stop-color=\"#ea6f8f\"/><stop offset=\"1\" stop-color=\"#43235f\"/></radialGradient></defs><rect width=\"320\" height=\"200\" fill=\"url(#g)\"/>';\n    }\n    if (on(\"mid\")) {\n      s +=\n        '<circle cx=\"160\" cy=\"100\" r=\"72\" fill=\"none\" stroke=\"#fff\" stroke-width=\"1.5\" opacity=\"0.24\"/><path d=\"M70 120 C60 70 120 40 170 52 C230 64 262 110 236 150 C210 190 100 180 70 120Z\" fill=\"#fff\" opacity=\"0.13\"/>';\n    }\n    if (on(\"front\")) {\n      s +=\n        '<path d=\"M70 200 C74 160 112 148 160 148 C208 148 246 160 250 200Z\" fill=\"#2a1a48\"/><rect x=\"146\" y=\"124\" width=\"28\" height=\"32\" fill=\"#d9987a\"/><ellipse cx=\"160\" cy=\"98\" rx=\"30\" ry=\"35\" fill=\"#f0b698\"/><path d=\"M128 96 C124 62 150 50 172 56 C196 62 198 84 192 98 C186 78 170 72 150 74 C140 76 132 84 128 96Z\" fill=\"#2b1230\"/><circle cx=\"160\" cy=\"160\" r=\"4\" fill=\"#ffd37a\"/>';\n    }\n  }\n  return `${s}</svg>`;\n}\n\nfunction sceneUri(index: number, layer: SceneLayer = \"all\") {\n  const k = mod(index, SCENE_COUNT);\n  const key = `${k}:${layer}`;\n  let uri = sceneCache.get(key);\n  if (!uri) {\n    uri = `data:image/svg+xml,${encodeURIComponent(sceneSvg(k, layer))}`;\n    sceneCache.set(key, uri);\n  }\n  return uri;\n}\n\nfunction cssUrl(list: string[] | null, index: number, layer: SceneLayer = \"all\") {\n  if (list) return `url(${JSON.stringify(list[mod(index, list.length)])})`;\n  return `url(\"${sceneUri(index, layer)}\")`;\n}\n\nfunction cx(base: string, extra?: string) {\n  return extra ? `${base} ${extra}` : base;\n}\n\nfunction rootBox(\n  width: number | string | undefined,\n  height: number | string | undefined,\n  aspect: string,\n  style: React.CSSProperties | undefined,\n): React.CSSProperties {\n  return {\n    width: width ?? \"100%\",\n    ...(height !== undefined ? { height } : { aspectRatio: aspect }),\n    ...style,\n  };\n}\n\nfunction arrowNav(e: React.KeyboardEvent, prev: () => void, next: () => void) {\n  if (e.defaultPrevented) return;\n  if (e.key === \"ArrowLeft\") {\n    e.preventDefault();\n    prev();\n  } else if (e.key === \"ArrowRight\") {\n    e.preventDefault();\n    next();\n  }\n}\n\nfunction useInView(ref: React.RefObject<HTMLElement | null>) {\n  const [visible, setVisible] = React.useState(true);\n  React.useEffect(() => {\n    const el = ref.current;\n    if (!el || typeof IntersectionObserver === \"undefined\") return;\n    const observer = new IntersectionObserver((entries) => {\n      const last = entries[entries.length - 1];\n      if (last) setVisible(last.isIntersecting);\n    });\n    observer.observe(el);\n    return () => observer.disconnect();\n  }, [ref]);\n  return visible;\n}\n\nfunction usePause() {\n  const [paused, setPaused] = React.useState(false);\n  const handlers = {\n    onPointerEnter: () => setPaused(true),\n    onPointerLeave: () => setPaused(false),\n    onFocus: (e: React.FocusEvent<HTMLElement>) => {\n      if (e.target.matches(\":focus-visible\")) setPaused(true);\n    },\n    onBlur: (e: React.FocusEvent<HTMLElement>) => {\n      if (!e.currentTarget.contains(e.relatedTarget as Node | null)) setPaused(false);\n    },\n  };\n  return [paused, handlers] as const;\n}\n\nfunction useSlideIndex(\n  count: number,\n  value: number | undefined,\n  initial: number,\n  onChange?: (index: number) => void,\n) {\n  const [inner, setInner] = React.useState(initial);\n  const controlled = value !== undefined;\n  const current = mod(controlled ? value : inner, count);\n  const set = (next: number) => {\n    const n = mod(next, count);\n    if (n === current) return;\n    if (!controlled) setInner(n);\n    onChange?.(n);\n  };\n  return [current, set] as const;\n}\n\ninterface FlipState {\n  cur: number;\n  from: number;\n  dir: 1 | -1;\n  n: number;\n}\n\nfunction useFlip(index: number, count: number) {\n  const [state, setState] = React.useState<FlipState>({ cur: index, from: -1, dir: 1, n: 0 });\n  if (state.cur !== index) {\n    const last = count - 1;\n    let dir: 1 | -1 = index > state.cur ? 1 : -1;\n    if (count > 2 && state.cur === last && index === 0) dir = 1;\n    if (count > 2 && state.cur === 0 && index === last) dir = -1;\n    setState({ cur: index, from: state.cur, dir, n: state.n + 1 });\n  }\n  const done = React.useCallback(() => {\n    setState((p) => (p.from === -1 ? p : { ...p, from: -1 }));\n  }, []);\n  return [state, done] as const;\n}\n\nexport interface ImageKenBurnsProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\"> {\n  images?: string[];\n  captions?: string[];\n  alt?: string;\n  width?: number | string;\n  height?: number | string;\n  aspect?: string;\n  index?: number;\n  defaultIndex?: number;\n  onChange?: (index: number) => void;\n  autoPlay?: boolean;\n  interval?: number;\n  loop?: boolean;\n  accent?: string;\n}\n\nconst css = `\n.hb-qe7 {\n  --hb-qe7-a: #2f7bff;\n  position: relative;\n  display: block;\n  box-sizing: border-box;\n  overflow: hidden;\n  border-radius: 14px;\n  background: #0a0a0a;\n  isolation: isolate;\n  font-family: inherit;\n  user-select: none;\n  -webkit-user-select: none;\n  -webkit-tap-highlight-color: transparent;\n}\n.hb-qe7 *, .hb-qe7 *::before, .hb-qe7 *::after { box-sizing: border-box; }\n.hb-qe7:focus-visible { outline: 2px solid var(--hb-qe7-a); outline-offset: 2px; }\n.hb-qe7-layer { position: absolute; inset: 0; }\n.hb-qe7-sr {\n  position: absolute;\n  width: 1px;\n  height: 1px;\n  margin: -1px;\n  padding: 0;\n  overflow: hidden;\n  clip-path: inset(50%);\n  white-space: nowrap;\n  border: 0;\n}\n.hb-qe7-slide {\n  position: absolute;\n  inset: 0;\n  background-size: cover;\n  background-position: center;\n  opacity: 0;\n  transition: opacity 0.9s ease;\n  will-change: transform, opacity;\n}\n.hb-qe7-slide[data-state=\"active\"] { opacity: 1; }\n.hb-qe7-slide[data-state=\"active\"], .hb-qe7-slide[data-state=\"leaving\"] {\n  animation: hb-qe7-kb calc(var(--hb-qe7-i) + 1400ms) linear both;\n}\n.hb-qe7-shade {\n  position: absolute;\n  inset: 0;\n  z-index: 1;\n  pointer-events: none;\n  background: linear-gradient(180deg, rgba(0, 0, 0, 0.42) 0%, rgba(0, 0, 0, 0) 28%, rgba(0, 0, 0, 0) 58%, rgba(0, 0, 0, 0.55) 100%);\n}\n.hb-qe7-bars {\n  position: absolute;\n  top: 10px;\n  left: 10px;\n  right: 10px;\n  z-index: 3;\n  display: flex;\n  gap: 4px;\n}\n.hb-qe7-bar {\n  position: relative;\n  flex: 1 1 0;\n  height: 3px;\n  overflow: hidden;\n  background: rgba(255, 255, 255, 0.32);\n  border-radius: 999px;\n}\n.hb-qe7-fill {\n  position: absolute;\n  inset: 0;\n  background: #fff;\n  border-radius: inherit;\n  transform: scaleX(0);\n  transform-origin: left center;\n}\n.hb-qe7-fill[data-state=\"done\"] { transform: scaleX(1); }\n.hb-qe7-fill[data-state=\"active\"] { animation: hb-qe7-fill var(--hb-qe7-i) linear both; }\n.hb-qe7[data-auto=\"false\"] .hb-qe7-fill[data-state=\"active\"] { animation: none; transform: scaleX(1); }\n.hb-qe7[data-paused=\"true\"] .hb-qe7-fill, .hb-qe7[data-paused=\"true\"] .hb-qe7-slide { animation-play-state: paused; }\n.hb-qe7-cap {\n  position: absolute;\n  left: 14px;\n  right: 14px;\n  bottom: 14px;\n  z-index: 3;\n  color: #fff;\n  font-size: 14px;\n  font-weight: 600;\n  line-height: 1.25;\n  letter-spacing: -0.01em;\n  text-shadow: 0 1px 12px rgba(0, 0, 0, 0.5);\n  overflow: hidden;\n  text-overflow: ellipsis;\n  white-space: nowrap;\n  pointer-events: none;\n  animation: hb-qe7-cap 0.7s cubic-bezier(0.2, 0.8, 0.2, 1) both;\n}\n.hb-qe7-hit {\n  position: absolute;\n  top: 22px;\n  bottom: 0;\n  z-index: 2;\n  margin: 0;\n  padding: 0;\n  background: transparent;\n  border: 0;\n  cursor: pointer;\n  -webkit-tap-highlight-color: transparent;\n}\n.hb-qe7-hit-l { left: 0; width: 35%; }\n.hb-qe7-hit-r { right: 0; width: 65%; }\n.hb-qe7-hit:focus-visible { outline: 2px solid var(--hb-qe7-a); outline-offset: -4px; }\n@keyframes hb-qe7-kb {\n  from { transform: scale(1.02) translate(0, 0); }\n  to { transform: scale(1.2) translate(var(--hb-qe7-tx, 0%), var(--hb-qe7-ty, 0%)); }\n}\n@keyframes hb-qe7-fill {\n  from { transform: scaleX(0); }\n  to { transform: scaleX(1); }\n}\n@keyframes hb-qe7-cap {\n  from { opacity: 0; transform: translateY(8px); }\n  to { opacity: 1; transform: translateY(0); }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-qe7-slide { transition: none; }\n  .hb-qe7-slide[data-state=\"active\"], .hb-qe7-slide[data-state=\"leaving\"], .hb-qe7-cap { animation: none; }\n  .hb-qe7-fill[data-state=\"active\"] { animation: none; transform: scaleX(1); }\n}\n`;\n\nexport function ImageKenBurns({\n  images,\n  captions,\n  alt = \"Photo\",\n  width,\n  height,\n  aspect = \"16 / 10\",\n  index: indexProp,\n  defaultIndex = 0,\n  onChange,\n  autoPlay = true,\n  interval = 4200,\n  loop = true,\n  accent = \"#2f7bff\",\n  className,\n  style,\n  onKeyDown,\n  ...rest\n}: ImageKenBurnsProps) {\n  const list = images && images.length > 0 ? images : null;\n  const count = list ? list.length : SCENE_COUNT;\n  const names = captions ?? (list ? [] : SCENE_NAMES);\n  const [index, setIndex] = useSlideIndex(count, indexProp, defaultIndex, onChange);\n  const [state, done] = useFlip(index, count);\n  const [paused, pause] = usePause();\n  const ref = React.useRef<HTMLDivElement>(null);\n  const visible = useInView(ref);\n  const label = (i: number) => `${alt} ${i + 1} of ${count}`;\n  const go = (next: number) => {\n    if (!loop && (next < 0 || next >= count)) return;\n    setIndex(next);\n  };\n\n  return (\n    <div\n      tabIndex={0}\n      role=\"group\"\n      aria-roledescription=\"carousel\"\n      aria-label={`${alt} stories`}\n      {...rest}\n      {...pause}\n      ref={ref}\n      className={cx(\"hb-qe7\", className)}\n      data-auto={autoPlay && count > 1 ? \"true\" : \"false\"}\n      data-paused={paused || !visible ? \"true\" : \"false\"}\n      style={\n        {\n          ...rootBox(width, height, aspect, style),\n          \"--hb-qe7-a\": accent,\n          \"--hb-qe7-i\": `${interval}ms`,\n        } as React.CSSProperties\n      }\n      onKeyDown={(e) => {\n        onKeyDown?.(e);\n        arrowNav(e, () => go(index - 1), () => go(index + 1));\n      }}\n    >\n      <style href=\"hb-image-ken-burns\" precedence=\"default\">\n        {css}\n      </style>\n      {Array.from({ length: count }, (_, i) => {\n        const tx = (hash(i * 3 + 1) % 7) - 3;\n        const ty = (hash(i * 3 + 2) % 5) - 2;\n        const phase = i === state.cur ? \"active\" : i === state.from ? \"leaving\" : \"idle\";\n        return (\n          <div\n            key={i}\n            className=\"hb-qe7-slide\"\n            data-state={phase}\n            role=\"img\"\n            aria-label={label(i)}\n            aria-hidden={i === index ? undefined : true}\n            style={\n              {\n                backgroundImage: cssUrl(list, i),\n                \"--hb-qe7-tx\": `${tx}%`,\n                \"--hb-qe7-ty\": `${ty}%`,\n              } as React.CSSProperties\n            }\n            onTransitionEnd={\n              phase === \"leaving\"\n                ? (e) => {\n                    if (e.propertyName === \"opacity\") done();\n                  }\n                : undefined\n            }\n          />\n        );\n      })}\n      <div className=\"hb-qe7-shade\" aria-hidden=\"true\" />\n      <div className=\"hb-qe7-bars\" aria-hidden=\"true\">\n        {Array.from({ length: count }, (_, i) => (\n          <span key={i} className=\"hb-qe7-bar\">\n            <span\n              className=\"hb-qe7-fill\"\n              data-state={i < index ? \"done\" : i === index ? \"active\" : \"idle\"}\n              onAnimationEnd={i === index && autoPlay ? () => go(index + 1) : undefined}\n            />\n          </span>\n        ))}\n      </div>\n      {names[index] ? (\n        <div key={index} className=\"hb-qe7-cap\">\n          {names[index]}\n        </div>\n      ) : null}\n      {count > 1 ? (\n        <>\n          <button type=\"button\" tabIndex={-1} className=\"hb-qe7-hit hb-qe7-hit-l\" aria-label=\"Previous photo\" onClick={() => go(index - 1)} />\n          <button type=\"button\" tabIndex={-1} className=\"hb-qe7-hit hb-qe7-hit-r\" aria-label=\"Next photo\" onClick={() => go(index + 1)} />\n        </>\n      ) : null}\n      <span className=\"hb-qe7-sr\" aria-live=\"polite\">\n        {label(index)}\n      </span>\n    </div>\n  );\n}\n"
    }
  ]
}