UNPKG

jb-payment-input

Version:
2 lines 4.79 kB
var t=Object.create,e=Object.defineProperty,i=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,r=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,s=(s,o,l)=>(l=null!=s?t(r(s)):{},((t,r,s,o)=>{if(r&&"object"==typeof r||"function"==typeof r)for(var l,u=n(r),p=0,c=u.length;p<c;p++)l=u[p],a.call(t,l)||l===s||e(t,l,{get:(t=>r[t]).bind(null,l),enumerable:!(o=i(r,l))||o.enumerable});return t})(!o&&s&&s.__esModule?l:e(l,"default",{value:s,enumerable:!0}),s));const o=s(require("jb-input")),l=s(require("jb-core")),u=s(require("jb-core/i18n"));function p(t,e,i,n){if("a"===i&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?n:"a"===i?n.call(t):n?n.value:e.get(t)}function c(t,e,i,n,r){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===n?r.call(t,i):r?r.value=i:e.set(t,i),i}const h=new u.JBDictionary({fa:{cardLengthValidation:"لطفا شماره کارت را کامل وارد کنید",IBANLengthValidation:"لطفا شماره شبا را کامل وارد کنید",IBANFullValidation:"شماره شبا وارد شده نامعتبر است"},en:{cardLengthValidation:"Please enter all 16 digits of your card number.",IBANLengthValidation:"Please enter all 26 digits of your IBAN number.",IBANFullValidation:"IBAN number is invalid"}}),d={validator:({value:t})=>16==t.length||0==t.length,message:h.get(u.i18n,"cardLengthValidation"),stateType:"tooShort"},f={validator:({value:t})=>26==t.length||0==t.length,message:h.get(u.i18n,"IBANLengthValidation"),stateType:"tooShort"},g={validator:/(?:(IR[0-9]{0,2})([0-9]{0,4})([0-9]{0,4})([0-9]{0,4})([0-9]{0,4})([0-9]{0,4})([0-9]{0,2}))?/g,message:h.get(u.i18n,"IBANFullValidation"),stateType:"typeMismatch"},m=["CARD","SHABA"];var b,y,w,A,v,I,j,C,T,B,V,E=class extends o.JBInputWebComponent{get paymentInputType(){return p(this,y,"f")}set paymentInputType(t){m.includes(t)&&c(this,y,t||"CARD","f")}get separatorString(){return p(this,w,"f")}set separatorString(t){c(this,w,t,"f"),c(this,A,RegExp(p(this,w,"f").replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/\s/g,"\\s"),"g"),"f");const e=this.standardValue(this.value,"SET_VALUE");this.elements.input.value=e.displayValue}constructor(){super(),b.add(this),y.set(this,this.getAttribute("input-type")||"CARD"),w.set(this," "),A.set(this,/\s/g),p(this,b,"m",v).call(this)}static get observedAttributes(){return[...o.JBInputWebComponent.observedAttributes,"input-type","separator"]}attributeChangedCallback(t,e,i){["input-type","separator"].includes(t)?p(this,b,"m",I).call(this,t,i):this.onAttributeChange(t,i)}};y=new WeakMap,w=new WeakMap,A=new WeakMap,b=new WeakSet,v=function(){const t=document.createElement("template");t.innerHTML="<style>.jb-input-web-component{--jb-input-input-direction:ltr}</style>",this.shadowRoot.appendChild(t.content.cloneNode(!0)),this.validation.addValidationListGetter(p(this,b,"m",V).bind(this)),p(this,b,"m",B).call(this),this.addStandardValueCallback(p(this,b,"m",T).bind(this))},I=function(t,e){switch(t){case"input-type":this.paymentInputType=e;break;case"separator":this.separatorString=e}},j=function(t){if("CARD"==p(this,y,"f")){let e=(0,l.faToEnDigits)(p(this,b,"m",C).call(this,t)).replace(/[^0-9]/g,"");return e=e.substring(0,16),e}if("SHABA"==p(this,y,"f")){const e=/(?<ir>(IR|ir|Ir|I|i)?)(?<other>.{0,})/g.exec(t);if(e&&e.groups){let t=(0,l.faToEnDigits)(p(this,b,"m",C).call(this,e.groups.other)).replace(/[^0-9]/g,"");t=t.substring(0,24);let i="";if(e.groups.ir)i=e.groups.ir.toUpperCase();else{if(!(t.length>0))return"";i="IR"}if(1==i.length){if(!(t.length>0))return i;i="IR"}return i+t}return""}return t},C=function(t){return t.replace(p(this,A,"f"),"")},T=function(t){let e="",i="";if("CARD"==p(this,y,"f")){i=p(this,b,"m",j).call(this,t);const n=RegExp(`(.*)(${p(this,A,"f").source})$`,"g");e=i.replace(/([0-9]{4})/g,`$1${p(this,w,"f")}`).replace(n,"$1")}if("SHABA"==p(this,y,"f")){i=p(this,b,"m",j).call(this,t);const n=/(IR[0-9]{0,2})([0-9]{0,4})([0-9]{0,4})([0-9]{0,4})([0-9]{0,4})([0-9]{0,4})([0-9]{0,2})/g.exec(i);e=n&&n.length>0?n.slice(1).filter((t=>""!==t)).join(p(this,w,"f")):i}return{value:i,displayValue:e}},B=function(){},V=function(){return"CARD"==p(this,y,"f")?[d]:[f,g]};!customElements.get("jb-payment-input")&&window.customElements.define("jb-payment-input",E),exports.JBPaymentInputWebComponent=E,exports.PaymentInputTypeList=m; //# sourceMappingURL=jb-payment-input.cjs.js.map