@jt-home/mfe-components 1.0.23 → 1.0.25

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