numora 3.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,7 @@ export declare function getSeparators(options: SeparatorOptions | FormattingOpti
6
6
  /**
7
7
  * Handles keyboard events for decimal separators, converting comma/dot and preventing duplicates.
8
8
  */
9
- export declare function handleDecimalSeparatorKey(e: KeyboardEvent, inputElement: HTMLInputElement, formattingOptions: FormattingOptions | undefined, decimalSeparator: string): boolean;
9
+ export declare function handleDecimalSeparatorKey(e: KeyboardEvent, inputElement: HTMLInputElement, decimalSeparator: string): boolean;
10
10
  /**
11
11
  * Trims decimals to a maximum length.
12
12
  */
package/dist/index.d.ts CHANGED
@@ -3,3 +3,6 @@ export { ThousandStyle, FormatOn } from './types';
3
3
  export { handleOnChangeNumoraInput, handleOnPasteNumoraInput, handleOnKeyDownNumoraInput, } from './utils/event-handlers';
4
4
  export { formatValueForDisplay, formatInputValue, } from './utils/format-utils';
5
5
  export type { FormattingOptions, CaretPositionInfo } from './types';
6
+ export { formatPercent, formatLargePercent } from './features/formatting/percent';
7
+ export { formatLargeNumber, type FormatLargeNumberOptions } from './features/formatting/large-number';
8
+ export { condenseDecimalZeros } from './features/formatting/subscript-notation';
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var V=Object.defineProperty;var F=(e,t,n)=>t in e?V(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var $=(e,t,n)=>F(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var b=(e=>(e.Blur="blur",e.Change="change",e))(b||{}),S=(e=>(e.None="none",e.Thousand="thousand",e.Lakh="lakh",e.Wan="wan",e))(S||{});const x=2,O=0,R=b.Blur,_=",",B=S.None,E=".",ee=!1,P=!1,W=!1,k=!1;function I(e){return{decimalSeparator:(e==null?void 0:e.decimalSeparator)??E,thousandSeparator:e==null?void 0:e.thousandSeparator}}function U(e,t){const n=e.startsWith("-"),r=n?e.slice(1):e,[s="",i=""]=r.split(t);return{sign:n?"-":"",integer:s,decimal:i}}function te(e,t){if(!e.value.includes(t))return!1;const{selectionStart:n,selectionEnd:r,value:s}=e;return!s.slice(n??0,r??0).includes(t)}function ne(e,t,n,r){const{key:s}=e;if(s!==","&&s!==".")return!1;if(te(t,r))return!0;if(s!==r){const{selectionStart:i,selectionEnd:a,value:o}=t,c=i??0,l=a??c;t.value=o.slice(0,c)+r+o.slice(l);const h=c+1;return t.setSelectionRange(h,h),!0}return!1}const re=(e,t,n=E)=>{const{sign:r,integer:s,decimal:i}=U(e,n);if(!e.includes(n))return e;const o=i.slice(0,t);return`${r}${s}${n}${o}`},ie=(e,t=E)=>{const n=e.indexOf(t);if(n===-1)return e;const r=e.slice(0,n+1),i=e.slice(n+1).split(",").join("").split(".").join("").split(t).join("");return r+i},se=(e,t=0,n=E)=>{if(t<=0)return e;const{sign:r,integer:s,decimal:i}=U(e,n);if(i.length>=t)return e.includes(n)?e:`${r}${s}${n}${i}`;const a=i.padEnd(t,"0");return`${r}${s}${n}${a}`},N={thousand:{size:3},lakh:{firstGroup:3,restGroup:2},wan:{size:4}};function j(e,t,n=S.Thousand,r=!1,s="."){if(!e||e==="0"||e===s||e==="-"||e===`-${s}`)return e;const i=e.includes(s),a=e.startsWith("-"),o=a?e.slice(1):e,[c,l]=o.split(s);if(!c){const u=l?`${s}${l}`:o;return a?`-${u}`:u}if(r&&c.startsWith("0")&&c.length>1){const u=c.match(/^(0+)/);if(u){const g=u[1],f=c.slice(g.length);if(f){const p=Z(f,t,n),m=g+p,w=a?"-":"";return i?l?`${w}${m}${s}${l}`:`${w}${m}${s}`:`${w}${m}`}}}const h=Z(c,t,n),d=a?"-":"";return i?l?`${d}${h}${s}${l}`:`${d}${h}${s}`:`${d}${h}`}function Z(e,t,n){if(e==="0"||e==="")return e;switch(n){case S.None:return e;case S.Thousand:return ae(e,t);case S.Lakh:return oe(e,t);case S.Wan:return ce(e,t);default:return e}}function ae(e,t){return z(e,t,N.thousand.size)}function oe(e,t){if(e.length<=N.lakh.firstGroup)return e;const n=e.split("").reverse(),r=[],s=n.slice(0,N.lakh.firstGroup).reverse().join("");r.push(s);for(let i=N.lakh.firstGroup;i<n.length;i+=N.lakh.restGroup)r.push(n.slice(i,i+N.lakh.restGroup).reverse().join(""));return r.reverse().join(t)}function ce(e,t){return z(e,t,N.wan.size)}function z(e,t,n){const r=e.split("").reverse(),s=[];for(let i=0;i<r.length;i+=n)s.push(r.slice(i,i+n).reverse().join(""));return s.reverse().join(t)}function le(e,t,n){return(t==null?void 0:t.formatOn)==="change"&&t.thousandSeparator?j(e,t.thousandSeparator,t.ThousandStyle??S.None,t.enableLeadingZeros,(n==null?void 0:n.decimalSeparator)??E):e}function v(e,t,n,r="."){let s=0;for(let i=0;i<t&&i<e.length;i++)e[i]!==n&&s++;return s}function he(e,t,n,r="."){if(t===0)return 0;let s=0;for(let i=0;i<e.length;i++)if(e[i]!==n){if(s===t-1)return i+1;s++}return e.length}function A(e,t,n,r="."){if(t===0)return 0;let s=0;for(let i=0;i<e.length;i++)if(e[i]!==n){if(s++,s===t)return i+1;if(s>t)return i}return e.length}function J(e,t,n){return t<0||t>=e.length?!1:e[t]===n}function ue(e,t={}){const{thousandSeparator:n,decimalSeparator:r=".",prefix:s="",suffix:i=""}=t,a=Array.from({length:e.length+1}).map(()=>!0);if(s&&a.fill(!1,0,s.length),i){const o=e.length-i.length;a.fill(!1,o+1,e.length+1)}for(let o=0;o<e.length;o++){const c=e[o];(n&&c===n||c===r)&&(a[o]=!1,o+1<e.length&&!/\d/.test(e[o+1])&&(a[o+1]=!1))}return a.some(o=>o)||a.fill(!0),a}function T(e,t,n,r){const s=e.length;if(t=Math.max(0,Math.min(t,s)),!n[t]){let i=t;for(;i<=s&&!n[i];)i++;let a=t;for(;a>=0&&!n[a];)a--;i<=s&&a>=0?t=t-a<i-t?a:i:i<=s?t=i:a>=0&&(t=a)}return(t===-1||t>s)&&(t=s),t}const K=(e,t)=>e===t;function de(e,t,n,r,s,i,a=".",o={}){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=J(e,n,r),d=e.indexOf(a),u=t.indexOf(a);if(o.isCharacterEquivalent&&e!==t){const p=fe(e,t,n,o.isCharacterEquivalent||K,i,o);if(p!==void 0)return p}if(l)return ge(e,t,n,r,h,d,u,i,a,o);const f=ve(e,t,n,r,h,a);return o.boundary?T(t,f,o.boundary):f}function fe(e,t,n,r,s,i){const a=e.length,o=t.length,c={},l=new Array(a);for(let f=0;f<a;f++){l[f]=-1;for(let p=0;p<o;p++){if(c[p])continue;if(r(e[f],t[p],{oldValue:e,newValue:t,typedRange:s,oldIndex:f,newIndex:p})){l[f]=p,c[p]=!0;break}}}let h=n;for(;h<a&&(l[h]===-1||!/\d/.test(e[h]));)h++;const d=h===a||l[h]===-1?o:l[h];for(h=n-1;h>=0&&l[h]===-1;)h--;const u=h===-1||l[h]===-1?0:l[h]+1;if(u>d)return d;const g=n-u<d-n?u:d;return i.boundary?T(t,g,i.boundary):g}function ge(e,t,n,r,s,i,a,o,c,l={}){if(s)return pe(e,t,n,r,a,c);const h=v(e,n,r,c),d=v(e,e.length,r,c),u=v(t,t.length,r,c),g=d-u,f=Se(e,n,r,h,g,i,o,c),p=i===-1||n<=i,m=be(t,f,r,g,o,c,p,a);return l.boundary?T(t,m,l.boundary):m}function pe(e,t,n,r,s,i){const a=n+1;if(a<e.length){const o=v(e,a,r,i),c=he(t,o,r,i);return c<t.length&&t[c]!==r?c+1:c}return n}function Se(e,t,n,r,s,i,a,o){if(a){const{start:l,isDelete:h}=a;return h?v(e,l,n,o):Math.max(0,v(e,l,n,o))}return t>0&&e[t-1]===n&&s>0?r+1:r}function be(e,t,n,r,s,i,a,o){if(a&&o!==-1){const l=e.substring(0,o),h=v(l,l.length,n,i);if(t<=h){const d=A(l,t,n,i);if(d>0&&d<l.length&&v(l,d,n,i)===t){if(l[d]===n&&s&&r>0&&d<l.length-1)return d+1;if(!s&&r>0&&d<l.length-1)return Math.min(d+1,l.length)}return d}}const c=A(e,t,n,i);if(c>0&&c<e.length&&v(e,c,n,i)===t){if(e[c]===n&&s&&r>0&&c<e.length-1)return c+1;if(!s&&r>0&&c<e.length-1)return Math.min(c+1,e.length)}return c}function ve(e,t,n,r,s,i){const a=n>=e.length,o=v(e,n,r,i),c=v(e,e.length,r,i),l=v(t,t.length,r,i);if(a||o===c)return t.length;const h=l-c;let d=o;h>0&&!a&&o<c&&(d=o+1);const u=A(t,d,r,i);return s&&!J(t,u,r)?Math.max(0,u-1):u}function me(e,t,n){const{selectionStart:r,selectionEnd:s,endOffset:i=0}=e;if(r!==s){const h=s-r;return{start:r,end:s,deletedLength:h,isDelete:!1}}if(i>0){const h=i;return{start:r,end:r+h,deletedLength:h,isDelete:!0}}const o=t.length,c=n.length,l=o-c;if(!(l<=0))return{start:r,end:r+l,deletedLength:l,isDelete:!1}}function Ee(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,s=t.length-1;for(;r>=n&&s>=n&&e[r]===t[s];)r--,s--;const i=r-n+1,a=s-n+1;if(!(i===0&&a===0))return{start:n,end:r+1,deletedLength:i,isDelete:i>a}}function G(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 Ne(e,t,n){return e.selectionStart===0&&e.selectionEnd===e.value.length?null:(G(e,t),setTimeout(()=>{e.value===n&&e.selectionStart!==t&&G(e,t)},0))}function $e(e){return Math.max(e.selectionStart,e.selectionEnd)}function Le(e,t,n){if((n==null?void 0:n.formatOn)!==b.Change||!n.thousandSeparator)return;const{selectionStart:r,selectionEnd:s,value:i}=t;if(r===null||s===null||r!==s)return;const{key:a}=e,o=n.thousandSeparator;a==="Backspace"&&r>0&&i[r-1]===o&&t.setSelectionRange(r-1,r-1),a==="Delete"&&i[r]===o&&t.setSelectionRange(r+1,r+1)}function we(e,t,n,r,s,i,a){if(!s)return;const{selectionStart:o=0,selectionEnd:c=0,endOffset:l=0}=s;let h=me({selectionStart:o,selectionEnd:c,endOffset:l},t,n);if(h||(h=Ee(t,n)),!h)return;const d=ue(n,{thousandSeparator:(a==null?void 0:a.thousandSeparator)??i.thousandSeparator,decimalSeparator:i.decimalSeparator}),u={thousandSeparator:(a==null?void 0:a.thousandSeparator)??i.thousandSeparator,isCharacterEquivalent:K,boundary:d},g=(a==null?void 0:a.thousandSeparator)??i.thousandSeparator??",",f=(a==null?void 0:a.ThousandStyle)??S.None,p=de(t,n,r,g,f,h,i.decimalSeparator,u);Ne(e,p,n)}function M(e){return e.replace(/[-[\]/{}()*+?.\\^$|]/g,"\\$&")}const De=(e,t=!1,n=".")=>{const r=M(n),s=new RegExp(`[^0-9${r}]`,"g");if(!t)return e.replace(s,"");const i=e.startsWith("-"),a=e.replace(s,"");if(i){if(a.length>0)return"-"+a;if(e==="-")return"-"}return a};function Me(e){const t=/([+-]?\d+\.?\d*)[eE]([+-]?\d+)/g;let n=e,r;const s=[];for(;(r=t.exec(e))!==null;){const i=r[0],a=r[1],o=parseInt(r[2],10);let c;if(o===0)c=a;else{const l=a.startsWith("-"),h=l?a.slice(1):a,[d,u=""]=h.split(".");o>0?c=ye(d,u,o):c=Ce(d,u,Math.abs(o)),l&&(c="-"+c)}s.push({full:i,expanded:c})}for(const{full:i,expanded:a}of s)n=n.replace(i,a);return n}function ye(e,t,n){const r=e+t;if(r==="0"||r.match(/^0+$/))return"0";const s=t.length;if(n<=s){const a=r.slice(0,e.length+n),o=r.slice(e.length+n);return o?`${a}.${o}`:a}const i=n-s;return r+"0".repeat(i)}function Ce(e,t,n){const r=e+t;if(r==="0"||r.match(/^0+$/))return"0";const a=e.length-n;if(a<=0){const o=Math.abs(a),c=`0.${"0".repeat(o)}${r}`;return C(c)}if(a<e.length){const o=r.slice(0,a),c=r.slice(a),l=`${o}.${c}`;return C(l)}return C(r)}function C(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 Ae(e){const t=/(\d+\.?\d*)\s*(Qa|Qi|Sx|Sp|[kmbMTO]|N)/gi;return e.replace(t,(n,r,s)=>{const i={k:3,K:3,m:6,M:6,b:9,B:9,T:12,t:12};let a;if(s.length>1){const g=s.charAt(0).toUpperCase()+s.slice(1).toLowerCase();a=i[s]||i[g]}else{const g=s.toLowerCase();a=i[s]||i[g]}if(!a)return n;const o=r.startsWith("-"),c=o?r.slice(1):r,[l,h=""]=c.split("."),d=l.replace(/^0+/,"")||"0";let u;if(h.length===0)u=d+"0".repeat(a);else if(h.length<=a){const g=a-h.length;u=d+h+"0".repeat(g)}else{const g=h.slice(0,a),f=h.slice(a);u=d+g+"."+f}return u=u.replace(/^(-?)0+([1-9])/,"$1$2"),u.match(/^-?0+$/)&&(u=o?"-0":"0"),u.includes(".")&&(u=u.replace(/\.?0+$/,"")),o&&!u.startsWith("-")?"-"+u:u})}function Ie(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[s,i]=n.split(".");if(s&&s.length>0){const o=(s.replace(/^0+/,"")||"0")+"."+i;return t?"-"+o:o}return e}if(n.startsWith("0")&&n.length>1){const s=n.replace(/^0+/,"")||"0";return t?"-"+s:s}return e}function Te(e){return e.replace(/[\u00A0\u2000-\u200B\u202F\u205F\u3000]/g," ").replace(/\s/g,"")}function L(e,t){const n=M(t);return e.replace(new RegExp(n,"g"),"")}const xe=(e,t)=>{let n=Te(e);return t!=null&&t.thousandSeparator&&(n=L(n,t.thousandSeparator)),t!=null&&t.enableCompactNotation&&(n=Ae(n)),n=Me(n),n=De(n,t==null?void 0:t.enableNegative,t==null?void 0:t.decimalSeparator),n=ie(n,(t==null?void 0:t.decimalSeparator)||E),t!=null&&t.enableLeadingZeros||(n=Ie(n)),n};function Oe(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 y(e,t,n,r){const s=I(n),i=r??(n==null?void 0:n.formatOn)===b.Change,a=xe(e,Oe(n,s,i)),o=re(a,t,s.decimalSeparator),c=(n==null?void 0:n.decimalMinLength)??0,l=se(o,c,s.decimalSeparator),h=l;return{formatted:le(l,n,s),raw:h}}function Re(e,t,n){const r=!!(n!=null&&n.thousandSeparator);return y(e,t,n,r)}function _e(e,t,n){if(e==="Backspace"||e==="Delete")return e==="Delete"&&t===n?{endOffset:1}:{endOffset:0}}function q(e,t){const{decimalSeparator:n}=I(t),r=e.target;if(ne(e,r,t,n)){e.preventDefault();return}return Le(e,r,t),_e(e.key,r.selectionStart,r.selectionEnd)}function H(e,t,n,r){const s=e.target,i=s.value,a=$e(s),o=I(r),c=(r==null?void 0:r.formatOn)===b.Change,{formatted:l,raw:h}=y(i,t,r,c);return s.value=l,i!==l&&we(s,i,l,a,n,o,r),{formatted:l,raw:h}}function Be(e,t,n,r){const s=r-n;return e+t+s}function Q(e,t,n){var u;e.preventDefault();const r=e.target,{value:s,selectionStart:i,selectionEnd:a}=r,o=((u=e.clipboardData)==null?void 0:u.getData("text/plain"))||"",c=s.slice(0,i||0)+o+s.slice(a||0),{formatted:l,raw:h}=y(c,t,n,!0);r.value=l;const d=Be(i||0,o.length,c.length,l.length);return r.setSelectionRange(d,d),{formatted:l,raw:h}}function Pe(e,t){const n=M(e);return t?`^-?[0-9]*[${n}]?[0-9]*$`:`^[0-9]*[${n}]?[0-9]*$`}function We(e){ke(e.decimalMaxLength),Ze(e.decimalMinLength),Ge(e.decimalMinLength,e.decimalMaxLength),Ue(e.formatOn),je(e.thousandSeparator),ze(e.thousandStyle),Je(e.decimalSeparator),Ke(e.thousandSeparator,e.decimalSeparator),D("enableCompactNotation",e.enableCompactNotation),D("enableNegative",e.enableNegative),D("enableLeadingZeros",e.enableLeadingZeros),D("rawValueMode",e.rawValueMode),qe(e.onChange)}function ke(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 Ze(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 Ge(e,t){if(!(e===void 0||t===void 0)&&e>t)throw new Error(`decimalMinLength (${e}) cannot be greater than decimalMaxLength (${t}).`)}function Ue(e){if(e!==void 0&&e!==b.Blur&&e!==b.Change)throw new Error(`formatOn must be either ${b.Blur} or ${b.Change}. Received: ${JSON.stringify(e)}`)}function je(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 ze(e){if(e!==void 0&&!Object.values(S).includes(e))throw new Error(`ThousandStyle must be one of: ${Object.values(S).map(t=>`'${t}'`).join(", ")}. Received: ${JSON.stringify(e)}`)}function Je(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 Ke(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 D(e,t){if(t!==void 0&&typeof t!="boolean")throw new Error(`${e} must be a boolean. Received: ${typeof t} (${JSON.stringify(t)})`)}function qe(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 He{constructor(t,{decimalMaxLength:n=x,decimalMinLength:r=O,formatOn:s=R,thousandSeparator:i=_,thousandStyle:a=B,decimalSeparator:o=E,enableCompactNotation:c=!0,enableNegative:l=P,enableLeadingZeros:h=W,rawValueMode:d=k,onChange:u,...g}){$(this,"element");$(this,"options");$(this,"resolvedOptions");$(this,"rawValue","");$(this,"caretPositionBeforeChange");if(We({decimalMaxLength:n,decimalMinLength:r,formatOn:s,thousandSeparator:i,thousandStyle:a,decimalSeparator:o,enableCompactNotation:c,enableNegative:l,enableLeadingZeros:h,rawValueMode:d,onChange:u}),this.options={decimalMaxLength:n,decimalMinLength:r,onChange:u,formatOn:s,thousandSeparator:i,thousandStyle:a,decimalSeparator:o,enableCompactNotation:c,enableNegative:l,enableLeadingZeros:h,rawValueMode:d,...g},this.resolvedOptions=this.getResolvedOptions(),this.createInputElement(t),this.setupEventListeners(),this.resolvedOptions.rawValueMode&&this.element.value){const f=this.element.value,p=this.resolvedOptions.thousandSeparator?L(f,this.resolvedOptions.thousandSeparator):f;this.rawValue=p,this.element.value=this.formatValueForDisplay(p)}else if(this.element.value){const f=this.element.value;this.element.value=this.formatValueForDisplay(f)}}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 Y=Pe(this.resolvedOptions.decimalSeparator,this.resolvedOptions.enableNegative);this.element.setAttribute("pattern",Y)}const{decimalMaxLength:n,decimalMinLength:r,formatOn:s,thousandSeparator:i,thousandStyle:a,decimalSeparator:o,enableCompactNotation:c,enableNegative:l,enableLeadingZeros:h,rawValueMode:d,onChange:u,value:g,defaultValue:f,type:p,inputMode:m,spellcheck:w,autocomplete:Qe,...X}=this.options;Object.assign(this.element,X),g!==void 0?this.element.value=g: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===b.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??x,decimalMinLength:this.options.decimalMinLength??O,formatOn:this.options.formatOn??R,thousandSeparator:this.options.thousandSeparator??_,thousandStyle:this.options.thousandStyle??B,decimalSeparator:this.options.decimalSeparator??E,enableCompactNotation:this.options.enableCompactNotation??ee,enableNegative:this.options.enableNegative??P,enableLeadingZeros:this.options.enableLeadingZeros??W,rawValueMode:this.options.rawValueMode??k,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 r=this.resolvedOptions.rawValueMode?this.rawValue:t;this.resolvedOptions.onChange(r)}}formatValueForDisplay(t){if(!t)return t;const{thousandSeparator:n,thousandStyle:r,enableLeadingZeros:s,decimalSeparator:i}=this.resolvedOptions;return n&&r!==S.None?j(t,n,r,s,i):t}handleChange(t){const{formatted:n,raw:r}=H(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:s}=n,i=this.buildFormattingOptions(),a=q(t,{formatOn:i.formatOn,thousandSeparator:i.thousandSeparator,ThousandStyle:i.ThousandStyle,decimalSeparator:i.decimalSeparator});a?this.caretPositionBeforeChange={selectionStart:r??0,selectionEnd:s??0,endOffset:a.endOffset}:this.caretPositionBeforeChange={selectionStart:r??0,selectionEnd:s??0}}handlePaste(t){const{formatted:n,raw:r}=Q(t,this.resolvedOptions.decimalMaxLength,this.buildFormattingOptions());this.handleValueChange(n,r);const s=new Event("input",{bubbles:!0,cancelable:!0});this.element.dispatchEvent(s)}handleFocus(t){if(this.resolvedOptions.formatOn===b.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:s}=this.resolvedOptions;if(r&&s!==S.None&&n.value){const i=n.value,a=this.formatValueForDisplay(n.value);n.value=a;const o=this.resolvedOptions.rawValueMode?L(a,r):void 0;if(this.handleValueChange(a,o),i!==a){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?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(M(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=b;exports.NumoraInput=He;exports.ThousandStyle=S;exports.formatInputValue=y;exports.formatValueForDisplay=Re;exports.handleOnChangeNumoraInput=H;exports.handleOnKeyDownNumoraInput=q;exports.handleOnPasteNumoraInput=Q;
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;