@spearwolf/shadow-objects 0.2.0 → 0.3.0

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.
Files changed (2) hide show
  1. package/bundle.js +3 -3
  2. package/package.json +3 -3
package/bundle.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*!
2
2
  @file @spearwolf/shadow-objects - the slightly different component framework
3
3
  @author Wolfger Schramm <wolfger@spearwolf.de>
4
- @version 0.2.0+bundle.20240804
4
+ @version 0.3.0+bundle.20240804
5
5
 
6
6
  Copyright 2024 Wolfger Schramm
7
7
 
@@ -18,13 +18,13 @@ See the License for the specific language governing permissions and
18
18
  limitations under the License.
19
19
 
20
20
  */
21
- import{beQuiet as Ct,createEffect as Qe,createSignal as Ce}from"@spearwolf/signalize";var b;(function(i){i[i.StructuralChanges=1]="StructuralChanges",i[i.ContentUpdates=2]="ContentUpdates",i[i.Removal=3]="Removal"})(b||(b={}));var p;(function(i){i[i.CreateEntities=1]="CreateEntities",i[i.DestroyEntities=2]="DestroyEntities",i[i.SetParent=3]="SetParent",i[i.UpdateOrder=4]="UpdateOrder",i[i.ChangeProperties=5]="ChangeProperties",i[i.ChangeToken=6]="ChangeToken",i[i.SendEvents=7]="SendEvents"})(p||(p={}));var M=Symbol.for("ShadowEntsGlobalNS"),S="#void",Re="contextLost",Me="configure",je="changeTrail",$e="destroy",Ne="loaded",Le="appliedChangeTrail",Fe="importedModule",De="destroyed",L="messageToView",We=16e3,Ie=16e3,Ue=4e3,Ve=1e3,ve="shadowObjects";function ze(i,e){i.indexOf(e)===-1&&i.push(e)}function be(i,e){let t=i.indexOf(e);t!==-1&&i.splice(t,1),i.push(e)}function A(i,e){let t=i.indexOf(e);t!==-1&&i.splice(t,1)}var j=i=>typeof i=="string"?i.trim()||M:typeof i=="symbol"?i:M;var W=class{#e;get uuid(){return this.#e}#t=0;constructor(e){this.#e=e}#r=!0;#i=0;#s=0;hasChanges(){return this.#t>0}get isNew(){return this.#r}get isCreated(){return this.#i>0&&this.#i>this.#s}get isDestroyed(){return this.#s>0&&this.#s>=this.#i}#n=S;#o;#a=0;#l;#u;#h;create(e=S,t,r=0){this.#t++,this.#i++,this.#l=e,this.#u=t,this.#h=r||void 0}destroy(){this.#s++,this.#t++}clear(){this.#t=0,this.#r=!1,this.#l=void 0,this.#u=void 0,this.#h=void 0,this.#d.clear(),this.#y.length=0,this.#p.length=0,this.#f.clear()}changeToken(e){e===this.#n?this.#l=void 0:(this.#l=e,this.#t++)}setParent(e){e===this.#o?this.#u=void 0:(this.#u=e??null,this.#t++)}changeOrder(e){e===this.#a?this.#h=void 0:(this.#h=e,this.#t++)}#c=new Map;#d=new Map;#y=[];changeProperty(e,t,r){let s=this.#c.get(e);r==null&&t!==s||r!=null&&!r(t,s)?(this.#d.set(e,t),be(this.#y,e),this.#t++):(this.#d.delete(e),A(this.#y,e))}removeProperty(e){let t=this.#c.has(e);this.#d.has(e)?(this.#d.delete(e),t||A(this.#y,e)):t&&(be(this.#y,e),this.#t++)}#p=[];#f=new Set;createEvent(e,t,r){this.#p.push({type:e,data:t}),r?.forEach(s=>this.#f.add(s)),this.#t++}transferEventsTo(e){this.#p.length>0&&(e.#p.push(...this.#p),this.#p.length=0),this.#f.size>0&&(e.#f=new Set([...e.#f,...this.#f]),this.#f.clear())}buildChangeTrail(e,t){let{isNew:r,isCreated:s,isDestroyed:n}=this;if(!(r&&n))switch(t){case b.StructuralChanges:r?e.push(this.makeCreateEntityChange()):n||(this.#u!==void 0&&this.#u!==this.#o?e.push(this.makeSetParentChange()):this.#h!==void 0&&this.#h!==this.#a&&e.push(this.makeUpdateOrderChange()),this.#l!==void 0&&this.#l!==this.#n&&e.push(this.makeChangeToken()));break;case b.ContentUpdates:!r&&s&&this.#y.length>0&&e.push(this.makeChangePropertyChange()),this.#p.length>0&&e.push(this.makeEvents());break;case b.Removal:n&&e.push(this.makeDestroyEntityChange());break}}makeEvents(){let e={type:p.SendEvents,uuid:this.#e,events:this.#p.slice(0)};return this.#f.size>0&&(e.transferables=Array.from(this.#f)),e}makeCreateEntityChange(){let e={type:p.CreateEntities,uuid:this.#e,token:this.#l};return this.#n=this.#l,this.#u!==void 0&&(e.parentUuid=this.#o=this.#u),this.#d.size>0&&(e.properties=Array.from(this.#d.entries()).filter(([,t])=>t!==void 0),e.properties.forEach(([t,r])=>this.#c.set(t,r))),this.#h!==void 0&&this.#h!==this.#a&&(e.order=this.#a=this.#h),e}makeDestroyEntityChange(){return{type:p.DestroyEntities,uuid:this.#e}}makeSetParentChange(){this.#o=this.#u??void 0;let e={type:p.SetParent,uuid:this.#e,parentUuid:this.#o};return this.#h!==void 0&&this.#h!==this.#a&&(e.order=this.#a=this.#h),e}makeUpdateOrderChange(){return this.#a=this.#h??0,{type:p.UpdateOrder,uuid:this.#e,order:this.#a}}makeChangeToken(){return this.#n=this.#l??S,{type:p.ChangeToken,uuid:this.#e,token:this.#n}}makeChangePropertyChange(){let e=this.#y.map(t=>{if(this.#d.has(t)){let r=this.#d.get(t);return this.#c.set(t,r),[t,r]}else return this.#c.delete(t),[t,void 0]});return{type:p.ChangeProperties,uuid:this.#e,properties:e}}};var qe=i=>{if(!(i===void 0||i.length===0))return i.filter(e=>e.length===1||e[1]!==void 0)},we=(i,e)=>{if(i===e||e===void 0)return i;if(i===void 0)return qe(e);for(let[t,r]of e){let s=i.find(([n])=>n===t);s===void 0?i.push([t,r]):s[1]=r}return qe(i)};var G=class{#e=new Map;get[Symbol.iterator](){return this.#e.entries.bind(this.#e)}clear(){this.#e.clear()}isEmpty(){return this.#e.size===0}hasComponentState(e){return this.#e.has(e)}getComponentState(e){return this.#e.get(e)}write(e){for(let t of e)if(t.type===p.CreateEntities)this.createEntity(t);else if(this.#e.has(t.uuid))switch(t.type){case p.DestroyEntities:this.destroyEntity(t);break;case p.SetParent:this.setParent(t);break;case p.UpdateOrder:this.updateOrder(t);break;case p.ChangeToken:this.changeToken(t);break;case p.ChangeProperties:this.changeProperties(t);break}}changeProperties({uuid:e,properties:t}){let r=this.getComponentState(e);r.properties=we(r.properties,t)}changeToken({uuid:e,token:t}){this.getComponentState(e).token=t||S}updateOrder({uuid:e,order:t}){this.getComponentState(e).order=t??0}setParent({uuid:e,parentUuid:t,order:r}){let s=this.getComponentState(e);s.parentUuid=t,s.order=r??0}destroyEntity({uuid:e}){this.#e.delete(e)}createEntity({uuid:e,token:t,parentUuid:r,order:s,properties:n}){this.#e.set(e,{token:t||S,parentUuid:r,order:s??0,properties:we(void 0,n)})}};var w=class i{static getContextsMap(){return globalThis.__shadowEntsContexts==null&&(globalThis.__shadowEntsContexts=new Map),globalThis.__shadowEntsContexts}static get(e){let t=j(e),r=i.getContextsMap();return r.has(t)?r.get(t):new i(t)}#e=new Map;#t=[];#r=new G;constructor(e=M){let t=j(e),r=i.getContextsMap();if(r.has(t))return r.get(t);this.ns=t,r.set(t,this)}addComponent(e){let t;this.#e.has(e.uuid)?(t=this.#e.get(e.uuid),t.component=e,t.children=[]):(t={component:e,children:[],changes:new W(e.uuid),propIsEqual:void 0},this.#e.set(e.uuid,t)),t.changes.create(e.token,e.parent?.uuid,e.order),e.parent?(this.addToChildren(e.parent,e),t.changes.setParent(e.parent.uuid)):this.#n(e,this.#t),this.#o=void 0}hasComponent(e){return this.#e.has(e.uuid)}hasComponents(){return this.#e.size>0}isRootComponent(e){return this.#t.includes(e.uuid)}destroyComponent(e){if(this.hasComponent(e)){let t=this.#e.get(e.uuid);t.children.slice(0).forEach(r=>this.#e.get(r)?.component.removeFromParent()),t.changes.destroy(),this.#o=void 0}}getChildren(e){return this.#e.get(e.uuid)?.children.map(t=>this.#e.get(t).component)??[]}removeFromParent(e,t){if(this.hasComponent(t)){let r=this.#e.get(e),s=this.#e.get(t.uuid),n=s.children.indexOf(e);n!==-1&&(s.children.splice(n,1),r.changes.setParent(void 0)),this.#n(r.component,this.#t),this.#o=void 0}}changeToken(e,t){this.#e.get(e.uuid)?.changes.changeToken(t)}isChildOf(e,t){return this.hasComponent(t)?this.#e.get(t.uuid).children.includes(e.uuid):!1}addToChildren(e,t){let r=this.#e.get(e.uuid);if(r)this.#n(t,r.children),this.#e.get(t.uuid)?.changes.setParent(e.uuid),A(this.#t,t.uuid),this.#o=void 0;else throw new Error(`the view component ${e.uuid} cannot have a child added to it because the component do not exist!`)}removeSubTree(e){let t=this.#e.get(e);t&&(t.children.slice(0).forEach(r=>this.removeSubTree(r)),this.destroyComponent(t.component),this.#i(e))}setProperty(e,t,r,s){let n=this.#e.get(e.uuid);return n!=null?(s!=null?(n.propIsEqual??=new Map,n.propIsEqual.set(t,s)):n.propIsEqual?.has(t)&&n.propIsEqual.delete(t),n.changes.changeProperty(t,r,s)):!1}removeProperty(e,t){this.#e.get(e.uuid)?.changes.removeProperty(t)}changeOrder(e){if(e.parent){let t=this.#e.get(e.parent.uuid);A(t.children,e.uuid),this.#n(e,t.children)}else A(this.#t,e.uuid),this.#n(e,this.#t);this.#e.get(e.uuid)?.changes.changeOrder(e.order),this.#o=void 0}traverseLevelOrderBFS(){return this.#a().map(e=>e.component)}dispatchShadowObjectsEvent(e,t,r,s){this.#e.get(e.uuid)?.changes.createEvent(t,r,s)}broadcastEvent(e,t=void 0){for(let r of this.traverseLevelOrderBFS())r.dispatchEvent(e,t,!1)}dispatchMessage(e,t,r=void 0,s=!1){this.#e.get(e)?.component.dispatchEvent(t,r,s)}buildChangeTrails(e=!0){let t=[];if(!this.hasComponents())return t;let r=this.#s();for(let s of r)s.buildChangeTrail(t,b.StructuralChanges);for(let s of r)s.buildChangeTrail(t,b.ContentUpdates);for(let s of r)s.buildChangeTrail(t,b.Removal),(s.isDestroyed||s.isNew&&!s.isCreated)&&this.#i(s.uuid),e&&s.clear();return this.#r.write(t),t}reCreateChanges(){if(!this.#r.isEmpty()){this.buildChangeTrails(!1);for(let[e,t]of this.#r){let r=this.#e.get(e);if(r){let s=new W(e);if(s.create(t.token,t.parentUuid,t.order),t.properties)for(let[n,o]of t.properties)s.changeProperty(n,o,r.propIsEqual?.get(n));r.changes.transferEventsTo(s),r.changes.clear(),r.changes=s}}this.#r.clear(),this.broadcastEvent(Re)}}clear(){if(this.#o=void 0,this.#r.clear(),this.#t.slice(0).forEach(e=>this.removeSubTree(e)),this.#t.length!==0)throw new Error("component-context panic: #rootComponents is not empty!");if(this.#e.size!==0)throw new Error("component-context panic: #components is not empty!")}#i(e){this.#e.has(e)&&(this.#e.delete(e),A(this.#t,e),this.#o=void 0)}#s(){return this.#a().filter(e=>e.changes.hasChanges()).map(e=>e.changes)}#n(e,t){if(t.length===0){t.push(e.uuid);return}if(t.includes(e.uuid))return;let r=t.length,s=new Array(r);if(s[0]=this.#e.get(t[0]).component,e.order<s[0].order){t.unshift(e.uuid);return}if(r===1){t.push(e.uuid);return}let n=r-1;if(s[n]=this.#e.get(t[n]).component,e.order>=s[n].order){t.push(e.uuid);return}if(r===2){t.splice(1,0,e.uuid);return}for(let o=n-1;o>=1;o--)if(s[o]=this.#e.get(t[o]).component,e.order>=s[o].order){t.splice(o+1,0,e.uuid);return}}#o;#a(){if(this.#o)return this.#o;let e=new Map,t=(r,s)=>{let n=this.#e.get(r);if(n!=null){e.has(s)?e.get(s).push(n):e.set(s,[n]);for(let o of n.children)t(o,s+1)}};return this.#t.forEach(r=>t(r,0)),this.#o=Array.from(e.entries()).sort((r,s)=>r[0]-s[0]).map(([,r])=>r).flat(),this.#o}};function T(i,e,t,r,s,n){function o(D){if(D!==void 0&&typeof D!="function")throw new TypeError("Function expected");return D}for(var h=r.kind,c=h==="getter"?"get":h==="setter"?"set":"value",l=!e&&i?r.static?i:i.prototype:null,u=e||(l?Object.getOwnPropertyDescriptor(l,r.name):{}),f,y=!1,N=t.length-1;N>=0;N--){var a={};for(var d in r)a[d]=d==="access"?{}:r[d];for(var d in r.access)a.access[d]=r.access[d];a.addInitializer=function(D){if(y)throw new TypeError("Cannot add initializers after decoration has completed");n.push(o(D||null))};var m=(0,t[N])(h==="accessor"?{get:u.get,set:u.set}:u[c],a);if(h==="accessor"){if(m===void 0)continue;if(m===null||typeof m!="object")throw new TypeError("Object expected");(f=o(m.get))&&(u.get=f),(f=o(m.set))&&(u.set=f),(f=o(m.init))&&s.unshift(f)}else(f=o(m))&&(h==="field"?s.unshift(f):u[c]=f)}l&&Object.defineProperty(l,r.name,u),y=!0}function v(i,e,t){for(var r=arguments.length>2,s=0;s<e.length;s++)t=r?e[s].call(i,t):e[s].call(i);return r?t:void 0}import{Priority as dt,emit as Ee,on as ft,onceAsync as Be,retain as pt,retainClear as yt}from"@spearwolf/eventize";import{createEffect as mt,createSignal as gt}from"@spearwolf/signalize";import{signal as He,signalReader as Ge}from"@spearwolf/signalize/decorators";var E=(()=>{var i;let e,t=[],r=[],s,n=[],o=[],h,c=[],l=[],u,f=[],y=[];return class x{static{let a=typeof Symbol=="function"&&Symbol.metadata?Object.create(null):void 0;e=[He()],s=[Ge()],h=[He()],u=[Ge()],T(this,null,e,{kind:"accessor",name:"viewReady",static:!1,private:!1,access:{has:d=>"viewReady"in d,get:d=>d.viewReady,set:(d,m)=>{d.viewReady=m}},metadata:a},t,r),T(this,null,s,{kind:"accessor",name:"viewReady$",static:!1,private:!1,access:{has:d=>"viewReady$"in d,get:d=>d.viewReady$,set:(d,m)=>{d.viewReady$=m}},metadata:a},n,o),T(this,null,h,{kind:"accessor",name:"proxyReady",static:!1,private:!1,access:{has:d=>"proxyReady"in d,get:d=>d.proxyReady,set:(d,m)=>{d.proxyReady=m}},metadata:a},c,l),T(this,null,u,{kind:"accessor",name:"proxyReady$",static:!1,private:!1,access:{has:d=>"proxyReady$"in d,get:d=>d.proxyReady$,set:(d,m)=>{d.proxyReady$=m}},metadata:a},f,y),a&&Object.defineProperty(this,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:a})}static{this.AfterSync="afterSync"}static{this.ContextLost="contextLost"}static{this.ContextCreated="contextCreated"}static get(a){if(a!=null)return globalThis.__shadowEnvs?.get(a)}#e;#t;#r;#i;#s;#n;#o;get viewReady(){return this.#o}set viewReady(a){this.#o=a}#a;get viewReady$(){return this.#a}set viewReady$(a){this.#a=a}#l;get proxyReady(){return this.#l}set proxyReady(a){this.#l=a}#u;get proxyReady$(){return this.#u}set proxyReady$(a){this.#u=a}constructor(){this.#r=!1,this.#i=!1,this.#s=!1,this.ns$=gt(),this.#o=v(this,t,!1),this.#a=(v(this,r),v(this,n,void 0)),this.#l=(v(this,o),v(this,c,!1)),this.#u=(v(this,l),v(this,f,void 0)),this.ready=(v(this,y),()=>this.isReady?Promise.resolve(this):Be(this,x.ContextCreated)),this.#h=()=>{this.#r&&this.#c()},pt(this,x.ContextCreated),ft(this,x.ContextLost,dt.AAA,()=>{yt(this,x.ContextCreated)}),mt(()=>{if(this.viewReady&&this.proxyReady)return this.view.reCreateChanges(),Ee(this,x.ContextCreated,this),this.#i&&(this.#i=!1,this.#c()),()=>{Ee(this,x.ContextLost,this)}},[this.viewReady$,this.proxyReady$])}get view(){return this.#e}set view(a){a!==this.#e&&(this.#e&&this.#e.ns&&globalThis.__shadowEnvs&&globalThis.__shadowEnvs.delete(this.#e.ns),this.#e=a??void 0,this.#e&&this.#e.ns&&(globalThis.__shadowEnvs??=new Map,globalThis.__shadowEnvs.has(this.#e.ns)&&globalThis.__shadowEnvs.get(this.#e.ns)!==this&&console.warn("ShadowEnv: overwrite a namespace already in use",this.#e.ns,globalThis.__shadowEnvs.get(this.#e.ns)),globalThis.__shadowEnvs.set(this.#e.ns,this)),this.viewReady=!!a)}get envProxy(){return this.#t}set envProxy(a){if(a!==this.#t){let d=this.#t;this.#t=a??void 0,this.#t&&(this.#t.onMessageToView=this.#d.bind(this)),d&&d.destroy(),this.proxyReady=!1,a?.start().then(()=>{this.proxyReady=!0}).catch(m=>{console.error("ShadowEnv: failed to start envProxy",m),this.proxyReady=!1})}}get isReady(){return!!(this.#e&&this.#t&&this.proxyReady)}sync(){if(!this.isReady){this.#i=!0;return}this.#r||(this.#r=!0,queueMicrotask(this.#h))}syncWait(){return this.#s=!0,this.sync(),this.#n?this.#n:(this.#n=Be(this,x.AfterSync).then(a=>(this.#n=void 0,a)),this.#n)}destroy(){let a=this.#e?.ns;this.envProxy?.destroy(),this.envProxy=void 0,this.view=void 0,a&&globalThis.__shadowEnvs.has(a)&&globalThis.__shadowEnvs.get(a)===this&&globalThis.__shadowEnvs.delete(a)}#h;async#c(){if(this.#r=!1,this.isReady){let a=this.view.buildChangeTrails();if(a.length>0)try{let d=this.#s;this.#s=!1,await this.envProxy.applyChangeTrail(a,d)}catch(d){console.error("ShadowEnv: failed to apply change trail",d)}finally{Ee(this,x.AfterSync,a)}}}#d(a){console.debug("ShadowEnv: onMessageToView",a.type,a.data),this.view?.dispatchMessage(a.uuid,a.type,a.data,a.traverseChildren)}}})();import{emit as bt,eventize as wt}from"@spearwolf/eventize";var g=["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"],vt=()=>{let i=Math.random()*4294967295|0,e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,r=Math.random()*4294967295|0;return(g[i&255]+g[i>>8&255]+g[i>>16&255]+g[i>>24&255]+"-"+g[e&255]+g[e>>8&255]+"-"+g[e>>16&15|64]+g[e>>24&255]+"-"+g[t&63|128]+g[t>>8&255]+"-"+g[t>>16&255]+g[t>>24&255]+g[r&255]+g[r>>8&255]+g[r>>16&255]+g[r>>24&255]).toLowerCase()},Ye=()=>globalThis?.crypto?.randomUUID?.()??vt();var I=class extends Error{constructor(e){super(e),this.name="ViewComponentError"}},Y=class i{#e;#t;#r;#i;#s=0;get uuid(){return this.#e}get token(){return this.#t}set token(e){e??=S,e!==this.#t&&(this.#t=e,this.#r?.changeToken(this,e))}get parent(){return this.#i}set parent(e){if(e){if(e.#r!==this.#r)throw new I("cannot set parent from different context");e.addChild(this)}else this.removeFromParent()}get context(){return this.#r}set context(e){this.#r!=e&&(this.#r&&this.destroy(),this.#r=e,e&&e.addComponent(this))}get order(){return this.#s}set order(e){let t=this.#s;this.#s=e??0,t!==this.#s&&this.#r.changeOrder(this)}constructor(e,t){wt(this),t instanceof i&&(t={parent:t}),this.#e=t?.uuid??Ye(),this.#t=e,this.#s=t?.order??0,this.#i=t?.parent;let r=t?.context??w.get();if(this.#i&&this.#i.#r!==r)throw new I("cannot set parent from different context");this.context=r}isChildOf(e){return this.#i===e}removeFromParent(){this.#i&&(this.#r?.removeFromParent(this.uuid,this.#i),this.#i=void 0)}addChild(e){if(e.#r!==this.#r)throw new I("cannot add a child from another context");e.isChildOf(this)||(e.removeFromParent(),e.#i=this,this.#r.addToChildren(this,e))}setProperty(e,t,r){this.#r.setProperty(this,e,t,r)}removeProperty(e){this.#r.removeProperty(this,e)}dispatchShadowObjectsEvent(e,t,r){this.#r.dispatchShadowObjectsEvent(this,e,t,r)}dispatchEvent(e,t,r){if(bt(this,e,t),r)for(let s of this.#r.getChildren(this))s.dispatchEvent(e,t,r)}destroy(){this.removeFromParent(),this.#r?.destroyComponent(this),this.#r=void 0}};import{createSignal as Et}from"@spearwolf/signalize";var J="shaeRequestEntParent",K="shaeReRequestEntParent",Je="shae-worker",X="shae-ent",Ke="shae-prop",O="token",P="ns",Z="local",Xe="no-autostart",Q="no-structured-clone",C="auto-sync",ee="src",te="name",re="value",se="type",ie="no-trim";var U=new Set(["on","true","yes","local","1"]);var Ze=i=>j(i.getAttribute(P)),V=(i,e)=>{if(i.hasAttribute(e)){let t=i.getAttribute(e)?.trim()?.toLowerCase()||"1";return U.has(t)}return!1};var _=class extends HTMLElement{static{this.observedAttributes=[P]}get ns(){return this.ns$.value}set ns(e){typeof e=="symbol"?this.ns$.set(e):this.ns$.set(j(e))}constructor(){super(),this.isShaeElement=!0,this.ns$=Et(M),this.#e=!1,this.ns$.onChange(e=>{typeof e=="string"&&e.length>0?this.getAttribute(P)!==e&&this.setAttribute(P,e):this.removeAttribute(P)})}connectedCallback(){this.#t()}attributeChangedCallback(e){e===P&&this.#t()}#e;syncShadowObjects(){this.#e||(this.#e=!0,queueMicrotask(()=>{this.#e=!1,E.get(this.ns)?.sync()}))}#t(){this.ns$.set(Ze(this))}};var ne=class extends _{static{this.observedAttributes=[..._.observedAttributes,O]}get componentContext(){return this.componentContext$.value}get viewComponent(){return this.viewComponent$.value}get uuid(){return this.viewComponent?.uuid}get token(){return this.token$.value}set token(e){this.token$.set(e)}constructor(){super(),this.isShaeEntElement=!0,this.componentContext$=Ce(),this.viewComponent$=Ce(),this.token$=Ce(),this.#s=!0,this.#u=()=>{let e=this.findShadowRootHost();e!=null&&this.dispatchEvent(new CustomEvent(K,{bubbles:!0,composed:!0,detail:{requester:this,shadowRootHost:e}}))},this.#h=e=>{let t=e.detail?.requester;if(t===this||!t?.isShaeEntElement||t.ns!==this.ns)return;let r=e.detail?.shadowRootHost;r&&this.#a?.has(r)&&this.#n()},this.#c=e=>{let t=e.detail?.requester;t!==this&&t?.isShaeEntElement&&t.ns===this.ns&&(e.stopPropagation(),t.#l(this))},this.#d(),this.token$.onChange(e=>{e==null?this.removeAttribute(O):this.getAttribute(O)!==e&&this.setAttribute(O,e)}),this.ns$.onChange(e=>{this.componentContext$.set(w.get(e)),this.isConnected&&this.#n()}),Qe(()=>{let e=this.viewComponent$.get();if(e){let t=e.context?.ns;return()=>{e.destroy(),t&&t!==this.ns?E.get(t)?.sync():this.syncShadowObjects()}}}),this.token$.onChange(e=>{let t=this.viewComponent$.value;t&&(t.token=e,this.syncShadowObjects())})}#e;#t(){this.#e?.();let e=this.componentContext$.onChange(t=>{let r=this.token$.value,s=this.viewComponent$.value;s?s.context=t:t&&(s=new Y(r,{context:t}),this.viewComponent$.set(s)),this.syncShadowObjects()});this.#e=()=>{e()}}#r(){this.#e?.(),this.#e=void 0}#i;#s;findShadowRootHost(){if(this.#s){this.#s=!1;let e=this;for(;e;){if(e.parentElement==null){let t=e.parentNode;t&&(this.#i=t.host);break}e=e.parentElement}}return this.#i}connectedCallback(){this.#s=!0,this.addEventListener("slotchange",this.#u,{capture:!1,passive:!1}),this.addEventListener(J,this.#c,{capture:!1,passive:!1}),this.#t(),Ct(()=>this.#d()),super.connectedCallback(),this.componentContext==null&&this.componentContext$.set(w.get(this.ns)),this.#n(),this.syncShadowObjects()}attributeChangedCallback(e){super.attributeChangedCallback(e),e===O&&this.#d()}disconnectedCallback(){this.#s=!0,this.removeEventListener("slotchange",this.#u,{capture:!1}),this.removeEventListener(J,this.#c,{capture:!1}),this.#l(void 0),this.componentContext$.set(void 0),this.syncShadowObjects(),this.#r()}#n(){this.dispatchEvent(new CustomEvent(J,{bubbles:!0,composed:!0,detail:{requester:this}}))}#o;#a;#l(e){if(this.entParentNode!==e){if(this.entParentNode&&this.entParentNode.removeEventListener(K,this.#h,{capture:!1}),this.entParentNode=e,this.entParentNode&&this.entParentNode.addEventListener(K,this.#h,{capture:!1,passive:!1}),this.#a=void 0,e){let t=[],r=this.parentElement;for(;r&&r!==e;)t.push(r),r.parentElement==null&&r.parentNode?r=r.parentNode.host:r=r.parentElement;t.length>0&&(this.#a=new WeakSet(t))}if(this.#o?.(),this.#o=void 0,e){let[,t]=Qe(()=>{let r=this.viewComponent$.get();if(r){let s=e.viewComponent$.get();r.parent=s&&s.context===r.context?s:void 0,r.parent==null&&queueMicrotask(()=>{this.#n()}),this.syncShadowObjects()}});this.#o=t}else{let t=this.viewComponent;t.parent&&(t.parent=void 0,this.syncShadowObjects())}}}#u;#h;#c;#d(){if(this.hasAttribute(O)){let e=this.getAttribute(O)?.trim()||void 0;this.token$.set(e)}}};customElements.define(X,ne);import{batch as et,connect as St,createEffect as tt,createSignal as $}from"@spearwolf/signalize";var xt=i=>{let e=i.parentElement;for(;e;){if(e.isShaeEntElement)return e;e=e.parentElement}},kt=new Set(["string","text","number","bigint","float","int","integer","hex","hexadecimal","oct","octal","bin","binary","bool","boolean","[]","text[]","string[]","number[]","float[]","int[]","integer[]","hex[]","hexadecimal[]","oct[]","octal[]","bin[]","binary[]","bool[]","boolean[]","int8array","uint8array","uint8clampedarray","int16array","uint16array","int32array","uint32array","float32array","float64array","bigint64array","biguint64array","json"]),oe=class extends HTMLElement{static{this.observedAttributes=[te,re,se,ie]}get name(){return this.name$.value}get value(){return this.valueOut$.value}set value(e){this.valueIn$.set(e)}get shouldTrim(){return this.shouldTrim$.value}get entNode(){return this.entNode$.value}set entNode(e){this.entNode$.set(e)}get viewComponent(){return this.viewComponent$.value}constructor(){super(),this.isShaeEntElement=!0,this.entNode$=$(),this.viewComponent$=$(),this.name$=$(),this.valueIn$=$(),this.valueOut$=$(),this.type$=$(),this.shouldTrim$=$(!0),this.#e=()=>{this.entNode$.set(xt(this))},this.#t=()=>{queueMicrotask(()=>{this.isConnected||this.entNode$.set(void 0)})},this.#r=()=>{this.name$.set(this.getAttribute(te)?.trim()??void 0)},this.#i=()=>{this.valueIn$.set(this.getAttribute(re))},this.#s=()=>{let e=this.getAttribute(se)?.trim().toLowerCase();e&&!kt.has(e)&&(console.warn(`[shae-prop:"${this.name}"] unknown type "${e}"`,{shaeProp:this}),e=void 0),this.type$.set(e)},this.#n=()=>{this.shouldTrim$.set(!V(this,ie))},this.entNode$.onChange(e=>{if(e){let t=St(e.viewComponent$,this.viewComponent$);return()=>{t.destroy()}}else this.viewComponent$.set(void 0)}),tt(()=>{let e=this.viewComponent$.get();if(e){let t=this.name$.get();if(t){let r=this.valueOut$.get();e.setProperty(t,r),this.isConnected&&this.entNode?.syncShadowObjects()}}}),tt(()=>{let e=this.type$.get(),t=this.shouldTrim$.get(),r=this.valueIn$.get();if(t&&typeof r=="string"&&(r=r.trim()),r=r||void 0,r!=null&&typeof r=="string"&&e)switch(e){case"string":case"text":break;case"number":r=Number(r);break;case"bigint":r=BigInt(r);break;case"float":r=parseFloat(r);break;case"int":case"integer":r=parseInt(r,10);break;case"hex":case"hexadecimal":r=parseInt(r,16);break;case"oct":case"octal":r=parseInt(r,8);break;case"bin":case"binary":r=parseInt(r,2);break;case"bool":case"boolean":r=U.has(r.toLowerCase());break;case"[]":case"text[]":case"string[]":r=r.split(/\W+/);break;case"number[]":r=r.split(/\W+/).map(s=>Number(s));break;case"float[]":r=r.split(/\W+/).map(s=>parseFloat(s));break;case"int[]":case"integer[]":r=r.split(/\W+/).map(s=>parseInt(s));break;case"hex[]":case"hexadecimal[]":r=r.split(/\W+/).map(s=>parseInt(s,16));break;case"oct[]":case"octal[]":r=r.split(/\W+/).map(s=>parseInt(s,8));break;case"bin[]":case"binary[]":r=r.split(/\W+/).map(s=>parseInt(s,2));break;case"bool[]":case"boolean[]":r=r.split(/\W+/).map(s=>U.has(s.toLowerCase()));break;case"int8array":r=new Int8Array(r.split(/\W+/).map(s=>Number(s)));break;case"uint8array":r=new Uint8Array(r.split(/\W+/).map(s=>Number(s)));break;case"uint8clampedarray":r=new Uint8ClampedArray(r.split(/\W+/).map(s=>Number(s)));break;case"int16array":r=new Int16Array(r.split(/\W+/).map(s=>Number(s)));break;case"uint16array":r=new Uint16Array(r.split(/\W+/).map(s=>Number(s)));break;case"int32array":r=new Int32Array(r.split(/\W+/).map(s=>Number(s)));break;case"uint32array":r=new Uint32Array(r.split(/\W+/).map(s=>Number(s)));break;case"float32array":r=new Float32Array(r.split(/\W+/).map(s=>Number(s)));break;case"float64array":r=new Float64Array(r.split(/\W+/).map(s=>Number(s)));break;case"bigint64array":r=new BigInt64Array(r.split(/\W+/).map(s=>BigInt(s)));break;case"biguint64array":r=new BigUint64Array(r.split(/\W+/).map(s=>BigInt(s)));break;case"json":r=JSON.parse(r);break;default:console.warn(`[shae-prop:"${this.name}"] unknown type "${e}"`,{value:r,shaeProp:this})}this.valueOut$.set(r)}),et(()=>{this.#r(),this.#i(),this.#s(),this.#n()})}connectedCallback(){et(()=>{this.#e(),this.#r(),this.#i(),this.#s(),this.#n()})}attributeChangedCallback(e){switch(e){case te:this.#r();break;case re:this.#i();break;case se:this.#s();break;case ie:this.#n();break}}disconnectedCallback(){this.#t()}#e;#t;#r;#i;#s;#n};customElements.whenDefined(X).then(()=>customElements.define(Ke,oe));import{on as ut}from"@spearwolf/eventize";import{batch as sr,createEffect as ir,createSignal as ct}from"@spearwolf/signalize";import{emit as At,eventize as Tt,getSubscriptionCount as rt,off as Ot,on as Pt}from"@spearwolf/eventize";var ae,Se=null,F=class{static{this.OnFrame=Symbol("onFrame")}#e=0;#t=0;constructor(){if(Se)return Se;Tt(this),Se=this}start(e){if(e!=null)return rt(this)===0&&this.#i(),Pt(this,ae.OnFrame,e),this.#t++,()=>{this.stop(e)}}stop(e){Ot(this,ae.OnFrame,e),rt(this)===0&&this.#s()}#r=e=>{At(this,ae.OnFrame,e),this.#i()};#i(){this.#e=requestAnimationFrame(this.#r)}#s(){cancelAnimationFrame(this.#e),this.#e=0}};ae=F;import{on as Zt}from"@spearwolf/eventize";import{emit as Ae,eventize as nt,off as Yt,on as ot,once as Jt}from"@spearwolf/eventize";import{batch as Kt,connect as Te,createEffect as Xt,createSignal as de,destroySignal as fe}from"@spearwolf/signalize";import{emit as It,off as Ut,on as it,once as Vt,Priority as zt}from"@spearwolf/eventize";import{batch as qt,createSignal as ke,destroySignals as Bt,value as Ht}from"@spearwolf/signalize";import{createSignal as _t}from"@spearwolf/signalize";var he=class{#e=new Map;keys(){return this.#e.keys()}entries(){return this.#e.entries()}clear(){for(let e of this.#e.values())e.destroy();this.#e.clear()}hasSignal(e){return this.#e.has(e)}getSignal(e){if(!this.#e.has(e)){let t=_t();return this.#e.set(e,t),t}return this.#e.get(e)}getSignalReader(e){return this.getSignal(e).get}getSignalWriter(e){return this.getSignal(e).set}};import{emit as Rt,off as Mt,retain as jt,retainClear as $t}from"@spearwolf/eventize";import{createEffect as Nt,destroySignalsAndEffects as Lt,value as Ft}from"@spearwolf/signalize";import{signal as Dt,signalReader as Wt}from"@spearwolf/signalize/decorators";var ue=(()=>{let i,e=[],t=[],r,s=[],n=[];return class le{static{let h=typeof Symbol=="function"&&Symbol.metadata?Object.create(null):void 0;i=[Dt()],r=[Wt()],T(this,null,i,{kind:"accessor",name:"value",static:!1,private:!1,access:{has:c=>"value"in c,get:c=>c.value,set:(c,l)=>{c.value=l}},metadata:h},e,t),T(this,null,r,{kind:"accessor",name:"value$",static:!1,private:!1,access:{has:c=>"value$"in c,get:c=>c.value$,set:(c,l)=>{c.value$=l}},metadata:h},s,n),h&&Object.defineProperty(this,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:h})}static{this.Value="value"}#e=[];#t;#r=v(this,e,void 0);get value(){return this.#r}set value(h){this.#r=h}#i=(v(this,t),v(this,s,void 0));get value$(){return this.#i}set value$(h){this.#i=h}constructor(){v(this,n),jt(this,le.Value),this.value$(h=>Rt(this,le.Value,h))}add(...h){for(let c of h)this.#e.push(c);this.#n()}clear(){this.#e.length=0,this.#s()}dispose(){this.clear(),Mt(this),Lt(this),$t(this,le.Value)}#s(){this.#t?.(),this.#t=void 0}#n(){this.#s();let[h,c]=Nt(()=>{for(let l of this.#e){let u=Ft(l);if(u!=null){this.value=u;return}}this.value=void 0},this.#e);this.#t=c,h()}}})();var xe="onCreate",R="onDestroy",st="onViewEvent";var ce=class{#e;#t;#r=new he;#i=new Map;#s;#n;#o=new Set;#a=[];#l=0;get kernel(){return this.#e}get uuid(){return this.#t}get order(){return this.#l}set order(e){this.#l!==e&&(this.#l=e,this.#s&&this.parent.resortChildren())}get parentUuid(){return this.#s||void 0}set parentUuid(e){this.#s!==e&&(this.removeFromParent(),this.#s=e||void 0,this.#n=e?this.#e.getEntity(e):void 0,this.#n&&this.#n.addChild(this))}get parent(){return!this.#n&&this.#s&&(this.#n=this.#e.getEntity(this.#s)),this.#n}set parent(e){this.parentUuid=e?.uuid}get hasParent(){return!!this.#s}get children(){return this.#a}constructor(e,t){this.#e=e,this.#t=t,Vt(this,R,zt.Min,this)}traverse(e){e(this);for(let t of this.#a)t.traverse(e)}onDestroy(){this.#r.clear(),Ut(this);for(let e of this.#i.values())e.unsubscribeFromPath(),e.unsubscribeFromParent?.(),e.ctxPath.dispose(),Bt(e.inherited,e.provide,e.context);this.#s=void 0,this.#n=void 0,this.#o.clear(),this.#a.length=0}addChild(e){if(this.#a.length===0){this.#o.add(e.uuid),this.#a.push(e);return}if(this.#o.has(e.uuid))throw new Error(`child with uuid: ${e.uuid} already exists! parentUuid: ${this.uuid}`);this.#o.add(e.uuid),this.#a.push(e),this.resortChildren();for(let[,t]of e.#i)e.#c(t)}resortChildren(){this.#a.sort((e,t)=>e.order-t.order)}removeChild(e){this.#o.has(e.uuid)&&(this.#o.delete(e.uuid),this.#a.splice(this.#a.indexOf(e),1))}removeFromParent(){if(this.#n){this.#n.removeChild(this),this.#n=void 0,this.#s=void 0;for(let[,e]of this.#i)e.unsubscribeFromParent&&(e.unsubscribeFromParent(),e.unsubscribeFromParent=void 0)}}dispatchMessageToView(e,t,r,s=!1){this.#e.dispatchMessageToView({uuid:this.#t,type:e,data:t,transferables:r,traverseChildren:s})}dispatchViewEvents(e){for(let{type:t,data:r}of e)It(this,st,t,r)}dispatchViewEvent(e,t){this.dispatchViewEvents([{type:e,data:t}])}#u(e){return this.#r.getSignal(e)}getPropertyReader(e){return this.#u(e).get}getPropertyWriter(e){return this.#u(e).set}setProperties(e){qt(()=>{for(let[t,r]of e)this.setProperty(t,r)})}setProperty(e,t){this.getPropertyWriter(e)(t)}getProperty(e){return Ht(this.getPropertyReader(e))}propKeys(){return Array.from(this.#r.keys())}propEntries(){return Array.from(this.#r.entries()).map(([e,t])=>[e,t.value])}hasContext(e){return this.#i.has(e)}useContext(e){return this.#h(e).context.get}provideContext(e){return this.#h(e).provide}#h(e){let t=this.#i.get(e);if(t==null){let r=ke(),s=ke(),n=ke(),o=new ue;o.add(s.get,r.get);let h=it(o,ue.Value,c=>{queueMicrotask(()=>{n.set(c)})});t={name:e,inherited:r,provide:s,context:n,ctxPath:o,unsubscribeFromPath:h},this.#i.set(e,t),this.#c(t)}return t}#c(e){this.parent&&(e.unsubscribeFromParent?.(),e.unsubscribeFromParent=it(this.parent.#h(e.name).ctxPath,ue.Value,t=>{e.inherited.set(t)}))}};var z=class{static get(e){return e??Gt}#e=new Map;#t=new Map;define(e,t){this.#e.has(e)?ze(this.#e.get(e).constructors,t):this.#e.set(e,{token:e,constructors:[t]})}appendRoute(e,t){if(this.#t.has(e)){let r=this.#t.get(e);for(let s of t)r.add(s)}else this.#t.set(e,new Set(t))}clearRoute(e){this.#t.delete(e)}findTokensByRoute(e){let t=new Set([e]),r=this.#t.has(e)?[...this.#t.get(e)]:[];for(;r.length;){let s=r.shift();t.has(s)||(t.add(s),this.#t.has(s)&&r.push(...Array.from(this.#t.get(s)).filter(n=>!t.has(n))))}return Array.from(t)}findConstructors(e){let t=this.findTokensByRoute(e),r=new Set;for(let s of t){let n=this.#e.get(s);if(n)for(let o of n.constructors)r.add(o)}return r.size>0?Array.from(r):void 0}hasToken(e){return this.#e.has(e)}hasRoute(e){return this.#t.has(e)}clear(){this.#e.clear(),this.#t.clear()}},Gt=new z;var k;(function(i){i[i.CreateAndDestroy=0]="CreateAndDestroy",i[i.JustCreate=1]="JustCreate",i[i.DestroyOnly=2]="DestroyOnly"})(k||(k={}));var at=i=>i.displayName||i.name,pe=class{#e=new Map;#t=new Set;#r;#i;#s=!0;constructor(e){nt(this),this.registry=z.get(e)}getEntity(e){let t=this.#e.get(e)?.entity;if(!t)throw new Error(`entity with uuid "${e}" not found!`);return t}hasEntity(e){return this.#e.has(e)}traverseLevelOrderBFS(e=!1){if(this.#s){let t=new Map,r=(s,n)=>{let o=this.getEntity(s);t.has(n)?t.get(n).push(o):t.set(n,[o]);for(let h of o.children)r(h.uuid,n+1)};this.#t.forEach(s=>r(s,0)),this.#r=Array.from(t.entries()).sort((s,n)=>s[0]-n[0]).map(([,s])=>s).flat(),this.#i=this.#r.slice().reverse(),this.#s=!1}return e?this.#i:this.#r}getEntityGraph(){return Array.from(this.#t).map(e=>this.getEntityGraphNode(e))}getEntityGraphNode(e){if(!this.#e.has(e))return;let{token:t,entity:r}=this.#e.get(e);return{token:t,entity:r,props:Object.fromEntries(r.propEntries()),children:r.children.map(s=>this.getEntityGraphNode(s.uuid))}}upgradeEntities(){for(let e of this.traverseLevelOrderBFS(!0))this.updateShadowObjects(e.uuid,k.DestroyOnly);for(let e of this.traverseLevelOrderBFS(!1))this.updateShadowObjects(e.uuid,k.JustCreate)}run(e){Kt(()=>{for(let t of e.changeTrail)this.parse(t)})}parse(e){switch(e.type){case p.CreateEntities:this.createEntity(e.uuid,e.token,e.parentUuid,e.order,e.properties),this.#s=!0;break;case p.DestroyEntities:this.destroyEntity(e.uuid),this.#s=!0;break;case p.SetParent:this.setParent(e.uuid,e.parentUuid,e.order),this.#s=!0;break;case p.UpdateOrder:this.updateOrder(e.uuid,e.order),this.#s=!0;break;case p.ChangeProperties:this.changeProperties(e.uuid,e.properties);break;case p.ChangeToken:this.changeToken(e.uuid,e.token);break;case p.SendEvents:this.dispatchEventsToEntity(e.uuid,e.events);break}}createEntity(e,t,r,s=0,n){let o=new ce(this,e);o.order=s;let h={token:t,entity:o,usedConstructors:new Map};this.#e.set(e,h),r&&(o.parentUuid=r),o.hasParent||this.#t.add(e),n&&o.setProperties(n),this.createShadowObjects(e)}destroyEntity(e){if(!this.#e.has(e))return;let{entity:t,usedConstructors:r}=this.#e.get(e);t.removeFromParent(),Ae(t,R,this),r.clear(),this.#e.delete(t.uuid),this.#t.delete(t.uuid)}setParent(e,t,r=0){let s=this.getEntity(e);s.parentUuid===t&&s.order===r||(s.removeFromParent(),s.order=r,s.parentUuid=t,s.hasParent?this.#t.delete(e):this.#t.add(e))}updateOrder(e,t){this.getEntity(e).order=t}dispatchEventsToEntity(e,t){this.getEntity(e)?.dispatchViewEvents(t)}changeProperties(e,t){this.getEntity(e).setProperties(t)}changeToken(e,t){if(!this.#e.has(e))return;let r=this.#e.get(e);r.token!==t&&(r.token=t,this.updateShadowObjects(e))}dispatchMessageToView(e){queueMicrotask(()=>{Ae(this,L,e)})}updateShadowObjects(e,t=k.CreateAndDestroy){let r=this.#e.get(e),s=new Set(this.registry.findConstructors(r.token)),n=t===k.CreateAndDestroy||t===k.DestroyOnly,o=t===k.CreateAndDestroy||t===k.JustCreate;if(n){for(let[h,c]of r.usedConstructors)if(!s.has(h)){r.usedConstructors.delete(h);for(let l of c)this.destroyShadowObject(l,r.entity)}}if(o)for(let h of s)r.usedConstructors.has(h)||this.constructShadowObject(h,r)}constructShadowObject(e,t){let r=new Set,s=new Set,n=new Map,o=new Map,h=new Map,c=nt(new e({entity:t.entity,provideContext(l,u,f){let y=o.get(l);if(y===void 0){y=de(u,f?{compareFn:f}:void 0),o.set(l,y);let N=Te(y,t.entity.provideContext(l));s.add(N.destroy.bind(N))}return y},useContext(l,u){let f=n.get(l);if(f===void 0){[f]=de(void 0,u?{compareFn:u}:void 0),n.set(l,f);let y=Te(t.entity.useContext(l),f);s.add(y.destroy.bind(y))}return f},useProperty(l,u){let f=h.get(l);if(f===void 0){[f]=de(void 0,u?{compareFn:u}:void 0),h.set(l,f);let y=Te(t.entity.getPropertyReader(l),f);s.add(y.destroy.bind(y))}return f},createEffect(...l){let u=Xt(...l);return s.add(u[1]),u},createSignal(...l){let u=de(...l);return s.add(()=>{fe(u)}),u},on(...l){let u=ot(...l);return s.add(u),u},onDestroy(l){r.add(l)}}));return console.debug("[Kernel] create shadow-object",at(e),{shadowObject:c,entity:t.entity}),Jt(c,R,()=>{console.debug("[Kernel] destroy shadow-object",at(e),{shadowObject:c,entity:t.entity});for(let u of r)u();for(let u of s)u();for(let u of n.values())fe(u);for(let u of h.values())fe(u);for(let[u]of o.values())fe(u);r.clear(),s.clear(),n.clear(),h.clear(),o.clear();let l=t.usedConstructors.get(e);l&&(l.delete(c),l.size===0&&t.usedConstructors.delete(e))}),t.usedConstructors.has(e)?t.usedConstructors.get(e).add(c):t.usedConstructors.set(e,new Set([c])),this.attachShadowObject(c,t.entity),c}createShadowObjects(e){let t=this.#e.get(e);this.registry.findConstructors(t.token)?.forEach(r=>{this.constructShadowObject(r,t)})}findShadowObjects(e){if(!this.#e.has(e))return[];let{usedConstructors:t}=this.#e.get(e);return Array.from(new Set(Array.from(t.values()).map(r=>Array.from(r)).flat()))}attachShadowObject(e,t){ot(t,e),typeof e[xe]=="function"&&e[xe](t)}destroyShadowObject(e,t){typeof e[R]=="function"&&e[R](t),Ae(e,R,t),Yt(t,e)}destroy(){for(let e of this.traverseLevelOrderBFS().reverse())this.destroyEntity(e.uuid)}};async function Oe(i,e,t,r=!0){if(t.has(e)){console.warn("importModule: skipping already imported module",e);return}else t.add(e);e.extends&&await Promise.all(e.extends.map(n=>Oe(i,n,t,!1)));let{registry:s}=i;if(e.define)for(let[n,o]of Object.entries(e.define))s.define(n,o);if(e.routes)for(let[n,o]of Object.entries(e.routes))s.appendRoute(n,o);await(e.initialize?.({define:(n,o)=>s.define(n,o),kernel:i,registry:s})??Promise.resolve()),r&&i.upgradeEntities()}var ye=i=>(typeof i=="string"&&(i=new URL(i,globalThis.location.href)),i.toString());function ht(i){return i.map(e=>{if(e.transferables&&e.transferables.length>0){let{transferables:t,...r}=e;return structuredClone(r,{transfer:t})}else return structuredClone(e)})}var me=class{#e;get registry(){return this.kernel.registry}constructor(e){this.#e=new Set,this.isLocalEnv=!0,this.disableStructuredClone=!1,this.kernel=new pe(e),Zt(this.kernel,L,t=>{if(this.onMessageToView!=null){let{type:r,uuid:s,traverseChildren:n}=t,o=structuredClone(t.data,{transfer:t.transferables});this.onMessageToView({type:r,uuid:s,data:o,traverseChildren:n})}})}start(){return Promise.resolve()}applyChangeTrail(e,t){let r={changeTrail:this.disableStructuredClone?e:ht(e)},s;try{this.kernel.run(r),s=Promise.resolve()}catch(n){s=Promise.reject(n)}return s}async importScript(e){let t=await import(ye(e));t[ve]&&await this.importModule(t[ve])}async importModule(e){return Oe(this.kernel,e,this.#e)}destroy(){this.kernel.destroy(),this.registry.clear(),this.#e.clear()}};import{emit as Qt,onceAsync as er,retain as tr}from"@spearwolf/eventize";function Pe(i){let e=new Blob([i],{type:"text/javascript"}),t=URL.createObjectURL(e),r=new Worker(t);return URL.revokeObjectURL(t),r}function _e(){return Pe(`var dr=Object.defineProperty;var Et=Object.getOwnPropertySymbols;var yr=Object.prototype.hasOwnProperty,pr=Object.prototype.propertyIsEnumerable;var bt=e=>{throw TypeError(e)};var gr=(e,t,r)=>t in e?dr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var St=(e,t)=>{var r={};for(var s in e)yr.call(e,s)&&t.indexOf(s)<0&&(r[s]=e[s]);if(e!=null&&Et)for(var s of Et(e))t.indexOf(s)<0&&pr.call(e,s)&&(r[s]=e[s]);return r};var d=(e,t,r)=>gr(e,typeof t!="symbol"?t+"":t,r),Ye=(e,t,r)=>t.has(e)||bt("Cannot "+r);var i=(e,t,r)=>(Ye(e,t,"read from private field"),r?r.call(e):t.get(e)),f=(e,t,r)=>t.has(e)?bt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,r),h=(e,t,r,s)=>(Ye(e,t,"write to private field"),s?s.call(e,r):t.set(e,r),r),E=(e,t,r)=>(Ye(e,t,"access private method"),r);var wt=(e,t,r,s)=>({set _(n){h(e,t,n,r)},get _(){return i(e,t,s)}});var pe="*",Ot=1,tt=2,rt=4,re=Symbol("eventize"),mr="[eventize]",qe=e=>e===pe,kt=e=>{switch(typeof e){case"string":case"symbol":return!0;default:return!1}},Pt=typeof console!="undefined",vr=Pt?console[console.warn?"warn":"log"].bind(console,mr):()=>{},Er=(e,t,r)=>(Object.defineProperty(e,t,{value:r,configurable:!0}),e),br=0,Ft=class{constructor(){d(this,"events",new Map);d(this,"eventNames",new Set)}static publish(e){e.sort((t,r)=>t.order-r.order).forEach(t=>t.emit())}add(e){Array.isArray(e)?e.forEach(t=>this.eventNames.add(t)):this.eventNames.add(e)}remove(e){Array.isArray(e)?e.forEach(t=>this.eventNames.delete(t)):this.eventNames.delete(e),this.clear(e)}clear(e){Array.isArray(e)?e.forEach(t=>this.events.delete(t)):this.events.delete(e)}retain(e,t){this.eventNames.has(e)&&this.events.set(e,{args:t,order:br++})}isKnown(e){return this.eventNames.has(e)}emit(e,t,r=[]){if(qe(e))this.eventNames.forEach(s=>this.emit(s,t,r));else if(this.events.has(e)){let{order:s,args:n}=this.events.get(e);r.push({order:s,emit:()=>t.apply(e,n)})}return r}},Ze=(e,t,r,s)=>{if(typeof t=="function"){let n=t.apply(e,r);n!=null&&(s==null||s(n))}},Sr=(e,t,r,s)=>Ze(t,t.emit,[e].concat(r),s),wr=e=>{switch(typeof e){case"function":return Ot;case"string":case"symbol":return tt;case"object":return rt}},Cr=0,Ar=()=>++Cr,Mt=class{constructor(e,t,r,s=null){d(this,"id");d(this,"eventName");d(this,"isCatchEmAll");d(this,"priority");d(this,"listener");d(this,"listenerObject");d(this,"listenerType");d(this,"callAfterApply");d(this,"isRemoved");d(this,"refCount");this.id=Ar(),this.eventName=e,this.isCatchEmAll=qe(e),this.listener=r,this.listenerObject=s,this.priority=t,this.listenerType=wr(r),this.callAfterApply=void 0,this.isRemoved=!1,this.refCount=1}isEqual(e,t=null){if(e===this)return!0;let r=typeof e;return r==="number"&&e===this.id?!0:t===null&&(r==="string"||r==="symbol")?e===pe||e===this.eventName:this.listener===e&&this.listenerObject===t}apply(e,t,r){if(this.isRemoved)return;let{listener:s,listenerObject:n}=this;switch(this.listenerType){case Ot:Ze(n,s,t,r),this.callAfterApply&&this.callAfterApply();break;case tt:Ze(n,n[s],t,r),this.callAfterApply&&this.callAfterApply();break;case rt:{let a=s[e];if(this.isCatchEmAll||this.eventName===e){if(typeof a=="function"){let o=a.apply(s,t);o!=null&&(r==null||r(o))}else Sr(e,s,t,r);this.callAfterApply&&this.callAfterApply()}break}}}},xr=(e,t)=>e.priority!==t.priority?t.priority-e.priority:e.id-t.id,Ct=e=>e==null?void 0:e.slice(0),At=(e,t)=>{let r=e.indexOf(t);r>-1&&e.splice(r,1)},Or=e=>e===rt||e===tt,et=(e,t,r)=>{let s=e.findIndex(n=>n.isEqual(t,r));s>-1&&(e[s].isRemoved=!0,e.splice(s,1))},Ne=(e,t,r)=>{let s=[];for(let n of e)(t==null&&n.listenerObject===r||n.eventName===t&&n.listener===r)&&s.push(n);for(let n of s)et(e,n,void 0)},Xe=e=>{e&&(e.forEach(t=>{t.isRemoved=!0}),e.length=0)},kr=(e,t)=>e.listenerType===t.listenerType?e.priority===t.priority&&e.eventName===t.eventName&&e.listenerObject===t.listenerObject&&e.listener===t.listener:!1,Pr=(e,t)=>{if(Or(e.listenerType))return t.find(r=>kr(e,r))},Fr=(e,t)=>{let r=Pr(e,t);return r?(r.refCount+=1,r):(t.push(e),t.sort(xr),e)},Mr=class{constructor(){d(this,"namedListeners");d(this,"catchEmAllListeners");d(this,"getListenersForEventName",e=>{let t=this.namedListeners.get(e);return t||(t=[],this.namedListeners.set(e,t)),t});this.namedListeners=new Map,this.catchEmAllListeners=[]}add(e){return Fr(e,e.isCatchEmAll?this.catchEmAllListeners:this.getListenersForEventName(e.eventName))}remove(e,t,r=!1){t==null&&Array.isArray(e)?e.forEach(s=>this.remove(s,null,r)):e==null||t==null&&qe(e)?this.removeAllListeners():t==null&&kt(e)?Xe(this.namedListeners.get(e)):e instanceof Mt?e.isRemoved||(e.refCount-=1,e.refCount<1&&(e.isRemoved=!0,this.namedListeners.forEach(s=>At(s,e)),At(this.catchEmAllListeners,e))):r?qe(e)?Ne(this.catchEmAllListeners,pe,e):this.namedListeners.forEach(s=>Ne(s,e,t)):(this.namedListeners.forEach(s=>{et(s,e,t),Ne(s,void 0,e)}),et(this.catchEmAllListeners,e,t),Ne(this.catchEmAllListeners,void 0,e))}removeAllListeners(){this.namedListeners.forEach(e=>Xe(e)),this.namedListeners.clear(),Xe(this.catchEmAllListeners)}forEach(e,t){let r=Ct(this.catchEmAllListeners),s=Ct(this.namedListeners.get(e));if(e===pe||!s||s.length===0)r.forEach(t);else if(r.length===0)s.forEach(t);else{let n=s.length,a=r.length,o=0,c=0;for(;o<n||c<a;){if(o<n){let l=s[o];if(c>=a||l.priority>=r[c].priority){t(l),++o;continue}}c<a&&(t(r[c]),++c)}}}getSubscriptionCount(){let e=this.catchEmAllListeners.length;for(let t of this.namedListeners.values())e+=t.length;return e}},Se=e=>!!(e&&e[re]);function Fe(e){if(Se(e))return e;let t=new Mr,r=new Ft;return Er(e,re,{keeper:r,store:t}),e}var st={Max:Number.POSITIVE_INFINITY,AAA:1e9,BB:1e6,C:1e3,Default:0,Low:-1e4,Min:Number.NEGATIVE_INFINITY},Tr=(e,t,r,s,n,a,o)=>{let c=e.add(new Mt(r,s,n,a));return t.emit(r,c,o),c},jr=(e,t,r,s)=>{let n=r.length,a=typeof r[0],o,c,l,u;if(n>=2&&n<=3&&a==="number"?(o=pe,[c,l,u]=r):n>=3&&n<=4&&typeof r[1]=="number"?[o,c,l,u]=r:(c=st.Default,a==="string"||a==="symbol"||Array.isArray(r[0])?[o,l,u]=r:(o=pe,[l,u]=r)),!l&&Pt)throw vr("called with insufficient arguments!",r),"subscribeTo() called with insufficient arguments!";let y=p=>ye=>Tr(e,t,ye,p,l,u,s);return Array.isArray(o)?o.map(p=>Array.isArray(p)?y(p[1])(p[0]):y(c)(p)):y(c)(o)},Tt=(e,t,r)=>{let s=[],n=jr(e,t,r,s);return Ft.publish(s),n},xt=e=>t=>{t.callAfterApply=()=>{e==null||e()}},jt=(e,t)=>Object.assign(()=>b(e,t),Array.isArray(t)?{listeners:t}:{listener:t}),Lt=(e,t,r,s)=>{let{store:n,keeper:a}=e[re];Array.isArray(t)?t.forEach(o=>{n.forEach(o,c=>c.apply(o,r,s)),a.retain(o,r)}):t!==pe&&(n.forEach(t,o=>{o.apply(t,r,s)}),a.retain(t,r))},x=(e,...t)=>{let r=Fe(e),{store:s,keeper:n}=r[re];return jt(r,Tt(s,n,t))},B=(e,...t)=>{let r=Fe(e),{store:s,keeper:n}=r[re],a=Tt(s,n,t),o=jt(r,a),c=!1,l=()=>{c||(o(),c=!0)};return Array.isArray(a)?a.forEach(xt(l)):xt(l)(a),l},Lr=(e,t)=>new Promise(r=>{B(e,t,r)}),b=(e,t,r)=>{if(!Se(e))throw new Error("object is not eventized");let{store:s,keeper:n}=e[re],a=typeof t,o=r!=null&&(a==="string"||a==="symbol");s.remove(t,r,o),Array.isArray(t)?n.remove(t.filter(c=>typeof c=="string")):kt(t)&&n.remove(t)},m=(e,t,...r)=>{if(!Se(e))throw new Error("object is not eventized");Lt(e,t,r)},Rr=(e,t,...r)=>{if(!Se(e))throw new Error("object is not eventized");let s=[];return Lt(e,t,r,n=>{s.push(n)}),s=s.map(n=>Array.isArray(n)?Promise.all(n):Promise.resolve(n)),s.length>0?Promise.all(s):Promise.resolve()},Me=(e,t)=>{let r=Fe(e),{keeper:s}=r[re];s.add(t)},it=(e,t)=>{if(!Se(e))throw new Error("object is not eventized");let{keeper:r}=e[re];r.clear(t)},V=(()=>{let e=(t={})=>Fe(t);return e.inject=(t={})=>(t=Fe(t),Object.assign(t,{on:(...r)=>x(t,...r),once:(...r)=>B(t,...r),onceAsync:r=>Lr(t,r),off:(r,s)=>b(t,r,s),emit:(r,...s)=>m(t,r,...s),emitAsync:(r,...s)=>Rr(t,r,...s),retain:r=>Me(t,r),retainClear:r=>it(t,r)}),t),e.is=Se,e})();var z=Symbol("signal"),nt=Symbol("destroySignal"),ot=Symbol("createEffect"),Rt=Symbol("destroyEffect");var Te,je,we=class{constructor(t="id",r=1){f(this,Te);f(this,je);h(this,Te,t),h(this,je,r)}make(){return Symbol(\`\${i(this,Te)}\${wt(this,je)._++}\`)}};Te=new WeakMap,je=new WeakMap;var se=V(),ge=V(),ie=V();var Le,ne=class{constructor(){f(this,Le,new Set)}batch(t){i(this,Le).add(t)}run(){m(ie,Array.from(i(this,Le)))}};Le=new WeakMap,d(ne,"current");var Dt=()=>ne.current;function Re(e){let t=ne.current;t?t=void 0:t=ne.current=new ne;try{e()}finally{t&&(ne.current=void 0,t.run())}}var at=[],Qe=()=>at.at(-1),zt=(e,t)=>{at.push(e);try{return t()}finally{at.pop()}};var Dr=e=>e!=null&&typeof e.then=="function",oe,ae,me,ve,Ce,G=class G{constructor(t,r){d(this,"id");d(this,"callback");f(this,oe);f(this,ae,new Set);f(this,me,new Set);d(this,"parentEffect");d(this,"childEffects",[]);d(this,"curChildEffectSlot",0);d(this,"autorun",!0);d(this,"shouldRun",!0);f(this,ve);f(this,Ce,!1);var s;this.callback=t,this.autorun=(s=r==null?void 0:r.autorun)!=null?s:!0,h(this,ve,r==null?void 0:r.dependencies),this.id=G.idGen.make(),x(ie,this.id,"recall",this),++G.count}hasStaticDeps(){return i(this,ve)!=null&&i(this,ve).length>0}saveSignalsFromDeps(){for(let t of i(this,ve))this.whenSignalIsRead(S(t).id)}static createEffect(t,r,s){let n=Array.isArray(r)?r:void 0,a=n?s!=null?s:{dependencies:n}:r;a&&n&&(a.dependencies=n);let o,c=Qe();return c!=null?(o=c.getCurrentChildEffect(),o==null&&(o=new G(t,a),c.attachChildEffect(o),m(ie,ot,o)),c.curChildEffectSlot++):(o=new G(t,a),m(ie,ot,o)),o.hasStaticDeps()?o.saveSignalsFromDeps():o.autorun&&o.run(),[o.run.bind(o),o.destroy.bind(o)]}getCurrentChildEffect(){return this.childEffects[this.curChildEffectSlot]}attachChildEffect(t){this.childEffects.push(t),this.parentEffect=this}run(){if(i(this,Ce)||!this.shouldRun)return;let t=Dt();t?t.batch(this.id):(this.runCleanupCallback(),this.curChildEffectSlot=0,this.shouldRun=!1,this.hasStaticDeps()?h(this,oe,this.callback()):h(this,oe,zt(this,this.callback)))}recall(){this.shouldRun=!0,this.autorun&&this.run()}whenSignalIsRead(t){i(this,ae).has(t)||(i(this,ae).add(t),x(se,t,"recall",this),B(ge,t,nt,this))}[nt](t){!i(this,me).has(t)&&i(this,ae).has(t)&&(i(this,me).add(t),b(se,t,this),i(this,me).size===i(this,ae).size&&this.destroy())}runCleanupCallback(){if(i(this,oe)!=null){let t=i(this,oe);h(this,oe,void 0),Dr(t)?Promise.resolve(t).then(r=>{typeof r=="function"&&r()}):t()}}destroy(){i(this,Ce)||(m(ie,Rt,this),this.runCleanupCallback(),b(se,this),b(ie,this),b(ge,this),h(this,Ce,!0),i(this,ae).clear(),i(this,me).clear(),this.childEffects.forEach(t=>{t.destroy()}),this.childEffects.length=0,--G.count)}};oe=new WeakMap,ae=new WeakMap,me=new WeakMap,ve=new WeakMap,Ce=new WeakMap,d(G,"idGen",new we("ef")),d(G,"count",0);var Ve=G;var ce=(...e)=>Ve.createEffect(...e);var W=new WeakMap,T=(e,t)=>{var r;return(r=W.get(e))==null?void 0:r.signals[t]},It=e=>{var r;let t=(r=W.get(e))==null?void 0:r.signals;if(t)return Object.values(t)};var $t=(e,t,r)=>{let s=W.get(e);s?s.signals[t]=r:W.set(e,{signals:{[t]:r},effects:{}})};function ct(...e){for(let t of e)if(W.has(t)){let r=W.get(t);for(let s of Object.values(r.signals))U(s);r.signals={}}}function lt(...e){for(let t of e)if(W.has(t)){let{signals:r,effects:s}=W.get(t);for(let n of Object.values(r))U(n);for(let[,n]of Object.values(s))n();W.delete(t)}}function Bt(e){let t=S(le(e)?e:T(...e));t!=null&&!t.muted&&!t.destroyed&&Ge(t.id,t.value,{touch:!0})}function K(e){var t,r;return le(e)?(t=S(e))==null?void 0:t.value:(r=S(T(...e)))==null?void 0:r.value}var Ut,We=class{constructor(t){d(this,Ut);this[z]=t}get get(){return this[z].reader}get set(){return this[z].writer}*[(Ut=z,Symbol.iterator)](){yield this.get,yield this.set}get value(){return K(this.get)}set value(t){this.set(t)}onChange(t){let[,r]=ce(()=>t(this.value),[this.get]);return r}get muted(){return this[z].muted}set muted(t){this[z].muted=t}touch(){Bt(this)}destroy(){U(this)}};var zr=0;function Nt(){return zr>0}var Ir=new we("si");function qt(e){var t;Nt()||(t=Qe())==null||t.whenSignalIsRead(e)}function Ge(e,t,r){m(se,e,t,r)}var le=e=>e!=null&&e[z]!=null,$r=e=>{let t=r=>{var s;return r?ce(()=>(e.destroyed||qt(e.id),r(e.value)),[t]):e.destroyed||((s=e.beforeReadFn)==null||s.call(e),qt(e.id)),e.value};return Object.defineProperty(t,z,{value:e}),t},I,_e=class _e{constructor(t,r){d(this,"id");d(this,"lazy");d(this,"compareFn");d(this,"beforeReadFn");d(this,"muted",!1);d(this,"destroyed",!1);f(this,I);d(this,"valueFn");d(this,"reader");d(this,"writer",(t,r)=>{var c,l,u;let s=(c=r==null?void 0:r.lazy)!=null?c:!1,n=(l=r==null?void 0:r.compareFn)!=null?l:this.compareFn,a=n!=null?n:(y,p)=>y===p;if((s!==this.lazy||s&&t!==this.valueFn||!s&&!a(t,i(this,I)))&&(s?(h(this,I,void 0),this.valueFn=t,this.lazy=!0):(h(this,I,t),this.valueFn=void 0,this.lazy=!1),!this.muted&&!this.destroyed)){Ge(this.id,i(this,I));return}((u=r==null?void 0:r.touch)!=null?u:!1)&&Ge(this.id,i(this,I),{touch:!0})});d(this,"object");this.id=Ir.make(),++_e.instanceCount,this.lazy=t,this.lazy?(this.value=void 0,this.valueFn=r):(this.value=r,this.valueFn=void 0),this.reader=$r(this),this.object=new We(this)}get value(){return this.lazy&&(h(this,I,this.valueFn()),this.valueFn=void 0,this.lazy=!1),i(this,I)}set value(t){h(this,I,t)}};I=new WeakMap,d(_e,"instanceCount",0);var Ke=_e,S=e=>e==null?void 0:e[z];function O(e=void 0,t){var s;let r;if(le(e))r=S(e);else{let n=(s=t==null?void 0:t.lazy)!=null?s:!1;r=new Ke(n,e),r.beforeReadFn=t==null?void 0:t.beforeReadFn,r.compareFn=t==null?void 0:t.compareFn}return r.object}var U=(...e)=>{for(let t of e){let r=S(t);r!=null&&!r.destroyed&&(r.destroyed=!0,r.beforeReadFn=void 0,--Ke.instanceCount,m(ge,r.id,r.id))}};var w,Ae=new WeakMap,De=new WeakMap,Qt=e=>typeof e=="function",he;(function(e){e.Signal="signal",e.Function="function",e.Property="property"})(he||(he={}));var Q,Vt,Gt,Wt,Kt,Ee,k,q,P,_,ue,ze,ht,N=class{constructor(t,r,s){f(this,ze);f(this,Ee);f(this,k,!1);f(this,q);f(this,P);f(this,_);f(this,ue);var a,o;let n=w.findConnection(t,r);if(n!=null)return n;V(this),Me(this,w.Value),h(this,q,S(t)),le(r)?(h(this,P,S(r)),h(this,_,he.Signal)):Qt(r)?(h(this,P,r),h(this,_,he.Function)):(h(this,P,r),h(this,_,he.Property)),h(this,ue,s),h(this,Ee,x(se,i(this,q).id,(c,l)=>{(l==null?void 0:l.touch)===!0?this.touch():E(this,ze,ht).call(this,!1)})),B(ge,i(this,q).id,"destroy",this),E(a=w,Q,Vt).call(a,this),s!=null&&E(o=w,Q,Wt).call(o,s,this),this.touch()}static findConnectionsBySignal(t){return Ae.get(S(t))}static findConnectionsByTarget(t){let r=De.get(t);return r?Array.from(r):void 0}static findConnectionsByObject(t){let r=new Set,s=It(t);if(s)for(let a of s.flatMap(o=>{let c=w.findConnectionsBySignal(o);return c?Array.from(c):[]}))r.add(a);let n=w.findConnectionsByTarget(t);if(n)for(let a of n)r.add(a);return r.size>0?Array.from(r):void 0}static findConnection(t,r){let s=Ae.get(S(t));if(s!=null){let n=Array.from(s),a=-1;if(le(r)){let o=S(r);a=n.findIndex(c=>i(c,P)===o)}else Qt(r)?a=n.findIndex(o=>i(o,P)===r):a=n.findIndex(o=>{if(i(o,_)===he.Property){let c=i(o,P);return c[0]===r[0]&&c[1]===r[1]}return!1});if(a>=0)return n[a]}}get isMuted(){return i(this,k)}nextValue(){return new Promise((t,r)=>{let s=0,n=[x(this,w.Value,a=>{s===1?(n.forEach(o=>{o()}),t(a)):++s}),x(this,w.Destroy,()=>{n.forEach(a=>{a()}),r()})]})}touch(){return E(this,ze,ht).call(this,!0)}mute(){return!this.isDestroyed&&!i(this,k)&&(h(this,k,!0),m(this,w.Mute,this)),this}unmute(){return!this.isDestroyed&&i(this,k)&&(h(this,k,!1),m(this,w.Unmute,this)),this}toggle(){return this.isDestroyed||(h(this,k,!i(this,k)),m(this,i(this,k)?w.Mute:w.Unmute,this)),i(this,k)}destroy(){var t,r,s;this.isDestroyed||(m(this,w.Destroy,this),b(this),E(t=w,Q,Gt).call(t,this),(r=i(this,Ee))==null||r.call(this),h(this,Ee,void 0),h(this,q,void 0),h(this,P,void 0),i(this,ue)!=null&&(E(s=w,Q,Kt).call(s,i(this,ue),this),h(this,ue,void 0)))}get isDestroyed(){return i(this,Ee)==null}hasTarget(t){return i(this,ue)===t}};Q=new WeakSet,Vt=function(t){if(!t.isDestroyed){let r=i(t,q),s=Ae.get(r);s?s.add(t):(s=new Set([t]),Ae.set(r,s))}},Gt=function(t){if(!t.isDestroyed){let r=i(t,q),s=Ae.get(r);s&&(s.delete(t),s.size===0&&Ae.delete(r))}},Wt=function(t,r){if(!r.isDestroyed){let s=De.get(t);s?s.add(r):(s=new Set([r]),De.set(t,s))}},Kt=function(t,r){if(!r.isDestroyed){let s=De.get(t);s&&(s.delete(r),s.size===0&&De.delete(t))}},Ee=new WeakMap,k=new WeakMap,q=new WeakMap,P=new WeakMap,_=new WeakMap,ue=new WeakMap,ze=new WeakSet,ht=function(t){if(!i(this,k)&&!this.isDestroyed){let{value:r}=i(this,q);if(i(this,_)===he.Signal)i(this,P).writer(r,t?{touch:t}:void 0);else if(i(this,_)===he.Function)i(this,P).call(this,r);else{let[s,n]=i(this,P);s[n](r)}m(this,w.Value,r)}return this},f(N,Q),d(N,"Value","value"),d(N,"Mute","mute"),d(N,"Unmute","unmute"),d(N,"Destroy","destroy");w=N;function Ie(e,t){var o;let r=Array.isArray(e)?T(...e):e,s=Array.isArray(t),n=s&&(o=T(...t))!=null?o:t,a=s?t[0]:t;return new N(r,n,a)}var _t=e=>{if(typeof e=="symbol")return e;let t=e.indexOf("$");return t>=0?e.slice(0,t):e};function Jt(e){return function(t,r){var a,o;let s=(a=e==null?void 0:e.name)!=null?a:_t(r.name),n=!!((o=e==null?void 0:e.readAsValue)!=null&&o);return{get(){let c=T(this,s);if(c)return n?K(c):c()},set(c){var l;(l=S(T(this,s)))==null||l.writer(c)},init(c){let[l,u]=O(void 0,e);return $t(this,s,l),u(c),K(l)}}}}function Ht(e){return function(t,r){var n;let s=(n=e==null?void 0:e.name)!=null?n:_t(r.name);return{get(){return T(this,s)}}}}var Yt;(function(e){e[e.StructuralChanges=1]="StructuralChanges",e[e.ContentUpdates=2]="ContentUpdates",e[e.Removal=3]="Removal"})(Yt||(Yt={}));var J;(function(e){e[e.CreateEntities=1]="CreateEntities",e[e.DestroyEntities=2]="DestroyEntities",e[e.SetParent=3]="SetParent",e[e.UpdateOrder=4]="UpdateOrder",e[e.ChangeProperties=5]="ChangeProperties",e[e.ChangeToken=6]="ChangeToken",e[e.SendEvents=7]="SendEvents"})(J||(J={}));var Pi=Symbol.for("ShadowEntsGlobalNS"),Ur="configure",Nr="changeTrail",qr="destroy",Qr="loaded",Xt="appliedChangeTrail",ut="importedModule",Vr="destroyed",yt="messageToView",ft="shadowObjects",$,rr,Gr=(rr=class{constructor(){f(this,$,new Map)}keys(){return i(this,$).keys()}entries(){return i(this,$).entries()}clear(){for(let e of i(this,$).values())e.destroy();i(this,$).clear()}hasSignal(e){return i(this,$).has(e)}getSignal(e){if(!i(this,$).has(e)){let t=O();return i(this,$).set(e,t),t}return i(this,$).get(e)}getSignalReader(e){return this.getSignal(e).get}getSignalWriter(e){return this.getSignal(e).set}},$=new WeakMap,rr);function Zt(e,t,r,s,n,a){function o(D){if(D!==void 0&&typeof D!="function")throw new TypeError("Function expected");return D}for(var c=s.kind,l=c==="getter"?"get":c==="setter"?"set":"value",u=!t&&e?s.static?e:e.prototype:null,y=t||(u?Object.getOwnPropertyDescriptor(u,s.name):{}),p,ye=!1,A=r.length-1;A>=0;A--){var Ue={};for(var g in s)Ue[g]=g==="access"?{}:s[g];for(var g in s.access)Ue.access[g]=s.access[g];Ue.addInitializer=function(D){if(ye)throw new TypeError("Cannot add initializers after decoration has completed");a.push(o(D||null))};var v=(0,r[A])(c==="accessor"?{get:y.get,set:y.set}:y[l],Ue);if(c==="accessor"){if(v===void 0)continue;if(v===null||typeof v!="object")throw new TypeError("Object expected");(p=o(v.get))&&(y.get=p),(p=o(v.set))&&(y.set=p),(p=o(v.init))&&n.unshift(p)}else(p=o(v))&&(c==="field"?n.unshift(p):y[l]=p)}u&&Object.defineProperty(u,s.name,y),ye=!0}function Je(e,t,r){for(var s=arguments.length>2,n=0;n<t.length;n++)r=s?t[n].call(e,r):t[n].call(e);return s?r:void 0}var dt=(()=>{var o,c,l,u,y,pt,ar,A;let e,t=[],r=[],s,n=[],a=[];return A=class{constructor(){f(this,y);f(this,o,[]);f(this,c);f(this,l,Je(this,t,void 0));f(this,u,(Je(this,r),Je(this,n,void 0)));Je(this,a),Me(this,A.Value),this.value$(g=>m(this,A.Value,g))}get value(){return i(this,l)}set value(g){h(this,l,g)}get value$(){return i(this,u)}set value$(g){h(this,u,g)}add(...g){for(let v of g)i(this,o).push(v);E(this,y,ar).call(this)}clear(){i(this,o).length=0,E(this,y,pt).call(this)}dispose(){this.clear(),b(this),lt(this),it(this,A.Value)}},o=new WeakMap,c=new WeakMap,l=new WeakMap,u=new WeakMap,y=new WeakSet,pt=function(){var g;(g=i(this,c))==null||g.call(this),h(this,c,void 0)},ar=function(){E(this,y,pt).call(this);let[g,v]=ce(()=>{for(let D of i(this,o)){let vt=K(D);if(vt!=null){this.value=vt;return}}this.value=void 0},i(this,o));h(this,c,v),g()},(()=>{let g=typeof Symbol=="function"&&Symbol.metadata?Object.create(null):void 0;e=[Jt()],s=[Ht()],Zt(A,null,e,{kind:"accessor",name:"value",static:!1,private:!1,access:{has:v=>"value"in v,get:v=>v.value,set:(v,D)=>{v.value=D}},metadata:g},t,r),Zt(A,null,s,{kind:"accessor",name:"value$",static:!1,private:!1,access:{has:v=>"value$"in v,get:v=>v.value$,set:(v,D)=>{v.value$=D}},metadata:g},n,a),g&&Object.defineProperty(A,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:g})})(),A.Value="value",A})(),er="onCreate",xe="onDestroy",Wr="onViewEvent",fe,Oe,be,Y,j,F,X,L,ke,R,gt,He,mt,sr,Kr=(sr=class{constructor(e,t){f(this,R);f(this,fe);f(this,Oe);f(this,be,new Gr);f(this,Y,new Map);f(this,j);f(this,F);f(this,X,new Set);f(this,L,[]);f(this,ke,0);h(this,fe,e),h(this,Oe,t),B(this,xe,st.Min,this)}get kernel(){return i(this,fe)}get uuid(){return i(this,Oe)}get order(){return i(this,ke)}set order(e){i(this,ke)!==e&&(h(this,ke,e),i(this,j)&&this.parent.resortChildren())}get parentUuid(){return i(this,j)||void 0}set parentUuid(e){i(this,j)!==e&&(this.removeFromParent(),h(this,j,e||void 0),h(this,F,e?i(this,fe).getEntity(e):void 0),i(this,F)&&i(this,F).addChild(this))}get parent(){return!i(this,F)&&i(this,j)&&h(this,F,i(this,fe).getEntity(i(this,j))),i(this,F)}set parent(e){this.parentUuid=e==null?void 0:e.uuid}get hasParent(){return!!i(this,j)}get children(){return i(this,L)}traverse(e){e(this);for(let t of i(this,L))t.traverse(e)}onDestroy(){var e;i(this,be).clear(),b(this);for(let t of i(this,Y).values())t.unsubscribeFromPath(),(e=t.unsubscribeFromParent)==null||e.call(t),t.ctxPath.dispose(),ct(t.inherited,t.provide,t.context);h(this,j,void 0),h(this,F,void 0),i(this,X).clear(),i(this,L).length=0}addChild(e){var t;if(i(this,L).length===0){i(this,X).add(e.uuid),i(this,L).push(e);return}if(i(this,X).has(e.uuid))throw new Error(\`child with uuid: \${e.uuid} already exists! parentUuid: \${this.uuid}\`);i(this,X).add(e.uuid),i(this,L).push(e),this.resortChildren();for(let[,r]of i(e,Y))E(t=e,R,mt).call(t,r)}resortChildren(){i(this,L).sort((e,t)=>e.order-t.order)}removeChild(e){i(this,X).has(e.uuid)&&(i(this,X).delete(e.uuid),i(this,L).splice(i(this,L).indexOf(e),1))}removeFromParent(){if(i(this,F)){i(this,F).removeChild(this),h(this,F,void 0),h(this,j,void 0);for(let[,e]of i(this,Y))e.unsubscribeFromParent&&(e.unsubscribeFromParent(),e.unsubscribeFromParent=void 0)}}dispatchMessageToView(e,t,r,s=!1){i(this,fe).dispatchMessageToView({uuid:i(this,Oe),type:e,data:t,transferables:r,traverseChildren:s})}dispatchViewEvents(e){for(let{type:t,data:r}of e)m(this,Wr,t,r)}dispatchViewEvent(e,t){this.dispatchViewEvents([{type:e,data:t}])}getPropertyReader(e){return E(this,R,gt).call(this,e).get}getPropertyWriter(e){return E(this,R,gt).call(this,e).set}setProperties(e){Re(()=>{for(let[t,r]of e)this.setProperty(t,r)})}setProperty(e,t){this.getPropertyWriter(e)(t)}getProperty(e){return K(this.getPropertyReader(e))}propKeys(){return Array.from(i(this,be).keys())}propEntries(){return Array.from(i(this,be).entries()).map(([e,t])=>[e,t.value])}hasContext(e){return i(this,Y).has(e)}useContext(e){return E(this,R,He).call(this,e).context.get}provideContext(e){return E(this,R,He).call(this,e).provide}},fe=new WeakMap,Oe=new WeakMap,be=new WeakMap,Y=new WeakMap,j=new WeakMap,F=new WeakMap,X=new WeakMap,L=new WeakMap,ke=new WeakMap,R=new WeakSet,gt=function(e){return i(this,be).getSignal(e)},He=function(e){let t=i(this,Y).get(e);if(t==null){let r=O(),s=O(),n=O(),a=new dt;a.add(s.get,r.get);let o=x(a,dt.Value,c=>{queueMicrotask(()=>{n.set(c)})});t={name:e,inherited:r,provide:s,context:n,ctxPath:a,unsubscribeFromPath:o},i(this,Y).set(e,t),E(this,R,mt).call(this,t)}return t},mt=function(e){var t,r;this.parent&&((t=e.unsubscribeFromParent)==null||t.call(e),e.unsubscribeFromParent=x(E(r=this.parent,R,He).call(r,e.name).ctxPath,dt.Value,s=>{e.inherited.set(s)}))},sr);function _r(e,t){e.indexOf(t)===-1&&e.push(t)}var Z,M,ir,cr=(ir=class{constructor(){f(this,Z,new Map);f(this,M,new Map)}static get(e){return e!=null?e:Jr}define(e,t){i(this,Z).has(e)?_r(i(this,Z).get(e).constructors,t):i(this,Z).set(e,{token:e,constructors:[t]})}appendRoute(e,t){if(i(this,M).has(e)){let r=i(this,M).get(e);for(let s of t)r.add(s)}else i(this,M).set(e,new Set(t))}clearRoute(e){i(this,M).delete(e)}findTokensByRoute(e){let t=new Set([e]),r=i(this,M).has(e)?[...i(this,M).get(e)]:[];for(;r.length;){let s=r.shift();t.has(s)||(t.add(s),i(this,M).has(s)&&r.push(...Array.from(i(this,M).get(s)).filter(n=>!t.has(n))))}return Array.from(t)}findConstructors(e){let t=this.findTokensByRoute(e),r=new Set;for(let s of t){let n=i(this,Z).get(s);if(n)for(let a of n.constructors)r.add(a)}return r.size>0?Array.from(r):void 0}hasToken(e){return i(this,Z).has(e)}hasRoute(e){return i(this,M).has(e)}clear(){i(this,Z).clear(),i(this,M).clear()}},Z=new WeakMap,M=new WeakMap,ir),Jr=new cr,H;(function(e){e[e.CreateAndDestroy=0]="CreateAndDestroy",e[e.JustCreate=1]="JustCreate",e[e.DestroyOnly=2]="DestroyOnly"})(H||(H={}));var tr=e=>e.displayName||e.name,C,ee,Pe,$e,te,nr,Hr=(nr=class{constructor(e){f(this,C,new Map);f(this,ee,new Set);f(this,Pe);f(this,$e);f(this,te,!0);V(this),this.registry=cr.get(e)}getEntity(e){var r;let t=(r=i(this,C).get(e))==null?void 0:r.entity;if(!t)throw new Error(\`entity with uuid "\${e}" not found!\`);return t}hasEntity(e){return i(this,C).has(e)}traverseLevelOrderBFS(e=!1){if(i(this,te)){let t=new Map,r=(s,n)=>{let a=this.getEntity(s);t.has(n)?t.get(n).push(a):t.set(n,[a]);for(let o of a.children)r(o.uuid,n+1)};i(this,ee).forEach(s=>r(s,0)),h(this,Pe,Array.from(t.entries()).sort((s,n)=>s[0]-n[0]).map(([,s])=>s).flat()),h(this,$e,i(this,Pe).slice().reverse()),h(this,te,!1)}return e?i(this,$e):i(this,Pe)}getEntityGraph(){return Array.from(i(this,ee)).map(e=>this.getEntityGraphNode(e))}getEntityGraphNode(e){if(!i(this,C).has(e))return;let{token:t,entity:r}=i(this,C).get(e);return{token:t,entity:r,props:Object.fromEntries(r.propEntries()),children:r.children.map(s=>this.getEntityGraphNode(s.uuid))}}upgradeEntities(){for(let e of this.traverseLevelOrderBFS(!0))this.updateShadowObjects(e.uuid,H.DestroyOnly);for(let e of this.traverseLevelOrderBFS(!1))this.updateShadowObjects(e.uuid,H.JustCreate)}run(e){Re(()=>{for(let t of e.changeTrail)this.parse(t)})}parse(e){switch(e.type){case J.CreateEntities:this.createEntity(e.uuid,e.token,e.parentUuid,e.order,e.properties),h(this,te,!0);break;case J.DestroyEntities:this.destroyEntity(e.uuid),h(this,te,!0);break;case J.SetParent:this.setParent(e.uuid,e.parentUuid,e.order),h(this,te,!0);break;case J.UpdateOrder:this.updateOrder(e.uuid,e.order),h(this,te,!0);break;case J.ChangeProperties:this.changeProperties(e.uuid,e.properties);break;case J.ChangeToken:this.changeToken(e.uuid,e.token);break;case J.SendEvents:this.dispatchEventsToEntity(e.uuid,e.events);break}}createEntity(e,t,r,s=0,n){let a=new Kr(this,e);a.order=s;let o={token:t,entity:a,usedConstructors:new Map};i(this,C).set(e,o),r&&(a.parentUuid=r),a.hasParent||i(this,ee).add(e),n&&a.setProperties(n),this.createShadowObjects(e)}destroyEntity(e){if(!i(this,C).has(e))return;let{entity:t,usedConstructors:r}=i(this,C).get(e);t.removeFromParent(),m(t,xe,this),r.clear(),i(this,C).delete(t.uuid),i(this,ee).delete(t.uuid)}setParent(e,t,r=0){let s=this.getEntity(e);s.parentUuid===t&&s.order===r||(s.removeFromParent(),s.order=r,s.parentUuid=t,s.hasParent?i(this,ee).delete(e):i(this,ee).add(e))}updateOrder(e,t){this.getEntity(e).order=t}dispatchEventsToEntity(e,t){var r;(r=this.getEntity(e))==null||r.dispatchViewEvents(t)}changeProperties(e,t){this.getEntity(e).setProperties(t)}changeToken(e,t){if(!i(this,C).has(e))return;let r=i(this,C).get(e);r.token!==t&&(r.token=t,this.updateShadowObjects(e))}dispatchMessageToView(e){queueMicrotask(()=>{m(this,yt,e)})}updateShadowObjects(e,t=H.CreateAndDestroy){let r=i(this,C).get(e),s=new Set(this.registry.findConstructors(r.token)),n=t===H.CreateAndDestroy||t===H.DestroyOnly,a=t===H.CreateAndDestroy||t===H.JustCreate;if(n){for(let[o,c]of r.usedConstructors)if(!s.has(o)){r.usedConstructors.delete(o);for(let l of c)this.destroyShadowObject(l,r.entity)}}if(a)for(let o of s)r.usedConstructors.has(o)||this.constructShadowObject(o,r)}constructShadowObject(e,t){let r=new Set,s=new Set,n=new Map,a=new Map,o=new Map,c=V(new e({entity:t.entity,provideContext(l,u,y){let p=a.get(l);if(p===void 0){p=O(u,y?{compareFn:y}:void 0),a.set(l,p);let ye=Ie(p,t.entity.provideContext(l));s.add(ye.destroy.bind(ye))}return p},useContext(l,u){let y=n.get(l);if(y===void 0){[y]=O(void 0,u?{compareFn:u}:void 0),n.set(l,y);let p=Ie(t.entity.useContext(l),y);s.add(p.destroy.bind(p))}return y},useProperty(l,u){let y=o.get(l);if(y===void 0){[y]=O(void 0,u?{compareFn:u}:void 0),o.set(l,y);let p=Ie(t.entity.getPropertyReader(l),y);s.add(p.destroy.bind(p))}return y},createEffect(...l){let u=ce(...l);return s.add(u[1]),u},createSignal(...l){let u=O(...l);return s.add(()=>{U(u)}),u},on(...l){let u=x(...l);return s.add(u),u},onDestroy(l){r.add(l)}}));return console.debug("[Kernel] create shadow-object",tr(e),{shadowObject:c,entity:t.entity}),B(c,xe,()=>{console.debug("[Kernel] destroy shadow-object",tr(e),{shadowObject:c,entity:t.entity});for(let u of r)u();for(let u of s)u();for(let u of n.values())U(u);for(let u of o.values())U(u);for(let[u]of a.values())U(u);r.clear(),s.clear(),n.clear(),o.clear(),a.clear();let l=t.usedConstructors.get(e);l&&(l.delete(c),l.size===0&&t.usedConstructors.delete(e))}),t.usedConstructors.has(e)?t.usedConstructors.get(e).add(c):t.usedConstructors.set(e,new Set([c])),this.attachShadowObject(c,t.entity),c}createShadowObjects(e){var r;let t=i(this,C).get(e);(r=this.registry.findConstructors(t.token))==null||r.forEach(s=>{this.constructShadowObject(s,t)})}findShadowObjects(e){if(!i(this,C).has(e))return[];let{usedConstructors:t}=i(this,C).get(e);return Array.from(new Set(Array.from(t.values()).map(r=>Array.from(r)).flat()))}attachShadowObject(e,t){x(t,e),typeof e[er]=="function"&&e[er](t)}destroyShadowObject(e,t){typeof e[xe]=="function"&&e[xe](t),m(e,xe,t),b(t,e)}destroy(){for(let e of this.traverseLevelOrderBFS().reverse())this.destroyEntity(e.uuid)}},C=new WeakMap,ee=new WeakMap,Pe=new WeakMap,$e=new WeakMap,te=new WeakMap,nr);async function lr(e,t,r,s=!0){var a,o;if(r.has(t)){console.warn("importModule: skipping already imported module",t);return}else r.add(t);t.extends&&await Promise.all(t.extends.map(c=>lr(e,c,r,!1)));let{registry:n}=e;if(t.define)for(let[c,l]of Object.entries(t.define))n.define(c,l);if(t.routes)for(let[c,l]of Object.entries(t.routes))n.appendRoute(c,l);await((o=(a=t.initialize)==null?void 0:a.call(t,{define:(c,l)=>n.define(c,l),kernel:e,registry:n}))!=null?o:Promise.resolve()),s&&e.upgradeEntities()}var Yr=e=>(typeof e=="string"&&(e=new URL(e,globalThis.location.href)),e.toString()),Be,de,hr,ur,fr,or,Xr=(or=class{constructor(e){f(this,de);f(this,Be,new Set);var t,r;this.kernel=(t=e==null?void 0:e.kernel)!=null?t:new Hr,this.postMessage=(r=e==null?void 0:e.postMessage)!=null?r:self.postMessage.bind(self),x(this.kernel,yt,"onMessageToView",this)}route(e){var t;switch(e.data.type){case Ur:E(this,de,hr).call(this,e.data);break;case Nr:E(this,de,ur).call(this,e.data);break;case qr:E(this,de,fr).call(this,e.data);break;default:console.warn("[MessageRouter] unknown message",(t=e.data.type)!=null?t:e.data)}}onMessageToView(e){let s=e,{transferables:t}=s,r=St(s,["transferables"]);this.postMessage({type:yt,data:r},{transfer:t})}},Be=new WeakMap,de=new WeakSet,hr=async function(e){try{let t=await import(Yr(e.importModule));t[ft]?(await lr(this.kernel,t[ft],i(this,Be)),this.postMessage({type:ut,url:e.importModule})):this.postMessage({type:ut,url:e.importModule,error:\`module has no "\${ft}" export\`})}catch(t){console.error("[MessageRouter] failed to import module",t),this.postMessage({type:ut,url:e.importModule,error:\`\${t}\`})}},ur=function(e){try{this.kernel.run(e)}catch(t){console.error("[MessageRouter] failed to apply change trail",t),this.postMessage({type:Xt,serial:e.serial,error:t.toString()})}e.serial&&this.postMessage({type:Xt,serial:e.serial})},fr=function(e){console.debug("[MessageRouter] on destroy",e),b(this.kernel,this),i(this,Be).clear(),this.postMessage({type:Vr})},or),Zr=class{constructor(){this.router=new Xr,this.onmessage=e=>{this.router.route(e)}}start(){self.addEventListener("message",this.onmessage),self.postMessage({type:Qr})}};console.debug("@spearwolf/shadow-objects: hello worker \\u{1F680}");var es=new Zr;es.start();
21
+ import{beQuiet as Ct,createEffect as Qe,createSignal as Ce}from"@spearwolf/signalize";var b;(function(i){i[i.StructuralChanges=1]="StructuralChanges",i[i.ContentUpdates=2]="ContentUpdates",i[i.Removal=3]="Removal"})(b||(b={}));var p;(function(i){i[i.CreateEntities=1]="CreateEntities",i[i.DestroyEntities=2]="DestroyEntities",i[i.SetParent=3]="SetParent",i[i.UpdateOrder=4]="UpdateOrder",i[i.ChangeProperties=5]="ChangeProperties",i[i.ChangeToken=6]="ChangeToken",i[i.SendEvents=7]="SendEvents"})(p||(p={}));var M=Symbol.for("ShadowEntsGlobalNS"),S="#void",Re="contextLost",Me="configure",je="changeTrail",$e="destroy",Ne="loaded",Le="appliedChangeTrail",Fe="importedModule",De="destroyed",L="messageToView",We=16e3,Ie=16e3,Ue=4e3,Ve=1e3,ve="shadowObjects";function ze(i,e){i.indexOf(e)===-1&&i.push(e)}function be(i,e){let t=i.indexOf(e);t!==-1&&i.splice(t,1),i.push(e)}function A(i,e){let t=i.indexOf(e);t!==-1&&i.splice(t,1)}var j=i=>typeof i=="string"?i.trim()||M:typeof i=="symbol"?i:M;var W=class{#e;get uuid(){return this.#e}#t=0;constructor(e){this.#e=e}#r=!0;#i=0;#s=0;hasChanges(){return this.#t>0}get isNew(){return this.#r}get isCreated(){return this.#i>0&&this.#i>this.#s}get isDestroyed(){return this.#s>0&&this.#s>=this.#i}#n=S;#o;#a=0;#l;#u;#h;create(e=S,t,r=0){this.#t++,this.#i++,this.#l=e,this.#u=t,this.#h=r||void 0}destroy(){this.#s++,this.#t++}clear(){this.#t=0,this.#r=!1,this.#l=void 0,this.#u=void 0,this.#h=void 0,this.#d.clear(),this.#y.length=0,this.#p.length=0,this.#f.clear()}changeToken(e){e===this.#n?this.#l=void 0:(this.#l=e,this.#t++)}setParent(e){e===this.#o?this.#u=void 0:(this.#u=e??null,this.#t++)}changeOrder(e){e===this.#a?this.#h=void 0:(this.#h=e,this.#t++)}#c=new Map;#d=new Map;#y=[];changeProperty(e,t,r){let s=this.#c.get(e);r==null&&t!==s||r!=null&&!r(t,s)?(this.#d.set(e,t),be(this.#y,e),this.#t++):(this.#d.delete(e),A(this.#y,e))}removeProperty(e){let t=this.#c.has(e);this.#d.has(e)?(this.#d.delete(e),t||A(this.#y,e)):t&&(be(this.#y,e),this.#t++)}#p=[];#f=new Set;createEvent(e,t,r){this.#p.push({type:e,data:t}),r?.forEach(s=>this.#f.add(s)),this.#t++}transferEventsTo(e){this.#p.length>0&&(e.#p.push(...this.#p),this.#p.length=0),this.#f.size>0&&(e.#f=new Set([...e.#f,...this.#f]),this.#f.clear())}buildChangeTrail(e,t){let{isNew:r,isCreated:s,isDestroyed:n}=this;if(!(r&&n))switch(t){case b.StructuralChanges:r?e.push(this.makeCreateEntityChange()):n||(this.#u!==void 0&&this.#u!==this.#o?e.push(this.makeSetParentChange()):this.#h!==void 0&&this.#h!==this.#a&&e.push(this.makeUpdateOrderChange()),this.#l!==void 0&&this.#l!==this.#n&&e.push(this.makeChangeToken()));break;case b.ContentUpdates:!r&&s&&this.#y.length>0&&e.push(this.makeChangePropertyChange()),this.#p.length>0&&e.push(this.makeEvents());break;case b.Removal:n&&e.push(this.makeDestroyEntityChange());break}}makeEvents(){let e={type:p.SendEvents,uuid:this.#e,events:this.#p.slice(0)};return this.#f.size>0&&(e.transferables=Array.from(this.#f)),e}makeCreateEntityChange(){let e={type:p.CreateEntities,uuid:this.#e,token:this.#l};return this.#n=this.#l,this.#u!==void 0&&(e.parentUuid=this.#o=this.#u),this.#d.size>0&&(e.properties=Array.from(this.#d.entries()).filter(([,t])=>t!==void 0),e.properties.forEach(([t,r])=>this.#c.set(t,r))),this.#h!==void 0&&this.#h!==this.#a&&(e.order=this.#a=this.#h),e}makeDestroyEntityChange(){return{type:p.DestroyEntities,uuid:this.#e}}makeSetParentChange(){this.#o=this.#u??void 0;let e={type:p.SetParent,uuid:this.#e,parentUuid:this.#o};return this.#h!==void 0&&this.#h!==this.#a&&(e.order=this.#a=this.#h),e}makeUpdateOrderChange(){return this.#a=this.#h??0,{type:p.UpdateOrder,uuid:this.#e,order:this.#a}}makeChangeToken(){return this.#n=this.#l??S,{type:p.ChangeToken,uuid:this.#e,token:this.#n}}makeChangePropertyChange(){let e=this.#y.map(t=>{if(this.#d.has(t)){let r=this.#d.get(t);return this.#c.set(t,r),[t,r]}else return this.#c.delete(t),[t,void 0]});return{type:p.ChangeProperties,uuid:this.#e,properties:e}}};var qe=i=>{if(!(i===void 0||i.length===0))return i.filter(e=>e.length===1||e[1]!==void 0)},we=(i,e)=>{if(i===e||e===void 0)return i;if(i===void 0)return qe(e);for(let[t,r]of e){let s=i.find(([n])=>n===t);s===void 0?i.push([t,r]):s[1]=r}return qe(i)};var G=class{#e=new Map;get[Symbol.iterator](){return this.#e.entries.bind(this.#e)}clear(){this.#e.clear()}isEmpty(){return this.#e.size===0}hasComponentState(e){return this.#e.has(e)}getComponentState(e){return this.#e.get(e)}write(e){for(let t of e)if(t.type===p.CreateEntities)this.createEntity(t);else if(this.#e.has(t.uuid))switch(t.type){case p.DestroyEntities:this.destroyEntity(t);break;case p.SetParent:this.setParent(t);break;case p.UpdateOrder:this.updateOrder(t);break;case p.ChangeToken:this.changeToken(t);break;case p.ChangeProperties:this.changeProperties(t);break}}changeProperties({uuid:e,properties:t}){let r=this.getComponentState(e);r.properties=we(r.properties,t)}changeToken({uuid:e,token:t}){this.getComponentState(e).token=t||S}updateOrder({uuid:e,order:t}){this.getComponentState(e).order=t??0}setParent({uuid:e,parentUuid:t,order:r}){let s=this.getComponentState(e);s.parentUuid=t,s.order=r??0}destroyEntity({uuid:e}){this.#e.delete(e)}createEntity({uuid:e,token:t,parentUuid:r,order:s,properties:n}){this.#e.set(e,{token:t||S,parentUuid:r,order:s??0,properties:we(void 0,n)})}};var w=class i{static getContextsMap(){return globalThis.__shadowEntsContexts==null&&(globalThis.__shadowEntsContexts=new Map),globalThis.__shadowEntsContexts}static get(e){let t=j(e),r=i.getContextsMap();return r.has(t)?r.get(t):new i(t)}#e=new Map;#t=[];#r=new G;constructor(e=M){let t=j(e),r=i.getContextsMap();if(r.has(t))return r.get(t);this.ns=t,r.set(t,this)}addComponent(e){let t;this.#e.has(e.uuid)?(t=this.#e.get(e.uuid),t.component=e,t.children=[]):(t={component:e,children:[],changes:new W(e.uuid),propIsEqual:void 0},this.#e.set(e.uuid,t)),t.changes.create(e.token,e.parent?.uuid,e.order),e.parent?(this.addToChildren(e.parent,e),t.changes.setParent(e.parent.uuid)):this.#n(e,this.#t),this.#o=void 0}hasComponent(e){return this.#e.has(e.uuid)}hasComponents(){return this.#e.size>0}isRootComponent(e){return this.#t.includes(e.uuid)}destroyComponent(e){if(this.hasComponent(e)){let t=this.#e.get(e.uuid);t.children.slice(0).forEach(r=>this.#e.get(r)?.component.removeFromParent()),t.changes.destroy(),this.#o=void 0}}getChildren(e){return this.#e.get(e.uuid)?.children.map(t=>this.#e.get(t).component)??[]}removeFromParent(e,t){if(this.hasComponent(t)){let r=this.#e.get(e),s=this.#e.get(t.uuid),n=s.children.indexOf(e);n!==-1&&(s.children.splice(n,1),r.changes.setParent(void 0)),this.#n(r.component,this.#t),this.#o=void 0}}changeToken(e,t){this.#e.get(e.uuid)?.changes.changeToken(t)}isChildOf(e,t){return this.hasComponent(t)?this.#e.get(t.uuid).children.includes(e.uuid):!1}addToChildren(e,t){let r=this.#e.get(e.uuid);if(r)this.#n(t,r.children),this.#e.get(t.uuid)?.changes.setParent(e.uuid),A(this.#t,t.uuid),this.#o=void 0;else throw new Error(`the view component ${e.uuid} cannot have a child added to it because the component do not exist!`)}removeSubTree(e){let t=this.#e.get(e);t&&(t.children.slice(0).forEach(r=>this.removeSubTree(r)),this.destroyComponent(t.component),this.#i(e))}setProperty(e,t,r,s){let n=this.#e.get(e.uuid);return n!=null?(s!=null?(n.propIsEqual??=new Map,n.propIsEqual.set(t,s)):n.propIsEqual?.has(t)&&n.propIsEqual.delete(t),n.changes.changeProperty(t,r,s)):!1}removeProperty(e,t){this.#e.get(e.uuid)?.changes.removeProperty(t)}changeOrder(e){if(e.parent){let t=this.#e.get(e.parent.uuid);A(t.children,e.uuid),this.#n(e,t.children)}else A(this.#t,e.uuid),this.#n(e,this.#t);this.#e.get(e.uuid)?.changes.changeOrder(e.order),this.#o=void 0}traverseLevelOrderBFS(){return this.#a().map(e=>e.component)}dispatchShadowObjectsEvent(e,t,r,s){this.#e.get(e.uuid)?.changes.createEvent(t,r,s)}broadcastEvent(e,t=void 0){for(let r of this.traverseLevelOrderBFS())r.dispatchEvent(e,t,!1)}dispatchMessage(e,t,r=void 0,s=!1){this.#e.get(e)?.component.dispatchEvent(t,r,s)}buildChangeTrails(e=!0){let t=[];if(!this.hasComponents())return t;let r=this.#s();for(let s of r)s.buildChangeTrail(t,b.StructuralChanges);for(let s of r)s.buildChangeTrail(t,b.ContentUpdates);for(let s of r)s.buildChangeTrail(t,b.Removal),(s.isDestroyed||s.isNew&&!s.isCreated)&&this.#i(s.uuid),e&&s.clear();return this.#r.write(t),t}reCreateChanges(){if(!this.#r.isEmpty()){this.buildChangeTrails(!1);for(let[e,t]of this.#r){let r=this.#e.get(e);if(r){let s=new W(e);if(s.create(t.token,t.parentUuid,t.order),t.properties)for(let[n,o]of t.properties)s.changeProperty(n,o,r.propIsEqual?.get(n));r.changes.transferEventsTo(s),r.changes.clear(),r.changes=s}}this.#r.clear(),this.broadcastEvent(Re)}}clear(){if(this.#o=void 0,this.#r.clear(),this.#t.slice(0).forEach(e=>this.removeSubTree(e)),this.#t.length!==0)throw new Error("component-context panic: #rootComponents is not empty!");if(this.#e.size!==0)throw new Error("component-context panic: #components is not empty!")}#i(e){this.#e.has(e)&&(this.#e.delete(e),A(this.#t,e),this.#o=void 0)}#s(){return this.#a().filter(e=>e.changes.hasChanges()).map(e=>e.changes)}#n(e,t){if(t.length===0){t.push(e.uuid);return}if(t.includes(e.uuid))return;let r=t.length,s=new Array(r);if(s[0]=this.#e.get(t[0]).component,e.order<s[0].order){t.unshift(e.uuid);return}if(r===1){t.push(e.uuid);return}let n=r-1;if(s[n]=this.#e.get(t[n]).component,e.order>=s[n].order){t.push(e.uuid);return}if(r===2){t.splice(1,0,e.uuid);return}for(let o=n-1;o>=1;o--)if(s[o]=this.#e.get(t[o]).component,e.order>=s[o].order){t.splice(o+1,0,e.uuid);return}}#o;#a(){if(this.#o)return this.#o;let e=new Map,t=(r,s)=>{let n=this.#e.get(r);if(n!=null){e.has(s)?e.get(s).push(n):e.set(s,[n]);for(let o of n.children)t(o,s+1)}};return this.#t.forEach(r=>t(r,0)),this.#o=Array.from(e.entries()).sort((r,s)=>r[0]-s[0]).map(([,r])=>r).flat(),this.#o}};function T(i,e,t,r,s,n){function o(D){if(D!==void 0&&typeof D!="function")throw new TypeError("Function expected");return D}for(var h=r.kind,c=h==="getter"?"get":h==="setter"?"set":"value",l=!e&&i?r.static?i:i.prototype:null,u=e||(l?Object.getOwnPropertyDescriptor(l,r.name):{}),f,y=!1,N=t.length-1;N>=0;N--){var a={};for(var d in r)a[d]=d==="access"?{}:r[d];for(var d in r.access)a.access[d]=r.access[d];a.addInitializer=function(D){if(y)throw new TypeError("Cannot add initializers after decoration has completed");n.push(o(D||null))};var m=(0,t[N])(h==="accessor"?{get:u.get,set:u.set}:u[c],a);if(h==="accessor"){if(m===void 0)continue;if(m===null||typeof m!="object")throw new TypeError("Object expected");(f=o(m.get))&&(u.get=f),(f=o(m.set))&&(u.set=f),(f=o(m.init))&&s.unshift(f)}else(f=o(m))&&(h==="field"?s.unshift(f):u[c]=f)}l&&Object.defineProperty(l,r.name,u),y=!0}function v(i,e,t){for(var r=arguments.length>2,s=0;s<e.length;s++)t=r?e[s].call(i,t):e[s].call(i);return r?t:void 0}import{Priority as dt,emit as Ee,on as ft,onceAsync as Be,retain as pt,retainClear as yt}from"@spearwolf/eventize";import{createEffect as mt,createSignal as gt}from"@spearwolf/signalize";import{signal as He,signalReader as Ge}from"@spearwolf/signalize/decorators";var E=(()=>{var i;let e,t=[],r=[],s,n=[],o=[],h,c=[],l=[],u,f=[],y=[];return class x{static{let a=typeof Symbol=="function"&&Symbol.metadata?Object.create(null):void 0;e=[He()],s=[Ge()],h=[He()],u=[Ge()],T(this,null,e,{kind:"accessor",name:"viewReady",static:!1,private:!1,access:{has:d=>"viewReady"in d,get:d=>d.viewReady,set:(d,m)=>{d.viewReady=m}},metadata:a},t,r),T(this,null,s,{kind:"accessor",name:"viewReady$",static:!1,private:!1,access:{has:d=>"viewReady$"in d,get:d=>d.viewReady$,set:(d,m)=>{d.viewReady$=m}},metadata:a},n,o),T(this,null,h,{kind:"accessor",name:"proxyReady",static:!1,private:!1,access:{has:d=>"proxyReady"in d,get:d=>d.proxyReady,set:(d,m)=>{d.proxyReady=m}},metadata:a},c,l),T(this,null,u,{kind:"accessor",name:"proxyReady$",static:!1,private:!1,access:{has:d=>"proxyReady$"in d,get:d=>d.proxyReady$,set:(d,m)=>{d.proxyReady$=m}},metadata:a},f,y),a&&Object.defineProperty(this,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:a})}static{this.AfterSync="afterSync"}static{this.ContextLost="contextLost"}static{this.ContextCreated="contextCreated"}static get(a){if(a!=null)return globalThis.__shadowEnvs?.get(a)}#e;#t;#r;#i;#s;#n;#o;get viewReady(){return this.#o}set viewReady(a){this.#o=a}#a;get viewReady$(){return this.#a}set viewReady$(a){this.#a=a}#l;get proxyReady(){return this.#l}set proxyReady(a){this.#l=a}#u;get proxyReady$(){return this.#u}set proxyReady$(a){this.#u=a}constructor(){this.#r=!1,this.#i=!1,this.#s=!1,this.ns$=gt(),this.#o=v(this,t,!1),this.#a=(v(this,r),v(this,n,void 0)),this.#l=(v(this,o),v(this,c,!1)),this.#u=(v(this,l),v(this,f,void 0)),this.ready=(v(this,y),()=>this.isReady?Promise.resolve(this):Be(this,x.ContextCreated)),this.#h=()=>{this.#r&&this.#c()},pt(this,x.ContextCreated),ft(this,x.ContextLost,dt.AAA,()=>{yt(this,x.ContextCreated)}),mt(()=>{if(this.viewReady&&this.proxyReady)return this.view.reCreateChanges(),Ee(this,x.ContextCreated,this),this.#i&&(this.#i=!1,this.#c()),()=>{Ee(this,x.ContextLost,this)}},[this.viewReady$,this.proxyReady$])}get view(){return this.#e}set view(a){a!==this.#e&&(this.#e&&this.#e.ns&&globalThis.__shadowEnvs&&globalThis.__shadowEnvs.delete(this.#e.ns),this.#e=a??void 0,this.#e&&this.#e.ns&&(globalThis.__shadowEnvs??=new Map,globalThis.__shadowEnvs.has(this.#e.ns)&&globalThis.__shadowEnvs.get(this.#e.ns)!==this&&console.warn("ShadowEnv: overwrite a namespace already in use",this.#e.ns,globalThis.__shadowEnvs.get(this.#e.ns)),globalThis.__shadowEnvs.set(this.#e.ns,this)),this.viewReady=!!a)}get envProxy(){return this.#t}set envProxy(a){if(a!==this.#t){let d=this.#t;this.#t=a??void 0,this.#t&&(this.#t.onMessageToView=this.#d.bind(this)),d&&d.destroy(),this.proxyReady=!1,a?.start().then(()=>{this.proxyReady=!0}).catch(m=>{console.error("ShadowEnv: failed to start envProxy",m),this.proxyReady=!1})}}get isReady(){return!!(this.#e&&this.#t&&this.proxyReady)}sync(){if(!this.isReady){this.#i=!0;return}this.#r||(this.#r=!0,queueMicrotask(this.#h))}syncWait(){return this.#s=!0,this.sync(),this.#n?this.#n:(this.#n=Be(this,x.AfterSync).then(a=>(this.#n=void 0,a)),this.#n)}destroy(){let a=this.#e?.ns;this.envProxy?.destroy(),this.envProxy=void 0,this.view=void 0,a&&globalThis.__shadowEnvs.has(a)&&globalThis.__shadowEnvs.get(a)===this&&globalThis.__shadowEnvs.delete(a)}#h;async#c(){if(this.#r=!1,this.isReady){let a=this.view.buildChangeTrails();if(a.length>0)try{let d=this.#s;this.#s=!1,await this.envProxy.applyChangeTrail(a,d)}catch(d){console.error("ShadowEnv: failed to apply change trail",d)}finally{Ee(this,x.AfterSync,a)}}}#d(a){console.debug("ShadowEnv: onMessageToView",a.type,a.data),this.view?.dispatchMessage(a.uuid,a.type,a.data,a.traverseChildren)}}})();import{emit as bt,eventize as wt}from"@spearwolf/eventize";var g=["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"],vt=()=>{let i=Math.random()*4294967295|0,e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,r=Math.random()*4294967295|0;return(g[i&255]+g[i>>8&255]+g[i>>16&255]+g[i>>24&255]+"-"+g[e&255]+g[e>>8&255]+"-"+g[e>>16&15|64]+g[e>>24&255]+"-"+g[t&63|128]+g[t>>8&255]+"-"+g[t>>16&255]+g[t>>24&255]+g[r&255]+g[r>>8&255]+g[r>>16&255]+g[r>>24&255]).toLowerCase()},Ye=()=>globalThis?.crypto?.randomUUID?.()??vt();var I=class extends Error{constructor(e){super(e),this.name="ViewComponentError"}},Y=class i{#e;#t;#r;#i;#s=0;get uuid(){return this.#e}get token(){return this.#t}set token(e){e??=S,e!==this.#t&&(this.#t=e,this.#r?.changeToken(this,e))}get parent(){return this.#i}set parent(e){if(e){if(e.#r!==this.#r)throw new I("cannot set parent from different context");e.addChild(this)}else this.removeFromParent()}get context(){return this.#r}set context(e){this.#r!=e&&(this.#r&&this.destroy(),this.#r=e,e&&e.addComponent(this))}get order(){return this.#s}set order(e){let t=this.#s;this.#s=e??0,t!==this.#s&&this.#r.changeOrder(this)}constructor(e,t){wt(this),t instanceof i&&(t={parent:t}),this.#e=t?.uuid??Ye(),this.#t=e,this.#s=t?.order??0,this.#i=t?.parent;let r=t?.context??w.get();if(this.#i&&this.#i.#r!==r)throw new I("cannot set parent from different context");this.context=r}isChildOf(e){return this.#i===e}removeFromParent(){this.#i&&(this.#r?.removeFromParent(this.uuid,this.#i),this.#i=void 0)}addChild(e){if(e.#r!==this.#r)throw new I("cannot add a child from another context");e.isChildOf(this)||(e.removeFromParent(),e.#i=this,this.#r.addToChildren(this,e))}setProperty(e,t,r){this.#r.setProperty(this,e,t,r)}removeProperty(e){this.#r.removeProperty(this,e)}dispatchShadowObjectsEvent(e,t,r){this.#r.dispatchShadowObjectsEvent(this,e,t,r)}dispatchEvent(e,t,r){if(bt(this,e,t),r)for(let s of this.#r.getChildren(this))s.dispatchEvent(e,t,r)}destroy(){this.removeFromParent(),this.#r?.destroyComponent(this),this.#r=void 0}};import{createSignal as Et}from"@spearwolf/signalize";var J="shaeRequestEntParent",K="shaeReRequestEntParent",Je="shae-worker",X="shae-ent",Ke="shae-prop",O="token",P="ns",Z="local",Xe="no-autostart",Q="no-structured-clone",C="auto-sync",ee="src",te="name",re="value",se="type",ie="no-trim";var U=new Set(["on","true","yes","local","1"]);var Ze=i=>j(i.getAttribute(P)),V=(i,e)=>{if(i.hasAttribute(e)){let t=i.getAttribute(e)?.trim()?.toLowerCase()||"1";return U.has(t)}return!1};var _=class extends HTMLElement{static{this.observedAttributes=[P]}get ns(){return this.ns$.value}set ns(e){typeof e=="symbol"?this.ns$.set(e):this.ns$.set(j(e))}constructor(){super(),this.isShaeElement=!0,this.ns$=Et(M),this.#e=!1,this.ns$.onChange(e=>{typeof e=="string"&&e.length>0?this.getAttribute(P)!==e&&this.setAttribute(P,e):this.removeAttribute(P)})}connectedCallback(){this.#t()}attributeChangedCallback(e){e===P&&this.#t()}#e;syncShadowObjects(){this.#e||(this.#e=!0,queueMicrotask(()=>{this.#e=!1,E.get(this.ns)?.sync()}))}#t(){this.ns$.set(Ze(this))}};var ne=class extends _{static{this.observedAttributes=[..._.observedAttributes,O]}get componentContext(){return this.componentContext$.value}get viewComponent(){return this.viewComponent$.value}get uuid(){return this.viewComponent?.uuid}get token(){return this.token$.value}set token(e){this.token$.set(e)}constructor(){super(),this.isShaeEntElement=!0,this.componentContext$=Ce(),this.viewComponent$=Ce(),this.token$=Ce(),this.#s=!0,this.#u=()=>{let e=this.findShadowRootHost();e!=null&&this.dispatchEvent(new CustomEvent(K,{bubbles:!0,composed:!0,detail:{requester:this,shadowRootHost:e}}))},this.#h=e=>{let t=e.detail?.requester;if(t===this||!t?.isShaeEntElement||t.ns!==this.ns)return;let r=e.detail?.shadowRootHost;r&&this.#a?.has(r)&&this.#n()},this.#c=e=>{let t=e.detail?.requester;t!==this&&t?.isShaeEntElement&&t.ns===this.ns&&(e.stopPropagation(),t.#l(this))},this.#d(),this.token$.onChange(e=>{e==null?this.removeAttribute(O):this.getAttribute(O)!==e&&this.setAttribute(O,e)}),this.ns$.onChange(e=>{this.componentContext$.set(w.get(e)),this.isConnected&&this.#n()}),Qe(()=>{let e=this.viewComponent$.get();if(e){let t=e.context?.ns;return()=>{e.destroy(),t&&t!==this.ns?E.get(t)?.sync():this.syncShadowObjects()}}}),this.token$.onChange(e=>{let t=this.viewComponent$.value;t&&(t.token=e,this.syncShadowObjects())})}#e;#t(){this.#e?.();let e=this.componentContext$.onChange(t=>{let r=this.token$.value,s=this.viewComponent$.value;s?s.context=t:t&&(s=new Y(r,{context:t}),this.viewComponent$.set(s)),this.syncShadowObjects()});this.#e=()=>{e()}}#r(){this.#e?.(),this.#e=void 0}#i;#s;findShadowRootHost(){if(this.#s){this.#s=!1;let e=this;for(;e;){if(e.parentElement==null){let t=e.parentNode;t&&(this.#i=t.host);break}e=e.parentElement}}return this.#i}connectedCallback(){this.#s=!0,this.addEventListener("slotchange",this.#u,{capture:!1,passive:!1}),this.addEventListener(J,this.#c,{capture:!1,passive:!1}),this.#t(),Ct(()=>this.#d()),super.connectedCallback(),this.componentContext==null&&this.componentContext$.set(w.get(this.ns)),this.#n(),this.syncShadowObjects()}attributeChangedCallback(e){super.attributeChangedCallback(e),e===O&&this.#d()}disconnectedCallback(){this.#s=!0,this.removeEventListener("slotchange",this.#u,{capture:!1}),this.removeEventListener(J,this.#c,{capture:!1}),this.#l(void 0),this.componentContext$.set(void 0),this.syncShadowObjects(),this.#r()}#n(){this.dispatchEvent(new CustomEvent(J,{bubbles:!0,composed:!0,detail:{requester:this}}))}#o;#a;#l(e){if(this.entParentNode!==e){if(this.entParentNode&&this.entParentNode.removeEventListener(K,this.#h,{capture:!1}),this.entParentNode=e,this.entParentNode&&this.entParentNode.addEventListener(K,this.#h,{capture:!1,passive:!1}),this.#a=void 0,e){let t=[],r=this.parentElement;for(;r&&r!==e;)t.push(r),r.parentElement==null&&r.parentNode?r=r.parentNode.host:r=r.parentElement;t.length>0&&(this.#a=new WeakSet(t))}if(this.#o?.(),this.#o=void 0,e){let[,t]=Qe(()=>{let r=this.viewComponent$.get();if(r){let s=e.viewComponent$.get();r.parent=s&&s.context===r.context?s:void 0,r.parent==null&&queueMicrotask(()=>{this.#n()}),this.syncShadowObjects()}});this.#o=t}else{let t=this.viewComponent;t.parent&&(t.parent=void 0,this.syncShadowObjects())}}}#u;#h;#c;#d(){if(this.hasAttribute(O)){let e=this.getAttribute(O)?.trim()||void 0;this.token$.set(e)}}};customElements.define(X,ne);import{batch as et,connect as St,createEffect as tt,createSignal as $}from"@spearwolf/signalize";var xt=i=>{let e=i.parentElement;for(;e;){if(e.isShaeEntElement)return e;e=e.parentElement}},kt=new Set(["string","text","number","bigint","float","int","integer","hex","hexadecimal","oct","octal","bin","binary","bool","boolean","[]","text[]","string[]","number[]","float[]","int[]","integer[]","hex[]","hexadecimal[]","oct[]","octal[]","bin[]","binary[]","bool[]","boolean[]","int8array","uint8array","uint8clampedarray","int16array","uint16array","int32array","uint32array","float32array","float64array","bigint64array","biguint64array","json"]),oe=class extends HTMLElement{static{this.observedAttributes=[te,re,se,ie]}get name(){return this.name$.value}get value(){return this.valueOut$.value}set value(e){this.valueIn$.set(e)}get shouldTrim(){return this.shouldTrim$.value}get entNode(){return this.entNode$.value}set entNode(e){this.entNode$.set(e)}get viewComponent(){return this.viewComponent$.value}constructor(){super(),this.isShaeEntElement=!0,this.entNode$=$(),this.viewComponent$=$(),this.name$=$(),this.valueIn$=$(),this.valueOut$=$(),this.type$=$(),this.shouldTrim$=$(!0),this.#e=()=>{this.entNode$.set(xt(this))},this.#t=()=>{queueMicrotask(()=>{this.isConnected||this.entNode$.set(void 0)})},this.#r=()=>{this.name$.set(this.getAttribute(te)?.trim()??void 0)},this.#i=()=>{this.valueIn$.set(this.getAttribute(re))},this.#s=()=>{let e=this.getAttribute(se)?.trim().toLowerCase();e&&!kt.has(e)&&(console.warn(`[shae-prop:"${this.name}"] unknown type "${e}"`,{shaeProp:this}),e=void 0),this.type$.set(e)},this.#n=()=>{this.shouldTrim$.set(!V(this,ie))},this.entNode$.onChange(e=>{if(e){let t=St(e.viewComponent$,this.viewComponent$);return()=>{t.destroy()}}else this.viewComponent$.set(void 0)}),tt(()=>{let e=this.viewComponent$.get();if(e){let t=this.name$.get();if(t){let r=this.valueOut$.get();e.setProperty(t,r),this.isConnected&&this.entNode?.syncShadowObjects()}}}),tt(()=>{let e=this.type$.get(),t=this.shouldTrim$.get(),r=this.valueIn$.get();if(t&&typeof r=="string"&&(r=r.trim()),r=r||void 0,r!=null&&typeof r=="string"&&e)switch(e){case"string":case"text":break;case"number":r=Number(r);break;case"bigint":r=BigInt(r);break;case"float":r=parseFloat(r);break;case"int":case"integer":r=parseInt(r,10);break;case"hex":case"hexadecimal":r=parseInt(r,16);break;case"oct":case"octal":r=parseInt(r,8);break;case"bin":case"binary":r=parseInt(r,2);break;case"bool":case"boolean":r=U.has(r.toLowerCase());break;case"[]":case"text[]":case"string[]":r=r.split(/\W+/);break;case"number[]":r=r.split(/\W+/).map(s=>Number(s));break;case"float[]":r=r.split(/\W+/).map(s=>parseFloat(s));break;case"int[]":case"integer[]":r=r.split(/\W+/).map(s=>parseInt(s));break;case"hex[]":case"hexadecimal[]":r=r.split(/\W+/).map(s=>parseInt(s,16));break;case"oct[]":case"octal[]":r=r.split(/\W+/).map(s=>parseInt(s,8));break;case"bin[]":case"binary[]":r=r.split(/\W+/).map(s=>parseInt(s,2));break;case"bool[]":case"boolean[]":r=r.split(/\W+/).map(s=>U.has(s.toLowerCase()));break;case"int8array":r=new Int8Array(r.split(/\W+/).map(s=>Number(s)));break;case"uint8array":r=new Uint8Array(r.split(/\W+/).map(s=>Number(s)));break;case"uint8clampedarray":r=new Uint8ClampedArray(r.split(/\W+/).map(s=>Number(s)));break;case"int16array":r=new Int16Array(r.split(/\W+/).map(s=>Number(s)));break;case"uint16array":r=new Uint16Array(r.split(/\W+/).map(s=>Number(s)));break;case"int32array":r=new Int32Array(r.split(/\W+/).map(s=>Number(s)));break;case"uint32array":r=new Uint32Array(r.split(/\W+/).map(s=>Number(s)));break;case"float32array":r=new Float32Array(r.split(/\W+/).map(s=>Number(s)));break;case"float64array":r=new Float64Array(r.split(/\W+/).map(s=>Number(s)));break;case"bigint64array":r=new BigInt64Array(r.split(/\W+/).map(s=>BigInt(s)));break;case"biguint64array":r=new BigUint64Array(r.split(/\W+/).map(s=>BigInt(s)));break;case"json":r=JSON.parse(r);break;default:console.warn(`[shae-prop:"${this.name}"] unknown type "${e}"`,{value:r,shaeProp:this})}this.valueOut$.set(r)}),et(()=>{this.#r(),this.#i(),this.#s(),this.#n()})}connectedCallback(){et(()=>{this.#e(),this.#r(),this.#i(),this.#s(),this.#n()})}attributeChangedCallback(e){switch(e){case te:this.#r();break;case re:this.#i();break;case se:this.#s();break;case ie:this.#n();break}}disconnectedCallback(){this.#t()}#e;#t;#r;#i;#s;#n};customElements.whenDefined(X).then(()=>customElements.define(Ke,oe));import{on as ut}from"@spearwolf/eventize";import{batch as sr,createEffect as ir,createSignal as ct}from"@spearwolf/signalize";import{emit as At,eventize as Tt,getSubscriptionCount as rt,off as Ot,on as Pt}from"@spearwolf/eventize";var ae,Se=null,F=class{static{this.OnFrame=Symbol("onFrame")}#e=0;#t=0;constructor(){if(Se)return Se;Tt(this),Se=this}start(e){if(e!=null)return rt(this)===0&&this.#i(),Pt(this,ae.OnFrame,e),this.#t++,()=>{this.stop(e)}}stop(e){Ot(this,ae.OnFrame,e),rt(this)===0&&this.#s()}#r=e=>{At(this,ae.OnFrame,e),this.#i()};#i(){this.#e=requestAnimationFrame(this.#r)}#s(){cancelAnimationFrame(this.#e),this.#e=0}};ae=F;import{on as Zt}from"@spearwolf/eventize";import{emit as Ae,eventize as nt,off as Yt,on as ot,once as Jt}from"@spearwolf/eventize";import{batch as Kt,connect as Te,createEffect as Xt,createSignal as de,destroySignal as fe}from"@spearwolf/signalize";import{emit as It,off as Ut,on as it,once as Vt,Priority as zt}from"@spearwolf/eventize";import{batch as qt,createSignal as ke,destroySignals as Bt,value as Ht}from"@spearwolf/signalize";import{createSignal as _t}from"@spearwolf/signalize";var he=class{#e=new Map;keys(){return this.#e.keys()}entries(){return this.#e.entries()}clear(){for(let e of this.#e.values())e.destroy();this.#e.clear()}hasSignal(e){return this.#e.has(e)}getSignal(e){if(!this.#e.has(e)){let t=_t();return this.#e.set(e,t),t}return this.#e.get(e)}getSignalReader(e){return this.getSignal(e).get}getSignalWriter(e){return this.getSignal(e).set}};import{emit as Rt,off as Mt,retain as jt,retainClear as $t}from"@spearwolf/eventize";import{createEffect as Nt,destroySignalsAndEffects as Lt,value as Ft}from"@spearwolf/signalize";import{signal as Dt,signalReader as Wt}from"@spearwolf/signalize/decorators";var ue=(()=>{let i,e=[],t=[],r,s=[],n=[];return class le{static{let h=typeof Symbol=="function"&&Symbol.metadata?Object.create(null):void 0;i=[Dt()],r=[Wt()],T(this,null,i,{kind:"accessor",name:"value",static:!1,private:!1,access:{has:c=>"value"in c,get:c=>c.value,set:(c,l)=>{c.value=l}},metadata:h},e,t),T(this,null,r,{kind:"accessor",name:"value$",static:!1,private:!1,access:{has:c=>"value$"in c,get:c=>c.value$,set:(c,l)=>{c.value$=l}},metadata:h},s,n),h&&Object.defineProperty(this,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:h})}static{this.Value="value"}#e=[];#t;#r=v(this,e,void 0);get value(){return this.#r}set value(h){this.#r=h}#i=(v(this,t),v(this,s,void 0));get value$(){return this.#i}set value$(h){this.#i=h}constructor(){v(this,n),jt(this,le.Value),this.value$(h=>Rt(this,le.Value,h))}add(...h){for(let c of h)this.#e.push(c);this.#n()}clear(){this.#e.length=0,this.#s()}dispose(){this.clear(),Mt(this),Lt(this),$t(this,le.Value)}#s(){this.#t?.(),this.#t=void 0}#n(){this.#s();let[h,c]=Nt(()=>{for(let l of this.#e){let u=Ft(l);if(u!=null){this.value=u;return}}this.value=void 0},this.#e);this.#t=c,h()}}})();var xe="onCreate",R="onDestroy",st="onViewEvent";var ce=class{#e;#t;#r=new he;#i=new Map;#s;#n;#o=new Set;#a=[];#l=0;get kernel(){return this.#e}get uuid(){return this.#t}get order(){return this.#l}set order(e){this.#l!==e&&(this.#l=e,this.#s&&this.parent.resortChildren())}get parentUuid(){return this.#s||void 0}set parentUuid(e){this.#s!==e&&(this.removeFromParent(),this.#s=e||void 0,this.#n=e?this.#e.getEntity(e):void 0,this.#n&&this.#n.addChild(this))}get parent(){return!this.#n&&this.#s&&(this.#n=this.#e.getEntity(this.#s)),this.#n}set parent(e){this.parentUuid=e?.uuid}get hasParent(){return!!this.#s}get children(){return this.#a}constructor(e,t){this.#e=e,this.#t=t,Vt(this,R,zt.Min,this)}traverse(e){e(this);for(let t of this.#a)t.traverse(e)}onDestroy(){this.#r.clear(),Ut(this);for(let e of this.#i.values())e.unsubscribeFromPath(),e.unsubscribeFromParent?.(),e.ctxPath.dispose(),Bt(e.inherited,e.provide,e.context);this.#s=void 0,this.#n=void 0,this.#o.clear(),this.#a.length=0}addChild(e){if(this.#a.length===0){this.#o.add(e.uuid),this.#a.push(e);return}if(this.#o.has(e.uuid))throw new Error(`child with uuid: ${e.uuid} already exists! parentUuid: ${this.uuid}`);this.#o.add(e.uuid),this.#a.push(e),this.resortChildren();for(let[,t]of e.#i)e.#c(t)}resortChildren(){this.#a.sort((e,t)=>e.order-t.order)}removeChild(e){this.#o.has(e.uuid)&&(this.#o.delete(e.uuid),this.#a.splice(this.#a.indexOf(e),1))}removeFromParent(){if(this.#n){this.#n.removeChild(this),this.#n=void 0,this.#s=void 0;for(let[,e]of this.#i)e.unsubscribeFromParent&&(e.unsubscribeFromParent(),e.unsubscribeFromParent=void 0)}}dispatchMessageToView(e,t,r,s=!1){this.#e.dispatchMessageToView({uuid:this.#t,type:e,data:t,transferables:r,traverseChildren:s})}dispatchViewEvents(e){for(let{type:t,data:r}of e)It(this,st,t,r)}dispatchViewEvent(e,t){this.dispatchViewEvents([{type:e,data:t}])}#u(e){return this.#r.getSignal(e)}getPropertyReader(e){return this.#u(e).get}getPropertyWriter(e){return this.#u(e).set}setProperties(e){qt(()=>{for(let[t,r]of e)this.setProperty(t,r)})}setProperty(e,t){this.getPropertyWriter(e)(t)}getProperty(e){return Ht(this.getPropertyReader(e))}propKeys(){return Array.from(this.#r.keys())}propEntries(){return Array.from(this.#r.entries()).map(([e,t])=>[e,t.value])}hasContext(e){return this.#i.has(e)}useContext(e){return this.#h(e).context.get}provideContext(e){return this.#h(e).provide}#h(e){let t=this.#i.get(e);if(t==null){let r=ke(),s=ke(),n=ke(),o=new ue;o.add(s.get,r.get);let h=it(o,ue.Value,c=>{queueMicrotask(()=>{n.set(c)})});t={name:e,inherited:r,provide:s,context:n,ctxPath:o,unsubscribeFromPath:h},this.#i.set(e,t),this.#c(t)}return t}#c(e){this.parent&&(e.unsubscribeFromParent?.(),e.unsubscribeFromParent=it(this.parent.#h(e.name).ctxPath,ue.Value,t=>{e.inherited.set(t)}))}};var z=class{static get(e){return e??Gt}#e=new Map;#t=new Map;define(e,t){this.#e.has(e)?ze(this.#e.get(e).constructors,t):this.#e.set(e,{token:e,constructors:[t]})}appendRoute(e,t){if(this.#t.has(e)){let r=this.#t.get(e);for(let s of t)r.add(s)}else this.#t.set(e,new Set(t))}clearRoute(e){this.#t.delete(e)}findTokensByRoute(e){let t=new Set([e]),r=this.#t.has(e)?[...this.#t.get(e)]:[];for(;r.length;){let s=r.shift();t.has(s)||(t.add(s),this.#t.has(s)&&r.push(...Array.from(this.#t.get(s)).filter(n=>!t.has(n))))}return Array.from(t)}findConstructors(e){let t=this.findTokensByRoute(e),r=new Set;for(let s of t){let n=this.#e.get(s);if(n)for(let o of n.constructors)r.add(o)}return r.size>0?Array.from(r):void 0}hasToken(e){return this.#e.has(e)}hasRoute(e){return this.#t.has(e)}clear(){this.#e.clear(),this.#t.clear()}},Gt=new z;var k;(function(i){i[i.CreateAndDestroy=0]="CreateAndDestroy",i[i.JustCreate=1]="JustCreate",i[i.DestroyOnly=2]="DestroyOnly"})(k||(k={}));var at=i=>i.displayName||i.name,pe=class{#e=new Map;#t=new Set;#r;#i;#s=!0;constructor(e){nt(this),this.registry=z.get(e)}getEntity(e){let t=this.#e.get(e)?.entity;if(!t)throw new Error(`entity with uuid "${e}" not found!`);return t}hasEntity(e){return this.#e.has(e)}traverseLevelOrderBFS(e=!1){if(this.#s){let t=new Map,r=(s,n)=>{let o=this.getEntity(s);t.has(n)?t.get(n).push(o):t.set(n,[o]);for(let h of o.children)r(h.uuid,n+1)};this.#t.forEach(s=>r(s,0)),this.#r=Array.from(t.entries()).sort((s,n)=>s[0]-n[0]).map(([,s])=>s).flat(),this.#i=this.#r.slice().reverse(),this.#s=!1}return e?this.#i:this.#r}getEntityGraph(){return Array.from(this.#t).map(e=>this.getEntityGraphNode(e))}getEntityGraphNode(e){if(!this.#e.has(e))return;let{token:t,entity:r}=this.#e.get(e);return{token:t,entity:r,props:Object.fromEntries(r.propEntries()),children:r.children.map(s=>this.getEntityGraphNode(s.uuid))}}upgradeEntities(){for(let e of this.traverseLevelOrderBFS(!0))this.updateShadowObjects(e.uuid,k.DestroyOnly);for(let e of this.traverseLevelOrderBFS(!1))this.updateShadowObjects(e.uuid,k.JustCreate)}run(e){Kt(()=>{for(let t of e.changeTrail)this.parse(t)})}parse(e){switch(e.type){case p.CreateEntities:this.createEntity(e.uuid,e.token,e.parentUuid,e.order,e.properties),this.#s=!0;break;case p.DestroyEntities:this.destroyEntity(e.uuid),this.#s=!0;break;case p.SetParent:this.setParent(e.uuid,e.parentUuid,e.order),this.#s=!0;break;case p.UpdateOrder:this.updateOrder(e.uuid,e.order),this.#s=!0;break;case p.ChangeProperties:this.changeProperties(e.uuid,e.properties);break;case p.ChangeToken:this.changeToken(e.uuid,e.token);break;case p.SendEvents:this.dispatchEventsToEntity(e.uuid,e.events);break}}createEntity(e,t,r,s=0,n){let o=new ce(this,e);o.order=s;let h={token:t,entity:o,usedConstructors:new Map};this.#e.set(e,h),r&&(o.parentUuid=r),o.hasParent||this.#t.add(e),n&&o.setProperties(n),this.createShadowObjects(e)}destroyEntity(e){if(!this.#e.has(e))return;let{entity:t,usedConstructors:r}=this.#e.get(e);t.removeFromParent(),Ae(t,R,this),r.clear(),this.#e.delete(t.uuid),this.#t.delete(t.uuid)}setParent(e,t,r=0){let s=this.getEntity(e);s.parentUuid===t&&s.order===r||(s.removeFromParent(),s.order=r,s.parentUuid=t,s.hasParent?this.#t.delete(e):this.#t.add(e))}updateOrder(e,t){this.getEntity(e).order=t}dispatchEventsToEntity(e,t){this.getEntity(e)?.dispatchViewEvents(t)}changeProperties(e,t){this.getEntity(e).setProperties(t)}changeToken(e,t){if(!this.#e.has(e))return;let r=this.#e.get(e);r.token!==t&&(r.token=t,this.updateShadowObjects(e))}dispatchMessageToView(e){queueMicrotask(()=>{Ae(this,L,e)})}updateShadowObjects(e,t=k.CreateAndDestroy){let r=this.#e.get(e),s=new Set(this.registry.findConstructors(r.token)),n=t===k.CreateAndDestroy||t===k.DestroyOnly,o=t===k.CreateAndDestroy||t===k.JustCreate;if(n){for(let[h,c]of r.usedConstructors)if(!s.has(h)){r.usedConstructors.delete(h);for(let l of c)this.destroyShadowObject(l,r.entity)}}if(o)for(let h of s)r.usedConstructors.has(h)||this.constructShadowObject(h,r)}constructShadowObject(e,t){let r=new Set,s=new Set,n=new Map,o=new Map,h=new Map,c=nt(new e({entity:t.entity,provideContext(l,u,f){let y=o.get(l);if(y===void 0){y=de(u,f?{compareFn:f}:void 0),o.set(l,y);let N=Te(y,t.entity.provideContext(l));s.add(N.destroy.bind(N))}return y},useContext(l,u){let f=n.get(l);if(f===void 0){[f]=de(void 0,u?{compareFn:u}:void 0),n.set(l,f);let y=Te(t.entity.useContext(l),f);s.add(y.destroy.bind(y))}return f},useProperty(l,u){let f=h.get(l);if(f===void 0){[f]=de(void 0,u?{compareFn:u}:void 0),h.set(l,f);let y=Te(t.entity.getPropertyReader(l),f);s.add(y.destroy.bind(y))}return f},createEffect(...l){let u=Xt(...l);return s.add(u[1]),u},createSignal(...l){let u=de(...l);return s.add(()=>{fe(u)}),u},on(...l){let u=ot(...l);return s.add(u),u},onDestroy(l){r.add(l)}}));return console.debug("[Kernel] create shadow-object",at(e),{shadowObject:c,entity:t.entity}),Jt(c,R,()=>{console.debug("[Kernel] destroy shadow-object",at(e),{shadowObject:c,entity:t.entity});for(let u of r)u();for(let u of s)u();for(let u of n.values())fe(u);for(let u of h.values())fe(u);for(let[u]of o.values())fe(u);r.clear(),s.clear(),n.clear(),h.clear(),o.clear();let l=t.usedConstructors.get(e);l&&(l.delete(c),l.size===0&&t.usedConstructors.delete(e))}),t.usedConstructors.has(e)?t.usedConstructors.get(e).add(c):t.usedConstructors.set(e,new Set([c])),this.attachShadowObject(c,t.entity),c}createShadowObjects(e){let t=this.#e.get(e);this.registry.findConstructors(t.token)?.forEach(r=>{this.constructShadowObject(r,t)})}findShadowObjects(e){if(!this.#e.has(e))return[];let{usedConstructors:t}=this.#e.get(e);return Array.from(new Set(Array.from(t.values()).map(r=>Array.from(r)).flat()))}attachShadowObject(e,t){ot(t,e),typeof e[xe]=="function"&&e[xe](t)}destroyShadowObject(e,t){typeof e[R]=="function"&&e[R](t),Ae(e,R,t),Yt(t,e)}destroy(){for(let e of this.traverseLevelOrderBFS().reverse())this.destroyEntity(e.uuid)}};async function Oe(i,e,t,r=!0){if(t.has(e)){console.warn("importModule: skipping already imported module",e);return}else t.add(e);e.extends&&await Promise.all(e.extends.map(n=>Oe(i,n,t,!1)));let{registry:s}=i;if(e.define)for(let[n,o]of Object.entries(e.define))s.define(n,o);if(e.routes)for(let[n,o]of Object.entries(e.routes))s.appendRoute(n,o);await(e.initialize?.({define:(n,o)=>s.define(n,o),kernel:i,registry:s})??Promise.resolve()),r&&i.upgradeEntities()}var ye=i=>(typeof i=="string"&&(i=new URL(i,globalThis.location.href)),i.toString());function ht(i){return i.map(e=>{if(e.transferables&&e.transferables.length>0){let{transferables:t,...r}=e;return structuredClone(r,{transfer:t})}else return structuredClone(e)})}var me=class{#e;get registry(){return this.kernel.registry}constructor(e){this.#e=new Set,this.isLocalEnv=!0,this.disableStructuredClone=!1,this.kernel=new pe(e),Zt(this.kernel,L,t=>{if(this.onMessageToView!=null){let{type:r,uuid:s,traverseChildren:n}=t,o=structuredClone(t.data,{transfer:t.transferables});this.onMessageToView({type:r,uuid:s,data:o,traverseChildren:n})}})}start(){return Promise.resolve()}applyChangeTrail(e,t){let r={changeTrail:this.disableStructuredClone?e:ht(e)},s;try{this.kernel.run(r),s=Promise.resolve()}catch(n){s=Promise.reject(n)}return s}async importScript(e){let t=await import(ye(e));t[ve]&&await this.importModule(t[ve])}async importModule(e){return Oe(this.kernel,e,this.#e)}destroy(){this.kernel.destroy(),this.registry.clear(),this.#e.clear()}};import{emit as Qt,onceAsync as er,retain as tr}from"@spearwolf/eventize";function Pe(i){let e=new Blob([i],{type:"text/javascript"}),t=URL.createObjectURL(e),r=new Worker(t);return URL.revokeObjectURL(t),r}function _e(){return Pe(`var dr=Object.defineProperty;var Et=Object.getOwnPropertySymbols;var yr=Object.prototype.hasOwnProperty,pr=Object.prototype.propertyIsEnumerable;var bt=e=>{throw TypeError(e)};var gr=(e,t,r)=>t in e?dr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var St=(e,t)=>{var r={};for(var s in e)yr.call(e,s)&&t.indexOf(s)<0&&(r[s]=e[s]);if(e!=null&&Et)for(var s of Et(e))t.indexOf(s)<0&&pr.call(e,s)&&(r[s]=e[s]);return r};var d=(e,t,r)=>gr(e,typeof t!="symbol"?t+"":t,r),Ye=(e,t,r)=>t.has(e)||bt("Cannot "+r);var i=(e,t,r)=>(Ye(e,t,"read from private field"),r?r.call(e):t.get(e)),f=(e,t,r)=>t.has(e)?bt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,r),h=(e,t,r,s)=>(Ye(e,t,"write to private field"),s?s.call(e,r):t.set(e,r),r),E=(e,t,r)=>(Ye(e,t,"access private method"),r);var wt=(e,t,r,s)=>({set _(n){h(e,t,n,r)},get _(){return i(e,t,s)}});var pe="*",Ot=1,tt=2,rt=4,re=Symbol.for("eventize"),mr="[eventize]",qe=e=>e===pe,kt=e=>{switch(typeof e){case"string":case"symbol":return!0;default:return!1}},Pt=typeof console!="undefined",vr=Pt?console[console.warn?"warn":"log"].bind(console,mr):()=>{},Er=(e,t,r)=>(Object.defineProperty(e,t,{value:r,configurable:!0}),e),br=0,Ft=class{constructor(){d(this,"events",new Map);d(this,"eventNames",new Set)}static publish(e){e.sort((t,r)=>t.order-r.order).forEach(t=>t.emit())}add(e){Array.isArray(e)?e.forEach(t=>this.eventNames.add(t)):this.eventNames.add(e)}remove(e){Array.isArray(e)?e.forEach(t=>this.eventNames.delete(t)):this.eventNames.delete(e),this.clear(e)}clear(e){Array.isArray(e)?e.forEach(t=>this.events.delete(t)):this.events.delete(e)}retain(e,t){this.eventNames.has(e)&&this.events.set(e,{args:t,order:br++})}isKnown(e){return this.eventNames.has(e)}emit(e,t,r=[]){if(qe(e))this.eventNames.forEach(s=>this.emit(s,t,r));else if(this.events.has(e)){let{order:s,args:n}=this.events.get(e);r.push({order:s,emit:()=>t.apply(e,n)})}return r}},Ze=(e,t,r,s)=>{if(typeof t=="function"){let n=t.apply(e,r);n!=null&&(s==null||s(n))}},Sr=(e,t,r,s)=>Ze(t,t.emit,[e].concat(r),s),wr=e=>{switch(typeof e){case"function":return Ot;case"string":case"symbol":return tt;case"object":return rt}},Cr=0,Ar=()=>++Cr,Mt=class{constructor(e,t,r,s=null){d(this,"id");d(this,"eventName");d(this,"isCatchEmAll");d(this,"priority");d(this,"listener");d(this,"listenerObject");d(this,"listenerType");d(this,"callAfterApply");d(this,"isRemoved");d(this,"refCount");this.id=Ar(),this.eventName=e,this.isCatchEmAll=qe(e),this.listener=r,this.listenerObject=s,this.priority=t,this.listenerType=wr(r),this.callAfterApply=void 0,this.isRemoved=!1,this.refCount=1}isEqual(e,t=null){if(e===this)return!0;let r=typeof e;return r==="number"&&e===this.id?!0:t===null&&(r==="string"||r==="symbol")?e===pe||e===this.eventName:this.listener===e&&this.listenerObject===t}apply(e,t,r){if(this.isRemoved)return;let{listener:s,listenerObject:n}=this;switch(this.listenerType){case Ot:Ze(n,s,t,r),this.callAfterApply&&this.callAfterApply();break;case tt:Ze(n,n[s],t,r),this.callAfterApply&&this.callAfterApply();break;case rt:{let a=s[e];if(this.isCatchEmAll||this.eventName===e){if(typeof a=="function"){let o=a.apply(s,t);o!=null&&(r==null||r(o))}else Sr(e,s,t,r);this.callAfterApply&&this.callAfterApply()}break}}}},xr=(e,t)=>e.priority!==t.priority?t.priority-e.priority:e.id-t.id,Ct=e=>e==null?void 0:e.slice(0),At=(e,t)=>{let r=e.indexOf(t);r>-1&&e.splice(r,1)},Or=e=>e===rt||e===tt,et=(e,t,r)=>{let s=e.findIndex(n=>n.isEqual(t,r));s>-1&&(e[s].isRemoved=!0,e.splice(s,1))},Ne=(e,t,r)=>{let s=[];for(let n of e)(t==null&&n.listenerObject===r||n.eventName===t&&n.listener===r)&&s.push(n);for(let n of s)et(e,n,void 0)},Xe=e=>{e&&(e.forEach(t=>{t.isRemoved=!0}),e.length=0)},kr=(e,t)=>e.listenerType===t.listenerType?e.priority===t.priority&&e.eventName===t.eventName&&e.listenerObject===t.listenerObject&&e.listener===t.listener:!1,Pr=(e,t)=>{if(Or(e.listenerType))return t.find(r=>kr(e,r))},Fr=(e,t)=>{let r=Pr(e,t);return r?(r.refCount+=1,r):(t.push(e),t.sort(xr),e)},Mr=class{constructor(){d(this,"namedListeners");d(this,"catchEmAllListeners");d(this,"getListenersForEventName",e=>{let t=this.namedListeners.get(e);return t||(t=[],this.namedListeners.set(e,t)),t});this.namedListeners=new Map,this.catchEmAllListeners=[]}add(e){return Fr(e,e.isCatchEmAll?this.catchEmAllListeners:this.getListenersForEventName(e.eventName))}remove(e,t,r=!1){t==null&&Array.isArray(e)?e.forEach(s=>this.remove(s,null,r)):e==null||t==null&&qe(e)?this.removeAllListeners():t==null&&kt(e)?Xe(this.namedListeners.get(e)):e instanceof Mt?e.isRemoved||(e.refCount-=1,e.refCount<1&&(e.isRemoved=!0,this.namedListeners.forEach(s=>At(s,e)),At(this.catchEmAllListeners,e))):r?qe(e)?Ne(this.catchEmAllListeners,pe,e):this.namedListeners.forEach(s=>Ne(s,e,t)):(this.namedListeners.forEach(s=>{et(s,e,t),Ne(s,void 0,e)}),et(this.catchEmAllListeners,e,t),Ne(this.catchEmAllListeners,void 0,e))}removeAllListeners(){this.namedListeners.forEach(e=>Xe(e)),this.namedListeners.clear(),Xe(this.catchEmAllListeners)}forEach(e,t){let r=Ct(this.catchEmAllListeners),s=Ct(this.namedListeners.get(e));if(e===pe||!s||s.length===0)r.forEach(t);else if(r.length===0)s.forEach(t);else{let n=s.length,a=r.length,o=0,c=0;for(;o<n||c<a;){if(o<n){let l=s[o];if(c>=a||l.priority>=r[c].priority){t(l),++o;continue}}c<a&&(t(r[c]),++c)}}}getSubscriptionCount(){let e=this.catchEmAllListeners.length;for(let t of this.namedListeners.values())e+=t.length;return e}},Se=e=>!!(e&&e[re]);function Fe(e){if(Se(e))return e;let t=new Mr,r=new Ft;return Er(e,re,{keeper:r,store:t}),e}var st={Max:Number.POSITIVE_INFINITY,AAA:1e9,BB:1e6,C:1e3,Default:0,Low:-1e4,Min:Number.NEGATIVE_INFINITY},Tr=(e,t,r,s,n,a,o)=>{let c=e.add(new Mt(r,s,n,a));return t.emit(r,c,o),c},jr=(e,t,r,s)=>{let n=r.length,a=typeof r[0],o,c,l,u;if(n>=2&&n<=3&&a==="number"?(o=pe,[c,l,u]=r):n>=3&&n<=4&&typeof r[1]=="number"?[o,c,l,u]=r:(c=st.Default,a==="string"||a==="symbol"||Array.isArray(r[0])?[o,l,u]=r:(o=pe,[l,u]=r)),!l&&Pt)throw vr("called with insufficient arguments!",r),"subscribeTo() called with insufficient arguments!";let y=p=>ye=>Tr(e,t,ye,p,l,u,s);return Array.isArray(o)?o.map(p=>Array.isArray(p)?y(p[1])(p[0]):y(c)(p)):y(c)(o)},Tt=(e,t,r)=>{let s=[],n=jr(e,t,r,s);return Ft.publish(s),n},xt=e=>t=>{t.callAfterApply=()=>{e==null||e()}},jt=(e,t)=>Object.assign(()=>b(e,t),Array.isArray(t)?{listeners:t}:{listener:t}),Lt=(e,t,r,s)=>{let{store:n,keeper:a}=e[re];Array.isArray(t)?t.forEach(o=>{n.forEach(o,c=>c.apply(o,r,s)),a.retain(o,r)}):t!==pe&&(n.forEach(t,o=>{o.apply(t,r,s)}),a.retain(t,r))},x=(e,...t)=>{let r=Fe(e),{store:s,keeper:n}=r[re];return jt(r,Tt(s,n,t))},B=(e,...t)=>{let r=Fe(e),{store:s,keeper:n}=r[re],a=Tt(s,n,t),o=jt(r,a),c=!1,l=()=>{c||(o(),c=!0)};return Array.isArray(a)?a.forEach(xt(l)):xt(l)(a),l},Lr=(e,t)=>new Promise(r=>{B(e,t,r)}),b=(e,t,r)=>{if(!Se(e))throw new Error("object is not eventized");let{store:s,keeper:n}=e[re],a=typeof t,o=r!=null&&(a==="string"||a==="symbol");s.remove(t,r,o),Array.isArray(t)?n.remove(t.filter(c=>typeof c=="string")):kt(t)&&n.remove(t)},m=(e,t,...r)=>{if(!Se(e))throw new Error("object is not eventized");Lt(e,t,r)},Rr=(e,t,...r)=>{if(!Se(e))throw new Error("object is not eventized");let s=[];return Lt(e,t,r,n=>{s.push(n)}),s=s.map(n=>Array.isArray(n)?Promise.all(n):Promise.resolve(n)),s.length>0?Promise.all(s):Promise.resolve()},Me=(e,t)=>{let r=Fe(e),{keeper:s}=r[re];s.add(t)},it=(e,t)=>{if(!Se(e))throw new Error("object is not eventized");let{keeper:r}=e[re];r.clear(t)},V=(()=>{let e=(t={})=>Fe(t);return e.inject=(t={})=>(t=Fe(t),Object.assign(t,{on:(...r)=>x(t,...r),once:(...r)=>B(t,...r),onceAsync:r=>Lr(t,r),off:(r,s)=>b(t,r,s),emit:(r,...s)=>m(t,r,...s),emitAsync:(r,...s)=>Rr(t,r,...s),retain:r=>Me(t,r),retainClear:r=>it(t,r)}),t),e.is=Se,e})();var z=Symbol.for("signal"),nt=Symbol.for("destroySignal"),ot=Symbol.for("createEffect"),Rt=Symbol.for("destroyEffect");var Te,je,we=class{constructor(t="id",r=1){f(this,Te);f(this,je);h(this,Te,t),h(this,je,r)}make(){return Symbol(\`\${i(this,Te)}\${wt(this,je)._++}\`)}};Te=new WeakMap,je=new WeakMap;var se=V(),ge=V(),ie=V();var Le,ne=class{constructor(){f(this,Le,new Set)}batch(t){i(this,Le).add(t)}run(){m(ie,Array.from(i(this,Le)))}};Le=new WeakMap,d(ne,"current");var Dt=()=>ne.current;function Re(e){let t=ne.current;t?t=void 0:t=ne.current=new ne;try{e()}finally{t&&(ne.current=void 0,t.run())}}var at=[],Qe=()=>at.at(-1),zt=(e,t)=>{at.push(e);try{return t()}finally{at.pop()}};var Dr=e=>e!=null&&typeof e.then=="function",oe,ae,me,ve,Ce,G=class G{constructor(t,r){d(this,"id");d(this,"callback");f(this,oe);f(this,ae,new Set);f(this,me,new Set);d(this,"parentEffect");d(this,"childEffects",[]);d(this,"curChildEffectSlot",0);d(this,"autorun",!0);d(this,"shouldRun",!0);f(this,ve);f(this,Ce,!1);var s;this.callback=t,this.autorun=(s=r==null?void 0:r.autorun)!=null?s:!0,h(this,ve,r==null?void 0:r.dependencies),this.id=G.idGen.make(),x(ie,this.id,"recall",this),++G.count}hasStaticDeps(){return i(this,ve)!=null&&i(this,ve).length>0}saveSignalsFromDeps(){for(let t of i(this,ve))this.whenSignalIsRead(S(t).id)}static createEffect(t,r,s){let n=Array.isArray(r)?r:void 0,a=n?s!=null?s:{dependencies:n}:r;a&&n&&(a.dependencies=n);let o,c=Qe();return c!=null?(o=c.getCurrentChildEffect(),o==null&&(o=new G(t,a),c.attachChildEffect(o),m(ie,ot,o)),c.curChildEffectSlot++):(o=new G(t,a),m(ie,ot,o)),o.hasStaticDeps()?o.saveSignalsFromDeps():o.autorun&&o.run(),[o.run.bind(o),o.destroy.bind(o)]}getCurrentChildEffect(){return this.childEffects[this.curChildEffectSlot]}attachChildEffect(t){this.childEffects.push(t),this.parentEffect=this}run(){if(i(this,Ce)||!this.shouldRun)return;let t=Dt();t?t.batch(this.id):(this.runCleanupCallback(),this.curChildEffectSlot=0,this.shouldRun=!1,this.hasStaticDeps()?h(this,oe,this.callback()):h(this,oe,zt(this,this.callback)))}recall(){this.shouldRun=!0,this.autorun&&this.run()}whenSignalIsRead(t){i(this,ae).has(t)||(i(this,ae).add(t),x(se,t,"recall",this),B(ge,t,nt,this))}[nt](t){!i(this,me).has(t)&&i(this,ae).has(t)&&(i(this,me).add(t),b(se,t,this),i(this,me).size===i(this,ae).size&&this.destroy())}runCleanupCallback(){if(i(this,oe)!=null){let t=i(this,oe);h(this,oe,void 0),Dr(t)?Promise.resolve(t).then(r=>{typeof r=="function"&&r()}):t()}}destroy(){i(this,Ce)||(m(ie,Rt,this),this.runCleanupCallback(),b(se,this),b(ie,this),b(ge,this),h(this,Ce,!0),i(this,ae).clear(),i(this,me).clear(),this.childEffects.forEach(t=>{t.destroy()}),this.childEffects.length=0,--G.count)}};oe=new WeakMap,ae=new WeakMap,me=new WeakMap,ve=new WeakMap,Ce=new WeakMap,d(G,"idGen",new we("ef")),d(G,"count",0);var Ve=G;var ce=(...e)=>Ve.createEffect(...e);var W=new WeakMap,T=(e,t)=>{var r;return(r=W.get(e))==null?void 0:r.signals[t]},It=e=>{var r;let t=(r=W.get(e))==null?void 0:r.signals;if(t)return Object.values(t)};var $t=(e,t,r)=>{let s=W.get(e);s?s.signals[t]=r:W.set(e,{signals:{[t]:r},effects:{}})};function ct(...e){for(let t of e)if(W.has(t)){let r=W.get(t);for(let s of Object.values(r.signals))U(s);r.signals={}}}function lt(...e){for(let t of e)if(W.has(t)){let{signals:r,effects:s}=W.get(t);for(let n of Object.values(r))U(n);for(let[,n]of Object.values(s))n();W.delete(t)}}function Bt(e){let t=S(le(e)?e:T(...e));t!=null&&!t.muted&&!t.destroyed&&Ge(t.id,t.value,{touch:!0})}function K(e){var t,r;return le(e)?(t=S(e))==null?void 0:t.value:(r=S(T(...e)))==null?void 0:r.value}var Ut,We=class{constructor(t){d(this,Ut);this[z]=t}get get(){return this[z].reader}get set(){return this[z].writer}*[(Ut=z,Symbol.iterator)](){yield this.get,yield this.set}get value(){return K(this.get)}set value(t){this.set(t)}onChange(t){let[,r]=ce(()=>t(this.value),[this.get]);return r}get muted(){return this[z].muted}set muted(t){this[z].muted=t}touch(){Bt(this)}destroy(){U(this)}};var zr=0;function Nt(){return zr>0}var Ir=new we("si");function qt(e){var t;Nt()||(t=Qe())==null||t.whenSignalIsRead(e)}function Ge(e,t,r){m(se,e,t,r)}var le=e=>e!=null&&e[z]!=null,$r=e=>{let t=r=>{var s;return r?ce(()=>(e.destroyed||qt(e.id),r(e.value)),[t]):e.destroyed||((s=e.beforeReadFn)==null||s.call(e),qt(e.id)),e.value};return Object.defineProperty(t,z,{value:e}),t},I,_e=class _e{constructor(t,r){d(this,"id");d(this,"lazy");d(this,"compareFn");d(this,"beforeReadFn");d(this,"muted",!1);d(this,"destroyed",!1);f(this,I);d(this,"valueFn");d(this,"reader");d(this,"writer",(t,r)=>{var c,l,u;let s=(c=r==null?void 0:r.lazy)!=null?c:!1,n=(l=r==null?void 0:r.compareFn)!=null?l:this.compareFn,a=n!=null?n:(y,p)=>y===p;if((s!==this.lazy||s&&t!==this.valueFn||!s&&!a(t,i(this,I)))&&(s?(h(this,I,void 0),this.valueFn=t,this.lazy=!0):(h(this,I,t),this.valueFn=void 0,this.lazy=!1),!this.muted&&!this.destroyed)){Ge(this.id,i(this,I));return}((u=r==null?void 0:r.touch)!=null?u:!1)&&Ge(this.id,i(this,I),{touch:!0})});d(this,"object");this.id=Ir.make(),++_e.instanceCount,this.lazy=t,this.lazy?(this.value=void 0,this.valueFn=r):(this.value=r,this.valueFn=void 0),this.reader=$r(this),this.object=new We(this)}get value(){return this.lazy&&(h(this,I,this.valueFn()),this.valueFn=void 0,this.lazy=!1),i(this,I)}set value(t){h(this,I,t)}};I=new WeakMap,d(_e,"instanceCount",0);var Ke=_e,S=e=>e==null?void 0:e[z];function O(e=void 0,t){var s;let r;if(le(e))r=S(e);else{let n=(s=t==null?void 0:t.lazy)!=null?s:!1;r=new Ke(n,e),r.beforeReadFn=t==null?void 0:t.beforeReadFn,r.compareFn=t==null?void 0:t.compareFn}return r.object}var U=(...e)=>{for(let t of e){let r=S(t);r!=null&&!r.destroyed&&(r.destroyed=!0,r.beforeReadFn=void 0,--Ke.instanceCount,m(ge,r.id,r.id))}};var w,Ae=new WeakMap,De=new WeakMap,Qt=e=>typeof e=="function",he;(function(e){e.Signal="signal",e.Function="function",e.Property="property"})(he||(he={}));var Q,Vt,Gt,Wt,Kt,Ee,k,q,P,_,ue,ze,ht,N=class{constructor(t,r,s){f(this,ze);f(this,Ee);f(this,k,!1);f(this,q);f(this,P);f(this,_);f(this,ue);var a,o;let n=w.findConnection(t,r);if(n!=null)return n;V(this),Me(this,w.Value),h(this,q,S(t)),le(r)?(h(this,P,S(r)),h(this,_,he.Signal)):Qt(r)?(h(this,P,r),h(this,_,he.Function)):(h(this,P,r),h(this,_,he.Property)),h(this,ue,s),h(this,Ee,x(se,i(this,q).id,(c,l)=>{(l==null?void 0:l.touch)===!0?this.touch():E(this,ze,ht).call(this,!1)})),B(ge,i(this,q).id,"destroy",this),E(a=w,Q,Vt).call(a,this),s!=null&&E(o=w,Q,Wt).call(o,s,this),this.touch()}static findConnectionsBySignal(t){return Ae.get(S(t))}static findConnectionsByTarget(t){let r=De.get(t);return r?Array.from(r):void 0}static findConnectionsByObject(t){let r=new Set,s=It(t);if(s)for(let a of s.flatMap(o=>{let c=w.findConnectionsBySignal(o);return c?Array.from(c):[]}))r.add(a);let n=w.findConnectionsByTarget(t);if(n)for(let a of n)r.add(a);return r.size>0?Array.from(r):void 0}static findConnection(t,r){let s=Ae.get(S(t));if(s!=null){let n=Array.from(s),a=-1;if(le(r)){let o=S(r);a=n.findIndex(c=>i(c,P)===o)}else Qt(r)?a=n.findIndex(o=>i(o,P)===r):a=n.findIndex(o=>{if(i(o,_)===he.Property){let c=i(o,P);return c[0]===r[0]&&c[1]===r[1]}return!1});if(a>=0)return n[a]}}get isMuted(){return i(this,k)}nextValue(){return new Promise((t,r)=>{let s=0,n=[x(this,w.Value,a=>{s===1?(n.forEach(o=>{o()}),t(a)):++s}),x(this,w.Destroy,()=>{n.forEach(a=>{a()}),r()})]})}touch(){return E(this,ze,ht).call(this,!0)}mute(){return!this.isDestroyed&&!i(this,k)&&(h(this,k,!0),m(this,w.Mute,this)),this}unmute(){return!this.isDestroyed&&i(this,k)&&(h(this,k,!1),m(this,w.Unmute,this)),this}toggle(){return this.isDestroyed||(h(this,k,!i(this,k)),m(this,i(this,k)?w.Mute:w.Unmute,this)),i(this,k)}destroy(){var t,r,s;this.isDestroyed||(m(this,w.Destroy,this),b(this),E(t=w,Q,Gt).call(t,this),(r=i(this,Ee))==null||r.call(this),h(this,Ee,void 0),h(this,q,void 0),h(this,P,void 0),i(this,ue)!=null&&(E(s=w,Q,Kt).call(s,i(this,ue),this),h(this,ue,void 0)))}get isDestroyed(){return i(this,Ee)==null}hasTarget(t){return i(this,ue)===t}};Q=new WeakSet,Vt=function(t){if(!t.isDestroyed){let r=i(t,q),s=Ae.get(r);s?s.add(t):(s=new Set([t]),Ae.set(r,s))}},Gt=function(t){if(!t.isDestroyed){let r=i(t,q),s=Ae.get(r);s&&(s.delete(t),s.size===0&&Ae.delete(r))}},Wt=function(t,r){if(!r.isDestroyed){let s=De.get(t);s?s.add(r):(s=new Set([r]),De.set(t,s))}},Kt=function(t,r){if(!r.isDestroyed){let s=De.get(t);s&&(s.delete(r),s.size===0&&De.delete(t))}},Ee=new WeakMap,k=new WeakMap,q=new WeakMap,P=new WeakMap,_=new WeakMap,ue=new WeakMap,ze=new WeakSet,ht=function(t){if(!i(this,k)&&!this.isDestroyed){let{value:r}=i(this,q);if(i(this,_)===he.Signal)i(this,P).writer(r,t?{touch:t}:void 0);else if(i(this,_)===he.Function)i(this,P).call(this,r);else{let[s,n]=i(this,P);s[n](r)}m(this,w.Value,r)}return this},f(N,Q),d(N,"Value","value"),d(N,"Mute","mute"),d(N,"Unmute","unmute"),d(N,"Destroy","destroy");w=N;function Ie(e,t){var o;let r=Array.isArray(e)?T(...e):e,s=Array.isArray(t),n=s&&(o=T(...t))!=null?o:t,a=s?t[0]:t;return new N(r,n,a)}var _t=e=>{if(typeof e=="symbol")return e;let t=e.indexOf("$");return t>=0?e.slice(0,t):e};function Jt(e){return function(t,r){var a,o;let s=(a=e==null?void 0:e.name)!=null?a:_t(r.name),n=!!((o=e==null?void 0:e.readAsValue)!=null&&o);return{get(){let c=T(this,s);if(c)return n?K(c):c()},set(c){var l;(l=S(T(this,s)))==null||l.writer(c)},init(c){let[l,u]=O(void 0,e);return $t(this,s,l),u(c),K(l)}}}}function Ht(e){return function(t,r){var n;let s=(n=e==null?void 0:e.name)!=null?n:_t(r.name);return{get(){return T(this,s)}}}}var Yt;(function(e){e[e.StructuralChanges=1]="StructuralChanges",e[e.ContentUpdates=2]="ContentUpdates",e[e.Removal=3]="Removal"})(Yt||(Yt={}));var J;(function(e){e[e.CreateEntities=1]="CreateEntities",e[e.DestroyEntities=2]="DestroyEntities",e[e.SetParent=3]="SetParent",e[e.UpdateOrder=4]="UpdateOrder",e[e.ChangeProperties=5]="ChangeProperties",e[e.ChangeToken=6]="ChangeToken",e[e.SendEvents=7]="SendEvents"})(J||(J={}));var Pi=Symbol.for("ShadowEntsGlobalNS"),Ur="configure",Nr="changeTrail",qr="destroy",Qr="loaded",Xt="appliedChangeTrail",ut="importedModule",Vr="destroyed",yt="messageToView",ft="shadowObjects",$,rr,Gr=(rr=class{constructor(){f(this,$,new Map)}keys(){return i(this,$).keys()}entries(){return i(this,$).entries()}clear(){for(let e of i(this,$).values())e.destroy();i(this,$).clear()}hasSignal(e){return i(this,$).has(e)}getSignal(e){if(!i(this,$).has(e)){let t=O();return i(this,$).set(e,t),t}return i(this,$).get(e)}getSignalReader(e){return this.getSignal(e).get}getSignalWriter(e){return this.getSignal(e).set}},$=new WeakMap,rr);function Zt(e,t,r,s,n,a){function o(D){if(D!==void 0&&typeof D!="function")throw new TypeError("Function expected");return D}for(var c=s.kind,l=c==="getter"?"get":c==="setter"?"set":"value",u=!t&&e?s.static?e:e.prototype:null,y=t||(u?Object.getOwnPropertyDescriptor(u,s.name):{}),p,ye=!1,A=r.length-1;A>=0;A--){var Ue={};for(var g in s)Ue[g]=g==="access"?{}:s[g];for(var g in s.access)Ue.access[g]=s.access[g];Ue.addInitializer=function(D){if(ye)throw new TypeError("Cannot add initializers after decoration has completed");a.push(o(D||null))};var v=(0,r[A])(c==="accessor"?{get:y.get,set:y.set}:y[l],Ue);if(c==="accessor"){if(v===void 0)continue;if(v===null||typeof v!="object")throw new TypeError("Object expected");(p=o(v.get))&&(y.get=p),(p=o(v.set))&&(y.set=p),(p=o(v.init))&&n.unshift(p)}else(p=o(v))&&(c==="field"?n.unshift(p):y[l]=p)}u&&Object.defineProperty(u,s.name,y),ye=!0}function Je(e,t,r){for(var s=arguments.length>2,n=0;n<t.length;n++)r=s?t[n].call(e,r):t[n].call(e);return s?r:void 0}var dt=(()=>{var o,c,l,u,y,pt,ar,A;let e,t=[],r=[],s,n=[],a=[];return A=class{constructor(){f(this,y);f(this,o,[]);f(this,c);f(this,l,Je(this,t,void 0));f(this,u,(Je(this,r),Je(this,n,void 0)));Je(this,a),Me(this,A.Value),this.value$(g=>m(this,A.Value,g))}get value(){return i(this,l)}set value(g){h(this,l,g)}get value$(){return i(this,u)}set value$(g){h(this,u,g)}add(...g){for(let v of g)i(this,o).push(v);E(this,y,ar).call(this)}clear(){i(this,o).length=0,E(this,y,pt).call(this)}dispose(){this.clear(),b(this),lt(this),it(this,A.Value)}},o=new WeakMap,c=new WeakMap,l=new WeakMap,u=new WeakMap,y=new WeakSet,pt=function(){var g;(g=i(this,c))==null||g.call(this),h(this,c,void 0)},ar=function(){E(this,y,pt).call(this);let[g,v]=ce(()=>{for(let D of i(this,o)){let vt=K(D);if(vt!=null){this.value=vt;return}}this.value=void 0},i(this,o));h(this,c,v),g()},(()=>{let g=typeof Symbol=="function"&&Symbol.metadata?Object.create(null):void 0;e=[Jt()],s=[Ht()],Zt(A,null,e,{kind:"accessor",name:"value",static:!1,private:!1,access:{has:v=>"value"in v,get:v=>v.value,set:(v,D)=>{v.value=D}},metadata:g},t,r),Zt(A,null,s,{kind:"accessor",name:"value$",static:!1,private:!1,access:{has:v=>"value$"in v,get:v=>v.value$,set:(v,D)=>{v.value$=D}},metadata:g},n,a),g&&Object.defineProperty(A,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:g})})(),A.Value="value",A})(),er="onCreate",xe="onDestroy",Wr="onViewEvent",fe,Oe,be,Y,j,F,X,L,ke,R,gt,He,mt,sr,Kr=(sr=class{constructor(e,t){f(this,R);f(this,fe);f(this,Oe);f(this,be,new Gr);f(this,Y,new Map);f(this,j);f(this,F);f(this,X,new Set);f(this,L,[]);f(this,ke,0);h(this,fe,e),h(this,Oe,t),B(this,xe,st.Min,this)}get kernel(){return i(this,fe)}get uuid(){return i(this,Oe)}get order(){return i(this,ke)}set order(e){i(this,ke)!==e&&(h(this,ke,e),i(this,j)&&this.parent.resortChildren())}get parentUuid(){return i(this,j)||void 0}set parentUuid(e){i(this,j)!==e&&(this.removeFromParent(),h(this,j,e||void 0),h(this,F,e?i(this,fe).getEntity(e):void 0),i(this,F)&&i(this,F).addChild(this))}get parent(){return!i(this,F)&&i(this,j)&&h(this,F,i(this,fe).getEntity(i(this,j))),i(this,F)}set parent(e){this.parentUuid=e==null?void 0:e.uuid}get hasParent(){return!!i(this,j)}get children(){return i(this,L)}traverse(e){e(this);for(let t of i(this,L))t.traverse(e)}onDestroy(){var e;i(this,be).clear(),b(this);for(let t of i(this,Y).values())t.unsubscribeFromPath(),(e=t.unsubscribeFromParent)==null||e.call(t),t.ctxPath.dispose(),ct(t.inherited,t.provide,t.context);h(this,j,void 0),h(this,F,void 0),i(this,X).clear(),i(this,L).length=0}addChild(e){var t;if(i(this,L).length===0){i(this,X).add(e.uuid),i(this,L).push(e);return}if(i(this,X).has(e.uuid))throw new Error(\`child with uuid: \${e.uuid} already exists! parentUuid: \${this.uuid}\`);i(this,X).add(e.uuid),i(this,L).push(e),this.resortChildren();for(let[,r]of i(e,Y))E(t=e,R,mt).call(t,r)}resortChildren(){i(this,L).sort((e,t)=>e.order-t.order)}removeChild(e){i(this,X).has(e.uuid)&&(i(this,X).delete(e.uuid),i(this,L).splice(i(this,L).indexOf(e),1))}removeFromParent(){if(i(this,F)){i(this,F).removeChild(this),h(this,F,void 0),h(this,j,void 0);for(let[,e]of i(this,Y))e.unsubscribeFromParent&&(e.unsubscribeFromParent(),e.unsubscribeFromParent=void 0)}}dispatchMessageToView(e,t,r,s=!1){i(this,fe).dispatchMessageToView({uuid:i(this,Oe),type:e,data:t,transferables:r,traverseChildren:s})}dispatchViewEvents(e){for(let{type:t,data:r}of e)m(this,Wr,t,r)}dispatchViewEvent(e,t){this.dispatchViewEvents([{type:e,data:t}])}getPropertyReader(e){return E(this,R,gt).call(this,e).get}getPropertyWriter(e){return E(this,R,gt).call(this,e).set}setProperties(e){Re(()=>{for(let[t,r]of e)this.setProperty(t,r)})}setProperty(e,t){this.getPropertyWriter(e)(t)}getProperty(e){return K(this.getPropertyReader(e))}propKeys(){return Array.from(i(this,be).keys())}propEntries(){return Array.from(i(this,be).entries()).map(([e,t])=>[e,t.value])}hasContext(e){return i(this,Y).has(e)}useContext(e){return E(this,R,He).call(this,e).context.get}provideContext(e){return E(this,R,He).call(this,e).provide}},fe=new WeakMap,Oe=new WeakMap,be=new WeakMap,Y=new WeakMap,j=new WeakMap,F=new WeakMap,X=new WeakMap,L=new WeakMap,ke=new WeakMap,R=new WeakSet,gt=function(e){return i(this,be).getSignal(e)},He=function(e){let t=i(this,Y).get(e);if(t==null){let r=O(),s=O(),n=O(),a=new dt;a.add(s.get,r.get);let o=x(a,dt.Value,c=>{queueMicrotask(()=>{n.set(c)})});t={name:e,inherited:r,provide:s,context:n,ctxPath:a,unsubscribeFromPath:o},i(this,Y).set(e,t),E(this,R,mt).call(this,t)}return t},mt=function(e){var t,r;this.parent&&((t=e.unsubscribeFromParent)==null||t.call(e),e.unsubscribeFromParent=x(E(r=this.parent,R,He).call(r,e.name).ctxPath,dt.Value,s=>{e.inherited.set(s)}))},sr);function _r(e,t){e.indexOf(t)===-1&&e.push(t)}var Z,M,ir,cr=(ir=class{constructor(){f(this,Z,new Map);f(this,M,new Map)}static get(e){return e!=null?e:Jr}define(e,t){i(this,Z).has(e)?_r(i(this,Z).get(e).constructors,t):i(this,Z).set(e,{token:e,constructors:[t]})}appendRoute(e,t){if(i(this,M).has(e)){let r=i(this,M).get(e);for(let s of t)r.add(s)}else i(this,M).set(e,new Set(t))}clearRoute(e){i(this,M).delete(e)}findTokensByRoute(e){let t=new Set([e]),r=i(this,M).has(e)?[...i(this,M).get(e)]:[];for(;r.length;){let s=r.shift();t.has(s)||(t.add(s),i(this,M).has(s)&&r.push(...Array.from(i(this,M).get(s)).filter(n=>!t.has(n))))}return Array.from(t)}findConstructors(e){let t=this.findTokensByRoute(e),r=new Set;for(let s of t){let n=i(this,Z).get(s);if(n)for(let a of n.constructors)r.add(a)}return r.size>0?Array.from(r):void 0}hasToken(e){return i(this,Z).has(e)}hasRoute(e){return i(this,M).has(e)}clear(){i(this,Z).clear(),i(this,M).clear()}},Z=new WeakMap,M=new WeakMap,ir),Jr=new cr,H;(function(e){e[e.CreateAndDestroy=0]="CreateAndDestroy",e[e.JustCreate=1]="JustCreate",e[e.DestroyOnly=2]="DestroyOnly"})(H||(H={}));var tr=e=>e.displayName||e.name,C,ee,Pe,$e,te,nr,Hr=(nr=class{constructor(e){f(this,C,new Map);f(this,ee,new Set);f(this,Pe);f(this,$e);f(this,te,!0);V(this),this.registry=cr.get(e)}getEntity(e){var r;let t=(r=i(this,C).get(e))==null?void 0:r.entity;if(!t)throw new Error(\`entity with uuid "\${e}" not found!\`);return t}hasEntity(e){return i(this,C).has(e)}traverseLevelOrderBFS(e=!1){if(i(this,te)){let t=new Map,r=(s,n)=>{let a=this.getEntity(s);t.has(n)?t.get(n).push(a):t.set(n,[a]);for(let o of a.children)r(o.uuid,n+1)};i(this,ee).forEach(s=>r(s,0)),h(this,Pe,Array.from(t.entries()).sort((s,n)=>s[0]-n[0]).map(([,s])=>s).flat()),h(this,$e,i(this,Pe).slice().reverse()),h(this,te,!1)}return e?i(this,$e):i(this,Pe)}getEntityGraph(){return Array.from(i(this,ee)).map(e=>this.getEntityGraphNode(e))}getEntityGraphNode(e){if(!i(this,C).has(e))return;let{token:t,entity:r}=i(this,C).get(e);return{token:t,entity:r,props:Object.fromEntries(r.propEntries()),children:r.children.map(s=>this.getEntityGraphNode(s.uuid))}}upgradeEntities(){for(let e of this.traverseLevelOrderBFS(!0))this.updateShadowObjects(e.uuid,H.DestroyOnly);for(let e of this.traverseLevelOrderBFS(!1))this.updateShadowObjects(e.uuid,H.JustCreate)}run(e){Re(()=>{for(let t of e.changeTrail)this.parse(t)})}parse(e){switch(e.type){case J.CreateEntities:this.createEntity(e.uuid,e.token,e.parentUuid,e.order,e.properties),h(this,te,!0);break;case J.DestroyEntities:this.destroyEntity(e.uuid),h(this,te,!0);break;case J.SetParent:this.setParent(e.uuid,e.parentUuid,e.order),h(this,te,!0);break;case J.UpdateOrder:this.updateOrder(e.uuid,e.order),h(this,te,!0);break;case J.ChangeProperties:this.changeProperties(e.uuid,e.properties);break;case J.ChangeToken:this.changeToken(e.uuid,e.token);break;case J.SendEvents:this.dispatchEventsToEntity(e.uuid,e.events);break}}createEntity(e,t,r,s=0,n){let a=new Kr(this,e);a.order=s;let o={token:t,entity:a,usedConstructors:new Map};i(this,C).set(e,o),r&&(a.parentUuid=r),a.hasParent||i(this,ee).add(e),n&&a.setProperties(n),this.createShadowObjects(e)}destroyEntity(e){if(!i(this,C).has(e))return;let{entity:t,usedConstructors:r}=i(this,C).get(e);t.removeFromParent(),m(t,xe,this),r.clear(),i(this,C).delete(t.uuid),i(this,ee).delete(t.uuid)}setParent(e,t,r=0){let s=this.getEntity(e);s.parentUuid===t&&s.order===r||(s.removeFromParent(),s.order=r,s.parentUuid=t,s.hasParent?i(this,ee).delete(e):i(this,ee).add(e))}updateOrder(e,t){this.getEntity(e).order=t}dispatchEventsToEntity(e,t){var r;(r=this.getEntity(e))==null||r.dispatchViewEvents(t)}changeProperties(e,t){this.getEntity(e).setProperties(t)}changeToken(e,t){if(!i(this,C).has(e))return;let r=i(this,C).get(e);r.token!==t&&(r.token=t,this.updateShadowObjects(e))}dispatchMessageToView(e){queueMicrotask(()=>{m(this,yt,e)})}updateShadowObjects(e,t=H.CreateAndDestroy){let r=i(this,C).get(e),s=new Set(this.registry.findConstructors(r.token)),n=t===H.CreateAndDestroy||t===H.DestroyOnly,a=t===H.CreateAndDestroy||t===H.JustCreate;if(n){for(let[o,c]of r.usedConstructors)if(!s.has(o)){r.usedConstructors.delete(o);for(let l of c)this.destroyShadowObject(l,r.entity)}}if(a)for(let o of s)r.usedConstructors.has(o)||this.constructShadowObject(o,r)}constructShadowObject(e,t){let r=new Set,s=new Set,n=new Map,a=new Map,o=new Map,c=V(new e({entity:t.entity,provideContext(l,u,y){let p=a.get(l);if(p===void 0){p=O(u,y?{compareFn:y}:void 0),a.set(l,p);let ye=Ie(p,t.entity.provideContext(l));s.add(ye.destroy.bind(ye))}return p},useContext(l,u){let y=n.get(l);if(y===void 0){[y]=O(void 0,u?{compareFn:u}:void 0),n.set(l,y);let p=Ie(t.entity.useContext(l),y);s.add(p.destroy.bind(p))}return y},useProperty(l,u){let y=o.get(l);if(y===void 0){[y]=O(void 0,u?{compareFn:u}:void 0),o.set(l,y);let p=Ie(t.entity.getPropertyReader(l),y);s.add(p.destroy.bind(p))}return y},createEffect(...l){let u=ce(...l);return s.add(u[1]),u},createSignal(...l){let u=O(...l);return s.add(()=>{U(u)}),u},on(...l){let u=x(...l);return s.add(u),u},onDestroy(l){r.add(l)}}));return console.debug("[Kernel] create shadow-object",tr(e),{shadowObject:c,entity:t.entity}),B(c,xe,()=>{console.debug("[Kernel] destroy shadow-object",tr(e),{shadowObject:c,entity:t.entity});for(let u of r)u();for(let u of s)u();for(let u of n.values())U(u);for(let u of o.values())U(u);for(let[u]of a.values())U(u);r.clear(),s.clear(),n.clear(),o.clear(),a.clear();let l=t.usedConstructors.get(e);l&&(l.delete(c),l.size===0&&t.usedConstructors.delete(e))}),t.usedConstructors.has(e)?t.usedConstructors.get(e).add(c):t.usedConstructors.set(e,new Set([c])),this.attachShadowObject(c,t.entity),c}createShadowObjects(e){var r;let t=i(this,C).get(e);(r=this.registry.findConstructors(t.token))==null||r.forEach(s=>{this.constructShadowObject(s,t)})}findShadowObjects(e){if(!i(this,C).has(e))return[];let{usedConstructors:t}=i(this,C).get(e);return Array.from(new Set(Array.from(t.values()).map(r=>Array.from(r)).flat()))}attachShadowObject(e,t){x(t,e),typeof e[er]=="function"&&e[er](t)}destroyShadowObject(e,t){typeof e[xe]=="function"&&e[xe](t),m(e,xe,t),b(t,e)}destroy(){for(let e of this.traverseLevelOrderBFS().reverse())this.destroyEntity(e.uuid)}},C=new WeakMap,ee=new WeakMap,Pe=new WeakMap,$e=new WeakMap,te=new WeakMap,nr);async function lr(e,t,r,s=!0){var a,o;if(r.has(t)){console.warn("importModule: skipping already imported module",t);return}else r.add(t);t.extends&&await Promise.all(t.extends.map(c=>lr(e,c,r,!1)));let{registry:n}=e;if(t.define)for(let[c,l]of Object.entries(t.define))n.define(c,l);if(t.routes)for(let[c,l]of Object.entries(t.routes))n.appendRoute(c,l);await((o=(a=t.initialize)==null?void 0:a.call(t,{define:(c,l)=>n.define(c,l),kernel:e,registry:n}))!=null?o:Promise.resolve()),s&&e.upgradeEntities()}var Yr=e=>(typeof e=="string"&&(e=new URL(e,globalThis.location.href)),e.toString()),Be,de,hr,ur,fr,or,Xr=(or=class{constructor(e){f(this,de);f(this,Be,new Set);var t,r;this.kernel=(t=e==null?void 0:e.kernel)!=null?t:new Hr,this.postMessage=(r=e==null?void 0:e.postMessage)!=null?r:self.postMessage.bind(self),x(this.kernel,yt,"onMessageToView",this)}route(e){var t;switch(e.data.type){case Ur:E(this,de,hr).call(this,e.data);break;case Nr:E(this,de,ur).call(this,e.data);break;case qr:E(this,de,fr).call(this,e.data);break;default:console.warn("[MessageRouter] unknown message",(t=e.data.type)!=null?t:e.data)}}onMessageToView(e){let s=e,{transferables:t}=s,r=St(s,["transferables"]);this.postMessage({type:yt,data:r},{transfer:t})}},Be=new WeakMap,de=new WeakSet,hr=async function(e){try{let t=await import(Yr(e.importModule));t[ft]?(await lr(this.kernel,t[ft],i(this,Be)),this.postMessage({type:ut,url:e.importModule})):this.postMessage({type:ut,url:e.importModule,error:\`module has no "\${ft}" export\`})}catch(t){console.error("[MessageRouter] failed to import module",t),this.postMessage({type:ut,url:e.importModule,error:\`\${t}\`})}},ur=function(e){try{this.kernel.run(e)}catch(t){console.error("[MessageRouter] failed to apply change trail",t),this.postMessage({type:Xt,serial:e.serial,error:t.toString()})}e.serial&&this.postMessage({type:Xt,serial:e.serial})},fr=function(e){console.debug("[MessageRouter] on destroy",e),b(this.kernel,this),i(this,Be).clear(),this.postMessage({type:Vr})},or),Zr=class{constructor(){this.router=new Xr,this.onmessage=e=>{this.router.route(e)}}start(){self.addEventListener("message",this.onmessage),self.postMessage({type:Qr})}};console.debug("@spearwolf/shadow-objects: hello worker \\u{1F680}");var es=new Zr;es.start();
22
22
  /*! Bundled license information:
23
23
 
24
24
  @spearwolf/eventize/lib/index.mjs:
25
25
  (*!
26
26
  =============================================================================
27
- @spearwolf/eventize 4.0.0+build.20240722
27
+ @spearwolf/eventize 4.0.1+build.20240804
28
28
  \u2014 https://github.com/spearwolf/eventize.git
29
29
  =============================================================================
30
30
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@spearwolf/shadow-objects",
3
3
  "description": "the slightly different component framework",
4
- "version": "0.2.0",
4
+ "version": "0.3.0",
5
5
  "author": {
6
6
  "name": "Wolfger Schramm",
7
7
  "email": "wolfger@spearwolf.de",
@@ -52,7 +52,7 @@
52
52
  "src/shae-worker.js"
53
53
  ],
54
54
  "dependencies": {
55
- "@spearwolf/eventize": "^4.0.0",
56
- "@spearwolf/signalize": "^0.15.0"
55
+ "@spearwolf/eventize": "^4.0.1",
56
+ "@spearwolf/signalize": "^0.16.0"
57
57
  }
58
58
  }