@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.
Files changed (53) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +122 -0
  3. package/dist/DocxRenderer-B8Ed3qFw.js +42 -0
  4. package/dist/PdfRenderer-CYtwJLrP.js +57 -0
  5. package/dist/SheetRenderer-C9AKQiKN.js +77 -0
  6. package/dist/TextRenderer-W4uPsa5O.js +59 -0
  7. package/dist/UnsupportedRenderer-BpyBTIIE.js +32 -0
  8. package/dist/docx-preview-B2OPGnfm.js +5525 -0
  9. package/dist/index-BlBE9ZR-.js +304 -0
  10. package/dist/light-file-preview.js +7 -0
  11. package/dist/light-file-preview.umd.cjs +209 -0
  12. package/dist/marked.esm-toXckLRC.js +1577 -0
  13. package/dist/pdf-B2JYpzlX.js +14597 -0
  14. package/dist/purify.es-D5dazAgD.js +553 -0
  15. package/dist/standalone/light-file-preview.iife.js +236 -0
  16. package/dist/standalone/style.css +1 -0
  17. package/dist/style.css +1 -0
  18. package/dist/text-CcxmtFce.js +24 -0
  19. package/dist/types/App.vue.d.ts +2 -0
  20. package/dist/types/DocsApp.vue.d.ts +2 -0
  21. package/dist/types/components/FilePreview.vue.d.ts +34 -0
  22. package/dist/types/components/renderers/DocxRenderer.vue.d.ts +12 -0
  23. package/dist/types/components/renderers/PdfRenderer.vue.d.ts +13 -0
  24. package/dist/types/components/renderers/SheetRenderer.vue.d.ts +14 -0
  25. package/dist/types/components/renderers/TextRenderer.vue.d.ts +15 -0
  26. package/dist/types/components/renderers/UnsupportedRenderer.vue.d.ts +6 -0
  27. package/dist/types/constants/file.d.ts +12 -0
  28. package/dist/types/docs-main.d.ts +1 -0
  29. package/dist/types/index.d.ts +10 -0
  30. package/dist/types/main.d.ts +1 -0
  31. package/dist/types/standalone-api.d.ts +17 -0
  32. package/dist/types/standalone.d.ts +6 -0
  33. package/dist/types/types.d.ts +17 -0
  34. package/dist/types/utils/download.d.ts +1 -0
  35. package/dist/types/utils/source.d.ts +9 -0
  36. package/dist/types/utils/text.d.ts +3 -0
  37. package/dist/types/vue2.d.ts +8 -0
  38. package/dist/vue2/DocxRenderer-IkLQeCjg.js +42 -0
  39. package/dist/vue2/PdfRenderer-DmgMRpqS.js +57 -0
  40. package/dist/vue2/SheetRenderer-CuAyFgj9.js +77 -0
  41. package/dist/vue2/TextRenderer-Bxqs7APd.js +59 -0
  42. package/dist/vue2/UnsupportedRenderer-Cs2uPl_6.js +31 -0
  43. package/dist/vue2/docx-preview-B2OPGnfm.js +5525 -0
  44. package/dist/vue2/light-file-preview-vue2.js +5 -0
  45. package/dist/vue2/light-file-preview-vue2.umd.cjs +236 -0
  46. package/dist/vue2/marked.esm-toXckLRC.js +1577 -0
  47. package/dist/vue2/pdf-B2JYpzlX.js +14597 -0
  48. package/dist/vue2/purify.es-D5dazAgD.js +553 -0
  49. package/dist/vue2/text-CcxmtFce.js +24 -0
  50. package/dist/vue2/vue2-CzAkhodr.js +6206 -0
  51. package/dist/vue2/xlsx-CZNBZqms.js +24774 -0
  52. package/dist/xlsx-CZNBZqms.js +24774 -0
  53. package/package.json +66 -0
@@ -0,0 +1,77 @@
1
+ import { d as B, g as $, o as E, a as F, b as e, c as t, F as f, h as v, e as w, t as r, f as b, r as k, n as L } from "./vue2-CzAkhodr.js";
2
+ import { r as M } from "./text-CcxmtFce.js";
3
+ const N = { class: "lfp-document lfp-sheet" }, V = {
4
+ key: 0,
5
+ class: "lfp-sheet__tabs"
6
+ }, X = ["onClick"], j = {
7
+ key: 1,
8
+ class: "lfp-hint"
9
+ }, z = {
10
+ key: 2,
11
+ class: "lfp-sheet__table-wrap"
12
+ }, A = { class: "lfp-sheet__table" }, W = /* @__PURE__ */ B({
13
+ __name: "SheetRenderer",
14
+ props: {
15
+ source: {},
16
+ maxRows: {},
17
+ maxCols: {}
18
+ },
19
+ emits: ["loading", "error"],
20
+ setup(u, { emit: C }) {
21
+ const i = u, m = C, y = new AbortController(), d = k(0), c = k([]), s = $(() => c.value[d.value]);
22
+ async function g() {
23
+ m("loading", !0);
24
+ try {
25
+ const l = await M(i.source, y.signal), h = await import("./xlsx-CZNBZqms.js"), o = h.read(l, { type: "array" });
26
+ c.value = o.SheetNames.map((a) => {
27
+ const n = h.utils.sheet_to_json(o.Sheets[a], {
28
+ header: 1,
29
+ raw: !1,
30
+ defval: ""
31
+ }), _ = n.length, S = n.reduce((p, R) => Math.max(p, R.length), 0), x = n.slice(0, i.maxRows).map((p) => p.slice(0, i.maxCols).map(String));
32
+ return {
33
+ name: a,
34
+ rows: x,
35
+ totalRows: _,
36
+ totalCols: S
37
+ };
38
+ });
39
+ } catch (l) {
40
+ m("error", l instanceof Error ? l : new Error("表格预览失败"));
41
+ } finally {
42
+ m("loading", !1);
43
+ }
44
+ }
45
+ return E(() => {
46
+ g();
47
+ }), F(() => {
48
+ y.abort();
49
+ }), (l, h) => (e(), t("div", N, [
50
+ c.value.length > 1 ? (e(), t("div", V, [
51
+ (e(!0), t(f, null, v(c.value, (o, a) => (e(), t("button", {
52
+ key: o.name,
53
+ class: L(["lfp-sheet__tab", { "is-active": a === d.value }]),
54
+ type: "button",
55
+ onClick: (n) => d.value = a
56
+ }, r(o.name), 11, X))), 128))
57
+ ])) : w("", !0),
58
+ s.value ? (e(), t("p", j, " 共 " + r(s.value.totalRows) + " 行," + r(s.value.totalCols) + " 列。当前最多展示 " + r(u.maxRows) + " 行、" + r(u.maxCols) + " 列。 ", 1)) : w("", !0),
59
+ s.value ? (e(), t("div", z, [
60
+ b("table", A, [
61
+ b("tbody", null, [
62
+ (e(!0), t(f, null, v(s.value.rows, (o, a) => (e(), t("tr", {
63
+ key: `${s.value.name}-${a}`
64
+ }, [
65
+ (e(!0), t(f, null, v(o, (n, _) => (e(), t("td", {
66
+ key: `${a}-${_}`
67
+ }, r(n), 1))), 128))
68
+ ]))), 128))
69
+ ])
70
+ ])
71
+ ])) : w("", !0)
72
+ ]));
73
+ }
74
+ });
75
+ export {
76
+ W as default
77
+ };
@@ -0,0 +1,59 @@
1
+ import { d as g, g as f, o as h, a as k, b as n, c as a, t as p, e as B, f as w, r as l } from "./vue2-CzAkhodr.js";
2
+ import { a as M } from "./text-CcxmtFce.js";
3
+ const C = { class: "lfp-document" }, T = {
4
+ key: 0,
5
+ class: "lfp-hint"
6
+ }, b = ["innerHTML"], N = {
7
+ key: 2,
8
+ class: "lfp-code"
9
+ }, H = /* @__PURE__ */ g({
10
+ __name: "TextRenderer",
11
+ props: {
12
+ source: {},
13
+ encoding: {},
14
+ extension: {},
15
+ maxBytes: {}
16
+ },
17
+ emits: ["loading", "error"],
18
+ setup(c, { emit: v }) {
19
+ const e = c, s = v, t = l(""), i = l(!1), u = new AbortController(), r = l(""), d = f(() => e.extension === "md"), y = f(() => e.extension === "json");
20
+ async function x() {
21
+ s("loading", !0);
22
+ try {
23
+ t.value = await M(e.source, e.encoding, e.maxBytes, u.signal);
24
+ const o = typeof e.source == "string" ? t.value.length : e.source.size;
25
+ if (i.value = o > e.maxBytes, y.value)
26
+ try {
27
+ t.value = JSON.stringify(JSON.parse(t.value), null, 2);
28
+ } catch {
29
+ }
30
+ if (d.value) {
31
+ const [{ marked: m }, { default: _ }] = await Promise.all([import("./marked.esm-toXckLRC.js"), import("./purify.es-D5dazAgD.js")]);
32
+ r.value = _.sanitize(m.parse(t.value));
33
+ } else
34
+ r.value = "";
35
+ } catch (o) {
36
+ s("error", o instanceof Error ? o : new Error("文本预览失败"));
37
+ } finally {
38
+ s("loading", !1);
39
+ }
40
+ }
41
+ return h(() => {
42
+ x();
43
+ }), k(() => {
44
+ u.abort();
45
+ }), (o, m) => (n(), a("div", C, [
46
+ i.value ? (n(), a("p", T, "文件较大,当前仅展示前 " + p(Math.round(c.maxBytes / 1024)) + " KB 内容。", 1)) : B("", !0),
47
+ d.value ? (n(), a("article", {
48
+ key: 1,
49
+ class: "lfp-markdown",
50
+ innerHTML: r.value
51
+ }, null, 8, b)) : (n(), a("pre", N, [
52
+ w("code", null, p(t.value), 1)
53
+ ]))
54
+ ]));
55
+ }
56
+ });
57
+ export {
58
+ H as default
59
+ };
@@ -0,0 +1,31 @@
1
+ import { d as n, b as l, c as o, f as t, t as s, u as i, i as r } from "./vue2-CzAkhodr.js";
2
+ const d = { class: "lfp-empty" }, p = { class: "lfp-hint" }, c = /* @__PURE__ */ n({
3
+ __name: "UnsupportedRenderer",
4
+ props: {
5
+ fileName: {},
6
+ src: {}
7
+ },
8
+ setup(a) {
9
+ return (f, e) => (l(), o("div", d, [
10
+ e[2] || (e[2] = t("p", null, "暂不支持当前格式的在线预览。", -1)),
11
+ t("p", p, "文件名:" + s(a.fileName), 1),
12
+ t("button", {
13
+ class: "lfp-button lfp-icon-button",
14
+ type: "button",
15
+ "aria-label": "Download",
16
+ title: "Download",
17
+ onClick: e[0] || (e[0] = (u) => i(r)(a.src, a.fileName))
18
+ }, [...e[1] || (e[1] = [
19
+ t("svg", {
20
+ viewBox: "0 0 24 24",
21
+ "aria-hidden": "true"
22
+ }, [
23
+ t("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" })
24
+ ], -1)
25
+ ])])
26
+ ]));
27
+ }
28
+ });
29
+ export {
30
+ c as default
31
+ };