numora 3.2.0 → 3.3.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.
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var oe=Object.defineProperty;var le=(e,t,n)=>t in e?oe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var D=(e,t,n)=>le(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var p=(e=>(e.Blur="blur",e.Change="change",e))(p||{}),E=(e=>(e.None="none",e.Thousand="thousand",e.Lakh="lakh",e.Wan="wan",e.Locale="locale",e))(E||{});const G=2,Z=0,P=p.Blur,he=",",H=E.None,$=".",k=!1,B=!1,W=!1,U=!1;function y(e){return e.replace(/[-[\]/{}()*+?.\\^$|]/g,"\\$&")}const z=new Map;function O(e,t="g"){const n=`${e}:${t}`;let r=z.get(n);return r||(r=new RegExp(e,t),z.set(n,r)),r}function ue(e,t="g"){const n=y(e);return O(n,t)}const de=/[.,]/g;function _(e){return{decimalSeparator:(e==null?void 0:e.decimalSeparator)??$,thousandSeparator:e==null?void 0:e.thousandSeparator}}function Y(e,t){const n=e.startsWith("-"),r=n?e.slice(1):e,[a="",i=""]=r.split(t);return{sign:n?"-":"",integer:a,decimal:i}}function fe(e,t){if(!e.value.includes(t))return!1;const{selectionStart:n,selectionEnd:r,value:a}=e;return!a.slice(n??0,r??0).includes(t)}function ge(e,t,n){const{key:r}=e;if(r!==","&&r!==".")return!1;if(fe(t,n))return!0;if(r!==n){const{selectionStart:a,selectionEnd:i,value:s}=t,c=a??0,l=i??c;t.value=s.slice(0,c)+n+s.slice(l);const o=c+1;return t.setSelectionRange(o,o),!0}return!1}const Se=(e,t,n=$)=>{const{sign:r,integer:a,decimal:i}=Y(e,n);if(!i)return e;const s=i.slice(0,t);return`${r}${a}${n}${s}`},Ee=(e,t=$)=>{const n=e.indexOf(t);if(n===-1||n===e.length-1)return e;const r=e.slice(0,n+1),a=e.slice(n+1),s=t==="."||t===","?de:O("[,\\."+y(t)+"]","g");return r+a.replace(s,"")},me=(e,t=0,n=$)=>{if(t<=0)return e;const{sign:r,integer:a,decimal:i}=Y(e,n);if(i.length>=t)return e;const s=i.padEnd(t,"0");return`${r}${a}${n}${s}`},v={thousand:{size:3},lakh:{firstGroup:3,restGroup:2},wan:{size:4}},pe=/^(0+)/;function Q(e,t,n=E.Thousand,r=!1,a="."){if(!e||e==="0"||e===a||e==="-"||e===`-${a}`)return e;const i=e.includes(a),s=e.startsWith("-"),c=s?e.slice(1):e,[l,o]=c.split(a);if(!l){const u=o?`${a}${o}`:c;return s?`-${u}`:u}if(r&&l.startsWith("0")&&l.length>1){const u=l.match(pe);if(u){const g=u[1],S=l.slice(g.length);if(S){const m=J(S,t,n),f=g+m,b=s?"-":"";return i?o?`${b}${f}${a}${o}`:`${b}${f}${a}`:`${b}${f}`}}}const h=J(l,t,n),d=s?"-":"";return i?o?`${d}${h}${a}${o}`:`${d}${h}${a}`:`${d}${h}`}function J(e,t,n){if(e==="0"||e==="")return e;switch(n){case E.None:return e;case E.Thousand:return X(e,t,v.thousand.size);case E.Lakh:return be(e,t);case E.Wan:return X(e,t,v.wan.size);default:return e}}function be(e,t){if(e.length<=v.lakh.firstGroup)return e;const n=[],r=e.length-v.lakh.firstGroup;n.unshift(e.slice(r));for(let a=r;a>0;a-=v.lakh.restGroup)n.unshift(e.slice(Math.max(0,a-v.lakh.restGroup),a));return n.join(t)}function X(e,t,n){const r=[];for(let a=e.length;a>0;a-=n)r.unshift(e.slice(Math.max(0,a-n),a));return r.join(t)}function Le(e,t,n){return(t==null?void 0:t.formatOn)===p.Change&&t.thousandSeparator?Q(e,t.thousandSeparator,t.ThousandStyle??E.None,t.enableLeadingZeros,(n==null?void 0:n.decimalSeparator)??$):e}function N(e,t,n){let r=0;for(let a=0;a<t&&a<e.length;a++)e[a]!==n&&r++;return r}function Ne(e,t,n){if(t===0)return 0;let r=0;for(let a=0;a<e.length;a++)if(e[a]!==n){if(r===t-1)return a+1;r++}return e.length}function T(e,t,n){if(t===0)return 0;let r=0;for(let a=0;a<e.length;a++)if(e[a]!==n){if(r++,r===t)return a+1;if(r>t)return a}return e.length}function V(e,t,n){return t<0||t>=e.length?!1:e[t]===n}const ve=/\d/;function $e(e,t={}){const{thousandSeparator:n,decimalSeparator:r=".",prefix:a="",suffix:i=""}=t,s=new Array(e.length+1).fill(!0);if(a&&s.fill(!1,0,a.length),i){const c=e.length-i.length;s.fill(!1,c+1,e.length+1)}for(let c=0;c<e.length;c++){const l=e[c];(n&&l===n||l===r)&&(s[c]=!1,c+1<e.length&&!ve.test(e[c+1])&&(s[c+1]=!1))}return s.some(c=>c)||s.fill(!0),s}function x(e,t,n,r){const a=e.length;if(t=Math.max(0,Math.min(t,a)),!n[t]){let i=t;for(;i<=a&&!n[i];)i++;let s=t;for(;s>=0&&!n[s];)s--;i<=a&&s>=0?t=t-s<i-t?s:i:i<=a?t=i:s>=0&&(t=s)}return(t===-1||t>a)&&(t=a),t}const j=/(\d+\.?\d*)\s*[kmbt]$/i,De=(e,t)=>e===t;function ye(e,t,n,r,a,i,s=".",c={}){if(n<0)return 0;if(n>e.length||e===""||t===""||j.test(e)&&!j.test(t)&&t.length>e.length&&n>=e.length-1)return t.length;const l=t.length<e.length,o=V(e,n,r),h=e.indexOf(s),d=t.indexOf(s);if(c.isCharacterEquivalent&&e!==t){const f=we(e,t,n,c.isCharacterEquivalent||De,i,c);if(f!==void 0)return f}const g=new Map,S=(f,b,w)=>{const C=`${f===e?"o":"n"}:${b}`;return g.has(C)||g.set(C,N(f,b,r)),g.get(C)};if(l)return Ce(e,t,n,r,o,h,d,i,c,S);const m=Re(e,t,n,r,o,S);return c.boundary?x(t,m,c.boundary):m}function we(e,t,n,r,a,i){const s=e.length,c=t.length;let l=0,o=0,h=c;for(let u=0;u<s;u++){let g=-1;for(let S=l;S<c;S++)if(r(e[u],t[S],{oldValue:e,newValue:t,typedRange:a,oldIndex:u,newIndex:S})){g=S;break}g!==-1&&(l=g+1,u<n?o=g+1:h===c&&/\d/.test(e[u])&&(h=g))}if(o>h)return h;const d=n-o<h-n?o:h;return i.boundary?x(t,d,i.boundary):d}function Ce(e,t,n,r,a,i,s,c,l={},o=N){if(a)return Ie(e,t,n,r,s,o);const h=o(e,n,r),d=o(e,e.length,r),u=o(t,t.length,r),g=d-u,S=Me(e,n,r,h,g,i,c,o),m=i===-1||n<=i,f=Ae(t,S,r,g,c,m,s,o);return l.boundary?x(t,f,l.boundary):f}function Ie(e,t,n,r,a,i=N){const s=n+1;if(s<e.length){const c=i(e,s,r),l=Ne(t,c,r);return l<t.length&&t[l]!==r?l+1:l}return n}function Me(e,t,n,r,a,i,s,c=N){if(s){const{start:o,isDelete:h}=s;return h?c(e,o,n):Math.max(0,c(e,o,n))}return t>0&&e[t-1]===n&&a>0?r+1:r}function K(e,t,n,r,a,i,s=N){if(t>0&&t<e.length&&s(e,t,r)===n){if(e[t]===r&&i&&a>0&&t<e.length-1)return t+1;if(!i&&a>0&&t<e.length-1)return Math.min(t+1,e.length)}return t}function Ae(e,t,n,r,a,i,s,c=N){if(i&&s!==-1){const o=e.substring(0,s),h=c(o,o.length,n);if(t<=h){const d=T(o,t,n);return K(o,d,t,n,r,a,c)}}const l=T(e,t,n);return K(e,l,t,n,r,a,c)}function Re(e,t,n,r,a,i=N){const s=n>=e.length,c=i(e,n,r),l=i(e,e.length,r),o=i(t,t.length,r);if(s||c===l)return t.length;const h=o-l;let d=c;h>0&&!s&&c<l&&(d=c+1);const u=T(t,d,r);return a&&!V(t,u,r)?Math.max(0,u-1):u}function Te(e,t,n){const{selectionStart:r,selectionEnd:a,endOffset:i=0}=e;if(r!==a){const h=a-r;return{start:r,end:a,deletedLength:h,isDelete:!1}}if(i>0){const h=i;return{start:r,end:r+h,deletedLength:h,isDelete:!0}}const c=t.length,l=n.length,o=c-l;if(!(o<=0))return{start:r,end:r+o,deletedLength:o,isDelete:!1}}function Oe(e,t){if(e===t)return;let n=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;let r=e.length-1,a=t.length-1;for(;r>=n&&a>=n&&e[r]===t[a];)r--,a--;const i=r-n+1,s=a-n+1;if(!(i===0&&s===0))return{start:n,end:r+1,deletedLength:i,isDelete:i>s}}function q(e,t){if(e.value=e.value,e===null)return!1;if(e.createTextRange){const n=e.createTextRange();return n.move("character",t),n.select(),!0}return e.selectionStart!==null||e.selectionStart===0?(e.focus(),e.setSelectionRange(t,t),!0):(e.focus(),!1)}function _e(e,t,n){return e.selectionStart===0&&e.selectionEnd===e.value.length?null:(q(e,t),setTimeout(()=>{e.value===n&&e.selectionStart!==t&&q(e,t)},0))}function xe(e){return Math.max(e.selectionStart,e.selectionEnd)}function Ge(e,t,n){if((n==null?void 0:n.formatOn)!==p.Change||!n.thousandSeparator)return;const{selectionStart:r,selectionEnd:a,value:i}=t;if(r===null||a===null||r!==a)return;const{key:s}=e,c=n.thousandSeparator;s==="Backspace"&&r>0&&i[r-1]===c&&t.setSelectionRange(r-1,r-1),s==="Delete"&&i[r]===c&&t.setSelectionRange(r+1,r+1)}function Ze(e,t,n,r,a,i,s){if(!a)return;const{selectionStart:c=0,selectionEnd:l=0,endOffset:o=0}=a;let h=Te({selectionStart:c,selectionEnd:l,endOffset:o},t,n);if(h||(h=Oe(t,n)),!h)return;const d=$e(n,{thousandSeparator:(s==null?void 0:s.thousandSeparator)??i.thousandSeparator,decimalSeparator:i.decimalSeparator}),u={thousandSeparator:(s==null?void 0:s.thousandSeparator)??i.thousandSeparator,isCharacterEquivalent:(f,b)=>{const w=(s==null?void 0:s.thousandSeparator)??i.thousandSeparator;return w&&f===w?!1:f===b},boundary:d},g=(s==null?void 0:s.thousandSeparator)??i.thousandSeparator??",",S=(s==null?void 0:s.ThousandStyle)??E.None,m=ye(t,n,r,g,S,h,i.decimalSeparator,u);_e(e,m,n)}const Pe=(e,t=!1,n=".")=>{const r=y(n),a=O(`[^0-9${r}]`,"g");if(!t)return e.replace(a,"");const i=e.startsWith("-"),s=e.replace(a,"");return i&&(s.length>0||e==="-")?"-"+s:s},ke=/([+-]?\d+\.?\d*)[eE]([+-]?\d+)/g,F=/^0+$/,A=/\.?0+$/;function Be(e){return!e.includes("e")&&!e.includes("E")?e:e.replace(ke,(t,n,r)=>{const a=parseInt(r,10);if(a===0)return n;const i=n.startsWith("-"),s=i?n.slice(1):n,[c,l=""]=s.split("."),o=a>0?We(c,l,a):Ue(c,l,Math.abs(a));return i?"-"+o:o})}function We(e,t,n){const r=e+t;if(r==="0"||F.test(r))return"0";const a=t.length;if(n<=a){const s=r.slice(0,e.length+n),c=r.slice(e.length+n);return c?`${s}.${c}`:s}const i=n-a;return r+"0".repeat(i)}function Ue(e,t,n){const r=e+t;if(r==="0"||F.test(r))return"0";const i=e.length-n;if(i<=0){const s=Math.abs(i),c=`0.${"0".repeat(s)}${r}`;return R(c)}if(i<e.length){const s=r.slice(0,i),c=r.slice(i),l=`${s}.${c}`;return R(l)}return R(r)}function R(e){if(!e.includes("."))return e;if(e==="0.")return"0";if(e.startsWith("0.")){const t=e.replace(A,"");return t==="0"?"0":t||"0"}if(e.startsWith("-0.")){const t=e.replace(A,"");return t==="-0"||t==="0"?"0":t||"0"}return e.replace(A,"")||e}const ze=/(\d+\.?\d*)\s*([kmbt])/gi,Je=/^0+/,Xe=/^(-?)0+([1-9])/,je=/^-?0+$/,Ke=/\.?0+$/,qe={k:3,m:6,b:9,t:12};function He(e){return e.replace(ze,(t,n,r)=>{const a=r.toLowerCase(),i=qe[a];if(!i)return t;const[s,c=""]=n.split("."),l=s.replace(Je,"")||"0";let o;if(c.length===0)o=l+"0".repeat(i);else if(c.length<=i){const h=i-c.length;o=l+c+"0".repeat(h)}else{const h=c.slice(0,i),d=c.slice(i);o=l+h+"."+d}return o=o.replace(Xe,"$1$2"),je.test(o)&&(o="0"),o.includes(".")&&(o=o.replace(Ke,"")),o})}function Ye(e){if(!e||e==="0"||e==="-0"||e==="-"||e===".")return e;const t=e.startsWith("-"),n=t?e.slice(1):e;if(n===".")return e;if(n.includes(".")){const[a,i]=n.split(".");if(a){const c=(a.replace(/^0+/,"")||"0")+"."+i;return t?"-"+c:c}return e}if(n.startsWith("0")){const a=n.replace(/^0+/,"")||"0";return t?"-"+a:a}return e}function Qe(e){return e.replace(/[\s\u200B]/g,"")}function L(e,t){const n=ue(t);return e.replace(n,"")}const Ve=(e,t)=>{let n=Qe(e);return t!=null&&t.thousandSeparator&&(n=L(n,t.thousandSeparator)),t!=null&&t.enableCompactNotation&&(n=He(n)),n=Be(n),n=Pe(n,t==null?void 0:t.enableNegative,t==null?void 0:t.decimalSeparator),n=Ee(n,t==null?void 0:t.decimalSeparator),t!=null&&t.enableLeadingZeros||(n=Ye(n)),n};function Fe(e,t,n){return{enableCompactNotation:e==null?void 0:e.enableCompactNotation,enableNegative:e==null?void 0:e.enableNegative,enableLeadingZeros:e==null?void 0:e.enableLeadingZeros,decimalSeparator:t.decimalSeparator,thousandSeparator:n?t.thousandSeparator:void 0}}function M(e,t,n,r){const a=_(n),i=r??(n==null?void 0:n.formatOn)===p.Change,s=Ve(e,Fe(n,a,i)),c=Se(s,t,a.decimalSeparator),l=(n==null?void 0:n.decimalMinLength)??0,o=me(c,l,a.decimalSeparator);return{formatted:Le(o,n,a),raw:o}}function et(e,t,n){const r=!!(n!=null&&n.thousandSeparator);return M(e,t,n,r)}function tt(e,t,n){if(e==="Backspace"||e==="Delete")return e==="Delete"&&t===n?{endOffset:1}:{endOffset:0}}function ee(e,t){const{decimalSeparator:n}=_(t),r=e.target;if(ge(e,r,n)){e.preventDefault();return}return Ge(e,r,t),tt(e.key,r.selectionStart,r.selectionEnd)}function te(e,t,n,r){const a=e.target,i=a.value,s=xe(a),c=_(r),l=(r==null?void 0:r.formatOn)===p.Change,{formatted:o,raw:h}=M(i,t,r,l);return a.value=o,i!==o&&Ze(a,i,o,s,n,c,r),{formatted:o,raw:h}}function nt(e,t,n,r){const a=r-n;return e+t+a}function ne(e,t,n){var u;e.preventDefault();const r=e.target,{value:a,selectionStart:i,selectionEnd:s}=r,c=((u=e.clipboardData)==null?void 0:u.getData("text/plain"))||"",l=a.slice(0,i||0)+c+a.slice(s||0),{formatted:o,raw:h}=M(l,t,n,!0);r.value=o;const d=nt(i||0,c.length,l.length,o.length);return r.setSelectionRange(d,d),{formatted:o,raw:h}}function re(e,t){const n=y(e);return t?`^-?[0-9]*[${n}]?[0-9]*$`:`^[0-9]*[${n}]?[0-9]*$`}function ae(e){var t,n;try{const a=new Intl.NumberFormat(e).formatToParts(123456789e-2);return{decimalSeparator:((t=a.find(i=>i.type==="decimal"))==null?void 0:t.value)??".",thousandSeparator:((n=a.find(i=>i.type==="group"))==null?void 0:n.value)??","}}catch{return{thousandSeparator:",",decimalSeparator:"."}}}function ie(e){let t=e.thousandSeparator??he,n=e.decimalSeparator??$,r=e.thousandStyle??H;if(e.thousandStyle===E.Locale||e.decimalSeparator==="auto"){const i=ae();e.thousandStyle===E.Locale&&(t=e.thousandSeparator??i.thousandSeparator,n=e.decimalSeparator==="auto"||e.decimalSeparator===void 0?i.decimalSeparator:e.decimalSeparator,r=E.Thousand),e.decimalSeparator==="auto"&&(n=i.decimalSeparator)}return{thousandSeparator:t,thousandStyle:r,decimalSeparator:n}}function se(e){rt(e.decimalMaxLength),at(e.decimalMinLength),it(e.decimalMinLength,e.decimalMaxLength),st(e.formatOn),ct(e.thousandSeparator),ot(e.thousandStyle),lt(e.decimalSeparator),ht(e.thousandSeparator,e.decimalSeparator),I("enableCompactNotation",e.enableCompactNotation),I("enableNegative",e.enableNegative),I("enableLeadingZeros",e.enableLeadingZeros),I("rawValueMode",e.rawValueMode),ut(e.onChange)}function rt(e){if(e!==void 0){if(typeof e!="number")throw new Error(`decimalMaxLength must be a number. Received: ${typeof e} (${JSON.stringify(e)})`);if(!Number.isInteger(e))throw new Error(`decimalMaxLength must be an integer. Received: ${e}`);if(e<0)throw new Error(`decimalMaxLength must be non-negative. Received: ${e}`)}}function at(e){if(e!==void 0){if(typeof e!="number")throw new Error(`decimalMinLength must be a number. Received: ${typeof e} (${JSON.stringify(e)})`);if(!Number.isInteger(e))throw new Error(`decimalMinLength must be an integer. Received: ${e}`);if(e<0)throw new Error(`decimalMinLength must be non-negative. Received: ${e}`)}}function it(e,t){if(!(e===void 0||t===void 0)&&e>t)throw new Error(`decimalMinLength (${e}) cannot be greater than decimalMaxLength (${t}).`)}function st(e){if(e!==void 0&&e!==p.Blur&&e!==p.Change)throw new Error(`formatOn must be either ${p.Blur} or ${p.Change}. Received: ${JSON.stringify(e)}`)}function ct(e){if(e!==void 0){if(typeof e!="string")throw new Error(`thousandSeparator must be a string. Received: ${typeof e} (${JSON.stringify(e)})`);if(e.length===0)throw new Error(`thousandSeparator cannot be empty. Received: ${JSON.stringify(e)}`);if(e.length>1)throw new Error(`thousandSeparator must be a single character. Received: "${e}" (length: ${e.length})`)}}function ot(e){if(e!==void 0&&!Object.values(E).includes(e))throw new Error(`ThousandStyle must be one of: ${Object.values(E).map(t=>`'${t}'`).join(", ")}. Received: ${JSON.stringify(e)}`)}function lt(e){if(!(e===void 0||e==="auto")){if(typeof e!="string")throw new Error(`decimalSeparator must be a string. Received: ${typeof e} (${JSON.stringify(e)})`);if(e.length===0)throw new Error(`decimalSeparator cannot be empty. Received: ${JSON.stringify(e)}`);if(e.length>1)throw new Error(`decimalSeparator must be a single character. Received: "${e}" (length: ${e.length})`)}}function ht(e,t){if(!(e===void 0||t===void 0)&&t!=="auto"&&e===t)throw new Error(`Decimal separator can't be same as thousand separator. thousandSeparator: ${e}, decimalSeparator: ${t}`)}function I(e,t){if(t!==void 0&&typeof t!="boolean")throw new Error(`${e} must be a boolean. Received: ${typeof t} (${JSON.stringify(t)})`)}function ut(e){if(e!==void 0&&typeof e!="function")throw new Error(`onChange must be a function or undefined. Received: ${typeof e} (${JSON.stringify(e)})`)}class dt{constructor(t,{decimalMaxLength:n=G,decimalMinLength:r=Z,formatOn:a=P,thousandSeparator:i,thousandStyle:s=H,decimalSeparator:c,enableCompactNotation:l=k,enableNegative:o=B,enableLeadingZeros:h=W,rawValueMode:d=U,onChange:u,...g}){D(this,"element");D(this,"resolvedOptions");D(this,"rawValue","");D(this,"caretPositionBeforeChange");se({decimalMaxLength:n,decimalMinLength:r,formatOn:a,thousandSeparator:i,thousandStyle:s,decimalSeparator:c,enableCompactNotation:l,enableNegative:o,enableLeadingZeros:h,rawValueMode:d,onChange:u});const S={decimalMaxLength:n,decimalMinLength:r,onChange:u,formatOn:a,thousandSeparator:i,thousandStyle:s,decimalSeparator:c,enableCompactNotation:l,enableNegative:o,enableLeadingZeros:h,rawValueMode:d,...g};if(this.resolvedOptions=this.getResolvedOptions(S),this.createInputElement(t,S),this.setupEventListeners(),this.resolvedOptions.rawValueMode&&this.element.value){const m=this.element.value,f=this.resolvedOptions.thousandSeparator?L(m,this.resolvedOptions.thousandSeparator):m;this.rawValue=f,this.element.value=this.formatValueForDisplay(f)}else if(this.element.value){const m=this.element.value;this.element.value=this.formatValueForDisplay(m)}}createInputElement(t,n){this.element=document.createElement("input"),this.element.setAttribute("type","text"),this.element.setAttribute("inputmode","decimal"),this.element.setAttribute("spellcheck","false"),this.element.setAttribute("autocomplete","off");const r=re(this.resolvedOptions.decimalSeparator,this.resolvedOptions.enableNegative);this.element.setAttribute("pattern",r);const{decimalMaxLength:a,decimalMinLength:i,formatOn:s,thousandSeparator:c,thousandStyle:l,decimalSeparator:o,enableCompactNotation:h,enableNegative:d,enableLeadingZeros:u,rawValueMode:g,onChange:S,value:m,defaultValue:f,type:b,inputMode:w,spellcheck:C,autocomplete:ft,...ce}=n;Object.assign(this.element,ce),m!==void 0?this.element.value=m:f!==void 0&&(this.element.defaultValue=f,this.element.value=f),t.appendChild(this.element)}setupEventListeners(){this.element.addEventListener("input",this.handleChange.bind(this)),this.element.addEventListener("keydown",this.handleKeyDown.bind(this)),this.element.addEventListener("paste",this.handlePaste.bind(this)),this.resolvedOptions.formatOn===p.Blur&&this.resolvedOptions.thousandSeparator&&(this.element.addEventListener("focus",this.handleFocus.bind(this)),this.element.addEventListener("blur",this.handleBlur.bind(this)))}getResolvedOptions(t){const n=ie({thousandSeparator:t.thousandSeparator,thousandStyle:t.thousandStyle,decimalSeparator:t.decimalSeparator});return{decimalMaxLength:t.decimalMaxLength??G,decimalMinLength:t.decimalMinLength??Z,formatOn:t.formatOn??P,thousandSeparator:n.thousandSeparator,thousandStyle:n.thousandStyle,decimalSeparator:n.decimalSeparator,enableCompactNotation:t.enableCompactNotation??k,enableNegative:t.enableNegative??B,enableLeadingZeros:t.enableLeadingZeros??W,rawValueMode:t.rawValueMode??U,onChange:t.onChange}}buildFormattingOptions(){return{formatOn:this.resolvedOptions.formatOn,thousandSeparator:this.resolvedOptions.thousandSeparator,ThousandStyle:this.resolvedOptions.thousandStyle,enableCompactNotation:this.resolvedOptions.enableCompactNotation,enableNegative:this.resolvedOptions.enableNegative,enableLeadingZeros:this.resolvedOptions.enableLeadingZeros,decimalSeparator:this.resolvedOptions.decimalSeparator,decimalMinLength:this.resolvedOptions.decimalMinLength,rawValueMode:this.resolvedOptions.rawValueMode}}handleValueChange(t,n){if(this.resolvedOptions.rawValueMode&&n!==void 0&&(this.rawValue=n),this.resolvedOptions.onChange){const r=this.resolvedOptions.rawValueMode?this.rawValue:t;this.resolvedOptions.onChange(r)}}formatValueForDisplay(t){if(!t)return t;const{thousandSeparator:n,thousandStyle:r,enableLeadingZeros:a,decimalSeparator:i}=this.resolvedOptions;return n&&r!==E.None?Q(t,n,r,a,i):t}handleChange(t){const{formatted:n,raw:r}=te(t,this.resolvedOptions.decimalMaxLength,this.caretPositionBeforeChange,this.buildFormattingOptions());this.caretPositionBeforeChange=void 0,this.handleValueChange(n,r)}handleKeyDown(t){const n=t.target,{selectionStart:r,selectionEnd:a}=n,i=this.buildFormattingOptions(),s=ee(t,{formatOn:i.formatOn,thousandSeparator:i.thousandSeparator,ThousandStyle:i.ThousandStyle,decimalSeparator:i.decimalSeparator});s?this.caretPositionBeforeChange={selectionStart:r??0,selectionEnd:a??0,endOffset:s.endOffset}:this.caretPositionBeforeChange={selectionStart:r??0,selectionEnd:a??0}}handlePaste(t){const{formatted:n,raw:r}=ne(t,this.resolvedOptions.decimalMaxLength,this.buildFormattingOptions());this.handleValueChange(n,r);const a=new Event("input",{bubbles:!0,cancelable:!0});this.element.dispatchEvent(a)}handleFocus(t){if(this.resolvedOptions.formatOn===p.Blur&&this.resolvedOptions.thousandSeparator){const n=t.target;n.value=L(n.value,this.resolvedOptions.thousandSeparator)}}handleBlur(t){const n=t.target,{thousandSeparator:r,thousandStyle:a}=this.resolvedOptions;if(r&&a!==E.None&&n.value){const i=this.formatValueForDisplay(n.value);n.value=i;const s=this.resolvedOptions.rawValueMode?L(i,r):void 0;this.handleValueChange(i,s)}}getValue(){return this.resolvedOptions.rawValueMode?this.rawValue:this.element.value}setValue(t){if(this.resolvedOptions.rawValueMode){const n=this.resolvedOptions.thousandSeparator?L(t,this.resolvedOptions.thousandSeparator):t;this.rawValue=n,this.element.value=this.formatValueForDisplay(n)}else this.element.value=t}disable(){this.element.disabled=!0}enable(){this.element.disabled=!1}addEventListener(t,n){this.element.addEventListener(t,n)}removeEventListener(t,n){this.element.removeEventListener(t,n)}getElement(){return this.element}get value(){return this.getValue()}set value(t){this.setValue(t)}get valueAsNumber(){const t=this.getValue();if(!t)return NaN;const n=this.resolvedOptions.thousandSeparator?L(t,this.resolvedOptions.thousandSeparator):t,r=this.resolvedOptions.decimalSeparator&&this.resolvedOptions.decimalSeparator!=="."?n.replace(new RegExp(y(this.resolvedOptions.decimalSeparator),"g"),"."):n;return parseFloat(r)}set valueAsNumber(t){if(isNaN(t)){this.setValue("");return}const n=t.toString();this.setValue(n)}}exports.FormatOn=p;exports.NumoraInput=dt;exports.ThousandStyle=E;exports.formatInputValue=M;exports.formatValueForDisplay=et;exports.getNumoraPattern=re;exports.getSeparatorsFromLocale=ae;exports.handleOnChangeNumoraInput=te;exports.handleOnKeyDownNumoraInput=ee;exports.handleOnPasteNumoraInput=ne;exports.removeThousandSeparators=L;exports.resolveLocaleOptions=ie;exports.validateNumoraInputOptions=se;
1
+ "use strict";var le=Object.defineProperty;var he=(e,t,n)=>t in e?le(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var C=(e,t,n)=>he(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var L=(e=>(e.Blur="blur",e.Change="change",e))(L||{}),p=(e=>(e.None="none",e.Thousand="thousand",e.Lakh="lakh",e.Wan="wan",e.Locale="locale",e))(p||{});const G=2,B=0,Z=L.Blur,ue=",",H=p.None,y=".",k=!1,W=!1,U=!1,P=!1;function w(e){return e.replace(/[-[\]/{}()*+?.\\^$|]/g,"\\$&")}const z=new Map;function O(e,t="g"){const n=`${e}:${t}`;let r=z.get(n);return r||(r=new RegExp(e,t),z.set(n,r)),r}function de(e,t="g"){const n=w(e);return O(n,t)}const fe=/[.,]/g;function _(e){return{decimalSeparator:(e==null?void 0:e.decimalSeparator)??y,thousandSeparator:e==null?void 0:e.thousandSeparator}}function Y(e,t){const n=e.startsWith("-"),r=n?e.slice(1):e,[i="",s=""]=r.split(t);return{sign:n?"-":"",integer:i,decimal:s}}function ge(e,t){if(!e.value.includes(t))return!1;const{selectionStart:n,selectionEnd:r,value:i}=e;return!i.slice(n??0,r??0).includes(t)}function Se(e,t,n){const{key:r}=e;if(r!==","&&r!==".")return!1;if(ge(t,n))return!0;if(r!==n){const{selectionStart:i,selectionEnd:s,value:a}=t,c=i??0,l=s??c;t.value=a.slice(0,c)+n+a.slice(l);const o=c+1;return t.setSelectionRange(o,o),!0}return!1}const Ee=(e,t,n=y)=>{const{sign:r,integer:i,decimal:s}=Y(e,n);if(!s)return e;const a=s.slice(0,t);return`${r}${i}${n}${a}`},me=(e,t=y)=>{const n=e.indexOf(t);if(n===-1||n===e.length-1)return e;const r=e.slice(0,n+1),i=e.slice(n+1),a=t==="."||t===","?fe:O("[,\\."+w(t)+"]","g");return r+i.replace(a,"")},pe=(e,t=0,n=y)=>{if(t<=0)return e;const{sign:r,integer:i,decimal:s}=Y(e,n);if(s.length>=t)return e;const a=s.padEnd(t,"0");return`${r}${i}${n}${a}`},D={thousand:{size:3},lakh:{firstGroup:3,restGroup:2},wan:{size:4}},be=/^(0+)/;function Q(e,t,n=p.Thousand,r=!1,i="."){if(!e||e==="0"||e===i||e==="-"||e===`-${i}`)return e;const s=e.includes(i),a=e.startsWith("-"),c=a?e.slice(1):e,[l,o]=c.split(i);if(!l){const u=o?`${i}${o}`:c;return a?`-${u}`:u}if(r&&l.startsWith("0")&&l.length>1){const u=l.match(be);if(u){const S=u[1],E=l.slice(S.length);if(E){const m=J(E,t,n),f=S+m,g=a?"-":"";return s?o?`${g}${f}${i}${o}`:`${g}${f}${i}`:`${g}${f}`}}}const h=J(l,t,n),d=a?"-":"";return s?o?`${d}${h}${i}${o}`:`${d}${h}${i}`:`${d}${h}`}function J(e,t,n){if(e==="0"||e==="")return e;switch(n){case p.None:return e;case p.Thousand:return X(e,t,D.thousand.size);case p.Lakh:return Le(e,t);case p.Wan:return X(e,t,D.wan.size);default:return e}}function Le(e,t){if(e.length<=D.lakh.firstGroup)return e;const n=[],r=e.length-D.lakh.firstGroup;n.unshift(e.slice(r));for(let i=r;i>0;i-=D.lakh.restGroup)n.unshift(e.slice(Math.max(0,i-D.lakh.restGroup),i));return n.join(t)}function X(e,t,n){const r=[];for(let i=e.length;i>0;i-=n)r.unshift(e.slice(Math.max(0,i-n),i));return r.join(t)}function Ne(e,t,n){return(t==null?void 0:t.formatOn)===L.Change&&t.thousandSeparator?Q(e,t.thousandSeparator,t.ThousandStyle??p.None,t.enableLeadingZeros,(n==null?void 0:n.decimalSeparator)??y):e}function $(e,t,n){let r=0;for(let i=0;i<t&&i<e.length;i++)e[i]!==n&&r++;return r}function ve(e,t,n){if(t===0)return 0;let r=0;for(let i=0;i<e.length;i++)if(e[i]!==n){if(r===t-1)return i+1;r++}return e.length}function T(e,t,n){if(t===0)return 0;let r=0;for(let i=0;i<e.length;i++)if(e[i]!==n){if(r++,r===t)return i+1;if(r>t)return i}return e.length}function V(e,t,n){return t<0||t>=e.length?!1:e[t]===n}const $e=/\d/;function De(e,t={}){const{thousandSeparator:n,decimalSeparator:r=".",prefix:i="",suffix:s=""}=t,a=new Array(e.length+1).fill(!0);if(i&&a.fill(!1,0,i.length),s){const c=e.length-s.length;a.fill(!1,c+1,e.length+1)}for(let c=0;c<e.length;c++){const l=e[c];(n&&l===n||l===r)&&(a[c]=!1,c+1<e.length&&!$e.test(e[c+1])&&(a[c+1]=!1))}return a.some(c=>c)||a.fill(!0),a}function x(e,t,n,r){const i=e.length;if(t=Math.max(0,Math.min(t,i)),r==="left"){for(;t>=0&&!n[t];)t--;t===-1&&(t=n.indexOf(!0))}else if(r==="right"){for(;t<=i&&!n[t];)t++;t>i&&(t=n.lastIndexOf(!0))}else if(!n[t]){let s=t;for(;s<=i&&!n[s];)s++;let a=t;for(;a>=0&&!n[a];)a--;s<=i&&a>=0?t=t-a<s-t?a:s:s<=i?t=s:a>=0&&(t=a)}return(t===-1||t>i)&&(t=i),t}const j=/(\d+\.?\d*)\s*[kmbt]$/i,ye=(e,t)=>e===t;function Ce(e,t,n,r,i,s,a=".",c={}){if(n<0)return 0;if(n>e.length||e===""||t===""||j.test(e)&&!j.test(t)&&t.length>e.length&&n>=e.length-1)return t.length;const l=t.length<e.length,o=V(e,n,r),h=e.indexOf(a),d=t.indexOf(a);if(c.isCharacterEquivalent&&e!==t){const f={thousandSeparator:r||void 0,...c},g=we(e,t,n,c.isCharacterEquivalent||ye,s,f);if(g!==void 0)return g}const S=new Map,E=(f,g,N)=>{const b=`${f===e?"o":"n"}:${g}`;return S.has(b)||S.set(b,$(f,g,r)),S.get(b)};if(l)return Ie(e,t,n,r,o,h,d,s,c,E);const m=Te(e,t,n,r,o,E);return c.boundary?x(t,m,c.boundary):m}function we(e,t,n,r,i,s){const a=e.length,c=t.length;let l=0,o=0,h=c;for(let g=0;g<a;g++){let N=-1;for(let b=l;b<c;b++)if(r(e[g],t[b],{oldValue:e,newValue:t,typedRange:i,oldIndex:g,newIndex:b})){N=b;break}N!==-1&&(l=N+1,g<n?o=N+1:h===c&&/\d/.test(e[g])&&(h=N))}if(o>h)return h;const d=t.length<e.length||i!==void 0&&i.isDelete===!1;let u,S=!1,E=!1;if(d){u=o;const g=s.thousandSeparator,N=s.decimalSeparator??".",b=u<t.length?t[u]:"";g&&b===g?(n>0?e[n-1]:"")===g?(u=h,S=!0):E=!0:b===N&&(E=!0)}else u=n-o<h-n?o:h;const m=d&&!S?"left":"right";if(s.boundary)return E?u:x(t,u,s.boundary,m);const f=s.thousandSeparator;if(!E&&f&&u>=0&&u<t.length&&t[u]===f)if(d&&!S)for(;u>0&&t[u]===f;)u--;else for(;u<t.length&&t[u]===f;)u++;return u}function Ie(e,t,n,r,i,s,a,c,l={},o=$){if(i)return Me(e,t,n,r,a,o);const h=o(e,n,r),d=o(e,e.length,r),u=o(t,t.length,r),S=d-u,E=Ae(e,n,r,h,S,s,c,o),m=s===-1||n<=s,f=Re(t,E,r,S,c,m,a,o);return l.boundary?x(t,f,l.boundary):f}function Me(e,t,n,r,i,s=$){const a=n+1;if(a<e.length){const c=s(e,a,r),l=ve(t,c,r);return l<t.length&&t[l]!==r?l+1:l}return n}function Ae(e,t,n,r,i,s,a,c=$){if(a){const{start:o,isDelete:h}=a;return h?c(e,o,n):Math.max(0,c(e,o,n))}return t>0&&e[t-1]===n&&i>0?r+1:r}function K(e,t,n,r,i,s,a=$){if(t>0&&t<e.length&&a(e,t,r)===n){if(e[t]===r&&s&&i>0&&t<e.length-1)return t+1;if(!s&&i>0&&t<e.length-1)return Math.min(t+1,e.length)}return t}function Re(e,t,n,r,i,s,a,c=$){if(s&&a!==-1){const o=e.substring(0,a),h=c(o,o.length,n);if(t<=h){const d=T(o,t,n);return K(o,d,t,n,r,i,c)}}const l=T(e,t,n);return K(e,l,t,n,r,i,c)}function Te(e,t,n,r,i,s=$){const a=n>=e.length,c=s(e,n,r),l=s(e,e.length,r),o=s(t,t.length,r);if(a||c===l)return t.length;const h=o-l;let d=c;h>0&&!a&&c<l&&(d=c+1);const u=T(t,d,r);return i&&!V(t,u,r)?Math.max(0,u-1):u}function Oe(e,t,n){const{selectionStart:r,selectionEnd:i,endOffset:s=0}=e;if(r!==i){const h=i-r;return{start:r,end:i,deletedLength:h,isDelete:!1}}if(s>0){const h=s;return{start:r,end:r+h,deletedLength:h,isDelete:!0}}const c=t.length,l=n.length,o=c-l;if(!(o<=0))return{start:r,end:r+o,deletedLength:o,isDelete:!1}}function _e(e,t){if(e===t)return;let n=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;let r=e.length-1,i=t.length-1;for(;r>=n&&i>=n&&e[r]===t[i];)r--,i--;const s=r-n+1,a=i-n+1;if(!(s===0&&a===0))return{start:n,end:r+1,deletedLength:s,isDelete:s>a}}function q(e,t){if(e.value=e.value,e===null)return!1;if(e.createTextRange){const n=e.createTextRange();return n.move("character",t),n.select(),!0}return e.selectionStart!==null||e.selectionStart===0?(e.focus(),e.setSelectionRange(t,t),!0):(e.focus(),!1)}function xe(e,t,n){return e.selectionStart===0&&e.selectionEnd===e.value.length?null:(q(e,t),setTimeout(()=>{e.value===n&&e.selectionStart!==t&&q(e,t)},0))}function Ge(e){return Math.max(e.selectionStart,e.selectionEnd)}function Be(e,t,n){if((n==null?void 0:n.formatOn)!==L.Change||!n.thousandSeparator)return;const{selectionStart:r,selectionEnd:i,value:s}=t;if(r===null||i===null||r!==i)return;const{key:a}=e,c=n.thousandSeparator;a==="Backspace"&&r>0&&s[r-1]===c&&t.setSelectionRange(r-1,r-1),a==="Delete"&&s[r]===c&&t.setSelectionRange(r+1,r+1)}function Ze(e,t,n,r,i,s,a){if(!i)return;const{selectionStart:c=0,selectionEnd:l=0,endOffset:o=0}=i;let h=Oe({selectionStart:c,selectionEnd:l,endOffset:o},t,n);if(h||(h=_e(t,n)),!h)return;const d=De(n,{thousandSeparator:(a==null?void 0:a.thousandSeparator)??s.thousandSeparator,decimalSeparator:s.decimalSeparator}),u={thousandSeparator:(a==null?void 0:a.thousandSeparator)??s.thousandSeparator,decimalSeparator:s.decimalSeparator,isCharacterEquivalent:(f,g)=>{const N=(a==null?void 0:a.thousandSeparator)??s.thousandSeparator;return N&&f===N?!1:f===g},boundary:d},S=(a==null?void 0:a.thousandSeparator)??s.thousandSeparator??",",E=(a==null?void 0:a.ThousandStyle)??p.None,m=Ce(t,n,r,S,E,h,s.decimalSeparator,u);xe(e,m,n)}const ke=(e,t=!1,n=".")=>{const r=w(n),i=O(`[^0-9${r}]`,"g");if(!t)return e.replace(i,"");const s=e.startsWith("-"),a=e.replace(i,"");return s&&(a.length>0||e==="-")?"-"+a:a},We=/([+-]?\d+\.?\d*)[eE]([+-]?\d+)/g,F=/^0+$/,A=/\.?0+$/;function Ue(e){return!e.includes("e")&&!e.includes("E")?e:e.replace(We,(t,n,r)=>{const i=parseInt(r,10);if(i===0)return n;const s=n.startsWith("-"),a=s?n.slice(1):n,[c,l=""]=a.split("."),o=i>0?Pe(c,l,i):ze(c,l,Math.abs(i));return s?"-"+o:o})}function Pe(e,t,n){const r=e+t;if(r==="0"||F.test(r))return"0";const i=t.length;if(n<=i){const a=r.slice(0,e.length+n),c=r.slice(e.length+n);return c?`${a}.${c}`:a}const s=n-i;return r+"0".repeat(s)}function ze(e,t,n){const r=e+t;if(r==="0"||F.test(r))return"0";const s=e.length-n;if(s<=0){const a=Math.abs(s),c=`0.${"0".repeat(a)}${r}`;return R(c)}if(s<e.length){const a=r.slice(0,s),c=r.slice(s),l=`${a}.${c}`;return R(l)}return R(r)}function R(e){if(!e.includes("."))return e;if(e==="0.")return"0";if(e.startsWith("0.")){const t=e.replace(A,"");return t==="0"?"0":t||"0"}if(e.startsWith("-0.")){const t=e.replace(A,"");return t==="-0"||t==="0"?"0":t||"0"}return e.replace(A,"")||e}const Je=/(\d+\.?\d*)\s*([kmbt])/gi,Xe=/^0+/,je=/^(-?)0+([1-9])/,Ke=/^-?0+$/,qe=/\.?0+$/,He={k:3,m:6,b:9,t:12};function Ye(e){return e.replace(Je,(t,n,r)=>{const i=r.toLowerCase(),s=He[i];if(!s)return t;const[a,c=""]=n.split("."),l=a.replace(Xe,"")||"0";let o;if(c.length===0)o=l+"0".repeat(s);else if(c.length<=s){const h=s-c.length;o=l+c+"0".repeat(h)}else{const h=c.slice(0,s),d=c.slice(s);o=l+h+"."+d}return o=o.replace(je,"$1$2"),Ke.test(o)&&(o="0"),o.includes(".")&&(o=o.replace(qe,"")),o})}function Qe(e){if(!e||e==="0"||e==="-0"||e==="-"||e===".")return e;const t=e.startsWith("-"),n=t?e.slice(1):e;if(n===".")return e;if(n.includes(".")){const[i,s]=n.split(".");if(i){const c=(i.replace(/^0+/,"")||"0")+"."+s;return t?"-"+c:c}return e}if(n.startsWith("0")){const i=n.replace(/^0+/,"")||"0";return t?"-"+i:i}return e}function Ve(e){return e.replace(/[\s\u200B]/g,"")}function v(e,t){const n=de(t);return e.replace(n,"")}const Fe=(e,t)=>{let n=Ve(e);return t!=null&&t.thousandSeparator&&(n=v(n,t.thousandSeparator)),t!=null&&t.enableCompactNotation&&(n=Ye(n)),n=Ue(n),n=ke(n,t==null?void 0:t.enableNegative,t==null?void 0:t.decimalSeparator),n=me(n,t==null?void 0:t.decimalSeparator),t!=null&&t.enableLeadingZeros||(n=Qe(n)),n};function et(e,t,n){return{enableCompactNotation:e==null?void 0:e.enableCompactNotation,enableNegative:e==null?void 0:e.enableNegative,enableLeadingZeros:e==null?void 0:e.enableLeadingZeros,decimalSeparator:t.decimalSeparator,thousandSeparator:n?t.thousandSeparator:void 0}}function M(e,t,n,r){const i=_(n),s=r??(n==null?void 0:n.formatOn)===L.Change,a=Fe(e,et(n,i,s)),c=Ee(a,t,i.decimalSeparator),l=(n==null?void 0:n.decimalMinLength)??0,o=pe(c,l,i.decimalSeparator);return{formatted:Ne(o,n,i),raw:o}}function tt(e,t,n){const r=!!(n!=null&&n.thousandSeparator);return M(e,t,n,r)}function nt(e,t,n){if(e==="Backspace"||e==="Delete")return e==="Delete"&&t===n?{endOffset:1}:{endOffset:0}}function ee(e,t){const{decimalSeparator:n}=_(t),r=e.target;if(Se(e,r,n)){e.preventDefault();return}return Be(e,r,t),nt(e.key,r.selectionStart,r.selectionEnd)}function te(e,t,n,r){const i=e.target,s=i.value,a=Ge(i),c=_(r),l=(r==null?void 0:r.formatOn)===L.Change,{formatted:o,raw:h}=M(s,t,r,l);return i.value=o,s!==o&&Ze(i,s,o,a,n,c,r),{formatted:o,raw:h}}function rt(e,t,n,r){const i=r-n;return e+t+i}function ne(e,t,n){var u;e.preventDefault();const r=e.target,{value:i,selectionStart:s,selectionEnd:a}=r,c=((u=e.clipboardData)==null?void 0:u.getData("text/plain"))||"",l=i.slice(0,s||0)+c+i.slice(a||0),{formatted:o,raw:h}=M(l,t,n,!0);r.value=o;const d=rt(s||0,c.length,l.length,o.length);return r.setSelectionRange(d,d),{formatted:o,raw:h}}function re(e,t){const n=w(e);return t?`^-?[0-9]*[${n}]?[0-9]*$`:`^[0-9]*[${n}]?[0-9]*$`}function ie(e){var t,n;try{const i=new Intl.NumberFormat(e).formatToParts(123456789e-2);return{decimalSeparator:((t=i.find(s=>s.type==="decimal"))==null?void 0:t.value)??".",thousandSeparator:((n=i.find(s=>s.type==="group"))==null?void 0:n.value)??","}}catch{return{thousandSeparator:",",decimalSeparator:"."}}}function se(e){let t=e.thousandSeparator??ue,n=e.decimalSeparator??y,r=e.thousandStyle??H;if(e.thousandStyle===p.Locale||e.decimalSeparator==="auto"){const s=ie();e.thousandStyle===p.Locale&&(t=e.thousandSeparator??s.thousandSeparator,n=e.decimalSeparator==="auto"||e.decimalSeparator===void 0?s.decimalSeparator:e.decimalSeparator,r=p.Thousand),e.decimalSeparator==="auto"&&(n=s.decimalSeparator)}return{thousandSeparator:t,thousandStyle:r,decimalSeparator:n}}function ae(e){it(e.decimalMaxLength),st(e.decimalMinLength),at(e.decimalMinLength,e.decimalMaxLength),ct(e.formatOn),ot(e.thousandSeparator),lt(e.thousandStyle),ht(e.decimalSeparator),ut(e.thousandSeparator,e.decimalSeparator),I("enableCompactNotation",e.enableCompactNotation),I("enableNegative",e.enableNegative),I("enableLeadingZeros",e.enableLeadingZeros),I("rawValueMode",e.rawValueMode),dt(e.onChange)}function it(e){if(e!==void 0){if(typeof e!="number")throw new Error(`decimalMaxLength must be a number. Received: ${typeof e} (${JSON.stringify(e)})`);if(!Number.isInteger(e))throw new Error(`decimalMaxLength must be an integer. Received: ${e}`);if(e<0)throw new Error(`decimalMaxLength must be non-negative. Received: ${e}`)}}function st(e){if(e!==void 0){if(typeof e!="number")throw new Error(`decimalMinLength must be a number. Received: ${typeof e} (${JSON.stringify(e)})`);if(!Number.isInteger(e))throw new Error(`decimalMinLength must be an integer. Received: ${e}`);if(e<0)throw new Error(`decimalMinLength must be non-negative. Received: ${e}`)}}function at(e,t){if(!(e===void 0||t===void 0)&&e>t)throw new Error(`decimalMinLength (${e}) cannot be greater than decimalMaxLength (${t}).`)}function ct(e){if(e!==void 0&&e!==L.Blur&&e!==L.Change)throw new Error(`formatOn must be either ${L.Blur} or ${L.Change}. Received: ${JSON.stringify(e)}`)}function ot(e){if(e!==void 0){if(typeof e!="string")throw new Error(`thousandSeparator must be a string. Received: ${typeof e} (${JSON.stringify(e)})`);if(e.length===0)throw new Error(`thousandSeparator cannot be empty. Received: ${JSON.stringify(e)}`);if(e.length>1)throw new Error(`thousandSeparator must be a single character. Received: "${e}" (length: ${e.length})`)}}function lt(e){if(e!==void 0&&!Object.values(p).includes(e))throw new Error(`ThousandStyle must be one of: ${Object.values(p).map(t=>`'${t}'`).join(", ")}. Received: ${JSON.stringify(e)}`)}function ht(e){if(!(e===void 0||e==="auto")){if(typeof e!="string")throw new Error(`decimalSeparator must be a string. Received: ${typeof e} (${JSON.stringify(e)})`);if(e.length===0)throw new Error(`decimalSeparator cannot be empty. Received: ${JSON.stringify(e)}`);if(e.length>1)throw new Error(`decimalSeparator must be a single character. Received: "${e}" (length: ${e.length})`)}}function ut(e,t){if(!(e===void 0||t===void 0)&&t!=="auto"&&e===t)throw new Error(`Decimal separator can't be same as thousand separator. thousandSeparator: ${e}, decimalSeparator: ${t}`)}function I(e,t){if(t!==void 0&&typeof t!="boolean")throw new Error(`${e} must be a boolean. Received: ${typeof t} (${JSON.stringify(t)})`)}function dt(e){if(e!==void 0&&typeof e!="function")throw new Error(`onChange must be a function or undefined. Received: ${typeof e} (${JSON.stringify(e)})`)}class ft{constructor(t,{decimalMaxLength:n=G,decimalMinLength:r=B,formatOn:i=Z,thousandSeparator:s,thousandStyle:a=H,decimalSeparator:c,enableCompactNotation:l=k,enableNegative:o=W,enableLeadingZeros:h=U,rawValueMode:d=P,onChange:u,...S}){C(this,"element");C(this,"resolvedOptions");C(this,"rawValue","");C(this,"caretPositionBeforeChange");ae({decimalMaxLength:n,decimalMinLength:r,formatOn:i,thousandSeparator:s,thousandStyle:a,decimalSeparator:c,enableCompactNotation:l,enableNegative:o,enableLeadingZeros:h,rawValueMode:d,onChange:u});const E={decimalMaxLength:n,decimalMinLength:r,onChange:u,formatOn:i,thousandSeparator:s,thousandStyle:a,decimalSeparator:c,enableCompactNotation:l,enableNegative:o,enableLeadingZeros:h,rawValueMode:d,...S};if(this.resolvedOptions=this.getResolvedOptions(E),this.createInputElement(t,E),this.setupEventListeners(),this.resolvedOptions.rawValueMode&&this.element.value){const m=this.element.value,f=this.resolvedOptions.thousandSeparator?v(m,this.resolvedOptions.thousandSeparator):m;this.rawValue=f,this.element.value=this.formatValueForDisplay(f)}else if(this.element.value){const m=this.element.value;this.element.value=this.formatValueForDisplay(m)}}createInputElement(t,n){this.element=document.createElement("input"),this.element.setAttribute("type","text"),this.element.setAttribute("inputmode","decimal"),this.element.setAttribute("spellcheck","false"),this.element.setAttribute("autocomplete","off");const r=re(this.resolvedOptions.decimalSeparator,this.resolvedOptions.enableNegative);this.element.setAttribute("pattern",r);const{decimalMaxLength:i,decimalMinLength:s,formatOn:a,thousandSeparator:c,thousandStyle:l,decimalSeparator:o,enableCompactNotation:h,enableNegative:d,enableLeadingZeros:u,rawValueMode:S,onChange:E,value:m,defaultValue:f,type:g,inputMode:N,spellcheck:b,autocomplete:ce,...oe}=n;Object.assign(this.element,oe),m!==void 0?this.element.value=m:f!==void 0&&(this.element.defaultValue=f,this.element.value=f),t.appendChild(this.element)}setupEventListeners(){this.element.addEventListener("input",this.handleChange.bind(this)),this.element.addEventListener("keydown",this.handleKeyDown.bind(this)),this.element.addEventListener("paste",this.handlePaste.bind(this)),this.resolvedOptions.formatOn===L.Blur&&this.resolvedOptions.thousandSeparator&&(this.element.addEventListener("focus",this.handleFocus.bind(this)),this.element.addEventListener("blur",this.handleBlur.bind(this)))}getResolvedOptions(t){const n=se({thousandSeparator:t.thousandSeparator,thousandStyle:t.thousandStyle,decimalSeparator:t.decimalSeparator});return{decimalMaxLength:t.decimalMaxLength??G,decimalMinLength:t.decimalMinLength??B,formatOn:t.formatOn??Z,thousandSeparator:n.thousandSeparator,thousandStyle:n.thousandStyle,decimalSeparator:n.decimalSeparator,enableCompactNotation:t.enableCompactNotation??k,enableNegative:t.enableNegative??W,enableLeadingZeros:t.enableLeadingZeros??U,rawValueMode:t.rawValueMode??P,onChange:t.onChange}}buildFormattingOptions(){return{formatOn:this.resolvedOptions.formatOn,thousandSeparator:this.resolvedOptions.thousandSeparator,ThousandStyle:this.resolvedOptions.thousandStyle,enableCompactNotation:this.resolvedOptions.enableCompactNotation,enableNegative:this.resolvedOptions.enableNegative,enableLeadingZeros:this.resolvedOptions.enableLeadingZeros,decimalSeparator:this.resolvedOptions.decimalSeparator,decimalMinLength:this.resolvedOptions.decimalMinLength,rawValueMode:this.resolvedOptions.rawValueMode}}handleValueChange(t,n){if(this.resolvedOptions.rawValueMode&&n!==void 0&&(this.rawValue=n),this.resolvedOptions.onChange){const r=this.resolvedOptions.rawValueMode?this.rawValue:t;this.resolvedOptions.onChange(r)}}formatValueForDisplay(t){if(!t)return t;const{thousandSeparator:n,thousandStyle:r,enableLeadingZeros:i,decimalSeparator:s}=this.resolvedOptions;return n&&r!==p.None?Q(t,n,r,i,s):t}handleChange(t){const{formatted:n,raw:r}=te(t,this.resolvedOptions.decimalMaxLength,this.caretPositionBeforeChange,this.buildFormattingOptions());this.caretPositionBeforeChange=void 0,this.handleValueChange(n,r)}handleKeyDown(t){const n=t.target,{selectionStart:r,selectionEnd:i}=n,s=this.buildFormattingOptions(),a=ee(t,{formatOn:s.formatOn,thousandSeparator:s.thousandSeparator,ThousandStyle:s.ThousandStyle,decimalSeparator:s.decimalSeparator});a?this.caretPositionBeforeChange={selectionStart:r??0,selectionEnd:i??0,endOffset:a.endOffset}:this.caretPositionBeforeChange={selectionStart:r??0,selectionEnd:i??0}}handlePaste(t){const{formatted:n,raw:r}=ne(t,this.resolvedOptions.decimalMaxLength,this.buildFormattingOptions());this.handleValueChange(n,r);const i=new Event("input",{bubbles:!0,cancelable:!0});this.element.dispatchEvent(i)}handleFocus(t){if(this.resolvedOptions.formatOn===L.Blur&&this.resolvedOptions.thousandSeparator){const n=t.target;n.value=v(n.value,this.resolvedOptions.thousandSeparator)}}handleBlur(t){const n=t.target,{thousandSeparator:r,thousandStyle:i}=this.resolvedOptions;if(r&&i!==p.None&&n.value){const s=this.formatValueForDisplay(n.value);n.value=s;const a=this.resolvedOptions.rawValueMode?v(s,r):void 0;this.handleValueChange(s,a)}}getValue(){return this.resolvedOptions.rawValueMode?this.rawValue:this.element.value}setValue(t){if(this.resolvedOptions.rawValueMode){const n=this.resolvedOptions.thousandSeparator?v(t,this.resolvedOptions.thousandSeparator):t;this.rawValue=n,this.element.value=this.formatValueForDisplay(n)}else this.element.value=t}disable(){this.element.disabled=!0}enable(){this.element.disabled=!1}addEventListener(t,n){this.element.addEventListener(t,n)}removeEventListener(t,n){this.element.removeEventListener(t,n)}getElement(){return this.element}get value(){return this.getValue()}set value(t){this.setValue(t)}get valueAsNumber(){const t=this.getValue();if(!t)return NaN;const n=this.resolvedOptions.thousandSeparator?v(t,this.resolvedOptions.thousandSeparator):t,r=this.resolvedOptions.decimalSeparator&&this.resolvedOptions.decimalSeparator!=="."?n.replace(new RegExp(w(this.resolvedOptions.decimalSeparator),"g"),"."):n;return parseFloat(r)}set valueAsNumber(t){if(isNaN(t)){this.setValue("");return}const n=t.toString();this.setValue(n)}}exports.FormatOn=L;exports.NumoraInput=ft;exports.ThousandStyle=p;exports.formatInputValue=M;exports.formatValueForDisplay=tt;exports.getNumoraPattern=re;exports.getSeparatorsFromLocale=ie;exports.handleOnChangeNumoraInput=te;exports.handleOnKeyDownNumoraInput=ee;exports.handleOnPasteNumoraInput=ne;exports.removeThousandSeparators=v;exports.resolveLocaleOptions=se;exports.validateNumoraInputOptions=ae;
package/dist/index.mjs CHANGED
@@ -1,25 +1,25 @@
1
- var te = Object.defineProperty;
2
- var ne = (e, t, n) => t in e ? te(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var D = (e, t, n) => ne(e, typeof t != "symbol" ? t + "" : t, n);
4
- var b = /* @__PURE__ */ ((e) => (e.Blur = "blur", e.Change = "change", e))(b || {}), m = /* @__PURE__ */ ((e) => (e.None = "none", e.Thousand = "thousand", e.Lakh = "lakh", e.Wan = "wan", e.Locale = "locale", e))(m || {});
5
- const G = 2, Z = 0, k = b.Blur, re = ",", H = m.None, v = ".", B = !1, P = !1, W = !1, U = !1;
6
- function w(e) {
1
+ var ne = Object.defineProperty;
2
+ var re = (e, t, n) => t in e ? ne(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var w = (e, t, n) => re(e, typeof t != "symbol" ? t + "" : t, n);
4
+ var N = /* @__PURE__ */ ((e) => (e.Blur = "blur", e.Change = "change", e))(N || {}), p = /* @__PURE__ */ ((e) => (e.None = "none", e.Thousand = "thousand", e.Lakh = "lakh", e.Wan = "wan", e.Locale = "locale", e))(p || {});
5
+ const G = 2, B = 0, Z = N.Blur, ie = ",", H = p.None, C = ".", k = !1, W = !1, U = !1, z = !1;
6
+ function y(e) {
7
7
  return e.replace(/[-[\]/{}()*+?.\\^$|]/g, "\\$&");
8
8
  }
9
- const z = /* @__PURE__ */ new Map();
9
+ const J = /* @__PURE__ */ new Map();
10
10
  function T(e, t = "g") {
11
11
  const n = `${e}:${t}`;
12
- let r = z.get(n);
13
- return r || (r = new RegExp(e, t), z.set(n, r)), r;
12
+ let r = J.get(n);
13
+ return r || (r = new RegExp(e, t), J.set(n, r)), r;
14
14
  }
15
- function ie(e, t = "g") {
16
- const n = w(e);
15
+ function se(e, t = "g") {
16
+ const n = y(e);
17
17
  return T(n, t);
18
18
  }
19
- const se = /[.,]/g;
19
+ const ae = /[.,]/g;
20
20
  function _(e) {
21
21
  return {
22
- decimalSeparator: (e == null ? void 0 : e.decimalSeparator) ?? v,
22
+ decimalSeparator: (e == null ? void 0 : e.decimalSeparator) ?? C,
23
23
  thousandSeparator: e == null ? void 0 : e.thousandSeparator
24
24
  };
25
25
  }
@@ -31,90 +31,90 @@ function Y(e, t) {
31
31
  decimal: s
32
32
  };
33
33
  }
34
- function ae(e, t) {
34
+ function ce(e, t) {
35
35
  if (!e.value.includes(t)) return !1;
36
36
  const { selectionStart: n, selectionEnd: r, value: i } = e;
37
37
  return !i.slice(n ?? 0, r ?? 0).includes(t);
38
38
  }
39
- function ce(e, t, n) {
39
+ function le(e, t, n) {
40
40
  const { key: r } = e;
41
41
  if (r !== "," && r !== ".") return !1;
42
- if (ae(t, n))
42
+ if (ce(t, n))
43
43
  return !0;
44
44
  if (r !== n) {
45
- const { selectionStart: i, selectionEnd: s, value: a } = t, c = i ?? 0, l = s ?? c;
46
- t.value = a.slice(0, c) + n + a.slice(l);
47
- const o = c + 1;
48
- return t.setSelectionRange(o, o), !0;
45
+ const { selectionStart: i, selectionEnd: s, value: a } = t, c = i ?? 0, o = s ?? c;
46
+ t.value = a.slice(0, c) + n + a.slice(o);
47
+ const l = c + 1;
48
+ return t.setSelectionRange(l, l), !0;
49
49
  }
50
50
  return !1;
51
51
  }
52
- const oe = (e, t, n = v) => {
52
+ const oe = (e, t, n = C) => {
53
53
  const { sign: r, integer: i, decimal: s } = Y(e, n);
54
54
  if (!s) return e;
55
55
  const a = s.slice(0, t);
56
56
  return `${r}${i}${n}${a}`;
57
- }, le = (e, t = v) => {
57
+ }, he = (e, t = C) => {
58
58
  const n = e.indexOf(t);
59
59
  if (n === -1 || n === e.length - 1) return e;
60
- const r = e.slice(0, n + 1), i = e.slice(n + 1), a = t === "." || t === "," ? se : T("[,\\." + w(t) + "]", "g");
60
+ const r = e.slice(0, n + 1), i = e.slice(n + 1), a = t === "." || t === "," ? ae : T("[,\\." + y(t) + "]", "g");
61
61
  return r + i.replace(a, "");
62
- }, he = (e, t = 0, n = v) => {
62
+ }, ue = (e, t = 0, n = C) => {
63
63
  if (t <= 0) return e;
64
64
  const { sign: r, integer: i, decimal: s } = Y(e, n);
65
65
  if (s.length >= t)
66
66
  return e;
67
67
  const a = s.padEnd(t, "0");
68
68
  return `${r}${i}${n}${a}`;
69
- }, $ = {
69
+ }, D = {
70
70
  thousand: { size: 3 },
71
71
  lakh: { firstGroup: 3, restGroup: 2 },
72
72
  wan: { size: 4 }
73
- }, ue = /^(0+)/;
74
- function Q(e, t, n = m.Thousand, r = !1, i = ".") {
73
+ }, de = /^(0+)/;
74
+ function Q(e, t, n = p.Thousand, r = !1, i = ".") {
75
75
  if (!e || e === "0" || e === i || e === "-" || e === `-${i}`)
76
76
  return e;
77
- const s = e.includes(i), a = e.startsWith("-"), c = a ? e.slice(1) : e, [l, o] = c.split(i);
78
- if (!l) {
79
- const u = o ? `${i}${o}` : c;
77
+ const s = e.includes(i), a = e.startsWith("-"), c = a ? e.slice(1) : e, [o, l] = c.split(i);
78
+ if (!o) {
79
+ const u = l ? `${i}${l}` : c;
80
80
  return a ? `-${u}` : u;
81
81
  }
82
- if (r && l.startsWith("0") && l.length > 1) {
83
- const u = l.match(ue);
82
+ if (r && o.startsWith("0") && o.length > 1) {
83
+ const u = o.match(de);
84
84
  if (u) {
85
- const g = u[1], S = l.slice(g.length);
86
- if (S) {
87
- const E = J(S, t, n), f = g + E, p = a ? "-" : "";
88
- return s ? o ? `${p}${f}${i}${o}` : `${p}${f}${i}` : `${p}${f}`;
85
+ const S = u[1], E = o.slice(S.length);
86
+ if (E) {
87
+ const m = P(E, t, n), f = S + m, g = a ? "-" : "";
88
+ return s ? l ? `${g}${f}${i}${l}` : `${g}${f}${i}` : `${g}${f}`;
89
89
  }
90
90
  }
91
91
  }
92
- const h = J(l, t, n), d = a ? "-" : "";
93
- return s ? o ? `${d}${h}${i}${o}` : `${d}${h}${i}` : `${d}${h}`;
92
+ const h = P(o, t, n), d = a ? "-" : "";
93
+ return s ? l ? `${d}${h}${i}${l}` : `${d}${h}${i}` : `${d}${h}`;
94
94
  }
95
- function J(e, t, n) {
95
+ function P(e, t, n) {
96
96
  if (e === "0" || e === "")
97
97
  return e;
98
98
  switch (n) {
99
- case m.None:
99
+ case p.None:
100
100
  return e;
101
- case m.Thousand:
102
- return X(e, t, $.thousand.size);
103
- case m.Lakh:
104
- return de(e, t);
105
- case m.Wan:
106
- return X(e, t, $.wan.size);
101
+ case p.Thousand:
102
+ return X(e, t, D.thousand.size);
103
+ case p.Lakh:
104
+ return fe(e, t);
105
+ case p.Wan:
106
+ return X(e, t, D.wan.size);
107
107
  default:
108
108
  return e;
109
109
  }
110
110
  }
111
- function de(e, t) {
112
- if (e.length <= $.lakh.firstGroup)
111
+ function fe(e, t) {
112
+ if (e.length <= D.lakh.firstGroup)
113
113
  return e;
114
- const n = [], r = e.length - $.lakh.firstGroup;
114
+ const n = [], r = e.length - D.lakh.firstGroup;
115
115
  n.unshift(e.slice(r));
116
- for (let i = r; i > 0; i -= $.lakh.restGroup)
117
- n.unshift(e.slice(Math.max(0, i - $.lakh.restGroup), i));
116
+ for (let i = r; i > 0; i -= D.lakh.restGroup)
117
+ n.unshift(e.slice(Math.max(0, i - D.lakh.restGroup), i));
118
118
  return n.join(t);
119
119
  }
120
120
  function X(e, t, n) {
@@ -123,22 +123,22 @@ function X(e, t, n) {
123
123
  r.unshift(e.slice(Math.max(0, i - n), i));
124
124
  return r.join(t);
125
125
  }
126
- function fe(e, t, n) {
127
- return (t == null ? void 0 : t.formatOn) === b.Change && t.thousandSeparator ? Q(
126
+ function ge(e, t, n) {
127
+ return (t == null ? void 0 : t.formatOn) === N.Change && t.thousandSeparator ? Q(
128
128
  e,
129
129
  t.thousandSeparator,
130
- t.ThousandStyle ?? m.None,
130
+ t.ThousandStyle ?? p.None,
131
131
  t.enableLeadingZeros,
132
- (n == null ? void 0 : n.decimalSeparator) ?? v
132
+ (n == null ? void 0 : n.decimalSeparator) ?? C
133
133
  ) : e;
134
134
  }
135
- function L(e, t, n) {
135
+ function $(e, t, n) {
136
136
  let r = 0;
137
137
  for (let i = 0; i < t && i < e.length; i++)
138
138
  e[i] !== n && r++;
139
139
  return r;
140
140
  }
141
- function ge(e, t, n) {
141
+ function Se(e, t, n) {
142
142
  if (t === 0)
143
143
  return 0;
144
144
  let r = 0;
@@ -150,7 +150,7 @@ function ge(e, t, n) {
150
150
  }
151
151
  return e.length;
152
152
  }
153
- function I(e, t, n) {
153
+ function R(e, t, n) {
154
154
  if (t === 0)
155
155
  return 0;
156
156
  let r = 0;
@@ -166,8 +166,8 @@ function I(e, t, n) {
166
166
  function V(e, t, n) {
167
167
  return t < 0 || t >= e.length ? !1 : e[t] === n;
168
168
  }
169
- const Se = /\d/;
170
- function Ee(e, t = {}) {
169
+ const Ee = /\d/;
170
+ function me(e, t = {}) {
171
171
  const {
172
172
  thousandSeparator: n,
173
173
  decimalSeparator: r = ".",
@@ -179,14 +179,22 @@ function Ee(e, t = {}) {
179
179
  a.fill(!1, c + 1, e.length + 1);
180
180
  }
181
181
  for (let c = 0; c < e.length; c++) {
182
- const l = e[c];
183
- (n && l === n || l === r) && (a[c] = !1, c + 1 < e.length && !Se.test(e[c + 1]) && (a[c + 1] = !1));
182
+ const o = e[c];
183
+ (n && o === n || o === r) && (a[c] = !1, c + 1 < e.length && !Ee.test(e[c + 1]) && (a[c + 1] = !1));
184
184
  }
185
185
  return a.some((c) => c) || a.fill(!0), a;
186
186
  }
187
187
  function x(e, t, n, r) {
188
188
  const i = e.length;
189
- if (t = Math.max(0, Math.min(t, i)), !n[t]) {
189
+ if (t = Math.max(0, Math.min(t, i)), r === "left") {
190
+ for (; t >= 0 && !n[t]; )
191
+ t--;
192
+ t === -1 && (t = n.indexOf(!0));
193
+ } else if (r === "right") {
194
+ for (; t <= i && !n[t]; )
195
+ t++;
196
+ t > i && (t = n.lastIndexOf(!0));
197
+ } else if (!n[t]) {
190
198
  let s = t;
191
199
  for (; s <= i && !n[s]; )
192
200
  s++;
@@ -197,133 +205,152 @@ function x(e, t, n, r) {
197
205
  }
198
206
  return (t === -1 || t > i) && (t = i), t;
199
207
  }
200
- const j = /(\d+\.?\d*)\s*[kmbt]$/i, me = (e, t) => e === t;
208
+ const j = /(\d+\.?\d*)\s*[kmbt]$/i, pe = (e, t) => e === t;
201
209
  function be(e, t, n, r, i, s, a = ".", c = {}) {
202
210
  if (n < 0)
203
211
  return 0;
204
212
  if (n > e.length || e === "" || t === "" || j.test(e) && !j.test(t) && t.length > e.length && n >= e.length - 1)
205
213
  return t.length;
206
- const l = t.length < e.length, o = V(
214
+ const o = t.length < e.length, l = V(
207
215
  e,
208
216
  n,
209
217
  r
210
218
  ), h = e.indexOf(a), d = t.indexOf(a);
211
219
  if (c.isCharacterEquivalent && e !== t) {
212
- const f = pe(
220
+ const f = {
221
+ thousandSeparator: r || void 0,
222
+ ...c
223
+ }, g = Le(
213
224
  e,
214
225
  t,
215
226
  n,
216
- c.isCharacterEquivalent || me,
227
+ c.isCharacterEquivalent || pe,
217
228
  s,
218
- c
229
+ f
219
230
  );
220
- if (f !== void 0)
221
- return f;
231
+ if (g !== void 0)
232
+ return g;
222
233
  }
223
- const g = /* @__PURE__ */ new Map(), S = (f, p, y) => {
224
- const C = `${f === e ? "o" : "n"}:${p}`;
225
- return g.has(C) || g.set(C, L(f, p, r)), g.get(C);
234
+ const S = /* @__PURE__ */ new Map(), E = (f, g, L) => {
235
+ const b = `${f === e ? "o" : "n"}:${g}`;
236
+ return S.has(b) || S.set(b, $(f, g, r)), S.get(b);
226
237
  };
227
- if (l)
228
- return Le(
238
+ if (o)
239
+ return Ne(
229
240
  e,
230
241
  t,
231
242
  n,
232
243
  r,
233
- o,
244
+ l,
234
245
  h,
235
246
  d,
236
247
  s,
237
248
  c,
238
- S
249
+ E
239
250
  );
240
- const E = De(
251
+ const m = Ce(
241
252
  e,
242
253
  t,
243
254
  n,
244
255
  r,
245
- o,
246
- S
256
+ l,
257
+ E
247
258
  );
248
- return c.boundary ? x(t, E, c.boundary) : E;
259
+ return c.boundary ? x(t, m, c.boundary) : m;
249
260
  }
250
- function pe(e, t, n, r, i, s) {
261
+ function Le(e, t, n, r, i, s) {
251
262
  const a = e.length, c = t.length;
252
- let l = 0, o = 0, h = c;
253
- for (let u = 0; u < a; u++) {
254
- let g = -1;
255
- for (let S = l; S < c; S++)
263
+ let o = 0, l = 0, h = c;
264
+ for (let g = 0; g < a; g++) {
265
+ let L = -1;
266
+ for (let b = o; b < c; b++)
256
267
  if (r(
257
- e[u],
258
- t[S],
268
+ e[g],
269
+ t[b],
259
270
  {
260
271
  oldValue: e,
261
272
  newValue: t,
262
273
  typedRange: i,
263
- oldIndex: u,
264
- newIndex: S
274
+ oldIndex: g,
275
+ newIndex: b
265
276
  }
266
277
  )) {
267
- g = S;
278
+ L = b;
268
279
  break;
269
280
  }
270
- g !== -1 && (l = g + 1, u < n ? o = g + 1 : h === c && /\d/.test(e[u]) && (h = g));
281
+ L !== -1 && (o = L + 1, g < n ? l = L + 1 : h === c && /\d/.test(e[g]) && (h = L));
271
282
  }
272
- if (o > h) return h;
273
- const d = n - o < h - n ? o : h;
274
- return s.boundary ? x(t, d, s.boundary) : d;
275
- }
276
- function Le(e, t, n, r, i, s, a, c, l = {}, o = L) {
283
+ if (l > h) return h;
284
+ const d = t.length < e.length || i !== void 0 && i.isDelete === !1;
285
+ let u, S = !1, E = !1;
286
+ if (d) {
287
+ u = l;
288
+ const g = s.thousandSeparator, L = s.decimalSeparator ?? ".", b = u < t.length ? t[u] : "";
289
+ g && b === g ? (n > 0 ? e[n - 1] : "") === g ? (u = h, S = !0) : E = !0 : b === L && (E = !0);
290
+ } else
291
+ u = n - l < h - n ? l : h;
292
+ const m = d && !S ? "left" : "right";
293
+ if (s.boundary)
294
+ return E ? u : x(t, u, s.boundary, m);
295
+ const f = s.thousandSeparator;
296
+ if (!E && f && u >= 0 && u < t.length && t[u] === f)
297
+ if (d && !S)
298
+ for (; u > 0 && t[u] === f; ) u--;
299
+ else
300
+ for (; u < t.length && t[u] === f; ) u++;
301
+ return u;
302
+ }
303
+ function Ne(e, t, n, r, i, s, a, c, o = {}, l = $) {
277
304
  if (i)
278
- return Ne(
305
+ return $e(
279
306
  e,
280
307
  t,
281
308
  n,
282
309
  r,
283
310
  a,
284
- o
311
+ l
285
312
  );
286
- const h = o(e, n, r), d = o(e, e.length, r), u = o(t, t.length, r), g = d - u, S = $e(
313
+ const h = l(e, n, r), d = l(e, e.length, r), u = l(t, t.length, r), S = d - u, E = ve(
287
314
  e,
288
315
  n,
289
316
  r,
290
317
  h,
291
- g,
318
+ S,
292
319
  s,
293
320
  c,
294
- o
295
- ), E = s === -1 || n <= s, f = ve(
321
+ l
322
+ ), m = s === -1 || n <= s, f = De(
296
323
  t,
297
- S,
324
+ E,
298
325
  r,
299
- g,
326
+ S,
300
327
  c,
301
- E,
328
+ m,
302
329
  a,
303
- o
330
+ l
304
331
  );
305
- return l.boundary ? x(t, f, l.boundary) : f;
332
+ return o.boundary ? x(t, f, o.boundary) : f;
306
333
  }
307
- function Ne(e, t, n, r, i, s = L) {
334
+ function $e(e, t, n, r, i, s = $) {
308
335
  const a = n + 1;
309
336
  if (a < e.length) {
310
- const c = s(e, a, r), l = ge(
337
+ const c = s(e, a, r), o = Se(
311
338
  t,
312
339
  c,
313
340
  r
314
341
  );
315
- return l < t.length && t[l] !== r ? l + 1 : l;
342
+ return o < t.length && t[o] !== r ? o + 1 : o;
316
343
  }
317
344
  return n;
318
345
  }
319
- function $e(e, t, n, r, i, s, a, c = L) {
346
+ function ve(e, t, n, r, i, s, a, c = $) {
320
347
  if (a) {
321
- const { start: o, isDelete: h } = a;
322
- return h ? c(e, o, n) : Math.max(0, c(e, o, n));
348
+ const { start: l, isDelete: h } = a;
349
+ return h ? c(e, l, n) : Math.max(0, c(e, l, n));
323
350
  }
324
351
  return t > 0 && e[t - 1] === n && i > 0 ? r + 1 : r;
325
352
  }
326
- function K(e, t, n, r, i, s, a = L) {
353
+ function K(e, t, n, r, i, s, a = $) {
327
354
  if (t > 0 && t < e.length && a(e, t, r) === n) {
328
355
  if (e[t] === r && s && i > 0 && t < e.length - 1)
329
356
  return t + 1;
@@ -332,33 +359,33 @@ function K(e, t, n, r, i, s, a = L) {
332
359
  }
333
360
  return t;
334
361
  }
335
- function ve(e, t, n, r, i, s, a, c = L) {
362
+ function De(e, t, n, r, i, s, a, c = $) {
336
363
  if (s && a !== -1) {
337
- const o = e.substring(0, a), h = c(o, o.length, n);
364
+ const l = e.substring(0, a), h = c(l, l.length, n);
338
365
  if (t <= h) {
339
- const d = I(
340
- o,
366
+ const d = R(
367
+ l,
341
368
  t,
342
369
  n
343
370
  );
344
- return K(o, d, t, n, r, i, c);
371
+ return K(l, d, t, n, r, i, c);
345
372
  }
346
373
  }
347
- const l = I(
374
+ const o = R(
348
375
  e,
349
376
  t,
350
377
  n
351
378
  );
352
- return K(e, l, t, n, r, i, c);
379
+ return K(e, o, t, n, r, i, c);
353
380
  }
354
- function De(e, t, n, r, i, s = L) {
355
- const a = n >= e.length, c = s(e, n, r), l = s(e, e.length, r), o = s(t, t.length, r);
356
- if (a || c === l)
381
+ function Ce(e, t, n, r, i, s = $) {
382
+ const a = n >= e.length, c = s(e, n, r), o = s(e, e.length, r), l = s(t, t.length, r);
383
+ if (a || c === o)
357
384
  return t.length;
358
- const h = o - l;
385
+ const h = l - o;
359
386
  let d = c;
360
- h > 0 && !a && c < l && (d = c + 1);
361
- const u = I(
387
+ h > 0 && !a && c < o && (d = c + 1);
388
+ const u = R(
362
389
  t,
363
390
  d,
364
391
  r
@@ -385,12 +412,12 @@ function we(e, t, n) {
385
412
  isDelete: !0
386
413
  };
387
414
  }
388
- const c = t.length, l = n.length, o = c - l;
389
- if (!(o <= 0))
415
+ const c = t.length, o = n.length, l = c - o;
416
+ if (!(l <= 0))
390
417
  return {
391
418
  start: r,
392
- end: r + o,
393
- deletedLength: o,
419
+ end: r + l,
420
+ deletedLength: l,
394
421
  isDelete: !1
395
422
  };
396
423
  }
@@ -421,16 +448,16 @@ function q(e, t) {
421
448
  }
422
449
  return e.selectionStart !== null || e.selectionStart === 0 ? (e.focus(), e.setSelectionRange(t, t), !0) : (e.focus(), !1);
423
450
  }
424
- function Ce(e, t, n) {
451
+ function Me(e, t, n) {
425
452
  return e.selectionStart === 0 && e.selectionEnd === e.value.length ? null : (q(e, t), setTimeout(() => {
426
453
  e.value === n && e.selectionStart !== t && q(e, t);
427
454
  }, 0));
428
455
  }
429
- function Me(e) {
456
+ function Ae(e) {
430
457
  return Math.max(e.selectionStart, e.selectionEnd);
431
458
  }
432
- function Ae(e, t, n) {
433
- if ((n == null ? void 0 : n.formatOn) !== b.Change || !n.thousandSeparator)
459
+ function Ie(e, t, n) {
460
+ if ((n == null ? void 0 : n.formatOn) !== N.Change || !n.thousandSeparator)
434
461
  return;
435
462
  const { selectionStart: r, selectionEnd: i, value: s } = t;
436
463
  if (r === null || i === null || r !== i)
@@ -440,51 +467,52 @@ function Ae(e, t, n) {
440
467
  }
441
468
  function Re(e, t, n, r, i, s, a) {
442
469
  if (!i) return;
443
- const { selectionStart: c = 0, selectionEnd: l = 0, endOffset: o = 0 } = i;
470
+ const { selectionStart: c = 0, selectionEnd: o = 0, endOffset: l = 0 } = i;
444
471
  let h = we(
445
- { selectionStart: c, selectionEnd: l, endOffset: o },
472
+ { selectionStart: c, selectionEnd: o, endOffset: l },
446
473
  t,
447
474
  n
448
475
  );
449
476
  if (h || (h = ye(t, n)), !h) return;
450
- const d = Ee(n, {
477
+ const d = me(n, {
451
478
  thousandSeparator: (a == null ? void 0 : a.thousandSeparator) ?? s.thousandSeparator,
452
479
  decimalSeparator: s.decimalSeparator
453
480
  }), u = {
454
481
  thousandSeparator: (a == null ? void 0 : a.thousandSeparator) ?? s.thousandSeparator,
455
- isCharacterEquivalent: (f, p) => {
456
- const y = (a == null ? void 0 : a.thousandSeparator) ?? s.thousandSeparator;
457
- return y && f === y ? !1 : f === p;
482
+ decimalSeparator: s.decimalSeparator,
483
+ isCharacterEquivalent: (f, g) => {
484
+ const L = (a == null ? void 0 : a.thousandSeparator) ?? s.thousandSeparator;
485
+ return L && f === L ? !1 : f === g;
458
486
  },
459
487
  boundary: d
460
- }, g = (a == null ? void 0 : a.thousandSeparator) ?? s.thousandSeparator ?? ",", S = (a == null ? void 0 : a.ThousandStyle) ?? m.None, E = be(
488
+ }, S = (a == null ? void 0 : a.thousandSeparator) ?? s.thousandSeparator ?? ",", E = (a == null ? void 0 : a.ThousandStyle) ?? p.None, m = be(
461
489
  t,
462
490
  n,
463
491
  r,
464
- g,
465
492
  S,
493
+ E,
466
494
  h,
467
495
  s.decimalSeparator,
468
496
  u
469
497
  );
470
- Ce(e, E, n);
498
+ Me(e, m, n);
471
499
  }
472
- const Ie = (e, t = !1, n = ".") => {
473
- const r = w(n), i = T(`[^0-9${r}]`, "g");
500
+ const Te = (e, t = !1, n = ".") => {
501
+ const r = y(n), i = T(`[^0-9${r}]`, "g");
474
502
  if (!t)
475
503
  return e.replace(i, "");
476
504
  const s = e.startsWith("-"), a = e.replace(i, "");
477
505
  return s && (a.length > 0 || e === "-") ? "-" + a : a;
478
- }, Te = /([+-]?\d+\.?\d*)[eE]([+-]?\d+)/g, F = /^0+$/, A = /\.?0+$/;
479
- function _e(e) {
480
- return !e.includes("e") && !e.includes("E") ? e : e.replace(Te, (t, n, r) => {
506
+ }, _e = /([+-]?\d+\.?\d*)[eE]([+-]?\d+)/g, F = /^0+$/, A = /\.?0+$/;
507
+ function xe(e) {
508
+ return !e.includes("e") && !e.includes("E") ? e : e.replace(_e, (t, n, r) => {
481
509
  const i = parseInt(r, 10);
482
510
  if (i === 0) return n;
483
- const s = n.startsWith("-"), a = s ? n.slice(1) : n, [c, l = ""] = a.split("."), o = i > 0 ? xe(c, l, i) : Oe(c, l, Math.abs(i));
484
- return s ? "-" + o : o;
511
+ const s = n.startsWith("-"), a = s ? n.slice(1) : n, [c, o = ""] = a.split("."), l = i > 0 ? Oe(c, o, i) : Ge(c, o, Math.abs(i));
512
+ return s ? "-" + l : l;
485
513
  });
486
514
  }
487
- function xe(e, t, n) {
515
+ function Oe(e, t, n) {
488
516
  const r = e + t;
489
517
  if (r === "0" || F.test(r))
490
518
  return "0";
@@ -496,22 +524,22 @@ function xe(e, t, n) {
496
524
  const s = n - i;
497
525
  return r + "0".repeat(s);
498
526
  }
499
- function Oe(e, t, n) {
527
+ function Ge(e, t, n) {
500
528
  const r = e + t;
501
529
  if (r === "0" || F.test(r))
502
530
  return "0";
503
531
  const s = e.length - n;
504
532
  if (s <= 0) {
505
533
  const a = Math.abs(s), c = `0.${"0".repeat(a)}${r}`;
506
- return R(c);
534
+ return I(c);
507
535
  }
508
536
  if (s < e.length) {
509
- const a = r.slice(0, s), c = r.slice(s), l = `${a}.${c}`;
510
- return R(l);
537
+ const a = r.slice(0, s), c = r.slice(s), o = `${a}.${c}`;
538
+ return I(o);
511
539
  }
512
- return R(r);
540
+ return I(r);
513
541
  }
514
- function R(e) {
542
+ function I(e) {
515
543
  if (!e.includes("."))
516
544
  return e;
517
545
  if (e === "0.")
@@ -526,7 +554,7 @@ function R(e) {
526
554
  }
527
555
  return e.replace(A, "") || e;
528
556
  }
529
- const Ge = /(\d+\.?\d*)\s*([kmbt])/gi, Ze = /^0+/, ke = /^(-?)0+([1-9])/, Be = /^-?0+$/, Pe = /\.?0+$/, We = {
557
+ const Be = /(\d+\.?\d*)\s*([kmbt])/gi, Ze = /^0+/, ke = /^(-?)0+([1-9])/, We = /^-?0+$/, Ue = /\.?0+$/, ze = {
530
558
  k: 3,
531
559
  // Thousand
532
560
  m: 6,
@@ -536,26 +564,26 @@ const Ge = /(\d+\.?\d*)\s*([kmbt])/gi, Ze = /^0+/, ke = /^(-?)0+([1-9])/, Be = /
536
564
  t: 12
537
565
  // Trillion
538
566
  };
539
- function Ue(e) {
540
- return e.replace(Ge, (t, n, r) => {
541
- const i = r.toLowerCase(), s = We[i];
567
+ function Je(e) {
568
+ return e.replace(Be, (t, n, r) => {
569
+ const i = r.toLowerCase(), s = ze[i];
542
570
  if (!s)
543
571
  return t;
544
- const [a, c = ""] = n.split("."), l = a.replace(Ze, "") || "0";
545
- let o;
572
+ const [a, c = ""] = n.split("."), o = a.replace(Ze, "") || "0";
573
+ let l;
546
574
  if (c.length === 0)
547
- o = l + "0".repeat(s);
575
+ l = o + "0".repeat(s);
548
576
  else if (c.length <= s) {
549
577
  const h = s - c.length;
550
- o = l + c + "0".repeat(h);
578
+ l = o + c + "0".repeat(h);
551
579
  } else {
552
580
  const h = c.slice(0, s), d = c.slice(s);
553
- o = l + h + "." + d;
581
+ l = o + h + "." + d;
554
582
  }
555
- return o = o.replace(ke, "$1$2"), Be.test(o) && (o = "0"), o.includes(".") && (o = o.replace(Pe, "")), o;
583
+ return l = l.replace(ke, "$1$2"), We.test(l) && (l = "0"), l.includes(".") && (l = l.replace(Ue, "")), l;
556
584
  });
557
585
  }
558
- function ze(e) {
586
+ function Pe(e) {
559
587
  if (!e || e === "0" || e === "-0" || e === "-" || e === ".")
560
588
  return e;
561
589
  const t = e.startsWith("-"), n = t ? e.slice(1) : e;
@@ -575,22 +603,22 @@ function ze(e) {
575
603
  }
576
604
  return e;
577
605
  }
578
- function Je(e) {
606
+ function Xe(e) {
579
607
  return e.replace(/[\s\u200B]/g, "");
580
608
  }
581
- function N(e, t) {
582
- const n = ie(t);
609
+ function v(e, t) {
610
+ const n = se(t);
583
611
  return e.replace(n, "");
584
612
  }
585
- const Xe = (e, t) => {
586
- let n = Je(e);
587
- return t != null && t.thousandSeparator && (n = N(n, t.thousandSeparator)), t != null && t.enableCompactNotation && (n = Ue(n)), n = _e(n), n = Ie(
613
+ const je = (e, t) => {
614
+ let n = Xe(e);
615
+ return t != null && t.thousandSeparator && (n = v(n, t.thousandSeparator)), t != null && t.enableCompactNotation && (n = Je(n)), n = xe(n), n = Te(
588
616
  n,
589
617
  t == null ? void 0 : t.enableNegative,
590
618
  t == null ? void 0 : t.decimalSeparator
591
- ), n = le(n, t == null ? void 0 : t.decimalSeparator), t != null && t.enableLeadingZeros || (n = ze(n)), n;
619
+ ), n = he(n, t == null ? void 0 : t.decimalSeparator), t != null && t.enableLeadingZeros || (n = Pe(n)), n;
592
620
  };
593
- function je(e, t, n) {
621
+ function Ke(e, t, n) {
594
622
  return {
595
623
  enableCompactNotation: e == null ? void 0 : e.enableCompactNotation,
596
624
  enableNegative: e == null ? void 0 : e.enableNegative,
@@ -600,19 +628,19 @@ function je(e, t, n) {
600
628
  };
601
629
  }
602
630
  function O(e, t, n, r) {
603
- const i = _(n), s = r ?? (n == null ? void 0 : n.formatOn) === b.Change, a = Xe(
631
+ const i = _(n), s = r ?? (n == null ? void 0 : n.formatOn) === N.Change, a = je(
604
632
  e,
605
- je(n, i, s)
633
+ Ke(n, i, s)
606
634
  ), c = oe(
607
635
  a,
608
636
  t,
609
637
  i.decimalSeparator
610
- ), l = (n == null ? void 0 : n.decimalMinLength) ?? 0, o = he(
638
+ ), o = (n == null ? void 0 : n.decimalMinLength) ?? 0, l = ue(
611
639
  c,
612
- l,
640
+ o,
613
641
  i.decimalSeparator
614
642
  );
615
- return { formatted: fe(o, n, i), raw: o };
643
+ return { formatted: ge(l, n, i), raw: l };
616
644
  }
617
645
  function ft(e, t, n) {
618
646
  const r = !!(n != null && n.thousandSeparator);
@@ -623,7 +651,7 @@ function ft(e, t, n) {
623
651
  r
624
652
  );
625
653
  }
626
- function Ke(e, t, n) {
654
+ function qe(e, t, n) {
627
655
  if (e === "Backspace" || e === "Delete")
628
656
  return e === "Delete" && t === n ? {
629
657
  endOffset: 1
@@ -631,58 +659,58 @@ function Ke(e, t, n) {
631
659
  endOffset: 0
632
660
  };
633
661
  }
634
- function qe(e, t) {
662
+ function He(e, t) {
635
663
  const { decimalSeparator: n } = _(t), r = e.target;
636
- if (ce(e, r, n)) {
664
+ if (le(e, r, n)) {
637
665
  e.preventDefault();
638
666
  return;
639
667
  }
640
- return Ae(e, r, t), Ke(e.key, r.selectionStart, r.selectionEnd);
668
+ return Ie(e, r, t), qe(e.key, r.selectionStart, r.selectionEnd);
641
669
  }
642
- function He(e, t, n, r) {
643
- const i = e.target, s = i.value, a = Me(i), c = _(r), l = (r == null ? void 0 : r.formatOn) === b.Change, { formatted: o, raw: h } = O(
670
+ function Ye(e, t, n, r) {
671
+ const i = e.target, s = i.value, a = Ae(i), c = _(r), o = (r == null ? void 0 : r.formatOn) === N.Change, { formatted: l, raw: h } = O(
644
672
  s,
645
673
  t,
646
674
  r,
647
- l
675
+ o
648
676
  );
649
- return i.value = o, s !== o && Re(
677
+ return i.value = l, s !== l && Re(
650
678
  i,
651
679
  s,
652
- o,
680
+ l,
653
681
  a,
654
682
  n,
655
683
  c,
656
684
  r
657
- ), { formatted: o, raw: h };
685
+ ), { formatted: l, raw: h };
658
686
  }
659
- function Ye(e, t, n, r) {
687
+ function Qe(e, t, n, r) {
660
688
  const i = r - n;
661
689
  return e + t + i;
662
690
  }
663
- function Qe(e, t, n) {
691
+ function Ve(e, t, n) {
664
692
  var u;
665
693
  e.preventDefault();
666
- const r = e.target, { value: i, selectionStart: s, selectionEnd: a } = r, c = ((u = e.clipboardData) == null ? void 0 : u.getData("text/plain")) || "", l = i.slice(0, s || 0) + c + i.slice(a || 0), { formatted: o, raw: h } = O(
667
- l,
694
+ const r = e.target, { value: i, selectionStart: s, selectionEnd: a } = r, c = ((u = e.clipboardData) == null ? void 0 : u.getData("text/plain")) || "", o = i.slice(0, s || 0) + c + i.slice(a || 0), { formatted: l, raw: h } = O(
695
+ o,
668
696
  t,
669
697
  n,
670
698
  !0
671
699
  );
672
- r.value = o;
673
- const d = Ye(
700
+ r.value = l;
701
+ const d = Qe(
674
702
  s || 0,
675
703
  c.length,
676
- l.length,
677
- o.length
704
+ o.length,
705
+ l.length
678
706
  );
679
- return r.setSelectionRange(d, d), { formatted: o, raw: h };
707
+ return r.setSelectionRange(d, d), { formatted: l, raw: h };
680
708
  }
681
- function Ve(e, t) {
682
- const n = w(e);
709
+ function Fe(e, t) {
710
+ const n = y(e);
683
711
  return t ? `^-?[0-9]*[${n}]?[0-9]*$` : `^[0-9]*[${n}]?[0-9]*$`;
684
712
  }
685
- function Fe(e) {
713
+ function et(e) {
686
714
  var t, n;
687
715
  try {
688
716
  const i = new Intl.NumberFormat(e).formatToParts(123456789e-2);
@@ -694,18 +722,18 @@ function Fe(e) {
694
722
  return { thousandSeparator: ",", decimalSeparator: "." };
695
723
  }
696
724
  }
697
- function et(e) {
698
- let t = e.thousandSeparator ?? re, n = e.decimalSeparator ?? v, r = e.thousandStyle ?? H;
699
- if (e.thousandStyle === m.Locale || e.decimalSeparator === "auto") {
700
- const s = Fe();
701
- e.thousandStyle === m.Locale && (t = e.thousandSeparator ?? s.thousandSeparator, n = e.decimalSeparator === "auto" || e.decimalSeparator === void 0 ? s.decimalSeparator : e.decimalSeparator, r = m.Thousand), e.decimalSeparator === "auto" && (n = s.decimalSeparator);
725
+ function tt(e) {
726
+ let t = e.thousandSeparator ?? ie, n = e.decimalSeparator ?? C, r = e.thousandStyle ?? H;
727
+ if (e.thousandStyle === p.Locale || e.decimalSeparator === "auto") {
728
+ const s = et();
729
+ e.thousandStyle === p.Locale && (t = e.thousandSeparator ?? s.thousandSeparator, n = e.decimalSeparator === "auto" || e.decimalSeparator === void 0 ? s.decimalSeparator : e.decimalSeparator, r = p.Thousand), e.decimalSeparator === "auto" && (n = s.decimalSeparator);
702
730
  }
703
731
  return { thousandSeparator: t, thousandStyle: r, decimalSeparator: n };
704
732
  }
705
- function tt(e) {
706
- nt(e.decimalMaxLength), rt(e.decimalMinLength), it(e.decimalMinLength, e.decimalMaxLength), st(e.formatOn), at(e.thousandSeparator), ct(e.thousandStyle), ot(e.decimalSeparator), lt(e.thousandSeparator, e.decimalSeparator), M("enableCompactNotation", e.enableCompactNotation), M("enableNegative", e.enableNegative), M("enableLeadingZeros", e.enableLeadingZeros), M("rawValueMode", e.rawValueMode), ht(e.onChange);
707
- }
708
733
  function nt(e) {
734
+ rt(e.decimalMaxLength), it(e.decimalMinLength), st(e.decimalMinLength, e.decimalMaxLength), at(e.formatOn), ct(e.thousandSeparator), lt(e.thousandStyle), ot(e.decimalSeparator), ht(e.thousandSeparator, e.decimalSeparator), M("enableCompactNotation", e.enableCompactNotation), M("enableNegative", e.enableNegative), M("enableLeadingZeros", e.enableLeadingZeros), M("rawValueMode", e.rawValueMode), ut(e.onChange);
735
+ }
736
+ function rt(e) {
709
737
  if (e !== void 0) {
710
738
  if (typeof e != "number")
711
739
  throw new Error(
@@ -721,7 +749,7 @@ function nt(e) {
721
749
  );
722
750
  }
723
751
  }
724
- function rt(e) {
752
+ function it(e) {
725
753
  if (e !== void 0) {
726
754
  if (typeof e != "number")
727
755
  throw new Error(
@@ -737,19 +765,19 @@ function rt(e) {
737
765
  );
738
766
  }
739
767
  }
740
- function it(e, t) {
768
+ function st(e, t) {
741
769
  if (!(e === void 0 || t === void 0) && e > t)
742
770
  throw new Error(
743
771
  `decimalMinLength (${e}) cannot be greater than decimalMaxLength (${t}).`
744
772
  );
745
773
  }
746
- function st(e) {
747
- if (e !== void 0 && e !== b.Blur && e !== b.Change)
774
+ function at(e) {
775
+ if (e !== void 0 && e !== N.Blur && e !== N.Change)
748
776
  throw new Error(
749
- `formatOn must be either ${b.Blur} or ${b.Change}. Received: ${JSON.stringify(e)}`
777
+ `formatOn must be either ${N.Blur} or ${N.Change}. Received: ${JSON.stringify(e)}`
750
778
  );
751
779
  }
752
- function at(e) {
780
+ function ct(e) {
753
781
  if (e !== void 0) {
754
782
  if (typeof e != "string")
755
783
  throw new Error(
@@ -765,10 +793,10 @@ function at(e) {
765
793
  );
766
794
  }
767
795
  }
768
- function ct(e) {
769
- if (e !== void 0 && !Object.values(m).includes(e))
796
+ function lt(e) {
797
+ if (e !== void 0 && !Object.values(p).includes(e))
770
798
  throw new Error(
771
- `ThousandStyle must be one of: ${Object.values(m).map((t) => `'${t}'`).join(", ")}. Received: ${JSON.stringify(e)}`
799
+ `ThousandStyle must be one of: ${Object.values(p).map((t) => `'${t}'`).join(", ")}. Received: ${JSON.stringify(e)}`
772
800
  );
773
801
  }
774
802
  function ot(e) {
@@ -787,7 +815,7 @@ function ot(e) {
787
815
  );
788
816
  }
789
817
  }
790
- function lt(e, t) {
818
+ function ht(e, t) {
791
819
  if (!(e === void 0 || t === void 0) && t !== "auto" && e === t)
792
820
  throw new Error(
793
821
  `Decimal separator can't be same as thousand separator. thousandSeparator: ${e}, decimalSeparator: ${t}`
@@ -799,7 +827,7 @@ function M(e, t) {
799
827
  `${e} must be a boolean. Received: ${typeof t} (${JSON.stringify(t)})`
800
828
  );
801
829
  }
802
- function ht(e) {
830
+ function ut(e) {
803
831
  if (e !== void 0 && typeof e != "function")
804
832
  throw new Error(
805
833
  `onChange must be a function or undefined. Received: ${typeof e} (${JSON.stringify(e)})`
@@ -808,36 +836,36 @@ function ht(e) {
808
836
  class gt {
809
837
  constructor(t, {
810
838
  decimalMaxLength: n = G,
811
- decimalMinLength: r = Z,
812
- formatOn: i = k,
839
+ decimalMinLength: r = B,
840
+ formatOn: i = Z,
813
841
  thousandSeparator: s,
814
842
  thousandStyle: a = H,
815
843
  decimalSeparator: c,
816
- enableCompactNotation: l = B,
817
- enableNegative: o = P,
818
- enableLeadingZeros: h = W,
819
- rawValueMode: d = U,
844
+ enableCompactNotation: o = k,
845
+ enableNegative: l = W,
846
+ enableLeadingZeros: h = U,
847
+ rawValueMode: d = z,
820
848
  onChange: u,
821
- ...g
849
+ ...S
822
850
  }) {
823
- D(this, "element");
824
- D(this, "resolvedOptions");
825
- D(this, "rawValue", "");
826
- D(this, "caretPositionBeforeChange");
827
- tt({
851
+ w(this, "element");
852
+ w(this, "resolvedOptions");
853
+ w(this, "rawValue", "");
854
+ w(this, "caretPositionBeforeChange");
855
+ nt({
828
856
  decimalMaxLength: n,
829
857
  decimalMinLength: r,
830
858
  formatOn: i,
831
859
  thousandSeparator: s,
832
860
  thousandStyle: a,
833
861
  decimalSeparator: c,
834
- enableCompactNotation: l,
835
- enableNegative: o,
862
+ enableCompactNotation: o,
863
+ enableNegative: l,
836
864
  enableLeadingZeros: h,
837
865
  rawValueMode: d,
838
866
  onChange: u
839
867
  });
840
- const S = {
868
+ const E = {
841
869
  decimalMaxLength: n,
842
870
  decimalMinLength: r,
843
871
  onChange: u,
@@ -845,66 +873,66 @@ class gt {
845
873
  thousandSeparator: s,
846
874
  thousandStyle: a,
847
875
  decimalSeparator: c,
848
- enableCompactNotation: l,
849
- enableNegative: o,
876
+ enableCompactNotation: o,
877
+ enableNegative: l,
850
878
  enableLeadingZeros: h,
851
879
  rawValueMode: d,
852
- ...g
880
+ ...S
853
881
  };
854
- if (this.resolvedOptions = this.getResolvedOptions(S), this.createInputElement(t, S), this.setupEventListeners(), this.resolvedOptions.rawValueMode && this.element.value) {
855
- const E = this.element.value, f = this.resolvedOptions.thousandSeparator ? N(E, this.resolvedOptions.thousandSeparator) : E;
882
+ if (this.resolvedOptions = this.getResolvedOptions(E), this.createInputElement(t, E), this.setupEventListeners(), this.resolvedOptions.rawValueMode && this.element.value) {
883
+ const m = this.element.value, f = this.resolvedOptions.thousandSeparator ? v(m, this.resolvedOptions.thousandSeparator) : m;
856
884
  this.rawValue = f, this.element.value = this.formatValueForDisplay(f);
857
885
  } else if (this.element.value) {
858
- const E = this.element.value;
859
- this.element.value = this.formatValueForDisplay(E);
886
+ const m = this.element.value;
887
+ this.element.value = this.formatValueForDisplay(m);
860
888
  }
861
889
  }
862
890
  createInputElement(t, n) {
863
891
  this.element = document.createElement("input"), this.element.setAttribute("type", "text"), this.element.setAttribute("inputmode", "decimal"), this.element.setAttribute("spellcheck", "false"), this.element.setAttribute("autocomplete", "off");
864
- const r = Ve(this.resolvedOptions.decimalSeparator, this.resolvedOptions.enableNegative);
892
+ const r = Fe(this.resolvedOptions.decimalSeparator, this.resolvedOptions.enableNegative);
865
893
  this.element.setAttribute("pattern", r);
866
894
  const {
867
895
  decimalMaxLength: i,
868
896
  decimalMinLength: s,
869
897
  formatOn: a,
870
898
  thousandSeparator: c,
871
- thousandStyle: l,
872
- decimalSeparator: o,
899
+ thousandStyle: o,
900
+ decimalSeparator: l,
873
901
  enableCompactNotation: h,
874
902
  enableNegative: d,
875
903
  enableLeadingZeros: u,
876
- rawValueMode: g,
877
- onChange: S,
878
- value: E,
904
+ rawValueMode: S,
905
+ onChange: E,
906
+ value: m,
879
907
  defaultValue: f,
880
- type: p,
881
- inputMode: y,
882
- spellcheck: C,
883
- autocomplete: ut,
884
- ...ee
908
+ type: g,
909
+ inputMode: L,
910
+ spellcheck: b,
911
+ autocomplete: ee,
912
+ ...te
885
913
  } = n;
886
- Object.assign(this.element, ee), E !== void 0 ? this.element.value = E : f !== void 0 && (this.element.defaultValue = f, this.element.value = f), t.appendChild(this.element);
914
+ Object.assign(this.element, te), m !== void 0 ? this.element.value = m : f !== void 0 && (this.element.defaultValue = f, this.element.value = f), t.appendChild(this.element);
887
915
  }
888
916
  setupEventListeners() {
889
- this.element.addEventListener("input", this.handleChange.bind(this)), this.element.addEventListener("keydown", this.handleKeyDown.bind(this)), this.element.addEventListener("paste", this.handlePaste.bind(this)), this.resolvedOptions.formatOn === b.Blur && this.resolvedOptions.thousandSeparator && (this.element.addEventListener("focus", this.handleFocus.bind(this)), this.element.addEventListener("blur", this.handleBlur.bind(this)));
917
+ this.element.addEventListener("input", this.handleChange.bind(this)), this.element.addEventListener("keydown", this.handleKeyDown.bind(this)), this.element.addEventListener("paste", this.handlePaste.bind(this)), this.resolvedOptions.formatOn === N.Blur && this.resolvedOptions.thousandSeparator && (this.element.addEventListener("focus", this.handleFocus.bind(this)), this.element.addEventListener("blur", this.handleBlur.bind(this)));
890
918
  }
891
919
  getResolvedOptions(t) {
892
- const n = et({
920
+ const n = tt({
893
921
  thousandSeparator: t.thousandSeparator,
894
922
  thousandStyle: t.thousandStyle,
895
923
  decimalSeparator: t.decimalSeparator
896
924
  });
897
925
  return {
898
926
  decimalMaxLength: t.decimalMaxLength ?? G,
899
- decimalMinLength: t.decimalMinLength ?? Z,
900
- formatOn: t.formatOn ?? k,
927
+ decimalMinLength: t.decimalMinLength ?? B,
928
+ formatOn: t.formatOn ?? Z,
901
929
  thousandSeparator: n.thousandSeparator,
902
930
  thousandStyle: n.thousandStyle,
903
931
  decimalSeparator: n.decimalSeparator,
904
- enableCompactNotation: t.enableCompactNotation ?? B,
905
- enableNegative: t.enableNegative ?? P,
906
- enableLeadingZeros: t.enableLeadingZeros ?? W,
907
- rawValueMode: t.rawValueMode ?? U,
932
+ enableCompactNotation: t.enableCompactNotation ?? k,
933
+ enableNegative: t.enableNegative ?? W,
934
+ enableLeadingZeros: t.enableLeadingZeros ?? U,
935
+ rawValueMode: t.rawValueMode ?? z,
908
936
  onChange: t.onChange
909
937
  };
910
938
  }
@@ -931,7 +959,7 @@ class gt {
931
959
  if (!t)
932
960
  return t;
933
961
  const { thousandSeparator: n, thousandStyle: r, enableLeadingZeros: i, decimalSeparator: s } = this.resolvedOptions;
934
- return n && r !== m.None ? Q(
962
+ return n && r !== p.None ? Q(
935
963
  t,
936
964
  n,
937
965
  r,
@@ -940,7 +968,7 @@ class gt {
940
968
  ) : t;
941
969
  }
942
970
  handleChange(t) {
943
- const { formatted: n, raw: r } = He(
971
+ const { formatted: n, raw: r } = Ye(
944
972
  t,
945
973
  this.resolvedOptions.decimalMaxLength,
946
974
  this.caretPositionBeforeChange,
@@ -949,7 +977,7 @@ class gt {
949
977
  this.caretPositionBeforeChange = void 0, this.handleValueChange(n, r);
950
978
  }
951
979
  handleKeyDown(t) {
952
- const n = t.target, { selectionStart: r, selectionEnd: i } = n, s = this.buildFormattingOptions(), a = qe(t, {
980
+ const n = t.target, { selectionStart: r, selectionEnd: i } = n, s = this.buildFormattingOptions(), a = He(t, {
953
981
  formatOn: s.formatOn,
954
982
  thousandSeparator: s.thousandSeparator,
955
983
  ThousandStyle: s.ThousandStyle,
@@ -965,23 +993,23 @@ class gt {
965
993
  };
966
994
  }
967
995
  handlePaste(t) {
968
- const { formatted: n, raw: r } = Qe(t, this.resolvedOptions.decimalMaxLength, this.buildFormattingOptions());
996
+ const { formatted: n, raw: r } = Ve(t, this.resolvedOptions.decimalMaxLength, this.buildFormattingOptions());
969
997
  this.handleValueChange(n, r);
970
998
  const i = new Event("input", { bubbles: !0, cancelable: !0 });
971
999
  this.element.dispatchEvent(i);
972
1000
  }
973
1001
  handleFocus(t) {
974
- if (this.resolvedOptions.formatOn === b.Blur && this.resolvedOptions.thousandSeparator) {
1002
+ if (this.resolvedOptions.formatOn === N.Blur && this.resolvedOptions.thousandSeparator) {
975
1003
  const n = t.target;
976
- n.value = N(n.value, this.resolvedOptions.thousandSeparator);
1004
+ n.value = v(n.value, this.resolvedOptions.thousandSeparator);
977
1005
  }
978
1006
  }
979
1007
  handleBlur(t) {
980
1008
  const n = t.target, { thousandSeparator: r, thousandStyle: i } = this.resolvedOptions;
981
- if (r && i !== m.None && n.value) {
1009
+ if (r && i !== p.None && n.value) {
982
1010
  const s = this.formatValueForDisplay(n.value);
983
1011
  n.value = s;
984
- const a = this.resolvedOptions.rawValueMode ? N(s, r) : void 0;
1012
+ const a = this.resolvedOptions.rawValueMode ? v(s, r) : void 0;
985
1013
  this.handleValueChange(s, a);
986
1014
  }
987
1015
  }
@@ -990,7 +1018,7 @@ class gt {
990
1018
  }
991
1019
  setValue(t) {
992
1020
  if (this.resolvedOptions.rawValueMode) {
993
- const n = this.resolvedOptions.thousandSeparator ? N(t, this.resolvedOptions.thousandSeparator) : t;
1021
+ const n = this.resolvedOptions.thousandSeparator ? v(t, this.resolvedOptions.thousandSeparator) : t;
994
1022
  this.rawValue = n, this.element.value = this.formatValueForDisplay(n);
995
1023
  } else
996
1024
  this.element.value = t;
@@ -1038,7 +1066,7 @@ class gt {
1038
1066
  const t = this.getValue();
1039
1067
  if (!t)
1040
1068
  return NaN;
1041
- const n = this.resolvedOptions.thousandSeparator ? N(t, this.resolvedOptions.thousandSeparator) : t, r = this.resolvedOptions.decimalSeparator && this.resolvedOptions.decimalSeparator !== "." ? n.replace(new RegExp(w(this.resolvedOptions.decimalSeparator), "g"), ".") : n;
1069
+ const n = this.resolvedOptions.thousandSeparator ? v(t, this.resolvedOptions.thousandSeparator) : t, r = this.resolvedOptions.decimalSeparator && this.resolvedOptions.decimalSeparator !== "." ? n.replace(new RegExp(y(this.resolvedOptions.decimalSeparator), "g"), ".") : n;
1042
1070
  return parseFloat(r);
1043
1071
  }
1044
1072
  /**
@@ -1054,17 +1082,17 @@ class gt {
1054
1082
  }
1055
1083
  }
1056
1084
  export {
1057
- b as FormatOn,
1085
+ N as FormatOn,
1058
1086
  gt as NumoraInput,
1059
- m as ThousandStyle,
1087
+ p as ThousandStyle,
1060
1088
  O as formatInputValue,
1061
1089
  ft as formatValueForDisplay,
1062
- Ve as getNumoraPattern,
1063
- Fe as getSeparatorsFromLocale,
1064
- He as handleOnChangeNumoraInput,
1065
- qe as handleOnKeyDownNumoraInput,
1066
- Qe as handleOnPasteNumoraInput,
1067
- N as removeThousandSeparators,
1068
- et as resolveLocaleOptions,
1069
- tt as validateNumoraInputOptions
1090
+ Fe as getNumoraPattern,
1091
+ et as getSeparatorsFromLocale,
1092
+ Ye as handleOnChangeNumoraInput,
1093
+ He as handleOnKeyDownNumoraInput,
1094
+ Ve as handleOnPasteNumoraInput,
1095
+ v as removeThousandSeparators,
1096
+ tt as resolveLocaleOptions,
1097
+ nt as validateNumoraInputOptions
1070
1098
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "numora",
3
- "version": "3.2.0",
3
+ "version": "3.3.0",
4
4
  "description": "Framework-agnostic numeric input library for DeFi and financial apps",
5
5
  "homepage": "https://numora.xyz/",
6
6
  "main": "dist/index.js",