numora 3.0.2 → 3.2.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 ae=Object.defineProperty;var ce=(e,t,n)=>t in e?ae(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var v=(e,t,n)=>ce(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var $=(e=>(e.Blur="blur",e.Change="change",e))($||{}),m=(e=>(e.None="none",e.Thousand="thousand",e.Lakh="lakh",e.Wan="wan",e))(m||{});const _=2,z=0,Z=$.Blur,B=",",W=m.None,N=".",le=!1,k=!1,U=!1,G=!1;function I(e){return{decimalSeparator:(e==null?void 0:e.decimalSeparator)??N,thousandSeparator:e==null?void 0:e.thousandSeparator}}function K(e,t){const n=e.startsWith("-"),s=n?e.slice(1):e,[o="",r=""]=s.split(t);return{sign:n?"-":"",integer:o,decimal:r}}function he(e,t){if(!e.value.includes(t))return!1;const{selectionStart:n,selectionEnd:s,value:o}=e;return!o.slice(n??0,s??0).includes(t)}function ue(e,t,n){const{key:s}=e;if(s!==","&&s!==".")return!1;if(he(t,n))return!0;if(s!==n){const{selectionStart:o,selectionEnd:r,value:i}=t,a=o??0,c=r??a;t.value=i.slice(0,a)+n+i.slice(c);const l=a+1;return t.setSelectionRange(l,l),!0}return!1}const fe=(e,t,n=N)=>{const{sign:s,integer:o,decimal:r}=K(e,n);if(!e.includes(n))return e;const a=r.slice(0,t);return`${s}${o}${n}${a}`},de=(e,t=N)=>{const n=e.indexOf(t);if(n===-1)return e;const s=e.slice(0,n+1),r=e.slice(n+1).split(",").join("").split(".").join("").split(t).join("");return s+r},ge=(e,t=0,n=N)=>{if(t<=0)return e;const{sign:s,integer:o,decimal:r}=K(e,n);if(r.length>=t)return e.includes(n)?e:`${s}${o}${n}${r}`;const i=r.padEnd(t,"0");return`${s}${o}${n}${i}`},E={thousand:{size:3},lakh:{firstGroup:3,restGroup:2},wan:{size:4}};function y(e,t,n=m.Thousand,s=!1,o="."){if(!e||e==="0"||e===o||e==="-"||e===`-${o}`)return e;const r=e.includes(o),i=e.startsWith("-"),a=i?e.slice(1):e,[c,l]=a.split(o);if(!c){const f=l?`${o}${l}`:a;return i?`-${f}`:f}if(s&&c.startsWith("0")&&c.length>1){const f=c.match(/^(0+)/);if(f){const d=f[1],g=c.slice(d.length);if(g){const p=j(g,t,n),S=d+p,D=i?"-":"";return r?l?`${D}${S}${o}${l}`:`${D}${S}${o}`:`${D}${S}`}}}const h=j(c,t,n),u=i?"-":"";return r?l?`${u}${h}${o}${l}`:`${u}${h}${o}`:`${u}${h}`}function j(e,t,n){if(e==="0"||e==="")return e;switch(n){case m.None:return e;case m.Thousand:return pe(e,t);case m.Lakh:return me(e,t);case m.Wan:return Se(e,t);default:return e}}function pe(e,t){return q(e,t,E.thousand.size)}function me(e,t){if(e.length<=E.lakh.firstGroup)return e;const n=e.split("").reverse(),s=[],o=n.slice(0,E.lakh.firstGroup).reverse().join("");s.push(o);for(let r=E.lakh.firstGroup;r<n.length;r+=E.lakh.restGroup)s.push(n.slice(r,r+E.lakh.restGroup).reverse().join(""));return s.reverse().join(t)}function Se(e,t){return q(e,t,E.wan.size)}function q(e,t,n){const s=e.split("").reverse(),o=[];for(let r=0;r<s.length;r+=n)o.push(s.slice(r,r+n).reverse().join(""));return o.reverse().join(t)}function $e(e,t,n){return(t==null?void 0:t.formatOn)===$.Change&&t.thousandSeparator?y(e,t.thousandSeparator,t.ThousandStyle??m.None,t.enableLeadingZeros,(n==null?void 0:n.decimalSeparator)??N):e}function b(e,t,n,s="."){let o=0;for(let r=0;r<t&&r<e.length;r++)e[r]!==n&&o++;return o}function be(e,t,n,s="."){if(t===0)return 0;let o=0;for(let r=0;r<e.length;r++)if(e[r]!==n){if(o===t-1)return r+1;o++}return e.length}function A(e,t,n,s="."){if(t===0)return 0;let o=0;for(let r=0;r<e.length;r++)if(e[r]!==n){if(o++,o===t)return r+1;if(o>t)return r}return e.length}function Q(e,t,n){return t<0||t>=e.length?!1:e[t]===n}function Ne(e,t={}){const{thousandSeparator:n,decimalSeparator:s=".",prefix:o="",suffix:r=""}=t,i=Array.from({length:e.length+1}).map(()=>!0);if(o&&i.fill(!1,0,o.length),r){const a=e.length-r.length;i.fill(!1,a+1,e.length+1)}for(let a=0;a<e.length;a++){const c=e[a];(n&&c===n||c===s)&&(i[a]=!1,a+1<e.length&&!/\d/.test(e[a+1])&&(i[a+1]=!1))}return i.some(a=>a)||i.fill(!0),i}function P(e,t,n,s){const o=e.length;if(t=Math.max(0,Math.min(t,o)),!n[t]){let r=t;for(;r<=o&&!n[r];)r++;let i=t;for(;i>=0&&!n[i];)i--;r<=o&&i>=0?t=t-i<r-t?i:r:r<=o?t=r:i>=0&&(t=i)}return(t===-1||t>o)&&(t=o),t}const H=(e,t)=>e===t;function De(e,t,n,s,o,r,i=".",a={}){if(n<0)return 0;if(n>e.length||e===""||t==="")return t.length;const c=/(\d+\.?\d*)\s*[kmbMTOQaqiSxsxSpOoNn]$/i;if(c.test(e)&&!c.test(t)&&t.length>e.length&&n>=e.length-1)return t.length;const l=t.length<e.length,h=Q(e,n,s),u=e.indexOf(i),f=t.indexOf(i);if(a.isCharacterEquivalent&&e!==t){const p=Le(e,t,n,a.isCharacterEquivalent||H,r,a);if(p!==void 0)return p}if(l)return Ee(e,t,n,s,h,u,f,r,i,a);const g=Me(e,t,n,s,h,i);return a.boundary?P(t,g,a.boundary):g}function Le(e,t,n,s,o,r){const i=e.length,a=t.length,c={},l=new Array(i);for(let g=0;g<i;g++){l[g]=-1;for(let p=0;p<a;p++){if(c[p])continue;if(s(e[g],t[p],{oldValue:e,newValue:t,typedRange:o,oldIndex:g,newIndex:p})){l[g]=p,c[p]=!0;break}}}let h=n;for(;h<i&&(l[h]===-1||!/\d/.test(e[h]));)h++;const u=h===i||l[h]===-1?a:l[h];for(h=n-1;h>=0&&l[h]===-1;)h--;const f=h===-1||l[h]===-1?0:l[h]+1;if(f>u)return u;const d=n-f<u-n?f:u;return r.boundary?P(t,d,r.boundary):d}function Ee(e,t,n,s,o,r,i,a,c,l={}){if(o)return we(e,t,n,s,i,c);const h=b(e,n,s,c),u=b(e,e.length,s,c),f=b(t,t.length,s,c),d=u-f,g=ve(e,n,s,h,d,r,a,c),p=r===-1||n<=r,S=ye(t,g,s,d,a,c,p,i);return l.boundary?P(t,S,l.boundary):S}function we(e,t,n,s,o,r){const i=n+1;if(i<e.length){const a=b(e,i,s,r),c=be(t,a,s,r);return c<t.length&&t[c]!==s?c+1:c}return n}function ve(e,t,n,s,o,r,i,a){if(i){const{start:l,isDelete:h}=i;return h?b(e,l,n,a):Math.max(0,b(e,l,n,a))}return t>0&&e[t-1]===n&&o>0?s+1:s}function ye(e,t,n,s,o,r,i,a){if(i&&a!==-1){const l=e.substring(0,a),h=b(l,l.length,n,r);if(t<=h){const u=A(l,t,n,r);if(u>0&&u<l.length&&b(l,u,n,r)===t){if(l[u]===n&&o&&s>0&&u<l.length-1)return u+1;if(!o&&s>0&&u<l.length-1)return Math.min(u+1,l.length)}return u}}const c=A(e,t,n,r);if(c>0&&c<e.length&&b(e,c,n,r)===t){if(e[c]===n&&o&&s>0&&c<e.length-1)return c+1;if(!o&&s>0&&c<e.length-1)return Math.min(c+1,e.length)}return c}function Me(e,t,n,s,o,r){const i=n>=e.length,a=b(e,n,s,r),c=b(e,e.length,s,r),l=b(t,t.length,s,r);if(i||a===c)return t.length;const h=l-c;let u=a;h>0&&!i&&a<c&&(u=a+1);const f=A(t,u,s,r);return o&&!Q(t,f,s)?Math.max(0,f-1):f}function xe(e,t,n){const{selectionStart:s,selectionEnd:o,endOffset:r=0}=e;if(s!==o){const h=o-s;return{start:s,end:o,deletedLength:h,isDelete:!1}}if(r>0){const h=r;return{start:s,end:s+h,deletedLength:h,isDelete:!0}}const a=t.length,c=n.length,l=a-c;if(!(l<=0))return{start:s,end:s+l,deletedLength:l,isDelete:!1}}function Ce(e,t){if(e===t)return;let n=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;let s=e.length-1,o=t.length-1;for(;s>=n&&o>=n&&e[s]===t[o];)s--,o--;const r=s-n+1,i=o-n+1;if(!(r===0&&i===0))return{start:n,end:s+1,deletedLength:r,isDelete:r>i}}function J(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 Te(e,t,n){return e.selectionStart===0&&e.selectionEnd===e.value.length?null:(J(e,t),setTimeout(()=>{e.value===n&&e.selectionStart!==t&&J(e,t)},0))}function Ae(e){return Math.max(e.selectionStart,e.selectionEnd)}function Ie(e,t,n){if((n==null?void 0:n.formatOn)!==$.Change||!n.thousandSeparator)return;const{selectionStart:s,selectionEnd:o,value:r}=t;if(s===null||o===null||s!==o)return;const{key:i}=e,a=n.thousandSeparator;i==="Backspace"&&s>0&&r[s-1]===a&&t.setSelectionRange(s-1,s-1),i==="Delete"&&r[s]===a&&t.setSelectionRange(s+1,s+1)}function Pe(e,t,n,s,o,r,i){if(!o)return;const{selectionStart:a=0,selectionEnd:c=0,endOffset:l=0}=o;let h=xe({selectionStart:a,selectionEnd:c,endOffset:l},t,n);if(h||(h=Ce(t,n)),!h)return;const u=Ne(n,{thousandSeparator:(i==null?void 0:i.thousandSeparator)??r.thousandSeparator,decimalSeparator:r.decimalSeparator}),f={thousandSeparator:(i==null?void 0:i.thousandSeparator)??r.thousandSeparator,isCharacterEquivalent:H,boundary:u},d=(i==null?void 0:i.thousandSeparator)??r.thousandSeparator??",",g=(i==null?void 0:i.ThousandStyle)??m.None,p=De(t,n,s,d,g,h,r.decimalSeparator,f);Te(e,p,n)}function V(e){const[t,n=""]=e.split(".");return t.length+n.length>30}function X(e,t){const n=e.replace(".",""),s=t.replace(".",""),o=Math.max(n.length,s.length),r=n.padStart(o,"0"),i=s.padStart(o,"0");for(let a=0;a<o;a++){const c=parseInt(r[a],10),l=parseInt(i[a],10);if(c!==l)return c-l}return 0}const Oe=[{suffix:"N",zeros:30},{suffix:"O",zeros:27},{suffix:"Sp",zeros:24},{suffix:"Sx",zeros:21},{suffix:"Qi",zeros:18},{suffix:"Qa",zeros:15},{suffix:"T",zeros:12},{suffix:"B",zeros:9},{suffix:"M",zeros:6},{suffix:"k",zeros:3}];function Y(e,t,n=0){const[s,o=""]=e.split(t),r=s.replace(/^0+/,"")||"0";for(const i of Oe)if(i.zeros>=n&&(r.length>i.zeros||r.length===i.zeros&&o.length>0)){const a=i.zeros;if(r.length>a){const c=r.slice(0,-a),u=(r.slice(-a)+o).replace(/0+$/,"");return{scaledValue:u?`${c}${t}${u}`:c,scaleSuffix:i.suffix}}else{const c=a-r.length,l="0",u=("0".repeat(c)+r+o).replace(/0+$/,"");return{scaledValue:u?`${l}${t}${u}`:l,scaleSuffix:i.suffix}}}return{scaledValue:e,scaleSuffix:""}}function O(e,t,n,s,o=!1,r=!1){if(r&&o&&n>0)return`0${s}${"0".repeat(n)}`;const[i,a=""]=e.split(s);let c;if(t===0)c=i;else if(a.length===0){const l="0".repeat(Math.max(t,n));c=`${i}${s}${l}`}else if(a.length<t){const l=Math.max(t-a.length,n-a.length);c=`${i}${s}${a}${"0".repeat(l)}`}else c=`${i}${s}${a.slice(0,t)}`;if(n>0){const[l,h=""]=c.split(s);if(h.length<n){const u=n-h.length;c=`${l}${s}${h}${"0".repeat(u)}`}}if(n===0)c=c.replace(/(\.[0-9]*?)0+$/,"$1").replace(/\.$/,"");else{const[l,h=""]=c.split(s);if(h){const u=h.replace(/0+$/,""),f=u.length>=n?u:h.slice(0,n);c=f?`${l}${s}${f}`:l}}return c}function F(e,t){return!e||e==="0"||e===t||e==="-"||e===`-${t}`}function ee(e){const t=e.startsWith("-");return{isNegative:t,absoluteValue:t?e.slice(1):e}}function te(e,t){if(!e||e==="0")return"0";const n=e.includes(t),[s,o=""]=n?e.split(t):[e,""];let r;if(o.length<=2){const a=2-o.length;r=s+o+"0".repeat(a)}else r=s+o.slice(0,2)+t+o.slice(2);let i=r.replace(/^0+/,"")||"0";if(i.startsWith(t)&&(i="0"+i),i.includes(t)){const[a,c]=i.split(t);return a==="0"&&!c?"0":i}return i}function Re(e,t){const{decimals:n,decimalSeparator:s,thousandSeparator:o,thousandStyle:r,decimalsMin:i=0}=t;if(F(e,s))return"0";const{isNegative:a,absoluteValue:c}=ee(e),l=te(c,s);let h=l;o&&r!==m.None&&(h=y(l,o,r,!1,s));const u=O(h,n,i,s,!1,e==="0");return`${a?"-":""}${u}`}function _e(e,t=2,n=N,s,o=m.None){const r=Re(e,{decimals:t,decimalSeparator:n,thousandSeparator:s,thousandStyle:o,decimalsMin:t});return r==="0"?"0%":`${r}%`}function ze(e,t=2,n={}){const{missingPlaceholder:s="?",veryLargePlaceholder:o="🔥",decimalsUnder:r=1e3,decimalSeparator:i=N,thousandSeparator:a,thousandStyle:c=m.None}=n;if(e==null||e==="")return s;if(F(e,i))return"0%";const{isNegative:l,absoluteValue:h}=ee(e),u=te(h,i);if(V(u))return o;const{scaledValue:f,scaleSuffix:d}=Y(u,i),p=X(f,r.toString())<0?t:0;let S=f;a&&c!==m.None&&(S=y(f,a,c,!1,i));const D=O(S,p,p,i,!1,!1);return`${l?"-":""}${D}${d}%`}function Ze(e){const t="₀₁₂₃₄₅₆₇₈₉";return e.replace(/[0-9]/g,n=>t[+n])}function Be(e,t=8,n=N){if(!e||!e.includes(n))return e;const s=e.startsWith("-"),o=s?e.slice(1):e,[r,i]=o.split(n);if(!i||!i.length)return e;const a=i.match(/^(0{3,})/);if(!a)return e;const l=a[1].length,h=i.slice(l),u=r==="0"&&l>=5?l+1:l,f=Ze(u.toString());let d=`0${f}${h}`;const g=f.length,p=Math.max(0,t-g-1);h.length>p&&(d=`0${f}${h.slice(0,p)}`),d=d.replace(/0+$/,"");const S=r==="0"?d:`${r}${d}`;return s?`-${S}`:S}const L={minScale:0,decimalsUnder:1e3,decimals:2,decimalsMin:0,decimalsMinAppliesToZero:!1,veryLargePlaceholder:"🔥",decimalSeparator:N};function We(e,t={}){const{minScale:n=L.minScale,decimalsUnder:s=L.decimalsUnder,decimals:o=L.decimals,decimalsMin:r=L.decimalsMin,decimalsMinAppliesToZero:i=L.decimalsMinAppliesToZero,veryLargePlaceholder:a=L.veryLargePlaceholder,decimalSeparator:c=L.decimalSeparator,thousandSeparator:l,thousandStyle:h=m.None}=t;if(!e||e==="0"||e===c||e==="-"||e===`-${c}`)return i&&r>0?`0${c}${"0".repeat(r)}`:"0";const u=e.startsWith("-"),f=u?e.slice(1):e;if(V(f))return a;const{scaledValue:d,scaleSuffix:g}=Y(f,c,n),S=X(d,s.toString())<0?o:0;let D=d;l&&h!==m.None&&(D=y(d,l,h,!1,c));const R=O(D,S,r,c,i,e==="0");return`${u?"-":""}${R}${g}`}function x(e){return e.replace(/[-[\]/{}()*+?.\\^$|]/g,"\\$&")}const ke=(e,t=!1,n=".")=>{const s=x(n),o=new RegExp(`[^0-9${s}]`,"g");if(!t)return e.replace(o,"");const r=e.startsWith("-"),i=e.replace(o,"");if(r){if(i.length>0)return"-"+i;if(e==="-")return"-"}return i};function Ue(e){const t=/([+-]?\d+\.?\d*)[eE]([+-]?\d+)/g;let n=e,s;const o=[];for(;(s=t.exec(e))!==null;){const r=s[0],i=s[1],a=parseInt(s[2],10);let c;if(a===0)c=i;else{const l=i.startsWith("-"),h=l?i.slice(1):i,[u,f=""]=h.split(".");a>0?c=Ge(u,f,a):c=je(u,f,Math.abs(a)),l&&(c="-"+c)}o.push({full:r,expanded:c})}for(const{full:r,expanded:i}of o)n=n.replace(r,i);return n}function Ge(e,t,n){const s=e+t;if(s==="0"||s.match(/^0+$/))return"0";const o=t.length;if(n<=o){const i=s.slice(0,e.length+n),a=s.slice(e.length+n);return a?`${i}.${a}`:i}const r=n-o;return s+"0".repeat(r)}function je(e,t,n){const s=e+t;if(s==="0"||s.match(/^0+$/))return"0";const i=e.length-n;if(i<=0){const a=Math.abs(i),c=`0.${"0".repeat(a)}${s}`;return T(c)}if(i<e.length){const a=s.slice(0,i),c=s.slice(i),l=`${a}.${c}`;return T(l)}return T(s)}function T(e){if(!e.includes("."))return e;if(e==="0"||e==="0.")return"0";if(e.startsWith("0.")){const t=e.replace(/\.?0+$/,"");return t==="0"?"0":t||"0"}if(e.startsWith("-0.")){const t=e.replace(/\.?0+$/,"");return t==="-0"||t==="0"?"0":t||"0"}return e.replace(/\.?0+$/,"")||e}function Je(e){const t=/(\d+\.?\d*)\s*(Qa|Qi|Sx|Sp|[kmbMTO]|N)/gi;return e.replace(t,(n,s,o)=>{const r={k:3,K:3,m:6,M:6,b:9,B:9,T:12,t:12};let i;if(o.length>1){const d=o.charAt(0).toUpperCase()+o.slice(1).toLowerCase();i=r[o]||r[d]}else{const d=o.toLowerCase();i=r[o]||r[d]}if(!i)return n;const a=s.startsWith("-"),c=a?s.slice(1):s,[l,h=""]=c.split("."),u=l.replace(/^0+/,"")||"0";let f;if(h.length===0)f=u+"0".repeat(i);else if(h.length<=i){const d=i-h.length;f=u+h+"0".repeat(d)}else{const d=h.slice(0,i),g=h.slice(i);f=u+d+"."+g}return f=f.replace(/^(-?)0+([1-9])/,"$1$2"),f.match(/^-?0+$/)&&(f=a?"-0":"0"),f.includes(".")&&(f=f.replace(/\.?0+$/,"")),a&&!f.startsWith("-")?"-"+f:f})}function Ke(e){if(!e||e==="0"||e==="-0"||e==="-"||e===".")return e;const t=e.startsWith("-"),n=t?e.slice(1):e;if(!n||n==="0"||n===".")return e;if(n.includes(".")){const[o,r]=n.split(".");if(o&&o.length>0){const a=(o.replace(/^0+/,"")||"0")+"."+r;return t?"-"+a:a}return e}if(n.startsWith("0")&&n.length>1){const o=n.replace(/^0+/,"")||"0";return t?"-"+o:o}return e}function qe(e){return e.replace(/[\u00A0\u2000-\u200B\u202F\u205F\u3000]/g," ").replace(/\s/g,"")}function w(e,t){const n=x(t);return e.replace(new RegExp(n,"g"),"")}const Qe=(e,t)=>{let n=qe(e);return t!=null&&t.thousandSeparator&&(n=w(n,t.thousandSeparator)),t!=null&&t.enableCompactNotation&&(n=Je(n)),n=Ue(n),n=ke(n,t==null?void 0:t.enableNegative,t==null?void 0:t.decimalSeparator),n=de(n,(t==null?void 0:t.decimalSeparator)||N),t!=null&&t.enableLeadingZeros||(n=Ke(n)),n};function He(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 C(e,t,n,s){const o=I(n),r=s??(n==null?void 0:n.formatOn)===$.Change,i=Qe(e,He(n,o,r)),a=fe(i,t,o.decimalSeparator),c=(n==null?void 0:n.decimalMinLength)??0,l=ge(a,c,o.decimalSeparator),h=l;return{formatted:$e(l,n,o),raw:h}}function Ve(e,t,n){const s=!!(n!=null&&n.thousandSeparator);return C(e,t,n,s)}function Xe(e,t,n){if(e==="Backspace"||e==="Delete")return e==="Delete"&&t===n?{endOffset:1}:{endOffset:0}}function ne(e,t){const{decimalSeparator:n}=I(t),s=e.target;if(ue(e,s,n)){e.preventDefault();return}return Ie(e,s,t),Xe(e.key,s.selectionStart,s.selectionEnd)}function se(e,t,n,s){const o=e.target,r=o.value,i=Ae(o),a=I(s),c=(s==null?void 0:s.formatOn)===$.Change,{formatted:l,raw:h}=C(r,t,s,c);return o.value=l,r!==l&&Pe(o,r,l,i,n,a,s),{formatted:l,raw:h}}function Ye(e,t,n,s){const o=s-n;return e+t+o}function re(e,t,n){var f;e.preventDefault();const s=e.target,{value:o,selectionStart:r,selectionEnd:i}=s,a=((f=e.clipboardData)==null?void 0:f.getData("text/plain"))||"",c=o.slice(0,r||0)+a+o.slice(i||0),{formatted:l,raw:h}=C(c,t,n,!0);s.value=l;const u=Ye(r||0,a.length,c.length,l.length);return s.setSelectionRange(u,u),{formatted:l,raw:h}}function Fe(e,t){const n=x(e);return t?`^-?[0-9]*[${n}]?[0-9]*$`:`^[0-9]*[${n}]?[0-9]*$`}function et(e){tt(e.decimalMaxLength),nt(e.decimalMinLength),st(e.decimalMinLength,e.decimalMaxLength),rt(e.formatOn),it(e.thousandSeparator),ot(e.thousandStyle),at(e.decimalSeparator),ct(e.thousandSeparator,e.decimalSeparator),M("enableCompactNotation",e.enableCompactNotation),M("enableNegative",e.enableNegative),M("enableLeadingZeros",e.enableLeadingZeros),M("rawValueMode",e.rawValueMode),lt(e.onChange)}function tt(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 nt(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 st(e,t){if(!(e===void 0||t===void 0)&&e>t)throw new Error(`decimalMinLength (${e}) cannot be greater than decimalMaxLength (${t}).`)}function rt(e){if(e!==void 0&&e!==$.Blur&&e!==$.Change)throw new Error(`formatOn must be either ${$.Blur} or ${$.Change}. Received: ${JSON.stringify(e)}`)}function it(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(m).includes(e))throw new Error(`ThousandStyle must be one of: ${Object.values(m).map(t=>`'${t}'`).join(", ")}. Received: ${JSON.stringify(e)}`)}function at(e){if(e!==void 0){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 ct(e,t){if(!(e===void 0||t===void 0)&&e===t)throw new Error(`Decimal separator can't be same as thousand separator. thousandSeparator: ${e}, decimalSeparator: ${t}`)}function M(e,t){if(t!==void 0&&typeof t!="boolean")throw new Error(`${e} must be a boolean. Received: ${typeof t} (${JSON.stringify(t)})`)}function lt(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 ht{constructor(t,{decimalMaxLength:n=_,decimalMinLength:s=z,formatOn:o=Z,thousandSeparator:r=B,thousandStyle:i=W,decimalSeparator:a=N,enableCompactNotation:c=!0,enableNegative:l=k,enableLeadingZeros:h=U,rawValueMode:u=G,onChange:f,...d}){v(this,"element");v(this,"options");v(this,"resolvedOptions");v(this,"rawValue","");v(this,"caretPositionBeforeChange");if(et({decimalMaxLength:n,decimalMinLength:s,formatOn:o,thousandSeparator:r,thousandStyle:i,decimalSeparator:a,enableCompactNotation:c,enableNegative:l,enableLeadingZeros:h,rawValueMode:u,onChange:f}),this.options={decimalMaxLength:n,decimalMinLength:s,onChange:f,formatOn:o,thousandSeparator:r,thousandStyle:i,decimalSeparator:a,enableCompactNotation:c,enableNegative:l,enableLeadingZeros:h,rawValueMode:u,...d},this.resolvedOptions=this.getResolvedOptions(),this.createInputElement(t),this.setupEventListeners(),this.resolvedOptions.rawValueMode&&this.element.value){const g=this.element.value,p=this.resolvedOptions.thousandSeparator?w(g,this.resolvedOptions.thousandSeparator):g;this.rawValue=p,this.element.value=this.formatValueForDisplay(p)}else if(this.element.value){const g=this.element.value;this.element.value=this.formatValueForDisplay(g)}}createInputElement(t){if(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"),this.resolvedOptions.decimalSeparator!==void 0&&this.resolvedOptions.enableNegative!==void 0){const oe=Fe(this.resolvedOptions.decimalSeparator,this.resolvedOptions.enableNegative);this.element.setAttribute("pattern",oe)}const{decimalMaxLength:n,decimalMinLength:s,formatOn:o,thousandSeparator:r,thousandStyle:i,decimalSeparator:a,enableCompactNotation:c,enableNegative:l,enableLeadingZeros:h,rawValueMode:u,onChange:f,value:d,defaultValue:g,type:p,inputMode:S,spellcheck:D,autocomplete:R,...ie}=this.options;Object.assign(this.element,ie),d!==void 0?this.element.value=d:g!==void 0&&(this.element.defaultValue=g,this.element.value=g),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===$.Blur&&this.resolvedOptions.thousandSeparator&&(this.element.addEventListener("focus",this.handleFocus.bind(this)),this.element.addEventListener("blur",this.handleBlur.bind(this)))}getResolvedOptions(){return{decimalMaxLength:this.options.decimalMaxLength??_,decimalMinLength:this.options.decimalMinLength??z,formatOn:this.options.formatOn??Z,thousandSeparator:this.options.thousandSeparator??B,thousandStyle:this.options.thousandStyle??W,decimalSeparator:this.options.decimalSeparator??N,enableCompactNotation:this.options.enableCompactNotation??le,enableNegative:this.options.enableNegative??k,enableLeadingZeros:this.options.enableLeadingZeros??U,rawValueMode:this.options.rawValueMode??G,onChange:this.options.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 s=this.resolvedOptions.rawValueMode?this.rawValue:t;this.resolvedOptions.onChange(s)}}formatValueForDisplay(t){if(!t)return t;const{thousandSeparator:n,thousandStyle:s,enableLeadingZeros:o,decimalSeparator:r}=this.resolvedOptions;return n&&s!==m.None?y(t,n,s,o,r):t}handleChange(t){const{formatted:n,raw:s}=se(t,this.resolvedOptions.decimalMaxLength,this.caretPositionBeforeChange,this.buildFormattingOptions());this.caretPositionBeforeChange=void 0,this.handleValueChange(n,s)}handleKeyDown(t){const n=t.target,{selectionStart:s,selectionEnd:o}=n,r=this.buildFormattingOptions(),i=ne(t,{formatOn:r.formatOn,thousandSeparator:r.thousandSeparator,ThousandStyle:r.ThousandStyle,decimalSeparator:r.decimalSeparator});i?this.caretPositionBeforeChange={selectionStart:s??0,selectionEnd:o??0,endOffset:i.endOffset}:this.caretPositionBeforeChange={selectionStart:s??0,selectionEnd:o??0}}handlePaste(t){const{formatted:n,raw:s}=re(t,this.resolvedOptions.decimalMaxLength,this.buildFormattingOptions());this.handleValueChange(n,s);const o=new Event("input",{bubbles:!0,cancelable:!0});this.element.dispatchEvent(o)}handleFocus(t){if(this.resolvedOptions.formatOn===$.Blur&&this.resolvedOptions.thousandSeparator){const n=t.target;n.value=w(n.value,this.resolvedOptions.thousandSeparator)}}handleBlur(t){const n=t.target,{thousandSeparator:s,thousandStyle:o}=this.resolvedOptions;if(s&&o!==m.None&&n.value){n.value;const r=this.formatValueForDisplay(n.value);n.value=r;const i=this.resolvedOptions.rawValueMode?w(r,s):void 0;this.handleValueChange(r,i)}}getValue(){return this.resolvedOptions.rawValueMode?this.rawValue:this.element.value}setValue(t){if(this.resolvedOptions.rawValueMode){const n=this.resolvedOptions.thousandSeparator?w(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?w(t,this.resolvedOptions.thousandSeparator):t,s=this.resolvedOptions.decimalSeparator&&this.resolvedOptions.decimalSeparator!=="."?n.replace(new RegExp(x(this.resolvedOptions.decimalSeparator),"g"),"."):n;return parseFloat(s)}set valueAsNumber(t){if(isNaN(t)){this.setValue("");return}const n=t.toString();this.setValue(n)}}exports.FormatOn=$;exports.NumoraInput=ht;exports.ThousandStyle=m;exports.condenseDecimalZeros=Be;exports.formatInputValue=C;exports.formatLargeNumber=We;exports.formatLargePercent=ze;exports.formatPercent=_e;exports.formatValueForDisplay=Ve;exports.handleOnChangeNumoraInput=se;exports.handleOnKeyDownNumoraInput=ne;exports.handleOnPasteNumoraInput=re;exports.removeThousandSeparators=w;
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;