@work-zhanguo/light-file-preview 0.0.11 → 0.0.13
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/README.md +119 -91
- package/dist/SheetRenderer-Dr5f9ZTy.js +918 -0
- package/dist/{UnsupportedRenderer-vjWyKDpT.js → UnsupportedRenderer-Z8yR4DCm.js} +1 -1
- package/dist/index-CB4lf4Rv.js +346 -0
- package/dist/light-file-preview.js +1 -1
- package/dist/light-file-preview.umd.cjs +66 -66
- package/dist/standalone/light-file-preview.iife.js +50 -50
- package/dist/standalone/style.css +1 -1
- package/dist/style.css +1 -1
- package/dist/vue2/{DocxRenderer-Z4HX5Nb8.js → DocxRenderer-DGXNIVsp.js} +1 -1
- package/dist/vue2/{PdfRenderer-qVQzlsuJ.js → PdfRenderer-CANDrYvV.js} +1 -1
- package/dist/vue2/SheetRenderer-CM49qq4y.js +918 -0
- package/dist/vue2/{TextRenderer-CCh9A3GD.js → TextRenderer-CFNsDxIx.js} +1 -1
- package/dist/vue2/{UnsupportedRenderer-Bv7s0246.js → UnsupportedRenderer-NMI6uTEn.js} +1 -1
- package/dist/vue2/light-file-preview-vue2.js +1 -1
- package/dist/vue2/light-file-preview-vue2.umd.cjs +108 -108
- package/dist/vue2/{vue2-DiVuCQ1b.js → vue2-n72zoIZI.js} +1491 -1450
- package/package.json +4 -1
- package/public/screenshots/effect-docx.png +0 -0
- package/public/screenshots/effect-pdf.png +0 -0
- package/public/screenshots/effect-pptx.png +0 -0
- package/public/screenshots/effect-xlsx.png +0 -0
- package/public/screenshots/preview-dialog.png +0 -0
- package/public/screenshots/preview-docs.png +0 -0
- package/public/screenshots/preview-home.png +0 -0
- package/dist/SheetRenderer-Dfa4Vi-f.js +0 -576
- package/dist/index-CNi6OyzI.js +0 -305
- package/dist/vue2/SheetRenderer-9kIteUQN.js +0 -576
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineComponent as o, openBlock as l, createElementBlock as a, createElementVNode as t, toDisplayString as i, unref as r } from "vue";
|
|
2
|
-
import { d as s } from "./index-
|
|
2
|
+
import { d as s } from "./index-CB4lf4Rv.js";
|
|
3
3
|
const d = { class: "lfp-empty" }, p = { class: "lfp-hint" }, c = /* @__PURE__ */ o({
|
|
4
4
|
__name: "UnsupportedRenderer",
|
|
5
5
|
props: {
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import { defineComponent as z, defineAsyncComponent as R, ref as E, computed as f, watch as U, onBeforeUnmount as X, openBlock as s, createBlock as k, Teleport as W, createElementBlock as v, normalizeClass as G, createCommentVNode as L, createElementVNode as l, toDisplayString as D, createVNode as J, Transition as Q, withCtx as Y, Fragment as ee, unref as S, reactive as N, createApp as O, h as V } from "vue";
|
|
2
|
+
const w = {
|
|
3
|
+
image: ["png", "jpg", "jpeg", "gif", "webp", "bmp", "svg"],
|
|
4
|
+
pdf: ["pdf"],
|
|
5
|
+
text: ["txt", "json", "js", "ts", "jsx", "tsx", "html", "css", "md", "csv"],
|
|
6
|
+
docx: ["docx"],
|
|
7
|
+
sheet: ["xls", "xlsx", "csv"],
|
|
8
|
+
video: ["mp4", "webm"],
|
|
9
|
+
audio: ["mp3", "wav"]
|
|
10
|
+
}, te = ["doc", "ppt", "pptx"];
|
|
11
|
+
function j(e = "") {
|
|
12
|
+
const n = e.split("#")[0].split("?")[0].split(".");
|
|
13
|
+
return n.length > 1 ? n[n.length - 1].toLowerCase() : "";
|
|
14
|
+
}
|
|
15
|
+
function oe(e) {
|
|
16
|
+
const t = j(e);
|
|
17
|
+
return w.image.includes(t) ? "image" : w.pdf.includes(t) ? "pdf" : w.docx.includes(t) ? "docx" : w.sheet.includes(t) ? "sheet" : w.video.includes(t) ? "video" : w.audio.includes(t) ? "audio" : w.text.includes(t) ? t === "csv" ? "sheet" : "text" : (te.includes(t), "unsupported");
|
|
18
|
+
}
|
|
19
|
+
function ne(e) {
|
|
20
|
+
if (/^(blob:|data:|https?:\/\/|file:\/\/)/i.test(e))
|
|
21
|
+
return e;
|
|
22
|
+
try {
|
|
23
|
+
const t = new URL(e, window.location.href);
|
|
24
|
+
return t.pathname = t.pathname.split("/").map((n) => encodeURIComponent(decodeURIComponent(n))).join("/"), t.toString();
|
|
25
|
+
} catch (t) {
|
|
26
|
+
return e.split("/").map((n) => encodeURIComponent(decodeURIComponent(n))).join("/");
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function K(e, t) {
|
|
30
|
+
var r;
|
|
31
|
+
if (typeof e == "string") {
|
|
32
|
+
const m = ne(e), d = e.split("/"), o = (r = t != null ? t : d[d.length - 1]) != null ? r : "unknown";
|
|
33
|
+
return {
|
|
34
|
+
source: e,
|
|
35
|
+
src: m,
|
|
36
|
+
name: decodeURIComponent(o.split("?")[0].split("#")[0]),
|
|
37
|
+
extension: j(o)
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const n = URL.createObjectURL(e), c = t != null ? t : "name" in e && typeof e.name == "string" ? e.name : "blob";
|
|
41
|
+
return {
|
|
42
|
+
source: e,
|
|
43
|
+
src: n,
|
|
44
|
+
name: c,
|
|
45
|
+
extension: j(c),
|
|
46
|
+
cleanup: () => URL.revokeObjectURL(n)
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function ae(e, t) {
|
|
50
|
+
const n = document.createElement("a");
|
|
51
|
+
n.href = e, n.download = t, n.target = "_blank", n.rel = "noopener", document.body.append(n), n.click(), n.remove();
|
|
52
|
+
}
|
|
53
|
+
const le = ["aria-modal"], se = {
|
|
54
|
+
key: 0,
|
|
55
|
+
class: "lfp-toolbar"
|
|
56
|
+
}, ie = { class: "lfp-toolbar__meta" }, ue = { class: "lfp-title" }, re = { class: "lfp-badge" }, ce = { class: "lfp-toolbar__actions" }, de = { class: "lfp-content" }, ve = {
|
|
57
|
+
key: 0,
|
|
58
|
+
class: "lfp-loading"
|
|
59
|
+
}, me = {
|
|
60
|
+
key: 0,
|
|
61
|
+
class: "lfp-error"
|
|
62
|
+
}, pe = ["src", "alt"], fe = ["src"], ge = ["src"], I = /* @__PURE__ */ z({
|
|
63
|
+
__name: "FilePreview",
|
|
64
|
+
props: {
|
|
65
|
+
source: {},
|
|
66
|
+
fileName: {},
|
|
67
|
+
mode: { default: "inline" },
|
|
68
|
+
visible: { type: Boolean, default: !0 },
|
|
69
|
+
loadingText: { default: "文件加载中..." },
|
|
70
|
+
textEncoding: { default: "utf-8" },
|
|
71
|
+
maxTextBytes: { default: 1024 * 1024 * 2 },
|
|
72
|
+
maxSheetRows: { default: 200 },
|
|
73
|
+
maxSheetCols: { default: 50 },
|
|
74
|
+
pdfScale: { default: 1.35 },
|
|
75
|
+
showToolbar: { type: Boolean, default: !0 },
|
|
76
|
+
dialogTitle: { default: "文件预览" }
|
|
77
|
+
},
|
|
78
|
+
emits: ["update:visible", "error"],
|
|
79
|
+
setup(e, { emit: t }) {
|
|
80
|
+
const n = R(() => import("./PdfRenderer-Due2M5cA.js")), c = R(() => import("./TextRenderer-KUhpnf63.js")), r = R(() => import("./DocxRenderer-DogNhBLd.js")), m = R(() => import("./SheetRenderer-Dr5f9ZTy.js")), d = R(() => import("./UnsupportedRenderer-Z8yR4DCm.js")), o = e, A = t, g = E(null), x = E(!1), b = E(""), y = E(0), a = E(K(o.source, o.fileName)), Z = {
|
|
81
|
+
image: "图片",
|
|
82
|
+
pdf: "PDF",
|
|
83
|
+
text: "文本",
|
|
84
|
+
docx: "DOCX",
|
|
85
|
+
sheet: "表格",
|
|
86
|
+
video: "视频",
|
|
87
|
+
audio: "音频",
|
|
88
|
+
unsupported: "下载"
|
|
89
|
+
}, p = f(() => oe(a.value.name)), H = f(() => Z[p.value]), $ = f(() => o.fileName || a.value.name || o.dialogTitle), h = f(() => o.mode === "dialog"), q = f(() => h.value ? o.visible : !0), P = f(() => `${a.value.src}::${y.value}`), _ = f(
|
|
90
|
+
() => [
|
|
91
|
+
a.value.src,
|
|
92
|
+
a.value.extension,
|
|
93
|
+
o.textEncoding,
|
|
94
|
+
o.maxTextBytes,
|
|
95
|
+
o.maxSheetRows,
|
|
96
|
+
o.maxSheetCols,
|
|
97
|
+
o.pdfScale,
|
|
98
|
+
y.value
|
|
99
|
+
].join("::")
|
|
100
|
+
), B = f(() => p.value === "image" ? "img" : p.value === "video" ? "video" : p.value === "audio" ? "audio" : null);
|
|
101
|
+
U(
|
|
102
|
+
() => [o.source, o.fileName],
|
|
103
|
+
() => {
|
|
104
|
+
var i, u;
|
|
105
|
+
(i = g.value) == null || i.call(g), a.value = K(o.source, o.fileName), g.value = (u = a.value.cleanup) != null ? u : null, b.value = "", x.value = !1, y.value += 1;
|
|
106
|
+
},
|
|
107
|
+
{ immediate: !0 }
|
|
108
|
+
), U(
|
|
109
|
+
() => [o.textEncoding, o.maxTextBytes, o.maxSheetRows, o.maxSheetCols, o.pdfScale],
|
|
110
|
+
() => {
|
|
111
|
+
b.value = "", x.value = !1, y.value += 1;
|
|
112
|
+
}
|
|
113
|
+
), U(
|
|
114
|
+
() => o.visible,
|
|
115
|
+
(i, u) => {
|
|
116
|
+
if (h.value) {
|
|
117
|
+
if (!i) {
|
|
118
|
+
x.value = !1;
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
u || (b.value = "", x.value = !1, y.value += 1);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
), U(
|
|
125
|
+
() => o.mode,
|
|
126
|
+
(i, u) => {
|
|
127
|
+
i === "dialog" && u !== "dialog" && o.visible && (b.value = "", x.value = !1, y.value += 1);
|
|
128
|
+
}
|
|
129
|
+
), X(() => {
|
|
130
|
+
var i;
|
|
131
|
+
(i = g.value) == null || i.call(g);
|
|
132
|
+
});
|
|
133
|
+
function F() {
|
|
134
|
+
A("update:visible", !1);
|
|
135
|
+
}
|
|
136
|
+
function M() {
|
|
137
|
+
ae(a.value.src, a.value.name);
|
|
138
|
+
}
|
|
139
|
+
function T(i) {
|
|
140
|
+
b.value = i.message, A("error", i);
|
|
141
|
+
}
|
|
142
|
+
function C(i) {
|
|
143
|
+
x.value = i;
|
|
144
|
+
}
|
|
145
|
+
return (i, u) => (s(), k(W, {
|
|
146
|
+
to: "body",
|
|
147
|
+
disabled: !h.value
|
|
148
|
+
}, [
|
|
149
|
+
q.value ? (s(), v("div", {
|
|
150
|
+
key: 0,
|
|
151
|
+
class: G(["lfp-wrapper", { "is-dialog": h.value }])
|
|
152
|
+
}, [
|
|
153
|
+
h.value ? (s(), v("div", {
|
|
154
|
+
key: 0,
|
|
155
|
+
class: "lfp-backdrop",
|
|
156
|
+
onClick: F
|
|
157
|
+
})) : L("", !0),
|
|
158
|
+
l("section", {
|
|
159
|
+
class: "lfp-panel",
|
|
160
|
+
role: "dialog",
|
|
161
|
+
"aria-modal": h.value ? "true" : "false"
|
|
162
|
+
}, [
|
|
163
|
+
e.showToolbar ? (s(), v("header", se, [
|
|
164
|
+
l("div", ie, [
|
|
165
|
+
l("strong", ue, D($.value), 1),
|
|
166
|
+
l("span", re, D(H.value), 1)
|
|
167
|
+
]),
|
|
168
|
+
l("div", ce, [
|
|
169
|
+
l("button", {
|
|
170
|
+
class: "lfp-button lfp-icon-button",
|
|
171
|
+
type: "button",
|
|
172
|
+
"aria-label": "Download",
|
|
173
|
+
title: "Download",
|
|
174
|
+
onClick: M
|
|
175
|
+
}, [...u[0] || (u[0] = [
|
|
176
|
+
l("svg", {
|
|
177
|
+
viewBox: "0 0 24 24",
|
|
178
|
+
"aria-hidden": "true"
|
|
179
|
+
}, [
|
|
180
|
+
l("path", { d: "M12 3.5a1 1 0 0 1 1 1V12l2.8-2.8a1 1 0 1 1 1.4 1.42l-4.5 4.48a1 1 0 0 1-1.4 0l-4.5-4.48a1 1 0 0 1 1.4-1.42L11 12V4.5a1 1 0 0 1 1-1Zm-7 13a1 1 0 0 1 1 1v.75c0 .41.34.75.75.75h10.5a.75.75 0 0 0 .75-.75v-.75a1 1 0 1 1 2 0v.75A2.75 2.75 0 0 1 17.25 21H6.75A2.75 2.75 0 0 1 4 18.25v-.75a1 1 0 0 1 1-1Z" })
|
|
181
|
+
], -1)
|
|
182
|
+
])]),
|
|
183
|
+
h.value ? (s(), v("button", {
|
|
184
|
+
key: 0,
|
|
185
|
+
class: "lfp-button lfp-button is-ghost lfp-icon-button",
|
|
186
|
+
type: "button",
|
|
187
|
+
"aria-label": "Close",
|
|
188
|
+
title: "Close",
|
|
189
|
+
onClick: F
|
|
190
|
+
}, [...u[1] || (u[1] = [
|
|
191
|
+
l("svg", {
|
|
192
|
+
viewBox: "0 0 24 24",
|
|
193
|
+
"aria-hidden": "true"
|
|
194
|
+
}, [
|
|
195
|
+
l("path", { d: "M6.7 5.3a1 1 0 0 1 1.4 0L12 9.17l3.9-3.88a1 1 0 1 1 1.4 1.42L13.4 10.6l3.9 3.89a1 1 0 0 1-1.4 1.42L12 12.03l-3.9 3.88a1 1 0 0 1-1.4-1.42l3.9-3.89-3.9-3.89a1 1 0 0 1 0-1.42Z" })
|
|
196
|
+
], -1)
|
|
197
|
+
])])) : L("", !0)
|
|
198
|
+
])
|
|
199
|
+
])) : L("", !0),
|
|
200
|
+
l("div", de, [
|
|
201
|
+
J(Q, { name: "lfp-fade" }, {
|
|
202
|
+
default: Y(() => [
|
|
203
|
+
x.value ? (s(), v("div", ve, [
|
|
204
|
+
u[2] || (u[2] = l("span", { class: "lfp-spinner" }, null, -1)),
|
|
205
|
+
l("span", null, D(e.loadingText), 1)
|
|
206
|
+
])) : L("", !0)
|
|
207
|
+
]),
|
|
208
|
+
_: 1
|
|
209
|
+
}),
|
|
210
|
+
b.value ? (s(), v("div", me, [
|
|
211
|
+
l("p", null, D(b.value), 1),
|
|
212
|
+
l("button", {
|
|
213
|
+
class: "lfp-button lfp-icon-button",
|
|
214
|
+
type: "button",
|
|
215
|
+
"aria-label": "Download",
|
|
216
|
+
title: "Download",
|
|
217
|
+
onClick: M
|
|
218
|
+
}, [...u[3] || (u[3] = [
|
|
219
|
+
l("svg", {
|
|
220
|
+
viewBox: "0 0 24 24",
|
|
221
|
+
"aria-hidden": "true"
|
|
222
|
+
}, [
|
|
223
|
+
l("path", { d: "M12 3.5a1 1 0 0 1 1 1V12l2.8-2.8a1 1 0 1 1 1.4 1.42l-4.5 4.48a1 1 0 0 1-1.4 0l-4.5-4.48a1 1 0 0 1 1.4-1.42L11 12V4.5a1 1 0 0 1 1-1Zm-7 13a1 1 0 0 1 1 1v.75c0 .41.34.75.75.75h10.5a.75.75 0 0 0 .75-.75v-.75a1 1 0 1 1 2 0v.75A2.75 2.75 0 0 1 17.25 21H6.75A2.75 2.75 0 0 1 4 18.25v-.75a1 1 0 0 1 1-1Z" })
|
|
224
|
+
], -1)
|
|
225
|
+
])])
|
|
226
|
+
])) : (s(), v(ee, { key: 1 }, [
|
|
227
|
+
B.value === "img" ? (s(), v("img", {
|
|
228
|
+
key: P.value,
|
|
229
|
+
class: "lfp-image",
|
|
230
|
+
src: a.value.src,
|
|
231
|
+
alt: a.value.name,
|
|
232
|
+
loading: "lazy"
|
|
233
|
+
}, null, 8, pe)) : B.value === "video" ? (s(), v("video", {
|
|
234
|
+
key: P.value,
|
|
235
|
+
class: "lfp-media",
|
|
236
|
+
src: a.value.src,
|
|
237
|
+
controls: "",
|
|
238
|
+
preload: "metadata"
|
|
239
|
+
}, null, 8, fe)) : B.value === "audio" ? (s(), v("audio", {
|
|
240
|
+
key: P.value,
|
|
241
|
+
class: "lfp-audio",
|
|
242
|
+
src: a.value.src,
|
|
243
|
+
controls: "",
|
|
244
|
+
preload: "metadata"
|
|
245
|
+
}, null, 8, ge)) : p.value === "pdf" ? (s(), k(S(n), {
|
|
246
|
+
key: _.value,
|
|
247
|
+
source: typeof o.source == "string" ? a.value.src : o.source,
|
|
248
|
+
scale: e.pdfScale,
|
|
249
|
+
onLoading: C,
|
|
250
|
+
onError: T
|
|
251
|
+
}, null, 8, ["source", "scale"])) : p.value === "docx" ? (s(), k(S(r), {
|
|
252
|
+
key: _.value,
|
|
253
|
+
source: typeof o.source == "string" ? a.value.src : o.source,
|
|
254
|
+
onLoading: C,
|
|
255
|
+
onError: T
|
|
256
|
+
}, null, 8, ["source"])) : p.value === "sheet" ? (s(), k(S(m), {
|
|
257
|
+
key: _.value,
|
|
258
|
+
source: typeof o.source == "string" ? a.value.src : o.source,
|
|
259
|
+
"max-cols": e.maxSheetCols,
|
|
260
|
+
"max-rows": e.maxSheetRows,
|
|
261
|
+
onLoading: C,
|
|
262
|
+
onError: T
|
|
263
|
+
}, null, 8, ["source", "max-cols", "max-rows"])) : p.value === "text" ? (s(), k(S(c), {
|
|
264
|
+
key: _.value,
|
|
265
|
+
source: typeof o.source == "string" ? a.value.src : o.source,
|
|
266
|
+
encoding: e.textEncoding,
|
|
267
|
+
extension: a.value.extension,
|
|
268
|
+
"max-bytes": e.maxTextBytes,
|
|
269
|
+
onLoading: C,
|
|
270
|
+
onError: T
|
|
271
|
+
}, null, 8, ["source", "encoding", "extension", "max-bytes"])) : (s(), k(S(d), {
|
|
272
|
+
key: 7,
|
|
273
|
+
"file-name": a.value.name,
|
|
274
|
+
src: a.value.src
|
|
275
|
+
}, null, 8, ["file-name", "src"]))
|
|
276
|
+
], 64))
|
|
277
|
+
])
|
|
278
|
+
], 8, le)
|
|
279
|
+
], 2)) : L("", !0)
|
|
280
|
+
], 8, ["disabled"]));
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
function xe(e) {
|
|
284
|
+
if (typeof e == "string") {
|
|
285
|
+
const t = document.querySelector(e);
|
|
286
|
+
if (!t)
|
|
287
|
+
throw new Error(`未找到挂载节点:${e}`);
|
|
288
|
+
return t;
|
|
289
|
+
}
|
|
290
|
+
return e;
|
|
291
|
+
}
|
|
292
|
+
function be(e, t) {
|
|
293
|
+
const n = N({ ...t }), c = xe(e), r = O({
|
|
294
|
+
render: () => V(I, n)
|
|
295
|
+
});
|
|
296
|
+
return r.mount(c), {
|
|
297
|
+
update(m) {
|
|
298
|
+
Object.assign(n, m);
|
|
299
|
+
},
|
|
300
|
+
unmount() {
|
|
301
|
+
r.unmount();
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
function he(e) {
|
|
306
|
+
const t = document.createElement("div");
|
|
307
|
+
document.body.append(t);
|
|
308
|
+
let n;
|
|
309
|
+
const c = e["onUpdate:visible"], r = N({
|
|
310
|
+
visible: !0,
|
|
311
|
+
mode: "dialog",
|
|
312
|
+
...e,
|
|
313
|
+
"onUpdate:visible"(d) {
|
|
314
|
+
c == null || c(d), r.visible = d, d || queueMicrotask(() => n.unmount());
|
|
315
|
+
}
|
|
316
|
+
}), m = O({
|
|
317
|
+
render: () => V(I, r)
|
|
318
|
+
});
|
|
319
|
+
return m.mount(t), n = {
|
|
320
|
+
update(d) {
|
|
321
|
+
Object.assign(r, d);
|
|
322
|
+
},
|
|
323
|
+
unmount() {
|
|
324
|
+
m.unmount(), t.remove();
|
|
325
|
+
}
|
|
326
|
+
}, n;
|
|
327
|
+
}
|
|
328
|
+
function ye() {
|
|
329
|
+
const e = {
|
|
330
|
+
mount: be,
|
|
331
|
+
openDialog: he
|
|
332
|
+
};
|
|
333
|
+
return typeof window != "undefined" && (window.LightFilePreview = e), e;
|
|
334
|
+
}
|
|
335
|
+
const ke = {
|
|
336
|
+
install(e) {
|
|
337
|
+
e.component("LightFilePreview", I);
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
export {
|
|
341
|
+
I as _,
|
|
342
|
+
ae as d,
|
|
343
|
+
ke as i,
|
|
344
|
+
he as o,
|
|
345
|
+
ye as r
|
|
346
|
+
};
|