jb-national-input
Version:
national input web component
2 lines • 2.59 kB
JavaScript
!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).JBNationalInput={},t.JBInput)}(this,(function(t,e){"use strict";var n,i,o,r=Object.create,a=Object.defineProperty,u=Object.getOwnPropertyDescriptor,s=Object.getOwnPropertyNames,l=Object.getPrototypeOf,c=Object.prototype.hasOwnProperty;function p(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)}o=null!=(n=e)?r(l(n)):{},e=((t,e,n,i)=>{if(e&&"object"==typeof e||"function"==typeof e)for(var o,r=s(e),l=0,p=r.length;l<p;l++)o=r[l],c.call(t,o)||o===n||a(t,o,{get:(t=>e[t]).bind(null,o),enumerable:!(i=u(e,o))||i.enumerable});return t})(!i&&n&&n.__esModule?o:a(o,"default",{value:n,enumerable:!0}),n);var d,f,b,h,m;function y(t){return"string"!=typeof t?"":t.replace(/[۰-۹]/g,(function(t){return String.fromCharCode(t.charCodeAt(0)-1728)}))}var g=class extends e.JBInputWebComponent{constructor(){super(),d.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(p(this,d,"m",m).bind(this)),p(this,d,"m",b).call(this),this.addStandardValueCallback(p(this,d,"m",f).bind(this))}};d=new WeakSet,f=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=y(e),{value:n,displayValue:e}},b=function(){this.elements.input.addEventListener("beforeinput",p(this,d,"m",h).bind(this))},h=function(t){const e=t.data;/[\u06F0-\u06F90-9]{1,10}/g.test(e)||"deleteContentBackward"==t.inputType||t.preventDefault()},m=function(){return[{validator:({value:t})=>function(t){if(0===t.length)return!0;const e=y(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",g),t.JBNationalInputWebComponent=g}));
//# sourceMappingURL=jb-national-input.umd.js.map