@files-preview-app/preview-file 1.0.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +299 -295
- package/THIRD_PARTY_LICENSES.md +7 -3
- package/dist/angular.cjs +825 -0
- package/dist/angular.cjs.map +1 -1
- package/dist/angular.js +824 -0
- package/dist/angular.js.map +1 -1
- package/dist/index.cjs +808 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +804 -1
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +825 -0
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +4 -0
- package/dist/react.d.ts +4 -0
- package/dist/react.js +824 -0
- package/dist/react.js.map +1 -1
- package/dist/vue.cjs +825 -0
- package/dist/vue.cjs.map +1 -1
- package/dist/vue.js +824 -0
- package/dist/vue.js.map +1 -1
- package/package.json +17 -4
package/README.md
CHANGED
|
@@ -1,296 +1,300 @@
|
|
|
1
|
-
# @
|
|
2
|
-
|
|
3
|
-
> **Universal, all-in-one client-side file preview package for React, Angular, Vue, and Vanilla JS.**
|
|
4
|
-
> Preview **PDF, Word (.docx), Excel (.xlsx), CSV, Images, Video, Audio, and Code/Text** with a built-in toolbar (zoom, rotate, thumbnails, page jump, download, print). 100% free, permissive open-source, and client-side (no cloud or server needed).
|
|
5
|
-
|
|
6
|
-
[](https://opensource.org/licenses/MIT)
|
|
8
|
-
|
|
9
|
-
---
|
|
10
|
-
|
|
11
|
-
## 📦 Installation
|
|
12
|
-
|
|
13
|
-
Just install this **single package** in your project:
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
npm install @
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
Or using Yarn / pnpm:
|
|
20
|
-
```bash
|
|
21
|
-
yarn add @
|
|
22
|
-
# or
|
|
23
|
-
pnpm add @
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
Import the toolbar stylesheet in your main CSS or component:
|
|
27
|
-
```css
|
|
28
|
-
import '@
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
---
|
|
32
|
-
|
|
33
|
-
## 🚀 Quick Start by Framework
|
|
34
|
-
|
|
35
|
-
### 1. React (`@
|
|
36
|
-
|
|
37
|
-
```tsx
|
|
38
|
-
import React, { useState } from 'react';
|
|
39
|
-
import { FilePreview } from '@
|
|
40
|
-
import '@
|
|
41
|
-
|
|
42
|
-
export default function App() {
|
|
43
|
-
const [selectedFile, setSelectedFile] = useState<File | string>('https://example.com/sample.pdf');
|
|
44
|
-
|
|
45
|
-
return (
|
|
46
|
-
<div>
|
|
47
|
-
{/* File input for local files */}
|
|
48
|
-
<input
|
|
49
|
-
type="file"
|
|
50
|
-
onChange={(e) => e.target.files?.[0] && setSelectedFile(e.target.files[0])}
|
|
51
|
-
/>
|
|
52
|
-
|
|
53
|
-
{/* Preview container */}
|
|
54
|
-
<div style={{ width: '100%', height: '800px', marginTop: '16px' }}>
|
|
55
|
-
<FilePreview
|
|
56
|
-
src={selectedFile}
|
|
57
|
-
options={{
|
|
58
|
-
theme: 'light', // 'light' | 'dark' | 'auto'
|
|
59
|
-
showToolbar: true,
|
|
60
|
-
toolbarPosition: 'top' // 'top' | 'bottom'
|
|
61
|
-
}}
|
|
62
|
-
onLoaded={(info) => console.log('File loaded successfully:', info)}
|
|
63
|
-
onError={(error) => console.error('Preview error:', error)}
|
|
64
|
-
/>
|
|
65
|
-
</div>
|
|
66
|
-
</div>
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
---
|
|
72
|
-
|
|
73
|
-
### 2. Angular (`@
|
|
74
|
-
|
|
75
|
-
In your standalone component or NgModule:
|
|
76
|
-
|
|
77
|
-
```typescript
|
|
78
|
-
import { Component } from '@angular/core';
|
|
79
|
-
import { FilePreviewComponent } from '@
|
|
80
|
-
|
|
81
|
-
@Component({
|
|
82
|
-
selector: 'app-root',
|
|
83
|
-
standalone: true,
|
|
84
|
-
imports: [FilePreviewComponent],
|
|
85
|
-
template: `
|
|
86
|
-
<div style="width: 100%; height: 800px;">
|
|
87
|
-
<input type="file" (change)="onFileSelected($event)" />
|
|
88
|
-
|
|
89
|
-
<fp-file-preview
|
|
90
|
-
[src]="fileSource"
|
|
91
|
-
[options]="{ theme: 'light', showToolbar: true }"
|
|
92
|
-
(loaded)="onLoaded($event)"
|
|
93
|
-
(error)="onError($event)"
|
|
94
|
-
/>
|
|
95
|
-
</div>
|
|
96
|
-
`,
|
|
97
|
-
styleUrls: ['@
|
|
98
|
-
})
|
|
99
|
-
export class AppComponent {
|
|
100
|
-
fileSource: string | File = 'https://example.com/report.xlsx';
|
|
101
|
-
|
|
102
|
-
onFileSelected(event: Event) {
|
|
103
|
-
const input = event.target as HTMLInputElement;
|
|
104
|
-
if (input.files?.[0]) {
|
|
105
|
-
this.fileSource = input.files[0];
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
onLoaded(event: unknown) {
|
|
110
|
-
console.log('Preview ready', event);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
onError(err: Error) {
|
|
114
|
-
console.error('Preview failed', err);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
---
|
|
120
|
-
|
|
121
|
-
### 3. Vue 3 (`@
|
|
122
|
-
|
|
123
|
-
```vue
|
|
124
|
-
<template>
|
|
125
|
-
<div style="width: 100%; height: 800px;">
|
|
126
|
-
<input type="file" @change="onFileChange" />
|
|
127
|
-
|
|
128
|
-
<FilePreview
|
|
129
|
-
:src="currentFile"
|
|
130
|
-
:options="{ theme: 'dark', showToolbar: true }"
|
|
131
|
-
@loaded="handleLoaded"
|
|
132
|
-
@error="handleError"
|
|
133
|
-
/>
|
|
134
|
-
</div>
|
|
135
|
-
</template>
|
|
136
|
-
|
|
137
|
-
<script setup lang="ts">
|
|
138
|
-
import { ref } from 'vue';
|
|
139
|
-
import { FilePreview } from '@
|
|
140
|
-
import '@
|
|
141
|
-
|
|
142
|
-
const currentFile = ref<File | string>('/sample.docx');
|
|
143
|
-
|
|
144
|
-
function onFileChange(event: Event) {
|
|
145
|
-
const target = event.target as HTMLInputElement;
|
|
146
|
-
if (target.files?.[0]) {
|
|
147
|
-
currentFile.value = target.files[0];
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function handleLoaded(data: unknown) {
|
|
152
|
-
console.log('Loaded:', data);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
function handleError(err: unknown) {
|
|
156
|
-
console.error('Error:', err);
|
|
157
|
-
}
|
|
158
|
-
</script>
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
---
|
|
162
|
-
|
|
163
|
-
### 4. Vanilla JavaScript / TypeScript (`@
|
|
164
|
-
|
|
165
|
-
```html
|
|
166
|
-
<link rel="stylesheet" href="node_modules/@
|
|
167
|
-
|
|
168
|
-
<div id="viewer-container" style="width: 100%; height: 800px;"></div>
|
|
169
|
-
|
|
170
|
-
<script type="module">
|
|
171
|
-
import { FilePreviewViewer } from '@
|
|
172
|
-
|
|
173
|
-
const container = document.getElementById('viewer-container');
|
|
174
|
-
const viewer = new FilePreviewViewer();
|
|
175
|
-
|
|
176
|
-
// Preview from URL, File, Blob, or ArrayBuffer
|
|
177
|
-
await viewer.preview(container, 'https://example.com/invoice.pdf', {
|
|
178
|
-
theme: 'light',
|
|
179
|
-
showToolbar: true
|
|
180
|
-
});
|
|
181
|
-
</script>
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
---
|
|
185
|
-
|
|
186
|
-
## 📂 Supported Extensions & Built-in Controls
|
|
187
|
-
|
|
188
|
-
The viewer automatically recognizes the file extension and magic binary bytes, activating the corresponding renderer and controls:
|
|
189
|
-
|
|
190
|
-
| File Format | Extensions | Controls Available |
|
|
191
|
-
|---|---|---|
|
|
192
|
-
| **PDF** | `.pdf` | Zoom In/Out, Fit to Page, Rotate CW/CCW, Page Navigation Jump, Thumbnails Sidebar, Download, Print |
|
|
193
|
-
| **Word Document** | `.docx` | Full layout rendering, Zoom In/Out, Fit to Page, Download, Print |
|
|
194
|
-
| **Excel Spreadsheet** | `.xlsx`, `.xls` | Multi-Sheet Tabs Navigation, Formatted Grid Table, Zoom In/Out, Download, Print |
|
|
195
|
-
| **
|
|
196
|
-
| **
|
|
197
|
-
| **
|
|
198
|
-
| **
|
|
199
|
-
| **
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
|
244
|
-
|
|
245
|
-
| **
|
|
246
|
-
| **
|
|
247
|
-
| **
|
|
248
|
-
| **
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
|
|
264
|
-
/** Show
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
1
|
+
# @files-preview-app/preview-file
|
|
2
|
+
|
|
3
|
+
> **Universal, all-in-one client-side file preview package for React, Angular, Vue, and Vanilla JS.**
|
|
4
|
+
> Preview **PDF, Word (.docx), Excel (.xlsx), CSV, Images, Video, Audio, and Code/Text** with a built-in toolbar (zoom, rotate, thumbnails, page jump, download, print). 100% free, permissive open-source, and client-side (no cloud or server needed).
|
|
5
|
+
|
|
6
|
+
[](https://www.npmjs.com/package/@files-preview-app/preview-file)
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## 📦 Installation
|
|
12
|
+
|
|
13
|
+
Just install this **single package** in your project:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @files-preview-app/preview-file
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Or using Yarn / pnpm:
|
|
20
|
+
```bash
|
|
21
|
+
yarn add @files-preview-app/preview-file
|
|
22
|
+
# or
|
|
23
|
+
pnpm add @files-preview-app/preview-file
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Import the toolbar stylesheet in your main CSS or component:
|
|
27
|
+
```css
|
|
28
|
+
import '@files-preview-app/preview-file/styles.css';
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## 🚀 Quick Start by Framework
|
|
34
|
+
|
|
35
|
+
### 1. React (`@files-preview-app/preview-file/react`)
|
|
36
|
+
|
|
37
|
+
```tsx
|
|
38
|
+
import React, { useState } from 'react';
|
|
39
|
+
import { FilePreview } from '@files-preview-app/preview-file/react';
|
|
40
|
+
import '@files-preview-app/preview-file/styles.css';
|
|
41
|
+
|
|
42
|
+
export default function App() {
|
|
43
|
+
const [selectedFile, setSelectedFile] = useState<File | string>('https://example.com/sample.pdf');
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<div>
|
|
47
|
+
{/* File input for local files */}
|
|
48
|
+
<input
|
|
49
|
+
type="file"
|
|
50
|
+
onChange={(e) => e.target.files?.[0] && setSelectedFile(e.target.files[0])}
|
|
51
|
+
/>
|
|
52
|
+
|
|
53
|
+
{/* Preview container */}
|
|
54
|
+
<div style={{ width: '100%', height: '800px', marginTop: '16px' }}>
|
|
55
|
+
<FilePreview
|
|
56
|
+
src={selectedFile}
|
|
57
|
+
options={{
|
|
58
|
+
theme: 'light', // 'light' | 'dark' | 'auto'
|
|
59
|
+
showToolbar: true,
|
|
60
|
+
toolbarPosition: 'top' // 'top' | 'bottom'
|
|
61
|
+
}}
|
|
62
|
+
onLoaded={(info) => console.log('File loaded successfully:', info)}
|
|
63
|
+
onError={(error) => console.error('Preview error:', error)}
|
|
64
|
+
/>
|
|
65
|
+
</div>
|
|
66
|
+
</div>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
### 2. Angular (`@files-preview-app/preview-file/angular`)
|
|
74
|
+
|
|
75
|
+
In your standalone component or NgModule:
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
import { Component } from '@angular/core';
|
|
79
|
+
import { FilePreviewComponent } from '@files-preview-app/preview-file/angular';
|
|
80
|
+
|
|
81
|
+
@Component({
|
|
82
|
+
selector: 'app-root',
|
|
83
|
+
standalone: true,
|
|
84
|
+
imports: [FilePreviewComponent],
|
|
85
|
+
template: `
|
|
86
|
+
<div style="width: 100%; height: 800px;">
|
|
87
|
+
<input type="file" (change)="onFileSelected($event)" />
|
|
88
|
+
|
|
89
|
+
<fp-file-preview
|
|
90
|
+
[src]="fileSource"
|
|
91
|
+
[options]="{ theme: 'light', showToolbar: true }"
|
|
92
|
+
(loaded)="onLoaded($event)"
|
|
93
|
+
(error)="onError($event)"
|
|
94
|
+
/>
|
|
95
|
+
</div>
|
|
96
|
+
`,
|
|
97
|
+
styleUrls: ['@files-preview-app/preview-file/styles.css']
|
|
98
|
+
})
|
|
99
|
+
export class AppComponent {
|
|
100
|
+
fileSource: string | File = 'https://example.com/report.xlsx';
|
|
101
|
+
|
|
102
|
+
onFileSelected(event: Event) {
|
|
103
|
+
const input = event.target as HTMLInputElement;
|
|
104
|
+
if (input.files?.[0]) {
|
|
105
|
+
this.fileSource = input.files[0];
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
onLoaded(event: unknown) {
|
|
110
|
+
console.log('Preview ready', event);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
onError(err: Error) {
|
|
114
|
+
console.error('Preview failed', err);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
### 3. Vue 3 (`@files-preview-app/preview-file/vue`)
|
|
122
|
+
|
|
123
|
+
```vue
|
|
124
|
+
<template>
|
|
125
|
+
<div style="width: 100%; height: 800px;">
|
|
126
|
+
<input type="file" @change="onFileChange" />
|
|
127
|
+
|
|
128
|
+
<FilePreview
|
|
129
|
+
:src="currentFile"
|
|
130
|
+
:options="{ theme: 'dark', showToolbar: true }"
|
|
131
|
+
@loaded="handleLoaded"
|
|
132
|
+
@error="handleError"
|
|
133
|
+
/>
|
|
134
|
+
</div>
|
|
135
|
+
</template>
|
|
136
|
+
|
|
137
|
+
<script setup lang="ts">
|
|
138
|
+
import { ref } from 'vue';
|
|
139
|
+
import { FilePreview } from '@files-preview-app/preview-file/vue';
|
|
140
|
+
import '@files-preview-app/preview-file/styles.css';
|
|
141
|
+
|
|
142
|
+
const currentFile = ref<File | string>('/sample.docx');
|
|
143
|
+
|
|
144
|
+
function onFileChange(event: Event) {
|
|
145
|
+
const target = event.target as HTMLInputElement;
|
|
146
|
+
if (target.files?.[0]) {
|
|
147
|
+
currentFile.value = target.files[0];
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function handleLoaded(data: unknown) {
|
|
152
|
+
console.log('Loaded:', data);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function handleError(err: unknown) {
|
|
156
|
+
console.error('Error:', err);
|
|
157
|
+
}
|
|
158
|
+
</script>
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
### 4. Vanilla JavaScript / TypeScript (`@files-preview-app/preview-file`)
|
|
164
|
+
|
|
165
|
+
```html
|
|
166
|
+
<link rel="stylesheet" href="node_modules/@files-preview-app/preview-file/dist/styles.css" />
|
|
167
|
+
|
|
168
|
+
<div id="viewer-container" style="width: 100%; height: 800px;"></div>
|
|
169
|
+
|
|
170
|
+
<script type="module">
|
|
171
|
+
import { FilePreviewViewer } from '@files-preview-app/preview-file';
|
|
172
|
+
|
|
173
|
+
const container = document.getElementById('viewer-container');
|
|
174
|
+
const viewer = new FilePreviewViewer();
|
|
175
|
+
|
|
176
|
+
// Preview from URL, File, Blob, or ArrayBuffer
|
|
177
|
+
await viewer.preview(container, 'https://example.com/invoice.pdf', {
|
|
178
|
+
theme: 'light',
|
|
179
|
+
showToolbar: true
|
|
180
|
+
});
|
|
181
|
+
</script>
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## 📂 Supported Extensions & Built-in Controls
|
|
187
|
+
|
|
188
|
+
The viewer automatically recognizes the file extension and magic binary bytes, activating the corresponding renderer and controls:
|
|
189
|
+
|
|
190
|
+
| File Format | Extensions | Controls Available |
|
|
191
|
+
|---|---|---|
|
|
192
|
+
| **PDF** | `.pdf` | Zoom In/Out, Fit to Page, Rotate CW/CCW, Page Navigation Jump, Thumbnails Sidebar, Download, Print |
|
|
193
|
+
| **Word Document** | `.docx` | Full layout rendering, Zoom In/Out, Fit to Page, Download, Print |
|
|
194
|
+
| **Excel Spreadsheet** | `.xlsx`, `.xls` | Multi-Sheet Tabs Navigation, Formatted Grid Table, Zoom In/Out, Download, Print |
|
|
195
|
+
| **PowerPoint** | `.pptx`, `.ppsx` | Slide-by-Slide Navigation, Slide Thumbnails Sidebar, Zoom In/Out, Fit to Slide, Download, Print |
|
|
196
|
+
| **CSV / TSV Data** | `.csv`, `.tsv` | Tabular Grid with Header Styling, Comma/Tab auto-detection, Zoom In/Out, Download, Print |
|
|
197
|
+
| **ZIP Archives** | `.zip` | File Tree & Table Explorer, Compression Stats, Search Filter, Individual File Download, Download Zip |
|
|
198
|
+
| **Rich Markdown** | `.md`, `.markdown` | Rendered GitHub Markdown (Tables, Checklists, Blockquotes), Syntax Highlighted Code, Font Zoom, Download, Print |
|
|
199
|
+
| **3D Models** | `.stl`, `.obj` | 360° Orbit Mouse Controls, Perspective Camera, Lighting, Wireframe Toggle, Zoom, Reset View, Download |
|
|
200
|
+
| **Images** | `.png`, `.jpg`, `.jpeg`, `.gif`, `.webp`, `.bmp`, `.svg`, `.ico`, `.tiff` | Pan & Zoom, Reset / Fit, Rotate 90°, Download, Print |
|
|
201
|
+
| **Video** | `.mp4`, `.webm`, `.ogg`, `.mov` | Play / Pause, Rotate, Fullscreen, Download |
|
|
202
|
+
| **Audio** | `.mp3`, `.wav`, `.ogg`, `.flac`, `.aac` | Play / Pause, Volume, Seek, Download |
|
|
203
|
+
| **Code & Text** | `.js`, `.ts`, `.jsx`, `.tsx`, `.html`, `.css`, `.json`, `.xml`, `.yaml`, `.py`, `.java`, `.cpp`, `.sql`, `.md`, `.txt`, `.sh`, etc. (190+ languages) | Syntax Highlighting via highlight.js, Font Scaling Zoom In/Out, Download, Print |
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## 📥 How to Pass Values (`src` prop)
|
|
208
|
+
|
|
209
|
+
You can pass the file source in **any** of the following formats:
|
|
210
|
+
|
|
211
|
+
### 1. From HTML `<input type="file">` (File object)
|
|
212
|
+
```tsx
|
|
213
|
+
const file = event.target.files[0];
|
|
214
|
+
<FilePreview src={file} />
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### 2. URL String (Public URL or CDN)
|
|
218
|
+
```tsx
|
|
219
|
+
<FilePreview src="https://example.com/documents/contract.pdf" />
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### 3. Blob Object
|
|
223
|
+
```tsx
|
|
224
|
+
const blob = new Blob([data], { type: 'application/pdf' });
|
|
225
|
+
<FilePreview src={blob} />
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### 4. ArrayBuffer or Uint8Array
|
|
229
|
+
```tsx
|
|
230
|
+
const buffer = await response.arrayBuffer();
|
|
231
|
+
<FilePreview src={buffer} />
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### 5. Base64 Data URI
|
|
235
|
+
```tsx
|
|
236
|
+
<FilePreview src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..." />
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
## 🎛️ Toolbar Features Matrix
|
|
242
|
+
|
|
243
|
+
| Control | How it Works |
|
|
244
|
+
|---|---|
|
|
245
|
+
| **Thumbnails** | Toggles a collapsible sidebar showing miniature rendered previews of each page/sheet. |
|
|
246
|
+
| **Zoom In / Zoom Out** | Dynamically scales document, canvas, or font size without pixelation. |
|
|
247
|
+
| **Fit to Page** | Automatically fits the preview perfectly within your container dimensions. |
|
|
248
|
+
| **Page Jump** | Numeric input field allowing users to type a page or sheet number and jump instantly. |
|
|
249
|
+
| **Rotate** | Rotates documents, images, and videos 90 degrees clockwise or counterclockwise. |
|
|
250
|
+
| **Play / Pause** | Controls video and audio playback directly from the unified toolbar. |
|
|
251
|
+
| **Download** | Downloads the original file to the user's disk with proper filename and MIME type. |
|
|
252
|
+
| **Print** | Opens the browser print dialog formatted specifically for clean printing. |
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
## 🎨 Viewer Options
|
|
257
|
+
|
|
258
|
+
Pass configuration via the `options` object:
|
|
259
|
+
|
|
260
|
+
```typescript
|
|
261
|
+
interface PreviewViewerOptions {
|
|
262
|
+
/** Color theme: 'light' | 'dark' | 'auto' (default: 'light') */
|
|
263
|
+
theme?: 'light' | 'dark' | 'auto';
|
|
264
|
+
/** Show top toolbar (default: true) */
|
|
265
|
+
showToolbar?: boolean;
|
|
266
|
+
/** Toolbar placement: 'top' | 'bottom' (default: 'top') */
|
|
267
|
+
toolbarPosition?: 'top' | 'bottom';
|
|
268
|
+
/** Show thumbnails panel on initial load (default: false) */
|
|
269
|
+
showThumbnails?: boolean;
|
|
270
|
+
/** Custom wrapper CSS class name */
|
|
271
|
+
className?: string;
|
|
272
|
+
/** Initial zoom multiplier (1.0 = 100%) */
|
|
273
|
+
zoom?: number;
|
|
274
|
+
}
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
---
|
|
278
|
+
|
|
279
|
+
## 🛡️ Security & Licensing
|
|
280
|
+
|
|
281
|
+
- **100% Client-Side**: No document or file data is ever sent to any remote server or third-party cloud.
|
|
282
|
+
- **XSS Protection**: HTML and SVG previews are sanitized with `DOMPurify`.
|
|
283
|
+
- **Strictly Permissive Licenses**: Every dependency used is audited and verified under **MIT**, **Apache-2.0**, or **BSD-3-Clause**. No GPL, AGPL, commercial paywalls, or restrictive terms.
|
|
284
|
+
|
|
285
|
+
See [THIRD_PARTY_LICENSES.md](THIRD_PARTY_LICENSES.md) for full licensing details.
|
|
286
|
+
|
|
287
|
+
---
|
|
288
|
+
|
|
289
|
+
## 👨💻 Author
|
|
290
|
+
|
|
291
|
+
**Sumit Patel**
|
|
292
|
+
- GitHub: [@patelsumit5192](https://github.com/patelsumit5192)
|
|
293
|
+
- npm: [patel.sumit51](https://www.npmjs.com/~patel.sumit51)
|
|
294
|
+
- Repository: [https://github.com/patelsumit5192/preview-file](https://github.com/patelsumit5192/preview-file)
|
|
295
|
+
|
|
296
|
+
---
|
|
297
|
+
|
|
298
|
+
## 📄 License
|
|
299
|
+
|
|
296
300
|
MIT © 2026 Sumit Patel
|
package/THIRD_PARTY_LICENSES.md
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
# Third-Party Licenses
|
|
2
2
|
|
|
3
|
-
This project uses the following open-source libraries. All dependencies use permissive licenses (MIT, Apache-2.0, or BSD) that allow free commercial and personal use.
|
|
3
|
+
This project uses the following open-source libraries. All dependencies use strictly permissive licenses (MIT, Apache-2.0, or BSD) that allow free commercial and personal use with zero copyright claims or restrictions.
|
|
4
4
|
|
|
5
5
|
| Package | Version | License | Author/Org | URL |
|
|
6
6
|
|---|---|---|---|---|
|
|
7
7
|
| pdfjs-dist | ^4.x | Apache-2.0 | Mozilla | https://github.com/nicolo-ribaudo/pdfjs-dist |
|
|
8
8
|
| docx-preview | ^0.3.x | Apache-2.0 | Volodymyr Baydalka | https://github.com/VolodymyrBaydalka/docxjs |
|
|
9
9
|
| exceljs | ^4.x | MIT | Guyon Roche | https://github.com/exceljs/exceljs |
|
|
10
|
+
| pptx-browser | ^4.x | MIT | Christophervr | https://github.com/christophervr/pptx-browser |
|
|
10
11
|
| papaparse | ^5.x | MIT | Matt Holt | https://github.com/mholt/PapaParse |
|
|
11
|
-
|
|
|
12
|
+
| fflate | ^0.8.x | MIT | Arjun Barrett | https://github.com/101arrowz/fflate |
|
|
13
|
+
| marked | ^18.x | MIT | Christopher Jeffrey | https://github.com/markedjs/marked |
|
|
14
|
+
| three | ^0.186.x | MIT | Ricardo Cabello (Mr.doob) | https://github.com/mrdoob/three.js |
|
|
15
|
+
| highlight.js | ^11.x | BSD-3-Clause | Ivan Sagalaev | https://github.com/highlightjs/highlight.js |
|
|
12
16
|
| @panzoom/panzoom | ^4.x | MIT | Timmy Willison | https://github.com/timmywil/panzoom |
|
|
13
17
|
| dompurify | ^3.x | Apache-2.0 | Cure53 | https://github.com/cure53/DOMPurify |
|
|
14
18
|
|
|
15
|
-
All licenses are included in their respective `node_modules/<package>/LICENSE` files.
|
|
19
|
+
All licenses are included in their respective `node_modules/<package>/LICENSE` files.
|