{
  "$schema": "https://shadcn-svelte.com/schema/registry-item.json",
  "name": "image-text",
  "title": "ImageText",
  "type": "registry:ui",
  "description": "Moves a photograph through one stationary, selectable text element.",
  "dependencies": [],
  "meta": {
    "kida": {
      "package": {
        "name": "@kida-ui/svelte",
        "exportName": "ImageText",
        "styleImports": [
          "@kida-ui/styles/components/image-text.css"
        ]
      },
      "framework": "svelte"
    }
  },
  "categories": [
    "text"
  ],
  "files": [
    {
      "content": "<script lang=\"ts\">\nimport './image-text.css'\nimport { type ImageTextControls, imageText, imageTextStyle } from './image-text.motion.js'\nimport { untrack } from 'svelte'\nimport type { ImageTextProps } from './image-text.types.js'\n\nlet {\n  text,\n  as = 'h2',\n  image,\n  position,\n  duration,\n  zoom,\n  paused = false,\n  element = $bindable(null),\n  style,\n  ...rest\n}: ImageTextProps = $props()\n\nlet controls: ImageTextControls | null = null\nconst root = $derived(element)\nconst restartKey = $derived(JSON.stringify([text, duration, image, zoom]))\n\nconst rootStyle = $derived.by(() => {\n  const authored = style\n  const variables = imageTextStyle({ image, position, duration })\n  const measured = untrack(() => element?.style.getPropertyValue('--kida-image-text-size'))\n  if (measured) variables['--kida-image-text-size'] = measured\n  return [...Object.entries(variables).map(([key, value]) => `${key}: ${value}`), authored]\n    .filter(Boolean)\n    .join('; ')\n})\n\nconst attributes = $derived({\n  ...rest,\n  style: rootStyle,\n  'data-kida-image-text': '',\n  'data-image': 'loading',\n  'data-state': 'pending',\n  'data-suspended': 'true',\n  'data-paused': String(paused),\n})\n\n$effect(() => {\n  const node = root\n  void restartKey\n  if (!node) return\n  const created = untrack(() => imageText(node, { image, position, duration, zoom, paused }))\n  controls = created\n  return () => {\n    created.destroy()\n    if (controls === created) controls = null\n  }\n})\n\n$effect(() => {\n  const value = paused\n  untrack(() => controls?.setPaused(value))\n})\n</script>\n\n{#if as === 'h1'}<h1 {...attributes} bind:this={element}>{text}</h1>\n{:else if as === 'h3'}<h3 {...attributes} bind:this={element}>{text}</h3>\n{:else if as === 'h4'}<h4 {...attributes} bind:this={element}>{text}</h4>\n{:else if as === 'h5'}<h5 {...attributes} bind:this={element}>{text}</h5>\n{:else if as === 'h6'}<h6 {...attributes} bind:this={element}>{text}</h6>\n{:else if as === 'p'}<p {...attributes} bind:this={element}>{text}</p>\n{:else}<h2 {...attributes} bind:this={element}>{text}</h2>\n{/if}\n",
      "type": "registry:ui",
      "target": "kida/image-text.svelte"
    },
    {
      "content": "import type { ImageTextOptions } from './image-text.motion.js';\n\nimport type { HTMLAttributes } from 'svelte/elements';\n\ntype TextAttributes<T extends EventTarget> = Omit<HTMLAttributes<T>, 'children'>;\n\nexport interface ImageTextProps extends ImageTextOptions, TextAttributes<HTMLElement> {\n    text: string;\n    as?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'p';\n    element?: HTMLElement | null;\n}\n",
      "type": "registry:ui",
      "target": "kida/image-text.types.ts"
    },
    {
      "content": "import { prefersReducedMotion, watchReducedMotion } from './reduced-motion.motion.js'\n\nexport interface ImageTextOptions {\n  /** A photo or texture supplied by the application. */\n  image: string\n  /** Center crop, in percentages. @default [50, 50] */\n  position?: readonly [number, number]\n  /** Milliseconds per complete crop cycle; zero is static. @default 9600 */\n  duration?: number\n  /** Image overscan, clamped to 1–4. @default 1.28 */\n  zoom?: number\n  /** Freeze the current frame without restarting the cycle. @default false */\n  paused?: boolean\n}\n\nexport interface ImageTextControls {\n  setPaused(paused: boolean): void\n  destroy(): void\n}\n\nconst finite = (value: number | undefined, fallback: number) =>\n  value !== undefined && Number.isFinite(value) ? value : fallback\nconst percent = (value: number) => Math.min(100, Math.max(0, value))\n\n/** Deterministic styles for SSR and the shared background-position keyframes. */\nexport function imageTextStyle({\n  image,\n  position,\n  duration,\n}: ImageTextOptions): Record<string, string> {\n  const x = percent(finite(position?.[0], 50))\n  const y = percent(finite(position?.[1], 50))\n  const crop = (dx: number, dy: number) => `${percent(x + dx)}% ${percent(y + dy)}%`\n  return {\n    '--kida-image-text-image': image.trim() ? `url(${JSON.stringify(image)})` : 'none',\n    '--kida-image-text-position': crop(0, 0),\n    '--kida-image-text-crop-one': crop(30, -16),\n    '--kida-image-text-crop-two': crop(-26, 18),\n    '--kida-image-text-crop-three': crop(18, -8),\n    ...(duration === undefined\n      ? {}\n      : { '--kida-image-text-duration': `${Math.max(0, finite(duration, 9600))}ms` }),\n  }\n}\n\n/** A decoded photograph moves beneath one unsplit text element. No per-frame JS work. */\nexport function imageText(root: HTMLElement, options: ImageTextOptions): ImageTextControls {\n  let disposed = false\n  let decoded = false\n  let visible = false\n  let paused = options.paused ?? false\n  let reduced = prefersReducedMotion()\n  const duration = Math.max(0, finite(options.duration, 9600))\n  const zoom = Math.min(4, Math.max(1, finite(options.zoom, 1.28)))\n  const photo = new Image()\n\n  root.dataset.image = 'loading'\n  root.dataset.state = 'pending'\n  root.dataset.suspended = 'true'\n  root.dataset.paused = String(paused)\n\n  const measure = () => {\n    if (disposed || !decoded) return\n    // Decode, font reflow and resize are the only geometry reads; animation just repaints.\n    const scale =\n      Math.max(root.clientWidth / photo.naturalWidth, root.clientHeight / photo.naturalHeight) *\n      zoom\n    root.style.setProperty(\n      '--kida-image-text-size',\n      `${Math.ceil(photo.naturalWidth * scale)}px ${Math.ceil(photo.naturalHeight * scale)}px`,\n    )\n  }\n  const update = () => {\n    if (disposed || !decoded) return\n    if (reduced || duration === 0 || !root.textContent?.trim()) {\n      root.dataset.state = 'settled'\n    } else if (visible && !document.hidden && !paused) {\n      root.dataset.state = 'moving'\n    }\n    root.dataset.suspended = String(\n      root.dataset.state !== 'moving' || paused || !visible || document.hidden,\n    )\n  }\n  const fail = () => {\n    if (disposed) return\n    root.dataset.image = 'error'\n    root.dataset.state = 'fallback'\n  }\n  const intersection = new IntersectionObserver(([entry]) => {\n    visible = entry?.isIntersecting ?? false\n    update()\n  })\n  const resize = new ResizeObserver(measure)\n  const unwatch = watchReducedMotion((value) => {\n    reduced = value\n    update()\n  })\n\n  photo.onload = async () => {\n    try {\n      await photo.decode()\n      if (disposed) return\n      decoded = true\n      measure()\n      root.dataset.image = 'ready'\n      update()\n    } catch {\n      fail()\n    }\n  }\n  photo.onerror = fail\n  intersection.observe(root)\n  resize.observe(root)\n  document.addEventListener('visibilitychange', update)\n  if (options.image.trim()) photo.src = options.image\n  else fail()\n\n  return {\n    setPaused(value) {\n      if (disposed) return\n      paused = value\n      root.dataset.paused = String(value)\n      update()\n    },\n    destroy() {\n      disposed = true\n      photo.onload = null\n      photo.onerror = null\n      photo.removeAttribute('src')\n      intersection.disconnect()\n      resize.disconnect()\n      unwatch()\n      document.removeEventListener('visibilitychange', update)\n      root.dataset.state = 'pending'\n      root.dataset.image = 'loading'\n      root.dataset.suspended = 'true'\n      root.style.removeProperty('--kida-image-text-size')\n    },\n  }\n}\n",
      "type": "registry:ui",
      "target": "kida/image-text.motion.ts"
    },
    {
      "content": "const QUERY = '(prefers-reduced-motion: reduce)'\n\n/**\n * Whether the user has asked for reduced motion.\n *\n * SSR-safe: returns `false` when there is no `window`, matching the CSS default\n * (the `prefers-reduced-motion` media query in `@kida-ui/styles` is the real guard;\n * this is for the JS-driven paths that CSS cannot express).\n */\nexport function prefersReducedMotion(): boolean {\n  if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return false\n  return window.matchMedia(QUERY).matches\n}\n\n/**\n * Subscribe to changes of the reduced-motion preference.\n * Returns an unsubscribe function. No-op (and immediately unsubscribable) on the server.\n */\nexport function watchReducedMotion(onChange: (reduced: boolean) => void): () => void {\n  if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return () => {}\n\n  const list = window.matchMedia(QUERY)\n  const handler = (event: MediaQueryListEvent) => onChange(event.matches)\n  list.addEventListener('change', handler)\n  return () => list.removeEventListener('change', handler)\n}\n",
      "type": "registry:ui",
      "target": "kida/reduced-motion.motion.ts"
    },
    {
      "content": "@import './tokens.css';\n\n[data-kida-image-text] {\n  margin: 0;\n  color: var(--kida-image-text-ink, var(--kida-ink, #211c24));\n  font-size: var(--kida-image-text-font-size, clamp(2.5rem, 6vw, 7.375rem));\n  font-weight: var(--kida-image-text-weight, 520);\n  line-height: var(--kida-image-text-leading, 1.06);\n  letter-spacing: var(--kida-image-text-tracking, -0.065em);\n  overflow-wrap: anywhere;\n  text-wrap: pretty;\n}\n\n@supports ((background-clip: text) or (-webkit-background-clip: text)) {\n  [data-kida-image-text][data-image=\"ready\"] {\n    background-color: var(--kida-image-text-ink, var(--kida-ink, #211c24));\n    background-image:\n      linear-gradient(\n        var(--kida-image-text-tint, #3c092b8c),\n        var(--kida-image-text-tint, #3c092b8c)\n      ),\n      var(--kida-image-text-image);\n    background-size:\n      100% 100%,\n      var(--kida-image-text-size, cover);\n    background-repeat: no-repeat;\n    background-position: var(--kida-image-text-position, 50% 50%);\n    background-clip: text;\n    -webkit-background-clip: text;\n    color: transparent;\n    -webkit-text-fill-color: transparent;\n  }\n\n  [data-kida-image-text][data-image=\"ready\"][data-state=\"moving\"] {\n    animation: kida-image-text-drift\n      var(--kida-image-text-duration, calc(var(--kida-duration-xl, 800ms) * 12))\n      var(--kida-ease-in-out, cubic-bezier(0.65, 0, 0.35, 1)) infinite both;\n  }\n\n  [data-kida-image-text][data-image=\"ready\"][data-suspended=\"true\"],\n  [data-kida-image-text][data-image=\"ready\"][data-paused=\"true\"] {\n    animation-play-state: paused;\n  }\n}\n\n@keyframes kida-image-text-drift {\n  0%,\n  100% {\n    background-position: var(--kida-image-text-position, 50% 50%);\n  }\n  25% {\n    background-position: var(--kida-image-text-crop-one, 80% 34%);\n  }\n  50% {\n    background-position: var(--kida-image-text-crop-two, 24% 68%);\n  }\n  75% {\n    background-position: var(--kida-image-text-crop-three, 68% 42%);\n  }\n}\n\n[data-kida-image-text]::selection {\n  color: var(--kida-image-text-ink, var(--kida-ink, #211c24));\n  -webkit-text-fill-color: var(--kida-image-text-ink, var(--kida-ink, #211c24));\n  background: var(--kida-image-text-selection, #f4cf63);\n}\n\n@media (prefers-reduced-motion: reduce) {\n  [data-kida-image-text][data-image=\"ready\"][data-state=\"moving\"] {\n    animation: none;\n  }\n}\n\n@media (forced-colors: active) {\n  [data-kida-image-text][data-image=\"ready\"] {\n    background: none;\n    color: CanvasText;\n    -webkit-text-fill-color: CanvasText;\n  }\n}\n\n@media print {\n  [data-kida-image-text][data-image=\"ready\"] {\n    background: none;\n    color: #211c24;\n    -webkit-text-fill-color: #211c24;\n  }\n}\n\n@media (forced-colors: active), print {\n  [data-kida-image-text][data-image=\"ready\"][data-state] {\n    animation: none;\n  }\n}\n",
      "type": "registry:ui",
      "target": "kida/image-text.css"
    },
    {
      "content": "/*\n * Kida UI — motion tokens.\n * Plain CSS custom properties (ADR D7). No preprocessor, no Tailwind, no build step.\n */\n\n:root {\n  /* Durations */\n  --kida-duration-xs: 100ms;\n  --kida-duration-sm: 150ms;\n  --kida-duration-md: 300ms;\n  --kida-duration-lg: 500ms;\n  --kida-duration-xl: 800ms;\n\n  /* Easings */\n  --kida-ease-out: cubic-bezier(0.16, 1, 0.3, 1);\n  --kida-ease-in: cubic-bezier(0.7, 0, 0.84, 0);\n  --kida-ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);\n  --kida-ease-spring: linear(0, 0.5, 0.9, 1.02, 1);\n\n  /* Travel distances used by the enter/exit keyframes */\n  --kida-distance-sm: 4px;\n  --kida-distance-md: 8px;\n  --kida-distance-lg: 16px;\n\n  /* Stagger step between siblings */\n  --kida-stagger: 60ms;\n}\n\n/*\n * The shared reduced-motion guard for CSS-driven animation in the library.\n * Durations collapse to ~0 by default. Components whose presence lifecycle cannot safely observe\n * a 1ms animation, such as Collapse, disable it explicitly and complete presence in their adapter.\n */\n@media (prefers-reduced-motion: reduce) {\n  :root {\n    --kida-duration-xs: 1ms;\n    --kida-duration-sm: 1ms;\n    --kida-duration-md: 1ms;\n    --kida-duration-lg: 1ms;\n    --kida-duration-xl: 1ms;\n    --kida-distance-sm: 0px;\n    --kida-distance-md: 0px;\n    --kida-distance-lg: 0px;\n    --kida-stagger: 0ms;\n  }\n}\n",
      "type": "registry:ui",
      "target": "kida/tokens.css"
    }
  ]
}
