@dotss/ui 1.5.0 → 1.6.0

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,4 +1,4 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const p=require("@emotion/react/jsx-runtime"),c=require("react"),oe=require("@emotion/styled"),se=require("../hooks/useCheckHasFocus/useCheckHasFocus.cjs"),ae=require("../hooks/useCheckHoverPossible/useCheckHoverPossible.cjs"),ce=require("../hooks/useCheckKeyboardMode/useCheckKeyboardMode.cjs"),le=l=>l&&l.__esModule?l:{default:l},C=le(oe),ue=C.default.div`
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const y=require("@emotion/react/jsx-runtime"),c=require("react"),le=require("@emotion/styled"),ue=require("../hooks/useCheckHasFocus/useCheckHasFocus.cjs"),he=require("../hooks/useCheckHoverPossible/useCheckHoverPossible.cjs"),de=require("../hooks/useCheckKeyboardMode/useCheckKeyboardMode.cjs"),fe=l=>l&&l.__esModule?l:{default:l},D=fe(le),ge=D.default.div`
2
2
  list-style-type: none;
3
3
  margin: 0;
4
4
  padding: 0;
@@ -8,7 +8,7 @@
8
8
  position: relative;
9
9
  cursor: grab;
10
10
  transition: transform 0.3s ease-out;
11
- `,de=C.default.div`
11
+ `,me=D.default.div`
12
12
  position: relative;
13
13
  width: auto;
14
14
  height: fit-content;
@@ -40,7 +40,7 @@
40
40
  @supports not selector(:has(:focus-visible)) {
41
41
  ${({focusWithin:l,theme:i})=>l?{outline:`${i.palette.grey[100]} solid 2px`}:{}}
42
42
  }
43
- `,w=C.default.div`
43
+ `,k=D.default.div`
44
44
  height: 54px;
45
45
  display: flex;
46
46
  align-items: center;
@@ -48,7 +48,7 @@
48
48
  scroll-snap-align: start;
49
49
  position: relative;
50
50
 
51
- ${({theme:{palette:{grey:l},typography:{h2M:i},spacing:{content:u}}})=>({fontSize:i.size,fontWeight:i.weight,lineHeight:i.lineHeight,letterSpacing:i.letterSpacing,color:l[100],padding:u(3)})};
51
+ ${({theme:{palette:{grey:l},typography:{h2M:i},spacing:{content:h}}})=>({fontSize:i.size,fontWeight:i.weight,lineHeight:i.lineHeight,letterSpacing:i.letterSpacing,color:l[100],padding:h(3)})};
52
52
 
53
- ${({selected:l,theme:{palette:{grey:i},typography:{h4M:u}}})=>l?{"&, & *":{color:`${i[100]} !important`}}:{color:`${i[30]} !important`,fontSize:`${u.size} !important`,fontWeight:`${u.weight} !important`,lineHeight:`${u.lineHeight} !important`,letterSpacing:`${u.letterSpacing} !important`,"& *":{color:`${i[30]} !important`}}}
54
- `,f=Object.freeze({FRICTION:.95,SNAP_FORCE:.2,SNAP_VELOCITY_THRESHOLD:.04,MIN_VELOCITY:.01,MAX_VELOCITY:1.62,NEAR_ZERO_VELOCITY:.2,BOUNDARY_PX:4}),he=c.forwardRef(function({column:i,value:u=i[0].value,onChange:b,renderLabel:O,inlineCSS:R,wrapperProps:m,thumbProps:L,...Y},F){const A=i.findIndex(e=>e.value===u),S=c.useRef(A),s=c.useRef(null),[E,g]=c.useState(A*54),[y,D]=c.useState(!1),[I,$]=c.useState(0),[M,V]=c.useState(0),[T,H]=c.useState(!1),[q,P]=c.useState([]),j=c.useId(),d=c.useRef(null),{isHoverPossible:U}=ae.default(),{isKeyboardMode:W}=ce.default(),{hasFocus:z}=se.default({ref:s}),X=e=>{if(e.length<2)return 0;const t=e[0],n=e[e.length-1],r=n.time-t.time,a=n.y-t.y;if(r===0)return 0;const o=a/r;return Math.max(-f.MAX_VELOCITY,Math.min(f.MAX_VELOCITY,o))},K=e=>{d.current&&cancelAnimationFrame(d.current),H(!0);let t=e*-1,n=E,r=performance.now();const a=54*(i.length-1),o=h=>{const x=h-r;r=h,n+=t*x,n<0?(n=0,t=0):n>a&&(n=a,t=0),t*=f.FRICTION,g(n),s.current&&(s.current.children[0].scrollTop=n);const _=Math.round(n/54)*54,te=Math.abs(n-_),ne=Math.abs(t)<=f.NEAR_ZERO_VELOCITY,ie=Math.abs(t)<=f.SNAP_VELOCITY_THRESHOLD,re=te<=f.BOUNDARY_PX;ne&&re||ie?(H(!1),B(n)):d.current=requestAnimationFrame(o)};d.current=requestAnimationFrame(o)},B=e=>{d.current&&cancelAnimationFrame(d.current);const t=Math.max(0,Math.min(Math.round(e/54),i.length-1)),n=t*54;S.current=t;const r=a=>{if(Math.abs(a-n)<1)g(n),s.current&&(s.current.children[0].scrollTop=n),i[t]&&b(i[t].value);else{const o=a+(n-a)*f.SNAP_FORCE;g(o),s.current&&(s.current.children[0].scrollTop=o),d.current=requestAnimationFrame(()=>r(o))}};d.current=requestAnimationFrame(()=>r(e))},N=e=>{D(!0),V(e),$(E),H(!1),P([{time:performance.now(),y:e}])},Z=e=>{if(!y||T)return;const t=M-e;let n=I+t;const r=54*(i.length-1);n<0?n=0:n>r&&(n=r),g(n),s.current&&(s.current.children[0].scrollTop=n);const a=performance.now();P(o=>[...o,{time:a,y:e}].filter(h=>a-h.time<=100))},G=e=>{var n,r;e.stopPropagation();let t=S.current;e.key==="ArrowUp"?(t+=1,t>i.length-1&&(t=0)):e.key==="ArrowDown"?(t-=1,t<0&&(t=i.length-1)):e.key==="PageUp"?(t+=5,t>i.length-1&&(t=0)):e.key==="PageDown"?(t-=5,t<0&&(t=i.length-1)):e.key==="Home"?t=0:e.key==="End"&&(t=i.length-1),b(i[t].value),S.current=t,(r=(n=s.current)==null?void 0:n.querySelector(`.chain-picker-item[data-index="${S.current}"]`))==null||r.focus()},J=e=>{e.preventDefault(),e.stopPropagation(),N(e.clientY)},Q=e=>N(e.touches[0].clientY),ee=e=>{e.preventDefault(),e.stopPropagation(),Z(e.clientY)},v=e=>{if(!y||(D(!1),!U&&e.type==="mouseup"))return;const t=X(q);if(Math.abs(t)<f.MIN_VELOCITY){const r=e.target.closest("[data-index]");if(r){const a=Number(r.dataset.index);if(i[a]&&s.current){const o=s.current.children[0];o.scrollTo({top:a*54,behavior:"smooth"});const h=()=>{Math.abs(o.scrollTop-a*54)<1&&(b(i[a].value),o.removeEventListener("scroll",h))};o.addEventListener("scroll",h)}}return}K(t)};return c.useLayoutEffect(()=>{const t=i.findIndex(n=>n.value===u)*54;g(t),s.current&&(s.current.children[0].scrollTop=t)},[u,i,54]),c.useLayoutEffect(()=>()=>{d.current&&cancelAnimationFrame(d.current)},[]),c.useEffect(()=>{const e=s.current;if(!e)return;const t=n=>{const r=n;if(r.preventDefault(),r.stopPropagation(),!y||T)return;const a=M-r.touches[0].clientY;let o=I+a;const h=54*(i.length-1);o<0?o=0:o>h&&(o=h),g(o),s.current&&(s.current.children[0].scrollTop=o);const x=performance.now();P(k=>[...k,{time:x,y:r.touches[0].clientY}].filter(_=>x-_.time<=100))};return e.addEventListener("touchmove",t,{passive:!1}),()=>{e.removeEventListener("touchmove",t)}},[y,T,M,I,54,i.length]),p.jsx(de,{ref:s,...m,css:m==null?void 0:m.inlineCSS,focusWithin:W&&z,children:p.jsx(ue,{role:"group",ref:F,css:R,...Y,onMouseDown:J,onMouseMove:ee,onMouseUp:v,onMouseLeave:v,onTouchStart:Q,onTouchEnd:v,onTouchCancel:v,children:i.map((e,t)=>{const n=Math.round(E/54),r=t===n;return p.jsxs(c.Fragment,{children:[t===0&&p.jsx(w,{className:"chain-picker-item","data-index":t-1,selected:!1,distance:-1}),p.jsx(w,{className:"chain-picker-item","data-index":t,"data-selected":r,selected:r,distance:t-n,role:"spinbutton",tabIndex:r?0:-1,"aria-hidden":r?"false":"true","aria-valuenow":e.value,"aria-valuetext":e.ariaValueText??e.label,"aria-valuemin":i[0].value,"aria-valuemax":i[i.length-1].value,...L,onKeyDown:G,children:O?O(e,r):e.label}),t===i.length-1&&p.jsx(w,{className:"chain-picker-item","data-index":t+1,selected:!1,distance:i.length-n})]},`${j}_${e.label}`)})})})});exports.default=he;
53
+ ${({selected:l,theme:{palette:{grey:i},typography:{h4M:h}}})=>l?{"&, & *":{color:`${i[100]} !important`}}:{color:`${i[30]} !important`,fontSize:`${h.size} !important`,fontWeight:`${h.weight} !important`,lineHeight:`${h.lineHeight} !important`,letterSpacing:`${h.letterSpacing} !important`,"& *":{color:`${i[30]} !important`}}}
54
+ `,f=Object.freeze({FRICTION:.95,SNAP_FORCE:.2,SNAP_VELOCITY_THRESHOLD:.04,MIN_VELOCITY:.01,MAX_VELOCITY:1.62,NEAR_ZERO_VELOCITY:.2,BOUNDARY_PX:4}),pe=c.forwardRef(function({column:i,value:h=i[0].value,onChange:E,onSpin:S,onSnap:p,renderLabel:N,inlineCSS:$,wrapperProps:x,thumbProps:V,...q},j){const T=i.findIndex(t=>t.value===h),M=c.useRef(T),o=c.useRef(null),[H,v]=c.useState(T*54),[b,L]=c.useState(!1),[P,U]=c.useState(0),[_,W]=c.useState(0),[w,C]=c.useState(!1),[z,O]=c.useState([]),X=c.useId(),d=c.useRef(null),A=c.useRef(T),{isHoverPossible:K}=he.default(),{isKeyboardMode:B}=de.default(),{hasFocus:Z}=ue.default({ref:o}),g=c.useCallback(t=>{const e=Math.max(0,Math.min(Math.round(t/54),i.length-1));e===A.current||!i[e]||(A.current=e,S==null||S(i[e].value))},[i,54,S]),G=t=>{if(t.length<2)return 0;const e=t[0],n=t[t.length-1],r=n.time-e.time,a=n.y-e.y;if(r===0)return 0;const s=a/r;return Math.max(-f.MAX_VELOCITY,Math.min(f.MAX_VELOCITY,s))},J=t=>{d.current&&cancelAnimationFrame(d.current),C(!0);let e=t*-1,n=H,r=performance.now();const a=54*(i.length-1),s=u=>{const m=u-r;r=u,n+=e*m,n<0?(n=0,e=0):n>a&&(n=a,e=0),e*=f.FRICTION,v(n),g(n),o.current&&(o.current.children[0].scrollTop=n);const R=Math.round(n/54)*54,se=Math.abs(n-R),oe=Math.abs(e)<=f.NEAR_ZERO_VELOCITY,ae=Math.abs(e)<=f.SNAP_VELOCITY_THRESHOLD,ce=se<=f.BOUNDARY_PX;oe&&ce||ae?(C(!1),Q(n)):d.current=requestAnimationFrame(s)};d.current=requestAnimationFrame(s)},Q=t=>{d.current&&cancelAnimationFrame(d.current);const e=Math.max(0,Math.min(Math.round(t/54),i.length-1)),n=e*54;M.current=e;const r=a=>{if(Math.abs(a-n)<1)v(n),g(n),o.current&&(o.current.children[0].scrollTop=n),i[e]&&(E(i[e].value),p==null||p(i[e].value));else{const s=a+(n-a)*f.SNAP_FORCE;v(s),g(s),o.current&&(o.current.children[0].scrollTop=s),d.current=requestAnimationFrame(()=>r(s))}};d.current=requestAnimationFrame(()=>r(t))},Y=t=>{L(!0),W(t),U(H),C(!1),O([{time:performance.now(),y:t}])},ee=t=>{if(!b||w)return;const e=_-t;let n=P+e;const r=54*(i.length-1);n<0?n=0:n>r&&(n=r),v(n),g(n),o.current&&(o.current.children[0].scrollTop=n);const a=performance.now();O(s=>[...s,{time:a,y:t}].filter(u=>a-u.time<=100))},te=t=>{var n,r;t.stopPropagation();let e=M.current;t.key==="ArrowUp"?(e+=1,e>i.length-1&&(e=0)):t.key==="ArrowDown"?(e-=1,e<0&&(e=i.length-1)):t.key==="PageUp"?(e+=5,e>i.length-1&&(e=0)):t.key==="PageDown"?(e-=5,e<0&&(e=i.length-1)):t.key==="Home"?e=0:t.key==="End"&&(e=i.length-1),E(i[e].value),M.current=e,(r=(n=o.current)==null?void 0:n.querySelector(`.chain-picker-item[data-index="${M.current}"]`))==null||r.focus()},ie=t=>{t.preventDefault(),t.stopPropagation(),Y(t.clientY)},ne=t=>Y(t.touches[0].clientY),re=t=>{t.preventDefault(),t.stopPropagation(),ee(t.clientY)},I=t=>{if(!b||(L(!1),!K&&t.type==="mouseup"))return;const e=G(z);if(Math.abs(e)<f.MIN_VELOCITY){const r=t.target.closest("[data-index]");if(r){const a=Number(r.dataset.index);if(i[a]&&o.current){const s=o.current.children[0],u=a*54;g(u),s.scrollTo({top:u,behavior:"smooth"});const m=()=>{Math.abs(s.scrollTop-u)<1&&(E(i[a].value),p==null||p(i[a].value),s.removeEventListener("scroll",m))};s.addEventListener("scroll",m)}}return}J(e)};return c.useLayoutEffect(()=>{const t=i.findIndex(n=>n.value===h),e=t*54;v(e),A.current=t,o.current&&(o.current.children[0].scrollTop=e)},[h,i,54]),c.useLayoutEffect(()=>()=>{d.current&&cancelAnimationFrame(d.current)},[]),c.useEffect(()=>{const t=o.current;if(!t)return;const e=n=>{const r=n;if(r.preventDefault(),r.stopPropagation(),!b||w)return;const a=_-r.touches[0].clientY;let s=P+a;const u=54*(i.length-1);s<0?s=0:s>u&&(s=u),v(s),g(s),o.current&&(o.current.children[0].scrollTop=s);const m=performance.now();O(F=>[...F,{time:m,y:r.touches[0].clientY}].filter(R=>m-R.time<=100))};return t.addEventListener("touchmove",e,{passive:!1}),()=>{t.removeEventListener("touchmove",e)}},[b,w,_,P,54,i.length,g]),y.jsx(me,{ref:o,...x,css:x==null?void 0:x.inlineCSS,focusWithin:B&&Z,children:y.jsx(ge,{role:"group",ref:j,css:$,...q,onMouseDown:ie,onMouseMove:re,onMouseUp:I,onMouseLeave:I,onTouchStart:ne,onTouchEnd:I,onTouchCancel:I,children:i.map((t,e)=>{const n=Math.round(H/54),r=e===n;return y.jsxs(c.Fragment,{children:[e===0&&y.jsx(k,{className:"chain-picker-item","data-index":e-1,selected:!1,distance:-1}),y.jsx(k,{className:"chain-picker-item","data-index":e,"data-selected":r,selected:r,distance:e-n,role:"spinbutton",tabIndex:r?0:-1,"aria-hidden":r?"false":"true","aria-valuenow":t.value,"aria-valuetext":t.ariaValueText??t.label,"aria-valuemin":i[0].value,"aria-valuemax":i[i.length-1].value,...V,onKeyDown:te,children:N?N(t,r):t.label}),e===i.length-1&&y.jsx(k,{className:"chain-picker-item","data-index":e+1,selected:!1,distance:i.length-n})]},`${X}_${t.label}`)})})})});exports.default=pe;
@@ -14,6 +14,8 @@ export interface ChainPickerProps extends GeneralComponentProps<Omit<HTMLAttribu
14
14
  column: ChainPickerItem[];
15
15
  value?: number;
16
16
  onChange: (selectedValue: number) => void;
17
+ onSpin?: (selectedValue: number) => void;
18
+ onSnap?: (selectedValue: number) => void;
17
19
  renderLabel?: (item: ChainPickerItem, isSelected: boolean) => ReactNode;
18
20
  wrapperProps?: GeneralComponentProps<HTMLAttributes<HTMLDivElement>>;
19
21
  thumbProps?: GeneralComponentProps<HTMLAttributes<HTMLDivElement>>;
@@ -1,10 +1,10 @@
1
- import { jsx as m, jsxs as ae } from "@emotion/react/jsx-runtime";
2
- import { forwardRef as ce, useRef as C, useState as g, useId as le, useLayoutEffect as L, useEffect as he, Fragment as ue } from "react";
3
- import O from "@emotion/styled";
4
- import de from "../hooks/useCheckHasFocus/useCheckHasFocus.es.js";
5
- import fe from "../hooks/useCheckHoverPossible/useCheckHoverPossible.es.js";
6
- import ge from "../hooks/useCheckKeyboardMode/useCheckKeyboardMode.es.js";
7
- const me = O.div`
1
+ import { jsx as y, jsxs as ue } from "@emotion/react/jsx-runtime";
2
+ import { forwardRef as de, useRef as S, useState as v, useId as fe, useCallback as ge, useLayoutEffect as V, useEffect as me, Fragment as pe } from "react";
3
+ import Y from "@emotion/styled";
4
+ import ve from "../hooks/useCheckHasFocus/useCheckHasFocus.es.js";
5
+ import ye from "../hooks/useCheckHoverPossible/useCheckHoverPossible.es.js";
6
+ import Ie from "../hooks/useCheckKeyboardMode/useCheckKeyboardMode.es.js";
7
+ const be = Y.div`
8
8
  list-style-type: none;
9
9
  margin: 0;
10
10
  padding: 0;
@@ -14,7 +14,7 @@ const me = O.div`
14
14
  position: relative;
15
15
  cursor: grab;
16
16
  transition: transform 0.3s ease-out;
17
- `, pe = O.div`
17
+ `, xe = Y.div`
18
18
  position: relative;
19
19
  width: auto;
20
20
  height: fit-content;
@@ -48,7 +48,7 @@ const me = O.div`
48
48
  outline: `${i.palette.grey[100]} solid 2px`
49
49
  } : {}}
50
50
  }
51
- `, A = O.div`
51
+ `, _ = Y.div`
52
52
  height: 54px;
53
53
  display: flex;
54
54
  align-items: center;
@@ -60,7 +60,7 @@ const me = O.div`
60
60
  theme: {
61
61
  palette: { grey: u },
62
62
  typography: { h2M: i },
63
- spacing: { content: c }
63
+ spacing: { content: l }
64
64
  }
65
65
  }) => ({
66
66
  fontSize: i.size,
@@ -68,14 +68,14 @@ const me = O.div`
68
68
  lineHeight: i.lineHeight,
69
69
  letterSpacing: i.letterSpacing,
70
70
  color: u[100],
71
- padding: c(3)
71
+ padding: l(3)
72
72
  })};
73
73
 
74
74
  ${({
75
75
  selected: u,
76
76
  theme: {
77
77
  palette: { grey: i },
78
- typography: { h4M: c }
78
+ typography: { h4M: l }
79
79
  }
80
80
  }) => u ? {
81
81
  "&, & *": {
@@ -83,10 +83,10 @@ const me = O.div`
83
83
  }
84
84
  } : {
85
85
  color: `${i[30]} !important`,
86
- fontSize: `${c.size} !important`,
87
- fontWeight: `${c.weight} !important`,
88
- lineHeight: `${c.lineHeight} !important`,
89
- letterSpacing: `${c.letterSpacing} !important`,
86
+ fontSize: `${l.size} !important`,
87
+ fontWeight: `${l.weight} !important`,
88
+ lineHeight: `${l.lineHeight} !important`,
89
+ letterSpacing: `${l.letterSpacing} !important`,
90
90
  "& *": {
91
91
  color: `${i[30]} !important`
92
92
  }
@@ -105,180 +105,199 @@ const me = O.div`
105
105
  // px/ms 이 값 이하이면 '거의 멈춤'으로 판단
106
106
  BOUNDARY_PX: 4
107
107
  // px 아이템 경계(정렬 위치)와의 거리 허용치
108
- }), Te = ce(function({
108
+ }), Ce = de(function({
109
109
  column: i,
110
- value: c = i[0].value,
111
- onChange: b,
112
- renderLabel: N,
113
- inlineCSS: F,
114
- wrapperProps: p,
115
- thumbProps: R,
116
- ...$
117
- }, V) {
118
- const k = i.findIndex((e) => e.value === c), S = C(k), s = C(null), [E, f] = g(k * 54), [y, D] = g(!1), [x, U] = g(0), [T, W] = g(0), [M, H] = g(!1), [q, w] = g([]), z = le(), l = C(null), { isHoverPossible: X } = fe(), { isKeyboardMode: j } = ge(), { hasFocus: K } = de({ ref: s }), B = (e) => {
119
- if (e.length < 2) return 0;
120
- const t = e[0], n = e[e.length - 1], r = n.time - t.time, a = n.y - t.y;
110
+ value: l = i[0].value,
111
+ onChange: T,
112
+ onSpin: I,
113
+ onSnap: m,
114
+ renderLabel: L,
115
+ inlineCSS: U,
116
+ wrapperProps: b,
117
+ thumbProps: W,
118
+ ...q
119
+ }, z) {
120
+ const H = i.findIndex((t) => t.value === l), x = S(H), s = S(null), [P, p] = v(H * 54), [M, R] = v(!1), [w, X] = v(0), [C, j] = v(0), [A, O] = v(!1), [K, k] = v([]), B = fe(), h = S(null), N = S(H), { isHoverPossible: Z } = ye(), { isKeyboardMode: G } = Ie(), { hasFocus: J } = ve({ ref: s }), f = ge(
121
+ (t) => {
122
+ const e = Math.max(
123
+ 0,
124
+ Math.min(Math.round(t / 54), i.length - 1)
125
+ );
126
+ e === N.current || !i[e] || (N.current = e, I == null || I(i[e].value));
127
+ },
128
+ [i, 54, I]
129
+ ), Q = (t) => {
130
+ if (t.length < 2) return 0;
131
+ const e = t[0], n = t[t.length - 1], r = n.time - e.time, a = n.y - e.y;
121
132
  if (r === 0) return 0;
122
133
  const o = a / r;
123
134
  return Math.max(
124
135
  -d.MAX_VELOCITY,
125
136
  Math.min(d.MAX_VELOCITY, o)
126
137
  );
127
- }, Z = (e) => {
128
- l.current && cancelAnimationFrame(l.current), H(!0);
129
- let t = e * -1, n = E, r = performance.now();
130
- const a = 54 * (i.length - 1), o = (h) => {
131
- const I = h - r;
132
- r = h, n += t * I, n < 0 ? (n = 0, t = 0) : n > a && (n = a, t = 0), t *= d.FRICTION, f(n), s.current && (s.current.children[0].scrollTop = n);
133
- const P = Math.round(n / 54) * 54, ie = Math.abs(n - P), re = Math.abs(t) <= d.NEAR_ZERO_VELOCITY, oe = Math.abs(t) <= d.SNAP_VELOCITY_THRESHOLD, se = ie <= d.BOUNDARY_PX;
134
- re && se || oe ? (H(!1), G(n)) : l.current = requestAnimationFrame(o);
138
+ }, ee = (t) => {
139
+ h.current && cancelAnimationFrame(h.current), O(!0);
140
+ let e = t * -1, n = P, r = performance.now();
141
+ const a = 54 * (i.length - 1), o = (c) => {
142
+ const g = c - r;
143
+ r = c, n += e * g, n < 0 ? (n = 0, e = 0) : n > a && (n = a, e = 0), e *= d.FRICTION, p(n), f(n), s.current && (s.current.children[0].scrollTop = n);
144
+ const D = Math.round(n / 54) * 54, ae = Math.abs(n - D), ce = Math.abs(e) <= d.NEAR_ZERO_VELOCITY, le = Math.abs(e) <= d.SNAP_VELOCITY_THRESHOLD, he = ae <= d.BOUNDARY_PX;
145
+ ce && he || le ? (O(!1), te(n)) : h.current = requestAnimationFrame(o);
135
146
  };
136
- l.current = requestAnimationFrame(o);
137
- }, G = (e) => {
138
- l.current && cancelAnimationFrame(l.current);
139
- const t = Math.max(0, Math.min(Math.round(e / 54), i.length - 1)), n = t * 54;
140
- S.current = t;
147
+ h.current = requestAnimationFrame(o);
148
+ }, te = (t) => {
149
+ h.current && cancelAnimationFrame(h.current);
150
+ const e = Math.max(0, Math.min(Math.round(t / 54), i.length - 1)), n = e * 54;
151
+ x.current = e;
141
152
  const r = (a) => {
142
153
  if (Math.abs(a - n) < 1)
143
- f(n), s.current && (s.current.children[0].scrollTop = n), i[t] && b(i[t].value);
154
+ p(n), f(n), s.current && (s.current.children[0].scrollTop = n), i[e] && (T(i[e].value), m == null || m(i[e].value));
144
155
  else {
145
156
  const o = a + (n - a) * d.SNAP_FORCE;
146
- f(o), s.current && (s.current.children[0].scrollTop = o), l.current = requestAnimationFrame(() => r(o));
157
+ p(o), f(o), s.current && (s.current.children[0].scrollTop = o), h.current = requestAnimationFrame(() => r(o));
147
158
  }
148
159
  };
149
- l.current = requestAnimationFrame(() => r(e));
150
- }, _ = (e) => {
151
- D(!0), W(e), U(E), H(!1), w([{ time: performance.now(), y: e }]);
152
- }, J = (e) => {
153
- if (!y || M) return;
154
- const t = T - e;
155
- let n = x + t;
160
+ h.current = requestAnimationFrame(() => r(t));
161
+ }, F = (t) => {
162
+ R(!0), j(t), X(P), O(!1), k([{ time: performance.now(), y: t }]);
163
+ }, ie = (t) => {
164
+ if (!M || A) return;
165
+ const e = C - t;
166
+ let n = w + e;
156
167
  const r = 54 * (i.length - 1);
157
- n < 0 ? n = 0 : n > r && (n = r), f(n), s.current && (s.current.children[0].scrollTop = n);
168
+ n < 0 ? n = 0 : n > r && (n = r), p(n), f(n), s.current && (s.current.children[0].scrollTop = n);
158
169
  const a = performance.now();
159
- w(
160
- (o) => [...o, { time: a, y: e }].filter((h) => a - h.time <= 100)
170
+ k(
171
+ (o) => [...o, { time: a, y: t }].filter((c) => a - c.time <= 100)
161
172
  );
162
- }, Q = (e) => {
173
+ }, ne = (t) => {
163
174
  var n, r;
164
- e.stopPropagation();
165
- let t = S.current;
166
- e.key === "ArrowUp" ? (t += 1, t > i.length - 1 && (t = 0)) : e.key === "ArrowDown" ? (t -= 1, t < 0 && (t = i.length - 1)) : e.key === "PageUp" ? (t += 5, t > i.length - 1 && (t = 0)) : e.key === "PageDown" ? (t -= 5, t < 0 && (t = i.length - 1)) : e.key === "Home" ? t = 0 : e.key === "End" && (t = i.length - 1), b(i[t].value), S.current = t, (r = (n = s.current) == null ? void 0 : n.querySelector(`.chain-picker-item[data-index="${S.current}"]`)) == null || r.focus();
167
- }, ee = (e) => {
168
- e.preventDefault(), e.stopPropagation(), _(e.clientY);
169
- }, te = (e) => _(e.touches[0].clientY), ne = (e) => {
170
- e.preventDefault(), e.stopPropagation(), J(e.clientY);
171
- }, v = (e) => {
172
- if (!y || (D(!1), !X && e.type === "mouseup")) return;
173
- const t = B(q);
174
- if (Math.abs(t) < d.MIN_VELOCITY) {
175
- const r = e.target.closest("[data-index]");
175
+ t.stopPropagation();
176
+ let e = x.current;
177
+ t.key === "ArrowUp" ? (e += 1, e > i.length - 1 && (e = 0)) : t.key === "ArrowDown" ? (e -= 1, e < 0 && (e = i.length - 1)) : t.key === "PageUp" ? (e += 5, e > i.length - 1 && (e = 0)) : t.key === "PageDown" ? (e -= 5, e < 0 && (e = i.length - 1)) : t.key === "Home" ? e = 0 : t.key === "End" && (e = i.length - 1), T(i[e].value), x.current = e, (r = (n = s.current) == null ? void 0 : n.querySelector(`.chain-picker-item[data-index="${x.current}"]`)) == null || r.focus();
178
+ }, re = (t) => {
179
+ t.preventDefault(), t.stopPropagation(), F(t.clientY);
180
+ }, oe = (t) => F(t.touches[0].clientY), se = (t) => {
181
+ t.preventDefault(), t.stopPropagation(), ie(t.clientY);
182
+ }, E = (t) => {
183
+ if (!M || (R(!1), !Z && t.type === "mouseup")) return;
184
+ const e = Q(K);
185
+ if (Math.abs(e) < d.MIN_VELOCITY) {
186
+ const r = t.target.closest("[data-index]");
176
187
  if (r) {
177
188
  const a = Number(r.dataset.index);
178
189
  if (i[a] && s.current) {
179
- const o = s.current.children[0];
180
- o.scrollTo({
181
- top: a * 54,
190
+ const o = s.current.children[0], c = a * 54;
191
+ f(c), o.scrollTo({
192
+ top: c,
182
193
  behavior: "smooth"
183
194
  });
184
- const h = () => {
185
- Math.abs(o.scrollTop - a * 54) < 1 && (b(i[a].value), o.removeEventListener("scroll", h));
195
+ const g = () => {
196
+ Math.abs(o.scrollTop - c) < 1 && (T(i[a].value), m == null || m(i[a].value), o.removeEventListener("scroll", g));
186
197
  };
187
- o.addEventListener("scroll", h);
198
+ o.addEventListener("scroll", g);
188
199
  }
189
200
  }
190
201
  return;
191
202
  }
192
- Z(t);
203
+ ee(e);
193
204
  };
194
- return L(() => {
195
- const t = i.findIndex((n) => n.value === c) * 54;
196
- f(t), s.current && (s.current.children[0].scrollTop = t);
197
- }, [c, i, 54]), L(() => () => {
198
- l.current && cancelAnimationFrame(l.current);
199
- }, []), he(() => {
200
- const e = s.current;
201
- if (!e) return;
202
- const t = (n) => {
205
+ return V(() => {
206
+ const t = i.findIndex((n) => n.value === l), e = t * 54;
207
+ p(e), N.current = t, s.current && (s.current.children[0].scrollTop = e);
208
+ }, [l, i, 54]), V(() => () => {
209
+ h.current && cancelAnimationFrame(h.current);
210
+ }, []), me(() => {
211
+ const t = s.current;
212
+ if (!t) return;
213
+ const e = (n) => {
203
214
  const r = n;
204
- if (r.preventDefault(), r.stopPropagation(), !y || M) return;
205
- const a = T - r.touches[0].clientY;
206
- let o = x + a;
207
- const h = 54 * (i.length - 1);
208
- o < 0 ? o = 0 : o > h && (o = h), f(o), s.current && (s.current.children[0].scrollTop = o);
209
- const I = performance.now();
210
- w(
211
- (Y) => [...Y, { time: I, y: r.touches[0].clientY }].filter(
212
- (P) => I - P.time <= 100
215
+ if (r.preventDefault(), r.stopPropagation(), !M || A) return;
216
+ const a = C - r.touches[0].clientY;
217
+ let o = w + a;
218
+ const c = 54 * (i.length - 1);
219
+ o < 0 ? o = 0 : o > c && (o = c), p(o), f(o), s.current && (s.current.children[0].scrollTop = o);
220
+ const g = performance.now();
221
+ k(
222
+ ($) => [...$, { time: g, y: r.touches[0].clientY }].filter(
223
+ (D) => g - D.time <= 100
213
224
  )
214
225
  );
215
226
  };
216
- return e.addEventListener("touchmove", t, { passive: !1 }), () => {
217
- e.removeEventListener("touchmove", t);
227
+ return t.addEventListener("touchmove", e, { passive: !1 }), () => {
228
+ t.removeEventListener("touchmove", e);
218
229
  };
219
- }, [y, M, T, x, 54, i.length]), /* @__PURE__ */ m(
220
- pe,
230
+ }, [
231
+ M,
232
+ A,
233
+ C,
234
+ w,
235
+ 54,
236
+ i.length,
237
+ f
238
+ ]), /* @__PURE__ */ y(
239
+ xe,
221
240
  {
222
241
  ref: s,
223
- ...p,
224
- css: p == null ? void 0 : p.inlineCSS,
225
- focusWithin: j && K,
226
- children: /* @__PURE__ */ m(
227
- me,
242
+ ...b,
243
+ css: b == null ? void 0 : b.inlineCSS,
244
+ focusWithin: G && J,
245
+ children: /* @__PURE__ */ y(
246
+ be,
228
247
  {
229
248
  role: "group",
230
- ref: V,
231
- css: F,
232
- ...$,
233
- onMouseDown: ee,
234
- onMouseMove: ne,
235
- onMouseUp: v,
236
- onMouseLeave: v,
237
- onTouchStart: te,
238
- onTouchEnd: v,
239
- onTouchCancel: v,
240
- children: i.map((e, t) => {
241
- const n = Math.round(E / 54), r = t === n;
242
- return /* @__PURE__ */ ae(ue, { children: [
243
- t === 0 && /* @__PURE__ */ m(
244
- A,
249
+ ref: z,
250
+ css: U,
251
+ ...q,
252
+ onMouseDown: re,
253
+ onMouseMove: se,
254
+ onMouseUp: E,
255
+ onMouseLeave: E,
256
+ onTouchStart: oe,
257
+ onTouchEnd: E,
258
+ onTouchCancel: E,
259
+ children: i.map((t, e) => {
260
+ const n = Math.round(P / 54), r = e === n;
261
+ return /* @__PURE__ */ ue(pe, { children: [
262
+ e === 0 && /* @__PURE__ */ y(
263
+ _,
245
264
  {
246
265
  className: "chain-picker-item",
247
- "data-index": t - 1,
266
+ "data-index": e - 1,
248
267
  selected: !1,
249
268
  distance: -1
250
269
  }
251
270
  ),
252
- /* @__PURE__ */ m(
253
- A,
271
+ /* @__PURE__ */ y(
272
+ _,
254
273
  {
255
274
  className: "chain-picker-item",
256
- "data-index": t,
275
+ "data-index": e,
257
276
  "data-selected": r,
258
277
  selected: r,
259
- distance: t - n,
278
+ distance: e - n,
260
279
  role: "spinbutton",
261
280
  tabIndex: r ? 0 : -1,
262
281
  "aria-hidden": r ? "false" : "true",
263
- "aria-valuenow": e.value,
264
- "aria-valuetext": e.ariaValueText ?? e.label,
282
+ "aria-valuenow": t.value,
283
+ "aria-valuetext": t.ariaValueText ?? t.label,
265
284
  "aria-valuemin": i[0].value,
266
285
  "aria-valuemax": i[i.length - 1].value,
267
- ...R,
268
- onKeyDown: Q,
269
- children: N ? N(e, r) : e.label
286
+ ...W,
287
+ onKeyDown: ne,
288
+ children: L ? L(t, r) : t.label
270
289
  }
271
290
  ),
272
- t === i.length - 1 && /* @__PURE__ */ m(
273
- A,
291
+ e === i.length - 1 && /* @__PURE__ */ y(
292
+ _,
274
293
  {
275
294
  className: "chain-picker-item",
276
- "data-index": t + 1,
295
+ "data-index": e + 1,
277
296
  selected: !1,
278
297
  distance: i.length - n
279
298
  }
280
299
  )
281
- ] }, `${z}_${e.label}`);
300
+ ] }, `${B}_${t.label}`);
282
301
  })
283
302
  }
284
303
  )
@@ -286,5 +305,5 @@ const me = O.div`
286
305
  );
287
306
  });
288
307
  export {
289
- Te as default
308
+ Ce as default
290
309
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotss/ui",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "description": "React UI components for Dotss",
5
5
  "type": "module",
6
6
  "main": "./index.cjs",