@brftech/filex-core 0.1.56
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 +108 -0
- package/dist/ArchiveViewer-CJdaw5x3.js +99 -0
- package/dist/ArchiveViewer-CJdaw5x3.js.map +1 -0
- package/dist/CsvViewer-QYx_tePQ.js +132 -0
- package/dist/CsvViewer-QYx_tePQ.js.map +1 -0
- package/dist/DrawioViewer-GWt0TyB7.js +141 -0
- package/dist/DrawioViewer-GWt0TyB7.js.map +1 -0
- package/dist/EpubViewer-Je0ywklQ.js +146 -0
- package/dist/EpubViewer-Je0ywklQ.js.map +1 -0
- package/dist/IpynbViewer-TsB4gqP-.js +175 -0
- package/dist/IpynbViewer-TsB4gqP-.js.map +1 -0
- package/dist/MermaidViewer-CXfeDS-7.js +128 -0
- package/dist/MermaidViewer-CXfeDS-7.js.map +1 -0
- package/dist/PsdViewer-VtPpxKVe.js +113 -0
- package/dist/PsdViewer-VtPpxKVe.js.map +1 -0
- package/dist/TiffViewer-OINn9bbb.js +133 -0
- package/dist/TiffViewer-OINn9bbb.js.map +1 -0
- package/dist/UTIF-Cjsrlm0l.js +3104 -0
- package/dist/UTIF-Cjsrlm0l.js.map +1 -0
- package/dist/Viewer3D-xvvyiWHd.js +61 -0
- package/dist/Viewer3D-xvvyiWHd.js.map +1 -0
- package/dist/_commonjsHelpers-DaMA6jEr.js +9 -0
- package/dist/_commonjsHelpers-DaMA6jEr.js.map +1 -0
- package/dist/filex-core.js +26 -0
- package/dist/filex-core.js.map +1 -0
- package/dist/filex-core.umd.cjs +285 -0
- package/dist/filex-core.umd.cjs.map +1 -0
- package/dist/index-CmSYzt6L.js +5404 -0
- package/dist/index-CmSYzt6L.js.map +1 -0
- package/dist/index-UFULWo35.js +10736 -0
- package/dist/index-UFULWo35.js.map +1 -0
- package/dist/index.d.ts +1089 -0
- package/dist/katex-yuB6V-q6.js +11616 -0
- package/dist/katex-yuB6V-q6.js.map +1 -0
- package/dist/papaparse.min-VB1HBwYX.js +441 -0
- package/dist/papaparse.min-VB1HBwYX.js.map +1 -0
- package/dist/style.css +1 -0
- package/dist/useViewerFetch-czqbd2Lj.js +25 -0
- package/dist/useViewerFetch-czqbd2Lj.js.map +1 -0
- package/package.json +113 -0
- package/src/FileExplorer.vue +1872 -0
- package/src/components/Breadcrumb.vue +282 -0
- package/src/components/ContextMenu.vue +152 -0
- package/src/components/GridView.vue +166 -0
- package/src/components/ListView.vue +212 -0
- package/src/components/PendingOpsTray.vue +91 -0
- package/src/components/RecentlyOpened.vue +155 -0
- package/src/components/StarButton.vue +101 -0
- package/src/components/TagPicker.vue +184 -0
- package/src/components/Toolbar.vue +220 -0
- package/src/components/UploadProgress.vue +78 -0
- package/src/composables/useFileApi.ts +692 -0
- package/src/composables/useKeyboardShortcuts.ts +144 -0
- package/src/composables/useLocale.ts +60 -0
- package/src/composables/useMonacoLoader.ts +98 -0
- package/src/composables/usePendingOps.ts +200 -0
- package/src/composables/useSelection.ts +81 -0
- package/src/composables/useUploadChunked.ts +250 -0
- package/src/composables/useViewerFetch.ts +58 -0
- package/src/index.ts +80 -0
- package/src/locales/en.ts +122 -0
- package/src/locales/index.ts +12 -0
- package/src/locales/tr.ts +122 -0
- package/src/modals/ConvertModal.vue +254 -0
- package/src/modals/DeleteConfirmModal.vue +32 -0
- package/src/modals/Modal.vue +104 -0
- package/src/modals/NewFolderModal.vue +64 -0
- package/src/modals/PermissionsModal.vue +815 -0
- package/src/modals/PreviewModal.vue +1070 -0
- package/src/modals/RenameModal.vue +58 -0
- package/src/modals/ShareModal.vue +135 -0
- package/src/styles/base.css +1224 -0
- package/src/styles/variables.css +90 -0
- package/src/types/ExplorerConfig.ts +282 -0
- package/src/types/FileNode.ts +136 -0
- package/src/types/index.ts +27 -0
- package/src/types/peers.d.ts +45 -0
- package/src/viewers/ArchiveViewer.vue +186 -0
- package/src/viewers/CsvViewer.vue +319 -0
- package/src/viewers/DrawioViewer.vue +243 -0
- package/src/viewers/EpubViewer.vue +307 -0
- package/src/viewers/IpynbViewer.vue +365 -0
- package/src/viewers/MermaidViewer.vue +259 -0
- package/src/viewers/PdfViewer.vue +562 -0
- package/src/viewers/PsdViewer.vue +264 -0
- package/src/viewers/TiffViewer.vue +273 -0
- package/src/viewers/Viewer3D.vue +120 -0
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* PsdViewer — Photoshop document preview via `ag-psd`.
|
|
4
|
+
*
|
|
5
|
+
* Lazy-imports `ag-psd` (~150 KB). Renders the flattened composite to
|
|
6
|
+
* a canvas via `psd.canvas`. A simple layer panel toggles the rendered
|
|
7
|
+
* preview (V1: just lists names + visibility; full composite swap on
|
|
8
|
+
* toggle requires re-rendering with `applyOpacity`/`composite` logic
|
|
9
|
+
* — left as TODO for V2 since `ag-psd` doesn't ship a composite
|
|
10
|
+
* pipeline of its own).
|
|
11
|
+
*/
|
|
12
|
+
import { onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
|
13
|
+
import { fetchViewerArrayBuffer } from '../composables/useViewerFetch';
|
|
14
|
+
|
|
15
|
+
const props = defineProps<{
|
|
16
|
+
url: string;
|
|
17
|
+
mime?: string;
|
|
18
|
+
ext: string;
|
|
19
|
+
t?: (key: string) => string;
|
|
20
|
+
authHeaders?: () => Record<string, string>;
|
|
21
|
+
authCredentials?: RequestCredentials;
|
|
22
|
+
}>();
|
|
23
|
+
|
|
24
|
+
interface FlatLayer {
|
|
25
|
+
index: number;
|
|
26
|
+
name: string;
|
|
27
|
+
hidden: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const canvasEl = ref<HTMLCanvasElement | null>(null);
|
|
31
|
+
const layers = ref<FlatLayer[]>([]);
|
|
32
|
+
const error = ref<string | null>(null);
|
|
33
|
+
const loading = ref(true);
|
|
34
|
+
const showLayerPanel = ref(false);
|
|
35
|
+
const dims = ref<{ width: number; height: number }>({ width: 0, height: 0 });
|
|
36
|
+
const scale = ref(1);
|
|
37
|
+
|
|
38
|
+
let renderToken = 0;
|
|
39
|
+
|
|
40
|
+
let agPsd: any = null;
|
|
41
|
+
async function ensureAgPsd(): Promise<any | null> {
|
|
42
|
+
if (agPsd) return agPsd;
|
|
43
|
+
try {
|
|
44
|
+
const mod = await import(/* @vite-ignore */ 'ag-psd');
|
|
45
|
+
agPsd = mod;
|
|
46
|
+
return agPsd;
|
|
47
|
+
} catch {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function flattenLayers(node: any, list: FlatLayer[]): void {
|
|
53
|
+
if (!node) return;
|
|
54
|
+
if (Array.isArray(node.children)) {
|
|
55
|
+
for (const child of node.children) {
|
|
56
|
+
list.push({
|
|
57
|
+
index: list.length,
|
|
58
|
+
name: child.name ?? '(unnamed)',
|
|
59
|
+
hidden: !!child.hidden,
|
|
60
|
+
});
|
|
61
|
+
if (child.children) flattenLayers(child, list);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function load(): Promise<void> {
|
|
67
|
+
loading.value = true;
|
|
68
|
+
error.value = null;
|
|
69
|
+
layers.value = [];
|
|
70
|
+
const myToken = ++renderToken;
|
|
71
|
+
|
|
72
|
+
const lib = await ensureAgPsd();
|
|
73
|
+
if (myToken !== renderToken) return;
|
|
74
|
+
if (!lib) {
|
|
75
|
+
error.value = props.t
|
|
76
|
+
? props.t('viewer.peer_not_installed')
|
|
77
|
+
: 'PSD viewer requires `ag-psd` — install or use download.';
|
|
78
|
+
loading.value = false;
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
try {
|
|
83
|
+
const buf = await fetchViewerArrayBuffer({
|
|
84
|
+
url: props.url,
|
|
85
|
+
headers: props.authHeaders?.() ?? {},
|
|
86
|
+
credentials: props.authCredentials,
|
|
87
|
+
});
|
|
88
|
+
if (myToken !== renderToken) return;
|
|
89
|
+
const psd = lib.readPsd(buf, {
|
|
90
|
+
skipLayerImageData: false,
|
|
91
|
+
skipCompositeImageData: false,
|
|
92
|
+
skipThumbnail: true,
|
|
93
|
+
});
|
|
94
|
+
dims.value = { width: psd.width, height: psd.height };
|
|
95
|
+
|
|
96
|
+
const composite = psd.canvas;
|
|
97
|
+
if (composite && canvasEl.value) {
|
|
98
|
+
const target = canvasEl.value;
|
|
99
|
+
target.width = psd.width;
|
|
100
|
+
target.height = psd.height;
|
|
101
|
+
const ctx = target.getContext('2d');
|
|
102
|
+
ctx?.drawImage(composite, 0, 0);
|
|
103
|
+
} else {
|
|
104
|
+
throw new Error('PSD has no composite image (skipCompositeImageData?)');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const flat: FlatLayer[] = [];
|
|
108
|
+
flattenLayers(psd, flat);
|
|
109
|
+
layers.value = flat;
|
|
110
|
+
} catch (err) {
|
|
111
|
+
error.value = err instanceof Error ? err.message : 'PSD decode failed';
|
|
112
|
+
} finally {
|
|
113
|
+
loading.value = false;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function zoomIn(): void {
|
|
118
|
+
scale.value = Math.min(8, scale.value * 1.25);
|
|
119
|
+
}
|
|
120
|
+
function zoomOut(): void {
|
|
121
|
+
scale.value = Math.max(0.1, scale.value / 1.25);
|
|
122
|
+
}
|
|
123
|
+
function reset(): void {
|
|
124
|
+
scale.value = 1;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
onMounted(load);
|
|
128
|
+
onBeforeUnmount(() => {
|
|
129
|
+
renderToken++;
|
|
130
|
+
});
|
|
131
|
+
watch(() => props.url, load);
|
|
132
|
+
|
|
133
|
+
function tt(key: string, fallback: string): string {
|
|
134
|
+
return props.t ? props.t(key) : fallback;
|
|
135
|
+
}
|
|
136
|
+
</script>
|
|
137
|
+
|
|
138
|
+
<template>
|
|
139
|
+
<div class="filex-viewer-psd">
|
|
140
|
+
<div class="filex-viewer-psd__pane">
|
|
141
|
+
<div v-if="error" class="filex-viewer-fallback">
|
|
142
|
+
<span class="filex-viewer-fallback__icon">🎨</span>
|
|
143
|
+
<p>{{ error }}</p>
|
|
144
|
+
</div>
|
|
145
|
+
<div v-else-if="loading" class="filex-viewer-fallback">
|
|
146
|
+
<span class="filex-viewer-fallback__icon">⏳</span>
|
|
147
|
+
<p>{{ tt('viewer.loading', 'Loading…') }}</p>
|
|
148
|
+
</div>
|
|
149
|
+
<canvas
|
|
150
|
+
v-show="!loading && !error"
|
|
151
|
+
ref="canvasEl"
|
|
152
|
+
/>
|
|
153
|
+
</div>
|
|
154
|
+
</div>
|
|
155
|
+
</template>
|
|
156
|
+
|
|
157
|
+
<style scoped>
|
|
158
|
+
.filex-viewer-psd {
|
|
159
|
+
display: flex;
|
|
160
|
+
flex-direction: column;
|
|
161
|
+
width: 100%;
|
|
162
|
+
height: 100%;
|
|
163
|
+
min-height: 70vh;
|
|
164
|
+
background: var(--fe-bg, #fff);
|
|
165
|
+
}
|
|
166
|
+
.filex-viewer-psd__bar {
|
|
167
|
+
display: flex;
|
|
168
|
+
align-items: center;
|
|
169
|
+
gap: 6px;
|
|
170
|
+
padding: 8px 12px;
|
|
171
|
+
background: var(--fe-bg-elev, #f7f8fa);
|
|
172
|
+
border-bottom: 1px solid var(--fe-border, #e2e6ed);
|
|
173
|
+
font-size: 13px;
|
|
174
|
+
}
|
|
175
|
+
.filex-viewer-spacer { flex: 1; }
|
|
176
|
+
.filex-viewer-psd__dim {
|
|
177
|
+
font-size: 12px;
|
|
178
|
+
color: var(--fe-text-muted, #5a6475);
|
|
179
|
+
}
|
|
180
|
+
.filex-viewer-psd__zoom {
|
|
181
|
+
min-width: 50px;
|
|
182
|
+
text-align: center;
|
|
183
|
+
font-variant-numeric: tabular-nums;
|
|
184
|
+
font-size: 12px;
|
|
185
|
+
}
|
|
186
|
+
.filex-viewer-psd__main {
|
|
187
|
+
flex: 1;
|
|
188
|
+
display: flex;
|
|
189
|
+
min-height: 0;
|
|
190
|
+
}
|
|
191
|
+
.filex-viewer-psd__layers {
|
|
192
|
+
width: 240px;
|
|
193
|
+
border-right: 1px solid var(--fe-border, #e2e6ed);
|
|
194
|
+
overflow-y: auto;
|
|
195
|
+
padding: 8px 0;
|
|
196
|
+
background: var(--fe-bg-elev, #f7f8fa);
|
|
197
|
+
}
|
|
198
|
+
.filex-viewer-psd__layers ul {
|
|
199
|
+
list-style: none;
|
|
200
|
+
margin: 0;
|
|
201
|
+
padding: 0;
|
|
202
|
+
}
|
|
203
|
+
.filex-viewer-psd__layers li {
|
|
204
|
+
display: flex;
|
|
205
|
+
align-items: center;
|
|
206
|
+
gap: 6px;
|
|
207
|
+
padding: 4px 12px;
|
|
208
|
+
font-size: 12px;
|
|
209
|
+
}
|
|
210
|
+
.filex-viewer-psd__layer-vis {
|
|
211
|
+
width: 14px;
|
|
212
|
+
text-align: center;
|
|
213
|
+
color: var(--fe-text-muted, #5a6475);
|
|
214
|
+
}
|
|
215
|
+
.filex-viewer-psd__layer-vis[data-hidden="1"] { color: var(--fe-border-strong, #c7ced9); }
|
|
216
|
+
.filex-viewer-psd__layer-name {
|
|
217
|
+
flex: 1;
|
|
218
|
+
white-space: nowrap;
|
|
219
|
+
overflow: hidden;
|
|
220
|
+
text-overflow: ellipsis;
|
|
221
|
+
}
|
|
222
|
+
.filex-viewer-psd__pane {
|
|
223
|
+
flex: 1;
|
|
224
|
+
overflow: auto;
|
|
225
|
+
padding: 16px;
|
|
226
|
+
background: #2a2d33;
|
|
227
|
+
display: flex;
|
|
228
|
+
align-items: flex-start;
|
|
229
|
+
justify-content: flex-start;
|
|
230
|
+
}
|
|
231
|
+
.filex-viewer-psd__pane canvas {
|
|
232
|
+
background: #fff
|
|
233
|
+
repeating-conic-gradient(#e0e0e0 0% 25%, transparent 0% 50%) 50% / 16px 16px;
|
|
234
|
+
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
|
|
235
|
+
}
|
|
236
|
+
.filex-viewer-fallback {
|
|
237
|
+
text-align: center;
|
|
238
|
+
padding: 32px;
|
|
239
|
+
color: #c8cdd6;
|
|
240
|
+
margin: auto;
|
|
241
|
+
}
|
|
242
|
+
.filex-viewer-fallback__icon {
|
|
243
|
+
font-size: 48px;
|
|
244
|
+
display: block;
|
|
245
|
+
margin-bottom: 12px;
|
|
246
|
+
}
|
|
247
|
+
.filex-viewer-btn {
|
|
248
|
+
border: 1px solid var(--fe-border, #e2e6ed);
|
|
249
|
+
background: var(--fe-bg, #fff);
|
|
250
|
+
color: var(--fe-text, #1a1e27);
|
|
251
|
+
padding: 4px 10px;
|
|
252
|
+
border-radius: 4px;
|
|
253
|
+
cursor: pointer;
|
|
254
|
+
font: inherit;
|
|
255
|
+
font-size: 12px;
|
|
256
|
+
}
|
|
257
|
+
.filex-viewer-btn:hover:not(:disabled) {
|
|
258
|
+
background: var(--fe-bg-hover, #edf0f5);
|
|
259
|
+
}
|
|
260
|
+
.filex-viewer-btn.is-active {
|
|
261
|
+
background: var(--fe-bg-selected, #dfe8ff);
|
|
262
|
+
border-color: var(--fe-primary, #3b82f6);
|
|
263
|
+
}
|
|
264
|
+
</style>
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* TiffViewer — multi-page TIFF preview via `utif`.
|
|
4
|
+
*
|
|
5
|
+
* Lazy-imports `utif` (~50 KB). Decodes IFDs once, paints the active
|
|
6
|
+
* page to a `<canvas>` via `UTIF.toRGBA8`. Page navigation (1/N) +
|
|
7
|
+
* zoom in/out controls. Browser <img> can't render TIFF natively, so
|
|
8
|
+
* the canvas pipeline is the only option short of server-side
|
|
9
|
+
* conversion.
|
|
10
|
+
*/
|
|
11
|
+
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
|
12
|
+
import { fetchViewerArrayBuffer } from '../composables/useViewerFetch';
|
|
13
|
+
|
|
14
|
+
const props = defineProps<{
|
|
15
|
+
url: string;
|
|
16
|
+
mime?: string;
|
|
17
|
+
ext: string;
|
|
18
|
+
t?: (key: string) => string;
|
|
19
|
+
authHeaders?: () => Record<string, string>;
|
|
20
|
+
authCredentials?: RequestCredentials;
|
|
21
|
+
}>();
|
|
22
|
+
|
|
23
|
+
const canvasEl = ref<HTMLCanvasElement | null>(null);
|
|
24
|
+
const error = ref<string | null>(null);
|
|
25
|
+
const loading = ref(true);
|
|
26
|
+
const scale = ref(1);
|
|
27
|
+
const pageIndex = ref(0);
|
|
28
|
+
const pageCount = ref(0);
|
|
29
|
+
const pageDims = ref<{ width: number; height: number }>({ width: 0, height: 0 });
|
|
30
|
+
|
|
31
|
+
let UTIF: any = null;
|
|
32
|
+
let ifds: any[] | null = null;
|
|
33
|
+
let renderToken = 0;
|
|
34
|
+
|
|
35
|
+
async function ensureUtif(): Promise<any | null> {
|
|
36
|
+
if (UTIF) return UTIF;
|
|
37
|
+
try {
|
|
38
|
+
const mod = await import(/* @vite-ignore */ 'utif');
|
|
39
|
+
UTIF = mod.default ?? mod;
|
|
40
|
+
return UTIF;
|
|
41
|
+
} catch {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function load(): Promise<void> {
|
|
47
|
+
loading.value = true;
|
|
48
|
+
error.value = null;
|
|
49
|
+
ifds = null;
|
|
50
|
+
pageIndex.value = 0;
|
|
51
|
+
pageCount.value = 0;
|
|
52
|
+
const myToken = ++renderToken;
|
|
53
|
+
|
|
54
|
+
const lib = await ensureUtif();
|
|
55
|
+
if (myToken !== renderToken) return;
|
|
56
|
+
if (!lib) {
|
|
57
|
+
error.value = props.t
|
|
58
|
+
? props.t('viewer.peer_not_installed')
|
|
59
|
+
: 'TIFF viewer requires `utif` — install or use download.';
|
|
60
|
+
loading.value = false;
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
const buf = await fetchViewerArrayBuffer({
|
|
66
|
+
url: props.url,
|
|
67
|
+
headers: props.authHeaders?.() ?? {},
|
|
68
|
+
credentials: props.authCredentials,
|
|
69
|
+
});
|
|
70
|
+
if (myToken !== renderToken) return;
|
|
71
|
+
ifds = lib.decode(buf);
|
|
72
|
+
pageCount.value = ifds?.length ?? 0;
|
|
73
|
+
if (pageCount.value === 0) {
|
|
74
|
+
throw new Error('No pages decoded');
|
|
75
|
+
}
|
|
76
|
+
paint();
|
|
77
|
+
} catch (err) {
|
|
78
|
+
error.value = err instanceof Error ? err.message : 'TIFF decode failed';
|
|
79
|
+
} finally {
|
|
80
|
+
loading.value = false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function paint(): void {
|
|
85
|
+
if (!UTIF || !ifds || !canvasEl.value) return;
|
|
86
|
+
const idx = Math.max(0, Math.min(pageIndex.value, ifds.length - 1));
|
|
87
|
+
const ifd = ifds[idx];
|
|
88
|
+
try {
|
|
89
|
+
UTIF.decodeImage(undefined, ifd);
|
|
90
|
+
} catch {
|
|
91
|
+
// some images already decoded — UTIF.decodeImage is idempotent on
|
|
92
|
+
// older versions.
|
|
93
|
+
}
|
|
94
|
+
const rgba = UTIF.toRGBA8(ifd);
|
|
95
|
+
const w = ifd.width;
|
|
96
|
+
const h = ifd.height;
|
|
97
|
+
pageDims.value = { width: w, height: h };
|
|
98
|
+
const canvas = canvasEl.value;
|
|
99
|
+
canvas.width = w;
|
|
100
|
+
canvas.height = h;
|
|
101
|
+
const ctx = canvas.getContext('2d');
|
|
102
|
+
if (!ctx) return;
|
|
103
|
+
const imageData = ctx.createImageData(w, h);
|
|
104
|
+
imageData.data.set(rgba);
|
|
105
|
+
ctx.putImageData(imageData, 0, 0);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function next(): void {
|
|
109
|
+
if (pageIndex.value < pageCount.value - 1) {
|
|
110
|
+
pageIndex.value++;
|
|
111
|
+
paint();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function prev(): void {
|
|
115
|
+
if (pageIndex.value > 0) {
|
|
116
|
+
pageIndex.value--;
|
|
117
|
+
paint();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function zoomIn(): void {
|
|
121
|
+
scale.value = Math.min(8, scale.value * 1.25);
|
|
122
|
+
}
|
|
123
|
+
function zoomOut(): void {
|
|
124
|
+
scale.value = Math.max(0.1, scale.value / 1.25);
|
|
125
|
+
}
|
|
126
|
+
function reset(): void {
|
|
127
|
+
scale.value = 1;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
onMounted(load);
|
|
131
|
+
onBeforeUnmount(() => {
|
|
132
|
+
renderToken++;
|
|
133
|
+
ifds = null;
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
watch(() => props.url, load);
|
|
137
|
+
|
|
138
|
+
const pageLabel = computed(() => {
|
|
139
|
+
const m = (props.t && props.t('viewer.page_n_of_m')) || 'Page {n} of {m}';
|
|
140
|
+
return m.replace('{n}', String(pageIndex.value + 1)).replace('{m}', String(pageCount.value));
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
function tt(key: string, fallback: string): string {
|
|
144
|
+
return props.t ? props.t(key) : fallback;
|
|
145
|
+
}
|
|
146
|
+
</script>
|
|
147
|
+
|
|
148
|
+
<template>
|
|
149
|
+
<div class="filex-viewer-tiff">
|
|
150
|
+
<div class="filex-viewer-tiff__pane">
|
|
151
|
+
<div v-if="error" class="filex-viewer-fallback">
|
|
152
|
+
<span class="filex-viewer-fallback__icon">🖼️</span>
|
|
153
|
+
<p>{{ error }}</p>
|
|
154
|
+
</div>
|
|
155
|
+
<div v-else-if="loading" class="filex-viewer-fallback">
|
|
156
|
+
<span class="filex-viewer-fallback__icon">⏳</span>
|
|
157
|
+
<p>{{ tt('viewer.loading', 'Loading…') }}</p>
|
|
158
|
+
</div>
|
|
159
|
+
<canvas
|
|
160
|
+
v-show="!loading && !error"
|
|
161
|
+
ref="canvasEl"
|
|
162
|
+
:style="{ imageRendering: 'pixelated' }"
|
|
163
|
+
/>
|
|
164
|
+
<div v-if="!loading && !error && pageCount > 1" class="filex-viewer-tiff__pager">
|
|
165
|
+
<button
|
|
166
|
+
type="button"
|
|
167
|
+
class="filex-viewer-btn"
|
|
168
|
+
:disabled="pageIndex === 0"
|
|
169
|
+
@click="prev"
|
|
170
|
+
>‹</button>
|
|
171
|
+
<span class="filex-viewer-tiff__pages">{{ pageLabel }}</span>
|
|
172
|
+
<button
|
|
173
|
+
type="button"
|
|
174
|
+
class="filex-viewer-btn"
|
|
175
|
+
:disabled="pageIndex >= pageCount - 1"
|
|
176
|
+
@click="next"
|
|
177
|
+
>›</button>
|
|
178
|
+
</div>
|
|
179
|
+
</div>
|
|
180
|
+
</div>
|
|
181
|
+
</template>
|
|
182
|
+
|
|
183
|
+
<style scoped>
|
|
184
|
+
.filex-viewer-tiff__pager {
|
|
185
|
+
position: absolute;
|
|
186
|
+
bottom: 12px;
|
|
187
|
+
left: 50%;
|
|
188
|
+
transform: translateX(-50%);
|
|
189
|
+
display: flex;
|
|
190
|
+
align-items: center;
|
|
191
|
+
gap: 8px;
|
|
192
|
+
padding: 4px 8px;
|
|
193
|
+
background: var(--fe-bg-elev, rgba(255, 255, 255, 0.9));
|
|
194
|
+
border: 1px solid var(--fe-border, #e2e6ed);
|
|
195
|
+
border-radius: 6px;
|
|
196
|
+
backdrop-filter: blur(4px);
|
|
197
|
+
}
|
|
198
|
+
.filex-viewer-tiff__pages {
|
|
199
|
+
font-size: 12px;
|
|
200
|
+
font-variant-numeric: tabular-nums;
|
|
201
|
+
}
|
|
202
|
+
.filex-viewer-tiff {
|
|
203
|
+
display: flex;
|
|
204
|
+
flex-direction: column;
|
|
205
|
+
width: 100%;
|
|
206
|
+
height: 100%;
|
|
207
|
+
min-height: 70vh;
|
|
208
|
+
background: var(--fe-bg, #fff);
|
|
209
|
+
}
|
|
210
|
+
.filex-viewer-tiff__bar {
|
|
211
|
+
display: flex;
|
|
212
|
+
align-items: center;
|
|
213
|
+
gap: 6px;
|
|
214
|
+
padding: 8px 12px;
|
|
215
|
+
background: var(--fe-bg-elev, #f7f8fa);
|
|
216
|
+
border-bottom: 1px solid var(--fe-border, #e2e6ed);
|
|
217
|
+
font-size: 13px;
|
|
218
|
+
}
|
|
219
|
+
.filex-viewer-tiff__pages {
|
|
220
|
+
min-width: 110px;
|
|
221
|
+
text-align: center;
|
|
222
|
+
font-variant-numeric: tabular-nums;
|
|
223
|
+
font-size: 12px;
|
|
224
|
+
}
|
|
225
|
+
.filex-viewer-tiff__zoom {
|
|
226
|
+
min-width: 50px;
|
|
227
|
+
text-align: center;
|
|
228
|
+
font-variant-numeric: tabular-nums;
|
|
229
|
+
font-size: 12px;
|
|
230
|
+
}
|
|
231
|
+
.filex-viewer-spacer { flex: 1; }
|
|
232
|
+
.filex-viewer-tiff__pane {
|
|
233
|
+
flex: 1;
|
|
234
|
+
overflow: auto;
|
|
235
|
+
padding: 16px;
|
|
236
|
+
background: #2a2d33;
|
|
237
|
+
display: flex;
|
|
238
|
+
align-items: flex-start;
|
|
239
|
+
justify-content: flex-start;
|
|
240
|
+
}
|
|
241
|
+
.filex-viewer-tiff__pane canvas {
|
|
242
|
+
background: #fff;
|
|
243
|
+
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
|
|
244
|
+
}
|
|
245
|
+
.filex-viewer-fallback {
|
|
246
|
+
text-align: center;
|
|
247
|
+
padding: 32px;
|
|
248
|
+
color: #c8cdd6;
|
|
249
|
+
margin: auto;
|
|
250
|
+
}
|
|
251
|
+
.filex-viewer-fallback__icon {
|
|
252
|
+
font-size: 48px;
|
|
253
|
+
display: block;
|
|
254
|
+
margin-bottom: 12px;
|
|
255
|
+
}
|
|
256
|
+
.filex-viewer-btn {
|
|
257
|
+
border: 1px solid var(--fe-border, #e2e6ed);
|
|
258
|
+
background: var(--fe-bg, #fff);
|
|
259
|
+
color: var(--fe-text, #1a1e27);
|
|
260
|
+
padding: 4px 10px;
|
|
261
|
+
border-radius: 4px;
|
|
262
|
+
cursor: pointer;
|
|
263
|
+
font: inherit;
|
|
264
|
+
font-size: 12px;
|
|
265
|
+
}
|
|
266
|
+
.filex-viewer-btn:hover:not(:disabled) {
|
|
267
|
+
background: var(--fe-bg-hover, #edf0f5);
|
|
268
|
+
}
|
|
269
|
+
.filex-viewer-btn:disabled {
|
|
270
|
+
opacity: 0.4;
|
|
271
|
+
cursor: not-allowed;
|
|
272
|
+
}
|
|
273
|
+
</style>
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* Viewer3D — 3D model preview via `@google/model-viewer`.
|
|
4
|
+
*
|
|
5
|
+
* Lazy-imports the `@google/model-viewer` web component (~80 KB).
|
|
6
|
+
*
|
|
7
|
+
* Format support: model-viewer **only** understands glTF (`.gltf`,
|
|
8
|
+
* `.glb`) and USDZ (iOS). For unsupported formats (`.stl`, `.obj`,
|
|
9
|
+
* `.fbx`, `.3ds`) we deliberately render a download fallback instead
|
|
10
|
+
* of feeding them to model-viewer — earlier code did the latter,
|
|
11
|
+
* which surfaced as `JSON.parse(<ascii STL>)` SyntaxError because
|
|
12
|
+
* model-viewer parses the response body as glTF JSON. (sweep-2026-05-09
|
|
13
|
+
* bugs 19-20.)
|
|
14
|
+
*
|
|
15
|
+
* GLB rendering size: model-viewer mounts its canvas inside a
|
|
16
|
+
* shadow root that doesn't always inherit `height: 100%` from
|
|
17
|
+
* flexbox parents — we pin explicit sizing on the host element
|
|
18
|
+
* to avoid the "Framebuffer is incomplete: zero size" warning.
|
|
19
|
+
* (sweep-2026-05-09 bug 21.)
|
|
20
|
+
*/
|
|
21
|
+
import { computed, onMounted, ref, watch } from 'vue';
|
|
22
|
+
|
|
23
|
+
const props = defineProps<{
|
|
24
|
+
url: string;
|
|
25
|
+
mime?: string;
|
|
26
|
+
ext: string;
|
|
27
|
+
/** Locale-aware error/loading messages. */
|
|
28
|
+
t?: (key: string) => string;
|
|
29
|
+
}>();
|
|
30
|
+
|
|
31
|
+
const SUPPORTED_EXTS = new Set(['glb', 'gltf', 'usdz']);
|
|
32
|
+
|
|
33
|
+
const isSupported = computed(() => SUPPORTED_EXTS.has((props.ext || '').toLowerCase()));
|
|
34
|
+
|
|
35
|
+
const error = ref<string | null>(null);
|
|
36
|
+
const ready = ref(false);
|
|
37
|
+
|
|
38
|
+
async function load(): Promise<void> {
|
|
39
|
+
ready.value = false;
|
|
40
|
+
error.value = null;
|
|
41
|
+
// Bail out early for formats model-viewer can't parse — feeding
|
|
42
|
+
// them to <model-viewer> triggers JSON.parse SyntaxError because
|
|
43
|
+
// it expects glTF JSON.
|
|
44
|
+
if (!isSupported.value) {
|
|
45
|
+
error.value = props.t
|
|
46
|
+
? props.t('viewer.format_unsupported_3d')
|
|
47
|
+
: `3D format ".${props.ext}" not supported in browser preview — please download.`;
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
await import(/* @vite-ignore */ '@google/model-viewer');
|
|
52
|
+
ready.value = true;
|
|
53
|
+
} catch {
|
|
54
|
+
error.value = props.t
|
|
55
|
+
? props.t('viewer.peer_not_installed')
|
|
56
|
+
: '3D viewer requires `@google/model-viewer` — install or use download.';
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
onMounted(load);
|
|
61
|
+
|
|
62
|
+
watch(() => props.url, () => {
|
|
63
|
+
// Re-evaluate on URL change (different file may need different
|
|
64
|
+
// fallback message).
|
|
65
|
+
load();
|
|
66
|
+
});
|
|
67
|
+
</script>
|
|
68
|
+
|
|
69
|
+
<template>
|
|
70
|
+
<div class="filex-viewer-3d">
|
|
71
|
+
<model-viewer
|
|
72
|
+
v-if="ready && !error"
|
|
73
|
+
:src="url"
|
|
74
|
+
auto-rotate
|
|
75
|
+
camera-controls
|
|
76
|
+
touch-action="pan-y"
|
|
77
|
+
shadow-intensity="1"
|
|
78
|
+
:alt="ext + ' model'"
|
|
79
|
+
style="width: 100%; height: 100%; min-height: 480px; display: block"
|
|
80
|
+
/>
|
|
81
|
+
<div v-else-if="error" class="filex-viewer-fallback">
|
|
82
|
+
<span class="filex-viewer-fallback__icon">📦</span>
|
|
83
|
+
<p>{{ error }}</p>
|
|
84
|
+
</div>
|
|
85
|
+
<div v-else class="filex-viewer-fallback">
|
|
86
|
+
<span class="filex-viewer-fallback__icon">⏳</span>
|
|
87
|
+
<p>{{ t ? t('viewer.loading') : 'Loading…' }}</p>
|
|
88
|
+
</div>
|
|
89
|
+
</div>
|
|
90
|
+
</template>
|
|
91
|
+
|
|
92
|
+
<style scoped>
|
|
93
|
+
.filex-viewer-3d {
|
|
94
|
+
width: 100%;
|
|
95
|
+
height: 100%;
|
|
96
|
+
min-height: 480px;
|
|
97
|
+
background: #1a1a1a;
|
|
98
|
+
display: flex;
|
|
99
|
+
align-items: center;
|
|
100
|
+
justify-content: center;
|
|
101
|
+
}
|
|
102
|
+
.filex-viewer-3d :deep(model-viewer) {
|
|
103
|
+
width: 100%;
|
|
104
|
+
height: 100%;
|
|
105
|
+
min-height: 480px;
|
|
106
|
+
background: #1a1a1a;
|
|
107
|
+
display: block;
|
|
108
|
+
}
|
|
109
|
+
.filex-viewer-fallback {
|
|
110
|
+
text-align: center;
|
|
111
|
+
color: #c8cdd6;
|
|
112
|
+
padding: 32px;
|
|
113
|
+
max-width: 480px;
|
|
114
|
+
}
|
|
115
|
+
.filex-viewer-fallback__icon {
|
|
116
|
+
font-size: 48px;
|
|
117
|
+
display: block;
|
|
118
|
+
margin-bottom: 12px;
|
|
119
|
+
}
|
|
120
|
+
</style>
|