@lamberl-lee/file-preview 0.2.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.
- package/COPYING +674 -0
- package/LICENSE +165 -0
- package/README.md +165 -0
- package/dist/AudioPreview.d.ts +9 -0
- package/dist/AudioPreview.js +29 -0
- package/dist/AudioPreview.js.map +1 -0
- package/dist/CodePreview.d.ts +10 -0
- package/dist/CodePreview.js +121 -0
- package/dist/CodePreview.js.map +1 -0
- package/dist/CsvPreview.d.ts +9 -0
- package/dist/CsvPreview.js +117 -0
- package/dist/CsvPreview.js.map +1 -0
- package/dist/DocxPreview.d.ts +11 -0
- package/dist/DocxPreview.js +89 -0
- package/dist/DocxPreview.js.map +1 -0
- package/dist/EpubPreview.d.ts +9 -0
- package/dist/EpubPreview.js +693 -0
- package/dist/EpubPreview.js.map +1 -0
- package/dist/HtmlPreview.d.ts +9 -0
- package/dist/HtmlPreview.js +60 -0
- package/dist/HtmlPreview.js.map +1 -0
- package/dist/ImagePreview.d.ts +9 -0
- package/dist/ImagePreview.js +44 -0
- package/dist/ImagePreview.js.map +1 -0
- package/dist/LargeFileGate.d.ts +12 -0
- package/dist/LargeFileGate.js +88 -0
- package/dist/LargeFileGate.js.map +1 -0
- package/dist/MarkdownPreview.d.ts +8 -0
- package/dist/MarkdownPreview.js +140 -0
- package/dist/MarkdownPreview.js.map +1 -0
- package/dist/PdfPreview.d.ts +11 -0
- package/dist/PdfPreview.js +206 -0
- package/dist/PdfPreview.js.map +1 -0
- package/dist/PlainTextLargePreview.d.ts +9 -0
- package/dist/PlainTextLargePreview.js +62 -0
- package/dist/PlainTextLargePreview.js.map +1 -0
- package/dist/PluginPreviewRenderer.d.ts +13 -0
- package/dist/PluginPreviewRenderer.js +89 -0
- package/dist/PluginPreviewRenderer.js.map +1 -0
- package/dist/PptxPreview.d.ts +16 -0
- package/dist/PptxPreview.js +376 -0
- package/dist/PptxPreview.js.map +1 -0
- package/dist/PreviewErrorBoundary.d.ts +29 -0
- package/dist/PreviewErrorBoundary.js +53 -0
- package/dist/PreviewErrorBoundary.js.map +1 -0
- package/dist/PreviewFallback.d.ts +18 -0
- package/dist/PreviewFallback.js +143 -0
- package/dist/PreviewFallback.js.map +1 -0
- package/dist/PreviewLoading.d.ts +8 -0
- package/dist/PreviewLoading.js +14 -0
- package/dist/PreviewLoading.js.map +1 -0
- package/dist/RtfPreview.d.ts +10 -0
- package/dist/RtfPreview.js +240 -0
- package/dist/RtfPreview.js.map +1 -0
- package/dist/ShikiSourceView.d.ts +11 -0
- package/dist/ShikiSourceView.js +112 -0
- package/dist/ShikiSourceView.js.map +1 -0
- package/dist/SvgPreview.d.ts +9 -0
- package/dist/SvgPreview.js +89 -0
- package/dist/SvgPreview.js.map +1 -0
- package/dist/TextPreview.d.ts +9 -0
- package/dist/TextPreview.js +9 -0
- package/dist/TextPreview.js.map +1 -0
- package/dist/VideoPreview.d.ts +9 -0
- package/dist/VideoPreview.js +18 -0
- package/dist/VideoPreview.js.map +1 -0
- package/dist/XlsxPreview.d.ts +12 -0
- package/dist/XlsxPreview.js +856 -0
- package/dist/XlsxPreview.js.map +1 -0
- package/dist/ZipPreview.d.ts +9 -0
- package/dist/ZipPreview.js +153 -0
- package/dist/ZipPreview.js.map +1 -0
- package/dist/core/binary.d.ts +10 -0
- package/dist/core/binary.js +27 -0
- package/dist/core/binary.js.map +1 -0
- package/dist/core/config.d.ts +17 -0
- package/dist/core/config.js +19 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/download.d.ts +5 -0
- package/dist/core/download.js +20 -0
- package/dist/core/download.js.map +1 -0
- package/dist/core/i18n.d.ts +101 -0
- package/dist/core/i18n.js +200 -0
- package/dist/core/i18n.js.map +1 -0
- package/dist/core/plugin.d.ts +38 -0
- package/dist/core/plugin.js +46 -0
- package/dist/core/plugin.js.map +1 -0
- package/dist/core/registry.d.ts +13 -0
- package/dist/core/registry.js +33 -0
- package/dist/core/registry.js.map +1 -0
- package/dist/core/source.d.ts +14 -0
- package/dist/core/source.js +131 -0
- package/dist/core/source.js.map +1 -0
- package/dist/core/types.d.ts +88 -0
- package/dist/core/types.js +27 -0
- package/dist/core/types.js.map +1 -0
- package/dist/hooks/useObjectUrlFromSource.d.ts +9 -0
- package/dist/hooks/useObjectUrlFromSource.js +50 -0
- package/dist/hooks/useObjectUrlFromSource.js.map +1 -0
- package/dist/hooks/useSourceBase64.d.ts +10 -0
- package/dist/hooks/useSourceBase64.js +32 -0
- package/dist/hooks/useSourceBase64.js.map +1 -0
- package/dist/hooks/useSourceText.d.ts +10 -0
- package/dist/hooks/useSourceText.js +32 -0
- package/dist/hooks/useSourceText.js.map +1 -0
- package/dist/icons.d.ts +44 -0
- package/dist/icons.js +248 -0
- package/dist/icons.js.map +1 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +147 -0
- package/dist/index.js.map +1 -0
- package/dist/limits.d.ts +26 -0
- package/dist/limits.js +45 -0
- package/dist/limits.js.map +1 -0
- package/dist/performance-limits.d.ts +27 -0
- package/dist/performance-limits.js +54 -0
- package/dist/performance-limits.js.map +1 -0
- package/dist/plugins/audio-plugin.d.ts +7 -0
- package/dist/plugins/audio-plugin.js +11 -0
- package/dist/plugins/audio-plugin.js.map +1 -0
- package/dist/plugins/builtin-plugins.d.ts +9 -0
- package/dist/plugins/builtin-plugins.js +43 -0
- package/dist/plugins/builtin-plugins.js.map +1 -0
- package/dist/plugins/csv-plugin.d.ts +7 -0
- package/dist/plugins/csv-plugin.js +11 -0
- package/dist/plugins/csv-plugin.js.map +1 -0
- package/dist/plugins/docx-plugin.d.ts +7 -0
- package/dist/plugins/docx-plugin.js +15 -0
- package/dist/plugins/docx-plugin.js.map +1 -0
- package/dist/plugins/epub-plugin.d.ts +7 -0
- package/dist/plugins/epub-plugin.js +15 -0
- package/dist/plugins/epub-plugin.js.map +1 -0
- package/dist/plugins/html-plugin.d.ts +7 -0
- package/dist/plugins/html-plugin.js +11 -0
- package/dist/plugins/html-plugin.js.map +1 -0
- package/dist/plugins/image-plugin.d.ts +7 -0
- package/dist/plugins/image-plugin.js +11 -0
- package/dist/plugins/image-plugin.js.map +1 -0
- package/dist/plugins/markdown-plugin.d.ts +7 -0
- package/dist/plugins/markdown-plugin.js +11 -0
- package/dist/plugins/markdown-plugin.js.map +1 -0
- package/dist/plugins/pdf-plugin.d.ts +7 -0
- package/dist/plugins/pdf-plugin.js +15 -0
- package/dist/plugins/pdf-plugin.js.map +1 -0
- package/dist/plugins/pptx-plugin.d.ts +7 -0
- package/dist/plugins/pptx-plugin.js +15 -0
- package/dist/plugins/pptx-plugin.js.map +1 -0
- package/dist/plugins/rtf-plugin.d.ts +7 -0
- package/dist/plugins/rtf-plugin.js +15 -0
- package/dist/plugins/rtf-plugin.js.map +1 -0
- package/dist/plugins/source-code-plugin.d.ts +7 -0
- package/dist/plugins/source-code-plugin.js +11 -0
- package/dist/plugins/source-code-plugin.js.map +1 -0
- package/dist/plugins/svg-plugin.d.ts +7 -0
- package/dist/plugins/svg-plugin.js +11 -0
- package/dist/plugins/svg-plugin.js.map +1 -0
- package/dist/plugins/text-plugin.d.ts +7 -0
- package/dist/plugins/text-plugin.js +11 -0
- package/dist/plugins/text-plugin.js.map +1 -0
- package/dist/plugins/video-plugin.d.ts +7 -0
- package/dist/plugins/video-plugin.js +11 -0
- package/dist/plugins/video-plugin.js.map +1 -0
- package/dist/plugins/xlsx-plugin.d.ts +7 -0
- package/dist/plugins/xlsx-plugin.js +15 -0
- package/dist/plugins/xlsx-plugin.js.map +1 -0
- package/dist/plugins/zip-plugin.d.ts +7 -0
- package/dist/plugins/zip-plugin.js +15 -0
- package/dist/plugins/zip-plugin.js.map +1 -0
- package/dist/preview-adapters/AudioPreviewAdapter.d.ts +8 -0
- package/dist/preview-adapters/AudioPreviewAdapter.js +31 -0
- package/dist/preview-adapters/AudioPreviewAdapter.js.map +1 -0
- package/dist/preview-adapters/CsvPreviewAdapter.d.ts +8 -0
- package/dist/preview-adapters/CsvPreviewAdapter.js +28 -0
- package/dist/preview-adapters/CsvPreviewAdapter.js.map +1 -0
- package/dist/preview-adapters/DocxPreviewAdapter.d.ts +8 -0
- package/dist/preview-adapters/DocxPreviewAdapter.js +16 -0
- package/dist/preview-adapters/DocxPreviewAdapter.js.map +1 -0
- package/dist/preview-adapters/EpubPreviewAdapter.d.ts +8 -0
- package/dist/preview-adapters/EpubPreviewAdapter.js +28 -0
- package/dist/preview-adapters/EpubPreviewAdapter.js.map +1 -0
- package/dist/preview-adapters/HtmlPreviewAdapter.d.ts +8 -0
- package/dist/preview-adapters/HtmlPreviewAdapter.js +28 -0
- package/dist/preview-adapters/HtmlPreviewAdapter.js.map +1 -0
- package/dist/preview-adapters/ImagePreviewAdapter.d.ts +8 -0
- package/dist/preview-adapters/ImagePreviewAdapter.js +31 -0
- package/dist/preview-adapters/ImagePreviewAdapter.js.map +1 -0
- package/dist/preview-adapters/MarkdownPreviewAdapter.d.ts +8 -0
- package/dist/preview-adapters/MarkdownPreviewAdapter.js +28 -0
- package/dist/preview-adapters/MarkdownPreviewAdapter.js.map +1 -0
- package/dist/preview-adapters/PdfPreviewAdapter.d.ts +8 -0
- package/dist/preview-adapters/PdfPreviewAdapter.js +16 -0
- package/dist/preview-adapters/PdfPreviewAdapter.js.map +1 -0
- package/dist/preview-adapters/PptxPreviewAdapter.d.ts +8 -0
- package/dist/preview-adapters/PptxPreviewAdapter.js +16 -0
- package/dist/preview-adapters/PptxPreviewAdapter.js.map +1 -0
- package/dist/preview-adapters/RtfPreviewAdapter.d.ts +8 -0
- package/dist/preview-adapters/RtfPreviewAdapter.js +54 -0
- package/dist/preview-adapters/RtfPreviewAdapter.js.map +1 -0
- package/dist/preview-adapters/SourceCodePreviewAdapter.d.ts +8 -0
- package/dist/preview-adapters/SourceCodePreviewAdapter.js +35 -0
- package/dist/preview-adapters/SourceCodePreviewAdapter.js.map +1 -0
- package/dist/preview-adapters/SvgPreviewAdapter.d.ts +8 -0
- package/dist/preview-adapters/SvgPreviewAdapter.js +28 -0
- package/dist/preview-adapters/SvgPreviewAdapter.js.map +1 -0
- package/dist/preview-adapters/TextPreviewAdapter.d.ts +8 -0
- package/dist/preview-adapters/TextPreviewAdapter.js +28 -0
- package/dist/preview-adapters/TextPreviewAdapter.js.map +1 -0
- package/dist/preview-adapters/UnsupportedPluginPreview.d.ts +11 -0
- package/dist/preview-adapters/UnsupportedPluginPreview.js +34 -0
- package/dist/preview-adapters/UnsupportedPluginPreview.js.map +1 -0
- package/dist/preview-adapters/VideoPreviewAdapter.d.ts +8 -0
- package/dist/preview-adapters/VideoPreviewAdapter.js +31 -0
- package/dist/preview-adapters/VideoPreviewAdapter.js.map +1 -0
- package/dist/preview-adapters/XlsxPreviewAdapter.d.ts +8 -0
- package/dist/preview-adapters/XlsxPreviewAdapter.js +17 -0
- package/dist/preview-adapters/XlsxPreviewAdapter.js.map +1 -0
- package/dist/preview-adapters/ZipPreviewAdapter.d.ts +8 -0
- package/dist/preview-adapters/ZipPreviewAdapter.js +28 -0
- package/dist/preview-adapters/ZipPreviewAdapter.js.map +1 -0
- package/dist/remote-url.d.ts +20 -0
- package/dist/remote-url.js +478 -0
- package/dist/remote-url.js.map +1 -0
- package/dist/rtf/load-rtfjs.d.ts +42 -0
- package/dist/rtf/load-rtfjs.js +71 -0
- package/dist/rtf/load-rtfjs.js.map +1 -0
- package/dist/rtf/normalize-codepage.d.ts +33 -0
- package/dist/rtf/normalize-codepage.js +88 -0
- package/dist/rtf/normalize-codepage.js.map +1 -0
- package/dist/shiki.d.ts +35 -0
- package/dist/shiki.js +128 -0
- package/dist/shiki.js.map +1 -0
- package/dist/styles/AudioPreview.css +35 -0
- package/dist/styles/CsvPreview.css +106 -0
- package/dist/styles/DocxPreview.css +93 -0
- package/dist/styles/EpubPreview.css +509 -0
- package/dist/styles/HtmlPreview.css +15 -0
- package/dist/styles/ImagePreview.css +45 -0
- package/dist/styles/LargeFileGate.css +55 -0
- package/dist/styles/MarkdownPreview.css +291 -0
- package/dist/styles/PdfPreview.css +68 -0
- package/dist/styles/PlainTextLargePreview.css +85 -0
- package/dist/styles/PluginDebugBar.css +30 -0
- package/dist/styles/PptxPreview.css +207 -0
- package/dist/styles/PreviewFallback.css +88 -0
- package/dist/styles/PreviewLoading.css +13 -0
- package/dist/styles/RtfPreview.css +99 -0
- package/dist/styles/ShikiSourceView.css +159 -0
- package/dist/styles/SvgPreview.css +99 -0
- package/dist/styles/VideoPreview.css +19 -0
- package/dist/styles/ViewModeBar.css +38 -0
- package/dist/styles/XlsxPreview.css +361 -0
- package/dist/styles/ZipPreview.css +86 -0
- package/dist/styles/base.css +238 -0
- package/dist/styles/index.css +39 -0
- package/dist/support-status.d.ts +19 -0
- package/dist/support-status.js +174 -0
- package/dist/support-status.js.map +1 -0
- package/dist/utils.d.ts +17 -0
- package/dist/utils.js +205 -0
- package/dist/utils.js.map +1 -0
- package/package.json +125 -0
- package/scripts/copy-pdf-worker.mjs +31 -0
- package/scripts/copy-rtfjs-bundles.mjs +49 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
const zhCN = {
|
|
2
|
+
// View mode bar
|
|
3
|
+
preview: "\u9884\u89C8",
|
|
4
|
+
source: "\u6E90\u7801",
|
|
5
|
+
split: "\u5206\u680F",
|
|
6
|
+
// Common actions
|
|
7
|
+
download: "\u4E0B\u8F7D",
|
|
8
|
+
copy: "\u590D\u5236",
|
|
9
|
+
search: "\u641C\u7D22...",
|
|
10
|
+
zoomIn: "\u653E\u5927",
|
|
11
|
+
zoomOut: "\u7F29\u5C0F",
|
|
12
|
+
reset: "\u91CD\u7F6E",
|
|
13
|
+
fullscreen: "\u5168\u5C4F",
|
|
14
|
+
previous: "\u4E0A\u4E00\u4E2A",
|
|
15
|
+
next: "\u4E0B\u4E00\u4E2A",
|
|
16
|
+
// Page / slide units
|
|
17
|
+
page: "\u9875",
|
|
18
|
+
pages: "\u9875",
|
|
19
|
+
slideView: "\u5E7B\u706F\u7247\u89C6\u56FE",
|
|
20
|
+
gridView: "\u7F29\u7565\u56FE\u89C6\u56FE",
|
|
21
|
+
previousPage: "\u4E0A\u4E00\u9875 (\u2190)",
|
|
22
|
+
nextPage: "\u4E0B\u4E00\u9875 (\u2192)",
|
|
23
|
+
// Loading states
|
|
24
|
+
loadingPreview: "\u52A0\u8F7D\u9884\u89C8\u4E2D...",
|
|
25
|
+
loadingRtf: "\u6B63\u5728\u89E3\u6790 RTF...",
|
|
26
|
+
loadingSpreadsheet: "\u6B63\u5728\u89E3\u6790\u8868\u683C...",
|
|
27
|
+
loadingEbook: "Loading e-book...",
|
|
28
|
+
loadingPresentation: "\u6B63\u5728\u89E3\u6790\u6F14\u793A\u6587\u7A3F...",
|
|
29
|
+
// Error states
|
|
30
|
+
previewFailed: "\u9884\u89C8\u5931\u8D25",
|
|
31
|
+
parseFailed: "\u89E3\u6790\u5931\u8D25",
|
|
32
|
+
formatNotSupported: "\u683C\u5F0F\u4E0D\u652F\u6301",
|
|
33
|
+
// Legacy office formats
|
|
34
|
+
legacyDocTitle: "\u65E7\u7248 Word \u683C\u5F0F\u6682\u4E0D\u652F\u6301",
|
|
35
|
+
legacyPptTitle: "\u65E7\u7248 PowerPoint \u683C\u5F0F\u6682\u4E0D\u652F\u6301",
|
|
36
|
+
legacyXlsTitle: "\u65E7\u7248 Excel \u683C\u5F0F\u6682\u4E0D\u652F\u6301",
|
|
37
|
+
legacyDocDesc: "\u8BE5\u6587\u4EF6\u4E3A\u65E7\u7248 .doc \u4E8C\u8FDB\u5236\u683C\u5F0F\uFF0C\u5F53\u524D\u6D4F\u89C8\u5668\u7AEF\u9884\u89C8\u4EC5\u652F\u6301 .docx\u3002\u5EFA\u8BAE\u4F7F\u7528 Word \u6216 WPS \u5C06\u6587\u4EF6\u53E6\u5B58\u4E3A .docx \u540E\u91CD\u8BD5\u3002",
|
|
38
|
+
legacyPptDesc: "\u8BE5\u6587\u4EF6\u4E3A\u65E7\u7248 .ppt \u4E8C\u8FDB\u5236\u683C\u5F0F\uFF0C\u5F53\u524D\u4EC5\u652F\u6301 Open XML \u683C\u5F0F\uFF08.pptx\uFF09\u3002\u5EFA\u8BAE\u4F7F\u7528 PowerPoint \u6216 WPS \u5C06\u6587\u4EF6\u53E6\u5B58\u4E3A .pptx \u683C\u5F0F\u540E\u91CD\u8BD5\u3002",
|
|
39
|
+
legacyXlsDesc: "\u8BE5\u6587\u4EF6\u4E3A\u65E7\u7248 .xls \u4E8C\u8FDB\u5236\u683C\u5F0F\uFF0C\u5F53\u524D\u4EC5\u652F\u6301 Open XML \u683C\u5F0F\uFF08.xlsx/.xlsm\uFF09\u3002\u5EFA\u8BAE\u4F7F\u7528 Excel \u6216 WPS \u5C06\u6587\u4EF6\u53E6\u5B58\u4E3A .xlsx \u683C\u5F0F\u540E\u91CD\u8BD5\u3002",
|
|
40
|
+
legacyXlsFallbackDesc: "\u5F53\u524D\u6587\u4EF6\u4E3A\u65E7\u7248 .xls \u683C\u5F0F\uFF0C\u90E8\u5206\u5185\u5BB9\u53EF\u80FD\u65E0\u6CD5\u5B8C\u6574\u663E\u793A\u3002\u5EFA\u8BAE\u53E6\u5B58\u4E3A .xlsx \u683C\u5F0F\u4EE5\u83B7\u5F97\u6700\u4F73\u9884\u89C8\u6548\u679C\u3002",
|
|
41
|
+
legacyXlsError: "\u8BE5\u6587\u4EF6\u4E3A\u65E7\u7248 Excel \u4E8C\u8FDB\u5236\u683C\u5F0F\uFF08.xls\uFF09\uFF0C\u5F53\u524D\u4EC5\u652F\u6301 Open XML \u683C\u5F0F\uFF08.xlsx/.xlsm\uFF09\u3002\u5EFA\u8BAE\u4F7F\u7528 Excel \u6216 WPS \u5C06\u6587\u4EF6\u53E6\u5B58\u4E3A .xlsx \u683C\u5F0F\u540E\u91CD\u8BD5\u3002",
|
|
42
|
+
legacyXlsBanner: "\u65E7\u7248 Excel \u683C\u5F0F\u6682\u4E0D\u652F\u6301",
|
|
43
|
+
unsupportedFileType: "\u8BE5\u6587\u4EF6\u7C7B\u578B ({fileType}) \u6682\u4E0D\u652F\u6301\u6D4F\u89C8\u5668\u7AEF\u9884\u89C8\u3002",
|
|
44
|
+
// Large file
|
|
45
|
+
largeFileHint: "\u5F53\u524D\u6587\u4EF6\u8F83\u5927\uFF0C\u6D4F\u89C8\u5668\u7AEF\u89E3\u6790\u53EF\u80FD\u9700\u8981\u66F4\u957F\u65F6\u95F4\uFF0C\u671F\u95F4\u9875\u9762\u53EF\u80FD\u77ED\u6682\u5361\u987F\u3002",
|
|
46
|
+
largeFile: "\u5927\u6587\u4EF6",
|
|
47
|
+
largeFileRows: "\u884C",
|
|
48
|
+
largeFileCols: "\u5217",
|
|
49
|
+
largeFileImages: "\u5F20\u56FE\u7247",
|
|
50
|
+
largeFileFastModeBanner: "\u5F53\u524D Excel \u6587\u4EF6\u8F83\u5927\uFF08{fileSize}\uFF09\uFF0C\u5DF2\u9ED8\u8BA4\u4F7F\u7528\u5FEB\u901F\u6A21\u5F0F\uFF1A\u4EC5\u6E32\u67D3\u524D {rowLimit} \u884C\uFF0C\u5E76\u8DF3\u8FC7\u56FE\u7247\u89E3\u6790\u3002",
|
|
51
|
+
largeFileFidelityBanner: "\u5F53\u524D\u6B63\u5728\u4F7F\u7528\u9AD8\u4FDD\u771F\u6A21\u5F0F\u9884\u89C8\u5927\u6587\u4EF6\uFF0C\u53EF\u80FD\u5BFC\u81F4\u6D4F\u89C8\u5668\u5361\u987F\u3002",
|
|
52
|
+
largeFileFidelityConfirm: "\u5F53\u524D Excel \u6587\u4EF6\u5927\u5C0F\u4E3A {fileSize}\uFF0C\u9AD8\u4FDD\u771F\u6A21\u5F0F\u53EF\u80FD\u5BFC\u81F4\u6D4F\u89C8\u5668\u5361\u987F\u751A\u81F3\u65E0\u54CD\u5E94\u3002\u662F\u5426\u7EE7\u7EED\uFF1F",
|
|
53
|
+
truncatedRows: "\u6570\u636E\u91CF\u8F83\u5927\uFF0C\u4EC5\u663E\u793A\u524D {shown} \u884C\uFF08\u5171 {total} \u884C\uFF09",
|
|
54
|
+
// Spreadsheet
|
|
55
|
+
sheetNotFound: "\u672A\u627E\u5230\u5DE5\u4F5C\u8868",
|
|
56
|
+
fastMode: "\u5FEB\u901F",
|
|
57
|
+
fidelityMode: "\u9AD8\u4FDD\u771F",
|
|
58
|
+
fastModeTitle: "\u5FEB\u901F\u6A21\u5F0F\uFF1A\u9650\u5236\u884C\u6570\uFF0C\u8DF3\u8FC7\u56FE\u7247\u548C\u590D\u6742\u6837\u5F0F",
|
|
59
|
+
fidelityModeTitle: "\u9AD8\u4FDD\u771F\u6A21\u5F0F\uFF1A\u4FDD\u7559\u6837\u5F0F\u3001\u56FE\u7247\u3001\u6279\u6CE8",
|
|
60
|
+
noData: "\u65E0\u6570\u636E",
|
|
61
|
+
noSearchResults: "\u672A\u627E\u5230\u5339\u914D\u6570\u636E",
|
|
62
|
+
comment: "\u6279\u6CE8",
|
|
63
|
+
unsupportedImageFormat: "\u4E0D\u652F\u6301\u7684\u56FE\u7247\u683C\u5F0F",
|
|
64
|
+
unknown: "\u672A\u77E5",
|
|
65
|
+
downloadOriginal: "\u4E0B\u8F7D\u539F\u6587\u4EF6",
|
|
66
|
+
// Plain text
|
|
67
|
+
lines: "\u884C",
|
|
68
|
+
wordWrapOn: "\u5F00\u542F\u81EA\u52A8\u6362\u884C",
|
|
69
|
+
wordWrapOff: "\u5173\u95ED\u81EA\u52A8\u6362\u884C",
|
|
70
|
+
copyContent: "\u590D\u5236\u5185\u5BB9",
|
|
71
|
+
// Markdown
|
|
72
|
+
oversizedCodeBlock: "\u5927\u4EE3\u7801\u5757",
|
|
73
|
+
// RTF
|
|
74
|
+
rtfFallback: "\u5BCC\u6587\u672C\u6E32\u67D3\u4E0D\u53EF\u7528\uFF0C\u5DF2\u964D\u7EA7\u4E3A\u7EAF\u6587\u672C\u9884\u89C8",
|
|
75
|
+
rtfNoText: "\u65E0\u6CD5\u4ECE\u6587\u4EF6\u4E2D\u63D0\u53D6\u6587\u672C\u5185\u5BB9\u3002",
|
|
76
|
+
showErrorDetails: "\u67E5\u770B\u9519\u8BEF\u8BE6\u60C5",
|
|
77
|
+
// EPUB
|
|
78
|
+
noChaptersFound: "No Chapters Found",
|
|
79
|
+
ebookLoadFailed: "Failed to Load E-book",
|
|
80
|
+
unknownError: "\u672A\u77E5\u9519\u8BEF",
|
|
81
|
+
tableOfContents: "Table of Contents",
|
|
82
|
+
foundInChapters: "Found in {count} chapter(s)",
|
|
83
|
+
noResultsFound: "\u672A\u627E\u5230\u7ED3\u679C",
|
|
84
|
+
searchPlaceholder: "\u641C\u7D22...",
|
|
85
|
+
// Shared fallback
|
|
86
|
+
previewNotAvailable: "\u9884\u89C8\u4E0D\u53EF\u7528",
|
|
87
|
+
failedToLoadPreview: "\u9884\u89C8\u52A0\u8F7D\u5931\u8D25",
|
|
88
|
+
failedToReadFile: "\u6587\u4EF6\u8BFB\u53D6\u5931\u8D25",
|
|
89
|
+
loadingCancelled: "\u52A0\u8F7D\u5DF2\u53D6\u6D88",
|
|
90
|
+
copyCode: "\u590D\u5236\u4EE3\u7801"
|
|
91
|
+
};
|
|
92
|
+
const enUS = {
|
|
93
|
+
// View mode bar
|
|
94
|
+
preview: "Preview",
|
|
95
|
+
source: "Source",
|
|
96
|
+
split: "Split",
|
|
97
|
+
// Common actions
|
|
98
|
+
download: "Download",
|
|
99
|
+
copy: "Copy",
|
|
100
|
+
search: "Search...",
|
|
101
|
+
zoomIn: "Zoom In",
|
|
102
|
+
zoomOut: "Zoom Out",
|
|
103
|
+
reset: "Reset",
|
|
104
|
+
fullscreen: "Fullscreen",
|
|
105
|
+
previous: "Previous",
|
|
106
|
+
next: "Next",
|
|
107
|
+
// Page / slide units
|
|
108
|
+
page: "page",
|
|
109
|
+
pages: "pages",
|
|
110
|
+
slideView: "Slide View",
|
|
111
|
+
gridView: "Grid View",
|
|
112
|
+
previousPage: "Previous Page (\u2190)",
|
|
113
|
+
nextPage: "Next Page (\u2192)",
|
|
114
|
+
// Loading states
|
|
115
|
+
loadingPreview: "Loading preview...",
|
|
116
|
+
loadingRtf: "Parsing RTF...",
|
|
117
|
+
loadingSpreadsheet: "Parsing spreadsheet...",
|
|
118
|
+
loadingEbook: "Loading e-book...",
|
|
119
|
+
loadingPresentation: "Parsing presentation...",
|
|
120
|
+
// Error states
|
|
121
|
+
previewFailed: "Preview Failed",
|
|
122
|
+
parseFailed: "Parse Failed",
|
|
123
|
+
formatNotSupported: "Format Not Supported",
|
|
124
|
+
// Legacy office formats
|
|
125
|
+
legacyDocTitle: "Legacy Word format not supported",
|
|
126
|
+
legacyPptTitle: "Legacy PowerPoint format not supported",
|
|
127
|
+
legacyXlsTitle: "Legacy Excel format not supported",
|
|
128
|
+
legacyDocDesc: "This file is in the legacy .doc binary format. Browser-side preview only supports .docx. Please use Word or WPS to save the file as .docx and try again.",
|
|
129
|
+
legacyPptDesc: "This file is in the legacy .ppt binary format. Only the Open XML format (.pptx) is supported. Please use PowerPoint or WPS to save the file as .pptx and try again.",
|
|
130
|
+
legacyXlsDesc: "This file is in the legacy .xls binary format. Only the Open XML format (.xlsx/.xlsm) is supported. Please use Excel or WPS to save the file as .xlsx and try again.",
|
|
131
|
+
legacyXlsFallbackDesc: "This file is in the legacy .xls format. Some content may not display correctly. Please save as .xlsx for the best preview experience.",
|
|
132
|
+
legacyXlsError: "This file is in the legacy .xls binary format. Only the Open XML format (.xlsx/.xlsm) is supported. Please use Excel or WPS to save the file as .xlsx and try again.",
|
|
133
|
+
legacyXlsBanner: "Legacy Excel format not supported",
|
|
134
|
+
unsupportedFileType: "File type ({fileType}) is not supported for browser-side preview.",
|
|
135
|
+
// Large file
|
|
136
|
+
largeFileHint: "This file is large. Browser-side parsing may take longer and the page may briefly freeze.",
|
|
137
|
+
largeFile: "Large File",
|
|
138
|
+
largeFileRows: "rows",
|
|
139
|
+
largeFileCols: "cols",
|
|
140
|
+
largeFileImages: "images",
|
|
141
|
+
largeFileFastModeBanner: "This Excel file is large ({fileSize}). Fast mode is enabled by default: only the first {rowLimit} rows are rendered and image parsing is skipped.",
|
|
142
|
+
largeFileFidelityBanner: "You are using fidelity mode to preview a large file. This may cause the browser to freeze.",
|
|
143
|
+
largeFileFidelityConfirm: "This Excel file is {fileSize}. Fidelity mode may cause the browser to freeze or become unresponsive. Continue?",
|
|
144
|
+
truncatedRows: "Data is large. Showing first {shown} of {total} rows",
|
|
145
|
+
// Spreadsheet
|
|
146
|
+
sheetNotFound: "No Sheets Found",
|
|
147
|
+
fastMode: "Fast",
|
|
148
|
+
fidelityMode: "Fidelity",
|
|
149
|
+
fastModeTitle: "Fast mode: limited rows, skip images and complex styles",
|
|
150
|
+
fidelityModeTitle: "Fidelity mode: preserve styles, images, and comments",
|
|
151
|
+
noData: "No data",
|
|
152
|
+
noSearchResults: "No matching data found",
|
|
153
|
+
comment: "Comment",
|
|
154
|
+
unsupportedImageFormat: "Unsupported image format",
|
|
155
|
+
unknown: "Unknown",
|
|
156
|
+
downloadOriginal: "Download Original",
|
|
157
|
+
// Plain text
|
|
158
|
+
lines: "lines",
|
|
159
|
+
wordWrapOn: "Enable word wrap",
|
|
160
|
+
wordWrapOff: "Disable word wrap",
|
|
161
|
+
copyContent: "Copy content",
|
|
162
|
+
// Markdown
|
|
163
|
+
oversizedCodeBlock: "Large code block",
|
|
164
|
+
// RTF
|
|
165
|
+
rtfFallback: "Rich text rendering unavailable, fallback to plain text preview",
|
|
166
|
+
rtfNoText: "Unable to extract text content from file.",
|
|
167
|
+
showErrorDetails: "Show error details",
|
|
168
|
+
// EPUB
|
|
169
|
+
noChaptersFound: "No Chapters Found",
|
|
170
|
+
ebookLoadFailed: "Failed to Load E-book",
|
|
171
|
+
unknownError: "Unknown error",
|
|
172
|
+
tableOfContents: "Table of Contents",
|
|
173
|
+
foundInChapters: "Found in {count} chapter(s)",
|
|
174
|
+
noResultsFound: "No results found",
|
|
175
|
+
searchPlaceholder: "Search...",
|
|
176
|
+
// Shared fallback
|
|
177
|
+
previewNotAvailable: "Preview Not Available",
|
|
178
|
+
failedToLoadPreview: "Failed to Load Preview",
|
|
179
|
+
failedToReadFile: "Failed to Read File",
|
|
180
|
+
loadingCancelled: "Loading Cancelled",
|
|
181
|
+
copyCode: "Copy code"
|
|
182
|
+
};
|
|
183
|
+
import { createContext, useContext } from "react";
|
|
184
|
+
const defaultLocale = zhCN;
|
|
185
|
+
const LocaleContext = createContext(defaultLocale);
|
|
186
|
+
const LocaleProvider = LocaleContext.Provider;
|
|
187
|
+
function useLocale() {
|
|
188
|
+
return useContext(LocaleContext);
|
|
189
|
+
}
|
|
190
|
+
function getDefaultLocale() {
|
|
191
|
+
return defaultLocale;
|
|
192
|
+
}
|
|
193
|
+
export {
|
|
194
|
+
LocaleProvider,
|
|
195
|
+
enUS,
|
|
196
|
+
getDefaultLocale,
|
|
197
|
+
useLocale,
|
|
198
|
+
zhCN
|
|
199
|
+
};
|
|
200
|
+
//# sourceMappingURL=i18n.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/i18n.ts"],"sourcesContent":["/**\n * FileVista i18n — locale messages for all UI strings.\n *\n * Library consumers can import and override any locale, or provide\n * a fully custom translation via `<FileVistaProvider locale={...}>`.\n *\n * Usage in components:\n * import { useLocale } from \"./core/i18n\";\n * const t = useLocale();\n * <button>{t.preview}</button>\n */\n\n// ─── Type definition ───\n\nexport interface LocaleMessages {\n // View mode bar\n preview: string;\n source: string;\n split: string;\n\n // Common actions\n download: string;\n copy: string;\n search: string;\n zoomIn: string;\n zoomOut: string;\n reset: string;\n fullscreen: string;\n previous: string;\n next: string;\n\n // Page / slide units\n page: string;\n pages: string;\n slideView: string;\n gridView: string;\n previousPage: string;\n nextPage: string;\n\n // Loading states\n loadingPreview: string;\n loadingRtf: string;\n loadingSpreadsheet: string;\n loadingEbook: string;\n loadingPresentation: string;\n\n // Error states\n previewFailed: string;\n parseFailed: string;\n formatNotSupported: string;\n\n // Legacy office formats\n legacyDocTitle: string;\n legacyPptTitle: string;\n legacyXlsTitle: string;\n legacyDocDesc: string;\n legacyPptDesc: string;\n legacyXlsDesc: string;\n legacyXlsFallbackDesc: string;\n legacyXlsError: string;\n legacyXlsBanner: string;\n unsupportedFileType: string;\n\n // Large file\n largeFileHint: string;\n largeFile: string;\n largeFileRows: string;\n largeFileCols: string;\n largeFileImages: string;\n largeFileFastModeBanner: string;\n largeFileFidelityBanner: string;\n largeFileFidelityConfirm: string;\n truncatedRows: string;\n\n // Spreadsheet\n sheetNotFound: string;\n fastMode: string;\n fidelityMode: string;\n fastModeTitle: string;\n fidelityModeTitle: string;\n noData: string;\n noSearchResults: string;\n comment: string;\n unsupportedImageFormat: string;\n unknown: string;\n downloadOriginal: string;\n\n // Plain text\n lines: string;\n wordWrapOn: string;\n wordWrapOff: string;\n copyContent: string;\n\n // Markdown\n oversizedCodeBlock: string;\n\n // RTF\n rtfFallback: string;\n rtfNoText: string;\n showErrorDetails: string;\n\n // EPUB\n noChaptersFound: string;\n ebookLoadFailed: string;\n unknownError: string;\n tableOfContents: string;\n foundInChapters: string;\n noResultsFound: string;\n searchPlaceholder: string;\n\n // Shared fallback\n previewNotAvailable: string;\n failedToLoadPreview: string;\n failedToReadFile: string;\n loadingCancelled: string;\n copyCode: string;\n}\n\n// ─── zh-CN (default) ───\n\nexport const zhCN: LocaleMessages = {\n // View mode bar\n preview: \"预览\",\n source: \"源码\",\n split: \"分栏\",\n\n // Common actions\n download: \"下载\",\n copy: \"复制\",\n search: \"搜索...\",\n zoomIn: \"放大\",\n zoomOut: \"缩小\",\n reset: \"重置\",\n fullscreen: \"全屏\",\n previous: \"上一个\",\n next: \"下一个\",\n\n // Page / slide units\n page: \"页\",\n pages: \"页\",\n slideView: \"幻灯片视图\",\n gridView: \"缩略图视图\",\n previousPage: \"上一页 (←)\",\n nextPage: \"下一页 (→)\",\n\n // Loading states\n loadingPreview: \"加载预览中...\",\n loadingRtf: \"正在解析 RTF...\",\n loadingSpreadsheet: \"正在解析表格...\",\n loadingEbook: \"Loading e-book...\",\n loadingPresentation: \"正在解析演示文稿...\",\n\n // Error states\n previewFailed: \"预览失败\",\n parseFailed: \"解析失败\",\n formatNotSupported: \"格式不支持\",\n\n // Legacy office formats\n legacyDocTitle: \"旧版 Word 格式暂不支持\",\n legacyPptTitle: \"旧版 PowerPoint 格式暂不支持\",\n legacyXlsTitle: \"旧版 Excel 格式暂不支持\",\n legacyDocDesc: \"该文件为旧版 .doc 二进制格式,当前浏览器端预览仅支持 .docx。建议使用 Word 或 WPS 将文件另存为 .docx 后重试。\",\n legacyPptDesc: \"该文件为旧版 .ppt 二进制格式,当前仅支持 Open XML 格式(.pptx)。建议使用 PowerPoint 或 WPS 将文件另存为 .pptx 格式后重试。\",\n legacyXlsDesc: \"该文件为旧版 .xls 二进制格式,当前仅支持 Open XML 格式(.xlsx/.xlsm)。建议使用 Excel 或 WPS 将文件另存为 .xlsx 格式后重试。\",\n legacyXlsFallbackDesc: \"当前文件为旧版 .xls 格式,部分内容可能无法完整显示。建议另存为 .xlsx 格式以获得最佳预览效果。\",\n legacyXlsError: \"该文件为旧版 Excel 二进制格式(.xls),当前仅支持 Open XML 格式(.xlsx/.xlsm)。建议使用 Excel 或 WPS 将文件另存为 .xlsx 格式后重试。\",\n legacyXlsBanner: \"旧版 Excel 格式暂不支持\",\n unsupportedFileType: \"该文件类型 ({fileType}) 暂不支持浏览器端预览。\",\n\n // Large file\n largeFileHint: \"当前文件较大,浏览器端解析可能需要更长时间,期间页面可能短暂卡顿。\",\n largeFile: \"大文件\",\n largeFileRows: \"行\",\n largeFileCols: \"列\",\n largeFileImages: \"张图片\",\n largeFileFastModeBanner: \"当前 Excel 文件较大({fileSize}),已默认使用快速模式:仅渲染前 {rowLimit} 行,并跳过图片解析。\",\n largeFileFidelityBanner: \"当前正在使用高保真模式预览大文件,可能导致浏览器卡顿。\",\n largeFileFidelityConfirm: \"当前 Excel 文件大小为 {fileSize},高保真模式可能导致浏览器卡顿甚至无响应。是否继续?\",\n truncatedRows: \"数据量较大,仅显示前 {shown} 行(共 {total} 行)\",\n\n // Spreadsheet\n sheetNotFound: \"未找到工作表\",\n fastMode: \"快速\",\n fidelityMode: \"高保真\",\n fastModeTitle: \"快速模式:限制行数,跳过图片和复杂样式\",\n fidelityModeTitle: \"高保真模式:保留样式、图片、批注\",\n noData: \"无数据\",\n noSearchResults: \"未找到匹配数据\",\n comment: \"批注\",\n unsupportedImageFormat: \"不支持的图片格式\",\n unknown: \"未知\",\n downloadOriginal: \"下载原文件\",\n\n // Plain text\n lines: \"行\",\n wordWrapOn: \"开启自动换行\",\n wordWrapOff: \"关闭自动换行\",\n copyContent: \"复制内容\",\n\n // Markdown\n oversizedCodeBlock: \"大代码块\",\n\n // RTF\n rtfFallback: \"富文本渲染不可用,已降级为纯文本预览\",\n rtfNoText: \"无法从文件中提取文本内容。\",\n showErrorDetails: \"查看错误详情\",\n\n // EPUB\n noChaptersFound: \"No Chapters Found\",\n ebookLoadFailed: \"Failed to Load E-book\",\n unknownError: \"未知错误\",\n tableOfContents: \"Table of Contents\",\n foundInChapters: \"Found in {count} chapter(s)\",\n noResultsFound: \"未找到结果\",\n searchPlaceholder: \"搜索...\",\n\n // Shared fallback\n previewNotAvailable: \"预览不可用\",\n failedToLoadPreview: \"预览加载失败\",\n failedToReadFile: \"文件读取失败\",\n loadingCancelled: \"加载已取消\",\n copyCode: \"复制代码\",\n};\n\n// ─── en-US ───\n\nexport const enUS: LocaleMessages = {\n // View mode bar\n preview: \"Preview\",\n source: \"Source\",\n split: \"Split\",\n\n // Common actions\n download: \"Download\",\n copy: \"Copy\",\n search: \"Search...\",\n zoomIn: \"Zoom In\",\n zoomOut: \"Zoom Out\",\n reset: \"Reset\",\n fullscreen: \"Fullscreen\",\n previous: \"Previous\",\n next: \"Next\",\n\n // Page / slide units\n page: \"page\",\n pages: \"pages\",\n slideView: \"Slide View\",\n gridView: \"Grid View\",\n previousPage: \"Previous Page (←)\",\n nextPage: \"Next Page (→)\",\n\n // Loading states\n loadingPreview: \"Loading preview...\",\n loadingRtf: \"Parsing RTF...\",\n loadingSpreadsheet: \"Parsing spreadsheet...\",\n loadingEbook: \"Loading e-book...\",\n loadingPresentation: \"Parsing presentation...\",\n\n // Error states\n previewFailed: \"Preview Failed\",\n parseFailed: \"Parse Failed\",\n formatNotSupported: \"Format Not Supported\",\n\n // Legacy office formats\n legacyDocTitle: \"Legacy Word format not supported\",\n legacyPptTitle: \"Legacy PowerPoint format not supported\",\n legacyXlsTitle: \"Legacy Excel format not supported\",\n legacyDocDesc: \"This file is in the legacy .doc binary format. Browser-side preview only supports .docx. Please use Word or WPS to save the file as .docx and try again.\",\n legacyPptDesc: \"This file is in the legacy .ppt binary format. Only the Open XML format (.pptx) is supported. Please use PowerPoint or WPS to save the file as .pptx and try again.\",\n legacyXlsDesc: \"This file is in the legacy .xls binary format. Only the Open XML format (.xlsx/.xlsm) is supported. Please use Excel or WPS to save the file as .xlsx and try again.\",\n legacyXlsFallbackDesc: \"This file is in the legacy .xls format. Some content may not display correctly. Please save as .xlsx for the best preview experience.\",\n legacyXlsError: \"This file is in the legacy .xls binary format. Only the Open XML format (.xlsx/.xlsm) is supported. Please use Excel or WPS to save the file as .xlsx and try again.\",\n legacyXlsBanner: \"Legacy Excel format not supported\",\n unsupportedFileType: \"File type ({fileType}) is not supported for browser-side preview.\",\n\n // Large file\n largeFileHint: \"This file is large. Browser-side parsing may take longer and the page may briefly freeze.\",\n largeFile: \"Large File\",\n largeFileRows: \"rows\",\n largeFileCols: \"cols\",\n largeFileImages: \"images\",\n largeFileFastModeBanner: \"This Excel file is large ({fileSize}). Fast mode is enabled by default: only the first {rowLimit} rows are rendered and image parsing is skipped.\",\n largeFileFidelityBanner: \"You are using fidelity mode to preview a large file. This may cause the browser to freeze.\",\n largeFileFidelityConfirm: \"This Excel file is {fileSize}. Fidelity mode may cause the browser to freeze or become unresponsive. Continue?\",\n truncatedRows: \"Data is large. Showing first {shown} of {total} rows\",\n\n // Spreadsheet\n sheetNotFound: \"No Sheets Found\",\n fastMode: \"Fast\",\n fidelityMode: \"Fidelity\",\n fastModeTitle: \"Fast mode: limited rows, skip images and complex styles\",\n fidelityModeTitle: \"Fidelity mode: preserve styles, images, and comments\",\n noData: \"No data\",\n noSearchResults: \"No matching data found\",\n comment: \"Comment\",\n unsupportedImageFormat: \"Unsupported image format\",\n unknown: \"Unknown\",\n downloadOriginal: \"Download Original\",\n\n // Plain text\n lines: \"lines\",\n wordWrapOn: \"Enable word wrap\",\n wordWrapOff: \"Disable word wrap\",\n copyContent: \"Copy content\",\n\n // Markdown\n oversizedCodeBlock: \"Large code block\",\n\n // RTF\n rtfFallback: \"Rich text rendering unavailable, fallback to plain text preview\",\n rtfNoText: \"Unable to extract text content from file.\",\n showErrorDetails: \"Show error details\",\n\n // EPUB\n noChaptersFound: \"No Chapters Found\",\n ebookLoadFailed: \"Failed to Load E-book\",\n unknownError: \"Unknown error\",\n tableOfContents: \"Table of Contents\",\n foundInChapters: \"Found in {count} chapter(s)\",\n noResultsFound: \"No results found\",\n searchPlaceholder: \"Search...\",\n\n // Shared fallback\n previewNotAvailable: \"Preview Not Available\",\n failedToLoadPreview: \"Failed to Load Preview\",\n failedToReadFile: \"Failed to Read File\",\n loadingCancelled: \"Loading Cancelled\",\n copyCode: \"Copy code\",\n};\n\n// ─── Context ───\n\nimport { createContext, useContext } from \"react\";\n\nconst defaultLocale = zhCN;\n\nconst LocaleContext = createContext<LocaleMessages>(defaultLocale);\n\n/** Provider component — wrap your preview tree with this to override locale. */\nexport const LocaleProvider = LocaleContext.Provider;\n\n/** Hook to access the current locale messages. */\nexport function useLocale(): LocaleMessages {\n return useContext(LocaleContext);\n}\n\n/** Get the default locale (zh-CN). */\nexport function getDefaultLocale(): LocaleMessages {\n return defaultLocale;\n}\n"],"mappings":"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","names":[]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ComponentType } from 'react';
|
|
2
|
+
import { FileInfo } from './types.js';
|
|
3
|
+
|
|
4
|
+
interface PreviewPlugin {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
priority?: number;
|
|
8
|
+
match(file: FileInfo): boolean;
|
|
9
|
+
load(): Promise<{
|
|
10
|
+
default: ComponentType<{
|
|
11
|
+
file: FileInfo;
|
|
12
|
+
}>;
|
|
13
|
+
}>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Wrap a dynamic-import loader so that, if the import fails because an
|
|
17
|
+
* optional peer dependency is missing (e.g. `pdfjs-dist`, `exceljs`), the
|
|
18
|
+
* user sees a clear "install this package" message instead of the raw
|
|
19
|
+
* bundler error.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* load: loadWithOptionalDep(
|
|
23
|
+
* () => import("../preview-adapters/PdfPreviewAdapter"),
|
|
24
|
+
* { package: "pdfjs-dist", featureLabel: "PDF preview" },
|
|
25
|
+
* )
|
|
26
|
+
*/
|
|
27
|
+
declare function loadWithOptionalDep<T>(loader: () => Promise<T>, meta: {
|
|
28
|
+
package: string;
|
|
29
|
+
featureLabel: string;
|
|
30
|
+
}): () => Promise<T>;
|
|
31
|
+
declare class MissingPeerDependencyError extends Error {
|
|
32
|
+
packageName: string;
|
|
33
|
+
featureLabel: string;
|
|
34
|
+
cause: unknown;
|
|
35
|
+
constructor(packageName: string, featureLabel: string, cause: unknown);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { MissingPeerDependencyError, type PreviewPlugin, loadWithOptionalDep };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
function loadWithOptionalDep(loader, meta) {
|
|
2
|
+
return async () => {
|
|
3
|
+
try {
|
|
4
|
+
return await loader();
|
|
5
|
+
} catch (cause) {
|
|
6
|
+
if (isModuleNotFoundError(cause, meta.package)) {
|
|
7
|
+
throw new MissingPeerDependencyError(meta.package, meta.featureLabel, cause);
|
|
8
|
+
}
|
|
9
|
+
throw cause;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
class MissingPeerDependencyError extends Error {
|
|
14
|
+
constructor(packageName, featureLabel, cause) {
|
|
15
|
+
super(
|
|
16
|
+
`${featureLabel} requires the optional peer dependency "${packageName}".
|
|
17
|
+
|
|
18
|
+
Install it in your app:
|
|
19
|
+
pnpm add ${packageName}
|
|
20
|
+
# or: npm install ${packageName}
|
|
21
|
+
# or: yarn add ${packageName}
|
|
22
|
+
|
|
23
|
+
See: https://github.com/CoderLambert/filevista/tree/main/packages/file-preview#optional-peer-dependencies`
|
|
24
|
+
);
|
|
25
|
+
this.packageName = packageName;
|
|
26
|
+
this.featureLabel = featureLabel;
|
|
27
|
+
this.cause = cause;
|
|
28
|
+
this.name = "MissingPeerDependencyError";
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function isModuleNotFoundError(error, packageName) {
|
|
32
|
+
if (!(error instanceof Error)) return false;
|
|
33
|
+
const message = error.message ?? "";
|
|
34
|
+
if (!message) return false;
|
|
35
|
+
if (!message.includes(packageName)) return false;
|
|
36
|
+
return message.includes("Cannot find module") || // Node ESM, Webpack
|
|
37
|
+
message.includes("Failed to fetch dynamically imported module") || // Native browser ESM
|
|
38
|
+
message.includes("Failed to resolve module specifier") || // Vite dev
|
|
39
|
+
message.includes("Module not found") || // Webpack production
|
|
40
|
+
message.includes("Unable to resolve");
|
|
41
|
+
}
|
|
42
|
+
export {
|
|
43
|
+
MissingPeerDependencyError,
|
|
44
|
+
loadWithOptionalDep
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/plugin.ts"],"sourcesContent":["import type { ComponentType } from \"react\";\nimport type { FileInfo } from \"../utils\";\n\nexport interface PreviewPlugin {\n id: string;\n name: string;\n priority?: number;\n match(file: FileInfo): boolean;\n load(): Promise<{ default: ComponentType<{ file: FileInfo }> }>;\n}\n\n/**\n * Wrap a dynamic-import loader so that, if the import fails because an\n * optional peer dependency is missing (e.g. `pdfjs-dist`, `exceljs`), the\n * user sees a clear \"install this package\" message instead of the raw\n * bundler error.\n *\n * @example\n * load: loadWithOptionalDep(\n * () => import(\"../preview-adapters/PdfPreviewAdapter\"),\n * { package: \"pdfjs-dist\", featureLabel: \"PDF preview\" },\n * )\n */\nexport function loadWithOptionalDep<T>(\n loader: () => Promise<T>,\n meta: { package: string; featureLabel: string },\n): () => Promise<T> {\n return async () => {\n try {\n return await loader();\n } catch (cause) {\n if (isModuleNotFoundError(cause, meta.package)) {\n throw new MissingPeerDependencyError(meta.package, meta.featureLabel, cause);\n }\n throw cause;\n }\n };\n}\n\nexport class MissingPeerDependencyError extends Error {\n constructor(\n public packageName: string,\n public featureLabel: string,\n public cause: unknown,\n ) {\n super(\n `${featureLabel} requires the optional peer dependency \"${packageName}\".\\n\\n` +\n `Install it in your app:\\n` +\n ` pnpm add ${packageName}\\n` +\n ` # or: npm install ${packageName}\\n` +\n ` # or: yarn add ${packageName}\\n\\n` +\n `See: https://github.com/CoderLambert/filevista/tree/main/packages/file-preview#optional-peer-dependencies`,\n );\n this.name = \"MissingPeerDependencyError\";\n }\n}\n\n/**\n * Detect \"module not found\" failures across the bundlers/runtimes our users\n * are likely on — Webpack, Turbopack, Vite, native ESM, esbuild.\n *\n * We deliberately match loosely. False positives are cheap (the install hint\n * is always actionable) but false negatives swallow the affordance.\n */\nfunction isModuleNotFoundError(error: unknown, packageName: string): boolean {\n if (!(error instanceof Error)) return false;\n const message = error.message ?? \"\";\n if (!message) return false;\n\n // The package name must appear in the message — otherwise we're attributing\n // an unrelated error to the wrong dependency.\n if (!message.includes(packageName)) return false;\n\n return (\n message.includes(\"Cannot find module\") || // Node ESM, Webpack\n message.includes(\"Failed to fetch dynamically imported module\") || // Native browser ESM\n message.includes(\"Failed to resolve module specifier\") || // Vite dev\n message.includes(\"Module not found\") || // Webpack production\n message.includes(\"Unable to resolve\") // Metro / some bundlers\n );\n}\n"],"mappings":"AAuBO,SAAS,oBACd,QACA,MACkB;AAClB,SAAO,YAAY;AACjB,QAAI;AACF,aAAO,MAAM,OAAO;AAAA,IACtB,SAAS,OAAO;AACd,UAAI,sBAAsB,OAAO,KAAK,OAAO,GAAG;AAC9C,cAAM,IAAI,2BAA2B,KAAK,SAAS,KAAK,cAAc,KAAK;AAAA,MAC7E;AACA,YAAM;AAAA,IACR;AAAA,EACF;AACF;AAEO,MAAM,mCAAmC,MAAM;AAAA,EACpD,YACS,aACA,cACA,OACP;AACA;AAAA,MACE,GAAG,YAAY,2CAA2C,WAAW;AAAA;AAAA;AAAA,aAErD,WAAW;AAAA,sBACF,WAAW;AAAA,mBACd,WAAW;AAAA;AAAA;AAAA,IAEnC;AAXO;AACA;AACA;AAUP,SAAK,OAAO;AAAA,EACd;AACF;AASA,SAAS,sBAAsB,OAAgB,aAA8B;AAC3E,MAAI,EAAE,iBAAiB,OAAQ,QAAO;AACtC,QAAM,UAAU,MAAM,WAAW;AACjC,MAAI,CAAC,QAAS,QAAO;AAIrB,MAAI,CAAC,QAAQ,SAAS,WAAW,EAAG,QAAO;AAE3C,SACE,QAAQ,SAAS,oBAAoB;AAAA,EACrC,QAAQ,SAAS,6CAA6C;AAAA,EAC9D,QAAQ,SAAS,oCAAoC;AAAA,EACrD,QAAQ,SAAS,kBAAkB;AAAA,EACnC,QAAQ,SAAS,mBAAmB;AAExC;","names":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FileInfo } from './types.js';
|
|
2
|
+
import { PreviewPlugin } from './plugin.js';
|
|
3
|
+
import 'react';
|
|
4
|
+
|
|
5
|
+
declare class PreviewPluginRegistry {
|
|
6
|
+
private plugins;
|
|
7
|
+
register(plugin: PreviewPlugin): void;
|
|
8
|
+
resolve(file: FileInfo): PreviewPlugin | null;
|
|
9
|
+
list(): PreviewPlugin[];
|
|
10
|
+
}
|
|
11
|
+
declare function createPreviewPluginRegistry(plugins: PreviewPlugin[]): PreviewPluginRegistry;
|
|
12
|
+
|
|
13
|
+
export { PreviewPluginRegistry, createPreviewPluginRegistry };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
class PreviewPluginRegistry {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.plugins = [];
|
|
4
|
+
}
|
|
5
|
+
register(plugin) {
|
|
6
|
+
const existingIndex = this.plugins.findIndex((item) => item.id === plugin.id);
|
|
7
|
+
if (existingIndex >= 0) {
|
|
8
|
+
this.plugins[existingIndex] = plugin;
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
this.plugins.push(plugin);
|
|
12
|
+
}
|
|
13
|
+
resolve(file) {
|
|
14
|
+
return this.list().find((plugin) => plugin.match(file)) ?? null;
|
|
15
|
+
}
|
|
16
|
+
list() {
|
|
17
|
+
return [...this.plugins].sort(
|
|
18
|
+
(a, b) => (b.priority ?? 0) - (a.priority ?? 0)
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function createPreviewPluginRegistry(plugins) {
|
|
23
|
+
const registry = new PreviewPluginRegistry();
|
|
24
|
+
for (const plugin of plugins) {
|
|
25
|
+
registry.register(plugin);
|
|
26
|
+
}
|
|
27
|
+
return registry;
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
PreviewPluginRegistry,
|
|
31
|
+
createPreviewPluginRegistry
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/registry.ts"],"sourcesContent":["import type { FileInfo } from \"../utils\";\nimport type { PreviewPlugin } from \"./plugin\";\n\nexport class PreviewPluginRegistry {\n private plugins: PreviewPlugin[] = [];\n\n register(plugin: PreviewPlugin): void {\n const existingIndex = this.plugins.findIndex((item) => item.id === plugin.id);\n\n if (existingIndex >= 0) {\n this.plugins[existingIndex] = plugin;\n return;\n }\n\n this.plugins.push(plugin);\n }\n\n resolve(file: FileInfo): PreviewPlugin | null {\n return this.list().find((plugin) => plugin.match(file)) ?? null;\n }\n\n list(): PreviewPlugin[] {\n return [...this.plugins].sort(\n (a, b) => (b.priority ?? 0) - (a.priority ?? 0)\n );\n }\n}\n\nexport function createPreviewPluginRegistry(\n plugins: PreviewPlugin[]\n): PreviewPluginRegistry {\n const registry = new PreviewPluginRegistry();\n\n for (const plugin of plugins) {\n registry.register(plugin);\n }\n\n return registry;\n}"],"mappings":"AAGO,MAAM,sBAAsB;AAAA,EAA5B;AACL,SAAQ,UAA2B,CAAC;AAAA;AAAA,EAEpC,SAAS,QAA6B;AACpC,UAAM,gBAAgB,KAAK,QAAQ,UAAU,CAAC,SAAS,KAAK,OAAO,OAAO,EAAE;AAE5E,QAAI,iBAAiB,GAAG;AACtB,WAAK,QAAQ,aAAa,IAAI;AAC9B;AAAA,IACF;AAEA,SAAK,QAAQ,KAAK,MAAM;AAAA,EAC1B;AAAA,EAEA,QAAQ,MAAsC;AAC5C,WAAO,KAAK,KAAK,EAAE,KAAK,CAAC,WAAW,OAAO,MAAM,IAAI,CAAC,KAAK;AAAA,EAC7D;AAAA,EAEA,OAAwB;AACtB,WAAO,CAAC,GAAG,KAAK,OAAO,EAAE;AAAA,MACvB,CAAC,GAAG,OAAO,EAAE,YAAY,MAAM,EAAE,YAAY;AAAA,IAC/C;AAAA,EACF;AACF;AAEO,SAAS,4BACd,SACuB;AACvB,QAAM,WAAW,IAAI,sBAAsB;AAE3C,aAAW,UAAU,SAAS;AAC5B,aAAS,SAAS,MAAM;AAAA,EAC1B;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PreviewSource } from './types.js';
|
|
2
|
+
|
|
3
|
+
interface ReadSourceOptions {
|
|
4
|
+
signal?: AbortSignal;
|
|
5
|
+
}
|
|
6
|
+
declare function readSourceAsArrayBuffer(source: PreviewSource, options?: ReadSourceOptions): Promise<ArrayBuffer>;
|
|
7
|
+
declare function readSourceAsText(source: PreviewSource, options?: ReadSourceOptions): Promise<string>;
|
|
8
|
+
declare function readSourceAsBase64(source: PreviewSource, options?: ReadSourceOptions): Promise<string>;
|
|
9
|
+
declare function createObjectUrlFromSource(source: PreviewSource): string | null;
|
|
10
|
+
declare function getSourceName(source: PreviewSource): string | undefined;
|
|
11
|
+
declare function getSourceMimeType(source: PreviewSource): string | undefined;
|
|
12
|
+
declare function getSourceSize(source: PreviewSource): number | undefined;
|
|
13
|
+
|
|
14
|
+
export { type ReadSourceOptions, createObjectUrlFromSource, getSourceMimeType, getSourceName, getSourceSize, readSourceAsArrayBuffer, readSourceAsBase64, readSourceAsText };
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
async function readSourceAsArrayBuffer(source, options = {}) {
|
|
2
|
+
switch (source.kind) {
|
|
3
|
+
case "file":
|
|
4
|
+
if (options.signal?.aborted) {
|
|
5
|
+
throw new DOMException("The operation was aborted.", "AbortError");
|
|
6
|
+
}
|
|
7
|
+
return source.file.arrayBuffer();
|
|
8
|
+
case "blob":
|
|
9
|
+
if (options.signal?.aborted) {
|
|
10
|
+
throw new DOMException("The operation was aborted.", "AbortError");
|
|
11
|
+
}
|
|
12
|
+
return source.blob.arrayBuffer();
|
|
13
|
+
case "arrayBuffer":
|
|
14
|
+
if (options.signal?.aborted) {
|
|
15
|
+
throw new DOMException("The operation was aborted.", "AbortError");
|
|
16
|
+
}
|
|
17
|
+
return source.buffer;
|
|
18
|
+
case "url": {
|
|
19
|
+
const response = await fetch(source.url, {
|
|
20
|
+
headers: source.headers,
|
|
21
|
+
signal: options.signal
|
|
22
|
+
});
|
|
23
|
+
if (!response.ok) {
|
|
24
|
+
throw new Error(`Failed to fetch file: ${response.status}`);
|
|
25
|
+
}
|
|
26
|
+
return response.arrayBuffer();
|
|
27
|
+
}
|
|
28
|
+
default:
|
|
29
|
+
throw new Error("Unsupported preview source");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async function readSourceAsText(source, options = {}) {
|
|
33
|
+
switch (source.kind) {
|
|
34
|
+
case "file":
|
|
35
|
+
if (options.signal?.aborted) {
|
|
36
|
+
throw new DOMException("The operation was aborted.", "AbortError");
|
|
37
|
+
}
|
|
38
|
+
return source.file.text();
|
|
39
|
+
case "blob":
|
|
40
|
+
if (options.signal?.aborted) {
|
|
41
|
+
throw new DOMException("The operation was aborted.", "AbortError");
|
|
42
|
+
}
|
|
43
|
+
return source.blob.text();
|
|
44
|
+
case "arrayBuffer":
|
|
45
|
+
if (options.signal?.aborted) {
|
|
46
|
+
throw new DOMException("The operation was aborted.", "AbortError");
|
|
47
|
+
}
|
|
48
|
+
return new TextDecoder("utf-8").decode(source.buffer);
|
|
49
|
+
case "url": {
|
|
50
|
+
const response = await fetch(source.url, {
|
|
51
|
+
headers: source.headers,
|
|
52
|
+
signal: options.signal
|
|
53
|
+
});
|
|
54
|
+
if (!response.ok) {
|
|
55
|
+
throw new Error(`Failed to fetch text: ${response.status}`);
|
|
56
|
+
}
|
|
57
|
+
return response.text();
|
|
58
|
+
}
|
|
59
|
+
default:
|
|
60
|
+
throw new Error("Unsupported preview source");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async function readSourceAsBase64(source, options = {}) {
|
|
64
|
+
const buffer = await readSourceAsArrayBuffer(source, options);
|
|
65
|
+
const bytes = new Uint8Array(buffer);
|
|
66
|
+
let binary = "";
|
|
67
|
+
for (let i = 0; i < bytes.length; i += 8192) {
|
|
68
|
+
const chunk = bytes.subarray(i, Math.min(i + 8192, bytes.length));
|
|
69
|
+
binary += String.fromCharCode(...chunk);
|
|
70
|
+
}
|
|
71
|
+
return btoa(binary);
|
|
72
|
+
}
|
|
73
|
+
function createObjectUrlFromSource(source) {
|
|
74
|
+
if (source.kind === "file") {
|
|
75
|
+
return URL.createObjectURL(source.file);
|
|
76
|
+
}
|
|
77
|
+
if (source.kind === "blob") {
|
|
78
|
+
return URL.createObjectURL(source.blob);
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
function getSourceName(source) {
|
|
83
|
+
switch (source.kind) {
|
|
84
|
+
case "file":
|
|
85
|
+
return source.file.name;
|
|
86
|
+
case "blob":
|
|
87
|
+
case "arrayBuffer":
|
|
88
|
+
return source.name;
|
|
89
|
+
case "url":
|
|
90
|
+
return source.name || source.url.split("/").pop();
|
|
91
|
+
default:
|
|
92
|
+
return void 0;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function getSourceMimeType(source) {
|
|
96
|
+
switch (source.kind) {
|
|
97
|
+
case "file":
|
|
98
|
+
return source.file.type;
|
|
99
|
+
case "blob":
|
|
100
|
+
return source.mimeType || source.blob.type;
|
|
101
|
+
case "arrayBuffer":
|
|
102
|
+
case "url":
|
|
103
|
+
return source.mimeType;
|
|
104
|
+
default:
|
|
105
|
+
return void 0;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function getSourceSize(source) {
|
|
109
|
+
switch (source.kind) {
|
|
110
|
+
case "file":
|
|
111
|
+
return source.file.size;
|
|
112
|
+
case "blob":
|
|
113
|
+
return source.blob.size;
|
|
114
|
+
case "arrayBuffer":
|
|
115
|
+
return source.buffer.byteLength;
|
|
116
|
+
case "url":
|
|
117
|
+
return void 0;
|
|
118
|
+
default:
|
|
119
|
+
return void 0;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
export {
|
|
123
|
+
createObjectUrlFromSource,
|
|
124
|
+
getSourceMimeType,
|
|
125
|
+
getSourceName,
|
|
126
|
+
getSourceSize,
|
|
127
|
+
readSourceAsArrayBuffer,
|
|
128
|
+
readSourceAsBase64,
|
|
129
|
+
readSourceAsText
|
|
130
|
+
};
|
|
131
|
+
//# sourceMappingURL=source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/source.ts"],"sourcesContent":["import type { PreviewSource } from \"./types\";\n\nexport interface ReadSourceOptions {\n signal?: AbortSignal;\n}\n\nexport async function readSourceAsArrayBuffer(\n source: PreviewSource,\n options: ReadSourceOptions = {}\n): Promise<ArrayBuffer> {\n switch (source.kind) {\n case \"file\":\n if (options.signal?.aborted) {\n throw new DOMException(\"The operation was aborted.\", \"AbortError\");\n }\n return source.file.arrayBuffer();\n\n case \"blob\":\n if (options.signal?.aborted) {\n throw new DOMException(\"The operation was aborted.\", \"AbortError\");\n }\n return source.blob.arrayBuffer();\n\n case \"arrayBuffer\":\n if (options.signal?.aborted) {\n throw new DOMException(\"The operation was aborted.\", \"AbortError\");\n }\n return source.buffer;\n\n case \"url\": {\n const response = await fetch(source.url, {\n headers: source.headers,\n signal: options.signal,\n });\n\n if (!response.ok) {\n throw new Error(`Failed to fetch file: ${response.status}`);\n }\n\n return response.arrayBuffer();\n }\n\n default:\n throw new Error(\"Unsupported preview source\");\n }\n}\n\nexport async function readSourceAsText(\n source: PreviewSource,\n options: ReadSourceOptions = {}\n): Promise<string> {\n switch (source.kind) {\n case \"file\":\n if (options.signal?.aborted) {\n throw new DOMException(\"The operation was aborted.\", \"AbortError\");\n }\n return source.file.text();\n\n case \"blob\":\n if (options.signal?.aborted) {\n throw new DOMException(\"The operation was aborted.\", \"AbortError\");\n }\n return source.blob.text();\n\n case \"arrayBuffer\":\n if (options.signal?.aborted) {\n throw new DOMException(\"The operation was aborted.\", \"AbortError\");\n }\n return new TextDecoder(\"utf-8\").decode(source.buffer);\n\n case \"url\": {\n const response = await fetch(source.url, {\n headers: source.headers,\n signal: options.signal,\n });\n\n if (!response.ok) {\n throw new Error(`Failed to fetch text: ${response.status}`);\n }\n\n return response.text();\n }\n\n default:\n throw new Error(\"Unsupported preview source\");\n }\n}\n\nexport async function readSourceAsBase64(\n source: PreviewSource,\n options: ReadSourceOptions = {}\n): Promise<string> {\n const buffer = await readSourceAsArrayBuffer(source, options);\n const bytes = new Uint8Array(buffer);\n\n let binary = \"\";\n for (let i = 0; i < bytes.length; i += 8192) {\n const chunk = bytes.subarray(i, Math.min(i + 8192, bytes.length));\n binary += String.fromCharCode(...chunk);\n }\n\n return btoa(binary);\n}\n\nexport function createObjectUrlFromSource(source: PreviewSource): string | null {\n if (source.kind === \"file\") {\n return URL.createObjectURL(source.file);\n }\n\n if (source.kind === \"blob\") {\n return URL.createObjectURL(source.blob);\n }\n\n return null;\n}\n\nexport function getSourceName(source: PreviewSource): string | undefined {\n switch (source.kind) {\n case \"file\":\n return source.file.name;\n\n case \"blob\":\n case \"arrayBuffer\":\n return source.name;\n\n case \"url\":\n return source.name || source.url.split(\"/\").pop();\n\n default:\n return undefined;\n }\n}\n\nexport function getSourceMimeType(source: PreviewSource): string | undefined {\n switch (source.kind) {\n case \"file\":\n return source.file.type;\n\n case \"blob\":\n return source.mimeType || source.blob.type;\n\n case \"arrayBuffer\":\n case \"url\":\n return source.mimeType;\n\n default:\n return undefined;\n }\n}\n\nexport function getSourceSize(source: PreviewSource): number | undefined {\n switch (source.kind) {\n case \"file\":\n return source.file.size;\n\n case \"blob\":\n return source.blob.size;\n\n case \"arrayBuffer\":\n return source.buffer.byteLength;\n\n case \"url\":\n return undefined;\n\n default:\n return undefined;\n }\n}\n"],"mappings":"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","names":[]}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core types for the preview pipeline.
|
|
3
|
+
*
|
|
4
|
+
* Kept dependency-free so that {@link PreviewSource}, {@link NormalizedFile},
|
|
5
|
+
* {@link FileInfo}, and the {@link FileType} union can be shared between the
|
|
6
|
+
* runtime helpers in `utils.ts` and the plugin/registry layer without forming
|
|
7
|
+
* a cycle.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Canonical file-type tags recognized by the built-in plugin registry.
|
|
11
|
+
* Use {@link detectFileType} (in `utils`) to map a filename + MIME pair to one
|
|
12
|
+
* of these values.
|
|
13
|
+
*/
|
|
14
|
+
declare const ALL_FILE_TYPES: readonly ["pdf", "markdown", "json", "code", "docx", "doc", "pptx", "ppt", "xlsx", "xls", "html", "zip", "svg", "rtf", "epub", "image", "text", "csv", "video", "audio", "unknown"];
|
|
15
|
+
type FileType = (typeof ALL_FILE_TYPES)[number];
|
|
16
|
+
/**
|
|
17
|
+
* Source abstraction read by every preview plugin.
|
|
18
|
+
*
|
|
19
|
+
* Plugins should never touch raw `File`/`Blob`/`ArrayBuffer`/URL directly —
|
|
20
|
+
* always go through `readSourceAsText` / `readSourceAsArrayBuffer` / the
|
|
21
|
+
* matching React hooks. That keeps consumers free to mix local uploads,
|
|
22
|
+
* blobs, decoded buffers, and remote URLs without each plugin re-deriving
|
|
23
|
+
* the data path.
|
|
24
|
+
*/
|
|
25
|
+
type PreviewSource = {
|
|
26
|
+
kind: "file";
|
|
27
|
+
file: File;
|
|
28
|
+
} | {
|
|
29
|
+
kind: "blob";
|
|
30
|
+
blob: Blob;
|
|
31
|
+
name?: string;
|
|
32
|
+
mimeType?: string;
|
|
33
|
+
} | {
|
|
34
|
+
kind: "arrayBuffer";
|
|
35
|
+
buffer: ArrayBuffer;
|
|
36
|
+
name?: string;
|
|
37
|
+
mimeType?: string;
|
|
38
|
+
} | {
|
|
39
|
+
kind: "url";
|
|
40
|
+
url: string;
|
|
41
|
+
name?: string;
|
|
42
|
+
mimeType?: string;
|
|
43
|
+
headers?: Record<string, string>;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* The shape consumers pass into `<PluginPreviewRenderer file={...} />`.
|
|
47
|
+
*
|
|
48
|
+
* `source` is the only field the plugin pipeline reads. The legacy `content`
|
|
49
|
+
* and `url` fields exist for pre-Stage-18 callers and will be removed in a
|
|
50
|
+
* future major.
|
|
51
|
+
*/
|
|
52
|
+
interface FileInfo {
|
|
53
|
+
id: string;
|
|
54
|
+
name: string;
|
|
55
|
+
size: number;
|
|
56
|
+
type: string;
|
|
57
|
+
fileType: FileType;
|
|
58
|
+
/**
|
|
59
|
+
* Primary source abstraction. Mandatory in Stage 18+.
|
|
60
|
+
* Read via `readSourceAsText` / `readSourceAsArrayBuffer` from `core/source`.
|
|
61
|
+
*/
|
|
62
|
+
source: PreviewSource;
|
|
63
|
+
/**
|
|
64
|
+
* @deprecated Use `source` + `readSourceAsText`/`readSourceAsArrayBuffer`.
|
|
65
|
+
* Compatibility field for legacy preview components.
|
|
66
|
+
*/
|
|
67
|
+
content?: string | null;
|
|
68
|
+
/**
|
|
69
|
+
* @deprecated Use `source` or an adapter-local object URL.
|
|
70
|
+
* Compatibility field for legacy media preview components.
|
|
71
|
+
*/
|
|
72
|
+
url?: string | null;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Slimmer normalized representation used by the registry / plugin internals.
|
|
76
|
+
* Most consumers should work with {@link FileInfo} instead.
|
|
77
|
+
*/
|
|
78
|
+
interface NormalizedFile {
|
|
79
|
+
id: string;
|
|
80
|
+
name: string;
|
|
81
|
+
size?: number;
|
|
82
|
+
mimeType?: string;
|
|
83
|
+
extension?: string;
|
|
84
|
+
fileType: FileType;
|
|
85
|
+
source: PreviewSource;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export { ALL_FILE_TYPES, type FileInfo, type FileType, type NormalizedFile, type PreviewSource };
|