@files-preview-app/preview-file 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +296 -0
- package/THIRD_PARTY_LICENSES.md +15 -0
- package/dist/angular.cjs +1908 -0
- package/dist/angular.cjs.map +1 -0
- package/dist/angular.d.cts +25 -0
- package/dist/angular.d.ts +25 -0
- package/dist/angular.js +1879 -0
- package/dist/angular.js.map +1 -0
- package/dist/index.cjs +1851 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +25 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +1801 -0
- package/dist/index.js.map +1 -0
- package/dist/react.cjs +1837 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +40 -0
- package/dist/react.d.ts +40 -0
- package/dist/react.js +1807 -0
- package/dist/react.js.map +1 -0
- package/dist/styles.css +190 -0
- package/dist/vue.cjs +1832 -0
- package/dist/vue.cjs.map +1 -0
- package/dist/vue.d.cts +44 -0
- package/dist/vue.d.ts +44 -0
- package/dist/vue.js +1802 -0
- package/dist/vue.js.map +1 -0
- package/package.json +114 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sumit and @file-preview contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
# @patel.sumit51/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/@patel.sumit51/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 @patel.sumit51/preview-file
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Or using Yarn / pnpm:
|
|
20
|
+
```bash
|
|
21
|
+
yarn add @patel.sumit51/preview-file
|
|
22
|
+
# or
|
|
23
|
+
pnpm add @patel.sumit51/preview-file
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Import the toolbar stylesheet in your main CSS or component:
|
|
27
|
+
```css
|
|
28
|
+
import '@patel.sumit51/preview-file/styles.css';
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## 🚀 Quick Start by Framework
|
|
34
|
+
|
|
35
|
+
### 1. React (`@patel.sumit51/preview-file/react`)
|
|
36
|
+
|
|
37
|
+
```tsx
|
|
38
|
+
import React, { useState } from 'react';
|
|
39
|
+
import { FilePreview } from '@patel.sumit51/preview-file/react';
|
|
40
|
+
import '@patel.sumit51/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 (`@patel.sumit51/preview-file/angular`)
|
|
74
|
+
|
|
75
|
+
In your standalone component or NgModule:
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
import { Component } from '@angular/core';
|
|
79
|
+
import { FilePreviewComponent } from '@patel.sumit51/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: ['@patel.sumit51/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 (`@patel.sumit51/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 '@patel.sumit51/preview-file/vue';
|
|
140
|
+
import '@patel.sumit51/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 (`@patel.sumit51/preview-file`)
|
|
164
|
+
|
|
165
|
+
```html
|
|
166
|
+
<link rel="stylesheet" href="node_modules/@patel.sumit51/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 '@patel.sumit51/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
|
+
| **CSV / TSV Data** | `.csv`, `.tsv` | Tabular Grid with Header Styling, Comma/Tab auto-detection, Zoom In/Out, Download, Print |
|
|
196
|
+
| **Images** | `.png`, `.jpg`, `.jpeg`, `.gif`, `.webp`, `.bmp`, `.svg`, `.ico`, `.tiff` | Pan & Zoom, Reset / Fit, Rotate 90°, Download, Print |
|
|
197
|
+
| **Video** | `.mp4`, `.webm`, `.ogg`, `.mov` | Play / Pause, Rotate, Fullscreen, Download |
|
|
198
|
+
| **Audio** | `.mp3`, `.wav`, `.ogg`, `.flac`, `.aac` | Play / Pause, Volume, Seek, Download |
|
|
199
|
+
| **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 |
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
## 📥 How to Pass Values (`src` prop)
|
|
204
|
+
|
|
205
|
+
You can pass the file source in **any** of the following formats:
|
|
206
|
+
|
|
207
|
+
### 1. From HTML `<input type="file">` (File object)
|
|
208
|
+
```tsx
|
|
209
|
+
const file = event.target.files[0];
|
|
210
|
+
<FilePreview src={file} />
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### 2. URL String (Public URL or CDN)
|
|
214
|
+
```tsx
|
|
215
|
+
<FilePreview src="https://example.com/documents/contract.pdf" />
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### 3. Blob Object
|
|
219
|
+
```tsx
|
|
220
|
+
const blob = new Blob([data], { type: 'application/pdf' });
|
|
221
|
+
<FilePreview src={blob} />
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### 4. ArrayBuffer or Uint8Array
|
|
225
|
+
```tsx
|
|
226
|
+
const buffer = await response.arrayBuffer();
|
|
227
|
+
<FilePreview src={buffer} />
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### 5. Base64 Data URI
|
|
231
|
+
```tsx
|
|
232
|
+
<FilePreview src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..." />
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## 🎛️ Toolbar Features Matrix
|
|
238
|
+
|
|
239
|
+
| Control | How it Works |
|
|
240
|
+
|---|---|
|
|
241
|
+
| **Thumbnails** | Toggles a collapsible sidebar showing miniature rendered previews of each page/sheet. |
|
|
242
|
+
| **Zoom In / Zoom Out** | Dynamically scales document, canvas, or font size without pixelation. |
|
|
243
|
+
| **Fit to Page** | Automatically fits the preview perfectly within your container dimensions. |
|
|
244
|
+
| **Page Jump** | Numeric input field allowing users to type a page or sheet number and jump instantly. |
|
|
245
|
+
| **Rotate** | Rotates documents, images, and videos 90 degrees clockwise or counterclockwise. |
|
|
246
|
+
| **Play / Pause** | Controls video and audio playback directly from the unified toolbar. |
|
|
247
|
+
| **Download** | Downloads the original file to the user's disk with proper filename and MIME type. |
|
|
248
|
+
| **Print** | Opens the browser print dialog formatted specifically for clean printing. |
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## 🎨 Viewer Options
|
|
253
|
+
|
|
254
|
+
Pass configuration via the `options` object:
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
interface PreviewViewerOptions {
|
|
258
|
+
/** Color theme: 'light' | 'dark' | 'auto' (default: 'light') */
|
|
259
|
+
theme?: 'light' | 'dark' | 'auto';
|
|
260
|
+
/** Show top toolbar (default: true) */
|
|
261
|
+
showToolbar?: boolean;
|
|
262
|
+
/** Toolbar placement: 'top' | 'bottom' (default: 'top') */
|
|
263
|
+
toolbarPosition?: 'top' | 'bottom';
|
|
264
|
+
/** Show thumbnails panel on initial load (default: false) */
|
|
265
|
+
showThumbnails?: boolean;
|
|
266
|
+
/** Custom wrapper CSS class name */
|
|
267
|
+
className?: string;
|
|
268
|
+
/** Initial zoom multiplier (1.0 = 100%) */
|
|
269
|
+
zoom?: number;
|
|
270
|
+
}
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
## 🛡️ Security & Licensing
|
|
276
|
+
|
|
277
|
+
- **100% Client-Side**: No document or file data is ever sent to any remote server or third-party cloud.
|
|
278
|
+
- **XSS Protection**: HTML and SVG previews are sanitized with `DOMPurify`.
|
|
279
|
+
- **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.
|
|
280
|
+
|
|
281
|
+
See [THIRD_PARTY_LICENSES.md](THIRD_PARTY_LICENSES.md) for full licensing details.
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
## 👨💻 Author
|
|
286
|
+
|
|
287
|
+
**Sumit Patel**
|
|
288
|
+
- GitHub: [@patelsumit5192](https://github.com/patelsumit5192)
|
|
289
|
+
- npm: [patel.sumit51](https://www.npmjs.com/~patel.sumit51)
|
|
290
|
+
- Repository: [https://github.com/patelsumit5192/preview-file](https://github.com/patelsumit5192/preview-file)
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
## 📄 License
|
|
295
|
+
|
|
296
|
+
MIT © 2026 Sumit Patel
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Third-Party Licenses
|
|
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.
|
|
4
|
+
|
|
5
|
+
| Package | Version | License | Author/Org | URL |
|
|
6
|
+
|---|---|---|---|---|
|
|
7
|
+
| pdfjs-dist | ^4.x | Apache-2.0 | Mozilla | https://github.com/nicolo-ribaudo/pdfjs-dist |
|
|
8
|
+
| docx-preview | ^0.3.x | Apache-2.0 | Volodymyr Baydalka | https://github.com/VolodymyrBaydalka/docxjs |
|
|
9
|
+
| exceljs | ^4.x | MIT | Guyon Roche | https://github.com/exceljs/exceljs |
|
|
10
|
+
| papaparse | ^5.x | MIT | Matt Holt | https://github.com/mholt/PapaParse |
|
|
11
|
+
| highlight.js | ^11.x | BSD-3-Clause | Ivan Googol | https://github.com/highlightjs/highlight.js |
|
|
12
|
+
| @panzoom/panzoom | ^4.x | MIT | Timmy Willison | https://github.com/timmywil/panzoom |
|
|
13
|
+
| dompurify | ^3.x | Apache-2.0 | Cure53 | https://github.com/cure53/DOMPurify |
|
|
14
|
+
|
|
15
|
+
All licenses are included in their respective `node_modules/<package>/LICENSE` files.
|