@jt-home/mfe-components 1.0.61 → 1.0.62-beta.1

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.
@@ -1,8 +1,908 @@
1
- import { J as m, a as i, b as s } from "../index-D67nILVt.js";
2
- import "vue";
3
- import "element-plus";
1
+ import './style.css';
2
+ import { t as l } from "../shared/locale-DZoOXmOC.js";
3
+ import { defineAsyncComponent as re, defineComponent as _, ref as j, watch as N, h as r, computed as y, onMounted as P, onBeforeUnmount as M, render as f } from "vue";
4
+ import { ElIcon as k } from "element-plus";
5
+ import { ZoomOut as oe, ZoomIn as ie, RefreshLeft as le, Download as ce } from "@element-plus/icons-vue";
6
+ const se = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAANgAAADYCAMAAAC+/t3fAAAAaVBMVEUAAABWapNVapKeqsLJztx3hKnGzN2yu8////9XapWcqMGps8lXapVYa5RWaZWps8lfcJjS1+KjrsVXapWapr////9sfaKrtMrV2uWBj7B4iKqWob1wgaXr7fOBj6/Ax9dhc5yhq8OKl7Wba+6tAAAAE3RSTlMAgGDuDyVLoYDe2XuXRb68cy6e4BCQEAAAAyZJREFUeNrt29tyokAUheGOQjIoeMhuCQ4e0Pd/yCE1STU4mGq7bXqzZ/23ufoqYblTqkIIIYQQQggNlM42Lzctf5nMD22bKQYVOQ30sTPt6dEO74mKXLoiCgDTi1RFbUMUBhZXluQUDKbnWxWtjMLB2pYqUjmFg8WUzSg0TL+rCKVZeJheRJj9DYWHRRnHbBSYnr+qcSsoKCyeLKcfK/emc2UqH4LFGMcVWVftTC4w/TbmhGQjwvR6RBmNAbMYx4nD7k/I1GF3ZZOH3RtHAbDhcZQAG5SJgOn1Vt0mAzYwIUJgvjJ/2OVo2pcmcoQZWehxpBGue5sJEQTryyTBeuMoCtadEFmwjkwYzIyjNJief02IONj3OAqE/ZVJhJnZj3RS1c4nld04ijiC/5EJhbUyobBWJhT2OY5CYa1MKKyVCYXpdSIUphdbob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teBwMR+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==", ue = /* @__PURE__ */ new Set([
7
+ "jpg",
8
+ "jpeg",
9
+ "png",
10
+ "gif",
11
+ "webp",
12
+ "bmp",
13
+ "svg",
14
+ "avif",
15
+ "ico"
16
+ ]), me = /* @__PURE__ */ new Set(["mp4", "webm", "ogg", "ogv", "mov", "m4v"]), ve = /* @__PURE__ */ new Set([
17
+ "mp3",
18
+ "wav",
19
+ "ogg",
20
+ "oga",
21
+ "m4a",
22
+ "aac",
23
+ "flac"
24
+ ]), fe = /* @__PURE__ */ new Set([
25
+ "html",
26
+ "htm",
27
+ "txt",
28
+ "json",
29
+ "xml",
30
+ "csv",
31
+ "md",
32
+ "log"
33
+ ]), we = /* @__PURE__ */ new Set([
34
+ "doc",
35
+ "docx",
36
+ "xls",
37
+ "xlsx",
38
+ "ppt",
39
+ "pptx",
40
+ "zip",
41
+ "rar",
42
+ "7z"
43
+ ]), T = {
44
+ component: "JtAttachmentPreview",
45
+ marker: "2026-06-25-download-error-detail",
46
+ source: "@jt-home/mfe-components/src/components/JtAttachmentPreview/index.ts",
47
+ pdfLoadMode: "vue-office-pdf-src",
48
+ previewDownloadMode: "openByParams-uses-registered-downloadRequest",
49
+ downloadResponseMode: "supports-blob-and-axios-response-data-blob"
50
+ };
51
+ function m(e, t) {
52
+ console.info(`[JtAttachmentPreview DEBUG ${T.marker}] ${e}`, {
53
+ ...T,
54
+ ...t
55
+ });
56
+ }
57
+ typeof window < "u" && (window.__JT_ATTACHMENT_PREVIEW_DEBUG__ = T);
58
+ let w = null, p = null, B = null;
59
+ const pe = re(
60
+ () => (
61
+ // PDF 渲染依赖是可选 peer;固定导入已发布的 Vue3 子入口,避开依赖 postinstall 生成的默认入口。
62
+ import("@vue-office/pdf/lib/v3/index.js").then((e) => e.default)
63
+ )
64
+ );
65
+ function be(e) {
66
+ return typeof e == "string" ? { url: e } : e;
67
+ }
68
+ function G(e) {
69
+ const [t] = e.split(/[?#]/);
70
+ return t ?? "";
71
+ }
72
+ function x(e, t) {
73
+ if (t?.trim()) return t.trim();
74
+ const a = G(e).split("/").filter(Boolean).pop();
75
+ if (!a) return l("common.附件预览");
76
+ try {
77
+ return decodeURIComponent(a);
78
+ } catch {
79
+ return a;
80
+ }
81
+ }
82
+ function I(e) {
83
+ return G(e).match(/\.([a-z0-9]+)$/i)?.[1]?.toLowerCase() ?? "";
84
+ }
85
+ function he(e) {
86
+ return e?.trim().replace(/^\./, "").toLowerCase() ?? "";
87
+ }
88
+ function ye(e) {
89
+ const t = he(e);
90
+ return ue.has(t) ? "image" : t === "pdf" ? "pdf" : me.has(t) ? "video" : ve.has(t) ? "audio" : fe.has(t) ? "iframe" : we.has(t) ? "unsupported" : "unknown";
91
+ }
92
+ function O(e) {
93
+ const t = e.toLowerCase().split(";")[0]?.trim() ?? "";
94
+ return t.startsWith("image/") ? "image" : t === "application/pdf" ? "pdf" : t.startsWith("video/") ? "video" : t.startsWith("audio/") ? "audio" : t.startsWith("text/") ? "iframe" : "unknown";
95
+ }
96
+ function K(e) {
97
+ if (!e.url.trim()) return "empty";
98
+ if (e.mode && e.mode !== "auto") return e.mode;
99
+ if (e.mimeType) {
100
+ const a = O(e.mimeType);
101
+ if (a !== "unknown") return a;
102
+ }
103
+ const t = ye(
104
+ e.extension || I(e.name || "") || I(e.url)
105
+ );
106
+ return t !== "unknown" ? t : "unknown";
107
+ }
108
+ async function ge(e) {
109
+ try {
110
+ const a = (await fetch(e, { method: "HEAD" })).headers.get("content-type") ?? "";
111
+ return O(a);
112
+ } catch {
113
+ return "unknown";
114
+ }
115
+ }
116
+ async function H(e, t) {
117
+ const a = await fetch(e, t);
118
+ if (!a.ok) throw new Error(`fetch failed: ${a.status}`);
119
+ return a.blob();
120
+ }
121
+ function W(e, t, a, o = !1) {
122
+ return r(
123
+ "button",
124
+ {
125
+ class: a,
126
+ type: "button",
127
+ onClick: () => {
128
+ m("download-button-click", {
129
+ url: e.url,
130
+ downloadName: t,
131
+ fallbackToRawUrl: o
132
+ }), z(e, t, {
133
+ fallbackToRawUrl: o
134
+ });
135
+ }
136
+ },
137
+ [
138
+ r(
139
+ k,
140
+ { class: "jt-attachment-preview-service__download-icon" },
141
+ () => r(ce)
142
+ ),
143
+ r(
144
+ "span",
145
+ { class: "jt-attachment-preview-service__download-text" },
146
+ l("common.下载")
147
+ )
148
+ ]
149
+ );
150
+ }
151
+ function L(e) {
152
+ return e === "image" || e === "pdf";
153
+ }
154
+ function Q(e) {
155
+ return r(
156
+ "div",
157
+ { class: "jt-attachment-preview-service__preview-fallback" },
158
+ [
159
+ r("img", {
160
+ class: "jt-attachment-preview-service__preview-fallback-icon",
161
+ src: e.icon,
162
+ alt: ""
163
+ }),
164
+ r(
165
+ "div",
166
+ { class: "jt-attachment-preview-service__unsupported-text" },
167
+ l("common.暂不支持预览此类型的文件")
168
+ ),
169
+ r(
170
+ "div",
171
+ {
172
+ class: "jt-attachment-preview-service__file-name",
173
+ title: e.name
174
+ },
175
+ e.name
176
+ )
177
+ ]
178
+ );
179
+ }
180
+ function U(e, t) {
181
+ const a = document.createElement("a");
182
+ a.href = e, a.download = t, a.style.display = "none", document.body.appendChild(a), a.click(), a.remove();
183
+ }
184
+ function J(e, t) {
185
+ const a = URL.createObjectURL(e);
186
+ U(a, t), window.setTimeout(() => URL.revokeObjectURL(a), 1e3);
187
+ }
188
+ function R(e) {
189
+ return e instanceof Blob || Object.prototype.toString.call(e) === "[object Blob]";
190
+ }
191
+ function Ae(e, t) {
192
+ if (R(e))
193
+ return e;
194
+ if (e && typeof e == "object") {
195
+ const a = e;
196
+ if (R(a.data)) {
197
+ const o = a.data;
198
+ return {
199
+ blob: a.data,
200
+ name: a.fileName || a.name || o.name || t
201
+ };
202
+ }
203
+ }
204
+ return null;
205
+ }
206
+ async function Ee(e, t, a = {}) {
207
+ m("download-start", {
208
+ url: e,
209
+ downloadName: t,
210
+ fallbackToRawUrl: !!a.fallbackToRawUrl,
211
+ hasRequestInit: !!a.requestInit
212
+ });
213
+ try {
214
+ const o = await H(e, a.requestInit);
215
+ m("download-blob-ready", {
216
+ url: e,
217
+ downloadName: t,
218
+ blobType: o.type,
219
+ blobSize: o.size
220
+ }), J(o, t);
221
+ } catch {
222
+ m("download-blob-failed", {
223
+ url: e,
224
+ downloadName: t,
225
+ fallbackToRawUrl: !!a.fallbackToRawUrl
226
+ }), a.fallbackToRawUrl && U(e, t);
227
+ }
228
+ }
229
+ function S(e, t) {
230
+ return e instanceof Blob ? { blob: e, name: t } : e ? {
231
+ url: e.url,
232
+ blob: e.blob,
233
+ name: e.name || t,
234
+ requestInit: e.requestInit,
235
+ fallbackToRawUrl: e.fallbackToRawUrl
236
+ } : null;
237
+ }
238
+ async function z(e, t, a = {}) {
239
+ const o = {
240
+ url: e.url,
241
+ name: t,
242
+ params: e.requestParams,
243
+ options: e
244
+ };
245
+ try {
246
+ let n = null;
247
+ if (m("download-resolve-start", {
248
+ url: e.url,
249
+ downloadName: t,
250
+ hasCustomDownload: !!e.download,
251
+ hasRegisteredDownload: !!p?.downloadRequest,
252
+ useRegisteredDownload: !!e.useRegisteredDownload,
253
+ hasRequestParams: Object.prototype.hasOwnProperty.call(
254
+ e,
255
+ "requestParams"
256
+ )
257
+ }), e.download) {
258
+ m("download-custom-handler-start", {
259
+ url: e.url,
260
+ downloadName: t
261
+ });
262
+ const i = await e.download(o);
263
+ if (n = S(i, t), !n) {
264
+ m("download-custom-handler-done", {
265
+ url: e.url,
266
+ downloadName: t
267
+ });
268
+ return;
269
+ }
270
+ } else if (e.useRegisteredDownload && p?.downloadRequest) {
271
+ m("download-setup-request-start", {
272
+ url: e.url,
273
+ downloadName: t,
274
+ params: e.requestParams
275
+ });
276
+ const i = await p.downloadRequest(
277
+ e.requestParams
278
+ );
279
+ m("download-request-response", {
280
+ isBlob: R(i),
281
+ isDataBlob: !!i && typeof i == "object" && R(i.data),
282
+ responseType: Object.prototype.toString.call(i)
283
+ });
284
+ const v = Ae(i, t), u = v || (p.mapDownloadResponse ? p.mapDownloadResponse(
285
+ i,
286
+ e.requestParams
287
+ ) : i);
288
+ n = S(u, t);
289
+ }
290
+ if (n?.blob) {
291
+ m("download-result-blob", {
292
+ downloadName: n.name,
293
+ blobType: n.blob.type,
294
+ blobSize: n.blob.size
295
+ }), J(n.blob, n.name);
296
+ return;
297
+ }
298
+ const c = n?.url || e.downloadUrl || e.url, d = n?.name || t;
299
+ await Ee(c, d, {
300
+ requestInit: n?.requestInit || e.downloadRequestInit,
301
+ fallbackToRawUrl: n?.fallbackToRawUrl ?? e.downloadFallbackToRawUrl ?? a.fallbackToRawUrl
302
+ });
303
+ } catch (n) {
304
+ m("download-handler-failed", {
305
+ url: e.url,
306
+ downloadName: t,
307
+ errorName: n instanceof Error ? n.name : "",
308
+ errorMessage: n instanceof Error ? n.message : String(n),
309
+ errorStack: n instanceof Error ? n.stack : "",
310
+ errorResponseStatus: n && typeof n == "object" ? n.response?.status : void 0,
311
+ errorResponseType: n && typeof n == "object" ? Object.prototype.toString.call(
312
+ n.response?.data
313
+ ) : void 0,
314
+ errorResponseDataType: n && typeof n == "object" ? n.response?.data?.type : void 0
315
+ }), a.fallbackToRawUrl && U(e.downloadUrl || e.url, t);
316
+ }
317
+ }
318
+ const je = _({
319
+ name: "JtAttachmentPreviewPdfOffice",
320
+ props: {
321
+ url: {
322
+ type: String,
323
+ required: !0
324
+ },
325
+ name: {
326
+ type: String,
327
+ required: !0
328
+ },
329
+ downloadName: {
330
+ type: String,
331
+ required: !0
332
+ },
333
+ downloadable: {
334
+ type: Boolean,
335
+ required: !0
336
+ }
337
+ },
338
+ emits: {
339
+ previewLoad: (e) => e instanceof Event,
340
+ previewError: (e) => e instanceof Event
341
+ },
342
+ setup(e, { emit: t }) {
343
+ const a = j("ready");
344
+ function o() {
345
+ a.value = "ready", t("previewLoad", new Event("load"));
346
+ }
347
+ function n() {
348
+ a.value = "error", t("previewError", new Event("error"));
349
+ }
350
+ return N(
351
+ () => e.url,
352
+ () => {
353
+ a.value = "ready";
354
+ }
355
+ ), () => r("div", { class: "jt-attachment-preview-service__pdf-viewer" }, [
356
+ // PDF 预览只负责把现有 URL 交给 vue-office,下载和接口适配仍由外层服务处理。
357
+ a.value === "error" ? r("div", { class: "jt-attachment-preview-service__pdf-state" }, [
358
+ Q({
359
+ icon: de,
360
+ name: e.name
361
+ })
362
+ ]) : r(pe, {
363
+ class: "jt-attachment-preview-service__pdf-document",
364
+ src: e.url,
365
+ onRendered: o,
366
+ onError: n
367
+ })
368
+ ]);
369
+ }
370
+ }), De = _({
371
+ name: "JtAttachmentPreviewImageTransform",
372
+ props: {
373
+ url: {
374
+ type: String,
375
+ required: !0
376
+ },
377
+ name: {
378
+ type: String,
379
+ required: !0
380
+ },
381
+ downloadName: {
382
+ type: String,
383
+ required: !0
384
+ },
385
+ downloadable: {
386
+ type: Boolean,
387
+ required: !0
388
+ },
389
+ fit: {
390
+ type: String,
391
+ default: "contain"
392
+ }
393
+ },
394
+ emits: {
395
+ previewLoad: (e) => e instanceof Event,
396
+ previewError: (e) => e instanceof Event
397
+ },
398
+ setup(e, { emit: t }) {
399
+ const a = j(null), o = j("ready"), n = j(1), c = j(!1);
400
+ let d = 0, i = 0, v = 0, u = 0, A = 0, g = 0, b = 0;
401
+ const E = y(
402
+ () => ({
403
+ "--jt-attachment-preview-service-image-fit": e.fit,
404
+ transform: `translate(${d}px, ${i}px) scale(${n.value})`
405
+ })
406
+ );
407
+ function h() {
408
+ a.value && (a.value.style.transform = `translate(${d}px, ${i}px) scale(${n.value})`);
409
+ }
410
+ function X() {
411
+ b || (b = window.requestAnimationFrame(() => {
412
+ b = 0, h();
413
+ }));
414
+ }
415
+ function C(s) {
416
+ n.value = Math.min(Math.max(Number(s.toFixed(2)), 0.2), 5), n.value <= 1 && (d = 0, i = 0), h();
417
+ }
418
+ function Z() {
419
+ C(n.value + 0.2);
420
+ }
421
+ function F() {
422
+ const s = Math.max(Number((n.value - 0.2).toFixed(2)), 0.2);
423
+ n.value = s, s <= 1 && (d = 0, i = 0), h();
424
+ }
425
+ function q() {
426
+ d = 0, i = 0, C(1);
427
+ }
428
+ function $(s) {
429
+ o.value = "ready", t("previewLoad", s);
430
+ }
431
+ function ee(s) {
432
+ o.value = "error", t("previewError", s);
433
+ }
434
+ function te(s) {
435
+ n.value <= 1 || (s.preventDefault(), c.value = !0, v = s.clientX, u = s.clientY, A = d, g = i, window.addEventListener("pointermove", Y), window.addEventListener("pointerup", ne, { once: !0 }));
436
+ }
437
+ function Y(s) {
438
+ c.value && (d = A + s.clientX - v, i = g + s.clientY - u, X());
439
+ }
440
+ function ne() {
441
+ c.value = !1, window.removeEventListener("pointermove", Y);
442
+ }
443
+ function ae(s) {
444
+ s.preventDefault(), C(n.value + (s.deltaY < 0 ? 0.1 : -0.1));
445
+ }
446
+ return P(h), N(
447
+ () => e.url,
448
+ () => {
449
+ o.value = "ready", q();
450
+ }
451
+ ), M(() => {
452
+ window.removeEventListener("pointermove", Y), b && window.cancelAnimationFrame(b);
453
+ }), () => r(
454
+ "div",
455
+ { class: "jt-attachment-preview-service__image-viewer" },
456
+ o.value === "error" ? Q({
457
+ icon: se,
458
+ name: e.name
459
+ }) : [
460
+ r("img", {
461
+ ref: a,
462
+ class: [
463
+ "jt-attachment-preview-service__media",
464
+ "jt-attachment-preview-service__image",
465
+ n.value > 1 ? "jt-attachment-preview-service__image--draggable" : "",
466
+ c.value ? "jt-attachment-preview-service__image--dragging" : ""
467
+ ],
468
+ src: e.url,
469
+ alt: e.name,
470
+ style: E.value,
471
+ onLoad: $,
472
+ onError: ee,
473
+ onPointerdown: te,
474
+ onWheel: ae,
475
+ onDragstart: (s) => s.preventDefault(),
476
+ draggable: !1
477
+ }),
478
+ r(
479
+ "div",
480
+ { class: "jt-attachment-preview-service__image-toolbar" },
481
+ [
482
+ r(
483
+ "button",
484
+ {
485
+ class: "jt-attachment-preview-service__image-tool",
486
+ type: "button",
487
+ title: l("common.缩小"),
488
+ onClick: F
489
+ },
490
+ [r(k, () => r(oe))]
491
+ ),
492
+ r(
493
+ "span",
494
+ { class: "jt-attachment-preview-service__image-scale" },
495
+ `${Math.round(n.value * 100)}%`
496
+ ),
497
+ r(
498
+ "button",
499
+ {
500
+ class: "jt-attachment-preview-service__image-tool",
501
+ type: "button",
502
+ title: l("common.放大"),
503
+ onClick: Z
504
+ },
505
+ [r(k, () => r(ie))]
506
+ ),
507
+ r(
508
+ "button",
509
+ {
510
+ class: "jt-attachment-preview-service__image-tool",
511
+ type: "button",
512
+ title: l("common.复位"),
513
+ onClick: q
514
+ },
515
+ [r(k, () => r(le))]
516
+ )
517
+ ]
518
+ )
519
+ ]
520
+ );
521
+ }
522
+ }), ke = _({
523
+ name: "JtAttachmentPreviewService",
524
+ props: {
525
+ options: {
526
+ type: Object,
527
+ required: !0
528
+ },
529
+ onDestroy: {
530
+ type: Function,
531
+ required: !0
532
+ }
533
+ },
534
+ setup(e) {
535
+ const t = y(
536
+ () => x(e.options.url, e.options.name)
537
+ ), a = y(
538
+ () => e.options.downloadName || t.value
539
+ ), o = y(() => K(e.options)), n = y(
540
+ () => ({
541
+ zIndex: e.options.zIndex ?? 3e3,
542
+ "--jt-attachment-preview-service-image-fit": e.options.fit ?? "contain"
543
+ })
544
+ );
545
+ function c() {
546
+ e.options.onClose?.(), e.onDestroy();
547
+ }
548
+ function d(u) {
549
+ u.key === "Escape" && e.options.closeOnPressEscape !== !1 && c();
550
+ }
551
+ function i(u) {
552
+ e.options.onLoad?.(u);
553
+ }
554
+ function v(u) {
555
+ e.options.onError?.(u);
556
+ }
557
+ return P(() => {
558
+ document.addEventListener("keydown", d), document.body.classList.add("jt-attachment-preview-service-lock");
559
+ }), M(() => {
560
+ document.removeEventListener("keydown", d), document.body.classList.remove("jt-attachment-preview-service-lock");
561
+ }), () => {
562
+ const u = e.options.downloadable === !1 ? [] : [
563
+ W(
564
+ e.options,
565
+ a.value,
566
+ "jt-attachment-preview-service__top-download"
567
+ )
568
+ ];
569
+ return r(
570
+ "div",
571
+ { class: "jt-attachment-preview-service", style: n.value },
572
+ [
573
+ r("div", { class: "jt-attachment-preview-service__modal" }, [
574
+ r("div", { class: "jt-attachment-preview-service__header" }, [
575
+ r(
576
+ "div",
577
+ {
578
+ class: "jt-attachment-preview-service__filename",
579
+ title: t.value
580
+ },
581
+ t.value
582
+ ),
583
+ r(
584
+ "div",
585
+ { class: "jt-attachment-preview-service__header-actions" },
586
+ [
587
+ ...u,
588
+ r(
589
+ "button",
590
+ {
591
+ class: "jt-attachment-preview-service__close",
592
+ type: "button",
593
+ "aria-label": l("common.关闭"),
594
+ onClick: c
595
+ },
596
+ "×"
597
+ )
598
+ ]
599
+ )
600
+ ]),
601
+ r("div", { class: "jt-attachment-preview-service__body" }, [
602
+ Be({
603
+ type: o.value,
604
+ url: e.options.url,
605
+ name: t.value,
606
+ downloadName: a.value,
607
+ sourceOptions: e.options,
608
+ downloadable: e.options.downloadable !== !1,
609
+ onLoad: i,
610
+ onError: v
611
+ })
612
+ ])
613
+ ])
614
+ ]
615
+ );
616
+ };
617
+ }
618
+ }), D = _({
619
+ name: "JtAttachmentPreviewDetectingService",
620
+ props: {
621
+ options: {
622
+ type: Object,
623
+ required: !0
624
+ },
625
+ onDestroy: {
626
+ type: Function,
627
+ required: !0
628
+ },
629
+ title: {
630
+ type: String,
631
+ default: l("common.正在识别文件类型")
632
+ },
633
+ desc: {
634
+ type: String,
635
+ default: l("common.请稍候,识别完成后将自动预览或下载")
636
+ },
637
+ spinning: {
638
+ type: Boolean,
639
+ default: !0
640
+ }
641
+ },
642
+ setup(e) {
643
+ const t = y(
644
+ () => x(e.options.url, e.options.name)
645
+ ), a = y(() => ({
646
+ zIndex: e.options.zIndex ?? 3e3
647
+ }));
648
+ function o() {
649
+ e.options.onClose?.(), e.onDestroy();
650
+ }
651
+ function n(c) {
652
+ c.key === "Escape" && e.options.closeOnPressEscape !== !1 && o();
653
+ }
654
+ return P(() => {
655
+ document.addEventListener("keydown", n), document.body.classList.add("jt-attachment-preview-service-lock");
656
+ }), M(() => {
657
+ document.removeEventListener("keydown", n), document.body.classList.remove("jt-attachment-preview-service-lock");
658
+ }), () => r(
659
+ "div",
660
+ { class: "jt-attachment-preview-service", style: a.value },
661
+ [
662
+ r("div", { class: "jt-attachment-preview-service__modal" }, [
663
+ r("div", { class: "jt-attachment-preview-service__header" }, [
664
+ r(
665
+ "div",
666
+ {
667
+ class: "jt-attachment-preview-service__filename",
668
+ title: t.value
669
+ },
670
+ t.value
671
+ ),
672
+ r(
673
+ "div",
674
+ { class: "jt-attachment-preview-service__header-actions" },
675
+ [
676
+ r(
677
+ "button",
678
+ {
679
+ class: "jt-attachment-preview-service__close",
680
+ type: "button",
681
+ "aria-label": l("common.关闭"),
682
+ onClick: o
683
+ },
684
+ "×"
685
+ )
686
+ ]
687
+ )
688
+ ]),
689
+ r("div", { class: "jt-attachment-preview-service__body" }, [
690
+ r("div", { class: "jt-attachment-preview-service__detecting" }, [
691
+ e.spinning ? r("span", {
692
+ class: "jt-attachment-preview-service__detecting-spinner"
693
+ }) : null,
694
+ r(
695
+ "span",
696
+ { class: "jt-attachment-preview-service__detecting-title" },
697
+ e.title
698
+ ),
699
+ r(
700
+ "span",
701
+ { class: "jt-attachment-preview-service__detecting-desc" },
702
+ e.desc
703
+ )
704
+ ])
705
+ ])
706
+ ])
707
+ ]
708
+ );
709
+ }
710
+ });
711
+ function Be(e) {
712
+ return e.type === "empty" ? r(
713
+ "div",
714
+ { class: "jt-attachment-preview-service__empty" },
715
+ l("common.暂无附件")
716
+ ) : e.type === "image" ? r(De, {
717
+ url: e.url,
718
+ name: e.name,
719
+ downloadName: e.downloadName,
720
+ downloadable: e.downloadable,
721
+ onPreviewLoad: e.onLoad,
722
+ onPreviewError: e.onError
723
+ }) : e.type === "pdf" ? r(je, {
724
+ url: e.url,
725
+ name: e.name,
726
+ downloadName: e.downloadName,
727
+ downloadable: e.downloadable,
728
+ onPreviewLoad: e.onLoad,
729
+ onPreviewError: e.onError
730
+ }) : r("div", { class: "jt-attachment-preview-service__unsupported" }, [
731
+ r("div", { class: "jt-attachment-preview-service__file-card" }, [
732
+ r(
733
+ "div",
734
+ { class: "jt-attachment-preview-service__file-icon" },
735
+ "FILE"
736
+ ),
737
+ r(
738
+ "div",
739
+ { class: "jt-attachment-preview-service__unsupported-text" },
740
+ l("common.暂不支持预览此类型的文件")
741
+ )
742
+ ]),
743
+ r(
744
+ "div",
745
+ {
746
+ class: "jt-attachment-preview-service__file-name",
747
+ title: e.name
748
+ },
749
+ e.name
750
+ ),
751
+ e.downloadable ? W(
752
+ e.sourceOptions,
753
+ e.downloadName,
754
+ "jt-attachment-preview-service__primary-download"
755
+ ) : null
756
+ ]);
757
+ }
758
+ function V(e) {
759
+ if (typeof document > "u")
760
+ return { close: () => {
761
+ } };
762
+ m("open-called", {
763
+ rawOptions: typeof e == "string" ? e : { ...e }
764
+ }), w?.close();
765
+ const t = be(
766
+ e
767
+ ), a = t.downloadName || x(t.url, t.name);
768
+ let o = !1, n = null, c = null;
769
+ const d = () => {
770
+ o = !0, n && (f(null, n), n.remove(), n = null), c && (URL.revokeObjectURL(c), c = null), w?.close === d && (w = null);
771
+ };
772
+ function i() {
773
+ o || (n || (n = document.createElement("div"), document.body.appendChild(n)), f(
774
+ r(ke, {
775
+ options: t,
776
+ onDestroy: d
777
+ }),
778
+ n
779
+ ));
780
+ }
781
+ function v() {
782
+ o || (n || (n = document.createElement("div"), document.body.appendChild(n)), f(
783
+ r(D, {
784
+ options: t,
785
+ onDestroy: d
786
+ }),
787
+ n
788
+ ));
789
+ }
790
+ function u() {
791
+ n && (f(null, n), n.remove(), n = null);
792
+ }
793
+ function A() {
794
+ o || z(t, a, {
795
+ fallbackToRawUrl: !0
796
+ });
797
+ }
798
+ const g = K(t);
799
+ return m("type-resolved", {
800
+ resolvedType: g,
801
+ url: t.url,
802
+ name: t.name,
803
+ mode: t.mode,
804
+ mimeType: t.mimeType,
805
+ extension: t.extension
806
+ }), L(g) ? i() : g === "unknown" ? (v(), ge(t.url).then(async (b) => {
807
+ if (!o) {
808
+ if (L(b)) {
809
+ t.mode = b, i();
810
+ return;
811
+ }
812
+ try {
813
+ const E = await H(t.url), h = O(E.type);
814
+ if (L(h)) {
815
+ c = URL.createObjectURL(E), t.url = c, t.mode = h, i();
816
+ return;
817
+ }
818
+ u(), J(E, a);
819
+ } catch {
820
+ u(), A();
821
+ }
822
+ }
823
+ })) : A(), w = { close: d }, w;
824
+ }
825
+ function Re(e) {
826
+ if (typeof e == "function") {
827
+ p = null, B = e;
828
+ return;
829
+ }
830
+ p = e, B = async (t) => {
831
+ const a = await p.request(t);
832
+ return p.mapResponse(a, t);
833
+ };
834
+ }
835
+ function _e(e) {
836
+ if (typeof document > "u")
837
+ return { close: () => {
838
+ } };
839
+ w?.close();
840
+ let t = !1, a = document.createElement("div");
841
+ document.body.appendChild(a);
842
+ const o = () => {
843
+ t = !0, a && (f(null, a), a.remove(), a = null), w?.close === o && (w = null);
844
+ }, n = { close: o };
845
+ return w = n, B ? (f(
846
+ r(D, {
847
+ options: { url: "", name: l("common.附件预览") },
848
+ title: l("common.正在获取文件信息"),
849
+ desc: l("common.请稍候,获取完成后将自动预览或下载"),
850
+ spinning: !0,
851
+ onDestroy: o
852
+ }),
853
+ a
854
+ ), Promise.resolve(B(e)).then((c) => {
855
+ if (!t) {
856
+ if (!c?.url) {
857
+ f(
858
+ r(D, {
859
+ options: { url: "", name: l("common.附件预览") },
860
+ title: l("common.文件信息缺少URL"),
861
+ desc: l("common.请检查mapResponse是否返回了url字段"),
862
+ spinning: !1,
863
+ onDestroy: o
864
+ }),
865
+ a
866
+ );
867
+ return;
868
+ }
869
+ V({
870
+ ...c,
871
+ requestParams: e,
872
+ useRegisteredDownload: !0
873
+ });
874
+ }
875
+ }).catch((c) => {
876
+ if (t) return;
877
+ const d = c instanceof Error ? c.message : l("common.接口请求失败");
878
+ f(
879
+ r(D, {
880
+ options: { url: "", name: l("common.附件预览") },
881
+ title: l("common.文件信息获取失败"),
882
+ desc: d,
883
+ spinning: !1,
884
+ onDestroy: o
885
+ }),
886
+ a
887
+ );
888
+ }), n) : (f(
889
+ r(D, {
890
+ options: { url: "", name: l("common.附件预览") },
891
+ title: l("common.附件预览未初始化"),
892
+ desc: l("common.请先调用setupJtAttachmentPreview注册请求配置"),
893
+ spinning: !1,
894
+ onDestroy: o
895
+ }),
896
+ a
897
+ ), n);
898
+ }
899
+ const Ce = Object.assign(V, {
900
+ openByParams: _e,
901
+ setup: Re
902
+ });
903
+ globalThis.__JT_ATTACHMENT_PREVIEW_SERVICE__ = Ce;
4
904
  export {
5
- m as JtAttachmentPreview,
6
- i as JtAttachmentPreviewByParams,
7
- s as setupJtAttachmentPreview
905
+ Ce as JtAttachmentPreview,
906
+ _e as JtAttachmentPreviewByParams,
907
+ Re as setupJtAttachmentPreview
8
908
  };