@trendyol/baklava
Version:
Trendyol Baklava Design System
3 lines (2 loc) • 19.1 kB
JavaScript
var d=function(u,c,g,o){if(g==="a"&&!o)throw new TypeError("Private accessor was defined without a getter");if(typeof c=="function"?u!==c||!o:!c.has(u))throw new TypeError("Cannot read private member from an object whose class did not declare it");return g==="m"?o:g==="a"?o.call(u):o?o.value:c.get(u)},w=function(u,c,g,o,y){if(o==="m")throw new TypeError("Private method is not writable");if(o==="a"&&!y)throw new TypeError("Private accessor was defined without a setter");if(typeof c=="function"?u!==c||!y:!c.has(u))throw new TypeError("Cannot write private member to an object whose class did not declare it");return o==="a"?y.call(u,g):y?y.value=g:c.set(u,g),g};function pt(u){var c,g,o,y,S,P,E,Z,_,D,$,U,O,k,T,V,z,q,B;class J extends u{constructor(...s){var n,m,p;super(...s),c.add(this),this.internals=this.attachInternals(),g.set(this,!1),o.set(this,!1),y.set(this,!1),S.set(this,void 0),P.set(this,void 0),E.set(this,!0),_.set(this,""),D.set(this,()=>{w(this,y,!0,"f"),w(this,g,!0,"f"),d(this,c,"m",V).call(this)}),$.set(this,()=>{w(this,g,!1,"f"),d(this,c,"m",z).call(this,this.shouldFormValueUpdate()?d(this,_,"f"):""),!this.validity.valid&&d(this,y,"f")&&w(this,o,!0,"f");let F=d(this,c,"m",V).call(this);this.validationMessageCallback&&this.validationMessageCallback(F?this.internals.validationMessage:"")}),U.set(this,()=>{var F;d(this,E,"f")&&this.validationTarget&&(this.internals.setValidity(this.validity,this.validationMessage,this.validationTarget),w(this,E,!1,"f")),w(this,y,!0,"f"),w(this,o,!0,"f"),d(this,c,"m",V).call(this),(F=this===null||this===void 0?void 0:this.validationMessageCallback)===null||F===void 0||F.call(this,this.showError?this.internals.validationMessage:"")}),O.set(this,void 0),k.set(this,!1),T.set(this,Promise.resolve()),(n=this.addEventListener)===null||n===void 0||n.call(this,"focus",d(this,D,"f")),(m=this.addEventListener)===null||m===void 0||m.call(this,"blur",d(this,$,"f")),(p=this.addEventListener)===null||p===void 0||p.call(this,"invalid",d(this,U,"f")),this.setValue(null)}static get formAssociated(){return!0}static get validators(){return this.formControlValidators||[]}static get observedAttributes(){let s=this.validators.map(p=>p.attribute).flat(),n=super.observedAttributes||[];return[...new Set([...n,...s])]}static getValidator(s){return this.validators.find(n=>n.attribute===s)||null}static getValidators(s){return this.validators.filter(n=>{var m;if(n.attribute===s||!((m=n.attribute)===null||m===void 0)&&m.includes(s))return!0})}get form(){return this.internals.form}get showError(){return d(this,c,"m",V).call(this)}checkValidity(){return this.internals.checkValidity()}get validity(){return this.internals.validity}get validationMessage(){return this.internals.validationMessage}attributeChangedCallback(s,n,m){var p;(p=super.attributeChangedCallback)===null||p===void 0||p.call(this,s,n,m);let x=this.constructor.getValidators(s);x!=null&&x.length&&this.validationTarget&&this.setValue(d(this,_,"f"))}setValue(s){var n;w(this,o,!1,"f"),(n=this.validationMessageCallback)===null||n===void 0||n.call(this,""),w(this,_,s,"f");let p=this.shouldFormValueUpdate()?s:null;this.internals.setFormValue(p),d(this,c,"m",z).call(this,p),this.valueChangedCallback&&this.valueChangedCallback(p),d(this,c,"m",V).call(this)}shouldFormValueUpdate(){return!0}get validationComplete(){return new Promise(s=>s(d(this,T,"f")))}formResetCallback(){var s,n;w(this,y,!1,"f"),w(this,o,!1,"f"),d(this,c,"m",V).call(this),(s=this.resetFormControl)===null||s===void 0||s.call(this),(n=this.validationMessageCallback)===null||n===void 0||n.call(this,d(this,c,"m",V).call(this)?this.validationMessage:"")}}return g=new WeakMap,o=new WeakMap,y=new WeakMap,S=new WeakMap,P=new WeakMap,E=new WeakMap,_=new WeakMap,D=new WeakMap,$=new WeakMap,U=new WeakMap,O=new WeakMap,k=new WeakMap,T=new WeakMap,c=new WeakSet,Z=function(){let s=this.getRootNode(),n=`${this.localName}[name="${this.getAttribute("name")}"]`;return s.querySelectorAll(n)},V=function(){if(this.hasAttribute("disabled"))return!1;let s=d(this,o,"f")||d(this,y,"f")&&!this.validity.valid&&!d(this,g,"f");return s&&this.internals.states?this.internals.states.add("--show-error"):this.internals.states&&this.internals.states.delete("--show-error"),s},z=function(s){let n=this.constructor,m={},p=n.validators,F=[],x=p.some(M=>M.isValid instanceof Promise);d(this,k,"f")||(w(this,T,new Promise(M=>{w(this,O,M,"f")}),"f"),w(this,k,!0,"f")),d(this,S,"f")&&(d(this,S,"f").abort(),w(this,P,d(this,S,"f"),"f"));let R=new AbortController;w(this,S,R,"f");let L,H=!1;p.length&&(p.forEach(M=>{let K=M.key||"customError",N=M.isValid(this,s,R.signal);N instanceof Promise?(F.push(N),N.then(G=>{G!=null&&(m[K]=!G,L=d(this,c,"m",B).call(this,M,s),d(this,c,"m",q).call(this,m,L))})):(m[K]=!N,this.validity[K]!==!N&&(H=!0),!N&&!L&&(L=d(this,c,"m",B).call(this,M,s)))}),Promise.allSettled(F).then(()=>{var M;R!=null&&R.signal.aborted||(w(this,k,!1,"f"),(M=d(this,O,"f"))===null||M===void 0||M.call(this))}),(H||!x)&&d(this,c,"m",q).call(this,m,L))},q=function(s,n){if(this.validationTarget)this.internals.setValidity(s,n,this.validationTarget),w(this,E,!1,"f");else{if(this.internals.setValidity(s,n),this.internals.validity.valid)return;w(this,E,!0,"f")}},B=function(s,n){if(this.validityCallback){let m=this.validityCallback(s.key||"customError");if(m)return m}return s.message instanceof Function?s.message(this,n):s.message},J}(function(){"use strict";let u=new WeakMap,c=new WeakMap,g=new WeakMap,o=new WeakMap,y=new WeakMap,S=new WeakMap,P=new WeakMap,E=new WeakMap,Z=new WeakMap,_=new WeakMap,D=new WeakMap,$=new WeakMap,U=new WeakMap,O=new WeakMap,k=new WeakMap,T={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"},V=(e,t)=>{for(let a in T){t[a]=null;let i=null,r=T[a];Object.defineProperty(t,a,{get(){return i},set(h){i=h,e.isConnected?e.setAttribute(r,h):_.set(e,t)}})}};function z(e){let t=o.get(e),{form:a}=t;G(e,a,t),L(e,t.labels)}let q=(e,t=!1)=>{let a=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode(h){return o.has(h)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}}),i=a.nextNode(),r=!t||e.disabled;for(;i;)i.formDisabledCallback&&r&&p(i,e.disabled),i=a.nextNode()},B={attributes:!0,attributeFilter:["disabled"]},J=new MutationObserver(e=>{for(let t of e){let a=t.target;a.constructor.formAssociated?p(a,a.hasAttribute("disabled")):a.localName==="fieldset"&&q(a)}});function A(e){e.forEach(t=>{let{addedNodes:a,removedNodes:i}=t,r=Array.from(a),h=Array.from(i);r.forEach(l=>{if(o.has(l)&&l.constructor.formAssociated&&z(l),_.has(l)){let v=_.get(l);Object.keys(T).filter(f=>v[f]!==null).forEach(f=>{l.setAttribute(T[f],v[f])}),_.delete(l)}if(k.has(l)){let v=k.get(l);l.setAttribute("internals-valid",v.validity.valid.toString()),l.setAttribute("internals-invalid",(!v.validity.valid).toString()),l.setAttribute("aria-invalid",(!v.validity.valid).toString()),k.delete(l)}if(l.localName==="form"){let v=E.get(l),C=document.createTreeWalker(l,NodeFilter.SHOW_ELEMENT,{acceptNode(b){return o.has(b)&&!(v&&v.has(b))?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}}),f=C.nextNode();for(;f;)z(f),f=C.nextNode()}l.localName==="fieldset"&&(J.observe(l,B),q(l,!0))}),h.forEach(l=>{let v=o.get(l);v&&g.get(v)&&F(v),P.has(l)&&P.get(l).disconnect()})})}function s(e){e.forEach(t=>{let{removedNodes:a}=t;a.forEach(i=>{let r=U.get(t.target);o.has(i)&&it(i),r.disconnect()})})}let n=e=>{let t=new MutationObserver(s);t.observe(e,{childList:!0}),U.set(e,t)};new MutationObserver(A);let m={childList:!0,subtree:!0},p=(e,t)=>{e.toggleAttribute("internals-disabled",t),t?e.setAttribute("aria-disabled","true"):e.removeAttribute("aria-disabled"),e.formDisabledCallback&&e.formDisabledCallback.apply(e,[t])},F=e=>{g.get(e).forEach(a=>{a.remove()}),g.set(e,[])},x=(e,t)=>{let a=document.createElement("input");return a.type="hidden",a.name=e.getAttribute("name"),e.after(a),g.get(t).push(a),a},R=(e,t)=>{g.set(t,[]),J.observe(e,B)},L=(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)}},H=e=>{let t=Array.from(e.elements).filter(h=>!h.tagName.includes("-")&&h.validity).map(h=>h.validity.valid),a=E.get(e)||[],i=Array.from(a).filter(h=>h.isConnected).map(h=>o.get(h).validity.valid),r=[...t,...i].includes(!1);e.toggleAttribute("internals-invalid",r),e.toggleAttribute("internals-valid",!r)},M=e=>{H(Q(e.target))},K=e=>{H(Q(e.target))},N=e=>{let t=":is(:is(button, 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 h=E.get(e);if(e.noValidate)return;h.size&&Array.from(h).reverse().map(C=>o.get(C).reportValidity()).includes(!1)&&i.preventDefault()}})},et=e=>{let t=E.get(e.target);t&&t.size&&t.forEach(a=>{a.constructor.formAssociated&&a.formResetCallback&&a.formResetCallback.apply(a)})},G=(e,t,a)=>{if(t){let i=E.get(t);if(i)i.add(e);else{let r=new Set;r.add(e),E.set(t,r),N(t),t.addEventListener("reset",et),t.addEventListener("input",M),t.addEventListener("change",K)}S.set(t,{ref:e,internals:a}),e.constructor.formAssociated&&e.formAssociatedCallback&&setTimeout(()=>{e.formAssociatedCallback.apply(e,[t])},0),H(t)}},Q=e=>{let t=e.parentNode;return t&&t.tagName!=="FORM"&&(t=Q(t)),t},I=(e,t,a=DOMException)=>{if(!e.constructor.formAssociated)throw new a(t)},at=(e,t,a)=>{let i=E.get(e);return i&&i.size&&i.forEach(r=>{o.get(r)[a]()||(t=!1)}),t},it=e=>{if(e.constructor.formAssociated){let t=o.get(e),{labels:a,form:i}=t;L(e,a),G(e,i,t)}};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&&H(a),e),dt=e=>{let t=!0;for(let a in e)a!=="valid"&&e[a]!==!1&&(t=!1);return t},tt=new WeakMap;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");tt.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=tt.get(this);return i.toggleAttribute(`state${t}`,!0),i.part&&i.part.add(`state${t}`),a}clear(){for(let[t]of this.entries())this.delete(t);super.clear()}delete(t){let a=super.delete(t),i=tt.get(this);return 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,r){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!r)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?e!==t||!r:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?r.call(e,a):r?r.value=a:t.set(e,a),a}var j;class ut{constructor(t){j.set(this,void 0),ht(this,j,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,j,"f").length}[(j=new WeakMap,Symbol.iterator)](){return st(this,j,"f")[Symbol.iterator]()}item(t){return this[t]==null?null:this[t]}namedItem(t){return this[t]==null?null:this[t]}}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),c.set(this,i),o.set(t,this),V(t,this),R(t,this),Object.seal(this),it(t),a instanceof DocumentFragment&&n(a)}checkValidity(){let t=u.get(this);if(I(t,"Failed to execute 'checkValidity' on 'ElementInternals': The target element is not a form-associated custom element."),!this.willValidate)return!0;let a=c.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);I(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=Q(t)),a}get labels(){let t=u.get(this);I(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(I(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=$.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(I(a,"Failed to execute 'setFormValue' on 'ElementInternals': The target element is not a form-associated custom element."),F(this),t!=null&&!(t instanceof FormData)){if(a.getAttribute("name")){let i=x(a,this);i.value=t}}else t!=null&&t instanceof FormData&&Array.from(t).reverse().forEach(([i,r])=>{if(typeof r=="string"){let h=x(a,this);h.name=i,h.value=r}});Z.set(a,t)}setValidity(t,a,i){let r=u.get(this);if(I(r,"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.");$.set(this,i);let h=c.get(this),l={};for(let f in t)l[f]=t[f];Object.keys(l).length===0&<(h);let v={...h,...l};delete v.valid;let{valid:C}=ct(h,v,this.form);if(!C&&!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.");y.set(this,C?"":a),r.isConnected?(r.toggleAttribute("internals-invalid",!C),r.toggleAttribute("internals-valid",C),r.setAttribute("aria-invalid",`${!C}`)):k.set(r,this)}get shadowRoot(){let t=u.get(this),a=D.get(t);return a||null}get validationMessage(){let t=u.get(this);return I(t,"Failed to read the 'validationMessage' property from 'ElementInternals': The target element is not a form-associated custom element."),y.get(this)}get validity(){let t=u.get(this);return I(t,"Failed to read the 'validity' property from 'ElementInternals': The target element is not a form-associated custom element."),c.get(this)}get willValidate(){let t=u.get(this);return I(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(!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(!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{let t=function(...f){let b=r.apply(this,f),W=new MutationObserver(A);return D.set(this,b),window.ShadyDOM?W.observe(this,m):W.observe(b,m),P.set(this,W),b},a=function(...f){let b=l.apply(this,f);return at(this,b,"checkValidity")},i=function(...f){let b=v.apply(this,f);return at(this,b,"reportValidity")};window.ElementInternals=rt;let e=customElements.define;customElements.define=function(f,b,W){if(b.formAssociated){let Y=b.prototype.connectedCallback;b.prototype.connectedCallback=function(){O.has(this)||(O.set(this,!0),this.hasAttribute("disabled")&&p(this,!0)),Y!=null&&Y.apply(this)}}e.apply(customElements,[f,b,W])},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(o.has(this))throw new DOMException("DOMException: Failed to execute 'attachInternals' on 'HTMLElement': ElementInternals for the specified element was already attached.");return new rt(this)};let r=Element.prototype.attachShadow;Element.prototype.attachShadow=t,new MutationObserver(A).observe(document.documentElement,m);let l=HTMLFormElement.prototype.checkValidity;HTMLFormElement.prototype.checkValidity=a;let v=HTMLFormElement.prototype.reportValidity;HTMLFormElement.prototype.reportValidity=i;let{get:C}=Object.getOwnPropertyDescriptor(HTMLFormElement.prototype,"elements");Object.defineProperty(HTMLFormElement.prototype,"elements",{get(...f){let b=C.call(this,...f),W=Array.from(E.get(this)||[]);if(W.length===0)return b;let Y=Array.from(b).concat(W).sort((ot,ft)=>ot.compareDocumentPosition?ot.compareDocumentPosition(ft)&2?1:-1:0);return new ut(Y)}}),window.CustomStateSet||(window.CustomStateSet=X)}})();export{pt as a};
//# sourceMappingURL=chunk-DJOD4BTL.js.map