{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "terminal",
  "title": "Terminal",
  "author": "AlgorizeTech",
  "description": "Ask the user to pick one of 3 terminal variants: https://avaraui.com/view/terminal. This item holds 3 of them as looks of one component (default, glass, minimal). Skip the question if the user already named one. A terminal-styled code block with a title bar, window controls and copy button. Use it to present install and CLI commands the way a reader expects to see them.",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "utils"
  ],
  "files": [
    {
      "path": "src/components/custom/blocks/TerminalBlock.tsx",
      "content": "\"use client\";\n\nimport { cn } from \"@/lib/utils\";\nimport { Check, Copy, Terminal as TerminalIcon } from \"lucide-react\";\nimport React, { forwardRef, useState } from \"react\";\nimport { getThemeStyles } from \"./terminal-theme\";\n\n// ==========================================\n// THEME & CONFIGURATION\n// ==========================================\nexport type TerminalVariant = \"default\" | \"glass\" | \"minimal\";\nexport type TerminalColor =\n  | \"indigo\"\n  | \"rose\"\n  | \"emerald\"\n  | \"zinc\"\n  | (string & {});\n\n// ==========================================\n// SYNTAX HIGHLIGHTER ENGINE\n// ==========================================\nconst highlightCode = (code: string, language: string) => {\n  let html = code\n    .replace(/&/g, \"&amp;\")\n    .replace(/</g, \"&lt;\")\n    .replace(/>/g, \"&gt;\");\n\n  const colors = {\n    keyword: \"text-[#A626A4] dark:text-[#C678DD] font-medium\",\n    string: \"text-[#50A14F] dark:text-[#98C379]\",\n    function: \"text-[#4078F2] dark:text-[#61AFEF]\",\n    number: \"text-[#986801] dark:text-[#D19A66]\",\n    property: \"text-[#E45649] dark:text-[#E5C07B]\",\n    tag: \"text-[#E45649] dark:text-[#E06C75]\",\n    component: \"text-[#C18401] dark:text-[#E5C07B] font-semibold\",\n    operator: \"text-[#383A42] dark:text-[#ABB2BF]\",\n    comment: \"text-[#A0A1A7] dark:text-[#5C6370]\",\n    punctuation: \"text-[#383A42] dark:text-[#ABB2BF]\",\n    stringContent: \"text-[#50A14F] dark:text-[#98C379]\",\n    command: \"text-[#4078F2] dark:text-[#61AFEF] font-semibold\",\n    flag: \"text-[#986801] dark:text-[#D19A66]\",\n    arg: \"text-[#50A14F] dark:text-[#98C379]\",\n  };\n\n  const lang = language.toLowerCase();\n\n  // Each branch below is a SINGLE pass over the escaped source. Chaining\n  // separate .replace() calls does not work here: a later rule matches the\n  // markup an earlier rule injected. The quote rule, for one, matched the\n  // quotes of an already-emitted class=\"...\" attribute and nested a <span>\n  // inside it, which the browser then rendered as visible text.\n\n  if (lang === \"html\" || lang === \"xml\") {\n    return html.replace(\n      /(&lt;!--[\\s\\S]*?--&gt;)|(&lt;\\/?)([a-zA-Z0-9-]+)|([a-zA-Z0-9-]+)(=)([\"'])(.*?)\\6|(\\/&gt;|&gt;)/g,\n      (match, comment, brackets, tagName, attr, eq, quote, content, closer) => {\n        if (comment) return `<span class=\"${colors.comment}\">${comment}</span>`;\n        if (brackets !== undefined)\n          return `<span class=\"${colors.punctuation}\">${brackets}</span><span class=\"${colors.tag}\">${tagName}</span>`;\n        if (attr !== undefined)\n          return `<span class=\"${colors.property}\">${attr}</span><span class=\"${colors.operator}\">${eq}</span><span class=\"${colors.property}\">${quote}</span><span class=\"${colors.stringContent}\">${content}</span><span class=\"${colors.property}\">${quote}</span>`;\n        if (closer) return `<span class=\"${colors.punctuation}\">${closer}</span>`;\n        return match;\n      }\n    );\n  }\n\n  if (lang === \"css\") {\n    return html.replace(\n      /(\\/\\*[\\s\\S]*?\\*\\/)|(@[a-zA-Z-]+)|([^\\s{}/;][^{}/;]*?)(?=\\s*\\{)|([a-zA-Z-]+)(\\s*:)([^;{}]+)(;?)|([{}])/g,\n      (match, comment, atRule, selector, prop, colon, val, semi, brace) => {\n        if (comment) return `<span class=\"${colors.comment}\">${comment}</span>`;\n        if (atRule) return `<span class=\"${colors.keyword}\">${atRule}</span>`;\n        if (selector !== undefined)\n          return `<span class=\"${colors.tag}\">${selector}</span>`;\n        if (prop !== undefined)\n          return `<span class=\"${colors.property}\">${prop}</span><span class=\"${colors.punctuation}\">${colon}</span><span class=\"${colors.stringContent}\">${val}</span><span class=\"${colors.punctuation}\">${semi}</span>`;\n        if (brace) return `<span class=\"${colors.punctuation}\">${brace}</span>`;\n        return match;\n      }\n    );\n  }\n\n  if (lang === \"bash\" || lang === \"sh\" || lang === \"shell\" || lang === \"terminal\") {\n    return html.replace(\n      /(#[^\\n]*)|(\"[^\"\\n]*\"|'[^'\\n]*')|(\\b(?:npm|yarn|pnpm|npx|node|git|cd|ls|rm|mkdir|echo|cat|sudo|apt|brew|bun|docker)\\b)|(\\s--?[a-zA-Z0-9][a-zA-Z0-9-]*)/g,\n      (match, comment, str, command, flag) => {\n        if (comment) return `<span class=\"${colors.comment}\">${comment}</span>`;\n        if (str) return `<span class=\"${colors.string}\">${str}</span>`;\n        if (command) return `<span class=\"${colors.command}\">${command}</span>`;\n        if (flag) return `<span class=\"${colors.flag}\">${flag}</span>`;\n        return match;\n      }\n    );\n  }\n\n  // JS / TS / Generic Code\n  html = html.replace(\n    /([\"'](?:\\\\.|[^\\\\])*?[\"']|`(?:\\\\`|[^`])*`)|(\\/\\/.*|\\/\\*[\\s\\S]*?\\*\\/)|(&lt;\\/?[a-zA-Z0-9_-]+)|(\\/&gt;|&gt;)|([a-zA-Z0-9_-]+)(?=\\s*[:=])|(\\b\\d+\\.?\\d*\\b)|(\\b(?:const|let|var|function|return|if|else|for|while|import|export|from|default|class|extends|implements|new|this|typeof|instanceof|switch|case|break|continue|try|catch|finally|async|await|interface|type|public|private|protected|readonly)\\b)|([a-zA-Z_$][a-zA-Z0-9_$]*)(?=\\s*\\()|(\\b[A-Z][a-zA-Z0-9_$]*\\b)|([=+\\-*/!&|{}()[\\]]+)/g,\n    (_, str, comment, jsxTag, jsxBracket, attrKey, num, keyword, func, comp, operator) => {\n      if (str) {\n        const quote = str[0];\n        if ([\"'\", '\"', \"`\"].includes(quote)) {\n          const inside = str.slice(1, -1);\n          const endQuote = str[str.length - 1];\n          return `<span class=\"${colors.property}\">${quote}</span><span class=\"${colors.stringContent}\">${inside}</span><span class=\"${colors.property}\">${endQuote}</span>`;\n        }\n        return `<span class=\"${colors.string}\">${str}</span>`;\n      }\n      if (comment) return `<span class=\"${colors.comment}\">${comment}</span>`;\n      if (jsxTag) {\n        const isClosing = jsxTag.includes(\"/\");\n        const brackets = isClosing ? \"&lt;/\" : \"&lt;\";\n        const tagName = jsxTag.replace(brackets, \"\");\n        const isComponent = /^[A-Z]/.test(tagName);\n        const tagColor = isComponent ? colors.component : colors.tag;\n        return `<span class=\"${colors.punctuation}\">${brackets}</span><span class=\"${tagColor}\">${tagName}</span>`;\n      }\n      if (jsxBracket) return `<span class=\"${colors.punctuation}\">${jsxBracket}</span>`;\n      if (attrKey) return `<span class=\"${colors.property}\">${attrKey}</span>`;\n      if (num) return `<span class=\"${colors.number}\">${num}</span>`;\n      if (keyword) return `<span class=\"${colors.keyword}\">${keyword}</span>`;\n      if (func) return `<span class=\"${colors.function}\">${func}</span>`;\n      if (comp) return `<span class=\"${colors.component}\">${comp}</span>`;\n      if (operator) return `<span class=\"${colors.operator}\">${operator}</span>`;\n      return _;\n    }\n  );\n\n  html = html.replace(\n    /\\b(true|false|null|undefined)\\b/g,\n    `<span class=\"${colors.number}\">$1</span>`\n  );\n\n  return html;\n};\n\n// ==========================================\n// COMPONENT\n// ==========================================\nexport interface TerminalBlockProps\n  extends React.HTMLAttributes<HTMLDivElement> {\n  code: string;\n  language?: string;\n  filename?: string;\n  copyable?: boolean;\n  variant?: TerminalVariant;\n  color?: TerminalColor;\n}\n\nexport const TerminalBlock = forwardRef<HTMLDivElement, TerminalBlockProps>(\n  (\n    {\n      code,\n      language = \"bash\",\n      filename,\n      copyable = true,\n      variant = \"default\",\n      color = \"primary\",\n      className,\n      ...props\n    },\n    ref,\n  ) => {\n    const [copied, setCopied] = useState(false);\n    const { theme, style } = getThemeStyles(color as string);\n\n    const handleCopy = async () => {\n      try {\n        await navigator.clipboard.writeText(code);\n        setCopied(true);\n        setTimeout(() => setCopied(false), 2000);\n      } catch (err) {\n        console.error(\"Failed to copy text: \", err);\n      }\n    };\n\n    const variantStyles = {\n      default:\n        \"bg-card text-card-foreground border border-border shadow-xl\",\n      glass:\n        \"bg-card/80 text-card-foreground backdrop-blur-xl border border-border/80 shadow-2xl\",\n      minimal: \"bg-transparent border border-border\",\n    };\n\n    const headerStyles = {\n      default:\n        \"bg-muted/80 border-b border-border\",\n      glass:\n        \"bg-muted/60 border-b border-border/80\",\n      minimal:\n        \"bg-muted border-b border-border\",\n    };\n\n    const highlightedCode = highlightCode(code, language);\n\n    return (\n      <div\n        ref={ref}\n        className={cn(\n          \"w-full rounded-xl overflow-hidden flex flex-col font-sans\",\n          variantStyles[variant],\n          className,\n        )}\n        style={style}\n        {...props}\n      >\n        {/* Header */}\n        <div\n          className={cn(\n            \"flex items-center justify-between px-4 py-3 h-12 select-none\",\n            headerStyles[variant],\n          )}\n        >\n          <div className=\"flex items-center gap-4 w-1/3\">\n            {variant !== \"minimal\" ? (\n              <div className=\"flex items-center gap-1.5\">\n                <div className=\"w-3 h-3 rounded-full bg-[#ff5f56]\" />\n                <div className=\"w-3 h-3 rounded-full bg-[#ffbd2e]\" />\n                <div className=\"w-3 h-3 rounded-full bg-[#27c93f]\" />\n              </div>\n            ) : (\n              <TerminalIcon className=\"w-4 h-4 text-muted-foreground\" />\n            )}\n          </div>\n\n          <div className=\"flex items-center justify-center w-1/3\">\n            {filename && (\n              <span className=\"text-xs font-medium font-mono text-muted-foreground\">\n                {filename}\n              </span>\n            )}\n          </div>\n\n          <div className=\"flex items-center justify-end gap-3 w-1/3\">\n            {language && (\n              <span\n                className={cn(\n                  \"px-2 py-1 rounded-md text-[10px] font-semibold uppercase tracking-wider\",\n                  theme.bg,\n                  theme.border,\n                  \"border\",\n                )}\n              >\n                {language}\n              </span>\n            )}\n            {copyable && (\n              <button\n                onClick={handleCopy}\n                className=\"flex items-center justify-center w-8 h-8 rounded-lg transition-all hover:bg-foreground/10 text-muted-foreground\"\n                title=\"Copy code\"\n              >\n                {copied ? (\n                  <Check className={cn(\"w-4 h-4\", theme.text)} />\n                ) : (\n                  <Copy className=\"w-4 h-4\" />\n                )}\n              </button>\n            )}\n          </div>\n        </div>\n\n        {/* Code Area */}\n        <div className=\"p-4 md:p-6 overflow-x-auto\">\n          <pre className=\"m-0 bg-transparent p-0 w-max min-w-full\">\n            <code\n              className=\"font-mono text-sm leading-relaxed text-foreground\"\n              dangerouslySetInnerHTML={{ __html: highlightedCode }}\n            />\n          </pre>\n        </div>\n      </div>\n    );\n  },\n);\nTerminalBlock.displayName = \"TerminalBlock\";\n",
      "type": "registry:component",
      "target": "components/custom/blocks/TerminalBlock.tsx"
    },
    {
      "path": "src/components/custom/blocks/terminal-theme.ts",
      "content": "\"use client\";\n\nimport React from \"react\";\n\nconst colorThemes: Record<string, Record<string, string>> = {\n  primary: {\n    bg: \"bg-primary/10 text-primary\",\n    border: \"border-primary/30\",\n    text: \"text-primary\",\n  },\n  indigo: {\n    bg: \"bg-indigo-500/10 text-indigo-400\",\n    border: \"border-indigo-500/30\",\n    text: \"text-indigo-400\",\n  },\n  rose: {\n    bg: \"bg-rose-500/10 text-rose-400\",\n    border: \"border-rose-500/30\",\n    text: \"text-rose-400\",\n  },\n  emerald: {\n    bg: \"bg-emerald-500/10 text-emerald-400\",\n    border: \"border-emerald-500/30\",\n    text: \"text-emerald-400\",\n  },\n  zinc: {\n    bg: \"bg-zinc-500/10 text-zinc-400\",\n    border: \"border-zinc-500/30\",\n    text: \"text-zinc-400\",\n  },\n};\n\nconst hexToRgb = (hex: string) => {\n  let cleanHex = hex.replace(/^#/, \"\");\n  if (cleanHex.length === 3)\n    cleanHex = cleanHex\n      .split(\"\")\n      .map((x) => x + x)\n      .join(\"\");\n  const result = /^([a-f\\d]{2})([a-f\\d]{2})([a-f\\d]{2})$/i.exec(cleanHex);\n  return result\n    ? `${parseInt(result[1], 16)}, ${parseInt(result[2], 16)}, ${parseInt(result[3], 16)}`\n    : \"99, 102, 241\";\n};\n\nexport const getThemeStyles = (color: string) => {\n  if (color && color.startsWith(\"#\")) {\n    const rgb = hexToRgb(color);\n    return {\n      theme: {\n        bg: \"bg-[rgba(var(--term-rgb),0.1)] text-[var(--term-color)]\",\n        border: \"border-[rgba(var(--term-rgb),0.3)]\",\n        text: \"text-[var(--term-color)]\",\n      },\n      style: {\n        \"--term-color\": color,\n        \"--term-rgb\": rgb,\n      } as React.CSSProperties,\n    };\n  }\n  return { theme: colorThemes[color] || colorThemes.primary, style: {} };\n};\n",
      "type": "registry:component",
      "target": "components/custom/blocks/terminal-theme.ts"
    }
  ],
  "docs": "Named exports: TerminalBlock, getThemeStyles (from terminal-theme.ts, which installs alongside). `code` is the only required prop; `language` defaults to bash and also understands sh, shell, terminal, html, xml, css and a generic JS/TS fallback. `filename` fills the title bar and `copyable` toggles the copy button. Variants: default | glass | minimal. Highlighting is a built-in regex tokenizer, not Shiki or Prism — good for snippets, not a full editor. For several files behind tabs, use `custom-code-block`.",
  "categories": [
    "code"
  ],
  "type": "registry:component"
}
