πŸ“„ File detail

components/StructuredDiff/colorDiff.ts

🧩 .tsπŸ“ 38 linesπŸ’Ύ 1,137 bytesπŸ“ text
← Back to All Files

🎯 Use case

This file lives under β€œcomponents/”, which covers shared React UI pieces. On the API surface it exposes ColorModuleUnavailableReason, getColorModuleUnavailableReason, expectColorDiff, expectColorFile, and getSyntaxTheme β€” mainly functions, hooks, or classes. Dependencies touch color-diff-napi. It composes internal code from utils (relative imports).

Generated from folder role, exports, dependency roots, and inline comments β€” not hand-reviewed for every path.

🧠 Inline summary

import { ColorDiff, ColorFile, getSyntaxTheme as nativeGetSyntaxTheme, type SyntaxTheme,

πŸ“€ Exports (heuristic)

  • ColorModuleUnavailableReason
  • getColorModuleUnavailableReason
  • expectColorDiff
  • expectColorFile
  • getSyntaxTheme

πŸ“š External import roots

Package roots from from "…" (relative paths omitted).

  • color-diff-napi

πŸ–₯️ Source preview

import {
  ColorDiff,
  ColorFile,
  getSyntaxTheme as nativeGetSyntaxTheme,
  type SyntaxTheme,
} from 'color-diff-napi'
import { isEnvDefinedFalsy } from '../../utils/envUtils.js'

export type ColorModuleUnavailableReason = 'env'

/**
 * Returns a static reason why the color-diff module is unavailable, or null if available.
 * 'env' = disabled via CLAUDE_CODE_SYNTAX_HIGHLIGHT
 *
 * The TS port of color-diff works in all build modes, so the only way to
 * disable it is via the env var.
 */
export function getColorModuleUnavailableReason(): ColorModuleUnavailableReason | null {
  if (isEnvDefinedFalsy(process.env.CLAUDE_CODE_SYNTAX_HIGHLIGHT)) {
    return 'env'
  }
  return null
}

export function expectColorDiff(): typeof ColorDiff | null {
  return getColorModuleUnavailableReason() === null ? ColorDiff : null
}

export function expectColorFile(): typeof ColorFile | null {
  return getColorModuleUnavailableReason() === null ? ColorFile : null
}

export function getSyntaxTheme(themeName: string): SyntaxTheme | null {
  return getColorModuleUnavailableReason() === null
    ? nativeGetSyntaxTheme(themeName)
    : null
}