numora 3.3.0 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,6 +6,7 @@ export interface NumoraInputOptions extends Partial<Omit<HTMLInputElement, 'valu
6
6
  decimalSeparator?: string;
7
7
  decimalMaxLength?: number;
8
8
  decimalMinLength?: number;
9
+ locale?: string | true;
9
10
  enableCompactNotation?: boolean;
10
11
  enableNegative?: boolean;
11
12
  enableLeadingZeros?: boolean;
@@ -19,7 +20,7 @@ export declare class NumoraInput {
19
20
  private resolvedOptions;
20
21
  private rawValue;
21
22
  private caretPositionBeforeChange?;
22
- constructor(container: HTMLElement, { decimalMaxLength, decimalMinLength, formatOn, thousandSeparator, thousandStyle, decimalSeparator, enableCompactNotation, enableNegative, enableLeadingZeros, rawValueMode, onChange, ...rest }: NumoraInputOptions);
23
+ constructor(container: HTMLElement, { decimalMaxLength, decimalMinLength, formatOn, thousandSeparator, thousandStyle, decimalSeparator, locale, enableCompactNotation, enableNegative, enableLeadingZeros, rawValueMode, onChange, ...rest }: NumoraInputOptions);
23
24
  private createInputElement;
24
25
  private setupEventListeners;
25
26
  private getResolvedOptions;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export * from './NumoraInput';
2
2
  export { ThousandStyle, FormatOn } from './types';
3
- export { getSeparatorsFromLocale, resolveLocaleOptions } from './utils/locale';
3
+ export { getSeparatorsFromLocale, applyLocale } from './utils/locale';
4
4
  export { handleOnChangeNumoraInput, handleOnPasteNumoraInput, handleOnKeyDownNumoraInput, } from './utils/event-handlers';
5
5
  export { formatValueForDisplay, formatInputValue, } from './utils/format-utils';
6
6
  export type { FormattingOptions, CaretPositionInfo } from './types';
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var le=Object.defineProperty;var he=(e,t,n)=>t in e?le(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var C=(e,t,n)=>he(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var L=(e=>(e.Blur="blur",e.Change="change",e))(L||{}),p=(e=>(e.None="none",e.Thousand="thousand",e.Lakh="lakh",e.Wan="wan",e.Locale="locale",e))(p||{});const G=2,B=0,Z=L.Blur,ue=",",H=p.None,y=".",k=!1,W=!1,U=!1,P=!1;function w(e){return e.replace(/[-[\]/{}()*+?.\\^$|]/g,"\\$&")}const z=new Map;function O(e,t="g"){const n=`${e}:${t}`;let r=z.get(n);return r||(r=new RegExp(e,t),z.set(n,r)),r}function de(e,t="g"){const n=w(e);return O(n,t)}const fe=/[.,]/g;function _(e){return{decimalSeparator:(e==null?void 0:e.decimalSeparator)??y,thousandSeparator:e==null?void 0:e.thousandSeparator}}function Y(e,t){const n=e.startsWith("-"),r=n?e.slice(1):e,[i="",s=""]=r.split(t);return{sign:n?"-":"",integer:i,decimal:s}}function ge(e,t){if(!e.value.includes(t))return!1;const{selectionStart:n,selectionEnd:r,value:i}=e;return!i.slice(n??0,r??0).includes(t)}function Se(e,t,n){const{key:r}=e;if(r!==","&&r!==".")return!1;if(ge(t,n))return!0;if(r!==n){const{selectionStart:i,selectionEnd:s,value:a}=t,c=i??0,l=s??c;t.value=a.slice(0,c)+n+a.slice(l);const o=c+1;return t.setSelectionRange(o,o),!0}return!1}const Ee=(e,t,n=y)=>{const{sign:r,integer:i,decimal:s}=Y(e,n);if(!s)return e;const a=s.slice(0,t);return`${r}${i}${n}${a}`},me=(e,t=y)=>{const n=e.indexOf(t);if(n===-1||n===e.length-1)return e;const r=e.slice(0,n+1),i=e.slice(n+1),a=t==="."||t===","?fe:O("[,\\."+w(t)+"]","g");return r+i.replace(a,"")},pe=(e,t=0,n=y)=>{if(t<=0)return e;const{sign:r,integer:i,decimal:s}=Y(e,n);if(s.length>=t)return e;const a=s.padEnd(t,"0");return`${r}${i}${n}${a}`},D={thousand:{size:3},lakh:{firstGroup:3,restGroup:2},wan:{size:4}},be=/^(0+)/;function Q(e,t,n=p.Thousand,r=!1,i="."){if(!e||e==="0"||e===i||e==="-"||e===`-${i}`)return e;const s=e.includes(i),a=e.startsWith("-"),c=a?e.slice(1):e,[l,o]=c.split(i);if(!l){const u=o?`${i}${o}`:c;return a?`-${u}`:u}if(r&&l.startsWith("0")&&l.length>1){const u=l.match(be);if(u){const S=u[1],E=l.slice(S.length);if(E){const m=J(E,t,n),f=S+m,g=a?"-":"";return s?o?`${g}${f}${i}${o}`:`${g}${f}${i}`:`${g}${f}`}}}const h=J(l,t,n),d=a?"-":"";return s?o?`${d}${h}${i}${o}`:`${d}${h}${i}`:`${d}${h}`}function J(e,t,n){if(e==="0"||e==="")return e;switch(n){case p.None:return e;case p.Thousand:return X(e,t,D.thousand.size);case p.Lakh:return Le(e,t);case p.Wan:return X(e,t,D.wan.size);default:return e}}function Le(e,t){if(e.length<=D.lakh.firstGroup)return e;const n=[],r=e.length-D.lakh.firstGroup;n.unshift(e.slice(r));for(let i=r;i>0;i-=D.lakh.restGroup)n.unshift(e.slice(Math.max(0,i-D.lakh.restGroup),i));return n.join(t)}function X(e,t,n){const r=[];for(let i=e.length;i>0;i-=n)r.unshift(e.slice(Math.max(0,i-n),i));return r.join(t)}function Ne(e,t,n){return(t==null?void 0:t.formatOn)===L.Change&&t.thousandSeparator?Q(e,t.thousandSeparator,t.ThousandStyle??p.None,t.enableLeadingZeros,(n==null?void 0:n.decimalSeparator)??y):e}function $(e,t,n){let r=0;for(let i=0;i<t&&i<e.length;i++)e[i]!==n&&r++;return r}function ve(e,t,n){if(t===0)return 0;let r=0;for(let i=0;i<e.length;i++)if(e[i]!==n){if(r===t-1)return i+1;r++}return e.length}function T(e,t,n){if(t===0)return 0;let r=0;for(let i=0;i<e.length;i++)if(e[i]!==n){if(r++,r===t)return i+1;if(r>t)return i}return e.length}function V(e,t,n){return t<0||t>=e.length?!1:e[t]===n}const $e=/\d/;function De(e,t={}){const{thousandSeparator:n,decimalSeparator:r=".",prefix:i="",suffix:s=""}=t,a=new Array(e.length+1).fill(!0);if(i&&a.fill(!1,0,i.length),s){const c=e.length-s.length;a.fill(!1,c+1,e.length+1)}for(let c=0;c<e.length;c++){const l=e[c];(n&&l===n||l===r)&&(a[c]=!1,c+1<e.length&&!$e.test(e[c+1])&&(a[c+1]=!1))}return a.some(c=>c)||a.fill(!0),a}function x(e,t,n,r){const i=e.length;if(t=Math.max(0,Math.min(t,i)),r==="left"){for(;t>=0&&!n[t];)t--;t===-1&&(t=n.indexOf(!0))}else if(r==="right"){for(;t<=i&&!n[t];)t++;t>i&&(t=n.lastIndexOf(!0))}else if(!n[t]){let s=t;for(;s<=i&&!n[s];)s++;let a=t;for(;a>=0&&!n[a];)a--;s<=i&&a>=0?t=t-a<s-t?a:s:s<=i?t=s:a>=0&&(t=a)}return(t===-1||t>i)&&(t=i),t}const j=/(\d+\.?\d*)\s*[kmbt]$/i,ye=(e,t)=>e===t;function Ce(e,t,n,r,i,s,a=".",c={}){if(n<0)return 0;if(n>e.length||e===""||t===""||j.test(e)&&!j.test(t)&&t.length>e.length&&n>=e.length-1)return t.length;const l=t.length<e.length,o=V(e,n,r),h=e.indexOf(a),d=t.indexOf(a);if(c.isCharacterEquivalent&&e!==t){const f={thousandSeparator:r||void 0,...c},g=we(e,t,n,c.isCharacterEquivalent||ye,s,f);if(g!==void 0)return g}const S=new Map,E=(f,g,N)=>{const b=`${f===e?"o":"n"}:${g}`;return S.has(b)||S.set(b,$(f,g,r)),S.get(b)};if(l)return Ie(e,t,n,r,o,h,d,s,c,E);const m=Te(e,t,n,r,o,E);return c.boundary?x(t,m,c.boundary):m}function we(e,t,n,r,i,s){const a=e.length,c=t.length;let l=0,o=0,h=c;for(let g=0;g<a;g++){let N=-1;for(let b=l;b<c;b++)if(r(e[g],t[b],{oldValue:e,newValue:t,typedRange:i,oldIndex:g,newIndex:b})){N=b;break}N!==-1&&(l=N+1,g<n?o=N+1:h===c&&/\d/.test(e[g])&&(h=N))}if(o>h)return h;const d=t.length<e.length||i!==void 0&&i.isDelete===!1;let u,S=!1,E=!1;if(d){u=o;const g=s.thousandSeparator,N=s.decimalSeparator??".",b=u<t.length?t[u]:"";g&&b===g?(n>0?e[n-1]:"")===g?(u=h,S=!0):E=!0:b===N&&(E=!0)}else u=n-o<h-n?o:h;const m=d&&!S?"left":"right";if(s.boundary)return E?u:x(t,u,s.boundary,m);const f=s.thousandSeparator;if(!E&&f&&u>=0&&u<t.length&&t[u]===f)if(d&&!S)for(;u>0&&t[u]===f;)u--;else for(;u<t.length&&t[u]===f;)u++;return u}function Ie(e,t,n,r,i,s,a,c,l={},o=$){if(i)return Me(e,t,n,r,a,o);const h=o(e,n,r),d=o(e,e.length,r),u=o(t,t.length,r),S=d-u,E=Ae(e,n,r,h,S,s,c,o),m=s===-1||n<=s,f=Re(t,E,r,S,c,m,a,o);return l.boundary?x(t,f,l.boundary):f}function Me(e,t,n,r,i,s=$){const a=n+1;if(a<e.length){const c=s(e,a,r),l=ve(t,c,r);return l<t.length&&t[l]!==r?l+1:l}return n}function Ae(e,t,n,r,i,s,a,c=$){if(a){const{start:o,isDelete:h}=a;return h?c(e,o,n):Math.max(0,c(e,o,n))}return t>0&&e[t-1]===n&&i>0?r+1:r}function K(e,t,n,r,i,s,a=$){if(t>0&&t<e.length&&a(e,t,r)===n){if(e[t]===r&&s&&i>0&&t<e.length-1)return t+1;if(!s&&i>0&&t<e.length-1)return Math.min(t+1,e.length)}return t}function Re(e,t,n,r,i,s,a,c=$){if(s&&a!==-1){const o=e.substring(0,a),h=c(o,o.length,n);if(t<=h){const d=T(o,t,n);return K(o,d,t,n,r,i,c)}}const l=T(e,t,n);return K(e,l,t,n,r,i,c)}function Te(e,t,n,r,i,s=$){const a=n>=e.length,c=s(e,n,r),l=s(e,e.length,r),o=s(t,t.length,r);if(a||c===l)return t.length;const h=o-l;let d=c;h>0&&!a&&c<l&&(d=c+1);const u=T(t,d,r);return i&&!V(t,u,r)?Math.max(0,u-1):u}function Oe(e,t,n){const{selectionStart:r,selectionEnd:i,endOffset:s=0}=e;if(r!==i){const h=i-r;return{start:r,end:i,deletedLength:h,isDelete:!1}}if(s>0){const h=s;return{start:r,end:r+h,deletedLength:h,isDelete:!0}}const c=t.length,l=n.length,o=c-l;if(!(o<=0))return{start:r,end:r+o,deletedLength:o,isDelete:!1}}function _e(e,t){if(e===t)return;let n=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;let r=e.length-1,i=t.length-1;for(;r>=n&&i>=n&&e[r]===t[i];)r--,i--;const s=r-n+1,a=i-n+1;if(!(s===0&&a===0))return{start:n,end:r+1,deletedLength:s,isDelete:s>a}}function q(e,t){if(e.value=e.value,e===null)return!1;if(e.createTextRange){const n=e.createTextRange();return n.move("character",t),n.select(),!0}return e.selectionStart!==null||e.selectionStart===0?(e.focus(),e.setSelectionRange(t,t),!0):(e.focus(),!1)}function xe(e,t,n){return e.selectionStart===0&&e.selectionEnd===e.value.length?null:(q(e,t),setTimeout(()=>{e.value===n&&e.selectionStart!==t&&q(e,t)},0))}function Ge(e){return Math.max(e.selectionStart,e.selectionEnd)}function Be(e,t,n){if((n==null?void 0:n.formatOn)!==L.Change||!n.thousandSeparator)return;const{selectionStart:r,selectionEnd:i,value:s}=t;if(r===null||i===null||r!==i)return;const{key:a}=e,c=n.thousandSeparator;a==="Backspace"&&r>0&&s[r-1]===c&&t.setSelectionRange(r-1,r-1),a==="Delete"&&s[r]===c&&t.setSelectionRange(r+1,r+1)}function Ze(e,t,n,r,i,s,a){if(!i)return;const{selectionStart:c=0,selectionEnd:l=0,endOffset:o=0}=i;let h=Oe({selectionStart:c,selectionEnd:l,endOffset:o},t,n);if(h||(h=_e(t,n)),!h)return;const d=De(n,{thousandSeparator:(a==null?void 0:a.thousandSeparator)??s.thousandSeparator,decimalSeparator:s.decimalSeparator}),u={thousandSeparator:(a==null?void 0:a.thousandSeparator)??s.thousandSeparator,decimalSeparator:s.decimalSeparator,isCharacterEquivalent:(f,g)=>{const N=(a==null?void 0:a.thousandSeparator)??s.thousandSeparator;return N&&f===N?!1:f===g},boundary:d},S=(a==null?void 0:a.thousandSeparator)??s.thousandSeparator??",",E=(a==null?void 0:a.ThousandStyle)??p.None,m=Ce(t,n,r,S,E,h,s.decimalSeparator,u);xe(e,m,n)}const ke=(e,t=!1,n=".")=>{const r=w(n),i=O(`[^0-9${r}]`,"g");if(!t)return e.replace(i,"");const s=e.startsWith("-"),a=e.replace(i,"");return s&&(a.length>0||e==="-")?"-"+a:a},We=/([+-]?\d+\.?\d*)[eE]([+-]?\d+)/g,F=/^0+$/,A=/\.?0+$/;function Ue(e){return!e.includes("e")&&!e.includes("E")?e:e.replace(We,(t,n,r)=>{const i=parseInt(r,10);if(i===0)return n;const s=n.startsWith("-"),a=s?n.slice(1):n,[c,l=""]=a.split("."),o=i>0?Pe(c,l,i):ze(c,l,Math.abs(i));return s?"-"+o:o})}function Pe(e,t,n){const r=e+t;if(r==="0"||F.test(r))return"0";const i=t.length;if(n<=i){const a=r.slice(0,e.length+n),c=r.slice(e.length+n);return c?`${a}.${c}`:a}const s=n-i;return r+"0".repeat(s)}function ze(e,t,n){const r=e+t;if(r==="0"||F.test(r))return"0";const s=e.length-n;if(s<=0){const a=Math.abs(s),c=`0.${"0".repeat(a)}${r}`;return R(c)}if(s<e.length){const a=r.slice(0,s),c=r.slice(s),l=`${a}.${c}`;return R(l)}return R(r)}function R(e){if(!e.includes("."))return e;if(e==="0.")return"0";if(e.startsWith("0.")){const t=e.replace(A,"");return t==="0"?"0":t||"0"}if(e.startsWith("-0.")){const t=e.replace(A,"");return t==="-0"||t==="0"?"0":t||"0"}return e.replace(A,"")||e}const Je=/(\d+\.?\d*)\s*([kmbt])/gi,Xe=/^0+/,je=/^(-?)0+([1-9])/,Ke=/^-?0+$/,qe=/\.?0+$/,He={k:3,m:6,b:9,t:12};function Ye(e){return e.replace(Je,(t,n,r)=>{const i=r.toLowerCase(),s=He[i];if(!s)return t;const[a,c=""]=n.split("."),l=a.replace(Xe,"")||"0";let o;if(c.length===0)o=l+"0".repeat(s);else if(c.length<=s){const h=s-c.length;o=l+c+"0".repeat(h)}else{const h=c.slice(0,s),d=c.slice(s);o=l+h+"."+d}return o=o.replace(je,"$1$2"),Ke.test(o)&&(o="0"),o.includes(".")&&(o=o.replace(qe,"")),o})}function Qe(e){if(!e||e==="0"||e==="-0"||e==="-"||e===".")return e;const t=e.startsWith("-"),n=t?e.slice(1):e;if(n===".")return e;if(n.includes(".")){const[i,s]=n.split(".");if(i){const c=(i.replace(/^0+/,"")||"0")+"."+s;return t?"-"+c:c}return e}if(n.startsWith("0")){const i=n.replace(/^0+/,"")||"0";return t?"-"+i:i}return e}function Ve(e){return e.replace(/[\s\u200B]/g,"")}function v(e,t){const n=de(t);return e.replace(n,"")}const Fe=(e,t)=>{let n=Ve(e);return t!=null&&t.thousandSeparator&&(n=v(n,t.thousandSeparator)),t!=null&&t.enableCompactNotation&&(n=Ye(n)),n=Ue(n),n=ke(n,t==null?void 0:t.enableNegative,t==null?void 0:t.decimalSeparator),n=me(n,t==null?void 0:t.decimalSeparator),t!=null&&t.enableLeadingZeros||(n=Qe(n)),n};function et(e,t,n){return{enableCompactNotation:e==null?void 0:e.enableCompactNotation,enableNegative:e==null?void 0:e.enableNegative,enableLeadingZeros:e==null?void 0:e.enableLeadingZeros,decimalSeparator:t.decimalSeparator,thousandSeparator:n?t.thousandSeparator:void 0}}function M(e,t,n,r){const i=_(n),s=r??(n==null?void 0:n.formatOn)===L.Change,a=Fe(e,et(n,i,s)),c=Ee(a,t,i.decimalSeparator),l=(n==null?void 0:n.decimalMinLength)??0,o=pe(c,l,i.decimalSeparator);return{formatted:Ne(o,n,i),raw:o}}function tt(e,t,n){const r=!!(n!=null&&n.thousandSeparator);return M(e,t,n,r)}function nt(e,t,n){if(e==="Backspace"||e==="Delete")return e==="Delete"&&t===n?{endOffset:1}:{endOffset:0}}function ee(e,t){const{decimalSeparator:n}=_(t),r=e.target;if(Se(e,r,n)){e.preventDefault();return}return Be(e,r,t),nt(e.key,r.selectionStart,r.selectionEnd)}function te(e,t,n,r){const i=e.target,s=i.value,a=Ge(i),c=_(r),l=(r==null?void 0:r.formatOn)===L.Change,{formatted:o,raw:h}=M(s,t,r,l);return i.value=o,s!==o&&Ze(i,s,o,a,n,c,r),{formatted:o,raw:h}}function rt(e,t,n,r){const i=r-n;return e+t+i}function ne(e,t,n){var u;e.preventDefault();const r=e.target,{value:i,selectionStart:s,selectionEnd:a}=r,c=((u=e.clipboardData)==null?void 0:u.getData("text/plain"))||"",l=i.slice(0,s||0)+c+i.slice(a||0),{formatted:o,raw:h}=M(l,t,n,!0);r.value=o;const d=rt(s||0,c.length,l.length,o.length);return r.setSelectionRange(d,d),{formatted:o,raw:h}}function re(e,t){const n=w(e);return t?`^-?[0-9]*[${n}]?[0-9]*$`:`^[0-9]*[${n}]?[0-9]*$`}function ie(e){var t,n;try{const i=new Intl.NumberFormat(e).formatToParts(123456789e-2);return{decimalSeparator:((t=i.find(s=>s.type==="decimal"))==null?void 0:t.value)??".",thousandSeparator:((n=i.find(s=>s.type==="group"))==null?void 0:n.value)??","}}catch{return{thousandSeparator:",",decimalSeparator:"."}}}function se(e){let t=e.thousandSeparator??ue,n=e.decimalSeparator??y,r=e.thousandStyle??H;if(e.thousandStyle===p.Locale||e.decimalSeparator==="auto"){const s=ie();e.thousandStyle===p.Locale&&(t=e.thousandSeparator??s.thousandSeparator,n=e.decimalSeparator==="auto"||e.decimalSeparator===void 0?s.decimalSeparator:e.decimalSeparator,r=p.Thousand),e.decimalSeparator==="auto"&&(n=s.decimalSeparator)}return{thousandSeparator:t,thousandStyle:r,decimalSeparator:n}}function ae(e){it(e.decimalMaxLength),st(e.decimalMinLength),at(e.decimalMinLength,e.decimalMaxLength),ct(e.formatOn),ot(e.thousandSeparator),lt(e.thousandStyle),ht(e.decimalSeparator),ut(e.thousandSeparator,e.decimalSeparator),I("enableCompactNotation",e.enableCompactNotation),I("enableNegative",e.enableNegative),I("enableLeadingZeros",e.enableLeadingZeros),I("rawValueMode",e.rawValueMode),dt(e.onChange)}function it(e){if(e!==void 0){if(typeof e!="number")throw new Error(`decimalMaxLength must be a number. Received: ${typeof e} (${JSON.stringify(e)})`);if(!Number.isInteger(e))throw new Error(`decimalMaxLength must be an integer. Received: ${e}`);if(e<0)throw new Error(`decimalMaxLength must be non-negative. Received: ${e}`)}}function st(e){if(e!==void 0){if(typeof e!="number")throw new Error(`decimalMinLength must be a number. Received: ${typeof e} (${JSON.stringify(e)})`);if(!Number.isInteger(e))throw new Error(`decimalMinLength must be an integer. Received: ${e}`);if(e<0)throw new Error(`decimalMinLength must be non-negative. Received: ${e}`)}}function at(e,t){if(!(e===void 0||t===void 0)&&e>t)throw new Error(`decimalMinLength (${e}) cannot be greater than decimalMaxLength (${t}).`)}function ct(e){if(e!==void 0&&e!==L.Blur&&e!==L.Change)throw new Error(`formatOn must be either ${L.Blur} or ${L.Change}. Received: ${JSON.stringify(e)}`)}function ot(e){if(e!==void 0){if(typeof e!="string")throw new Error(`thousandSeparator must be a string. Received: ${typeof e} (${JSON.stringify(e)})`);if(e.length===0)throw new Error(`thousandSeparator cannot be empty. Received: ${JSON.stringify(e)}`);if(e.length>1)throw new Error(`thousandSeparator must be a single character. Received: "${e}" (length: ${e.length})`)}}function lt(e){if(e!==void 0&&!Object.values(p).includes(e))throw new Error(`ThousandStyle must be one of: ${Object.values(p).map(t=>`'${t}'`).join(", ")}. Received: ${JSON.stringify(e)}`)}function ht(e){if(!(e===void 0||e==="auto")){if(typeof e!="string")throw new Error(`decimalSeparator must be a string. Received: ${typeof e} (${JSON.stringify(e)})`);if(e.length===0)throw new Error(`decimalSeparator cannot be empty. Received: ${JSON.stringify(e)}`);if(e.length>1)throw new Error(`decimalSeparator must be a single character. Received: "${e}" (length: ${e.length})`)}}function ut(e,t){if(!(e===void 0||t===void 0)&&t!=="auto"&&e===t)throw new Error(`Decimal separator can't be same as thousand separator. thousandSeparator: ${e}, decimalSeparator: ${t}`)}function I(e,t){if(t!==void 0&&typeof t!="boolean")throw new Error(`${e} must be a boolean. Received: ${typeof t} (${JSON.stringify(t)})`)}function dt(e){if(e!==void 0&&typeof e!="function")throw new Error(`onChange must be a function or undefined. Received: ${typeof e} (${JSON.stringify(e)})`)}class ft{constructor(t,{decimalMaxLength:n=G,decimalMinLength:r=B,formatOn:i=Z,thousandSeparator:s,thousandStyle:a=H,decimalSeparator:c,enableCompactNotation:l=k,enableNegative:o=W,enableLeadingZeros:h=U,rawValueMode:d=P,onChange:u,...S}){C(this,"element");C(this,"resolvedOptions");C(this,"rawValue","");C(this,"caretPositionBeforeChange");ae({decimalMaxLength:n,decimalMinLength:r,formatOn:i,thousandSeparator:s,thousandStyle:a,decimalSeparator:c,enableCompactNotation:l,enableNegative:o,enableLeadingZeros:h,rawValueMode:d,onChange:u});const E={decimalMaxLength:n,decimalMinLength:r,onChange:u,formatOn:i,thousandSeparator:s,thousandStyle:a,decimalSeparator:c,enableCompactNotation:l,enableNegative:o,enableLeadingZeros:h,rawValueMode:d,...S};if(this.resolvedOptions=this.getResolvedOptions(E),this.createInputElement(t,E),this.setupEventListeners(),this.resolvedOptions.rawValueMode&&this.element.value){const m=this.element.value,f=this.resolvedOptions.thousandSeparator?v(m,this.resolvedOptions.thousandSeparator):m;this.rawValue=f,this.element.value=this.formatValueForDisplay(f)}else if(this.element.value){const m=this.element.value;this.element.value=this.formatValueForDisplay(m)}}createInputElement(t,n){this.element=document.createElement("input"),this.element.setAttribute("type","text"),this.element.setAttribute("inputmode","decimal"),this.element.setAttribute("spellcheck","false"),this.element.setAttribute("autocomplete","off");const r=re(this.resolvedOptions.decimalSeparator,this.resolvedOptions.enableNegative);this.element.setAttribute("pattern",r);const{decimalMaxLength:i,decimalMinLength:s,formatOn:a,thousandSeparator:c,thousandStyle:l,decimalSeparator:o,enableCompactNotation:h,enableNegative:d,enableLeadingZeros:u,rawValueMode:S,onChange:E,value:m,defaultValue:f,type:g,inputMode:N,spellcheck:b,autocomplete:ce,...oe}=n;Object.assign(this.element,oe),m!==void 0?this.element.value=m:f!==void 0&&(this.element.defaultValue=f,this.element.value=f),t.appendChild(this.element)}setupEventListeners(){this.element.addEventListener("input",this.handleChange.bind(this)),this.element.addEventListener("keydown",this.handleKeyDown.bind(this)),this.element.addEventListener("paste",this.handlePaste.bind(this)),this.resolvedOptions.formatOn===L.Blur&&this.resolvedOptions.thousandSeparator&&(this.element.addEventListener("focus",this.handleFocus.bind(this)),this.element.addEventListener("blur",this.handleBlur.bind(this)))}getResolvedOptions(t){const n=se({thousandSeparator:t.thousandSeparator,thousandStyle:t.thousandStyle,decimalSeparator:t.decimalSeparator});return{decimalMaxLength:t.decimalMaxLength??G,decimalMinLength:t.decimalMinLength??B,formatOn:t.formatOn??Z,thousandSeparator:n.thousandSeparator,thousandStyle:n.thousandStyle,decimalSeparator:n.decimalSeparator,enableCompactNotation:t.enableCompactNotation??k,enableNegative:t.enableNegative??W,enableLeadingZeros:t.enableLeadingZeros??U,rawValueMode:t.rawValueMode??P,onChange:t.onChange}}buildFormattingOptions(){return{formatOn:this.resolvedOptions.formatOn,thousandSeparator:this.resolvedOptions.thousandSeparator,ThousandStyle:this.resolvedOptions.thousandStyle,enableCompactNotation:this.resolvedOptions.enableCompactNotation,enableNegative:this.resolvedOptions.enableNegative,enableLeadingZeros:this.resolvedOptions.enableLeadingZeros,decimalSeparator:this.resolvedOptions.decimalSeparator,decimalMinLength:this.resolvedOptions.decimalMinLength,rawValueMode:this.resolvedOptions.rawValueMode}}handleValueChange(t,n){if(this.resolvedOptions.rawValueMode&&n!==void 0&&(this.rawValue=n),this.resolvedOptions.onChange){const r=this.resolvedOptions.rawValueMode?this.rawValue:t;this.resolvedOptions.onChange(r)}}formatValueForDisplay(t){if(!t)return t;const{thousandSeparator:n,thousandStyle:r,enableLeadingZeros:i,decimalSeparator:s}=this.resolvedOptions;return n&&r!==p.None?Q(t,n,r,i,s):t}handleChange(t){const{formatted:n,raw:r}=te(t,this.resolvedOptions.decimalMaxLength,this.caretPositionBeforeChange,this.buildFormattingOptions());this.caretPositionBeforeChange=void 0,this.handleValueChange(n,r)}handleKeyDown(t){const n=t.target,{selectionStart:r,selectionEnd:i}=n,s=this.buildFormattingOptions(),a=ee(t,{formatOn:s.formatOn,thousandSeparator:s.thousandSeparator,ThousandStyle:s.ThousandStyle,decimalSeparator:s.decimalSeparator});a?this.caretPositionBeforeChange={selectionStart:r??0,selectionEnd:i??0,endOffset:a.endOffset}:this.caretPositionBeforeChange={selectionStart:r??0,selectionEnd:i??0}}handlePaste(t){const{formatted:n,raw:r}=ne(t,this.resolvedOptions.decimalMaxLength,this.buildFormattingOptions());this.handleValueChange(n,r);const i=new Event("input",{bubbles:!0,cancelable:!0});this.element.dispatchEvent(i)}handleFocus(t){if(this.resolvedOptions.formatOn===L.Blur&&this.resolvedOptions.thousandSeparator){const n=t.target;n.value=v(n.value,this.resolvedOptions.thousandSeparator)}}handleBlur(t){const n=t.target,{thousandSeparator:r,thousandStyle:i}=this.resolvedOptions;if(r&&i!==p.None&&n.value){const s=this.formatValueForDisplay(n.value);n.value=s;const a=this.resolvedOptions.rawValueMode?v(s,r):void 0;this.handleValueChange(s,a)}}getValue(){return this.resolvedOptions.rawValueMode?this.rawValue:this.element.value}setValue(t){if(this.resolvedOptions.rawValueMode){const n=this.resolvedOptions.thousandSeparator?v(t,this.resolvedOptions.thousandSeparator):t;this.rawValue=n,this.element.value=this.formatValueForDisplay(n)}else this.element.value=t}disable(){this.element.disabled=!0}enable(){this.element.disabled=!1}addEventListener(t,n){this.element.addEventListener(t,n)}removeEventListener(t,n){this.element.removeEventListener(t,n)}getElement(){return this.element}get value(){return this.getValue()}set value(t){this.setValue(t)}get valueAsNumber(){const t=this.getValue();if(!t)return NaN;const n=this.resolvedOptions.thousandSeparator?v(t,this.resolvedOptions.thousandSeparator):t,r=this.resolvedOptions.decimalSeparator&&this.resolvedOptions.decimalSeparator!=="."?n.replace(new RegExp(w(this.resolvedOptions.decimalSeparator),"g"),"."):n;return parseFloat(r)}set valueAsNumber(t){if(isNaN(t)){this.setValue("");return}const n=t.toString();this.setValue(n)}}exports.FormatOn=L;exports.NumoraInput=ft;exports.ThousandStyle=p;exports.formatInputValue=M;exports.formatValueForDisplay=tt;exports.getNumoraPattern=re;exports.getSeparatorsFromLocale=ie;exports.handleOnChangeNumoraInput=te;exports.handleOnKeyDownNumoraInput=ee;exports.handleOnPasteNumoraInput=ne;exports.removeThousandSeparators=v;exports.resolveLocaleOptions=se;exports.validateNumoraInputOptions=ae;
1
+ "use strict";var le=Object.defineProperty;var he=(e,t,n)=>t in e?le(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var w=(e,t,n)=>he(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var N=(e=>(e.Blur="blur",e.Change="change",e))(N||{}),m=(e=>(e.None="none",e.Thousand="thousand",e.Lakh="lakh",e.Wan="wan",e))(m||{});const G=2,B=0,Z=N.Blur,ue=",",k=m.None,C=".",W=!1,U=!1,P=!1,z=!1;function y(e){return e.replace(/[-[\]/{}()*+?.\\^$|]/g,"\\$&")}const J=new Map;function O(e,t="g"){const n=`${e}:${t}`;let r=J.get(n);return r||(r=new RegExp(e,t),J.set(n,r)),r}function de(e,t="g"){const n=y(e);return O(n,t)}const fe=/[.,]/g;function _(e){return{decimalSeparator:(e==null?void 0:e.decimalSeparator)??C,thousandSeparator:e==null?void 0:e.thousandSeparator}}function Y(e,t){const n=e.startsWith("-"),r=n?e.slice(1):e,[i="",s=""]=r.split(t);return{sign:n?"-":"",integer:i,decimal:s}}function ge(e,t){if(!e.value.includes(t))return!1;const{selectionStart:n,selectionEnd:r,value:i}=e;return!i.slice(n??0,r??0).includes(t)}function Se(e,t,n){const{key:r}=e;if(r!==","&&r!==".")return!1;if(ge(t,n))return!0;if(r!==n){const{selectionStart:i,selectionEnd:s,value:a}=t,c=i??0,l=s??c;t.value=a.slice(0,c)+n+a.slice(l);const o=c+1;return t.setSelectionRange(o,o),!0}return!1}const Ee=(e,t,n=C)=>{const{sign:r,integer:i,decimal:s}=Y(e,n);if(!s)return e;const a=s.slice(0,t);return`${r}${i}${n}${a}`},pe=(e,t=C)=>{const n=e.indexOf(t);if(n===-1||n===e.length-1)return e;const r=e.slice(0,n+1),i=e.slice(n+1),a=t==="."||t===","?fe:O("[,\\."+y(t)+"]","g");return r+i.replace(a,"")},me=(e,t=0,n=C)=>{if(t<=0)return e;const{sign:r,integer:i,decimal:s}=Y(e,n);if(s.length>=t)return e;const a=s.padEnd(t,"0");return`${r}${i}${n}${a}`},D={thousand:{size:3},lakh:{firstGroup:3,restGroup:2},wan:{size:4}},be=/^(0+)/;function Q(e,t,n=m.Thousand,r=!1,i="."){if(!e||e==="0"||e===i||e==="-"||e===`-${i}`)return e;const s=e.includes(i),a=e.startsWith("-"),c=a?e.slice(1):e,[l,o]=c.split(i);if(!l){const u=o?`${i}${o}`:c;return a?`-${u}`:u}if(r&&l.startsWith("0")&&l.length>1){const u=l.match(be);if(u){const S=u[1],E=l.slice(S.length);if(E){const p=X(E,t,n),g=S+p,d=a?"-":"";return s?o?`${d}${g}${i}${o}`:`${d}${g}${i}`:`${d}${g}`}}}const h=X(l,t,n),f=a?"-":"";return s?o?`${f}${h}${i}${o}`:`${f}${h}${i}`:`${f}${h}`}function X(e,t,n){if(e==="0"||e==="")return e;switch(n){case m.None:return e;case m.Thousand:return j(e,t,D.thousand.size);case m.Lakh:return Ne(e,t);case m.Wan:return j(e,t,D.wan.size);default:return e}}function Ne(e,t){if(e.length<=D.lakh.firstGroup)return e;const n=[],r=e.length-D.lakh.firstGroup;n.unshift(e.slice(r));for(let i=r;i>0;i-=D.lakh.restGroup)n.unshift(e.slice(Math.max(0,i-D.lakh.restGroup),i));return n.join(t)}function j(e,t,n){const r=[];for(let i=e.length;i>0;i-=n)r.unshift(e.slice(Math.max(0,i-n),i));return r.join(t)}function Le(e,t,n){return(t==null?void 0:t.formatOn)===N.Change&&t.thousandSeparator?Q(e,t.thousandSeparator,t.ThousandStyle??m.None,t.enableLeadingZeros,(n==null?void 0:n.decimalSeparator)??C):e}function $(e,t,n){let r=0;for(let i=0;i<t&&i<e.length;i++)e[i]!==n&&r++;return r}function ve(e,t,n){if(t===0)return 0;let r=0;for(let i=0;i<e.length;i++)if(e[i]!==n){if(r===t-1)return i+1;r++}return e.length}function T(e,t,n){if(t===0)return 0;let r=0;for(let i=0;i<e.length;i++)if(e[i]!==n){if(r++,r===t)return i+1;if(r>t)return i}return e.length}function V(e,t,n){return t<0||t>=e.length?!1:e[t]===n}const $e=/\d/;function De(e,t={}){const{thousandSeparator:n,decimalSeparator:r=".",prefix:i="",suffix:s=""}=t,a=new Array(e.length+1).fill(!0);if(i&&a.fill(!1,0,i.length),s){const c=e.length-s.length;a.fill(!1,c+1,e.length+1)}for(let c=0;c<e.length;c++){const l=e[c];(n&&l===n||l===r)&&(a[c]=!1,c+1<e.length&&!$e.test(e[c+1])&&(a[c+1]=!1))}return a.some(c=>c)||a.fill(!0),a}function x(e,t,n,r){const i=e.length;if(t=Math.max(0,Math.min(t,i)),r==="left"){for(;t>=0&&!n[t];)t--;t===-1&&(t=n.indexOf(!0))}else if(r==="right"){for(;t<=i&&!n[t];)t++;t>i&&(t=n.lastIndexOf(!0))}else if(!n[t]){let s=t;for(;s<=i&&!n[s];)s++;let a=t;for(;a>=0&&!n[a];)a--;s<=i&&a>=0?t=t-a<s-t?a:s:s<=i?t=s:a>=0&&(t=a)}return(t===-1||t>i)&&(t=i),t}const K=/(\d+\.?\d*)\s*[kmbt]$/i,Ce=(e,t)=>e===t;function we(e,t,n,r,i,s,a=".",c={}){if(n<0)return 0;if(n>e.length||e===""||t===""||K.test(e)&&!K.test(t)&&t.length>e.length&&n>=e.length-1)return t.length;const l=t.length<e.length,o=V(e,n,r),h=e.indexOf(a),f=t.indexOf(a);if(c.isCharacterEquivalent&&e!==t){const g={thousandSeparator:r||void 0,...c},d=ye(e,t,n,c.isCharacterEquivalent||Ce,s,g);if(d!==void 0)return d}const S=new Map,E=(g,d,L)=>{const b=`${g===e?"o":"n"}:${d}`;return S.has(b)||S.set(b,$(g,d,r)),S.get(b)};if(l)return Ie(e,t,n,r,o,h,f,s,c,E);const p=Te(e,t,n,r,o,E);return c.boundary?x(t,p,c.boundary):p}function ye(e,t,n,r,i,s){const a=e.length,c=t.length;let l=0,o=0,h=c;for(let d=0;d<a;d++){let L=-1;for(let b=l;b<c;b++)if(r(e[d],t[b],{oldValue:e,newValue:t,typedRange:i,oldIndex:d,newIndex:b})){L=b;break}L!==-1&&(l=L+1,d<n?o=L+1:h===c&&/\d/.test(e[d])&&(h=L))}if(o>h)return h;const f=t.length<e.length||i!==void 0&&i.isDelete===!1;let u,S=!1,E=!1;if(f){u=o;const d=s.thousandSeparator,L=s.decimalSeparator??".",b=u<t.length?t[u]:"";d&&b===d?(n>0?e[n-1]:"")===d?(u=h,S=!0):E=!0:b===L&&(E=!0)}else u=n-o<h-n?o:h;const p=f&&!S?"left":"right";if(s.boundary)return E?u:x(t,u,s.boundary,p);const g=s.thousandSeparator;if(!E&&g&&u>=0&&u<t.length&&t[u]===g)if(f&&!S)for(;u>0&&t[u]===g;)u--;else for(;u<t.length&&t[u]===g;)u++;return u}function Ie(e,t,n,r,i,s,a,c,l={},o=$){if(i)return Me(e,t,n,r,a,o);const h=o(e,n,r),f=o(e,e.length,r),u=o(t,t.length,r),S=f-u,E=Ae(e,n,r,h,S,s,c,o),p=s===-1||n<=s,g=Re(t,E,r,S,c,p,a,o);return l.boundary?x(t,g,l.boundary):g}function Me(e,t,n,r,i,s=$){const a=n+1;if(a<e.length){const c=s(e,a,r),l=ve(t,c,r);return l<t.length&&t[l]!==r?l+1:l}return n}function Ae(e,t,n,r,i,s,a,c=$){if(a){const{start:o,isDelete:h}=a;return h?c(e,o,n):Math.max(0,c(e,o,n))}return t>0&&e[t-1]===n&&i>0?r+1:r}function q(e,t,n,r,i,s,a=$){if(t>0&&t<e.length&&a(e,t,r)===n){if(e[t]===r&&s&&i>0&&t<e.length-1)return t+1;if(!s&&i>0&&t<e.length-1)return Math.min(t+1,e.length)}return t}function Re(e,t,n,r,i,s,a,c=$){if(s&&a!==-1){const o=e.substring(0,a),h=c(o,o.length,n);if(t<=h){const f=T(o,t,n);return q(o,f,t,n,r,i,c)}}const l=T(e,t,n);return q(e,l,t,n,r,i,c)}function Te(e,t,n,r,i,s=$){const a=n>=e.length,c=s(e,n,r),l=s(e,e.length,r),o=s(t,t.length,r);if(a||c===l)return t.length;const h=o-l;let f=c;h>0&&!a&&c<l&&(f=c+1);const u=T(t,f,r);return i&&!V(t,u,r)?Math.max(0,u-1):u}function Oe(e,t,n){const{selectionStart:r,selectionEnd:i,endOffset:s=0}=e;if(r!==i){const h=i-r;return{start:r,end:i,deletedLength:h,isDelete:!1}}if(s>0){const h=s;return{start:r,end:r+h,deletedLength:h,isDelete:!0}}const c=t.length,l=n.length,o=c-l;if(!(o<=0))return{start:r,end:r+o,deletedLength:o,isDelete:!1}}function _e(e,t){if(e===t)return;let n=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;let r=e.length-1,i=t.length-1;for(;r>=n&&i>=n&&e[r]===t[i];)r--,i--;const s=r-n+1,a=i-n+1;if(!(s===0&&a===0))return{start:n,end:r+1,deletedLength:s,isDelete:s>a}}function H(e,t){if(e.value=e.value,e===null)return!1;if(e.createTextRange){const n=e.createTextRange();return n.move("character",t),n.select(),!0}return e.selectionStart!==null||e.selectionStart===0?(e.focus(),e.setSelectionRange(t,t),!0):(e.focus(),!1)}function xe(e,t,n){return e.selectionStart===0&&e.selectionEnd===e.value.length?null:(H(e,t),setTimeout(()=>{e.value===n&&e.selectionStart!==t&&H(e,t)},0))}function Ge(e){return Math.max(e.selectionStart,e.selectionEnd)}function Be(e,t,n){if((n==null?void 0:n.formatOn)!==N.Change||!n.thousandSeparator)return;const{selectionStart:r,selectionEnd:i,value:s}=t;if(r===null||i===null||r!==i)return;const{key:a}=e,c=n.thousandSeparator;a==="Backspace"&&r>0&&s[r-1]===c&&t.setSelectionRange(r-1,r-1),a==="Delete"&&s[r]===c&&t.setSelectionRange(r+1,r+1)}function Ze(e,t,n,r,i,s,a){if(!i)return;const{selectionStart:c=0,selectionEnd:l=0,endOffset:o=0}=i;let h=Oe({selectionStart:c,selectionEnd:l,endOffset:o},t,n);if(h||(h=_e(t,n)),!h)return;const f=De(n,{thousandSeparator:(a==null?void 0:a.thousandSeparator)??s.thousandSeparator,decimalSeparator:s.decimalSeparator}),u={thousandSeparator:(a==null?void 0:a.thousandSeparator)??s.thousandSeparator,decimalSeparator:s.decimalSeparator,isCharacterEquivalent:(g,d)=>{const L=(a==null?void 0:a.thousandSeparator)??s.thousandSeparator;return L&&g===L?!1:g===d},boundary:f},S=(a==null?void 0:a.thousandSeparator)??s.thousandSeparator??",",E=(a==null?void 0:a.ThousandStyle)??m.None,p=we(t,n,r,S,E,h,s.decimalSeparator,u);xe(e,p,n)}const ke=(e,t=!1,n=".")=>{const r=y(n),i=O(`[^0-9${r}]`,"g");if(!t)return e.replace(i,"");const s=e.startsWith("-"),a=e.replace(i,"");return s&&(a.length>0||e==="-")?"-"+a:a},We=/([+-]?\d+\.?\d*)[eE]([+-]?\d+)/g,F=/^0+$/,A=/\.?0+$/;function Ue(e){return!e.includes("e")&&!e.includes("E")?e:e.replace(We,(t,n,r)=>{const i=parseInt(r,10);if(i===0)return n;const s=n.startsWith("-"),a=s?n.slice(1):n,[c,l=""]=a.split("."),o=i>0?Pe(c,l,i):ze(c,l,Math.abs(i));return s?"-"+o:o})}function Pe(e,t,n){const r=e+t;if(r==="0"||F.test(r))return"0";const i=t.length;if(n<=i){const a=r.slice(0,e.length+n),c=r.slice(e.length+n);return c?`${a}.${c}`:a}const s=n-i;return r+"0".repeat(s)}function ze(e,t,n){const r=e+t;if(r==="0"||F.test(r))return"0";const s=e.length-n;if(s<=0){const a=Math.abs(s),c=`0.${"0".repeat(a)}${r}`;return R(c)}if(s<e.length){const a=r.slice(0,s),c=r.slice(s),l=`${a}.${c}`;return R(l)}return R(r)}function R(e){if(!e.includes("."))return e;if(e==="0.")return"0";if(e.startsWith("0.")){const t=e.replace(A,"");return t==="0"?"0":t||"0"}if(e.startsWith("-0.")){const t=e.replace(A,"");return t==="-0"||t==="0"?"0":t||"0"}return e.replace(A,"")||e}const Je=/(\d+\.?\d*)\s*([kmbt])/gi,Xe=/^0+/,je=/^(-?)0+([1-9])/,Ke=/^-?0+$/,qe=/\.?0+$/,He={k:3,m:6,b:9,t:12};function Ye(e){return e.replace(Je,(t,n,r)=>{const i=r.toLowerCase(),s=He[i];if(!s)return t;const[a,c=""]=n.split("."),l=a.replace(Xe,"")||"0";let o;if(c.length===0)o=l+"0".repeat(s);else if(c.length<=s){const h=s-c.length;o=l+c+"0".repeat(h)}else{const h=c.slice(0,s),f=c.slice(s);o=l+h+"."+f}return o=o.replace(je,"$1$2"),Ke.test(o)&&(o="0"),o.includes(".")&&(o=o.replace(qe,"")),o})}function Qe(e){if(!e||e==="0"||e==="-0"||e==="-"||e===".")return e;const t=e.startsWith("-"),n=t?e.slice(1):e;if(n===".")return e;if(n.includes(".")){const[i,s]=n.split(".");if(i){const c=(i.replace(/^0+/,"")||"0")+"."+s;return t?"-"+c:c}return e}if(n.startsWith("0")){const i=n.replace(/^0+/,"")||"0";return t?"-"+i:i}return e}function Ve(e){return e.replace(/[\s\u200B]/g,"")}function v(e,t){const n=de(t);return e.replace(n,"")}const Fe=(e,t)=>{let n=Ve(e);return t!=null&&t.thousandSeparator&&(n=v(n,t.thousandSeparator)),t!=null&&t.enableCompactNotation&&(n=Ye(n)),n=Ue(n),n=ke(n,t==null?void 0:t.enableNegative,t==null?void 0:t.decimalSeparator),n=pe(n,t==null?void 0:t.decimalSeparator),t!=null&&t.enableLeadingZeros||(n=Qe(n)),n};function et(e,t,n){return{enableCompactNotation:e==null?void 0:e.enableCompactNotation,enableNegative:e==null?void 0:e.enableNegative,enableLeadingZeros:e==null?void 0:e.enableLeadingZeros,decimalSeparator:t.decimalSeparator,thousandSeparator:n?t.thousandSeparator:void 0}}function M(e,t,n,r){const i=_(n),s=r??(n==null?void 0:n.formatOn)===N.Change,a=Fe(e,et(n,i,s)),c=Ee(a,t,i.decimalSeparator),l=(n==null?void 0:n.decimalMinLength)??0,o=me(c,l,i.decimalSeparator);return{formatted:Le(o,n,i),raw:o}}function tt(e,t,n){const r=!!(n!=null&&n.thousandSeparator);return M(e,t,n,r)}function nt(e,t,n){if(e==="Backspace"||e==="Delete")return e==="Delete"&&t===n?{endOffset:1}:{endOffset:0}}function ee(e,t){const{decimalSeparator:n}=_(t),r=e.target;if(Se(e,r,n)){e.preventDefault();return}return Be(e,r,t),nt(e.key,r.selectionStart,r.selectionEnd)}function te(e,t,n,r){const i=e.target,s=i.value,a=Ge(i),c=_(r),l=(r==null?void 0:r.formatOn)===N.Change,{formatted:o,raw:h}=M(s,t,r,l);return i.value=o,s!==o&&Ze(i,s,o,a,n,c,r),{formatted:o,raw:h}}function rt(e,t,n,r){const i=r-n;return e+t+i}function ne(e,t,n){var u;e.preventDefault();const r=e.target,{value:i,selectionStart:s,selectionEnd:a}=r,c=((u=e.clipboardData)==null?void 0:u.getData("text/plain"))||"",l=i.slice(0,s||0)+c+i.slice(a||0),{formatted:o,raw:h}=M(l,t,n,!0);r.value=o;const f=rt(s||0,c.length,l.length,o.length);return r.setSelectionRange(f,f),{formatted:o,raw:h}}function re(e,t){const n=y(e);return t?`^-?[0-9]*[${n}]?[0-9]*$`:`^[0-9]*[${n}]?[0-9]*$`}function ie(e){var t,n;try{const i=new Intl.NumberFormat(e).formatToParts(123456789e-2);return{decimalSeparator:((t=i.find(s=>s.type==="decimal"))==null?void 0:t.value)??".",thousandSeparator:((n=i.find(s=>s.type==="group"))==null?void 0:n.value)??","}}catch{return{thousandSeparator:",",decimalSeparator:"."}}}function se(e,t){if(!e)return t;const r=ie(e===!0?void 0:e);return{thousandSeparator:t.thousandSeparator??r.thousandSeparator,decimalSeparator:t.decimalSeparator??r.decimalSeparator}}function ae(e){it(e.decimalMaxLength),st(e.decimalMinLength),at(e.decimalMinLength,e.decimalMaxLength),ct(e.formatOn),ot(e.thousandSeparator),lt(e.thousandStyle),ht(e.decimalSeparator),ut(e.thousandSeparator,e.decimalSeparator),I("enableCompactNotation",e.enableCompactNotation),I("enableNegative",e.enableNegative),I("enableLeadingZeros",e.enableLeadingZeros),I("rawValueMode",e.rawValueMode),dt(e.onChange)}function it(e){if(e!==void 0){if(typeof e!="number")throw new Error(`decimalMaxLength must be a number. Received: ${typeof e} (${JSON.stringify(e)})`);if(!Number.isInteger(e))throw new Error(`decimalMaxLength must be an integer. Received: ${e}`);if(e<0)throw new Error(`decimalMaxLength must be non-negative. Received: ${e}`)}}function st(e){if(e!==void 0){if(typeof e!="number")throw new Error(`decimalMinLength must be a number. Received: ${typeof e} (${JSON.stringify(e)})`);if(!Number.isInteger(e))throw new Error(`decimalMinLength must be an integer. Received: ${e}`);if(e<0)throw new Error(`decimalMinLength must be non-negative. Received: ${e}`)}}function at(e,t){if(!(e===void 0||t===void 0)&&e>t)throw new Error(`decimalMinLength (${e}) cannot be greater than decimalMaxLength (${t}).`)}function ct(e){if(e!==void 0&&e!==N.Blur&&e!==N.Change)throw new Error(`formatOn must be either ${N.Blur} or ${N.Change}. Received: ${JSON.stringify(e)}`)}function ot(e){if(e!==void 0){if(typeof e!="string")throw new Error(`thousandSeparator must be a string. Received: ${typeof e} (${JSON.stringify(e)})`);if(e.length===0)throw new Error(`thousandSeparator cannot be empty. Received: ${JSON.stringify(e)}`);if(e.length>1)throw new Error(`thousandSeparator must be a single character. Received: "${e}" (length: ${e.length})`)}}function lt(e){if(e!==void 0&&!Object.values(m).includes(e))throw new Error(`ThousandStyle must be one of: ${Object.values(m).map(t=>`'${t}'`).join(", ")}. Received: ${JSON.stringify(e)}`)}function ht(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 ut(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 I(e,t){if(t!==void 0&&typeof t!="boolean")throw new Error(`${e} must be a boolean. Received: ${typeof t} (${JSON.stringify(t)})`)}function dt(e){if(e!==void 0&&typeof e!="function")throw new Error(`onChange must be a function or undefined. Received: ${typeof e} (${JSON.stringify(e)})`)}class ft{constructor(t,{decimalMaxLength:n=G,decimalMinLength:r=B,formatOn:i=Z,thousandSeparator:s,thousandStyle:a=k,decimalSeparator:c,locale:l,enableCompactNotation:o=W,enableNegative:h=U,enableLeadingZeros:f=P,rawValueMode:u=z,onChange:S,...E}){w(this,"element");w(this,"resolvedOptions");w(this,"rawValue","");w(this,"caretPositionBeforeChange");ae({decimalMaxLength:n,decimalMinLength:r,formatOn:i,thousandSeparator:s,thousandStyle:a,decimalSeparator:c,enableCompactNotation:o,enableNegative:h,enableLeadingZeros:f,rawValueMode:u,onChange:S});const p={decimalMaxLength:n,decimalMinLength:r,onChange:S,formatOn:i,thousandSeparator:s,thousandStyle:a,decimalSeparator:c,locale:l,enableCompactNotation:o,enableNegative:h,enableLeadingZeros:f,rawValueMode:u,...E};if(this.resolvedOptions=this.getResolvedOptions(p),this.createInputElement(t,p),this.setupEventListeners(),this.resolvedOptions.rawValueMode&&this.element.value){const g=this.element.value,d=this.resolvedOptions.thousandSeparator?v(g,this.resolvedOptions.thousandSeparator):g;this.rawValue=d,this.element.value=this.formatValueForDisplay(d)}else if(this.element.value){const g=this.element.value;this.element.value=this.formatValueForDisplay(g)}}createInputElement(t,n){this.element=document.createElement("input"),this.element.setAttribute("type","text"),this.element.setAttribute("inputmode","decimal"),this.element.setAttribute("spellcheck","false"),this.element.setAttribute("autocomplete","off");const r=re(this.resolvedOptions.decimalSeparator,this.resolvedOptions.enableNegative);this.element.setAttribute("pattern",r);const{decimalMaxLength:i,decimalMinLength:s,formatOn:a,thousandSeparator:c,thousandStyle:l,decimalSeparator:o,locale:h,enableCompactNotation:f,enableNegative:u,enableLeadingZeros:S,rawValueMode:E,onChange:p,value:g,defaultValue:d,type:L,inputMode:b,spellcheck:ce,autocomplete:gt,...oe}=n;Object.assign(this.element,oe),g!==void 0?this.element.value=g:d!==void 0&&(this.element.defaultValue=d,this.element.value=d),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===N.Blur&&this.resolvedOptions.thousandSeparator&&(this.element.addEventListener("focus",this.handleFocus.bind(this)),this.element.addEventListener("blur",this.handleBlur.bind(this)))}getResolvedOptions(t){const n=se(t.locale,{thousandSeparator:t.thousandSeparator,decimalSeparator:t.decimalSeparator});return{decimalMaxLength:t.decimalMaxLength??G,decimalMinLength:t.decimalMinLength??B,formatOn:t.formatOn??Z,thousandSeparator:n.thousandSeparator??ue,thousandStyle:t.thousandStyle??k,decimalSeparator:n.decimalSeparator??C,enableCompactNotation:t.enableCompactNotation??W,enableNegative:t.enableNegative??U,enableLeadingZeros:t.enableLeadingZeros??P,rawValueMode:t.rawValueMode??z,onChange:t.onChange}}buildFormattingOptions(){return{formatOn:this.resolvedOptions.formatOn,thousandSeparator:this.resolvedOptions.thousandSeparator,ThousandStyle:this.resolvedOptions.thousandStyle,enableCompactNotation:this.resolvedOptions.enableCompactNotation,enableNegative:this.resolvedOptions.enableNegative,enableLeadingZeros:this.resolvedOptions.enableLeadingZeros,decimalSeparator:this.resolvedOptions.decimalSeparator,decimalMinLength:this.resolvedOptions.decimalMinLength,rawValueMode:this.resolvedOptions.rawValueMode}}handleValueChange(t,n){if(this.resolvedOptions.rawValueMode&&n!==void 0&&(this.rawValue=n),this.resolvedOptions.onChange){const r=this.resolvedOptions.rawValueMode?this.rawValue:t;this.resolvedOptions.onChange(r)}}formatValueForDisplay(t){if(!t)return t;const{thousandSeparator:n,thousandStyle:r,enableLeadingZeros:i,decimalSeparator:s}=this.resolvedOptions;return n&&r!==m.None?Q(t,n,r,i,s):t}handleChange(t){const{formatted:n,raw:r}=te(t,this.resolvedOptions.decimalMaxLength,this.caretPositionBeforeChange,this.buildFormattingOptions());this.caretPositionBeforeChange=void 0,this.handleValueChange(n,r)}handleKeyDown(t){const n=t.target,{selectionStart:r,selectionEnd:i}=n,s=this.buildFormattingOptions(),a=ee(t,{formatOn:s.formatOn,thousandSeparator:s.thousandSeparator,ThousandStyle:s.ThousandStyle,decimalSeparator:s.decimalSeparator});a?this.caretPositionBeforeChange={selectionStart:r??0,selectionEnd:i??0,endOffset:a.endOffset}:this.caretPositionBeforeChange={selectionStart:r??0,selectionEnd:i??0}}handlePaste(t){const{formatted:n,raw:r}=ne(t,this.resolvedOptions.decimalMaxLength,this.buildFormattingOptions());this.handleValueChange(n,r);const i=new Event("input",{bubbles:!0,cancelable:!0});this.element.dispatchEvent(i)}handleFocus(t){if(this.resolvedOptions.formatOn===N.Blur&&this.resolvedOptions.thousandSeparator){const n=t.target;n.value=v(n.value,this.resolvedOptions.thousandSeparator)}}handleBlur(t){const n=t.target,{thousandSeparator:r,thousandStyle:i}=this.resolvedOptions;if(r&&i!==m.None&&n.value){const s=this.formatValueForDisplay(n.value);n.value=s;const a=this.resolvedOptions.rawValueMode?v(s,r):void 0;this.handleValueChange(s,a)}}getValue(){return this.resolvedOptions.rawValueMode?this.rawValue:this.element.value}setValue(t){if(this.resolvedOptions.rawValueMode){const n=this.resolvedOptions.thousandSeparator?v(t,this.resolvedOptions.thousandSeparator):t;this.rawValue=n,this.element.value=this.formatValueForDisplay(n)}else this.element.value=t}disable(){this.element.disabled=!0}enable(){this.element.disabled=!1}addEventListener(t,n){this.element.addEventListener(t,n)}removeEventListener(t,n){this.element.removeEventListener(t,n)}getElement(){return this.element}get value(){return this.getValue()}set value(t){this.setValue(t)}get valueAsNumber(){const t=this.getValue();if(!t)return NaN;const n=this.resolvedOptions.thousandSeparator?v(t,this.resolvedOptions.thousandSeparator):t,r=this.resolvedOptions.decimalSeparator&&this.resolvedOptions.decimalSeparator!=="."?n.replace(new RegExp(y(this.resolvedOptions.decimalSeparator),"g"),"."):n;return parseFloat(r)}set valueAsNumber(t){if(isNaN(t)){this.setValue("");return}const n=t.toString();this.setValue(n)}}exports.FormatOn=N;exports.NumoraInput=ft;exports.ThousandStyle=m;exports.applyLocale=se;exports.formatInputValue=M;exports.formatValueForDisplay=tt;exports.getNumoraPattern=re;exports.getSeparatorsFromLocale=ie;exports.handleOnChangeNumoraInput=te;exports.handleOnKeyDownNumoraInput=ee;exports.handleOnPasteNumoraInput=ne;exports.removeThousandSeparators=v;exports.validateNumoraInputOptions=ae;
package/dist/index.mjs CHANGED
@@ -1,19 +1,19 @@
1
1
  var ne = Object.defineProperty;
2
2
  var re = (e, t, n) => t in e ? ne(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
3
  var w = (e, t, n) => re(e, typeof t != "symbol" ? t + "" : t, n);
4
- var N = /* @__PURE__ */ ((e) => (e.Blur = "blur", e.Change = "change", e))(N || {}), p = /* @__PURE__ */ ((e) => (e.None = "none", e.Thousand = "thousand", e.Lakh = "lakh", e.Wan = "wan", e.Locale = "locale", e))(p || {});
5
- const G = 2, B = 0, Z = N.Blur, ie = ",", H = p.None, C = ".", k = !1, W = !1, U = !1, z = !1;
6
- function y(e) {
4
+ var N = /* @__PURE__ */ ((e) => (e.Blur = "blur", e.Change = "change", e))(N || {}), m = /* @__PURE__ */ ((e) => (e.None = "none", e.Thousand = "thousand", e.Lakh = "lakh", e.Wan = "wan", e))(m || {});
5
+ const G = 2, B = 0, Z = N.Blur, ie = ",", k = m.None, C = ".", W = !1, U = !1, z = !1, J = !1;
6
+ function M(e) {
7
7
  return e.replace(/[-[\]/{}()*+?.\\^$|]/g, "\\$&");
8
8
  }
9
- const J = /* @__PURE__ */ new Map();
9
+ const P = /* @__PURE__ */ new Map();
10
10
  function T(e, t = "g") {
11
11
  const n = `${e}:${t}`;
12
- let r = J.get(n);
13
- return r || (r = new RegExp(e, t), J.set(n, r)), r;
12
+ let r = P.get(n);
13
+ return r || (r = new RegExp(e, t), P.set(n, r)), r;
14
14
  }
15
15
  function se(e, t = "g") {
16
- const n = y(e);
16
+ const n = M(e);
17
17
  return T(n, t);
18
18
  }
19
19
  const ae = /[.,]/g;
@@ -36,20 +36,20 @@ function ce(e, t) {
36
36
  const { selectionStart: n, selectionEnd: r, value: i } = e;
37
37
  return !i.slice(n ?? 0, r ?? 0).includes(t);
38
38
  }
39
- function le(e, t, n) {
39
+ function oe(e, t, n) {
40
40
  const { key: r } = e;
41
41
  if (r !== "," && r !== ".") return !1;
42
42
  if (ce(t, n))
43
43
  return !0;
44
44
  if (r !== n) {
45
- const { selectionStart: i, selectionEnd: s, value: a } = t, c = i ?? 0, o = s ?? c;
46
- t.value = a.slice(0, c) + n + a.slice(o);
47
- const l = c + 1;
48
- return t.setSelectionRange(l, l), !0;
45
+ const { selectionStart: i, selectionEnd: s, value: a } = t, c = i ?? 0, l = s ?? c;
46
+ t.value = a.slice(0, c) + n + a.slice(l);
47
+ const o = c + 1;
48
+ return t.setSelectionRange(o, o), !0;
49
49
  }
50
50
  return !1;
51
51
  }
52
- const oe = (e, t, n = C) => {
52
+ const le = (e, t, n = C) => {
53
53
  const { sign: r, integer: i, decimal: s } = Y(e, n);
54
54
  if (!s) return e;
55
55
  const a = s.slice(0, t);
@@ -57,7 +57,7 @@ const oe = (e, t, n = C) => {
57
57
  }, he = (e, t = C) => {
58
58
  const n = e.indexOf(t);
59
59
  if (n === -1 || n === e.length - 1) return e;
60
- const r = e.slice(0, n + 1), i = e.slice(n + 1), a = t === "." || t === "," ? ae : T("[,\\." + y(t) + "]", "g");
60
+ const r = e.slice(0, n + 1), i = e.slice(n + 1), a = t === "." || t === "," ? ae : T("[,\\." + M(t) + "]", "g");
61
61
  return r + i.replace(a, "");
62
62
  }, ue = (e, t = 0, n = C) => {
63
63
  if (t <= 0) return e;
@@ -71,39 +71,39 @@ const oe = (e, t, n = C) => {
71
71
  lakh: { firstGroup: 3, restGroup: 2 },
72
72
  wan: { size: 4 }
73
73
  }, de = /^(0+)/;
74
- function Q(e, t, n = p.Thousand, r = !1, i = ".") {
74
+ function Q(e, t, n = m.Thousand, r = !1, i = ".") {
75
75
  if (!e || e === "0" || e === i || e === "-" || e === `-${i}`)
76
76
  return e;
77
- const s = e.includes(i), a = e.startsWith("-"), c = a ? e.slice(1) : e, [o, l] = c.split(i);
78
- if (!o) {
79
- const u = l ? `${i}${l}` : c;
77
+ const s = e.includes(i), a = e.startsWith("-"), c = a ? e.slice(1) : e, [l, o] = c.split(i);
78
+ if (!l) {
79
+ const u = o ? `${i}${o}` : c;
80
80
  return a ? `-${u}` : u;
81
81
  }
82
- if (r && o.startsWith("0") && o.length > 1) {
83
- const u = o.match(de);
82
+ if (r && l.startsWith("0") && l.length > 1) {
83
+ const u = l.match(de);
84
84
  if (u) {
85
- const S = u[1], E = o.slice(S.length);
85
+ const S = u[1], E = l.slice(S.length);
86
86
  if (E) {
87
- const m = P(E, t, n), f = S + m, g = a ? "-" : "";
88
- return s ? l ? `${g}${f}${i}${l}` : `${g}${f}${i}` : `${g}${f}`;
87
+ const p = X(E, t, n), g = S + p, d = a ? "-" : "";
88
+ return s ? o ? `${d}${g}${i}${o}` : `${d}${g}${i}` : `${d}${g}`;
89
89
  }
90
90
  }
91
91
  }
92
- const h = P(o, t, n), d = a ? "-" : "";
93
- return s ? l ? `${d}${h}${i}${l}` : `${d}${h}${i}` : `${d}${h}`;
92
+ const h = X(l, t, n), f = a ? "-" : "";
93
+ return s ? o ? `${f}${h}${i}${o}` : `${f}${h}${i}` : `${f}${h}`;
94
94
  }
95
- function P(e, t, n) {
95
+ function X(e, t, n) {
96
96
  if (e === "0" || e === "")
97
97
  return e;
98
98
  switch (n) {
99
- case p.None:
99
+ case m.None:
100
100
  return e;
101
- case p.Thousand:
102
- return X(e, t, D.thousand.size);
103
- case p.Lakh:
101
+ case m.Thousand:
102
+ return j(e, t, D.thousand.size);
103
+ case m.Lakh:
104
104
  return fe(e, t);
105
- case p.Wan:
106
- return X(e, t, D.wan.size);
105
+ case m.Wan:
106
+ return j(e, t, D.wan.size);
107
107
  default:
108
108
  return e;
109
109
  }
@@ -117,7 +117,7 @@ function fe(e, t) {
117
117
  n.unshift(e.slice(Math.max(0, i - D.lakh.restGroup), i));
118
118
  return n.join(t);
119
119
  }
120
- function X(e, t, n) {
120
+ function j(e, t, n) {
121
121
  const r = [];
122
122
  for (let i = e.length; i > 0; i -= n)
123
123
  r.unshift(e.slice(Math.max(0, i - n), i));
@@ -127,7 +127,7 @@ function ge(e, t, n) {
127
127
  return (t == null ? void 0 : t.formatOn) === N.Change && t.thousandSeparator ? Q(
128
128
  e,
129
129
  t.thousandSeparator,
130
- t.ThousandStyle ?? p.None,
130
+ t.ThousandStyle ?? m.None,
131
131
  t.enableLeadingZeros,
132
132
  (n == null ? void 0 : n.decimalSeparator) ?? C
133
133
  ) : e;
@@ -167,7 +167,7 @@ function V(e, t, n) {
167
167
  return t < 0 || t >= e.length ? !1 : e[t] === n;
168
168
  }
169
169
  const Ee = /\d/;
170
- function me(e, t = {}) {
170
+ function pe(e, t = {}) {
171
171
  const {
172
172
  thousandSeparator: n,
173
173
  decimalSeparator: r = ".",
@@ -179,8 +179,8 @@ function me(e, t = {}) {
179
179
  a.fill(!1, c + 1, e.length + 1);
180
180
  }
181
181
  for (let c = 0; c < e.length; c++) {
182
- const o = e[c];
183
- (n && o === n || o === r) && (a[c] = !1, c + 1 < e.length && !Ee.test(e[c + 1]) && (a[c + 1] = !1));
182
+ const l = e[c];
183
+ (n && l === n || l === r) && (a[c] = !1, c + 1 < e.length && !Ee.test(e[c + 1]) && (a[c + 1] = !1));
184
184
  }
185
185
  return a.some((c) => c) || a.fill(!0), a;
186
186
  }
@@ -205,102 +205,102 @@ function x(e, t, n, r) {
205
205
  }
206
206
  return (t === -1 || t > i) && (t = i), t;
207
207
  }
208
- const j = /(\d+\.?\d*)\s*[kmbt]$/i, pe = (e, t) => e === t;
209
- function be(e, t, n, r, i, s, a = ".", c = {}) {
208
+ const K = /(\d+\.?\d*)\s*[kmbt]$/i, be = (e, t) => e === t;
209
+ function me(e, t, n, r, i, s, a = ".", c = {}) {
210
210
  if (n < 0)
211
211
  return 0;
212
- if (n > e.length || e === "" || t === "" || j.test(e) && !j.test(t) && t.length > e.length && n >= e.length - 1)
212
+ if (n > e.length || e === "" || t === "" || K.test(e) && !K.test(t) && t.length > e.length && n >= e.length - 1)
213
213
  return t.length;
214
- const o = t.length < e.length, l = V(
214
+ const l = t.length < e.length, o = V(
215
215
  e,
216
216
  n,
217
217
  r
218
- ), h = e.indexOf(a), d = t.indexOf(a);
218
+ ), h = e.indexOf(a), f = t.indexOf(a);
219
219
  if (c.isCharacterEquivalent && e !== t) {
220
- const f = {
220
+ const g = {
221
221
  thousandSeparator: r || void 0,
222
222
  ...c
223
- }, g = Le(
223
+ }, d = Le(
224
224
  e,
225
225
  t,
226
226
  n,
227
- c.isCharacterEquivalent || pe,
227
+ c.isCharacterEquivalent || be,
228
228
  s,
229
- f
229
+ g
230
230
  );
231
- if (g !== void 0)
232
- return g;
231
+ if (d !== void 0)
232
+ return d;
233
233
  }
234
- const S = /* @__PURE__ */ new Map(), E = (f, g, L) => {
235
- const b = `${f === e ? "o" : "n"}:${g}`;
236
- return S.has(b) || S.set(b, $(f, g, r)), S.get(b);
234
+ const S = /* @__PURE__ */ new Map(), E = (g, d, L) => {
235
+ const b = `${g === e ? "o" : "n"}:${d}`;
236
+ return S.has(b) || S.set(b, $(g, d, r)), S.get(b);
237
237
  };
238
- if (o)
238
+ if (l)
239
239
  return Ne(
240
240
  e,
241
241
  t,
242
242
  n,
243
243
  r,
244
- l,
244
+ o,
245
245
  h,
246
- d,
246
+ f,
247
247
  s,
248
248
  c,
249
249
  E
250
250
  );
251
- const m = Ce(
251
+ const p = Ce(
252
252
  e,
253
253
  t,
254
254
  n,
255
255
  r,
256
- l,
256
+ o,
257
257
  E
258
258
  );
259
- return c.boundary ? x(t, m, c.boundary) : m;
259
+ return c.boundary ? x(t, p, c.boundary) : p;
260
260
  }
261
261
  function Le(e, t, n, r, i, s) {
262
262
  const a = e.length, c = t.length;
263
- let o = 0, l = 0, h = c;
264
- for (let g = 0; g < a; g++) {
263
+ let l = 0, o = 0, h = c;
264
+ for (let d = 0; d < a; d++) {
265
265
  let L = -1;
266
- for (let b = o; b < c; b++)
266
+ for (let b = l; b < c; b++)
267
267
  if (r(
268
- e[g],
268
+ e[d],
269
269
  t[b],
270
270
  {
271
271
  oldValue: e,
272
272
  newValue: t,
273
273
  typedRange: i,
274
- oldIndex: g,
274
+ oldIndex: d,
275
275
  newIndex: b
276
276
  }
277
277
  )) {
278
278
  L = b;
279
279
  break;
280
280
  }
281
- L !== -1 && (o = L + 1, g < n ? l = L + 1 : h === c && /\d/.test(e[g]) && (h = L));
281
+ L !== -1 && (l = L + 1, d < n ? o = L + 1 : h === c && /\d/.test(e[d]) && (h = L));
282
282
  }
283
- if (l > h) return h;
284
- const d = t.length < e.length || i !== void 0 && i.isDelete === !1;
283
+ if (o > h) return h;
284
+ const f = t.length < e.length || i !== void 0 && i.isDelete === !1;
285
285
  let u, S = !1, E = !1;
286
- if (d) {
287
- u = l;
288
- const g = s.thousandSeparator, L = s.decimalSeparator ?? ".", b = u < t.length ? t[u] : "";
289
- g && b === g ? (n > 0 ? e[n - 1] : "") === g ? (u = h, S = !0) : E = !0 : b === L && (E = !0);
286
+ if (f) {
287
+ u = o;
288
+ const d = s.thousandSeparator, L = s.decimalSeparator ?? ".", b = u < t.length ? t[u] : "";
289
+ d && b === d ? (n > 0 ? e[n - 1] : "") === d ? (u = h, S = !0) : E = !0 : b === L && (E = !0);
290
290
  } else
291
- u = n - l < h - n ? l : h;
292
- const m = d && !S ? "left" : "right";
291
+ u = n - o < h - n ? o : h;
292
+ const p = f && !S ? "left" : "right";
293
293
  if (s.boundary)
294
- return E ? u : x(t, u, s.boundary, m);
295
- const f = s.thousandSeparator;
296
- if (!E && f && u >= 0 && u < t.length && t[u] === f)
297
- if (d && !S)
298
- for (; u > 0 && t[u] === f; ) u--;
294
+ return E ? u : x(t, u, s.boundary, p);
295
+ const g = s.thousandSeparator;
296
+ if (!E && g && u >= 0 && u < t.length && t[u] === g)
297
+ if (f && !S)
298
+ for (; u > 0 && t[u] === g; ) u--;
299
299
  else
300
- for (; u < t.length && t[u] === f; ) u++;
300
+ for (; u < t.length && t[u] === g; ) u++;
301
301
  return u;
302
302
  }
303
- function Ne(e, t, n, r, i, s, a, c, o = {}, l = $) {
303
+ function Ne(e, t, n, r, i, s, a, c, l = {}, o = $) {
304
304
  if (i)
305
305
  return $e(
306
306
  e,
@@ -308,9 +308,9 @@ function Ne(e, t, n, r, i, s, a, c, o = {}, l = $) {
308
308
  n,
309
309
  r,
310
310
  a,
311
- l
311
+ o
312
312
  );
313
- const h = l(e, n, r), d = l(e, e.length, r), u = l(t, t.length, r), S = d - u, E = ve(
313
+ const h = o(e, n, r), f = o(e, e.length, r), u = o(t, t.length, r), S = f - u, E = ve(
314
314
  e,
315
315
  n,
316
316
  r,
@@ -318,39 +318,39 @@ function Ne(e, t, n, r, i, s, a, c, o = {}, l = $) {
318
318
  S,
319
319
  s,
320
320
  c,
321
- l
322
- ), m = s === -1 || n <= s, f = De(
321
+ o
322
+ ), p = s === -1 || n <= s, g = De(
323
323
  t,
324
324
  E,
325
325
  r,
326
326
  S,
327
327
  c,
328
- m,
328
+ p,
329
329
  a,
330
- l
330
+ o
331
331
  );
332
- return o.boundary ? x(t, f, o.boundary) : f;
332
+ return l.boundary ? x(t, g, l.boundary) : g;
333
333
  }
334
334
  function $e(e, t, n, r, i, s = $) {
335
335
  const a = n + 1;
336
336
  if (a < e.length) {
337
- const c = s(e, a, r), o = Se(
337
+ const c = s(e, a, r), l = Se(
338
338
  t,
339
339
  c,
340
340
  r
341
341
  );
342
- return o < t.length && t[o] !== r ? o + 1 : o;
342
+ return l < t.length && t[l] !== r ? l + 1 : l;
343
343
  }
344
344
  return n;
345
345
  }
346
346
  function ve(e, t, n, r, i, s, a, c = $) {
347
347
  if (a) {
348
- const { start: l, isDelete: h } = a;
349
- return h ? c(e, l, n) : Math.max(0, c(e, l, n));
348
+ const { start: o, isDelete: h } = a;
349
+ return h ? c(e, o, n) : Math.max(0, c(e, o, n));
350
350
  }
351
351
  return t > 0 && e[t - 1] === n && i > 0 ? r + 1 : r;
352
352
  }
353
- function K(e, t, n, r, i, s, a = $) {
353
+ function q(e, t, n, r, i, s, a = $) {
354
354
  if (t > 0 && t < e.length && a(e, t, r) === n) {
355
355
  if (e[t] === r && s && i > 0 && t < e.length - 1)
356
356
  return t + 1;
@@ -361,33 +361,33 @@ function K(e, t, n, r, i, s, a = $) {
361
361
  }
362
362
  function De(e, t, n, r, i, s, a, c = $) {
363
363
  if (s && a !== -1) {
364
- const l = e.substring(0, a), h = c(l, l.length, n);
364
+ const o = e.substring(0, a), h = c(o, o.length, n);
365
365
  if (t <= h) {
366
- const d = R(
367
- l,
366
+ const f = R(
367
+ o,
368
368
  t,
369
369
  n
370
370
  );
371
- return K(l, d, t, n, r, i, c);
371
+ return q(o, f, t, n, r, i, c);
372
372
  }
373
373
  }
374
- const o = R(
374
+ const l = R(
375
375
  e,
376
376
  t,
377
377
  n
378
378
  );
379
- return K(e, o, t, n, r, i, c);
379
+ return q(e, l, t, n, r, i, c);
380
380
  }
381
381
  function Ce(e, t, n, r, i, s = $) {
382
- const a = n >= e.length, c = s(e, n, r), o = s(e, e.length, r), l = s(t, t.length, r);
383
- if (a || c === o)
382
+ const a = n >= e.length, c = s(e, n, r), l = s(e, e.length, r), o = s(t, t.length, r);
383
+ if (a || c === l)
384
384
  return t.length;
385
- const h = l - o;
386
- let d = c;
387
- h > 0 && !a && c < o && (d = c + 1);
385
+ const h = o - l;
386
+ let f = c;
387
+ h > 0 && !a && c < l && (f = c + 1);
388
388
  const u = R(
389
389
  t,
390
- d,
390
+ f,
391
391
  r
392
392
  );
393
393
  return i && !V(t, u, r) ? Math.max(0, u - 1) : u;
@@ -412,16 +412,16 @@ function we(e, t, n) {
412
412
  isDelete: !0
413
413
  };
414
414
  }
415
- const c = t.length, o = n.length, l = c - o;
416
- if (!(l <= 0))
415
+ const c = t.length, l = n.length, o = c - l;
416
+ if (!(o <= 0))
417
417
  return {
418
418
  start: r,
419
- end: r + l,
420
- deletedLength: l,
419
+ end: r + o,
420
+ deletedLength: o,
421
421
  isDelete: !1
422
422
  };
423
423
  }
424
- function ye(e, t) {
424
+ function Me(e, t) {
425
425
  if (e === t)
426
426
  return;
427
427
  let n = 0;
@@ -439,7 +439,7 @@ function ye(e, t) {
439
439
  isDelete: s > a
440
440
  };
441
441
  }
442
- function q(e, t) {
442
+ function H(e, t) {
443
443
  if (e.value = e.value, e === null)
444
444
  return !1;
445
445
  if (e.createTextRange) {
@@ -448,9 +448,9 @@ function q(e, t) {
448
448
  }
449
449
  return e.selectionStart !== null || e.selectionStart === 0 ? (e.focus(), e.setSelectionRange(t, t), !0) : (e.focus(), !1);
450
450
  }
451
- function Me(e, t, n) {
452
- return e.selectionStart === 0 && e.selectionEnd === e.value.length ? null : (q(e, t), setTimeout(() => {
453
- e.value === n && e.selectionStart !== t && q(e, t);
451
+ function ye(e, t, n) {
452
+ return e.selectionStart === 0 && e.selectionEnd === e.value.length ? null : (H(e, t), setTimeout(() => {
453
+ e.value === n && e.selectionStart !== t && H(e, t);
454
454
  }, 0));
455
455
  }
456
456
  function Ae(e) {
@@ -467,25 +467,25 @@ function Ie(e, t, n) {
467
467
  }
468
468
  function Re(e, t, n, r, i, s, a) {
469
469
  if (!i) return;
470
- const { selectionStart: c = 0, selectionEnd: o = 0, endOffset: l = 0 } = i;
470
+ const { selectionStart: c = 0, selectionEnd: l = 0, endOffset: o = 0 } = i;
471
471
  let h = we(
472
- { selectionStart: c, selectionEnd: o, endOffset: l },
472
+ { selectionStart: c, selectionEnd: l, endOffset: o },
473
473
  t,
474
474
  n
475
475
  );
476
- if (h || (h = ye(t, n)), !h) return;
477
- const d = me(n, {
476
+ if (h || (h = Me(t, n)), !h) return;
477
+ const f = pe(n, {
478
478
  thousandSeparator: (a == null ? void 0 : a.thousandSeparator) ?? s.thousandSeparator,
479
479
  decimalSeparator: s.decimalSeparator
480
480
  }), u = {
481
481
  thousandSeparator: (a == null ? void 0 : a.thousandSeparator) ?? s.thousandSeparator,
482
482
  decimalSeparator: s.decimalSeparator,
483
- isCharacterEquivalent: (f, g) => {
483
+ isCharacterEquivalent: (g, d) => {
484
484
  const L = (a == null ? void 0 : a.thousandSeparator) ?? s.thousandSeparator;
485
- return L && f === L ? !1 : f === g;
485
+ return L && g === L ? !1 : g === d;
486
486
  },
487
- boundary: d
488
- }, S = (a == null ? void 0 : a.thousandSeparator) ?? s.thousandSeparator ?? ",", E = (a == null ? void 0 : a.ThousandStyle) ?? p.None, m = be(
487
+ boundary: f
488
+ }, S = (a == null ? void 0 : a.thousandSeparator) ?? s.thousandSeparator ?? ",", E = (a == null ? void 0 : a.ThousandStyle) ?? m.None, p = me(
489
489
  t,
490
490
  n,
491
491
  r,
@@ -495,10 +495,10 @@ function Re(e, t, n, r, i, s, a) {
495
495
  s.decimalSeparator,
496
496
  u
497
497
  );
498
- Me(e, m, n);
498
+ ye(e, p, n);
499
499
  }
500
500
  const Te = (e, t = !1, n = ".") => {
501
- const r = y(n), i = T(`[^0-9${r}]`, "g");
501
+ const r = M(n), i = T(`[^0-9${r}]`, "g");
502
502
  if (!t)
503
503
  return e.replace(i, "");
504
504
  const s = e.startsWith("-"), a = e.replace(i, "");
@@ -508,8 +508,8 @@ function xe(e) {
508
508
  return !e.includes("e") && !e.includes("E") ? e : e.replace(_e, (t, n, r) => {
509
509
  const i = parseInt(r, 10);
510
510
  if (i === 0) return n;
511
- const s = n.startsWith("-"), a = s ? n.slice(1) : n, [c, o = ""] = a.split("."), l = i > 0 ? Oe(c, o, i) : Ge(c, o, Math.abs(i));
512
- return s ? "-" + l : l;
511
+ const s = n.startsWith("-"), a = s ? n.slice(1) : n, [c, l = ""] = a.split("."), o = i > 0 ? Oe(c, l, i) : Ge(c, l, Math.abs(i));
512
+ return s ? "-" + o : o;
513
513
  });
514
514
  }
515
515
  function Oe(e, t, n) {
@@ -534,8 +534,8 @@ function Ge(e, t, n) {
534
534
  return I(c);
535
535
  }
536
536
  if (s < e.length) {
537
- const a = r.slice(0, s), c = r.slice(s), o = `${a}.${c}`;
538
- return I(o);
537
+ const a = r.slice(0, s), c = r.slice(s), l = `${a}.${c}`;
538
+ return I(l);
539
539
  }
540
540
  return I(r);
541
541
  }
@@ -569,18 +569,18 @@ function Je(e) {
569
569
  const i = r.toLowerCase(), s = ze[i];
570
570
  if (!s)
571
571
  return t;
572
- const [a, c = ""] = n.split("."), o = a.replace(Ze, "") || "0";
573
- let l;
572
+ const [a, c = ""] = n.split("."), l = a.replace(Ze, "") || "0";
573
+ let o;
574
574
  if (c.length === 0)
575
- l = o + "0".repeat(s);
575
+ o = l + "0".repeat(s);
576
576
  else if (c.length <= s) {
577
577
  const h = s - c.length;
578
- l = o + c + "0".repeat(h);
578
+ o = l + c + "0".repeat(h);
579
579
  } else {
580
- const h = c.slice(0, s), d = c.slice(s);
581
- l = o + h + "." + d;
580
+ const h = c.slice(0, s), f = c.slice(s);
581
+ o = l + h + "." + f;
582
582
  }
583
- return l = l.replace(ke, "$1$2"), We.test(l) && (l = "0"), l.includes(".") && (l = l.replace(Ue, "")), l;
583
+ return o = o.replace(ke, "$1$2"), We.test(o) && (o = "0"), o.includes(".") && (o = o.replace(Ue, "")), o;
584
584
  });
585
585
  }
586
586
  function Pe(e) {
@@ -631,18 +631,18 @@ function O(e, t, n, r) {
631
631
  const i = _(n), s = r ?? (n == null ? void 0 : n.formatOn) === N.Change, a = je(
632
632
  e,
633
633
  Ke(n, i, s)
634
- ), c = oe(
634
+ ), c = le(
635
635
  a,
636
636
  t,
637
637
  i.decimalSeparator
638
- ), o = (n == null ? void 0 : n.decimalMinLength) ?? 0, l = ue(
638
+ ), l = (n == null ? void 0 : n.decimalMinLength) ?? 0, o = ue(
639
639
  c,
640
- o,
640
+ l,
641
641
  i.decimalSeparator
642
642
  );
643
- return { formatted: ge(l, n, i), raw: l };
643
+ return { formatted: ge(o, n, i), raw: o };
644
644
  }
645
- function ft(e, t, n) {
645
+ function gt(e, t, n) {
646
646
  const r = !!(n != null && n.thousandSeparator);
647
647
  return O(
648
648
  e,
@@ -661,28 +661,28 @@ function qe(e, t, n) {
661
661
  }
662
662
  function He(e, t) {
663
663
  const { decimalSeparator: n } = _(t), r = e.target;
664
- if (le(e, r, n)) {
664
+ if (oe(e, r, n)) {
665
665
  e.preventDefault();
666
666
  return;
667
667
  }
668
668
  return Ie(e, r, t), qe(e.key, r.selectionStart, r.selectionEnd);
669
669
  }
670
670
  function Ye(e, t, n, r) {
671
- const i = e.target, s = i.value, a = Ae(i), c = _(r), o = (r == null ? void 0 : r.formatOn) === N.Change, { formatted: l, raw: h } = O(
671
+ const i = e.target, s = i.value, a = Ae(i), c = _(r), l = (r == null ? void 0 : r.formatOn) === N.Change, { formatted: o, raw: h } = O(
672
672
  s,
673
673
  t,
674
674
  r,
675
- o
675
+ l
676
676
  );
677
- return i.value = l, s !== l && Re(
677
+ return i.value = o, s !== o && Re(
678
678
  i,
679
679
  s,
680
- l,
680
+ o,
681
681
  a,
682
682
  n,
683
683
  c,
684
684
  r
685
- ), { formatted: l, raw: h };
685
+ ), { formatted: o, raw: h };
686
686
  }
687
687
  function Qe(e, t, n, r) {
688
688
  const i = r - n;
@@ -691,23 +691,23 @@ function Qe(e, t, n, r) {
691
691
  function Ve(e, t, n) {
692
692
  var u;
693
693
  e.preventDefault();
694
- const r = e.target, { value: i, selectionStart: s, selectionEnd: a } = r, c = ((u = e.clipboardData) == null ? void 0 : u.getData("text/plain")) || "", o = i.slice(0, s || 0) + c + i.slice(a || 0), { formatted: l, raw: h } = O(
695
- o,
694
+ const r = e.target, { value: i, selectionStart: s, selectionEnd: a } = r, c = ((u = e.clipboardData) == null ? void 0 : u.getData("text/plain")) || "", l = i.slice(0, s || 0) + c + i.slice(a || 0), { formatted: o, raw: h } = O(
695
+ l,
696
696
  t,
697
697
  n,
698
698
  !0
699
699
  );
700
- r.value = l;
701
- const d = Qe(
700
+ r.value = o;
701
+ const f = Qe(
702
702
  s || 0,
703
703
  c.length,
704
- o.length,
705
- l.length
704
+ l.length,
705
+ o.length
706
706
  );
707
- return r.setSelectionRange(d, d), { formatted: l, raw: h };
707
+ return r.setSelectionRange(f, f), { formatted: o, raw: h };
708
708
  }
709
709
  function Fe(e, t) {
710
- const n = y(e);
710
+ const n = M(e);
711
711
  return t ? `^-?[0-9]*[${n}]?[0-9]*$` : `^[0-9]*[${n}]?[0-9]*$`;
712
712
  }
713
713
  function et(e) {
@@ -722,16 +722,16 @@ function et(e) {
722
722
  return { thousandSeparator: ",", decimalSeparator: "." };
723
723
  }
724
724
  }
725
- function tt(e) {
726
- let t = e.thousandSeparator ?? ie, n = e.decimalSeparator ?? C, r = e.thousandStyle ?? H;
727
- if (e.thousandStyle === p.Locale || e.decimalSeparator === "auto") {
728
- const s = et();
729
- e.thousandStyle === p.Locale && (t = e.thousandSeparator ?? s.thousandSeparator, n = e.decimalSeparator === "auto" || e.decimalSeparator === void 0 ? s.decimalSeparator : e.decimalSeparator, r = p.Thousand), e.decimalSeparator === "auto" && (n = s.decimalSeparator);
730
- }
731
- return { thousandSeparator: t, thousandStyle: r, decimalSeparator: n };
725
+ function tt(e, t) {
726
+ if (!e) return t;
727
+ const r = et(e === !0 ? void 0 : e);
728
+ return {
729
+ thousandSeparator: t.thousandSeparator ?? r.thousandSeparator,
730
+ decimalSeparator: t.decimalSeparator ?? r.decimalSeparator
731
+ };
732
732
  }
733
733
  function nt(e) {
734
- rt(e.decimalMaxLength), it(e.decimalMinLength), st(e.decimalMinLength, e.decimalMaxLength), at(e.formatOn), ct(e.thousandSeparator), lt(e.thousandStyle), ot(e.decimalSeparator), ht(e.thousandSeparator, e.decimalSeparator), M("enableCompactNotation", e.enableCompactNotation), M("enableNegative", e.enableNegative), M("enableLeadingZeros", e.enableLeadingZeros), M("rawValueMode", e.rawValueMode), ut(e.onChange);
734
+ rt(e.decimalMaxLength), it(e.decimalMinLength), st(e.decimalMinLength, e.decimalMaxLength), at(e.formatOn), ct(e.thousandSeparator), ot(e.thousandStyle), lt(e.decimalSeparator), ht(e.thousandSeparator, e.decimalSeparator), y("enableCompactNotation", e.enableCompactNotation), y("enableNegative", e.enableNegative), y("enableLeadingZeros", e.enableLeadingZeros), y("rawValueMode", e.rawValueMode), ut(e.onChange);
735
735
  }
736
736
  function rt(e) {
737
737
  if (e !== void 0) {
@@ -793,14 +793,14 @@ function ct(e) {
793
793
  );
794
794
  }
795
795
  }
796
- function lt(e) {
797
- if (e !== void 0 && !Object.values(p).includes(e))
796
+ function ot(e) {
797
+ if (e !== void 0 && !Object.values(m).includes(e))
798
798
  throw new Error(
799
- `ThousandStyle must be one of: ${Object.values(p).map((t) => `'${t}'`).join(", ")}. Received: ${JSON.stringify(e)}`
799
+ `ThousandStyle must be one of: ${Object.values(m).map((t) => `'${t}'`).join(", ")}. Received: ${JSON.stringify(e)}`
800
800
  );
801
801
  }
802
- function ot(e) {
803
- if (!(e === void 0 || e === "auto")) {
802
+ function lt(e) {
803
+ if (e !== void 0) {
804
804
  if (typeof e != "string")
805
805
  throw new Error(
806
806
  `decimalSeparator must be a string. Received: ${typeof e} (${JSON.stringify(e)})`
@@ -816,12 +816,12 @@ function ot(e) {
816
816
  }
817
817
  }
818
818
  function ht(e, t) {
819
- if (!(e === void 0 || t === void 0) && t !== "auto" && e === t)
819
+ if (!(e === void 0 || t === void 0) && e === t)
820
820
  throw new Error(
821
821
  `Decimal separator can't be same as thousand separator. thousandSeparator: ${e}, decimalSeparator: ${t}`
822
822
  );
823
823
  }
824
- function M(e, t) {
824
+ function y(e, t) {
825
825
  if (t !== void 0 && typeof t != "boolean")
826
826
  throw new Error(
827
827
  `${e} must be a boolean. Received: ${typeof t} (${JSON.stringify(t)})`
@@ -833,20 +833,21 @@ function ut(e) {
833
833
  `onChange must be a function or undefined. Received: ${typeof e} (${JSON.stringify(e)})`
834
834
  );
835
835
  }
836
- class gt {
836
+ class St {
837
837
  constructor(t, {
838
838
  decimalMaxLength: n = G,
839
839
  decimalMinLength: r = B,
840
840
  formatOn: i = Z,
841
841
  thousandSeparator: s,
842
- thousandStyle: a = H,
842
+ thousandStyle: a = k,
843
843
  decimalSeparator: c,
844
- enableCompactNotation: o = k,
845
- enableNegative: l = W,
846
- enableLeadingZeros: h = U,
847
- rawValueMode: d = z,
848
- onChange: u,
849
- ...S
844
+ locale: l,
845
+ enableCompactNotation: o = W,
846
+ enableNegative: h = U,
847
+ enableLeadingZeros: f = z,
848
+ rawValueMode: u = J,
849
+ onChange: S,
850
+ ...E
850
851
  }) {
851
852
  w(this, "element");
852
853
  w(this, "resolvedOptions");
@@ -860,31 +861,32 @@ class gt {
860
861
  thousandStyle: a,
861
862
  decimalSeparator: c,
862
863
  enableCompactNotation: o,
863
- enableNegative: l,
864
- enableLeadingZeros: h,
865
- rawValueMode: d,
866
- onChange: u
864
+ enableNegative: h,
865
+ enableLeadingZeros: f,
866
+ rawValueMode: u,
867
+ onChange: S
867
868
  });
868
- const E = {
869
+ const p = {
869
870
  decimalMaxLength: n,
870
871
  decimalMinLength: r,
871
- onChange: u,
872
+ onChange: S,
872
873
  formatOn: i,
873
874
  thousandSeparator: s,
874
875
  thousandStyle: a,
875
876
  decimalSeparator: c,
877
+ locale: l,
876
878
  enableCompactNotation: o,
877
- enableNegative: l,
878
- enableLeadingZeros: h,
879
- rawValueMode: d,
880
- ...S
879
+ enableNegative: h,
880
+ enableLeadingZeros: f,
881
+ rawValueMode: u,
882
+ ...E
881
883
  };
882
- if (this.resolvedOptions = this.getResolvedOptions(E), this.createInputElement(t, E), this.setupEventListeners(), this.resolvedOptions.rawValueMode && this.element.value) {
883
- const m = this.element.value, f = this.resolvedOptions.thousandSeparator ? v(m, this.resolvedOptions.thousandSeparator) : m;
884
- this.rawValue = f, this.element.value = this.formatValueForDisplay(f);
884
+ if (this.resolvedOptions = this.getResolvedOptions(p), this.createInputElement(t, p), this.setupEventListeners(), this.resolvedOptions.rawValueMode && this.element.value) {
885
+ const g = this.element.value, d = this.resolvedOptions.thousandSeparator ? v(g, this.resolvedOptions.thousandSeparator) : g;
886
+ this.rawValue = d, this.element.value = this.formatValueForDisplay(d);
885
887
  } else if (this.element.value) {
886
- const m = this.element.value;
887
- this.element.value = this.formatValueForDisplay(m);
888
+ const g = this.element.value;
889
+ this.element.value = this.formatValueForDisplay(g);
888
890
  }
889
891
  }
890
892
  createInputElement(t, n) {
@@ -896,43 +898,43 @@ class gt {
896
898
  decimalMinLength: s,
897
899
  formatOn: a,
898
900
  thousandSeparator: c,
899
- thousandStyle: o,
900
- decimalSeparator: l,
901
- enableCompactNotation: h,
902
- enableNegative: d,
903
- enableLeadingZeros: u,
904
- rawValueMode: S,
905
- onChange: E,
906
- value: m,
907
- defaultValue: f,
908
- type: g,
909
- inputMode: L,
910
- spellcheck: b,
911
- autocomplete: ee,
901
+ thousandStyle: l,
902
+ decimalSeparator: o,
903
+ locale: h,
904
+ enableCompactNotation: f,
905
+ enableNegative: u,
906
+ enableLeadingZeros: S,
907
+ rawValueMode: E,
908
+ onChange: p,
909
+ value: g,
910
+ defaultValue: d,
911
+ type: L,
912
+ inputMode: b,
913
+ spellcheck: ee,
914
+ autocomplete: dt,
912
915
  ...te
913
916
  } = n;
914
- Object.assign(this.element, te), m !== void 0 ? this.element.value = m : f !== void 0 && (this.element.defaultValue = f, this.element.value = f), t.appendChild(this.element);
917
+ Object.assign(this.element, te), g !== void 0 ? this.element.value = g : d !== void 0 && (this.element.defaultValue = d, this.element.value = d), t.appendChild(this.element);
915
918
  }
916
919
  setupEventListeners() {
917
920
  this.element.addEventListener("input", this.handleChange.bind(this)), this.element.addEventListener("keydown", this.handleKeyDown.bind(this)), this.element.addEventListener("paste", this.handlePaste.bind(this)), this.resolvedOptions.formatOn === N.Blur && this.resolvedOptions.thousandSeparator && (this.element.addEventListener("focus", this.handleFocus.bind(this)), this.element.addEventListener("blur", this.handleBlur.bind(this)));
918
921
  }
919
922
  getResolvedOptions(t) {
920
- const n = tt({
923
+ const n = tt(t.locale, {
921
924
  thousandSeparator: t.thousandSeparator,
922
- thousandStyle: t.thousandStyle,
923
925
  decimalSeparator: t.decimalSeparator
924
926
  });
925
927
  return {
926
928
  decimalMaxLength: t.decimalMaxLength ?? G,
927
929
  decimalMinLength: t.decimalMinLength ?? B,
928
930
  formatOn: t.formatOn ?? Z,
929
- thousandSeparator: n.thousandSeparator,
930
- thousandStyle: n.thousandStyle,
931
- decimalSeparator: n.decimalSeparator,
932
- enableCompactNotation: t.enableCompactNotation ?? k,
933
- enableNegative: t.enableNegative ?? W,
934
- enableLeadingZeros: t.enableLeadingZeros ?? U,
935
- rawValueMode: t.rawValueMode ?? z,
931
+ thousandSeparator: n.thousandSeparator ?? ie,
932
+ thousandStyle: t.thousandStyle ?? k,
933
+ decimalSeparator: n.decimalSeparator ?? C,
934
+ enableCompactNotation: t.enableCompactNotation ?? W,
935
+ enableNegative: t.enableNegative ?? U,
936
+ enableLeadingZeros: t.enableLeadingZeros ?? z,
937
+ rawValueMode: t.rawValueMode ?? J,
936
938
  onChange: t.onChange
937
939
  };
938
940
  }
@@ -959,7 +961,7 @@ class gt {
959
961
  if (!t)
960
962
  return t;
961
963
  const { thousandSeparator: n, thousandStyle: r, enableLeadingZeros: i, decimalSeparator: s } = this.resolvedOptions;
962
- return n && r !== p.None ? Q(
964
+ return n && r !== m.None ? Q(
963
965
  t,
964
966
  n,
965
967
  r,
@@ -1006,7 +1008,7 @@ class gt {
1006
1008
  }
1007
1009
  handleBlur(t) {
1008
1010
  const n = t.target, { thousandSeparator: r, thousandStyle: i } = this.resolvedOptions;
1009
- if (r && i !== p.None && n.value) {
1011
+ if (r && i !== m.None && n.value) {
1010
1012
  const s = this.formatValueForDisplay(n.value);
1011
1013
  n.value = s;
1012
1014
  const a = this.resolvedOptions.rawValueMode ? v(s, r) : void 0;
@@ -1066,7 +1068,7 @@ class gt {
1066
1068
  const t = this.getValue();
1067
1069
  if (!t)
1068
1070
  return NaN;
1069
- const n = this.resolvedOptions.thousandSeparator ? v(t, this.resolvedOptions.thousandSeparator) : t, r = this.resolvedOptions.decimalSeparator && this.resolvedOptions.decimalSeparator !== "." ? n.replace(new RegExp(y(this.resolvedOptions.decimalSeparator), "g"), ".") : n;
1071
+ const n = this.resolvedOptions.thousandSeparator ? v(t, this.resolvedOptions.thousandSeparator) : t, r = this.resolvedOptions.decimalSeparator && this.resolvedOptions.decimalSeparator !== "." ? n.replace(new RegExp(M(this.resolvedOptions.decimalSeparator), "g"), ".") : n;
1070
1072
  return parseFloat(r);
1071
1073
  }
1072
1074
  /**
@@ -1083,16 +1085,16 @@ class gt {
1083
1085
  }
1084
1086
  export {
1085
1087
  N as FormatOn,
1086
- gt as NumoraInput,
1087
- p as ThousandStyle,
1088
+ St as NumoraInput,
1089
+ m as ThousandStyle,
1090
+ tt as applyLocale,
1088
1091
  O as formatInputValue,
1089
- ft as formatValueForDisplay,
1092
+ gt as formatValueForDisplay,
1090
1093
  Fe as getNumoraPattern,
1091
1094
  et as getSeparatorsFromLocale,
1092
1095
  Ye as handleOnChangeNumoraInput,
1093
1096
  He as handleOnKeyDownNumoraInput,
1094
1097
  Ve as handleOnPasteNumoraInput,
1095
1098
  v as removeThousandSeparators,
1096
- tt as resolveLocaleOptions,
1097
1099
  nt as validateNumoraInputOptions
1098
1100
  };
package/dist/types.d.ts CHANGED
@@ -6,8 +6,7 @@ export declare enum ThousandStyle {
6
6
  None = "none",
7
7
  Thousand = "thousand",
8
8
  Lakh = "lakh",
9
- Wan = "wan",
10
- Locale = "locale"
9
+ Wan = "wan"
11
10
  }
12
11
  export interface FormattingOptions {
13
12
  formatOn?: FormatOn;
@@ -1,14 +1,11 @@
1
- import { ThousandStyle } from '../types';
2
1
  export declare function getSeparatorsFromLocale(locale?: string): {
3
2
  thousandSeparator: string;
4
3
  decimalSeparator: string;
5
4
  };
6
- export declare function resolveLocaleOptions(options: {
5
+ export declare function applyLocale(locale: string | true | undefined, options: {
7
6
  thousandSeparator?: string;
8
- thousandStyle?: ThousandStyle;
9
7
  decimalSeparator?: string;
10
8
  }): {
11
- thousandSeparator: string;
12
- thousandStyle: ThousandStyle;
13
- decimalSeparator: string;
9
+ thousandSeparator?: string;
10
+ decimalSeparator?: string;
14
11
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "numora",
3
- "version": "3.3.0",
3
+ "version": "3.4.0",
4
4
  "description": "Framework-agnostic numeric input library for DeFi and financial apps",
5
5
  "homepage": "https://numora.xyz/",
6
6
  "main": "dist/index.js",