{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ink-reveal",
  "title": "InkReveal",
  "description": "Inks a Panel or PanelPair frame (6 poses) before its cut number lands (1 pose) and its content appears in one cut. CSS only; the stroke starts in reading order (top-right under dir=\"rtl\").",
  "registryDependencies": [
    "https://frame12.dev/r/frame12-styles.json",
    "https://frame12.dev/r/use-tempo.json",
    "https://frame12.dev/r/ink-stroke.json",
    "https://frame12.dev/r/panel.json"
  ],
  "files": [
    {
      "path": "ui/ink-reveal.tsx",
      "content": "'use client';\n\nimport * as React from 'react';\nimport { useResolvedMotion } from '@/hooks/use-tempo';\nimport { isInkCycleEvent, useInkCycle } from './ink';\n\n// Same union as `MotionMode` in use-on-twos.ts. Declared locally so this file only needs use-tempo.\ntype MotionMode = 'stepped' | 'smooth' | 'cut';\n\nexport interface InkRevealProps {\n  /**\n   * Inks the wrapped panel when this changes to `true` after mount: the frame draws (6 poses),\n   * the cut number lands (1 pose), then the content appears in one cut. A value that is `true` at\n   * mount never plays (rule 5; the `ink-autoplay` lint rule enforces it).\n   */\n  play?: boolean;\n  /** The reveal's own motion, resolved against the viewer's tempo and OS reduced motion. */\n  motion?: MotionMode;\n  /** Called once per reveal, when the content has appeared; not when motion cancels the reveal. */\n  onEnd?: () => void;\n  /** One `Panel` or `PanelPair`. */\n  children?: React.ReactNode;\n}\n\n/** Reads the measured frame polygon and returns the top-right corner's position along it (0..1). */\nfunction topRightFraction(polygon: SVGPolygonElement | null): number {\n  const raw = polygon?.getAttribute('points')?.trim();\n  if (!raw) return 0;\n  const nums = raw.split(/[\\s,]+/).map(Number);\n  const pts: [number, number][] = [];\n  for (let i = 0; i + 1 < nums.length; i += 2) pts.push([nums[i], nums[i + 1]]);\n  if (pts.length < 3) return 0;\n  let total = 0;\n  const lens = pts.map((p, i) => {\n    const q = pts[(i + 1) % pts.length];\n    const l = Math.hypot(q[0] - p[0], q[1] - p[1]);\n    total += l;\n    return l;\n  });\n  return total > 0 ? lens[0] / total : 0;\n}\n\n/**\n * Inks a `Panel` (or `PanelPair`) frame before its content appears, by CSS alone. The stroke\n * starts at the top-left corner (top-right under `dir=\"rtl\"`) and follows reading order. Only the\n * measured frame polygon (`pathLength=\"1\"`) is animated, never the SSR `viewBox` polygon.\n */\nexport function InkReveal({ play = false, motion = 'stepped', onEnd, children }: InkRevealProps) {\n  const resolved = useResolvedMotion(motion);\n  const cycle = useInkCycle(play);\n  // A cycle is consumed when its content has appeared or when motion resolves to cut mid-reveal.\n  // Only a new false → true change of `play` reveals again; re-enabling motion never replays it.\n  const [ended, setEnded] = React.useState<number>(0);\n  if (resolved === 'cut' && play && cycle > 0 && ended !== cycle) setEnded(cycle);\n  const playing = play && cycle > 0 && ended !== cycle && resolved !== 'cut';\n  // Every panel body lands at the same pose, so the first one's animationend means all content\n  // has appeared. A PanelPair (two bodies) or nested panels must still end the cycle only once,\n  // and the events arrive before React re-renders, hence a ref rather than state.\n  const endedRef = React.useRef<number>(0);\n  const ref = React.useRef<HTMLDivElement | null>(null);\n  const [start, setStart] = React.useState<{ cycle: number; rtl: boolean }>({ cycle: 0, rtl: false });\n  // The animation only starts once this play's start corner is known (same commit, before paint).\n  const ready = start.cycle === cycle;\n\n  // Read once per play, on the user's action (never per frame): direction, and each frame's own\n  // top-right corner position along its outline (a PanelPair's two panels have different shapes),\n  // written to that polygon so its RTL stroke starts at its own corner.\n  const useIso = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;\n  useIso(() => {\n    if (!playing || ready || !ref.current) return;\n    const rtl = getComputedStyle(ref.current).direction === 'rtl';\n    for (const polygon of ref.current.querySelectorAll<SVGPolygonElement>(\n      '.f12-panel-frame polygon:not([vector-effect])',\n    )) {\n      const at = rtl ? topRightFraction(polygon) : 0;\n      polygon.style.setProperty('--f12-ink-from', String(-at));\n      polygon.style.setProperty('--f12-ink-to', String(1 - at));\n    }\n    setStart({ cycle, rtl });\n  }, [playing, ready, cycle]);\n\n  return (\n    <div\n      ref={ref}\n      className={`f12-ink-reveal f12-m-${resolved}`}\n      data-ink={playing && ready ? (cycle % 2 ? 'a' : 'b') : undefined}\n      data-ink-dir={start.rtl ? 'rtl' : 'ltr'}\n      onAnimationEnd={(e) => {\n        const target = e.target as Element;\n        if (\n          ended === cycle ||\n          endedRef.current === cycle ||\n          !isInkCycleEvent(e.animationName, 'f12InkLand', cycle) ||\n          !target.classList?.contains('f12-panel-body') ||\n          // A nested InkReveal reports its own completion, never this one's.\n          target.closest('.f12-ink-reveal') !== e.currentTarget\n        ) {\n          return;\n        }\n        endedRef.current = cycle;\n        setEnded(cycle);\n        onEnd?.();\n      }}\n    >\n      {children}\n    </div>\n  );\n}\n",
      "type": "registry:ui",
      "target": "components/frame12/ink-reveal.tsx"
    }
  ],
  "type": "registry:ui"
}