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