@spearwolf/shadow-objects 0.10.0 → 0.12.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.
- package/bundle.js +2 -2
- package/package.json +1 -1
- package/src/elements/ShaeElement.d.ts.map +1 -1
- package/src/elements/ShaeElement.js.map +1 -1
- package/src/elements/ShaeEntElement.d.ts +2 -0
- package/src/elements/ShaeEntElement.d.ts.map +1 -1
- package/src/elements/ShaeEntElement.js +39 -1
- package/src/elements/ShaeEntElement.js.map +1 -1
- package/src/entities/Entity.d.ts +1 -0
- package/src/entities/Entity.d.ts.map +1 -1
- package/src/entities/Entity.js +13 -2
- package/src/entities/Entity.js.map +1 -1
- package/src/entities/Kernel.d.ts.map +1 -1
- package/src/entities/Kernel.js +8 -1
- package/src/entities/Kernel.js.map +1 -1
- package/src/entities/SignalsPath.d.ts +1 -0
- package/src/entities/SignalsPath.d.ts.map +1 -1
- package/src/entities/SignalsPath.js +4 -0
- package/src/entities/SignalsPath.js.map +1 -1
- package/src/entities/events.d.ts +4 -0
- package/src/entities/events.d.ts.map +1 -1
- package/src/entities/events.js +2 -0
- package/src/entities/events.js.map +1 -1
- package/src/view/ComponentChanges.d.ts.map +1 -1
- package/src/view/ComponentChanges.js +10 -5
- package/src/view/ComponentChanges.js.map +1 -1
- package/src/view/ComponentContext.d.ts +1 -0
- package/src/view/ComponentContext.d.ts.map +1 -1
- package/src/view/ComponentContext.js +11 -3
- package/src/view/ComponentContext.js.map +1 -1
- package/src/view/ViewComponent.d.ts.map +1 -1
- package/src/view/ViewComponent.js +3 -0
- package/src/view/ViewComponent.js.map +1 -1
package/bundle.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
@file @spearwolf/shadow-objects - a reactive entity-component framework that feels at home in the shadows
|
|
3
3
|
@author Wolfger Schramm <wolfger@spearwolf.de>
|
|
4
|
-
@version 0.
|
|
4
|
+
@version 0.12.0+bundle.20250320
|
|
5
5
|
|
|
6
6
|
Copyright 2025 Wolfger Schramm
|
|
7
7
|
|
|
@@ -18,7 +18,7 @@ See the License for the specific language governing permissions and
|
|
|
18
18
|
limitations under the License.
|
|
19
19
|
|
|
20
20
|
*/
|
|
21
|
-
var X="*",Bt=1,vt=2,wt=4,N=Symbol.for("eventize"),Rs="[eventize]",De=s=>s===X,qt=s=>{switch(typeof s){case"string":case"symbol":return!0;default:return!1}},Gt=typeof console<"u",Ls=Gt?console[console.warn?"warn":"log"].bind(console,Rs):()=>{},Ms=(s,e,t)=>(Object.defineProperty(s,e,{value:t,configurable:!0}),s),_s=0,Ht=class{static publish(s){s.sort((e,t)=>e.order-t.order).forEach(e=>e.emit())}events=new Map;eventNames=new Set;add(s){Array.isArray(s)?s.forEach(e=>this.eventNames.add(e)):this.eventNames.add(s)}remove(s){Array.isArray(s)?s.forEach(e=>this.eventNames.delete(e)):this.eventNames.delete(s),this.clear(s)}clear(s){Array.isArray(s)?s.forEach(e=>this.events.delete(e)):this.events.delete(s)}retain(s,e){this.eventNames.has(s)&&this.events.set(s,{args:e,order:_s++})}isKnown(s){return this.eventNames.has(s)}emit(s,e,t=[]){if(De(s))this.eventNames.forEach(r=>this.emit(r,e,t));else if(this.events.has(s)){let{order:r,args:i}=this.events.get(s);t.push({order:r,emit:()=>e.apply(s,i)})}return t}},mt=(s,e,t,r)=>{if(typeof e=="function"){let i=e.apply(s,t);i!=null&&r?.(i)}},js=(s,e,t,r)=>mt(e,e.emit,[s].concat(t),r),Ns=s=>{switch(typeof s){case"function":return Bt;case"string":case"symbol":return vt;case"object":return wt}},Ds=0,Is=()=>++Ds,Qt=class{id;eventName;isCatchEmAll;priority;listener;listenerObject;listenerType;callAfterApply;isRemoved;refCount;constructor(s,e,t,r=null){this.id=Is(),this.eventName=s,this.isCatchEmAll=De(s),this.listener=t,this.listenerObject=r,this.priority=e,this.listenerType=Ns(t),this.callAfterApply=void 0,this.isRemoved=!1,this.refCount=1}isEqual(s,e=null){if(s===this)return!0;let t=typeof s;return t==="number"&&s===this.id?!0:e===null&&(t==="string"||t==="symbol")?s===X||s===this.eventName:this.listener===s&&this.listenerObject===e}apply(s,e,t){if(this.isRemoved)return;let{listener:r,listenerObject:i}=this;switch(this.listenerType){case Bt:mt(i,r,e,t),this.callAfterApply&&this.callAfterApply();break;case vt:mt(i,i[r],e,t),this.callAfterApply&&this.callAfterApply();break;case wt:{let n=r[s];if(this.isCatchEmAll||this.eventName===s){if(typeof n=="function"){let o=n.apply(r,e);o!=null&&t?.(o)}else js(s,r,e,t);this.callAfterApply&&this.callAfterApply()}break}}}},$s=(s,e)=>s.priority!==e.priority?e.priority-s.priority:s.id-e.id,zt=s=>s?.slice(0),Ut=(s,e)=>{let t=s.indexOf(e);t>-1&&s.splice(t,1)},Ws=s=>s===wt||s===vt,bt=(s,e,t)=>{let r=s.findIndex(i=>i.isEqual(e,t));r>-1&&(s[r].isRemoved=!0,s.splice(r,1))},Ne=(s,e,t)=>{let r=[];for(let i of s)(e==null&&i.listenerObject===t||i.eventName===e&&i.listener===t)&&r.push(i);for(let i of r)bt(s,i,void 0)},yt=s=>{s&&(s.forEach(e=>{e.isRemoved=!0}),s.length=0)},Fs=(s,e)=>s.listenerType===e.listenerType?s.priority===e.priority&&s.eventName===e.eventName&&s.listenerObject===e.listenerObject&&s.listener===e.listener:!1,zs=(s,e)=>{if(Ws(s.listenerType))return e.find(t=>Fs(s,t))},Us=(s,e)=>{let t=zs(s,e);return t?(t.refCount+=1,t):(e.push(s),e.sort($s),s)},Vs=class{namedListeners;catchEmAllListeners;getListenersForEventName=s=>{let e=this.namedListeners.get(s);return e||(e=[],this.namedListeners.set(s,e)),e};constructor(){this.namedListeners=new Map,this.catchEmAllListeners=[]}add(s){return Us(s,s.isCatchEmAll?this.catchEmAllListeners:this.getListenersForEventName(s.eventName))}remove(s,e,t=!1){e==null&&Array.isArray(s)?s.forEach(r=>this.remove(r,null,t)):s==null||e==null&&De(s)?this.removeAllListeners():e==null&&qt(s)?yt(this.namedListeners.get(s)):s instanceof Qt?s.isRemoved||(s.refCount-=1,s.refCount<1&&(s.isRemoved=!0,this.namedListeners.forEach(r=>Ut(r,s)),Ut(this.catchEmAllListeners,s))):t?De(s)?Ne(this.catchEmAllListeners,X,s):this.namedListeners.forEach(r=>Ne(r,s,e)):(this.namedListeners.forEach(r=>{bt(r,s,e),Ne(r,void 0,s)}),bt(this.catchEmAllListeners,s,e),Ne(this.catchEmAllListeners,void 0,s))}removeAllListeners(){this.namedListeners.forEach(s=>yt(s)),this.namedListeners.clear(),yt(this.catchEmAllListeners)}forEach(s,e){let t=zt(this.catchEmAllListeners),r=zt(this.namedListeners.get(s));if(s===X||!r||r.length===0)t.forEach(e);else if(t.length===0)r.forEach(e);else{let i=r.length,n=t.length,o=0,l=0;for(;o<i||l<n;){if(o<i){let a=r[o];if(l>=n||a.priority>=t[l].priority){e(a),++o;continue}}l<n&&(e(t[l]),++l)}}}getSubscriptionCount(){let s=this.catchEmAllListeners.length;for(let e of this.namedListeners.values())s+=e.length;return s}},ee=s=>!!(s&&s[N]);function be(s){if(ee(s))return s;let e=new Vs,t=new Ht;return Ms(s,N,{keeper:t,store:e}),s}var ve={Max:Number.POSITIVE_INFINITY,AAA:1e9,BB:1e6,C:1e3,Default:0,Low:-1e4,Min:Number.NEGATIVE_INFINITY},Bs=(s,e,t,r,i,n,o)=>{let l=s.add(new Qt(t,r,i,n));return e.emit(t,l,o),l},qs=(s,e,t,r)=>{let i=t.length,n=typeof t[0],o,l,a,h;if(i>=2&&i<=3&&n==="number"?(o=X,[l,a,h]=t):i>=3&&i<=4&&typeof t[1]=="number"?[o,l,a,h]=t:(l=ve.Default,n==="string"||n==="symbol"||Array.isArray(t[0])?[o,a,h]=t:(o=X,[a,h]=t)),!a&&Gt)throw Ls("called with insufficient arguments!",t),"subscribeTo() called with insufficient arguments!";let u=d=>E=>Bs(s,e,E,d,a,h,r);return Array.isArray(o)?o.map(d=>Array.isArray(d)?u(d[1])(d[0]):u(l)(d)):u(l)(o)},Yt=(s,e,t)=>{let r=[],i=qs(s,e,t,r);return Ht.publish(r),i},Vt=s=>e=>{e.callAfterApply=()=>{s?.()}},Kt=(s,e)=>Object.assign(()=>y(s,e),Array.isArray(e)?{listeners:e}:{listener:e}),Jt=(s,e,t,r)=>{let{store:i,keeper:n}=s[N];Array.isArray(e)?e.forEach(o=>{i.forEach(o,l=>l.apply(o,t,r)),n.retain(o,t)}):e!==X&&(i.forEach(e,o=>{o.apply(e,t,r)}),n.retain(e,t))},g=(s,...e)=>{let t=be(s),{store:r,keeper:i}=t[N];return Kt(t,Yt(r,i,e))},v=(s,...e)=>{let t=be(s),{store:r,keeper:i}=t[N],n=Yt(r,i,e),o=Kt(t,n),l=!1,a=()=>{l||(o(),l=!0)};return Array.isArray(n)?n.forEach(Vt(a)):Vt(a)(n),a},he=(s,e)=>new Promise(t=>{v(s,e,t)}),y=(s,e,t)=>{if(!ee(s))throw new Error("object is not eventized");let{store:r,keeper:i}=s[N],n=typeof e,o=t!=null&&(n==="string"||n==="symbol");r.remove(e,t,o),Array.isArray(e)?i.remove(e.filter(l=>typeof l=="string")):qt(e)&&i.remove(e)},c=(s,e,...t)=>{if(!ee(s))throw new Error("object is not eventized");Jt(s,e,t)},Gs=(s,e,...t)=>{if(!ee(s))throw new Error("object is not eventized");let r=[];return Jt(s,e,t,i=>{r.push(i)}),r=r.map(i=>Array.isArray(i)?Promise.all(i):Promise.resolve(i)),r.length>0?Promise.all(r):Promise.resolve()},D=(s,e)=>{let t=be(s),{keeper:r}=t[N];r.add(e)},F=(s,e)=>{if(!ee(s))throw new Error("object is not eventized");let{keeper:t}=s[N];t.clear(e)},w=(()=>{let s=(e={})=>be(e);return s.inject=(e={})=>(e=be(e),Object.assign(e,{on:(...t)=>g(e,...t),once:(...t)=>v(e,...t),onceAsync:t=>he(e,t),off:(t,r)=>y(e,t,r),emit:(t,...r)=>c(e,t,...r),emitAsync:(t,...r)=>Gs(e,t,...r),retain:t=>D(e,t),retainClear:t=>F(e,t)}),e),s.is=ee,s})();var Et=s=>ee(s)?s[N]?.store?.getSubscriptionCount()??0:0;var z=w(),U=w(),V=w();var te=class{static current;#e=new Set;batch(e){this.#e.add(e)}run(){c(V,Array.from(this.#e))}},Zt=()=>te.current;function k(s){let e=te.current;e?e=void 0:e=te.current=new te;try{s()}finally{e&&(te.current=void 0,e.run())}}var Ct=0;function St(s){Ct++;try{s()}finally{Ct--}}function Ie(){return Ct>0}var T=Symbol.for("signal"),se=Symbol.for("effect"),xt=Symbol.for("destroySignal"),kt=Symbol.for("createEffect"),Xt=Symbol.for("destroyEffect"),le="value",At="mute",Tt="unmute",B="destroy";var q=new Map,L=class s{#e=new Set;#t=new Set;#s=new Map;#i=new WeakMap;#r=new Map;#o=new Set;#a=new Set;#n=!1;#h;static get(e){if(e!=null)return e instanceof s&&!e.#n?e:q.get(e)}static findOrCreate(e){if(e==null)throw new Error("Cannot create a group with a null object");return new s(e)}static destroy(e){q.get(e)?.destroy()}static clear(){for(let e of q.values())e.destroy();q.clear()}constructor(e){if(e!=null&&e instanceof s&&!e.#n)return e;if(e??=this,q.has(e))return q.get(e);q.set(e,this),w(this)}attachGroup(e){if(this.#n)throw new Error("Cannot attach a group to a destroyed group");if(e===this)throw new Error("Cannot attach a group to itself");return this.#e.add(e),e.#h&&e.#h!==this&&e.#h.#e.delete(e),e.#h=this,e}detachGroup(e){if(this.#n)throw new Error("Cannot detach a group from a destroyed group");return e!==this&&this.#e.has(e)&&(this.#e.delete(e),e.#h=void 0),e}attachSignal(e){if(this.#n)throw new Error("Cannot attach a signal to a destroyed group");let t=m(e);if(t?.destroyed)throw new Error("Cannot attach a destroyed signal to a group");return t&&this.#t.add(t),e}attachSignalByName(e,t){if(this.#n)throw new Error("Cannot attach a named signal to a destroyed group");if(t){this.attachSignal(t);let r=m(t);this.#s.set(e,r),this.#r.has(e)?this.#r.get(e).push(r):this.#r.set(e,[r]),this.#i.has(r)?this.#i.get(r).add(e):this.#i.set(r,new Set([e]))}else this.#s.delete(e);return t}hasSignal(e){return this.#s.has(e)||this.#h?.hasSignal(e)}signal(e){if(!this.#n)return this.#s.get(e)?.object??this.#h?.signal(e)}detachSignal(e){if(this.#n)return e;let t=m(e);if(t&&(this.#t.delete(t),this.#i.has(t))){let r=this.#i.get(t);for(let i of r)if(this.#r.has(i)){let n=this.#r.get(i);n.splice(n.indexOf(t),1),n.length===0?(this.#s.delete(i),this.#r.delete(i)):this.#s.get(i)===t&&this.#s.set(i,n.at(-1))}r.clear(),this.#i.delete(t)}return e}attachEffect(e){if(this.#n)throw new Error("Cannot attach an effect to a destroyed group");return this.#o.add(e),e}runEffects(){if(this.#n)throw new Error("Cannot run effects on a destroyed group");for(let e of this.#o)e.run();for(let e of this.#e)e.runEffects()}attachLink(e){if(this.#n)throw new Error("Cannot attach a link to a destroyed group");if(e?.isDestroyed)throw new Error("Cannot attach a destroyed link to a group");return e&&this.#a.add(e),e}detachLink(e){return this.#n||e&&this.#a.delete(e),e}destroy(){if(!this.#n){c(this,B,this),y(this);for(let e of this.#e)e.destroy();for(let e of this.#o)e.destroy();for(let e of this.#t)S(e);for(let e of this.#a)e.destroy();this.#e.clear(),this.#t.clear(),this.#s.clear(),this.#r.clear(),this.#o.clear(),this.#a.clear(),this.#h?.detachGroup(this),q.delete(this),this.#n=!0,this.#e=void 0,this.#t=void 0,this.#i=void 0,this.#s=void 0,this.#r=void 0,this.#i=void 0,this.#a=void 0,Object.freeze(this)}}};var $e=class{[se];constructor(e){this[se]=e,v(e,ue.Destroy,()=>{this[se]=void 0})}run=()=>this[se]?.run();destroy=()=>{this[se]?.destroy(),this[se]=void 0}};var ce=class{#e;#t;constructor(e="id",t=1){this.#e=e,this.#t=t}make(){return Symbol(`${this.#e}${this.#t++}`)}};var Ot=[],We=()=>Ot.at(-1),es=(s,e)=>{Ot.push(s);try{return e()}finally{Ot.pop()}};var Hs=s=>s!=null&&typeof s.then=="function",ue=class s{static idGen=new ce("ef");static Destroy="destroy";static count=0;id;callback;#e;#t=new Set;#s=new Set;parentEffect;childEffects=[];curChildEffectSlot=0;autorun=!0;shouldRun=!0;#i;#r=!1;constructor(e,t){w(this),this.callback=e;let r;t?.attach!=null&&(r=L.findOrCreate(t.attach),r.attachEffect(this)),this.autorun=t?.autorun??!0,this.#i=t?.dependencies?t.dependencies.map(i=>{switch(typeof i){case"string":case"symbol":return r.signal(i);default:return i}}):void 0,this.id=s.idGen.make(),g(V,this.id,"recall",this),++s.count}hasStaticDeps(){return this.#i!=null&&this.#i.length>0}saveSignalsFromDeps(){for(let e of this.#i)this.whenSignalIsRead(m(e).id)}static createEffect(e,t,r){let i=Array.isArray(t)?t:void 0,n=i?r??{dependencies:i}:t;n&&i&&(n.dependencies=i);let o,l=We();return l!=null?(o=l.getCurrentChildEffect(),o==null&&(o=new s(e,n),l.attachChildEffect(o),c(V,kt,o)),l.curChildEffectSlot++):(o=new s(e,n),c(V,kt,o)),o.hasStaticDeps()?o.saveSignalsFromDeps():o.autorun&&o.run(),new $e(o)}getCurrentChildEffect(){return this.childEffects[this.curChildEffectSlot]}attachChildEffect(e){this.childEffects.push(e),this.parentEffect=this}run=()=>{if(this.#r||!this.shouldRun)return;let e=Zt();e?e.batch(this.id):(this.runCleanupCallback(),this.curChildEffectSlot=0,this.shouldRun=!1,this.hasStaticDeps()?this.#e=this.callback():this.#e=es(this,this.callback))};recall(){this.shouldRun=!0,this.autorun&&this.run()}whenSignalIsRead(e){this.#t.has(e)||(this.#t.add(e),g(z,e,"recall",this),v(U,e,xt,this))}[xt](e){!this.#s.has(e)&&this.#t.has(e)&&(this.#s.add(e),y(z,e,this),this.#s.size===this.#t.size&&this.destroy())}runCleanupCallback(){if(this.#e!=null){let e=this.#e;this.#e=void 0,Hs(e)?Promise.resolve(e).then(t=>{typeof t=="function"&&t()}):e()}}destroy=()=>{this.#r||(c(this,s.Destroy,this),y(this),c(V,Xt,this),this.runCleanupCallback(),y(z,this),y(V,this),y(U,this),this.#r=!0,this.#t.clear(),this.#s.clear(),this.childEffects.forEach(e=>{e.destroy()}),this.childEffects.length=0,--s.count)}};var b=(...s)=>ue.createEffect(...s);var we=new WeakMap,Qs=s=>{let e=we.get(s);return e||(e={},we.set(s,e)),e},A=(s,e)=>we.get(s)?.signals?.get(e);var ts=(s,e,t)=>{let r=Qs(s);r.signals??=new Map,r.signals.set(e,t)};function Ee(...s){for(let e of s)if(we.has(e)){let t=we.get(e);if(t.signals){for(let r of t.signals.values())S(r);t.signals.clear(),t.signals=void 0}}}function ss(s){let e=m(fe(s)?s:A(...s));e!=null&&!e.muted&&!e.destroyed&&Fe(e.id,e.value,{touch:!0})}function re(s){return fe(s)?m(s)?.value:m(A(...s))?.value}var ze=class{[T];constructor(e){this[T]=e}get get(){return this[T].reader}get set(){return this[T].writer}get value(){return re(this.get)}set value(e){this.set(e)}onChange(e){let{destroy:t}=b(()=>e(this.value),[this.get]);return t}get muted(){return this[T].muted}set muted(e){this[T].muted=e}touch(){ss(this)}destroy(){S(this)}};var Ys=new ce("si");function rs(s){Ie()||We()?.whenSignalIsRead(s)}function Fe(s,e,t){Ie()||c(z,s,e,t)}var fe=s=>s!=null&&s[T]!=null,Ks=s=>{let e=t=>(t?b(()=>(s.destroyed||rs(s.id),t(s.value)),[e]):s.destroyed||(s.beforeRead?.(),rs(s.id)),s.value);return Object.defineProperty(e,T,{value:s}),e},Ue=class s{static instanceCount=0;id;lazy;get[T](){return this}compare;beforeRead;muted=!1;destroyed=!1;#e=void 0;get value(){return this.lazy&&(this.#e=this.valueFn(),this.valueFn=void 0,this.lazy=!1),this.#e}set value(e){this.#e=e}valueFn;reader;writer=(e,t)=>{let r=t?.lazy??!1,n=t?.compare??this.compare??((l,a)=>l===a);if((r!==this.lazy||r&&e!==this.valueFn||!r&&!n(e,this.#e))&&(r?(this.#e=void 0,this.valueFn=e,this.lazy=!0):(this.#e=e,this.valueFn=void 0,this.lazy=!1),!this.muted&&!this.destroyed)){Fe(this.id,this.#e);return}(t?.touch??!1)&&Fe(this.id,this.#e,{touch:!0})};object;constructor(e,t){this.id=Ys.make(),++s.instanceCount,this.lazy=e,this.lazy?(this.value=void 0,this.valueFn=t):(this.value=t,this.valueFn=void 0),this.reader=Ks(this),this.object=new ze(this)}},m=s=>s?.[T];function f(s=void 0,e){let t;if(fe(s))t=m(s);else{let r=e?.lazy??!1;t=new Ue(r,s),t.beforeRead=e?.beforeRead,t.compare=e?.compare}return e?.attach!=null&&L.findOrCreate(e.attach).attachSignal(t),t.object}var S=(...s)=>{for(let e of s){let t=m(e);t!=null&&!t.destroyed&&(t.destroyed=!0,t.beforeRead=void 0,--Ue.instanceCount,c(U,t.id,t.id))}};var Ve=class{#e=!1;#t;source;lastValue;isDestroyed=!1;constructor(e){w(this),this.source=m(e),this.#t=g(z,this.source.id,(t,r)=>{!this.#e&&!this.isDestroyed&&(r?.touch===!0?this.touch():this.write())}),v(U,this.source.id,()=>this.destroy())}attach(e){let t=L.findOrCreate(e);return t.attachLink(this),v(this,B,()=>{t.detachLink(this)}),t}nextValue(){return new Promise((e,t)=>{let r=[],i=()=>r.forEach(n=>{n()});r.push(v(this,le,n=>{i(),e(n)}),v(this,B,()=>{i(),t()}))})}async*asyncValues(e){let t=0;for(;!this.isDestroyed;)try{let r=await this.nextValue();if(e&&e(r,t++))break;D(this,le),yield r}catch{break}F(this,le)}destroy(){this.isDestroyed||(this.#t?.(),this.#t=void 0,c(this,B,this),F(this,le),y(this),this.lastValue=void 0,this.isDestroyed=!0,Object.freeze(this))}get isMuted(){return this.#e}mute(){return!this.isDestroyed&&!this.#e&&(this.#e=!0,c(this,At,this)),this}unmute(){return!this.isDestroyed&&this.#e&&(this.#e=!1,c(this,Tt,this)),this}toggle(){return this.isDestroyed||(this.#e=!this.#e,c(this,this.#e?At:Tt,this)),this.#e}updateValue(e){if(!this.#e&&!this.isDestroyed){let{value:t}=this.source;e(t),c(this,le,t),this.lastValue=t}}},Be=class extends Ve{target;constructor(e,t){super(e),this.target=m(t),v(U,this.target.id,()=>this.destroy()),this.touch()}touch(){return this.updateValue(e=>{this.target.writer(e,{touch:!0})}),this}write(){this.updateValue(e=>{this.target.writer(e)})}},qe=class extends Ve{target;constructor(e,t){super(e),this.target=t,this.touch()}touch(){return this.updateValue(e=>{this.target(e)}),this}write(){this.updateValue(e=>{this.target(e)})}};var Ge=new Map;function de(s,e,t){let r=m(s),i;if(Ge.has(r)){i=Ge.get(r);let h=m(e)??e;if(i.has(h))return i.get(h)}else i=new Map,Ge.set(r,i);let n=m(e),o=n!=null?new Be(s,n):new qe(s,e),l=t?.attach;l&&o.attach(l);let a=n??e;return i.set(a,o),v(o,B,()=>{i.delete(a),i.size===0&&Ge.delete(r)}),o}var He=class s{static fromProps(e,t){let r=new s,i=t?t.map(n=>[n,e[n]]):Object.entries(e);for(let[n,o]of i)r.#e.set(n,f(o));return r}#e=new Map;keys(){return this.#e.keys()}signals(){return this.#e.values()}entries(){return this.#e.entries()}clear(){for(let e of this.#e.values())e.destroy();this.#e.clear()}has(e){return this.#e.has(e)}get(e){if(!this.#e.has(e)){let t=f();return this.#e.set(e,t),t}return this.#e.get(e)}update(e){e.size&&k(()=>{for(let[t,r]of e.entries())this.get(t).set(r)})}updateFromProps(e,t){k(()=>{let r=t?t.map(i=>[i,e[i]]):Object.entries(e);for(let[i,n]of r)this.get(i).set(n)})}};var M;(function(s){s[s.StructuralChanges=1]="StructuralChanges",s[s.ContentUpdates=2]="ContentUpdates",s[s.Removal=3]="Removal"})(M||(M={}));var p;(function(s){s[s.CreateEntities=1]="CreateEntities",s[s.DestroyEntities=2]="DestroyEntities",s[s.SetParent=3]="SetParent",s[s.UpdateOrder=4]="UpdateOrder",s[s.ChangeProperties=5]="ChangeProperties",s[s.ChangeToken=6]="ChangeToken",s[s.SendEvents=7]="SendEvents"})(p||(p={}));var ie=Symbol.for("ShadowEntsGlobalNS"),I="#void",is="contextLost",ns="configure",os="changeTrail",as="destroy",hs="loaded",ls="appliedChangeTrail",us="importedModule",cs="destroyed",pe="messageToView",fs=16e3,ds=16e3,ps=4e3,gs=1e3,Pt="shadowObjects";function ys(s,e){s.indexOf(e)===-1&&s.push(e)}function Rt(s,e){let t=s.indexOf(e);t!==-1&&s.splice(t,1),s.push(e)}function G(s,e){let t=s.indexOf(e);t!==-1&&s.splice(t,1)}var ne=s=>typeof s=="string"?s.trim()||ie:typeof s=="symbol"?s:ie;var Ce=class{#e;get uuid(){return this.#e}#t=0;constructor(e){this.#e=e}#s=!0;#i=0;#r=0;hasChanges(){return this.#t>0}get isNew(){return this.#s}get isCreated(){return this.#i>0&&this.#i>this.#r}get isDestroyed(){return this.#r>0&&this.#r>=this.#i}#o=I;#a;#n=0;#h;#u;#l;create(e=I,t,r=0){this.#t++,this.#i++,this.#h=e,this.#u=t,this.#l=r||void 0}destroy(){this.#r++,this.#t++}clear(){this.#t=0,this.#s=!1,this.#h=void 0,this.#u=void 0,this.#l=void 0,this.#f.clear(),this.#d.length=0,this.#g.length=0,this.#p.clear()}changeToken(e){e===this.#o?this.#h=void 0:(this.#h=e,this.#t++)}setParent(e){e===this.#a?this.#u=void 0:(this.#u=e??null,this.#t++)}changeOrder(e){e===this.#n?this.#l=void 0:(this.#l=e,this.#t++)}#c=new Map;#f=new Map;#d=[];changeProperty(e,t,r){let i=this.#c.get(e);r==null&&t!==i||r!=null&&!r(t,i)?(this.#f.set(e,t),Rt(this.#d,e),this.#t++):(this.#f.delete(e),G(this.#d,e))}removeProperty(e){let t=this.#c.has(e);this.#f.has(e)?(this.#f.delete(e),t||G(this.#d,e)):t&&(Rt(this.#d,e),this.#t++)}#g=[];#p=new Set;createEvent(e,t,r){this.#g.push({type:e,data:t}),r?.forEach(i=>this.#p.add(i)),this.#t++}transferEventsTo(e){this.#g.length>0&&(e.#g.push(...this.#g),this.#g.length=0),this.#p.size>0&&(e.#p=new Set([...e.#p,...this.#p]),this.#p.clear())}buildChangeTrail(e,t){let{isNew:r,isCreated:i,isDestroyed:n}=this;if(!(r&&n))switch(t){case M.StructuralChanges:r?e.push(this.makeCreateEntityChange()):n||(this.#u!==void 0&&this.#u!==this.#a?e.push(this.makeSetParentChange()):this.#l!==void 0&&this.#l!==this.#n&&e.push(this.makeUpdateOrderChange()),this.#h!==void 0&&this.#h!==this.#o&&e.push(this.makeChangeToken()));break;case M.ContentUpdates:!r&&i&&this.#d.length>0&&e.push(this.makeChangePropertyChange()),this.#g.length>0&&e.push(this.makeEvents());break;case M.Removal:n&&e.push(this.makeDestroyEntityChange());break}}makeEvents(){let e={type:p.SendEvents,uuid:this.#e,events:this.#g.slice(0)};return this.#p.size>0&&(e.transferables=Array.from(this.#p)),e}makeCreateEntityChange(){let e={type:p.CreateEntities,uuid:this.#e,token:this.#h};return this.#o=this.#h,this.#u!==void 0&&(e.parentUuid=this.#a=this.#u),this.#f.size>0&&(e.properties=Array.from(this.#f.entries()).filter(([,t])=>t!==void 0),e.properties.forEach(([t,r])=>this.#c.set(t,r))),this.#l!==void 0&&this.#l!==this.#n&&(e.order=this.#n=this.#l),e}makeDestroyEntityChange(){return{type:p.DestroyEntities,uuid:this.#e}}makeSetParentChange(){this.#a=this.#u??void 0;let e={type:p.SetParent,uuid:this.#e,parentUuid:this.#a};return this.#l!==void 0&&this.#l!==this.#n&&(e.order=this.#n=this.#l),e}makeUpdateOrderChange(){return this.#n=this.#l??0,{type:p.UpdateOrder,uuid:this.#e,order:this.#n}}makeChangeToken(){return this.#o=this.#h??I,{type:p.ChangeToken,uuid:this.#e,token:this.#o}}makeChangePropertyChange(){let e=this.#d.map(t=>{if(this.#f.has(t)){let r=this.#f.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 ms=s=>{if(!(s===void 0||s.length===0))return s.filter(e=>e.length===1||e[1]!==void 0)},Lt=(s,e)=>{if(s===e||e===void 0)return s;if(s===void 0)return ms(e);for(let[t,r]of e){let i=s.find(([n])=>n===t);i===void 0?s.push([t,r]):i[1]=r}return ms(s)};var Qe=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=Lt(r.properties,t)}changeToken({uuid:e,token:t}){this.getComponentState(e).token=t||I}updateOrder({uuid:e,order:t}){this.getComponentState(e).order=t??0}setParent({uuid:e,parentUuid:t,order:r}){let i=this.getComponentState(e);i.parentUuid=t,i.order=r??0}destroyEntity({uuid:e}){this.#e.delete(e)}createEntity({uuid:e,token:t,parentUuid:r,order:i,properties:n}){this.#e.set(e,{token:t||I,parentUuid:r,order:i??0,properties:Lt(void 0,n)})}};var R=class s{static{this.ReRequestParentRoots="re-request-parent-roots"}static getContextsMap(){return globalThis.__shadowEntsContexts==null&&(globalThis.__shadowEntsContexts=new Map),globalThis.__shadowEntsContexts}static get(e){let t=ne(e),r=s.getContextsMap();return r.has(t)?r.get(t):new s(t)}#e=new Map;#t=[];#s=new Qe;constructor(e=ie){let t=ne(e),r=s.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 Ce(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.#o(e,this.#t),this.#a=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.#a=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),i=this.#e.get(t.uuid),n=i.children.indexOf(e);n!==-1&&(i.children.splice(n,1),r.changes.setParent(void 0)),this.#o(r.component,this.#t),this.#a=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.#o(t,r.children),this.#e.get(t.uuid)?.changes.setParent(e.uuid),G(this.#t,t.uuid),this.#a=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,i){let n=this.#e.get(e.uuid);return n!=null?(i!=null?(n.propIsEqual??=new Map,n.propIsEqual.set(t,i)):n.propIsEqual?.has(t)&&n.propIsEqual.delete(t),n.changes.changeProperty(t,r,i)):!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);G(t.children,e.uuid),this.#o(e,t.children)}else G(this.#t,e.uuid),this.#o(e,this.#t);this.#e.get(e.uuid)?.changes.changeOrder(e.order),this.#a=void 0}traverseLevelOrderBFS(){return this.#n().map(e=>e.component)}dispatchShadowObjectsEvent(e,t,r,i){this.#e.get(e.uuid)?.changes.createEvent(t,r,i)}broadcastEvent(e,t=void 0){for(let r of this.traverseLevelOrderBFS())r.dispatchEvent(e,t,!1)}dispatchMessage(e,t,r=void 0,i=!1){this.#e.get(e)?.component.dispatchEvent(t,r,i)}dispatchReRequestParentRoots(){for(let e of this.#t)this.dispatchMessage(e,s.ReRequestParentRoots)}buildChangeTrails(e=!0){let t=[];if(!this.hasComponents())return t;let r=this.#r();for(let i of r)i.buildChangeTrail(t,M.StructuralChanges);for(let i of r)i.buildChangeTrail(t,M.ContentUpdates);for(let i of r)i.buildChangeTrail(t,M.Removal),(i.isDestroyed||i.isNew&&!i.isCreated)&&this.#i(i.uuid),e&&i.clear();return this.#s.write(t),t}reCreateChanges(){if(!this.#s.isEmpty()){this.buildChangeTrails(!1);for(let[e,t]of this.#s){let r=this.#e.get(e);if(r){let i=new Ce(e);if(i.create(t.token,t.parentUuid,t.order),t.properties)for(let[n,o]of t.properties)i.changeProperty(n,o,r.propIsEqual?.get(n));r.changes.transferEventsTo(i),r.changes.clear(),r.changes=i}}this.#s.clear(),this.broadcastEvent(is)}}clear(){if(this.#a=void 0,this.#s.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),G(this.#t,e),this.#a=void 0)}#r(){return this.#n().filter(e=>e.changes.hasChanges()).map(e=>e.changes)}#o(e,t){if(t.length===0){t.push(e.uuid);return}if(t.includes(e.uuid))return;let r=t.length,i=new Array(r);if(i[0]=this.#e.get(t[0]).component,e.order<i[0].order){t.unshift(e.uuid);return}if(r===1){t.push(e.uuid);return}let n=r-1;if(i[n]=this.#e.get(t[n]).component,e.order>=i[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(i[o]=this.#e.get(t[o]).component,e.order>=i[o].order){t.splice(o+1,0,e.uuid);return}}#a;#n(){if(this.#a)return this.#a;let e=new Map,t=(r,i)=>{let n=this.#e.get(r);if(n!=null){e.has(i)?e.get(i).push(n):e.set(i,[n]);for(let o of n.children)t(o,i+1)}};return this.#t.forEach(r=>t(r,0)),this.#a=Array.from(e.entries()).sort((r,i)=>r[0]-i[0]).map(([,r])=>r).flat(),this.#a}};function Se(s,e,t,r,i,n){function o(me){if(me!==void 0&&typeof me!="function")throw new TypeError("Function expected");return me}for(var l=r.kind,a=l==="getter"?"get":l==="setter"?"set":"value",h=!e&&s?r.static?s:s.prototype:null,u=e||(h?Object.getOwnPropertyDescriptor(h,r.name):{}),d,E=!1,oe=t.length-1;oe>=0;oe--){var je={};for(var ae in r)je[ae]=ae==="access"?{}:r[ae];for(var ae in r.access)je.access[ae]=r.access[ae];je.addInitializer=function(me){if(E)throw new TypeError("Cannot add initializers after decoration has completed");n.push(o(me||null))};var Z=(0,t[oe])(l==="accessor"?{get:u.get,set:u.set}:u[a],je);if(l==="accessor"){if(Z===void 0)continue;if(Z===null||typeof Z!="object")throw new TypeError("Object expected");(d=o(Z.get))&&(u.get=d),(d=o(Z.set))&&(u.set=d),(d=o(Z.init))&&i.unshift(d)}else(d=o(Z))&&(l==="field"?i.unshift(d):u[a]=d)}h&&Object.defineProperty(h,r.name,u),E=!0}function H(s,e,t){for(var r=arguments.length>2,i=0;i<e.length;i++)t=r?e[i].call(s,t):e[i].call(s);return r?t:void 0}function xe(s){return function(e,t){let r=s?.name||t.name,i=!!(s?.readAsValue??!1);return{get(){let n=A(this,r);if(n)return i?n.value:n.get()},set(n){A(this,r)?.set(n)},init(n){let o=f(n,s);return ts(this,r,o),L.findOrCreate(this).attachSignalByName(r,o),o.value}}}}var P="ConsoleLogger",O=`${P}Storage`,Js=!!(globalThis.location?.host?.startsWith("localhost")??!1),Ae="localStorage"in globalThis,Ye=Symbol.for(P),bs=!1,vs=s=>{if(typeof s=="boolean")return s;switch(s.toLowerCase()){case"true":case"yes":case"on":return!0;default:return!1}},_t=s=>[Ae?P:void 0,...Array.isArray(s)?s:[s]].filter(Boolean).join(".");function Mt(s,e=void 0,t){let r=_t(s),i=Ae?localStorage.getItem(r):globalThis[O]?.[r];return i!=null?e(i):t}function ke(s,e){Ae?localStorage.setItem(_t(s),e):(globalThis[O]==null&&(globalThis[O]={},console.debug(`${P}: Initialize`,{[O]:globalThis[O]})),globalThis[O][_t(s)]=e)}var x=class s{static{this.sharedConfig={enable:Js,debug:!1,info:!0,warn:!0,"styles.debug":"color: #111; background: #999; display: inline-block; padding: 0 0.25em; margin: 0; border-radius: 0.25em","styles.info":"color: #020; background: #8a8; display: inline-block; padding: 0 0.25em; margin: 0; border-radius: 0.25em","styles.warn":"color: #fa0; background: #a98; display: inline-block; padding: 0 0.25em; margin: 0; border-radius: 0.25em","styles.error":"color: #ff0; background: #a00; display: inline-block; padding: 0 0.25em; margin: 0; border-radius: 0.25em"}}static get isEnabled(){return s.sharedConfig.enable}static get isDebug(){return s.sharedConfig.enable&&s.sharedConfig.debug}static{this.sharedStyles={get debug(){return s.sharedConfig["styles.debug"]},set debug(e){s.sharedConfig["styles.debug"]=e},get info(){return s.sharedConfig["styles.info"]},set info(e){s.sharedConfig["styles.info"]=e},get warn(){return s.sharedConfig["styles.warn"]},set warn(e){s.sharedConfig["styles.warn"]=e},get error(){return s.sharedConfig["styles.error"]},set error(e){s.sharedConfig["styles.error"]=e}}}static loadConfig(){Ae?(["enable","debug","info","warn"].forEach(e=>{this.sharedConfig[e]=Mt(e,vs,this.sharedConfig[e])}),["debug","info","warn","error"].forEach(e=>{this.sharedStyles[e]=Mt(["styles",e],void 0,this.sharedStyles[e])}),s.isDebug&&console.debug(`${P}: Load config from localStorage`,s.sharedConfig),globalThis[P]?.[Ye]||(globalThis[P]??={[Ye]:!0,get enable(){return s.sharedConfig.enable},set enable(e){s.sharedConfig.enable=e,ke("enable",e?"true":"false")},get debug(){return s.sharedConfig.debug},set debug(e){s.sharedConfig.debug=e,ke("debug",e?"true":"false")},get info(){return s.sharedConfig.info},set info(e){s.sharedConfig.info=e,ke("info",e?"true":"false")},get warn(){return s.sharedConfig.warn},set warn(e){s.sharedConfig.warn=e,ke("warn",e?"true":"false")}})):globalThis[O]?.[Ye]||(globalThis[O]={[Ye]:!0,...s.sharedConfig,...globalThis[O]},s.sharedConfig=globalThis[O],s.isDebug&&console.debug(`${P}: Load config from ${O}`,globalThis[O]))}constructor(e){this.enable=!0,this.namespace=(e||"").trim()||P,bs||(s.loadConfig(),bs=!0);let t=[this.namespace,"enable"];this.enable=Mt(t,vs,this.enable),ke(t,Ae?this.enable?"true":"false":this.enable)}get isEnabled(){return this.enable&&s.sharedConfig.enable}get isDebug(){return this.isEnabled&&s.sharedConfig.debug}get isInfo(){return this.isEnabled&&s.sharedConfig.info}get isWarn(){return this.isEnabled&&s.sharedConfig.warn}debug(...e){this.#e("debug",s.sharedStyles.debug,e)}info(...e){this.#e("info",s.sharedStyles.info,e)}warn(...e){this.#e("warn",s.sharedStyles.warn,e)}error(...e){this.#e("error",s.sharedStyles.error,e)}#e(e,t,r){console[e](`%c${this.namespace}`,t,...r)}};var _=(()=>{var s;let e,t=[],r=[],i,n=[],o=[];return class ${static{let a=typeof Symbol=="function"&&Symbol.metadata?Object.create(null):void 0;e=[xe()],i=[xe()],Se(this,null,e,{kind:"accessor",name:"viewReady",static:!1,private:!1,access:{has:h=>"viewReady"in h,get:h=>h.viewReady,set:(h,u)=>{h.viewReady=u}},metadata:a},t,r),Se(this,null,i,{kind:"accessor",name:"proxyReady",static:!1,private:!1,access:{has:h=>"proxyReady"in h,get:h=>h.proxyReady,set:(h,u)=>{h.proxyReady=u}},metadata:a},n,o),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;#s;#i;#r;#o;#a;get viewReady(){return this.#a}set viewReady(a){this.#a=a}#n;get proxyReady(){return this.#n}set proxyReady(a){this.#n=a}#h;get isDestroyed(){return this.#h}constructor(){this.#s=!1,this.#i=!1,this.#r=!1,this.logger=new x("ShadowEnv"),this.ns$=f(),this.#a=H(this,t,!1),this.#n=(H(this,r),H(this,n,!1)),this.#h=(H(this,o),!1),this.ready=async()=>this.isReady?this:he(this,$.ContextCreated),this.#u=()=>{this.#s&&this.#l()},D(this,$.ContextCreated),g(this,$.ContextLost,ve.AAA,()=>{F(this,$.ContextCreated)}),b(()=>{if(this.viewReady&&this.proxyReady)return this.view.reCreateChanges(),c(this,$.ContextCreated,this),this.#i&&(this.#i=!1,this.#l()),()=>{c(this,$.ContextLost,this)}},[A(this,"viewReady"),A(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&&this.logger.isWarn&&this.logger.warn("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 h=this.#t;this.#t=a??void 0,this.#t&&(this.#t.onMessageToView=this.#c.bind(this)),h&&h.destroy(),this.proxyReady=!1,a?.start().then(()=>{this.proxyReady=!0}).catch(u=>{this.logger.error("failed to start envProxy",u),this.proxyReady=!1})}}get isReady(){return!!(this.#e&&this.#t&&this.proxyReady&&!this.isDestroyed)}sync(){if(!this.isReady){this.#i=!0;return}this.#s||(this.#s=!0,queueMicrotask(this.#u))}syncWait(){return this.#r=!0,this.sync(),this.#o?this.#o:(this.#o=he(this,$.AfterSync).then(a=>(this.#o=void 0,a)),this.#o)}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),Ee(this),y(this),this.#h=!0,Object.freeze(this)}#u;async#l(){if(this.#s=!1,this.isReady){let a=this.view.buildChangeTrails();if(a.length>0)try{let h=this.#r;this.#r=!1,await this.envProxy.applyChangeTrail(a,h)}catch(h){this.logger.error("failed to apply change trail",h)}finally{c(this,$.AfterSync,a)}}}#c(a){this.logger.isDebug&&this.logger.debug("onMessageToView",a.type,a.data),this.view?.dispatchMessage(a.uuid,a.type,a.data,a.traverseChildren)}}})();var C=["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"],Zs=()=>{let s=Math.random()*4294967295|0,e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,r=Math.random()*4294967295|0;return(C[s&255]+C[s>>8&255]+C[s>>16&255]+C[s>>24&255]+"-"+C[e&255]+C[e>>8&255]+"-"+C[e>>16&15|64]+C[e>>24&255]+"-"+C[t&63|128]+C[t>>8&255]+"-"+C[t>>16&255]+C[t>>24&255]+C[r&255]+C[r>>8&255]+C[r>>16&255]+C[r>>24&255]).toLowerCase()},ws=()=>globalThis?.crypto?.randomUUID?.()??Zs();var Te=class extends Error{constructor(e){super(e),this.name="ViewComponentError"}},Ke=class s{#e;#t;#s;#i;#r=0;get uuid(){return this.#e}get token(){return this.#t}set token(e){e??=I,e!==this.#t&&(this.#t=e,this.#s?.changeToken(this,e))}get parent(){return this.#i}set parent(e){if(e){if(e.#s!==this.#s)throw new Te("cannot set parent from different context");e.addChild(this)}else this.removeFromParent()}get context(){return this.#s}set context(e){this.#s!=e&&(this.#s&&this.destroy(),this.#s=e,e&&e.addComponent(this))}get order(){return this.#r}set order(e){let t=this.#r;this.#r=e??0,t!==this.#r&&this.#s.changeOrder(this)}constructor(e,t){w(this),t instanceof s&&(t={parent:t}),this.#e=t?.uuid??ws(),this.#t=e,this.#r=t?.order??0,this.#i=t?.parent;let r=t?.context??R.get();if(this.#i&&this.#i.#s!==r)throw new Te("cannot set parent from different context");this.context=r}isChildOf(e){return this.#i===e}removeFromParent(){this.#i&&(this.#s?.removeFromParent(this.uuid,this.#i),this.#i=void 0)}addChild(e){if(e.#s!==this.#s)throw new Te("cannot add a child from another context");e.isChildOf(this)||(e.removeFromParent(),e.#i=this,this.#s.addToChildren(this,e))}setProperty(e,t,r){this.#s.setProperty(this,e,t,r)}removeProperty(e){this.#s.removeProperty(this,e)}dispatchShadowObjectsEvent(e,t,r){this.#s.dispatchShadowObjectsEvent(this,e,t,r)}dispatchEvent(e,t,r){if(c(this,e,t),r)for(let i of this.#s.getChildren(this))i.dispatchEvent(e,t,r)}destroy(){this.removeFromParent(),this.#s?.destroyComponent(this),this.#s=void 0}};var Je="shaeRequestEntParent",Ze="shaeReRequestEntParent",Es="shae-worker",Xe="shae-ent",Cs="shae-prop",Q="token",Y="ns",et="local",Ss="no-autostart",tt="no-structured-clone",j="auto-sync",st="src",rt="name",it="value",nt="type",ot="no-trim";var Oe=new Set(["on","true","yes","local","1"]);var xs=s=>ne(s.getAttribute(Y)),Pe=(s,e)=>{if(s.hasAttribute(e)){let t=s.getAttribute(e)?.trim()?.toLowerCase()||"1";return Oe.has(t)}return!1};var ks=(s,e)=>{e.set(xs(s))},jt=new Set,Nt=!1,Xs=s=>{jt.add(s),Nt||(Nt=!0,queueMicrotask(()=>{Nt=!1;for(let e of jt)_.get(e)?.sync();jt.clear()}))},K=class extends HTMLElement{static{this.observedAttributes=[Y]}get ns(){return this.ns$.value}set ns(e){typeof e=="symbol"?this.ns$.set(e):this.ns$.set(ne(e))}constructor(){super(),this.isShaeElement=!0,this.ns$=f(ie),this.ns$.onChange(e=>{typeof e=="string"&&e.length>0?this.getAttribute(Y)!==e&&this.setAttribute(Y,e):this.removeAttribute(Y)}),ks(this,this.ns$)}attributeChangedCallback(e){e===Y&&ks(this,this.ns$)}syncShadowObjects(){Xs(this.ns)}};var at=class extends K{static{this.observedAttributes=[...K.observedAttributes,Q]}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$=f(),this.viewComponent$=f(),this.token$=f(),this.#r=!0,this.#l=()=>{let e=this.findShadowRootHost();e!=null&&this.dispatchEvent(new CustomEvent(Ze,{bubbles:!0,composed:!0,detail:{requester:this,shadowRootHost:e}}))},this.#c=e=>{let t=e.detail?.requester;if(t===this||!t?.isShaeEntElement||t.ns!==this.ns)return;let r=e.detail?.shadowRootHost;r&&this.#h?.has(r)&&this.#a()},this.#f=e=>{let t=e.detail?.requester;t!==this&&t?.isShaeEntElement&&t.ns===this.ns&&(e.stopPropagation(),t.#u(this))},this.ns$.onChange(e=>{this.componentContext$.set(R.get(e)),this.isConnected&&this.#a()}),this.#d(),this.token$.onChange(e=>{e==null?this.removeAttribute(Q):this.getAttribute(Q)!==e&&this.setAttribute(Q,e)}),b(()=>{let e=this.viewComponent$.get();if(e){let t=g(e,R.ReRequestParentRoots,()=>this.#o()),r=e.context?.ns;return()=>{t(),e.destroy(),r&&r!==this.ns?_.get(r)?.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,i=this.viewComponent$.value;i?i.context=t:t&&(i=new Ke(r,{context:t}),this.viewComponent$.set(i)),this.syncShadowObjects()});this.#e=()=>{e()}}#s(){this.#e?.(),this.#e=void 0}#i;#r;findShadowRootHost(){if(this.#r){this.#r=!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.#r=!0,this.addEventListener("slotchange",this.#l,{capture:!1,passive:!1}),this.addEventListener(Je,this.#f,{capture:!1,passive:!1}),this.#t(),St(()=>this.#d()),this.componentContext==null&&this.componentContext$.set(R.get(this.ns)),this.#a(),this.componentContext?.dispatchReRequestParentRoots(),this.syncShadowObjects()}attributeChangedCallback(e){super.attributeChangedCallback(e),e===Q&&this.#d()}disconnectedCallback(){this.#r=!0,this.removeEventListener("slotchange",this.#l,{capture:!1}),this.removeEventListener(Je,this.#f,{capture:!1}),this.#u(void 0),this.componentContext$.set(void 0),this.syncShadowObjects(),this.#s()}#o(){this.isConnected&&this.#a()}#a(){this.dispatchEvent(new CustomEvent(Je,{bubbles:!0,composed:!0,detail:{requester:this}}))}#n;#h;#u(e){if(this.entParentNode!==e){if(this.entParentNode&&this.entParentNode.removeEventListener(Ze,this.#c,{capture:!1}),this.entParentNode=e,this.entParentNode&&this.entParentNode.addEventListener(Ze,this.#c,{capture:!1,passive:!1}),this.#h=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.#h=new WeakSet(t))}if(this.#n?.(),this.#n=void 0,e){let t=b(()=>{let r=this.viewComponent$.get();if(r){let i=e.viewComponent$.get();r.parent=i&&i.context===r.context?i:void 0,r.parent==null&&queueMicrotask(()=>{this.#a()}),this.syncShadowObjects()}});this.#n=()=>t.destroy()}else{let t=this.viewComponent;t.parent&&(t.parent=void 0,this.syncShadowObjects())}}}#l;#c;#f;#d(){if(this.hasAttribute(Q)){let e=this.getAttribute(Q)?.trim()||void 0;this.token$.set(e)}}};customElements.define(Xe,at);var er=s=>{let e=s.parentElement;for(;e;){if(e.isShaeEntElement)return e;e=e.parentElement}},tr=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"]),ht=class extends HTMLElement{static{this.observedAttributes=[rt,it,nt,ot]}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$=f(),this.viewComponent$=f(),this.name$=f(),this.valueIn$=f(),this.valueOut$=f(),this.type$=f(),this.shouldTrim$=f(!0),this.logger=new x("ShaePropElement"),this.#e=()=>{this.entNode$.set(er(this))},this.#t=()=>{queueMicrotask(()=>{this.isConnected||this.entNode$.set(void 0)})},this.#s=()=>{this.name$.set(this.getAttribute(rt)?.trim()??void 0)},this.#i=()=>{this.valueIn$.set(this.getAttribute(it))},this.#r=()=>{let e=this.getAttribute(nt)?.trim().toLowerCase();e&&!tr.has(e)&&(this.logger.isWarn&&this.logger.warn(`[${this.name}] unknown type "${e}"`,{shaeProp:this}),e=void 0),this.type$.set(e)},this.#o=()=>{this.shouldTrim$.set(!Pe(this,ot))},this.entNode$.onChange(e=>{if(e){let t=de(e.viewComponent$,this.viewComponent$);return()=>{t.destroy()}}else this.viewComponent$.set(void 0)}),b(()=>{let e=this.viewComponent$.get();if(e){let t=this.name$.get();if(t){let r=this.valueOut$.get();this.logger.isDebug&&this.logger.debug(`[${this.name}] view-component set-property`,t,r,e.uuid,{viewComponent:e,shaeProp:this}),e.setProperty(t,r),this.isConnected&&this.entNode?.syncShadowObjects()}}}),b(()=>{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=Oe.has(r.toLowerCase());break;case"[]":case"text[]":case"string[]":r=r.split(/\W+/);break;case"number[]":r=r.split(/\W+/).map(i=>Number(i));break;case"float[]":r=r.split(/\W+/).map(i=>parseFloat(i));break;case"int[]":case"integer[]":r=r.split(/\W+/).map(i=>parseInt(i));break;case"hex[]":case"hexadecimal[]":r=r.split(/\W+/).map(i=>parseInt(i,16));break;case"oct[]":case"octal[]":r=r.split(/\W+/).map(i=>parseInt(i,8));break;case"bin[]":case"binary[]":r=r.split(/\W+/).map(i=>parseInt(i,2));break;case"bool[]":case"boolean[]":r=r.split(/\W+/).map(i=>Oe.has(i.toLowerCase()));break;case"int8array":r=new Int8Array(r.split(/\W+/).map(i=>Number(i)));break;case"uint8array":r=new Uint8Array(r.split(/\W+/).map(i=>Number(i)));break;case"uint8clampedarray":r=new Uint8ClampedArray(r.split(/\W+/).map(i=>Number(i)));break;case"int16array":r=new Int16Array(r.split(/\W+/).map(i=>Number(i)));break;case"uint16array":r=new Uint16Array(r.split(/\W+/).map(i=>Number(i)));break;case"int32array":r=new Int32Array(r.split(/\W+/).map(i=>Number(i)));break;case"uint32array":r=new Uint32Array(r.split(/\W+/).map(i=>Number(i)));break;case"float32array":r=new Float32Array(r.split(/\W+/).map(i=>Number(i)));break;case"float64array":r=new Float64Array(r.split(/\W+/).map(i=>Number(i)));break;case"bigint64array":r=new BigInt64Array(r.split(/\W+/).map(i=>BigInt(i)));break;case"biguint64array":r=new BigUint64Array(r.split(/\W+/).map(i=>BigInt(i)));break;case"json":r=JSON.parse(r);break;default:this.logger.isWarn&&this.logger.warn(`[${this.name}] unknown type "${e}"`,{value:r,shaeProp:this})}this.valueOut$.set(r)}),k(()=>{this.#s(),this.#i(),this.#r(),this.#o()})}connectedCallback(){k(()=>{this.#e(),this.#s(),this.#i(),this.#r(),this.#o()})}attributeChangedCallback(e){switch(e){case rt:this.#s();break;case it:this.#i();break;case nt:this.#r();break;case ot:this.#o();break}}disconnectedCallback(){this.#t()}#e;#t;#s;#i;#r;#o};customElements.whenDefined(Xe).then(()=>customElements.define(Cs,ht));var lt,Dt=null,ge=class{static{this.OnFrame=Symbol("onFrame")}#e=0;#t=0;constructor(){if(Dt)return Dt;w(this),Dt=this}start(e){if(e!=null)return Et(this)===0&&this.#i(),g(this,lt.OnFrame,e),this.#t++,()=>{this.stop(e)}}stop(e){y(this,lt.OnFrame,e),Et(this)===0&&this.#r()}#s=e=>{c(this,lt.OnFrame,e),this.#i()};#i(){this.#e=requestAnimationFrame(this.#s)}#r(){cancelAnimationFrame(this.#e),this.#e=0}};lt=ge;var ye="value",ut=(()=>{let s,e=[],t=[];return class{static{let i=typeof Symbol=="function"&&Symbol.metadata?Object.create(null):void 0;s=[xe({name:ye})],Se(this,null,s,{kind:"accessor",name:"value",static:!1,private:!1,access:{has:n=>"value"in n,get:n=>n.value,set:(n,o)=>{n.value=o}},metadata:i},e,t),i&&Object.defineProperty(this,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:i})}static{this.Value=ye}#e=[];#t;#s=H(this,e,void 0);get value(){return this.#s}set value(i){this.#s=i}constructor(){H(this,t),D(this,ye),A(this,ye).onChange(i=>c(this,ye,i))}add(...i){for(let n of i)this.#e.push(n);this.#r()}clear(){this.#e.length=0,this.#i()}dispose(){this.clear(),F(this,ye),y(this),Ee(this)}#i(){this.#t?.destroy(),this.#t=void 0}#r(){this.#i(),this.#t=b(()=>{for(let i of this.#e){let n=re(i);if(n!=null){this.value=n;return}}this.value=void 0},this.#e),this.#t.run()}}})();var It="onCreate",J="onDestroy",As="onViewEvent";var ct=class{#e;#t;#s=new He;#i=new Map;#r;#o;#a=new Set;#n=[];#h=0;get kernel(){return this.#e}get uuid(){return this.#t}get order(){return this.#h}set order(e){this.#h!==e&&(this.#h=e,this.#r&&this.parent.resortChildren())}get parentUuid(){return this.#r||void 0}set parentUuid(e){this.#r!==e&&(this.removeFromParent(),this.#r=e||void 0,this.#o=e?this.#e.getEntity(e):void 0,this.#o&&this.#o.addChild(this))}get parent(){return!this.#o&&this.#r&&(this.#o=this.#e.getEntity(this.#r)),this.#o}set parent(e){this.parentUuid=e?.uuid}get hasParent(){return!!this.#r}get children(){return this.#n}constructor(e,t){this.#e=e,this.#t=t,v(this,J,ve.Min,this)}traverse(e){e(this);for(let t of this.#n)t.traverse(e)}onDestroy(){this.#s.clear(),y(this);for(let e of this.#i.values())e.unsubscribeFromPath(),e.unsubscribeFromParent?.(),e.ctxPath.dispose(),e.inherited.destroy(),e.provide.destroy(),e.context.destroy();this.#r=void 0,this.#o=void 0,this.#a.clear(),this.#n.length=0}addChild(e){if(this.#n.length===0){this.#a.add(e.uuid),this.#n.push(e);return}if(this.#a.has(e.uuid))throw new Error(`child with uuid: ${e.uuid} already exists! parentUuid: ${this.uuid}`);this.#a.add(e.uuid),this.#n.push(e),this.resortChildren();for(let[,t]of e.#i)e.#c(t)}resortChildren(){this.#n.sort((e,t)=>e.order-t.order)}removeChild(e){this.#a.has(e.uuid)&&(this.#a.delete(e.uuid),this.#n.splice(this.#n.indexOf(e),1))}removeFromParent(){if(this.#o){this.#o.removeChild(this),this.#o=void 0,this.#r=void 0;for(let[,e]of this.#i)e.unsubscribeFromParent&&(e.unsubscribeFromParent(),e.unsubscribeFromParent=void 0)}}dispatchMessageToView(e,t,r,i=!1){this.#e.dispatchMessageToView({uuid:this.#t,type:e,data:t,transferables:r,traverseChildren:i})}dispatchViewEvents(e){for(let{type:t,data:r}of e)c(this,As,t,r)}dispatchViewEvent(e,t){this.dispatchViewEvents([{type:e,data:t}])}#u(e){return this.#s.get(e)}getPropertyReader(e){return this.#u(e).get}getPropertyWriter(e){return this.#u(e).set}setProperties(e){k(()=>{for(let[t,r]of e)this.setProperty(t,r)})}setProperty(e,t){this.getPropertyWriter(e)(t)}getProperty(e){return re(this.getPropertyReader(e))}propKeys(){return Array.from(this.#s.keys())}propEntries(){return Array.from(this.#s.entries()).map(([e,t])=>[e,t.value])}hasContext(e){return this.#i.has(e)}useContext(e){return this.#l(e).context.get}provideContext(e){return this.#l(e).provide}#l(e){let t=this.#i.get(e);if(t==null){let r=f(),i=f(),n=f(),o=new ut;o.add(i.get,r.get);let l=g(o,ut.Value,a=>{queueMicrotask(()=>{n.set(a)})});t={name:e,inherited:r,provide:i,context:n,ctxPath:o,unsubscribeFromPath:l},this.#i.set(e,t),this.#c(t)}return t}#c(e){this.parent&&(e.unsubscribeFromParent?.(),e.unsubscribeFromParent=g(this.parent.#l(e.name).ctxPath,ut.Value,t=>{e.inherited.set(t)}))}};var Re=class{static get(e){return e??sr}#e=new Map;#t=new Map;define(e,t){this.#e.has(e)?ys(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 i of t)r.add(i)}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 i=r.shift();t.has(i)||(t.add(i),this.#t.has(i)&&r.push(...Array.from(this.#t.get(i)).filter(n=>!t.has(n))))}return Array.from(t)}findConstructors(e){let t=this.findTokensByRoute(e),r=new Set;for(let i of t){let n=this.#e.get(i);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()}},sr=new Re;var W;(function(s){s[s.CreateAndDestroy=0]="CreateAndDestroy",s[s.JustCreate=1]="JustCreate",s[s.DestroyOnly=2]="DestroyOnly"})(W||(W={}));var Ts=s=>s.displayName||s.name,ft=class{#e;#t;#s;#i;#r;constructor(e){this.logger=new x("Kernel"),this.#e=new Map,this.#t=new Set,this.#r=!0,w(this),this.registry=Re.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.#r){let t=new Map,r=(i,n)=>{let o=this.getEntity(i);t.has(n)?t.get(n).push(o):t.set(n,[o]);for(let l of o.children)r(l.uuid,n+1)};this.#t.forEach(i=>r(i,0)),this.#s=Array.from(t.entries()).sort((i,n)=>i[0]-n[0]).map(([,i])=>i).flat(),this.#i=this.#s.slice().reverse(),this.#r=!1}return e?this.#i:this.#s}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(i=>this.getEntityGraphNode(i.uuid))}}upgradeEntities(){for(let e of this.traverseLevelOrderBFS(!0))this.updateShadowObjects(e.uuid,W.DestroyOnly);for(let e of this.traverseLevelOrderBFS(!1))this.updateShadowObjects(e.uuid,W.JustCreate)}run(e){k(()=>{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.#r=!0;break;case p.DestroyEntities:this.destroyEntity(e.uuid),this.#r=!0;break;case p.SetParent:this.setParent(e.uuid,e.parentUuid,e.order),this.#r=!0;break;case p.UpdateOrder:this.updateOrder(e.uuid,e.order),this.#r=!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,i=0,n){let o=new ct(this,e);o.order=i;let l={token:t,entity:o,usedConstructors:new Map};this.#e.set(e,l),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(),c(t,J,this),r.clear(),this.#e.delete(t.uuid),this.#t.delete(t.uuid)}setParent(e,t,r=0){let i=this.getEntity(e);i.parentUuid===t&&i.order===r||(i.removeFromParent(),i.order=r,i.parentUuid=t,i.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(()=>{c(this,pe,e)})}updateShadowObjects(e,t=W.CreateAndDestroy){let r=this.#e.get(e),i=new Set(this.registry.findConstructors(r.token)),n=t===W.CreateAndDestroy||t===W.DestroyOnly,o=t===W.CreateAndDestroy||t===W.JustCreate;if(n){for(let[l,a]of r.usedConstructors)if(!i.has(l)){r.usedConstructors.delete(l);for(let h of a)this.destroyShadowObject(h,r.entity)}}if(o)for(let l of i)r.usedConstructors.has(l)||this.constructShadowObject(l,r)}constructShadowObject(e,t){let r=new Set,i=new Set,n=new Map,o=new Map,l=new Map,a=w(new e({entity:t.entity,provideContext(h,u,d){let E=o.get(h);if(E===void 0){E=f(u,d?{compare:d}:void 0),o.set(h,E);let oe=de(E,t.entity.provideContext(h));i.add(oe.destroy.bind(oe))}return E},useContext(h,u){let d=n.get(h);if(d===void 0){d=f(void 0,u?{compare:u}:void 0).get,n.set(h,d);let E=de(t.entity.useContext(h),d);i.add(E.destroy.bind(E))}return d},useProperty(h,u){let d=l.get(h);if(d===void 0){d=f(void 0,u?{compare:u}:void 0).get,l.set(h,d);let E=de(t.entity.getPropertyReader(h),d);i.add(E.destroy.bind(E))}return d},createEffect(...h){let u=b(...h);return i.add(u.destroy),u},createSignal(...h){let u=f(...h);return i.add(()=>{S(u)}),u},on(...h){let u=g(...h);return i.add(u),u},once(...h){let u=v(...h);return i.add(u),u},onDestroy(h){r.add(h)}}));return this.logger.isInfo&&this.logger.info("create shadow-object",Ts(e),{shadowObject:a,entity:t.entity}),v(a,J,()=>{this.logger.isInfo&&this.logger.info("destroy shadow-object",Ts(e),{shadowObject:a,entity:t.entity});for(let u of r)u();for(let u of i)u();for(let u of n.values())S(u);for(let u of l.values())S(u);for(let u of o.values())S(u);r.clear(),i.clear(),n.clear(),l.clear(),o.clear();let h=t.usedConstructors.get(e);h&&(h.delete(a),h.size===0&&t.usedConstructors.delete(e))}),t.usedConstructors.has(e)?t.usedConstructors.get(e).add(a):t.usedConstructors.set(e,new Set([a])),this.attachShadowObject(a,t.entity),a}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){g(t,e),typeof e[It]=="function"&&e[It](t)}destroyShadowObject(e,t){typeof e[J]=="function"&&e[J](t),c(e,J,t),y(t,e)}destroy(){for(let e of this.traverseLevelOrderBFS().reverse())this.destroyEntity(e.uuid)}};async function $t(s,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=>$t(s,n,t,!1)));let{registry:i}=s;if(e.define)for(let[n,o]of Object.entries(e.define))i.define(n,o);if(e.routes)for(let[n,o]of Object.entries(e.routes))i.appendRoute(n,o);await(e.initialize?.({define:(n,o)=>i.define(n,o),kernel:s,registry:i})??Promise.resolve()),r&&s.upgradeEntities()}var dt=s=>(typeof s=="string"&&(s=new URL(s,globalThis.location.href)),s.toString());function Os(s){return s.map(e=>{if(e.transferables&&e.transferables.length>0){let{transferables:t,...r}=e;return structuredClone(r,{transfer:t})}else return structuredClone(e)})}var pt=class{#e;get registry(){return this.kernel.registry}constructor(e){this.#e=new Set,this.isLocalEnv=!0,this.disableStructuredClone=!1,this.kernel=new ft(e),g(this.kernel,pe,t=>{if(this.onMessageToView!=null){let{type:r,uuid:i,traverseChildren:n}=t,o=structuredClone(t.data,{transfer:t.transferables});this.onMessageToView({type:r,uuid:i,data:o,traverseChildren:n})}})}start(){return Promise.resolve()}applyChangeTrail(e,t){let r={changeTrail:this.disableStructuredClone?e:Os(e)},i;try{this.kernel.run(r),i=Promise.resolve()}catch(n){i=Promise.reject(n)}return i}async importScript(e){let t=await import(dt(e));t[Pt]&&await this.importModule(t[Pt])}async importModule(e){return $t(this.kernel,e,this.#e)}destroy(){this.kernel.destroy(),this.registry.clear(),this.#e.clear()}};function Wt(s){let e=new Blob([s],{type:"text/javascript"}),t=URL.createObjectURL(e),r=new Worker(t);return URL.revokeObjectURL(t),r}function Ft(){return Wt('var Ps=Object.defineProperty;var Ke=Object.getOwnPropertySymbols;var jt=Object.prototype.hasOwnProperty,Mt=Object.prototype.propertyIsEnumerable;var js=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Tt=e=>{throw TypeError(e)};var rt=(e,t,s)=>t in e?Ps(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,it=(e,t)=>{for(var s in t||(t={}))jt.call(t,s)&&rt(e,s,t[s]);if(Ke)for(var s of Ke(t))Mt.call(t,s)&&rt(e,s,t[s]);return e};var Lt=(e,t)=>{var s={};for(var r in e)jt.call(e,r)&&t.indexOf(r)<0&&(s[r]=e[r]);if(e!=null&&Ke)for(var r of Ke(e))t.indexOf(r)<0&&Mt.call(e,r)&&(s[r]=e[r]);return s};var c=(e,t,s)=>rt(e,typeof t!="symbol"?t+"":t,s),at=(e,t,s)=>t.has(e)||Tt("Cannot "+s);var i=(e,t,s)=>(at(e,t,"read from private field"),s?s.call(e):t.get(e)),g=(e,t,s)=>t.has(e)?Tt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,s),u=(e,t,s,r)=>(at(e,t,"write to private field"),r?r.call(e,s):t.set(e,s),s),b=(e,t,s)=>(at(e,t,"access private method"),s);var Dt=(e,t,s,r)=>({set _(a){u(e,t,a,s)},get _(){return i(e,t,r)}});var nt=function(e,t){this[0]=e,this[1]=t},Rt=(e,t,s)=>{var r=(n,h,l,d)=>{try{var p=s[n](h),f=(h=p.value)instanceof nt,v=p.done;Promise.resolve(f?h[0]:h).then(C=>f?r(n==="return"?n:"next",h[1]?{done:C.done,value:C.value}:C,l,d):l({value:C,done:v})).catch(C=>r("throw",C,l,d))}catch(C){d(C)}},a=n=>o[n]=h=>new Promise((l,d)=>r(n,h,l,d)),o={};return s=s.apply(e,t),o[js("asyncIterator")]=()=>o,a("next"),a("throw"),a("return"),o};var Nt;(function(e){e[e.StructuralChanges=1]="StructuralChanges",e[e.ContentUpdates=2]="ContentUpdates",e[e.Removal=3]="Removal"})(Nt||(Nt={}));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 jr=Symbol.for("ShadowEntsGlobalNS"),Ms="configure",Ts="changeTrail",Ls="destroy",Ds="loaded",zt="appliedChangeTrail",ot="importedModule",Rs="destroyed",gt="messageToView",ht="shadowObjects",z="ConsoleLogger",M=`${z}Storage`,Qt,Xt,Zt,Ns=!!((Zt=(Xt=(Qt=globalThis.location)==null?void 0:Qt.host)==null?void 0:Xt.startsWith("localhost"))!=null&&Zt),Ve="localStorage"in globalThis,Ye=Symbol.for(z),Vt=!1,xt=e=>{if(typeof e=="boolean")return e;switch(e.toLowerCase()){case"true":case"yes":case"on":return!0;default:return!1}},yt=e=>[Ve?z:void 0,...Array.isArray(e)?e:[e]].filter(Boolean).join(".");function lt(e,t=void 0,s){var o;let r=yt(e),a=Ve?localStorage.getItem(r):(o=globalThis[M])==null?void 0:o[r];return a!=null?t(a):s}function Te(e,t){Ve?localStorage.setItem(yt(e),t):(globalThis[M]==null&&(globalThis[M]={},console.debug(`${z}: Initialize`,{[M]:globalThis[M]})),globalThis[M][yt(e)]=t)}var de,De,y,zs=(y=class{constructor(t){g(this,de);this.enable=!0,this.namespace=(t||"").trim()||z,Vt||(y.loadConfig(),Vt=!0);let s=[this.namespace,"enable"];this.enable=lt(s,xt,this.enable),Te(s,Ve?this.enable?"true":"false":this.enable)}static get isEnabled(){return y.sharedConfig.enable}static get isDebug(){return y.sharedConfig.enable&&y.sharedConfig.debug}static loadConfig(){var t,s,r;Ve?(["enable","debug","info","warn"].forEach(a=>{this.sharedConfig[a]=lt(a,xt,this.sharedConfig[a])}),["debug","info","warn","error"].forEach(a=>{this.sharedStyles[a]=lt(["styles",a],void 0,this.sharedStyles[a])}),y.isDebug&&console.debug(`${z}: Load config from localStorage`,y.sharedConfig),(t=globalThis[z])!=null&&t[Ye]||((s=globalThis[z])!=null||(globalThis[z]={[Ye]:!0,get enable(){return y.sharedConfig.enable},set enable(a){y.sharedConfig.enable=a,Te("enable",a?"true":"false")},get debug(){return y.sharedConfig.debug},set debug(a){y.sharedConfig.debug=a,Te("debug",a?"true":"false")},get info(){return y.sharedConfig.info},set info(a){y.sharedConfig.info=a,Te("info",a?"true":"false")},get warn(){return y.sharedConfig.warn},set warn(a){y.sharedConfig.warn=a,Te("warn",a?"true":"false")}}))):(r=globalThis[M])!=null&&r[Ye]||(globalThis[M]=it(it({[Ye]:!0},y.sharedConfig),globalThis[M]),y.sharedConfig=globalThis[M],y.isDebug&&console.debug(`${z}: Load config from ${M}`,globalThis[M]))}get isEnabled(){return this.enable&&y.sharedConfig.enable}get isDebug(){return this.isEnabled&&y.sharedConfig.debug}get isInfo(){return this.isEnabled&&y.sharedConfig.info}get isWarn(){return this.isEnabled&&y.sharedConfig.warn}debug(...t){b(this,de,De).call(this,"debug",y.sharedStyles.debug,t)}info(...t){b(this,de,De).call(this,"info",y.sharedStyles.info,t)}warn(...t){b(this,de,De).call(this,"warn",y.sharedStyles.warn,t)}error(...t){b(this,de,De).call(this,"error",y.sharedStyles.error,t)}},de=new WeakSet,De=function(t,s,r){console[t](`%c${this.namespace}`,s,...r)},y.sharedConfig={enable:Ns,debug:!1,info:!0,warn:!0,"styles.debug":"color: #111; background: #999; display: inline-block; padding: 0 0.25em; margin: 0; border-radius: 0.25em","styles.info":"color: #020; background: #8a8; display: inline-block; padding: 0 0.25em; margin: 0; border-radius: 0.25em","styles.warn":"color: #fa0; background: #a98; display: inline-block; padding: 0 0.25em; margin: 0; border-radius: 0.25em","styles.error":"color: #ff0; background: #a00; display: inline-block; padding: 0 0.25em; margin: 0; border-radius: 0.25em"},y.sharedStyles={get debug(){return y.sharedConfig["styles.debug"]},set debug(t){y.sharedConfig["styles.debug"]=t},get info(){return y.sharedConfig["styles.info"]},set info(t){y.sharedConfig["styles.info"]=t},get warn(){return y.sharedConfig["styles.warn"]},set warn(t){y.sharedConfig["styles.warn"]=t},get error(){return y.sharedConfig["styles.error"]},set error(t){y.sharedConfig["styles.error"]=t}},y),pe="*",ns=1,St=2,At=4,oe=Symbol.for("eventize"),Vs="[eventize]",He=e=>e===pe,os=e=>{switch(typeof e){case"string":case"symbol":return!0;default:return!1}},hs=typeof console<"u",xs=hs?console[console.warn?"warn":"log"].bind(console,Vs):()=>{},Fs=(e,t,s)=>(Object.defineProperty(e,t,{value:s,configurable:!0}),e),Is=0,ls=class{constructor(){c(this,"events",new Map);c(this,"eventNames",new Set)}static publish(e){e.sort((t,s)=>t.order-s.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:Is++})}isKnown(e){return this.eventNames.has(e)}emit(e,t,s=[]){if(He(e))this.eventNames.forEach(r=>this.emit(r,t,s));else if(this.events.has(e)){let{order:r,args:a}=this.events.get(e);s.push({order:r,emit:()=>t.apply(e,a)})}return s}},pt=(e,t,s,r)=>{if(typeof t=="function"){let a=t.apply(e,s);a!=null&&(r==null||r(a))}},Us=(e,t,s,r)=>pt(t,t.emit,[e].concat(s),r),Bs=e=>{switch(typeof e){case"function":return ns;case"string":case"symbol":return St;case"object":return At}},Gs=0,$s=()=>++Gs,ds=class{constructor(e,t,s,r=null){c(this,"id");c(this,"eventName");c(this,"isCatchEmAll");c(this,"priority");c(this,"listener");c(this,"listenerObject");c(this,"listenerType");c(this,"callAfterApply");c(this,"isRemoved");c(this,"refCount");this.id=$s(),this.eventName=e,this.isCatchEmAll=He(e),this.listener=s,this.listenerObject=r,this.priority=t,this.listenerType=Bs(s),this.callAfterApply=void 0,this.isRemoved=!1,this.refCount=1}isEqual(e,t=null){if(e===this)return!0;let s=typeof e;return s==="number"&&e===this.id?!0:t===null&&(s==="string"||s==="symbol")?e===pe||e===this.eventName:this.listener===e&&this.listenerObject===t}apply(e,t,s){if(this.isRemoved)return;let{listener:r,listenerObject:a}=this;switch(this.listenerType){case ns:pt(a,r,t,s),this.callAfterApply&&this.callAfterApply();break;case St:pt(a,a[r],t,s),this.callAfterApply&&this.callAfterApply();break;case At:{let o=r[e];if(this.isCatchEmAll||this.eventName===e){if(typeof o=="function"){let n=o.apply(r,t);n!=null&&(s==null||s(n))}else Us(e,r,t,s);this.callAfterApply&&this.callAfterApply()}break}}}},Ws=(e,t)=>e.priority!==t.priority?t.priority-e.priority:e.id-t.id,Ft=e=>e==null?void 0:e.slice(0),It=(e,t)=>{let s=e.indexOf(t);s>-1&&e.splice(s,1)},qs=e=>e===At||e===St,vt=(e,t,s)=>{let r=e.findIndex(a=>a.isEqual(t,s));r>-1&&(e[r].isRemoved=!0,e.splice(r,1))},Qe=(e,t,s)=>{let r=[];for(let a of e)(t==null&&a.listenerObject===s||a.eventName===t&&a.listener===s)&&r.push(a);for(let a of r)vt(e,a,void 0)},dt=e=>{e&&(e.forEach(t=>{t.isRemoved=!0}),e.length=0)},Js=(e,t)=>e.listenerType===t.listenerType?e.priority===t.priority&&e.eventName===t.eventName&&e.listenerObject===t.listenerObject&&e.listener===t.listener:!1,Ks=(e,t)=>{if(qs(e.listenerType))return t.find(s=>Js(e,s))},Ys=(e,t)=>{let s=Ks(e,t);return s?(s.refCount+=1,s):(t.push(e),t.sort(Ws),e)},Qs=class{constructor(){c(this,"namedListeners");c(this,"catchEmAllListeners");c(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 Ys(e,e.isCatchEmAll?this.catchEmAllListeners:this.getListenersForEventName(e.eventName))}remove(e,t,s=!1){t==null&&Array.isArray(e)?e.forEach(r=>this.remove(r,null,s)):e==null||t==null&&He(e)?this.removeAllListeners():t==null&&os(e)?dt(this.namedListeners.get(e)):e instanceof ds?e.isRemoved||(e.refCount-=1,e.refCount<1&&(e.isRemoved=!0,this.namedListeners.forEach(r=>It(r,e)),It(this.catchEmAllListeners,e))):s?He(e)?Qe(this.catchEmAllListeners,pe,e):this.namedListeners.forEach(r=>Qe(r,e,t)):(this.namedListeners.forEach(r=>{vt(r,e,t),Qe(r,void 0,e)}),vt(this.catchEmAllListeners,e,t),Qe(this.catchEmAllListeners,void 0,e))}removeAllListeners(){this.namedListeners.forEach(e=>dt(e)),this.namedListeners.clear(),dt(this.catchEmAllListeners)}forEach(e,t){let s=Ft(this.catchEmAllListeners),r=Ft(this.namedListeners.get(e));if(e===pe||!r||r.length===0)s.forEach(t);else if(s.length===0)r.forEach(t);else{let a=r.length,o=s.length,n=0,h=0;for(;n<a||h<o;){if(n<a){let l=r[n];if(h>=o||l.priority>=s[h].priority){t(l),++n;continue}}h<o&&(t(s[h]),++h)}}}getSubscriptionCount(){let e=this.catchEmAllListeners.length;for(let t of this.namedListeners.values())e+=t.length;return e}},je=e=>!!(e&&e[oe]);function xe(e){if(je(e))return e;let t=new Qs,s=new ls;return Fs(e,oe,{keeper:s,store:t}),e}var us={Max:Number.POSITIVE_INFINITY,AAA:1e9,BB:1e6,C:1e3,Default:0,Low:-1e4,Min:Number.NEGATIVE_INFINITY},Xs=(e,t,s,r,a,o,n)=>{let h=e.add(new ds(s,r,a,o));return t.emit(s,h,n),h},Zs=(e,t,s,r)=>{let a=s.length,o=typeof s[0],n,h,l,d;if(a>=2&&a<=3&&o==="number"?(n=pe,[h,l,d]=s):a>=3&&a<=4&&typeof s[1]=="number"?[n,h,l,d]=s:(h=us.Default,o==="string"||o==="symbol"||Array.isArray(s[0])?[n,l,d]=s:(n=pe,[l,d]=s)),!l&&hs)throw xs("called with insufficient arguments!",s),"subscribeTo() called with insufficient arguments!";let p=f=>v=>Xs(e,t,v,f,l,d,r);return Array.isArray(n)?n.map(f=>Array.isArray(f)?p(f[1])(f[0]):p(h)(f)):p(h)(n)},cs=(e,t,s)=>{let r=[],a=Zs(e,t,s,r);return ls.publish(r),a},Ut=e=>t=>{t.callAfterApply=()=>{e==null||e()}},fs=(e,t)=>Object.assign(()=>T(e,t),Array.isArray(t)?{listeners:t}:{listener:t}),gs=(e,t,s,r)=>{let{store:a,keeper:o}=e[oe];Array.isArray(t)?t.forEach(n=>{a.forEach(n,h=>h.apply(n,s,r)),o.retain(n,s)}):t!==pe&&(a.forEach(t,n=>{n.apply(t,s,r)}),o.retain(t,s))},Z=(e,...t)=>{let s=xe(e),{store:r,keeper:a}=s[oe];return fs(s,cs(r,a,t))},L=(e,...t)=>{let s=xe(e),{store:r,keeper:a}=s[oe],o=cs(r,a,t),n=fs(s,o),h=!1,l=()=>{h||(n(),h=!0)};return Array.isArray(o)?o.forEach(Ut(l)):Ut(l)(o),l},Hs=(e,t)=>new Promise(s=>{L(e,t,s)}),T=(e,t,s)=>{if(!je(e))throw new Error("object is not eventized");let{store:r,keeper:a}=e[oe],o=typeof t,n=s!=null&&(o==="string"||o==="symbol");r.remove(t,s,n),Array.isArray(t)?a.remove(t.filter(h=>typeof h=="string")):os(t)&&a.remove(t)},m=(e,t,...s)=>{if(!je(e))throw new Error("object is not eventized");gs(e,t,s)},_s=(e,t,...s)=>{if(!je(e))throw new Error("object is not eventized");let r=[];return gs(e,t,s,a=>{r.push(a)}),r=r.map(a=>Array.isArray(a)?Promise.all(a):Promise.resolve(a)),r.length>0?Promise.all(r):Promise.resolve()},kt=(e,t)=>{let s=xe(e),{keeper:r}=s[oe];r.add(t)},_e=(e,t)=>{if(!je(e))throw new Error("object is not eventized");let{keeper:s}=e[oe];s.clear(t)},ae=(()=>{let e=(t={})=>xe(t);return e.inject=(t={})=>(t=xe(t),Object.assign(t,{on:(...s)=>Z(t,...s),once:(...s)=>L(t,...s),onceAsync:s=>Hs(t,s),off:(s,r)=>T(t,s,r),emit:(s,...r)=>m(t,s,...r),emitAsync:(s,...r)=>_s(t,s,...r),retain:s=>kt(t,s),retainClear:s=>_e(t,s)}),t),e.is=je,e})(),Ne=ae(),Fe=ae(),we=ae(),ft,Be,Re=(ft=class{constructor(){g(this,Be,new Set)}batch(e){i(this,Be).add(e)}run(){m(we,Array.from(i(this,Be)))}},Be=new WeakMap,c(ft,"current"),ft),er=()=>Re.current;function et(e){let t=Re.current;t?t=void 0:t=Re.current=new Re;try{e()}finally{t&&(Re.current=void 0,t.run())}}var tr=0;function ys(){return tr>0}var W=Symbol.for("signal"),me=Symbol.for("effect"),Bt=Symbol.for("destroySignal"),Gt=Symbol.for("createEffect"),sr=Symbol.for("destroyEffect"),Le="value",$t="mute",Wt="unmute",ze="destroy",H=new Map,x,_,D,F,I,ue,ee,E,U,ie,tt=(ie=class{constructor(t){g(this,x,new Set);g(this,_,new Set);g(this,D,new Map);g(this,F,new WeakMap);g(this,I,new Map);g(this,ue,new Set);g(this,ee,new Set);g(this,E,!1);g(this,U);if(t!=null&&t instanceof ie&&!i(t,E))return t;if(t!=null||(t=this),H.has(t))return H.get(t);H.set(t,this),ae(this)}static get(t){if(t!=null)return t instanceof ie&&!i(t,E)?t:H.get(t)}static findOrCreate(t){if(t==null)throw new Error("Cannot create a group with a null object");return new ie(t)}static destroy(t){var s;(s=H.get(t))==null||s.destroy()}static clear(){for(let t of H.values())t.destroy();H.clear()}attachGroup(t){if(i(this,E))throw new Error("Cannot attach a group to a destroyed group");if(t===this)throw new Error("Cannot attach a group to itself");return i(this,x).add(t),i(t,U)&&i(t,U)!==this&&i(i(t,U),x).delete(t),u(t,U,this),t}detachGroup(t){if(i(this,E))throw new Error("Cannot detach a group from a destroyed group");return t!==this&&i(this,x).has(t)&&(i(this,x).delete(t),u(t,U,void 0)),t}attachSignal(t){if(i(this,E))throw new Error("Cannot attach a signal to a destroyed group");let s=k(t);if(s!=null&&s.destroyed)throw new Error("Cannot attach a destroyed signal to a group");return s&&i(this,_).add(s),t}attachSignalByName(t,s){if(i(this,E))throw new Error("Cannot attach a named signal to a destroyed group");if(s){this.attachSignal(s);let r=k(s);i(this,D).set(t,r),i(this,I).has(t)?i(this,I).get(t).push(r):i(this,I).set(t,[r]),i(this,F).has(r)?i(this,F).get(r).add(t):i(this,F).set(r,new Set([t]))}else i(this,D).delete(t);return s}hasSignal(t){var s;return i(this,D).has(t)||((s=i(this,U))==null?void 0:s.hasSignal(t))}signal(t){var s,r,a;if(!i(this,E))return(a=(s=i(this,D).get(t))==null?void 0:s.object)!=null?a:(r=i(this,U))==null?void 0:r.signal(t)}detachSignal(t){if(i(this,E))return t;let s=k(t);if(s&&(i(this,_).delete(s),i(this,F).has(s))){let r=i(this,F).get(s);for(let a of r)if(i(this,I).has(a)){let o=i(this,I).get(a);o.splice(o.indexOf(s),1),o.length===0?(i(this,D).delete(a),i(this,I).delete(a)):i(this,D).get(a)===s&&i(this,D).set(a,o.at(-1))}r.clear(),i(this,F).delete(s)}return t}attachEffect(t){if(i(this,E))throw new Error("Cannot attach an effect to a destroyed group");return i(this,ue).add(t),t}runEffects(){if(i(this,E))throw new Error("Cannot run effects on a destroyed group");for(let t of i(this,ue))t.run();for(let t of i(this,x))t.runEffects()}attachLink(t){if(i(this,E))throw new Error("Cannot attach a link to a destroyed group");if(t!=null&&t.isDestroyed)throw new Error("Cannot attach a destroyed link to a group");return t&&i(this,ee).add(t),t}detachLink(t){return i(this,E)||t&&i(this,ee).delete(t),t}destroy(){var t;if(!i(this,E)){m(this,ze,this),T(this);for(let s of i(this,x))s.destroy();for(let s of i(this,ue))s.destroy();for(let s of i(this,_))le(s);for(let s of i(this,ee))s.destroy();i(this,x).clear(),i(this,_).clear(),i(this,D).clear(),i(this,I).clear(),i(this,ue).clear(),i(this,ee).clear(),(t=i(this,U))==null||t.detachGroup(this),H.delete(this),u(this,E,!0),u(this,x,void 0),u(this,_,void 0),u(this,F,void 0),u(this,D,void 0),u(this,I,void 0),u(this,F,void 0),u(this,ee,void 0),Object.freeze(this)}}},x=new WeakMap,_=new WeakMap,D=new WeakMap,F=new WeakMap,I=new WeakMap,ue=new WeakMap,ee=new WeakMap,E=new WeakMap,U=new WeakMap,ie),Ht,rr=(Ht=me,class{constructor(e){c(this,Ht);c(this,"run",()=>{var e;return(e=this[me])==null?void 0:e.run()});c(this,"destroy",()=>{var e;(e=this[me])==null||e.destroy(),this[me]=void 0});this[me]=e,L(e,ms.Destroy,()=>{this[me]=void 0})}}),Ge,$e,_t,ps=(_t=class{constructor(e="id",t=1){g(this,Ge);g(this,$e);u(this,Ge,e),u(this,$e,t)}make(){return Symbol(`${i(this,Ge)}${Dt(this,$e)._++}`)}},Ge=new WeakMap,$e=new WeakMap,_t),mt=[],vs=()=>mt.at(-1),ir=(e,t)=>{mt.push(e);try{return t()}finally{mt.pop()}},ar=e=>e!=null&&typeof e.then=="function",A,te,se,ce,fe,Ce,ms=(A=class{constructor(t,s){c(this,"id");c(this,"callback");g(this,te);g(this,se,new Set);g(this,ce,new Set);c(this,"parentEffect");c(this,"childEffects",[]);c(this,"curChildEffectSlot",0);c(this,"autorun",!0);c(this,"shouldRun",!0);g(this,fe);g(this,Ce,!1);c(this,"run",()=>{if(i(this,Ce)||!this.shouldRun)return;let t=er();t?t.batch(this.id):(this.runCleanupCallback(),this.curChildEffectSlot=0,this.shouldRun=!1,this.hasStaticDeps()?u(this,te,this.callback()):u(this,te,ir(this,this.callback)))});c(this,"destroy",()=>{i(this,Ce)||(m(this,A.Destroy,this),T(this),m(we,sr,this),this.runCleanupCallback(),T(Ne,this),T(we,this),T(Fe,this),u(this,Ce,!0),i(this,se).clear(),i(this,ce).clear(),this.childEffects.forEach(t=>{t.destroy()}),this.childEffects.length=0,--A.count)});var a;ae(this),this.callback=t;let r;(s==null?void 0:s.attach)!=null&&(r=tt.findOrCreate(s.attach),r.attachEffect(this)),this.autorun=(a=s==null?void 0:s.autorun)!=null?a:!0,u(this,fe,s!=null&&s.dependencies?s.dependencies.map(o=>{switch(typeof o){case"string":case"symbol":return r.signal(o);default:return o}}):void 0),this.id=A.idGen.make(),Z(we,this.id,"recall",this),++A.count}hasStaticDeps(){return i(this,fe)!=null&&i(this,fe).length>0}saveSignalsFromDeps(){for(let t of i(this,fe))this.whenSignalIsRead(k(t).id)}static createEffect(t,s,r){let a=Array.isArray(s)?s:void 0,o=a?r!=null?r:{dependencies:a}:s;o&&a&&(o.dependencies=a);let n,h=vs();return h!=null?(n=h.getCurrentChildEffect(),n==null&&(n=new A(t,o),h.attachChildEffect(n),m(we,Gt,n)),h.curChildEffectSlot++):(n=new A(t,o),m(we,Gt,n)),n.hasStaticDeps()?n.saveSignalsFromDeps():n.autorun&&n.run(),new rr(n)}getCurrentChildEffect(){return this.childEffects[this.curChildEffectSlot]}attachChildEffect(t){this.childEffects.push(t),this.parentEffect=this}recall(){this.shouldRun=!0,this.autorun&&this.run()}whenSignalIsRead(t){i(this,se).has(t)||(i(this,se).add(t),Z(Ne,t,"recall",this),L(Fe,t,Bt,this))}[Bt](t){!i(this,ce).has(t)&&i(this,se).has(t)&&(i(this,ce).add(t),T(Ne,t,this),i(this,ce).size===i(this,se).size&&this.destroy())}runCleanupCallback(){if(i(this,te)!=null){let t=i(this,te);u(this,te,void 0),ar(t)?Promise.resolve(t).then(s=>{typeof s=="function"&&s()}):t()}}},te=new WeakMap,se=new WeakMap,ce=new WeakMap,fe=new WeakMap,Ce=new WeakMap,c(A,"idGen",new ps("ef")),c(A,"Destroy","destroy"),c(A,"count",0),A),st=(...e)=>ms.createEffect(...e),Ie=new WeakMap,nr=e=>{let t=Ie.get(e);return t||(t={},Ie.set(e,t)),t},Ue=(e,t)=>{var s,r;return(r=(s=Ie.get(e))==null?void 0:s.signals)==null?void 0:r.get(t)},or=(e,t,s)=>{var a;let r=nr(e);(a=r.signals)!=null||(r.signals=new Map),r.signals.set(t,s)};function hr(...e){for(let t of e)if(Ie.has(t)){let s=Ie.get(t);if(s.signals){for(let r of s.signals.values())le(r);s.signals.clear(),s.signals=void 0}}}function lr(e){let t=k(Pt(e)?e:Ue(...e));t!=null&&!t.muted&&!t.destroyed&&bt(t.id,t.value,{touch:!0})}function Ot(e){var t,s;return Pt(e)?(t=k(e))==null?void 0:t.value:(s=k(Ue(...e)))==null?void 0:s.value}var es,dr=(es=W,class{constructor(e){c(this,es);this[W]=e}get get(){return this[W].reader}get set(){return this[W].writer}get value(){return Ot(this.get)}set value(e){this.set(e)}onChange(e){let{destroy:t}=st(()=>e(this.value),[this.get]);return t}get muted(){return this[W].muted}set muted(e){this[W].muted=e}touch(){lr(this)}destroy(){le(this)}}),ur=new ps("si");function qt(e){var t;ys()||((t=vs())==null||t.whenSignalIsRead(e))}function bt(e,t,s){ys()||m(Ne,e,t,s)}var Pt=e=>e!=null&&e[W]!=null,cr=e=>{let t=s=>{var r;return s?st(()=>(e.destroyed||qt(e.id),s(e.value)),[t]):e.destroyed||((r=e.beforeRead)==null||r.call(e),qt(e.id)),e.value};return Object.defineProperty(t,W,{value:e}),t},ge,B,bs=(ge=class{constructor(t,s){c(this,"id");c(this,"lazy");c(this,"compare");c(this,"beforeRead");c(this,"muted",!1);c(this,"destroyed",!1);g(this,B);c(this,"valueFn");c(this,"reader");c(this,"writer",(t,s)=>{var o,n,h,l;let r=(o=s==null?void 0:s.lazy)!=null?o:!1,a=(h=(n=s==null?void 0:s.compare)!=null?n:this.compare)!=null?h:(d,p)=>d===p;if((r!==this.lazy||r&&t!==this.valueFn||!r&&!a(t,i(this,B)))&&(r?(u(this,B,void 0),this.valueFn=t,this.lazy=!0):(u(this,B,t),this.valueFn=void 0,this.lazy=!1),!this.muted&&!this.destroyed)){bt(this.id,i(this,B));return}(l=s==null?void 0:s.touch)!=null&&l&&bt(this.id,i(this,B),{touch:!0})});c(this,"object");this.id=ur.make(),++ge.instanceCount,this.lazy=t,this.lazy?(this.value=void 0,this.valueFn=s):(this.value=s,this.valueFn=void 0),this.reader=cr(this),this.object=new dr(this)}get[W](){return this}get value(){return this.lazy&&(u(this,B,this.valueFn()),this.valueFn=void 0,this.lazy=!1),i(this,B)}set value(t){u(this,B,t)}},B=new WeakMap,c(ge,"instanceCount",0),ge),k=e=>e==null?void 0:e[W];function q(e=void 0,t){var r;let s;if(Pt(e))s=k(e);else{let a=(r=t==null?void 0:t.lazy)!=null?r:!1;s=new bs(a,e),s.beforeRead=t==null?void 0:t.beforeRead,s.compare=t==null?void 0:t.compare}return(t==null?void 0:t.attach)!=null&&tt.findOrCreate(t.attach).attachSignal(s),s.object}var le=(...e)=>{for(let t of e){let s=k(t);s!=null&&!s.destroyed&&(s.destroyed=!0,s.beforeRead=void 0,--bs.instanceCount,m(Fe,s.id,s.id))}},S,Se,ts,ws=(ts=class{constructor(e){g(this,S,!1);g(this,Se);c(this,"source");c(this,"lastValue");c(this,"isDestroyed",!1);ae(this),this.source=k(e),u(this,Se,Z(Ne,this.source.id,(t,s)=>{!i(this,S)&&!this.isDestroyed&&((s==null?void 0:s.touch)===!0?this.touch():this.write())})),L(Fe,this.source.id,()=>this.destroy())}attach(e){let t=tt.findOrCreate(e);return t.attachLink(this),L(this,ze,()=>{t.detachLink(this)}),t}nextValue(){return new Promise((e,t)=>{let s=[],r=()=>s.forEach(a=>{a()});s.push(L(this,Le,a=>{r(),e(a)}),L(this,ze,()=>{r(),t()}))})}asyncValues(e){return Rt(this,null,function*(){let t=0;for(;!this.isDestroyed;)try{let s=yield new nt(this.nextValue());if(e&&e(s,t++))break;kt(this,Le),yield s}catch(s){break}_e(this,Le)})}destroy(){var e;this.isDestroyed||((e=i(this,Se))==null||e.call(this),u(this,Se,void 0),m(this,ze,this),_e(this,Le),T(this),this.lastValue=void 0,this.isDestroyed=!0,Object.freeze(this))}get isMuted(){return i(this,S)}mute(){return!this.isDestroyed&&!i(this,S)&&(u(this,S,!0),m(this,$t,this)),this}unmute(){return!this.isDestroyed&&i(this,S)&&(u(this,S,!1),m(this,Wt,this)),this}toggle(){return this.isDestroyed||(u(this,S,!i(this,S)),m(this,i(this,S)?$t:Wt,this)),i(this,S)}updateValue(e){if(!i(this,S)&&!this.isDestroyed){let{value:t}=this.source;e(t),m(this,Le,t),this.lastValue=t}}},S=new WeakMap,Se=new WeakMap,ts),fr=class extends ws{constructor(t,s){super(t);c(this,"target");this.target=k(s),L(Fe,this.target.id,()=>this.destroy()),this.touch()}touch(){return this.updateValue(t=>{this.target.writer(t,{touch:!0})}),this}write(){this.updateValue(t=>{this.target.writer(t)})}},gr=class extends ws{constructor(t,s){super(t);c(this,"target");this.target=s,this.touch()}touch(){return this.updateValue(t=>{this.target(t)}),this}write(){this.updateValue(t=>{this.target(t)})}},Xe=new Map;function ut(e,t,s){var d;let r=k(e),a;if(Xe.has(r)){a=Xe.get(r);let p=(d=k(t))!=null?d:t;if(a.has(p))return a.get(p)}else a=new Map,Xe.set(r,a);let o=k(t),n=o!=null?new fr(e,o):new gr(e,t),h=s==null?void 0:s.attach;h&&n.attach(h);let l=o!=null?o:t;return a.set(l,n),L(n,ze,()=>{a.delete(l),a.size===0&&Xe.delete(r)}),n}var O,Ae,yr=(Ae=class{constructor(){g(this,O,new Map)}static fromProps(t,s){let r=new Ae,a=s?s.map(o=>[o,t[o]]):Object.entries(t);for(let[o,n]of a)i(r,O).set(o,q(n));return r}keys(){return i(this,O).keys()}signals(){return i(this,O).values()}entries(){return i(this,O).entries()}clear(){for(let t of i(this,O).values())t.destroy();i(this,O).clear()}has(t){return i(this,O).has(t)}get(t){if(!i(this,O).has(t)){let s=q();return i(this,O).set(t,s),s}return i(this,O).get(t)}update(t){t.size&&et(()=>{for(let[s,r]of t.entries())this.get(s).set(r)})}updateFromProps(t,s){et(()=>{let r=s?s.map(a=>[a,t[a]]):Object.entries(t);for(let[a,o]of r)this.get(a).set(o)})}},O=new WeakMap,Ae);function pr(e,t,s,r,a,o){function n(Me){if(Me!==void 0&&typeof Me!="function")throw new TypeError("Function expected");return Me}for(var h=r.kind,l=h==="getter"?"get":h==="setter"?"set":"value",d=!t&&e?r.static?e:e.prototype:null,p=t||(d?Object.getOwnPropertyDescriptor(d,r.name):{}),f,v=!1,C=s.length-1;C>=0;C--){var Je={};for(var ve in r)Je[ve]=ve==="access"?{}:r[ve];for(var ve in r.access)Je.access[ve]=r.access[ve];Je.addInitializer=function(Me){if(v)throw new TypeError("Cannot add initializers after decoration has completed");o.push(n(Me||null))};var he=(0,s[C])(h==="accessor"?{get:p.get,set:p.set}:p[l],Je);if(h==="accessor"){if(he===void 0)continue;if(he===null||typeof he!="object")throw new TypeError("Object expected");(f=n(he.get))&&(p.get=f),(f=n(he.set))&&(p.set=f),(f=n(he.init))&&a.unshift(f)}else(f=n(he))&&(h==="field"?a.unshift(f):p[l]=f)}d&&Object.defineProperty(d,r.name,p),v=!0}function Jt(e,t,s){for(var r=arguments.length>2,a=0;a<t.length;a++)s=r?t[a].call(e,s):t[a].call(e);return r?s:void 0}function vr(e){return function(t,s){var o;let r=(e==null?void 0:e.name)||s.name,a=!!((o=e==null?void 0:e.readAsValue)!=null&&o);return{get(){let n=Ue(this,r);if(n)return a?n.value:n.get()},set(n){var h;(h=Ue(this,r))==null||h.set(n)},init(n){let h=q(n,e);return or(this,r,h),tt.findOrCreate(this).attachSignalByName(r,h),h.value}}}}var be="value",ct=(()=>{var r,a,o,n,wt,Es,d;let e,t=[],s=[];return d=class{constructor(){g(this,n);g(this,r,[]);g(this,a);g(this,o,Jt(this,t,void 0));Jt(this,s),kt(this,be),Ue(this,be).onChange(f=>m(this,be,f))}get value(){return i(this,o)}set value(f){u(this,o,f)}add(...f){for(let v of f)i(this,r).push(v);b(this,n,Es).call(this)}clear(){i(this,r).length=0,b(this,n,wt).call(this)}dispose(){this.clear(),_e(this,be),T(this),hr(this)}},r=new WeakMap,a=new WeakMap,o=new WeakMap,n=new WeakSet,wt=function(){var f;(f=i(this,a))==null||f.destroy(),u(this,a,void 0)},Es=function(){b(this,n,wt).call(this),u(this,a,st(()=>{for(let f of i(this,r)){let v=Ot(f);if(v!=null){this.value=v;return}}this.value=void 0},i(this,r))),i(this,a).run()},(()=>{let f=typeof Symbol=="function"&&Symbol.metadata?Object.create(null):void 0;e=[vr({name:be})],pr(d,null,e,{kind:"accessor",name:"value",static:!1,private:!1,access:{has:v=>"value"in v,get:v=>v.value,set:(v,C)=>{v.value=C}},metadata:f},t,s),f&&Object.defineProperty(d,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:f})})(),d.Value=be,d})(),Kt="onCreate",Ee="onDestroy",mr="onViewEvent",re,ke,ye,Y,R,P,Q,N,Oe,V,Et,Ze,Ct,ss,br=(ss=class{constructor(e,t){g(this,V);g(this,re);g(this,ke);g(this,ye,new yr);g(this,Y,new Map);g(this,R);g(this,P);g(this,Q,new Set);g(this,N,[]);g(this,Oe,0);u(this,re,e),u(this,ke,t),L(this,Ee,us.Min,this)}get kernel(){return i(this,re)}get uuid(){return i(this,ke)}get order(){return i(this,Oe)}set order(e){i(this,Oe)!==e&&(u(this,Oe,e),i(this,R)&&this.parent.resortChildren())}get parentUuid(){return i(this,R)||void 0}set parentUuid(e){i(this,R)!==e&&(this.removeFromParent(),u(this,R,e||void 0),u(this,P,e?i(this,re).getEntity(e):void 0),i(this,P)&&i(this,P).addChild(this))}get parent(){return!i(this,P)&&i(this,R)&&u(this,P,i(this,re).getEntity(i(this,R))),i(this,P)}set parent(e){this.parentUuid=e==null?void 0:e.uuid}get hasParent(){return!!i(this,R)}get children(){return i(this,N)}traverse(e){e(this);for(let t of i(this,N))t.traverse(e)}onDestroy(){var e;i(this,ye).clear(),T(this);for(let t of i(this,Y).values())t.unsubscribeFromPath(),(e=t.unsubscribeFromParent)==null||e.call(t),t.ctxPath.dispose(),t.inherited.destroy(),t.provide.destroy(),t.context.destroy();u(this,R,void 0),u(this,P,void 0),i(this,Q).clear(),i(this,N).length=0}addChild(e){var t;if(i(this,N).length===0){i(this,Q).add(e.uuid),i(this,N).push(e);return}if(i(this,Q).has(e.uuid))throw new Error(`child with uuid: ${e.uuid} already exists! parentUuid: ${this.uuid}`);i(this,Q).add(e.uuid),i(this,N).push(e),this.resortChildren();for(let[,s]of i(e,Y))b(t=e,V,Ct).call(t,s)}resortChildren(){i(this,N).sort((e,t)=>e.order-t.order)}removeChild(e){i(this,Q).has(e.uuid)&&(i(this,Q).delete(e.uuid),i(this,N).splice(i(this,N).indexOf(e),1))}removeFromParent(){if(i(this,P)){i(this,P).removeChild(this),u(this,P,void 0),u(this,R,void 0);for(let[,e]of i(this,Y))e.unsubscribeFromParent&&(e.unsubscribeFromParent(),e.unsubscribeFromParent=void 0)}}dispatchMessageToView(e,t,s,r=!1){i(this,re).dispatchMessageToView({uuid:i(this,ke),type:e,data:t,transferables:s,traverseChildren:r})}dispatchViewEvents(e){for(let{type:t,data:s}of e)m(this,mr,t,s)}dispatchViewEvent(e,t){this.dispatchViewEvents([{type:e,data:t}])}getPropertyReader(e){return b(this,V,Et).call(this,e).get}getPropertyWriter(e){return b(this,V,Et).call(this,e).set}setProperties(e){et(()=>{for(let[t,s]of e)this.setProperty(t,s)})}setProperty(e,t){this.getPropertyWriter(e)(t)}getProperty(e){return Ot(this.getPropertyReader(e))}propKeys(){return Array.from(i(this,ye).keys())}propEntries(){return Array.from(i(this,ye).entries()).map(([e,t])=>[e,t.value])}hasContext(e){return i(this,Y).has(e)}useContext(e){return b(this,V,Ze).call(this,e).context.get}provideContext(e){return b(this,V,Ze).call(this,e).provide}},re=new WeakMap,ke=new WeakMap,ye=new WeakMap,Y=new WeakMap,R=new WeakMap,P=new WeakMap,Q=new WeakMap,N=new WeakMap,Oe=new WeakMap,V=new WeakSet,Et=function(e){return i(this,ye).get(e)},Ze=function(e){let t=i(this,Y).get(e);if(t==null){let s=q(),r=q(),a=q(),o=new ct;o.add(r.get,s.get);let n=Z(o,ct.Value,h=>{queueMicrotask(()=>{a.set(h)})});t={name:e,inherited:s,provide:r,context:a,ctxPath:o,unsubscribeFromPath:n},i(this,Y).set(e,t),b(this,V,Ct).call(this,t)}return t},Ct=function(e){var t,s;this.parent&&((t=e.unsubscribeFromParent)==null||t.call(e),e.unsubscribeFromParent=Z(b(s=this.parent,V,Ze).call(s,e.name).ctxPath,ct.Value,r=>{e.inherited.set(r)}))},ss);function wr(e,t){e.indexOf(t)===-1&&e.push(t)}var X,j,rs,Cs=(rs=class{constructor(){g(this,X,new Map);g(this,j,new Map)}static get(e){return e!=null?e:Er}define(e,t){i(this,X).has(e)?wr(i(this,X).get(e).constructors,t):i(this,X).set(e,{token:e,constructors:[t]})}appendRoute(e,t){if(i(this,j).has(e)){let s=i(this,j).get(e);for(let r of t)s.add(r)}else i(this,j).set(e,new Set(t))}clearRoute(e){i(this,j).delete(e)}findTokensByRoute(e){let t=new Set([e]),s=i(this,j).has(e)?[...i(this,j).get(e)]:[];for(;s.length;){let r=s.shift();t.has(r)||(t.add(r),i(this,j).has(r)&&s.push(...Array.from(i(this,j).get(r)).filter(a=>!t.has(a))))}return Array.from(t)}findConstructors(e){let t=this.findTokensByRoute(e),s=new Set;for(let r of t){let a=i(this,X).get(r);if(a)for(let o of a.constructors)s.add(o)}return s.size>0?Array.from(s):void 0}hasToken(e){return i(this,X).has(e)}hasRoute(e){return i(this,j).has(e)}clear(){i(this,X).clear(),i(this,j).clear()}},X=new WeakMap,j=new WeakMap,rs),Er=new Cs,K;(function(e){e[e.CreateAndDestroy=0]="CreateAndDestroy",e[e.JustCreate=1]="JustCreate",e[e.DestroyOnly=2]="DestroyOnly"})(K||(K={}));var Yt=e=>e.displayName||e.name,w,G,Pe,We,$,is,Cr=(is=class{constructor(e){g(this,w);g(this,G);g(this,Pe);g(this,We);g(this,$);this.logger=new zs("Kernel"),u(this,w,new Map),u(this,G,new Set),u(this,$,!0),ae(this),this.registry=Cs.get(e)}getEntity(e){var s;let t=(s=i(this,w).get(e))==null?void 0:s.entity;if(!t)throw new Error(`entity with uuid "${e}" not found!`);return t}hasEntity(e){return i(this,w).has(e)}traverseLevelOrderBFS(e=!1){if(i(this,$)){let t=new Map,s=(r,a)=>{let o=this.getEntity(r);t.has(a)?t.get(a).push(o):t.set(a,[o]);for(let n of o.children)s(n.uuid,a+1)};i(this,G).forEach(r=>s(r,0)),u(this,Pe,Array.from(t.entries()).sort((r,a)=>r[0]-a[0]).map(([,r])=>r).flat()),u(this,We,i(this,Pe).slice().reverse()),u(this,$,!1)}return e?i(this,We):i(this,Pe)}getEntityGraph(){return Array.from(i(this,G)).map(e=>this.getEntityGraphNode(e))}getEntityGraphNode(e){if(!i(this,w).has(e))return;let{token:t,entity:s}=i(this,w).get(e);return{token:t,entity:s,props:Object.fromEntries(s.propEntries()),children:s.children.map(r=>this.getEntityGraphNode(r.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){et(()=>{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),u(this,$,!0);break;case J.DestroyEntities:this.destroyEntity(e.uuid),u(this,$,!0);break;case J.SetParent:this.setParent(e.uuid,e.parentUuid,e.order),u(this,$,!0);break;case J.UpdateOrder:this.updateOrder(e.uuid,e.order),u(this,$,!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,s,r=0,a){let o=new br(this,e);o.order=r;let n={token:t,entity:o,usedConstructors:new Map};i(this,w).set(e,n),s&&(o.parentUuid=s),o.hasParent||i(this,G).add(e),a&&o.setProperties(a),this.createShadowObjects(e)}destroyEntity(e){if(!i(this,w).has(e))return;let{entity:t,usedConstructors:s}=i(this,w).get(e);t.removeFromParent(),m(t,Ee,this),s.clear(),i(this,w).delete(t.uuid),i(this,G).delete(t.uuid)}setParent(e,t,s=0){let r=this.getEntity(e);r.parentUuid===t&&r.order===s||(r.removeFromParent(),r.order=s,r.parentUuid=t,r.hasParent?i(this,G).delete(e):i(this,G).add(e))}updateOrder(e,t){this.getEntity(e).order=t}dispatchEventsToEntity(e,t){var s;(s=this.getEntity(e))==null||s.dispatchViewEvents(t)}changeProperties(e,t){this.getEntity(e).setProperties(t)}changeToken(e,t){if(!i(this,w).has(e))return;let s=i(this,w).get(e);s.token!==t&&(s.token=t,this.updateShadowObjects(e))}dispatchMessageToView(e){queueMicrotask(()=>{m(this,gt,e)})}updateShadowObjects(e,t=K.CreateAndDestroy){let s=i(this,w).get(e),r=new Set(this.registry.findConstructors(s.token)),a=t===K.CreateAndDestroy||t===K.DestroyOnly,o=t===K.CreateAndDestroy||t===K.JustCreate;if(a){for(let[n,h]of s.usedConstructors)if(!r.has(n)){s.usedConstructors.delete(n);for(let l of h)this.destroyShadowObject(l,s.entity)}}if(o)for(let n of r)s.usedConstructors.has(n)||this.constructShadowObject(n,s)}constructShadowObject(e,t){let s=new Set,r=new Set,a=new Map,o=new Map,n=new Map,h=ae(new e({entity:t.entity,provideContext(l,d,p){let f=o.get(l);if(f===void 0){f=q(d,p?{compare:p}:void 0),o.set(l,f);let v=ut(f,t.entity.provideContext(l));r.add(v.destroy.bind(v))}return f},useContext(l,d){let p=a.get(l);if(p===void 0){p=q(void 0,d?{compare:d}:void 0).get,a.set(l,p);let f=ut(t.entity.useContext(l),p);r.add(f.destroy.bind(f))}return p},useProperty(l,d){let p=n.get(l);if(p===void 0){p=q(void 0,d?{compare:d}:void 0).get,n.set(l,p);let f=ut(t.entity.getPropertyReader(l),p);r.add(f.destroy.bind(f))}return p},createEffect(...l){let d=st(...l);return r.add(d.destroy),d},createSignal(...l){let d=q(...l);return r.add(()=>{le(d)}),d},on(...l){let d=Z(...l);return r.add(d),d},once(...l){let d=L(...l);return r.add(d),d},onDestroy(l){s.add(l)}}));return this.logger.isInfo&&this.logger.info("create shadow-object",Yt(e),{shadowObject:h,entity:t.entity}),L(h,Ee,()=>{this.logger.isInfo&&this.logger.info("destroy shadow-object",Yt(e),{shadowObject:h,entity:t.entity});for(let d of s)d();for(let d of r)d();for(let d of a.values())le(d);for(let d of n.values())le(d);for(let d of o.values())le(d);s.clear(),r.clear(),a.clear(),n.clear(),o.clear();let l=t.usedConstructors.get(e);l&&(l.delete(h),l.size===0&&t.usedConstructors.delete(e))}),t.usedConstructors.has(e)?t.usedConstructors.get(e).add(h):t.usedConstructors.set(e,new Set([h])),this.attachShadowObject(h,t.entity),h}createShadowObjects(e){var s;let t=i(this,w).get(e);(s=this.registry.findConstructors(t.token))==null||s.forEach(r=>{this.constructShadowObject(r,t)})}findShadowObjects(e){if(!i(this,w).has(e))return[];let{usedConstructors:t}=i(this,w).get(e);return Array.from(new Set(Array.from(t.values()).map(s=>Array.from(s)).flat()))}attachShadowObject(e,t){Z(t,e),typeof e[Kt]=="function"&&e[Kt](t)}destroyShadowObject(e,t){typeof e[Ee]=="function"&&e[Ee](t),m(e,Ee,t),T(t,e)}destroy(){for(let e of this.traverseLevelOrderBFS().reverse())this.destroyEntity(e.uuid)}},w=new WeakMap,G=new WeakMap,Pe=new WeakMap,We=new WeakMap,$=new WeakMap,is);async function Ss(e,t,s,r=!0){var o,n;if(s.has(t)){console.warn("importModule: skipping already imported module",t);return}else s.add(t);t.extends&&await Promise.all(t.extends.map(h=>Ss(e,h,s,!1)));let{registry:a}=e;if(t.define)for(let[h,l]of Object.entries(t.define))a.define(h,l);if(t.routes)for(let[h,l]of Object.entries(t.routes))a.appendRoute(h,l);await((n=(o=t.initialize)==null?void 0:o.call(t,{define:(h,l)=>a.define(h,l),kernel:e,registry:a}))!=null?n:Promise.resolve()),r&&e.upgradeEntities()}var Sr=e=>(typeof e=="string"&&(e=new URL(e,globalThis.location.href)),e.toString()),qe,ne,As,ks,Os,as,Ar=(as=class{constructor(e){g(this,ne);g(this,qe,new Set);var t,s;this.kernel=(t=e==null?void 0:e.kernel)!=null?t:new Cr,this.postMessage=(s=e==null?void 0:e.postMessage)!=null?s:self.postMessage.bind(self),Z(this.kernel,gt,"onMessageToView",this)}route(e){var t;switch(e.data.type){case Ms:b(this,ne,As).call(this,e.data);break;case Ts:b(this,ne,ks).call(this,e.data);break;case Ls:b(this,ne,Os).call(this,e.data);break;default:console.warn("[MessageRouter] unknown message",(t=e.data.type)!=null?t:e.data)}}onMessageToView(e){let r=e,{transferables:t}=r,s=Lt(r,["transferables"]);this.postMessage({type:gt,data:s},{transfer:t})}},qe=new WeakMap,ne=new WeakSet,As=async function(e){try{let t=await import(Sr(e.importModule));t[ht]?(await Ss(this.kernel,t[ht],i(this,qe)),this.postMessage({type:ot,url:e.importModule})):this.postMessage({type:ot,url:e.importModule,error:`module has no "${ht}" export`})}catch(t){console.error("[MessageRouter] failed to import module",t),this.postMessage({type:ot,url:e.importModule,error:`${t}`})}},ks=function(e){try{this.kernel.run(e)}catch(t){console.error("[MessageRouter] failed to apply change trail",t),this.postMessage({type:zt,serial:e.serial,error:t.toString()})}e.serial&&this.postMessage({type:zt,serial:e.serial})},Os=function(e){console.debug("[MessageRouter] on destroy",e),T(this.kernel,this),i(this,qe).clear(),this.postMessage({type:Rs})},as),kr=class{constructor(){this.onmessage=e=>{var t;e.data.type===z?globalThis[M]=e.data.config:((t=this.router)!=null||(this.router=new Ar),this.router.route(e))}}start(){self.addEventListener("message",this.onmessage),self.postMessage({type:Ds})}};console.debug("@spearwolf/shadow-objects/WorkerRuntime: hello!");var Or=new kr;Or.start();\n/*! Bundled license information:\n\n@spearwolf/eventize/lib/index.mjs:\n (*!\n =============================================================================\n @spearwolf/eventize 4.0.1+build.20240804\n \u2014 https://github.com/spearwolf/eventize.git\n =============================================================================\n \n Copyright 2015-2024 Wolfger Schramm\n \n Licensed under the Apache License, Version 2.0 (the "License");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n \n http://www.apache.org/licenses/LICENSE-2.0\n \n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an "AS IS" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n *)\n*/\n')}var Ps=()=>new Ft;var Le=(s,e,t=1e3,r)=>new Promise((i,n)=>{let o,l,a=()=>{clearTimeout(o),s.removeEventListener("message",l)};t!==0&&t!==1/0&&(o=setTimeout(()=>{a(),n(new Error(`Timeout waiting for message of type: ${e}`))},t)),l=h=>{if(h.data.type===e)try{(!r||r(h.data))&&(a(),i())}catch(u){a(),n(u.toString())}},s.addEventListener("message",l)});var rr=s=>{let e;if(s!=null&&Array.isArray(s))for(let t of s)t.transferables&&(e?e=[...e,...t.transferables]:e=t.transferables,delete t.transferables);return e},gt=class s{static{this.WorkerLoaded="workerLoaded"}#e;#t;#s;get isDestroyed(){return this.#t}get workerLoaded(){return he(this,s.WorkerLoaded)}constructor(){this.#t=!1,this.#s=0,this.logger=new x("RemoteWorkerEnv"),D(this,s.WorkerLoaded)}async start(){if(this.#e)return this.logger.isWarn&&this.logger.warn("already started"),this.workerLoaded.then(()=>{if(this.isDestroyed)throw"worker was destroyed"});let e=this.#e=Ps();this.configureConsoleLogger(e);try{if(await Le(e,hs,fs),this.isDestroyed)throw"worker was destroyed";e.addEventListener("message",this.onMessageFromWorker.bind(this)),queueMicrotask(()=>{c(this,s.WorkerLoaded,this)})}catch(t){throw this.logger.error("failed to start",t),this.#e=void 0,t}}applyChangeTrail(e,t){let r=rr(e),i={type:os,changeTrail:e},n=++this.#s;return t&&(i.serial=n),this.#e.postMessage(i,r),t?Le(this.#e,ls,ps,o=>{if(o.error)throw o.error;return o.serial===n}):Promise.resolve()}importScript(e){return e=dt(e),this.#e.postMessage({type:ns,importModule:e}),Le(this.#e,us,ds,t=>{if(t.error)throw t.error;return t.url===e})}destroy(){if(!this.#e)return;let e=this.#e;this.#e=void 0,this.#t=!0,e.postMessage({type:as}),Le(e,cs,gs).finally(()=>{e.terminate()})}onMessageFromWorker(e){e.data?.type===pe?this.onMessageToView?.(e.data.data):this.logger.isDebug&&this.logger.debug("message from worker",e)}configureConsoleLogger(e){let t=`${P}.RemoteWorkerEnv.workerConfig`,r=JSON.parse(localStorage.getItem(t)??"{}");this.logger.isInfo&&this.logger.info("load console-logger worker config",{localStorageKey:t,workerConfig:r}),e.postMessage({type:P,config:{...x.sharedConfig,enable:this.logger.isEnabled,...r,...x.isEnabled?{}:{enable:!1}}})}};var Me,_e=class extends K{static{this.observedAttributes=[...K.observedAttributes,et,st,tt]}static{this.DefaultAutoSync="frame"}#e;#t;#s;#i;#r;constructor(){super(),this.isShaeWorkerElement=!0,this.shadowEnv=new _,this.logger=new x("ShaeWorkerElement"),this.autostart=!0,this.isConnected$=f(!1),this.autoSync$=f(Me.DefaultAutoSync),this.src$=f(""),this.#e=!1,this.#t=!1,this.ns$.onChange(e=>{this.shadowEnv.view=R.get(e)}),g(this.shadowEnv,_.ContextCreated,()=>{this.#r?.run(),this.dispatchEvent(new CustomEvent(_.ContextCreated.toLowerCase(),{bubbles:!1,detail:{shadowEnv:this.shadowEnv}}))}),g(this.shadowEnv,_.ContextLost,()=>{this.dispatchEvent(new CustomEvent(_.ContextLost.toLowerCase(),{bubbles:!1,detail:{shadowEnv:this.shadowEnv}}))}),this.autoSync$.onChange(e=>{let t=this.hasAttribute(j),r=t?this.getAttribute(j):void 0;e===Me.DefaultAutoSync?t&&r!==e&&this.setAttribute(j,e):r!==e&&this.setAttribute(j,e)}),this.#n(),this.#o()}#o(){this.#r=b(()=>{let e=this.src$.get();e&&this.importScript(e)},{autorun:!1})}get shouldAutostart(){return this.autostart&&!Pe(this,Ss)}get autoSync(){return this.autoSync$.value}set autoSync(e){typeof e!="string"&&(e=e?Me.DefaultAutoSync:"no"),this.autoSync$.set(`${e}`.trim().toLowerCase())}get frameLoop(){return this.#s??=new ge,this.#s}[ge.OnFrame](){this.syncShadowObjects()}async importScript(e){if(!e)throw new Error("src is blank");let t=await this.shadowEnv.ready();return this.logger.isInfo&&this.logger.info("shadowEnv importScript:",e,{shadowEnv:t}),await t.envProxy.importScript(e),this}connectedCallback(){k(()=>{this.hasAttribute(j)&&this.autoSync$.set(this.getAttribute(j)),this.isConnected$.set(!0)}),this.shouldAutostart&&this.start()}disconnectedCallback(){this.isConnected$.set(!1),this.#a()}attributeChangedCallback(e){if(super.attributeChangedCallback(e),e===et&&this.shadowEnv.envProxy!=null)throw new Error('Changing the "local" attribute after the shadowEnv has been created is not supported.');if(e===tt&&this.#h(),e===j&&(this.autoSync=this.hasAttribute(j)?this.getAttribute(j):!0),e===st){let t=(this.getAttribute(st)||"").trim();this.src$.set(t),this.shadowEnv.isReady&&this.#r?.run()}}start(){if(!this.#t){if(this.#e=!1,this.shadowEnv.view??=R.get(this.ns),this.shadowEnv.envProxy==null){let e=Pe(this,et)?new pt:new gt;this.shadowEnv.envProxy=e,this.#h()}this.#t=!0}return this.shadowEnv.ready()}destroy(){this.#i?.destroy(),this.#r?.destroy(),S(this.isConnected$,this.autoSync$,this.src$),this.shadowEnv.envProxy=void 0,this.shadowEnv.destroy()}#a(){this.#e||(this.#e=!0,queueMicrotask(()=>{this.#e&&this.destroy()}))}#n(){this.#i=b(()=>{if(this.isConnected$.get()){let e=(this.autoSync$.get()||Me.DefaultAutoSync).trim().toLowerCase(),t;if(["true","yes","on","frame","auto-sync"].includes(e))return this.logger.isDebug&&this.logger.debug("auto-sync",e,this),this.frameLoop.start(this),()=>{this.frameLoop.stop(this)};if(e.toLowerCase().endsWith("fps")){let r=parseInt(e,10);r>0?t=Math.floor(1e3/r):this.logger.isWarn&&this.logger.warn(`invalid auto-sync value: ${e}`)}else t=parseInt(e,10),isNaN(t)&&(t=void 0,["false","no","off"].includes(e)||this.logger.error(`invalid auto-sync value: ${e}`));if(t!==void 0&&t>0){this.logger.isDebug&&this.logger.debug("auto-sync interval (ms)",t,this);let r=setInterval(()=>{this.syncShadowObjects()},t);return()=>{clearInterval(r)}}else this.logger.isDebug&&this.logger.debug("auto-sync off",this)}},[this.autoSync$,this.isConnected$])}#h(){let e=this.shadowEnv.envProxy;e?.isLocalEnv&&(e.disableStructuredClone=this.hasAttribute(tt))}};Me=_e;customElements.define(Es,_e);globalThis.SHADOW_ENTS_BUNDLE_LOADED=!0;
|
|
21
|
+
var X="*",qt=1,wt=2,Et=4,j=Symbol.for("eventize"),Ls="[eventize]",Ie=s=>s===X,Gt=s=>{switch(typeof s){case"string":case"symbol":return!0;default:return!1}},Ht=typeof console<"u",_s=Ht?console[console.warn?"warn":"log"].bind(console,Ls):()=>{},Ns=(s,e,t)=>(Object.defineProperty(s,e,{value:t,configurable:!0}),s),js=0,Qt=class{static publish(s){s.sort((e,t)=>e.order-t.order).forEach(e=>e.emit())}events=new Map;eventNames=new Set;add(s){Array.isArray(s)?s.forEach(e=>this.eventNames.add(e)):this.eventNames.add(s)}remove(s){Array.isArray(s)?s.forEach(e=>this.eventNames.delete(e)):this.eventNames.delete(s),this.clear(s)}clear(s){Array.isArray(s)?s.forEach(e=>this.events.delete(e)):this.events.delete(s)}retain(s,e){this.eventNames.has(s)&&this.events.set(s,{args:e,order:js++})}isKnown(s){return this.eventNames.has(s)}emit(s,e,t=[]){if(Ie(s))this.eventNames.forEach(r=>this.emit(r,e,t));else if(this.events.has(s)){let{order:r,args:i}=this.events.get(s);t.push({order:r,emit:()=>e.apply(s,i)})}return t}},bt=(s,e,t,r)=>{if(typeof e=="function"){let i=e.apply(s,t);i!=null&&r?.(i)}},Ds=(s,e,t,r)=>bt(e,e.emit,[s].concat(t),r),Is=s=>{switch(typeof s){case"function":return qt;case"string":case"symbol":return wt;case"object":return Et}},$s=0,Ws=()=>++$s,Yt=class{id;eventName;isCatchEmAll;priority;listener;listenerObject;listenerType;callAfterApply;isRemoved;refCount;constructor(s,e,t,r=null){this.id=Ws(),this.eventName=s,this.isCatchEmAll=Ie(s),this.listener=t,this.listenerObject=r,this.priority=e,this.listenerType=Is(t),this.callAfterApply=void 0,this.isRemoved=!1,this.refCount=1}isEqual(s,e=null){if(s===this)return!0;let t=typeof s;return t==="number"&&s===this.id?!0:e===null&&(t==="string"||t==="symbol")?s===X||s===this.eventName:this.listener===s&&this.listenerObject===e}apply(s,e,t){if(this.isRemoved)return;let{listener:r,listenerObject:i}=this;switch(this.listenerType){case qt:bt(i,r,e,t),this.callAfterApply&&this.callAfterApply();break;case wt:bt(i,i[r],e,t),this.callAfterApply&&this.callAfterApply();break;case Et:{let n=r[s];if(this.isCatchEmAll||this.eventName===s){if(typeof n=="function"){let o=n.apply(r,e);o!=null&&t?.(o)}else Ds(s,r,e,t);this.callAfterApply&&this.callAfterApply()}break}}}},Fs=(s,e)=>s.priority!==e.priority?e.priority-s.priority:s.id-e.id,Ut=s=>s?.slice(0),Vt=(s,e)=>{let t=s.indexOf(e);t>-1&&s.splice(t,1)},zs=s=>s===Et||s===wt,vt=(s,e,t)=>{let r=s.findIndex(i=>i.isEqual(e,t));r>-1&&(s[r].isRemoved=!0,s.splice(r,1))},De=(s,e,t)=>{let r=[];for(let i of s)(e==null&&i.listenerObject===t||i.eventName===e&&i.listener===t)&&r.push(i);for(let i of r)vt(s,i,void 0)},mt=s=>{s&&(s.forEach(e=>{e.isRemoved=!0}),s.length=0)},Us=(s,e)=>s.listenerType===e.listenerType?s.priority===e.priority&&s.eventName===e.eventName&&s.listenerObject===e.listenerObject&&s.listener===e.listener:!1,Vs=(s,e)=>{if(zs(s.listenerType))return e.find(t=>Us(s,t))},Bs=(s,e)=>{let t=Vs(s,e);return t?(t.refCount+=1,t):(e.push(s),e.sort(Fs),s)},qs=class{namedListeners;catchEmAllListeners;getListenersForEventName=s=>{let e=this.namedListeners.get(s);return e||(e=[],this.namedListeners.set(s,e)),e};constructor(){this.namedListeners=new Map,this.catchEmAllListeners=[]}add(s){return Bs(s,s.isCatchEmAll?this.catchEmAllListeners:this.getListenersForEventName(s.eventName))}remove(s,e,t=!1){e==null&&Array.isArray(s)?s.forEach(r=>this.remove(r,null,t)):s==null||e==null&&Ie(s)?this.removeAllListeners():e==null&&Gt(s)?mt(this.namedListeners.get(s)):s instanceof Yt?s.isRemoved||(s.refCount-=1,s.refCount<1&&(s.isRemoved=!0,this.namedListeners.forEach(r=>Vt(r,s)),Vt(this.catchEmAllListeners,s))):t?Ie(s)?De(this.catchEmAllListeners,X,s):this.namedListeners.forEach(r=>De(r,s,e)):(this.namedListeners.forEach(r=>{vt(r,s,e),De(r,void 0,s)}),vt(this.catchEmAllListeners,s,e),De(this.catchEmAllListeners,void 0,s))}removeAllListeners(){this.namedListeners.forEach(s=>mt(s)),this.namedListeners.clear(),mt(this.catchEmAllListeners)}forEach(s,e){let t=Ut(this.catchEmAllListeners),r=Ut(this.namedListeners.get(s));if(s===X||!r||r.length===0)t.forEach(e);else if(t.length===0)r.forEach(e);else{let i=r.length,n=t.length,o=0,l=0;for(;o<i||l<n;){if(o<i){let a=r[o];if(l>=n||a.priority>=t[l].priority){e(a),++o;continue}}l<n&&(e(t[l]),++l)}}}getSubscriptionCount(){let s=this.catchEmAllListeners.length;for(let e of this.namedListeners.values())s+=e.length;return s}},ee=s=>!!(s&&s[j]);function be(s){if(ee(s))return s;let e=new qs,t=new Qt;return Ns(s,j,{keeper:t,store:e}),s}var ve={Max:Number.POSITIVE_INFINITY,AAA:1e9,BB:1e6,C:1e3,Default:0,Low:-1e4,Min:Number.NEGATIVE_INFINITY},Gs=(s,e,t,r,i,n,o)=>{let l=s.add(new Yt(t,r,i,n));return e.emit(t,l,o),l},Hs=(s,e,t,r)=>{let i=t.length,n=typeof t[0],o,l,a,h;if(i>=2&&i<=3&&n==="number"?(o=X,[l,a,h]=t):i>=3&&i<=4&&typeof t[1]=="number"?[o,l,a,h]=t:(l=ve.Default,n==="string"||n==="symbol"||Array.isArray(t[0])?[o,a,h]=t:(o=X,[a,h]=t)),!a&&Ht)throw _s("called with insufficient arguments!",t),"subscribeTo() called with insufficient arguments!";let u=d=>E=>Gs(s,e,E,d,a,h,r);return Array.isArray(o)?o.map(d=>Array.isArray(d)?u(d[1])(d[0]):u(l)(d)):u(l)(o)},Kt=(s,e,t)=>{let r=[],i=Hs(s,e,t,r);return Qt.publish(r),i},Bt=s=>e=>{e.callAfterApply=()=>{s?.()}},Jt=(s,e)=>Object.assign(()=>y(s,e),Array.isArray(e)?{listeners:e}:{listener:e}),Zt=(s,e,t,r)=>{let{store:i,keeper:n}=s[j];Array.isArray(e)?e.forEach(o=>{i.forEach(o,l=>l.apply(o,t,r)),n.retain(o,t)}):e!==X&&(i.forEach(e,o=>{o.apply(e,t,r)}),n.retain(e,t))},g=(s,...e)=>{let t=be(s),{store:r,keeper:i}=t[j];return Jt(t,Kt(r,i,e))},v=(s,...e)=>{let t=be(s),{store:r,keeper:i}=t[j],n=Kt(r,i,e),o=Jt(t,n),l=!1,a=()=>{l||(o(),l=!0)};return Array.isArray(n)?n.forEach(Bt(a)):Bt(a)(n),a},he=(s,e)=>new Promise(t=>{v(s,e,t)}),y=(s,e,t)=>{if(!ee(s))throw new Error("object is not eventized");let{store:r,keeper:i}=s[j],n=typeof e,o=t!=null&&(n==="string"||n==="symbol");r.remove(e,t,o),Array.isArray(e)?i.remove(e.filter(l=>typeof l=="string")):Gt(e)&&i.remove(e)},c=(s,e,...t)=>{if(!ee(s))throw new Error("object is not eventized");Zt(s,e,t)},Qs=(s,e,...t)=>{if(!ee(s))throw new Error("object is not eventized");let r=[];return Zt(s,e,t,i=>{r.push(i)}),r=r.map(i=>Array.isArray(i)?Promise.all(i):Promise.resolve(i)),r.length>0?Promise.all(r):Promise.resolve()},D=(s,e)=>{let t=be(s),{keeper:r}=t[j];r.add(e)},F=(s,e)=>{if(!ee(s))throw new Error("object is not eventized");let{keeper:t}=s[j];t.clear(e)},w=(()=>{let s=(e={})=>be(e);return s.inject=(e={})=>(e=be(e),Object.assign(e,{on:(...t)=>g(e,...t),once:(...t)=>v(e,...t),onceAsync:t=>he(e,t),off:(t,r)=>y(e,t,r),emit:(t,...r)=>c(e,t,...r),emitAsync:(t,...r)=>Qs(e,t,...r),retain:t=>D(e,t),retainClear:t=>F(e,t)}),e),s.is=ee,s})();var Ct=s=>ee(s)?s[j]?.store?.getSubscriptionCount()??0:0;var z=w(),U=w(),V=w();var te=class{static current;#e=new Set;batch(e){this.#e.add(e)}run(){c(V,Array.from(this.#e))}},Xt=()=>te.current;function k(s){let e=te.current;e?e=void 0:e=te.current=new te;try{s()}finally{e&&(te.current=void 0,e.run())}}var St=0;function xt(s){St++;try{s()}finally{St--}}function $e(){return St>0}var T=Symbol.for("signal"),se=Symbol.for("effect"),kt=Symbol.for("destroySignal"),At=Symbol.for("createEffect"),es=Symbol.for("destroyEffect"),le="value",Tt="mute",Ot="unmute",B="destroy";var q=new Map,M=class s{#e=new Set;#t=new Set;#s=new Map;#i=new WeakMap;#r=new Map;#n=new Set;#a=new Set;#o=!1;#h;static get(e){if(e!=null)return e instanceof s&&!e.#o?e:q.get(e)}static findOrCreate(e){if(e==null)throw new Error("Cannot create a group with a null object");return new s(e)}static destroy(e){q.get(e)?.destroy()}static clear(){for(let e of q.values())e.destroy();q.clear()}constructor(e){if(e!=null&&e instanceof s&&!e.#o)return e;if(e??=this,q.has(e))return q.get(e);q.set(e,this),w(this)}attachGroup(e){if(this.#o)throw new Error("Cannot attach a group to a destroyed group");if(e===this)throw new Error("Cannot attach a group to itself");return this.#e.add(e),e.#h&&e.#h!==this&&e.#h.#e.delete(e),e.#h=this,e}detachGroup(e){if(this.#o)throw new Error("Cannot detach a group from a destroyed group");return e!==this&&this.#e.has(e)&&(this.#e.delete(e),e.#h=void 0),e}attachSignal(e){if(this.#o)throw new Error("Cannot attach a signal to a destroyed group");let t=m(e);if(t?.destroyed)throw new Error("Cannot attach a destroyed signal to a group");return t&&this.#t.add(t),e}attachSignalByName(e,t){if(this.#o)throw new Error("Cannot attach a named signal to a destroyed group");if(t){this.attachSignal(t);let r=m(t);this.#s.set(e,r),this.#r.has(e)?this.#r.get(e).push(r):this.#r.set(e,[r]),this.#i.has(r)?this.#i.get(r).add(e):this.#i.set(r,new Set([e]))}else this.#s.delete(e);return t}hasSignal(e){return this.#s.has(e)||this.#h?.hasSignal(e)}signal(e){if(!this.#o)return this.#s.get(e)?.object??this.#h?.signal(e)}detachSignal(e){if(this.#o)return e;let t=m(e);if(t&&(this.#t.delete(t),this.#i.has(t))){let r=this.#i.get(t);for(let i of r)if(this.#r.has(i)){let n=this.#r.get(i);n.splice(n.indexOf(t),1),n.length===0?(this.#s.delete(i),this.#r.delete(i)):this.#s.get(i)===t&&this.#s.set(i,n.at(-1))}r.clear(),this.#i.delete(t)}return e}attachEffect(e){if(this.#o)throw new Error("Cannot attach an effect to a destroyed group");return this.#n.add(e),e}runEffects(){if(this.#o)throw new Error("Cannot run effects on a destroyed group");for(let e of this.#n)e.run();for(let e of this.#e)e.runEffects()}attachLink(e){if(this.#o)throw new Error("Cannot attach a link to a destroyed group");if(e?.isDestroyed)throw new Error("Cannot attach a destroyed link to a group");return e&&this.#a.add(e),e}detachLink(e){return this.#o||e&&this.#a.delete(e),e}destroy(){if(!this.#o){c(this,B,this),y(this);for(let e of this.#e)e.destroy();for(let e of this.#n)e.destroy();for(let e of this.#t)S(e);for(let e of this.#a)e.destroy();this.#e.clear(),this.#t.clear(),this.#s.clear(),this.#r.clear(),this.#n.clear(),this.#a.clear(),this.#h?.detachGroup(this),q.delete(this),this.#o=!0,this.#e=void 0,this.#t=void 0,this.#i=void 0,this.#s=void 0,this.#r=void 0,this.#i=void 0,this.#a=void 0,Object.freeze(this)}}};var We=class{[se];constructor(e){this[se]=e,v(e,ue.Destroy,()=>{this[se]=void 0})}run=()=>this[se]?.run();destroy=()=>{this[se]?.destroy(),this[se]=void 0}};var ce=class{#e;#t;constructor(e="id",t=1){this.#e=e,this.#t=t}make(){return Symbol(`${this.#e}${this.#t++}`)}};var Pt=[],Fe=()=>Pt.at(-1),ts=(s,e)=>{Pt.push(s);try{return e()}finally{Pt.pop()}};var Ys=s=>s!=null&&typeof s.then=="function",ue=class s{static idGen=new ce("ef");static Destroy="destroy";static count=0;id;callback;#e;#t=new Set;#s=new Set;parentEffect;childEffects=[];curChildEffectSlot=0;autorun=!0;shouldRun=!0;#i;#r=!1;constructor(e,t){w(this),this.callback=e;let r;t?.attach!=null&&(r=M.findOrCreate(t.attach),r.attachEffect(this)),this.autorun=t?.autorun??!0,this.#i=t?.dependencies?t.dependencies.map(i=>{switch(typeof i){case"string":case"symbol":return r.signal(i);default:return i}}):void 0,this.id=s.idGen.make(),g(V,this.id,"recall",this),++s.count}hasStaticDeps(){return this.#i!=null&&this.#i.length>0}saveSignalsFromDeps(){for(let e of this.#i)this.whenSignalIsRead(m(e).id)}static createEffect(e,t,r){let i=Array.isArray(t)?t:void 0,n=i?r??{dependencies:i}:t;n&&i&&(n.dependencies=i);let o,l=Fe();return l!=null?(o=l.getCurrentChildEffect(),o==null&&(o=new s(e,n),l.attachChildEffect(o),c(V,At,o)),l.curChildEffectSlot++):(o=new s(e,n),c(V,At,o)),o.hasStaticDeps()?o.saveSignalsFromDeps():o.autorun&&o.run(),new We(o)}getCurrentChildEffect(){return this.childEffects[this.curChildEffectSlot]}attachChildEffect(e){this.childEffects.push(e),this.parentEffect=this}run=()=>{if(this.#r||!this.shouldRun)return;let e=Xt();e?e.batch(this.id):(this.runCleanupCallback(),this.curChildEffectSlot=0,this.shouldRun=!1,this.hasStaticDeps()?this.#e=this.callback():this.#e=ts(this,this.callback))};recall(){this.shouldRun=!0,this.autorun&&this.run()}whenSignalIsRead(e){this.#t.has(e)||(this.#t.add(e),g(z,e,"recall",this),v(U,e,kt,this))}[kt](e){!this.#s.has(e)&&this.#t.has(e)&&(this.#s.add(e),y(z,e,this),this.#s.size===this.#t.size&&this.destroy())}runCleanupCallback(){if(this.#e!=null){let e=this.#e;this.#e=void 0,Ys(e)?Promise.resolve(e).then(t=>{typeof t=="function"&&t()}):e()}}destroy=()=>{this.#r||(c(this,s.Destroy,this),y(this),c(V,es,this),this.runCleanupCallback(),y(z,this),y(V,this),y(U,this),this.#r=!0,this.#t.clear(),this.#s.clear(),this.childEffects.forEach(e=>{e.destroy()}),this.childEffects.length=0,--s.count)}};var b=(...s)=>ue.createEffect(...s);var we=new WeakMap,Ks=s=>{let e=we.get(s);return e||(e={},we.set(s,e)),e},A=(s,e)=>we.get(s)?.signals?.get(e);var ss=(s,e,t)=>{let r=Ks(s);r.signals??=new Map,r.signals.set(e,t)};function Ee(...s){for(let e of s)if(we.has(e)){let t=we.get(e);if(t.signals){for(let r of t.signals.values())S(r);t.signals.clear(),t.signals=void 0}}}function rs(s){let e=m(fe(s)?s:A(...s));e!=null&&!e.muted&&!e.destroyed&&ze(e.id,e.value,{touch:!0})}function re(s){return fe(s)?m(s)?.value:m(A(...s))?.value}var Ue=class{[T];constructor(e){this[T]=e}get get(){return this[T].reader}get set(){return this[T].writer}get value(){return re(this.get)}set value(e){this.set(e)}onChange(e){let{destroy:t}=b(()=>e(this.value),[this.get]);return t}get muted(){return this[T].muted}set muted(e){this[T].muted=e}touch(){rs(this)}destroy(){S(this)}};var Js=new ce("si");function is(s){$e()||Fe()?.whenSignalIsRead(s)}function ze(s,e,t){$e()||c(z,s,e,t)}var fe=s=>s!=null&&s[T]!=null,Zs=s=>{let e=t=>(t?b(()=>(s.destroyed||is(s.id),t(s.value)),[e]):s.destroyed||(s.beforeRead?.(),is(s.id)),s.value);return Object.defineProperty(e,T,{value:s}),e},Ve=class s{static instanceCount=0;id;lazy;get[T](){return this}compare;beforeRead;muted=!1;destroyed=!1;#e=void 0;get value(){return this.lazy&&(this.#e=this.valueFn(),this.valueFn=void 0,this.lazy=!1),this.#e}set value(e){this.#e=e}valueFn;reader;writer=(e,t)=>{let r=t?.lazy??!1,n=t?.compare??this.compare??((l,a)=>l===a);if((r!==this.lazy||r&&e!==this.valueFn||!r&&!n(e,this.#e))&&(r?(this.#e=void 0,this.valueFn=e,this.lazy=!0):(this.#e=e,this.valueFn=void 0,this.lazy=!1),!this.muted&&!this.destroyed)){ze(this.id,this.#e);return}(t?.touch??!1)&&ze(this.id,this.#e,{touch:!0})};object;constructor(e,t){this.id=Js.make(),++s.instanceCount,this.lazy=e,this.lazy?(this.value=void 0,this.valueFn=t):(this.value=t,this.valueFn=void 0),this.reader=Zs(this),this.object=new Ue(this)}},m=s=>s?.[T];function f(s=void 0,e){let t;if(fe(s))t=m(s);else{let r=e?.lazy??!1;t=new Ve(r,s),t.beforeRead=e?.beforeRead,t.compare=e?.compare}return e?.attach!=null&&M.findOrCreate(e.attach).attachSignal(t),t.object}var S=(...s)=>{for(let e of s){let t=m(e);t!=null&&!t.destroyed&&(t.destroyed=!0,t.beforeRead=void 0,--Ve.instanceCount,c(U,t.id,t.id))}};var Be=class{#e=!1;#t;source;lastValue;isDestroyed=!1;constructor(e){w(this),this.source=m(e),this.#t=g(z,this.source.id,(t,r)=>{!this.#e&&!this.isDestroyed&&(r?.touch===!0?this.touch():this.write())}),v(U,this.source.id,()=>this.destroy())}attach(e){let t=M.findOrCreate(e);return t.attachLink(this),v(this,B,()=>{t.detachLink(this)}),t}nextValue(){return new Promise((e,t)=>{let r=[],i=()=>r.forEach(n=>{n()});r.push(v(this,le,n=>{i(),e(n)}),v(this,B,()=>{i(),t()}))})}async*asyncValues(e){let t=0;for(;!this.isDestroyed;)try{let r=await this.nextValue();if(e&&e(r,t++))break;D(this,le),yield r}catch{break}F(this,le)}destroy(){this.isDestroyed||(this.#t?.(),this.#t=void 0,c(this,B,this),F(this,le),y(this),this.lastValue=void 0,this.isDestroyed=!0,Object.freeze(this))}get isMuted(){return this.#e}mute(){return!this.isDestroyed&&!this.#e&&(this.#e=!0,c(this,Tt,this)),this}unmute(){return!this.isDestroyed&&this.#e&&(this.#e=!1,c(this,Ot,this)),this}toggle(){return this.isDestroyed||(this.#e=!this.#e,c(this,this.#e?Tt:Ot,this)),this.#e}updateValue(e){if(!this.#e&&!this.isDestroyed){let{value:t}=this.source;e(t),c(this,le,t),this.lastValue=t}}},qe=class extends Be{target;constructor(e,t){super(e),this.target=m(t),v(U,this.target.id,()=>this.destroy()),this.touch()}touch(){return this.updateValue(e=>{this.target.writer(e,{touch:!0})}),this}write(){this.updateValue(e=>{this.target.writer(e)})}},Ge=class extends Be{target;constructor(e,t){super(e),this.target=t,this.touch()}touch(){return this.updateValue(e=>{this.target(e)}),this}write(){this.updateValue(e=>{this.target(e)})}};var He=new Map;function de(s,e,t){let r=m(s),i;if(He.has(r)){i=He.get(r);let h=m(e)??e;if(i.has(h))return i.get(h)}else i=new Map,He.set(r,i);let n=m(e),o=n!=null?new qe(s,n):new Ge(s,e),l=t?.attach;l&&o.attach(l);let a=n??e;return i.set(a,o),v(o,B,()=>{i.delete(a),i.size===0&&He.delete(r)}),o}var Qe=class s{static fromProps(e,t){let r=new s,i=t?t.map(n=>[n,e[n]]):Object.entries(e);for(let[n,o]of i)r.#e.set(n,f(o));return r}#e=new Map;keys(){return this.#e.keys()}signals(){return this.#e.values()}entries(){return this.#e.entries()}clear(){for(let e of this.#e.values())e.destroy();this.#e.clear()}has(e){return this.#e.has(e)}get(e){if(!this.#e.has(e)){let t=f();return this.#e.set(e,t),t}return this.#e.get(e)}update(e){e.size&&k(()=>{for(let[t,r]of e.entries())this.get(t).set(r)})}updateFromProps(e,t){k(()=>{let r=t?t.map(i=>[i,e[i]]):Object.entries(e);for(let[i,n]of r)this.get(i).set(n)})}};var L;(function(s){s[s.StructuralChanges=1]="StructuralChanges",s[s.ContentUpdates=2]="ContentUpdates",s[s.Removal=3]="Removal"})(L||(L={}));var p;(function(s){s[s.CreateEntities=1]="CreateEntities",s[s.DestroyEntities=2]="DestroyEntities",s[s.SetParent=3]="SetParent",s[s.UpdateOrder=4]="UpdateOrder",s[s.ChangeProperties=5]="ChangeProperties",s[s.ChangeToken=6]="ChangeToken",s[s.SendEvents=7]="SendEvents"})(p||(p={}));var ie=Symbol.for("ShadowEntsGlobalNS"),I="#void",ns="contextLost",os="configure",as="changeTrail",hs="destroy",ls="loaded",us="appliedChangeTrail",cs="importedModule",fs="destroyed",pe="messageToView",ds=16e3,ps=16e3,gs=4e3,ys=1e3,Rt="shadowObjects";function ms(s,e){s.indexOf(e)===-1&&s.push(e)}function Mt(s,e){let t=s.indexOf(e);t!==-1&&s.splice(t,1),s.push(e)}function G(s,e){let t=s.indexOf(e);t!==-1&&s.splice(t,1)}var ne=s=>typeof s=="string"?s.trim()||ie:typeof s=="symbol"?s:ie;var Ce="#root",Se=class{#e;get uuid(){return this.#e}#t=0;constructor(e){this.#e=e}#s=!0;#i=0;#r=0;hasChanges(){return this.#t>0}get isNew(){return this.#s}get isCreated(){return this.#i>0&&this.#i>this.#r}get isDestroyed(){return this.#r>0&&this.#r>=this.#i}#n=I;#a;#o=0;#h;#l;#u;create(e=I,t,r=0){this.#t++,this.#i++,this.#h=e,this.#l=t??Ce,this.#u=r||void 0}destroy(){this.#r++,this.#t++}clear(){this.#t=0,this.#s=!1,this.#h=void 0,this.#l=void 0,this.#u=void 0,this.#f.clear(),this.#g.length=0,this.#p.length=0,this.#d.clear()}changeToken(e){e===this.#n?this.#h=void 0:(this.#h=e,this.#t++)}setParent(e){e===this.#a?this.#l=void 0:(this.#l=e??Ce,this.#t++)}changeOrder(e){e===this.#o?this.#u=void 0:(this.#u=e,this.#t++)}#c=new Map;#f=new Map;#g=[];changeProperty(e,t,r){let i=this.#c.get(e);r==null&&t!==i||r!=null&&!r(t,i)?(this.#f.set(e,t),Mt(this.#g,e),this.#t++):(this.#f.delete(e),G(this.#g,e))}removeProperty(e){let t=this.#c.has(e);this.#f.has(e)?(this.#f.delete(e),t||G(this.#g,e)):t&&(Mt(this.#g,e),this.#t++)}#p=[];#d=new Set;createEvent(e,t,r){this.#p.push({type:e,data:t}),r?.forEach(i=>this.#d.add(i)),this.#t++}transferEventsTo(e){this.#p.length>0&&(e.#p.push(...this.#p),this.#p.length=0),this.#d.size>0&&(e.#d=new Set([...e.#d,...this.#d]),this.#d.clear())}buildChangeTrail(e,t){let{isNew:r,isCreated:i,isDestroyed:n}=this;if(!(r&&n))switch(t){case L.StructuralChanges:r?e.push(this.makeCreateEntityChange()):n||(this.#l!==void 0&&!(this.#l===Ce&&this.#a===void 0)?e.push(this.makeSetParentChange()):this.#u!==void 0&&this.#u!==this.#o&&e.push(this.makeUpdateOrderChange()),this.#h!==void 0&&this.#h!==this.#n&&e.push(this.makeChangeToken()));break;case L.ContentUpdates:!r&&i&&this.#g.length>0&&e.push(this.makeChangePropertyChange()),this.#p.length>0&&e.push(this.makeEvents());break;case L.Removal:n&&e.push(this.makeDestroyEntityChange());break}}makeEvents(){let e={type:p.SendEvents,uuid:this.#e,events:this.#p.slice(0)};return this.#d.size>0&&(e.transferables=Array.from(this.#d)),e}makeCreateEntityChange(){let e={type:p.CreateEntities,uuid:this.#e,token:this.#h};if(this.#n=this.#h,this.#l!==void 0){let t=this.#l===Ce?void 0:this.#l;this.#a=t,t!==void 0&&(e.parentUuid=t)}return this.#f.size>0&&(e.properties=Array.from(this.#f.entries()).filter(([,t])=>t!==void 0),e.properties.forEach(([t,r])=>this.#c.set(t,r))),this.#u!==void 0&&this.#u!==this.#o&&(e.order=this.#o=this.#u),e}makeDestroyEntityChange(){return{type:p.DestroyEntities,uuid:this.#e}}makeSetParentChange(){this.#a=this.#l===Ce?void 0:this.#l;let e={type:p.SetParent,uuid:this.#e,parentUuid:this.#a};return this.#u!==void 0&&this.#u!==this.#o&&(e.order=this.#o=this.#u),e}makeUpdateOrderChange(){return this.#o=this.#u??0,{type:p.UpdateOrder,uuid:this.#e,order:this.#o}}makeChangeToken(){return this.#n=this.#h??I,{type:p.ChangeToken,uuid:this.#e,token:this.#n}}makeChangePropertyChange(){let e=this.#g.map(t=>{if(this.#f.has(t)){let r=this.#f.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 bs=s=>{if(!(s===void 0||s.length===0))return s.filter(e=>e.length===1||e[1]!==void 0)},Lt=(s,e)=>{if(s===e||e===void 0)return s;if(s===void 0)return bs(e);for(let[t,r]of e){let i=s.find(([n])=>n===t);i===void 0?s.push([t,r]):i[1]=r}return bs(s)};var Ye=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=Lt(r.properties,t)}changeToken({uuid:e,token:t}){this.getComponentState(e).token=t||I}updateOrder({uuid:e,order:t}){this.getComponentState(e).order=t??0}setParent({uuid:e,parentUuid:t,order:r}){let i=this.getComponentState(e);i.parentUuid=t,i.order=r??0}destroyEntity({uuid:e}){this.#e.delete(e)}createEntity({uuid:e,token:t,parentUuid:r,order:i,properties:n}){this.#e.set(e,{token:t||I,parentUuid:r,order:i??0,properties:Lt(void 0,n)})}};var R=class s{static{this.ReRequestParentRoots="re-request-parent-roots"}static getContextsMap(){return globalThis.__shadowEntsContexts==null&&(globalThis.__shadowEntsContexts=new Map),globalThis.__shadowEntsContexts}static get(e){let t=ne(e),r=s.getContextsMap();return r.has(t)?r.get(t):new s(t)}#e=new Map;#t=[];#s=new Ye;constructor(e=ie){let t=ne(e),r=s.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 Se(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.#a=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.#a=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),i=this.#e.get(t.uuid),n=i.children.indexOf(e);n!==-1&&(i.children.splice(n,1),r.changes.setParent(void 0)),this.#n(r.component,this.#t),this.#a=void 0}}moveToRoot(e){let t=this.#e.get(e);t&&(t.changes?.setParent(void 0),this.#n(t.component,this.#t)),this.#a=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),G(this.#t,t.uuid),this.#a=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,i){let n=this.#e.get(e.uuid);return n!=null?(i!=null?(n.propIsEqual??=new Map,n.propIsEqual.set(t,i)):n.propIsEqual?.has(t)&&n.propIsEqual.delete(t),n.changes.changeProperty(t,r,i)):!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);G(t.children,e.uuid),this.#n(e,t.children)}else G(this.#t,e.uuid),this.#n(e,this.#t);this.#e.get(e.uuid)?.changes.changeOrder(e.order),this.#a=void 0}traverseLevelOrderBFS(){return this.#o().map(e=>e.component)}dispatchShadowObjectsEvent(e,t,r,i){this.#e.get(e.uuid)?.changes.createEvent(t,r,i)}broadcastEvent(e,t=void 0){for(let r of this.traverseLevelOrderBFS())r.dispatchEvent(e,t,!1)}dispatchMessage(e,t,r=void 0,i=!1){this.#e.get(e)?.component.dispatchEvent(t,r,i)}dispatchReRequestParentRoots(){for(let e of this.#t)this.dispatchMessage(e,s.ReRequestParentRoots)}buildChangeTrails(e=!0){let t=[];if(!this.hasComponents())return t;let r=this.#r();for(let i of r)i.buildChangeTrail(t,L.StructuralChanges);for(let i of r)i.buildChangeTrail(t,L.ContentUpdates);for(let i of r)i.buildChangeTrail(t,L.Removal),(i.isDestroyed||i.isNew&&!i.isCreated)&&this.#i(i.uuid),e&&i.clear();return this.#s.write(t),t}reCreateChanges(){if(!this.#s.isEmpty()){this.buildChangeTrails(!1);for(let[e,t]of this.#s){let r=this.#e.get(e);if(r){let i=new Se(e);if(i.create(t.token,t.parentUuid,t.order),t.properties)for(let[n,o]of t.properties)i.changeProperty(n,o,r.propIsEqual?.get(n));r.changes.transferEventsTo(i),r.changes.clear(),r.changes=i}}this.#s.clear(),this.broadcastEvent(ns)}}clear(){if(this.#a=void 0,this.#s.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),G(this.#t,e),this.#a=void 0)}#r(){return this.#o().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,i=new Array(r);if(i[0]=this.#e.get(t[0]).component,e.order<i[0].order){t.unshift(e.uuid);return}if(r===1){t.push(e.uuid);return}let n=r-1;if(i[n]=this.#e.get(t[n]).component,e.order>=i[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(i[o]=this.#e.get(t[o]).component,e.order>=i[o].order){t.splice(o+1,0,e.uuid);return}}#a;#o(){if(this.#a)return this.#a;let e=new Map,t=(r,i)=>{let n=this.#e.get(r);if(n!=null){e.has(i)?e.get(i).push(n):e.set(i,[n]);for(let o of n.children)t(o,i+1)}};return this.#t.forEach(r=>t(r,0)),this.#a=Array.from(e.entries()).sort((r,i)=>r[0]-i[0]).map(([,r])=>r).flat(),this.#a}};function xe(s,e,t,r,i,n){function o(me){if(me!==void 0&&typeof me!="function")throw new TypeError("Function expected");return me}for(var l=r.kind,a=l==="getter"?"get":l==="setter"?"set":"value",h=!e&&s?r.static?s:s.prototype:null,u=e||(h?Object.getOwnPropertyDescriptor(h,r.name):{}),d,E=!1,oe=t.length-1;oe>=0;oe--){var je={};for(var ae in r)je[ae]=ae==="access"?{}:r[ae];for(var ae in r.access)je.access[ae]=r.access[ae];je.addInitializer=function(me){if(E)throw new TypeError("Cannot add initializers after decoration has completed");n.push(o(me||null))};var Z=(0,t[oe])(l==="accessor"?{get:u.get,set:u.set}:u[a],je);if(l==="accessor"){if(Z===void 0)continue;if(Z===null||typeof Z!="object")throw new TypeError("Object expected");(d=o(Z.get))&&(u.get=d),(d=o(Z.set))&&(u.set=d),(d=o(Z.init))&&i.unshift(d)}else(d=o(Z))&&(l==="field"?i.unshift(d):u[a]=d)}h&&Object.defineProperty(h,r.name,u),E=!0}function H(s,e,t){for(var r=arguments.length>2,i=0;i<e.length;i++)t=r?e[i].call(s,t):e[i].call(s);return r?t:void 0}function ke(s){return function(e,t){let r=s?.name||t.name,i=!!(s?.readAsValue??!1);return{get(){let n=A(this,r);if(n)return i?n.value:n.get()},set(n){A(this,r)?.set(n)},init(n){let o=f(n,s);return ss(this,r,o),M.findOrCreate(this).attachSignalByName(r,o),o.value}}}}var P="ConsoleLogger",O=`${P}Storage`,Xs=!!(globalThis.location?.host?.startsWith("localhost")??!1),Te="localStorage"in globalThis,Ke=Symbol.for(P),vs=!1,ws=s=>{if(typeof s=="boolean")return s;switch(s.toLowerCase()){case"true":case"yes":case"on":return!0;default:return!1}},Nt=s=>[Te?P:void 0,...Array.isArray(s)?s:[s]].filter(Boolean).join(".");function _t(s,e=void 0,t){let r=Nt(s),i=Te?localStorage.getItem(r):globalThis[O]?.[r];return i!=null?e(i):t}function Ae(s,e){Te?localStorage.setItem(Nt(s),e):(globalThis[O]==null&&(globalThis[O]={},console.debug(`${P}: Initialize`,{[O]:globalThis[O]})),globalThis[O][Nt(s)]=e)}var x=class s{static{this.sharedConfig={enable:Xs,debug:!1,info:!0,warn:!0,"styles.debug":"color: #111; background: #999; display: inline-block; padding: 0 0.25em; margin: 0; border-radius: 0.25em","styles.info":"color: #020; background: #8a8; display: inline-block; padding: 0 0.25em; margin: 0; border-radius: 0.25em","styles.warn":"color: #fa0; background: #a98; display: inline-block; padding: 0 0.25em; margin: 0; border-radius: 0.25em","styles.error":"color: #ff0; background: #a00; display: inline-block; padding: 0 0.25em; margin: 0; border-radius: 0.25em"}}static get isEnabled(){return s.sharedConfig.enable}static get isDebug(){return s.sharedConfig.enable&&s.sharedConfig.debug}static{this.sharedStyles={get debug(){return s.sharedConfig["styles.debug"]},set debug(e){s.sharedConfig["styles.debug"]=e},get info(){return s.sharedConfig["styles.info"]},set info(e){s.sharedConfig["styles.info"]=e},get warn(){return s.sharedConfig["styles.warn"]},set warn(e){s.sharedConfig["styles.warn"]=e},get error(){return s.sharedConfig["styles.error"]},set error(e){s.sharedConfig["styles.error"]=e}}}static loadConfig(){Te?(["enable","debug","info","warn"].forEach(e=>{this.sharedConfig[e]=_t(e,ws,this.sharedConfig[e])}),["debug","info","warn","error"].forEach(e=>{this.sharedStyles[e]=_t(["styles",e],void 0,this.sharedStyles[e])}),s.isDebug&&console.debug(`${P}: Load config from localStorage`,s.sharedConfig),globalThis[P]?.[Ke]||(globalThis[P]??={[Ke]:!0,get enable(){return s.sharedConfig.enable},set enable(e){s.sharedConfig.enable=e,Ae("enable",e?"true":"false")},get debug(){return s.sharedConfig.debug},set debug(e){s.sharedConfig.debug=e,Ae("debug",e?"true":"false")},get info(){return s.sharedConfig.info},set info(e){s.sharedConfig.info=e,Ae("info",e?"true":"false")},get warn(){return s.sharedConfig.warn},set warn(e){s.sharedConfig.warn=e,Ae("warn",e?"true":"false")}})):globalThis[O]?.[Ke]||(globalThis[O]={[Ke]:!0,...s.sharedConfig,...globalThis[O]},s.sharedConfig=globalThis[O],s.isDebug&&console.debug(`${P}: Load config from ${O}`,globalThis[O]))}constructor(e){this.enable=!0,this.namespace=(e||"").trim()||P,vs||(s.loadConfig(),vs=!0);let t=[this.namespace,"enable"];this.enable=_t(t,ws,this.enable),Ae(t,Te?this.enable?"true":"false":this.enable)}get isEnabled(){return this.enable&&s.sharedConfig.enable}get isDebug(){return this.isEnabled&&s.sharedConfig.debug}get isInfo(){return this.isEnabled&&s.sharedConfig.info}get isWarn(){return this.isEnabled&&s.sharedConfig.warn}debug(...e){this.#e("debug",s.sharedStyles.debug,e)}info(...e){this.#e("info",s.sharedStyles.info,e)}warn(...e){this.#e("warn",s.sharedStyles.warn,e)}error(...e){this.#e("error",s.sharedStyles.error,e)}#e(e,t,r){console[e](`%c${this.namespace}`,t,...r)}};var _=(()=>{var s;let e,t=[],r=[],i,n=[],o=[];return class ${static{let a=typeof Symbol=="function"&&Symbol.metadata?Object.create(null):void 0;e=[ke()],i=[ke()],xe(this,null,e,{kind:"accessor",name:"viewReady",static:!1,private:!1,access:{has:h=>"viewReady"in h,get:h=>h.viewReady,set:(h,u)=>{h.viewReady=u}},metadata:a},t,r),xe(this,null,i,{kind:"accessor",name:"proxyReady",static:!1,private:!1,access:{has:h=>"proxyReady"in h,get:h=>h.proxyReady,set:(h,u)=>{h.proxyReady=u}},metadata:a},n,o),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;#s;#i;#r;#n;#a;get viewReady(){return this.#a}set viewReady(a){this.#a=a}#o;get proxyReady(){return this.#o}set proxyReady(a){this.#o=a}#h;get isDestroyed(){return this.#h}constructor(){this.#s=!1,this.#i=!1,this.#r=!1,this.logger=new x("ShadowEnv"),this.ns$=f(),this.#a=H(this,t,!1),this.#o=(H(this,r),H(this,n,!1)),this.#h=(H(this,o),!1),this.ready=async()=>this.isReady?this:he(this,$.ContextCreated),this.#l=()=>{this.#s&&this.#u()},D(this,$.ContextCreated),g(this,$.ContextLost,ve.AAA,()=>{F(this,$.ContextCreated)}),b(()=>{if(this.viewReady&&this.proxyReady)return this.view.reCreateChanges(),c(this,$.ContextCreated,this),this.#i&&(this.#i=!1,this.#u()),()=>{c(this,$.ContextLost,this)}},[A(this,"viewReady"),A(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&&this.logger.isWarn&&this.logger.warn("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 h=this.#t;this.#t=a??void 0,this.#t&&(this.#t.onMessageToView=this.#c.bind(this)),h&&h.destroy(),this.proxyReady=!1,a?.start().then(()=>{this.proxyReady=!0}).catch(u=>{this.logger.error("failed to start envProxy",u),this.proxyReady=!1})}}get isReady(){return!!(this.#e&&this.#t&&this.proxyReady&&!this.isDestroyed)}sync(){if(!this.isReady){this.#i=!0;return}this.#s||(this.#s=!0,queueMicrotask(this.#l))}syncWait(){return this.#r=!0,this.sync(),this.#n?this.#n:(this.#n=he(this,$.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),Ee(this),y(this),this.#h=!0,Object.freeze(this)}#l;async#u(){if(this.#s=!1,this.isReady){let a=this.view.buildChangeTrails();if(a.length>0)try{let h=this.#r;this.#r=!1,await this.envProxy.applyChangeTrail(a,h)}catch(h){this.logger.error("failed to apply change trail",h)}finally{c(this,$.AfterSync,a)}}}#c(a){this.logger.isDebug&&this.logger.debug("onMessageToView",a.type,a.data),this.view?.dispatchMessage(a.uuid,a.type,a.data,a.traverseChildren)}}})();var C=["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"],er=()=>{let s=Math.random()*4294967295|0,e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,r=Math.random()*4294967295|0;return(C[s&255]+C[s>>8&255]+C[s>>16&255]+C[s>>24&255]+"-"+C[e&255]+C[e>>8&255]+"-"+C[e>>16&15|64]+C[e>>24&255]+"-"+C[t&63|128]+C[t>>8&255]+"-"+C[t>>16&255]+C[t>>24&255]+C[r&255]+C[r>>8&255]+C[r>>16&255]+C[r>>24&255]).toLowerCase()},Es=()=>globalThis?.crypto?.randomUUID?.()??er();var Oe=class extends Error{constructor(e){super(e),this.name="ViewComponentError"}},Je=class s{#e;#t;#s;#i;#r=0;get uuid(){return this.#e}get token(){return this.#t}set token(e){e??=I,e!==this.#t&&(this.#t=e,this.#s?.changeToken(this,e))}get parent(){return this.#i}set parent(e){if(e){if(e.#s!==this.#s)throw new Oe("cannot set parent from different context");e.addChild(this)}else this.removeFromParent()}get context(){return this.#s}set context(e){this.#s!=e&&(this.#s&&this.destroy(),this.#s=e,e&&e.addComponent(this))}get order(){return this.#r}set order(e){let t=this.#r;this.#r=e??0,t!==this.#r&&this.#s.changeOrder(this)}constructor(e,t){w(this),t instanceof s&&(t={parent:t}),this.#e=t?.uuid??Es(),this.#t=e,this.#r=t?.order??0,this.#i=t?.parent;let r=t?.context??R.get();if(this.#i&&this.#i.#s!==r)throw new Oe("cannot set parent from different context");this.context=r}isChildOf(e){return this.#i===e}removeFromParent(){this.#i?(this.#s?.removeFromParent(this.uuid,this.#i),this.#i=void 0):this.#s?.moveToRoot(this.uuid)}addChild(e){if(e.#s!==this.#s)throw new Oe("cannot add a child from another context");e.isChildOf(this)||(e.removeFromParent(),e.#i=this,this.#s.addToChildren(this,e))}setProperty(e,t,r){this.#s.setProperty(this,e,t,r)}removeProperty(e){this.#s.removeProperty(this,e)}dispatchShadowObjectsEvent(e,t,r){this.#s.dispatchShadowObjectsEvent(this,e,t,r)}dispatchEvent(e,t,r){if(c(this,e,t),r)for(let i of this.#s.getChildren(this))i.dispatchEvent(e,t,r)}destroy(){this.removeFromParent(),this.#s?.destroyComponent(this),this.#s=void 0}};var Ze="shaeRequestEntParent",Xe="shaeReRequestEntParent",Cs="shae-worker",et="shae-ent",Ss="shae-prop",Q="token",Y="ns",tt="local",xs="no-autostart",st="no-structured-clone",N="auto-sync",rt="src",it="name",nt="value",ot="type",at="no-trim";var Pe=new Set(["on","true","yes","local","1"]);var ks=s=>ne(s.getAttribute(Y)),Re=(s,e)=>{if(s.hasAttribute(e)){let t=s.getAttribute(e)?.trim()?.toLowerCase()||"1";return Pe.has(t)}return!1};var As=(s,e)=>{e.set(ks(s))},jt=new Set,Dt=!1,tr=s=>{jt.add(s),Dt||(Dt=!0,queueMicrotask(()=>{Dt=!1;for(let e of jt)_.get(e)?.sync();jt.clear()}))},K=class extends HTMLElement{static{this.observedAttributes=[Y]}get ns(){return this.ns$.value}set ns(e){typeof e=="symbol"?this.ns$.set(e):this.ns$.set(ne(e))}constructor(){super(),this.isShaeElement=!0,this.ns$=f(ie),this.ns$.onChange(e=>{typeof e=="string"&&e.length>0?this.getAttribute(Y)!==e&&this.setAttribute(Y,e):this.removeAttribute(Y)}),As(this,this.ns$)}attributeChangedCallback(e){e===Y&&As(this,this.ns$)}syncShadowObjects(){tr(this.ns)}};var ht=class extends K{static{this.observedAttributes=[...K.observedAttributes,Q]}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)}#e;constructor(){super(),this.isShaeEntElement=!0,this.componentContext$=f(),this.viewComponent$=f(),this.token$=f(),this.#n=!0,this.#g=()=>{let e=this.findShadowRootHost();e!=null&&this.dispatchEvent(new CustomEvent(Xe,{bubbles:!0,composed:!0,detail:{requester:this,shadowRootHost:e}}))},this.#p=e=>{let t=e.detail?.requester;if(t===this||!t?.isShaeEntElement||t.ns!==this.ns)return;let r=e.detail?.shadowRootHost;r&&this.#c?.has(r)&&this.#l()},this.#d=e=>{let t=e.detail?.requester;t!==this&&t?.isShaeEntElement&&t.ns===this.ns&&(e.stopPropagation(),t.#f(this))},this.ns$.onChange(e=>{this.componentContext$.set(R.get(e)),this.isConnected&&this.#l()}),this.#y(),this.token$.onChange(e=>{e==null?this.removeAttribute(Q):this.getAttribute(Q)!==e&&this.setAttribute(Q,e)}),b(()=>{let e=this.viewComponent$.get();if(e){let t=g(e,R.ReRequestParentRoots,()=>this.#h()),r=e.context?.ns;return()=>{t(),e.destroy(),r&&r!==this.ns?_.get(r)?.sync():this.syncShadowObjects()}}}),this.token$.onChange(e=>{let t=this.viewComponent$.value;t&&(t.token=e,this.syncShadowObjects())})}#t;#s(){this.#t?.();let e=this.componentContext$.onChange(t=>{let r=this.token$.value,i=this.viewComponent$.value;i?i.context=t:t&&(i=new Je(r,{context:t}),this.viewComponent$.set(i)),this.syncShadowObjects()});this.#t=()=>{e()}}#i(){this.#t?.(),this.#t=void 0}#r;#n;findShadowRootHost(){if(this.#n){this.#n=!1;let e=this;for(;e;){if(e.parentElement==null){let t=e.parentNode;t&&(this.#r=t.host);break}e=e.parentElement}}return this.#r}getParentNodeForObserver(){let e=this.parentNode;return e||(e.host??e)}connectedCallback(){this.#n=!0,this.addEventListener("slotchange",this.#g,{capture:!1,passive:!1}),this.addEventListener(Ze,this.#d,{capture:!1,passive:!1}),this.#s(),xt(()=>this.#y()),this.componentContext==null&&this.componentContext$.set(R.get(this.ns)),this.#l(),this.componentContext?.dispatchReRequestParentRoots(),this.#a(),this.syncShadowObjects()}#a(){this.#o();let e=this.getParentNodeForObserver();e&&(this.#e=new MutationObserver((t,r)=>{for(let{target:i,removedNodes:n}of t)if(i===e){for(let o of n)if(o===this){this.#o(),this.onParentChanged(this.getParentNodeForObserver(),e);break}}}),this.#e.observe(e,{childList:!0,subtree:!1,attributes:!1}))}onParentChanged(e,t){this.#f(void 0),this.#l()}#o(){this.#e?.disconnect(),this.#e=void 0}attributeChangedCallback(e){super.attributeChangedCallback(e),e===Q&&this.#y()}disconnectedCallback(){this.#n=!0,this.#o(),this.removeEventListener("slotchange",this.#g,{capture:!1}),this.removeEventListener(Ze,this.#d,{capture:!1}),this.#f(void 0),this.componentContext$.set(void 0),this.syncShadowObjects(),this.#i()}#h(){this.isConnected&&(this.#f(void 0),this.#l())}#l(){this.dispatchEvent(new CustomEvent(Ze,{bubbles:!0,composed:!0,detail:{requester:this}}))}#u;#c;#f(e){if(this.entParentNode!==e){if(this.entParentNode&&this.entParentNode.removeEventListener(Xe,this.#p,{capture:!1}),this.entParentNode=e,this.entParentNode&&this.entParentNode.addEventListener(Xe,this.#p,{capture:!1,passive:!1}),this.#c=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.#c=new WeakSet(t))}if(this.#u?.(),this.#u=void 0,e){let t=b(()=>{let r=this.viewComponent$.get();if(r){let i=e.viewComponent$.get();r.parent=i&&i.context===r.context?i:void 0,r.parent==null&&queueMicrotask(()=>{this.#l()}),this.syncShadowObjects()}});this.#u=()=>t.destroy()}else{let t=this.viewComponent;t.parent&&(t.parent=void 0,this.syncShadowObjects())}}}#g;#p;#d;#y(){if(this.hasAttribute(Q)){let e=this.getAttribute(Q)?.trim()||void 0;this.token$.set(e)}}};customElements.define(et,ht);var sr=s=>{let e=s.parentElement;for(;e;){if(e.isShaeEntElement)return e;e=e.parentElement}},rr=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"]),lt=class extends HTMLElement{static{this.observedAttributes=[it,nt,ot,at]}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$=f(),this.viewComponent$=f(),this.name$=f(),this.valueIn$=f(),this.valueOut$=f(),this.type$=f(),this.shouldTrim$=f(!0),this.logger=new x("ShaePropElement"),this.#e=()=>{this.entNode$.set(sr(this))},this.#t=()=>{queueMicrotask(()=>{this.isConnected||this.entNode$.set(void 0)})},this.#s=()=>{this.name$.set(this.getAttribute(it)?.trim()??void 0)},this.#i=()=>{this.valueIn$.set(this.getAttribute(nt))},this.#r=()=>{let e=this.getAttribute(ot)?.trim().toLowerCase();e&&!rr.has(e)&&(this.logger.isWarn&&this.logger.warn(`[${this.name}] unknown type "${e}"`,{shaeProp:this}),e=void 0),this.type$.set(e)},this.#n=()=>{this.shouldTrim$.set(!Re(this,at))},this.entNode$.onChange(e=>{if(e){let t=de(e.viewComponent$,this.viewComponent$);return()=>{t.destroy()}}else this.viewComponent$.set(void 0)}),b(()=>{let e=this.viewComponent$.get();if(e){let t=this.name$.get();if(t){let r=this.valueOut$.get();this.logger.isDebug&&this.logger.debug(`[${this.name}] view-component set-property`,t,r,e.uuid,{viewComponent:e,shaeProp:this}),e.setProperty(t,r),this.isConnected&&this.entNode?.syncShadowObjects()}}}),b(()=>{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=Pe.has(r.toLowerCase());break;case"[]":case"text[]":case"string[]":r=r.split(/\W+/);break;case"number[]":r=r.split(/\W+/).map(i=>Number(i));break;case"float[]":r=r.split(/\W+/).map(i=>parseFloat(i));break;case"int[]":case"integer[]":r=r.split(/\W+/).map(i=>parseInt(i));break;case"hex[]":case"hexadecimal[]":r=r.split(/\W+/).map(i=>parseInt(i,16));break;case"oct[]":case"octal[]":r=r.split(/\W+/).map(i=>parseInt(i,8));break;case"bin[]":case"binary[]":r=r.split(/\W+/).map(i=>parseInt(i,2));break;case"bool[]":case"boolean[]":r=r.split(/\W+/).map(i=>Pe.has(i.toLowerCase()));break;case"int8array":r=new Int8Array(r.split(/\W+/).map(i=>Number(i)));break;case"uint8array":r=new Uint8Array(r.split(/\W+/).map(i=>Number(i)));break;case"uint8clampedarray":r=new Uint8ClampedArray(r.split(/\W+/).map(i=>Number(i)));break;case"int16array":r=new Int16Array(r.split(/\W+/).map(i=>Number(i)));break;case"uint16array":r=new Uint16Array(r.split(/\W+/).map(i=>Number(i)));break;case"int32array":r=new Int32Array(r.split(/\W+/).map(i=>Number(i)));break;case"uint32array":r=new Uint32Array(r.split(/\W+/).map(i=>Number(i)));break;case"float32array":r=new Float32Array(r.split(/\W+/).map(i=>Number(i)));break;case"float64array":r=new Float64Array(r.split(/\W+/).map(i=>Number(i)));break;case"bigint64array":r=new BigInt64Array(r.split(/\W+/).map(i=>BigInt(i)));break;case"biguint64array":r=new BigUint64Array(r.split(/\W+/).map(i=>BigInt(i)));break;case"json":r=JSON.parse(r);break;default:this.logger.isWarn&&this.logger.warn(`[${this.name}] unknown type "${e}"`,{value:r,shaeProp:this})}this.valueOut$.set(r)}),k(()=>{this.#s(),this.#i(),this.#r(),this.#n()})}connectedCallback(){k(()=>{this.#e(),this.#s(),this.#i(),this.#r(),this.#n()})}attributeChangedCallback(e){switch(e){case it:this.#s();break;case nt:this.#i();break;case ot:this.#r();break;case at:this.#n();break}}disconnectedCallback(){this.#t()}#e;#t;#s;#i;#r;#n};customElements.whenDefined(et).then(()=>customElements.define(Ss,lt));var ut,It=null,ge=class{static{this.OnFrame=Symbol("onFrame")}#e=0;#t=0;constructor(){if(It)return It;w(this),It=this}start(e){if(e!=null)return Ct(this)===0&&this.#i(),g(this,ut.OnFrame,e),this.#t++,()=>{this.stop(e)}}stop(e){y(this,ut.OnFrame,e),Ct(this)===0&&this.#r()}#s=e=>{c(this,ut.OnFrame,e),this.#i()};#i(){this.#e=requestAnimationFrame(this.#s)}#r(){cancelAnimationFrame(this.#e),this.#e=0}};ut=ge;var ye="value",ct=(()=>{let s,e=[],t=[];return class{static{let i=typeof Symbol=="function"&&Symbol.metadata?Object.create(null):void 0;s=[ke({name:ye})],xe(this,null,s,{kind:"accessor",name:"value",static:!1,private:!1,access:{has:n=>"value"in n,get:n=>n.value,set:(n,o)=>{n.value=o}},metadata:i},e,t),i&&Object.defineProperty(this,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:i})}static{this.Value=ye}#e=[];#t;#s=H(this,e,void 0);get value(){return this.#s}set value(i){this.#s=i}constructor(){H(this,t),D(this,ye),A(this,ye).onChange(i=>c(this,ye,i))}add(...i){for(let n of i)this.#e.push(n);this.#r()}pop(){this.#e.pop(),this.#r()}clear(){this.#e.length=0,this.#i()}dispose(){this.clear(),F(this,ye),y(this),Ee(this)}#i(){this.#t?.destroy(),this.#t=void 0}#r(){this.#i(),this.#t=b(()=>{for(let i of this.#e){let n=re(i);if(n!=null){this.value=n;return}}this.value=void 0},this.#e),this.#t.run()}}})();var $t="onCreate",J="onDestroy",Ts="onParentChanged",Os="onViewEvent";var ft=class{#e;#t;#s=new Qe;#i=new Map;#r;#n;#a=new Set;#o=[];#h=0;get kernel(){return this.#e}get uuid(){return this.#t}get order(){return this.#h}set order(e){this.#h!==e&&(this.#h=e,this.#r&&this.parent.resortChildren())}get parentUuid(){return this.#r||void 0}set parentUuid(e){this.#r!==e&&(this.removeFromParent(),this.#r=e||void 0,this.#n=e?this.#e.getEntity(e):void 0,this.#n&&this.#n.addChild(this))}get parent(){return!this.#n&&this.#r&&(this.#n=this.#e.getEntity(this.#r)),this.#n}set parent(e){this.parentUuid=e?.uuid}get hasParent(){return!!this.#r}get children(){return this.#o}constructor(e,t){this.#e=e,this.#t=t,v(this,J,ve.Min,this)}traverse(e){e(this);for(let t of this.#o)t.traverse(e)}onDestroy(){this.#s.clear(),y(this);for(let e of this.#i.values())e.unsubscribeFromPath(),e.unsubscribeFromParent?.(),e.ctxPath.dispose(),e.inherited.destroy(),e.provide.destroy(),e.context.destroy();this.#r=void 0,this.#n=void 0,this.#a.clear(),this.#o.length=0}addChild(e){if(this.#o.length===0){this.#a.add(e.uuid),this.#o.push(e);return}if(this.#a.has(e.uuid))throw new Error(`child with uuid: ${e.uuid} already exists! parentUuid: ${this.uuid}`);this.#a.add(e.uuid),this.#o.push(e),this.resortChildren();for(let[,t]of e.#i)e.#c(t)}resortChildren(){this.#o.sort((e,t)=>e.order-t.order)}removeChild(e){this.#a.has(e.uuid)&&(this.#a.delete(e.uuid),this.#o.splice(this.#o.indexOf(e),1))}removeFromParent(){if(this.#n){this.#n.removeChild(this),this.#n=void 0,this.#r=void 0;for(let[,e]of this.#i)e.unsubscribeFromParent&&(e.unsubscribeFromParent(),e.unsubscribeFromParent=void 0)}}reSubscribeToParentContexts(){for(let[,e]of this.#i)this.#c(e)}dispatchMessageToView(e,t,r,i=!1){this.#e.dispatchMessageToView({uuid:this.#t,type:e,data:t,transferables:r,traverseChildren:i})}dispatchViewEvents(e){for(let{type:t,data:r}of e)c(this,Os,t,r)}dispatchViewEvent(e,t){this.dispatchViewEvents([{type:e,data:t}])}#l(e){return this.#s.get(e)}getPropertyReader(e){return this.#l(e).get}getPropertyWriter(e){return this.#l(e).set}setProperties(e){k(()=>{for(let[t,r]of e)this.setProperty(t,r)})}setProperty(e,t){this.getPropertyWriter(e)(t)}getProperty(e){return re(this.getPropertyReader(e))}propKeys(){return Array.from(this.#s.keys())}propEntries(){return Array.from(this.#s.entries()).map(([e,t])=>[e,t.value])}hasContext(e){return this.#i.has(e)}useContext(e){return this.#u(e).context.get}provideContext(e){return this.#u(e).provide}#u(e){let t=this.#i.get(e);if(t==null){let r=f(),i=f(),n=f(),o=new ct;o.add(i.get,r.get);let l=g(o,ct.Value,a=>{queueMicrotask(()=>{n.set(a)})});t={name:e,inherited:r,provide:i,context:n,ctxPath:o,unsubscribeFromPath:l},this.#i.set(e,t),this.#c(t)}return t}#c(e){if(e.unsubscribeFromParent?.(),e.unsubscribeFromParent=void 0,this.parent){let t=this.parent.#u(e.name).ctxPath;e.inherited.set(t.value),e.unsubscribeFromParent=g(t,ct.Value,r=>{e.inherited.set(r)})}else e.inherited.set(void 0)}};var Me=class{static get(e){return e??ir}#e=new Map;#t=new Map;define(e,t){this.#e.has(e)?ms(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 i of t)r.add(i)}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 i=r.shift();t.has(i)||(t.add(i),this.#t.has(i)&&r.push(...Array.from(this.#t.get(i)).filter(n=>!t.has(n))))}return Array.from(t)}findConstructors(e){let t=this.findTokensByRoute(e),r=new Set;for(let i of t){let n=this.#e.get(i);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()}},ir=new Me;var W;(function(s){s[s.CreateAndDestroy=0]="CreateAndDestroy",s[s.JustCreate=1]="JustCreate",s[s.DestroyOnly=2]="DestroyOnly"})(W||(W={}));var Ps=s=>s.displayName||s.name,dt=class{#e;#t;#s;#i;#r;constructor(e){this.logger=new x("Kernel"),this.#e=new Map,this.#t=new Set,this.#r=!0,w(this),this.registry=Me.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.#r){let t=new Map,r=(i,n)=>{let o=this.getEntity(i);t.has(n)?t.get(n).push(o):t.set(n,[o]);for(let l of o.children)r(l.uuid,n+1)};this.#t.forEach(i=>r(i,0)),this.#s=Array.from(t.entries()).sort((i,n)=>i[0]-n[0]).map(([,i])=>i).flat(),this.#i=this.#s.slice().reverse(),this.#r=!1}return e?this.#i:this.#s}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(i=>this.getEntityGraphNode(i.uuid))}}upgradeEntities(){for(let e of this.traverseLevelOrderBFS(!0))this.updateShadowObjects(e.uuid,W.DestroyOnly);for(let e of this.traverseLevelOrderBFS(!1))this.updateShadowObjects(e.uuid,W.JustCreate)}run(e){k(()=>{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.#r=!0;break;case p.DestroyEntities:this.destroyEntity(e.uuid),this.#r=!0;break;case p.SetParent:this.setParent(e.uuid,e.parentUuid,e.order),this.#r=!0;break;case p.UpdateOrder:this.updateOrder(e.uuid,e.order),this.#r=!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,i=0,n){let o=new ft(this,e);o.order=i;let l={token:t,entity:o,usedConstructors:new Map};this.#e.set(e,l),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(),c(t,J,this),r.clear(),this.#e.delete(t.uuid),this.#t.delete(t.uuid)}setParent(e,t,r=0){let i=this.getEntity(e);i.parentUuid===t&&i.order===r||(i.removeFromParent(),i.order=r,i.parentUuid=t,i.hasParent?this.#t.delete(e):this.#t.add(e),i.reSubscribeToParentContexts(),queueMicrotask(()=>{this.logger.isDebug&&this.logger.debug("entity.onParentChanged",{uuid:e,parentUuid:t,order:r,entity:i}),c(i,Ts,i)}))}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(()=>{c(this,pe,e)})}updateShadowObjects(e,t=W.CreateAndDestroy){let r=this.#e.get(e),i=new Set(this.registry.findConstructors(r.token)),n=t===W.CreateAndDestroy||t===W.DestroyOnly,o=t===W.CreateAndDestroy||t===W.JustCreate;if(n){for(let[l,a]of r.usedConstructors)if(!i.has(l)){r.usedConstructors.delete(l);for(let h of a)this.destroyShadowObject(h,r.entity)}}if(o)for(let l of i)r.usedConstructors.has(l)||this.constructShadowObject(l,r)}constructShadowObject(e,t){let r=new Set,i=new Set,n=new Map,o=new Map,l=new Map,a=w(new e({entity:t.entity,provideContext(h,u,d){let E=o.get(h);if(E===void 0){E=f(u,d?{compare:d}:void 0),o.set(h,E);let oe=de(E,t.entity.provideContext(h));i.add(oe.destroy.bind(oe))}return E},useContext(h,u){let d=n.get(h);if(d===void 0){d=f(void 0,u?{compare:u}:void 0).get,n.set(h,d);let E=de(t.entity.useContext(h),d);i.add(E.destroy.bind(E))}return d},useProperty(h,u){let d=l.get(h);if(d===void 0){d=f(void 0,u?{compare:u}:void 0).get,l.set(h,d);let E=de(t.entity.getPropertyReader(h),d);i.add(E.destroy.bind(E))}return d},createEffect(...h){let u=b(...h);return i.add(u.destroy),u},createSignal(...h){let u=f(...h);return i.add(()=>{S(u)}),u},on(...h){let u=g(...h);return i.add(u),u},once(...h){let u=v(...h);return i.add(u),u},onDestroy(h){r.add(h)}}));return this.logger.isInfo&&this.logger.info("create shadow-object",Ps(e),{shadowObject:a,entity:t.entity}),v(a,J,()=>{this.logger.isInfo&&this.logger.info("destroy shadow-object",Ps(e),{shadowObject:a,entity:t.entity});for(let u of r)u();for(let u of i)u();for(let u of n.values())S(u);for(let u of l.values())S(u);for(let u of o.values())S(u);r.clear(),i.clear(),n.clear(),l.clear(),o.clear();let h=t.usedConstructors.get(e);h&&(h.delete(a),h.size===0&&t.usedConstructors.delete(e))}),t.usedConstructors.has(e)?t.usedConstructors.get(e).add(a):t.usedConstructors.set(e,new Set([a])),this.attachShadowObject(a,t.entity),a}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){g(t,e),typeof e[$t]=="function"&&e[$t](t)}destroyShadowObject(e,t){typeof e[J]=="function"&&e[J](t),c(e,J,t),y(t,e)}destroy(){for(let e of this.traverseLevelOrderBFS().reverse())this.destroyEntity(e.uuid)}};async function Wt(s,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=>Wt(s,n,t,!1)));let{registry:i}=s;if(e.define)for(let[n,o]of Object.entries(e.define))i.define(n,o);if(e.routes)for(let[n,o]of Object.entries(e.routes))i.appendRoute(n,o);await(e.initialize?.({define:(n,o)=>i.define(n,o),kernel:s,registry:i})??Promise.resolve()),r&&s.upgradeEntities()}var pt=s=>(typeof s=="string"&&(s=new URL(s,globalThis.location.href)),s.toString());function Rs(s){return s.map(e=>{if(e.transferables&&e.transferables.length>0){let{transferables:t,...r}=e;return structuredClone(r,{transfer:t})}else return structuredClone(e)})}var gt=class{#e;get registry(){return this.kernel.registry}constructor(e){this.#e=new Set,this.isLocalEnv=!0,this.disableStructuredClone=!1,this.kernel=new dt(e),g(this.kernel,pe,t=>{if(this.onMessageToView!=null){let{type:r,uuid:i,traverseChildren:n}=t,o=structuredClone(t.data,{transfer:t.transferables});this.onMessageToView({type:r,uuid:i,data:o,traverseChildren:n})}})}start(){return Promise.resolve()}applyChangeTrail(e,t){let r={changeTrail:this.disableStructuredClone?e:Rs(e)},i;try{this.kernel.run(r),i=Promise.resolve()}catch(n){i=Promise.reject(n)}return i}async importScript(e){let t=await import(pt(e));t[Rt]&&await this.importModule(t[Rt])}async importModule(e){return Wt(this.kernel,e,this.#e)}destroy(){this.kernel.destroy(),this.registry.clear(),this.#e.clear()}};function Ft(s){let e=new Blob([s],{type:"text/javascript"}),t=URL.createObjectURL(e),r=new Worker(t);return URL.revokeObjectURL(t),r}function zt(){return Ft('var Ps=Object.defineProperty;var Ke=Object.getOwnPropertySymbols;var Mt=Object.prototype.hasOwnProperty,Tt=Object.prototype.propertyIsEnumerable;var js=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Dt=e=>{throw TypeError(e)};var it=(e,t,s)=>t in e?Ps(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,at=(e,t)=>{for(var s in t||(t={}))Mt.call(t,s)&&it(e,s,t[s]);if(Ke)for(var s of Ke(t))Tt.call(t,s)&&it(e,s,t[s]);return e};var Lt=(e,t)=>{var s={};for(var r in e)Mt.call(e,r)&&t.indexOf(r)<0&&(s[r]=e[r]);if(e!=null&&Ke)for(var r of Ke(e))t.indexOf(r)<0&&Tt.call(e,r)&&(s[r]=e[r]);return s};var c=(e,t,s)=>it(e,typeof t!="symbol"?t+"":t,s),nt=(e,t,s)=>t.has(e)||Dt("Cannot "+s);var i=(e,t,s)=>(nt(e,t,"read from private field"),s?s.call(e):t.get(e)),g=(e,t,s)=>t.has(e)?Dt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,s),u=(e,t,s,r)=>(nt(e,t,"write to private field"),r?r.call(e,s):t.set(e,s),s),m=(e,t,s)=>(nt(e,t,"access private method"),s);var Rt=(e,t,s,r)=>({set _(a){u(e,t,a,s)},get _(){return i(e,t,r)}});var ot=function(e,t){this[0]=e,this[1]=t},Nt=(e,t,s)=>{var r=(n,h,l,d)=>{try{var p=s[n](h),f=(h=p.value)instanceof ot,v=p.done;Promise.resolve(f?h[0]:h).then(E=>f?r(n==="return"?n:"next",h[1]?{done:E.done,value:E.value}:E,l,d):l({value:E,done:v})).catch(E=>r("throw",E,l,d))}catch(E){d(E)}},a=n=>o[n]=h=>new Promise((l,d)=>r(n,h,l,d)),o={};return s=s.apply(e,t),o[js("asyncIterator")]=()=>o,a("next"),a("throw"),a("return"),o};var xt;(function(e){e[e.StructuralChanges=1]="StructuralChanges",e[e.ContentUpdates=2]="ContentUpdates",e[e.Removal=3]="Removal"})(xt||(xt={}));var K;(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"})(K||(K={}));var Mr=Symbol.for("ShadowEntsGlobalNS"),Ms="configure",Ts="changeTrail",Ds="destroy",Ls="loaded",zt="appliedChangeTrail",ht="importedModule",Rs="destroyed",yt="messageToView",lt="shadowObjects",z="ConsoleLogger",M=`${z}Storage`,Xt,Zt,Ht,Ns=!!((Ht=(Zt=(Xt=globalThis.location)==null?void 0:Xt.host)==null?void 0:Zt.startsWith("localhost"))!=null&&Ht),ze="localStorage"in globalThis,Ye=Symbol.for(z),Vt=!1,Ft=e=>{if(typeof e=="boolean")return e;switch(e.toLowerCase()){case"true":case"yes":case"on":return!0;default:return!1}},pt=e=>[ze?z:void 0,...Array.isArray(e)?e:[e]].filter(Boolean).join(".");function dt(e,t=void 0,s){var o;let r=pt(e),a=ze?localStorage.getItem(r):(o=globalThis[M])==null?void 0:o[r];return a!=null?t(a):s}function Te(e,t){ze?localStorage.setItem(pt(e),t):(globalThis[M]==null&&(globalThis[M]={},console.debug(`${z}: Initialize`,{[M]:globalThis[M]})),globalThis[M][pt(e)]=t)}var de,Le,y,xs=(y=class{constructor(t){g(this,de);this.enable=!0,this.namespace=(t||"").trim()||z,Vt||(y.loadConfig(),Vt=!0);let s=[this.namespace,"enable"];this.enable=dt(s,Ft,this.enable),Te(s,ze?this.enable?"true":"false":this.enable)}static get isEnabled(){return y.sharedConfig.enable}static get isDebug(){return y.sharedConfig.enable&&y.sharedConfig.debug}static loadConfig(){var t,s,r;ze?(["enable","debug","info","warn"].forEach(a=>{this.sharedConfig[a]=dt(a,Ft,this.sharedConfig[a])}),["debug","info","warn","error"].forEach(a=>{this.sharedStyles[a]=dt(["styles",a],void 0,this.sharedStyles[a])}),y.isDebug&&console.debug(`${z}: Load config from localStorage`,y.sharedConfig),(t=globalThis[z])!=null&&t[Ye]||((s=globalThis[z])!=null||(globalThis[z]={[Ye]:!0,get enable(){return y.sharedConfig.enable},set enable(a){y.sharedConfig.enable=a,Te("enable",a?"true":"false")},get debug(){return y.sharedConfig.debug},set debug(a){y.sharedConfig.debug=a,Te("debug",a?"true":"false")},get info(){return y.sharedConfig.info},set info(a){y.sharedConfig.info=a,Te("info",a?"true":"false")},get warn(){return y.sharedConfig.warn},set warn(a){y.sharedConfig.warn=a,Te("warn",a?"true":"false")}}))):(r=globalThis[M])!=null&&r[Ye]||(globalThis[M]=at(at({[Ye]:!0},y.sharedConfig),globalThis[M]),y.sharedConfig=globalThis[M],y.isDebug&&console.debug(`${z}: Load config from ${M}`,globalThis[M]))}get isEnabled(){return this.enable&&y.sharedConfig.enable}get isDebug(){return this.isEnabled&&y.sharedConfig.debug}get isInfo(){return this.isEnabled&&y.sharedConfig.info}get isWarn(){return this.isEnabled&&y.sharedConfig.warn}debug(...t){m(this,de,Le).call(this,"debug",y.sharedStyles.debug,t)}info(...t){m(this,de,Le).call(this,"info",y.sharedStyles.info,t)}warn(...t){m(this,de,Le).call(this,"warn",y.sharedStyles.warn,t)}error(...t){m(this,de,Le).call(this,"error",y.sharedStyles.error,t)}},de=new WeakSet,Le=function(t,s,r){console[t](`%c${this.namespace}`,s,...r)},y.sharedConfig={enable:Ns,debug:!1,info:!0,warn:!0,"styles.debug":"color: #111; background: #999; display: inline-block; padding: 0 0.25em; margin: 0; border-radius: 0.25em","styles.info":"color: #020; background: #8a8; display: inline-block; padding: 0 0.25em; margin: 0; border-radius: 0.25em","styles.warn":"color: #fa0; background: #a98; display: inline-block; padding: 0 0.25em; margin: 0; border-radius: 0.25em","styles.error":"color: #ff0; background: #a00; display: inline-block; padding: 0 0.25em; margin: 0; border-radius: 0.25em"},y.sharedStyles={get debug(){return y.sharedConfig["styles.debug"]},set debug(t){y.sharedConfig["styles.debug"]=t},get info(){return y.sharedConfig["styles.info"]},set info(t){y.sharedConfig["styles.info"]=t},get warn(){return y.sharedConfig["styles.warn"]},set warn(t){y.sharedConfig["styles.warn"]=t},get error(){return y.sharedConfig["styles.error"]},set error(t){y.sharedConfig["styles.error"]=t}},y),pe="*",os=1,kt=2,At=4,oe=Symbol.for("eventize"),zs="[eventize]",_e=e=>e===pe,hs=e=>{switch(typeof e){case"string":case"symbol":return!0;default:return!1}},ls=typeof console<"u",Vs=ls?console[console.warn?"warn":"log"].bind(console,zs):()=>{},Fs=(e,t,s)=>(Object.defineProperty(e,t,{value:s,configurable:!0}),e),Is=0,ds=class{constructor(){c(this,"events",new Map);c(this,"eventNames",new Set)}static publish(e){e.sort((t,s)=>t.order-s.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:Is++})}isKnown(e){return this.eventNames.has(e)}emit(e,t,s=[]){if(_e(e))this.eventNames.forEach(r=>this.emit(r,t,s));else if(this.events.has(e)){let{order:r,args:a}=this.events.get(e);s.push({order:r,emit:()=>t.apply(e,a)})}return s}},vt=(e,t,s,r)=>{if(typeof t=="function"){let a=t.apply(e,s);a!=null&&(r==null||r(a))}},Us=(e,t,s,r)=>vt(t,t.emit,[e].concat(s),r),Gs=e=>{switch(typeof e){case"function":return os;case"string":case"symbol":return kt;case"object":return At}},$s=0,Bs=()=>++$s,us=class{constructor(e,t,s,r=null){c(this,"id");c(this,"eventName");c(this,"isCatchEmAll");c(this,"priority");c(this,"listener");c(this,"listenerObject");c(this,"listenerType");c(this,"callAfterApply");c(this,"isRemoved");c(this,"refCount");this.id=Bs(),this.eventName=e,this.isCatchEmAll=_e(e),this.listener=s,this.listenerObject=r,this.priority=t,this.listenerType=Gs(s),this.callAfterApply=void 0,this.isRemoved=!1,this.refCount=1}isEqual(e,t=null){if(e===this)return!0;let s=typeof e;return s==="number"&&e===this.id?!0:t===null&&(s==="string"||s==="symbol")?e===pe||e===this.eventName:this.listener===e&&this.listenerObject===t}apply(e,t,s){if(this.isRemoved)return;let{listener:r,listenerObject:a}=this;switch(this.listenerType){case os:vt(a,r,t,s),this.callAfterApply&&this.callAfterApply();break;case kt:vt(a,a[r],t,s),this.callAfterApply&&this.callAfterApply();break;case At:{let o=r[e];if(this.isCatchEmAll||this.eventName===e){if(typeof o=="function"){let n=o.apply(r,t);n!=null&&(s==null||s(n))}else Us(e,r,t,s);this.callAfterApply&&this.callAfterApply()}break}}}},Ws=(e,t)=>e.priority!==t.priority?t.priority-e.priority:e.id-t.id,It=e=>e==null?void 0:e.slice(0),Ut=(e,t)=>{let s=e.indexOf(t);s>-1&&e.splice(s,1)},qs=e=>e===At||e===kt,mt=(e,t,s)=>{let r=e.findIndex(a=>a.isEqual(t,s));r>-1&&(e[r].isRemoved=!0,e.splice(r,1))},Qe=(e,t,s)=>{let r=[];for(let a of e)(t==null&&a.listenerObject===s||a.eventName===t&&a.listener===s)&&r.push(a);for(let a of r)mt(e,a,void 0)},ut=e=>{e&&(e.forEach(t=>{t.isRemoved=!0}),e.length=0)},Js=(e,t)=>e.listenerType===t.listenerType?e.priority===t.priority&&e.eventName===t.eventName&&e.listenerObject===t.listenerObject&&e.listener===t.listener:!1,Ks=(e,t)=>{if(qs(e.listenerType))return t.find(s=>Js(e,s))},Ys=(e,t)=>{let s=Ks(e,t);return s?(s.refCount+=1,s):(t.push(e),t.sort(Ws),e)},Qs=class{constructor(){c(this,"namedListeners");c(this,"catchEmAllListeners");c(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 Ys(e,e.isCatchEmAll?this.catchEmAllListeners:this.getListenersForEventName(e.eventName))}remove(e,t,s=!1){t==null&&Array.isArray(e)?e.forEach(r=>this.remove(r,null,s)):e==null||t==null&&_e(e)?this.removeAllListeners():t==null&&hs(e)?ut(this.namedListeners.get(e)):e instanceof us?e.isRemoved||(e.refCount-=1,e.refCount<1&&(e.isRemoved=!0,this.namedListeners.forEach(r=>Ut(r,e)),Ut(this.catchEmAllListeners,e))):s?_e(e)?Qe(this.catchEmAllListeners,pe,e):this.namedListeners.forEach(r=>Qe(r,e,t)):(this.namedListeners.forEach(r=>{mt(r,e,t),Qe(r,void 0,e)}),mt(this.catchEmAllListeners,e,t),Qe(this.catchEmAllListeners,void 0,e))}removeAllListeners(){this.namedListeners.forEach(e=>ut(e)),this.namedListeners.clear(),ut(this.catchEmAllListeners)}forEach(e,t){let s=It(this.catchEmAllListeners),r=It(this.namedListeners.get(e));if(e===pe||!r||r.length===0)s.forEach(t);else if(s.length===0)r.forEach(t);else{let a=r.length,o=s.length,n=0,h=0;for(;n<a||h<o;){if(n<a){let l=r[n];if(h>=o||l.priority>=s[h].priority){t(l),++n;continue}}h<o&&(t(s[h]),++h)}}}getSubscriptionCount(){let e=this.catchEmAllListeners.length;for(let t of this.namedListeners.values())e+=t.length;return e}},je=e=>!!(e&&e[oe]);function Ve(e){if(je(e))return e;let t=new Qs,s=new ds;return Fs(e,oe,{keeper:s,store:t}),e}var cs={Max:Number.POSITIVE_INFINITY,AAA:1e9,BB:1e6,C:1e3,Default:0,Low:-1e4,Min:Number.NEGATIVE_INFINITY},Xs=(e,t,s,r,a,o,n)=>{let h=e.add(new us(s,r,a,o));return t.emit(s,h,n),h},Zs=(e,t,s,r)=>{let a=s.length,o=typeof s[0],n,h,l,d;if(a>=2&&a<=3&&o==="number"?(n=pe,[h,l,d]=s):a>=3&&a<=4&&typeof s[1]=="number"?[n,h,l,d]=s:(h=cs.Default,o==="string"||o==="symbol"||Array.isArray(s[0])?[n,l,d]=s:(n=pe,[l,d]=s)),!l&&ls)throw Vs("called with insufficient arguments!",s),"subscribeTo() called with insufficient arguments!";let p=f=>v=>Xs(e,t,v,f,l,d,r);return Array.isArray(n)?n.map(f=>Array.isArray(f)?p(f[1])(f[0]):p(h)(f)):p(h)(n)},fs=(e,t,s)=>{let r=[],a=Zs(e,t,s,r);return ds.publish(r),a},Gt=e=>t=>{t.callAfterApply=()=>{e==null||e()}},gs=(e,t)=>Object.assign(()=>T(e,t),Array.isArray(t)?{listeners:t}:{listener:t}),ys=(e,t,s,r)=>{let{store:a,keeper:o}=e[oe];Array.isArray(t)?t.forEach(n=>{a.forEach(n,h=>h.apply(n,s,r)),o.retain(n,s)}):t!==pe&&(a.forEach(t,n=>{n.apply(t,s,r)}),o.retain(t,s))},Z=(e,...t)=>{let s=Ve(e),{store:r,keeper:a}=s[oe];return gs(s,fs(r,a,t))},D=(e,...t)=>{let s=Ve(e),{store:r,keeper:a}=s[oe],o=fs(r,a,t),n=gs(s,o),h=!1,l=()=>{h||(n(),h=!0)};return Array.isArray(o)?o.forEach(Gt(l)):Gt(l)(o),l},Hs=(e,t)=>new Promise(s=>{D(e,t,s)}),T=(e,t,s)=>{if(!je(e))throw new Error("object is not eventized");let{store:r,keeper:a}=e[oe],o=typeof t,n=s!=null&&(o==="string"||o==="symbol");r.remove(t,s,n),Array.isArray(t)?a.remove(t.filter(h=>typeof h=="string")):hs(t)&&a.remove(t)},b=(e,t,...s)=>{if(!je(e))throw new Error("object is not eventized");ys(e,t,s)},_s=(e,t,...s)=>{if(!je(e))throw new Error("object is not eventized");let r=[];return ys(e,t,s,a=>{r.push(a)}),r=r.map(a=>Array.isArray(a)?Promise.all(a):Promise.resolve(a)),r.length>0?Promise.all(r):Promise.resolve()},Ot=(e,t)=>{let s=Ve(e),{keeper:r}=s[oe];r.add(t)},et=(e,t)=>{if(!je(e))throw new Error("object is not eventized");let{keeper:s}=e[oe];s.clear(t)},ae=(()=>{let e=(t={})=>Ve(t);return e.inject=(t={})=>(t=Ve(t),Object.assign(t,{on:(...s)=>Z(t,...s),once:(...s)=>D(t,...s),onceAsync:s=>Hs(t,s),off:(s,r)=>T(t,s,r),emit:(s,...r)=>b(t,s,...r),emitAsync:(s,...r)=>_s(t,s,...r),retain:s=>Ot(t,s),retainClear:s=>et(t,s)}),t),e.is=je,e})(),Ne=ae(),Fe=ae(),we=ae(),gt,Ge,Re=(gt=class{constructor(){g(this,Ge,new Set)}batch(e){i(this,Ge).add(e)}run(){b(we,Array.from(i(this,Ge)))}},Ge=new WeakMap,c(gt,"current"),gt),er=()=>Re.current;function tt(e){let t=Re.current;t?t=void 0:t=Re.current=new Re;try{e()}finally{t&&(Re.current=void 0,t.run())}}var tr=0;function ps(){return tr>0}var q=Symbol.for("signal"),me=Symbol.for("effect"),$t=Symbol.for("destroySignal"),Bt=Symbol.for("createEffect"),sr=Symbol.for("destroyEffect"),De="value",Wt="mute",qt="unmute",xe="destroy",H=new Map,V,_,R,F,I,ue,ee,C,U,ie,st=(ie=class{constructor(t){g(this,V,new Set);g(this,_,new Set);g(this,R,new Map);g(this,F,new WeakMap);g(this,I,new Map);g(this,ue,new Set);g(this,ee,new Set);g(this,C,!1);g(this,U);if(t!=null&&t instanceof ie&&!i(t,C))return t;if(t!=null||(t=this),H.has(t))return H.get(t);H.set(t,this),ae(this)}static get(t){if(t!=null)return t instanceof ie&&!i(t,C)?t:H.get(t)}static findOrCreate(t){if(t==null)throw new Error("Cannot create a group with a null object");return new ie(t)}static destroy(t){var s;(s=H.get(t))==null||s.destroy()}static clear(){for(let t of H.values())t.destroy();H.clear()}attachGroup(t){if(i(this,C))throw new Error("Cannot attach a group to a destroyed group");if(t===this)throw new Error("Cannot attach a group to itself");return i(this,V).add(t),i(t,U)&&i(t,U)!==this&&i(i(t,U),V).delete(t),u(t,U,this),t}detachGroup(t){if(i(this,C))throw new Error("Cannot detach a group from a destroyed group");return t!==this&&i(this,V).has(t)&&(i(this,V).delete(t),u(t,U,void 0)),t}attachSignal(t){if(i(this,C))throw new Error("Cannot attach a signal to a destroyed group");let s=A(t);if(s!=null&&s.destroyed)throw new Error("Cannot attach a destroyed signal to a group");return s&&i(this,_).add(s),t}attachSignalByName(t,s){if(i(this,C))throw new Error("Cannot attach a named signal to a destroyed group");if(s){this.attachSignal(s);let r=A(s);i(this,R).set(t,r),i(this,I).has(t)?i(this,I).get(t).push(r):i(this,I).set(t,[r]),i(this,F).has(r)?i(this,F).get(r).add(t):i(this,F).set(r,new Set([t]))}else i(this,R).delete(t);return s}hasSignal(t){var s;return i(this,R).has(t)||((s=i(this,U))==null?void 0:s.hasSignal(t))}signal(t){var s,r,a;if(!i(this,C))return(a=(s=i(this,R).get(t))==null?void 0:s.object)!=null?a:(r=i(this,U))==null?void 0:r.signal(t)}detachSignal(t){if(i(this,C))return t;let s=A(t);if(s&&(i(this,_).delete(s),i(this,F).has(s))){let r=i(this,F).get(s);for(let a of r)if(i(this,I).has(a)){let o=i(this,I).get(a);o.splice(o.indexOf(s),1),o.length===0?(i(this,R).delete(a),i(this,I).delete(a)):i(this,R).get(a)===s&&i(this,R).set(a,o.at(-1))}r.clear(),i(this,F).delete(s)}return t}attachEffect(t){if(i(this,C))throw new Error("Cannot attach an effect to a destroyed group");return i(this,ue).add(t),t}runEffects(){if(i(this,C))throw new Error("Cannot run effects on a destroyed group");for(let t of i(this,ue))t.run();for(let t of i(this,V))t.runEffects()}attachLink(t){if(i(this,C))throw new Error("Cannot attach a link to a destroyed group");if(t!=null&&t.isDestroyed)throw new Error("Cannot attach a destroyed link to a group");return t&&i(this,ee).add(t),t}detachLink(t){return i(this,C)||t&&i(this,ee).delete(t),t}destroy(){var t;if(!i(this,C)){b(this,xe,this),T(this);for(let s of i(this,V))s.destroy();for(let s of i(this,ue))s.destroy();for(let s of i(this,_))le(s);for(let s of i(this,ee))s.destroy();i(this,V).clear(),i(this,_).clear(),i(this,R).clear(),i(this,I).clear(),i(this,ue).clear(),i(this,ee).clear(),(t=i(this,U))==null||t.detachGroup(this),H.delete(this),u(this,C,!0),u(this,V,void 0),u(this,_,void 0),u(this,F,void 0),u(this,R,void 0),u(this,I,void 0),u(this,F,void 0),u(this,ee,void 0),Object.freeze(this)}}},V=new WeakMap,_=new WeakMap,R=new WeakMap,F=new WeakMap,I=new WeakMap,ue=new WeakMap,ee=new WeakMap,C=new WeakMap,U=new WeakMap,ie),_t,rr=(_t=me,class{constructor(e){c(this,_t);c(this,"run",()=>{var e;return(e=this[me])==null?void 0:e.run()});c(this,"destroy",()=>{var e;(e=this[me])==null||e.destroy(),this[me]=void 0});this[me]=e,D(e,bs.Destroy,()=>{this[me]=void 0})}}),$e,Be,es,vs=(es=class{constructor(e="id",t=1){g(this,$e);g(this,Be);u(this,$e,e),u(this,Be,t)}make(){return Symbol(`${i(this,$e)}${Rt(this,Be)._++}`)}},$e=new WeakMap,Be=new WeakMap,es),bt=[],ms=()=>bt.at(-1),ir=(e,t)=>{bt.push(e);try{return t()}finally{bt.pop()}},ar=e=>e!=null&&typeof e.then=="function",k,te,se,ce,fe,Ee,bs=(k=class{constructor(t,s){c(this,"id");c(this,"callback");g(this,te);g(this,se,new Set);g(this,ce,new Set);c(this,"parentEffect");c(this,"childEffects",[]);c(this,"curChildEffectSlot",0);c(this,"autorun",!0);c(this,"shouldRun",!0);g(this,fe);g(this,Ee,!1);c(this,"run",()=>{if(i(this,Ee)||!this.shouldRun)return;let t=er();t?t.batch(this.id):(this.runCleanupCallback(),this.curChildEffectSlot=0,this.shouldRun=!1,this.hasStaticDeps()?u(this,te,this.callback()):u(this,te,ir(this,this.callback)))});c(this,"destroy",()=>{i(this,Ee)||(b(this,k.Destroy,this),T(this),b(we,sr,this),this.runCleanupCallback(),T(Ne,this),T(we,this),T(Fe,this),u(this,Ee,!0),i(this,se).clear(),i(this,ce).clear(),this.childEffects.forEach(t=>{t.destroy()}),this.childEffects.length=0,--k.count)});var a;ae(this),this.callback=t;let r;(s==null?void 0:s.attach)!=null&&(r=st.findOrCreate(s.attach),r.attachEffect(this)),this.autorun=(a=s==null?void 0:s.autorun)!=null?a:!0,u(this,fe,s!=null&&s.dependencies?s.dependencies.map(o=>{switch(typeof o){case"string":case"symbol":return r.signal(o);default:return o}}):void 0),this.id=k.idGen.make(),Z(we,this.id,"recall",this),++k.count}hasStaticDeps(){return i(this,fe)!=null&&i(this,fe).length>0}saveSignalsFromDeps(){for(let t of i(this,fe))this.whenSignalIsRead(A(t).id)}static createEffect(t,s,r){let a=Array.isArray(s)?s:void 0,o=a?r!=null?r:{dependencies:a}:s;o&&a&&(o.dependencies=a);let n,h=ms();return h!=null?(n=h.getCurrentChildEffect(),n==null&&(n=new k(t,o),h.attachChildEffect(n),b(we,Bt,n)),h.curChildEffectSlot++):(n=new k(t,o),b(we,Bt,n)),n.hasStaticDeps()?n.saveSignalsFromDeps():n.autorun&&n.run(),new rr(n)}getCurrentChildEffect(){return this.childEffects[this.curChildEffectSlot]}attachChildEffect(t){this.childEffects.push(t),this.parentEffect=this}recall(){this.shouldRun=!0,this.autorun&&this.run()}whenSignalIsRead(t){i(this,se).has(t)||(i(this,se).add(t),Z(Ne,t,"recall",this),D(Fe,t,$t,this))}[$t](t){!i(this,ce).has(t)&&i(this,se).has(t)&&(i(this,ce).add(t),T(Ne,t,this),i(this,ce).size===i(this,se).size&&this.destroy())}runCleanupCallback(){if(i(this,te)!=null){let t=i(this,te);u(this,te,void 0),ar(t)?Promise.resolve(t).then(s=>{typeof s=="function"&&s()}):t()}}},te=new WeakMap,se=new WeakMap,ce=new WeakMap,fe=new WeakMap,Ee=new WeakMap,c(k,"idGen",new vs("ef")),c(k,"Destroy","destroy"),c(k,"count",0),k),rt=(...e)=>bs.createEffect(...e),Ie=new WeakMap,nr=e=>{let t=Ie.get(e);return t||(t={},Ie.set(e,t)),t},Ue=(e,t)=>{var s,r;return(r=(s=Ie.get(e))==null?void 0:s.signals)==null?void 0:r.get(t)},or=(e,t,s)=>{var a;let r=nr(e);(a=r.signals)!=null||(r.signals=new Map),r.signals.set(t,s)};function hr(...e){for(let t of e)if(Ie.has(t)){let s=Ie.get(t);if(s.signals){for(let r of s.signals.values())le(r);s.signals.clear(),s.signals=void 0}}}function lr(e){let t=A(jt(e)?e:Ue(...e));t!=null&&!t.muted&&!t.destroyed&&wt(t.id,t.value,{touch:!0})}function Pt(e){var t,s;return jt(e)?(t=A(e))==null?void 0:t.value:(s=A(Ue(...e)))==null?void 0:s.value}var ts,dr=(ts=q,class{constructor(e){c(this,ts);this[q]=e}get get(){return this[q].reader}get set(){return this[q].writer}get value(){return Pt(this.get)}set value(e){this.set(e)}onChange(e){let{destroy:t}=rt(()=>e(this.value),[this.get]);return t}get muted(){return this[q].muted}set muted(e){this[q].muted=e}touch(){lr(this)}destroy(){le(this)}}),ur=new vs("si");function Jt(e){var t;ps()||((t=ms())==null||t.whenSignalIsRead(e))}function wt(e,t,s){ps()||b(Ne,e,t,s)}var jt=e=>e!=null&&e[q]!=null,cr=e=>{let t=s=>{var r;return s?rt(()=>(e.destroyed||Jt(e.id),s(e.value)),[t]):e.destroyed||((r=e.beforeRead)==null||r.call(e),Jt(e.id)),e.value};return Object.defineProperty(t,q,{value:e}),t},ge,G,ws=(ge=class{constructor(t,s){c(this,"id");c(this,"lazy");c(this,"compare");c(this,"beforeRead");c(this,"muted",!1);c(this,"destroyed",!1);g(this,G);c(this,"valueFn");c(this,"reader");c(this,"writer",(t,s)=>{var o,n,h,l;let r=(o=s==null?void 0:s.lazy)!=null?o:!1,a=(h=(n=s==null?void 0:s.compare)!=null?n:this.compare)!=null?h:(d,p)=>d===p;if((r!==this.lazy||r&&t!==this.valueFn||!r&&!a(t,i(this,G)))&&(r?(u(this,G,void 0),this.valueFn=t,this.lazy=!0):(u(this,G,t),this.valueFn=void 0,this.lazy=!1),!this.muted&&!this.destroyed)){wt(this.id,i(this,G));return}(l=s==null?void 0:s.touch)!=null&&l&&wt(this.id,i(this,G),{touch:!0})});c(this,"object");this.id=ur.make(),++ge.instanceCount,this.lazy=t,this.lazy?(this.value=void 0,this.valueFn=s):(this.value=s,this.valueFn=void 0),this.reader=cr(this),this.object=new dr(this)}get[q](){return this}get value(){return this.lazy&&(u(this,G,this.valueFn()),this.valueFn=void 0,this.lazy=!1),i(this,G)}set value(t){u(this,G,t)}},G=new WeakMap,c(ge,"instanceCount",0),ge),A=e=>e==null?void 0:e[q];function J(e=void 0,t){var r;let s;if(jt(e))s=A(e);else{let a=(r=t==null?void 0:t.lazy)!=null?r:!1;s=new ws(a,e),s.beforeRead=t==null?void 0:t.beforeRead,s.compare=t==null?void 0:t.compare}return(t==null?void 0:t.attach)!=null&&st.findOrCreate(t.attach).attachSignal(s),s.object}var le=(...e)=>{for(let t of e){let s=A(t);s!=null&&!s.destroyed&&(s.destroyed=!0,s.beforeRead=void 0,--ws.instanceCount,b(Fe,s.id,s.id))}},S,Se,ss,Cs=(ss=class{constructor(e){g(this,S,!1);g(this,Se);c(this,"source");c(this,"lastValue");c(this,"isDestroyed",!1);ae(this),this.source=A(e),u(this,Se,Z(Ne,this.source.id,(t,s)=>{!i(this,S)&&!this.isDestroyed&&((s==null?void 0:s.touch)===!0?this.touch():this.write())})),D(Fe,this.source.id,()=>this.destroy())}attach(e){let t=st.findOrCreate(e);return t.attachLink(this),D(this,xe,()=>{t.detachLink(this)}),t}nextValue(){return new Promise((e,t)=>{let s=[],r=()=>s.forEach(a=>{a()});s.push(D(this,De,a=>{r(),e(a)}),D(this,xe,()=>{r(),t()}))})}asyncValues(e){return Nt(this,null,function*(){let t=0;for(;!this.isDestroyed;)try{let s=yield new ot(this.nextValue());if(e&&e(s,t++))break;Ot(this,De),yield s}catch(s){break}et(this,De)})}destroy(){var e;this.isDestroyed||((e=i(this,Se))==null||e.call(this),u(this,Se,void 0),b(this,xe,this),et(this,De),T(this),this.lastValue=void 0,this.isDestroyed=!0,Object.freeze(this))}get isMuted(){return i(this,S)}mute(){return!this.isDestroyed&&!i(this,S)&&(u(this,S,!0),b(this,Wt,this)),this}unmute(){return!this.isDestroyed&&i(this,S)&&(u(this,S,!1),b(this,qt,this)),this}toggle(){return this.isDestroyed||(u(this,S,!i(this,S)),b(this,i(this,S)?Wt:qt,this)),i(this,S)}updateValue(e){if(!i(this,S)&&!this.isDestroyed){let{value:t}=this.source;e(t),b(this,De,t),this.lastValue=t}}},S=new WeakMap,Se=new WeakMap,ss),fr=class extends Cs{constructor(t,s){super(t);c(this,"target");this.target=A(s),D(Fe,this.target.id,()=>this.destroy()),this.touch()}touch(){return this.updateValue(t=>{this.target.writer(t,{touch:!0})}),this}write(){this.updateValue(t=>{this.target.writer(t)})}},gr=class extends Cs{constructor(t,s){super(t);c(this,"target");this.target=s,this.touch()}touch(){return this.updateValue(t=>{this.target(t)}),this}write(){this.updateValue(t=>{this.target(t)})}},Xe=new Map;function ct(e,t,s){var d;let r=A(e),a;if(Xe.has(r)){a=Xe.get(r);let p=(d=A(t))!=null?d:t;if(a.has(p))return a.get(p)}else a=new Map,Xe.set(r,a);let o=A(t),n=o!=null?new fr(e,o):new gr(e,t),h=s==null?void 0:s.attach;h&&n.attach(h);let l=o!=null?o:t;return a.set(l,n),D(n,xe,()=>{a.delete(l),a.size===0&&Xe.delete(r)}),n}var O,ke,yr=(ke=class{constructor(){g(this,O,new Map)}static fromProps(t,s){let r=new ke,a=s?s.map(o=>[o,t[o]]):Object.entries(t);for(let[o,n]of a)i(r,O).set(o,J(n));return r}keys(){return i(this,O).keys()}signals(){return i(this,O).values()}entries(){return i(this,O).entries()}clear(){for(let t of i(this,O).values())t.destroy();i(this,O).clear()}has(t){return i(this,O).has(t)}get(t){if(!i(this,O).has(t)){let s=J();return i(this,O).set(t,s),s}return i(this,O).get(t)}update(t){t.size&&tt(()=>{for(let[s,r]of t.entries())this.get(s).set(r)})}updateFromProps(t,s){tt(()=>{let r=s?s.map(a=>[a,t[a]]):Object.entries(t);for(let[a,o]of r)this.get(a).set(o)})}},O=new WeakMap,ke);function pr(e,t,s,r,a,o){function n(Me){if(Me!==void 0&&typeof Me!="function")throw new TypeError("Function expected");return Me}for(var h=r.kind,l=h==="getter"?"get":h==="setter"?"set":"value",d=!t&&e?r.static?e:e.prototype:null,p=t||(d?Object.getOwnPropertyDescriptor(d,r.name):{}),f,v=!1,E=s.length-1;E>=0;E--){var Je={};for(var ve in r)Je[ve]=ve==="access"?{}:r[ve];for(var ve in r.access)Je.access[ve]=r.access[ve];Je.addInitializer=function(Me){if(v)throw new TypeError("Cannot add initializers after decoration has completed");o.push(n(Me||null))};var he=(0,s[E])(h==="accessor"?{get:p.get,set:p.set}:p[l],Je);if(h==="accessor"){if(he===void 0)continue;if(he===null||typeof he!="object")throw new TypeError("Object expected");(f=n(he.get))&&(p.get=f),(f=n(he.set))&&(p.set=f),(f=n(he.init))&&a.unshift(f)}else(f=n(he))&&(h==="field"?a.unshift(f):p[l]=f)}d&&Object.defineProperty(d,r.name,p),v=!0}function Kt(e,t,s){for(var r=arguments.length>2,a=0;a<t.length;a++)s=r?t[a].call(e,s):t[a].call(e);return r?s:void 0}function vr(e){return function(t,s){var o;let r=(e==null?void 0:e.name)||s.name,a=!!((o=e==null?void 0:e.readAsValue)!=null&&o);return{get(){let n=Ue(this,r);if(n)return a?n.value:n.get()},set(n){var h;(h=Ue(this,r))==null||h.set(n)},init(n){let h=J(n,e);return or(this,r,h),st.findOrCreate(this).attachSignalByName(r,h),h.value}}}}var be="value",ft=(()=>{var r,a,o,n,Ct,Et,d;let e,t=[],s=[];return d=class{constructor(){g(this,n);g(this,r,[]);g(this,a);g(this,o,Kt(this,t,void 0));Kt(this,s),Ot(this,be),Ue(this,be).onChange(f=>b(this,be,f))}get value(){return i(this,o)}set value(f){u(this,o,f)}add(...f){for(let v of f)i(this,r).push(v);m(this,n,Et).call(this)}pop(){i(this,r).pop(),m(this,n,Et).call(this)}clear(){i(this,r).length=0,m(this,n,Ct).call(this)}dispose(){this.clear(),et(this,be),T(this),hr(this)}},r=new WeakMap,a=new WeakMap,o=new WeakMap,n=new WeakSet,Ct=function(){var f;(f=i(this,a))==null||f.destroy(),u(this,a,void 0)},Et=function(){m(this,n,Ct).call(this),u(this,a,rt(()=>{for(let f of i(this,r)){let v=Pt(f);if(v!=null){this.value=v;return}}this.value=void 0},i(this,r))),i(this,a).run()},(()=>{let f=typeof Symbol=="function"&&Symbol.metadata?Object.create(null):void 0;e=[vr({name:be})],pr(d,null,e,{kind:"accessor",name:"value",static:!1,private:!1,access:{has:v=>"value"in v,get:v=>v.value,set:(v,E)=>{v.value=E}},metadata:f},t,s),f&&Object.defineProperty(d,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:f})})(),d.Value=be,d})(),Yt="onCreate",Ce="onDestroy",mr="onParentChanged",br="onViewEvent",re,Ae,ye,$,N,P,Q,x,Oe,L,St,Ze,He,rs,wr=(rs=class{constructor(e,t){g(this,L);g(this,re);g(this,Ae);g(this,ye,new yr);g(this,$,new Map);g(this,N);g(this,P);g(this,Q,new Set);g(this,x,[]);g(this,Oe,0);u(this,re,e),u(this,Ae,t),D(this,Ce,cs.Min,this)}get kernel(){return i(this,re)}get uuid(){return i(this,Ae)}get order(){return i(this,Oe)}set order(e){i(this,Oe)!==e&&(u(this,Oe,e),i(this,N)&&this.parent.resortChildren())}get parentUuid(){return i(this,N)||void 0}set parentUuid(e){i(this,N)!==e&&(this.removeFromParent(),u(this,N,e||void 0),u(this,P,e?i(this,re).getEntity(e):void 0),i(this,P)&&i(this,P).addChild(this))}get parent(){return!i(this,P)&&i(this,N)&&u(this,P,i(this,re).getEntity(i(this,N))),i(this,P)}set parent(e){this.parentUuid=e==null?void 0:e.uuid}get hasParent(){return!!i(this,N)}get children(){return i(this,x)}traverse(e){e(this);for(let t of i(this,x))t.traverse(e)}onDestroy(){var e;i(this,ye).clear(),T(this);for(let t of i(this,$).values())t.unsubscribeFromPath(),(e=t.unsubscribeFromParent)==null||e.call(t),t.ctxPath.dispose(),t.inherited.destroy(),t.provide.destroy(),t.context.destroy();u(this,N,void 0),u(this,P,void 0),i(this,Q).clear(),i(this,x).length=0}addChild(e){var t;if(i(this,x).length===0){i(this,Q).add(e.uuid),i(this,x).push(e);return}if(i(this,Q).has(e.uuid))throw new Error(`child with uuid: ${e.uuid} already exists! parentUuid: ${this.uuid}`);i(this,Q).add(e.uuid),i(this,x).push(e),this.resortChildren();for(let[,s]of i(e,$))m(t=e,L,He).call(t,s)}resortChildren(){i(this,x).sort((e,t)=>e.order-t.order)}removeChild(e){i(this,Q).has(e.uuid)&&(i(this,Q).delete(e.uuid),i(this,x).splice(i(this,x).indexOf(e),1))}removeFromParent(){if(i(this,P)){i(this,P).removeChild(this),u(this,P,void 0),u(this,N,void 0);for(let[,e]of i(this,$))e.unsubscribeFromParent&&(e.unsubscribeFromParent(),e.unsubscribeFromParent=void 0)}}reSubscribeToParentContexts(){for(let[,e]of i(this,$))m(this,L,He).call(this,e)}dispatchMessageToView(e,t,s,r=!1){i(this,re).dispatchMessageToView({uuid:i(this,Ae),type:e,data:t,transferables:s,traverseChildren:r})}dispatchViewEvents(e){for(let{type:t,data:s}of e)b(this,br,t,s)}dispatchViewEvent(e,t){this.dispatchViewEvents([{type:e,data:t}])}getPropertyReader(e){return m(this,L,St).call(this,e).get}getPropertyWriter(e){return m(this,L,St).call(this,e).set}setProperties(e){tt(()=>{for(let[t,s]of e)this.setProperty(t,s)})}setProperty(e,t){this.getPropertyWriter(e)(t)}getProperty(e){return Pt(this.getPropertyReader(e))}propKeys(){return Array.from(i(this,ye).keys())}propEntries(){return Array.from(i(this,ye).entries()).map(([e,t])=>[e,t.value])}hasContext(e){return i(this,$).has(e)}useContext(e){return m(this,L,Ze).call(this,e).context.get}provideContext(e){return m(this,L,Ze).call(this,e).provide}},re=new WeakMap,Ae=new WeakMap,ye=new WeakMap,$=new WeakMap,N=new WeakMap,P=new WeakMap,Q=new WeakMap,x=new WeakMap,Oe=new WeakMap,L=new WeakSet,St=function(e){return i(this,ye).get(e)},Ze=function(e){let t=i(this,$).get(e);if(t==null){let s=J(),r=J(),a=J(),o=new ft;o.add(r.get,s.get);let n=Z(o,ft.Value,h=>{queueMicrotask(()=>{a.set(h)})});t={name:e,inherited:s,provide:r,context:a,ctxPath:o,unsubscribeFromPath:n},i(this,$).set(e,t),m(this,L,He).call(this,t)}return t},He=function(e){var t,s;if((t=e.unsubscribeFromParent)==null||t.call(e),e.unsubscribeFromParent=void 0,this.parent){let r=m(s=this.parent,L,Ze).call(s,e.name).ctxPath;e.inherited.set(r.value),e.unsubscribeFromParent=Z(r,ft.Value,a=>{e.inherited.set(a)})}else e.inherited.set(void 0)},rs);function Cr(e,t){e.indexOf(t)===-1&&e.push(t)}var X,j,is,Es=(is=class{constructor(){g(this,X,new Map);g(this,j,new Map)}static get(e){return e!=null?e:Er}define(e,t){i(this,X).has(e)?Cr(i(this,X).get(e).constructors,t):i(this,X).set(e,{token:e,constructors:[t]})}appendRoute(e,t){if(i(this,j).has(e)){let s=i(this,j).get(e);for(let r of t)s.add(r)}else i(this,j).set(e,new Set(t))}clearRoute(e){i(this,j).delete(e)}findTokensByRoute(e){let t=new Set([e]),s=i(this,j).has(e)?[...i(this,j).get(e)]:[];for(;s.length;){let r=s.shift();t.has(r)||(t.add(r),i(this,j).has(r)&&s.push(...Array.from(i(this,j).get(r)).filter(a=>!t.has(a))))}return Array.from(t)}findConstructors(e){let t=this.findTokensByRoute(e),s=new Set;for(let r of t){let a=i(this,X).get(r);if(a)for(let o of a.constructors)s.add(o)}return s.size>0?Array.from(s):void 0}hasToken(e){return i(this,X).has(e)}hasRoute(e){return i(this,j).has(e)}clear(){i(this,X).clear(),i(this,j).clear()}},X=new WeakMap,j=new WeakMap,is),Er=new Es,Y;(function(e){e[e.CreateAndDestroy=0]="CreateAndDestroy",e[e.JustCreate=1]="JustCreate",e[e.DestroyOnly=2]="DestroyOnly"})(Y||(Y={}));var Qt=e=>e.displayName||e.name,w,B,Pe,We,W,as,Sr=(as=class{constructor(e){g(this,w);g(this,B);g(this,Pe);g(this,We);g(this,W);this.logger=new xs("Kernel"),u(this,w,new Map),u(this,B,new Set),u(this,W,!0),ae(this),this.registry=Es.get(e)}getEntity(e){var s;let t=(s=i(this,w).get(e))==null?void 0:s.entity;if(!t)throw new Error(`entity with uuid "${e}" not found!`);return t}hasEntity(e){return i(this,w).has(e)}traverseLevelOrderBFS(e=!1){if(i(this,W)){let t=new Map,s=(r,a)=>{let o=this.getEntity(r);t.has(a)?t.get(a).push(o):t.set(a,[o]);for(let n of o.children)s(n.uuid,a+1)};i(this,B).forEach(r=>s(r,0)),u(this,Pe,Array.from(t.entries()).sort((r,a)=>r[0]-a[0]).map(([,r])=>r).flat()),u(this,We,i(this,Pe).slice().reverse()),u(this,W,!1)}return e?i(this,We):i(this,Pe)}getEntityGraph(){return Array.from(i(this,B)).map(e=>this.getEntityGraphNode(e))}getEntityGraphNode(e){if(!i(this,w).has(e))return;let{token:t,entity:s}=i(this,w).get(e);return{token:t,entity:s,props:Object.fromEntries(s.propEntries()),children:s.children.map(r=>this.getEntityGraphNode(r.uuid))}}upgradeEntities(){for(let e of this.traverseLevelOrderBFS(!0))this.updateShadowObjects(e.uuid,Y.DestroyOnly);for(let e of this.traverseLevelOrderBFS(!1))this.updateShadowObjects(e.uuid,Y.JustCreate)}run(e){tt(()=>{for(let t of e.changeTrail)this.parse(t)})}parse(e){switch(e.type){case K.CreateEntities:this.createEntity(e.uuid,e.token,e.parentUuid,e.order,e.properties),u(this,W,!0);break;case K.DestroyEntities:this.destroyEntity(e.uuid),u(this,W,!0);break;case K.SetParent:this.setParent(e.uuid,e.parentUuid,e.order),u(this,W,!0);break;case K.UpdateOrder:this.updateOrder(e.uuid,e.order),u(this,W,!0);break;case K.ChangeProperties:this.changeProperties(e.uuid,e.properties);break;case K.ChangeToken:this.changeToken(e.uuid,e.token);break;case K.SendEvents:this.dispatchEventsToEntity(e.uuid,e.events);break}}createEntity(e,t,s,r=0,a){let o=new wr(this,e);o.order=r;let n={token:t,entity:o,usedConstructors:new Map};i(this,w).set(e,n),s&&(o.parentUuid=s),o.hasParent||i(this,B).add(e),a&&o.setProperties(a),this.createShadowObjects(e)}destroyEntity(e){if(!i(this,w).has(e))return;let{entity:t,usedConstructors:s}=i(this,w).get(e);t.removeFromParent(),b(t,Ce,this),s.clear(),i(this,w).delete(t.uuid),i(this,B).delete(t.uuid)}setParent(e,t,s=0){let r=this.getEntity(e);r.parentUuid===t&&r.order===s||(r.removeFromParent(),r.order=s,r.parentUuid=t,r.hasParent?i(this,B).delete(e):i(this,B).add(e),r.reSubscribeToParentContexts(),queueMicrotask(()=>{this.logger.isDebug&&this.logger.debug("entity.onParentChanged",{uuid:e,parentUuid:t,order:s,entity:r}),b(r,mr,r)}))}updateOrder(e,t){this.getEntity(e).order=t}dispatchEventsToEntity(e,t){var s;(s=this.getEntity(e))==null||s.dispatchViewEvents(t)}changeProperties(e,t){this.getEntity(e).setProperties(t)}changeToken(e,t){if(!i(this,w).has(e))return;let s=i(this,w).get(e);s.token!==t&&(s.token=t,this.updateShadowObjects(e))}dispatchMessageToView(e){queueMicrotask(()=>{b(this,yt,e)})}updateShadowObjects(e,t=Y.CreateAndDestroy){let s=i(this,w).get(e),r=new Set(this.registry.findConstructors(s.token)),a=t===Y.CreateAndDestroy||t===Y.DestroyOnly,o=t===Y.CreateAndDestroy||t===Y.JustCreate;if(a){for(let[n,h]of s.usedConstructors)if(!r.has(n)){s.usedConstructors.delete(n);for(let l of h)this.destroyShadowObject(l,s.entity)}}if(o)for(let n of r)s.usedConstructors.has(n)||this.constructShadowObject(n,s)}constructShadowObject(e,t){let s=new Set,r=new Set,a=new Map,o=new Map,n=new Map,h=ae(new e({entity:t.entity,provideContext(l,d,p){let f=o.get(l);if(f===void 0){f=J(d,p?{compare:p}:void 0),o.set(l,f);let v=ct(f,t.entity.provideContext(l));r.add(v.destroy.bind(v))}return f},useContext(l,d){let p=a.get(l);if(p===void 0){p=J(void 0,d?{compare:d}:void 0).get,a.set(l,p);let f=ct(t.entity.useContext(l),p);r.add(f.destroy.bind(f))}return p},useProperty(l,d){let p=n.get(l);if(p===void 0){p=J(void 0,d?{compare:d}:void 0).get,n.set(l,p);let f=ct(t.entity.getPropertyReader(l),p);r.add(f.destroy.bind(f))}return p},createEffect(...l){let d=rt(...l);return r.add(d.destroy),d},createSignal(...l){let d=J(...l);return r.add(()=>{le(d)}),d},on(...l){let d=Z(...l);return r.add(d),d},once(...l){let d=D(...l);return r.add(d),d},onDestroy(l){s.add(l)}}));return this.logger.isInfo&&this.logger.info("create shadow-object",Qt(e),{shadowObject:h,entity:t.entity}),D(h,Ce,()=>{this.logger.isInfo&&this.logger.info("destroy shadow-object",Qt(e),{shadowObject:h,entity:t.entity});for(let d of s)d();for(let d of r)d();for(let d of a.values())le(d);for(let d of n.values())le(d);for(let d of o.values())le(d);s.clear(),r.clear(),a.clear(),n.clear(),o.clear();let l=t.usedConstructors.get(e);l&&(l.delete(h),l.size===0&&t.usedConstructors.delete(e))}),t.usedConstructors.has(e)?t.usedConstructors.get(e).add(h):t.usedConstructors.set(e,new Set([h])),this.attachShadowObject(h,t.entity),h}createShadowObjects(e){var s;let t=i(this,w).get(e);(s=this.registry.findConstructors(t.token))==null||s.forEach(r=>{this.constructShadowObject(r,t)})}findShadowObjects(e){if(!i(this,w).has(e))return[];let{usedConstructors:t}=i(this,w).get(e);return Array.from(new Set(Array.from(t.values()).map(s=>Array.from(s)).flat()))}attachShadowObject(e,t){Z(t,e),typeof e[Yt]=="function"&&e[Yt](t)}destroyShadowObject(e,t){typeof e[Ce]=="function"&&e[Ce](t),b(e,Ce,t),T(t,e)}destroy(){for(let e of this.traverseLevelOrderBFS().reverse())this.destroyEntity(e.uuid)}},w=new WeakMap,B=new WeakMap,Pe=new WeakMap,We=new WeakMap,W=new WeakMap,as);async function Ss(e,t,s,r=!0){var o,n;if(s.has(t)){console.warn("importModule: skipping already imported module",t);return}else s.add(t);t.extends&&await Promise.all(t.extends.map(h=>Ss(e,h,s,!1)));let{registry:a}=e;if(t.define)for(let[h,l]of Object.entries(t.define))a.define(h,l);if(t.routes)for(let[h,l]of Object.entries(t.routes))a.appendRoute(h,l);await((n=(o=t.initialize)==null?void 0:o.call(t,{define:(h,l)=>a.define(h,l),kernel:e,registry:a}))!=null?n:Promise.resolve()),r&&e.upgradeEntities()}var kr=e=>(typeof e=="string"&&(e=new URL(e,globalThis.location.href)),e.toString()),qe,ne,ks,As,Os,ns,Ar=(ns=class{constructor(e){g(this,ne);g(this,qe,new Set);var t,s;this.kernel=(t=e==null?void 0:e.kernel)!=null?t:new Sr,this.postMessage=(s=e==null?void 0:e.postMessage)!=null?s:self.postMessage.bind(self),Z(this.kernel,yt,"onMessageToView",this)}route(e){var t;switch(e.data.type){case Ms:m(this,ne,ks).call(this,e.data);break;case Ts:m(this,ne,As).call(this,e.data);break;case Ds:m(this,ne,Os).call(this,e.data);break;default:console.warn("[MessageRouter] unknown message",(t=e.data.type)!=null?t:e.data)}}onMessageToView(e){let r=e,{transferables:t}=r,s=Lt(r,["transferables"]);this.postMessage({type:yt,data:s},{transfer:t})}},qe=new WeakMap,ne=new WeakSet,ks=async function(e){try{let t=await import(kr(e.importModule));t[lt]?(await Ss(this.kernel,t[lt],i(this,qe)),this.postMessage({type:ht,url:e.importModule})):this.postMessage({type:ht,url:e.importModule,error:`module has no "${lt}" export`})}catch(t){console.error("[MessageRouter] failed to import module",t),this.postMessage({type:ht,url:e.importModule,error:`${t}`})}},As=function(e){try{this.kernel.run(e)}catch(t){console.error("[MessageRouter] failed to apply change trail",t),this.postMessage({type:zt,serial:e.serial,error:t.toString()})}e.serial&&this.postMessage({type:zt,serial:e.serial})},Os=function(e){console.debug("[MessageRouter] on destroy",e),T(this.kernel,this),i(this,qe).clear(),this.postMessage({type:Rs})},ns),Or=class{constructor(){this.onmessage=e=>{var t;e.data.type===z?globalThis[M]=e.data.config:((t=this.router)!=null||(this.router=new Ar),this.router.route(e))}}start(){self.addEventListener("message",this.onmessage),self.postMessage({type:Ls})}};console.debug("@spearwolf/shadow-objects/WorkerRuntime: hello!");var Pr=new Or;Pr.start();\n/*! Bundled license information:\n\n@spearwolf/eventize/lib/index.mjs:\n (*!\n =============================================================================\n @spearwolf/eventize 4.0.1+build.20240804\n \u2014 https://github.com/spearwolf/eventize.git\n =============================================================================\n \n Copyright 2015-2024 Wolfger Schramm\n \n Licensed under the Apache License, Version 2.0 (the "License");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n \n http://www.apache.org/licenses/LICENSE-2.0\n \n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an "AS IS" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n *)\n*/\n')}var Ms=()=>new zt;var Le=(s,e,t=1e3,r)=>new Promise((i,n)=>{let o,l,a=()=>{clearTimeout(o),s.removeEventListener("message",l)};t!==0&&t!==1/0&&(o=setTimeout(()=>{a(),n(new Error(`Timeout waiting for message of type: ${e}`))},t)),l=h=>{if(h.data.type===e)try{(!r||r(h.data))&&(a(),i())}catch(u){a(),n(u.toString())}},s.addEventListener("message",l)});var nr=s=>{let e;if(s!=null&&Array.isArray(s))for(let t of s)t.transferables&&(e?e=[...e,...t.transferables]:e=t.transferables,delete t.transferables);return e},yt=class s{static{this.WorkerLoaded="workerLoaded"}#e;#t;#s;get isDestroyed(){return this.#t}get workerLoaded(){return he(this,s.WorkerLoaded)}constructor(){this.#t=!1,this.#s=0,this.logger=new x("RemoteWorkerEnv"),D(this,s.WorkerLoaded)}async start(){if(this.#e)return this.logger.isWarn&&this.logger.warn("already started"),this.workerLoaded.then(()=>{if(this.isDestroyed)throw"worker was destroyed"});let e=this.#e=Ms();this.configureConsoleLogger(e);try{if(await Le(e,ls,ds),this.isDestroyed)throw"worker was destroyed";e.addEventListener("message",this.onMessageFromWorker.bind(this)),queueMicrotask(()=>{c(this,s.WorkerLoaded,this)})}catch(t){throw this.logger.error("failed to start",t),this.#e=void 0,t}}applyChangeTrail(e,t){let r=nr(e),i={type:as,changeTrail:e},n=++this.#s;return t&&(i.serial=n),this.#e.postMessage(i,r),t?Le(this.#e,us,gs,o=>{if(o.error)throw o.error;return o.serial===n}):Promise.resolve()}importScript(e){return e=pt(e),this.#e.postMessage({type:os,importModule:e}),Le(this.#e,cs,ps,t=>{if(t.error)throw t.error;return t.url===e})}destroy(){if(!this.#e)return;let e=this.#e;this.#e=void 0,this.#t=!0,e.postMessage({type:hs}),Le(e,fs,ys).finally(()=>{e.terminate()})}onMessageFromWorker(e){e.data?.type===pe?this.onMessageToView?.(e.data.data):this.logger.isDebug&&this.logger.debug("message from worker",e)}configureConsoleLogger(e){let t=`${P}.RemoteWorkerEnv.workerConfig`,r=JSON.parse(localStorage.getItem(t)??"{}");this.logger.isInfo&&this.logger.info("load console-logger worker config",{localStorageKey:t,workerConfig:r}),e.postMessage({type:P,config:{...x.sharedConfig,enable:this.logger.isEnabled,...r,...x.isEnabled?{}:{enable:!1}}})}};var _e,Ne=class extends K{static{this.observedAttributes=[...K.observedAttributes,tt,rt,st]}static{this.DefaultAutoSync="frame"}#e;#t;#s;#i;#r;constructor(){super(),this.isShaeWorkerElement=!0,this.shadowEnv=new _,this.logger=new x("ShaeWorkerElement"),this.autostart=!0,this.isConnected$=f(!1),this.autoSync$=f(_e.DefaultAutoSync),this.src$=f(""),this.#e=!1,this.#t=!1,this.ns$.onChange(e=>{this.shadowEnv.view=R.get(e)}),g(this.shadowEnv,_.ContextCreated,()=>{this.#r?.run(),this.dispatchEvent(new CustomEvent(_.ContextCreated.toLowerCase(),{bubbles:!1,detail:{shadowEnv:this.shadowEnv}}))}),g(this.shadowEnv,_.ContextLost,()=>{this.dispatchEvent(new CustomEvent(_.ContextLost.toLowerCase(),{bubbles:!1,detail:{shadowEnv:this.shadowEnv}}))}),this.autoSync$.onChange(e=>{let t=this.hasAttribute(N),r=t?this.getAttribute(N):void 0;e===_e.DefaultAutoSync?t&&r!==e&&this.setAttribute(N,e):r!==e&&this.setAttribute(N,e)}),this.#o(),this.#n()}#n(){this.#r=b(()=>{let e=this.src$.get();e&&this.importScript(e)},{autorun:!1})}get shouldAutostart(){return this.autostart&&!Re(this,xs)}get autoSync(){return this.autoSync$.value}set autoSync(e){typeof e!="string"&&(e=e?_e.DefaultAutoSync:"no"),this.autoSync$.set(`${e}`.trim().toLowerCase())}get frameLoop(){return this.#s??=new ge,this.#s}[ge.OnFrame](){this.syncShadowObjects()}async importScript(e){if(!e)throw new Error("src is blank");let t=await this.shadowEnv.ready();return this.logger.isInfo&&this.logger.info("shadowEnv importScript:",e,{shadowEnv:t}),await t.envProxy.importScript(e),this}connectedCallback(){k(()=>{this.hasAttribute(N)&&this.autoSync$.set(this.getAttribute(N)),this.isConnected$.set(!0)}),this.shouldAutostart&&this.start()}disconnectedCallback(){this.isConnected$.set(!1),this.#a()}attributeChangedCallback(e){if(super.attributeChangedCallback(e),e===tt&&this.shadowEnv.envProxy!=null)throw new Error('Changing the "local" attribute after the shadowEnv has been created is not supported.');if(e===st&&this.#h(),e===N&&(this.autoSync=this.hasAttribute(N)?this.getAttribute(N):!0),e===rt){let t=(this.getAttribute(rt)||"").trim();this.src$.set(t),this.shadowEnv.isReady&&this.#r?.run()}}start(){if(!this.#t){if(this.#e=!1,this.shadowEnv.view??=R.get(this.ns),this.shadowEnv.envProxy==null){let e=Re(this,tt)?new gt:new yt;this.shadowEnv.envProxy=e,this.#h()}this.#t=!0}return this.shadowEnv.ready()}destroy(){this.#i?.destroy(),this.#r?.destroy(),S(this.isConnected$,this.autoSync$,this.src$),this.shadowEnv.envProxy=void 0,this.shadowEnv.destroy()}#a(){this.#e||(this.#e=!0,queueMicrotask(()=>{this.#e&&this.destroy()}))}#o(){this.#i=b(()=>{if(this.isConnected$.get()){let e=(this.autoSync$.get()||_e.DefaultAutoSync).trim().toLowerCase(),t;if(["true","yes","on","frame","auto-sync"].includes(e))return this.logger.isDebug&&this.logger.debug("auto-sync",e,this),this.frameLoop.start(this),()=>{this.frameLoop.stop(this)};if(e.toLowerCase().endsWith("fps")){let r=parseInt(e,10);r>0?t=Math.floor(1e3/r):this.logger.isWarn&&this.logger.warn(`invalid auto-sync value: ${e}`)}else t=parseInt(e,10),isNaN(t)&&(t=void 0,["false","no","off"].includes(e)||this.logger.error(`invalid auto-sync value: ${e}`));if(t!==void 0&&t>0){this.logger.isDebug&&this.logger.debug("auto-sync interval (ms)",t,this);let r=setInterval(()=>{this.syncShadowObjects()},t);return()=>{clearInterval(r)}}else this.logger.isDebug&&this.logger.debug("auto-sync off",this)}},[this.autoSync$,this.isConnected$])}#h(){let e=this.shadowEnv.envProxy;e?.isLocalEnv&&(e.disableStructuredClone=this.hasAttribute(st))}};_e=Ne;customElements.define(Cs,Ne);globalThis.SHADOW_ENTS_BUNDLE_LOADED=!0;
|
|
22
22
|
/*! Bundled license information:
|
|
23
23
|
|
|
24
24
|
@spearwolf/eventize/lib/index.mjs:
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ShaeElement.d.ts","sourceRoot":"","sources":["../../../src/elements/ShaeElement.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,MAAM,EAAC,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"ShaeElement.d.ts","sourceRoot":"","sources":["../../../src/elements/ShaeElement.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,MAAM,EAAC,MAAM,sBAAsB,CAAC;AAE1D,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,aAAa,CAAC;AA2B/C,qBAAa,WAAY,SAAQ,WAAW;IAC1C,MAAM,CAAC,kBAAkB,WAAa;IAEtC,QAAQ,CAAC,aAAa,QAAQ;IAE9B,QAAQ,CAAC,GAAG,wBAAyC;IAErD,IAAI,EAAE,IAAI,aAAa,CAEtB;IAED,IAAI,EAAE,CAAC,EAAE,EAAE,aAAa,EAMvB;;IAkBD,wBAAwB,CAAC,IAAI,EAAE,MAAM;IAMrC,iBAAiB;CAGlB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ShaeElement.js","sourceRoot":"","sources":["../../../src/elements/ShaeElement.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAE,MAAM,EAAC,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAC,QAAQ,EAAC,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"ShaeElement.js","sourceRoot":"","sources":["../../../src/elements/ShaeElement.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAE,MAAM,EAAC,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAC,QAAQ,EAAC,MAAM,iBAAiB,CAAC;AAEzC,OAAO,EAAC,sBAAsB,EAAC,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAC,WAAW,EAAC,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAC,SAAS,EAAC,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAC,OAAO,EAAC,MAAM,gBAAgB,CAAC;AAEvC,MAAM,eAAe,GAAG,CAAC,EAAe,EAAE,EAAyB,EAAE,EAAE;IACrE,EAAE,CAAC,GAAG,CAAC,sBAAsB,CAAC,EAAE,CAAC,CAAC,CAAC;AACrC,CAAC,CAAC;AAEF,MAAM,cAAc,GAAG,IAAI,GAAG,EAAiB,CAAC;AAChD,IAAI,mBAAmB,GAAG,KAAK,CAAC;AAEhC,MAAM,iBAAiB,GAAG,CAAC,EAAiB,EAAE,EAAE;IAC9C,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACvB,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACzB,mBAAmB,GAAG,IAAI,CAAC;QAC3B,cAAc,CAAC,GAAG,EAAE;YAClB,mBAAmB,GAAG,KAAK,CAAC;YAC5B,KAAK,MAAM,EAAE,IAAI,cAAc,EAAE,CAAC;gBAChC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC;YAC5B,CAAC;YACD,cAAc,CAAC,KAAK,EAAE,CAAC;QACzB,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,OAAO,WAAY,SAAQ,WAAW;aACnC,uBAAkB,GAAG,CAAC,OAAO,CAAC,AAAZ,CAAa;IAMtC,IAAI,EAAE;QACJ,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC;IACxB,CAAC;IAED,IAAI,EAAE,CAAC,EAAiB;QACtB,IAAI,OAAO,EAAE,KAAK,QAAQ,EAAE,CAAC;YAC3B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACnB,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;IAED;QACE,KAAK,EAAE,CAAC;QAjBD,kBAAa,GAAG,IAAI,CAAC;QAErB,QAAG,GAAG,YAAY,CAAgB,QAAQ,CAAC,CAAC;QAiBnD,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,EAAE;YACvB,IAAI,OAAO,EAAE,KAAK,QAAQ,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC5C,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;oBACtC,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;gBACjC,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;YAChC,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IAClC,CAAC;IAED,wBAAwB,CAAC,IAAY;QACnC,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;YACrB,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;IAED,iBAAiB;QACf,iBAAiB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC7B,CAAC"}
|