@privado-inc/file-viewer-vite-plugin 3.1.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/LICENSE ADDED
@@ -0,0 +1,160 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and
10
+ distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright
13
+ owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other entities
16
+ that control, are controlled by, or are under common control with that entity.
17
+ For the purposes of this definition, "control" means (i) the power, direct or
18
+ indirect, to cause the direction or management of such entity, whether by
19
+ contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
20
+ outstanding shares, or (iii) beneficial ownership of such entity.
21
+
22
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
23
+ permissions granted by this License.
24
+
25
+ "Source" form shall mean the preferred form for making modifications, including
26
+ but not limited to software source code, documentation source, and configuration
27
+ files.
28
+
29
+ "Object" form shall mean any form resulting from mechanical transformation or
30
+ translation of a Source form, including but not limited to compiled object code,
31
+ generated documentation, and conversions to other media types.
32
+
33
+ "Work" shall mean the work of authorship, whether in Source or Object form,
34
+ made available under the License, as indicated by a copyright notice that is
35
+ included in or attached to the work.
36
+
37
+ "Derivative Works" shall mean any work, whether in Source or Object form, that
38
+ is based on (or derived from) the Work and for which the editorial revisions,
39
+ annotations, elaborations, or other modifications represent, as a whole, an
40
+ original work of authorship. For the purposes of this License, Derivative Works
41
+ shall not include works that remain separable from, or merely link (or bind by
42
+ name) to the interfaces of, the Work and Derivative Works thereof.
43
+
44
+ "Contribution" shall mean any work of authorship, including the original version
45
+ of the Work and any modifications or additions to that Work or Derivative Works
46
+ thereof, that is intentionally submitted to Licensor for inclusion in the Work by
47
+ the copyright owner or by an individual or Legal Entity authorized to submit on
48
+ behalf of the copyright owner. For the purposes of this definition, "submitted"
49
+ means any form of electronic, verbal, or written communication sent to the
50
+ Licensor or its representatives, including but not limited to communication on
51
+ electronic mailing lists, source code control systems, and issue tracking systems
52
+ that are managed by, or on behalf of, the Licensor for the purpose of discussing
53
+ and improving the Work, but excluding communication that is conspicuously marked
54
+ or otherwise designated in writing by the copyright owner as "Not a
55
+ Contribution."
56
+
57
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
58
+ of whom a Contribution has been received by Licensor and subsequently
59
+ incorporated within the Work.
60
+
61
+ 2. Grant of Copyright License. Subject to the terms and conditions of this
62
+ License, each Contributor hereby grants to You a perpetual, worldwide,
63
+ non-exclusive, no-charge, royalty-free, irrevocable copyright license to
64
+ reproduce, prepare Derivative Works of, publicly display, publicly perform,
65
+ sublicense, and distribute the Work and such Derivative Works in Source or
66
+ Object form.
67
+
68
+ 3. Grant of Patent License. Subject to the terms and conditions of this License,
69
+ each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
70
+ no-charge, royalty-free, irrevocable (except as stated in this section) patent
71
+ license to make, have made, use, offer to sell, sell, import, and otherwise
72
+ transfer the Work, where such license applies only to those patent claims
73
+ licensable by such Contributor that are necessarily infringed by their
74
+ Contribution(s) alone or by combination of their Contribution(s) with the Work to
75
+ which such Contribution(s) was submitted. If You institute patent litigation
76
+ against any entity (including a cross-claim or counterclaim in a lawsuit)
77
+ alleging that the Work or a Contribution incorporated within the Work
78
+ constitutes direct or contributory patent infringement, then any patent licenses
79
+ granted to You under this License for that Work shall terminate as of the date
80
+ such litigation is filed.
81
+
82
+ 4. Redistribution. You may reproduce and distribute copies of the Work or
83
+ Derivative Works thereof in any medium, with or without modifications, and in
84
+ Source or Object form, provided that You meet the following conditions:
85
+
86
+ (a) You must give any other recipients of the Work or Derivative Works a copy of
87
+ this License; and
88
+
89
+ (b) You must cause any modified files to carry prominent notices stating that
90
+ You changed the files; and
91
+
92
+ (c) You must retain, in the Source form of any Derivative Works that You
93
+ distribute, all copyright, patent, trademark, and attribution notices from the
94
+ Source form of the Work, excluding those notices that do not pertain to any part
95
+ of the Derivative Works; and
96
+
97
+ (d) If the Work includes a "NOTICE" text file as part of its distribution, then
98
+ any Derivative Works that You distribute must include a readable copy of the
99
+ attribution notices contained within such NOTICE file, excluding those notices
100
+ that do not pertain to any part of the Derivative Works, in at least one of the
101
+ following places: within a NOTICE text file distributed as part of the Derivative
102
+ Works; within the Source form or documentation, if provided along with the
103
+ Derivative Works; or, within a display generated by the Derivative Works, if and
104
+ wherever such third-party notices normally appear. The contents of the NOTICE
105
+ file are for informational purposes only and do not modify the License. You may
106
+ add Your own attribution notices within Derivative Works that You distribute,
107
+ alongside or as an addendum to the NOTICE text from the Work, provided that such
108
+ additional attribution notices cannot be construed as modifying the License.
109
+
110
+ You may add Your own copyright statement to Your modifications and may provide
111
+ additional or different license terms and conditions for use, reproduction, or
112
+ distribution of Your modifications, or for any such Derivative Works as a whole,
113
+ provided Your use, reproduction, and distribution of the Work otherwise complies
114
+ with the conditions stated in this License.
115
+
116
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any
117
+ Contribution intentionally submitted for inclusion in the Work by You to the
118
+ Licensor shall be under the terms and conditions of this License, without any
119
+ additional terms or conditions. Notwithstanding the above, nothing herein shall
120
+ supersede or modify the terms of any separate license agreement you may have
121
+ executed with Licensor regarding such Contributions.
122
+
123
+ 6. Trademarks. This License does not grant permission to use the trade names,
124
+ trademarks, service marks, or product names of the Licensor, except as required
125
+ for reasonable and customary use in describing the origin of the Work and
126
+ reproducing the content of the NOTICE file.
127
+
128
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
129
+ writing, Licensor provides the Work (and each Contributor provides its
130
+ Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
131
+ KIND, either express or implied, including, without limitation, any warranties or
132
+ conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
133
+ PARTICULAR PURPOSE. You are solely responsible for determining the
134
+ appropriateness of using or redistributing the Work and assume any risks
135
+ associated with Your exercise of permissions under this License.
136
+
137
+ 8. Limitation of Liability. In no event and under no legal theory, whether in
138
+ tort (including negligence), contract, or otherwise, unless required by
139
+ applicable law (such as deliberate and grossly negligent acts) or agreed to in
140
+ writing, shall any Contributor be liable to You for damages, including any
141
+ direct, indirect, special, incidental, or consequential damages of any character
142
+ arising as a result of this License or out of the use or inability to use the
143
+ Work (including but not limited to damages for loss of goodwill, work stoppage,
144
+ computer failure or malfunction, or any and all other commercial damages or
145
+ losses), even if such Contributor has been advised of the possibility of such
146
+ damages.
147
+
148
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or
149
+ Derivative Works thereof, You may choose to offer, and charge a fee for,
150
+ acceptance of support, warranty, indemnity, or other liability obligations and/or
151
+ rights consistent with this License. However, in accepting such obligations, You
152
+ may act only on Your own behalf and on Your sole responsibility, not on behalf of
153
+ any other Contributor, and only if You agree to indemnify, defend, and hold each
154
+ Contributor harmless for any liability incurred by, or claims asserted against,
155
+ such Contributor by reason of your accepting any such warranty or additional
156
+ liability.
157
+
158
+ END OF TERMS AND CONDITIONS
159
+
160
+ Copyright 2026 Flyfish Viewer
package/NOTICE ADDED
@@ -0,0 +1,13 @@
1
+ @privado-inc/file-viewer-vite-plugin
2
+ Copyright 2026 Privado
3
+
4
+ This package is built from flyfish-dev/file-viewer v3.1.2
5
+ (https://github.com/flyfish-dev/file-viewer), packages/presets/vite-plugin
6
+ (@file-viewer/vite-plugin), Copyright 2026 Flyfish Viewer, licensed under the
7
+ Apache License, Version 2.0 (see LICENSE).
8
+
9
+ Privado republished it under its own package name only. The upstream source is
10
+ unmodified.
11
+
12
+ This package does not include or depend on the proprietary @file-viewer/ppt
13
+ runtime. If that runtime is absent, the plugin skips its assets.
package/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # @privado-inc/file-viewer-vite-plugin
2
+
3
+ Vite plugin for `@privado-inc/file-viewer`. It copies the runtime assets
4
+ (PDF.js worker and wasm, PPTX and spreadsheet workers) into the app build.
5
+
6
+ Built from [flyfish-dev/file-viewer](https://github.com/flyfish-dev/file-viewer)
7
+ v3.1.2 `@file-viewer/vite-plugin`. Upstream source is unmodified; this package
8
+ compiles `packages/presets/vite-plugin/src` under a Privado package name.
9
+
10
+ ## Usage
11
+
12
+ ```bash
13
+ npm i @privado-inc/file-viewer
14
+ npm i -D @privado-inc/file-viewer-vite-plugin
15
+ ```
16
+
17
+ ```ts
18
+ // vite.config.ts
19
+ import { defineConfig } from "vite";
20
+ import fileViewer from "@privado-inc/file-viewer-vite-plugin";
21
+
22
+ export default defineConfig({
23
+ plugins: [fileViewer({ copyAssets: true })],
24
+ });
25
+ ```
26
+
27
+ For the `virtual:file-viewer-renderers` module types, add
28
+ `"@privado-inc/file-viewer-vite-plugin/client"` to `compilerOptions.types`.
29
+
30
+ ## Building from source
31
+
32
+ ```bash
33
+ pnpm install --filter "@privado-inc/file-viewer-vite-plugin..."
34
+ pnpm --filter @privado-inc/file-viewer-vite-plugin build
35
+ ```
package/client.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ declare module 'virtual:file-viewer-renderers' {
2
+ import type {
3
+ FileRenderHandler,
4
+ FileViewerRenderedInstance,
5
+ FileViewerRendererPluginInput,
6
+ } from '@file-viewer/core';
7
+
8
+ type BrowserRendererHandler = FileRenderHandler<FileViewerRenderedInstance, HTMLDivElement>;
9
+
10
+ export interface ConfiguredFileViewerRendererPlan {
11
+ preset: string | null;
12
+ autoPresets: string[];
13
+ formats: string[];
14
+ rendererIds: string[];
15
+ packages: string[];
16
+ generatedBy: '@file-viewer/vite-plugin';
17
+ }
18
+
19
+ export const configuredFileViewerRenderers: FileViewerRendererPluginInput<BrowserRendererHandler>;
20
+ export const fileViewerRendererPlan: ConfiguredFileViewerRendererPlan;
21
+ export default configuredFileViewerRenderers;
22
+ }
@@ -0,0 +1,151 @@
1
+ import type { Plugin } from 'vite';
2
+ export type FileViewerVitePreset = 'all' | 'lite' | 'standard' | 'office' | 'engineering';
3
+ export type FileViewerVitePresetMode = FileViewerVitePreset | 'auto';
4
+ export type FileViewerMissingRendererMode = 'error' | 'warn' | 'ignore';
5
+ export type FileViewerChunkStrategy = 'renderer' | 'none';
6
+ export interface FileViewerRendererScanOptions {
7
+ /**
8
+ * Disable a shared scan object without branching user config.
9
+ */
10
+ enabled?: boolean;
11
+ /**
12
+ * Source roots, relative to Vite root, that should be inspected for format hints.
13
+ * Defaults to common application source folders.
14
+ */
15
+ roots?: readonly string[];
16
+ /**
17
+ * Text-like source extensions to inspect. Values may include or omit the dot.
18
+ */
19
+ extensions?: readonly string[];
20
+ /**
21
+ * Large generated files are ignored by default to keep config/startup fast.
22
+ */
23
+ maxFileSize?: number;
24
+ }
25
+ export interface FileViewerCopyAssetsOptions {
26
+ /**
27
+ * Directory used by Vite dev. Defaults to config.publicDir.
28
+ */
29
+ publicDir?: string;
30
+ /**
31
+ * Directory used after production build. Defaults to build.outDir.
32
+ */
33
+ outDir?: string;
34
+ /**
35
+ * Directory below publicDir/outDir where assets are published. When omitted,
36
+ * projects with an installed @file-viewer/*-full package use `file-viewer`;
37
+ * other projects keep the existing output-root layout. Use an empty string
38
+ * to explicitly publish at the output root. The injected runtime module
39
+ * keeps every renderer's default asset base aligned with this directory.
40
+ */
41
+ baseDir?: string;
42
+ /**
43
+ * Copy during dev server startup, build closeBundle, or both.
44
+ */
45
+ mode?: 'dev' | 'build' | 'both';
46
+ }
47
+ export interface FileViewerRenderersPluginOptions {
48
+ /**
49
+ * File extensions or renderer ids. Examples: pdf, .dwg, typst, zip, xmind.
50
+ */
51
+ formats?: readonly string[];
52
+ /**
53
+ * Explicit renderer ids. Useful when several extensions share one renderer.
54
+ */
55
+ renderers?: readonly string[];
56
+ /**
57
+ * Presets import their dedicated @file-viewer/preset-* package. Use `auto`
58
+ * to discover installed preset packages, and add `formats` / `renderers`
59
+ * when you need to extend a preset with extra lines.
60
+ */
61
+ preset?: FileViewerVitePresetMode;
62
+ /**
63
+ * Auto-discovers installed `@file-viewer/preset-*` packages and registers
64
+ * them globally for framework components. Defaults to true only when no
65
+ * explicit preset/formats/renderers are configured, or when `preset: 'auto'`.
66
+ */
67
+ autoPresets?: boolean | readonly FileViewerVitePreset[];
68
+ /**
69
+ * Injects the virtual renderer module into Vite HTML entrypoints so
70
+ * framework components can consume auto-registered renderers without
71
+ * application code importing `virtual:file-viewer-renderers`.
72
+ */
73
+ inject?: boolean;
74
+ /**
75
+ * Virtual module id consumed by application code.
76
+ */
77
+ moduleId?: string;
78
+ /**
79
+ * Controls how planned-but-not-yet-extracted renderer lines are reported.
80
+ */
81
+ missingRenderer?: FileViewerMissingRendererMode;
82
+ /**
83
+ * Adds renderer-oriented manualChunks when the user did not define one.
84
+ */
85
+ chunkStrategy?: FileViewerChunkStrategy;
86
+ /**
87
+ * Wraps existing manualChunks functions with known circular-dependency-safe
88
+ * vendor groups. This keeps CodeMirror/Lezer/Sandpack in one chunk when host
89
+ * apps split node_modules by package name, avoiding production TDZ errors.
90
+ */
91
+ stabilizeInteropChunks?: boolean;
92
+ /**
93
+ * Copies known worker/WASM/vendor assets for selected renderer lines.
94
+ */
95
+ copyAssets?: boolean | FileViewerCopyAssetsOptions;
96
+ /**
97
+ * Opt-in source scan. The plugin reads lightweight hints such as
98
+ * `fileViewerFormats = ['pdf', 'docx']`, `data-file-viewer-formats="pdf,docx"`,
99
+ * and upload `accept=".pdf,.docx"` declarations, then merges them with
100
+ * `formats` / `renderers` before generating the virtual module.
101
+ */
102
+ scan?: boolean | FileViewerRendererScanOptions;
103
+ }
104
+ interface MissingRendererNotice {
105
+ format: string;
106
+ targetPackage?: string;
107
+ note: string;
108
+ }
109
+ export declare function extractFileViewerRendererHintTokens(source: string): string[];
110
+ export declare function collectFileViewerRendererScanTokens(projectRoot: string, scan: FileViewerRenderersPluginOptions['scan']): string[];
111
+ export interface FileViewerCopyAssetsTargetConfig {
112
+ /** Vite project root. Defaults to process.cwd(). */
113
+ projectRoot?: string;
114
+ /** Resolved Vite publicDir. Defaults to `public`. */
115
+ publicDir?: string;
116
+ /** Resolved Vite build.outDir. Defaults to `dist`. */
117
+ outDir?: string;
118
+ }
119
+ export interface FileViewerCopyAssetsTarget {
120
+ mode: 'dev' | 'build';
121
+ outputRoot: string;
122
+ targetRoot: string;
123
+ baseDir: string;
124
+ installedFullPackages: string[];
125
+ installedAssetPackages: string[];
126
+ }
127
+ /**
128
+ * Resolves the exact directory used by copyAssets without running a Vite build.
129
+ * This is exported so integrations can validate their deployment contract.
130
+ */
131
+ export declare function resolveFileViewerCopyAssetsTarget(mode: 'dev' | 'build', value?: true | FileViewerCopyAssetsOptions, config?: FileViewerCopyAssetsTargetConfig): FileViewerCopyAssetsTarget;
132
+ export declare function fileViewerRenderers(options?: FileViewerRenderersPluginOptions): Plugin;
133
+ export declare function createFileViewerManualChunks(options?: FileViewerRenderersPluginOptions): (id: string) => string | undefined;
134
+ export declare function resolveFileViewerRendererSelection(options?: FileViewerRenderersPluginOptions, projectRoot?: string): {
135
+ preset: FileViewerVitePreset | null;
136
+ presetPackage: string | null;
137
+ autoPresets: FileViewerVitePreset[];
138
+ autoPresetPackages: string[];
139
+ formats: string[];
140
+ packages: string[];
141
+ rendererIds: string[];
142
+ renderers: {
143
+ id: string;
144
+ packageName: string;
145
+ formats: string[];
146
+ rendererIds: string[];
147
+ chunkName: string;
148
+ }[];
149
+ missing: MissingRendererNotice[];
150
+ };
151
+ export default fileViewerRenderers;