@macrowing/filepilot 0.1.0 → 1.0.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/dist/builtin.js +70 -3
- package/dist/chunk-CKS4FUE2.js +169 -0
- package/dist/chunk-KCRUK7FG.js +41 -0
- package/dist/index.cjs +115 -76
- package/dist/index.d.cts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +7 -9
- package/dist/react.cjs +115 -72
- package/dist/react.d.cts +7 -1
- package/dist/react.d.ts +7 -1
- package/dist/react.js +6 -4
- package/package.json +28 -8
- package/dist/chunk-EQYOJW24.js +0 -111
- package/dist/chunk-MHWH3ZGP.js +0 -59
package/dist/builtin.js
CHANGED
|
@@ -1,7 +1,74 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
createFilePilotRegistry
|
|
3
|
+
} from "./chunk-KCRUK7FG.js";
|
|
4
|
+
|
|
5
|
+
// src/builtin.ts
|
|
6
|
+
var builtinParsers = [
|
|
7
|
+
{
|
|
8
|
+
id: "filepilot-parser-drawio",
|
|
9
|
+
kind: "drawing",
|
|
10
|
+
extensions: ["drawio", "dio"],
|
|
11
|
+
mimeTypes: ["application/vnd.jgraph.mxfile", "application/x-drawio", "application/drawio"],
|
|
12
|
+
load: () => import("@macrowing/filepilot-parser-drawio")
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
id: "filepilot-parser-viewer",
|
|
16
|
+
kind: "viewer",
|
|
17
|
+
extensions: ["md", "markdown", "mdx", "txt", "text", "log", "csv", "json", "xml", "yaml", "yml", "png", "jpg", "jpeg", "gif", "webp", "bmp", "svg"],
|
|
18
|
+
mimeTypes: [
|
|
19
|
+
"text/markdown",
|
|
20
|
+
"text/x-markdown",
|
|
21
|
+
"text/plain",
|
|
22
|
+
"text/csv",
|
|
23
|
+
"application/json",
|
|
24
|
+
"application/xml",
|
|
25
|
+
"text/xml",
|
|
26
|
+
"image/png",
|
|
27
|
+
"image/jpeg",
|
|
28
|
+
"image/gif",
|
|
29
|
+
"image/webp",
|
|
30
|
+
"image/bmp",
|
|
31
|
+
"image/svg+xml"
|
|
32
|
+
],
|
|
33
|
+
load: () => import("@macrowing/filepilot-parser-viewer")
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
id: "filepilot-parser-pdf",
|
|
37
|
+
kind: "pdf",
|
|
38
|
+
extensions: ["pdf"],
|
|
39
|
+
mimeTypes: ["application/pdf"],
|
|
40
|
+
load: () => import("@macrowing/filepilot-parser-pdf")
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
id: "filepilot-parser-office",
|
|
44
|
+
kind: "office",
|
|
45
|
+
extensions: ["doc", "docx", "ppt", "pptx", "xls", "xlsx"],
|
|
46
|
+
mimeTypes: [
|
|
47
|
+
"application/msword",
|
|
48
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
49
|
+
"application/vnd.ms-powerpoint",
|
|
50
|
+
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
51
|
+
"application/vnd.ms-excel",
|
|
52
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
53
|
+
],
|
|
54
|
+
load: () => import("@macrowing/filepilot-parser-office")
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
id: "filepilot-parser-mmind",
|
|
58
|
+
kind: "mindmap",
|
|
59
|
+
extensions: ["mmind"],
|
|
60
|
+
mimeTypes: ["application/json", "application/x-mmind"],
|
|
61
|
+
load: () => import("@macrowing/filepilot-parser-mmind")
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
id: "filepilot-parser-mdoc",
|
|
65
|
+
kind: "docflow",
|
|
66
|
+
extensions: ["mdoc"],
|
|
67
|
+
mimeTypes: ["application/x-mdoc", "application/vnd.docflow.mdoc", "application/octet-stream"],
|
|
68
|
+
load: () => import("@macrowing/filepilot-parser-mdoc")
|
|
69
|
+
}
|
|
70
|
+
];
|
|
71
|
+
var defaultRegistry = createFilePilotRegistry(builtinParsers);
|
|
5
72
|
export {
|
|
6
73
|
builtinParsers,
|
|
7
74
|
defaultRegistry
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createFilePilotRegistry
|
|
3
|
+
} from "./chunk-KCRUK7FG.js";
|
|
4
|
+
|
|
5
|
+
// src/react.tsx
|
|
6
|
+
import React, { Suspense, useEffect, useMemo, useRef } from "react";
|
|
7
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
var loadingKeyframes = `
|
|
9
|
+
@keyframes fp-loading-spin {
|
|
10
|
+
to {
|
|
11
|
+
transform: rotate(360deg);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@keyframes fp-loading-line-pulse {
|
|
16
|
+
0%,
|
|
17
|
+
100% {
|
|
18
|
+
opacity: 0.45;
|
|
19
|
+
transform: scaleX(0.86);
|
|
20
|
+
transform-origin: left center;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
50% {
|
|
24
|
+
opacity: 1;
|
|
25
|
+
transform: scaleX(1);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
`;
|
|
29
|
+
var FilePilotLoading = ({ stage = "\u89E3\u6790\u5668\u52A0\u8F7D\u4E2D", message = "\u6B63\u5728\u51C6\u5907\u6587\u4EF6\u9884\u89C8\u80FD\u529B", progress }) => {
|
|
30
|
+
const resolvedProgress = typeof progress === "number" && Number.isFinite(progress) ? Math.max(0, Math.min(1, progress)) : void 0;
|
|
31
|
+
const progressWidth = `${Math.round((resolvedProgress ?? 0.42) * 100)}%`;
|
|
32
|
+
return /* @__PURE__ */ jsxs("div", { style: {
|
|
33
|
+
display: "grid",
|
|
34
|
+
placeItems: "center",
|
|
35
|
+
alignContent: "center",
|
|
36
|
+
gap: 18,
|
|
37
|
+
width: "100%",
|
|
38
|
+
height: "100%",
|
|
39
|
+
minHeight: 480,
|
|
40
|
+
padding: 24,
|
|
41
|
+
color: "#1f2937",
|
|
42
|
+
textAlign: "center",
|
|
43
|
+
background: "radial-gradient(circle at center, rgba(56, 103, 214, 0.12), transparent 42%), #f8fafc"
|
|
44
|
+
}, children: [
|
|
45
|
+
/* @__PURE__ */ jsx("style", { children: loadingKeyframes }),
|
|
46
|
+
/* @__PURE__ */ jsxs("div", { style: { position: "relative", display: "grid", placeItems: "center", width: 112, height: 112 }, children: [
|
|
47
|
+
/* @__PURE__ */ jsx("div", { style: {
|
|
48
|
+
position: "absolute",
|
|
49
|
+
inset: 0,
|
|
50
|
+
border: "3px solid rgba(56, 103, 214, 0.14)",
|
|
51
|
+
borderTopColor: "#3867d6",
|
|
52
|
+
borderRightColor: "#7298f0",
|
|
53
|
+
borderRadius: 999,
|
|
54
|
+
boxShadow: "0 0 0 8px rgba(255, 255, 255, 0.58), 0 18px 42px rgba(56, 103, 214, 0.16)",
|
|
55
|
+
animation: "fp-loading-spin 0.92s linear infinite"
|
|
56
|
+
} }),
|
|
57
|
+
/* @__PURE__ */ jsxs("div", { style: {
|
|
58
|
+
position: "relative",
|
|
59
|
+
display: "block",
|
|
60
|
+
width: 56,
|
|
61
|
+
height: 66,
|
|
62
|
+
background: "#ffffff",
|
|
63
|
+
border: "1px solid rgba(56, 103, 214, 0.18)",
|
|
64
|
+
borderRadius: 8,
|
|
65
|
+
boxShadow: "0 14px 28px rgba(31, 41, 55, 0.12), inset 0 0 0 1px rgba(255, 255, 255, 0.68)"
|
|
66
|
+
}, children: [
|
|
67
|
+
/* @__PURE__ */ jsx("div", { style: {
|
|
68
|
+
position: "absolute",
|
|
69
|
+
left: -8,
|
|
70
|
+
bottom: 8,
|
|
71
|
+
width: 45,
|
|
72
|
+
height: 54,
|
|
73
|
+
background: "rgba(56, 103, 214, 0.08)",
|
|
74
|
+
border: "1px solid rgba(56, 103, 214, 0.12)",
|
|
75
|
+
borderRadius: 8,
|
|
76
|
+
transform: "rotate(-5deg)",
|
|
77
|
+
zIndex: -1
|
|
78
|
+
} }),
|
|
79
|
+
/* @__PURE__ */ jsx("div", { style: {
|
|
80
|
+
position: "absolute",
|
|
81
|
+
top: -1,
|
|
82
|
+
right: -1,
|
|
83
|
+
width: 18,
|
|
84
|
+
height: 18,
|
|
85
|
+
background: "linear-gradient(135deg, rgba(56, 103, 214, 0.18) 0 50%, transparent 50% 100%)",
|
|
86
|
+
borderTopRightRadius: 8
|
|
87
|
+
} }),
|
|
88
|
+
/* @__PURE__ */ jsxs("div", { style: { position: "absolute", top: 18, left: 12, right: 10, display: "grid", gap: 6 }, children: [
|
|
89
|
+
/* @__PURE__ */ jsx("span", { style: { display: "block", height: 5, background: "rgba(56, 103, 214, 0.16)", borderRadius: 999, animation: "fp-loading-line-pulse 1.25s ease-in-out infinite" } }),
|
|
90
|
+
/* @__PURE__ */ jsx("span", { style: { display: "block", height: 5, width: "78%", background: "rgba(56, 103, 214, 0.16)", borderRadius: 999, animation: "fp-loading-line-pulse 1.25s ease-in-out infinite", animationDelay: "0.12s" } }),
|
|
91
|
+
/* @__PURE__ */ jsx("span", { style: { display: "block", height: 5, width: "56%", background: "rgba(56, 103, 214, 0.16)", borderRadius: 999, animation: "fp-loading-line-pulse 1.25s ease-in-out infinite", animationDelay: "0.24s" } })
|
|
92
|
+
] })
|
|
93
|
+
] })
|
|
94
|
+
] }),
|
|
95
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "grid", gap: 6, maxWidth: "min(360px, 100%)" }, children: [
|
|
96
|
+
/* @__PURE__ */ jsx("strong", { style: { color: "#1f2937", fontSize: 16 }, children: "\u6B63\u5728\u52A0\u8F7D\u6587\u6863..." }),
|
|
97
|
+
/* @__PURE__ */ jsx("span", { style: { color: "#526173", fontSize: 13, lineHeight: 1.6 }, children: stage }),
|
|
98
|
+
message ? /* @__PURE__ */ jsx("span", { style: { color: "#526173", fontSize: 13, lineHeight: 1.6 }, children: message }) : null
|
|
99
|
+
] }),
|
|
100
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "grid", gap: 7, width: "min(320px, 76vw)", marginTop: 8 }, children: [
|
|
101
|
+
/* @__PURE__ */ jsx("div", { style: { position: "relative", height: 7, overflow: "hidden", background: "rgba(56, 103, 214, 0.1)", borderRadius: 999 }, children: /* @__PURE__ */ jsx("span", { style: {
|
|
102
|
+
position: "absolute",
|
|
103
|
+
inset: "0 auto 0 0",
|
|
104
|
+
width: progressWidth,
|
|
105
|
+
minWidth: 8,
|
|
106
|
+
background: "linear-gradient(90deg, #3867d6, #7298f0)",
|
|
107
|
+
borderRadius: "inherit",
|
|
108
|
+
transition: "width 0.16s ease",
|
|
109
|
+
animation: resolvedProgress == null ? "fp-loading-line-pulse 1.05s ease-in-out infinite" : void 0
|
|
110
|
+
} }) }),
|
|
111
|
+
/* @__PURE__ */ jsx("span", { style: { color: "#526173", fontSize: 12 }, children: resolvedProgress == null ? "\u51C6\u5907\u4E2D" : `${Math.round(resolvedProgress * 100)}%` })
|
|
112
|
+
] })
|
|
113
|
+
] });
|
|
114
|
+
};
|
|
115
|
+
var normalizeLocale = (locale) => locale?.startsWith("en") ? "en-US" : "zh-CN";
|
|
116
|
+
var defaultRegistry = createFilePilotRegistry();
|
|
117
|
+
var defaultFallback = /* @__PURE__ */ jsx(FilePilotLoading, {});
|
|
118
|
+
var viewerCache = /* @__PURE__ */ new WeakMap();
|
|
119
|
+
var getLazyViewerEntry = (parser) => {
|
|
120
|
+
const cached = viewerCache.get(parser);
|
|
121
|
+
if (cached) return cached;
|
|
122
|
+
const entry = {
|
|
123
|
+
Viewer: React.lazy(() => parser.load().catch((error) => {
|
|
124
|
+
entry.loadError = error;
|
|
125
|
+
entry.errorListeners.forEach((listener) => listener(error));
|
|
126
|
+
throw error;
|
|
127
|
+
})),
|
|
128
|
+
errorListeners: /* @__PURE__ */ new Set()
|
|
129
|
+
};
|
|
130
|
+
viewerCache.set(parser, entry);
|
|
131
|
+
return entry;
|
|
132
|
+
};
|
|
133
|
+
var FilePilot = ({
|
|
134
|
+
file,
|
|
135
|
+
registry = defaultRegistry,
|
|
136
|
+
parserId,
|
|
137
|
+
options,
|
|
138
|
+
locale,
|
|
139
|
+
className,
|
|
140
|
+
style,
|
|
141
|
+
fallback = defaultFallback,
|
|
142
|
+
unsupported = null,
|
|
143
|
+
onError
|
|
144
|
+
}) => {
|
|
145
|
+
const parser = registry.resolve(file, parserId);
|
|
146
|
+
const resolvedLocale = normalizeLocale(locale);
|
|
147
|
+
const viewerEntry = useMemo(() => parser ? getLazyViewerEntry(parser) : void 0, [parser]);
|
|
148
|
+
const onErrorRef = useRef(onError);
|
|
149
|
+
onErrorRef.current = onError;
|
|
150
|
+
useEffect(() => {
|
|
151
|
+
if (!viewerEntry) return;
|
|
152
|
+
const listener = (error) => onErrorRef.current?.(error);
|
|
153
|
+
viewerEntry.errorListeners.add(listener);
|
|
154
|
+
if (viewerEntry.loadError !== void 0) listener(viewerEntry.loadError);
|
|
155
|
+
return () => {
|
|
156
|
+
viewerEntry.errorListeners.delete(listener);
|
|
157
|
+
};
|
|
158
|
+
}, [viewerEntry]);
|
|
159
|
+
const Viewer = viewerEntry?.Viewer;
|
|
160
|
+
if (!Viewer) {
|
|
161
|
+
return /* @__PURE__ */ jsx(Fragment, { children: typeof unsupported === "function" ? unsupported(file) : unsupported });
|
|
162
|
+
}
|
|
163
|
+
return /* @__PURE__ */ jsx("div", { style: { position: "relative", display: "flex", flexDirection: "column", width: "100%", height: "100%", minHeight: 480, flex: "1 1 auto", ...style }, children: /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx("div", { style: { position: "absolute", inset: 0, display: "flex" }, children: fallback }), children: /* @__PURE__ */ jsx(Viewer, { file, options, locale: resolvedLocale, className, style }) }) });
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
export {
|
|
167
|
+
FilePilotLoading,
|
|
168
|
+
FilePilot
|
|
169
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// src/registry.ts
|
|
2
|
+
var normalizeExtension = (extension) => extension?.replace(/^\./, "").toLowerCase();
|
|
3
|
+
var getFileExtension = (file) => {
|
|
4
|
+
if (file.extension) return normalizeExtension(file.extension);
|
|
5
|
+
const name = file.name?.split(/[?#]/)[0];
|
|
6
|
+
const index = name?.lastIndexOf(".") ?? -1;
|
|
7
|
+
return index >= 0 ? normalizeExtension(name?.slice(index + 1)) : void 0;
|
|
8
|
+
};
|
|
9
|
+
var hasExtensionMatch = (parser, extension) => Boolean(
|
|
10
|
+
extension && parser.extensions.some((item) => normalizeExtension(item) === extension)
|
|
11
|
+
);
|
|
12
|
+
var hasMimeTypeMatch = (parser, mimeType) => Boolean(
|
|
13
|
+
mimeType && parser.mimeTypes?.some((item) => item.toLowerCase() === mimeType)
|
|
14
|
+
);
|
|
15
|
+
var createFilePilotRegistry = (initialParsers = []) => {
|
|
16
|
+
const parsers = /* @__PURE__ */ new Map();
|
|
17
|
+
initialParsers.forEach((parser) => parsers.set(parser.id, parser));
|
|
18
|
+
return {
|
|
19
|
+
register(parser) {
|
|
20
|
+
parsers.set(parser.id, parser);
|
|
21
|
+
return () => parsers.delete(parser.id);
|
|
22
|
+
},
|
|
23
|
+
unregister(id) {
|
|
24
|
+
parsers.delete(id);
|
|
25
|
+
},
|
|
26
|
+
resolve(file, parserId) {
|
|
27
|
+
const extension = getFileExtension(file);
|
|
28
|
+
const mimeType = file.mimeType?.toLowerCase();
|
|
29
|
+
if (parserId) return parsers.get(parserId);
|
|
30
|
+
const list = Array.from(parsers.values());
|
|
31
|
+
return list.find((parser) => hasExtensionMatch(parser, extension)) ?? list.find((parser) => hasMimeTypeMatch(parser, mimeType));
|
|
32
|
+
},
|
|
33
|
+
list() {
|
|
34
|
+
return Array.from(parsers.values());
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export {
|
|
40
|
+
createFilePilotRegistry
|
|
41
|
+
};
|
package/dist/index.cjs
CHANGED
|
@@ -31,9 +31,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
FilePilot: () => FilePilot,
|
|
34
|
-
|
|
35
|
-
createFilePilotRegistry: () => createFilePilotRegistry
|
|
36
|
-
defaultRegistry: () => defaultRegistry
|
|
34
|
+
FilePilotLoading: () => FilePilotLoading,
|
|
35
|
+
createFilePilotRegistry: () => createFilePilotRegistry
|
|
37
36
|
});
|
|
38
37
|
module.exports = __toCommonJS(index_exports);
|
|
39
38
|
|
|
@@ -75,78 +74,119 @@ var createFilePilotRegistry = (initialParsers = []) => {
|
|
|
75
74
|
};
|
|
76
75
|
};
|
|
77
76
|
|
|
78
|
-
// src/builtin.ts
|
|
79
|
-
var builtinParsers = [
|
|
80
|
-
{
|
|
81
|
-
id: "filepilot-parser-drawio",
|
|
82
|
-
kind: "drawing",
|
|
83
|
-
extensions: ["drawio", "dio"],
|
|
84
|
-
mimeTypes: ["application/vnd.jgraph.mxfile", "application/x-drawio", "application/drawio"],
|
|
85
|
-
load: () => import("@macrowing/filepilot-parser-drawio")
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
id: "filepilot-parser-viewer",
|
|
89
|
-
kind: "viewer",
|
|
90
|
-
extensions: ["md", "markdown", "mdx", "txt", "text", "log", "csv", "json", "xml", "yaml", "yml", "png", "jpg", "jpeg", "gif", "webp", "bmp", "svg"],
|
|
91
|
-
mimeTypes: [
|
|
92
|
-
"text/markdown",
|
|
93
|
-
"text/x-markdown",
|
|
94
|
-
"text/plain",
|
|
95
|
-
"text/csv",
|
|
96
|
-
"application/json",
|
|
97
|
-
"application/xml",
|
|
98
|
-
"text/xml",
|
|
99
|
-
"image/png",
|
|
100
|
-
"image/jpeg",
|
|
101
|
-
"image/gif",
|
|
102
|
-
"image/webp",
|
|
103
|
-
"image/bmp",
|
|
104
|
-
"image/svg+xml"
|
|
105
|
-
],
|
|
106
|
-
load: () => import("@macrowing/filepilot-parser-viewer")
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
id: "filepilot-parser-pdf",
|
|
110
|
-
kind: "pdf",
|
|
111
|
-
extensions: ["pdf"],
|
|
112
|
-
mimeTypes: ["application/pdf"],
|
|
113
|
-
load: () => import("@macrowing/filepilot-parser-pdf")
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
id: "filepilot-parser-office",
|
|
117
|
-
kind: "office",
|
|
118
|
-
extensions: ["doc", "docx", "ppt", "pptx", "xls", "xlsx"],
|
|
119
|
-
mimeTypes: [
|
|
120
|
-
"application/msword",
|
|
121
|
-
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
122
|
-
"application/vnd.ms-powerpoint",
|
|
123
|
-
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
124
|
-
"application/vnd.ms-excel",
|
|
125
|
-
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
126
|
-
],
|
|
127
|
-
load: () => import("@macrowing/filepilot-parser-office")
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
id: "filepilot-parser-mmind",
|
|
131
|
-
kind: "mindmap",
|
|
132
|
-
extensions: ["mmind"],
|
|
133
|
-
mimeTypes: ["application/json", "application/x-mmind"],
|
|
134
|
-
load: () => import("@macrowing/filepilot-parser-mmind")
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
id: "filepilot-parser-mdoc",
|
|
138
|
-
kind: "docflow",
|
|
139
|
-
extensions: ["mdoc"],
|
|
140
|
-
mimeTypes: ["application/x-mdoc", "application/vnd.docflow.mdoc", "application/octet-stream"],
|
|
141
|
-
load: () => import("@macrowing/filepilot-parser-mdoc")
|
|
142
|
-
}
|
|
143
|
-
];
|
|
144
|
-
var defaultRegistry = createFilePilotRegistry(builtinParsers);
|
|
145
|
-
|
|
146
77
|
// src/react.tsx
|
|
147
78
|
var import_react = __toESM(require("react"), 1);
|
|
148
79
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
80
|
+
var loadingKeyframes = `
|
|
81
|
+
@keyframes fp-loading-spin {
|
|
82
|
+
to {
|
|
83
|
+
transform: rotate(360deg);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
@keyframes fp-loading-line-pulse {
|
|
88
|
+
0%,
|
|
89
|
+
100% {
|
|
90
|
+
opacity: 0.45;
|
|
91
|
+
transform: scaleX(0.86);
|
|
92
|
+
transform-origin: left center;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
50% {
|
|
96
|
+
opacity: 1;
|
|
97
|
+
transform: scaleX(1);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
`;
|
|
101
|
+
var FilePilotLoading = ({ stage = "\u89E3\u6790\u5668\u52A0\u8F7D\u4E2D", message = "\u6B63\u5728\u51C6\u5907\u6587\u4EF6\u9884\u89C8\u80FD\u529B", progress }) => {
|
|
102
|
+
const resolvedProgress = typeof progress === "number" && Number.isFinite(progress) ? Math.max(0, Math.min(1, progress)) : void 0;
|
|
103
|
+
const progressWidth = `${Math.round((resolvedProgress ?? 0.42) * 100)}%`;
|
|
104
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: {
|
|
105
|
+
display: "grid",
|
|
106
|
+
placeItems: "center",
|
|
107
|
+
alignContent: "center",
|
|
108
|
+
gap: 18,
|
|
109
|
+
width: "100%",
|
|
110
|
+
height: "100%",
|
|
111
|
+
minHeight: 480,
|
|
112
|
+
padding: 24,
|
|
113
|
+
color: "#1f2937",
|
|
114
|
+
textAlign: "center",
|
|
115
|
+
background: "radial-gradient(circle at center, rgba(56, 103, 214, 0.12), transparent 42%), #f8fafc"
|
|
116
|
+
}, children: [
|
|
117
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", { children: loadingKeyframes }),
|
|
118
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { position: "relative", display: "grid", placeItems: "center", width: 112, height: 112 }, children: [
|
|
119
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: {
|
|
120
|
+
position: "absolute",
|
|
121
|
+
inset: 0,
|
|
122
|
+
border: "3px solid rgba(56, 103, 214, 0.14)",
|
|
123
|
+
borderTopColor: "#3867d6",
|
|
124
|
+
borderRightColor: "#7298f0",
|
|
125
|
+
borderRadius: 999,
|
|
126
|
+
boxShadow: "0 0 0 8px rgba(255, 255, 255, 0.58), 0 18px 42px rgba(56, 103, 214, 0.16)",
|
|
127
|
+
animation: "fp-loading-spin 0.92s linear infinite"
|
|
128
|
+
} }),
|
|
129
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: {
|
|
130
|
+
position: "relative",
|
|
131
|
+
display: "block",
|
|
132
|
+
width: 56,
|
|
133
|
+
height: 66,
|
|
134
|
+
background: "#ffffff",
|
|
135
|
+
border: "1px solid rgba(56, 103, 214, 0.18)",
|
|
136
|
+
borderRadius: 8,
|
|
137
|
+
boxShadow: "0 14px 28px rgba(31, 41, 55, 0.12), inset 0 0 0 1px rgba(255, 255, 255, 0.68)"
|
|
138
|
+
}, children: [
|
|
139
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: {
|
|
140
|
+
position: "absolute",
|
|
141
|
+
left: -8,
|
|
142
|
+
bottom: 8,
|
|
143
|
+
width: 45,
|
|
144
|
+
height: 54,
|
|
145
|
+
background: "rgba(56, 103, 214, 0.08)",
|
|
146
|
+
border: "1px solid rgba(56, 103, 214, 0.12)",
|
|
147
|
+
borderRadius: 8,
|
|
148
|
+
transform: "rotate(-5deg)",
|
|
149
|
+
zIndex: -1
|
|
150
|
+
} }),
|
|
151
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: {
|
|
152
|
+
position: "absolute",
|
|
153
|
+
top: -1,
|
|
154
|
+
right: -1,
|
|
155
|
+
width: 18,
|
|
156
|
+
height: 18,
|
|
157
|
+
background: "linear-gradient(135deg, rgba(56, 103, 214, 0.18) 0 50%, transparent 50% 100%)",
|
|
158
|
+
borderTopRightRadius: 8
|
|
159
|
+
} }),
|
|
160
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { position: "absolute", top: 18, left: 12, right: 10, display: "grid", gap: 6 }, children: [
|
|
161
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { display: "block", height: 5, background: "rgba(56, 103, 214, 0.16)", borderRadius: 999, animation: "fp-loading-line-pulse 1.25s ease-in-out infinite" } }),
|
|
162
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { display: "block", height: 5, width: "78%", background: "rgba(56, 103, 214, 0.16)", borderRadius: 999, animation: "fp-loading-line-pulse 1.25s ease-in-out infinite", animationDelay: "0.12s" } }),
|
|
163
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { display: "block", height: 5, width: "56%", background: "rgba(56, 103, 214, 0.16)", borderRadius: 999, animation: "fp-loading-line-pulse 1.25s ease-in-out infinite", animationDelay: "0.24s" } })
|
|
164
|
+
] })
|
|
165
|
+
] })
|
|
166
|
+
] }),
|
|
167
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "grid", gap: 6, maxWidth: "min(360px, 100%)" }, children: [
|
|
168
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { style: { color: "#1f2937", fontSize: 16 }, children: "\u6B63\u5728\u52A0\u8F7D\u6587\u6863..." }),
|
|
169
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { color: "#526173", fontSize: 13, lineHeight: 1.6 }, children: stage }),
|
|
170
|
+
message ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { color: "#526173", fontSize: 13, lineHeight: 1.6 }, children: message }) : null
|
|
171
|
+
] }),
|
|
172
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "grid", gap: 7, width: "min(320px, 76vw)", marginTop: 8 }, children: [
|
|
173
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { position: "relative", height: 7, overflow: "hidden", background: "rgba(56, 103, 214, 0.1)", borderRadius: 999 }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: {
|
|
174
|
+
position: "absolute",
|
|
175
|
+
inset: "0 auto 0 0",
|
|
176
|
+
width: progressWidth,
|
|
177
|
+
minWidth: 8,
|
|
178
|
+
background: "linear-gradient(90deg, #3867d6, #7298f0)",
|
|
179
|
+
borderRadius: "inherit",
|
|
180
|
+
transition: "width 0.16s ease",
|
|
181
|
+
animation: resolvedProgress == null ? "fp-loading-line-pulse 1.05s ease-in-out infinite" : void 0
|
|
182
|
+
} }) }),
|
|
183
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { color: "#526173", fontSize: 12 }, children: resolvedProgress == null ? "\u51C6\u5907\u4E2D" : `${Math.round(resolvedProgress * 100)}%` })
|
|
184
|
+
] })
|
|
185
|
+
] });
|
|
186
|
+
};
|
|
149
187
|
var normalizeLocale = (locale) => locale?.startsWith("en") ? "en-US" : "zh-CN";
|
|
188
|
+
var defaultRegistry = createFilePilotRegistry();
|
|
189
|
+
var defaultFallback = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FilePilotLoading, {});
|
|
150
190
|
var viewerCache = /* @__PURE__ */ new WeakMap();
|
|
151
191
|
var getLazyViewerEntry = (parser) => {
|
|
152
192
|
const cached = viewerCache.get(parser);
|
|
@@ -170,7 +210,7 @@ var FilePilot = ({
|
|
|
170
210
|
locale,
|
|
171
211
|
className,
|
|
172
212
|
style,
|
|
173
|
-
fallback =
|
|
213
|
+
fallback = defaultFallback,
|
|
174
214
|
unsupported = null,
|
|
175
215
|
onError
|
|
176
216
|
}) => {
|
|
@@ -192,12 +232,11 @@ var FilePilot = ({
|
|
|
192
232
|
if (!Viewer) {
|
|
193
233
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: typeof unsupported === "function" ? unsupported(file) : unsupported });
|
|
194
234
|
}
|
|
195
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { fallback, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Viewer, { file, options, locale: resolvedLocale, className, style }) });
|
|
235
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { position: "relative", display: "flex", flexDirection: "column", width: "100%", height: "100%", minHeight: 480, flex: "1 1 auto", ...style }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { fallback: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { position: "absolute", inset: 0, display: "flex" }, children: fallback }), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Viewer, { file, options, locale: resolvedLocale, className, style }) }) });
|
|
196
236
|
};
|
|
197
237
|
// Annotate the CommonJS export names for ESM import in node:
|
|
198
238
|
0 && (module.exports = {
|
|
199
239
|
FilePilot,
|
|
200
|
-
|
|
201
|
-
createFilePilotRegistry
|
|
202
|
-
defaultRegistry
|
|
240
|
+
FilePilotLoading,
|
|
241
|
+
createFilePilotRegistry
|
|
203
242
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { FilePilotParser, FilePilotRegistry } from '@macrowing/filepilot-types';
|
|
2
2
|
export { FilePilotFile, FilePilotKind, FilePilotLocale, FilePilotParser, FilePilotProps, FilePilotRegistry, FilePilotRenderProps, FilePilotSource } from '@macrowing/filepilot-types';
|
|
3
|
-
export {
|
|
4
|
-
export { FilePilot } from './react.cjs';
|
|
3
|
+
export { FilePilot, FilePilotLoading } from './react.cjs';
|
|
5
4
|
import 'react';
|
|
6
5
|
|
|
7
6
|
declare const createFilePilotRegistry: (initialParsers?: FilePilotParser[]) => FilePilotRegistry;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { FilePilotParser, FilePilotRegistry } from '@macrowing/filepilot-types';
|
|
2
2
|
export { FilePilotFile, FilePilotKind, FilePilotLocale, FilePilotParser, FilePilotProps, FilePilotRegistry, FilePilotRenderProps, FilePilotSource } from '@macrowing/filepilot-types';
|
|
3
|
-
export {
|
|
4
|
-
export { FilePilot } from './react.js';
|
|
3
|
+
export { FilePilot, FilePilotLoading } from './react.js';
|
|
5
4
|
import 'react';
|
|
6
5
|
|
|
7
6
|
declare const createFilePilotRegistry: (initialParsers?: FilePilotParser[]) => FilePilotRegistry;
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
-
FilePilot
|
|
3
|
-
|
|
2
|
+
FilePilot,
|
|
3
|
+
FilePilotLoading
|
|
4
|
+
} from "./chunk-CKS4FUE2.js";
|
|
4
5
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
defaultRegistry
|
|
8
|
-
} from "./chunk-EQYOJW24.js";
|
|
6
|
+
createFilePilotRegistry
|
|
7
|
+
} from "./chunk-KCRUK7FG.js";
|
|
9
8
|
export {
|
|
10
9
|
FilePilot,
|
|
11
|
-
|
|
12
|
-
createFilePilotRegistry
|
|
13
|
-
defaultRegistry
|
|
10
|
+
FilePilotLoading,
|
|
11
|
+
createFilePilotRegistry
|
|
14
12
|
};
|
package/dist/react.cjs
CHANGED
|
@@ -30,7 +30,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/react.tsx
|
|
31
31
|
var react_exports = {};
|
|
32
32
|
__export(react_exports, {
|
|
33
|
-
FilePilot: () => FilePilot
|
|
33
|
+
FilePilot: () => FilePilot,
|
|
34
|
+
FilePilotLoading: () => FilePilotLoading
|
|
34
35
|
});
|
|
35
36
|
module.exports = __toCommonJS(react_exports);
|
|
36
37
|
var import_react = __toESM(require("react"), 1);
|
|
@@ -73,77 +74,118 @@ var createFilePilotRegistry = (initialParsers = []) => {
|
|
|
73
74
|
};
|
|
74
75
|
};
|
|
75
76
|
|
|
76
|
-
// src/builtin.ts
|
|
77
|
-
var builtinParsers = [
|
|
78
|
-
{
|
|
79
|
-
id: "filepilot-parser-drawio",
|
|
80
|
-
kind: "drawing",
|
|
81
|
-
extensions: ["drawio", "dio"],
|
|
82
|
-
mimeTypes: ["application/vnd.jgraph.mxfile", "application/x-drawio", "application/drawio"],
|
|
83
|
-
load: () => import("@macrowing/filepilot-parser-drawio")
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
id: "filepilot-parser-viewer",
|
|
87
|
-
kind: "viewer",
|
|
88
|
-
extensions: ["md", "markdown", "mdx", "txt", "text", "log", "csv", "json", "xml", "yaml", "yml", "png", "jpg", "jpeg", "gif", "webp", "bmp", "svg"],
|
|
89
|
-
mimeTypes: [
|
|
90
|
-
"text/markdown",
|
|
91
|
-
"text/x-markdown",
|
|
92
|
-
"text/plain",
|
|
93
|
-
"text/csv",
|
|
94
|
-
"application/json",
|
|
95
|
-
"application/xml",
|
|
96
|
-
"text/xml",
|
|
97
|
-
"image/png",
|
|
98
|
-
"image/jpeg",
|
|
99
|
-
"image/gif",
|
|
100
|
-
"image/webp",
|
|
101
|
-
"image/bmp",
|
|
102
|
-
"image/svg+xml"
|
|
103
|
-
],
|
|
104
|
-
load: () => import("@macrowing/filepilot-parser-viewer")
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
id: "filepilot-parser-pdf",
|
|
108
|
-
kind: "pdf",
|
|
109
|
-
extensions: ["pdf"],
|
|
110
|
-
mimeTypes: ["application/pdf"],
|
|
111
|
-
load: () => import("@macrowing/filepilot-parser-pdf")
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
id: "filepilot-parser-office",
|
|
115
|
-
kind: "office",
|
|
116
|
-
extensions: ["doc", "docx", "ppt", "pptx", "xls", "xlsx"],
|
|
117
|
-
mimeTypes: [
|
|
118
|
-
"application/msword",
|
|
119
|
-
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
120
|
-
"application/vnd.ms-powerpoint",
|
|
121
|
-
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
122
|
-
"application/vnd.ms-excel",
|
|
123
|
-
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
124
|
-
],
|
|
125
|
-
load: () => import("@macrowing/filepilot-parser-office")
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
id: "filepilot-parser-mmind",
|
|
129
|
-
kind: "mindmap",
|
|
130
|
-
extensions: ["mmind"],
|
|
131
|
-
mimeTypes: ["application/json", "application/x-mmind"],
|
|
132
|
-
load: () => import("@macrowing/filepilot-parser-mmind")
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
id: "filepilot-parser-mdoc",
|
|
136
|
-
kind: "docflow",
|
|
137
|
-
extensions: ["mdoc"],
|
|
138
|
-
mimeTypes: ["application/x-mdoc", "application/vnd.docflow.mdoc", "application/octet-stream"],
|
|
139
|
-
load: () => import("@macrowing/filepilot-parser-mdoc")
|
|
140
|
-
}
|
|
141
|
-
];
|
|
142
|
-
var defaultRegistry = createFilePilotRegistry(builtinParsers);
|
|
143
|
-
|
|
144
77
|
// src/react.tsx
|
|
145
78
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
79
|
+
var loadingKeyframes = `
|
|
80
|
+
@keyframes fp-loading-spin {
|
|
81
|
+
to {
|
|
82
|
+
transform: rotate(360deg);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@keyframes fp-loading-line-pulse {
|
|
87
|
+
0%,
|
|
88
|
+
100% {
|
|
89
|
+
opacity: 0.45;
|
|
90
|
+
transform: scaleX(0.86);
|
|
91
|
+
transform-origin: left center;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
50% {
|
|
95
|
+
opacity: 1;
|
|
96
|
+
transform: scaleX(1);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
`;
|
|
100
|
+
var FilePilotLoading = ({ stage = "\u89E3\u6790\u5668\u52A0\u8F7D\u4E2D", message = "\u6B63\u5728\u51C6\u5907\u6587\u4EF6\u9884\u89C8\u80FD\u529B", progress }) => {
|
|
101
|
+
const resolvedProgress = typeof progress === "number" && Number.isFinite(progress) ? Math.max(0, Math.min(1, progress)) : void 0;
|
|
102
|
+
const progressWidth = `${Math.round((resolvedProgress ?? 0.42) * 100)}%`;
|
|
103
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: {
|
|
104
|
+
display: "grid",
|
|
105
|
+
placeItems: "center",
|
|
106
|
+
alignContent: "center",
|
|
107
|
+
gap: 18,
|
|
108
|
+
width: "100%",
|
|
109
|
+
height: "100%",
|
|
110
|
+
minHeight: 480,
|
|
111
|
+
padding: 24,
|
|
112
|
+
color: "#1f2937",
|
|
113
|
+
textAlign: "center",
|
|
114
|
+
background: "radial-gradient(circle at center, rgba(56, 103, 214, 0.12), transparent 42%), #f8fafc"
|
|
115
|
+
}, children: [
|
|
116
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", { children: loadingKeyframes }),
|
|
117
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { position: "relative", display: "grid", placeItems: "center", width: 112, height: 112 }, children: [
|
|
118
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: {
|
|
119
|
+
position: "absolute",
|
|
120
|
+
inset: 0,
|
|
121
|
+
border: "3px solid rgba(56, 103, 214, 0.14)",
|
|
122
|
+
borderTopColor: "#3867d6",
|
|
123
|
+
borderRightColor: "#7298f0",
|
|
124
|
+
borderRadius: 999,
|
|
125
|
+
boxShadow: "0 0 0 8px rgba(255, 255, 255, 0.58), 0 18px 42px rgba(56, 103, 214, 0.16)",
|
|
126
|
+
animation: "fp-loading-spin 0.92s linear infinite"
|
|
127
|
+
} }),
|
|
128
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: {
|
|
129
|
+
position: "relative",
|
|
130
|
+
display: "block",
|
|
131
|
+
width: 56,
|
|
132
|
+
height: 66,
|
|
133
|
+
background: "#ffffff",
|
|
134
|
+
border: "1px solid rgba(56, 103, 214, 0.18)",
|
|
135
|
+
borderRadius: 8,
|
|
136
|
+
boxShadow: "0 14px 28px rgba(31, 41, 55, 0.12), inset 0 0 0 1px rgba(255, 255, 255, 0.68)"
|
|
137
|
+
}, children: [
|
|
138
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: {
|
|
139
|
+
position: "absolute",
|
|
140
|
+
left: -8,
|
|
141
|
+
bottom: 8,
|
|
142
|
+
width: 45,
|
|
143
|
+
height: 54,
|
|
144
|
+
background: "rgba(56, 103, 214, 0.08)",
|
|
145
|
+
border: "1px solid rgba(56, 103, 214, 0.12)",
|
|
146
|
+
borderRadius: 8,
|
|
147
|
+
transform: "rotate(-5deg)",
|
|
148
|
+
zIndex: -1
|
|
149
|
+
} }),
|
|
150
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: {
|
|
151
|
+
position: "absolute",
|
|
152
|
+
top: -1,
|
|
153
|
+
right: -1,
|
|
154
|
+
width: 18,
|
|
155
|
+
height: 18,
|
|
156
|
+
background: "linear-gradient(135deg, rgba(56, 103, 214, 0.18) 0 50%, transparent 50% 100%)",
|
|
157
|
+
borderTopRightRadius: 8
|
|
158
|
+
} }),
|
|
159
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { position: "absolute", top: 18, left: 12, right: 10, display: "grid", gap: 6 }, children: [
|
|
160
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { display: "block", height: 5, background: "rgba(56, 103, 214, 0.16)", borderRadius: 999, animation: "fp-loading-line-pulse 1.25s ease-in-out infinite" } }),
|
|
161
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { display: "block", height: 5, width: "78%", background: "rgba(56, 103, 214, 0.16)", borderRadius: 999, animation: "fp-loading-line-pulse 1.25s ease-in-out infinite", animationDelay: "0.12s" } }),
|
|
162
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { display: "block", height: 5, width: "56%", background: "rgba(56, 103, 214, 0.16)", borderRadius: 999, animation: "fp-loading-line-pulse 1.25s ease-in-out infinite", animationDelay: "0.24s" } })
|
|
163
|
+
] })
|
|
164
|
+
] })
|
|
165
|
+
] }),
|
|
166
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "grid", gap: 6, maxWidth: "min(360px, 100%)" }, children: [
|
|
167
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { style: { color: "#1f2937", fontSize: 16 }, children: "\u6B63\u5728\u52A0\u8F7D\u6587\u6863..." }),
|
|
168
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { color: "#526173", fontSize: 13, lineHeight: 1.6 }, children: stage }),
|
|
169
|
+
message ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { color: "#526173", fontSize: 13, lineHeight: 1.6 }, children: message }) : null
|
|
170
|
+
] }),
|
|
171
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "grid", gap: 7, width: "min(320px, 76vw)", marginTop: 8 }, children: [
|
|
172
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { position: "relative", height: 7, overflow: "hidden", background: "rgba(56, 103, 214, 0.1)", borderRadius: 999 }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: {
|
|
173
|
+
position: "absolute",
|
|
174
|
+
inset: "0 auto 0 0",
|
|
175
|
+
width: progressWidth,
|
|
176
|
+
minWidth: 8,
|
|
177
|
+
background: "linear-gradient(90deg, #3867d6, #7298f0)",
|
|
178
|
+
borderRadius: "inherit",
|
|
179
|
+
transition: "width 0.16s ease",
|
|
180
|
+
animation: resolvedProgress == null ? "fp-loading-line-pulse 1.05s ease-in-out infinite" : void 0
|
|
181
|
+
} }) }),
|
|
182
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { color: "#526173", fontSize: 12 }, children: resolvedProgress == null ? "\u51C6\u5907\u4E2D" : `${Math.round(resolvedProgress * 100)}%` })
|
|
183
|
+
] })
|
|
184
|
+
] });
|
|
185
|
+
};
|
|
146
186
|
var normalizeLocale = (locale) => locale?.startsWith("en") ? "en-US" : "zh-CN";
|
|
187
|
+
var defaultRegistry = createFilePilotRegistry();
|
|
188
|
+
var defaultFallback = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FilePilotLoading, {});
|
|
147
189
|
var viewerCache = /* @__PURE__ */ new WeakMap();
|
|
148
190
|
var getLazyViewerEntry = (parser) => {
|
|
149
191
|
const cached = viewerCache.get(parser);
|
|
@@ -167,7 +209,7 @@ var FilePilot = ({
|
|
|
167
209
|
locale,
|
|
168
210
|
className,
|
|
169
211
|
style,
|
|
170
|
-
fallback =
|
|
212
|
+
fallback = defaultFallback,
|
|
171
213
|
unsupported = null,
|
|
172
214
|
onError
|
|
173
215
|
}) => {
|
|
@@ -189,9 +231,10 @@ var FilePilot = ({
|
|
|
189
231
|
if (!Viewer) {
|
|
190
232
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: typeof unsupported === "function" ? unsupported(file) : unsupported });
|
|
191
233
|
}
|
|
192
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { fallback, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Viewer, { file, options, locale: resolvedLocale, className, style }) });
|
|
234
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { position: "relative", display: "flex", flexDirection: "column", width: "100%", height: "100%", minHeight: 480, flex: "1 1 auto", ...style }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { fallback: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { position: "absolute", inset: 0, display: "flex" }, children: fallback }), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Viewer, { file, options, locale: resolvedLocale, className, style }) }) });
|
|
193
235
|
};
|
|
194
236
|
// Annotate the CommonJS export names for ESM import in node:
|
|
195
237
|
0 && (module.exports = {
|
|
196
|
-
FilePilot
|
|
238
|
+
FilePilot,
|
|
239
|
+
FilePilotLoading
|
|
197
240
|
});
|
package/dist/react.d.cts
CHANGED
|
@@ -2,6 +2,12 @@ import React from 'react';
|
|
|
2
2
|
import { FilePilotProps } from '@macrowing/filepilot-types';
|
|
3
3
|
export { FilePilotLocale, FilePilotProps } from '@macrowing/filepilot-types';
|
|
4
4
|
|
|
5
|
+
type FilePilotLoadingProps = {
|
|
6
|
+
stage?: string;
|
|
7
|
+
message?: string;
|
|
8
|
+
progress?: number;
|
|
9
|
+
};
|
|
10
|
+
declare const FilePilotLoading: ({ stage, message, progress }: FilePilotLoadingProps) => React.JSX.Element;
|
|
5
11
|
declare const FilePilot: ({ file, registry, parserId, options, locale, className, style, fallback, unsupported, onError }: FilePilotProps) => React.JSX.Element;
|
|
6
12
|
|
|
7
|
-
export { FilePilot };
|
|
13
|
+
export { FilePilot, FilePilotLoading, type FilePilotLoadingProps };
|
package/dist/react.d.ts
CHANGED
|
@@ -2,6 +2,12 @@ import React from 'react';
|
|
|
2
2
|
import { FilePilotProps } from '@macrowing/filepilot-types';
|
|
3
3
|
export { FilePilotLocale, FilePilotProps } from '@macrowing/filepilot-types';
|
|
4
4
|
|
|
5
|
+
type FilePilotLoadingProps = {
|
|
6
|
+
stage?: string;
|
|
7
|
+
message?: string;
|
|
8
|
+
progress?: number;
|
|
9
|
+
};
|
|
10
|
+
declare const FilePilotLoading: ({ stage, message, progress }: FilePilotLoadingProps) => React.JSX.Element;
|
|
5
11
|
declare const FilePilot: ({ file, registry, parserId, options, locale, className, style, fallback, unsupported, onError }: FilePilotProps) => React.JSX.Element;
|
|
6
12
|
|
|
7
|
-
export { FilePilot };
|
|
13
|
+
export { FilePilot, FilePilotLoading, type FilePilotLoadingProps };
|
package/dist/react.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@macrowing/filepilot",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Extensible, lazy-loaded React file preview toolkit.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -28,18 +28,38 @@
|
|
|
28
28
|
"dist"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@macrowing/filepilot-
|
|
32
|
-
"@macrowing/filepilot-parser-mdoc": "0.1.0",
|
|
33
|
-
"@macrowing/filepilot-parser-mmind": "0.1.0",
|
|
34
|
-
"@macrowing/filepilot-parser-pdf": "0.1.0",
|
|
35
|
-
"@macrowing/filepilot-parser-office": "0.1.0",
|
|
36
|
-
"@macrowing/filepilot-types": "0.1.0",
|
|
37
|
-
"@macrowing/filepilot-parser-viewer": "0.1.0"
|
|
31
|
+
"@macrowing/filepilot-types": "0.2.0"
|
|
38
32
|
},
|
|
39
33
|
"peerDependencies": {
|
|
34
|
+
"@macrowing/filepilot-parser-drawio": "^1.0.0",
|
|
35
|
+
"@macrowing/filepilot-parser-mdoc": "^1.0.0",
|
|
36
|
+
"@macrowing/filepilot-parser-mmind": "^1.0.0",
|
|
37
|
+
"@macrowing/filepilot-parser-office": "^1.0.0",
|
|
38
|
+
"@macrowing/filepilot-parser-pdf": "^1.0.0",
|
|
39
|
+
"@macrowing/filepilot-parser-viewer": "^1.0.0",
|
|
40
40
|
"react": ">=18.2.0 || >=19.0.0",
|
|
41
41
|
"react-dom": ">=18.2.0 || >=19.0.0"
|
|
42
42
|
},
|
|
43
|
+
"peerDependenciesMeta": {
|
|
44
|
+
"@macrowing/filepilot-parser-drawio": {
|
|
45
|
+
"optional": true
|
|
46
|
+
},
|
|
47
|
+
"@macrowing/filepilot-parser-mdoc": {
|
|
48
|
+
"optional": true
|
|
49
|
+
},
|
|
50
|
+
"@macrowing/filepilot-parser-mmind": {
|
|
51
|
+
"optional": true
|
|
52
|
+
},
|
|
53
|
+
"@macrowing/filepilot-parser-office": {
|
|
54
|
+
"optional": true
|
|
55
|
+
},
|
|
56
|
+
"@macrowing/filepilot-parser-pdf": {
|
|
57
|
+
"optional": true
|
|
58
|
+
},
|
|
59
|
+
"@macrowing/filepilot-parser-viewer": {
|
|
60
|
+
"optional": true
|
|
61
|
+
}
|
|
62
|
+
},
|
|
43
63
|
"devDependencies": {
|
|
44
64
|
"rimraf": "^6.0.1",
|
|
45
65
|
"tsup": "^8.4.0"
|
package/dist/chunk-EQYOJW24.js
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
// src/registry.ts
|
|
2
|
-
var normalizeExtension = (extension) => extension?.replace(/^\./, "").toLowerCase();
|
|
3
|
-
var getFileExtension = (file) => {
|
|
4
|
-
if (file.extension) return normalizeExtension(file.extension);
|
|
5
|
-
const name = file.name?.split(/[?#]/)[0];
|
|
6
|
-
const index = name?.lastIndexOf(".") ?? -1;
|
|
7
|
-
return index >= 0 ? normalizeExtension(name?.slice(index + 1)) : void 0;
|
|
8
|
-
};
|
|
9
|
-
var hasExtensionMatch = (parser, extension) => Boolean(
|
|
10
|
-
extension && parser.extensions.some((item) => normalizeExtension(item) === extension)
|
|
11
|
-
);
|
|
12
|
-
var hasMimeTypeMatch = (parser, mimeType) => Boolean(
|
|
13
|
-
mimeType && parser.mimeTypes?.some((item) => item.toLowerCase() === mimeType)
|
|
14
|
-
);
|
|
15
|
-
var createFilePilotRegistry = (initialParsers = []) => {
|
|
16
|
-
const parsers = /* @__PURE__ */ new Map();
|
|
17
|
-
initialParsers.forEach((parser) => parsers.set(parser.id, parser));
|
|
18
|
-
return {
|
|
19
|
-
register(parser) {
|
|
20
|
-
parsers.set(parser.id, parser);
|
|
21
|
-
return () => parsers.delete(parser.id);
|
|
22
|
-
},
|
|
23
|
-
unregister(id) {
|
|
24
|
-
parsers.delete(id);
|
|
25
|
-
},
|
|
26
|
-
resolve(file, parserId) {
|
|
27
|
-
const extension = getFileExtension(file);
|
|
28
|
-
const mimeType = file.mimeType?.toLowerCase();
|
|
29
|
-
if (parserId) return parsers.get(parserId);
|
|
30
|
-
const list = Array.from(parsers.values());
|
|
31
|
-
return list.find((parser) => hasExtensionMatch(parser, extension)) ?? list.find((parser) => hasMimeTypeMatch(parser, mimeType));
|
|
32
|
-
},
|
|
33
|
-
list() {
|
|
34
|
-
return Array.from(parsers.values());
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
// src/builtin.ts
|
|
40
|
-
var builtinParsers = [
|
|
41
|
-
{
|
|
42
|
-
id: "filepilot-parser-drawio",
|
|
43
|
-
kind: "drawing",
|
|
44
|
-
extensions: ["drawio", "dio"],
|
|
45
|
-
mimeTypes: ["application/vnd.jgraph.mxfile", "application/x-drawio", "application/drawio"],
|
|
46
|
-
load: () => import("@macrowing/filepilot-parser-drawio")
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
id: "filepilot-parser-viewer",
|
|
50
|
-
kind: "viewer",
|
|
51
|
-
extensions: ["md", "markdown", "mdx", "txt", "text", "log", "csv", "json", "xml", "yaml", "yml", "png", "jpg", "jpeg", "gif", "webp", "bmp", "svg"],
|
|
52
|
-
mimeTypes: [
|
|
53
|
-
"text/markdown",
|
|
54
|
-
"text/x-markdown",
|
|
55
|
-
"text/plain",
|
|
56
|
-
"text/csv",
|
|
57
|
-
"application/json",
|
|
58
|
-
"application/xml",
|
|
59
|
-
"text/xml",
|
|
60
|
-
"image/png",
|
|
61
|
-
"image/jpeg",
|
|
62
|
-
"image/gif",
|
|
63
|
-
"image/webp",
|
|
64
|
-
"image/bmp",
|
|
65
|
-
"image/svg+xml"
|
|
66
|
-
],
|
|
67
|
-
load: () => import("@macrowing/filepilot-parser-viewer")
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
id: "filepilot-parser-pdf",
|
|
71
|
-
kind: "pdf",
|
|
72
|
-
extensions: ["pdf"],
|
|
73
|
-
mimeTypes: ["application/pdf"],
|
|
74
|
-
load: () => import("@macrowing/filepilot-parser-pdf")
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
id: "filepilot-parser-office",
|
|
78
|
-
kind: "office",
|
|
79
|
-
extensions: ["doc", "docx", "ppt", "pptx", "xls", "xlsx"],
|
|
80
|
-
mimeTypes: [
|
|
81
|
-
"application/msword",
|
|
82
|
-
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
83
|
-
"application/vnd.ms-powerpoint",
|
|
84
|
-
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
85
|
-
"application/vnd.ms-excel",
|
|
86
|
-
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
87
|
-
],
|
|
88
|
-
load: () => import("@macrowing/filepilot-parser-office")
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
id: "filepilot-parser-mmind",
|
|
92
|
-
kind: "mindmap",
|
|
93
|
-
extensions: ["mmind"],
|
|
94
|
-
mimeTypes: ["application/json", "application/x-mmind"],
|
|
95
|
-
load: () => import("@macrowing/filepilot-parser-mmind")
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
id: "filepilot-parser-mdoc",
|
|
99
|
-
kind: "docflow",
|
|
100
|
-
extensions: ["mdoc"],
|
|
101
|
-
mimeTypes: ["application/x-mdoc", "application/vnd.docflow.mdoc", "application/octet-stream"],
|
|
102
|
-
load: () => import("@macrowing/filepilot-parser-mdoc")
|
|
103
|
-
}
|
|
104
|
-
];
|
|
105
|
-
var defaultRegistry = createFilePilotRegistry(builtinParsers);
|
|
106
|
-
|
|
107
|
-
export {
|
|
108
|
-
createFilePilotRegistry,
|
|
109
|
-
builtinParsers,
|
|
110
|
-
defaultRegistry
|
|
111
|
-
};
|
package/dist/chunk-MHWH3ZGP.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
defaultRegistry
|
|
3
|
-
} from "./chunk-EQYOJW24.js";
|
|
4
|
-
|
|
5
|
-
// src/react.tsx
|
|
6
|
-
import React, { Suspense, useEffect, useMemo, useRef } from "react";
|
|
7
|
-
import { Fragment, jsx } from "react/jsx-runtime";
|
|
8
|
-
var normalizeLocale = (locale) => locale?.startsWith("en") ? "en-US" : "zh-CN";
|
|
9
|
-
var viewerCache = /* @__PURE__ */ new WeakMap();
|
|
10
|
-
var getLazyViewerEntry = (parser) => {
|
|
11
|
-
const cached = viewerCache.get(parser);
|
|
12
|
-
if (cached) return cached;
|
|
13
|
-
const entry = {
|
|
14
|
-
Viewer: React.lazy(() => parser.load().catch((error) => {
|
|
15
|
-
entry.loadError = error;
|
|
16
|
-
entry.errorListeners.forEach((listener) => listener(error));
|
|
17
|
-
throw error;
|
|
18
|
-
})),
|
|
19
|
-
errorListeners: /* @__PURE__ */ new Set()
|
|
20
|
-
};
|
|
21
|
-
viewerCache.set(parser, entry);
|
|
22
|
-
return entry;
|
|
23
|
-
};
|
|
24
|
-
var FilePilot = ({
|
|
25
|
-
file,
|
|
26
|
-
registry = defaultRegistry,
|
|
27
|
-
parserId,
|
|
28
|
-
options,
|
|
29
|
-
locale,
|
|
30
|
-
className,
|
|
31
|
-
style,
|
|
32
|
-
fallback = null,
|
|
33
|
-
unsupported = null,
|
|
34
|
-
onError
|
|
35
|
-
}) => {
|
|
36
|
-
const parser = registry.resolve(file, parserId);
|
|
37
|
-
const resolvedLocale = normalizeLocale(locale);
|
|
38
|
-
const viewerEntry = useMemo(() => parser ? getLazyViewerEntry(parser) : void 0, [parser]);
|
|
39
|
-
const onErrorRef = useRef(onError);
|
|
40
|
-
onErrorRef.current = onError;
|
|
41
|
-
useEffect(() => {
|
|
42
|
-
if (!viewerEntry) return;
|
|
43
|
-
const listener = (error) => onErrorRef.current?.(error);
|
|
44
|
-
viewerEntry.errorListeners.add(listener);
|
|
45
|
-
if (viewerEntry.loadError !== void 0) listener(viewerEntry.loadError);
|
|
46
|
-
return () => {
|
|
47
|
-
viewerEntry.errorListeners.delete(listener);
|
|
48
|
-
};
|
|
49
|
-
}, [viewerEntry]);
|
|
50
|
-
const Viewer = viewerEntry?.Viewer;
|
|
51
|
-
if (!Viewer) {
|
|
52
|
-
return /* @__PURE__ */ jsx(Fragment, { children: typeof unsupported === "function" ? unsupported(file) : unsupported });
|
|
53
|
-
}
|
|
54
|
-
return /* @__PURE__ */ jsx(Suspense, { fallback, children: /* @__PURE__ */ jsx(Viewer, { file, options, locale: resolvedLocale, className, style }) });
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
export {
|
|
58
|
-
FilePilot
|
|
59
|
-
};
|