@component-hook/picker 1.4.4 → 1.5.1

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,749 +1,451 @@
1
1
  import "./index.css";
2
- import Re, { forwardRef as be, useState as W, useRef as j, useMemo as F, useImperativeHandle as Z, useEffect as G } from "react";
3
- var q = { exports: {} }, H = {};
4
- var ae;
5
- function xe() {
6
- if (ae) return H;
7
- ae = 1;
8
- var e = /* @__PURE__ */ Symbol.for("react.transitional.element"), n = /* @__PURE__ */ Symbol.for("react.fragment");
9
- function r(o, s, a) {
10
- var f = null;
11
- if (a !== void 0 && (f = "" + a), s.key !== void 0 && (f = "" + s.key), "key" in s) {
12
- a = {};
13
- for (var c in s)
14
- c !== "key" && (a[c] = s[c]);
15
- } else a = s;
16
- return s = a.ref, {
17
- $$typeof: e,
18
- type: o,
19
- key: f,
20
- ref: s !== void 0 ? s : null,
21
- props: a
22
- };
23
- }
24
- return H.Fragment = n, H.jsx = r, H.jsxs = r, H;
2
+ import { forwardRef as e, useEffect as t, useImperativeHandle as n, useMemo as r, useRef as i, useState as a } from "react";
3
+ import { Fragment as o, jsx as s, jsxs as c } from "react/jsx-runtime";
4
+ //#region src/shared/constants.ts
5
+ var l = .52, u = .008, d = [
6
+ "year",
7
+ "month",
8
+ "day"
9
+ ], f = [
10
+ "hour",
11
+ "minute",
12
+ "second"
13
+ ], p = Array.isArray;
14
+ //#endregion
15
+ //#region src/shared/utils/common.ts
16
+ function m(e, t) {
17
+ if (y(e)) return "multiple";
18
+ let [n] = e;
19
+ return n?.[t.children] ? "cascade" : "single";
25
20
  }
26
- var z = {};
27
- var ue;
28
- function Oe() {
29
- return ue || (ue = 1, process.env.NODE_ENV !== "production" && (function() {
30
- function e(t) {
31
- if (t == null) return null;
32
- if (typeof t == "function")
33
- return t.$$typeof === E ? null : t.displayName || t.name || null;
34
- if (typeof t == "string") return t;
35
- switch (t) {
36
- case M:
37
- return "Fragment";
38
- case O:
39
- return "Profiler";
40
- case v:
41
- return "StrictMode";
42
- case m:
43
- return "Suspense";
44
- case w:
45
- return "SuspenseList";
46
- case I:
47
- return "Activity";
48
- }
49
- if (typeof t == "object")
50
- switch (typeof t.tag == "number" && console.error(
51
- "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
52
- ), t.$$typeof) {
53
- case x:
54
- return "Portal";
55
- case T:
56
- return t.displayName || "Context";
57
- case l:
58
- return (t._context.displayName || "Context") + ".Consumer";
59
- case g:
60
- var i = t.render;
61
- return t = t.displayName, t || (t = i.displayName || i.name || "", t = t !== "" ? "ForwardRef(" + t + ")" : "ForwardRef"), t;
62
- case A:
63
- return i = t.displayName || null, i !== null ? i : e(t.type) || "Memo";
64
- case Y:
65
- i = t._payload, t = t._init;
66
- try {
67
- return e(t(i));
68
- } catch {
69
- }
70
- }
71
- return null;
72
- }
73
- function n(t) {
74
- return "" + t;
75
- }
76
- function r(t) {
77
- try {
78
- n(t);
79
- var i = !1;
80
- } catch {
81
- i = !0;
82
- }
83
- if (i) {
84
- i = console;
85
- var R = i.error, y = typeof Symbol == "function" && Symbol.toStringTag && t[Symbol.toStringTag] || t.constructor.name || "Object";
86
- return R.call(
87
- i,
88
- "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
89
- y
90
- ), n(t);
91
- }
92
- }
93
- function o(t) {
94
- if (t === M) return "<>";
95
- if (typeof t == "object" && t !== null && t.$$typeof === Y)
96
- return "<...>";
97
- try {
98
- var i = e(t);
99
- return i ? "<" + i + ">" : "<...>";
100
- } catch {
101
- return "<...>";
102
- }
103
- }
104
- function s() {
105
- var t = k.A;
106
- return t === null ? null : t.getOwner();
107
- }
108
- function a() {
109
- return Error("react-stack-top-frame");
110
- }
111
- function f(t) {
112
- if (P.call(t, "key")) {
113
- var i = Object.getOwnPropertyDescriptor(t, "key").get;
114
- if (i && i.isReactWarning) return !1;
115
- }
116
- return t.key !== void 0;
117
- }
118
- function c(t, i) {
119
- function R() {
120
- U || (U = !0, console.error(
121
- "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
122
- i
123
- ));
124
- }
125
- R.isReactWarning = !0, Object.defineProperty(t, "key", {
126
- get: R,
127
- configurable: !0
128
- });
129
- }
130
- function S() {
131
- var t = e(this.type);
132
- return L[t] || (L[t] = !0, console.error(
133
- "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
134
- )), t = this.props.ref, t !== void 0 ? t : null;
135
- }
136
- function d(t, i, R, y, B, K) {
137
- var C = R.ref;
138
- return t = {
139
- $$typeof: b,
140
- type: t,
141
- key: i,
142
- props: R,
143
- _owner: y
144
- }, (C !== void 0 ? C : null) !== null ? Object.defineProperty(t, "ref", {
145
- enumerable: !1,
146
- get: S
147
- }) : Object.defineProperty(t, "ref", { enumerable: !1, value: null }), t._store = {}, Object.defineProperty(t._store, "validated", {
148
- configurable: !1,
149
- enumerable: !1,
150
- writable: !0,
151
- value: 0
152
- }), Object.defineProperty(t, "_debugInfo", {
153
- configurable: !1,
154
- enumerable: !1,
155
- writable: !0,
156
- value: null
157
- }), Object.defineProperty(t, "_debugStack", {
158
- configurable: !1,
159
- enumerable: !1,
160
- writable: !0,
161
- value: B
162
- }), Object.defineProperty(t, "_debugTask", {
163
- configurable: !1,
164
- enumerable: !1,
165
- writable: !0,
166
- value: K
167
- }), Object.freeze && (Object.freeze(t.props), Object.freeze(t)), t;
168
- }
169
- function _(t, i, R, y, B, K) {
170
- var C = i.children;
171
- if (C !== void 0)
172
- if (y)
173
- if (V(C)) {
174
- for (y = 0; y < C.length; y++)
175
- p(C[y]);
176
- Object.freeze && Object.freeze(C);
177
- } else
178
- console.error(
179
- "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
180
- );
181
- else p(C);
182
- if (P.call(i, "key")) {
183
- C = e(t);
184
- var $ = Object.keys(i).filter(function(ke) {
185
- return ke !== "key";
186
- });
187
- y = 0 < $.length ? "{key: someKey, " + $.join(": ..., ") + ": ...}" : "{key: someKey}", ce[C + y] || ($ = 0 < $.length ? "{" + $.join(": ..., ") + ": ...}" : "{}", console.error(
188
- `A props object containing a "key" prop is being spread into JSX:
189
- let props = %s;
190
- <%s {...props} />
191
- React keys must be passed directly to JSX without using spread:
192
- let props = %s;
193
- <%s key={someKey} {...props} />`,
194
- y,
195
- C,
196
- $,
197
- C
198
- ), ce[C + y] = !0);
199
- }
200
- if (C = null, R !== void 0 && (r(R), C = "" + R), f(i) && (r(i.key), C = "" + i.key), "key" in i) {
201
- R = {};
202
- for (var ee in i)
203
- ee !== "key" && (R[ee] = i[ee]);
204
- } else R = i;
205
- return C && c(
206
- R,
207
- typeof t == "function" ? t.displayName || t.name || "Unknown" : t
208
- ), d(
209
- t,
210
- C,
211
- R,
212
- s(),
213
- B,
214
- K
215
- );
216
- }
217
- function p(t) {
218
- u(t) ? t._store && (t._store.validated = 1) : typeof t == "object" && t !== null && t.$$typeof === Y && (t._payload.status === "fulfilled" ? u(t._payload.value) && t._payload.value._store && (t._payload.value._store.validated = 1) : t._store && (t._store.validated = 1));
219
- }
220
- function u(t) {
221
- return typeof t == "object" && t !== null && t.$$typeof === b;
222
- }
223
- var h = Re, b = /* @__PURE__ */ Symbol.for("react.transitional.element"), x = /* @__PURE__ */ Symbol.for("react.portal"), M = /* @__PURE__ */ Symbol.for("react.fragment"), v = /* @__PURE__ */ Symbol.for("react.strict_mode"), O = /* @__PURE__ */ Symbol.for("react.profiler"), l = /* @__PURE__ */ Symbol.for("react.consumer"), T = /* @__PURE__ */ Symbol.for("react.context"), g = /* @__PURE__ */ Symbol.for("react.forward_ref"), m = /* @__PURE__ */ Symbol.for("react.suspense"), w = /* @__PURE__ */ Symbol.for("react.suspense_list"), A = /* @__PURE__ */ Symbol.for("react.memo"), Y = /* @__PURE__ */ Symbol.for("react.lazy"), I = /* @__PURE__ */ Symbol.for("react.activity"), E = /* @__PURE__ */ Symbol.for("react.client.reference"), k = h.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, P = Object.prototype.hasOwnProperty, V = Array.isArray, D = console.createTask ? console.createTask : function() {
224
- return null;
225
- };
226
- h = {
227
- react_stack_bottom_frame: function(t) {
228
- return t();
229
- }
230
- };
231
- var U, L = {}, oe = h.react_stack_bottom_frame.bind(
232
- h,
233
- a
234
- )(), se = D(o(a)), ce = {};
235
- z.Fragment = M, z.jsx = function(t, i, R) {
236
- var y = 1e4 > k.recentlyCreatedOwnerStacks++;
237
- return _(
238
- t,
239
- i,
240
- R,
241
- !1,
242
- y ? Error("react-stack-top-frame") : oe,
243
- y ? D(o(t)) : se
244
- );
245
- }, z.jsxs = function(t, i, R) {
246
- var y = 1e4 > k.recentlyCreatedOwnerStacks++;
247
- return _(
248
- t,
249
- i,
250
- R,
251
- !0,
252
- y ? Error("react-stack-top-frame") : oe,
253
- y ? D(o(t)) : se
254
- );
255
- };
256
- })()), z;
21
+ function h(e) {
22
+ return {
23
+ children: e?.children || "children",
24
+ label: e?.label || "label",
25
+ value: e?.value || "value"
26
+ };
257
27
  }
258
- var ie;
259
- function Me() {
260
- return ie || (ie = 1, process.env.NODE_ENV === "production" ? q.exports = xe() : q.exports = Oe()), q.exports;
28
+ function g(e, t, n) {
29
+ if (y(e)) return [];
30
+ let r = [], i = e, a = 0;
31
+ for (; i;) {
32
+ let e = t[a], o = v(i, e, n);
33
+ o === -1 && (o = 0), r.push(i), a += 1, i = i[o]?.[n.children];
34
+ }
35
+ return r;
261
36
  }
262
- var N = Me();
263
- const ye = Array.isArray;
264
- function Ce(e, n) {
265
- if (Ee(e)) return "multiple";
266
- const [r] = e;
267
- return r?.[n.children] ? "cascade" : "single";
37
+ function _(e, t, n, r) {
38
+ let i = [...n], a = e, o = t + 1;
39
+ for (; a?.[r.children];) {
40
+ let e = a[r.children][0];
41
+ i[o] = e.value, a = e, o += 1;
42
+ }
43
+ return i;
268
44
  }
269
- function we(e) {
270
- return {
271
- children: e?.children || "children",
272
- label: e?.label || "label",
273
- value: e?.value || "value"
274
- };
45
+ function v(e, t, n) {
46
+ return e.findIndex((e) => e?.[n.value] === t);
275
47
  }
276
- function Ae(e, n, r) {
277
- if (Ee(e)) return [];
278
- const o = [];
279
- let s = e, a = 0;
280
- for (; s; ) {
281
- const f = n[a];
282
- let c = Te(s, f, r);
283
- c === -1 && (c = 0), o.push(s), a += 1, s = s[c]?.[r.children];
284
- }
285
- return o;
48
+ function y(e) {
49
+ let [t] = e;
50
+ return p(t);
286
51
  }
287
- function Pe(e, n, r, o) {
288
- const s = [...r];
289
- let a = e, f = n + 1;
290
- for (; a?.[o.children]; ) {
291
- const c = a[o.children][0];
292
- s[f] = c.value, a = c, f += 1;
293
- }
294
- return s;
52
+ function b(e, t) {
53
+ return e > t ? "horizontal" : t > e ? "vertical" : "";
295
54
  }
296
- function Te(e, n, r) {
297
- return e.findIndex((o) => o?.[r.value] === n);
55
+ function x() {
56
+ let { fontSize: e } = getComputedStyle(document.documentElement);
57
+ return Number(e.replace("px", "")) || 16;
298
58
  }
299
- function Ee(e) {
300
- const [n] = e;
301
- return ye(n);
59
+ function S(e, t, n) {
60
+ let r = [];
61
+ for (let i = e; i <= t; i++) {
62
+ let e = n(String(i));
63
+ r.push({
64
+ label: e,
65
+ value: i
66
+ });
67
+ }
68
+ return r;
302
69
  }
303
- function Ne(e, n) {
304
- return e > n ? "horizontal" : n > e ? "vertical" : "";
70
+ function C(e, t) {
71
+ return e === t.getFullYear();
305
72
  }
306
- function X(e, n, r) {
307
- const o = [];
308
- for (let s = e; s <= n; s++) {
309
- const a = r(`${s}`);
310
- o.push({ label: a, value: s });
311
- }
312
- return o;
73
+ function w(e, t) {
74
+ return e === t.getFullYear();
313
75
  }
314
- function le(e, n) {
315
- return e === n.getFullYear();
76
+ function T(e, t) {
77
+ return e === t.getMonth() + 1;
316
78
  }
317
- function fe(e, n) {
318
- return e === n.getFullYear();
79
+ function E(e, t) {
80
+ return e === t.getMonth() + 1;
319
81
  }
320
- function Ye(e, n) {
321
- return e === n.getMonth() + 1;
82
+ function D(e, t) {
83
+ return new Date(e, t, 0).getDate();
322
84
  }
323
- function Ie(e, n) {
324
- return e === n.getMonth() + 1;
85
+ function O(e, t, n) {
86
+ let r = /* @__PURE__ */ new Date(), i = Date.now(), a = e.getTime(), o = t.getTime(), s = i >= a && i <= o;
87
+ return n === "year" ? s ? r.getFullYear() : e.getFullYear() : n === "month" ? (s ? r.getMonth() : e.getMonth()) + 1 : s ? r.getDate() : e.getDate();
325
88
  }
326
- function je(e, n) {
327
- return new Date(e, n, 0).getDate();
89
+ function k(e) {
90
+ return e;
328
91
  }
329
- function de(e, n, r) {
330
- const o = /* @__PURE__ */ new Date(), s = Date.now(), a = e.getTime(), f = n.getTime(), c = s >= a && s <= f;
331
- return r === "year" ? c ? o.getFullYear() : e.getFullYear() : r === "month" ? c ? o.getMonth() + 1 : e.getMonth() + 1 : c ? o.getDate() : e.getDate();
92
+ function A(e) {
93
+ return /^(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d$/.test(e);
332
94
  }
333
- function te(e) {
334
- return e;
95
+ function j(e) {
96
+ if (!A(e)) return null;
97
+ let [t, n, r] = e.split(":", 3);
98
+ return {
99
+ hour: Number(t),
100
+ minute: Number(n),
101
+ second: Number(r)
102
+ };
335
103
  }
336
- function De(e) {
337
- return /^(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d$/.test(e);
104
+ function M(e) {
105
+ return e.padStart(2, "0");
338
106
  }
339
- function me(e) {
340
- if (!De(e)) return null;
341
- const [n, r, o] = e.split(":");
342
- return { hour: Number(n), minute: Number(r), second: Number(o) };
107
+ function N(e, t, n) {
108
+ let r = Date.now(), { hour: i, minute: a, second: o } = e, { hour: s, minute: c, second: l } = t, u = (/* @__PURE__ */ new Date()).setHours(i, a, o), d = (/* @__PURE__ */ new Date()).setHours(s, c, l), f = r >= u && r <= d;
109
+ return n === "hour" ? f ? (/* @__PURE__ */ new Date()).getHours() : i : n === "minute" ? f ? (/* @__PURE__ */ new Date()).getMinutes() : a : f ? (/* @__PURE__ */ new Date()).getSeconds() : o;
343
110
  }
344
- function ne(e) {
345
- return e.padStart(2, "0");
111
+ //#endregion
112
+ //#region src/react/hooks/fixed-forward-ref.ts
113
+ function P(t) {
114
+ return e(t);
346
115
  }
347
- function he(e, n, r) {
348
- const o = Date.now(), { hour: s, minute: a, second: f } = e, { hour: c, minute: S, second: d } = n, _ = (/* @__PURE__ */ new Date()).setHours(s, a, f), p = (/* @__PURE__ */ new Date()).setHours(c, S, d), u = o >= _ && o <= p;
349
- return r === "hour" ? u ? (/* @__PURE__ */ new Date()).getHours() : s : r === "minute" ? u ? (/* @__PURE__ */ new Date()).getMinutes() : a : u ? (/* @__PURE__ */ new Date()).getSeconds() : f;
116
+ //#endregion
117
+ //#region src/shared/utils/pointer.ts
118
+ function F() {
119
+ let e = {
120
+ startX: 0,
121
+ startY: 0,
122
+ deltaX: 0,
123
+ deltaY: 0,
124
+ offsetX: 0,
125
+ offsetY: 0
126
+ }, t = "", n = !0, r = () => t === "vertical", i = () => t === "horizontal";
127
+ function a() {
128
+ e.deltaX = 0, e.deltaY = 0, e.offsetX = 0, e.offsetY = 0, t = "", n = !0;
129
+ }
130
+ function o(t) {
131
+ let n = "touches" in t ? t.touches[0] : t;
132
+ a(), e.startX = n.clientX, e.startY = n.clientY;
133
+ }
134
+ function s(r) {
135
+ if (!e.startX || !e.startY) return !0;
136
+ let i = "touches" in r ? r.touches[0] : r;
137
+ e.deltaX = Math.max(i.clientX, 0) - e.startX, e.deltaY = i.clientY - e.startY, e.offsetX = Math.abs(e.deltaX), e.offsetY = Math.abs(e.deltaY), (!t || e.offsetX < 10 && e.offsetY < 10) && (t = b(e.offsetX, e.offsetY)), n && (e.offsetX > 5 || e.offsetY > 5) && (n = !1);
138
+ }
139
+ function c() {
140
+ e.startX = 0, e.startY = 0;
141
+ }
142
+ return {
143
+ pointer: e,
144
+ move: s,
145
+ start: o,
146
+ stop: c,
147
+ reset: a,
148
+ isVertical: r,
149
+ isHorizontal: i
150
+ };
350
151
  }
351
- function Q(e) {
352
- return be(e);
152
+ //#endregion
153
+ //#region src/react/hooks/use-scroll-snap.ts
154
+ function I({ column: e, onChange: t }) {
155
+ let n = x() / 16, [o, s] = a(0), c = i(null), l = i(0), d = i(0), f = i(0), p = i(0), m = i(!1), h = i(null), { pointer: g, start: _, move: v, stop: y } = r(() => F(), []);
156
+ function b(e) {
157
+ return e * n;
158
+ }
159
+ function S(t) {
160
+ let n = e.length, r = Math.round(-t / b(48));
161
+ return r < 0 ? 0 : r >= n ? n - 1 : r;
162
+ }
163
+ function C(e) {
164
+ let n = -e * b(48), r = () => t?.(e);
165
+ m.current && n !== l.current ? h.current = r : r(), E(n);
166
+ }
167
+ function w(e) {
168
+ _(e), m.current = !0, s(0), f.current = Date.now(), d.current = l.current, p.current = d.current, h.current = null;
169
+ }
170
+ function T(t) {
171
+ if (v(t)) return;
172
+ let n = e.length, r = d.current + g.deltaY, i = b((n - 1) * -48), a = Math.min(Math.max(r, i), 0), o = Date.now();
173
+ E(a), !(o - f.current <= 300) && (f.current = o, p.current = a);
174
+ }
175
+ function E(e) {
176
+ l.current = e, c.current && c.current.style.setProperty("--offset-y", String(e));
177
+ }
178
+ function D() {
179
+ y();
180
+ let e = l.current - p.current, t = Date.now() - f.current;
181
+ if (t < 300 && Math.abs(e) > 15) {
182
+ O(e, t);
183
+ return;
184
+ }
185
+ let n = S(l.current);
186
+ s(150), C(n), m.current = !1;
187
+ }
188
+ function O(e, t) {
189
+ let n = Math.abs(e / t), r = S(l.current + n / u * (e < 0 ? -1 : 1));
190
+ s(300), C(r);
191
+ }
192
+ function k() {
193
+ s(0), m.current = !1, h.current &&= (h.current(), null);
194
+ }
195
+ function A(e, t = "auto") {
196
+ m.current && t === "smooth" || (h.current = null, m.current = t === "smooth", s(t === "smooth" ? 150 : 0), C(e));
197
+ }
198
+ return {
199
+ columnRef: c,
200
+ transitionDuration: o,
201
+ onPointerDown: w,
202
+ onPointerMove: T,
203
+ onPointerUp: D,
204
+ stopInertialSliding: k,
205
+ scrollToIndex: A
206
+ };
353
207
  }
354
- const Fe = 16, J = 48, Ve = 0.52, pe = 150, re = 300, $e = 15, Xe = 8e-3, ge = 5, Ue = ["year", "month", "day"], Le = ["hour", "minute", "second"];
355
- function He() {
356
- const e = {
357
- startX: 0,
358
- startY: 0,
359
- deltaX: 0,
360
- deltaY: 0,
361
- offsetX: 0,
362
- offsetY: 0
363
- };
364
- let n = "", r = !0;
365
- const o = () => n === "vertical", s = () => n === "horizontal";
366
- function a() {
367
- e.deltaX = 0, e.deltaY = 0, e.offsetX = 0, e.offsetY = 0, n = "", r = !0;
368
- }
369
- function f(d) {
370
- const _ = "touches" in d ? d.touches[0] : d;
371
- a(), e.startX = _.clientX, e.startY = _.clientY;
372
- }
373
- function c(d) {
374
- if (!e.startX || !e.startY) return !0;
375
- const _ = "touches" in d ? d.touches[0] : d;
376
- e.deltaX = Math.max(_.clientX, 0) - e.startX, e.deltaY = _.clientY - e.startY, e.offsetX = Math.abs(e.deltaX), e.offsetY = Math.abs(e.deltaY);
377
- const p = 10;
378
- (!n || e.offsetX < p && e.offsetY < p) && (n = Ne(e.offsetX, e.offsetY)), r && (e.offsetX > ge || e.offsetY > ge) && (r = !1);
379
- }
380
- function S() {
381
- e.startX = 0, e.startY = 0;
382
- }
383
- return {
384
- pointer: e,
385
- move: c,
386
- start: f,
387
- stop: S,
388
- reset: a,
389
- isVertical: o,
390
- isHorizontal: s
391
- };
208
+ //#endregion
209
+ //#region src/react/components/picker-column.tsx
210
+ function L({ column: e, fields: t, selectedIndex: r = 0, onChange: i }, a) {
211
+ let { columnRef: o, transitionDuration: c, onPointerDown: u, onPointerMove: d, onPointerUp: f, stopInertialSliding: p, scrollToIndex: m } = I({
212
+ column: e,
213
+ onChange: h
214
+ });
215
+ function h(e) {
216
+ e !== r && i(e);
217
+ }
218
+ function g(e = r, t) {
219
+ m(e, t);
220
+ }
221
+ function _(e) {
222
+ e !== r && g(e, "smooth");
223
+ }
224
+ return n(a, () => ({ scrollToSelected: g })), /* @__PURE__ */ s("div", {
225
+ role: "presentation",
226
+ "aria-label": "Picker column",
227
+ className: "chook-picker-column",
228
+ onTouchStart: u,
229
+ onTouchMove: d,
230
+ onTouchEnd: f,
231
+ onTouchCancel: f,
232
+ onMouseDown: u,
233
+ onMouseMove: d,
234
+ onMouseUp: f,
235
+ onMouseLeave: f,
236
+ style: {
237
+ overflowY: "hidden",
238
+ touchAction: "none"
239
+ },
240
+ children: /* @__PURE__ */ s("ul", {
241
+ ref: o,
242
+ style: {
243
+ overflowY: "hidden",
244
+ transform: "translate3d(0, calc(var(--offset-y) * 1px), 0)",
245
+ transitionDuration: `${c}ms`,
246
+ transitionProperty: c ? "all" : "none",
247
+ touchAction: "none"
248
+ },
249
+ onTransitionEnd: p,
250
+ children: e.map((e, n) => /* @__PURE__ */ s("div", {
251
+ tabIndex: 0,
252
+ role: "button",
253
+ "aria-label": "Select option",
254
+ className: "chook-picker-column-item",
255
+ onClick: () => _(n),
256
+ onKeyDown: (e) => {
257
+ (e.key === "Enter" || e.key === " ") && _(n);
258
+ },
259
+ children: /* @__PURE__ */ s("p", {
260
+ className: "chook-picker-column-label",
261
+ style: { transform: `rotate3d(1, 0, 0, calc((${n * 48} + var(--offset-y)) * ${l}deg)` },
262
+ children: e?.[t.label]
263
+ })
264
+ }, e?.[t.value]))
265
+ })
266
+ });
392
267
  }
393
- function ze({ column: e, onChange: n }) {
394
- const o = Number.parseFloat(getComputedStyle(document.documentElement).fontSize) / Fe, [s, a] = W(0), f = j(null), c = j(0), S = j(0), d = j(0), _ = j(0), p = j(!1), u = j(null), { pointer: h, start: b, move: x, stop: M } = F(() => He(), []);
395
- function v(E) {
396
- return E * o;
397
- }
398
- function O(E) {
399
- const k = e.length, P = Math.round(-E / v(J));
400
- return P < 0 ? 0 : P >= k ? k - 1 : P;
401
- }
402
- function l(E) {
403
- const k = -E * v(J), P = () => n?.(E);
404
- p.current && k !== c.current ? u.current = P : P(), m(k);
405
- }
406
- function T(E) {
407
- b(E), p.current = !0, a(0), d.current = Date.now(), S.current = c.current, _.current = S.current, u.current = null;
408
- }
409
- function g(E) {
410
- if (x(E)) return;
411
- const P = e.length, V = S.current + h.deltaY, D = v((P - 1) * -J), U = Math.min(Math.max(V, D), 0), L = Date.now();
412
- m(U), !(L - d.current <= re) && (d.current = L, _.current = U);
413
- }
414
- function m(E) {
415
- c.current = E, f.current && f.current.style.setProperty("--offset-y", `${E}`);
416
- }
417
- function w() {
418
- M();
419
- const E = c.current - _.current, k = Date.now() - d.current;
420
- if (k < re && Math.abs(E) > $e) {
421
- A(E, k);
422
- return;
423
- }
424
- const P = O(c.current);
425
- a(pe), l(P), p.current = !1;
426
- }
427
- function A(E, k) {
428
- const P = Math.abs(E / k), V = c.current + P / Xe * (E < 0 ? -1 : 1), D = O(V);
429
- a(re), l(D);
430
- }
431
- function Y() {
432
- a(0), p.current = !1, u.current && (u.current(), u.current = null);
433
- }
434
- function I(E, k = "auto") {
435
- p.current && k === "smooth" || (u.current = null, p.current = k === "smooth", a(k === "smooth" ? pe : 0), l(E));
436
- }
437
- return {
438
- columnRef: f,
439
- transitionDuration: s,
440
- onPointerDown: T,
441
- onPointerMove: g,
442
- onPointerUp: w,
443
- stopInertialSliding: Y,
444
- scrollToIndex: I
445
- };
268
+ var R = P(L);
269
+ R.displayName = "Column";
270
+ //#endregion
271
+ //#region src/react/components/picker-columns.tsx
272
+ function z(e, t) {
273
+ let { loading: r, loadingSlot: a, columns: l, emptySlot: u, currentColumns: d, fields: f, selectedIndices: p, updateSelectedValueByIndex: m } = e, h = i([]);
274
+ function g(e, t) {
275
+ h.current[e]?.scrollToSelected(t);
276
+ }
277
+ return n(t, () => ({ scrollColumnToSelected: g })), r ? /* @__PURE__ */ c(o, { children: [/* @__PURE__ */ s("div", {
278
+ className: "chook-picker-loading",
279
+ children: a
280
+ }), /* @__PURE__ */ s("div", { className: "chook-picker-columns" })] }) : l.length ? /* @__PURE__ */ c("div", {
281
+ className: "chook-picker-columns chook-picker-columns-backdrop",
282
+ onTouchMove: (e) => e.stopPropagation(),
283
+ children: [d.map((e, t) => /* @__PURE__ */ s(R, {
284
+ ref: (e) => {
285
+ h.current[t] = e;
286
+ },
287
+ column: e,
288
+ fields: f,
289
+ selectedIndex: p[t],
290
+ onChange: (e) => m(t, e)
291
+ }, t)), /* @__PURE__ */ s("div", { className: "chook-picker-mask-backdrop" })]
292
+ }) : /* @__PURE__ */ s("div", {
293
+ className: "chook-picker-columns",
294
+ children: u
295
+ });
446
296
  }
447
- function We({ column: e, fields: n, selectedIndex: r = 0, onChange: o }, s) {
448
- const {
449
- columnRef: a,
450
- transitionDuration: f,
451
- onPointerDown: c,
452
- onPointerMove: S,
453
- onPointerUp: d,
454
- stopInertialSliding: _,
455
- scrollToIndex: p
456
- } = ze({
457
- column: e,
458
- onChange: u
459
- });
460
- function u(x) {
461
- x !== r && o(x);
462
- }
463
- function h(x = r, M) {
464
- p(x, M);
465
- }
466
- function b(x) {
467
- x !== r && h(x, "smooth");
468
- }
469
- return Z(s, () => ({
470
- scrollToSelected: h
471
- })), /* @__PURE__ */ N.jsx(
472
- "div",
473
- {
474
- role: "presentation",
475
- "aria-label": "Picker column",
476
- className: "chook-picker-column",
477
- onTouchStart: c,
478
- onTouchMove: S,
479
- onTouchEnd: d,
480
- onTouchCancel: d,
481
- onMouseDown: c,
482
- onMouseMove: S,
483
- onMouseUp: d,
484
- onMouseLeave: d,
485
- style: {
486
- overflowY: "hidden",
487
- touchAction: "none"
488
- },
489
- children: /* @__PURE__ */ N.jsx(
490
- "ul",
491
- {
492
- ref: a,
493
- style: {
494
- overflowY: "hidden",
495
- transform: "translate3d(0, calc(var(--offset-y) * 1px), 0)",
496
- transitionDuration: `${f}ms`,
497
- transitionProperty: f ? "all" : "none",
498
- touchAction: "none"
499
- },
500
- onTransitionEnd: _,
501
- children: e.map((x, M) => /* @__PURE__ */ N.jsx(
502
- "div",
503
- {
504
- tabIndex: 0,
505
- role: "button",
506
- "aria-label": "Select option",
507
- className: "chook-picker-column-item",
508
- onClick: () => b(M),
509
- onKeyDown: (v) => {
510
- (v.key === "Enter" || v.key === " ") && b(M);
511
- },
512
- children: /* @__PURE__ */ N.jsx(
513
- "p",
514
- {
515
- className: "chook-picker-column-label",
516
- style: {
517
- transform: `rotate3d(1, 0, 0, calc((${M * J} + var(--offset-y)) * ${Ve}deg)`
518
- },
519
- children: x?.[n.label]
520
- }
521
- )
522
- },
523
- x?.[n.value]
524
- ))
525
- }
526
- )
527
- }
528
- );
297
+ var B = P(z);
298
+ B.displayName = "Columns";
299
+ //#endregion
300
+ //#region src/react/components/picker.tsx
301
+ function V({ values: e, columns: n, loading: o = !1, loadingSlot: c, emptySlot: l, columnsFieldNames: u, onChange: d }) {
302
+ let [f, p] = a(e ?? []), [y, b] = a([]), x = i(null), S = h(u), C = m(n, S), w = r(() => C === "single" ? [n] : C === "multiple" ? n : g(n, f, S), [
303
+ n,
304
+ C,
305
+ f,
306
+ S
307
+ ]);
308
+ function T(e, t) {
309
+ let n = w[e], r = n[t]?.[S.value];
310
+ if (r === f[e]) return;
311
+ let i = [...f];
312
+ if (i[e] = r, C === "cascade") {
313
+ let r = n[t], a = _(r, e, i, S);
314
+ p(a), d?.(a);
315
+ } else p(i), d?.(i);
316
+ }
317
+ function E(e) {
318
+ return e.some((e, t) => e !== f[t]);
319
+ }
320
+ return t(() => {
321
+ !e || !E(e) || p([...e]);
322
+ }, [e]), t(() => {
323
+ let e = w.length, t = [], n = [...f], r = !1;
324
+ for (let i = 0; i < e; i++) {
325
+ let e = w[i], a = f[i], o = v(e, a, S);
326
+ if (o === -1) {
327
+ let r = (y[i] ?? 0) >= e.length ? Math.max(e.length - 1, 0) : 0;
328
+ n[i] = e[r]?.[S.value], t[i] = r;
329
+ } else t[i] = o;
330
+ t[i] !== y[i] && (x.current?.scrollColumnToSelected(i, t[i]), r = !0);
331
+ }
332
+ r && (p(n), b(t));
333
+ }, [
334
+ f,
335
+ w,
336
+ S
337
+ ]), /* @__PURE__ */ s("div", {
338
+ className: "chook-picker-container",
339
+ "aria-label": "Picker",
340
+ children: /* @__PURE__ */ s(B, {
341
+ ref: x,
342
+ loading: o,
343
+ loadingSlot: c,
344
+ columns: n,
345
+ emptySlot: l,
346
+ currentColumns: w,
347
+ fields: S,
348
+ selectedIndices: y,
349
+ updateSelectedValueByIndex: T
350
+ })
351
+ });
529
352
  }
530
- const _e = Q(We);
531
- _e.displayName = "Column";
532
- function Be(e, n) {
533
- const {
534
- loading: r,
535
- loadingSlot: o,
536
- columns: s,
537
- emptySlot: a,
538
- currentColumns: f,
539
- fields: c,
540
- selectedIndices: S,
541
- updateSelectedValueByIndex: d
542
- } = e, _ = j([]);
543
- function p(u, h) {
544
- _.current[u]?.scrollToSelected(h);
545
- }
546
- return Z(n, () => ({
547
- scrollColumnToSelected: p
548
- })), r ? /* @__PURE__ */ N.jsxs(N.Fragment, { children: [
549
- /* @__PURE__ */ N.jsx("div", { className: "chook-picker-loading", children: o }),
550
- /* @__PURE__ */ N.jsx("div", { className: "chook-picker-columns" })
551
- ] }) : s.length ? /* @__PURE__ */ N.jsxs(
552
- "div",
553
- {
554
- className: "chook-picker-columns chook-picker-columns-backdrop",
555
- onTouchMove: (u) => u.stopPropagation(),
556
- children: [
557
- f.map((u, h) => /* @__PURE__ */ N.jsx(
558
- _e,
559
- {
560
- ref: (b) => {
561
- _.current[h] = b;
562
- },
563
- column: u,
564
- fields: c,
565
- selectedIndex: S[h],
566
- onChange: (b) => d(h, b)
567
- },
568
- h
569
- )),
570
- /* @__PURE__ */ N.jsx("div", { className: "chook-picker-mask-backdrop" })
571
- ]
572
- }
573
- ) : /* @__PURE__ */ N.jsx("div", { className: "chook-picker-columns", children: a });
353
+ //#endregion
354
+ //#region src/react/components/date-picker.tsx
355
+ function H({ values: e, columnsType: i = d, minDate: o = new Date((/* @__PURE__ */ new Date()).getFullYear() - 10, 0, 1), maxDate: c = new Date((/* @__PURE__ */ new Date()).getFullYear() + 10, 11, 31), formatYearLabel: l = k, formatMonthLabel: u = k, formatDayLabel: f = k, onChange: p }, m) {
356
+ let [h, g] = a([]), _ = r(() => e ?? h, [e, h]), v = r(() => {
357
+ let e = {
358
+ year: y,
359
+ month: b,
360
+ day: x
361
+ };
362
+ return i.map((t) => e[t]());
363
+ }, [
364
+ i,
365
+ o,
366
+ c,
367
+ _,
368
+ l,
369
+ u,
370
+ f
371
+ ]);
372
+ function y() {
373
+ return S(o.getFullYear(), c.getFullYear(), l);
374
+ }
375
+ function b() {
376
+ let e = A("year");
377
+ return S(C(e, o) ? o.getMonth() + 1 : 1, w(e, c) ? c.getMonth() + 1 : 12, u);
378
+ }
379
+ function x() {
380
+ let e = A("year"), t = A("month"), n = C(e, o) && T(t, o), r = w(e, c) && E(t, c);
381
+ return S(n ? o.getDate() : 1, r ? c.getDate() : D(e, t), f);
382
+ }
383
+ function A(e) {
384
+ let t = i.indexOf(e), n = _?.[t];
385
+ return n ? Number(n) : O(o, c, e);
386
+ }
387
+ function j(t) {
388
+ e || g(t), p?.(t);
389
+ }
390
+ function M() {
391
+ j(i.map((e) => O(o, c, e)));
392
+ }
393
+ return t(() => {
394
+ (!e || !e.length) && M();
395
+ }, []), n(m, () => ({ setCurrentDate: M })), /* @__PURE__ */ s(V, {
396
+ values: _,
397
+ columns: v,
398
+ onChange: j
399
+ });
574
400
  }
575
- const Se = Q(Be);
576
- Se.displayName = "Columns";
577
- function ve({
578
- values: e,
579
- columns: n,
580
- loading: r = !1,
581
- loadingSlot: o,
582
- emptySlot: s,
583
- columnsFieldNames: a,
584
- onChange: f
585
- }) {
586
- const [c, S] = W(e ?? []), [d, _] = W([]), p = j(null), u = we(a), h = Ce(n, u), b = F(() => h === "single" ? [n] : h === "multiple" ? n : Ae(n, c, u), [n, h, c, u]);
587
- function x(v, O) {
588
- const l = b[v], T = l[O]?.[u.value], g = c[v];
589
- if (T === g) return;
590
- const m = [...c];
591
- if (m[v] = T, h === "cascade") {
592
- const w = l[O], A = Pe(w, v, m, u);
593
- S(A), f?.(A);
594
- } else
595
- S(m), f?.(m);
596
- }
597
- function M(v) {
598
- return v.some((O, l) => O !== c[l]);
599
- }
600
- return G(() => {
601
- !e || !M(e) || S([...e]);
602
- }, [e]), G(() => {
603
- const v = b.length, O = [], l = [...c];
604
- let T = !1;
605
- for (let g = 0; g < v; g++) {
606
- const m = b[g], w = c[g], A = Te(m, w, u);
607
- if (A === -1) {
608
- const I = (d[g] ?? 0) >= m.length ? Math.max(m.length - 1, 0) : 0;
609
- l[g] = m[I]?.[u.value], O[g] = I;
610
- } else
611
- O[g] = A;
612
- O[g] !== d[g] && (p.current?.scrollColumnToSelected(g, O[g]), T = !0);
613
- }
614
- T && (S(l), _(O));
615
- }, [c, b, u]), /* @__PURE__ */ N.jsx(
616
- "div",
617
- {
618
- className: "chook-picker-container",
619
- "aria-label": "Picker",
620
- children: /* @__PURE__ */ N.jsx(
621
- Se,
622
- {
623
- ref: p,
624
- loading: r,
625
- loadingSlot: o,
626
- columns: n,
627
- emptySlot: s,
628
- currentColumns: b,
629
- fields: u,
630
- selectedIndices: d,
631
- updateSelectedValueByIndex: x
632
- }
633
- )
634
- }
635
- );
401
+ var U = P(H);
402
+ U.displayName = "DatePicker";
403
+ //#endregion
404
+ //#region src/react/components/time-picker.tsx
405
+ function W({ values: e, columnsType: i = f, minTime: o, maxTime: c, formatHourLabel: l = M, formatMinuteLabel: u = M, formatSecondLabel: d = M, onChange: p }, m) {
406
+ let [h, g] = a([]), _ = r(() => e ?? h, [e, h]), v = r(() => j(o ?? "") ?? {
407
+ hour: 0,
408
+ minute: 0,
409
+ second: 0
410
+ }, [o]), y = r(() => j(c ?? "") ?? {
411
+ hour: 23,
412
+ minute: 59,
413
+ second: 59
414
+ }, [c]), b = {
415
+ hour: C,
416
+ minute: w,
417
+ second: T
418
+ }, x = i.map((e) => b[e]());
419
+ function C() {
420
+ return S(v.hour, y.hour, l);
421
+ }
422
+ function w() {
423
+ let e = E("hour"), { hour: t, minute: n } = v, { hour: r, minute: i } = y;
424
+ return S(e === t ? n : 0, e === r ? i : 59, u);
425
+ }
426
+ function T() {
427
+ let e = E("hour"), t = E("minute"), { hour: n, minute: r, second: i } = v, { hour: a, minute: o, second: s } = y;
428
+ return S(e === n && t === r ? i : 0, e === a && t === o ? s : 59, d);
429
+ }
430
+ function E(e) {
431
+ let t = i.indexOf(e), n = _?.[t];
432
+ return n === void 0 ? N(v, y, e) : Number(n);
433
+ }
434
+ function D(t) {
435
+ e || g(t), p?.(t);
436
+ }
437
+ function O() {
438
+ D(i.map((e) => N(v, y, e)));
439
+ }
440
+ return t(() => {
441
+ (!e || !e.length) && O();
442
+ }, []), n(m, () => ({ setCurrentTime: O })), /* @__PURE__ */ s(V, {
443
+ values: _,
444
+ columns: x,
445
+ onChange: D
446
+ });
636
447
  }
637
- function qe({
638
- values: e,
639
- columnsType: n = Ue,
640
- minDate: r = new Date((/* @__PURE__ */ new Date()).getFullYear() - 10, 0, 1),
641
- maxDate: o = new Date((/* @__PURE__ */ new Date()).getFullYear() + 10, 11, 31),
642
- formatYearLabel: s = te,
643
- formatMonthLabel: a = te,
644
- formatDayLabel: f = te,
645
- onChange: c
646
- }, S) {
647
- const [d, _] = W([]), p = F(() => e ?? d, [e, d]), u = F(() => {
648
- const l = {
649
- year: h,
650
- month: b,
651
- day: x
652
- };
653
- return n.map((T) => l[T]());
654
- }, [n, r, o, p, s, a, f]);
655
- function h() {
656
- const l = r.getFullYear(), T = o.getFullYear();
657
- return X(l, T, s);
658
- }
659
- function b() {
660
- const l = M("year"), T = le(l, r) ? r.getMonth() + 1 : 1, g = fe(l, o) ? o.getMonth() + 1 : 12;
661
- return X(T, g, a);
662
- }
663
- function x() {
664
- const l = M("year"), T = M("month"), g = le(l, r) && Ye(T, r), m = fe(l, o) && Ie(T, o), w = g ? r.getDate() : 1, A = m ? o.getDate() : je(l, T);
665
- return X(w, A, f);
666
- }
667
- function M(l) {
668
- const T = n.indexOf(l), g = p?.[T];
669
- return g ? Number(g) : de(r, o, l);
670
- }
671
- function v(l) {
672
- e || _(l), c?.(l);
673
- }
674
- function O() {
675
- const l = n.map((T) => de(r, o, T));
676
- v(l);
677
- }
678
- return G(() => {
679
- (!e || !e.length) && O();
680
- }, []), Z(S, () => ({
681
- setCurrentDate: O
682
- })), /* @__PURE__ */ N.jsx(
683
- ve,
684
- {
685
- values: p,
686
- columns: u,
687
- onChange: v
688
- }
689
- );
690
- }
691
- const Je = Q(qe);
692
- Je.displayName = "DatePicker";
693
- function Ge({
694
- values: e,
695
- columnsType: n = Le,
696
- minTime: r,
697
- maxTime: o,
698
- formatHourLabel: s = ne,
699
- formatMinuteLabel: a = ne,
700
- formatSecondLabel: f = ne,
701
- onChange: c
702
- }, S) {
703
- const [d, _] = W([]), p = F(() => e ?? d, [e, d]), u = F(() => me(r ?? "") ?? { hour: 0, minute: 0, second: 0 }, [r]), h = F(() => me(o ?? "") ?? { hour: 23, minute: 59, second: 59 }, [o]), b = {
704
- hour: M,
705
- minute: v,
706
- second: O
707
- }, x = n.map((m) => b[m]());
708
- function M() {
709
- return X(u.hour, h.hour, s);
710
- }
711
- function v() {
712
- const m = l("hour"), { hour: w, minute: A } = u, { hour: Y, minute: I } = h;
713
- return X(m === w ? A : 0, m === Y ? I : 59, a);
714
- }
715
- function O() {
716
- const m = l("hour"), w = l("minute"), { hour: A, minute: Y, second: I } = u, { hour: E, minute: k, second: P } = h;
717
- return X(m === A && w === Y ? I : 0, m === E && w === k ? P : 59, f);
718
- }
719
- function l(m) {
720
- const w = n.indexOf(m), A = p?.[w];
721
- return A !== void 0 ? Number(A) : he(u, h, m);
722
- }
723
- function T(m) {
724
- e || _(m), c?.(m);
725
- }
726
- function g() {
727
- const m = n.map((w) => he(u, h, w));
728
- T(m);
729
- }
730
- return G(() => {
731
- (!e || !e.length) && g();
732
- }, []), Z(S, () => ({
733
- setCurrentTime: g
734
- })), /* @__PURE__ */ N.jsx(
735
- ve,
736
- {
737
- values: p,
738
- columns: x,
739
- onChange: T
740
- }
741
- );
742
- }
743
- const Ze = Q(Ge);
744
- Ze.displayName = "TimePicker";
745
- export {
746
- Je as DatePicker,
747
- ve as Picker,
748
- Ze as TimePicker
749
- };
448
+ var G = P(W);
449
+ G.displayName = "TimePicker";
450
+ //#endregion
451
+ export { U as DatePicker, V as Picker, G as TimePicker };