UNPKG

finpro

Version:
3 lines (2 loc) 19.6 kB
var h=function(u,d,f,l){if(f==="a"&&!l)throw new TypeError("Private accessor was defined without a getter");if(typeof d=="function"?u!==d||!l:!d.has(u))throw new TypeError("Cannot read private member from an object whose class did not declare it");return f==="m"?l:f==="a"?l.call(u):l?l.value:d.get(u)},y=function(u,d,f,l,w){if(l==="m")throw new TypeError("Private method is not writable");if(l==="a"&&!w)throw new TypeError("Private accessor was defined without a setter");if(typeof d=="function"?u!==d||!w:!d.has(u))throw new TypeError("Cannot write private member to an object whose class did not declare it");return l==="a"?w.call(u,f):w?w.value=f:d.set(u,f),f};function pt(u){var d,f,l,w,T,P,C,A,I,H,D,W,S,_,b,z,$,U;class j extends u{constructor(...r){super(...r),d.add(this),this.internals=this.attachInternals(),f.set(this,!1),l.set(this,!1),w.set(this,!1),T.set(this,void 0),P.set(this,void 0),A.set(this,""),I.set(this,()=>{y(this,w,!0,"f"),y(this,f,!0,"f"),h(this,d,"m",b).call(this)}),H.set(this,()=>{y(this,f,!1,"f"),h(this,d,"m",z).call(this,this.shouldFormValueUpdate()?h(this,A,"f"):""),!this.validity.valid&&h(this,w,"f")&&y(this,l,!0,"f");let n=h(this,d,"m",b).call(this);this.validationMessageCallback&&this.validationMessageCallback(n?this.internals.validationMessage:"")}),D.set(this,()=>{var n;y(this,l,!0,"f"),h(this,d,"m",b).call(this),(n=this===null||this===void 0?void 0:this.validationMessageCallback)===null||n===void 0||n.call(this,this.showError?this.internals.validationMessage:"")}),W.set(this,void 0),S.set(this,!1),_.set(this,Promise.resolve()),this.addEventListener("focus",h(this,I,"f")),this.addEventListener("blur",h(this,H,"f")),this.addEventListener("invalid",h(this,D,"f")),this.setValue(null)}static get formAssociated(){return!0}static get validators(){return this.formControlValidators||[]}static get observedAttributes(){let r=this.validators.map(p=>p.attribute).flat(),n=super.observedAttributes||[];return[...new Set([...n,...r])]}static getValidator(r){return this.validators.find(n=>n.attribute===r)||null}static getValidators(r){return this.validators.filter(n=>{var m;if(n.attribute===r||!((m=n.attribute)===null||m===void 0)&&m.includes(r))return!0})}get form(){return this.internals.form}get showError(){return h(this,d,"m",b).call(this)}checkValidity(){return this.internals.checkValidity()}get validity(){return this.internals.validity}get validationMessage(){return this.internals.validationMessage}attributeChangedCallback(r,n,m){var p;(p=super.attributeChangedCallback)===null||p===void 0||p.call(this,r,n,m);let x=this.constructor.getValidators(r);x!=null&&x.length&&this.validationTarget&&this.setValue(h(this,A,"f"))}setValue(r){var n;y(this,l,!1,"f"),(n=this.validationMessageCallback)===null||n===void 0||n.call(this,""),y(this,A,r,"f");let p=this.shouldFormValueUpdate()?r:null;this.internals.setFormValue(p),h(this,d,"m",z).call(this,p),this.valueChangedCallback&&this.valueChangedCallback(p),h(this,d,"m",b).call(this)}shouldFormValueUpdate(){return!0}get validationComplete(){return new Promise(r=>r(h(this,_,"f")))}formResetCallback(){var r,n;y(this,w,!1,"f"),y(this,l,!1,"f"),h(this,d,"m",b).call(this),(r=this.resetFormControl)===null||r===void 0||r.call(this),(n=this.validationMessageCallback)===null||n===void 0||n.call(this,h(this,d,"m",b).call(this)?this.validationMessage:"")}}return f=new WeakMap,l=new WeakMap,w=new WeakMap,T=new WeakMap,P=new WeakMap,A=new WeakMap,I=new WeakMap,H=new WeakMap,D=new WeakMap,W=new WeakMap,S=new WeakMap,_=new WeakMap,d=new WeakSet,C=function(){let r=this.getRootNode(),n=`${this.localName}[name="${this.getAttribute("name")}"]`;return r.querySelectorAll(n)},b=function(){if(this.hasAttribute("disabled"))return!1;let r=h(this,l,"f")||h(this,w,"f")&&!this.validity.valid&&!h(this,f,"f");return r&&this.internals.states?this.internals.states.add("--show-error"):this.internals.states&&this.internals.states.delete("--show-error"),r},z=function(r){let n=this.constructor,m={},p=n.validators,R=[],x=p.some(v=>v.isValid instanceof Promise);h(this,S,"f")||(y(this,_,new Promise(v=>{y(this,W,v,"f")}),"f"),y(this,S,!0,"f")),h(this,T,"f")&&(h(this,T,"f").abort(),y(this,P,h(this,T,"f"),"f"));let L=new AbortController;y(this,T,L,"f");let O,q=!1;p.length&&(p.forEach(v=>{let B=v.key||"customError",N=v.isValid(this,r,L.signal);N instanceof Promise?(R.push(N),N.then(G=>{G!=null&&(m[B]=!G,O=h(this,d,"m",U).call(this,v,r),h(this,d,"m",$).call(this,m,O))})):(m[B]=!N,this.validity[B]!==!N&&(q=!0),!N&&!O&&(O=h(this,d,"m",U).call(this,v,r)))}),Promise.allSettled(R).then(()=>{var v;L!=null&&L.signal.aborted||(y(this,S,!1,"f"),(v=h(this,W,"f"))===null||v===void 0||v.call(this))}),(q||!x)&&h(this,d,"m",$).call(this,m,O))},$=function(r,n){if(this.validationTarget)this.internals.setValidity(r,n,this.validationTarget);else{if(this.internals.setValidity(r,n),this.internals.validity.valid)return;let m=0,p=setInterval(()=>{m>=100||this.validity.valid?clearInterval(p):this.validationTarget&&(this.internals.setValidity(this.validity,n,this.validationTarget),clearInterval(p)),m+=1},0)}},U=function(r,n){if(this.validityCallback){let m=this.validityCallback(r.key||"customError");if(m)return m}return r.message instanceof Function?r.message(this,n):r.message},j}(function(){"use strict";let u=new WeakMap,d=new WeakMap,f=new WeakMap,l=new WeakMap,w=new WeakMap,T=new WeakMap,P=new WeakMap,C=new WeakMap,A=new WeakMap,I=new WeakMap,H=new WeakMap,D=new WeakMap,W=new WeakMap,S=new WeakMap,_=new WeakMap,b={ariaAtomic:"aria-atomic",ariaAutoComplete:"aria-autocomplete",ariaBusy:"aria-busy",ariaChecked:"aria-checked",ariaColCount:"aria-colcount",ariaColIndex:"aria-colindex",ariaColIndexText:"aria-colindextext",ariaColSpan:"aria-colspan",ariaCurrent:"aria-current",ariaDisabled:"aria-disabled",ariaExpanded:"aria-expanded",ariaHasPopup:"aria-haspopup",ariaHidden:"aria-hidden",ariaInvalid:"aria-invalid",ariaKeyShortcuts:"aria-keyshortcuts",ariaLabel:"aria-label",ariaLevel:"aria-level",ariaLive:"aria-live",ariaModal:"aria-modal",ariaMultiLine:"aria-multiline",ariaMultiSelectable:"aria-multiselectable",ariaOrientation:"aria-orientation",ariaPlaceholder:"aria-placeholder",ariaPosInSet:"aria-posinset",ariaPressed:"aria-pressed",ariaReadOnly:"aria-readonly",ariaRelevant:"aria-relevant",ariaRequired:"aria-required",ariaRoleDescription:"aria-roledescription",ariaRowCount:"aria-rowcount",ariaRowIndex:"aria-rowindex",ariaRowIndexText:"aria-rowindextext",ariaRowSpan:"aria-rowspan",ariaSelected:"aria-selected",ariaSetSize:"aria-setsize",ariaSort:"aria-sort",ariaValueMax:"aria-valuemax",ariaValueMin:"aria-valuemin",ariaValueNow:"aria-valuenow",ariaValueText:"aria-valuetext",role:"role"},z=(e,t)=>{for(let a in b){t[a]=null;let i=null,s=b[a];Object.defineProperty(t,a,{get(){return i},set(c){i=c,e.isConnected?e.setAttribute(s,c):I.set(e,t)}})}};function $(e){let t=l.get(e),{form:a}=t;tt(e,a,t),q(e,t.labels)}let U=(e,t=!1)=>{let a=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode(c){return l.has(c)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}}),i=a.nextNode(),s=!t||e.disabled;for(;i;)i.formDisabledCallback&&s&&R(i,e.disabled),i=a.nextNode()},j={attributes:!0,attributeFilter:["disabled","name"]},M=Q()?new MutationObserver(e=>{for(let t of e){let a=t.target;if(t.attributeName==="disabled"&&(a.constructor.formAssociated?R(a,a.hasAttribute("disabled")):a.localName==="fieldset"&&U(a)),t.attributeName==="name"&&a.constructor.formAssociated){let i=l.get(a),s=A.get(a);i.setFormValue(s)}}}):{};function r(e){e.forEach(t=>{let{addedNodes:a,removedNodes:i}=t,s=Array.from(a),c=Array.from(i);s.forEach(o=>{var E;if(l.has(o)&&o.constructor.formAssociated&&$(o),I.has(o)){let g=I.get(o);Object.keys(b).filter(k=>g[k]!==null).forEach(k=>{o.setAttribute(b[k],g[k])}),I.delete(o)}if(_.has(o)){let g=_.get(o);o.setAttribute("internals-valid",g.validity.valid.toString()),o.setAttribute("internals-invalid",(!g.validity.valid).toString()),o.setAttribute("aria-invalid",(!g.validity.valid).toString()),_.delete(o)}if(o.localName==="form"){let g=C.get(o),F=document.createTreeWalker(o,NodeFilter.SHOW_ELEMENT,{acceptNode(ot){return l.has(ot)&&!(g&&g.has(ot))?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}}),k=F.nextNode();for(;k;)$(k),k=F.nextNode()}o.localName==="fieldset"&&((E=M.observe)==null||E.call(M,o,j),U(o,!0))}),c.forEach(o=>{let E=l.get(o);E&&f.get(E)&&x(E),P.has(o)&&P.get(o).disconnect()})})}function n(e){e.forEach(t=>{let{removedNodes:a}=t;a.forEach(i=>{let s=W.get(t.target);l.has(i)&&at(i),s.disconnect()})})}let m=e=>{var a;let t=new MutationObserver(n);(a=t.observe)==null||a.call(t,e,{childList:!0}),W.set(e,t)};Q()&&new MutationObserver(r);let p={childList:!0,subtree:!0},R=(e,t)=>{e.toggleAttribute("internals-disabled",t),t?e.setAttribute("aria-disabled","true"):e.removeAttribute("aria-disabled"),e.formDisabledCallback&&e.formDisabledCallback.apply(e,[t])},x=e=>{f.get(e).forEach(a=>{a.remove()}),f.set(e,[])},L=(e,t)=>{let a=document.createElement("input");return a.type="hidden",a.name=e.getAttribute("name"),e.after(a),f.get(t).push(a),a},O=(e,t)=>{var a;f.set(t,[]),(a=M.observe)==null||a.call(M,e,j)},q=(e,t)=>{if(t.length){Array.from(t).forEach(i=>i.addEventListener("click",e.click.bind(e)));let a=t[0].id;t[0].id||(a=`${t[0].htmlFor}_Label`,t[0].id=a),e.setAttribute("aria-labelledby",a)}},v=e=>{let t=Array.from(e.elements).filter(c=>!c.tagName.includes("-")&&c.validity).map(c=>c.validity.valid),a=C.get(e)||[],i=Array.from(a).filter(c=>c.isConnected).map(c=>l.get(c).validity.valid),s=[...t,...i].includes(!1);e.toggleAttribute("internals-invalid",s),e.toggleAttribute("internals-valid",!s)},B=e=>{v(J(e.target))},N=e=>{v(J(e.target))},Z=e=>{let t=":is(button[type=submit], input[type=submit], button:not([type])):not([disabled])",a=`${t}:not([form])`;e.id&&(a+=`,${t}[form='${e.id}']`),e.addEventListener("click",i=>{if(i.target.closest(a)){let c=C.get(e);if(e.noValidate)return;c.size&&Array.from(c).reverse().map(g=>l.get(g).reportValidity()).includes(!1)&&i.preventDefault()}})},G=e=>{let t=C.get(e.target);t&&t.size&&t.forEach(a=>{a.constructor.formAssociated&&a.formResetCallback&&a.formResetCallback.apply(a)})},tt=(e,t,a)=>{if(t){let i=C.get(t);if(i)i.add(e);else{let s=new Set;s.add(e),C.set(t,s),Z(t),t.addEventListener("reset",G),t.addEventListener("input",B),t.addEventListener("change",N)}T.set(t,{ref:e,internals:a}),e.constructor.formAssociated&&e.formAssociatedCallback&&setTimeout(()=>{e.formAssociatedCallback.apply(e,[t])},0),v(t)}},J=e=>{let t=e.parentNode;return t&&t.tagName!=="FORM"&&(t=J(t)),t},V=(e,t,a=DOMException)=>{if(!e.constructor.formAssociated)throw new a(t)},et=(e,t,a)=>{let i=C.get(e);return i&&i.size&&i.forEach(s=>{l.get(s)[a]()||(t=!1)}),t},at=e=>{if(e.constructor.formAssociated){let t=l.get(e),{labels:a,form:i}=t;q(e,a),tt(e,i,t)}};function Q(){return typeof MutationObserver<"u"}class nt{constructor(){this.badInput=!1,this.customError=!1,this.patternMismatch=!1,this.rangeOverflow=!1,this.rangeUnderflow=!1,this.stepMismatch=!1,this.tooLong=!1,this.tooShort=!1,this.typeMismatch=!1,this.valid=!0,this.valueMissing=!1,Object.seal(this)}}let lt=e=>(e.badInput=!1,e.customError=!1,e.patternMismatch=!1,e.rangeOverflow=!1,e.rangeUnderflow=!1,e.stepMismatch=!1,e.tooLong=!1,e.tooShort=!1,e.typeMismatch=!1,e.valid=!0,e.valueMissing=!1,e),ct=(e,t,a)=>(e.valid=dt(t),Object.keys(t).forEach(i=>e[i]=t[i]),a&&v(a),e),dt=e=>{let t=!0;for(let a in e)a!=="valid"&&e[a]!==!1&&(t=!1);return t},Y=new WeakMap;function it(e,t){e.toggleAttribute(t,!0),e.part&&e.part.add(t)}class X extends Set{static get isPolyfilled(){return!0}constructor(t){if(super(),!t||!t.tagName||t.tagName.indexOf("-")===-1)throw new TypeError("Illegal constructor");Y.set(this,t)}add(t){if(!/^--/.test(t)||typeof t!="string")throw new DOMException(`Failed to execute 'add' on 'CustomStateSet': The specified value ${t} must start with '--'.`);let a=super.add(t),i=Y.get(this),s=`state${t}`;return i.isConnected?it(i,s):setTimeout(()=>{it(i,s)}),a}clear(){for(let[t]of this.entries())this.delete(t);super.clear()}delete(t){let a=super.delete(t),i=Y.get(this);return i.isConnected?(i.toggleAttribute(`state${t}`,!1),i.part&&i.part.remove(`state${t}`)):setTimeout(()=>{i.toggleAttribute(`state${t}`,!1),i.part&&i.part.remove(`state${t}`)}),a}}function st(e,t,a,i){if(a==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?e!==t||!i:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return a==="m"?i:a==="a"?i.call(e):i?i.value:t.get(e)}function ht(e,t,a,i,s){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?e!==t||!s:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(e,a):s?s.value=a:t.set(e,a),a}var K;class ut{constructor(t){K.set(this,void 0),ht(this,K,t,"f");for(let a=0;a<t.length;a++){let i=t[a];this[a]=i,i.hasAttribute("name")&&(this[i.getAttribute("name")]=i)}Object.freeze(this)}get length(){return st(this,K,"f").length}[(K=new WeakMap,Symbol.iterator)](){return st(this,K,"f")[Symbol.iterator]()}item(t){return this[t]==null?null:this[t]}namedItem(t){return this[t]==null?null:this[t]}}function ft(){let e=HTMLFormElement.prototype.checkValidity;HTMLFormElement.prototype.checkValidity=a;let t=HTMLFormElement.prototype.reportValidity;HTMLFormElement.prototype.reportValidity=i;function a(...c){let o=e.apply(this,c);return et(this,o,"checkValidity")}function i(...c){let o=t.apply(this,c);return et(this,o,"reportValidity")}let{get:s}=Object.getOwnPropertyDescriptor(HTMLFormElement.prototype,"elements");Object.defineProperty(HTMLFormElement.prototype,"elements",{get(...c){let o=s.call(this,...c),E=Array.from(C.get(this)||[]);if(E.length===0)return o;let g=Array.from(o).concat(E).sort((F,k)=>F.compareDocumentPosition?F.compareDocumentPosition(k)&2?1:-1:0);return new ut(g)}})}class rt{static get isPolyfilled(){return!0}constructor(t){if(!t||!t.tagName||t.tagName.indexOf("-")===-1)throw new TypeError("Illegal constructor");let a=t.getRootNode(),i=new nt;this.states=new X(t),u.set(this,t),d.set(this,i),l.set(t,this),z(t,this),O(t,this),Object.seal(this),a instanceof DocumentFragment&&m(a)}checkValidity(){let t=u.get(this);if(V(t,"Failed to execute 'checkValidity' on 'ElementInternals': The target element is not a form-associated custom element."),!this.willValidate)return!0;let a=d.get(this);if(!a.valid){let i=new Event("invalid",{bubbles:!1,cancelable:!0,composed:!1});t.dispatchEvent(i)}return a.valid}get form(){let t=u.get(this);V(t,"Failed to read the 'form' property from 'ElementInternals': The target element is not a form-associated custom element.");let a;return t.constructor.formAssociated===!0&&(a=J(t)),a}get labels(){let t=u.get(this);V(t,"Failed to read the 'labels' property from 'ElementInternals': The target element is not a form-associated custom element.");let a=t.getAttribute("id"),i=t.getRootNode();return i&&a?i.querySelectorAll(`[for="${a}"]`):[]}reportValidity(){let t=u.get(this);if(V(t,"Failed to execute 'reportValidity' on 'ElementInternals': The target element is not a form-associated custom element."),!this.willValidate)return!0;let a=this.checkValidity(),i=D.get(this);if(i&&!t.constructor.formAssociated)throw new DOMException("Failed to execute 'reportValidity' on 'ElementInternals': The target element is not a form-associated custom element.");return!a&&i&&(t.focus(),i.focus()),a}setFormValue(t){let a=u.get(this);if(V(a,"Failed to execute 'setFormValue' on 'ElementInternals': The target element is not a form-associated custom element."),x(this),t!=null&&!(t instanceof FormData)){if(a.getAttribute("name")){let i=L(a,this);i.value=t}}else t!=null&&t instanceof FormData&&Array.from(t).reverse().forEach(([i,s])=>{if(typeof s=="string"){let c=L(a,this);c.name=i,c.value=s}});A.set(a,t)}setValidity(t,a,i){let s=u.get(this);if(V(s,"Failed to execute 'setValidity' on 'ElementInternals': The target element is not a form-associated custom element."),!t)throw new TypeError("Failed to execute 'setValidity' on 'ElementInternals': 1 argument required, but only 0 present.");D.set(this,i);let c=d.get(this),o={};for(let F in t)o[F]=t[F];Object.keys(o).length===0&&lt(c);let E={...c,...o};delete E.valid;let{valid:g}=ct(c,E,this.form);if(!g&&!a)throw new DOMException("Failed to execute 'setValidity' on 'ElementInternals': The second argument should not be empty if one or more flags in the first argument are true.");w.set(this,g?"":a),s.isConnected?(s.toggleAttribute("internals-invalid",!g),s.toggleAttribute("internals-valid",g),s.setAttribute("aria-invalid",`${!g}`)):_.set(s,this)}get shadowRoot(){let t=u.get(this),a=H.get(t);return a||null}get validationMessage(){let t=u.get(this);return V(t,"Failed to read the 'validationMessage' property from 'ElementInternals': The target element is not a form-associated custom element."),w.get(this)}get validity(){let t=u.get(this);return V(t,"Failed to read the 'validity' property from 'ElementInternals': The target element is not a form-associated custom element."),d.get(this)}get willValidate(){let t=u.get(this);return V(t,"Failed to read the 'willValidate' property from 'ElementInternals': The target element is not a form-associated custom element."),!(t.disabled||t.hasAttribute("disabled")||t.hasAttribute("readonly"))}}function mt(){if(typeof window>"u"||!window.ElementInternals||!HTMLElement.prototype.attachInternals)return!1;class e extends HTMLElement{constructor(){super(),this.internals=this.attachInternals()}}let t=`element-internals-feature-detection-${Math.random().toString(36).replace(/[^a-z]+/g,"")}`;customElements.define(t,e);let a=new e;return["shadowRoot","form","willValidate","validity","validationMessage","labels","setFormValue","setValidity","checkValidity","reportValidity"].every(i=>i in a.internals)}if(mt()){if(typeof window<"u"&&!window.CustomStateSet){window.CustomStateSet=X;let e=HTMLElement.prototype.attachInternals;HTMLElement.prototype.attachInternals=function(...t){let a=e.call(this,t);return a.states=new X(this),a}}}else{if(typeof window<"u"&&(window.ElementInternals=rt),typeof CustomElementRegistry<"u"){let e=CustomElementRegistry.prototype.define;CustomElementRegistry.prototype.define=function(t,a,i){if(a.formAssociated){let s=a.prototype.connectedCallback;a.prototype.connectedCallback=function(){S.has(this)||(S.set(this,!0),this.hasAttribute("disabled")&&R(this,!0)),s!=null&&s.apply(this),at(this)}}e.call(this,t,a,i)}}if(typeof HTMLElement<"u"&&(HTMLElement.prototype.attachInternals=function(){if(this.tagName){if(this.tagName.indexOf("-")===-1)throw new Error("Failed to execute 'attachInternals' on 'HTMLElement': Unable to attach ElementInternals to non-custom elements.")}else return{};if(l.has(this))throw new DOMException("DOMException: Failed to execute 'attachInternals' on 'HTMLElement': ElementInternals for the specified element was already attached.");return new rt(this)}),typeof Element<"u"){let e=function(...a){let i=t.apply(this,a);if(H.set(this,i),Q()){let s=new MutationObserver(r);window.ShadyDOM?s.observe(this,p):s.observe(i,p),P.set(this,s)}return i},t=Element.prototype.attachShadow;Element.prototype.attachShadow=e}Q()&&new MutationObserver(r).observe(document.documentElement,p),typeof HTMLFormElement<"u"&&ft(),typeof window<"u"&&!window.CustomStateSet&&(window.CustomStateSet=X)}})();export{pt as a}; //# sourceMappingURL=chunk-T72NEGXT.js.map