@tonar/react-kit 0.1.0-beta.2 → 0.2.9

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.
@@ -1,237 +0,0 @@
1
- import { useCreateSafeRef as e, useRAfInterval as t } from "../hooks.esm.js";
2
- import { Component as n, cloneElement as r, forwardRef as i, useCallback as a, useEffect as o, useImperativeHandle as s, useMemo as c, useRef as l, useState as u } from "react";
3
- import { Fragment as d, jsx as f, jsxs as p } from "react/jsx-runtime";
4
- import '../css/components.C24nnsjt.css';//#region src/components/carousel/hooks/index.ts
5
- var m = (e, t) => {
6
- e.style.cssText = `transition-duration: 0s; --index: ${t}`, e.clientLeft, e.style.cssText = "";
7
- }, h = (e, t) => {
8
- let n = e.previousElementSibling;
9
- if (!n) return;
10
- let [r, i] = t;
11
- n.children[0]?.classList.toggle("show", r), n.children[1]?.classList.toggle("show", i);
12
- }, g = (e, t, n) => {
13
- e.style.setProperty("--index", `${t}`);
14
- let r = e.parentElement;
15
- if (!r) return;
16
- let i = r.parentElement?.nextElementSibling;
17
- i && (i.querySelector(".active")?.classList.remove("active"), i.children[t >= i.children.length ? 0 : t]?.classList.add("active")), h(r, n);
18
- }, _ = ({ showArrow: e, length: t, cardWidth: n, wrapperRef: r }) => {
19
- let i = c(() => {
20
- let e = (r?.parentElement?.parentElement?.clientWidth || n) ?? 0;
21
- return n ? Math.floor(e / n) : 1;
22
- }, [r, n]);
23
- return a((n) => {
24
- if (e !== "auto") return [!0, !0];
25
- let r;
26
- return r = t > i && n + i - 1 < t - 1, [n > 0, r];
27
- }, [
28
- i,
29
- t,
30
- e
31
- ]);
32
- }, v = ({ length: t, loop: n, showArrow: r, cardWidth: i, onNonLoopEnd: s, offsetOnEnd: c = 0 }) => {
33
- let u = t, d = l(0), [f, p, v] = e();
34
- c = ~~c, c = c < 0 || c >= t ? 0 : c;
35
- let y = _({
36
- showArrow: r,
37
- length: t,
38
- cardWidth: i,
39
- wrapperRef: f
40
- });
41
- o(() => {
42
- let e = f?.parentElement;
43
- r !== "auto" || !e || h(e, y(d.current));
44
- }, [t]);
45
- let b = a((e) => {
46
- if (!f) return;
47
- n && (d.current >= u && e !== "prev" ? (d.current = 0, m(f, d.current)) : d.current <= 0 && e === "prev" && (d.current = u, m(f, d.current))), e === "prev" ? d.current-- : d.current++;
48
- let r = y(d.current);
49
- g(f, d.current, r), !n && s && d.current === t - c - 1 && s(e ?? "next", d.current, t, c);
50
- }, [
51
- t,
52
- n,
53
- f,
54
- y,
55
- c,
56
- s,
57
- u
58
- ]), x = a((e) => {
59
- let r = d.current;
60
- d.current = e < 0 ? 0 : e > t ? t : e;
61
- let i = y(d.current);
62
- if (f && g(f, d.current, i), !n && s) {
63
- let e = r < d.current ? "next" : "prev", n = t - c - 1;
64
- (d.current >= n && r < n || d.current <= n && r > n) && s(e, d.current, t, c);
65
- }
66
- }, [
67
- t,
68
- n,
69
- f,
70
- y,
71
- c,
72
- s
73
- ]), S = a(() => d.current, []);
74
- return o(() => x(d.current), [f]), [
75
- p,
76
- b,
77
- x,
78
- S,
79
- v
80
- ];
81
- }, y = (() => {
82
- let e = Math.random().toString(36).slice(2), t = 0;
83
- return () => `${e}-${++t}`;
84
- })(), b = (e, t, n) => c(() => {
85
- if (!Array.isArray(e) || !e.length) throw Error("Carousel children must be an array");
86
- if (t) {
87
- let t = e[0], n = [...e];
88
- return n.push(r(t, { key: y() })), n;
89
- }
90
- return e;
91
- }, [n === "child" ? e : e?.length, t]), x = {
92
- carousel: "_carousel_1ryaf_1",
93
- wrapper: "_wrapper_1ryaf_13",
94
- inner: "_inner_1ryaf_13",
95
- arrow: "_arrow_1ryaf_36",
96
- left: "_left_1ryaf_48",
97
- right: "_right_1ryaf_49",
98
- indicator: "_indicator_1ryaf_85"
99
- }, S = i(({ cardWidth: e, cardHeight: n, wrapperWidth: r, wrapperHeight: i, gapSize: a, loop: c = !0, duration: l = 6e3, autoPlay: u = !0, showArrow: m = "always", indicatorType: h = "line", className: g, style: _, children: y, rerender: S = "length", onNonLoopEnd: C, offsetOnEnd: w = 0, arrows: T }, E) => {
100
- let D = b(y, c, S), [O, k, A, j] = v({
101
- length: y.length,
102
- loop: c,
103
- showArrow: m,
104
- cardWidth: e,
105
- onNonLoopEnd: C,
106
- offsetOnEnd: w
107
- }), [M, N] = t(k, l);
108
- return o(() => (u && M(), N), [
109
- M,
110
- N,
111
- u
112
- ]), s(E, () => ({
113
- run: M,
114
- stop: N,
115
- stepChange: k,
116
- jumpChange: A,
117
- getCurrentIndex: j
118
- }), [
119
- M,
120
- N,
121
- k,
122
- A,
123
- j
124
- ]), /* @__PURE__ */ p(d, { children: [/* @__PURE__ */ p("div", {
125
- className: `${x.carousel} ${g ?? ""}`,
126
- style: {
127
- ..._,
128
- "--wrapperWidth": r,
129
- "--wrapperHeight": i,
130
- "--cardWidth": e,
131
- "--cardHeight": n,
132
- "--gapSize": a
133
- },
134
- onMouseEnter: N,
135
- onMouseLeave: u ? M : void 0,
136
- children: [/* @__PURE__ */ p("div", {
137
- className: `${x.arrow} ${m}`,
138
- children: [T?.[0] ? T[0]({
139
- onClick: () => k("prev"),
140
- className: x.left
141
- }) : /* @__PURE__ */ f("i", {
142
- className: x.left,
143
- onClick: () => k("prev")
144
- }), T?.[1] ? T[1]({
145
- onClick: () => k(),
146
- className: x.right
147
- }) : /* @__PURE__ */ f("i", {
148
- className: x.right,
149
- onClick: () => k()
150
- })]
151
- }), /* @__PURE__ */ f("div", {
152
- className: x.wrapper,
153
- children: /* @__PURE__ */ f("div", {
154
- className: x.inner,
155
- ref: O,
156
- children: D
157
- })
158
- })]
159
- }), /* @__PURE__ */ f("div", {
160
- className: `${x.indicator} ${h}`,
161
- children: y.map((e, t) => /* @__PURE__ */ f("i", { onClick: (e) => {
162
- e.stopPropagation(), A(t);
163
- } }, t))
164
- })] });
165
- });
166
- S.displayName = "Carousel";
167
- //#endregion
168
- //#region src/components/custom-show/index.tsx
169
- function C({ when: e, fallback: t = void 0, children: n }) {
170
- return /* @__PURE__ */ f(d, { children: e ? n : t });
171
- }
172
- //#endregion
173
- //#region src/components/async-custom-show/index.tsx
174
- function w({ when: e, fallback: t, children: n }) {
175
- let [r, i] = u(void 0);
176
- return o(() => {
177
- if (!e) return;
178
- let t = !0;
179
- return Promise.resolve(e).then((e) => t && i(e)), () => void (t = !1);
180
- }, [e]), /* @__PURE__ */ f(d, { children: r ? n(r) : t });
181
- }
182
- //#endregion
183
- //#region \0@oxc-project+runtime@0.139.0/helpers/esm/typeof.js
184
- function T(e) {
185
- "@babel/helpers - typeof";
186
- return T = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(e) {
187
- return typeof e;
188
- } : function(e) {
189
- return e && typeof Symbol == "function" && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
190
- }, T(e);
191
- }
192
- //#endregion
193
- //#region \0@oxc-project+runtime@0.139.0/helpers/esm/toPrimitive.js
194
- function E(e, t) {
195
- if (T(e) != "object" || !e) return e;
196
- var n = e[Symbol.toPrimitive];
197
- if (n !== void 0) {
198
- var r = n.call(e, t || "default");
199
- if (T(r) != "object") return r;
200
- throw TypeError("@@toPrimitive must return a primitive value.");
201
- }
202
- return (t === "string" ? String : Number)(e);
203
- }
204
- //#endregion
205
- //#region \0@oxc-project+runtime@0.139.0/helpers/esm/toPropertyKey.js
206
- function D(e) {
207
- var t = E(e, "string");
208
- return T(t) == "symbol" ? t : t + "";
209
- }
210
- //#endregion
211
- //#region \0@oxc-project+runtime@0.139.0/helpers/esm/defineProperty.js
212
- function O(e, t, n) {
213
- return (t = D(t)) in e ? Object.defineProperty(e, t, {
214
- value: n,
215
- enumerable: !0,
216
- configurable: !0,
217
- writable: !0
218
- }) : e[t] = n, e;
219
- }
220
- //#endregion
221
- //#region src/components/error-boundary/index.tsx
222
- var k = class extends n {
223
- constructor(...e) {
224
- super(...e), O(this, "state", { hasError: !1 }), O(this, "msg", this.props.msg ?? "组件加载失败");
225
- }
226
- static getDerivedStateFromError() {
227
- return { hasError: !0 };
228
- }
229
- componentDidCatch(e, t) {
230
- console.error(`${this.msg}:`, e, t);
231
- }
232
- render() {
233
- return this.state.hasError ? this.props.fallback : this.props.children;
234
- }
235
- };
236
- //#endregion
237
- export { S as i, w as n, C as r, k as t };