@xiping/react-components 0.0.66 → 0.0.67
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 +10 -2
- package/dist/cjs/components/txt-reader/TxtReader.d.ts +4 -0
- package/dist/cjs/components/txt-reader/TxtReader.js +1 -1
- package/dist/cjs/react-components.css +1 -1
- package/dist/es/components/txt-reader/TxtReader.d.ts +4 -0
- package/dist/es/components/txt-reader/TxtReader.js +69 -57
- package/dist/es/react-components.css +1 -1
- package/package.json +16 -17
|
@@ -9,6 +9,10 @@ interface TxtReaderProps {
|
|
|
9
9
|
onProgressChange?: (progress: number) => void;
|
|
10
10
|
initialScrollPosition?: number;
|
|
11
11
|
cacheKey?: string;
|
|
12
|
+
showTopProgress?: boolean;
|
|
13
|
+
topProgressClassName?: string;
|
|
14
|
+
showBottomProgress?: boolean;
|
|
15
|
+
bottomProgressClassName?: string;
|
|
12
16
|
}
|
|
13
17
|
export declare const TxtReader: FC<TxtReaderProps>;
|
|
14
18
|
export default TxtReader;
|
|
@@ -1,68 +1,80 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { useRef as
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
const
|
|
1
|
+
import { jsxs as s, Fragment as F, jsx as e } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as a } from "react";
|
|
3
|
+
import r from "clsx";
|
|
4
|
+
import { useScroll as _, useTransform as v, useMotionTemplate as y, motion as n } from "motion/react";
|
|
5
|
+
const g = 16, I = 1.5, L = "normal", j = ({
|
|
6
6
|
content: f,
|
|
7
|
-
lineHeight:
|
|
8
|
-
fontSize:
|
|
9
|
-
fontWeight:
|
|
10
|
-
className:
|
|
11
|
-
style:
|
|
12
|
-
onProgressChange:
|
|
13
|
-
initialScrollPosition:
|
|
14
|
-
cacheKey:
|
|
7
|
+
lineHeight: m = I,
|
|
8
|
+
fontSize: d = g,
|
|
9
|
+
fontWeight: p = L,
|
|
10
|
+
className: u = "",
|
|
11
|
+
style: x = {},
|
|
12
|
+
onProgressChange: t,
|
|
13
|
+
initialScrollPosition: R,
|
|
14
|
+
cacheKey: S,
|
|
15
|
+
showTopProgress: T = !0,
|
|
16
|
+
topProgressClassName: b,
|
|
17
|
+
showBottomProgress: h = !0,
|
|
18
|
+
bottomProgressClassName: N
|
|
15
19
|
}) => {
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
[l]
|
|
26
|
-
);
|
|
27
|
-
return d(() => {
|
|
28
|
-
if (!r.current) return;
|
|
29
|
-
let t = c;
|
|
30
|
-
if (e) {
|
|
31
|
-
const o = localStorage.getItem(`txtReader-${e}`);
|
|
32
|
-
o && (t = parseInt(o, 10));
|
|
33
|
-
}
|
|
34
|
-
t && (r.current.scrollTop = t, l());
|
|
35
|
-
}, [e, c, l]), d(() => {
|
|
36
|
-
const t = r.current;
|
|
37
|
-
if (t)
|
|
38
|
-
return t.addEventListener("scroll", n), () => {
|
|
39
|
-
t.removeEventListener("scroll", n);
|
|
40
|
-
};
|
|
41
|
-
}, [n]), /* @__PURE__ */ a("div", { className: "relative w-full h-full", children: [
|
|
42
|
-
/* @__PURE__ */ H(
|
|
43
|
-
"div",
|
|
20
|
+
const l = a(null), o = a(null), { scrollYProgress: i } = _({
|
|
21
|
+
container: l,
|
|
22
|
+
target: o
|
|
23
|
+
}), c = v(() => (i.get() * 100).toFixed(2)), w = y`${c}%`;
|
|
24
|
+
return c.on("change", (E) => {
|
|
25
|
+
t == null || t(Number(E));
|
|
26
|
+
}), /* @__PURE__ */ s(F, { children: [
|
|
27
|
+
T && /* @__PURE__ */ e(
|
|
28
|
+
n.div,
|
|
44
29
|
{
|
|
45
|
-
|
|
46
|
-
className:
|
|
47
|
-
"
|
|
48
|
-
|
|
30
|
+
id: "scroll-indicator",
|
|
31
|
+
className: r(
|
|
32
|
+
"fixed left-0 top-0 right-0 bg-[#ff0088] h-2.5",
|
|
33
|
+
b
|
|
49
34
|
),
|
|
50
35
|
style: {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
...E
|
|
55
|
-
},
|
|
56
|
-
children: f
|
|
36
|
+
scaleX: i,
|
|
37
|
+
originX: 0
|
|
38
|
+
}
|
|
57
39
|
}
|
|
58
40
|
),
|
|
59
|
-
/* @__PURE__ */
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
41
|
+
/* @__PURE__ */ s(
|
|
42
|
+
"div",
|
|
43
|
+
{
|
|
44
|
+
className: "relative w-full h-full overflow-y-auto",
|
|
45
|
+
ref: l,
|
|
46
|
+
children: [
|
|
47
|
+
/* @__PURE__ */ e(
|
|
48
|
+
"div",
|
|
49
|
+
{
|
|
50
|
+
ref: o,
|
|
51
|
+
className: r("w-full whitespace-pre-wrap break-words", u),
|
|
52
|
+
style: {
|
|
53
|
+
fontSize: `${d}px`,
|
|
54
|
+
lineHeight: m,
|
|
55
|
+
fontWeight: p,
|
|
56
|
+
...x
|
|
57
|
+
},
|
|
58
|
+
children: f
|
|
59
|
+
}
|
|
60
|
+
),
|
|
61
|
+
h && /* @__PURE__ */ e(
|
|
62
|
+
n.div,
|
|
63
|
+
{
|
|
64
|
+
id: "scroll-present",
|
|
65
|
+
className: r(
|
|
66
|
+
"fixed text-white rounded text-sm bg-black bg-opacity-70 pl-2 pr-2 pb-1 pt-1 right-5 bottom-5",
|
|
67
|
+
N
|
|
68
|
+
),
|
|
69
|
+
children: w
|
|
70
|
+
}
|
|
71
|
+
)
|
|
72
|
+
]
|
|
73
|
+
}
|
|
74
|
+
)
|
|
63
75
|
] });
|
|
64
76
|
};
|
|
65
77
|
export {
|
|
66
|
-
|
|
67
|
-
|
|
78
|
+
j as TxtReader,
|
|
79
|
+
j as default
|
|
68
80
|
};
|