@apollo-design/react-docx-preview 0.1.0 → 0.2.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 +201 -201
- package/README.md +86 -0
- package/dist/DocxViewer.d.ts +7 -4
- package/dist/context.d.ts +1 -0
- package/dist/hooks/useDocViewer.d.ts +3 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +180 -148
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -17,14 +17,22 @@ function v(e) {
|
|
|
17
17
|
return e && typeof e == "object" && "message" in e ? String(e.message) : String(e);
|
|
18
18
|
}
|
|
19
19
|
function y(e) {
|
|
20
|
+
try {
|
|
21
|
+
let t = new URL(e, window.location.href).pathname.split("/").filter(Boolean).pop();
|
|
22
|
+
return t && decodeURIComponent(t) || "document.docx";
|
|
23
|
+
} catch {
|
|
24
|
+
return "document.docx";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function b(e) {
|
|
20
28
|
if (typeof e == "number" && isFinite(e) && e > 0) {
|
|
21
29
|
let t = e > 10 ? e / 100 : e;
|
|
22
30
|
return Math.max(f, Math.min(p, Math.round(t * 100) / 100));
|
|
23
31
|
}
|
|
24
32
|
return "fit";
|
|
25
33
|
}
|
|
26
|
-
function
|
|
27
|
-
let [a, o] = i(!1), [s, l] = i(null), [u, d] = i(!1), [
|
|
34
|
+
function x(e, t = {}) {
|
|
35
|
+
let [a, o] = i(!1), [s, l] = i(null), [u, d] = i(!1), [x, S] = i(0), [C, w] = i(0), [T, E] = i(1), [D, O] = i(() => b(t.initialScale)), [k, A] = i(t.showThumbs !== !1), [j, M] = i(!1), N = r({
|
|
28
36
|
docName: "",
|
|
29
37
|
docBlob: null,
|
|
30
38
|
wrapperEl: null,
|
|
@@ -34,37 +42,37 @@ function b(e, t = {}) {
|
|
|
34
42
|
currentPage: 0,
|
|
35
43
|
pageObserver: null,
|
|
36
44
|
thumbPageSynced: -1
|
|
37
|
-
}),
|
|
45
|
+
}), P = r({
|
|
38
46
|
docLoaded: u,
|
|
39
|
-
currentPage:
|
|
40
|
-
scaleMode:
|
|
41
|
-
thumbsVisible:
|
|
42
|
-
currentScale:
|
|
47
|
+
currentPage: x,
|
|
48
|
+
scaleMode: D,
|
|
49
|
+
thumbsVisible: k,
|
|
50
|
+
currentScale: T
|
|
43
51
|
});
|
|
44
|
-
|
|
52
|
+
P.current = {
|
|
45
53
|
docLoaded: u,
|
|
46
|
-
currentPage:
|
|
47
|
-
scaleMode:
|
|
48
|
-
thumbsVisible:
|
|
49
|
-
currentScale:
|
|
54
|
+
currentPage: x,
|
|
55
|
+
scaleMode: D,
|
|
56
|
+
thumbsVisible: k,
|
|
57
|
+
currentScale: T
|
|
50
58
|
};
|
|
51
|
-
let
|
|
52
|
-
|
|
53
|
-
let
|
|
54
|
-
function
|
|
59
|
+
let F = r(t);
|
|
60
|
+
F.current = t;
|
|
61
|
+
let I = C > 1, L = k && C > 1 && u, R = u && x > 0, z = u && x < C - 1, B = u && T > .100001, V = u && T < 3.999999, H = D === "fit" ? "适应宽度" : Math.round(D * 100) + "%";
|
|
62
|
+
function U() {
|
|
55
63
|
let t = e.thumbs.current;
|
|
56
64
|
if (!t) return;
|
|
57
|
-
let n = t.children, r =
|
|
65
|
+
let n = t.children, r = N.current.currentPage;
|
|
58
66
|
for (let e = 0; e < n.length; e++) n[e].classList.toggle("current", Number(n[e].getAttribute("data-page")) === r);
|
|
59
|
-
|
|
67
|
+
P.current.thumbsVisible && n.length > 1 && P.current.docLoaded && N.current.thumbPageSynced !== r && n[r] && (N.current.thumbPageSynced = r, n[r].scrollIntoView({ block: "nearest" }));
|
|
60
68
|
}
|
|
61
|
-
function
|
|
69
|
+
function W() {
|
|
62
70
|
let t = e.thumbs.current;
|
|
63
71
|
if (!t) return;
|
|
64
|
-
t.innerHTML = "",
|
|
65
|
-
let n =
|
|
66
|
-
if (n.length <= 1 || !
|
|
67
|
-
let r = 94 /
|
|
72
|
+
t.innerHTML = "", N.current.thumbPageSynced = -1;
|
|
73
|
+
let n = N.current.sections;
|
|
74
|
+
if (n.length <= 1 || !N.current.naturalWidth) return;
|
|
75
|
+
let r = 94 / N.current.naturalWidth;
|
|
68
76
|
for (let e = 0; e < n.length; e++) {
|
|
69
77
|
let i = document.createElement("div");
|
|
70
78
|
i.className = "thumb", i.setAttribute("data-page", String(e));
|
|
@@ -75,39 +83,39 @@ function b(e, t = {}) {
|
|
|
75
83
|
let s = document.createElement("div");
|
|
76
84
|
s.className = "thumb-label", s.textContent = String(e + 1), i.appendChild(a), i.appendChild(s), t.appendChild(i);
|
|
77
85
|
}
|
|
78
|
-
|
|
86
|
+
U();
|
|
79
87
|
}
|
|
80
|
-
function
|
|
88
|
+
function G() {
|
|
81
89
|
let t = e.stage.current;
|
|
82
|
-
if (!
|
|
90
|
+
if (!N.current.naturalWidth || !t) return 1;
|
|
83
91
|
let n = t.clientWidth - 48;
|
|
84
|
-
return Math.min(h, n /
|
|
92
|
+
return Math.min(h, n / N.current.naturalWidth);
|
|
85
93
|
}
|
|
86
|
-
function
|
|
87
|
-
let t = e.stage.current, n = e.docBox.current, r =
|
|
88
|
-
if (!
|
|
89
|
-
let a = t.scrollHeight - t.clientHeight, o = t.scrollWidth - t.clientWidth, s = a > 0 ? t.scrollTop / a : 0, c = o > 0 ? t.scrollLeft / o : 0, l =
|
|
90
|
-
|
|
94
|
+
function K() {
|
|
95
|
+
let t = e.stage.current, n = e.docBox.current, r = N.current.wrapperEl, i = N.current.naturalWidth;
|
|
96
|
+
if (!P.current.docLoaded || !r || !i || !t || !n) return;
|
|
97
|
+
let a = t.scrollHeight - t.clientHeight, o = t.scrollWidth - t.clientWidth, s = a > 0 ? t.scrollTop / a : 0, c = o > 0 ? t.scrollLeft / o : 0, l = P.current.scaleMode, u = l === "fit" ? G() : l;
|
|
98
|
+
E(u), n.style.width = Math.ceil(i * u) + "px", n.style.height = Math.ceil(N.current.naturalHeight * u) + "px", r.style.width = i + "px", r.style.transform = "scale(" + u + ")", r.style.transformOrigin = "top left";
|
|
91
99
|
let d = t.scrollHeight - t.clientHeight, f = t.scrollWidth - t.clientWidth;
|
|
92
100
|
d > 0 && (t.scrollTop = s * d), f > 0 && (t.scrollLeft = c * f);
|
|
93
101
|
}
|
|
94
|
-
function
|
|
95
|
-
let t =
|
|
102
|
+
function q(e) {
|
|
103
|
+
let t = P.current.currentScale / m, n = Math.round(t);
|
|
96
104
|
Math.abs(t - n) < .01 && (t = n);
|
|
97
105
|
let r = e > 0 ? (Math.floor(t) + 1) * m : (Math.ceil(t) - 1) * m;
|
|
98
|
-
|
|
106
|
+
J(Math.max(f, Math.min(p, Math.round(r * 100) / 100)));
|
|
99
107
|
}
|
|
100
|
-
function
|
|
101
|
-
|
|
108
|
+
function J(e) {
|
|
109
|
+
P.current.scaleMode = e, O(e), K();
|
|
102
110
|
}
|
|
103
|
-
function
|
|
104
|
-
|
|
111
|
+
function Y(e) {
|
|
112
|
+
M(!1), J(e === "fit" ? "fit" : parseFloat(e));
|
|
105
113
|
}
|
|
106
|
-
function
|
|
107
|
-
let e = !
|
|
108
|
-
|
|
114
|
+
function ee() {
|
|
115
|
+
let e = !P.current.thumbsVisible;
|
|
116
|
+
A(e), P.current.thumbsVisible = e, P.current.docLoaded && P.current.scaleMode === "fit" && K();
|
|
109
117
|
}
|
|
110
|
-
function
|
|
118
|
+
function te(e) {
|
|
111
119
|
let t = getComputedStyle(e), n = parseFloat(t.paddingTop) || 0, r = parseFloat(t.paddingRight) || 0, i = parseFloat(t.paddingBottom) || 0, a = parseFloat(t.paddingLeft) || 0, o = e.offsetWidth - r, s = e.offsetHeight - i, c = Math.max(4, Math.round(Math.min(n, r, i, a) * .25)), l = {
|
|
112
120
|
tl: {
|
|
113
121
|
left: a - c,
|
|
@@ -131,35 +139,35 @@ function b(e, t = {}) {
|
|
|
131
139
|
n.className = "page-corner " + t, n.setAttribute("aria-hidden", "true"), n.style.width = c + "px", n.style.height = c + "px", n.style.left = l[t].left + "px", n.style.top = l[t].top + "px", e.appendChild(n);
|
|
132
140
|
}
|
|
133
141
|
}
|
|
134
|
-
function
|
|
142
|
+
function ne(t) {
|
|
135
143
|
let n = e.stage.current;
|
|
136
144
|
if (!n) return;
|
|
137
145
|
let r = parseFloat(getComputedStyle(n).paddingTop) || 0;
|
|
138
146
|
n.scrollTop = n.scrollTop + (t.getBoundingClientRect().top - n.getBoundingClientRect().top) - r;
|
|
139
147
|
}
|
|
140
148
|
function X(e) {
|
|
141
|
-
let t =
|
|
142
|
-
if (!
|
|
149
|
+
let t = N.current.sections;
|
|
150
|
+
if (!P.current.docLoaded || t.length === 0) return;
|
|
143
151
|
let n = Math.max(0, Math.min(e, t.length - 1));
|
|
144
|
-
|
|
152
|
+
N.current.currentPage = n, S(n), ne(t[n]);
|
|
145
153
|
}
|
|
146
|
-
function
|
|
154
|
+
function re(e) {
|
|
147
155
|
let t = parseInt(e, 10);
|
|
148
156
|
Number.isNaN(t) || X(t - 1);
|
|
149
157
|
}
|
|
150
|
-
function
|
|
151
|
-
|
|
152
|
-
let t = e.stage.current, n =
|
|
158
|
+
function ie() {
|
|
159
|
+
N.current.pageObserver && (N.current.pageObserver.disconnect(), N.current.pageObserver = null);
|
|
160
|
+
let t = e.stage.current, n = N.current.sections;
|
|
153
161
|
if (typeof window.IntersectionObserver != "function" || n.length <= 1 || !t) return;
|
|
154
162
|
let r = [];
|
|
155
|
-
|
|
163
|
+
N.current.pageObserver = new IntersectionObserver((e) => {
|
|
156
164
|
for (let t of e) {
|
|
157
165
|
let e = Number(t.target.getAttribute("data-page"));
|
|
158
166
|
Number.isNaN(e) || (r[e] = t.intersectionRatio);
|
|
159
167
|
}
|
|
160
168
|
let t = -1, n = -1;
|
|
161
169
|
for (let e = 0; e < r.length; e++) r[e] > n && (n = r[e], t = e);
|
|
162
|
-
t >= 0 && n > 0 && (
|
|
170
|
+
t >= 0 && n > 0 && (N.current.currentPage = t, S(t));
|
|
163
171
|
}, {
|
|
164
172
|
root: t,
|
|
165
173
|
threshold: [
|
|
@@ -170,56 +178,56 @@ function b(e, t = {}) {
|
|
|
170
178
|
1
|
|
171
179
|
]
|
|
172
180
|
});
|
|
173
|
-
for (let e of n)
|
|
181
|
+
for (let e of n) N.current.pageObserver.observe(e);
|
|
174
182
|
}
|
|
175
|
-
function
|
|
176
|
-
|
|
183
|
+
function Z() {
|
|
184
|
+
N.current.pageObserver && (N.current.pageObserver.disconnect(), N.current.pageObserver = null);
|
|
177
185
|
let t = e.docBox.current, n = e.thumbs.current;
|
|
178
|
-
t && (t.innerHTML = "", t.style.width = "", t.style.height = ""), n && (n.innerHTML = ""),
|
|
186
|
+
t && (t.innerHTML = "", t.style.width = "", t.style.height = ""), n && (n.innerHTML = ""), N.current.thumbPageSynced = -1, N.current.wrapperEl = null, N.current.sections = [], N.current.naturalWidth = 0, N.current.naturalHeight = 0, N.current.currentPage = 0, S(0), w(0), d(!1);
|
|
179
187
|
}
|
|
180
|
-
async function
|
|
181
|
-
if (
|
|
188
|
+
async function Q(t, n) {
|
|
189
|
+
if (Z(), l(null), M(!1), o(!0), _(t)) {
|
|
182
190
|
o(!1);
|
|
183
191
|
let e = /* @__PURE__ */ Error("legacy binary document (.wps/.doc), not OOXML");
|
|
184
192
|
l({
|
|
185
193
|
title: "无法打开" + (n ? "「" + n + "」" : "文档"),
|
|
186
194
|
detail: "这是旧版二进制文档格式(.wps / .doc),不是 OOXML(.docx)。即使是新版 WPS Office,默认保存的 .wps 仍是二进制格式。请用 WPS 或 Word 将其另存为 .docx 后重试。"
|
|
187
|
-
}),
|
|
195
|
+
}), F.current.onError?.(e);
|
|
188
196
|
return;
|
|
189
197
|
}
|
|
190
198
|
let r = {
|
|
191
199
|
hideWrapperOnPrint: !0,
|
|
192
200
|
paginate: !0,
|
|
193
201
|
experimental: !0,
|
|
194
|
-
...
|
|
202
|
+
...F.current.renderOptions
|
|
195
203
|
};
|
|
196
204
|
try {
|
|
197
205
|
let n = e.docBox.current, i = e.stage.current;
|
|
198
206
|
if (!n || !i) throw Error("viewer is not mounted");
|
|
199
207
|
let a = await c(t, n, void 0, r), o = n.querySelector(".docx-wrapper") || n;
|
|
200
|
-
|
|
208
|
+
N.current.wrapperEl = o;
|
|
201
209
|
let s = o.querySelectorAll("section"), l = [];
|
|
202
210
|
for (let e = 0; e < s.length; e++) {
|
|
203
211
|
let t = s[e];
|
|
204
|
-
t.setAttribute("data-page", String(e)),
|
|
212
|
+
t.setAttribute("data-page", String(e)), te(t), l.push(t);
|
|
205
213
|
}
|
|
206
|
-
|
|
214
|
+
N.current.sections = l;
|
|
207
215
|
let u = 0;
|
|
208
216
|
for (let e of l) u = Math.max(u, e.offsetWidth);
|
|
209
|
-
u || (u = o.scrollWidth),
|
|
217
|
+
u || (u = o.scrollWidth), N.current.naturalWidth = u, N.current.naturalHeight = o.offsetHeight, N.current.currentPage = 0, P.current.docLoaded = !0, d(!0), w(l.length), S(0), K(), W(), ie(), i.scrollTop = 0, i.scrollLeft = 0, F.current.onRendered?.(a);
|
|
210
218
|
} catch (e) {
|
|
211
|
-
console.error(e),
|
|
219
|
+
console.error(e), Z(), l({
|
|
212
220
|
title: "无法打开" + (n ? "「" + n + "」" : "文档"),
|
|
213
221
|
detail: v(e) + " —— 请确认这是有效且未加密的 .docx 文件。"
|
|
214
|
-
}),
|
|
222
|
+
}), F.current.onError?.(e);
|
|
215
223
|
} finally {
|
|
216
224
|
o(!1);
|
|
217
225
|
}
|
|
218
226
|
}
|
|
219
|
-
async function
|
|
227
|
+
async function $(e, t) {
|
|
220
228
|
if (!e) return;
|
|
221
229
|
let n = t || typeof File < "u" && e instanceof File && e.name || "document.docx";
|
|
222
|
-
if (
|
|
230
|
+
if (N.current.docName = n, N.current.docBlob = e instanceof Blob ? e : new Blob([e]), e instanceof Blob) {
|
|
223
231
|
let t;
|
|
224
232
|
try {
|
|
225
233
|
t = await new Promise((t, n) => {
|
|
@@ -230,75 +238,99 @@ function b(e, t = {}) {
|
|
|
230
238
|
l({
|
|
231
239
|
title: "读取文件失败",
|
|
232
240
|
detail: "浏览器无法读取「" + n + "」,请重试。"
|
|
233
|
-
}),
|
|
241
|
+
}), F.current.onError?.(e);
|
|
234
242
|
return;
|
|
235
243
|
}
|
|
236
|
-
return
|
|
244
|
+
return Q(t, n);
|
|
237
245
|
}
|
|
238
|
-
return
|
|
246
|
+
return Q(e, n);
|
|
239
247
|
}
|
|
240
|
-
function
|
|
241
|
-
|
|
248
|
+
async function ae(e, t, n) {
|
|
249
|
+
if (e) {
|
|
250
|
+
o(!0), l(null);
|
|
251
|
+
try {
|
|
252
|
+
let r;
|
|
253
|
+
if (t) r = await t(e);
|
|
254
|
+
else {
|
|
255
|
+
let t = await fetch(e);
|
|
256
|
+
if (!t.ok) throw Error("HTTP " + t.status + " " + t.statusText);
|
|
257
|
+
r = await t.blob();
|
|
258
|
+
}
|
|
259
|
+
if (!r) throw Error("文档数据为空");
|
|
260
|
+
return await $(r, n || y(e));
|
|
261
|
+
} catch (e) {
|
|
262
|
+
console.error(e), l({
|
|
263
|
+
title: "加载文档失败",
|
|
264
|
+
detail: v(e) + " —— 请确认地址可访问(如需鉴权请使用 customRequest)。"
|
|
265
|
+
}), F.current.onError?.(e);
|
|
266
|
+
} finally {
|
|
267
|
+
o(!1);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
function oe() {
|
|
272
|
+
let e = N.current.docBlob;
|
|
242
273
|
if (!e) return;
|
|
243
274
|
let t = URL.createObjectURL(e), n = document.createElement("a");
|
|
244
|
-
n.href = t, n.download =
|
|
275
|
+
n.href = t, n.download = N.current.docName || "document.docx", document.body.appendChild(n), n.click(), document.body.removeChild(n), setTimeout(() => URL.revokeObjectURL(t), 1e4);
|
|
245
276
|
}
|
|
246
277
|
return n(() => {
|
|
247
278
|
function t() {
|
|
248
|
-
|
|
279
|
+
P.current.docLoaded && P.current.scaleMode === "fit" && K();
|
|
249
280
|
}
|
|
250
281
|
function n(e) {
|
|
251
|
-
e.target.closest(".docx-viewer .scale-select") ||
|
|
282
|
+
e.target.closest(".docx-viewer .scale-select") || M(!1);
|
|
252
283
|
}
|
|
253
284
|
function r(t) {
|
|
254
|
-
t.key === "Escape" &&
|
|
285
|
+
t.key === "Escape" && M(!1);
|
|
255
286
|
let n = t.target && t.target.tagName;
|
|
256
|
-
n !== "INPUT" && n !== "TEXTAREA" && n !== "SELECT" && (!e.stage.current || !e.stage.current.contains(t.target) || (t.key === "ArrowLeft" || t.key === "ArrowUp" || t.key === "PageUp" ? (t.preventDefault(), X(
|
|
287
|
+
n !== "INPUT" && n !== "TEXTAREA" && n !== "SELECT" && (!e.stage.current || !e.stage.current.contains(t.target) || (t.key === "ArrowLeft" || t.key === "ArrowUp" || t.key === "PageUp" ? (t.preventDefault(), X(P.current.currentPage - 1)) : t.key === "ArrowRight" || t.key === "ArrowDown" || t.key === "PageDown" || t.key === " " ? (t.preventDefault(), X(P.current.currentPage + 1)) : t.key === "Home" ? X(0) : t.key === "End" && X(N.current.sections.length - 1)));
|
|
257
288
|
}
|
|
258
289
|
return window.addEventListener("resize", t), document.addEventListener("click", n), document.addEventListener("keydown", r), () => {
|
|
259
|
-
window.removeEventListener("resize", t), document.removeEventListener("click", n), document.removeEventListener("keydown", r),
|
|
290
|
+
window.removeEventListener("resize", t), document.removeEventListener("click", n), document.removeEventListener("keydown", r), N.current.pageObserver && (N.current.pageObserver.disconnect(), N.current.pageObserver = null);
|
|
260
291
|
};
|
|
261
292
|
}, []), n(() => {
|
|
262
|
-
|
|
263
|
-
}, [
|
|
293
|
+
U();
|
|
294
|
+
}, [x, L]), {
|
|
264
295
|
...e,
|
|
265
296
|
loading: a,
|
|
266
297
|
error: s,
|
|
267
298
|
docLoaded: u,
|
|
268
|
-
currentPage:
|
|
269
|
-
pageCount:
|
|
270
|
-
currentScale:
|
|
271
|
-
scaleMode:
|
|
272
|
-
thumbsVisible:
|
|
273
|
-
dropdownOpen:
|
|
274
|
-
setDropdownOpen:
|
|
275
|
-
pagerShown:
|
|
276
|
-
thumbsShown:
|
|
277
|
-
canPrev:
|
|
278
|
-
canNext:
|
|
279
|
-
canZoomOut:
|
|
280
|
-
canZoomIn:
|
|
281
|
-
scaleLabel:
|
|
282
|
-
open:
|
|
299
|
+
currentPage: x,
|
|
300
|
+
pageCount: C,
|
|
301
|
+
currentScale: T,
|
|
302
|
+
scaleMode: D,
|
|
303
|
+
thumbsVisible: k,
|
|
304
|
+
dropdownOpen: j,
|
|
305
|
+
setDropdownOpen: M,
|
|
306
|
+
pagerShown: I,
|
|
307
|
+
thumbsShown: L,
|
|
308
|
+
canPrev: R,
|
|
309
|
+
canNext: z,
|
|
310
|
+
canZoomOut: B,
|
|
311
|
+
canZoomIn: V,
|
|
312
|
+
scaleLabel: H,
|
|
313
|
+
open: $,
|
|
314
|
+
openUrl: ae,
|
|
283
315
|
goToPage: X,
|
|
284
|
-
jumpToPage:
|
|
285
|
-
zoomStep:
|
|
286
|
-
setScale:
|
|
287
|
-
toggleThumbs:
|
|
288
|
-
download:
|
|
316
|
+
jumpToPage: re,
|
|
317
|
+
zoomStep: q,
|
|
318
|
+
setScale: Y,
|
|
319
|
+
toggleThumbs: ee,
|
|
320
|
+
download: oe
|
|
289
321
|
};
|
|
290
322
|
}
|
|
291
323
|
//#endregion
|
|
292
324
|
//#region src/context.ts
|
|
293
|
-
var
|
|
294
|
-
function
|
|
295
|
-
let e = t(
|
|
325
|
+
var S = e(null);
|
|
326
|
+
function C() {
|
|
327
|
+
let e = t(S);
|
|
296
328
|
if (!e) throw Error("DocxViewer components must be used inside <DocxViewer>");
|
|
297
329
|
return e;
|
|
298
330
|
}
|
|
299
331
|
//#endregion
|
|
300
332
|
//#region src/components/icons/IconThumbs.tsx
|
|
301
|
-
function
|
|
333
|
+
function w() {
|
|
302
334
|
return /* @__PURE__ */ u("svg", {
|
|
303
335
|
width: "16",
|
|
304
336
|
height: "16",
|
|
@@ -315,7 +347,7 @@ function C() {
|
|
|
315
347
|
}
|
|
316
348
|
//#endregion
|
|
317
349
|
//#region src/components/icons/IconPrevPage.tsx
|
|
318
|
-
function
|
|
350
|
+
function T() {
|
|
319
351
|
return /* @__PURE__ */ u("svg", {
|
|
320
352
|
width: "16",
|
|
321
353
|
height: "16",
|
|
@@ -333,7 +365,7 @@ function w() {
|
|
|
333
365
|
}
|
|
334
366
|
//#endregion
|
|
335
367
|
//#region src/components/icons/IconNextPage.tsx
|
|
336
|
-
function
|
|
368
|
+
function E() {
|
|
337
369
|
return /* @__PURE__ */ u("svg", {
|
|
338
370
|
width: "16",
|
|
339
371
|
height: "16",
|
|
@@ -351,7 +383,7 @@ function T() {
|
|
|
351
383
|
}
|
|
352
384
|
//#endregion
|
|
353
385
|
//#region src/components/icons/IconZoomOut.tsx
|
|
354
|
-
function
|
|
386
|
+
function D() {
|
|
355
387
|
return /* @__PURE__ */ d("svg", {
|
|
356
388
|
width: "16",
|
|
357
389
|
height: "16",
|
|
@@ -375,7 +407,7 @@ function E() {
|
|
|
375
407
|
}
|
|
376
408
|
//#endregion
|
|
377
409
|
//#region src/components/icons/IconZoomIn.tsx
|
|
378
|
-
function
|
|
410
|
+
function O() {
|
|
379
411
|
return /* @__PURE__ */ d("svg", {
|
|
380
412
|
width: "16",
|
|
381
413
|
height: "16",
|
|
@@ -399,7 +431,7 @@ function D() {
|
|
|
399
431
|
}
|
|
400
432
|
//#endregion
|
|
401
433
|
//#region src/components/icons/IconChevronDown.tsx
|
|
402
|
-
function
|
|
434
|
+
function k() {
|
|
403
435
|
return /* @__PURE__ */ u("svg", {
|
|
404
436
|
width: "10",
|
|
405
437
|
height: "10",
|
|
@@ -417,7 +449,7 @@ function O() {
|
|
|
417
449
|
}
|
|
418
450
|
//#endregion
|
|
419
451
|
//#region src/components/icons/IconOpenFile.tsx
|
|
420
|
-
function
|
|
452
|
+
function A() {
|
|
421
453
|
return /* @__PURE__ */ u("svg", {
|
|
422
454
|
width: "16",
|
|
423
455
|
height: "16",
|
|
@@ -434,7 +466,7 @@ function k() {
|
|
|
434
466
|
}
|
|
435
467
|
//#endregion
|
|
436
468
|
//#region src/components/icons/IconDownload.tsx
|
|
437
|
-
function
|
|
469
|
+
function j() {
|
|
438
470
|
return /* @__PURE__ */ u("svg", {
|
|
439
471
|
width: "16",
|
|
440
472
|
height: "16",
|
|
@@ -452,7 +484,7 @@ function A() {
|
|
|
452
484
|
}
|
|
453
485
|
//#endregion
|
|
454
486
|
//#region src/components/Toolbar.tsx
|
|
455
|
-
var
|
|
487
|
+
var M = [
|
|
456
488
|
"fit",
|
|
457
489
|
"0.5",
|
|
458
490
|
"0.75",
|
|
@@ -461,8 +493,8 @@ var j = [
|
|
|
461
493
|
"1.5",
|
|
462
494
|
"2"
|
|
463
495
|
];
|
|
464
|
-
function
|
|
465
|
-
let e =
|
|
496
|
+
function N() {
|
|
497
|
+
let e = C(), t = r(null);
|
|
466
498
|
function n(t) {
|
|
467
499
|
let n = t.currentTarget;
|
|
468
500
|
e.jumpToPage(n.value), n.blur();
|
|
@@ -484,7 +516,7 @@ function M() {
|
|
|
484
516
|
title: "缩略图",
|
|
485
517
|
disabled: !e.docLoaded || e.pageCount <= 1,
|
|
486
518
|
onClick: e.toggleThumbs,
|
|
487
|
-
children: /* @__PURE__ */ u(
|
|
519
|
+
children: /* @__PURE__ */ u(w, {})
|
|
488
520
|
}),
|
|
489
521
|
/* @__PURE__ */ u("span", { className: "toolbar-divider" }),
|
|
490
522
|
/* @__PURE__ */ d("span", {
|
|
@@ -497,7 +529,7 @@ function M() {
|
|
|
497
529
|
title: "上一页",
|
|
498
530
|
disabled: !e.canPrev,
|
|
499
531
|
onClick: () => e.goToPage(e.currentPage - 1),
|
|
500
|
-
children: /* @__PURE__ */ u(
|
|
532
|
+
children: /* @__PURE__ */ u(T, {})
|
|
501
533
|
}),
|
|
502
534
|
/* @__PURE__ */ d("span", {
|
|
503
535
|
className: "page-info",
|
|
@@ -523,7 +555,7 @@ function M() {
|
|
|
523
555
|
title: "下一页",
|
|
524
556
|
disabled: !e.canNext,
|
|
525
557
|
onClick: () => e.goToPage(e.currentPage + 1),
|
|
526
|
-
children: /* @__PURE__ */ u(
|
|
558
|
+
children: /* @__PURE__ */ u(E, {})
|
|
527
559
|
})
|
|
528
560
|
]
|
|
529
561
|
})
|
|
@@ -540,7 +572,7 @@ function M() {
|
|
|
540
572
|
title: "缩小",
|
|
541
573
|
disabled: !e.canZoomOut,
|
|
542
574
|
onClick: () => e.zoomStep(-1),
|
|
543
|
-
children: /* @__PURE__ */ u(
|
|
575
|
+
children: /* @__PURE__ */ u(D, {})
|
|
544
576
|
}),
|
|
545
577
|
/* @__PURE__ */ d("div", {
|
|
546
578
|
className: "scale-select",
|
|
@@ -550,11 +582,11 @@ function M() {
|
|
|
550
582
|
onClick: (t) => {
|
|
551
583
|
t.stopPropagation(), e.setDropdownOpen(!e.dropdownOpen);
|
|
552
584
|
},
|
|
553
|
-
children: [/* @__PURE__ */ u("span", { children: e.scaleLabel }), /* @__PURE__ */ u(
|
|
585
|
+
children: [/* @__PURE__ */ u("span", { children: e.scaleLabel }), /* @__PURE__ */ u(k, {})]
|
|
554
586
|
}), /* @__PURE__ */ u("div", {
|
|
555
587
|
className: "dropdown",
|
|
556
588
|
hidden: !e.dropdownOpen,
|
|
557
|
-
children:
|
|
589
|
+
children: M.map((t) => /* @__PURE__ */ u("button", {
|
|
558
590
|
type: "button",
|
|
559
591
|
className: e.scaleMode === "fit" && t === "fit" || String(e.scaleMode) === t ? "selected" : void 0,
|
|
560
592
|
onClick: () => e.setScale(t),
|
|
@@ -568,7 +600,7 @@ function M() {
|
|
|
568
600
|
title: "放大",
|
|
569
601
|
disabled: !e.canZoomIn,
|
|
570
602
|
onClick: () => e.zoomStep(1),
|
|
571
|
-
children: /* @__PURE__ */ u(
|
|
603
|
+
children: /* @__PURE__ */ u(O, {})
|
|
572
604
|
})
|
|
573
605
|
]
|
|
574
606
|
})
|
|
@@ -581,7 +613,7 @@ function M() {
|
|
|
581
613
|
type: "button",
|
|
582
614
|
title: "打开文档",
|
|
583
615
|
onClick: () => t.current?.click(),
|
|
584
|
-
children: /* @__PURE__ */ u(
|
|
616
|
+
children: /* @__PURE__ */ u(A, {})
|
|
585
617
|
}),
|
|
586
618
|
/* @__PURE__ */ u("button", {
|
|
587
619
|
className: "tbtn",
|
|
@@ -589,7 +621,7 @@ function M() {
|
|
|
589
621
|
title: "下载文档",
|
|
590
622
|
disabled: !e.docLoaded,
|
|
591
623
|
onClick: e.download,
|
|
592
|
-
children: /* @__PURE__ */ u(
|
|
624
|
+
children: /* @__PURE__ */ u(j, {})
|
|
593
625
|
}),
|
|
594
626
|
/* @__PURE__ */ u("input", {
|
|
595
627
|
ref: t,
|
|
@@ -605,8 +637,8 @@ function M() {
|
|
|
605
637
|
}
|
|
606
638
|
//#endregion
|
|
607
639
|
//#region src/components/ErrorBanner.tsx
|
|
608
|
-
function
|
|
609
|
-
let e =
|
|
640
|
+
function P() {
|
|
641
|
+
let e = C();
|
|
610
642
|
return /* @__PURE__ */ d("div", {
|
|
611
643
|
className: "error-banner",
|
|
612
644
|
hidden: !e.error,
|
|
@@ -615,8 +647,8 @@ function N() {
|
|
|
615
647
|
}
|
|
616
648
|
//#endregion
|
|
617
649
|
//#region src/components/ThumbnailsSidebar.tsx
|
|
618
|
-
function
|
|
619
|
-
let e =
|
|
650
|
+
function F() {
|
|
651
|
+
let e = C();
|
|
620
652
|
function t(t) {
|
|
621
653
|
let n = t.target.closest(".thumb");
|
|
622
654
|
n && e.goToPage(Number(n.getAttribute("data-page")));
|
|
@@ -631,8 +663,8 @@ function P() {
|
|
|
631
663
|
}
|
|
632
664
|
//#endregion
|
|
633
665
|
//#region src/components/DocumentStage.tsx
|
|
634
|
-
function
|
|
635
|
-
let e =
|
|
666
|
+
function I() {
|
|
667
|
+
let e = C();
|
|
636
668
|
return /* @__PURE__ */ d("main", {
|
|
637
669
|
ref: e.stage,
|
|
638
670
|
className: "stage",
|
|
@@ -648,37 +680,37 @@ function F() {
|
|
|
648
680
|
}
|
|
649
681
|
//#endregion
|
|
650
682
|
//#region src/DocxViewer.tsx
|
|
651
|
-
function
|
|
652
|
-
let
|
|
683
|
+
function L({ url: e, customRequest: t, name: i, initialScale: a, showThumbs: o, renderOptions: s, className: c, style: l, onRendered: f, onError: p }) {
|
|
684
|
+
let m = x({
|
|
653
685
|
stage: r(null),
|
|
654
686
|
docBox: r(null),
|
|
655
687
|
thumbs: r(null)
|
|
656
688
|
}, {
|
|
657
|
-
initialScale:
|
|
658
|
-
showThumbs:
|
|
659
|
-
renderOptions:
|
|
660
|
-
onRendered:
|
|
661
|
-
onError:
|
|
662
|
-
});
|
|
663
|
-
return n(() => {
|
|
664
|
-
e &&
|
|
665
|
-
}, [e,
|
|
666
|
-
value:
|
|
689
|
+
initialScale: a,
|
|
690
|
+
showThumbs: o,
|
|
691
|
+
renderOptions: s,
|
|
692
|
+
onRendered: f,
|
|
693
|
+
onError: p
|
|
694
|
+
}), h = r(t);
|
|
695
|
+
return h.current = t, n(() => {
|
|
696
|
+
e && m.openUrl(e, h.current, i);
|
|
697
|
+
}, [e, i]), /* @__PURE__ */ u(S.Provider, {
|
|
698
|
+
value: m,
|
|
667
699
|
children: /* @__PURE__ */ d("div", {
|
|
668
|
-
className:
|
|
669
|
-
style:
|
|
700
|
+
className: c ? `docx-viewer ${c}` : "docx-viewer",
|
|
701
|
+
style: l,
|
|
670
702
|
children: [
|
|
671
|
-
/* @__PURE__ */ u(M, {}),
|
|
672
703
|
/* @__PURE__ */ u(N, {}),
|
|
704
|
+
/* @__PURE__ */ u(P, {}),
|
|
673
705
|
/* @__PURE__ */ d("div", {
|
|
674
706
|
className: "body",
|
|
675
|
-
children: [/* @__PURE__ */ u(
|
|
707
|
+
children: [/* @__PURE__ */ u(F, {}), /* @__PURE__ */ u(I, {})]
|
|
676
708
|
})
|
|
677
709
|
]
|
|
678
710
|
})
|
|
679
711
|
});
|
|
680
712
|
}
|
|
681
713
|
//#endregion
|
|
682
|
-
export {
|
|
714
|
+
export { L as DocxPreview, L as DocxViewer, L as default, a as defaultOptions, o as parseAsync, s as renderAsync, l as renderDocument, x as useDocViewer };
|
|
683
715
|
|
|
684
716
|
//# sourceMappingURL=index.js.map
|