@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 { defineComponent as $, ref as k, computed as B, onMounted as E, onBeforeUnmount as L, openBlock as e, createElementBlock as t, Fragment as v, renderList as f, normalizeClass as M, toDisplayString as r, createCommentVNode as w, createElementVNode as b } from "vue";
2
+ import { r as N } from "./text-CcxmtFce.js";
3
+ const V = { class: "lfp-document lfp-sheet" }, X = {
4
+ key: 0,
5
+ class: "lfp-sheet__tabs"
6
+ }, j = ["onClick"], z = {
7
+ key: 1,
8
+ class: "lfp-hint"
9
+ }, A = {
10
+ key: 2,
11
+ class: "lfp-sheet__table-wrap"
12
+ }, D = { class: "lfp-sheet__table" }, W = /* @__PURE__ */ $({
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([]), n = B(() => c.value[d.value]);
22
+ async function g() {
23
+ m("loading", !0);
24
+ try {
25
+ const l = await N(i.source, y.signal), h = await import("./xlsx-CZNBZqms.js"), a = h.read(l, { type: "array" });
26
+ c.value = a.SheetNames.map((o) => {
27
+ const s = h.utils.sheet_to_json(a.Sheets[o], {
28
+ header: 1,
29
+ raw: !1,
30
+ defval: ""
31
+ }), _ = s.length, S = s.reduce((p, R) => Math.max(p, R.length), 0), x = s.slice(0, i.maxRows).map((p) => p.slice(0, i.maxCols).map(String));
32
+ return {
33
+ name: o,
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
+ }), L(() => {
48
+ y.abort();
49
+ }), (l, h) => (e(), t("div", V, [
50
+ c.value.length > 1 ? (e(), t("div", X, [
51
+ (e(!0), t(v, null, f(c.value, (a, o) => (e(), t("button", {
52
+ key: a.name,
53
+ class: M(["lfp-sheet__tab", { "is-active": o === d.value }]),
54
+ type: "button",
55
+ onClick: (s) => d.value = o
56
+ }, r(a.name), 11, j))), 128))
57
+ ])) : w("", !0),
58
+ n.value ? (e(), t("p", z, " 共 " + r(n.value.totalRows) + " 行," + r(n.value.totalCols) + " 列。当前最多展示 " + r(u.maxRows) + " 行、" + r(u.maxCols) + " 列。 ", 1)) : w("", !0),
59
+ n.value ? (e(), t("div", A, [
60
+ b("table", D, [
61
+ b("tbody", null, [
62
+ (e(!0), t(v, null, f(n.value.rows, (a, o) => (e(), t("tr", {
63
+ key: `${n.value.name}-${o}`
64
+ }, [
65
+ (e(!0), t(v, null, f(a, (s, _) => (e(), t("td", {
66
+ key: `${o}-${_}`
67
+ }, r(s), 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 { defineComponent as g, ref as l, computed as f, onMounted as h, onBeforeUnmount as k, openBlock as n, createElementBlock as r, toDisplayString as p, createCommentVNode as B, createElementVNode as w } from "vue";
2
+ import { a as M } from "./text-CcxmtFce.js";
3
+ const C = { class: "lfp-document" }, T = {
4
+ key: 0,
5
+ class: "lfp-hint"
6
+ }, E = ["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(i, { emit: v }) {
19
+ const e = i, a = v, t = l(""), c = l(!1), u = new AbortController(), s = l(""), d = f(() => e.extension === "md"), y = f(() => e.extension === "json");
20
+ async function x() {
21
+ a("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 (c.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
+ s.value = _.sanitize(m.parse(t.value));
33
+ } else
34
+ s.value = "";
35
+ } catch (o) {
36
+ a("error", o instanceof Error ? o : new Error("文本预览失败"));
37
+ } finally {
38
+ a("loading", !1);
39
+ }
40
+ }
41
+ return h(() => {
42
+ x();
43
+ }), k(() => {
44
+ u.abort();
45
+ }), (o, m) => (n(), r("div", C, [
46
+ c.value ? (n(), r("p", T, "文件较大,当前仅展示前 " + p(Math.round(i.maxBytes / 1024)) + " KB 内容。", 1)) : B("", !0),
47
+ d.value ? (n(), r("article", {
48
+ key: 1,
49
+ class: "lfp-markdown",
50
+ innerHTML: s.value
51
+ }, null, 8, E)) : (n(), r("pre", N, [
52
+ w("code", null, p(t.value), 1)
53
+ ]))
54
+ ]));
55
+ }
56
+ });
57
+ export {
58
+ H as default
59
+ };
@@ -0,0 +1,32 @@
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-BlBE9ZR-.js";
3
+ const d = { class: "lfp-empty" }, p = { class: "lfp-hint" }, c = /* @__PURE__ */ o({
4
+ __name: "UnsupportedRenderer",
5
+ props: {
6
+ fileName: {},
7
+ src: {}
8
+ },
9
+ setup(n) {
10
+ return (m, e) => (l(), a("div", d, [
11
+ e[2] || (e[2] = t("p", null, "暂不支持当前格式的在线预览。", -1)),
12
+ t("p", p, "文件名:" + i(n.fileName), 1),
13
+ t("button", {
14
+ class: "lfp-button lfp-icon-button",
15
+ type: "button",
16
+ "aria-label": "Download",
17
+ title: "Download",
18
+ onClick: e[0] || (e[0] = (f) => r(s)(n.src, n.fileName))
19
+ }, [...e[1] || (e[1] = [
20
+ t("svg", {
21
+ viewBox: "0 0 24 24",
22
+ "aria-hidden": "true"
23
+ }, [
24
+ 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" })
25
+ ], -1)
26
+ ])])
27
+ ]));
28
+ }
29
+ });
30
+ export {
31
+ c as default
32
+ };