import * as pdfjs_dist from 'pdfjs-dist'; type PreviewSource = File | Blob | string | ArrayBuffer; type PreviewFit = "contain" | "cover" | "width" | "height" | "actual" | "scale-down"; type PreviewFallback = "inline" | "download" | "custom"; type PreviewTheme = "light" | "dark" | "auto"; type PreviewLocale = "zh-CN" | "en-US"; type PreviewToolbarBuiltInAction = "previous" | "next" | "queue" | "zoom-out" | "zoom-in" | "zoom-reset" | "rotate-left" | "rotate-right" | "download" | "fullscreen" | "exit-fullscreen" | "print" | "search"; type PreviewToolbarActionId = PreviewToolbarBuiltInAction | (string & {}); interface PreviewFile { source: PreviewSource; name: string; extension: string; mimeType: string; size?: number; url?: string; blob?: Blob; } interface PreviewItem { file: PreviewSource; fileName?: string; mimeType?: string; } interface PreviewSize { width: number; height: number; } interface PreviewToolbarOptions { zoom?: boolean; rotate?: boolean; download?: boolean; fullscreen?: boolean; print?: boolean; search?: boolean; order?: PreviewToolbarActionId[]; labels?: Partial>; titles?: Partial>; icons?: Partial>; actions?: PreviewToolbarCustomAction[]; render?: (ctx: PreviewToolbarRenderContext) => HTMLElement | void; } interface PreviewToolbarCustomAction { id: string; label: string; title?: string; icon?: string | HTMLElement | SVGElement; order?: number; disabled?: boolean | ((ctx: PreviewToolbarRenderContext) => boolean); hidden?: boolean | ((ctx: PreviewToolbarRenderContext) => boolean); className?: string; onClick: (ctx: PreviewToolbarRenderContext) => void | Promise; } interface PreviewToolbarRenderContext { file?: PreviewFile; index: number; length: number; viewport: HTMLElement; canPrevious: boolean; canNext: boolean; isFullscreen: boolean; zoom?: number; zoomLabel?: string; previous: () => Promise; next: () => Promise; /** Jump to a 1-based page in the active preview. Returns false for non-paginated formats. */ goToPage: (page: number) => boolean; command: (command: PreviewCommand) => void | boolean | undefined; canCommand: (command: PreviewCommand) => boolean; refreshCommandSupport: () => void; setZoom: (zoom?: number) => void; download: () => void; fullscreen: () => void; print: () => void; search: (query: string) => number; clearSearch: () => void; } interface PreviewOptions { container: HTMLElement | string; file?: PreviewSource; files?: Array; initialIndex?: number; /** Initial 1-based page for paginated previews. Out-of-range values are clamped. */ initialPage?: number; fileName?: string; mimeType?: string; width?: number | string; height?: number | string; zoom?: number; fit?: PreviewFit; plugins?: PreviewPlugin[]; fallback?: PreviewFallback; locale?: PreviewLocale; messages?: Partial; renderFallback?: (ctx: PreviewContext) => Promise | PreviewInstance; toolbar?: boolean | PreviewToolbarOptions; theme?: PreviewTheme; className?: string; onLoad?: (file: PreviewFile) => void; onError?: (error: Error, file?: PreviewFile) => void; onUnsupported?: (file: PreviewFile) => void; } interface PreviewMessages { [key: string]: string | undefined; loading: string; unsupportedTitle: string; downloadTitle: string; downloadFile: string; file: string; unnamedFile: string; format: string; unknown: string; mime: string; undeclared: string; size: string; source: string; remoteUrl: string; localFile: string; textPlainLanguage: string; textLineCount: string; textWrap: string; textCopy: string; textCopied: string; textCopyFailed: string; textDownload: string; textDownloadReady: string; textLargeFileNotice: string; textHighlightSkipped: string; textPreviewFailedTitle: string; textPreviewFailedMessage: string; textOpenOriginal: string; lrcPreviewMode: string; lrcDisplayMode: string; lrcAnnotatedMode: string; lrcSourceMode: string; lrcWordTimestamp: string; lrcMale: string; lrcFemale: string; lrcDuet: string; lrcAuthor: string; lrcLyricist: string; lrcLrcBy: string; lrcAlbum: string; lrcLength: string; lrcOffset: string; lrcTool: string; lrcVersion: string; lrcTrackInformation: string; lrcEmpty: string; officeLegacyConversionTitle: string; officeLegacyBinaryNotice: string; officeLegacyMetaFormatType: string; officeLegacyMetaFileStructure: string; officeLegacyOleDetected: string; officeLegacyOleMissing: string; officeLegacyMetaTextFragments: string; officeLegacyTextFragmentCount: string; officeLegacyMetaParseStatus: string; officeLegacyReadableFragments: string; officeLegacyNoText: string; officeLegacyWordParseFailed: string; officeSheetParseFailed: string; officeUnsupportedTitle: string; officeUnsupportedLegacyMessage: string; officeUnsupportedGenericMessage: string; officeUnsupportedIntro: string; officeUnsupportedSupportedFormats: string; officeErrorWithMessage: string; officeErrorWithoutMessage: string; officeConvertedTitle: string; officeConvertedPdfFailed: string; pdfEncryptedTitle: string; pdfEncryptedMessage: string; pdfPreviewFailedTitle: string; pdfCorruptedMessage: string; pdfCannotLoadMessage: string; pdfDownload: string; pdfPageLoading: string; pdfPageEmpty: string; pdfPageRenderFailed: string; pdfPreviousPage: string; pdfNextPage: string; pdfPageInput: string; pdfPagePosition: string; pdfPageLabel: string; pdfSummaryPages: string; pdfSummaryPageSizes: string; pdfSummaryFit: string; pdfSummaryActualSize: string; pdfSummaryFitWidth: string; pdfSummaryZoom: string; imagePreviewFailedTitle: string; imagePreviewFailedMessage: string; imageDownload: string; imageZoomOut: string; imageZoomIn: string; imageRotate: string; imageReset: string; } interface PreviewContext { host: HTMLElement; viewport: HTMLElement; file: PreviewFile; size: PreviewSize; options: Omit & Required> & { messages: PreviewMessages; /** Whether the caller explicitly selected a fit mode instead of using the viewer default. */ fitWasProvided: boolean; }; toolbar?: PreviewToolbarRenderContext; /** Aborted when this render is superseded or the viewer is destroyed. */ signal?: AbortSignal; setLoading: (loading: boolean) => void; setError: (error: Error | string) => void; } interface PreviewInstance { resize?: (size: PreviewSize) => void; /** Jump to a 1-based page. Returns false when the rendered preview has no pages. */ goToPage?: (page: number) => boolean; command?: (command: PreviewCommand) => void | boolean; canCommand?: (command: PreviewCommand) => boolean; /** Resolve once any lazily rendered content is ready to be captured for printing. */ preparePrint?: () => void | Promise; destroy: () => void; } type PreviewCommand = "zoom-in" | "zoom-out" | "zoom-reset" | "rotate-right" | "rotate-left"; interface PreviewPlugin { name: string; match: (file: PreviewFile) => boolean | Promise; render: (ctx: PreviewContext) => Promise | PreviewInstance; } interface FileViewer { reload: (file?: PreviewSource) => Promise; next: () => Promise; previous: () => Promise; goTo: (index: number) => Promise; /** Jump to a 1-based page in the active preview. */ goToPage: (page: number) => boolean; getCurrentIndex: () => number; resize: () => void; destroy: () => void; } declare function createViewer(options: PreviewOptions): FileViewer; interface PreviewSupportOptions { fileName?: string; mimeType?: string; } /** 在挂载预览器前,按实际插件顺序判断文件是否有可用的预览路径。 */ declare function isPreviewSupported(source: PreviewSource, plugins: PreviewPlugin[], options?: PreviewSupportOptions): Promise; declare function imagePlugin(): PreviewPlugin; interface VideoPluginOptions { /** Space-separated restrictions for the browser's native video controls, such as "nodownload". */ controlsList?: string; } declare function videoPlugin(options?: VideoPluginOptions): PreviewPlugin; declare function audioPlugin(): PreviewPlugin; declare function textPlugin(): PreviewPlugin; type PdfJsModule = typeof pdfjs_dist; type PdfWebFallbackScripts = "auto" | "never" | "always"; interface PdfPluginOptions { pdfjs?: PdfJsModule; workerSrc?: string; compatibilityMode?: "auto" | "modern" | "legacy"; cMapUrl?: string; cMapPacked?: boolean; standardFontDataUrl?: string; useSystemFonts?: boolean; disableStream?: boolean; disableAutoFetch?: boolean; disableRange?: boolean; rangeChunkSize?: number; useFetchData?: boolean; webFallbackScripts?: PdfWebFallbackScripts; } declare function pdfPlugin(options?: PdfJsModule | PdfPluginOptions): PreviewPlugin; declare function epubPlugin(): PreviewPlugin; declare function xpsPlugin(): PreviewPlugin; interface OfficeConversionContext { file: PreviewContext["file"]; arrayBuffer: ArrayBuffer; extension: string; detectedFormat?: "docx" | "xlsx" | "pptx"; reason: "complex-docx" | "legacy-office" | "manual"; } type OfficeConversionResult = Blob | ArrayBuffer | string | { blob?: Blob; data?: Blob | ArrayBuffer; url?: string; fileName?: string; mimeType?: string; }; interface OfficePluginOptions { convert?: (ctx: OfficeConversionContext) => Promise | OfficeConversionResult | null | undefined; preferConversion?: boolean | ((ctx: OfficeConversionContext) => boolean | Promise); pdf?: PdfPluginOptions; } declare function officePlugin(options?: OfficePluginOptions): PreviewPlugin; declare function ofdPlugin(): PreviewPlugin; declare function archivePlugin(): PreviewPlugin; declare function emailPlugin(): PreviewPlugin; declare function drawingPlugin(): PreviewPlugin; declare function xmindPlugin(): PreviewPlugin; interface LibreDwgPreviewOptions { /** * Enable the built-in LibreDWG WASM preview for DWG files. * * It is best-effort and intentionally lower priority than `binaryRenderer`. */ enabled?: boolean; /** * Public URL that contains libredwg-web.wasm. * * Example: `/vendor/libredwg-web` */ wasmBaseUrl?: string; /** * Run LibreDWG parsing in a dedicated worker when `workerModuleUrl` or * `workerFactory` is available. Defaults to true. */ useWorker?: boolean; /** * Browser-loadable URL for the ESM entry of `@mlightcad/libredwg-web`. * The worker imports this URL without bundling the GPL dependency into core. */ workerModuleUrl?: string; /** Create a custom module worker that implements the LibreDWG worker protocol. */ workerFactory?: () => Worker; /** Maximum time allowed for worker parsing. Defaults to 120 seconds. */ workerTimeoutMs?: number; } interface WebglDwgPreviewOptions { /** Directory containing the DWG parser and MTEXT worker bundles. */ workerBaseUrl: string; /** * Loads the optional WebGL CAD engine. * * Keeping this import in the host application lets strict bundlers resolve * the peer only when WebGL DWG preview is enabled. * * @example `() => import("@mlightcad/cad-simple-viewer")` */ engineLoader: WebglDwgEngineLoader; /** Optional base URL for CAD fonts and other runtime resources. */ baseUrl?: string; /** Skip loading the engine's default font set. Defaults to false. */ notLoadDefaultFonts?: boolean; /** Verify both worker URLs before opening a drawing. Defaults to true. */ checkWorkers?: boolean; /** Paint converted entities incrementally while parsing. Defaults to true. */ progressiveRendering?: boolean; /** Render converted entities on the main thread. Defaults to false. */ useMainThreadDraw?: boolean; } type WebglDwgEngineLoader = () => Promise; interface CadBinaryPreviewContext { panel: HTMLElement; fileName: string; extension: "dwg" | "dwf"; arrayBuffer: ArrayBuffer; bytes: Uint8Array; preview: PreviewContext; } interface CadPluginOptions { /** * Optional high-fidelity renderer for proprietary binary CAD files. When it * returns a preview instance, it takes over DWG/DWF rendering completely. * * Use it for custom front-end engines or server-side CAD conversion services. */ binaryRenderer?: (ctx: CadBinaryPreviewContext) => Promise | PreviewInstance | void; /** * High-fidelity WebGL DWG rendering with layers, blocks, hatches and text. * * The two worker bundles must be copied to `workerBaseUrl` by the host app. * Rendering errors are surfaced to the host instead of switching renderers. */ webglDwg?: false | WebglDwgPreviewOptions; /** * Built-in best-effort DWG preview powered by LibreDWG WASM. * * Pass `false` to keep the old metadata-only DWG behavior. Pass an object to * configure the public WASM asset path. */ libreDwg?: false | LibreDwgPreviewOptions; } declare function cadPlugin(options?: CadPluginOptions): PreviewPlugin; declare function model3dPlugin(): PreviewPlugin; declare function gisPlugin(): PreviewPlugin; declare function assetPlugin(): PreviewPlugin; declare function fallbackPlugin(): PreviewPlugin; export { type CadBinaryPreviewContext, type CadPluginOptions, type FileViewer, type LibreDwgPreviewOptions, type OfficeConversionContext, type OfficeConversionResult, type OfficePluginOptions, type PdfPluginOptions, type PdfWebFallbackScripts, type PreviewCommand, type PreviewContext, type PreviewFallback, type PreviewFile, type PreviewFit, type PreviewInstance, type PreviewItem, type PreviewLocale, type PreviewMessages, type PreviewOptions, type PreviewPlugin, type PreviewSize, type PreviewSource, type PreviewSupportOptions, type PreviewTheme, type PreviewToolbarActionId, type PreviewToolbarBuiltInAction, type PreviewToolbarCustomAction, type PreviewToolbarOptions, type PreviewToolbarRenderContext, type VideoPluginOptions, type WebglDwgEngineLoader, type WebglDwgPreviewOptions, archivePlugin, assetPlugin, audioPlugin, cadPlugin, createViewer, drawingPlugin, emailPlugin, epubPlugin, fallbackPlugin, gisPlugin, imagePlugin, isPreviewSupported, model3dPlugin, ofdPlugin, officePlugin, pdfPlugin, textPlugin, videoPlugin, xmindPlugin, xpsPlugin };