{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "skeleton-auto",
  "title": "Skeleton auto",
  "description": "SkeletonSwap traces its children's text lines, controls and avatars (<img> or data-skeleton elements) into shimmer blocks with one shared sweep, then cross-fades to the real content; includes line, circle and block primitives.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/goodui-motion.json"
  ],
  "files": [
    {
      "path": "registry/components/feedback/skeleton-auto.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\"\nimport { cn } from \"@/lib/utils\"\nimport { GooduiTokens, ease as easing } from \"@/lib/goodui-motion\"\n\n// Every block's highlight is offset by its own x position, so one band sweeps across the whole layout.\nconst CSS = `\n@keyframes pc-skeleton-auto-sweep { from { transform: translateX(-70%) } to { transform: translateX(70%) } }\n/* :where() keeps specificity at zero so Tailwind classes (absolute, bg-*) always win. */\n:where(.pc-skeleton-auto) {\n  overflow: hidden;\n  background-color: color-mix(in oklab, var(--foreground) 8%, transparent);\n}\n.pc-skeleton-auto::after {\n  content: \"\"; position: absolute; top: 0; bottom: 0;\n  left: calc(-1 * var(--pc-sk-x, 0px)); width: var(--pc-sk-w, 100%); min-width: 100%;\n  background: linear-gradient(90deg, transparent 30%, color-mix(in oklab, var(--background) 65%, transparent) 50%, transparent 70%);\n  transform: translateX(-70%);\n  animation: pc-skeleton-auto-sweep 1.7s var(--pc-ease-in-out) infinite;\n}\n.dark .pc-skeleton-auto::after { background: linear-gradient(90deg, transparent 30%, color-mix(in oklab, var(--foreground) 7%, transparent) 50%, transparent 70%); }\n@media (prefers-reduced-motion: reduce) { .pc-skeleton-auto::after { animation: none; opacity: 0 } }\n`\n\nfunction SkeletonStyle() {\n  return (\n    <style href=\"pc-skeleton-auto\" precedence=\"default\">\n      {CSS}\n    </style>\n  )\n}\n\n/* -------------------------------------------------------------- primitives */\n\nexport type SkeletonProps = React.ComponentProps<\"div\">\n\n/** A shimmering block. Size it with classes, e.g. \"h-24 w-full rounded-xl\". */\nexport function Skeleton({ className, ...props }: SkeletonProps) {\n  return (\n    <>\n      <GooduiTokens />\n      <SkeletonStyle />\n      <div aria-hidden=\"true\" data-slot=\"skeleton\" className={cn(\"pc-skeleton-auto relative rounded-md\", className)} {...props} />\n    </>\n  )\n}\n\nexport type SkeletonLineProps = SkeletonProps & {\n  /** CSS width, e.g. \"60%\" or 120. */\n  width?: number | string\n}\n\n/** One line of text. */\nexport function SkeletonLine({ width = \"100%\", className, style, ...props }: SkeletonLineProps) {\n  return <Skeleton className={cn(\"h-3 rounded-full\", className)} style={{ width, ...style }} {...props} />\n}\n\nexport type SkeletonCircleProps = SkeletonProps & {\n  /** Diameter in px. */\n  size?: number\n}\n\n/** An avatar or icon placeholder. */\nexport function SkeletonCircle({ size = 40, className, style, ...props }: SkeletonCircleProps) {\n  return <Skeleton className={cn(\"shrink-0 rounded-full\", className)} style={{ width: size, height: size, ...style }} {...props} />\n}\n\n/* ------------------------------------------------------------ auto layout */\n\ntype Bone = { x: number; y: number; w: number; h: number; r: string; text?: boolean }\n\nconst LEAF_TAGS = new Set([\"img\", \"svg\", \"video\", \"canvas\", \"input\", \"textarea\", \"select\", \"button\", \"picture\", \"iframe\", \"progress\", \"meter\"])\n\n/** Reads the rendered children and returns a block for every text line, image, icon and control. */\nfunction measureBones(root: HTMLElement, content: HTMLElement): Bone[] {\n  // Bones are absolutely positioned against the padding box, so measure from inside the border.\n  const box = root.getBoundingClientRect()\n  const base = { left: box.left + root.clientLeft, top: box.top + root.clientTop }\n  const bones: Bone[] = []\n  const range = document.createRange()\n\n  const walk = (el: Element) => {\n    for (const node of Array.from(el.childNodes)) {\n      if (node.nodeType === Node.TEXT_NODE) {\n        if (!node.textContent?.trim()) continue\n        const clip = el.getBoundingClientRect()\n        range.selectNodeContents(node)\n        // One rect per wrapped line, so paragraphs become several bars of the right lengths.\n        for (const r of Array.from(range.getClientRects())) {\n          const left = Math.max(r.left, clip.left)\n          const right = Math.min(r.right, clip.right)\n          if (right - left < 2 || r.height < 2) continue\n          const h = Math.max(6, Math.round(r.height * 0.62))\n          const bone = { x: left - base.left, y: r.top - base.top + (r.height - h) / 2, w: right - left, h, r: `${Math.min(h / 2, 6)}px`, text: true }\n          // React splits \"{a} · {b}\" into several text nodes; join pieces that sit on the same line.\n          const prev = bones[bones.length - 1]\n          if (prev?.text && Math.abs(prev.y - bone.y) < 2 && prev.h === bone.h && bone.x - (prev.x + prev.w) < 8 && bone.x >= prev.x) {\n            prev.w = bone.x + bone.w - prev.x\n          } else bones.push(bone)\n        }\n      } else if (node instanceof Element) {\n        if (node.hasAttribute(\"data-skeleton-ignore\")) continue\n        const style = getComputedStyle(node)\n        if (style.display === \"none\" || style.visibility === \"hidden\") continue\n        const tag = node.tagName.toLowerCase()\n        if (LEAF_TAGS.has(tag) || node.hasAttribute(\"data-skeleton\")) {\n          const r = node.getBoundingClientRect()\n          if (r.width < 2 || r.height < 2) continue\n          const radius = tag === \"svg\" ? \"4px\" : style.borderRadius && style.borderRadius !== \"0px\" ? style.borderRadius : \"6px\"\n          bones.push({ x: r.left - base.left, y: r.top - base.top, w: r.width, h: r.height, r: radius })\n          continue\n        }\n        walk(node)\n      }\n    }\n  }\n  walk(content)\n  range.detach?.()\n  return bones\n}\n\nexport type SkeletonSwapProps = Omit<React.ComponentProps<\"div\">, \"children\"> & {\n  /** While true, the children are hidden and the skeleton shows; set it to false to cross-fade to the content. */\n  loading: boolean\n  /**\n   * The real content. While loading, render it with placeholder data: it stays invisible and its layout is traced\n   * into skeleton blocks. Mark parts with data-skeleton (one solid block) or data-skeleton-ignore (skip).\n   */\n  children: React.ReactNode\n  /** Hand-made skeleton instead of the traced one. */\n  fallback?: React.ReactNode\n  /** Announced to screen readers while loading. */\n  loadingLabel?: string\n}\n\n/** Shows a shimmer skeleton shaped like its children while loading, then cross-fades to the real content. */\nexport function SkeletonSwap({ loading, children, fallback, loadingLabel = \"Loading…\", className, ...props }: SkeletonSwapProps) {\n  const reduce = useReducedMotion() ?? false\n  const rootRef = React.useRef<HTMLDivElement>(null)\n  const contentRef = React.useRef<HTMLDivElement>(null)\n  const [bones, setBones] = React.useState<Bone[]>([])\n  const [width, setWidth] = React.useState(0)\n  const auto = fallback === undefined\n\n  React.useLayoutEffect(() => {\n    const root = rootRef.current\n    const content = contentRef.current\n    if (!loading || !auto || !root || !content) return\n    let frame = 0\n    const run = () => {\n      cancelAnimationFrame(frame)\n      frame = requestAnimationFrame(() => {\n        setBones(measureBones(root, content))\n        setWidth(root.offsetWidth)\n      })\n    }\n    setBones(measureBones(root, content))\n    setWidth(root.offsetWidth)\n    const ro = new ResizeObserver(run)\n    ro.observe(root)\n    const mo = new MutationObserver(run)\n    mo.observe(content, { childList: true, subtree: true, characterData: true })\n    return () => {\n      cancelAnimationFrame(frame)\n      ro.disconnect()\n      mo.disconnect()\n    }\n  }, [loading, auto])\n\n  const fade = reduce ? { duration: 0.15 } : { duration: 0.35, ease: easing.inOut }\n\n  return (\n    <div ref={rootRef} aria-busy={loading} className={cn(\"relative grid\", className)} {...props}>\n      <SkeletonStyle />\n      {loading && (\n        <span role=\"status\" className=\"sr-only\">\n          {loadingLabel}\n        </span>\n      )}\n      <motion.div\n        ref={contentRef}\n        className=\"col-start-1 row-start-1 min-w-0\"\n        inert={loading}\n        aria-hidden={loading || undefined}\n        initial={false}\n        animate={{ opacity: loading ? 0 : 1 }}\n        transition={fade}\n      >\n        {children}\n      </motion.div>\n      <AnimatePresence initial={false}>\n        {loading && (\n          <motion.div\n            key=\"skeleton\"\n            aria-hidden=\"true\"\n            // An absolute child placed in a grid cell would be positioned against that cell, so the traced layer is not placed.\n            className={cn(\"pointer-events-none min-w-0\", auto ? \"absolute inset-0\" : \"col-start-1 row-start-1\")}\n            initial={{ opacity: 0 }}\n            animate={{ opacity: 1 }}\n            exit={{ opacity: 0 }}\n            transition={fade}\n          >\n            {auto\n              ? bones.map((b, i) => (\n                  <div\n                    key={i}\n                    className=\"pc-skeleton-auto absolute\"\n                    style={{\n                      left: b.x,\n                      top: b.y,\n                      width: b.w,\n                      height: b.h,\n                      borderRadius: b.r,\n                      [\"--pc-sk-x\" as string]: `${b.x}px`,\n                      [\"--pc-sk-w\" as string]: `${width}px`,\n                    }}\n                  />\n                ))\n              : fallback}\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </div>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/skeleton-auto.tsx"
    }
  ],
  "categories": [
    "components",
    "feedback"
  ],
  "type": "registry:component"
}