@jt-home/mfe-components 1.0.4 → 1.0.6

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.
@@ -0,0 +1,751 @@
1
+ import { defineComponent as L, openBlock as O, createElementBlock as I, createElementVNode as J, ref as x, watch as q, onBeforeUnmount as T, h as n, computed as D, onMounted as W, nextTick as ae, render as A } from "vue";
2
+ import { ElIcon as N } from "element-plus";
3
+ /*! Element Plus Icons Vue v2.3.2 */
4
+ var re = /* @__PURE__ */ L({
5
+ name: "Download",
6
+ __name: "download",
7
+ setup(e) {
8
+ return (t, a) => (O(), I("svg", {
9
+ xmlns: "http://www.w3.org/2000/svg",
10
+ viewBox: "0 0 1024 1024"
11
+ }, [
12
+ J("path", {
13
+ fill: "currentColor",
14
+ d: "M160 832h704a32 32 0 1 1 0 64H160a32 32 0 1 1 0-64m384-253.696 236.288-236.352 45.248 45.248L508.8 704 192 387.2l45.248-45.248L480 584.704V128h64z"
15
+ })
16
+ ]));
17
+ }
18
+ }), ie = re, oe = /* @__PURE__ */ L({
19
+ name: "RefreshLeft",
20
+ __name: "refresh-left",
21
+ setup(e) {
22
+ return (t, a) => (O(), I("svg", {
23
+ xmlns: "http://www.w3.org/2000/svg",
24
+ viewBox: "0 0 1024 1024"
25
+ }, [
26
+ J("path", {
27
+ fill: "currentColor",
28
+ d: "M289.088 296.704h92.992a32 32 0 0 1 0 64H232.96a32 32 0 0 1-32-32V179.712a32 32 0 0 1 64 0v50.56a384 384 0 0 1 643.84 282.88 384 384 0 0 1-383.936 384 384 384 0 0 1-384-384h64a320 320 0 1 0 640 0 320 320 0 0 0-555.712-216.448z"
29
+ })
30
+ ]));
31
+ }
32
+ }), ce = oe, se = /* @__PURE__ */ L({
33
+ name: "ZoomIn",
34
+ __name: "zoom-in",
35
+ setup(e) {
36
+ return (t, a) => (O(), I("svg", {
37
+ xmlns: "http://www.w3.org/2000/svg",
38
+ viewBox: "0 0 1024 1024"
39
+ }, [
40
+ J("path", {
41
+ fill: "currentColor",
42
+ d: "m795.904 750.72 124.992 124.928a32 32 0 0 1-45.248 45.248L750.656 795.904a416 416 0 1 1 45.248-45.248zM480 832a352 352 0 1 0 0-704 352 352 0 0 0 0 704m-32-384v-96a32 32 0 0 1 64 0v96h96a32 32 0 0 1 0 64h-96v96a32 32 0 0 1-64 0v-96h-96a32 32 0 0 1 0-64z"
43
+ })
44
+ ]));
45
+ }
46
+ }), le = se, ue = /* @__PURE__ */ L({
47
+ name: "ZoomOut",
48
+ __name: "zoom-out",
49
+ setup(e) {
50
+ return (t, a) => (O(), I("svg", {
51
+ xmlns: "http://www.w3.org/2000/svg",
52
+ viewBox: "0 0 1024 1024"
53
+ }, [
54
+ J("path", {
55
+ fill: "currentColor",
56
+ d: "m795.904 750.72 124.992 124.928a32 32 0 0 1-45.248 45.248L750.656 795.904a416 416 0 1 1 45.248-45.248zM480 832a352 352 0 1 0 0-704 352 352 0 0 0 0 704M352 448h256a32 32 0 0 1 0 64H352a32 32 0 0 1 0-64"
57
+ })
58
+ ]));
59
+ }
60
+ }), de = ue;
61
+ const ve = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAANgAAADYCAMAAAC+/t3fAAAAaVBMVEUAAABWapNVapKeqsLJztx3hKnGzN2yu8////9XapWcqMGps8lXapVYa5RWaZWps8lfcJjS1+KjrsVXapWapr////9sfaKrtMrV2uWBj7B4iKqWob1wgaXr7fOBj6/Ax9dhc5yhq8OKl7Wba+6tAAAAE3RSTlMAgGDuDyVLoYDe2XuXRb68cy6e4BCQEAAAAyZJREFUeNrt29tyokAUheGOQjIoeMhuCQ4e0Pd/yCE1STU4mGq7bXqzZ/23ufoqYblTqkIIIYQQQggNlM42Lzctf5nMD22bKQYVOQ30sTPt6dEO74mKXLoiCgDTi1RFbUMUBhZXluQUDKbnWxWtjMLB2pYqUjmFg8WUzSg0TL+rCKVZeJheRJj9DYWHRRnHbBSYnr+qcSsoKCyeLKcfK/emc2UqH4LFGMcVWV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lBjFosoMHeCuUj3AgILjTSmMqLAHk00pk2DwHjS8Uz9QYGF5hnzN0OB7cYpdfKoKyCw1sRCGVJAUGCyW+MsI/o0CKyVDiGiNKA0gsDkMG+w38sCdQQF5o7Vok63ZRiwcEbkKxlHehcUmFPLDrFkXEOW5L4/vaWlMtnBgBVdA+N2kOW6yuYnIymQDgosGSt7dtOHcZXOAYHta30L+09luteBwMR+xzJ/KNO9DgTG+wVwh0xt61BgojZTTdb1MILA+NViikO68tiXgsDE6sMcxNsEv4Ra+Jm5rOKsQwYgMJ7OzTmWxb2r7jK3izdc2OmGxTX56871WMsciTg8YGGHG/ZUKcS2BI7y9/5j7SsnrXJLjW0otqIbBQisvG5NEiLRxYSl6w4KzE1m3FLonPCG5ugnCLBoN6qUmXQ0Ta/5MWAx+wuVjv1L+K/xHgNmspxSqbAuMcL0DAaMxRopCn2UWPJj+3/NJutXiYGAWaxUI/0qkbndKQhYXJTK50j9wYDF7Me+LQKBVWc2of5gwNis1kzdAYGt3nIJdQcDFpM9DTF1BgQ2u1fja2dAYMHbLqHOgMDCsW352w8iCKweWDHffhBBYOyba2Nabz+IKDB3eFk+36+IILDQXPlQRnpdKLC0d+W9sjMoMN8kJY04woEC+6kbJY05dIMC86OPSaHA0ugREQWWR7tQYP/atZcUBmEoCsNHA4FEBxHvyKJQ7P7X2EGdlHbiNYNjON8OfvIkZP2Zi9tqV7CE2V77TyxL2PdkXJ52GUuYvZbKL1IsYcfr9GPbq2WxhJ2gMIUpTGEcFKYwEgpTGAmFKYyEwhRGQmEKI+EJy3YDCeeNdgOesMH4ZTgk4zfAoxi9GR6dsctwCfRD1sNnNm7HCmtuY8wRH42dZSXCL/CW5QQcmtoax4iLIuOglQkVpIHrPlzGPqCSNE8diT4FiIiIiIjIP2/v9e/hKQXqEwAAAABJRU5ErkJggg==", fe = /* @__PURE__ */ new Set(["jpg", "jpeg", "png", "gif", "webp", "bmp", "svg", "avif", "ico"]), we = /* @__PURE__ */ new Set(["mp4", "webm", "ogg", "ogv", "mov", "m4v"]), pe = /* @__PURE__ */ new Set(["mp3", "wav", "ogg", "oga", "m4a", "aac", "flac"]), he = /* @__PURE__ */ new Set(["html", "htm", "txt", "json", "xml", "csv", "md", "log"]), ge = /* @__PURE__ */ new Set([
62
+ "doc",
63
+ "docx",
64
+ "xls",
65
+ "xlsx",
66
+ "ppt",
67
+ "pptx",
68
+ "zip",
69
+ "rar",
70
+ "7z"
71
+ ]);
72
+ let _ = null, U = null, P = null;
73
+ async function ye() {
74
+ return U || (U = Promise.all([
75
+ import("../pdf-BmBuG7of.js"),
76
+ import("../pdf.worker.min-4PI-nNLo.js")
77
+ ]).then(([e, t]) => (e.GlobalWorkerOptions.workerSrc = t.default, e))), U;
78
+ }
79
+ function Ae(e) {
80
+ return typeof e == "string" ? { url: e } : e;
81
+ }
82
+ function V(e) {
83
+ const [t] = e.split(/[?#]/);
84
+ return t ?? "";
85
+ }
86
+ function z(e, t) {
87
+ if (t?.trim()) return t.trim();
88
+ const a = V(e).split("/").filter(Boolean).pop();
89
+ if (!a) return "附件预览";
90
+ try {
91
+ return decodeURIComponent(a);
92
+ } catch {
93
+ return a;
94
+ }
95
+ }
96
+ function F(e) {
97
+ return V(e).match(/\.([a-z0-9]+)$/i)?.[1]?.toLowerCase() ?? "";
98
+ }
99
+ function K(e) {
100
+ const t = e.toLowerCase().split(";")[0]?.trim() ?? "";
101
+ return t.startsWith("image/") ? "image" : t === "application/pdf" ? "pdf" : t.startsWith("video/") ? "video" : t.startsWith("audio/") ? "audio" : t.startsWith("text/") ? "iframe" : "unknown";
102
+ }
103
+ function X(e) {
104
+ if (!e.url.trim()) return "empty";
105
+ if (e.mode && e.mode !== "auto") return e.mode;
106
+ if (e.mimeType) {
107
+ const a = K(e.mimeType);
108
+ if (a !== "unknown") return a;
109
+ }
110
+ const t = F(e.url);
111
+ return fe.has(t) ? "image" : t === "pdf" ? "pdf" : we.has(t) ? "video" : pe.has(t) ? "audio" : he.has(t) ? "iframe" : ge.has(t) ? "unsupported" : "unknown";
112
+ }
113
+ async function _e(e) {
114
+ try {
115
+ const a = (await fetch(e, { method: "HEAD" })).headers.get("content-type") ?? "";
116
+ return K(a);
117
+ } catch {
118
+ return "unknown";
119
+ }
120
+ }
121
+ async function Z(e) {
122
+ const t = await fetch(e);
123
+ if (!t.ok) throw new Error(`fetch failed: ${t.status}`);
124
+ return t.blob();
125
+ }
126
+ function be(e, t) {
127
+ const a = F(t);
128
+ return a === "doc" || a === "docx" ? "W" : a === "xls" || a === "xlsx" ? "X" : a === "ppt" || a === "pptx" ? "P" : a === "zip" || a === "rar" || a === "7z" ? "ZIP" : e === "pdf" ? "PDF" : "FILE";
129
+ }
130
+ function $(e, t, a) {
131
+ return n(
132
+ "button",
133
+ {
134
+ class: a,
135
+ type: "button",
136
+ onClick: () => {
137
+ te(e, t);
138
+ }
139
+ },
140
+ [
141
+ n(N, { class: "jt-attachment-preview-service__download-icon" }, () => n(ie)),
142
+ n("span", { class: "jt-attachment-preview-service__download-text" }, "下载")
143
+ ]
144
+ );
145
+ }
146
+ function R(e) {
147
+ return e === "image" || e === "pdf";
148
+ }
149
+ function ee(e) {
150
+ return n("div", { class: "jt-attachment-preview-service__preview-fallback" }, [
151
+ n("img", {
152
+ class: "jt-attachment-preview-service__preview-fallback-icon",
153
+ src: e.icon,
154
+ alt: ""
155
+ }),
156
+ n("div", { class: "jt-attachment-preview-service__unsupported-text" }, "暂不支持预览此类型的文件"),
157
+ n("div", { class: "jt-attachment-preview-service__file-name", title: e.name }, e.name)
158
+ ]);
159
+ }
160
+ function H(e, t) {
161
+ const a = document.createElement("a");
162
+ a.href = e, a.download = t, a.style.display = "none", document.body.appendChild(a), a.click(), a.remove();
163
+ }
164
+ async function te(e, t) {
165
+ try {
166
+ const a = await Z(e), i = URL.createObjectURL(a);
167
+ H(i, t), URL.revokeObjectURL(i);
168
+ } catch {
169
+ H(e, t);
170
+ }
171
+ }
172
+ const je = L({
173
+ name: "JtAttachmentPreviewPdfCanvas",
174
+ props: {
175
+ url: {
176
+ type: String,
177
+ required: !0
178
+ },
179
+ name: {
180
+ type: String,
181
+ required: !0
182
+ },
183
+ downloadName: {
184
+ type: String,
185
+ required: !0
186
+ },
187
+ downloadable: {
188
+ type: Boolean,
189
+ required: !0
190
+ }
191
+ },
192
+ emits: {
193
+ previewLoad: (e) => e instanceof Event,
194
+ previewError: (e) => e instanceof Event
195
+ },
196
+ setup(e, { emit: t }) {
197
+ const a = x("loading"), i = x([]), r = x([]), s = /* @__PURE__ */ new Map(), l = x("");
198
+ let d = null, h = [], v = 0;
199
+ async function m(o, u) {
200
+ if (!u) return null;
201
+ const w = typeof u == "string" ? await o.getDestination(u) : u;
202
+ return !Array.isArray(w) || !w[0] ? null : await o.getPageIndex(w[0]) + 1;
203
+ }
204
+ async function k(o, u, w = 0) {
205
+ if (!u?.length) return [];
206
+ const j = [];
207
+ for (const E of u) {
208
+ const C = await m(o, E.dest);
209
+ j.push({
210
+ title: E.title || "未命名标题",
211
+ pageNumber: C,
212
+ level: w
213
+ });
214
+ const g = await k(o, E.items, w + 1);
215
+ j.push(...g);
216
+ }
217
+ return j;
218
+ }
219
+ function p() {
220
+ v += 1;
221
+ for (const o of h)
222
+ o.cancel();
223
+ h = [], d?.destroy(), d = null, s.clear();
224
+ }
225
+ async function b() {
226
+ p();
227
+ const o = v;
228
+ a.value = "loading", l.value = "", i.value = [], r.value = [];
229
+ try {
230
+ const u = await ye();
231
+ if (o !== v) return;
232
+ d = u.getDocument({ url: e.url });
233
+ const w = await d.promise;
234
+ if (o !== v) return;
235
+ i.value = Array.from({ length: w.numPages }, (C, g) => g + 1), r.value = await k(w, await w.getOutline()), await ae();
236
+ const j = s.values().next().value, E = Math.max((j?.parentElement?.clientWidth ?? 800) - 32, 320);
237
+ for (const C of i.value) {
238
+ if (o !== v) return;
239
+ const g = await w.getPage(C), y = s.get(C), M = y?.getContext("2d");
240
+ if (!y || !M) continue;
241
+ const G = g.getViewport({ scale: 1 }), S = Math.min(E / G.width, 2), c = g.getViewport({ scale: S }), B = window.devicePixelRatio || 1;
242
+ y.width = Math.floor(c.width * B), y.height = Math.floor(c.height * B), y.style.width = `${Math.floor(c.width)}px`, y.style.height = `${Math.floor(c.height)}px`, M.setTransform(B, 0, 0, B, 0, 0);
243
+ const Q = g.render({
244
+ canvas: y,
245
+ canvasContext: M,
246
+ viewport: c
247
+ });
248
+ h.push(Q), await Q.promise;
249
+ }
250
+ if (o !== v) return;
251
+ a.value = "ready", t("previewLoad", new Event("load"));
252
+ } catch (u) {
253
+ if (o !== v) return;
254
+ a.value = "error", l.value = u instanceof Error ? u.message : "PDF 加载失败", t("previewError", new Event("error"));
255
+ }
256
+ }
257
+ q(() => e.url, b, { immediate: !0 }), T(p);
258
+ function f(o) {
259
+ if (!o) return;
260
+ s.get(o)?.scrollIntoView({ behavior: "smooth", block: "start" });
261
+ }
262
+ return () => n("div", { class: "jt-attachment-preview-service__pdf-viewer" }, [
263
+ a.value === "loading" ? n("div", { class: "jt-attachment-preview-service__pdf-state" }, "PDF 加载中...") : null,
264
+ a.value === "error" ? n("div", { class: "jt-attachment-preview-service__pdf-state" }, [
265
+ ee({
266
+ icon: me,
267
+ name: e.name
268
+ })
269
+ ]) : null,
270
+ null,
271
+ null,
272
+ n(
273
+ "div",
274
+ {
275
+ class: [
276
+ "jt-attachment-preview-service__pdf-layout",
277
+ a.value !== "ready" ? "jt-attachment-preview-service__pdf-layout--hidden" : ""
278
+ ]
279
+ },
280
+ [
281
+ r.value.length ? n("aside", { class: "jt-attachment-preview-service__pdf-outline" }, [
282
+ n("div", { class: "jt-attachment-preview-service__pdf-outline-title" }, "目录"),
283
+ n(
284
+ "div",
285
+ { class: "jt-attachment-preview-service__pdf-outline-list" },
286
+ r.value.map(
287
+ (o, u) => n(
288
+ "button",
289
+ {
290
+ key: `${o.title}-${u}`,
291
+ class: "jt-attachment-preview-service__pdf-outline-item",
292
+ style: { paddingLeft: `${12 + o.level * 14}px` },
293
+ type: "button",
294
+ disabled: !o.pageNumber,
295
+ title: o.title,
296
+ onClick: () => f(o.pageNumber)
297
+ },
298
+ o.title
299
+ )
300
+ )
301
+ )
302
+ ]) : null,
303
+ n(
304
+ "div",
305
+ { class: "jt-attachment-preview-service__pdf-pages" },
306
+ i.value.map(
307
+ (o) => n("canvas", {
308
+ key: o,
309
+ ref: (u) => {
310
+ u instanceof HTMLCanvasElement && s.set(o, u);
311
+ },
312
+ class: "jt-attachment-preview-service__pdf-page"
313
+ })
314
+ )
315
+ )
316
+ ]
317
+ )
318
+ ]);
319
+ }
320
+ }), Ee = L({
321
+ name: "JtAttachmentPreviewImageTransform",
322
+ props: {
323
+ url: {
324
+ type: String,
325
+ required: !0
326
+ },
327
+ name: {
328
+ type: String,
329
+ required: !0
330
+ },
331
+ downloadName: {
332
+ type: String,
333
+ required: !0
334
+ },
335
+ downloadable: {
336
+ type: Boolean,
337
+ required: !0
338
+ },
339
+ fit: {
340
+ type: String,
341
+ default: "contain"
342
+ }
343
+ },
344
+ emits: {
345
+ previewLoad: (e) => e instanceof Event,
346
+ previewError: (e) => e instanceof Event
347
+ },
348
+ setup(e, { emit: t }) {
349
+ const a = x(null), i = x("ready"), r = x(1), s = x(!1);
350
+ let l = 0, d = 0, h = 0, v = 0, m = 0, k = 0, p = 0;
351
+ const b = D(() => ({
352
+ "--jt-attachment-preview-service-image-fit": e.fit,
353
+ transform: `translate(${l}px, ${d}px) scale(${r.value})`
354
+ }));
355
+ function f() {
356
+ a.value && (a.value.style.transform = `translate(${l}px, ${d}px) scale(${r.value})`);
357
+ }
358
+ function o() {
359
+ p || (p = window.requestAnimationFrame(() => {
360
+ p = 0, f();
361
+ }));
362
+ }
363
+ function u(c) {
364
+ r.value = Math.min(Math.max(Number(c.toFixed(2)), 0.2), 5), r.value <= 1 && (l = 0, d = 0), f();
365
+ }
366
+ function w() {
367
+ u(r.value + 0.2);
368
+ }
369
+ function j() {
370
+ const c = Math.max(Number((r.value - 0.2).toFixed(2)), 0.2);
371
+ r.value = c, c <= 1 && (l = 0, d = 0), f();
372
+ }
373
+ function E() {
374
+ l = 0, d = 0, u(1);
375
+ }
376
+ function C(c) {
377
+ i.value = "ready", t("previewLoad", c);
378
+ }
379
+ function g(c) {
380
+ i.value = "error", t("previewError", c);
381
+ }
382
+ function y(c) {
383
+ r.value <= 1 || (c.preventDefault(), s.value = !0, h = c.clientX, v = c.clientY, m = l, k = d, window.addEventListener("pointermove", M), window.addEventListener("pointerup", G, { once: !0 }));
384
+ }
385
+ function M(c) {
386
+ s.value && (l = m + c.clientX - h, d = k + c.clientY - v, o());
387
+ }
388
+ function G() {
389
+ s.value = !1, window.removeEventListener("pointermove", M);
390
+ }
391
+ function S(c) {
392
+ c.preventDefault(), u(r.value + (c.deltaY < 0 ? 0.1 : -0.1));
393
+ }
394
+ return W(f), q(() => e.url, () => {
395
+ i.value = "ready", E();
396
+ }), T(() => {
397
+ window.removeEventListener("pointermove", M), p && window.cancelAnimationFrame(p);
398
+ }), () => n("div", { class: "jt-attachment-preview-service__image-viewer" }, i.value === "error" ? ee({
399
+ icon: ve,
400
+ name: e.name
401
+ }) : [
402
+ n("img", {
403
+ ref: a,
404
+ class: [
405
+ "jt-attachment-preview-service__media",
406
+ "jt-attachment-preview-service__image",
407
+ r.value > 1 ? "jt-attachment-preview-service__image--draggable" : "",
408
+ s.value ? "jt-attachment-preview-service__image--dragging" : ""
409
+ ],
410
+ src: e.url,
411
+ alt: e.name,
412
+ style: b.value,
413
+ onLoad: C,
414
+ onError: g,
415
+ onPointerdown: y,
416
+ onWheel: S,
417
+ onDragstart: (c) => c.preventDefault(),
418
+ draggable: !1
419
+ }),
420
+ n("div", { class: "jt-attachment-preview-service__image-toolbar" }, [
421
+ n(
422
+ "button",
423
+ {
424
+ class: "jt-attachment-preview-service__image-tool",
425
+ type: "button",
426
+ title: "缩小",
427
+ onClick: j
428
+ },
429
+ [n(N, () => n(de))]
430
+ ),
431
+ n("span", { class: "jt-attachment-preview-service__image-scale" }, `${Math.round(r.value * 100)}%`),
432
+ n(
433
+ "button",
434
+ {
435
+ class: "jt-attachment-preview-service__image-tool",
436
+ type: "button",
437
+ title: "放大",
438
+ onClick: w
439
+ },
440
+ [n(N, () => n(le))]
441
+ ),
442
+ n(
443
+ "button",
444
+ {
445
+ class: "jt-attachment-preview-service__image-tool",
446
+ type: "button",
447
+ title: "复位",
448
+ onClick: E
449
+ },
450
+ [n(N, () => n(ce))]
451
+ )
452
+ ])
453
+ ]);
454
+ }
455
+ }), De = L({
456
+ name: "JtAttachmentPreviewService",
457
+ props: {
458
+ options: {
459
+ type: Object,
460
+ required: !0
461
+ },
462
+ onDestroy: {
463
+ type: Function,
464
+ required: !0
465
+ }
466
+ },
467
+ setup(e) {
468
+ const t = D(() => z(e.options.url, e.options.name)), a = D(() => e.options.downloadName || t.value), i = D(() => X(e.options)), r = D(() => be(i.value, e.options.url)), s = D(() => ({
469
+ zIndex: e.options.zIndex ?? 3e3,
470
+ "--jt-attachment-preview-service-image-fit": e.options.fit ?? "contain"
471
+ }));
472
+ function l() {
473
+ e.options.onClose?.(), e.onDestroy();
474
+ }
475
+ function d(m) {
476
+ m.key === "Escape" && e.options.closeOnPressEscape !== !1 && l();
477
+ }
478
+ function h(m) {
479
+ e.options.onLoad?.(m);
480
+ }
481
+ function v(m) {
482
+ e.options.onError?.(m);
483
+ }
484
+ return W(() => {
485
+ document.addEventListener("keydown", d), document.body.classList.add("jt-attachment-preview-service-lock");
486
+ }), T(() => {
487
+ document.removeEventListener("keydown", d), document.body.classList.remove("jt-attachment-preview-service-lock");
488
+ }), () => {
489
+ const m = e.options.downloadable === !1 ? [] : [$(e.options.url, a.value, "jt-attachment-preview-service__top-download")];
490
+ return n("div", { class: "jt-attachment-preview-service", style: s.value }, [
491
+ n("div", { class: "jt-attachment-preview-service__modal" }, [
492
+ n("div", { class: "jt-attachment-preview-service__header" }, [
493
+ n("div", { class: "jt-attachment-preview-service__filename", title: t.value }, t.value),
494
+ n("div", { class: "jt-attachment-preview-service__header-actions" }, [
495
+ ...m,
496
+ n(
497
+ "button",
498
+ {
499
+ class: "jt-attachment-preview-service__close",
500
+ type: "button",
501
+ "aria-label": "关闭",
502
+ onClick: l
503
+ },
504
+ "×"
505
+ )
506
+ ])
507
+ ]),
508
+ n("div", { class: "jt-attachment-preview-service__body" }, [
509
+ xe({
510
+ type: i.value,
511
+ url: e.options.url,
512
+ name: t.value,
513
+ downloadName: a.value,
514
+ sandbox: e.options.sandbox,
515
+ iconText: r.value,
516
+ downloadable: e.options.downloadable !== !1,
517
+ onLoad: h,
518
+ onError: v
519
+ })
520
+ ])
521
+ ])
522
+ ]);
523
+ };
524
+ }
525
+ }), Y = L({
526
+ name: "JtAttachmentPreviewDetectingService",
527
+ props: {
528
+ options: {
529
+ type: Object,
530
+ required: !0
531
+ },
532
+ onDestroy: {
533
+ type: Function,
534
+ required: !0
535
+ },
536
+ title: {
537
+ type: String,
538
+ default: "正在识别文件类型"
539
+ },
540
+ desc: {
541
+ type: String,
542
+ default: "请稍候,识别完成后将自动预览或下载"
543
+ },
544
+ spinning: {
545
+ type: Boolean,
546
+ default: !0
547
+ }
548
+ },
549
+ setup(e) {
550
+ const t = D(() => z(e.options.url, e.options.name)), a = D(() => ({
551
+ zIndex: e.options.zIndex ?? 3e3
552
+ }));
553
+ function i() {
554
+ e.options.onClose?.(), e.onDestroy();
555
+ }
556
+ function r(s) {
557
+ s.key === "Escape" && e.options.closeOnPressEscape !== !1 && i();
558
+ }
559
+ return W(() => {
560
+ document.addEventListener("keydown", r), document.body.classList.add("jt-attachment-preview-service-lock");
561
+ }), T(() => {
562
+ document.removeEventListener("keydown", r), document.body.classList.remove("jt-attachment-preview-service-lock");
563
+ }), () => n("div", { class: "jt-attachment-preview-service", style: a.value }, [
564
+ n("div", { class: "jt-attachment-preview-service__modal" }, [
565
+ n("div", { class: "jt-attachment-preview-service__header" }, [
566
+ n("div", { class: "jt-attachment-preview-service__filename", title: t.value }, t.value),
567
+ n("div", { class: "jt-attachment-preview-service__header-actions" }, [
568
+ n(
569
+ "button",
570
+ {
571
+ class: "jt-attachment-preview-service__close",
572
+ type: "button",
573
+ "aria-label": "关闭",
574
+ onClick: i
575
+ },
576
+ "×"
577
+ )
578
+ ])
579
+ ]),
580
+ n("div", { class: "jt-attachment-preview-service__body" }, [
581
+ n("div", { class: "jt-attachment-preview-service__detecting" }, [
582
+ e.spinning ? n("span", { class: "jt-attachment-preview-service__detecting-spinner" }) : null,
583
+ n("span", { class: "jt-attachment-preview-service__detecting-title" }, e.title),
584
+ n("span", { class: "jt-attachment-preview-service__detecting-desc" }, e.desc)
585
+ ])
586
+ ])
587
+ ])
588
+ ]);
589
+ }
590
+ });
591
+ function xe(e) {
592
+ return e.type === "empty" ? n("div", { class: "jt-attachment-preview-service__empty" }, "暂无附件") : e.type === "image" ? n(Ee, {
593
+ url: e.url,
594
+ name: e.name,
595
+ downloadName: e.downloadName,
596
+ downloadable: e.downloadable,
597
+ onPreviewLoad: e.onLoad,
598
+ onPreviewError: e.onError
599
+ }) : e.type === "video" ? n("video", {
600
+ class: "jt-attachment-preview-service__media",
601
+ src: e.url,
602
+ controls: !0,
603
+ onLoadeddata: e.onLoad,
604
+ onError: e.onError
605
+ }) : e.type === "audio" ? n("audio", {
606
+ class: "jt-attachment-preview-service__audio",
607
+ src: e.url,
608
+ controls: !0,
609
+ onLoadeddata: e.onLoad,
610
+ onError: e.onError
611
+ }) : e.type === "pdf" ? n(je, {
612
+ url: e.url,
613
+ name: e.name,
614
+ downloadName: e.downloadName,
615
+ downloadable: e.downloadable,
616
+ onPreviewLoad: e.onLoad,
617
+ onPreviewError: e.onError
618
+ }) : e.type === "iframe" ? n("iframe", {
619
+ class: "jt-attachment-preview-service__iframe",
620
+ src: e.url,
621
+ title: e.name,
622
+ sandbox: e.sandbox || void 0,
623
+ onLoad: e.onLoad
624
+ }) : n("div", { class: "jt-attachment-preview-service__unsupported" }, [
625
+ n("div", { class: "jt-attachment-preview-service__file-card" }, [
626
+ n("div", { class: "jt-attachment-preview-service__file-icon" }, e.iconText),
627
+ n("div", { class: "jt-attachment-preview-service__unsupported-text" }, "暂不支持预览此类型的文件")
628
+ ]),
629
+ n("div", { class: "jt-attachment-preview-service__file-name", title: e.name }, e.name),
630
+ e.downloadable ? $(e.url, e.downloadName, "jt-attachment-preview-service__primary-download") : null
631
+ ]);
632
+ }
633
+ function ne(e) {
634
+ if (typeof document > "u")
635
+ return { close: () => {
636
+ } };
637
+ _?.close();
638
+ const t = Ae(e), a = t.downloadName || z(t.url, t.name);
639
+ let i = !1, r = null, s = null;
640
+ const l = () => {
641
+ i = !0, r && (A(null, r), r.remove(), r = null), s && (URL.revokeObjectURL(s), s = null), _?.close === l && (_ = null);
642
+ };
643
+ function d() {
644
+ i || (r || (r = document.createElement("div"), document.body.appendChild(r)), A(n(De, { options: t, onDestroy: l }), r));
645
+ }
646
+ function h() {
647
+ i || (r || (r = document.createElement("div"), document.body.appendChild(r)), A(n(Y, { options: t, onDestroy: l }), r));
648
+ }
649
+ function v() {
650
+ r && (A(null, r), r.remove(), r = null);
651
+ }
652
+ function m() {
653
+ i || te(t.url, a);
654
+ }
655
+ function k(b) {
656
+ if (i) return;
657
+ const f = URL.createObjectURL(b);
658
+ H(f, a), URL.revokeObjectURL(f);
659
+ }
660
+ const p = X(t);
661
+ return R(p) ? d() : p === "unknown" ? (h(), _e(t.url).then(async (b) => {
662
+ if (!i) {
663
+ if (R(b)) {
664
+ t.mode = b, d();
665
+ return;
666
+ }
667
+ try {
668
+ const f = await Z(t.url), o = K(f.type);
669
+ if (R(o)) {
670
+ s = URL.createObjectURL(f), t.url = s, t.mode = o, d();
671
+ return;
672
+ }
673
+ v(), k(f);
674
+ } catch {
675
+ v(), m();
676
+ }
677
+ }
678
+ })) : m(), _ = { close: l }, _;
679
+ }
680
+ function Le(e) {
681
+ P = e;
682
+ }
683
+ function ke(e) {
684
+ if (typeof document > "u")
685
+ return { close: () => {
686
+ } };
687
+ _?.close();
688
+ let t = !1, a = document.createElement("div");
689
+ document.body.appendChild(a);
690
+ const i = () => {
691
+ t = !0, a && (A(null, a), a.remove(), a = null), _?.close === i && (_ = null);
692
+ }, r = { close: i };
693
+ return _ = r, P ? (A(
694
+ n(Y, {
695
+ options: { url: "", name: "附件预览" },
696
+ title: "正在获取文件信息",
697
+ desc: "请稍候,获取完成后将自动预览或下载",
698
+ spinning: !0,
699
+ onDestroy: i
700
+ }),
701
+ a
702
+ ), P.request(e).then((s) => {
703
+ if (t) return;
704
+ const l = P?.mapResponse(s, e);
705
+ if (!l?.url) {
706
+ A(
707
+ n(Y, {
708
+ options: { url: "", name: "附件预览" },
709
+ title: "文件信息缺少 URL",
710
+ desc: "请检查 mapResponse 是否返回了 url 字段",
711
+ spinning: !1,
712
+ onDestroy: i
713
+ }),
714
+ a
715
+ );
716
+ return;
717
+ }
718
+ ne(l);
719
+ }).catch((s) => {
720
+ if (t) return;
721
+ const l = s instanceof Error ? s.message : "接口请求失败";
722
+ A(
723
+ n(Y, {
724
+ options: { url: "", name: "附件预览" },
725
+ title: "文件信息获取失败",
726
+ desc: l,
727
+ spinning: !1,
728
+ onDestroy: i
729
+ }),
730
+ a
731
+ );
732
+ }), r) : (A(
733
+ n(Y, {
734
+ options: { url: "", name: "附件预览" },
735
+ title: "附件预览未初始化",
736
+ desc: "请先调用 setupJtAttachmentPreview 注册请求配置",
737
+ spinning: !1,
738
+ onDestroy: i
739
+ }),
740
+ a
741
+ ), r);
742
+ }
743
+ const Ye = Object.assign(ne, {
744
+ openByParams: ke,
745
+ setup: Le
746
+ });
747
+ export {
748
+ Ye as JtAttachmentPreview,
749
+ ke as JtAttachmentPreviewByParams,
750
+ Le as setupJtAttachmentPreview
751
+ };