{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"quote-share","type":"registry:component","title":"Quote share","description":"Lifts the words you select out of the paragraph and into a shareable quote card.","author":"Yash Bavadiya <https://xevrion.dev>","dependencies":["motion"],"registryDependencies":["utils"],"files":[{"path":"components/quote-share.tsx","type":"registry:component","content":"\"use client\";\n\nimport {\n  useCallback,\n  useEffect,\n  useLayoutEffect,\n  useRef,\n  useState,\n} from \"react\";\nimport { AnimatePresence, motion } from \"motion/react\";\nimport { useReducedMotion } from \"@/hooks/use-reduced-motion\";\nimport { cn } from \"@/lib/utils\";\n\n/* The teachable part: the quote card is built from the reader's own words.\n   Every selected word is measured where it sits in the paragraph, then the\n   card lays the same words out and plays each one back from its old spot\n   (a FLIP per word), so the quote visibly lifts out of the article and the\n   gaps it leaves behind show exactly where it came from. */\n\ntype Word = { text: string; x: number; y: number; w: number; h: number };\ntype Quote = { words: Word[]; text: string; top: number; bottom: number };\n\nconst EASE_OUT = [0.23, 1, 0.32, 1] as const;\n// Longer than a typical UI move on purpose: the words cross most of the\n// frame and the reader needs to see where they land. iOS drawer curve, so\n// they leave the paragraph at once and settle gently.\nconst FLIGHT = { duration: 460, easing: \"cubic-bezier(0.32, 0.72, 0, 1)\" };\n// The way home is quicker and plainer: the reader has already seen the trip.\nconst RETURN = { duration: 300, easing: \"cubic-bezier(0.77, 0, 0.175, 1)\" };\n// Per-word stagger, capped so a long quote never takes longer to arrive.\nconst STAGGER = 12;\nconst STAGGER_MAX = 160;\n// Past this a quote card stops being a quote.\nconst MAX_WORDS = 50;\n// Space kept between the pill and the selected line.\nconst PILL_GAP = 10;\nconst PILL_H = 36;\n\n// Snaps a selection that starts or ends mid-word out to the whole word, so a\n// sloppy drag still quotes \"reading\", not \"ading\".\nfunction snap(range: Range) {\n  const r = range.cloneRange();\n  const { startContainer: s, endContainer: e } = r;\n  if (s.nodeType === Node.TEXT_NODE) {\n    const t = (s as Text).data;\n    let i = r.startOffset;\n    while (i > 0 && /\\S/.test(t[i - 1])) i--;\n    r.setStart(s, i);\n  }\n  if (e.nodeType === Node.TEXT_NODE) {\n    const t = (e as Text).data;\n    let i = r.endOffset;\n    while (i < t.length && /\\S/.test(t[i])) i++;\n    r.setEnd(e, i);\n  }\n  return r;\n}\n\nfunction collectWords(range: Range, frame: DOMRect): Word[] {\n  const root =\n    range.commonAncestorContainer.nodeType === Node.TEXT_NODE\n      ? range.commonAncestorContainer.parentNode!\n      : range.commonAncestorContainer;\n  const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);\n  const words: Word[] = [];\n  for (let n = walker.currentNode as Text | null; n; n = walker.nextNode() as Text | null) {\n    if (n.nodeType !== Node.TEXT_NODE || !range.intersectsNode(n)) continue;\n    const start = n === range.startContainer ? range.startOffset : 0;\n    const end = n === range.endContainer ? range.endOffset : n.data.length;\n    for (const m of n.data.slice(start, end).matchAll(/\\S+/g)) {\n      const r = document.createRange();\n      const from = start + (m.index ?? 0);\n      r.setStart(n, from);\n      r.setEnd(n, from + m[0].length);\n      const box = r.getClientRects()[0];\n      if (!box) continue;\n      words.push({\n        text: m[0],\n        x: box.left - frame.left,\n        y: box.top - frame.top,\n        w: box.width,\n        h: box.height,\n      });\n    }\n  }\n  return words;\n}\n\n// A link that scrolls to and highlights the passage in supporting browsers.\n// Long quotes use the start,end form so the URL stays short.\nfunction fragmentFor(words: string[]) {\n  const enc = (s: string) =>\n    encodeURIComponent(s).replace(/-/g, \"%2D\");\n  if (words.length <= 8) return `#:~:text=${enc(words.join(\" \"))}`;\n  return `#:~:text=${enc(words.slice(0, 4).join(\" \"))},${enc(words.slice(-4).join(\" \"))}`;\n}\n\nexport function QuoteShare({\n  author,\n  title,\n  url,\n  children,\n  className,\n}: {\n  author: string;\n  title: string;\n  // Page URL for Copy link; defaults to the current page.\n  url?: string;\n  // The article. Scrolls inside this frame; give the frame a height with\n  // className, or `h-auto` to let the article run the full page height.\n  children: React.ReactNode;\n  className?: string;\n}) {\n  const reduceMotion = useReducedMotion() ?? false;\n  const frame = useRef<HTMLDivElement>(null);\n  const scroller = useRef<HTMLDivElement>(null);\n  const pillEl = useRef<HTMLDivElement>(null);\n  const card = useRef<HTMLDivElement>(null);\n  const firstButton = useRef<HTMLButtonElement>(null);\n  const wordEls = useRef<(HTMLSpanElement | null)[]>([]);\n  const range = useRef<Range | null>(null);\n  const pointerDown = useRef(false);\n  const settle = useRef<ReturnType<typeof setTimeout>>(undefined);\n  const copyTimer = useRef<ReturnType<typeof setTimeout>>(undefined);\n\n  const [pill, setPill] = useState<{ tooLong: boolean } | null>(null);\n  const [quote, setQuote] = useState<Quote | null>(null);\n  const [closing, setClosing] = useState(false);\n  const [copied, setCopied] = useState<\"text\" | \"link\" | null>(null);\n\n  // Puts the pill over the first selected line, or under the last one when\n  // there is no room above. Written straight to the element: it runs on\n  // every scroll, which must not re-render.\n  const positionPill = useCallback(() => {\n    const el = pillEl.current;\n    const r = range.current;\n    const f = frame.current;\n    if (!el || !r || !f) return;\n    const box = f.getBoundingClientRect();\n    const rects = [...r.getClientRects()].filter((b) => b.width > 0);\n    if (!rects.length) return;\n    const first = rects[0];\n    const last = rects[rects.length - 1];\n    let y = first.top - box.top - PILL_GAP;\n    let below = false;\n    if (y - PILL_H < 8) {\n      y = last.bottom - box.top + PILL_GAP;\n      below = true;\n    }\n    const half = el.offsetWidth / 2;\n    const cx = (first.left + first.right) / 2 - box.left;\n    const x = Math.min(Math.max(cx, half + 8), box.width - half - 8);\n    el.style.transform = `translate(${x}px, ${y}px) translate(-50%, ${below ? \"0\" : \"-100%\"})`;\n    el.style.transformOrigin = below ? \"center top\" : \"center bottom\";\n    // Scrolled out of the frame: hide rather than float over nothing.\n    el.style.visibility = y < 0 || y > box.height ? \"hidden\" : \"\";\n  }, []);\n\n  const readSelection = useCallback(() => {\n    const sel = window.getSelection();\n    const article = scroller.current;\n    if (!sel || !sel.rangeCount || sel.isCollapsed || !article) {\n      range.current = null;\n      setPill(null);\n      return;\n    }\n    const r = sel.getRangeAt(0);\n    if (!article.contains(r.commonAncestorContainer) || !sel.toString().trim()) {\n      range.current = null;\n      setPill(null);\n      return;\n    }\n    range.current = snap(r);\n    const count = range.current.toString().trim().split(/\\s+/).length;\n    setPill({ tooLong: count > MAX_WORDS });\n  }, []);\n\n  useLayoutEffect(() => {\n    if (pill) positionPill();\n  }, [pill, positionPill]);\n\n  // Mouse selections show the pill on release; keyboard and touch-handle\n  // selections have no release, so they show once the selection sits still.\n  useEffect(() => {\n    const onChange = () => {\n      clearTimeout(settle.current);\n      if (pointerDown.current) return;\n      // Long enough to skip the intermediate states of a Shift+Arrow run.\n      settle.current = setTimeout(readSelection, 180);\n    };\n    const onUp = () => {\n      if (!pointerDown.current) return;\n      pointerDown.current = false;\n      clearTimeout(settle.current);\n      // The click that collapses a selection lands after pointerup.\n      settle.current = setTimeout(readSelection, 0);\n    };\n    document.addEventListener(\"selectionchange\", onChange);\n    document.addEventListener(\"pointerup\", onUp);\n    return () => {\n      document.removeEventListener(\"selectionchange\", onChange);\n      document.removeEventListener(\"pointerup\", onUp);\n      clearTimeout(settle.current);\n      clearTimeout(copyTimer.current);\n    };\n  }, [readSelection]);\n\n  const lift = () => {\n    const r = range.current;\n    const f = frame.current;\n    if (!r || !f || pill?.tooLong) return;\n    const box = f.getBoundingClientRect();\n    const words = collectWords(r, box);\n    if (!words.length) return;\n    const top = Math.min(...words.map((w) => w.y));\n    const bottom = Math.max(...words.map((w) => w.y + w.h));\n    window.getSelection()?.removeAllRanges();\n    setPill(null);\n    setClosing(false);\n    setCopied(null);\n    setQuote({ words, text: words.map((w) => w.text).join(\" \"), top, bottom });\n  };\n\n  // Lays the card out, then flies every word in from where it was read.\n  // Before paint, so no frame shows the words already in the card.\n  useLayoutEffect(() => {\n    if (!quote || closing) return;\n    const f = frame.current;\n    const c = card.current;\n    if (!f || !c) return;\n    const box = f.getBoundingClientRect();\n    // Beside the passage rather than over it, so the gaps the words leave\n    // stay in view: below it when there is room, else above, else as far\n    // from it as the frame allows.\n    const h = c.offsetHeight;\n    const room = 16;\n    const below = quote.bottom + room;\n    const above = quote.top - room - h;\n    const top =\n      below + h <= box.height - room\n        ? below\n        : above >= room\n          ? above\n          : quote.top > box.height / 2\n            ? room\n            : box.height - h - room;\n    c.style.top = `${top}px`;\n    firstButton.current?.focus({ preventScroll: true });\n    if (reduceMotion) return;\n    const anims: Animation[] = [];\n    quote.words.forEach((w, i) => {\n      const el = wordEls.current[i];\n      if (!el) return;\n      const t = el.getBoundingClientRect();\n      const dx = w.x - (t.left - box.left);\n      const dy = w.y - (t.top - box.top);\n      const s = w.h / t.height;\n      anims.push(\n        el.animate(\n          [{ transform: `translate(${dx}px, ${dy}px) scale(${s})` }, { transform: \"none\" }],\n          { ...FLIGHT, delay: Math.min(i * STAGGER, STAGGER_MAX), fill: \"backwards\" },\n        ),\n      );\n    });\n    return () => anims.forEach((a) => a.cancel());\n  }, [quote, closing, reduceMotion]);\n\n  const finish = useCallback(() => {\n    setQuote(null);\n    setClosing(false);\n    scroller.current?.focus({ preventScroll: true });\n  }, []);\n\n  // Sends every word back to its gap, then lets the paragraph have it.\n  useLayoutEffect(() => {\n    if (!quote || !closing) return;\n    const f = frame.current;\n    if (!f || reduceMotion) {\n      // Matches the card's own fade, so reduced motion still gets a close.\n      const t = setTimeout(finish, 150);\n      return () => clearTimeout(t);\n    }\n    const box = f.getBoundingClientRect();\n    const anims: Animation[] = [];\n    quote.words.forEach((w, i) => {\n      const el = wordEls.current[i];\n      if (!el) return;\n      el.getAnimations().forEach((a) => a.cancel());\n      const t = el.getBoundingClientRect();\n      anims.push(\n        el.animate(\n          [\n            { transform: \"none\" },\n            {\n              transform: `translate(${w.x - (t.left - box.left)}px, ${w.y - (t.top - box.top)}px) scale(${w.h / t.height})`,\n            },\n          ],\n          { ...RETURN, fill: \"forwards\" },\n        ),\n      );\n    });\n    let done = false;\n    Promise.all(anims.map((a) => a.finished))\n      .then(() => {\n        if (!done) finish();\n      })\n      .catch(() => {});\n    return () => {\n      done = true;\n    };\n  }, [quote, closing, reduceMotion, finish]);\n\n  const close = useCallback(() => {\n    if (quote && !closing) setClosing(true);\n  }, [quote, closing]);\n\n  useEffect(() => {\n    if (!quote) return;\n    const onKey = (e: KeyboardEvent) => {\n      if (e.key === \"Escape\") close();\n    };\n    document.addEventListener(\"keydown\", onKey);\n    return () => document.removeEventListener(\"keydown\", onKey);\n  }, [quote, close]);\n\n  const copy = async (kind: \"text\" | \"link\") => {\n    if (!quote) return;\n    const base = (url ?? window.location.href).split(\"#\")[0];\n    const value =\n      kind === \"text\"\n        ? `“${quote.text}” (${author}, ${title})`\n        : base + fragmentFor(quote.words.map((w) => w.text));\n    setCopied(kind);\n    clearTimeout(copyTimer.current);\n    // Long enough to read the confirmation, short enough to copy again.\n    copyTimer.current = setTimeout(() => setCopied(null), 1600);\n    try {\n      await navigator.clipboard.writeText(value);\n    } catch {\n      setCopied(null);\n    }\n  };\n\n  // Keeps Tab inside the open card.\n  const trap = (e: React.KeyboardEvent) => {\n    if (e.key !== \"Tab\" || !card.current) return;\n    const items = [...card.current.querySelectorAll<HTMLElement>(\"button\")];\n    const i = items.indexOf(document.activeElement as HTMLElement);\n    const next = e.shiftKey ? (i <= 0 ? items.length - 1 : i - 1) : (i + 1) % items.length;\n    e.preventDefault();\n    items[next]?.focus();\n  };\n\n  const open = quote !== null && !closing;\n\n  return (\n    <div\n      ref={frame}\n      className={cn(\n        \"relative h-[540px] w-[560px] max-w-full overflow-hidden rounded-2xl bg-background shadow-raised\",\n        className,\n      )}\n    >\n      <div\n        ref={scroller}\n        tabIndex={0}\n        aria-label={title}\n        role=\"region\"\n        onPointerDown={() => {\n          pointerDown.current = true;\n        }}\n        onScroll={positionPill}\n        // A stable gutter, so locking scroll while the card is up never\n        // shifts the text and leaves the gaps misaligned.\n        style={{ scrollbarGutter: \"stable\" }}\n        className={cn(\n          \"h-full px-7 py-7 outline-hidden selection:bg-foreground/15\",\n          \"focus-visible:outline-2 focus-visible:outline-solid focus-visible:-outline-offset-2 focus-visible:outline-foreground\",\n          quote ? \"overflow-y-hidden\" : \"overflow-y-auto\",\n          \"[scrollbar-width:none] [&::-webkit-scrollbar]:hidden\",\n        )}\n      >\n        {children}\n      </div>\n\n      {/* The gaps the words leave behind. */}\n      {quote && (\n        <div aria-hidden className=\"pointer-events-none absolute inset-0\">\n          {quote.words.map((w, i) => (\n            <span\n              key={i}\n              className=\"absolute rounded-[4px] bg-background\"\n              style={{ left: w.x - 1, top: w.y, width: w.w + 2, height: w.h }}\n            >\n              <span className=\"absolute inset-x-0.5 inset-y-[3px] rounded-[3px] bg-foreground/[0.06]\" />\n            </span>\n          ))}\n        </div>\n      )}\n\n      <AnimatePresence>\n        {pill && !quote && (\n          <motion.div\n            ref={pillEl}\n            key=\"pill\"\n            className=\"absolute top-0 left-0 z-20\"\n            initial={{ opacity: 0 }}\n            animate={{ opacity: 1, transition: { duration: 0.16, ease: EASE_OUT } }}\n            exit={{ opacity: 0, transition: { duration: 0.1, ease: EASE_OUT } }}\n          >\n            <motion.button\n              type=\"button\"\n              // Keeps the selection alive through the click.\n              onPointerDown={(e) => e.preventDefault()}\n              onClick={lift}\n              disabled={pill.tooLong}\n              initial={{ scale: reduceMotion ? 1 : 0.94, filter: \"blur(4px)\", y: reduceMotion ? 0 : 4 }}\n              animate={{ scale: 1, filter: \"blur(0px)\", y: 0, transition: { duration: 0.2, ease: EASE_OUT } }}\n              className={cn(\n                \"flex h-9 items-center gap-2 rounded-full bg-foreground px-3.5 text-sm font-medium whitespace-nowrap text-background shadow-raised outline-hidden\",\n                \"transition-[scale,opacity] duration-150 ease-out active:scale-[0.96] disabled:opacity-60 disabled:active:scale-100\",\n                \"focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-offset-2 focus-visible:outline-foreground\",\n              )}\n            >\n              <svg viewBox=\"0 0 16 16\" className=\"size-4\" fill=\"currentColor\" aria-hidden>\n                <path d=\"M3 8.5c0-2.4 1.2-4.2 3.3-5l.5 1c-1.2.6-1.9 1.5-2 2.6H6.5V12H3zm6.5 0c0-2.4 1.2-4.2 3.3-5l.5 1c-1.2.6-1.9 1.5-2 2.6H13V12H9.5z\" />\n              </svg>\n              {pill.tooLong ? \"Too long to quote\" : \"Share quote\"}\n            </motion.button>\n          </motion.div>\n        )}\n      </AnimatePresence>\n\n      {quote && (\n        <>\n          <motion.div\n            aria-hidden\n            onClick={close}\n            className=\"absolute inset-0 z-30 bg-background/70\"\n            initial={{ opacity: 0 }}\n            animate={{ opacity: open ? 1 : 0 }}\n            transition={{ duration: open ? 0.3 : 0.24, ease: EASE_OUT }}\n          />\n          <div\n            ref={card}\n            role=\"dialog\"\n            aria-modal=\"true\"\n            aria-label=\"Share quote\"\n            onKeyDown={trap}\n            className=\"absolute left-1/2 z-40 w-[min(440px,calc(100%-32px))] -translate-x-1/2 p-5\"\n          >\n            {/* The card's surface scales on its own layer, so the words on\n                top keep exact positions for their flight. */}\n            <motion.div\n              aria-hidden\n              className=\"absolute inset-0 rounded-2xl bg-muted shadow-raised\"\n              initial={{ opacity: 0, scale: reduceMotion ? 1 : 0.96 }}\n              animate={\n                open\n                  ? { opacity: 1, scale: 1, transition: { duration: 0.28, ease: EASE_OUT } }\n                  : { opacity: 0, scale: reduceMotion ? 1 : 0.98, transition: { duration: 0.2, ease: EASE_OUT } }\n              }\n            />\n            <div className=\"relative\">\n              <Reveal open={open} delay={0.22} reduce={reduceMotion}>\n                <svg aria-hidden viewBox=\"0 0 32 24\" className=\"h-4 w-[22px] fill-foreground/20\">\n                  <path d=\"M0 24V14.4C0 6.6 4.2 1.8 12.4 0l1.4 3.4C9.4 4.8 7.3 7.6 7 11.2h6.2V24H0Zm18.2 0V14.4C18.2 6.6 22.4 1.8 30.6 0L32 3.4c-4.4 1.4-6.5 4.2-6.8 7.8h6.2V24H18.2Z\" />\n                </svg>\n              </Reveal>\n              <motion.p\n                className=\"mt-3 text-[18px]/[1.5] font-medium tracking-[-0.01em] text-foreground\"\n                initial={reduceMotion ? { opacity: 0 } : false}\n                animate={{ opacity: open || !reduceMotion ? 1 : 0 }}\n                transition={{ duration: 0.15 }}\n              >\n                {quote.words.map((w, i) => (\n                  <span key={i}>\n                    <span\n                      ref={(el) => {\n                        wordEls.current[i] = el;\n                      }}\n                      className=\"inline-block origin-top-left will-change-transform\"\n                    >\n                      {w.text}\n                    </span>{\" \"}\n                  </span>\n                ))}\n              </motion.p>\n              {/* Credit and actions share a row, which keeps the card short\n                  enough to sit beside the passage instead of over it. */}\n              <Reveal open={open} delay={0.3} reduce={reduceMotion}>\n                <div className=\"mt-4 flex flex-wrap items-center gap-x-3 gap-y-3 border-t border-border pt-4\">\n                  <p className=\"flex min-w-[150px] flex-1 flex-col text-[13px]/[1.35]\">\n                    <span className=\"font-medium text-foreground\">{author}</span>\n                    <span className=\"text-pretty text-muted-foreground\">{title}</span>\n                  </p>\n                  <div className=\"flex gap-2\">\n                    <CardButton\n                      ref={firstButton}\n                      onClick={() => copy(\"text\")}\n                      done={copied === \"text\"}\n                      label=\"Copy text\"\n                    />\n                    <CardButton\n                      onClick={() => copy(\"link\")}\n                      done={copied === \"link\"}\n                      label=\"Copy link\"\n                    />\n                  </div>\n                </div>\n              </Reveal>\n              <span role=\"status\" className=\"sr-only\">\n                {copied === \"text\" ? \"Quote copied\" : copied === \"link\" ? \"Link copied\" : \"\"}\n              </span>\n            </div>\n          </div>\n        </>\n      )}\n    </div>\n  );\n}\n\nfunction Reveal({\n  open,\n  delay,\n  reduce,\n  children,\n}: {\n  open: boolean;\n  delay: number;\n  reduce: boolean;\n  children: React.ReactNode;\n}) {\n  return (\n    <motion.div\n      initial={{ opacity: 0, filter: \"blur(4px)\", y: reduce ? 0 : 4 }}\n      animate={\n        open\n          ? { opacity: 1, filter: \"blur(0px)\", y: 0, transition: { duration: 0.24, delay: reduce ? 0 : delay, ease: EASE_OUT } }\n          : { opacity: 0, filter: \"blur(2px)\", y: 0, transition: { duration: 0.14, ease: EASE_OUT } }\n      }\n    >\n      {children}\n    </motion.div>\n  );\n}\n\nfunction CardButton({\n  label,\n  done,\n  onClick,\n  ref,\n}: {\n  label: string;\n  done: boolean;\n  onClick: () => void;\n  ref?: React.Ref<HTMLButtonElement>;\n}) {\n  return (\n    <button\n      ref={ref}\n      type=\"button\"\n      onClick={onClick}\n      className={cn(\n        \"flex h-9 items-center gap-2 rounded-full bg-background px-3.5 text-sm font-medium text-foreground shadow-raised outline-hidden\",\n        \"transition-[scale] duration-150 ease-out active:scale-[0.96]\",\n        \"focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-offset-2 focus-visible:outline-foreground\",\n      )}\n    >\n      <span className=\"relative size-4\">\n        <AnimatePresence initial={false} mode=\"popLayout\">\n          <motion.svg\n            key={done ? \"done\" : \"idle\"}\n            viewBox=\"0 0 16 16\"\n            className=\"absolute inset-0 size-4\"\n            fill=\"none\"\n            stroke=\"currentColor\"\n            strokeWidth={1.5}\n            strokeLinecap=\"round\"\n            strokeLinejoin=\"round\"\n            aria-hidden\n            initial={{ opacity: 0, scale: 0.25, filter: \"blur(4px)\" }}\n            animate={{ opacity: 1, scale: 1, filter: \"blur(0px)\" }}\n            exit={{ opacity: 0, scale: 0.25, filter: \"blur(4px)\" }}\n            transition={{ type: \"spring\", duration: 0.3, bounce: 0 }}\n          >\n            {done ? (\n              <path d=\"M3.5 8.5 6.5 11.5 12.5 4.5\" />\n            ) : label === \"Copy link\" ? (\n              <path d=\"M6.75 9.25a2.75 2.75 0 0 0 3.9 0l2-2a2.75 2.75 0 0 0-3.9-3.9l-.6.6M9.25 6.75a2.75 2.75 0 0 0-3.9 0l-2 2a2.75 2.75 0 0 0 3.9 3.9l.6-.6\" />\n            ) : (\n              <>\n                <rect x=\"5.25\" y=\"5.25\" width=\"8\" height=\"8\" rx=\"1.75\" />\n                <path d=\"M10.75 5.25V4a1.25 1.25 0 0 0-1.25-1.25H4A1.25 1.25 0 0 0 2.75 4v5.5A1.25 1.25 0 0 0 4 10.75h1.25\" />\n              </>\n            )}\n          </motion.svg>\n        </AnimatePresence>\n      </span>\n      {done ? \"Copied\" : label}\n    </button>\n  );\n}\n\n// The passage other readers quoted most, marked the way reading apps mark a\n// popular highlight. One tap selects it, so the idea is a click away before\n// anyone thinks to drag across text.\nfunction TopHighlight({ children }: { children: React.ReactNode }) {\n  const select = (el: HTMLElement) => {\n    const sel = window.getSelection();\n    if (!sel || !sel.isCollapsed) return;\n    const r = document.createRange();\n    r.selectNodeContents(el);\n    sel.removeAllRanges();\n    sel.addRange(r);\n  };\n  return (\n    <span\n      role=\"button\"\n      tabIndex={0}\n      aria-label=\"Select the top highlight\"\n      onClick={(e) => select(e.currentTarget)}\n      onKeyDown={(e) => {\n        if (e.key !== \"Enter\" && e.key !== \" \") return;\n        e.preventDefault();\n        select(e.currentTarget);\n      }}\n      className=\"cursor-pointer rounded-[3px] underline decoration-foreground/30 decoration-dashed decoration-1 underline-offset-[5px] outline-hidden transition-[text-decoration-color] duration-150 ease-out hover:decoration-foreground/70 focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-offset-2 focus-visible:outline-foreground\"\n    >\n      {children}\n    </span>\n  );\n}\n\nexport default function QuoteShareDemo() {\n  return (\n    <QuoteShare author=\"Ines Hartmann\" title=\"The case for slower software\">\n      <article className=\"text-[15px]/[1.7] text-foreground/85\">\n        <p className=\"text-sm text-muted-foreground\">Essay, 6 min read</p>\n        <h2 className=\"mt-2 text-2xl font-semibold tracking-tight text-foreground\">\n          The case for slower software\n        </h2>\n        <p className=\"mt-5\">\n          Every product review I sit in eventually arrives at the same verdict:\n          make it faster. Faster to load, faster to finish, faster to forget.\n          Speed is the one metric nobody argues with.\n        </p>\n        <p className=\"mt-4\">\n          But the tools I keep coming back to are not the fastest ones. They\n          are the ones that give me a moment to notice what I am doing.{\" \"}\n          <TopHighlight>\n            A good interface does not rush you through a decision; it holds\n            the door open just long enough for you to walk through on purpose.\n          </TopHighlight>\n        </p>\n        <p className=\"mt-4\">\n          Try selecting any sentence in this essay, or tap the underlined\n          one above. The pill that appears is\n          the whole feature: no share sheet, no modal full of networks, just\n          the words you chose and two ways to pass them on.\n        </p>\n        <p className=\"mt-4\">\n          Slowness, used carefully, is a form of respect. It tells the person\n          on the other side that their attention is worth more than a\n          completion rate, and that the software will wait for them instead of\n          the other way around.\n        </p>\n        <p className=\"mt-4\">\n          None of this means adding delays. It means choosing where the pauses\n          go, the way a good editor chooses where the paragraphs break.\n        </p>\n      </article>\n    </QuoteShare>\n  );\n}\n"},{"path":"hooks/use-reduced-motion.ts","type":"registry:hook","target":"hooks/use-reduced-motion.ts","content":"\"use client\";\n\nimport { useSyncExternalStore } from \"react\";\n\n// Motion's useReducedMotion reads the media query on the very first client\n// render, but the server can't know it, so every component that renders\n// differently under reduced motion broke hydration for those users. This\n// reports false during hydration, matching the server HTML, then the real\n// preference straight after, and follows it if it changes.\nconst query = \"(prefers-reduced-motion: reduce)\";\n\nfunction subscribe(onChange: () => void) {\n  const media = window.matchMedia(query);\n  media.addEventListener(\"change\", onChange);\n  return () => media.removeEventListener(\"change\", onChange);\n}\n\nexport function useReducedMotion() {\n  return useSyncExternalStore(\n    subscribe,\n    () => window.matchMedia(query).matches,\n    () => false,\n  );\n}\n"}],"cssVars":{"light":{"shadow-raised":"0 0 0 1px oklch(0 0 0 / 0.06), 0 1px 2px oklch(0 0 0 / 0.06), 0 6px 16px -6px oklch(0 0 0 / 0.12)"},"dark":{"shadow-raised":"0 0 0 1px oklch(1 0 0 / 0.08), 0 1px 2px oklch(0 0 0 / 0.4), 0 6px 16px -6px oklch(0 0 0 / 0.6)"},"theme":{"shadow-raised":"var(--shadow-raised)"}},"categories":["text"],"docs":"From ui lab: https://lab.xevrion.dev/lab/quote-share"}