{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"action-icons","title":"Action Icons","description":"The animated copy icon, selection check and reveal eye that CopyButton, Code and Resource List draw. Install copy-button to copy a value.","dependencies":["@phosphor-icons/react@2.1.10"],"registryDependencies":["@siteplane/base"],"files":[{"path":"packages/ui/src/components/action-icons/action-icons.tsx","content":"\"use client\";\n\nimport { EyeIcon, EyeSlashIcon } from \"@phosphor-icons/react/dist/ssr\";\nimport { useEffect, useRef, useState } from \"react\";\n\nimport { useSiteplaneMessages } from \"../../system/locale/messages-context\";\nimport { cn } from \"../../system/utils/cn\";\n\nimport \"./action-icons.css\";\n\nexport type CopyIconPhase = \"idle\" | \"check\" | \"check-out\" | \"redraw\";\n\n/** How long the check stays on the icon before it fades, in milliseconds. */\nconst copyCheckHold = 2000;\n\n/**\n * A motion token in milliseconds, read where the kit's tokens are set, so the\n * phases below keep in step with the copy feedback in motion.css. The value\n * the kit ships stands in where there is no document.\n */\nfunction motionTokenMs(name: `--motion-${string}`, fallback: number): number {\n  if (typeof document === \"undefined\" || typeof getComputedStyle !== \"function\")\n    return fallback;\n  const value = getComputedStyle(document.documentElement)\n    .getPropertyValue(name)\n    .trim();\n  const parsed = Number.parseFloat(value);\n  if (!Number.isFinite(parsed)) return fallback;\n  return value.endsWith(\"ms\") ? parsed : parsed * 1000;\n}\n\nlet copyStatus: HTMLElement | null = null;\n\n/**\n * The polite live region that announces a copy (rulebook T7). A copy button\n * keeps its place and its focus, and not every screen reader reads a new name\n * on the focused element, so the confirmation is said here, once for the\n * page. It sits on the body, which a modal dialog leaves readable: Base UI\n * keeps aria-live regions out of what it hides.\n */\nfunction copyStatusRegion(): HTMLElement | null {\n  if (typeof document === \"undefined\") return null;\n  if (copyStatus?.isConnected) return copyStatus;\n  const region = document.createElement(\"div\");\n  region.setAttribute(\"aria-atomic\", \"true\");\n  region.setAttribute(\"aria-live\", \"polite\");\n  region.setAttribute(\"role\", \"status\");\n  region.setAttribute(\"data-slot\", \"copy-status\");\n  region.className = \"sp-copy-status sr-only\";\n  document.body.append(region);\n  copyStatus = region;\n  return region;\n}\n\n/**\n * Says `text` in the shared copy live region and takes it back after `hold`\n * milliseconds, unless something else was said since. The region is emptied\n * first and takes the text a micro beat later, so the same words are\n * announced again. Returns a function that stops what is still to come.\n */\nexport function announceCopyStatus(text: string, hold: number): () => void {\n  const region = copyStatusRegion();\n  if (!region) return () => {};\n  region.textContent = \"\";\n  const timers = [\n    setTimeout(\n      () => {\n        region.textContent = text;\n      },\n      motionTokenMs(\"--motion-duration-micro\", 100),\n    ),\n    setTimeout(() => {\n      if (region.textContent === text) region.textContent = \"\";\n    }, hold),\n  ];\n  return () => {\n    for (const timer of timers) clearTimeout(timer);\n  };\n}\n\nexport type CopyIconPhaseOptions = {\n  /**\n   * Whether a copy is announced in the shared live region. Turn it off where\n   * the caller says it itself, such as a status line of its own, so a copy is\n   * announced once.\n   */\n  announce?: boolean;\n  /**\n   * What the shared region says after a copy: CopyButton's `copied` message\n   * by default, \"Copied\" in English.\n   */\n  announcement?: string | undefined;\n};\n\nexport function useCopyIconPhase({\n  announce = true,\n  announcement: announcementProp,\n}: CopyIconPhaseOptions = {}) {\n  const messages = useSiteplaneMessages(\"copyButton\");\n  const announcement = announcementProp ?? messages.copied;\n  const [copyPhase, setCopyPhase] = useState<CopyIconPhase>(\"idle\");\n  const timersRef = useRef<ReturnType<typeof setTimeout>[]>([]);\n  const stopAnnouncementRef = useRef<(() => void) | undefined>(undefined);\n  useEffect(() => {\n    // The region exists before the first copy, so that copy is announced.\n    if (announce) copyStatusRegion();\n    return () => {\n      for (const timer of timersRef.current) clearTimeout(timer);\n      stopAnnouncementRef.current?.();\n    };\n  }, [announce]);\n  function playCopyFeedback() {\n    for (const timer of timersRef.current) clearTimeout(timer);\n    stopAnnouncementRef.current?.();\n    setCopyPhase(\"check\");\n    // The check stays for two seconds, long enough to read a \"copied\" label\n    // beside it; then it fades and, a micro beat later, the copy icon draws\n    // itself again: the first stroke, then the second from 80% of the first.\n    const checkOut = motionTokenMs(\"--motion-duration-fast\", 150);\n    const beat = motionTokenMs(\"--motion-duration-micro\", 100);\n    const draw = motionTokenMs(\"--motion-duration-slow\", 320);\n    const redraw = copyCheckHold + checkOut + beat;\n    // The region says the copy for as long as the check shows.\n    stopAnnouncementRef.current = announce\n      ? announceCopyStatus(announcement, copyCheckHold)\n      : undefined;\n    timersRef.current = [\n      setTimeout(() => setCopyPhase(\"check-out\"), copyCheckHold),\n      setTimeout(() => setCopyPhase(\"redraw\"), redraw),\n      setTimeout(() => setCopyPhase(\"idle\"), redraw + draw * 1.8),\n    ];\n  }\n  return {\n    copyPhase,\n    isShowingCheck: copyPhase === \"check\" || copyPhase === \"check-out\",\n    playCopyFeedback,\n  };\n}\n\n/**\n * The copy icon that turns into a check and draws itself again. Both glyphs\n * are the kit's icon set, Phosphor in the Regular weight, drawn as the centre\n * lines of Phosphor's copy and check with their 16-unit stroke in the 256-unit\n * box, so that they can draw themselves. The check runs from the tip of its\n * long arm to the tip of its short arm, because its draw-in dashes it from the\n * end (action-icons.css) and the short arm comes first. In a Button it is the\n * glyph of the Button's size, as every glyph is, and 16 px elsewhere\n * (action-icons.css).\n */\nexport function CopyRedrawIcon({\n  className,\n  phase,\n}: {\n  className?: string;\n  phase: CopyIconPhase;\n}) {\n  return (\n    <span\n      className={cn(\"sp-copy relative inline-flex\", className)}\n      data-phase={phase}\n    >\n      <svg\n        aria-hidden=\"true\"\n        className=\"sp-copy-check absolute inset-0 mx-0 size-full\"\n        fill=\"none\"\n        stroke=\"currentColor\"\n        strokeLinecap=\"round\"\n        strokeLinejoin=\"round\"\n        strokeWidth=\"16\"\n        viewBox=\"0 0 256 256\"\n      >\n        <path d=\"M224 72 96 200 40 144\" pathLength={1} />\n      </svg>\n      <svg\n        aria-hidden=\"true\"\n        className=\"sp-copy-draw absolute inset-0 mx-0 size-full\"\n        fill=\"none\"\n        stroke=\"currentColor\"\n        strokeLinecap=\"round\"\n        strokeLinejoin=\"round\"\n        strokeWidth=\"16\"\n        viewBox=\"0 0 256 256\"\n      >\n        <path d=\"M88 80V40h128v128h-40\" data-draw=\"1\" pathLength={1} />\n        <rect\n          data-draw=\"2\"\n          height=\"128\"\n          pathLength={1}\n          width=\"128\"\n          x=\"40\"\n          y=\"88\"\n        />\n      </svg>\n    </span>\n  );\n}\n\n/**\n * Passive selection mark. The element around it owns the state: it carries\n * `data-selected` while the row is selected, and the shared check motion in\n * motion.css draws the check in and pops the glyph (rulebook M1). The icon\n * stays mounted so the check can draw back out. It is the kit's check, the\n * centre line of Phosphor's check with the Regular 16-unit stroke.\n */\nexport function SelectionCheckIcon({ className }: { className?: string }) {\n  return (\n    <svg\n      aria-hidden=\"true\"\n      className={cn(\"sp-check-glyph-motion mx-0 size-4 shrink-0\", className)}\n      fill=\"none\"\n      stroke=\"currentColor\"\n      strokeLinecap=\"round\"\n      strokeLinejoin=\"round\"\n      strokeWidth=\"16\"\n      viewBox=\"0 0 256 256\"\n    >\n      {/* pathLength 24 is the dash length of the shared draw-in. */}\n      <path\n        className=\"sp-check-path-motion\"\n        d=\"M40 144 96 200 224 72\"\n        pathLength={24}\n      />\n    </svg>\n  );\n}\n\nexport function RevealIcon({\n  className,\n  revealed,\n}: {\n  className?: string;\n  revealed: boolean;\n}) {\n  return revealed ? (\n    <EyeSlashIcon\n      aria-hidden=\"true\"\n      className={cn(\"sp-icon-pop size-4\", className)}\n    />\n  ) : (\n    <EyeIcon\n      aria-hidden=\"true\"\n      className={cn(\"sp-icon-pop size-4\", className)}\n    />\n  );\n}\n","type":"registry:ui","target":"~/src/siteplane/components/action-icons/action-icons.tsx"},{"path":"packages/ui/src/components/action-icons/action-icons.css","content":"@layer theme, base, components, siteplane, utilities;\n\n@layer siteplane {\n  /* The copy feedback of CopyRedrawIcon (rulebook T7) on the motion tokens;\n   * useCopyIconPhase times its phases from the same tokens. The check draws\n   * in over two micro steps, holds, fades over the fast step, then the copy\n   * icon draws itself again over the slow step, the kit's time for a draw.\n   * Its glyphs sit in a Button, whose shared icon opacity (design-rework.css)\n   * is a zero-specificity rule of this layer, so the phases below refine it\n   * without raising their importance; at rest the copy glyph keeps the\n   * Button's opacity. */\n  /* The copy icon is the glyph of the Button it sits in, the glyph ladder's\n   * --sp-rw-button-icon (design-rework.css), and 16 px outside a Button; its\n   * two glyphs fill it. */\n  :where(.sp-copy) {\n    width: var(--sp-rw-button-icon, var(--sp-rw-control-icon));\n    height: var(--sp-rw-button-icon, var(--sp-rw-control-icon));\n  }\n\n  .sp-copy-check {\n    opacity: 0;\n    transition: opacity var(--motion-duration-fast) var(--motion-ease-linear);\n  }\n\n  /* The check is the success green, the colour of a copy that went through:\n   * the tone of the success dot, as every status glyph (rulebook C4). On a\n   * Button whose fill takes a colour of its own (accent, destructive and\n   * inverse, and the glass film) the green would sink into it, so the check\n   * takes the Button's text colour there, as the copy glyph does. */\n  :where(.sp-copy-check) {\n    color: var(--sp-semantic-color-success);\n  }\n\n  [data-chassis]:is(\n      [data-variant=\"accent\"],\n      [data-variant=\"destructive\"],\n      [data-variant=\"inverse\"],\n      [data-variant=\"glass\"]\n    )\n    .sp-copy-check {\n    color: inherit;\n  }\n\n  .sp-copy-check path {\n    stroke-dasharray: 1 2;\n    stroke-dashoffset: 0;\n  }\n\n  .sp-copy[data-phase=\"check\"] .sp-copy-check {\n    opacity: 1;\n    transition: none;\n  }\n\n  .sp-copy[data-phase=\"check\"] .sp-copy-check path {\n    animation: sp-check-draw calc(var(--motion-duration-micro) * 2)\n      var(--motion-ease-linear) both;\n  }\n\n  @keyframes sp-check-draw {\n    from {\n      stroke-dashoffset: -1.1;\n    }\n\n    to {\n      stroke-dashoffset: 0;\n    }\n  }\n\n  .sp-copy-draw [data-draw] {\n    stroke-dasharray: 1 2;\n    stroke-dashoffset: 0;\n  }\n\n  .sp-copy[data-phase=\"check\"] .sp-copy-draw,\n  .sp-copy[data-phase=\"check-out\"] .sp-copy-draw {\n    opacity: 0;\n  }\n\n  .sp-copy[data-phase=\"check\"] .sp-copy-draw [data-draw],\n  .sp-copy[data-phase=\"check-out\"] .sp-copy-draw [data-draw] {\n    stroke-dashoffset: 1.1;\n  }\n\n  .sp-copy[data-phase=\"redraw\"] .sp-copy-check {\n    opacity: 0;\n    transition: none;\n  }\n\n  .sp-copy[data-phase=\"redraw\"] .sp-copy-draw [data-draw] {\n    animation: sp-stroke-draw var(--motion-duration-slow)\n      var(--motion-ease-linear) both;\n  }\n\n  .sp-copy[data-phase=\"redraw\"] .sp-copy-draw [data-draw=\"2\"] {\n    animation-delay: calc(var(--motion-duration-slow) * 0.8);\n  }\n\n  @keyframes sp-stroke-draw {\n    from {\n      stroke-dashoffset: 1.1;\n    }\n\n    to {\n      stroke-dashoffset: 0;\n    }\n  }\n\n  /* Reduced motion (M5): the check shows and the copy icon draws at once,\n   * and the check stays whole until the icon returns. The document mode, the\n   * provider preset and the system setting each switch it; every selector\n   * names the phase, so it ranks above the phase rules it stops. */\n  html[data-motion-reduce=\"true\"]\n    .sp-copy[data-phase]\n    :is(.sp-copy-check, .sp-copy-check path, .sp-copy-draw [data-draw]),\n  [data-sp-motion=\"reduced\"]\n    .sp-copy[data-phase]\n    :is(.sp-copy-check, .sp-copy-check path, .sp-copy-draw [data-draw]) {\n    transition-duration: 1ms;\n    animation-duration: 1ms;\n    animation-delay: 0ms;\n  }\n\n  html[data-motion-reduce=\"true\"]\n    .sp-copy[data-phase=\"check-out\"]\n    .sp-copy-check,\n  [data-sp-motion=\"reduced\"] .sp-copy[data-phase=\"check-out\"] .sp-copy-check {\n    opacity: 1;\n    transition: none;\n  }\n\n  @media (prefers-reduced-motion: reduce) {\n    :root\n      .sp-copy[data-phase]\n      :is(.sp-copy-check, .sp-copy-check path, .sp-copy-draw [data-draw]) {\n      transition-duration: 1ms;\n      animation-duration: 1ms;\n      animation-delay: 0ms;\n    }\n\n    :root .sp-copy[data-phase=\"check-out\"] .sp-copy-check {\n      opacity: 1;\n      transition: none;\n    }\n  }\n}\n","type":"registry:ui","target":"~/src/siteplane/components/action-icons/action-icons.css"},{"path":"packages/ui/src/components/action-icons/index.ts","content":"export * from \"./action-icons\";\n","type":"registry:ui","target":"~/src/siteplane/components/action-icons/index.ts"}],"type":"registry:ui"}