{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ink",
  "title": "Ink",
  "description": "What the ink components share: useInk(), which hands an svg to svg-scroll-draw on the scroll (finishing at mid-screen) or once in view; useSize(); and Hershey's script, a public-domain single-stroke handwriting font, laid out by script().",
  "dependencies": [
    "svg-scroll-draw@^2.29.0"
  ],
  "registryDependencies": [
    "https://scrollfx-ui.vercel.app/r/plotter.json"
  ],
  "files": [
    {
      "path": "lib/ink.ts",
      "content": "/**\n * ink — what the scrollfx ink components share: a hook that hands an <svg> to\n * svg-scroll-draw, either tied to the scroll (finishing as it reaches the\n * middle of the screen) or played once as it comes into view; a hook that\n * measures an element; and Hershey's script, a single-stroke handwriting\n * font, for ink-signature.\n *\n * Part of scrollfx (MIT): https://github.com/DhruvilChauahan0210/scrollfx\n * Needs: react, svg-scroll-draw, and lib/plotter (installed with it).\n */\n\nimport { useEffect, useState, type RefObject } from 'react';\nimport { scrollDraw } from 'svg-scroll-draw';\nimport { scrollWindow, staggerFor, type Point } from '@/lib/plotter';\n\n/**\n * When a drawing is made: `scroll` ties it to the scroll, the last stroke\n * landing as it reaches the middle of the screen; `view` plays it once, over\n * `duration` ms, when it comes into view. Reduced motion shows it drawn.\n */\nexport type InkTrigger = 'scroll' | 'view';\n\nexport interface InkOptions {\n  /** How many paths the svg holds; the drawing waits until there are some. */\n  paths: number;\n  /** The strokes start one after another over this many ranges (see scrollWindow): 0 all at once, 1 spread over the drawing, paths − 1 strictly in turn. */\n  spread?: number;\n  trigger?: InkTrigger;\n  /** With `view`, the whole drawing's length in ms. */\n  duration?: number;\n  /** Anything that changes when the strokes do, so the drawing starts again with them. */\n  version?: unknown;\n}\n\n/**\n * Hand the svg in `ref` to svg-scroll-draw. Give the svg\n * `data-scroll-draw-pending` (with svg-scroll-draw/no-flash.css imported) and\n * a `key` that changes with its strokes, so new strokes never show whole for\n * a frame before the engine sets them.\n */\nexport function useInk(ref: RefObject<SVGSVGElement | null>, { paths, spread = 0, trigger = 'scroll', duration = 1200, version }: InkOptions) {\n  useEffect(() => {\n    const svg = ref.current;\n    if (!svg || !paths) return;\n    const stagger = staggerFor(paths, spread);\n    const draw =\n      trigger === 'view'\n        ? scrollDraw(svg, { selector: 'path', autoplay: true, once: true, duration: duration / (1 + spread), stagger, easing: 'linear', native: false })\n        : scrollDraw(svg, { selector: 'path', stagger, easing: 'linear', trigger: scrollWindow(spread), progressVar: false });\n    return () => draw.destroy();\n  }, [ref, paths, spread, trigger, duration, version]);\n}\n\n/** An element's size in whole px, kept up to date; null until measured. */\nexport function useSize(ref: RefObject<HTMLElement | null>) {\n  const [size, setSize] = useState<{ w: number; h: number } | null>(null);\n  useEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    const measure = () => {\n      const w = Math.round(el.offsetWidth), h = Math.round(el.offsetHeight);\n      setSize((s) => (s && s.w === w && s.h === h ? s : { w, h }));\n    };\n    measure();\n    const ro = new ResizeObserver(measure);\n    ro.observe(el);\n    return () => ro.disconnect();\n  }, [ref]);\n  return size;\n}\n\n// ── Hershey's script ────────────────────────────────────────────────────────\n\n/*\n * Hershey's script simplex, ASCII 32–126, from the hershey-fonts package by\n * Kamal Mostafa (https://github.com/kamalmostafa/hershey-fonts, cursive.jhf).\n * The Hershey fonts are in the public domain, with these acknowledgements to\n * go with the data:\n *\n *   - The Hershey Fonts were originally created by Dr. A. V. Hershey while\n *     working at the U. S. National Bureau of Standards.\n *   - The format of the Font data in this distribution was originally created\n *     by James Hurt, Cognition, Inc., 900 Technology Park Drive, Billerica,\n *     MA 01821 (mit-eddie!ci-dandelion!hurt).\n *\n * Each string is one glyph: two characters for its left and right edges, then\n * the pen's points as pairs, each coordinate its char code minus 82 ('R'), x\n * right and y down, the baseline at y = 9. \" R\" lifts the pen.\n */\nconst SCRIPT: readonly string[] = [\n  \"JZ\", // space\n  \"MWRFRT RRYQZR[SZRY\", // !\n  \"JZNFNM RVFVM\", // \"\n  \"H]SBLb RYBRb RLOZO RKUYU\", // #\n  \"H\\\\PBP_ RTBT_ RYIWGTFPFMGKIKKLMMNOOUQWRXSYUYXWZT[P[MZKX\", // $\n  \"F^[FI[ RNFPHPJOLMMKMIKIIJGLFNFPGSHVHYG[F RWTUUTWTYV[X[ZZ[X[VYTWT\", // %\n  \"E_\\\\O\\\\N[MZMYNXPVUTXRZP[L[JZIYHWHUISJRQNRMSKSIRGPFNGMIMKNNPQUXWZY[[[\\\\Z\\\\Y\", // &\n  \"PTRMRQ\", // '\n  \"KYVBTDRGPKOPOTPYR]T`Vb\", // (\n  \"KYNBPDRGTKUPUTTYR]P`Nb\", // )\n  \"JZRLRX RMOWU RWOMU\", // *\n  \"E_RIR[ RIR[R\", // +\n  \"NVSWRXQWRVSWSYQ[\", // ,\n  \"E_IR[R\", // -\n  \"NVRVQWRXSWRV\", // .\n  \"G][BIb\", // /\n  \"H\\\\QFNGLJKOKRLWNZQ[S[VZXWYRYOXJVGSFQF\", // 0\n  \"H\\\\NJPISFS[\", // 1\n  \"H\\\\LKLJMHNGPFTFVGWHXJXLWNUQK[Y[\", // 2\n  \"H\\\\MFXFRNUNWOXPYSYUXXVZS[P[MZLYKW\", // 3\n  \"H\\\\UFKTZT RUFU[\", // 4\n  \"H\\\\WFMFLOMNPMSMVNXPYSYUXXVZS[P[MZLYKW\", // 5\n  \"H\\\\XIWGTFRFOGMJLOLTMXOZR[S[VZXXYUYTXQVOSNRNOOMQLT\", // 6\n  \"H\\\\YFO[ RKFYF\", // 7\n  \"H\\\\PFMGLILKMMONSOVPXRYTYWXYWZT[P[MZLYKWKTLRNPQOUNWMXKXIWGTFPF\", // 8\n  \"H\\\\XMWPURRSQSNRLPKMKLLINGQFRFUGWIXMXRWWUZR[P[MZLX\", // 9\n  \"NVROQPRQSPRO RRVQWRXSWRV\", // :\n  \"NVROQPRQSPRO RSWRXQWRVSWSYQ[\", // ;\n  \"F^ZIJRZ[\", // <\n  \"E_IO[O RIU[U\", // =\n  \"F^JIZRJ[\", // >\n  \"I[LKLJMHNGPFTFVGW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q[TYZV\", // Z\n  \"KYPBPb ROBVB RObVb\", // [\n  \"KYKFY^\", // \\\n  \"KYUBUb RNBUB RNbUb\", // ]\n  \"JZRDJR RRDZR\", // ^\n  \"G[Gb[b\", // _\n  \"NVSKQMQORPSORNQO\", // `\n  \"L\\\\UUTSRRPRNSMTLVLXMZO[Q[SZTXVRUWUZV[W[YZZY\\\\V\", // a\n  \"M[MVOSRNSLTITGSFQGPIOMNTNZO[P[RZTXUUURVVWWYW[V\", // b\n  \"MXTTTSSRQROSNTMVMXNZP[S[VYXV\", // c\n  \"L\\\\UUTSRRPRNSMTLVLXMZO[Q[SZTXZF RVRUWUZV[W[YZZY\\\\V\", // d\n  \"NXOYQXRWSUSSRRQROSNUNXOZQ[S[UZVYXV\", // e\n  \"OWOVSQUNVLWIWGVFTGSIQQNZKaJdJfKgMfNcOZP[R[TZUYWV\", // f\n  \"L[UUTSRRPRNSMTLVLXMZO[Q[SZTY RVRTYPdOfMgLfLdMaP^S\\\\U[XY[V\", // g\n  \"M\\\\MVOSRNSLTITGSFQGPIOMNSM[ RM[NXOVQSSRURVSVUUXUZV[W[YZZY\\\\V\", // h\n  \"PWSMSNTNTMSM RPVRRPXPZQ[R[TZUYWV\", // i\n  \"PWSMSNTNTMSM RPVRRLdKfIgHfHdIaL^O\\\\Q[TYWV\", // j\n  \"M[MVOSRNSLTITGSFQGPIOMNSM[ RM[NXOVQSSRURVSVUTVQV RQVSWTZU[V[XZYY[V\", // k\n  \"OWOVQSTNULVIVGUFSGRIQMPTPZQ[R[TZUYWV\", // l\n  \"E^EVGSIRJSJTIXH[ RIXJVLSNRPRQSQTPXO[ RPXQVSSURWRXSXUWXWZX[Y[[Z\\\\Y^V\", // m\n  \"J\\\\JVLSNROSOTNXM[ RNXOVQSSRURVSVUUXUZV[W[YZZY\\\\V\", // n\n  \"LZRRPRNSMTLVLXMZO[Q[SZTYUWUUTSRRQSQURWTXWXYWZV\", // o\n  \"KZKVMSNQMUGg RMUNSPRRRTSUUUWTYSZQ[ RMZO[R[UZWYZV\", // p\n  \"L[UUTSRRPRNSMTLVLXMZO[Q[SZ RVRUUSZPaOdOfPgRfScS\\\\U[XY[V\", // q\n  \"MZMVOSPQPSSSTTTVSYSZT[U[WZXYZV\", // r\n  \"NYNVPSQQQSSVTXTZR[ RNZP[T[VZWYYV\", // s\n  \"OXOVQSSO RVFPXPZQ[S[UZVYXV RPNWN\", // t\n  \"L[LVNRLXLZM[O[QZSXUU RVRTXTZU[V[XZYY[V\", // u\n  \"L[LVNRMWMZN[O[RZTXUUUR RURVVWWYW[V\", // v\n  \"I^LRJTIWIYJ[L[NZPX RRRPXPZQ[S[UZWXXUXR RXRYVZW\\\\W^V\", // w\n  \"JZJVLSNRPRQSQZR[U[XYZV RWSVRTRSSOZN[L[KZ\", // x\n  \"L[LVNRLXLZM[O[QZSXUU RVRPdOfMgLfLdMaP^S\\\\U[XY[V\", // y\n  \"LZLVNSPRRRTTTVSXQZN[P\\\\Q^QaPdOfMgLfLdMaP^S\\\\WYZV\", // z\n  \"KYRCQEQGRISJTLTNSPORSTTVTXSZR[Q]Q_Ra\", // {\n  \"NVRBRb\", // |\n  \"KYRCSESGRIQJPLPNQPURQTPVPXQZR[S]S_Ra\", // }\n  \"F^ISJQLPNPPQTTVUXUZT[Q[O\", // ~\n];\n\n/** Hershey's em is 32 units. */\nconst EM = 32;\nconst BASELINE = 9;\n\n/** Curves where a glyph turns gently, as a pen does: each such corner becomes a quadratic between its neighbours' midpoints. */\nfunction rounded(pts: Point[]): Point[] {\n  if (pts.length < 3) return pts;\n  const out: Point[] = [pts[0]];\n  const mid = (i: number): Point => [(pts[i][0] + pts[i + 1][0]) / 2, (pts[i][1] + pts[i + 1][1]) / 2];\n  for (let i = 1; i < pts.length - 1; i++) {\n    const ax = pts[i][0] - pts[i - 1][0], ay = pts[i][1] - pts[i - 1][1];\n    const bx = pts[i + 1][0] - pts[i][0], by = pts[i + 1][1] - pts[i][1];\n    const n = Math.hypot(ax, ay) * Math.hypot(bx, by);\n    if (n > 0 && (ax * bx + ay * by) / n > Math.cos((70 * Math.PI) / 180)) {\n      const p0 = mid(i - 1), p2 = mid(i);\n      for (let k = 0; k <= 6; k++) {\n        const t = k / 6;\n        out.push([(1 - t) ** 2 * p0[0] + 2 * (1 - t) * t * pts[i][0] + t * t * p2[0], (1 - t) ** 2 * p0[1] + 2 * (1 - t) * t * pts[i][1] + t * t * p2[1]]);\n      }\n    } else out.push(pts[i]);\n  }\n  out.push(pts[pts.length - 1]);\n  return out;\n}\n\n/**\n * `text` written in Hershey's script at `size` px to the em, leaning `slant`\n * (x moved right per unit up): the pen's lines in writing order, letter by\n * letter, moved so the ink's box starts at `pad`, with that box's size (pad\n * included) and the baseline's y. Characters outside ASCII are left out\n * (accents are dropped first). Pure, so it lays out the same on the server.\n */\nexport function script(text: string, { size = 56, slant = 0.18, pad = 4 } = {}) {\n  const k = size / EM;\n  const raw: Point[][] = [];\n  let x = 0;\n  for (const ch of text.normalize('NFD').replace(/[̀-ͯ]/g, '')) {\n    const code = ch.charCodeAt(0);\n    if (code < 32 || code > 126) continue;\n    const g = SCRIPT[code - 32];\n    const v = (i: number) => g.charCodeAt(i) - 82;\n    const ox = x - v(0);\n    for (const s of g.slice(2).split(' R').filter(Boolean)) {\n      const pts: Point[] = [];\n      for (let i = 0; i + 1 < s.length; i += 2) {\n        const gx = s.charCodeAt(i) - 82, gy = s.charCodeAt(i + 1) - 82;\n        pts.push([(ox + gx + (BASELINE - gy) * slant) * k, gy * k]);\n      }\n      raw.push(rounded(pts));\n    }\n    x += v(1) - v(0);\n  }\n  let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;\n  for (const l of raw) for (const [px, py] of l) { x0 = Math.min(x0, px); y0 = Math.min(y0, py); x1 = Math.max(x1, px); y1 = Math.max(y1, py); }\n  if (!raw.length) return { lines: [] as Point[][], w: 0, h: 0, baseline: 0 };\n  const lines = raw.map((l) => l.map(([px, py]): Point => [px - x0 + pad, py - y0 + pad]));\n  return { lines, w: Math.ceil(x1 - x0 + pad * 2), h: Math.ceil(y1 - y0 + pad * 2), baseline: BASELINE * k - y0 + pad };\n}\n",
      "type": "registry:lib"
    }
  ],
  "type": "registry:lib"
}