@file-viewer/core 2.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 +160 -0
- package/README.en.md +78 -0
- package/README.md +83 -0
- package/dist/assets.d.ts +62 -0
- package/dist/assets.js +260 -0
- package/dist/browser.d.ts +1 -0
- package/dist/browser.js +1 -0
- package/dist/capabilities.d.ts +24 -0
- package/dist/capabilities.js +95 -0
- package/dist/document.d.ts +9 -0
- package/dist/document.js +86 -0
- package/dist/documentDom/anchors.d.ts +7 -0
- package/dist/documentDom/anchors.js +196 -0
- package/dist/documentDom/index.d.ts +5 -0
- package/dist/documentDom/index.js +3 -0
- package/dist/documentDom/providers.d.ts +13 -0
- package/dist/documentDom/providers.js +52 -0
- package/dist/documentDom/scroll.d.ts +12 -0
- package/dist/documentDom/scroll.js +42 -0
- package/dist/documentDom.d.ts +5 -0
- package/dist/documentDom.js +3 -0
- package/dist/documentEvents.d.ts +73 -0
- package/dist/documentEvents.js +150 -0
- package/dist/documentSearch.d.ts +50 -0
- package/dist/documentSearch.js +459 -0
- package/dist/documentZoom.d.ts +47 -0
- package/dist/documentZoom.js +184 -0
- package/dist/export.d.ts +26 -0
- package/dist/export.js +466 -0
- package/dist/formats.d.ts +305 -0
- package/dist/formats.js +207 -0
- package/dist/headless.d.ts +25 -0
- package/dist/headless.js +14 -0
- package/dist/index.d.ts +78 -0
- package/dist/index.js +118 -0
- package/dist/lifecycleFacade.d.ts +46 -0
- package/dist/lifecycleFacade.js +68 -0
- package/dist/loading.d.ts +59 -0
- package/dist/loading.js +489 -0
- package/dist/operations.d.ts +287 -0
- package/dist/operations.js +485 -0
- package/dist/options.d.ts +16 -0
- package/dist/options.js +92 -0
- package/dist/presentation.d.ts +14 -0
- package/dist/presentation.js +16 -0
- package/dist/printLayout.d.ts +19 -0
- package/dist/printLayout.js +83 -0
- package/dist/registry.d.ts +2 -0
- package/dist/registry.js +63 -0
- package/dist/rendererDispatcher.d.ts +21 -0
- package/dist/rendererDispatcher.js +42 -0
- package/dist/rendererHandler.d.ts +165 -0
- package/dist/rendererHandler.js +354 -0
- package/dist/renderers/archive.d.ts +2 -0
- package/dist/renderers/archive.js +547 -0
- package/dist/renderers/archiveCache.d.ts +10 -0
- package/dist/renderers/archiveCache.js +96 -0
- package/dist/renderers/archiveFallback.d.ts +7 -0
- package/dist/renderers/archiveFallback.js +166 -0
- package/dist/renderers/archiveShared.d.ts +23 -0
- package/dist/renderers/archiveShared.js +71 -0
- package/dist/renderers/audio.d.ts +8 -0
- package/dist/renderers/audio.js +219 -0
- package/dist/renderers/cad.d.ts +2 -0
- package/dist/renderers/cad.js +445 -0
- package/dist/renderers/code.d.ts +11 -0
- package/dist/renderers/code.js +233 -0
- package/dist/renderers/data.d.ts +7 -0
- package/dist/renderers/data.js +370 -0
- package/dist/renderers/drawing.d.ts +10 -0
- package/dist/renderers/drawing.js +537 -0
- package/dist/renderers/eda.d.ts +2 -0
- package/dist/renderers/eda.js +434 -0
- package/dist/renderers/edaParser.d.ts +77 -0
- package/dist/renderers/edaParser.js +569 -0
- package/dist/renderers/email.d.ts +2 -0
- package/dist/renderers/email.js +463 -0
- package/dist/renderers/epub.d.ts +2 -0
- package/dist/renderers/epub.js +330 -0
- package/dist/renderers/geo.d.ts +2 -0
- package/dist/renderers/geo.js +284 -0
- package/dist/renderers/image.d.ts +2 -0
- package/dist/renderers/image.js +179 -0
- package/dist/renderers/index.d.ts +21 -0
- package/dist/renderers/index.js +207 -0
- package/dist/renderers/markdown.d.ts +2 -0
- package/dist/renderers/markdown.js +83 -0
- package/dist/renderers/model.d.ts +2 -0
- package/dist/renderers/model.js +566 -0
- package/dist/renderers/ofd.d.ts +2 -0
- package/dist/renderers/ofd.js +255 -0
- package/dist/renderers/openDocument.d.ts +2 -0
- package/dist/renderers/openDocument.js +122 -0
- package/dist/renderers/pdf.d.ts +3 -0
- package/dist/renderers/pdf.js +846 -0
- package/dist/renderers/pdfStyles.d.ts +1 -0
- package/dist/renderers/pdfStyles.js +1 -0
- package/dist/renderers/pptx.d.ts +2 -0
- package/dist/renderers/pptx.js +202 -0
- package/dist/renderers/spreadsheet/state.d.ts +80 -0
- package/dist/renderers/spreadsheet/state.js +96 -0
- package/dist/renderers/spreadsheet/view.d.ts +25 -0
- package/dist/renderers/spreadsheet/view.js +833 -0
- package/dist/renderers/spreadsheet/worker/index.d.ts +2 -0
- package/dist/renderers/spreadsheet/worker/index.js +1 -0
- package/dist/renderers/spreadsheet/worker/sheetjs/SheetJsModel.d.ts +73 -0
- package/dist/renderers/spreadsheet/worker/sheetjs/SheetJsModel.js +623 -0
- package/dist/renderers/spreadsheet/worker/sheetjs/color.d.ts +2 -0
- package/dist/renderers/spreadsheet/worker/sheetjs/color.js +73 -0
- package/dist/renderers/spreadsheet/worker/sheetjs/index.d.ts +1 -0
- package/dist/renderers/spreadsheet/worker/sheetjs/index.js +1 -0
- package/dist/renderers/spreadsheet/worker/sheetjs/parser.d.ts +18 -0
- package/dist/renderers/spreadsheet/worker/sheetjs/parser.js +106 -0
- package/dist/renderers/spreadsheet/worker/sheetjs/sheet.worker.d.ts +1 -0
- package/dist/renderers/spreadsheet/worker/sheetjs/sheet.worker.js +11 -0
- package/dist/renderers/spreadsheet/worker/type.d.ts +57 -0
- package/dist/renderers/spreadsheet/worker/type.js +1 -0
- package/dist/renderers/spreadsheet.d.ts +3 -0
- package/dist/renderers/spreadsheet.js +929 -0
- package/dist/renderers/typst.d.ts +8 -0
- package/dist/renderers/typst.js +415 -0
- package/dist/renderers/umd/parser.d.ts +30 -0
- package/dist/renderers/umd/parser.js +408 -0
- package/dist/renderers/umd.d.ts +2 -0
- package/dist/renderers/umd.js +297 -0
- package/dist/renderers/video.d.ts +8 -0
- package/dist/renderers/video.js +108 -0
- package/dist/renderers/wordDoc.d.ts +5 -0
- package/dist/renderers/wordDoc.js +284 -0
- package/dist/renderers/wordDocx.d.ts +5 -0
- package/dist/renderers/wordDocx.js +501 -0
- package/dist/renderers/wordDocx.worker.d.ts +1 -0
- package/dist/renderers/wordDocx.worker.js +96 -0
- package/dist/source.d.ts +18 -0
- package/dist/source.js +152 -0
- package/dist/sourceLoading.d.ts +566 -0
- package/dist/sourceLoading.js +918 -0
- package/dist/state.d.ts +16 -0
- package/dist/state.js +81 -0
- package/dist/types.d.ts +446 -0
- package/dist/types.js +1 -0
- package/dist/viewer.d.ts +8 -0
- package/dist/viewer.js +285 -0
- package/dist/viewerOperations.d.ts +88 -0
- package/dist/viewerOperations.js +242 -0
- package/dist/watermark.d.ts +15 -0
- package/dist/watermark.js +81 -0
- package/dist/worker.d.ts +34 -0
- package/dist/worker.js +101 -0
- package/package.json +109 -0
- package/vendor/ofd/dltech/jbig2/arithmetic_decoder.js +183 -0
- package/vendor/ofd/dltech/jbig2/ccitt.js +1070 -0
- package/vendor/ofd/dltech/jbig2/compatibility.js +12 -0
- package/vendor/ofd/dltech/jbig2/core_utils.js +180 -0
- package/vendor/ofd/dltech/jbig2/is_node.js +27 -0
- package/vendor/ofd/dltech/jbig2/jbig2.js +2589 -0
- package/vendor/ofd/dltech/jbig2/jbig2_stream.js +81 -0
- package/vendor/ofd/dltech/jbig2/primitives.js +387 -0
- package/vendor/ofd/dltech/jbig2/stream.js +1348 -0
- package/vendor/ofd/dltech/jbig2/util.js +972 -0
- package/vendor/ofd/dltech/ofd/ofd.d.ts +11 -0
- package/vendor/ofd/dltech/ofd/ofd.js +100 -0
- package/vendor/ofd/dltech/ofd/ofd_parser.js +395 -0
- package/vendor/ofd/dltech/ofd/ofd_render.js +473 -0
- package/vendor/ofd/dltech/ofd/ofd_util.js +350 -0
- package/vendor/ofd/dltech/ofd/pipeline.js +26 -0
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/README.en.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# @file-viewer/core
|
|
2
|
+
|
|
3
|
+
Framework-neutral TypeScript foundation for Flyfish File Viewer.
|
|
4
|
+
|
|
5
|
+
This package is the migration base for the next architecture: one pure TypeScript core package with internal `headless`, `browser`, and `renderers` layers, plus multiple native standard component packages for Vue, React, pure JavaScript, jQuery, and Svelte. Core owns the shared format matrix, source detection, renderer protocol, capability calculation, lifecycle context, operation guards, operation/event/search/location/zoom/print/export contracts, heavy renderer asset manifests, option normalization, pure state models, and framework-neutral browser rendering engine.
|
|
6
|
+
|
|
7
|
+
Browser execution belongs inside core only when it remains framework-neutral TypeScript. DOM mounting, `HTMLElement` traversal, search highlights, zoom provider discovery, print windows, download triggers, Canvas, Worker, and WASM renderers must not depend on Vue, React, Svelte, or any component package. Framework component packages keep their own local controller, component lifecycle, toolbar/search/loading UI, and ecosystem interaction layer while depending on `@file-viewer/core` as the only shared base.
|
|
8
|
+
|
|
9
|
+
`@file-viewer/core` is the only shared foundation package. It owns the headless contracts plus browser/renderers layers for the direct `createViewer(container, options)` engine, renderer registry, DOM provider registry, print layout helpers, browser asset resolution, and framework-neutral DOM/Canvas/Worker/WASM rendering contracts. Core source is public; the private Gitea aggregate remains available for the complete workspace, unified release automation, sponsorship, and priority support.
|
|
10
|
+
|
|
11
|
+
Migrated browser renderers currently include media, code, Markdown, images, UMD, geospatial data, Word DOCX/DOC, Excel/Spreadsheet, OpenDocument/RTF, PDF, OFD, email, EDA, CAD, Typst, PPTX, EPUB, 3D models, drawing files, data assets, and archives. Component packages should reuse these handlers instead of carrying framework-specific renderer copies.
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @file-viewer/core
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Entry points
|
|
18
|
+
|
|
19
|
+
Use `@file-viewer/core/headless` when a component package, server-side helper, or build script only needs framework-neutral contracts: format support, source normalization, renderer capability metadata, lifecycle/operation context, option normalization, state helpers, and static asset resolution. This entry intentionally does not expose the DOM viewer engine or browser renderers.
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import {
|
|
23
|
+
DEFAULT_SUPPORTED_EXTENSIONS,
|
|
24
|
+
normalizeSource,
|
|
25
|
+
resolveFileViewerRendererAssets
|
|
26
|
+
} from '@file-viewer/core/headless'
|
|
27
|
+
|
|
28
|
+
const source = normalizeSource({ url: '/files/report.pdf' })
|
|
29
|
+
const pdfAssets = resolveFileViewerRendererAssets('pdf', {
|
|
30
|
+
baseUrl: '/file-viewer/'
|
|
31
|
+
})
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Use `@file-viewer/core/browser` when a native component package or pure browser integration needs the direct DOM engine, renderer registry, search/zoom providers, print/export adapters, and framework-neutral Canvas/Worker/WASM renderers.
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import {
|
|
38
|
+
createViewer,
|
|
39
|
+
coreBrowserRendererHandlers
|
|
40
|
+
} from '@file-viewer/core/browser'
|
|
41
|
+
|
|
42
|
+
const viewer = createViewer(document.querySelector('#viewer')!, {
|
|
43
|
+
options: {
|
|
44
|
+
toolbar: true
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
await viewer.load({ url: '/files/report.pdf' })
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The root `@file-viewer/core` entry remains the complete compatibility entry for existing integrations. New component packages should prefer the narrowest explicit entry point they need: `headless` for contracts and build-time helpers, `browser` for real browser preview.
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import {
|
|
55
|
+
listFileViewerRendererAssetManifests,
|
|
56
|
+
resolveFileViewerRendererAssets
|
|
57
|
+
} from '@file-viewer/core'
|
|
58
|
+
|
|
59
|
+
const manifests = listFileViewerRendererAssetManifests()
|
|
60
|
+
const archiveAssets = resolveFileViewerRendererAssets('archive', {
|
|
61
|
+
baseUrl: '/file-viewer/'
|
|
62
|
+
})
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
The manifest API lets wrappers and deployment scripts discover archive, DOCX, Spreadsheet, CAD, Typst, and data-asset worker/WASM resources from the same core contract instead of hard-coding per-framework paths.
|
|
66
|
+
|
|
67
|
+
Official documentation: https://doc.flyfish-viewer.app/
|
|
68
|
+
|
|
69
|
+
Online demo: https://viewer.flyfish.dev/
|
|
70
|
+
|
|
71
|
+
Public source repositories:
|
|
72
|
+
|
|
73
|
+
- GitHub: https://github.com/flyfish-dev/file-viewer-core
|
|
74
|
+
- Gitee: https://gitee.com/flyfish-dev/file-viewer-core
|
|
75
|
+
|
|
76
|
+
The GitHub/Gitee repositories are distributed public source packages. The private Gitea aggregate remains useful for the complete workspace, release automation, integration history, sponsorship, and priority support.
|
|
77
|
+
|
|
78
|
+
License: Apache-2.0. For second development or commercial use, keep clear Flyfish Viewer attribution and contribute shared compatibility improvements where possible.
|
package/README.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# @file-viewer/core
|
|
2
|
+
|
|
3
|
+
Framework-neutral TypeScript foundation for Flyfish File Viewer.
|
|
4
|
+
|
|
5
|
+
This package is the migration base for the next architecture: one pure TypeScript core package with internal `headless`, `browser`, and `renderers` layers, plus multiple native standard component packages for Vue, React, pure JavaScript, jQuery and Svelte. Core owns the shared format matrix, source detection, renderer protocol, capability calculation, lifecycle context, operation/event/search/location/zoom/print/export contracts, heavy renderer asset manifests, option normalization, pure state models, and framework-neutral browser rendering engine.
|
|
6
|
+
|
|
7
|
+
Browser execution belongs inside core only when it remains framework-neutral TypeScript. DOM mounting, `HTMLElement` traversal, search highlights, zoom provider discovery, print windows, download triggers, Canvas, Worker and WASM renderers must not depend on Vue, React, Svelte or any component package. Framework component packages keep their own local controller, component lifecycle, toolbar/search/loading UI, and ecosystem interaction layer while depending on `@file-viewer/core` as the only shared base.
|
|
8
|
+
|
|
9
|
+
`@file-viewer/core` is the only shared foundation package. It owns the headless contracts plus browser/renderers layers for the direct `createViewer(container, options)` engine, renderer registry, DOM provider registry, print layout helpers, browser asset resolution, and framework-neutral DOM/Canvas/Worker/WASM rendering contracts. Core source is public; the private Gitea aggregate remains available for the complete workspace, unified release automation, sponsorship, and priority support.
|
|
10
|
+
|
|
11
|
+
Current migrated browser renderers include media, code, Markdown, images, UMD, geo data, Word DOCX/DOC, Excel/Spreadsheet, OpenDocument/RTF, PDF, OFD, email, EDA, CAD, Typst, PPTX, EPUB, 3D models, drawing files, data assets and archives. Component packages should reuse these handlers instead of carrying framework-specific renderer copies.
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @file-viewer/core
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Entry points
|
|
18
|
+
|
|
19
|
+
Use `@file-viewer/core/headless` when a component package, server-side helper or build script only needs framework-neutral contracts: format support, source normalization, renderer capability metadata, lifecycle/operation context, option normalization, state helpers and static asset resolution. This entry intentionally does not expose the DOM viewer engine or browser renderers.
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import {
|
|
23
|
+
DEFAULT_SUPPORTED_EXTENSIONS,
|
|
24
|
+
normalizeSource,
|
|
25
|
+
resolveFileViewerRendererAssets
|
|
26
|
+
} from '@file-viewer/core/headless'
|
|
27
|
+
|
|
28
|
+
const source = normalizeSource({ url: '/files/report.pdf' })
|
|
29
|
+
const pdfAssets = resolveFileViewerRendererAssets('pdf', {
|
|
30
|
+
baseUrl: '/file-viewer/'
|
|
31
|
+
})
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Use `@file-viewer/core/browser` when a native component package or a pure browser integration needs the direct DOM engine, renderer registry, search/zoom providers, print/export adapters and framework-neutral Canvas/Worker/WASM renderers.
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import {
|
|
38
|
+
createViewer,
|
|
39
|
+
coreBrowserRendererHandlers
|
|
40
|
+
} from '@file-viewer/core/browser'
|
|
41
|
+
|
|
42
|
+
const viewer = createViewer(document.querySelector('#viewer')!, {
|
|
43
|
+
options: {
|
|
44
|
+
toolbar: true
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
await viewer.load({ url: '/files/report.pdf' })
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The root `@file-viewer/core` entry remains the complete compatibility entry for existing integrations. New component packages should prefer the narrowest explicit entry point they need: `headless` for contracts and build-time helpers, `browser` for real browser preview.
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import {
|
|
55
|
+
listFileViewerRendererAssetManifests,
|
|
56
|
+
resolveFileViewerRendererAssets
|
|
57
|
+
} from '@file-viewer/core'
|
|
58
|
+
|
|
59
|
+
const manifests = listFileViewerRendererAssetManifests()
|
|
60
|
+
const cadAssets = resolveFileViewerRendererAssets('cad', {
|
|
61
|
+
baseUrl: '/file-viewer/',
|
|
62
|
+
options: {
|
|
63
|
+
cad: {
|
|
64
|
+
wasmPath: '/file-viewer/wasm/cad/'
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The manifest API lets wrappers and deployment scripts discover archive, DOCX, Spreadsheet, CAD, Typst and data-asset worker/WASM resources from the same core contract instead of hard-coding per-framework paths.
|
|
71
|
+
|
|
72
|
+
Official documentation: https://doc.flyfish-viewer.app/
|
|
73
|
+
|
|
74
|
+
Online demo: https://viewer.flyfish.dev/
|
|
75
|
+
|
|
76
|
+
Public source repositories:
|
|
77
|
+
|
|
78
|
+
- GitHub: https://github.com/flyfish-dev/file-viewer-core
|
|
79
|
+
- Gitee: https://gitee.com/flyfish-dev/file-viewer-core
|
|
80
|
+
|
|
81
|
+
The GitHub/Gitee repositories are distributed public source packages. The private Gitea aggregate remains useful for the complete workspace, release automation, integration history, sponsorship, and priority support.
|
|
82
|
+
|
|
83
|
+
License: Apache-2.0. For second development or commercial use, keep clear Flyfish Viewer attribution and contribute shared compatibility improvements where possible.
|
package/dist/assets.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { FileViewerArchiveOptions, FileViewerCadOptions, FileViewerDataOptions, FileViewerDocxOptions, FileViewerOptions, FileViewerSpreadsheetOptions, FileViewerTypstOptions } from './types';
|
|
2
|
+
export declare const DEFAULT_FILE_VIEWER_ARCHIVE_WORKER_PATH = "vendor/libarchive/worker-bundle.js";
|
|
3
|
+
export declare const DEFAULT_FILE_VIEWER_ARCHIVE_WASM_PATH = "vendor/libarchive/libarchive.wasm";
|
|
4
|
+
export declare const DEFAULT_FILE_VIEWER_DOCX_WORKER_PATH = "vendor/docx/docx.worker.js";
|
|
5
|
+
export declare const DEFAULT_FILE_VIEWER_SPREADSHEET_WORKER_PATH = "vendor/xlsx/sheet.worker.js";
|
|
6
|
+
export declare const DEFAULT_FILE_VIEWER_CAD_WASM_PATH = "wasm/cad/";
|
|
7
|
+
export declare const DEFAULT_FILE_VIEWER_CAD_WORKER_PATH = "wasm/cad/dwg-worker.js";
|
|
8
|
+
export declare const DEFAULT_FILE_VIEWER_CAD_DWF_WASM_PATH = "wasm/cad/dwfv-render.wasm";
|
|
9
|
+
export declare const DEFAULT_FILE_VIEWER_TYPST_COMPILER_WASM_URL = "https://cdn.jsdelivr.net/npm/@myriaddreamin/typst-ts-web-compiler@0.7.0/pkg/typst_ts_web_compiler_bg.wasm";
|
|
10
|
+
export declare const DEFAULT_FILE_VIEWER_TYPST_RENDERER_WASM_URL = "https://cdn.jsdelivr.net/npm/@myriaddreamin/typst-ts-renderer@0.7.0/pkg/typst_ts_renderer_bg.wasm";
|
|
11
|
+
export declare const DEFAULT_FILE_VIEWER_TYPST_RENDERER_WASM_PACKAGE_PATH = "@myriaddreamin/typst-ts-renderer/pkg/typst_ts_renderer_bg.wasm";
|
|
12
|
+
export declare const DEFAULT_FILE_VIEWER_DATA_SQL_WASM_URL = "https://cdn.jsdelivr.net/npm/sql.js@1.14.1/dist/sql-wasm.wasm";
|
|
13
|
+
export interface ResolveFileViewerAssetUrlOptions {
|
|
14
|
+
baseUrl?: string;
|
|
15
|
+
documentBaseUrl?: string;
|
|
16
|
+
trimTrailingSlash?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface ResolvedFileViewerCadAssetUrls {
|
|
19
|
+
wasmPath: string;
|
|
20
|
+
workerUrl: string;
|
|
21
|
+
dwfWasmUrl: string;
|
|
22
|
+
}
|
|
23
|
+
export type FileViewerRendererAssetKind = 'worker' | 'wasm' | 'wasm-directory' | 'script' | 'bundled-wasm';
|
|
24
|
+
export type FileViewerRendererAssetTarget = 'public' | 'bundled' | 'external';
|
|
25
|
+
export type FileViewerRendererAssetOptionPath = 'archive.workerUrl' | 'archive.wasmUrl' | 'cad.wasmPath' | 'cad.workerUrl' | 'cad.dwfWasmUrl' | 'data.sqlWasmUrl' | 'docx.workerUrl' | 'spreadsheet.workerUrl' | 'typst.compilerWasmUrl' | 'typst.rendererWasmUrl';
|
|
26
|
+
export interface FileViewerRendererAssetDefinition {
|
|
27
|
+
id: string;
|
|
28
|
+
rendererId: string;
|
|
29
|
+
kind: FileViewerRendererAssetKind;
|
|
30
|
+
target: FileViewerRendererAssetTarget;
|
|
31
|
+
required: boolean;
|
|
32
|
+
defaultPath?: string;
|
|
33
|
+
defaultUrl?: string;
|
|
34
|
+
packagePath?: string;
|
|
35
|
+
optionPath?: FileViewerRendererAssetOptionPath;
|
|
36
|
+
description: string;
|
|
37
|
+
}
|
|
38
|
+
export interface FileViewerRendererAssetManifest {
|
|
39
|
+
rendererId: string;
|
|
40
|
+
assets: readonly FileViewerRendererAssetDefinition[];
|
|
41
|
+
}
|
|
42
|
+
export interface ResolvedFileViewerRendererAsset extends FileViewerRendererAssetDefinition {
|
|
43
|
+
configured: boolean;
|
|
44
|
+
url?: string;
|
|
45
|
+
packagePath?: string;
|
|
46
|
+
}
|
|
47
|
+
export interface ResolveFileViewerRendererAssetsOptions extends ResolveFileViewerAssetUrlOptions {
|
|
48
|
+
options?: FileViewerOptions | null;
|
|
49
|
+
}
|
|
50
|
+
export declare const DEFAULT_FILE_VIEWER_RENDERER_ASSET_MANIFESTS: readonly FileViewerRendererAssetManifest[];
|
|
51
|
+
export declare const resolveFileViewerAssetUrl: (value: string | URL | undefined, fallback: string, options?: ResolveFileViewerAssetUrlOptions) => string;
|
|
52
|
+
export declare const resolveFileViewerArchiveWorkerUrl: (options?: Pick<FileViewerArchiveOptions, "workerUrl"> | null, baseUrl?: string) => string;
|
|
53
|
+
export declare const resolveFileViewerArchiveWasmUrl: (options?: Pick<FileViewerArchiveOptions, "wasmUrl"> | null, fallback?: string) => string;
|
|
54
|
+
export declare const resolveFileViewerCadAssetUrls: (options?: Pick<FileViewerCadOptions, "wasmPath" | "workerUrl" | "dwfWasmUrl"> | null, documentBaseUrl?: string) => ResolvedFileViewerCadAssetUrls;
|
|
55
|
+
export declare const resolveFileViewerDocxWorkerUrl: (options?: Pick<FileViewerDocxOptions, "workerUrl"> | null, documentBaseUrl?: string) => string;
|
|
56
|
+
export declare const resolveFileViewerSpreadsheetWorkerUrl: (options?: Pick<FileViewerSpreadsheetOptions, "workerUrl"> | null, documentBaseUrl?: string) => string;
|
|
57
|
+
export declare const resolveFileViewerTypstCompilerWasmUrl: (options?: Pick<FileViewerTypstOptions, "compilerWasmUrl"> | null, overrides?: Array<string | undefined>) => string;
|
|
58
|
+
export declare const resolveFileViewerTypstRendererWasmUrl: (options?: Pick<FileViewerTypstOptions, "rendererWasmUrl"> | null, overrides?: Array<string | undefined>) => string;
|
|
59
|
+
export declare const resolveFileViewerDataSqlWasmUrl: (options?: Pick<FileViewerDataOptions, "sqlWasmUrl"> | null, overrides?: Array<string | undefined>) => string;
|
|
60
|
+
export declare const listFileViewerRendererAssetManifests: () => FileViewerRendererAssetManifest[];
|
|
61
|
+
export declare const getFileViewerRendererAssetManifest: (rendererId: string) => FileViewerRendererAssetManifest | null;
|
|
62
|
+
export declare const resolveFileViewerRendererAssets: (rendererId: string, resolveOptions?: ResolveFileViewerRendererAssetsOptions) => ResolvedFileViewerRendererAsset[];
|
package/dist/assets.js
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
export const DEFAULT_FILE_VIEWER_ARCHIVE_WORKER_PATH = 'vendor/libarchive/worker-bundle.js';
|
|
2
|
+
export const DEFAULT_FILE_VIEWER_ARCHIVE_WASM_PATH = 'vendor/libarchive/libarchive.wasm';
|
|
3
|
+
export const DEFAULT_FILE_VIEWER_DOCX_WORKER_PATH = 'vendor/docx/docx.worker.js';
|
|
4
|
+
export const DEFAULT_FILE_VIEWER_SPREADSHEET_WORKER_PATH = 'vendor/xlsx/sheet.worker.js';
|
|
5
|
+
export const DEFAULT_FILE_VIEWER_CAD_WASM_PATH = 'wasm/cad/';
|
|
6
|
+
export const DEFAULT_FILE_VIEWER_CAD_WORKER_PATH = 'wasm/cad/dwg-worker.js';
|
|
7
|
+
export const DEFAULT_FILE_VIEWER_CAD_DWF_WASM_PATH = 'wasm/cad/dwfv-render.wasm';
|
|
8
|
+
export const DEFAULT_FILE_VIEWER_TYPST_COMPILER_WASM_URL = 'https://cdn.jsdelivr.net/npm/@myriaddreamin/typst-ts-web-compiler@0.7.0/pkg/typst_ts_web_compiler_bg.wasm';
|
|
9
|
+
export const DEFAULT_FILE_VIEWER_TYPST_RENDERER_WASM_URL = 'https://cdn.jsdelivr.net/npm/@myriaddreamin/typst-ts-renderer@0.7.0/pkg/typst_ts_renderer_bg.wasm';
|
|
10
|
+
export const DEFAULT_FILE_VIEWER_TYPST_RENDERER_WASM_PACKAGE_PATH = '@myriaddreamin/typst-ts-renderer/pkg/typst_ts_renderer_bg.wasm';
|
|
11
|
+
export const DEFAULT_FILE_VIEWER_DATA_SQL_WASM_URL = 'https://cdn.jsdelivr.net/npm/sql.js@1.14.1/dist/sql-wasm.wasm';
|
|
12
|
+
export const DEFAULT_FILE_VIEWER_RENDERER_ASSET_MANIFESTS = [
|
|
13
|
+
{
|
|
14
|
+
rendererId: 'archive',
|
|
15
|
+
assets: [
|
|
16
|
+
{
|
|
17
|
+
id: 'libarchive-worker',
|
|
18
|
+
rendererId: 'archive',
|
|
19
|
+
kind: 'worker',
|
|
20
|
+
target: 'public',
|
|
21
|
+
required: false,
|
|
22
|
+
defaultPath: DEFAULT_FILE_VIEWER_ARCHIVE_WORKER_PATH,
|
|
23
|
+
optionPath: 'archive.workerUrl',
|
|
24
|
+
description: 'libarchive.js module worker used for broad archive format parsing.',
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
id: 'libarchive-wasm',
|
|
28
|
+
rendererId: 'archive',
|
|
29
|
+
kind: 'wasm',
|
|
30
|
+
target: 'public',
|
|
31
|
+
required: false,
|
|
32
|
+
defaultPath: DEFAULT_FILE_VIEWER_ARCHIVE_WASM_PATH,
|
|
33
|
+
optionPath: 'archive.wasmUrl',
|
|
34
|
+
description: 'libarchive.js WebAssembly module expected next to the public worker.',
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
rendererId: 'cad',
|
|
40
|
+
assets: [
|
|
41
|
+
{
|
|
42
|
+
id: 'cad-wasm-directory',
|
|
43
|
+
rendererId: 'cad',
|
|
44
|
+
kind: 'wasm-directory',
|
|
45
|
+
target: 'public',
|
|
46
|
+
required: true,
|
|
47
|
+
defaultPath: DEFAULT_FILE_VIEWER_CAD_WASM_PATH,
|
|
48
|
+
optionPath: 'cad.wasmPath',
|
|
49
|
+
description: '@flyfish-dev/cad-viewer WebAssembly directory for DWG/DXF helpers.',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
id: 'cad-dwg-worker',
|
|
53
|
+
rendererId: 'cad',
|
|
54
|
+
kind: 'worker',
|
|
55
|
+
target: 'public',
|
|
56
|
+
required: true,
|
|
57
|
+
defaultPath: DEFAULT_FILE_VIEWER_CAD_WORKER_PATH,
|
|
58
|
+
optionPath: 'cad.workerUrl',
|
|
59
|
+
description: 'DWG worker entry used by @flyfish-dev/cad-viewer.',
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
id: 'cad-dwf-wasm',
|
|
63
|
+
rendererId: 'cad',
|
|
64
|
+
kind: 'wasm',
|
|
65
|
+
target: 'public',
|
|
66
|
+
required: true,
|
|
67
|
+
defaultPath: DEFAULT_FILE_VIEWER_CAD_DWF_WASM_PATH,
|
|
68
|
+
optionPath: 'cad.dwfWasmUrl',
|
|
69
|
+
description: 'DWF/DWFx/XPS raster WebAssembly module used by @flyfish-dev/cad-viewer.',
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
rendererId: 'office-word-openxml',
|
|
75
|
+
assets: [
|
|
76
|
+
{
|
|
77
|
+
id: 'docx-worker',
|
|
78
|
+
rendererId: 'office-word-openxml',
|
|
79
|
+
kind: 'worker',
|
|
80
|
+
target: 'public',
|
|
81
|
+
required: false,
|
|
82
|
+
defaultPath: DEFAULT_FILE_VIEWER_DOCX_WORKER_PATH,
|
|
83
|
+
optionPath: 'docx.workerUrl',
|
|
84
|
+
description: 'Optional DOCX worker for off-main-thread docx-preview parsing and HTML assembly.',
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
rendererId: 'spreadsheet-openxml',
|
|
90
|
+
assets: [
|
|
91
|
+
{
|
|
92
|
+
id: 'spreadsheet-worker',
|
|
93
|
+
rendererId: 'spreadsheet-openxml',
|
|
94
|
+
kind: 'worker',
|
|
95
|
+
target: 'public',
|
|
96
|
+
required: false,
|
|
97
|
+
defaultPath: DEFAULT_FILE_VIEWER_SPREADSHEET_WORKER_PATH,
|
|
98
|
+
optionPath: 'spreadsheet.workerUrl',
|
|
99
|
+
description: 'Optional Spreadsheet worker for off-main-thread styled-exceljs workbook parsing.',
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
rendererId: 'typst',
|
|
105
|
+
assets: [
|
|
106
|
+
{
|
|
107
|
+
id: 'typst-compiler-wasm',
|
|
108
|
+
rendererId: 'typst',
|
|
109
|
+
kind: 'wasm',
|
|
110
|
+
target: 'external',
|
|
111
|
+
required: true,
|
|
112
|
+
defaultUrl: DEFAULT_FILE_VIEWER_TYPST_COMPILER_WASM_URL,
|
|
113
|
+
optionPath: 'typst.compilerWasmUrl',
|
|
114
|
+
description: 'Typst compiler WebAssembly module; configurable for private CDN deployment.',
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
id: 'typst-renderer-wasm',
|
|
118
|
+
rendererId: 'typst',
|
|
119
|
+
kind: 'bundled-wasm',
|
|
120
|
+
target: 'bundled',
|
|
121
|
+
required: true,
|
|
122
|
+
defaultUrl: DEFAULT_FILE_VIEWER_TYPST_RENDERER_WASM_URL,
|
|
123
|
+
packagePath: DEFAULT_FILE_VIEWER_TYPST_RENDERER_WASM_PACKAGE_PATH,
|
|
124
|
+
optionPath: 'typst.rendererWasmUrl',
|
|
125
|
+
description: 'Typst SVG renderer WebAssembly module bundled by the active frontend build tool.',
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
rendererId: 'data-asset',
|
|
131
|
+
assets: [
|
|
132
|
+
{
|
|
133
|
+
id: 'data-sql-wasm',
|
|
134
|
+
rendererId: 'data-asset',
|
|
135
|
+
kind: 'wasm',
|
|
136
|
+
target: 'external',
|
|
137
|
+
required: false,
|
|
138
|
+
defaultUrl: DEFAULT_FILE_VIEWER_DATA_SQL_WASM_URL,
|
|
139
|
+
optionPath: 'data.sqlWasmUrl',
|
|
140
|
+
description: 'sql.js WebAssembly module used when previewing SQLite files.',
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
},
|
|
144
|
+
];
|
|
145
|
+
const DEFAULT_FILE_VIEWER_DOCUMENT_BASE_URL = 'http://localhost/';
|
|
146
|
+
export const resolveFileViewerAssetUrl = (value, fallback, options = {}) => {
|
|
147
|
+
const raw = value ? String(value) : fallback;
|
|
148
|
+
const documentBaseUrl = options.documentBaseUrl || DEFAULT_FILE_VIEWER_DOCUMENT_BASE_URL;
|
|
149
|
+
const baseUrl = options.baseUrl
|
|
150
|
+
? options.baseUrl.endsWith('/') ? options.baseUrl : `${options.baseUrl}/`
|
|
151
|
+
: documentBaseUrl;
|
|
152
|
+
const resolvedBase = options.baseUrl
|
|
153
|
+
? new URL(baseUrl, documentBaseUrl).href
|
|
154
|
+
: baseUrl;
|
|
155
|
+
const resolved = new URL(raw, resolvedBase).href;
|
|
156
|
+
return options.trimTrailingSlash ? resolved.replace(/\/+$/, '') : resolved;
|
|
157
|
+
};
|
|
158
|
+
export const resolveFileViewerArchiveWorkerUrl = (options, baseUrl) => {
|
|
159
|
+
return resolveFileViewerAssetUrl(options === null || options === void 0 ? void 0 : options.workerUrl, DEFAULT_FILE_VIEWER_ARCHIVE_WORKER_PATH, { baseUrl });
|
|
160
|
+
};
|
|
161
|
+
export const resolveFileViewerArchiveWasmUrl = (options, fallback = '') => {
|
|
162
|
+
if (!(options === null || options === void 0 ? void 0 : options.wasmUrl)) {
|
|
163
|
+
return fallback;
|
|
164
|
+
}
|
|
165
|
+
return resolveFileViewerAssetUrl(options.wasmUrl, fallback || options.wasmUrl);
|
|
166
|
+
};
|
|
167
|
+
export const resolveFileViewerCadAssetUrls = (options, documentBaseUrl) => {
|
|
168
|
+
return {
|
|
169
|
+
wasmPath: resolveFileViewerAssetUrl(options === null || options === void 0 ? void 0 : options.wasmPath, DEFAULT_FILE_VIEWER_CAD_WASM_PATH, {
|
|
170
|
+
documentBaseUrl,
|
|
171
|
+
trimTrailingSlash: true,
|
|
172
|
+
}),
|
|
173
|
+
workerUrl: resolveFileViewerAssetUrl(options === null || options === void 0 ? void 0 : options.workerUrl, DEFAULT_FILE_VIEWER_CAD_WORKER_PATH, {
|
|
174
|
+
documentBaseUrl,
|
|
175
|
+
}),
|
|
176
|
+
dwfWasmUrl: resolveFileViewerAssetUrl(options === null || options === void 0 ? void 0 : options.dwfWasmUrl, DEFAULT_FILE_VIEWER_CAD_DWF_WASM_PATH, {
|
|
177
|
+
documentBaseUrl,
|
|
178
|
+
}),
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
export const resolveFileViewerDocxWorkerUrl = (options, documentBaseUrl) => {
|
|
182
|
+
return resolveFileViewerAssetUrl(options === null || options === void 0 ? void 0 : options.workerUrl, DEFAULT_FILE_VIEWER_DOCX_WORKER_PATH, {
|
|
183
|
+
documentBaseUrl,
|
|
184
|
+
});
|
|
185
|
+
};
|
|
186
|
+
export const resolveFileViewerSpreadsheetWorkerUrl = (options, documentBaseUrl) => {
|
|
187
|
+
return resolveFileViewerAssetUrl(options === null || options === void 0 ? void 0 : options.workerUrl, DEFAULT_FILE_VIEWER_SPREADSHEET_WORKER_PATH, {
|
|
188
|
+
documentBaseUrl,
|
|
189
|
+
});
|
|
190
|
+
};
|
|
191
|
+
export const resolveFileViewerTypstCompilerWasmUrl = (options, overrides = []) => {
|
|
192
|
+
return (options === null || options === void 0 ? void 0 : options.compilerWasmUrl) ||
|
|
193
|
+
overrides.find(Boolean) ||
|
|
194
|
+
DEFAULT_FILE_VIEWER_TYPST_COMPILER_WASM_URL;
|
|
195
|
+
};
|
|
196
|
+
export const resolveFileViewerTypstRendererWasmUrl = (options, overrides = []) => {
|
|
197
|
+
return (options === null || options === void 0 ? void 0 : options.rendererWasmUrl) ||
|
|
198
|
+
overrides.find(Boolean) ||
|
|
199
|
+
DEFAULT_FILE_VIEWER_TYPST_RENDERER_WASM_URL;
|
|
200
|
+
};
|
|
201
|
+
export const resolveFileViewerDataSqlWasmUrl = (options, overrides = []) => {
|
|
202
|
+
return (options === null || options === void 0 ? void 0 : options.sqlWasmUrl) ||
|
|
203
|
+
overrides.find(Boolean) ||
|
|
204
|
+
DEFAULT_FILE_VIEWER_DATA_SQL_WASM_URL;
|
|
205
|
+
};
|
|
206
|
+
export const listFileViewerRendererAssetManifests = () => {
|
|
207
|
+
return [...DEFAULT_FILE_VIEWER_RENDERER_ASSET_MANIFESTS];
|
|
208
|
+
};
|
|
209
|
+
export const getFileViewerRendererAssetManifest = (rendererId) => {
|
|
210
|
+
return DEFAULT_FILE_VIEWER_RENDERER_ASSET_MANIFESTS.find(manifest => manifest.rendererId === rendererId) || null;
|
|
211
|
+
};
|
|
212
|
+
const getRendererAssetOptionValue = (options, optionPath) => {
|
|
213
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
214
|
+
switch (optionPath) {
|
|
215
|
+
case 'archive.workerUrl':
|
|
216
|
+
return (_a = options === null || options === void 0 ? void 0 : options.archive) === null || _a === void 0 ? void 0 : _a.workerUrl;
|
|
217
|
+
case 'archive.wasmUrl':
|
|
218
|
+
return (_b = options === null || options === void 0 ? void 0 : options.archive) === null || _b === void 0 ? void 0 : _b.wasmUrl;
|
|
219
|
+
case 'cad.wasmPath':
|
|
220
|
+
return (_c = options === null || options === void 0 ? void 0 : options.cad) === null || _c === void 0 ? void 0 : _c.wasmPath;
|
|
221
|
+
case 'cad.workerUrl':
|
|
222
|
+
return (_d = options === null || options === void 0 ? void 0 : options.cad) === null || _d === void 0 ? void 0 : _d.workerUrl;
|
|
223
|
+
case 'cad.dwfWasmUrl':
|
|
224
|
+
return (_e = options === null || options === void 0 ? void 0 : options.cad) === null || _e === void 0 ? void 0 : _e.dwfWasmUrl;
|
|
225
|
+
case 'data.sqlWasmUrl':
|
|
226
|
+
return (_f = options === null || options === void 0 ? void 0 : options.data) === null || _f === void 0 ? void 0 : _f.sqlWasmUrl;
|
|
227
|
+
case 'docx.workerUrl':
|
|
228
|
+
return (_g = options === null || options === void 0 ? void 0 : options.docx) === null || _g === void 0 ? void 0 : _g.workerUrl;
|
|
229
|
+
case 'spreadsheet.workerUrl':
|
|
230
|
+
return (_h = options === null || options === void 0 ? void 0 : options.spreadsheet) === null || _h === void 0 ? void 0 : _h.workerUrl;
|
|
231
|
+
case 'typst.compilerWasmUrl':
|
|
232
|
+
return (_j = options === null || options === void 0 ? void 0 : options.typst) === null || _j === void 0 ? void 0 : _j.compilerWasmUrl;
|
|
233
|
+
case 'typst.rendererWasmUrl':
|
|
234
|
+
return (_k = options === null || options === void 0 ? void 0 : options.typst) === null || _k === void 0 ? void 0 : _k.rendererWasmUrl;
|
|
235
|
+
default:
|
|
236
|
+
return undefined;
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
export const resolveFileViewerRendererAssets = (rendererId, resolveOptions = {}) => {
|
|
240
|
+
const manifest = getFileViewerRendererAssetManifest(rendererId);
|
|
241
|
+
if (!manifest) {
|
|
242
|
+
return [];
|
|
243
|
+
}
|
|
244
|
+
return manifest.assets.map(asset => {
|
|
245
|
+
const optionValue = getRendererAssetOptionValue(resolveOptions.options, asset.optionPath);
|
|
246
|
+
const raw = optionValue ? String(optionValue) : asset.defaultUrl || asset.defaultPath;
|
|
247
|
+
const resolved = {
|
|
248
|
+
...asset,
|
|
249
|
+
configured: Boolean(optionValue),
|
|
250
|
+
};
|
|
251
|
+
if (raw) {
|
|
252
|
+
resolved.url = resolveFileViewerAssetUrl(raw, raw, {
|
|
253
|
+
baseUrl: resolveOptions.baseUrl,
|
|
254
|
+
documentBaseUrl: resolveOptions.documentBaseUrl,
|
|
255
|
+
trimTrailingSlash: asset.kind === 'wasm-directory' || resolveOptions.trimTrailingSlash,
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
return resolved;
|
|
259
|
+
});
|
|
260
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './index';
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './index.js';
|