@glodon-aiot/react-components 3.19.0-alpha.22 → 3.19.0-alpha.24

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.
@@ -1,367 +1,439 @@
1
- var v = (i, r, n) => new Promise((y, m) => {
2
- var C = (s) => {
1
+ var g = (o, n, r) => new Promise((f, u) => {
2
+ var w = (l) => {
3
3
  try {
4
- e(n.next(s));
5
- } catch (u) {
6
- m(u);
4
+ e(r.next(l));
5
+ } catch (s) {
6
+ u(s);
7
7
  }
8
- }, k = (s) => {
8
+ }, h = (l) => {
9
9
  try {
10
- e(n.throw(s));
11
- } catch (u) {
12
- m(u);
10
+ e(r.throw(l));
11
+ } catch (s) {
12
+ u(s);
13
13
  }
14
- }, e = (s) => s.done ? y(s.value) : Promise.resolve(s.value).then(C, k);
15
- e((n = n.apply(i, r)).next());
14
+ }, e = (l) => l.done ? f(l.value) : Promise.resolve(l.value).then(w, h);
15
+ e((r = r.apply(o, n)).next());
16
16
  });
17
- import { jsxs as g, jsx as t } from "react/jsx-runtime";
18
- import { useMemo as x, useState as w, useEffect as oe, useCallback as B } from "react";
19
- import { message as h, Space as ie, Button as ae, Dropdown as se, Spin as ce } from "antd";
20
- import { DownloadOutlined as le, CopyOutlined as de } from "@ant-design/icons";
21
- import { getFileExtension as A, getFileType as ue } from "../../utils/file.mjs";
22
- import { MAX_FILE_SIZE as S } from "./constants.mjs";
23
- import { normalizeUrl as me } from "./utils.mjs";
24
- import { useZipViewer as pe } from "./hooks/useZipViewer.mjs";
25
- import { TextRenderer as P, CodeRenderer as fe, XmlRenderer as we, HtmlRenderer as he, MarkdownRenderer as ve, JsonlRenderer as xe, TsvRenderer as ye, CsvRenderer as be, JsonRenderer as ge } from "./components/FileRenderers.mjs";
26
- import { AudioRenderer as Ce, VideoRenderer as ke, ImageRenderer as Fe } from "./components/MediaRenderers.mjs";
27
- import { ZipRenderer as Re } from "./components/ZipRenderer.mjs";
28
- import { ErrorAlert as ze } from "./components/ErrorAlert.mjs";
17
+ import { jsxs as C, jsx as t } from "react/jsx-runtime";
18
+ import { useMemo as x, useState as p, useEffect as _, useCallback as M, useRef as de } from "react";
19
+ import { message as b, Space as ue, Button as D, Dropdown as me, Spin as Z, Alert as J } from "antd";
20
+ import { DownloadOutlined as L, CopyOutlined as pe } from "@ant-design/icons";
21
+ import { renderAsync as fe } from "docx-preview";
22
+ import { getFileExtension as V, getFileType as we } from "../../utils/file.mjs";
23
+ import { MAX_FILE_SIZE as B } from "./constants.mjs";
24
+ import { normalizeUrl as he } from "./utils.mjs";
25
+ import { useZipViewer as ye } from "./hooks/useZipViewer.mjs";
26
+ import { TextRenderer as X, CodeRenderer as ve, XmlRenderer as ge, HtmlRenderer as xe, MarkdownRenderer as be, JsonlRenderer as ke, TsvRenderer as Ce, CsvRenderer as Te, JsonRenderer as Re } from "./components/FileRenderers.mjs";
27
+ import { AudioRenderer as Fe, VideoRenderer as ze, ImageRenderer as Ne } from "./components/MediaRenderers.mjs";
28
+ import { ZipRenderer as Ee } from "./components/ZipRenderer.mjs";
29
+ import { ErrorAlert as Me } from "./components/ErrorAlert.mjs";
29
30
  import "./style.less.mjs";
30
- import Te from "./components/PDFViewer/index.mjs";
31
- const Ne = (i) => {
32
- if (!i)
31
+ import Be from "./components/PDFViewer/index.mjs";
32
+ const De = (o) => {
33
+ if (!o)
33
34
  return "unknown";
34
- const r = i.split(";")[0].trim().toLowerCase();
35
- return r.startsWith("image/") ? "image" : r.startsWith("video/") ? "video" : r.startsWith("audio/") ? "audio" : r === "application/pdf" ? "pdf" : r === "text/markdown" || r === "text/x-markdown" ? "markdown" : r === "application/json" ? "json" : r === "application/jsonl" ? "jsonl" : r === "text/csv" || r === "application/csv" ? "csv" : r === "text/tab-separated-values" ? "tsv" : r === "application/javascript" || r === "text/javascript" ? "code" : r === "application/xml" || r === "text/xml" ? "xml" : r === "text/html" || r === "application/xhtml+xml" ? "html" : r === "text/plain" ? "text" : "unknown";
36
- }, Ee = (i) => !i || Number.isNaN(i) ? "大小未知" : i < 1024 ? `${i}B` : i < 1024 * 1024 ? `${(i / 1024).toFixed(1)}KB` : i < 1024 * 1024 * 1024 ? `${(i / 1024 / 1024).toFixed(1)}MB` : `${(i / 1024 / 1024 / 1024).toFixed(1)}GB`, Be = (i, r) => {
37
- if (r)
38
- return r;
35
+ const n = o.split(";")[0].trim().toLowerCase();
36
+ return n.startsWith("image/") ? "image" : n.startsWith("video/") ? "video" : n.startsWith("audio/") ? "audio" : n === "application/pdf" ? "pdf" : n === "text/markdown" || n === "text/x-markdown" ? "markdown" : n === "application/json" ? "json" : n === "application/jsonl" ? "jsonl" : n === "text/csv" || n === "application/csv" ? "csv" : n === "text/tab-separated-values" ? "tsv" : n === "application/javascript" || n === "text/javascript" ? "code" : n === "application/xml" || n === "text/xml" ? "xml" : n === "text/html" || n === "application/xhtml+xml" ? "html" : n === "text/plain" ? "text" : "unknown";
37
+ }, Le = (o) => !o || Number.isNaN(o) ? "大小未知" : o < 1024 ? `${o}B` : o < 1024 * 1024 ? `${(o / 1024).toFixed(1)}KB` : o < 1024 * 1024 * 1024 ? `${(o / 1024 / 1024).toFixed(1)}MB` : `${(o / 1024 / 1024 / 1024).toFixed(1)}GB`, Se = (o, n) => {
38
+ if (n)
39
+ return n;
39
40
  try {
40
- const m = new URL(i).pathname.split("/").filter(Boolean).pop();
41
- return decodeURIComponent(m || i);
42
- } catch (n) {
43
- return i;
41
+ const u = new URL(o).pathname.split("/").filter(Boolean).pop();
42
+ return decodeURIComponent(u || o);
43
+ } catch (r) {
44
+ return o;
44
45
  }
45
- }, Se = (i) => {
46
+ }, je = (o) => {
46
47
  const {
47
- url: r,
48
- fileName: n,
49
- className: y,
50
- style: m,
51
- showToolbar: C = !1,
52
- page: k = 1
53
- } = i, e = x(() => me(r), [r]);
48
+ url: n,
49
+ fileName: r,
50
+ className: f,
51
+ style: u,
52
+ showToolbar: w = !1,
53
+ page: h = 1
54
+ } = o, e = x(() => he(n), [n]);
54
55
  console.log("normalizedUrl", e);
55
- const s = x(() => {
56
- const c = A(e), o = n ? A(n) : void 0;
57
- return ue(c || o);
58
- }, [e, n]), [u, b] = w(s), {
59
- zipFiles: W,
60
- zipLoading: H,
61
- zipError: Z,
62
- selectedZipFile: _,
63
- zipFileContent: J,
64
- handleFileClick: X
65
- } = pe(s === "zip" ? e : ""), [G, d] = w(!0), [U, p] = w(null), [a, j] = w(null), [l, M] = w(0), [K, $] = w(!1), D = x(() => Be(e, n), [n, e]), q = x(() => Ee(l), [l]), F = !!(a != null && a.content), Q = !F && !e, Y = x(() => [{
56
+ const l = x(() => V(e) || V(r || ""), [e, r]), s = x(() => we(l), [l]), [k, T] = p(s), {
57
+ zipFiles: G,
58
+ zipLoading: K,
59
+ zipError: q,
60
+ selectedZipFile: Q,
61
+ zipFileContent: Y,
62
+ handleFileClick: ee
63
+ } = ye(s === "zip" ? e : ""), [te, m] = p(!0), [S, y] = p(null), [a, j] = p(null), [c, $] = p(0), [re, O] = p(!1), U = x(() => Se(e, r), [r, e]), ne = x(() => Le(c), [c]), R = !!(a != null && a.content), oe = !R && !e, ie = x(() => [{
66
64
  key: "copy-content",
67
65
  label: "复制内容",
68
- disabled: !F
66
+ disabled: !R
69
67
  }, {
70
68
  key: "copy-url",
71
69
  label: "复制地址",
72
70
  disabled: !e
73
- }], [F, e]);
74
- oe(() => {
75
- if (b(s), s === "pdf" || s === "zip") {
76
- d(!1);
71
+ }], [R, e]);
72
+ _(() => {
73
+ if (T(s), s === "pdf" || s === "zip") {
74
+ m(!1);
77
75
  return;
78
76
  }
79
77
  if (!e) {
80
- p("文件URL不能为空"), d(!1);
78
+ y("文件URL不能为空"), m(!1);
81
79
  return;
82
80
  }
83
81
  if (["image", "video", "audio", "office"].includes(s)) {
84
- d(!1);
82
+ m(!1);
85
83
  return;
86
84
  }
87
- d(!0), p(null), v(void 0, null, function* () {
85
+ m(!0), y(null), g(void 0, null, function* () {
88
86
  try {
89
87
  if (e.startsWith("blob:") || e.startsWith("data:")) {
90
- const f = yield fetch(e);
91
- if (!f.ok)
92
- throw new Error(`HTTP error! status: ${f.status}`);
93
- const V = yield f.blob(), E = V.size;
94
- if (M(E), E > S) {
95
- p(`文件过大(${Math.round(E / 1024 / 1024)}MB),无法预览。请下载后查看。`), d(!1);
88
+ const v = yield fetch(e);
89
+ if (!v.ok)
90
+ throw new Error(`HTTP error! status: ${v.status}`);
91
+ const P = yield v.blob(), E = P.size;
92
+ if ($(E), E > B) {
93
+ y(`文件过大(${Math.round(E / 1024 / 1024)}MB),无法预览。请下载后查看。`), m(!1);
96
94
  return;
97
95
  }
98
- const ne = yield V.text();
99
- s === "unknown" && b("text"), j({
100
- content: ne
101
- }), d(!1);
96
+ const ce = yield P.text();
97
+ s === "unknown" && T("text"), j({
98
+ content: ce
99
+ }), m(!1);
102
100
  return;
103
101
  }
104
- const o = yield fetch(e, {
102
+ const i = yield fetch(e, {
105
103
  method: "HEAD"
106
- }), z = o.headers.get("Content-Length"), re = o.headers.get("Content-Type"), T = z ? parseInt(z, 10) : 0;
107
- if (M(T), s === "unknown") {
108
- const f = Ne(re);
109
- f !== "unknown" && b(f);
104
+ }), I = i.headers.get("Content-Length"), le = i.headers.get("Content-Type"), z = I ? parseInt(I, 10) : 0;
105
+ if ($(z), s === "unknown") {
106
+ const v = De(le);
107
+ v !== "unknown" && T(v);
110
108
  }
111
- if (T > S) {
112
- p(`文件过大(${Math.round(T / 1024 / 1024)}MB),无法预览。请下载后查看。`), d(!1);
109
+ if (z > B) {
110
+ y(`文件过大(${Math.round(z / 1024 / 1024)}MB),无法预览。请下载后查看。`), m(!1);
113
111
  return;
114
112
  }
115
113
  const N = yield fetch(e);
116
114
  if (!N.ok)
117
115
  throw new Error(`HTTP error! status: ${N.status}`);
118
- const O = yield N.text(), I = new Blob([O]).size;
119
- if (I > S) {
120
- p(`文件过大(${Math.round(I / 1024 / 1024)}MB),无法预览。请下载后查看。`), d(!1);
116
+ const A = yield N.text(), W = new Blob([A]).size;
117
+ if (W > B) {
118
+ y(`文件过大(${Math.round(W / 1024 / 1024)}MB),无法预览。请下载后查看。`), m(!1);
121
119
  return;
122
120
  }
123
- u === "unknown" && b("text"), j({
124
- content: O
125
- }), d(!1);
126
- } catch (c) {
127
- p(c.message || "加载文件失败"), d(!1);
121
+ k === "unknown" && T("text"), j({
122
+ content: A
123
+ }), m(!1);
124
+ } catch (d) {
125
+ y(d.message || "加载文件失败"), m(!1);
128
126
  }
129
127
  });
130
128
  }, [e, s]);
131
- const R = B(() => v(void 0, null, function* () {
132
- var c;
129
+ const F = M(() => g(void 0, null, function* () {
130
+ var d;
133
131
  if (!(a != null && a.content)) {
134
- h.warning("暂无可复制的内容");
132
+ b.warning("暂无可复制的内容");
135
133
  return;
136
134
  }
137
135
  try {
138
- if ($(!0), (c = navigator == null ? void 0 : navigator.clipboard) != null && c.writeText)
136
+ if (O(!0), (d = navigator == null ? void 0 : navigator.clipboard) != null && d.writeText)
139
137
  yield navigator.clipboard.writeText(a.content);
140
138
  else {
141
- const o = document.createElement("textarea");
142
- o.value = a.content, o.style.position = "fixed", o.style.opacity = "0", document.body.appendChild(o), o.select(), document.execCommand("copy"), document.body.removeChild(o);
139
+ const i = document.createElement("textarea");
140
+ i.value = a.content, i.style.position = "fixed", i.style.opacity = "0", document.body.appendChild(i), i.select(), document.execCommand("copy"), document.body.removeChild(i);
143
141
  }
144
- h.success("内容已复制到剪贴板");
145
- } catch (o) {
146
- h.error((o == null ? void 0 : o.message) || "复制失败,请手动复制");
142
+ b.success("内容已复制到剪贴板");
143
+ } catch (i) {
144
+ b.error((i == null ? void 0 : i.message) || "复制失败,请手动复制");
147
145
  } finally {
148
- $(!1);
146
+ O(!1);
149
147
  }
150
- }), [a]), L = B(() => v(void 0, null, function* () {
151
- var c;
148
+ }), [a]), H = M(() => g(void 0, null, function* () {
149
+ var d;
152
150
  if (!e) {
153
- h.warning("暂无可复制的地址");
151
+ b.warning("暂无可复制的地址");
154
152
  return;
155
153
  }
156
154
  try {
157
- if ((c = navigator == null ? void 0 : navigator.clipboard) != null && c.writeText)
155
+ if ((d = navigator == null ? void 0 : navigator.clipboard) != null && d.writeText)
158
156
  yield navigator.clipboard.writeText(e);
159
157
  else {
160
- const o = document.createElement("textarea");
161
- o.value = e, o.style.position = "fixed", o.style.opacity = "0", document.body.appendChild(o), o.select(), document.execCommand("copy"), document.body.removeChild(o);
158
+ const i = document.createElement("textarea");
159
+ i.value = e, i.style.position = "fixed", i.style.opacity = "0", document.body.appendChild(i), i.select(), document.execCommand("copy"), document.body.removeChild(i);
162
160
  }
163
- h.success("链接已复制到剪贴板");
164
- } catch (o) {
165
- h.error((o == null ? void 0 : o.message) || "复制失败,请手动复制");
161
+ b.success("链接已复制到剪贴板");
162
+ } catch (i) {
163
+ b.error((i == null ? void 0 : i.message) || "复制失败,请手动复制");
166
164
  }
167
- }), [e]), ee = B((o) => v(void 0, [o], function* ({
168
- key: c
165
+ }), [e]), ae = M((i) => g(void 0, [i], function* ({
166
+ key: d
169
167
  }) {
170
- c === "copy-content" && (yield R()), c === "copy-url" && (yield L());
171
- }), [R, L]), te = () => {
172
- if (G)
168
+ d === "copy-content" && (yield F()), d === "copy-url" && (yield H());
169
+ }), [F, H]), se = () => {
170
+ if (te)
173
171
  return /* @__PURE__ */ t("div", {
174
172
  className: "document-viewer-loading",
175
- children: /* @__PURE__ */ t(ce, {
173
+ children: /* @__PURE__ */ t(Z, {
176
174
  size: "large",
177
175
  tip: "加载中..."
178
176
  })
179
177
  });
180
- if (U)
181
- return /* @__PURE__ */ t(ze, {
178
+ if (S)
179
+ return /* @__PURE__ */ t(Me, {
182
180
  message: "加载失败",
183
- description: U,
181
+ description: S,
184
182
  url: e,
185
- fileName: n
183
+ fileName: r
186
184
  });
187
- if (u === "unknown" && (a != null && a.content))
188
- return /* @__PURE__ */ t(P, {
185
+ if (k === "unknown" && (a != null && a.content))
186
+ return /* @__PURE__ */ t(X, {
189
187
  fileContent: a,
190
- fileSize: l,
188
+ fileSize: c,
191
189
  url: e,
192
- fileName: n
190
+ fileName: r
193
191
  });
194
- switch (u) {
192
+ switch (k) {
195
193
  case "text":
196
- return /* @__PURE__ */ t(P, {
194
+ return /* @__PURE__ */ t(X, {
197
195
  fileContent: a,
198
- fileSize: l,
196
+ fileSize: c,
199
197
  url: e,
200
- fileName: n
198
+ fileName: r
201
199
  });
202
200
  case "json":
203
- return /* @__PURE__ */ t(ge, {
201
+ return /* @__PURE__ */ t(Re, {
204
202
  fileContent: a,
205
- fileSize: l,
203
+ fileSize: c,
206
204
  url: e,
207
- fileName: n
205
+ fileName: r
208
206
  });
209
207
  case "csv":
210
- return /* @__PURE__ */ t(be, {
208
+ return /* @__PURE__ */ t(Te, {
211
209
  fileContent: a,
212
- fileSize: l,
210
+ fileSize: c,
213
211
  url: e,
214
- fileName: n
212
+ fileName: r
215
213
  });
216
214
  case "tsv":
217
- return /* @__PURE__ */ t(ye, {
215
+ return /* @__PURE__ */ t(Ce, {
218
216
  fileContent: a,
219
- fileSize: l,
217
+ fileSize: c,
220
218
  url: e,
221
- fileName: n
219
+ fileName: r
222
220
  });
223
221
  case "jsonl":
224
- return /* @__PURE__ */ t(xe, {
222
+ return /* @__PURE__ */ t(ke, {
225
223
  fileContent: a,
226
- fileSize: l,
224
+ fileSize: c,
227
225
  url: e,
228
- fileName: n
226
+ fileName: r
229
227
  });
230
228
  case "markdown":
231
- return /* @__PURE__ */ t(ve, {
229
+ return /* @__PURE__ */ t(be, {
232
230
  fileContent: a,
233
- fileSize: l,
231
+ fileSize: c,
234
232
  url: e,
235
- fileName: n
233
+ fileName: r
236
234
  });
237
235
  case "html":
238
- return /* @__PURE__ */ t(he, {
236
+ return /* @__PURE__ */ t(xe, {
239
237
  fileContent: a,
240
- fileSize: l,
238
+ fileSize: c,
241
239
  url: e,
242
- fileName: n
240
+ fileName: r
243
241
  });
244
242
  case "xml":
245
- return /* @__PURE__ */ t(we, {
243
+ return /* @__PURE__ */ t(ge, {
246
244
  fileContent: a,
247
- fileSize: l,
245
+ fileSize: c,
248
246
  url: e,
249
- fileName: n
247
+ fileName: r
250
248
  });
251
249
  case "code":
252
- return /* @__PURE__ */ t(fe, {
250
+ return /* @__PURE__ */ t(ve, {
253
251
  fileContent: a,
254
- fileSize: l,
252
+ fileSize: c,
255
253
  url: e,
256
- fileName: n
254
+ fileName: r
257
255
  });
258
256
  case "image":
259
- return /* @__PURE__ */ t(Fe, {
257
+ return /* @__PURE__ */ t(Ne, {
260
258
  url: e,
261
- fileName: n
259
+ fileName: r
262
260
  });
263
261
  case "video":
264
- return /* @__PURE__ */ t(ke, {
262
+ return /* @__PURE__ */ t(ze, {
265
263
  url: e,
266
- fileName: n
264
+ fileName: r
267
265
  });
268
266
  case "audio":
269
- return /* @__PURE__ */ t(Ce, {
267
+ return /* @__PURE__ */ t(Fe, {
270
268
  url: e,
271
- fileName: n
269
+ fileName: r
272
270
  });
273
271
  case "pdf":
274
- return /* @__PURE__ */ t(Te, {
272
+ return /* @__PURE__ */ t(Be, {
275
273
  fileUrl: e,
276
- pageNumber: k
274
+ pageNumber: h
277
275
  });
278
276
  case "office":
279
- return /* @__PURE__ */ t(Ue, {
280
- url: e
277
+ return /* @__PURE__ */ t($e, {
278
+ url: e,
279
+ fileName: r,
280
+ extension: l
281
281
  });
282
282
  case "zip":
283
- return /* @__PURE__ */ t(Re, {
284
- zipFiles: W,
285
- zipLoading: H,
286
- zipError: Z,
287
- selectedZipFile: _,
288
- zipFileContent: J,
289
- onFileClick: X,
283
+ return /* @__PURE__ */ t(Ee, {
284
+ zipFiles: G,
285
+ zipLoading: K,
286
+ zipError: q,
287
+ selectedZipFile: Q,
288
+ zipFileContent: Y,
289
+ onFileClick: ee,
290
290
  url: e
291
291
  });
292
292
  case "unknown":
293
293
  default:
294
- return /* @__PURE__ */ t(je, {
294
+ return /* @__PURE__ */ t(Ue, {
295
295
  url: e
296
296
  });
297
297
  }
298
298
  };
299
- return /* @__PURE__ */ g("div", {
300
- className: `document-viewer ${y || ""}`,
301
- style: m,
302
- children: [C && /* @__PURE__ */ g("div", {
299
+ return /* @__PURE__ */ C("div", {
300
+ className: `document-viewer ${f || ""}`,
301
+ style: u,
302
+ children: [w && /* @__PURE__ */ C("div", {
303
303
  className: "document-viewer-toolbar",
304
- children: [/* @__PURE__ */ g("div", {
304
+ children: [/* @__PURE__ */ C("div", {
305
305
  className: "document-viewer-toolbar-meta",
306
306
  children: [/* @__PURE__ */ t("span", {
307
307
  className: "document-viewer-toolbar-name",
308
- title: D,
309
- children: D
308
+ title: U,
309
+ children: U
310
310
  }), /* @__PURE__ */ t("span", {
311
311
  className: "document-viewer-toolbar-size",
312
- children: q
312
+ children: ne
313
313
  })]
314
- }), /* @__PURE__ */ g(ie, {
314
+ }), /* @__PURE__ */ C(ue, {
315
315
  size: 8,
316
316
  wrap: !0,
317
- children: [/* @__PURE__ */ t(ae, {
318
- icon: /* @__PURE__ */ t(le, {}),
317
+ children: [/* @__PURE__ */ t(D, {
318
+ icon: /* @__PURE__ */ t(L, {}),
319
319
  size: "small",
320
320
  href: e,
321
321
  target: "_blank",
322
322
  rel: "noopener noreferrer",
323
- download: n || void 0,
323
+ download: r || void 0,
324
324
  children: "下载"
325
- }), /* @__PURE__ */ t(se.Button, {
325
+ }), /* @__PURE__ */ t(me.Button, {
326
326
  size: "small",
327
- icon: /* @__PURE__ */ t(de, {}),
327
+ icon: /* @__PURE__ */ t(pe, {}),
328
328
  menu: {
329
- items: Y,
330
- onClick: ee
329
+ items: ie,
330
+ onClick: ae
331
331
  },
332
- disabled: Q,
333
- loading: K,
334
- onClick: R,
332
+ disabled: oe,
333
+ loading: re,
334
+ onClick: F,
335
335
  children: "复制"
336
336
  })]
337
337
  })]
338
338
  }), /* @__PURE__ */ t("div", {
339
339
  className: "document-viewer-body",
340
- children: te()
340
+ children: se()
341
341
  })]
342
342
  });
343
- }, Ue = ({
344
- url: i
345
- }) => {
346
- const r = `https://view.officeapps.live.com/op/embed.aspx?src=${encodeURIComponent(i)}`;
347
- return /* @__PURE__ */ t("div", {
348
- className: "document-viewer-office",
349
- children: /* @__PURE__ */ t("iframe", {
350
- src: r,
351
- className: "document-viewer-iframe",
352
- title: "Office Document Preview"
343
+ }, $e = ({
344
+ url: o,
345
+ fileName: n,
346
+ extension: r
347
+ }) => r === "docx" ? /* @__PURE__ */ t(Oe, {
348
+ url: o,
349
+ fileName: n
350
+ }) : /* @__PURE__ */ t("div", {
351
+ className: "document-viewer-office",
352
+ children: /* @__PURE__ */ t(J, {
353
+ className: "document-viewer-alert-full",
354
+ message: "暂不支持在线预览",
355
+ description: "当前仅支持 docx 文件在线预览,其他 Office 文档请下载后查看。",
356
+ type: "info",
357
+ showIcon: !0,
358
+ action: /* @__PURE__ */ t(D, {
359
+ type: "link",
360
+ icon: /* @__PURE__ */ t(L, {}),
361
+ href: o,
362
+ download: n,
363
+ target: "_blank",
364
+ rel: "noopener noreferrer",
365
+ children: "下载文件"
353
366
  })
367
+ })
368
+ }), Oe = ({
369
+ url: o,
370
+ fileName: n
371
+ }) => {
372
+ const r = de(null), [f, u] = p(!0), [w, h] = p(null);
373
+ return _(() => {
374
+ let e = !1;
375
+ const l = r.current;
376
+ return l && (l.innerHTML = ""), u(!0), h(null), g(void 0, null, function* () {
377
+ try {
378
+ const s = yield fetch(o);
379
+ if (!s.ok)
380
+ throw new Error(`HTTP error! status: ${s.status}`);
381
+ const k = yield s.blob();
382
+ if (e || !r.current)
383
+ return;
384
+ yield fe(k, r.current, void 0, {
385
+ inWrapper: !1,
386
+ ignoreWidth: !1,
387
+ ignoreHeight: !1,
388
+ breakPages: !0
389
+ }), e || u(!1);
390
+ } catch (s) {
391
+ e || (h((s == null ? void 0 : s.message) || "DOCX文件预览失败"), u(!1));
392
+ }
393
+ }), () => {
394
+ e = !0, l && (l.innerHTML = "");
395
+ };
396
+ }, [o]), /* @__PURE__ */ C("div", {
397
+ className: "document-viewer-office document-viewer-docx",
398
+ children: [f && /* @__PURE__ */ t("div", {
399
+ className: "document-viewer-loading",
400
+ children: /* @__PURE__ */ t(Z, {
401
+ size: "large",
402
+ tip: "加载DOCX中..."
403
+ })
404
+ }), w && /* @__PURE__ */ t(J, {
405
+ className: "document-viewer-alert-full",
406
+ message: "DOCX预览失败",
407
+ description: "文件无法在线预览,请下载后查看。",
408
+ type: "warning",
409
+ showIcon: !0,
410
+ action: /* @__PURE__ */ t(D, {
411
+ type: "link",
412
+ icon: /* @__PURE__ */ t(L, {}),
413
+ href: o,
414
+ download: n,
415
+ target: "_blank",
416
+ rel: "noopener noreferrer",
417
+ children: "下载文件"
418
+ })
419
+ }), /* @__PURE__ */ t("div", {
420
+ ref: r,
421
+ className: "document-viewer-docx-content",
422
+ style: {
423
+ display: f || w ? "none" : void 0
424
+ }
425
+ })]
354
426
  });
355
- }, je = ({
356
- url: i
427
+ }, Ue = ({
428
+ url: o
357
429
  }) => /* @__PURE__ */ t("div", {
358
430
  className: "document-viewer-unknown",
359
431
  children: /* @__PURE__ */ t("iframe", {
360
- src: i,
432
+ src: o,
361
433
  className: "document-viewer-iframe",
362
434
  title: "File Preview"
363
435
  })
364
- }), Ge = Se;
436
+ }), tt = je;
365
437
  export {
366
- Ge as default
438
+ tt as default
367
439
  };