{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "xlsx-worker-protocol",
  "title": "XLSX worker protocol",
  "description": "Typed worker messages, parse limits, and error codes for the XLSX viewer.",
  "registryDependencies": [
    "@retab/xlsx-workbook"
  ],
  "files": [
    {
      "path": "registry/new-york-v4/lib/xlsx-worker-protocol.ts",
      "content": "import type { CompactSheet } from \"@/lib/xlsx-workbook\";\n\nexport interface XlsxParseLimits {\n  maxRowMajorIndex: number;\n  maxNonEmptyCells: number;\n  maxTextChars: number;\n}\n\nexport const XLSX_PARSE_LIMITS: XlsxParseLimits = {\n  maxRowMajorIndex: 0xffffffff,\n  maxNonEmptyCells: 1_000_000,\n  maxTextChars: 50_000_000,\n};\n\nexport type XlsxWorkerErrorCode =\n  | \"parse_failed\"\n  | \"range_too_large\"\n  | \"too_many_cells\"\n  | \"text_too_large\";\n\nexport type XlsxWorkerRequest = {\n  type: \"parse_workbook\";\n  buffer: ArrayBuffer;\n};\n\nexport type XlsxWorkerResponse =\n  | { type: \"workbook\"; sheets: CompactSheet[] }\n  | { type: \"error\"; message: string; code: XlsxWorkerErrorCode };\n\nexport class XlsxWorkerError extends Error {\n  constructor(\n    readonly code: XlsxWorkerErrorCode,\n    message: string,\n  ) {\n    super(message);\n    this.name = \"XlsxWorkerError\";\n  }\n}\n\n// ZIP local-file-header variants (\"PK\\x03\\x04\", empty, and spanned archives)\n// cover .xlsx/.xlsm/.xlsb/.ods. The OLE2 / Compound File Binary header covers\n// legacy binary .xls.\nconst SPREADSHEET_CONTAINER_PREFIXES: ReadonlyArray<ReadonlyArray<number>> = [\n  [0x50, 0x4b, 0x03, 0x04],\n  [0x50, 0x4b, 0x05, 0x06],\n  [0x50, 0x4b, 0x07, 0x08],\n  [0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1],\n];\n\nfunction hasBytePrefix(\n  bytes: Uint8Array,\n  prefix: ReadonlyArray<number>,\n): boolean {\n  if (bytes.length < prefix.length) return false;\n  for (let i = 0; i < prefix.length; i++) {\n    if (bytes[i] !== prefix[i]) return false;\n  }\n  return true;\n}\n\n/**\n * True when the buffer begins with a recognized spreadsheet container\n * signature: a ZIP archive (.xlsx/.xlsm/.xlsb/.ods) or an OLE2 compound file\n * (legacy .xls). This guards SheetJS's lenient format sniffer, which would\n * otherwise coerce arbitrary bytes — a mislabeled PDF, image, or text file —\n * into a degenerate single-cell sheet instead of surfacing a parse error.\n */\nexport function isSpreadsheetContainer(buffer: ArrayBuffer): boolean {\n  const bytes = new Uint8Array(buffer);\n  return SPREADSHEET_CONTAINER_PREFIXES.some((prefix) =>\n    hasBytePrefix(bytes, prefix),\n  );\n}\n",
      "type": "registry:lib",
      "target": "@lib/xlsx-worker-protocol.ts"
    }
  ],
  "type": "registry:lib"
}