@webqit/oohtml 4.1.1-debug.4 → 4.1.1-debug.6

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
@@ -17,7 +17,7 @@ ${g}
17
17
  /*[ Shared style sheet ]*/
18
18
  `}else{let p=()=>{let g=he(Ct.call(t,f));ze.call(this,c.sheet,g,!d&&u)};c.isConnected?p():setTimeout(()=>{p()},0)}})},{live:!0,subtree:"cross-roots",timing:"intercept",generation:"entrants"})}function Ai(i,t,e,r){let n=this,o=i.textContent,s,c=e&&r?`@scope (${r}) {
19
19
  ${o.trim()}
20
- }`:o.trim();try{s=new n.CSSStyleSheet,s.replaceSync(c),ze.call(this,s,t,!e&&r);let l=()=>i.getRootNode().adoptedStyleSheets.push(s);i.isConnected?l():setTimeout(()=>{l()},0)}catch{let a=n.document.createElement("style");i.after(a),a.textContent=c,s=a.sheet,ze.call(this,s,t,!e&&r)}return s}function ze(i,t,e=null){let r=i?.cssRules.length||-1;for(let n=0;n<r;++n){let o=i.cssRules[n];o instanceof CSSImportRule||Cr.call(this,o,t,e)}}function Cr(i,t,e=null){if(i instanceof CSSStyleRule){Tr.call(this,i,t,e);return}if([window.CSSScopeRule,window.CSSMediaRule,window.CSSContainerRule,window.CSSSupportsRule,window.CSSLayerBlockRule].some(r=>r&&i instanceof r)){let r=i.cssRules.length;for(let n=0;n<r;++n)Cr.call(this,i.cssRules[n],t,e)}}function Tr(i,t,e=null){let r=Be.call(this,i.selectorText,t,e,1);if(i.selectorText=r,i.cssRules){let n=i.cssRules.length;for(let o=0;o<n;++o)Tr.call(this,i.cssRules[o],t)}}function Ge({advanced:i={},...t}){let{config:e,window:r}=V.call(this,"scoped-js",t,{script:{retention:"retain",mimeTypes:"module|text/javascript|application/javascript"},api:{scripts:"scripts"},advanced:oe(i)});e.scriptSelector=(Array.isArray(e.script.mimeTypes)?e.script.mimeTypes:e.script.mimeTypes.split("|")).concat("").reduce((n,o)=>{let s=o?`[type="${r.CSS.escape(o)}"]`:":not([type])";return n.concat(`script${s}`)},[]).join(","),r.webqit.oohtml.Script={compileCache:[new Map,new Map],execute:$i.bind(r,e)},Ei.call(r,e),Pi.call(r,e)}function Ei(i){let t=this,e=new Map;if(i.api.scripts in t.Element.prototype)throw new Error(`The "Element" class already has a "${i.api.scripts}" property!`);Object.defineProperty(t.Element.prototype,i.api.scripts,{get:function(){return e.has(this)||e.set(this,[]),e.get(this)}}),Object.defineProperties(t.HTMLScriptElement.prototype,{scoped:{configurable:!0,get(){return this.hasAttribute("scoped")},set(r){this.toggleAttribute("scoped",r)}},quantum:{configurable:!0,get(){return this.hasAttribute("quantum")},set(r){this.toggleAttribute("quantum",r)}}})}async function $i(i,t){let e=this,{realdom:r}=e.webqit,n=fe(t);if(!n)throw new Error("Argument must be a valid exec hash.");let{script:o,compiledScript:s,thisContext:c}=n;i.script.retention==="dispose"?o.remove():i.script.retention==="dispose"?o.textContent='"source hidden"':o.textContent=await s.toString();let l=o.getRootNode();S(l).has("scriptEnv")||S(l).set("scriptEnv",Object.create(null));let a=(await s.bind(c,S(l).get("scriptEnv"))).execute();o.quantum&&Object.defineProperty(o,"state",{value:a}),r.realtime(e.document).observe(o,()=>{o.quantum&&a.dispose(),c instanceof e.Element&&c[i.api.scripts]?.splice(c[i.api.scripts].indexOf(o,1))},{subtree:"cross-roots",timing:"sync",generation:"exits"})}function Pi(i){let t=this,{webqit:{oohtml:e,realdom:r,QuantumScript:n,AsyncQuantumScript:o,QuantumModule:s}}=t;t.HTMLScriptElement.supports||(t.HTMLScriptElement.supports=l=>["text/javascript","application/javascript"].includes(l));let c=new WeakSet;r.realtime(t.document).query(i.scriptSelector,l=>{l.entrants.forEach(a=>{if(c.has(a))return;let u=(a._=a.textContent.trim())&&a._.startsWith("/*@oohtml*/if(false){")&&a._.endsWith("}/*@oohtml*/")?a._.slice(21,-12):a.textContent;if(!a.scoped&&!a.quantum&&!u.includes("quantum"))return;c.add(a);let d=bt(u),f=e.Script.compileCache[a.quantum?0:1],p;if(!(p=f.get(d))){let{parserParams:h,compilerParams:b,runtimeParams:O}=i.advanced;p=new(a.type==="module"?s:n||o)(u,{exportNamespace:`#${a.id}`,fileName:`${t.document.url?.split("#")?.[0]||""}#${a.id}`,parserParams:{...h,quantumMode:a.quantum},compilerParams:b,runtimeParams:O}),f.set(d,p)}let g=a.scoped?a.parentNode||l.target:a.type==="module"?void 0:t;a.scoped&&g[i.api.scripts].push(a);let y=bt({script:a,compiledScript:p,thisContext:g});l.type==="query"||a.type&&!t.HTMLScriptElement.supports(a.type)?e.Script.execute(y):a.textContent=`webqit.oohtml.Script.execute( '${y}' );`})},{live:!0,subtree:"cross-roots",timing:"intercept",generation:"entrants",eventDetails:!0})}function Xe(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,Ci.call(e,t)}function Ci(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)}})})}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}}}=M;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,Ti.call(e,t)}function Ir(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 c=Object.keys(o),l=t instanceof e.Document?t.documentElement:t,a=i.attr.bindingsreflection;c.length&&a&&l.setAttribute?l.setAttribute(i.attr.bindingsreflection,c.join(" ")):a&&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 Ti(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 Ii.call(t,i,this,o,s)}}),Object.defineProperty(r,i.api.bindings,{get:function(){return e.proxy(Ir.call(t,i,this))}})})}function Ii(i,t,e,{merge:r,diff:n,namespace:o}={}){let s=this,{webqit:{Observer:c}}=s,l=Ir.call(this,i,t),a={diff:n,namespace:o},u=r?[]:c.ownKeys(l,a).filter(d=>!(d in e));return c.batch(l,()=>(u.length&&c.deleteProperties(l,u,a),c.set(l,e,a)),a)}var K=class{static instance(t){return S(t).get("defsmanager::instance")||new this(t)}constructor(t,e=null,r=0){let{window:n}=M,{webqit:{realdom:o,oohtml:{configs:s}}}=n;S(t).get("defsmanager::instance")?.dispose(),S(t).set("defsmanager::instance",this),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(c=>{this.export(c.entrants,!0),this.export(c.exits,!1)},{live:!0,timing:"sync"}),this.realtimeB=o.realtime(this.host).attr(["src","loading"],(...c)=>this.evaluateLoading(...c),{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.`)}export(t,e){let{window:r}=M,{webqit:{Observer:n}}=r,o,s=this.defs["#"]||[];n.batch(this.defs,()=>{t.forEach(c=>{if(c.nodeType!==1)return;let l=c.matches(this.config.templateSelector),a=(c.getAttribute(l?this.config.attr.def:this.config.attr.fragmentdef)||"").trim();e?(l&&a?new K(c,this.host,this.level+1):(s.push(c),o=!0),a&&(this.validateDefId(a),n.set(this.defs,(!l&&"#"||"")+a,c))):(l&&a?K.instance(c).dispose():(s=s.filter(u=>u!==c),o=!0),a&&n.deleteProperty(this.defs,(!l&&"#"||"")+a))}),o&&n.set(this.defs,"#",s)})}evaluateLoading([t,e],{signal:r}){let{window:{webqit:{Observer:n}}}=M,o=(t.value||"").trim();if(!o)return;let s,c=u=>{if(!u)return s;s=u.then(()=>a.remove())},l=(e.value||"").trim(),a=n.intercept(this.defs,"get",async(u,d,f)=>(l==="lazy"&&c(this.load(o,!0)),await c(),f()),{signal:r});l!=="lazy"&&c(this.load(o))}load(t){let{window:e}=M;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,c)=>this.host.dispatchEvent(new e.CustomEvent(s,{detail:c})),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}}}=M,e=(this.host.getAttribute(this.config.attr.extends)||"").trim(),r=(this.host.getAttribute(this.config.attr.inherits)||"").trim(),n=c=>{c.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(c=>c.trim()).filter(c=>c)).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}}}=M;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 c=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(c)):e.reduce(this.contextModules,r,e.get,a=>(t._currentSource="context",t.respondWith(Array.isArray(a)?a:a.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 c={...this.constructor.createRequest(o.value.trim()),live:!0,signal:s};this.host.parentNode[this.configs.CONTEXT_API.api.contexts].request(c,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 qr(){let{window:i}=M,{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(c){return r.HTML_IMPORTS.elements.import.includes("-")&&c instanceof this?c:S(c).get("import::instance")||new this(c)}constructor(...c){super();let l=c[0]||this;S(l).set("import::instance",this),Object.defineProperty(this,"el",{get:()=>l,configurable:!1});let a={};Object.defineProperty(this,"#",{get:()=>a,configurable:!1}),a.slottedElements=new Set,a.setAnchorNode=u=>(a.anchorNode=u,u),a.importRequest=(u,d=null)=>{let f={...ot.createRequest(a.moduleRef?.includes("#")?a.moduleRef:`${a.moduleRef}#`),live:d&&!0,signal:d};(this.el.isConnected?this.el.parentNode:a.anchorNode.parentNode)[r.CONTEXT_API.api.contexts].request(f,p=>{u((p instanceof i.HTMLTemplateElement?[...p.content.children]:Array.isArray(p)?p:p&&[p])||[])})},a.hydrate=(u,d)=>{a.moduleRef=(this.el.getAttribute(r.HTML_IMPORTS.attr.ref)||"").trim(),u.replaceWith(a.setAnchorNode(this.createAnchorNode())),a.autoRestore(()=>{d.forEach(f=>{a.slottedElements.add(f),S(f).set("slot@imports",this.el)})}),a.hydrationImportRequest=new AbortController,a.importRequest(f=>{if(a.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)||"",b=(g++,p.find(O=>O.tagName===v&&O.fragmentDef===h&&O.i===g));!b||S(y).set("original@imports",b.el)}),a.originalsRemapped=!0},a.hydrationImportRequest.signal)},a.autoRestore=(u=null)=>{a.autoRestoreRealtime?.disconnect(),u&&u();let d=()=>{a.anchorNode?.replaceWith(this.el),a.anchorNode=null,this.el.setAttribute("data-nodecount",0)};if(!a.slottedElements.size)return d();let f=e.realtime(i.document).observe([...a.slottedElements],p=>{if(p.exits.forEach(g=>{S(g).delete("slot@imports"),a.slottedElements.delete(g)}),!a.slottedElements.size){if(f.disconnect(),!p.target.isConnected)return;d()}},{subtree:"cross-roots",timing:"sync",generation:"exits"});a.autoRestoreRealtime=f},a.connectedCallback=()=>{if(a.slottedElements.size)throw new Error("Illegal reinsertion into the DOM; import slot is not empty!");a.moduleRefRealtime||(a.moduleRefRealtime=e.realtime(this.el).attr(r.HTML_IMPORTS.attr.ref,(u,{signal:d})=>{a.moduleRef=u.value,a.importRequest(f=>!a.hydrationImportRequest&&this.fill(f),d)},{live:!0,timing:"sync",lifecycleSignals:!0}),a.hydrationImportRequest?.abort(),a.hydrationImportRequest=null)},a.disconnectedCallback=()=>{a.hydrationImportRequest?.abort(),a.hydrationImportRequest=null,!a.anchorNode.isConnected&&(a.moduleRefRealtime?.disconnect(),a.moduleRefRealtime=null)}}createAnchorNode(){if(i.webqit.env!=="server")return i.document.createTextNode("");let c=i.document.createElement("div");c.textContent=this.el.outerHTML;let l=i.document.createComment(c.innerHTML);return S(l).set("isAnchorNode",!0),l}fill(c){Array.isArray(c)&&(c=new Set(c)),this.el.setAttribute("data-nodecount",c.size),this["#"].autoRestore(()=>{if(this["#"].slottedElements.forEach(l=>{let a=S(l).get("original@imports");c.has(a)?c.delete(a):(this["#"].slottedElements.delete(l),l.remove())}),c.size){let l=this["#"].anchorNode,a=this["#"].setAnchorNode(this.createAnchorNode());(this.el.isConnected?this.el:l).replaceWith(a)}c.forEach(l=>{let a=l.cloneNode(!0);a.hasAttribute(r.HTML_IMPORTS.attr.fragmentdef)||a.toggleAttribute(r.HTML_IMPORTS.attr.fragmentdef,!0),S(a).set("original@imports",l),S(a).set("slot@imports",this.el),this["#"].slottedElements.add(a),this["#"].anchorNode.before(a)})})}empty(){this["#"].slottedElements.forEach(c=>c.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}")`,c=`substring(., string-length(.) - string-length("${o}") + 1) = "${o}"`;return`${s} and ${c}`};t.anchorNodeSelector=`comment()[${r(`&lt;${t.elements.import}`,`&lt;/${t.elements.import}&gt;`)}]`,e.webqit.HTMLImportsContext=ot,e.webqit.HTMLImportElement=qr(),qi.call(e,t),Ri.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 qi(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,c=!1,l=null){return r(this,...arguments)}})});function r(n,o,s=!1,c=null){let l={};typeof s=="function"?(c=s,s=!1):typeof s=="object"&&s?l={...s,...l}:l={live:s};let a={...ot.createRequest(o),...l};return n[e.CONTEXT_API.api.contexts].request(a,c)}}function Ri(i){let t=this,{webqit:{Observer:e,realdom:r,oohtml:{configs:n},HTMLImportElement:o,HTMLImportsContext:s}}=t,c=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?u.target:u.target.getRootNode();let p=nt(f.ownerContext);f.defId&&e.set(p,f.defId,d),c(f.ownerContext)}else c(d)}),u.exits.forEach(d=>{if(d.matches(i.templateSelector)){let f=K.instance(d),p=nt(f.ownerContext);f.defId&&e.deleteProperty(p,f.defId),l(f.ownerContext)}else l(d)})},{live:!0,subtree:"cross-roots",timing:"sync",staticSensitivity:!0}),r.realtime(t.document).query(i.elements.import,u=>{u.entrants.forEach(d=>a(d,!0,u)),u.exits.forEach(d=>a(d,!1,u))},{live:!0,subtree:"cross-roots",timing:"sync"});function a(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 Ke(i={}){let{config:t,window:e}=V.call(this,"data-binding",i,{attr:{render:"render",itemIndex:"data-key"},tokens:{nodeType:"processing-instruction",tagStart:"?{",tagEnd:"}?",stateStart:"; [=",stateEnd:"]"}});({CONTEXT_API:t.CONTEXT_API,BINDINGS_API:t.BINDINGS_API,HTML_IMPORTS:t.HTML_IMPORTS}=e.webqit.oohtml.configs),t.attrSelector=`[${e.CSS.escape(t.attr.render)}]`;let r=(n,o)=>{let s=`starts-with(., "${n}")`,c=`substring(., string-length(.) - string-length("${o}") + 1) = "${o}"`;return`${s} and ${c}`};t.discreteBindingsSelector=`comment()[${r(t.tokens.tagStart,t.tokens.tagEnd)}]`,Mi.call(e,t)}function Mi(i){let t=this,{webqit:{realdom:e}}=t;e.realtime(t.document).query(`(${i.discreteBindingsSelector})`,r=>{Rr.call(this,...r.exits),ji.call(this,i,...r.entrants)},{live:!0,subtree:"cross-roots",timing:"sync"}),e.realtime(t.document).query(i.attrSelector,r=>{Rr.call(this,...r.exits),Ni.call(this,i,...r.entrants)},{live:!0,subtree:"cross-roots",timing:"sync",staticSensitivity:!0})}function Mr(i,t){let{webqit:{realdom:e,Observer:r,DOMBindingsContext:n}}=this;if(S(t).has("data-binding"))return S(t).get("data-binding");let o=Object.create(null),s=new AbortController;o.$exec__=(l,a,...u)=>{e.schedule("write",()=>l[a](...u))},o.$assign__=(l,a,u)=>{e.schedule("write",()=>l[a]=u)},r.intercept(o,{get:(l,a,u)=>{if(!(l.key in o)){let d={...n.createRequest(l.key),live:!0,signal:s.signal};t[i.CONTEXT_API.api.contexts].request(d,f=>{r.set(o,l.key,f)})}return u(o[l.key]??(l.key in globalThis?globalThis[l.key]:void 0))},has:(l,a,u)=>u(!0)});let c={scope:o,abortController:s,bindings:new Map};return S(t).set("data-binding",c),c}function Rr(...i){for(let t of i){let e=t.nodeName==="#text"?t.parentNode:t,{bindings:r,abortController:n}=S(e).get("data-binding")||{};if(!r?.has(t))return;r.get(t).state.dispose(),r.get(t).signals?.forEach(o=>o.abort()),r.delete(t),r.size||(n.abort(),S(e).delete("data-binding"))}}async function ji(i,...t){let e=this,r=o=>{let s=i.tokens.tagStart.split("").map(p=>`\\${p}`).join(""),c=i.tokens.tagEnd.split("").map(p=>`\\${p}`).join(""),l=i.tokens.stateStart.split("").map(p=>p===" "?"(?:\\s+)?":`\\${p}`).join(""),a=i.tokens.stateEnd.split("").map(p=>`\\${p}`).join(""),u=`^${s}(.*?)(?:${l}(\\d+)${a}(?:\\s+)?)?${c}$`,[,d,f]=o.match(new RegExp(u));return{raw:o,expr:d,span:parseInt(f??0)}},n=t.reduce((o,s)=>{if(s.isBound)return o;let c=r(s.nodeValue),l=s;if(c.span){if(l=s.nextSibling,l?.nodeName!=="#text"||l.nodeValue.length<c.span)return o;l.nodeValue.length>c.span&&l.splitText(c.span)}else l=s.ownerDocument.createTextNode(""),s.after(l);l.isBound=!0;let a=s;return e.webqit.env!=="server"&&(a.remove(),a=null),o.concat({textNode:l,template:c,anchorNode:a})},[]);for(let{textNode:o,template:s,anchorNode:c}of n){let l=ki(i,s.expr),{scope:a,bindings:u}=Mr.call(this,i,o.parentNode);Object.defineProperty(o,"$oohtml_internal_databinding_anchorNode",{value:c,configurable:!0}),u.set(o,{state:await(await l.bind(o,a)).execute()})}}var Ye=new Map;function ki(i,t){if(Ye.has(t))return Ye.get(t);let e=`let content = ((${t}) ?? '') + '';`;e+="$assign__(this, 'nodeValue', content);",e+=`if ( this.$oohtml_internal_databinding_anchorNode ) { $assign__(this.$oohtml_internal_databinding_anchorNode, 'nodeValue', "${i.tokens.tagStart}${Tt(t)}${i.tokens.stateStart}" + content.length + "${i.tokens.stateEnd} ${i.tokens.tagEnd}"); }`;let{webqit:{QuantumModule:r}}=this,n=new r(e);return Ye.set(t,n),n}async function Ni(i,...t){for(let e of t){let r=Di(i,e.getAttribute(i.attr.render)),{scope:n,bindings:o}=Mr.call(this,i,e),s=[];Object.defineProperty(e,"$oohtml_internal_databinding_signals",{value:s,configurable:!0}),o.set(e,{signals:s,state:await(await r.bind(e,n)).execute()})}}var Ze=new Map;function Di(i,t){if(Ze.has(t))return Ze.get(t);let e={},r=$t(t,";").map(s=>{let[c,l]=$t(s,":").map(p=>p.trim()),a=c[0],u=c.slice(1).trim(),d=`(${l})`,f=`(${d} ?? '')`;if(a==="&")return u.startsWith("--")?`$exec__(this.style, 'setProperty', "${Tt(u)}", ${f});`:`$assign__(this.style, "${Tt(u)}", ${f});`;if(a==="%")return`$exec__(this.classList, 'toggle', "${Tt(u)}", !!${d});`;if(a==="~")return u.startsWith("?")?`$exec__(this, 'toggleAttribute', "${Tt(u.substring(1).trim())}", !!${d});`:`$exec__(this, 'setAttribute', "${Tt(u)}", ${f});`;if(a==="@"){if(e[u])throw new Error(`Duplicate binding: ${c}.`);if(e[u]=!0,u==="text")return`$assign__(this, 'textContent', ${f});`;if(u==="html")return`$exec__(this, 'setHTML', ${f});`;if(u==="items"){let[p,g]=$t(l,"/");if(!g)throw new Error(`Invalid ${a}items spec: ${s}; no import specifier.`);let[y,v,h,b]=p.trim().match(/(.*?[\)\s+])(of|in)([\(\{\[\s+].*)/i)||[];if(!y)throw new Error(`Invalid ${a}items spec: ${s}.`);if(v.startsWith("(")?v=v.trim().slice(1,-1).split(",").map(_=>_.trim()):v=[v],v.length>(h==="in"?3:2))throw new Error(`Invalid ${a}items spec: ${s}.`);let O=h==="in"?v[2]:v[1]||"$index__";return`
20
+ }`:o.trim();try{s=new n.CSSStyleSheet,s.replaceSync(c),ze.call(this,s,t,!e&&r);let l=()=>i.getRootNode().adoptedStyleSheets.push(s);i.isConnected?l():setTimeout(()=>{l()},0)}catch{let a=n.document.createElement("style");i.after(a),a.textContent=c,s=a.sheet,ze.call(this,s,t,!e&&r)}return s}function ze(i,t,e=null){let r=i?.cssRules.length||-1;for(let n=0;n<r;++n){let o=i.cssRules[n];o instanceof CSSImportRule||Cr.call(this,o,t,e)}}function Cr(i,t,e=null){if(i instanceof CSSStyleRule){Tr.call(this,i,t,e);return}if([window.CSSScopeRule,window.CSSMediaRule,window.CSSContainerRule,window.CSSSupportsRule,window.CSSLayerBlockRule].some(r=>r&&i instanceof r)){let r=i.cssRules.length;for(let n=0;n<r;++n)Cr.call(this,i.cssRules[n],t,e)}}function Tr(i,t,e=null){let r=Be.call(this,i.selectorText,t,e,1);if(i.selectorText=r,i.cssRules){let n=i.cssRules.length;for(let o=0;o<n;++o)Tr.call(this,i.cssRules[o],t)}}function Ge({advanced:i={},...t}){let{config:e,window:r}=V.call(this,"scoped-js",t,{script:{retention:"retain",mimeTypes:"module|text/javascript|application/javascript"},api:{scripts:"scripts"},advanced:oe(i)});e.scriptSelector=(Array.isArray(e.script.mimeTypes)?e.script.mimeTypes:e.script.mimeTypes.split("|")).concat("").reduce((n,o)=>{let s=o?`[type="${r.CSS.escape(o)}"]`:":not([type])";return n.concat(`script${s}`)},[]).join(","),r.webqit.oohtml.Script={compileCache:[new Map,new Map],execute:$i.bind(r,e)},Ei.call(r,e),Pi.call(r,e)}function Ei(i){let t=this,e=new Map;if(i.api.scripts in t.Element.prototype)throw new Error(`The "Element" class already has a "${i.api.scripts}" property!`);Object.defineProperty(t.Element.prototype,i.api.scripts,{get:function(){return e.has(this)||e.set(this,[]),e.get(this)}}),Object.defineProperties(t.HTMLScriptElement.prototype,{scoped:{configurable:!0,get(){return this.hasAttribute("scoped")},set(r){this.toggleAttribute("scoped",r)}},quantum:{configurable:!0,get(){return this.hasAttribute("quantum")},set(r){this.toggleAttribute("quantum",r)}}})}async function $i(i,t){let e=this,{realdom:r}=e.webqit,n=fe(t);if(!n)throw new Error("Argument must be a valid exec hash.");let{script:o,compiledScript:s,thisContext:c}=n;i.script.retention==="dispose"?o.remove():i.script.retention==="dispose"?o.textContent='"source hidden"':o.textContent=await s.toString();let l=o.getRootNode();S(l).has("scriptEnv")||S(l).set("scriptEnv",Object.create(null));let a=(await s.bind(c,S(l).get("scriptEnv"))).execute();o.quantum&&Object.defineProperty(o,"state",{value:a}),r.realtime(e.document).observe(o,()=>{o.quantum&&a.dispose(),c instanceof e.Element&&c[i.api.scripts]?.splice(c[i.api.scripts].indexOf(o,1))},{subtree:"cross-roots",timing:"sync",generation:"exits"})}function Pi(i){let t=this,{webqit:{oohtml:e,realdom:r,QuantumScript:n,AsyncQuantumScript:o,QuantumModule:s}}=t;t.HTMLScriptElement.supports||(t.HTMLScriptElement.supports=l=>["text/javascript","application/javascript"].includes(l));let c=new WeakSet;r.realtime(t.document).query(i.scriptSelector,l=>{l.entrants.forEach(a=>{if(c.has(a))return;let u=(a._=a.textContent.trim())&&a._.startsWith("/*@oohtml*/if(false){")&&a._.endsWith("}/*@oohtml*/")?a._.slice(21,-12):a.textContent;if(!a.scoped&&!a.quantum&&!u.includes("quantum"))return;c.add(a);let d=bt(u),f=e.Script.compileCache[a.quantum?0:1],p;if(!(p=f.get(d))){let{parserParams:h,compilerParams:b,runtimeParams:O}=i.advanced;p=new(a.type==="module"?s:n||o)(u,{exportNamespace:`#${a.id}`,fileName:`${t.document.url?.split("#")?.[0]||""}#${a.id}`,parserParams:{...h,quantumMode:a.quantum},compilerParams:b,runtimeParams:O}),f.set(d,p)}let g=a.scoped?a.parentNode||l.target:a.type==="module"?void 0:t;a.scoped&&g[i.api.scripts].push(a);let y=bt({script:a,compiledScript:p,thisContext:g}),v=l.type==="query"||a.type&&!t.HTMLScriptElement.supports(a.type);console.log("--------////",l.event),v?e.Script.execute(y):a.textContent=`webqit.oohtml.Script.execute( '${y}' );`})},{live:!0,subtree:"cross-roots",timing:"intercept",generation:"entrants",eventDetails:!0})}function Xe(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,Ci.call(e,t)}function Ci(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)}})})}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}}}=M;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,Ti.call(e,t)}function Ir(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 c=Object.keys(o),l=t instanceof e.Document?t.documentElement:t,a=i.attr.bindingsreflection;c.length&&a&&l.setAttribute?l.setAttribute(i.attr.bindingsreflection,c.join(" ")):a&&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 Ti(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 Ii.call(t,i,this,o,s)}}),Object.defineProperty(r,i.api.bindings,{get:function(){return e.proxy(Ir.call(t,i,this))}})})}function Ii(i,t,e,{merge:r,diff:n,namespace:o}={}){let s=this,{webqit:{Observer:c}}=s,l=Ir.call(this,i,t),a={diff:n,namespace:o},u=r?[]:c.ownKeys(l,a).filter(d=>!(d in e));return c.batch(l,()=>(u.length&&c.deleteProperties(l,u,a),c.set(l,e,a)),a)}var K=class{static instance(t){return S(t).get("defsmanager::instance")||new this(t)}constructor(t,e=null,r=0){let{window:n}=M,{webqit:{realdom:o,oohtml:{configs:s}}}=n;S(t).get("defsmanager::instance")?.dispose(),S(t).set("defsmanager::instance",this),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(c=>{this.export(c.entrants,!0),this.export(c.exits,!1)},{live:!0,timing:"sync"}),this.realtimeB=o.realtime(this.host).attr(["src","loading"],(...c)=>this.evaluateLoading(...c),{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.`)}export(t,e){let{window:r}=M,{webqit:{Observer:n}}=r,o,s=this.defs["#"]||[];n.batch(this.defs,()=>{t.forEach(c=>{if(c.nodeType!==1)return;let l=c.matches(this.config.templateSelector),a=(c.getAttribute(l?this.config.attr.def:this.config.attr.fragmentdef)||"").trim();e?(l&&a?new K(c,this.host,this.level+1):(s.push(c),o=!0),a&&(this.validateDefId(a),n.set(this.defs,(!l&&"#"||"")+a,c))):(l&&a?K.instance(c).dispose():(s=s.filter(u=>u!==c),o=!0),a&&n.deleteProperty(this.defs,(!l&&"#"||"")+a))}),o&&n.set(this.defs,"#",s)})}evaluateLoading([t,e],{signal:r}){let{window:{webqit:{Observer:n}}}=M,o=(t.value||"").trim();if(!o)return;let s,c=u=>{if(!u)return s;s=u.then(()=>a.remove())},l=(e.value||"").trim(),a=n.intercept(this.defs,"get",async(u,d,f)=>(l==="lazy"&&c(this.load(o,!0)),await c(),f()),{signal:r});l!=="lazy"&&c(this.load(o))}load(t){let{window:e}=M;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,c)=>this.host.dispatchEvent(new e.CustomEvent(s,{detail:c})),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}}}=M,e=(this.host.getAttribute(this.config.attr.extends)||"").trim(),r=(this.host.getAttribute(this.config.attr.inherits)||"").trim(),n=c=>{c.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(c=>c.trim()).filter(c=>c)).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}}}=M;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 c=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(c)):e.reduce(this.contextModules,r,e.get,a=>(t._currentSource="context",t.respondWith(Array.isArray(a)?a:a.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 c={...this.constructor.createRequest(o.value.trim()),live:!0,signal:s};this.host.parentNode[this.configs.CONTEXT_API.api.contexts].request(c,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 qr(){let{window:i}=M,{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(c){return r.HTML_IMPORTS.elements.import.includes("-")&&c instanceof this?c:S(c).get("import::instance")||new this(c)}constructor(...c){super();let l=c[0]||this;S(l).set("import::instance",this),Object.defineProperty(this,"el",{get:()=>l,configurable:!1});let a={};Object.defineProperty(this,"#",{get:()=>a,configurable:!1}),a.slottedElements=new Set,a.setAnchorNode=u=>(a.anchorNode=u,u),a.importRequest=(u,d=null)=>{let f={...ot.createRequest(a.moduleRef?.includes("#")?a.moduleRef:`${a.moduleRef}#`),live:d&&!0,signal:d};(this.el.isConnected?this.el.parentNode:a.anchorNode.parentNode)[r.CONTEXT_API.api.contexts].request(f,p=>{u((p instanceof i.HTMLTemplateElement?[...p.content.children]:Array.isArray(p)?p:p&&[p])||[])})},a.hydrate=(u,d)=>{a.moduleRef=(this.el.getAttribute(r.HTML_IMPORTS.attr.ref)||"").trim(),u.replaceWith(a.setAnchorNode(this.createAnchorNode())),a.autoRestore(()=>{d.forEach(f=>{a.slottedElements.add(f),S(f).set("slot@imports",this.el)})}),a.hydrationImportRequest=new AbortController,a.importRequest(f=>{if(a.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)||"",b=(g++,p.find(O=>O.tagName===v&&O.fragmentDef===h&&O.i===g));!b||S(y).set("original@imports",b.el)}),a.originalsRemapped=!0},a.hydrationImportRequest.signal)},a.autoRestore=(u=null)=>{a.autoRestoreRealtime?.disconnect(),u&&u();let d=()=>{a.anchorNode?.replaceWith(this.el),a.anchorNode=null,this.el.setAttribute("data-nodecount",0)};if(!a.slottedElements.size)return d();let f=e.realtime(i.document).observe([...a.slottedElements],p=>{if(p.exits.forEach(g=>{S(g).delete("slot@imports"),a.slottedElements.delete(g)}),!a.slottedElements.size){if(f.disconnect(),!p.target.isConnected)return;d()}},{subtree:"cross-roots",timing:"sync",generation:"exits"});a.autoRestoreRealtime=f},a.connectedCallback=()=>{if(a.slottedElements.size)throw new Error("Illegal reinsertion into the DOM; import slot is not empty!");a.moduleRefRealtime||(a.moduleRefRealtime=e.realtime(this.el).attr(r.HTML_IMPORTS.attr.ref,(u,{signal:d})=>{a.moduleRef=u.value,a.importRequest(f=>!a.hydrationImportRequest&&this.fill(f),d)},{live:!0,timing:"sync",lifecycleSignals:!0}),a.hydrationImportRequest?.abort(),a.hydrationImportRequest=null)},a.disconnectedCallback=()=>{a.hydrationImportRequest?.abort(),a.hydrationImportRequest=null,!a.anchorNode.isConnected&&(a.moduleRefRealtime?.disconnect(),a.moduleRefRealtime=null)}}createAnchorNode(){if(i.webqit.env!=="server")return i.document.createTextNode("");let c=i.document.createElement("div");c.textContent=this.el.outerHTML;let l=i.document.createComment(c.innerHTML);return S(l).set("isAnchorNode",!0),l}fill(c){Array.isArray(c)&&(c=new Set(c)),this.el.setAttribute("data-nodecount",c.size),this["#"].autoRestore(()=>{if(this["#"].slottedElements.forEach(l=>{let a=S(l).get("original@imports");c.has(a)?c.delete(a):(this["#"].slottedElements.delete(l),l.remove())}),c.size){let l=this["#"].anchorNode,a=this["#"].setAnchorNode(this.createAnchorNode());(this.el.isConnected?this.el:l).replaceWith(a)}c.forEach(l=>{let a=l.cloneNode(!0);a.hasAttribute(r.HTML_IMPORTS.attr.fragmentdef)||a.toggleAttribute(r.HTML_IMPORTS.attr.fragmentdef,!0),S(a).set("original@imports",l),S(a).set("slot@imports",this.el),this["#"].slottedElements.add(a),this["#"].anchorNode.before(a)})})}empty(){this["#"].slottedElements.forEach(c=>c.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}")`,c=`substring(., string-length(.) - string-length("${o}") + 1) = "${o}"`;return`${s} and ${c}`};t.anchorNodeSelector=`comment()[${r(`&lt;${t.elements.import}`,`&lt;/${t.elements.import}&gt;`)}]`,e.webqit.HTMLImportsContext=ot,e.webqit.HTMLImportElement=qr(),qi.call(e,t),Ri.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 qi(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,c=!1,l=null){return r(this,...arguments)}})});function r(n,o,s=!1,c=null){let l={};typeof s=="function"?(c=s,s=!1):typeof s=="object"&&s?l={...s,...l}:l={live:s};let a={...ot.createRequest(o),...l};return n[e.CONTEXT_API.api.contexts].request(a,c)}}function Ri(i){let t=this,{webqit:{Observer:e,realdom:r,oohtml:{configs:n},HTMLImportElement:o,HTMLImportsContext:s}}=t,c=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?u.target:u.target.getRootNode();let p=nt(f.ownerContext);f.defId&&e.set(p,f.defId,d),c(f.ownerContext)}else c(d)}),u.exits.forEach(d=>{if(d.matches(i.templateSelector)){let f=K.instance(d),p=nt(f.ownerContext);f.defId&&e.deleteProperty(p,f.defId),l(f.ownerContext)}else l(d)})},{live:!0,subtree:"cross-roots",timing:"sync",staticSensitivity:!0}),r.realtime(t.document).query(i.elements.import,u=>{u.entrants.forEach(d=>a(d,!0,u)),u.exits.forEach(d=>a(d,!1,u))},{live:!0,subtree:"cross-roots",timing:"sync"});function a(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 Ke(i={}){let{config:t,window:e}=V.call(this,"data-binding",i,{attr:{render:"render",itemIndex:"data-key"},tokens:{nodeType:"processing-instruction",tagStart:"?{",tagEnd:"}?",stateStart:"; [=",stateEnd:"]"}});({CONTEXT_API:t.CONTEXT_API,BINDINGS_API:t.BINDINGS_API,HTML_IMPORTS:t.HTML_IMPORTS}=e.webqit.oohtml.configs),t.attrSelector=`[${e.CSS.escape(t.attr.render)}]`;let r=(n,o)=>{let s=`starts-with(., "${n}")`,c=`substring(., string-length(.) - string-length("${o}") + 1) = "${o}"`;return`${s} and ${c}`};t.discreteBindingsSelector=`comment()[${r(t.tokens.tagStart,t.tokens.tagEnd)}]`,Mi.call(e,t)}function Mi(i){let t=this,{webqit:{realdom:e}}=t;e.realtime(t.document).query(`(${i.discreteBindingsSelector})`,r=>{Rr.call(this,...r.exits),ji.call(this,i,...r.entrants)},{live:!0,subtree:"cross-roots",timing:"sync"}),e.realtime(t.document).query(i.attrSelector,r=>{Rr.call(this,...r.exits),Ni.call(this,i,...r.entrants)},{live:!0,subtree:"cross-roots",timing:"sync",staticSensitivity:!0})}function Mr(i,t){let{webqit:{realdom:e,Observer:r,DOMBindingsContext:n}}=this;if(S(t).has("data-binding"))return S(t).get("data-binding");let o=Object.create(null),s=new AbortController;o.$exec__=(l,a,...u)=>{e.schedule("write",()=>l[a](...u))},o.$assign__=(l,a,u)=>{e.schedule("write",()=>l[a]=u)},r.intercept(o,{get:(l,a,u)=>{if(!(l.key in o)){let d={...n.createRequest(l.key),live:!0,signal:s.signal};t[i.CONTEXT_API.api.contexts].request(d,f=>{r.set(o,l.key,f)})}return u(o[l.key]??(l.key in globalThis?globalThis[l.key]:void 0))},has:(l,a,u)=>u(!0)});let c={scope:o,abortController:s,bindings:new Map};return S(t).set("data-binding",c),c}function Rr(...i){for(let t of i){let e=t.nodeName==="#text"?t.parentNode:t,{bindings:r,abortController:n}=S(e).get("data-binding")||{};if(!r?.has(t))return;r.get(t).state.dispose(),r.get(t).signals?.forEach(o=>o.abort()),r.delete(t),r.size||(n.abort(),S(e).delete("data-binding"))}}async function ji(i,...t){let e=this,r=o=>{let s=i.tokens.tagStart.split("").map(p=>`\\${p}`).join(""),c=i.tokens.tagEnd.split("").map(p=>`\\${p}`).join(""),l=i.tokens.stateStart.split("").map(p=>p===" "?"(?:\\s+)?":`\\${p}`).join(""),a=i.tokens.stateEnd.split("").map(p=>`\\${p}`).join(""),u=`^${s}(.*?)(?:${l}(\\d+)${a}(?:\\s+)?)?${c}$`,[,d,f]=o.match(new RegExp(u));return{raw:o,expr:d,span:parseInt(f??0)}},n=t.reduce((o,s)=>{if(s.isBound)return o;let c=r(s.nodeValue),l=s;if(c.span){if(l=s.nextSibling,l?.nodeName!=="#text"||l.nodeValue.length<c.span)return o;l.nodeValue.length>c.span&&l.splitText(c.span)}else l=s.ownerDocument.createTextNode(""),s.after(l);l.isBound=!0;let a=s;return e.webqit.env!=="server"&&(a.remove(),a=null),o.concat({textNode:l,template:c,anchorNode:a})},[]);for(let{textNode:o,template:s,anchorNode:c}of n){let l=ki(i,s.expr),{scope:a,bindings:u}=Mr.call(this,i,o.parentNode);Object.defineProperty(o,"$oohtml_internal_databinding_anchorNode",{value:c,configurable:!0}),u.set(o,{state:await(await l.bind(o,a)).execute()})}}var Ye=new Map;function ki(i,t){if(Ye.has(t))return Ye.get(t);let e=`let content = ((${t}) ?? '') + '';`;e+="$assign__(this, 'nodeValue', content);",e+=`if ( this.$oohtml_internal_databinding_anchorNode ) { $assign__(this.$oohtml_internal_databinding_anchorNode, 'nodeValue', "${i.tokens.tagStart}${Tt(t)}${i.tokens.stateStart}" + content.length + "${i.tokens.stateEnd} ${i.tokens.tagEnd}"); }`;let{webqit:{QuantumModule:r}}=this,n=new r(e);return Ye.set(t,n),n}async function Ni(i,...t){for(let e of t){let r=Di(i,e.getAttribute(i.attr.render)),{scope:n,bindings:o}=Mr.call(this,i,e),s=[];Object.defineProperty(e,"$oohtml_internal_databinding_signals",{value:s,configurable:!0}),o.set(e,{signals:s,state:await(await r.bind(e,n)).execute()})}}var Ze=new Map;function Di(i,t){if(Ze.has(t))return Ze.get(t);let e={},r=$t(t,";").map(s=>{let[c,l]=$t(s,":").map(p=>p.trim()),a=c[0],u=c.slice(1).trim(),d=`(${l})`,f=`(${d} ?? '')`;if(a==="&")return u.startsWith("--")?`$exec__(this.style, 'setProperty', "${Tt(u)}", ${f});`:`$assign__(this.style, "${Tt(u)}", ${f});`;if(a==="%")return`$exec__(this.classList, 'toggle', "${Tt(u)}", !!${d});`;if(a==="~")return u.startsWith("?")?`$exec__(this, 'toggleAttribute', "${Tt(u.substring(1).trim())}", !!${d});`:`$exec__(this, 'setAttribute', "${Tt(u)}", ${f});`;if(a==="@"){if(e[u])throw new Error(`Duplicate binding: ${c}.`);if(e[u]=!0,u==="text")return`$assign__(this, 'textContent', ${f});`;if(u==="html")return`$exec__(this, 'setHTML', ${f});`;if(u==="items"){let[p,g]=$t(l,"/");if(!g)throw new Error(`Invalid ${a}items spec: ${s}; no import specifier.`);let[y,v,h,b]=p.trim().match(/(.*?[\)\s+])(of|in)([\(\{\[\s+].*)/i)||[];if(!y)throw new Error(`Invalid ${a}items spec: ${s}.`);if(v.startsWith("(")?v=v.trim().slice(1,-1).split(",").map(_=>_.trim()):v=[v],v.length>(h==="in"?3:2))throw new Error(`Invalid ${a}items spec: ${s}.`);let O=h==="in"?v[2]:v[1]||"$index__";return`
21
21
  let $iteratee__ = ${b};
22
22
  let $import__ = this.${i.HTML_IMPORTS.api.import}( ${g.trim()}, true );
23
23
  this.$oohtml_internal_databinding_signals?.push( $import__ );