@turinhub/atomix-common-ui 0.4.0 → 0.5.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/README.md +20 -2
- package/dist/AuthPanel-C_2JBE7t.cjs +2 -0
- package/dist/AuthPanel-C_2JBE7t.cjs.map +1 -0
- package/dist/AuthPanel-D2HFX8eN.js +656 -0
- package/dist/AuthPanel-D2HFX8eN.js.map +1 -0
- package/dist/auth.cjs +2 -0
- package/dist/auth.cjs.map +1 -0
- package/dist/auth.d.ts +11 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +9 -0
- package/dist/auth.js.map +1 -0
- package/dist/components/AuthLoginPanel.d.ts +55 -0
- package/dist/components/AuthLoginPanel.d.ts.map +1 -0
- package/dist/components/AuthPageShell.d.ts +11 -0
- package/dist/components/AuthPageShell.d.ts.map +1 -0
- package/dist/components/AuthPanel.d.ts +20 -0
- package/dist/components/AuthPanel.d.ts.map +1 -0
- package/dist/components/AuthRegisterPanel.d.ts +34 -0
- package/dist/components/AuthRegisterPanel.d.ts.map +1 -0
- package/dist/components/AuthVisualCarousel.d.ts +20 -0
- package/dist/components/AuthVisualCarousel.d.ts.map +1 -0
- package/dist/components/DataTable.d.ts +2 -2
- package/dist/components/DataTable.d.ts.map +1 -1
- package/dist/components/ImageReader.d.ts +44 -0
- package/dist/components/ImageReader.d.ts.map +1 -0
- package/dist/components/VideoReader.d.ts +39 -0
- package/dist/components/VideoReader.d.ts.map +1 -0
- package/dist/components/media-utils.d.ts +9 -0
- package/dist/components/media-utils.d.ts.map +1 -0
- package/dist/data-table.cjs +1 -1
- package/dist/data-table.cjs.map +1 -1
- package/dist/data-table.js +83 -73
- package/dist/data-table.js.map +1 -1
- package/dist/image-reader.cjs +2 -0
- package/dist/image-reader.cjs.map +1 -0
- package/dist/image-reader.d.ts +3 -0
- package/dist/image-reader.d.ts.map +1 -0
- package/dist/image-reader.js +214 -0
- package/dist/image-reader.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -2
- package/dist/index.js.map +1 -1
- package/dist/media-utils-5UPuocc1.js +23 -0
- package/dist/media-utils-5UPuocc1.js.map +1 -0
- package/dist/media-utils-X1dDYP9W.cjs +2 -0
- package/dist/media-utils-X1dDYP9W.cjs.map +1 -0
- package/dist/pdf-reader.cjs +1 -1
- package/dist/pdf-reader.cjs.map +1 -1
- package/dist/pdf-reader.js +1 -1
- package/dist/pdf-reader.js.map +1 -1
- package/dist/simple-pdf-reader.cjs +1 -1
- package/dist/simple-pdf-reader.cjs.map +1 -1
- package/dist/simple-pdf-reader.js +1 -1
- package/dist/simple-pdf-reader.js.map +1 -1
- package/dist/types/component-types.d.ts +1 -0
- package/dist/types/component-types.d.ts.map +1 -1
- package/dist/video-reader.cjs +2 -0
- package/dist/video-reader.cjs.map +1 -0
- package/dist/video-reader.d.ts +3 -0
- package/dist/video-reader.d.ts.map +1 -0
- package/dist/video-reader.js +158 -0
- package/dist/video-reader.js.map +1 -0
- package/package.json +31 -1
- package/dist/index-BiA_tnaq.cjs +0 -13
- package/dist/index-BiA_tnaq.cjs.map +0 -1
- package/dist/index-BypbGNpR.js +0 -18821
- package/dist/index-BypbGNpR.js.map +0 -1
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { j as e } from "./jsx-runtime-B4hRZ52C.js";
|
|
2
|
+
import { ZoomOut as de, ZoomIn as ue, RotateCcw as xe, RotateCw as fe, ExternalLink as pe } from "lucide-react";
|
|
3
|
+
import { useState as m, useCallback as F, useMemo as ge, useEffect as je } from "react";
|
|
4
|
+
import { c as I } from "./utils-B6yFEsav.js";
|
|
5
|
+
import { i as he, g as be } from "./media-utils-5UPuocc1.js";
|
|
6
|
+
const ve = [
|
|
7
|
+
"jpg",
|
|
8
|
+
"jpeg",
|
|
9
|
+
"png",
|
|
10
|
+
"gif",
|
|
11
|
+
"webp",
|
|
12
|
+
"svg",
|
|
13
|
+
"bmp",
|
|
14
|
+
"avif",
|
|
15
|
+
"ico"
|
|
16
|
+
], we = [
|
|
17
|
+
"image/jpeg",
|
|
18
|
+
"image/png",
|
|
19
|
+
"image/gif",
|
|
20
|
+
"image/webp",
|
|
21
|
+
"image/svg+xml",
|
|
22
|
+
"image/bmp",
|
|
23
|
+
"image/avif",
|
|
24
|
+
"image/x-icon",
|
|
25
|
+
"image/vnd.microsoft.icon"
|
|
26
|
+
], Ne = (s) => s ? s instanceof Error ? s : new Error(s) : null, Ee = (s, d, a) => Math.min(Math.max(s, d), a);
|
|
27
|
+
function Oe({
|
|
28
|
+
src: s,
|
|
29
|
+
alt: d = "",
|
|
30
|
+
fileName: a,
|
|
31
|
+
mimeType: u,
|
|
32
|
+
components: G,
|
|
33
|
+
loading: S = !1,
|
|
34
|
+
error: Z,
|
|
35
|
+
className: M,
|
|
36
|
+
containerClassName: $,
|
|
37
|
+
imageClassName: T,
|
|
38
|
+
toolbarClassName: X,
|
|
39
|
+
loadingText: Y = "正在加载图片...",
|
|
40
|
+
errorText: y = "图片加载失败",
|
|
41
|
+
unsupportedText: q = "暂不支持该图片格式",
|
|
42
|
+
showToolbar: H = !0,
|
|
43
|
+
showOpenInNewTab: J = !0,
|
|
44
|
+
objectFit: K = "contain",
|
|
45
|
+
initialScale: Q = 1,
|
|
46
|
+
minScale: x = 0.25,
|
|
47
|
+
maxScale: f = 4,
|
|
48
|
+
scaleStep: _ = 0.25,
|
|
49
|
+
scale: p,
|
|
50
|
+
onScaleChange: l,
|
|
51
|
+
rotation: g,
|
|
52
|
+
onRotationChange: c,
|
|
53
|
+
allowUnsupportedFormat: V = !1,
|
|
54
|
+
supportedExtensions: W = ve,
|
|
55
|
+
supportedMimeTypes: C = we,
|
|
56
|
+
onLoad: j,
|
|
57
|
+
onError: h,
|
|
58
|
+
style: ee,
|
|
59
|
+
...te
|
|
60
|
+
}) {
|
|
61
|
+
const { Card: k, CardContent: O, Button: P, Skeleton: b } = G || {}, [se, ne] = m(Q), [re, ie] = m(0), [ae, v] = m(!0), [oe, w] = m(null), i = p ?? se, N = g ?? re, r = Ne(Z) || oe, z = V || he({
|
|
62
|
+
src: s,
|
|
63
|
+
fileName: a,
|
|
64
|
+
mimeType: u,
|
|
65
|
+
supportedExtensions: W,
|
|
66
|
+
supportedMimeTypes: C
|
|
67
|
+
}), L = S || ae && !r, R = F(
|
|
68
|
+
(t) => {
|
|
69
|
+
const n = Ee(t, x, f);
|
|
70
|
+
p === void 0 && ne(n), l == null || l(n);
|
|
71
|
+
},
|
|
72
|
+
[p, f, x, l]
|
|
73
|
+
), U = F(
|
|
74
|
+
(t) => {
|
|
75
|
+
const n = (t % 360 + 360) % 360;
|
|
76
|
+
g === void 0 && ie(n), c == null || c(n);
|
|
77
|
+
},
|
|
78
|
+
[g, c]
|
|
79
|
+
), le = ge(() => {
|
|
80
|
+
const t = be(s, a);
|
|
81
|
+
return t ? t.toUpperCase() : u || "图片";
|
|
82
|
+
}, [a, u, s]);
|
|
83
|
+
je(() => {
|
|
84
|
+
v(!0), w(null);
|
|
85
|
+
}, [s]);
|
|
86
|
+
const o = (t, n, B, D) => {
|
|
87
|
+
const me = "inline-flex h-8 w-8 items-center justify-center rounded-md border border-input bg-background text-foreground shadow-sm transition-colors hover:bg-accent hover:text-accent-foreground disabled:pointer-events-none disabled:opacity-50";
|
|
88
|
+
return P ? /* @__PURE__ */ e.jsx(
|
|
89
|
+
P,
|
|
90
|
+
{
|
|
91
|
+
"aria-label": t,
|
|
92
|
+
className: "h-8 w-8",
|
|
93
|
+
disabled: D,
|
|
94
|
+
onClick: B,
|
|
95
|
+
size: "icon",
|
|
96
|
+
title: t,
|
|
97
|
+
type: "button",
|
|
98
|
+
variant: "outline",
|
|
99
|
+
children: n
|
|
100
|
+
}
|
|
101
|
+
) : /* @__PURE__ */ e.jsx(
|
|
102
|
+
"button",
|
|
103
|
+
{
|
|
104
|
+
"aria-label": t,
|
|
105
|
+
className: me,
|
|
106
|
+
disabled: D,
|
|
107
|
+
onClick: B,
|
|
108
|
+
title: t,
|
|
109
|
+
type: "button",
|
|
110
|
+
children: n
|
|
111
|
+
}
|
|
112
|
+
);
|
|
113
|
+
}, ce = () => /* @__PURE__ */ e.jsx("div", { className: "w-full space-y-3 p-4", role: "status", "aria-live": "polite", children: b ? /* @__PURE__ */ e.jsxs(e.Fragment, { children: [
|
|
114
|
+
/* @__PURE__ */ e.jsx(b, { className: "h-4 w-32" }),
|
|
115
|
+
/* @__PURE__ */ e.jsx(b, { className: "h-80 w-full" })
|
|
116
|
+
] }) : /* @__PURE__ */ e.jsx("p", { className: "text-sm text-muted-foreground", children: Y }) }), A = (t) => /* @__PURE__ */ e.jsxs("div", { className: "p-4 text-center text-sm text-destructive", role: "alert", children: [
|
|
117
|
+
/* @__PURE__ */ e.jsx("p", { className: "font-medium", children: t || y }),
|
|
118
|
+
r != null && r.message ? /* @__PURE__ */ e.jsx("p", { className: "mt-1 opacity-80", children: r.message }) : null
|
|
119
|
+
] }), E = /* @__PURE__ */ e.jsxs(
|
|
120
|
+
"div",
|
|
121
|
+
{
|
|
122
|
+
className: I(
|
|
123
|
+
"flex h-full min-h-[360px] flex-col overflow-hidden rounded-md border bg-background",
|
|
124
|
+
$
|
|
125
|
+
),
|
|
126
|
+
children: [
|
|
127
|
+
H ? /* @__PURE__ */ e.jsxs(
|
|
128
|
+
"div",
|
|
129
|
+
{
|
|
130
|
+
className: I(
|
|
131
|
+
"flex flex-wrap items-center justify-between gap-2 border-b px-3 py-2",
|
|
132
|
+
X
|
|
133
|
+
),
|
|
134
|
+
children: [
|
|
135
|
+
/* @__PURE__ */ e.jsx("span", { className: "text-xs font-medium text-muted-foreground", children: le }),
|
|
136
|
+
/* @__PURE__ */ e.jsxs("div", { className: "flex items-center gap-1", children: [
|
|
137
|
+
o(
|
|
138
|
+
"缩小",
|
|
139
|
+
/* @__PURE__ */ e.jsx(de, { className: "h-4 w-4" }),
|
|
140
|
+
() => R(i - _),
|
|
141
|
+
i <= x
|
|
142
|
+
),
|
|
143
|
+
/* @__PURE__ */ e.jsxs("span", { className: "min-w-14 text-center text-xs text-muted-foreground", children: [
|
|
144
|
+
Math.round(i * 100),
|
|
145
|
+
"%"
|
|
146
|
+
] }),
|
|
147
|
+
o(
|
|
148
|
+
"放大",
|
|
149
|
+
/* @__PURE__ */ e.jsx(ue, { className: "h-4 w-4" }),
|
|
150
|
+
() => R(i + _),
|
|
151
|
+
i >= f
|
|
152
|
+
),
|
|
153
|
+
o(
|
|
154
|
+
"向左旋转",
|
|
155
|
+
/* @__PURE__ */ e.jsx(xe, { className: "h-4 w-4" }),
|
|
156
|
+
() => U(N - 90)
|
|
157
|
+
),
|
|
158
|
+
o(
|
|
159
|
+
"向右旋转",
|
|
160
|
+
/* @__PURE__ */ e.jsx(fe, { className: "h-4 w-4" }),
|
|
161
|
+
() => U(N + 90)
|
|
162
|
+
),
|
|
163
|
+
J ? o(
|
|
164
|
+
"新窗口打开",
|
|
165
|
+
/* @__PURE__ */ e.jsx(pe, { className: "h-4 w-4" }),
|
|
166
|
+
() => window.open(s, "_blank", "noreferrer")
|
|
167
|
+
) : null
|
|
168
|
+
] })
|
|
169
|
+
]
|
|
170
|
+
}
|
|
171
|
+
) : null,
|
|
172
|
+
/* @__PURE__ */ e.jsxs("div", { className: "relative flex min-h-0 flex-1 items-center justify-center overflow-auto bg-muted/20 p-4", children: [
|
|
173
|
+
z ? r ? A() : null : A(q),
|
|
174
|
+
z && !r ? /* @__PURE__ */ e.jsxs(e.Fragment, { children: [
|
|
175
|
+
L ? ce() : null,
|
|
176
|
+
/* @__PURE__ */ e.jsx(
|
|
177
|
+
"img",
|
|
178
|
+
{
|
|
179
|
+
...te,
|
|
180
|
+
alt: d,
|
|
181
|
+
className: I(
|
|
182
|
+
"max-h-full max-w-full transition-transform",
|
|
183
|
+
L ? "invisible absolute" : "visible",
|
|
184
|
+
T
|
|
185
|
+
),
|
|
186
|
+
onError: () => {
|
|
187
|
+
const t = new Error(y);
|
|
188
|
+
v(!1), w(t), h == null || h(t);
|
|
189
|
+
},
|
|
190
|
+
onLoad: () => {
|
|
191
|
+
v(!1), w(null), j == null || j();
|
|
192
|
+
},
|
|
193
|
+
src: s,
|
|
194
|
+
style: {
|
|
195
|
+
objectFit: K,
|
|
196
|
+
transform: `scale(${i}) rotate(${N}deg)`,
|
|
197
|
+
transformOrigin: "center center",
|
|
198
|
+
...ee
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
)
|
|
202
|
+
] }) : null
|
|
203
|
+
] })
|
|
204
|
+
]
|
|
205
|
+
}
|
|
206
|
+
);
|
|
207
|
+
return k ? /* @__PURE__ */ e.jsx(k, { className: M, children: O ? /* @__PURE__ */ e.jsx(O, { children: E }) : E }) : /* @__PURE__ */ e.jsx("div", { className: M, children: E });
|
|
208
|
+
}
|
|
209
|
+
export {
|
|
210
|
+
Oe as ImageReader,
|
|
211
|
+
ve as SUPPORTED_IMAGE_EXTENSIONS,
|
|
212
|
+
we as SUPPORTED_IMAGE_MIME_TYPES
|
|
213
|
+
};
|
|
214
|
+
//# sourceMappingURL=image-reader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image-reader.js","sources":["../src/components/ImageReader.tsx"],"sourcesContent":["import {\n ExternalLink as ExternalLinkIcon,\n RotateCcw as RotateCcwIcon,\n RotateCw as RotateCwIcon,\n ZoomIn as ZoomInIcon,\n ZoomOut as ZoomOutIcon,\n} from 'lucide-react';\nimport { useCallback, useEffect, useMemo, useState } from 'react';\nimport type { HTMLAttributes, ImgHTMLAttributes, ReactNode } from 'react';\n\nimport { cn } from '../lib/utils';\nimport type {\n ButtonComponent,\n CardComponent,\n SkeletonComponent,\n UIComponent,\n} from '../types/component-types';\n\nimport { getMediaExtension, isSupportedMediaSource } from './media-utils';\n\nexport const SUPPORTED_IMAGE_EXTENSIONS = [\n 'jpg',\n 'jpeg',\n 'png',\n 'gif',\n 'webp',\n 'svg',\n 'bmp',\n 'avif',\n 'ico',\n] as const;\n\nexport const SUPPORTED_IMAGE_MIME_TYPES = [\n 'image/jpeg',\n 'image/png',\n 'image/gif',\n 'image/webp',\n 'image/svg+xml',\n 'image/bmp',\n 'image/avif',\n 'image/x-icon',\n 'image/vnd.microsoft.icon',\n] as const;\n\nexport interface ImageReaderUIComponents {\n Card?: CardComponent;\n CardContent?: UIComponent<HTMLAttributes<HTMLDivElement>>;\n Button?: ButtonComponent;\n Skeleton?: SkeletonComponent;\n}\n\nexport interface ImageReaderProps\n extends Omit<\n ImgHTMLAttributes<HTMLImageElement>,\n | 'alt'\n | 'children'\n | 'className'\n | 'loading'\n | 'onError'\n | 'onLoad'\n | 'src'\n > {\n src: string;\n alt?: string;\n fileName?: string;\n mimeType?: string;\n components?: ImageReaderUIComponents;\n loading?: boolean;\n error?: Error | string | null;\n className?: string;\n containerClassName?: string;\n imageClassName?: string;\n toolbarClassName?: string;\n loadingText?: string;\n errorText?: string;\n unsupportedText?: string;\n showToolbar?: boolean;\n showOpenInNewTab?: boolean;\n objectFit?: 'contain' | 'cover' | 'fill' | 'none' | 'scale-down';\n initialScale?: number;\n minScale?: number;\n maxScale?: number;\n scaleStep?: number;\n scale?: number;\n onScaleChange?: (scale: number) => void;\n rotation?: number;\n onRotationChange?: (rotation: number) => void;\n allowUnsupportedFormat?: boolean;\n supportedExtensions?: readonly string[];\n supportedMimeTypes?: readonly string[];\n onLoad?: () => void;\n onError?: (error: Error) => void;\n}\n\nconst normalizeError = (error: Error | string | null | undefined) => {\n if (!error) return null;\n return error instanceof Error ? error : new Error(error);\n};\n\nconst clamp = (value: number, min: number, max: number) =>\n Math.min(Math.max(value, min), max);\n\nexport function ImageReader({\n src,\n alt = '',\n fileName,\n mimeType,\n components,\n loading = false,\n error,\n className,\n containerClassName,\n imageClassName,\n toolbarClassName,\n loadingText = '正在加载图片...',\n errorText = '图片加载失败',\n unsupportedText = '暂不支持该图片格式',\n showToolbar = true,\n showOpenInNewTab = true,\n objectFit = 'contain',\n initialScale = 1,\n minScale = 0.25,\n maxScale = 4,\n scaleStep = 0.25,\n scale: controlledScale,\n onScaleChange,\n rotation: controlledRotation,\n onRotationChange,\n allowUnsupportedFormat = false,\n supportedExtensions = SUPPORTED_IMAGE_EXTENSIONS,\n supportedMimeTypes = SUPPORTED_IMAGE_MIME_TYPES,\n onLoad,\n onError,\n style,\n ...imageProps\n}: ImageReaderProps) {\n const { Card, CardContent, Button, Skeleton } = components || {};\n const [internalScale, setInternalScale] = useState(initialScale);\n const [internalRotation, setInternalRotation] = useState(0);\n const [isImageLoading, setIsImageLoading] = useState(true);\n const [imageError, setImageError] = useState<Error | null>(null);\n\n const scale = controlledScale ?? internalScale;\n const rotation = controlledRotation ?? internalRotation;\n const displayedError = normalizeError(error) || imageError;\n const isSupported =\n allowUnsupportedFormat ||\n isSupportedMediaSource({\n src,\n fileName,\n mimeType,\n supportedExtensions,\n supportedMimeTypes,\n });\n const isLoading = loading || (isImageLoading && !displayedError);\n\n const setNextScale = useCallback(\n (nextScale: number) => {\n const clampedScale = clamp(nextScale, minScale, maxScale);\n if (controlledScale === undefined) {\n setInternalScale(clampedScale);\n }\n onScaleChange?.(clampedScale);\n },\n [controlledScale, maxScale, minScale, onScaleChange]\n );\n\n const setNextRotation = useCallback(\n (nextRotation: number) => {\n const normalizedRotation = ((nextRotation % 360) + 360) % 360;\n if (controlledRotation === undefined) {\n setInternalRotation(normalizedRotation);\n }\n onRotationChange?.(normalizedRotation);\n },\n [controlledRotation, onRotationChange]\n );\n\n const formatLabel = useMemo(() => {\n const extension = getMediaExtension(src, fileName);\n return extension ? extension.toUpperCase() : mimeType || '图片';\n }, [fileName, mimeType, src]);\n\n useEffect(() => {\n setIsImageLoading(true);\n setImageError(null);\n }, [src]);\n\n const renderButton = (\n label: string,\n icon: ReactNode,\n onClick: () => void,\n disabled?: boolean\n ) => {\n const buttonClassName =\n 'inline-flex h-8 w-8 items-center justify-center rounded-md border border-input bg-background text-foreground shadow-sm transition-colors hover:bg-accent hover:text-accent-foreground disabled:pointer-events-none disabled:opacity-50';\n\n if (Button) {\n return (\n <Button\n aria-label={label}\n className=\"h-8 w-8\"\n disabled={disabled}\n onClick={onClick}\n size=\"icon\"\n title={label}\n type=\"button\"\n variant=\"outline\"\n >\n {icon}\n </Button>\n );\n }\n\n return (\n <button\n aria-label={label}\n className={buttonClassName}\n disabled={disabled}\n onClick={onClick}\n title={label}\n type=\"button\"\n >\n {icon}\n </button>\n );\n };\n\n const renderLoading = () => (\n <div className=\"w-full space-y-3 p-4\" role=\"status\" aria-live=\"polite\">\n {Skeleton ? (\n <>\n <Skeleton className=\"h-4 w-32\" />\n <Skeleton className=\"h-80 w-full\" />\n </>\n ) : (\n <p className=\"text-sm text-muted-foreground\">{loadingText}</p>\n )}\n </div>\n );\n\n const renderError = (message?: string) => (\n <div className=\"p-4 text-center text-sm text-destructive\" role=\"alert\">\n <p className=\"font-medium\">{message || errorText}</p>\n {displayedError?.message ? (\n <p className=\"mt-1 opacity-80\">{displayedError.message}</p>\n ) : null}\n </div>\n );\n\n const body = (\n <div\n className={cn(\n 'flex h-full min-h-[360px] flex-col overflow-hidden rounded-md border bg-background',\n containerClassName\n )}\n >\n {showToolbar ? (\n <div\n className={cn(\n 'flex flex-wrap items-center justify-between gap-2 border-b px-3 py-2',\n toolbarClassName\n )}\n >\n <span className=\"text-xs font-medium text-muted-foreground\">\n {formatLabel}\n </span>\n <div className=\"flex items-center gap-1\">\n {renderButton(\n '缩小',\n <ZoomOutIcon className=\"h-4 w-4\" />,\n () => setNextScale(scale - scaleStep),\n scale <= minScale\n )}\n <span className=\"min-w-14 text-center text-xs text-muted-foreground\">\n {Math.round(scale * 100)}%\n </span>\n {renderButton(\n '放大',\n <ZoomInIcon className=\"h-4 w-4\" />,\n () => setNextScale(scale + scaleStep),\n scale >= maxScale\n )}\n {renderButton(\n '向左旋转',\n <RotateCcwIcon className=\"h-4 w-4\" />,\n () => setNextRotation(rotation - 90)\n )}\n {renderButton(\n '向右旋转',\n <RotateCwIcon className=\"h-4 w-4\" />,\n () => setNextRotation(rotation + 90)\n )}\n {showOpenInNewTab\n ? renderButton(\n '新窗口打开',\n <ExternalLinkIcon className=\"h-4 w-4\" />,\n () => window.open(src, '_blank', 'noreferrer')\n )\n : null}\n </div>\n </div>\n ) : null}\n <div className=\"relative flex min-h-0 flex-1 items-center justify-center overflow-auto bg-muted/20 p-4\">\n {!isSupported\n ? renderError(unsupportedText)\n : displayedError\n ? renderError()\n : null}\n {isSupported && !displayedError ? (\n <>\n {isLoading ? renderLoading() : null}\n <img\n {...imageProps}\n alt={alt}\n className={cn(\n 'max-h-full max-w-full transition-transform',\n isLoading ? 'invisible absolute' : 'visible',\n imageClassName\n )}\n onError={() => {\n const nextError = new Error(errorText);\n setIsImageLoading(false);\n setImageError(nextError);\n onError?.(nextError);\n }}\n onLoad={() => {\n setIsImageLoading(false);\n setImageError(null);\n onLoad?.();\n }}\n src={src}\n style={{\n objectFit,\n transform: `scale(${scale}) rotate(${rotation}deg)`,\n transformOrigin: 'center center',\n ...style,\n }}\n />\n </>\n ) : null}\n </div>\n </div>\n );\n\n if (Card) {\n return (\n <Card className={className}>\n {CardContent ? <CardContent>{body}</CardContent> : body}\n </Card>\n );\n }\n\n return <div className={className}>{body}</div>;\n}\n"],"names":["SUPPORTED_IMAGE_EXTENSIONS","SUPPORTED_IMAGE_MIME_TYPES","normalizeError","error","clamp","value","min","max","ImageReader","src","alt","fileName","mimeType","components","loading","className","containerClassName","imageClassName","toolbarClassName","loadingText","errorText","unsupportedText","showToolbar","showOpenInNewTab","objectFit","initialScale","minScale","maxScale","scaleStep","controlledScale","onScaleChange","controlledRotation","onRotationChange","allowUnsupportedFormat","supportedExtensions","supportedMimeTypes","onLoad","onError","style","imageProps","Card","CardContent","Button","Skeleton","internalScale","setInternalScale","useState","internalRotation","setInternalRotation","isImageLoading","setIsImageLoading","imageError","setImageError","scale","rotation","displayedError","isSupported","isSupportedMediaSource","isLoading","setNextScale","useCallback","nextScale","clampedScale","setNextRotation","nextRotation","normalizedRotation","formatLabel","useMemo","extension","getMediaExtension","useEffect","renderButton","label","icon","onClick","disabled","buttonClassName","jsx","renderLoading","jsxs","Fragment","renderError","message","body","cn","ZoomOutIcon","ZoomInIcon","RotateCcwIcon","RotateCwIcon","ExternalLinkIcon","nextError"],"mappings":";;;;;AAoBO,MAAMA,KAA6B;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAEaC,KAA6B;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAoDMC,KAAiB,CAACC,MACjBA,IACEA,aAAiB,QAAQA,IAAQ,IAAI,MAAMA,CAAK,IADpC,MAIfC,KAAQ,CAACC,GAAeC,GAAaC,MACzC,KAAK,IAAI,KAAK,IAAIF,GAAOC,CAAG,GAAGC,CAAG;AAE7B,SAASC,GAAY;AAAA,EAC1B,KAAAC;AAAA,EACA,KAAAC,IAAM;AAAA,EACN,UAAAC;AAAA,EACA,UAAAC;AAAA,EACA,YAAAC;AAAA,EACA,SAAAC,IAAU;AAAA,EACV,OAAAX;AAAA,EACA,WAAAY;AAAA,EACA,oBAAAC;AAAA,EACA,gBAAAC;AAAA,EACA,kBAAAC;AAAA,EACA,aAAAC,IAAc;AAAA,EACd,WAAAC,IAAY;AAAA,EACZ,iBAAAC,IAAkB;AAAA,EAClB,aAAAC,IAAc;AAAA,EACd,kBAAAC,IAAmB;AAAA,EACnB,WAAAC,IAAY;AAAA,EACZ,cAAAC,IAAe;AAAA,EACf,UAAAC,IAAW;AAAA,EACX,UAAAC,IAAW;AAAA,EACX,WAAAC,IAAY;AAAA,EACZ,OAAOC;AAAA,EACP,eAAAC;AAAA,EACA,UAAUC;AAAA,EACV,kBAAAC;AAAA,EACA,wBAAAC,IAAyB;AAAA,EACzB,qBA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;AAAA,UACF,EAAA,CACF,IACE;AAAA,QAAA,EAAA,CACN;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAIJ,SAAIE,IAEAqC,gBAAAA,EAAAA,IAACrC,KAAK,WAAAzB,GACH,UAAA0B,0BAAeA,GAAA,EAAa,UAAA0C,EAAA,CAAK,IAAiBA,EAAA,CACrD,IAIGN,gBAAAA,EAAAA,IAAC,OAAA,EAAI,WAAA9D,GAAuB,UAAAoE,EAAA,CAAK;AAC1C;"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./utils-IjLH3w2e.cjs"),e=require("./AuthPanel-C_2JBE7t.cjs");exports.cn=t.cn;exports.AuthLoginPanel=e.AuthLoginPanel;exports.AuthPageShell=e.AuthPageShell;exports.AuthPanel=e.AuthPanel;exports.AuthRegisterPanel=e.AuthRegisterPanel;exports.AuthVisualCarousel=e.AuthVisualCarousel;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
1
|
export { cn } from './lib/utils';
|
|
2
|
+
export { AuthLoginPanel } from './components/AuthLoginPanel';
|
|
3
|
+
export type { AuthLoginMethod, AuthLoginPanelProps, AuthPasswordLoginPayload, AuthSmsCodeResult, AuthSmsLoginPayload, AuthSocialProvider, AuthUIComponents, AuthValidationResult, } from './components/AuthLoginPanel';
|
|
4
|
+
export { AuthRegisterPanel } from './components/AuthRegisterPanel';
|
|
5
|
+
export type { AuthRegisterPanelProps, AuthRegisterPayload, } from './components/AuthRegisterPanel';
|
|
6
|
+
export { AuthPageShell } from './components/AuthPageShell';
|
|
7
|
+
export type { AuthPageShellProps } from './components/AuthPageShell';
|
|
8
|
+
export { AuthVisualCarousel } from './components/AuthVisualCarousel';
|
|
9
|
+
export type { AuthVisualCarouselItem, AuthVisualCarouselProps, } from './components/AuthVisualCarousel';
|
|
10
|
+
export { AuthPanel } from './components/AuthPanel';
|
|
11
|
+
export type { AuthPanelMode, AuthPanelProps } from './components/AuthPanel';
|
|
2
12
|
export type { UIComponent, ButtonComponent, InputComponent, CardComponent, TableComponent, TableRowComponent, TableCellComponent, SelectComponent, SelectTriggerComponent, SelectContentComponent, SelectItemComponent, SelectValueComponent, DialogComponent, DialogContentComponent, DialogHeaderComponent, DialogFooterComponent, DialogTitleComponent, DialogDescriptionComponent, LabelComponent, DropdownMenuComponent, DropdownMenuTriggerComponent, DropdownMenuContentComponent, DropdownMenuRadioGroupComponent, DropdownMenuRadioItemComponent, SkeletonComponent, TabsComponent, TabsListComponent, TabsTriggerComponent, TabsContentComponent, ScrollAreaComponent, } from './types/component-types';
|
|
3
13
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAGjC,YAAY,EACV,WAAW,EACX,eAAe,EACf,cAAc,EACd,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,sBAAsB,EACtB,sBAAsB,EACtB,mBAAmB,EACnB,oBAAoB,EACpB,eAAe,EACf,sBAAsB,EACtB,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,0BAA0B,EAC1B,cAAc,EACd,qBAAqB,EACrB,4BAA4B,EAC5B,4BAA4B,EAC5B,+BAA+B,EAC/B,8BAA8B,EAC9B,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":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|
+
import { c as s } from "./utils-B6yFEsav.js";
|
|
2
|
+
import { A as l, a as u, b as h, c as o, d as r } from "./AuthPanel-D2HFX8eN.js";
|
|
2
3
|
export {
|
|
3
|
-
|
|
4
|
+
l as AuthLoginPanel,
|
|
5
|
+
u as AuthPageShell,
|
|
6
|
+
h as AuthPanel,
|
|
7
|
+
o as AuthRegisterPanel,
|
|
8
|
+
r as AuthVisualCarousel,
|
|
9
|
+
s as cn
|
|
4
10
|
};
|
|
5
11
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const a = (s, e) => {
|
|
2
|
+
const t = e || s;
|
|
3
|
+
if (!t) return "";
|
|
4
|
+
const n = t.split(/[?#]/)[0] || "", o = n.split(".").pop();
|
|
5
|
+
return !o || o === n ? "" : o.toLowerCase();
|
|
6
|
+
}, c = ({
|
|
7
|
+
src: s,
|
|
8
|
+
fileName: e,
|
|
9
|
+
mimeType: t,
|
|
10
|
+
supportedExtensions: n,
|
|
11
|
+
supportedMimeTypes: o
|
|
12
|
+
}) => {
|
|
13
|
+
const i = t == null ? void 0 : t.toLowerCase();
|
|
14
|
+
if (i && o.some((r) => i === r))
|
|
15
|
+
return !0;
|
|
16
|
+
const u = a(s, e);
|
|
17
|
+
return u ? n.some((r) => r === u) : !t;
|
|
18
|
+
};
|
|
19
|
+
export {
|
|
20
|
+
a as g,
|
|
21
|
+
c as i
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=media-utils-5UPuocc1.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media-utils-5UPuocc1.js","sources":["../src/components/media-utils.ts"],"sourcesContent":["export const getMediaExtension = (src?: string, fileName?: string) => {\n const candidate = fileName || src;\n if (!candidate) return '';\n\n const withoutQuery = candidate.split(/[?#]/)[0] || '';\n const extension = withoutQuery.split('.').pop();\n\n if (!extension || extension === withoutQuery) return '';\n\n return extension.toLowerCase();\n};\n\nexport const isSupportedMediaSource = ({\n src,\n fileName,\n mimeType,\n supportedExtensions,\n supportedMimeTypes,\n}: {\n src?: string;\n fileName?: string;\n mimeType?: string;\n supportedExtensions: readonly string[];\n supportedMimeTypes: readonly string[];\n}) => {\n const normalizedMimeType = mimeType?.toLowerCase();\n\n if (\n normalizedMimeType &&\n supportedMimeTypes.some((type) => normalizedMimeType === type)\n ) {\n return true;\n }\n\n const extension = getMediaExtension(src, fileName);\n\n return extension\n ? supportedExtensions.some((supported) => supported === extension)\n : !mimeType;\n};\n"],"names":["getMediaExtension","src","fileName","candidate","withoutQuery","extension","isSupportedMediaSource","mimeType","supportedExtensions","supportedMimeTypes","normalizedMimeType","type","supported"],"mappings":"AAAO,MAAMA,IAAoB,CAACC,GAAcC,MAAsB;AACpE,QAAMC,IAAYD,KAAYD;AAC9B,MAAI,CAACE,EAAW,QAAO;AAEvB,QAAMC,IAAeD,EAAU,MAAM,MAAM,EAAE,CAAC,KAAK,IAC7CE,IAAYD,EAAa,MAAM,GAAG,EAAE,IAAA;AAE1C,SAAI,CAACC,KAAaA,MAAcD,IAAqB,KAE9CC,EAAU,YAAA;AACnB,GAEaC,IAAyB,CAAC;AAAA,EACrC,KAAAL;AAAA,EACA,UAAAC;AAAA,EACA,UAAAK;AAAA,EACA,qBAAAC;AAAA,EACA,oBAAAC;AACF,MAMM;AACJ,QAAMC,IAAqBH,KAAA,gBAAAA,EAAU;AAErC,MACEG,KACAD,EAAmB,KAAK,CAACE,MAASD,MAAuBC,CAAI;AAE7D,WAAO;AAGT,QAAMN,IAAYL,EAAkBC,GAAKC,CAAQ;AAEjD,SAAOG,IACHG,EAAoB,KAAK,CAACI,MAAcA,MAAcP,CAAS,IAC/D,CAACE;AACP;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";const c=(n,s)=>{const t=s||n;if(!t)return"";const o=t.split(/[?#]/)[0]||"",e=o.split(".").pop();return!e||e===o?"":e.toLowerCase()},a=({src:n,fileName:s,mimeType:t,supportedExtensions:o,supportedMimeTypes:e})=>{const i=t==null?void 0:t.toLowerCase();if(i&&e.some(r=>i===r))return!0;const u=c(n,s);return u?o.some(r=>r===u):!t};exports.getMediaExtension=c;exports.isSupportedMediaSource=a;
|
|
2
|
+
//# sourceMappingURL=media-utils-X1dDYP9W.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media-utils-X1dDYP9W.cjs","sources":["../src/components/media-utils.ts"],"sourcesContent":["export const getMediaExtension = (src?: string, fileName?: string) => {\n const candidate = fileName || src;\n if (!candidate) return '';\n\n const withoutQuery = candidate.split(/[?#]/)[0] || '';\n const extension = withoutQuery.split('.').pop();\n\n if (!extension || extension === withoutQuery) return '';\n\n return extension.toLowerCase();\n};\n\nexport const isSupportedMediaSource = ({\n src,\n fileName,\n mimeType,\n supportedExtensions,\n supportedMimeTypes,\n}: {\n src?: string;\n fileName?: string;\n mimeType?: string;\n supportedExtensions: readonly string[];\n supportedMimeTypes: readonly string[];\n}) => {\n const normalizedMimeType = mimeType?.toLowerCase();\n\n if (\n normalizedMimeType &&\n supportedMimeTypes.some((type) => normalizedMimeType === type)\n ) {\n return true;\n }\n\n const extension = getMediaExtension(src, fileName);\n\n return extension\n ? supportedExtensions.some((supported) => supported === extension)\n : !mimeType;\n};\n"],"names":["getMediaExtension","src","fileName","candidate","withoutQuery","extension","isSupportedMediaSource","mimeType","supportedExtensions","supportedMimeTypes","normalizedMimeType","type","supported"],"mappings":"aAAO,MAAMA,EAAoB,CAACC,EAAcC,IAAsB,CACpE,MAAMC,EAAYD,GAAYD,EAC9B,GAAI,CAACE,EAAW,MAAO,GAEvB,MAAMC,EAAeD,EAAU,MAAM,MAAM,EAAE,CAAC,GAAK,GAC7CE,EAAYD,EAAa,MAAM,GAAG,EAAE,IAAA,EAE1C,MAAI,CAACC,GAAaA,IAAcD,EAAqB,GAE9CC,EAAU,YAAA,CACnB,EAEaC,EAAyB,CAAC,CACrC,IAAAL,EACA,SAAAC,EACA,SAAAK,EACA,oBAAAC,EACA,mBAAAC,CACF,IAMM,CACJ,MAAMC,EAAqBH,GAAA,YAAAA,EAAU,cAErC,GACEG,GACAD,EAAmB,KAAME,GAASD,IAAuBC,CAAI,EAE7D,MAAO,GAGT,MAAMN,EAAYL,EAAkBC,EAAKC,CAAQ,EAEjD,OAAOG,EACHG,EAAoB,KAAMI,GAAcA,IAAcP,CAAS,EAC/D,CAACE,CACP"}
|
package/dist/pdf-reader.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./jsx-runtime-BB_1_6y_.cjs"),x=require("lucide-react"),n=require("react"),_e=require("./PDFSidebar-Di0D-yPS.cjs");function Be(f,h){const R=n.useRef(void 0);return n.useCallback((...I)=>{R.current&&clearTimeout(R.current),R.current=setTimeout(()=>f(...I),h)},[f,h])}function Ve({url:f,initialPage:h=1,initialScale:R=1,initialRotation:I=0,currentPage:J,onPageChange:C,scale:O,onScaleChange:w,rotation:$,onRotationChange:D,minScale:W=.5,maxScale:L=2.5,showToolbar:ue=!0,showSidebar:E=!0,showRotation:ae=!0,showModeToggle:xe=!0,showFullscreen:me=!0,enableHotkeys:Q=!0,enableMobileNav:de=!0,displayMode:fe="single",className:pe,toolbarClassName:je,contentClassName:he,contentHeight:Ee="80vh",pageClassName:H,workerUrl:q,cMapUrl:g,standardFontDataUrl:k,components:u,onLoadSuccess:P,onLoadError:p,onPageRender:v,loadingText:ve="正在加载PDF文档...",errorText:U="PDF加载失败"}){const[ee,G]=n.useState(null),[be,K]=n.useState(h),[Re,ge]=n.useState(R),[ke,ye]=n.useState(I),[Te,S]=n.useState(!1),[y,M]=n.useState(null),[m,_]=n.useState(0),[te,B]=n.useState(!1),[T,se]=n.useState(fe==="scroll"),[V,ne]=n.useState(E);n.useEffect(()=>{ne(E)},[E]);const[re,Ne]=n.useState(void 0),[ie,Ce]=n.useState(null),le=n.useRef(null),F=n.useRef(null),Z=n.useRef(new Map),i=J??be,j=O??Re,z=$??ke,b=J!==void 0,o=T,{Card:we,CardContent:De,Button:d,Input:Pe,Skeleton:Se}=u||{};n.useEffect(()=>{G(null),_(0),M(null),S(!1),b||K(Math.max(1,h))},[f,h,b]);const Me=n.useMemo(()=>{const e={withCredentials:!1};return g&&(e.cMapUrl=g,e.cMapPacked=!0),k&&(e.standardFontDataUrl=k),e},[g,k]);n.useEffect(()=>{let e=!0;return(async()=>{try{const l=await Promise.resolve().then(()=>require("./index-BiA_tnaq.cjs"));if(typeof window<"u"){const r=l.pdfjs,c=r==null?void 0:r.version;r!=null&&r.GlobalWorkerOptions&&c&&(q?r.GlobalWorkerOptions.workerSrc=q:r.GlobalWorkerOptions.workerSrc=`https://cdn.jsdelivr.net/npm/pdfjs-dist@${c}/build/pdf.worker.min.mjs`,!g&&r.GlobalWorkerOptions&&(r.GlobalWorkerOptions.cMapUrl=`https://unpkg.com/pdfjs-dist@${c}/cmaps/`),!k&&r.GlobalWorkerOptions&&(r.GlobalWorkerOptions.standardFontDataUrl=`https://unpkg.com/pdfjs-dist@${c}/standard_fonts/`))}e&&Ce(l)}catch(l){if(e){const r=l instanceof Error?l:new Error("无法加载 react-pdf 库");M(r),S(!1),p==null||p(r)}}})(),()=>{e=!1}},[q,g,k,p]);const Fe=n.useCallback(e=>{console.error("PDF加载失败:",e),console.error("PDF URL:",f),G(null),_(0),M(new Error(`${U}: ${e.message||"请检查文件路径或网络连接"}`)),S(!1),p==null||p(e)},[f,U,p]),ze=n.useCallback(e=>{G(e),_(e.numPages),M(null),S(!1),b||K(s=>Math.max(1,Math.min(s,Math.max(e.numPages,1)))),P==null||P(e)},[b,P]),a=n.useCallback(e=>{if(!Number.isFinite(e))return;const s=m>0?Math.max(1,Math.min(Math.trunc(e),m)):Math.max(1,Math.trunc(e));b||K(s),s!==i&&(C==null||C(s))},[m,b,i,C]),Ae=n.useCallback((e,s)=>{s?Z.current.set(e,s):Z.current.delete(e)},[]),Ie=n.useCallback(()=>{const e=F.current;if(!e||!o||m<=0)return;const s=e.getBoundingClientRect().top;let l=i,r=Number.POSITIVE_INFINITY;Z.current.forEach((c,A)=>{const oe=Math.abs(c.getBoundingClientRect().top-s);oe<r&&(r=oe,l=A)}),l!==i&&a(l)},[i,a,o,m]),N=n.useCallback(e=>{const s=Math.max(W,Math.min(L,j+e));O===void 0&&ge(s),w==null||w(s)},[j,W,L,O,w]),Oe=n.useCallback(()=>{const e=(z+90)%360;$===void 0&&ye(e),D==null||D(e)},[z,$,D]),ce=Be(e=>{Ne(e)},100);n.useEffect(()=>{if(!F.current)return;const e=F.current,s=()=>{ce(e.clientWidth)};s();const l=new ResizeObserver(()=>{s()});return l.observe(e),()=>{l.disconnect()}},[ce]),n.useEffect(()=>{if(!Q)return;const e=s=>{const l=s.target,r=typeof document<"u"?document.activeElement:null,c=l||r,A=c==null?void 0:c.getAttribute("role");c&&(c.tagName==="INPUT"||c.tagName==="TEXTAREA"||c.tagName==="SELECT"||c.isContentEditable||A==="textbox"||A==="spinbutton")||((s.ctrlKey||s.metaKey)&&(s.key==="="||s.key==="+")?(s.preventDefault(),N(.1)):(s.ctrlKey||s.metaKey)&&s.key==="-"?(s.preventDefault(),N(-.1)):!o&&s.key==="ArrowLeft"?(s.preventDefault(),a(i-1)):!o&&s.key==="ArrowRight"&&(s.preventDefault(),a(i+1)))};return document.addEventListener("keydown",e),()=>{document.removeEventListener("keydown",e)}},[Q,i,a,o,N]);const $e=n.useCallback(async()=>{var e,s;if(!(typeof document>"u"))if(document.fullscreenElement)document.exitFullscreen&&(await document.exitFullscreen(),B(!1));else try{await((s=(e=le.current)==null?void 0:e.requestFullscreen)==null?void 0:s.call(e)),B(!0)}catch(l){console.error("Error attempting to enable fullscreen:",l)}},[]);n.useEffect(()=>{if(typeof document>"u")return;const e=()=>{B(!!document.fullscreenElement)};return document.addEventListener("fullscreenchange",e),()=>{document.removeEventListener("fullscreenchange",e)}},[]);const We=n.useCallback(e=>{a(e),se(!1)},[a]),Le=()=>ue?t.jsxRuntimeExports.jsxs("div",{className:`flex items-center justify-between gap-4 border-b px-4 py-2 ${je||""}`,children:[t.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[E&&t.jsxRuntimeExports.jsx(d,{variant:"outline",size:"icon",onClick:()=>ne(!V),title:V?"隐藏侧边栏":"显示侧边栏",children:t.jsxRuntimeExports.jsx(x.PanelLeft,{})}),t.jsxRuntimeExports.jsx(d,{variant:"outline",size:"icon",onClick:()=>N(-.1),disabled:j<=W,children:t.jsxRuntimeExports.jsx(x.ZoomOut,{})}),t.jsxRuntimeExports.jsxs("span",{className:"min-w-[3rem] text-center text-sm",children:[Math.round(j*100),"%"]}),t.jsxRuntimeExports.jsx(d,{variant:"outline",size:"icon",onClick:()=>N(.1),disabled:j>=L,children:t.jsxRuntimeExports.jsx(x.ZoomIn,{})}),ae&&t.jsxRuntimeExports.jsx(d,{variant:"outline",size:"icon",onClick:Oe,children:t.jsxRuntimeExports.jsx(x.RotateCw,{})}),xe&&t.jsxRuntimeExports.jsx(d,{variant:"outline",size:"icon",onClick:()=>se(!T),title:T?"单页模式":"滚动模式",children:T?t.jsxRuntimeExports.jsx(x.ScrollText,{}):t.jsxRuntimeExports.jsx(x.FileText,{})}),me&&t.jsxRuntimeExports.jsx(d,{variant:"outline",size:"icon",onClick:$e,children:te?t.jsxRuntimeExports.jsx(x.Minimize2,{}):t.jsxRuntimeExports.jsx(x.Maximize2,{})})]}),t.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[!o&&t.jsxRuntimeExports.jsx(d,{variant:"outline",size:"icon",onClick:()=>a(i-1),disabled:i<=1,children:t.jsxRuntimeExports.jsx(x.ChevronLeft,{})}),t.jsxRuntimeExports.jsx(Pe,{type:"number",min:1,max:m,value:i,onChange:e=>a(parseInt(e.target.value)||1),disabled:o,readOnly:o,title:o?"滚动模式下页码仅显示当前位置":void 0,className:"w-16 text-center"}),t.jsxRuntimeExports.jsxs("span",{className:"text-sm text-muted-foreground",children:["/ ",m]}),!o&&t.jsxRuntimeExports.jsx(d,{variant:"outline",size:"icon",onClick:()=>a(i+1),disabled:m>0&&i>=m,children:t.jsxRuntimeExports.jsx(x.ChevronRight,{})})]})]}):null,X=()=>t.jsxRuntimeExports.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsxRuntimeExports.jsx("p",{className:"text-muted-foreground",children:ve})}),Y=()=>t.jsxRuntimeExports.jsx("div",{className:"flex h-full min-h-[400px] items-center justify-center px-4 text-center text-destructive",children:t.jsxRuntimeExports.jsxs("div",{className:"max-w-md",children:[t.jsxRuntimeExports.jsx("p",{className:"mb-2 text-lg font-medium",children:"文件加载失败"}),t.jsxRuntimeExports.jsx("p",{className:"text-sm opacity-80",children:y==null?void 0:y.message})]})}),qe=()=>{if(!ie)return X();const{Document:e,Page:s}=ie;return t.jsxRuntimeExports.jsx("div",{ref:F,onScroll:o?Ie:void 0,className:`pdf-container flex-1 overflow-y-auto ${he||""}`,children:t.jsxRuntimeExports.jsx("div",{className:"flex min-h-full justify-center px-4",children:t.jsxRuntimeExports.jsx(e,{file:f,onLoadError:Fe,options:Me,loading:X(),error:Y(),onLoadSuccess:ze,children:y?Y():T?Array.from(new Array(m),(l,r)=>t.jsxRuntimeExports.jsx("div",{ref:c=>Ae(r+1,c),"data-page-number":r+1,className:`mb-4 ${H||""}`,children:t.jsxRuntimeExports.jsx(s,{pageNumber:r+1,renderTextLayer:!1,renderAnnotationLayer:!1,width:re,scale:j,rotate:z,onRenderSuccess:()=>v==null?void 0:v(r+1)})},`page_${r+1}`)):t.jsxRuntimeExports.jsx("div",{className:H||"",children:t.jsxRuntimeExports.jsx(s,{pageNumber:i,renderTextLayer:!1,renderAnnotationLayer:!1,width:re,scale:j,rotate:z,onRenderSuccess:()=>v==null?void 0:v(i)})})},f)})})},Ge=()=>{if(!E||!V||!ee)return null;const e=_e.PDFSidebar;return t.jsxRuntimeExports.jsx(e,{pdfDocument:ee,currentPage:i,onPageClick:We,components:{Tabs:u.Tabs,TabsList:u.TabsList,TabsTrigger:u.TabsTrigger,TabsContent:u.TabsContent,ScrollArea:u.ScrollArea,Skeleton:Se}})},Ke=()=>!de||o?null:t.jsxRuntimeExports.jsxs("div",{className:"fixed bottom-4 left-1/2 z-50 flex -translate-x-1/2 gap-2 md:hidden",children:[t.jsxRuntimeExports.jsxs(d,{variant:"secondary",size:"sm",onClick:()=>a(i-1),disabled:o||i<=1,title:o?"滚动模式下通过滚动定位页面":void 0,children:[t.jsxRuntimeExports.jsx(x.ChevronLeft,{}),t.jsxRuntimeExports.jsx("span",{className:"ml-1",children:"上一页"})]}),t.jsxRuntimeExports.jsxs(d,{variant:"secondary",size:"sm",onClick:()=>a(i+1),disabled:o||i>=m,title:o?"滚动模式下通过滚动定位页面":void 0,children:[t.jsxRuntimeExports.jsx("span",{className:"mr-1",children:"下一页"}),t.jsxRuntimeExports.jsx(x.ChevronRight,{})]})]});if(!u)return t.jsxRuntimeExports.jsx("div",{className:"p-4 text-center text-destructive",children:"错误:请通过 components prop 注入 UI 组件"});if(E){const e=[];if(u.Tabs||e.push("Tabs"),u.TabsList||e.push("TabsList"),u.TabsTrigger||e.push("TabsTrigger"),u.TabsContent||e.push("TabsContent"),u.ScrollArea||e.push("ScrollArea"),e.length>0){const s=e.length===1?e[0]:`${e.slice(0,-1).join("、")} 和 ${e[e.length-1]}`;return t.jsxRuntimeExports.jsxs("div",{className:"p-4 text-center text-destructive",children:["错误:侧边栏功能需要注入 ",s," 组件"]})}}return t.jsxRuntimeExports.jsxs("div",{ref:le,children:[t.jsxRuntimeExports.jsxs(we,{className:pe,children:[Le(),t.jsxRuntimeExports.jsx(De,{className:"p-0",style:{height:te?"100vh":Ee},children:t.jsxRuntimeExports.jsx("div",{className:"flex h-full flex-col",children:t.jsxRuntimeExports.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[Ge(),Te?X():y?Y():qe()]})})})]}),Ke()]})}exports.PDFReader=Ve;
|
|
1
|
+
"use strict";var Be=Object.create;var ue=Object.defineProperty;var Ve=Object.getOwnPropertyDescriptor;var Ze=Object.getOwnPropertyNames;var Xe=Object.getPrototypeOf,Ye=Object.prototype.hasOwnProperty;var Je=(l,a,f,v)=>{if(a&&typeof a=="object"||typeof a=="function")for(let h of Ze(a))!Ye.call(l,h)&&h!==f&&ue(l,h,{get:()=>a[h],enumerable:!(v=Ve(a,h))||v.enumerable});return l};var Qe=(l,a,f)=>(f=l!=null?Be(Xe(l)):{},Je(a||!l||!l.__esModule?ue(f,"default",{value:l,enumerable:!0}):f,l));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./jsx-runtime-BB_1_6y_.cjs"),d=require("lucide-react"),n=require("react"),He=require("./PDFSidebar-Di0D-yPS.cjs");function Ue(l,a){const f=n.useRef(void 0);return n.useCallback((...v)=>{f.current&&clearTimeout(f.current),f.current=setTimeout(()=>l(...v),a)},[l,a])}function et({url:l,initialPage:a=1,initialScale:f=1,initialRotation:v=0,currentPage:h,onPageChange:D,scale:$,onScaleChange:P,rotation:W,onRotationChange:S,minScale:L=.5,maxScale:G=2.5,showToolbar:ae=!0,showSidebar:R=!0,showRotation:xe=!0,showModeToggle:me=!0,showFullscreen:de=!0,enableHotkeys:Q=!0,enableMobileNav:fe=!0,displayMode:pe="single",className:je,toolbarClassName:he,contentClassName:Ee,contentHeight:be="80vh",pageClassName:H,workerUrl:q,cMapUrl:y,standardFontDataUrl:T,components:x,onLoadSuccess:M,onLoadError:E,onPageRender:g,loadingText:ve="正在加载PDF文档...",errorText:U="PDF加载失败"}){const[ee,K]=n.useState(null),[Re,_]=n.useState(a),[ge,ke]=n.useState(f),[ye,Te]=n.useState(v),[Ne,F]=n.useState(!1),[N,z]=n.useState(null),[p,B]=n.useState(0),[te,V]=n.useState(!1),[C,se]=n.useState(pe==="scroll"),[Z,ne]=n.useState(R);n.useEffect(()=>{ne(R)},[R]);const[re,Ce]=n.useState(void 0),[ie,we]=n.useState(null),le=n.useRef(null),A=n.useRef(null),X=n.useRef(new Map),i=h??Re,b=$??ge,I=W??ye,k=h!==void 0,u=C,{Card:De,CardContent:Pe,Button:j,Input:Se,Skeleton:Me}=x||{};n.useEffect(()=>{K(null),B(0),z(null),F(!1),k||_(Math.max(1,a))},[l,a,k]);const Fe=n.useMemo(()=>{const e={withCredentials:!1};return y&&(e.cMapUrl=y,e.cMapPacked=!0),T&&(e.standardFontDataUrl=T),e},[y,T]);n.useEffect(()=>{let e=!0;return(async()=>{try{const c=await import("react-pdf");if(typeof window<"u"){const r=c.pdfjs,o=r==null?void 0:r.version;r!=null&&r.GlobalWorkerOptions&&o&&(q?r.GlobalWorkerOptions.workerSrc=q:r.GlobalWorkerOptions.workerSrc=`https://cdn.jsdelivr.net/npm/pdfjs-dist@${o}/build/pdf.worker.min.mjs`,!y&&r.GlobalWorkerOptions&&(r.GlobalWorkerOptions.cMapUrl=`https://unpkg.com/pdfjs-dist@${o}/cmaps/`),!T&&r.GlobalWorkerOptions&&(r.GlobalWorkerOptions.standardFontDataUrl=`https://unpkg.com/pdfjs-dist@${o}/standard_fonts/`))}e&&we(c)}catch(c){if(e){const r=c instanceof Error?c:new Error("无法加载 react-pdf 库");z(r),F(!1),E==null||E(r)}}})(),()=>{e=!1}},[q,y,T,E]);const ze=n.useCallback(e=>{console.error("PDF加载失败:",e),console.error("PDF URL:",l),K(null),B(0),z(new Error(`${U}: ${e.message||"请检查文件路径或网络连接"}`)),F(!1),E==null||E(e)},[l,U,E]),Ae=n.useCallback(e=>{K(e),B(e.numPages),z(null),F(!1),k||_(s=>Math.max(1,Math.min(s,Math.max(e.numPages,1)))),M==null||M(e)},[k,M]),m=n.useCallback(e=>{if(!Number.isFinite(e))return;const s=p>0?Math.max(1,Math.min(Math.trunc(e),p)):Math.max(1,Math.trunc(e));k||_(s),s!==i&&(D==null||D(s))},[p,k,i,D]),Ie=n.useCallback((e,s)=>{s?X.current.set(e,s):X.current.delete(e)},[]),Oe=n.useCallback(()=>{const e=A.current;if(!e||!u||p<=0)return;const s=e.getBoundingClientRect().top;let c=i,r=Number.POSITIVE_INFINITY;X.current.forEach((o,O)=>{const oe=Math.abs(o.getBoundingClientRect().top-s);oe<r&&(r=oe,c=O)}),c!==i&&m(c)},[i,m,u,p]),w=n.useCallback(e=>{const s=Math.max(L,Math.min(G,b+e));$===void 0&&ke(s),P==null||P(s)},[b,L,G,$,P]),$e=n.useCallback(()=>{const e=(I+90)%360;W===void 0&&Te(e),S==null||S(e)},[I,W,S]),ce=Ue(e=>{Ce(e)},100);n.useEffect(()=>{if(!A.current)return;const e=A.current,s=()=>{ce(e.clientWidth)};s();const c=new ResizeObserver(()=>{s()});return c.observe(e),()=>{c.disconnect()}},[ce]),n.useEffect(()=>{if(!Q)return;const e=s=>{const c=s.target,r=typeof document<"u"?document.activeElement:null,o=c||r,O=o==null?void 0:o.getAttribute("role");o&&(o.tagName==="INPUT"||o.tagName==="TEXTAREA"||o.tagName==="SELECT"||o.isContentEditable||O==="textbox"||O==="spinbutton")||((s.ctrlKey||s.metaKey)&&(s.key==="="||s.key==="+")?(s.preventDefault(),w(.1)):(s.ctrlKey||s.metaKey)&&s.key==="-"?(s.preventDefault(),w(-.1)):!u&&s.key==="ArrowLeft"?(s.preventDefault(),m(i-1)):!u&&s.key==="ArrowRight"&&(s.preventDefault(),m(i+1)))};return document.addEventListener("keydown",e),()=>{document.removeEventListener("keydown",e)}},[Q,i,m,u,w]);const We=n.useCallback(async()=>{var e,s;if(!(typeof document>"u"))if(document.fullscreenElement)document.exitFullscreen&&(await document.exitFullscreen(),V(!1));else try{await((s=(e=le.current)==null?void 0:e.requestFullscreen)==null?void 0:s.call(e)),V(!0)}catch(c){console.error("Error attempting to enable fullscreen:",c)}},[]);n.useEffect(()=>{if(typeof document>"u")return;const e=()=>{V(!!document.fullscreenElement)};return document.addEventListener("fullscreenchange",e),()=>{document.removeEventListener("fullscreenchange",e)}},[]);const Le=n.useCallback(e=>{m(e),se(!1)},[m]),Ge=()=>ae?t.jsxRuntimeExports.jsxs("div",{className:`flex items-center justify-between gap-4 border-b px-4 py-2 ${he||""}`,children:[t.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[R&&t.jsxRuntimeExports.jsx(j,{variant:"outline",size:"icon",onClick:()=>ne(!Z),title:Z?"隐藏侧边栏":"显示侧边栏",children:t.jsxRuntimeExports.jsx(d.PanelLeft,{})}),t.jsxRuntimeExports.jsx(j,{variant:"outline",size:"icon",onClick:()=>w(-.1),disabled:b<=L,children:t.jsxRuntimeExports.jsx(d.ZoomOut,{})}),t.jsxRuntimeExports.jsxs("span",{className:"min-w-[3rem] text-center text-sm",children:[Math.round(b*100),"%"]}),t.jsxRuntimeExports.jsx(j,{variant:"outline",size:"icon",onClick:()=>w(.1),disabled:b>=G,children:t.jsxRuntimeExports.jsx(d.ZoomIn,{})}),xe&&t.jsxRuntimeExports.jsx(j,{variant:"outline",size:"icon",onClick:$e,children:t.jsxRuntimeExports.jsx(d.RotateCw,{})}),me&&t.jsxRuntimeExports.jsx(j,{variant:"outline",size:"icon",onClick:()=>se(!C),title:C?"单页模式":"滚动模式",children:C?t.jsxRuntimeExports.jsx(d.ScrollText,{}):t.jsxRuntimeExports.jsx(d.FileText,{})}),de&&t.jsxRuntimeExports.jsx(j,{variant:"outline",size:"icon",onClick:We,children:te?t.jsxRuntimeExports.jsx(d.Minimize2,{}):t.jsxRuntimeExports.jsx(d.Maximize2,{})})]}),t.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[!u&&t.jsxRuntimeExports.jsx(j,{variant:"outline",size:"icon",onClick:()=>m(i-1),disabled:i<=1,children:t.jsxRuntimeExports.jsx(d.ChevronLeft,{})}),t.jsxRuntimeExports.jsx(Se,{type:"number",min:1,max:p,value:i,onChange:e=>m(parseInt(e.target.value)||1),disabled:u,readOnly:u,title:u?"滚动模式下页码仅显示当前位置":void 0,className:"w-16 text-center"}),t.jsxRuntimeExports.jsxs("span",{className:"text-sm text-muted-foreground",children:["/ ",p]}),!u&&t.jsxRuntimeExports.jsx(j,{variant:"outline",size:"icon",onClick:()=>m(i+1),disabled:p>0&&i>=p,children:t.jsxRuntimeExports.jsx(d.ChevronRight,{})})]})]}):null,Y=()=>t.jsxRuntimeExports.jsx("div",{className:"flex h-full items-center justify-center",children:t.jsxRuntimeExports.jsx("p",{className:"text-muted-foreground",children:ve})}),J=()=>t.jsxRuntimeExports.jsx("div",{className:"flex h-full min-h-[400px] items-center justify-center px-4 text-center text-destructive",children:t.jsxRuntimeExports.jsxs("div",{className:"max-w-md",children:[t.jsxRuntimeExports.jsx("p",{className:"mb-2 text-lg font-medium",children:"文件加载失败"}),t.jsxRuntimeExports.jsx("p",{className:"text-sm opacity-80",children:N==null?void 0:N.message})]})}),qe=()=>{if(!ie)return Y();const{Document:e,Page:s}=ie;return t.jsxRuntimeExports.jsx("div",{ref:A,onScroll:u?Oe:void 0,className:`pdf-container flex-1 overflow-y-auto ${Ee||""}`,children:t.jsxRuntimeExports.jsx("div",{className:"flex min-h-full justify-center px-4",children:t.jsxRuntimeExports.jsx(e,{file:l,onLoadError:ze,options:Fe,loading:Y(),error:J(),onLoadSuccess:Ae,children:N?J():C?Array.from(new Array(p),(c,r)=>t.jsxRuntimeExports.jsx("div",{ref:o=>Ie(r+1,o),"data-page-number":r+1,className:`mb-4 ${H||""}`,children:t.jsxRuntimeExports.jsx(s,{pageNumber:r+1,renderTextLayer:!1,renderAnnotationLayer:!1,width:re,scale:b,rotate:I,onRenderSuccess:()=>g==null?void 0:g(r+1)})},`page_${r+1}`)):t.jsxRuntimeExports.jsx("div",{className:H||"",children:t.jsxRuntimeExports.jsx(s,{pageNumber:i,renderTextLayer:!1,renderAnnotationLayer:!1,width:re,scale:b,rotate:I,onRenderSuccess:()=>g==null?void 0:g(i)})})},l)})})},Ke=()=>{if(!R||!Z||!ee)return null;const e=He.PDFSidebar;return t.jsxRuntimeExports.jsx(e,{pdfDocument:ee,currentPage:i,onPageClick:Le,components:{Tabs:x.Tabs,TabsList:x.TabsList,TabsTrigger:x.TabsTrigger,TabsContent:x.TabsContent,ScrollArea:x.ScrollArea,Skeleton:Me}})},_e=()=>!fe||u?null:t.jsxRuntimeExports.jsxs("div",{className:"fixed bottom-4 left-1/2 z-50 flex -translate-x-1/2 gap-2 md:hidden",children:[t.jsxRuntimeExports.jsxs(j,{variant:"secondary",size:"sm",onClick:()=>m(i-1),disabled:u||i<=1,title:u?"滚动模式下通过滚动定位页面":void 0,children:[t.jsxRuntimeExports.jsx(d.ChevronLeft,{}),t.jsxRuntimeExports.jsx("span",{className:"ml-1",children:"上一页"})]}),t.jsxRuntimeExports.jsxs(j,{variant:"secondary",size:"sm",onClick:()=>m(i+1),disabled:u||i>=p,title:u?"滚动模式下通过滚动定位页面":void 0,children:[t.jsxRuntimeExports.jsx("span",{className:"mr-1",children:"下一页"}),t.jsxRuntimeExports.jsx(d.ChevronRight,{})]})]});if(!x)return t.jsxRuntimeExports.jsx("div",{className:"p-4 text-center text-destructive",children:"错误:请通过 components prop 注入 UI 组件"});if(R){const e=[];if(x.Tabs||e.push("Tabs"),x.TabsList||e.push("TabsList"),x.TabsTrigger||e.push("TabsTrigger"),x.TabsContent||e.push("TabsContent"),x.ScrollArea||e.push("ScrollArea"),e.length>0){const s=e.length===1?e[0]:`${e.slice(0,-1).join("、")} 和 ${e[e.length-1]}`;return t.jsxRuntimeExports.jsxs("div",{className:"p-4 text-center text-destructive",children:["错误:侧边栏功能需要注入 ",s," 组件"]})}}return t.jsxRuntimeExports.jsxs("div",{ref:le,children:[t.jsxRuntimeExports.jsxs(De,{className:je,children:[Ge(),t.jsxRuntimeExports.jsx(Pe,{className:"p-0",style:{height:te?"100vh":be},children:t.jsxRuntimeExports.jsx("div",{className:"flex h-full flex-col",children:t.jsxRuntimeExports.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[Ke(),Ne?Y():N?J():qe()]})})})]}),_e()]})}exports.PDFReader=et;
|
|
2
2
|
//# sourceMappingURL=pdf-reader.cjs.map
|