@webqit/oohtml 4.1.8 → 4.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.lite.js CHANGED
@@ -51,7 +51,7 @@ ${g}
51
51
  const abort = () => this.removeEventListener( '${u}', handler );
52
52
  this.$oohtml_internal_databinding_signals?.push( { abort } );
53
53
  `}if(s.trim())throw new Error(`Invalid binding: ${s}.`)}).join(`
54
- `),{webqit:{QuantumModule:n}}=this,o=new n(r);return Ge.set(t,o),o}var It=i=>i.replace(/"/g,'\\"');function Nr(i){let t=this,{webqit:{oohtml:{configs:{DATA_BINDING:e}}}}=t;$t(t,i,`(${e.discreteBindingsSelector})`).forEach(r=>{let n=Rr(e,r.nodeValue);Mr.call(t,e,n.expr)}),(i?.matches(e.attrSelector)?[i]:[]).concat([...i?.querySelectorAll(e.attrSelector)||[]]).forEach(r=>{jr.call(t,e,r.getAttribute(e.attr.render))})}var it=class extends B{static createRequest(t=null){let e=super.createRequest();if(t?.startsWith("@")){let[r,...n]=n.slice(1).split(".").map(o=>o.trim());e.targetContext=r,e.detail=n.join(".")}else e.detail=t;return e}get bindingsObj(){return this.host[this.configs.BINDINGS_API.api.bindings]}matchEvent(t){return super.matchEvent(t)&&(!t.detail||!this.detail||(Array.isArray(t.detail)?t.detail[0]===this.detail:t.detail===this.detail))}handle(t){if(t.meta.controller?.abort(),!(t.detail+"").trim())return t.respondWith(this.bindingsObj);let{window:{webqit:{Observer:e}}}=j;t.meta.controller=e.reduce(this.bindingsObj,Array.isArray(t.detail)?t.detail:[t.detail],e.get,r=>{this.disposed||t.respondWith(r.value)},{live:t.live,signal:t.signal,descripted:!0})}unsubscribed(t){t.meta.controller?.abort()}};H(it,"kind","bindings");function Qe(i={}){let{config:t,window:e}=V.call(this,"bindings-api",i,{attr:{bindingsreflection:"bindings"},api:{bind:"bind",bindings:"bindings"}});e.webqit.DOMBindingsContext=it,ji.call(e,t)}function kr(i,t){let e=this,{webqit:{Observer:r,oohtml:{configs:{CONTEXT_API:n}}}}=e;if(!S(t).has("bindings")){let o=Object.create(null);S(t).set("bindings",o),r.observe(o,s=>{let a=Object.keys(o),l=t instanceof e.Document?t.documentElement:t,c=i.attr.bindingsreflection;a.length&&c&&l.setAttribute?l.setAttribute(i.attr.bindingsreflection,a.join(" ")):c&&l.setAttribute&&l.toggleAttribute(i.attr.bindingsreflection,!1);let u=t[n.api.contexts];for(let d of s)if(d.type==="delete"){let f=u.find(it.kind,d.key);f&&u.detach(f)}else u.find(it.kind,d.key)||u.attach(new it(d.key))})}return S(t).get("bindings")}function ji(i){let t=this,{webqit:{Observer:e}}=t;[t.Document.prototype,t.Element.prototype,t.ShadowRoot.prototype].forEach(r=>{let n=r===t.Document.prototype?"Document":r===t.ShadowRoot.prototype?"ShadowRoot":"Element";if(i.api.bind in r)throw new Error(`The ${n} prototype already has a "${i.api.bind}" API!`);if(i.api.bindings in r)throw new Error(`The ${n} prototype already has a "${i.api.bindings}" API!`);Object.defineProperty(r,i.api.bind,{value:function(o,s={}){return Ni.call(t,i,this,o,s)}}),Object.defineProperty(r,i.api.bindings,{get:function(){return e.proxy(kr.call(t,i,this))}})})}function Ni(i,t,e,{merge:r,diff:n,namespace:o}={}){let s=this,{webqit:{Observer:a}}=s,l=kr.call(this,i,t),c={diff:n,namespace:o},u=r?[]:a.ownKeys(l,c).filter(d=>!(d in e));return a.batch(l,()=>(u.length&&a.deleteProperties(l,u,c),a.set(l,e,c)),c)}var K=class{static instance(t){return S(t).get("defsmanager::instance")||new this(t)}constructor(t,e=null,r=0){let{window:n}=j,{webqit:{realdom:o,oohtml:{configs:s}}}=n;S(t).get("defsmanager::instance")?.dispose(),S(t).set("defsmanager::instance",this),this.window=n,this.host=t,this.config=s.HTML_IMPORTS,this.parent=e,this.level=r,this.defs=nt(this.host),this.defId=(this.host.getAttribute(this.config.attr.def)||"").trim(),this.validateDefId(this.defId),this.realtimeA=o.realtime(this.host.content).children(a=>{this.expose(a.entrants,!0),this.expose(a.exits,!1)},{live:!0,timing:"sync"}),this.realtimeB=o.realtime(this.host).attr(["src","loading"],(...a)=>this.evaluateLoading(...a),{live:!0,atomic:!0,timing:"sync",lifecycleSignals:!0}),this.realtimeC=this.evalInheritance()}validateDefId(t){if(["@","/","*","#"].some(e=>t.includes(e)))throw new Error(`The export ID "${t}" contains an invalid character.`)}expose(t,e){let{window:r}=j,{webqit:{Observer:n}}=r,o,s=this.defs["#"]||[];n.batch(this.defs,()=>{t.forEach(a=>{if(a.nodeType!==1)return;let l=a.matches(this.config.templateSelector),c=(a.getAttribute(l?this.config.attr.def:this.config.attr.fragmentdef)||"").trim();e?(l&&c?new K(a,this.host,this.level+1):(s.push(a),o=!0,typeof requestIdleCallback=="function"&&requestIdleCallback(()=>{this.config.idleCompilers?.forEach(u=>u.call(this.window,a))})),c&&(this.validateDefId(c),n.set(this.defs,(!l&&"#"||"")+c,a))):(l&&c?K.instance(a).dispose():(s=s.filter(u=>u!==a),o=!0),c&&n.deleteProperty(this.defs,(!l&&"#"||"")+c))}),o&&n.set(this.defs,"#",s)})}evaluateLoading([t,e],{signal:r}){let{window:{webqit:{Observer:n}}}=j,o=(t.value||"").trim();if(!o)return;let s,a=u=>{if(!u)return s;s=u.then(()=>c.remove())},l=(e.value||"").trim(),c=n.intercept(this.defs,"get",async(u,d,f)=>(l==="lazy"&&a(this.load(o,!0)),await a(),f()),{signal:r});l!=="lazy"&&a(this.load(o))}load(t){let{window:e}=j;if(this.host.content.children.length)return Promise.resolve();if(this.fetchInFlight?.src===t)return this.fetchInFlight.request;this.fetchInFlight?.controller.abort();let r=new AbortController,n=(s,a)=>this.host.dispatchEvent(new e.CustomEvent(s,{detail:a})),o=e.fetch(t,{signal:r.signal,element:this.host}).then(s=>s.ok?s.text():Promise.reject(s.statusText)).then(s=>(this.host.innerHTML=s.trim(),n("load"),this.host)).catch(s=>(console.error(`Error fetching the bundle at "${t}": ${s.message}`),this.fetchInFlight=null,n("loaderror"),this.host));return this.fetchInFlight={src:t,request:o,controller:r},o}evalInheritance(){if(!this.parent)return[];let{window:{webqit:{Observer:t}}}=j,e=(this.host.getAttribute(this.config.attr.extends)||"").trim(),r=(this.host.getAttribute(this.config.attr.inherits)||"").trim(),n=a=>{a.forEach(l=>{t.get(this.defs,l.key)===l.oldValue&&(["get","set","def"].includes(l.type)?t[l.type.replace("get","set")](this.defs,l.key,l.value):l.type==="delete"&&t.deleteProperty(this.defs,l.key))})},o=[],s=nt(this.parent);return e&&o.push(t.reduce(s,[e,this.config.api.defs,1/0],t.get,n,{live:!0})),(r=r.split(" ").map(a=>a.trim()).filter(a=>a)).length&&o.push(t.get(s,r,n,{live:!0})),o}dispose(){this.realtimeA.disconnect(),this.realtimeB.disconnect(),this.realtimeC.forEach(t=>t instanceof Promise?t.then(e=>e.abort()):t.abort()),Object.entries(this.defs).forEach(([t,e])=>{t.startsWith("#")||K.instance(e).dispose()})}};var ot=class extends B{static createRequest(t=null){let e=super.createRequest();if(t?.startsWith("/"))e.detail=t,e.targetContext=1/0;else if(t?.startsWith("@")){let[r,...n]=n.slice(1).split(/(?<=\w)(?=\/|#)/).map(o=>o.trim());e.targetContext=r,e.detail=n.join("")}else e.detail=t;return e}get localModules(){return nt(this.host)}handle(t){let{window:{webqit:{Observer:e}}}=j;if(t.meta.controller?.abort(),(t.detail||"").trim()==="/")return t.respondWith(this.localModules);let r=(t.detail||"").split(/\/|(?<=\w)(?=#)/g).map(o=>o.trim()).filter(o=>o);if(!r.length)return t.respondWith();r=r.join(`/${this.configs.HTML_IMPORTS.api.defs}/`)?.split("/")||[];let n={live:t.live,signal:t.signal,descripted:!0};t.meta.controller=e.reduce(this.localModules,r,e.get,(o,{signal:s}={})=>{let a=Array.isArray(o)?o:o.value,l=Array.isArray(o)?o.length:o.value;if(!(!l&&this.host.isConnected===!1))return l||!this.contextModules?(t._isValidLocalResult=l,t.respondWith(a)):e.reduce(this.contextModules,r,e.get,c=>(t._currentSource="context",t.respondWith(Array.isArray(c)?c:c.value)),{...n,signal:s})},{lifecycleSignals:!0,...n})}unsubscribed(t){t.meta.controller?.abort()}realtimeSources(t){this.host=t;let e=()=>{for(let o of this.subscriptions)o._isValidLocalResult||this.handle(o)},r=this.configs.HTML_IMPORTS;if(!this.host.matches||!r.attr.importscontext)return;this.refdSourceController?.disconnect();let n=this.host.ownerDocument.defaultView.webqit.realdom;this.refdSourceController=n.realtime(this.host).attr(r.attr.importscontext,(o,{signal:s})=>{if(!o.value)return this.contextModules=void 0,e();let a={...this.constructor.createRequest(o.value.trim()),live:!0,signal:s};this.host.parentNode[this.configs.CONTEXT_API.api.contexts].request(a,l=>{this.contextModules=l&&Object.getPrototypeOf(l)?nt(l):l,e()})},{live:!0,timing:"sync",lifecycleSignals:!0})}initialize(t){return this.realtimeSources(t),super.initialize(t)}dispose(t){return this.refdSourceController?.disconnect(),super.dispose(t)}};H(ot,"kind","html-imports");function Dr(){let{window:i}=j,{webqit:t}=i,{realdom:e,oohtml:{configs:r}}=t;if(t.HTMLImportElement)return t.HTMLImportElement;let n=r.HTML_IMPORTS.elements.import.includes("-")?i.HTMLElement:class{};class o extends n{static instance(a){return r.HTML_IMPORTS.elements.import.includes("-")&&a instanceof this?a:S(a).get("import::instance")||new this(a)}constructor(...a){super();let l=a[0]||this;S(l).set("import::instance",this),Object.defineProperty(this,"el",{get:()=>l,configurable:!1});let c={};Object.defineProperty(this,"#",{get:()=>c,configurable:!1}),c.slottedElements=new Set,c.setAnchorNode=u=>(c.anchorNode=u,u),c.importRequest=(u,d=null)=>{let f={...ot.createRequest(c.moduleRef?.includes("#")?c.moduleRef:`${c.moduleRef}#`),live:d&&!0,signal:d};(this.el.isConnected?this.el.parentNode:c.anchorNode.parentNode)[r.CONTEXT_API.api.contexts].request(f,p=>{u((p instanceof i.HTMLTemplateElement?[...p.content.children]:Array.isArray(p)?p:p&&[p])||[])})},c.hydrate=(u,d)=>{c.moduleRef=(this.el.getAttribute(r.HTML_IMPORTS.attr.ref)||"").trim(),u.replaceWith(c.setAnchorNode(this.createAnchorNode())),c.autoRestore(()=>{d.forEach(f=>{c.slottedElements.add(f),S(f).set("slot@imports",this.el)})}),c.hydrationImportRequest=new AbortController,c.importRequest(f=>{if(c.originalsRemapped)return this.fill(f);let p=f.map((y,v)=>({el:y,fragmentDef:y.getAttribute(r.HTML_IMPORTS.attr.fragmentdef)||"",tagName:y.tagName,i:v})),g=-1;d.forEach(y=>{let v=y.tagName,h=y.getAttribute(r.HTML_IMPORTS.attr.fragmentdef)||"",w=(g++,p.find(O=>O.tagName===v&&O.fragmentDef===h&&O.i===g));!w||S(y).set("original@imports",w.el)}),c.originalsRemapped=!0},c.hydrationImportRequest.signal)},c.autoRestore=(u=null)=>{c.autoRestoreRealtime?.disconnect(),u&&u();let d=()=>{c.anchorNode?.replaceWith(this.el),c.anchorNode=null,this.el.setAttribute("data-nodecount",0)};if(!c.slottedElements.size)return d();let f=e.realtime(i.document).observe([...c.slottedElements],p=>{if(p.exits.forEach(g=>{S(g).delete("slot@imports"),c.slottedElements.delete(g)}),!c.slottedElements.size){if(f.disconnect(),!p.target.isConnected)return;d()}},{subtree:"cross-roots",timing:"sync",generation:"exits"});c.autoRestoreRealtime=f},c.connectedCallback=()=>{if(c.slottedElements.size)throw new Error("Illegal reinsertion into the DOM; import slot is not empty!");c.moduleRefRealtime||(c.moduleRefRealtime=e.realtime(this.el).attr(r.HTML_IMPORTS.attr.ref,(u,{signal:d})=>{c.moduleRef=u.value,c.importRequest(f=>!c.hydrationImportRequest&&this.fill(f),d)},{live:!0,timing:"sync",lifecycleSignals:!0}),c.hydrationImportRequest?.abort(),c.hydrationImportRequest=null)},c.disconnectedCallback=()=>{c.hydrationImportRequest?.abort(),c.hydrationImportRequest=null,!c.anchorNode.isConnected&&(c.moduleRefRealtime?.disconnect(),c.moduleRefRealtime=null)}}createAnchorNode(){if(i.webqit.env!=="server")return i.document.createTextNode("");let a=i.document.createElement("div");a.textContent=this.el.outerHTML;let l=i.document.createComment(a.innerHTML);return S(l).set("isAnchorNode",!0),l}fill(a){Array.isArray(a)&&(a=new Set(a)),this.el.setAttribute("data-nodecount",a.size),this["#"].autoRestore(()=>{if(this["#"].slottedElements.forEach(l=>{let c=S(l).get("original@imports");a.has(c)?a.delete(c):(this["#"].slottedElements.delete(l),l.remove())}),a.size){let l=this["#"].anchorNode,c=this["#"].setAnchorNode(this.createAnchorNode());(this.el.isConnected?this.el:l).replaceWith(c)}a.forEach(l=>{let c=l.cloneNode(!0);c.hasAttribute(r.HTML_IMPORTS.attr.fragmentdef)||c.toggleAttribute(r.HTML_IMPORTS.attr.fragmentdef,!0),S(c).set("original@imports",l),S(c).set("slot@imports",this.el),this["#"].slottedElements.add(c),this["#"].anchorNode.before(c)})})}empty(){this["#"].slottedElements.forEach(a=>a.remove())}get anchorNode(){return this["#"].anchorNode}get moduleRef(){return this["#"].moduleRef}get slottedElements(){return this["#"].slottedElements}}return r.HTML_IMPORTS.elements.import.includes("-")&&customElements.define(r.HTML_IMPORTS.elements.import,o),t.HTMLImportElement=o,o}function Je(i={}){let{config:t,window:e}=V.call(this,"html-imports",i,{elements:{import:"import"},attr:{def:"def",extends:"extends",inherits:"inherits",ref:"ref",importscontext:"importscontext"},api:{def:"def",defs:"defs",import:"import"}});t.attr.fragmentdef||(t.attr.fragmentdef=t.attr.def),t.templateSelector=`template[${e.CSS.escape(t.attr.def)}]`,t.importsContextSelector=`[${e.CSS.escape(t.attr.importscontext)}]`,t.slottedElementsSelector=`[${e.CSS.escape(t.attr.fragmentdef)}]:not(template)`;let r=(n,o)=>{let s=`starts-with(., "${n}")`,a=`substring(., string-length(.) - string-length("${o}") + 1) = "${o}"`;return`${s} and ${a}`};t.anchorNodeSelector=`comment()[${r(`&lt;${t.elements.import}`,`&lt;/${t.elements.import}&gt;`)}]`,e.webqit.HTMLImportsContext=ot,e.webqit.HTMLImportElement=Dr(),ki.call(e,t),Di.call(e,t)}function nt(i,t=!0){if(!S(i).has("defs")&&t){let e=Object.create(null);S(i).set("defs",e)}return S(i).get("defs")}function ki(i){let t=this,{webqit:{oohtml:{configs:e}}}=t;if(i.api.def in t.HTMLTemplateElement.prototype)throw new Error(`The "HTMLTemplateElement" prototype already has a "${i.api.def}" API!`);if(i.api.defs in t.HTMLTemplateElement.prototype)throw new Error(`The "HTMLTemplateElement" prototype already has a "${i.api.defs}" API!`);Object.defineProperty(t.HTMLTemplateElement.prototype,i.api.def,{get:function(){return this.getAttribute(i.attr.def)}}),Object.defineProperty(t.HTMLTemplateElement.prototype,i.api.defs,{get:function(){return nt(this)}}),Object.defineProperty(t.HTMLTemplateElement.prototype,"scoped",{configurable:!0,get(){return this.hasAttribute("scoped")},set(n){this.toggleAttribute("scoped",n)}}),[t.Document.prototype,t.Element.prototype,t.ShadowRoot.prototype].forEach(n=>{let o=n===t.Document.prototype?"Document":n===t.ShadowRoot.prototype?"ShadowRoot":"Element";if(i.api.import in n)throw new Error(`The ${o} prototype already has a "${i.api.import}" API!`);Object.defineProperty(n,i.api.import,{value:function(s,a=!1,l=null){return r(this,...arguments)}})});function r(n,o,s=!1,a=null){let l={};typeof s=="function"?(a=s,s=!1):typeof s=="object"&&s?l={...s,...l}:l={live:s};let c={...ot.createRequest(o),...l};return n[e.CONTEXT_API.api.contexts].request(c,a)}}function Di(i){let t=this,{webqit:{Observer:e,realdom:r,oohtml:{configs:n},HTMLImportElement:o,HTMLImportsContext:s}}=t,a=u=>{let d=u[n.CONTEXT_API.api.contexts];d.find(s.kind)||d.attach(new s)},l=u=>{let d=u[n.CONTEXT_API.api.contexts],f=d.find(s.kind);f&&(!u.isConnected||!u.matches?.(i.importsContextSelector)&&!Object.keys(f.localModules).length)&&d.detach(f)};r.realtime(t.document).query([i.templateSelector,i.importsContextSelector],u=>{u.entrants.forEach(d=>{if(d.matches(i.templateSelector)){let f=K.instance(d);f.ownerContext=d.scoped?d.parentNode:d.getRootNode();let p=nt(f.ownerContext);f.defId&&e.set(p,f.defId,d),a(f.ownerContext)}else a(d)}),u.exits.forEach(d=>{if(d.matches(i.templateSelector)){let f=K.instance(d),p=nt(f.ownerContext);f.defId&&f.ownerContext.isConnected&&e.deleteProperty(p,f.defId),l(f.ownerContext)}else l(d)})},{live:!0,subtree:"cross-roots",timing:"sync",staticSensitivity:!0,eventDetails:!0}),r.realtime(t.document).query(i.elements.import,u=>{u.entrants.forEach(d=>c(d,!0,u)),u.exits.forEach(d=>c(d,!1,u))},{live:!0,subtree:"cross-roots",timing:"sync"});function c(u,d){let f=o.instance(u);d?f["#"].connectedCallback():f["#"].disconnectedCallback()}t.webqit.env!=="server"&&r.realtime(t.document).query(`(${i.anchorNodeSelector})`,u=>{u.entrants.forEach(d=>{if(S(d).get("isAnchorNode"))return;let f=t.document.createElement("div");f.innerHTML=d.nodeValue,f.innerHTML=f.firstChild.textContent;let p=f.firstChild,g=parseInt(p.getAttribute("data-nodecount")),y=new Set,v=d;for(;(v=v.previousElementSibling)&&v.matches(i.slottedElementsSelector)&&g--;)y.add(v);o.instance(p)["#"].hydrate(d,y)})},{live:!0,subtree:"cross-roots",timing:"sync"})}function Ye(i={}){let{config:t,window:e}=V.call(this,"context-api",i,{attr:{contextname:"contextname"},api:{contexts:"contexts"}});e.webqit.DOMContexts=ct,e.webqit.DOMContext=B,e.webqit.DOMContextRequestEvent=de(),e.webqit.DOMContextResponse=wt,e.webqit.DuplicateContextError=xt,Li.call(e,t)}function Li(i){let t=this;[t.Document.prototype,t.Element.prototype,t.ShadowRoot.prototype].forEach(e=>{let r=e===t.Document.prototype?"Document":e===t.ShadowRoot.prototype?"ShadowRoot":"Element";if(i.api.contexts in e)throw new Error(`The ${r} prototype already has a "${i.api.contexts}" API!`);Object.defineProperty(e,i.api.contexts,{get:function(){return ct.instance(this)}})})}function Ke({advanced:i={},...t}){let{config:e,window:r}=V.call(this,"scoped-css",t,{api:{styleSheets:"styleSheets"},style:{retention:"retain",mimeTypes:"text/css",strategy:null}});e.styleSelector=(Array.isArray(e.style.mimeTypes)?e.style.mimeTypes:e.style.mimeTypes.split("|")).concat("").reduce((n,o)=>{let s=o?`[type="${r.CSS.escape(o)}"]`:":not([type])";return n.concat(`style${s}`)},[]).join(","),r.webqit.oohtml.Style={compileCache:new Map},Hi.call(r,e),Fi.call(r,e)}function Hi(i){let t=this,e=new Map;[t.Element.prototype].forEach(r=>{let n="Element";if(i.api.styleSheets in r)throw new Error(`The ${n} prototype already has a "${i.api.styleSheets}" API!`);Object.defineProperty(r,i.api.styleSheets,{get:function(){return e.has(this)||e.set(this,[]),e.get(this)}})}),Object.defineProperty(t.HTMLStyleElement.prototype,"scoped",{configurable:!0,get(){return this.hasAttribute("scoped")},set(r){this.toggleAttribute("scoped",r)}})}function Fi(i){let t=this,{webqit:{oohtml:e,realdom:r}}=t,n=Object.getOwnPropertyDescriptor(globalThis,"window")?.get?.toString().includes("[native code]")??!1;t.CSS.supports||(t.CSS.supports=()=>!1);let o=new WeakSet;r.realtime(t.document).query(i.styleSelector,s=>{s.entrants.forEach(a=>{if(o.has(a))return;o.add(a);let l=bt(a.textContent),c=CSS.supports("selector(:has(a,b))"),u=a.scoped&&(c?`:has(> style[rand-${l}])`:`[rand-${l}]`),d=a.scoped&&t.CSSScopeRule&&!1,f=a.scoped&&a.parentNode||a.getRootNode();if(f instanceof t.Element){if(f[i.api.styleSheets].push(a),!n)return;(c?a:f).toggleAttribute(`rand-${l}`,!0)}if(!!n)if(a.scoped&&a.hasAttribute("shared")){let p;(p=e.Style.compileCache.get(l))||(p=Wi.call(t,a,null,d,u),e.Style.compileCache.set(l,p)),Object.defineProperty(a,"sheet",{value:p,configurable:!0}),a.textContent=`
54
+ `),{webqit:{QuantumModule:n}}=this,o=new n(r);return Ge.set(t,o),o}var It=i=>i.replace(/"/g,'\\"');function Nr(i){let t=this,{webqit:{oohtml:{configs:{DATA_BINDING:e}}}}=t;$t(t,i,`(${e.discreteBindingsSelector})`).forEach(r=>{let n=Rr(e,r.nodeValue);Mr.call(t,e,n.expr)}),(i?.matches(e.attrSelector)?[i]:[]).concat([...i?.querySelectorAll(e.attrSelector)||[]]).forEach(r=>{jr.call(t,e,r.getAttribute(e.attr.render))})}var it=class extends B{static createRequest(t=null){let e=super.createRequest();if(t?.startsWith("@")){let[r,...n]=n.slice(1).split(".").map(o=>o.trim());e.targetContext=r,e.detail=n.join(".")}else e.detail=t;return e}get bindingsObj(){return this.host[this.configs.BINDINGS_API.api.bindings]}matchEvent(t){return super.matchEvent(t)&&(!t.detail||!this.detail||(Array.isArray(t.detail)?t.detail[0]===this.detail:t.detail===this.detail))}handle(t){if(t.meta.controller?.abort(),!(t.detail+"").trim())return t.respondWith(this.bindingsObj);let{window:{webqit:{Observer:e}}}=j;t.meta.controller=e.reduce(this.bindingsObj,Array.isArray(t.detail)?t.detail:[t.detail],e.get,r=>{this.disposed||t.respondWith(r.value)},{live:t.live,signal:t.signal,descripted:!0})}unsubscribed(t){t.meta.controller?.abort()}};H(it,"kind","bindings");function Qe(i={}){let{config:t,window:e}=V.call(this,"bindings-api",i,{attr:{bindingsreflection:"bindings"},api:{bind:"bind",bindings:"bindings"}});e.webqit.DOMBindingsContext=it,ji.call(e,t)}function kr(i,t){let e=this,{webqit:{Observer:r,oohtml:{configs:{CONTEXT_API:n}}}}=e;if(!S(t).has("bindings")){let o=Object.create(null);S(t).set("bindings",o),r.observe(o,s=>{let a=Object.keys(o),l=t instanceof e.Document?t.documentElement:t,c=i.attr.bindingsreflection;a.length&&c&&l.setAttribute?l.setAttribute(i.attr.bindingsreflection,a.join(" ")):c&&l.setAttribute&&l.toggleAttribute(i.attr.bindingsreflection,!1);let u=t[n.api.contexts];for(let d of s)if(d.type==="delete"){let f=u.find(it.kind,d.key);f&&u.detach(f)}else u.find(it.kind,d.key)||u.attach(new it(d.key))})}return S(t).get("bindings")}function ji(i){let t=this,{webqit:{Observer:e}}=t;[t.Document.prototype,t.Element.prototype,t.ShadowRoot.prototype].forEach(r=>{let n=r===t.Document.prototype?"Document":r===t.ShadowRoot.prototype?"ShadowRoot":"Element";if(i.api.bind in r)throw new Error(`The ${n} prototype already has a "${i.api.bind}" API!`);if(i.api.bindings in r)throw new Error(`The ${n} prototype already has a "${i.api.bindings}" API!`);Object.defineProperty(r,i.api.bind,{value:function(o,s={}){return Ni.call(t,i,this,o,s)}}),Object.defineProperty(r,i.api.bindings,{get:function(){return e.proxy(kr.call(t,i,this))}})})}function Ni(i,t,e,{merge:r,diff:n,namespace:o}={}){let s=this,{webqit:{Observer:a}}=s,l=kr.call(this,i,t),c={diff:n,namespace:o},u=r?[]:a.ownKeys(l,c).filter(d=>!(d in e));return a.batch(l,()=>(u.length&&a.deleteProperties(l,u,c),a.set(l,e,c)),c)}var K=class{static instance(t){return S(t).get("defsmanager::instance")||new this(t)}constructor(t,e=null,r=0){let{window:n}=j,{webqit:{realdom:o,oohtml:{configs:s}}}=n;S(t).get("defsmanager::instance")?.dispose(),S(t).set("defsmanager::instance",this),this.window=n,this.host=t,this.config=s.HTML_IMPORTS,this.parent=e,this.level=r,this.defs=nt(this.host),this.defId=(this.host.getAttribute(this.config.attr.def)||"").trim(),this.validateDefId(this.defId),this.realtimeA=o.realtime(this.host.content).children(a=>{this.expose(a.entrants,!0),this.expose(a.exits,!1)},{live:!0,timing:"sync"}),this.realtimeB=o.realtime(this.host).attr(["src","loading"],(...a)=>this.evaluateLoading(...a),{live:!0,atomic:!0,timing:"sync",lifecycleSignals:!0}),this.realtimeC=this.evalInheritance()}validateDefId(t){if(["@","/","*","#"].some(e=>t.includes(e)))throw new Error(`The export ID "${t}" contains an invalid character.`)}expose(t,e){let{window:r}=j,{webqit:{Observer:n}}=r,o,s=this.defs["#"]||[];n.batch(this.defs,()=>{t.forEach(a=>{if(a.nodeType!==1)return;let l=a.matches(this.config.templateSelector),c=(a.getAttribute(l?this.config.attr.def:this.config.attr.fragmentdef)||"").trim();e?(l&&c?new K(a,this.host,this.level+1):(s.push(a),o=!0,typeof requestIdleCallback=="function"&&requestIdleCallback(()=>{this.config.idleCompilers?.forEach(u=>u.call(this.window,a))})),c&&(this.validateDefId(c),n.set(this.defs,(!l&&"#"||"")+c,a))):(l&&c?K.instance(a).dispose():(s=s.filter(u=>u!==a),o=!0),c&&n.deleteProperty(this.defs,(!l&&"#"||"")+c))}),o&&n.set(this.defs,"#",s)})}evaluateLoading([t,e],{signal:r}){let{window:{webqit:{Observer:n}}}=j,o=(t.value||"").trim();if(!o)return;let s,a=u=>{if(!u)return s;s=u.then(()=>c.remove())},l=(e.value||"").trim(),c=n.intercept(this.defs,"get",async(u,d,f)=>(l==="lazy"&&a(this.load(o,!0)),await a(),f()),{signal:r});l!=="lazy"&&a(this.load(o))}load(t){let{window:e}=j;if(this.host.content.children.length)return Promise.resolve();if(this.fetchInFlight?.src===t)return this.fetchInFlight.request;this.fetchInFlight?.controller.abort();let r=new AbortController,n=(s,a)=>this.host.dispatchEvent(new e.CustomEvent(s,{detail:a})),o=e.fetch(t,{signal:r.signal,element:this.host}).then(s=>s.ok?s.text():Promise.reject(s.statusText)).then(s=>(this.host.innerHTML=s.trim(),n("load"),this.host)).catch(s=>(console.error(`Error fetching the bundle at "${t}": ${s.message}`),this.fetchInFlight=null,n("loaderror"),this.host));return this.fetchInFlight={src:t,request:o,controller:r},o}evalInheritance(){if(!this.parent)return[];let{window:{webqit:{Observer:t}}}=j,e=(this.host.getAttribute(this.config.attr.extends)||"").trim(),r=(this.host.getAttribute(this.config.attr.inherits)||"").trim(),n=a=>{a.forEach(l=>{t.get(this.defs,l.key)===l.oldValue&&(["get","set","def"].includes(l.type)?t[l.type.replace("get","set")](this.defs,l.key,l.value):l.type==="delete"&&t.deleteProperty(this.defs,l.key))})},o=[],s=nt(this.parent);return e&&o.push(t.reduce(s,[e,this.config.api.defs,1/0],t.get,n,{live:!0})),(r=r.split(" ").map(a=>a.trim()).filter(a=>a)).length&&o.push(t.get(s,r,n,{live:!0})),o}dispose(){this.realtimeA.disconnect(),this.realtimeB.disconnect(),this.realtimeC.forEach(t=>t instanceof Promise?t.then(e=>e.abort()):t.abort()),Object.entries(this.defs).forEach(([t,e])=>{t.startsWith("#")||K.instance(e).dispose()})}};var ot=class extends B{static createRequest(t=null){let e=super.createRequest();if(t?.startsWith("/"))e.detail=t,e.targetContext=1/0;else if(t?.startsWith("@")){let[r,...n]=n.slice(1).split(/(?<=\w)(?=\/|#)/).map(o=>o.trim());e.targetContext=r,e.detail=n.join("")}else e.detail=t;return e}get localModules(){return nt(this.host)}handle(t){let{window:{webqit:{Observer:e}}}=j;if(t.meta.controller?.abort(),(t.detail||"").trim()==="/")return t.respondWith(this.localModules);let r=(t.detail||"").split(/\/|(?<=\w)(?=#)/g).map(o=>o.trim()).filter(o=>o);if(!r.length)return t.respondWith();r=r.join(`/${this.configs.HTML_IMPORTS.api.defs}/`)?.split("/")||[];let n={live:t.live,signal:t.signal,descripted:!0};t.meta.controller=e.reduce(this.localModules,r,e.get,(o,{signal:s}={})=>{let a=Array.isArray(o)?o:o.value,l=Array.isArray(o)?o.length:o.value;if(!(!l&&this.host.isConnected===!1))return l||!this.contextModules?(t._isValidLocalResult=l,t.respondWith(a)):e.reduce(this.contextModules,r,e.get,c=>(t._currentSource="context",t.respondWith(Array.isArray(c)?c:c.value)),{...n,signal:s})},{lifecycleSignals:!0,...n})}unsubscribed(t){t.meta.controller?.abort()}realtimeSources(t){this.host=t;let e=()=>{for(let o of this.subscriptions)o._isValidLocalResult||this.handle(o)},r=this.configs.HTML_IMPORTS;if(!this.host.matches||!r.attr.importscontext)return;this.refdSourceController?.disconnect();let n=this.host.ownerDocument.defaultView.webqit.realdom;this.refdSourceController=n.realtime(this.host).attr(r.attr.importscontext,(o,{signal:s})=>{if(!o.value)return this.contextModules=void 0,e();let a={...this.constructor.createRequest(o.value.trim()),live:!0,signal:s};this.host.parentNode[this.configs.CONTEXT_API.api.contexts].request(a,l=>{this.contextModules=l&&Object.getPrototypeOf(l)?nt(l):l,e()})},{live:!0,timing:"sync",lifecycleSignals:!0})}initialize(t){return this.realtimeSources(t),super.initialize(t)}dispose(t){return this.refdSourceController?.disconnect(),super.dispose(t)}};H(ot,"kind","html-imports");function Dr(){let{window:i}=j,{webqit:t}=i,{realdom:e,oohtml:{configs:r}}=t;if(t.HTMLImportElement)return t.HTMLImportElement;let n=r.HTML_IMPORTS.elements.import.includes("-")?i.HTMLElement:class{};class o extends n{static instance(a){return r.HTML_IMPORTS.elements.import.includes("-")&&a instanceof this?a:S(a).get("import::instance")||new this(a)}constructor(...a){super();let l=a[0]||this;S(l).set("import::instance",this),Object.defineProperty(this,"el",{get:()=>l,configurable:!1});let c={};Object.defineProperty(this,"#",{get:()=>c,configurable:!1}),c.slottedElements=new Set,c.setAnchorNode=u=>(c.anchorNode=u,u),c.importRequest=(u,d=null)=>{let f={...ot.createRequest(c.moduleRef?.includes("#")?c.moduleRef:`${c.moduleRef}#`),live:d&&!0,signal:d};(this.el.isConnected?this.el.parentNode:c.anchorNode.parentNode)[r.CONTEXT_API.api.contexts].request(f,p=>{u((p instanceof i.HTMLTemplateElement?[...p.content.children]:Array.isArray(p)?p:p&&[p])||[])})},c.hydrate=(u,d)=>{c.moduleRef=(this.el.getAttribute(r.HTML_IMPORTS.attr.ref)||"").trim(),u.replaceWith(c.setAnchorNode(this.createAnchorNode())),c.autoRestore(()=>{d.forEach(f=>{c.slottedElements.add(f),S(f).set("slot@imports",this.el)})}),c.hydrationImportRequest=new AbortController,c.importRequest(f=>{if(c.originalsRemapped)return this.fill(f);let p=f.map((y,v)=>({el:y,fragmentDef:y.getAttribute(r.HTML_IMPORTS.attr.fragmentdef)||"",tagName:y.tagName,i:v})),g=-1;d.forEach(y=>{let v=y.tagName,h=y.getAttribute(r.HTML_IMPORTS.attr.fragmentdef)||"",w=(g++,p.find(O=>O.tagName===v&&O.fragmentDef===h&&O.i===g));!w||S(y).set("original@imports",w.el)}),c.originalsRemapped=!0},c.hydrationImportRequest.signal)},c.autoRestore=(u=null)=>{c.autoRestoreRealtime?.disconnect(),u&&u();let d=()=>{c.anchorNode?.replaceWith(this.el),c.anchorNode=null,this.el.setAttribute("data-nodecount",0)};if(!c.slottedElements.size)return d();let f=e.realtime(i.document).observe([...c.slottedElements],p=>{if(p.exits.forEach(g=>{S(g).delete("slot@imports"),c.slottedElements.delete(g)}),!c.slottedElements.size){if(f.disconnect(),!p.target.isConnected)return;d()}},{subtree:"cross-roots",timing:"sync",generation:"exits"});c.autoRestoreRealtime=f},c.connectedCallback=()=>{if(c.slottedElements.size)throw new Error("Illegal reinsertion into the DOM; import slot is not empty!");c.moduleRefRealtime||(c.moduleRefRealtime=e.realtime(this.el).attr(r.HTML_IMPORTS.attr.ref,(u,{signal:d})=>{c.moduleRef=u.value,c.importRequest(f=>!c.hydrationImportRequest&&this.fill(f),d)},{live:!0,timing:"sync",lifecycleSignals:!0}),c.hydrationImportRequest?.abort(),c.hydrationImportRequest=null)},c.disconnectedCallback=()=>{c.hydrationImportRequest?.abort(),c.hydrationImportRequest=null,!c.anchorNode?.isConnected&&(c.moduleRefRealtime?.disconnect(),c.moduleRefRealtime=null)}}createAnchorNode(){if(i.webqit.env!=="server")return i.document.createTextNode("");let a=i.document.createElement("div");a.textContent=this.el.outerHTML;let l=i.document.createComment(a.innerHTML);return S(l).set("isAnchorNode",!0),l}fill(a){Array.isArray(a)&&(a=new Set(a)),this.el.setAttribute("data-nodecount",a.size),this["#"].autoRestore(()=>{if(this["#"].slottedElements.forEach(l=>{let c=S(l).get("original@imports");a.has(c)?a.delete(c):(this["#"].slottedElements.delete(l),l.remove())}),a.size){let l=this["#"].anchorNode,c=this["#"].setAnchorNode(this.createAnchorNode());(this.el.isConnected?this.el:l).replaceWith(c)}a.forEach(l=>{let c=l.cloneNode(!0);c.hasAttribute(r.HTML_IMPORTS.attr.fragmentdef)||c.toggleAttribute(r.HTML_IMPORTS.attr.fragmentdef,!0),S(c).set("original@imports",l),S(c).set("slot@imports",this.el),this["#"].slottedElements.add(c),this["#"].anchorNode.before(c)})})}empty(){this["#"].slottedElements.forEach(a=>a.remove())}get anchorNode(){return this["#"].anchorNode}get moduleRef(){return this["#"].moduleRef}get slottedElements(){return this["#"].slottedElements}}return r.HTML_IMPORTS.elements.import.includes("-")&&customElements.define(r.HTML_IMPORTS.elements.import,o),t.HTMLImportElement=o,o}function Je(i={}){let{config:t,window:e}=V.call(this,"html-imports",i,{elements:{import:"import"},attr:{def:"def",extends:"extends",inherits:"inherits",ref:"ref",importscontext:"importscontext"},api:{def:"def",defs:"defs",import:"import"}});t.attr.fragmentdef||(t.attr.fragmentdef=t.attr.def),t.templateSelector=`template[${e.CSS.escape(t.attr.def)}]`,t.importsContextSelector=`[${e.CSS.escape(t.attr.importscontext)}]`,t.slottedElementsSelector=`[${e.CSS.escape(t.attr.fragmentdef)}]:not(template)`;let r=(n,o)=>{let s=`starts-with(., "${n}")`,a=`substring(., string-length(.) - string-length("${o}") + 1) = "${o}"`;return`${s} and ${a}`};t.anchorNodeSelector=`comment()[${r(`&lt;${t.elements.import}`,`&lt;/${t.elements.import}&gt;`)}]`,e.webqit.HTMLImportsContext=ot,e.webqit.HTMLImportElement=Dr(),ki.call(e,t),Di.call(e,t)}function nt(i,t=!0){if(!S(i).has("defs")&&t){let e=Object.create(null);S(i).set("defs",e)}return S(i).get("defs")}function ki(i){let t=this,{webqit:{oohtml:{configs:e}}}=t;if(i.api.def in t.HTMLTemplateElement.prototype)throw new Error(`The "HTMLTemplateElement" prototype already has a "${i.api.def}" API!`);if(i.api.defs in t.HTMLTemplateElement.prototype)throw new Error(`The "HTMLTemplateElement" prototype already has a "${i.api.defs}" API!`);Object.defineProperty(t.HTMLTemplateElement.prototype,i.api.def,{get:function(){return this.getAttribute(i.attr.def)}}),Object.defineProperty(t.HTMLTemplateElement.prototype,i.api.defs,{get:function(){return nt(this)}}),Object.defineProperty(t.HTMLTemplateElement.prototype,"scoped",{configurable:!0,get(){return this.hasAttribute("scoped")},set(n){this.toggleAttribute("scoped",n)}}),[t.Document.prototype,t.Element.prototype,t.ShadowRoot.prototype].forEach(n=>{let o=n===t.Document.prototype?"Document":n===t.ShadowRoot.prototype?"ShadowRoot":"Element";if(i.api.import in n)throw new Error(`The ${o} prototype already has a "${i.api.import}" API!`);Object.defineProperty(n,i.api.import,{value:function(s,a=!1,l=null){return r(this,...arguments)}})});function r(n,o,s=!1,a=null){let l={};typeof s=="function"?(a=s,s=!1):typeof s=="object"&&s?l={...s,...l}:l={live:s};let c={...ot.createRequest(o),...l};return n[e.CONTEXT_API.api.contexts].request(c,a)}}function Di(i){let t=this,{webqit:{Observer:e,realdom:r,oohtml:{configs:n},HTMLImportElement:o,HTMLImportsContext:s}}=t,a=u=>{let d=u[n.CONTEXT_API.api.contexts];d.find(s.kind)||d.attach(new s)},l=u=>{let d=u[n.CONTEXT_API.api.contexts],f=d.find(s.kind);f&&(!u.isConnected||!u.matches?.(i.importsContextSelector)&&!Object.keys(f.localModules).length)&&d.detach(f)};r.realtime(t.document).query([i.templateSelector,i.importsContextSelector],u=>{u.entrants.forEach(d=>{if(d.matches(i.templateSelector)){let f=K.instance(d);f.ownerContext=d.scoped?d.parentNode:d.getRootNode();let p=nt(f.ownerContext);f.defId&&e.set(p,f.defId,d),a(f.ownerContext)}else a(d)}),u.exits.forEach(d=>{if(d.matches(i.templateSelector)){let f=K.instance(d),p=nt(f.ownerContext);f.defId&&f.ownerContext.isConnected&&e.deleteProperty(p,f.defId),l(f.ownerContext)}else l(d)})},{live:!0,subtree:"cross-roots",timing:"sync",staticSensitivity:!0,eventDetails:!0}),r.realtime(t.document).query(i.elements.import,u=>{u.entrants.forEach(d=>c(d,!0,u)),u.exits.forEach(d=>c(d,!1,u))},{live:!0,subtree:"cross-roots",timing:"sync"});function c(u,d){let f=o.instance(u);d?f["#"].connectedCallback():f["#"].disconnectedCallback()}t.webqit.env!=="server"&&r.realtime(t.document).query(`(${i.anchorNodeSelector})`,u=>{u.entrants.forEach(d=>{if(S(d).get("isAnchorNode"))return;let f=t.document.createElement("div");f.innerHTML=d.nodeValue,f.innerHTML=f.firstChild.textContent;let p=f.firstChild,g=parseInt(p.getAttribute("data-nodecount")),y=new Set,v=d;for(;(v=v.previousElementSibling)&&v.matches(i.slottedElementsSelector)&&g--;)y.add(v);o.instance(p)["#"].hydrate(d,y)})},{live:!0,subtree:"cross-roots",timing:"sync"})}function Ye(i={}){let{config:t,window:e}=V.call(this,"context-api",i,{attr:{contextname:"contextname"},api:{contexts:"contexts"}});e.webqit.DOMContexts=ct,e.webqit.DOMContext=B,e.webqit.DOMContextRequestEvent=de(),e.webqit.DOMContextResponse=wt,e.webqit.DuplicateContextError=xt,Li.call(e,t)}function Li(i){let t=this;[t.Document.prototype,t.Element.prototype,t.ShadowRoot.prototype].forEach(e=>{let r=e===t.Document.prototype?"Document":e===t.ShadowRoot.prototype?"ShadowRoot":"Element";if(i.api.contexts in e)throw new Error(`The ${r} prototype already has a "${i.api.contexts}" API!`);Object.defineProperty(e,i.api.contexts,{get:function(){return ct.instance(this)}})})}function Ke({advanced:i={},...t}){let{config:e,window:r}=V.call(this,"scoped-css",t,{api:{styleSheets:"styleSheets"},style:{retention:"retain",mimeTypes:"text/css",strategy:null}});e.styleSelector=(Array.isArray(e.style.mimeTypes)?e.style.mimeTypes:e.style.mimeTypes.split("|")).concat("").reduce((n,o)=>{let s=o?`[type="${r.CSS.escape(o)}"]`:":not([type])";return n.concat(`style${s}`)},[]).join(","),r.webqit.oohtml.Style={compileCache:new Map},Hi.call(r,e),Fi.call(r,e)}function Hi(i){let t=this,e=new Map;[t.Element.prototype].forEach(r=>{let n="Element";if(i.api.styleSheets in r)throw new Error(`The ${n} prototype already has a "${i.api.styleSheets}" API!`);Object.defineProperty(r,i.api.styleSheets,{get:function(){return e.has(this)||e.set(this,[]),e.get(this)}})}),Object.defineProperty(t.HTMLStyleElement.prototype,"scoped",{configurable:!0,get(){return this.hasAttribute("scoped")},set(r){this.toggleAttribute("scoped",r)}})}function Fi(i){let t=this,{webqit:{oohtml:e,realdom:r}}=t,n=Object.getOwnPropertyDescriptor(globalThis,"window")?.get?.toString().includes("[native code]")??!1;t.CSS.supports||(t.CSS.supports=()=>!1);let o=new WeakSet;r.realtime(t.document).query(i.styleSelector,s=>{s.entrants.forEach(a=>{if(o.has(a))return;o.add(a);let l=bt(a.textContent),c=CSS.supports("selector(:has(a,b))"),u=a.scoped&&(c?`:has(> style[rand-${l}])`:`[rand-${l}]`),d=a.scoped&&t.CSSScopeRule&&!1,f=a.scoped&&a.parentNode||a.getRootNode();if(f instanceof t.Element){if(f[i.api.styleSheets].push(a),!n)return;(c?a:f).toggleAttribute(`rand-${l}`,!0)}if(!!n)if(a.scoped&&a.hasAttribute("shared")){let p;(p=e.Style.compileCache.get(l))||(p=Wi.call(t,a,null,d,u),e.Style.compileCache.set(l,p)),Object.defineProperty(a,"sheet",{value:p,configurable:!0}),a.textContent=`
55
55
  /*[ Shared style sheet ]*/
56
56
  `}else{let p=()=>{let g=he(Tt.call(t,f));Ze.call(this,a.sheet,g,!d&&u)};a.isConnected?p():setTimeout(()=>{p()},0)}})},{live:!0,subtree:"cross-roots",timing:"intercept",generation:"entrants"})}function Wi(i,t,e,r){let n=this,o=i.textContent,s,a=e&&r?`@scope (${r}) {
57
57
  ${o.trim()}