UNPKG

jb-payment-input

Version:
3 lines (2 loc) 3.99 kB
"use strict";var t=require("jb-input");function e(t,e,r,i){if("a"===r&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?i:"a"===r?i.call(t):i?i.value:e.get(t)}function r(t,e,r,i,n){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!n:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?n.call(t,r):n?n.value=r:e.set(t,r),r}"function"==typeof SuppressedError&&SuppressedError;function i(t){if("string"!=typeof t)return"";return t.replace(/[۰-۹]/g,(function(t){return String.fromCharCode(t.charCodeAt(0)-1728)}))}const n={validator:({value:t})=>16==t.length,message:"لطفا شماره کارت را کامل وارد کنید"},s={validator:({value:t})=>26==t.length,message:"لطفا شماره شبا را کامل وارد کنید"},a={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:"لطفا شماره شبا را صحیح وارد کنید"},o=["CARD","SHABA"];var u,p,l,h,c,f,d,g,m,y,b;class w extends t.JBInputWebComponent{get paymentInputType(){return e(this,p,"f")}set paymentInputType(t){o.includes(t)&&r(this,p,t||"CARD","f")}get separatorString(){return e(this,l,"f")}set separatorString(t){r(this,l,t,"f"),r(this,h,RegExp(e(this,l,"f").replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/\s/g,"\\s"),"g"),"f");const i=this.standardValue(this.value,"SET_VALUE");this.elements.input.value=i.displayValue}constructor(){super(),u.add(this),p.set(this,this.getAttribute("input-type")||"CARD"),l.set(this," "),h.set(this,/\s/g),e(this,u,"m",c).call(this)}static get observedAttributes(){return[...t.JBInputWebComponent.observedAttributes,"input-type","separator"]}attributeChangedCallback(t,r,i){["input-type","separator"].includes(t)?e(this,u,"m",f).call(this,t,i):this.onAttributeChange(t,i)}}p=new WeakMap,l=new WeakMap,h=new WeakMap,u=new WeakSet,c=function(){const t=document.createElement("template");t.innerHTML="<style>.jb-input-web-component {\n --jb-input-input-direction: ltr;\n}</style>",this.shadowRoot.appendChild(t.content.cloneNode(!0)),this.validation.addValidationListGetter(e(this,u,"m",b).bind(this)),e(this,u,"m",y).call(this),this.addStandardValueCallback(e(this,u,"m",m).bind(this))},f=function(t,e){switch(t){case"input-type":this.paymentInputType=e;break;case"separator":this.separatorString=e}},d=function(t){if("CARD"==e(this,p,"f")){let r=i(e(this,u,"m",g).call(this,t)).replace(/[^0-9]/g,"");return r=r.substring(0,16),r}if("SHABA"==e(this,p,"f")){const r=/(?<ir>(IR|ir|Ir|I|i)?)(?<other>.{0,})/g.exec(t);if(r&&r.groups){let t=i(e(this,u,"m",g).call(this,r.groups.other)).replace(/[^0-9]/g,"");t=t.substring(0,24);let n="";if(r.groups.ir)n=r.groups.ir.toUpperCase();else{if(!(t.length>0))return"";n="IR"}if(1==n.length){if(!(t.length>0))return n;n="IR"}return n+t}return""}return t},g=function(t){return t.replace(e(this,h,"f"),"")},m=function(t){let r="",i="";if(console.log({inputType:e(this,p,"f")}),"CARD"==e(this,p,"f")){i=e(this,u,"m",d).call(this,t);const n=RegExp(`(.*)(${e(this,h,"f").source})$`,"g");r=i.replace(/([0-9]{4})/g,`$1${e(this,l,"f")}`).replace(n,"$1")}if("SHABA"==e(this,p,"f")){i=e(this,u,"m",d).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);r=n&&n.length>0?n.slice(1).filter((t=>""!==t)).join(e(this,l,"f")):i}return{value:i,displayValue:r}},y=function(){},b=function(){return"CARD"==e(this,p,"f")?[n]:[s,a]};!customElements.get("jb-payment-input")&&window.customElements.define("jb-payment-input",w),exports.JBPaymentInputWebComponent=w,exports.PaymentInputTypeList=o; //# sourceMappingURL=jb-payment-input.cjs.js.map