import{S as t}from"./p-24fbb59b.js";import{i as s}from"./p-add8f9c6.js";class e extends t{constructor(t,s=!1){super(),this.insertMode=!0,this.maskConfig=t,this.overrideValue=s,this.slotRegex=new RegExp(t.slot),this.acceptRegex=new RegExp(t.accept,"g"),this.insertMode=!1!==t.insertMode}static getPhoneMaskStrategy(t=!1){return new e(this.DEFAULT_PHONE_MASK_CONFIG,t)}static getZipcodeMaskStrategy(t=!1){return new e(this.DEFAULT_ZIPCODE_MASK_CONFIG,t)}static getTaxIdMaskStrategy(t=!1){return new e(this.DEFAULT_TAX_ID_MASK_CONFIG,t)}setMaskConfig(t){this.maskConfig=t}format(t,e){const i=null==e?void 0:e.caretPosition;if(t.length>this.getLengthLimit()&&s(i)){const s=[...t],e=t.length-this.getLengthLimit();return s.splice(i-e,e),s.join("")}return this.replaceMaskWithMatchedInputSlots(t,this.getMatchedInputSlotValue(t))}calculateCaretPosition(t,e){if(!s(e))return null;if(t.length>this.getLengthLimit())return e-(t.length-this.getLengthLimit());const i=t.substring(0,e);return e+(this.format(i).length-i.length)}shouldOverrideComponentValueAfterBlur(){return!!this.overrideValue||!(!this.maskConfig||!0!==this.maskConfig.overrideValue)}shouldTriggerAtInit(){return!(!this.maskConfig||!0!==this.maskConfig.triggerAtInit)}getLengthLimit(){return this.maskConfig.mask.length}getMatchedInputSlotValue(t){return t.match(this.acceptRegex)||[]}replaceMaskWithMatchedInputSlots(t,s){const e=[];let i=-1;for(let r=0;r<this.maskConfig.mask.length;r++){const n=this.maskConfig.mask.charAt(r);if(this.slotRegex.test(n)&&s.length){const t=s.shift();t&&(e.push(t),i=r)}else this.insertMode||s.shift(),t.charAt(r)===n&&(i=r),e.push(n)}const r=this.insertMode?i+1:t.length;return e.join("").slice(0,r)}}e.DEFAULT_PHONE_MASK_CONFIG={mask:"(999) 999-9999",slot:"9",accept:/\d/g},e.DEFAULT_ZIPCODE_MASK_CONFIG={mask:"99999",slot:"9",accept:/\d/g},e.DEFAULT_TAX_ID_MASK_CONFIG={mask:"99-9999999",slot:"9",accept:/\d/g};export{e as S}