UNPKG

jb-payment-input

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