UNPKG

jb-payment-input

Version:
2 lines 4.62 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("jb-input")):"function"==typeof define&&define.amd?define(["exports","jb-input"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).JBPaymentInput={},t.JBInput)}(this,(function(t,e){"use strict";var n,i,r,s=Object.create,a=Object.defineProperty,o=Object.getOwnPropertyDescriptor,l=Object.getOwnPropertyNames,u=Object.getPrototypeOf,p=Object.prototype.hasOwnProperty;function c(t,e,n,i){if("a"===n&&!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"===n?i:"a"===n?i.call(t):i?i.value:e.get(t)}function h(t,e,n,i,r){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!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"===i?r.call(t,n):r?r.value=n:e.set(t,n),n}r=null!=(n=e)?s(u(n)):{},e=((t,e,n,i)=>{if(e&&"object"==typeof e||"function"==typeof e)for(var r,s=l(e),u=0,c=s.length;u<c;u++)r=s[u],p.call(t,r)||r===n||a(t,r,{get:(t=>e[t]).bind(null,r),enumerable:!(i=o(e,r))||i.enumerable});return t})(!i&&n&&n.__esModule?r:a(r,"default",{value:n,enumerable:!0}),n);function f(t){return"string"!=typeof t?"":t.replace(/[۰-۹]/g,(function(t){return String.fromCharCode(t.charCodeAt(0)-1728)}))}const d={validator:({value:t})=>16==t.length||0==t.length,message:"لطفا شماره کارت را کامل وارد کنید"},g={validator:({value:t})=>26==t.length||0==t.length,message:"لطفا شماره شبا را کامل وارد کنید"},m={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:"شماره شبا وارد شده نامعتبر است"},b=["CARD","SHABA"];var y,w,v,C,A,j,I,R,T,E,P,O=class extends e.JBInputWebComponent{get paymentInputType(){return c(this,w,"f")}set paymentInputType(t){b.includes(t)&&h(this,w,t||"CARD","f")}get separatorString(){return c(this,v,"f")}set separatorString(t){h(this,v,t,"f"),h(this,C,RegExp(c(this,v,"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(),y.add(this),w.set(this,this.getAttribute("input-type")||"CARD"),v.set(this," "),C.set(this,/\s/g),c(this,y,"m",A).call(this)}static get observedAttributes(){return[...e.JBInputWebComponent.observedAttributes,"input-type","separator"]}attributeChangedCallback(t,e,n){["input-type","separator"].includes(t)?c(this,y,"m",j).call(this,t,n):this.onAttributeChange(t,n)}};w=new WeakMap,v=new WeakMap,C=new WeakMap,y=new WeakSet,A=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(c(this,y,"m",P).bind(this)),c(this,y,"m",E).call(this),this.addStandardValueCallback(c(this,y,"m",T).bind(this))},j=function(t,e){switch(t){case"input-type":this.paymentInputType=e;break;case"separator":this.separatorString=e}},I=function(t){if("CARD"==c(this,w,"f")){let e=f(c(this,y,"m",R).call(this,t)).replace(/[^0-9]/g,"");return e=e.substring(0,16),e}if("SHABA"==c(this,w,"f")){const e=/(?<ir>(IR|ir|Ir|I|i)?)(?<other>.{0,})/g.exec(t);if(e&&e.groups){let t=f(c(this,y,"m",R).call(this,e.groups.other)).replace(/[^0-9]/g,"");t=t.substring(0,24);let n="";if(e.groups.ir)n=e.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},R=function(t){return t.replace(c(this,C,"f"),"")},T=function(t){let e="",n="";if("CARD"==c(this,w,"f")){n=c(this,y,"m",I).call(this,t);const i=RegExp(`(.*)(${c(this,C,"f").source})$`,"g");e=n.replace(/([0-9]{4})/g,`$1${c(this,v,"f")}`).replace(i,"$1")}if("SHABA"==c(this,w,"f")){n=c(this,y,"m",I).call(this,t);const i=/(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(n);e=i&&i.length>0?i.slice(1).filter((t=>""!==t)).join(c(this,v,"f")):n}return{value:n,displayValue:e}},E=function(){},P=function(){return"CARD"==c(this,w,"f")?[d]:[g,m]};!customElements.get("jb-payment-input")&&window.customElements.define("jb-payment-input",O),t.JBPaymentInputWebComponent=O,t.PaymentInputTypeList=b})); //# sourceMappingURL=jb-payment-input.umd.js.map