quirk-ui 0.0.80 → 0.0.82

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,143 +1,165 @@
1
- import { jsxs as E, jsx as s } from "react/jsx-runtime";
2
- import { useState as o, useRef as X, useEffect as y } from "react";
3
- import { A as vt } from "../../arrow-left-BIJvHwNQ.js";
4
- import { A as bt } from "../../arrow-right-QEwnX3Sk.js";
5
- import '../../assets/index31.css';const ft = "_carousel_zbb4v_1", _t = "_noPointerEvents_zbb4v_9", pt = "_trackContainer_zbb4v_13", mt = "_track_zbb4v_13", wt = "_page_zbb4v_28", Mt = "_controls_zbb4v_34", gt = "_indicators_zbb4v_45", xt = "_indicator_zbb4v_45", $t = "_active_zbb4v_62", zt = "_buttons_zbb4v_66", Ct = "_prev_zbb4v_71", Et = "_disabled_zbb4v_71", Xt = "_next_zbb4v_72", n = {
6
- carousel: ft,
7
- noPointerEvents: _t,
8
- trackContainer: pt,
9
- track: mt,
10
- page: wt,
11
- controls: Mt,
12
- indicators: gt,
13
- indicator: xt,
14
- active: $t,
15
- buttons: zt,
16
- prev: Ct,
17
- disabled: Et,
18
- next: Xt
1
+ import { jsxs as A, jsx as r } from "react/jsx-runtime";
2
+ import { useState as c, useRef as C, useEffect as E } from "react";
3
+ import { A as Mt } from "../../arrow-left-BIJvHwNQ.js";
4
+ import { A as wt } from "../../arrow-right-QEwnX3Sk.js";
5
+ import '../../assets/index31.css';const gt = "_carousel_zbb4v_1", xt = "_noPointerEvents_zbb4v_9", $t = "_trackContainer_zbb4v_13", zt = "_track_zbb4v_13", Ct = "_page_zbb4v_28", Et = "_controls_zbb4v_34", Xt = "_indicators_zbb4v_45", yt = "_indicator_zbb4v_45", It = "_active_zbb4v_62", Nt = "_buttons_zbb4v_66", kt = "_prev_zbb4v_71", Tt = "_disabled_zbb4v_71", At = "_next_zbb4v_72", o = {
6
+ carousel: gt,
7
+ noPointerEvents: xt,
8
+ trackContainer: $t,
9
+ track: zt,
10
+ page: Ct,
11
+ controls: Et,
12
+ indicators: Xt,
13
+ indicator: yt,
14
+ active: It,
15
+ buttons: Nt,
16
+ prev: kt,
17
+ disabled: Tt,
18
+ next: At
19
19
  };
20
- function It({
21
- items: N,
22
- itemsPerPage: f = 9,
23
- itemsPerRow: O = 3,
24
- autoplay: q = !1,
25
- autoplayInterval: k = 3,
26
- className: F,
27
- externalRef: H,
28
- siblingRef: a,
29
- isSplit: T = !1
20
+ function Pt({
21
+ items: _,
22
+ itemsPerPage: l = 9,
23
+ itemsPerRow: J = 3,
24
+ autoplay: K = !1,
25
+ autoplayInterval: W = 3,
26
+ className: Q,
27
+ externalRef: V,
28
+ siblingRef: i,
29
+ isSplit: D = !1
30
30
  }) {
31
- const [l, i] = o(0), [h, _] = o(0), [I, J] = o(0), [p, K] = o(f), [W, Q] = o(!1), [A, V] = o(q), Y = X(null), m = X(null), v = X(null), w = H, [D, P] = o(null), [S, L] = o(null), [Z, j] = o(!1), [d, R] = o(null), [M, U] = o(null), tt = (t) => {
32
- console.log(Math.abs((M ?? 0) - (d ?? 0))), Math.abs((M ?? 0) - (d ?? 0)) > 25 && (t.stopPropagation(), t.preventDefault());
33
- }, et = (t) => {
34
- R(t.clientX);
35
- }, nt = (t) => {
36
- d !== null && Math.abs(t.clientX - d) > 5 && (j(!0), U(t.clientX));
37
- }, ot = () => {
38
- if (!d || !M) {
39
- x();
31
+ const [d, u] = c(0), [v, m] = c(0), [S, Z] = c(0), [M, tt] = c(l), [w, et] = c(!1), [L, nt] = c(K), ot = C(null), g = C(null), b = C(null), x = V, [f, X] = c(!1), [P, Y] = c(null), [$, R] = c(null), [j, U] = c(null), [st, B] = c(!1), [p, G] = c(null), [y, O] = c(null), ct = (t) => {
32
+ Math.abs((y ?? 0) - (p ?? 0)) > 25 && (t.stopPropagation(), t.preventDefault());
33
+ }, rt = (t) => {
34
+ G(t.clientX);
35
+ }, at = (t) => {
36
+ p !== null && Math.abs(t.clientX - p) > 5 && (B(!0), O(t.clientX));
37
+ }, lt = () => {
38
+ if (!p || !y) {
39
+ I();
40
40
  return;
41
41
  }
42
- const t = d - M;
43
- Math.abs(t) > 50 && (t > 0 ? z() : C()), x();
44
- }, st = () => {
45
- x();
46
- }, x = () => {
47
- j(!1), R(null), U(null);
48
- }, ct = (t) => {
49
- P(t.touches[0].clientX);
50
- }, rt = (t) => {
51
- L(t.touches[0].clientX);
52
- }, at = () => {
53
- if (D === null || S === null) return;
54
- const t = D - S;
55
- Math.abs(t) > 50 && (t > 0 ? z() : C()), P(null), L(null);
56
- }, lt = (t, e) => {
57
- const r = [];
58
- for (let c = 0; c < t.length; c += e)
59
- r.push(t.slice(c, c + e));
60
- return r;
42
+ const t = p - y;
43
+ Math.abs(t) > 50 && (t > 0 ? k() : T()), I();
44
+ }, it = () => {
45
+ I();
46
+ }, I = () => {
47
+ B(!1), G(null), O(null);
48
+ }, dt = (t) => {
49
+ R(t.touches[0].clientX), Y(t.touches[0].clientY), X(!1);
50
+ }, q = C(null);
51
+ E(() => {
52
+ const t = q.current;
53
+ if (!t) return;
54
+ const e = (n) => {
55
+ const s = n.touches[0].clientX - ($ ?? 0), a = n.touches[0].clientY - (P ?? 0);
56
+ !f && Math.abs(s) > Math.abs(a) && X(!0), f && (n.preventDefault(), U(n.touches[0].clientX));
57
+ };
58
+ return t.addEventListener("touchmove", e), () => {
59
+ t.removeEventListener("touchmove", e);
60
+ };
61
+ }, [f, $, P]);
62
+ const ut = () => {
63
+ if ($ === null || j === null) return;
64
+ const t = $ - j;
65
+ Math.abs(t) > 50 && (t > 0 ? k() : T()), R(null), U(null), Y(null), X(!1);
66
+ }, ht = (t, e) => {
67
+ const n = [];
68
+ for (let s = 0; s < t.length; s += e)
69
+ n.push(t.slice(s, s + e));
70
+ return n;
61
71
  };
62
- y(() => {
72
+ E(() => {
63
73
  if (typeof window < "u") {
64
74
  const t = () => {
65
- const e = window.innerWidth < 768;
66
- Q(e), K(e ? 1 : f), i(0);
75
+ const e = window.innerWidth < 768, n = e ? 1 : l;
76
+ et(e), tt(e ? 1 : l), u(
77
+ (s) => Math.min(s, Math.ceil(_.length / n) - 1)
78
+ );
67
79
  };
68
80
  return t(), window.addEventListener("resize", t), () => window.removeEventListener("resize", t);
69
81
  }
70
- }, [f]);
71
- const g = Math.ceil(p / O), B = lt(N, p), u = B.length, it = 3 * 16, dt = 6 * 16;
72
- y(() => {
82
+ }, [l]);
83
+ const z = Math.ceil(M / J), F = ht(_, M), h = F.length, vt = 3 * 16, bt = 6 * 16;
84
+ E(() => {
73
85
  const t = new ResizeObserver((e) => {
74
- var r, c;
75
- for (let b of e)
76
- b.contentRect && (W ? _(b.contentRect.width - dt) : T ? a != null && a.current ? _(
77
- b.contentRect.width - ((r = a == null ? void 0 : a.current) == null ? void 0 : r.offsetWidth) - it
78
- ) : _(b.contentRect.width) : (_(b.contentRect.width), J(
79
- ((c = m == null ? void 0 : m.current) == null ? void 0 : c.children[0].children[0].children[0].getBoundingClientRect().width) ?? 0
80
- )), i(0));
86
+ var n, s;
87
+ for (let a of e)
88
+ if (a.contentRect) {
89
+ w ? m(a.contentRect.width - bt) : D ? i != null && i.current ? m(
90
+ a.contentRect.width - ((n = i == null ? void 0 : i.current) == null ? void 0 : n.offsetWidth) - vt
91
+ ) : m(a.contentRect.width) : (m(a.contentRect.width), Z(
92
+ ((s = g == null ? void 0 : g.current) == null ? void 0 : s.children[0].children[0].children[0].getBoundingClientRect().width) ?? 0
93
+ ));
94
+ const _t = w ? 1 : l;
95
+ u(
96
+ (mt) => Math.min(mt, Math.ceil(_.length / _t) - 1)
97
+ );
98
+ }
81
99
  });
82
- return w != null && w.current && t.observe(w.current), () => t.disconnect();
83
- }, [W, T]);
84
- const $ = () => {
85
- v.current && clearInterval(v.current), V(!1);
86
- }, z = () => {
87
- $(), i((t) => Math.min(t + 1, u - 1));
88
- }, C = () => {
89
- $(), i((t) => Math.max(t - 1, 0));
90
- }, ut = (t) => {
91
- $(), i(t);
92
- }, ht = () => h ? `translateX(-${l * h}px)` : "translateX(0px)", G = () => {
93
- i((t) => t >= u - 1 ? 0 : t + 1);
100
+ return x != null && x.current && t.observe(x.current), () => t.disconnect();
101
+ }, [w, D]);
102
+ const N = () => {
103
+ b.current && clearInterval(b.current), nt(!1);
104
+ }, k = () => {
105
+ N(), u((t) => Math.min(t + 1, h - 1));
106
+ }, T = () => {
107
+ N(), u((t) => Math.max(t - 1, 0));
108
+ }, ft = (t) => {
109
+ N(), u(t);
110
+ }, pt = () => v ? `translateX(-${d * v}px)` : "translateX(0px)", H = () => {
111
+ u((t) => t >= h - 1 ? 0 : t + 1);
94
112
  };
95
- return y(() => (A && (v.current = setInterval(
96
- G,
97
- k * 1e3
113
+ return E(() => (L && (b.current = setInterval(
114
+ H,
115
+ W * 1e3
98
116
  )), () => {
99
- v.current && clearInterval(v.current);
100
- }), [A, k, G]), /* @__PURE__ */ E("div", { className: `${F ?? ""} ${n.carousel}`, ref: Y, children: [
101
- /* @__PURE__ */ s(
117
+ b.current && clearInterval(b.current);
118
+ }), [L, W, H]), /* @__PURE__ */ A("div", { className: `${Q ?? ""} ${o.carousel}`, ref: ot, children: [
119
+ /* @__PURE__ */ r(
102
120
  "div",
103
121
  {
104
- className: n.trackContainer,
105
- style: { maxWidth: `${h}px` },
106
- onTouchStart: ct,
107
- onTouchMove: rt,
108
- onTouchEnd: at,
109
- onMouseDown: et,
110
- onMouseMove: nt,
111
- onMouseUp: ot,
112
- onMouseLeave: st,
113
- children: /* @__PURE__ */ s(
122
+ ref: q,
123
+ className: `${o.trackContainer} ${st || f ? o.noPointerEvents : ""}
124
+ `,
125
+ style: {
126
+ maxWidth: `${v}px`,
127
+ touchAction: f ? "none" : "pan-y"
128
+ },
129
+ onTouchStart: dt,
130
+ onTouchEnd: ut,
131
+ onMouseDown: rt,
132
+ onMouseMove: at,
133
+ onMouseUp: lt,
134
+ onMouseLeave: it,
135
+ children: /* @__PURE__ */ r(
114
136
  "div",
115
137
  {
116
- ref: m,
117
- className: `${n.track} ${Z ? n.noPointerEvents : ""}`,
118
- style: { width: `${u * 100}%`, transform: ht() },
119
- children: B.map((t, e) => /* @__PURE__ */ s(
138
+ ref: g,
139
+ className: o.track,
140
+ style: { width: `${h * 100}%`, transform: pt() },
141
+ children: F.map((t, e) => /* @__PURE__ */ r(
120
142
  "div",
121
143
  {
122
- className: n.page,
144
+ className: o.page,
123
145
  style: {
124
- display: g > 1 ? "grid" : "flex",
146
+ display: z > 1 ? "grid" : "flex",
125
147
  gridTemplateColumns: `repeat(${Math.ceil(
126
- p / g
148
+ M / z
127
149
  )}, 1fr)`,
128
- gridTemplateRows: `repeat(${g}, auto)`,
129
- width: `${h}px`
150
+ gridTemplateRows: `repeat(${z}, auto)`,
151
+ width: `${v}px`
130
152
  },
131
- children: t.map((r, c) => /* @__PURE__ */ s(
153
+ children: t.map((n, s) => /* @__PURE__ */ r(
132
154
  "div",
133
155
  {
134
- onClickCapture: tt,
156
+ onClickCapture: ct,
135
157
  style: {
136
- width: `${h / g - 16}px`
158
+ width: `${v / z - 16}px`
137
159
  },
138
- children: r
160
+ children: n
139
161
  },
140
- c
162
+ s
141
163
  ))
142
164
  },
143
165
  e
@@ -146,42 +168,42 @@ function It({
146
168
  )
147
169
  }
148
170
  ),
149
- u > 1 && /* @__PURE__ */ E(
171
+ h > 1 && /* @__PURE__ */ A(
150
172
  "div",
151
173
  {
152
- className: n.controls,
174
+ className: o.controls,
153
175
  style: {
154
- maxWidth: I > 0 && f === 1 ? `${I}px` : "unset"
176
+ maxWidth: S > 0 && l === 1 && !w ? `${S}px` : "unset"
155
177
  },
156
178
  children: [
157
- /* @__PURE__ */ s("div", { className: n.indicators, children: Array.from({ length: u }).map((t, e) => /* @__PURE__ */ s(
179
+ /* @__PURE__ */ r("div", { className: o.indicators, children: Array.from({ length: h }).map((t, e) => /* @__PURE__ */ r(
158
180
  "button",
159
181
  {
160
- className: `${n.indicator} ${e === l ? n.active : ""}`,
161
- onClick: () => ut(e),
182
+ className: `${o.indicator} ${e === d ? o.active : ""}`,
183
+ onClick: () => ft(e),
162
184
  "aria-label": `Go to group ${e + 1}`
163
185
  },
164
186
  e
165
187
  )) }),
166
- /* @__PURE__ */ E("div", { className: n.buttons, children: [
167
- /* @__PURE__ */ s(
188
+ /* @__PURE__ */ A("div", { className: o.buttons, children: [
189
+ /* @__PURE__ */ r(
168
190
  "button",
169
191
  {
170
192
  "aria-label": "Previous slide",
171
- className: `${n.prev} ${l === 0 ? n.disabled : ""}`,
172
- onClick: C,
173
- disabled: l === 0,
174
- children: /* @__PURE__ */ s(vt, { size: 36 })
193
+ className: `${o.prev} ${d === 0 ? o.disabled : ""}`,
194
+ onClick: T,
195
+ disabled: d === 0,
196
+ children: /* @__PURE__ */ r(Mt, { size: 36 })
175
197
  }
176
198
  ),
177
- /* @__PURE__ */ s(
199
+ /* @__PURE__ */ r(
178
200
  "button",
179
201
  {
180
202
  "aria-label": "Next slide",
181
- className: `${n.next} ${l >= u - 1 ? n.disabled : ""}`,
182
- onClick: z,
183
- disabled: l >= N.length - p,
184
- children: /* @__PURE__ */ s(bt, { size: 36 })
203
+ className: `${o.next} ${d >= h - 1 ? o.disabled : ""}`,
204
+ onClick: k,
205
+ disabled: d >= _.length - M,
206
+ children: /* @__PURE__ */ r(wt, { size: 36 })
185
207
  }
186
208
  )
187
209
  ] })
@@ -191,5 +213,5 @@ function It({
191
213
  ] });
192
214
  }
193
215
  export {
194
- It as Carousel
216
+ Pt as Carousel
195
217
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "quirk-ui",
3
3
  "private": false,
4
- "version": "0.0.80",
4
+ "version": "0.0.82",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {