@eternalheart/react-file-preview 1.0.0 → 1.0.2
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/README.md +69 -0
- package/README.zh-CN.md +69 -0
- package/lib/FilePreviewModal.d.ts +2 -1
- package/lib/FilePreviewModal.d.ts.map +1 -1
- package/lib/index.cjs +1 -1
- package/lib/index.cjs.map +1 -1
- package/lib/index.css +1 -1
- package/lib/index.d.ts +5 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.mjs +494 -478
- package/lib/index.mjs.map +1 -1
- package/lib/pdfjs/cmaps/78-EUC-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/78-EUC-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/78-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/78-RKSJ-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/78-RKSJ-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/78-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/78ms-RKSJ-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/78ms-RKSJ-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/83pv-RKSJ-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/90ms-RKSJ-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/90ms-RKSJ-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/90msp-RKSJ-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/90msp-RKSJ-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/90pv-RKSJ-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/90pv-RKSJ-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/Add-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/Add-RKSJ-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/Add-RKSJ-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/Add-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/Adobe-CNS1-0.bcmap +0 -0
- package/lib/pdfjs/cmaps/Adobe-CNS1-1.bcmap +0 -0
- package/lib/pdfjs/cmaps/Adobe-CNS1-2.bcmap +0 -0
- package/lib/pdfjs/cmaps/Adobe-CNS1-3.bcmap +0 -0
- package/lib/pdfjs/cmaps/Adobe-CNS1-4.bcmap +0 -0
- package/lib/pdfjs/cmaps/Adobe-CNS1-5.bcmap +0 -0
- package/lib/pdfjs/cmaps/Adobe-CNS1-6.bcmap +0 -0
- package/lib/pdfjs/cmaps/Adobe-CNS1-UCS2.bcmap +0 -0
- package/lib/pdfjs/cmaps/Adobe-GB1-0.bcmap +0 -0
- package/lib/pdfjs/cmaps/Adobe-GB1-1.bcmap +0 -0
- package/lib/pdfjs/cmaps/Adobe-GB1-2.bcmap +0 -0
- package/lib/pdfjs/cmaps/Adobe-GB1-3.bcmap +0 -0
- package/lib/pdfjs/cmaps/Adobe-GB1-4.bcmap +0 -0
- package/lib/pdfjs/cmaps/Adobe-GB1-5.bcmap +0 -0
- package/lib/pdfjs/cmaps/Adobe-GB1-UCS2.bcmap +0 -0
- package/lib/pdfjs/cmaps/Adobe-Japan1-0.bcmap +0 -0
- package/lib/pdfjs/cmaps/Adobe-Japan1-1.bcmap +0 -0
- package/lib/pdfjs/cmaps/Adobe-Japan1-2.bcmap +0 -0
- package/lib/pdfjs/cmaps/Adobe-Japan1-3.bcmap +0 -0
- package/lib/pdfjs/cmaps/Adobe-Japan1-4.bcmap +0 -0
- package/lib/pdfjs/cmaps/Adobe-Japan1-5.bcmap +0 -0
- package/lib/pdfjs/cmaps/Adobe-Japan1-6.bcmap +0 -0
- package/lib/pdfjs/cmaps/Adobe-Japan1-UCS2.bcmap +0 -0
- package/lib/pdfjs/cmaps/Adobe-Korea1-0.bcmap +0 -0
- package/lib/pdfjs/cmaps/Adobe-Korea1-1.bcmap +0 -0
- package/lib/pdfjs/cmaps/Adobe-Korea1-2.bcmap +0 -0
- package/lib/pdfjs/cmaps/Adobe-Korea1-UCS2.bcmap +0 -0
- package/lib/pdfjs/cmaps/B5-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/B5-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/B5pc-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/B5pc-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/CNS-EUC-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/CNS-EUC-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/CNS1-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/CNS1-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/CNS2-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/CNS2-V.bcmap +3 -0
- package/lib/pdfjs/cmaps/ETHK-B5-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/ETHK-B5-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/ETen-B5-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/ETen-B5-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/ETenms-B5-H.bcmap +3 -0
- package/lib/pdfjs/cmaps/ETenms-B5-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/EUC-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/EUC-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/Ext-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/Ext-RKSJ-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/Ext-RKSJ-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/Ext-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/GB-EUC-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/GB-EUC-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/GB-H.bcmap +4 -0
- package/lib/pdfjs/cmaps/GB-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/GBK-EUC-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/GBK-EUC-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/GBK2K-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/GBK2K-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/GBKp-EUC-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/GBKp-EUC-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/GBT-EUC-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/GBT-EUC-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/GBT-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/GBT-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/GBTpc-EUC-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/GBTpc-EUC-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/GBpc-EUC-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/GBpc-EUC-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/H.bcmap +0 -0
- package/lib/pdfjs/cmaps/HKdla-B5-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/HKdla-B5-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/HKdlb-B5-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/HKdlb-B5-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/HKgccs-B5-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/HKgccs-B5-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/HKm314-B5-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/HKm314-B5-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/HKm471-B5-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/HKm471-B5-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/HKscs-B5-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/HKscs-B5-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/Hankaku.bcmap +0 -0
- package/lib/pdfjs/cmaps/Hiragana.bcmap +0 -0
- package/lib/pdfjs/cmaps/KSC-EUC-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/KSC-EUC-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/KSC-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/KSC-Johab-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/KSC-Johab-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/KSC-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/KSCms-UHC-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/KSCms-UHC-HW-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/KSCms-UHC-HW-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/KSCms-UHC-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/KSCpc-EUC-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/KSCpc-EUC-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/Katakana.bcmap +0 -0
- package/lib/pdfjs/cmaps/LICENSE +36 -0
- package/lib/pdfjs/cmaps/NWP-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/NWP-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/RKSJ-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/RKSJ-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/Roman.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniCNS-UCS2-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniCNS-UCS2-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniCNS-UTF16-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniCNS-UTF16-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniCNS-UTF32-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniCNS-UTF32-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniCNS-UTF8-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniCNS-UTF8-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniGB-UCS2-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniGB-UCS2-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniGB-UTF16-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniGB-UTF16-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniGB-UTF32-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniGB-UTF32-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniGB-UTF8-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniGB-UTF8-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniJIS-UCS2-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniJIS-UCS2-HW-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniJIS-UCS2-HW-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniJIS-UCS2-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniJIS-UTF16-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniJIS-UTF16-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniJIS-UTF32-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniJIS-UTF32-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniJIS-UTF8-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniJIS-UTF8-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniJIS2004-UTF16-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniJIS2004-UTF16-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniJIS2004-UTF32-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniJIS2004-UTF32-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniJIS2004-UTF8-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniJIS2004-UTF8-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniJISPro-UCS2-HW-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniJISPro-UCS2-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniJISPro-UTF8-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniJISX0213-UTF32-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniJISX0213-UTF32-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniJISX02132004-UTF32-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniJISX02132004-UTF32-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniKS-UCS2-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniKS-UCS2-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniKS-UTF16-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniKS-UTF16-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniKS-UTF32-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniKS-UTF32-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniKS-UTF8-H.bcmap +0 -0
- package/lib/pdfjs/cmaps/UniKS-UTF8-V.bcmap +0 -0
- package/lib/pdfjs/cmaps/V.bcmap +0 -0
- package/lib/pdfjs/cmaps/WP-Symbol.bcmap +0 -0
- package/lib/pdfjs/pdf.worker.min.mjs +21 -0
- package/lib/types.d.ts +4 -0
- package/lib/types.d.ts.map +1 -1
- package/lib/utils/pdfConfig.d.ts +40 -0
- package/lib/utils/pdfConfig.d.ts.map +1 -1
- package/package.json +19 -27
package/README.md
CHANGED
|
@@ -41,6 +41,75 @@ pnpm add @eternalheart/react-file-preview
|
|
|
41
41
|
import '@eternalheart/react-file-preview/style.css';
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
+
### PDF.js Configuration (Optional)
|
|
45
|
+
|
|
46
|
+
If you need to preview PDF files, it's recommended to configure PDF.js to use local static files for better performance and stability:
|
|
47
|
+
|
|
48
|
+
#### Method 1: Use CDN (Default)
|
|
49
|
+
|
|
50
|
+
By default, the component automatically uses unpkg CDN to load PDF.js, no additional configuration needed.
|
|
51
|
+
|
|
52
|
+
#### Method 2: Use Local Static Files (Recommended for Production)
|
|
53
|
+
|
|
54
|
+
1. Copy PDF.js files to your public directory:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
# Copy PDF.js files from node_modules to public directory
|
|
58
|
+
cp -r node_modules/pdfjs-dist/build/pdf.worker.min.mjs public/pdfjs/
|
|
59
|
+
cp -r node_modules/pdfjs-dist/cmaps public/pdfjs/
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
2. Configure PDF.js in your app entry:
|
|
63
|
+
|
|
64
|
+
```tsx
|
|
65
|
+
import { configurePdfjs } from '@eternalheart/react-file-preview';
|
|
66
|
+
|
|
67
|
+
// Configure to use local static files
|
|
68
|
+
configurePdfjs({
|
|
69
|
+
workerSrc: '/pdfjs/pdf.worker.min.mjs',
|
|
70
|
+
cMapUrl: '/pdfjs/cmaps/',
|
|
71
|
+
cMapPacked: true
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
#### Auto-copy with Vite (Recommended)
|
|
76
|
+
|
|
77
|
+
Configure auto-copy in `vite.config.ts`:
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
import { defineConfig } from 'vite';
|
|
81
|
+
import { viteStaticCopy } from 'vite-plugin-static-copy';
|
|
82
|
+
|
|
83
|
+
export default defineConfig({
|
|
84
|
+
plugins: [
|
|
85
|
+
viteStaticCopy({
|
|
86
|
+
targets: [
|
|
87
|
+
{
|
|
88
|
+
src: 'node_modules/pdfjs-dist/build/pdf.worker.min.mjs',
|
|
89
|
+
dest: 'pdfjs'
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
src: 'node_modules/pdfjs-dist/cmaps',
|
|
93
|
+
dest: 'pdfjs'
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
})
|
|
97
|
+
]
|
|
98
|
+
});
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Then configure in your app entry:
|
|
102
|
+
|
|
103
|
+
```tsx
|
|
104
|
+
import { configurePdfjs } from '@eternalheart/react-file-preview';
|
|
105
|
+
|
|
106
|
+
configurePdfjs({
|
|
107
|
+
workerSrc: '/pdfjs/pdf.worker.min.mjs',
|
|
108
|
+
cMapUrl: '/pdfjs/cmaps/',
|
|
109
|
+
cMapPacked: true
|
|
110
|
+
});
|
|
111
|
+
```
|
|
112
|
+
|
|
44
113
|
## 🚀 Quick Start
|
|
45
114
|
|
|
46
115
|
📖 **New to this library?** Check out the [Quick Start Guide](./QUICK_START.md) for a 5-minute introduction!
|
package/README.zh-CN.md
CHANGED
|
@@ -39,6 +39,75 @@ pnpm add react-file-preview
|
|
|
39
39
|
import 'react-file-preview/style.css';
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
+
### PDF.js 配置(可选)
|
|
43
|
+
|
|
44
|
+
如果你需要预览 PDF 文件,建议配置 PDF.js 使用本地静态文件以提高性能和稳定性:
|
|
45
|
+
|
|
46
|
+
#### 方式 1: 使用 CDN(默认)
|
|
47
|
+
|
|
48
|
+
默认情况下,组件会自动使用 unpkg CDN 加载 PDF.js,无需额外配置。
|
|
49
|
+
|
|
50
|
+
#### 方式 2: 使用本地静态文件(推荐用于生产环境)
|
|
51
|
+
|
|
52
|
+
1. 将 PDF.js 文件复制到你的 public 目录:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
# 从 node_modules 复制 PDF.js 文件到 public 目录
|
|
56
|
+
cp -r node_modules/pdfjs-dist/build/pdf.worker.min.mjs public/pdfjs/
|
|
57
|
+
cp -r node_modules/pdfjs-dist/cmaps public/pdfjs/
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
2. 在应用入口配置 PDF.js:
|
|
61
|
+
|
|
62
|
+
```tsx
|
|
63
|
+
import { configurePdfjs } from '@eternalheart/react-file-preview';
|
|
64
|
+
|
|
65
|
+
// 配置使用本地静态文件
|
|
66
|
+
configurePdfjs({
|
|
67
|
+
workerSrc: '/pdfjs/pdf.worker.min.mjs',
|
|
68
|
+
cMapUrl: '/pdfjs/cmaps/',
|
|
69
|
+
cMapPacked: true
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
#### 使用 Vite 自动复制(推荐)
|
|
74
|
+
|
|
75
|
+
在 `vite.config.ts` 中配置自动复制:
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
import { defineConfig } from 'vite';
|
|
79
|
+
import { viteStaticCopy } from 'vite-plugin-static-copy';
|
|
80
|
+
|
|
81
|
+
export default defineConfig({
|
|
82
|
+
plugins: [
|
|
83
|
+
viteStaticCopy({
|
|
84
|
+
targets: [
|
|
85
|
+
{
|
|
86
|
+
src: 'node_modules/pdfjs-dist/build/pdf.worker.min.mjs',
|
|
87
|
+
dest: 'pdfjs'
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
src: 'node_modules/pdfjs-dist/cmaps',
|
|
91
|
+
dest: 'pdfjs'
|
|
92
|
+
}
|
|
93
|
+
]
|
|
94
|
+
})
|
|
95
|
+
]
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
然后在应用入口配置:
|
|
100
|
+
|
|
101
|
+
```tsx
|
|
102
|
+
import { configurePdfjs } from '@eternalheart/react-file-preview';
|
|
103
|
+
|
|
104
|
+
configurePdfjs({
|
|
105
|
+
workerSrc: '/pdfjs/pdf.worker.min.mjs',
|
|
106
|
+
cMapUrl: '/pdfjs/cmaps/',
|
|
107
|
+
cMapPacked: true
|
|
108
|
+
});
|
|
109
|
+
```
|
|
110
|
+
|
|
42
111
|
## 🚀 快速开始
|
|
43
112
|
|
|
44
113
|
📖 **第一次使用?** 查看 [快速开始指南](./QUICK_START.md) 获取 5 分钟入门教程!
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { PreviewFileInput } from './types';
|
|
1
|
+
import { PreviewFileInput, CustomRenderer } from './types';
|
|
2
2
|
interface FilePreviewModalProps {
|
|
3
3
|
files: PreviewFileInput[];
|
|
4
4
|
currentIndex: number;
|
|
5
5
|
isOpen: boolean;
|
|
6
6
|
onClose: () => void;
|
|
7
7
|
onNavigate?: (index: number) => void;
|
|
8
|
+
customRenderers?: CustomRenderer[];
|
|
8
9
|
}
|
|
9
10
|
export declare const FilePreviewModal: React.FC<FilePreviewModalProps>;
|
|
10
11
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FilePreviewModal.d.ts","sourceRoot":"","sources":["../src/FilePreviewModal.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"FilePreviewModal.d.ts","sourceRoot":"","sources":["../src/FilePreviewModal.tsx"],"names":[],"mappings":"AAgBA,OAAO,EAAe,gBAAgB,EAAY,cAAc,EAAE,MAAM,SAAS,CAAC;AAalF,UAAU,qBAAqB;IAC7B,KAAK,EAAE,gBAAgB,EAAE,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,eAAe,CAAC,EAAE,cAAc,EAAE,CAAC;CACpC;AA6CD,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CA6T5D,CAAC"}
|
package/lib/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("react"),D=require("framer-motion"),y=require("lucide-react"),P=require("react-pdf"),X=require("mammoth"),U=require("xlsx"),W=require("pptx-preview"),V=require("video.js"),_=require("react-markdown"),Z=require("remark-gfm"),O=require("react-syntax-highlighter");function G(s){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const o in s)if(o!=="default"){const c=Object.getOwnPropertyDescriptor(s,o);Object.defineProperty(r,o,c.get?c:{enumerable:!0,get:()=>s[o]})}}return r.default=s,Object.freeze(r)}const $=G(U);function I(s){try{const c=new URL(s).pathname.split("/").pop()||"file";return decodeURIComponent(c)}catch{const r=s.split("/").pop()||"file";return decodeURIComponent(r)}}function z(s){var c;const r=((c=s.split(".").pop())==null?void 0:c.toLowerCase())||"";return{jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",gif:"image/gif",webp:"image/webp",svg:"image/svg+xml",bmp:"image/bmp",ico:"image/x-icon",mp4:"video/mp4",webm:"video/webm",ogg:"video/ogg",ogv:"video/ogg",mov:"video/quicktime",avi:"video/x-msvideo",mkv:"video/x-matroska",m4v:"video/x-m4v","3gp":"video/3gpp",flv:"video/x-flv",mp3:"audio/mpeg",wav:"audio/wav",m4a:"audio/mp4",aac:"audio/aac",flac:"audio/flac",pdf:"application/pdf",docx:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",xlsx:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",pptx:"application/vnd.openxmlformats-officedocument.presentationml.presentation",ppt:"application/vnd.ms-powerpoint",txt:"text/plain",md:"text/markdown",markdown:"text/markdown",json:"application/json",xml:"application/xml",html:"text/html",css:"text/css",js:"text/javascript",ts:"text/typescript",jsx:"text/javascript",tsx:"text/typescript",py:"text/x-python",java:"text/x-java",cpp:"text/x-c++src",c:"text/x-csrc",cs:"text/x-csharp",php:"text/x-php",rb:"text/x-ruby",go:"text/x-go",rs:"text/x-rust",yaml:"text/yaml",yml:"text/yaml"}[r]||"application/octet-stream"}function H(s,r=0){if(s instanceof File)return{id:`file-${Date.now()}-${r}`,name:s.name,url:URL.createObjectURL(s),type:s.type||z(s.name),size:s.size};if(typeof s=="string"){const o=I(s);return{id:`url-${Date.now()}-${r}`,name:o,url:s,type:z(o)}}return{id:s.id||`link-${Date.now()}-${r}`,name:s.name,url:s.url,type:s.type||z(s.name),size:s.size}}function B(s){return s.map((r,o)=>H(r,o))}const Y=({url:s,zoom:r,rotation:o,onZoomChange:c})=>{const[d,u]=t.useState(!1),[i,n]=t.useState(null),[a,w]=t.useState({x:0,y:0}),[x,h]=t.useState(!1),[b,l]=t.useState({x:0,y:0}),[m,f]=t.useState(1),j=t.useRef(null);t.useEffect(()=>{u(!1),n(null),w({x:0,y:0}),f(1)},[s]),t.useEffect(()=>{f(r)},[r]),t.useEffect(()=>{w({x:0,y:0})},[r,o]);const N=()=>{u(!0)},S=()=>{n("图片加载失败"),u(!0)},C=()=>{w({x:0,y:0})},R=t.useCallback(v=>{v.preventDefault(),v.stopPropagation();const E=v.deltaY>0?-.1:.1;f(g=>{const T=Math.max(.5,Math.min(5,g+E));return c&&c(T),T})},[c]),L=t.useCallback(v=>{v.button===0&&(h(!0),l({x:v.clientX-a.x,y:v.clientY-a.y}))},[a]),p=t.useCallback(v=>{x&&w({x:v.clientX-b.x,y:v.clientY-b.y})},[x,b]),k=t.useCallback(()=>{h(!1)},[]);return e.jsxs("div",{ref:j,className:"flex items-center justify-center w-full h-full overflow-hidden",onWheel:R,onMouseDown:L,onMouseMove:p,onMouseUp:k,onMouseLeave:k,style:{cursor:x?"grabbing":"grab"},children:[!d&&!i&&e.jsx("div",{className:"flex items-center justify-center",children:e.jsx("div",{className:"w-12 h-12 border-4 border-white/20 border-t-white rounded-full animate-spin"})}),i&&e.jsx("div",{className:"text-white/70 text-center",children:e.jsx("p",{className:"text-lg",children:i})}),e.jsx(D.motion.img,{src:s,alt:"Preview",className:`max-w-none select-none ${d?"":"hidden"}`,style:{transform:`translate(${a.x}px, ${a.y}px) scale(${m}) rotate(${o}deg)`,transformOrigin:"center",transition:x?"none":"transform 0.3s ease-out"},onLoad:N,onError:S,onDoubleClick:C,initial:{opacity:0},animate:{opacity:d?1:0},transition:{duration:.3},draggable:!1})]})},K=P.pdfjs.version,Q="/pdf.worker.min.mjs";P.pdfjs.GlobalWorkerOptions.workerSrc=Q;const J=P.pdfjs.GlobalWorkerOptions.workerSrc,q=`https://unpkg.com/pdfjs-dist@${K}/build/pdf.worker.min.mjs`;typeof window<"u"&&window.addEventListener("error",s=>{var r;(r=s.message)!=null&&r.includes("pdf.worker")&&P.pdfjs.GlobalWorkerOptions.workerSrc===J&&(console.warn("本地 PDF worker 加载失败,切换到 CDN:",q),P.pdfjs.GlobalWorkerOptions.workerSrc=q)});const ee=({url:s,zoom:r,currentPage:o,onPageChange:c,onTotalPagesChange:d})=>{const[u,i]=t.useState(0),[n,a]=t.useState(null),w=t.useRef(null),x=t.useRef(new Map);t.useEffect(()=>{a(null)},[s]);const h=({numPages:f})=>{i(f),d(f),c(1)},b=f=>{console.error("PDF 加载错误:",f),a("PDF 文件加载失败")},l=t.useCallback(()=>{if(!w.current)return;const f=w.current,j=f.scrollTop,N=f.clientHeight,S=j+N/2;let C=1,R=1/0;x.current.forEach((L,p)=>{const k=L.getBoundingClientRect(),v=f.getBoundingClientRect(),E=k.top-v.top+k.height/2+j,g=Math.abs(E-S);g<R&&(R=g,C=p)}),C!==o&&c(C)},[o,c]);t.useEffect(()=>{const f=w.current;if(f)return f.addEventListener("scroll",l),()=>f.removeEventListener("scroll",l)},[l]);const m=t.useCallback((f,j)=>{j?x.current.set(f,j):x.current.delete(f)},[]);return e.jsxs("div",{ref:w,className:"flex flex-col items-center w-full h-full overflow-auto py-8 px-4",children:[n&&e.jsx("div",{className:"text-white/70 text-center",children:e.jsx("p",{className:"text-lg",children:n})}),!n&&e.jsx(P.Document,{file:s,onLoadSuccess:h,onLoadError:b,loading:e.jsx("div",{className:"flex items-center justify-center min-h-screen",children:e.jsx("div",{className:"w-12 h-12 border-4 border-white/20 border-t-white rounded-full animate-spin"})}),children:e.jsx("div",{className:"flex flex-col gap-4",children:Array.from(new Array(u),(f,j)=>{const N=j+1;return e.jsxs("div",{ref:S=>m(N,S),className:"relative",children:[e.jsx(P.Page,{pageNumber:N,scale:r,loading:e.jsx("div",{className:"flex items-center justify-center p-8 bg-white/5 rounded-lg min-h-[600px]",children:e.jsx("div",{className:"w-8 h-8 border-4 border-white/20 border-t-white rounded-full animate-spin"})}),renderTextLayer:!0,renderAnnotationLayer:!0,className:"shadow-2xl"}),e.jsx("div",{className:"absolute top-2 right-2 bg-black/60 backdrop-blur-sm text-white text-xs px-3 py-1 rounded-full",children:N})]},`page_${N}`)})})}),u>0&&e.jsxs("div",{className:"sticky bottom-4 mt-8 bg-black/60 backdrop-blur-xl text-white px-6 py-3 rounded-full text-sm font-medium shadow-2xl border border-white/10",children:["第 ",o," 页 / 共 ",u," 页"]})]})},te=({url:s})=>{const[r,o]=t.useState(""),[c,d]=t.useState(!0),[u,i]=t.useState(null);return t.useEffect(()=>{(async()=>{d(!0),i(null),o("");try{const a=await fetch(s);if(!a.ok)throw new Error("文件加载失败");const w=await a.arrayBuffer(),x=await X.convertToHtml({arrayBuffer:w});o(x.value)}catch(a){console.error("Docx 解析错误:",a),i("Word 文档解析失败")}finally{d(!1)}})()},[s]),c?e.jsx("div",{className:"flex items-center justify-center w-full h-full",children:e.jsx("div",{className:"w-12 h-12 border-4 border-white/20 border-t-white rounded-full animate-spin"})}):u?e.jsx("div",{className:"flex items-center justify-center w-full h-full",children:e.jsx("div",{className:"text-white/70 text-center",children:e.jsx("p",{className:"text-lg",children:u})})}):e.jsx("div",{className:"w-full h-full overflow-auto p-8",children:e.jsx("div",{className:"max-w-4xl mx-auto bg-white rounded-lg shadow-2xl p-12",dangerouslySetInnerHTML:{__html:r},style:{fontFamily:"system-ui, -apple-system, sans-serif",lineHeight:"1.6",color:"#333"}})})},se=({url:s})=>{const[r,o]=t.useState([]),[c,d]=t.useState(0),[u,i]=t.useState(!0),[n,a]=t.useState(null);if(t.useEffect(()=>{(async()=>{i(!0),a(null),o([]);try{const h=await fetch(s);if(!h.ok)throw new Error("文件加载失败");const b=await h.arrayBuffer(),l=$.read(b,{type:"array"}),m=l.SheetNames.map(f=>{const j=l.Sheets[f],N=$.utils.sheet_to_json(j,{header:1});return{name:f,data:N}});o(m),d(0)}catch(h){console.error("Excel 解析错误:",h),a("Excel 文件解析失败")}finally{i(!1)}})()},[s]),u)return e.jsx("div",{className:"flex items-center justify-center w-full h-full",children:e.jsx("div",{className:"w-12 h-12 border-4 border-white/20 border-t-white rounded-full animate-spin"})});if(n)return e.jsx("div",{className:"flex items-center justify-center w-full h-full",children:e.jsx("div",{className:"text-white/70 text-center",children:e.jsx("p",{className:"text-lg",children:n})})});const w=r[c];return e.jsxs("div",{className:"w-full h-full flex flex-col overflow-hidden",children:[r.length>1&&e.jsx("div",{className:"flex gap-2 p-4 bg-black/20 backdrop-blur-sm overflow-x-auto border-b border-white/10",children:r.map((x,h)=>e.jsx("button",{onClick:()=>d(h),className:`px-4 py-2 rounded-lg text-sm font-medium transition-all ${c===h?"bg-gradient-to-r from-purple-500 to-pink-500 text-white shadow-lg":"bg-white/10 text-white hover:bg-white/20"}`,children:x.name},h))}),e.jsx("div",{className:"flex-1 overflow-auto p-8",children:e.jsx("div",{className:"inline-block min-w-full bg-gradient-to-br from-gray-800/90 to-gray-900/90 backdrop-blur-xl rounded-2xl shadow-2xl overflow-hidden border border-white/10",children:e.jsx("table",{className:"min-w-full divide-y divide-white/10",children:e.jsx("tbody",{className:"divide-y divide-white/10",children:w==null?void 0:w.data.map((x,h)=>e.jsx("tr",{className:`transition-colors ${h===0?"bg-gradient-to-r from-purple-500/20 to-pink-500/20 font-semibold":"hover:bg-white/5"}`,children:x.map((b,l)=>e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-200 border-r border-white/10",children:String(b??"")},l))},h))})})})})]})},re=({url:s})=>{const[r,o]=t.useState(!0),[c,d]=t.useState(null),u=t.useRef(null),i=t.useRef(null),n=t.useRef(null),a=t.useRef(null),w=t.useRef(null),x=t.useRef({width:0,height:0}),h=t.useCallback(()=>{if(!u.current)return{width:960,height:540};const l=u.current.clientWidth,m=Math.floor(l*9/16);return console.log("计算尺寸:",{width:l,height:m}),{width:l,height:m}},[]),b=t.useCallback(async()=>{if(!(!u.current||!a.current)){console.log("重新初始化预览器...");try{if(i.current)try{i.current.destroy()}catch(f){console.error("销毁预览器失败:",f)}u.current.innerHTML="";const l=h();console.log("重新初始化使用尺寸:",l);const m=W.init(u.current,{width:l.width,height:l.height});i.current=m,await m.preview(a.current),console.log("重新初始化成功")}catch(l){console.error("重新初始化失败:",l)}}},[h]);return t.useEffect(()=>{if(!u.current)return;let l=!0;const m=()=>{if(l){l=!1;const C=h();x.current=C;return}const f=h(),j=x.current,N=Math.abs(j.width-f.width),S=Math.abs(j.height-f.height);if(N<10&&S<10){console.log("尺寸变化太小,忽略");return}console.log("检测到尺寸变化:",{old:j,new:f,diff:{width:N,height:S}}),x.current=f,w.current&&clearTimeout(w.current),w.current=window.setTimeout(()=>{i.current&&a.current&&(console.log("尺寸变化,准备重新初始化"),b())},800)};return n.current=new ResizeObserver(()=>{m()}),n.current.observe(u.current),()=>{n.current&&n.current.disconnect(),w.current&&clearTimeout(w.current)}},[h,b]),t.useEffect(()=>{let l=!0;const m=async()=>{if(!u.current){console.log("Container ref not ready");return}o(!0),d(null);try{console.log("开始加载 PPTX:",s);const j=await fetch(s);if(!j.ok)throw new Error("文件加载失败");const N=await j.arrayBuffer();if(a.current=N,console.log("文件加载成功,大小:",N.byteLength),!l)return;u.current&&(u.current.innerHTML="");const S=h();console.log("使用尺寸:",S),console.log("初始化预览器...");const C=W.init(u.current,{width:S.width,height:S.height});i.current=C,console.log("开始预览..."),C.preview(N).then(()=>{console.log("预览成功"),l&&o(!1)}).catch(R=>{console.error("预览失败:",R),l&&(d("PPT 文件预览失败"),o(!1))})}catch(j){console.error("PPTX 解析错误:",j),l&&(d(j instanceof Error?j.message:"PPT 文件解析失败"),o(!1))}},f=setTimeout(()=>{m()},100);return()=>{if(l=!1,clearTimeout(f),a.current=null,i.current)try{i.current.destroy()}catch(j){console.error("销毁预览器失败:",j)}i.current=null}},[s,h]),e.jsxs("div",{className:"relative flex flex-col items-center w-full h-full pt-[8px]",children:[r&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50 backdrop-blur-sm z-10 rounded-2xl",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-12 h-12 mx-auto mb-3 border-4 border-white/20 border-t-white rounded-full animate-spin"}),e.jsx("p",{className:"text-sm text-white/70 font-medium",children:"加载 PPT 中..."})]})}),c&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50 backdrop-blur-sm z-10 rounded-2xl",children:e.jsxs("div",{className:"text-center max-w-md",children:[e.jsx("div",{className:"w-32 h-32 mx-auto mb-6 rounded-3xl bg-gradient-to-br from-orange-500 via-red-500 to-pink-500 flex items-center justify-center shadow-2xl",children:e.jsx(y.Presentation,{className:"w-16 h-16 text-white"})}),e.jsx("p",{className:"text-xl text-white/90 mb-3 font-medium",children:"PPT 预览"}),e.jsx("p",{className:"text-sm text-white/60 mb-6",children:c||"浏览器暂不支持直接预览 PPT 文件"}),e.jsxs("a",{href:s,download:!0,className:"inline-flex items-center gap-2 px-6 py-3 bg-gradient-to-r from-purple-500 to-pink-500 text-white rounded-xl hover:scale-105 transition-all shadow-lg",children:[e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"})}),"下载文件"]}),e.jsx("p",{className:"text-xs text-white/40 mt-4",children:"提示:可以使用 Microsoft PowerPoint 或 WPS 打开"})]})}),e.jsx("div",{ref:u,className:"pptx-wrapper w-full max-w-6xl"})]})},oe=s=>{var c;const r=((c=s.split(".").pop())==null?void 0:c.toLowerCase().split("?")[0])||"";return{mp4:"video/mp4",webm:"video/webm",ogg:"video/ogg",ogv:"video/ogg",mov:"video/quicktime",avi:"video/x-msvideo",mkv:"video/x-matroska",m4v:"video/mp4","3gp":"video/3gpp",flv:"video/x-flv"}[r]||"video/mp4"},ne=({url:s})=>{const[r,o]=t.useState(null),[c,d]=t.useState(!0),u=t.useRef(null),i=t.useRef(null);return t.useEffect(()=>{if(!i.current&&u.current){const n=document.createElement("video-js");n.classList.add("vjs-big-play-centered","vjs-theme-apple"),u.current.appendChild(n);const a=oe(s),x=V(n,{controls:!0,responsive:!0,fluid:!0,preload:"auto",controlBar:{children:["playToggle","volumePanel","currentTimeDisplay","timeDivider","durationDisplay","progressControl","remainingTimeDisplay","fullscreenToggle"],volumePanel:{inline:!1}},html5:{vhs:{overrideNative:!0},nativeVideoTracks:!1,nativeAudioTracks:!1,nativeTextTracks:!1},sources:a==="video/quicktime"?[{src:s,type:"video/quicktime"},{src:s,type:"video/mp4"}]:[{src:s,type:a}]});x.on("loadeddata",()=>{d(!1)}),x.on("error",()=>{const h=x.error();console.error("Video.js error:",h),o(`视频加载失败: ${(h==null?void 0:h.message)||"未知错误"}`),d(!1)}),i.current=x}},[s]),t.useEffect(()=>{const n=i.current;return()=>{n&&!n.isDisposed()&&(n.dispose(),i.current=null)}},[]),r?e.jsx("div",{className:"flex items-center justify-center w-full h-full",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-16 h-16 mx-auto mb-4 rounded-full bg-red-500/10 flex items-center justify-center",children:e.jsx("svg",{className:"w-8 h-8 text-red-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})}),e.jsx("p",{className:"text-lg font-medium text-white/90 mb-2",children:"视频加载失败"}),e.jsx("p",{className:"text-sm text-white/60",children:r})]})}):e.jsx("div",{className:"flex items-center justify-center w-full h-full p-8",children:e.jsxs("div",{className:"w-full max-w-5xl relative",children:[c&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/20 backdrop-blur-sm rounded-2xl z-10",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-12 h-12 mx-auto mb-3 border-3 border-white/20 border-t-white rounded-full animate-spin"}),e.jsx("p",{className:"text-sm text-white/70 font-medium",children:"加载视频中..."})]})}),e.jsx("div",{ref:u,className:"overflow-hidden",style:{boxShadow:"0 20px 60px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.05)"}})]})})},le=({url:s,fileName:r})=>{const[o,c]=t.useState(null),[d,u]=t.useState(!1),[i,n]=t.useState(0),[a,w]=t.useState(0),[x,h]=t.useState(1),[b,l]=t.useState(!1),m=t.useRef(null);t.useEffect(()=>{const p=m.current;if(!p)return;const k=()=>{isNaN(p.currentTime)||n(p.currentTime)},v=()=>{!isNaN(p.duration)&&isFinite(p.duration)&&w(p.duration)},E=()=>u(!1),g=()=>v();return p.addEventListener("timeupdate",k),p.addEventListener("loadedmetadata",v),p.addEventListener("durationchange",v),p.addEventListener("canplay",g),p.addEventListener("ended",E),p.readyState>=1&&v(),()=>{p.removeEventListener("timeupdate",k),p.removeEventListener("loadedmetadata",v),p.removeEventListener("durationchange",v),p.removeEventListener("canplay",g),p.removeEventListener("ended",E)}},[]);const f=()=>{m.current&&(d?m.current.pause():m.current.play(),u(!d))},j=p=>{const k=parseFloat(p.target.value);n(k),m.current&&(m.current.currentTime=k)},N=p=>{const k=parseFloat(p.target.value);h(k),m.current&&(m.current.volume=k),k>0&&l(!1)},S=()=>{m.current&&(m.current.muted=!b,l(!b))},C=p=>{m.current&&(m.current.currentTime+=p)},R=p=>{if(!isFinite(p)||isNaN(p)||p<0)return"0:00";const k=Math.floor(p/60),v=Math.floor(p%60);return`${k}:${v.toString().padStart(2,"0")}`},L=()=>{c("音频加载失败")};return o?e.jsx("div",{className:"flex items-center justify-center w-full h-full",children:e.jsx("div",{className:"text-white/70 text-center",children:e.jsx("p",{className:"text-lg",children:o})})}):e.jsxs("div",{className:"flex flex-col items-center justify-center w-full h-full p-8 gap-8",children:[e.jsx("div",{className:"w-64 h-64 rounded-3xl bg-gradient-to-br from-purple-500 via-pink-500 to-rose-500 flex items-center justify-center shadow-2xl backdrop-blur-xl",children:e.jsx(y.Music,{className:"w-32 h-32 text-white"})}),e.jsxs("div",{className:"text-white text-center max-w-md",children:[e.jsx("p",{className:"text-2xl font-medium mb-1",children:r}),e.jsx("p",{className:"text-sm text-white/60",children:"音频文件"})]}),e.jsxs("div",{className:"w-full max-w-md bg-white/10 backdrop-blur-xl rounded-2xl p-6 border border-white/20",children:[e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"relative h-4 flex items-center",children:[e.jsx("div",{className:"absolute w-full h-[6px] bg-white/20 rounded-full"}),e.jsx("div",{className:"absolute h-[6px] bg-gradient-to-r from-purple-500 to-pink-500 rounded-full transition-all duration-100 ease-linear pointer-events-none",style:{width:`${a>0?i/a*100:i>100?100:i}%`}}),e.jsx("input",{type:"range",min:"0",max:a>0?a:100+(i>100?i%100:0),value:i,onChange:j,className:"audio-slider absolute w-full"})]}),e.jsxs("div",{className:"flex justify-between text-xs text-white/60 mt-3",children:[e.jsx("span",{children:R(i)}),e.jsx("span",{children:R(a)})]})]}),e.jsxs("div",{className:"flex items-center justify-center gap-4 mb-4",children:[e.jsx("button",{onClick:()=>C(-10),className:"w-10 h-10 rounded-full bg-white/10 hover:bg-white/20 flex items-center justify-center text-white transition-all",children:e.jsx(y.SkipBack,{className:"w-5 h-5"})}),e.jsx("button",{onClick:f,className:"w-14 h-14 rounded-full bg-gradient-to-br from-purple-500 to-pink-500 hover:scale-105 flex items-center justify-center text-white transition-all shadow-lg",children:d?e.jsx(y.Pause,{className:"w-6 h-6"}):e.jsx(y.Play,{className:"w-6 h-6 ml-1"})}),e.jsx("button",{onClick:()=>C(10),className:"w-10 h-10 rounded-full bg-white/10 hover:bg-white/20 flex items-center justify-center text-white transition-all",children:e.jsx(y.SkipForward,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:S,className:"text-white/80 hover:text-white transition-colors",children:b||x===0?e.jsx(y.VolumeX,{className:"w-5 h-5"}):e.jsx(y.Volume2,{className:"w-5 h-5"})}),e.jsxs("div",{className:"flex-1 relative h-3 flex items-center",children:[e.jsx("div",{className:"absolute w-full h-[4px] bg-white/20 rounded-full"}),e.jsx("div",{className:"absolute h-[4px] bg-purple-500 rounded-full transition-all duration-100 pointer-events-none",style:{width:`${(b?0:x)*100}%`}}),e.jsx("input",{type:"range",min:"0",max:"1",step:"0.01",value:b?0:x,onChange:N,className:"volume-slider absolute w-full"})]})]})]}),e.jsx("audio",{ref:m,src:s,onError:L,className:"hidden"})]})},A={'pre[class*="language-"]':{color:"#d4d4d4",fontSize:"13px",textShadow:"none",fontFamily:'Menlo, Monaco, Consolas, "Andale Mono", "Ubuntu Mono", "Courier New", monospace',direction:"ltr",textAlign:"left",whiteSpace:"pre",wordSpacing:"normal",wordBreak:"normal",lineHeight:"1.5",MozTabSize:"4",OTabSize:"4",tabSize:"4",WebkitHyphens:"none",MozHyphens:"none",msHyphens:"none",hyphens:"none",padding:"1em",margin:".5em 0",overflow:"auto",background:"#1e1e1e"},'code[class*="language-"]':{color:"#d4d4d4",fontSize:"13px",textShadow:"none",fontFamily:'Menlo, Monaco, Consolas, "Andale Mono", "Ubuntu Mono", "Courier New", monospace',direction:"ltr",textAlign:"left",whiteSpace:"pre",wordSpacing:"normal",wordBreak:"normal",lineHeight:"1.5",MozTabSize:"4",OTabSize:"4",tabSize:"4",WebkitHyphens:"none",MozHyphens:"none",msHyphens:"none",hyphens:"none"},'pre[class*="language-"]::selection':{textShadow:"none",background:"#264F78"},'code[class*="language-"]::selection':{textShadow:"none",background:"#264F78"},'pre[class*="language-"] *::selection':{textShadow:"none",background:"#264F78"},'code[class*="language-"] *::selection':{textShadow:"none",background:"#264F78"},':not(pre) > code[class*="language-"]':{padding:".1em .3em",borderRadius:".3em",color:"#db4c69",background:"#1e1e1e"},".namespace":{Opacity:".7"},"doctype.doctype-tag":{color:"#569CD6"},"doctype.name":{color:"#9cdcfe"},comment:{color:"#6a9955"},prolog:{color:"#6a9955"},punctuation:{color:"#d4d4d4"},".language-html .language-css .token.punctuation":{color:"#d4d4d4"},".language-html .language-javascript .token.punctuation":{color:"#d4d4d4"},property:{color:"#9cdcfe"},tag:{color:"#569cd6"},boolean:{color:"#569cd6"},number:{color:"#b5cea8"},constant:{color:"#9cdcfe"},symbol:{color:"#b5cea8"},inserted:{color:"#b5cea8"},unit:{color:"#b5cea8"},selector:{color:"#d7ba7d"},"attr-name":{color:"#9cdcfe"},string:{color:"#ce9178"},char:{color:"#ce9178"},builtin:{color:"#ce9178"},deleted:{color:"#ce9178"},".language-css .token.string.url":{textDecoration:"underline"},operator:{color:"#d4d4d4"},entity:{color:"#569cd6"},"operator.arrow":{color:"#569CD6"},atrule:{color:"#ce9178"},"atrule.rule":{color:"#c586c0"},"atrule.url":{color:"#9cdcfe"},"atrule.url.function":{color:"#dcdcaa"},"atrule.url.punctuation":{color:"#d4d4d4"},keyword:{color:"#569CD6"},"keyword.module":{color:"#c586c0"},"keyword.control-flow":{color:"#c586c0"},function:{color:"#dcdcaa"},"function.maybe-class-name":{color:"#dcdcaa"},regex:{color:"#d16969"},important:{color:"#569cd6"},italic:{fontStyle:"italic"},"class-name":{color:"#4ec9b0"},"maybe-class-name":{color:"#4ec9b0"},console:{color:"#9cdcfe"},parameter:{color:"#9cdcfe"},interpolation:{color:"#9cdcfe"},"punctuation.interpolation-punctuation":{color:"#569cd6"},variable:{color:"#9cdcfe"},"imports.maybe-class-name":{color:"#9cdcfe"},"exports.maybe-class-name":{color:"#9cdcfe"},escape:{color:"#d7ba7d"},"tag.punctuation":{color:"#808080"},cdata:{color:"#808080"},"attr-value":{color:"#ce9178"},"attr-value.punctuation":{color:"#ce9178"},"attr-value.punctuation.attr-equals":{color:"#d4d4d4"},namespace:{color:"#4ec9b0"},'pre[class*="language-javascript"]':{color:"#9cdcfe"},'code[class*="language-javascript"]':{color:"#9cdcfe"},'pre[class*="language-jsx"]':{color:"#9cdcfe"},'code[class*="language-jsx"]':{color:"#9cdcfe"},'pre[class*="language-typescript"]':{color:"#9cdcfe"},'code[class*="language-typescript"]':{color:"#9cdcfe"},'pre[class*="language-tsx"]':{color:"#9cdcfe"},'code[class*="language-tsx"]':{color:"#9cdcfe"},'pre[class*="language-css"]':{color:"#ce9178"},'code[class*="language-css"]':{color:"#ce9178"},'pre[class*="language-html"]':{color:"#d4d4d4"},'code[class*="language-html"]':{color:"#d4d4d4"},".language-regex .token.anchor":{color:"#dcdcaa"},".language-html .token.punctuation":{color:"#808080"},'pre[class*="language-"] > code[class*="language-"]':{position:"relative",zIndex:"1"},".line-highlight.line-highlight":{background:"#f7ebc6",boxShadow:"inset 5px 0 0 #f7d87c",zIndex:"0"}},ae=({url:s})=>{const[r,o]=t.useState(""),[c,d]=t.useState(!0),[u,i]=t.useState(null);return t.useEffect(()=>{(async()=>{try{d(!0),i(null);const a=await fetch(s);if(!a.ok)throw new Error("加载失败");const w=await a.text();o(w)}catch(a){i("Markdown 文件加载失败"),console.error(a)}finally{d(!1)}})()},[s]),c?e.jsx("div",{className:"flex items-center justify-center w-full h-full",children:e.jsx("div",{className:"w-12 h-12 border-4 border-white/20 border-t-white rounded-full animate-spin"})}):u?e.jsx("div",{className:"flex items-center justify-center w-full h-full",children:e.jsx("div",{className:"text-white/70 text-center",children:e.jsx("p",{className:"text-lg",children:u})})}):e.jsx("div",{className:"w-full h-full overflow-auto p-8",children:e.jsx("div",{className:"max-w-4xl mx-auto bg-white/5 backdrop-blur-sm rounded-2xl p-8 border border-white/10",children:e.jsx("div",{className:"prose prose-invert prose-lg max-w-none",children:e.jsx(_,{remarkPlugins:[Z],components:{code({node:n,inline:a,className:w,children:x,...h}){const b=/language-(\w+)/.exec(w||"");return!a&&b?e.jsx(O.Prism,{style:A,language:b[1],PreTag:"div",className:"rounded-lg",...h,children:String(x).replace(/\n$/,"")}):e.jsx("code",{className:"bg-white/10 px-1.5 py-0.5 rounded text-sm",...h,children:x})},h1:({children:n})=>e.jsx("h1",{className:"text-4xl font-bold mb-4 text-white border-b border-white/20 pb-2",children:n}),h2:({children:n})=>e.jsx("h2",{className:"text-3xl font-bold mb-3 text-white mt-8",children:n}),h3:({children:n})=>e.jsx("h3",{className:"text-2xl font-bold mb-2 text-white mt-6",children:n}),p:({children:n})=>e.jsx("p",{className:"text-white/90 mb-4 leading-relaxed",children:n}),a:({href:n,children:a})=>e.jsx("a",{href:n,className:"text-blue-400 hover:text-blue-300 underline",target:"_blank",rel:"noopener noreferrer",children:a}),ul:({children:n})=>e.jsx("ul",{className:"list-disc list-inside mb-4 text-white/90",children:n}),ol:({children:n})=>e.jsx("ol",{className:"list-decimal list-inside mb-4 text-white/90",children:n}),li:({children:n})=>e.jsx("li",{className:"mb-1",children:n}),blockquote:({children:n})=>e.jsx("blockquote",{className:"border-l-4 border-blue-500 pl-4 italic text-white/80 my-4",children:n}),table:({children:n})=>e.jsx("div",{className:"overflow-x-auto my-4",children:e.jsx("table",{className:"min-w-full border border-white/20",children:n})}),th:({children:n})=>e.jsx("th",{className:"border border-white/20 px-4 py-2 bg-white/10 text-white font-semibold",children:n}),td:({children:n})=>e.jsx("td",{className:"border border-white/20 px-4 py-2 text-white/90",children:n}),hr:()=>e.jsx("hr",{className:"border-white/20 my-6"}),img:({src:n,alt:a})=>e.jsx("img",{src:n,alt:a,className:"rounded-lg max-w-full h-auto my-4"})},children:r})})})})},ce=s=>{var c;const r=((c=s.split(".").pop())==null?void 0:c.toLowerCase())||"";return{js:"javascript",jsx:"jsx",ts:"typescript",tsx:"tsx",py:"python",java:"java",cpp:"cpp",c:"c",cs:"csharp",php:"php",rb:"ruby",go:"go",rs:"rust",swift:"swift",kt:"kotlin",scala:"scala",sh:"bash",bash:"bash",zsh:"bash",json:"json",xml:"xml",html:"html",css:"css",scss:"scss",sass:"sass",less:"less",sql:"sql",yaml:"yaml",yml:"yaml",toml:"toml",ini:"ini",conf:"nginx",md:"markdown",txt:"text"}[r]||"text"},ie=({url:s,fileName:r})=>{const[o,c]=t.useState(""),[d,u]=t.useState(!0),[i,n]=t.useState(null),a=ce(r);return t.useEffect(()=>{(async()=>{try{u(!0),n(null);const x=await fetch(s);if(!x.ok)throw new Error("加载失败");const h=await x.text();c(h)}catch(x){n("文本文件加载失败"),console.error(x)}finally{u(!1)}})()},[s]),d?e.jsx("div",{className:"flex items-center justify-center w-full h-full",children:e.jsx("div",{className:"w-12 h-12 border-4 border-white/20 border-t-white rounded-full animate-spin"})}):i?e.jsx("div",{className:"flex items-center justify-center w-full h-full",children:e.jsx("div",{className:"text-white/70 text-center",children:e.jsx("p",{className:"text-lg",children:i})})}):e.jsx("div",{className:"w-full h-full overflow-auto p-8",children:e.jsxs("div",{className:"max-w-6xl mx-auto bg-white/5 backdrop-blur-sm rounded-2xl border border-white/10 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-3 px-6 py-4 bg-white/5 border-b border-white/10",children:[e.jsx(y.FileText,{className:"w-5 h-5 text-white/70"}),e.jsx("span",{className:"text-white font-medium",children:r}),e.jsx("span",{className:"ml-auto text-xs text-white/50 uppercase",children:a})]}),e.jsx("div",{className:"text-sm",children:a==="text"?e.jsx("pre",{className:"p-6 text-white/90 font-mono whitespace-pre-wrap break-words",children:o}):e.jsx(O.Prism,{language:a,style:A,showLineNumbers:!0,customStyle:{margin:0,padding:"1.5rem",background:"transparent",fontSize:"0.875rem"},lineNumberStyle:{minWidth:"3em",paddingRight:"1em",color:"rgba(255, 255, 255, 0.3)",userSelect:"none"},children:o})})]})})},de=({fileName:s,fileType:r,onDownload:o})=>e.jsxs("div",{className:"flex flex-col items-center justify-center w-full h-full p-8 gap-6",children:[e.jsx("div",{className:"w-32 h-32 rounded-full bg-white/10 flex items-center justify-center",children:e.jsx(y.FileQuestion,{className:"w-16 h-16 text-white/70"})}),e.jsxs("div",{className:"text-white text-center",children:[e.jsx("p",{className:"text-xl font-medium mb-2",children:s}),e.jsxs("p",{className:"text-white/70",children:["不支持预览此文件类型 (",r,")"]})]}),e.jsxs("button",{onClick:o,className:"flex items-center gap-2 px-6 py-3 bg-white/10 hover:bg-white/20 backdrop-blur-sm rounded-lg text-white font-medium transition-all",children:[e.jsx(y.Download,{className:"w-5 h-5"}),"下载文件查看"]})]}),ue=s=>{var d;const r=((d=s.name.split(".").pop())==null?void 0:d.toLowerCase())||"",o=s.type.toLowerCase();if(o.startsWith("image/")||["jpg","jpeg","png","gif","webp","svg"].includes(r))return"image";if(o.includes("pdf")||r==="pdf")return"pdf";if(o.includes("wordprocessingml")||r==="docx")return"docx";if(o.includes("spreadsheetml")||r==="xlsx")return"xlsx";if(o.includes("presentationml")||r==="pptx"||r==="ppt")return"pptx";if(o.startsWith("video/")||["mp4","webm","ogg","ogv","mov","avi","mkv","m4v","3gp","flv"].includes(r))return"video";if(o.startsWith("audio/")||["mp3","wav","ogg","m4a","flac","aac"].includes(r))return"audio";if(r==="md"||r==="markdown")return"markdown";const c=["txt","log","csv","js","jsx","ts","tsx","json","py","java","cpp","c","h","cs","php","rb","go","rs","swift","kt","html","css","scss","sass","less","xml","yaml","yml","toml","ini","conf","sh","bash","zsh","sql"];return o.startsWith("text/")||c.includes(r)?"text":"unsupported"},me=({files:s,currentIndex:r,isOpen:o,onClose:c,onNavigate:d})=>{const[u,i]=t.useState(1),[n,a]=t.useState(0),[w,x]=t.useState(1),[,h]=t.useState(1),b=t.useMemo(()=>B(s),[s]),l=b[r],m=l?ue(l):"unsupported";t.useEffect(()=>{i(1),a(0),x(1),h(1)},[r]),t.useEffect(()=>{if(o){const g=document.body.style.overflow,T=document.body.style.paddingRight,F=window.innerWidth-document.documentElement.clientWidth;return document.body.style.overflow="hidden",F>0&&(document.body.style.paddingRight=`${F}px`),()=>{document.body.style.overflow=g,document.body.style.paddingRight=T}}},[o]),t.useEffect(()=>{if(!o)return;const g=T=>{T.key==="Escape"?c():T.key==="ArrowLeft"&&r>0?d==null||d(r-1):T.key==="ArrowRight"&&r<b.length-1&&(d==null||d(r+1))};return window.addEventListener("keydown",g),()=>window.removeEventListener("keydown",g)},[o,r,b.length,c,d]);const f=t.useCallback(()=>{i(g=>Math.min(g+.25,5))},[]),j=t.useCallback(()=>{i(g=>Math.max(g-.25,.5))},[]),N=t.useCallback(()=>{a(g=>g+90)},[]),S=t.useCallback(()=>{a(g=>g-90)},[]),C=t.useCallback(()=>{i(1),a(0)},[]),R=t.useCallback(()=>{i(1)},[]),L=t.useCallback(g=>{i(g)},[]),p=t.useCallback(()=>{i(1),a(0)},[]),k=t.useCallback(()=>{if(!l)return;const g=document.createElement("a");g.href=l.url,g.download=l.name,g.click()},[l]);if(!o||!l)return null;const v=m==="image"||m==="pdf",E=m==="image";return e.jsx(D.AnimatePresence,{children:o&&e.jsx(D.motion.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80 backdrop-blur-md overflow-hidden",onClick:c,onWheel:g=>g.stopPropagation(),children:e.jsxs("div",{className:"relative w-full h-full flex flex-col overflow-hidden",onClick:g=>g.stopPropagation(),children:[e.jsx(D.motion.div,{initial:{y:-100},animate:{y:0},exit:{y:-100},className:"absolute top-0 left-0 right-0 z-10 p-4",children:e.jsxs("div",{className:"max-w-7xl mx-auto flex items-center justify-between bg-black/40 backdrop-blur-xl rounded-2xl px-6 py-4 shadow-2xl border border-white/10",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h2",{className:"text-white font-medium text-lg truncate",children:l.name}),e.jsxs("p",{className:"text-white/60 text-sm",children:[r+1," / ",b.length]})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-4",children:[v&&e.jsxs(e.Fragment,{children:[e.jsx(M,{icon:e.jsx(y.ZoomOut,{className:"w-5 h-5"}),label:"缩小",onClick:j,disabled:u<=.5}),e.jsxs("span",{className:"text-white/70 text-sm min-w-[4rem] text-center font-medium",children:[Math.round(u*100),"%"]}),e.jsx(M,{icon:e.jsx(y.ZoomIn,{className:"w-5 h-5"}),label:"放大",onClick:f,disabled:u>=5}),e.jsx("div",{className:"w-px h-6 bg-white/20 mx-2"}),e.jsx(M,{icon:e.jsx(y.Minimize2,{className:"w-5 h-5"}),label:"适应窗口",onClick:C}),e.jsx(M,{icon:e.jsx(y.Maximize2,{className:"w-5 h-5"}),label:"原始尺寸",onClick:R}),e.jsx("div",{className:"w-px h-6 bg-white/20 mx-2"})]}),E&&e.jsxs(e.Fragment,{children:[e.jsx(M,{icon:e.jsx(y.RotateCcw,{className:"w-5 h-5"}),label:"向左旋转",onClick:S}),e.jsx(M,{icon:e.jsx(y.RotateCw,{className:"w-5 h-5"}),label:"向右旋转",onClick:N}),e.jsx("div",{className:"w-px h-6 bg-white/20 mx-2"})]}),(v||E)&&e.jsxs(e.Fragment,{children:[e.jsx(M,{icon:e.jsx(y.RefreshCw,{className:"w-5 h-5"}),label:"复原",onClick:p}),e.jsx("div",{className:"w-px h-6 bg-white/20 mx-2"})]}),e.jsx(M,{icon:e.jsx(y.Download,{className:"w-5 h-5"}),label:"下载",onClick:k}),e.jsx("div",{className:"w-px h-6 bg-white/20 mx-2"}),e.jsx(M,{icon:e.jsx(y.X,{className:"w-5 h-5"}),label:"关闭",onClick:c})]})]})}),e.jsxs("div",{className:"flex-1 flex items-center justify-center pt-24 pb-8 overflow-auto",children:[m==="image"&&e.jsx(Y,{url:l.url,zoom:u,rotation:n,onZoomChange:L}),m==="pdf"&&e.jsx(ee,{url:l.url,zoom:u,currentPage:w,onPageChange:x,onTotalPagesChange:h}),m==="docx"&&e.jsx(te,{url:l.url}),m==="xlsx"&&e.jsx(se,{url:l.url}),m==="pptx"&&e.jsx(re,{url:l.url}),m==="video"&&e.jsx(ne,{url:l.url}),m==="audio"&&e.jsx(le,{url:l.url,fileName:l.name}),m==="markdown"&&e.jsx(ae,{url:l.url}),m==="text"&&e.jsx(ie,{url:l.url,fileName:l.name}),m==="unsupported"&&e.jsx(de,{fileName:l.name,fileType:l.type,onDownload:k})]}),b.length>1&&e.jsxs(e.Fragment,{children:[r>0&&e.jsx(D.motion.button,{initial:{x:-100,opacity:0},animate:{x:0,opacity:1},exit:{x:-100,opacity:0},onClick:()=>d==null?void 0:d(r-1),className:"absolute left-4 top-1/2 -translate-y-1/2 w-12 h-12 rounded-full bg-black/40 backdrop-blur-xl border border-white/10 flex items-center justify-center text-white hover:bg-black/60 transition-all shadow-2xl",children:e.jsx(y.ChevronLeft,{className:"w-6 h-6"})}),r<b.length-1&&e.jsx(D.motion.button,{initial:{x:100,opacity:0},animate:{x:0,opacity:1},exit:{x:100,opacity:0},onClick:()=>d==null?void 0:d(r+1),className:"absolute right-4 top-1/2 -translate-y-1/2 w-12 h-12 rounded-full bg-black/40 backdrop-blur-xl border border-white/10 flex items-center justify-center text-white hover:bg-black/60 transition-all shadow-2xl",children:e.jsx(y.ChevronRight,{className:"w-6 h-6"})})]})]})})})},M=({icon:s,label:r,onClick:o,disabled:c})=>e.jsx("button",{onClick:o,disabled:c,title:r,className:`p-2 rounded-lg transition-all ${c?"text-white/30 cursor-not-allowed":"text-white hover:bg-white/10 active:bg-white/20"}`,children:s});exports.FilePreviewModal=me;exports.normalizeFile=H;exports.normalizeFiles=B;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("react"),_=require("react-dom"),D=require("framer-motion"),y=require("lucide-react"),T=require("react-pdf"),Z=require("mammoth"),I=require("xlsx"),W=require("pptx-preview"),G=require("video.js"),Y=require("react-markdown"),J=require("remark-gfm"),H=require("react-syntax-highlighter");function K(s){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const n in s)if(n!=="default"){const a=Object.getOwnPropertyDescriptor(s,n);Object.defineProperty(r,n,a.get?a:{enumerable:!0,get:()=>s[n]})}}return r.default=s,Object.freeze(r)}const O=K(I),Q="1.0.2",ee={version:Q};function te(s){try{const a=new URL(s).pathname.split("/").pop()||"file";return decodeURIComponent(a)}catch{const r=s.split("/").pop()||"file";return decodeURIComponent(r)}}function $(s){var a;const r=((a=s.split(".").pop())==null?void 0:a.toLowerCase())||"";return{jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",gif:"image/gif",webp:"image/webp",svg:"image/svg+xml",bmp:"image/bmp",ico:"image/x-icon",mp4:"video/mp4",webm:"video/webm",ogg:"video/ogg",ogv:"video/ogg",mov:"video/quicktime",avi:"video/x-msvideo",mkv:"video/x-matroska",m4v:"video/x-m4v","3gp":"video/3gpp",flv:"video/x-flv",mp3:"audio/mpeg",wav:"audio/wav",m4a:"audio/mp4",aac:"audio/aac",flac:"audio/flac",pdf:"application/pdf",docx:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",xlsx:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",pptx:"application/vnd.openxmlformats-officedocument.presentationml.presentation",ppt:"application/vnd.ms-powerpoint",txt:"text/plain",md:"text/markdown",markdown:"text/markdown",json:"application/json",xml:"application/xml",html:"text/html",css:"text/css",js:"text/javascript",ts:"text/typescript",jsx:"text/javascript",tsx:"text/typescript",py:"text/x-python",java:"text/x-java",cpp:"text/x-c++src",c:"text/x-csrc",cs:"text/x-csharp",php:"text/x-php",rb:"text/x-ruby",go:"text/x-go",rs:"text/x-rust",yaml:"text/yaml",yml:"text/yaml"}[r]||"application/octet-stream"}function B(s,r=0){if(s instanceof File)return{id:`file-${Date.now()}-${r}`,name:s.name,url:URL.createObjectURL(s),type:s.type||$(s.name),size:s.size};if(typeof s=="string"){const n=te(s);return{id:`url-${Date.now()}-${r}`,name:n,url:s,type:$(n)}}return{id:s.id||`link-${Date.now()}-${r}`,name:s.name,url:s.url,type:s.type||$(s.name),size:s.size}}function A(s){return s.map((r,n)=>B(r,n))}const se=({url:s,zoom:r,rotation:n,onZoomChange:a})=>{const[d,u]=t.useState(!1),[i,o]=t.useState(null),[c,w]=t.useState({x:0,y:0}),[f,x]=t.useState(!1),[b,h]=t.useState({x:0,y:0}),[l,p]=t.useState(1),m=t.useRef(null);t.useEffect(()=>{u(!1),o(null),w({x:0,y:0}),p(1)},[s]),t.useEffect(()=>{p(r)},[r]),t.useEffect(()=>{w({x:0,y:0})},[r,n]);const N=()=>{u(!0)},S=()=>{o("图片加载失败"),u(!0)},C=()=>{w({x:0,y:0})},M=t.useCallback(v=>{v.preventDefault(),v.stopPropagation();const E=v.deltaY>0?-.1:.1;p(R=>{const z=Math.max(.5,Math.min(5,R+E));return a&&a(z),z})},[a]),L=t.useCallback(v=>{v.button===0&&(x(!0),h({x:v.clientX-c.x,y:v.clientY-c.y}))},[c]),g=t.useCallback(v=>{f&&w({x:v.clientX-b.x,y:v.clientY-b.y})},[f,b]),k=t.useCallback(()=>{x(!1)},[]);return e.jsxs("div",{ref:m,className:"flex items-center justify-center w-full h-full overflow-hidden",onWheel:M,onMouseDown:L,onMouseMove:g,onMouseUp:k,onMouseLeave:k,style:{cursor:f?"grabbing":"grab"},children:[!d&&!i&&e.jsx("div",{className:"flex items-center justify-center",children:e.jsx("div",{className:"w-12 h-12 border-4 border-white/20 border-t-white rounded-full animate-spin"})}),i&&e.jsx("div",{className:"text-white/70 text-center",children:e.jsx("p",{className:"text-lg",children:i})}),e.jsx(D.motion.img,{src:s,alt:"Preview",className:`max-w-none select-none ${d?"":"hidden"}`,style:{transform:`translate(${c.x}px, ${c.y}px) scale(${l}) rotate(${n}deg)`,transformOrigin:"center",transition:f?"none":"transform 0.3s ease-out"},onLoad:N,onError:S,onDoubleClick:C,initial:{opacity:0},animate:{opacity:d?1:0},transition:{duration:.3},draggable:!1})]})};function U(s){if(typeof window>"u")return;const{workerSrc:r=`https://unpkg.com/pdfjs-dist@${T.pdfjs.version}/build/pdf.worker.min.mjs`,cMapUrl:n=`https://unpkg.com/pdfjs-dist@${T.pdfjs.version}/cmaps/`,cMapPacked:a=!0}=s||{};T.pdfjs.GlobalWorkerOptions.workerSrc=r,T.pdfjs.GlobalWorkerOptions.cMapUrl=n,T.pdfjs.GlobalWorkerOptions.cMapPacked=a}U();const re=({url:s,zoom:r,currentPage:n,onPageChange:a,onTotalPagesChange:d})=>{const[u,i]=t.useState(0),[o,c]=t.useState(null),w=t.useRef(null),f=t.useRef(new Map);t.useEffect(()=>{c(null)},[s]);const x=({numPages:p})=>{i(p),d(p),a(1)},b=p=>{console.error("PDF 加载错误:",p),c("PDF 文件加载失败")},h=t.useCallback(()=>{if(!w.current)return;const p=w.current,m=p.scrollTop,N=p.clientHeight,S=m+N/2;let C=1,M=1/0;f.current.forEach((L,g)=>{const k=L.getBoundingClientRect(),v=p.getBoundingClientRect(),E=k.top-v.top+k.height/2+m,R=Math.abs(E-S);R<M&&(M=R,C=g)}),C!==n&&a(C)},[n,a]);t.useEffect(()=>{const p=w.current;if(p)return p.addEventListener("scroll",h),()=>p.removeEventListener("scroll",h)},[h]);const l=t.useCallback((p,m)=>{m?f.current.set(p,m):f.current.delete(p)},[]);return e.jsxs("div",{ref:w,className:"flex flex-col items-center w-full h-full overflow-auto py-8 px-4",children:[o&&e.jsx("div",{className:"text-white/70 text-center",children:e.jsx("p",{className:"text-lg",children:o})}),!o&&e.jsx(T.Document,{file:s,onLoadSuccess:x,onLoadError:b,loading:e.jsx("div",{className:"flex items-center justify-center min-h-screen",children:e.jsx("div",{className:"w-12 h-12 border-4 border-white/20 border-t-white rounded-full animate-spin"})}),children:e.jsx("div",{className:"flex flex-col gap-4",children:Array.from(new Array(u),(p,m)=>{const N=m+1;return e.jsxs("div",{ref:S=>l(N,S),className:"relative",children:[e.jsx(T.Page,{pageNumber:N,scale:r,loading:e.jsx("div",{className:"flex items-center justify-center p-8 bg-white/5 rounded-lg min-h-[600px]",children:e.jsx("div",{className:"w-8 h-8 border-4 border-white/20 border-t-white rounded-full animate-spin"})}),renderTextLayer:!0,renderAnnotationLayer:!0,className:"shadow-2xl"}),e.jsx("div",{className:"absolute top-2 right-2 bg-black/60 backdrop-blur-sm text-white text-xs px-3 py-1 rounded-full",children:N})]},`page_${N}`)})})}),u>0&&e.jsxs("div",{className:"sticky bottom-4 mt-8 bg-black/60 backdrop-blur-xl text-white px-6 py-3 rounded-full text-sm font-medium shadow-2xl border border-white/10",children:["第 ",n," 页 / 共 ",u," 页"]})]})},oe=({url:s})=>{const[r,n]=t.useState(""),[a,d]=t.useState(!0),[u,i]=t.useState(null);return t.useEffect(()=>{(async()=>{d(!0),i(null),n("");try{const c=await fetch(s);if(!c.ok)throw new Error("文件加载失败");const w=await c.arrayBuffer(),f=await Z.convertToHtml({arrayBuffer:w});n(f.value)}catch(c){console.error("Docx 解析错误:",c),i("Word 文档解析失败")}finally{d(!1)}})()},[s]),a?e.jsx("div",{className:"flex items-center justify-center w-full h-full",children:e.jsx("div",{className:"w-12 h-12 border-4 border-white/20 border-t-white rounded-full animate-spin"})}):u?e.jsx("div",{className:"flex items-center justify-center w-full h-full",children:e.jsx("div",{className:"text-white/70 text-center",children:e.jsx("p",{className:"text-lg",children:u})})}):e.jsx("div",{className:"w-full h-full overflow-auto p-8",children:e.jsx("div",{className:"max-w-4xl mx-auto bg-white rounded-lg shadow-2xl p-12",dangerouslySetInnerHTML:{__html:r},style:{fontFamily:"system-ui, -apple-system, sans-serif",lineHeight:"1.6",color:"#333"}})})},ne=({url:s})=>{const[r,n]=t.useState([]),[a,d]=t.useState(0),[u,i]=t.useState(!0),[o,c]=t.useState(null);if(t.useEffect(()=>{(async()=>{i(!0),c(null),n([]);try{const x=await fetch(s);if(!x.ok)throw new Error("文件加载失败");const b=await x.arrayBuffer(),h=O.read(b,{type:"array"}),l=h.SheetNames.map(p=>{const m=h.Sheets[p],N=O.utils.sheet_to_json(m,{header:1});return{name:p,data:N}});n(l),d(0)}catch(x){console.error("Excel 解析错误:",x),c("Excel 文件解析失败")}finally{i(!1)}})()},[s]),u)return e.jsx("div",{className:"flex items-center justify-center w-full h-full",children:e.jsx("div",{className:"w-12 h-12 border-4 border-white/20 border-t-white rounded-full animate-spin"})});if(o)return e.jsx("div",{className:"flex items-center justify-center w-full h-full",children:e.jsx("div",{className:"text-white/70 text-center",children:e.jsx("p",{className:"text-lg",children:o})})});const w=r[a];return e.jsxs("div",{className:"w-full h-full flex flex-col overflow-hidden",children:[r.length>1&&e.jsx("div",{className:"flex gap-2 p-4 bg-black/20 backdrop-blur-sm overflow-x-auto border-b border-white/10",children:r.map((f,x)=>e.jsx("button",{onClick:()=>d(x),className:`px-4 py-2 rounded-lg text-sm font-medium transition-all ${a===x?"bg-gradient-to-r from-purple-500 to-pink-500 text-white shadow-lg":"bg-white/10 text-white hover:bg-white/20"}`,children:f.name},x))}),e.jsx("div",{className:"flex-1 overflow-auto p-8",children:e.jsx("div",{className:"inline-block min-w-full bg-gradient-to-br from-gray-800/90 to-gray-900/90 backdrop-blur-xl rounded-2xl shadow-2xl overflow-hidden border border-white/10",children:e.jsx("table",{className:"min-w-full divide-y divide-white/10",children:e.jsx("tbody",{className:"divide-y divide-white/10",children:w==null?void 0:w.data.map((f,x)=>e.jsx("tr",{className:`transition-colors ${x===0?"bg-gradient-to-r from-purple-500/20 to-pink-500/20 font-semibold":"hover:bg-white/5"}`,children:f.map((b,h)=>e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-200 border-r border-white/10",children:String(b??"")},h))},x))})})})})]})},le=({url:s})=>{const[r,n]=t.useState(!0),[a,d]=t.useState(null),u=t.useRef(null),i=t.useRef(null),o=t.useRef(null),c=t.useRef(null),w=t.useRef(null),f=t.useRef({width:0,height:0}),x=t.useCallback(()=>{if(!u.current)return{width:960,height:540};const h=u.current.clientWidth,l=Math.floor(h*9/16);return console.log("计算尺寸:",{width:h,height:l}),{width:h,height:l}},[]),b=t.useCallback(async()=>{if(!(!u.current||!c.current)){console.log("重新初始化预览器...");try{if(i.current)try{i.current.destroy()}catch(p){console.error("销毁预览器失败:",p)}u.current.innerHTML="";const h=x();console.log("重新初始化使用尺寸:",h);const l=W.init(u.current,{width:h.width,height:h.height});i.current=l,await l.preview(c.current),console.log("重新初始化成功")}catch(h){console.error("重新初始化失败:",h)}}},[x]);return t.useEffect(()=>{if(!u.current)return;let h=!0;const l=()=>{if(h){h=!1;const C=x();f.current=C;return}const p=x(),m=f.current,N=Math.abs(m.width-p.width),S=Math.abs(m.height-p.height);if(N<10&&S<10){console.log("尺寸变化太小,忽略");return}console.log("检测到尺寸变化:",{old:m,new:p,diff:{width:N,height:S}}),f.current=p,w.current&&clearTimeout(w.current),w.current=window.setTimeout(()=>{i.current&&c.current&&(console.log("尺寸变化,准备重新初始化"),b())},800)};return o.current=new ResizeObserver(()=>{l()}),o.current.observe(u.current),()=>{o.current&&o.current.disconnect(),w.current&&clearTimeout(w.current)}},[x,b]),t.useEffect(()=>{let h=!0;const l=async()=>{if(!u.current){console.log("Container ref not ready");return}n(!0),d(null);try{console.log("开始加载 PPTX:",s);const m=await fetch(s);if(!m.ok)throw new Error("文件加载失败");const N=await m.arrayBuffer();if(c.current=N,console.log("文件加载成功,大小:",N.byteLength),!h)return;u.current&&(u.current.innerHTML="");const S=x();console.log("使用尺寸:",S),console.log("初始化预览器...");const C=W.init(u.current,{width:S.width,height:S.height});i.current=C,console.log("开始预览..."),C.preview(N).then(()=>{console.log("预览成功"),h&&n(!1)}).catch(M=>{console.error("预览失败:",M),h&&(d("PPT 文件预览失败"),n(!1))})}catch(m){console.error("PPTX 解析错误:",m),h&&(d(m instanceof Error?m.message:"PPT 文件解析失败"),n(!1))}},p=setTimeout(()=>{l()},100);return()=>{if(h=!1,clearTimeout(p),c.current=null,i.current)try{i.current.destroy()}catch(m){console.error("销毁预览器失败:",m)}i.current=null}},[s,x]),e.jsxs("div",{className:"relative flex flex-col items-center w-full h-full pt-[8px]",children:[r&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50 backdrop-blur-sm z-10 rounded-2xl",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-12 h-12 mx-auto mb-3 border-4 border-white/20 border-t-white rounded-full animate-spin"}),e.jsx("p",{className:"text-sm text-white/70 font-medium",children:"加载 PPT 中..."})]})}),a&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50 backdrop-blur-sm z-10 rounded-2xl",children:e.jsxs("div",{className:"text-center max-w-md",children:[e.jsx("div",{className:"w-32 h-32 mx-auto mb-6 rounded-3xl bg-gradient-to-br from-orange-500 via-red-500 to-pink-500 flex items-center justify-center shadow-2xl",children:e.jsx(y.Presentation,{className:"w-16 h-16 text-white"})}),e.jsx("p",{className:"text-xl text-white/90 mb-3 font-medium",children:"PPT 预览"}),e.jsx("p",{className:"text-sm text-white/60 mb-6",children:a||"浏览器暂不支持直接预览 PPT 文件"}),e.jsxs("a",{href:s,download:!0,className:"inline-flex items-center gap-2 px-6 py-3 bg-gradient-to-r from-purple-500 to-pink-500 text-white rounded-xl hover:scale-105 transition-all shadow-lg",children:[e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"})}),"下载文件"]}),e.jsx("p",{className:"text-xs text-white/40 mt-4",children:"提示:可以使用 Microsoft PowerPoint 或 WPS 打开"})]})}),e.jsx("div",{ref:u,className:"pptx-wrapper w-full max-w-6xl"})]})},ae=s=>{var a;const r=((a=s.split(".").pop())==null?void 0:a.toLowerCase().split("?")[0])||"";return{mp4:"video/mp4",webm:"video/webm",ogg:"video/ogg",ogv:"video/ogg",mov:"video/quicktime",avi:"video/x-msvideo",mkv:"video/x-matroska",m4v:"video/mp4","3gp":"video/3gpp",flv:"video/x-flv"}[r]||"video/mp4"},ce=({url:s})=>{const[r,n]=t.useState(null),[a,d]=t.useState(!0),u=t.useRef(null),i=t.useRef(null);return t.useEffect(()=>{if(!i.current&&u.current){const o=document.createElement("video-js");o.classList.add("vjs-big-play-centered","vjs-theme-apple"),u.current.appendChild(o);const c=ae(s),f=G(o,{controls:!0,responsive:!0,fluid:!0,preload:"auto",controlBar:{children:["playToggle","volumePanel","currentTimeDisplay","timeDivider","durationDisplay","progressControl","remainingTimeDisplay","fullscreenToggle"],volumePanel:{inline:!1}},html5:{vhs:{overrideNative:!0},nativeVideoTracks:!1,nativeAudioTracks:!1,nativeTextTracks:!1},sources:c==="video/quicktime"?[{src:s,type:"video/quicktime"},{src:s,type:"video/mp4"}]:[{src:s,type:c}]});f.on("loadeddata",()=>{d(!1)}),f.on("error",()=>{const x=f.error();console.error("Video.js error:",x),n(`视频加载失败: ${(x==null?void 0:x.message)||"未知错误"}`),d(!1)}),i.current=f}},[s]),t.useEffect(()=>{const o=i.current;return()=>{o&&!o.isDisposed()&&(o.dispose(),i.current=null)}},[]),r?e.jsx("div",{className:"flex items-center justify-center w-full h-full",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-16 h-16 mx-auto mb-4 rounded-full bg-red-500/10 flex items-center justify-center",children:e.jsx("svg",{className:"w-8 h-8 text-red-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})}),e.jsx("p",{className:"text-lg font-medium text-white/90 mb-2",children:"视频加载失败"}),e.jsx("p",{className:"text-sm text-white/60",children:r})]})}):e.jsx("div",{className:"flex items-center justify-center w-full h-full p-8",children:e.jsxs("div",{className:"w-full max-w-5xl relative",children:[a&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/20 backdrop-blur-sm rounded-2xl z-10",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-12 h-12 mx-auto mb-3 border-3 border-white/20 border-t-white rounded-full animate-spin"}),e.jsx("p",{className:"text-sm text-white/70 font-medium",children:"加载视频中..."})]})}),e.jsx("div",{ref:u,className:"overflow-hidden",style:{boxShadow:"0 20px 60px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.05)"}})]})})},ie=({url:s,fileName:r})=>{const[n,a]=t.useState(null),[d,u]=t.useState(!1),[i,o]=t.useState(0),[c,w]=t.useState(0),[f,x]=t.useState(1),[b,h]=t.useState(!1),l=t.useRef(null);t.useEffect(()=>{const g=l.current;if(!g)return;const k=()=>{isNaN(g.currentTime)||o(g.currentTime)},v=()=>{!isNaN(g.duration)&&isFinite(g.duration)&&w(g.duration)},E=()=>u(!1),R=()=>v();return g.addEventListener("timeupdate",k),g.addEventListener("loadedmetadata",v),g.addEventListener("durationchange",v),g.addEventListener("canplay",R),g.addEventListener("ended",E),g.readyState>=1&&v(),()=>{g.removeEventListener("timeupdate",k),g.removeEventListener("loadedmetadata",v),g.removeEventListener("durationchange",v),g.removeEventListener("canplay",R),g.removeEventListener("ended",E)}},[]);const p=()=>{l.current&&(d?l.current.pause():l.current.play(),u(!d))},m=g=>{const k=parseFloat(g.target.value);o(k),l.current&&(l.current.currentTime=k)},N=g=>{const k=parseFloat(g.target.value);x(k),l.current&&(l.current.volume=k),k>0&&h(!1)},S=()=>{l.current&&(l.current.muted=!b,h(!b))},C=g=>{l.current&&(l.current.currentTime+=g)},M=g=>{if(!isFinite(g)||isNaN(g)||g<0)return"0:00";const k=Math.floor(g/60),v=Math.floor(g%60);return`${k}:${v.toString().padStart(2,"0")}`},L=()=>{a("音频加载失败")};return n?e.jsx("div",{className:"flex items-center justify-center w-full h-full",children:e.jsx("div",{className:"text-white/70 text-center",children:e.jsx("p",{className:"text-lg",children:n})})}):e.jsxs("div",{className:"flex flex-col items-center justify-center w-full h-full p-8 gap-8",children:[e.jsx("div",{className:"w-64 h-64 rounded-3xl bg-gradient-to-br from-purple-500 via-pink-500 to-rose-500 flex items-center justify-center shadow-2xl backdrop-blur-xl",children:e.jsx(y.Music,{className:"w-32 h-32 text-white"})}),e.jsxs("div",{className:"text-white text-center max-w-md",children:[e.jsx("p",{className:"text-2xl font-medium mb-1",children:r}),e.jsx("p",{className:"text-sm text-white/60",children:"音频文件"})]}),e.jsxs("div",{className:"w-full max-w-md bg-white/10 backdrop-blur-xl rounded-2xl p-6 border border-white/20",children:[e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"relative h-4 flex items-center",children:[e.jsx("div",{className:"absolute w-full h-[6px] bg-white/20 rounded-full"}),e.jsx("div",{className:"absolute h-[6px] bg-gradient-to-r from-purple-500 to-pink-500 rounded-full transition-all duration-100 ease-linear pointer-events-none",style:{width:`${c>0?i/c*100:i>100?100:i}%`}}),e.jsx("input",{type:"range",min:"0",max:c>0?c:100+(i>100?i%100:0),value:i,onChange:m,className:"audio-slider absolute w-full"})]}),e.jsxs("div",{className:"flex justify-between text-xs text-white/60 mt-3",children:[e.jsx("span",{children:M(i)}),e.jsx("span",{children:M(c)})]})]}),e.jsxs("div",{className:"flex items-center justify-center gap-4 mb-4",children:[e.jsx("button",{onClick:()=>C(-10),className:"w-10 h-10 rounded-full bg-white/10 hover:bg-white/20 flex items-center justify-center text-white transition-all",children:e.jsx(y.SkipBack,{className:"w-5 h-5"})}),e.jsx("button",{onClick:p,className:"w-14 h-14 rounded-full bg-gradient-to-br from-purple-500 to-pink-500 hover:scale-105 flex items-center justify-center text-white transition-all shadow-lg",children:d?e.jsx(y.Pause,{className:"w-6 h-6"}):e.jsx(y.Play,{className:"w-6 h-6 ml-1"})}),e.jsx("button",{onClick:()=>C(10),className:"w-10 h-10 rounded-full bg-white/10 hover:bg-white/20 flex items-center justify-center text-white transition-all",children:e.jsx(y.SkipForward,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:S,className:"text-white/80 hover:text-white transition-colors",children:b||f===0?e.jsx(y.VolumeX,{className:"w-5 h-5"}):e.jsx(y.Volume2,{className:"w-5 h-5"})}),e.jsxs("div",{className:"flex-1 relative h-3 flex items-center",children:[e.jsx("div",{className:"absolute w-full h-[4px] bg-white/20 rounded-full"}),e.jsx("div",{className:"absolute h-[4px] bg-purple-500 rounded-full transition-all duration-100 pointer-events-none",style:{width:`${(b?0:f)*100}%`}}),e.jsx("input",{type:"range",min:"0",max:"1",step:"0.01",value:b?0:f,onChange:N,className:"volume-slider absolute w-full"})]})]})]}),e.jsx("audio",{ref:l,src:s,onError:L,className:"hidden"})]})},X={'pre[class*="language-"]':{color:"#d4d4d4",fontSize:"13px",textShadow:"none",fontFamily:'Menlo, Monaco, Consolas, "Andale Mono", "Ubuntu Mono", "Courier New", monospace',direction:"ltr",textAlign:"left",whiteSpace:"pre",wordSpacing:"normal",wordBreak:"normal",lineHeight:"1.5",MozTabSize:"4",OTabSize:"4",tabSize:"4",WebkitHyphens:"none",MozHyphens:"none",msHyphens:"none",hyphens:"none",padding:"1em",margin:".5em 0",overflow:"auto",background:"#1e1e1e"},'code[class*="language-"]':{color:"#d4d4d4",fontSize:"13px",textShadow:"none",fontFamily:'Menlo, Monaco, Consolas, "Andale Mono", "Ubuntu Mono", "Courier New", monospace',direction:"ltr",textAlign:"left",whiteSpace:"pre",wordSpacing:"normal",wordBreak:"normal",lineHeight:"1.5",MozTabSize:"4",OTabSize:"4",tabSize:"4",WebkitHyphens:"none",MozHyphens:"none",msHyphens:"none",hyphens:"none"},'pre[class*="language-"]::selection':{textShadow:"none",background:"#264F78"},'code[class*="language-"]::selection':{textShadow:"none",background:"#264F78"},'pre[class*="language-"] *::selection':{textShadow:"none",background:"#264F78"},'code[class*="language-"] *::selection':{textShadow:"none",background:"#264F78"},':not(pre) > code[class*="language-"]':{padding:".1em .3em",borderRadius:".3em",color:"#db4c69",background:"#1e1e1e"},".namespace":{Opacity:".7"},"doctype.doctype-tag":{color:"#569CD6"},"doctype.name":{color:"#9cdcfe"},comment:{color:"#6a9955"},prolog:{color:"#6a9955"},punctuation:{color:"#d4d4d4"},".language-html .language-css .token.punctuation":{color:"#d4d4d4"},".language-html .language-javascript .token.punctuation":{color:"#d4d4d4"},property:{color:"#9cdcfe"},tag:{color:"#569cd6"},boolean:{color:"#569cd6"},number:{color:"#b5cea8"},constant:{color:"#9cdcfe"},symbol:{color:"#b5cea8"},inserted:{color:"#b5cea8"},unit:{color:"#b5cea8"},selector:{color:"#d7ba7d"},"attr-name":{color:"#9cdcfe"},string:{color:"#ce9178"},char:{color:"#ce9178"},builtin:{color:"#ce9178"},deleted:{color:"#ce9178"},".language-css .token.string.url":{textDecoration:"underline"},operator:{color:"#d4d4d4"},entity:{color:"#569cd6"},"operator.arrow":{color:"#569CD6"},atrule:{color:"#ce9178"},"atrule.rule":{color:"#c586c0"},"atrule.url":{color:"#9cdcfe"},"atrule.url.function":{color:"#dcdcaa"},"atrule.url.punctuation":{color:"#d4d4d4"},keyword:{color:"#569CD6"},"keyword.module":{color:"#c586c0"},"keyword.control-flow":{color:"#c586c0"},function:{color:"#dcdcaa"},"function.maybe-class-name":{color:"#dcdcaa"},regex:{color:"#d16969"},important:{color:"#569cd6"},italic:{fontStyle:"italic"},"class-name":{color:"#4ec9b0"},"maybe-class-name":{color:"#4ec9b0"},console:{color:"#9cdcfe"},parameter:{color:"#9cdcfe"},interpolation:{color:"#9cdcfe"},"punctuation.interpolation-punctuation":{color:"#569cd6"},variable:{color:"#9cdcfe"},"imports.maybe-class-name":{color:"#9cdcfe"},"exports.maybe-class-name":{color:"#9cdcfe"},escape:{color:"#d7ba7d"},"tag.punctuation":{color:"#808080"},cdata:{color:"#808080"},"attr-value":{color:"#ce9178"},"attr-value.punctuation":{color:"#ce9178"},"attr-value.punctuation.attr-equals":{color:"#d4d4d4"},namespace:{color:"#4ec9b0"},'pre[class*="language-javascript"]':{color:"#9cdcfe"},'code[class*="language-javascript"]':{color:"#9cdcfe"},'pre[class*="language-jsx"]':{color:"#9cdcfe"},'code[class*="language-jsx"]':{color:"#9cdcfe"},'pre[class*="language-typescript"]':{color:"#9cdcfe"},'code[class*="language-typescript"]':{color:"#9cdcfe"},'pre[class*="language-tsx"]':{color:"#9cdcfe"},'code[class*="language-tsx"]':{color:"#9cdcfe"},'pre[class*="language-css"]':{color:"#ce9178"},'code[class*="language-css"]':{color:"#ce9178"},'pre[class*="language-html"]':{color:"#d4d4d4"},'code[class*="language-html"]':{color:"#d4d4d4"},".language-regex .token.anchor":{color:"#dcdcaa"},".language-html .token.punctuation":{color:"#808080"},'pre[class*="language-"] > code[class*="language-"]':{position:"relative",zIndex:"1"},".line-highlight.line-highlight":{background:"#f7ebc6",boxShadow:"inset 5px 0 0 #f7d87c",zIndex:"0"}},de=({url:s})=>{const[r,n]=t.useState(""),[a,d]=t.useState(!0),[u,i]=t.useState(null);return t.useEffect(()=>{(async()=>{try{d(!0),i(null);const c=await fetch(s);if(!c.ok)throw new Error("加载失败");const w=await c.text();n(w)}catch(c){i("Markdown 文件加载失败"),console.error(c)}finally{d(!1)}})()},[s]),a?e.jsx("div",{className:"flex items-center justify-center w-full h-full",children:e.jsx("div",{className:"w-12 h-12 border-4 border-white/20 border-t-white rounded-full animate-spin"})}):u?e.jsx("div",{className:"flex items-center justify-center w-full h-full",children:e.jsx("div",{className:"text-white/70 text-center",children:e.jsx("p",{className:"text-lg",children:u})})}):e.jsx("div",{className:"w-full h-full overflow-auto p-8",children:e.jsx("div",{className:"max-w-4xl mx-auto bg-white/5 backdrop-blur-sm rounded-2xl p-8 border border-white/10",children:e.jsx("div",{className:"prose prose-invert prose-lg max-w-none",children:e.jsx(Y,{remarkPlugins:[J],components:{code({node:o,inline:c,className:w,children:f,...x}){const b=/language-(\w+)/.exec(w||"");return!c&&b?e.jsx(H.Prism,{style:X,language:b[1],PreTag:"div",className:"rounded-lg",...x,children:String(f).replace(/\n$/,"")}):e.jsx("code",{className:"bg-white/10 px-1.5 py-0.5 rounded text-sm",...x,children:f})},h1:({children:o})=>e.jsx("h1",{className:"text-4xl font-bold mb-4 text-white border-b border-white/20 pb-2",children:o}),h2:({children:o})=>e.jsx("h2",{className:"text-3xl font-bold mb-3 text-white mt-8",children:o}),h3:({children:o})=>e.jsx("h3",{className:"text-2xl font-bold mb-2 text-white mt-6",children:o}),p:({children:o})=>e.jsx("p",{className:"text-white/90 mb-4 leading-relaxed",children:o}),a:({href:o,children:c})=>e.jsx("a",{href:o,className:"text-blue-400 hover:text-blue-300 underline",target:"_blank",rel:"noopener noreferrer",children:c}),ul:({children:o})=>e.jsx("ul",{className:"list-disc list-inside mb-4 text-white/90",children:o}),ol:({children:o})=>e.jsx("ol",{className:"list-decimal list-inside mb-4 text-white/90",children:o}),li:({children:o})=>e.jsx("li",{className:"mb-1",children:o}),blockquote:({children:o})=>e.jsx("blockquote",{className:"border-l-4 border-blue-500 pl-4 italic text-white/80 my-4",children:o}),table:({children:o})=>e.jsx("div",{className:"overflow-x-auto my-4",children:e.jsx("table",{className:"min-w-full border border-white/20",children:o})}),th:({children:o})=>e.jsx("th",{className:"border border-white/20 px-4 py-2 bg-white/10 text-white font-semibold",children:o}),td:({children:o})=>e.jsx("td",{className:"border border-white/20 px-4 py-2 text-white/90",children:o}),hr:()=>e.jsx("hr",{className:"border-white/20 my-6"}),img:({src:o,alt:c})=>e.jsx("img",{src:o,alt:c,className:"rounded-lg max-w-full h-auto my-4"})},children:r})})})})},ue=s=>{var a;const r=((a=s.split(".").pop())==null?void 0:a.toLowerCase())||"";return{js:"javascript",jsx:"jsx",ts:"typescript",tsx:"tsx",py:"python",java:"java",cpp:"cpp",c:"c",cs:"csharp",php:"php",rb:"ruby",go:"go",rs:"rust",swift:"swift",kt:"kotlin",scala:"scala",sh:"bash",bash:"bash",zsh:"bash",json:"json",xml:"xml",html:"html",css:"css",scss:"scss",sass:"sass",less:"less",sql:"sql",yaml:"yaml",yml:"yaml",toml:"toml",ini:"ini",conf:"nginx",md:"markdown",txt:"text"}[r]||"text"},me=({url:s,fileName:r})=>{const[n,a]=t.useState(""),[d,u]=t.useState(!0),[i,o]=t.useState(null),c=ue(r);return t.useEffect(()=>{(async()=>{try{u(!0),o(null);const f=await fetch(s);if(!f.ok)throw new Error("加载失败");const x=await f.text();a(x)}catch(f){o("文本文件加载失败"),console.error(f)}finally{u(!1)}})()},[s]),d?e.jsx("div",{className:"flex items-center justify-center w-full h-full",children:e.jsx("div",{className:"w-12 h-12 border-4 border-white/20 border-t-white rounded-full animate-spin"})}):i?e.jsx("div",{className:"flex items-center justify-center w-full h-full",children:e.jsx("div",{className:"text-white/70 text-center",children:e.jsx("p",{className:"text-lg",children:i})})}):e.jsx("div",{className:"w-full h-full overflow-auto p-8",children:e.jsxs("div",{className:"max-w-6xl mx-auto bg-white/5 backdrop-blur-sm rounded-2xl border border-white/10 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-3 px-6 py-4 bg-white/5 border-b border-white/10",children:[e.jsx(y.FileText,{className:"w-5 h-5 text-white/70"}),e.jsx("span",{className:"text-white font-medium",children:r}),e.jsx("span",{className:"ml-auto text-xs text-white/50 uppercase",children:c})]}),e.jsx("div",{className:"text-sm",children:c==="text"?e.jsx("pre",{className:"p-6 text-white/90 font-mono whitespace-pre-wrap break-words",children:n}):e.jsx(H.Prism,{language:c,style:X,showLineNumbers:!0,customStyle:{margin:0,padding:"1.5rem",background:"transparent",fontSize:"0.875rem"},lineNumberStyle:{minWidth:"3em",paddingRight:"1em",color:"rgba(255, 255, 255, 0.3)",userSelect:"none"},children:n})})]})})},xe=({fileName:s,fileType:r,onDownload:n})=>e.jsxs("div",{className:"flex flex-col items-center justify-center w-full h-full p-8 gap-6",children:[e.jsx("div",{className:"w-32 h-32 rounded-full bg-white/10 flex items-center justify-center",children:e.jsx(y.FileQuestion,{className:"w-16 h-16 text-white/70"})}),e.jsxs("div",{className:"text-white text-center",children:[e.jsx("p",{className:"text-xl font-medium mb-2",children:s}),e.jsxs("p",{className:"text-white/70",children:["不支持预览此文件类型 (",r,")"]})]}),e.jsxs("button",{onClick:n,className:"flex items-center gap-2 px-6 py-3 bg-white/10 hover:bg-white/20 backdrop-blur-sm rounded-lg text-white font-medium transition-all",children:[e.jsx(y.Download,{className:"w-5 h-5"}),"下载文件查看"]})]}),he=s=>{var d;const r=((d=s.name.split(".").pop())==null?void 0:d.toLowerCase())||"",n=s.type.toLowerCase();if(n.startsWith("image/")||["jpg","jpeg","png","gif","webp","svg"].includes(r))return"image";if(n.includes("pdf")||r==="pdf")return"pdf";if(n.includes("wordprocessingml")||r==="docx")return"docx";if(n.includes("spreadsheetml")||r==="xlsx")return"xlsx";if(n.includes("presentationml")||r==="pptx"||r==="ppt")return"pptx";if(n.startsWith("video/")||["mp4","webm","ogg","ogv","mov","avi","mkv","m4v","3gp","flv"].includes(r))return"video";if(n.startsWith("audio/")||["mp3","wav","ogg","m4a","flac","aac"].includes(r))return"audio";if(r==="md"||r==="markdown")return"markdown";const a=["txt","log","csv","js","jsx","ts","tsx","json","py","java","cpp","c","h","cs","php","rb","go","rs","swift","kt","html","css","scss","sass","less","xml","yaml","yml","toml","ini","conf","sh","bash","zsh","sql"];return n.startsWith("text/")||a.includes(r)?"text":"unsupported"},fe=({files:s,currentIndex:r,isOpen:n,onClose:a,onNavigate:d,customRenderers:u=[]})=>{const[i,o]=t.useState(1),[c,w]=t.useState(0),[f,x]=t.useState(1),[,b]=t.useState(1),h=t.useMemo(()=>A(s),[s]),l=h[r],p=t.useMemo(()=>l?u.find(j=>j.test(l)):null,[l,u]),m=l?he(l):"unsupported";t.useEffect(()=>{o(1),w(0),x(1),b(1)},[r]),t.useEffect(()=>{if(n){const j=document.body.style.overflow,F=document.body.style.paddingRight,q=window.innerWidth-document.documentElement.clientWidth;return document.body.style.overflow="hidden",q>0&&(document.body.style.paddingRight=`${q}px`),()=>{document.body.style.overflow=j,document.body.style.paddingRight=F}}},[n]),t.useEffect(()=>{if(!n)return;const j=F=>{F.key==="Escape"?a():F.key==="ArrowLeft"&&r>0?d==null||d(r-1):F.key==="ArrowRight"&&r<h.length-1&&(d==null||d(r+1))};return window.addEventListener("keydown",j),()=>window.removeEventListener("keydown",j)},[n,r,h.length,a,d]);const N=t.useCallback(()=>{o(j=>Math.min(j+.25,5))},[]),S=t.useCallback(()=>{o(j=>Math.max(j-.25,.5))},[]),C=t.useCallback(()=>{w(j=>j+90)},[]),M=t.useCallback(()=>{w(j=>j-90)},[]),L=t.useCallback(()=>{o(1),w(0)},[]),g=t.useCallback(()=>{o(1)},[]),k=t.useCallback(j=>{o(j)},[]),v=t.useCallback(()=>{o(1),w(0)},[]),E=t.useCallback(()=>{if(!l)return;const j=document.createElement("a");j.href=l.url,j.download=l.name,j.click()},[l]);if(!n||!l)return null;const R=m==="image"||m==="pdf",z=m==="image",V=e.jsx(D.AnimatePresence,{children:n&&e.jsx(D.motion.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/80 backdrop-blur-md overflow-hidden",onClick:a,onWheel:j=>j.stopPropagation(),children:e.jsxs("div",{className:"relative w-full h-full flex flex-col overflow-hidden",onClick:j=>j.stopPropagation(),children:[e.jsx(D.motion.div,{initial:{y:-100},animate:{y:0},exit:{y:-100},className:"absolute top-0 left-0 right-0 z-10 p-4",children:e.jsxs("div",{className:"max-w-7xl mx-auto flex items-center justify-between bg-black/40 backdrop-blur-xl rounded-2xl px-6 py-4 shadow-2xl border border-white/10",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h2",{className:"text-white font-medium text-lg truncate",children:l.name}),e.jsxs("p",{className:"text-white/60 text-sm",children:[r+1," / ",h.length]})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-4",children:[R&&e.jsxs(e.Fragment,{children:[e.jsx(P,{icon:e.jsx(y.ZoomOut,{className:"w-5 h-5"}),label:"缩小",onClick:S,disabled:i<=.5}),e.jsxs("span",{className:"text-white/70 text-sm min-w-[4rem] text-center font-medium",children:[Math.round(i*100),"%"]}),e.jsx(P,{icon:e.jsx(y.ZoomIn,{className:"w-5 h-5"}),label:"放大",onClick:N,disabled:i>=5}),e.jsx("div",{className:"w-px h-6 bg-white/20 mx-2"}),e.jsx(P,{icon:e.jsx(y.Minimize2,{className:"w-5 h-5"}),label:"适应窗口",onClick:L}),e.jsx(P,{icon:e.jsx(y.Maximize2,{className:"w-5 h-5"}),label:"原始尺寸",onClick:g}),e.jsx("div",{className:"w-px h-6 bg-white/20 mx-2"})]}),z&&e.jsxs(e.Fragment,{children:[e.jsx(P,{icon:e.jsx(y.RotateCcw,{className:"w-5 h-5"}),label:"向左旋转",onClick:M}),e.jsx(P,{icon:e.jsx(y.RotateCw,{className:"w-5 h-5"}),label:"向右旋转",onClick:C}),e.jsx("div",{className:"w-px h-6 bg-white/20 mx-2"})]}),(R||z)&&e.jsxs(e.Fragment,{children:[e.jsx(P,{icon:e.jsx(y.RefreshCw,{className:"w-5 h-5"}),label:"复原",onClick:v}),e.jsx("div",{className:"w-px h-6 bg-white/20 mx-2"})]}),e.jsx(P,{icon:e.jsx(y.Download,{className:"w-5 h-5"}),label:"下载",onClick:E}),e.jsx("div",{className:"w-px h-6 bg-white/20 mx-2"}),e.jsx(P,{icon:e.jsx(y.X,{className:"w-5 h-5"}),label:"关闭",onClick:a})]})]})}),e.jsx("div",{className:"flex-1 flex items-center justify-center pt-24 pb-8 overflow-auto",children:p?p.render(l):e.jsxs(e.Fragment,{children:[m==="image"&&e.jsx(se,{url:l.url,zoom:i,rotation:c,onZoomChange:k}),m==="pdf"&&e.jsx(re,{url:l.url,zoom:i,currentPage:f,onPageChange:x,onTotalPagesChange:b}),m==="docx"&&e.jsx(oe,{url:l.url}),m==="xlsx"&&e.jsx(ne,{url:l.url}),m==="pptx"&&e.jsx(le,{url:l.url}),m==="video"&&e.jsx(ce,{url:l.url}),m==="audio"&&e.jsx(ie,{url:l.url,fileName:l.name}),m==="markdown"&&e.jsx(de,{url:l.url}),m==="text"&&e.jsx(me,{url:l.url,fileName:l.name}),m==="unsupported"&&e.jsx(xe,{fileName:l.name,fileType:l.type,onDownload:E})]})}),h.length>1&&e.jsxs(e.Fragment,{children:[r>0&&e.jsx(D.motion.button,{initial:{x:-100,opacity:0},animate:{x:0,opacity:1},exit:{x:-100,opacity:0},onClick:()=>d==null?void 0:d(r-1),className:"absolute left-4 top-1/2 -translate-y-1/2 w-12 h-12 rounded-full bg-black/40 backdrop-blur-xl border border-white/10 flex items-center justify-center text-white hover:bg-black/60 transition-all shadow-2xl",children:e.jsx(y.ChevronLeft,{className:"w-6 h-6"})}),r<h.length-1&&e.jsx(D.motion.button,{initial:{x:100,opacity:0},animate:{x:0,opacity:1},exit:{x:100,opacity:0},onClick:()=>d==null?void 0:d(r+1),className:"absolute right-4 top-1/2 -translate-y-1/2 w-12 h-12 rounded-full bg-black/40 backdrop-blur-xl border border-white/10 flex items-center justify-center text-white hover:bg-black/60 transition-all shadow-2xl",children:e.jsx(y.ChevronRight,{className:"w-6 h-6"})})]})]})})});return _.createPortal(V,document.body)},P=({icon:s,label:r,onClick:n,disabled:a})=>e.jsx("button",{onClick:n,disabled:a,title:r,className:`p-2 rounded-lg transition-all ${a?"text-white/30 cursor-not-allowed":"text-white hover:bg-white/10 active:bg-white/20"}`,children:s}),pe=ee.version;Object.defineProperty(exports,"pdfjs",{enumerable:!0,get:()=>T.pdfjs});exports.FilePreviewModal=fe;exports.VERSION=pe;exports.configurePdfjs=U;exports.normalizeFile=B;exports.normalizeFiles=A;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|