numora 3.0.1 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { FormatOn, ThousandStyle } from './types';
2
- export interface NumoraInputOptions extends Partial<Omit<HTMLInputElement, 'value' | 'defaultValue' | 'onchange'>> {
2
+ export interface NumoraInputOptions extends Partial<Omit<HTMLInputElement, 'value' | 'defaultValue' | 'onChange'>> {
3
3
  formatOn?: FormatOn;
4
4
  thousandSeparator?: string;
5
5
  thousandStyle?: ThousandStyle;
package/dist/index.d.ts CHANGED
@@ -6,3 +6,4 @@ export type { FormattingOptions, CaretPositionInfo } from './types';
6
6
  export { formatPercent, formatLargePercent } from './features/formatting/percent';
7
7
  export { formatLargeNumber, type FormatLargeNumberOptions } from './features/formatting/large-number';
8
8
  export { condenseDecimalZeros } from './features/formatting/subscript-notation';
9
+ export { removeThousandSeparators } from './features/sanitization';
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}`},L={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,L.thousand.size)}function me(e,t){if(e.length<=L.lakh.firstGroup)return e;const n=e.split("").reverse(),s=[],o=n.slice(0,L.lakh.firstGroup).reverse().join("");s.push(o);for(let r=L.lakh.firstGroup;r<n.length;r+=L.lakh.restGroup)s.push(n.slice(r,r+L.lakh.restGroup).reverse().join(""));return s.reverse().join(t)}function Se(e,t){return q(e,t,L.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 T(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=Ee(e,t,n,a.isCharacterEquivalent||H,r,a);if(p!==void 0)return p}if(l)return Le(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 Ee(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 Le(e,t,n,s,o,r,i,a,c,l={}){if(o)return ve(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=we(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 ve(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 we(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=T(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=T(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=T(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 Ae(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 Te(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);Ae(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 E={minScale:0,decimalsUnder:1e3,decimals:2,decimalsMin:0,decimalsMinAppliesToZero:!1,veryLargePlaceholder:"🔥",decimalSeparator:N};function We(e,t={}){const{minScale:n=E.minScale,decimalsUnder:s=E.decimalsUnder,decimals:o=E.decimals,decimalsMin:r=E.decimalsMin,decimalsMinAppliesToZero:i=E.decimalsMinAppliesToZero,veryLargePlaceholder:a=E.veryLargePlaceholder,decimalSeparator:c=E.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 A(c)}if(i<e.length){const a=s.slice(0,i),c=s.slice(i),l=`${a}.${c}`;return A(l)}return A(s)}function A(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=Te(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){const r=n.value,i=this.formatValueForDisplay(n.value);n.value=i;const a=this.resolvedOptions.rawValueMode?w(i,s):void 0;if(this.handleValueChange(i,a),r!==i){const c=new Event("input",{bubbles:!0,cancelable:!0});this.element.dispatchEvent(c);const l=new Event("change",{bubbles:!0,cancelable:!0});this.element.dispatchEvent(l)}}}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;
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;
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  var re = Object.defineProperty;
2
2
  var ie = (e, t, n) => t in e ? re(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var v = (e, t, n) => ie(e, typeof t != "symbol" ? t + "" : t, n);
4
- var $ = /* @__PURE__ */ ((e) => (e.Blur = "blur", e.Change = "change", e))($ || {}), S = /* @__PURE__ */ ((e) => (e.None = "none", e.Thousand = "thousand", e.Lakh = "lakh", e.Wan = "wan", e))(S || {});
5
- const _ = 2, z = 0, Z = $.Blur, B = ",", W = S.None, N = ".", oe = !1, k = !1, U = !1, G = !1;
3
+ var w = (e, t, n) => ie(e, typeof t != "symbol" ? t + "" : t, n);
4
+ var m = /* @__PURE__ */ ((e) => (e.Blur = "blur", e.Change = "change", e))(m || {}), S = /* @__PURE__ */ ((e) => (e.None = "none", e.Thousand = "thousand", e.Lakh = "lakh", e.Wan = "wan", e))(S || {});
5
+ const _ = 2, z = 0, Z = m.Blur, B = ",", W = S.None, N = ".", oe = !1, k = !1, U = !1, G = !1;
6
6
  function T(e) {
7
7
  return {
8
8
  decimalSeparator: (e == null ? void 0 : e.decimalSeparator) ?? N,
@@ -70,8 +70,8 @@ function y(e, t, n = S.Thousand, s = !1, o = ".") {
70
70
  if (f) {
71
71
  const d = f[1], g = c.slice(d.length);
72
72
  if (g) {
73
- const p = j(g, t, n), m = d + p, D = i ? "-" : "";
74
- return r ? l ? `${D}${m}${o}${l}` : `${D}${m}${o}` : `${D}${m}`;
73
+ const p = j(g, t, n), $ = d + p, D = i ? "-" : "";
74
+ return r ? l ? `${D}${$}${o}${l}` : `${D}${$}${o}` : `${D}${$}`;
75
75
  }
76
76
  }
77
77
  }
@@ -116,7 +116,7 @@ function q(e, t, n) {
116
116
  return o.reverse().join(t);
117
117
  }
118
118
  function pe(e, t, n) {
119
- return (t == null ? void 0 : t.formatOn) === $.Change && t.thousandSeparator ? y(
119
+ return (t == null ? void 0 : t.formatOn) === m.Change && t.thousandSeparator ? y(
120
120
  e,
121
121
  t.thousandSeparator,
122
122
  t.ThousandStyle ?? S.None,
@@ -158,7 +158,7 @@ function A(e, t, n, s = ".") {
158
158
  function Q(e, t, n) {
159
159
  return t < 0 || t >= e.length ? !1 : e[t] === n;
160
160
  }
161
- function me(e, t = {}) {
161
+ function $e(e, t = {}) {
162
162
  const {
163
163
  thousandSeparator: n,
164
164
  decimalSeparator: s = ".",
@@ -189,7 +189,7 @@ function I(e, t, n, s) {
189
189
  return (t === -1 || t > o) && (t = o), t;
190
190
  }
191
191
  const H = (e, t) => e === t;
192
- function $e(e, t, n, s, o, r, i = ".", a = {}) {
192
+ function me(e, t, n, s, o, r, i = ".", a = {}) {
193
193
  if (n < 0)
194
194
  return 0;
195
195
  if (n > e.length || e === "" || t === "")
@@ -227,7 +227,7 @@ function $e(e, t, n, s, o, r, i = ".", a = {}) {
227
227
  i,
228
228
  a
229
229
  );
230
- const g = ve(
230
+ const g = we(
231
231
  e,
232
232
  t,
233
233
  n,
@@ -303,7 +303,7 @@ function Ne(e, t, n, s, o, r, i, a, c, l = {}) {
303
303
  r,
304
304
  a,
305
305
  c
306
- ), p = r === -1 || n <= r, m = Le(
306
+ ), p = r === -1 || n <= r, $ = Le(
307
307
  t,
308
308
  g,
309
309
  s,
@@ -313,7 +313,7 @@ function Ne(e, t, n, s, o, r, i, a, c, l = {}) {
313
313
  p,
314
314
  i
315
315
  );
316
- return l.boundary ? I(t, m, l.boundary) : m;
316
+ return l.boundary ? I(t, $, l.boundary) : $;
317
317
  }
318
318
  function De(e, t, n, s, o, r) {
319
319
  const i = n + 1;
@@ -398,7 +398,7 @@ function Le(e, t, n, s, o, r, i, a) {
398
398
  }
399
399
  return c;
400
400
  }
401
- function ve(e, t, n, s, o, r) {
401
+ function we(e, t, n, s, o, r) {
402
402
  const i = n >= e.length, a = b(
403
403
  e,
404
404
  n,
@@ -428,7 +428,7 @@ function ve(e, t, n, s, o, r) {
428
428
  );
429
429
  return o && !Q(t, f, s) ? Math.max(0, f - 1) : f;
430
430
  }
431
- function we(e, t, n) {
431
+ function ve(e, t, n) {
432
432
  const { selectionStart: s, selectionEnd: o, endOffset: r = 0 } = e;
433
433
  if (s !== o) {
434
434
  const h = o - s;
@@ -493,7 +493,7 @@ function xe(e) {
493
493
  return Math.max(e.selectionStart, e.selectionEnd);
494
494
  }
495
495
  function Ce(e, t, n) {
496
- if ((n == null ? void 0 : n.formatOn) !== $.Change || !n.thousandSeparator)
496
+ if ((n == null ? void 0 : n.formatOn) !== m.Change || !n.thousandSeparator)
497
497
  return;
498
498
  const { selectionStart: s, selectionEnd: o, value: r } = t;
499
499
  if (s === null || o === null || s !== o)
@@ -504,20 +504,20 @@ function Ce(e, t, n) {
504
504
  function Ae(e, t, n, s, o, r, i) {
505
505
  if (!o) return;
506
506
  const { selectionStart: a = 0, selectionEnd: c = 0, endOffset: l = 0 } = o;
507
- let h = we(
507
+ let h = ve(
508
508
  { selectionStart: a, selectionEnd: c, endOffset: l },
509
509
  t,
510
510
  n
511
511
  );
512
512
  if (h || (h = ye(t, n)), !h) return;
513
- const u = me(n, {
513
+ const u = $e(n, {
514
514
  thousandSeparator: (i == null ? void 0 : i.thousandSeparator) ?? r.thousandSeparator,
515
515
  decimalSeparator: r.decimalSeparator
516
516
  }), f = {
517
517
  thousandSeparator: (i == null ? void 0 : i.thousandSeparator) ?? r.thousandSeparator,
518
518
  isCharacterEquivalent: H,
519
519
  boundary: u
520
- }, d = (i == null ? void 0 : i.thousandSeparator) ?? r.thousandSeparator ?? ",", g = (i == null ? void 0 : i.ThousandStyle) ?? S.None, p = $e(
520
+ }, d = (i == null ? void 0 : i.thousandSeparator) ?? r.thousandSeparator ?? ",", g = (i == null ? void 0 : i.ThousandStyle) ?? S.None, p = me(
521
521
  t,
522
522
  n,
523
523
  s,
@@ -529,11 +529,11 @@ function Ae(e, t, n, s, o, r, i) {
529
529
  );
530
530
  Me(e, p, n);
531
531
  }
532
- function V(e) {
532
+ function X(e) {
533
533
  const [t, n = ""] = e.split(".");
534
534
  return t.length + n.length > 30;
535
535
  }
536
- function X(e, t) {
536
+ function Y(e, t) {
537
537
  const n = e.replace(".", ""), s = t.replace(".", ""), o = Math.max(n.length, s.length), r = n.padStart(o, "0"), i = s.padStart(o, "0");
538
538
  for (let a = 0; a < o; a++) {
539
539
  const c = parseInt(r[a], 10), l = parseInt(i[a], 10);
@@ -564,7 +564,7 @@ const Te = [
564
564
  { suffix: "k", zeros: 3 }
565
565
  // Thousand
566
566
  ];
567
- function Y(e, t, n = 0) {
567
+ function V(e, t, n = 0) {
568
568
  const [s, o = ""] = e.split(t), r = s.replace(/^0+/, "") || "0";
569
569
  for (const i of Te)
570
570
  if (i.zeros >= n && (r.length > i.zeros || r.length === i.zeros && o.length > 0)) {
@@ -678,13 +678,13 @@ function at(e, t = 2, n = {}) {
678
678
  if (F(e, i))
679
679
  return "0%";
680
680
  const { isNegative: l, absoluteValue: h } = ee(e), u = te(h, i);
681
- if (V(u))
681
+ if (X(u))
682
682
  return o;
683
- const { scaledValue: f, scaleSuffix: d } = Y(u, i), p = X(f, r.toString()) < 0 ? t : 0;
684
- let m = f;
685
- a && c !== S.None && (m = y(f, a, c, !1, i));
683
+ const { scaledValue: f, scaleSuffix: d } = V(u, i), p = Y(f, r.toString()) < 0 ? t : 0;
684
+ let $ = f;
685
+ a && c !== S.None && ($ = y(f, a, c, !1, i));
686
686
  const D = P(
687
- m,
687
+ $,
688
688
  p,
689
689
  p,
690
690
  i,
@@ -710,8 +710,8 @@ function ct(e, t = 8, n = N) {
710
710
  let d = `0${f}${h}`;
711
711
  const g = f.length, p = Math.max(0, t - g - 1);
712
712
  h.length > p && (d = `0${f}${h.slice(0, p)}`), d = d.replace(/0+$/, "");
713
- const m = r === "0" ? d : `${r}${d}`;
714
- return s ? `-${m}` : m;
713
+ const $ = r === "0" ? d : `${r}${d}`;
714
+ return s ? `-${$}` : $;
715
715
  }
716
716
  const E = {
717
717
  minScale: 0,
@@ -737,13 +737,13 @@ function lt(e, t = {}) {
737
737
  if (!e || e === "0" || e === c || e === "-" || e === `-${c}`)
738
738
  return i && r > 0 ? `0${c}${"0".repeat(r)}` : "0";
739
739
  const u = e.startsWith("-"), f = u ? e.slice(1) : e;
740
- if (V(f))
740
+ if (X(f))
741
741
  return a;
742
- const { scaledValue: d, scaleSuffix: g } = Y(
742
+ const { scaledValue: d, scaleSuffix: g } = V(
743
743
  f,
744
744
  c,
745
745
  n
746
- ), m = X(d, s.toString()) < 0 ? o : 0;
746
+ ), $ = Y(d, s.toString()) < 0 ? o : 0;
747
747
  let D = d;
748
748
  l && h !== S.None && (D = y(
749
749
  d,
@@ -754,7 +754,7 @@ function lt(e, t = {}) {
754
754
  ));
755
755
  const R = P(
756
756
  D,
757
- m,
757
+ $,
758
758
  r,
759
759
  c,
760
760
  i,
@@ -908,13 +908,13 @@ function Be(e) {
908
908
  function We(e) {
909
909
  return e.replace(/[\u00A0\u2000-\u200B\u202F\u205F\u3000]/g, " ").replace(/\s/g, "");
910
910
  }
911
- function w(e, t) {
911
+ function v(e, t) {
912
912
  const n = x(t);
913
913
  return e.replace(new RegExp(n, "g"), "");
914
914
  }
915
915
  const ke = (e, t) => {
916
916
  let n = We(e);
917
- return t != null && t.thousandSeparator && (n = w(n, t.thousandSeparator)), t != null && t.enableCompactNotation && (n = Ze(n)), n = Re(n), n = Oe(
917
+ return t != null && t.thousandSeparator && (n = v(n, t.thousandSeparator)), t != null && t.enableCompactNotation && (n = Ze(n)), n = Re(n), n = Oe(
918
918
  n,
919
919
  t == null ? void 0 : t.enableNegative,
920
920
  t == null ? void 0 : t.decimalSeparator
@@ -930,7 +930,7 @@ function Ue(e, t, n) {
930
930
  };
931
931
  }
932
932
  function O(e, t, n, s) {
933
- const o = T(n), r = s ?? (n == null ? void 0 : n.formatOn) === $.Change, i = ke(
933
+ const o = T(n), r = s ?? (n == null ? void 0 : n.formatOn) === m.Change, i = ke(
934
934
  e,
935
935
  Ue(n, o, r)
936
936
  ), a = le(
@@ -970,7 +970,7 @@ function je(e, t) {
970
970
  return Ce(e, s, t), Ge(e.key, s.selectionStart, s.selectionEnd);
971
971
  }
972
972
  function Je(e, t, n, s) {
973
- const o = e.target, r = o.value, i = xe(o), a = T(s), c = (s == null ? void 0 : s.formatOn) === $.Change, { formatted: l, raw: h } = O(
973
+ const o = e.target, r = o.value, i = xe(o), a = T(s), c = (s == null ? void 0 : s.formatOn) === m.Change, { formatted: l, raw: h } = O(
974
974
  r,
975
975
  t,
976
976
  s,
@@ -1013,9 +1013,9 @@ function Qe(e, t) {
1013
1013
  return t ? `^-?[0-9]*[${n}]?[0-9]*$` : `^[0-9]*[${n}]?[0-9]*$`;
1014
1014
  }
1015
1015
  function He(e) {
1016
- Ve(e.decimalMaxLength), Xe(e.decimalMinLength), Ye(e.decimalMinLength, e.decimalMaxLength), Fe(e.formatOn), et(e.thousandSeparator), tt(e.thousandStyle), nt(e.decimalSeparator), st(e.thousandSeparator, e.decimalSeparator), M("enableCompactNotation", e.enableCompactNotation), M("enableNegative", e.enableNegative), M("enableLeadingZeros", e.enableLeadingZeros), M("rawValueMode", e.rawValueMode), rt(e.onChange);
1016
+ Xe(e.decimalMaxLength), Ye(e.decimalMinLength), Ve(e.decimalMinLength, e.decimalMaxLength), Fe(e.formatOn), et(e.thousandSeparator), tt(e.thousandStyle), nt(e.decimalSeparator), st(e.thousandSeparator, e.decimalSeparator), M("enableCompactNotation", e.enableCompactNotation), M("enableNegative", e.enableNegative), M("enableLeadingZeros", e.enableLeadingZeros), M("rawValueMode", e.rawValueMode), rt(e.onChange);
1017
1017
  }
1018
- function Ve(e) {
1018
+ function Xe(e) {
1019
1019
  if (e !== void 0) {
1020
1020
  if (typeof e != "number")
1021
1021
  throw new Error(
@@ -1031,7 +1031,7 @@ function Ve(e) {
1031
1031
  );
1032
1032
  }
1033
1033
  }
1034
- function Xe(e) {
1034
+ function Ye(e) {
1035
1035
  if (e !== void 0) {
1036
1036
  if (typeof e != "number")
1037
1037
  throw new Error(
@@ -1047,16 +1047,16 @@ function Xe(e) {
1047
1047
  );
1048
1048
  }
1049
1049
  }
1050
- function Ye(e, t) {
1050
+ function Ve(e, t) {
1051
1051
  if (!(e === void 0 || t === void 0) && e > t)
1052
1052
  throw new Error(
1053
1053
  `decimalMinLength (${e}) cannot be greater than decimalMaxLength (${t}).`
1054
1054
  );
1055
1055
  }
1056
1056
  function Fe(e) {
1057
- if (e !== void 0 && e !== $.Blur && e !== $.Change)
1057
+ if (e !== void 0 && e !== m.Blur && e !== m.Change)
1058
1058
  throw new Error(
1059
- `formatOn must be either ${$.Blur} or ${$.Change}. Received: ${JSON.stringify(e)}`
1059
+ `formatOn must be either ${m.Blur} or ${m.Change}. Received: ${JSON.stringify(e)}`
1060
1060
  );
1061
1061
  }
1062
1062
  function et(e) {
@@ -1130,11 +1130,11 @@ class ut {
1130
1130
  onChange: f,
1131
1131
  ...d
1132
1132
  }) {
1133
- v(this, "element");
1134
- v(this, "options");
1135
- v(this, "resolvedOptions");
1136
- v(this, "rawValue", "");
1137
- v(this, "caretPositionBeforeChange");
1133
+ w(this, "element");
1134
+ w(this, "options");
1135
+ w(this, "resolvedOptions");
1136
+ w(this, "rawValue", "");
1137
+ w(this, "caretPositionBeforeChange");
1138
1138
  if (He({
1139
1139
  decimalMaxLength: n,
1140
1140
  decimalMinLength: s,
@@ -1161,7 +1161,7 @@ class ut {
1161
1161
  rawValueMode: u,
1162
1162
  ...d
1163
1163
  }, this.resolvedOptions = this.getResolvedOptions(), this.createInputElement(t), this.setupEventListeners(), this.resolvedOptions.rawValueMode && this.element.value) {
1164
- const g = this.element.value, p = this.resolvedOptions.thousandSeparator ? w(g, this.resolvedOptions.thousandSeparator) : g;
1164
+ const g = this.element.value, p = this.resolvedOptions.thousandSeparator ? v(g, this.resolvedOptions.thousandSeparator) : g;
1165
1165
  this.rawValue = p, this.element.value = this.formatValueForDisplay(p);
1166
1166
  } else if (this.element.value) {
1167
1167
  const g = this.element.value;
@@ -1188,7 +1188,7 @@ class ut {
1188
1188
  value: d,
1189
1189
  defaultValue: g,
1190
1190
  type: p,
1191
- inputMode: m,
1191
+ inputMode: $,
1192
1192
  spellcheck: D,
1193
1193
  autocomplete: R,
1194
1194
  ...ne
@@ -1196,7 +1196,7 @@ class ut {
1196
1196
  Object.assign(this.element, ne), d !== void 0 ? this.element.value = d : g !== void 0 && (this.element.defaultValue = g, this.element.value = g), t.appendChild(this.element);
1197
1197
  }
1198
1198
  setupEventListeners() {
1199
- 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)));
1199
+ 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 === m.Blur && this.resolvedOptions.thousandSeparator && (this.element.addEventListener("focus", this.handleFocus.bind(this)), this.element.addEventListener("blur", this.handleBlur.bind(this)));
1200
1200
  }
1201
1201
  getResolvedOptions() {
1202
1202
  return {
@@ -1276,23 +1276,19 @@ class ut {
1276
1276
  this.element.dispatchEvent(o);
1277
1277
  }
1278
1278
  handleFocus(t) {
1279
- if (this.resolvedOptions.formatOn === $.Blur && this.resolvedOptions.thousandSeparator) {
1279
+ if (this.resolvedOptions.formatOn === m.Blur && this.resolvedOptions.thousandSeparator) {
1280
1280
  const n = t.target;
1281
- n.value = w(n.value, this.resolvedOptions.thousandSeparator);
1281
+ n.value = v(n.value, this.resolvedOptions.thousandSeparator);
1282
1282
  }
1283
1283
  }
1284
1284
  handleBlur(t) {
1285
1285
  const n = t.target, { thousandSeparator: s, thousandStyle: o } = this.resolvedOptions;
1286
1286
  if (s && o !== S.None && n.value) {
1287
- const r = n.value, i = this.formatValueForDisplay(n.value);
1288
- n.value = i;
1289
- const a = this.resolvedOptions.rawValueMode ? w(i, s) : void 0;
1290
- if (this.handleValueChange(i, a), r !== i) {
1291
- const c = new Event("input", { bubbles: !0, cancelable: !0 });
1292
- this.element.dispatchEvent(c);
1293
- const l = new Event("change", { bubbles: !0, cancelable: !0 });
1294
- this.element.dispatchEvent(l);
1295
- }
1287
+ n.value;
1288
+ const r = this.formatValueForDisplay(n.value);
1289
+ n.value = r;
1290
+ const i = this.resolvedOptions.rawValueMode ? v(r, s) : void 0;
1291
+ this.handleValueChange(r, i);
1296
1292
  }
1297
1293
  }
1298
1294
  getValue() {
@@ -1300,7 +1296,7 @@ class ut {
1300
1296
  }
1301
1297
  setValue(t) {
1302
1298
  if (this.resolvedOptions.rawValueMode) {
1303
- const n = this.resolvedOptions.thousandSeparator ? w(t, this.resolvedOptions.thousandSeparator) : t;
1299
+ const n = this.resolvedOptions.thousandSeparator ? v(t, this.resolvedOptions.thousandSeparator) : t;
1304
1300
  this.rawValue = n, this.element.value = this.formatValueForDisplay(n);
1305
1301
  } else
1306
1302
  this.element.value = t;
@@ -1348,7 +1344,7 @@ class ut {
1348
1344
  const t = this.getValue();
1349
1345
  if (!t)
1350
1346
  return NaN;
1351
- 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;
1347
+ const n = this.resolvedOptions.thousandSeparator ? v(t, this.resolvedOptions.thousandSeparator) : t, s = this.resolvedOptions.decimalSeparator && this.resolvedOptions.decimalSeparator !== "." ? n.replace(new RegExp(x(this.resolvedOptions.decimalSeparator), "g"), ".") : n;
1352
1348
  return parseFloat(s);
1353
1349
  }
1354
1350
  /**
@@ -1364,7 +1360,7 @@ class ut {
1364
1360
  }
1365
1361
  }
1366
1362
  export {
1367
- $ as FormatOn,
1363
+ m as FormatOn,
1368
1364
  ut as NumoraInput,
1369
1365
  S as ThousandStyle,
1370
1366
  ct as condenseDecimalZeros,
@@ -1375,5 +1371,6 @@ export {
1375
1371
  ht as formatValueForDisplay,
1376
1372
  Je as handleOnChangeNumoraInput,
1377
1373
  je as handleOnKeyDownNumoraInput,
1378
- qe as handleOnPasteNumoraInput
1374
+ qe as handleOnPasteNumoraInput,
1375
+ v as removeThousandSeparators
1379
1376
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "numora",
3
- "version": "3.0.1",
3
+ "version": "3.0.2",
4
4
  "description": "Precision-first numeric input library for DeFi and financial applications",
5
5
  "homepage": "https://numora.xyz/",
6
6
  "main": "dist/index.js",