/* mQuery 0.7 (nightly) (8/29/2023, 6:37:52 PM), vitmalina@gmail.com */ class Query{static version=.8;constructor(e,t){this.context=t??document;let r=[];if(Array.isArray(e))r=e;else if(e instanceof Node||e instanceof Window)r=[e];else if(e instanceof Query)r=e.nodes;else if("string"==typeof e){if("function"!=typeof this.context.querySelector)throw new Error("Invalid context");r=Array.from(this.context.querySelectorAll(e))}else if(null==e)r=[];else{t=Array.from(e??[]);if("object"!=typeof e||!Array.isArray(t))throw new Error(`Invalid selector "${e}"`);r=t}this.nodes=r,this.length=r.length,this.each((e,t)=>{this[t]=e})}static _fragment(e){let r=document.createElement("template");return r.innerHTML=e,r.content.childNodes.forEach(e=>{var t=Query._scriptConvert(e);t!=e&&r.content.replaceChild(t,e)}),r.content}static _scriptConvert(e){let t=e=>{let t=e.ownerDocument,r=t.createElement("script");r.text=e.text;var s=e.attributes;for(let e=0;e{e.parentNode.replaceChild(t(e),e)}),e}static _fixProp(e){var t={cellpadding:"cellPadding",cellspacing:"cellSpacing",class:"className",colspan:"colSpan",contenteditable:"contentEditable",for:"htmlFor",frameborder:"frameBorder",maxlength:"maxLength",readonly:"readOnly",rowspan:"rowSpan",tabindex:"tabIndex",usemap:"useMap"};return t[e]||e}_insert(n,r){let i=[],a=this.length;if(!(a<1)){let e=this;if("string"==typeof r)this.each(e=>{var t=Query._fragment(r);i.push(...t.childNodes),e[n](t)});else if(r instanceof Query){let s=1==a;r.each(r=>{this.each(e=>{var t=s?r:r.cloneNode(!0);i.push(t),e[n](t),Query._scriptConvert(t)})}),s||r.remove()}else{if(!(r instanceof Node))throw new Error(`Incorrect argument for "${n}(html)". It expects one string argument.`);this.each(e=>{var t=1===a?r:Query._fragment(r.outerHTML);i.push(...1===a?[r]:t.childNodes),e[n](t)}),1{e=Array.from(e.querySelectorAll(t));0{(e===t||"string"==typeof t&&e.matches&&e.matches(t)||"function"==typeof t&&t(e))&&r.push(e)}),new Query(r,this.context)}next(){let t=[];return this.each(e=>{e=e.nextElementSibling;e&&t.push(e)}),new Query(t,this.context)}prev(){let t=[];return this.each(e=>{e=e.previousElementSibling;e&&t.push(e)}),new Query(t,this.context)}shadow(e){let t=[];this.each(e=>{e.shadowRoot&&t.push(e.shadowRoot)});let r=new Query(t,this.context);return e?r.find(e):r}closest(t){let r=[];return this.each(e=>{e=e.closest(t);e&&r.push(e)}),new Query(r,this.context)}host(t){let r=[],s=e=>e.parentNode?s(e.parentNode):e,n=e=>{e=s(e);r.push(e.host||e),e.host&&t&&n(e.host)};return this.each(e=>{n(e)}),new Query(r,this.context)}parent(e){return this.parents(e,!0)}parents(e,t){let r=[],s=e=>{if(-1==r.indexOf(e)&&r.push(e),!t&&e.parentNode)return s(e.parentNode)};this.each(e=>{e.parentNode&&s(e.parentNode)});let n=new Query(r,this.context);return e?n.filter(e):n}add(e){e=e instanceof Query?e.nodes:Array.isArray(e)?e:[e];return new Query(this.nodes.concat(e),this.context)}each(r){return this.nodes.forEach((e,t)=>{r(e,t,this)}),this}append(e){return this._insert("append",e)}prepend(e){return this._insert("prepend",e)}after(e){return this._insert("after",e)}before(e){return this._insert("before",e)}replace(e){return this._insert("replaceWith",e)}remove(){return this.each(e=>{e.remove()}),this}css(t,e){let s=t;var r=arguments.length;if(0!==r&&(1!==r||"string"!=typeof t))return"object"!=typeof t&&(s={},s[t]=e),this.each((r,e)=>{Object.keys(s).forEach(e=>{var t=String(s[e]).toLowerCase().includes("!important")?"important":"";r.style.setProperty(e,String(s[e]).replace(/\!important/i,""),t)})}),this;if(this[0]){let e=this[0].style;if("string"!=typeof t)return Object.fromEntries(this[0].style.cssText.split(";").filter(e=>!!e).map(e=>e.split(":").map(e=>e.trim())));r=e.getPropertyPriority(t);return e.getPropertyValue(t)+(r?"!"+r:"")}}addClass(e){return this.toggleClass(e,!0),this}removeClass(e){return this.toggleClass(e,!1),this}toggleClass(t,s){return"string"==typeof t&&(t=t.split(/[,\s]+/)),this.each(r=>{let e=t;null==e&&!1===s&&(e=Array.from(r.classList)),e.forEach(t=>{if(""!==t){let e=null!=s?s?"add":"remove":"toggle";r.classList[e](t)}})}),this}hasClass(e){if(null==(e="string"==typeof e?e.split(/[,\s]+/):e)&&0{r=r||e.every(e=>Array.from(t.classList??[]).includes(e))}),r}on(e,s,n){"function"==typeof s&&(n=s,s=void 0);let i;return s?.delegate&&(i=s.delegate,delete s.delegate),(e=e.split(/[,\s]+/)).forEach(e=>{let[t,r]=String(e).toLowerCase().split(".");if(i){let r=n;n=e=>{var t=query(e.target).parents(i);0{this._save(e,"events",[{event:t,scope:r,callback:n,options:s}]),e.addEventListener(t,n,s)})}),this}off(e,t,i){return"function"==typeof t&&(i=t,t=void 0),(e=(e??"").split(/[,\s]+/)).forEach(e=>{let[s,n]=String(e).toLowerCase().split(".");this.each(t=>{if(Array.isArray(t._mQuery?.events))for(let e=t._mQuery.events.length-1;0<=e;e--){var r=t._mQuery.events[e];null==n||""===n?r.event!=s&&""!==s||r.callback!=i&&null!=i||(t.removeEventListener(r.event,r.callback,r.options),t._mQuery.events.splice(e,1)):r.event!=s&&""!==s||r.scope!=n||(t.removeEventListener(r.event,r.callback,r.options),t._mQuery.events.splice(e,1))}})}),this}trigger(e,t){let r;return r=e instanceof Event||e instanceof CustomEvent?e:new(["click","dblclick","mousedown","mouseup","mousemove"].includes(e)?MouseEvent:["keydown","keyup","keypress"].includes(e)?KeyboardEvent:Event)(e,t),this.each(e=>{e.dispatchEvent(r)}),this}attr(t,r){if(void 0===r&&"string"==typeof t)return this[0]?this[0].getAttribute(t):void 0;{let e={};return"object"==typeof t?e=t:e[t]=r,this.each(r=>{Object.entries(e).forEach(([e,t])=>{r.setAttribute(e,t)})}),this}}removeAttr(){return this.each(t=>{Array.from(arguments).forEach(e=>{t.removeAttribute(e)})}),this}prop(t,r){if(void 0===r&&"string"==typeof t)return this[0]?this[0][t]:void 0;{let e={};return"object"==typeof t?e=t:e[t]=r,this.each(r=>{Object.entries(e).forEach(([e,t])=>{e=Query._fixProp(e);r[e]=t,"innerHTML"==e&&Query._scriptConvert(r)})}),this}}removeProp(){return this.each(t=>{Array.from(arguments).forEach(e=>{delete t[Query._fixProp(e)]})}),this}data(r,t){if(r instanceof Object)Object.entries(r).forEach(e=>{this.data(e[0],e[1])});else{if(r&&-1!=r.indexOf("-")&&console.error(`Key "${r}" contains "-" (dash). Dashes are not allowed in property names. Use camelCase instead.`),!(arguments.length<2))return this.each(e=>{null!=t?e.dataset[r]=t instanceof Object?JSON.stringify(t):t:delete e.dataset[r]}),this;if(this[0]){let t=Object.assign({},this[0].dataset);return Object.keys(t).forEach(e=>{if(t[e].startsWith("[")||t[e].startsWith("{"))try{t[e]=JSON.parse(t[e])}catch(e){}}),r?t[r]:t}}}removeData(e){return"string"==typeof e&&(e=e.split(/[,\s]+/)),this.each(t=>{e.forEach(e=>{delete t.dataset[e]})}),this}show(){return this.toggle(!0)}hide(){return this.toggle(!1)}toggle(i){return this.each(e=>{var t,r=e.style.display,s=getComputedStyle(e).display,n="none"==r||"none"==s;!n||null!=i&&!0!==i||(t=e instanceof HTMLTableRowElement?"table-row":e instanceof HTMLTableCellElement?"table-cell":"block",e.style.display=e._mQuery?.prevDisplay??(r==s&&"none"!=s?"":t),this._save(e,"prevDisplay",null)),n||null!=i&&!1!==i||("none"!=s&&this._save(e,"prevDisplay",s),e.style.setProperty("display","none"))})}empty(){return this.html("")}html(e){return e instanceof HTMLElement?this.empty().append(e):this.prop("innerHTML",e)}text(e){return this.prop("textContent",e)}val(e){return this.prop("value",e)}change(){return this.trigger("change")}click(){return this.trigger("click")}}let query=function(e,t){if("function"!=typeof e)return new Query(e,t);"complete"==document.readyState?e():window.addEventListener("load",e)};query.html=e=>{e=Query._fragment(e);return query(e.children,e)},query.version=Query.version;export{query as $,query as default,query,Query};