jb-national-input
Version:
national input web component
2 lines • 1.86 kB
JavaScript
import{JBInputWebComponent as t}from"jb-input";function e(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)}var n,i,o,a,r;function s(t){return"string"!=typeof t?"":t.replace(/[۰-۹]/g,(function(t){return String.fromCharCode(t.charCodeAt(0)-1728)}))}var u=class extends t{constructor(){super(),n.add(this),this.initMobileInputWebComponent()}initMobileInputWebComponent(){const t=document.createElement("template");t.innerHTML="<style>.jb-input-web-component{--jb-input-input-direction: var(--jb-national-input-input-direction, ltr)}</style>",this.shadowRoot.appendChild(t.content.cloneNode(!0)),this.validation.addValidationListGetter(e(this,n,"m",r).bind(this)),e(this,n,"m",o).call(this),this.addStandardValueCallback(e(this,n,"m",i).bind(this))}};n=new WeakSet,i=function(t){let e="",n="";const i=/(?<nationalId>[\u06F0-\u06F90-9]{1,10})/g.exec(t);return e=i&&i.groups?i.groups.nationalId:"",n=s(e),{value:n,displayValue:e}},o=function(){this.elements.input.addEventListener("beforeinput",e(this,n,"m",a).bind(this))},a=function(t){const e=t.data;/[\u06F0-\u06F90-9]{1,10}/g.test(e)||"deleteContentBackward"==t.inputType||t.preventDefault()},r=function(){return[{validator:({value:t})=>function(t){if(0===t.length)return!0;const e=s(t);if(!/^\d{10}$/.test(e))return!1;const n=+e[9],i=e.split("").slice(0,9).reduce(((t,e,n)=>t+ +e*(10-n)),0)%11;return i<2?n===i:n+i===11}(t),message:"کد ملی وارد شده نامعتبر است"}]};!customElements.get("jb-national-input")&&window.customElements.define("jb-national-input",u);export{u as JBNationalInputWebComponent};
//# sourceMappingURL=jb-national-input.js.map