document-viewer-vue3 0.1.0
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 +21 -0
- package/README.md +178 -0
- package/THIRD_PARTY_NOTICES.md +43 -0
- package/document-viewer-vue3/README.md +178 -0
- package/document-viewer-vue3/chunks/defineProperty-CGeCBTWF.js +39 -0
- package/document-viewer-vue3/chunks/jszip.min-BuCM2Hjj.js +3051 -0
- package/document-viewer-vue3/chunks/pdf-DaNcdZr-.js +14983 -0
- package/document-viewer-vue3/chunks/presentation-m6mYdP0-.js +97 -0
- package/document-viewer-vue3/chunks/spreadsheet-DLmwTbuh.js +16350 -0
- package/document-viewer-vue3/chunks/word-B__uJIJJ.js +3188 -0
- package/document-viewer-vue3/chunks/word-binary-DsiUIgdh.js +6144 -0
- package/document-viewer-vue3/chunks/word-ml-5809L5ca.js +161 -0
- package/document-viewer-vue3/document-viewer-vue3.js +317 -0
- package/document-viewer-vue3/document-viewer-vue3.umd.cjs +94 -0
- package/document-viewer-vue3/style.css +2 -0
- package/document-viewer-vue3/types/components/DocumentViewer.vue.d.ts +42 -0
- package/document-viewer-vue3/types/formats.d.ts +7 -0
- package/document-viewer-vue3/types/index.d.ts +11 -0
- package/document-viewer-vue3/types/types.d.ts +80 -0
- package/package.json +87 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { n as e, t } from "./jszip.min-BuCM2Hjj.js";
|
|
2
|
+
//#region src/engines/word-ml.ts
|
|
3
|
+
var n = /* @__PURE__ */ e(t(), 1), r = "http://schemas.microsoft.com/office/word/2003/wordml", i = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", a = "http://schemas.openxmlformats.org/officeDocument/2006/relationships", o = "http://schemas.openxmlformats.org/package/2006/relationships", s = "http://schemas.openxmlformats.org/package/2006/content-types", c = "http://schemas.microsoft.com/office/word/2003/auxHint", l = "urn:schemas-microsoft-com:vml", u = "http://www.w3.org/2000/xmlns/", d = {
|
|
4
|
+
"h-ansi": "hAnsi",
|
|
5
|
+
fareast: "eastAsia",
|
|
6
|
+
"b-cs": "bCs",
|
|
7
|
+
"i-cs": "iCs",
|
|
8
|
+
"sz-cs": "szCs",
|
|
9
|
+
"lang-cs": "lang",
|
|
10
|
+
"panose-1": "panose1",
|
|
11
|
+
"line-rule": "lineRule",
|
|
12
|
+
"line-pitch": "linePitch",
|
|
13
|
+
"char-space": "charSpace",
|
|
14
|
+
"hanging-chars": "hangingChars",
|
|
15
|
+
"first-line": "firstLine",
|
|
16
|
+
"first-line-chars": "firstLineChars",
|
|
17
|
+
"left-chars": "leftChars",
|
|
18
|
+
"right-chars": "rightChars"
|
|
19
|
+
};
|
|
20
|
+
function f(e) {
|
|
21
|
+
let t = new Uint8Array(e), n = t[0] === 255 && t[1] === 254 || t[0] === 60 && t[1] === 0, r = t[0] === 254 && t[1] === 255 || t[0] === 0 && t[1] === 60;
|
|
22
|
+
return new TextDecoder(n ? "utf-16le" : r ? "utf-16be" : "utf-8").decode(t);
|
|
23
|
+
}
|
|
24
|
+
async function p(e, t) {
|
|
25
|
+
let p = f(e);
|
|
26
|
+
if (/<!DOCTYPE\b|<!ENTITY\b/i.test(p)) throw Error("Word 2003 XML must not contain a DTD or entity declarations.");
|
|
27
|
+
let m = t.ownerDocument.defaultView, h = m?.DOMParser ?? globalThis.DOMParser, g = m?.XMLSerializer ?? globalThis.XMLSerializer, _ = new h().parseFromString(p, "application/xml");
|
|
28
|
+
if (_.getElementsByTagName("parsererror").length || _.documentElement.localName !== "wordDocument" || _.documentElement.namespaceURI !== r) throw Error("Invalid Word 2003 XML document.");
|
|
29
|
+
let v = Array.from(_.documentElement.children).find((e) => e.namespaceURI === r && e.localName === "body");
|
|
30
|
+
if (!v) throw Error("Word 2003 XML document has no body.");
|
|
31
|
+
let y = new n.default(), b = new g(), x = [], S = /* @__PURE__ */ new Map();
|
|
32
|
+
for (let e of Array.from(_.getElementsByTagNameNS(r, "binData"))) {
|
|
33
|
+
let t = e.getAttributeNS(r, "name") || "";
|
|
34
|
+
if (S.has(t)) continue;
|
|
35
|
+
let n = /\.(png|jpe?g|gif|bmp|tiff?|emf|wmf)$/i.exec(t)?.[1]?.toLowerCase(), i = e.textContent?.replace(/\s/g, "") || "";
|
|
36
|
+
if (t && n && /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(i) && i) {
|
|
37
|
+
let e = `media/image${S.size + 1}.${n}`;
|
|
38
|
+
S.set(t, {
|
|
39
|
+
path: e,
|
|
40
|
+
bytes: i
|
|
41
|
+
}), y.file(`word/${e}`, i, { base64: !0 });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
let C = (e) => {
|
|
45
|
+
let t = _.implementation.createDocument(i, `w:${e}`, null);
|
|
46
|
+
return t.documentElement.setAttributeNS(u, "xmlns:r", a), t;
|
|
47
|
+
}, w = (e) => `<?xml version="1.0" encoding="UTF-8"?>${b.serializeToString(e)}`, T = /* @__PURE__ */ new Map();
|
|
48
|
+
function E(e, t, n) {
|
|
49
|
+
let r = T.get(e);
|
|
50
|
+
r || (r = _.implementation.createDocument(o, "Relationships", null), T.set(e, r));
|
|
51
|
+
let i = `rId${r.documentElement.children.length + 1}`, s = r.createElementNS(o, "Relationship");
|
|
52
|
+
return s.setAttribute("Id", i), s.setAttribute("Type", `${a}/${t}`), s.setAttribute("Target", n), r.documentElement.appendChild(s), i;
|
|
53
|
+
}
|
|
54
|
+
let D = 0, O = 0;
|
|
55
|
+
function k(e, t, n, o = 0) {
|
|
56
|
+
if (o > 256) throw Error("Word 2003 XML nesting is too deep.");
|
|
57
|
+
let s = t.ownerDocument;
|
|
58
|
+
if (e.nodeType === 3 || e.nodeType === 4) {
|
|
59
|
+
t.appendChild(s.createTextNode(e.textContent || ""));
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (e.nodeType !== 1) return;
|
|
63
|
+
let f = e, p = f.namespaceURI === r;
|
|
64
|
+
if (p && f.localName === "binData") return;
|
|
65
|
+
if (f.namespaceURI === c) {
|
|
66
|
+
for (let e of Array.from(f.childNodes)) k(e, t, n, o + 1);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (p && (f.localName === "hdr" || f.localName === "ftr") && t.localName === "sectPr") {
|
|
70
|
+
let e = f.localName === "hdr", c = `${e ? "header" : "footer"}${e ? ++D : ++O}.xml`, l = C(e ? "hdr" : "ftr");
|
|
71
|
+
for (let e of Array.from(f.childNodes)) k(e, l.documentElement, c, o + 1);
|
|
72
|
+
y.file(`word/${c}`, w(l)), x.push([`/word/${c}`, `application/vnd.openxmlformats-officedocument.wordprocessingml.${e ? "header" : "footer"}+xml`]);
|
|
73
|
+
let u = s.createElementNS(i, `w:${e ? "header" : "footer"}Reference`), d = f.getAttributeNS(r, "type");
|
|
74
|
+
u.setAttributeNS(i, "w:type", d === "first" || d === "even" ? d : "default"), u.setAttributeNS(a, "r:id", E(n, e ? "header" : "footer", c)), t.appendChild(u);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
let m = p ? i : f.namespaceURI, h = p && d[f.localName] || f.localName, g = p ? `w:${h}` : f.nodeName, _ = s.createElementNS(m, g);
|
|
78
|
+
for (let e of Array.from(f.attributes)) {
|
|
79
|
+
if (e.namespaceURI === u || m === l && (h === "imagedata" || h === "fill") && (e.localName === "src" || e.localName === "href")) continue;
|
|
80
|
+
let t = e.namespaceURI === r, n = t && d[e.localName] || e.localName, a = e.value;
|
|
81
|
+
t && n === "hint" && a === "fareast" && (a = "eastAsia"), p && h === "fldChar" && t && n === "fldCharType" && a === "start" && (a = "begin"), _.setAttributeNS(t ? i : e.namespaceURI, t ? `w:${n}` : e.name, a);
|
|
82
|
+
}
|
|
83
|
+
if (m === l && (h === "imagedata" || h === "fill")) {
|
|
84
|
+
let e = S.get(f.getAttribute("src") || "");
|
|
85
|
+
e && _.setAttributeNS(a, "r:id", E(n, "image", e.path));
|
|
86
|
+
}
|
|
87
|
+
t.appendChild(_);
|
|
88
|
+
for (let e of Array.from(f.childNodes)) k(e, _, n, o + 1);
|
|
89
|
+
}
|
|
90
|
+
let A = C("document"), j = A.createElementNS(i, "w:body");
|
|
91
|
+
A.documentElement.appendChild(j);
|
|
92
|
+
for (let e of Array.from(v.childNodes)) k(e, j, "document.xml");
|
|
93
|
+
for (let e of Array.from(j.children)) {
|
|
94
|
+
if (e.localName !== "sectPr" || e === j.lastElementChild) continue;
|
|
95
|
+
let t = e.previousElementSibling;
|
|
96
|
+
(!t || t.localName !== "p") && (t = A.createElementNS(i, "w:p"), j.insertBefore(t, e));
|
|
97
|
+
let n = Array.from(t.children).find((e) => e.localName === "pPr");
|
|
98
|
+
n || (n = A.createElementNS(i, "w:pPr"), t.insertBefore(n, t.firstChild)), n.appendChild(e);
|
|
99
|
+
}
|
|
100
|
+
y.file("word/document.xml", w(A)), x.push(["/word/document.xml", "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"]);
|
|
101
|
+
for (let [e, t, n, i] of [
|
|
102
|
+
[
|
|
103
|
+
"styles",
|
|
104
|
+
"styles",
|
|
105
|
+
"styles.xml",
|
|
106
|
+
"styles"
|
|
107
|
+
],
|
|
108
|
+
[
|
|
109
|
+
"fonts",
|
|
110
|
+
"fonts",
|
|
111
|
+
"fontTable.xml",
|
|
112
|
+
"fontTable"
|
|
113
|
+
],
|
|
114
|
+
[
|
|
115
|
+
"docPr",
|
|
116
|
+
"settings",
|
|
117
|
+
"settings.xml",
|
|
118
|
+
"settings"
|
|
119
|
+
]
|
|
120
|
+
]) {
|
|
121
|
+
let a = Array.from(_.documentElement.children).find((t) => t.namespaceURI === r && t.localName === e);
|
|
122
|
+
if (!a) continue;
|
|
123
|
+
let o = C(t);
|
|
124
|
+
for (let e of Array.from(a.childNodes)) k(e, o.documentElement, n);
|
|
125
|
+
y.file(`word/${n}`, w(o)), E("document.xml", i, n), x.push([`/word/${n}`, `application/vnd.openxmlformats-officedocument.wordprocessingml.${i}+xml`]);
|
|
126
|
+
}
|
|
127
|
+
for (let [e, t] of T) y.file(`word/_rels/${e}.rels`, w(t));
|
|
128
|
+
let M = _.implementation.createDocument(o, "Relationships", null), N = M.createElementNS(o, "Relationship"), P = [
|
|
129
|
+
["Id", "rId1"],
|
|
130
|
+
["Type", `${a}/officeDocument`],
|
|
131
|
+
["Target", "word/document.xml"]
|
|
132
|
+
];
|
|
133
|
+
for (let [e, t] of P) N.setAttribute(e, t);
|
|
134
|
+
M.documentElement.appendChild(N), y.file("_rels/.rels", w(M));
|
|
135
|
+
let F = _.implementation.createDocument(s, "Types", null), I = [
|
|
136
|
+
["rels", "application/vnd.openxmlformats-package.relationships+xml"],
|
|
137
|
+
["xml", "application/xml"],
|
|
138
|
+
...Object.entries({
|
|
139
|
+
png: "image/png",
|
|
140
|
+
jpg: "image/jpeg",
|
|
141
|
+
jpeg: "image/jpeg",
|
|
142
|
+
gif: "image/gif",
|
|
143
|
+
bmp: "image/bmp",
|
|
144
|
+
tif: "image/tiff",
|
|
145
|
+
tiff: "image/tiff",
|
|
146
|
+
emf: "image/x-emf",
|
|
147
|
+
wmf: "image/x-wmf"
|
|
148
|
+
})
|
|
149
|
+
];
|
|
150
|
+
for (let [e, t] of I) {
|
|
151
|
+
let n = F.createElementNS(s, "Default");
|
|
152
|
+
n.setAttribute("Extension", e), n.setAttribute("ContentType", t), F.documentElement.appendChild(n);
|
|
153
|
+
}
|
|
154
|
+
for (let [e, t] of x) {
|
|
155
|
+
let n = F.createElementNS(s, "Override");
|
|
156
|
+
n.setAttribute("PartName", e), n.setAttribute("ContentType", t), F.documentElement.appendChild(n);
|
|
157
|
+
}
|
|
158
|
+
return y.file("[Content_Types].xml", w(F)), y.generateAsync({ type: "arraybuffer" });
|
|
159
|
+
}
|
|
160
|
+
//#endregion
|
|
161
|
+
export { p as convertWordMlToDocx };
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { computed as e, createCommentVNode as t, createElementBlock as n, createElementVNode as r, defineComponent as i, nextTick as a, normalizeClass as o, normalizeStyle as s, onBeforeUnmount as ee, onMounted as te, openBlock as c, ref as l, renderSlot as u, toDisplayString as d, vShow as ne, watch as f, withDirectives as re } from "vue";
|
|
2
|
+
//#region src/engines/index.ts
|
|
3
|
+
async function ie(e) {
|
|
4
|
+
switch (e) {
|
|
5
|
+
case "word": return (await import("./chunks/word-B__uJIJJ.js")).renderWordDocument;
|
|
6
|
+
case "spreadsheet": return (await import("./chunks/spreadsheet-DLmwTbuh.js")).renderSpreadsheetDocument;
|
|
7
|
+
case "pdf": return (await import("./chunks/pdf-DaNcdZr-.js")).renderPdfDocument;
|
|
8
|
+
case "presentation": return (await import("./chunks/presentation-m6mYdP0-.js")).renderPresentationDocument;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/formats.ts
|
|
13
|
+
var p = [
|
|
14
|
+
"doc",
|
|
15
|
+
"dot",
|
|
16
|
+
"docx",
|
|
17
|
+
"docm",
|
|
18
|
+
"dotx",
|
|
19
|
+
"dotm",
|
|
20
|
+
"xls",
|
|
21
|
+
"xlsx",
|
|
22
|
+
"xlsm",
|
|
23
|
+
"xlsb",
|
|
24
|
+
"xlt",
|
|
25
|
+
"xltx",
|
|
26
|
+
"xltm",
|
|
27
|
+
"pdf",
|
|
28
|
+
"pptx",
|
|
29
|
+
"pptm",
|
|
30
|
+
"pot",
|
|
31
|
+
"potx",
|
|
32
|
+
"potm",
|
|
33
|
+
"ppsx",
|
|
34
|
+
"ppsm"
|
|
35
|
+
], m = new Set(p), h = p.map((e) => `.${e}`).join(",");
|
|
36
|
+
function g(e) {
|
|
37
|
+
let t = e.split(/[?#]/, 1)[0] ?? "", n = t.split("/").pop() ?? t, r = n.lastIndexOf(".");
|
|
38
|
+
return r >= 0 ? n.slice(r + 1).toLowerCase() : "";
|
|
39
|
+
}
|
|
40
|
+
function _(e) {
|
|
41
|
+
return m.has(g(e));
|
|
42
|
+
}
|
|
43
|
+
function v(e) {
|
|
44
|
+
return [
|
|
45
|
+
"doc",
|
|
46
|
+
"dot",
|
|
47
|
+
"docx",
|
|
48
|
+
"docm",
|
|
49
|
+
"dotx",
|
|
50
|
+
"dotm"
|
|
51
|
+
].includes(e) ? "word" : [
|
|
52
|
+
"xls",
|
|
53
|
+
"xlsx",
|
|
54
|
+
"xlsm",
|
|
55
|
+
"xlsb",
|
|
56
|
+
"xlt",
|
|
57
|
+
"xltx",
|
|
58
|
+
"xltm"
|
|
59
|
+
].includes(e) ? "spreadsheet" : e === "pdf" ? "pdf" : [
|
|
60
|
+
"pptx",
|
|
61
|
+
"pptm",
|
|
62
|
+
"potx",
|
|
63
|
+
"potm",
|
|
64
|
+
"ppsx",
|
|
65
|
+
"ppsm"
|
|
66
|
+
].includes(e) ? "presentation" : null;
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/components/DocumentViewer.vue?vue&type=script&setup=true&lang.ts
|
|
70
|
+
var ae = ["data-theme", "data-state"], y = {
|
|
71
|
+
key: 0,
|
|
72
|
+
class: "document-viewer__toolbar"
|
|
73
|
+
}, oe = { class: "document-viewer__identity" }, se = ["title"], b = { key: 0 }, x = { class: "document-viewer__actions" }, S = ["disabled"], ce = ["disabled"], le = ["disabled"], ue = ["disabled"], de = ["disabled"], fe = ["role"], pe = {
|
|
74
|
+
class: "document-viewer__file-mark",
|
|
75
|
+
"aria-hidden": "true"
|
|
76
|
+
}, C = {
|
|
77
|
+
key: 2,
|
|
78
|
+
class: "document-viewer__loading",
|
|
79
|
+
role: "status",
|
|
80
|
+
"aria-live": "polite"
|
|
81
|
+
}, w = /* @__PURE__ */ i({
|
|
82
|
+
name: "DocumentViewer",
|
|
83
|
+
__name: "DocumentViewer",
|
|
84
|
+
props: {
|
|
85
|
+
file: {},
|
|
86
|
+
url: {},
|
|
87
|
+
filename: {},
|
|
88
|
+
height: { default: "100%" },
|
|
89
|
+
strict: {
|
|
90
|
+
type: Boolean,
|
|
91
|
+
default: !0
|
|
92
|
+
},
|
|
93
|
+
emptyText: { default: "选择一个 Word、Excel、PDF 或 PowerPoint 文件开始预览" },
|
|
94
|
+
options: {}
|
|
95
|
+
},
|
|
96
|
+
emits: [
|
|
97
|
+
"load-start",
|
|
98
|
+
"load-complete",
|
|
99
|
+
"unload-start",
|
|
100
|
+
"unload-complete",
|
|
101
|
+
"progress",
|
|
102
|
+
"zoom-change",
|
|
103
|
+
"error"
|
|
104
|
+
],
|
|
105
|
+
setup(i, { expose: p, emit: m }) {
|
|
106
|
+
let h = i, w = m, T = l(null), E = l(null), D = l("empty"), O = l(""), k = l({
|
|
107
|
+
current: 0,
|
|
108
|
+
total: 1
|
|
109
|
+
}), A = l(0), j = l(1), M = !1, N = 0, P = null, F = null, I = null, L = null, R = e(() => {
|
|
110
|
+
if (h.file?.name) return h.file.name;
|
|
111
|
+
if (h.filename) return h.filename;
|
|
112
|
+
if (!h.url) return "";
|
|
113
|
+
try {
|
|
114
|
+
let e = typeof window > "u" ? "http://localhost/" : window.location.href;
|
|
115
|
+
return decodeURIComponent(new URL(h.url, e).pathname.split("/").pop() || "");
|
|
116
|
+
} catch {
|
|
117
|
+
return h.url;
|
|
118
|
+
}
|
|
119
|
+
}), z = e(() => g(R.value)), B = e(() => v(z.value)), V = e(() => !!(h.file || h.url)), H = e(() => !h.strict || _(R.value)), me = e(() => typeof h.height == "number" ? `${h.height}px` : h.height), he = e(() => h.options?.theme ?? "light"), ge = e(() => h.options?.toolbar !== !1), U = e(() => Math.max(.25, h.options?.minZoom ?? .5)), W = e(() => Math.max(U.value, h.options?.maxZoom ?? 2.5)), _e = e(() => k.value.total ? Math.min(100, Math.round(k.value.current / k.value.total * 100)) : 0), ve = e(() => D.value === "error" ? O.value : D.value === "unsupported" ? z.value ? `暂不支持 .${z.value};请选择 DOC/DOCX、XLS/XLSX、PDF 或 PPTX 文档。` : "无法识别文件类型,请通过 filename 属性提供扩展名。" : h.emptyText), ye = (e) => e instanceof Error && e.message ? e.message : typeof e == "string" ? e : "文档预览失败。", be = (e) => B.value ? {
|
|
120
|
+
filename: R.value,
|
|
121
|
+
extension: z.value,
|
|
122
|
+
kind: B.value,
|
|
123
|
+
byteLength: e
|
|
124
|
+
} : null;
|
|
125
|
+
async function G(e = "replace") {
|
|
126
|
+
P?.abort(e), P = null;
|
|
127
|
+
let t = I;
|
|
128
|
+
t && w("unload-start", t), await F?.destroy(), F = null, L = null, I = null, E.value?.replaceChildren(), t && w("unload-complete", t);
|
|
129
|
+
}
|
|
130
|
+
async function xe(e) {
|
|
131
|
+
if (h.file) return h.file.arrayBuffer();
|
|
132
|
+
if (!h.url) throw Error("没有可读取的文档来源。");
|
|
133
|
+
let t = await fetch(h.url, {
|
|
134
|
+
...h.options?.fetchOptions,
|
|
135
|
+
signal: e
|
|
136
|
+
});
|
|
137
|
+
if (!t.ok) throw Error(`文档请求失败:HTTP ${t.status}`);
|
|
138
|
+
return t.arrayBuffer();
|
|
139
|
+
}
|
|
140
|
+
async function K() {
|
|
141
|
+
if (!M) return;
|
|
142
|
+
let e = ++N;
|
|
143
|
+
if (await G(), A.value = 0, O.value = "", k.value = {
|
|
144
|
+
current: 0,
|
|
145
|
+
total: 1
|
|
146
|
+
}, !V.value) {
|
|
147
|
+
D.value = "empty";
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (!H.value || !B.value) {
|
|
151
|
+
D.value = "unsupported";
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
await a();
|
|
155
|
+
let t = E.value, n = be();
|
|
156
|
+
if (!t || !n) return;
|
|
157
|
+
let r = new AbortController();
|
|
158
|
+
P = r, D.value = "loading", w("load-start", n);
|
|
159
|
+
try {
|
|
160
|
+
let i = await xe(r.signal);
|
|
161
|
+
if (r.signal.aborted || e !== N) return;
|
|
162
|
+
let a = await ie(n.kind);
|
|
163
|
+
if (r.signal.aborted || e !== N) return;
|
|
164
|
+
let o = await a({
|
|
165
|
+
container: t,
|
|
166
|
+
buffer: i,
|
|
167
|
+
extension: n.extension,
|
|
168
|
+
filename: n.filename,
|
|
169
|
+
signal: r.signal,
|
|
170
|
+
options: h.options ?? {},
|
|
171
|
+
onProgress(e) {
|
|
172
|
+
k.value = e, w("progress", e);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
if (r.signal.aborted || e !== N) {
|
|
176
|
+
await o.destroy();
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
F = o, L = i, A.value = o.pageCount ?? 0, I = {
|
|
180
|
+
...n,
|
|
181
|
+
byteLength: i.byteLength,
|
|
182
|
+
pageCount: o.pageCount
|
|
183
|
+
}, D.value = "ready", w("load-complete", I);
|
|
184
|
+
} catch (t) {
|
|
185
|
+
if (r.signal.aborted || e !== N) return;
|
|
186
|
+
let n = ye(t);
|
|
187
|
+
O.value = n, D.value = "error", w("error", n);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
function q() {
|
|
191
|
+
return {
|
|
192
|
+
scale: j.value,
|
|
193
|
+
percent: Math.round(j.value * 100)
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
function J(e) {
|
|
197
|
+
j.value = Math.min(W.value, Math.max(U.value, Number(e.toFixed(2))));
|
|
198
|
+
let t = q();
|
|
199
|
+
return w("zoom-change", t), t;
|
|
200
|
+
}
|
|
201
|
+
let Y = () => J(j.value + .1), X = () => J(j.value - .1), Z = () => J(h.options?.initialZoom ?? 1);
|
|
202
|
+
function Q() {
|
|
203
|
+
if (!L) return;
|
|
204
|
+
let e = new Blob([L], { type: h.file?.type || "application/octet-stream" }), t = URL.createObjectURL(e), n = document.createElement("a");
|
|
205
|
+
n.href = t, n.download = R.value || "document", n.click(), URL.revokeObjectURL(t);
|
|
206
|
+
}
|
|
207
|
+
function $() {
|
|
208
|
+
window.print();
|
|
209
|
+
}
|
|
210
|
+
return p({
|
|
211
|
+
reload: K,
|
|
212
|
+
destroy: () => G("destroy"),
|
|
213
|
+
zoomIn: Y,
|
|
214
|
+
zoomOut: X,
|
|
215
|
+
resetZoom: Z,
|
|
216
|
+
setZoom: J,
|
|
217
|
+
getZoomState: q,
|
|
218
|
+
downloadOriginalFile: Q,
|
|
219
|
+
print: $,
|
|
220
|
+
getScrollContainer: () => T.value
|
|
221
|
+
}), f(() => [
|
|
222
|
+
h.file,
|
|
223
|
+
h.url,
|
|
224
|
+
h.filename
|
|
225
|
+
], () => void K(), { flush: "post" }), f(() => h.options?.initialZoom, (e) => J(e ?? 1)), te(() => {
|
|
226
|
+
M = !0, j.value = Math.min(W.value, Math.max(U.value, h.options?.initialZoom ?? 1)), K();
|
|
227
|
+
}), ee(() => {
|
|
228
|
+
M = !1, N += 1, G("destroy");
|
|
229
|
+
}), (e, i) => (c(), n("section", {
|
|
230
|
+
class: "document-viewer",
|
|
231
|
+
"data-theme": he.value,
|
|
232
|
+
"data-state": D.value,
|
|
233
|
+
style: s({
|
|
234
|
+
"--document-viewer-height": me.value,
|
|
235
|
+
"--document-viewer-zoom": j.value
|
|
236
|
+
}),
|
|
237
|
+
"aria-label": "文档预览"
|
|
238
|
+
}, [
|
|
239
|
+
ge.value && V.value && H.value ? (c(), n("header", y, [
|
|
240
|
+
u(e.$slots, "toolbar-start", {
|
|
241
|
+
zoom: q(),
|
|
242
|
+
status: D.value
|
|
243
|
+
}),
|
|
244
|
+
r("div", oe, [
|
|
245
|
+
r("span", null, d(z.value.toUpperCase()), 1),
|
|
246
|
+
r("strong", { title: R.value }, d(R.value), 9, se),
|
|
247
|
+
A.value ? (c(), n("small", b, d(A.value) + " " + d(B.value === "spreadsheet" ? "个工作表" : "页"), 1)) : t("", !0)
|
|
248
|
+
]),
|
|
249
|
+
r("div", x, [
|
|
250
|
+
r("button", {
|
|
251
|
+
type: "button",
|
|
252
|
+
title: "缩小",
|
|
253
|
+
disabled: D.value !== "ready",
|
|
254
|
+
onClick: X
|
|
255
|
+
}, "−", 8, S),
|
|
256
|
+
r("button", {
|
|
257
|
+
type: "button",
|
|
258
|
+
class: "document-viewer__zoom",
|
|
259
|
+
title: "重置缩放",
|
|
260
|
+
disabled: D.value !== "ready",
|
|
261
|
+
onClick: Z
|
|
262
|
+
}, d(Math.round(j.value * 100)) + "% ", 9, ce),
|
|
263
|
+
r("button", {
|
|
264
|
+
type: "button",
|
|
265
|
+
title: "放大",
|
|
266
|
+
disabled: D.value !== "ready",
|
|
267
|
+
onClick: Y
|
|
268
|
+
}, "+", 8, le),
|
|
269
|
+
i[0] || (i[0] = r("span", { class: "document-viewer__separator" }, null, -1)),
|
|
270
|
+
r("button", {
|
|
271
|
+
type: "button",
|
|
272
|
+
title: "下载原文件",
|
|
273
|
+
disabled: D.value !== "ready",
|
|
274
|
+
onClick: Q
|
|
275
|
+
}, "↓", 8, ue),
|
|
276
|
+
r("button", {
|
|
277
|
+
type: "button",
|
|
278
|
+
title: "打印",
|
|
279
|
+
disabled: D.value !== "ready",
|
|
280
|
+
onClick: $
|
|
281
|
+
}, "⎙", 8, de)
|
|
282
|
+
]),
|
|
283
|
+
u(e.$slots, "toolbar-end", {
|
|
284
|
+
zoom: q(),
|
|
285
|
+
status: D.value
|
|
286
|
+
})
|
|
287
|
+
])) : t("", !0),
|
|
288
|
+
D.value === "empty" || D.value === "unsupported" || D.value === "error" ? (c(), n("div", {
|
|
289
|
+
key: 1,
|
|
290
|
+
class: o(["document-viewer__state", { "is-error": D.value !== "empty" }]),
|
|
291
|
+
role: D.value === "empty" ? "status" : "alert"
|
|
292
|
+
}, [
|
|
293
|
+
r("span", pe, d(D.value === "empty" ? "DOC" : "!"), 1),
|
|
294
|
+
r("p", null, d(ve.value), 1),
|
|
295
|
+
D.value === "error" ? (c(), n("button", {
|
|
296
|
+
key: 0,
|
|
297
|
+
type: "button",
|
|
298
|
+
onClick: K
|
|
299
|
+
}, "重新加载")) : t("", !0)
|
|
300
|
+
], 10, fe)) : t("", !0),
|
|
301
|
+
re(r("div", {
|
|
302
|
+
ref_key: "scrollContainer",
|
|
303
|
+
ref: T,
|
|
304
|
+
class: "document-viewer__viewport"
|
|
305
|
+
}, [r("div", {
|
|
306
|
+
ref_key: "renderRoot",
|
|
307
|
+
ref: E,
|
|
308
|
+
class: "document-viewer__content"
|
|
309
|
+
}, null, 512)], 512), [[ne, D.value === "loading" || D.value === "ready"]]),
|
|
310
|
+
D.value === "loading" ? (c(), n("div", C, [i[1] || (i[1] = r("span", { class: "document-viewer__spinner" }, null, -1)), r("div", null, [r("strong", null, d(k.value.label || "正在读取文档"), 1), r("span", null, [r("i", { style: s({ width: `${_e.value}%` }) }, null, 4)])])])) : t("", !0)
|
|
311
|
+
], 12, ae));
|
|
312
|
+
}
|
|
313
|
+
}), T = { install(e, t = {}) {
|
|
314
|
+
e.component(t.componentName ?? "DocumentViewer", w);
|
|
315
|
+
} };
|
|
316
|
+
//#endregion
|
|
317
|
+
export { h as DOCUMENT_VIEWER_ACCEPT, p as DOCUMENT_VIEWER_EXTENSIONS, w as DocumentViewer, T as DocumentViewerPlugin, T as default, g as getDocumentExtension, v as getDocumentKind, _ as isSupportedDocumentName };
|