numora 2.0.2 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +94 -111
- package/dist/utils/event-handlers.d.ts +0 -10
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export * from './NumoraInput';
|
|
2
2
|
export { ThousandStyle, FormatOn } from './types';
|
|
3
|
-
export { handleOnChangeNumoraInput, handleOnPasteNumoraInput, handleOnKeyDownNumoraInput,
|
|
3
|
+
export { handleOnChangeNumoraInput, handleOnPasteNumoraInput, handleOnKeyDownNumoraInput, } from './utils/event-handlers';
|
|
4
4
|
export type { FormattingOptions, CaretPositionInfo } from './types';
|
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 w=(e,t,n)=>F(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var v=(e=>(e.Blur="blur",e.Change="change",e))(v||{}),b=(e=>(e.None="none",e.Thousand="thousand",e.Lakh="lakh",e.Wan="wan",e))(b||{});const x=2,O=0,R=v.Blur,_=",",P=b.None,E=".",B=!1,W=!1,k=!1,Z=!1;function m(e){return e.replace(/[-[\]/{}()*+?.\\^$|]/g,"\\$&")}function y(e){return{decimalSeparator:(e==null?void 0:e.decimalSeparator)??E,thousandSeparator:e==null?void 0:e.thousandSeparator}}function ee(e,t){if(e.key!==t)return!1;const n=e.target;return n?n.value.includes(t):!1}function te(e,t,n,r){const{selectionStart:i,selectionEnd:a,value:s}=t,{key:o}=e,c=n==null?void 0:n.ThousandStyle;if(c!==b.None&&c!==void 0||o!==","&&o!==".")return!1;if(ee(e,r))return!0;if(o!==r){const l=i??0,h=a??l,d=s.slice(0,l)+r+s.slice(h);t.value=d;const u=l+1;return t.setSelectionRange(u,u),!0}return!1}const ne=(e,t,n=E)=>{const[r,i]=e.split(n);return i?`${r}${n}${i.slice(0,t)}`:e},re=(e,t=E)=>{const n=m(t),r=new RegExp(`(${n}.*?)${n}`,"g");return e.replace(r,`$1${t}`)},se=(e,t=0,n=E)=>{if(t===0)return e;if(!e||e==="0"||e===n||e==="-"||e===`-${n}`)return e==="-"||e===`-${n}`?`-${n}${"0".repeat(t)}`:e===n?`${n}${"0".repeat(t)}`:`${e}${n}${"0".repeat(t)}`;const r=e.includes(n),i=e.startsWith("-"),a=i?e.slice(1):e,[s,o=""]=a.split(n);if(!r){const c="0".repeat(t);return i?`-${s}${n}${c}`:`${s}${n}${c}`}if(o.length<t){const c=t-o.length,l=o+"0".repeat(c);return i?`-${s}${n}${l}`:`${s}${n}${l}`}return e},ie=(e,t=!1,n=".")=>{const r=m(n),i=new RegExp(`[^0-9${r}]`,"g");if(!t)return e.replace(i,"");const a=e.startsWith("-"),s=e.replace(i,"");if(a){if(s.length>0)return"-"+s;if(e==="-")return"-"}return s};function ae(e){const t=/([+-]?\d+\.?\d*)[eE]([+-]?\d+)/g;let n=e,r;const i=[];for(;(r=t.exec(e))!==null;){const a=r[0],s=r[1],o=parseInt(r[2],10);let c;if(o===0)c=s;else{const l=s.startsWith("-"),h=l?s.slice(1):s,[d,u=""]=h.split(".");o>0?c=oe(d,u,o):c=ce(d,u,Math.abs(o)),l&&(c="-"+c)}i.push({full:a,expanded:c})}for(const{full:a,expanded:s}of i)n=n.replace(a,s);return n}function oe(e,t,n){const r=e+t;if(r==="0"||r.match(/^0+$/))return"0";const i=t.length;if(n<=i){const s=r.slice(0,e.length+n),o=r.slice(e.length+n);return o?`${s}.${o}`:s}const a=n-i;return r+"0".repeat(a)}function ce(e,t,n){const r=e+t;if(r==="0"||r.match(/^0+$/))return"0";const s=e.length-n;if(s<=0){const o=Math.abs(s),c=`0.${"0".repeat(o)}${r}`;return A(c)}if(s<e.length){const o=r.slice(0,s),c=r.slice(s),l=`${o}.${c}`;return A(l)}return A(r)}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 le(e){const t=/(\d+\.?\d*)\s*(Qa|Qi|Sx|Sp|[kmbMTO]|N)/gi;return e.replace(t,(n,r,i)=>{const a={k:3,m:6,M:6,b:9,T:12,Qa:15,Qi:18,Sx:21,Sp:24,O:27,N:30};let s;if(i.length>1)s=a[i]||a[i.charAt(0).toUpperCase()+i.slice(1).toLowerCase()];else{const f=i.toLowerCase();s=a[i]||a[f]}if(!s)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(s);else if(h.length<=s){const f=s-h.length;u=d+h+"0".repeat(f)}else{const f=h.slice(0,s),g=h.slice(s);u=d+f+"."+g}return u=u.replace(/^(-?)0+([1-9])/,"$1$2"),u.match(/^-?0+$/)&&(u=o?"-0":"0"),u=u.replace(/\.?0+$/,""),o&&!u.startsWith("-")?"-"+u:u})}function he(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[i,a]=n.split(".");if(i&&i.length>0){const o=(i.replace(/^0+/,"")||"0")+"."+a;return t?"-"+o:o}return e}if(n.startsWith("0")&&n.length>1){const i=n.replace(/^0+/,"")||"0";return t?"-"+i:i}return e}function ue(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 de=(e,t)=>{let n=ue(e);return t!=null&&t.thousandSeparator&&(n=L(n,t.thousandSeparator)),t!=null&&t.enableCompactNotation&&(n=le(n)),n=ae(n),n=ie(n,t==null?void 0:t.enableNegative,t==null?void 0:t.decimalSeparator),n=re(n,(t==null?void 0:t.decimalSeparator)||E),t!=null&&t.enableLeadingZeros||(n=he(n)),n};function fe(e,t,n){return{enableCompactNotation:e==null?void 0:e.enableCompactNotation,enableNegative:e==null?void 0:e.enableNegative,enableLeadingZeros:e==null?void 0:e.enableLeadingZeros,decimalSeparator:t.decimalSeparator,thousandSeparator:n?t.thousandSeparator:void 0}}const N={thousand:{size:3},lakh:{firstGroup:3,restGroup:2},wan:{size:4}};function z(e,t,n,r=!1,i="."){if(!e||e==="0"||e===i||e==="-"||e===`-${i}`)return e;const a=e.includes(i),s=e.startsWith("-"),o=s?e.slice(1):e,[c,l]=o.split(i);if(!c){const u=l?`${i}${l}`:o;return s?`-${u}`:u}if(r&&c.startsWith("0")&&c.length>1){const u=c.match(/^(0+)/);if(u){const f=u[1],g=c.slice(f.length);if(g){const p=G(g,t,n),$=f+p,D=s?"-":"";return a?l?`${D}${$}${i}${l}`:`${D}${$}${i}`:`${D}${$}`}}}const h=G(c,t,n),d=s?"-":"";return a?l?`${d}${h}${i}${l}`:`${d}${h}${i}`:`${d}${h}`}function G(e,t,n){if(e==="0"||e==="")return e;switch(n){case b.None:return e;case b.Thousand:return ge(e,t);case b.Lakh:return pe(e,t);case b.Wan:return be(e,t);default:return e}}function ge(e,t){return j(e,t,N.thousand.size)}function pe(e,t){if(e.length<=N.lakh.firstGroup)return e;const n=e.split("").reverse(),r=[],i=n.slice(0,N.lakh.firstGroup).reverse().join("");r.push(i);for(let a=N.lakh.firstGroup;a<n.length;a+=N.lakh.restGroup)r.push(n.slice(a,a+N.lakh.restGroup).reverse().join(""));return r.reverse().join(t)}function be(e,t){return j(e,t,N.wan.size)}function j(e,t,n){const r=e.split("").reverse(),i=[];for(let a=0;a<r.length;a+=n)i.push(r.slice(a,a+n).reverse().join(""));return i.reverse().join(t)}function Se(e,t,n){return(t==null?void 0:t.formatOn)==="change"&&t.thousandSeparator?z(e,t.thousandSeparator,t.ThousandStyle??b.None,t.enableLeadingZeros,(n==null?void 0:n.decimalSeparator)??E):e}function S(e,t,n,r="."){let i=0;for(let a=0;a<t&&a<e.length;a++){const s=e[a];s!==n&&s!==r&&i++}return i}function ve(e,t,n,r="."){if(t===0)return 0;let i=0;for(let a=0;a<e.length;a++){const s=e[a];if(s!==n&&s!==r){if(i===t-1)return a+1;i++}}return e.length}function C(e,t,n,r="."){if(t===0)return 0;let i=0;for(let a=0;a<e.length;a++){const s=e[a];if(s!==n&&s!==r){if(i++,i===t)return a+1;if(i>t)return a}}return e.length}function J(e,t,n){return t<0||t>=e.length?!1:e[t]===n}function $e(e,t={}){const{thousandSeparator:n,decimalSeparator:r=".",prefix:i="",suffix:a=""}=t,s=Array.from({length:e.length+1}).map(()=>!0);if(i&&s.fill(!1,0,i.length),a){const o=e.length-a.length;s.fill(!1,o+1,e.length+1)}for(let o=0;o<e.length;o++){const c=e[o];(n&&c===n||c===r)&&(s[o]=!1,o+1<e.length&&!/\d/.test(e[o+1])&&(s[o+1]=!1))}return s.some(o=>o)||s.fill(!0),s}function T(e,t,n,r){const i=e.length;if(t=Math.max(0,Math.min(t,i)),!n[t]){let a=t;for(;a<=i&&!n[a];)a++;let s=t;for(;s>=0&&!n[s];)s--;a<=i&&s>=0?t=t-s<a-t?s:a:a<=i?t=a:s>=0&&(t=s)}return(t===-1||t>i)&&(t=i),t}const H=(e,t)=>e===t;function Ee(e,t,n,r,i,a,s=".",o={}){if(n<0)return 0;if(n>e.length||e===""||t==="")return t.length;const c=t.length<e.length,l=J(e,n,r),h=e.indexOf(s),d=t.indexOf(s);if(o.isCharacterEquivalent&&e!==t){const g=Ne(e,t,n,o.isCharacterEquivalent||H,a,o);if(g!==void 0)return g}if(c)return we(e,t,n,r,l,h,d,a,s,o);const f=Me(e,t,n,r,l,s);return o.boundary?T(t,f,o.boundary):f}function Ne(e,t,n,r,i,a){const s=e.length,o=t.length,c={},l=new Array(s);for(let g=0;g<s;g++){l[g]=-1;for(let p=0;p<o;p++){if(c[p])continue;if(r(e[g],t[p],{oldValue:e,newValue:t,typedRange:i,oldIndex:g,newIndex:p})){l[g]=p,c[p]=!0;break}}}let h=n;for(;h<s&&(l[h]===-1||!/\d/.test(e[h]));)h++;const d=h===s||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 f=n-u<d-n?u:d;return a.boundary?T(t,f,a.boundary):f}function we(e,t,n,r,i,a,s,o,c,l={}){if(i)return Le(e,t,n,r,s,c);const h=S(e,n,r,c),d=S(e,e.length,r,c),u=S(t,t.length,r,c),f=d-u,g=me(e,n,r,h,f,a,o,c),p=a===-1||n<=a,$=De(t,g,r,f,o,c,p,s);return l.boundary?T(t,$,l.boundary):$}function Le(e,t,n,r,i,a){const s=n+1;if(s<e.length){const o=S(e,s,r,a),c=ve(t,o,r,a);return c<t.length&&t[c]!==r?c+1:c}return n}function me(e,t,n,r,i,a,s,o){if(s){const{start:l,isDelete:h}=s;return h?S(e,l,n,o):Math.max(0,S(e,l,n,o))}return t>0&&e[t-1]===n&&i>0?r+1:r}function De(e,t,n,r,i,a,s,o){if(s&&o!==-1){const l=e.substring(0,o),h=S(l,l.length,n,a);if(t<=h){const d=C(l,t,n,a);if(d>0&&d<l.length&&S(l,d,n,a)===t){if(l[d]===n&&i&&r>0&&d<l.length-1)return d+1;if(!i&&r>0&&d<l.length-1)return Math.min(d+1,l.length)}return d}}const c=C(e,t,n,a);if(c>0&&c<e.length&&S(e,c,n,a)===t){if(e[c]===n&&i&&r>0&&c<e.length-1)return c+1;if(!i&&r>0&&c<e.length-1)return Math.min(c+1,e.length)}return c}function Me(e,t,n,r,i,a){const s=n>=e.length,o=S(e,n,r,a),c=S(e,e.length,r,a),l=S(t,t.length,r,a);if(s||o===c)return t.length;const h=l-c;let d=o;h>0&&!s&&o<c&&(d=o+1);const u=C(t,d,r,a);return i&&!J(t,u,r)?Math.max(0,u-1):u}function ye(e,t,n){const{selectionStart:r,selectionEnd:i,endOffset:a=0}=e;if(r!==i){const h=i-r;return{start:r,end:i,deletedLength:h,isDelete:!1}}if(a>0){const h=a;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 Ae(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 a=r-n+1,s=i-n+1;if(!(a===0&&s===0))return{start:n,end:r+1,deletedLength:a,isDelete:a>s}}function U(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 Ce(e,t,n){return e.selectionStart===0&&e.selectionEnd===e.value.length?null:(U(e,t),setTimeout(()=>{e.value===n&&e.selectionStart!==t&&U(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)!==v.Change||!n.thousandSeparator)return;const{selectionStart:r,selectionEnd:i,value:a}=t;if(r===null||i===null||r!==i)return;const{key:s}=e,o=n.thousandSeparator;s==="Backspace"&&r>0&&a[r-1]===o&&t.setSelectionRange(r-1,r-1),s==="Delete"&&a[r]===o&&t.setSelectionRange(r+1,r+1)}function xe(e,t,n,r,i,a,s){if(!i)return;const{selectionStart:o=0,selectionEnd:c=0,endOffset:l=0}=i;let h=ye({selectionStart:o,selectionEnd:c,endOffset:l},t,n);if(h||(h=Ae(t,n)),!h)return;const d=$e(n,{thousandSeparator:(s==null?void 0:s.thousandSeparator)??a.thousandSeparator,decimalSeparator:a.decimalSeparator}),u={thousandSeparator:(s==null?void 0:s.thousandSeparator)??a.thousandSeparator,isCharacterEquivalent:H,boundary:d},f=(s==null?void 0:s.thousandSeparator)??a.thousandSeparator??",",g=(s==null?void 0:s.ThousandStyle)??b.None,p=Ee(t,n,r,f,g,h,a.decimalSeparator,u);Ce(e,p,n)}function I(e,t,n,r,i){const a=de(e,fe(r,i,n)),s=ne(a,t,i.decimalSeparator),o=(r==null?void 0:r.decimalMinLength)??0,c=se(s,o,i.decimalSeparator),l=c;return{formatted:Se(c,r,i),raw:l}}function Oe(e,t,n){if(e==="Backspace"||e==="Delete")return e==="Delete"&&t===n?{endOffset:1}:{endOffset:0}}function K(e,t){const{decimalSeparator:n}=y(t),r=e.target;if(te(e,r,t,n)){e.preventDefault();return}return Ie(e,r,t),Oe(e.key,r.selectionStart,r.selectionEnd)}function q(e,t,n,r){const i=e.target,a=i.value,s=Te(i),o=y(r),c=(r==null?void 0:r.formatOn)===v.Change,{formatted:l,raw:h}=I(a,t,c,r,o);i.value=l,r!=null&&r.rawValueMode&&i.setAttribute("data-raw-value",h),a!==l&&xe(i,a,l,s,n,o,r)}function Re(e,t,n,r){const i=r-n;return e+t+i}function Q(e,t,n){var f;e.preventDefault();const r=e.target,{value:i,selectionStart:a,selectionEnd:s}=r,o=y(n),c=((f=e.clipboardData)==null?void 0:f.getData("text/plain"))||"",l=i.slice(0,a||0)+c+i.slice(s||0),{formatted:h,raw:d}=I(l,t,!0,n,o);r.value=h,n!=null&&n.rawValueMode&&r.setAttribute("data-raw-value",d);const u=Re(a||0,c.length,l.length,h.length);return r.setSelectionRange(u,u),r.value}function _e(e,t,n){if(!e)return e;const r=y(n),i=!0,{formatted:a}=I(e,t,i,n,r);return a}function Pe(e,t){const n=m(e);return t?`^-?[0-9]*[${n}]?[0-9]*$`:`^[0-9]*[${n}]?[0-9]*$`}function Be(e){We(e.decimalMaxLength),ke(e.decimalMinLength),Ze(e.decimalMinLength,e.decimalMaxLength),Ge(e.formatOn),Ue(e.thousandSeparator),ze(e.thousandStyle),je(e.decimalSeparator),Je(e.thousandSeparator,e.decimalSeparator),M("enableCompactNotation",e.enableCompactNotation),M("enableNegative",e.enableNegative),M("enableLeadingZeros",e.enableLeadingZeros),M("rawValueMode",e.rawValueMode),He(e.onChange)}function We(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 ke(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 Ze(e,t){if(!(e===void 0||t===void 0)&&e>t)throw new Error(`decimalMinLength (${e}) cannot be greater than decimalMaxLength (${t}).`)}function Ge(e){if(e!==void 0&&e!==v.Blur&&e!==v.Change)throw new Error(`formatOn must be either ${v.Blur} or ${v.Change}. Received: ${JSON.stringify(e)}`)}function Ue(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(b).includes(e))throw new Error(`ThousandStyle must be one of: ${Object.values(b).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 Je(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 He(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 Ke{constructor(t,{decimalMaxLength:n=x,decimalMinLength:r=O,formatOn:i=R,thousandSeparator:a=_,thousandStyle:s=P,decimalSeparator:o=E,enableCompactNotation:c=B,enableNegative:l=W,enableLeadingZeros:h=k,rawValueMode:d=Z,onChange:u,...f}){w(this,"element");w(this,"options");w(this,"resolvedOptions");w(this,"rawValue","");w(this,"caretPositionBeforeChange");if(Be({decimalMaxLength:n,decimalMinLength:r,formatOn:i,thousandSeparator:a,thousandStyle:s,decimalSeparator:o,enableCompactNotation:c,enableNegative:l,enableLeadingZeros:h,rawValueMode:d,onChange:u}),this.options={decimalMaxLength:n,decimalMinLength:r,onChange:u,formatOn:i,thousandSeparator:a,thousandStyle:s,decimalSeparator:o,enableCompactNotation:c,enableNegative:l,enableLeadingZeros:h,rawValueMode:d,...f},this.resolvedOptions=this.getResolvedOptions(),this.createInputElement(t),this.setupEventListeners(),this.resolvedOptions.rawValueMode&&this.element.value){const g=this.element.value,p=this.resolvedOptions.thousandSeparator?L(g,this.resolvedOptions.thousandSeparator):g;this.rawValue=p,this.element.value=this.formatValueForDisplay(p)}else if(this.element.value&&!this.resolvedOptions.rawValueMode){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 Y=Pe(this.resolvedOptions.decimalSeparator,this.resolvedOptions.enableNegative);this.element.setAttribute("pattern",Y)}const{decimalMaxLength:n,decimalMinLength:r,formatOn:i,thousandSeparator:a,thousandStyle:s,decimalSeparator:o,enableCompactNotation:c,enableNegative:l,enableLeadingZeros:h,rawValueMode:d,onChange:u,value:f,defaultValue:g,type:p,inputMode:$,spellcheck:D,autocomplete:qe,...X}=this.options;Object.assign(this.element,X),f!==void 0?this.element.value=f: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===v.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??P,decimalSeparator:this.options.decimalSeparator??E,enableCompactNotation:this.options.enableCompactNotation??B,enableNegative:this.options.enableNegative??W,enableLeadingZeros:this.options.enableLeadingZeros??k,rawValueMode:this.options.rawValueMode??Z,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){const r=n??t;if(this.resolvedOptions.rawValueMode&&this.updateRawValue(r),this.resolvedOptions.onChange){const i=this.resolvedOptions.rawValueMode?this.rawValue:t;this.resolvedOptions.onChange(i)}}formatValueForDisplay(t){if(!t)return t;const{thousandSeparator:n,thousandStyle:r,enableLeadingZeros:i,decimalSeparator:a}=this.resolvedOptions;return n&&r!==b.None?z(t,n,r,i,a):t}handleChange(t){const n=t.target;q(t,this.resolvedOptions.decimalMaxLength,this.caretPositionBeforeChange,this.buildFormattingOptions()),this.caretPositionBeforeChange=void 0,this.handleValueChange(n.value)}handleKeyDown(t){const n=t.target,{selectionStart:r,selectionEnd:i}=n,a=this.buildFormattingOptions(),s=K(t,{formatOn:a.formatOn,thousandSeparator:a.thousandSeparator,ThousandStyle:a.ThousandStyle,decimalSeparator:a.decimalSeparator});s?this.caretPositionBeforeChange={selectionStart:r??0,selectionEnd:i??0,endOffset:s.endOffset}:this.caretPositionBeforeChange={selectionStart:r??0,selectionEnd:i??0}}handlePaste(t){const n=Q(t,this.resolvedOptions.decimalMaxLength,this.buildFormattingOptions());this.handleValueChange(n);const r=new Event("input",{bubbles:!0,cancelable:!0});this.element.dispatchEvent(r)}handleFocus(t){if(this.resolvedOptions.formatOn===v.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:i}=this.resolvedOptions;if(r&&i!==b.None&&n.value){const a=n.value,s=this.formatValueForDisplay(n.value);if(n.value=s,this.handleValueChange(s),a!==s){const o=new Event("input",{bubbles:!0,cancelable:!0});this.element.dispatchEvent(o);const c=new Event("change",{bubbles:!0,cancelable:!0});this.element.dispatchEvent(c)}}}updateRawValue(t){const n=this.element.getAttribute("data-raw-value");if(n!==null){this.rawValue=n,this.element.removeAttribute("data-raw-value");return}if(!this.resolvedOptions.thousandSeparator){this.rawValue=t;return}this.rawValue=L(t,this.resolvedOptions.thousandSeparator)}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=v;exports.NumoraInput=Ke;exports.ThousandStyle=b;exports.formatValueForNumora=_e;exports.handleOnChangeNumoraInput=q;exports.handleOnKeyDownNumoraInput=K;exports.handleOnPasteNumoraInput=Q;
|
|
1
|
+
"use strict";var Y=Object.defineProperty;var V=(e,t,n)=>t in e?Y(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var w=(e,t,n)=>V(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var v=(e=>(e.Blur="blur",e.Change="change",e))(v||{}),b=(e=>(e.None="none",e.Thousand="thousand",e.Lakh="lakh",e.Wan="wan",e))(b||{});const I=2,x=0,O=v.Blur,R=",",_=b.None,E=".",F=!1,P=!1,B=!1,W=!1;function M(e){return e.replace(/[-[\]/{}()*+?.\\^$|]/g,"\\$&")}function C(e){return{decimalSeparator:(e==null?void 0:e.decimalSeparator)??E,thousandSeparator:e==null?void 0:e.thousandSeparator}}function ee(e,t){const n=e.target;return n?n.value.includes(t):!1}function te(e,t,n,r){const{selectionStart:i,selectionEnd:a,value:s}=t,{key:o}=e,c=n==null?void 0:n.ThousandStyle;if(c!==b.None&&c!==void 0||o!==","&&o!==".")return!1;if(ee(e,r))return!0;if(o!==r){const l=i??0,h=a??l,d=s.slice(0,l)+r+s.slice(h);t.value=d;const u=l+1;return t.setSelectionRange(u,u),!0}return!1}const ne=(e,t,n=E)=>{const[r,i]=e.split(n);return i?`${r}${n}${i.slice(0,t)}`:e},re=(e,t=E)=>{const n=M(t),r=new RegExp(`(${n}.*?)${n}`,"g");return e.replace(r,`$1${t}`)},se=(e,t=0,n=E)=>{if(t===0)return e;if(!e||e==="0"||e===n||e==="-"||e===`-${n}`)return e==="-"||e===`-${n}`?`-${n}${"0".repeat(t)}`:e===n?`${n}${"0".repeat(t)}`:`${e}${n}${"0".repeat(t)}`;const r=e.includes(n),i=e.startsWith("-"),a=i?e.slice(1):e,[s,o=""]=a.split(n);if(!r){const c="0".repeat(t);return i?`-${s}${n}${c}`:`${s}${n}${c}`}if(o.length<t){const c=t-o.length,l=o+"0".repeat(c);return i?`-${s}${n}${l}`:`${s}${n}${l}`}return e},ie=(e,t=!1,n=".")=>{const r=M(n),i=new RegExp(`[^0-9${r}]`,"g");if(!t)return e.replace(i,"");const a=e.startsWith("-"),s=e.replace(i,"");if(a){if(s.length>0)return"-"+s;if(e==="-")return"-"}return s};function ae(e){const t=/([+-]?\d+\.?\d*)[eE]([+-]?\d+)/g;let n=e,r;const i=[];for(;(r=t.exec(e))!==null;){const a=r[0],s=r[1],o=parseInt(r[2],10);let c;if(o===0)c=s;else{const l=s.startsWith("-"),h=l?s.slice(1):s,[d,u=""]=h.split(".");o>0?c=oe(d,u,o):c=ce(d,u,Math.abs(o)),l&&(c="-"+c)}i.push({full:a,expanded:c})}for(const{full:a,expanded:s}of i)n=n.replace(a,s);return n}function oe(e,t,n){const r=e+t;if(r==="0"||r.match(/^0+$/))return"0";const i=t.length;if(n<=i){const s=r.slice(0,e.length+n),o=r.slice(e.length+n);return o?`${s}.${o}`:s}const a=n-i;return r+"0".repeat(a)}function ce(e,t,n){const r=e+t;if(r==="0"||r.match(/^0+$/))return"0";const s=e.length-n;if(s<=0){const o=Math.abs(s),c=`0.${"0".repeat(o)}${r}`;return y(c)}if(s<e.length){const o=r.slice(0,s),c=r.slice(s),l=`${o}.${c}`;return y(l)}return y(r)}function y(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 le(e){const t=/(\d+\.?\d*)\s*(Qa|Qi|Sx|Sp|[kmbMTO]|N)/gi;return e.replace(t,(n,r,i)=>{const a={k:3,K:3,m:6,M:6,b:9,B:9,T:12,t:12};let s;if(i.length>1){const f=i.charAt(0).toUpperCase()+i.slice(1).toLowerCase();s=a[i]||a[f]}else{const f=i.toLowerCase();s=a[i]||a[f]}if(!s)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(s);else if(h.length<=s){const f=s-h.length;u=d+h+"0".repeat(f)}else{const f=h.slice(0,s),g=h.slice(s);u=d+f+"."+g}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 he(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[i,a]=n.split(".");if(i&&i.length>0){const o=(i.replace(/^0+/,"")||"0")+"."+a;return t?"-"+o:o}return e}if(n.startsWith("0")&&n.length>1){const i=n.replace(/^0+/,"")||"0";return t?"-"+i:i}return e}function ue(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 de=(e,t)=>{let n=ue(e);return t!=null&&t.thousandSeparator&&(n=L(n,t.thousandSeparator)),t!=null&&t.enableCompactNotation&&(n=le(n)),n=ae(n),n=ie(n,t==null?void 0:t.enableNegative,t==null?void 0:t.decimalSeparator),n=re(n,(t==null?void 0:t.decimalSeparator)||E),t!=null&&t.enableLeadingZeros||(n=he(n)),n};function fe(e,t,n){return{enableCompactNotation:e==null?void 0:e.enableCompactNotation,enableNegative:e==null?void 0:e.enableNegative,enableLeadingZeros:e==null?void 0:e.enableLeadingZeros,decimalSeparator:t.decimalSeparator,thousandSeparator:n?t.thousandSeparator:void 0}}const N={thousand:{size:3},lakh:{firstGroup:3,restGroup:2},wan:{size:4}};function z(e,t,n,r=!1,i="."){if(!e||e==="0"||e===i||e==="-"||e===`-${i}`)return e;const a=e.includes(i),s=e.startsWith("-"),o=s?e.slice(1):e,[c,l]=o.split(i);if(!c){const u=l?`${i}${l}`:o;return s?`-${u}`:u}if(r&&c.startsWith("0")&&c.length>1){const u=c.match(/^(0+)/);if(u){const f=u[1],g=c.slice(f.length);if(g){const p=k(g,t,n),$=f+p,D=s?"-":"";return a?l?`${D}${$}${i}${l}`:`${D}${$}${i}`:`${D}${$}`}}}const h=k(c,t,n),d=s?"-":"";return a?l?`${d}${h}${i}${l}`:`${d}${h}${i}`:`${d}${h}`}function k(e,t,n){if(e==="0"||e==="")return e;switch(n){case b.None:return e;case b.Thousand:return ge(e,t);case b.Lakh:return pe(e,t);case b.Wan:return be(e,t);default:return e}}function ge(e,t){return G(e,t,N.thousand.size)}function pe(e,t){if(e.length<=N.lakh.firstGroup)return e;const n=e.split("").reverse(),r=[],i=n.slice(0,N.lakh.firstGroup).reverse().join("");r.push(i);for(let a=N.lakh.firstGroup;a<n.length;a+=N.lakh.restGroup)r.push(n.slice(a,a+N.lakh.restGroup).reverse().join(""));return r.reverse().join(t)}function be(e,t){return G(e,t,N.wan.size)}function G(e,t,n){const r=e.split("").reverse(),i=[];for(let a=0;a<r.length;a+=n)i.push(r.slice(a,a+n).reverse().join(""));return i.reverse().join(t)}function Se(e,t,n){return(t==null?void 0:t.formatOn)==="change"&&t.thousandSeparator?z(e,t.thousandSeparator,t.ThousandStyle??b.None,t.enableLeadingZeros,(n==null?void 0:n.decimalSeparator)??E):e}function S(e,t,n,r="."){let i=0;for(let a=0;a<t&&a<e.length;a++){const s=e[a];s!==n&&s!==r&&i++}return i}function ve(e,t,n,r="."){if(t===0)return 0;let i=0;for(let a=0;a<e.length;a++){const s=e[a];if(s!==n&&s!==r){if(i===t-1)return a+1;i++}}return e.length}function A(e,t,n,r="."){if(t===0)return 0;let i=0;for(let a=0;a<e.length;a++){const s=e[a];if(s!==n&&s!==r){if(i++,i===t)return a+1;if(i>t)return a}}return e.length}function U(e,t,n){return t<0||t>=e.length?!1:e[t]===n}function $e(e,t={}){const{thousandSeparator:n,decimalSeparator:r=".",prefix:i="",suffix:a=""}=t,s=Array.from({length:e.length+1}).map(()=>!0);if(i&&s.fill(!1,0,i.length),a){const o=e.length-a.length;s.fill(!1,o+1,e.length+1)}for(let o=0;o<e.length;o++){const c=e[o];(n&&c===n||c===r)&&(s[o]=!1,o+1<e.length&&!/\d/.test(e[o+1])&&(s[o+1]=!1))}return s.some(o=>o)||s.fill(!0),s}function T(e,t,n,r){const i=e.length;if(t=Math.max(0,Math.min(t,i)),!n[t]){let a=t;for(;a<=i&&!n[a];)a++;let s=t;for(;s>=0&&!n[s];)s--;a<=i&&s>=0?t=t-s<a-t?s:a:a<=i?t=a:s>=0&&(t=s)}return(t===-1||t>i)&&(t=i),t}const j=(e,t)=>e===t;function Ee(e,t,n,r,i,a,s=".",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=U(e,n,r),d=e.indexOf(s),u=t.indexOf(s);if(o.isCharacterEquivalent&&e!==t){const p=Ne(e,t,n,o.isCharacterEquivalent||j,a,o);if(p!==void 0)return p}if(l)return we(e,t,n,r,h,d,u,a,s,o);const g=me(e,t,n,r,h,s);return o.boundary?T(t,g,o.boundary):g}function Ne(e,t,n,r,i,a){const s=e.length,o=t.length,c={},l=new Array(s);for(let g=0;g<s;g++){l[g]=-1;for(let p=0;p<o;p++){if(c[p])continue;if(r(e[g],t[p],{oldValue:e,newValue:t,typedRange:i,oldIndex:g,newIndex:p})){l[g]=p,c[p]=!0;break}}}let h=n;for(;h<s&&(l[h]===-1||!/\d/.test(e[h]));)h++;const d=h===s||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 f=n-u<d-n?u:d;return a.boundary?T(t,f,a.boundary):f}function we(e,t,n,r,i,a,s,o,c,l={}){if(i)return Le(e,t,n,r,s,c);const h=S(e,n,r,c),d=S(e,e.length,r,c),u=S(t,t.length,r,c),f=d-u,g=Me(e,n,r,h,f,a,o,c),p=a===-1||n<=a,$=De(t,g,r,f,o,c,p,s);return l.boundary?T(t,$,l.boundary):$}function Le(e,t,n,r,i,a){const s=n+1;if(s<e.length){const o=S(e,s,r,a),c=ve(t,o,r,a);return c<t.length&&t[c]!==r?c+1:c}return n}function Me(e,t,n,r,i,a,s,o){if(s){const{start:l,isDelete:h}=s;return h?S(e,l,n,o):Math.max(0,S(e,l,n,o))}return t>0&&e[t-1]===n&&i>0?r+1:r}function De(e,t,n,r,i,a,s,o){if(s&&o!==-1){const l=e.substring(0,o),h=S(l,l.length,n,a);if(t<=h){const d=A(l,t,n,a);if(d>0&&d<l.length&&S(l,d,n,a)===t){if(l[d]===n&&i&&r>0&&d<l.length-1)return d+1;if(!i&&r>0&&d<l.length-1)return Math.min(d+1,l.length)}return d}}const c=A(e,t,n,a);if(c>0&&c<e.length&&S(e,c,n,a)===t){if(e[c]===n&&i&&r>0&&c<e.length-1)return c+1;if(!i&&r>0&&c<e.length-1)return Math.min(c+1,e.length)}return c}function me(e,t,n,r,i,a){const s=n>=e.length,o=S(e,n,r,a),c=S(e,e.length,r,a),l=S(t,t.length,r,a);if(s||o===c)return t.length;const h=l-c;let d=o;h>0&&!s&&o<c&&(d=o+1);const u=A(t,d,r,a);return i&&!U(t,u,r)?Math.max(0,u-1):u}function ye(e,t,n){const{selectionStart:r,selectionEnd:i,endOffset:a=0}=e;if(r!==i){const h=i-r;return{start:r,end:i,deletedLength:h,isDelete:!1}}if(a>0){const h=a;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 Ae(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 a=r-n+1,s=i-n+1;if(!(a===0&&s===0))return{start:n,end:r+1,deletedLength:a,isDelete:a>s}}function Z(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 Ce(e,t,n){return e.selectionStart===0&&e.selectionEnd===e.value.length?null:(Z(e,t),setTimeout(()=>{e.value===n&&e.selectionStart!==t&&Z(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)!==v.Change||!n.thousandSeparator)return;const{selectionStart:r,selectionEnd:i,value:a}=t;if(r===null||i===null||r!==i)return;const{key:s}=e,o=n.thousandSeparator;s==="Backspace"&&r>0&&a[r-1]===o&&t.setSelectionRange(r-1,r-1),s==="Delete"&&a[r]===o&&t.setSelectionRange(r+1,r+1)}function xe(e,t,n,r,i,a,s){if(!i)return;const{selectionStart:o=0,selectionEnd:c=0,endOffset:l=0}=i;let h=ye({selectionStart:o,selectionEnd:c,endOffset:l},t,n);if(h||(h=Ae(t,n)),!h)return;const d=$e(n,{thousandSeparator:(s==null?void 0:s.thousandSeparator)??a.thousandSeparator,decimalSeparator:a.decimalSeparator}),u={thousandSeparator:(s==null?void 0:s.thousandSeparator)??a.thousandSeparator,isCharacterEquivalent:j,boundary:d},f=(s==null?void 0:s.thousandSeparator)??a.thousandSeparator??",",g=(s==null?void 0:s.ThousandStyle)??b.None,p=Ee(t,n,r,f,g,h,a.decimalSeparator,u);Ce(e,p,n)}function J(e,t,n,r,i){const a=de(e,fe(r,i,n)),s=ne(a,t,i.decimalSeparator),o=(r==null?void 0:r.decimalMinLength)??0,c=se(s,o,i.decimalSeparator),l=c;return{formatted:Se(c,r,i),raw:l}}function Oe(e,t,n){if(e==="Backspace"||e==="Delete")return e==="Delete"&&t===n?{endOffset:1}:{endOffset:0}}function K(e,t){const{decimalSeparator:n}=C(t),r=e.target;if(te(e,r,t,n)){e.preventDefault();return}return Ie(e,r,t),Oe(e.key,r.selectionStart,r.selectionEnd)}function q(e,t,n,r){const i=e.target,a=i.value,s=Te(i),o=C(r),c=(r==null?void 0:r.formatOn)===v.Change,{formatted:l,raw:h}=J(a,t,c,r,o);i.value=l,r!=null&&r.rawValueMode&&i.setAttribute("data-raw-value",h),a!==l&&xe(i,a,l,s,n,o,r)}function Re(e,t,n,r){const i=r-n;return e+t+i}function H(e,t,n){var f;e.preventDefault();const r=e.target,{value:i,selectionStart:a,selectionEnd:s}=r,o=C(n),c=((f=e.clipboardData)==null?void 0:f.getData("text/plain"))||"",l=i.slice(0,a||0)+c+i.slice(s||0),{formatted:h,raw:d}=J(l,t,!0,n,o);r.value=h,n!=null&&n.rawValueMode&&r.setAttribute("data-raw-value",d);const u=Re(a||0,c.length,l.length,h.length);return r.setSelectionRange(u,u),r.value}function _e(e,t){const n=M(e);return t?`^-?[0-9]*[${n}]?[0-9]*$`:`^[0-9]*[${n}]?[0-9]*$`}function Pe(e){Be(e.decimalMaxLength),We(e.decimalMinLength),ke(e.decimalMinLength,e.decimalMaxLength),Ze(e.formatOn),ze(e.thousandSeparator),Ge(e.thousandStyle),Ue(e.decimalSeparator),je(e.thousandSeparator,e.decimalSeparator),m("enableCompactNotation",e.enableCompactNotation),m("enableNegative",e.enableNegative),m("enableLeadingZeros",e.enableLeadingZeros),m("rawValueMode",e.rawValueMode),Je(e.onChange)}function Be(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 We(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 ke(e,t){if(!(e===void 0||t===void 0)&&e>t)throw new Error(`decimalMinLength (${e}) cannot be greater than decimalMaxLength (${t}).`)}function Ze(e){if(e!==void 0&&e!==v.Blur&&e!==v.Change)throw new Error(`formatOn must be either ${v.Blur} or ${v.Change}. Received: ${JSON.stringify(e)}`)}function ze(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 Ge(e){if(e!==void 0&&!Object.values(b).includes(e))throw new Error(`ThousandStyle must be one of: ${Object.values(b).map(t=>`'${t}'`).join(", ")}. Received: ${JSON.stringify(e)}`)}function Ue(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 je(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 Je(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 Ke{constructor(t,{decimalMaxLength:n=I,decimalMinLength:r=x,formatOn:i=O,thousandSeparator:a=R,thousandStyle:s=_,decimalSeparator:o=E,enableCompactNotation:c=!0,enableNegative:l=P,enableLeadingZeros:h=B,rawValueMode:d=W,onChange:u,...f}){w(this,"element");w(this,"options");w(this,"resolvedOptions");w(this,"rawValue","");w(this,"caretPositionBeforeChange");if(Pe({decimalMaxLength:n,decimalMinLength:r,formatOn:i,thousandSeparator:a,thousandStyle:s,decimalSeparator:o,enableCompactNotation:c,enableNegative:l,enableLeadingZeros:h,rawValueMode:d,onChange:u}),this.options={decimalMaxLength:n,decimalMinLength:r,onChange:u,formatOn:i,thousandSeparator:a,thousandStyle:s,decimalSeparator:o,enableCompactNotation:c,enableNegative:l,enableLeadingZeros:h,rawValueMode:d,...f},this.resolvedOptions=this.getResolvedOptions(),this.createInputElement(t),this.setupEventListeners(),this.resolvedOptions.rawValueMode&&this.element.value){const g=this.element.value,p=this.resolvedOptions.thousandSeparator?L(g,this.resolvedOptions.thousandSeparator):g;this.rawValue=p,this.element.value=this.formatValueForDisplay(p)}else if(this.element.value&&!this.resolvedOptions.rawValueMode){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 X=_e(this.resolvedOptions.decimalSeparator,this.resolvedOptions.enableNegative);this.element.setAttribute("pattern",X)}const{decimalMaxLength:n,decimalMinLength:r,formatOn:i,thousandSeparator:a,thousandStyle:s,decimalSeparator:o,enableCompactNotation:c,enableNegative:l,enableLeadingZeros:h,rawValueMode:d,onChange:u,value:f,defaultValue:g,type:p,inputMode:$,spellcheck:D,autocomplete:qe,...Q}=this.options;Object.assign(this.element,Q),f!==void 0?this.element.value=f: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===v.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??I,decimalMinLength:this.options.decimalMinLength??x,formatOn:this.options.formatOn??O,thousandSeparator:this.options.thousandSeparator??R,thousandStyle:this.options.thousandStyle??_,decimalSeparator:this.options.decimalSeparator??E,enableCompactNotation:this.options.enableCompactNotation??F,enableNegative:this.options.enableNegative??P,enableLeadingZeros:this.options.enableLeadingZeros??B,rawValueMode:this.options.rawValueMode??W,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){const r=n??t;if(this.resolvedOptions.rawValueMode&&this.updateRawValue(r),this.resolvedOptions.onChange){const i=this.resolvedOptions.rawValueMode?this.rawValue:t;this.resolvedOptions.onChange(i)}}formatValueForDisplay(t){if(!t)return t;const{thousandSeparator:n,thousandStyle:r,enableLeadingZeros:i,decimalSeparator:a}=this.resolvedOptions;return n&&r!==b.None?z(t,n,r,i,a):t}handleChange(t){const n=t.target;q(t,this.resolvedOptions.decimalMaxLength,this.caretPositionBeforeChange,this.buildFormattingOptions()),this.caretPositionBeforeChange=void 0,this.handleValueChange(n.value)}handleKeyDown(t){const n=t.target,{selectionStart:r,selectionEnd:i}=n,a=this.buildFormattingOptions(),s=K(t,{formatOn:a.formatOn,thousandSeparator:a.thousandSeparator,ThousandStyle:a.ThousandStyle,decimalSeparator:a.decimalSeparator});s?this.caretPositionBeforeChange={selectionStart:r??0,selectionEnd:i??0,endOffset:s.endOffset}:this.caretPositionBeforeChange={selectionStart:r??0,selectionEnd:i??0}}handlePaste(t){const n=H(t,this.resolvedOptions.decimalMaxLength,this.buildFormattingOptions());this.handleValueChange(n);const r=new Event("input",{bubbles:!0,cancelable:!0});this.element.dispatchEvent(r)}handleFocus(t){if(this.resolvedOptions.formatOn===v.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:i}=this.resolvedOptions;if(r&&i!==b.None&&n.value){const a=n.value,s=this.formatValueForDisplay(n.value);if(n.value=s,this.handleValueChange(s),a!==s){const o=new Event("input",{bubbles:!0,cancelable:!0});this.element.dispatchEvent(o);const c=new Event("change",{bubbles:!0,cancelable:!0});this.element.dispatchEvent(c)}}}updateRawValue(t){const n=this.element.getAttribute("data-raw-value");if(n!==null){this.rawValue=n,this.element.removeAttribute("data-raw-value");return}if(!this.resolvedOptions.thousandSeparator){this.rawValue=t;return}this.rawValue=L(t,this.resolvedOptions.thousandSeparator)}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=v;exports.NumoraInput=Ke;exports.ThousandStyle=b;exports.handleOnChangeNumoraInput=q;exports.handleOnKeyDownNumoraInput=K;exports.handleOnPasteNumoraInput=H;
|
package/dist/index.mjs
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var w = (e, t, n) =>
|
|
1
|
+
var K = Object.defineProperty;
|
|
2
|
+
var Q = (e, t, n) => t in e ? K(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var w = (e, t, n) => Q(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
4
|
var v = /* @__PURE__ */ ((e) => (e.Blur = "blur", e.Change = "change", e))(v || {}), b = /* @__PURE__ */ ((e) => (e.None = "none", e.Thousand = "thousand", e.Lakh = "lakh", e.Wan = "wan", e))(b || {});
|
|
5
|
-
const
|
|
6
|
-
function
|
|
5
|
+
const x = 2, I = 0, R = v.Blur, O = ",", _ = b.None, E = ".", X = !1, P = !1, B = !1, W = !1;
|
|
6
|
+
function M(e) {
|
|
7
7
|
return e.replace(/[-[\]/{}()*+?.\\^$|]/g, "\\$&");
|
|
8
8
|
}
|
|
9
|
-
function
|
|
9
|
+
function C(e) {
|
|
10
10
|
return {
|
|
11
11
|
decimalSeparator: (e == null ? void 0 : e.decimalSeparator) ?? E,
|
|
12
12
|
thousandSeparator: e == null ? void 0 : e.thousandSeparator
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
15
|
function Y(e, t) {
|
|
16
|
-
if (e.key !== t)
|
|
17
|
-
return !1;
|
|
18
16
|
const n = e.target;
|
|
19
17
|
return n ? n.value.includes(t) : !1;
|
|
20
18
|
}
|
|
@@ -36,7 +34,7 @@ const F = (e, t, n = E) => {
|
|
|
36
34
|
const [r, i] = e.split(n);
|
|
37
35
|
return i ? `${r}${n}${i.slice(0, t)}` : e;
|
|
38
36
|
}, ee = (e, t = E) => {
|
|
39
|
-
const n =
|
|
37
|
+
const n = M(t), r = new RegExp(`(${n}.*?)${n}`, "g");
|
|
40
38
|
return e.replace(r, `$1${t}`);
|
|
41
39
|
}, te = (e, t = 0, n = E) => {
|
|
42
40
|
if (t === 0)
|
|
@@ -54,7 +52,7 @@ const F = (e, t, n = E) => {
|
|
|
54
52
|
}
|
|
55
53
|
return e;
|
|
56
54
|
}, ne = (e, t = !1, n = ".") => {
|
|
57
|
-
const r =
|
|
55
|
+
const r = M(n), i = new RegExp(`[^0-9${r}]`, "g");
|
|
58
56
|
if (!t)
|
|
59
57
|
return e.replace(i, "");
|
|
60
58
|
const a = e.startsWith("-"), s = e.replace(i, "");
|
|
@@ -104,15 +102,15 @@ function ie(e, t, n) {
|
|
|
104
102
|
const s = e.length - n;
|
|
105
103
|
if (s <= 0) {
|
|
106
104
|
const o = Math.abs(s), c = `0.${"0".repeat(o)}${r}`;
|
|
107
|
-
return
|
|
105
|
+
return y(c);
|
|
108
106
|
}
|
|
109
107
|
if (s < e.length) {
|
|
110
108
|
const o = r.slice(0, s), c = r.slice(s), l = `${o}.${c}`;
|
|
111
|
-
return
|
|
109
|
+
return y(l);
|
|
112
110
|
}
|
|
113
|
-
return
|
|
111
|
+
return y(r);
|
|
114
112
|
}
|
|
115
|
-
function
|
|
113
|
+
function y(e) {
|
|
116
114
|
if (!e.includes("."))
|
|
117
115
|
return e;
|
|
118
116
|
if (e === "0" || e === "0.")
|
|
@@ -133,31 +131,26 @@ function ae(e) {
|
|
|
133
131
|
const a = {
|
|
134
132
|
k: 3,
|
|
135
133
|
// Thousand
|
|
134
|
+
K: 3,
|
|
135
|
+
// Thousand
|
|
136
136
|
m: 6,
|
|
137
137
|
// Million (lowercase)
|
|
138
138
|
M: 6,
|
|
139
139
|
// Million (uppercase)
|
|
140
140
|
b: 9,
|
|
141
141
|
// Billion
|
|
142
|
+
B: 9,
|
|
143
|
+
// Billion
|
|
142
144
|
T: 12,
|
|
143
145
|
// Trillion
|
|
144
|
-
|
|
145
|
-
//
|
|
146
|
-
Qi: 18,
|
|
147
|
-
// Quintillion
|
|
148
|
-
Sx: 21,
|
|
149
|
-
// Sextillion
|
|
150
|
-
Sp: 24,
|
|
151
|
-
// Septillion
|
|
152
|
-
O: 27,
|
|
153
|
-
// Octillion
|
|
154
|
-
N: 30
|
|
155
|
-
// Nonillion
|
|
146
|
+
t: 12
|
|
147
|
+
// Trillion
|
|
156
148
|
};
|
|
157
149
|
let s;
|
|
158
|
-
if (i.length > 1)
|
|
159
|
-
|
|
160
|
-
|
|
150
|
+
if (i.length > 1) {
|
|
151
|
+
const f = i.charAt(0).toUpperCase() + i.slice(1).toLowerCase();
|
|
152
|
+
s = a[i] || a[f];
|
|
153
|
+
} else {
|
|
161
154
|
const f = i.toLowerCase();
|
|
162
155
|
s = a[i] || a[f];
|
|
163
156
|
}
|
|
@@ -174,7 +167,7 @@ function ae(e) {
|
|
|
174
167
|
const f = h.slice(0, s), g = h.slice(s);
|
|
175
168
|
u = d + f + "." + g;
|
|
176
169
|
}
|
|
177
|
-
return u = u.replace(/^(-?)0+([1-9])/, "$1$2"), u.match(/^-?0+$/) && (u = o ? "-0" : "0"), u = u.replace(/\.?0+$/, ""), o && !u.startsWith("-") ? "-" + u : u;
|
|
170
|
+
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;
|
|
178
171
|
});
|
|
179
172
|
}
|
|
180
173
|
function oe(e) {
|
|
@@ -201,7 +194,7 @@ function ce(e) {
|
|
|
201
194
|
return e.replace(/[\u00A0\u2000-\u200B\u202F\u205F\u3000]/g, " ").replace(/\s/g, "");
|
|
202
195
|
}
|
|
203
196
|
function L(e, t) {
|
|
204
|
-
const n =
|
|
197
|
+
const n = M(t);
|
|
205
198
|
return e.replace(new RegExp(n, "g"), "");
|
|
206
199
|
}
|
|
207
200
|
const le = (e, t) => {
|
|
@@ -239,15 +232,15 @@ function z(e, t, n, r = !1, i = ".") {
|
|
|
239
232
|
if (u) {
|
|
240
233
|
const f = u[1], g = c.slice(f.length);
|
|
241
234
|
if (g) {
|
|
242
|
-
const p =
|
|
243
|
-
return a ? l ? `${
|
|
235
|
+
const p = k(g, t, n), $ = f + p, D = s ? "-" : "";
|
|
236
|
+
return a ? l ? `${D}${$}${i}${l}` : `${D}${$}${i}` : `${D}${$}`;
|
|
244
237
|
}
|
|
245
238
|
}
|
|
246
239
|
}
|
|
247
|
-
const h =
|
|
240
|
+
const h = k(c, t, n), d = s ? "-" : "";
|
|
248
241
|
return a ? l ? `${d}${h}${i}${l}` : `${d}${h}${i}` : `${d}${h}`;
|
|
249
242
|
}
|
|
250
|
-
function
|
|
243
|
+
function k(e, t, n) {
|
|
251
244
|
if (e === "0" || e === "")
|
|
252
245
|
return e;
|
|
253
246
|
switch (n) {
|
|
@@ -264,7 +257,7 @@ function G(e, t, n) {
|
|
|
264
257
|
}
|
|
265
258
|
}
|
|
266
259
|
function ue(e, t) {
|
|
267
|
-
return
|
|
260
|
+
return G(e, t, N.thousand.size);
|
|
268
261
|
}
|
|
269
262
|
function de(e, t) {
|
|
270
263
|
if (e.length <= N.lakh.firstGroup)
|
|
@@ -276,9 +269,9 @@ function de(e, t) {
|
|
|
276
269
|
return r.reverse().join(t);
|
|
277
270
|
}
|
|
278
271
|
function fe(e, t) {
|
|
279
|
-
return
|
|
272
|
+
return G(e, t, N.wan.size);
|
|
280
273
|
}
|
|
281
|
-
function
|
|
274
|
+
function G(e, t, n) {
|
|
282
275
|
const r = e.split("").reverse(), i = [];
|
|
283
276
|
for (let a = 0; a < r.length; a += n)
|
|
284
277
|
i.push(r.slice(a, a + n).reverse().join(""));
|
|
@@ -315,7 +308,7 @@ function pe(e, t, n, r = ".") {
|
|
|
315
308
|
}
|
|
316
309
|
return e.length;
|
|
317
310
|
}
|
|
318
|
-
function
|
|
311
|
+
function A(e, t, n, r = ".") {
|
|
319
312
|
if (t === 0)
|
|
320
313
|
return 0;
|
|
321
314
|
let i = 0;
|
|
@@ -330,7 +323,7 @@ function C(e, t, n, r = ".") {
|
|
|
330
323
|
}
|
|
331
324
|
return e.length;
|
|
332
325
|
}
|
|
333
|
-
function
|
|
326
|
+
function U(e, t, n) {
|
|
334
327
|
return t < 0 || t >= e.length ? !1 : e[t] === n;
|
|
335
328
|
}
|
|
336
329
|
function be(e, t = {}) {
|
|
@@ -363,51 +356,54 @@ function T(e, t, n, r) {
|
|
|
363
356
|
}
|
|
364
357
|
return (t === -1 || t > i) && (t = i), t;
|
|
365
358
|
}
|
|
366
|
-
const
|
|
359
|
+
const j = (e, t) => e === t;
|
|
367
360
|
function Se(e, t, n, r, i, a, s = ".", o = {}) {
|
|
368
361
|
if (n < 0)
|
|
369
362
|
return 0;
|
|
370
363
|
if (n > e.length || e === "" || t === "")
|
|
371
364
|
return t.length;
|
|
372
|
-
const c =
|
|
365
|
+
const c = /(\d+\.?\d*)\s*[kmbMTOQaqiSxsxSpOoNn]$/i;
|
|
366
|
+
if (c.test(e) && !c.test(t) && t.length > e.length && n >= e.length - 1)
|
|
367
|
+
return t.length;
|
|
368
|
+
const l = t.length < e.length, h = U(
|
|
373
369
|
e,
|
|
374
370
|
n,
|
|
375
371
|
r
|
|
376
|
-
),
|
|
372
|
+
), d = e.indexOf(s), u = t.indexOf(s);
|
|
377
373
|
if (o.isCharacterEquivalent && e !== t) {
|
|
378
|
-
const
|
|
374
|
+
const p = ve(
|
|
379
375
|
e,
|
|
380
376
|
t,
|
|
381
377
|
n,
|
|
382
|
-
o.isCharacterEquivalent ||
|
|
378
|
+
o.isCharacterEquivalent || j,
|
|
383
379
|
a,
|
|
384
380
|
o
|
|
385
381
|
);
|
|
386
|
-
if (
|
|
387
|
-
return
|
|
382
|
+
if (p !== void 0)
|
|
383
|
+
return p;
|
|
388
384
|
}
|
|
389
|
-
if (
|
|
385
|
+
if (l)
|
|
390
386
|
return $e(
|
|
391
387
|
e,
|
|
392
388
|
t,
|
|
393
389
|
n,
|
|
394
390
|
r,
|
|
395
|
-
l,
|
|
396
391
|
h,
|
|
397
392
|
d,
|
|
393
|
+
u,
|
|
398
394
|
a,
|
|
399
395
|
s,
|
|
400
396
|
o
|
|
401
397
|
);
|
|
402
|
-
const
|
|
398
|
+
const g = Le(
|
|
403
399
|
e,
|
|
404
400
|
t,
|
|
405
401
|
n,
|
|
406
402
|
r,
|
|
407
|
-
|
|
403
|
+
h,
|
|
408
404
|
s
|
|
409
405
|
);
|
|
410
|
-
return o.boundary ? T(t,
|
|
406
|
+
return o.boundary ? T(t, g, o.boundary) : g;
|
|
411
407
|
}
|
|
412
408
|
function ve(e, t, n, r, i, a) {
|
|
413
409
|
const s = e.length, o = t.length, c = {}, l = new Array(s);
|
|
@@ -531,7 +527,7 @@ function we(e, t, n, r, i, a, s, o) {
|
|
|
531
527
|
a
|
|
532
528
|
);
|
|
533
529
|
if (t <= h) {
|
|
534
|
-
const d =
|
|
530
|
+
const d = A(
|
|
535
531
|
l,
|
|
536
532
|
t,
|
|
537
533
|
n,
|
|
@@ -551,7 +547,7 @@ function we(e, t, n, r, i, a, s, o) {
|
|
|
551
547
|
return d;
|
|
552
548
|
}
|
|
553
549
|
}
|
|
554
|
-
const c =
|
|
550
|
+
const c = A(
|
|
555
551
|
e,
|
|
556
552
|
t,
|
|
557
553
|
n,
|
|
@@ -592,15 +588,15 @@ function Le(e, t, n, r, i, a) {
|
|
|
592
588
|
const h = l - c;
|
|
593
589
|
let d = o;
|
|
594
590
|
h > 0 && !s && o < c && (d = o + 1);
|
|
595
|
-
const u =
|
|
591
|
+
const u = A(
|
|
596
592
|
t,
|
|
597
593
|
d,
|
|
598
594
|
r,
|
|
599
595
|
a
|
|
600
596
|
);
|
|
601
|
-
return i && !
|
|
597
|
+
return i && !U(t, u, r) ? Math.max(0, u - 1) : u;
|
|
602
598
|
}
|
|
603
|
-
function
|
|
599
|
+
function Me(e, t, n) {
|
|
604
600
|
const { selectionStart: r, selectionEnd: i, endOffset: a = 0 } = e;
|
|
605
601
|
if (r !== i) {
|
|
606
602
|
const h = i - r;
|
|
@@ -629,7 +625,7 @@ function De(e, t, n) {
|
|
|
629
625
|
isDelete: !1
|
|
630
626
|
};
|
|
631
627
|
}
|
|
632
|
-
function
|
|
628
|
+
function De(e, t) {
|
|
633
629
|
if (e === t)
|
|
634
630
|
return;
|
|
635
631
|
let n = 0;
|
|
@@ -647,7 +643,7 @@ function Me(e, t) {
|
|
|
647
643
|
isDelete: a > s
|
|
648
644
|
};
|
|
649
645
|
}
|
|
650
|
-
function
|
|
646
|
+
function Z(e, t) {
|
|
651
647
|
if (e.value = e.value, e === null)
|
|
652
648
|
return !1;
|
|
653
649
|
if (e.createTextRange) {
|
|
@@ -657,8 +653,8 @@ function U(e, t) {
|
|
|
657
653
|
return e.selectionStart !== null || e.selectionStart === 0 ? (e.focus(), e.setSelectionRange(t, t), !0) : (e.focus(), !1);
|
|
658
654
|
}
|
|
659
655
|
function me(e, t, n) {
|
|
660
|
-
return e.selectionStart === 0 && e.selectionEnd === e.value.length ? null : (
|
|
661
|
-
e.value === n && e.selectionStart !== t &&
|
|
656
|
+
return e.selectionStart === 0 && e.selectionEnd === e.value.length ? null : (Z(e, t), setTimeout(() => {
|
|
657
|
+
e.value === n && e.selectionStart !== t && Z(e, t);
|
|
662
658
|
}, 0));
|
|
663
659
|
}
|
|
664
660
|
function ye(e) {
|
|
@@ -676,18 +672,18 @@ function Ae(e, t, n) {
|
|
|
676
672
|
function Ce(e, t, n, r, i, a, s) {
|
|
677
673
|
if (!i) return;
|
|
678
674
|
const { selectionStart: o = 0, selectionEnd: c = 0, endOffset: l = 0 } = i;
|
|
679
|
-
let h =
|
|
675
|
+
let h = Me(
|
|
680
676
|
{ selectionStart: o, selectionEnd: c, endOffset: l },
|
|
681
677
|
t,
|
|
682
678
|
n
|
|
683
679
|
);
|
|
684
|
-
if (h || (h =
|
|
680
|
+
if (h || (h = De(t, n)), !h) return;
|
|
685
681
|
const d = be(n, {
|
|
686
682
|
thousandSeparator: (s == null ? void 0 : s.thousandSeparator) ?? a.thousandSeparator,
|
|
687
683
|
decimalSeparator: a.decimalSeparator
|
|
688
684
|
}), u = {
|
|
689
685
|
thousandSeparator: (s == null ? void 0 : s.thousandSeparator) ?? a.thousandSeparator,
|
|
690
|
-
isCharacterEquivalent:
|
|
686
|
+
isCharacterEquivalent: j,
|
|
691
687
|
boundary: d
|
|
692
688
|
}, f = (s == null ? void 0 : s.thousandSeparator) ?? a.thousandSeparator ?? ",", g = (s == null ? void 0 : s.ThousandStyle) ?? b.None, p = Se(
|
|
693
689
|
t,
|
|
@@ -701,7 +697,7 @@ function Ce(e, t, n, r, i, a, s) {
|
|
|
701
697
|
);
|
|
702
698
|
me(e, p, n);
|
|
703
699
|
}
|
|
704
|
-
function
|
|
700
|
+
function J(e, t, n, r, i) {
|
|
705
701
|
const a = le(
|
|
706
702
|
e,
|
|
707
703
|
he(r, i, n)
|
|
@@ -725,7 +721,7 @@ function Te(e, t, n) {
|
|
|
725
721
|
};
|
|
726
722
|
}
|
|
727
723
|
function xe(e, t) {
|
|
728
|
-
const { decimalSeparator: n } =
|
|
724
|
+
const { decimalSeparator: n } = C(t), r = e.target;
|
|
729
725
|
if (V(e, r, t, n)) {
|
|
730
726
|
e.preventDefault();
|
|
731
727
|
return;
|
|
@@ -733,7 +729,7 @@ function xe(e, t) {
|
|
|
733
729
|
return Ae(e, r, t), Te(e.key, r.selectionStart, r.selectionEnd);
|
|
734
730
|
}
|
|
735
731
|
function Ie(e, t, n, r) {
|
|
736
|
-
const i = e.target, a = i.value, s = ye(i), o =
|
|
732
|
+
const i = e.target, a = i.value, s = ye(i), o = C(r), c = (r == null ? void 0 : r.formatOn) === v.Change, { formatted: l, raw: h } = J(
|
|
737
733
|
a,
|
|
738
734
|
t,
|
|
739
735
|
c,
|
|
@@ -757,7 +753,7 @@ function Re(e, t, n, r) {
|
|
|
757
753
|
function Oe(e, t, n) {
|
|
758
754
|
var f;
|
|
759
755
|
e.preventDefault();
|
|
760
|
-
const r = e.target, { value: i, selectionStart: a, selectionEnd: s } = r, o =
|
|
756
|
+
const r = e.target, { value: i, selectionStart: a, selectionEnd: s } = r, o = C(n), c = ((f = e.clipboardData) == null ? void 0 : f.getData("text/plain")) || "", l = i.slice(0, a || 0) + c + i.slice(s || 0), { formatted: h, raw: d } = J(
|
|
761
757
|
l,
|
|
762
758
|
t,
|
|
763
759
|
!0,
|
|
@@ -773,24 +769,12 @@ function Oe(e, t, n) {
|
|
|
773
769
|
);
|
|
774
770
|
return r.setSelectionRange(u, u), r.value;
|
|
775
771
|
}
|
|
776
|
-
function Ke(e, t, n) {
|
|
777
|
-
if (!e)
|
|
778
|
-
return e;
|
|
779
|
-
const r = y(n), i = !0, { formatted: a } = x(
|
|
780
|
-
e,
|
|
781
|
-
t,
|
|
782
|
-
i,
|
|
783
|
-
n,
|
|
784
|
-
r
|
|
785
|
-
);
|
|
786
|
-
return a;
|
|
787
|
-
}
|
|
788
772
|
function _e(e, t) {
|
|
789
|
-
const n =
|
|
773
|
+
const n = M(e);
|
|
790
774
|
return t ? `^-?[0-9]*[${n}]?[0-9]*$` : `^[0-9]*[${n}]?[0-9]*$`;
|
|
791
775
|
}
|
|
792
776
|
function Pe(e) {
|
|
793
|
-
Be(e.decimalMaxLength), We(e.decimalMinLength), ke(e.decimalMinLength, e.decimalMaxLength), Ze(e.formatOn),
|
|
777
|
+
Be(e.decimalMaxLength), We(e.decimalMinLength), ke(e.decimalMinLength, e.decimalMaxLength), Ze(e.formatOn), ze(e.thousandSeparator), Ge(e.thousandStyle), Ue(e.decimalSeparator), je(e.thousandSeparator, e.decimalSeparator), m("enableCompactNotation", e.enableCompactNotation), m("enableNegative", e.enableNegative), m("enableLeadingZeros", e.enableLeadingZeros), m("rawValueMode", e.rawValueMode), Je(e.onChange);
|
|
794
778
|
}
|
|
795
779
|
function Be(e) {
|
|
796
780
|
if (e !== void 0) {
|
|
@@ -836,7 +820,7 @@ function Ze(e) {
|
|
|
836
820
|
`formatOn must be either ${v.Blur} or ${v.Change}. Received: ${JSON.stringify(e)}`
|
|
837
821
|
);
|
|
838
822
|
}
|
|
839
|
-
function
|
|
823
|
+
function ze(e) {
|
|
840
824
|
if (e !== void 0) {
|
|
841
825
|
if (typeof e != "string")
|
|
842
826
|
throw new Error(
|
|
@@ -852,13 +836,13 @@ function Ge(e) {
|
|
|
852
836
|
);
|
|
853
837
|
}
|
|
854
838
|
}
|
|
855
|
-
function
|
|
839
|
+
function Ge(e) {
|
|
856
840
|
if (e !== void 0 && !Object.values(b).includes(e))
|
|
857
841
|
throw new Error(
|
|
858
842
|
`ThousandStyle must be one of: ${Object.values(b).map((t) => `'${t}'`).join(", ")}. Received: ${JSON.stringify(e)}`
|
|
859
843
|
);
|
|
860
844
|
}
|
|
861
|
-
function
|
|
845
|
+
function Ue(e) {
|
|
862
846
|
if (e !== void 0) {
|
|
863
847
|
if (typeof e != "string")
|
|
864
848
|
throw new Error(
|
|
@@ -892,18 +876,18 @@ function Je(e) {
|
|
|
892
876
|
`onChange must be a function or undefined. Received: ${typeof e} (${JSON.stringify(e)})`
|
|
893
877
|
);
|
|
894
878
|
}
|
|
895
|
-
class
|
|
879
|
+
class Ke {
|
|
896
880
|
constructor(t, {
|
|
897
|
-
decimalMaxLength: n =
|
|
898
|
-
decimalMinLength: r =
|
|
899
|
-
formatOn: i =
|
|
900
|
-
thousandSeparator: a =
|
|
901
|
-
thousandStyle: s =
|
|
881
|
+
decimalMaxLength: n = x,
|
|
882
|
+
decimalMinLength: r = I,
|
|
883
|
+
formatOn: i = R,
|
|
884
|
+
thousandSeparator: a = O,
|
|
885
|
+
thousandStyle: s = _,
|
|
902
886
|
decimalSeparator: o = E,
|
|
903
|
-
enableCompactNotation: c =
|
|
904
|
-
enableNegative: l =
|
|
905
|
-
enableLeadingZeros: h =
|
|
906
|
-
rawValueMode: d =
|
|
887
|
+
enableCompactNotation: c = !0,
|
|
888
|
+
enableNegative: l = P,
|
|
889
|
+
enableLeadingZeros: h = B,
|
|
890
|
+
rawValueMode: d = W,
|
|
907
891
|
onChange: u,
|
|
908
892
|
...f
|
|
909
893
|
}) {
|
|
@@ -947,8 +931,8 @@ class Qe {
|
|
|
947
931
|
}
|
|
948
932
|
createInputElement(t) {
|
|
949
933
|
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) {
|
|
950
|
-
const
|
|
951
|
-
this.element.setAttribute("pattern",
|
|
934
|
+
const H = _e(this.resolvedOptions.decimalSeparator, this.resolvedOptions.enableNegative);
|
|
935
|
+
this.element.setAttribute("pattern", H);
|
|
952
936
|
}
|
|
953
937
|
const {
|
|
954
938
|
decimalMaxLength: n,
|
|
@@ -968,9 +952,9 @@ class Qe {
|
|
|
968
952
|
// Exclude - forced to 'text' above
|
|
969
953
|
inputMode: $,
|
|
970
954
|
// Exclude - forced to 'decimal' above
|
|
971
|
-
spellcheck:
|
|
955
|
+
spellcheck: D,
|
|
972
956
|
// Exclude - forced to 'false' above
|
|
973
|
-
autocomplete:
|
|
957
|
+
autocomplete: qe,
|
|
974
958
|
// Exclude - forced to 'off' above
|
|
975
959
|
...q
|
|
976
960
|
} = this.options;
|
|
@@ -981,16 +965,16 @@ class Qe {
|
|
|
981
965
|
}
|
|
982
966
|
getResolvedOptions() {
|
|
983
967
|
return {
|
|
984
|
-
decimalMaxLength: this.options.decimalMaxLength ??
|
|
985
|
-
decimalMinLength: this.options.decimalMinLength ??
|
|
986
|
-
formatOn: this.options.formatOn ??
|
|
987
|
-
thousandSeparator: this.options.thousandSeparator ??
|
|
988
|
-
thousandStyle: this.options.thousandStyle ??
|
|
968
|
+
decimalMaxLength: this.options.decimalMaxLength ?? x,
|
|
969
|
+
decimalMinLength: this.options.decimalMinLength ?? I,
|
|
970
|
+
formatOn: this.options.formatOn ?? R,
|
|
971
|
+
thousandSeparator: this.options.thousandSeparator ?? O,
|
|
972
|
+
thousandStyle: this.options.thousandStyle ?? _,
|
|
989
973
|
decimalSeparator: this.options.decimalSeparator ?? E,
|
|
990
|
-
enableCompactNotation: this.options.enableCompactNotation ??
|
|
991
|
-
enableNegative: this.options.enableNegative ??
|
|
992
|
-
enableLeadingZeros: this.options.enableLeadingZeros ??
|
|
993
|
-
rawValueMode: this.options.rawValueMode ??
|
|
974
|
+
enableCompactNotation: this.options.enableCompactNotation ?? X,
|
|
975
|
+
enableNegative: this.options.enableNegative ?? P,
|
|
976
|
+
enableLeadingZeros: this.options.enableLeadingZeros ?? B,
|
|
977
|
+
rawValueMode: this.options.rawValueMode ?? W,
|
|
994
978
|
onChange: this.options.onChange
|
|
995
979
|
};
|
|
996
980
|
}
|
|
@@ -1144,7 +1128,7 @@ class Qe {
|
|
|
1144
1128
|
const t = this.getValue();
|
|
1145
1129
|
if (!t)
|
|
1146
1130
|
return NaN;
|
|
1147
|
-
const n = this.resolvedOptions.thousandSeparator ? L(t, this.resolvedOptions.thousandSeparator) : t, r = this.resolvedOptions.decimalSeparator && this.resolvedOptions.decimalSeparator !== "." ? n.replace(new RegExp(
|
|
1131
|
+
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;
|
|
1148
1132
|
return parseFloat(r);
|
|
1149
1133
|
}
|
|
1150
1134
|
/**
|
|
@@ -1161,9 +1145,8 @@ class Qe {
|
|
|
1161
1145
|
}
|
|
1162
1146
|
export {
|
|
1163
1147
|
v as FormatOn,
|
|
1164
|
-
|
|
1148
|
+
Ke as NumoraInput,
|
|
1165
1149
|
b as ThousandStyle,
|
|
1166
|
-
Ke as formatValueForNumora,
|
|
1167
1150
|
Ie as handleOnChangeNumoraInput,
|
|
1168
1151
|
xe as handleOnKeyDownNumoraInput,
|
|
1169
1152
|
Oe as handleOnPasteNumoraInput
|
|
@@ -22,13 +22,3 @@ export declare function handleOnKeyDownNumoraInput(e: KeyboardEvent, formattingO
|
|
|
22
22
|
*/
|
|
23
23
|
export declare function handleOnChangeNumoraInput(e: Event, decimalMaxLength: number, caretPositionBeforeChange?: CaretPositionInfo, formattingOptions?: FormattingOptions): void;
|
|
24
24
|
export declare function handleOnPasteNumoraInput(e: ClipboardEvent, decimalMaxLength: number, formattingOptions?: FormattingOptions): string;
|
|
25
|
-
/**
|
|
26
|
-
* Formats a value programmatically using Numora's full pipeline.
|
|
27
|
-
* This is useful for formatting values that are set externally (e.g., from props in React).
|
|
28
|
-
*
|
|
29
|
-
* @param value - The raw value to format
|
|
30
|
-
* @param maxDecimals - Maximum number of decimal places allowed
|
|
31
|
-
* @param formattingOptions - Formatting options (formatOn, thousandSeparator, etc.)
|
|
32
|
-
* @returns The formatted value string
|
|
33
|
-
*/
|
|
34
|
-
export declare function formatValueForNumora(value: string, maxDecimals: number, formattingOptions?: FormattingOptions): string;
|