{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "marker",
  "type": "registry:ui",
  "title": "Marker",
  "description": "A highlighter stroke across the one phrase in a paragraph a reader should not miss. The first time the phrase scrolls into view, the stroke sweeps across it from the start of the line to the end, the way a pen would, and wraps across lines with the text.…",
  "author": "ofri-peretz <https://github.com/ofri-peretz>",
  "categories": [
    "decorative",
    "effect"
  ],
  "dependencies": [],
  "registryDependencies": [
    "https://ds.interlace.tools/r/interlace-base.json",
    "https://ds.interlace.tools/r/cn.json",
    "https://ds.interlace.tools/r/motion-token.json",
    "https://ds.interlace.tools/r/use-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/interlace-ui/effects/marker.tsx",
      "target": "components/ui/effects/marker.tsx",
      "type": "registry:ui",
      "content": "'use client';\n\nimport * as React from 'react';\n\n// @interlace/marker v1.0.1 — Interlace design system.\n// Docs, props and live preview: https://ds.interlace.tools/c/marker\n// What changed since: https://ds.interlace.tools/c/marker#history\n// Generated banner — keep it, the upgrade diff reads this version.\n\n/**\n * @interlace/ui — Marker\n *\n * A highlighter stroke across the one phrase in a paragraph a reader should\n * not miss. The first time the phrase scrolls into view, the stroke sweeps\n * across it from the start of the line to the end, the way a pen would, and\n * wraps across lines with the text. It is emphasis, so use it once or twice\n * on a page, not on every sentence.\n *\n * ## Content first\n *\n * It is a `<mark>`, so the emphasis is in the HTML for a screen reader and a\n * crawler, and the finished stroke is in the server HTML. The text itself\n * never moves, fades or changes colour; only the stroke behind it is drawn.\n * In forced-colours mode, where backgrounds are dropped, the phrase is\n * underlined instead.\n *\n * ## Motion\n *\n * One Web Animations API animation of `background-size`, from nothing to the\n * full phrase, starting at the inline-start edge, so it sweeps right to left\n * in a right-to-left paragraph. Under `prefers-reduced-motion: reduce`,\n * without IntersectionObserver, or without `element.animate`, the stroke is\n * simply there.\n *\n * ## Tokens\n *\n * `tone` picks the colour (`--highlight` or `--primary`), mixed toward\n * transparent so body text keeps its own colour and contrast on top of it.\n * `--marker-color` and `--marker-size` can be retuned by a theme.\n *\n * ## Composition\n *\n *   Marker                              (mark — data-slot=\"marker\", data-variant, data-tone)\n *\n * | Rule | Concept                 | Where in this file                                   |\n * | ---- | ----------------------- | ---------------------------------------------------- |\n * | R4   | Extends native el       | `mark` props                                         |\n * | R6   | data-slot per part      | marker                                               |\n * | R7   | cn + ...rest            | `cn(…, className)` + `{...props}`                    |\n * | R8   | Enums, not booleans     | `variant`, `tone`                                    |\n * | R19  | Tokens only             | `--highlight`, `--primary`                           |\n * | R25  | Client component        | the sweep runs in the browser                        |\n * | R26  | A11y from native el     | `<mark>` semantics                                   |\n */\n\nimport { cn } from '@/lib/utils';\nimport { useReducedMotion } from '@/hooks/use-reduced-motion';\nimport { motionEase } from '@/lib/motion-token';\n\nconst VARIANTS = {\n  /** A highlighter across the lower half of the letters. */\n  band: '[--marker-size:0.62em] bg-[position:0_82%] rtl:bg-[position:100%_82%]',\n  /** A highlighter across the whole line. */\n  full: '[--marker-size:100%] bg-[position:0_50%] rtl:bg-[position:100%_50%]',\n  /** A thick pen line under the letters. */\n  underline: '[--marker-size:0.14em] bg-[position:0_100%] rtl:bg-[position:100%_100%]',\n} as const;\n\nconst TONES = {\n  highlight:\n    '[--marker-color:color-mix(in_oklch,var(--highlight)_60%,transparent)] dark:[--marker-color:color-mix(in_oklch,var(--highlight)_40%,transparent)]',\n  primary:\n    '[--marker-color:color-mix(in_oklch,var(--primary)_22%,transparent)] dark:[--marker-color:color-mix(in_oklch,var(--primary)_30%,transparent)]',\n} as const;\n\n/** The underline is a line, not a wash, so it takes the tone at full strength. */\nconst UNDERLINE_TONES = {\n  highlight: '[--marker-color:var(--highlight)]',\n  primary: '[--marker-color:var(--primary)]',\n} as const;\n\nexport type MarkerVariant = keyof typeof VARIANTS;\nexport type MarkerTone = keyof typeof TONES;\n\nexport interface MarkerProps extends React.ComponentPropsWithoutRef<'mark'> {\n  /** The shape of the stroke: `band` across the lower half, `full` across the line, `underline` under it. @default 'band' */\n  variant?: MarkerVariant;\n  /** The colour of the stroke. @default 'highlight' */\n  tone?: MarkerTone;\n  /** Milliseconds the sweep takes. @default 700 */\n  duration?: number;\n  /** Milliseconds to wait after the phrase enters the viewport. @default 150 */\n  delay?: number;\n}\n\nexport function Marker({\n  variant = 'band',\n  tone = 'highlight',\n  duration = 700,\n  delay = 150,\n  className,\n  children,\n  ...props\n}: MarkerProps) {\n  const reduced = useReducedMotion();\n  const ref = React.useRef<HTMLElement>(null);\n\n  // Before paint: take the stroke away, so it can be drawn instead of flashing.\n  React.useLayoutEffect(() => {\n    const el = ref.current;\n    if (!el || reduced || typeof el.animate !== 'function') return;\n    if (typeof IntersectionObserver === 'undefined') return;\n    if (el.dataset.marked) return;\n\n    // The resolved height of the stroke, e.g. \"100% 8px\" → \"8px\".\n    // Only the first layer: a consumer's own background adds a comma-separated second one.\n    const height = getComputedStyle(el).backgroundSize.split(',')[0]!.trim().split(/\\s+/)[1] ?? '100%';\n    const from = `0% ${height}`;\n    const to = `100% ${height}`;\n    el.style.backgroundSize = from;\n\n    const io = new IntersectionObserver(\n      (entries) => {\n        if (!entries.some((e) => e.isIntersecting)) return;\n        io.disconnect();\n        el.dataset.marked = 'true';\n        el.style.backgroundSize = '';\n        el.animate([{ backgroundSize: from }, { backgroundSize: to }], {\n          duration,\n          delay,\n          easing: motionEase(el, 'move'),\n          fill: 'backwards',\n        });\n      },\n      { threshold: 0.75 },\n    );\n    io.observe(el);\n\n    return () => {\n      io.disconnect();\n      el.style.backgroundSize = '';\n      for (const a of el.getAnimations?.() ?? []) a.cancel();\n    };\n  }, [reduced, duration, delay, variant]);\n\n  return (\n    <mark\n      ref={ref}\n      data-slot=\"marker\"\n      data-variant={variant}\n      data-tone={tone}\n      className={cn(\n        'text-inherit bg-transparent bg-no-repeat [background-image:linear-gradient(var(--marker-color),var(--marker-color))] bg-[length:100%_var(--marker-size)] px-[0.1em] [box-decoration-break:slice] forced-colors:underline',\n        VARIANTS[variant],\n        variant === 'underline' ? UNDERLINE_TONES[tone] : TONES[tone],\n        className,\n      )}\n      {...props}\n    >\n      {children}\n    </mark>\n  );\n}\n"
    }
  ],
  "meta": {
    "tier": "effect",
    "client": true,
    "minViewport": null,
    "loading": false,
    "version": "1.0.1",
    "since": "2.0.0"
  },
  "docs": "## @interlace/marker\n\nInstalled to `components/ui/effects/marker.tsx`.\n\n```tsx\nimport { /* … */ } from '@/components/ui/effects/marker';\n```\n\nProps, a11y contract, live preview and source: https://ds.interlace.tools/c/marker\n\nRequires the `@interlace/interlace-base` CSS baseline (installed automatically as a registry dependency). For the Interlace look, also add `@interlace/theme`."
}
