{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "files-log-viewer",
  "type": "registry:component",
  "title": "Log viewers",
  "description": "A tail-anchored log list with a level filter",
  "author": "sudo-kw <https://github.com/sudo-kw>",
  "dependencies": [
    "@gpuix/native@0.11.0",
    "@gpuix/react@0.11.0",
    "effect@4.1.2",
    "react@^19.2.4"
  ],
  "registryDependencies": [
    "https://gpuixui.sudokw.com/gpuix-data.json",
    "https://gpuixui.sudokw.com/gpuix-primitives.json",
    "https://gpuixui.sudokw.com/gpuix-tokens.json",
    "https://gpuixui.sudokw.com/gpuix-tw.json"
  ],
  "files": [
    {
      "path": "packages/files/src/log/log-viewer.tsx",
      "target": "@ui/gpuixui/files/log/log-viewer.tsx",
      "type": "registry:component",
      "content": "import type { Props } from \"@gpuix/react\";\nimport { mergeStyles } from \"@gpuix/react/floating\";\nimport { VirtualList } from \"../../data/index.js\";\nimport { Toggle, ToggleGroup } from \"../../primitives/index.js\";\nimport { cn } from \"../../tw/index.js\";\nimport * as Arr from \"effect/Array\";\nimport * as HashSet from \"effect/HashSet\";\nimport * as Option from \"effect/Option\";\nimport * as Str from \"effect/String\";\nimport { useMemo, useState } from \"react\";\nimport { recipeStyle } from \"../recipe.js\";\nimport { statusTone, textStyle, useTheme, type Theme } from \"../theme.js\";\nimport {\n  filterByLevel,\n  isLogLevel,\n  levelTone,\n  LEVEL_COLUMN_WIDTH,\n  LOG_LEVELS,\n  parseLogLine,\n  type LogLevel,\n} from \"./logic.js\";\nimport { LOG_ROW, LOG_TOOLBAR, LOG_VIEWER_ROOT } from \"./recipe.js\";\n\nexport interface LogViewerProps extends Omit<Props, \"children\"> {\n  readonly lines: ReadonlyArray<string>;\n\n  readonly height: number;\n\n  readonly rowHeight?: number;\n\n  readonly enabledLevels?: ReadonlyArray<LogLevel>;\n\n  readonly onEnabledLevelsChange?: (levels: ReadonlyArray<LogLevel>) => void;\n\n  readonly followTail?: boolean;\n\n  readonly onFollowTailChange?: (follow: boolean) => void;\n  readonly className?: string;\n  readonly testId?: string;\n}\n\nconst levelColour = (theme: Theme, level: LogLevel): string =>\n  Option.match(levelTone(level), {\n    onNone: () => theme.colors.mutedForeground,\n    onSome: (tone) => statusTone(theme, tone).foreground,\n  });\n\nexport const LogViewer = ({\n  lines,\n  height,\n  rowHeight: namedRowHeight,\n  enabledLevels,\n  onEnabledLevelsChange,\n  followTail,\n  onFollowTailChange,\n  className,\n  testId,\n  style,\n  ...rest\n}: LogViewerProps) => {\n  const theme = useTheme();\n  const [heldLevels, setHeldLevels] =\n    useState<ReadonlyArray<LogLevel>>(LOG_LEVELS);\n  const [heldFollow, setHeldFollow] = useState(true);\n\n  const levels = enabledLevels ?? heldLevels;\n  const follow = followTail ?? heldFollow;\n  const rowHeight = namedRowHeight ?? theme.density.rowHeight;\n\n  const entries = useMemo(() => Arr.map(lines, parseLogLine), [lines]);\n  const visible = useMemo(\n    () => filterByLevel(entries, HashSet.fromIterable(levels)),\n    [entries, levels],\n  );\n\n  const commitLevels = (next: ReadonlyArray<LogLevel>): void => {\n    if (enabledLevels === undefined) setHeldLevels(next);\n    onEnabledLevelsChange?.(next);\n  };\n\n  const commitFollow = (next: boolean): void => {\n    if (followTail === undefined) setHeldFollow(next);\n    onFollowTailChange?.(next);\n  };\n\n  return (\n    <div\n      {...rest}\n      style={mergeStyles(\n        recipeStyle(cn(LOG_VIEWER_ROOT, className), theme),\n        style,\n      )}\n    >\n      <div style={recipeStyle(LOG_TOOLBAR, theme)}>\n        <ToggleGroup\n          type=\"multiple\"\n          size=\"sm\"\n          label=\"Log levels\"\n          options={Arr.map(LOG_LEVELS, (level) => ({\n            value: level,\n            label: Str.capitalize(level),\n          }))}\n          value={levels}\n          onValueChange={(next) => commitLevels(Arr.filter(next, isLogLevel))}\n        />\n        <Toggle size=\"sm\" pressed={follow} onPressedChange={commitFollow}>\n          Follow tail\n        </Toggle>\n      </div>\n      <VirtualList\n        height={height}\n        followTail={follow}\n        alignment=\"bottom\"\n        testId={testId}\n      >\n        {visible.map((entry, index) => (\n          <div\n            key={index}\n            style={{\n              ...recipeStyle(LOG_ROW, theme),\n              height: rowHeight,\n            }}\n          >\n            <text\n              style={{\n                ...textStyle(theme, \"code\"),\n                color: levelColour(theme, entry.level),\n                width: LEVEL_COLUMN_WIDTH,\n                flexGrow: 0,\n                flexShrink: 0,\n                flexBasis: LEVEL_COLUMN_WIDTH,\n              }}\n            >\n              {entry.level}\n            </text>\n            <text\n              style={{\n                ...textStyle(theme, \"code\"),\n                color: theme.colors.foreground,\n                flexGrow: 1,\n                flexShrink: 1,\n                flexBasis: 0,\n                minWidth: 0,\n              }}\n            >\n              {entry.message}\n            </text>\n          </div>\n        ))}\n      </VirtualList>\n    </div>\n  );\n};\n"
    },
    {
      "path": "packages/files/src/log/logic.ts",
      "target": "@ui/gpuixui/files/log/logic.ts",
      "type": "registry:lib",
      "content": "import type { StatusTone } from \"../../tokens/index.js\";\nimport * as Arr from \"effect/Array\";\nimport * as HashSet from \"effect/HashSet\";\nimport * as Option from \"effect/Option\";\nimport * as Str from \"effect/String\";\n\nexport const LOG_LEVELS = [\"error\", \"warn\", \"info\", \"debug\", \"trace\"] as const;\n\nexport type LogLevel = (typeof LOG_LEVELS)[number];\n\nexport const LEVEL_COLUMN_WIDTH = 56;\n\nexport const isLogLevel = (value: string): value is LogLevel =>\n  Arr.some(LOG_LEVELS, (level) => level === value);\n\nexport interface LogEntry {\n  readonly level: LogLevel;\n  readonly message: string;\n}\n\nexport const DEFAULT_LEVEL: LogLevel = \"info\";\n\nconst LEVEL_ALIASES: Readonly<Record<string, LogLevel>> = {\n  error: \"error\",\n  warning: \"warn\",\n  warn: \"warn\",\n  info: \"info\",\n  debug: \"debug\",\n  trace: \"trace\",\n};\n\nconst levelOf = (token: string): Option.Option<LogLevel> =>\n  Option.fromNullishOr(LEVEL_ALIASES[Str.toLowerCase(Str.trim(token))]);\n\nconst LEVEL_PREFIX = /^\\[?([A-Za-z]+)\\]?[:\\s]+/;\n\nexport const parseLogLine = (line: string): LogEntry => {\n  const trimmed = Str.trim(line);\n  const match = LEVEL_PREFIX.exec(trimmed);\n  if (match !== null) {\n    const [full, token] = match;\n    if (full !== undefined && token !== undefined) {\n      const level = levelOf(token);\n      if (Option.isSome(level)) {\n        return {\n          level: level.value,\n          message: Str.trim(trimmed.slice(full.length)),\n        };\n      }\n    }\n  }\n  return { level: DEFAULT_LEVEL, message: trimmed };\n};\n\nexport const filterByLevel = (\n  entries: ReadonlyArray<LogEntry>,\n  enabled: HashSet.HashSet<LogLevel>,\n): ReadonlyArray<LogEntry> =>\n  Arr.filter(entries, (entry) => HashSet.has(enabled, entry.level));\n\nconst LEVEL_TONES: Readonly<Record<LogLevel, Option.Option<StatusTone>>> = {\n  error: Option.some(\"destructive\"),\n  warn: Option.some(\"warning\"),\n  info: Option.some(\"info\"),\n  debug: Option.none(),\n  trace: Option.none(),\n};\n\nexport const levelTone = (level: LogLevel): Option.Option<StatusTone> =>\n  LEVEL_TONES[level];\n"
    },
    {
      "path": "packages/files/src/log/recipe.ts",
      "target": "@ui/gpuixui/files/log/recipe.ts",
      "type": "registry:lib",
      "content": "export const LOG_VIEWER_ROOT =\n  \"flex flex-col rounded-md border border-input bg-card text-foreground overflow-hidden\";\n\nexport const LOG_TOOLBAR =\n  \"flex flex-row items-center gap-2 border-b border-input px-2 py-1\";\n\nexport const LOG_ROW = \"flex flex-row items-center gap-2 px-2\";\n"
    },
    {
      "path": "packages/files/src/recipe.ts",
      "target": "@ui/gpuixui/files/recipe.ts",
      "type": "registry:lib",
      "content": "import type { StyleDesc } from \"@gpuix/react\";\nimport { classesToStyle } from \"../tw/index.js\";\nimport * as MutableHashMap from \"effect/MutableHashMap\";\nimport * as Option from \"effect/Option\";\nimport type { Theme } from \"./theme.js\";\n\nconst CACHE_LIMIT = 256;\n\nconst compiled = new WeakMap<\n  Theme,\n  MutableHashMap.MutableHashMap<string, StyleDesc>\n>();\n\nexport const recipeStyle = (recipe: string, theme: Theme): StyleDesc => {\n  const byRecipe = compiled.get(theme);\n  if (byRecipe !== undefined) {\n    const hit = MutableHashMap.get(byRecipe, recipe);\n    if (Option.isSome(hit)) return hit.value;\n  }\n  const style = Object.freeze(classesToStyle(recipe, theme).style);\n  if (byRecipe === undefined) {\n    compiled.set(theme, MutableHashMap.make([recipe, style]));\n  } else if (MutableHashMap.size(byRecipe) < CACHE_LIMIT) {\n    MutableHashMap.set(byRecipe, recipe, style);\n  }\n  return style;\n};\n"
    },
    {
      "path": "packages/files/src/theme.ts",
      "target": "@ui/gpuixui/files/theme.ts",
      "type": "registry:lib",
      "content": "import type { Theme } from \"../tokens/index.js\";\nimport { useTheme as useTokenTheme } from \"../tokens/react.js\";\n\nexport {\n  pointerWash,\n  statusTone,\n  textStyle,\n  themeColors,\n} from \"../tokens/index.js\";\nexport type { Theme };\n\nexport const useTheme = (): Theme => useTokenTheme();\n"
    }
  ],
  "docs": "[Log viewers](https://gpuixui.sudokw.com/files/log-viewer) — These are GPUix native components: the files render through GPUix's reconciler against `@gpuix/react`, not the DOM, and need the per-platform `@gpuix/native` binding. The CLI installs the `@gpuixui/*` runtime the components import as registry items, so the copied tree resolves on its own; wrap it in `ThemeProvider` before it renders.",
  "meta": {
    "url": "/files/log-viewer",
    "kind": "component",
    "runtime": "gpuix",
    "registry": "gpuixui"
  }
}