@eternalheart/vue-file-preview 1.6.13 → 1.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/README.md +4 -0
  2. package/README.zh-CN.md +4 -0
  3. package/lib/FilePreviewContent.vue.d.ts +25 -6
  4. package/lib/FilePreviewEmbed.vue.d.ts +19 -6
  5. package/lib/FilePreviewModal.vue.d.ts +19 -6
  6. package/lib/chunks/{EmptyState.vue_vue_type_script_setup_true_lang-C7qk6wj0.mjs → EmptyState.vue_vue_type_script_setup_true_lang-DSQp7H-K.mjs} +1 -1
  7. package/lib/chunks/{avifLoader-CAUzjn-d-C0KRpetN.mjs → avifLoader-CAUzjn-d-Cf00sjt2.mjs} +1 -1
  8. package/lib/chunks/{heicLoader-D_9PukkA-Czof_5FJ.mjs → heicLoader-D_9PukkA-cn1P7b2x.mjs} +1 -1
  9. package/lib/chunks/{index-BASg1cr4.mjs → index-0VXtKKev.mjs} +1018 -1018
  10. package/lib/chunks/index-0fXL30y0.mjs +333 -0
  11. package/lib/chunks/{index-C9mAajbD.mjs → index-B1AwVHWI.mjs} +191 -191
  12. package/lib/chunks/{index-BvBqDq3O.mjs → index-B77rFiau.mjs} +2023 -2023
  13. package/lib/chunks/index-BB10as16.mjs +108 -0
  14. package/lib/chunks/index-BBIn-k4u.mjs +359 -0
  15. package/lib/chunks/index-BSzaI9ea.mjs +122 -0
  16. package/lib/chunks/index-BZvy39tn.mjs +117 -0
  17. package/lib/chunks/index-BlJEM2Lb.mjs +383 -0
  18. package/lib/chunks/{index-CxKZKUJj.mjs → index-CZlnxQFA.mjs} +1385 -1385
  19. package/lib/chunks/index-ClhTPqDI.mjs +137 -0
  20. package/lib/chunks/{index-8Vpbg2kS.mjs → index-D690gnNu.mjs} +118 -117
  21. package/lib/chunks/index-D7WykPYL.mjs +51 -0
  22. package/lib/chunks/{index-DZZN3kYi.mjs → index-DBzyeU0G.mjs} +1609 -1375
  23. package/lib/chunks/{index-Dkro_8Fy.mjs → index-DKFX5ToE.mjs} +33 -33
  24. package/lib/chunks/index-DRmKaFXK.mjs +157 -0
  25. package/lib/chunks/index-DXf3wXT5.mjs +155 -0
  26. package/lib/chunks/{index-BuqPb5mP.mjs → index-Dp7QQjNH.mjs} +114 -114
  27. package/lib/chunks/index-FzI__DHC.mjs +104 -0
  28. package/lib/chunks/index-PWjCziZG.mjs +90 -0
  29. package/lib/chunks/index-bT6XWKO_.mjs +52 -0
  30. package/lib/chunks/{index-DN4Ui0Gh.mjs → index-tX9VR6Vo.mjs} +122 -122
  31. package/lib/chunks/{jp2Loader-Dig19xyo-CKUaGhPl.mjs → jp2Loader-Dig19xyo-D-OEDL3n.mjs} +1 -1
  32. package/lib/chunks/{psdLoader-C0tKUXXl-CYWoQis5.mjs → psdLoader-C0tKUXXl-CVN06LUc.mjs} +1 -1
  33. package/lib/chunks/{rawLoader-C-tPeFAB-C35zC8nZ.mjs → rawLoader-C-tPeFAB-DBqcJPFK.mjs} +5 -5
  34. package/lib/chunks/{tiffLoader-BlhByX8w-BOxg_Du5.mjs → tiffLoader-BlhByX8w-8-0icdyL.mjs} +1 -1
  35. package/lib/chunks/{useShikiHighlight-BPmcxA-h.mjs → useShikiHighlight-a_GUszuU.mjs} +1 -1
  36. package/lib/composables/useAudioPlayer.d.ts +1 -1
  37. package/lib/composables/usePreviewEvents.d.ts +27 -0
  38. package/lib/composables/useRequest.d.ts +16 -4
  39. package/lib/composables/useThemeMode.d.ts +1 -1
  40. package/lib/composables/useTranslator.d.ts +2 -2
  41. package/lib/core/events.d.ts +69 -0
  42. package/lib/core/i18n/index.d.ts +29 -0
  43. package/lib/core/i18n/messages/en-US.d.ts +5 -0
  44. package/lib/core/i18n/messages/index.d.ts +9 -0
  45. package/lib/core/i18n/messages/zh-CN.d.ts +5 -0
  46. package/lib/core/i18n/types.d.ts +23 -0
  47. package/lib/core/index.d.ts +34 -0
  48. package/lib/core/loaders/avifLoader.d.ts +22 -0
  49. package/lib/core/loaders/heicLoader.d.ts +21 -0
  50. package/lib/core/loaders/jp2Loader.d.ts +16 -0
  51. package/lib/core/loaders/jp2Worker.d.ts +1 -0
  52. package/lib/core/loaders/psdLoader.d.ts +14 -0
  53. package/lib/core/loaders/rawLoader.d.ts +14 -0
  54. package/lib/core/loaders/registry.d.ts +32 -0
  55. package/lib/core/loaders/tiffLoader.d.ts +28 -0
  56. package/lib/core/loaders/types.d.ts +56 -0
  57. package/lib/core/types.d.ts +89 -0
  58. package/lib/core/utils/csvParser.d.ts +31 -0
  59. package/lib/core/utils/emptyState.d.ts +28 -0
  60. package/lib/core/utils/excelDataConverter.d.ts +61 -0
  61. package/lib/core/utils/fileNormalizer.d.ts +21 -0
  62. package/lib/core/utils/fileType.d.ts +21 -0
  63. package/lib/core/utils/legacy-office/doc.d.ts +25 -0
  64. package/lib/core/utils/legacy-office/index.d.ts +8 -0
  65. package/lib/core/utils/legacy-office/ole.d.ts +8 -0
  66. package/lib/core/utils/legacy-office/ppt.d.ts +79 -0
  67. package/lib/core/utils/legacy-office/xls.d.ts +28 -0
  68. package/lib/core/utils/mimeTypes.d.ts +29 -0
  69. package/lib/core/utils/ooxml/docx.d.ts +17 -0
  70. package/lib/core/utils/ooxml/index.d.ts +4 -0
  71. package/lib/core/utils/ooxml/pptx.d.ts +7 -0
  72. package/lib/core/utils/ooxml/xml.d.ts +15 -0
  73. package/lib/core/utils/ooxml/zip.d.ts +3 -0
  74. package/lib/core/utils/pdfWorker.d.ts +61 -0
  75. package/lib/core/utils/previewMode.d.ts +7 -0
  76. package/lib/core/utils/request.d.ts +49 -0
  77. package/lib/core/utils/subtitleParser.d.ts +44 -0
  78. package/lib/core/utils/textDecoder.d.ts +30 -0
  79. package/lib/core/utils/uint8ArrayPolyfill.d.ts +18 -0
  80. package/lib/core/utils/zipReader.d.ts +51 -0
  81. package/lib/core/workers/imageDecoder.worker.d.ts +31 -0
  82. package/lib/core/workers/workerClient.d.ts +14 -0
  83. package/lib/i18n/localeKey.d.ts +1 -1
  84. package/lib/index.cjs +60 -60
  85. package/lib/index.css +1 -1
  86. package/lib/index.d.ts +11 -9
  87. package/lib/index.mjs +15 -12
  88. package/lib/renderers/Audio/index.vue.d.ts +1 -1
  89. package/lib/renderers/Cad/index.vue.d.ts +1 -1
  90. package/lib/renderers/Cad/toolbar.d.ts +2 -2
  91. package/lib/renderers/Csv/index.vue.d.ts +1 -1
  92. package/lib/renderers/Doc/index.vue.d.ts +1 -1
  93. package/lib/renderers/Docx/index.vue.d.ts +1 -1
  94. package/lib/renderers/Epub/index.vue.d.ts +1 -1
  95. package/lib/renderers/Font/index.vue.d.ts +1 -1
  96. package/lib/renderers/Image/index.vue.d.ts +2 -2
  97. package/lib/renderers/Json/index.vue.d.ts +2 -2
  98. package/lib/renderers/Markdown/index.vue.d.ts +1 -1
  99. package/lib/renderers/Mobi/index.vue.d.ts +1 -1
  100. package/lib/renderers/Msg/index.vue.d.ts +1 -1
  101. package/lib/renderers/Pdf/index.vue.d.ts +1 -1
  102. package/lib/renderers/Ppt/index.vue.d.ts +1 -1
  103. package/lib/renderers/Pptx/index.vue.d.ts +2 -2
  104. package/lib/renderers/Subtitle/index.vue.d.ts +1 -1
  105. package/lib/renderers/Text/index.vue.d.ts +2 -2
  106. package/lib/renderers/Unsupported/index.vue.d.ts +1 -1
  107. package/lib/renderers/Video/index.vue.d.ts +1 -1
  108. package/lib/renderers/Xlsx/index.vue.d.ts +2 -2
  109. package/lib/renderers/Xml/index.vue.d.ts +1 -1
  110. package/lib/renderers/Zip/TreeItem.vue.d.ts +1 -1
  111. package/lib/renderers/Zip/index.vue.d.ts +1 -1
  112. package/lib/renderers/base.types.d.ts +1 -1
  113. package/lib/renderers/registry.d.ts +1 -1
  114. package/lib/types.d.ts +3 -3
  115. package/package.json +2 -2
  116. package/lib/chunks/index--612Smof.mjs +0 -383
  117. package/lib/chunks/index-B21EAyWz.mjs +0 -137
  118. package/lib/chunks/index-BB0i4QqI.mjs +0 -117
  119. package/lib/chunks/index-BVdrGK3Q.mjs +0 -356
  120. package/lib/chunks/index-BlrFFeqc.mjs +0 -330
  121. package/lib/chunks/index-Bp9CuvMZ.mjs +0 -157
  122. package/lib/chunks/index-Bxpf9v5j.mjs +0 -104
  123. package/lib/chunks/index-CDg6vIbT.mjs +0 -51
  124. package/lib/chunks/index-CWE-hKSs.mjs +0 -90
  125. package/lib/chunks/index-CY3xzGgt.mjs +0 -108
  126. package/lib/chunks/index-D30L8tm9.mjs +0 -155
  127. package/lib/chunks/index-VdzIFJJW.mjs +0 -118
  128. package/lib/chunks/index-aoXgVLBb.mjs +0 -52
@@ -0,0 +1,31 @@
1
+ /**
2
+ * 轻量 CSV/TSV 解析器
3
+ * 支持 RFC 4180 基础特性:
4
+ * - 双引号字段、字段内包含分隔符
5
+ * - 双引号转义("" 表示字面量 ")
6
+ * - 字段内换行(\r\n / \n)
7
+ */
8
+ export interface CsvParseOptions {
9
+ /** 分隔符,CSV 为 "," TSV 为 "\t"。默认根据文件名自动识别 */
10
+ delimiter?: string;
11
+ /** 将首行作为表头 */
12
+ firstRowAsHeader?: boolean;
13
+ }
14
+ export interface CsvParseResult {
15
+ /** 表头(可能为空数组) */
16
+ header: string[];
17
+ /** 数据行 */
18
+ rows: string[][];
19
+ /** 列数 */
20
+ columnCount: number;
21
+ /** 分隔符(实际使用的) */
22
+ delimiter: string;
23
+ }
24
+ /**
25
+ * 根据文件名推断分隔符
26
+ */
27
+ export declare function guessCsvDelimiter(fileName: string): string;
28
+ /**
29
+ * 解析 CSV/TSV 文本
30
+ */
31
+ export declare function parseCsv(text: string, options?: CsvParseOptions): CsvParseResult;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * 空内容判定与提示策略(框架无关,React / Vue / Angular 共用)
3
+ *
4
+ * 默认行为是「原生展示」:文本类内容为空时保持空白,不插入任何占位内容。
5
+ * 需要通过 `emptyHint` 显式开启提示,文案取 `t('file.empty')`,可用 `messages` 覆盖。
6
+ */
7
+ /**
8
+ * 空内容提示策略
9
+ * - `auto`:按类型取默认值。文本类(内容即文件内容)保持空白;结构化类型(需解析产出内容)显示提示
10
+ * - `always`:强制显示提示
11
+ * - `never`:一律保持空白
12
+ */
13
+ export type EmptyHintMode = 'auto' | 'always' | 'never';
14
+ /**
15
+ * 空内容类型
16
+ * - `textual`:文件内容本身就是渲染结果(text / json 等)
17
+ * - `structured`:内容必须由解析器产出,空输入时解析器无输出(xlsx / pptx 等)
18
+ */
19
+ export type EmptyContentKind = 'textual' | 'structured';
20
+ /**
21
+ * 判断文本内容是否为空:仅含空白字符(含 BOM、换行、空格)视为空。
22
+ * `null` / `undefined` / `''` 均视为空。
23
+ */
24
+ export declare function isEmptyContent(text: string | null | undefined): boolean;
25
+ /**
26
+ * 计算是否展示空内容提示(不负责判定内容是否为空)。
27
+ */
28
+ export declare function resolveEmptyHint(mode: EmptyHintMode | undefined, kind: EmptyContentKind): boolean;
@@ -0,0 +1,61 @@
1
+ import type { Workbook } from 'exceljs';
2
+ interface XCellStyle {
3
+ align?: 'left' | 'center' | 'right';
4
+ valign?: 'top' | 'middle' | 'bottom';
5
+ font?: {
6
+ name?: string;
7
+ size?: number;
8
+ bold?: boolean;
9
+ italic?: boolean;
10
+ };
11
+ bgcolor?: string;
12
+ textwrap?: boolean;
13
+ color?: string;
14
+ strike?: boolean;
15
+ underline?: boolean;
16
+ border?: {
17
+ top?: string[];
18
+ right?: string[];
19
+ bottom?: string[];
20
+ left?: string[];
21
+ };
22
+ }
23
+ interface XCellData {
24
+ text: string;
25
+ style?: number;
26
+ merge?: [number, number];
27
+ }
28
+ interface XRowData {
29
+ height?: number;
30
+ hide?: boolean;
31
+ cells: Record<string, XCellData>;
32
+ }
33
+ export interface XSheetData {
34
+ name: string;
35
+ styles?: XCellStyle[];
36
+ merges?: string[];
37
+ rows?: Record<string, XRowData>;
38
+ cols?: Record<string, {
39
+ width?: number;
40
+ hide?: boolean;
41
+ } | number>;
42
+ }
43
+ /**
44
+ * 规范化来自 HTTP/Blob 的 Excel 二进制数据。
45
+ * 某些网关会在 ZIP 文件前追加 BOM 或响应包装字节,ExcelJS 会因此解析失败。
46
+ */
47
+ export declare function normalizeExcelBuffer(data: ArrayBuffer | Uint8Array): Uint8Array;
48
+ /**
49
+ * 获取 x-data-spreadsheet 所需的行数。
50
+ * 保留默认最小行数,避免小表格失去原有的可视空白区域。
51
+ */
52
+ export declare function getSpreadsheetRowCount(sheets: readonly Pick<XSheetData, 'rows'>[], minimum?: number): number;
53
+ /**
54
+ * 将 exceljs Workbook 转换为 x-data-spreadsheet 数据格式
55
+ */
56
+ export declare function convertWorkbookToSpreadsheetData(workbook: Workbook): XSheetData[];
57
+ /**
58
+ * 将解析后的 CSV/TSV 数据转换为 x-data-spreadsheet 数据格式
59
+ */
60
+ export declare function convertCsvToSpreadsheetData(header: string[], rows: string[][], sheetName?: string): XSheetData[];
61
+ export {};
@@ -0,0 +1,21 @@
1
+ import { PreviewFile, PreviewFileInput } from '../types.js';
2
+ /**
3
+ * 从 URL 字符串中提取文件名
4
+ */
5
+ export declare function getFileNameFromUrl(url: string): string;
6
+ /**
7
+ * 从文件名中推断 MIME 类型
8
+ */
9
+ export declare function inferMimeType(fileName: string): string;
10
+ /**
11
+ * 标准化文件输入为 PreviewFile 格式
12
+ * 支持三种输入类型:
13
+ * 1. File 对象(原生浏览器 File)
14
+ * 2. PreviewFileLink 对象(包含 name, url, type 等属性)
15
+ * 3. string(HTTP URL)
16
+ */
17
+ export declare function normalizeFile(input: PreviewFileInput, index?: number): PreviewFile;
18
+ /**
19
+ * 批量标准化文件输入
20
+ */
21
+ export declare function normalizeFiles(inputs: PreviewFileInput[]): PreviewFile[];
@@ -0,0 +1,21 @@
1
+ import type { PreviewFile, FileType } from '../types.js';
2
+ /**
3
+ * 根据 PreviewFile 的 mime 类型和文件名后缀推断文件类型
4
+ */
5
+ export declare function getFileType(file: PreviewFile): FileType;
6
+ /**
7
+ * 根据文件名后缀推断代码高亮语言
8
+ */
9
+ export declare function getLanguageFromFileName(fileName: string): string;
10
+ /**
11
+ * 根据视频文件 URL 推断 MIME 类型(用于 video.js sources)
12
+ */
13
+ export declare function getVideoMimeType(url: string, mimeType?: string): string;
14
+ /**
15
+ * 格式化文件大小为人类可读格式
16
+ */
17
+ export declare function formatFileSize(bytes: number): string;
18
+ /**
19
+ * 格式化时长 (秒) 为 mm:ss
20
+ */
21
+ export declare function formatTime(time: number): string;
@@ -0,0 +1,25 @@
1
+ export interface LegacyDocTheme {
2
+ font: string;
3
+ size: number;
4
+ color: string;
5
+ titleFont: string;
6
+ titleSize: number;
7
+ titleColor: string;
8
+ headingFont: string;
9
+ heading2Size: number;
10
+ heading3Size: number;
11
+ heading3Color: string;
12
+ linkColor: string;
13
+ }
14
+ export interface LegacyDocPreview {
15
+ paragraphs: string[];
16
+ text: string;
17
+ theme?: LegacyDocTheme;
18
+ metadata?: {
19
+ title?: string;
20
+ author?: string;
21
+ wordCount?: number;
22
+ };
23
+ }
24
+ export declare function parseLegacyDoc(data: ArrayBuffer): LegacyDocPreview;
25
+ export declare function legacyDocToHtml(preview: LegacyDocPreview): string;
@@ -0,0 +1,8 @@
1
+ export type { LegacyDocPreview, LegacyDocTheme } from './doc.js';
2
+ export type { LegacyPptPreview, LegacyPptSlide, LegacyPptTheme, LegacyPptTable, LegacyPptSize, } from './ppt.js';
3
+ export type { LegacyXlsWorkbook, LegacyXlsSheet, LegacyXlsCell, LegacyXlsMerge } from './xls.js';
4
+ export { legacyDocToHtml, parseLegacyDoc } from './doc.js';
5
+ export { legacyPptToHtml, parseLegacyPpt } from './ppt.js';
6
+ export { parseLegacyXls, convertLegacyXlsToSpreadsheetData, isLegacyXls } from './xls.js';
7
+ export declare function renderLegacyDocHtml(data: ArrayBuffer): Promise<string>;
8
+ export declare function renderLegacyPptHtml(data: ArrayBuffer): Promise<string>;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Minimal OLE2 / Compound File Binary (MS-CFB) reader.
3
+ * Improved with better validation and error handling.
4
+ */
5
+ export declare function isOleCompoundFile(data: ArrayBuffer | Uint8Array): boolean;
6
+ export declare function readOleStream(data: ArrayBuffer | Uint8Array, streamName: string): Uint8Array | null;
7
+ export declare function readOleStreamAny(data: ArrayBuffer | Uint8Array, names: string[]): Uint8Array | null;
8
+ export declare function u8ToDataView(u8: Uint8Array): DataView;
@@ -0,0 +1,79 @@
1
+ export type PptTextRole = 'title' | 'subtitle' | 'body' | 'meta' | 'kicker';
2
+ export type PptSlideLayout = 'hero' | 'section' | 'content' | 'image' | 'table';
3
+ export type PptShapeKind = 'title' | 'subtitle' | 'body' | 'meta' | 'image' | 'table';
4
+ export interface LegacyPptImage {
5
+ data: string;
6
+ width?: number;
7
+ height?: number;
8
+ alt?: string;
9
+ mimeType?: string;
10
+ }
11
+ export interface LegacyPptTextBlock {
12
+ role: PptTextRole;
13
+ text: string;
14
+ textType?: number;
15
+ }
16
+ export interface LegacyPptTable {
17
+ cols: number;
18
+ rows: number;
19
+ cells: string[][];
20
+ }
21
+ export interface LegacyPptSlide {
22
+ index: number;
23
+ layout: PptSlideLayout;
24
+ blocks: LegacyPptTextBlock[];
25
+ images?: LegacyPptImage[];
26
+ table?: LegacyPptTable;
27
+ shapes?: LegacyPptShape[];
28
+ theme?: LegacyPptTheme;
29
+ }
30
+ export interface LegacyPptTheme {
31
+ brand: string;
32
+ onBrand: string;
33
+ surface: string;
34
+ title: string;
35
+ body: string;
36
+ accent: string;
37
+ background?: string;
38
+ font?: string;
39
+ titleFont?: string;
40
+ bodyFont?: string;
41
+ titleSize?: number;
42
+ bodySize?: number;
43
+ }
44
+ export interface LegacyPptSize {
45
+ width: number;
46
+ height: number;
47
+ }
48
+ export interface LegacyPptBox {
49
+ x: number;
50
+ y: number;
51
+ w: number;
52
+ h: number;
53
+ }
54
+ export interface LegacyPptParagraph {
55
+ text: string;
56
+ indent: number;
57
+ }
58
+ export interface LegacyPptShape {
59
+ kind: PptShapeKind;
60
+ box: LegacyPptBox;
61
+ center?: boolean;
62
+ narrow?: boolean;
63
+ wash?: boolean;
64
+ shadow?: boolean;
65
+ color?: string;
66
+ fontSize?: number;
67
+ fontFamily?: string;
68
+ text?: string;
69
+ paragraphs?: LegacyPptParagraph[];
70
+ image?: LegacyPptImage;
71
+ table?: LegacyPptTable;
72
+ }
73
+ export interface LegacyPptPreview {
74
+ slides: LegacyPptSlide[];
75
+ theme: LegacyPptTheme;
76
+ size: LegacyPptSize;
77
+ }
78
+ export declare function parseLegacyPpt(data: ArrayBuffer): LegacyPptPreview;
79
+ export declare function legacyPptToHtml(preview: LegacyPptPreview): string;
@@ -0,0 +1,28 @@
1
+ import type { XSheetData } from '../excelDataConverter.js';
2
+ export interface LegacyXlsCell {
3
+ row: number;
4
+ col: number;
5
+ text: string;
6
+ }
7
+ export interface LegacyXlsMerge {
8
+ rowFirst: number;
9
+ rowLast: number;
10
+ colFirst: number;
11
+ colLast: number;
12
+ }
13
+ export interface LegacyXlsSheet {
14
+ name: string;
15
+ hidden: boolean;
16
+ cells: LegacyXlsCell[];
17
+ merges: LegacyXlsMerge[];
18
+ colWidths: Map<number, number>;
19
+ rowHeights: Map<number, number>;
20
+ hiddenColumns?: Set<number>;
21
+ hiddenRows?: Set<number>;
22
+ }
23
+ export interface LegacyXlsWorkbook {
24
+ sheets: LegacyXlsSheet[];
25
+ }
26
+ export declare function isLegacyXls(data: ArrayBuffer | Uint8Array): boolean;
27
+ export declare function parseLegacyXls(data: ArrayBuffer | Uint8Array): LegacyXlsWorkbook;
28
+ export declare function convertLegacyXlsToSpreadsheetData(workbook: LegacyXlsWorkbook | null | undefined): XSheetData[];
@@ -0,0 +1,29 @@
1
+ /**
2
+ * 文件扩展名到 MIME 类型的映射表
3
+ * 包含标准格式和高级图片格式(HEIC/AVIF/TIFF/RAW/PSD等)
4
+ */
5
+ export declare const EXTENSION_TO_MIME: Record<string, string>;
6
+ /**
7
+ * 根据文件扩展名获取 MIME 类型
8
+ * @param extension 文件扩展名(不含点号)
9
+ * @returns MIME 类型字符串,未知时返回 'application/octet-stream'
10
+ */
11
+ export declare function getMimeTypeFromExtension(extension: string): string;
12
+ /**
13
+ * 根据文件名获取 MIME 类型
14
+ * @param fileName 文件名
15
+ * @returns MIME 类型字符串
16
+ */
17
+ export declare function getMimeTypeFromFileName(fileName: string): string;
18
+ /**
19
+ * 检测是否为高级图片格式(需要额外解码)
20
+ * @param mimeType MIME 类型
21
+ * @returns 是否为高级图片格式
22
+ */
23
+ export declare function isAdvancedImageFormat(mimeType: string): boolean;
24
+ /**
25
+ * 检测是否为 RAW 格式
26
+ * @param mimeType MIME 类型
27
+ * @returns 是否为 RAW 格式
28
+ */
29
+ export declare function isRawFormat(mimeType: string): boolean;
@@ -0,0 +1,17 @@
1
+ export interface DocxTheme {
2
+ font?: string;
3
+ size?: number;
4
+ color?: string;
5
+ titleFont?: string;
6
+ titleSize?: number;
7
+ titleColor?: string;
8
+ headingFont?: string;
9
+ heading1Size?: number;
10
+ heading2Size?: number;
11
+ heading3Size?: number;
12
+ heading3Color?: string;
13
+ linkColor?: string;
14
+ }
15
+ export declare const DOCX_MAMMOTH_STYLE_MAP: string[];
16
+ export declare function docxThemeToCssVars(theme: DocxTheme): Record<string, string>;
17
+ export declare function readDocxTheme(data: ArrayBuffer): Promise<DocxTheme>;
@@ -0,0 +1,4 @@
1
+ export { readDocxTheme, docxThemeToCssVars, DOCX_MAMMOTH_STYLE_MAP } from './docx.js';
2
+ export type { DocxTheme } from './docx.js';
3
+ export { readPptxSlideSize } from './pptx.js';
4
+ export type { PptxSlideSize } from './pptx.js';
@@ -0,0 +1,7 @@
1
+ export interface PptxSlideSize {
2
+ cx: number;
3
+ cy: number;
4
+ ratio: number;
5
+ }
6
+ /** Read `p:sldSz` from ppt/presentation.xml (EMU). Falls back to 16:9. */
7
+ export declare function readPptxSlideSize(data: ArrayBuffer): Promise<PptxSlideSize>;
@@ -0,0 +1,15 @@
1
+ /** Minimal XML tree parser for OOXML (namespace-tolerant, no DOM). */
2
+ export interface XmlNode {
3
+ name: string;
4
+ attrs: Record<string, string>;
5
+ children: XmlNode[];
6
+ text: string;
7
+ }
8
+ export declare function localName(name: string): string;
9
+ export declare function decodeEntities(value: string): string;
10
+ export declare function parseXml(xml: string): XmlNode;
11
+ export declare function kids(node: XmlNode, name: string): XmlNode[];
12
+ export declare function kid(node: XmlNode, name: string): XmlNode | undefined;
13
+ export declare function deepKids(node: XmlNode, name: string): XmlNode[];
14
+ export declare function attr(node: XmlNode, name: string): string | undefined;
15
+ export declare function textOf(node: XmlNode): string;
@@ -0,0 +1,3 @@
1
+ import type JSZip from 'jszip';
2
+ export declare function findZipEntry(zip: JSZip, suffix: string): string | null;
3
+ export declare function readZipTextLoose(zip: JSZip, suffix: string): Promise<string | null>;
@@ -0,0 +1,61 @@
1
+ /**
2
+ * PDF.js Worker 配置选项
3
+ */
4
+ export interface PdfWorkerOptions {
5
+ /**
6
+ * PDF.js worker 文件路径
7
+ * 默认使用 CDN
8
+ */
9
+ workerSrc?: string;
10
+ /**
11
+ * CMap 文件目录路径
12
+ * 默认使用 CDN
13
+ */
14
+ cMapUrl?: string;
15
+ /**
16
+ * 是否使用压缩的 CMap 文件
17
+ * 默认: true
18
+ */
19
+ cMapPacked?: boolean;
20
+ /**
21
+ * PDF.js 标准字体文件目录路径
22
+ * 默认使用 CDN
23
+ */
24
+ standardFontDataUrl?: string;
25
+ /**
26
+ * PDF.js WASM 文件目录路径(用于 JBIG2、JPEG 2000 等图像解码)
27
+ * 默认使用 CDN
28
+ */
29
+ wasmUrl?: string;
30
+ }
31
+ export interface PdfDocumentOptions {
32
+ cMapUrl: string;
33
+ cMapPacked: boolean;
34
+ standardFontDataUrl: string;
35
+ wasmUrl?: string;
36
+ }
37
+ /**
38
+ * 配置 PDF.js Worker 和文档资源参数(框架无关)
39
+ *
40
+ * @param pdfjs - pdfjs-dist 模块(由调用方传入,避免 core 包硬依赖 pdfjs-dist)
41
+ * @param options - 配置选项
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * import * as pdfjs from 'pdfjs-dist';
46
+ * import { configurePdfWorker } from '@eternalheart/file-preview-core';
47
+ *
48
+ * configurePdfWorker(pdfjs, {
49
+ * workerSrc: '/pdfjs/pdf.worker.min.mjs',
50
+ * cMapUrl: '/pdfjs/cmaps/',
51
+ * cMapPacked: true,
52
+ * standardFontDataUrl: '/pdfjs/standard_fonts/',
53
+ * wasmUrl: '/pdfjs/wasm/',
54
+ * });
55
+ * ```
56
+ */
57
+ export declare function configurePdfWorker(pdfjs: any, options?: PdfWorkerOptions): void;
58
+ /**
59
+ * 获取应传给 PDF.js getDocument 的资源配置。
60
+ */
61
+ export declare function getPdfDocumentOptions(): PdfDocumentOptions | null;
@@ -0,0 +1,7 @@
1
+ export type PreviewMode = 'modal' | 'embed';
2
+ /**
3
+ * 计算关闭按钮的实际显隐值(框架无关,React / Vue 两端共用)。
4
+ * - 显式传入 showClose 时以其为准
5
+ * - 未传时按 mode 取默认值:modal 显示,embed 隐藏
6
+ */
7
+ export declare function resolveShowClose(mode: PreviewMode | undefined, showClose?: boolean): boolean;
@@ -0,0 +1,49 @@
1
+ import type { Fetcher, FileContent, FileLoader, RequestOptions } from '../types.js';
2
+ /**
3
+ * 判断 URL 是否为库内已解析的本地资源(object URL / data URL)。
4
+ * 这类 URL 不需要也不能再经过用户的 requestInit / requestHandler。
5
+ */
6
+ export declare function isInlineResourceUrl(url: string): boolean;
7
+ /**
8
+ * 构造一个只负责注入 headers / RequestInit 的 FileLoader。
9
+ *
10
+ * 适合「只想补一个 Authorization / Cookie」的迁移场景:
11
+ * ```ts
12
+ * loadFile={withHeaders({ Authorization: `Bearer ${token}` })}
13
+ * ```
14
+ * 复杂逻辑(签名刷新、加解密、大文件直链)请直接写 `loadFile`。
15
+ * `init.signal` 会被组件传入的取消信号覆盖。
16
+ */
17
+ export declare function withHeaders(headers: HeadersInit, init?: RequestInit): FileLoader;
18
+ /**
19
+ * 把 FileLoader 的返回值转成可直接消费的 URL。
20
+ * - Blob:创建 `blob:` URL,并通过 `revoke` 交还释放责任;
21
+ * - `{ url }`:原样返回,`revoke` 为 null(生命周期由调用方管理)。
22
+ */
23
+ export declare function resolveConsumableUrl(content: FileContent): {
24
+ url: string;
25
+ revoke: (() => void) | null;
26
+ };
27
+ /**
28
+ * 构造一个统一的 fetcher:
29
+ * - 调用方 init 与外部 RequestInitFactory 合并(外部为底,调用方为优先级更高的覆盖层)
30
+ * - 提供 requestHandler 时由 handler 接管,否则走原生 fetch
31
+ * - 失败统一包装成 PreviewRequestError,并回调 options.onRequestError
32
+ * - 主动取消(AbortError)原样抛出,不视为失败
33
+ *
34
+ * 不传 options 时,等价于直接返回原生 fetch。
35
+ */
36
+ export declare function createFetcher(options?: RequestOptions): Fetcher;
37
+ /**
38
+ * 用 fetcher 把 URL 拉成 blob: URL,方便喂给 <img src> / <Document file> 等。
39
+ * 调用方负责在不再需要时 URL.revokeObjectURL(blobUrl)。
40
+ */
41
+ export declare function fetchAsBlobUrl(url: string, fetcher?: Fetcher, init?: RequestInit): Promise<string>;
42
+ /**
43
+ * 通过 fetcher 下载文件到本地:
44
+ * - 先用 fetcher 拉成 Blob(自动复用鉴权 init / handler)
45
+ * - createObjectURL → 触发 <a download> → revokeObjectURL
46
+ *
47
+ * 鉴权 URL 场景下,比直接 `<a href={url} download>` 更可靠(后者不带自定义 header)。
48
+ */
49
+ export declare function downloadFileWithFetcher(url: string, fileName: string, fetcher?: Fetcher, init?: RequestInit): Promise<void>;
@@ -0,0 +1,44 @@
1
+ /**
2
+ * 时间文本(字幕 / 歌词)解析器
3
+ * 支持:SRT、WebVTT、LRC、Enhanced LRC (ELRC)、ASS / SSA、TTML
4
+ * 不依赖任何第三方库
5
+ */
6
+ export type SubtitleFormat = 'srt' | 'vtt' | 'lrc' | 'elrc' | 'ass' | 'ssa' | 'ttml';
7
+ /** ELRC 的逐字时间戳片段 */
8
+ export interface SubtitleWord {
9
+ /** 该词起始时间(秒) */
10
+ start: number;
11
+ /** 词文本 */
12
+ text: string;
13
+ }
14
+ export interface SubtitleCue {
15
+ /** 索引(SRT 为数字字符串;VTT 可选;其他格式可空) */
16
+ id?: string;
17
+ /** 起始时间(秒) */
18
+ start: number;
19
+ /** 结束时间(秒) */
20
+ end: number;
21
+ /** 纯文本(多行合并,保留换行) */
22
+ text: string;
23
+ /** 增强歌词(ELRC)的逐字时间戳 */
24
+ words?: SubtitleWord[];
25
+ /** ASS / SSA 的样式名 */
26
+ style?: string;
27
+ }
28
+ export interface SubtitleParseResult {
29
+ format: SubtitleFormat;
30
+ cues: SubtitleCue[];
31
+ /** WebVTT / ASS 的头部注释或元数据(可选) */
32
+ header?: string;
33
+ /** LRC / ELRC 的元数据(ti / ar / al / by / offset / length 等) */
34
+ metadata?: Record<string, string>;
35
+ }
36
+ /**
37
+ * 格式化秒数为 HH:MM:SS.mmm
38
+ */
39
+ export declare function formatSubtitleTime(seconds: number): string;
40
+ /**
41
+ * 解析时间文本(字幕 / 歌词)。
42
+ * 自动识别格式,也可通过 format 参数显式指定。
43
+ */
44
+ export declare function parseSubtitle(text: string, format?: SubtitleFormat): SubtitleParseResult;
@@ -0,0 +1,30 @@
1
+ import type { Fetcher } from '../types.js';
2
+ /**
3
+ * 文本编码解码工具
4
+ * 自动检测 BOM → 严格 UTF-8 → GBK 降级,覆盖绝大多数中文文本场景
5
+ */
6
+ /**
7
+ * 智能解码:自动识别编码并解码为字符串
8
+ *
9
+ * 检测优先级:
10
+ * 1. BOM(UTF-8 / UTF-16 LE / UTF-16 BE)
11
+ * 2. 严格 UTF-8(`fatal: true`,所有字节均为合法 UTF-8 序列)
12
+ * 3. GBK(中文 Windows 常见默认编码,兼容 GB2312 / GBK / GB18030 子集)
13
+ * 4. 兜底:有损 UTF-8(替换非法字节为 U+FFFD)
14
+ */
15
+ export declare function decodeText(buffer: ArrayBuffer | Uint8Array): string;
16
+ /** @deprecated 请使用 decodeText,此别名保留兼容 */
17
+ export declare const decodeUtf8: typeof decodeText;
18
+ export interface FetchTextOptions {
19
+ fetcher?: Fetcher;
20
+ init?: RequestInit;
21
+ signal?: AbortSignal;
22
+ }
23
+ /**
24
+ * 从 URL fetch 文本资源,自动检测编码。
25
+ *
26
+ * 兼容两种调用方式:
27
+ * - `fetchTextUtf8(url, init)` —— 兼容旧 API
28
+ * - `fetchTextUtf8(url, { fetcher, init })` —— 注入自定义 fetcher(鉴权场景)
29
+ */
30
+ export declare function fetchTextUtf8(url: string, optionsOrInit?: FetchTextOptions | RequestInit): Promise<string>;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Uint8Array hex/base64 polyfill(ES2025 提案方法)
3
+ *
4
+ * 背景:pdfjs-dist 6.x 内部使用了 `Uint8Array.prototype.toHex` /
5
+ * `toBase64` / `fromBase64` 等 ES2025 提案方法。其 legacy 构建虽自带
6
+ * core-js polyfill,但这些 polyfill 是纯副作用模块,在 webpack/umi 等
7
+ * 二次打包环境下可能被 tree-shake 或延迟执行,导致运行时报错:
8
+ * `TypeError: a.toHex is not a function`
9
+ * `Uint8Array.fromBase64 is not a function`
10
+ *
11
+ * 本函数主动、幂等地安装这组方法。必须在使用 pdfjs 之前调用(运行时函数
12
+ * 调用无法被 tree-shake)。仅当原生/pdfjs 未提供时才写入,不覆盖已存在实现。
13
+ */
14
+ /**
15
+ * 安装 Uint8Array hex/base64 方法(幂等)。
16
+ * 仅在对应方法缺失时写入,已存在的原生实现不会被覆盖。
17
+ */
18
+ export declare function installUint8ArrayHexBase64Polyfill(): void;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * ZIP 工具:基于 jszip 读取压缩包结构
3
+ * 仅做 framework-agnostic 的读取与分类,渲染交由 renderer 自行处理
4
+ */
5
+ import JSZip from 'jszip';
6
+ export interface ZipEntryInfo {
7
+ /** 完整路径(以 / 分隔,目录带尾部 /) */
8
+ path: string;
9
+ /** 文件名(不含路径) */
10
+ name: string;
11
+ /** 所在目录路径(不含尾部 /) */
12
+ dir: string;
13
+ /** 是否目录 */
14
+ isDir: boolean;
15
+ /** 未压缩大小(字节),目录为 0 */
16
+ size: number;
17
+ /** 最后修改时间 */
18
+ date?: Date;
19
+ }
20
+ export interface ZipTreeNode {
21
+ /** 名称(不含父路径) */
22
+ name: string;
23
+ /** 完整路径(目录带尾部 /) */
24
+ path: string;
25
+ /** 是否目录 */
26
+ isDir: boolean;
27
+ /** 子节点(仅目录) */
28
+ children?: ZipTreeNode[];
29
+ /** 文件大小 */
30
+ size: number;
31
+ }
32
+ /**
33
+ * 从 ArrayBuffer 加载 zip
34
+ */
35
+ export declare function loadZip(buffer: ArrayBuffer): Promise<JSZip>;
36
+ /**
37
+ * 列出所有条目(平铺)
38
+ */
39
+ export declare function listZipEntries(zip: JSZip): ZipEntryInfo[];
40
+ /**
41
+ * 将平铺的条目组织为树
42
+ */
43
+ export declare function buildZipTree(entries: ZipEntryInfo[]): ZipTreeNode;
44
+ /**
45
+ * 读取某个 zip 条目为文本(强制 UTF-8 解码)
46
+ */
47
+ export declare function readZipEntryText(zip: JSZip, path: string): Promise<string>;
48
+ /**
49
+ * 读取某个 zip 条目为 Blob(用于图片/媒体/PDF 等)
50
+ */
51
+ export declare function readZipEntryBlob(zip: JSZip, path: string, mimeType?: string): Promise<Blob>;