@xiping/react-components 0.0.66 → 0.0.68

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