@eternalheart/vue-file-preview 1.6.13 → 1.7.0

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 (125) hide show
  1. package/README.md +2 -0
  2. package/README.zh-CN.md +2 -0
  3. package/lib/FilePreviewContent.vue.d.ts +17 -6
  4. package/lib/FilePreviewEmbed.vue.d.ts +14 -6
  5. package/lib/FilePreviewModal.vue.d.ts +14 -6
  6. package/lib/chunks/{EmptyState.vue_vue_type_script_setup_true_lang-C7qk6wj0.mjs → EmptyState.vue_vue_type_script_setup_true_lang--ZOobbGi.mjs} +1 -1
  7. package/lib/chunks/{avifLoader-CAUzjn-d-C0KRpetN.mjs → avifLoader-CAUzjn-d-CnJpGYJ2.mjs} +1 -1
  8. package/lib/chunks/{heicLoader-D_9PukkA-Czof_5FJ.mjs → heicLoader-D_9PukkA-g_dLrWLP.mjs} +1 -1
  9. package/lib/chunks/index-6XZXYqbp.mjs +125 -0
  10. package/lib/chunks/{index-B21EAyWz.mjs → index-BPSzwMOC.mjs} +51 -51
  11. package/lib/chunks/index-BYQ9S7Mk.mjs +104 -0
  12. package/lib/chunks/{index-8Vpbg2kS.mjs → index-Bf94DwQu.mjs} +105 -104
  13. package/lib/chunks/index-BfOWoMpY.mjs +359 -0
  14. package/lib/chunks/index-Bg8poMIm.mjs +117 -0
  15. package/lib/chunks/index-BzwJ0VWu.mjs +108 -0
  16. package/lib/chunks/index-C41YET0_.mjs +51 -0
  17. package/lib/chunks/{index-BvBqDq3O.mjs → index-C4hIk6pa.mjs} +2023 -2023
  18. package/lib/chunks/{index-BASg1cr4.mjs → index-C8lyQPe3.mjs} +1018 -1018
  19. package/lib/chunks/{index-C9mAajbD.mjs → index-CWPdNhoe.mjs} +200 -200
  20. package/lib/chunks/{index-BuqPb5mP.mjs → index-CrVQPnFj.mjs} +112 -112
  21. package/lib/chunks/{index-D30L8tm9.mjs → index-D5IF9F-D.mjs} +57 -57
  22. package/lib/chunks/{index-DN4Ui0Gh.mjs → index-DFeKS8tR.mjs} +120 -120
  23. package/lib/chunks/index-DM8Dfl-m.mjs +52 -0
  24. package/lib/chunks/index-DZe0BxAB.mjs +90 -0
  25. package/lib/chunks/{index-BlrFFeqc.mjs → index-GFcSJEwj.mjs} +75 -75
  26. package/lib/chunks/{index-Dkro_8Fy.mjs → index-LPGxJDnT.mjs} +32 -32
  27. package/lib/chunks/index-aKiIuKKx.mjs +157 -0
  28. package/lib/chunks/{index-DZZN3kYi.mjs → index-c-pYJEmH.mjs} +1589 -1394
  29. package/lib/chunks/{index-CxKZKUJj.mjs → index-z9RqL2wI.mjs} +1651 -1651
  30. package/lib/chunks/index-zLQlyNR2.mjs +383 -0
  31. package/lib/chunks/{jp2Loader-Dig19xyo-CKUaGhPl.mjs → jp2Loader-Dig19xyo-fCO1knZ0.mjs} +1 -1
  32. package/lib/chunks/{psdLoader-C0tKUXXl-CYWoQis5.mjs → psdLoader-C0tKUXXl-DihMskai.mjs} +1 -1
  33. package/lib/chunks/{rawLoader-C-tPeFAB-C35zC8nZ.mjs → rawLoader-C-tPeFAB-BSfDPl-z.mjs} +5 -5
  34. package/lib/chunks/{tiffLoader-BlhByX8w-BOxg_Du5.mjs → tiffLoader-BlhByX8w-JY5DaTre.mjs} +1 -1
  35. package/lib/chunks/{useShikiHighlight-BPmcxA-h.mjs → useShikiHighlight-C-ztcJBE.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 +52 -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-BB0i4QqI.mjs +0 -117
  118. package/lib/chunks/index-BVdrGK3Q.mjs +0 -356
  119. package/lib/chunks/index-Bp9CuvMZ.mjs +0 -157
  120. package/lib/chunks/index-Bxpf9v5j.mjs +0 -104
  121. package/lib/chunks/index-CDg6vIbT.mjs +0 -51
  122. package/lib/chunks/index-CWE-hKSs.mjs +0 -90
  123. package/lib/chunks/index-CY3xzGgt.mjs +0 -108
  124. package/lib/chunks/index-VdzIFJJW.mjs +0 -118
  125. package/lib/chunks/index-aoXgVLBb.mjs +0 -52
@@ -1,4 +1,4 @@
1
- import { k as i } from "./index-DZZN3kYi.mjs";
1
+ import { J as i } from "./index-c-pYJEmH.mjs";
2
2
  class f {
3
3
  async needsDecode(t) {
4
4
  return t === "image/vnd.adobe.photoshop";
@@ -1,5 +1,5 @@
1
- import { k as b } from "./index-DZZN3kYi.mjs";
2
- const k = /* @__PURE__ */ new Set([
1
+ import { J as b } from "./index-c-pYJEmH.mjs";
2
+ const B = /* @__PURE__ */ new Set([
3
3
  "image/x-canon-cr2",
4
4
  "image/x-nikon-nef",
5
5
  "image/x-sony-arw",
@@ -53,9 +53,9 @@ function m(a) {
53
53
  }
54
54
  return e >= 0 && i > e ? new Blob([a.slice(e, i)], { type: "image/jpeg" }) : null;
55
55
  }
56
- class B {
56
+ class j {
57
57
  async needsDecode(e) {
58
- return k.has(e);
58
+ return B.has(e);
59
59
  }
60
60
  async decode(e, i) {
61
61
  const l = e instanceof Blob ? await e.arrayBuffer() : e;
@@ -76,7 +76,7 @@ class B {
76
76
  };
77
77
  }
78
78
  }
79
- const _ = new B();
79
+ const _ = new j();
80
80
  export {
81
81
  _ as default
82
82
  };
@@ -1,4 +1,4 @@
1
- import { k as i } from "./index-DZZN3kYi.mjs";
1
+ import { J as i } from "./index-c-pYJEmH.mjs";
2
2
  class p {
3
3
  /**
4
4
  * TIFF 浏览器均不原生支持(除 Safari 部分版本),始终需要解码
@@ -1,6 +1,6 @@
1
1
  import { ref as i, watch as c } from "vue";
2
2
  import { codeToHtml as h } from "shiki";
3
- import { g as f } from "./index-DZZN3kYi.mjs";
3
+ import { g as f } from "./index-c-pYJEmH.mjs";
4
4
  function T(t, n) {
5
5
  const a = f(), e = i(""), r = i([]), l = i(!0);
6
6
  return c([t, n, a], async () => {
@@ -1,5 +1,5 @@
1
1
  import { type Ref } from 'vue';
2
- import { formatTime } from '@eternalheart/file-preview-core';
2
+ import { formatTime } from '../core/index.js';
3
3
  /**
4
4
  * Vue 3 版本的音频播放器 composable
5
5
  * 与 React 版的 useAudioPlayer 行为对齐
@@ -0,0 +1,27 @@
1
+ import { type PreviewErrorPayload, type PreviewErrorStage, type PreviewFile, type PreviewReporter } from '../core/index.js';
2
+ /** 顶层聚合时补齐的上下文。 */
3
+ export interface PreviewEventsHostContext {
4
+ /** 当前文件 */
5
+ file?: PreviewFile;
6
+ /** 当前索引 */
7
+ index: number;
8
+ /** 本代次可接受的 URL 集合(原始 URL 与 resolved URL) */
9
+ urls: string[];
10
+ }
11
+ export interface PreviewEventsHost {
12
+ /** 供内置渲染器上报的通道 */
13
+ reporter: PreviewReporter;
14
+ /** 顶层自用:补上下文 + 代次校验 + 去重后派发 */
15
+ report: (error: unknown, stage?: PreviewErrorStage, cause?: unknown) => void;
16
+ /** 切换文件时重置去重状态 */
17
+ reset: () => void;
18
+ }
19
+ /**
20
+ * 提供预览事件通道。
21
+ * - 渲染器通过 usePreviewEvents() 取 reporter 上报;
22
+ * - 顶层通过返回值里的 report 直接上报(请求层、错误边界等);
23
+ * - 去重与代次校验在这里统一完成,宿主只会收到干净的 payload。
24
+ */
25
+ export declare function providePreviewEvents(getContext: () => PreviewEventsHostContext, dispatch: (payload: PreviewErrorPayload) => void): PreviewEventsHost;
26
+ /** 渲染器侧使用;未接入事件通道时返回 noop。 */
27
+ export declare function usePreviewEvents(): PreviewReporter;
@@ -1,23 +1,35 @@
1
1
  import { type ComputedRef, type Ref } from 'vue';
2
- import type { Fetcher, PreviewFile, RequestHandler, RequestInitFactory, ShouldFetchAsBlob } from '@eternalheart/file-preview-core';
2
+ import type { Fetcher, FileLoader, PreviewFile, RequestHandler, RequestInitFactory, ShouldFetchAsBlob } from '../core/index.js';
3
3
  export interface RequestContextValue {
4
4
  fetcher: Fetcher;
5
+ loadFile?: FileLoader;
5
6
  shouldFetchAsBlob?: ShouldFetchAsBlob;
6
7
  }
7
8
  export declare function provideRequestContext(options: {
9
+ loadFile?: FileLoader;
8
10
  requestInit?: RequestInitFactory;
9
11
  requestHandler?: RequestHandler;
10
12
  shouldFetchAsBlob?: ShouldFetchAsBlob;
13
+ onRequestError?: (url: string, error: unknown) => void;
11
14
  } | (() => {
15
+ loadFile?: FileLoader;
12
16
  requestInit?: RequestInitFactory;
13
17
  requestHandler?: RequestHandler;
14
18
  shouldFetchAsBlob?: ShouldFetchAsBlob;
19
+ onRequestError?: (url: string, error: unknown) => void;
15
20
  })): ComputedRef<RequestContextValue>;
16
21
  export declare function useRequestContext(): ComputedRef<RequestContextValue>;
17
22
  export declare function useFetcher(): ComputedRef<Fetcher>;
23
+ declare const DEPRECATED_REQUEST_PROPS: readonly ["requestInit", "requestHandler", "shouldFetchAsBlob"];
24
+ /** 过渡期提示:旧鉴权参数已废弃,1.8.0 移除。 */
25
+ export declare function warnDeprecatedRequestProps(used: Partial<Record<(typeof DEPRECATED_REQUEST_PROPS)[number], unknown>>): void;
18
26
  /**
19
27
  * 解析 file 的可消费 URL:
20
- * - 未配置 shouldFetchAsBlob 或返回 false:直接派生自 file.url(不入 ref,避免切换文件时残留旧值)
21
- * - 返回 true:用 fetcher 拉成 blob: URL,组件卸载或 file 变化时 revoke
28
+ * - 配置了 loadFile 且是远程可预览文件:由宿主取数,Blob 转 blob: URL,`{ url }` 直接使用;
29
+ * - 未配置 loadFile、shouldFetchAsBlob 返回 true:用 fetcher 拉成 blob: URL;
30
+ * - 其余:直接派生自 file.url(不入 ref,避免切换文件时残留旧值)
31
+ *
32
+ * onError 用于把取数失败上报给宿主(默认仍回退原 URL 继续尝试)。
22
33
  */
23
- export declare function useResolvedUrl(file: Ref<PreviewFile | undefined>): ComputedRef<string>;
34
+ export declare function useResolvedUrl(file: Ref<PreviewFile | undefined>, onError?: (error: unknown) => void): ComputedRef<string>;
35
+ export {};
@@ -1,3 +1,3 @@
1
1
  import { type ComputedRef, type Ref } from 'vue';
2
- import type { Theme } from '@eternalheart/file-preview-core';
2
+ import type { Theme } from '../core/index.js';
3
3
  export declare function useThemeMode(theme: Ref<Theme>): ComputedRef<'dark' | 'light'>;
@@ -1,6 +1,6 @@
1
1
  import { type Ref, type MaybeRef, type ComputedRef } from 'vue';
2
- import { type Locale, type Messages, type Translator } from '@eternalheart/file-preview-core';
3
- import { type LocaleInjection } from '../i18n/localeKey';
2
+ import { type Locale, type Messages, type Translator } from '../core/index.js';
3
+ import { type LocaleInjection } from '../i18n/localeKey.js';
4
4
  /**
5
5
  * 在主组件中调用,向子树注入 locale context
6
6
  */
@@ -0,0 +1,52 @@
1
+ import { PreviewError } from './i18n/index.js';
2
+ import type { PreviewFile } from './types.js';
3
+ /** 失败发生的阶段:取数 / 解析 / 渲染。 */
4
+ export type PreviewErrorStage = 'request' | 'parse' | 'render';
5
+ /**
6
+ * 加载或渲染失败时对外派发的载荷。
7
+ * 框架无关:React / Vue / Angular 三端共用同一形状。
8
+ */
9
+ export interface PreviewErrorPayload {
10
+ /** 失败所属文件(顶层已按当前文件补齐)。 */
11
+ file: PreviewFile;
12
+ /** 失败所属文件在 files 中的索引。 */
13
+ index: number;
14
+ /** 原始异常(未经包装),便于宿主上报监控与自行判别。 */
15
+ error: unknown;
16
+ /** 失败阶段。 */
17
+ stage: PreviewErrorStage;
18
+ /** 框架侧补充的诊断信息(如 React ErrorInfo),其他端可能为空。 */
19
+ cause?: unknown;
20
+ }
21
+ /**
22
+ * 请求阶段异常标记。
23
+ * 由 createFetcher 统一包装抛出,渲染器 catch 后无需判断即可让 stage
24
+ * 自动推断为 'request',避免逐个渲染器改造两侧 try/catch。
25
+ *
26
+ * 包装时保留内层 PreviewError 的 key/params,并覆盖 message 为原始异常信息,
27
+ * 保证既有日志与断言(如 "Request failed: 404")不受影响。
28
+ */
29
+ export declare class PreviewRequestError extends PreviewError {
30
+ readonly cause: unknown;
31
+ constructor(cause: unknown);
32
+ }
33
+ /**
34
+ * 推断失败阶段:
35
+ * - 显式传入 stage 时优先采用;
36
+ * - 请求包装异常推断为 'request';
37
+ * - 响应状态类 key(HTTP 非 2xx)推断为 'request';
38
+ * - 其余一律视为 'parse'。
39
+ */
40
+ export declare function resolveErrorStage(error: unknown, explicit?: PreviewErrorStage): PreviewErrorStage;
41
+ /**
42
+ * 渲染器侧最小上报口。
43
+ * - begin(url):标记本次加载对应的 URL,供顶层做代次校验,防止切换文件后
44
+ * 旧渲染器的迟到回调被误归属到新文件。
45
+ * - error(err, stage?):上报失败,stage 缺省时按 resolveErrorStage 推断。
46
+ */
47
+ export interface PreviewReporter {
48
+ begin(url: string): void;
49
+ error(error: unknown, stage?: PreviewErrorStage): void;
50
+ }
51
+ /** 未接入事件通道时的占位实现,保证渲染器可无条件调用。 */
52
+ export declare const noopReporter: PreviewReporter;
@@ -0,0 +1,29 @@
1
+ import type { CreateTranslatorOptions, MessageKey, TranslateParams, Translator } from './types.js';
2
+ import { builtInMessages } from './messages/index.js';
3
+ /**
4
+ * 创建一个翻译函数(纯函数,零依赖)。
5
+ *
6
+ * - locale 命中失败时会兜底到 `fallbackLocale`(默认 'en-US')
7
+ * - userMessages 浅合并到内置字典之上,可覆盖任何 key
8
+ * - 翻译值中的 `{param}` 会被对应参数替换
9
+ * - 完全找不到 key 时返回 key 本身,方便排错
10
+ */
11
+ export declare function createTranslator(options: CreateTranslatorOptions): Translator;
12
+ export { builtInMessages };
13
+ /** 可跨 Worker 传递的错误信息。 */
14
+ export type PreviewErrorDetail = string | PreviewErrorData | PreviewErrorDetail[];
15
+ export interface PreviewErrorData {
16
+ key: MessageKey;
17
+ params?: TranslateParams;
18
+ detail?: PreviewErrorDetail;
19
+ }
20
+ export declare function serializeError(error: unknown): PreviewErrorDetail;
21
+ /** 底层保留词典键和参数,由调用方按自己的 locale 翻译。 */
22
+ export declare function translateError(t: Translator, error: unknown): string;
23
+ export declare class PreviewError extends Error implements PreviewErrorData {
24
+ readonly key: MessageKey;
25
+ readonly params?: TranslateParams | undefined;
26
+ readonly detail?: PreviewErrorDetail;
27
+ constructor(key: MessageKey, params?: TranslateParams | undefined, detail?: unknown);
28
+ }
29
+ export type { Locale, MessageKey, Messages, TranslateParams, Translator, CreateTranslatorOptions, } from './types.js';
@@ -0,0 +1,5 @@
1
+ import type { Messages } from '../types.js';
2
+ /**
3
+ * Built-in English (en-US) dictionary
4
+ */
5
+ export declare const enUS: Messages;
@@ -0,0 +1,9 @@
1
+ import type { Locale, Messages } from '../types.js';
2
+ import { zhCN } from './zh-CN.js';
3
+ import { enUS } from './en-US.js';
4
+ /**
5
+ * 内置语言字典
6
+ * 字典权威源 — 两个 framework 包都从这里 import,杜绝双框架字典脱钩
7
+ */
8
+ export declare const builtInMessages: Record<Locale, Messages>;
9
+ export { zhCN, enUS };
@@ -0,0 +1,5 @@
1
+ import type { Messages } from '../types.js';
2
+ /**
3
+ * 内置中文字典
4
+ */
5
+ export declare const zhCN: Messages;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * 国际化(i18n)类型定义
3
+ * 框架无关,零依赖
4
+ */
5
+ /** 内置 zh-CN / en-US,也允许任意自定义 locale 字符串 */
6
+ export type Locale = 'zh-CN' | 'en-US' | (string & {});
7
+ /** 翻译 key(点号分组的扁平字符串,如 'toolbar.zoom_in') */
8
+ export type MessageKey = string;
9
+ /** 单个语言的字典:key → 翻译值(值中可包含 {param} 形式占位) */
10
+ export type Messages = Record<MessageKey, string>;
11
+ /** 翻译参数(用于 {param} 插值) */
12
+ export type TranslateParams = Record<string, string | number>;
13
+ /** 翻译函数 */
14
+ export type Translator = (key: MessageKey, params?: TranslateParams) => string;
15
+ /** createTranslator 选项 */
16
+ export interface CreateTranslatorOptions {
17
+ /** 当前语言 */
18
+ locale: Locale;
19
+ /** 用户自定义字典,浅合并到内置字典之上 */
20
+ messages?: Partial<Record<Locale, Partial<Messages>>>;
21
+ /** locale 命中失败时的兜底语言,默认 'en-US' */
22
+ fallbackLocale?: Locale;
23
+ }
@@ -0,0 +1,34 @@
1
+ export type { PreviewFile, PreviewFileLink, PreviewFileInput, FileType, PreviewState, Theme, CustomRendererEventPayload, RequestHandler, RequestInitFactory, RequestOptions, Fetcher, ShouldFetchAsBlob, FileContent, FileLoader, } from './types.js';
2
+ export { SUPPORTED_FILE_TYPES } from './types.js';
3
+ export { normalizeFile, normalizeFiles, getFileNameFromUrl, inferMimeType, } from './utils/fileNormalizer.js';
4
+ export { resolveShowClose } from './utils/previewMode.js';
5
+ export type { PreviewMode } from './utils/previewMode.js';
6
+ export { isEmptyContent, resolveEmptyHint } from './utils/emptyState.js';
7
+ export type { EmptyHintMode, EmptyContentKind } from './utils/emptyState.js';
8
+ export { getFileType, getLanguageFromFileName, getVideoMimeType, formatFileSize, formatTime, } from './utils/fileType.js';
9
+ export { parseCsv, guessCsvDelimiter } from './utils/csvParser.js';
10
+ export type { CsvParseOptions, CsvParseResult } from './utils/csvParser.js';
11
+ export { decodeText, decodeUtf8, fetchTextUtf8 } from './utils/textDecoder.js';
12
+ export type { FetchTextOptions } from './utils/textDecoder.js';
13
+ export { createFetcher, fetchAsBlobUrl, downloadFileWithFetcher, isInlineResourceUrl, resolveConsumableUrl, withHeaders, } from './utils/request.js';
14
+ export { PreviewRequestError, resolveErrorStage, noopReporter, } from './events.js';
15
+ export type { PreviewErrorStage, PreviewErrorPayload, PreviewReporter, } from './events.js';
16
+ export { parseSubtitle, formatSubtitleTime } from './utils/subtitleParser.js';
17
+ export type { SubtitleCue, SubtitleWord, SubtitleParseResult, SubtitleFormat, } from './utils/subtitleParser.js';
18
+ export { loadZip, listZipEntries, buildZipTree, readZipEntryText, readZipEntryBlob, } from './utils/zipReader.js';
19
+ export type { ZipEntryInfo, ZipTreeNode } from './utils/zipReader.js';
20
+ export { convertWorkbookToSpreadsheetData, convertCsvToSpreadsheetData, getSpreadsheetRowCount, normalizeExcelBuffer, } from './utils/excelDataConverter.js';
21
+ export type { XSheetData } from './utils/excelDataConverter.js';
22
+ export { parseLegacyDoc, legacyDocToHtml, renderLegacyDocHtml, parseLegacyPpt, legacyPptToHtml, renderLegacyPptHtml, parseLegacyXls, convertLegacyXlsToSpreadsheetData, isLegacyXls, } from './utils/legacy-office/index.js';
23
+ export type { LegacyDocPreview, LegacyDocTheme, LegacyPptPreview, LegacyPptSlide, LegacyPptTheme, LegacyPptTable, LegacyPptSize, LegacyXlsWorkbook, LegacyXlsSheet, LegacyXlsCell, LegacyXlsMerge, } from './utils/legacy-office/index.js';
24
+ export { readDocxTheme, docxThemeToCssVars, DOCX_MAMMOTH_STYLE_MAP, readPptxSlideSize } from './utils/ooxml/index.js';
25
+ export type { DocxTheme, PptxSlideSize } from './utils/ooxml/index.js';
26
+ export { configurePdfWorker, getPdfDocumentOptions } from './utils/pdfWorker.js';
27
+ export type { PdfWorkerOptions, PdfDocumentOptions } from './utils/pdfWorker.js';
28
+ export { installUint8ArrayHexBase64Polyfill } from './utils/uint8ArrayPolyfill.js';
29
+ export { createTranslator, builtInMessages, PreviewError, translateError } from './i18n/index.js';
30
+ export type { Locale, MessageKey, Messages, TranslateParams, Translator, CreateTranslatorOptions, } from './i18n/types.js';
31
+ export { EXTENSION_TO_MIME, getMimeTypeFromExtension, getMimeTypeFromFileName, isAdvancedImageFormat, isRawFormat, } from './utils/mimeTypes.js';
32
+ export { registerLoader, getLoader, hasLoader, getLoaderForMimeType, detectImageFormat, } from './loaders/registry.js';
33
+ export type { ImageDecoder, DecodeOptions, ImageMetadata, LoaderRegistry, } from './loaders/types.js';
34
+ export { shouldUseWorker, decodeInWorker } from './workers/workerClient.js';
@@ -0,0 +1,22 @@
1
+ import type { ImageDecoder, DecodeOptions, ImageMetadata } from './types.js';
2
+ /**
3
+ * AVIF 图片解码器
4
+ * 现代浏览器(Chrome 85+、Firefox 93+、Safari 16+)已原生支持 AVIF
5
+ * 不支持时降级到 WASM 解码
6
+ */
7
+ declare class AvifLoader implements ImageDecoder {
8
+ /**
9
+ * 检测是否需要解码:仅在浏览器不原生支持 AVIF 时需要
10
+ */
11
+ needsDecode(mimeType: string): Promise<boolean>;
12
+ /**
13
+ * 解码 AVIF 文件为 PNG Blob
14
+ */
15
+ decode(file: Blob | ArrayBuffer, options?: DecodeOptions): Promise<Blob>;
16
+ /**
17
+ * 获取 AVIF 元数据
18
+ */
19
+ getMetadata(_file: Blob | ArrayBuffer): Promise<ImageMetadata>;
20
+ }
21
+ declare const _default: AvifLoader;
22
+ export default _default;
@@ -0,0 +1,21 @@
1
+ import type { ImageDecoder, DecodeOptions, ImageMetadata } from './types.js';
2
+ /**
3
+ * HEIC/HEIF 图片解码器
4
+ * 基于 heic2any 库,将 HEIC 格式转换为 JPEG
5
+ */
6
+ declare class HeicLoader implements ImageDecoder {
7
+ /**
8
+ * HEIC 格式浏览器均不原生支持,始终需要解码
9
+ */
10
+ needsDecode(mimeType: string): Promise<boolean>;
11
+ /**
12
+ * 解码 HEIC 文件为 JPEG Blob
13
+ */
14
+ decode(file: Blob | ArrayBuffer, options?: DecodeOptions): Promise<Blob>;
15
+ /**
16
+ * 获取 HEIC 元数据(当前版本暂不实现,返回空对象)
17
+ */
18
+ getMetadata(_file: Blob | ArrayBuffer): Promise<ImageMetadata>;
19
+ }
20
+ declare const _default: HeicLoader;
21
+ export default _default;
@@ -0,0 +1,16 @@
1
+ import type { ImageDecoder, DecodeOptions, ImageMetadata } from './types.js';
2
+ /**
3
+ * JPEG 2000 图片解码器
4
+ *
5
+ * 解码路径:
6
+ * 1. Safari 原生支持 → 直接返回原文件
7
+ * 2. Worker(jpeg2000 → OpenJPEG WASM 内部回退)→ 主线程不阻塞,CSS 动画流畅
8
+ * 3. 主线程仅承担 Canvas 渲染(毫秒级,不影响动画)
9
+ */
10
+ declare class Jp2Loader implements ImageDecoder {
11
+ needsDecode(mimeType: string): Promise<boolean>;
12
+ decode(file: Blob | ArrayBuffer, options?: DecodeOptions): Promise<Blob>;
13
+ getMetadata(_file: Blob | ArrayBuffer): Promise<ImageMetadata>;
14
+ }
15
+ declare const _default: Jp2Loader;
16
+ export default _default;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ import type { ImageDecoder, DecodeOptions, ImageMetadata } from './types.js';
2
+ /**
3
+ * PSD (Adobe Photoshop) 图片解码器
4
+ *
5
+ * 基于 ag-psd 库解析 PSD 文件,提取合并后的预览图层。
6
+ * 不解析图层结构、文字图层、调整层效果——仅展示最终合并效果。
7
+ */
8
+ declare class PsdLoader implements ImageDecoder {
9
+ needsDecode(mimeType: string): Promise<boolean>;
10
+ decode(file: Blob | ArrayBuffer, options?: DecodeOptions): Promise<Blob>;
11
+ getMetadata(file: Blob | ArrayBuffer): Promise<ImageMetadata>;
12
+ }
13
+ declare const _default: PsdLoader;
14
+ export default _default;
@@ -0,0 +1,14 @@
1
+ import type { ImageDecoder, DecodeOptions, ImageMetadata } from './types.js';
2
+ /**
3
+ * RAW 图片解码器
4
+ *
5
+ * 默认模式:提取嵌入的 JPEG 缩略图(快速、零依赖)
6
+ * 完整模式:暂未集成 RAW 完整像素解码引擎,自动退回到嵌入预览
7
+ */
8
+ declare class RawLoader implements ImageDecoder {
9
+ needsDecode(mimeType: string): Promise<boolean>;
10
+ decode(file: Blob | ArrayBuffer, options?: DecodeOptions): Promise<Blob>;
11
+ getMetadata(_file: Blob | ArrayBuffer): Promise<ImageMetadata>;
12
+ }
13
+ declare const _default: RawLoader;
14
+ export default _default;
@@ -0,0 +1,32 @@
1
+ import type { ImageDecoder } from './types.js';
2
+ import type { PreviewFile } from '../types.js';
3
+ /**
4
+ * 注册一个图片解码器
5
+ * @param mimeType MIME 类型
6
+ * @param loader 解码器实例
7
+ */
8
+ export declare function registerLoader(mimeType: string, loader: ImageDecoder): void;
9
+ /**
10
+ * 获取指定 MIME 类型的 loader
11
+ * @param mimeType MIME 类型
12
+ * @returns loader 实例,未注册时返回 null
13
+ */
14
+ export declare function getLoader(mimeType: string): ImageDecoder | null;
15
+ /**
16
+ * 检查是否有指定 MIME 类型的 loader
17
+ * @param mimeType MIME 类型
18
+ * @returns 是否已注册
19
+ */
20
+ export declare function hasLoader(mimeType: string): boolean;
21
+ /**
22
+ * 动态加载并获取指定 MIME 类型的 loader
23
+ * @param mimeType MIME 类型
24
+ * @returns loader 实例,不支持时返回 null
25
+ */
26
+ export declare function getLoaderForMimeType(mimeType: string): Promise<ImageDecoder | null>;
27
+ /**
28
+ * 检测图片格式(优先级:MIME type > 扩展名 > 文件头魔数)
29
+ * @param file 文件对象
30
+ * @returns MIME 类型字符串
31
+ */
32
+ export declare function detectImageFormat(file: File | PreviewFile): Promise<string>;
@@ -0,0 +1,28 @@
1
+ import type { ImageDecoder, DecodeOptions, ImageMetadata } from './types.js';
2
+ /**
3
+ * TIFF 解码选项扩展(支持多页)
4
+ */
5
+ interface TiffDecodeOptions extends DecodeOptions {
6
+ /** 页码(1-based,默认 1) */
7
+ page?: number;
8
+ }
9
+ /**
10
+ * TIFF 图片解码器
11
+ * 基于 utif (UTIF.js) 库,支持单页和多页 TIFF
12
+ */
13
+ declare class TiffLoader implements ImageDecoder {
14
+ /**
15
+ * TIFF 浏览器均不原生支持(除 Safari 部分版本),始终需要解码
16
+ */
17
+ needsDecode(mimeType: string): Promise<boolean>;
18
+ /**
19
+ * 解码 TIFF 文件为 PNG Blob
20
+ */
21
+ decode(file: Blob | ArrayBuffer, options?: TiffDecodeOptions): Promise<Blob>;
22
+ /**
23
+ * 获取 TIFF 元数据(包括页数)
24
+ */
25
+ getMetadata(file: Blob | ArrayBuffer): Promise<ImageMetadata>;
26
+ }
27
+ declare const _default: TiffLoader;
28
+ export default _default;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * 图片解码选项
3
+ */
4
+ export interface DecodeOptions {
5
+ /** RAW 格式是否加载完整图像(默认 false,仅提取缩略图) */
6
+ fullQuality?: boolean;
7
+ /** 目标输出格式(默认 'image/png') */
8
+ outputFormat?: 'image/jpeg' | 'image/png';
9
+ /** 进度回调(0-100) */
10
+ onProgress?: (percent: number) => void;
11
+ /** TIFF 多页格式的页码(从 1 开始,默认 1) */
12
+ page?: number;
13
+ }
14
+ /**
15
+ * 图片元数据
16
+ */
17
+ export interface ImageMetadata {
18
+ /** 图片宽度(像素) */
19
+ width?: number;
20
+ /** 图片高度(像素) */
21
+ height?: number;
22
+ /** 总页数(多页格式如 TIFF) */
23
+ pageCount?: number;
24
+ /** 格式名称 */
25
+ format?: string;
26
+ /** EXIF 信息(可选) */
27
+ exif?: Record<string, unknown>;
28
+ }
29
+ /**
30
+ * 图片解码器统一接口
31
+ */
32
+ export interface ImageDecoder {
33
+ /**
34
+ * 检测该格式是否需要解码(浏览器不原生支持)
35
+ * @param mimeType MIME 类型(如 'image/heic')
36
+ * @returns 是否需要解码
37
+ */
38
+ needsDecode(mimeType: string): Promise<boolean>;
39
+ /**
40
+ * 解码为浏览器可直接展示的格式
41
+ * @param file 原始文件(Blob 或 ArrayBuffer)
42
+ * @param options 解码选项
43
+ * @returns 解码后的 Blob 或 data URL
44
+ */
45
+ decode(file: Blob | ArrayBuffer, options?: DecodeOptions): Promise<Blob | string>;
46
+ /**
47
+ * 获取元数据(可选)
48
+ * @param file 原始文件
49
+ * @returns 图片元数据
50
+ */
51
+ getMetadata?(file: Blob | ArrayBuffer): Promise<ImageMetadata>;
52
+ }
53
+ /**
54
+ * Loader 注册表类型(格式 MIME type 到 loader 的映射)
55
+ */
56
+ export type LoaderRegistry = Map<string, ImageDecoder>;
@@ -0,0 +1,89 @@
1
+ export interface PreviewFileLink {
2
+ id?: string;
3
+ name: string;
4
+ url: string;
5
+ type: string;
6
+ size?: number;
7
+ /** 保留原始本地 File,用于处理浏览器误报的 MIME 类型 */
8
+ file?: File;
9
+ }
10
+ export interface PreviewFile {
11
+ id: string;
12
+ name: string;
13
+ url: string;
14
+ type: string;
15
+ size?: number;
16
+ file?: File;
17
+ }
18
+ export type PreviewFileInput = File | PreviewFileLink | string;
19
+ export type FileType = 'image' | 'pdf' | 'docx' | 'doc' | 'xlsx' | 'xls' | 'pptx' | 'ppt' | 'msg' | 'epub' | 'mobi' | 'video' | 'audio' | 'markdown' | 'json' | 'csv' | 'xml' | 'subtitle' | 'zip' | 'text' | 'font' | 'cad' | 'unsupported';
20
+ /**
21
+ * 支持的文件类型列表(不包括 'unsupported')
22
+ */
23
+ export declare const SUPPORTED_FILE_TYPES: Exclude<FileType, 'unsupported'>[];
24
+ export interface PreviewState {
25
+ zoom: number;
26
+ rotation: number;
27
+ currentPage: number;
28
+ totalPages: number;
29
+ }
30
+ export type Theme = 'auto' | 'dark' | 'light';
31
+ export interface CustomRendererEventPayload<T = unknown> {
32
+ name: string;
33
+ payload?: T;
34
+ file: PreviewFile;
35
+ }
36
+ /**
37
+ * 自定义请求处理器:完全接管 URL 的请求过程。
38
+ * 用于鉴权 URL 等场景(注入 Authorization、Cookie、签名头等)。
39
+ * 接收已合并好的 RequestInit,需返回标准 Response。
40
+ */
41
+ export type RequestHandler = (url: string, init?: RequestInit) => Promise<Response>;
42
+ /**
43
+ * RequestInit 工厂:可以是固定对象,也可以根据 url 异步推导。
44
+ * 与库内调用方传入的 init 合并(库内 init 优先,用户 factory 兜底)。
45
+ */
46
+ export type RequestInitFactory = RequestInit | ((url: string) => RequestInit | Promise<RequestInit>);
47
+ /**
48
+ * 顶层请求选项:requestInit 与 requestHandler 同时存在时,handler 接收已合并的 init。
49
+ */
50
+ export interface RequestOptions {
51
+ requestInit?: RequestInitFactory;
52
+ requestHandler?: RequestHandler;
53
+ /**
54
+ * 请求阶段失败钩子:handler / requestInit 抛出时同步回调(原始异常),
55
+ * 之后 fetcher 仍会抛出 PreviewRequestError。
56
+ * 主动取消(AbortError)不算失败,不会触发该回调。
57
+ * 用于把取数失败上报给宿主。
58
+ */
59
+ onRequestError?: (url: string, error: unknown) => void;
60
+ }
61
+ /**
62
+ * 与原生 fetch 同签名的请求函数。库内所有 fetch 调用经它发出。
63
+ */
64
+ export type Fetcher = (url: string, init?: RequestInit) => Promise<Response>;
65
+ /**
66
+ * 是否对该文件先 fetch 成 Blob 再生成 blob: URL 喂给底层渲染器。
67
+ * 命中后所有 src 类(image/video/audio/pdf)都走 fetcher,能复用鉴权头。
68
+ *
69
+ * @deprecated 将在 1.8.0 移除;请改用 `FileLoader`(`loadFile` prop)。
70
+ */
71
+ export type ShouldFetchAsBlob = (file: PreviewFile) => boolean;
72
+ /**
73
+ * `FileLoader` 的返回值:
74
+ * - `Blob`:库内转成 `blob:` URL 并负责释放;
75
+ * - `{ url }`:已是可直接消费的 URL(预签名直链、后端代理等),生命周期由调用方管理。
76
+ */
77
+ export type FileContent = Blob | {
78
+ url: string;
79
+ };
80
+ /**
81
+ * 统一取数入口:由宿主决定文件内容怎么拿。
82
+ *
83
+ * 传入后库内不再对原始 URL 发起任何请求,也不注入 / 合并任何 RequestInit;
84
+ * 文档类读取 Blob 内容解析,src 类使用返回的 `blob:` 或直链 URL。
85
+ * `signal` 在切换文件或卸载时 abort,调用方应透传给自己的 HTTP 客户端。
86
+ */
87
+ export type FileLoader = (file: PreviewFile, ctx: {
88
+ signal: AbortSignal;
89
+ }) => Promise<FileContent>;
@@ -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;