@l1yp/file-viewer 0.1.0 → 0.1.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 (29) hide show
  1. package/README.md +1 -0
  2. package/dist/components/DocxNavigationPane.js +7 -0
  3. package/dist/components/DocxNavigationPane.vue.d.ts +23 -0
  4. package/dist/components/DocxNavigationPane.vue_vue_type_script_setup_true_lang.js +96 -0
  5. package/dist/components/DocxViewer.js +1 -1
  6. package/dist/components/DocxViewer.vue_vue_type_script_setup_true_lang.js +70 -37
  7. package/dist/components/FileViewerBody.js +1 -1
  8. package/dist/components/FileViewerBody.vue.d.ts +5 -0
  9. package/dist/components/FileViewerBody.vue_vue_type_script_setup_true_lang.js +248 -247
  10. package/dist/components/PptxNavigationPane.js +7 -0
  11. package/dist/components/PptxNavigationPane.vue.d.ts +20 -0
  12. package/dist/components/PptxNavigationPane.vue_vue_type_script_setup_true_lang.js +118 -0
  13. package/dist/components/PptxViewer.js +1 -1
  14. package/dist/components/PptxViewer.vue_vue_type_script_setup_true_lang.js +64 -38
  15. package/dist/components/XlsxViewer.js +1 -1
  16. package/dist/components/XlsxViewer.vue_vue_type_script_setup_true_lang.js +299 -304
  17. package/dist/components/ZipBrowser.js +1 -1
  18. package/dist/components/ZipBrowser.vue.d.ts +3 -1
  19. package/dist/components/ZipBrowser.vue_vue_type_script_setup_true_lang.js +152 -122
  20. package/dist/composables/useElementNavigation.d.ts +21 -0
  21. package/dist/composables/useElementNavigation.js +61 -0
  22. package/dist/lib/archiveHtml.d.ts +49 -0
  23. package/dist/lib/archiveHtml.js +375 -0
  24. package/dist/lib/docxNavigation.d.ts +31 -0
  25. package/dist/lib/docxNavigation.js +63 -0
  26. package/dist/lib/pptxNavigation.d.ts +7 -0
  27. package/dist/lib/pptxNavigation.js +27 -0
  28. package/dist/style.css +1 -1
  29. package/package.json +1 -1
@@ -0,0 +1,7 @@
1
+ import e from "../_virtual/_plugin-vue_export-helper.js";
2
+ import t from "./PptxNavigationPane.vue_vue_type_script_setup_true_lang.js";
3
+ /* empty css */
4
+ //#region src/components/PptxNavigationPane.vue
5
+ var n = /*#__PURE__*/ e(t, [["__scopeId", "data-v-1de8828c"]]);
6
+ //#endregion
7
+ export { n as default };
@@ -0,0 +1,20 @@
1
+ import type { PptxViewer } from '@aiden0z/pptx-renderer';
2
+ import type { PptxNavigationItem } from '@/lib/pptxNavigation';
3
+ type __VLS_Props = {
4
+ viewer: PptxViewer;
5
+ items: readonly PptxNavigationItem[];
6
+ activeIndex: number;
7
+ };
8
+ type __VLS_ModelProps = {
9
+ 'collapsed'?: boolean;
10
+ };
11
+ type __VLS_PublicProps = __VLS_Props & __VLS_ModelProps;
12
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_PublicProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
13
+ navigate: (index: number) => any;
14
+ "update:collapsed": (value: boolean) => any;
15
+ }, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
16
+ onNavigate?: ((index: number) => any) | undefined;
17
+ "onUpdate:collapsed"?: ((value: boolean) => any) | undefined;
18
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
19
+ declare const _default: typeof __VLS_export;
20
+ export default _default;
@@ -0,0 +1,118 @@
1
+ import e from "./icons/Icon.js";
2
+ import { Fragment as t, createElementBlock as n, createElementVNode as r, createVNode as i, defineComponent as a, mergeModels as o, nextTick as s, normalizeClass as c, onBeforeUnmount as l, onMounted as u, openBlock as d, renderList as f, toDisplayString as p, useModel as m, useTemplateRef as h, watch as g } from "vue";
3
+ //#region src/components/PptxNavigationPane.vue?vue&type=script&setup=true&lang.ts
4
+ var _ = { class: "pn__header" }, v = { class: "pn__count" }, y = {
5
+ ref: "list",
6
+ class: "pn__list",
7
+ "aria-label": "幻灯片列表"
8
+ }, b = [
9
+ "data-nav-slide-index",
10
+ "aria-current",
11
+ "title",
12
+ "onClick"
13
+ ], x = { class: "pn__number" }, S = { class: "pn__preview-wrap" }, C = ["data-slide-index"], w = { class: "pn__label" }, T = /*@__PURE__*/ a({
14
+ __name: "PptxNavigationPane",
15
+ props: /*@__PURE__*/ o({
16
+ viewer: {},
17
+ items: {},
18
+ activeIndex: {}
19
+ }, {
20
+ collapsed: {
21
+ type: Boolean,
22
+ default: !1
23
+ },
24
+ collapsedModifiers: {}
25
+ }),
26
+ emits: /*@__PURE__*/ o(["navigate"], ["update:collapsed"]),
27
+ setup(a, { emit: o }) {
28
+ let T = a, E = o, D = m(a, "collapsed"), O = h("list"), k = /* @__PURE__ */ new Map(), A = /* @__PURE__ */ new Map(), j = null;
29
+ function M() {
30
+ j?.disconnect(), j = null;
31
+ for (let e of A.values()) e.dispose();
32
+ A.clear();
33
+ for (let e of k.values()) e.innerHTML = "";
34
+ }
35
+ function N(e, t) {
36
+ if (A.has(e)) return;
37
+ let n = T.viewer.renderThumbnailToContainer(e, t, { width: 104 });
38
+ n && (A.set(e, n), n.ready.catch(() => {
39
+ A.get(e) === n && (n.dispose(), A.delete(e), t.innerHTML = "");
40
+ }));
41
+ }
42
+ async function P() {
43
+ if (M(), D.value) return;
44
+ await s();
45
+ let e = O.value;
46
+ if (e) {
47
+ if (typeof IntersectionObserver > "u") {
48
+ for (let [e, t] of k) N(e, t);
49
+ return;
50
+ }
51
+ j = new IntersectionObserver((e) => {
52
+ for (let t of e) {
53
+ if (!t.isIntersecting) continue;
54
+ let e = t.target, n = Number(e.dataset.slideIndex);
55
+ Number.isInteger(n) && N(n, e), j?.unobserve(e);
56
+ }
57
+ }, {
58
+ root: e,
59
+ rootMargin: "140px 0px"
60
+ });
61
+ for (let e of k.values()) j.observe(e);
62
+ }
63
+ }
64
+ function F(e, t) {
65
+ let n = k.get(e);
66
+ if (n && n !== t && j?.unobserve(n), !(t instanceof HTMLElement)) {
67
+ k.delete(e);
68
+ return;
69
+ }
70
+ k.set(e, t), j?.observe(t);
71
+ }
72
+ return g(() => T.viewer, P, { flush: "post" }), g(() => T.items, P, { flush: "post" }), g(D, P, { flush: "post" }), g(() => T.activeIndex, async (e) => {
73
+ await s(), O.value?.querySelector(`[data-nav-slide-index="${e}"]`)?.scrollIntoView({ block: "nearest" });
74
+ }), u(P), l(M), (o, s) => (d(), n("aside", {
75
+ class: c(["pn", { "pn--collapsed": D.value }]),
76
+ "aria-label": "幻灯片导航"
77
+ }, [D.value ? (d(), n("button", {
78
+ key: 0,
79
+ type: "button",
80
+ class: "pn__reopen",
81
+ "aria-label": "展开幻灯片导航",
82
+ title: "展开幻灯片导航",
83
+ onClick: s[0] ||= (e) => D.value = !1
84
+ }, [i(e, {
85
+ name: "chevronRight",
86
+ size: 15
87
+ })])) : (d(), n(t, { key: 1 }, [r("header", _, [r("div", null, [s[2] ||= r("strong", { class: "pn__title" }, "幻灯片", -1), r("span", v, p(a.items.length) + " 张", 1)]), r("button", {
88
+ type: "button",
89
+ class: "pn__collapse",
90
+ "aria-label": "收起幻灯片导航",
91
+ title: "收起幻灯片导航",
92
+ onClick: s[1] ||= (e) => D.value = !0
93
+ }, [i(e, {
94
+ name: "chevronLeft",
95
+ size: 15
96
+ })])]), r("nav", y, [(d(!0), n(t, null, f(a.items, (e) => (d(), n("button", {
97
+ key: e.index,
98
+ type: "button",
99
+ class: c(["pn__item", { "pn__item--active": e.index === a.activeIndex }]),
100
+ "data-nav-slide-index": e.index,
101
+ "aria-current": e.index === a.activeIndex ? "page" : void 0,
102
+ title: `${e.index + 1}. ${e.title}`,
103
+ onClick: (t) => E("navigate", e.index)
104
+ }, [
105
+ r("span", x, p(e.index + 1), 1),
106
+ r("span", S, [r("span", {
107
+ ref_for: !0,
108
+ ref: (t) => F(e.index, t),
109
+ class: "pn__preview",
110
+ "data-slide-index": e.index,
111
+ "aria-hidden": "true"
112
+ }, null, 8, C)]),
113
+ r("span", w, p(e.title), 1)
114
+ ], 10, b))), 128))], 512)], 64))], 2));
115
+ }
116
+ });
117
+ //#endregion
118
+ export { T as default };
@@ -2,6 +2,6 @@ import e from "../_virtual/_plugin-vue_export-helper.js";
2
2
  import t from "./PptxViewer.vue_vue_type_script_setup_true_lang.js";
3
3
  /* empty css */
4
4
  //#region src/components/PptxViewer.vue
5
- var n = /*#__PURE__*/ e(t, [["__scopeId", "data-v-47d76691"]]);
5
+ var n = /*#__PURE__*/ e(t, [["__scopeId", "data-v-e6f736b9"]]);
6
6
  //#endregion
7
7
  export { n as default };
@@ -1,73 +1,99 @@
1
- import { createCommentVNode as e, createElementBlock as t, createElementVNode as n, defineComponent as r, onBeforeUnmount as i, onMounted as a, openBlock as o, ref as s, toDisplayString as c, watch as l } from "vue";
2
- import u from "pdfjs-dist/build/pdf.worker.min.mjs?url";
3
- import { PptxViewer as d, RECOMMENDED_ZIP_LIMITS as f } from "@aiden0z/pptx-renderer";
4
- import p from "pdfjs-dist/build/pdf.min.mjs?url";
1
+ import e from "./PptxNavigationPane.js";
2
+ import { buildPptxNavigation as t } from "../lib/pptxNavigation.js";
3
+ import { createBlock as n, createCommentVNode as r, createElementBlock as i, createElementVNode as a, defineComponent as o, onBeforeUnmount as s, onMounted as c, openBlock as l, shallowRef as u, toDisplayString as d, watch as f } from "vue";
4
+ import p from "pdfjs-dist/build/pdf.worker.min.mjs?url";
5
+ import { PptxViewer as m, RECOMMENDED_ZIP_LIMITS as h } from "@aiden0z/pptx-renderer";
6
+ import g from "pdfjs-dist/build/pdf.min.mjs?url";
5
7
  //#region src/components/PptxViewer.vue?vue&type=script&setup=true&lang.ts
6
- var m = { class: "pv" }, h = {
8
+ var _ = { class: "pv" }, v = { class: "pv__stage" }, y = {
7
9
  key: 0,
8
10
  class: "pv__overlay"
9
- }, g = {
11
+ }, b = {
10
12
  key: 1,
11
13
  class: "pv__overlay"
12
- }, _ = { class: "pv__msg pv__msg--error" }, v = /*@__PURE__*/ r({
14
+ }, x = { class: "pv__msg pv__msg--error" }, S = /*@__PURE__*/ o({
13
15
  __name: "PptxViewer",
14
16
  props: {
15
17
  url: {},
16
18
  name: {},
17
19
  size: {}
18
20
  },
19
- setup(r) {
20
- let v = r, y = s("loading"), b = s(""), x = s(null), S = null;
21
- function C() {
22
- if (S) {
21
+ setup(o) {
22
+ let S = o, C = u("loading"), w = u(""), T = u(null), E = u(null), D = u([]), O = u(0), k = u(!1), A = null, j = null, M;
23
+ function N() {
24
+ if (j = null, M && clearTimeout(M), M = void 0, E.value = null, D.value = [], A) {
23
25
  try {
24
- S.destroy();
26
+ A.destroy();
25
27
  } catch {}
26
- S = null;
28
+ A = null;
27
29
  }
28
30
  }
29
- async function w() {
30
- let e = x.value;
31
- if (!v.url || !e) return;
32
- y.value = "loading", b.value = "", C(), e.innerHTML = "";
33
- let t = v.url;
31
+ async function P() {
32
+ let e = T.value;
33
+ if (!S.url || !e) return;
34
+ C.value = "loading", w.value = "", N(), e.innerHTML = "";
35
+ let n = S.url;
34
36
  try {
35
- let n = await fetch(t);
36
- if (!n.ok) throw Error(`HTTP ${n.status}`);
37
- let r = await n.arrayBuffer();
38
- if (v.url !== t || x.value !== e) return;
39
- let i = await d.open(r, e, {
40
- zipLimits: f,
37
+ let r = await fetch(n);
38
+ if (!r.ok) throw Error(`HTTP ${r.status}`);
39
+ let i = await r.arrayBuffer();
40
+ if (S.url !== n || T.value !== e) return;
41
+ let a = await m.open(i, e, {
42
+ zipLimits: h,
41
43
  scrollContainer: e,
42
44
  listOptions: { windowed: !0 },
43
45
  pdfjs: {
44
- moduleUrl: p,
45
- workerUrl: u
46
+ moduleUrl: g,
47
+ workerUrl: p
48
+ },
49
+ onSlideChange: (e) => {
50
+ j !== null && e !== j || S.url === n && (O.value = e);
46
51
  }
47
52
  });
48
- if (v.url !== t || x.value !== e) {
53
+ if (S.url !== n || T.value !== e) {
49
54
  try {
50
- i.destroy();
55
+ a.destroy();
51
56
  } catch {}
52
57
  return;
53
58
  }
54
- S = i, y.value = "ready";
59
+ A = a, E.value = a, D.value = a.presentationData ? t(a.presentationData) : [], O.value = a.currentSlideIndex, C.value = "ready";
55
60
  } catch (e) {
56
- b.value = e instanceof Error ? e.message : String(e), y.value = "error";
61
+ w.value = e instanceof Error ? e.message : String(e), C.value = "error";
57
62
  }
58
63
  }
59
- return a(w), l(() => v.url, w), i(() => {
60
- C(), x.value && (x.value.innerHTML = "");
61
- }), (r, i) => (o(), t("div", m, [n("div", {
64
+ function F(e) {
65
+ j = e, O.value = e, M && clearTimeout(M), M = setTimeout(() => {
66
+ j = null, M = void 0;
67
+ }, 1e3), A?.goToSlide(e, {
68
+ behavior: "smooth",
69
+ block: "start"
70
+ });
71
+ }
72
+ return c(P), f(() => S.url, P), s(() => {
73
+ N(), T.value && (T.value.innerHTML = "");
74
+ }), (t, o) => (l(), i("div", _, [C.value === "ready" && E.value ? (l(), n(e, {
75
+ key: 0,
76
+ collapsed: k.value,
77
+ "onUpdate:collapsed": o[0] ||= (e) => k.value = e,
78
+ viewer: E.value,
79
+ items: D.value,
80
+ "active-index": O.value,
81
+ onNavigate: F
82
+ }, null, 8, [
83
+ "collapsed",
84
+ "viewer",
85
+ "items",
86
+ "active-index"
87
+ ])) : r("", !0), a("div", v, [a("div", {
62
88
  ref_key: "docEl",
63
- ref: x,
89
+ ref: T,
64
90
  class: "pv__doc"
65
- }, null, 512), y.value === "loading" ? (o(), t("div", h, [...i[0] ||= [n("p", { class: "pv__msg" }, "正在渲染 PPT…", -1)]])) : y.value === "error" ? (o(), t("div", g, [n("div", _, [n("p", null, "渲染失败:" + c(b.value), 1), n("button", {
91
+ }, null, 512), C.value === "loading" ? (l(), i("div", y, [...o[1] ||= [a("p", { class: "pv__msg" }, "正在渲染 PPT…", -1)]])) : C.value === "error" ? (l(), i("div", b, [a("div", x, [a("p", null, "渲染失败:" + d(w.value), 1), a("button", {
66
92
  type: "button",
67
93
  class: "pv__retry",
68
- onClick: w
69
- }, "重试")])])) : e("", !0)]));
94
+ onClick: P
95
+ }, "重试")])])) : r("", !0)])]));
70
96
  }
71
97
  });
72
98
  //#endregion
73
- export { v as default };
99
+ export { S as default };
@@ -2,6 +2,6 @@ import e from "../_virtual/_plugin-vue_export-helper.js";
2
2
  import t from "./XlsxViewer.vue_vue_type_script_setup_true_lang.js";
3
3
  /* empty css */
4
4
  //#region src/components/XlsxViewer.vue
5
- var n = /*#__PURE__*/ e(t, [["__scopeId", "data-v-7c63a9a3"]]);
5
+ var n = /*#__PURE__*/ e(t, [["__scopeId", "data-v-f4f6d50c"]]);
6
6
  //#endregion
7
7
  export { n as default };