@spearwolf/shadow-objects 0.20.0 → 0.21.1
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/README.md +86 -0
- package/bundle.js +4 -4
- package/package.json +3 -3
- package/src/constants.d.ts +4 -4
- package/src/constants.js +4 -4
- package/tsconfig.lib.tsbuildinfo +1 -1
package/README.md
CHANGED
|
@@ -57,6 +57,92 @@ class Foo {
|
|
|
57
57
|
> Sorry, at this point there should be a precise and crisp introduction to the concepts of the framework, but unfortunately this is not currently available.
|
|
58
58
|
> Instead of that, a few insights into the implementation will follow
|
|
59
59
|
|
|
60
|
+
## 📖 Shadow Objects CHEAT SHEET
|
|
61
|
+
|
|
62
|
+
There are two ways to create a _shadow object component_: either as a _function_ or as a _class_:
|
|
63
|
+
|
|
64
|
+
### Create Shadow Object by FUNCTION
|
|
65
|
+
|
|
66
|
+
```js
|
|
67
|
+
import { onDestroy, type ShadowObjectParams, type Entity } from "@spearwolf/shadow-objects/shadow-objects.js";
|
|
68
|
+
|
|
69
|
+
function MyShadowObject(params: ShadowObjectParams) {
|
|
70
|
+
//
|
|
71
|
+
// ... PUT YOUR IMPLEMENTATION HERE ...
|
|
72
|
+
//
|
|
73
|
+
|
|
74
|
+
// Return an object. This step is optional.
|
|
75
|
+
return {
|
|
76
|
+
// All methods here are reactive and correspond to entity events of the same name!
|
|
77
|
+
|
|
78
|
+
[onDestroy](entity: Entity) {
|
|
79
|
+
// Called when the shadow object is destroyed.
|
|
80
|
+
// This is one of the predefined events that a shadow object can receive.
|
|
81
|
+
|
|
82
|
+
// This can happen when the entity is destroyed or the shadow object component
|
|
83
|
+
// is removed from the entity (e.g., by changing the entity token, view properties, and/or routing)
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
fooBar(plah) {
|
|
87
|
+
/* is called when the entity receives a 'fooBar' event */
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Create Shadow Object by CLASS
|
|
94
|
+
|
|
95
|
+
Essentially the same as above, but as a `class`:
|
|
96
|
+
|
|
97
|
+
```js
|
|
98
|
+
import { onDestroy, type ShadowObjectParams, type Entity } from "@spearwolf/shadow-objects/shadow-objects.js";
|
|
99
|
+
|
|
100
|
+
class MyShadowObject {
|
|
101
|
+
constructor(params: ShadowObjectParams) {
|
|
102
|
+
//
|
|
103
|
+
// ... INITIALIZE SHADOW OBJECT ...
|
|
104
|
+
//
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
[onDestroy](entity: Entity) {
|
|
108
|
+
// ...
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
fooBar(plah) {
|
|
112
|
+
// ...
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Shadow Object Construction API
|
|
118
|
+
|
|
119
|
+
The parameters that a shadow object receives when it is created contain all the important API methods for exchanging data and events with the _view_ and also with the _shadow entity hierarchy and context_.
|
|
120
|
+
|
|
121
|
+
[The interface `ShadowObjectsParams` is defined here](./src/types.ts)
|
|
122
|
+
|
|
123
|
+
#### Properties
|
|
124
|
+
|
|
125
|
+
__entity__: The shadow entity.
|
|
126
|
+
|
|
127
|
+
#### Methods
|
|
128
|
+
|
|
129
|
+
| Name | Call Signature | Description |
|
|
130
|
+
|------|----------------|-------------|
|
|
131
|
+
| __useProperty__ | `useProperty(name, isEqual?): SignalReader` | Read access to the property value from the view |
|
|
132
|
+
| __useContext__ | `useContext(name, isEqual?): SignalReader` | Get the value for a named context. The context is derived from the shadow entity hierarchy and the shadow object's position within it. |
|
|
133
|
+
| __useParentContext__ | `useParentContext(name, isEqual?): SignalReader` | Unlike the `useContext` method, this method skips the context of the _current_ shadow entity and directly requests the context of the parent entity. This is useful when you want to provide a custom context that depends on the parent context. |
|
|
134
|
+
| __provideContext__ | `provideContext(name, initialValue?, isEqual?): Signal` | Specify a context. This context overrides (if set) the context of the same name from the entity's parent hierarchy. The context applies to the current entity and all child entities. |
|
|
135
|
+
| __provideGlobalContext__ | `provideGlobalContext(name, initialValue?, isEqual?): Signal` | Define a context that applies to _all_ entities, regardless of hierarchy. |
|
|
136
|
+
| __createEffect__ | `createEffect(...): Effect` | see [@spearwolf/signalize#createEffect()](https://github.com/spearwolf/signalize) |
|
|
137
|
+
| __createSignal__ | `createSignal(...): Signal` | see [@spearwolf/signalize#createSignal()](https://github.com/spearwolf/signalize) |
|
|
138
|
+
| __createMemo__ | `createMemo(...): SignalReader` | see [@spearwolf/signalize#createMemo()](https://github.com/spearwolf/signalize) |
|
|
139
|
+
| __on__ | `on(...): UnsubscribeCallback` | see [@spearwolf/eventize#on()](https://github.com/spearwolf/eventize) |
|
|
140
|
+
| __once__ | `once(...): UnsubscribeCallback` | see [@spearwolf/eventize#once()](https://github.com/spearwolf/eventize) |
|
|
141
|
+
| __onDestroy__ | `onDestroy(callback)` | Called when the shadow object is destroyed. |
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
## Documentation
|
|
145
|
+
|
|
60
146
|
TODO ... add documentation here ... !
|
|
61
147
|
|
|
62
148
|
Here is the big class graph overview:
|
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.21.1+bundle.20251108
|
|
5
5
|
|
|
6
6
|
Copyright 2025 Wolfger Schramm
|
|
7
7
|
|
|
@@ -18,17 +18,17 @@ See the License for the specific language governing permissions and
|
|
|
18
18
|
limitations under the License.
|
|
19
19
|
|
|
20
20
|
*/
|
|
21
|
-
var rt="*",Ye=1,Ce=2,Ee=4,W=Symbol.for("eventize"),$s="[eventize]",It=s=>s===rt,Ke=s=>{switch(typeof s){case"string":case"symbol":return!0;default:return!1}},Je=typeof console<"u",Is=Je?console[console.warn?"warn":"log"].bind(console,$s):()=>{},Fs=(s,t,e)=>(Object.defineProperty(s,t,{value:e,configurable:!0}),s),Ws=0,Xe=class{static publish(s){s.sort((t,e)=>t.order-e.order).forEach(t=>t.emit())}events=new Map;eventNames=new Set;add(s){Array.isArray(s)?s.forEach(t=>this.eventNames.add(t)):this.eventNames.add(s)}remove(s){Array.isArray(s)?s.forEach(t=>this.eventNames.delete(t)):this.eventNames.delete(s),this.clear(s)}clear(s){Array.isArray(s)?s.forEach(t=>this.events.delete(t)):this.events.delete(s)}retain(s,t){this.eventNames.has(s)&&this.events.set(s,{args:t,order:Ws++})}isKnown(s){return this.eventNames.has(s)}emit(s,t,e=[]){if(It(s))this.eventNames.forEach(r=>this.emit(r,t,e));else if(this.events.has(s)){let{order:r,args:i}=this.events.get(s);e.push({order:r,emit:()=>t.apply(s,i)})}return e}},ve=(s,t,e,r)=>{if(typeof t=="function"){let i=t.apply(s,e);i!=null&&r?.(i)}},zs=(s,t,e,r)=>ve(t,t.emit,[s].concat(e),r),Us=s=>{switch(typeof s){case"function":return Ye;case"string":case"symbol":return Ce;case"object":return Ee}},Vs=0,Gs=()=>++Vs,Ze=class{id;eventName;isCatchEmAll;priority;listener;listenerObject;listenerType;callAfterApply;isRemoved;refCount;constructor(s,t,e,r=null){this.id=Gs(),this.eventName=s,this.isCatchEmAll=It(s),this.listener=e,this.listenerObject=r,this.priority=t,this.listenerType=Us(e),this.callAfterApply=void 0,this.isRemoved=!1,this.refCount=1}isEqual(s,t=null){if(s===this)return!0;let e=typeof s;return e==="number"&&s===this.id?!0:t===null&&(e==="string"||e==="symbol")?s===rt||s===this.eventName:this.listener===s&&this.listenerObject===t}apply(s,t,e){if(this.isRemoved)return;let{listener:r,listenerObject:i}=this;switch(this.listenerType){case Ye:ve(i,r,t,e),this.callAfterApply&&this.callAfterApply();break;case Ce:ve(i,i[r],t,e),this.callAfterApply&&this.callAfterApply();break;case Ee:{let n=r[s];if(this.isCatchEmAll||this.eventName===s){if(typeof n=="function"){let o=n.apply(r,t);o!=null&&e?.(o)}else zs(s,r,t,e);this.callAfterApply&&this.callAfterApply()}break}}}},Bs=(s,t)=>s.priority!==t.priority?t.priority-s.priority:s.id-t.id,qe=s=>s?.slice(0),He=(s,t)=>{let e=s.indexOf(t);e>-1&&s.splice(e,1)},qs=s=>s===Ee||s===Ce,we=(s,t,e)=>{let r=s.findIndex(i=>i.isEqual(t,e));r>-1&&(s[r].isRemoved=!0,s.splice(r,1))},$t=(s,t,e)=>{let r=[];for(let i of s)(t==null&&i.listenerObject===e||i.eventName===t&&i.listener===e)&&r.push(i);for(let i of r)we(s,i,void 0)},be=s=>{s&&(s.forEach(t=>{t.isRemoved=!0}),s.length=0)},Hs=(s,t)=>s.listenerType===t.listenerType?s.priority===t.priority&&s.eventName===t.eventName&&s.listenerObject===t.listenerObject&&s.listener===t.listener:!1,Qs=(s,t)=>{if(qs(s.listenerType))return t.find(e=>Hs(s,e))},Ys=(s,t)=>{let e=Qs(s,t);return e?(e.refCount+=1,e):(t.push(s),t.sort(Bs),s)},Ks=class{namedListeners;catchEmAllListeners;getListenersForEventName=s=>{let t=this.namedListeners.get(s);return t||(t=[],this.namedListeners.set(s,t)),t};constructor(){this.namedListeners=new Map,this.catchEmAllListeners=[]}add(s){return Ys(s,s.isCatchEmAll?this.catchEmAllListeners:this.getListenersForEventName(s.eventName))}remove(s,t,e=!1){t==null&&Array.isArray(s)?s.forEach(r=>this.remove(r,null,e)):s==null||t==null&&It(s)?this.removeAllListeners():t==null&&Ke(s)?be(this.namedListeners.get(s)):s instanceof Ze?s.isRemoved||(s.refCount-=1,s.refCount<1&&(s.isRemoved=!0,this.namedListeners.forEach(r=>He(r,s)),He(this.catchEmAllListeners,s))):e?It(s)?$t(this.catchEmAllListeners,rt,s):this.namedListeners.forEach(r=>$t(r,s,t)):(this.namedListeners.forEach(r=>{we(r,s,t),$t(r,void 0,s)}),we(this.catchEmAllListeners,s,t),$t(this.catchEmAllListeners,void 0,s))}removeAllListeners(){this.namedListeners.forEach(s=>be(s)),this.namedListeners.clear(),be(this.catchEmAllListeners)}forEach(s,t){let e=qe(this.catchEmAllListeners),r=qe(this.namedListeners.get(s));if(s===rt||!r||r.length===0)e.forEach(t);else if(e.length===0)r.forEach(t);else{let i=r.length,n=e.length,o=0,h=0;for(;o<i||h<n;){if(o<i){let a=r[o];if(h>=n||a.priority>=e[h].priority){t(a),++o;continue}}h<n&&(t(e[h]),++h)}}}getSubscriptionCount(){let s=this.catchEmAllListeners.length;for(let t of this.namedListeners.values())s+=t.length;return s}},it=s=>!!(s&&s[W]);function wt(s){if(it(s))return s;let t=new Ks,e=new Xe;return Fs(s,W,{keeper:e,store:t}),s}var nt={Max:Number.POSITIVE_INFINITY,AAA:1e9,BB:1e6,C:1e3,Default:0,Low:-1e4,Min:Number.NEGATIVE_INFINITY},Js=(s,t,e,r,i,n,o)=>{let h=s.add(new Ze(e,r,i,n));return t.emit(e,h,o),h},Xs=(s,t,e,r)=>{let i=e.length,n=typeof e[0],o,h,a,c;if(i>=2&&i<=3&&n==="number"?(o=rt,[h,a,c]=e):i>=3&&i<=4&&typeof e[1]=="number"?[o,h,a,c]=e:(h=nt.Default,n==="string"||n==="symbol"||Array.isArray(e[0])?[o,a,c]=e:(o=rt,[a,c]=e)),!a&&Je)throw Is("called with insufficient arguments!",e),"subscribeTo() called with insufficient arguments!";let p=l=>u=>Js(s,t,u,l,a,c,r);return Array.isArray(o)?o.map(l=>Array.isArray(l)?p(l[1])(l[0]):p(h)(l)):p(h)(o)},ts=(s,t,e)=>{let r=[],i=Xs(s,t,e,r);return Xe.publish(r),i},Qe=s=>t=>{t.callAfterApply=()=>{s?.()}},es=(s,t)=>Object.assign(()=>v(s,t),Array.isArray(t)?{listeners:t}:{listener:t}),ss=(s,t,e,r)=>{let{store:i,keeper:n}=s[W];Array.isArray(t)?t.forEach(o=>{i.forEach(o,h=>h.apply(o,e,r)),n.retain(o,e)}):t!==rt&&(i.forEach(t,o=>{o.apply(t,e,r)}),n.retain(t,e))},b=(s,...t)=>{let e=wt(s),{store:r,keeper:i}=e[W];return es(e,ts(r,i,t))},E=(s,...t)=>{let e=wt(s),{store:r,keeper:i}=e[W],n=ts(r,i,t),o=es(e,n),h=!1,a=()=>{h||(o(),h=!0)};return Array.isArray(n)?n.forEach(Qe(a)):Qe(a)(n),a},ct=(s,t)=>new Promise(e=>{E(s,t,e)}),v=(s,t,e)=>{if(!it(s))throw new Error("object is not eventized");let{store:r,keeper:i}=s[W],n=typeof t,o=e!=null&&(n==="string"||n==="symbol");r.remove(t,e,o),Array.isArray(t)?i.remove(t.filter(h=>typeof h=="string")):Ke(t)&&i.remove(t)},d=(s,t,...e)=>{if(!it(s))throw new Error("object is not eventized");ss(s,t,e)},Zs=(s,t,...e)=>{if(!it(s))throw new Error("object is not eventized");let r=[];return ss(s,t,e,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()},z=(s,t)=>{let e=wt(s),{keeper:r}=e[W];r.add(t)},B=(s,t)=>{if(!it(s))throw new Error("object is not eventized");let{keeper:e}=s[W];e.clear(t)},S=(()=>{let s=(t={})=>wt(t);return s.inject=(t={})=>(t=wt(t),Object.assign(t,{on:(...e)=>b(t,...e),once:(...e)=>E(t,...e),onceAsync:e=>ct(t,e),off:(e,r)=>v(t,e,r),emit:(e,...r)=>d(t,e,...r),emitAsync:(e,...r)=>Zs(t,e,...r),retain:e=>z(t,e),retainClear:e=>B(t,e)}),t),s.is=it,s})();var Se=s=>it(s)?s[W]?.store?.getSubscriptionCount()??0:0;var q=S(),N=S(),H=S();var ot=class{static current;#t=new Set;batch(t){this.#t.add(t)}run(){d(H,Array.from(this.#t))}},rs=()=>ot.current;function O(s){let t=ot.current;t?t=void 0:t=ot.current=new ot;try{s()}finally{t&&(ot.current=void 0,t.run())}}var xe=0;function ke(s){xe++;try{s()}finally{xe--}}function Ft(){return xe>0}var R=Symbol.for("signal"),at=Symbol.for("effect"),Ae=Symbol.for("destroySignal"),Oe=Symbol.for("createEffect"),is=Symbol.for("destroyEffect"),ft="value",Te="mute",Pe="unmute",Q="destroy";var Y=new Map,M=class s{#t=new Set;#e=new Set;#s=new Map;#r=new WeakMap;#i=new Map;#n=new Set;#o=new Set;#a;static get(t){if(t!=null)return t instanceof s?t:Y.get(t)}static findOrCreate(t){if(t==null)throw new Error("Cannot create a group with a null object");return new s(t)}static destroy(t){console.warn("SignalGroup.destroy(obj) is deprecated. Use SignalGroup.delete(obj) instead."),s.delete(t)}static delete(t){Y.get(t)?.clear()}static clear(){for(let t of Y.values())t.destroy();Y.clear()}constructor(t){if(t!=null&&t instanceof s)return t;if(t??=this,Y.has(t))return Y.get(t);Y.set(t,this),S(this)}attachGroup(t){if(t===this)throw new Error("Cannot attach a group to itself");return this.#t.add(t),t.#a&&t.#a!==this&&t.#a.#t.delete(t),t.#a=this,t}detachGroup(t){return t!==this&&this.#t.has(t)&&(this.#t.delete(t),t.#a=void 0),t}attachSignal(t){let e=w(t);if(e?.destroyed)throw new Error("Cannot attach a destroyed signal to a group");return e&&this.#e.add(e),t}attachSignalByName(t,e){if(e){this.attachSignal(e);let r=w(e);this.#s.set(t,r),this.#i.has(t)?this.#i.get(t).push(r):this.#i.set(t,[r]),this.#r.has(r)?this.#r.get(r).add(t):this.#r.set(r,new Set([t]))}else this.#s.delete(t);return e}hasSignal(t){return this.#s.has(t)||this.#a?.hasSignal(t)}signal(t){return this.#s.get(t)?.object??this.#a?.signal(t)}detachSignal(t){let e=w(t);if(e&&(this.#e.delete(e),this.#r.has(e))){let r=this.#r.get(e);for(let i of r)if(this.#i.has(i)){let n=this.#i.get(i);n.splice(n.indexOf(e),1),n.length===0?(this.#s.delete(i),this.#i.delete(i)):this.#s.get(i)===e&&this.#s.set(i,n.at(-1))}r.clear(),this.#r.delete(e)}return t}attachEffect(t){return this.#n.add(t),t}runEffects(){for(let t of this.#n)t.run();for(let t of this.#t)t.runEffects()}attachLink(t){if(t?.isDestroyed)throw new Error("Cannot attach a destroyed link to a group");return t&&this.#o.add(t),t}detachLink(t){return t&&this.#o.delete(t),t}destroy(){console.warn("SignalGroup#destroy is deprecated. Use SignalGroup#clear instead."),this.clear()}clear(){d(this,Q,this),v(this);for(let t of this.#t)t.destroy();for(let t of this.#n)t.destroy();for(let t of this.#e)x(t);for(let t of this.#o)t.destroy();this.#t.clear(),this.#e.clear(),this.#s.clear(),this.#i.clear(),this.#n.clear(),this.#o.clear(),this.#a?.detachGroup(this),Y.delete(this)}};var Wt=class{[at];constructor(t){this[at]=t,E(t,dt.Destroy,()=>{this[at]=void 0})}run=()=>this[at]?.run();destroy=()=>{this[at]?.destroy(),this[at]=void 0}};var pt=class{#t;#e;constructor(t="id",e=1){this.#t=t,this.#e=e}make(){return Symbol(`${this.#t}${this.#e++}`)}};var Re=[],zt=()=>Re.at(-1),ns=(s,t)=>{Re.push(s);try{return t()}finally{Re.pop()}};var tr=s=>s!=null&&typeof s.then=="function",dt=class s{static idGen=new pt("ef");static Destroy="destroy";static count=0;id;callback;#t;#e=new Set;#s=new Set;parentEffect;childEffects=[];curChildEffectSlot=0;autorun=!0;shouldRun=!0;#r;#i=!1;constructor(t,e){S(this),this.callback=t;let r;e?.attach!=null&&(r=M.findOrCreate(e.attach),r.attachEffect(this)),this.autorun=e?.autorun??!0,this.#r=e?.dependencies?e.dependencies.map(i=>{switch(typeof i){case"string":case"symbol":return r.signal(i);default:return i}}):void 0,this.id=s.idGen.make(),b(H,this.id,"recall",this),++s.count}hasStaticDeps(){return this.#r!=null&&this.#r.length>0}saveSignalsFromDeps(){for(let t of this.#r)this.whenSignalIsRead(w(t).id)}static createEffect(t,e,r){let i=Array.isArray(e)?e:void 0,n=i?r??{dependencies:i}:e;n&&i&&(n.dependencies=i);let o,h=zt();return h!=null?(o=h.getCurrentChildEffect(),o==null&&(o=new s(t,n),h.attachChildEffect(o),d(H,Oe,o)),h.curChildEffectSlot++):(o=new s(t,n),d(H,Oe,o)),o.hasStaticDeps()?o.saveSignalsFromDeps():o.autorun&&o.run(),new Wt(o)}getCurrentChildEffect(){return this.childEffects[this.curChildEffectSlot]}attachChildEffect(t){this.childEffects.push(t),this.parentEffect=this}run=()=>{if(this.#i||!this.shouldRun)return;let t=rs();t?t.batch(this.id):(this.runCleanupCallback(),this.curChildEffectSlot=0,this.shouldRun=!1,this.hasStaticDeps()?this.#t=this.callback():this.#t=ns(this,this.callback))};recall(){this.shouldRun=!0,this.autorun&&this.run()}whenSignalIsRead(t){this.#e.has(t)||(this.#e.add(t),b(q,t,"recall",this),E(N,t,Ae,this))}[Ae](t){!this.#s.has(t)&&this.#e.has(t)&&(this.#s.add(t),v(q,t,this),this.#s.size===this.#e.size&&this.destroy())}runCleanupCallback(){if(this.#t!=null){let t=this.#t;this.#t=void 0,tr(t)?Promise.resolve(t).then(e=>{typeof e=="function"&&e()}):t()}}destroy=()=>{this.#i||(d(this,s.Destroy,this),v(this),d(H,is,this),this.runCleanupCallback(),v(q,this),v(H,this),v(N,this),this.#i=!0,this.#e.clear(),this.#s.clear(),this.childEffects.forEach(t=>{t.destroy()}),this.childEffects.length=0,--s.count)}};var C=(...s)=>dt.createEffect(...s);var Ct=new WeakMap,er=s=>{let t=Ct.get(s);return t||(t={},Ct.set(s,t)),t},T=(s,t)=>Ct.get(s)?.signals?.get(t);var os=(s,t,e)=>{let r=er(s);r.signals??=new Map,r.signals.set(t,e)};function Et(...s){for(let t of s)if(Ct.has(t)){let e=Ct.get(t);if(e.signals){for(let r of e.signals.values())x(r);e.signals.clear(),e.signals=void 0}}}function as(s){let t=w(gt(s)?s:T(...s));t!=null&&!t.muted&&!t.destroyed&&Ut(t.id,t.value,{touch:!0})}function ht(s){return gt(s)?w(s)?.value:w(T(...s))?.value}var Vt=class{[R];constructor(t){this[R]=t}get get(){return this[R].reader}get set(){return this[R].writer}get value(){return ht(this.get)}set value(t){this.set(t)}onChange(t){let{destroy:e}=C(()=>t(this.value),[this.get]);return e}get muted(){return this[R].muted}set muted(t){this[R].muted=t}touch(){as(this)}destroy(){x(this)}};var sr=new pt("si");function hs(s){Ft()||zt()?.whenSignalIsRead(s)}function Ut(s,t,e){Ft()||d(q,s,t,e)}var gt=s=>s!=null&&s[R]!=null,rr=s=>{let t=e=>(e?C(()=>(s.destroyed||hs(s.id),e(s.value)),[t]):s.destroyed||(s.beforeRead?.(),hs(s.id)),s.value);return Object.defineProperty(t,R,{value:s}),t},Gt=class s{static instanceCount=0;id;lazy;get[R](){return this}compare;beforeRead;muted=!1;destroyed=!1;#t=void 0;get value(){return this.lazy&&(this.#t=this.valueFn(),this.valueFn=void 0,this.lazy=!1),this.#t}set value(t){this.#t=t}valueFn;reader;writer=(t,e)=>{let r=e?.lazy??!1,n=e?.compare??this.compare??((h,a)=>h===a);if((r!==this.lazy||r&&t!==this.valueFn||!r&&!n(t,this.#t))&&(r?(this.#t=void 0,this.valueFn=t,this.lazy=!0):(this.#t=t,this.valueFn=void 0,this.lazy=!1),!this.muted&&!this.destroyed)){Ut(this.id,this.#t);return}(e?.touch??!1)&&Ut(this.id,this.#t,{touch:!0})};object;constructor(t,e){this.id=sr.make(),++s.instanceCount,this.lazy=t,this.lazy?(this.value=void 0,this.valueFn=e):(this.value=e,this.valueFn=void 0),this.reader=rr(this),this.object=new Vt(this)}},w=s=>s?.[R];function f(s=void 0,t){let e;if(gt(s))e=w(s);else{let r=t?.lazy??!1;e=new Gt(r,s),e.beforeRead=t?.beforeRead,e.compare=t?.compare}return t?.attach!=null&&M.findOrCreate(t.attach).attachSignal(e),e.object}var x=(...s)=>{for(let t of s){let e=w(t);e!=null&&!e.destroyed&&(e.destroyed=!0,e.beforeRead=void 0,--Gt.instanceCount,d(N,e.id,e.id))}};function Me(s,t){let e=f(),r=t?.attach!=null?M.findOrCreate(t.attach):void 0;r!=null&&(t?.name?r.attachSignalByName(t.name,e):r.attachSignal(e));let i=C(()=>e.set(s()),{autorun:!1,attach:r}),n=w(e);return n.beforeRead=i.run,E(N,n.id,i.destroy),e.get}var Bt=class{#t=!1;#e;source;lastValue;isDestroyed=!1;constructor(t){S(this),this.source=w(t),this.#e=b(q,this.source.id,(e,r)=>{!this.#t&&!this.isDestroyed&&(r?.touch===!0?this.touch():this.write())}),E(N,this.source.id,()=>this.destroy())}attach(t){let e=M.findOrCreate(t);return e.attachLink(this),E(this,Q,()=>{e.detachLink(this)}),e}nextValue(){return new Promise((t,e)=>{let r=[],i=()=>r.forEach(n=>{n()});r.push(E(this,ft,n=>{i(),t(n)}),E(this,Q,()=>{i(),e()}))})}async*asyncValues(t){let e=0;for(;!this.isDestroyed;)try{let r=await this.nextValue();if(t&&t(r,e++))break;z(this,ft),yield r}catch{break}B(this,ft)}destroy(){this.isDestroyed||(this.#e?.(),this.#e=void 0,d(this,Q,this),B(this,ft),v(this),this.lastValue=void 0,this.isDestroyed=!0,Object.freeze(this))}get isMuted(){return this.#t}mute(){return!this.isDestroyed&&!this.#t&&(this.#t=!0,d(this,Te,this)),this}unmute(){return!this.isDestroyed&&this.#t&&(this.#t=!1,d(this,Pe,this)),this}toggle(){return this.isDestroyed||(this.#t=!this.#t,d(this,this.#t?Te:Pe,this)),this.#t}updateValue(t){if(!this.#t&&!this.isDestroyed){let{value:e}=this.source;t(e),d(this,ft,e),this.lastValue=e}}},qt=class extends Bt{target;constructor(t,e){super(t),this.target=w(e),E(N,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)})}},Ht=class extends Bt{target;constructor(t,e){super(t),this.target=e,this.touch()}touch(){return this.updateValue(t=>{this.target(t)}),this}write(){this.updateValue(t=>{this.target(t)})}};var Qt=new Map;function j(s,t,e){let r=w(s),i;if(Qt.has(r)){i=Qt.get(r);let c=w(t)??t;if(i.has(c))return i.get(c)}else i=new Map,Qt.set(r,i);let n=w(t),o=n!=null?new qt(s,n):new Ht(s,t),h=e?.attach;h&&o.attach(h);let a=n??t;return i.set(a,o),E(o,Q,()=>{i.delete(a),i.size===0&&Qt.delete(r)}),o}var Yt=class s{static fromProps(t,e){let r=new s,i=e?e.map(n=>[n,t[n]]):Object.entries(t);for(let[n,o]of i)r.#t.set(n,f(o));return r}#t=new Map;keys(){return this.#t.keys()}signals(){return this.#t.values()}entries(){return this.#t.entries()}clear(){for(let t of this.#t.values())t.destroy();this.#t.clear()}has(t){return this.#t.has(t)}get(t){if(!this.#t.has(t)){let e=f();return this.#t.set(t,e),e}return this.#t.get(t)}update(t){t.size&&O(()=>{for(let[e,r]of t.entries())this.get(e).set(r)})}updateFromProps(t,e){O(()=>{let r=e?e.map(i=>[i,t[i]]):Object.entries(t);for(let[i,n]of r)this.get(i).set(n)})}};var $;(function(s){s[s.StructuralChanges=1]="StructuralChanges",s[s.ContentUpdates=2]="ContentUpdates",s[s.Removal=3]="Removal"})($||($={}));var m;(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"})(m||(m={}));var lt=Symbol.for("ShadowEntsGlobalNS"),U="#void",ls="contextLost",us="configure",cs="changeTrail",fs="destroy",ds="loaded",ps="appliedChangeTrail",gs="importedModule",ys="destroyed",yt="messageToView",ms=16e3,bs=16e3,vs=4e3,ws=1e3,Le="shadowObjects";function Cs(s,t){s.indexOf(t)===-1&&s.push(t)}function _e(s,t){let e=s.indexOf(t);e!==-1&&s.splice(e,1),s.push(t)}function K(s,t){let e=s.indexOf(t);e!==-1&&s.splice(e,1)}var ut=s=>typeof s=="string"?s.trim()||lt:typeof s=="symbol"?s:lt;var St="#root",xt=class{#t;get uuid(){return this.#t}#e=0;constructor(t){this.#t=t}#s=!0;#r=0;#i=0;hasChanges(){return this.#e>0}get isNew(){return this.#s}get isCreated(){return this.#r>0&&this.#r>this.#i}get isDestroyed(){return this.#i>0&&this.#i>=this.#r}#n=U;#o;#a=0;#h;#l;#u;create(t=U,e,r=0){this.#e++,this.#r++,this.#h=t,this.#l=e??St,this.#u=r||void 0}destroy(){this.#i++,this.#e++}clear(){this.#e=0,this.#s=!1,this.#h=void 0,this.#l=void 0,this.#u=void 0,this.#f.clear(),this.#d.length=0,this.#g.length=0,this.#p.clear()}changeToken(t){t===this.#n?this.#h=void 0:(this.#h=t,this.#e++)}setParent(t){t===this.#o?this.#l=void 0:(this.#l=t??St,this.#e++)}changeOrder(t){t===this.#a?this.#u=void 0:(this.#u=t,this.#e++)}#c=new Map;#f=new Map;#d=[];changeProperty(t,e,r){let i=this.#c.get(t);r==null&&e!==i||r!=null&&!r(e,i)?(this.#f.set(t,e),_e(this.#d,t),this.#e++):(this.#f.delete(t),K(this.#d,t))}removeProperty(t){let e=this.#c.has(t);this.#f.has(t)?(this.#f.delete(t),e||K(this.#d,t)):e&&(_e(this.#d,t),this.#e++)}#g=[];#p=new Set;createEvent(t,e,r){this.#g.push({type:t,data:e}),r?.forEach(i=>this.#p.add(i)),this.#e++}transferEventsTo(t){this.#g.length>0&&(t.#g.push(...this.#g),this.#g.length=0),this.#p.size>0&&(t.#p=new Set([...t.#p,...this.#p]),this.#p.clear())}buildChangeTrail(t,e){let{isNew:r,isCreated:i,isDestroyed:n}=this;if(!(r&&n))switch(e){case $.StructuralChanges:r?t.push(this.makeCreateEntityChange()):n||(this.#l!==void 0&&!(this.#l===St&&this.#o===void 0)?t.push(this.makeSetParentChange()):this.#u!==void 0&&this.#u!==this.#a&&t.push(this.makeUpdateOrderChange()),this.#h!==void 0&&this.#h!==this.#n&&t.push(this.makeChangeToken()));break;case $.ContentUpdates:!r&&i&&this.#d.length>0&&t.push(this.makeChangePropertyChange()),this.#g.length>0&&t.push(this.makeEvents());break;case $.Removal:n&&t.push(this.makeDestroyEntityChange());break}}makeEvents(){let t={type:m.SendEvents,uuid:this.#t,events:this.#g.slice(0)};return this.#p.size>0&&(t.transferables=Array.from(this.#p)),t}makeCreateEntityChange(){let t={type:m.CreateEntities,uuid:this.#t,token:this.#h};if(this.#n=this.#h,this.#l!==void 0){let e=this.#l===St?void 0:this.#l;this.#o=e,e!==void 0&&(t.parentUuid=e)}return this.#f.size>0&&(t.properties=Array.from(this.#f.entries()).filter(([,e])=>e!==void 0),t.properties.forEach(([e,r])=>this.#c.set(e,r))),this.#u!==void 0&&this.#u!==this.#a&&(t.order=this.#a=this.#u),t}makeDestroyEntityChange(){return{type:m.DestroyEntities,uuid:this.#t}}makeSetParentChange(){this.#o=this.#l===St?void 0:this.#l;let t={type:m.SetParent,uuid:this.#t,parentUuid:this.#o};return this.#u!==void 0&&this.#u!==this.#a&&(t.order=this.#a=this.#u),t}makeUpdateOrderChange(){return this.#a=this.#u??0,{type:m.UpdateOrder,uuid:this.#t,order:this.#a}}makeChangeToken(){return this.#n=this.#h??U,{type:m.ChangeToken,uuid:this.#t,token:this.#n}}makeChangePropertyChange(){let t=this.#d.map(e=>{if(this.#f.has(e)){let r=this.#f.get(e);return this.#c.set(e,r),[e,r]}else return this.#c.delete(e),[e,void 0]});return{type:m.ChangeProperties,uuid:this.#t,properties:t}}};var Es=s=>{if(!(s===void 0||s.length===0))return s.filter(t=>t.length===1||t[1]!==void 0)},je=(s,t)=>{if(s===t||t===void 0)return s;if(s===void 0)return Es(t);for(let[e,r]of t){let i=s.find(([n])=>n===e);i===void 0?s.push([e,r]):i[1]=r}return Es(s)};var Kt=class{#t=new Map;get[Symbol.iterator](){return this.#t.entries.bind(this.#t)}clear(){this.#t.clear()}isEmpty(){return this.#t.size===0}hasComponentState(t){return this.#t.has(t)}getComponentState(t){return this.#t.get(t)}write(t){for(let e of t)if(e.type===m.CreateEntities)this.createEntity(e);else if(this.#t.has(e.uuid))switch(e.type){case m.DestroyEntities:this.destroyEntity(e);break;case m.SetParent:this.setParent(e);break;case m.UpdateOrder:this.updateOrder(e);break;case m.ChangeToken:this.changeToken(e);break;case m.ChangeProperties:this.changeProperties(e);break}}changeProperties({uuid:t,properties:e}){let r=this.getComponentState(t);r.properties=je(r.properties,e)}changeToken({uuid:t,token:e}){this.getComponentState(t).token=e||U}updateOrder({uuid:t,order:e}){this.getComponentState(t).order=e??0}setParent({uuid:t,parentUuid:e,order:r}){let i=this.getComponentState(t);i.parentUuid=e,i.order=r??0}destroyEntity({uuid:t}){this.#t.delete(t)}createEntity({uuid:t,token:e,parentUuid:r,order:i,properties:n}){this.#t.set(t,{token:e||U,parentUuid:r,order:i??0,properties:je(void 0,n)})}};var D=class s{static{this.ReRequestParentRoots="re-request-parent-roots"}static getContextsMap(){return globalThis.__shadowEntsContexts==null&&(globalThis.__shadowEntsContexts=new Map),globalThis.__shadowEntsContexts}static get(t){let e=ut(t),r=s.getContextsMap();return r.has(e)?r.get(e):new s(e)}#t=new Map;#e=[];#s=new Kt;constructor(t=lt){let e=ut(t),r=s.getContextsMap();if(r.has(e))return r.get(e);this.ns=e,r.set(e,this)}addComponent(t){let e;this.#t.has(t.uuid)?(e=this.#t.get(t.uuid),e.component=t,e.children=[]):(e={component:t,children:[],changes:new xt(t.uuid),propIsEqual:void 0},this.#t.set(t.uuid,e)),e.changes.create(t.token,t.parent?.uuid,t.order),t.parent?(this.addToChildren(t.parent,t),e.changes.setParent(t.parent.uuid)):this.#n(t,this.#e),this.#o=void 0}hasComponent(t){return this.#t.has(t.uuid)}hasComponents(){return this.#t.size>0}isRootComponent(t){return this.#e.includes(t.uuid)}destroyComponent(t){if(this.hasComponent(t)){let e=this.#t.get(t.uuid);e.children.slice(0).forEach(r=>this.#t.get(r)?.component.removeFromParent()),e.changes.destroy(),this.#o=void 0}}getChildren(t){return this.#t.get(t.uuid)?.children.map(e=>this.#t.get(e).component)??[]}removeFromParent(t,e){if(this.hasComponent(e)){let r=this.#t.get(t),i=this.#t.get(e.uuid),n=i.children.indexOf(t);n!==-1&&(i.children.splice(n,1),r.changes.setParent(void 0)),this.#n(r.component,this.#e),this.#o=void 0}}moveToRoot(t){let e=this.#t.get(t);e&&(e.changes?.setParent(void 0),this.#n(e.component,this.#e)),this.#o=void 0}changeToken(t,e){this.#t.get(t.uuid)?.changes.changeToken(e)}isChildOf(t,e){return this.hasComponent(e)?this.#t.get(e.uuid).children.includes(t.uuid):!1}addToChildren(t,e){let r=this.#t.get(t.uuid);if(r)this.#n(e,r.children),this.#t.get(e.uuid)?.changes.setParent(t.uuid),K(this.#e,e.uuid),this.#o=void 0;else throw new Error(`the view component ${t.uuid} cannot have a child added to it because the component do not exist!`)}removeSubTree(t){let e=this.#t.get(t);e&&(e.children.slice(0).forEach(r=>this.removeSubTree(r)),this.destroyComponent(e.component),this.#r(t))}setProperty(t,e,r,i){let n=this.#t.get(t.uuid);return n!=null?(i!=null?(n.propIsEqual??=new Map,n.propIsEqual.set(e,i)):n.propIsEqual?.has(e)&&n.propIsEqual.delete(e),n.changes.changeProperty(e,r,i)):!1}removeProperty(t,e){this.#t.get(t.uuid)?.changes.removeProperty(e)}changeOrder(t){if(t.parent){let e=this.#t.get(t.parent.uuid);K(e.children,t.uuid),this.#n(t,e.children)}else K(this.#e,t.uuid),this.#n(t,this.#e);this.#t.get(t.uuid)?.changes.changeOrder(t.order),this.#o=void 0}traverseLevelOrderBFS(){return this.#a().map(t=>t.component)}dispatchShadowObjectsEvent(t,e,r,i){this.#t.get(t.uuid)?.changes.createEvent(e,r,i)}broadcastEvent(t,e=void 0){for(let r of this.traverseLevelOrderBFS())r.dispatchEvent(t,e,!1)}dispatchMessage(t,e,r=void 0,i=!1){this.#t.get(t)?.component.dispatchEvent(e,r,i)}dispatchReRequestParentRoots(){for(let t of this.#e)this.dispatchMessage(t,s.ReRequestParentRoots)}buildChangeTrails(t=!0){let e=[];if(!this.hasComponents())return e;let r=this.#i();for(let i of r)i.buildChangeTrail(e,$.StructuralChanges);for(let i of r)i.buildChangeTrail(e,$.ContentUpdates);for(let i of r)i.buildChangeTrail(e,$.Removal),(i.isDestroyed||i.isNew&&!i.isCreated)&&this.#r(i.uuid),t&&i.clear();return this.#s.write(e),e}reCreateChanges(){if(!this.#s.isEmpty()){this.buildChangeTrails(!1);for(let[t,e]of this.#s){let r=this.#t.get(t);if(r){let i=new xt(t);if(i.create(e.token,e.parentUuid,e.order),e.properties)for(let[n,o]of e.properties)i.changeProperty(n,o,r.propIsEqual?.get(n));r.changes.transferEventsTo(i),r.changes.clear(),r.changes=i}}this.#s.clear(),this.broadcastEvent(ls)}}clear(){if(this.#o=void 0,this.#s.clear(),this.#e.slice(0).forEach(t=>this.removeSubTree(t)),this.#e.length!==0)throw new Error("component-context panic: #rootComponents is not empty!");if(this.#t.size!==0)throw new Error("component-context panic: #components is not empty!")}#r(t){this.#t.has(t)&&(this.#t.delete(t),K(this.#e,t),this.#o=void 0)}#i(){return this.#a().filter(t=>t.changes.hasChanges()).map(t=>t.changes)}#n(t,e){if(e.length===0){e.push(t.uuid);return}if(e.includes(t.uuid))return;let r=e.length,i=new Array(r);if(i[0]=this.#t.get(e[0]).component,t.order<i[0].order){e.unshift(t.uuid);return}if(r===1){e.push(t.uuid);return}let n=r-1;if(i[n]=this.#t.get(e[n]).component,t.order>=i[n].order){e.push(t.uuid);return}if(r===2){e.splice(1,0,t.uuid);return}for(let o=n-1;o>=1;o--)if(i[o]=this.#t.get(e[o]).component,t.order>=i[o].order){e.splice(o+1,0,t.uuid);return}}#o;#a(){if(this.#o)return this.#o;let t=new Map,e=(r,i)=>{let n=this.#t.get(r);if(n!=null){t.has(i)?t.get(i).push(n):t.set(i,[n]);for(let o of n.children)e(o,i+1)}};return this.#e.forEach(r=>e(r,0)),this.#o=Array.from(t.entries()).sort((r,i)=>r[0]-i[0]).map(([,r])=>r).flat(),this.#o}};function kt(s,t,e,r,i,n){function o(vt){if(vt!==void 0&&typeof vt!="function")throw new TypeError("Function expected");return vt}for(var h=r.kind,a=h==="getter"?"get":h==="setter"?"set":"value",c=!t&&s?r.static?s:s.prototype:null,p=t||(c?Object.getOwnPropertyDescriptor(c,r.name):{}),l,u=!1,g=e.length-1;g>=0;g--){var y={};for(var P in r)y[P]=P==="access"?{}:r[P];for(var P in r.access)y.access[P]=r.access[P];y.addInitializer=function(vt){if(u)throw new TypeError("Cannot add initializers after decoration has completed");n.push(o(vt||null))};var st=(0,e[g])(h==="accessor"?{get:p.get,set:p.set}:p[a],y);if(h==="accessor"){if(st===void 0)continue;if(st===null||typeof st!="object")throw new TypeError("Object expected");(l=o(st.get))&&(p.get=l),(l=o(st.set))&&(p.set=l),(l=o(st.init))&&i.unshift(l)}else(l=o(st))&&(h==="field"?i.unshift(l):p[a]=l)}c&&Object.defineProperty(c,r.name,p),u=!0}function J(s,t,e){for(var r=arguments.length>2,i=0;i<t.length;i++)e=r?t[i].call(s,e):t[i].call(s);return r?e:void 0}function At(s){return function(t,e){let r=s?.name||e.name,i=!!(s?.readAsValue??!1);return{get(){let n=T(this,r);if(n)return i?n.value:n.get()},set(n){T(this,r)?.set(n)},init(n){let o=f(n,s);return os(this,r,o),M.findOrCreate(this).attachSignalByName(r,o),o.value}}}}var _="ConsoleLogger",L=`${_}Storage`,ir=!!(globalThis.location?.host?.startsWith("localhost")??!1),Tt="localStorage"in globalThis,Jt=Symbol.for(_),Ss=!1,xs=s=>{if(typeof s=="boolean")return s;switch(s.toLowerCase()){case"true":case"yes":case"on":return!0;default:return!1}},Ne=s=>[Tt?_:void 0,...Array.isArray(s)?s:[s]].filter(Boolean).join(".");function De(s,t=void 0,e){let r=Ne(s),i=Tt?localStorage.getItem(r):globalThis[L]?.[r];return i!=null?t(i):e}function Ot(s,t){Tt?localStorage.setItem(Ne(s),t):(globalThis[L]==null&&(globalThis[L]={},console.debug(`${_}: Initialize`,{[L]:globalThis[L]})),globalThis[L][Ne(s)]=t)}var A=class s{static{this.sharedConfig={enable:ir,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(t){s.sharedConfig["styles.debug"]=t},get info(){return s.sharedConfig["styles.info"]},set info(t){s.sharedConfig["styles.info"]=t},get warn(){return s.sharedConfig["styles.warn"]},set warn(t){s.sharedConfig["styles.warn"]=t},get error(){return s.sharedConfig["styles.error"]},set error(t){s.sharedConfig["styles.error"]=t}}}static loadConfig(){Tt?(["enable","debug","info","warn"].forEach(t=>{this.sharedConfig[t]=De(t,xs,this.sharedConfig[t])}),["debug","info","warn","error"].forEach(t=>{this.sharedStyles[t]=De(["styles",t],void 0,this.sharedStyles[t])}),s.isDebug&&console.debug(`${_}: Load config from localStorage`,s.sharedConfig),globalThis[_]?.[Jt]||(globalThis[_]??={[Jt]:!0,get enable(){return s.sharedConfig.enable},set enable(t){s.sharedConfig.enable=t,Ot("enable",t?"true":"false")},get debug(){return s.sharedConfig.debug},set debug(t){s.sharedConfig.debug=t,Ot("debug",t?"true":"false")},get info(){return s.sharedConfig.info},set info(t){s.sharedConfig.info=t,Ot("info",t?"true":"false")},get warn(){return s.sharedConfig.warn},set warn(t){s.sharedConfig.warn=t,Ot("warn",t?"true":"false")}})):globalThis[L]?.[Jt]||(globalThis[L]={[Jt]:!0,...s.sharedConfig,...globalThis[L]},s.sharedConfig=globalThis[L],s.isDebug&&console.debug(`${_}: Load config from ${L}`,globalThis[L]))}constructor(t){this.enable=!0,this.namespace=(t||"").trim()||_,Ss||(s.loadConfig(),Ss=!0);let e=[this.namespace,"enable"];this.enable=De(e,xs,this.enable),Ot(e,Tt?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(...t){this.#t("debug",s.sharedStyles.debug,t)}info(...t){this.#t("info",s.sharedStyles.info,t)}warn(...t){this.#t("warn",s.sharedStyles.warn,t)}error(...t){this.#t("error",s.sharedStyles.error,t)}#t(t,e,r){console[t](`%c${this.namespace}`,e,...r)}};var I=(()=>{var s;let t,e=[],r=[],i,n=[],o=[];return class V{static{let a=typeof Symbol=="function"&&Symbol.metadata?Object.create(null):void 0;t=[At()],i=[At()],kt(this,null,t,{kind:"accessor",name:"viewReady",static:!1,private:!1,access:{has:c=>"viewReady"in c,get:c=>c.viewReady,set:(c,p)=>{c.viewReady=p}},metadata:a},e,r),kt(this,null,i,{kind:"accessor",name:"proxyReady",static:!1,private:!1,access:{has:c=>"proxyReady"in c,get:c=>c.proxyReady,set:(c,p)=>{c.proxyReady=p}},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)}#t;#e;#s;#r;#i;#n;#o;get viewReady(){return this.#o}set viewReady(a){this.#o=a}#a;get proxyReady(){return this.#a}set proxyReady(a){this.#a=a}#h;get isDestroyed(){return this.#h}constructor(){this.#s=!1,this.#r=!1,this.#i=!1,this.logger=new A("ShadowEnv"),this.ns$=f(),this.#o=J(this,e,!1),this.#a=(J(this,r),J(this,n,!1)),this.#h=(J(this,o),!1),this.ready=async()=>this.isReady?this:ct(this,V.ContextCreated),this.#l=()=>{this.#s&&this.#u()},z(this,V.ContextCreated),b(this,V.ContextLost,nt.AAA,()=>{B(this,V.ContextCreated)}),C(()=>{if(this.viewReady&&this.proxyReady)return this.view.reCreateChanges(),d(this,V.ContextCreated,this),this.#r&&(this.#r=!1,this.#u()),()=>{d(this,V.ContextLost,this)}},[T(this,"viewReady"),T(this,"proxyReady")])}get view(){return this.#t}set view(a){a!==this.#t&&(this.#t&&this.#t.ns&&globalThis.__shadowEnvs&&globalThis.__shadowEnvs.delete(this.#t.ns),this.#t=a??void 0,this.#t&&this.#t.ns&&(globalThis.__shadowEnvs??=new Map,globalThis.__shadowEnvs.has(this.#t.ns)&&globalThis.__shadowEnvs.get(this.#t.ns)!==this&&this.logger.isWarn&&this.logger.warn("overwrite a namespace already in use",this.#t.ns,globalThis.__shadowEnvs.get(this.#t.ns)),globalThis.__shadowEnvs.set(this.#t.ns,this)),this.viewReady=!!a)}get envProxy(){return this.#e}set envProxy(a){if(a!==this.#e){let c=this.#e;this.#e=a??void 0,this.#e&&(this.#e.onMessageToView=this.#c.bind(this)),c&&c.destroy(),this.proxyReady=!1,a?.start().then(()=>{this.proxyReady=!0}).catch(p=>{this.logger.error("failed to start envProxy",p),this.proxyReady=!1})}}get isReady(){return!!(this.#t&&this.#e&&this.proxyReady&&!this.isDestroyed)}sync(){if(!this.isReady){this.#r=!0;return}this.#s||(this.#s=!0,queueMicrotask(this.#l))}syncWait(){return this.#i=!0,this.sync(),this.#n?this.#n:(this.#n=ct(this,V.AfterSync).then(a=>(this.#n=void 0,a)),this.#n)}destroy(){let a=this.#t?.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),Et(this),v(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 c=this.#i;this.#i=!1,await this.envProxy.applyChangeTrail(a,c)}catch(c){this.logger.error("failed to apply change trail",c)}finally{d(this,V.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 k=["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"],nr=()=>{let s=Math.random()*4294967295|0,t=Math.random()*4294967295|0,e=Math.random()*4294967295|0,r=Math.random()*4294967295|0;return(k[s&255]+k[s>>8&255]+k[s>>16&255]+k[s>>24&255]+"-"+k[t&255]+k[t>>8&255]+"-"+k[t>>16&15|64]+k[t>>24&255]+"-"+k[e&63|128]+k[e>>8&255]+"-"+k[e>>16&255]+k[e>>24&255]+k[r&255]+k[r>>8&255]+k[r>>16&255]+k[r>>24&255]).toLowerCase()},ks=()=>globalThis?.crypto?.randomUUID?.()??nr();var Pt=class extends Error{constructor(t){super(t),this.name="ViewComponentError"}},Xt=class s{#t;#e;#s;#r;#i=0;get uuid(){return this.#t}get token(){return this.#e}set token(t){t??=U,t!==this.#e&&(this.#e=t,this.#s?.changeToken(this,t))}get parent(){return this.#r}set parent(t){if(t){if(t.#s!==this.#s)throw new Pt("cannot set parent from different context");t.addChild(this)}else this.removeFromParent()}get context(){return this.#s}set context(t){this.#s!=t&&(this.#s&&this.destroy(),this.#s=t,t&&t.addComponent(this))}get order(){return this.#i}set order(t){let e=this.#i;this.#i=t??0,e!==this.#i&&this.#s.changeOrder(this)}constructor(t,e){S(this),e instanceof s&&(e={parent:e}),this.#t=e?.uuid??ks(),this.#e=t,this.#i=e?.order??0,this.#r=e?.parent;let r=e?.context??D.get();if(this.#r&&this.#r.#s!==r)throw new Pt("cannot set parent from different context");this.context=r}isChildOf(t){return this.#r===t}removeFromParent(){this.#r?(this.#s?.removeFromParent(this.uuid,this.#r),this.#r=void 0):this.#s?.moveToRoot(this.uuid)}addChild(t){if(t.#s!==this.#s)throw new Pt("cannot add a child from another context");t.isChildOf(this)||(t.removeFromParent(),t.#r=this,this.#s.addToChildren(this,t))}setProperty(t,e,r){this.#s.setProperty(this,t,e,r)}removeProperty(t){this.#s.removeProperty(this,t)}dispatchShadowObjectsEvent(t,e,r){this.#s.dispatchShadowObjectsEvent(this,t,e,r)}dispatchEvent(t,e,r){if(d(this,t,e),r)for(let i of this.#s.getChildren(this))i.dispatchEvent(t,e,r)}destroy(){this.removeFromParent(),this.#s?.destroyComponent(this),this.#s=void 0}};var Zt="shaeRequestEntParent",te="shaeReRequestEntParent",As="shae-worker",ee="shae-ent",Os="shae-prop",X="token",Z="ns",se="local",Ts="no-autostart",re="no-structured-clone",F="auto-sync",ie="src",ne="name",oe="value",ae="type",he="no-trim";var Rt=new Set(["on","true","yes","local","1"]);var Ps=s=>ut(s.getAttribute(Z)),Mt=(s,t)=>{if(s.hasAttribute(t)){let e=s.getAttribute(t)?.trim()?.toLowerCase()||"1";return Rt.has(e)}return!1};var Rs=(s,t)=>{t.set(Ps(s))},$e=new Set,Ie=!1,or=s=>{$e.add(s),Ie||(Ie=!0,queueMicrotask(()=>{Ie=!1;for(let t of $e)I.get(t)?.sync();$e.clear()}))},tt=class extends HTMLElement{static{this.observedAttributes=[Z]}get ns(){return this.ns$.value}set ns(t){typeof t=="symbol"?this.ns$.set(t):this.ns$.set(ut(t))}constructor(){super(),this.isShaeElement=!0,this.ns$=f(lt),this.ns$.onChange(t=>{typeof t=="string"&&t.length>0?this.getAttribute(Z)!==t&&this.setAttribute(Z,t):this.removeAttribute(Z)}),Rs(this,this.ns$)}attributeChangedCallback(t){t===Z&&Rs(this,this.ns$)}syncShadowObjects(){or(this.ns)}};var le=class extends tt{static{this.observedAttributes=[...tt.observedAttributes,X]}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(t){this.token$.set(t)}#t;constructor(){super(),this.isShaeEntElement=!0,this.componentContext$=f(),this.viewComponent$=f(),this.token$=f(),this.#n=!0,this.#f=()=>{let t=this.findShadowRootHost();t!=null&&this.dispatchEvent(new CustomEvent(te,{bubbles:!0,composed:!0,detail:{requester:this,shadowRootHost:t}}))},this.#d=t=>{let e=t.detail?.requester;if(e===this||!e?.isShaeEntElement||e.ns!==this.ns)return;t.detail?.shadowRootHost&&this.#l()},this.#g=t=>{let e=t.detail?.requester;e!==this&&e?.isShaeEntElement&&e.ns===this.ns&&(t.stopPropagation(),e.#c(this))},this.ns$.onChange(t=>{this.componentContext$.set(D.get(t)),this.isConnected&&this.#l()}),this.#p(),this.token$.onChange(t=>{t==null?this.removeAttribute(X):this.getAttribute(X)!==t&&this.setAttribute(X,t)}),C(()=>{let t=this.viewComponent$.get();if(t){let e=b(t,D.ReRequestParentRoots,()=>this.#h()),r=t.context?.ns;return()=>{e(),t.destroy(),r&&r!==this.ns?I.get(r)?.sync():this.syncShadowObjects()}}}),this.token$.onChange(t=>{let e=this.viewComponent$.value;e&&(e.token=t,this.syncShadowObjects())})}#e;#s(){this.#e?.();let t=this.componentContext$.onChange(e=>{let r=this.token$.value,i=this.viewComponent$.value;i?i.context=e:e&&(i=new Xt(r,{context:e}),this.viewComponent$.set(i)),this.syncShadowObjects()});this.#e=()=>{t()}}#r(){this.#e?.(),this.#e=void 0}#i;#n;findShadowRootHost(){if(this.#n){this.#n=!1;let t=this;for(;t;){if(t.parentElement==null){let e=t.parentNode;e&&(this.#i=e.host);break}t=t.parentElement}}return this.#i}getParentNodeForObserver(){let t=this.parentNode;return t||(t.host??t)}connectedCallback(){this.#n=!0,this.addEventListener("slotchange",this.#f,{capture:!1,passive:!1}),this.addEventListener(Zt,this.#g,{capture:!1,passive:!1}),this.#s(),ke(()=>this.#p()),this.componentContext==null&&this.componentContext$.set(D.get(this.ns)),this.#l(),this.componentContext?.dispatchReRequestParentRoots(),this.#o(),this.syncShadowObjects()}#o(){this.#a();let t=this.getParentNodeForObserver();t&&(this.#t=new MutationObserver((e,r)=>{for(let{target:i,removedNodes:n}of e)if(i===t){for(let o of n)if(o===this){this.#a(),this.onParentChanged(this.getParentNodeForObserver(),t);break}}}),this.#t.observe(t,{childList:!0,subtree:!1,attributes:!1}))}onParentChanged(t,e){this.#c(void 0),this.#l()}#a(){this.#t?.disconnect(),this.#t=void 0}attributeChangedCallback(t){super.attributeChangedCallback(t),t===X&&this.#p()}disconnectedCallback(){this.#n=!0,this.#a(),this.removeEventListener("slotchange",this.#f,{capture:!1}),this.removeEventListener(Zt,this.#g,{capture:!1}),this.#c(void 0),this.componentContext$.set(void 0),this.syncShadowObjects(),this.#r()}#h(){this.isConnected&&(this.#c(void 0),this.#l())}#l(){this.dispatchEvent(new CustomEvent(Zt,{bubbles:!0,composed:!0,detail:{requester:this}}))}#u;#c(t){if(this.entParentNode!==t)if(this.entParentNode&&this.entParentNode.removeEventListener(te,this.#d,{capture:!1}),this.entParentNode=t,this.entParentNode&&this.entParentNode.addEventListener(te,this.#d,{capture:!1,passive:!1}),this.#u?.(),this.#u=void 0,t){let e=C(()=>{let r=this.viewComponent$.get();if(r){let i=t.viewComponent$.get();r.parent=i&&i.context===r.context?i:void 0,r.parent==null&&queueMicrotask(()=>{this.#l()}),this.syncShadowObjects()}});this.#u=()=>e.destroy()}else{let e=this.viewComponent;e.parent&&(e.parent=void 0,this.syncShadowObjects())}}#f;#d;#g;#p(){if(this.hasAttribute(X)){let t=this.getAttribute(X)?.trim()||void 0;this.token$.set(t)}}};customElements.define(ee,le);var ar=s=>{let t=s.parentElement;for(;t;){if(t.isShaeEntElement)return t;t=t.parentElement}},hr=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"]),ue=class extends HTMLElement{static{this.observedAttributes=[ne,oe,ae,he]}get name(){return this.name$.value}get value(){return this.valueOut$.value}set value(t){this.valueIn$.set(t)}get shouldTrim(){return this.shouldTrim$.value}get entNode(){return this.entNode$.value}set entNode(t){this.entNode$.set(t)}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 A("ShaePropElement"),this.#t=()=>{this.entNode$.set(ar(this))},this.#e=()=>{queueMicrotask(()=>{this.isConnected||this.entNode$.set(void 0)})},this.#s=()=>{this.name$.set(this.getAttribute(ne)?.trim()??void 0)},this.#r=()=>{this.valueIn$.set(this.getAttribute(oe))},this.#i=()=>{let t=this.getAttribute(ae)?.trim().toLowerCase();t&&!hr.has(t)&&(this.logger.isWarn&&this.logger.warn(`[${this.name}] unknown type "${t}"`,{shaeProp:this}),t=void 0),this.type$.set(t)},this.#n=()=>{this.shouldTrim$.set(!Mt(this,he))},this.entNode$.onChange(t=>{if(t){let e=j(t.viewComponent$,this.viewComponent$);return()=>{e.destroy()}}else this.viewComponent$.set(void 0)}),C(()=>{let t=this.viewComponent$.get();if(t){let e=this.name$.get();if(e){let r=this.valueOut$.get();this.logger.isDebug&&this.logger.debug(`[${this.name}] view-component set-property`,e,r,t.uuid,{viewComponent:t,shaeProp:this}),t.setProperty(e,r),this.isConnected&&this.entNode?.syncShadowObjects()}}}),C(()=>{let t=this.type$.get(),e=this.shouldTrim$.get(),r=this.valueIn$.get();if(e&&typeof r=="string"&&(r=r.trim()),r=r||void 0,r!=null&&typeof r=="string"&&t)switch(t){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=Rt.has(r.toLowerCase());break;case"[]":case"text[]":case"string[]":r=r.split(/\W+/);break;case"number[]":r=r.split(/\s+/).map(i=>Number(i));break;case"float[]":r=r.split(/\s+/).map(i=>parseFloat(i));break;case"int[]":case"integer[]":r=r.split(/\s+/).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=>Rt.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(/\s+/).map(i=>Number(i)));break;case"float64array":r=new Float64Array(r.split(/\s+/).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 "${t}"`,{value:r,shaeProp:this})}this.valueOut$.set(r)}),O(()=>{this.#s(),this.#r(),this.#i(),this.#n()})}connectedCallback(){O(()=>{this.#t(),this.#s(),this.#r(),this.#i(),this.#n()})}attributeChangedCallback(t){switch(t){case ne:this.#s();break;case oe:this.#r();break;case ae:this.#i();break;case he:this.#n();break}}disconnectedCallback(){this.#e()}#t;#e;#s;#r;#i;#n};customElements.whenDefined(ee).then(()=>customElements.define(Os,ue));var ce,Fe=null,mt=class{static{this.OnFrame=Symbol("onFrame")}#t=0;#e=0;constructor(){if(Fe)return Fe;S(this),Fe=this}start(t){if(t!=null)return Se(this)===0&&this.#r(),b(this,ce.OnFrame,t),this.#e++,()=>{this.stop(t)}}stop(t){v(this,ce.OnFrame,t),Se(this)===0&&this.#i()}#s=t=>{d(this,ce.OnFrame,t),this.#r()};#r(){this.#t=requestAnimationFrame(this.#s)}#i(){cancelAnimationFrame(this.#t),this.#t=0}};ce=mt;var bt="value",Lt=(()=>{let s,t=[],e=[];return class{static{let i=typeof Symbol=="function"&&Symbol.metadata?Object.create(null):void 0;s=[At({name:bt})],kt(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},t,e),i&&Object.defineProperty(this,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:i})}static{this.Value=bt}#t;#e;#s;get value(){return this.#s}set value(i){this.#s=i}constructor(i){this.#t=[],this.#s=J(this,t,void 0),this.value$=J(this,e),z(this,bt),this.value$=T(this,bt),this.value$.onChange(n=>d(this,bt,n)),i&&this.add(...i)}add(...i){return this.#t.push(...i),this.#i(),this.#r(i)}unshift(...i){return this.#t.unshift(...i),this.#i(),this.#r(i)}remove(...i){this.#r(i)()}clear(){this.#t.length=0,this.#i()}dispose(){this.clear(),this.#e?.destroy(),this.#e=void 0,B(this,bt),v(this),this.value$.destroy(),Et(this)}#r(i){return()=>{for(let n of i){let o=this.#t.indexOf(n);o!==-1&&this.#t.splice(o,1)}this.#i()}}#i(){this.#e?.destroy(),this.#t.length===0?(this.#e=void 0,this.value=void 0):(this.#e=C(()=>{let i;for(let n of this.#t){let o=ht(n);if(o!=null){i=o;break}}this.value=i},this.#t),this.#e.run())}}})();var We="onCreate",et="onDestroy",Ms="onParentChanged",Ls="onViewEvent";var ze=new Map,Ue=!1,lr=(s,t)=>{ze.set(s,t),Ue||(Ue=!0,queueMicrotask(()=>{Ue=!1;let e=Array.from(ze.entries());ze.clear();for(let[r,i]of e)r.set(i)}))},fe=class{#t;#e;#s=new Yt;#r=new Map;#i=new Map;#n;#o;#a=new Set;#h=[];#l=0;get kernel(){return this.#t}get uuid(){return this.#e}get order(){return this.#l}set order(t){this.#l!==t&&(this.#l=t,this.#n&&this.parent.resortChildren())}get parentUuid(){return this.#n||void 0}set parentUuid(t){this.#n!==t&&(this.removeFromParent(),this.#n=t||void 0,this.#o=t?this.#t.getEntity(t):void 0,this.#o&&this.#o.addChild(this))}get parent(){return!this.#o&&this.#n&&(this.#o=this.#t.getEntity(this.#n)),this.#o}set parent(t){this.parentUuid=t?.uuid}get hasParent(){return!!this.#n}get children(){return this.#h}constructor(t,e){this.#t=t,this.#e=e,E(this,et,nt.Min,this)}traverse(t){t(this);for(let e of this.#h)e.traverse(t)}onDestroy(){this.#s.clear(),v(this);for(let t of this.#i.values())t.cleanup(),t.signal.destroy();this.#i.clear();for(let t of this.#r.values())t.context.set(void 0),t.unsubscribePathValue(),t.unsubscribeFromParent?.(),t.valuePath.dispose(),t.inherited.destroy(),t.provide.destroy(),t.context.destroy();this.#n=void 0,this.#o=void 0,this.#a.clear(),this.#h.length=0}addChild(t){if(this.#h.length===0){this.#a.add(t.uuid),this.#h.push(t);return}if(this.#a.has(t.uuid))throw new Error(`child with uuid: ${t.uuid} already exists! parentUuid: ${this.uuid}`);this.#a.add(t.uuid),this.#h.push(t),this.resortChildren();for(let[,e]of t.#r)t.#d(e)}resortChildren(){this.#h.sort((t,e)=>t.order-e.order)}removeChild(t){this.#a.has(t.uuid)&&(this.#a.delete(t.uuid),this.#h.splice(this.#h.indexOf(t),1))}removeFromParent(){if(this.#o){this.#o.removeChild(this),this.#o=void 0,this.#n=void 0;for(let[,t]of this.#r)t.unsubscribeFromParent&&(t.unsubscribeFromParent(),t.unsubscribeFromParent=void 0)}}reSubscribeToParentContexts(){for(let[,t]of this.#r)this.#d(t)}dispatchMessageToView(t,e,r,i=!1){this.#t.dispatchMessageToView({uuid:this.#e,type:t,data:e,transferables:r,traverseChildren:i})}dispatchViewEvents(t){for(let{type:e,data:r}of t)d(this,Ls,e,r)}dispatchViewEvent(t,e){this.dispatchViewEvents([{type:t,data:e}])}#u(t){return this.#s.get(t)}getPropertyReader(t){return this.#u(t).get}getPropertyWriter(t){return this.#u(t).set}setProperties(t){this.clearTruthyPropsCache(),O(()=>{for(let[e,r]of t)this.setProperty(e,r)})}setProperty(t,e){this.getPropertyWriter(t)(e)}getProperty(t){return ht(this.getPropertyReader(t))}propKeys(){return Array.from(this.#s.keys())}propEntries(){return Array.from(this.#s.entries()).map(([t,e])=>[t,e.value])}#c;clearTruthyPropsCache(){this.#c=void 0}truthyProps(){if(this.#c)return this.#c.size?this.#c:void 0;let t=new Set;for(let[e,r]of this.#s.entries())if(typeof e=="string"){let i=r.value;i!=null&&i!==!1&&i!==""&&t.add(e)}return this.#c=t,t.size?t:void 0}hasContext(t){return this.#r.has(t)}useContext(t){return this.#f(t).context.get}useParentContext(t){return this.#f(t).inherited.get}provideContext(t){return this.#f(t).provide}provideGlobalContext(t){if(this.#i.has(t))return this.#i.get(t).signal;let e=this.#t.findOrCreateRootContext(t),r=f(),i=e.add(r);return this.#i.set(t,{cleanup:i,signal:r}),r}#f(t){if(this.#r.has(t))return this.#r.get(t);let e=f(),r=f(),i=f(),n=new Lt([r,e]),o=b(n,Lt.Value,a=>{lr(i,a)}),h={name:t,inherited:e,provide:r,context:i,valuePath:n,unsubscribePathValue:o};return this.#r.set(t,h),this.#d(h),h}#d(t){if(t.unsubscribeFromParent?.(),t.unsubscribeFromParent=void 0,this.parent){let e=this.parent.#f(t.name),r=j(e.context,t.inherited);t.unsubscribeFromParent=r.destroy.bind(r)}else{let e=this.#t.findOrCreateRootContext(t.name),r=j(e.value$,t.inherited);t.unsubscribeFromParent=r.destroy.bind(r)}}};var _s=s=>{let t=s.split("@").map(e=>e.trim());if(t.length===2&&t[1])return t[0]?{key:`${t[0]}@${t[1]}`,prop:t[1],token:t[0]}:{key:t[1],prop:t[1]}},de=(s,t)=>{for(let e of t)s.add(e)},ur=(s,t)=>{if(s!=null)for(let e of s.constructors)t.add(e)},_t=class{static get(t){return t??cr}#t=new Map;#e=new Map;#s=new Map;define(t,e){this.#t.has(t)?Cs(this.#t.get(t).constructors,e):this.#t.set(t,{token:t,constructors:[e]})}appendRoute(t,e){let r=_s(t);r?this.#s.has(r.key)?de(this.#s.get(r.key).routes,e):this.#s.set(r.key,{routes:new Set(e),token:r.token}):this.#e.has(t)?de(this.#e.get(t),e):this.#e.set(t,new Set(e))}clearRoute(t){let e=_s(t);e?this.#s.delete(e.key):this.#e.delete(t)}findTokensByRoute(t,e){let r=new Set([t]),i=this.#e.has(t)?[...this.#e.get(t)]:[];for(;i.length;){let n=i.shift();r.has(n)||(r.add(n),this.#e.has(n)&&i.push(...Array.from(this.#e.get(n)).filter(o=>!r.has(o))))}if(e){for(let o of e)this.#s.has(o)&&de(r,this.#s.get(o).routes);let n;do{n=r.size;for(let o of new Set(r))for(let h of e){let a=`${o}@${h}`;this.#s.has(a)&&de(r,this.#s.get(a).routes)}}while(n!==r.size)}return r}findConstructors(t,e){let r=this.findTokensByRoute(t,e),i=new Set;for(let n of r)ur(this.#t.get(n),i);return i.size>0?Array.from(i):void 0}hasToken(t){return this.#t.has(t)}hasRoute(t){return this.#e.has(t)}clear(){this.#t.clear(),this.#e.clear()}},cr=new _t;var G;(function(s){s[s.CreateAndDestroy=0]="CreateAndDestroy",s[s.JustCreate=1]="JustCreate",s[s.DestroyOnly=2]="DestroyOnly"})(G||(G={}));var js=s=>s.displayName||s.name,pe=class{#t;#e;#s;#r;#i;#n;constructor(t){this.logger=new A("Kernel"),this.#t=new Map,this.#e=new Set,this.#i=!0,this.#n=new Map,S(this),this.registry=_t.get(t)}getEntity(t){let e=this.#t.get(t)?.entity;if(!e)throw new Error(`entity with uuid "${t}" not found!`);return e}hasEntity(t){return this.#t.has(t)}traverseLevelOrderBFS(t=!1){if(this.#i){let e=new Map,r=(i,n)=>{let o=this.getEntity(i);e.has(n)?e.get(n).push(o):e.set(n,[o]);for(let h of o.children)r(h.uuid,n+1)};this.#e.forEach(i=>r(i,0)),this.#s=Array.from(e.entries()).sort((i,n)=>i[0]-n[0]).map(([,i])=>i).flat(),this.#r=this.#s.slice().reverse(),this.#i=!1}return t?this.#r:this.#s}getEntityGraph(){return Array.from(this.#e).map(t=>this.getEntityGraphNode(t))}getEntityGraphNode(t){if(!this.#t.has(t))return;let{token:e,entity:r}=this.#t.get(t);return{token:e,entity:r,props:Object.fromEntries(r.propEntries()),children:r.children.map(i=>this.getEntityGraphNode(i.uuid))}}upgradeEntities(){let t=new Map;for(let e of this.traverseLevelOrderBFS(!0))t.set(e.uuid,this.updateShadowObjects(e.uuid,G.DestroyOnly));for(let e of this.traverseLevelOrderBFS(!1))this.updateShadowObjects(e.uuid,G.JustCreate,t.get(e.uuid));t.clear()}run(t){this.logger.isDebug&&this.logger.debug("sync",t),O(()=>{for(let e of t.changeTrail)this.parse(e)})}parse(t){switch(t.type){case m.CreateEntities:this.createEntity(t.uuid,t.token,t.parentUuid,t.order,t.properties),this.#i=!0;break;case m.DestroyEntities:this.destroyEntity(t.uuid),this.#i=!0;break;case m.SetParent:this.setParent(t.uuid,t.parentUuid,t.order),this.#i=!0;break;case m.UpdateOrder:this.updateOrder(t.uuid,t.order),this.#i=!0;break;case m.ChangeProperties:this.changeProperties(t.uuid,t.properties);break;case m.ChangeToken:this.changeToken(t.uuid,t.token);break;case m.SendEvents:this.dispatchEventsToEntity(t.uuid,t.events);break}}createEntity(t,e,r,i=0,n){let o=new fe(this,t);o.order=i;let h={token:e,entity:o,usedConstructors:new Map};this.#t.set(t,h),r&&(o.parentUuid=r),o.hasParent||this.#e.add(t),n&&o.setProperties(n),this.createShadowObjects(t)}destroyEntity(t){if(!this.#t.has(t))return;let{entity:e,usedConstructors:r}=this.#t.get(t);e.removeFromParent(),d(e,et,this),r.clear(),this.#t.delete(e.uuid),this.#e.delete(e.uuid)}setParent(t,e,r=0){let i=this.getEntity(t);i.parentUuid===e&&i.order===r||(i.removeFromParent(),i.order=r,i.parentUuid=e,i.hasParent?this.#e.delete(t):this.#e.add(t),i.reSubscribeToParentContexts(),queueMicrotask(()=>{this.logger.isDebug&&this.logger.debug("entity.onParentChanged",{uuid:t,parentUuid:e,order:r,entity:i}),d(i,Ms,i)}))}updateOrder(t,e){this.getEntity(t).order=e}dispatchEventsToEntity(t,e){this.getEntity(t)?.dispatchViewEvents(e)}changeProperties(t,e){this.getEntity(t).setProperties(e),this.updateShadowObjects(t)}changeToken(t,e){if(!this.#t.has(t))return;let r=this.#t.get(t);r.token!==e&&(r.token=e,this.updateShadowObjects(t))}dispatchMessageToView(t){queueMicrotask(()=>{d(this,yt,t)})}updateShadowObjects(t,e=G.CreateAndDestroy,r){let i=this.#t.get(t);r??=new Set(this.registry.findConstructors(i.token,i.entity.truthyProps()));let n=e===G.CreateAndDestroy||e===G.DestroyOnly,o=e===G.CreateAndDestroy||e===G.JustCreate;if(n){for(let[h,a]of i.usedConstructors)if(!r.has(h)){i.usedConstructors.delete(h);for(let c of a)this.destroyShadowObject(c,i.entity)}}if(o)for(let h of r)i.usedConstructors.has(h)||this.constructShadowObject(h,i);return r}constructShadowObject(t,e){let r=new Set,i=new Set,n=new Map,o=new Map,h=new Map,a=new Map,c=new Map,p=S(new t({entity:e.entity,provideContext(l,u,g){let y=h.get(l);if(y==null){y=f(u,g?{compare:g}:void 0);let P=j(y,e.entity.provideContext(l));i.add(P.destroy.bind(P)),h.set(l,y)}return y},provideGlobalContext(l,u,g){let y=a.get(l);if(y==null){y=f(u,g?{compare:g}:void 0);let P=j(y,e.entity.provideGlobalContext(l));i.add(P.destroy.bind(P)),a.set(l,y)}return y},useContext(l,u){let g=n.get(l);if(g===void 0){g=f(void 0,u?{compare:u}:void 0).get,n.set(l,g);let y=j(e.entity.useContext(l),g);i.add(y.destroy.bind(y))}return g},useParentContext(l,u){let g=o.get(l);if(g===void 0){g=f(void 0,u?{compare:u}:void 0).get,o.set(l,g);let y=j(e.entity.useParentContext(l),g);i.add(y.destroy.bind(y))}return g},useProperty(l,u){let g=c.get(l);if(g===void 0){g=f(void 0,u?{compare:u}:void 0).get,c.set(l,g);let y=j(e.entity.getPropertyReader(l),g);i.add(y.destroy.bind(y))}return g},createEffect(...l){let u=C(...l);return i.add(u.destroy),u},createSignal(...l){let u=f(...l);return i.add(()=>{x(u)}),u},createMemo(...l){let u=Me(...l);return i.add(()=>{x(u)}),u},on(...l){let u=b(...l);return i.add(u),u},once(...l){let u=E(...l);return i.add(u),u},onDestroy(l){r.add(l)}}));return this.logger.isInfo&&this.logger.info("create shadow-object",js(t),{shadowObject:p,entity:e.entity}),E(e.entity,et,nt.Low,()=>{this.logger.isInfo&&this.logger.info("destroy shadow-object",js(t),{shadowObject:p,entity:e.entity});for(let u of r)u();for(let u of i)u();for(let u of n.values())x(u);for(let u of o.values())x(u);for(let u of c.values())x(u);for(let u of h.values())x(u);for(let u of a.values())x(u);r.clear(),i.clear(),n.clear(),o.clear(),c.clear(),h.clear(),a.clear();let l=e.usedConstructors.get(t);l&&(l.delete(p),l.size===0&&e.usedConstructors.delete(t))}),e.usedConstructors.has(t)?e.usedConstructors.get(t).add(p):e.usedConstructors.set(t,new Set([p])),this.attachShadowObject(p,e.entity),p}createShadowObjects(t){let e=this.#t.get(t);this.registry.findConstructors(e.token,e.entity.truthyProps())?.forEach(r=>{this.constructShadowObject(r,e)})}findShadowObjects(t){if(!this.#t.has(t))return[];let{usedConstructors:e}=this.#t.get(t);return Array.from(new Set(Array.from(e.values()).map(r=>Array.from(r)).flat()))}attachShadowObject(t,e){b(e,t),typeof t[We]=="function"&&t[We](e)}destroyShadowObject(t,e){typeof t[et]=="function"&&t[et](e),d(t,et,e),v(e,t)}findOrCreateRootContext(t){let e=this.#n.get(t);return e||(e=new Lt,this.#n.set(t,e)),e}destroy(){for(let t of this.#n.values())t.dispose();this.#n.clear();for(let t of this.traverseLevelOrderBFS().reverse())this.destroyEntity(t.uuid)}};async function Ve(s,t,e,r=!0){if(e.has(t)){console.warn("importModule: skipping already imported module",t);return}else e.add(t);t.extends&&await Promise.all(t.extends.map(n=>Ve(s,n,e,!1)));let{registry:i}=s;if(t.define)for(let[n,o]of Object.entries(t.define))i.define(n,o);if(t.routes)for(let[n,o]of Object.entries(t.routes))i.appendRoute(n,o);await(t.initialize?.({define:(n,o)=>i.define(n,o),kernel:s,registry:i})??Promise.resolve()),r&&s.upgradeEntities()}var ge=s=>(typeof s=="string"&&(s=new URL(s,globalThis.location.href)),s.toString());function Ds(s){return s.map(t=>{if(t.transferables&&t.transferables.length>0){let{transferables:e,...r}=t;return structuredClone(r,{transfer:e})}else return structuredClone(t)})}var ye=class{#t;get registry(){return this.kernel.registry}constructor(t){this.#t=new Set,this.isLocalEnv=!0,this.disableStructuredClone=!1,this.kernel=new pe(t),b(this.kernel,yt,e=>{if(this.onMessageToView!=null){let{type:r,uuid:i,traverseChildren:n}=e,o=structuredClone(e.data,{transfer:e.transferables});this.onMessageToView({type:r,uuid:i,data:o,traverseChildren:n})}})}start(){return Promise.resolve()}applyChangeTrail(t,e){let r={changeTrail:this.disableStructuredClone?t:Ds(t)},i;try{this.kernel.run(r),i=Promise.resolve()}catch(n){i=Promise.reject(n)}return i}async importScript(t){let e=await import(ge(t));e[Le]&&await this.importModule(e[Le])}async importModule(t){return Ve(this.kernel,t,this.#t)}destroy(){this.kernel.destroy(),this.registry.clear(),this.#t.clear()}};function Ge(s){let t=new Blob([s],{type:"text/javascript"}),e=URL.createObjectURL(t),r=new Worker(e);return URL.revokeObjectURL(e),r}function Be(){return Ge('var Rs=Object.defineProperty;var ee=Object.getOwnPropertySymbols;var ze=Object.prototype.hasOwnProperty,Ve=Object.prototype.propertyIsEnumerable;var Fs=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),Ne=t=>{throw TypeError(t)};var de=(t,e,s)=>e in t?Rs(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s,ce=(t,e)=>{for(var s in e||(e={}))ze.call(e,s)&&de(t,s,e[s]);if(ee)for(var s of ee(e))Ve.call(e,s)&&de(t,s,e[s]);return t};var $e=(t,e)=>{var s={};for(var i in t)ze.call(t,i)&&e.indexOf(i)<0&&(s[i]=t[i]);if(t!=null&&ee)for(var i of ee(t))e.indexOf(i)<0&&Ve.call(t,i)&&(s[i]=t[i]);return s};var d=(t,e,s)=>de(t,typeof e!="symbol"?e+"":e,s),fe=(t,e,s)=>e.has(t)||Ne("Cannot "+s);var r=(t,e,s)=>(fe(t,e,"read from private field"),s?s.call(t):e.get(t)),c=(t,e,s)=>e.has(t)?Ne("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,s),f=(t,e,s,i)=>(fe(t,e,"write to private field"),i?i.call(t,s):e.set(t,s),s),m=(t,e,s)=>(fe(t,e,"access private method"),s);var Ie=(t,e,s,i)=>({set _(a){f(t,e,a,s)},get _(){return r(t,e,i)}});var ge=function(t,e){this[0]=t,this[1]=e},Ge=(t,e,s)=>{var i=(n,l,p,b)=>{try{var u=s[n](l),h=(l=u.value)instanceof ge,g=u.done;Promise.resolve(h?l[0]:l).then(y=>h?i(n==="return"?n:"next",l[1]?{done:y.done,value:y.value}:y,p,b):p({value:y,done:g})).catch(y=>i("throw",y,p,b))}catch(y){b(y)}},a=n=>o[n]=l=>new Promise((p,b)=>i(n,l,p,b)),o={};return s=s.apply(t,e),o[Fs("asyncIterator")]=()=>o,a("next"),a("throw"),a("return"),o};var Ue;(function(t){t[t.StructuralChanges=1]="StructuralChanges",t[t.ContentUpdates=2]="ContentUpdates",t[t.Removal=3]="Removal"})(Ue||(Ue={}));var H;(function(t){t[t.CreateEntities=1]="CreateEntities",t[t.DestroyEntities=2]="DestroyEntities",t[t.SetParent=3]="SetParent",t[t.UpdateOrder=4]="UpdateOrder",t[t.ChangeProperties=5]="ChangeProperties",t[t.ChangeToken=6]="ChangeToken",t[t.SendEvents=7]="SendEvents"})(H||(H={}));var $i=Symbol.for("ShadowEntsGlobalNS"),zs="configure",Vs="changeTrail",Ns="destroy",$s="loaded",Be="appliedChangeTrail",pe="importedModule",Is="destroyed",Ee="messageToView",ye="shadowObjects",z="ConsoleLogger",L=`${z}Storage`,rs,as,ns,Gs=!!((ns=(as=(rs=globalThis.location)==null?void 0:rs.host)==null?void 0:as.startsWith("localhost"))!=null&&ns),Wt="localStorage"in globalThis,se=Symbol.for(z),We=!1,qe=t=>{if(typeof t=="boolean")return t;switch(t.toLowerCase()){case"true":case"yes":case"on":return!0;default:return!1}},Se=t=>[Wt?z:void 0,...Array.isArray(t)?t:[t]].filter(Boolean).join(".");function ve(t,e=void 0,s){var o;let i=Se(t),a=Wt?localStorage.getItem(i):(o=globalThis[L])==null?void 0:o[i];return a!=null?e(a):s}function zt(t,e){Wt?localStorage.setItem(Se(t),e):(globalThis[L]==null&&(globalThis[L]={},console.debug(`${z}: Initialize`,{[L]:globalThis[L]})),globalThis[L][Se(t)]=e)}var gt,Nt,v,Us=(v=class{constructor(e){c(this,gt);this.enable=!0,this.namespace=(e||"").trim()||z,We||(v.loadConfig(),We=!0);let s=[this.namespace,"enable"];this.enable=ve(s,qe,this.enable),zt(s,Wt?this.enable?"true":"false":this.enable)}static get isEnabled(){return v.sharedConfig.enable}static get isDebug(){return v.sharedConfig.enable&&v.sharedConfig.debug}static loadConfig(){var e,s,i;Wt?(["enable","debug","info","warn"].forEach(a=>{this.sharedConfig[a]=ve(a,qe,this.sharedConfig[a])}),["debug","info","warn","error"].forEach(a=>{this.sharedStyles[a]=ve(["styles",a],void 0,this.sharedStyles[a])}),v.isDebug&&console.debug(`${z}: Load config from localStorage`,v.sharedConfig),(e=globalThis[z])!=null&&e[se]||((s=globalThis[z])!=null||(globalThis[z]={[se]:!0,get enable(){return v.sharedConfig.enable},set enable(a){v.sharedConfig.enable=a,zt("enable",a?"true":"false")},get debug(){return v.sharedConfig.debug},set debug(a){v.sharedConfig.debug=a,zt("debug",a?"true":"false")},get info(){return v.sharedConfig.info},set info(a){v.sharedConfig.info=a,zt("info",a?"true":"false")},get warn(){return v.sharedConfig.warn},set warn(a){v.sharedConfig.warn=a,zt("warn",a?"true":"false")}}))):(i=globalThis[L])!=null&&i[se]||(globalThis[L]=ce(ce({[se]:!0},v.sharedConfig),globalThis[L]),v.sharedConfig=globalThis[L],v.isDebug&&console.debug(`${z}: Load config from ${L}`,globalThis[L]))}get isEnabled(){return this.enable&&v.sharedConfig.enable}get isDebug(){return this.isEnabled&&v.sharedConfig.debug}get isInfo(){return this.isEnabled&&v.sharedConfig.info}get isWarn(){return this.isEnabled&&v.sharedConfig.warn}debug(...e){m(this,gt,Nt).call(this,"debug",v.sharedStyles.debug,e)}info(...e){m(this,gt,Nt).call(this,"info",v.sharedStyles.info,e)}warn(...e){m(this,gt,Nt).call(this,"warn",v.sharedStyles.warn,e)}error(...e){m(this,gt,Nt).call(this,"error",v.sharedStyles.error,e)}},gt=new WeakSet,Nt=function(e,s,i){console[e](`%c${this.namespace}`,s,...i)},v.sharedConfig={enable:Gs,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"},v.sharedStyles={get debug(){return v.sharedConfig["styles.debug"]},set debug(e){v.sharedConfig["styles.debug"]=e},get info(){return v.sharedConfig["styles.info"]},set info(e){v.sharedConfig["styles.info"]=e},get warn(){return v.sharedConfig["styles.warn"]},set warn(e){v.sharedConfig["styles.warn"]=e},get error(){return v.sharedConfig["styles.error"]},set error(e){v.sharedConfig["styles.error"]=e}},v),Ct="*",ps=1,Te=2,De=4,dt=Symbol.for("eventize"),Bs="[eventize]",he=t=>t===Ct,ys=t=>{switch(typeof t){case"string":case"symbol":return!0;default:return!1}},vs=typeof console<"u",Ws=vs?console[console.warn?"warn":"log"].bind(console,Bs):()=>{},qs=(t,e,s)=>(Object.defineProperty(t,e,{value:s,configurable:!0}),t),Js=0,bs=class{constructor(){d(this,"events",new Map);d(this,"eventNames",new Set)}static publish(t){t.sort((e,s)=>e.order-s.order).forEach(e=>e.emit())}add(t){Array.isArray(t)?t.forEach(e=>this.eventNames.add(e)):this.eventNames.add(t)}remove(t){Array.isArray(t)?t.forEach(e=>this.eventNames.delete(e)):this.eventNames.delete(t),this.clear(t)}clear(t){Array.isArray(t)?t.forEach(e=>this.events.delete(e)):this.events.delete(t)}retain(t,e){this.eventNames.has(t)&&this.events.set(t,{args:e,order:Js++})}isKnown(t){return this.eventNames.has(t)}emit(t,e,s=[]){if(he(t))this.eventNames.forEach(i=>this.emit(i,e,s));else if(this.events.has(t)){let{order:i,args:a}=this.events.get(t);s.push({order:i,emit:()=>e.apply(t,a)})}return s}},ke=(t,e,s,i)=>{if(typeof e=="function"){let a=e.apply(t,s);a!=null&&(i==null||i(a))}},Ks=(t,e,s,i)=>ke(e,e.emit,[t].concat(s),i),Ys=t=>{switch(typeof t){case"function":return ps;case"string":case"symbol":return Te;case"object":return De}},Hs=0,Qs=()=>++Hs,ms=class{constructor(t,e,s,i=null){d(this,"id");d(this,"eventName");d(this,"isCatchEmAll");d(this,"priority");d(this,"listener");d(this,"listenerObject");d(this,"listenerType");d(this,"callAfterApply");d(this,"isRemoved");d(this,"refCount");this.id=Qs(),this.eventName=t,this.isCatchEmAll=he(t),this.listener=s,this.listenerObject=i,this.priority=e,this.listenerType=Ys(s),this.callAfterApply=void 0,this.isRemoved=!1,this.refCount=1}isEqual(t,e=null){if(t===this)return!0;let s=typeof t;return s==="number"&&t===this.id?!0:e===null&&(s==="string"||s==="symbol")?t===Ct||t===this.eventName:this.listener===t&&this.listenerObject===e}apply(t,e,s){if(this.isRemoved)return;let{listener:i,listenerObject:a}=this;switch(this.listenerType){case ps:ke(a,i,e,s),this.callAfterApply&&this.callAfterApply();break;case Te:ke(a,a[i],e,s),this.callAfterApply&&this.callAfterApply();break;case De:{let o=i[t];if(this.isCatchEmAll||this.eventName===t){if(typeof o=="function"){let n=o.apply(i,e);n!=null&&(s==null||s(n))}else Ks(t,i,e,s);this.callAfterApply&&this.callAfterApply()}break}}}},Xs=(t,e)=>t.priority!==e.priority?e.priority-t.priority:t.id-e.id,Je=t=>t==null?void 0:t.slice(0),Ke=(t,e)=>{let s=t.indexOf(e);s>-1&&t.splice(s,1)},Zs=t=>t===De||t===Te,Ae=(t,e,s)=>{let i=t.findIndex(a=>a.isEqual(e,s));i>-1&&(t[i].isRemoved=!0,t.splice(i,1))},ie=(t,e,s)=>{let i=[];for(let a of t)(e==null&&a.listenerObject===s||a.eventName===e&&a.listener===s)&&i.push(a);for(let a of i)Ae(t,a,void 0)},be=t=>{t&&(t.forEach(e=>{e.isRemoved=!0}),t.length=0)},_s=(t,e)=>t.listenerType===e.listenerType?t.priority===e.priority&&t.eventName===e.eventName&&t.listenerObject===e.listenerObject&&t.listener===e.listener:!1,ti=(t,e)=>{if(Zs(t.listenerType))return e.find(s=>_s(t,s))},ei=(t,e)=>{let s=ti(t,e);return s?(s.refCount+=1,s):(e.push(t),e.sort(Xs),t)},si=class{constructor(){d(this,"namedListeners");d(this,"catchEmAllListeners");d(this,"getListenersForEventName",t=>{let e=this.namedListeners.get(t);return e||(e=[],this.namedListeners.set(t,e)),e});this.namedListeners=new Map,this.catchEmAllListeners=[]}add(t){return ei(t,t.isCatchEmAll?this.catchEmAllListeners:this.getListenersForEventName(t.eventName))}remove(t,e,s=!1){e==null&&Array.isArray(t)?t.forEach(i=>this.remove(i,null,s)):t==null||e==null&&he(t)?this.removeAllListeners():e==null&&ys(t)?be(this.namedListeners.get(t)):t instanceof ms?t.isRemoved||(t.refCount-=1,t.refCount<1&&(t.isRemoved=!0,this.namedListeners.forEach(i=>Ke(i,t)),Ke(this.catchEmAllListeners,t))):s?he(t)?ie(this.catchEmAllListeners,Ct,t):this.namedListeners.forEach(i=>ie(i,t,e)):(this.namedListeners.forEach(i=>{Ae(i,t,e),ie(i,void 0,t)}),Ae(this.catchEmAllListeners,t,e),ie(this.catchEmAllListeners,void 0,t))}removeAllListeners(){this.namedListeners.forEach(t=>be(t)),this.namedListeners.clear(),be(this.catchEmAllListeners)}forEach(t,e){let s=Je(this.catchEmAllListeners),i=Je(this.namedListeners.get(t));if(t===Ct||!i||i.length===0)s.forEach(e);else if(s.length===0)i.forEach(e);else{let a=i.length,o=s.length,n=0,l=0;for(;n<a||l<o;){if(n<a){let p=i[n];if(l>=o||p.priority>=s[l].priority){e(p),++n;continue}}l<o&&(e(s[l]),++l)}}}getSubscriptionCount(){let t=this.catchEmAllListeners.length;for(let e of this.namedListeners.values())t+=e.length;return t}},Rt=t=>!!(t&&t[dt]);function qt(t){if(Rt(t))return t;let e=new si,s=new bs;return qs(t,dt,{keeper:s,store:e}),t}var Le={Max:Number.POSITIVE_INFINITY,AAA:1e9,BB:1e6,C:1e3,Default:0,Low:-1e4,Min:Number.NEGATIVE_INFINITY},ii=(t,e,s,i,a,o,n)=>{let l=t.add(new ms(s,i,a,o));return e.emit(s,l,n),l},ri=(t,e,s,i)=>{let a=s.length,o=typeof s[0],n,l,p,b;if(a>=2&&a<=3&&o==="number"?(n=Ct,[l,p,b]=s):a>=3&&a<=4&&typeof s[1]=="number"?[n,l,p,b]=s:(l=Le.Default,o==="string"||o==="symbol"||Array.isArray(s[0])?[n,p,b]=s:(n=Ct,[p,b]=s)),!p&&vs)throw Ws("called with insufficient arguments!",s),"subscribeTo() called with insufficient arguments!";let u=h=>g=>ii(t,e,g,h,p,b,i);return Array.isArray(n)?n.map(h=>Array.isArray(h)?u(h[1])(h[0]):u(l)(h)):u(l)(n)},ws=(t,e,s)=>{let i=[],a=ri(t,e,s,i);return bs.publish(i),a},Ye=t=>e=>{e.callAfterApply=()=>{t==null||t()}},Cs=(t,e)=>Object.assign(()=>x(t,e),Array.isArray(e)?{listeners:e}:{listener:e}),Es=(t,e,s,i)=>{let{store:a,keeper:o}=t[dt];Array.isArray(e)?e.forEach(n=>{a.forEach(n,l=>l.apply(n,s,i)),o.retain(n,s)}):e!==Ct&&(a.forEach(e,n=>{n.apply(e,s,i)}),o.retain(e,s))},ht=(t,...e)=>{let s=qt(t),{store:i,keeper:a}=s[dt];return Cs(s,ws(i,a,e))},O=(t,...e)=>{let s=qt(t),{store:i,keeper:a}=s[dt],o=ws(i,a,e),n=Cs(s,o),l=!1,p=()=>{l||(n(),l=!0)};return Array.isArray(o)?o.forEach(Ye(p)):Ye(p)(o),p},ai=(t,e)=>new Promise(s=>{O(t,e,s)}),x=(t,e,s)=>{if(!Rt(t))throw new Error("object is not eventized");let{store:i,keeper:a}=t[dt],o=typeof e,n=s!=null&&(o==="string"||o==="symbol");i.remove(e,s,n),Array.isArray(e)?a.remove(e.filter(l=>typeof l=="string")):ys(e)&&a.remove(e)},w=(t,e,...s)=>{if(!Rt(t))throw new Error("object is not eventized");Es(t,e,s)},ni=(t,e,...s)=>{if(!Rt(t))throw new Error("object is not eventized");let i=[];return Es(t,e,s,a=>{i.push(a)}),i=i.map(a=>Array.isArray(a)?Promise.all(a):Promise.resolve(a)),i.length>0?Promise.all(i):Promise.resolve()},xe=(t,e)=>{let s=qt(t),{keeper:i}=s[dt];i.add(e)},le=(t,e)=>{if(!Rt(t))throw new Error("object is not eventized");let{keeper:s}=t[dt];s.clear(e)},lt=(()=>{let t=(e={})=>qt(e);return t.inject=(e={})=>(e=qt(e),Object.assign(e,{on:(...s)=>ht(e,...s),once:(...s)=>O(e,...s),onceAsync:s=>ai(e,s),off:(s,i)=>x(e,s,i),emit:(s,...i)=>w(e,s,...i),emitAsync:(s,...i)=>ni(e,s,...i),retain:s=>xe(e,s),retainClear:s=>le(e,s)}),e),t.is=Rt,t})(),Ut=lt(),xt=lt(),At=lt(),Ce,Yt,$t=(Ce=class{constructor(){c(this,Yt,new Set)}batch(t){r(this,Yt).add(t)}run(){w(At,Array.from(r(this,Yt)))}},Yt=new WeakMap,d(Ce,"current"),Ce),oi=()=>$t.current;function ue(t){let e=$t.current;e?e=void 0:e=$t.current=new $t;try{t()}finally{e&&($t.current=void 0,e.run())}}var hi=0;function Ss(){return hi>0}var Y=Symbol.for("signal"),St=Symbol.for("effect"),He=Symbol.for("destroySignal"),Qe=Symbol.for("createEffect"),li=Symbol.for("destroyEffect"),Vt="value",Xe="mute",Ze="unmute",Bt="destroy",et=new Map,B,pt,V,X,W,yt,vt,N,tt,_t=(tt=class{constructor(e){c(this,B,new Set);c(this,pt,new Set);c(this,V,new Map);c(this,X,new WeakMap);c(this,W,new Map);c(this,yt,new Set);c(this,vt,new Set);c(this,N);if(e!=null&&e instanceof tt)return e;if(e!=null||(e=this),et.has(e))return et.get(e);et.set(e,this),lt(this)}static get(e){if(e!=null)return e instanceof tt?e:et.get(e)}static findOrCreate(e){if(e==null)throw new Error("Cannot create a group with a null object");return new tt(e)}static destroy(e){console.warn("SignalGroup.destroy(obj) is deprecated. Use SignalGroup.delete(obj) instead."),tt.delete(e)}static delete(e){var s;(s=et.get(e))==null||s.clear()}static clear(){for(let e of et.values())e.destroy();et.clear()}attachGroup(e){if(e===this)throw new Error("Cannot attach a group to itself");return r(this,B).add(e),r(e,N)&&r(e,N)!==this&&r(r(e,N),B).delete(e),f(e,N,this),e}detachGroup(e){return e!==this&&r(this,B).has(e)&&(r(this,B).delete(e),f(e,N,void 0)),e}attachSignal(e){let s=E(e);if(s!=null&&s.destroyed)throw new Error("Cannot attach a destroyed signal to a group");return s&&r(this,pt).add(s),e}attachSignalByName(e,s){if(s){this.attachSignal(s);let i=E(s);r(this,V).set(e,i),r(this,W).has(e)?r(this,W).get(e).push(i):r(this,W).set(e,[i]),r(this,X).has(i)?r(this,X).get(i).add(e):r(this,X).set(i,new Set([e]))}else r(this,V).delete(e);return s}hasSignal(e){var s;return r(this,V).has(e)||((s=r(this,N))==null?void 0:s.hasSignal(e))}signal(e){var s,i,a;return(a=(s=r(this,V).get(e))==null?void 0:s.object)!=null?a:(i=r(this,N))==null?void 0:i.signal(e)}detachSignal(e){let s=E(e);if(s&&(r(this,pt).delete(s),r(this,X).has(s))){let i=r(this,X).get(s);for(let a of i)if(r(this,W).has(a)){let o=r(this,W).get(a);o.splice(o.indexOf(s),1),o.length===0?(r(this,V).delete(a),r(this,W).delete(a)):r(this,V).get(a)===s&&r(this,V).set(a,o.at(-1))}i.clear(),r(this,X).delete(s)}return e}attachEffect(e){return r(this,yt).add(e),e}runEffects(){for(let e of r(this,yt))e.run();for(let e of r(this,B))e.runEffects()}attachLink(e){if(e!=null&&e.isDestroyed)throw new Error("Cannot attach a destroyed link to a group");return e&&r(this,vt).add(e),e}detachLink(e){return e&&r(this,vt).delete(e),e}destroy(){console.warn("SignalGroup#destroy is deprecated. Use SignalGroup#clear instead."),this.clear()}clear(){var e;w(this,Bt,this),x(this);for(let s of r(this,B))s.destroy();for(let s of r(this,yt))s.destroy();for(let s of r(this,pt))U(s);for(let s of r(this,vt))s.destroy();r(this,B).clear(),r(this,pt).clear(),r(this,V).clear(),r(this,W).clear(),r(this,yt).clear(),r(this,vt).clear(),(e=r(this,N))==null||e.detachGroup(this),et.delete(this)}},B=new WeakMap,pt=new WeakMap,V=new WeakMap,X=new WeakMap,W=new WeakMap,yt=new WeakMap,vt=new WeakMap,N=new WeakMap,tt),os,ui=(os=St,class{constructor(t){d(this,os);d(this,"run",()=>{var t;return(t=this[St])==null?void 0:t.run()});d(this,"destroy",()=>{var t;(t=this[St])==null||t.destroy(),this[St]=void 0});this[St]=t,O(t,Os.Destroy,()=>{this[St]=void 0})}}),Ht,Qt,hs,ks=(hs=class{constructor(t="id",e=1){c(this,Ht);c(this,Qt);f(this,Ht,t),f(this,Qt,e)}make(){return Symbol(`${r(this,Ht)}${Ie(this,Qt)._++}`)}},Ht=new WeakMap,Qt=new WeakMap,hs),Oe=[],As=()=>Oe.at(-1),di=(t,e)=>{Oe.push(t);try{return e()}finally{Oe.pop()}},ci=t=>t!=null&&typeof t.then=="function",A,st,it,bt,mt,Pt,Os=(A=class{constructor(e,s){d(this,"id");d(this,"callback");c(this,st);c(this,it,new Set);c(this,bt,new Set);d(this,"parentEffect");d(this,"childEffects",[]);d(this,"curChildEffectSlot",0);d(this,"autorun",!0);d(this,"shouldRun",!0);c(this,mt);c(this,Pt,!1);d(this,"run",()=>{if(r(this,Pt)||!this.shouldRun)return;let e=oi();e?e.batch(this.id):(this.runCleanupCallback(),this.curChildEffectSlot=0,this.shouldRun=!1,this.hasStaticDeps()?f(this,st,this.callback()):f(this,st,di(this,this.callback)))});d(this,"destroy",()=>{r(this,Pt)||(w(this,A.Destroy,this),x(this),w(At,li,this),this.runCleanupCallback(),x(Ut,this),x(At,this),x(xt,this),f(this,Pt,!0),r(this,it).clear(),r(this,bt).clear(),this.childEffects.forEach(e=>{e.destroy()}),this.childEffects.length=0,--A.count)});var a;lt(this),this.callback=e;let i;(s==null?void 0:s.attach)!=null&&(i=_t.findOrCreate(s.attach),i.attachEffect(this)),this.autorun=(a=s==null?void 0:s.autorun)!=null?a:!0,f(this,mt,s!=null&&s.dependencies?s.dependencies.map(o=>{switch(typeof o){case"string":case"symbol":return i.signal(o);default:return o}}):void 0),this.id=A.idGen.make(),ht(At,this.id,"recall",this),++A.count}hasStaticDeps(){return r(this,mt)!=null&&r(this,mt).length>0}saveSignalsFromDeps(){for(let e of r(this,mt))this.whenSignalIsRead(E(e).id)}static createEffect(e,s,i){let a=Array.isArray(s)?s:void 0,o=a?i!=null?i:{dependencies:a}:s;o&&a&&(o.dependencies=a);let n,l=As();return l!=null?(n=l.getCurrentChildEffect(),n==null&&(n=new A(e,o),l.attachChildEffect(n),w(At,Qe,n)),l.curChildEffectSlot++):(n=new A(e,o),w(At,Qe,n)),n.hasStaticDeps()?n.saveSignalsFromDeps():n.autorun&&n.run(),new ui(n)}getCurrentChildEffect(){return this.childEffects[this.curChildEffectSlot]}attachChildEffect(e){this.childEffects.push(e),this.parentEffect=this}recall(){this.shouldRun=!0,this.autorun&&this.run()}whenSignalIsRead(e){r(this,it).has(e)||(r(this,it).add(e),ht(Ut,e,"recall",this),O(xt,e,He,this))}[He](e){!r(this,bt).has(e)&&r(this,it).has(e)&&(r(this,bt).add(e),x(Ut,e,this),r(this,bt).size===r(this,it).size&&this.destroy())}runCleanupCallback(){if(r(this,st)!=null){let e=r(this,st);f(this,st,void 0),ci(e)?Promise.resolve(e).then(s=>{typeof s=="function"&&s()}):e()}}},st=new WeakMap,it=new WeakMap,bt=new WeakMap,mt=new WeakMap,Pt=new WeakMap,d(A,"idGen",new ks("ef")),d(A,"Destroy","destroy"),d(A,"count",0),A),te=(...t)=>Os.createEffect(...t),Jt=new WeakMap,fi=t=>{let e=Jt.get(t);return e||(e={},Jt.set(t,e)),e},Kt=(t,e)=>{var s,i;return(i=(s=Jt.get(t))==null?void 0:s.signals)==null?void 0:i.get(e)},gi=(t,e,s)=>{var a;let i=fi(t);(a=i.signals)!=null||(i.signals=new Map),i.signals.set(e,s)};function pi(...t){for(let e of t)if(Jt.has(e)){let s=Jt.get(e);if(s.signals){for(let i of s.signals.values())U(i);s.signals.clear(),s.signals=void 0}}}function yi(t){let e=E(Fe(t)?t:Kt(...t));e!=null&&!e.muted&&!e.destroyed&&Pe(e.id,e.value,{touch:!0})}function Re(t){var e,s;return Fe(t)?(e=E(t))==null?void 0:e.value:(s=E(Kt(...t)))==null?void 0:s.value}var ls,vi=(ls=Y,class{constructor(t){d(this,ls);this[Y]=t}get get(){return this[Y].reader}get set(){return this[Y].writer}get value(){return Re(this.get)}set value(t){this.set(t)}onChange(t){let{destroy:e}=te(()=>t(this.value),[this.get]);return e}get muted(){return this[Y].muted}set muted(t){this[Y].muted=t}touch(){yi(this)}destroy(){U(this)}}),bi=new ks("si");function _e(t){var e;Ss()||((e=As())==null||e.whenSignalIsRead(t))}function Pe(t,e,s){Ss()||w(Ut,t,e,s)}var Fe=t=>t!=null&&t[Y]!=null,mi=t=>{let e=s=>{var i;return s?te(()=>(t.destroyed||_e(t.id),s(t.value)),[e]):t.destroyed||((i=t.beforeRead)==null||i.call(t),_e(t.id)),t.value};return Object.defineProperty(e,Y,{value:t}),e},wt,$,Ps=(wt=class{constructor(e,s){d(this,"id");d(this,"lazy");d(this,"compare");d(this,"beforeRead");d(this,"muted",!1);d(this,"destroyed",!1);c(this,$);d(this,"valueFn");d(this,"reader");d(this,"writer",(e,s)=>{var o,n,l,p;let i=(o=s==null?void 0:s.lazy)!=null?o:!1,a=(l=(n=s==null?void 0:s.compare)!=null?n:this.compare)!=null?l:(b,u)=>b===u;if((i!==this.lazy||i&&e!==this.valueFn||!i&&!a(e,r(this,$)))&&(i?(f(this,$,void 0),this.valueFn=e,this.lazy=!0):(f(this,$,e),this.valueFn=void 0,this.lazy=!1),!this.muted&&!this.destroyed)){Pe(this.id,r(this,$));return}(p=s==null?void 0:s.touch)!=null&&p&&Pe(this.id,r(this,$),{touch:!0})});d(this,"object");this.id=bi.make(),++wt.instanceCount,this.lazy=e,this.lazy?(this.value=void 0,this.valueFn=s):(this.value=s,this.valueFn=void 0),this.reader=mi(this),this.object=new vi(this)}get[Y](){return this}get value(){return this.lazy&&(f(this,$,this.valueFn()),this.valueFn=void 0,this.lazy=!1),r(this,$)}set value(e){f(this,$,e)}},$=new WeakMap,d(wt,"instanceCount",0),wt),E=t=>t==null?void 0:t[Y];function k(t=void 0,e){var i;let s;if(Fe(t))s=E(t);else{let a=(i=e==null?void 0:e.lazy)!=null?i:!1;s=new Ps(a,t),s.beforeRead=e==null?void 0:e.beforeRead,s.compare=e==null?void 0:e.compare}return(e==null?void 0:e.attach)!=null&&_t.findOrCreate(e.attach).attachSignal(s),s.object}var U=(...t)=>{for(let e of t){let s=E(e);s!=null&&!s.destroyed&&(s.destroyed=!0,s.beforeRead=void 0,--Ps.instanceCount,w(xt,s.id,s.id))}};function wi(t,e){let s=k(),i=(e==null?void 0:e.attach)!=null?_t.findOrCreate(e.attach):void 0;i!=null&&(e!=null&&e.name?i.attachSignalByName(e.name,s):i.attachSignal(s));let a=te(()=>s.set(t()),{autorun:!1,attach:i}),o=E(s);return o.beforeRead=a.run,O(xt,o.id,a.destroy),s.get}var S,Mt,us,Ms=(us=class{constructor(t){c(this,S,!1);c(this,Mt);d(this,"source");d(this,"lastValue");d(this,"isDestroyed",!1);lt(this),this.source=E(t),f(this,Mt,ht(Ut,this.source.id,(e,s)=>{!r(this,S)&&!this.isDestroyed&&((s==null?void 0:s.touch)===!0?this.touch():this.write())})),O(xt,this.source.id,()=>this.destroy())}attach(t){let e=_t.findOrCreate(t);return e.attachLink(this),O(this,Bt,()=>{e.detachLink(this)}),e}nextValue(){return new Promise((t,e)=>{let s=[],i=()=>s.forEach(a=>{a()});s.push(O(this,Vt,a=>{i(),t(a)}),O(this,Bt,()=>{i(),e()}))})}asyncValues(t){return Ge(this,null,function*(){let e=0;for(;!this.isDestroyed;)try{let s=yield new ge(this.nextValue());if(t&&t(s,e++))break;xe(this,Vt),yield s}catch(s){break}le(this,Vt)})}destroy(){var t;this.isDestroyed||((t=r(this,Mt))==null||t.call(this),f(this,Mt,void 0),w(this,Bt,this),le(this,Vt),x(this),this.lastValue=void 0,this.isDestroyed=!0,Object.freeze(this))}get isMuted(){return r(this,S)}mute(){return!this.isDestroyed&&!r(this,S)&&(f(this,S,!0),w(this,Xe,this)),this}unmute(){return!this.isDestroyed&&r(this,S)&&(f(this,S,!1),w(this,Ze,this)),this}toggle(){return this.isDestroyed||(f(this,S,!r(this,S)),w(this,r(this,S)?Xe:Ze,this)),r(this,S)}updateValue(t){if(!r(this,S)&&!this.isDestroyed){let{value:e}=this.source;t(e),w(this,Vt,e),this.lastValue=e}}},S=new WeakMap,Mt=new WeakMap,us),Ci=class extends Ms{constructor(e,s){super(e);d(this,"target");this.target=E(s),O(xt,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)})}},Ei=class extends Ms{constructor(e,s){super(e);d(this,"target");this.target=s,this.touch()}touch(){return this.updateValue(e=>{this.target(e)}),this}write(){this.updateValue(e=>{this.target(e)})}},re=new Map;function ft(t,e,s){var b;let i=E(t),a;if(re.has(i)){a=re.get(i);let u=(b=E(e))!=null?b:e;if(a.has(u))return a.get(u)}else a=new Map,re.set(i,a);let o=E(e),n=o!=null?new Ci(t,o):new Ei(t,e),l=s==null?void 0:s.attach;l&&n.attach(l);let p=o!=null?o:e;return a.set(p,n),O(n,Bt,()=>{a.delete(p),a.size===0&&re.delete(i)}),n}var j,jt,Si=(jt=class{constructor(){c(this,j,new Map)}static fromProps(e,s){let i=new jt,a=s?s.map(o=>[o,e[o]]):Object.entries(e);for(let[o,n]of a)r(i,j).set(o,k(n));return i}keys(){return r(this,j).keys()}signals(){return r(this,j).values()}entries(){return r(this,j).entries()}clear(){for(let e of r(this,j).values())e.destroy();r(this,j).clear()}has(e){return r(this,j).has(e)}get(e){if(!r(this,j).has(e)){let s=k();return r(this,j).set(e,s),s}return r(this,j).get(e)}update(e){e.size&&ue(()=>{for(let[s,i]of e.entries())this.get(s).set(i)})}updateFromProps(e,s){ue(()=>{let i=s?s.map(a=>[a,e[a]]):Object.entries(e);for(let[a,o]of i)this.get(a).set(o)})}},j=new WeakMap,jt);function ki(t,e,s,i,a,o){function n(Ft){if(Ft!==void 0&&typeof Ft!="function")throw new TypeError("Function expected");return Ft}for(var l=i.kind,p=l==="getter"?"get":l==="setter"?"set":"value",b=!e&&t?i.static?t:t.prototype:null,u=e||(b?Object.getOwnPropertyDescriptor(b,i.name):{}),h,g=!1,y=s.length-1;y>=0;y--){var M={};for(var Et in i)M[Et]=Et==="access"?{}:i[Et];for(var Et in i.access)M.access[Et]=i.access[Et];M.addInitializer=function(Ft){if(g)throw new TypeError("Cannot add initializers after decoration has completed");o.push(n(Ft||null))};var ct=(0,s[y])(l==="accessor"?{get:u.get,set:u.set}:u[p],M);if(l==="accessor"){if(ct===void 0)continue;if(ct===null||typeof ct!="object")throw new TypeError("Object expected");(h=n(ct.get))&&(u.get=h),(h=n(ct.set))&&(u.set=h),(h=n(ct.init))&&a.unshift(h)}else(h=n(ct))&&(l==="field"?a.unshift(h):u[p]=h)}b&&Object.defineProperty(b,i.name,u),g=!0}function ts(t,e,s){for(var i=arguments.length>2,a=0;a<e.length;a++)s=i?e[a].call(t,s):e[a].call(t);return i?s:void 0}function Ai(t){return function(e,s){var o;let i=(t==null?void 0:t.name)||s.name,a=!!((o=t==null?void 0:t.readAsValue)!=null&&o);return{get(){let n=Kt(this,i);if(n)return a?n.value:n.get()},set(n){var l;(l=Kt(this,i))==null||l.set(n)},init(n){let l=k(n,t);return gi(this,i,l),_t.findOrCreate(this).attachSignalByName(i,l),l.value}}}}var kt="value",Me=(()=>{var i,a,o,n,ne,It,b;let t,e=[],s=[];return b=class{constructor(h){c(this,n);c(this,i);c(this,a);c(this,o);f(this,i,[]),f(this,o,ts(this,e,void 0)),this.value$=ts(this,s),xe(this,kt),this.value$=Kt(this,kt),this.value$.onChange(g=>w(this,kt,g)),h&&this.add(...h)}get value(){return r(this,o)}set value(h){f(this,o,h)}add(...h){return r(this,i).push(...h),m(this,n,It).call(this),m(this,n,ne).call(this,h)}unshift(...h){return r(this,i).unshift(...h),m(this,n,It).call(this),m(this,n,ne).call(this,h)}remove(...h){m(this,n,ne).call(this,h)()}clear(){r(this,i).length=0,m(this,n,It).call(this)}dispose(){var h;this.clear(),(h=r(this,a))==null||h.destroy(),f(this,a,void 0),le(this,kt),x(this),this.value$.destroy(),pi(this)}},i=new WeakMap,a=new WeakMap,o=new WeakMap,n=new WeakSet,ne=function(h){return()=>{for(let g of h){let y=r(this,i).indexOf(g);y!==-1&&r(this,i).splice(y,1)}m(this,n,It).call(this)}},It=function(){var h;(h=r(this,a))==null||h.destroy(),r(this,i).length===0?(f(this,a,void 0),this.value=void 0):(f(this,a,te(()=>{let g;for(let y of r(this,i)){let M=Re(y);if(M!=null){g=M;break}}this.value=g},r(this,i))),r(this,a).run())},(()=>{let h=typeof Symbol=="function"&&Symbol.metadata?Object.create(null):void 0;t=[Ai({name:kt})],ki(b,null,t,{kind:"accessor",name:"value",static:!1,private:!1,access:{has:g=>"value"in g,get:g=>g.value,set:(g,y)=>{g.value=y}},metadata:h},e,s),h&&Object.defineProperty(b,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:h})})(),b.Value=kt,b})(),es="onCreate",Ot="onDestroy",Oi="onParentChanged",Pi="onViewEvent",me=new Map,we=!1,Mi=(t,e)=>{me.set(t,e),we||(we=!0,queueMicrotask(()=>{we=!1;let s=Array.from(me.entries());me.clear();for(let[i,a]of s)i.set(a)}))},q,Tt,rt,I,at,R,T,Z,F,Dt,P,je,nt,Gt,oe,ds,ji=(ds=class{constructor(t,e){c(this,P);c(this,q);c(this,Tt);c(this,rt,new Si);c(this,I,new Map);c(this,at,new Map);c(this,R);c(this,T);c(this,Z,new Set);c(this,F,[]);c(this,Dt,0);c(this,nt);f(this,q,t),f(this,Tt,e),O(this,Ot,Le.Min,this)}get kernel(){return r(this,q)}get uuid(){return r(this,Tt)}get order(){return r(this,Dt)}set order(t){r(this,Dt)!==t&&(f(this,Dt,t),r(this,R)&&this.parent.resortChildren())}get parentUuid(){return r(this,R)||void 0}set parentUuid(t){r(this,R)!==t&&(this.removeFromParent(),f(this,R,t||void 0),f(this,T,t?r(this,q).getEntity(t):void 0),r(this,T)&&r(this,T).addChild(this))}get parent(){return!r(this,T)&&r(this,R)&&f(this,T,r(this,q).getEntity(r(this,R))),r(this,T)}set parent(t){this.parentUuid=t==null?void 0:t.uuid}get hasParent(){return!!r(this,R)}get children(){return r(this,F)}traverse(t){t(this);for(let e of r(this,F))e.traverse(t)}onDestroy(){var t;r(this,rt).clear(),x(this);for(let e of r(this,at).values())e.cleanup(),e.signal.destroy();r(this,at).clear();for(let e of r(this,I).values())e.context.set(void 0),e.unsubscribePathValue(),(t=e.unsubscribeFromParent)==null||t.call(e),e.valuePath.dispose(),e.inherited.destroy(),e.provide.destroy(),e.context.destroy();f(this,R,void 0),f(this,T,void 0),r(this,Z).clear(),r(this,F).length=0}addChild(t){var e;if(r(this,F).length===0){r(this,Z).add(t.uuid),r(this,F).push(t);return}if(r(this,Z).has(t.uuid))throw new Error(`child with uuid: ${t.uuid} already exists! parentUuid: ${this.uuid}`);r(this,Z).add(t.uuid),r(this,F).push(t),this.resortChildren();for(let[,s]of r(t,I))m(e=t,P,oe).call(e,s)}resortChildren(){r(this,F).sort((t,e)=>t.order-e.order)}removeChild(t){r(this,Z).has(t.uuid)&&(r(this,Z).delete(t.uuid),r(this,F).splice(r(this,F).indexOf(t),1))}removeFromParent(){if(r(this,T)){r(this,T).removeChild(this),f(this,T,void 0),f(this,R,void 0);for(let[,t]of r(this,I))t.unsubscribeFromParent&&(t.unsubscribeFromParent(),t.unsubscribeFromParent=void 0)}}reSubscribeToParentContexts(){for(let[,t]of r(this,I))m(this,P,oe).call(this,t)}dispatchMessageToView(t,e,s,i=!1){r(this,q).dispatchMessageToView({uuid:r(this,Tt),type:t,data:e,transferables:s,traverseChildren:i})}dispatchViewEvents(t){for(let{type:e,data:s}of t)w(this,Pi,e,s)}dispatchViewEvent(t,e){this.dispatchViewEvents([{type:t,data:e}])}getPropertyReader(t){return m(this,P,je).call(this,t).get}getPropertyWriter(t){return m(this,P,je).call(this,t).set}setProperties(t){this.clearTruthyPropsCache(),ue(()=>{for(let[e,s]of t)this.setProperty(e,s)})}setProperty(t,e){this.getPropertyWriter(t)(e)}getProperty(t){return Re(this.getPropertyReader(t))}propKeys(){return Array.from(r(this,rt).keys())}propEntries(){return Array.from(r(this,rt).entries()).map(([t,e])=>[t,e.value])}clearTruthyPropsCache(){f(this,nt,void 0)}truthyProps(){if(r(this,nt))return r(this,nt).size?r(this,nt):void 0;let t=new Set;for(let[e,s]of r(this,rt).entries())if(typeof e=="string"){let i=s.value;i!=null&&i!==!1&&i!==""&&t.add(e)}return f(this,nt,t),t.size?t:void 0}hasContext(t){return r(this,I).has(t)}useContext(t){return m(this,P,Gt).call(this,t).context.get}useParentContext(t){return m(this,P,Gt).call(this,t).inherited.get}provideContext(t){return m(this,P,Gt).call(this,t).provide}provideGlobalContext(t){if(r(this,at).has(t))return r(this,at).get(t).signal;let e=r(this,q).findOrCreateRootContext(t),s=k(),i=e.add(s);return r(this,at).set(t,{cleanup:i,signal:s}),s}},q=new WeakMap,Tt=new WeakMap,rt=new WeakMap,I=new WeakMap,at=new WeakMap,R=new WeakMap,T=new WeakMap,Z=new WeakMap,F=new WeakMap,Dt=new WeakMap,P=new WeakSet,je=function(t){return r(this,rt).get(t)},nt=new WeakMap,Gt=function(t){if(r(this,I).has(t))return r(this,I).get(t);let e=k(),s=k(),i=k(),a=new Me([s,e]),o=ht(a,Me.Value,l=>{Mi(i,l)}),n={name:t,inherited:e,provide:s,context:i,valuePath:a,unsubscribePathValue:o};return r(this,I).set(t,n),m(this,P,oe).call(this,n),n},oe=function(t){var e,s;if((e=t.unsubscribeFromParent)==null||e.call(t),t.unsubscribeFromParent=void 0,this.parent){let i=m(s=this.parent,P,Gt).call(s,t.name),a=ft(i.context,t.inherited);t.unsubscribeFromParent=a.destroy.bind(a)}else{let i=r(this,q).findOrCreateRootContext(t.name),a=ft(i.value$,t.inherited);t.unsubscribeFromParent=a.destroy.bind(a)}},ds);function Ti(t,e){t.indexOf(e)===-1&&t.push(e)}var ss=t=>{let e=t.split("@").map(s=>s.trim());if(e.length===2&&e[1])return e[0]?{key:`${e[0]}@${e[1]}`,prop:e[1],token:e[0]}:{key:e[1],prop:e[1]}},ae=(t,e)=>{for(let s of e)t.add(s)},Di=(t,e)=>{if(t!=null)for(let s of t.constructors)e.add(s)},_,D,G,cs,js=(cs=class{constructor(){c(this,_,new Map);c(this,D,new Map);c(this,G,new Map)}static get(t){return t!=null?t:Li}define(t,e){r(this,_).has(t)?Ti(r(this,_).get(t).constructors,e):r(this,_).set(t,{token:t,constructors:[e]})}appendRoute(t,e){let s=ss(t);s?r(this,G).has(s.key)?ae(r(this,G).get(s.key).routes,e):r(this,G).set(s.key,{routes:new Set(e),token:s.token}):r(this,D).has(t)?ae(r(this,D).get(t),e):r(this,D).set(t,new Set(e))}clearRoute(t){let e=ss(t);e?r(this,G).delete(e.key):r(this,D).delete(t)}findTokensByRoute(t,e){let s=new Set([t]),i=r(this,D).has(t)?[...r(this,D).get(t)]:[];for(;i.length;){let a=i.shift();s.has(a)||(s.add(a),r(this,D).has(a)&&i.push(...Array.from(r(this,D).get(a)).filter(o=>!s.has(o))))}if(e){for(let o of e)r(this,G).has(o)&&ae(s,r(this,G).get(o).routes);let a;do{a=s.size;for(let o of new Set(s))for(let n of e){let l=`${o}@${n}`;r(this,G).has(l)&&ae(s,r(this,G).get(l).routes)}}while(a!==s.size)}return s}findConstructors(t,e){let s=this.findTokensByRoute(t,e),i=new Set;for(let a of s)Di(r(this,_).get(a),i);return i.size>0?Array.from(i):void 0}hasToken(t){return r(this,_).has(t)}hasRoute(t){return r(this,D).has(t)}clear(){r(this,_).clear(),r(this,D).clear()}},_=new WeakMap,D=new WeakMap,G=new WeakMap,cs),Li=new js,Q;(function(t){t[t.CreateAndDestroy=0]="CreateAndDestroy",t[t.JustCreate=1]="JustCreate",t[t.DestroyOnly=2]="DestroyOnly"})(Q||(Q={}));var is=t=>t.displayName||t.name,C,J,Lt,Xt,K,ot,fs,xi=(fs=class{constructor(t){c(this,C);c(this,J);c(this,Lt);c(this,Xt);c(this,K);c(this,ot);this.logger=new Us("Kernel"),f(this,C,new Map),f(this,J,new Set),f(this,K,!0),f(this,ot,new Map),lt(this),this.registry=js.get(t)}getEntity(t){var s;let e=(s=r(this,C).get(t))==null?void 0:s.entity;if(!e)throw new Error(`entity with uuid "${t}" not found!`);return e}hasEntity(t){return r(this,C).has(t)}traverseLevelOrderBFS(t=!1){if(r(this,K)){let e=new Map,s=(i,a)=>{let o=this.getEntity(i);e.has(a)?e.get(a).push(o):e.set(a,[o]);for(let n of o.children)s(n.uuid,a+1)};r(this,J).forEach(i=>s(i,0)),f(this,Lt,Array.from(e.entries()).sort((i,a)=>i[0]-a[0]).map(([,i])=>i).flat()),f(this,Xt,r(this,Lt).slice().reverse()),f(this,K,!1)}return t?r(this,Xt):r(this,Lt)}getEntityGraph(){return Array.from(r(this,J)).map(t=>this.getEntityGraphNode(t))}getEntityGraphNode(t){if(!r(this,C).has(t))return;let{token:e,entity:s}=r(this,C).get(t);return{token:e,entity:s,props:Object.fromEntries(s.propEntries()),children:s.children.map(i=>this.getEntityGraphNode(i.uuid))}}upgradeEntities(){let t=new Map;for(let e of this.traverseLevelOrderBFS(!0))t.set(e.uuid,this.updateShadowObjects(e.uuid,Q.DestroyOnly));for(let e of this.traverseLevelOrderBFS(!1))this.updateShadowObjects(e.uuid,Q.JustCreate,t.get(e.uuid));t.clear()}run(t){this.logger.isDebug&&this.logger.debug("sync",t),ue(()=>{for(let e of t.changeTrail)this.parse(e)})}parse(t){switch(t.type){case H.CreateEntities:this.createEntity(t.uuid,t.token,t.parentUuid,t.order,t.properties),f(this,K,!0);break;case H.DestroyEntities:this.destroyEntity(t.uuid),f(this,K,!0);break;case H.SetParent:this.setParent(t.uuid,t.parentUuid,t.order),f(this,K,!0);break;case H.UpdateOrder:this.updateOrder(t.uuid,t.order),f(this,K,!0);break;case H.ChangeProperties:this.changeProperties(t.uuid,t.properties);break;case H.ChangeToken:this.changeToken(t.uuid,t.token);break;case H.SendEvents:this.dispatchEventsToEntity(t.uuid,t.events);break}}createEntity(t,e,s,i=0,a){let o=new ji(this,t);o.order=i;let n={token:e,entity:o,usedConstructors:new Map};r(this,C).set(t,n),s&&(o.parentUuid=s),o.hasParent||r(this,J).add(t),a&&o.setProperties(a),this.createShadowObjects(t)}destroyEntity(t){if(!r(this,C).has(t))return;let{entity:e,usedConstructors:s}=r(this,C).get(t);e.removeFromParent(),w(e,Ot,this),s.clear(),r(this,C).delete(e.uuid),r(this,J).delete(e.uuid)}setParent(t,e,s=0){let i=this.getEntity(t);i.parentUuid===e&&i.order===s||(i.removeFromParent(),i.order=s,i.parentUuid=e,i.hasParent?r(this,J).delete(t):r(this,J).add(t),i.reSubscribeToParentContexts(),queueMicrotask(()=>{this.logger.isDebug&&this.logger.debug("entity.onParentChanged",{uuid:t,parentUuid:e,order:s,entity:i}),w(i,Oi,i)}))}updateOrder(t,e){this.getEntity(t).order=e}dispatchEventsToEntity(t,e){var s;(s=this.getEntity(t))==null||s.dispatchViewEvents(e)}changeProperties(t,e){this.getEntity(t).setProperties(e),this.updateShadowObjects(t)}changeToken(t,e){if(!r(this,C).has(t))return;let s=r(this,C).get(t);s.token!==e&&(s.token=e,this.updateShadowObjects(t))}dispatchMessageToView(t){queueMicrotask(()=>{w(this,Ee,t)})}updateShadowObjects(t,e=Q.CreateAndDestroy,s){let i=r(this,C).get(t);s!=null||(s=new Set(this.registry.findConstructors(i.token,i.entity.truthyProps())));let a=e===Q.CreateAndDestroy||e===Q.DestroyOnly,o=e===Q.CreateAndDestroy||e===Q.JustCreate;if(a){for(let[n,l]of i.usedConstructors)if(!s.has(n)){i.usedConstructors.delete(n);for(let p of l)this.destroyShadowObject(p,i.entity)}}if(o)for(let n of s)i.usedConstructors.has(n)||this.constructShadowObject(n,i);return s}constructShadowObject(t,e){let s=new Set,i=new Set,a=new Map,o=new Map,n=new Map,l=new Map,p=new Map,b=lt(new t({entity:e.entity,provideContext(u,h,g){let y=n.get(u);if(y==null){y=k(h,g?{compare:g}:void 0);let M=ft(y,e.entity.provideContext(u));i.add(M.destroy.bind(M)),n.set(u,y)}return y},provideGlobalContext(u,h,g){let y=l.get(u);if(y==null){y=k(h,g?{compare:g}:void 0);let M=ft(y,e.entity.provideGlobalContext(u));i.add(M.destroy.bind(M)),l.set(u,y)}return y},useContext(u,h){let g=a.get(u);if(g===void 0){g=k(void 0,h?{compare:h}:void 0).get,a.set(u,g);let y=ft(e.entity.useContext(u),g);i.add(y.destroy.bind(y))}return g},useParentContext(u,h){let g=o.get(u);if(g===void 0){g=k(void 0,h?{compare:h}:void 0).get,o.set(u,g);let y=ft(e.entity.useParentContext(u),g);i.add(y.destroy.bind(y))}return g},useProperty(u,h){let g=p.get(u);if(g===void 0){g=k(void 0,h?{compare:h}:void 0).get,p.set(u,g);let y=ft(e.entity.getPropertyReader(u),g);i.add(y.destroy.bind(y))}return g},createEffect(...u){let h=te(...u);return i.add(h.destroy),h},createSignal(...u){let h=k(...u);return i.add(()=>{U(h)}),h},createMemo(...u){let h=wi(...u);return i.add(()=>{U(h)}),h},on(...u){let h=ht(...u);return i.add(h),h},once(...u){let h=O(...u);return i.add(h),h},onDestroy(u){s.add(u)}}));return this.logger.isInfo&&this.logger.info("create shadow-object",is(t),{shadowObject:b,entity:e.entity}),O(e.entity,Ot,Le.Low,()=>{this.logger.isInfo&&this.logger.info("destroy shadow-object",is(t),{shadowObject:b,entity:e.entity});for(let h of s)h();for(let h of i)h();for(let h of a.values())U(h);for(let h of o.values())U(h);for(let h of p.values())U(h);for(let h of n.values())U(h);for(let h of l.values())U(h);s.clear(),i.clear(),a.clear(),o.clear(),p.clear(),n.clear(),l.clear();let u=e.usedConstructors.get(t);u&&(u.delete(b),u.size===0&&e.usedConstructors.delete(t))}),e.usedConstructors.has(t)?e.usedConstructors.get(t).add(b):e.usedConstructors.set(t,new Set([b])),this.attachShadowObject(b,e.entity),b}createShadowObjects(t){var s;let e=r(this,C).get(t);(s=this.registry.findConstructors(e.token,e.entity.truthyProps()))==null||s.forEach(i=>{this.constructShadowObject(i,e)})}findShadowObjects(t){if(!r(this,C).has(t))return[];let{usedConstructors:e}=r(this,C).get(t);return Array.from(new Set(Array.from(e.values()).map(s=>Array.from(s)).flat()))}attachShadowObject(t,e){ht(e,t),typeof t[es]=="function"&&t[es](e)}destroyShadowObject(t,e){typeof t[Ot]=="function"&&t[Ot](e),w(t,Ot,e),x(e,t)}findOrCreateRootContext(t){let e=r(this,ot).get(t);return e||(e=new Me,r(this,ot).set(t,e)),e}destroy(){for(let t of r(this,ot).values())t.dispose();r(this,ot).clear();for(let t of this.traverseLevelOrderBFS().reverse())this.destroyEntity(t.uuid)}},C=new WeakMap,J=new WeakMap,Lt=new WeakMap,Xt=new WeakMap,K=new WeakMap,ot=new WeakMap,fs);async function Ts(t,e,s,i=!0){var o,n;if(s.has(e)){console.warn("importModule: skipping already imported module",e);return}else s.add(e);e.extends&&await Promise.all(e.extends.map(l=>Ts(t,l,s,!1)));let{registry:a}=t;if(e.define)for(let[l,p]of Object.entries(e.define))a.define(l,p);if(e.routes)for(let[l,p]of Object.entries(e.routes))a.appendRoute(l,p);await((n=(o=e.initialize)==null?void 0:o.call(e,{define:(l,p)=>a.define(l,p),kernel:t,registry:a}))!=null?n:Promise.resolve()),i&&t.upgradeEntities()}var Ri=t=>(typeof t=="string"&&(t=new URL(t,globalThis.location.href)),t.toString()),Zt,ut,Ds,Ls,xs,gs,Fi=(gs=class{constructor(t){c(this,ut);c(this,Zt,new Set);var e,s;this.kernel=(e=t==null?void 0:t.kernel)!=null?e:new xi,this.postMessage=(s=t==null?void 0:t.postMessage)!=null?s:self.postMessage.bind(self),ht(this.kernel,Ee,"onMessageToView",this)}route(t){var e;switch(t.data.type){case zs:m(this,ut,Ds).call(this,t.data);break;case Vs:m(this,ut,Ls).call(this,t.data);break;case Ns:m(this,ut,xs).call(this,t.data);break;default:console.warn("[MessageRouter] unknown message",(e=t.data.type)!=null?e:t.data)}}onMessageToView(t){let i=t,{transferables:e}=i,s=$e(i,["transferables"]);this.postMessage({type:Ee,data:s},{transfer:e})}},Zt=new WeakMap,ut=new WeakSet,Ds=async function(t){try{let e=await import(Ri(t.importModule));e[ye]?(await Ts(this.kernel,e[ye],r(this,Zt)),this.postMessage({type:pe,url:t.importModule})):this.postMessage({type:pe,url:t.importModule,error:`module has no "${ye}" export`})}catch(e){console.error("[MessageRouter] failed to import module",e),this.postMessage({type:pe,url:t.importModule,error:`${e}`})}},Ls=function(t){try{this.kernel.run(t)}catch(e){console.error("[MessageRouter] failed to apply change trail",e),this.postMessage({type:Be,serial:t.serial,error:e.toString()})}t.serial&&this.postMessage({type:Be,serial:t.serial})},xs=function(t){console.debug("[MessageRouter] on destroy",t),x(this.kernel,this),r(this,Zt).clear(),this.postMessage({type:Is})},gs),zi=class{constructor(){this.onmessage=t=>{var e;t.data.type===z?globalThis[L]=t.data.config:((e=this.router)!=null||(this.router=new Fi),this.router.route(t))}}start(){self.addEventListener("message",this.onmessage),self.postMessage({type:$s})}};console.debug("@spearwolf/shadow-objects/WorkerRuntime: hello!");var Vi=new zi;Vi.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 Ns=()=>new Be;var jt=(s,t,e=1e3,r)=>new Promise((i,n)=>{let o,h,a=()=>{clearTimeout(o),s.removeEventListener("message",h)};e!==0&&e!==1/0&&(o=setTimeout(()=>{a(),n(new Error(`Timeout waiting for message of type: ${t}`))},e)),h=c=>{if(c.data.type===t)try{(!r||r(c.data))&&(a(),i())}catch(p){a(),n(p.toString())}},s.addEventListener("message",h)});var fr=s=>{let t;if(s!=null&&Array.isArray(s))for(let e of s)e.transferables&&(t?t=[...t,...e.transferables]:t=e.transferables,delete e.transferables);return t},me=class s{static{this.WorkerLoaded="workerLoaded"}#t;#e;#s;get isDestroyed(){return this.#e}get workerLoaded(){return ct(this,s.WorkerLoaded)}constructor(){this.#e=!1,this.#s=0,this.logger=new A("RemoteWorkerEnv"),z(this,s.WorkerLoaded)}async start(){if(this.#t)return this.logger.isWarn&&this.logger.warn("already started"),this.workerLoaded.then(()=>{if(this.isDestroyed)throw"worker was destroyed"});let t=this.#t=Ns();this.configureConsoleLogger(t);try{if(await jt(t,ds,ms),this.isDestroyed)throw"worker was destroyed";t.addEventListener("message",this.onMessageFromWorker.bind(this)),queueMicrotask(()=>{d(this,s.WorkerLoaded,this)})}catch(e){throw this.logger.error("failed to start",e),this.#t=void 0,e}}applyChangeTrail(t,e){let r=fr(t),i={type:cs,changeTrail:t},n=++this.#s;return e&&(i.serial=n),this.#t.postMessage(i,r),e?jt(this.#t,ps,vs,o=>{if(o.error)throw o.error;return o.serial===n}):Promise.resolve()}importScript(t){return t=ge(t),this.#t.postMessage({type:us,importModule:t}),jt(this.#t,gs,bs,e=>{if(e.error)throw e.error;return e.url===t})}destroy(){if(!this.#t)return;let t=this.#t;this.#t=void 0,this.#e=!0,t.postMessage({type:fs}),jt(t,ys,ws).finally(()=>{t.terminate()})}onMessageFromWorker(t){t.data?.type===yt?this.onMessageToView?.(t.data.data):this.logger.isDebug&&this.logger.debug("message from worker",t)}configureConsoleLogger(t){let e=`${_}.RemoteWorkerEnv.workerConfig`,r=JSON.parse(localStorage.getItem(e)??"{}");this.logger.isInfo&&this.logger.info("load console-logger worker config",{localStorageKey:e,workerConfig:r}),t.postMessage({type:_,config:{...A.sharedConfig,enable:this.logger.isEnabled,...r,...A.isEnabled?{}:{enable:!1}}})}};var Dt,Nt=class extends tt{static{this.observedAttributes=[...tt.observedAttributes,se,ie,re]}static{this.DefaultAutoSync="frame"}#t;#e;#s;#r;#i;constructor(){super(),this.isShaeWorkerElement=!0,this.shadowEnv=new I,this.logger=new A("ShaeWorkerElement"),this.autostart=!0,this.isConnected$=f(!1),this.autoSync$=f(Dt.DefaultAutoSync),this.src$=f(""),this.#t=!1,this.#e=!1,this.ns$.onChange(t=>{this.shadowEnv.view=D.get(t)}),b(this.shadowEnv,I.ContextCreated,()=>{this.#i?.run(),this.dispatchEvent(new CustomEvent(I.ContextCreated.toLowerCase(),{bubbles:!1,detail:{shadowEnv:this.shadowEnv}}))}),b(this.shadowEnv,I.ContextLost,()=>{this.dispatchEvent(new CustomEvent(I.ContextLost.toLowerCase(),{bubbles:!1,detail:{shadowEnv:this.shadowEnv}}))}),this.autoSync$.onChange(t=>{let e=this.hasAttribute(F),r=e?this.getAttribute(F):void 0;t===Dt.DefaultAutoSync?e&&r!==t&&this.setAttribute(F,t):r!==t&&this.setAttribute(F,t)}),this.#a(),this.#n()}#n(){this.#i=C(()=>{let t=this.src$.get();t&&this.importScript(t)},{autorun:!1})}get shouldAutostart(){return this.autostart&&!Mt(this,Ts)}get autoSync(){return this.autoSync$.value}set autoSync(t){typeof t!="string"&&(t=t?Dt.DefaultAutoSync:"no"),this.autoSync$.set(`${t}`.trim().toLowerCase())}get frameLoop(){return this.#s??=new mt,this.#s}[mt.OnFrame](){this.syncShadowObjects()}async importScript(t){if(!t)throw new Error("src is blank");let e=await this.shadowEnv.ready();return this.logger.isInfo&&this.logger.info("shadowEnv importScript:",t,{shadowEnv:e}),await e.envProxy.importScript(t),this}connectedCallback(){O(()=>{this.hasAttribute(F)&&this.autoSync$.set(this.getAttribute(F)),this.isConnected$.set(!0)}),this.shouldAutostart&&this.start()}disconnectedCallback(){this.isConnected$.set(!1),this.#o()}attributeChangedCallback(t){if(super.attributeChangedCallback(t),t===se&&this.shadowEnv.envProxy!=null)throw new Error('Changing the "local" attribute after the shadowEnv has been created is not supported.');if(t===re&&this.#h(),t===F&&(this.autoSync=this.hasAttribute(F)?this.getAttribute(F):!0),t===ie){let e=(this.getAttribute(ie)||"").trim();this.src$.set(e),this.shadowEnv.isReady&&this.#i?.run()}}start(){if(!this.#e){if(this.#t=!1,this.shadowEnv.view??=D.get(this.ns),this.shadowEnv.envProxy==null){let t=Mt(this,se)?new ye:new me;this.shadowEnv.envProxy=t,this.#h()}this.#e=!0}return this.shadowEnv.ready()}destroy(){this.#r?.destroy(),this.#i?.destroy(),x(this.isConnected$,this.autoSync$,this.src$),this.shadowEnv.envProxy=void 0,this.shadowEnv.destroy()}#o(){this.#t||(this.#t=!0,queueMicrotask(()=>{this.#t&&this.destroy()}))}#a(){this.#r=C(()=>{if(this.isConnected$.get()){let t=(this.autoSync$.get()||Dt.DefaultAutoSync).trim().toLowerCase(),e;if(["true","yes","on","frame","auto-sync"].includes(t))return this.logger.isDebug&&this.logger.debug("auto-sync",t,this),this.frameLoop.start(this),()=>{this.frameLoop.stop(this)};if(t.toLowerCase().endsWith("fps")){let r=parseInt(t,10);r>0?e=Math.floor(1e3/r):this.logger.isWarn&&this.logger.warn(`invalid auto-sync value: ${t}`)}else e=parseInt(t,10),isNaN(e)&&(e=void 0,["false","no","off"].includes(t)||this.logger.error(`invalid auto-sync value: ${t}`));if(e!==void 0&&e>0){this.logger.isDebug&&this.logger.debug("auto-sync interval (ms)",e,this);let r=setInterval(()=>{this.syncShadowObjects()},e);return()=>{clearInterval(r)}}else this.logger.isDebug&&this.logger.debug("auto-sync off",this)}},[this.autoSync$,this.isConnected$])}#h(){let t=this.shadowEnv.envProxy;t?.isLocalEnv&&(t.disableStructuredClone=this.hasAttribute(re))}};Dt=Nt;customElements.define(As,Nt);globalThis.SHADOW_ENTS_BUNDLE_LOADED=!0;
|
|
21
|
+
var st="*",Je=1,Ee=2,Se=4,W=Symbol.for("eventize"),Fs="[eventize]",Ft=s=>s===st,Xe=s=>{switch(typeof s){case"string":case"symbol":return!0;default:return!1}},Ze=typeof console<"u",Ws=Ze?console[console.warn?"warn":"log"].bind(console,Fs):()=>{},zs=(s,t,e)=>(Object.defineProperty(s,t,{value:e,configurable:!0}),s),Us=0,ts=class{static publish(s){s.sort((t,e)=>t.order-e.order).forEach(t=>t.emit())}events=new Map;eventNames=new Set;add(s){Array.isArray(s)?s.forEach(t=>this.eventNames.add(t)):this.eventNames.add(s)}remove(s){Array.isArray(s)?s.forEach(t=>this.eventNames.delete(t)):this.eventNames.delete(s),this.clear(s)}clear(s){Array.isArray(s)?s.forEach(t=>this.events.delete(t)):this.events.delete(s)}retain(s,t){this.eventNames.has(s)&&this.events.set(s,{args:t,order:Us++})}isKnown(s){return this.eventNames.has(s)}emit(s,t,e=[]){if(Ft(s))this.eventNames.forEach(r=>this.emit(r,t,e));else if(this.events.has(s)){let{order:r,args:i}=this.events.get(s);e.push({order:r,emit:()=>t.apply(s,i)})}return e}},we=(s,t,e,r)=>{if(typeof t=="function"){let i=t.apply(s,e);i!=null&&r?.(i)}},Vs=(s,t,e,r)=>we(t,t.emit,[s].concat(e),r),Gs=s=>{switch(typeof s){case"function":return Je;case"string":case"symbol":return Ee;case"object":return Se}},Bs=0,qs=()=>++Bs,es=class{id;eventName;isCatchEmAll;priority;listener;listenerObject;listenerType;callAfterApply;isRemoved;refCount;constructor(s,t,e,r=null){this.id=qs(),this.eventName=s,this.isCatchEmAll=Ft(s),this.listener=e,this.listenerObject=r,this.priority=t,this.listenerType=Gs(e),this.callAfterApply=void 0,this.isRemoved=!1,this.refCount=1}isEqual(s,t=null){if(s===this)return!0;let e=typeof s;return e==="number"&&s===this.id?!0:t===null&&(e==="string"||e==="symbol")?s===st||s===this.eventName:this.listener===s&&this.listenerObject===t}apply(s,t,e){if(this.isRemoved)return;let{listener:r,listenerObject:i}=this;switch(this.listenerType){case Je:we(i,r,t,e),this.callAfterApply&&this.callAfterApply();break;case Ee:we(i,i[r],t,e),this.callAfterApply&&this.callAfterApply();break;case Se:{let n=r[s];if(this.isCatchEmAll||this.eventName===s){if(typeof n=="function"){let o=n.apply(r,t);o!=null&&e?.(o)}else Vs(s,r,t,e);this.callAfterApply&&this.callAfterApply()}break}}}},Hs=(s,t)=>s.priority!==t.priority?t.priority-s.priority:s.id-t.id,Qe=s=>s?.slice(0),Ye=(s,t)=>{let e=s.indexOf(t);e>-1&&s.splice(e,1)},Qs=s=>s===Se||s===Ee,Ce=(s,t,e)=>{let r=s.findIndex(i=>i.isEqual(t,e));r>-1&&(s[r].isRemoved=!0,s.splice(r,1))},It=(s,t,e)=>{let r=[];for(let i of s)(t==null&&i.listenerObject===e||i.eventName===t&&i.listener===e)&&r.push(i);for(let i of r)Ce(s,i,void 0)},ve=s=>{s&&(s.forEach(t=>{t.isRemoved=!0}),s.length=0)},Ys=(s,t)=>s.listenerType===t.listenerType?s.priority===t.priority&&s.eventName===t.eventName&&s.listenerObject===t.listenerObject&&s.listener===t.listener:!1,Ks=(s,t)=>{if(Qs(s.listenerType))return t.find(e=>Ys(s,e))},Js=(s,t)=>{let e=Ks(s,t);return e?(e.refCount+=1,e):(t.push(s),t.sort(Hs),s)},Xs=class{namedListeners;catchEmAllListeners;getListenersForEventName=s=>{let t=this.namedListeners.get(s);return t||(t=[],this.namedListeners.set(s,t)),t};constructor(){this.namedListeners=new Map,this.catchEmAllListeners=[]}add(s){return Js(s,s.isCatchEmAll?this.catchEmAllListeners:this.getListenersForEventName(s.eventName))}remove(s,t,e=!1){t==null&&Array.isArray(s)?s.forEach(r=>this.remove(r,null,e)):s==null||t==null&&Ft(s)?this.removeAllListeners():t==null&&Xe(s)?ve(this.namedListeners.get(s)):s instanceof es?s.isRemoved||(s.refCount-=1,s.refCount<1&&(s.isRemoved=!0,this.namedListeners.forEach(r=>Ye(r,s)),Ye(this.catchEmAllListeners,s))):e?Ft(s)&&typeof s=="object"?It(this.catchEmAllListeners,st,s):this.namedListeners.forEach(r=>It(r,s,t)):(this.namedListeners.forEach(r=>{Ce(r,s,t),typeof s=="object"&&It(r,void 0,s)}),Ce(this.catchEmAllListeners,s,t),typeof s=="object"&&It(this.catchEmAllListeners,void 0,s))}removeAllListeners(){this.namedListeners.forEach(s=>ve(s)),this.namedListeners.clear(),ve(this.catchEmAllListeners)}forEach(s,t){let e=Qe(this.catchEmAllListeners),r=Qe(this.namedListeners.get(s));if(s===st||!r||r.length===0)e.forEach(t);else if(e.length===0)r.forEach(t);else{let i=r.length,n=e.length,o=0,h=0;for(;o<i||h<n;){if(o<i){let a=r[o];if(h>=n||a.priority>=e[h].priority){t(a),++o;continue}}h<n&&(t(e[h]),++h)}}}getSubscriptionCount(){let s=this.catchEmAllListeners.length;for(let t of this.namedListeners.values())s+=t.length;return s}},rt=s=>!!(s&&s[W]);function wt(s){if(rt(s))return s;let t=new Xs,e=new ts;return zs(s,W,{keeper:e,store:t}),s}var z={Max:Number.POSITIVE_INFINITY,AAA:1e9,BB:1e6,C:1e3,Default:0,Low:-1e4,Min:Number.NEGATIVE_INFINITY},Zs=(s,t,e,r,i,n,o)=>{let h=s.add(new es(e,r,i,n));return t.emit(e,h,o),h},tr=(s,t,e,r)=>{let i=e.length,n=typeof e[0],o,h,a,c;if(i>=2&&i<=3&&n==="number"?(o=st,[h,a,c]=e):i>=3&&i<=4&&typeof e[1]=="number"?[o,h,a,c]=e:(h=z.Default,n==="string"||n==="symbol"||Array.isArray(e[0])?[o,a,c]=e:(o=st,[a,c]=e)),!a&&Ze)throw Ws("called with insufficient arguments!",e),"subscribeTo() called with insufficient arguments!";let p=l=>u=>Zs(s,t,u,l,a,c,r);return Array.isArray(o)?o.map(l=>Array.isArray(l)?p(l[1])(l[0]):p(h)(l)):p(h)(o)},ss=(s,t,e)=>{let r=[],i=tr(s,t,e,r);return ts.publish(r),i},Ke=s=>t=>{t.callAfterApply=()=>{s?.()}},rs=(s,t)=>Object.assign(()=>E(s,t),Array.isArray(t)?{listeners:t}:{listener:t}),is=(s,t,e,r)=>{let{store:i,keeper:n}=s[W];Array.isArray(t)?t.forEach(o=>{i.forEach(o,h=>h.apply(o,e,r)),n.retain(o,e)}):t!==st&&(i.forEach(t,o=>{o.apply(t,e,r)}),n.retain(t,e))},m=(s,...t)=>{let e=wt(s),{store:r,keeper:i}=e[W];return rs(e,ss(r,i,t))},C=(s,...t)=>{let e=wt(s),{store:r,keeper:i}=e[W],n=ss(r,i,t),o=rs(e,n),h=!1,a=()=>{h||(o(),h=!0)};return Array.isArray(n)?n.forEach(Ke(a)):Ke(a)(n),a},ct=(s,t)=>new Promise(e=>{C(s,t,e)}),E=(s,t,e)=>{if(!rt(s))throw new Error("object is not eventized");let{store:r,keeper:i}=s[W],n=typeof t,o=e!=null&&(n==="string"||n==="symbol");r.remove(t,e,o),Array.isArray(t)?i.remove(t.filter(h=>typeof h=="string")):Xe(t)&&i.remove(t)},d=(s,t,...e)=>{if(!rt(s))throw new Error("object is not eventized");is(s,t,e)},er=(s,t,...e)=>{if(!rt(s))throw new Error("object is not eventized");let r=[];return is(s,t,e,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()},U=(s,t)=>{let e=wt(s),{keeper:r}=e[W];r.add(t)},H=(s,t)=>{if(!rt(s))throw new Error("object is not eventized");let{keeper:e}=s[W];e.clear(t)},S=(()=>{let s=(t={})=>wt(t);return s.inject=(t={})=>(t=wt(t),Object.assign(t,{on:(...e)=>m(t,...e),once:(...e)=>C(t,...e),onceAsync:e=>ct(t,e),off:(e,r)=>E(t,e,r),emit:(e,...r)=>d(t,e,...r),emitAsync:(e,...r)=>er(t,e,...r),retain:e=>U(t,e),retainClear:e=>H(t,e)}),t),s.is=rt,s})();var xe=s=>rt(s)?s[W]?.store?.getSubscriptionCount()??0:0;var R=Symbol.for("signal"),it=Symbol.for("effect"),ke=Symbol.for("destroySignal"),Ae=Symbol.for("createEffect"),ns=Symbol.for("destroyEffect"),ft="value",Oe="mute",Te="unmute",Q="destroy",nt=Symbol.for("recall");var ot=S(),D=S(),V=S(),Wt=S();var at=class{static current;delayedEffects=[];batch(t,e){let r=this.delayedEffects.length;for(let i=0;i<r;i++){let[n,o]=this.delayedEffects[i];if(!(n>e))if(n===e){o.add(t);return}else{this.delayedEffects.splice(i,0,[e,new Set([t])]);return}}this.delayedEffects.push([e,new Set([t])])}run(){let t=new Set,e=[m(V,(i,n)=>{n===nt&&t.add(i)}),m(Wt,i=>{t.add(i)})],r=this.delayedEffects.flatMap(([,i])=>Array.from(i));for(let i of r)t.has(i)||d(V,i,i,nt);e.forEach(i=>{i()})}},os=()=>at.current;function O(s){let t=at.current;t?t=void 0:t=at.current=new at;try{s()}finally{t&&(at.current=void 0,t.run())}}var Pe=0;function Re(s){Pe++;try{s()}finally{Pe--}}function zt(){return Pe>0}var Ut=class{[it];constructor(t){this[it]=t,C(t,dt.Destroy,()=>{this[it]=void 0})}run=()=>this[it]?.run();destroy=()=>{this[it]?.destroy(),this[it]=void 0}};var Y=new Map,M=class s{#t=new Set;#e=new Set;#s=new Map;#i=new WeakMap;#r=new Map;#n=new Set;#o=new Set;#a;static get(t){if(t!=null)return t instanceof s?t:Y.get(t)}static findOrCreate(t){if(t==null)throw new Error("Cannot create a group with a null object");return new s(t)}static destroy(t){console.warn("SignalGroup.destroy(obj) is deprecated. Use SignalGroup.delete(obj) instead."),s.delete(t)}static delete(t){Y.get(t)?.clear()}static clear(){for(let t of Y.values())t.destroy();Y.clear()}constructor(t){if(t!=null&&t instanceof s)return t;if(t??=this,Y.has(t))return Y.get(t);Y.set(t,this),S(this)}attachGroup(t){if(t===this)throw new Error("Cannot attach a group to itself");return this.#t.add(t),t.#a&&t.#a!==this&&t.#a.#t.delete(t),t.#a=this,t}detachGroup(t){return t!==this&&this.#t.has(t)&&(this.#t.delete(t),t.#a=void 0),t}attachSignal(t){let e=v(t);if(e?.destroyed)throw new Error("Cannot attach a destroyed signal to a group");return e&&this.#e.add(e),t}attachSignalByName(t,e){if(e){this.attachSignal(e);let r=v(e);this.#s.set(t,r),this.#r.has(t)?this.#r.get(t).push(r):this.#r.set(t,[r]),this.#i.has(r)?this.#i.get(r).add(t):this.#i.set(r,new Set([t]))}else this.#s.delete(t);return e}hasSignal(t){return this.#s.has(t)||this.#a?.hasSignal(t)}signal(t){return this.#s.get(t)?.object??this.#a?.signal(t)}detachSignal(t){let e=v(t);if(e&&(this.#e.delete(e),this.#i.has(e))){let r=this.#i.get(e);for(let i of r)if(this.#r.has(i)){let n=this.#r.get(i);n.splice(n.indexOf(e),1),n.length===0?(this.#s.delete(i),this.#r.delete(i)):this.#s.get(i)===e&&this.#s.set(i,n.at(-1))}r.clear(),this.#i.delete(e)}return t}attachEffect(t){return this.#n.add(t),t}runEffects(){for(let t of this.#n)t.run();for(let t of this.#t)t.runEffects()}attachLink(t){if(t?.isDestroyed)throw new Error("Cannot attach a destroyed link to a group");return t&&this.#o.add(t),t}detachLink(t){return t&&this.#o.delete(t),t}destroy(){console.warn("SignalGroup#destroy is deprecated. Use SignalGroup#clear instead."),this.clear()}clear(){d(this,Q,this),E(this);for(let t of this.#t)t.destroy();for(let t of this.#n)t.destroy();for(let t of this.#e)x(t);for(let t of this.#o)t.destroy();this.#t.clear(),this.#e.clear(),this.#s.clear(),this.#r.clear(),this.#n.clear(),this.#o.clear(),this.#a?.detachGroup(this),Y.delete(this)}};var pt=class{#t;#e;constructor(t="id",e=1){this.#t=t,this.#e=e}make(){return Symbol(`${this.#t}${this.#e++}`)}};var Me=[],Vt=()=>Me.at(-1),as=(s,t)=>{Me.push(s);try{return t()}finally{Me.pop()}};var sr=s=>s!=null&&typeof s.then=="function",dt=class s{static idGen=new pt("ef");static Destroy="destroy";static count=0;id;callback;#t;#e=new Set;#s=new Set;#i=new Map;#r=new Set;parentEffect;childEffects=[];curChildEffectSlot=0;autorun=!0;shouldRun=!0;priority;#n;#o=!1;constructor(t,e){S(this),this.callback=t;let r;e?.attach!=null&&(r=M.findOrCreate(e.attach),r.attachEffect(this)),this.autorun=e?.autorun??!0,this.#n=e?.dependencies?e.dependencies.map(i=>{switch(typeof i){case"string":case"symbol":return r.signal(i);default:return i}}):void 0,this.id=s.idGen.make(),this.priority=e?.priority??0,m(V,this.id,nt,this),++s.count}hasStaticDeps(){return this.#n!=null&&this.#n.length>0}saveSignalsFromDeps(){for(let t of this.#n)this.whenSignalIsRead(v(t).id)}static createEffect(t,e,r){let i=Array.isArray(e)?e:void 0,n=i?r??{dependencies:i}:e;n&&i&&(n.dependencies=i);let o,h=Vt();return h!=null?(o=h.getCurrentChildEffect(),o==null&&(o=new s(t,n),h.attachChildEffect(o),d(V,Ae,o)),h.curChildEffectSlot++):(o=new s(t,n),d(V,Ae,o)),o.hasStaticDeps()?o.saveSignalsFromDeps():o.autorun&&o.run(),new Ut(o)}getCurrentChildEffect(){return this.childEffects[this.curChildEffectSlot]}attachChildEffect(t){this.childEffects.push(t),this.parentEffect=this}run=()=>{if(this.#o||!this.shouldRun)return;let t=os();t?t.batch(this.id,this.priority):(this.runCleanupCallback(),this.curChildEffectSlot=0,this.shouldRun=!1,d(Wt,this.id,this.id),this.hasStaticDeps()?this.#t=this.callback():(this.#s=new Set(this.#e),this.#t=as(this,this.callback),this.cleanupLostSignals(),this.#r.clear()))};[nt](){this.shouldRun=!0,this.autorun&&this.run()}whenSignalIsRead(t){this.#s.delete(t),this.#e.has(t)||(this.#e.add(t),this.#i.set(t,[m(ot,t,this.priority,nt,this),C(D,t,ke,this)]))}[ke](t){!this.#r.has(t)&&this.#e.has(t)&&(this.#r.add(t),this.unsubscribeSignal(t),this.#r.size===this.#e.size&&this.destroy())}cleanupLostSignals(){for(let t of this.#s)this.unsubscribeSignal(t),this.#e.delete(t)}unsubscribeSignal(t){this.#i.has(t)&&(this.#i.get(t).forEach(e=>{e()}),this.#i.delete(t))}runCleanupCallback(){if(this.#t!=null){let t=this.#t;this.#t=void 0,sr(t)?Promise.resolve(t).then(e=>{typeof e=="function"&&e()}):t()}}destroy=()=>{this.#o||(d(this,s.Destroy,this),E(this),d(V,ns,this),this.runCleanupCallback(),E(ot,this),E(V,this),E(D,this),this.#o=!0,this.#e.clear(),this.#s.clear(),this.#i.clear(),this.#r.clear(),this.childEffects.forEach(t=>{t.destroy()}),this.childEffects.length=0,--s.count)}};var w=(...s)=>dt.createEffect(...s);var Ct=new WeakMap,rr=s=>{let t=Ct.get(s);return t||(t={},Ct.set(s,t)),t},T=(s,t)=>Ct.get(s)?.signals?.get(t);var hs=(s,t,e)=>{let r=rr(s);r.signals??=new Map,r.signals.set(t,e)};function Et(...s){for(let t of s)if(Ct.has(t)){let e=Ct.get(t);if(e.signals){for(let r of e.signals.values())x(r);e.signals.clear(),e.signals=void 0}}}function ls(s){let t=v(gt(s)?s:T(...s));t!=null&&!t.muted&&!t.destroyed&&Gt(t.id,t.value,{touch:!0})}function ht(s){return gt(s)?v(s)?.value:v(T(...s))?.value}var Bt=class{[R];constructor(t){this[R]=t}get get(){return this[R].reader}get set(){return this[R].writer}get value(){return ht(this.get)}set value(t){this.set(t)}onChange(t){let{destroy:e}=w(()=>t(this.value),[this.get]);return e}get muted(){return this[R].muted}set muted(t){this[R].muted=t}touch(){ls(this)}destroy(){x(this)}};var ir=new pt("si");function us(s){zt()||Vt()?.whenSignalIsRead(s)}function Gt(s,t,e){zt()||d(ot,s,t,e)}var gt=s=>s!=null&&s[R]!=null,nr=s=>{let t=e=>(e?w(()=>(s.destroyed||us(s.id),e(s.value)),[t]):s.destroyed||(s.beforeRead?.(),us(s.id)),s.value);return Object.defineProperty(t,R,{value:s}),t},qt=class s{static instanceCount=0;id;lazy;get[R](){return this}compare;beforeRead;muted=!1;destroyed=!1;#t=void 0;get value(){return this.lazy&&(this.#t=this.valueFn(),this.valueFn=void 0,this.lazy=!1),this.#t}set value(t){this.#t=t}valueFn;reader;writer=(t,e)=>{let r=e?.lazy??!1,n=e?.compare??this.compare??((h,a)=>h===a);if((r!==this.lazy||r&&t!==this.valueFn||!r&&!n(t,this.#t))&&(r?(this.#t=void 0,this.valueFn=t,this.lazy=!0):(this.#t=t,this.valueFn=void 0,this.lazy=!1),!this.muted&&!this.destroyed)){Gt(this.id,this.#t);return}(e?.touch??!1)&&Gt(this.id,this.#t,{touch:!0})};object;constructor(t,e){this.id=ir.make(),++s.instanceCount,this.lazy=t,this.lazy?(this.value=void 0,this.valueFn=e):(this.value=e,this.valueFn=void 0),this.reader=nr(this),this.object=new Bt(this)}},v=s=>s?.[R];function f(s=void 0,t){let e;if(gt(s))e=v(s);else{let r=t?.lazy??!1;e=new qt(r,s),e.beforeRead=t?.beforeRead,e.compare=t?.compare}return t?.attach!=null&&M.findOrCreate(t.attach).attachSignal(e),e.object}var x=(...s)=>{for(let t of s){let e=v(t);e!=null&&!e.destroyed&&(e.destroyed=!0,e.beforeRead=void 0,--qt.instanceCount,d(D,e.id,e.id))}};function Le(s,t){let e=f(),r=t?.attach!=null?M.findOrCreate(t.attach):void 0;r!=null&&(t?.name?r.attachSignalByName(t.name,e):r.attachSignal(e));let i=w(()=>e.set(s()),{autorun:!(t?.lazy??!1),priority:t?.priority??z.C,attach:r}),n=v(e);return n.beforeRead=i.run,C(D,n.id,i.destroy),e.get}var Ht=class{#t=!1;#e;source;lastValue;isDestroyed=!1;constructor(t){S(this),this.source=v(t),this.#e=m(ot,this.source.id,(e,r)=>{!this.#t&&!this.isDestroyed&&(r?.touch===!0?this.touch():this.write())}),C(D,this.source.id,()=>this.destroy())}attach(t){let e=M.findOrCreate(t);return e.attachLink(this),C(this,Q,()=>{e.detachLink(this)}),e}nextValue(){return new Promise((t,e)=>{let r=[],i=()=>r.forEach(n=>{n()});r.push(C(this,ft,n=>{i(),t(n)}),C(this,Q,()=>{i(),e()}))})}async*asyncValues(t){let e=0;for(;!this.isDestroyed;)try{let r=await this.nextValue();if(t&&t(r,e++))break;U(this,ft),yield r}catch{break}H(this,ft)}destroy(){this.isDestroyed||(this.#e?.(),this.#e=void 0,d(this,Q,this),H(this,ft),E(this),this.lastValue=void 0,this.isDestroyed=!0,Object.freeze(this))}get isMuted(){return this.#t}mute(){return!this.isDestroyed&&!this.#t&&(this.#t=!0,d(this,Oe,this)),this}unmute(){return!this.isDestroyed&&this.#t&&(this.#t=!1,d(this,Te,this)),this}toggle(){return this.isDestroyed||(this.#t=!this.#t,d(this,this.#t?Oe:Te,this)),this.#t}updateValue(t){if(!this.#t&&!this.isDestroyed){let{value:e}=this.source;t(e),d(this,ft,e),this.lastValue=e}}},Qt=class extends Ht{target;constructor(t,e){super(t),this.target=v(e),C(D,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)})}},Yt=class extends Ht{target;constructor(t,e){super(t),this.target=e,this.touch()}touch(){return this.updateValue(t=>{this.target(t)}),this}write(){this.updateValue(t=>{this.target(t)})}};var Kt=new Map;function _(s,t,e){let r=v(s),i;if(Kt.has(r)){i=Kt.get(r);let c=v(t)??t;if(i.has(c))return i.get(c)}else i=new Map,Kt.set(r,i);let n=v(t),o=n!=null?new Qt(s,n):new Yt(s,t),h=e?.attach;h&&o.attach(h);let a=n??t;return i.set(a,o),C(o,Q,()=>{i.delete(a),i.size===0&&Kt.delete(r)}),o}var Jt=class s{static fromProps(t,e){let r=new s,i=e?e.map(n=>[n,t[n]]):Object.entries(t);for(let[n,o]of i)r.#t.set(n,f(o));return r}#t=new Map;keys(){return this.#t.keys()}signals(){return this.#t.values()}entries(){return this.#t.entries()}clear(){for(let t of this.#t.values())t.destroy();this.#t.clear()}has(t){return this.#t.has(t)}get(t){if(!this.#t.has(t)){let e=f();return this.#t.set(t,e),e}return this.#t.get(t)}update(t){t.size&&O(()=>{for(let[e,r]of t.entries())this.get(e).set(r)})}updateFromProps(t,e){O(()=>{let r=e?e.map(i=>[i,t[i]]):Object.entries(t);for(let[i,n]of r)this.get(i).set(n)})}};var $;(function(s){s[s.StructuralChanges=1]="StructuralChanges",s[s.ContentUpdates=2]="ContentUpdates",s[s.Removal=3]="Removal"})($||($={}));var b;(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"})(b||(b={}));var lt=Symbol.for("ShadowEntsGlobalNS"),G="#void",cs="contextLost",fs="configure",ds="changeTrail",ps="destroy",gs="loaded",ys="appliedChangeTrail",ms="importedModule",bs="destroyed",yt="messageToView",vs=6e4,ws=6e4,Cs=5e3,Es=5e3,je="shadowObjects";function Ss(s,t){s.indexOf(t)===-1&&s.push(t)}function _e(s,t){let e=s.indexOf(t);e!==-1&&s.splice(e,1),s.push(t)}function K(s,t){let e=s.indexOf(t);e!==-1&&s.splice(e,1)}var ut=s=>typeof s=="string"?s.trim()||lt:typeof s=="symbol"?s:lt;var St="#root",xt=class{#t;get uuid(){return this.#t}#e=0;constructor(t){this.#t=t}#s=!0;#i=0;#r=0;hasChanges(){return this.#e>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=G;#o;#a=0;#h;#l;#u;create(t=G,e,r=0){this.#e++,this.#i++,this.#h=t,this.#l=e??St,this.#u=r||void 0}destroy(){this.#r++,this.#e++}clear(){this.#e=0,this.#s=!1,this.#h=void 0,this.#l=void 0,this.#u=void 0,this.#f.clear(),this.#d.length=0,this.#g.length=0,this.#p.clear()}changeToken(t){t===this.#n?this.#h=void 0:(this.#h=t,this.#e++)}setParent(t){t===this.#o?this.#l=void 0:(this.#l=t??St,this.#e++)}changeOrder(t){t===this.#a?this.#u=void 0:(this.#u=t,this.#e++)}#c=new Map;#f=new Map;#d=[];changeProperty(t,e,r){let i=this.#c.get(t);r==null&&e!==i||r!=null&&!r(e,i)?(this.#f.set(t,e),_e(this.#d,t),this.#e++):(this.#f.delete(t),K(this.#d,t))}removeProperty(t){let e=this.#c.has(t);this.#f.has(t)?(this.#f.delete(t),e||K(this.#d,t)):e&&(_e(this.#d,t),this.#e++)}#g=[];#p=new Set;createEvent(t,e,r){this.#g.push({type:t,data:e}),r?.forEach(i=>this.#p.add(i)),this.#e++}transferEventsTo(t){this.#g.length>0&&(t.#g.push(...this.#g),this.#g.length=0),this.#p.size>0&&(t.#p=new Set([...t.#p,...this.#p]),this.#p.clear())}buildChangeTrail(t,e){let{isNew:r,isCreated:i,isDestroyed:n}=this;if(!(r&&n))switch(e){case $.StructuralChanges:r?t.push(this.makeCreateEntityChange()):n||(this.#l!==void 0&&!(this.#l===St&&this.#o===void 0)?t.push(this.makeSetParentChange()):this.#u!==void 0&&this.#u!==this.#a&&t.push(this.makeUpdateOrderChange()),this.#h!==void 0&&this.#h!==this.#n&&t.push(this.makeChangeToken()));break;case $.ContentUpdates:!r&&i&&this.#d.length>0&&t.push(this.makeChangePropertyChange()),this.#g.length>0&&t.push(this.makeEvents());break;case $.Removal:n&&t.push(this.makeDestroyEntityChange());break}}makeEvents(){let t={type:b.SendEvents,uuid:this.#t,events:this.#g.slice(0)};return this.#p.size>0&&(t.transferables=Array.from(this.#p)),t}makeCreateEntityChange(){let t={type:b.CreateEntities,uuid:this.#t,token:this.#h};if(this.#n=this.#h,this.#l!==void 0){let e=this.#l===St?void 0:this.#l;this.#o=e,e!==void 0&&(t.parentUuid=e)}return this.#f.size>0&&(t.properties=Array.from(this.#f.entries()).filter(([,e])=>e!==void 0),t.properties.forEach(([e,r])=>this.#c.set(e,r))),this.#u!==void 0&&this.#u!==this.#a&&(t.order=this.#a=this.#u),t}makeDestroyEntityChange(){return{type:b.DestroyEntities,uuid:this.#t}}makeSetParentChange(){this.#o=this.#l===St?void 0:this.#l;let t={type:b.SetParent,uuid:this.#t,parentUuid:this.#o};return this.#u!==void 0&&this.#u!==this.#a&&(t.order=this.#a=this.#u),t}makeUpdateOrderChange(){return this.#a=this.#u??0,{type:b.UpdateOrder,uuid:this.#t,order:this.#a}}makeChangeToken(){return this.#n=this.#h??G,{type:b.ChangeToken,uuid:this.#t,token:this.#n}}makeChangePropertyChange(){let t=this.#d.map(e=>{if(this.#f.has(e)){let r=this.#f.get(e);return this.#c.set(e,r),[e,r]}else return this.#c.delete(e),[e,void 0]});return{type:b.ChangeProperties,uuid:this.#t,properties:t}}};var xs=s=>{if(!(s===void 0||s.length===0))return s.filter(t=>t.length===1||t[1]!==void 0)},Ne=(s,t)=>{if(s===t||t===void 0)return s;if(s===void 0)return xs(t);for(let[e,r]of t){let i=s.find(([n])=>n===e);i===void 0?s.push([e,r]):i[1]=r}return xs(s)};var Xt=class{#t=new Map;get[Symbol.iterator](){return this.#t.entries.bind(this.#t)}clear(){this.#t.clear()}isEmpty(){return this.#t.size===0}hasComponentState(t){return this.#t.has(t)}getComponentState(t){return this.#t.get(t)}write(t){for(let e of t)if(e.type===b.CreateEntities)this.createEntity(e);else if(this.#t.has(e.uuid))switch(e.type){case b.DestroyEntities:this.destroyEntity(e);break;case b.SetParent:this.setParent(e);break;case b.UpdateOrder:this.updateOrder(e);break;case b.ChangeToken:this.changeToken(e);break;case b.ChangeProperties:this.changeProperties(e);break}}changeProperties({uuid:t,properties:e}){let r=this.getComponentState(t);r.properties=Ne(r.properties,e)}changeToken({uuid:t,token:e}){this.getComponentState(t).token=e||G}updateOrder({uuid:t,order:e}){this.getComponentState(t).order=e??0}setParent({uuid:t,parentUuid:e,order:r}){let i=this.getComponentState(t);i.parentUuid=e,i.order=r??0}destroyEntity({uuid:t}){this.#t.delete(t)}createEntity({uuid:t,token:e,parentUuid:r,order:i,properties:n}){this.#t.set(t,{token:e||G,parentUuid:r,order:i??0,properties:Ne(void 0,n)})}};var N=class s{static{this.ReRequestParentRoots="re-request-parent-roots"}static getContextsMap(){return globalThis.__shadowEntsContexts==null&&(globalThis.__shadowEntsContexts=new Map),globalThis.__shadowEntsContexts}static get(t){let e=ut(t),r=s.getContextsMap();return r.has(e)?r.get(e):new s(e)}#t=new Map;#e=[];#s=new Xt;constructor(t=lt){let e=ut(t),r=s.getContextsMap();if(r.has(e))return r.get(e);this.ns=e,r.set(e,this)}addComponent(t){let e;this.#t.has(t.uuid)?(e=this.#t.get(t.uuid),e.component=t,e.children=[]):(e={component:t,children:[],changes:new xt(t.uuid),propIsEqual:void 0},this.#t.set(t.uuid,e)),e.changes.create(t.token,t.parent?.uuid,t.order),t.parent?(this.addToChildren(t.parent,t),e.changes.setParent(t.parent.uuid)):this.#n(t,this.#e),this.#o=void 0}hasComponent(t){return this.#t.has(t.uuid)}hasComponents(){return this.#t.size>0}isRootComponent(t){return this.#e.includes(t.uuid)}destroyComponent(t){if(this.hasComponent(t)){let e=this.#t.get(t.uuid);e.children.slice(0).forEach(r=>this.#t.get(r)?.component.removeFromParent()),e.changes.destroy(),this.#o=void 0}}getChildren(t){return this.#t.get(t.uuid)?.children.map(e=>this.#t.get(e).component)??[]}removeFromParent(t,e){if(this.hasComponent(e)){let r=this.#t.get(t),i=this.#t.get(e.uuid),n=i.children.indexOf(t);n!==-1&&(i.children.splice(n,1),r.changes.setParent(void 0)),this.#n(r.component,this.#e),this.#o=void 0}}moveToRoot(t){let e=this.#t.get(t);e&&(e.changes?.setParent(void 0),this.#n(e.component,this.#e)),this.#o=void 0}changeToken(t,e){this.#t.get(t.uuid)?.changes.changeToken(e)}isChildOf(t,e){return this.hasComponent(e)?this.#t.get(e.uuid).children.includes(t.uuid):!1}addToChildren(t,e){let r=this.#t.get(t.uuid);if(r)this.#n(e,r.children),this.#t.get(e.uuid)?.changes.setParent(t.uuid),K(this.#e,e.uuid),this.#o=void 0;else throw new Error(`the view component ${t.uuid} cannot have a child added to it because the component do not exist!`)}removeSubTree(t){let e=this.#t.get(t);e&&(e.children.slice(0).forEach(r=>this.removeSubTree(r)),this.destroyComponent(e.component),this.#i(t))}setProperty(t,e,r,i){let n=this.#t.get(t.uuid);return n!=null?(i!=null?(n.propIsEqual??=new Map,n.propIsEqual.set(e,i)):n.propIsEqual?.has(e)&&n.propIsEqual.delete(e),n.changes.changeProperty(e,r,i)):!1}removeProperty(t,e){this.#t.get(t.uuid)?.changes.removeProperty(e)}changeOrder(t){if(t.parent){let e=this.#t.get(t.parent.uuid);K(e.children,t.uuid),this.#n(t,e.children)}else K(this.#e,t.uuid),this.#n(t,this.#e);this.#t.get(t.uuid)?.changes.changeOrder(t.order),this.#o=void 0}traverseLevelOrderBFS(){return this.#a().map(t=>t.component)}dispatchShadowObjectsEvent(t,e,r,i){this.#t.get(t.uuid)?.changes.createEvent(e,r,i)}broadcastEvent(t,e=void 0){for(let r of this.traverseLevelOrderBFS())r.dispatchEvent(t,e,!1)}dispatchMessage(t,e,r=void 0,i=!1){this.#t.get(t)?.component.dispatchEvent(e,r,i)}dispatchReRequestParentRoots(){for(let t of this.#e)this.dispatchMessage(t,s.ReRequestParentRoots)}buildChangeTrails(t=!0){let e=[];if(!this.hasComponents())return e;let r=this.#r();for(let i of r)i.buildChangeTrail(e,$.StructuralChanges);for(let i of r)i.buildChangeTrail(e,$.ContentUpdates);for(let i of r)i.buildChangeTrail(e,$.Removal),(i.isDestroyed||i.isNew&&!i.isCreated)&&this.#i(i.uuid),t&&i.clear();return this.#s.write(e),e}reCreateChanges(){if(!this.#s.isEmpty()){this.buildChangeTrails(!1);for(let[t,e]of this.#s){let r=this.#t.get(t);if(r){let i=new xt(t);if(i.create(e.token,e.parentUuid,e.order),e.properties)for(let[n,o]of e.properties)i.changeProperty(n,o,r.propIsEqual?.get(n));r.changes.transferEventsTo(i),r.changes.clear(),r.changes=i}}this.#s.clear(),this.broadcastEvent(cs)}}clear(){if(this.#o=void 0,this.#s.clear(),this.#e.slice(0).forEach(t=>this.removeSubTree(t)),this.#e.length!==0)throw new Error("component-context panic: #rootComponents is not empty!");if(this.#t.size!==0)throw new Error("component-context panic: #components is not empty!")}#i(t){this.#t.has(t)&&(this.#t.delete(t),K(this.#e,t),this.#o=void 0)}#r(){return this.#a().filter(t=>t.changes.hasChanges()).map(t=>t.changes)}#n(t,e){if(e.length===0){e.push(t.uuid);return}if(e.includes(t.uuid))return;let r=e.length,i=new Array(r);if(i[0]=this.#t.get(e[0]).component,t.order<i[0].order){e.unshift(t.uuid);return}if(r===1){e.push(t.uuid);return}let n=r-1;if(i[n]=this.#t.get(e[n]).component,t.order>=i[n].order){e.push(t.uuid);return}if(r===2){e.splice(1,0,t.uuid);return}for(let o=n-1;o>=1;o--)if(i[o]=this.#t.get(e[o]).component,t.order>=i[o].order){e.splice(o+1,0,t.uuid);return}}#o;#a(){if(this.#o)return this.#o;let t=new Map,e=(r,i)=>{let n=this.#t.get(r);if(n!=null){t.has(i)?t.get(i).push(n):t.set(i,[n]);for(let o of n.children)e(o,i+1)}};return this.#e.forEach(r=>e(r,0)),this.#o=Array.from(t.entries()).sort((r,i)=>r[0]-i[0]).map(([,r])=>r).flat(),this.#o}};function kt(s,t,e,r,i,n){function o(vt){if(vt!==void 0&&typeof vt!="function")throw new TypeError("Function expected");return vt}for(var h=r.kind,a=h==="getter"?"get":h==="setter"?"set":"value",c=!t&&s?r.static?s:s.prototype:null,p=t||(c?Object.getOwnPropertyDescriptor(c,r.name):{}),l,u=!1,g=e.length-1;g>=0;g--){var y={};for(var P in r)y[P]=P==="access"?{}:r[P];for(var P in r.access)y.access[P]=r.access[P];y.addInitializer=function(vt){if(u)throw new TypeError("Cannot add initializers after decoration has completed");n.push(o(vt||null))};var et=(0,e[g])(h==="accessor"?{get:p.get,set:p.set}:p[a],y);if(h==="accessor"){if(et===void 0)continue;if(et===null||typeof et!="object")throw new TypeError("Object expected");(l=o(et.get))&&(p.get=l),(l=o(et.set))&&(p.set=l),(l=o(et.init))&&i.unshift(l)}else(l=o(et))&&(h==="field"?i.unshift(l):p[a]=l)}c&&Object.defineProperty(c,r.name,p),u=!0}function J(s,t,e){for(var r=arguments.length>2,i=0;i<t.length;i++)e=r?t[i].call(s,e):t[i].call(s);return r?e:void 0}function At(s){return function(t,e){let r=s?.name||e.name,i=!!(s?.readAsValue??!1);return{get(){let n=T(this,r);if(n)return i?n.value:n.get()},set(n){T(this,r)?.set(n)},init(n){let o=f(n,s);return hs(this,r,o),M.findOrCreate(this).attachSignalByName(r,o),o.value}}}}var j="ConsoleLogger",L=`${j}Storage`,or=!!(globalThis.location?.host?.startsWith("localhost")??!1),Tt="localStorage"in globalThis,Zt=Symbol.for(j),ks=!1,As=s=>{if(typeof s=="boolean")return s;switch(s.toLowerCase()){case"true":case"yes":case"on":return!0;default:return!1}},$e=s=>[Tt?j:void 0,...Array.isArray(s)?s:[s]].filter(Boolean).join(".");function De(s,t=void 0,e){let r=$e(s),i=Tt?localStorage.getItem(r):globalThis[L]?.[r];return i!=null?t(i):e}function Ot(s,t){Tt?localStorage.setItem($e(s),t):(globalThis[L]==null&&(globalThis[L]={},console.debug(`${j}: Initialize`,{[L]:globalThis[L]})),globalThis[L][$e(s)]=t)}var A=class s{static{this.sharedConfig={enable:or,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(t){s.sharedConfig["styles.debug"]=t},get info(){return s.sharedConfig["styles.info"]},set info(t){s.sharedConfig["styles.info"]=t},get warn(){return s.sharedConfig["styles.warn"]},set warn(t){s.sharedConfig["styles.warn"]=t},get error(){return s.sharedConfig["styles.error"]},set error(t){s.sharedConfig["styles.error"]=t}}}static loadConfig(){Tt?(["enable","debug","info","warn"].forEach(t=>{this.sharedConfig[t]=De(t,As,this.sharedConfig[t])}),["debug","info","warn","error"].forEach(t=>{this.sharedStyles[t]=De(["styles",t],void 0,this.sharedStyles[t])}),s.isDebug&&console.debug(`${j}: Load config from localStorage`,s.sharedConfig),globalThis[j]?.[Zt]||(globalThis[j]??={[Zt]:!0,get enable(){return s.sharedConfig.enable},set enable(t){s.sharedConfig.enable=t,Ot("enable",t?"true":"false")},get debug(){return s.sharedConfig.debug},set debug(t){s.sharedConfig.debug=t,Ot("debug",t?"true":"false")},get info(){return s.sharedConfig.info},set info(t){s.sharedConfig.info=t,Ot("info",t?"true":"false")},get warn(){return s.sharedConfig.warn},set warn(t){s.sharedConfig.warn=t,Ot("warn",t?"true":"false")}})):globalThis[L]?.[Zt]||(globalThis[L]={[Zt]:!0,...s.sharedConfig,...globalThis[L]},s.sharedConfig=globalThis[L],s.isDebug&&console.debug(`${j}: Load config from ${L}`,globalThis[L]))}constructor(t){this.enable=!0,this.namespace=(t||"").trim()||j,ks||(s.loadConfig(),ks=!0);let e=[this.namespace,"enable"];this.enable=De(e,As,this.enable),Ot(e,Tt?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(...t){this.#t("debug",s.sharedStyles.debug,t)}info(...t){this.#t("info",s.sharedStyles.info,t)}warn(...t){this.#t("warn",s.sharedStyles.warn,t)}error(...t){this.#t("error",s.sharedStyles.error,t)}#t(t,e,r){console[t](`%c${this.namespace}`,e,...r)}};var I=(()=>{var s;let t,e=[],r=[],i,n=[],o=[];return class B{static{let a=typeof Symbol=="function"&&Symbol.metadata?Object.create(null):void 0;t=[At()],i=[At()],kt(this,null,t,{kind:"accessor",name:"viewReady",static:!1,private:!1,access:{has:c=>"viewReady"in c,get:c=>c.viewReady,set:(c,p)=>{c.viewReady=p}},metadata:a},e,r),kt(this,null,i,{kind:"accessor",name:"proxyReady",static:!1,private:!1,access:{has:c=>"proxyReady"in c,get:c=>c.proxyReady,set:(c,p)=>{c.proxyReady=p}},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)}#t;#e;#s;#i;#r;#n;#o;get viewReady(){return this.#o}set viewReady(a){this.#o=a}#a;get proxyReady(){return this.#a}set proxyReady(a){this.#a=a}#h;get isDestroyed(){return this.#h}constructor(){this.#s=!1,this.#i=!1,this.#r=!1,this.logger=new A("ShadowEnv"),this.ns$=f(),this.#o=J(this,e,!1),this.#a=(J(this,r),J(this,n,!1)),this.#h=(J(this,o),!1),this.ready=async()=>this.isReady?this:ct(this,B.ContextCreated),this.#l=()=>{this.#s&&this.#u()},U(this,B.ContextCreated),m(this,B.ContextLost,z.AAA,()=>{H(this,B.ContextCreated)}),w(()=>{if(this.viewReady&&this.proxyReady)return this.view.reCreateChanges(),d(this,B.ContextCreated,this),this.#i&&(this.#i=!1,this.#u()),()=>{d(this,B.ContextLost,this)}},[T(this,"viewReady"),T(this,"proxyReady")])}get view(){return this.#t}set view(a){a!==this.#t&&(this.#t&&this.#t.ns&&globalThis.__shadowEnvs&&globalThis.__shadowEnvs.delete(this.#t.ns),this.#t=a??void 0,this.#t&&this.#t.ns&&(globalThis.__shadowEnvs??=new Map,globalThis.__shadowEnvs.has(this.#t.ns)&&globalThis.__shadowEnvs.get(this.#t.ns)!==this&&this.logger.isWarn&&this.logger.warn("overwrite a namespace already in use",this.#t.ns,globalThis.__shadowEnvs.get(this.#t.ns)),globalThis.__shadowEnvs.set(this.#t.ns,this)),this.viewReady=!!a)}get envProxy(){return this.#e}set envProxy(a){if(a!==this.#e){let c=this.#e;this.#e=a??void 0,this.#e&&(this.#e.onMessageToView=this.#c.bind(this)),c&&c.destroy(),this.proxyReady=!1,a?.start().then(()=>{this.proxyReady=!0}).catch(p=>{this.logger.error("failed to start envProxy",p),this.proxyReady=!1})}}get isReady(){return!!(this.#t&&this.#e&&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=ct(this,B.AfterSync).then(a=>(this.#n=void 0,a)),this.#n)}destroy(){let a=this.#t?.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),Et(this),E(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 c=this.#r;this.#r=!1,await this.envProxy.applyChangeTrail(a,c)}catch(c){this.logger.error("failed to apply change trail",c)}finally{d(this,B.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 k=["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"],ar=()=>{let s=Math.random()*4294967295|0,t=Math.random()*4294967295|0,e=Math.random()*4294967295|0,r=Math.random()*4294967295|0;return(k[s&255]+k[s>>8&255]+k[s>>16&255]+k[s>>24&255]+"-"+k[t&255]+k[t>>8&255]+"-"+k[t>>16&15|64]+k[t>>24&255]+"-"+k[e&63|128]+k[e>>8&255]+"-"+k[e>>16&255]+k[e>>24&255]+k[r&255]+k[r>>8&255]+k[r>>16&255]+k[r>>24&255]).toLowerCase()},Os=()=>globalThis?.crypto?.randomUUID?.()??ar();var Pt=class extends Error{constructor(t){super(t),this.name="ViewComponentError"}},te=class s{#t;#e;#s;#i;#r=0;get uuid(){return this.#t}get token(){return this.#e}set token(t){t??=G,t!==this.#e&&(this.#e=t,this.#s?.changeToken(this,t))}get parent(){return this.#i}set parent(t){if(t){if(t.#s!==this.#s)throw new Pt("cannot set parent from different context");t.addChild(this)}else this.removeFromParent()}get context(){return this.#s}set context(t){this.#s!=t&&(this.#s&&this.destroy(),this.#s=t,t&&t.addComponent(this))}get order(){return this.#r}set order(t){let e=this.#r;this.#r=t??0,e!==this.#r&&this.#s.changeOrder(this)}constructor(t,e){S(this),e instanceof s&&(e={parent:e}),this.#t=e?.uuid??Os(),this.#e=t,this.#r=e?.order??0,this.#i=e?.parent;let r=e?.context??N.get();if(this.#i&&this.#i.#s!==r)throw new Pt("cannot set parent from different context");this.context=r}isChildOf(t){return this.#i===t}removeFromParent(){this.#i?(this.#s?.removeFromParent(this.uuid,this.#i),this.#i=void 0):this.#s?.moveToRoot(this.uuid)}addChild(t){if(t.#s!==this.#s)throw new Pt("cannot add a child from another context");t.isChildOf(this)||(t.removeFromParent(),t.#i=this,this.#s.addToChildren(this,t))}setProperty(t,e,r){this.#s.setProperty(this,t,e,r)}removeProperty(t){this.#s.removeProperty(this,t)}dispatchShadowObjectsEvent(t,e,r){this.#s.dispatchShadowObjectsEvent(this,t,e,r)}dispatchEvent(t,e,r){if(d(this,t,e),r)for(let i of this.#s.getChildren(this))i.dispatchEvent(t,e,r)}destroy(){this.removeFromParent(),this.#s?.destroyComponent(this),this.#s=void 0}};var ee="shaeRequestEntParent",se="shaeReRequestEntParent",Ts="shae-worker",re="shae-ent",Ps="shae-prop",X="token";var ie="local",Rs="no-autostart",ne="no-structured-clone",F="auto-sync";var oe="name",ae="value",he="type",le="no-trim";var Rt=new Set(["on","true","yes","local","1"]);var Ms=s=>ut(s.getAttribute("ns")),Lt=(s,t)=>{if(s.hasAttribute(t)){let e=s.getAttribute(t)?.trim()?.toLowerCase()||"1";return Rt.has(e)}return!1};var Ls=(s,t)=>{t.set(Ms(s))},Ie=new Set,Fe=!1,hr=s=>{Ie.add(s),Fe||(Fe=!0,queueMicrotask(()=>{Fe=!1;for(let t of Ie)I.get(t)?.sync();Ie.clear()}))},Z=class extends HTMLElement{static{this.observedAttributes=["ns"]}get ns(){return this.ns$.value}set ns(t){typeof t=="symbol"?this.ns$.set(t):this.ns$.set(ut(t))}constructor(){super(),this.isShaeElement=!0,this.ns$=f(lt),this.ns$.onChange(t=>{typeof t=="string"&&t.length>0?this.getAttribute("ns")!==t&&this.setAttribute("ns",t):this.removeAttribute("ns")}),Ls(this,this.ns$)}attributeChangedCallback(t){t==="ns"&&Ls(this,this.ns$)}syncShadowObjects(){hr(this.ns)}};var ue=class extends Z{static{this.observedAttributes=[...Z.observedAttributes,X]}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(t){this.token$.set(t)}#t;constructor(){super(),this.isShaeEntElement=!0,this.componentContext$=f(),this.viewComponent$=f(),this.token$=f(),this.#n=!0,this.#f=()=>{let t=this.findShadowRootHost();t!=null&&this.dispatchEvent(new CustomEvent(se,{bubbles:!0,composed:!0,detail:{requester:this,shadowRootHost:t}}))},this.#d=t=>{let e=t.detail?.requester;if(e===this||!e?.isShaeEntElement||e.ns!==this.ns)return;t.detail?.shadowRootHost&&this.#l()},this.#g=t=>{let e=t.detail?.requester;e!==this&&e?.isShaeEntElement&&e.ns===this.ns&&(t.stopPropagation(),e.#c(this))},this.ns$.onChange(t=>{this.componentContext$.set(N.get(t)),this.isConnected&&this.#l()}),this.#p(),this.token$.onChange(t=>{t==null?this.removeAttribute(X):this.getAttribute(X)!==t&&this.setAttribute(X,t)}),w(()=>{let t=this.viewComponent$.get();if(t){let e=m(t,N.ReRequestParentRoots,()=>this.#h()),r=t.context?.ns;return()=>{e(),t.destroy(),r&&r!==this.ns?I.get(r)?.sync():this.syncShadowObjects()}}}),this.token$.onChange(t=>{let e=this.viewComponent$.value;e&&(e.token=t,this.syncShadowObjects())})}#e;#s(){this.#e?.();let t=this.componentContext$.onChange(e=>{let r=this.token$.value,i=this.viewComponent$.value;i?i.context=e:e&&(i=new te(r,{context:e}),this.viewComponent$.set(i)),this.syncShadowObjects()});this.#e=()=>{t()}}#i(){this.#e?.(),this.#e=void 0}#r;#n;findShadowRootHost(){if(this.#n){this.#n=!1;let t=this;for(;t;){if(t.parentElement==null){let e=t.parentNode;e&&(this.#r=e.host);break}t=t.parentElement}}return this.#r}getParentNodeForObserver(){let t=this.parentNode;return t||(t.host??t)}connectedCallback(){this.#n=!0,this.addEventListener("slotchange",this.#f,{capture:!1,passive:!1}),this.addEventListener(ee,this.#g,{capture:!1,passive:!1}),this.#s(),Re(()=>this.#p()),this.componentContext==null&&this.componentContext$.set(N.get(this.ns)),this.#l(),this.componentContext?.dispatchReRequestParentRoots(),this.#o(),this.syncShadowObjects()}#o(){this.#a();let t=this.getParentNodeForObserver();t&&(this.#t=new MutationObserver((e,r)=>{for(let{target:i,removedNodes:n}of e)if(i===t){for(let o of n)if(o===this){this.#a(),this.onParentChanged(this.getParentNodeForObserver(),t);break}}}),this.#t.observe(t,{childList:!0,subtree:!1,attributes:!1}))}onParentChanged(t,e){this.#c(void 0),this.#l()}#a(){this.#t?.disconnect(),this.#t=void 0}attributeChangedCallback(t){super.attributeChangedCallback(t),t===X&&this.#p()}disconnectedCallback(){this.#n=!0,this.#a(),this.removeEventListener("slotchange",this.#f,{capture:!1}),this.removeEventListener(ee,this.#g,{capture:!1}),this.#c(void 0),this.componentContext$.set(void 0),this.syncShadowObjects(),this.#i()}#h(){this.isConnected&&(this.#c(void 0),this.#l())}#l(){this.dispatchEvent(new CustomEvent(ee,{bubbles:!0,composed:!0,detail:{requester:this}}))}#u;#c(t){if(this.entParentNode!==t)if(this.entParentNode&&this.entParentNode.removeEventListener(se,this.#d,{capture:!1}),this.entParentNode=t,this.entParentNode&&this.entParentNode.addEventListener(se,this.#d,{capture:!1,passive:!1}),this.#u?.(),this.#u=void 0,t){let e=w(()=>{let r=this.viewComponent$.get();if(r){let i=t.viewComponent$.get();r.parent=i&&i.context===r.context?i:void 0,r.parent==null&&queueMicrotask(()=>{this.#l()}),this.syncShadowObjects()}});this.#u=()=>e.destroy()}else{let e=this.viewComponent;e.parent&&(e.parent=void 0,this.syncShadowObjects())}}#f;#d;#g;#p(){if(this.hasAttribute(X)){let t=this.getAttribute(X)?.trim()||void 0;this.token$.set(t)}}};customElements.define(re,ue);var lr=s=>{let t=s.parentElement;for(;t;){if(t.isShaeEntElement)return t;t=t.parentElement}},ur=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"]),ce=class extends HTMLElement{static{this.observedAttributes=[oe,ae,he,le]}get name(){return this.name$.value}get value(){return this.valueOut$.value}set value(t){this.valueIn$.set(t)}get shouldTrim(){return this.shouldTrim$.value}get entNode(){return this.entNode$.value}set entNode(t){this.entNode$.set(t)}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 A("ShaePropElement"),this.#t=()=>{this.entNode$.set(lr(this))},this.#e=()=>{queueMicrotask(()=>{this.isConnected||this.entNode$.set(void 0)})},this.#s=()=>{this.name$.set(this.getAttribute(oe)?.trim()??void 0)},this.#i=()=>{this.valueIn$.set(this.getAttribute(ae))},this.#r=()=>{let t=this.getAttribute(he)?.trim().toLowerCase();t&&!ur.has(t)&&(this.logger.isWarn&&this.logger.warn(`[${this.name}] unknown type "${t}"`,{shaeProp:this}),t=void 0),this.type$.set(t)},this.#n=()=>{this.shouldTrim$.set(!Lt(this,le))},this.entNode$.onChange(t=>{if(t){let e=_(t.viewComponent$,this.viewComponent$);return()=>{e.destroy()}}else this.viewComponent$.set(void 0)}),w(()=>{let t=this.viewComponent$.get();if(t){let e=this.name$.get();if(e){let r=this.valueOut$.get();this.logger.isDebug&&this.logger.debug(`[${this.name}] view-component set-property`,e,r,t.uuid,{viewComponent:t,shaeProp:this}),t.setProperty(e,r),this.isConnected&&this.entNode?.syncShadowObjects()}}}),w(()=>{let t=this.type$.get(),e=this.shouldTrim$.get(),r=this.valueIn$.get();if(e&&typeof r=="string"&&(r=r.trim()),r=r||void 0,r!=null&&typeof r=="string"&&t)switch(t){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=Rt.has(r.toLowerCase());break;case"[]":case"text[]":case"string[]":r=r.split(/\W+/);break;case"number[]":r=r.split(/\s+/).map(i=>Number(i));break;case"float[]":r=r.split(/\s+/).map(i=>parseFloat(i));break;case"int[]":case"integer[]":r=r.split(/\s+/).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=>Rt.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(/\s+/).map(i=>Number(i)));break;case"float64array":r=new Float64Array(r.split(/\s+/).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 "${t}"`,{value:r,shaeProp:this})}this.valueOut$.set(r)}),O(()=>{this.#s(),this.#i(),this.#r(),this.#n()})}connectedCallback(){O(()=>{this.#t(),this.#s(),this.#i(),this.#r(),this.#n()})}attributeChangedCallback(t){switch(t){case oe:this.#s();break;case ae:this.#i();break;case he:this.#r();break;case le:this.#n();break}}disconnectedCallback(){this.#e()}#t;#e;#s;#i;#r;#n};customElements.whenDefined(re).then(()=>customElements.define(Ps,ce));var fe,We=null,mt=class{static{this.OnFrame=Symbol("onFrame")}#t=0;#e=0;constructor(){if(We)return We;S(this),We=this}start(t){if(t!=null)return xe(this)===0&&this.#i(),m(this,fe.OnFrame,t),this.#e++,()=>{this.stop(t)}}stop(t){E(this,fe.OnFrame,t),xe(this)===0&&this.#r()}#s=t=>{d(this,fe.OnFrame,t),this.#i()};#i(){this.#t=requestAnimationFrame(this.#s)}#r(){cancelAnimationFrame(this.#t),this.#t=0}};fe=mt;var bt="value",jt=(()=>{let s,t=[],e=[];return class{static{let i=typeof Symbol=="function"&&Symbol.metadata?Object.create(null):void 0;s=[At({name:bt})],kt(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},t,e),i&&Object.defineProperty(this,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:i})}static{this.Value=bt}#t;#e;#s;get value(){return this.#s}set value(i){this.#s=i}constructor(i){this.#t=[],this.#s=J(this,t,void 0),this.value$=J(this,e),U(this,bt),this.value$=T(this,bt),this.value$.onChange(n=>d(this,bt,n)),i&&this.add(...i)}add(...i){return this.#t.push(...i),this.#r(),this.#i(i)}unshift(...i){return this.#t.unshift(...i),this.#r(),this.#i(i)}remove(...i){this.#i(i)()}clear(){this.#t.length=0,this.#r()}dispose(){this.clear(),this.#e?.destroy(),this.#e=void 0,H(this,bt),E(this),this.value$.destroy(),Et(this)}#i(i){return()=>{for(let n of i){let o=this.#t.indexOf(n);o!==-1&&this.#t.splice(o,1)}this.#r()}}#r(){this.#e?.destroy(),this.#t.length===0?(this.#e=void 0,this.value=void 0):(this.#e=w(()=>{let i;for(let n of this.#t){let o=ht(n);if(o!=null){i=o;break}}this.value=i},this.#t),this.#e.run())}}})();var ze="onCreate",tt="onDestroy",js="onParentChanged",_s="onViewEvent";var Ue=new Map,Ve=!1,cr=(s,t)=>{Ue.set(s,t),Ve||(Ve=!0,queueMicrotask(()=>{Ve=!1;let e=Array.from(Ue.entries());Ue.clear();for(let[r,i]of e)r.set(i)}))},de=class{#t;#e;#s=new Jt;#i=new Map;#r=new Map;#n;#o;#a=new Set;#h=[];#l=0;get kernel(){return this.#t}get uuid(){return this.#e}get order(){return this.#l}set order(t){this.#l!==t&&(this.#l=t,this.#n&&this.parent.resortChildren())}get parentUuid(){return this.#n||void 0}set parentUuid(t){this.#n!==t&&(this.removeFromParent(),this.#n=t||void 0,this.#o=t?this.#t.getEntity(t):void 0,this.#o&&this.#o.addChild(this))}get parent(){return!this.#o&&this.#n&&(this.#o=this.#t.getEntity(this.#n)),this.#o}set parent(t){this.parentUuid=t?.uuid}get hasParent(){return!!this.#n}get children(){return this.#h}constructor(t,e){this.#t=t,this.#e=e,C(this,tt,z.Min,this)}traverse(t){t(this);for(let e of this.#h)e.traverse(t)}onDestroy(){this.#s.clear(),E(this);for(let t of this.#r.values())t.cleanup(),t.signal.destroy();this.#r.clear();for(let t of this.#i.values())t.context.set(void 0),t.unsubscribePathValue(),t.unsubscribeFromParent?.(),t.valuePath.dispose(),t.inherited.destroy(),t.provide.destroy(),t.context.destroy();this.#n=void 0,this.#o=void 0,this.#a.clear(),this.#h.length=0}addChild(t){if(this.#h.length===0){this.#a.add(t.uuid),this.#h.push(t);return}if(this.#a.has(t.uuid))throw new Error(`child with uuid: ${t.uuid} already exists! parentUuid: ${this.uuid}`);this.#a.add(t.uuid),this.#h.push(t),this.resortChildren();for(let[,e]of t.#i)t.#d(e)}resortChildren(){this.#h.sort((t,e)=>t.order-e.order)}removeChild(t){this.#a.has(t.uuid)&&(this.#a.delete(t.uuid),this.#h.splice(this.#h.indexOf(t),1))}removeFromParent(){if(this.#o){this.#o.removeChild(this),this.#o=void 0,this.#n=void 0;for(let[,t]of this.#i)t.unsubscribeFromParent&&(t.unsubscribeFromParent(),t.unsubscribeFromParent=void 0)}}reSubscribeToParentContexts(){for(let[,t]of this.#i)this.#d(t)}dispatchMessageToView(t,e,r,i=!1){this.#t.dispatchMessageToView({uuid:this.#e,type:t,data:e,transferables:r,traverseChildren:i})}dispatchViewEvents(t){for(let{type:e,data:r}of t)d(this,_s,e,r)}dispatchViewEvent(t,e){this.dispatchViewEvents([{type:t,data:e}])}#u(t){return this.#s.get(t)}getPropertyReader(t){return this.#u(t).get}getPropertyWriter(t){return this.#u(t).set}setProperties(t){this.clearTruthyPropsCache(),O(()=>{for(let[e,r]of t)this.setProperty(e,r)})}setProperty(t,e){this.getPropertyWriter(t)(e)}getProperty(t){return ht(this.getPropertyReader(t))}propKeys(){return Array.from(this.#s.keys())}propEntries(){return Array.from(this.#s.entries()).map(([t,e])=>[t,e.value])}#c;clearTruthyPropsCache(){this.#c=void 0}truthyProps(){if(this.#c)return this.#c.size?this.#c:void 0;let t=new Set;for(let[e,r]of this.#s.entries())if(typeof e=="string"){let i=r.value;i!=null&&i!==!1&&i!==""&&t.add(e)}return this.#c=t,t.size?t:void 0}hasContext(t){return this.#i.has(t)}useContext(t){return this.#f(t).context.get}useParentContext(t){return this.#f(t).inherited.get}provideContext(t){return this.#f(t).provide}provideGlobalContext(t){if(this.#r.has(t))return this.#r.get(t).signal;let e=this.#t.findOrCreateRootContext(t),r=f(),i=e.add(r);return this.#r.set(t,{cleanup:i,signal:r}),r}#f(t){if(this.#i.has(t))return this.#i.get(t);let e=f(),r=f(),i=f(),n=new jt([r,e]),o=m(n,jt.Value,a=>{cr(i,a)}),h={name:t,inherited:e,provide:r,context:i,valuePath:n,unsubscribePathValue:o};return this.#i.set(t,h),this.#d(h),h}#d(t){if(t.unsubscribeFromParent?.(),t.unsubscribeFromParent=void 0,this.parent){let e=this.parent.#f(t.name),r=_(e.context,t.inherited);t.unsubscribeFromParent=r.destroy.bind(r)}else{let e=this.#t.findOrCreateRootContext(t.name),r=_(e.value$,t.inherited);t.unsubscribeFromParent=r.destroy.bind(r)}}};var Ns=s=>{let t=s.split("@").map(e=>e.trim());if(t.length===2&&t[1])return t[0]?{key:`${t[0]}@${t[1]}`,prop:t[1],token:t[0]}:{key:t[1],prop:t[1]}},pe=(s,t)=>{for(let e of t)s.add(e)},fr=(s,t)=>{if(s!=null)for(let e of s.constructors)t.add(e)},_t=class{static get(t){return t??dr}#t=new Map;#e=new Map;#s=new Map;define(t,e){this.#t.has(t)?Ss(this.#t.get(t).constructors,e):this.#t.set(t,{token:t,constructors:[e]})}appendRoute(t,e){let r=Ns(t);r?this.#s.has(r.key)?pe(this.#s.get(r.key).routes,e):this.#s.set(r.key,{routes:new Set(e),token:r.token}):this.#e.has(t)?pe(this.#e.get(t),e):this.#e.set(t,new Set(e))}clearRoute(t){let e=Ns(t);e?this.#s.delete(e.key):this.#e.delete(t)}findTokensByRoute(t,e){let r=new Set([t]),i=this.#e.has(t)?[...this.#e.get(t)]:[];for(;i.length;){let n=i.shift();r.has(n)||(r.add(n),this.#e.has(n)&&i.push(...Array.from(this.#e.get(n)).filter(o=>!r.has(o))))}if(e){for(let o of e)this.#s.has(o)&&pe(r,this.#s.get(o).routes);let n;do{n=r.size;for(let o of new Set(r))for(let h of e){let a=`${o}@${h}`;this.#s.has(a)&&pe(r,this.#s.get(a).routes)}}while(n!==r.size)}return r}findConstructors(t,e){let r=this.findTokensByRoute(t,e),i=new Set;for(let n of r)fr(this.#t.get(n),i);return i.size>0?Array.from(i):void 0}hasToken(t){return this.#t.has(t)}hasRoute(t){return this.#e.has(t)}clear(){this.#t.clear(),this.#e.clear()}},dr=new _t;var q;(function(s){s[s.CreateAndDestroy=0]="CreateAndDestroy",s[s.JustCreate=1]="JustCreate",s[s.DestroyOnly=2]="DestroyOnly"})(q||(q={}));var Ds=s=>s.displayName||s.name,ge=class{#t;#e;#s;#i;#r;#n;constructor(t){this.logger=new A("Kernel"),this.#t=new Map,this.#e=new Set,this.#r=!0,this.#n=new Map,S(this),this.registry=_t.get(t)}getEntity(t){let e=this.#t.get(t)?.entity;if(!e)throw new Error(`entity with uuid "${t}" not found!`);return e}hasEntity(t){return this.#t.has(t)}traverseLevelOrderBFS(t=!1){if(this.#r){let e=new Map,r=(i,n)=>{let o=this.getEntity(i);e.has(n)?e.get(n).push(o):e.set(n,[o]);for(let h of o.children)r(h.uuid,n+1)};this.#e.forEach(i=>r(i,0)),this.#s=Array.from(e.entries()).sort((i,n)=>i[0]-n[0]).map(([,i])=>i).flat(),this.#i=this.#s.slice().reverse(),this.#r=!1}return t?this.#i:this.#s}getEntityGraph(){return Array.from(this.#e).map(t=>this.getEntityGraphNode(t))}getEntityGraphNode(t){if(!this.#t.has(t))return;let{token:e,entity:r}=this.#t.get(t);return{token:e,entity:r,props:Object.fromEntries(r.propEntries()),children:r.children.map(i=>this.getEntityGraphNode(i.uuid))}}upgradeEntities(){let t=new Map;for(let e of this.traverseLevelOrderBFS(!0))t.set(e.uuid,this.updateShadowObjects(e.uuid,q.DestroyOnly));for(let e of this.traverseLevelOrderBFS(!1))this.updateShadowObjects(e.uuid,q.JustCreate,t.get(e.uuid));t.clear()}run(t){this.logger.isDebug&&this.logger.debug("sync",t),O(()=>{for(let e of t.changeTrail)this.parse(e)})}parse(t){switch(t.type){case b.CreateEntities:this.createEntity(t.uuid,t.token,t.parentUuid,t.order,t.properties),this.#r=!0;break;case b.DestroyEntities:this.destroyEntity(t.uuid),this.#r=!0;break;case b.SetParent:this.setParent(t.uuid,t.parentUuid,t.order),this.#r=!0;break;case b.UpdateOrder:this.updateOrder(t.uuid,t.order),this.#r=!0;break;case b.ChangeProperties:this.changeProperties(t.uuid,t.properties);break;case b.ChangeToken:this.changeToken(t.uuid,t.token);break;case b.SendEvents:this.dispatchEventsToEntity(t.uuid,t.events);break}}createEntity(t,e,r,i=0,n){let o=new de(this,t);o.order=i;let h={token:e,entity:o,usedConstructors:new Map};this.#t.set(t,h),r&&(o.parentUuid=r),o.hasParent||this.#e.add(t),n&&o.setProperties(n),this.createShadowObjects(t)}destroyEntity(t){if(!this.#t.has(t))return;let{entity:e,usedConstructors:r}=this.#t.get(t);e.removeFromParent(),d(e,tt,this),r.clear(),this.#t.delete(e.uuid),this.#e.delete(e.uuid)}setParent(t,e,r=0){let i=this.getEntity(t);i.parentUuid===e&&i.order===r||(i.removeFromParent(),i.order=r,i.parentUuid=e,i.hasParent?this.#e.delete(t):this.#e.add(t),i.reSubscribeToParentContexts(),queueMicrotask(()=>{this.logger.isDebug&&this.logger.debug("entity.onParentChanged",{uuid:t,parentUuid:e,order:r,entity:i}),d(i,js,i)}))}updateOrder(t,e){this.getEntity(t).order=e}dispatchEventsToEntity(t,e){this.getEntity(t)?.dispatchViewEvents(e)}changeProperties(t,e){this.getEntity(t).setProperties(e),this.updateShadowObjects(t)}changeToken(t,e){if(!this.#t.has(t))return;let r=this.#t.get(t);r.token!==e&&(r.token=e,this.updateShadowObjects(t))}dispatchMessageToView(t){queueMicrotask(()=>{d(this,yt,t)})}updateShadowObjects(t,e=q.CreateAndDestroy,r){let i=this.#t.get(t);r??=new Set(this.registry.findConstructors(i.token,i.entity.truthyProps()));let n=e===q.CreateAndDestroy||e===q.DestroyOnly,o=e===q.CreateAndDestroy||e===q.JustCreate;if(n){for(let[h,a]of i.usedConstructors)if(!r.has(h)){i.usedConstructors.delete(h);for(let c of a)this.destroyShadowObject(c,i.entity)}}if(o)for(let h of r)i.usedConstructors.has(h)||this.constructShadowObject(h,i);return r}constructShadowObject(t,e){let r=new Set,i=new Set,n=new Map,o=new Map,h=new Map,a=new Map,c=new Map,p=S(new t({entity:e.entity,provideContext(l,u,g){let y=h.get(l);if(y==null){y=f(u,g?{compare:g}:void 0);let P=_(y,e.entity.provideContext(l));i.add(P.destroy.bind(P)),h.set(l,y)}return y},provideGlobalContext(l,u,g){let y=a.get(l);if(y==null){y=f(u,g?{compare:g}:void 0);let P=_(y,e.entity.provideGlobalContext(l));i.add(P.destroy.bind(P)),a.set(l,y)}return y},useContext(l,u){let g=n.get(l);if(g===void 0){g=f(void 0,u?{compare:u}:void 0).get,n.set(l,g);let y=_(e.entity.useContext(l),g);i.add(y.destroy.bind(y))}return g},useParentContext(l,u){let g=o.get(l);if(g===void 0){g=f(void 0,u?{compare:u}:void 0).get,o.set(l,g);let y=_(e.entity.useParentContext(l),g);i.add(y.destroy.bind(y))}return g},useProperty(l,u){let g=c.get(l);if(g===void 0){g=f(void 0,u?{compare:u}:void 0).get,c.set(l,g);let y=_(e.entity.getPropertyReader(l),g);i.add(y.destroy.bind(y))}return g},createEffect(...l){let u=w(...l);return i.add(u.destroy),u},createSignal(...l){let u=f(...l);return i.add(()=>{x(u)}),u},createMemo(...l){let u=Le(...l);return i.add(()=>{x(u)}),u},on(...l){let u=m(...l);return i.add(u),u},once(...l){let u=C(...l);return i.add(u),u},onDestroy(l){r.add(l)}}));return this.logger.isInfo&&this.logger.info("create shadow-object",Ds(t),{shadowObject:p,entity:e.entity}),C(e.entity,tt,z.Low,()=>{this.logger.isInfo&&this.logger.info("destroy shadow-object",Ds(t),{shadowObject:p,entity:e.entity});for(let u of r)u();for(let u of i)u();for(let u of n.values())x(u);for(let u of o.values())x(u);for(let u of c.values())x(u);for(let u of h.values())x(u);for(let u of a.values())x(u);r.clear(),i.clear(),n.clear(),o.clear(),c.clear(),h.clear(),a.clear();let l=e.usedConstructors.get(t);l&&(l.delete(p),l.size===0&&e.usedConstructors.delete(t))}),e.usedConstructors.has(t)?e.usedConstructors.get(t).add(p):e.usedConstructors.set(t,new Set([p])),this.attachShadowObject(p,e.entity),p}createShadowObjects(t){let e=this.#t.get(t);this.registry.findConstructors(e.token,e.entity.truthyProps())?.forEach(r=>{this.constructShadowObject(r,e)})}findShadowObjects(t){if(!this.#t.has(t))return[];let{usedConstructors:e}=this.#t.get(t);return Array.from(new Set(Array.from(e.values()).map(r=>Array.from(r)).flat()))}attachShadowObject(t,e){m(e,t),typeof t[ze]=="function"&&t[ze](e)}destroyShadowObject(t,e){typeof t[tt]=="function"&&t[tt](e),d(t,tt,e),E(e,t)}findOrCreateRootContext(t){let e=this.#n.get(t);return e||(e=new jt,this.#n.set(t,e)),e}destroy(){for(let t of this.#n.values())t.dispose();this.#n.clear();for(let t of this.traverseLevelOrderBFS().reverse())this.destroyEntity(t.uuid)}};async function Ge(s,t,e,r=!0){if(e.has(t)){console.warn("importModule: skipping already imported module",t);return}else e.add(t);t.extends&&await Promise.all(t.extends.map(n=>Ge(s,n,e,!1)));let{registry:i}=s;if(t.define)for(let[n,o]of Object.entries(t.define))i.define(n,o);if(t.routes)for(let[n,o]of Object.entries(t.routes))i.appendRoute(n,o);await(t.initialize?.({define:(n,o)=>i.define(n,o),kernel:s,registry:i})??Promise.resolve()),r&&s.upgradeEntities()}var ye=s=>(typeof s=="string"&&(s=new URL(s,globalThis.location.href)),s.toString());function $s(s){return s.map(t=>{if(t.transferables&&t.transferables.length>0){let{transferables:e,...r}=t;return structuredClone(r,{transfer:e})}else return structuredClone(t)})}var me=class{#t;get registry(){return this.kernel.registry}constructor(t){this.#t=new Set,this.isLocalEnv=!0,this.disableStructuredClone=!1,this.kernel=new ge(t),m(this.kernel,yt,e=>{if(this.onMessageToView!=null){let{type:r,uuid:i,traverseChildren:n}=e,o=structuredClone(e.data,{transfer:e.transferables});this.onMessageToView({type:r,uuid:i,data:o,traverseChildren:n})}})}start(){return Promise.resolve()}applyChangeTrail(t,e){let r={changeTrail:this.disableStructuredClone?t:$s(t)},i;try{this.kernel.run(r),i=Promise.resolve()}catch(n){i=Promise.reject(n)}return i}async importScript(t){let e=await import(ye(t));e[je]&&await this.importModule(e[je])}async importModule(t){return Ge(this.kernel,t,this.#t)}destroy(){this.kernel.destroy(),this.registry.clear(),this.#t.clear()}};function Be(s){let t=new Blob([s],{type:"text/javascript"}),e=URL.createObjectURL(t),r=new Worker(e);return URL.revokeObjectURL(e),r}function qe(){return Be('var Fs=Object.defineProperty;var se=Object.getOwnPropertySymbols;var Ve=Object.prototype.hasOwnProperty,$e=Object.prototype.propertyIsEnumerable;var Vs=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),Ie=e=>{throw TypeError(e)};var ge=(e,t,s)=>t in e?Fs(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,ye=(e,t)=>{for(var s in t||(t={}))Ve.call(t,s)&&ge(e,s,t[s]);if(se)for(var s of se(t))$e.call(t,s)&&ge(e,s,t[s]);return e};var Ge=(e,t)=>{var s={};for(var i in e)Ve.call(e,i)&&t.indexOf(i)<0&&(s[i]=e[i]);if(e!=null&&se)for(var i of se(e))t.indexOf(i)<0&&$e.call(e,i)&&(s[i]=e[i]);return s};var u=(e,t,s)=>ge(e,typeof t!="symbol"?t+"":t,s),pe=(e,t,s)=>t.has(e)||Ie("Cannot "+s);var r=(e,t,s)=>(pe(e,t,"read from private field"),s?s.call(e):t.get(e)),c=(e,t,s)=>t.has(e)?Ie("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,s),f=(e,t,s,i)=>(pe(e,t,"write to private field"),i?i.call(e,s):t.set(e,s),s),m=(e,t,s)=>(pe(e,t,"access private method"),s);var Ue=(e,t,s,i)=>({set _(a){f(e,t,a,s)},get _(){return r(e,t,i)}});var ve=function(e,t){this[0]=e,this[1]=t},Be=(e,t,s)=>{var i=(n,l,y,b)=>{try{var d=s[n](l),h=(l=d.value)instanceof ve,g=d.done;Promise.resolve(h?l[0]:l).then(p=>h?i(n==="return"?n:"next",l[1]?{done:p.done,value:p.value}:p,y,b):y({value:p,done:g})).catch(p=>i("throw",p,y,b))}catch(p){b(p)}},a=n=>o[n]=l=>new Promise((y,b)=>i(n,l,y,b)),o={};return s=s.apply(e,t),o[Vs("asyncIterator")]=()=>o,a("next"),a("throw"),a("return"),o};var We;(function(e){e[e.StructuralChanges=1]="StructuralChanges",e[e.ContentUpdates=2]="ContentUpdates",e[e.Removal=3]="Removal"})(We||(We={}));var X;(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"})(X||(X={}));var Ui=Symbol.for("ShadowEntsGlobalNS"),$s="configure",Is="changeTrail",Gs="destroy",Us="loaded",qe="appliedChangeTrail",be="importedModule",Bs="destroyed",Ae="messageToView",me="shadowObjects",N="ConsoleLogger",D=`${N}Storage`,ns,os,hs,Ws=!!((hs=(os=(ns=globalThis.location)==null?void 0:ns.host)==null?void 0:os.startsWith("localhost"))!=null&&hs),Jt="localStorage"in globalThis,ie=Symbol.for(N),Je=!1,Ke=e=>{if(typeof e=="boolean")return e;switch(e.toLowerCase()){case"true":case"yes":case"on":return!0;default:return!1}},Oe=e=>[Jt?N:void 0,...Array.isArray(e)?e:[e]].filter(Boolean).join(".");function we(e,t=void 0,s){var o;let i=Oe(e),a=Jt?localStorage.getItem(i):(o=globalThis[D])==null?void 0:o[i];return a!=null?t(a):s}function Vt(e,t){Jt?localStorage.setItem(Oe(e),t):(globalThis[D]==null&&(globalThis[D]={},console.debug(`${N}: Initialize`,{[D]:globalThis[D]})),globalThis[D][Oe(e)]=t)}var vt,It,v,qs=(v=class{constructor(t){c(this,vt);this.enable=!0,this.namespace=(t||"").trim()||N,Je||(v.loadConfig(),Je=!0);let s=[this.namespace,"enable"];this.enable=we(s,Ke,this.enable),Vt(s,Jt?this.enable?"true":"false":this.enable)}static get isEnabled(){return v.sharedConfig.enable}static get isDebug(){return v.sharedConfig.enable&&v.sharedConfig.debug}static loadConfig(){var t,s,i;Jt?(["enable","debug","info","warn"].forEach(a=>{this.sharedConfig[a]=we(a,Ke,this.sharedConfig[a])}),["debug","info","warn","error"].forEach(a=>{this.sharedStyles[a]=we(["styles",a],void 0,this.sharedStyles[a])}),v.isDebug&&console.debug(`${N}: Load config from localStorage`,v.sharedConfig),(t=globalThis[N])!=null&&t[ie]||((s=globalThis[N])!=null||(globalThis[N]={[ie]:!0,get enable(){return v.sharedConfig.enable},set enable(a){v.sharedConfig.enable=a,Vt("enable",a?"true":"false")},get debug(){return v.sharedConfig.debug},set debug(a){v.sharedConfig.debug=a,Vt("debug",a?"true":"false")},get info(){return v.sharedConfig.info},set info(a){v.sharedConfig.info=a,Vt("info",a?"true":"false")},get warn(){return v.sharedConfig.warn},set warn(a){v.sharedConfig.warn=a,Vt("warn",a?"true":"false")}}))):(i=globalThis[D])!=null&&i[ie]||(globalThis[D]=ye(ye({[ie]:!0},v.sharedConfig),globalThis[D]),v.sharedConfig=globalThis[D],v.isDebug&&console.debug(`${N}: Load config from ${D}`,globalThis[D]))}get isEnabled(){return this.enable&&v.sharedConfig.enable}get isDebug(){return this.isEnabled&&v.sharedConfig.debug}get isInfo(){return this.isEnabled&&v.sharedConfig.info}get isWarn(){return this.isEnabled&&v.sharedConfig.warn}debug(...t){m(this,vt,It).call(this,"debug",v.sharedStyles.debug,t)}info(...t){m(this,vt,It).call(this,"info",v.sharedStyles.info,t)}warn(...t){m(this,vt,It).call(this,"warn",v.sharedStyles.warn,t)}error(...t){m(this,vt,It).call(this,"error",v.sharedStyles.error,t)}},vt=new WeakSet,It=function(t,s,i){console[t](`%c${this.namespace}`,s,...i)},v.sharedConfig={enable:Ws,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"},v.sharedStyles={get debug(){return v.sharedConfig["styles.debug"]},set debug(t){v.sharedConfig["styles.debug"]=t},get info(){return v.sharedConfig["styles.info"]},set info(t){v.sharedConfig["styles.info"]=t},get warn(){return v.sharedConfig["styles.warn"]},set warn(t){v.sharedConfig["styles.warn"]=t},get error(){return v.sharedConfig["styles.error"]},set error(t){v.sharedConfig["styles.error"]=t}},v),kt="*",vs=1,xe=2,Re=4,ft=Symbol.for("eventize"),Js="[eventize]",le=e=>e===kt,bs=e=>{switch(typeof e){case"string":case"symbol":return!0;default:return!1}},ms=typeof console<"u",Ks=ms?console[console.warn?"warn":"log"].bind(console,Js):()=>{},Ys=(e,t,s)=>(Object.defineProperty(e,t,{value:s,configurable:!0}),e),Hs=0,ws=class{constructor(){u(this,"events",new Map);u(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:Hs++})}isKnown(e){return this.eventNames.has(e)}emit(e,t,s=[]){if(le(e))this.eventNames.forEach(i=>this.emit(i,t,s));else if(this.events.has(e)){let{order:i,args:a}=this.events.get(e);s.push({order:i,emit:()=>t.apply(e,a)})}return s}},Pe=(e,t,s,i)=>{if(typeof t=="function"){let a=t.apply(e,s);a!=null&&(i==null||i(a))}},Qs=(e,t,s,i)=>Pe(t,t.emit,[e].concat(s),i),Xs=e=>{switch(typeof e){case"function":return vs;case"string":case"symbol":return xe;case"object":return Re}},Zs=0,_s=()=>++Zs,Cs=class{constructor(e,t,s,i=null){u(this,"id");u(this,"eventName");u(this,"isCatchEmAll");u(this,"priority");u(this,"listener");u(this,"listenerObject");u(this,"listenerType");u(this,"callAfterApply");u(this,"isRemoved");u(this,"refCount");this.id=_s(),this.eventName=e,this.isCatchEmAll=le(e),this.listener=s,this.listenerObject=i,this.priority=t,this.listenerType=Xs(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===kt||e===this.eventName:this.listener===e&&this.listenerObject===t}apply(e,t,s){if(this.isRemoved)return;let{listener:i,listenerObject:a}=this;switch(this.listenerType){case vs:Pe(a,i,t,s),this.callAfterApply&&this.callAfterApply();break;case xe:Pe(a,a[i],t,s),this.callAfterApply&&this.callAfterApply();break;case Re:{let o=i[e];if(this.isCatchEmAll||this.eventName===e){if(typeof o=="function"){let n=o.apply(i,t);n!=null&&(s==null||s(n))}else Qs(e,i,t,s);this.callAfterApply&&this.callAfterApply()}break}}}},ti=(e,t)=>e.priority!==t.priority?t.priority-e.priority:e.id-t.id,Ye=e=>e==null?void 0:e.slice(0),He=(e,t)=>{let s=e.indexOf(t);s>-1&&e.splice(s,1)},ei=e=>e===Re||e===xe,Me=(e,t,s)=>{let i=e.findIndex(a=>a.isEqual(t,s));i>-1&&(e[i].isRemoved=!0,e.splice(i,1))},re=(e,t,s)=>{let i=[];for(let a of e)(t==null&&a.listenerObject===s||a.eventName===t&&a.listener===s)&&i.push(a);for(let a of i)Me(e,a,void 0)},Ce=e=>{e&&(e.forEach(t=>{t.isRemoved=!0}),e.length=0)},si=(e,t)=>e.listenerType===t.listenerType?e.priority===t.priority&&e.eventName===t.eventName&&e.listenerObject===t.listenerObject&&e.listener===t.listener:!1,ii=(e,t)=>{if(ei(e.listenerType))return t.find(s=>si(e,s))},ri=(e,t)=>{let s=ii(e,t);return s?(s.refCount+=1,s):(t.push(e),t.sort(ti),e)},ai=class{constructor(){u(this,"namedListeners");u(this,"catchEmAllListeners");u(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 ri(e,e.isCatchEmAll?this.catchEmAllListeners:this.getListenersForEventName(e.eventName))}remove(e,t,s=!1){t==null&&Array.isArray(e)?e.forEach(i=>this.remove(i,null,s)):e==null||t==null&&le(e)?this.removeAllListeners():t==null&&bs(e)?Ce(this.namedListeners.get(e)):e instanceof Cs?e.isRemoved||(e.refCount-=1,e.refCount<1&&(e.isRemoved=!0,this.namedListeners.forEach(i=>He(i,e)),He(this.catchEmAllListeners,e))):s?le(e)&&typeof e=="object"?re(this.catchEmAllListeners,kt,e):this.namedListeners.forEach(i=>re(i,e,t)):(this.namedListeners.forEach(i=>{Me(i,e,t),typeof e=="object"&&re(i,void 0,e)}),Me(this.catchEmAllListeners,e,t),typeof e=="object"&&re(this.catchEmAllListeners,void 0,e))}removeAllListeners(){this.namedListeners.forEach(e=>Ce(e)),this.namedListeners.clear(),Ce(this.catchEmAllListeners)}forEach(e,t){let s=Ye(this.catchEmAllListeners),i=Ye(this.namedListeners.get(e));if(e===kt||!i||i.length===0)s.forEach(t);else if(s.length===0)i.forEach(t);else{let a=i.length,o=s.length,n=0,l=0;for(;n<a||l<o;){if(n<a){let y=i[n];if(l>=o||y.priority>=s[l].priority){t(y),++n;continue}}l<o&&(t(s[l]),++l)}}}getSubscriptionCount(){let e=this.catchEmAllListeners.length;for(let t of this.namedListeners.values())e+=t.length;return e}},zt=e=>!!(e&&e[ft]);function Kt(e){if(zt(e))return e;let t=new ai,s=new ws;return Ys(e,ft,{keeper:s,store:t}),e}var fe={Max:Number.POSITIVE_INFINITY,AAA:1e9,BB:1e6,C:1e3,Default:0,Low:-1e4,Min:Number.NEGATIVE_INFINITY},ni=(e,t,s,i,a,o,n)=>{let l=e.add(new Cs(s,i,a,o));return t.emit(s,l,n),l},oi=(e,t,s,i)=>{let a=s.length,o=typeof s[0],n,l,y,b;if(a>=2&&a<=3&&o==="number"?(n=kt,[l,y,b]=s):a>=3&&a<=4&&typeof s[1]=="number"?[n,l,y,b]=s:(l=fe.Default,o==="string"||o==="symbol"||Array.isArray(s[0])?[n,y,b]=s:(n=kt,[y,b]=s)),!y&&ms)throw Ks("called with insufficient arguments!",s),"subscribeTo() called with insufficient arguments!";let d=h=>g=>ni(e,t,g,h,y,b,i);return Array.isArray(n)?n.map(h=>Array.isArray(h)?d(h[1])(h[0]):d(l)(h)):d(l)(n)},Es=(e,t,s)=>{let i=[],a=oi(e,t,s,i);return ws.publish(i),a},Qe=e=>t=>{t.callAfterApply=()=>{e==null||e()}},Ss=(e,t)=>Object.assign(()=>z(e,t),Array.isArray(t)?{listeners:t}:{listener:t}),ks=(e,t,s,i)=>{let{store:a,keeper:o}=e[ft];Array.isArray(t)?t.forEach(n=>{a.forEach(n,l=>l.apply(n,s,i)),o.retain(n,s)}):t!==kt&&(a.forEach(t,n=>{n.apply(t,s,i)}),o.retain(t,s))},Q=(e,...t)=>{let s=Kt(e),{store:i,keeper:a}=s[ft];return Ss(s,Es(i,a,t))},O=(e,...t)=>{let s=Kt(e),{store:i,keeper:a}=s[ft],o=Es(i,a,t),n=Ss(s,o),l=!1,y=()=>{l||(n(),l=!0)};return Array.isArray(o)?o.forEach(Qe(y)):Qe(y)(o),y},hi=(e,t)=>new Promise(s=>{O(e,t,s)}),z=(e,t,s)=>{if(!zt(e))throw new Error("object is not eventized");let{store:i,keeper:a}=e[ft],o=typeof t,n=s!=null&&(o==="string"||o==="symbol");i.remove(t,s,n),Array.isArray(t)?a.remove(t.filter(l=>typeof l=="string")):bs(t)&&a.remove(t)},w=(e,t,...s)=>{if(!zt(e))throw new Error("object is not eventized");ks(e,t,s)},li=(e,t,...s)=>{if(!zt(e))throw new Error("object is not eventized");let i=[];return ks(e,t,s,a=>{i.push(a)}),i=i.map(a=>Array.isArray(a)?Promise.all(a):Promise.resolve(a)),i.length>0?Promise.all(i):Promise.resolve()},Ne=(e,t)=>{let s=Kt(e),{keeper:i}=s[ft];i.add(t)},de=(e,t)=>{if(!zt(e))throw new Error("object is not eventized");let{keeper:s}=e[ft];s.clear(t)},it=(()=>{let e=(t={})=>Kt(t);return e.inject=(t={})=>(t=Kt(t),Object.assign(t,{on:(...s)=>Q(t,...s),once:(...s)=>O(t,...s),onceAsync:s=>hi(t,s),off:(s,i)=>z(t,s,i),emit:(s,...i)=>w(t,s,...i),emitAsync:(s,...i)=>li(t,s,...i),retain:s=>Ne(t,s),retainClear:s=>de(t,s)}),t),e.is=zt,e})(),H=Symbol.for("signal"),Ot=Symbol.for("effect"),Xe=Symbol.for("destroySignal"),Ze=Symbol.for("createEffect"),di=Symbol.for("destroyEffect"),$t="value",_e="mute",ts="unmute",Wt="destroy",qt=Symbol.for("recall"),ue=it(),Nt=it(),yt=it(),As=it(),ke,Gt=(ke=class{constructor(){u(this,"delayedEffects",[])}batch(e,t){let s=this.delayedEffects.length;for(let i=0;i<s;i++){let[a,o]=this.delayedEffects[i];if(!(a>t))if(a===t){o.add(e);return}else{this.delayedEffects.splice(i,0,[t,new Set([e])]);return}}this.delayedEffects.push([t,new Set([e])])}run(){let e=new Set,t=[Q(yt,(i,a)=>{a===qt&&e.add(i)}),Q(As,i=>{e.add(i)})],s=this.delayedEffects.flatMap(([,i])=>Array.from(i));for(let i of s)e.has(i)||w(yt,i,i,qt);t.forEach(i=>{i()})}},u(ke,"current"),ke),ui=()=>Gt.current;function ce(e){let t=Gt.current;t?t=void 0:t=Gt.current=new Gt;try{e()}finally{t&&(Gt.current=void 0,t.run())}}var ci=0;function Os(){return ci>0}var ls,fi=(ls=Ot,class{constructor(e){u(this,ls);u(this,"run",()=>{var e;return(e=this[Ot])==null?void 0:e.run()});u(this,"destroy",()=>{var e;(e=this[Ot])==null||e.destroy(),this[Ot]=void 0});this[Ot]=e,O(e,js.Destroy,()=>{this[Ot]=void 0})}}),rt=new Map,B,bt,F,_,W,mt,wt,V,st,te=(st=class{constructor(t){c(this,B,new Set);c(this,bt,new Set);c(this,F,new Map);c(this,_,new WeakMap);c(this,W,new Map);c(this,mt,new Set);c(this,wt,new Set);c(this,V);if(t!=null&&t instanceof st)return t;if(t!=null||(t=this),rt.has(t))return rt.get(t);rt.set(t,this),it(this)}static get(t){if(t!=null)return t instanceof st?t:rt.get(t)}static findOrCreate(t){if(t==null)throw new Error("Cannot create a group with a null object");return new st(t)}static destroy(t){console.warn("SignalGroup.destroy(obj) is deprecated. Use SignalGroup.delete(obj) instead."),st.delete(t)}static delete(t){var s;(s=rt.get(t))==null||s.clear()}static clear(){for(let t of rt.values())t.destroy();rt.clear()}attachGroup(t){if(t===this)throw new Error("Cannot attach a group to itself");return r(this,B).add(t),r(t,V)&&r(t,V)!==this&&r(r(t,V),B).delete(t),f(t,V,this),t}detachGroup(t){return t!==this&&r(this,B).has(t)&&(r(this,B).delete(t),f(t,V,void 0)),t}attachSignal(t){let s=E(t);if(s!=null&&s.destroyed)throw new Error("Cannot attach a destroyed signal to a group");return s&&r(this,bt).add(s),t}attachSignalByName(t,s){if(s){this.attachSignal(s);let i=E(s);r(this,F).set(t,i),r(this,W).has(t)?r(this,W).get(t).push(i):r(this,W).set(t,[i]),r(this,_).has(i)?r(this,_).get(i).add(t):r(this,_).set(i,new Set([t]))}else r(this,F).delete(t);return s}hasSignal(t){var s;return r(this,F).has(t)||((s=r(this,V))==null?void 0:s.hasSignal(t))}signal(t){var s,i,a;return(a=(s=r(this,F).get(t))==null?void 0:s.object)!=null?a:(i=r(this,V))==null?void 0:i.signal(t)}detachSignal(t){let s=E(t);if(s&&(r(this,bt).delete(s),r(this,_).has(s))){let i=r(this,_).get(s);for(let a of i)if(r(this,W).has(a)){let o=r(this,W).get(a);o.splice(o.indexOf(s),1),o.length===0?(r(this,F).delete(a),r(this,W).delete(a)):r(this,F).get(a)===s&&r(this,F).set(a,o.at(-1))}i.clear(),r(this,_).delete(s)}return t}attachEffect(t){return r(this,mt).add(t),t}runEffects(){for(let t of r(this,mt))t.run();for(let t of r(this,B))t.runEffects()}attachLink(t){if(t!=null&&t.isDestroyed)throw new Error("Cannot attach a destroyed link to a group");return t&&r(this,wt).add(t),t}detachLink(t){return t&&r(this,wt).delete(t),t}destroy(){console.warn("SignalGroup#destroy is deprecated. Use SignalGroup#clear instead."),this.clear()}clear(){var t;w(this,Wt,this),z(this);for(let s of r(this,B))s.destroy();for(let s of r(this,mt))s.destroy();for(let s of r(this,bt))U(s);for(let s of r(this,wt))s.destroy();r(this,B).clear(),r(this,bt).clear(),r(this,F).clear(),r(this,W).clear(),r(this,mt).clear(),r(this,wt).clear(),(t=r(this,V))==null||t.detachGroup(this),rt.delete(this)}},B=new WeakMap,bt=new WeakMap,F=new WeakMap,_=new WeakMap,W=new WeakMap,mt=new WeakMap,wt=new WeakMap,V=new WeakMap,st),Qt,Xt,ds,Ps=(ds=class{constructor(e="id",t=1){c(this,Qt);c(this,Xt);f(this,Qt,e),f(this,Xt,t)}make(){return Symbol(`${r(this,Qt)}${Ue(this,Xt)._++}`)}},Qt=new WeakMap,Xt=new WeakMap,ds),je=[],Ms=()=>je.at(-1),gi=(e,t)=>{je.push(e);try{return t()}finally{je.pop()}},yi=e=>e!=null&&typeof e.then=="function",A,at,q,Ct,nt,ot,Et,jt,js=(A=class{constructor(t,s){u(this,"id");u(this,"callback");c(this,at);c(this,q,new Set);c(this,Ct,new Set);c(this,nt,new Map);c(this,ot,new Set);u(this,"parentEffect");u(this,"childEffects",[]);u(this,"curChildEffectSlot",0);u(this,"autorun",!0);u(this,"shouldRun",!0);u(this,"priority");c(this,Et);c(this,jt,!1);u(this,"run",()=>{if(r(this,jt)||!this.shouldRun)return;let t=ui();t?t.batch(this.id,this.priority):(this.runCleanupCallback(),this.curChildEffectSlot=0,this.shouldRun=!1,w(As,this.id,this.id),this.hasStaticDeps()?f(this,at,this.callback()):(f(this,Ct,new Set(r(this,q))),f(this,at,gi(this,this.callback)),this.cleanupLostSignals(),r(this,ot).clear()))});u(this,"destroy",()=>{r(this,jt)||(w(this,A.Destroy,this),z(this),w(yt,di,this),this.runCleanupCallback(),z(ue,this),z(yt,this),z(Nt,this),f(this,jt,!0),r(this,q).clear(),r(this,Ct).clear(),r(this,nt).clear(),r(this,ot).clear(),this.childEffects.forEach(t=>{t.destroy()}),this.childEffects.length=0,--A.count)});var a,o;it(this),this.callback=t;let i;(s==null?void 0:s.attach)!=null&&(i=te.findOrCreate(s.attach),i.attachEffect(this)),this.autorun=(a=s==null?void 0:s.autorun)!=null?a:!0,f(this,Et,s!=null&&s.dependencies?s.dependencies.map(n=>{switch(typeof n){case"string":case"symbol":return i.signal(n);default:return n}}):void 0),this.id=A.idGen.make(),this.priority=(o=s==null?void 0:s.priority)!=null?o:0,Q(yt,this.id,qt,this),++A.count}hasStaticDeps(){return r(this,Et)!=null&&r(this,Et).length>0}saveSignalsFromDeps(){for(let t of r(this,Et))this.whenSignalIsRead(E(t).id)}static createEffect(t,s,i){let a=Array.isArray(s)?s:void 0,o=a?i!=null?i:{dependencies:a}:s;o&&a&&(o.dependencies=a);let n,l=Ms();return l!=null?(n=l.getCurrentChildEffect(),n==null&&(n=new A(t,o),l.attachChildEffect(n),w(yt,Ze,n)),l.curChildEffectSlot++):(n=new A(t,o),w(yt,Ze,n)),n.hasStaticDeps()?n.saveSignalsFromDeps():n.autorun&&n.run(),new fi(n)}getCurrentChildEffect(){return this.childEffects[this.curChildEffectSlot]}attachChildEffect(t){this.childEffects.push(t),this.parentEffect=this}[qt](){this.shouldRun=!0,this.autorun&&this.run()}whenSignalIsRead(t){r(this,Ct).delete(t),r(this,q).has(t)||(r(this,q).add(t),r(this,nt).set(t,[Q(ue,t,this.priority,qt,this),O(Nt,t,Xe,this)]))}[Xe](t){!r(this,ot).has(t)&&r(this,q).has(t)&&(r(this,ot).add(t),this.unsubscribeSignal(t),r(this,ot).size===r(this,q).size&&this.destroy())}cleanupLostSignals(){for(let t of r(this,Ct))this.unsubscribeSignal(t),r(this,q).delete(t)}unsubscribeSignal(t){r(this,nt).has(t)&&(r(this,nt).get(t).forEach(s=>{s()}),r(this,nt).delete(t))}runCleanupCallback(){if(r(this,at)!=null){let t=r(this,at);f(this,at,void 0),yi(t)?Promise.resolve(t).then(s=>{typeof s=="function"&&s()}):t()}}},at=new WeakMap,q=new WeakMap,Ct=new WeakMap,nt=new WeakMap,ot=new WeakMap,Et=new WeakMap,jt=new WeakMap,u(A,"idGen",new Ps("ef")),u(A,"Destroy","destroy"),u(A,"count",0),A),ee=(...e)=>js.createEffect(...e),Yt=new WeakMap,pi=e=>{let t=Yt.get(e);return t||(t={},Yt.set(e,t)),t},Ht=(e,t)=>{var s,i;return(i=(s=Yt.get(e))==null?void 0:s.signals)==null?void 0:i.get(t)},vi=(e,t,s)=>{var a;let i=pi(e);(a=i.signals)!=null||(i.signals=new Map),i.signals.set(t,s)};function bi(...e){for(let t of e)if(Yt.has(t)){let s=Yt.get(t);if(s.signals){for(let i of s.signals.values())U(i);s.signals.clear(),s.signals=void 0}}}function mi(e){let t=E(Fe(e)?e:Ht(...e));t!=null&&!t.muted&&!t.destroyed&&Te(t.id,t.value,{touch:!0})}function ze(e){var t,s;return Fe(e)?(t=E(e))==null?void 0:t.value:(s=E(Ht(...e)))==null?void 0:s.value}var us,wi=(us=H,class{constructor(e){u(this,us);this[H]=e}get get(){return this[H].reader}get set(){return this[H].writer}get value(){return ze(this.get)}set value(e){this.set(e)}onChange(e){let{destroy:t}=ee(()=>e(this.value),[this.get]);return t}get muted(){return this[H].muted}set muted(e){this[H].muted=e}touch(){mi(this)}destroy(){U(this)}}),Ci=new Ps("si");function es(e){var t;Os()||((t=Ms())==null||t.whenSignalIsRead(e))}function Te(e,t,s){Os()||w(ue,e,t,s)}var Fe=e=>e!=null&&e[H]!=null,Ei=e=>{let t=s=>{var i;return s?ee(()=>(e.destroyed||es(e.id),s(e.value)),[t]):e.destroyed||((i=e.beforeRead)==null||i.call(e),es(e.id)),e.value};return Object.defineProperty(t,H,{value:e}),t},St,$,Ts=(St=class{constructor(t,s){u(this,"id");u(this,"lazy");u(this,"compare");u(this,"beforeRead");u(this,"muted",!1);u(this,"destroyed",!1);c(this,$);u(this,"valueFn");u(this,"reader");u(this,"writer",(t,s)=>{var o,n,l,y;let i=(o=s==null?void 0:s.lazy)!=null?o:!1,a=(l=(n=s==null?void 0:s.compare)!=null?n:this.compare)!=null?l:((b,d)=>b===d);if((i!==this.lazy||i&&t!==this.valueFn||!i&&!a(t,r(this,$)))&&(i?(f(this,$,void 0),this.valueFn=t,this.lazy=!0):(f(this,$,t),this.valueFn=void 0,this.lazy=!1),!this.muted&&!this.destroyed)){Te(this.id,r(this,$));return}(y=s==null?void 0:s.touch)!=null&&y&&Te(this.id,r(this,$),{touch:!0})});u(this,"object");this.id=Ci.make(),++St.instanceCount,this.lazy=t,this.lazy?(this.value=void 0,this.valueFn=s):(this.value=s,this.valueFn=void 0),this.reader=Ei(this),this.object=new wi(this)}get[H](){return this}get value(){return this.lazy&&(f(this,$,this.valueFn()),this.valueFn=void 0,this.lazy=!1),r(this,$)}set value(t){f(this,$,t)}},$=new WeakMap,u(St,"instanceCount",0),St),E=e=>e==null?void 0:e[H];function k(e=void 0,t){var i;let s;if(Fe(e))s=E(e);else{let a=(i=t==null?void 0:t.lazy)!=null?i:!1;s=new Ts(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&&te.findOrCreate(t.attach).attachSignal(s),s.object}var U=(...e)=>{for(let t of e){let s=E(t);s!=null&&!s.destroyed&&(s.destroyed=!0,s.beforeRead=void 0,--Ts.instanceCount,w(Nt,s.id,s.id))}};function Si(e,t){var n,l;let s=k(),i=(t==null?void 0:t.attach)!=null?te.findOrCreate(t.attach):void 0;i!=null&&(t!=null&&t.name?i.attachSignalByName(t.name,s):i.attachSignal(s));let a=ee(()=>s.set(e()),{autorun:!((n=t==null?void 0:t.lazy)!=null&&n),priority:(l=t==null?void 0:t.priority)!=null?l:fe.C,attach:i}),o=E(s);return o.beforeRead=a.run,O(Nt,o.id,a.destroy),s.get}var S,Tt,cs,Ls=(cs=class{constructor(e){c(this,S,!1);c(this,Tt);u(this,"source");u(this,"lastValue");u(this,"isDestroyed",!1);it(this),this.source=E(e),f(this,Tt,Q(ue,this.source.id,(t,s)=>{!r(this,S)&&!this.isDestroyed&&((s==null?void 0:s.touch)===!0?this.touch():this.write())})),O(Nt,this.source.id,()=>this.destroy())}attach(e){let t=te.findOrCreate(e);return t.attachLink(this),O(this,Wt,()=>{t.detachLink(this)}),t}nextValue(){return new Promise((e,t)=>{let s=[],i=()=>s.forEach(a=>{a()});s.push(O(this,$t,a=>{i(),e(a)}),O(this,Wt,()=>{i(),t()}))})}asyncValues(e){return Be(this,null,function*(){let t=0;for(;!this.isDestroyed;)try{let s=yield new ve(this.nextValue());if(e&&e(s,t++))break;Ne(this,$t),yield s}catch(s){break}de(this,$t)})}destroy(){var e;this.isDestroyed||((e=r(this,Tt))==null||e.call(this),f(this,Tt,void 0),w(this,Wt,this),de(this,$t),z(this),this.lastValue=void 0,this.isDestroyed=!0,Object.freeze(this))}get isMuted(){return r(this,S)}mute(){return!this.isDestroyed&&!r(this,S)&&(f(this,S,!0),w(this,_e,this)),this}unmute(){return!this.isDestroyed&&r(this,S)&&(f(this,S,!1),w(this,ts,this)),this}toggle(){return this.isDestroyed||(f(this,S,!r(this,S)),w(this,r(this,S)?_e:ts,this)),r(this,S)}updateValue(e){if(!r(this,S)&&!this.isDestroyed){let{value:t}=this.source;e(t),w(this,$t,t),this.lastValue=t}}},S=new WeakMap,Tt=new WeakMap,cs),ki=class extends Ls{constructor(t,s){super(t);u(this,"target");this.target=E(s),O(Nt,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)})}},Ai=class extends Ls{constructor(t,s){super(t);u(this,"target");this.target=s,this.touch()}touch(){return this.updateValue(t=>{this.target(t)}),this}write(){this.updateValue(t=>{this.target(t)})}},ae=new Map;function pt(e,t,s){var b;let i=E(e),a;if(ae.has(i)){a=ae.get(i);let d=(b=E(t))!=null?b:t;if(a.has(d))return a.get(d)}else a=new Map,ae.set(i,a);let o=E(t),n=o!=null?new ki(e,o):new Ai(e,t),l=s==null?void 0:s.attach;l&&n.attach(l);let y=o!=null?o:t;return a.set(y,n),O(n,Wt,()=>{a.delete(y),a.size===0&&ae.delete(i)}),n}var j,Lt,Oi=(Lt=class{constructor(){c(this,j,new Map)}static fromProps(t,s){let i=new Lt,a=s?s.map(o=>[o,t[o]]):Object.entries(t);for(let[o,n]of a)r(i,j).set(o,k(n));return i}keys(){return r(this,j).keys()}signals(){return r(this,j).values()}entries(){return r(this,j).entries()}clear(){for(let t of r(this,j).values())t.destroy();r(this,j).clear()}has(t){return r(this,j).has(t)}get(t){if(!r(this,j).has(t)){let s=k();return r(this,j).set(t,s),s}return r(this,j).get(t)}update(t){t.size&&ce(()=>{for(let[s,i]of t.entries())this.get(s).set(i)})}updateFromProps(t,s){ce(()=>{let i=s?s.map(a=>[a,t[a]]):Object.entries(t);for(let[a,o]of i)this.get(a).set(o)})}},j=new WeakMap,Lt);function Pi(e,t,s,i,a,o){function n(Ft){if(Ft!==void 0&&typeof Ft!="function")throw new TypeError("Function expected");return Ft}for(var l=i.kind,y=l==="getter"?"get":l==="setter"?"set":"value",b=!t&&e?i.static?e:e.prototype:null,d=t||(b?Object.getOwnPropertyDescriptor(b,i.name):{}),h,g=!1,p=s.length-1;p>=0;p--){var M={};for(var At in i)M[At]=At==="access"?{}:i[At];for(var At in i.access)M.access[At]=i.access[At];M.addInitializer=function(Ft){if(g)throw new TypeError("Cannot add initializers after decoration has completed");o.push(n(Ft||null))};var gt=(0,s[p])(l==="accessor"?{get:d.get,set:d.set}:d[y],M);if(l==="accessor"){if(gt===void 0)continue;if(gt===null||typeof gt!="object")throw new TypeError("Object expected");(h=n(gt.get))&&(d.get=h),(h=n(gt.set))&&(d.set=h),(h=n(gt.init))&&a.unshift(h)}else(h=n(gt))&&(l==="field"?a.unshift(h):d[y]=h)}b&&Object.defineProperty(b,i.name,d),g=!0}function ss(e,t,s){for(var i=arguments.length>2,a=0;a<t.length;a++)s=i?t[a].call(e,s):t[a].call(e);return i?s:void 0}function Mi(e){return function(t,s){var o;let i=(e==null?void 0:e.name)||s.name,a=!!((o=e==null?void 0:e.readAsValue)!=null&&o);return{get(){let n=Ht(this,i);if(n)return a?n.value:n.get()},set(n){var l;(l=Ht(this,i))==null||l.set(n)},init(n){let l=k(n,e);return vi(this,i,l),te.findOrCreate(this).attachSignalByName(i,l),l.value}}}}var Pt="value",Le=(()=>{var i,a,o,n,oe,Ut,b;let e,t=[],s=[];return b=class{constructor(h){c(this,n);c(this,i);c(this,a);c(this,o);f(this,i,[]),f(this,o,ss(this,t,void 0)),this.value$=ss(this,s),Ne(this,Pt),this.value$=Ht(this,Pt),this.value$.onChange(g=>w(this,Pt,g)),h&&this.add(...h)}get value(){return r(this,o)}set value(h){f(this,o,h)}add(...h){return r(this,i).push(...h),m(this,n,Ut).call(this),m(this,n,oe).call(this,h)}unshift(...h){return r(this,i).unshift(...h),m(this,n,Ut).call(this),m(this,n,oe).call(this,h)}remove(...h){m(this,n,oe).call(this,h)()}clear(){r(this,i).length=0,m(this,n,Ut).call(this)}dispose(){var h;this.clear(),(h=r(this,a))==null||h.destroy(),f(this,a,void 0),de(this,Pt),z(this),this.value$.destroy(),bi(this)}},i=new WeakMap,a=new WeakMap,o=new WeakMap,n=new WeakSet,oe=function(h){return()=>{for(let g of h){let p=r(this,i).indexOf(g);p!==-1&&r(this,i).splice(p,1)}m(this,n,Ut).call(this)}},Ut=function(){var h;(h=r(this,a))==null||h.destroy(),r(this,i).length===0?(f(this,a,void 0),this.value=void 0):(f(this,a,ee(()=>{let g;for(let p of r(this,i)){let M=ze(p);if(M!=null){g=M;break}}this.value=g},r(this,i))),r(this,a).run())},(()=>{let h=typeof Symbol=="function"&&Symbol.metadata?Object.create(null):void 0;e=[Mi({name:Pt})],Pi(b,null,e,{kind:"accessor",name:"value",static:!1,private:!1,access:{has:g=>"value"in g,get:g=>g.value,set:(g,p)=>{g.value=p}},metadata:h},t,s),h&&Object.defineProperty(b,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:h})})(),b.Value=Pt,b})(),is="onCreate",Mt="onDestroy",ji="onParentChanged",Ti="onViewEvent",Ee=new Map,Se=!1,Li=(e,t)=>{Ee.set(e,t),Se||(Se=!0,queueMicrotask(()=>{Se=!1;let s=Array.from(Ee.entries());Ee.clear();for(let[i,a]of s)i.set(a)}))},J,Dt,ht,I,lt,x,T,tt,R,xt,P,De,dt,Bt,he,fs,Di=(fs=class{constructor(e,t){c(this,P);c(this,J);c(this,Dt);c(this,ht,new Oi);c(this,I,new Map);c(this,lt,new Map);c(this,x);c(this,T);c(this,tt,new Set);c(this,R,[]);c(this,xt,0);c(this,dt);f(this,J,e),f(this,Dt,t),O(this,Mt,fe.Min,this)}get kernel(){return r(this,J)}get uuid(){return r(this,Dt)}get order(){return r(this,xt)}set order(e){r(this,xt)!==e&&(f(this,xt,e),r(this,x)&&this.parent.resortChildren())}get parentUuid(){return r(this,x)||void 0}set parentUuid(e){r(this,x)!==e&&(this.removeFromParent(),f(this,x,e||void 0),f(this,T,e?r(this,J).getEntity(e):void 0),r(this,T)&&r(this,T).addChild(this))}get parent(){return!r(this,T)&&r(this,x)&&f(this,T,r(this,J).getEntity(r(this,x))),r(this,T)}set parent(e){this.parentUuid=e==null?void 0:e.uuid}get hasParent(){return!!r(this,x)}get children(){return r(this,R)}traverse(e){e(this);for(let t of r(this,R))t.traverse(e)}onDestroy(){var e;r(this,ht).clear(),z(this);for(let t of r(this,lt).values())t.cleanup(),t.signal.destroy();r(this,lt).clear();for(let t of r(this,I).values())t.context.set(void 0),t.unsubscribePathValue(),(e=t.unsubscribeFromParent)==null||e.call(t),t.valuePath.dispose(),t.inherited.destroy(),t.provide.destroy(),t.context.destroy();f(this,x,void 0),f(this,T,void 0),r(this,tt).clear(),r(this,R).length=0}addChild(e){var t;if(r(this,R).length===0){r(this,tt).add(e.uuid),r(this,R).push(e);return}if(r(this,tt).has(e.uuid))throw new Error(`child with uuid: ${e.uuid} already exists! parentUuid: ${this.uuid}`);r(this,tt).add(e.uuid),r(this,R).push(e),this.resortChildren();for(let[,s]of r(e,I))m(t=e,P,he).call(t,s)}resortChildren(){r(this,R).sort((e,t)=>e.order-t.order)}removeChild(e){r(this,tt).has(e.uuid)&&(r(this,tt).delete(e.uuid),r(this,R).splice(r(this,R).indexOf(e),1))}removeFromParent(){if(r(this,T)){r(this,T).removeChild(this),f(this,T,void 0),f(this,x,void 0);for(let[,e]of r(this,I))e.unsubscribeFromParent&&(e.unsubscribeFromParent(),e.unsubscribeFromParent=void 0)}}reSubscribeToParentContexts(){for(let[,e]of r(this,I))m(this,P,he).call(this,e)}dispatchMessageToView(e,t,s,i=!1){r(this,J).dispatchMessageToView({uuid:r(this,Dt),type:e,data:t,transferables:s,traverseChildren:i})}dispatchViewEvents(e){for(let{type:t,data:s}of e)w(this,Ti,t,s)}dispatchViewEvent(e,t){this.dispatchViewEvents([{type:e,data:t}])}getPropertyReader(e){return m(this,P,De).call(this,e).get}getPropertyWriter(e){return m(this,P,De).call(this,e).set}setProperties(e){this.clearTruthyPropsCache(),ce(()=>{for(let[t,s]of e)this.setProperty(t,s)})}setProperty(e,t){this.getPropertyWriter(e)(t)}getProperty(e){return ze(this.getPropertyReader(e))}propKeys(){return Array.from(r(this,ht).keys())}propEntries(){return Array.from(r(this,ht).entries()).map(([e,t])=>[e,t.value])}clearTruthyPropsCache(){f(this,dt,void 0)}truthyProps(){if(r(this,dt))return r(this,dt).size?r(this,dt):void 0;let e=new Set;for(let[t,s]of r(this,ht).entries())if(typeof t=="string"){let i=s.value;i!=null&&i!==!1&&i!==""&&e.add(t)}return f(this,dt,e),e.size?e:void 0}hasContext(e){return r(this,I).has(e)}useContext(e){return m(this,P,Bt).call(this,e).context.get}useParentContext(e){return m(this,P,Bt).call(this,e).inherited.get}provideContext(e){return m(this,P,Bt).call(this,e).provide}provideGlobalContext(e){if(r(this,lt).has(e))return r(this,lt).get(e).signal;let t=r(this,J).findOrCreateRootContext(e),s=k(),i=t.add(s);return r(this,lt).set(e,{cleanup:i,signal:s}),s}},J=new WeakMap,Dt=new WeakMap,ht=new WeakMap,I=new WeakMap,lt=new WeakMap,x=new WeakMap,T=new WeakMap,tt=new WeakMap,R=new WeakMap,xt=new WeakMap,P=new WeakSet,De=function(e){return r(this,ht).get(e)},dt=new WeakMap,Bt=function(e){if(r(this,I).has(e))return r(this,I).get(e);let t=k(),s=k(),i=k(),a=new Le([s,t]),o=Q(a,Le.Value,l=>{Li(i,l)}),n={name:e,inherited:t,provide:s,context:i,valuePath:a,unsubscribePathValue:o};return r(this,I).set(e,n),m(this,P,he).call(this,n),n},he=function(e){var t,s;if((t=e.unsubscribeFromParent)==null||t.call(e),e.unsubscribeFromParent=void 0,this.parent){let i=m(s=this.parent,P,Bt).call(s,e.name),a=pt(i.context,e.inherited);e.unsubscribeFromParent=a.destroy.bind(a)}else{let i=r(this,J).findOrCreateRootContext(e.name),a=pt(i.value$,e.inherited);e.unsubscribeFromParent=a.destroy.bind(a)}},fs);function xi(e,t){e.indexOf(t)===-1&&e.push(t)}var rs=e=>{let t=e.split("@").map(s=>s.trim());if(t.length===2&&t[1])return t[0]?{key:`${t[0]}@${t[1]}`,prop:t[1],token:t[0]}:{key:t[1],prop:t[1]}},ne=(e,t)=>{for(let s of t)e.add(s)},Ri=(e,t)=>{if(e!=null)for(let s of e.constructors)t.add(s)},et,L,G,gs,Ds=(gs=class{constructor(){c(this,et,new Map);c(this,L,new Map);c(this,G,new Map)}static get(e){return e!=null?e:Ni}define(e,t){r(this,et).has(e)?xi(r(this,et).get(e).constructors,t):r(this,et).set(e,{token:e,constructors:[t]})}appendRoute(e,t){let s=rs(e);s?r(this,G).has(s.key)?ne(r(this,G).get(s.key).routes,t):r(this,G).set(s.key,{routes:new Set(t),token:s.token}):r(this,L).has(e)?ne(r(this,L).get(e),t):r(this,L).set(e,new Set(t))}clearRoute(e){let t=rs(e);t?r(this,G).delete(t.key):r(this,L).delete(e)}findTokensByRoute(e,t){let s=new Set([e]),i=r(this,L).has(e)?[...r(this,L).get(e)]:[];for(;i.length;){let a=i.shift();s.has(a)||(s.add(a),r(this,L).has(a)&&i.push(...Array.from(r(this,L).get(a)).filter(o=>!s.has(o))))}if(t){for(let o of t)r(this,G).has(o)&&ne(s,r(this,G).get(o).routes);let a;do{a=s.size;for(let o of new Set(s))for(let n of t){let l=`${o}@${n}`;r(this,G).has(l)&&ne(s,r(this,G).get(l).routes)}}while(a!==s.size)}return s}findConstructors(e,t){let s=this.findTokensByRoute(e,t),i=new Set;for(let a of s)Ri(r(this,et).get(a),i);return i.size>0?Array.from(i):void 0}hasToken(e){return r(this,et).has(e)}hasRoute(e){return r(this,L).has(e)}clear(){r(this,et).clear(),r(this,L).clear()}},et=new WeakMap,L=new WeakMap,G=new WeakMap,gs),Ni=new Ds,Z;(function(e){e[e.CreateAndDestroy=0]="CreateAndDestroy",e[e.JustCreate=1]="JustCreate",e[e.DestroyOnly=2]="DestroyOnly"})(Z||(Z={}));var as=e=>e.displayName||e.name,C,K,Rt,Zt,Y,ut,ys,zi=(ys=class{constructor(e){c(this,C);c(this,K);c(this,Rt);c(this,Zt);c(this,Y);c(this,ut);this.logger=new qs("Kernel"),f(this,C,new Map),f(this,K,new Set),f(this,Y,!0),f(this,ut,new Map),it(this),this.registry=Ds.get(e)}getEntity(e){var s;let t=(s=r(this,C).get(e))==null?void 0:s.entity;if(!t)throw new Error(`entity with uuid "${e}" not found!`);return t}hasEntity(e){return r(this,C).has(e)}traverseLevelOrderBFS(e=!1){if(r(this,Y)){let t=new Map,s=(i,a)=>{let o=this.getEntity(i);t.has(a)?t.get(a).push(o):t.set(a,[o]);for(let n of o.children)s(n.uuid,a+1)};r(this,K).forEach(i=>s(i,0)),f(this,Rt,Array.from(t.entries()).sort((i,a)=>i[0]-a[0]).map(([,i])=>i).flat()),f(this,Zt,r(this,Rt).slice().reverse()),f(this,Y,!1)}return e?r(this,Zt):r(this,Rt)}getEntityGraph(){return Array.from(r(this,K)).map(e=>this.getEntityGraphNode(e))}getEntityGraphNode(e){if(!r(this,C).has(e))return;let{token:t,entity:s}=r(this,C).get(e);return{token:t,entity:s,props:Object.fromEntries(s.propEntries()),children:s.children.map(i=>this.getEntityGraphNode(i.uuid))}}upgradeEntities(){let e=new Map;for(let t of this.traverseLevelOrderBFS(!0))e.set(t.uuid,this.updateShadowObjects(t.uuid,Z.DestroyOnly));for(let t of this.traverseLevelOrderBFS(!1))this.updateShadowObjects(t.uuid,Z.JustCreate,e.get(t.uuid));e.clear()}run(e){this.logger.isDebug&&this.logger.debug("sync",e),ce(()=>{for(let t of e.changeTrail)this.parse(t)})}parse(e){switch(e.type){case X.CreateEntities:this.createEntity(e.uuid,e.token,e.parentUuid,e.order,e.properties),f(this,Y,!0);break;case X.DestroyEntities:this.destroyEntity(e.uuid),f(this,Y,!0);break;case X.SetParent:this.setParent(e.uuid,e.parentUuid,e.order),f(this,Y,!0);break;case X.UpdateOrder:this.updateOrder(e.uuid,e.order),f(this,Y,!0);break;case X.ChangeProperties:this.changeProperties(e.uuid,e.properties);break;case X.ChangeToken:this.changeToken(e.uuid,e.token);break;case X.SendEvents:this.dispatchEventsToEntity(e.uuid,e.events);break}}createEntity(e,t,s,i=0,a){let o=new Di(this,e);o.order=i;let n={token:t,entity:o,usedConstructors:new Map};r(this,C).set(e,n),s&&(o.parentUuid=s),o.hasParent||r(this,K).add(e),a&&o.setProperties(a),this.createShadowObjects(e)}destroyEntity(e){if(!r(this,C).has(e))return;let{entity:t,usedConstructors:s}=r(this,C).get(e);t.removeFromParent(),w(t,Mt,this),s.clear(),r(this,C).delete(t.uuid),r(this,K).delete(t.uuid)}setParent(e,t,s=0){let i=this.getEntity(e);i.parentUuid===t&&i.order===s||(i.removeFromParent(),i.order=s,i.parentUuid=t,i.hasParent?r(this,K).delete(e):r(this,K).add(e),i.reSubscribeToParentContexts(),queueMicrotask(()=>{this.logger.isDebug&&this.logger.debug("entity.onParentChanged",{uuid:e,parentUuid:t,order:s,entity:i}),w(i,ji,i)}))}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),this.updateShadowObjects(e)}changeToken(e,t){if(!r(this,C).has(e))return;let s=r(this,C).get(e);s.token!==t&&(s.token=t,this.updateShadowObjects(e))}dispatchMessageToView(e){queueMicrotask(()=>{w(this,Ae,e)})}updateShadowObjects(e,t=Z.CreateAndDestroy,s){let i=r(this,C).get(e);s!=null||(s=new Set(this.registry.findConstructors(i.token,i.entity.truthyProps())));let a=t===Z.CreateAndDestroy||t===Z.DestroyOnly,o=t===Z.CreateAndDestroy||t===Z.JustCreate;if(a){for(let[n,l]of i.usedConstructors)if(!s.has(n)){i.usedConstructors.delete(n);for(let y of l)this.destroyShadowObject(y,i.entity)}}if(o)for(let n of s)i.usedConstructors.has(n)||this.constructShadowObject(n,i);return s}constructShadowObject(e,t){let s=new Set,i=new Set,a=new Map,o=new Map,n=new Map,l=new Map,y=new Map,b=it(new e({entity:t.entity,provideContext(d,h,g){let p=n.get(d);if(p==null){p=k(h,g?{compare:g}:void 0);let M=pt(p,t.entity.provideContext(d));i.add(M.destroy.bind(M)),n.set(d,p)}return p},provideGlobalContext(d,h,g){let p=l.get(d);if(p==null){p=k(h,g?{compare:g}:void 0);let M=pt(p,t.entity.provideGlobalContext(d));i.add(M.destroy.bind(M)),l.set(d,p)}return p},useContext(d,h){let g=a.get(d);if(g===void 0){g=k(void 0,h?{compare:h}:void 0).get,a.set(d,g);let p=pt(t.entity.useContext(d),g);i.add(p.destroy.bind(p))}return g},useParentContext(d,h){let g=o.get(d);if(g===void 0){g=k(void 0,h?{compare:h}:void 0).get,o.set(d,g);let p=pt(t.entity.useParentContext(d),g);i.add(p.destroy.bind(p))}return g},useProperty(d,h){let g=y.get(d);if(g===void 0){g=k(void 0,h?{compare:h}:void 0).get,y.set(d,g);let p=pt(t.entity.getPropertyReader(d),g);i.add(p.destroy.bind(p))}return g},createEffect(...d){let h=ee(...d);return i.add(h.destroy),h},createSignal(...d){let h=k(...d);return i.add(()=>{U(h)}),h},createMemo(...d){let h=Si(...d);return i.add(()=>{U(h)}),h},on(...d){let h=Q(...d);return i.add(h),h},once(...d){let h=O(...d);return i.add(h),h},onDestroy(d){s.add(d)}}));return this.logger.isInfo&&this.logger.info("create shadow-object",as(e),{shadowObject:b,entity:t.entity}),O(t.entity,Mt,fe.Low,()=>{this.logger.isInfo&&this.logger.info("destroy shadow-object",as(e),{shadowObject:b,entity:t.entity});for(let h of s)h();for(let h of i)h();for(let h of a.values())U(h);for(let h of o.values())U(h);for(let h of y.values())U(h);for(let h of n.values())U(h);for(let h of l.values())U(h);s.clear(),i.clear(),a.clear(),o.clear(),y.clear(),n.clear(),l.clear();let d=t.usedConstructors.get(e);d&&(d.delete(b),d.size===0&&t.usedConstructors.delete(e))}),t.usedConstructors.has(e)?t.usedConstructors.get(e).add(b):t.usedConstructors.set(e,new Set([b])),this.attachShadowObject(b,t.entity),b}createShadowObjects(e){var s;let t=r(this,C).get(e);(s=this.registry.findConstructors(t.token,t.entity.truthyProps()))==null||s.forEach(i=>{this.constructShadowObject(i,t)})}findShadowObjects(e){if(!r(this,C).has(e))return[];let{usedConstructors:t}=r(this,C).get(e);return Array.from(new Set(Array.from(t.values()).map(s=>Array.from(s)).flat()))}attachShadowObject(e,t){Q(t,e),typeof e[is]=="function"&&e[is](t)}destroyShadowObject(e,t){typeof e[Mt]=="function"&&e[Mt](t),w(e,Mt,t),z(t,e)}findOrCreateRootContext(e){let t=r(this,ut).get(e);return t||(t=new Le,r(this,ut).set(e,t)),t}destroy(){for(let e of r(this,ut).values())e.dispose();r(this,ut).clear();for(let e of this.traverseLevelOrderBFS().reverse())this.destroyEntity(e.uuid)}},C=new WeakMap,K=new WeakMap,Rt=new WeakMap,Zt=new WeakMap,Y=new WeakMap,ut=new WeakMap,ys);async function xs(e,t,s,i=!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(l=>xs(e,l,s,!1)));let{registry:a}=e;if(t.define)for(let[l,y]of Object.entries(t.define))a.define(l,y);if(t.routes)for(let[l,y]of Object.entries(t.routes))a.appendRoute(l,y);await((n=(o=t.initialize)==null?void 0:o.call(t,{define:(l,y)=>a.define(l,y),kernel:e,registry:a}))!=null?n:Promise.resolve()),i&&e.upgradeEntities()}var Fi=e=>(typeof e=="string"&&(e=new URL(e,globalThis.location.href)),e.toString()),_t,ct,Rs,Ns,zs,ps,Vi=(ps=class{constructor(e){c(this,ct);c(this,_t,new Set);var t,s;this.kernel=(t=e==null?void 0:e.kernel)!=null?t:new zi,this.postMessage=(s=e==null?void 0:e.postMessage)!=null?s:self.postMessage.bind(self),Q(this.kernel,Ae,"onMessageToView",this)}route(e){var t;switch(e.data.type){case $s:m(this,ct,Rs).call(this,e.data);break;case Is:m(this,ct,Ns).call(this,e.data);break;case Gs:m(this,ct,zs).call(this,e.data);break;default:console.warn("[MessageRouter] unknown message",(t=e.data.type)!=null?t:e.data)}}onMessageToView(e){let i=e,{transferables:t}=i,s=Ge(i,["transferables"]);this.postMessage({type:Ae,data:s},{transfer:t})}},_t=new WeakMap,ct=new WeakSet,Rs=async function(e){try{let t=await import(Fi(e.importModule));t[me]?(await xs(this.kernel,t[me],r(this,_t)),this.postMessage({type:be,url:e.importModule})):this.postMessage({type:be,url:e.importModule,error:`module has no "${me}" export`})}catch(t){console.error("[MessageRouter] failed to import module",t),this.postMessage({type:be,url:e.importModule,error:`${t}`})}},Ns=function(e){try{this.kernel.run(e)}catch(t){console.error("[MessageRouter] failed to apply change trail",t),this.postMessage({type:qe,serial:e.serial,error:t.toString()})}e.serial&&this.postMessage({type:qe,serial:e.serial})},zs=function(e){console.debug("[MessageRouter] on destroy",e),z(this.kernel,this),r(this,_t).clear(),this.postMessage({type:Bs})},ps),$i=class{constructor(){this.onmessage=e=>{var t;e.data.type===N?globalThis[D]=e.data.config:((t=this.router)!=null||(this.router=new Vi),this.router.route(e))}}start(){self.addEventListener("message",this.onmessage),self.postMessage({type:Us})}};console.debug("@spearwolf/shadow-objects/WorkerRuntime: hello!");var Ii=new $i;Ii.start();\n/*! Bundled license information:\n\n@spearwolf/eventize/lib/index.mjs:\n (*!\n =============================================================================\n @spearwolf/eventize 4.0.2+build.20250807\n \u2014 https://github.com/spearwolf/eventize.git\n =============================================================================\n \n Copyright 2015-2025 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 Is=()=>new qe;var Nt=(s,t,e=1e3,r)=>new Promise((i,n)=>{let o,h,a=()=>{clearTimeout(o),s.removeEventListener("message",h)};e!==0&&e!==1/0&&(o=setTimeout(()=>{a(),n(new Error(`Timeout waiting for message of type: ${t}`))},e)),h=c=>{if(c.data.type===t)try{(!r||r(c.data))&&(a(),i())}catch(p){a(),n(p.toString())}},s.addEventListener("message",h)});var pr=s=>{let t;if(s!=null&&Array.isArray(s))for(let e of s)e.transferables&&(t?t=[...t,...e.transferables]:t=e.transferables,delete e.transferables);return t},be=class s{static{this.WorkerLoaded="workerLoaded"}#t;#e;#s;get isDestroyed(){return this.#e}get workerLoaded(){return ct(this,s.WorkerLoaded)}constructor(){this.#e=!1,this.#s=0,this.logger=new A("RemoteWorkerEnv"),U(this,s.WorkerLoaded)}async start(){if(this.#t)return this.logger.isWarn&&this.logger.warn("already started"),this.workerLoaded.then(()=>{if(this.isDestroyed)throw"worker was destroyed"});let t=this.#t=Is();this.configureConsoleLogger(t);try{if(await Nt(t,gs,vs),this.isDestroyed)throw"worker was destroyed";t.addEventListener("message",this.onMessageFromWorker.bind(this)),queueMicrotask(()=>{d(this,s.WorkerLoaded,this)})}catch(e){throw this.logger.error("failed to start",e),this.#t=void 0,e}}applyChangeTrail(t,e){let r=pr(t),i={type:ds,changeTrail:t},n=++this.#s;return e&&(i.serial=n),this.#t.postMessage(i,r),e?Nt(this.#t,ys,Cs,o=>{if(o.error)throw o.error;return o.serial===n}):Promise.resolve()}importScript(t){return t=ye(t),this.#t.postMessage({type:fs,importModule:t}),Nt(this.#t,ms,ws,e=>{if(e.error)throw e.error;return e.url===t})}destroy(){if(!this.#t)return;let t=this.#t;this.#t=void 0,this.#e=!0,t.postMessage({type:ps}),Nt(t,bs,Es).finally(()=>{t.terminate()})}onMessageFromWorker(t){t.data?.type===yt?this.onMessageToView?.(t.data.data):this.logger.isDebug&&this.logger.debug("message from worker",t)}configureConsoleLogger(t){let e=`${j}.RemoteWorkerEnv.workerConfig`,r=JSON.parse(localStorage.getItem(e)??"{}");this.logger.isInfo&&this.logger.info("load console-logger worker config",{localStorageKey:e,workerConfig:r}),t.postMessage({type:j,config:{...A.sharedConfig,enable:this.logger.isEnabled,...r,...A.isEnabled?{}:{enable:!1}}})}};var Dt,$t=class extends Z{static{this.observedAttributes=[...Z.observedAttributes,ie,"src",ne]}static{this.DefaultAutoSync="frame"}#t;#e;#s;#i;#r;constructor(){super(),this.isShaeWorkerElement=!0,this.shadowEnv=new I,this.logger=new A("ShaeWorkerElement"),this.autostart=!0,this.isConnected$=f(!1),this.autoSync$=f(Dt.DefaultAutoSync),this.src$=f(""),this.#t=!1,this.#e=!1,this.ns$.onChange(t=>{this.shadowEnv.view=N.get(t)}),m(this.shadowEnv,I.ContextCreated,()=>{this.#r?.run(),this.dispatchEvent(new CustomEvent(I.ContextCreated.toLowerCase(),{bubbles:!1,detail:{shadowEnv:this.shadowEnv}}))}),m(this.shadowEnv,I.ContextLost,()=>{this.dispatchEvent(new CustomEvent(I.ContextLost.toLowerCase(),{bubbles:!1,detail:{shadowEnv:this.shadowEnv}}))}),this.autoSync$.onChange(t=>{let e=this.hasAttribute(F),r=e?this.getAttribute(F):void 0;t===Dt.DefaultAutoSync?e&&r!==t&&this.setAttribute(F,t):r!==t&&this.setAttribute(F,t)}),this.#a(),this.#n()}#n(){this.#r=w(()=>{let t=this.src$.get();t&&this.importScript(t)},{autorun:!1})}get shouldAutostart(){return this.autostart&&!Lt(this,Rs)}get autoSync(){return this.autoSync$.value}set autoSync(t){typeof t!="string"&&(t=t?Dt.DefaultAutoSync:"no"),this.autoSync$.set(`${t}`.trim().toLowerCase())}get frameLoop(){return this.#s??=new mt,this.#s}[mt.OnFrame](){this.syncShadowObjects()}async importScript(t){if(!t)throw new Error("src is blank");let e=await this.shadowEnv.ready();return this.logger.isInfo&&this.logger.info("shadowEnv importScript:",t,{shadowEnv:e}),await e.envProxy.importScript(t),this}connectedCallback(){O(()=>{this.hasAttribute(F)&&this.autoSync$.set(this.getAttribute(F)),this.isConnected$.set(!0)}),this.shouldAutostart&&this.start()}disconnectedCallback(){this.isConnected$.set(!1),this.#o()}attributeChangedCallback(t){if(super.attributeChangedCallback(t),t===ie&&this.shadowEnv.envProxy!=null)throw new Error('Changing the "local" attribute after the shadowEnv has been created is not supported.');if(t===ne&&this.#h(),t===F&&(this.autoSync=this.hasAttribute(F)?this.getAttribute(F):!0),t==="src"){let e=(this.getAttribute("src")||"").trim();this.src$.set(e),this.shadowEnv.isReady&&this.#r?.run()}}start(){if(!this.#e){if(this.#t=!1,this.shadowEnv.view??=N.get(this.ns),this.shadowEnv.envProxy==null){let t=Lt(this,ie)?new me:new be;this.shadowEnv.envProxy=t,this.#h()}this.#e=!0}return this.shadowEnv.ready()}destroy(){this.#i?.destroy(),this.#r?.destroy(),x(this.isConnected$,this.autoSync$,this.src$),this.shadowEnv.envProxy=void 0,this.shadowEnv.destroy()}#o(){this.#t||(this.#t=!0,queueMicrotask(()=>{this.#t&&this.destroy()}))}#a(){this.#i=w(()=>{if(this.isConnected$.get()){let t=(this.autoSync$.get()||Dt.DefaultAutoSync).trim().toLowerCase(),e;if(["true","yes","on","frame","auto-sync"].includes(t))return this.logger.isDebug&&this.logger.debug("auto-sync",t,this),this.frameLoop.start(this),()=>{this.frameLoop.stop(this)};if(t.toLowerCase().endsWith("fps")){let r=parseInt(t,10);r>0?e=Math.floor(1e3/r):this.logger.isWarn&&this.logger.warn(`invalid auto-sync value: ${t}`)}else e=parseInt(t,10),isNaN(e)&&(e=void 0,["false","no","off"].includes(t)||this.logger.error(`invalid auto-sync value: ${t}`));if(e!==void 0&&e>0){this.logger.isDebug&&this.logger.debug("auto-sync interval (ms)",e,this);let r=setInterval(()=>{this.syncShadowObjects()},e);return()=>{clearInterval(r)}}else this.logger.isDebug&&this.logger.debug("auto-sync off",this)}},[this.autoSync$,this.isConnected$])}#h(){let t=this.shadowEnv.envProxy;t?.isLocalEnv&&(t.disableStructuredClone=this.hasAttribute(ne))}};Dt=$t;customElements.define(Ts,$t);globalThis.SHADOW_ENTS_BUNDLE_LOADED=!0;
|
|
22
22
|
/*! Bundled license information:
|
|
23
23
|
|
|
24
24
|
@spearwolf/eventize/lib/index.mjs:
|
|
25
25
|
(*!
|
|
26
26
|
=============================================================================
|
|
27
|
-
@spearwolf/eventize 4.0.
|
|
27
|
+
@spearwolf/eventize 4.0.2+build.20250807
|
|
28
28
|
— https://github.com/spearwolf/eventize.git
|
|
29
29
|
=============================================================================
|
|
30
30
|
|
|
31
|
-
Copyright 2015-
|
|
31
|
+
Copyright 2015-2025 Wolfger Schramm
|
|
32
32
|
|
|
33
33
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
34
34
|
you may not use this file except in compliance with the License.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spearwolf/shadow-objects",
|
|
3
3
|
"description": "a reactive entity-component framework that feels at home in the shadows",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.21.1",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Wolfger Schramm",
|
|
7
7
|
"email": "wolfger@spearwolf.de",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"src/shae-worker.js"
|
|
62
62
|
],
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@spearwolf/eventize": "^4.0.
|
|
65
|
-
"@spearwolf/signalize": "^0.
|
|
64
|
+
"@spearwolf/eventize": "^4.0.2",
|
|
65
|
+
"@spearwolf/signalize": "^0.24.0"
|
|
66
66
|
}
|
|
67
67
|
}
|
package/src/constants.d.ts
CHANGED
|
@@ -31,9 +31,9 @@ export declare const Destroyed = "destroyed";
|
|
|
31
31
|
* The `messageToView` event is fired when the kernel receives a message from an entity (to its view component counterpart)
|
|
32
32
|
*/
|
|
33
33
|
export declare const MessageToView = "messageToView";
|
|
34
|
-
export declare const WorkerLoadTimeout =
|
|
35
|
-
export declare const WorkerConfigureTimeout =
|
|
36
|
-
export declare const WorkerChangeTrailTimeout =
|
|
37
|
-
export declare const WorkerDestroyTimeout =
|
|
34
|
+
export declare const WorkerLoadTimeout = 60000;
|
|
35
|
+
export declare const WorkerConfigureTimeout = 60000;
|
|
36
|
+
export declare const WorkerChangeTrailTimeout = 5000;
|
|
37
|
+
export declare const WorkerDestroyTimeout = 5000;
|
|
38
38
|
export declare const ShadowObjectsExport = "shadowObjects";
|
|
39
39
|
//# sourceMappingURL=constants.d.ts.map
|
package/src/constants.js
CHANGED
|
@@ -32,9 +32,9 @@ export const Destroyed = 'destroyed';
|
|
|
32
32
|
* The `messageToView` event is fired when the kernel receives a message from an entity (to its view component counterpart)
|
|
33
33
|
*/
|
|
34
34
|
export const MessageToView = 'messageToView';
|
|
35
|
-
export const WorkerLoadTimeout =
|
|
36
|
-
export const WorkerConfigureTimeout =
|
|
37
|
-
export const WorkerChangeTrailTimeout =
|
|
38
|
-
export const WorkerDestroyTimeout =
|
|
35
|
+
export const WorkerLoadTimeout = 60000;
|
|
36
|
+
export const WorkerConfigureTimeout = 60000;
|
|
37
|
+
export const WorkerChangeTrailTimeout = 5000;
|
|
38
|
+
export const WorkerDestroyTimeout = 5000;
|
|
39
39
|
export const ShadowObjectsExport = 'shadowObjects';
|
|
40
40
|
//# sourceMappingURL=constants.js.map
|
package/tsconfig.lib.tsbuildinfo
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../src/bundle.ts","../src/constants.ts","../src/create-worker.bundle.ts","../src/create-worker.ts","../src/elements.ts","../src/index.ts","../src/shadow-objects.ts","../src/shadow-objects.worker.js","../src/shae-ent.ts","../src/shae-prop.ts","../src/shae-worker.ts","../src/types.ts","../src/elements/ShaeElement.ts","../src/elements/ShaeEntElement.ts","../src/elements/ShaePropElement.ts","../src/elements/ShaeWorkerElement.ts","../src/elements/constants.ts","../src/elements/events.ts","../src/in-the-dark/Entity.ts","../src/in-the-dark/Kernel.ts","../src/in-the-dark/Registry.ts","../src/in-the-dark/ShadowObject.ts","../src/in-the-dark/SignalsPath.ts","../src/in-the-dark/events.ts","../src/in-the-dark/importModule.ts","../src/utils/ConsoleLogger.ts","../src/utils/FrameLoop.ts","../src/utils/array-utils.ts","../src/utils/attr-utils.ts","../src/utils/constants.ts","../src/utils/generateUUID.ts","../src/utils/props-utils.ts","../src/utils/toNamespace.ts","../src/utils/toUrlString.ts","../src/utils/waitForMessageOfType.ts","../src/view/ComponentChanges.ts","../src/view/ComponentContext.ts","../src/view/ComponentMemory.ts","../src/view/IShadowObjectEnvProxy.ts","../src/view/LocalShadowObjectEnv.ts","../src/view/RemoteWorkerEnv.ts","../src/view/ShadowEnv.ts","../src/view/ViewComponent.ts","../src/view/cloneChangeTrail.ts","../src/worker/MessageRouter.ts","../src/worker/WorkerRuntime.ts"],"version":"5.
|
|
1
|
+
{"root":["../src/bundle.ts","../src/constants.ts","../src/create-worker.bundle.ts","../src/create-worker.ts","../src/elements.ts","../src/index.ts","../src/shadow-objects.ts","../src/shadow-objects.worker.js","../src/shae-ent.ts","../src/shae-prop.ts","../src/shae-worker.ts","../src/types.ts","../src/elements/ShaeElement.ts","../src/elements/ShaeEntElement.ts","../src/elements/ShaePropElement.ts","../src/elements/ShaeWorkerElement.ts","../src/elements/constants.ts","../src/elements/events.ts","../src/in-the-dark/Entity.ts","../src/in-the-dark/Kernel.ts","../src/in-the-dark/Registry.ts","../src/in-the-dark/ShadowObject.ts","../src/in-the-dark/SignalsPath.ts","../src/in-the-dark/events.ts","../src/in-the-dark/importModule.ts","../src/utils/ConsoleLogger.ts","../src/utils/FrameLoop.ts","../src/utils/array-utils.ts","../src/utils/attr-utils.ts","../src/utils/constants.ts","../src/utils/generateUUID.ts","../src/utils/props-utils.ts","../src/utils/toNamespace.ts","../src/utils/toUrlString.ts","../src/utils/waitForMessageOfType.ts","../src/view/ComponentChanges.ts","../src/view/ComponentContext.ts","../src/view/ComponentMemory.ts","../src/view/IShadowObjectEnvProxy.ts","../src/view/LocalShadowObjectEnv.ts","../src/view/RemoteWorkerEnv.ts","../src/view/ShadowEnv.ts","../src/view/ViewComponent.ts","../src/view/cloneChangeTrail.ts","../src/worker/MessageRouter.ts","../src/worker/WorkerRuntime.ts"],"version":"5.9.3"}
|