{
  "$schema": "https://shadcn-vue.com/schema/registry-item.json",
  "name": "photo-pile",
  "title": "PhotoPile",
  "description": "Layers draggable photos that spring back into a playful composition.",
  "dependencies": [
    "motion@^13.1.0"
  ],
  "files": [
    {
      "path": "registry/vue/kida/photo-pile.vue",
      "content": "<script setup lang=\"ts\">\nimport './photo-pile.css'\nimport { photoPile } from './photo-pile.motion.js'\nimport { shallowRef, watch } from 'vue'\nimport type { PhotoPilePhoto, PhotoPileProps } from './photo-pile.types.js'\n\ndefineOptions({ name: 'KidaPhotoPile', inheritAttrs: false })\nconst props = defineProps<PhotoPileProps>()\nconst element = shallowRef<HTMLFieldSetElement | null>(null)\nconst items = new Map<string, HTMLButtonElement>()\ndefineExpose({ element })\nconst positions = [\n  { x: -54, y: -10, rotation: -7 },\n  { x: 52, y: -18, rotation: 6 },\n  { x: 2, y: 30, rotation: -1.5 },\n  { x: -24, y: -38, rotation: 4 },\n  { x: 38, y: 24, rotation: -5 },\n] as const\n\nwatch(\n  [\n    () => element.value,\n    () => JSON.stringify(props.photos.map((photo) => photo.id)),\n    () => props.dragScale,\n    () => props.tilt,\n  ],\n  (_, __, onCleanup) => {\n    const node = element.value\n    if (!node) return\n    // Collection changes end the previous gesture and reset layering in the new DOM order.\n    node.querySelectorAll<HTMLElement>('[data-kida-photo-item]').forEach((item, index) => {\n      item.style.zIndex = String(index + 1)\n    })\n    onCleanup(photoPile(node, { ...props }))\n  },\n  { flush: 'post' },\n)\n\nfunction setItem(id: string, node: unknown) {\n  if (node) items.set(id, node as HTMLButtonElement)\n  else items.delete(id)\n}\n\nfunction itemStyle(photo: PhotoPilePhoto, index: number) {\n  const fallback = positions[index % positions.length] ?? positions[0]\n  return {\n    '--kida-photo-x': `${(photo.x ?? fallback.x) * (props.spread ?? 1)}px`,\n    '--kida-photo-y': `${(photo.y ?? fallback.y) * (props.spread ?? 1)}px`,\n    '--kida-photo-rotation': `${photo.rotation ?? fallback.rotation}deg`,\n    zIndex: items.get(photo.id)?.style.zIndex ?? index + 1,\n  }\n}\n</script>\n\n<template>\n  <fieldset v-bind=\"$attrs\" ref=\"element\" :aria-label=\"($attrs['aria-label'] as string | undefined) ?? 'Draggable photo pile'\" data-kida-photo-pile=\"\">\n    <span data-kida-photo-stage=\"\">\n      <button v-for=\"(photo, index) in props.photos\" :key=\"photo.id\" :ref=\"(node) => setItem(photo.id, node)\" type=\"button\" :aria-label=\"`Bring ${photo.alt || `Photo ${index + 1}`} to front and drag`\" data-kida-photo-item=\"\" :style=\"itemStyle(photo, index)\">\n        <span data-kida-photo-card=\"\">\n          <img v-bind=\"photo.imageProps\" :src=\"photo.src\" :alt=\"photo.alt\" :draggable=\"false\" />\n        </span>\n      </button>\n    </span>\n  </fieldset>\n</template>\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/vue/kida/photo-pile.types.ts",
      "content": "import type { PhotoPileOptions } from './photo-pile.motion.js';\n\nimport type { ImgHTMLAttributes } from 'vue';\n\nexport interface PhotoPilePhoto {\n    /** Unique, stable key for this photo. */\n    id: string;\n    src: string;\n    alt: string;\n    x?: number;\n    y?: number;\n    rotation?: number;\n    imageProps?: Omit<ImgHTMLAttributes, 'src' | 'alt' | 'draggable'>;\n}\n\nexport interface PhotoPileProps extends PhotoPileOptions {\n    photos: readonly PhotoPilePhoto[];\n    /** Multiplies default and authored x/y offsets. @default 1 */\n    spread?: number;\n}\n\n/** Vue component refs expose the root DOM element, null when presence removes it. */\nexport interface KidaElement {\n    element: HTMLElement | null;\n}\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/vue/kida/photo-pile.css",
      "content": "[data-kida-photo-pile] {\n  --kida-photo-width: clamp(9rem, 42%, 13.5rem);\n  --kida-photo-radius: 0.55rem;\n  --kida-photo-frame: #fffafb;\n  --kida-photo-shadow: 0 0.8rem 2rem rgb(50 30 42 / 16%);\n\n  position: relative;\n  display: block;\n  min-inline-size: 0;\n  width: min(100%, 36rem);\n  min-height: 22rem;\n  margin: 0;\n  padding: 0;\n  border: 0;\n  isolation: isolate;\n}\n\n/* Chromium does not reliably use a fieldset itself as the containing block for absolutely\n   positioned children. A normal-flow stage keeps every card anchored to the pile wherever the\n   fieldset appears on the page. */\n[data-kida-photo-stage] {\n  position: relative;\n  /* Grid centers fractional card sizes without percentage transforms, which WebKit rounds. */\n  display: grid;\n  place-items: center;\n  /* Fill explicitly sized previews as well as the pile's default minimum height. */\n  height: 100%;\n  min-height: inherit;\n}\n\n[data-kida-photo-item] {\n  position: absolute;\n  width: var(--kida-photo-width);\n  margin: 0;\n  padding: 0;\n  border: 0;\n  border-radius: var(--kida-photo-radius);\n  background: transparent;\n  cursor: grab;\n  touch-action: none;\n  transform: translate(var(--kida-photo-x), var(--kida-photo-y)) rotate(var(--kida-photo-rotation));\n}\n\n[data-kida-photo-item][data-dragging] {\n  cursor: grabbing;\n}\n\n[data-kida-photo-item]:focus-visible {\n  outline: 3px solid var(--kida-photo-focus, #6d52a8);\n  outline-offset: 5px;\n}\n\n[data-kida-photo-card] {\n  display: block;\n  padding: 0.45rem 0.45rem 1.8rem;\n  border: 1px solid rgb(55 35 48 / 12%);\n  border-radius: var(--kida-photo-radius);\n  background: var(--kida-photo-frame);\n  box-shadow: var(--kida-photo-shadow);\n  user-select: none;\n}\n\n[data-kida-photo-card] img {\n  display: block;\n  width: 100%;\n  aspect-ratio: 4 / 5;\n  border-radius: calc(var(--kida-photo-radius) - 0.2rem);\n  object-fit: cover;\n  pointer-events: none;\n}\n\n@media (max-width: 32rem) {\n  [data-kida-photo-pile] {\n    --kida-photo-width: min(48%, 10.5rem);\n\n    min-height: 18rem;\n  }\n}\n\n@media (prefers-reduced-motion: reduce) {\n  [data-kida-photo-card] {\n    /* biome-ignore lint/complexity/noImportantStyles: stops an in-flight inline transform */\n    transform: none !important;\n  }\n}\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/vue/kida/photo-pile.motion.ts",
      "content": "import { animate } from 'motion'\nimport { prefersReducedMotion } from './reduced-motion.motion.js'\n\nexport interface PhotoPileOptions {\n  /** Scale applied while a photo is being dragged. @default 1.035 */\n  dragScale?: number\n  /** Degrees of responsive tilt per horizontal CSS pixel. @default 0.025 */\n  tilt?: number\n}\n\nconst DEFAULTS = { dragScale: 1.035, tilt: 0.025 } as const\nconst IDENTITY = 'translate3d(0px, 0px, 0) rotate(0deg) scale(1)'\n\n/**\n * Adds direct pointer dragging and a spring return to every photo card in a pile.\n * The positioned item stays still; only its inner card moves, so authored layout transforms\n * never compete with the drag transform.\n */\nexport function photoPile(root: HTMLElement, options: PhotoPileOptions = {}): () => void {\n  const { dragScale = DEFAULTS.dragScale, tilt = DEFAULTS.tilt } = options\n  const reduced = prefersReducedMotion()\n  const items = [...root.querySelectorAll<HTMLElement>('[data-kida-photo-item]')]\n  const cleanups: Array<() => void> = []\n  const originalZ = new Map(items.map((item) => [item, item.style.zIndex]))\n  let topLayer = items.length\n\n  const activate = (item: HTMLElement) => {\n    topLayer += 1\n    item.style.zIndex = String(topLayer)\n  }\n\n  for (const item of items) {\n    const card = item.querySelector<HTMLElement>('[data-kida-photo-card]')\n    if (!card) continue\n\n    let pointerId: number | undefined\n    let originX = 0\n    let originY = 0\n    let x = 0\n    let y = 0\n    let frame = 0\n    let settleFrame = 0\n    let controls: ReturnType<typeof animate> | undefined\n\n    const transform = () =>\n      `translate3d(${x}px, ${y}px, 0) rotate(${x * tilt}deg) scale(${dragScale})`\n\n    const paint = () => {\n      frame = 0\n      card.style.transform = transform()\n    }\n\n    const settle = () => {\n      controls?.cancel()\n      controls = undefined\n      card.style.transform = 'none'\n      card.style.willChange = 'auto'\n      delete item.dataset.dragging\n    }\n\n    const onPointerDown = (event: PointerEvent) => {\n      if (pointerId !== undefined || (event.pointerType === 'mouse' && event.button !== 0)) return\n      if (settleFrame) {\n        cancelAnimationFrame(settleFrame)\n        settleFrame = 0\n      }\n      controls?.cancel()\n      pointerId = event.pointerId\n      originX = event.clientX\n      originY = event.clientY\n      x = 0\n      y = 0\n      activate(item)\n      item.dataset.dragging = ''\n      card.style.willChange = 'transform'\n      card.style.transform = IDENTITY\n      try {\n        item.setPointerCapture(pointerId)\n      } catch {\n        // Synthetic pointer events and older browsers may not expose capture; window listeners\n        // below still keep the gesture alive.\n      }\n    }\n\n    const onPointerMove = (event: PointerEvent) => {\n      if (event.pointerId !== pointerId) return\n      x = event.clientX - originX\n      y = event.clientY - originY\n      if (!frame) frame = requestAnimationFrame(paint)\n    }\n\n    const onPointerEnd = (event: PointerEvent) => {\n      if (event.pointerId !== pointerId) return\n      pointerId = undefined\n      if (frame) {\n        cancelAnimationFrame(frame)\n        frame = 0\n        card.style.transform = transform()\n      }\n      try {\n        if (item.hasPointerCapture(event.pointerId)) item.releasePointerCapture(event.pointerId)\n      } catch {\n        // See the capture fallback above.\n      }\n\n      if (reduced) {\n        settle()\n        return\n      }\n\n      const from = transform()\n      controls = animate(\n        card,\n        { transform: [from, IDENTITY] },\n        {\n          type: 'spring',\n          stiffness: 420,\n          damping: 30,\n          mass: 0.7,\n          // Motion commits the final keyframe after calling onComplete. Clear that committed\n          // identity transform on the following frame so the card truly returns to authored CSS.\n          onComplete: () => {\n            settleFrame = requestAnimationFrame(() => {\n              settleFrame = 0\n              settle()\n            })\n          },\n        },\n      )\n    }\n\n    const onFocus = () => activate(item)\n    item.addEventListener('pointerdown', onPointerDown)\n    window.addEventListener('pointermove', onPointerMove)\n    window.addEventListener('pointerup', onPointerEnd)\n    window.addEventListener('pointercancel', onPointerEnd)\n    item.addEventListener('focusin', onFocus)\n\n    cleanups.push(() => {\n      item.removeEventListener('pointerdown', onPointerDown)\n      window.removeEventListener('pointermove', onPointerMove)\n      window.removeEventListener('pointerup', onPointerEnd)\n      window.removeEventListener('pointercancel', onPointerEnd)\n      item.removeEventListener('focusin', onFocus)\n      if (frame) cancelAnimationFrame(frame)\n      if (settleFrame) cancelAnimationFrame(settleFrame)\n      settle()\n    })\n  }\n\n  return () => {\n    for (const cleanup of cleanups) cleanup()\n    for (const item of items) item.style.zIndex = originalZ.get(item) ?? ''\n  }\n}\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/vue/kida/reduced-motion.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"
    }
  ],
  "meta": {
    "kida": {
      "package": {
        "name": "@kida-ui/vue",
        "exportName": "PhotoPile",
        "styleImports": [
          "@kida-ui/styles/kida.css"
        ]
      },
      "framework": "vue"
    }
  },
  "categories": [
    "image"
  ],
  "type": "registry:ui"
}
