@designbyadrian/react-interactive-input 3.0.0 → 3.1.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,22 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("react");var J={exports:{}},L={};/**
2
- * @license React
3
- * react-jsx-runtime.production.js
4
- *
5
- * Copyright (c) Meta Platforms, Inc. and affiliates.
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file in the root directory of this source tree.
9
- */var ee;function ue(){if(ee)return L;ee=1;var a=Symbol.for("react.transitional.element"),d=Symbol.for("react.fragment");function R(v,u,m){var N=null;if(m!==void 0&&(N=""+m),u.key!==void 0&&(N=""+u.key),"key"in u){m={};for(var E in u)E!=="key"&&(m[E]=u[E])}else m=u;return u=m.ref,{$$typeof:a,type:v,key:N,ref:u!==void 0?u:null,props:m}}return L.Fragment=d,L.jsx=R,L.jsxs=R,L}var V={};/**
10
- * @license React
11
- * react-jsx-runtime.development.js
12
- *
13
- * Copyright (c) Meta Platforms, Inc. and affiliates.
14
- *
15
- * This source code is licensed under the MIT license found in the
16
- * LICENSE file in the root directory of this source tree.
17
- */var te;function ie(){return te||(te=1,process.env.NODE_ENV!=="production"&&(function(){function a(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===S?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case P:return"Fragment";case M:return"Profiler";case j:return"StrictMode";case o:return"Suspense";case p:return"SuspenseList";case y:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case C:return"Portal";case X:return e.displayName||"Context";case F:return(e._context.displayName||"Context")+".Consumer";case s:var n=e.render;return e=e.displayName,e||(e=n.displayName||n.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case i:return n=e.displayName||null,n!==null?n:a(e.type)||"Memo";case k:n=e._payload,e=e._init;try{return a(e(n))}catch{}}return null}function d(e){return""+e}function R(e){try{d(e);var n=!1}catch{n=!0}if(n){n=console;var c=n.error,l=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return c.call(n,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",l),d(e)}}function v(e){if(e===P)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===k)return"<...>";try{var n=a(e);return n?"<"+n+">":"<...>"}catch{return"<...>"}}function u(){var e=w.A;return e===null?null:e.getOwner()}function m(){return Error("react-stack-top-frame")}function N(e){if(z.call(e,"key")){var n=Object.getOwnPropertyDescriptor(e,"key").get;if(n&&n.isReactWarning)return!1}return e.key!==void 0}function E(e,n){function c(){h||(h=!0,console.error("%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)",n))}c.isReactWarning=!0,Object.defineProperty(e,"key",{get:c,configurable:!0})}function x(){var e=a(this.type);return $[e]||($[e]=!0,console.error("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.")),e=this.props.ref,e!==void 0?e:null}function I(e,n,c,l,q,B){var f=c.ref;return e={$$typeof:A,type:e,key:n,props:c,_owner:l},(f!==void 0?f:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:x}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:q}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:B}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function b(e,n,c,l,q,B){var f=n.children;if(f!==void 0)if(l)if(t(f)){for(l=0;l<f.length;l++)_(f[l]);Object.freeze&&Object.freeze(f)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else _(f);if(z.call(n,"key")){f=a(e);var Y=Object.keys(n).filter(function(oe){return oe!=="key"});l=0<Y.length?"{key: someKey, "+Y.join(": ..., ")+": ...}":"{key: someKey}",D[f+l]||(Y=0<Y.length?"{"+Y.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
18
- let props = %s;
19
- <%s {...props} />
20
- React keys must be passed directly to JSX without using spread:
21
- let props = %s;
22
- <%s key={someKey} {...props} />`,l,f,Y,f),D[f+l]=!0)}if(f=null,c!==void 0&&(R(c),f=""+c),N(n)&&(R(n.key),f=""+n.key),"key"in n){c={};for(var K in n)K!=="key"&&(c[K]=n[K])}else c=n;return f&&E(c,typeof e=="function"?e.displayName||e.name||"Unknown":e),I(e,f,c,u(),q,B)}function _(e){O(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===k&&(e._payload.status==="fulfilled"?O(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function O(e){return typeof e=="object"&&e!==null&&e.$$typeof===A}var T=g,A=Symbol.for("react.transitional.element"),C=Symbol.for("react.portal"),P=Symbol.for("react.fragment"),j=Symbol.for("react.strict_mode"),M=Symbol.for("react.profiler"),F=Symbol.for("react.consumer"),X=Symbol.for("react.context"),s=Symbol.for("react.forward_ref"),o=Symbol.for("react.suspense"),p=Symbol.for("react.suspense_list"),i=Symbol.for("react.memo"),k=Symbol.for("react.lazy"),y=Symbol.for("react.activity"),S=Symbol.for("react.client.reference"),w=T.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,z=Object.prototype.hasOwnProperty,t=Array.isArray,r=console.createTask?console.createTask:function(){return null};T={react_stack_bottom_frame:function(e){return e()}};var h,$={},W=T.react_stack_bottom_frame.bind(T,m)(),U=r(v(m)),D={};V.Fragment=P,V.jsx=function(e,n,c){var l=1e4>w.recentlyCreatedOwnerStacks++;return b(e,n,c,!1,l?Error("react-stack-top-frame"):W,l?r(v(e)):U)},V.jsxs=function(e,n,c){var l=1e4>w.recentlyCreatedOwnerStacks++;return b(e,n,c,!0,l?Error("react-stack-top-frame"):W,l?r(v(e)):U)}})()),V}var re;function le(){return re||(re=1,process.env.NODE_ENV==="production"?J.exports=ue():J.exports=ie()),J.exports}var ae=le();const fe=/^-?\d*[.,]?\d*$/,ne=(a,d)=>fe.test(a)?a:d,Z=a=>{const d=a.toString().split(".");return d.length>1?d[1].length:0},se=a=>a.replace(",","."),Q=a=>parseFloat(se(a)),G=a=>Number.isFinite(a)?String(a):"",de=a=>G(Q(a)),H=(a,d)=>{var v;if(a.value===d)return;const R=(v=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"value"))==null?void 0:v.set;R?R.call(a,d):a.value=d,a.dispatchEvent(new Event("input",{bubbles:!0})),R&&(a.value=a.value)},ce=g.forwardRef(({defaultValue:a,mask:d=ne,onBlur:R,onChange:v,onFocus:u,onKeyDown:m,step:N=1,value:E,...x},I)=>{const b=g.useRef(null);g.useImperativeHandle(I,()=>b.current);const[_,O]=g.useState(E??(a!=null?String(a):"")),T=g.useRef(_);T.current=_;const A=g.useRef(!1),C=d===ne;g.useEffect(()=>{E===void 0||A.current||O(E)},[E]);const P=s=>{const o=s.target,p=o.value,i=d(p,T.current);if(i!==p){const y=o.selectionStart??p.length,S=Math.min(i.length,Math.max(0,y-(p.length-i.length)));o.value=i,o.setSelectionRange(S,S);return}if(T.current=i,O(i),!v)return;const k=se(i);if(k!==i){const y=o.selectionStart??i.length,S=o.selectionEnd??i.length;o.value=k,v(s),o.value=i,o.setSelectionRange(y,S)}else v(s)},j=s=>{const o=b.current;if(!o)return;const p=Q(T.current),i=Number(N)||1,k=Z(i);let y=(Number.isFinite(p)?p:0)+s*i;const S=x.min!==void 0?Number(x.min):NaN,w=x.max!==void 0?Number(x.max):NaN;Number.isNaN(S)||(y=Math.max(y,S)),Number.isNaN(w)||(y=Math.min(y,w)),H(o,y.toFixed(k))},M=s=>{m==null||m(s),!s.defaultPrevented&&(s.key==="ArrowUp"?(s.preventDefault(),j(1)):s.key==="ArrowDown"&&(s.preventDefault(),j(-1)))},F=s=>{A.current=!0,u==null||u(s)},X=s=>{A.current=!1;const o=T.current,p=C?de(o):o;p!==o?H(s.target,p):E!==void 0&&E!==o&&O(E),R==null||R(s)};return ae.jsx("input",{inputMode:"decimal",...x,type:"text",ref:b,value:_,onBlur:X,onChange:P,onFocus:F,onKeyDown:M})}),me=["metaKey","ctrlKey","altKey","shiftKey"],be=3;function Ee({value:a,modifiers:d={altKey:1,ctrlKey:1,metaKey:1,shiftKey:.1},style:R={},onBlur:v,onFocus:u,onKeyDown:m,onPointerCancel:N,onPointerDown:E,onPointerMove:x,onPointerUp:I,...b}){const _=g.useRef(null),[O,T]=g.useState(!1),[A,C]=g.useState(!1),P=b.step?+b.step:1,j=b.min!==void 0?+b.min:void 0,M=b.max!==void 0?+b.max:void 0,F={cursor:O&&!A?void 0:"ew-resize",touchAction:"none",...R};g.useEffect(()=>()=>{const t=_.current;t!=null&&t.scrubbing&&(document.body.style.cursor=t.previousBodyCursor)},[]);const X=t=>{for(const r of me)if(t[r])return d[r]??1;return 1},s=(t,r,h)=>{if(_.current=null,!!r.scrubbing){C(!1),document.body.style.cursor=r.previousBodyCursor;try{t.releasePointerCapture(r.pointerId)}catch{}h&&H(t,G(r.startValue)),t.blur()}},o=t=>{if(E==null||E(t),t.defaultPrevented||t.button!==0||b.disabled||b.readOnly)return;const r=t.currentTarget;if(document.activeElement===r)return;let h=Q(r.value);Number.isFinite(h)||(h=Number(b.defaultValue??j??0)||0),_.current={pointerId:t.pointerId,startX:t.clientX,lastX:t.clientX,startValue:h,accumulated:h,scrubbing:!1,previousBodyCursor:""}},p=t=>{x==null||x(t);const r=_.current;if(!r||r.pointerId!==t.pointerId)return;const h=t.currentTarget;if(t.buttons===0){_.current=null;return}if(!r.scrubbing){if(Math.abs(t.clientX-r.startX)<be)return;r.scrubbing=!0,r.lastX=t.clientX,C(!0),r.previousBodyCursor=document.body.style.cursor,document.body.style.cursor="ew-resize";try{h.setPointerCapture(t.pointerId)}catch{}}const $=X(t),W=P*$,U=Z(P)+Z($);r.accumulated+=(t.clientX-r.lastX)*W,r.lastX=t.clientX,j!==void 0&&(r.accumulated=Math.max(r.accumulated,j)),M!==void 0&&(r.accumulated=Math.min(r.accumulated,M));const D=+r.accumulated.toFixed(U);Number.isNaN(D)||H(h,G(D))},i=t=>{const r=_.current;!r||r.pointerId!==t.pointerId||s(t.currentTarget,r,!1)},k=t=>{I==null||I(t),i(t)},y=t=>{N==null||N(t),i(t)},S=t=>{const r=_.current;if(t.key==="Escape"&&(r!=null&&r.scrubbing)){t.preventDefault(),s(t.currentTarget,r,!0);return}m==null||m(t)},w=t=>{T(!0),u==null||u(t)},z=t=>{T(!1),v==null||v(t)};return ae.jsx(ce,{...b,defaultValue:b.defaultValue??0,style:F,value:a!==void 0?G(a):void 0,onBlur:z,onFocus:w,onKeyDown:S,onPointerCancel:y,onPointerDown:o,onPointerMove:p,onPointerUp:k})}exports.InteractiveInput=Ee;exports.MaskedInput=ce;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("react/jsx-runtime"),l=require("react"),Y=/^-?\d*[.,]?\d*$/,_=(r,i)=>Y.test(r)?r:i,z=r=>{const i=r.toString().split(".");return i.length>1?i[1].length:0},D=r=>r.replace(",","."),F=r=>parseFloat(D(r)),A=r=>Number.isFinite(r)?String(r):"",$=r=>A(F(r)),j=(r,i)=>{var m;if(r.value===i)return;const b=(m=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"value"))==null?void 0:m.set;b?b.call(r,i):r.value=i,r.dispatchEvent(new Event("input",{bubbles:!0})),b&&(r.value=r.value)},P=l.forwardRef(({defaultValue:r,mask:i=_,onBlur:b,onChange:m,onFocus:N,onKeyDown:v,step:S=1,value:o,...h},E)=>{const u=l.useRef(null);l.useImperativeHandle(E,()=>u.current);const[M,d]=l.useState(o??(r!=null?String(r):"")),x=l.useRef(M);x.current=M;const R=l.useRef(!1),C=i===_;l.useEffect(()=>{o===void 0||R.current||d(o)},[o]);const X=c=>{const n=c.target,a=n.value,s=i(a,x.current);if(s!==a){const f=n.selectionStart??a.length,g=Math.min(s.length,Math.max(0,f-(a.length-s.length)));n.value=s,n.setSelectionRange(g,g);return}if(x.current=s,d(s),!m)return;const I=D(s);if(I!==s){const f=n.selectionStart??s.length,g=n.selectionEnd??s.length;n.value=I,m(c),n.value=s,n.setSelectionRange(f,g)}else m(c)},p=c=>{const n=u.current;if(!n)return;const a=F(x.current),s=Number(S)||1,I=z(s);let f=(Number.isFinite(a)?a:0)+c*s;const g=h.min!==void 0?Number(h.min):NaN,O=h.max!==void 0?Number(h.max):NaN;Number.isNaN(g)||(f=Math.max(f,g)),Number.isNaN(O)||(f=Math.min(f,O)),j(n,f.toFixed(I))},T=c=>{v==null||v(c),!c.defaultPrevented&&(c.key==="ArrowUp"?(c.preventDefault(),p(1)):c.key==="ArrowDown"&&(c.preventDefault(),p(-1)))},k=c=>{R.current=!0,N==null||N(c)},V=c=>{R.current=!1;const n=x.current,a=C?$(n):n;a!==n?j(c.target,a):o!==void 0&&o!==n&&d(o),b==null||b(c)};return w.jsx("input",{inputMode:"decimal",...h,type:"text",ref:u,value:M,onBlur:V,onChange:X,onFocus:k,onKeyDown:T})}),J=["metaKey","ctrlKey","altKey","shiftKey"],Q=3,U=l.forwardRef(({value:r,modifiers:i={altKey:1,ctrlKey:1,metaKey:1,shiftKey:.1},style:b={},onBlur:m,onFocus:N,onKeyDown:v,onPointerCancel:S,onPointerDown:o,onPointerMove:h,onPointerUp:E,...u},M)=>{const d=l.useRef(null),[x,R]=l.useState(!1),[C,X]=l.useState(!1),p=u.step?+u.step:1,T=u.min!==void 0?+u.min:void 0,k=u.max!==void 0?+u.max:void 0,V={cursor:x&&!C?void 0:"ew-resize",touchAction:"none",...b};l.useEffect(()=>()=>{const t=d.current;t!=null&&t.scrubbing&&(document.body.style.cursor=t.previousBodyCursor)},[]);const c=t=>{for(const e of J)if(t[e])return i[e]??1;return 1},n=(t,e,y)=>{if(d.current=null,!!e.scrubbing){X(!1),document.body.style.cursor=e.previousBodyCursor;try{t.releasePointerCapture(e.pointerId)}catch{}y&&j(t,A(e.startValue)),t.blur()}},a=t=>{if(o==null||o(t),t.defaultPrevented||t.button!==0||u.disabled||u.readOnly)return;const e=t.currentTarget;if(document.activeElement===e)return;let y=F(e.value);Number.isFinite(y)||(y=Number(u.defaultValue??T??0)||0),d.current={pointerId:t.pointerId,startX:t.clientX,lastX:t.clientX,startValue:y,accumulated:y,scrubbing:!1,previousBodyCursor:""}},s=t=>{h==null||h(t);const e=d.current;if(!e||e.pointerId!==t.pointerId)return;const y=t.currentTarget;if(t.buttons===0){d.current=null;return}if(!e.scrubbing){if(Math.abs(t.clientX-e.startX)<Q)return;e.scrubbing=!0,e.lastX=t.clientX,X(!0),e.previousBodyCursor=document.body.style.cursor,document.body.style.cursor="ew-resize";try{y.setPointerCapture(t.pointerId)}catch{}}const H=c(t),L=p*H,G=z(p)+z(H);e.accumulated+=(t.clientX-e.lastX)*L,e.lastX=t.clientX,T!==void 0&&(e.accumulated=Math.max(e.accumulated,T)),k!==void 0&&(e.accumulated=Math.min(e.accumulated,k));const K=+e.accumulated.toFixed(G);Number.isNaN(K)||j(y,A(K))},I=t=>{const e=d.current;!e||e.pointerId!==t.pointerId||n(t.currentTarget,e,!1)},f=t=>{E==null||E(t),I(t)},g=t=>{S==null||S(t),I(t)},O=t=>{const e=d.current;if(t.key==="Escape"&&(e!=null&&e.scrubbing)){t.preventDefault(),n(t.currentTarget,e,!0);return}v==null||v(t)},q=t=>{R(!0),N==null||N(t)},B=t=>{R(!1),m==null||m(t)};return w.jsx(P,{...u,ref:M,defaultValue:u.defaultValue??0,style:V,value:r!==void 0?A(r):void 0,onBlur:B,onFocus:q,onKeyDown:O,onPointerCancel:g,onPointerDown:a,onPointerMove:s,onPointerUp:f})});exports.InteractiveInput=U;exports.MaskedInput=P;
@@ -1,487 +1,212 @@
1
- import ie, { forwardRef as le, useRef as J, useImperativeHandle as fe, useState as Z, useEffect as se } from "react";
2
- var q = { exports: {} }, D = {};
3
- /**
4
- * @license React
5
- * react-jsx-runtime.production.js
6
- *
7
- * Copyright (c) Meta Platforms, Inc. and affiliates.
8
- *
9
- * This source code is licensed under the MIT license found in the
10
- * LICENSE file in the root directory of this source tree.
11
- */
12
- var te;
13
- function de() {
14
- if (te) return D;
15
- te = 1;
16
- var a = Symbol.for("react.transitional.element"), d = Symbol.for("react.fragment");
17
- function R(v, u, m) {
18
- var g = null;
19
- if (m !== void 0 && (g = "" + m), u.key !== void 0 && (g = "" + u.key), "key" in u) {
20
- m = {};
21
- for (var E in u)
22
- E !== "key" && (m[E] = u[E]);
23
- } else m = u;
24
- return u = m.ref, {
25
- $$typeof: a,
26
- type: v,
27
- key: g,
28
- ref: u !== void 0 ? u : null,
29
- props: m
30
- };
31
- }
32
- return D.Fragment = d, D.jsx = R, D.jsxs = R, D;
33
- }
34
- var L = {};
35
- /**
36
- * @license React
37
- * react-jsx-runtime.development.js
38
- *
39
- * Copyright (c) Meta Platforms, Inc. and affiliates.
40
- *
41
- * This source code is licensed under the MIT license found in the
42
- * LICENSE file in the root directory of this source tree.
43
- */
44
- var re;
45
- function me() {
46
- return re || (re = 1, process.env.NODE_ENV !== "production" && (function() {
47
- function a(e) {
48
- if (e == null) return null;
49
- if (typeof e == "function")
50
- return e.$$typeof === x ? null : e.displayName || e.name || null;
51
- if (typeof e == "string") return e;
52
- switch (e) {
53
- case A:
54
- return "Fragment";
55
- case C:
56
- return "Profiler";
57
- case P:
58
- return "StrictMode";
59
- case c:
60
- return "Suspense";
61
- case p:
62
- return "SuspenseList";
63
- case h:
64
- return "Activity";
65
- }
66
- if (typeof e == "object")
67
- switch (typeof e.tag == "number" && console.error(
68
- "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
69
- ), e.$$typeof) {
70
- case I:
71
- return "Portal";
72
- case F:
73
- return e.displayName || "Context";
74
- case Y:
75
- return (e._context.displayName || "Context") + ".Consumer";
76
- case s:
77
- var n = e.render;
78
- return e = e.displayName, e || (e = n.displayName || n.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
79
- case i:
80
- return n = e.displayName || null, n !== null ? n : a(e.type) || "Memo";
81
- case k:
82
- n = e._payload, e = e._init;
83
- try {
84
- return a(e(n));
85
- } catch {
86
- }
87
- }
88
- return null;
89
- }
90
- function d(e) {
91
- return "" + e;
92
- }
93
- function R(e) {
94
- try {
95
- d(e);
96
- var n = !1;
97
- } catch {
98
- n = !0;
99
- }
100
- if (n) {
101
- n = console;
102
- var o = n.error, l = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
103
- return o.call(
104
- n,
105
- "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
106
- l
107
- ), d(e);
108
- }
109
- }
110
- function v(e) {
111
- if (e === A) return "<>";
112
- if (typeof e == "object" && e !== null && e.$$typeof === k)
113
- return "<...>";
114
- try {
115
- var n = a(e);
116
- return n ? "<" + n + ">" : "<...>";
117
- } catch {
118
- return "<...>";
119
- }
120
- }
121
- function u() {
122
- var e = w.A;
123
- return e === null ? null : e.getOwner();
124
- }
125
- function m() {
126
- return Error("react-stack-top-frame");
127
- }
128
- function g(e) {
129
- if (V.call(e, "key")) {
130
- var n = Object.getOwnPropertyDescriptor(e, "key").get;
131
- if (n && n.isReactWarning) return !1;
132
- }
133
- return e.key !== void 0;
134
- }
135
- function E(e, n) {
136
- function o() {
137
- y || (y = !0, console.error(
138
- "%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)",
139
- n
140
- ));
141
- }
142
- o.isReactWarning = !0, Object.defineProperty(e, "key", {
143
- get: o,
144
- configurable: !0
145
- });
146
- }
147
- function N() {
148
- var e = a(this.type);
149
- return X[e] || (X[e] = !0, console.error(
150
- "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."
151
- )), e = this.props.ref, e !== void 0 ? e : null;
152
- }
153
- function j(e, n, o, l, U, B) {
154
- var f = o.ref;
155
- return e = {
156
- $$typeof: O,
157
- type: e,
158
- key: n,
159
- props: o,
160
- _owner: l
161
- }, (f !== void 0 ? f : null) !== null ? Object.defineProperty(e, "ref", {
162
- enumerable: !1,
163
- get: N
164
- }) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
165
- configurable: !1,
166
- enumerable: !1,
167
- writable: !0,
168
- value: 0
169
- }), Object.defineProperty(e, "_debugInfo", {
170
- configurable: !1,
171
- enumerable: !1,
172
- writable: !0,
173
- value: null
174
- }), Object.defineProperty(e, "_debugStack", {
175
- configurable: !1,
176
- enumerable: !1,
177
- writable: !0,
178
- value: U
179
- }), Object.defineProperty(e, "_debugTask", {
180
- configurable: !1,
181
- enumerable: !1,
182
- writable: !0,
183
- value: B
184
- }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
185
- }
186
- function b(e, n, o, l, U, B) {
187
- var f = n.children;
188
- if (f !== void 0)
189
- if (l)
190
- if (t(f)) {
191
- for (l = 0; l < f.length; l++)
192
- _(f[l]);
193
- Object.freeze && Object.freeze(f);
194
- } else
195
- console.error(
196
- "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
197
- );
198
- else _(f);
199
- if (V.call(n, "key")) {
200
- f = a(e);
201
- var M = Object.keys(n).filter(function(ue) {
202
- return ue !== "key";
203
- });
204
- l = 0 < M.length ? "{key: someKey, " + M.join(": ..., ") + ": ...}" : "{key: someKey}", $[f + l] || (M = 0 < M.length ? "{" + M.join(": ..., ") + ": ...}" : "{}", console.error(
205
- `A props object containing a "key" prop is being spread into JSX:
206
- let props = %s;
207
- <%s {...props} />
208
- React keys must be passed directly to JSX without using spread:
209
- let props = %s;
210
- <%s key={someKey} {...props} />`,
211
- l,
212
- f,
213
- M,
214
- f
215
- ), $[f + l] = !0);
216
- }
217
- if (f = null, o !== void 0 && (R(o), f = "" + o), g(n) && (R(n.key), f = "" + n.key), "key" in n) {
218
- o = {};
219
- for (var K in n)
220
- K !== "key" && (o[K] = n[K]);
221
- } else o = n;
222
- return f && E(
223
- o,
224
- typeof e == "function" ? e.displayName || e.name || "Unknown" : e
225
- ), j(
226
- e,
227
- f,
228
- o,
229
- u(),
230
- U,
231
- B
232
- );
233
- }
234
- function _(e) {
235
- S(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === k && (e._payload.status === "fulfilled" ? S(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
236
- }
237
- function S(e) {
238
- return typeof e == "object" && e !== null && e.$$typeof === O;
239
- }
240
- var T = ie, O = Symbol.for("react.transitional.element"), I = Symbol.for("react.portal"), A = Symbol.for("react.fragment"), P = Symbol.for("react.strict_mode"), C = Symbol.for("react.profiler"), Y = Symbol.for("react.consumer"), F = Symbol.for("react.context"), s = Symbol.for("react.forward_ref"), c = Symbol.for("react.suspense"), p = Symbol.for("react.suspense_list"), i = Symbol.for("react.memo"), k = Symbol.for("react.lazy"), h = Symbol.for("react.activity"), x = Symbol.for("react.client.reference"), w = T.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, V = Object.prototype.hasOwnProperty, t = Array.isArray, r = console.createTask ? console.createTask : function() {
241
- return null;
242
- };
243
- T = {
244
- react_stack_bottom_frame: function(e) {
245
- return e();
246
- }
247
- };
248
- var y, X = {}, z = T.react_stack_bottom_frame.bind(
249
- T,
250
- m
251
- )(), W = r(v(m)), $ = {};
252
- L.Fragment = A, L.jsx = function(e, n, o) {
253
- var l = 1e4 > w.recentlyCreatedOwnerStacks++;
254
- return b(
255
- e,
256
- n,
257
- o,
258
- !1,
259
- l ? Error("react-stack-top-frame") : z,
260
- l ? r(v(e)) : W
261
- );
262
- }, L.jsxs = function(e, n, o) {
263
- var l = 1e4 > w.recentlyCreatedOwnerStacks++;
264
- return b(
265
- e,
266
- n,
267
- o,
268
- !0,
269
- l ? Error("react-stack-top-frame") : z,
270
- l ? r(v(e)) : W
271
- );
272
- };
273
- })()), L;
274
- }
275
- var ne;
276
- function be() {
277
- return ne || (ne = 1, process.env.NODE_ENV === "production" ? q.exports = de() : q.exports = me()), q.exports;
278
- }
279
- var oe = be();
280
- const Ee = /^-?\d*[.,]?\d*$/, ae = (a, d) => Ee.test(a) ? a : d, Q = (a) => {
281
- const d = a.toString().split(".");
282
- return d.length > 1 ? d[1].length : 0;
283
- }, ce = (a) => a.replace(",", "."), ee = (a) => parseFloat(ce(a)), G = (a) => Number.isFinite(a) ? String(a) : "", ve = (a) => G(ee(a)), H = (a, d) => {
284
- var v;
285
- if (a.value === d) return;
286
- const R = (v = Object.getOwnPropertyDescriptor(
1
+ import { jsx as B } from "react/jsx-runtime";
2
+ import { forwardRef as j, useRef as k, useImperativeHandle as J, useState as K, useEffect as L } from "react";
3
+ const Q = /^-?\d*[.,]?\d*$/, w = (r, u) => Q.test(r) ? r : u, V = (r) => {
4
+ const u = r.toString().split(".");
5
+ return u.length > 1 ? u[1].length : 0;
6
+ }, P = (r) => r.replace(",", "."), z = (r) => parseFloat(P(r)), A = (r) => Number.isFinite(r) ? String(r) : "", U = (r) => A(z(r)), O = (r, u) => {
7
+ var f;
8
+ if (r.value === u) return;
9
+ const m = (f = Object.getOwnPropertyDescriptor(
287
10
  HTMLInputElement.prototype,
288
11
  "value"
289
- )) == null ? void 0 : v.set;
290
- R ? R.call(a, d) : a.value = d, a.dispatchEvent(new Event("input", { bubbles: !0 })), R && (a.value = a.value);
291
- }, Re = le(
12
+ )) == null ? void 0 : f.set;
13
+ m ? m.call(r, u) : r.value = u, r.dispatchEvent(new Event("input", { bubbles: !0 })), m && (r.value = r.value);
14
+ }, W = j(
292
15
  ({
293
- defaultValue: a,
294
- mask: d = ae,
295
- onBlur: R,
296
- onChange: v,
297
- onFocus: u,
298
- onKeyDown: m,
299
- step: g = 1,
300
- value: E,
301
- ...N
302
- }, j) => {
303
- const b = J(null);
304
- fe(
305
- j,
306
- () => b.current
16
+ defaultValue: r,
17
+ mask: u = w,
18
+ onBlur: m,
19
+ onChange: f,
20
+ onFocus: g,
21
+ onKeyDown: N,
22
+ step: R = 1,
23
+ value: l,
24
+ ...b
25
+ }, E) => {
26
+ const i = k(null);
27
+ J(
28
+ E,
29
+ () => i.current
307
30
  );
308
- const [_, S] = Z(
309
- E ?? (a != null ? String(a) : "")
310
- ), T = J(_);
311
- T.current = _;
312
- const O = J(!1), I = d === ae;
313
- se(() => {
314
- E === void 0 || O.current || S(E);
315
- }, [E]);
316
- const A = (s) => {
317
- const c = s.target, p = c.value, i = d(p, T.current);
318
- if (i !== p) {
319
- const h = c.selectionStart ?? p.length, x = Math.min(
320
- i.length,
321
- Math.max(0, h - (p.length - i.length))
31
+ const [p, o] = K(
32
+ l ?? (r != null ? String(r) : "")
33
+ ), v = k(p);
34
+ v.current = p;
35
+ const I = k(!1), C = u === w;
36
+ L(() => {
37
+ l === void 0 || I.current || o(l);
38
+ }, [l]);
39
+ const X = (c) => {
40
+ const n = c.target, a = n.value, s = u(a, v.current);
41
+ if (s !== a) {
42
+ const d = n.selectionStart ?? a.length, h = Math.min(
43
+ s.length,
44
+ Math.max(0, d - (a.length - s.length))
322
45
  );
323
- c.value = i, c.setSelectionRange(x, x);
46
+ n.value = s, n.setSelectionRange(h, h);
324
47
  return;
325
48
  }
326
- if (T.current = i, S(i), !v) return;
327
- const k = ce(i);
328
- if (k !== i) {
329
- const h = c.selectionStart ?? i.length, x = c.selectionEnd ?? i.length;
330
- c.value = k, v(s), c.value = i, c.setSelectionRange(h, x);
49
+ if (v.current = s, o(s), !f) return;
50
+ const x = P(s);
51
+ if (x !== s) {
52
+ const d = n.selectionStart ?? s.length, h = n.selectionEnd ?? s.length;
53
+ n.value = x, f(c), n.value = s, n.setSelectionRange(d, h);
331
54
  } else
332
- v(s);
333
- }, P = (s) => {
334
- const c = b.current;
335
- if (!c) return;
336
- const p = ee(T.current), i = Number(g) || 1, k = Q(i);
337
- let h = (Number.isFinite(p) ? p : 0) + s * i;
338
- const x = N.min !== void 0 ? Number(N.min) : NaN, w = N.max !== void 0 ? Number(N.max) : NaN;
339
- Number.isNaN(x) || (h = Math.max(h, x)), Number.isNaN(w) || (h = Math.min(h, w)), H(c, h.toFixed(k));
340
- }, C = (s) => {
341
- m == null || m(s), !s.defaultPrevented && (s.key === "ArrowUp" ? (s.preventDefault(), P(1)) : s.key === "ArrowDown" && (s.preventDefault(), P(-1)));
342
- }, Y = (s) => {
343
- O.current = !0, u == null || u(s);
344
- }, F = (s) => {
345
- O.current = !1;
346
- const c = T.current, p = I ? ve(c) : c;
347
- p !== c ? H(s.target, p) : E !== void 0 && E !== c && S(E), R == null || R(s);
55
+ f(c);
56
+ }, M = (c) => {
57
+ const n = i.current;
58
+ if (!n) return;
59
+ const a = z(v.current), s = Number(R) || 1, x = V(s);
60
+ let d = (Number.isFinite(a) ? a : 0) + c * s;
61
+ const h = b.min !== void 0 ? Number(b.min) : NaN, T = b.max !== void 0 ? Number(b.max) : NaN;
62
+ Number.isNaN(h) || (d = Math.max(d, h)), Number.isNaN(T) || (d = Math.min(d, T)), O(n, d.toFixed(x));
348
63
  };
349
- return /* @__PURE__ */ oe.jsx(
64
+ return /* @__PURE__ */ B(
350
65
  "input",
351
66
  {
352
67
  inputMode: "decimal",
353
- ...N,
68
+ ...b,
354
69
  type: "text",
355
- ref: b,
356
- value: _,
357
- onBlur: F,
358
- onChange: A,
359
- onFocus: Y,
360
- onKeyDown: C
70
+ ref: i,
71
+ value: p,
72
+ onBlur: (c) => {
73
+ I.current = !1;
74
+ const n = v.current, a = C ? U(n) : n;
75
+ a !== n ? O(c.target, a) : l !== void 0 && l !== n && o(l), m == null || m(c);
76
+ },
77
+ onChange: X,
78
+ onFocus: (c) => {
79
+ I.current = !0, g == null || g(c);
80
+ },
81
+ onKeyDown: (c) => {
82
+ N == null || N(c), !c.defaultPrevented && (c.key === "ArrowUp" ? (c.preventDefault(), M(1)) : c.key === "ArrowDown" && (c.preventDefault(), M(-1)));
83
+ }
361
84
  }
362
85
  );
363
86
  }
364
- ), _e = [
87
+ ), Z = [
365
88
  "metaKey",
366
89
  "ctrlKey",
367
90
  "altKey",
368
91
  "shiftKey"
369
- ], pe = 3;
370
- function he({
371
- value: a,
372
- modifiers: d = {
373
- altKey: 1,
374
- ctrlKey: 1,
375
- metaKey: 1,
376
- shiftKey: 0.1
377
- },
378
- style: R = {},
379
- onBlur: v,
380
- onFocus: u,
381
- onKeyDown: m,
382
- onPointerCancel: g,
383
- onPointerDown: E,
384
- onPointerMove: N,
385
- onPointerUp: j,
386
- ...b
387
- }) {
388
- const _ = J(null), [S, T] = Z(!1), [O, I] = Z(!1), A = b.step ? +b.step : 1, P = b.min !== void 0 ? +b.min : void 0, C = b.max !== void 0 ? +b.max : void 0, Y = {
389
- cursor: S && !O ? void 0 : "ew-resize",
390
- touchAction: "none",
391
- ...R
392
- };
393
- se(
394
- () => () => {
395
- const t = _.current;
396
- t != null && t.scrubbing && (document.body.style.cursor = t.previousBodyCursor);
92
+ ], tt = 3, nt = j(
93
+ ({
94
+ value: r,
95
+ modifiers: u = {
96
+ altKey: 1,
97
+ ctrlKey: 1,
98
+ metaKey: 1,
99
+ shiftKey: 0.1
397
100
  },
398
- []
399
- );
400
- const F = (t) => {
401
- for (const r of _e)
402
- if (t[r]) return d[r] ?? 1;
403
- return 1;
404
- }, s = (t, r, y) => {
405
- if (_.current = null, !!r.scrubbing) {
406
- I(!1), document.body.style.cursor = r.previousBodyCursor;
407
- try {
408
- t.releasePointerCapture(r.pointerId);
409
- } catch {
101
+ style: m = {},
102
+ onBlur: f,
103
+ onFocus: g,
104
+ onKeyDown: N,
105
+ onPointerCancel: R,
106
+ onPointerDown: l,
107
+ onPointerMove: b,
108
+ onPointerUp: E,
109
+ ...i
110
+ }, p) => {
111
+ const o = k(null), [v, I] = K(!1), [C, X] = K(!1), M = i.step ? +i.step : 1, S = i.min !== void 0 ? +i.min : void 0, F = i.max !== void 0 ? +i.max : void 0, D = {
112
+ cursor: v && !C ? void 0 : "ew-resize",
113
+ touchAction: "none",
114
+ ...m
115
+ };
116
+ L(
117
+ () => () => {
118
+ const t = o.current;
119
+ t != null && t.scrubbing && (document.body.style.cursor = t.previousBodyCursor);
120
+ },
121
+ []
122
+ );
123
+ const c = (t) => {
124
+ for (const e of Z)
125
+ if (t[e]) return u[e] ?? 1;
126
+ return 1;
127
+ }, n = (t, e, y) => {
128
+ if (o.current = null, !!e.scrubbing) {
129
+ X(!1), document.body.style.cursor = e.previousBodyCursor;
130
+ try {
131
+ t.releasePointerCapture(e.pointerId);
132
+ } catch {
133
+ }
134
+ y && O(t, A(e.startValue)), t.blur();
135
+ }
136
+ }, a = (t) => {
137
+ if (l == null || l(t), t.defaultPrevented || t.button !== 0 || i.disabled || i.readOnly) return;
138
+ const e = t.currentTarget;
139
+ if (document.activeElement === e) return;
140
+ let y = z(e.value);
141
+ Number.isFinite(y) || (y = Number(i.defaultValue ?? S ?? 0) || 0), o.current = {
142
+ pointerId: t.pointerId,
143
+ startX: t.clientX,
144
+ lastX: t.clientX,
145
+ startValue: y,
146
+ accumulated: y,
147
+ scrubbing: !1,
148
+ previousBodyCursor: ""
149
+ };
150
+ }, s = (t) => {
151
+ b == null || b(t);
152
+ const e = o.current;
153
+ if (!e || e.pointerId !== t.pointerId) return;
154
+ const y = t.currentTarget;
155
+ if (t.buttons === 0) {
156
+ o.current = null;
157
+ return;
410
158
  }
411
- y && H(t, G(r.startValue)), t.blur();
412
- }
413
- }, c = (t) => {
414
- if (E == null || E(t), t.defaultPrevented || t.button !== 0 || b.disabled || b.readOnly) return;
415
- const r = t.currentTarget;
416
- if (document.activeElement === r) return;
417
- let y = ee(r.value);
418
- Number.isFinite(y) || (y = Number(b.defaultValue ?? P ?? 0) || 0), _.current = {
419
- pointerId: t.pointerId,
420
- startX: t.clientX,
421
- lastX: t.clientX,
422
- startValue: y,
423
- accumulated: y,
424
- scrubbing: !1,
425
- previousBodyCursor: ""
159
+ if (!e.scrubbing) {
160
+ if (Math.abs(t.clientX - e.startX) < tt) return;
161
+ e.scrubbing = !0, e.lastX = t.clientX, X(!0), e.previousBodyCursor = document.body.style.cursor, document.body.style.cursor = "ew-resize";
162
+ try {
163
+ y.setPointerCapture(t.pointerId);
164
+ } catch {
165
+ }
166
+ }
167
+ const H = c(t), $ = M * H, q = V(M) + V(H);
168
+ e.accumulated += (t.clientX - e.lastX) * $, e.lastX = t.clientX, S !== void 0 && (e.accumulated = Math.max(e.accumulated, S)), F !== void 0 && (e.accumulated = Math.min(e.accumulated, F));
169
+ const _ = +e.accumulated.toFixed(q);
170
+ Number.isNaN(_) || O(y, A(_));
171
+ }, x = (t) => {
172
+ const e = o.current;
173
+ !e || e.pointerId !== t.pointerId || n(t.currentTarget, e, !1);
174
+ }, d = (t) => {
175
+ E == null || E(t), x(t);
176
+ }, h = (t) => {
177
+ R == null || R(t), x(t);
178
+ }, T = (t) => {
179
+ const e = o.current;
180
+ if (t.key === "Escape" && (e != null && e.scrubbing)) {
181
+ t.preventDefault(), n(t.currentTarget, e, !0);
182
+ return;
183
+ }
184
+ N == null || N(t);
185
+ }, G = (t) => {
186
+ I(!0), g == null || g(t);
187
+ }, Y = (t) => {
188
+ I(!1), f == null || f(t);
426
189
  };
427
- }, p = (t) => {
428
- N == null || N(t);
429
- const r = _.current;
430
- if (!r || r.pointerId !== t.pointerId) return;
431
- const y = t.currentTarget;
432
- if (t.buttons === 0) {
433
- _.current = null;
434
- return;
435
- }
436
- if (!r.scrubbing) {
437
- if (Math.abs(t.clientX - r.startX) < pe) return;
438
- r.scrubbing = !0, r.lastX = t.clientX, I(!0), r.previousBodyCursor = document.body.style.cursor, document.body.style.cursor = "ew-resize";
439
- try {
440
- y.setPointerCapture(t.pointerId);
441
- } catch {
190
+ return /* @__PURE__ */ B(
191
+ W,
192
+ {
193
+ ...i,
194
+ ref: p,
195
+ defaultValue: i.defaultValue ?? 0,
196
+ style: D,
197
+ value: r !== void 0 ? A(r) : void 0,
198
+ onBlur: Y,
199
+ onFocus: G,
200
+ onKeyDown: T,
201
+ onPointerCancel: h,
202
+ onPointerDown: a,
203
+ onPointerMove: s,
204
+ onPointerUp: d
442
205
  }
443
- }
444
- const X = F(t), z = A * X, W = Q(A) + Q(X);
445
- r.accumulated += (t.clientX - r.lastX) * z, r.lastX = t.clientX, P !== void 0 && (r.accumulated = Math.max(r.accumulated, P)), C !== void 0 && (r.accumulated = Math.min(r.accumulated, C));
446
- const $ = +r.accumulated.toFixed(W);
447
- Number.isNaN($) || H(y, G($));
448
- }, i = (t) => {
449
- const r = _.current;
450
- !r || r.pointerId !== t.pointerId || s(t.currentTarget, r, !1);
451
- }, k = (t) => {
452
- j == null || j(t), i(t);
453
- }, h = (t) => {
454
- g == null || g(t), i(t);
455
- }, x = (t) => {
456
- const r = _.current;
457
- if (t.key === "Escape" && (r != null && r.scrubbing)) {
458
- t.preventDefault(), s(t.currentTarget, r, !0);
459
- return;
460
- }
461
- m == null || m(t);
462
- }, w = (t) => {
463
- T(!0), u == null || u(t);
464
- }, V = (t) => {
465
- T(!1), v == null || v(t);
466
- };
467
- return /* @__PURE__ */ oe.jsx(
468
- Re,
469
- {
470
- ...b,
471
- defaultValue: b.defaultValue ?? 0,
472
- style: Y,
473
- value: a !== void 0 ? G(a) : void 0,
474
- onBlur: V,
475
- onFocus: w,
476
- onKeyDown: x,
477
- onPointerCancel: h,
478
- onPointerDown: c,
479
- onPointerMove: p,
480
- onPointerUp: k
481
- }
482
- );
483
- }
206
+ );
207
+ }
208
+ );
484
209
  export {
485
- he as InteractiveInput,
486
- Re as MaskedInput
210
+ nt as InteractiveInput,
211
+ W as MaskedInput
487
212
  };
@@ -19,5 +19,5 @@ interface InteractiveInputProps extends React.InputHTMLAttributes<HTMLInputEleme
19
19
  * modifier keys (read live from each pointer event) and can be cancelled with
20
20
  * Escape, restoring the value from before the drag.
21
21
  */
22
- export default function InteractiveInput({ value, modifiers, style: _style, onBlur, onFocus, onKeyDown, onPointerCancel, onPointerDown, onPointerMove, onPointerUp, ...props }: InteractiveInputProps): import("react").JSX.Element;
23
- export {};
22
+ declare const InteractiveInput: import("react").ForwardRefExoticComponent<InteractiveInputProps & import("react").RefAttributes<HTMLInputElement>>;
23
+ export default InteractiveInput;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@designbyadrian/react-interactive-input",
3
- "version": "3.0.0",
3
+ "version": "3.1.1",
4
4
  "description": "Adjust values in numeric input boxes by clicking and dragging horizontally, just like in Blender and similar 3D applications.",
5
5
  "keywords": [
6
6
  "react",
@@ -46,8 +46,8 @@
46
46
  "dist/types"
47
47
  ],
48
48
  "peerDependencies": {
49
- "react": "^19.0.0",
50
- "react-dom": "^19.0.0"
49
+ "react": ">=18.0.0",
50
+ "react-dom": ">=18.0.0"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@chromatic-com/storybook": "^3.2.6",