{"version":3,"sources":["/home/mkabumattar/work/withrawi/rawi/dist/chunk-XYGAEXAR.cjs","../src/core/file-readers/readers/office.reader.ts"],"names":["OfficeReader","AbstractFileReader","options","fileType","filePath","startTime"],"mappings":"AAAA;AACA,wDAAwC,4CCDT,IASlBA,CAAAA,CAAN,MAAA,QAA2BC,mBAAmB,CACnD,WAAA,CAAYC,CAAAA,CAA6B,CAAC,CAAA,CAAG,CAC3C,KAAA,CAAMA,CAAO,CACf,CAEA,OAAA,CAAQC,CAAAA,CAAsC,CAC5C,MAAO,CAAA,KAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,KAAA,CAAA,KAAA,CAAA,KAQP,CAAA,CAAE,QAAA,CAASA,CAAQ,CACrB,CAEA,MAAM,IAAA,CAAKC,CAAAA,CAA6C,CACtD,IAAMC,CAAAA,CAAY,IAAA,CAAK,GAAA,CAAI,CAAA,CAE3B,GAAI,CACF,MAAM,IAAA,CAAK,YAAA,CAAaD,CAAQ,CAAA,CAChC,IAAA,CAAK,UAAA,CAAW,CAAA,qCAAA,EAAwCA,CAAQ,CAAA,CAAA;AD7BwQ","file":"/home/mkabumattar/work/withrawi/rawi/dist/chunk-XYGAEXAR.cjs","sourcesContent":[null,"import {parseOfficeAsync} from 'officeparser';\nimport type {\n  FileReaderOptions,\n  FileReaderResult,\n  SupportedFileType,\n} from '../interfaces/types.js';\nimport {SupportedFileType as FileType} from '../interfaces/types.js';\nimport {AbstractFileReader} from './base.reader.js';\n\nexport class OfficeReader extends AbstractFileReader {\n  constructor(options: FileReaderOptions = {}) {\n    super(options);\n  }\n\n  canRead(fileType: SupportedFileType): boolean {\n    return [\n      FileType.PDF,\n      FileType.DOCX,\n      FileType.PPTX,\n      FileType.XLSX,\n      FileType.ODT,\n      FileType.ODP,\n      FileType.ODS,\n    ].includes(fileType);\n  }\n\n  async read(filePath: string): Promise<FileReaderResult> {\n    const startTime = Date.now();\n\n    try {\n      await this.validateFile(filePath);\n      this.logVerbose(`Starting office file extraction for: ${filePath}`);\n\n      const text = await this.#extractOfficeText(filePath);\n      const {size} = await this.getFileStats(filePath);\n      const processingTime = Date.now() - startTime;\n\n      this.logVerbose(\n        `Office file extraction completed in ${processingTime}ms`,\n      );\n\n      const fileType = this.#getFileTypeFromPath(filePath);\n      const mimeType = this.#getMimeTypeForFileType(fileType);\n\n      const metadata = this.createMetadata(\n        filePath,\n        size,\n        fileType.toLowerCase(),\n        processingTime,\n        mimeType,\n        {\n          wordCount: text.split(/\\s+/).filter((word) => word.length > 0).length,\n          characterCount: text.length,\n        },\n      );\n\n      return {\n        success: true,\n        content: {\n          text: text.trim(),\n          metadata,\n        },\n      };\n    } catch (error) {\n      this.logVerbose(`Office file extraction failed: ${error}`);\n      return {\n        success: false,\n        error: error instanceof Error ? error.message : String(error),\n      };\n    }\n  }\n\n  async #extractOfficeText(filePath: string): Promise<string> {\n    try {\n      const result = await parseOfficeAsync(filePath);\n\n      if (!result || typeof result !== 'string') {\n        throw new Error('No readable text found in office document');\n      }\n\n      return result;\n    } catch (error) {\n      throw new Error(\n        `Office file parsing error: ${\n          error instanceof Error ? error.message : String(error)\n        }`,\n      );\n    }\n  }\n\n  #getFileTypeFromPath(filePath: string): string {\n    const extension = filePath.toLowerCase().split('.').pop() || '';\n    const extensionMap: Record<string, string> = {\n      pdf: 'pdf',\n      docx: 'docx',\n      pptx: 'pptx',\n      xlsx: 'xlsx',\n      odt: 'odt',\n      odp: 'odp',\n      ods: 'ods',\n    };\n    return extensionMap[extension] || 'unknown';\n  }\n\n  #getMimeTypeForFileType(fileType: string): string {\n    const mimeTypes: Record<string, string> = {\n      pdf: 'application/pdf',\n      docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',\n      pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',\n      xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',\n      odt: 'application/vnd.oasis.opendocument.text',\n      odp: 'application/vnd.oasis.opendocument.presentation',\n      ods: 'application/vnd.oasis.opendocument.spreadsheet',\n    };\n    return mimeTypes[fileType] || 'application/octet-stream';\n  }\n}\n"]}