@dotss/ui 1.0.7 → 1.0.8

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 h=require("@emotion/react/jsx-runtime"),l=require("react"),B=require("@emotion/styled"),G=require("../hooks/useCheckHasFocus/useCheckHasFocus.cjs"),J=require("../hooks/useCheckHoverPossible/useCheckHoverPossible.cjs"),Q=require("../hooks/useCheckKeyboardMode/useCheckKeyboardMode.cjs"),X=s=>s&&s.__esModule?s:{default:s},H=X(B),Z=H.default.div`
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`
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
- `,ee=H.default.div`
11
+ `,de=C.default.div`
12
12
  position: relative;
13
13
  width: auto;
14
14
  height: fit-content;
@@ -33,14 +33,14 @@
33
33
 
34
34
  @supports selector(:has(:focus-visible)) {
35
35
  &:has(:focus-visible) {
36
- outline: ${({theme:s})=>s.palette.grey[100]} solid 2px;
36
+ outline: ${({theme:l})=>l.palette.grey[100]} solid 2px;
37
37
  }
38
38
  }
39
39
 
40
40
  @supports not selector(:has(:focus-visible)) {
41
- ${({focusWithin:s,theme:t})=>s?{outline:`${t.palette.grey[100]} solid 2px`}:{}}
41
+ ${({focusWithin:l,theme:i})=>l?{outline:`${i.palette.grey[100]} solid 2px`}:{}}
42
42
  }
43
- `,m=H.default.div`
43
+ `,w=C.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:s},typography:{h2M:t},spacing:{content:r}}})=>({fontSize:t.size,fontWeight:t.weight,lineHeight:t.lineHeight,letterSpacing:t.letterSpacing,color:s[100],padding:r(3)})};
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)})};
52
52
 
53
- ${({selected:s,theme:{palette:{grey:t},typography:{h4M:r}}})=>s?{"&, & *":{color:`${t[100]} !important`}}:{color:`${t[30]} !important`,fontSize:`${r.size} !important`,fontWeight:`${r.weight} !important`,lineHeight:`${r.lineHeight} !important`,letterSpacing:`${r.letterSpacing} !important`,"& *":{color:`${t[30]} !important`}}}
54
- `,_=3,te=l.forwardRef(function({column:t,value:r=t[0].value,onChange:y,renderLabel:k,inlineCSS:C,wrapperProps:g,thumbProps:R,...j},q){const T=t.findIndex(i=>i.value===r),p=l.useRef(T),o=l.useRef(null),[f,S]=l.useState(T*54),[w,P]=l.useState(!1),[D,E]=l.useState(0),[L,O]=l.useState(0),Y=l.useId(),{isHoverPossible:N}=J.default(),{isKeyboardMode:W}=Q.default(),{hasFocus:F}=G.default({ref:o}),I=i=>{P(!0),O(i),E(f)},M=i=>{if(!w)return;const e=L-i;let n=D+e;const a=54*(t.length-1);n<0?n=0:n>a&&(n=a),S(n),o.current&&(o.current.children[0].scrollTop=n)},z=i=>{var n,a;i.stopPropagation();let e=p.current;i.key==="ArrowUp"?(e+=1,e>t.length-1&&(e=0)):i.key==="ArrowDown"?(e-=1,e<0&&(e=t.length-1)):i.key==="PageUp"?(e+=5,e>t.length-1&&(e=0)):i.key==="PageDown"?(e-=5,e<0&&(e=t.length-1)):i.key==="Home"?e=0:i.key==="End"&&(e=t.length-1),y(t[e].value),p.current=e,(a=(n=o.current)==null?void 0:n.querySelector(`.chain-picker-item[data-index="${p.current}"]`))==null||a.focus()},A=i=>I(i.clientY),K=i=>I(i.touches[0].clientY),U=i=>M(i.clientY),V=i=>M(i.touches[0].clientY),v=i=>{if(!w||(P(!1),!N&&i.type==="mouseup"))return;if(Math.abs(D-f)<_){const u=i.target.closest("[data-index]");if(u){const x=Number(u.dataset.index);if(t[x]&&o.current){const b=o.current.children[0];b.scrollTo({top:x*54,behavior:"smooth"});const $=()=>{Math.abs(b.scrollTop-x*54)<1&&(y(t[x].value),b.removeEventListener("scroll",$))};b.addEventListener("scroll",$)}}return}let e=Math.round(f/54),n=e*54;const a=54*(t.length-1);n<0?(n=0,e=0):n>a&&(n=a,e=t.length-1),p.current=e;const c=d=>{if(Math.abs(d-n)<1)S(n),o.current&&(o.current.children[0].scrollTop=n);else{const u=d+(n-d)/5;S(u),o.current&&(o.current.children[0].scrollTop=u),requestAnimationFrame(()=>c(u))}};requestAnimationFrame(()=>c(f)),t[e]&&y(t[e].value)};return l.useLayoutEffect(()=>{const e=t.findIndex(n=>n.value===r)*54;S(e),o.current&&(o.current.children[0].scrollTop=e)},[r,t,54]),h.jsx(ee,{ref:o,...g,css:g==null?void 0:g.inlineCSS,focusWithin:W&&F,children:h.jsx(Z,{role:"group",ref:q,css:C,...j,onMouseDown:A,onMouseMove:U,onMouseUp:v,onMouseLeave:v,onTouchStart:K,onTouchMove:V,onTouchEnd:v,onTouchCancel:v,children:t.map((i,e)=>{const n=t.findIndex(d=>d.value===r),a=n===0?0:Math.round(f/54),c=e===a;return h.jsxs(l.Fragment,{children:[e===0&&h.jsx(m,{className:"chain-picker-item","data-index":e-1,selected:!1,distance:(n+1)*-1}),h.jsx(m,{className:"chain-picker-item","data-index":e,"data-selected":c,selected:c,distance:e-n,role:"spinbutton",tabIndex:c?0:-1,"aria-hidden":c?"false":"true","aria-valuenow":i.value,"aria-valuetext":i.ariaValueText??i.label,"aria-valuemin":t[0].value,"aria-valuemax":t[t.length-1].value,...R,onKeyDown:z,children:k?k(i,c):i.label}),e===t.length-1&&h.jsx(m,{className:"chain-picker-item","data-index":e+1,selected:!1,distance:t.length-n})]},`${Y}_${i.label}`)})})})});exports.SCROLL_POSITION_THRESHOLD=_;exports.default=te;
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;
@@ -1,7 +1,10 @@
1
1
  import { HTMLAttributes, ReactNode } from 'react';
2
2
  import { GeneralComponentProps } from '../typings/component';
3
3
 
4
- export declare const SCROLL_POSITION_THRESHOLD = 3;
4
+ export interface VelocitySample {
5
+ time: number;
6
+ y: number;
7
+ }
5
8
  export interface ChainPickerItem {
6
9
  label: string;
7
10
  value: number;
@@ -1,10 +1,10 @@
1
- import { jsx as f, jsxs as B } from "@emotion/react/jsx-runtime";
2
- import { forwardRef as G, useRef as C, useState as b, useId as J, useLayoutEffect as Q, Fragment as X } from "react";
3
- import H from "@emotion/styled";
4
- import Z from "../hooks/useCheckHasFocus/useCheckHasFocus.es.js";
5
- import ee from "../hooks/useCheckHoverPossible/useCheckHoverPossible.es.js";
6
- import te from "../hooks/useCheckKeyboardMode/useCheckKeyboardMode.es.js";
7
- const ie = H.div`
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`
8
8
  list-style-type: none;
9
9
  margin: 0;
10
10
  padding: 0;
@@ -14,7 +14,7 @@ const ie = H.div`
14
14
  position: relative;
15
15
  cursor: grab;
16
16
  transition: transform 0.3s ease-out;
17
- `, ne = H.div`
17
+ `, pe = O.div`
18
18
  position: relative;
19
19
  width: auto;
20
20
  height: fit-content;
@@ -39,16 +39,16 @@ const ie = H.div`
39
39
 
40
40
  @supports selector(:has(:focus-visible)) {
41
41
  &:has(:focus-visible) {
42
- outline: ${({ theme: a }) => a.palette.grey[100]} solid 2px;
42
+ outline: ${({ theme: u }) => u.palette.grey[100]} solid 2px;
43
43
  }
44
44
  }
45
45
 
46
46
  @supports not selector(:has(:focus-visible)) {
47
- ${({ focusWithin: a, theme: t }) => a ? {
48
- outline: `${t.palette.grey[100]} solid 2px`
47
+ ${({ focusWithin: u, theme: i }) => u ? {
48
+ outline: `${i.palette.grey[100]} solid 2px`
49
49
  } : {}}
50
50
  }
51
- `, y = H.div`
51
+ `, A = O.div`
52
52
  height: 54px;
53
53
  display: flex;
54
54
  align-items: center;
@@ -58,162 +58,227 @@ const ie = H.div`
58
58
 
59
59
  ${({
60
60
  theme: {
61
- palette: { grey: a },
62
- typography: { h2M: t },
63
- spacing: { content: r }
61
+ palette: { grey: u },
62
+ typography: { h2M: i },
63
+ spacing: { content: c }
64
64
  }
65
65
  }) => ({
66
- fontSize: t.size,
67
- fontWeight: t.weight,
68
- lineHeight: t.lineHeight,
69
- letterSpacing: t.letterSpacing,
70
- color: a[100],
71
- padding: r(3)
66
+ fontSize: i.size,
67
+ fontWeight: i.weight,
68
+ lineHeight: i.lineHeight,
69
+ letterSpacing: i.letterSpacing,
70
+ color: u[100],
71
+ padding: c(3)
72
72
  })};
73
73
 
74
74
  ${({
75
- selected: a,
75
+ selected: u,
76
76
  theme: {
77
- palette: { grey: t },
78
- typography: { h4M: r }
77
+ palette: { grey: i },
78
+ typography: { h4M: c }
79
79
  }
80
- }) => a ? {
80
+ }) => u ? {
81
81
  "&, & *": {
82
- color: `${t[100]} !important`
82
+ color: `${i[100]} !important`
83
83
  }
84
84
  } : {
85
- color: `${t[30]} !important`,
86
- fontSize: `${r.size} !important`,
87
- fontWeight: `${r.weight} !important`,
88
- lineHeight: `${r.lineHeight} !important`,
89
- letterSpacing: `${r.letterSpacing} !important`,
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`,
90
90
  "& *": {
91
- color: `${t[30]} !important`
91
+ color: `${i[30]} !important`
92
92
  }
93
93
  }}
94
- `, oe = 3, fe = G(function({
95
- column: t,
96
- value: r = t[0].value,
97
- onChange: x,
98
- renderLabel: k,
99
- inlineCSS: E,
100
- wrapperProps: g,
101
- thumbProps: Y,
102
- ...L
103
- }, W) {
104
- const w = t.findIndex((i) => i.value === r), u = C(w), o = C(null), [h, p] = b(w * 54), [P, T] = b(!1), [$, F] = b(0), [N, R] = b(0), z = J(), { isHoverPossible: A } = ee(), { isKeyboardMode: K } = te(), { hasFocus: O } = Z({ ref: o }), D = (i) => {
105
- T(!0), R(i), F(h);
106
- }, I = (i) => {
107
- if (!P) return;
108
- const e = N - i;
109
- let n = $ + e;
110
- const s = 54 * (t.length - 1);
111
- n < 0 ? n = 0 : n > s && (n = s), p(n), o.current && (o.current.children[0].scrollTop = n);
112
- }, j = (i) => {
113
- var n, s;
114
- i.stopPropagation();
115
- let e = u.current;
116
- i.key === "ArrowUp" ? (e += 1, e > t.length - 1 && (e = 0)) : i.key === "ArrowDown" ? (e -= 1, e < 0 && (e = t.length - 1)) : i.key === "PageUp" ? (e += 5, e > t.length - 1 && (e = 0)) : i.key === "PageDown" ? (e -= 5, e < 0 && (e = t.length - 1)) : i.key === "Home" ? e = 0 : i.key === "End" && (e = t.length - 1), x(t[e].value), u.current = e, (s = (n = o.current) == null ? void 0 : n.querySelector(`.chain-picker-item[data-index="${u.current}"]`)) == null || s.focus();
117
- }, q = (i) => D(i.clientY), U = (i) => D(i.touches[0].clientY), _ = (i) => I(i.clientY), V = (i) => I(i.touches[0].clientY), m = (i) => {
118
- if (!P || (T(!1), !A && i.type === "mouseup")) return;
119
- if (Math.abs($ - h) < oe) {
120
- const d = i.target.closest("[data-index]");
121
- if (d) {
122
- const S = Number(d.dataset.index);
123
- if (t[S] && o.current) {
124
- const v = o.current.children[0];
125
- v.scrollTo({
126
- top: S * 54,
94
+ `, d = Object.freeze({
95
+ FRICTION: 0.95,
96
+ // 마찰 계수
97
+ SNAP_FORCE: 0.2,
98
+ // 스냅 강도: 최종값 결정시 얼마나 빠르게 값을 결정할 것인지?
99
+ SNAP_VELOCITY_THRESHOLD: 0.04,
100
+ // 0.1px/frame
101
+ MIN_VELOCITY: 0.01,
102
+ MAX_VELOCITY: 1.62,
103
+ // px/ms 단위 (27px/frame = 1.619px/ms, 한 프레임에 요소의 최대 절반까지 이동 가능, 60fps 기준)
104
+ NEAR_ZERO_VELOCITY: 0.2,
105
+ // px/ms 이 값 이하이면 '거의 멈춤'으로 판단
106
+ BOUNDARY_PX: 4
107
+ // px 아이템 경계(정렬 위치)와의 거리 허용치
108
+ }), Te = ce(function({
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;
121
+ if (r === 0) return 0;
122
+ const o = a / r;
123
+ return Math.max(
124
+ -d.MAX_VELOCITY,
125
+ Math.min(d.MAX_VELOCITY, o)
126
+ );
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);
135
+ };
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;
141
+ const r = (a) => {
142
+ if (Math.abs(a - n) < 1)
143
+ f(n), s.current && (s.current.children[0].scrollTop = n), i[t] && b(i[t].value);
144
+ else {
145
+ const o = a + (n - a) * d.SNAP_FORCE;
146
+ f(o), s.current && (s.current.children[0].scrollTop = o), l.current = requestAnimationFrame(() => r(o));
147
+ }
148
+ };
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;
156
+ 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);
158
+ const a = performance.now();
159
+ w(
160
+ (o) => [...o, { time: a, y: e }].filter((h) => a - h.time <= 100)
161
+ );
162
+ }, Q = (e) => {
163
+ 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]");
176
+ if (r) {
177
+ const a = Number(r.dataset.index);
178
+ if (i[a] && s.current) {
179
+ const o = s.current.children[0];
180
+ o.scrollTo({
181
+ top: a * 54,
127
182
  behavior: "smooth"
128
183
  });
129
- const M = () => {
130
- Math.abs(v.scrollTop - S * 54) < 1 && (x(t[S].value), v.removeEventListener("scroll", M));
184
+ const h = () => {
185
+ Math.abs(o.scrollTop - a * 54) < 1 && (b(i[a].value), o.removeEventListener("scroll", h));
131
186
  };
132
- v.addEventListener("scroll", M);
187
+ o.addEventListener("scroll", h);
133
188
  }
134
189
  }
135
190
  return;
136
191
  }
137
- let e = Math.round(h / 54), n = e * 54;
138
- const s = 54 * (t.length - 1);
139
- n < 0 ? (n = 0, e = 0) : n > s && (n = s, e = t.length - 1), u.current = e;
140
- const l = (c) => {
141
- if (Math.abs(c - n) < 1)
142
- p(n), o.current && (o.current.children[0].scrollTop = n);
143
- else {
144
- const d = c + (n - c) / 5;
145
- p(d), o.current && (o.current.children[0].scrollTop = d), requestAnimationFrame(() => l(d));
146
- }
147
- };
148
- requestAnimationFrame(() => l(h)), t[e] && x(t[e].value);
192
+ Z(t);
149
193
  };
150
- return Q(() => {
151
- const e = t.findIndex((n) => n.value === r) * 54;
152
- p(e), o.current && (o.current.children[0].scrollTop = e);
153
- }, [r, t, 54]), /* @__PURE__ */ f(
154
- ne,
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) => {
203
+ 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
213
+ )
214
+ );
215
+ };
216
+ return e.addEventListener("touchmove", t, { passive: !1 }), () => {
217
+ e.removeEventListener("touchmove", t);
218
+ };
219
+ }, [y, M, T, x, 54, i.length]), /* @__PURE__ */ m(
220
+ pe,
155
221
  {
156
- ref: o,
157
- ...g,
158
- css: g == null ? void 0 : g.inlineCSS,
159
- focusWithin: K && O,
160
- children: /* @__PURE__ */ f(
161
- ie,
222
+ ref: s,
223
+ ...p,
224
+ css: p == null ? void 0 : p.inlineCSS,
225
+ focusWithin: j && K,
226
+ children: /* @__PURE__ */ m(
227
+ me,
162
228
  {
163
229
  role: "group",
164
- ref: W,
165
- css: E,
166
- ...L,
167
- onMouseDown: q,
168
- onMouseMove: _,
169
- onMouseUp: m,
170
- onMouseLeave: m,
171
- onTouchStart: U,
172
- onTouchMove: V,
173
- onTouchEnd: m,
174
- onTouchCancel: m,
175
- children: t.map((i, e) => {
176
- const n = t.findIndex((c) => c.value === r), s = n === 0 ? 0 : Math.round(h / 54), l = e === s;
177
- return /* @__PURE__ */ B(X, { children: [
178
- e === 0 && /* @__PURE__ */ f(
179
- y,
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,
180
245
  {
181
246
  className: "chain-picker-item",
182
- "data-index": e - 1,
247
+ "data-index": t - 1,
183
248
  selected: !1,
184
- distance: (n + 1) * -1
249
+ distance: -1
185
250
  }
186
251
  ),
187
- /* @__PURE__ */ f(
188
- y,
252
+ /* @__PURE__ */ m(
253
+ A,
189
254
  {
190
255
  className: "chain-picker-item",
191
- "data-index": e,
192
- "data-selected": l,
193
- selected: l,
194
- distance: e - n,
256
+ "data-index": t,
257
+ "data-selected": r,
258
+ selected: r,
259
+ distance: t - n,
195
260
  role: "spinbutton",
196
- tabIndex: l ? 0 : -1,
197
- "aria-hidden": l ? "false" : "true",
198
- "aria-valuenow": i.value,
199
- "aria-valuetext": i.ariaValueText ?? i.label,
200
- "aria-valuemin": t[0].value,
201
- "aria-valuemax": t[t.length - 1].value,
202
- ...Y,
203
- onKeyDown: j,
204
- children: k ? k(i, l) : i.label
261
+ tabIndex: r ? 0 : -1,
262
+ "aria-hidden": r ? "false" : "true",
263
+ "aria-valuenow": e.value,
264
+ "aria-valuetext": e.ariaValueText ?? e.label,
265
+ "aria-valuemin": i[0].value,
266
+ "aria-valuemax": i[i.length - 1].value,
267
+ ...R,
268
+ onKeyDown: Q,
269
+ children: N ? N(e, r) : e.label
205
270
  }
206
271
  ),
207
- e === t.length - 1 && /* @__PURE__ */ f(
208
- y,
272
+ t === i.length - 1 && /* @__PURE__ */ m(
273
+ A,
209
274
  {
210
275
  className: "chain-picker-item",
211
- "data-index": e + 1,
276
+ "data-index": t + 1,
212
277
  selected: !1,
213
- distance: t.length - n
278
+ distance: i.length - n
214
279
  }
215
280
  )
216
- ] }, `${z}_${i.label}`);
281
+ ] }, `${z}_${e.label}`);
217
282
  })
218
283
  }
219
284
  )
@@ -221,6 +286,5 @@ const ie = H.div`
221
286
  );
222
287
  });
223
288
  export {
224
- oe as SCROLL_POSITION_THRESHOLD,
225
- fe as default
289
+ Te as default
226
290
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotss/ui",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "React UI components for Dotss",
5
5
  "type": "module",
6
6
  "main": "./index.cjs",