@glodon-aiot/react-components 3.9.0-beta.9 → 3.11.0-snapshot.1765331441

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 (34) hide show
  1. package/dist/aiot-react-components.js +20191 -0
  2. package/dist/aiot-react-components.umd.cjs +183 -0
  3. package/dist/es/components/DocumentViewer/components/DownloadButton.mjs +18 -0
  4. package/dist/es/components/DocumentViewer/components/ErrorAlert.mjs +27 -0
  5. package/dist/es/components/DocumentViewer/components/FileRenderers.mjs +476 -0
  6. package/dist/es/components/DocumentViewer/components/MediaRenderers.mjs +41 -0
  7. package/dist/es/components/DocumentViewer/components/PdfRenderer.mjs +44 -0
  8. package/dist/es/components/DocumentViewer/components/ZipRenderer.mjs +147 -0
  9. package/dist/es/components/DocumentViewer/constants.mjs +21 -0
  10. package/dist/es/components/DocumentViewer/hooks/usePdfViewer.mjs +31 -0
  11. package/dist/es/components/DocumentViewer/hooks/useZipViewer.mjs +151 -0
  12. package/dist/es/components/DocumentViewer/index.mjs +270 -0
  13. package/dist/es/components/DocumentViewer/style.less.mjs +4 -0
  14. package/dist/es/components/DocumentViewer/utils.mjs +60 -0
  15. package/dist/es/index.mjs +36 -34
  16. package/dist/es/utils/file.mjs +17 -0
  17. package/dist/lib/index.js +10 -2
  18. package/dist/src/components/DocumentViewer/components/DownloadButton.d.ts +7 -0
  19. package/dist/src/components/DocumentViewer/components/ErrorAlert.d.ts +10 -0
  20. package/dist/src/components/DocumentViewer/components/FileRenderers.d.ts +23 -0
  21. package/dist/src/components/DocumentViewer/components/MediaRenderers.d.ts +9 -0
  22. package/dist/src/components/DocumentViewer/components/PdfRenderer.d.ts +10 -0
  23. package/dist/src/components/DocumentViewer/components/ZipRenderer.d.ts +22 -0
  24. package/dist/src/components/DocumentViewer/components/index.d.ts +9 -0
  25. package/dist/src/components/DocumentViewer/constants.d.ts +21 -0
  26. package/dist/src/components/DocumentViewer/hooks/index.d.ts +5 -0
  27. package/dist/src/components/DocumentViewer/hooks/usePdfViewer.d.ts +7 -0
  28. package/dist/src/components/DocumentViewer/hooks/useZipViewer.d.ts +21 -0
  29. package/dist/src/components/DocumentViewer/index.d.ts +9 -0
  30. package/dist/src/components/DocumentViewer/utils.d.ts +18 -0
  31. package/dist/src/index.d.ts +1 -0
  32. package/dist/src/utils/file.d.ts +16 -0
  33. package/dist/style.css +1 -0
  34. package/package.json +15 -11
@@ -0,0 +1,147 @@
1
+ import { jsx as e, jsxs as i } from "react/jsx-runtime";
2
+ import { Spin as f, Alert as d, Table as m } from "antd";
3
+ import h from "../index.mjs";
4
+ import { formatFileSize as p } from "../utils.mjs";
5
+ const v = ({
6
+ zipFiles: r,
7
+ zipLoading: a,
8
+ zipError: t,
9
+ selectedZipFile: o,
10
+ zipFileContent: n,
11
+ onFileClick: s,
12
+ url: c
13
+ }) => a ? /* @__PURE__ */ e("div", {
14
+ className: "document-viewer-loading",
15
+ children: /* @__PURE__ */ e(f, {
16
+ size: "large",
17
+ tip: "加载 ZIP 文件..."
18
+ })
19
+ }) : t && r.length === 0 ? /* @__PURE__ */ e(d, {
20
+ message: "ZIP 加载失败",
21
+ description: t,
22
+ type: "error",
23
+ showIcon: !0,
24
+ action: /* @__PURE__ */ e("a", {
25
+ href: c,
26
+ target: "_blank",
27
+ rel: "noopener noreferrer",
28
+ children: "下载文件"
29
+ })
30
+ }) : /* @__PURE__ */ i("div", {
31
+ className: "document-viewer-zip",
32
+ children: [t && r.length > 0 && /* @__PURE__ */ e(d, {
33
+ message: "提示",
34
+ description: t,
35
+ type: "warning",
36
+ showIcon: !0,
37
+ style: {
38
+ marginBottom: 16
39
+ }
40
+ }), /* @__PURE__ */ i("div", {
41
+ style: {
42
+ display: "flex",
43
+ height: "100%",
44
+ gap: "16px"
45
+ },
46
+ children: [/* @__PURE__ */ i("div", {
47
+ style: {
48
+ width: "300px",
49
+ borderRight: "1px solid #e8e8e8",
50
+ overflow: "auto",
51
+ display: "flex",
52
+ flexDirection: "column"
53
+ },
54
+ children: [/* @__PURE__ */ i("div", {
55
+ style: {
56
+ padding: "12px",
57
+ fontWeight: "bold",
58
+ borderBottom: "1px solid #e8e8e8",
59
+ flexShrink: 0
60
+ },
61
+ children: ["文件列表 (", r.length, ")"]
62
+ }), /* @__PURE__ */ e("div", {
63
+ style: {
64
+ flex: 1,
65
+ overflow: "auto",
66
+ minHeight: 0
67
+ },
68
+ children: /* @__PURE__ */ e(m, {
69
+ dataSource: r,
70
+ size: "small",
71
+ pagination: !1,
72
+ scroll: {
73
+ y: "100%"
74
+ },
75
+ onRow: (l) => ({
76
+ onClick: () => s(l.name),
77
+ style: {
78
+ cursor: "pointer",
79
+ backgroundColor: o === l.name ? "#e6f7ff" : "transparent"
80
+ }
81
+ }),
82
+ columns: [{
83
+ title: "文件名",
84
+ dataIndex: "name",
85
+ key: "name",
86
+ ellipsis: !0,
87
+ render: (l) => /* @__PURE__ */ e("span", {
88
+ title: l,
89
+ children: l.split("/").pop()
90
+ })
91
+ }, {
92
+ title: "大小",
93
+ dataIndex: "size",
94
+ key: "size",
95
+ width: 80,
96
+ render: (l) => p(l)
97
+ }]
98
+ })
99
+ })]
100
+ }), /* @__PURE__ */ e("div", {
101
+ style: {
102
+ flex: 1,
103
+ overflow: "auto",
104
+ display: "flex",
105
+ flexDirection: "column"
106
+ },
107
+ children: o && n ? /* @__PURE__ */ i("div", {
108
+ style: {
109
+ display: "flex",
110
+ flexDirection: "column",
111
+ height: "100%"
112
+ },
113
+ children: [/* @__PURE__ */ e("div", {
114
+ style: {
115
+ padding: "12px",
116
+ borderBottom: "1px solid #e8e8e8",
117
+ fontWeight: "bold",
118
+ flexShrink: 0
119
+ },
120
+ children: n.name
121
+ }), /* @__PURE__ */ e("div", {
122
+ style: {
123
+ flex: 1,
124
+ overflow: "auto",
125
+ padding: "16px"
126
+ },
127
+ children: /* @__PURE__ */ e(h, {
128
+ url: n.blobUrl,
129
+ fileName: n.name
130
+ })
131
+ })]
132
+ }) : /* @__PURE__ */ e("div", {
133
+ style: {
134
+ display: "flex",
135
+ alignItems: "center",
136
+ justifyContent: "center",
137
+ height: "100%",
138
+ color: "#999"
139
+ },
140
+ children: "请从左侧列表中选择文件进行预览"
141
+ })
142
+ })]
143
+ })]
144
+ });
145
+ export {
146
+ v as ZipRenderer
147
+ };
@@ -0,0 +1,21 @@
1
+ const _ = 5242880, I = 2097152, S = 2097152, o = 5242880, t = 5242880, E = 2097152, s = 2097152, n = 2097152, A = 2097152, c = 104857600, M = 104857600, X = 1e4, Z = 1e4, L = 5e3, e = 1e3, N = 5242880, P = 3e4, F = ["text", "json", "csv", "tsv", "markdown", "html", "xml", "jsonl", "image", "pdf", "code"];
2
+ export {
3
+ Z as MAX_CSV_ROWS,
4
+ o as MAX_CSV_SIZE,
5
+ X as MAX_DISPLAY_LINES,
6
+ I as MAX_DISPLAY_SIZE,
7
+ c as MAX_FALLBACK_SIZE,
8
+ _ as MAX_FILE_SIZE,
9
+ A as MAX_HIGHLIGHT_SIZE,
10
+ L as MAX_JSONL_LINES,
11
+ E as MAX_JSONL_SIZE,
12
+ S as MAX_JSON_SIZE,
13
+ s as MAX_MARKDOWN_SIZE,
14
+ t as MAX_TSV_SIZE,
15
+ n as MAX_XML_SIZE,
16
+ e as MAX_ZIP_FILES,
17
+ M as MAX_ZIP_FILE_SIZE,
18
+ F as SAFE_FILE_TYPES,
19
+ N as ZIP_CHUNK_SIZE,
20
+ P as ZIP_ENTRIES_TIMEOUT
21
+ };
@@ -0,0 +1,31 @@
1
+ import { useState as f, useRef as d, useEffect as i } from "react";
2
+ const L = (t) => {
3
+ const [l, u] = f(null), [s, n] = f(!0), [a, o] = f(null), r = d(null);
4
+ return i(() => {
5
+ if (!t) {
6
+ o("文件URL不能为空"), n(!1);
7
+ return;
8
+ }
9
+ return r.current && (URL.revokeObjectURL(r.current), r.current = null, u(null)), n(!0), o(null), fetch(t).then((e) => {
10
+ if (!e.ok)
11
+ throw new Error(`HTTP error! status: ${e.status}`);
12
+ return e.blob();
13
+ }).then((e) => {
14
+ if (e.type && e.type !== "application/pdf" && !t.toLowerCase().endsWith(".pdf"))
15
+ throw new Error("文件不是有效的 PDF 格式");
16
+ const c = URL.createObjectURL(e);
17
+ r.current = c, u(c), n(!1);
18
+ }).catch((e) => {
19
+ o(e.message || "加载 PDF 失败"), n(!1);
20
+ }), () => {
21
+ r.current && (URL.revokeObjectURL(r.current), r.current = null);
22
+ };
23
+ }, [t]), {
24
+ pdfBlobUrl: l,
25
+ pdfLoading: s,
26
+ pdfError: a
27
+ };
28
+ };
29
+ export {
30
+ L as usePdfViewer
31
+ };
@@ -0,0 +1,151 @@
1
+ var U = (c, R, f) => new Promise((Z, u) => {
2
+ var I = (w) => {
3
+ try {
4
+ d(f.next(w));
5
+ } catch (r) {
6
+ u(r);
7
+ }
8
+ }, p = (w) => {
9
+ try {
10
+ d(f.throw(w));
11
+ } catch (r) {
12
+ u(r);
13
+ }
14
+ }, d = (w) => w.done ? Z(w.value) : Promise.resolve(w.value).then(I, p);
15
+ d((f = f.apply(c, R)).next());
16
+ });
17
+ import { useState as h, useEffect as L, useCallback as F } from "react";
18
+ import { configure as M, BlobReader as T, ZipReader as S, HttpRangeReader as k, BlobWriter as H } from "@zip.js/zip.js";
19
+ import { ZIP_CHUNK_SIZE as A, MAX_FALLBACK_SIZE as y, MAX_ZIP_FILES as m, ZIP_ENTRIES_TIMEOUT as B, MAX_ZIP_FILE_SIZE as C, SAFE_FILE_TYPES as O } from "../constants.mjs";
20
+ import { checkRangeSupport as j, getFileSize as D } from "../utils.mjs";
21
+ import { getFileExtension as v, getFileType as x } from "../../../utils/file.mjs";
22
+ const J = (c) => {
23
+ const [R, f] = h([]), [Z, u] = h(!0), [I, p] = h(null), [d, w] = h(null), [r, P] = h(null);
24
+ L(() => {
25
+ if (!c) {
26
+ p("文件URL不能为空"), u(!1);
27
+ return;
28
+ }
29
+ u(!0), p(null), f([]), w(null), r != null && r.blobUrl && (URL.revokeObjectURL(r.blobUrl), P(null));
30
+ let e = null;
31
+ U(void 0, null, function* () {
32
+ try {
33
+ M({
34
+ chunkSize: A,
35
+ useWebWorkers: !1
36
+ });
37
+ const {
38
+ supportsRange: n,
39
+ fileSize: t
40
+ } = yield j(c);
41
+ if (n) {
42
+ const o = new k(c);
43
+ e = new S(o);
44
+ const b = (yield Promise.race([e.getEntries(), new Promise((i, a) => setTimeout(() => a(new Error("读取 ZIP 目录结构超时")), B))])).filter((i) => !i.directory).map((i) => ({
45
+ name: i.filename,
46
+ size: i.uncompressedSize || 0,
47
+ isDirectory: !1
48
+ }));
49
+ b.sort((i, a) => i.name.localeCompare(a.name)), b.length > m ? (p(`ZIP 文件包含 ${b.length} 个文件,仅显示前 ${m} 个`), f(b.slice(0, m))) : f(b);
50
+ } else {
51
+ if (t > y)
52
+ throw new Error(`服务器不支持 HTTP Range 请求,且文件过大(${Math.round(t / 1024 / 1024)}MB),无法预览。请下载后查看。`);
53
+ const o = yield fetch(c);
54
+ if (!o.ok)
55
+ throw new Error(`HTTP error! status: ${o.status}`);
56
+ const g = yield o.blob(), b = new T(g);
57
+ e = new S(b);
58
+ const a = (yield e.getEntries()).filter((s) => !s.directory).map((s) => ({
59
+ name: s.filename,
60
+ size: s.uncompressedSize || 0,
61
+ isDirectory: !1
62
+ }));
63
+ a.sort((s, l) => s.name.localeCompare(l.name)), a.length > m ? (p(`ZIP 文件包含 ${a.length} 个文件,仅显示前 ${m} 个`), f(a.slice(0, m))) : f(a);
64
+ }
65
+ e && (yield e.close()), u(!1);
66
+ } catch (n) {
67
+ if (e)
68
+ try {
69
+ yield e.close();
70
+ } catch (o) {
71
+ }
72
+ const t = n.message || n.toString() || "加载 ZIP 文件失败";
73
+ if (t.includes("Range") || t.includes("range") || t.includes("HTTP Range not supported") || t.includes("超时"))
74
+ try {
75
+ const o = yield D(c);
76
+ if (o > y)
77
+ throw new Error(`文件过大(${Math.round(o / 1024 / 1024)}MB),无法通过 Range 请求加载,且文件过大无法下载整个文件预览。请下载后查看。`);
78
+ const g = yield fetch(c);
79
+ if (!g.ok)
80
+ throw new Error(`HTTP error! status: ${g.status}`);
81
+ const b = yield g.blob(), i = new T(b);
82
+ e = new S(i);
83
+ const s = (yield e.getEntries()).filter((l) => !l.directory).map((l) => ({
84
+ name: l.filename,
85
+ size: l.uncompressedSize || 0,
86
+ isDirectory: !1
87
+ }));
88
+ s.sort((l, E) => l.name.localeCompare(E.name)), s.length > m ? (p(`ZIP 文件包含 ${s.length} 个文件,仅显示前 ${m} 个`), f(s.slice(0, m))) : f(s), e && (yield e.close()), u(!1);
89
+ return;
90
+ } catch (o) {
91
+ const g = o.message || o.toString();
92
+ p(`ZIP 文件加载失败: ${t}。Fallback 方案也失败: ${g}`);
93
+ }
94
+ else
95
+ p(t);
96
+ u(!1);
97
+ }
98
+ });
99
+ }, [c]);
100
+ const z = F((e) => U(void 0, null, function* () {
101
+ if (d === e && r) {
102
+ w(null), r.blobUrl && URL.revokeObjectURL(r.blobUrl), P(null);
103
+ return;
104
+ }
105
+ w(e);
106
+ try {
107
+ let n = null, t;
108
+ try {
109
+ const s = new k(c);
110
+ n = new S(s), t = (yield n.getEntries()).find((E) => E.filename === e);
111
+ } catch (s) {
112
+ const l = yield fetch(c);
113
+ if (!l.ok)
114
+ throw new Error(`HTTP error! status: ${l.status}`);
115
+ const E = yield l.blob(), _ = new T(E);
116
+ n = new S(_), t = (yield n.getEntries()).find(($) => $.filename === e);
117
+ }
118
+ if (!t)
119
+ throw new Error("文件不存在");
120
+ if (t.directory)
121
+ throw new Error("无法预览目录");
122
+ if ((t.uncompressedSize || 0) > C)
123
+ throw new Error("文件过大(超过 100MB),无法预览");
124
+ const g = yield t.getData(new H()), b = URL.createObjectURL(g), i = v(e), a = x(i);
125
+ if (!O.includes(a))
126
+ throw new Error(`不支持预览 ${i || "未知"} 格式的文件`);
127
+ P({
128
+ name: e,
129
+ blobUrl: b,
130
+ type: a
131
+ }), n && (yield n.close());
132
+ } catch (n) {
133
+ const t = n.message || n.toString() || "预览文件失败";
134
+ p(t);
135
+ }
136
+ }), [c, d, r]);
137
+ return L(() => () => {
138
+ r != null && r.blobUrl && URL.revokeObjectURL(r.blobUrl);
139
+ }, [r]), {
140
+ zipFiles: R,
141
+ zipLoading: Z,
142
+ zipError: I,
143
+ selectedZipFile: d,
144
+ zipFileContent: r,
145
+ handleFileClick: z,
146
+ setSelectedZipFile: w
147
+ };
148
+ };
149
+ export {
150
+ J as useZipViewer
151
+ };
@@ -0,0 +1,270 @@
1
+ var N = (c, e, t) => new Promise((w, u) => {
2
+ var o = (i) => {
3
+ try {
4
+ l(t.next(i));
5
+ } catch (f) {
6
+ u(f);
7
+ }
8
+ }, h = (i) => {
9
+ try {
10
+ l(t.throw(i));
11
+ } catch (f) {
12
+ u(f);
13
+ }
14
+ }, l = (i) => i.done ? w(i.value) : Promise.resolve(i.value).then(o, h);
15
+ l((t = t.apply(c, e)).next());
16
+ });
17
+ import { jsx as r, jsxs as A } from "react/jsx-runtime";
18
+ import { useMemo as j, useState as p, useEffect as H } from "react";
19
+ import { Spin as O, Alert as Z } from "antd";
20
+ import { getFileExtension as T, getFileType as _ } from "../../utils/file.mjs";
21
+ import { MAX_FILE_SIZE as x } from "./constants.mjs";
22
+ import { usePdfViewer as J } from "./hooks/usePdfViewer.mjs";
23
+ import { useZipViewer as W } from "./hooks/useZipViewer.mjs";
24
+ import { CodeRenderer as X, XmlRenderer as q, HtmlRenderer as G, MarkdownRenderer as K, JsonlRenderer as Q, TsvRenderer as Y, CsvRenderer as ee, JsonRenderer as re, TextRenderer as te } from "./components/FileRenderers.mjs";
25
+ import { AudioRenderer as ne, VideoRenderer as oe, ImageRenderer as ie } from "./components/MediaRenderers.mjs";
26
+ import { PdfRenderer as se } from "./components/PdfRenderer.mjs";
27
+ import { ZipRenderer as ae } from "./components/ZipRenderer.mjs";
28
+ import { ErrorAlert as ce } from "./components/ErrorAlert.mjs";
29
+ import "./style.less.mjs";
30
+ const de = (c) => {
31
+ const {
32
+ url: e,
33
+ fileName: t,
34
+ className: w,
35
+ style: u
36
+ } = c, o = j(() => {
37
+ const m = T(e), L = t ? T(t) : void 0;
38
+ return _(m || L);
39
+ }, [e, t]), {
40
+ pdfBlobUrl: h,
41
+ pdfLoading: l,
42
+ pdfError: i
43
+ } = J(o === "pdf" ? e : ""), {
44
+ zipFiles: f,
45
+ zipLoading: $,
46
+ zipError: B,
47
+ selectedZipFile: U,
48
+ zipFileContent: y,
49
+ handleFileClick: D
50
+ } = W(o === "zip" ? e : ""), [I, n] = p(!0), [b, d] = p(null), [s, k] = p(null), [a, F] = p(0);
51
+ H(() => {
52
+ if (o === "pdf" || o === "zip") {
53
+ n(!1);
54
+ return;
55
+ }
56
+ if (!e) {
57
+ d("文件URL不能为空"), n(!1);
58
+ return;
59
+ }
60
+ if (["image", "video", "audio", "office", "unknown"].includes(o)) {
61
+ n(!1);
62
+ return;
63
+ }
64
+ n(!0), d(null), N(void 0, null, function* () {
65
+ try {
66
+ if (e.startsWith("blob:") || e.startsWith("data:")) {
67
+ const z = yield fetch(e);
68
+ if (!z.ok)
69
+ throw new Error(`HTTP error! status: ${z.status}`);
70
+ const M = yield z.blob(), E = M.size;
71
+ if (F(E), E > x) {
72
+ d(`文件过大(${Math.round(E / 1024 / 1024)}MB),无法预览。请下载后查看。`), n(!1);
73
+ return;
74
+ }
75
+ const V = yield M.text();
76
+ k({
77
+ content: V
78
+ }), n(!1);
79
+ return;
80
+ }
81
+ const v = (yield fetch(e, {
82
+ method: "HEAD"
83
+ })).headers.get("Content-Length"), g = v ? parseInt(v, 10) : 0;
84
+ if (F(g), g > x) {
85
+ d(`文件过大(${Math.round(g / 1024 / 1024)}MB),无法预览。请下载后查看。`), n(!1);
86
+ return;
87
+ }
88
+ const R = yield fetch(e);
89
+ if (!R.ok)
90
+ throw new Error(`HTTP error! status: ${R.status}`);
91
+ const S = yield R.text(), C = new Blob([S]).size;
92
+ if (C > x) {
93
+ d(`文件过大(${Math.round(C / 1024 / 1024)}MB),无法预览。请下载后查看。`), n(!1);
94
+ return;
95
+ }
96
+ k({
97
+ content: S
98
+ }), n(!1);
99
+ } catch (m) {
100
+ d(m.message || "加载文件失败"), n(!1);
101
+ }
102
+ });
103
+ }, [e, o]);
104
+ const P = () => {
105
+ if (I)
106
+ return /* @__PURE__ */ r("div", {
107
+ className: "document-viewer-loading",
108
+ children: /* @__PURE__ */ r(O, {
109
+ size: "large",
110
+ tip: "加载中..."
111
+ })
112
+ });
113
+ if (b)
114
+ return /* @__PURE__ */ r(ce, {
115
+ message: "加载失败",
116
+ description: b,
117
+ url: e,
118
+ fileName: t
119
+ });
120
+ switch (o) {
121
+ case "text":
122
+ return /* @__PURE__ */ r(te, {
123
+ fileContent: s,
124
+ fileSize: a,
125
+ url: e,
126
+ fileName: t
127
+ });
128
+ case "json":
129
+ return /* @__PURE__ */ r(re, {
130
+ fileContent: s,
131
+ fileSize: a,
132
+ url: e,
133
+ fileName: t
134
+ });
135
+ case "csv":
136
+ return /* @__PURE__ */ r(ee, {
137
+ fileContent: s,
138
+ fileSize: a,
139
+ url: e,
140
+ fileName: t
141
+ });
142
+ case "tsv":
143
+ return /* @__PURE__ */ r(Y, {
144
+ fileContent: s,
145
+ fileSize: a,
146
+ url: e,
147
+ fileName: t
148
+ });
149
+ case "jsonl":
150
+ return /* @__PURE__ */ r(Q, {
151
+ fileContent: s,
152
+ fileSize: a,
153
+ url: e,
154
+ fileName: t
155
+ });
156
+ case "markdown":
157
+ return /* @__PURE__ */ r(K, {
158
+ fileContent: s,
159
+ fileSize: a,
160
+ url: e,
161
+ fileName: t
162
+ });
163
+ case "html":
164
+ return /* @__PURE__ */ r(G, {
165
+ fileContent: s,
166
+ fileSize: a,
167
+ url: e,
168
+ fileName: t
169
+ });
170
+ case "xml":
171
+ return /* @__PURE__ */ r(q, {
172
+ fileContent: s,
173
+ fileSize: a,
174
+ url: e,
175
+ fileName: t
176
+ });
177
+ case "code":
178
+ return /* @__PURE__ */ r(X, {
179
+ fileContent: s,
180
+ fileSize: a,
181
+ url: e,
182
+ fileName: t
183
+ });
184
+ case "image":
185
+ return /* @__PURE__ */ r(ie, {
186
+ url: e,
187
+ fileName: t
188
+ });
189
+ case "video":
190
+ return /* @__PURE__ */ r(oe, {
191
+ url: e,
192
+ fileName: t
193
+ });
194
+ case "audio":
195
+ return /* @__PURE__ */ r(ne, {
196
+ url: e,
197
+ fileName: t
198
+ });
199
+ case "pdf":
200
+ return /* @__PURE__ */ r(se, {
201
+ pdfBlobUrl: h,
202
+ pdfLoading: l,
203
+ pdfError: i,
204
+ url: e,
205
+ fileName: t
206
+ });
207
+ case "office":
208
+ return /* @__PURE__ */ r(le, {
209
+ url: e
210
+ });
211
+ case "zip":
212
+ return /* @__PURE__ */ r(ae, {
213
+ zipFiles: f,
214
+ zipLoading: $,
215
+ zipError: B,
216
+ selectedZipFile: U,
217
+ zipFileContent: y,
218
+ onFileClick: D,
219
+ url: e
220
+ });
221
+ case "unknown":
222
+ default:
223
+ return /* @__PURE__ */ r(fe, {
224
+ url: e
225
+ });
226
+ }
227
+ };
228
+ return /* @__PURE__ */ r("div", {
229
+ className: `document-viewer ${w || ""}`,
230
+ style: u,
231
+ children: P()
232
+ });
233
+ }, le = ({
234
+ url: c
235
+ }) => {
236
+ const e = `https://view.officeapps.live.com/op/embed.aspx?src=${encodeURIComponent(c)}`;
237
+ return /* @__PURE__ */ A("div", {
238
+ className: "document-viewer-office",
239
+ children: [/* @__PURE__ */ r("iframe", {
240
+ src: e,
241
+ className: "document-viewer-iframe",
242
+ title: "Office Document Preview"
243
+ }), /* @__PURE__ */ r("div", {
244
+ className: "document-viewer-fallback",
245
+ children: /* @__PURE__ */ r(Z, {
246
+ message: "预览可能不可用",
247
+ description: /* @__PURE__ */ r("a", {
248
+ href: c,
249
+ target: "_blank",
250
+ rel: "noopener noreferrer",
251
+ children: "点击下载文件"
252
+ }),
253
+ type: "info",
254
+ showIcon: !0
255
+ })
256
+ })]
257
+ });
258
+ }, fe = ({
259
+ url: c
260
+ }) => /* @__PURE__ */ r("div", {
261
+ className: "document-viewer-unknown",
262
+ children: /* @__PURE__ */ r("iframe", {
263
+ src: c,
264
+ className: "document-viewer-iframe",
265
+ title: "File Preview"
266
+ })
267
+ }), Le = de;
268
+ export {
269
+ Le as default
270
+ };
@@ -0,0 +1,4 @@
1
+ const t = "";
2
+ export {
3
+ t as default
4
+ };
@@ -0,0 +1,60 @@
1
+ var i = (s, n, e) => new Promise((t, c) => {
2
+ var o = (a) => {
3
+ try {
4
+ r(e.next(a));
5
+ } catch (g) {
6
+ c(g);
7
+ }
8
+ }, h = (a) => {
9
+ try {
10
+ r(e.throw(a));
11
+ } catch (g) {
12
+ c(g);
13
+ }
14
+ }, r = (a) => a.done ? t(a.value) : Promise.resolve(a.value).then(o, h);
15
+ r((e = e.apply(s, n)).next());
16
+ });
17
+ const p = (s) => {
18
+ if (s === 0)
19
+ return "0 B";
20
+ const n = 1024, e = ["B", "KB", "MB", "GB"], t = Math.floor(Math.log(s) / Math.log(n));
21
+ return Math.round(s / Math.pow(n, t) * 100) / 100 + " " + e[t];
22
+ }, d = (s) => i(void 0, null, function* () {
23
+ let n = !1, e = 0;
24
+ try {
25
+ const t = yield fetch(s, {
26
+ method: "HEAD",
27
+ headers: {
28
+ Range: "bytes=0-0"
29
+ }
30
+ }), c = t.headers.get("Accept-Ranges"), o = t.headers.get("Content-Range"), h = t.headers.get("Content-Length");
31
+ if (o) {
32
+ const r = o.match(/bytes \d+-\d+\/(\d+)/);
33
+ r && (e = parseInt(r[1], 10));
34
+ } else
35
+ h && (e = parseInt(h, 10));
36
+ return n = t.status === 206 || c === "bytes" || o !== null && o.startsWith("bytes"), {
37
+ supportsRange: n,
38
+ fileSize: e
39
+ };
40
+ } catch (t) {
41
+ return console.warn("Range 支持检测失败:", t), {
42
+ supportsRange: !1,
43
+ fileSize: 0
44
+ };
45
+ }
46
+ }), f = (s) => i(void 0, null, function* () {
47
+ try {
48
+ const e = (yield fetch(s, {
49
+ method: "HEAD"
50
+ })).headers.get("Content-Length");
51
+ return e ? parseInt(e, 10) : 0;
52
+ } catch (n) {
53
+ return console.warn("无法获取文件大小:", n), 0;
54
+ }
55
+ });
56
+ export {
57
+ d as checkRangeSupport,
58
+ p as formatFileSize,
59
+ f as getFileSize
60
+ };