UNPKG

jb-payment-input

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