@work-zhanguo/light-file-preview 0.0.12 → 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 +118 -91
- package/dist/SheetRenderer-Dr5f9ZTy.js +918 -0
- package/dist/{UnsupportedRenderer-_3Y2XGCI.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 +72 -72
- package/dist/standalone/light-file-preview.iife.js +52 -52
- package/dist/standalone/style.css +1 -1
- package/dist/style.css +1 -1
- package/dist/vue2/{DocxRenderer-BUzCqs85.js → DocxRenderer-DGXNIVsp.js} +1 -1
- package/dist/vue2/{PdfRenderer-pDvWG0pi.js → PdfRenderer-CANDrYvV.js} +1 -1
- package/dist/vue2/SheetRenderer-CM49qq4y.js +918 -0
- package/dist/vue2/{TextRenderer-B0bVXhgh.js → TextRenderer-CFNsDxIx.js} +1 -1
- package/dist/vue2/{UnsupportedRenderer-CvvKjt07.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 +53 -53
- package/dist/vue2/{vue2-CqSgN38_.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-D1DAXE1c.js +0 -706
- package/dist/index-wdafvObE.js +0 -305
- package/dist/vue2/SheetRenderer-Z48WXEZj.js +0 -706
package/dist/index-wdafvObE.js
DELETED
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
import { defineComponent as V, defineAsyncComponent as h, ref as U, computed as w, watch as Z, onBeforeUnmount as H, openBlock as s, createBlock as x, Teleport as K, createElementBlock as v, normalizeClass as q, createCommentVNode as y, createElementVNode as a, toDisplayString as E, createVNode as z, Transition as X, withCtx as $, Fragment as G, unref as k, reactive as A, createApp as F, h as M } from "vue";
|
|
2
|
-
const g = {
|
|
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
|
-
}, J = ["doc", "ppt", "pptx"];
|
|
11
|
-
function S(e = "") {
|
|
12
|
-
const o = e.split("#")[0].split("?")[0].split(".");
|
|
13
|
-
return o.length > 1 ? o[o.length - 1].toLowerCase() : "";
|
|
14
|
-
}
|
|
15
|
-
function Q(e) {
|
|
16
|
-
const t = S(e);
|
|
17
|
-
return g.image.includes(t) ? "image" : g.pdf.includes(t) ? "pdf" : g.docx.includes(t) ? "docx" : g.sheet.includes(t) ? "sheet" : g.video.includes(t) ? "video" : g.audio.includes(t) ? "audio" : g.text.includes(t) ? t === "csv" ? "sheet" : "text" : (J.includes(t), "unsupported");
|
|
18
|
-
}
|
|
19
|
-
function W(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((o) => encodeURIComponent(decodeURIComponent(o))).join("/"), t.toString();
|
|
25
|
-
} catch (t) {
|
|
26
|
-
return e.split("/").map((o) => encodeURIComponent(decodeURIComponent(o))).join("/");
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
function I(e, t) {
|
|
30
|
-
var i;
|
|
31
|
-
if (typeof e == "string") {
|
|
32
|
-
const p = W(e), d = e.split("/"), l = (i = t != null ? t : d[d.length - 1]) != null ? i : "unknown";
|
|
33
|
-
return {
|
|
34
|
-
source: e,
|
|
35
|
-
src: p,
|
|
36
|
-
name: decodeURIComponent(l.split("?")[0].split("#")[0]),
|
|
37
|
-
extension: S(l)
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
const o = URL.createObjectURL(e), c = t != null ? t : "name" in e && typeof e.name == "string" ? e.name : "blob";
|
|
41
|
-
return {
|
|
42
|
-
source: e,
|
|
43
|
-
src: o,
|
|
44
|
-
name: c,
|
|
45
|
-
extension: S(c),
|
|
46
|
-
cleanup: () => URL.revokeObjectURL(o)
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
function Y(e, t) {
|
|
50
|
-
const o = document.createElement("a");
|
|
51
|
-
o.href = e, o.download = t, o.target = "_blank", o.rel = "noopener", document.body.append(o), o.click(), o.remove();
|
|
52
|
-
}
|
|
53
|
-
const ee = ["aria-modal"], te = {
|
|
54
|
-
key: 0,
|
|
55
|
-
class: "lfp-toolbar"
|
|
56
|
-
}, oe = { class: "lfp-toolbar__meta" }, ne = { class: "lfp-title" }, le = { class: "lfp-badge" }, ae = { class: "lfp-toolbar__actions" }, se = { class: "lfp-content" }, ie = {
|
|
57
|
-
key: 0,
|
|
58
|
-
class: "lfp-loading"
|
|
59
|
-
}, re = {
|
|
60
|
-
key: 0,
|
|
61
|
-
class: "lfp-error"
|
|
62
|
-
}, ue = ["src", "alt"], ce = ["src"], de = ["src"], C = /* @__PURE__ */ V({
|
|
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 o = h(() => import("./PdfRenderer-Due2M5cA.js")), c = h(() => import("./TextRenderer-KUhpnf63.js")), i = h(() => import("./DocxRenderer-DogNhBLd.js")), p = h(() => import("./SheetRenderer-D1DAXE1c.js")), d = h(() => import("./UnsupportedRenderer-_3Y2XGCI.js")), l = e, D = t, f = U(null), j = U(!1), L = U(""), n = U(I(l.source, l.fileName)), m = w(() => Q(n.value.name)), N = w(() => l.fileName || n.value.name || l.dialogTitle), b = w(() => l.mode === "dialog"), O = w(() => b.value ? l.visible : !0), T = w(() => m.value === "image" ? "img" : m.value === "video" ? "video" : m.value === "audio" ? "audio" : null);
|
|
81
|
-
Z(
|
|
82
|
-
() => [l.source, l.fileName],
|
|
83
|
-
() => {
|
|
84
|
-
var r, u;
|
|
85
|
-
(r = f.value) == null || r.call(f), n.value = I(l.source, l.fileName), f.value = (u = n.value.cleanup) != null ? u : null, L.value = "";
|
|
86
|
-
},
|
|
87
|
-
{ immediate: !0 }
|
|
88
|
-
), H(() => {
|
|
89
|
-
var r;
|
|
90
|
-
(r = f.value) == null || r.call(f);
|
|
91
|
-
});
|
|
92
|
-
function B() {
|
|
93
|
-
D("update:visible", !1);
|
|
94
|
-
}
|
|
95
|
-
function P() {
|
|
96
|
-
Y(n.value.src, n.value.name);
|
|
97
|
-
}
|
|
98
|
-
function R(r) {
|
|
99
|
-
L.value = r.message, D("error", r);
|
|
100
|
-
}
|
|
101
|
-
function _(r) {
|
|
102
|
-
j.value = r;
|
|
103
|
-
}
|
|
104
|
-
return (r, u) => (s(), x(K, {
|
|
105
|
-
to: "body",
|
|
106
|
-
disabled: !b.value
|
|
107
|
-
}, [
|
|
108
|
-
O.value ? (s(), v("div", {
|
|
109
|
-
key: 0,
|
|
110
|
-
class: q(["lfp-wrapper", { "is-dialog": b.value }])
|
|
111
|
-
}, [
|
|
112
|
-
b.value ? (s(), v("div", {
|
|
113
|
-
key: 0,
|
|
114
|
-
class: "lfp-backdrop",
|
|
115
|
-
onClick: B
|
|
116
|
-
})) : y("", !0),
|
|
117
|
-
a("section", {
|
|
118
|
-
class: "lfp-panel",
|
|
119
|
-
role: "dialog",
|
|
120
|
-
"aria-modal": b.value ? "true" : "false"
|
|
121
|
-
}, [
|
|
122
|
-
e.showToolbar ? (s(), v("header", te, [
|
|
123
|
-
a("div", oe, [
|
|
124
|
-
a("strong", ne, E(N.value), 1),
|
|
125
|
-
a("span", le, E(m.value), 1)
|
|
126
|
-
]),
|
|
127
|
-
a("div", ae, [
|
|
128
|
-
a("button", {
|
|
129
|
-
class: "lfp-button lfp-icon-button",
|
|
130
|
-
type: "button",
|
|
131
|
-
"aria-label": "Download",
|
|
132
|
-
title: "Download",
|
|
133
|
-
onClick: P
|
|
134
|
-
}, [...u[0] || (u[0] = [
|
|
135
|
-
a("svg", {
|
|
136
|
-
viewBox: "0 0 24 24",
|
|
137
|
-
"aria-hidden": "true"
|
|
138
|
-
}, [
|
|
139
|
-
a("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" })
|
|
140
|
-
], -1)
|
|
141
|
-
])]),
|
|
142
|
-
b.value ? (s(), v("button", {
|
|
143
|
-
key: 0,
|
|
144
|
-
class: "lfp-button lfp-button is-ghost lfp-icon-button",
|
|
145
|
-
type: "button",
|
|
146
|
-
"aria-label": "Close",
|
|
147
|
-
title: "Close",
|
|
148
|
-
onClick: B
|
|
149
|
-
}, [...u[1] || (u[1] = [
|
|
150
|
-
a("svg", {
|
|
151
|
-
viewBox: "0 0 24 24",
|
|
152
|
-
"aria-hidden": "true"
|
|
153
|
-
}, [
|
|
154
|
-
a("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" })
|
|
155
|
-
], -1)
|
|
156
|
-
])])) : y("", !0)
|
|
157
|
-
])
|
|
158
|
-
])) : y("", !0),
|
|
159
|
-
a("div", se, [
|
|
160
|
-
z(X, { name: "lfp-fade" }, {
|
|
161
|
-
default: $(() => [
|
|
162
|
-
j.value ? (s(), v("div", ie, [
|
|
163
|
-
u[2] || (u[2] = a("span", { class: "lfp-spinner" }, null, -1)),
|
|
164
|
-
a("span", null, E(e.loadingText), 1)
|
|
165
|
-
])) : y("", !0)
|
|
166
|
-
]),
|
|
167
|
-
_: 1
|
|
168
|
-
}),
|
|
169
|
-
L.value ? (s(), v("div", re, [
|
|
170
|
-
a("p", null, E(L.value), 1),
|
|
171
|
-
a("button", {
|
|
172
|
-
class: "lfp-button lfp-icon-button",
|
|
173
|
-
type: "button",
|
|
174
|
-
"aria-label": "Download",
|
|
175
|
-
title: "Download",
|
|
176
|
-
onClick: P
|
|
177
|
-
}, [...u[3] || (u[3] = [
|
|
178
|
-
a("svg", {
|
|
179
|
-
viewBox: "0 0 24 24",
|
|
180
|
-
"aria-hidden": "true"
|
|
181
|
-
}, [
|
|
182
|
-
a("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" })
|
|
183
|
-
], -1)
|
|
184
|
-
])])
|
|
185
|
-
])) : (s(), v(G, { key: 1 }, [
|
|
186
|
-
T.value === "img" ? (s(), v("img", {
|
|
187
|
-
key: n.value.src,
|
|
188
|
-
class: "lfp-image",
|
|
189
|
-
src: n.value.src,
|
|
190
|
-
alt: n.value.name,
|
|
191
|
-
loading: "lazy"
|
|
192
|
-
}, null, 8, ue)) : T.value === "video" ? (s(), v("video", {
|
|
193
|
-
key: n.value.src,
|
|
194
|
-
class: "lfp-media",
|
|
195
|
-
src: n.value.src,
|
|
196
|
-
controls: "",
|
|
197
|
-
preload: "metadata"
|
|
198
|
-
}, null, 8, ce)) : T.value === "audio" ? (s(), v("audio", {
|
|
199
|
-
key: n.value.src,
|
|
200
|
-
class: "lfp-audio",
|
|
201
|
-
src: n.value.src,
|
|
202
|
-
controls: "",
|
|
203
|
-
preload: "metadata"
|
|
204
|
-
}, null, 8, de)) : m.value === "pdf" ? (s(), x(k(o), {
|
|
205
|
-
key: n.value.src,
|
|
206
|
-
source: typeof l.source == "string" ? n.value.src : l.source,
|
|
207
|
-
scale: e.pdfScale,
|
|
208
|
-
onLoading: _,
|
|
209
|
-
onError: R
|
|
210
|
-
}, null, 8, ["source", "scale"])) : m.value === "docx" ? (s(), x(k(i), {
|
|
211
|
-
key: n.value.src,
|
|
212
|
-
source: typeof l.source == "string" ? n.value.src : l.source,
|
|
213
|
-
onLoading: _,
|
|
214
|
-
onError: R
|
|
215
|
-
}, null, 8, ["source"])) : m.value === "sheet" ? (s(), x(k(p), {
|
|
216
|
-
key: n.value.src,
|
|
217
|
-
source: typeof l.source == "string" ? n.value.src : l.source,
|
|
218
|
-
"max-cols": e.maxSheetCols,
|
|
219
|
-
"max-rows": e.maxSheetRows,
|
|
220
|
-
onLoading: _,
|
|
221
|
-
onError: R
|
|
222
|
-
}, null, 8, ["source", "max-cols", "max-rows"])) : m.value === "text" ? (s(), x(k(c), {
|
|
223
|
-
key: n.value.src,
|
|
224
|
-
source: typeof l.source == "string" ? n.value.src : l.source,
|
|
225
|
-
encoding: e.textEncoding,
|
|
226
|
-
extension: n.value.extension,
|
|
227
|
-
"max-bytes": e.maxTextBytes,
|
|
228
|
-
onLoading: _,
|
|
229
|
-
onError: R
|
|
230
|
-
}, null, 8, ["source", "encoding", "extension", "max-bytes"])) : (s(), x(k(d), {
|
|
231
|
-
key: 7,
|
|
232
|
-
"file-name": n.value.name,
|
|
233
|
-
src: n.value.src
|
|
234
|
-
}, null, 8, ["file-name", "src"]))
|
|
235
|
-
], 64))
|
|
236
|
-
])
|
|
237
|
-
], 8, ee)
|
|
238
|
-
], 2)) : y("", !0)
|
|
239
|
-
], 8, ["disabled"]));
|
|
240
|
-
}
|
|
241
|
-
});
|
|
242
|
-
function ve(e) {
|
|
243
|
-
if (typeof e == "string") {
|
|
244
|
-
const t = document.querySelector(e);
|
|
245
|
-
if (!t)
|
|
246
|
-
throw new Error(`未找到挂载节点:${e}`);
|
|
247
|
-
return t;
|
|
248
|
-
}
|
|
249
|
-
return e;
|
|
250
|
-
}
|
|
251
|
-
function pe(e, t) {
|
|
252
|
-
const o = A({ ...t }), c = ve(e), i = F({
|
|
253
|
-
render: () => M(C, o)
|
|
254
|
-
});
|
|
255
|
-
return i.mount(c), {
|
|
256
|
-
update(p) {
|
|
257
|
-
Object.assign(o, p);
|
|
258
|
-
},
|
|
259
|
-
unmount() {
|
|
260
|
-
i.unmount();
|
|
261
|
-
}
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
function me(e) {
|
|
265
|
-
const t = document.createElement("div");
|
|
266
|
-
document.body.append(t);
|
|
267
|
-
let o;
|
|
268
|
-
const c = e["onUpdate:visible"], i = A({
|
|
269
|
-
visible: !0,
|
|
270
|
-
mode: "dialog",
|
|
271
|
-
...e,
|
|
272
|
-
"onUpdate:visible"(d) {
|
|
273
|
-
c == null || c(d), i.visible = d, d || queueMicrotask(() => o.unmount());
|
|
274
|
-
}
|
|
275
|
-
}), p = F({
|
|
276
|
-
render: () => M(C, i)
|
|
277
|
-
});
|
|
278
|
-
return p.mount(t), o = {
|
|
279
|
-
update(d) {
|
|
280
|
-
Object.assign(i, d);
|
|
281
|
-
},
|
|
282
|
-
unmount() {
|
|
283
|
-
p.unmount(), t.remove();
|
|
284
|
-
}
|
|
285
|
-
}, o;
|
|
286
|
-
}
|
|
287
|
-
function ge() {
|
|
288
|
-
const e = {
|
|
289
|
-
mount: pe,
|
|
290
|
-
openDialog: me
|
|
291
|
-
};
|
|
292
|
-
return typeof window != "undefined" && (window.LightFilePreview = e), e;
|
|
293
|
-
}
|
|
294
|
-
const be = {
|
|
295
|
-
install(e) {
|
|
296
|
-
e.component("LightFilePreview", C);
|
|
297
|
-
}
|
|
298
|
-
};
|
|
299
|
-
export {
|
|
300
|
-
C as _,
|
|
301
|
-
Y as d,
|
|
302
|
-
be as i,
|
|
303
|
-
me as o,
|
|
304
|
-
ge as r
|
|
305
|
-
};
|