@spearwolf/shadow-objects 0.33.0 → 0.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +350 -61
- package/README.md +66 -13
- package/bundle.js +6 -53
- package/package.json +15 -3
- package/src/ChangeTrailRefusedError.d.ts +27 -0
- package/src/ChangeTrailRefusedError.d.ts.map +1 -0
- package/src/ChangeTrailRefusedError.js +12 -0
- package/src/ChangeTrailRefusedError.js.map +7 -0
- package/src/EntityUuidInUseError.d.ts +19 -0
- package/src/EntityUuidInUseError.d.ts.map +1 -0
- package/src/EntityUuidInUseError.js +11 -0
- package/src/EntityUuidInUseError.js.map +7 -0
- package/src/WorkerTimeoutError.d.ts +26 -0
- package/src/WorkerTimeoutError.d.ts.map +1 -0
- package/src/WorkerTimeoutError.js +12 -0
- package/src/WorkerTimeoutError.js.map +7 -0
- package/src/bundle.d.ts +1 -1
- package/src/bundle.d.ts.map +1 -1
- package/src/bundle.js +1 -1
- package/src/bundle.js.map +2 -2
- package/src/constants.d.ts +13 -2
- package/src/constants.d.ts.map +1 -1
- package/src/constants.js +7 -1
- package/src/constants.js.map +2 -2
- package/src/create-worker.bundle.d.ts +1 -1
- package/src/create-worker.bundle.d.ts.map +1 -1
- package/src/create-worker.bundle.js.map +1 -1
- package/src/create-worker.d.ts +1 -1
- package/src/create-worker.d.ts.map +1 -1
- package/src/create-worker.js.map +1 -1
- package/src/elements/ShaeElement.d.ts +70 -2
- package/src/elements/ShaeElement.d.ts.map +1 -1
- package/src/elements/ShaeElement.js +129 -25
- package/src/elements/ShaeElement.js.map +3 -3
- package/src/elements/ShaeEntElement.d.ts +39 -1
- package/src/elements/ShaeEntElement.d.ts.map +1 -1
- package/src/elements/ShaeEntElement.js +397 -167
- package/src/elements/ShaeEntElement.js.map +2 -2
- package/src/elements/ShaeLifecycleElement.d.ts +71 -0
- package/src/elements/ShaeLifecycleElement.d.ts.map +1 -0
- package/src/elements/ShaeLifecycleElement.js +83 -0
- package/src/elements/ShaeLifecycleElement.js.map +7 -0
- package/src/elements/ShaePropElement.d.ts +61 -2
- package/src/elements/ShaePropElement.d.ts.map +1 -1
- package/src/elements/ShaePropElement.js +264 -219
- package/src/elements/ShaePropElement.js.map +2 -2
- package/src/elements/ShaeWorkerElement.d.ts +59 -5
- package/src/elements/ShaeWorkerElement.d.ts.map +1 -1
- package/src/elements/ShaeWorkerElement.js +271 -73
- package/src/elements/ShaeWorkerElement.js.map +2 -2
- package/src/elements/constants.d.ts +9 -0
- package/src/elements/constants.d.ts.map +1 -1
- package/src/elements/constants.js +18 -0
- package/src/elements/constants.js.map +2 -2
- package/src/elements/deferredTeardown.d.ts +24 -0
- package/src/elements/deferredTeardown.d.ts.map +1 -0
- package/src/elements/deferredTeardown.js +30 -0
- package/src/elements/deferredTeardown.js.map +7 -0
- package/src/elements/displayContentsRule.d.ts +25 -0
- package/src/elements/displayContentsRule.d.ts.map +1 -0
- package/src/elements/displayContentsRule.js +37 -0
- package/src/elements/displayContentsRule.js.map +7 -0
- package/src/elements/events.d.ts +10 -7
- package/src/elements/events.d.ts.map +1 -1
- package/src/elements/forwardCustomEvents.d.ts +19 -0
- package/src/elements/forwardCustomEvents.d.ts.map +1 -0
- package/src/elements/forwardCustomEvents.js +47 -0
- package/src/elements/forwardCustomEvents.js.map +7 -0
- package/src/elements/hostedSlots.d.ts +36 -0
- package/src/elements/hostedSlots.d.ts.map +1 -0
- package/src/elements/hostedSlots.js +118 -0
- package/src/elements/hostedSlots.js.map +7 -0
- package/src/elements/parentRemoval.d.ts +18 -0
- package/src/elements/parentRemoval.d.ts.map +1 -0
- package/src/elements/parentRemoval.js +60 -0
- package/src/elements/parentRemoval.js.map +7 -0
- package/src/elements/propValueConverters.d.ts +3 -0
- package/src/elements/propValueConverters.d.ts.map +1 -0
- package/src/elements/propValueConverters.js +54 -0
- package/src/elements/propValueConverters.js.map +7 -0
- package/src/elements/requestEntAncestor.d.ts +32 -0
- package/src/elements/requestEntAncestor.d.ts.map +1 -0
- package/src/elements/requestEntAncestor.js +16 -0
- package/src/elements/requestEntAncestor.js.map +7 -0
- package/src/elements.js.map +1 -1
- package/src/in-the-dark/Entity.d.ts +143 -3
- package/src/in-the-dark/Entity.d.ts.map +1 -1
- package/src/in-the-dark/Entity.js +330 -63
- package/src/in-the-dark/Entity.js.map +3 -3
- package/src/in-the-dark/Kernel.d.ts +98 -16
- package/src/in-the-dark/Kernel.d.ts.map +1 -1
- package/src/in-the-dark/Kernel.js +466 -379
- package/src/in-the-dark/Kernel.js.map +3 -3
- package/src/in-the-dark/Registry.d.ts +7 -1
- package/src/in-the-dark/Registry.d.ts.map +1 -1
- package/src/in-the-dark/Registry.js +112 -14
- package/src/in-the-dark/Registry.js.map +2 -2
- package/src/in-the-dark/ShadowObject.d.ts.map +1 -1
- package/src/in-the-dark/ShadowObject.js +1 -0
- package/src/in-the-dark/ShadowObject.js.map +2 -2
- package/src/in-the-dark/ShadowObjectCreationScope.d.ts +133 -0
- package/src/in-the-dark/ShadowObjectCreationScope.d.ts.map +1 -0
- package/src/in-the-dark/ShadowObjectCreationScope.js +603 -0
- package/src/in-the-dark/ShadowObjectCreationScope.js.map +7 -0
- package/src/in-the-dark/SignalsPath.d.ts +2 -0
- package/src/in-the-dark/SignalsPath.d.ts.map +1 -1
- package/src/in-the-dark/SignalsPath.js +6 -2
- package/src/in-the-dark/SignalsPath.js.map +2 -2
- package/src/in-the-dark/displayName.d.ts +4 -0
- package/src/in-the-dark/displayName.d.ts.map +1 -0
- package/src/in-the-dark/displayName.js +5 -0
- package/src/in-the-dark/displayName.js.map +7 -0
- package/src/in-the-dark/events.js.map +1 -1
- package/src/in-the-dark/importModule.d.ts +7 -0
- package/src/in-the-dark/importModule.d.ts.map +1 -1
- package/src/in-the-dark/importModule.js +5 -2
- package/src/in-the-dark/importModule.js.map +2 -2
- package/src/index.d.ts +9 -1
- package/src/index.d.ts.map +1 -1
- package/src/index.js +9 -1
- package/src/index.js.map +2 -2
- package/src/inspect/createKernelSnapshot.d.ts +17 -0
- package/src/inspect/createKernelSnapshot.d.ts.map +1 -0
- package/src/inspect/createKernelSnapshot.js +247 -0
- package/src/inspect/createKernelSnapshot.js.map +7 -0
- package/src/inspect/createViewSnapshot.d.ts +10 -0
- package/src/inspect/createViewSnapshot.d.ts.map +1 -0
- package/src/inspect/createViewSnapshot.js +143 -0
- package/src/inspect/createViewSnapshot.js.map +7 -0
- package/src/inspect/normalizeInspectRequest.d.ts +32 -0
- package/src/inspect/normalizeInspectRequest.d.ts.map +1 -0
- package/src/inspect/normalizeInspectRequest.js +55 -0
- package/src/inspect/normalizeInspectRequest.js.map +7 -0
- package/src/inspect/serializeValue.d.ts +13 -0
- package/src/inspect/serializeValue.d.ts.map +1 -0
- package/src/inspect/serializeValue.js +149 -0
- package/src/inspect/serializeValue.js.map +7 -0
- package/src/inspect/types.d.ts +260 -0
- package/src/inspect/types.d.ts.map +1 -0
- package/src/inspect/types.js +1 -0
- package/src/inspect/types.js.map +7 -0
- package/src/model-context/ModelContextLike.d.ts +59 -0
- package/src/model-context/ModelContextLike.d.ts.map +1 -0
- package/src/model-context/ModelContextLike.js +15 -0
- package/src/model-context/ModelContextLike.js.map +7 -0
- package/src/model-context/exposeShadowEnvsToModelContext.d.ts +48 -0
- package/src/model-context/exposeShadowEnvsToModelContext.d.ts.map +1 -0
- package/src/model-context/exposeShadowEnvsToModelContext.js +39 -0
- package/src/model-context/exposeShadowEnvsToModelContext.js.map +7 -0
- package/src/model-context/redactProps.d.ts +14 -0
- package/src/model-context/redactProps.d.ts.map +1 -0
- package/src/model-context/redactProps.js +22 -0
- package/src/model-context/redactProps.js.map +7 -0
- package/src/model-context/sharedExposure.d.ts +32 -0
- package/src/model-context/sharedExposure.d.ts.map +1 -0
- package/src/model-context/sharedExposure.js +108 -0
- package/src/model-context/sharedExposure.js.map +7 -0
- package/src/model-context/toolSupport.d.ts +72 -0
- package/src/model-context/toolSupport.d.ts.map +1 -0
- package/src/model-context/toolSupport.js +145 -0
- package/src/model-context/toolSupport.js.map +7 -0
- package/src/model-context/tools/findEntities.d.ts +15 -0
- package/src/model-context/tools/findEntities.d.ts.map +1 -0
- package/src/model-context/tools/findEntities.js +71 -0
- package/src/model-context/tools/findEntities.js.map +7 -0
- package/src/model-context/tools/getEntity.d.ts +16 -0
- package/src/model-context/tools/getEntity.d.ts.map +1 -0
- package/src/model-context/tools/getEntity.js +65 -0
- package/src/model-context/tools/getEntity.js.map +7 -0
- package/src/model-context/tools/getEntityTree.d.ts +4 -0
- package/src/model-context/tools/getEntityTree.d.ts.map +1 -0
- package/src/model-context/tools/getEntityTree.js +58 -0
- package/src/model-context/tools/getEntityTree.js.map +7 -0
- package/src/model-context/tools/getRegistry.d.ts +14 -0
- package/src/model-context/tools/getRegistry.d.ts.map +1 -0
- package/src/model-context/tools/getRegistry.js +39 -0
- package/src/model-context/tools/getRegistry.js.map +7 -0
- package/src/model-context/tools/index.d.ts +9 -0
- package/src/model-context/tools/index.d.ts.map +1 -0
- package/src/model-context/tools/index.js +16 -0
- package/src/model-context/tools/index.js.map +7 -0
- package/src/model-context/tools/listEnvs.d.ts +33 -0
- package/src/model-context/tools/listEnvs.d.ts.map +1 -0
- package/src/model-context/tools/listEnvs.js +37 -0
- package/src/model-context/tools/listEnvs.js.map +7 -0
- package/src/model-context.d.ts +13 -0
- package/src/model-context.d.ts.map +1 -0
- package/src/model-context.js +15 -0
- package/src/model-context.js.map +7 -0
- package/src/shadow-objects.d.ts +4 -0
- package/src/shadow-objects.d.ts.map +1 -1
- package/src/shadow-objects.js +6 -0
- package/src/shadow-objects.js.map +2 -2
- package/src/shadow-objects.worker.js +0 -1
- package/src/shadow-objects.worker.js.map +2 -2
- package/src/shae-ent.js.map +1 -1
- package/src/shae-prop.js +2 -2
- package/src/shae-prop.js.map +2 -2
- package/src/shae-worker.js.map +1 -1
- package/src/testing/TestEntity.d.ts +79 -0
- package/src/testing/TestEntity.d.ts.map +1 -0
- package/src/testing/TestEntity.js +135 -0
- package/src/testing/TestEntity.js.map +7 -0
- package/src/testing/createTestKernel.d.ts +11 -0
- package/src/testing/createTestKernel.d.ts.map +1 -0
- package/src/testing/createTestKernel.js +132 -0
- package/src/testing/createTestKernel.js.map +7 -0
- package/src/testing/mountShadowObject.d.ts +21 -0
- package/src/testing/mountShadowObject.d.ts.map +1 -0
- package/src/testing/mountShadowObject.js +72 -0
- package/src/testing/mountShadowObject.js.map +7 -0
- package/src/testing/recordKernelErrors.d.ts +21 -0
- package/src/testing/recordKernelErrors.d.ts.map +1 -0
- package/src/testing/recordKernelErrors.js +39 -0
- package/src/testing/recordKernelErrors.js.map +7 -0
- package/src/testing/settle.d.ts +15 -0
- package/src/testing/settle.d.ts.map +1 -0
- package/src/testing/settle.js +19 -0
- package/src/testing/settle.js.map +7 -0
- package/src/testing/types.d.ts +119 -0
- package/src/testing/types.d.ts.map +1 -0
- package/src/testing/types.js +1 -0
- package/src/testing/types.js.map +7 -0
- package/src/testing.d.ts +14 -0
- package/src/testing.d.ts.map +1 -0
- package/src/testing.js +11 -0
- package/src/testing.js.map +7 -0
- package/src/types.d.ts +185 -14
- package/src/types.d.ts.map +1 -1
- package/src/utils/ConsoleLogger.d.ts +45 -10
- package/src/utils/ConsoleLogger.d.ts.map +1 -1
- package/src/utils/ConsoleLogger.js +51 -26
- package/src/utils/ConsoleLogger.js.map +2 -2
- package/src/utils/FrameLoop.d.ts +42 -3
- package/src/utils/FrameLoop.d.ts.map +1 -1
- package/src/utils/FrameLoop.js +71 -10
- package/src/utils/FrameLoop.js.map +2 -2
- package/src/utils/MicrotaskCollector.d.ts +45 -0
- package/src/utils/MicrotaskCollector.d.ts.map +1 -0
- package/src/utils/MicrotaskCollector.js +33 -0
- package/src/utils/MicrotaskCollector.js.map +7 -0
- package/src/utils/MicrotaskGate.d.ts +17 -0
- package/src/utils/MicrotaskGate.d.ts.map +1 -0
- package/src/utils/MicrotaskGate.js +20 -0
- package/src/utils/MicrotaskGate.js.map +7 -0
- package/src/utils/array-utils.js.map +1 -1
- package/src/utils/attr-utils.d.ts +11 -0
- package/src/utils/attr-utils.d.ts.map +1 -1
- package/src/utils/attr-utils.js +5 -1
- package/src/utils/attr-utils.js.map +2 -2
- package/src/utils/constants.js.map +1 -1
- package/src/utils/generateUUID.d.ts +11 -0
- package/src/utils/generateUUID.d.ts.map +1 -1
- package/src/utils/generateUUID.js +31 -266
- package/src/utils/generateUUID.js.map +2 -2
- package/src/utils/props-utils.d.ts +3 -2
- package/src/utils/props-utils.d.ts.map +1 -1
- package/src/utils/props-utils.js +13 -24
- package/src/utils/props-utils.js.map +2 -2
- package/src/utils/runGuarded.d.ts +27 -0
- package/src/utils/runGuarded.d.ts.map +1 -0
- package/src/utils/runGuarded.js +11 -0
- package/src/utils/runGuarded.js.map +7 -0
- package/src/utils/toMaybe.d.ts.map +1 -1
- package/src/utils/toMaybe.js.map +1 -1
- package/src/utils/toNamespace.d.ts.map +1 -1
- package/src/utils/toNamespace.js.map +1 -1
- package/src/utils/toUrlString.d.ts +12 -0
- package/src/utils/toUrlString.d.ts.map +1 -1
- package/src/utils/toUrlString.js.map +2 -2
- package/src/utils/waitForMessageOfType.d.ts +12 -1
- package/src/utils/waitForMessageOfType.d.ts.map +1 -1
- package/src/utils/waitForMessageOfType.js +16 -1
- package/src/utils/waitForMessageOfType.js.map +2 -2
- package/src/view/ComponentChanges.d.ts +88 -1
- package/src/view/ComponentChanges.d.ts.map +1 -1
- package/src/view/ComponentChanges.js +243 -73
- package/src/view/ComponentChanges.js.map +2 -2
- package/src/view/ComponentContext.d.ts +206 -16
- package/src/view/ComponentContext.d.ts.map +1 -1
- package/src/view/ComponentContext.js +548 -91
- package/src/view/ComponentContext.js.map +2 -2
- package/src/view/ComponentMemory.d.ts +3 -3
- package/src/view/ComponentMemory.d.ts.map +1 -1
- package/src/view/ComponentMemory.js.map +1 -1
- package/src/view/IShadowObjectEnvProxy.d.ts +38 -3
- package/src/view/IShadowObjectEnvProxy.d.ts.map +1 -1
- package/src/view/LocalShadowObjectEnv.d.ts +8 -1
- package/src/view/LocalShadowObjectEnv.d.ts.map +1 -1
- package/src/view/LocalShadowObjectEnv.js +23 -7
- package/src/view/LocalShadowObjectEnv.js.map +2 -2
- package/src/view/RemoteWorkerEnv.d.ts +108 -5
- package/src/view/RemoteWorkerEnv.d.ts.map +1 -1
- package/src/view/RemoteWorkerEnv.js +244 -77
- package/src/view/RemoteWorkerEnv.js.map +2 -2
- package/src/view/ShadowEnv.d.ts +79 -2
- package/src/view/ShadowEnv.d.ts.map +1 -1
- package/src/view/ShadowEnv.js +323 -59
- package/src/view/ShadowEnv.js.map +3 -3
- package/src/view/ViewComponent.d.ts +78 -14
- package/src/view/ViewComponent.d.ts.map +1 -1
- package/src/view/ViewComponent.js +90 -14
- package/src/view/ViewComponent.js.map +2 -2
- package/src/view/cloneChangeTrail.js.map +2 -2
- package/src/worker/MessageRouter.d.ts +14 -0
- package/src/worker/MessageRouter.d.ts.map +1 -1
- package/src/worker/MessageRouter.js +98 -15
- package/src/worker/MessageRouter.js.map +2 -2
- package/src/worker/WorkerRuntime.d.ts +22 -1
- package/src/worker/WorkerRuntime.d.ts.map +1 -1
- package/src/worker/WorkerRuntime.js +60 -8
- package/src/worker/WorkerRuntime.js.map +2 -2
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.35.0+bundle.20260906
|
|
5
5
|
|
|
6
6
|
Copyright 2026 Wolfger Schramm
|
|
7
7
|
|
|
@@ -18,62 +18,15 @@ See the License for the specific language governing permissions and
|
|
|
18
18
|
limitations under the License.
|
|
19
19
|
|
|
20
20
|
*/
|
|
21
|
-
var pt="shaeRequestEntParent",gt="shaeReRequestEntParent",Us="shae-worker",yt="shae-ent",Vs="shae-prop",ce="token",q="forward-custom-events";var vt="local",Bs="no-autostart",mt="no-structured-clone",H="auto-sync";var bt="name",wt="value",Et="type",Ct="no-trim";var Ce="*",Ys=1,ss=2,is=4,Q=Symbol.for("eventize"),or="[eventize]",rs=s=>s===Ce,Js=s=>{switch(typeof s){case"string":case"symbol":return!0;default:return!1}},Xs=typeof console<"u",ar=Xs?console[console.warn?"warn":"log"].bind(console,or):()=>{},hr=(s,e,t)=>(Object.defineProperty(s,e,{value:t,configurable:!0}),s),lr=0,ns=class{static publish(s){s.sort((e,t)=>e.order-t.order).forEach(e=>e.replay())}events=new Map;eventNames=new Set;add(s){Array.isArray(s)?s.forEach(e=>this.eventNames.add(e)):this.eventNames.add(s)}remove(s){Array.isArray(s)?s.forEach(e=>this.eventNames.delete(e)):this.eventNames.delete(s),this.clear(s)}clear(s){Array.isArray(s)?s.forEach(e=>this.events.delete(e)):this.events.delete(s)}retain(s,e){this.eventNames.has(s)&&this.events.set(s,{args:e,order:lr++})}isKnown(s){return this.eventNames.has(s)}replayTo(s,e,t=[]){if(rs(s))this.eventNames.forEach(i=>this.replayTo(i,e,t));else if(this.events.has(s)){let{order:i,args:r}=this.events.get(s);t.push({order:i,replay:()=>e.apply(s,r)})}return t}},es=(s,e,t,i)=>{if(typeof e=="function"){let r=e.apply(s,t);r!=null&&i?.(r)}},cr=(s,e,t,i)=>es(e,e.emit,[s].concat(t),i),ur=s=>{switch(typeof s){case"function":return Ys;case"string":case"symbol":return ss;case"object":return is}},dr=0,fr=()=>++dr,Zs=class{id;eventName;isCatchEmAll;priority;listener;listenerObject;listenerType;callAfterApply;isRemoved;refCount;constructor(s,e,t,i=null){this.id=fr(),this.eventName=s,this.isCatchEmAll=rs(s),this.listener=t,this.listenerObject=i,this.priority=e,this.listenerType=ur(t),this.callAfterApply=void 0,this.isRemoved=!1,this.refCount=1}isEqual(s,e=null){if(s===this)return!0;let t=typeof s;return t==="number"&&s===this.id?!0:e===null&&(t==="string"||t==="symbol")?s===Ce||s===this.eventName:this.listener===s&&this.listenerObject===e}apply(s,e,t){if(this.isRemoved)return;let{listener:i,listenerObject:r}=this;switch(this.listenerType){case Ys:es(r,i,e,t),this.callAfterApply&&this.callAfterApply();break;case ss:es(r,r[i],e,t),this.callAfterApply&&this.callAfterApply();break;case is:{let n=i[s];if(this.isCatchEmAll||this.eventName===s){if(typeof n=="function"){let o=n.apply(i,e);o!=null&&t?.(o)}else cr(s,i,e,t);this.callAfterApply&&this.callAfterApply()}break}}}},pr=(s,e)=>s.priority!==e.priority?e.priority-s.priority:s.id-e.id,gr=(s,e)=>{let t=0,i=s.length;for(;t<i;){let r=t+i>>>1;pr(e,s[r])<0?i=r:t=r+1}return t},Gs=s=>s?.slice(0),qs=(s,e)=>{let t=s.indexOf(e);t>-1&&s.splice(t,1)},yr=s=>s===is||s===ss,ts=(s,e,t)=>{let i=s.findIndex(r=>r.isEqual(e,t));i>-1&&(s[i].isRemoved=!0,s.splice(i,1))},Xt=(s,e,t)=>{let i=[];for(let r of s)(e==null&&r.listenerObject===t||r.eventName===e&&r.listener===t)&&i.push(r);for(let r of i)ts(s,r,void 0)},Zt=s=>{s&&(s.forEach(e=>{e.isRemoved=!0}),s.length=0)},vr=(s,e)=>s.listenerType===e.listenerType?s.priority===e.priority&&s.eventName===e.eventName&&s.listenerObject===e.listenerObject&&s.listener===e.listener:!1,mr=(s,e)=>{if(yr(s.listenerType))return e.find(t=>vr(s,t))},br=(s,e)=>{let t=mr(s,e);return t?(t.refCount+=1,t):(e.splice(gr(e,s),0,s),s)},wr=class{namedListeners;catchEmAllListeners;getListenersForEventName=s=>{let e=this.namedListeners.get(s);return e||(e=[],this.namedListeners.set(s,e)),e};constructor(){this.namedListeners=new Map,this.catchEmAllListeners=[]}add(s){return br(s,s.isCatchEmAll?this.catchEmAllListeners:this.getListenersForEventName(s.eventName))}remove(s,e,t=!1){if(e==null&&Array.isArray(s)){s.forEach(i=>this.remove(i,null,t));return}if(s==null||e==null&&rs(s)){this.removeAllListeners();return}if(e==null&&Js(s)){this.removeByEventName(s);return}if(s instanceof Zs){this.removeByEventListener(s);return}if(t){this.removeByEventNameAndListenerObject(s,e);return}this.removeByListener(s,e)}removeByEventName(s){Zt(this.namedListeners.get(s)),this.namedListeners.delete(s)}removeByEventListener(s){s.isRemoved||(s.refCount-=1,!(s.refCount>=1)&&(s.isRemoved=!0,this.namedListeners.forEach((e,t)=>{qs(e,s),e.length===0&&this.namedListeners.delete(t)}),qs(this.catchEmAllListeners,s)))}removeByEventNameAndListenerObject(s,e){this.namedListeners.forEach((t,i)=>{Xt(t,s,e),t.length===0&&this.namedListeners.delete(i)})}removeByListener(s,e){let t=typeof s=="object";this.namedListeners.forEach((i,r)=>{ts(i,s,e),t&&Xt(i,void 0,s),i.length===0&&this.namedListeners.delete(r)}),ts(this.catchEmAllListeners,s,e),t&&Xt(this.catchEmAllListeners,void 0,s)}removeAllListeners(){this.namedListeners.forEach(s=>Zt(s)),this.namedListeners.clear(),Zt(this.catchEmAllListeners)}forEach(s,e){let t=Gs(this.catchEmAllListeners),i=Gs(this.namedListeners.get(s));if(s===Ce||!i||i.length===0)t.forEach(e);else if(t.length===0)i.forEach(e);else{let r=i.length,n=t.length,o=0,a=0;for(;o<r||a<n;){if(o<r){let f=i[o];if(a>=n||f.priority>=t[a].priority){e(f),++o;continue}}a<n&&(e(t[a]),++a)}}}getSubscriptionCount(){let s=this.catchEmAllListeners.length;for(let e of this.namedListeners.values())s+=e.length;return s}},ue=s=>!!(s&&s[Q]);function qe(s){if(ue(s))return s;let e=new wr,t=new ns;return hr(s,Q,{keeper:t,store:e}),s}var K={Max:Number.POSITIVE_INFINITY,Critical:1e9,High:1e6,Normal:0,Low:-1e4,Min:Number.NEGATIVE_INFINITY,AAA:1e9,BB:1e6,C:1e3,Default:0},Er=(s,e,t,i,r,n,o)=>{let a=s.add(new Zs(t,i,r,n));return e.replayTo(t,a,o),a},ei=(s,e,t,i)=>{let r=t.length,n=typeof t[0],o,a,f,m;if(r>=2&&r<=3&&n==="number"?(o=Ce,[a,f,m]=t):r>=3&&r<=4&&typeof t[1]=="number"?[o,a,f,m]=t:(a=K.Default,n==="string"||n==="symbol"||Array.isArray(t[0])?[o,f,m]=t:(o=Ce,[f,m]=t)),!f)throw Xs&&ar("called with insufficient arguments!",t),new Error("subscribeTo() called with insufficient arguments");let P=c=>D=>Er(s,e,D,c,f,m,i);return Array.isArray(o)?o.map(c=>Array.isArray(c)?P(c[1])(c[0]):P(a)(c)):P(a)(o)},Cr=(s,e,t)=>{let i=[],r=ei(s,e,t,i);return ns.publish(i),r},Sr=(s,e,t)=>{let i=[];return{listeners:ei(s,e,t,i),publishRetained:()=>ns.publish(i)}},Hs=s=>e=>{e.callAfterApply=()=>{s?.()}},ti=(s,e)=>Object.assign(()=>A(s,e),Array.isArray(e)?{listeners:e}:{listener:e}),Qs=(s,e,t,i)=>{if(e===Ce)throw new Error("emit() must be called with a concrete event name \u2014 '*' is reserved for subscribing to all events and cannot be emitted");let{store:r,keeper:n}=s[Q];r.forEach(e,o=>o.apply(e,t,i)),n.retain(e,t)},si=(s,e,t,i)=>{Array.isArray(e)?e.forEach(r=>Qs(s,r,t,i)):Qs(s,e,t,i)},Ks=(s,e,t,i)=>{if(e===Ce)throw new Error("emit() must be called with a concrete event name \u2014 '*' is reserved for subscribing to all events and cannot be emitted");let r=s,n=r[e];if(typeof n=="function"){let a=n.apply(s,t);a!=null&&i?.(a);return}let o=r.emit;if(typeof o=="function"){let a=o.apply(s,[e,...t]);a!=null&&i?.(a)}},ii=(s,e,t,i)=>{Array.isArray(e)?e.forEach(r=>Ks(s,r,t,i)):Ks(s,e,t,i)},ri=s=>s!=null&&typeof s=="object";function b(s,...e){let t=qe(s),{store:i,keeper:r}=t[Q];return ti(t,Cr(i,r,e))}function C(s,...e){let t=qe(s),{store:i,keeper:r}=t[Q],{listeners:n,publishRetained:o}=Sr(i,r,e),a=ti(t,n),f=!1,m=()=>{f||(a(),f=!0)};return Array.isArray(n)?n.forEach(Hs(m)):Hs(m)(n),o(),m}function St(s,e){return new Promise(t=>{C(s,e,t)})}function A(s,e,t){if(!ue(s))return;let{store:i,keeper:r}=s[Q],n=typeof e,o=t!=null&&(n==="string"||n==="symbol");i.remove(e,t,o),Array.isArray(e)?r.remove(e.filter(a=>typeof a=="string")):Js(e)&&r.remove(e)}function g(s,e,...t){ue(s)?si(s,e,t):ri(s)&&ii(s,e,t)}function kr(s,e,...t){let i=[],r=n=>{i.push(n)};return ue(s)?si(s,e,t,r):ri(s)&&ii(s,e,t,r),i=i.map(n=>Array.isArray(n)?Promise.all(n):Promise.resolve(n)),i.length>0?Promise.all(i):Promise.resolve()}function Y(s,e){let t=qe(s),{keeper:i}=t[Q];i.add(e)}function de(s,e){if(!ue(s))throw new Error("object is not eventized");let{keeper:t}=s[Q];t.clear(e)}function Ar(s,e){if(!ue(s))throw new Error("object is not eventized");let{keeper:t}=s[Q];t.remove(e)}var Pr=b,Tr=C,xr=A,Or=g,Rr=kr,Mr=St,Lr=Y,Dr=de,Nr=Ar,T=(()=>{let s=(e={})=>qe(e);return s.inject=(e={})=>(e=qe(e),Object.assign(e,{on:(...t)=>Pr(e,...t),once:(...t)=>Tr(e,...t),onceAsync:t=>Mr(e,t),off:(t,i)=>xr(e,t,i),emit:(t,...i)=>Or(e,t,...i),emitAsync:(t,...i)=>Rr(e,t,...i),retain:t=>Lr(e,t),retainClear:t=>Dr(e,t),unretain:t=>Nr(e,t)}),e),s.is=ue,s})();var os=s=>ue(s)?s[Q]?.store?.getSubscriptionCount()??0:0;var J=Symbol.for("signal"),De=Symbol.for("effect"),ni=Symbol.for("destroySignal"),oi=Symbol.for("createEffect"),_r=Symbol.for("destroyEffect"),_e="value",us="mute",ds="unmute",pe="destroy",Wr="off",Qe=Symbol.for("recall"),Ke=T(),fe=T(),Se=T(),ci=T(),ke=class{static current;delayedEffects=[];batch(e,t){let i=this.delayedEffects.length;for(let r=0;r<i;r++){let[n,o]=this.delayedEffects[r];if(!(n>t)){if(n===t){o.add(e);return}this.delayedEffects.splice(r,0,[t,new Set([e])]);return}}this.delayedEffects.push([t,new Set([e])])}flush(){this.run(),this.delayedEffects.length=0}run(){let e=new Set,t=[];try{t.push(b(Se,(i,r)=>{r===Qe&&e.add(i)}),b(ci,i=>{e.add(i)}));for(let[,i]of this.delayedEffects)for(let r of i)e.has(r)||g(Se,r,r,Qe)}finally{for(let i of t)i()}}},ui=()=>ke.current;function W(s){let e=ke.current;e?e=void 0:e=ke.current=new ke;try{s()}finally{e&&(ke.current=void 0,e.run())}}var as=0;function xt(s){as++;try{s()}finally{as--}}function fs(){return as>0}var kt=class{[De];constructor(e){this[De]=e,C(e,pe,()=>{this[De]=void 0})}run=()=>this[De]?.run();destroy=()=>{this[De]?.destroy(),this[De]=void 0}},hs=[],di=()=>hs.at(-1),$r=(s,e)=>{hs.push(s);try{return e()}finally{hs.pop()}};var Ne=new WeakMap,He=new Set,ai=new FinalizationRegistry(s=>{He.has(s)&&s.clear()});var re=class s{#e=new Set;#t=new Set;#s=new Map;#i=new WeakMap;#r=new Map;#n=new Set;#a=new Set;#o;#h;static get(e){if(e!=null)return e instanceof s?e:Ne.get(e)}static findOrCreate(e){if(e==null)throw new Error("Cannot create a group with a null object");return new s(e)}static destroy(e){console.warn("SignalGroup.destroy(obj) is deprecated. Use SignalGroup.delete(obj) instead."),s.delete(e)}static delete(e){Ne.get(e)?.clear()}static clear(){for(let e of[...He])e.clear();He.clear()}constructor(e){if(e!=null&&e instanceof s)return e;if(e??=this,Ne.has(e))return Ne.get(e);this.#h=new WeakRef(e),Ne.set(e,this),He.add(this),e!==this&&ai.register(e,this,this),T(this)}attachGroup(e){if(e===this)throw new Error("Cannot attach a group to itself");return this.#e.add(e),e.#o&&e.#o!==this&&e.#o.#e.delete(e),e.#o=this,e}detachGroup(e){return e!==this&&this.#e.has(e)&&(this.#e.delete(e),e.#o=void 0),e}attachSignal(e){let t=R(e);if(t?.destroyed)throw new Error("Cannot attach a destroyed signal to a group");return t&&this.#t.add(t),e}attachSignalByName(e,t){if(t){this.attachSignal(t);let i=R(t);this.#s.set(e,i);let r=this.#r.get(e);r?r.add(i):this.#r.set(e,new Set([i])),this.#i.has(i)?this.#i.get(i).add(e):this.#i.set(i,new Set([e]))}else this.#s.delete(e);return t}hasSignal(e){return this.#s.has(e)||!!this.#o?.hasSignal(e)}signal(e){return this.#s.get(e)?.object??this.#o?.signal(e)}detachSignal(e){let t=R(e);if(t&&(this.#t.delete(t),this.#i.has(t))){let i=this.#i.get(t);for(let r of i){let n=this.#r.get(r);if(n){if(n.delete(t),n.size===0)this.#s.delete(r),this.#r.delete(r);else if(this.#s.get(r)===t){let o;for(let a of n)o=a;this.#s.set(r,o)}}}i.clear(),this.#i.delete(t)}return e}attachEffect(e){return this.#n.add(e),e}runEffects(){for(let e of this.#n)e.run();for(let e of this.#e)e.runEffects()}attachLink(e){if(e?.isDestroyed)throw new Error("Cannot attach a destroyed link to a group");return e&&this.#a.add(e),e}detachLink(e){return e&&this.#a.delete(e),e}destroy(){console.warn("SignalGroup#destroy is deprecated. Use SignalGroup#clear instead."),this.clear()}off(){for(let e of this.#e)e.off();for(let e of this.#n)e.destroy();this.#n.clear();for(let e of this.#a)e.destroy();this.#a.clear();for(let e of this.#t)e.destroyed||g(fe,e.id,e.id,{detach:!0});g(this,Wr,this)}clear(){g(this,pe,this),A(this);for(let e of this.#e)e.clear();for(let e of this.#n)e.destroy();for(let e of this.#t)M(e);for(let e of this.#a)e.destroy();if(this.#e.clear(),this.#t.clear(),this.#s.clear(),this.#r.clear(),this.#n.clear(),this.#a.clear(),this.#o?.detachGroup(this),this.#h){let e=this.#h.deref();e!==void 0&&Ne.delete(e),this.#h=void 0}He.delete(this),ai.unregister(this)}},At=class{#e;#t;constructor(e="id",t=1){this.#e=e,this.#t=t}make(){return Symbol(`${this.#e}${this.#t++}`)}},Fr=s=>s!=null&&typeof s.then=="function",ls=class s{static idGen=new At("ef");static count=0;static maxDepth=256;id;callback;#e;#t=new Set;#s=new Set;#i=new Map;#r=new Set;childEffects=[];curChildEffectSlot=0;autorun=!0;shouldRun=!0;priority;#n;#a=!1;#o=0;constructor(e,t){T(this),this.callback=e;let i;t?.attach!=null&&(i=re.findOrCreate(t.attach),i.attachEffect(this)),this.autorun=t?.autorun??!0,this.#n=t?.dependencies?t.dependencies.map(r=>{switch(typeof r){case"string":case"symbol":return i.signal(r);default:return r}}):void 0,this.id=s.idGen.make(),this.priority=t?.priority??0,b(Se,this.id,Qe,this),++s.count}hasStaticDeps(){return this.#n!=null&&this.#n.length>0}saveSignalsFromDeps(){for(let e of this.#n)this.whenSignalIsRead(R(e).id)}static createEffect(e,t,i){let r=Array.isArray(t)?t:void 0,n=r?i??{dependencies:r}:t;n&&r&&(n.dependencies=r);let o,a=di();return a!=null?(o=a.getCurrentChildEffect(),o==null&&(o=new s(e,n),a.attachChildEffect(o),g(Se,oi,o)),a.curChildEffectSlot++):(o=new s(e,n),g(Se,oi,o)),o.hasStaticDeps()?o.saveSignalsFromDeps():o.autorun&&o.run(),new kt(o)}getCurrentChildEffect(){return this.childEffects[this.curChildEffectSlot]}attachChildEffect(e){this.childEffects.push(e)}run=()=>{if(this.#a||!this.shouldRun)return;let e=ui();if(e){e.batch(this.id,this.priority);return}if(this.#o>=s.maxDepth)throw new Error(`[signalize] Effect ${this.id.toString()} exceeded maxDepth=${s.maxDepth}: an effect callback recursively re-triggered itself (likely by writing a signal it depends on). Break the cycle, or raise EffectImpl.maxDepth if the recursion is intentional.`);this.#o++;try{if(this.runCleanupCallback(),this.destroyChildEffects(),this.curChildEffectSlot=0,this.shouldRun=!1,g(ci,this.id,this.id),this.hasStaticDeps())this.#e=this.callback();else{this.#s.clear();for(let t of this.#t)this.#s.add(t);this.#e=$r(this,this.callback),this.cleanupLostSignals(),this.#r.clear()}}finally{this.#o--}};[Qe](){this.shouldRun=!0,this.autorun&&this.run()}whenSignalIsRead(e){this.#s.delete(e),this.#t.has(e)||(this.#t.add(e),this.#i.set(e,[b(Ke,e,this.priority,Qe,this),C(fe,e,ni,this)]))}[ni](e,t){if(this.#t.has(e)){if(t?.detach){this.unsubscribeSignal(e),this.#t.delete(e),this.#r.delete(e),this.#s.delete(e),this.#t.size===0&&this.destroy();return}this.#r.has(e)||(this.#r.add(e),this.unsubscribeSignal(e),this.#r.size===this.#t.size&&this.destroy())}}cleanupLostSignals(){for(let e of this.#s)this.unsubscribeSignal(e),this.#t.delete(e)}destroyChildEffects(){for(let e of this.childEffects)e.destroy();this.childEffects.length=0}unsubscribeSignal(e){this.#i.has(e)&&(this.#i.get(e).forEach(t=>{t()}),this.#i.delete(e))}runCleanupCallback(){if(this.#e!=null){let e=this.#e;this.#e=void 0,Fr(e)?Promise.resolve(e).then(t=>{typeof t=="function"&&t()}):e()}}destroy=()=>{this.#a||(g(this,pe,this),A(this),g(Se,_r,this),this.runCleanupCallback(),this.destroyChildEffects(),A(Ke,this),A(Se,this),A(fe,this),this.#a=!0,this.#t.clear(),this.#s.clear(),this.#i.clear(),this.#r.clear(),--s.count)}},S=ls.createEffect;var Ye=new WeakMap,jr=s=>{let e=Ye.get(s);return e||(e={},Ye.set(s,e)),e},G=(s,e)=>Ye.get(s)?.signals?.get(e);var fi=(s,e,t)=>{let i=jr(s);i.signals??=new Map,i.signals.set(e,t)};function Je(...s){for(let e of s)if(Ye.has(e)){let t=Ye.get(e);if(t.signals){for(let i of t.signals.values())M(i);t.signals.clear(),t.signals=void 0}}}function pi(s){let e=R(Ae(s)?s:G(...s));e!=null&&!e.muted&&!e.destroyed&&cs(e.id,e.value,{touch:!0})}function We(s){return Ae(s)?R(s)?.value:R(G(...s))?.value}var Pt=class{[J];constructor(e){this[J]=e}get get(){return this[J].reader}get set(){return this[J].writer}get value(){return We(this.get)}set value(e){this.set(e)}onChange(e){let{destroy:t}=S(()=>e(this.value),[this.get]);return t}get muted(){return this[J].muted}set muted(e){this[J].muted=e}touch(){pi(this)}destroy(){M(this)}},zr=new At("si"),hi=!1;function Ir(){hi||(hi=!0,console.warn("signalReader(callback) is deprecated and will be removed in a future release. Use Signal.onChange(callback) instead \u2014 it returns an unsubscribe function for proper cleanup."))}function li(s){fs()||di()?.whenSignalIsRead(s)}function cs(s,e,t){fs()||g(Ke,s,e,t)}var Ae=s=>s!=null&&s[J]!=null,Ur=s=>{let e=t=>(s.destroyed||s.beforeRead?.(),t?(Ir(),S(()=>(s.destroyed||li(s.id),t(s.value)),[e])):s.destroyed||li(s.id),s.value);return Object.defineProperty(e,J,{value:s}),e},Tt=class s{static instanceCount=0;id;lazy;get[J](){return this}compare;beforeRead;muted=!1;destroyed=!1;#e=void 0;get value(){return this.lazy&&(this.#e=this.valueFn(),this.valueFn=void 0,this.lazy=!1),this.#e}set value(e){this.#e=e}valueFn;reader;writer=(e,t)=>{let i=t?.lazy??!1,n=t?.compare??this.compare??((a,f)=>a===f);if((i!==this.lazy||i&&e!==this.valueFn||!i&&!n(e,this.#e))&&(i?(this.#e=void 0,this.valueFn=e,this.lazy=!0):(this.#e=e,this.valueFn=void 0,this.lazy=!1),!this.muted&&!this.destroyed)){cs(this.id,this.#e);return}(t?.touch??!1)&&!this.muted&&!this.destroyed&&cs(this.id,this.#e,{touch:!0})};object;constructor(e,t){this.id=zr.make(),++s.instanceCount,this.lazy=e,this.lazy?(this.value=void 0,this.valueFn=t):(this.value=t,this.valueFn=void 0),this.reader=Ur(this),this.object=new Pt(this)}},R=s=>s?.[J];function y(s=void 0,e){let t;if(Ae(s))t=R(s);else{let i=e?.lazy??!1;t=new Tt(i,s),t.beforeRead=e?.beforeRead,t.compare=e?.compare}return e?.attach!=null&&re.findOrCreate(e.attach).attachSignal(t),t.object}var M=(...s)=>{for(let e of s){let t=R(e);t!=null&&!t.destroyed&&(t.destroyed=!0,t.beforeRead=void 0,--Tt.instanceCount,g(fe,t.id,t.id))}};function Ot(s,e){let t=y(),i=e?.attach!=null?re.findOrCreate(e.attach):void 0;i!=null&&(e?.name?i.attachSignalByName(e.name,t):i.attachSignal(t));let r=S(()=>{W(()=>{t.set(s())})},{autorun:!(e?.lazy??!1),priority:e?.priority??K.C,attach:i}),n=R(t);return n.beforeRead=r.run,C(fe,n.id,r.destroy),t.get}var Mt=class{#e=!1;#t;source;lastValue;isDestroyed=!1;constructor(e){T(this),this.source=R(e),this.#t=b(Ke,this.source.id,(t,i)=>{!this.#e&&!this.isDestroyed&&(i?.touch===!0?this.touch():this.write())}),C(fe,this.source.id,()=>this.destroy())}attach(e){let t=re.findOrCreate(e);return t.attachLink(this),C(this,pe,()=>{t.detachLink(this)}),t}nextValue(){return new Promise((e,t)=>{let i=[],r=()=>i.forEach(n=>{n()});i.push(C(this,_e,n=>{r(),e(n)}),C(this,pe,()=>{r(),t()}))})}async*asyncValues(e){Y(this,_e);try{let t=0;for(;!this.isDestroyed;)try{let i=await this.nextValue();if(e?.(i,t++))break;yield i}catch{break}}finally{de(this,_e)}}destroy(){this.isDestroyed||(this.#t?.(),this.#t=void 0,g(this,pe,this),de(this,_e),A(this),this.lastValue=void 0,this.isDestroyed=!0,Object.freeze(this))}get isMuted(){return this.#e}mute(){return!this.isDestroyed&&!this.#e&&(this.#e=!0,g(this,us,this)),this}unmute(){return!this.isDestroyed&&this.#e&&(this.#e=!1,g(this,ds,this)),this}toggleMute(){return this.isDestroyed||(this.#e=!this.#e,g(this,this.#e?us:ds,this)),this.#e}updateValue(e){if(!this.#e&&!this.isDestroyed){let{value:t}=this.source;e(t),g(this,_e,t),this.lastValue=t}}},ps=class extends Mt{target;constructor(e,t){super(e),this.target=R(t),C(fe,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)})}},gs=class extends Mt{target;constructor(e,t){super(e),this.target=t,this.touch()}touch(){return this.updateValue(e=>{this.target(e)}),this}write(){this.updateValue(e=>{this.target(e)})}},Rt=new Map;function $(s,e,t){let i=R(s),r=R(e),n=r??e,o;if(Rt.has(i)){if(o=Rt.get(i),o.has(n))return o.get(n)}else o=new Map,Rt.set(i,o);let a=r!=null?new ps(s,r):new gs(s,e),f=t?.attach;return f&&a.attach(f),o.set(n,a),C(a,pe,()=>{o.delete(n),o.size===0&&Rt.delete(i)}),a}var Lt=class s{static fromProps(e,t){let i=new s,r=t?t.map(n=>[n,e[n]]):Object.entries(e);for(let[n,o]of r)i.#e.set(n,y(o));return i}#e=new Map;keys(){return this.#e.keys()}signals(){return this.#e.values()}entries(){return this.#e.entries()}clear(){for(let e of this.#e.values())e.destroy();this.#e.clear()}has(e){return this.#e.has(e)}get(e){if(!this.#e.has(e)){let t=y();return this.#e.set(e,t),t}return this.#e.get(e)}update(e){e.size&&W(()=>{for(let[t,i]of e.entries())this.get(t).set(i)})}updateFromProps(e,t){W(()=>{let i=t?t.map(r=>[r,e[r]]):Object.entries(e);for(let[r,n]of i)this.get(r).set(n)})}};var ne=(s=>(s[s.StructuralChanges=1]="StructuralChanges",s[s.ContentUpdates=2]="ContentUpdates",s[s.Removal=3]="Removal",s))(ne||{}),E=(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",s))(E||{}),Pe=Symbol.for("ShadowEntsGlobalNS"),F="#void",gi="contextLost",yi="configure",vi="changeTrail",mi="destroy",bi="loaded",wi="appliedChangeTrail",Ei="importedModule",Ci="destroyed",$e="messageToView",Si=6e4,ki=6e4,Ai=5e3,Pi=5e3,ys="shadowObjects";function Ti(s,e){s.indexOf(e)===-1&&s.push(e)}function vs(s,e){let t=s.indexOf(e);t!==-1&&s.splice(t,1),s.push(e)}function oe(s,e){let t=s.indexOf(e);t!==-1&&s.splice(t,1)}var Te=s=>typeof s=="string"?s.trim()||Pe:typeof s=="symbol"?s:Pe;var Xe="#root",Ze=class{#e;get uuid(){return this.#e}#t=0;constructor(e){this.#e=e}#s=!0;#i=0;#r=0;hasChanges(){return this.#t>0}get isNew(){return this.#s}get isCreated(){return this.#i>0&&this.#i>this.#r}get isDestroyed(){return this.#r>0&&this.#r>=this.#i}#n=F;#a;#o=0;#h=!1;#l;#u;#c;create(e=F,t,i=0,r=!1){this.#t++,this.#i++,this.#l=e,this.#u=t??Xe,this.#c=i||void 0,this.#h=r}destroy(){this.#r++,this.#t++}clear(){this.#t=0,this.#s=!1,this.#l=void 0,this.#u=void 0,this.#c=void 0,this.#p.clear(),this.#g.length=0,this.#d.length=0,this.#f.clear()}changeToken(e){e??=F,e===this.#n?this.#l=this.#s?e:void 0:(this.#l=e,this.#t++)}setParent(e){e===this.#a?this.#u=void 0:(this.#u=e??Xe,this.#t++)}changeOrder(e){e===this.#o?this.#c=void 0:(this.#c=e,this.#t++)}#y=new Map;#p=new Map;#g=[];changeProperty(e,t,i){let r=this.#y.get(e),n=i==null&&t!==r||i!=null&&!i(t,r);return n?(this.#p.set(e,t),vs(this.#g,e),this.#t++):(this.#p.delete(e),oe(this.#g,e)),n}removeProperty(e){let t=this.#y.has(e);this.#p.has(e)?(this.#p.delete(e),t||oe(this.#g,e)):t&&(vs(this.#g,e),this.#t++)}#d=[];#f=new Set;createEvent(e,t,i){this.#d.push({type:e,data:t});for(let r of i??[])this.#f.add(r);this.#t++}transferEventsTo(e){this.#d.length>0&&(e.#d.push(...this.#d),this.#d.length=0),this.#f.size>0&&(e.#f=new Set([...e.#f,...this.#f]),this.#f.clear())}buildChangeTrail(e,t){let{isNew:i,isCreated:r,isDestroyed:n}=this;if(!(i&&n))switch(t){case ne.StructuralChanges:i?e.push(this.makeCreateEntityChange()):n||(this.#u!==void 0&&!(this.#u===Xe&&this.#a===void 0)?e.push(this.makeSetParentChange()):this.#c!==void 0&&this.#c!==this.#o&&e.push(this.makeUpdateOrderChange()),this.#l!==void 0&&this.#l!==this.#n&&e.push(this.makeChangeToken()));break;case ne.ContentUpdates:!i&&r&&this.#g.length>0&&e.push(this.makeChangePropertyChange()),this.#d.length>0&&e.push(this.makeEvents());break;case ne.Removal:n&&e.push(this.makeDestroyEntityChange());break}}makeEvents(){let e={type:E.SendEvents,uuid:this.#e,events:this.#d.slice(0)};return this.#f.size>0&&(e.transferables=Array.from(this.#f)),e}makeCreateEntityChange(){let e=this.#l??this.#n,t={type:E.CreateEntities,uuid:this.#e,token:e};if(this.#n=e,this.#u!==void 0){let i=this.#u===Xe?void 0:this.#u;this.#a=i,i!==void 0&&(t.parentUuid=i)}if(this.#p.size>0){t.properties=Array.from(this.#p.entries()).filter(([,i])=>i!==void 0);for(let[i,r]of t.properties)this.#y.set(i,r)}return this.#c!==void 0&&this.#c!==this.#o&&(t.order=this.#o=this.#c),this.#h&&(t.autoDestructionOnParentRemoval=!0),t}makeDestroyEntityChange(){return{type:E.DestroyEntities,uuid:this.#e}}makeSetParentChange(){this.#a=this.#u===Xe?void 0:this.#u;let e={type:E.SetParent,uuid:this.#e,parentUuid:this.#a};return this.#c!==void 0&&this.#c!==this.#o&&(e.order=this.#o=this.#c),e}makeUpdateOrderChange(){return this.#o=this.#c??0,{type:E.UpdateOrder,uuid:this.#e,order:this.#o}}makeChangeToken(){return this.#n=this.#l??F,{type:E.ChangeToken,uuid:this.#e,token:this.#n}}makeChangePropertyChange(){let e=this.#g.map(t=>{if(this.#p.has(t)){let i=this.#p.get(t);return i===void 0?this.#y.delete(t):this.#y.set(t,i),[t,i]}else return this.#y.delete(t),[t,void 0]});return{type:E.ChangeProperties,uuid:this.#e,properties:e}}};var xi=s=>{if(!(s===void 0||s.length===0))return s.filter(e=>e.length===1||e[1]!==void 0)},ms=(s,e)=>{if(s===e||e===void 0)return s;if(s===void 0)return xi(e);for(let[t,i]of e){let r=s.find(([n])=>n===t);r===void 0?s.push([t,i]):r[1]=i}return xi(s)};var Dt=class{#e=new Map;get[Symbol.iterator](){return this.#e.entries.bind(this.#e)}clear(){this.#e.clear()}isEmpty(){return this.#e.size===0}hasComponentState(e){return this.#e.has(e)}getComponentState(e){return this.#e.get(e)}write(e){for(let t of e)if(t.type===E.CreateEntities)this.createEntity(t);else if(this.#e.has(t.uuid))switch(t.type){case E.DestroyEntities:this.destroyEntity(t);break;case E.SetParent:this.setParent(t);break;case E.UpdateOrder:this.updateOrder(t);break;case E.ChangeToken:this.changeToken(t);break;case E.ChangeProperties:this.changeProperties(t);break}}changeProperties({uuid:e,properties:t}){let i=this.getComponentState(e);i.properties=ms(i.properties,t)}changeToken({uuid:e,token:t}){this.getComponentState(e).token=t||F}updateOrder({uuid:e,order:t}){this.getComponentState(e).order=t??0}setParent({uuid:e,parentUuid:t,order:i}){let r=this.getComponentState(e);r.parentUuid=t,i!==void 0&&(r.order=i)}destroyEntity({uuid:e}){this.#e.delete(e)}createEntity({uuid:e,token:t,parentUuid:i,order:r,properties:n,autoDestructionOnParentRemoval:o}){this.#e.set(e,{token:t||F,parentUuid:i,order:r??0,properties:ms(void 0,n),...o?{autoDestructionOnParentRemoval:!0}:{}})}};var et=class extends Error{constructor(e="the component context has been disposed"){super(e),this.name="ComponentContextDisposedError"}},I=class s{static{this.ReRequestParentRoots="re-request-parent-roots"}static getContextsMap(){return globalThis.__shadowEntsContexts==null&&(globalThis.__shadowEntsContexts=new Map),globalThis.__shadowEntsContexts}static get(e){let t=Te(e),i=s.getContextsMap();return i.has(t)?i.get(t):new s(t)}#e=new Map;#t=[];#s=!1;#i=new Dt;constructor(e=Pe){let t=Te(e),i=s.getContextsMap();if(i.has(t))return i.get(t);this.ns=t,i.set(t,this)}get isDisposed(){return this.#s}addComponent(e){if(this.#s)throw new et(`the view component ${e.uuid} cannot join the component context because it has been disposed`);let t=this.#e.get(e.uuid);if(t){if(t.component!==e)for(let i of t.children.slice(0))this.#e.get(i)?.component.removeFromParent();t.component=e,t.children=[]}else t={component:e,children:[],changes:new Ze(e.uuid),propIsEqual:void 0},this.#e.set(e.uuid,t);t.changes.create(e.token,e.parent?.uuid,e.order,e.autoDestructionOnParentRemoval),e.parent?(this.addToChildren(e.parent,e),t.changes.setParent(e.parent.uuid)):this.#o(e,this.#t),this.#h=void 0}hasComponent(e){return this.#e.has(e.uuid)}hasComponents(){return this.#e.size>0}isRootComponent(e){return this.#t.includes(e.uuid)}destroyComponent(e){if(this.hasComponent(e)){let t=this.#e.get(e.uuid);for(let i of t.children.slice(0))this.#e.get(i)?.component.removeFromParent();t.changes.destroy(),this.#h=void 0}}getChildren(e){return this.#e.get(e.uuid)?.children.map(t=>this.#e.get(t).component)??[]}removeFromParent(e,t){if(this.hasComponent(t)){let i=this.#e.get(e);if(i===void 0)return;let r=this.#e.get(t.uuid),n=r.children.indexOf(e);n!==-1&&(r.children.splice(n,1),i.changes.setParent(void 0)),this.#o(i.component,this.#t),this.#h=void 0}}moveToRoot(e){let t=this.#e.get(e);t&&(t.changes?.setParent(void 0),this.#o(t.component,this.#t)),this.#h=void 0}changeToken(e,t){this.#e.get(e.uuid)?.changes.changeToken(t)}isChildOf(e,t){return this.hasComponent(t)?this.#e.get(t.uuid).children.includes(e.uuid):!1}addToChildren(e,t){let i=this.#e.get(e.uuid);if(i)this.#o(t,i.children),this.#e.get(t.uuid)?.changes.setParent(e.uuid),oe(this.#t,t.uuid),this.#h=void 0;else throw new Error(`the view component ${e.uuid} cannot have a child added to it because the component do not exist!`)}removeSubTree(e){this.#r(e,new Set)}#r(e,t){if(t.has(e))return;t.add(e);let i=this.#e.get(e);if(i){for(let r of i.children.slice(0))this.#r(r,t);this.destroyComponent(i.component),this.#n(e)}}setProperty(e,t,i,r){let n=this.#e.get(e.uuid);return n!=null?(r!=null?(n.propIsEqual??=new Map,n.propIsEqual.set(t,r)):n.propIsEqual?.has(t)&&n.propIsEqual.delete(t),n.changes.changeProperty(t,i,r)):!1}removeProperty(e,t){this.#e.get(e.uuid)?.changes.removeProperty(t)}changeOrder(e){let t=this.#e.get(e.uuid);if(t===void 0)return;let i=e.parent?this.#e.get(e.parent.uuid):void 0;i!==void 0?(oe(i.children,e.uuid),this.#o(e,i.children)):e.parent==null&&(oe(this.#t,e.uuid),this.#o(e,this.#t)),t.changes.changeOrder(e.order),this.#h=void 0}traverseLevelOrderBFS(){return this.#l().map(e=>e.component)}dispatchShadowObjectsEvent(e,t,i,r){this.#e.get(e.uuid)?.changes.createEvent(t,i,r)}broadcastEvent(e,t=void 0){for(let i of this.traverseLevelOrderBFS())i.dispatchEvent(e,t,!1)}dispatchMessage(e,t,i=void 0,r=!1){this.#e.get(e)?.component.dispatchEvent(t,i,r)}dispatchReRequestParentRoots(){for(let e of this.#t)this.dispatchMessage(e,s.ReRequestParentRoots)}buildChangeTrails(e=!0){let t=[];if(!this.hasComponents())return t;let i=this.#a();for(let r of i)r.buildChangeTrail(t,ne.StructuralChanges);for(let r of i)r.buildChangeTrail(t,ne.ContentUpdates);for(let r of i)r.buildChangeTrail(t,ne.Removal),(r.isDestroyed||r.isNew&&!r.isCreated)&&this.#n(r.uuid),e&&r.clear();return this.#i.write(t),t}reCreateChanges(){if(!this.#i.isEmpty()){this.buildChangeTrails(!1);for(let[e,t]of this.#i){let i=this.#e.get(e);if(i){let r=new Ze(e);if(r.create(t.token,t.parentUuid,t.order,t.autoDestructionOnParentRemoval),t.properties)for(let[n,o]of t.properties)r.changeProperty(n,o,i.propIsEqual?.get(n));i.changes.transferEventsTo(r),i.changes.clear(),i.changes=r}}this.#i.clear(),this.broadcastEvent(gi)}}clear(){this.#h=void 0,this.#i.clear();for(let e of this.#t.slice(0))this.removeSubTree(e);if(this.#t.length!==0)throw new Error("component-context panic: #rootComponents is not empty!");if(this.#e.size!==0)throw new Error("component-context panic: #components is not empty!")}dispose(){if(this.#s)return;for(let{component:t}of Array.from(this.#e.values()))t.destroy();this.clear(),this.#s=!0;let e=s.getContextsMap();this.ns!=null&&e.get(this.ns)===this&&e.delete(this.ns)}#n(e){let t=this.#e.get(e);if(t===void 0)return;let i=t.component.parent?.uuid;if(i!==void 0){let r=this.#e.get(i);r!==void 0&&oe(r.children,e)}this.#e.delete(e),oe(this.#t,e),this.#h=void 0}#a(){return this.#l().filter(e=>e.changes.hasChanges()).map(e=>e.changes)}#o(e,t){if(t.includes(e.uuid))return;let{order:i}=e;for(let r=0;r<t.length;r++){let n=this.#e.get(t[r])?.component;if(n!==void 0&&i<n.order){t.splice(r,0,e.uuid);return}}t.push(e.uuid)}#h;#l(){if(this.#h)return this.#h;let e=new Map,t=(i,r)=>{let n=this.#e.get(i);if(n==null)return;let o=e.get(r);o?o.push(n):e.set(r,[n]);for(let a of n.children)t(a,r+1)};for(let i of this.#t)t(i,0);return this.#h=Array.from(e.entries()).sort((i,r)=>i[0]-r[0]).flatMap(([,i])=>i),this.#h}};function tt(s){return function(e,t){let i=s?.name||t.name,r=!!(s?.readAsValue??!1);return{get(){let n=G(this,i);if(n)return r?n.value:n.get()},set(n){G(this,i)?.set(n)},init(n){let o=y(n,s);return fi(this,i,o),re.findOrCreate(this).attachSignalByName(i,o),o.value}}}}var V="ConsoleLogger",U=`${V}Storage`,Vr=!!(globalThis.location?.host?.startsWith("localhost")??!1),it="localStorage"in globalThis,Nt=Symbol.for(V),Oi=!1,Ri=s=>{if(typeof s=="boolean")return s;switch(s.toLowerCase()){case"true":case"yes":case"on":return!0;default:return!1}},ws=s=>[it?V:void 0,...Array.isArray(s)?s:[s]].filter(Boolean).join(".");function bs(s,e,t){let i=ws(s),r=it?localStorage.getItem(i):globalThis[U]?.[i];return r==null?t:e?e(r):r}function st(s,e){it?localStorage.setItem(ws(s),e):(globalThis[U]==null&&(globalThis[U]={},console.debug(`${V}: Initialize`,{[U]:globalThis[U]})),globalThis[U][ws(s)]=e)}var N=class s{constructor(e){this.enable=!0,this.namespace=(e||"").trim()||V,Oi||(s.loadConfig(),Oi=!0);let t=[this.namespace,"enable"];this.enable=bs(t,Ri,this.enable),st(t,it?this.enable?"true":"false":this.enable)}static{this.sharedConfig={enable:Vr,debug:!1,info:!0,warn:!0,"styles.debug":"color: #111; background: #999; display: inline-block; padding: 0 0.25em; margin: 0; border-radius: 0.25em","styles.info":"color: #020; background: #8a8; display: inline-block; padding: 0 0.25em; margin: 0; border-radius: 0.25em","styles.warn":"color: #fa0; background: #a98; display: inline-block; padding: 0 0.25em; margin: 0; border-radius: 0.25em","styles.error":"color: #ff0; background: #a00; display: inline-block; padding: 0 0.25em; margin: 0; border-radius: 0.25em"}}static get isEnabled(){return s.sharedConfig.enable}static get isDebug(){return s.sharedConfig.enable&&s.sharedConfig.debug}static{this.sharedStyles={get debug(){return s.sharedConfig["styles.debug"]},set debug(e){s.sharedConfig["styles.debug"]=e},get info(){return s.sharedConfig["styles.info"]},set info(e){s.sharedConfig["styles.info"]=e},get warn(){return s.sharedConfig["styles.warn"]},set warn(e){s.sharedConfig["styles.warn"]=e},get error(){return s.sharedConfig["styles.error"]},set error(e){s.sharedConfig["styles.error"]=e}}}static loadConfig(){it?(["enable","debug","info","warn"].forEach(e=>{this.sharedConfig[e]=bs(e,Ri,this.sharedConfig[e])}),["debug","info","warn","error"].forEach(e=>{this.sharedStyles[e]=bs(["styles",e],void 0,this.sharedStyles[e])}),s.isDebug&&console.debug(`${V}: Load config from localStorage`,s.sharedConfig),globalThis[V]?.[Nt]||(globalThis[V]??={[Nt]:!0,get enable(){return s.sharedConfig.enable},set enable(e){s.sharedConfig.enable=e,st("enable",e?"true":"false")},get debug(){return s.sharedConfig.debug},set debug(e){s.sharedConfig.debug=e,st("debug",e?"true":"false")},get info(){return s.sharedConfig.info},set info(e){s.sharedConfig.info=e,st("info",e?"true":"false")},get warn(){return s.sharedConfig.warn},set warn(e){s.sharedConfig.warn=e,st("warn",e?"true":"false")}})):globalThis[U]?.[Nt]||(globalThis[U]={[Nt]:!0,...s.sharedConfig,...globalThis[U]},s.sharedConfig=globalThis[U],s.isDebug&&console.debug(`${V}: Load config from ${U}`,globalThis[U]))}get isEnabled(){return this.enable&&s.sharedConfig.enable}get isDebug(){return this.isEnabled&&s.sharedConfig.debug}get isInfo(){return this.isEnabled&&s.sharedConfig.info}get isWarn(){return this.isEnabled&&s.sharedConfig.warn}debug(...e){this.#e("debug",s.sharedStyles.debug,e)}info(...e){this.#e("info",s.sharedStyles.info,e)}warn(...e){this.#e("warn",s.sharedStyles.warn,e)}error(...e){this.#e("error",s.sharedStyles.error,e)}#e(e,t,i){console[e](`%c${this.namespace}`,t,...i)}};var Br=Object.create,ks=Object.defineProperty,Gr=Object.getOwnPropertyDescriptor,Li=(s,e)=>(e=Symbol[s])?e:Symbol.for("Symbol."+s),ze=s=>{throw TypeError(s)},qr=(s,e,t)=>e in s?ks(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,Mi=(s,e)=>ks(s,"name",{value:e,configurable:!0}),Hr=s=>[,,,Br(s?.[Li("metadata")]??null)],Di=["class","method","getter","setter","accessor","field","value","get","set"],rt=s=>s!==void 0&&typeof s!="function"?ze("Function expected"):s,Qr=(s,e,t,i,r)=>({kind:Di[s],name:e,metadata:i,addInitializer:n=>t._?ze("Already initialized"):r.push(rt(n||null))}),Ni=(s,e)=>qr(e,Li("metadata"),s[3]),_t=(s,e,t,i)=>{for(var r=0,n=s[e>>1],o=n&&n.length;r<o;r++)e&1?n[r].call(t):i=n[r].call(t,i);return i},_i=(s,e,t,i,r,n)=>{var o,a,f,m,P,c=e&7,D=!!(e&8),w=!!(e&16),O=c>3?s.length+1:c?D?1:2:0,le=Di[c+5],u=c>3&&(s[O-1]=[]),l=s[O]||(s[O]=[]),h=c&&(!w&&!D&&(r=r.prototype),c<5&&(c>3||!w)&&Gr(c<4?r:{get[t](){return v(this,n)},set[t](d){return k(this,n,d)}},t));c?w&&c<4&&Mi(n,(c>2?"set ":c>1?"get ":"")+t):Mi(r,t);for(var p=i.length-1;p>=0;p--)m=Qr(c,t,f={},s[3],l),c&&(m.static=D,m.private=w,P=m.access={has:w?d=>Kr(r,d):d=>t in d},c^3&&(P.get=w?d=>(c^1?v:xe)(d,r,c^4?n:h.get):d=>d[t]),c>2&&(P.set=w?(d,_)=>k(d,r,_,c^4?n:h.set):(d,_)=>d[t]=_)),a=(0,i[p])(c?c<4?w?n:h[le]:c>4?void 0:{get:h.get,set:h.set}:r,m),f._=1,c^4||a===void 0?rt(a)&&(c>4?u.unshift(a):c?w?n=a:h[le]=a:r=a):typeof a!="object"||a===null?ze("Object expected"):(rt(o=a.get)&&(h.get=o),rt(o=a.set)&&(h.set=o),rt(o=a.init)&&u.unshift(o));return c||Ni(s,r),h&&ks(r,t,h),w?c^4?n:h:r},As=(s,e,t)=>e.has(s)||ze("Cannot "+t),Kr=(s,e)=>Object(e)!==e?ze('Cannot use the "in" operator on this value'):s.has(e),v=(s,e,t)=>(As(s,e,"read from private field"),t?t.call(s):e.get(s)),j=(s,e,t)=>e.has(s)?ze("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,t),k=(s,e,t,i)=>(As(s,e,"write to private field"),i?i.call(s,t):e.set(s,t),t),xe=(s,e,t)=>(As(s,e,"access private method"),t),Wi,$i,L,X,Oe,Re,je,ae,ve,Ps,Ts,Z,Fe,Wt,ge,Es,Cs,Ss,Fi,ji,me=class extends Error{constructor(e="the shadow environment has been destroyed"){super(e),this.name="ShadowEnvDestroyedError"}};$i=[tt()],Wi=[tt()];var ee=class ye{constructor(){j(this,ge),j(this,L),j(this,X),j(this,Oe,!1),j(this,Re,!1),j(this,je,!1),j(this,ae),this.logger=new N("ShadowEnv"),this.ns$=y(),j(this,Ps,_t(ve,8,this,!1)),_t(ve,11,this),j(this,Ts,_t(ve,12,this,!1)),_t(ve,15,this),j(this,Z,!1),j(this,Fe),j(this,Wt),this.ready=async()=>{if(v(this,Z))throw new me;return this.isReady?this:Promise.race([St(this,ye.ContextCreated),xe(this,ge,Es).call(this)])},j(this,Cs,()=>{v(this,Oe)&&xe(this,ge,Ss).call(this)});let e=this;Y(e,ye.ContextCreated),b(e,ye.ContextLost,K.AAA,()=>{de(e,ye.ContextCreated)}),S(()=>{if(this.viewReady&&this.proxyReady)return this.view.reCreateChanges(),g(e,ye.ContextCreated,e),v(this,Re)&&(k(this,Re,!1),xe(this,ge,Ss).call(this)),()=>{g(e,ye.ContextLost,e)}},[G(this,"viewReady"),G(this,"proxyReady")])}static get(e){if(e!=null)return globalThis.__shadowEnvs?.get(e)}get isDestroyed(){return v(this,Z)}get view(){return v(this,L)}set view(e){e!==v(this,L)&&(v(this,L)?.ns&&globalThis.__shadowEnvs&&globalThis.__shadowEnvs.delete(v(this,L).ns),k(this,L,e??void 0),v(this,L)?.ns&&(globalThis.__shadowEnvs??=new Map,globalThis.__shadowEnvs.has(v(this,L).ns)&&globalThis.__shadowEnvs.get(v(this,L).ns)!==this&&this.logger.isWarn&&this.logger.warn("overwrite a namespace already in use",v(this,L).ns,globalThis.__shadowEnvs.get(v(this,L).ns)),globalThis.__shadowEnvs.set(v(this,L).ns,this)),this.viewReady=!!e)}get envProxy(){return v(this,X)}set envProxy(e){if(e!==v(this,X)){let t=v(this,X);k(this,X,e??void 0),v(this,X)&&(v(this,X).onMessageToView=xe(this,ge,Fi).bind(this),v(this,X).onProxyFailed=xe(this,ge,ji).bind(this)),t&&t.destroy(),this.proxyReady=!1,e?.start().then(()=>{this.proxyReady=!0}).catch(i=>{this.logger.error("failed to start envProxy",i),this.proxyReady=!1})}}get isReady(){return!!(v(this,L)&&v(this,X)&&this.proxyReady&&!this.isDestroyed)}sync(){if(!v(this,Z)){if(!this.isReady){k(this,Re,!0);return}v(this,Oe)||(k(this,Oe,!0),queueMicrotask(v(this,Cs)))}}syncWait(){return v(this,Z)?Promise.reject(new me):(k(this,je,!0),this.sync(),v(this,ae)?v(this,ae):(k(this,ae,Promise.race([St(this,ye.AfterSync),xe(this,ge,Es).call(this)]).then(e=>(k(this,ae,void 0),e),e=>{throw k(this,ae,void 0),e})),v(this,ae)))}destroy(){var e;if(v(this,Z))return;k(this,Z,!0),k(this,Oe,!1),k(this,Re,!1),k(this,je,!1);let t=v(this,L)?.ns;this.envProxy=void 0,this.view=void 0;let i=globalThis.__shadowEnvs;t&&i?.get(t)===this&&i.delete(t),(e=v(this,Wt))==null||e.call(this,new me),k(this,ae,void 0),Je(this),A(this),Object.freeze(this)}};ve=Hr(null);L=new WeakMap;X=new WeakMap;Oe=new WeakMap;Re=new WeakMap;je=new WeakMap;ae=new WeakMap;Ps=new WeakMap;Ts=new WeakMap;Z=new WeakMap;Fe=new WeakMap;Wt=new WeakMap;ge=new WeakSet;Es=function(){return v(this,Fe)==null&&(k(this,Fe,new Promise((s,e)=>{k(this,Wt,e)})),v(this,Fe).catch(()=>{})),v(this,Fe)};Cs=new WeakMap;Ss=async function(){if(k(this,Oe,!1),v(this,Z))return;if(!this.isReady){k(this,Re,!0);return}let s=this.view.buildChangeTrails(),e=v(this,je);k(this,je,!1);try{s.length>0&&await this.envProxy.applyChangeTrail(s,e)}catch(t){this.logger.error("failed to apply change trail",t)}finally{g(this,ee.AfterSync,s)}};Fi=function(s){this.logger.isDebug&&this.logger.debug("onMessageToView",s.type,s.data),this.view?.dispatchMessage(s.uuid,s.type,s.data,s.traverseChildren)};ji=function(s){if(!v(this,Z)){this.logger.error("the environment proxy failed",s);try{g(this,ee.ProxyFailed,s,this)}finally{this.proxyReady=!1}}};_i(ve,4,"viewReady",$i,ee,Ps);_i(ve,4,"proxyReady",Wi,ee,Ts);Ni(ve,ee);ee.AfterSync="afterSync";ee.ContextLost="contextLost";ee.ContextCreated="contextCreated";ee.ProxyFailed="proxyFailed";var B=ee;var x=["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"],Yr=()=>{let s=Math.random()*4294967295|0,e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,i=Math.random()*4294967295|0;return(x[s&255]+x[s>>8&255]+x[s>>16&255]+x[s>>24&255]+"-"+x[e&255]+x[e>>8&255]+"-"+x[e>>16&15|64]+x[e>>24&255]+"-"+x[t&63|128]+x[t>>8&255]+"-"+x[t>>16&255]+x[t>>24&255]+x[i&255]+x[i>>8&255]+x[i>>16&255]+x[i>>24&255]).toLowerCase()},zi=()=>globalThis?.crypto?.randomUUID?.()??Yr();var Ie=class extends Error{constructor(e){super(e),this.name="ViewComponentError"}};function Ii(s,e){if(s.context==null)throw new Ie("cannot add a child to a destroyed view component");if(s.context!==e)throw new Ie("cannot add a child from another context")}var $t=class s{#e;#t;#s;#i;#r=0;#n;get uuid(){return this.#e}get token(){return this.#t}set token(e){e??=F,e!==this.#t&&(this.#t=e,this.#s?.changeToken(this,e))}get parent(){return this.#i}set parent(e){e?e.addChild(this):this.removeFromParent()}get context(){return this.#s}set context(e){let t=e??void 0;if(this.#s!==t){if(t?.isDisposed)throw new et(`the view component ${this.#e} cannot join the component context because it has been disposed`);this.#s&&this.destroy(),this.#s=t;try{t?.addComponent(this)}catch(i){throw this.#s=void 0,i}}}get isDestroyed(){return this.#s==null}get order(){return this.#r}set order(e){let t=this.#r;this.#r=e??0,t!==this.#r&&this.#s?.changeOrder(this)}get autoDestructionOnParentRemoval(){return this.#n}constructor(e,t){T(this),t instanceof s&&(t={parent:t}),this.#e=t?.uuid??zi(),this.#t=e??F,this.#r=t?.order??0,this.#i=t?.parent,this.#n=t?.autoDestructionOnParentRemoval??!1;let i=t?.context??I.get();this.#i&&Ii(this.#i,i),this.context=i}isChildOf(e){return this.#i===e}removeFromParent(){this.#i?(this.#s?.removeFromParent(this.uuid,this.#i),this.#i=void 0):this.#s?.moveToRoot(this.uuid)}addChild(e){if(e.#s==null)throw new Ie("cannot add a destroyed view component as a child");Ii(this,e.#s);for(let t=this;t!=null;t=t.#i)if(t===e)throw new Ie("cannot add the component itself or one of its ancestors as a child: this would create a cycle");e.isChildOf(this)||(e.removeFromParent(),e.#i=this,this.#s.addToChildren(this,e))}setProperty(e,t,i){return this.#s?.setProperty(this,e,t,i)??!1}removeProperty(e){this.#s?.removeProperty(this,e)}dispatchShadowObjectsEvent(e,t,i){this.#s?.dispatchShadowObjectsEvent(this,e,t,i)}dispatchEvent(e,t,i){if(g(this,e,t),i)for(let r of this.#s?.getChildren(this)??[])r.dispatchEvent(e,t,i)}destroy(){this.removeFromParent(),this.#s?.destroyComponent(this),this.#s=void 0}};var nt=new Set(["on","true","yes","local","1"]);var Ui=s=>Te(s.getAttribute("ns")??void 0),at=(s,e)=>{if(s.hasAttribute(e)){let t=s.getAttribute(e)?.trim()?.toLowerCase()||"1";return nt.has(t)}return!1};var Vi=(s,e)=>{e.set(Ui(s))},xs=new Set,Os=!1,Jr=s=>{xs.add(s),Os||(Os=!0,queueMicrotask(()=>{Os=!1;for(let e of xs)B.get(e)?.sync();xs.clear()}))},be=class extends HTMLElement{constructor(){super(),this.isShaeElement=!0,this.ns$=y(Pe),this.ns$.onChange(e=>{typeof e=="string"&&e.length>0?this.getAttribute("ns")!==e&&this.setAttribute("ns",e):this.removeAttribute("ns")}),Vi(this,this.ns$)}static{this.observedAttributes=["ns"]}get ns(){return this.ns$.value}set ns(e){typeof e=="symbol"?this.ns$.set(e):this.ns$.set(Te(e))}attributeChangedCallback(e){e==="ns"&&Vi(this,this.ns$)}syncShadowObjects(){Jr(this.ns)}};var Ft=class extends be{constructor(){super(),this.isShaeEntElement=!0,this.componentContext$=y(),this.viewComponent$=y(),this.token$=y(),this.forwardCustomEvents$=y(!1),this.#n=!0,this.#y=()=>{let e=this.findShadowRootHost();e!=null&&this.dispatchEvent(new CustomEvent(gt,{bubbles:!0,composed:!0,detail:{requester:this,shadowRootHost:e}}))},this.#p=e=>{let t=e.detail?.requester;if(t===this||!t?.isShaeEntElement||t.ns!==this.ns)return;e.detail?.shadowRootHost&&this.#l()},this.#g=e=>{let t=e.detail?.requester;t!==this&&t?.isShaeEntElement&&t.ns===this.ns&&(e.stopPropagation(),t.#c(this))},this.ns$.onChange(e=>{this.componentContext$.set(I.get(e)),this.isConnected&&this.#l()}),this.#d(),this.token$.onChange(e=>{e==null?this.removeAttribute(ce):this.getAttribute(ce)!==e&&this.setAttribute(ce,e)}),this.#f(),this.forwardCustomEvents$.onChange(e=>{if(!e)this.removeAttribute(q);else if(e===!0)this.hasAttribute(q)||this.setAttribute(q,"");else{let t=Array.from(e).join(",");this.getAttribute(q)!==t&&this.setAttribute(q,t)}}),S(()=>{let e=this.viewComponent$.get();if(e){let t=b(e,I.ReRequestParentRoots,()=>this.#h()),i=e.context?.ns;return()=>{t(),e.destroy(),i&&i!==this.ns?B.get(i)?.sync():this.syncShadowObjects()}}}),S(()=>{let e=this.viewComponent$.get();if(!e)return;let t=Object.hasOwn(e,"dispatchEvent")?Object.getPrototypeOf(e).dispatchEvent:e.dispatchEvent,i=this.forwardCustomEvents$.get();if(!i)return;let r=i instanceof Set?i:void 0,n=(o,a,f)=>{t.call(e,o,a,f),o!==I.ReRequestParentRoots&&(r&&!r.has(o)||this.dispatchEvent(new CustomEvent(o,{bubbles:!0,composed:!0,detail:a})))};return Object.defineProperty(e,"dispatchEvent",{value:n,writable:!0,configurable:!0}),()=>{Object.hasOwn(e,"dispatchEvent")&&e.dispatchEvent===n&&delete e.dispatchEvent}}),this.token$.onChange(e=>{let t=this.viewComponent$.value;t&&(t.token=e,this.syncShadowObjects())}),this.style.display="contents"}static{this.observedAttributes=[...be.observedAttributes,ce,q]}get componentContext(){return this.componentContext$.value}get viewComponent(){return this.viewComponent$.value}get uuid(){return this.viewComponent?.uuid}get token(){return this.token$.value}set token(e){this.token$.set(e)}#e;#t;#s(){this.#t?.();let e=this.componentContext$.onChange(t=>{let i=this.token$.value,r=this.viewComponent$.value;r?r.context=t:t&&(r=new $t(i??F,{context:t}),this.viewComponent$.set(r)),this.syncShadowObjects()});this.#t=()=>{e()}}#i(){this.#t?.(),this.#t=void 0}#r;#n;findShadowRootHost(){if(this.#n){this.#n=!1;let e=this;for(;e;){if(e.parentElement==null){let t=e.parentNode;t&&(this.#r=t.host);break}e=e.parentElement}}return this.#r}getParentNodeForObserver(){return this.parentNode??this.getRootNode()?.host??void 0}connectedCallback(){this.#n=!0,this.addEventListener("slotchange",this.#y,{capture:!1,passive:!1}),this.addEventListener(pt,this.#g,{capture:!1,passive:!1}),this.#s(),xt(()=>this.#d()),xt(()=>this.#f()),this.componentContext==null&&this.componentContext$.set(I.get(this.ns)),this.#l(),this.componentContext?.dispatchReRequestParentRoots(),this.#a(),this.syncShadowObjects()}#a(){this.#o();let e=this.getParentNodeForObserver();e&&(this.#e=new MutationObserver((t,i)=>{for(let{target:r,removedNodes:n}of t)if(r===e){for(let o of n)if(o===this){this.#o(),this.onParentChanged(this.getParentNodeForObserver(),e);break}}}),this.#e.observe(e,{childList:!0,subtree:!1,attributes:!1}))}onParentChanged(e,t){this.#c(void 0),this.#l()}#o(){this.#e?.disconnect(),this.#e=void 0}attributeChangedCallback(e){super.attributeChangedCallback(e),e===ce?this.#d():e===q&&this.#f()}disconnectedCallback(){this.#n=!0,this.#o(),this.removeEventListener("slotchange",this.#y,{capture:!1}),this.removeEventListener(pt,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(pt,{bubbles:!0,composed:!0,detail:{requester:this}}))}#u;#c(e){if(this.entParentNode!==e)if(this.entParentNode&&this.entParentNode.removeEventListener(gt,this.#p,{capture:!1}),this.entParentNode=e,this.entParentNode&&this.entParentNode.addEventListener(gt,this.#p,{capture:!1,passive:!1}),this.#u?.(),this.#u=void 0,e){let t=S(()=>{let i=this.viewComponent$.get();if(i){let r=e.viewComponent$.get();i.parent=r&&r.context===i.context?r:void 0,i.parent==null&&queueMicrotask(()=>{this.#l()}),this.syncShadowObjects()}});this.#u=()=>t.destroy()}else{let t=this.viewComponent;t?.parent&&(t.parent=void 0,this.syncShadowObjects())}}#y;#p;#g;#d(){if(this.hasAttribute(ce)){let e=this.getAttribute(ce)?.trim()||void 0;this.token$.set(e)}}#f(){if(this.hasAttribute(q)){let e=this.getAttribute(q);!e||e.trim().length===0?this.forwardCustomEvents$.set(!0):this.forwardCustomEvents$.set(new Set(e.split(",").map(t=>t.trim()).filter(t=>t.length>0)))}else this.forwardCustomEvents$.set(!1)}};customElements.define(yt,Ft);var Xr=s=>{let e=s.parentElement;for(;e;){if(e.isShaeEntElement)return e;e=e.parentElement}},Zr=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"]),jt=class extends HTMLElement{constructor(){super(),this.isShaePropElement=!0,this.entNode$=y(),this.viewComponent$=y(),this.name$=y(),this.valueIn$=y(),this.valueOut$=y(),this.type$=y(),this.shouldTrim$=y(!0),this.logger=new N("ShaePropElement"),this.#e=()=>{this.entNode$.set(Xr(this))},this.#t=()=>{queueMicrotask(()=>{this.isConnected||this.entNode$.set(void 0)})},this.#s=()=>{this.name$.set(this.getAttribute(bt)?.trim()??void 0)},this.#i=()=>{this.valueIn$.set(this.getAttribute(wt))},this.#r=()=>{let e=this.getAttribute(Et)?.trim().toLowerCase();e&&!Zr.has(e)&&(this.logger.isWarn&&this.logger.warn(`[${this.name}] unknown type "${e}"`,{shaeProp:this}),e=void 0),this.type$.set(e)},this.#n=()=>{this.shouldTrim$.set(!at(this,Ct))},this.entNode$.onChange(e=>{if(e){let t=$(e.viewComponent$,this.viewComponent$);return()=>{t.destroy()}}else this.viewComponent$.set(void 0)}),S(()=>{let e=this.viewComponent$.get();if(e){let t=this.name$.get();if(t){let i=this.valueOut$.get();this.logger.isDebug&&this.logger.debug(`[${this.name}] view-component set-property`,t,i,e.uuid,{viewComponent:e,shaeProp:this}),e.setProperty(t,i),this.isConnected&&this.entNode?.syncShadowObjects()}}}),S(()=>{let e=this.type$.get(),t=this.shouldTrim$.get(),i=this.valueIn$.get();if(t&&typeof i=="string"&&(i=i.trim()),i=i||void 0,i!=null&&typeof i=="string"&&e)switch(e){case"string":case"text":break;case"number":i=Number(i);break;case"bigint":i=BigInt(i);break;case"float":i=parseFloat(i);break;case"int":case"integer":i=parseInt(i,10);break;case"hex":case"hexadecimal":i=parseInt(i,16);break;case"oct":case"octal":i=parseInt(i,8);break;case"bin":case"binary":i=parseInt(i,2);break;case"bool":case"boolean":i=nt.has(i.toLowerCase());break;case"[]":case"text[]":case"string[]":i=i.split(/\W+/);break;case"number[]":i=i.split(/\s+/).map(r=>Number(r));break;case"float[]":i=i.split(/\s+/).map(r=>parseFloat(r));break;case"int[]":case"integer[]":i=i.split(/\s+/).map(r=>parseInt(r,10));break;case"hex[]":case"hexadecimal[]":i=i.split(/\W+/).map(r=>parseInt(r,16));break;case"oct[]":case"octal[]":i=i.split(/\W+/).map(r=>parseInt(r,8));break;case"bin[]":case"binary[]":i=i.split(/\W+/).map(r=>parseInt(r,2));break;case"bool[]":case"boolean[]":i=i.split(/\W+/).map(r=>nt.has(r.toLowerCase()));break;case"int8array":i=new Int8Array(i.split(/\W+/).map(r=>Number(r)));break;case"uint8array":i=new Uint8Array(i.split(/\W+/).map(r=>Number(r)));break;case"uint8clampedarray":i=new Uint8ClampedArray(i.split(/\W+/).map(r=>Number(r)));break;case"int16array":i=new Int16Array(i.split(/\W+/).map(r=>Number(r)));break;case"uint16array":i=new Uint16Array(i.split(/\W+/).map(r=>Number(r)));break;case"int32array":i=new Int32Array(i.split(/\W+/).map(r=>Number(r)));break;case"uint32array":i=new Uint32Array(i.split(/\W+/).map(r=>Number(r)));break;case"float32array":i=new Float32Array(i.split(/\s+/).map(r=>Number(r)));break;case"float64array":i=new Float64Array(i.split(/\s+/).map(r=>Number(r)));break;case"bigint64array":i=new BigInt64Array(i.split(/\W+/).map(r=>BigInt(r)));break;case"biguint64array":i=new BigUint64Array(i.split(/\W+/).map(r=>BigInt(r)));break;case"json":i=JSON.parse(i);break;default:this.logger.isWarn&&this.logger.warn(`[${this.name}] unknown type "${e}"`,{value:i,shaeProp:this})}this.valueOut$.set(i)}),W(()=>{this.#s(),this.#i(),this.#r(),this.#n()}),this.style.display="contents"}static{this.observedAttributes=[bt,wt,Et,Ct]}get name(){return this.name$.value}get value(){return this.valueOut$.value}set value(e){this.valueIn$.set(e)}get shouldTrim(){return this.shouldTrim$.value}get entNode(){return this.entNode$.value}set entNode(e){this.entNode$.set(e)}get viewComponent(){return this.viewComponent$.value}connectedCallback(){W(()=>{this.#e(),this.#s(),this.#i(),this.#r(),this.#n()})}attributeChangedCallback(e){switch(e){case bt:this.#s();break;case wt:this.#i();break;case Et:this.#r();break;case Ct:this.#n();break}}disconnectedCallback(){this.#t()}#e;#t;#s;#i;#r;#n};customElements.whenDefined(yt).then(()=>customElements.define(Vs,jt));var Rs=null,ht=class s{static{this.OnFrame=Symbol("onFrame")}#e=0;constructor(){if(Rs)return Rs;T(this),Rs=this}start(e){if(e!=null)return os(this)===0&&this.#s(),b(this,s.OnFrame,e),()=>{this.stop(e)}}stop(e){A(this,s.OnFrame,e),os(this)===0&&this.#i()}#t=e=>{g(this,s.OnFrame,e),this.#s()};#s(){this.#e=requestAnimationFrame(this.#t)}#i(){cancelAnimationFrame(this.#e),this.#e=0}};async function Ms(s,e,t,i=!0){if(t.has(e)){console.warn("importModule: skipping already imported module",e);return}else t.add(e);e.extends&&await Promise.all(e.extends.map(n=>Ms(s,n,t,!1)));let{registry:r}=s;if(e.define)for(let[n,o]of Object.entries(e.define))r.define(n,o);if(e.routes)for(let[n,o]of Object.entries(e.routes))r.appendRoute(n,o);await(e.initialize?.({define:(n,o)=>r.define(n,o),kernel:s,registry:r})??Promise.resolve()),i&&s.upgradeEntities()}var zt=s=>s??void 0;var Ls=Symbol("onCreate"),te=Symbol("onDestroy"),Bi=Symbol("onParentChanged"),It=Symbol("onViewEvent");var en=Object.create,Ds=Object.defineProperty,tn=Object.getOwnPropertyDescriptor,Hi=(s,e)=>(e=Symbol[s])?e:Symbol.for("Symbol."+s),Ve=s=>{throw TypeError(s)},sn=(s,e,t)=>e in s?Ds(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,Gi=(s,e)=>Ds(s,"name",{value:e,configurable:!0}),rn=s=>[,,,en(s?.[Hi("metadata")]??null)],Qi=["class","method","getter","setter","accessor","field","value","get","set"],lt=s=>s!==void 0&&typeof s!="function"?Ve("Function expected"):s,nn=(s,e,t,i,r)=>({kind:Qi[s],name:e,metadata:i,addInitializer:n=>t._?Ve("Already initialized"):r.push(lt(n||null))}),Ki=(s,e)=>sn(e,Hi("metadata"),s[3]),qi=(s,e,t,i)=>{for(var r=0,n=s[e>>1],o=n&&n.length;r<o;r++)e&1?n[r].call(t):i=n[r].call(t,i);return i},on=(s,e,t,i,r,n)=>{var o,a,f,m,P,c=e&7,D=!!(e&8),w=!!(e&16),O=c>3?s.length+1:c?D?1:2:0,le=Qi[c+5],u=c>3&&(s[O-1]=[]),l=s[O]||(s[O]=[]),h=c&&(!w&&!D&&(r=r.prototype),c<5&&(c>3||!w)&&tn(c<4?r:{get[t](){return z(this,n)},set[t](d){return ut(this,n,d)}},t));c?w&&c<4&&Gi(n,(c>2?"set ":c>1?"get ":"")+t):Gi(r,t);for(var p=i.length-1;p>=0;p--)m=nn(c,t,f={},s[3],l),c&&(m.static=D,m.private=w,P=m.access={has:w?d=>an(r,d):d=>t in d},c^3&&(P.get=w?d=>(c^1?z:we)(d,r,c^4?n:h.get):d=>d[t]),c>2&&(P.set=w?(d,_)=>ut(d,r,_,c^4?n:h.set):(d,_)=>d[t]=_)),a=(0,i[p])(c?c<4?w?n:h[le]:c>4?void 0:{get:h.get,set:h.set}:r,m),f._=1,c^4||a===void 0?lt(a)&&(c>4?u.unshift(a):c?w?n=a:h[le]=a:r=a):typeof a!="object"||a===null?Ve("Object expected"):(lt(o=a.get)&&(h.get=o),lt(o=a.set)&&(h.set=o),lt(o=a.init)&&u.unshift(o));return c||Ki(s,r),h&&Ds(r,t,h),w?c^4?n:h:r},Ns=(s,e,t)=>e.has(s)||Ve("Cannot "+t),an=(s,e)=>Object(e)!==e?Ve('Cannot use the "in" operator on this value'):s.has(e),z=(s,e,t)=>(Ns(s,e,"read from private field"),t?t.call(s):e.get(s)),Ut=(s,e,t)=>e.has(s)?Ve("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,t),ut=(s,e,t,i)=>(Ns(s,e,"write to private field"),i?i.call(s,t):e.set(s,t),t),we=(s,e,t)=>(Ns(s,e,"access private method"),t),Yi,se,Ee,dt,_s,he,Vt,ct,Ue="value";Yi=[tt({name:Ue})];var ie=class{constructor(e){Ut(this,he),Ut(this,se,[]),Ut(this,Ee),Ut(this,_s,qi(dt,8,this)),qi(dt,11,this),this.value$=void 0,Y(this,Ue),this.value$=G(this,Ue),this.value$.onChange(t=>g(this,Ue,t)),e&&this.add(...e)}add(...e){return z(this,se).push(...e),we(this,he,ct).call(this),we(this,he,Vt).call(this,e)}unshift(...e){return z(this,se).unshift(...e),we(this,he,ct).call(this),we(this,he,Vt).call(this,e)}remove(...e){we(this,he,Vt).call(this,e)()}clear(){z(this,se).length=0,we(this,he,ct).call(this)}dispose(){this.clear(),z(this,Ee)?.destroy(),ut(this,Ee,void 0),de(this,Ue),A(this),this.value$.destroy(),Je(this)}};dt=rn(null);se=new WeakMap;Ee=new WeakMap;_s=new WeakMap;he=new WeakSet;Vt=function(s){return()=>{for(let e of s){let t=z(this,se).indexOf(e);t!==-1&&z(this,se).splice(t,1)}we(this,he,ct).call(this)}};ct=function(){z(this,Ee)?.destroy(),z(this,se).length===0?(ut(this,Ee,void 0),this.value=void 0):(ut(this,Ee,S(()=>{let s;for(let e of z(this,se)){let t=We(e);if(t!=null){s=t;break}}this.value=s},z(this,se))),z(this,Ee).run())};on(dt,4,"value",Yi,ie,_s);Ki(dt,ie);ie.Value=Ue;var Ws=new Map,$s=!1,hn=(s,e)=>{Ws.set(s,e),$s||($s=!0,queueMicrotask(()=>{$s=!1;let t=Array.from(Ws.entries());Ws.clear();for(let[i,r]of t)i.set(r)}))},Bt=class{#e;#t;#s=new Lt;#i=new Map;#r=new Map;#n;#a;#o=new Set;#h=[];#l=0;get kernel(){return this.#e}get uuid(){return this.#t}get order(){return this.#l}set order(e){this.#l!==e&&(this.#l=e,this.#n&&this.parent.resortChildren())}get parentUuid(){return this.#n||void 0}set parentUuid(e){if(this.#n!==e){let t=e?this.#e.getEntity(e):void 0;this.removeFromParent(),this.#n=e||void 0,this.#a=t,this.#a&&this.#a.addChild(this),this.#p()}}get parent(){return!this.#a&&this.#n&&(this.#a=this.#e.getEntity(this.#n)),this.#a}set parent(e){this.parentUuid=e?.uuid}get hasParent(){return!!this.#n}get children(){return this.#h}constructor(e,t){this.#e=e,this.#t=t,C(this,te,K.Min,this)}traverse(e){e(this);for(let t of this.#h)t.traverse(e)}[te](){this.#s.clear(),A(this),this.#c?.();for(let e of this.#r.values())e.cleanup(),e.signal.destroy();this.#r.clear();for(let e of this.#i.values())e.context.set(void 0),e.unsubscribePathValue(),e.unsubscribeFromParent?.(),e.valuePath.dispose(),e.inherited.destroy(),e.provide.destroy(),e.context.destroy();this.#n=void 0,this.#a=void 0,this.#o.clear(),this.#h.length=0}addChild(e){if(this.#h.length===0){this.#o.add(e.uuid),this.#h.push(e);return}if(this.#o.has(e.uuid))throw new Error(`child with uuid: ${e.uuid} already exists! parentUuid: ${this.uuid}`);this.#o.add(e.uuid),this.#h.push(e),this.resortChildren();for(let[,t]of e.#i)e.#v(t)}resortChildren(){this.#h.sort((e,t)=>e.order-t.order)}removeChild(e){this.#o.has(e.uuid)&&(this.#o.delete(e.uuid),this.#h.splice(this.#h.indexOf(e),1))}removeFromParent(){if(this.#a){this.#a.removeChild(this),this.#a=void 0,this.#n=void 0;for(let[,e]of this.#i)e.unsubscribeFromParent&&(e.unsubscribeFromParent(),e.unsubscribeFromParent=void 0);this.#y()}}#u=!1;#c;get autoDestructionOnParentRemoval(){return this.#u}set autoDestructionOnParentRemoval(e){this.#u!==e&&(this.#u=e,this.#p())}#y(){this.#c&&(this.#c(),this.#c=void 0)}#p(){this.#y(),this.#u&&this.#a&&(this.#c=C(this.#a,te,K.Max,()=>{this.#c=void 0,this.#e.destroyEntity(this.#t)}))}reSubscribeToParentContexts(){for(let[,e]of this.#i)this.#v(e)}dispatchMessageToView(e,t,i,r=!1){this.#e.dispatchMessageToView({uuid:this.#t,type:e,data:t,transferables:i,traverseChildren:r})}dispatchViewEvents(e){for(let{type:t,data:i}of e)g(this,It,t,i)}dispatchViewEvent(e,t){this.dispatchViewEvents([{type:e,data:t}])}#g(e){return this.#s.get(e)}getPropertyReader(e){return this.#g(e).get}getPropertyWriter(e){return this.#g(e).set}setProperties(e){this.clearTruthyPropsCache(),W(()=>{for(let[t,i]of e)this.setProperty(t,i)})}setProperty(e,t){this.getPropertyWriter(e)(t)}getProperty(e){return We(this.getPropertyReader(e))}propKeys(){return Array.from(this.#s.keys())}propEntries(){return Array.from(this.#s.entries()).map(([e,t])=>[e,t.value])}#d;clearTruthyPropsCache(){this.#d=void 0}truthyProps(){if(this.#d)return this.#d.size?this.#d:void 0;let e=new Set;for(let[t,i]of this.#s.entries())if(typeof t=="string"){let r=i.value;r!=null&&r!==!1&&r!==""&&e.add(t)}return this.#d=e,e.size?e:void 0}hasContext(e){return this.#i.has(e)}useContext(e){return this.#f(e).context.get}useParentContext(e){return this.#f(e).inherited.get}provideContext(e){return this.#f(e).provide}provideGlobalContext(e){if(this.#r.has(e))return this.#r.get(e).signal;let t=this.#e.findOrCreateRootContext(e),i=y(),r=t.add(i);return this.#r.set(e,{cleanup:r,signal:i}),i}#f(e){if(this.#i.has(e))return this.#i.get(e);let t=y(),i=y(),r=y(),n=new ie([i,t]),o=b(n,ie.Value,f=>{hn(r,f)}),a={name:e,inherited:t,provide:i,context:r,valuePath:n,unsubscribePathValue:o};return this.#i.set(e,a),this.#v(a),a}#v(e){if(e.unsubscribeFromParent?.(),e.unsubscribeFromParent=void 0,this.parent){let t=this.parent.#f(e.name),i=$(t.context,e.inherited);e.unsubscribeFromParent=i.destroy.bind(i)}else{let t=this.#e.findOrCreateRootContext(e.name),i=$(t.value$,e.inherited);e.unsubscribeFromParent=i.destroy.bind(i)}}};var Ji=s=>{let e=s.split("@").map(t=>t.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]}},Gt=(s,e)=>{for(let t of e)s.add(t)},ln=(s,e)=>{if(s!=null)for(let t of s.constructors)e.add(t)},Me=class{static get(e){return e??cn}#e=new Map;#t=new Map;#s=new Map;define(e,t){let i=this.#e.get(e);i?Ti(i.constructors,t):this.#e.set(e,{token:e,constructors:[t]})}appendRoute(e,t){let i=Ji(e);if(i){let r=this.#s.get(i.key);r?Gt(r.routes,t):this.#s.set(i.key,{routes:new Set(t),token:i.token})}else{let r=this.#t.get(e);r?Gt(r,t):this.#t.set(e,new Set(t))}}clearRoute(e){let t=Ji(e);t?this.#s.delete(t.key):this.#t.delete(e)}findTokensByRoute(e,t){let i=new Set([e]),r=Array.from(this.#t.get(e)??[]);for(let n=r.shift();n!==void 0;n=r.shift()){if(i.has(n))continue;i.add(n);let o=this.#t.get(n);o&&r.push(...Array.from(o).filter(a=>!i.has(a)))}if(t){for(let o of t){let a=this.#s.get(o);a&&Gt(i,a.routes)}let n;do{n=i.size;for(let o of new Set(i))for(let a of t){let f=this.#s.get(`${o}@${a}`);f&&Gt(i,f.routes)}}while(n!==i.size)}return i}findConstructors(e,t){let i=this.findTokensByRoute(e,t),r=new Set;for(let n of i)ln(this.#e.get(n),r);return r.size>0?Array.from(r):void 0}hasToken(e){return this.#e.has(e)}hasRoute(e){return this.#t.has(e)}clear(){this.#e.clear(),this.#t.clear(),this.#s.clear()}},cn=new Me;var Xi=s=>s.displayName||s.name,Zi=!1,er=!1,tr=!1,sr=!1,ir=!1,qt=class{constructor(e){this.logger=new N("Kernel"),this.#e=new Map,this.#t=new Set,this.#s=[],this.#i=[],this.#r=!0,this.#n=new Map,T(this),this.registry=Me.get(e)}#e;#t;#s;#i;#r;#n;getEntity(e){return this.#a(e).entity}#a(e){let t=this.#e.get(e);if(t===void 0)throw new Error(`entity with uuid "${e}" not found!`);return t}hasEntity(e){return this.#e.has(e)}traverseLevelOrderBFS(e=!1){if(this.#r){let t=new Map,i=(r,n)=>{let o=this.getEntity(r),a=t.get(n);a?a.push(o):t.set(n,[o]);for(let f of o.children)i(f.uuid,n+1)};this.#t.forEach(r=>{i(r,0)}),this.#s=Array.from(t.entries()).sort((r,n)=>r[0]-n[0]).flatMap(([,r])=>r),this.#i=this.#s.slice().reverse(),this.#r=!1}return e?this.#i:this.#s}getEntityGraph(){return Array.from(this.#t).map(e=>this.getEntityGraphNode(e)).filter(e=>e!==void 0)}getEntityGraphNode(e){let t=this.#e.get(e);if(t===void 0)return;let{token:i,entity:r}=t;return{token:i,entity:r,props:Object.fromEntries(r.propEntries()),children:r.children.map(n=>this.getEntityGraphNode(n.uuid)).filter(n=>n!==void 0)}}upgradeEntities(){let e=new Map;for(let t of this.traverseLevelOrderBFS(!0))this.hasEntity(t.uuid)&&e.set(t.uuid,this.updateShadowObjects(t.uuid,2));for(let t of this.traverseLevelOrderBFS(!1))this.hasEntity(t.uuid)&&this.updateShadowObjects(t.uuid,1,e.get(t.uuid));e.clear()}run(e){this.logger.isDebug&&this.logger.debug("sync",e),W(()=>{for(let t of e.changeTrail)this.parse(t)})}parse(e){switch(e.type){case E.CreateEntities:this.createEntity(e.uuid,e.token,e.parentUuid,e.order,e.properties,e.autoDestructionOnParentRemoval),this.#r=!0;break;case E.DestroyEntities:this.destroyEntity(e.uuid),this.#r=!0;break;case E.SetParent:this.setParent(e.uuid,e.parentUuid,e.order),this.#r=!0;break;case E.UpdateOrder:this.updateOrder(e.uuid,e.order),this.#r=!0;break;case E.ChangeProperties:this.changeProperties(e.uuid,e.properties);break;case E.ChangeToken:this.changeToken(e.uuid,e.token);break;case E.SendEvents:this.dispatchEventsToEntity(e.uuid,e.events);break}}createEntity(e,t,i,r=0,n,o=!1){let a=new Bt(this,e);a.order=r;let f={token:t,entity:a,usedConstructors:new Map};this.#e.set(e,f),i&&(a.parentUuid=i),a.autoDestructionOnParentRemoval=o,a.hasParent||this.#t.add(e),n&&a.setProperties(n),this.createShadowObjects(f)}destroyEntity(e){let t=this.#e.get(e);if(t===void 0)return;let{entity:i,usedConstructors:r}=t,n=[...i.children];for(let o of n)o.autoDestructionOnParentRemoval?this.destroyEntity(o.uuid):(o.removeFromParent(),this.#t.add(o.uuid));i.removeFromParent(),g(i,te,i),r.clear(),this.#e.delete(i.uuid),this.#t.delete(i.uuid),this.#r=!0}setParent(e,t,i){let r=this.getEntity(e),n=i??r.order;if(!(r.parentUuid===t&&r.order===n)){if(t&&!this.#e.has(t))throw new Error(`entity with uuid "${t}" not found!`);r.removeFromParent(),r.order=n,r.parentUuid=t,r.hasParent?this.#t.delete(e):this.#t.add(e),r.reSubscribeToParentContexts(),queueMicrotask(()=>{this.logger.isDebug&&this.logger.debug("entity.onParentChanged",{uuid:e,parentUuid:t,order:n,entity:r}),g(r,Bi,r)})}}updateOrder(e,t){this.getEntity(e).order=t}dispatchEventsToEntity(e,t){this.getEntity(e)?.dispatchViewEvents(t)}changeProperties(e,t){this.getEntity(e).setProperties(t),this.updateShadowObjects(e)}changeToken(e,t){let i=this.#e.get(e);i!==void 0&&i.token!==t&&(i.token=t,this.updateShadowObjects(e))}dispatchMessageToView(e){queueMicrotask(()=>{g(this,$e,e)})}updateShadowObjects(e,t=0,i){let r=this.#a(e);i??=new Set(this.registry.findConstructors(r.token,r.entity.truthyProps()));let n=t===0||t===2,o=t===0||t===1;if(n){for(let[a,f]of r.usedConstructors)if(!i.has(a)){r.usedConstructors.delete(a);for(let m of f)this.destroyShadowObject(m,r.entity)}}if(o)for(let a of i)r.usedConstructors.has(a)||this.constructShadowObject(a,r);return i}constructShadowObject(e,t){let i=new Set,r=new Set,n=new Map,o=new Map,a=new Map,f=new Map,m=new Map,P=new Map,c=new Map,D=new Map,w=(u,l)=>{!ir&&l!=null&&typeof l=="function"&&(console.warn('[shadow-objects] Deprecation Warning: The "isEqual" option of "useProperty()" is now passed as {compare} argument. Please update your code accordingly.'),ir=!0);let h=typeof l=="function"?{compare:l}:l,p=c.get(u);if(p===void 0){p=y(void 0,h).get,c.set(u,p),D.set(u,h?.compare);let d=$(t.entity.getPropertyReader(u),p);r.add(d.destroy.bind(d))}else h?.compare!=null&&D.get(u)!==h.compare&&console.warn(`[shadow-objects] useProperty("${u}"): the cached signal already exists with a different (or no) {compare} function \u2014 the new options are ignored. Pass options only on the first call per property.`);return p},O=T(new e({entity:t.entity,provideContext(u,l,h){!Zi&&h!=null&&typeof h=="function"&&(console.warn('[shadow-objects] Deprecation Warning: The "isEqual" option of "provideContext()" is now passed as {compare} argument. Please update your code accordingly.'),Zi=!0);let p=typeof h=="function"?{compare:h}:h,d=m.get(u);if(d==null){let _=Ae(l),Jt=_?void 0:zt(l);if(d=y(Jt,p?.compare?{compare:p.compare}:void 0),_){let Ge=$(l,d);r.add(Ge.destroy.bind(Ge))}let Be=$(d,t.entity.provideContext(u));r.add(Be.destroy.bind(Be)),m.set(u,d)}return d!=null&&(p?.clearOnDestroy??!0)&&r.add(()=>{d.set(void 0)}),d},provideGlobalContext(u,l,h){!er&&h!=null&&typeof h=="function"&&(console.warn('[shadow-objects] Deprecation Warning: The "isEqual" option of "provideGlobalContext()" is now passed as {compare} argument. Please update your code accordingly.'),er=!0);let p=typeof h=="function"?{compare:h}:h,d=P.get(u);if(d==null){let _=Ae(l),Jt=_?void 0:zt(l);if(d=y(Jt,p?.compare?{compare:p.compare}:void 0),_){let Ge=$(l,d);r.add(Ge.destroy.bind(Ge))}let Be=$(d,t.entity.provideGlobalContext(u));r.add(Be.destroy.bind(Be)),P.set(u,d)}return d!=null&&(p?.clearOnDestroy??!0)&&r.add(()=>{d.set(void 0)}),d},useContext(u,l){!tr&&l!=null&&typeof l=="function"&&(console.warn('[shadow-objects] Deprecation Warning: The "isEqual" option of "useContext()" is now passed as {compare} argument. Please update your code accordingly.'),tr=!0);let h=typeof l=="function"?{compare:l}:l,p=n.get(u);if(p===void 0){p=y(void 0,h).get,n.set(u,p),o.set(u,h?.compare);let d=$(t.entity.useContext(u),p);r.add(d.destroy.bind(d))}else h?.compare!=null&&o.get(u)!==h.compare&&console.warn(`[shadow-objects] useContext("${String(u)}"): the cached signal already exists with a different (or no) {compare} function \u2014 the new options are ignored. Pass options only on the first call per context.`);return p},useParentContext(u,l){!sr&&l!=null&&typeof l=="function"&&(console.warn('[shadow-objects] Deprecation Warning: The "isEqual" option of "useParentContext()" is now passed as {compare} argument. Please update your code accordingly.'),sr=!0);let h=typeof l=="function"?{compare:l}:l,p=a.get(u);if(p===void 0){p=y(void 0,h).get,a.set(u,p),f.set(u,h?.compare);let d=$(t.entity.useParentContext(u),p);r.add(d.destroy.bind(d))}else h?.compare!=null&&f.get(u)!==h.compare&&console.warn(`[shadow-objects] useParentContext("${String(u)}"): the cached signal already exists with a different (or no) {compare} function \u2014 the new options are ignored. Pass options only on the first call per parent context.`);return p},dispatchMessageToView(u,l,h,p=!1){t.entity.dispatchMessageToView(u,l,h,p)},useProperty:w,useProperties(u){let l={};for(let h in u)Object.hasOwn(u,h)&&(l[h]=w(u[h]));return l},createResource(u,l){let h=y(),p=S(()=>{let d=zt(u());return h.set(d),d!==void 0&&l?()=>{l(d),h.set(void 0)}:()=>{h.set(void 0)}});return r.add(()=>{p.destroy(),h.set(void 0),M(h)}),h},createEffect(...u){let l=S(...u);return r.add(l.destroy),l},createSignal(...u){let l=y(...u);return r.add(()=>{M(l)}),l},createMemo(...u){let l=Ot(...u);return r.add(()=>{M(l)}),l},on(...u){let[l]=u;if(typeof l=="string"||typeof l=="symbol"||Array.isArray(l)){let p=b(t.entity,...u);return r.add(p),p}let h=b(...u);return r.add(h),Object.assign(()=>{r.delete(h),h()},h)},once(...u){let[l]=u;if(typeof l=="string"||typeof l=="symbol"||Array.isArray(l)){let p=C(t.entity,...u);return r.add(p),p}let h=C(...u);return r.add(h),Object.assign(()=>{r.delete(h),h()},h)},emit(...u){let[l]=u;typeof l=="string"||typeof l=="symbol"||Array.isArray(l)?g(t.entity,...u):g(...u)},onViewEvent(u){let l=b(t.entity,It,(h,p)=>{u(h,p)});r.add(l)},onDestroy(u){i.add(u)}}));this.logger.isInfo&&this.logger.info("create shadow-object",Xi(e),{shadowObject:O,entity:t.entity}),C(t.entity,te,K.Low,()=>{this.logger.isInfo&&this.logger.info("destroy shadow-object",Xi(e),{shadowObject:O,entity:t.entity});for(let l of i)l();for(let l of r)l();for(let l of n.values())M(l);for(let l of a.values())M(l);for(let l of c.values())M(l);for(let l of m.values())M(l);for(let l of P.values())M(l);i.clear(),r.clear(),n.clear(),a.clear(),c.clear(),m.clear(),P.clear();let u=t.usedConstructors.get(e);u&&(u.delete(O),u.size===0&&t.usedConstructors.delete(e))});let le=t.usedConstructors.get(e);return le?le.add(O):t.usedConstructors.set(e,new Set([O])),this.attachShadowObject(O,t.entity),O}createShadowObjects(e){this.registry.findConstructors(e.token,e.entity.truthyProps())?.forEach(t=>{this.constructShadowObject(t,e)})}findShadowObjects(e){let t=this.#e.get(e);if(t===void 0)return[];let{usedConstructors:i}=t;return Array.from(new Set(Array.from(i.values()).flatMap(r=>Array.from(r))))}attachShadowObject(e,t){b(t,e),typeof e[Ls]=="function"&&e[Ls](t)}destroyShadowObject(e,t){typeof e[te]=="function"&&e[te](t),g(e,te,t),A(t,e)}findOrCreateRootContext(e){let t=this.#n.get(e);return t||(t=new ie,this.#n.set(e,t)),t}destroy(){for(let e of this.#n.values())e.dispose();this.#n.clear();for(let e of this.traverseLevelOrderBFS().reverse())this.destroyEntity(e.uuid)}};var Ht=s=>(typeof s=="string"&&(s=new URL(s,globalThis.location.href)),s.toString());function rr(s){return s.map(e=>{if(e.transferables&&e.transferables.length>0){let{transferables:t,...i}=e;return structuredClone(i,{transfer:t})}else return structuredClone(e)})}var Qt=class{constructor(e){this.#e=new Set,this.isLocalEnv=!0,this.disableStructuredClone=!1,this.kernel=new qt(e),this.#t=this.kernel.registry===Me.get(),b(this.kernel,$e,t=>{let i=this.onMessageToView;if(i==null)return;let{type:r,uuid:n,traverseChildren:o}=t,a=structuredClone(t.data,{transfer:t.transferables});i.call(this,{type:r,uuid:n,data:a,traverseChildren:o})})}#e;#t;get registry(){return this.kernel.registry}start(){return Promise.resolve()}applyChangeTrail(e,t){let i={changeTrail:this.disableStructuredClone?e:rr(e)},r;try{this.kernel.run(i),r=Promise.resolve()}catch(n){r=Promise.reject(n)}return r}async importScript(e){let t=await import(Ht(e));t[ys]&&await this.importModule(t[ys])}async importModule(e){return Ms(this.kernel,e,this.#e)}destroy(){this.kernel.destroy(),this.#t||this.registry.clear(),this.#e.clear()}};function Fs(s){let e=new Blob([s],{type:"text/javascript"}),t=URL.createObjectURL(e),i=new Worker(t);return URL.revokeObjectURL(t),i}function js(){return Fs(`var Qi=Object.defineProperty;var Rt=Object.getOwnPropertySymbols;var Ns=Object.prototype.hasOwnProperty,Us=Object.prototype.propertyIsEnumerable;var qi=(s,e)=>(e=Symbol[s])?e:Symbol.for("Symbol."+s),_s=s=>{throw TypeError(s)};var is=(s,e,t)=>e in s?Qi(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,rs=(s,e)=>{for(var t in e||(e={}))Ns.call(e,t)&&is(s,t,e[t]);if(Rt)for(var t of Rt(e))Us.call(e,t)&&is(s,t,e[t]);return s};var js=(s,e)=>{var t={};for(var i in s)Ns.call(s,i)&&e.indexOf(i)<0&&(t[i]=s[i]);if(s!=null&&Rt)for(var i of Rt(s))e.indexOf(i)<0&&Us.call(s,i)&&(t[i]=s[i]);return t};var y=(s,e,t)=>is(s,typeof e!="symbol"?e+"":e,t),ns=(s,e,t)=>e.has(s)||_s("Cannot "+t);var n=(s,e,t)=>(ns(s,e,"read from private field"),t?t.call(s):e.get(s)),f=(s,e,t)=>e.has(s)?_s("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,t),g=(s,e,t,i)=>(ns(s,e,"write to private field"),i?i.call(s,t):e.set(s,t),t),S=(s,e,t)=>(ns(s,e,"access private method"),t);var Tt=(s,e,t,i)=>({set _(r){g(s,e,r,t)},get _(){return n(s,e,i)}});var os=function(s,e){this[0]=s,this[1]=e},Vs=(s,e,t)=>{var i=(c,d,w,k)=>{try{var v=t[c](d),B=(d=v.value)instanceof os,M=v.done;Promise.resolve(B?d[0]:d).then(C=>B?i(c==="return"?c:"next",d[1]?{done:C.done,value:C.value}:C,w,k):w({value:C,done:M})).catch(C=>i("throw",C,w,k))}catch(C){k(C)}},r=(c,d,w,k)=>a[c]=v=>(d=new Promise((B,M,C)=>(C=()=>i(c,v,B,M),o?o.then(C):C())),k=()=>o===w&&(o=0),o=w=d.then(k,k),d),o,a={};return t=t.apply(s,e),a[qi("asyncIterator")]=()=>a,r("next"),r("throw"),r("return"),a};var ae=(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",s))(ae||{});var Ws="configure",Is="changeTrail",Qs="destroy",qs="loaded",as="appliedChangeTrail",Dt="importedModule",Ks="destroyed",ut="messageToView";var zt="shadowObjects";var F="ConsoleLogger",D=\`\${F}Storage\`,Ys,Xs,Zs,Ki=!!((Zs=(Xs=(Ys=globalThis.location)==null?void 0:Ys.host)==null?void 0:Xs.startsWith("localhost"))!=null&&Zs),gt="localStorage"in globalThis,Bt=Symbol.for(F),Hs=!1,Js=s=>{if(typeof s=="boolean")return s;switch(s.toLowerCase()){case"true":case"yes":case"on":return!0;default:return!1}},ls=s=>[gt?F:void 0,...Array.isArray(s)?s:[s]].filter(Boolean).join(".");function cs(s,e,t){var o;let i=ls(s),r=gt?localStorage.getItem(i):(o=globalThis[D])==null?void 0:o[i];return r==null?t:e?e(r):r}function ft(s,e){gt?localStorage.setItem(ls(s),e):(globalThis[D]==null&&(globalThis[D]={},console.debug(\`\${F}: Initialize\`,{[D]:globalThis[D]})),globalThis[D][ls(s)]=e)}var $e,dt,b=class b{constructor(e){f(this,$e);this.enable=!0,this.namespace=(e||"").trim()||F,Hs||(b.loadConfig(),Hs=!0);let t=[this.namespace,"enable"];this.enable=cs(t,Js,this.enable),ft(t,gt?this.enable?"true":"false":this.enable)}static get isEnabled(){return b.sharedConfig.enable}static get isDebug(){return b.sharedConfig.enable&&b.sharedConfig.debug}static loadConfig(){var e,t,i;gt?(["enable","debug","info","warn"].forEach(r=>{this.sharedConfig[r]=cs(r,Js,this.sharedConfig[r])}),["debug","info","warn","error"].forEach(r=>{this.sharedStyles[r]=cs(["styles",r],void 0,this.sharedStyles[r])}),b.isDebug&&console.debug(\`\${F}: Load config from localStorage\`,b.sharedConfig),(e=globalThis[F])!=null&&e[Bt]||(t=globalThis[F])!=null||(globalThis[F]={[Bt]:!0,get enable(){return b.sharedConfig.enable},set enable(r){b.sharedConfig.enable=r,ft("enable",r?"true":"false")},get debug(){return b.sharedConfig.debug},set debug(r){b.sharedConfig.debug=r,ft("debug",r?"true":"false")},get info(){return b.sharedConfig.info},set info(r){b.sharedConfig.info=r,ft("info",r?"true":"false")},get warn(){return b.sharedConfig.warn},set warn(r){b.sharedConfig.warn=r,ft("warn",r?"true":"false")}})):(i=globalThis[D])!=null&&i[Bt]||(globalThis[D]=rs(rs({[Bt]:!0},b.sharedConfig),globalThis[D]),b.sharedConfig=globalThis[D],b.isDebug&&console.debug(\`\${F}: Load config from \${D}\`,globalThis[D]))}get isEnabled(){return this.enable&&b.sharedConfig.enable}get isDebug(){return this.isEnabled&&b.sharedConfig.debug}get isInfo(){return this.isEnabled&&b.sharedConfig.info}get isWarn(){return this.isEnabled&&b.sharedConfig.warn}debug(...e){S(this,$e,dt).call(this,"debug",b.sharedStyles.debug,e)}info(...e){S(this,$e,dt).call(this,"info",b.sharedStyles.info,e)}warn(...e){S(this,$e,dt).call(this,"warn",b.sharedStyles.warn,e)}error(...e){S(this,$e,dt).call(this,"error",b.sharedStyles.error,e)}};$e=new WeakSet,dt=function(e,t,i){console[e](\`%c\${this.namespace}\`,t,...i)},b.sharedConfig={enable:Ki,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"},b.sharedStyles={get debug(){return b.sharedConfig["styles.debug"]},set debug(e){b.sharedConfig["styles.debug"]=e},get info(){return b.sharedConfig["styles.info"]},set info(e){b.sharedConfig["styles.info"]=e},get warn(){return b.sharedConfig["styles.warn"]},set warn(e){b.sharedConfig["styles.warn"]=e},get error(){return b.sharedConfig["styles.error"]},set error(e){b.sharedConfig["styles.error"]=e}};var Ft=b;var Ne="*",ni=1,gs=2,ys=4,ce=Symbol.for("eventize"),Hi="[eventize]",ps=s=>s===Ne,oi=s=>{switch(typeof s){case"string":case"symbol":return!0;default:return!1}},ai=typeof console!="undefined",Ji=ai?console[console.warn?"warn":"log"].bind(console,Hi):()=>{},Yi=(s,e,t)=>(Object.defineProperty(s,e,{value:t,configurable:!0}),s),Xi=0,vs=class{constructor(){y(this,"events",new Map);y(this,"eventNames",new Set)}static publish(s){s.sort((e,t)=>e.order-t.order).forEach(e=>e.replay())}add(s){Array.isArray(s)?s.forEach(e=>this.eventNames.add(e)):this.eventNames.add(s)}remove(s){Array.isArray(s)?s.forEach(e=>this.eventNames.delete(e)):this.eventNames.delete(s),this.clear(s)}clear(s){Array.isArray(s)?s.forEach(e=>this.events.delete(e)):this.events.delete(s)}retain(s,e){this.eventNames.has(s)&&this.events.set(s,{args:e,order:Xi++})}isKnown(s){return this.eventNames.has(s)}replayTo(s,e,t=[]){if(ps(s))this.eventNames.forEach(i=>this.replayTo(i,e,t));else if(this.events.has(s)){let{order:i,args:r}=this.events.get(s);t.push({order:i,replay:()=>e.apply(s,r)})}return t}},fs=(s,e,t,i)=>{if(typeof e=="function"){let r=e.apply(s,t);r!=null&&(i==null||i(r))}},Zi=(s,e,t,i)=>fs(e,e.emit,[s].concat(t),i),er=s=>{switch(typeof s){case"function":return ni;case"string":case"symbol":return gs;case"object":return ys}},tr=0,sr=()=>++tr,ci=class{constructor(s,e,t,i=null){y(this,"id");y(this,"eventName");y(this,"isCatchEmAll");y(this,"priority");y(this,"listener");y(this,"listenerObject");y(this,"listenerType");y(this,"callAfterApply");y(this,"isRemoved");y(this,"refCount");this.id=sr(),this.eventName=s,this.isCatchEmAll=ps(s),this.listener=t,this.listenerObject=i,this.priority=e,this.listenerType=er(t),this.callAfterApply=void 0,this.isRemoved=!1,this.refCount=1}isEqual(s,e=null){if(s===this)return!0;let t=typeof s;return t==="number"&&s===this.id?!0:e===null&&(t==="string"||t==="symbol")?s===Ne||s===this.eventName:this.listener===s&&this.listenerObject===e}apply(s,e,t){if(this.isRemoved)return;let{listener:i,listenerObject:r}=this;switch(this.listenerType){case ni:fs(r,i,e,t),this.callAfterApply&&this.callAfterApply();break;case gs:fs(r,r[i],e,t),this.callAfterApply&&this.callAfterApply();break;case ys:{let o=i[s];if(this.isCatchEmAll||this.eventName===s){if(typeof o=="function"){let a=o.apply(i,e);a!=null&&(t==null||t(a))}else Zi(s,i,e,t);this.callAfterApply&&this.callAfterApply()}break}}}},ir=(s,e)=>s.priority!==e.priority?e.priority-s.priority:s.id-e.id,rr=(s,e)=>{let t=0,i=s.length;for(;t<i;){let r=t+i>>>1;ir(e,s[r])<0?i=r:t=r+1}return t},ei=s=>s==null?void 0:s.slice(0),ti=(s,e)=>{let t=s.indexOf(e);t>-1&&s.splice(t,1)},nr=s=>s===ys||s===gs,ds=(s,e,t)=>{let i=s.findIndex(r=>r.isEqual(e,t));i>-1&&(s[i].isRemoved=!0,s.splice(i,1))},hs=(s,e,t)=>{let i=[];for(let r of s)(e==null&&r.listenerObject===t||r.eventName===e&&r.listener===t)&&i.push(r);for(let r of i)ds(s,r,void 0)},us=s=>{s&&(s.forEach(e=>{e.isRemoved=!0}),s.length=0)},or=(s,e)=>s.listenerType===e.listenerType?s.priority===e.priority&&s.eventName===e.eventName&&s.listenerObject===e.listenerObject&&s.listener===e.listener:!1,ar=(s,e)=>{if(nr(s.listenerType))return e.find(t=>or(s,t))},cr=(s,e)=>{let t=ar(s,e);return t?(t.refCount+=1,t):(e.splice(rr(e,s),0,s),s)},lr=class{constructor(){y(this,"namedListeners");y(this,"catchEmAllListeners");y(this,"getListenersForEventName",s=>{let e=this.namedListeners.get(s);return e||(e=[],this.namedListeners.set(s,e)),e});this.namedListeners=new Map,this.catchEmAllListeners=[]}add(s){return cr(s,s.isCatchEmAll?this.catchEmAllListeners:this.getListenersForEventName(s.eventName))}remove(s,e,t=!1){if(e==null&&Array.isArray(s)){s.forEach(i=>this.remove(i,null,t));return}if(s==null||e==null&&ps(s)){this.removeAllListeners();return}if(e==null&&oi(s)){this.removeByEventName(s);return}if(s instanceof ci){this.removeByEventListener(s);return}if(t){this.removeByEventNameAndListenerObject(s,e);return}this.removeByListener(s,e)}removeByEventName(s){us(this.namedListeners.get(s)),this.namedListeners.delete(s)}removeByEventListener(s){s.isRemoved||(s.refCount-=1,!(s.refCount>=1)&&(s.isRemoved=!0,this.namedListeners.forEach((e,t)=>{ti(e,s),e.length===0&&this.namedListeners.delete(t)}),ti(this.catchEmAllListeners,s)))}removeByEventNameAndListenerObject(s,e){this.namedListeners.forEach((t,i)=>{hs(t,s,e),t.length===0&&this.namedListeners.delete(i)})}removeByListener(s,e){let t=typeof s=="object";this.namedListeners.forEach((i,r)=>{ds(i,s,e),t&&hs(i,void 0,s),i.length===0&&this.namedListeners.delete(r)}),ds(this.catchEmAllListeners,s,e),t&&hs(this.catchEmAllListeners,void 0,s)}removeAllListeners(){this.namedListeners.forEach(s=>us(s)),this.namedListeners.clear(),us(this.catchEmAllListeners)}forEach(s,e){let t=ei(this.catchEmAllListeners),i=ei(this.namedListeners.get(s));if(s===Ne||!i||i.length===0)t.forEach(e);else if(t.length===0)i.forEach(e);else{let r=i.length,o=t.length,a=0,c=0;for(;a<r||c<o;){if(a<r){let d=i[a];if(c>=o||d.priority>=t[c].priority){e(d),++a;continue}}c<o&&(e(t[c]),++c)}}}getSubscriptionCount(){let s=this.catchEmAllListeners.length;for(let e of this.namedListeners.values())s+=e.length;return s}},Ue=s=>!!(s&&s[ce]);function yt(s){if(Ue(s))return s;let e=new lr,t=new vs;return Yi(s,ce,{keeper:t,store:e}),s}var we={Max:Number.POSITIVE_INFINITY,Critical:1e9,High:1e6,Normal:0,Low:-1e4,Min:Number.NEGATIVE_INFINITY,AAA:1e9,BB:1e6,C:1e3,Default:0},hr=(s,e,t,i,r,o,a)=>{let c=s.add(new ci(t,i,r,o));return e.replayTo(t,c,a),c},li=(s,e,t,i)=>{let r=t.length,o=typeof t[0],a,c,d,w;if(r>=2&&r<=3&&o==="number"?(a=Ne,[c,d,w]=t):r>=3&&r<=4&&typeof t[1]=="number"?[a,c,d,w]=t:(c=we.Default,o==="string"||o==="symbol"||Array.isArray(t[0])?[a,d,w]=t:(a=Ne,[d,w]=t)),!d)throw ai&&Ji("called with insufficient arguments!",t),new Error("subscribeTo() called with insufficient arguments");let k=v=>B=>hr(s,e,B,v,d,w,i);return Array.isArray(a)?a.map(v=>Array.isArray(v)?k(v[1])(v[0]):k(c)(v)):k(c)(a)},ur=(s,e,t)=>{let i=[],r=li(s,e,t,i);return vs.publish(i),r},fr=(s,e,t)=>{let i=[];return{listeners:li(s,e,t,i),publishRetained:()=>vs.publish(i)}},si=s=>e=>{e.callAfterApply=()=>{s==null||s()}},hi=(s,e)=>Object.assign(()=>x(s,e),Array.isArray(e)?{listeners:e}:{listener:e}),ii=(s,e,t,i)=>{if(e===Ne)throw new Error("emit() must be called with a concrete event name \\u2014 '*' is reserved for subscribing to all events and cannot be emitted");let{store:r,keeper:o}=s[ce];r.forEach(e,a=>a.apply(e,t,i)),o.retain(e,t)},ui=(s,e,t,i)=>{Array.isArray(e)?e.forEach(r=>ii(s,r,t,i)):ii(s,e,t,i)},ri=(s,e,t,i)=>{if(e===Ne)throw new Error("emit() must be called with a concrete event name \\u2014 '*' is reserved for subscribing to all events and cannot be emitted");let r=s,o=r[e];if(typeof o=="function"){let c=o.apply(s,t);c!=null&&(i==null||i(c));return}let a=r.emit;if(typeof a=="function"){let c=a.apply(s,[e,...t]);c!=null&&(i==null||i(c))}},fi=(s,e,t,i)=>{Array.isArray(e)?e.forEach(r=>ri(s,r,t,i)):ri(s,e,t,i)},di=s=>s!=null&&typeof s=="object";function L(s,...e){let t=yt(s),{store:i,keeper:r}=t[ce];return hi(t,ur(i,r,e))}function A(s,...e){let t=yt(s),{store:i,keeper:r}=t[ce],{listeners:o,publishRetained:a}=fr(i,r,e),c=hi(t,o),d=!1,w=()=>{d||(c(),d=!0)};return Array.isArray(o)?o.forEach(si(w)):si(w)(o),a(),w}function dr(s,e){return new Promise(t=>{A(s,e,t)})}function x(s,e,t){if(!Ue(s))return;let{store:i,keeper:r}=s[ce],o=typeof e,a=t!=null&&(o==="string"||o==="symbol");i.remove(e,t,a),Array.isArray(e)?r.remove(e.filter(c=>typeof c=="string")):oi(e)&&r.remove(e)}function E(s,e,...t){Ue(s)?ui(s,e,t):di(s)&&fi(s,e,t)}function gr(s,e,...t){let i=[],r=o=>{i.push(o)};return Ue(s)?ui(s,e,t,r):di(s)&&fi(s,e,t,r),i=i.map(o=>Array.isArray(o)?Promise.all(o):Promise.resolve(o)),i.length>0?Promise.all(i):Promise.resolve()}function pt(s,e){let t=yt(s),{keeper:i}=t[ce];i.add(e)}function Ke(s,e){if(!Ue(s))throw new Error("object is not eventized");let{keeper:t}=s[ce];t.clear(e)}function yr(s,e){if(!Ue(s))throw new Error("object is not eventized");let{keeper:t}=s[ce];t.remove(e)}var pr=L,vr=A,mr=x,br=E,wr=gr,Er=dr,Sr=pt,Cr=Ke,kr=yr,_=(()=>{let s=(e={})=>yt(e);return s.inject=(e={})=>(e=yt(e),Object.assign(e,{on:(...t)=>pr(e,...t),once:(...t)=>vr(e,...t),onceAsync:t=>Er(e,t),off:(t,i)=>mr(e,t,i),emit:(t,...i)=>br(e,t,...i),emitAsync:(t,...i)=>wr(e,t,...i),retain:t=>Sr(e,t),retainClear:t=>Cr(e,t),unretain:t=>kr(e,t)}),e),s.is=Ue,s})();async function ms(s,e,t,i=!0){var o,a;if(t.has(e)){console.warn("importModule: skipping already imported module",e);return}else t.add(e);e.extends&&await Promise.all(e.extends.map(c=>ms(s,c,t,!1)));let{registry:r}=s;if(e.define)for(let[c,d]of Object.entries(e.define))r.define(c,d);if(e.routes)for(let[c,d]of Object.entries(e.routes))r.appendRoute(c,d);await((a=(o=e.initialize)==null?void 0:o.call(e,{define:(c,d)=>r.define(c,d),kernel:s,registry:r}))!=null?a:Promise.resolve()),i&&s.upgradeEntities()}var te=Symbol.for("signal"),He=Symbol.for("effect"),gi=Symbol.for("destroySignal"),yi=Symbol.for("createEffect"),Ar=Symbol.for("destroyEffect"),et="value",Ss="mute",Cs="unmute",Oe="destroy",Pr="off",mt=Symbol.for("recall"),bt=_(),Pe=_(),_e=_(),Ei=_(),Ae=class{constructor(){y(this,"delayedEffects",[])}batch(e,t){let i=this.delayedEffects.length;for(let r=0;r<i;r++){let[o,a]=this.delayedEffects[r];if(!(o>t)){if(o===t){a.add(e);return}this.delayedEffects.splice(r,0,[t,new Set([e])]);return}}this.delayedEffects.push([t,new Set([e])])}flush(){this.run(),this.delayedEffects.length=0}run(){let e=new Set,t=[];try{t.push(L(_e,(i,r)=>{r===mt&&e.add(i)}),L(Ei,i=>{e.add(i)}));for(let[,i]of this.delayedEffects)for(let r of i)e.has(r)||E(_e,r,r,mt)}finally{for(let i of t)i()}}};y(Ae,"current");var Si=()=>Ae.current;function xe(s){let e=Ae.current;e?e=void 0:e=Ae.current=new Ae;try{s()}finally{e&&(Ae.current=void 0,e.run())}}var Or=0;function ks(){return Or>0}var bi;bi=He;var Gt=class{constructor(e){y(this,bi);y(this,"run",()=>{var e;return(e=this[He])==null?void 0:e.run()});y(this,"destroy",()=>{var e;(e=this[He])==null||e.destroy(),this[He]=void 0});this[He]=e,A(e,Oe,()=>{this[He]=void 0})}},bs=[],Ci=()=>bs.at(-1),xr=(s,e)=>{bs.push(s);try{return e()}finally{bs.pop()}};var Je=new WeakMap,vt=new Set,pi=new FinalizationRegistry(s=>{vt.has(s)&&s.clear()});var Q,Ee,q,le,Se,he,ue,K,je,Ye=class Ye{constructor(e){f(this,Q,new Set);f(this,Ee,new Set);f(this,q,new Map);f(this,le,new WeakMap);f(this,Se,new Map);f(this,he,new Set);f(this,ue,new Set);f(this,K);f(this,je);if(e!=null&&e instanceof Ye)return e;if(e!=null||(e=this),Je.has(e))return Je.get(e);g(this,je,new WeakRef(e)),Je.set(e,this),vt.add(this),e!==this&&pi.register(e,this,this),_(this)}static get(e){if(e!=null)return e instanceof Ye?e:Je.get(e)}static findOrCreate(e){if(e==null)throw new Error("Cannot create a group with a null object");return new Ye(e)}static destroy(e){console.warn("SignalGroup.destroy(obj) is deprecated. Use SignalGroup.delete(obj) instead."),Ye.delete(e)}static delete(e){var t;(t=Je.get(e))==null||t.clear()}static clear(){for(let e of[...vt])e.clear();vt.clear()}attachGroup(e){if(e===this)throw new Error("Cannot attach a group to itself");return n(this,Q).add(e),n(e,K)&&n(e,K)!==this&&n(n(e,K),Q).delete(e),g(e,K,this),e}detachGroup(e){return e!==this&&n(this,Q).has(e)&&(n(this,Q).delete(e),g(e,K,void 0)),e}attachSignal(e){let t=R(e);if(t!=null&&t.destroyed)throw new Error("Cannot attach a destroyed signal to a group");return t&&n(this,Ee).add(t),e}attachSignalByName(e,t){if(t){this.attachSignal(t);let i=R(t);n(this,q).set(e,i);let r=n(this,Se).get(e);r?r.add(i):n(this,Se).set(e,new Set([i])),n(this,le).has(i)?n(this,le).get(i).add(e):n(this,le).set(i,new Set([e]))}else n(this,q).delete(e);return t}hasSignal(e){var t;return n(this,q).has(e)||!!((t=n(this,K))!=null&&t.hasSignal(e))}signal(e){var t,i,r;return(r=(t=n(this,q).get(e))==null?void 0:t.object)!=null?r:(i=n(this,K))==null?void 0:i.signal(e)}detachSignal(e){let t=R(e);if(t&&(n(this,Ee).delete(t),n(this,le).has(t))){let i=n(this,le).get(t);for(let r of i){let o=n(this,Se).get(r);if(o){if(o.delete(t),o.size===0)n(this,q).delete(r),n(this,Se).delete(r);else if(n(this,q).get(r)===t){let a;for(let c of o)a=c;n(this,q).set(r,a)}}}i.clear(),n(this,le).delete(t)}return e}attachEffect(e){return n(this,he).add(e),e}runEffects(){for(let e of n(this,he))e.run();for(let e of n(this,Q))e.runEffects()}attachLink(e){if(e!=null&&e.isDestroyed)throw new Error("Cannot attach a destroyed link to a group");return e&&n(this,ue).add(e),e}detachLink(e){return e&&n(this,ue).delete(e),e}destroy(){console.warn("SignalGroup#destroy is deprecated. Use SignalGroup#clear instead."),this.clear()}off(){for(let e of n(this,Q))e.off();for(let e of n(this,he))e.destroy();n(this,he).clear();for(let e of n(this,ue))e.destroy();n(this,ue).clear();for(let e of n(this,Ee))e.destroyed||E(Pe,e.id,e.id,{detach:!0});E(this,Pr,this)}clear(){var e;E(this,Oe,this),x(this);for(let t of n(this,Q))t.clear();for(let t of n(this,he))t.destroy();for(let t of n(this,Ee))G(t);for(let t of n(this,ue))t.destroy();if(n(this,Q).clear(),n(this,Ee).clear(),n(this,q).clear(),n(this,Se).clear(),n(this,he).clear(),n(this,ue).clear(),(e=n(this,K))==null||e.detachGroup(this),n(this,je)){let t=n(this,je).deref();t!==void 0&&Je.delete(t),g(this,je,void 0)}vt.delete(this),pi.unregister(this)}};Q=new WeakMap,Ee=new WeakMap,q=new WeakMap,le=new WeakMap,Se=new WeakMap,he=new WeakMap,ue=new WeakMap,K=new WeakMap,je=new WeakMap;var ge=Ye,Et,St,$t=class{constructor(e="id",t=1){f(this,Et);f(this,St);g(this,Et,e),g(this,St,t)}make(){return Symbol(\`\${n(this,Et)}\${Tt(this,St)._++}\`)}};Et=new WeakMap,St=new WeakMap;var Mr=s=>s!=null&&typeof s.then=="function",Ce,V,fe,ke,de,Ve,Xe,Ze,j=class j{constructor(e,t){y(this,"id");y(this,"callback");f(this,Ce);f(this,V,new Set);f(this,fe,new Set);f(this,ke,new Map);f(this,de,new Set);y(this,"childEffects",[]);y(this,"curChildEffectSlot",0);y(this,"autorun",!0);y(this,"shouldRun",!0);y(this,"priority");f(this,Ve);f(this,Xe,!1);f(this,Ze,0);y(this,"run",()=>{if(n(this,Xe)||!this.shouldRun)return;let e=Si();if(e){e.batch(this.id,this.priority);return}if(n(this,Ze)>=j.maxDepth)throw new Error(\`[signalize] Effect \${this.id.toString()} exceeded maxDepth=\${j.maxDepth}: an effect callback recursively re-triggered itself (likely by writing a signal it depends on). Break the cycle, or raise EffectImpl.maxDepth if the recursion is intentional.\`);Tt(this,Ze)._++;try{if(this.runCleanupCallback(),this.destroyChildEffects(),this.curChildEffectSlot=0,this.shouldRun=!1,E(Ei,this.id,this.id),this.hasStaticDeps())g(this,Ce,this.callback());else{n(this,fe).clear();for(let t of n(this,V))n(this,fe).add(t);g(this,Ce,xr(this,this.callback)),this.cleanupLostSignals(),n(this,de).clear()}}finally{Tt(this,Ze)._--}});y(this,"destroy",()=>{n(this,Xe)||(E(this,Oe,this),x(this),E(_e,Ar,this),this.runCleanupCallback(),this.destroyChildEffects(),x(bt,this),x(_e,this),x(Pe,this),g(this,Xe,!0),n(this,V).clear(),n(this,fe).clear(),n(this,ke).clear(),n(this,de).clear(),--j.count)});var r,o;_(this),this.callback=e;let i;(t==null?void 0:t.attach)!=null&&(i=ge.findOrCreate(t.attach),i.attachEffect(this)),this.autorun=(r=t==null?void 0:t.autorun)!=null?r:!0,g(this,Ve,t!=null&&t.dependencies?t.dependencies.map(a=>{switch(typeof a){case"string":case"symbol":return i.signal(a);default:return a}}):void 0),this.id=j.idGen.make(),this.priority=(o=t==null?void 0:t.priority)!=null?o:0,L(_e,this.id,mt,this),++j.count}hasStaticDeps(){return n(this,Ve)!=null&&n(this,Ve).length>0}saveSignalsFromDeps(){for(let e of n(this,Ve))this.whenSignalIsRead(R(e).id)}static createEffect(e,t,i){let r=Array.isArray(t)?t:void 0,o=r?i!=null?i:{dependencies:r}:t;o&&r&&(o.dependencies=r);let a,c=Ci();return c!=null?(a=c.getCurrentChildEffect(),a==null&&(a=new j(e,o),c.attachChildEffect(a),E(_e,yi,a)),c.curChildEffectSlot++):(a=new j(e,o),E(_e,yi,a)),a.hasStaticDeps()?a.saveSignalsFromDeps():a.autorun&&a.run(),new Gt(a)}getCurrentChildEffect(){return this.childEffects[this.curChildEffectSlot]}attachChildEffect(e){this.childEffects.push(e)}[mt](){this.shouldRun=!0,this.autorun&&this.run()}whenSignalIsRead(e){n(this,fe).delete(e),n(this,V).has(e)||(n(this,V).add(e),n(this,ke).set(e,[L(bt,e,this.priority,mt,this),A(Pe,e,gi,this)]))}[gi](e,t){if(n(this,V).has(e)){if(t!=null&&t.detach){this.unsubscribeSignal(e),n(this,V).delete(e),n(this,de).delete(e),n(this,fe).delete(e),n(this,V).size===0&&this.destroy();return}n(this,de).has(e)||(n(this,de).add(e),this.unsubscribeSignal(e),n(this,de).size===n(this,V).size&&this.destroy())}}cleanupLostSignals(){for(let e of n(this,fe))this.unsubscribeSignal(e),n(this,V).delete(e)}destroyChildEffects(){for(let e of this.childEffects)e.destroy();this.childEffects.length=0}unsubscribeSignal(e){n(this,ke).has(e)&&(n(this,ke).get(e).forEach(t=>{t()}),n(this,ke).delete(e))}runCleanupCallback(){if(n(this,Ce)!=null){let e=n(this,Ce);g(this,Ce,void 0),Mr(e)?Promise.resolve(e).then(t=>{typeof t=="function"&&t()}):e()}}};Ce=new WeakMap,V=new WeakMap,fe=new WeakMap,ke=new WeakMap,de=new WeakMap,Ve=new WeakMap,Xe=new WeakMap,Ze=new WeakMap,y(j,"idGen",new $t("ef")),y(j,"count",0),y(j,"maxDepth",256);var ws=j,ye=ws.createEffect;var wt=new WeakMap,Lr=s=>{let e=wt.get(s);return e||(e={},wt.set(s,e)),e},Me=(s,e)=>{var t,i;return(i=(t=wt.get(s))==null?void 0:t.signals)==null?void 0:i.get(e)};var ki=(s,e,t)=>{var r;let i=Lr(s);(r=i.signals)!=null||(i.signals=new Map),i.signals.set(e,t)};function As(...s){for(let e of s)if(wt.has(e)){let t=wt.get(e);if(t.signals){for(let i of t.signals.values())G(i);t.signals.clear(),t.signals=void 0}}}function Ai(s){let e=R(We(s)?s:Me(...s));e!=null&&!e.muted&&!e.destroyed&&Es(e.id,e.value,{touch:!0})}function tt(s){var e,t;return We(s)?(e=R(s))==null?void 0:e.value:(t=R(Me(...s)))==null?void 0:t.value}var wi;wi=te;var Nt=class{constructor(e){y(this,wi);this[te]=e}get get(){return this[te].reader}get set(){return this[te].writer}get value(){return tt(this.get)}set value(e){this.set(e)}onChange(e){let{destroy:t}=ye(()=>e(this.value),[this.get]);return t}get muted(){return this[te].muted}set muted(e){this[te].muted=e}touch(){Ai(this)}destroy(){G(this)}},Rr=new $t("si"),vi=!1;function Tr(){vi||(vi=!0,console.warn("signalReader(callback) is deprecated and will be removed in a future release. Use Signal.onChange(callback) instead \\u2014 it returns an unsubscribe function for proper cleanup."))}function mi(s){var e;ks()||(e=Ci())==null||e.whenSignalIsRead(s)}function Es(s,e,t){ks()||E(bt,s,e,t)}var We=s=>s!=null&&s[te]!=null,Dr=s=>{let e=t=>{var i;return s.destroyed||(i=s.beforeRead)==null||i.call(s),t?(Tr(),ye(()=>(s.destroyed||mi(s.id),t(s.value)),[e])):s.destroyed||mi(s.id),s.value};return Object.defineProperty(e,te,{value:s}),e},H,_t=class _t{constructor(e,t){y(this,"id");y(this,"lazy");y(this,"compare");y(this,"beforeRead");y(this,"muted",!1);y(this,"destroyed",!1);f(this,H);y(this,"valueFn");y(this,"reader");y(this,"writer",(e,t)=>{var c,d,w;let i=(c=t==null?void 0:t.lazy)!=null?c:!1,r=(d=t==null?void 0:t.compare)!=null?d:this.compare,o=r!=null?r:((k,v)=>k===v);if((i!==this.lazy||i&&e!==this.valueFn||!i&&!o(e,n(this,H)))&&(i?(g(this,H,void 0),this.valueFn=e,this.lazy=!0):(g(this,H,e),this.valueFn=void 0,this.lazy=!1),!this.muted&&!this.destroyed)){Es(this.id,n(this,H));return}(w=t==null?void 0:t.touch)!=null&&w&&!this.muted&&!this.destroyed&&Es(this.id,n(this,H),{touch:!0})});y(this,"object");this.id=Rr.make(),++_t.instanceCount,this.lazy=e,this.lazy?(this.value=void 0,this.valueFn=t):(this.value=t,this.valueFn=void 0),this.reader=Dr(this),this.object=new Nt(this)}get[te](){return this}get value(){return this.lazy&&(g(this,H,this.valueFn()),this.valueFn=void 0,this.lazy=!1),n(this,H)}set value(e){g(this,H,e)}};H=new WeakMap,y(_t,"instanceCount",0);var Ut=_t,R=s=>s==null?void 0:s[te];function O(s=void 0,e){var i;let t;if(We(s))t=R(s);else{let r=(i=e==null?void 0:e.lazy)!=null?i:!1;t=new Ut(r,s),t.beforeRead=e==null?void 0:e.beforeRead,t.compare=e==null?void 0:e.compare}return(e==null?void 0:e.attach)!=null&&ge.findOrCreate(e.attach).attachSignal(t),t.object}var G=(...s)=>{for(let e of s){let t=R(e);t!=null&&!t.destroyed&&(t.destroyed=!0,t.beforeRead=void 0,--Ut.instanceCount,E(Pe,t.id,t.id))}};function jt(s,e){var a,c;let t=O(),i=(e==null?void 0:e.attach)!=null?ge.findOrCreate(e.attach):void 0;i!=null&&(e!=null&&e.name?i.attachSignalByName(e.name,t):i.attachSignal(t));let r=ye(()=>{xe(()=>{t.set(s())})},{autorun:!((a=e==null?void 0:e.lazy)!=null&&a),priority:(c=e==null?void 0:e.priority)!=null?c:we.C,attach:i}),o=R(t);return o.beforeRead=r.run,A(Pe,o.id,r.destroy),t.get}var z,st,Wt=class{constructor(e){f(this,z,!1);f(this,st);y(this,"source");y(this,"lastValue");y(this,"isDestroyed",!1);_(this),this.source=R(e),g(this,st,L(bt,this.source.id,(t,i)=>{!n(this,z)&&!this.isDestroyed&&((i==null?void 0:i.touch)===!0?this.touch():this.write())})),A(Pe,this.source.id,()=>this.destroy())}attach(e){let t=ge.findOrCreate(e);return t.attachLink(this),A(this,Oe,()=>{t.detachLink(this)}),t}nextValue(){return new Promise((e,t)=>{let i=[],r=()=>i.forEach(o=>{o()});i.push(A(this,et,o=>{r(),e(o)}),A(this,Oe,()=>{r(),t()}))})}asyncValues(e){return Vs(this,null,function*(){pt(this,et);try{let t=0;for(;!this.isDestroyed;)try{let i=yield new os(this.nextValue());if(e!=null&&e(i,t++))break;yield i}catch(i){break}}finally{Ke(this,et)}})}destroy(){var e;this.isDestroyed||((e=n(this,st))==null||e.call(this),g(this,st,void 0),E(this,Oe,this),Ke(this,et),x(this),this.lastValue=void 0,this.isDestroyed=!0,Object.freeze(this))}get isMuted(){return n(this,z)}mute(){return!this.isDestroyed&&!n(this,z)&&(g(this,z,!0),E(this,Ss,this)),this}unmute(){return!this.isDestroyed&&n(this,z)&&(g(this,z,!1),E(this,Cs,this)),this}toggleMute(){return this.isDestroyed||(g(this,z,!n(this,z)),E(this,n(this,z)?Ss:Cs,this)),n(this,z)}updateValue(e){if(!n(this,z)&&!this.isDestroyed){let{value:t}=this.source;e(t),E(this,et,t),this.lastValue=t}}};z=new WeakMap,st=new WeakMap;var Ps=class extends Wt{constructor(t,i){super(t);y(this,"target");this.target=R(i),A(Pe,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)})}},Os=class extends Wt{constructor(t,i){super(t);y(this,"target");this.target=i,this.touch()}touch(){return this.updateValue(t=>{this.target(t)}),this}write(){this.updateValue(t=>{this.target(t)})}},Vt=new Map;function J(s,e,t){let i=R(s),r=R(e),o=r!=null?r:e,a;if(Vt.has(i)){if(a=Vt.get(i),a.has(o))return a.get(o)}else a=new Map,Vt.set(i,a);let c=r!=null?new Ps(s,r):new Os(s,e),d=t==null?void 0:t.attach;return d&&c.attach(d),a.set(o,c),A(c,Oe,()=>{a.delete(o),a.size===0&&Vt.delete(i)}),c}var $,xs=class xs{constructor(){f(this,$,new Map)}static fromProps(e,t){let i=new xs,r=t?t.map(o=>[o,e[o]]):Object.entries(e);for(let[o,a]of r)n(i,$).set(o,O(a));return i}keys(){return n(this,$).keys()}signals(){return n(this,$).values()}entries(){return n(this,$).entries()}clear(){for(let e of n(this,$).values())e.destroy();n(this,$).clear()}has(e){return n(this,$).has(e)}get(e){if(!n(this,$).has(e)){let t=O();return n(this,$).set(e,t),t}return n(this,$).get(e)}update(e){e.size&&xe(()=>{for(let[t,i]of e.entries())this.get(t).set(i)})}updateFromProps(e,t){xe(()=>{let i=t?t.map(r=>[r,e[r]]):Object.entries(e);for(let[r,o]of i)this.get(r).set(o)})}};$=new WeakMap;var It=xs;var Qt=s=>s!=null?s:void 0;var Ms=Symbol("onCreate"),se=Symbol("onDestroy"),Pi=Symbol("onParentChanged"),qt=Symbol("onViewEvent");function Oi(s){return function(e,t){var o;let i=(s==null?void 0:s.name)||t.name,r=!!((o=s==null?void 0:s.readAsValue)!=null&&o);return{get(){let a=Me(this,i);if(a)return r?a.value:a.get()},set(a){var c;(c=Me(this,i))==null||c.set(a)},init(a){let c=O(a,s);return ki(this,i,c),ge.findOrCreate(this).attachSignalByName(i,c),c.value}}}}var zr=Object.create,Ls=Object.defineProperty,Br=Object.getOwnPropertyDescriptor,Li=(s,e)=>(e=Symbol[s])?e:Symbol.for("Symbol."+s),rt=s=>{throw TypeError(s)},Fr=(s,e,t)=>e in s?Ls(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,xi=(s,e)=>Ls(s,"name",{value:e,configurable:!0}),Gr=s=>{var e;return[,,,zr((e=s==null?void 0:s[Li("metadata")])!=null?e:null)]},Ri=["class","method","getter","setter","accessor","field","value","get","set"],Ct=s=>s!==void 0&&typeof s!="function"?rt("Function expected"):s,$r=(s,e,t,i,r)=>({kind:Ri[s],name:e,metadata:i,addInitializer:o=>t._?rt("Already initialized"):r.push(Ct(o||null))}),Ti=(s,e)=>Fr(e,Li("metadata"),s[3]),Mi=(s,e,t,i)=>{for(var r=0,o=s[e>>1],a=o&&o.length;r<a;r++)e&1?o[r].call(t):i=o[r].call(t,i);return i},Nr=(s,e,t,i,r,o)=>{var a,c,d,w,k,v=e&7,B=!!(e&8),M=!!(e&16),C=v>3?s.length+1:v?B?1:2:0,at=Ri[v+5],u=v>3&&(s[C-1]=[]),h=s[C]||(s[C]=[]),l=v&&(!M&&!B&&(r=r.prototype),v<5&&(v>3||!M)&&Br(v<4?r:{get[t](){return N(this,o)},set[t](m){return At(this,o,m)}},t));v?M&&v<4&&xi(o,(v>2?"set ":v>1?"get ":"")+t):xi(r,t);for(var p=i.length-1;p>=0;p--)w=$r(v,t,d={},s[3],h),v&&(w.static=B,w.private=M,k=w.access={has:M?m=>Ur(r,m):m=>t in m},v^3&&(k.get=M?m=>(v^1?N:Le)(m,r,v^4?o:l.get):m=>m[t]),v>2&&(k.set=M?(m,oe)=>At(m,r,oe,v^4?o:l.set):(m,oe)=>m[t]=oe)),c=(0,i[p])(v?v<4?M?o:l[at]:v>4?void 0:{get:l.get,set:l.set}:r,w),d._=1,v^4||c===void 0?Ct(c)&&(v>4?u.unshift(c):v?M?o=c:l[at]=c:r=c):typeof c!="object"||c===null?rt("Object expected"):(Ct(a=c.get)&&(l.get=a),Ct(a=c.set)&&(l.set=a),Ct(a=c.init)&&u.unshift(a));return v||Ti(s,r),l&&Ls(r,t,l),M?v^4?o:l:r},Rs=(s,e,t)=>e.has(s)||rt("Cannot "+t),Ur=(s,e)=>Object(e)!==e?rt('Cannot use the "in" operator on this value'):s.has(e),N=(s,e,t)=>(Rs(s,e,"read from private field"),t?t.call(s):e.get(s)),Kt=(s,e,t)=>e.has(s)?rt("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,t),At=(s,e,t,i)=>(Rs(s,e,"write to private field"),i?i.call(s,t):e.set(s,t),t),Le=(s,e,t)=>(Rs(s,e,"access private method"),t),Di,ie,Re,Pt,Ts,pe,Ht,kt,it="value";Di=[Oi({name:it})];var re=class{constructor(e){Kt(this,pe),Kt(this,ie,[]),Kt(this,Re),Kt(this,Ts,Mi(Pt,8,this)),Mi(Pt,11,this),this.value$=void 0,pt(this,it),this.value$=Me(this,it),this.value$.onChange(t=>E(this,it,t)),e&&this.add(...e)}add(...e){return N(this,ie).push(...e),Le(this,pe,kt).call(this),Le(this,pe,Ht).call(this,e)}unshift(...e){return N(this,ie).unshift(...e),Le(this,pe,kt).call(this),Le(this,pe,Ht).call(this,e)}remove(...e){Le(this,pe,Ht).call(this,e)()}clear(){N(this,ie).length=0,Le(this,pe,kt).call(this)}dispose(){var e;this.clear(),(e=N(this,Re))==null||e.destroy(),At(this,Re,void 0),Ke(this,it),x(this),this.value$.destroy(),As(this)}};Pt=Gr(null);ie=new WeakMap;Re=new WeakMap;Ts=new WeakMap;pe=new WeakSet;Ht=function(s){return()=>{for(let e of s){let t=N(this,ie).indexOf(e);t!==-1&&N(this,ie).splice(t,1)}Le(this,pe,kt).call(this)}};kt=function(){var s;(s=N(this,Re))==null||s.destroy(),N(this,ie).length===0?(At(this,Re,void 0),this.value=void 0):(At(this,Re,ye(()=>{let e;for(let t of N(this,ie)){let i=tt(t);if(i!=null){e=i;break}}this.value=e},N(this,ie))),N(this,Re).run())};Nr(Pt,4,"value",Di,re,Ts);Ti(Pt,re);re.Value=it;var Ds=new Map,zs=!1,_r=(s,e)=>{Ds.set(s,e),zs||(zs=!0,queueMicrotask(()=>{zs=!1;let t=Array.from(Ds.entries());Ds.clear();for(let[i,r]of t)i.set(r)}))},Y,Ie,Te,X,De,W,T,ve,I,nt,Qe,me,P,Bs,Fs,Gs,ze,Ot,Jt,Yt=class{constructor(e,t){f(this,P);f(this,Y);f(this,Ie);f(this,Te,new It);f(this,X,new Map);f(this,De,new Map);f(this,W);f(this,T);f(this,ve,new Set);f(this,I,[]);f(this,nt,0);f(this,Qe,!1);f(this,me);f(this,ze);g(this,Y,e),g(this,Ie,t),A(this,se,we.Min,this)}get kernel(){return n(this,Y)}get uuid(){return n(this,Ie)}get order(){return n(this,nt)}set order(e){n(this,nt)!==e&&(g(this,nt,e),n(this,W)&&this.parent.resortChildren())}get parentUuid(){return n(this,W)||void 0}set parentUuid(e){if(n(this,W)!==e){let t=e?n(this,Y).getEntity(e):void 0;this.removeFromParent(),g(this,W,e||void 0),g(this,T,t),n(this,T)&&n(this,T).addChild(this),S(this,P,Fs).call(this)}}get parent(){return!n(this,T)&&n(this,W)&&g(this,T,n(this,Y).getEntity(n(this,W))),n(this,T)}set parent(e){this.parentUuid=e==null?void 0:e.uuid}get hasParent(){return!!n(this,W)}get children(){return n(this,I)}traverse(e){e(this);for(let t of n(this,I))t.traverse(e)}[se](){var e,t;n(this,Te).clear(),x(this),(e=n(this,me))==null||e.call(this);for(let i of n(this,De).values())i.cleanup(),i.signal.destroy();n(this,De).clear();for(let i of n(this,X).values())i.context.set(void 0),i.unsubscribePathValue(),(t=i.unsubscribeFromParent)==null||t.call(i),i.valuePath.dispose(),i.inherited.destroy(),i.provide.destroy(),i.context.destroy();g(this,W,void 0),g(this,T,void 0),n(this,ve).clear(),n(this,I).length=0}addChild(e){var t;if(n(this,I).length===0){n(this,ve).add(e.uuid),n(this,I).push(e);return}if(n(this,ve).has(e.uuid))throw new Error(\`child with uuid: \${e.uuid} already exists! parentUuid: \${this.uuid}\`);n(this,ve).add(e.uuid),n(this,I).push(e),this.resortChildren();for(let[,i]of n(e,X))S(t=e,P,Jt).call(t,i)}resortChildren(){n(this,I).sort((e,t)=>e.order-t.order)}removeChild(e){n(this,ve).has(e.uuid)&&(n(this,ve).delete(e.uuid),n(this,I).splice(n(this,I).indexOf(e),1))}removeFromParent(){if(n(this,T)){n(this,T).removeChild(this),g(this,T,void 0),g(this,W,void 0);for(let[,e]of n(this,X))e.unsubscribeFromParent&&(e.unsubscribeFromParent(),e.unsubscribeFromParent=void 0);S(this,P,Bs).call(this)}}get autoDestructionOnParentRemoval(){return n(this,Qe)}set autoDestructionOnParentRemoval(e){n(this,Qe)!==e&&(g(this,Qe,e),S(this,P,Fs).call(this))}reSubscribeToParentContexts(){for(let[,e]of n(this,X))S(this,P,Jt).call(this,e)}dispatchMessageToView(e,t,i,r=!1){n(this,Y).dispatchMessageToView({uuid:n(this,Ie),type:e,data:t,transferables:i,traverseChildren:r})}dispatchViewEvents(e){for(let{type:t,data:i}of e)E(this,qt,t,i)}dispatchViewEvent(e,t){this.dispatchViewEvents([{type:e,data:t}])}getPropertyReader(e){return S(this,P,Gs).call(this,e).get}getPropertyWriter(e){return S(this,P,Gs).call(this,e).set}setProperties(e){this.clearTruthyPropsCache(),xe(()=>{for(let[t,i]of e)this.setProperty(t,i)})}setProperty(e,t){this.getPropertyWriter(e)(t)}getProperty(e){return tt(this.getPropertyReader(e))}propKeys(){return Array.from(n(this,Te).keys())}propEntries(){return Array.from(n(this,Te).entries()).map(([e,t])=>[e,t.value])}clearTruthyPropsCache(){g(this,ze,void 0)}truthyProps(){if(n(this,ze))return n(this,ze).size?n(this,ze):void 0;let e=new Set;for(let[t,i]of n(this,Te).entries())if(typeof t=="string"){let r=i.value;r!=null&&r!==!1&&r!==""&&e.add(t)}return g(this,ze,e),e.size?e:void 0}hasContext(e){return n(this,X).has(e)}useContext(e){return S(this,P,Ot).call(this,e).context.get}useParentContext(e){return S(this,P,Ot).call(this,e).inherited.get}provideContext(e){return S(this,P,Ot).call(this,e).provide}provideGlobalContext(e){if(n(this,De).has(e))return n(this,De).get(e).signal;let t=n(this,Y).findOrCreateRootContext(e),i=O(),r=t.add(i);return n(this,De).set(e,{cleanup:r,signal:i}),i}};Y=new WeakMap,Ie=new WeakMap,Te=new WeakMap,X=new WeakMap,De=new WeakMap,W=new WeakMap,T=new WeakMap,ve=new WeakMap,I=new WeakMap,nt=new WeakMap,Qe=new WeakMap,me=new WeakMap,P=new WeakSet,Bs=function(){n(this,me)&&(n(this,me).call(this),g(this,me,void 0))},Fs=function(){S(this,P,Bs).call(this),n(this,Qe)&&n(this,T)&&g(this,me,A(n(this,T),se,we.Max,()=>{g(this,me,void 0),n(this,Y).destroyEntity(n(this,Ie))}))},Gs=function(e){return n(this,Te).get(e)},ze=new WeakMap,Ot=function(e){if(n(this,X).has(e))return n(this,X).get(e);let t=O(),i=O(),r=O(),o=new re([i,t]),a=L(o,re.Value,d=>{_r(r,d)}),c={name:e,inherited:t,provide:i,context:r,valuePath:o,unsubscribePathValue:a};return n(this,X).set(e,c),S(this,P,Jt).call(this,c),c},Jt=function(e){var t,i;if((t=e.unsubscribeFromParent)==null||t.call(e),e.unsubscribeFromParent=void 0,this.parent){let r=S(i=this.parent,P,Ot).call(i,e.name),o=J(r.context,e.inherited);e.unsubscribeFromParent=o.destroy.bind(o)}else{let r=n(this,Y).findOrCreateRootContext(e.name),o=J(r.value$,e.inherited);e.unsubscribeFromParent=o.destroy.bind(o)}};function zi(s,e){s.indexOf(e)===-1&&s.push(e)}var Bi=s=>{let e=s.split("@").map(t=>t.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]}},Xt=(s,e)=>{for(let t of e)s.add(t)},jr=(s,e)=>{if(s!=null)for(let t of s.constructors)e.add(t)},Be,ne,be,xt=class{constructor(){f(this,Be,new Map);f(this,ne,new Map);f(this,be,new Map)}static get(e){return e!=null?e:Vr}define(e,t){let i=n(this,Be).get(e);i?zi(i.constructors,t):n(this,Be).set(e,{token:e,constructors:[t]})}appendRoute(e,t){let i=Bi(e);if(i){let r=n(this,be).get(i.key);r?Xt(r.routes,t):n(this,be).set(i.key,{routes:new Set(t),token:i.token})}else{let r=n(this,ne).get(e);r?Xt(r,t):n(this,ne).set(e,new Set(t))}}clearRoute(e){let t=Bi(e);t?n(this,be).delete(t.key):n(this,ne).delete(e)}findTokensByRoute(e,t){var o;let i=new Set([e]),r=Array.from((o=n(this,ne).get(e))!=null?o:[]);for(let a=r.shift();a!==void 0;a=r.shift()){if(i.has(a))continue;i.add(a);let c=n(this,ne).get(a);c&&r.push(...Array.from(c).filter(d=>!i.has(d)))}if(t){for(let c of t){let d=n(this,be).get(c);d&&Xt(i,d.routes)}let a;do{a=i.size;for(let c of new Set(i))for(let d of t){let w=n(this,be).get(\`\${c}@\${d}\`);w&&Xt(i,w.routes)}}while(a!==i.size)}return i}findConstructors(e,t){let i=this.findTokensByRoute(e,t),r=new Set;for(let o of i)jr(n(this,Be).get(o),r);return r.size>0?Array.from(r):void 0}hasToken(e){return n(this,Be).has(e)}hasRoute(e){return n(this,ne).has(e)}clear(){n(this,Be).clear(),n(this,ne).clear(),n(this,be).clear()}};Be=new WeakMap,ne=new WeakMap,be=new WeakMap;var Vr=new xt;var Fi=s=>s.displayName||s.name,Gi=!1,$i=!1,Ni=!1,Ui=!1,_i=!1,U,Z,qe,ot,ee,Fe,Mt,$s,Zt=class{constructor(e){f(this,Mt);f(this,U);f(this,Z);f(this,qe);f(this,ot);f(this,ee);f(this,Fe);this.logger=new Ft("Kernel"),g(this,U,new Map),g(this,Z,new Set),g(this,qe,[]),g(this,ot,[]),g(this,ee,!0),g(this,Fe,new Map),_(this),this.registry=xt.get(e)}getEntity(e){return S(this,Mt,$s).call(this,e).entity}hasEntity(e){return n(this,U).has(e)}traverseLevelOrderBFS(e=!1){if(n(this,ee)){let t=new Map,i=(r,o)=>{let a=this.getEntity(r),c=t.get(o);c?c.push(a):t.set(o,[a]);for(let d of a.children)i(d.uuid,o+1)};n(this,Z).forEach(r=>{i(r,0)}),g(this,qe,Array.from(t.entries()).sort((r,o)=>r[0]-o[0]).flatMap(([,r])=>r)),g(this,ot,n(this,qe).slice().reverse()),g(this,ee,!1)}return e?n(this,ot):n(this,qe)}getEntityGraph(){return Array.from(n(this,Z)).map(e=>this.getEntityGraphNode(e)).filter(e=>e!==void 0)}getEntityGraphNode(e){let t=n(this,U).get(e);if(t===void 0)return;let{token:i,entity:r}=t;return{token:i,entity:r,props:Object.fromEntries(r.propEntries()),children:r.children.map(o=>this.getEntityGraphNode(o.uuid)).filter(o=>o!==void 0)}}upgradeEntities(){let e=new Map;for(let t of this.traverseLevelOrderBFS(!0))this.hasEntity(t.uuid)&&e.set(t.uuid,this.updateShadowObjects(t.uuid,2));for(let t of this.traverseLevelOrderBFS(!1))this.hasEntity(t.uuid)&&this.updateShadowObjects(t.uuid,1,e.get(t.uuid));e.clear()}run(e){this.logger.isDebug&&this.logger.debug("sync",e),xe(()=>{for(let t of e.changeTrail)this.parse(t)})}parse(e){switch(e.type){case ae.CreateEntities:this.createEntity(e.uuid,e.token,e.parentUuid,e.order,e.properties,e.autoDestructionOnParentRemoval),g(this,ee,!0);break;case ae.DestroyEntities:this.destroyEntity(e.uuid),g(this,ee,!0);break;case ae.SetParent:this.setParent(e.uuid,e.parentUuid,e.order),g(this,ee,!0);break;case ae.UpdateOrder:this.updateOrder(e.uuid,e.order),g(this,ee,!0);break;case ae.ChangeProperties:this.changeProperties(e.uuid,e.properties);break;case ae.ChangeToken:this.changeToken(e.uuid,e.token);break;case ae.SendEvents:this.dispatchEventsToEntity(e.uuid,e.events);break}}createEntity(e,t,i,r=0,o,a=!1){let c=new Yt(this,e);c.order=r;let d={token:t,entity:c,usedConstructors:new Map};n(this,U).set(e,d),i&&(c.parentUuid=i),c.autoDestructionOnParentRemoval=a,c.hasParent||n(this,Z).add(e),o&&c.setProperties(o),this.createShadowObjects(d)}destroyEntity(e){let t=n(this,U).get(e);if(t===void 0)return;let{entity:i,usedConstructors:r}=t,o=[...i.children];for(let a of o)a.autoDestructionOnParentRemoval?this.destroyEntity(a.uuid):(a.removeFromParent(),n(this,Z).add(a.uuid));i.removeFromParent(),E(i,se,i),r.clear(),n(this,U).delete(i.uuid),n(this,Z).delete(i.uuid),g(this,ee,!0)}setParent(e,t,i){let r=this.getEntity(e),o=i!=null?i:r.order;if(!(r.parentUuid===t&&r.order===o)){if(t&&!n(this,U).has(t))throw new Error(\`entity with uuid "\${t}" not found!\`);r.removeFromParent(),r.order=o,r.parentUuid=t,r.hasParent?n(this,Z).delete(e):n(this,Z).add(e),r.reSubscribeToParentContexts(),queueMicrotask(()=>{this.logger.isDebug&&this.logger.debug("entity.onParentChanged",{uuid:e,parentUuid:t,order:o,entity:r}),E(r,Pi,r)})}}updateOrder(e,t){this.getEntity(e).order=t}dispatchEventsToEntity(e,t){var i;(i=this.getEntity(e))==null||i.dispatchViewEvents(t)}changeProperties(e,t){this.getEntity(e).setProperties(t),this.updateShadowObjects(e)}changeToken(e,t){let i=n(this,U).get(e);i!==void 0&&i.token!==t&&(i.token=t,this.updateShadowObjects(e))}dispatchMessageToView(e){queueMicrotask(()=>{E(this,ut,e)})}updateShadowObjects(e,t=0,i){let r=S(this,Mt,$s).call(this,e);i!=null||(i=new Set(this.registry.findConstructors(r.token,r.entity.truthyProps())));let o=t===0||t===2,a=t===0||t===1;if(o){for(let[c,d]of r.usedConstructors)if(!i.has(c)){r.usedConstructors.delete(c);for(let w of d)this.destroyShadowObject(w,r.entity)}}if(a)for(let c of i)r.usedConstructors.has(c)||this.constructShadowObject(c,r);return i}constructShadowObject(e,t){let i=new Set,r=new Set,o=new Map,a=new Map,c=new Map,d=new Map,w=new Map,k=new Map,v=new Map,B=new Map,M=(u,h)=>{!_i&&h!=null&&typeof h=="function"&&(console.warn('[shadow-objects] Deprecation Warning: The "isEqual" option of "useProperty()" is now passed as {compare} argument. Please update your code accordingly.'),_i=!0);let l=typeof h=="function"?{compare:h}:h,p=v.get(u);if(p===void 0){p=O(void 0,l).get,v.set(u,p),B.set(u,l==null?void 0:l.compare);let m=J(t.entity.getPropertyReader(u),p);r.add(m.destroy.bind(m))}else(l==null?void 0:l.compare)!=null&&B.get(u)!==l.compare&&console.warn(\`[shadow-objects] useProperty("\${u}"): the cached signal already exists with a different (or no) {compare} function \\u2014 the new options are ignored. Pass options only on the first call per property.\`);return p},C=_(new e({entity:t.entity,provideContext(u,h,l){var oe;!Gi&&l!=null&&typeof l=="function"&&(console.warn('[shadow-objects] Deprecation Warning: The "isEqual" option of "provideContext()" is now passed as {compare} argument. Please update your code accordingly.'),Gi=!0);let p=typeof l=="function"?{compare:l}:l,m=w.get(u);if(m==null){let ct=We(h),ss=ct?void 0:Qt(h);if(m=O(ss,p!=null&&p.compare?{compare:p.compare}:void 0),ct){let ht=J(h,m);r.add(ht.destroy.bind(ht))}let lt=J(m,t.entity.provideContext(u));r.add(lt.destroy.bind(lt)),w.set(u,m)}return m!=null&&((oe=p==null?void 0:p.clearOnDestroy)==null||oe)&&r.add(()=>{m.set(void 0)}),m},provideGlobalContext(u,h,l){var oe;!$i&&l!=null&&typeof l=="function"&&(console.warn('[shadow-objects] Deprecation Warning: The "isEqual" option of "provideGlobalContext()" is now passed as {compare} argument. Please update your code accordingly.'),$i=!0);let p=typeof l=="function"?{compare:l}:l,m=k.get(u);if(m==null){let ct=We(h),ss=ct?void 0:Qt(h);if(m=O(ss,p!=null&&p.compare?{compare:p.compare}:void 0),ct){let ht=J(h,m);r.add(ht.destroy.bind(ht))}let lt=J(m,t.entity.provideGlobalContext(u));r.add(lt.destroy.bind(lt)),k.set(u,m)}return m!=null&&((oe=p==null?void 0:p.clearOnDestroy)==null||oe)&&r.add(()=>{m.set(void 0)}),m},useContext(u,h){!Ni&&h!=null&&typeof h=="function"&&(console.warn('[shadow-objects] Deprecation Warning: The "isEqual" option of "useContext()" is now passed as {compare} argument. Please update your code accordingly.'),Ni=!0);let l=typeof h=="function"?{compare:h}:h,p=o.get(u);if(p===void 0){p=O(void 0,l).get,o.set(u,p),a.set(u,l==null?void 0:l.compare);let m=J(t.entity.useContext(u),p);r.add(m.destroy.bind(m))}else(l==null?void 0:l.compare)!=null&&a.get(u)!==l.compare&&console.warn(\`[shadow-objects] useContext("\${String(u)}"): the cached signal already exists with a different (or no) {compare} function \\u2014 the new options are ignored. Pass options only on the first call per context.\`);return p},useParentContext(u,h){!Ui&&h!=null&&typeof h=="function"&&(console.warn('[shadow-objects] Deprecation Warning: The "isEqual" option of "useParentContext()" is now passed as {compare} argument. Please update your code accordingly.'),Ui=!0);let l=typeof h=="function"?{compare:h}:h,p=c.get(u);if(p===void 0){p=O(void 0,l).get,c.set(u,p),d.set(u,l==null?void 0:l.compare);let m=J(t.entity.useParentContext(u),p);r.add(m.destroy.bind(m))}else(l==null?void 0:l.compare)!=null&&d.get(u)!==l.compare&&console.warn(\`[shadow-objects] useParentContext("\${String(u)}"): the cached signal already exists with a different (or no) {compare} function \\u2014 the new options are ignored. Pass options only on the first call per parent context.\`);return p},dispatchMessageToView(u,h,l,p=!1){t.entity.dispatchMessageToView(u,h,l,p)},useProperty:M,useProperties(u){let h={};for(let l in u)Object.hasOwn(u,l)&&(h[l]=M(u[l]));return h},createResource(u,h){let l=O(),p=ye(()=>{let m=Qt(u());return l.set(m),m!==void 0&&h?()=>{h(m),l.set(void 0)}:()=>{l.set(void 0)}});return r.add(()=>{p.destroy(),l.set(void 0),G(l)}),l},createEffect(...u){let h=ye(...u);return r.add(h.destroy),h},createSignal(...u){let h=O(...u);return r.add(()=>{G(h)}),h},createMemo(...u){let h=jt(...u);return r.add(()=>{G(h)}),h},on(...u){let[h]=u;if(typeof h=="string"||typeof h=="symbol"||Array.isArray(h)){let p=L(t.entity,...u);return r.add(p),p}let l=L(...u);return r.add(l),Object.assign(()=>{r.delete(l),l()},l)},once(...u){let[h]=u;if(typeof h=="string"||typeof h=="symbol"||Array.isArray(h)){let p=A(t.entity,...u);return r.add(p),p}let l=A(...u);return r.add(l),Object.assign(()=>{r.delete(l),l()},l)},emit(...u){let[h]=u;typeof h=="string"||typeof h=="symbol"||Array.isArray(h)?E(t.entity,...u):E(...u)},onViewEvent(u){let h=L(t.entity,qt,(l,p)=>{u(l,p)});r.add(h)},onDestroy(u){i.add(u)}}));this.logger.isInfo&&this.logger.info("create shadow-object",Fi(e),{shadowObject:C,entity:t.entity}),A(t.entity,se,we.Low,()=>{this.logger.isInfo&&this.logger.info("destroy shadow-object",Fi(e),{shadowObject:C,entity:t.entity});for(let h of i)h();for(let h of r)h();for(let h of o.values())G(h);for(let h of c.values())G(h);for(let h of v.values())G(h);for(let h of w.values())G(h);for(let h of k.values())G(h);i.clear(),r.clear(),o.clear(),c.clear(),v.clear(),w.clear(),k.clear();let u=t.usedConstructors.get(e);u&&(u.delete(C),u.size===0&&t.usedConstructors.delete(e))});let at=t.usedConstructors.get(e);return at?at.add(C):t.usedConstructors.set(e,new Set([C])),this.attachShadowObject(C,t.entity),C}createShadowObjects(e){var t;(t=this.registry.findConstructors(e.token,e.entity.truthyProps()))==null||t.forEach(i=>{this.constructShadowObject(i,e)})}findShadowObjects(e){let t=n(this,U).get(e);if(t===void 0)return[];let{usedConstructors:i}=t;return Array.from(new Set(Array.from(i.values()).flatMap(r=>Array.from(r))))}attachShadowObject(e,t){L(t,e),typeof e[Ms]=="function"&&e[Ms](t)}destroyShadowObject(e,t){typeof e[se]=="function"&&e[se](t),E(e,se,t),x(t,e)}findOrCreateRootContext(e){let t=n(this,Fe).get(e);return t||(t=new re,n(this,Fe).set(e,t)),t}destroy(){for(let e of n(this,Fe).values())e.dispose();n(this,Fe).clear();for(let e of this.traverseLevelOrderBFS().reverse())this.destroyEntity(e.uuid)}};U=new WeakMap,Z=new WeakMap,qe=new WeakMap,ot=new WeakMap,ee=new WeakMap,Fe=new WeakMap,Mt=new WeakSet,$s=function(e){let t=n(this,U).get(e);if(t===void 0)throw new Error(\`entity with uuid "\${e}" not found!\`);return t};var ji=s=>(typeof s=="string"&&(s=new URL(s,globalThis.location.href)),s.toString());var Lt,Ge,Vi,Wi,Ii,es=class{constructor(e){f(this,Ge);f(this,Lt,new Set);var t,i;this.kernel=(t=e==null?void 0:e.kernel)!=null?t:new Zt,this.postMessage=(i=e==null?void 0:e.postMessage)!=null?i:self.postMessage.bind(self),L(this.kernel,ut,"onMessageToView",this)}route(e){var t;switch(e.data.type){case Ws:S(this,Ge,Vi).call(this,e.data);break;case Is:S(this,Ge,Wi).call(this,e.data);break;case Qs:S(this,Ge,Ii).call(this,e.data);break;default:console.warn("[MessageRouter] unknown message",(t=e.data.type)!=null?t:e.data)}}onMessageToView(e){let r=e,{transferables:t}=r,i=js(r,["transferables"]);this.postMessage({type:ut,data:i},{transfer:t})}};Lt=new WeakMap,Ge=new WeakSet,Vi=async function(e){let t=e.importModule;try{if(!t)throw new Error('missing "importModule" url');let i=await import(ji(t));i[zt]?(await ms(this.kernel,i[zt],n(this,Lt)),this.postMessage({type:Dt,url:t})):this.postMessage({type:Dt,url:t,error:\`module has no "\${zt}" export\`})}catch(i){console.error("[MessageRouter] failed to import module",i),this.postMessage({type:Dt,url:t,error:\`\${i}\`})}},Wi=function(e){try{this.kernel.run(e)}catch(t){console.error("[MessageRouter] failed to apply change trail",t),this.postMessage({type:as,serial:e.serial,error:\`\${t}\`})}e.serial&&this.postMessage({type:as,serial:e.serial})},Ii=function(e){console.debug("[MessageRouter] on destroy",e),x(this.kernel,this),n(this,Lt).clear(),this.postMessage({type:Ks})};var ts=class{constructor(){this.onmessage=e=>{var t;e.data.type===F?globalThis[D]=e.data.config:((t=this.router)!=null||(this.router=new es),this.router.route(e))}}start(){self.addEventListener("message",this.onmessage),self.postMessage({type:qs})}};console.debug("@spearwolf/shadow-objects/WorkerRuntime: hello!");var Wr=new ts;Wr.start();
|
|
22
|
-
/*! Bundled license information:
|
|
23
|
-
|
|
24
|
-
@spearwolf/eventize/lib/index.mjs:
|
|
25
|
-
(*!
|
|
26
|
-
=============================================================================
|
|
27
|
-
@spearwolf/eventize 5.0.0+build.20260513
|
|
28
|
-
\u2014 git+https://github.com/spearwolf/eventize.git
|
|
29
|
-
=============================================================================
|
|
30
|
-
|
|
31
|
-
Copyright 2015-2026 Wolfger Schramm
|
|
32
|
-
|
|
33
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
34
|
-
you may not use this file except in compliance with the License.
|
|
35
|
-
You may obtain a copy of the License at
|
|
36
|
-
|
|
37
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
38
|
-
|
|
39
|
-
Unless required by applicable law or agreed to in writing, software
|
|
40
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
41
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
42
|
-
See the License for the specific language governing permissions and
|
|
43
|
-
limitations under the License.
|
|
44
|
-
*)
|
|
21
|
+
var Kl=Object.defineProperty;var f=(s,e,t)=>()=>{if(t)throw t[0];try{return s&&(e=s(s=0)),e}catch(r){throw t=[r],r}};var Ql=(s,e)=>{for(var t in e)Kl(s,t,{get:e[t],enumerable:!0})};var Xt,zs,Zt,$n,js,Dn,Ae,ie,Ln,Ie,zn,Ws,pe,jn,Wn,_n,Fn,In,_s,Bn,at,es,Fs,Is,Te=f(()=>{"use strict";Xt="shaeRequestEntParent",zs="shaeReRequestEntParent",Zt="shaeReRequestEntHost",$n="shae-worker",js="shae-ent",Dn="shae-prop",Ae="token",ie="forward-custom-events",Ln="auto-destruct",Ie="local",zn="no-autostart",Ws="no-structured-clone",pe="auto-sync",jn="load-timeout",Wn="configure-timeout",_n="change-trail-timeout",Fn="inspect-timeout",In="destroy-timeout",_s="expose-to-model-context",Bn="redact-props",at="name",es="value",Fs="type",Is="no-trim"});function ns(s){if(oe(s))return ge(s),s;if(!ri(s)){let r=s;throw new TypeError(`eventize() cannot attach to ${r===null?"null":`a value of type '${typeof r}'`} \u2014 eventize needs an object or a function to attach to`)}if(!Object.isExtensible(s))throw new TypeError("eventize() cannot attach to a non-extensible object \u2014 eventize before freezing, or eventize a wrapper");let e=new Ph,t=new dh;return ah(s,ei,{protocol:ti,keeper:t,store:e}),s}function k(s,e,...t){oe(s)?kt(s,e,t,so):xt(s)&&St(s,e,t,Gs)}function me(s,e,...t){let r=I;I=null;try{oe(s)?kt(s,e,t,qs):xt(s)&&St(s,e,t,Hs)}finally{I=r}}function W(s,e,...t){let r=I,i=[];I=i;try{oe(s)?kt(s,e,t,qs):xt(s)&&St(s,e,t,Hs)}catch(n){i.push(n)}finally{I=r}if(i.length>0)throw Jr(i)}function Dh(s,e,...t){let r=[],i=n=>{r.push(n)};try{oe(s)?kt(s,e,t,so,i):xt(s)&&St(s,e,t,Gs,i)}catch(n){throw io(r),n}return r.length>0?Promise.all(r.map(n=>Array.isArray(n)?Promise.all(n):Promise.resolve(n))):Promise.resolve(void 0)}function Lh(s,e,...t){let r=[],i=o=>{r.push(o)},n=I;I=null;try{oe(s)?kt(s,e,t,qs,i):xt(s)&&St(s,e,t,Hs,i)}catch(o){throw io(r),o}finally{I=n}return r.length>0?Promise.all(r.map(o=>Array.isArray(o)?Promise.all(o):Promise.resolve(o))):Promise.resolve(void 0)}function jh(s,e,...t){let r=[],i=a=>{r.push(a)},n=I,o=[];I=o;try{oe(s)?kt(s,e,t,qs,i):xt(s)&&St(s,e,t,Hs,i)}catch(a){o.push(a)}finally{I=n}return r.length===0?o.length>0?Promise.reject(Jr(o)):Promise.resolve(void 0):Promise.allSettled(r.map(a=>Array.isArray(a)?Promise.allSettled(a):Promise.resolve(a))).then(a=>{let l=zh(r,a,o);if(o.length>0)throw Jr(o);return l})}function ii(s,e,t){let r=t?.signal,i,n,o=new Promise((u,c)=>{i=u,n=c});if(r!=null&&typeof r.addEventListener!="function")throw new TypeError("options.signal must be an AbortSignal (or omitted)");if(r?.aborted)return n(Jn(r)),o;let a,l=!1,h=T(s,e,(...u)=>{l=!0,r!=null&&a!=null&&r.removeEventListener("abort",a),i(u[0])});return r!=null&&!l&&(a=()=>{h(),n(Jn(r))},r.addEventListener("abort",a,{once:!0})),o}function S(s,e,t){if(!oe(s))return;let{store:r,keeper:i}=ge(s),n=typeof e,o=t!=null&&(n==="string"||n==="symbol");r.remove(e,t,o);let a=t==null&&Array.isArray(e)?e.flat(1/0):e;if(e==null||t==null&&Bh(a)){i.removeAll();return}t==null&&Zl(a)?i.remove(a.filter(Ue)):Ue(e)&&i.remove(e)}function ye(s,e){oo(e)&&si("retained"),ao("retain",e);let t=ns(s),{keeper:r}=ge(t);r.add(e)}function os(s,e){lo("retainClear",s,e,t=>t.clearAll(),(t,r)=>t.clear(r))}function ni(s,e){lo("unretain",s,e,t=>t.removeAll(),(t,r)=>t.remove(r))}var X,Jl,Xr,Zr,ei,ti,Xl,Be,si,Ue,ri,Zl,eh,th,sh,rh,ih,Vs,nh,Gs,oh,Oe,ah,lh,hh,Ct,ts,Bs,ch,uh,dh,fh,ph,rs,gh,mh,Xn,yh,vh,lt,Zn,wh,eo,bh,to,Eh,Ch,kh,Un,Sh,ne,ss,Us,Vn,is,Qr,xh,Ah,Gn,Th,Oh,Ph,Rh,Mh,Nh,ge,oe,so,$h,I,ro,Jr,qs,qn,kt,Hs,Hn,St,xt,Yn,io,zh,Y,Wh,Kn,Qn,_h,no,Fh,Ih,Bh,y,T,Jn,oo,ao,lo,Uh,Vh,Gh,qh,Hh,Yh,Kh,Qh,Jh,Xh,Zh,ec,tc,sc,ho,$,rc,co,B=f(()=>{X="*",Jl=1,Xr=2,Zr=4,ei=Symbol.for("eventize"),ti=6,Xl="[eventize]",Be=s=>s===X,si=s=>{let e=s==="emitted"?"emit":"retain";throw new Error(`${e}() must be called with a concrete event name \u2014 '*' is reserved for subscribing to all events and cannot be ${s}`)},Ue=s=>{switch(typeof s){case"string":case"symbol":return!0;default:return!1}},ri=s=>s!=null&&(typeof s=="object"||typeof s=="function"),Zl=s=>Array.isArray(s),eh=Object.prototype,th=(()=>{let s={},e=Function.prototype;for(let t of Reflect.ownKeys(Function.prototype))try{s[t]=e[t]}catch{}return s})(),sh=(s,e)=>{if(e==="constructor"||e==="__proto__")return;let t=s[e];if(t!==void 0&&t!==eh[e])return t===th[e]?void 0:t},rh=(s,e)=>{let t=new Array(e.length+1);t[0]=s;for(let r=0;r<e.length;++r)t[r+1]=e[r];return t},ih=s=>s,Vs=(s,e,t,r)=>{if(typeof e=="function"){let i=e.apply(s,t);return i!=null&&r?.(i),!0}return!1},nh=(s,e,t,r)=>{let i=s.emit;return typeof i=="function"&&Vs(s,i,rh(e,t),r)},Gs=(s,e,t,r)=>Vs(s,sh(s,e),t,r)||nh(s,e,t,r),oh=typeof console<"u",Oe=oh?console[typeof console.warn=="function"?"warn":"log"].bind(console,Xl):()=>{},ah=(s,e,t)=>(Object.defineProperty(s,e,{value:t,configurable:!1}),s),lh=0,hh=(s,e)=>s.order-e.order,Ct=s=>()=>{throw new Error(`EventKeeper: ${s} is the shared empty stand-in \u2014 replace it, never mutate it`)},ts=Object.freeze(Object.defineProperties(new Map,{set:{value:Ct("events")},delete:{value:Ct("events")},clear:{value:Ct("events")}})),Bs=Object.freeze(Object.defineProperties(new Set,{add:{value:Ct("eventNames")},delete:{value:Ct("eventNames")},clear:{value:Ct("eventNames")}})),ch=s=>{if(s.length!==0){s.sort(hh);for(let e of s)try{e.replay()}catch(t){Oe("a retained replay threw; the batch continues. event:",e.eventName,t)}}},uh=s=>e=>{typeof e?.then=="function"&&e.then(void 0,t=>{Oe("a retained replay rejected; the batch continues. event:",s,t)})},dh=class{events=ts;eventNames=Bs;mutableEvents(){return this.events===ts&&(this.events=new Map),this.events}mutableEventNames(){return this.eventNames===Bs&&(this.eventNames=new Set),this.eventNames}get retainedCount(){return this.events.size}retainedNames(){return Array.from(this.eventNames)}add(s){if(Array.isArray(s)){if(s.length===0)return;let e=this.mutableEventNames();s.forEach(t=>e.add(t))}else this.mutableEventNames().add(s)}remove(s){if(this.eventNames.size!==0){let e=this.eventNames;Array.isArray(s)?s.forEach(t=>e.delete(t)):e.delete(s),this.eventNames.size===0&&(this.eventNames=Bs)}this.clear(s)}clear(s){if(this.events.size===0)return;let e=this.events;Array.isArray(s)?s.forEach(t=>e.delete(t)):e.delete(s),this.events.size===0&&(this.events=ts)}removeAll(){this.eventNames=Bs,this.events=ts}clearAll(){this.events=ts}retain(s,e){this.eventNames.size!==0&&this.eventNames.has(s)&&this.mutableEvents().set(s,{args:e,order:lh++})}hasRetainedFor(s){return this.events.size!==0&&(Be(s)||this.events.has(s))}replayTo(s,e,t=[]){if(Be(s))this.events.forEach((r,i)=>{Be(i)||this.replayTo(i,e,t)});else{let r=this.events.get(s);r!=null&&t.push({order:r.order,eventName:s,replay:()=>{let i=this.events.get(s);i!==void 0&&e.apply(s,i.args,uh(s))}})}return t}},fh=s=>s!=null,ph=s=>s!=null&&typeof s=="object",rs=s=>{switch(typeof s){case"function":return Jl;case"string":case"symbol":return Xr;case"object":return s===null?void 0:Zr;default:return}},gh=0,mh=()=>++gh,Xn=0,yh=()=>({settled:!1,members:[],sequence:Xn++,onSettled:void 0}),vh=class{id;eventName;isCatchEmAll;priority;listener;listenerObject;listenerType;callAfterApply;isRemoved;refCount;onceObligations;constructor(s,e,t,r=null){this.id=mh(),this.eventName=s,this.isCatchEmAll=Be(s),this.listener=t,this.listenerObject=r,this.priority=e,this.listenerType=rs(t),this.callAfterApply=void 0,this.isRemoved=!1,this.refCount=0,this.onceObligations=void 0}isEqual(s,e){return this.listener===s&&this.listenerObject===e}detach(){if(this.isRemoved=!0,this.listener=null,this.listenerObject=null,this.callAfterApply=void 0,this.onceObligations!==void 0){for(let s of this.onceObligations){let e=s.members.indexOf(this);e>=0&&s.members.splice(e,1)}this.onceObligations=void 0}}apply(s,e=[],t){if(this.isRemoved)return;let{listener:r,listenerObject:i}=this,n=Xn;if(typeof r=="function"){Vs(i,r,e,t),this.callAfterApply&&this.callAfterApply(n);return}if(Ue(r)){fh(i)&&Vs(i,i[r],e,t)&&this.callAfterApply&&this.callAfterApply(n);return}ph(r)&&(this.isCatchEmAll||this.eventName===s)&&Gs(r,s,e,t)&&this.callAfterApply&&this.callAfterApply(n)}},lt=Symbol("eventize.EventStore.dedupIndex"),Zn=s=>s===Zr||s===Xr,wh=(s,e,t,r,i,n)=>s===n.listenerType?e===n.priority&&t===n.eventName&&i===n.listenerObject&&r===n.listener:!1,eo=(s,e,t)=>s===Zr?e:t,bh=s=>s!=null&&typeof s!="string"&&typeof s!="symbol",to=(s,e,t)=>{let r=e.listener,i=e.listenerObject,n=Zn(e.listenerType),o=n?eo(e.listenerType,r,i):void 0;n&&t(s,o,e),bh(r)&&!(n&&o===r)&&t(s,r,e),ri(i)&&i!==r&&!(n&&o===i)&&t(s,i,e)},Eh=(s,e,t)=>{let r=s.get(e);r===void 0?s.set(e,[t]):r.push(t)},Ch=(s,e,t)=>{let r=s.get(e);if(r===void 0)return;let i=r.indexOf(t);i<0||(r.splice(i,1),r.length===0&&s.delete(e))},kh=(s,e)=>{to(s[lt]??=new Map,e,Eh)},Un=(s,e)=>{let t=s[lt];t!==void 0&&to(t,e,Ch)},Sh=(s,e,t,r,i,n)=>{if(!Zn(s))return;let o=n[lt];if(o===void 0)return;let a=o.get(eo(s,r,i));if(a!==void 0){for(let l of a)if(wh(s,e,t,r,i,l))return l}},ne=Symbol("eventize.EventStore.heldBy"),ss=s=>{let e=s===void 0?[]:s.slice(0);return e[ne]=0,e[lt]=s===void 0?void 0:s[lt],e},Us=s=>()=>{throw new Error(`EventStore: ${s} is the shared empty stand-in \u2014 replace it, never mutate it`)},Vn=Object.freeze(Object.defineProperties(new Map,{set:{value:Us("namedListeners")},delete:{value:Us("namedListeners")},clear:{value:Us("namedListeners")}})),is=ss();for(let s of["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"])Object.defineProperty(is,s,{value:Us(`the catch-em-all bucket (${s}())`)});Object.freeze(is);Qr=s=>{s.forEach(e=>e.detach()),s[lt]=void 0},xh=(s,e)=>s.priority!==e.priority?e.priority-s.priority:s.id-e.id,Ah=(s,e)=>{let t=0,r=s.length;for(;t<r;){let i=t+r>>>1,n=s[i];if(n===void 0)throw new Error("EventStore: findInsertIndex encountered a hole");xh(e,n)<0?r=i:t=i+1}return t},Gn=(s,e,t,r,i)=>{let n=s.length;for(let o=0;o<n;o++){let a=s[o];a!==void 0&&e(a,t,r,i)}},Th=(s,e,t,r,i,n)=>{let o=s.length,a=e.length,l=0,h=0;for(;l<o||h<a;){let u=l<o?s[l]:void 0,c=h<a?e[h]:void 0;if(u!==void 0&&(c===void 0||u.priority>=c.priority)){t(u,r,i,n),++l;continue}if(c!==void 0)t(c,r,i,n),++h;else throw new Error("EventStore: forEach encountered a hole")}},Oh=Object.freeze([]),Ph=class{namedBuckets=Vn;catchEmAllBucket=is;get namedListeners(){return this.namedBuckets}get catchEmAllListeners(){return this.mutableCatchEmAllBucket()}mutableNamedBuckets(){return this.namedBuckets===Vn&&(this.namedBuckets=new Map),this.namedBuckets}mutableCatchEmAllBucket(){return this.catchEmAllBucket===is&&(this.catchEmAllBucket=ss()),this.catchEmAllBucket}getListenersForEventName(s){let e=this.namedBuckets.get(s);return e||(e=ss(),this.mutableNamedBuckets().set(s,e)),e}peekListeners(s){return Be(s)?this.catchEmAllBucket:this.namedBuckets.get(s)??Oh}bucketForMutation(s,e){if(e[ne]===0)return e;let t=ss(e);return e===this.catchEmAllBucket?this.catchEmAllBucket=t:this.namedBuckets.set(s,t),t}spliceOut(s,e,t){let r=e.indexOf(t);if(r<0)return e;let i=this.bucketForMutation(s,e);return i.splice(r,1),Un(i,t),i}detachByAssociation(s,e,t){let r=e;for(let i=e.length-1;i>=0;i--){let n=e[i];n!==void 0&&n.eventName===s&&(n.listener===t||n.listenerObject===t)&&(r===e&&(r=this.bucketForMutation(s,e)),r.splice(i,1),Un(r,n),n.detach())}return r}detachByIdentity(s,e,t,r,i){let n=e[lt];if(n===void 0)return e;let o=n.get(t);if(o===void 0)return e;let a=r==null,l=e;for(let h of o.slice())((a?h.listener===t:h.isEqual(t,r))||a&&i&&h.listenerObject===t)&&(l=this.spliceOut(s,l,h),h.detach());return l}lastAddCreatedListener=!1;add(s,e,t,r=null,i=null){let n=Be(s)?this.mutableCatchEmAllBucket():this.getListenersForEventName(s),o=rs(t),a=Sh(o,e,s,t,r,n),l=a??new vh(s,e,t,r);if(i===null?l.refCount+=1:l.onceObligations?.includes(i)||((l.onceObligations??=[]).push(i),i.members.push(l)),this.lastAddCreatedListener=!1,a)return a;let h=this.bucketForMutation(s,n);return h.splice(Ah(h,l),0,l),kh(h,l),this.lastAddCreatedListener=!0,l}remove(s,e,t=!1){if(e==null&&Array.isArray(s)){s.forEach(r=>this.remove(r,null,t));return}if(s==null||e==null&&Be(s)){this.removeAllListeners();return}if(e==null&&Ue(s)){this.removeByEventName(s);return}if(t&&Ue(s)){this.removeByEventNameAndListenerObject(s,e);return}this.removeByListener(s,e)}removeByEventName(s){let e=this.namedBuckets.get(s);e!==void 0&&(Qr(e),e[ne]===0&&(e.length=0),this.namedBuckets.delete(s))}release(s){s.isRemoved||(s.refCount-=1,!(s.refCount>0||s.onceObligations!==void 0)&&this.dropListener(s))}releaseObligation(s){s.settled||this.dischargeObligation(s)}settleOneShots(s,e){let t=s.onceObligations;if(t!==void 0)for(let r of t.slice())r.sequence<e&&!r.settled&&this.dischargeObligation(r)}dischargeObligation(s){s.settled=!0;let e=s.onSettled;s.onSettled=void 0,e?.();let t=s.members.slice();s.members.length=0;for(let r of t){let i=r.onceObligations;if(i!==void 0){let n=i.indexOf(s);n>=0&&i.splice(n,1),i.length===0&&(r.onceObligations=void 0,r.callAfterApply=void 0)}!r.isRemoved&&r.refCount===0&&r.onceObligations===void 0&&this.dropListener(r)}}dropListener(s){if(s.isCatchEmAll)this.spliceOut(s.eventName,this.catchEmAllBucket,s);else{let e=this.namedBuckets.get(s.eventName);e&&this.spliceOut(s.eventName,e,s).length===0&&this.namedBuckets.delete(s.eventName)}s.detach()}removeByEventNameAndListenerObject(s,e){if(Be(s)){this.detachByAssociation(s,this.catchEmAllBucket,e);return}let t=this.namedBuckets.get(s);if(!t)return;this.detachByAssociation(s,t,e).length===0&&this.namedBuckets.delete(s)}removeByListener(s,e){let t=typeof s=="object"||typeof s=="function";this.namedBuckets.forEach((r,i)=>{this.detachByIdentity(i,r,s,e,t).length===0&&this.namedBuckets.delete(i)}),this.detachByIdentity(X,this.catchEmAllBucket,s,e,t)}removeAllListeners(){this.namedBuckets.size!==0&&(this.namedBuckets.forEach(e=>{Qr(e),e[ne]===0&&(e.length=0)}),this.namedBuckets.clear());let s=this.catchEmAllBucket;s!==is&&(Qr(s),s[ne]!==0?this.catchEmAllBucket=ss():s.length=0)}forEach(s,e,t,r,i){let n=this.catchEmAllBucket,o=n.length>0?n:void 0,a=s===X?void 0:this.namedBuckets.get(s),l=a!==void 0&&a.length>0?a:void 0;if(l===void 0){if(o===void 0)return;o[ne]+=1;try{Gn(o,e,t,r,i)}finally{o[ne]-=1}return}l[ne]+=1,o!==void 0&&(o[ne]+=1);try{o===void 0?Gn(l,e,t,r,i):Th(l,o,e,t,r,i)}finally{l[ne]-=1,o!==void 0&&(o[ne]-=1)}}getSubscriptionCount(){let s=this.catchEmAllBucket.length;for(let e of this.namedBuckets.values())s+=e.length;return s}getSubscribedEventNames(){let s=Array.from(this.namedBuckets.keys());return this.catchEmAllBucket.length>0&&s.push(X),s}},Rh=s=>s[ei],Mh=s=>{throw new TypeError(`two incompatible copies of @spearwolf/eventize are active on this object (marker protocol ${String(s)}, expected ${ti}) \u2014 dedupe @spearwolf/eventize in your dependency tree so a single copy is loaded`)},Nh=s=>s?.protocol===ti,ge=s=>{let e=Rh(s);return Nh(e)?e:Mh(e?.protocol)},oe=s=>!!(s&&s[ei]);so=(s,e,t,r)=>{s.apply(e,t,r)},$h=(s,e)=>{Oe("a listener threw; the dispatch continues. event:",s,e)},I=null,ro=(s,e)=>{I!==null?I.push(e):$h(s,e)},Jr=s=>s.length===1?s[0]:new AggregateError(s,"emitStrict: one or more listeners failed"),qs=(s,e,t,r)=>{try{s.apply(e,t,r)}catch(i){ro(e,i)}},qn=(s,e,t,r,i,n)=>{e===X&&si("emitted");let o=n??ge(s);return o.store.forEach(e,r,e,t,i),o.keeper.retain(e,t),o},kt=(s,e,t,r,i)=>{if(Array.isArray(e)){let n;for(let o=0;o<e.length;o++)o in e&&(n=qn(s,e[o],t,r,i,n))}else qn(s,e,t,r,i)},Hs=(s,e,t,r)=>{try{Gs(s,e,t,r)}catch(i){ro(e,i)}},Hn=(s,e,t,r,i)=>{e===X&&si("emitted"),r(ih(s),e,t,i)},St=(s,e,t,r,i)=>{if(Array.isArray(e))for(let n=0;n<e.length;n++)n in e&&Hn(s,e[n],t,r,i);else Hn(s,e,t,r,i)},xt=ri;Yn=()=>{},io=s=>{for(let e of s)if(Array.isArray(e))for(let t of e)Promise.resolve(t).catch(Yn);else Promise.resolve(e).catch(Yn)};zh=(s,e,t)=>{let r=[];for(let[i,n]of e.entries()){if(n.status==="rejected"){t.push(n.reason);continue}if(!Array.isArray(s[i])){r.push(n.value);continue}let o=[];for(let a of n.value)a.status==="rejected"?t.push(a.reason):o.push(a.value);r.push(o)}return r};Y={Max:Number.POSITIVE_INFINITY,Critical:1e9,High:1e6,Medium:1e3,Normal:0,Low:-1e4,Min:Number.NEGATIVE_INFINITY,AAA:1e9,BB:1e6,C:1e3,Default:0},Wh=(s,e,t,r,i,n,o,a)=>{let l=s.add(t,r,i,n,a),h=s.lastAddCreatedListener;if(a!==null&&l.callAfterApply===void 0&&(l.callAfterApply=u=>s.settleOneShots(l,u)),e.hasRetainedFor(t)&&(h||a!==null)){let u=a===null?l:{apply:(c,g,p)=>{a.settled||l.apply(c,g,p)}};o.events=e.replayTo(t,u,o.events)}return l},Kn=(s,e)=>{if(typeof s!="number"||Number.isNaN(s))throw Oe("called with a NaN priority!",e),new Error("subscribeTo() called with a NaN priority",{cause:"invalid-priority"})},Qn=(s,e)=>{if(!Ue(s))throw Oe("called with a value that cannot be an event name!",e),new Error("subscribeTo() called with insufficient arguments",{cause:"invalid-name"})},_h=(s,e,t,r,i)=>{let n=t.length,o=typeof t[0],a,l,h,u;if(n>=2&&n<=3&&o==="number"?(a=X,[l,h,u]=t):n>=3&&n<=4&&typeof t[1]=="number"?[a,l,h,u]=t:(l=Y.Normal,o==="string"||o==="symbol"||Array.isArray(t[0])?[a,h,u]=t:(a=X,[h,u]=t)),!h||rs(h)===void 0){let g=h==null?"missing-listener":rs(h)===void 0?"not-dispatchable":"empty-method-name";throw Oe(g==="missing-listener"?"called with insufficient arguments!":g==="not-dispatchable"?"called with a value that cannot be a listener!":"called with an empty method name!",t),new Error("subscribeTo() called with insufficient arguments",{cause:g})}if(rs(h)===Xr&&u==null)throw Oe("called with a method name but no listener object!",t),new Error("subscribeTo() called with insufficient arguments",{cause:"missing-listener-object"});Array.isArray(a)||Qn(a,t),Kn(l,t);let c=(g,p)=>Wh(s,e,p,g,h,u,r,i);if(Array.isArray(a)){if(a.length===0)throw Oe("called with an empty array of event names!",t),new Error("subscribeTo() called with insufficient arguments",{cause:"empty-names"});for(let p=0;p<a.length;p++)if(!(p in a))throw Oe("called with a sparse array of event names!",t),new Error("subscribeTo() called with insufficient arguments",{cause:"sparse-names"});return a.map(p=>{let H=Array.isArray(p)?[p[0],p[1]??l]:[p,l];return Qn(H[0],t),Kn(H[1],t),H}).map(p=>c(p[1],p[0]))}return c(l,a)},no=(s,e,t,r=null)=>{let i={},n=_h(s,e,t,i,r);return i.events!==void 0&&ch(i.events),n},Fh=(s,e)=>{let t={host:s,listeners:e};return()=>{let r=t;if(r===null)return;t=null;let{store:i}=ge(r.host);Array.isArray(r.listeners)?r.listeners.forEach(n=>i.release(n)):i.release(r.listeners)}},Ih=(s,e)=>{let t={host:s,obligation:e};return e.settled?t=null:e.onSettled=()=>{t=null},()=>{let r=t;if(r===null)return;t=null;let{store:i}=ge(r.host);i.releaseObligation(r.obligation)}},Bh=s=>Array.isArray(s)?s.some(e=>e==null||e===X):s===X,y=(s,...e)=>{let t=ns(s),{store:r,keeper:i}=ge(t);return Fh(t,no(r,i,e))},T=(s,...e)=>{let t=ns(s),{store:r,keeper:i}=ge(t),n=yh();return no(r,i,e,n),Ih(t,n)},Jn=s=>s.reason??new DOMException("This operation was aborted","AbortError");oo=s=>Array.isArray(s)?s.some(e=>e===X):s===X,ao=(s,e)=>{if(!Array.isArray(e)){if(!Ue(e))throw new Error(`${s}() called with a value that cannot be an event name`,{cause:"invalid-name"});return}if(e.length===0)throw new Error(`${s}() called with an empty array of event names`,{cause:"empty-names"});for(let t=0;t<e.length;t++)if(!(t in e))throw new Error(`${s}() called with a sparse array of event names`,{cause:"sparse-names"});for(let t of e)if(!Ue(t))throw new Error(`${s}() called with a value that cannot be an event name`,{cause:"invalid-name"})},lo=(s,e,t,r,i)=>{if(!oe(e))throw new TypeError(`${s}() cannot operate on a non-eventized object \u2014 eventize(obj) first, or guard the call with isEventized(obj)`);let{keeper:n}=ge(e);if(oo(t)){r(n);return}ao(s,t),i(n,t)};Uh=y,Vh=T,Gh=S,qh=k,Hh=Dh,Yh=me,Kh=Lh,Qh=W,Jh=jh,Xh=ii,Zh=ye,ec=os,tc=ni,sc={on(...s){return Uh(this,...s)},once(...s){return Vh(this,...s)},onceAsync(s,e){return Xh(this,s,e)},off(s,e){Gh(this,s,e)},emit(s,...e){qh(this,s,...e)},emitAsync(s,...e){return Hh(this,s,...e)},emitSafe(s,...e){Yh(this,s,...e)},emitSafeAsync(s,...e){return Kh(this,s,...e)},emitStrict(s,...e){Qh(this,s,...e)},emitStrictAsync(s,...e){return Jh(this,s,...e)},retain(s){Zh(this,s)},retainClear(s){ec(this,s)},unretain(s){tc(this,s)}},ho=Object.entries(sc),$=(()=>{let s=(e={})=>ns(e);return s.inject=(e={})=>{e=ns(e);for(let[t,r]of ho)Object.defineProperty(e,t,{value:r.bind(e),writable:!0,enumerable:!1,configurable:!0});return e},s.is=oe,s})(),rc=class{constructor(){$(this)}};for(let[s,e]of ho)Object.defineProperty(rc.prototype,s,{value:e,writable:!0,enumerable:!1,configurable:!0});co=s=>oe(s)?ge(s).store.getSubscriptionCount():0});function fs(s){Tt++;try{let e=s();return Xs(e,"beQuiet","action",cc),e}finally{Tt--}}function Zs(){return Tt>0}function Co(){return Tt}function ko(){Tt=0}function So(s){Tt=s}function fo(s){Zs()||sr()?.whenSignalIsRead(s)}function fi(s,e,t){if(!Zs()){let r=er();try{k(us,s,e,t)}catch(i){Rt(i)}finally{tr(r,"notifying the effects of a signal write")}}}function ps(...s){let e=[];for(let t of s)if(Ot.has(t)){let r=Ot.get(t);if(r.signals){for(let i of r.signals.values())v(e,()=>R(i));r.signals.clear(),r.signals=void 0}}D(e,"destroying the signals of an object")}function Ro(s){if(!le(s)&&!Array.isArray(s))throw new TypeError("[signalize] touch: source must be a signal or an [object, propertyName] tuple");let e=_(le(s)?s:Ge(...s));e!=null&&!e.muted&&!e.destroyed&&fi(e.id,e.value,{touch:!0})}function qe(s){if(!le(s)&&!Array.isArray(s))throw new TypeError("[signalize] value: source must be a signal or an [object, propertyName] tuple");return le(s)?_(s)?.value:_(Ge(...s))?.value}function bc(){ui("signalReader(callback)","[signalize] signalReader(callback) is deprecated and will be removed in a future release. Use Signal.onChange(callback) instead \u2014 it returns an unsubscribe function for proper cleanup.")}function m(s=void 0,e){let t;if(le(s)){t=_(s);let r=vc.filter(i=>e?.[i]!=null);r.length>0&&he({level:"warn",source:"ignored-option",message:`[signalize] createSignal(existingSignal, {${r.join(", ")}}) is a passthrough: it returns the signal that was passed in, so nothing in those braces is applied. Only {attach} works on this path. Configure the signal where it is created, or drop the options.`})}else{let r=e?.lazy??!1;t=new vi(r,s),t.beforeRead=e?.beforeRead,t.compare=e?.compare}return e?.attach!=null&&Re.findOrCreate(e.attach).attachSignal(t),t.object}var ae,Z,wi,yo,vo,wo,ic,Ve,hs,nc,cs,bi,Ei,ve,oc,Pt,us,we,Me,Ci,ac,lc,hc,he,uo,ui,di,bo,Eo,ds,Xs,Tt,cc,D,v,ki,ct,er,tr,Rt,ut,sr,Si,xo,Ao,To,xi,Oo,uc,le,_,R,Ot,dc,Ge,Ai,Po,Js,ht,At,Pe,po,fc,go,pc,oi,ai,li,hi,ci,mo,rr,pi,gi,mi,yi,as,Qs,Mo,No,Ys,Ks,gc,mc,Re,ls,yc,vc,wc,Ec,vi,ir=f(()=>{B();ae=Symbol.for("@spearwolf/signalize/signal"),Z=Symbol.for("@spearwolf/signalize/effect"),wi=Symbol.for("@spearwolf/signalize/destroySignal"),yo=Symbol.for("@spearwolf/signalize/createEffect"),vo=Symbol.for("@spearwolf/signalize/destroyEffect"),wo=Symbol.for("@spearwolf/signalize/effectError"),ic=Symbol.for("@spearwolf/signalize/signalizeError"),Ve=Symbol.for("@spearwolf/signalize/queueUnsubscribes"),hs=Symbol.for("@spearwolf/signalize/autoMapResources"),nc=Symbol.for("@spearwolf/signalize/instances"),cs="value",bi="mute",Ei="unmute",ve="destroy",oc="off",Pt=Symbol.for("@spearwolf/signalize/recall"),us=$(),we=$(),Me=$(),Ci=$(),ac=(s,e)=>{try{let t=globalThis[nc]??=[];if(t.push({url:s,report:e}),t.length>1){let r={level:"error",source:"multiple-instances",message:`[signalize] ${t.length} copies of @spearwolf/signalize are loaded in this process; they share no signals, effects, groups or links. Loaded from: ${t.map(({url:i})=>i).join(", ")}`};try{t[0].report(r)}catch{e(r)}}return t.length}catch{return 0}},lc=0,hc=({level:s,message:e,error:t})=>{let r=s==="warn"?console.warn:console.error;t===void 0?r(e):r(e,t)},he=s=>{if(lc>0)try{k(Me,ic,s);return}catch(e){console.error(`[signalize] an onSignalizeError handler threw while reporting a ${s.source} diagnostic:`,e)}hc(s)};ac(import.meta.url,he);uo=new Set,ui=(s,e)=>{uo.has(s)||(uo.add(s),he({level:"warn",source:"deprecation",message:e}))},bo=s=>{di=s},Eo=()=>{if(di===void 0)throw new Error('[signalize] effect subsystem not registered \u2014 Signal.onChange() and signalReader(callback) need it. Import "@spearwolf/signalize" through its entry point, so that effects.js is evaluated.');return di},ds=s=>s!=null&&typeof s.then=="function",Xs=(s,e,t,r)=>{if(ds(s))throw new TypeError(`[signalize] ${e}: ${t} must be synchronous, but it returned a thenable. ${r}`)},Tt=0,cc="beQuiet() closes its frame the moment an async action returns its pending promise at the first `await` \u2014 every read after that point is tracked again and every write loud again, and the promise handed back would resolve outside the frame that appeared to produce it. Do the awaiting outside of beQuiet(), and pass a synchronous action.";D=(s,e)=>{if(s.length!==0)throw s.length===1?s[0]:new AggregateError(s,`[signalize] ${s.length} errors while ${e}`)},v=(s,e)=>{try{e()}catch(t){s.push(t)}},ki=0,er=()=>{ki++;let s=ct;return ct=void 0,s},tr=(s,e)=>{let t=ct;ct=s,ki--,t!==void 0&&D(t,e)},Rt=s=>ki===0?!1:(ct===void 0&&(ct=[]),ct.push(s),!0),ut=[],sr=()=>ut.at(-1),Si=(s,e)=>{ut.push(s);try{return e()}finally{ut.pop()}},xo=()=>ut.slice(),Ao=()=>{ut.length=0},To=s=>{ut.length=0,ut.push(...s)},xi=0,Oo=new FinalizationRegistry(()=>{--xi}),uc=s=>{++xi,Oo.register(s,void 0,s)};le=s=>s!=null&&s[ae]!=null,_=s=>s?.[ae],R=(...s)=>{for(let e of s){let t=_(e);if(t!=null&&!t.destroyed){t.destroyed=!0,t.beforeRead=void 0,Oo.unregister(t),--xi;let r=er();try{k(we,t.id,t.id)}catch(i){Rt(i)}finally{tr(r,"notifying the subscribers of a destroyed signal")}}}},Ot=new WeakMap,dc=s=>{let e=Ot.get(s);return e||(e={},Ot.set(s,e)),e},Ge=(s,e)=>Ot.get(s)?.signals?.get(e),Ai=(s,e)=>Ot.get(s)?.signals?.get(e),Po=(s,e,t)=>{let r=dc(s);r.signals??=new Map,r.signals.set(e,t)};Js=class{[ae];constructor(e){this[ae]=e}get get(){return this[ae].reader}get set(){return this[ae].writer}get value(){return qe(this.get)}set value(e){this.set(e)}onChange(e){let{destroy:t}=Eo()(()=>e(this.get()),[this.get]);return t}get muted(){return this[ae].muted}set muted(e){this[ae].muted=e}get destroyed(){return this[ae].destroyed}touch(){Ro(this)}destroy(){R(this)}},ht=new WeakMap,At=new Set,Pe=Symbol.for("@spearwolf/signalize/groupResources"),po=new FinalizationRegistry(s=>{for(let e of s.unsubs)try{e()}catch(t){he({level:"error",source:"group-finalizer",message:"[signalize] releasing the destroy-queue subscriptions of a collected SignalGroup failed:",error:t})}s.unsubs.clear(),s.selfRef!=null&&At.delete(s.selfRef)}),fc=s=>{let e=s[Pe].selfRef;if(!(e==null||!At.has(e)))try{s.clear()}catch(t){he({level:"error",source:"group-finalizer",message:"[signalize] a SignalGroup teardown threw in the FinalizationRegistry callback, where no caller can catch it:",error:t})}},go=new FinalizationRegistry(s=>{let e=s.deref();e!==void 0&&fc(e)}),pc=Symbol.for("@spearwolf/signalize/setParentGroup"),oi=1,ai=2,li=4,hi=8,ci=16,mo="[signalize] Cannot attach a group to one of its own descendants: this would create a cycle in the group graph",rr="[signalize] internal error: a shared empty stand-in collection was written to",pi=class extends Set{add(){throw new Error(rr)}},gi=class extends Map{set(){throw new Error(rr)}},mi=class extends WeakMap{set(){throw new Error(rr)}},yi=class extends WeakSet{add(){throw new Error(rr)}},as=new pi,Qs=new gi,Mo=new mi,No=new yi,Ys=s=>s===as?new Set:s,Ks=s=>s===Qs?new Map:s,gc=s=>s===Mo?new WeakMap:s,mc=s=>s===No?new WeakSet:s,Re=class s{#e=as;#t=new Set;#s=Qs;#i=Mo;#r=Qs;#n=as;#o=new Set;#a=Qs;[Pe]={unsubs:as};#h=as;#c=No;#l;#u=0;#g;static get(e){if(e!=null)return e instanceof s?e:ht.get(e)}static findOrCreate(e){if(e==null)throw new Error("[signalize] Cannot create a group with a null object");return e instanceof s?e:ht.get(e)??new s(e)}static destroy(e){ui("SignalGroup.destroy","[signalize] SignalGroup.destroy(obj) is deprecated. Use SignalGroup.delete(obj) instead."),s.delete(e)}static delete(e){if(e instanceof s){e.clear();return}ht.get(e)?.clear()}static clear(){let e=[];for(let t of[...At]){let r=t.deref();if(r===void 0){At.delete(t);continue}v(e,()=>r.clear())}D(e,"clearing all signal groups")}constructor(e){if(e!=null&&e instanceof s)return e;if(e??=this,ht.has(e))return ht.get(e);this.#g=new WeakRef(e),ht.set(e,this);let t=new WeakRef(this);this[Pe].selfRef=t,At.add(t),po.register(this,this[Pe],this),e!==this&&go.register(e,t,this),$(this)}attachGroup(e){if(e===this)throw new Error("[signalize] Cannot attach a group to itself");let t=this,r=this.#l;for(;r!=null;){if(r===e)throw new Error(mo);if(r=r.#l,r==null)break;if(r===e)throw new Error(mo);if(r=r.#l,t=t.#l,r!=null&&r===t)throw new Error("[signalize] Cannot attach a group: the parent chain of this group is already cyclic")}return(this.#e=Ys(this.#e)).add(e),e.#l&&e.#l!==this&&e.#l.#e.delete(e),e.#l=this,e}detachGroup(e){return e!==this&&this.#e.has(e)&&(this.#e.delete(e),e.#l=void 0),e}[pc](e){this.#l=e}attachSignal(e){let t=this.#d(e);return t&&(this.#n=Ys(this.#n)).add(t),e}#d(e){let t=_(e);if(t?.destroyed)throw new Error("[signalize] Cannot attach a destroyed signal to a group");if(t&&(this.#t.add(t),!this.#a.has(t))){let r=this[Pe].selfRef,i=new WeakRef(t),n=y(we,t.id,(a,l)=>{if(l?.detach)return;let h=i.deref(),u=r.deref();h!==void 0&&u!==void 0&&u.#m(h)});(this.#a=Ks(this.#a)).set(t,n);let o=this[Pe];(o.unsubs=Ys(o.unsubs)).add(n)}return t}#f(e){let t=this.#a.get(e);if(t)try{t()}finally{this.#a.delete(e),this[Pe].unsubs.delete(t)}}#p(e,t){let r=this.#r.get(e);r&&(r.delete(t),r.size===0&&this.#r.delete(e));let i=this.#i.get(t);i&&(i.delete(e),i.size===0&&(this.#i.delete(t),this.#n.has(t)||(this.#f(t),this.#t.delete(t),R(t))))}#v(e,t){this.#n.has(t)||this.#p(e,t)}attachSignalByName(e,t){if(t){let r=this.#d(t),i=this.#s.get(e);i!=null&&i!==r&&this.#v(e,i),(this.#s=Ks(this.#s)).set(e,r);let n=this.#r.get(e);n?n.add(r):(this.#r=Ks(this.#r)).set(e,new Set([r])),this.#i.has(r)?this.#i.get(r).add(e):(this.#i=gc(this.#i)).set(r,new Set([e]))}else{let r=this.#r.get(e);if(r)for(let i of[...r])this.#p(e,i);this.#s.delete(e)}return t}hasSignal(e){if(this.#u&oi)return!1;this.#u|=oi;try{return this.#s.has(e)||!!this.#l?.hasSignal(e)}finally{this.#u&=~oi}}signal(e){if(!(this.#u&ai)){this.#u|=ai;try{return this.#s.get(e)?.object??this.#l?.signal(e)}finally{this.#u&=~ai}}}detachSignal(e){let t=_(e);return t&&this.#m(t),e}#m(e){let t=[];if(v(t,()=>this.#f(e)),this.#t.delete(e),this.#n.delete(e),this.#i.has(e)){let r=this.#i.get(e);for(let i of r){let n=this.#r.get(i);if(n){if(n.delete(e),n.size===0)this.#s.delete(i),this.#r.delete(i);else if(this.#s.get(i)===e){let o;for(let a of n)o=a;(this.#s=Ks(this.#s)).set(i,o)}}}r.clear(),this.#i.delete(e)}D(t,"detaching a signal from a signal group")}attachEffect(e){let t=e!=null&&Z in e?e[Z]:e;if(t==null||t.destroyed)throw new Error("[signalize] Cannot attach a destroyed effect to a group");return this.#o.has(t)||(this.#o.add(t),T(t,ve,Y.Max,()=>{this.#o.delete(t)})),e}runEffects(){if(!(this.#u&li)){this.#u|=li;try{for(let e of this.#o)e.run();for(let e of this.#e)e.runEffects()}finally{this.#u&=~li}}}attachLink(e){if(e?.isDestroyed)throw new Error("[signalize] Cannot attach a destroyed link to a group");return e&&((this.#h=Ys(this.#h)).add(e),this.#c.has(e)||((this.#c=mc(this.#c)).add(e),T(e,ve,Y.Max,()=>{this.#h.delete(e)}))),e}detachLink(e){return e&&this.#h.delete(e),e}get memberCounts(){return{signals:this.#t.size,namedSignals:this.#s.size,signalsByName:this.#r.size,effects:this.#o.size,links:this.#h.size,groups:this.#e.size}}destroy(){ui("SignalGroup#destroy","[signalize] SignalGroup#destroy is deprecated. Use SignalGroup#clear instead."),this.clear()}off(){if(!(this.#u&hi)){this.#u|=hi;try{let e=[];for(let t of[...this.#e])v(e,()=>t.off());for(let t of[...this.#o])v(e,()=>t.destroy());this.#o.clear();for(let t of[...this.#h])v(e,()=>t.destroy());this.#h.clear();for(let t of[...this.#t])t.destroyed||v(e,()=>k(we,t.id,t.id,{detach:!0}));v(e,()=>k(this,oc,this)),D(e,"switching off a signal group")}finally{this.#u&=~hi}}}clear(){if(!(this.#u&ci)){this.#u|=ci;try{let e=[];v(e,()=>k(this,ve,this)),v(e,()=>S(this));for(let t of[...this.#e])v(e,()=>t.clear());for(let t of[...this.#o])v(e,()=>t.destroy());for(let t of[...this.#t])v(e,()=>R(t));for(let t of[...this.#h])v(e,()=>t.destroy());for(let t of[...this.#a.values()])v(e,()=>t());if(this.#a.clear(),this.#e.clear(),this.#t.clear(),this.#s.clear(),this.#r.clear(),this.#n.clear(),this.#o.clear(),this.#h.clear(),this.#l?.detachGroup(this),this.#g){let t=this.#g.deref();t!==void 0&&ht.delete(t),this.#g=void 0}At.delete(this[Pe].selfRef),this[Pe].unsubs.clear(),go.unregister(this),po.unregister(this),D(e,"clearing a signal group")}finally{this.#u&=~ci}}}},ls=class{#e;#t;constructor(e="id",t=1){this.#e=e,this.#t=t}make(){return Symbol(`${this.#e}${this.#t++}`)}},yc=new ls("si"),vc=["lazy","compare","beforeRead"],wc=(s,e)=>s===e;Ec=s=>{let e=t=>(s.destroyed||s.beforeRead?.(),t?(bc(),Eo()(()=>(s.destroyed||fo(s.id),t(s.value)),[e])):s.destroyed||fo(s.id),s.value);return Object.defineProperty(e,ae,{value:s}),e},vi=class{id;lazy;get[ae](){return this}compare;beforeRead;muted=!1;destroyed=!1;#e=void 0;get value(){return this.lazy&&(this.#e=this.valueFn(),this.valueFn=void 0,this.lazy=!1),this.#e}set value(e){this.#e=e}valueFn;reader;writer=(e,t)=>{let r=t?.lazy??!1,n=t?.compare??this.compare??wc;if((r!==this.lazy||r&&e!==this.valueFn||!r&&!n(e,this.#e))&&(r?(this.#e=void 0,this.valueFn=e,this.lazy=!0):(this.#e=e,this.valueFn=void 0,this.lazy=!1),!this.muted&&!this.destroyed)){fi(this.id,this.#e);return}(t?.touch??!1)&&!this.muted&&!this.destroyed&&fi(this.id,this.#e,{touch:!0})};object;constructor(e,t){this.id=yc.make(),uc(this),this.lazy=e,this.lazy?(this.value=void 0,this.valueFn=t):(this.value=t,this.valueFn=void 0),this.reader=Ec(this),this.object=new Js(this)}}});function ee(s){let e=Ne.current;e?e=void 0:e=Ne.current=new Ne;let t;try{let r=s();Xs(r,"batch","callback",xc)}catch(r){t=[r]}finally{if(e){Ne.current=void 0;try{e.run()}catch(r){t===void 0?t=[r]:t.push(r)}}}t!==void 0&&D(t,"running a batch")}function zo(s,e){let t=sr(),r=m();try{let i=e?.name||void 0,n=e?.attach!=null?Re.findOrCreate(e.attach):void 0;n!=null?i!=null?n.attachSignalByName(i,r):n.attachSignal(r):i!=null&&he({level:"warn",source:"ignored-option",message:`[signalize] createMemo({name: ${String(i)}}) without {attach} is ignored: a name only exists within a SignalGroup. Pass {attach} as well, or drop the name.`});let o=e?.batchWrites??!1,a=O(()=>{o?ee(()=>{r.set(s())}):r.set(s())},{autorun:!(e?.lazy??!1),priority:e?.priority??Y.C,attach:n}),l=_(r);l.beforeRead=a.runImmediately;let h=T(we,l.id,a.destroy);return a.onDestroy(()=>{h(),t!=null&&R(r)}),r.get}catch(i){let n=[i];e?.attach==null&&v(n,()=>R(r)),D(n,"creating a memo")}}function te(s){let e=Lo(),t=Co(),r=xo();kc(),ko(),Ao();let i=[],n;try{e&&v(i,()=>e.flush()),v(i,()=>{n=s(),Xs(n,"hibernate","callback",Pc)})}finally{Sc(e),So(t),To(r)}return D(i,"hibernating"),n}function $e(s,e,t){let r=_(s);if(r==null)throw new TypeError("[signalize] link: source must be a signal");let i=_(e),n=i??e,o=Ti.get(r);if(o==null)o=new Map,Ti.set(r,o);else if(o.has(n)){let h=o.get(n),u=t?.attach;return u&&h.attach(u),h}let a=i!=null?new Ni(s,i):new $i(s,e),l=t?.attach;return l&&a.attach(l),o.set(n,a),ms+=1,$o.register(a,a[Ve],a),o.size>=Rc&&!Do.has(r)&&(Do.add(r),he({level:"warn",source:"link-count",message:`[signalize] link(): ${o.size} links on a single source signal. A link is held until destroy(), unlink(), a cleared {attach} group, or the destruction of source/target \u2014 garbage collection alone does not reclaim one on a live source. If this is a hot path creating fresh callbacks, tear the old links down; getLinksCount(source) is the number to watch.`})),T(a,ve,Y.Max,()=>{o.delete(n),o.size===0&&Ti.delete(r),$o.unregister(a),ms>0&&(ms-=1)}),a}var Oi,Cc,Ne,Lo,kc,Sc,xc,Ac,Pi,Tc,Oc,dt,gs,Ri,nr,O,Pc,jo,Mi,or,Ni,$i,Ti,ms,$o,Rc,Do,Mc,ar,K=f(()=>{B();ir();ir();Oi=0,Cc=()=>Oi>0,Ne=class{static current;delayedEffects=[];batch(e,t){let r=this.delayedEffects.length;for(let i=0;i<r;i++){let[n,o]=this.delayedEffects[i];if(!(n>t)){if(n===t){o.add(e);return}this.delayedEffects.splice(i,0,[t,new Set([e])]);return}}this.delayedEffects.push([t,new Set([e])])}unbatch(e,t){let r=this.delayedEffects.length;for(let i=0;i<r;i++){let[n,o]=this.delayedEffects[i];if(n===t){o.delete(e);return}}}flush(){try{this.run()}finally{this.delayedEffects.length=0}}run(){if(this.delayedEffects.length===0)return;let e=new Set,t=[];Oi++;let r=er();try{t.push(y(Me,(i,n)=>{n===Pt&&e.add(i)}),y(Ci,i=>{e.add(i)}));for(let[,i]of this.delayedEffects)for(let n of i)if(!e.has(n))try{k(Me,n,n,Pt)}catch(o){Rt(o)}}finally{try{for(let i of t)i()}finally{try{tr(r,"flushing a batch of signal writes")}finally{Oi--}}}}},Lo=()=>Ne.current,kc=()=>{Ne.current=void 0},Sc=s=>{Ne.current=s},xc="batch() only sees writes made on the current call stack \u2014 an async callback stops being batched at its first `await`, so every write after that runs unbatched without any error. Move the async work outside of batch(), or split it into several synchronous batch() calls.";Ac=()=>{},Pi=class{[Z];constructor(e){this[Z]=e,T(e,ve,()=>{this[Z]=void 0})}run=()=>this[Z]?.run();runImmediately=()=>this[Z]?.runImmediately();get destroyed(){let e=this[Z];return e==null||e.destroyed}destroy=()=>{this[Z]?.destroy(),this[Z]=void 0};onDestroy(e){let t=this[Z];return t==null||t.destroyed?(e(),Ac):T(t,ve,e)}},Tc=0,Oc=()=>Tc>0,gs=(s,e,t)=>{if(Oc()){let r={error:e,effect:s,effectId:s.id,phase:t};try{k(Me,wo,r);return}catch(i){console.error(`[signalize] an onEffectError handler threw while reporting an error of effect ${s.id.toString()}:`,i)}}he({level:"error",source:"effect",message:`[signalize] unhandled rejection in the ${t} of effect ${s.id.toString()}:`,error:e})},Ri=class{active;#e;#t=!1;constructor(e,t){this.active=e,this.#e=t}complete(){this.#t=!0}mayCommit(e){return this.active&&(this.#t||e>this.#e)}},nr=class{static idGen=new ls("ef");static count=0;static maxDepth=256;id;callback;#e;#t=new Set;#s=new Set;#i=new Map;#r=0;#n=new Set;#o=[];autorun=!0;shouldRun=!0;#a=!1;priority;#h;#c=!1;get destroyed(){return this.#c}#l=0;#u=!1;#g=0;#d=!1;constructor(e,t){$(this),this.callback=e;let r=t?.attach!=null?Re.findOrCreate(t.attach):void 0;this.autorun=t?.autorun??!0,this.#h=t?.dependencies?t.dependencies.map(i=>{switch(typeof i){case"string":case"symbol":{if(r==null)throw new Error(`[signalize] createEffect: cannot resolve dependency "${String(i)}" \u2014 no SignalGroup is attached (missing "attach" option)`);let n=r.signal(i);if(n==null)throw new Error(`[signalize] createEffect: cannot resolve dependency "${String(i)}" \u2014 no signal with that name is registered in the attached SignalGroup`);return n}default:return i}}):void 0,this.id=dt.idGen.make(),this.priority=t?.priority??0,y(Me,this.id,Pt,this),r?.attachEffect(this),++dt.count}hasStaticDeps(){return this.#h!=null&&this.#h.length>0}saveSignalsFromDeps(){for(let e of this.#h){let t=_(e);t.destroyed||this.whenSignalIsRead(t.id)}}static createEffect(e,t,r){let i=Array.isArray(t)?t:void 0,n=i?{...r,dependencies:i}:t,o=new dt(e,n);try{sr()?.attachChildEffect(o),k(Me,yo,o),o.hasStaticDeps()?o.destroyed||o.saveSignalsFromDeps():o.autorun&&o.run()}catch(a){let l=[a];n?.attach==null&&v(l,()=>o.destroy()),D(l,"creating an effect")}return new Pi(o)}attachChildEffect(e){this.#o.push(e)}run(){this.#f(!1)}runImmediately(){this.#f(!0)}#f(e){if(this.#c||!this.shouldRun)return;let t=Lo();if(t){if(!e){this.autorun||(this.#a=!0),t.batch(this.id,this.priority);return}t.unbatch(this.id,this.priority)}if(this.#a=!1,this.#l>=dt.maxDepth)throw new Error(`[signalize] Effect ${this.id.toString()} exceeded maxDepth=${dt.maxDepth}: an effect callback recursively re-triggered itself (likely by writing a signal it depends on). Break the cycle, or raise the cap with setMaxEffectDepth(n) if the recursion is intentional.`);this.#l++;try{this.runCleanupCallback(),this.destroyChildEffects(),this.shouldRun=!1,Cc()&&k(Ci,this.id,this.id);let r=++this.#g;this.hasStaticDeps()?this.runStaticCallback(r):this.runDynamicCallback(r)}finally{if(this.#l--,this.#l===0&&this.#u&&(this.#u=!1,!this.#c&&this.hasNoLiveSignals()))try{this.destroy()}catch(r){gs(this,r,"cleanup")}}}runStaticCallback(e){this.saveSignalsFromDeps(),this.storeCleanupCallback(this.runWithoutAutoTracking(),e)}runDynamicCallback(e){let t=new Ri(!Zs(),this.#r);if(t.active){this.#s.clear();for(let r of this.#t)this.#s.add(r)}try{this.storeCleanupCallback(Si(this,this.callback),e),t.complete()}finally{t.mayCommit(this.#r)&&(this.cleanupLostSignals(),this.#n.clear())}}runWithoutAutoTracking(){let e=this.#d;this.#d=!0;try{return Si(this,this.callback)}finally{this.#d=e}}[Pt](){if(this.shouldRun=!0,!(!this.autorun&&!this.#a))try{this.run()}catch(e){if(!Rt(e))throw e}}whenSignalIsRead(e){this.#c||this.#d||(this.#r++,this.#s.delete(e),this.#t.has(e)||(this.#t.add(e),this.#i.set(e,[y(us,e,this.priority,Pt,this),T(we,e,wi,this)])))}[wi](e,t){try{this.onSignalDestroyed(e,t)}catch(r){if(t?.detach||!Rt(r))throw r}}onSignalDestroyed(e,t){if(this.#t.has(e)){if(t?.detach){this.unsubscribeSignal(e),this.#t.delete(e),this.#n.delete(e),this.#s.delete(e),this.hasNoLiveSignals()&&this.destroyWhenUntriggerable();return}this.#n.has(e)||(this.#n.add(e),this.unsubscribeSignal(e),this.hasNoLiveSignals()&&this.destroyWhenUntriggerable())}}destroyWhenUntriggerable(){if(this.#l>0){this.#u=!0;return}this.destroy()}hasNoLiveSignals(){return this.#i.size===0}cleanupLostSignals(){if(this.#s.size===0)return;let e=[];for(let t of this.#s)v(e,()=>this.unsubscribeSignal(t)),this.#t.delete(t);D(e,"unsubscribing an effect from a signal")}destroyChildEffects(){if(this.#o.length===0)return;let e=[];this.collectDestroyChildEffects(e),D(e,"destroying an effect")}collectDestroyChildEffects(e){for(let t of this.#o)v(e,()=>t.destroy());this.#o.length=0}unsubscribeSignal(e){if(this.#i.has(e)){let t=[];try{this.#i.get(e).forEach(r=>{v(t,()=>r())})}finally{this.#i.delete(e)}D(t,"unsubscribing an effect from a signal")}}storeCleanupCallback(e,t){if(!ds(e)){typeof e=="function"&&this.acceptCleanupCallback(e,t);return}Promise.resolve(e).then(r=>{typeof r=="function"&&this.acceptCleanupCallback(r,t)},r=>{gs(this,r,"callback")})}acceptCleanupCallback(e,t){if(this.#c||t!==this.#g){this.runOrphanedCleanupCallback(e);return}let r=this.#e;this.#e=e,r!=null&&this.runOrphanedCleanupCallback(r)}runCleanupCallback(){let e=this.#e;if(e==null)return;this.#e=void 0;let t=e();ds(t)&&Promise.resolve(t).catch(r=>{gs(this,r,"cleanup")})}runOrphanedCleanupCallback(e){try{let t=e();ds(t)&&Promise.resolve(t).catch(r=>{gs(this,r,"cleanup")})}catch(t){gs(this,t,"cleanup")}}destroy(){if(this.#c)return;this.#c=!0,S(us,this),S(Me,this),S(we,this);let e=[];v(e,()=>k(this,ve,this)),v(e,()=>S(this)),v(e,()=>k(Me,vo,this)),v(e,()=>this.runCleanupCallback());try{this.collectDestroyChildEffects(e)}finally{this.#t.clear(),this.#s.clear(),this.#i.clear(),this.#n.clear(),--dt.count}D(e,"destroying an effect")}};dt=nr;O=(...s)=>nr.createEffect(...s);bo(O);Pc="hibernate() restores the saved batch, quiet counter and effect stack the moment an async callback returns its pending promise at the first `await`, so everything past that `await` runs outside the hibernation it was written inside. Do the awaiting outside of hibernate(), and pass a synchronous callback.";jo="[signalize] SignalLink destroyed before the next value arrived",Mi=class{#e;#t;#s;#i=[];#r=!1;constructor(e,t,r){this.#e=e,this.#t=t,this.#s=r}get hasSettled(){return this.#r}add(e){this.#i.push(e)}releaseAll(){this.#s!=null&&(this.#s.cancel=void 0),this.#i.forEach(e=>{e()})}settleWithValue(e){this.#r=!0,this.releaseAll(),this.#e(e)}settleWithDestroy(){this.releaseAll(),this.#t(new Error(jo))}settleWithAbort(e){this.releaseAll(),this.#t(e)}settleWithCancel(){this.releaseAll(),this.#t(new Error("[signalize] SignalLink read cancelled by the iterator"))}},or=class{#e=!1;[Ve]=[];#t=0;#s=0;#i=0;source;lastValue;isDestroyed=!1;constructor(e){$(this),this.source=_(e);let t=new WeakRef(this);this[Ve].push(y(us,this.source.id,(r,i)=>{let n=t.deref();n!=null&&!n.#e&&!n.isDestroyed&&(i?.touch===!0?n.touch():n.write())})),this[Ve].push(T(we,this.source.id,()=>t.deref()?.destroy()))}releaseOnDestroy(e){this[Ve].push(e)}attach(e){let t=Re.findOrCreate(e);return t.attachLink(this),t}nextValue(e){return this.#r(null,e)}#r(e,t,r){let{signal:i}=t??{};return new Promise((n,o)=>{if(i?.aborted){o(i.reason);return}if(this.isDestroyed){o(new Error(jo));return}let a=new Mi(n,o,r);if(r!=null&&(r.cancel=()=>a.settleWithCancel()),a.add(T(this,ve,()=>a.settleWithDestroy())),i!=null){let h=()=>a.settleWithAbort(i.reason);i.addEventListener("abort",h,{once:!0}),a.add(()=>i.removeEventListener("abort",h))}let l=y(this,cs,h=>{this.#n(e)&&a.settleWithValue(h)});a.hasSettled?l():a.add(l)})}#n(e){return e==null?!0:e.generation===this.#i?!1:(e.generation=this.#i,!0)}asyncValues(e,t){let r={},i=this.#o(r,e,t),n=i.return.bind(i);i.return=(a=>(r.cancel?.(),n(a)));let o=i.throw.bind(i);return i.throw=(a=>(r.cancel?.(),o(a))),i}async*#o(e,t,r){ye(this,cs),this.#t+=1;let i={generation:0};try{let n=0;for(;!this.isDestroyed;)try{let o=await this.#r(i,r,e);if(t?.(o,n++))break;yield o}catch(o){if(r?.signal?.aborted&&o===r.signal.reason)throw o;break}}finally{this.#t-=1,this.#t===0&&ni(this,cs)}}destroy(){if(this.isDestroyed)return;this.isDestroyed=!0;let e=[];for(let t of this[Ve])v(e,t);this[Ve].length=0,v(e,()=>k(this,ve,this)),v(e,()=>S(this)),this.lastValue=void 0,Object.freeze(this),D(e,"tearing down a SignalLink")}get isMuted(){return this.#e}mute(){return!this.isDestroyed&&!this.#e&&(this.#e=!0,k(this,bi,this)),this}unmute(){return!this.isDestroyed&&this.#e&&(this.#e=!1,k(this,Ei,this)),this}toggleMute(){return this.isDestroyed||(this.#e=!this.#e,k(this,this.#e?bi:Ei,this)),this.#e}updateValue(e){if(!this.#e&&!this.isDestroyed){let t=++this.#s,{value:r}=this.source;if(e(r),this.isDestroyed||this.#s!==t)return;this.#i=t,k(this,cs,r),this.lastValue=r}}},Ni=class extends or{target;constructor(e,t){super(e),this.target=_(t);let r=new WeakRef(this);this.releaseOnDestroy(T(we,this.target.id,()=>r.deref()?.destroy())),this.touch()}touch(){return this.updateValue(e=>{this.target.writer(e,{touch:!0})}),this}write(){this.updateValue(e=>{this.target.writer(e)})}},$i=class extends or{target;constructor(e,t){super(e),this.target=t,this.touch()}touch(){return this.updateValue(e=>{this.target(e)}),this}write(){this.updateValue(e=>{this.target(e)})}},Ti=new WeakMap,ms=0,$o=new FinalizationRegistry(s=>{for(let e of s)try{e()}catch(t){he({level:"error",source:"link-finalizer",message:"[signalize] link: releasing the queue subscriptions of a collected link failed",error:t})}s.length=0,ms>0&&(ms-=1)}),Rc=1e3,Do=new WeakSet;Mc=new FinalizationRegistry(s=>{for(let e of s.unsubs)try{e()}catch(t){he({level:"error",source:"automap-finalizer",message:"[signalize] releasing the destroy-queue subscriptions of a collected SignalAutoMap failed:",error:t})}s.unsubs.clear()}),ar=class s{static fromProps(e,t){let r=new s,i=t?[...new Set(t)].map(n=>[n,e[n]]):Object.entries(e);for(let[n,o]of i)r.#i(n,o);return r}[hs]={unsubs:new Set};#e=new Map;#t=new Map;#s=new WeakRef(this);constructor(){Mc.register(this,this[hs],this)}#i(e,t){let r=m(t);this.#e.set(e,r);let i=this.#s,n=y(we,_(r).id,(o,a)=>{if(a?.detach)return;let l=i.deref();l!==void 0&&l.#r(e)});return this.#t.set(e,n),this[hs].unsubs.add(n),r}#r(e){let t=this.#t.get(e);try{t()}finally{this.#t.delete(e),this[hs].unsubs.delete(t),this.#e.delete(e)}}keys(){return this.#e.keys()}signals(){return this.#e.values()}entries(){return this.#e.entries()}clear(){let e=[...this.#e.values()],t=[];for(let r of[...this.#e.keys()])v(t,()=>this.#r(r));for(let r of e)v(t,()=>r.destroy());D(t,"clearing a signal auto map")}delete(e){let t=this.#e.get(e);return t===void 0?!1:(this.#r(e),t.destroy(),!0)}has(e){return this.#e.has(e)}get(e){return this.#e.has(e)?this.#e.get(e):this.#i(e)}update(e){e.size&&ee(()=>{for(let[t,r]of e.entries())this.get(t).set(r)})}updateFromProps(e,t){let r=t?t.map(i=>[i,e[i]]):Object.entries(e);r.length!==0&&ee(()=>{for(let[i,n]of r)this.get(i).set(n)})}}});var De,w,se,U,Wo,_o,Fo,Io,Bo,Uo,Vo,Go,qo,Ho,Mt,Yo,Ko,Qo,Jo,Xo,ys,V=f(()=>{"use strict";De=(s=>(s[s.StructuralChanges=1]="StructuralChanges",s[s.ContentUpdates=2]="ContentUpdates",s[s.Removal=3]="Removal",s))(De||{}),w=(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",s))(w||{}),se=Symbol.for("ShadowObjectsGlobalNS"),U="#void",Wo="contextLost",_o="configure",Fo="changeTrail",Io="inspect",Bo="destroy",Uo="loaded",Vo="appliedChangeTrail",Go="importedModule",qo="destroyed",Ho="inspected",Mt="messageToView",Yo=6e4,Ko=6e4,Qo=5e3,Jo=5e3,Xo=5e3,ys="shadowObjects"});var ft,lr=f(()=>{"use strict";V();ft=s=>typeof s=="string"?s.trim()||se:typeof s=="symbol"?s:se});function ur(s,e,t){let r=Di(s),i=ws?ws.getItem(r):He.ConsoleLoggerStorage?.[r];return i==null?t:e?e(i):i}function cr(s,e){ws&&ws.setItem(Di(s),e)}var ze,Nc,$c,Dc,ws,ia,hr,He,sa,ra,Di,na,oa,E,Q=f(()=>{"use strict";ze="ConsoleLogger",Nc=`${ze}Storage`,$c=new Set(["localhost","127.0.0.1","::1","[::1]"]),Dc=$c.has(globalThis.location?.hostname??""),ws=(()=>{try{let s=globalThis.localStorage;if(typeof s?.getItem!="function"||typeof s.setItem!="function"||typeof s.removeItem!="function")return;let e=`${ze}.probe`;try{s.setItem(e,e)}finally{s.removeItem(e)}return s}catch{return}})(),ia=ws!=null,hr=Symbol.for(ze),He=globalThis,sa=!1,ra=s=>{if(typeof s=="boolean")return s;switch(s.toLowerCase()){case"true":case"yes":case"on":return!0;default:return!1}},Di=s=>[ia?ze:void 0,...Array.isArray(s)?s:[s]].filter(Boolean).join(".");na=s=>Di(s),oa=(s,e)=>ur(s,void 0,e),E=class s{constructor(e){this.enable=!0,this.namespace=(e||"").trim()||ze,sa||(s.loadConfig(),sa=!0);let t=[this.namespace,"enable"];this.enable=ur(t,ra,this.enable)}static{this.sharedConfig={enable:Dc,debug:!1,info:!0,warn:!0,"styles.debug":"color: #111; background: #999; display: inline-block; padding: 0 0.25em; margin: 0; border-radius: 0.25em","styles.info":"color: #020; background: #8a8; display: inline-block; padding: 0 0.25em; margin: 0; border-radius: 0.25em","styles.warn":"color: #fa0; background: #a98; display: inline-block; padding: 0 0.25em; margin: 0; border-radius: 0.25em","styles.error":"color: #ff0; background: #a00; display: inline-block; padding: 0 0.25em; margin: 0; border-radius: 0.25em"}}static get isEnabled(){return s.sharedConfig.enable}static get isDebug(){return s.sharedConfig.enable&&s.sharedConfig.debug}static{this.sharedStyles={get debug(){return s.sharedConfig["styles.debug"]},set debug(e){s.sharedConfig["styles.debug"]=e},get info(){return s.sharedConfig["styles.info"]},set info(e){s.sharedConfig["styles.info"]=e},get warn(){return s.sharedConfig["styles.warn"]},set warn(e){s.sharedConfig["styles.warn"]=e},get error(){return s.sharedConfig["styles.error"]},set error(e){s.sharedConfig["styles.error"]=e}}}static loadConfig(){ia?(["enable","debug","info","warn"].forEach(e=>{this.sharedConfig[e]=ur(e,ra,this.sharedConfig[e])}),["debug","info","warn","error"].forEach(e=>{this.sharedStyles[e]=ur(["styles",e],void 0,this.sharedStyles[e])}),s.isDebug&&console.debug(`${ze}: Load config from localStorage`,s.sharedConfig),He.ConsoleLogger?.[hr]||(He.ConsoleLogger??={[hr]:!0,get enable(){return s.sharedConfig.enable},set enable(e){s.sharedConfig.enable=e,cr("enable",e?"true":"false")},get debug(){return s.sharedConfig.debug},set debug(e){s.sharedConfig.debug=e,cr("debug",e?"true":"false")},get info(){return s.sharedConfig.info},set info(e){s.sharedConfig.info=e,cr("info",e?"true":"false")},get warn(){return s.sharedConfig.warn},set warn(e){s.sharedConfig.warn=e,cr("warn",e?"true":"false")}})):He.ConsoleLoggerStorage?.[hr]||(He.ConsoleLoggerStorage={[hr]:!0,...s.sharedConfig,...He.ConsoleLoggerStorage},s.sharedConfig=He.ConsoleLoggerStorage,s.isDebug&&console.debug(`${ze}: Load config from ${Nc}`,He.ConsoleLoggerStorage))}get isEnabled(){return this.enable&&s.sharedConfig.enable}get isDebug(){return this.isEnabled&&s.sharedConfig.debug}get isInfo(){return this.isEnabled&&s.sharedConfig.info}get isWarn(){return this.isEnabled&&s.sharedConfig.warn}debug(...e){this.isDebug&&this.#e("debug",s.sharedStyles.debug,e)}info(...e){this.isInfo&&this.#e("info",s.sharedStyles.info,e)}warn(...e){this.isWarn&&this.#e("warn",s.sharedStyles.warn,e)}error(...e){this.#e("error",s.sharedStyles.error,e)}#e(e,t,r){console[e](`%c${this.namespace}`,t,...r)}}});var Ye,dr=f(()=>{"use strict";Ye=class{#e=new Map;#t=!1;#s;constructor(e){this.#s=e}add(...[e,t]){this.#e.set(e,t),!this.#t&&(this.#t=!0,queueMicrotask(()=>this.flush()))}flush(){if(this.#t=!1,this.#e.size===0)return;let e=this.#e;this.#e=new Map,this.#s(e)}}});function x(s,e,t,...r){try{e()}catch(i){s.error(t,...r,i)}}var Dt=f(()=>{"use strict"});function aa(s,e){s.indexOf(e)===-1&&s.push(e)}function Li(s,e){let t=s.indexOf(e);t!==-1&&s.splice(t,1),s.push(e)}function bs(s,e){let t=s.indexOf(e);t!==-1&&s.splice(t,1)}var zi=f(()=>{"use strict"});var pt,je,Es,la=f(()=>{"use strict";V();zi();pt="#root",je=Symbol("shadow-objects/property-without-value"),Es=class{#e;get uuid(){return this.#e}constructor(e){this.#e=e}#t=!0;#s=0;#i=0;hasChanges(){return this.#t&&this.isCreated||this.isDestroyed||this.#h!==void 0&&this.#h!==this.#r||this.#u()||this.#l!==void 0&&this.#l!==this.#o||this.#f.length>0||this.#v.length>0}get isNew(){return this.#t}get isCreated(){return this.#s>0&&this.#s>this.#i}get isDestroyed(){return this.#i>0&&this.#i>=this.#s}#r=U;#n;#o=0;#a=!1;#h;#c;#l;create(e=U,t,r=0,i=!1){this.#s++,this.#h=e,this.#c=t??pt,this.#l=r||void 0,this.#a=i}destroy(){this.#i++}#u(){return this.#c===void 0?!1:(this.#c===pt?void 0:this.#c)!==this.#n}clear(){this.#h=void 0,this.#c=void 0,this.#l=void 0,this.#d.clear(),this.#f.length=0,this.#p=void 0,this.#v.length=0,this.#m.clear()}changeToken(e){e??=U,!(e===this.#r&&this.#h===void 0&&!this.#t)&&(this.#h=e)}setParent(e){let t=e??pt;t===(this.#n??pt)&&this.#c===void 0||(this.#c=t)}changeOrder(e){e===this.#o&&this.#l===void 0||(this.#l=e)}#g=new Map;#d=new Map;#f=[];#p;changeProperty(e,t,r){let i=(u,c)=>u===je||c===je||r==null?u===c:r(u,c),n=this.#f.includes(e),o=this.#p?.has(e)??!1,a;n?a=this.#d.get(e):o?a=this.#p.get(e):a=this.#g.get(e);let l=!i(t,a);return!o&&(n?i(t,this.#g.get(e)):!l)?(this.#d.delete(e),bs(this.#f,e)):(this.#d.set(e,t),Li(this.#f,e)),l}setPropertyWithoutValue(e){return this.changeProperty(e,je)}removeProperty(e){let t=this.#f.includes(e);if(this.#d.delete(e),!this.#g.has(e)&&!this.#p?.has(e)){bs(this.#f,e);return}t||Li(this.#f,e)}getProperties(){let e=new Map(this.#g);for(let t of this.#f){let r=this.#d.get(t);r===void 0?e.delete(t):e.set(t,r)}return e}#v=[];#m=new Set;createEvent(e,t,r){this.#v.push({type:e,data:t});for(let i of r??[])this.#m.add(i)}transferEventsTo(e){this.#v.length>0&&(e.#v.push(...this.#v),this.#v.length=0),this.#m.size>0&&(e.#m=new Set([...e.#m,...this.#m]),this.#m.clear())}buildChangeTrail(e,t){let{isNew:r,isCreated:i,isDestroyed:n}=this;if(!(r&&n))switch(t){case De.StructuralChanges:r?e.push(this.makeCreateEntityChange()):n||(this.#u()?e.push(this.makeSetParentChange()):this.#l!==void 0&&this.#l!==this.#o&&e.push(this.makeUpdateOrderChange()),this.#h!==void 0&&this.#h!==this.#r&&e.push(this.makeChangeToken()));break;case De.ContentUpdates:!r&&i&&this.#f.length>0&&e.push(this.makeChangePropertyChange()),this.#v.length>0&&e.push(this.makeEvents());break;case De.Removal:n&&e.push(this.makeDestroyEntityChange());break}}makeEvents(){let e={type:w.SendEvents,uuid:this.#e,events:this.#v.slice(0)};return this.#m.size>0&&(e.transferables=Array.from(this.#m)),e}makeCreateEntityChange(){let e=this.#h??this.#r,t={type:w.CreateEntities,uuid:this.#e,token:e};if(this.#c!==void 0&&this.#c!==pt&&(t.parentUuid=this.#c),this.#d.size>0){let r=[];for(let[i,n]of this.#d)n===je?r.push([i]):n!==void 0&&r.push([i,n]);this.#y(r),r.length>0&&(t.properties=r)}return this.#l!==void 0&&this.#l!==this.#o&&(t.order=this.#l),this.#a&&(t.autoDestructionOnParentRemoval=!0),t}makeDestroyEntityChange(){return{type:w.DestroyEntities,uuid:this.#e}}makeSetParentChange(){let e={type:w.SetParent,uuid:this.#e,parentUuid:this.#c===pt?void 0:this.#c};return this.#l!==void 0&&this.#l!==this.#o&&(e.order=this.#l),e}makeUpdateOrderChange(){return{type:w.UpdateOrder,uuid:this.#e,order:this.#l??0}}makeChangeToken(){return{type:w.ChangeToken,uuid:this.#e,token:this.#h??U}}makeChangePropertyChange(){let e=this.#f.map(t=>{let r=this.#d.get(t);return r===je?[t]:[t,r]});return this.#y(e),{type:w.ChangeProperties,uuid:this.#e,properties:e}}#y(e){this.#p=new Map(e.map(t=>[t[0],t.length===1?je:t[1]]))}commitChange(e){switch(e.type){case w.CreateEntities:this.#w(e.token),this.#C(e.parentUuid),this.#k(e.order??this.#o),this.#S(e.properties);for(let t of this.#f.slice(0))this.#d.get(t)===void 0&&!this.#g.has(t)&&(this.#d.delete(t),bs(this.#f,t));this.#p=void 0,this.#t=!1;break;case w.SetParent:this.#C(e.parentUuid),this.#k(e.order??this.#o);break;case w.UpdateOrder:this.#k(e.order);break;case w.ChangeToken:this.#w(e.token);break;case w.ChangeProperties:this.#S(e.properties),this.#p=void 0;break;case w.SendEvents:this.#v.splice(0,e.events.length);for(let t of e.transferables??[])this.#m.delete(t);break;case w.DestroyEntities:this.#r=U,this.#n=void 0,this.#o=0,this.#g.clear(),this.#p=void 0,this.#t=!0;break}}#w(e){this.#r=e,this.#h===e&&(this.#h=void 0)}#C(e){this.#n=e,(this.#c===pt?void 0:this.#c)===e&&(this.#c=void 0)}#k(e){this.#o=e,this.#l===e&&(this.#l=void 0)}#S(e){for(let t of e??[]){let r=t[0],i=t.length===1?je:t[1];i===void 0?this.#g.delete(r):this.#g.set(r,i),this.#d.get(r)===i&&(this.#d.delete(r),bs(this.#f,r))}}}});var ha,ji,ca=f(()=>{"use strict";ha=s=>{if(s===void 0)return;let e=s.filter(t=>t.length===1||t[1]!==void 0);return e.length===0?void 0:e},ji=(s,e)=>{if(s===e||e===void 0)return s;if(s===void 0)return ha(e)?.map(t=>t.length===1?[t[0]]:[t[0],t[1]]);for(let t of e){let r=t[0],i=t.length===1?[r]:[r,t[1]],n=s.findIndex(([o])=>o===r);n===-1?s.push(i):s[n]=i}return ha(s)}});var fr,ua=f(()=>{"use strict";V();ca();fr=class{#e=new Map;get[Symbol.iterator](){return this.#e.entries.bind(this.#e)}clear(){this.#e.clear()}isEmpty(){return this.#e.size===0}hasComponentState(e){return this.#e.has(e)}getComponentState(e){return this.#e.get(e)}write(e){for(let t of e)if(t.type===w.CreateEntities)this.createEntity(t);else if(this.#e.has(t.uuid))switch(t.type){case w.DestroyEntities:this.destroyEntity(t);break;case w.SetParent:this.setParent(t);break;case w.UpdateOrder:this.updateOrder(t);break;case w.ChangeToken:this.changeToken(t);break;case w.ChangeProperties:this.changeProperties(t);break}}changeProperties({uuid:e,properties:t}){let r=this.getComponentState(e);r.properties=ji(r.properties,t)}changeToken({uuid:e,token:t}){this.getComponentState(e).token=t||U}updateOrder({uuid:e,order:t}){this.getComponentState(e).order=t??0}setParent({uuid:e,parentUuid:t,order:r}){let i=this.getComponentState(e);i.parentUuid=t,r!==void 0&&(i.order=r)}destroyEntity({uuid:e}){this.#e.delete(e)}createEntity({uuid:e,token:t,parentUuid:r,order:i,properties:n,autoDestructionOnParentRemoval:o}){this.#e.set(e,{token:t||U,parentUuid:r,order:i??0,properties:ji(void 0,n),...o?{autoDestructionOnParentRemoval:!0}:{}})}}});var pr,Cs,Wi,P,gt=f(()=>{"use strict";V();Q();dr();Dt();lr();la();ua();pr=class{#e=[];#t=new Set;get uuids(){return this.#e}get size(){return this.#e.length}has(e){return this.#t.has(e)}push(e){this.#e.push(e),this.#t.add(e)}insertAt(e,t){this.#e.splice(e,0,t),this.#t.add(t)}delete(e){if(!this.#t.delete(e))return!1;let t=this.#e.indexOf(e);return t!==-1&&this.#e.splice(t,1),!0}clear(){this.#e.length=0,this.#t.clear()}},Cs=class extends Error{constructor(e="the component context has been disposed"){super(e),this.name="ComponentContextDisposedError"}},Wi=class extends Error{constructor(e){super(`the view component cannot join the component context because the uuid ${e} is already held by another component`),this.name="ComponentUuidInUseError",this.uuid=e}},P=class s{static{this.ReRequestParentRoots="re-request-parent-roots"}static{this.ReRequestParent="re-request-parent"}static{this.ReRequestEntHost="re-request-ent-host"}static getContextsMap(){return globalThis.__shadowObjectsContexts==null&&(globalThis.__shadowObjectsContexts=new Map),globalThis.__shadowObjectsContexts}static get(e){let t=ft(e),r=s.getContextsMap();return r.has(t)?r.get(t):new s(t)}#e=new Map;#t=new pr;#s=!1;#i=new Set;#r(e){let t=this.#e.get(e.uuid);return t!==void 0&&t.component===e?t:void 0}#n=new fr;#o=new E("ComponentContext");#a;#h(e){return e.filter(t=>t.isDestroyed||t.isNew&&!t.isCreated)}#c(e,t){for(let r of e)t?.has(r)||r.isCreated||this.#p(r.uuid,r)}#l(){let e=this.#a;e!=null&&(this.#a=void 0,this.#c(e.retiring))}constructor(e=se){let t=ft(e),r=s.getContextsMap();if(r.has(t))return r.get(t);this.ns=t,r.set(t,this)}get isDisposed(){return this.#s}addComponent(e){if(this.#s)throw new Cs(`the view component ${e.uuid} cannot join the component context because it has been disposed`);let t=this.#e.get(e.uuid);if(t){if(t.component!==e){if(this.#i.has(t.component))throw new Wi(e.uuid);for(let r of[...t.children.uuids])this.#e.get(r)?.component.removeFromParent()}t.component=e,t.children.clear()}else t={component:e,children:new pr,changes:new Es(e.uuid),propIsEqual:void 0},this.#e.set(e.uuid,t);t.changes.create(e.token,e.parent?.uuid,e.order,e.autoDestructionOnParentRemoval),e.parent?(this.addToChildren(e.parent,e),t.changes.setParent(e.parent.uuid)):this.#m(e,this.#t),this.#i.add(e),this.#y=void 0}hasComponent(e){return this.#i.has(e)}hasComponents(){return this.#e.size>0}isRootComponent(e){return this.#r(e)!==void 0&&this.#t.has(e.uuid)}destroyComponent(e){this.#i.delete(e);let t=this.#r(e);if(t!==void 0&&!t.changes.isDestroyed){for(let r of[...t.children.uuids])this.#e.get(r)?.component.removeFromParent();t.changes.destroy(),this.#y=void 0}e.context===this&&e.destroy()}getChildren(e){let t=this.#r(e)?.children;if(t===void 0)return[];let r=[];for(let i of t.uuids){let n=this.#e.get(i);n!==void 0&&r.push(n.component)}return r}removeFromParent(e,t){let r=this.#r(t);if(r===void 0)return;let i=this.#r(e);i!==void 0&&r.children.delete(e.uuid)&&(i.changes.setParent(void 0),this.#m(i.component,this.#t),this.#y=void 0)}moveToRoot(e){let t=this.#r(e);if(t===void 0)return;(e.parent?this.#r(e.parent):void 0)?.children.delete(e.uuid),t.changes.setParent(void 0),this.#m(t.component,this.#t),this.#y=void 0}changeToken(e,t){this.#r(e)?.changes.changeToken(t)}isChildOf(e,t){let r=this.#r(t);return r!==void 0&&this.#r(e)!==void 0&&r.children.has(e.uuid)}addToChildren(e,t){let r=this.#r(e);if(r){let i=this.#r(t);if(i===void 0)return;this.#m(t,r.children),i.changes.setParent(e.uuid),this.#t.delete(t.uuid),this.#y=void 0}else throw new Error(`the view component ${e.uuid} cannot have a child added to it because this context does not hold it`)}removeSubTree(e){this.#u(e,new Set)}#u(e,t){if(t.has(e))return;t.add(e);let r=this.#e.get(e);if(r){for(let i of[...r.children.uuids])this.#u(i,t);this.#p(e),this.destroyComponent(r.component)}}setProperty(e,t,r,i){let n=this.#r(e);return n!=null?(i!=null?(n.propIsEqual??=new Map,n.propIsEqual.set(t,i)):n.propIsEqual?.has(t)&&n.propIsEqual.delete(t),n.changes.changeProperty(t,r,i)):!1}setPropertyWithoutValue(e,t){let r=this.#r(e);return r!=null?(r.propIsEqual?.delete(t),r.changes.setPropertyWithoutValue(t)):!1}removeProperty(e,t){this.#r(e)?.changes.removeProperty(t)}transferPropertiesTo(e,t){let r=this.#r(e);if(r!==void 0)for(let[i,n]of r.changes.getProperties()){n===je?t.setPropertyWithoutValue(e,i):t.setProperty(e,i,n);let o=r.propIsEqual?.get(i);o!=null&&t.#g(e,i,o)}}#g(e,t,r){let i=this.#r(e);i!==void 0&&(i.propIsEqual??=new Map,i.propIsEqual.set(t,r))}changeOrder(e){let t=this.#r(e);if(t===void 0)return;let r=e.parent?this.#r(e.parent):void 0;r!==void 0?(r.children.delete(e.uuid),this.#m(e,r.children)):e.parent==null&&(this.#t.delete(e.uuid),this.#m(e,this.#t)),t.changes.changeOrder(e.order),this.#y=void 0}traverseLevelOrderBFS(){return this.#w().map(e=>e.component)}dispatchShadowObjectsEvent(e,t,r,i){this.#r(e)?.changes.createEvent(t,r,i)}broadcastEvent(e,t=void 0){for(let r of this.traverseLevelOrderBFS())r.dispatchEvent(e,t,!1)}dispatchMessage(e,t,r=void 0,i=!1){this.#e.get(e)?.component.dispatchEvent(t,r,i)}dispatchReRequestParentRoots(){for(let e of[...this.#t.uuids])this.dispatchMessage(e,s.ReRequestParentRoots)}dispatchReRequestParentChildren(e){for(let t of this.getChildren(e))this.dispatchMessage(t.uuid,s.ReRequestParentRoots)}dispatchReRequestParentSiblings(e,t=void 0){let r=e.parent;if(r==null){this.dispatchReRequestParentRoots();return}for(let i of this.getChildren(r))i!==e&&this.dispatchMessage(i.uuid,s.ReRequestParent,t)}#d=new Ye(e=>this.#f(e));collectPeerReRequest(e,t=void 0){this.#d.add(e,t)}#f(e){let t=new Map;for(let[r,i]of e){if(!this.#i.has(r))continue;let n=r.parent??null,o=t.get(n);o===void 0?t.set(n,{data:i}):o.data=void 0}for(let[r,i]of t)x(this.#o,()=>{if(r==null)this.dispatchReRequestParentRoots();else for(let n of this.getChildren(r))this.dispatchMessage(n.uuid,s.ReRequestParent,i.data)},"a peer re-request round could not be delivered:",r?.uuid??"roots")}buildChangeTrails(e=!0){this.#d.flush(),this.#a!=null&&(this.#o.debug("committing an open change trail because a second one is being built",this.#a.entries),this.commitChangeTrail(this.#a.entries.length));let t=[],r=[],i=this.hasComponents()?this.#v():[],n=(o,a)=>{let l=t.length;o.buildChangeTrail(t,a);for(let h=l;h<t.length;h++)r[h]=o};for(let o of i)n(o,De.StructuralChanges);for(let o of i)n(o,De.ContentUpdates);for(let o of i)n(o,De.Removal);return this.#a={entries:t,owners:r,retiring:this.#h(i)},e&&this.commitChangeTrail(t.length),t}commitChangeTrail(e,t){let r=this.#a;if(r==null||t!=null&&t!==r.entries)return;let{entries:i,owners:n,retiring:o}=r,a=Math.min(Math.max(e,0),i.length);this.#a=void 0;let l=new Set(n.slice(a));for(let h=0;h<a;h++)n[h].commitChange(i[h]);this.#n.write(a===i.length?i:i.slice(0,a)),this.#c(o,l)}hasComponentState(e){return this.#n.hasComponentState(e)}getComponentState(e){let t=this.#n.getComponentState(e);if(t!==void 0)return{...t,properties:t.properties?.map(r=>r.length===1?[r[0]]:[r[0],r[1]])}}reCreateChanges(){if(this.#n.isEmpty())return;let e=this.buildChangeTrails(!1);this.#n.write(e),this.#l();for(let[t,r]of this.#n){let i=this.#e.get(t);if(i){let n=new Es(t);if(n.create(r.token,r.parentUuid,r.order,r.autoDestructionOnParentRemoval),r.properties)for(let o of r.properties){let a=o[0];o.length===1?n.setPropertyWithoutValue(a):n.changeProperty(a,o[1],i.propIsEqual?.get(a))}i.changes.transferEventsTo(n),i.changes.clear(),i.changes=n}}this.#n.clear(),this.broadcastEvent(Wo)}clear(){this.#y=void 0,this.#n.clear(),this.#a=void 0;for(let e of Array.from(this.#i))e.destroy();this.#i.clear();for(let e of[...this.#t.uuids])this.removeSubTree(e);if(this.#t.size!==0)throw new Error("component-context panic: #rootComponents is not empty!");if(this.#e.size!==0)throw new Error("component-context panic: #components is not empty!")}dispose(){if(this.#s)return;this.clear(),this.#s=!0;let e=s.getContextsMap();this.ns!=null&&e.get(this.ns)===this&&e.delete(this.ns)}#p(e,t){let r=this.#e.get(e);if(r===void 0||t!==void 0&&r.changes!==t)return;let i=r.component.parent?.uuid;if(i!==void 0){let n=this.#e.get(i);n!==void 0&&n.children.delete(e)}this.#e.delete(e),this.#t.delete(e),this.#y=void 0}#v(){return this.#w().filter(e=>e.changes.hasChanges()).map(e=>e.changes)}#m(e,t){if(t.has(e.uuid))return;let{order:r}=e,i=t.size>0?this.#e.get(t.uuids[t.size-1])?.component:void 0;if(i!==void 0&&r>=i.order){t.push(e.uuid);return}for(let n=0;n<t.size;n++){let o=this.#e.get(t.uuids[n])?.component;if(o!==void 0&&r<o.order){t.insertAt(n,e.uuid);return}}t.push(e.uuid)}#y;#w(){if(this.#y)return this.#y;let e=new Map,t=new Set,r=(i,n)=>{if(t.has(i))return;t.add(i);let o=this.#e.get(i);if(o==null)return;let a=e.get(n);a?a.push(o):e.set(n,[o]);for(let l of o.children.uuids)r(l,n+1)};for(let i of this.#t.uuids)r(i,0);return this.#y=Array.from(e.entries()).sort((i,n)=>i[0]-n[0]).flatMap(([,i])=>i),this.#y}}});function xs(s){return function(e,t){let r=s?.name||t.name,i=!!(s?.readAsValue??!1);return{get(){let n=Ai(this,r);if(n)return i?n.value:n.get()},set(n){Ai(this,r)?.set(n)},init(n){let o=m(n,s);return Po(this,r,o),Re.findOrCreate(this).attachSignalByName(r,o),o.value}}}}var Ii=f(()=>{ir();});var Ke,yr=f(()=>{"use strict";Ke=class extends Error{constructor(e,t,r){super(`the kernel applied ${e} of ${t} change trail entries`,r),this.name="ChangeTrailRefusedError",this.appliedCount=e,this.entryCount=t}}});var Lt,Bi=f(()=>{"use strict";Lt=s=>s.displayName||s.name});var ka,vr,jc,We,Sa,wr=f(()=>{"use strict";zi();Bi();ka=s=>{let e=s.split("@").map(t=>t.trim());if(e.length===2&&e[1])return e[0]?{key:`${e[0]}@${e[1]}`,prop:e[1]}:{key:e[1],prop:e[1]}},vr=(s,e)=>{for(let t of e)s.add(t)},jc=(s,e)=>{if(s!=null)for(let t of s)e.add(t)},We=class{static get(e){return e??Sa}#e=new Map;#t=new Map;#s=new Map;#i=new Set;#r=new Map;define(e,t){let r=this.#e.get(e);r?aa(r,t):this.#e.set(e,[t]),this.#n()}appendRoute(e,t){let r=ka(e);if(r){this.#i.add(r.prop);let i=this.#s.get(r.key);i?vr(i,t):this.#s.set(r.key,new Set(t))}else{let i=this.#t.get(e);i?vr(i,t):this.#t.set(e,new Set(t))}this.#n()}clearRoute(e){let t=ka(e);t?this.#s.delete(t.key):this.#t.delete(e),this.#n()}#n(){this.#r.clear()}#o(e){if(e===void 0||this.#i.size===0)return"";let t="";for(let r of e)this.#i.has(r)&&(t+=`${r.length}:${r}`);return t}#a(e,t){let r=this.#o(t),i=this.#r.get(e),n=i?.get(r);if(n!==void 0)return n;let o=new Set([e]),a=Array.from(this.#t.get(e)??[]);for(let l=a.shift();l!==void 0;l=a.shift()){if(o.has(l))continue;o.add(l);let h=this.#t.get(l);h&&a.push(...Array.from(h).filter(u=>!o.has(u)))}if(t){for(let h of t){let u=this.#s.get(h);u&&vr(o,u)}let l;do{l=o.size;for(let h of new Set(o))for(let u of t){let c=this.#s.get(`${h}@${u}`);c&&vr(o,c)}}while(l!==o.size)}return i===void 0&&(i=new Map,this.#r.set(e,i)),i.set(r,o),o}findTokensByRoute(e,t){return new Set(this.#a(e,t))}findConstructors(e,t){let r=this.#a(e,t),i=new Set;for(let n of r)jc(this.#e.get(n),i);return i.size>0?Array.from(i):void 0}hasToken(e){return this.#e.has(e)}hasRoute(e){return this.#t.has(e)}describe(){let e={};for(let[i,n]of this.#e)e[i]=n.map(Lt);let t={};for(let[i,n]of this.#t)t[i]=Array.from(n);let r={};for(let[i,n]of this.#s)r[i]=Array.from(n);return{tokens:e,routes:t,propRoutes:r}}tokensOf(e){let t=[];for(let[r,i]of this.#e)i.includes(e)&&t.push(r);return t}static isDefault(e){return e===Sa}clear(){this.#e.clear(),this.#t.clear(),this.#s.clear(),this.#i.clear(),this.#n()}},Sa=new We});function kr(s,e){return new Vi(Gi(e)).serialize(s,0,new Set)}var br,Er,Gi,Wc,_c,Ui,Cr,Fc,Vi,Sr=f(()=>{"use strict";K();br=Object.freeze({maxDepth:3,maxArrayLength:20,maxObjectEntries:30,maxStringLength:200}),Er=(s,e)=>s!==void 0&&Number.isFinite(s)?s:e,Gi=s=>({maxDepth:Er(s?.maxDepth,br.maxDepth),maxArrayLength:Er(s?.maxArrayLength,br.maxArrayLength),maxObjectEntries:Er(s?.maxObjectEntries,br.maxObjectEntries),maxStringLength:Er(s?.maxStringLength,br.maxStringLength)}),Wc=s=>typeof s.nodeType=="number"&&typeof s.nodeName=="string",_c=s=>{let e=Object.getPrototypeOf(s);return e===Object.prototype||e===null},Ui=s=>{let e=s.constructor;return typeof e=="function"&&e.name?e.name:"Object"},Cr=s=>({$type:"object",class:"Error",preview:{message:s instanceof Error?s.message:String(s)}}),Fc="$truncated";Vi=class{constructor(e){this.limits=e}serialize(e,t,r){switch(typeof e){case"undefined":return{$type:"undefined"};case"boolean":return e;case"number":return Number.isFinite(e)?e:String(e);case"string":return this.string(e);case"bigint":return{$type:"bigint",value:e.toString()};case"symbol":return e.description===void 0?{$type:"symbol"}:{$type:"symbol",description:e.description};case"function":try{return le(e)?this.signal(e,t,r):{$type:"function",name:e.name}}catch(i){return Cr(i)}case"object":if(e===null)return null;try{return le(e)?this.signal(e,t,r):this.object(e,t,r)}catch(i){return Cr(i)}}}string(e){return e.length<=this.limits.maxStringLength?e:{$type:"truncated",reason:"string",original:e.length,preview:e.slice(0,this.limits.maxStringLength)}}signal(e,t,r){if(r.has(e))return{$type:"circular"};r.add(e);try{let i;try{i=qe(e)}catch(n){return Cr(n)}return{$type:"signal",value:this.serialize(i,t,r)}}finally{r.delete(e)}}object(e,t,r){if(e instanceof Date)return{$type:"date",iso:Number.isNaN(e.getTime())?"Invalid Date":e.toISOString()};if(e instanceof ArrayBuffer)return{$type:"array-buffer",byteLength:e.byteLength,class:"ArrayBuffer"};if(ArrayBuffer.isView(e))return{$type:"typed-array",byteLength:e.byteLength,class:Ui(e)};if(Wc(e))return typeof e.id=="string"&&e.id?{$type:"dom",nodeName:e.nodeName,id:e.id}:{$type:"dom",nodeName:e.nodeName};if(e instanceof Error)return{$type:"object",class:Ui(e),preview:{name:e.name,message:e.message}};if(t>this.limits.maxDepth)return{$type:"truncated",reason:"depth"};if(r.has(e))return{$type:"circular"};r.add(e);try{return Array.isArray(e)?this.array(e,t,r):e instanceof Map?{$type:"object",class:"Map",preview:{size:e.size,entries:this.array(Array.from(e.entries()),t,r)}}:e instanceof Set?{$type:"object",class:"Set",preview:{size:e.size,entries:this.array(Array.from(e),t,r)}}:_c(e)?this.entries(e,t,r):{$type:"object",class:Ui(e),preview:this.entries(e,t,r)}}finally{r.delete(e)}}array(e,t,r){let i=[],n=this.limits.maxArrayLength;for(let o=0;o<e.length&&o<n;o++)i.push(this.serialize(e[o],t+1,r));return e.length>n&&i.push({$type:"truncated",reason:"length",original:e.length}),i}entries(e,t,r){let i={},n=Object.keys(e),o=this.limits.maxObjectEntries;for(let a=0;a<n.length&&a<o;a++){let l=n[a],h;try{h=e[l]}catch(u){i[l]=Cr(u);continue}i[l]=this.serialize(h,t+1,r)}return n.length>o&&(i[Fc]={$type:"truncated",reason:"entries",original:n.length}),i}}});var As,Ic,Bc,Uc,Vc,Gc,xr,zt,qi=f(()=>{"use strict";Sr();As=Object.freeze({maxDepth:4,maxDepthCap:64,maxNodes:250,maxMatches:50}),Ic=["props","shadowObjects","contexts","registry"],Bc=s=>s===void 0?As.maxDepth:Number.isFinite(s)?Math.min(As.maxDepthCap,Math.max(0,Math.floor(s))):As.maxDepthCap,Uc=s=>s===void 0?As.maxNodes:Number.isFinite(s)?Math.max(1,Math.floor(s)):Number.MAX_SAFE_INTEGER,Vc=s=>s===void 0?As.maxMatches:Number.isFinite(s)?Math.max(1,Math.floor(s)):Number.MAX_SAFE_INTEGER,Gc=s=>s===void 0?void 0:{token:s.token,propName:s.propName,shadowObject:s.shadowObject,contextName:s.contextName,limit:Vc(s.limit)},xr=s=>({include:new Set(s?.include??Ic),rootUuids:s?.rootUuids,maxDepth:Bc(s?.maxDepth),maxNodes:Uc(s?.maxNodes),limits:Gi(s?.values),filter:Gc(s?.filter)}),zt=class{#e;constructor(e){this.#e=e}take(){return this.#e<=0?!1:(this.#e--,!0)}}});function xa(s,e){return fs(()=>new Yi(s,xr(e)).build())}var jt,Ki,Hi,qc,Yi,Hc,Qi=f(()=>{"use strict";K();wr();qi();Sr();jt=s=>typeof s=="symbol"?{symbol:s.description??""}:s,Ki=s=>s!=null&&s!==!1&&s!=="",Hi=s=>s!=null,qc=()=>typeof globalThis.WorkerGlobalScope<"u";Yi=class{#e;#t;#s;#i=new Set;#r=[];#n=new Map;#o=!1;constructor(e,t){this.#e=e,this.#t=t,this.#s=new zt(t.maxNodes)}build(){let e=this.#e.traverseLevelOrderBFS(),{filter:t}=this.#t,r=t===void 0?this.#a(e):[],i={takenAt:Date.now(),thread:qc()?"worker":"main",counts:{entities:e.length,roots:e.filter(n=>!n.hasParent).length,shadowObjects:e.reduce((n,o)=>n+this.#d(o.uuid).length,0)},roots:r,globalContexts:this.#C(e)};return this.#t.include.has("registry")&&(i.registry={...this.#e.registry.describe(),isDefault:We.isDefault(this.#e.registry)}),this.#r.length>0&&(i.truncation=this.#r),t!==void 0&&(i.search=this.#c(e,t)),i}#a(e){let t=this.#u(e),r=this.#t.rootUuids!==void 0,i=[];for(let n of t){if(this.#i.has(n.uuid))continue;if(!this.#s.take()){this.#g(void 0);break}let o=this.#p(n,0);r&&(o.ancestors=this.#h(n)),i.push(o)}return i}#h(e){let t=[];for(let r=e.parent;r!==void 0;r=r.parent)t.unshift({uuid:r.uuid,token:this.#e.tokenOf(r.uuid)??""});return t}#c(e,t){let r=[],i=0;for(let n of e)if(this.#l(n,t)&&(i++,r.length<t.limit)){let o=this.#e.tokenOf(n.uuid)??"";r.push({uuid:n.uuid,token:o,path:[...this.#h(n).map(a=>a.token),o]})}return{matches:r,total:i}}#l(e,t){let{token:r,propName:i,shadowObject:n,contextName:o}=t;return!(r!==void 0&&this.#e.tokenOf(e.uuid)!==r||i!==void 0&&!e.propKeys().includes(i)||n!==void 0&&!this.#d(e.uuid).some(a=>a.displayName===n)||o!==void 0&&!e.contextNames().includes(o))}#u(e){let{rootUuids:t}=this.#t;if(t===void 0)return e.filter(i=>!i.hasParent);let r=[];for(let i of t){let n=this.#e.findEntity(i);n===void 0?this.#r.push({reason:"unknown-root",uuid:i,message:`the kernel holds no entity "${i}"`}):r.push(n)}return r}#g(e){if(this.#o)return;this.#o=!0;let t={reason:"max-nodes",message:`maxNodes ${this.#t.maxNodes} reached; ask again with rootUuids below the last node written`};e!==void 0&&(t.uuid=e),this.#r.push(t)}#d(e){let t=this.#n.get(e);return t===void 0&&(t=this.#e.describeShadowObjects(e),this.#n.set(e,t)),t}#f(e){return kr(e,this.#t.limits)}#p(e,t){let{uuid:r}=e;this.#i.add(r);let i={uuid:r,token:this.#e.tokenOf(r)??"",order:e.order,autoDestructionOnParentRemoval:e.autoDestructionOnParentRemoval,childCount:e.children.length};e.parentUuid!==void 0&&(i.parentUuid=e.parentUuid);let{include:n}=this.#t;return n.has("props")&&(i.props=this.#m(e)),n.has("shadowObjects")&&(i.shadowObjects=this.#d(r).map(Hc)),n.has("contexts")&&(i.contexts=this.#y(e)),t<this.#t.maxDepth?this.#v(e,i,t):e.children.length>0&&this.#r.push({reason:"max-depth",uuid:r,message:`the children of "${r}" were not walked: maxDepth ${this.#t.maxDepth} reached; ask again with rootUuids: ["${r}"]`}),i}#v(e,t,r){let i=[],n=[];for(let o of e.children){if(this.#e.findEntity(o.uuid)===void 0){n.push({uuid:o.uuid,reason:"not-in-kernel"});continue}if(this.#i.has(o.uuid)){n.push({uuid:o.uuid,reason:"already-in-graph"});continue}if(!this.#s.take()){this.#g(e.uuid);break}i.push(this.#p(o,r+1))}t.children=i,n.length>0&&(t.omittedChildren=n)}#m(e){return e.propEntries().map(([t,r])=>({name:t,value:this.#f(r),routes:Ki(r)}))}#y(e){let t=this.#d(e.uuid);return e.contextNames().map(r=>{let i=e.describeContext(r),n={name:jt(r),effective:this.#f(i.effective),providedBy:t.filter(o=>o.providesContexts.includes(r)).map(o=>o.displayName),source:this.#w(e,r,i.provided)};return i.provided!==void 0&&(n.provided=this.#f(i.provided)),i.inherited!==void 0&&(n.inherited=this.#f(i.inherited)),n})}#w(e,t,r){if(Hi(r))return{kind:"self"};for(let i=e.parent;i!==void 0;i=i.parent)if(Hi(i.describeContext(t)?.provided))return{kind:"ancestor",uuid:i.uuid};return Hi(this.#e.describeRootContext(t)?.value)?{kind:"global"}:{kind:"none"}}#C(e){let t=new Map;for(let i of e)for(let n of i.globalContextNames()){let o=t.get(n);o===void 0&&t.set(n,o=new Map),o.set(i.describeGlobalContext(n).signal,i)}let r=[];for(let i of this.#e.rootContextNames()){let n=this.#e.describeRootContext(i);if(n.signals.length===0)continue;let o=t.get(i),a=[];for(let l of n.signals){let h=o?.get(l);h!==void 0&&a.push({uuid:h.uuid,providedBy:this.#d(h.uuid).filter(u=>u.providesGlobalContexts.includes(i)).map(u=>u.displayName),value:this.#f(h.describeGlobalContext(i).value)})}r.push({name:jt(i),value:this.#f(n.value),providers:a})}return r}},Hc=s=>({displayName:s.displayName,definedUnder:s.definedUnder,usesProperties:s.usesProperties,usesContexts:s.usesContexts.map(jt),usesParentContexts:s.usesParentContexts.map(jt),providesContexts:s.providesContexts.map(jt),providesGlobalContexts:s.providesGlobalContexts.map(jt),hooks:s.hooks})});function Aa(s,e){return new Ji(s,xr(e)).build()}var Yc,Kc,Qc,Ji,Ta=f(()=>{"use strict";Te();Qi();qi();Sr();Yc=/^[A-Za-z_][\w-]*$/,Kc=s=>{let e=[];for(let t=s;t!==null;t=t.parentElement){if(t.id&&Yc.test(t.id)){e.unshift(`#${t.id}`);break}let r=t.parentElement;if(r===null){e.unshift(t.localName);break}let i=Array.from(r.children).filter(n=>n.localName===t.localName);e.unshift(`${t.localName}:nth-of-type(${i.indexOf(t)+1})`)}return e.join(" > ")},Qc=()=>{let s=new Map;if(typeof document>"u")return s;for(let e of Array.from(document.querySelectorAll(js))){let t=e.uuid;typeof t=="string"&&!s.has(t)&&s.set(t,Kc(e))}return s};Ji=class{#e;#t;#s;#i=new Set;#r=[];#n;#o=!1;constructor(e,t){this.#e=e,this.#t=t,this.#s=new zt(t.maxNodes),this.#n=Qc()}build(){let e=this.#e.traverseLevelOrderBFS(),t=this.#a(e),r=[];for(let n of t)if(!this.#i.has(n.uuid)){if(!this.#s.take()){this.#h(n.parent?.uuid);break}r.push(this.#c(n,0))}let i={takenAt:Date.now(),counts:{components:e.length,roots:e.filter(n=>n.parent===void 0).length},roots:r};return this.#r.length>0&&(i.truncation=this.#r),i}#a(e){let{rootUuids:t}=this.#t;if(t===void 0)return e.filter(n=>n.parent===void 0);let r=new Map(e.map(n=>[n.uuid,n])),i=[];for(let n of t){let o=r.get(n);o===void 0?this.#r.push({reason:"unknown-root",uuid:n,message:`the component context holds no component "${n}"`}):i.push(o)}return i}#h(e){if(this.#o)return;this.#o=!0;let t={reason:"max-nodes",message:`maxNodes ${this.#t.maxNodes} reached; ask again with rootUuids below the last node written`};e!==void 0&&(t.uuid=e),this.#r.push(t)}#c(e,t){let{uuid:r}=e;this.#i.add(r);let i=this.#e.getChildren(e),n={uuid:r,token:e.token,order:e.order,childCount:i.length};e.parent!==void 0&&(n.parentUuid=e.parent.uuid);let o=this.#n.get(r);if(o!==void 0&&(n.element=o),this.#t.include.has("props")){let a=this.#l(r);a!==void 0&&(n.props=a)}if(t<this.#t.maxDepth){let a=[],l=[];for(let h of i){if(this.#i.has(h.uuid)){l.push({uuid:h.uuid,reason:"already-in-graph"});continue}if(!this.#s.take()){this.#h(r);break}a.push(this.#c(h,t+1))}n.children=a,l.length>0&&(n.omittedChildren=l)}else i.length>0&&this.#r.push({reason:"max-depth",uuid:r,message:`the children of "${r}" were not walked: maxDepth ${this.#t.maxDepth} reached; ask again with rootUuids: ["${r}"]`});return n}#l(e){let t=this.#e.getComponentState(e)?.properties;if(t!==void 0)return t.map(r=>{let i=r.length===2?r[1]:void 0;return{name:r[0],value:kr(i,this.#t.limits),routes:Ki(i)}})}}});function Xi(s){let e=new Blob([s],{type:"text/javascript"}),t=URL.createObjectURL(e),r=new Worker(t);return URL.revokeObjectURL(t),r}var Oa=f(()=>{});function Zi(){return Xi('var cc=Object.defineProperty,lc=Object.defineProperties;var hc=Object.getOwnPropertyDescriptors;var $r=Object.getOwnPropertySymbols;var lo=Object.prototype.hasOwnProperty,ho=Object.prototype.propertyIsEnumerable;var uc=(s,e)=>(e=Symbol[s])?e:Symbol.for("Symbol."+s),uo=s=>{throw TypeError(s)};var zi=(s,e,t)=>e in s?cc(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,W=(s,e)=>{for(var t in e||(e={}))lo.call(e,t)&&zi(s,t,e[t]);if($r)for(var t of $r(e))ho.call(e,t)&&zi(s,t,e[t]);return s},rs=(s,e)=>lc(s,hc(e));var fo=(s,e)=>{var t={};for(var r in s)lo.call(s,r)&&e.indexOf(r)<0&&(t[r]=s[r]);if(s!=null&&$r)for(var r of $r(s))e.indexOf(r)<0&&ho.call(s,r)&&(t[r]=s[r]);return t};var p=(s,e,t)=>zi(s,typeof e!="symbol"?e+"":e,t),Pi=(s,e,t)=>e.has(s)||uo("Cannot "+t);var n=(s,e,t)=>(Pi(s,e,"read from private field"),t?t.call(s):e.get(s)),u=(s,e,t)=>e.has(s)?uo("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,t),d=(s,e,t,r)=>(Pi(s,e,"write to private field"),r?r.call(s,t):e.set(s,t),t),l=(s,e,t)=>(Pi(s,e,"access private method"),t);var xe=(s,e,t,r)=>({set _(i){d(s,e,i,t)},get _(){return n(s,e,r)}});var Mi=function(s,e){this[0]=s,this[1]=e},go=(s,e,t)=>{var r=(c,h,f,y)=>{try{var g=t[c](h),k=(h=g.value)instanceof Mi,S=g.done;Promise.resolve(k?h[0]:h).then(A=>k?r(c==="return"?c:"next",h[1]?{done:A.done,value:A.value}:A,f,y):f({value:A,done:S})).catch(A=>r("throw",A,f,y))}catch(A){y(A)}},i=(c,h,f,y)=>a[c]=g=>(h=new Promise((k,S,A)=>(A=()=>r(c,g,k,S),o?o.then(A):A())),y=()=>o===f&&(o=0),o=f=h.then(y,y),h),o,a={};return t=t.apply(s,e),a[uc("asyncIterator")]=()=>a,i("next"),i("throw"),i("return"),a};var Ie=(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",s))(Ie||{});var yo="configure",po="changeTrail",mo="inspect",Br="destroy",vo="loaded",Di="appliedChangeTrail",Nr="importedModule",bo="destroyed",Ri="inspected",_s="messageToView";var Gs="shadowObjects";var Ue="ConsoleLogger",dc=`${Ue}Storage`,fc=new Set(["localhost","127.0.0.1","::1","[::1]"]),So,Co,gc=fc.has((Co=(So=globalThis.location)==null?void 0:So.hostname)!=null?Co:""),Ws=(()=>{try{let s=globalThis.localStorage;if(typeof(s==null?void 0:s.getItem)!="function"||typeof s.setItem!="function"||typeof s.removeItem!="function")return;let e=`${Ue}.probe`;try{s.setItem(e,e)}finally{s.removeItem(e)}return s}catch(s){return}})(),ko=Ws!=null,Is=Symbol.for(Ue),ne=globalThis,wo=!1,Eo=s=>{if(typeof s=="boolean")return s;switch(s.toLowerCase()){case"true":case"yes":case"on":return!0;default:return!1}},xo=s=>[ko?Ue:void 0,...Array.isArray(s)?s:[s]].filter(Boolean).join(".");function Li(s,e,t){var o;let r=xo(s),i=Ws?Ws.getItem(r):(o=ne.ConsoleLoggerStorage)==null?void 0:o[r];return i==null?t:e?e(i):i}function Fr(s,e){Ws&&Ws.setItem(xo(s),e)}function Ao(s){let e=ne.ConsoleLoggerStorage;if(e!=null&&e===We.sharedConfig){Object.assign(e,s,{[Is]:!0});return}ne.ConsoleLoggerStorage=s}var kt,Us,w=class w{constructor(e){u(this,kt);this.enable=!0,this.namespace=(e||"").trim()||Ue,wo||(w.loadConfig(),wo=!0);let t=[this.namespace,"enable"];this.enable=Li(t,Eo,this.enable)}static get isEnabled(){return w.sharedConfig.enable}static get isDebug(){return w.sharedConfig.enable&&w.sharedConfig.debug}static loadConfig(){var e,t,r;ko?(["enable","debug","info","warn"].forEach(i=>{this.sharedConfig[i]=Li(i,Eo,this.sharedConfig[i])}),["debug","info","warn","error"].forEach(i=>{this.sharedStyles[i]=Li(["styles",i],void 0,this.sharedStyles[i])}),w.isDebug&&console.debug(`${Ue}: Load config from localStorage`,w.sharedConfig),(e=ne.ConsoleLogger)!=null&&e[Is]||(t=ne.ConsoleLogger)!=null||(ne.ConsoleLogger={[Is]:!0,get enable(){return w.sharedConfig.enable},set enable(i){w.sharedConfig.enable=i,Fr("enable",i?"true":"false")},get debug(){return w.sharedConfig.debug},set debug(i){w.sharedConfig.debug=i,Fr("debug",i?"true":"false")},get info(){return w.sharedConfig.info},set info(i){w.sharedConfig.info=i,Fr("info",i?"true":"false")},get warn(){return w.sharedConfig.warn},set warn(i){w.sharedConfig.warn=i,Fr("warn",i?"true":"false")}})):(r=ne.ConsoleLoggerStorage)!=null&&r[Is]||(ne.ConsoleLoggerStorage=W(W({[Is]:!0},w.sharedConfig),ne.ConsoleLoggerStorage),w.sharedConfig=ne.ConsoleLoggerStorage,w.isDebug&&console.debug(`${Ue}: Load config from ${dc}`,ne.ConsoleLoggerStorage))}get isEnabled(){return this.enable&&w.sharedConfig.enable}get isDebug(){return this.isEnabled&&w.sharedConfig.debug}get isInfo(){return this.isEnabled&&w.sharedConfig.info}get isWarn(){return this.isEnabled&&w.sharedConfig.warn}debug(...e){this.isDebug&&l(this,kt,Us).call(this,"debug",w.sharedStyles.debug,e)}info(...e){this.isInfo&&l(this,kt,Us).call(this,"info",w.sharedStyles.info,e)}warn(...e){this.isWarn&&l(this,kt,Us).call(this,"warn",w.sharedStyles.warn,e)}error(...e){l(this,kt,Us).call(this,"error",w.sharedStyles.error,e)}};kt=new WeakSet,Us=function(e,t,r){console[e](`%c${this.namespace}`,t,...r)},w.sharedConfig={enable:gc,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"},w.sharedStyles={get debug(){return w.sharedConfig["styles.debug"]},set debug(e){w.sharedConfig["styles.debug"]=e},get info(){return w.sharedConfig["styles.info"]},set info(e){w.sharedConfig["styles.info"]=e},get warn(){return w.sharedConfig["styles.warn"]},set warn(e){w.sharedConfig["styles.warn"]=e},get error(){return w.sharedConfig["styles.error"]},set error(e){w.sharedConfig["styles.error"]=e}};var We=w;var oe="*",yc=1,Bi=2,Ni=4,Fi=Symbol.for("eventize"),ji=6,pc="[eventize]",ot=s=>s===oe,_i=s=>{let e=s==="emitted"?"emit":"retain";throw new Error(`${e}() must be called with a concrete event name \\u2014 \'*\' is reserved for subscribing to all events and cannot be ${s}`)},at=s=>{switch(typeof s){case"string":case"symbol":return!0;default:return!1}},Gi=s=>s!=null&&(typeof s=="object"||typeof s=="function"),mc=s=>Array.isArray(s),vc=Object.prototype,bc=(()=>{let s={},e=Function.prototype;for(let t of Reflect.ownKeys(Function.prototype))try{s[t]=e[t]}catch(r){}return s})(),wc=(s,e)=>{if(e==="constructor"||e==="__proto__")return;let t=s[e];if(t!==void 0&&t!==vc[e])return t===bc[e]?void 0:t},Ec=(s,e)=>{let t=new Array(e.length+1);t[0]=s;for(let r=0;r<e.length;++r)t[r+1]=e[r];return t},Sc=s=>s,Gr=(s,e,t,r)=>{if(typeof e=="function"){let i=e.apply(s,t);return i!=null&&(r==null||r(i)),!0}return!1},Cc=(s,e,t,r)=>{let i=s.emit;return typeof i=="function"&&Gr(s,i,Ec(e,t),r)},Ir=(s,e,t,r)=>Gr(s,wc(s,e),t,r)||Cc(s,e,t,r),kc=typeof console!="undefined",Ve=kc?console[typeof console.warn=="function"?"warn":"log"].bind(console,pc):()=>{},xc=(s,e,t)=>(Object.defineProperty(s,e,{value:t,configurable:!1}),s),Ac=0,Oc=(s,e)=>s.order-e.order,is=s=>()=>{throw new Error(`EventKeeper: ${s} is the shared empty stand-in \\u2014 replace it, never mutate it`)},Vs=Object.freeze(Object.defineProperties(new Map,{set:{value:is("events")},delete:{value:is("events")},clear:{value:is("events")}})),jr=Object.freeze(Object.defineProperties(new Set,{add:{value:is("eventNames")},delete:{value:is("eventNames")},clear:{value:is("eventNames")}})),zc=s=>{if(s.length!==0){s.sort(Oc);for(let e of s)try{e.replay()}catch(t){Ve("a retained replay threw; the batch continues. event:",e.eventName,t)}}},Pc=s=>e=>{typeof(e==null?void 0:e.then)=="function"&&e.then(void 0,t=>{Ve("a retained replay rejected; the batch continues. event:",s,t)})},Mc=class{constructor(){p(this,"events",Vs);p(this,"eventNames",jr)}mutableEvents(){return this.events===Vs&&(this.events=new Map),this.events}mutableEventNames(){return this.eventNames===jr&&(this.eventNames=new Set),this.eventNames}get retainedCount(){return this.events.size}retainedNames(){return Array.from(this.eventNames)}add(s){if(Array.isArray(s)){if(s.length===0)return;let e=this.mutableEventNames();s.forEach(t=>e.add(t))}else this.mutableEventNames().add(s)}remove(s){if(this.eventNames.size!==0){let e=this.eventNames;Array.isArray(s)?s.forEach(t=>e.delete(t)):e.delete(s),this.eventNames.size===0&&(this.eventNames=jr)}this.clear(s)}clear(s){if(this.events.size===0)return;let e=this.events;Array.isArray(s)?s.forEach(t=>e.delete(t)):e.delete(s),this.events.size===0&&(this.events=Vs)}removeAll(){this.eventNames=jr,this.events=Vs}clearAll(){this.events=Vs}retain(s,e){this.eventNames.size!==0&&this.eventNames.has(s)&&this.mutableEvents().set(s,{args:e,order:Ac++})}hasRetainedFor(s){return this.events.size!==0&&(ot(s)||this.events.has(s))}replayTo(s,e,t=[]){if(ot(s))this.events.forEach((r,i)=>{ot(i)||this.replayTo(i,e,t)});else{let r=this.events.get(s);r!=null&&t.push({order:r.order,eventName:s,replay:()=>{let i=this.events.get(s);i!==void 0&&e.apply(s,i.args,Pc(s))}})}return t}},Dc=s=>s!=null,Rc=s=>s!=null&&typeof s=="object",Qs=s=>{switch(typeof s){case"function":return yc;case"string":case"symbol":return Bi;case"object":return s===null?void 0:Ni;default:return}},Lc=0,Tc=()=>++Lc,Bo=0,$c=()=>({settled:!1,members:[],sequence:Bo++,onSettled:void 0}),Bc=class{constructor(s,e,t,r=null){p(this,"id");p(this,"eventName");p(this,"isCatchEmAll");p(this,"priority");p(this,"listener");p(this,"listenerObject");p(this,"listenerType");p(this,"callAfterApply");p(this,"isRemoved");p(this,"refCount");p(this,"onceObligations");this.id=Tc(),this.eventName=s,this.isCatchEmAll=ot(s),this.listener=t,this.listenerObject=r,this.priority=e,this.listenerType=Qs(t),this.callAfterApply=void 0,this.isRemoved=!1,this.refCount=0,this.onceObligations=void 0}isEqual(s,e){return this.listener===s&&this.listenerObject===e}detach(){if(this.isRemoved=!0,this.listener=null,this.listenerObject=null,this.callAfterApply=void 0,this.onceObligations!==void 0){for(let s of this.onceObligations){let e=s.members.indexOf(this);e>=0&&s.members.splice(e,1)}this.onceObligations=void 0}}apply(s,e=[],t){if(this.isRemoved)return;let{listener:r,listenerObject:i}=this,o=Bo;if(typeof r=="function"){Gr(i,r,e,t),this.callAfterApply&&this.callAfterApply(o);return}if(at(r)){Dc(i)&&Gr(i,i[r],e,t)&&this.callAfterApply&&this.callAfterApply(o);return}Rc(r)&&(this.isCatchEmAll||this.eventName===s)&&Ir(r,s,e,t)&&this.callAfterApply&&this.callAfterApply(o)}},He=Symbol("eventize.EventStore.dedupIndex"),No=s=>s===Ni||s===Bi,Nc=(s,e,t,r,i,o)=>s===o.listenerType?e===o.priority&&t===o.eventName&&i===o.listenerObject&&r===o.listener:!1,Fo=(s,e,t)=>s===Ni?e:t,Fc=s=>s!=null&&typeof s!="string"&&typeof s!="symbol",jo=(s,e,t)=>{let r=e.listener,i=e.listenerObject,o=No(e.listenerType),a=o?Fo(e.listenerType,r,i):void 0;o&&t(s,a,e),Fc(r)&&!(o&&a===r)&&t(s,r,e),Gi(i)&&i!==r&&!(o&&a===i)&&t(s,i,e)},jc=(s,e,t)=>{let r=s.get(e);r===void 0?s.set(e,[t]):r.push(t)},_c=(s,e,t)=>{let r=s.get(e);if(r===void 0)return;let i=r.indexOf(t);i<0||(r.splice(i,1),r.length===0&&s.delete(e))},Gc=(s,e)=>{var t;jo((t=s[He])!=null?t:s[He]=new Map,e,jc)},Oo=(s,e)=>{let t=s[He];t!==void 0&&jo(t,e,_c)},Ic=(s,e,t,r,i,o)=>{if(!No(s))return;let a=o[He];if(a===void 0)return;let c=a.get(Fo(s,r,i));if(c!==void 0){for(let h of c)if(Nc(s,e,t,r,i,h))return h}},pe=Symbol("eventize.EventStore.heldBy"),Hs=s=>{let e=s===void 0?[]:s.slice(0);return e[pe]=0,e[He]=s===void 0?void 0:s[He],e},_r=s=>()=>{throw new Error(`EventStore: ${s} is the shared empty stand-in \\u2014 replace it, never mutate it`)},zo=Object.freeze(Object.defineProperties(new Map,{set:{value:_r("namedListeners")},delete:{value:_r("namedListeners")},clear:{value:_r("namedListeners")}})),Ks=Hs();for(let s of["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"])Object.defineProperty(Ks,s,{value:_r(`the catch-em-all bucket (${s}())`)});Object.freeze(Ks);var Ti=s=>{s.forEach(e=>e.detach()),s[He]=void 0},Uc=(s,e)=>s.priority!==e.priority?e.priority-s.priority:s.id-e.id,Wc=(s,e)=>{let t=0,r=s.length;for(;t<r;){let i=t+r>>>1,o=s[i];if(o===void 0)throw new Error("EventStore: findInsertIndex encountered a hole");Uc(e,o)<0?r=i:t=i+1}return t},Po=(s,e,t,r,i)=>{let o=s.length;for(let a=0;a<o;a++){let c=s[a];c!==void 0&&e(c,t,r,i)}},Vc=(s,e,t,r,i,o)=>{let a=s.length,c=e.length,h=0,f=0;for(;h<a||f<c;){let y=h<a?s[h]:void 0,g=f<c?e[f]:void 0;if(y!==void 0&&(g===void 0||y.priority>=g.priority)){t(y,r,i,o),++h;continue}if(g!==void 0)t(g,r,i,o),++f;else throw new Error("EventStore: forEach encountered a hole")}},Hc=Object.freeze([]),Qc=class{constructor(){p(this,"namedBuckets",zo);p(this,"catchEmAllBucket",Ks);p(this,"lastAddCreatedListener",!1)}get namedListeners(){return this.namedBuckets}get catchEmAllListeners(){return this.mutableCatchEmAllBucket()}mutableNamedBuckets(){return this.namedBuckets===zo&&(this.namedBuckets=new Map),this.namedBuckets}mutableCatchEmAllBucket(){return this.catchEmAllBucket===Ks&&(this.catchEmAllBucket=Hs()),this.catchEmAllBucket}getListenersForEventName(s){let e=this.namedBuckets.get(s);return e||(e=Hs(),this.mutableNamedBuckets().set(s,e)),e}peekListeners(s){var e;return ot(s)?this.catchEmAllBucket:(e=this.namedBuckets.get(s))!=null?e:Hc}bucketForMutation(s,e){if(e[pe]===0)return e;let t=Hs(e);return e===this.catchEmAllBucket?this.catchEmAllBucket=t:this.namedBuckets.set(s,t),t}spliceOut(s,e,t){let r=e.indexOf(t);if(r<0)return e;let i=this.bucketForMutation(s,e);return i.splice(r,1),Oo(i,t),i}detachByAssociation(s,e,t){let r=e;for(let i=e.length-1;i>=0;i--){let o=e[i];o!==void 0&&o.eventName===s&&(o.listener===t||o.listenerObject===t)&&(r===e&&(r=this.bucketForMutation(s,e)),r.splice(i,1),Oo(r,o),o.detach())}return r}detachByIdentity(s,e,t,r,i){let o=e[He];if(o===void 0)return e;let a=o.get(t);if(a===void 0)return e;let c=r==null,h=e;for(let f of a.slice())((c?f.listener===t:f.isEqual(t,r))||c&&i&&f.listenerObject===t)&&(h=this.spliceOut(s,h,f),f.detach());return h}add(s,e,t,r=null,i=null){var y,g;let o=ot(s)?this.mutableCatchEmAllBucket():this.getListenersForEventName(s),a=Qs(t),c=Ic(a,e,s,t,r,o),h=c!=null?c:new Bc(s,e,t,r);if(i===null?h.refCount+=1:(y=h.onceObligations)!=null&&y.includes(i)||(((g=h.onceObligations)!=null?g:h.onceObligations=[]).push(i),i.members.push(h)),this.lastAddCreatedListener=!1,c)return c;let f=this.bucketForMutation(s,o);return f.splice(Wc(f,h),0,h),Gc(f,h),this.lastAddCreatedListener=!0,h}remove(s,e,t=!1){if(e==null&&Array.isArray(s)){s.forEach(r=>this.remove(r,null,t));return}if(s==null||e==null&&ot(s)){this.removeAllListeners();return}if(e==null&&at(s)){this.removeByEventName(s);return}if(t&&at(s)){this.removeByEventNameAndListenerObject(s,e);return}this.removeByListener(s,e)}removeByEventName(s){let e=this.namedBuckets.get(s);e!==void 0&&(Ti(e),e[pe]===0&&(e.length=0),this.namedBuckets.delete(s))}release(s){s.isRemoved||(s.refCount-=1,!(s.refCount>0||s.onceObligations!==void 0)&&this.dropListener(s))}releaseObligation(s){s.settled||this.dischargeObligation(s)}settleOneShots(s,e){let t=s.onceObligations;if(t!==void 0)for(let r of t.slice())r.sequence<e&&!r.settled&&this.dischargeObligation(r)}dischargeObligation(s){s.settled=!0;let e=s.onSettled;s.onSettled=void 0,e==null||e();let t=s.members.slice();s.members.length=0;for(let r of t){let i=r.onceObligations;if(i!==void 0){let o=i.indexOf(s);o>=0&&i.splice(o,1),i.length===0&&(r.onceObligations=void 0,r.callAfterApply=void 0)}!r.isRemoved&&r.refCount===0&&r.onceObligations===void 0&&this.dropListener(r)}}dropListener(s){if(s.isCatchEmAll)this.spliceOut(s.eventName,this.catchEmAllBucket,s);else{let e=this.namedBuckets.get(s.eventName);e&&this.spliceOut(s.eventName,e,s).length===0&&this.namedBuckets.delete(s.eventName)}s.detach()}removeByEventNameAndListenerObject(s,e){if(ot(s)){this.detachByAssociation(s,this.catchEmAllBucket,e);return}let t=this.namedBuckets.get(s);if(!t)return;this.detachByAssociation(s,t,e).length===0&&this.namedBuckets.delete(s)}removeByListener(s,e){let t=typeof s=="object"||typeof s=="function";this.namedBuckets.forEach((r,i)=>{this.detachByIdentity(i,r,s,e,t).length===0&&this.namedBuckets.delete(i)}),this.detachByIdentity(oe,this.catchEmAllBucket,s,e,t)}removeAllListeners(){this.namedBuckets.size!==0&&(this.namedBuckets.forEach(e=>{Ti(e),e[pe]===0&&(e.length=0)}),this.namedBuckets.clear());let s=this.catchEmAllBucket;s!==Ks&&(Ti(s),s[pe]!==0?this.catchEmAllBucket=Hs():s.length=0)}forEach(s,e,t,r,i){let o=this.catchEmAllBucket,a=o.length>0?o:void 0,c=s===oe?void 0:this.namedBuckets.get(s),h=c!==void 0&&c.length>0?c:void 0;if(h===void 0){if(a===void 0)return;a[pe]+=1;try{Po(a,e,t,r,i)}finally{a[pe]-=1}return}h[pe]+=1,a!==void 0&&(a[pe]+=1);try{a===void 0?Po(h,e,t,r,i):Vc(h,a,e,t,r,i)}finally{h[pe]-=1,a!==void 0&&(a[pe]-=1)}}getSubscriptionCount(){let s=this.catchEmAllBucket.length;for(let e of this.namedBuckets.values())s+=e.length;return s}getSubscribedEventNames(){let s=Array.from(this.namedBuckets.keys());return this.catchEmAllBucket.length>0&&s.push(oe),s}},Kc=s=>s[Fi],Yc=s=>{throw new TypeError(`two incompatible copies of @spearwolf/eventize are active on this object (marker protocol ${String(s)}, expected ${ji}) \\u2014 dedupe @spearwolf/eventize in your dependency tree so a single copy is loaded`)},Jc=s=>(s==null?void 0:s.protocol)===ji,Qe=s=>{let e=Kc(s);return Jc(e)?e:Yc(e==null?void 0:e.protocol)},Ae=s=>!!(s&&s[Fi]);function Ys(s){if(Ae(s))return Qe(s),s;if(!Gi(s)){let r=s;throw new TypeError(`eventize() cannot attach to ${r===null?"null":`a value of type \'${typeof r}\'`} \\u2014 eventize needs an object or a function to attach to`)}if(!Object.isExtensible(s))throw new TypeError("eventize() cannot attach to a non-extensible object \\u2014 eventize before freezing, or eventize a wrapper");let e=new Qc,t=new Mc;return xc(s,Fi,{protocol:ji,keeper:t,store:e}),s}var _o=(s,e,t,r)=>{s.apply(e,t,r)},Xc=(s,e)=>{Ve("a listener threw; the dispatch continues. event:",s,e)},Q=null,Go=(s,e)=>{Q!==null?Q.push(e):Xc(s,e)},$i=s=>s.length===1?s[0]:new AggregateError(s,"emitStrict: one or more listeners failed"),Ur=(s,e,t,r)=>{try{s.apply(e,t,r)}catch(i){Go(e,i)}},Mo=(s,e,t,r,i,o)=>{e===oe&&_i("emitted");let a=o!=null?o:Qe(s);return a.store.forEach(e,r,e,t,i),a.keeper.retain(e,t),a},ns=(s,e,t,r,i)=>{if(Array.isArray(e)){let o;for(let a=0;a<e.length;a++)a in e&&(o=Mo(s,e[a],t,r,i,o))}else Mo(s,e,t,r,i)},Wr=(s,e,t,r)=>{try{Ir(s,e,t,r)}catch(i){Go(e,i)}},Do=(s,e,t,r,i)=>{e===oe&&_i("emitted"),r(Sc(s),e,t,i)},os=(s,e,t,r,i)=>{if(Array.isArray(e))for(let o=0;o<e.length;o++)o in e&&Do(s,e[o],t,r,i);else Do(s,e,t,r,i)},as=Gi;function x(s,e,...t){Ae(s)?ns(s,e,t,_o):as(s)&&os(s,e,t,Ir)}function Js(s,e,...t){let r=Q;Q=null;try{Ae(s)?ns(s,e,t,Ur):as(s)&&os(s,e,t,Wr)}finally{Q=r}}function xt(s,e,...t){let r=Q,i=[];Q=i;try{Ae(s)?ns(s,e,t,Ur):as(s)&&os(s,e,t,Wr)}catch(o){i.push(o)}finally{Q=r}if(i.length>0)throw $i(i)}var Ro=()=>{},Io=s=>{for(let e of s)if(Array.isArray(e))for(let t of e)Promise.resolve(t).catch(Ro);else Promise.resolve(e).catch(Ro)};function Zc(s,e,...t){let r=[],i=o=>{r.push(o)};try{Ae(s)?ns(s,e,t,_o,i):as(s)&&os(s,e,t,Ir,i)}catch(o){throw Io(r),o}return r.length>0?Promise.all(r.map(o=>Array.isArray(o)?Promise.all(o):Promise.resolve(o))):Promise.resolve(void 0)}function qc(s,e,...t){let r=[],i=a=>{r.push(a)},o=Q;Q=null;try{Ae(s)?ns(s,e,t,Ur,i):as(s)&&os(s,e,t,Wr,i)}catch(a){throw Io(r),a}finally{Q=o}return r.length>0?Promise.all(r.map(a=>Array.isArray(a)?Promise.all(a):Promise.resolve(a))):Promise.resolve(void 0)}var el=(s,e,t)=>{let r=[];for(let[i,o]of e.entries()){if(o.status==="rejected"){t.push(o.reason);continue}if(!Array.isArray(s[i])){r.push(o.value);continue}let a=[];for(let c of o.value)c.status==="rejected"?t.push(c.reason):a.push(c.value);r.push(a)}return r};function tl(s,e,...t){let r=[],i=c=>{r.push(c)},o=Q,a=[];Q=a;try{Ae(s)?ns(s,e,t,Ur,i):as(s)&&os(s,e,t,Wr,i)}catch(c){a.push(c)}finally{Q=o}return r.length===0?a.length>0?Promise.reject($i(a)):Promise.resolve(void 0):Promise.allSettled(r.map(c=>Array.isArray(c)?Promise.allSettled(c):Promise.resolve(c))).then(c=>{let h=el(r,c,a);if(a.length>0)throw $i(a);return h})}var me={Max:Number.POSITIVE_INFINITY,Critical:1e9,High:1e6,Medium:1e3,Normal:0,Low:-1e4,Min:Number.NEGATIVE_INFINITY,AAA:1e9,BB:1e6,C:1e3,Default:0},sl=(s,e,t,r,i,o,a,c)=>{let h=s.add(t,r,i,o,c),f=s.lastAddCreatedListener;if(c!==null&&h.callAfterApply===void 0&&(h.callAfterApply=y=>s.settleOneShots(h,y)),e.hasRetainedFor(t)&&(f||c!==null)){let y=c===null?h:{apply:(g,k,S)=>{c.settled||h.apply(g,k,S)}};a.events=e.replayTo(t,y,a.events)}return h},Lo=(s,e)=>{if(typeof s!="number"||Number.isNaN(s))throw Ve("called with a NaN priority!",e),new Error("subscribeTo() called with a NaN priority",{cause:"invalid-priority"})},To=(s,e)=>{if(!at(s))throw Ve("called with a value that cannot be an event name!",e),new Error("subscribeTo() called with insufficient arguments",{cause:"invalid-name"})},rl=(s,e,t,r,i)=>{let o=t.length,a=typeof t[0],c,h,f,y;if(o>=2&&o<=3&&a==="number"?(c=oe,[h,f,y]=t):o>=3&&o<=4&&typeof t[1]=="number"?[c,h,f,y]=t:(h=me.Normal,a==="string"||a==="symbol"||Array.isArray(t[0])?[c,f,y]=t:(c=oe,[f,y]=t)),!f||Qs(f)===void 0){let k=f==null?"missing-listener":Qs(f)===void 0?"not-dispatchable":"empty-method-name";throw Ve(k==="missing-listener"?"called with insufficient arguments!":k==="not-dispatchable"?"called with a value that cannot be a listener!":"called with an empty method name!",t),new Error("subscribeTo() called with insufficient arguments",{cause:k})}if(Qs(f)===Bi&&y==null)throw Ve("called with a method name but no listener object!",t),new Error("subscribeTo() called with insufficient arguments",{cause:"missing-listener-object"});Array.isArray(c)||To(c,t),Lo(h,t);let g=(k,S)=>sl(s,e,S,k,f,y,r,i);if(Array.isArray(c)){if(c.length===0)throw Ve("called with an empty array of event names!",t),new Error("subscribeTo() called with insufficient arguments",{cause:"empty-names"});for(let S=0;S<c.length;S++)if(!(S in c))throw Ve("called with a sparse array of event names!",t),new Error("subscribeTo() called with insufficient arguments",{cause:"sparse-names"});return c.map(S=>{var js;let A=Array.isArray(S)?[S[0],(js=S[1])!=null?js:h]:[S,h];return To(A[0],t),Lo(A[1],t),A}).map(S=>g(S[1],S[0]))}return g(h,c)},Uo=(s,e,t,r=null)=>{let i={},o=rl(s,e,t,i,r);return i.events!==void 0&&zc(i.events),o},il=(s,e)=>{let t={host:s,listeners:e};return()=>{let r=t;if(r===null)return;t=null;let{store:i}=Qe(r.host);Array.isArray(r.listeners)?r.listeners.forEach(o=>i.release(o)):i.release(r.listeners)}},nl=(s,e)=>{let t={host:s,obligation:e};return e.settled?t=null:e.onSettled=()=>{t=null},()=>{let r=t;if(r===null)return;t=null;let{store:i}=Qe(r.host);i.releaseObligation(r.obligation)}},ol=s=>Array.isArray(s)?s.some(e=>e==null||e===oe):s===oe,O=(s,...e)=>{let t=Ys(s),{store:r,keeper:i}=Qe(t);return il(t,Uo(r,i,e))},P=(s,...e)=>{let t=Ys(s),{store:r,keeper:i}=Qe(t),o=$c();return Uo(r,i,e,o),nl(t,o)},$o=s=>{var e;return(e=s.reason)!=null?e:new DOMException("This operation was aborted","AbortError")};function al(s,e,t){let r=t==null?void 0:t.signal,i,o,a=new Promise((y,g)=>{i=y,o=g});if(r!=null&&typeof r.addEventListener!="function")throw new TypeError("options.signal must be an AbortSignal (or omitted)");if(r!=null&&r.aborted)return o($o(r)),a;let c,h=!1,f=P(s,e,(...y)=>{h=!0,r!=null&&c!=null&&r.removeEventListener("abort",c),i(y[0])});return r!=null&&!h&&(c=()=>{f(),o($o(r))},r.addEventListener("abort",c,{once:!0})),a}function M(s,e,t){if(!Ae(s))return;let{store:r,keeper:i}=Qe(s),o=typeof e,a=t!=null&&(o==="string"||o==="symbol");r.remove(e,t,a);let c=t==null&&Array.isArray(e)?e.flat(1/0):e;if(e==null||t==null&&ol(c)){i.removeAll();return}t==null&&mc(c)?i.remove(c.filter(at)):at(e)&&i.remove(e)}var Wo=s=>Array.isArray(s)?s.some(e=>e===oe):s===oe,Vo=(s,e)=>{if(!Array.isArray(e)){if(!at(e))throw new Error(`${s}() called with a value that cannot be an event name`,{cause:"invalid-name"});return}if(e.length===0)throw new Error(`${s}() called with an empty array of event names`,{cause:"empty-names"});for(let t=0;t<e.length;t++)if(!(t in e))throw new Error(`${s}() called with a sparse array of event names`,{cause:"sparse-names"});for(let t of e)if(!at(t))throw new Error(`${s}() called with a value that cannot be an event name`,{cause:"invalid-name"})},Ho=(s,e,t,r,i)=>{if(!Ae(e))throw new TypeError(`${s}() cannot operate on a non-eventized object \\u2014 eventize(obj) first, or guard the call with isEventized(obj)`);let{keeper:o}=Qe(e);if(Wo(t)){r(o);return}Vo(s,t),i(o,t)};function Xs(s,e){Wo(e)&&_i("retained"),Vo("retain",e);let t=Ys(s),{keeper:r}=Qe(t);r.add(e)}function Ii(s,e){Ho("retainClear",s,e,t=>t.clearAll(),(t,r)=>t.clear(r))}function Ui(s,e){Ho("unretain",s,e,t=>t.removeAll(),(t,r)=>t.remove(r))}var cl=O,ll=P,hl=M,ul=x,dl=Zc,fl=Js,gl=qc,yl=xt,pl=tl,ml=al,vl=Xs,bl=Ii,wl=Ui,El={on(...s){return cl(this,...s)},once(...s){return ll(this,...s)},onceAsync(s,e){return ml(this,s,e)},off(s,e){hl(this,s,e)},emit(s,...e){ul(this,s,...e)},emitAsync(s,...e){return dl(this,s,...e)},emitSafe(s,...e){fl(this,s,...e)},emitSafeAsync(s,...e){return gl(this,s,...e)},emitStrict(s,...e){yl(this,s,...e)},emitStrictAsync(s,...e){return pl(this,s,...e)},retain(s){vl(this,s)},retainClear(s){bl(this,s)},unretain(s){wl(this,s)}},Qo=Object.entries(El),q=(()=>{let s=(e={})=>Ys(e);return s.inject=(e={})=>{e=Ys(e);for(let[t,r]of Qo)Object.defineProperty(e,t,{value:r.bind(e),writable:!0,enumerable:!1,configurable:!0});return e},s.is=Ae,s})(),Sl=class{constructor(){q(this)}};for(let[s,e]of Qo)Object.defineProperty(Sl.prototype,s,{value:e,writable:!0,enumerable:!1,configurable:!0});var cs=class extends Error{constructor(e,t,r){super(`the kernel applied ${e} of ${t} change trail entries`,r),this.name="ChangeTrailRefusedError",this.appliedCount=e,this.entryCount=t}};var Ko=`module has no "${Gs}" export`;async function Wi(s,e,t,r=!0){var o,a;if(t.has(e)){s.logger.warn("importModule: skipping already imported module",e);return}else t.add(e);e.extends&&await Promise.all(e.extends.map(c=>Wi(s,c,t,!1)));let{registry:i}=s;if(e.define)for(let[c,h]of Object.entries(e.define))i.define(c,h);if(e.routes)for(let[c,h]of Object.entries(e.routes))i.appendRoute(c,h);await((a=(o=e.initialize)==null?void 0:o.call(e,{define:(c,h)=>i.define(c,h),kernel:s,registry:i}))!=null?a:Promise.resolve()),r&&s.upgradeEntities()}var _l={};var be=Symbol.for("@spearwolf/signalize/signal"),he=Symbol.for("@spearwolf/signalize/effect"),dn=Symbol.for("@spearwolf/signalize/destroySignal"),sa=Symbol.for("@spearwolf/signalize/createEffect"),ra=Symbol.for("@spearwolf/signalize/destroyEffect"),ia=Symbol.for("@spearwolf/signalize/effectError"),Cl=Symbol.for("@spearwolf/signalize/signalizeError"),lt=Symbol.for("@spearwolf/signalize/queueUnsubscribes"),sr=Symbol.for("@spearwolf/signalize/autoMapResources"),Vi=Symbol.for("@spearwolf/signalize/instances"),rr="value",fn="mute",gn="unmute",Pe="destroy",kl="off",ds=Symbol.for("@spearwolf/signalize/recall"),ir=q(),Me=q(),Xe=q(),yn=q(),xl=(s,e)=>{var t;try{let r=(t=globalThis[Vi])!=null?t:globalThis[Vi]=[];if(r.push({url:s,report:e}),r.length>1){let i={level:"error",source:"multiple-instances",message:`[signalize] ${r.length} copies of @spearwolf/signalize are loaded in this process; they share no signals, effects, groups or links. Loaded from: ${r.map(({url:o})=>o).join(", ")}`};try{r[0].report(i)}catch(o){e(i)}}return r.length}catch(r){return 0}},Al=0;var Ol=({level:s,message:e,error:t})=>{let r=s==="warn"?console.warn:console.error;t===void 0?r(e):r(e,t)},Ee=s=>{if(Al>0)try{x(Xe,Cl,s);return}catch(e){console.error(`[signalize] an onSignalizeError handler threw while reporting a ${s.source} diagnostic:`,e)}Ol(s)};xl(_l.url,Ee);var Yo=new Set,Xi=(s,e)=>{Yo.has(s)||(Yo.add(s),Ee({level:"warn",source:"deprecation",message:e}))},Zi,na=s=>{Zi=s},oa=()=>{if(Zi===void 0)throw new Error(\'[signalize] effect subsystem not registered \\u2014 Signal.onChange() and signalReader(callback) need it. Import "@spearwolf/signalize" through its entry point, so that effects.js is evaluated.\');return Zi},nr=s=>s!=null&&typeof s.then=="function",pn=(s,e,t,r)=>{if(nr(s))throw new TypeError(`[signalize] ${e}: ${t} must be synchronous, but it returned a thenable. ${r}`)},qi=0,zl="beQuiet() closes its frame the moment an async action returns its pending promise at the first `await` \\u2014 every read after that point is tracked again and every write loud again, and the promise handed back would resolve outside the frame that appeared to produce it. Do the awaiting outside of beQuiet(), and pass a synchronous action.";function mn(s){qi++;try{let e=s();return pn(e,"beQuiet","action",zl),e}finally{qi--}}function Yr(){return qi>0}var F=(s,e)=>{if(s.length!==0)throw s.length===1?s[0]:new AggregateError(s,`[signalize] ${s.length} errors while ${e}`)},C=(s,e)=>{try{e()}catch(t){s.push(t)}},vn=0,zt,Jr=()=>{vn++;let s=zt;return zt=void 0,s},Xr=(s,e)=>{let t=zt;zt=s,vn--,t!==void 0&&F(t,e)},fs=s=>vn===0?!1:(zt===void 0&&(zt=[]),zt.push(s),!0),en=[],Zr=()=>en.at(-1),bn=(s,e)=>{en.push(s);try{return e()}finally{en.pop()}};var wn=0,aa=new FinalizationRegistry(()=>{--wn}),Pl=s=>{++wn,aa.register(s,void 0,s)};function Jo(s){var e;Yr()||(e=Zr())==null||e.whenSignalIsRead(s)}function tn(s,e,t){if(!Yr()){let r=Jr();try{x(ir,s,e,t)}catch(i){fs(i)}finally{Xr(r,"notifying the effects of a signal write")}}}var we=s=>s!=null&&s[be]!=null,H=s=>s==null?void 0:s[be],$=(...s)=>{for(let e of s){let t=H(e);if(t!=null&&!t.destroyed){t.destroyed=!0,t.beforeRead=void 0,aa.unregister(t),--wn;let r=Jr();try{x(Me,t.id,t.id)}catch(i){fs(i)}finally{Xr(r,"notifying the subscribers of a destroyed signal")}}}};var us=new WeakMap,Ml=s=>{let e=us.get(s);return e||(e={},us.set(s,e)),e},or=(s,e)=>{var t,r;return(r=(t=us.get(s))==null?void 0:t.signals)==null?void 0:r.get(e)},En=(s,e)=>{var t,r;return(r=(t=us.get(s))==null?void 0:t.signals)==null?void 0:r.get(e)};var ca=(s,e,t)=>{var i;let r=Ml(s);(i=r.signals)!=null||(r.signals=new Map),r.signals.set(e,t)};function Sn(...s){let e=[];for(let t of s)if(us.has(t)){let r=us.get(t);if(r.signals){for(let i of r.signals.values())C(e,()=>$(i));r.signals.clear(),r.signals=void 0}}F(e,"destroying the signals of an object")}function la(s){if(!we(s)&&!Array.isArray(s))throw new TypeError("[signalize] touch: source must be a signal or an [object, propertyName] tuple");let e=H(we(s)?s:or(...s));e!=null&&!e.muted&&!e.destroyed&&tn(e.id,e.value,{touch:!0})}function ht(s){var e,t;if(!we(s)&&!Array.isArray(s))throw new TypeError("[signalize] value: source must be a signal or an [object, propertyName] tuple");return we(s)?(e=H(s))==null?void 0:e.value:(t=H(or(...s)))==null?void 0:t.value}var ea;ea=be;var Kr=class{constructor(e){p(this,ea);this[be]=e}get get(){return this[be].reader}get set(){return this[be].writer}get value(){return ht(this.get)}set value(e){this.set(e)}onChange(e){let{destroy:t}=oa()(()=>e(this.get()),[this.get]);return t}get muted(){return this[be].muted}set muted(e){this[be].muted=e}get destroyed(){return this[be].destroyed}touch(){la(this)}destroy(){$(this)}},At=new WeakMap,ls=new Set,Ke=Symbol.for("@spearwolf/signalize/groupResources"),Xo=new FinalizationRegistry(s=>{for(let e of s.unsubs)try{e()}catch(t){Ee({level:"error",source:"group-finalizer",message:"[signalize] releasing the destroy-queue subscriptions of a collected SignalGroup failed:",error:t})}s.unsubs.clear(),s.selfRef!=null&&ls.delete(s.selfRef)}),Dl=s=>{let e=s[Ke].selfRef;if(!(e==null||!ls.has(e)))try{s.clear()}catch(t){Ee({level:"error",source:"group-finalizer",message:"[signalize] a SignalGroup teardown threw in the FinalizationRegistry callback, where no caller can catch it:",error:t})}},Zo=new FinalizationRegistry(s=>{let e=s.deref();e!==void 0&&Dl(e)});var Rl=Symbol.for("@spearwolf/signalize/setParentGroup"),Hi=1,Qi=2,Ki=4,Yi=8,Ji=16,qo="[signalize] Cannot attach a group to one of its own descendants: this would create a cycle in the group graph",qr="[signalize] internal error: a shared empty stand-in collection was written to",sn=class extends Set{add(){throw new Error(qr)}},rn=class extends Map{set(){throw new Error(qr)}},nn=class extends WeakMap{set(){throw new Error(qr)}},on=class extends WeakSet{add(){throw new Error(qr)}},Zs=new sn,Qr=new rn,ha=new nn,ua=new on,Vr=s=>s===Zs?new Set:s,Hr=s=>s===Qr?new Map:s,Ll=s=>s===ha?new WeakMap:s,Tl=s=>s===ua?new WeakSet:s,ta,ee,Oe,V,ae,te,Ye,ce,ze,le,hs,N,R,Ot,j,an,cn,ln,da,hn,ct=class ct{constructor(e){u(this,j);u(this,ee,Zs);u(this,Oe,new Set);u(this,V,Qr);u(this,ae,ha);u(this,te,Qr);u(this,Ye,Zs);u(this,ce,new Set);u(this,ze,Qr);p(this,ta,{unsubs:Zs});u(this,le,Zs);u(this,hs,ua);u(this,N);u(this,R,0);u(this,Ot);if(e!=null&&e instanceof ct)return e;if(e!=null||(e=this),At.has(e))return At.get(e);d(this,Ot,new WeakRef(e)),At.set(e,this);let t=new WeakRef(this);this[Ke].selfRef=t,ls.add(t),Xo.register(this,this[Ke],this),e!==this&&Zo.register(e,t,this),q(this)}static get(e){if(e!=null)return e instanceof ct?e:At.get(e)}static findOrCreate(e){var t;if(e==null)throw new Error("[signalize] Cannot create a group with a null object");return e instanceof ct?e:(t=At.get(e))!=null?t:new ct(e)}static destroy(e){Xi("SignalGroup.destroy","[signalize] SignalGroup.destroy(obj) is deprecated. Use SignalGroup.delete(obj) instead."),ct.delete(e)}static delete(e){var t;if(e instanceof ct){e.clear();return}(t=At.get(e))==null||t.clear()}static clear(){let e=[];for(let t of[...ls]){let r=t.deref();if(r===void 0){ls.delete(t);continue}C(e,()=>r.clear())}F(e,"clearing all signal groups")}attachGroup(e){if(e===this)throw new Error("[signalize] Cannot attach a group to itself");let t=this,r=n(this,N);for(;r!=null;){if(r===e)throw new Error(qo);if(r=n(r,N),r==null)break;if(r===e)throw new Error(qo);if(r=n(r,N),t=n(t,N),r!=null&&r===t)throw new Error("[signalize] Cannot attach a group: the parent chain of this group is already cyclic")}return d(this,ee,Vr(n(this,ee))).add(e),n(e,N)&&n(e,N)!==this&&n(n(e,N),ee).delete(e),d(e,N,this),e}detachGroup(e){return e!==this&&n(this,ee).has(e)&&(n(this,ee).delete(e),d(e,N,void 0)),e}[(ta=Ke,Rl)](e){d(this,N,e)}attachSignal(e){let t=l(this,j,an).call(this,e);return t&&d(this,Ye,Vr(n(this,Ye))).add(t),e}attachSignalByName(e,t){if(t){let r=l(this,j,an).call(this,t),i=n(this,V).get(e);i!=null&&i!==r&&l(this,j,da).call(this,e,i),d(this,V,Hr(n(this,V))).set(e,r);let o=n(this,te).get(e);o?o.add(r):d(this,te,Hr(n(this,te))).set(e,new Set([r])),n(this,ae).has(r)?n(this,ae).get(r).add(e):d(this,ae,Ll(n(this,ae))).set(r,new Set([e]))}else{let r=n(this,te).get(e);if(r)for(let i of[...r])l(this,j,ln).call(this,e,i);n(this,V).delete(e)}return t}hasSignal(e){var t;if(n(this,R)&Hi)return!1;d(this,R,n(this,R)|Hi);try{return n(this,V).has(e)||!!((t=n(this,N))!=null&&t.hasSignal(e))}finally{d(this,R,n(this,R)&~Hi)}}signal(e){var t,r,i;if(!(n(this,R)&Qi)){d(this,R,n(this,R)|Qi);try{return(i=(t=n(this,V).get(e))==null?void 0:t.object)!=null?i:(r=n(this,N))==null?void 0:r.signal(e)}finally{d(this,R,n(this,R)&~Qi)}}}detachSignal(e){let t=H(e);return t&&l(this,j,hn).call(this,t),e}attachEffect(e){let t=e!=null&&he in e?e[he]:e;if(t==null||t.destroyed)throw new Error("[signalize] Cannot attach a destroyed effect to a group");return n(this,ce).has(t)||(n(this,ce).add(t),P(t,Pe,me.Max,()=>{n(this,ce).delete(t)})),e}runEffects(){if(!(n(this,R)&Ki)){d(this,R,n(this,R)|Ki);try{for(let e of n(this,ce))e.run();for(let e of n(this,ee))e.runEffects()}finally{d(this,R,n(this,R)&~Ki)}}}attachLink(e){if(e!=null&&e.isDestroyed)throw new Error("[signalize] Cannot attach a destroyed link to a group");return e&&(d(this,le,Vr(n(this,le))).add(e),n(this,hs).has(e)||(d(this,hs,Tl(n(this,hs))).add(e),P(e,Pe,me.Max,()=>{n(this,le).delete(e)}))),e}detachLink(e){return e&&n(this,le).delete(e),e}get memberCounts(){return{signals:n(this,Oe).size,namedSignals:n(this,V).size,signalsByName:n(this,te).size,effects:n(this,ce).size,links:n(this,le).size,groups:n(this,ee).size}}destroy(){Xi("SignalGroup#destroy","[signalize] SignalGroup#destroy is deprecated. Use SignalGroup#clear instead."),this.clear()}off(){if(!(n(this,R)&Yi)){d(this,R,n(this,R)|Yi);try{let e=[];for(let t of[...n(this,ee)])C(e,()=>t.off());for(let t of[...n(this,ce)])C(e,()=>t.destroy());n(this,ce).clear();for(let t of[...n(this,le)])C(e,()=>t.destroy());n(this,le).clear();for(let t of[...n(this,Oe)])t.destroyed||C(e,()=>x(Me,t.id,t.id,{detach:!0}));C(e,()=>x(this,kl,this)),F(e,"switching off a signal group")}finally{d(this,R,n(this,R)&~Yi)}}}clear(){var e;if(!(n(this,R)&Ji)){d(this,R,n(this,R)|Ji);try{let t=[];C(t,()=>x(this,Pe,this)),C(t,()=>M(this));for(let r of[...n(this,ee)])C(t,()=>r.clear());for(let r of[...n(this,ce)])C(t,()=>r.destroy());for(let r of[...n(this,Oe)])C(t,()=>$(r));for(let r of[...n(this,le)])C(t,()=>r.destroy());for(let r of[...n(this,ze).values()])C(t,()=>r());if(n(this,ze).clear(),n(this,ee).clear(),n(this,Oe).clear(),n(this,V).clear(),n(this,te).clear(),n(this,Ye).clear(),n(this,ce).clear(),n(this,le).clear(),(e=n(this,N))==null||e.detachGroup(this),n(this,Ot)){let r=n(this,Ot).deref();r!==void 0&&At.delete(r),d(this,Ot,void 0)}ls.delete(this[Ke].selfRef),this[Ke].unsubs.clear(),Zo.unregister(this),Xo.unregister(this),F(t,"clearing a signal group")}finally{d(this,R,n(this,R)&~Ji)}}}};ee=new WeakMap,Oe=new WeakMap,V=new WeakMap,ae=new WeakMap,te=new WeakMap,Ye=new WeakMap,ce=new WeakMap,ze=new WeakMap,le=new WeakMap,hs=new WeakMap,N=new WeakMap,R=new WeakMap,Ot=new WeakMap,j=new WeakSet,an=function(e){let t=H(e);if(t!=null&&t.destroyed)throw new Error("[signalize] Cannot attach a destroyed signal to a group");if(t&&(n(this,Oe).add(t),!n(this,ze).has(t))){let r=this[Ke].selfRef,i=new WeakRef(t),o=O(Me,t.id,(c,h)=>{var g;if(h!=null&&h.detach)return;let f=i.deref(),y=r.deref();f!==void 0&&y!==void 0&&l(g=y,j,hn).call(g,f)});d(this,ze,Hr(n(this,ze))).set(t,o);let a=this[Ke];(a.unsubs=Vr(a.unsubs)).add(o)}return t},cn=function(e){let t=n(this,ze).get(e);if(t)try{t()}finally{n(this,ze).delete(e),this[Ke].unsubs.delete(t)}},ln=function(e,t){let r=n(this,te).get(e);r&&(r.delete(t),r.size===0&&n(this,te).delete(e));let i=n(this,ae).get(t);i&&(i.delete(e),i.size===0&&(n(this,ae).delete(t),n(this,Ye).has(t)||(l(this,j,cn).call(this,t),n(this,Oe).delete(t),$(t))))},da=function(e,t){n(this,Ye).has(t)||l(this,j,ln).call(this,e,t)},hn=function(e){let t=[];if(C(t,()=>l(this,j,cn).call(this,e)),n(this,Oe).delete(e),n(this,Ye).delete(e),n(this,ae).has(e)){let r=n(this,ae).get(e);for(let i of r){let o=n(this,te).get(i);if(o){if(o.delete(e),o.size===0)n(this,V).delete(i),n(this,te).delete(i);else if(n(this,V).get(i)===e){let a;for(let c of o)a=c;d(this,V,Hr(n(this,V))).set(i,a)}}}r.clear(),n(this,ae).delete(e)}F(t,"detaching a signal from a signal group")};var Je=ct,er,tr,qs=class{constructor(e="id",t=1){u(this,er);u(this,tr);d(this,er,e),d(this,tr,t)}make(){return Symbol(`${n(this,er)}${xe(this,tr)._++}`)}};er=new WeakMap,tr=new WeakMap;var $l=new qs("si"),Bl=["lazy","compare","beforeRead"],Nl=(s,e)=>s===e;function Fl(){Xi("signalReader(callback)","[signalize] signalReader(callback) is deprecated and will be removed in a future release. Use Signal.onChange(callback) instead \\u2014 it returns an unsubscribe function for proper cleanup.")}var jl=s=>{let e=t=>{var r;return s.destroyed||(r=s.beforeRead)==null||r.call(s),t?(Fl(),oa()(()=>(s.destroyed||Jo(s.id),t(s.value)),[e])):s.destroyed||Jo(s.id),s.value};return Object.defineProperty(e,be,{value:s}),e},ve,un=class{constructor(e,t){p(this,"id");p(this,"lazy");p(this,"compare");p(this,"beforeRead");p(this,"muted",!1);p(this,"destroyed",!1);u(this,ve);p(this,"valueFn");p(this,"reader");p(this,"writer",(e,t)=>{var c,h,f;let r=(c=t==null?void 0:t.lazy)!=null?c:!1,i=(h=t==null?void 0:t.compare)!=null?h:this.compare,o=i!=null?i:Nl;if((r!==this.lazy||r&&e!==this.valueFn||!r&&!o(e,n(this,ve)))&&(r?(d(this,ve,void 0),this.valueFn=e,this.lazy=!0):(d(this,ve,e),this.valueFn=void 0,this.lazy=!1),!this.muted&&!this.destroyed)){tn(this.id,n(this,ve));return}(f=t==null?void 0:t.touch)!=null&&f&&!this.muted&&!this.destroyed&&tn(this.id,n(this,ve),{touch:!0})});p(this,"object");this.id=$l.make(),Pl(this),this.lazy=e,this.lazy?(this.value=void 0,this.valueFn=t):(this.value=t,this.valueFn=void 0),this.reader=jl(this),this.object=new Kr(this)}get[be](){return this}get value(){return this.lazy&&(d(this,ve,this.valueFn()),this.valueFn=void 0,this.lazy=!1),n(this,ve)}set value(e){d(this,ve,e)}};ve=new WeakMap;function _(s=void 0,e){var r;let t;if(we(s)){t=H(s);let i=Bl.filter(o=>(e==null?void 0:e[o])!=null);i.length>0&&Ee({level:"warn",source:"ignored-option",message:`[signalize] createSignal(existingSignal, {${i.join(", ")}}) is a passthrough: it returns the signal that was passed in, so nothing in those braces is applied. Only {attach} works on this path. Configure the signal where it is created, or drop the options.`})}else{let i=(r=e==null?void 0:e.lazy)!=null?r:!1;t=new un(i,s),t.beforeRead=e==null?void 0:e.beforeRead,t.compare=e==null?void 0:e.compare}return(e==null?void 0:e.attach)!=null&&Je.findOrCreate(e.attach).attachSignal(t),t.object}var kn=0,Gl=()=>kn>0,ft=class{constructor(){p(this,"delayedEffects",[])}batch(e,t){let r=this.delayedEffects.length;for(let i=0;i<r;i++){let[o,a]=this.delayedEffects[i];if(!(o>t)){if(o===t){a.add(e);return}this.delayedEffects.splice(i,0,[t,new Set([e])]);return}}this.delayedEffects.push([t,new Set([e])])}unbatch(e,t){let r=this.delayedEffects.length;for(let i=0;i<r;i++){let[o,a]=this.delayedEffects[i];if(o===t){a.delete(e);return}}}flush(){try{this.run()}finally{this.delayedEffects.length=0}}run(){if(this.delayedEffects.length===0)return;let e=new Set,t=[];kn++;let r=Jr();try{t.push(O(Xe,(i,o)=>{o===ds&&e.add(i)}),O(yn,i=>{e.add(i)}));for(let[,i]of this.delayedEffects)for(let o of i)if(!e.has(o))try{x(Xe,o,o,ds)}catch(a){fs(a)}}finally{try{for(let i of t)i()}finally{try{Xr(r,"flushing a batch of signal writes")}finally{kn--}}}}};p(ft,"current");var Il=()=>ft.current;var Ul="batch() only sees writes made on the current call stack \\u2014 an async callback stops being batched at its first `await`, so every write after that runs unbatched without any error. Move the async work outside of batch(), or split it into several synchronous batch() calls.";function Bt(s){let e=ft.current;e?e=void 0:e=ft.current=new ft;let t;try{let r=s();pn(r,"batch","callback",Ul)}catch(r){t=[r]}finally{if(e){ft.current=void 0;try{e.run()}catch(r){t===void 0?t=[r]:t.push(r)}}}t!==void 0&&F(t,"running a batch")}var Wl=()=>{},ya;ya=he;var xn=class{constructor(e){p(this,ya);p(this,"run",()=>{var e;return(e=this[he])==null?void 0:e.run()});p(this,"runImmediately",()=>{var e;return(e=this[he])==null?void 0:e.runImmediately()});p(this,"destroy",()=>{var e;(e=this[he])==null||e.destroy(),this[he]=void 0});this[he]=e,P(e,Pe,()=>{this[he]=void 0})}get destroyed(){let e=this[he];return e==null||e.destroyed}onDestroy(e){let t=this[he];return t==null||t.destroyed?(e(),Wl):P(t,Pe,e)}},Vl=0,Hl=()=>Vl>0;var Pt,ar=(s,e,t)=>{if(Hl()){let r={error:e,effect:s,effectId:s.id,phase:t};try{x(Xe,ia,r);return}catch(i){console.error(`[signalize] an onEffectError handler threw while reporting an error of effect ${s.id.toString()}:`,i)}}Ee({level:"error",source:"effect",message:`[signalize] unhandled rejection in the ${t} of effect ${s.id.toString()}:`,error:e})},lr,hr,An=class{constructor(e,t){p(this,"active");u(this,lr);u(this,hr,!1);this.active=e,d(this,lr,t)}complete(){d(this,hr,!0)}mayCommit(e){return this.active&&(n(this,hr)||e>n(this,lr))}};lr=new WeakMap,hr=new WeakMap;var Dt,De,Re,Ze,gs,ut,Rt,ys,Lt,Le,dt,ps,ur,Tt,dr,On,Mt=class{constructor(e,t){u(this,dr);p(this,"id");p(this,"callback");u(this,Dt);u(this,De,new Set);u(this,Re,new Set);u(this,Ze,new Map);u(this,gs,0);u(this,ut,new Set);u(this,Rt,[]);p(this,"autorun",!0);p(this,"shouldRun",!0);u(this,ys,!1);p(this,"priority");u(this,Lt);u(this,Le,!1);u(this,dt,0);u(this,ps,!1);u(this,ur,0);u(this,Tt,!1);var i,o;q(this),this.callback=e;let r=(t==null?void 0:t.attach)!=null?Je.findOrCreate(t.attach):void 0;this.autorun=(i=t==null?void 0:t.autorun)!=null?i:!0,d(this,Lt,t!=null&&t.dependencies?t.dependencies.map(a=>{switch(typeof a){case"string":case"symbol":{if(r==null)throw new Error(`[signalize] createEffect: cannot resolve dependency "${String(a)}" \\u2014 no SignalGroup is attached (missing "attach" option)`);let c=r.signal(a);if(c==null)throw new Error(`[signalize] createEffect: cannot resolve dependency "${String(a)}" \\u2014 no signal with that name is registered in the attached SignalGroup`);return c}default:return a}}):void 0),this.id=Pt.idGen.make(),this.priority=(o=t==null?void 0:t.priority)!=null?o:0,O(Xe,this.id,ds,this),r==null||r.attachEffect(this),++Pt.count}get destroyed(){return n(this,Le)}hasStaticDeps(){return n(this,Lt)!=null&&n(this,Lt).length>0}saveSignalsFromDeps(){for(let e of n(this,Lt)){let t=H(e);t.destroyed||this.whenSignalIsRead(t.id)}}static createEffect(e,t,r){var c;let i=Array.isArray(t)?t:void 0,o=i?rs(W({},r),{dependencies:i}):t,a=new Pt(e,o);try{(c=Zr())==null||c.attachChildEffect(a),x(Xe,sa,a),a.hasStaticDeps()?a.destroyed||a.saveSignalsFromDeps():a.autorun&&a.run()}catch(h){let f=[h];(o==null?void 0:o.attach)==null&&C(f,()=>a.destroy()),F(f,"creating an effect")}return new xn(a)}attachChildEffect(e){n(this,Rt).push(e)}run(){l(this,dr,On).call(this,!1)}runImmediately(){l(this,dr,On).call(this,!0)}runStaticCallback(e){this.saveSignalsFromDeps(),this.storeCleanupCallback(this.runWithoutAutoTracking(),e)}runDynamicCallback(e){let t=new An(!Yr(),n(this,gs));if(t.active){n(this,Re).clear();for(let r of n(this,De))n(this,Re).add(r)}try{this.storeCleanupCallback(bn(this,this.callback),e),t.complete()}finally{t.mayCommit(n(this,gs))&&(this.cleanupLostSignals(),n(this,ut).clear())}}runWithoutAutoTracking(){let e=n(this,Tt);d(this,Tt,!0);try{return bn(this,this.callback)}finally{d(this,Tt,e)}}[ds](){if(this.shouldRun=!0,!(!this.autorun&&!n(this,ys)))try{this.run()}catch(e){if(!fs(e))throw e}}whenSignalIsRead(e){n(this,Le)||n(this,Tt)||(xe(this,gs)._++,n(this,Re).delete(e),n(this,De).has(e)||(n(this,De).add(e),n(this,Ze).set(e,[O(ir,e,this.priority,ds,this),P(Me,e,dn,this)])))}[dn](e,t){try{this.onSignalDestroyed(e,t)}catch(r){if(t!=null&&t.detach||!fs(r))throw r}}onSignalDestroyed(e,t){if(n(this,De).has(e)){if(t!=null&&t.detach){this.unsubscribeSignal(e),n(this,De).delete(e),n(this,ut).delete(e),n(this,Re).delete(e),this.hasNoLiveSignals()&&this.destroyWhenUntriggerable();return}n(this,ut).has(e)||(n(this,ut).add(e),this.unsubscribeSignal(e),this.hasNoLiveSignals()&&this.destroyWhenUntriggerable())}}destroyWhenUntriggerable(){if(n(this,dt)>0){d(this,ps,!0);return}this.destroy()}hasNoLiveSignals(){return n(this,Ze).size===0}cleanupLostSignals(){if(n(this,Re).size===0)return;let e=[];for(let t of n(this,Re))C(e,()=>this.unsubscribeSignal(t)),n(this,De).delete(t);F(e,"unsubscribing an effect from a signal")}destroyChildEffects(){if(n(this,Rt).length===0)return;let e=[];this.collectDestroyChildEffects(e),F(e,"destroying an effect")}collectDestroyChildEffects(e){for(let t of n(this,Rt))C(e,()=>t.destroy());n(this,Rt).length=0}unsubscribeSignal(e){if(n(this,Ze).has(e)){let t=[];try{n(this,Ze).get(e).forEach(r=>{C(t,()=>r())})}finally{n(this,Ze).delete(e)}F(t,"unsubscribing an effect from a signal")}}storeCleanupCallback(e,t){if(!nr(e)){typeof e=="function"&&this.acceptCleanupCallback(e,t);return}Promise.resolve(e).then(r=>{typeof r=="function"&&this.acceptCleanupCallback(r,t)},r=>{ar(this,r,"callback")})}acceptCleanupCallback(e,t){if(n(this,Le)||t!==n(this,ur)){this.runOrphanedCleanupCallback(e);return}let r=n(this,Dt);d(this,Dt,e),r!=null&&this.runOrphanedCleanupCallback(r)}runCleanupCallback(){let e=n(this,Dt);if(e==null)return;d(this,Dt,void 0);let t=e();nr(t)&&Promise.resolve(t).catch(r=>{ar(this,r,"cleanup")})}runOrphanedCleanupCallback(e){try{let t=e();nr(t)&&Promise.resolve(t).catch(r=>{ar(this,r,"cleanup")})}catch(t){ar(this,t,"cleanup")}}destroy(){if(n(this,Le))return;d(this,Le,!0),M(ir,this),M(Xe,this),M(Me,this);let e=[];C(e,()=>x(this,Pe,this)),C(e,()=>M(this)),C(e,()=>x(Xe,ra,this)),C(e,()=>this.runCleanupCallback());try{this.collectDestroyChildEffects(e)}finally{n(this,De).clear(),n(this,Re).clear(),n(this,Ze).clear(),n(this,ut).clear(),--Pt.count}F(e,"destroying an effect")}};Dt=new WeakMap,De=new WeakMap,Re=new WeakMap,Ze=new WeakMap,gs=new WeakMap,ut=new WeakMap,Rt=new WeakMap,ys=new WeakMap,Lt=new WeakMap,Le=new WeakMap,dt=new WeakMap,ps=new WeakMap,ur=new WeakMap,Tt=new WeakMap,dr=new WeakSet,On=function(e){if(n(this,Le)||!this.shouldRun)return;let t=Il();if(t){if(!e){this.autorun||d(this,ys,!0),t.batch(this.id,this.priority);return}t.unbatch(this.id,this.priority)}if(d(this,ys,!1),n(this,dt)>=Pt.maxDepth)throw new Error(`[signalize] Effect ${this.id.toString()} exceeded maxDepth=${Pt.maxDepth}: an effect callback recursively re-triggered itself (likely by writing a signal it depends on). Break the cycle, or raise the cap with setMaxEffectDepth(n) if the recursion is intentional.`);xe(this,dt)._++;try{this.runCleanupCallback(),this.destroyChildEffects(),this.shouldRun=!1,Gl()&&x(yn,this.id,this.id);let r=++xe(this,ur)._;this.hasStaticDeps()?this.runStaticCallback(r):this.runDynamicCallback(r)}finally{if(xe(this,dt)._--,n(this,dt)===0&&n(this,ps)&&(d(this,ps,!1),!n(this,Le)&&this.hasNoLiveSignals()))try{this.destroy()}catch(r){ar(this,r,"cleanup")}}},p(Mt,"idGen",new qs("ef")),p(Mt,"count",0),p(Mt,"maxDepth",256);Pt=Mt;var gt=(...s)=>Mt.createEffect(...s);na(gt);function va(s,e){var i,o,a;let t=Zr(),r=_();try{let c=(e==null?void 0:e.name)||void 0,h=(e==null?void 0:e.attach)!=null?Je.findOrCreate(e.attach):void 0;h!=null?c!=null?h.attachSignalByName(c,r):h.attachSignal(r):c!=null&&Ee({level:"warn",source:"ignored-option",message:`[signalize] createMemo({name: ${String(c)}}) without {attach} is ignored: a name only exists within a SignalGroup. Pass {attach} as well, or drop the name.`});let f=(i=e==null?void 0:e.batchWrites)!=null?i:!1,y=gt(()=>{f?Bt(()=>{r.set(s())}):r.set(s())},{autorun:!((o=e==null?void 0:e.lazy)!=null&&o),priority:(a=e==null?void 0:e.priority)!=null?a:me.C,attach:h}),g=H(r);g.beforeRead=y.runImmediately;let k=P(Me,g.id,y.destroy);return y.onDestroy(()=>{k(),t!=null&&$(r)}),r.get}catch(c){let h=[c];(e==null?void 0:e.attach)==null&&C(h,()=>$(r)),F(h,"creating a memo")}}var ba="[signalize] SignalLink destroyed before the next value arrived",fr,$t,ms,gr,yr,zn=class{constructor(e,t,r){u(this,fr);u(this,$t);u(this,ms);u(this,gr,[]);u(this,yr,!1);d(this,fr,e),d(this,$t,t),d(this,ms,r)}get hasSettled(){return n(this,yr)}add(e){n(this,gr).push(e)}releaseAll(){n(this,ms)!=null&&(n(this,ms).cancel=void 0),n(this,gr).forEach(e=>{e()})}settleWithValue(e){d(this,yr,!0),this.releaseAll(),n(this,fr).call(this,e)}settleWithDestroy(){this.releaseAll(),n(this,$t).call(this,new Error(ba))}settleWithAbort(e){this.releaseAll(),n(this,$t).call(this,e)}settleWithCancel(){this.releaseAll(),n(this,$t).call(this,new Error("[signalize] SignalLink read cancelled by the iterator"))}};fr=new WeakMap,$t=new WeakMap,ms=new WeakMap,gr=new WeakMap,yr=new WeakMap;var pa,K,vs,pr,bs,et,Pn,wa,Ea;pa=lt;var ti=class{constructor(e){u(this,et);u(this,K,!1);p(this,pa,[]);u(this,vs,0);u(this,pr,0);u(this,bs,0);p(this,"source");p(this,"lastValue");p(this,"isDestroyed",!1);q(this),this.source=H(e);let t=new WeakRef(this);this[lt].push(O(ir,this.source.id,(r,i)=>{let o=t.deref();o!=null&&!n(o,K)&&!o.isDestroyed&&((i==null?void 0:i.touch)===!0?o.touch():o.write())})),this[lt].push(P(Me,this.source.id,()=>{var r;return(r=t.deref())==null?void 0:r.destroy()}))}releaseOnDestroy(e){this[lt].push(e)}attach(e){let t=Je.findOrCreate(e);return t.attachLink(this),t}nextValue(e){return l(this,et,Pn).call(this,null,e)}asyncValues(e,t){let r={},i=l(this,et,Ea).call(this,r,e,t),o=i.return.bind(i);i.return=(c=>{var h;return(h=r.cancel)==null||h.call(r),o(c)});let a=i.throw.bind(i);return i.throw=(c=>{var h;return(h=r.cancel)==null||h.call(r),a(c)}),i}destroy(){if(this.isDestroyed)return;this.isDestroyed=!0;let e=[];for(let t of this[lt])C(e,t);this[lt].length=0,C(e,()=>x(this,Pe,this)),C(e,()=>M(this)),this.lastValue=void 0,Object.freeze(this),F(e,"tearing down a SignalLink")}get isMuted(){return n(this,K)}mute(){return!this.isDestroyed&&!n(this,K)&&(d(this,K,!0),x(this,fn,this)),this}unmute(){return!this.isDestroyed&&n(this,K)&&(d(this,K,!1),x(this,gn,this)),this}toggleMute(){return this.isDestroyed||(d(this,K,!n(this,K)),x(this,n(this,K)?fn:gn,this)),n(this,K)}updateValue(e){if(!n(this,K)&&!this.isDestroyed){let t=++xe(this,pr)._,{value:r}=this.source;if(e(r),this.isDestroyed||n(this,pr)!==t)return;d(this,bs,t),x(this,rr,r),this.lastValue=r}}};K=new WeakMap,vs=new WeakMap,pr=new WeakMap,bs=new WeakMap,et=new WeakSet,Pn=function(e,t,r){let{signal:i}=t!=null?t:{};return new Promise((o,a)=>{if(i!=null&&i.aborted){a(i.reason);return}if(this.isDestroyed){a(new Error(ba));return}let c=new zn(o,a,r);if(r!=null&&(r.cancel=()=>c.settleWithCancel()),c.add(P(this,Pe,()=>c.settleWithDestroy())),i!=null){let f=()=>c.settleWithAbort(i.reason);i.addEventListener("abort",f,{once:!0}),c.add(()=>i.removeEventListener("abort",f))}let h=O(this,rr,f=>{l(this,et,wa).call(this,e)&&c.settleWithValue(f)});c.hasSettled?h():c.add(h)})},wa=function(e){return e==null?!0:e.generation===n(this,bs)?!1:(e.generation=n(this,bs),!0)},Ea=function(e,t,r){return go(this,null,function*(){var o;Xs(this,rr),d(this,vs,n(this,vs)+1);let i={generation:0};try{let a=0;for(;!this.isDestroyed;)try{let c=yield new Mi(l(this,et,Pn).call(this,i,r,e));if(t!=null&&t(c,a++))break;yield c}catch(c){if((o=r==null?void 0:r.signal)!=null&&o.aborted&&c===r.signal.reason)throw c;break}}finally{d(this,vs,n(this,vs)-1),n(this,vs)===0&&Ui(this,rr)}})};var Mn=class extends ti{constructor(t,r){super(t);p(this,"target");this.target=H(r);let i=new WeakRef(this);this.releaseOnDestroy(P(Me,this.target.id,()=>{var o;return(o=i.deref())==null?void 0:o.destroy()})),this.touch()}touch(){return this.updateValue(t=>{this.target.writer(t,{touch:!0})}),this}write(){this.updateValue(t=>{this.target.writer(t)})}},Dn=class extends ti{constructor(t,r){super(t);p(this,"target");this.target=r,this.touch()}touch(){return this.updateValue(t=>{this.target(t)}),this}write(){this.updateValue(t=>{this.target(t)})}},Cn=new WeakMap,cr=0,fa=new FinalizationRegistry(s=>{for(let e of s)try{e()}catch(t){Ee({level:"error",source:"link-finalizer",message:"[signalize] link: releasing the queue subscriptions of a collected link failed",error:t})}s.length=0,cr>0&&(cr-=1)}),Ql=1e3,ga=new WeakSet;function Nt(s,e,t){let r=H(s);if(r==null)throw new TypeError("[signalize] link: source must be a signal");let i=H(e),o=i!=null?i:e,a=Cn.get(r);if(a==null)a=new Map,Cn.set(r,a);else if(a.has(o)){let f=a.get(o),y=t==null?void 0:t.attach;return y&&f.attach(y),f}let c=i!=null?new Mn(s,i):new Dn(s,e),h=t==null?void 0:t.attach;return h&&c.attach(h),a.set(o,c),cr+=1,fa.register(c,c[lt],c),a.size>=Ql&&!ga.has(r)&&(ga.add(r),Ee({level:"warn",source:"link-count",message:`[signalize] link(): ${a.size} links on a single source signal. A link is held until destroy(), unlink(), a cleared {attach} group, or the destruction of source/target \\u2014 garbage collection alone does not reclaim one on a live source. If this is a hot path creating fresh callbacks, tear the old links down; getLinksCount(source) is the number to watch.`})),P(c,Pe,me.Max,()=>{a.delete(o),a.size===0&&Cn.delete(r),fa.unregister(c),cr>0&&(cr-=1)}),c}var Kl=new FinalizationRegistry(s=>{for(let e of s.unsubs)try{e()}catch(t){Ee({level:"error",source:"automap-finalizer",message:"[signalize] releasing the destroy-queue subscriptions of a collected SignalAutoMap failed:",error:t})}s.unsubs.clear()}),ma,Y,ws,ri,qe,Rn,ei;ma=sr;var Ln=class Ln{constructor(){u(this,qe);p(this,ma,{unsubs:new Set});u(this,Y,new Map);u(this,ws,new Map);u(this,ri,new WeakRef(this));Kl.register(this,this[sr],this)}static fromProps(e,t){var o;let r=new Ln,i=t?[...new Set(t)].map(a=>[a,e[a]]):Object.entries(e);for(let[a,c]of i)l(o=r,qe,Rn).call(o,a,c);return r}keys(){return n(this,Y).keys()}signals(){return n(this,Y).values()}entries(){return n(this,Y).entries()}clear(){let e=[...n(this,Y).values()],t=[];for(let r of[...n(this,Y).keys()])C(t,()=>l(this,qe,ei).call(this,r));for(let r of e)C(t,()=>r.destroy());F(t,"clearing a signal auto map")}delete(e){let t=n(this,Y).get(e);return t===void 0?!1:(l(this,qe,ei).call(this,e),t.destroy(),!0)}has(e){return n(this,Y).has(e)}get(e){return n(this,Y).has(e)?n(this,Y).get(e):l(this,qe,Rn).call(this,e)}update(e){e.size&&Bt(()=>{for(let[t,r]of e.entries())this.get(t).set(r)})}updateFromProps(e,t){let r=t?t.map(i=>[i,e[i]]):Object.entries(e);r.length!==0&&Bt(()=>{for(let[i,o]of r)this.get(i).set(o)})}};Y=new WeakMap,ws=new WeakMap,ri=new WeakMap,qe=new WeakSet,Rn=function(e,t){let r=_(t);n(this,Y).set(e,r);let i=n(this,ri),o=O(Me,H(r).id,(a,c)=>{var f;if(c!=null&&c.detach)return;let h=i.deref();h!==void 0&&l(f=h,qe,ei).call(f,e)});return n(this,ws).set(e,o),this[sr].unsubs.add(o),r},ei=function(e){let t=n(this,ws).get(e);try{t()}finally{n(this,ws).delete(e),this[sr].unsubs.delete(t),n(this,Y).delete(e)}};var si=Ln;var ii=class extends Error{constructor(e){super(`the kernel cannot create an entity because the uuid ${e} is already held by another entity`),this.name="EntityUuidInUseError",this.uuid=e}};function D(s,e,t,...r){try{e()}catch(i){s.error(t,...r,i)}}var Es=s=>s.displayName||s.name;var Ft,Ss,mr,ni=class{constructor(e){u(this,Ft,new Map);u(this,Ss,!1);u(this,mr);d(this,mr,e)}add(...[e,t]){n(this,Ft).set(e,t),!n(this,Ss)&&(d(this,Ss,!0),queueMicrotask(()=>this.flush()))}flush(){if(d(this,Ss,!1),n(this,Ft).size===0)return;let e=n(this,Ft);d(this,Ft,new Map),n(this,mr).call(this,e)}};Ft=new WeakMap,Ss=new WeakMap,mr=new WeakMap;var oi=Symbol("onCreate"),ue=Symbol("onDestroy"),Tn=Symbol("onParentChanged"),Cs=Symbol("onViewEvent");function Sa(s){return function(e,t){var o;let r=(s==null?void 0:s.name)||t.name,i=!!((o=s==null?void 0:s.readAsValue)!=null&&o);return{get(){let a=En(this,r);if(a)return i?a.value:a.get()},set(a){var c;(c=En(this,r))==null||c.set(a)},init(a){let c=_(a,s);return ca(this,r,c),Je.findOrCreate(this).attachSignalByName(r,c),c.value}}}}var Yl=Object.create,$n=Object.defineProperty,Jl=Object.getOwnPropertyDescriptor,xa=(s,e)=>(e=Symbol[s])?e:Symbol.for("Symbol."+s),xs=s=>{throw TypeError(s)},Xl=(s,e,t)=>e in s?$n(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,Ca=(s,e)=>$n(s,"name",{value:e,configurable:!0}),Zl=s=>{var e;return[,,,Yl((e=s==null?void 0:s[xa("metadata")])!=null?e:null)]},Aa=["class","method","getter","setter","accessor","field","value","get","set"],vr=s=>s!==void 0&&typeof s!="function"?xs("Function expected"):s,ql=(s,e,t,r,i)=>({kind:Aa[s],name:e,metadata:r,addInitializer:o=>t._?xs("Already initialized"):i.push(vr(o||null))}),Oa=(s,e)=>Xl(e,xa("metadata"),s[3]),ka=(s,e,t,r)=>{for(var i=0,o=s[e>>1],a=o&&o.length;i<a;i++)e&1?o[i].call(t):r=o[i].call(t,r);return r},eh=(s,e,t,r,i,o)=>{var a,c,h,f,y,g=e&7,k=!!(e&8),S=!!(e&16),A=g>3?s.length+1:g?k?1:2:0,js=Aa[g+5],co=g>3&&(s[A-1]=[]),ac=s[A]||(s[A]=[]),ye=g&&(!S&&!k&&(i=i.prototype),g<5&&(g>3||!S)&&Jl(g<4?i:{get[t](){return J(this,o)},set[t](Z){return wr(this,o,Z)}},t));g?S&&g<4&&Ca(o,(g>2?"set ":g>1?"get ":"")+t):Ca(i,t);for(var Ai=r.length-1;Ai>=0;Ai--)f=ql(g,t,h={},s[3],ac),g&&(f.static=k,f.private=S,y=f.access={has:S?Z=>th(i,Z):Z=>t in Z},g^3&&(y.get=S?Z=>(g^1?J:yt)(Z,i,g^4?o:ye.get):Z=>Z[t]),g>2&&(y.set=S?(Z,Oi)=>wr(Z,i,Oi,g^4?o:ye.set):(Z,Oi)=>Z[t]=Oi)),c=(0,r[Ai])(g?g<4?S?o:ye[js]:g>4?void 0:{get:ye.get,set:ye.set}:i,f),h._=1,g^4||c===void 0?vr(c)&&(g>4?co.unshift(c):g?S?o=c:ye[js]=c:i=c):typeof c!="object"||c===null?xs("Object expected"):(vr(a=c.get)&&(ye.get=a),vr(a=c.set)&&(ye.set=a),vr(a=c.init)&&co.unshift(a));return g||Oa(s,i),ye&&$n(i,t,ye),S?g^4?o:ye:i},Bn=(s,e,t)=>e.has(s)||xs("Cannot "+t),th=(s,e)=>Object(e)!==e?xs(\'Cannot use the "in" operator on this value\'):s.has(e),J=(s,e,t)=>(Bn(s,e,"read from private field"),t?t.call(s):e.get(s)),ai=(s,e,t)=>e.has(s)?xs("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,t),wr=(s,e,t,r)=>(Bn(s,e,"write to private field"),r?r.call(s,t):e.set(s,t),t),yt=(s,e,t)=>(Bn(s,e,"access private method"),t),za,Se,pt,Er,Nn,tt,ci,br,ks="value";za=[Sa({name:ks})];var Te=class{constructor(e){ai(this,tt),ai(this,Se,[]),ai(this,pt),ai(this,Nn,ka(Er,8,this)),ka(Er,11,this),this.value$=void 0,Xs(this,ks),this.value$=or(this,ks),this.value$.onChange(t=>Js(this,ks,t)),e&&this.add(...e)}get signals(){return J(this,Se).slice()}add(...e){return J(this,Se).push(...e),yt(this,tt,br).call(this),yt(this,tt,ci).call(this,e)}unshift(...e){return J(this,Se).unshift(...e),yt(this,tt,br).call(this),yt(this,tt,ci).call(this,e)}remove(...e){yt(this,tt,ci).call(this,e)()}clear(){J(this,Se).length=0,yt(this,tt,br).call(this)}dispose(){var e;this.clear(),(e=J(this,pt))==null||e.destroy(),wr(this,pt,void 0),Ii(this,ks),M(this),this.value$.destroy(),Sn(this)}};Er=Zl(null);Se=new WeakMap;pt=new WeakMap;Nn=new WeakMap;tt=new WeakSet;ci=function(s){return()=>{for(let e of s){let t=J(this,Se).indexOf(e);t!==-1&&J(this,Se).splice(t,1)}yt(this,tt,br).call(this)}};br=function(){var s;(s=J(this,pt))==null||s.destroy(),J(this,Se).length===0?(wr(this,pt,void 0),this.value=void 0):(wr(this,pt,gt(()=>{let e;for(let t of J(this,Se)){let r=ht(t);if(r!=null){e=r;break}}this.value=e},J(this,Se))),J(this,pt).run())};eh(Er,4,"value",za,Te,Nn);Oa(Er,Te);Te.Value=ks;var Pa=new WeakMap,sh=s=>{let e=Pa.get(s);return e==null&&(e=new ni(t=>{for(let[r,i]of t)D(s.logger,()=>r.set(i.value),`an effect of a context value failed (${String(i.name)}):`,i.uuid)}),Pa.set(s,e)),e},rh=(s,e,t,r,i)=>{sh(s).add(e,{value:t,name:r,uuid:i})},G,re,mt,X,$e,L,jt,de,zs,Cr,m,Fn,se,Ma,jn,_t,st,_n,Gn,In,vt,Gt,Un,Da,Wn,As,Sr,Os=class Os{constructor(e,t){u(this,m);u(this,G);u(this,re);u(this,mt,new si);u(this,X,new Map);u(this,$e,new Map);u(this,L);u(this,jt,new Set);u(this,de,[]);u(this,zs,0);u(this,Cr,!1);u(this,_t,!1);u(this,st);u(this,vt);d(this,G,e),d(this,re,t)}get kernel(){return n(this,G)}get uuid(){return n(this,re)}get order(){return n(this,zs)}set order(e){n(this,zs)!==e&&(d(this,zs,e),n(this,L)&&n(this,L).resortChildren(),n(this,G).noteEntityTreeChange(n(this,re)))}get parentUuid(){var e;return(e=n(this,L))==null?void 0:e.uuid}set parentUuid(e){var t;if(((t=n(this,L))==null?void 0:t.uuid)!==e){let r=e?n(this,G).getEntity(e):void 0;r!=null&&this.assertAttachableTo(r),l(this,m,jn).call(this,r==null),d(this,L,r),n(this,L)&&n(this,L).addChild(this),l(this,m,Gn).call(this),n(this,G).noteEntityTreeChange(n(this,re))}}get parent(){return n(this,L)}set parent(e){this.parentUuid=e==null?void 0:e.uuid}get hasParent(){return!!n(this,L)}get children(){return n(this,de)}traverse(e){l(this,m,Fn).call(this,e,new Set)}[ue](){if(!n(this,Cr)){d(this,Cr,!0),l(this,m,se).call(this,"properties",()=>n(this,mt).clear()),l(this,m,se).call(this,"listeners",()=>M(this)),l(this,m,se).call(this,"auto-destruction subscription",()=>{var e;return(e=n(this,st))==null?void 0:e.call(this)});for(let e of n(this,$e).values())l(this,m,se).call(this,"global context cleanup",()=>e.cleanup()),l(this,m,se).call(this,"global context signal",()=>e.signal.destroy());for(let e of n(this,X).values())l(this,m,se).call(this,"context value reset",()=>e.context.set(void 0)),l(this,m,se).call(this,"context value subscription",()=>e.unsubscribePathValue()),l(this,m,se).call(this,"context parent subscription",()=>{var t;return(t=e.unsubscribeFromParent)==null?void 0:t.call(e)}),l(this,m,se).call(this,"context value path",()=>e.valuePath.dispose()),l(this,m,se).call(this,"inherited context signal",()=>e.inherited.destroy()),l(this,m,se).call(this,"provided context signal",()=>e.provide.destroy()),l(this,m,se).call(this,"context signal",()=>e.context.destroy());n(this,$e).clear(),n(this,X).clear(),d(this,L,void 0),n(this,jt).clear(),n(this,de).length=0}}assertAttachableTo(e){for(let t=e;t!=null;t=t.parent)if(t===this)throw new Error(`entity "${e.uuid}" cannot become the parent of "${this.uuid}": it is the entity itself or one of its descendants`)}addChild(e){var t;if(n(this,jt).has(e.uuid))throw new Error(`child with uuid: ${e.uuid} already exists! parentUuid: ${this.uuid}`);n(this,jt).add(e.uuid),l(this,m,Ma).call(this,e);for(let[,r]of n(e,X))l(t=e,m,Sr).call(t,r)}resortChildren(){n(this,de).sort((e,t)=>e.order-t.order)}removeChild(e){let t=n(this,de).indexOf(e);t!==-1&&(n(this,jt).delete(e.uuid),n(this,de).splice(t,1))}removeFromParent(e=!0){l(this,m,jn).call(this,e)}get autoDestructionOnParentRemoval(){return n(this,_t)}set autoDestructionOnParentRemoval(e){n(this,_t)!==e&&(d(this,_t,e),l(this,m,Gn).call(this))}reSubscribeToParentContexts(){for(let[,e]of n(this,X))l(this,m,Sr).call(this,e)}dispatchMessageToView(e,t,r,i=!1){n(this,G).dispatchMessageToView({uuid:n(this,re),type:e,data:t,transferables:r,traverseChildren:i})}dispatchViewEvents(e){for(let{type:t,data:r}of e)D(n(this,G).logger,()=>xt(this,Cs,t,r),"entity view event delivery failed:",t,n(this,re))}dispatchViewEvent(e,t){this.dispatchViewEvents([{type:e,data:t}])}getPropertyReader(e){return l(this,m,In).call(this,e).get}getPropertyWriter(e){let t=l(this,m,In).call(this,e);return(r,i)=>{this.clearTruthyPropsCache(),t.set(r,i)}}setProperties(e){Bt(()=>{for(let[t,r]of e)this.setProperty(t,r)})}setProperty(e,t){this.getPropertyWriter(e)(t)}getProperty(e){return ht(this.getPropertyReader(e))}propKeys(){return Array.from(n(this,mt).keys())}propEntries(){return Array.from(n(this,mt).entries()).map(([e,t])=>[e,t.value])}clearTruthyPropsCache(){d(this,vt,void 0)}truthyProps(){if(n(this,vt))return n(this,vt).size?n(this,vt):void 0;let e=new Set;for(let[t,r]of n(this,mt).entries())if(typeof t=="string"){let i=r.value;i!=null&&i!==!1&&i!==""&&e.add(t)}return d(this,vt,e),e.size?e:void 0}hasContext(e){return n(this,X).has(e)}contextNames(){return Array.from(n(this,X).keys())}describeContext(e){let t=n(this,X).get(e);if(t!==void 0)return{provided:t.provide.value,inherited:t.inherited.value,effective:t.context.value,hasProviders:t.providerFeeds.size>0}}globalContextNames(){return Array.from(n(this,$e).keys())}describeGlobalContext(e){let t=n(this,$e).get(e);if(t!==void 0)return{value:t.signal.value,signal:t.signal,hasProviders:t.providerFeeds.size>0}}useContext(e){return l(this,m,As).call(this,e).context.get}useParentContext(e){return l(this,m,As).call(this,e).inherited.get}provideContext(e){return l(this,m,As).call(this,e).provide}provideGlobalContext(e){return l(this,m,Wn).call(this,e).signal}attachContextProvider(e,t){var i;let r=l(this,m,As).call(this,e);return l(i=Os,Gt,Un).call(i,t,r.provide,r.providerFeeds)}attachGlobalContextProvider(e,t){var i;let r=l(this,m,Wn).call(this,e);return l(i=Os,Gt,Un).call(i,t,r.signal,r.providerFeeds)}};G=new WeakMap,re=new WeakMap,mt=new WeakMap,X=new WeakMap,$e=new WeakMap,L=new WeakMap,jt=new WeakMap,de=new WeakMap,zs=new WeakMap,Cr=new WeakMap,m=new WeakSet,Fn=function(e,t){var r;if(!t.has(this)){t.add(this),e(this);for(let i of n(this,de))l(r=i,m,Fn).call(r,e,t)}},se=function(e,t){D(n(this,G).logger,t,`entity teardown step failed (${e}):`,n(this,re))},Ma=function(e){let t=n(this,de).length;for(;t>0&&e.order<n(this,de)[t-1].order;)t--;n(this,de).splice(t,0,e)},jn=function(e){if(n(this,L)){if(n(this,L).removeChild(this),d(this,L,void 0),e)for(let[,t]of n(this,X))l(this,m,Sr).call(this,t);l(this,m,_n).call(this),n(this,G).noteEntityTreeChange(n(this,re))}},_t=new WeakMap,st=new WeakMap,_n=function(){n(this,st)&&(n(this,st).call(this),d(this,st,void 0))},Gn=function(){l(this,m,_n).call(this),n(this,_t)&&n(this,L)&&d(this,st,P(n(this,L),ue,me.Max,()=>{d(this,st,void 0),n(this,G).destroyEntity(n(this,re))}))},In=function(e){return n(this,mt).get(e)},vt=new WeakMap,Gt=new WeakSet,Un=function(e,t,r){let i=Nt(e,t);return r.add(i),()=>{var o;r.delete(i)&&(i.destroy(),l(o=Os,Gt,Da).call(o,r))}},Da=function(e){let t;for(let r of e)!r.isDestroyed&&r.source.value!=null&&(t=r);t==null||t.touch()},Wn=function(e){if(n(this,$e).has(e))return n(this,$e).get(e);let t=n(this,G).findOrCreateRootContext(e),r=_(),o={cleanup:t.add(r),signal:r,providerFeeds:new Set};return n(this,$e).set(e,o),o},As=function(e){if(n(this,X).has(e))return n(this,X).get(e);let t=_(),r=_(),i=_(),o=new Te([r,t]),a=O(o,Te.Value,h=>{rh(n(this,G),i,h,e,n(this,re))}),c={name:e,inherited:t,provide:r,context:i,valuePath:o,providerFeeds:new Set,unsubscribePathValue:a};return n(this,X).set(e,c),l(this,m,Sr).call(this,c),c},Sr=function(e){var t,r;if((t=e.unsubscribeFromParent)==null||t.call(e),e.unsubscribeFromParent=void 0,this.parent){let i=l(r=this.parent,m,As).call(r,e.name),o=Nt(i.context,e.inherited);e.unsubscribeFromParent=o.destroy.bind(o)}else{let i=n(this,G).findOrCreateRootContext(e.name),o=Nt(i.value$,e.inherited);e.unsubscribeFromParent=o.destroy.bind(o)}},u(Os,Gt);var li=Os;function Ra(s,e){s.indexOf(e)===-1&&s.push(e)}var La=s=>{let e=s.split("@").map(t=>t.trim());if(e.length===2&&e[1])return e[0]?{key:`${e[0]}@${e[1]}`,prop:e[1]}:{key:e[1],prop:e[1]}},hi=(s,e)=>{for(let t of e)s.add(t)},ih=(s,e)=>{if(s!=null)for(let t of s)e.add(t)},Be,Ce,Ne,It,Ps,fe,kr,$a,Vn,Ut=class{constructor(){u(this,fe);u(this,Be,new Map);u(this,Ce,new Map);u(this,Ne,new Map);u(this,It,new Set);u(this,Ps,new Map)}static get(e){return e!=null?e:Ta}define(e,t){let r=n(this,Be).get(e);r?Ra(r,t):n(this,Be).set(e,[t]),l(this,fe,kr).call(this)}appendRoute(e,t){let r=La(e);if(r){n(this,It).add(r.prop);let i=n(this,Ne).get(r.key);i?hi(i,t):n(this,Ne).set(r.key,new Set(t))}else{let i=n(this,Ce).get(e);i?hi(i,t):n(this,Ce).set(e,new Set(t))}l(this,fe,kr).call(this)}clearRoute(e){let t=La(e);t?n(this,Ne).delete(t.key):n(this,Ce).delete(e),l(this,fe,kr).call(this)}findTokensByRoute(e,t){return new Set(l(this,fe,Vn).call(this,e,t))}findConstructors(e,t){let r=l(this,fe,Vn).call(this,e,t),i=new Set;for(let o of r)ih(n(this,Be).get(o),i);return i.size>0?Array.from(i):void 0}hasToken(e){return n(this,Be).has(e)}hasRoute(e){return n(this,Ce).has(e)}describe(){let e={};for(let[i,o]of n(this,Be))e[i]=o.map(Es);let t={};for(let[i,o]of n(this,Ce))t[i]=Array.from(o);let r={};for(let[i,o]of n(this,Ne))r[i]=Array.from(o);return{tokens:e,routes:t,propRoutes:r}}tokensOf(e){let t=[];for(let[r,i]of n(this,Be))i.includes(e)&&t.push(r);return t}static isDefault(e){return e===Ta}clear(){n(this,Be).clear(),n(this,Ce).clear(),n(this,Ne).clear(),n(this,It).clear(),l(this,fe,kr).call(this)}};Be=new WeakMap,Ce=new WeakMap,Ne=new WeakMap,It=new WeakMap,Ps=new WeakMap,fe=new WeakSet,kr=function(){n(this,Ps).clear()},$a=function(e){if(e===void 0||n(this,It).size===0)return"";let t="";for(let r of e)n(this,It).has(r)&&(t+=`${r.length}:${r}`);return t},Vn=function(e,t){var h;let r=l(this,fe,$a).call(this,t),i=n(this,Ps).get(e),o=i==null?void 0:i.get(r);if(o!==void 0)return o;let a=new Set([e]),c=Array.from((h=n(this,Ce).get(e))!=null?h:[]);for(let f=c.shift();f!==void 0;f=c.shift()){if(a.has(f))continue;a.add(f);let y=n(this,Ce).get(f);y&&c.push(...Array.from(y).filter(g=>!a.has(g)))}if(t){for(let y of t){let g=n(this,Ne).get(y);g&&hi(a,g)}let f;do{f=a.size;for(let y of new Set(a))for(let g of t){let k=n(this,Ne).get(`${y}@${g}`);k&&hi(a,k)}}while(f!==a.size)}return i===void 0&&(i=new Map,n(this,Ps).set(e,i)),i.set(r,a),a};var Ta=new Ut;var Hn=s=>s!=null?s:void 0;var bt=()=>{let s=_(void 0);return $(s),s},nh=()=>{let s=gt(()=>{},{autorun:!1});return s.destroy(),s},Ba=()=>{};function Na(s,e){let[t]=e;return e.length>1&&typeof t=="object"&&t!==null&&!Array.isArray(t)?e:[s,...e]}var T,Fe,ge,Ds,Wt,U,Vt,Ht,xr,Qt,Ar,Kt,Yt,Rs,Jt,Or,rt,Xt,Zt,qt,Ls,zr,Pr,v,ke,Qn,ui,Ms,I,Kn,di=class{constructor(e,t,r,i){u(this,v);u(this,T);u(this,Fe);u(this,ge);u(this,Ds);u(this,Wt,new Set);u(this,U,new Set);u(this,Vt,new Set);u(this,Ht,new Map);u(this,xr,new Map);u(this,Qt,new Map);u(this,Ar,new Map);u(this,Kt,new Map);u(this,Yt,new Map);u(this,Rs,new Set);u(this,Jt,new Map);u(this,Or,new Map);u(this,rt);u(this,Xt);u(this,Zt);u(this,qt);u(this,Ls,!1);u(this,zr,!1);u(this,Pr);d(this,T,e),d(this,Fe,t),d(this,ge,r),d(this,Ds,i)}get displayName(){return n(this,ge)}get debugHandles(){return{shadowObject:n(this,rt),releaseScope:n(this,Xt),forgetShadowObject:n(this,Zt),unsubscribeFromEntityDestroy:n(this,qt)}}get debugCleanupCounts(){return{primary:n(this,Wt).size,secondary:n(this,U).size,contextFeeds:n(this,Vt).size}}describe(){return{displayName:n(this,ge),usesProperties:Array.from(n(this,Jt).keys()),usesContexts:Array.from(n(this,Ht).keys()),usesParentContexts:Array.from(n(this,Qt).keys()),providesContexts:Array.from(n(this,Kt).keys()),providesGlobalContexts:Array.from(n(this,Yt).keys())}}createAPI(){return{entity:n(this,T),provideContext:this.provideContext.bind(this),provideGlobalContext:this.provideGlobalContext.bind(this),useContext:this.useContext.bind(this),useParentContext:this.useParentContext.bind(this),dispatchMessageToView:this.dispatchMessageToView.bind(this),useProperty:this.useProperty.bind(this),useProperties:this.useProperties.bind(this),createResource:this.createResource.bind(this),createEffect:this.createEffect.bind(this),createSignal:this.createSignal.bind(this),createMemo:this.createMemo.bind(this),on:this.on.bind(this),once:this.once.bind(this),emit:this.emit.bind(this),onViewEvent:this.onViewEvent.bind(this),onDestroy:this.onDestroy.bind(this)}}bindTo(e,t,r){if(n(this,Ls))throw new Error(`the creation scope of "${n(this,ge)}" has torn down and cannot be bound`);if(n(this,rt)!==void 0)throw new Error(`the creation scope of "${n(this,ge)}" is already bound to a shadow-object`);d(this,rt,e),d(this,Xt,t),d(this,Zt,r),n(this,Fe).info("create shadow-object",n(this,ge),{shadowObject:e,entity:n(this,T)}),d(this,qt,P(n(this,T),ue,me.Low,()=>{this.tearDown()}))}tearDown(){if(n(this,Ls))return;d(this,Ls,!0),l(this,v,ke).call(this,"scope release",()=>{var i;return(i=n(this,Xt))==null?void 0:i.call(this)}),l(this,v,ke).call(this,"entity destroy subscription",()=>{var i;return(i=n(this,qt))==null?void 0:i.call(this)}),n(this,rt)!==void 0&&n(this,Fe).info("destroy shadow-object",n(this,ge),{shadowObject:n(this,rt),entity:n(this,T)});let e=new Set,t=(i,o)=>{let a=!1;for(let c of i)e.has(c)||(e.add(c),a=!0,l(this,v,ke).call(this,o,c));return a},r=!0;for(;r;){let i=t(n(this,Wt),"onDestroy callback"),o=t(n(this,U),"creation-api cleanup");r=i||o}for(let i of n(this,Vt))l(this,v,ke).call(this,"context feed release",i);for(let i of n(this,Ht).values())l(this,v,ke).call(this,"context reader",()=>$(i));for(let i of n(this,Qt).values())l(this,v,ke).call(this,"parent context reader",()=>$(i));for(let i of n(this,Jt).values())l(this,v,ke).call(this,"property reader",()=>$(i));for(let i of n(this,Kt).values())l(this,v,ke).call(this,"context provider",()=>$(i));for(let i of n(this,Yt).values())l(this,v,ke).call(this,"global context provider",()=>$(i));n(this,Wt).clear(),n(this,U).clear(),n(this,Vt).clear(),n(this,Ht).clear(),n(this,xr).clear(),n(this,Qt).clear(),n(this,Ar).clear(),n(this,Jt).clear(),n(this,Or).clear(),n(this,Kt).clear(),n(this,Yt).clear(),n(this,Rs).clear(),l(this,v,ke).call(this,"forget shadow-object",()=>{var i;return(i=n(this,Zt))==null?void 0:i.call(this)}),d(this,rt,void 0),d(this,Xt,void 0),d(this,Zt,void 0),d(this,qt,void 0),d(this,zr,!0)}useProperty(e,t){if(l(this,v,I).call(this,"useProperty"))return bt().get;l(this,v,Ms).call(this,t,"useProperty");let r=typeof t=="function"?{compare:t}:t;return l(this,v,ui).call(this,e,n(this,Jt),n(this,Or),()=>n(this,T).getPropertyReader(e),r,"useProperty","property")}useProperties(e){let t={};for(let r in e)Object.hasOwn(e,r)&&(t[r]=this.useProperty(e[r]));return t}provideContext(e,t,r){if(l(this,v,I).call(this,"provideContext"))return bt();l(this,v,Ms).call(this,r,"provideContext");let i=typeof r=="function"?{compare:r}:r;return l(this,v,Kn).call(this,e,n(this,Kt),o=>n(this,T).attachContextProvider(e,o),t,i)}provideGlobalContext(e,t,r){if(l(this,v,I).call(this,"provideGlobalContext"))return bt();l(this,v,Ms).call(this,r,"provideGlobalContext");let i=typeof r=="function"?{compare:r}:r;return l(this,v,Kn).call(this,e,n(this,Yt),o=>n(this,T).attachGlobalContextProvider(e,o),t,i)}useContext(e,t){if(l(this,v,I).call(this,"useContext"))return bt().get;l(this,v,Ms).call(this,t,"useContext");let r=typeof t=="function"?{compare:t}:t;return l(this,v,ui).call(this,e,n(this,Ht),n(this,xr),()=>n(this,T).useContext(e),r,"useContext","context")}useParentContext(e,t){if(l(this,v,I).call(this,"useParentContext"))return bt().get;l(this,v,Ms).call(this,t,"useParentContext");let r=typeof t=="function"?{compare:t}:t;return l(this,v,ui).call(this,e,n(this,Qt),n(this,Ar),()=>n(this,T).useParentContext(e),r,"useParentContext","parent context")}createSignal(...e){if(l(this,v,I).call(this,"createSignal"))return bt();let t=_(...e);return n(this,U).add(()=>{$(t)}),t}createEffect(...e){if(l(this,v,I).call(this,"createEffect"))return nh();let t=gt(...e);return n(this,U).add(t.destroy),t}createMemo(...e){if(l(this,v,I).call(this,"createMemo"))return bt().get;let t=va(...e);return n(this,U).add(()=>{$(t)}),t}createResource(e,t){if(l(this,v,I).call(this,"createResource"))return bt();let r=_(),i=gt(()=>{let o=Hn(e());return r.set(o),o!==void 0&&t?()=>{t(o),r.set(void 0)}:()=>{r.set(void 0)}});return n(this,U).add(()=>{try{i.destroy()}finally{r.set(void 0),$(r)}}),r}on(...e){if(l(this,v,I).call(this,"on"))return Ba;let t=O(...Na(n(this,T),e));return l(this,v,Qn).call(this,t)}once(...e){if(l(this,v,I).call(this,"once"))return Ba;let t=P(...Na(n(this,T),e));return l(this,v,Qn).call(this,t)}emit(...e){if(l(this,v,I).call(this,"emit"))return;let[t]=e;typeof t=="string"||typeof t=="symbol"||Array.isArray(t)?x(n(this,T),...e):x(...e)}onViewEvent(e){if(l(this,v,I).call(this,"onViewEvent"))return;let t=O(n(this,T),Cs,(r,i)=>{e(r,i)});n(this,U).add(t)}onDestroy(e){l(this,v,I).call(this,"onDestroy")||n(this,Wt).add(e)}dispatchMessageToView(e,t,r,i=!1){l(this,v,I).call(this,"dispatchMessageToView")||n(this,T).dispatchMessageToView(e,t,r,i)}};T=new WeakMap,Fe=new WeakMap,ge=new WeakMap,Ds=new WeakMap,Wt=new WeakMap,U=new WeakMap,Vt=new WeakMap,Ht=new WeakMap,xr=new WeakMap,Qt=new WeakMap,Ar=new WeakMap,Kt=new WeakMap,Yt=new WeakMap,Rs=new WeakMap,Jt=new WeakMap,Or=new WeakMap,rt=new WeakMap,Xt=new WeakMap,Zt=new WeakMap,qt=new WeakMap,Ls=new WeakMap,zr=new WeakMap,Pr=new WeakMap,v=new WeakSet,ke=function(e,t){D(n(this,Fe),t,`shadow-object teardown failed (${e}):`,n(this,ge))},Qn=function(e){return n(this,U).add(e),Object.assign(()=>{n(this,U).delete(e),e()},e)},ui=function(e,t,r,i,o,a,c){let h=t.get(e);if(h===void 0){h=_(void 0,o).get,t.set(e,h),r.set(e,o==null?void 0:o.compare);let f=Nt(i(),h);n(this,U).add(f.destroy.bind(f))}else(o==null?void 0:o.compare)!=null&&r.get(e)!==o.compare&&n(this,Fe).error(`[shadow-objects] ${a}("${String(e)}"): the cached signal already exists with a different (or no) {compare} function \\u2014 the new options are ignored. Pass options only on the first call per ${c}.`);return h},Ms=function(e,t){typeof e!="function"||n(this,Ds).has(t)||(n(this,Fe).error(`[shadow-objects] Deprecation Warning: The "isEqual" option of "${t}()" is now passed as {compare} argument. Please update your code accordingly.`),n(this,Ds).add(t))},I=function(e){var t,r;return n(this,zr)?((t=n(this,Pr))!=null&&t.has(e)||(((r=n(this,Pr))!=null?r:d(this,Pr,new Set)).add(e),n(this,Fe).error(`[shadow-objects] ${e}(): the creation scope of "${n(this,ge)}" has torn down \\u2014 the call does nothing. Something is still holding the creation API past the end of its shadow-object.`)),!0):!1},Kn=function(e,t,r,i,o){var c;let a=t.get(e);if(a==null){let h=we(i),f=h?void 0:Hn(i);if(a=_(f,o!=null&&o.compare?{compare:o.compare}:void 0),h){let y=Nt(i,a);n(this,U).add(y.destroy.bind(y))}n(this,Vt).add(r(a)),t.set(e,a)}return((c=o==null?void 0:o.clearOnDestroy)==null||c)&&!n(this,Rs).has(a)&&(n(this,Rs).add(a),n(this,U).add(()=>{a.set(void 0)})),a};var Fa=[["onCreate",oi],["onDestroy",ue],["onParentChanged",Tn],["onViewEvent",Cs]],pi,z,je,wt,es,Et,it,_e,mi,E,Yn,Jn,ja,_a,Mr,Ga,fi,Ia,Ua,Xn,gi,yi=class{constructor(e){u(this,E);u(this,pi,new We("Kernel"));u(this,z,new Map);u(this,je,new Set);u(this,wt,[]);u(this,es,[]);u(this,Et,!0);u(this,it,new Map);u(this,_e,new WeakMap);u(this,mi,new Set);q(this),this.registry=Ut.get(e)}get logger(){return n(this,pi)}getEntity(e){return l(this,E,Yn).call(this,e).entity}findEntity(e){var t;return(t=n(this,z).get(e))==null?void 0:t.entity}hasEntity(e){return n(this,z).has(e)}tokenOf(e){var t;return(t=n(this,z).get(e))==null?void 0:t.token}get debugEntityCounts(){return{entities:n(this,z).size,rootEntities:n(this,je).size,traversal:n(this,wt).length,traversalReversed:n(this,es).length}}traverseLevelOrderBFS(e=!1){if(n(this,Et)){let t=new Map,r=new Set,i=(o,a)=>{if(r.has(o))return;r.add(o);let c=this.findEntity(o);if(c===void 0)return;let h=t.get(a);h?h.push(c):t.set(a,[c]);for(let f of c.children)i(f.uuid,a+1)};n(this,je).forEach(o=>{i(o,0)}),d(this,wt,Array.from(t.entries()).sort((o,a)=>o[0]-a[0]).flatMap(([,o])=>o)),d(this,es,n(this,wt).slice().reverse()),d(this,Et,!1)}return e?n(this,es).slice():n(this,wt).slice()}getEntityGraph(){let e=new Set;return Array.from(n(this,je)).map(t=>l(this,E,Jn).call(this,t,e)).filter(t=>t!==void 0)}upgradeEntities(){let e=new Map;for(let t of this.traverseLevelOrderBFS(!0))this.hasEntity(t.uuid)&&e.set(t.uuid,l(this,E,Mr).call(this,t.uuid,2));for(let t of this.traverseLevelOrderBFS(!1))this.hasEntity(t.uuid)&&l(this,E,Mr).call(this,t.uuid,1,e.get(t.uuid));e.clear()}run(e){this.logger.debug("sync",e);let t=0;try{Bt(()=>{for(let r of e.changeTrail)l(this,E,ja).call(this,r),t++})}catch(r){throw new cs(t,e.changeTrail.length,{cause:r})}}createEntity(e,t,r,i=0,o,a=!1){if(n(this,z).has(e))throw new ii(e);let c=new li(this,e);c.order=i;let h={token:t,entity:c,usedConstructors:new Map};n(this,z).set(e,h),this.noteEntityTreeChange(e);try{r&&(c.parentUuid=r),c.autoDestructionOnParentRemoval=a,o&&c.setProperties(o),l(this,E,Ia).call(this,h)}catch(f){throw l(this,E,_a).call(this,e),f}}destroyEntity(e){let t=n(this,z).get(e);if(t===void 0)return;let{entity:r,usedConstructors:i}=t;try{let o=[...r.children];for(let c of o)D(this.logger,()=>{c.autoDestructionOnParentRemoval?this.destroyEntity(c.uuid):c.removeFromParent()},"child of a destroyed entity could not be handed on:",c.uuid);D(this.logger,()=>r.removeFromParent(),"entity could not be detached from its parent:",r.uuid);let a=this.findShadowObjects(r.uuid);for(let c of a)M(r,c),l(this,E,Xn).call(this,c,r);D(this.logger,()=>xt(r,ue,r),"entity onDestroy notification failed:",r.uuid);for(let c of a)D(this.logger,()=>{var h;return(h=n(this,_e).get(c))==null?void 0:h.tearDown()},"creation scope teardown of a destroyed entity failed:",r.uuid);D(this.logger,()=>r[ue](),"entity release failed:",r.uuid)}finally{i.clear(),n(this,z).delete(r.uuid),n(this,je).delete(r.uuid),d(this,Et,!0)}}setParent(e,t,r){let i=this.getEntity(e),o=r!=null?r:i.order;if(!(i.parentUuid===t&&i.order===o)){if(t&&!n(this,z).has(t))throw new Error(`entity with uuid "${t}" not found!`);t&&i.assertAttachableTo(this.getEntity(t)),i.removeFromParent(t==null),i.order=o,i.parentUuid=t,this.logger.debug("entity.onParentChanged",{uuid:e,parentUuid:t,order:o,entity:i}),D(this.logger,()=>xt(i,Tn,i),"entity onParentChanged notification failed:",e)}}updateOrder(e,t){this.getEntity(e).order=t}noteEntityTreeChange(e){d(this,Et,!0);let t=n(this,z).get(e);t!==void 0&&(t.entity.hasParent?n(this,je).delete(e):n(this,je).add(e))}dispatchEventsToEntity(e,t){var r;(r=this.findEntity(e))==null||r.dispatchViewEvents(t)}changeProperties(e,t){this.getEntity(e).setProperties(t),l(this,E,Mr).call(this,e)}changeToken(e,t){let r=n(this,z).get(e);if(r===void 0||r.token===t)return;let i=r.token;r.token=t,l(this,E,Mr).call(this,e,0,void 0,i)}dispatchMessageToView(e){queueMicrotask(()=>{Js(this,_s,e)})}findShadowObjects(e){let t=n(this,z).get(e);if(t===void 0)return[];let{usedConstructors:r}=t;return Array.from(new Set(Array.from(r.values()).flatMap(i=>Array.from(i))))}describeShadowObjects(e){var o;let t=n(this,z).get(e);if(t===void 0)return[];let r=new Set,i=[];for(let[a,c]of t.usedConstructors)for(let h of c){if(r.has(h))continue;r.add(h);let f=n(this,_e).get(h),y=Fa.filter(([,g])=>typeof h[g]=="function").map(([g])=>g);i.push(rs(W({},(o=f==null?void 0:f.describe())!=null?o:{displayName:Es(a),usesProperties:[],usesContexts:[],usesParentContexts:[],providesContexts:[],providesGlobalContexts:[]}),{definedUnder:this.registry.tokensOf(a),hooks:y}))}return i}findOrCreateRootContext(e){let t=n(this,it).get(e);return t||(t=new Te,n(this,it).set(e,t)),t}rootContextNames(){return Array.from(n(this,it).keys())}describeRootContext(e){let t=n(this,it).get(e);if(t!==void 0)return{value:t.value,signals:t.signals}}destroy(){for(let e of this.traverseLevelOrderBFS(!0))D(this.logger,()=>this.destroyEntity(e.uuid),"entity teardown during kernel destroy failed:",e.uuid);n(this,z).clear(),n(this,je).clear(),n(this,wt).length=0,n(this,es).length=0,d(this,Et,!0);for(let e of n(this,it).values())e.dispose();n(this,it).clear(),queueMicrotask(()=>{M(this)})}};pi=new WeakMap,z=new WeakMap,je=new WeakMap,wt=new WeakMap,es=new WeakMap,Et=new WeakMap,it=new WeakMap,_e=new WeakMap,mi=new WeakMap,E=new WeakSet,Yn=function(e){let t=n(this,z).get(e);if(t===void 0)throw new Error(`entity with uuid "${e}" not found!`);return t},Jn=function(e,t,r){let i=n(this,z).get(e);if(i===void 0){r==null||r.push({uuid:e,reason:"not-in-kernel"});return}if(t.has(e)){r==null||r.push({uuid:e,reason:"already-in-graph"});return}t.add(e);let{token:o,entity:a}=i,c=[],h=a.children.map(f=>l(this,E,Jn).call(this,f.uuid,t,c)).filter(f=>f!==void 0);return W({token:o,entity:a,props:Object.fromEntries(a.propEntries()),children:h},c.length>0?{omittedChildren:c}:{})},ja=function(e){switch(e.type){case Ie.CreateEntities:this.createEntity(e.uuid,e.token,e.parentUuid,e.order,e.properties,e.autoDestructionOnParentRemoval);break;case Ie.DestroyEntities:this.destroyEntity(e.uuid);break;case Ie.SetParent:this.setParent(e.uuid,e.parentUuid,e.order);break;case Ie.UpdateOrder:this.updateOrder(e.uuid,e.order);break;case Ie.ChangeProperties:this.changeProperties(e.uuid,e.properties);break;case Ie.ChangeToken:this.changeToken(e.uuid,e.token);break;case Ie.SendEvents:this.dispatchEventsToEntity(e.uuid,e.events);break}},_a=function(e){D(this.logger,()=>this.destroyEntity(e),"rollback of a failed entity creation could not destroy the entity:",e)},Mr=function(e,t=0,r,i){let o=l(this,E,Yn).call(this,e);r!=null||(r=new Set(this.registry.findConstructors(o.token,o.entity.truthyProps())));let a=t===0||t===2,c=t===0||t===1,h=[],f=[];if(a){for(let[y,g]of o.usedConstructors)if(!r.has(y)){o.usedConstructors.delete(y),h.push({construct:y,count:g.size});for(let k of g)l(this,E,gi).call(this,k,o.entity)}}if(c){for(let y of r)if(!o.usedConstructors.has(y))try{f.push(l(this,E,fi).call(this,y,o))}catch(g){throw l(this,E,Ga).call(this,o,f,h,i),g}}return r},Ga=function(e,t,r,i){if(n(this,z).get(e.entity.uuid)===e){i!==void 0&&(e.token=i);for(let o=t.length-1;o>=0;o--)D(this.logger,()=>l(this,E,gi).call(this,t[o],e.entity),"rollback of a failed shadow-object update could not remove a new shadow-object:",e.entity.uuid);for(let{construct:o,count:a}of r)for(let c=0;c<a;c++)D(this.logger,()=>l(this,E,fi).call(this,o,e),"rollback of a failed shadow-object update could not restore a shadow-object:",Es(o),e.entity.uuid)}},fi=function(e,t){let r=new di(t.entity,this.logger,Es(e),n(this,mi)),i;try{i=q(new e(r.createAPI()))}catch(a){throw r.tearDown(),a}n(this,_e).set(i,r),r.bindTo(i,()=>{n(this,_e).delete(i)},()=>{let a=t.usedConstructors.get(e);a&&(a.delete(i),a.size===0&&t.usedConstructors.delete(e))});let o=t.usedConstructors.get(e);o?o.add(i):t.usedConstructors.set(e,new Set([i]));try{l(this,E,Ua).call(this,i,t.entity)}catch(a){throw l(this,E,gi).call(this,i,t.entity),a}return i},Ia=function(e){var t;(t=this.registry.findConstructors(e.token,e.entity.truthyProps()))==null||t.forEach(r=>{l(this,E,fi).call(this,r,e)})},Ua=function(e,t){var r;for(let[i,o]of Fa)if(typeof e[i]=="function"&&typeof e[o]!="function"){let a=(r=n(this,_e).get(e))==null?void 0:r.displayName;this.logger.error(`the "${i}" lifecycle hook is a plain method and is never called; use the [${i}] symbol from "@spearwolf/shadow-objects/shadow-objects.js":`,a)}O(t,e),typeof e[oi]=="function"&&e[oi](t)},Xn=function(e,t){var i;let r=(i=n(this,_e).get(e))==null?void 0:i.displayName;typeof e[ue]=="function"&&D(this.logger,()=>e[ue](t),"shadow-object onDestroy hook failed:",r),D(this.logger,()=>xt(e,ue,t),"shadow-object onDestroy notification failed:",r)},gi=function(e,t){var r;l(this,E,Xn).call(this,e,t),(r=n(this,_e).get(e))==null||r.tearDown(),M(t,e)};var vi=Object.freeze({maxDepth:3,maxArrayLength:20,maxObjectEntries:30,maxStringLength:200}),bi=(s,e)=>s!==void 0&&Number.isFinite(s)?s:e,eo=s=>({maxDepth:bi(s==null?void 0:s.maxDepth,vi.maxDepth),maxArrayLength:bi(s==null?void 0:s.maxArrayLength,vi.maxArrayLength),maxObjectEntries:bi(s==null?void 0:s.maxObjectEntries,vi.maxObjectEntries),maxStringLength:bi(s==null?void 0:s.maxStringLength,vi.maxStringLength)}),oh=s=>typeof s.nodeType=="number"&&typeof s.nodeName=="string",ah=s=>{let e=Object.getPrototypeOf(s);return e===Object.prototype||e===null},Zn=s=>{let e=s.constructor;return typeof e=="function"&&e.name?e.name:"Object"},wi=s=>({$type:"object",class:"Error",preview:{message:s instanceof Error?s.message:String(s)}}),ch="$truncated";function Wa(s,e){return new qn(eo(e)).serialize(s,0,new Set)}var qn=class{constructor(e){this.limits=e}serialize(e,t,r){switch(typeof e){case"undefined":return{$type:"undefined"};case"boolean":return e;case"number":return Number.isFinite(e)?e:String(e);case"string":return this.string(e);case"bigint":return{$type:"bigint",value:e.toString()};case"symbol":return e.description===void 0?{$type:"symbol"}:{$type:"symbol",description:e.description};case"function":try{return we(e)?this.signal(e,t,r):{$type:"function",name:e.name}}catch(i){return wi(i)}case"object":if(e===null)return null;try{return we(e)?this.signal(e,t,r):this.object(e,t,r)}catch(i){return wi(i)}}}string(e){return e.length<=this.limits.maxStringLength?e:{$type:"truncated",reason:"string",original:e.length,preview:e.slice(0,this.limits.maxStringLength)}}signal(e,t,r){if(r.has(e))return{$type:"circular"};r.add(e);try{let i;try{i=ht(e)}catch(o){return wi(o)}return{$type:"signal",value:this.serialize(i,t,r)}}finally{r.delete(e)}}object(e,t,r){if(e instanceof Date)return{$type:"date",iso:Number.isNaN(e.getTime())?"Invalid Date":e.toISOString()};if(e instanceof ArrayBuffer)return{$type:"array-buffer",byteLength:e.byteLength,class:"ArrayBuffer"};if(ArrayBuffer.isView(e))return{$type:"typed-array",byteLength:e.byteLength,class:Zn(e)};if(oh(e))return typeof e.id=="string"&&e.id?{$type:"dom",nodeName:e.nodeName,id:e.id}:{$type:"dom",nodeName:e.nodeName};if(e instanceof Error)return{$type:"object",class:Zn(e),preview:{name:e.name,message:e.message}};if(t>this.limits.maxDepth)return{$type:"truncated",reason:"depth"};if(r.has(e))return{$type:"circular"};r.add(e);try{return Array.isArray(e)?this.array(e,t,r):e instanceof Map?{$type:"object",class:"Map",preview:{size:e.size,entries:this.array(Array.from(e.entries()),t,r)}}:e instanceof Set?{$type:"object",class:"Set",preview:{size:e.size,entries:this.array(Array.from(e),t,r)}}:ah(e)?this.entries(e,t,r):{$type:"object",class:Zn(e),preview:this.entries(e,t,r)}}finally{r.delete(e)}}array(e,t,r){let i=[],o=this.limits.maxArrayLength;for(let a=0;a<e.length&&a<o;a++)i.push(this.serialize(e[a],t+1,r));return e.length>o&&i.push({$type:"truncated",reason:"length",original:e.length}),i}entries(e,t,r){let i={},o=Object.keys(e),a=this.limits.maxObjectEntries;for(let c=0;c<o.length&&c<a;c++){let h=o[c],f;try{f=e[h]}catch(y){i[h]=wi(y);continue}i[h]=this.serialize(f,t+1,r)}return o.length>a&&(i[ch]={$type:"truncated",reason:"entries",original:o.length}),i}};var Dr=Object.freeze({maxDepth:4,maxDepthCap:64,maxNodes:250,maxMatches:50}),lh=["props","shadowObjects","contexts","registry"],hh=s=>s===void 0?Dr.maxDepth:Number.isFinite(s)?Math.min(Dr.maxDepthCap,Math.max(0,Math.floor(s))):Dr.maxDepthCap,uh=s=>s===void 0?Dr.maxNodes:Number.isFinite(s)?Math.max(1,Math.floor(s)):Number.MAX_SAFE_INTEGER,dh=s=>s===void 0?Dr.maxMatches:Number.isFinite(s)?Math.max(1,Math.floor(s)):Number.MAX_SAFE_INTEGER,fh=s=>s===void 0?void 0:{token:s.token,propName:s.propName,shadowObject:s.shadowObject,contextName:s.contextName,limit:dh(s.limit)},Va=s=>{var e;return{include:new Set((e=s==null?void 0:s.include)!=null?e:lh),rootUuids:s==null?void 0:s.rootUuids,maxDepth:hh(s==null?void 0:s.maxDepth),maxNodes:uh(s==null?void 0:s.maxNodes),limits:eo(s==null?void 0:s.values),filter:fh(s==null?void 0:s.filter)}},Ts,Ei=class{constructor(e){u(this,Ts);d(this,Ts,e)}take(){return n(this,Ts)<=0?!1:(xe(this,Ts)._--,!0)}};Ts=new WeakMap;var Bs=s=>{var e;return typeof s=="symbol"?{symbol:(e=s.description)!=null?e:""}:s},gh=s=>s!=null&&s!==!1&&s!=="",to=s=>s!=null,yh=()=>typeof globalThis.WorkerGlobalScope!="undefined";function Ha(s,e){return mn(()=>new so(s,Va(e)).build())}var B,ie,Ns,Fs,St,Rr,Lr,b,Qa,ro,Ka,Ya,Ja,io,$s,ts,no,Xa,Za,qa,ec,tc,so=class{constructor(e,t){u(this,b);u(this,B);u(this,ie);u(this,Ns);u(this,Fs,new Set);u(this,St,[]);u(this,Rr,new Map);u(this,Lr,!1);d(this,B,e),d(this,ie,t),d(this,Ns,new Ei(t.maxNodes))}build(){let e=n(this,B).traverseLevelOrderBFS(),{filter:t}=n(this,ie),r=t===void 0?l(this,b,Qa).call(this,e):[],i={takenAt:Date.now(),thread:yh()?"worker":"main",counts:{entities:e.length,roots:e.filter(o=>!o.hasParent).length,shadowObjects:e.reduce((o,a)=>o+l(this,b,$s).call(this,a.uuid).length,0)},roots:r,globalContexts:l(this,b,tc).call(this,e)};return n(this,ie).include.has("registry")&&(i.registry=rs(W({},n(this,B).registry.describe()),{isDefault:Ut.isDefault(n(this,B).registry)})),n(this,St).length>0&&(i.truncation=n(this,St)),t!==void 0&&(i.search=l(this,b,Ka).call(this,e,t)),i}};B=new WeakMap,ie=new WeakMap,Ns=new WeakMap,Fs=new WeakMap,St=new WeakMap,Rr=new WeakMap,Lr=new WeakMap,b=new WeakSet,Qa=function(e){let t=l(this,b,Ja).call(this,e),r=n(this,ie).rootUuids!==void 0,i=[];for(let o of t){if(n(this,Fs).has(o.uuid))continue;if(!n(this,Ns).take()){l(this,b,io).call(this,void 0);break}let a=l(this,b,no).call(this,o,0);r&&(a.ancestors=l(this,b,ro).call(this,o)),i.push(a)}return i},ro=function(e){var r;let t=[];for(let i=e.parent;i!==void 0;i=i.parent)t.unshift({uuid:i.uuid,token:(r=n(this,B).tokenOf(i.uuid))!=null?r:""});return t},Ka=function(e,t){var o;let r=[],i=0;for(let a of e)if(l(this,b,Ya).call(this,a,t)&&(i++,r.length<t.limit)){let c=(o=n(this,B).tokenOf(a.uuid))!=null?o:"";r.push({uuid:a.uuid,token:c,path:[...l(this,b,ro).call(this,a).map(h=>h.token),c]})}return{matches:r,total:i}},Ya=function(e,t){let{token:r,propName:i,shadowObject:o,contextName:a}=t;return!(r!==void 0&&n(this,B).tokenOf(e.uuid)!==r||i!==void 0&&!e.propKeys().includes(i)||o!==void 0&&!l(this,b,$s).call(this,e.uuid).some(c=>c.displayName===o)||a!==void 0&&!e.contextNames().includes(a))},Ja=function(e){let{rootUuids:t}=n(this,ie);if(t===void 0)return e.filter(i=>!i.hasParent);let r=[];for(let i of t){let o=n(this,B).findEntity(i);o===void 0?n(this,St).push({reason:"unknown-root",uuid:i,message:`the kernel holds no entity "${i}"`}):r.push(o)}return r},io=function(e){if(n(this,Lr))return;d(this,Lr,!0);let t={reason:"max-nodes",message:`maxNodes ${n(this,ie).maxNodes} reached; ask again with rootUuids below the last node written`};e!==void 0&&(t.uuid=e),n(this,St).push(t)},$s=function(e){let t=n(this,Rr).get(e);return t===void 0&&(t=n(this,B).describeShadowObjects(e),n(this,Rr).set(e,t)),t},ts=function(e){return Wa(e,n(this,ie).limits)},no=function(e,t){var a;let{uuid:r}=e;n(this,Fs).add(r);let i={uuid:r,token:(a=n(this,B).tokenOf(r))!=null?a:"",order:e.order,autoDestructionOnParentRemoval:e.autoDestructionOnParentRemoval,childCount:e.children.length};e.parentUuid!==void 0&&(i.parentUuid=e.parentUuid);let{include:o}=n(this,ie);return o.has("props")&&(i.props=l(this,b,Za).call(this,e)),o.has("shadowObjects")&&(i.shadowObjects=l(this,b,$s).call(this,r).map(ph)),o.has("contexts")&&(i.contexts=l(this,b,qa).call(this,e)),t<n(this,ie).maxDepth?l(this,b,Xa).call(this,e,i,t):e.children.length>0&&n(this,St).push({reason:"max-depth",uuid:r,message:`the children of "${r}" were not walked: maxDepth ${n(this,ie).maxDepth} reached; ask again with rootUuids: ["${r}"]`}),i},Xa=function(e,t,r){let i=[],o=[];for(let a of e.children){if(n(this,B).findEntity(a.uuid)===void 0){o.push({uuid:a.uuid,reason:"not-in-kernel"});continue}if(n(this,Fs).has(a.uuid)){o.push({uuid:a.uuid,reason:"already-in-graph"});continue}if(!n(this,Ns).take()){l(this,b,io).call(this,e.uuid);break}i.push(l(this,b,no).call(this,a,r+1))}t.children=i,o.length>0&&(t.omittedChildren=o)},Za=function(e){return e.propEntries().map(([t,r])=>({name:t,value:l(this,b,ts).call(this,r),routes:gh(r)}))},qa=function(e){let t=l(this,b,$s).call(this,e.uuid);return e.contextNames().map(r=>{let i=e.describeContext(r),o={name:Bs(r),effective:l(this,b,ts).call(this,i.effective),providedBy:t.filter(a=>a.providesContexts.includes(r)).map(a=>a.displayName),source:l(this,b,ec).call(this,e,r,i.provided)};return i.provided!==void 0&&(o.provided=l(this,b,ts).call(this,i.provided)),i.inherited!==void 0&&(o.inherited=l(this,b,ts).call(this,i.inherited)),o})},ec=function(e,t,r){var i,o;if(to(r))return{kind:"self"};for(let a=e.parent;a!==void 0;a=a.parent)if(to((i=a.describeContext(t))==null?void 0:i.provided))return{kind:"ancestor",uuid:a.uuid};return to((o=n(this,B).describeRootContext(t))==null?void 0:o.value)?{kind:"global"}:{kind:"none"}},tc=function(e){let t=new Map;for(let i of e)for(let o of i.globalContextNames()){let a=t.get(o);a===void 0&&t.set(o,a=new Map),a.set(i.describeGlobalContext(o).signal,i)}let r=[];for(let i of n(this,B).rootContextNames()){let o=n(this,B).describeRootContext(i);if(o.signals.length===0)continue;let a=t.get(i),c=[];for(let h of o.signals){let f=a==null?void 0:a.get(h);f!==void 0&&c.push({uuid:f.uuid,providedBy:l(this,b,$s).call(this,f.uuid).filter(y=>y.providesGlobalContexts.includes(i)).map(y=>y.displayName),value:l(this,b,ts).call(this,f.describeGlobalContext(i).value)})}r.push({name:Bs(i),value:l(this,b,ts).call(this,o.value),providers:c})}return r};var ph=s=>({displayName:s.displayName,definedUnder:s.definedUnder,usesProperties:s.usesProperties,usesContexts:s.usesContexts.map(Bs),usesParentContexts:s.usesParentContexts.map(Bs),providesContexts:s.providesContexts.map(Bs),providesGlobalContexts:s.providesGlobalContexts.map(Bs),hooks:s.hooks});var sc=s=>(typeof s=="string"&&(s=new URL(s,globalThis.location.href)),s.toString());var ao=s=>typeof s=="object"&&s!==null,oo=s=>{try{return s instanceof Error?{error:s.message||String(s),errorName:s.name}:{error:String(s)||"unknown error"}}catch(e){return{error:"an error that cannot be described"}}},Tr,Ci,ss,Ge,rc,ic,nc,oc,Si=class{constructor(e){u(this,Ge);u(this,Tr,new Set);u(this,Ci,new We("MessageRouter"));u(this,ss,!1);var t,r;this.kernel=(t=e==null?void 0:e.kernel)!=null?t:new yi,this.postMessage=(r=e==null?void 0:e.postMessage)!=null?r:self.postMessage.bind(self),O(this.kernel,_s,"onMessageToView",this)}get logger(){return n(this,Ci)}get isDestroyed(){return n(this,ss)}route(e){var r;let t=e.data;if(!ao(t)){this.logger.debug("discarding a message it cannot read",t);return}if(n(this,ss)){this.logger.debug("discarding a message that arrived after the teardown",t.type);return}switch(t.type){case yo:l(this,Ge,rc).call(this,t);break;case po:l(this,Ge,ic).call(this,t);break;case mo:l(this,Ge,nc).call(this,t);break;case Br:l(this,Ge,oc).call(this,t);break;default:this.logger.warn("unknown message",(r=t.type)!=null?r:t)}}onMessageToView(e){let i=e,{transferables:t}=i,r=fo(i,["transferables"]);this.postMessage({type:_s,data:r},{transfer:t!=null?t:[]})}};Tr=new WeakMap,Ci=new WeakMap,ss=new WeakMap,Ge=new WeakSet,rc=async function(e){let t=e.importModule;try{if(!t)throw new Error(\'missing "importModule" url\');let r=await import(sc(t));if(n(this,ss)){this.logger.debug("discarding a module that arrived after the teardown",t);return}r[Gs]?(await Wi(this.kernel,r[Gs],n(this,Tr)),this.postMessage({type:Nr,url:t})):this.postMessage({type:Nr,url:t,error:Ko})}catch(r){this.logger.error("failed to import module",r),this.postMessage(W({type:Nr,url:t},oo(r)))}},ic=function(e){var t;try{this.kernel.run(e)}catch(r){if(this.logger.error("failed to apply change trail",r),e.serial!=null){let i=r instanceof cs?r:void 0;this.postMessage(W(W({type:Di,serial:e.serial},oo((t=i==null?void 0:i.cause)!=null?t:r)),i?{appliedCount:i.appliedCount}:{}))}return}e.serial!=null&&this.postMessage({type:Di,serial:e.serial})},nc=function(e){try{let t=Ha(this.kernel,e.request);this.postMessage({type:Ri,serial:e.serial,snapshot:t})}catch(t){this.logger.error("failed to inspect the kernel",t),this.postMessage(W({type:Ri,serial:e.serial},oo(t)))}},oc=function(e){this.logger.debug("on destroy",e),d(this,ss,!0),M(this.kernel,this);try{this.kernel.destroy()}catch(t){this.logger.error("failed to tear the kernel down",t)}n(this,Tr).clear(),this.postMessage({type:bo})};var xi,nt,Ct,ki=class{constructor(){u(this,xi);u(this,nt);u(this,Ct);d(this,nt,!1),d(this,Ct,!1),this.onmessage=e=>{var r;let t=e.data;if(!ao(t)){this.logger.debug("discarding a message it cannot read",t);return}if(n(this,Ct)){this.logger.debug("discarding a message that arrived after the teardown",t.type);return}if(t.type===Ue){Ao(t.config),this.logger.debug("console-logger config installed",t.config);return}(r=this.router)!=null||(this.router=new Si),this.router.route(e),t.type===Br&&(d(this,Ct,!0),this.stop(),this.router=void 0)}}get logger(){var e;return(e=n(this,xi))!=null?e:d(this,xi,new We("WorkerRuntime"))}get isStarted(){return n(this,nt)}get isDestroyed(){return n(this,Ct)}start(){n(this,Ct)||n(this,nt)||(d(this,nt,!0),self.addEventListener("message",this.onmessage),self.postMessage({type:vo}))}stop(){n(this,nt)&&(d(this,nt,!1),self.removeEventListener("message",this.onmessage))}};xi=new WeakMap,nt=new WeakMap,Ct=new WeakMap;var mh=new ki;mh.start();\n/*! Bundled license information:\n\n@spearwolf/eventize/lib/index.mjs:\n (*!\n =============================================================================\n @spearwolf/eventize 6.2.0+build.20260830\n \u2014 git+https://github.com/spearwolf/eventize.git\n =============================================================================\n \n Copyright 2015-2026 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@spearwolf/signalize/dist/signalize.gcXQq0d2.js:\n@spearwolf/signalize/dist/index.js:\n@spearwolf/signalize/dist/decorators.js:\n (*!\n @file @spearwolf/signalize - signals and effects for all\n @author Wolfger Schramm <wolfger@spearwolf.de>\n @version 1.0.0+esm\n \n Copyright 2022-2026 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*/\n')}var Pa=f(()=>{Oa()});var Ra,Ma=f(()=>{Pa();Ra=()=>new Zi});var Ar,en=f(()=>{"use strict";Ar=s=>(typeof s=="string"&&(s=new URL(s,globalThis.location.href)),s.toString())});var Tr,Na=f(()=>{"use strict";Tr=class extends Error{constructor(e,t){super(`no ${e} message arrived from the worker within ${t}ms`),this.name="WorkerTimeoutError",this.messageType=e,this.timeout=t}}});async function tn(s,e,t,r=!0){if(t.has(e)){s.logger.warn("importModule: skipping already imported module",e);return}else t.add(e);e.extends&&await Promise.all(e.extends.map(n=>tn(s,n,t,!1)));let{registry:i}=s;if(e.define)for(let[n,o]of Object.entries(e.define))i.define(n,o);if(e.routes)for(let[n,o]of Object.entries(e.routes))i.appendRoute(n,o);await(e.initialize?.({define:(n,o)=>i.define(n,o),kernel:s,registry:i})??Promise.resolve()),r&&s.upgradeEntities()}var $a,Da=f(()=>{"use strict";V();$a=`module has no "${ys}" export`});var Or,La=f(()=>{"use strict";Or=class extends Error{constructor(e){super(`the kernel cannot create an entity because the uuid ${e} is already held by another entity`),this.name="EntityUuidInUseError",this.uuid=e}}});var Pr,re,sn,Wt,Rr=f(()=>{"use strict";Pr=Symbol("onCreate"),re=Symbol("onDestroy"),sn=Symbol("onParentChanged"),Wt=Symbol("onViewEvent")});var Jc,rn,Xc,Wa,Ft,Zc,za,eu,_a,Ts,tu,Fa,ja,su,nn,ru,G,Mr,Ps,Qe,Ia,ce,Je,Rs,on,_e,Nr,Os,_t,be,an=f(()=>{"use strict";B();K();Ii();Jc=Object.create,rn=Object.defineProperty,Xc=Object.getOwnPropertyDescriptor,Wa=(s,e)=>(e=Symbol[s])?e:Symbol.for("Symbol."+s),Ft=s=>{throw TypeError(s)},Zc=(s,e,t)=>e in s?rn(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,za=(s,e)=>rn(s,"name",{value:e,configurable:!0}),eu=s=>[,,,Jc(s?.[Wa("metadata")]??null)],_a=["class","method","getter","setter","accessor","field","value","get","set"],Ts=s=>s!==void 0&&typeof s!="function"?Ft("Function expected"):s,tu=(s,e,t,r,i)=>({kind:_a[s],name:e,metadata:r,addInitializer:n=>t._?Ft("Already initialized"):i.push(Ts(n||null))}),Fa=(s,e)=>Zc(e,Wa("metadata"),s[3]),ja=(s,e,t,r)=>{for(var i=0,n=s[e>>1],o=n&&n.length;i<o;i++)e&1?n[i].call(t):r=n[i].call(t,r);return r},su=(s,e,t,r,i,n)=>{var o,a,l,h,u,c=e&7,g=!!(e&8),p=!!(e&16),H=c>3?s.length+1:c?g?1:2:0,Qt=_a[c+5],Jt=c>3&&(s[H-1]=[]),Kr=s[H]||(s[H]=[]),C=c&&(!p&&!g&&(i=i.prototype),c<5&&(c>3||!p)&&Xc(c<4?i:{get[t](){return G(this,n)},set[t](b){return Ps(this,n,b)}},t));c?p&&c<4&&za(n,(c>2?"set ":c>1?"get ":"")+t):za(i,t);for(var nt=r.length-1;nt>=0;nt--)h=tu(c,t,l={},s[3],Kr),c&&(h.static=g,h.private=p,u=h.access={has:p?b=>ru(i,b):b=>t in b},c^3&&(u.get=p?b=>(c^1?G:Qe)(b,i,c^4?n:C.get):b=>b[t]),c>2&&(u.set=p?(b,ot)=>Ps(b,i,ot,c^4?n:C.set):(b,ot)=>b[t]=ot)),a=(0,r[nt])(c?c<4?p?n:C[Qt]:c>4?void 0:{get:C.get,set:C.set}:i,h),l._=1,c^4||a===void 0?Ts(a)&&(c>4?Jt.unshift(a):c?p?n=a:C[Qt]=a:i=a):typeof a!="object"||a===null?Ft("Object expected"):(Ts(o=a.get)&&(C.get=o),Ts(o=a.set)&&(C.set=o),Ts(o=a.init)&&Jt.unshift(o));return c||Fa(s,i),C&&rn(i,t,C),p?c^4?n:C:i},nn=(s,e,t)=>e.has(s)||Ft("Cannot "+t),ru=(s,e)=>Object(e)!==e?Ft('Cannot use the "in" operator on this value'):s.has(e),G=(s,e,t)=>(nn(s,e,"read from private field"),t?t.call(s):e.get(s)),Mr=(s,e,t)=>e.has(s)?Ft("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,t),Ps=(s,e,t,r)=>(nn(s,e,"write to private field"),r?r.call(s,t):e.set(s,t),t),Qe=(s,e,t)=>(nn(s,e,"access private method"),t),_t="value";Ia=[xs({name:_t})];be=class{constructor(e){Mr(this,_e),Mr(this,ce,[]),Mr(this,Je),Mr(this,on,ja(Rs,8,this)),ja(Rs,11,this),this.value$=void 0,ye(this,_t),this.value$=Ge(this,_t),this.value$.onChange(t=>me(this,_t,t)),e&&this.add(...e)}get signals(){return G(this,ce).slice()}add(...e){return G(this,ce).push(...e),Qe(this,_e,Os).call(this),Qe(this,_e,Nr).call(this,e)}unshift(...e){return G(this,ce).unshift(...e),Qe(this,_e,Os).call(this),Qe(this,_e,Nr).call(this,e)}remove(...e){Qe(this,_e,Nr).call(this,e)()}clear(){G(this,ce).length=0,Qe(this,_e,Os).call(this)}dispose(){this.clear(),G(this,Je)?.destroy(),Ps(this,Je,void 0),os(this,_t),S(this),this.value$.destroy(),ps(this)}};Rs=eu(null);ce=new WeakMap;Je=new WeakMap;on=new WeakMap;_e=new WeakSet;Nr=function(s){return()=>{for(let e of s){let t=G(this,ce).indexOf(e);t!==-1&&G(this,ce).splice(t,1)}Qe(this,_e,Os).call(this)}};Os=function(){G(this,Je)?.destroy(),G(this,ce).length===0?(Ps(this,Je,void 0),this.value=void 0):(Ps(this,Je,O(()=>{let s;for(let e of G(this,ce)){let t=qe(e);if(t!=null){s=t;break}}this.value=s},G(this,ce))),G(this,Je).run())};su(Rs,4,"value",Ia,be,on);Fa(Rs,be);be.Value=_t});var Ba,iu,nu,$r,Ua=f(()=>{"use strict";B();K();dr();Dt();Rr();an();Ba=new WeakMap,iu=s=>{let e=Ba.get(s);return e==null&&(e=new Ye(t=>{for(let[r,i]of t)x(s.logger,()=>r.set(i.value),`an effect of a context value failed (${String(i.name)}):`,i.uuid)}),Ba.set(s,e)),e},nu=(s,e,t,r,i)=>{iu(s).add(e,{value:t,name:r,uuid:i})},$r=class s{#e;#t;#s=new ar;#i=new Map;#r=new Map;#n;#o=new Set;#a=[];#h=0;#c=!1;get kernel(){return this.#e}get uuid(){return this.#t}get order(){return this.#h}set order(e){this.#h!==e&&(this.#h=e,this.#n&&this.#n.resortChildren(),this.#e.noteEntityTreeChange(this.#t))}get parentUuid(){return this.#n?.uuid}set parentUuid(e){if(this.#n?.uuid!==e){let t=e?this.#e.getEntity(e):void 0;t!=null&&this.assertAttachableTo(t),this.#d(t==null),this.#n=t,this.#n&&this.#n.addChild(this),this.#m(),this.#e.noteEntityTreeChange(this.#t)}}get parent(){return this.#n}set parent(e){this.parentUuid=e?.uuid}get hasParent(){return!!this.#n}get children(){return this.#a}constructor(e,t){this.#e=e,this.#t=t}traverse(e){this.#l(e,new Set)}#l(e,t){if(!t.has(this)){t.add(this),e(this);for(let r of this.#a)r.#l(e,t)}}[re](){if(!this.#c){this.#c=!0,this.#u("properties",()=>this.#s.clear()),this.#u("listeners",()=>S(this)),this.#u("auto-destruction subscription",()=>this.#p?.());for(let e of this.#r.values())this.#u("global context cleanup",()=>e.cleanup()),this.#u("global context signal",()=>e.signal.destroy());for(let e of this.#i.values())this.#u("context value reset",()=>e.context.set(void 0)),this.#u("context value subscription",()=>e.unsubscribePathValue()),this.#u("context parent subscription",()=>e.unsubscribeFromParent?.()),this.#u("context value path",()=>e.valuePath.dispose()),this.#u("inherited context signal",()=>e.inherited.destroy()),this.#u("provided context signal",()=>e.provide.destroy()),this.#u("context signal",()=>e.context.destroy());this.#r.clear(),this.#i.clear(),this.#n=void 0,this.#o.clear(),this.#a.length=0}}#u(e,t){x(this.#e.logger,t,`entity teardown step failed (${e}):`,this.#t)}assertAttachableTo(e){for(let t=e;t!=null;t=t.parent)if(t===this)throw new Error(`entity "${e.uuid}" cannot become the parent of "${this.uuid}": it is the entity itself or one of its descendants`)}addChild(e){if(this.#o.has(e.uuid))throw new Error(`child with uuid: ${e.uuid} already exists! parentUuid: ${this.uuid}`);this.#o.add(e.uuid),this.#g(e);for(let[,t]of e.#i)e.#x(t)}#g(e){let t=this.#a.length;for(;t>0&&e.order<this.#a[t-1].order;)t--;this.#a.splice(t,0,e)}resortChildren(){this.#a.sort((e,t)=>e.order-t.order)}removeChild(e){let t=this.#a.indexOf(e);t!==-1&&(this.#o.delete(e.uuid),this.#a.splice(t,1))}removeFromParent(e=!0){this.#d(e)}#d(e){if(this.#n){if(this.#n.removeChild(this),this.#n=void 0,e)for(let[,t]of this.#i)this.#x(t);this.#v(),this.#e.noteEntityTreeChange(this.#t)}}#f=!1;#p;get autoDestructionOnParentRemoval(){return this.#f}set autoDestructionOnParentRemoval(e){this.#f!==e&&(this.#f=e,this.#m())}#v(){this.#p&&(this.#p(),this.#p=void 0)}#m(){this.#v(),this.#f&&this.#n&&(this.#p=T(this.#n,re,Y.Max,()=>{this.#p=void 0,this.#e.destroyEntity(this.#t)}))}reSubscribeToParentContexts(){for(let[,e]of this.#i)this.#x(e)}dispatchMessageToView(e,t,r,i=!1){this.#e.dispatchMessageToView({uuid:this.#t,type:e,data:t,transferables:r,traverseChildren:i})}dispatchViewEvents(e){for(let{type:t,data:r}of e)x(this.#e.logger,()=>W(this,Wt,t,r),"entity view event delivery failed:",t,this.#t)}dispatchViewEvent(e,t){this.dispatchViewEvents([{type:e,data:t}])}#y(e){return this.#s.get(e)}getPropertyReader(e){return this.#y(e).get}getPropertyWriter(e){let t=this.#y(e);return(r,i)=>{this.clearTruthyPropsCache(),t.set(r,i)}}setProperties(e){ee(()=>{for(let[t,r]of e)this.setProperty(t,r)})}setProperty(e,t){this.getPropertyWriter(e)(t)}getProperty(e){return qe(this.getPropertyReader(e))}propKeys(){return Array.from(this.#s.keys())}propEntries(){return Array.from(this.#s.entries()).map(([e,t])=>[e,t.value])}#w;clearTruthyPropsCache(){this.#w=void 0}truthyProps(){if(this.#w)return this.#w.size?this.#w:void 0;let e=new Set;for(let[t,r]of this.#s.entries())if(typeof t=="string"){let i=r.value;i!=null&&i!==!1&&i!==""&&e.add(t)}return this.#w=e,e.size?e:void 0}hasContext(e){return this.#i.has(e)}contextNames(){return Array.from(this.#i.keys())}describeContext(e){let t=this.#i.get(e);if(t!==void 0)return{provided:t.provide.value,inherited:t.inherited.value,effective:t.context.value,hasProviders:t.providerFeeds.size>0}}globalContextNames(){return Array.from(this.#r.keys())}describeGlobalContext(e){let t=this.#r.get(e);if(t!==void 0)return{value:t.signal.value,signal:t.signal,hasProviders:t.providerFeeds.size>0}}useContext(e){return this.#b(e).context.get}useParentContext(e){return this.#b(e).inherited.get}provideContext(e){return this.#b(e).provide}provideGlobalContext(e){return this.#S(e).signal}attachContextProvider(e,t){let r=this.#b(e);return s.#C(t,r.provide,r.providerFeeds)}attachGlobalContextProvider(e,t){let r=this.#S(e);return s.#C(t,r.signal,r.providerFeeds)}static#C(e,t,r){let i=$e(e,t);return r.add(i),()=>{r.delete(i)&&(i.destroy(),s.#k(r))}}static#k(e){let t;for(let r of e)!r.isDestroyed&&r.source.value!=null&&(t=r);t?.touch()}#S(e){if(this.#r.has(e))return this.#r.get(e);let t=this.#e.findOrCreateRootContext(e),r=m(),n={cleanup:t.add(r),signal:r,providerFeeds:new Set};return this.#r.set(e,n),n}#b(e){if(this.#i.has(e))return this.#i.get(e);let t=m(),r=m(),i=m(),n=new be([r,t]),o=y(n,be.Value,l=>{nu(this.#e,i,l,e,this.#t)}),a={name:e,inherited:t,provide:r,context:i,valuePath:n,providerFeeds:new Set,unsubscribePathValue:o};return this.#i.set(e,a),this.#x(a),a}#x(e){if(e.unsubscribeFromParent?.(),e.unsubscribeFromParent=void 0,this.parent){let t=this.parent.#b(e.name),r=$e(t.context,e.inherited);e.unsubscribeFromParent=r.destroy.bind(r)}else{let t=this.#e.findOrCreateRootContext(e.name),r=$e(t.value$,e.inherited);e.unsubscribeFromParent=r.destroy.bind(r)}}}});var ln,Va=f(()=>{"use strict";ln=s=>s??void 0});function qa(s,e){let[t]=e;return e.length>1&&typeof t=="object"&&t!==null&&!Array.isArray(t)?e:[s,...e]}var Xe,ou,Ga,Dr,Ha=f(()=>{"use strict";B();K();Dt();Va();Rr();Xe=()=>{let s=m(void 0);return R(s),s},ou=()=>{let s=O(()=>{},{autorun:!1});return s.destroy(),s},Ga=()=>{};Dr=class{#e;#t;#s;#i;#r=new Set;#n=new Set;#o=new Set;#a=new Map;#h=new Map;#c=new Map;#l=new Map;#u=new Map;#g=new Map;#d=new Set;#f=new Map;#p=new Map;#v;#m;#y;#w;#C=!1;#k=!1;#S;get displayName(){return this.#s}get debugHandles(){return{shadowObject:this.#v,releaseScope:this.#m,forgetShadowObject:this.#y,unsubscribeFromEntityDestroy:this.#w}}get debugCleanupCounts(){return{primary:this.#r.size,secondary:this.#n.size,contextFeeds:this.#o.size}}describe(){return{displayName:this.#s,usesProperties:Array.from(this.#f.keys()),usesContexts:Array.from(this.#a.keys()),usesParentContexts:Array.from(this.#c.keys()),providesContexts:Array.from(this.#u.keys()),providesGlobalContexts:Array.from(this.#g.keys())}}constructor(e,t,r,i){this.#e=e,this.#t=t,this.#s=r,this.#i=i}createAPI(){return{entity:this.#e,provideContext:this.provideContext.bind(this),provideGlobalContext:this.provideGlobalContext.bind(this),useContext:this.useContext.bind(this),useParentContext:this.useParentContext.bind(this),dispatchMessageToView:this.dispatchMessageToView.bind(this),useProperty:this.useProperty.bind(this),useProperties:this.useProperties.bind(this),createResource:this.createResource.bind(this),createEffect:this.createEffect.bind(this),createSignal:this.createSignal.bind(this),createMemo:this.createMemo.bind(this),on:this.on.bind(this),once:this.once.bind(this),emit:this.emit.bind(this),onViewEvent:this.onViewEvent.bind(this),onDestroy:this.onDestroy.bind(this)}}bindTo(e,t,r){if(this.#C)throw new Error(`the creation scope of "${this.#s}" has torn down and cannot be bound`);if(this.#v!==void 0)throw new Error(`the creation scope of "${this.#s}" is already bound to a shadow-object`);this.#v=e,this.#m=t,this.#y=r,this.#t.info("create shadow-object",this.#s,{shadowObject:e,entity:this.#e}),this.#w=T(this.#e,re,Y.Low,()=>{this.tearDown()})}tearDown(){if(this.#C)return;this.#C=!0,this.#b("scope release",()=>this.#m?.()),this.#b("entity destroy subscription",()=>this.#w?.()),this.#v!==void 0&&this.#t.info("destroy shadow-object",this.#s,{shadowObject:this.#v,entity:this.#e});let e=new Set,t=(i,n)=>{let o=!1;for(let a of i)e.has(a)||(e.add(a),o=!0,this.#b(n,a));return o},r=!0;for(;r;){let i=t(this.#r,"onDestroy callback"),n=t(this.#n,"creation-api cleanup");r=i||n}for(let i of this.#o)this.#b("context feed release",i);for(let i of this.#a.values())this.#b("context reader",()=>R(i));for(let i of this.#c.values())this.#b("parent context reader",()=>R(i));for(let i of this.#f.values())this.#b("property reader",()=>R(i));for(let i of this.#u.values())this.#b("context provider",()=>R(i));for(let i of this.#g.values())this.#b("global context provider",()=>R(i));this.#r.clear(),this.#n.clear(),this.#o.clear(),this.#a.clear(),this.#h.clear(),this.#c.clear(),this.#l.clear(),this.#f.clear(),this.#p.clear(),this.#u.clear(),this.#g.clear(),this.#d.clear(),this.#b("forget shadow-object",()=>this.#y?.()),this.#v=void 0,this.#m=void 0,this.#y=void 0,this.#w=void 0,this.#k=!0}#b(e,t){x(this.#t,t,`shadow-object teardown failed (${e}):`,this.#s)}#x(e){return this.#n.add(e),Object.assign(()=>{this.#n.delete(e),e()},e)}#R(e,t,r,i,n,o,a){let l=t.get(e);if(l===void 0){l=m(void 0,n).get,t.set(e,l),r.set(e,n?.compare);let h=$e(i(),l);this.#n.add(h.destroy.bind(h))}else n?.compare!=null&&r.get(e)!==n.compare&&this.#t.error(`[shadow-objects] ${o}("${String(e)}"): the cached signal already exists with a different (or no) {compare} function \u2014 the new options are ignored. Pass options only on the first call per ${a}.`);return l}#T(e,t){typeof e!="function"||this.#i.has(t)||(this.#t.error(`[shadow-objects] Deprecation Warning: The "isEqual" option of "${t}()" is now passed as {compare} argument. Please update your code accordingly.`),this.#i.add(t))}#E(e){return this.#k?(this.#S?.has(e)||((this.#S??=new Set).add(e),this.#t.error(`[shadow-objects] ${e}(): the creation scope of "${this.#s}" has torn down \u2014 the call does nothing. Something is still holding the creation API past the end of its shadow-object.`)),!0):!1}useProperty(e,t){if(this.#E("useProperty"))return Xe().get;this.#T(t,"useProperty");let r=typeof t=="function"?{compare:t}:t;return this.#R(e,this.#f,this.#p,()=>this.#e.getPropertyReader(e),r,"useProperty","property")}useProperties(e){let t={};for(let r in e)Object.hasOwn(e,r)&&(t[r]=this.useProperty(e[r]));return t}#A(e,t,r,i,n){let o=t.get(e);if(o==null){let a=le(i),l=a?void 0:ln(i);if(o=m(l,n?.compare?{compare:n.compare}:void 0),a){let h=$e(i,o);this.#n.add(h.destroy.bind(h))}this.#o.add(r(o)),t.set(e,o)}return(n?.clearOnDestroy??!0)&&!this.#d.has(o)&&(this.#d.add(o),this.#n.add(()=>{o.set(void 0)})),o}provideContext(e,t,r){if(this.#E("provideContext"))return Xe();this.#T(r,"provideContext");let i=typeof r=="function"?{compare:r}:r;return this.#A(e,this.#u,n=>this.#e.attachContextProvider(e,n),t,i)}provideGlobalContext(e,t,r){if(this.#E("provideGlobalContext"))return Xe();this.#T(r,"provideGlobalContext");let i=typeof r=="function"?{compare:r}:r;return this.#A(e,this.#g,n=>this.#e.attachGlobalContextProvider(e,n),t,i)}useContext(e,t){if(this.#E("useContext"))return Xe().get;this.#T(t,"useContext");let r=typeof t=="function"?{compare:t}:t;return this.#R(e,this.#a,this.#h,()=>this.#e.useContext(e),r,"useContext","context")}useParentContext(e,t){if(this.#E("useParentContext"))return Xe().get;this.#T(t,"useParentContext");let r=typeof t=="function"?{compare:t}:t;return this.#R(e,this.#c,this.#l,()=>this.#e.useParentContext(e),r,"useParentContext","parent context")}createSignal(...e){if(this.#E("createSignal"))return Xe();let t=m(...e);return this.#n.add(()=>{R(t)}),t}createEffect(...e){if(this.#E("createEffect"))return ou();let t=O(...e);return this.#n.add(t.destroy),t}createMemo(...e){if(this.#E("createMemo"))return Xe().get;let t=zo(...e);return this.#n.add(()=>{R(t)}),t}createResource(e,t){if(this.#E("createResource"))return Xe();let r=m(),i=O(()=>{let n=ln(e());return r.set(n),n!==void 0&&t?()=>{t(n),r.set(void 0)}:()=>{r.set(void 0)}});return this.#n.add(()=>{try{i.destroy()}finally{r.set(void 0),R(r)}}),r}on(...e){if(this.#E("on"))return Ga;let t=y(...qa(this.#e,e));return this.#x(t)}once(...e){if(this.#E("once"))return Ga;let t=T(...qa(this.#e,e));return this.#x(t)}emit(...e){if(this.#E("emit"))return;let[t]=e;typeof t=="string"||typeof t=="symbol"||Array.isArray(t)?k(this.#e,...e):k(...e)}onViewEvent(e){if(this.#E("onViewEvent"))return;let t=y(this.#e,Wt,(r,i)=>{e(r,i)});this.#n.add(t)}onDestroy(e){this.#E("onDestroy")||this.#r.add(e)}dispatchMessageToView(e,t,r,i=!1){this.#E("dispatchMessageToView")||this.#e.dispatchMessageToView(e,t,r,i)}}});var Ya,Lr,Ka=f(()=>{"use strict";B();K();yr();V();La();Q();Dt();Bi();Ua();Rr();wr();Ha();an();Ya=[["onCreate",Pr],["onDestroy",re],["onParentChanged",sn],["onViewEvent",Wt]],Lr=class{#e=new E("Kernel");get logger(){return this.#e}#t=new Map;#s=new Set;#i=[];#r=[];#n=!0;#o=new Map;#a=new WeakMap;#h=new Set;constructor(e){$(this),this.registry=We.get(e)}getEntity(e){return this.#c(e).entity}findEntity(e){return this.#t.get(e)?.entity}#c(e){let t=this.#t.get(e);if(t===void 0)throw new Error(`entity with uuid "${e}" not found!`);return t}hasEntity(e){return this.#t.has(e)}tokenOf(e){return this.#t.get(e)?.token}get debugEntityCounts(){return{entities:this.#t.size,rootEntities:this.#s.size,traversal:this.#i.length,traversalReversed:this.#r.length}}traverseLevelOrderBFS(e=!1){if(this.#n){let t=new Map,r=new Set,i=(n,o)=>{if(r.has(n))return;r.add(n);let a=this.findEntity(n);if(a===void 0)return;let l=t.get(o);l?l.push(a):t.set(o,[a]);for(let h of a.children)i(h.uuid,o+1)};this.#s.forEach(n=>{i(n,0)}),this.#i=Array.from(t.entries()).sort((n,o)=>n[0]-o[0]).flatMap(([,n])=>n),this.#r=this.#i.slice().reverse(),this.#n=!1}return e?this.#r.slice():this.#i.slice()}getEntityGraph(){let e=new Set;return Array.from(this.#s).map(t=>this.#l(t,e)).filter(t=>t!==void 0)}#l(e,t,r){let i=this.#t.get(e);if(i===void 0){r?.push({uuid:e,reason:"not-in-kernel"});return}if(t.has(e)){r?.push({uuid:e,reason:"already-in-graph"});return}t.add(e);let{token:n,entity:o}=i,a=[],l=o.children.map(h=>this.#l(h.uuid,t,a)).filter(h=>h!==void 0);return{token:n,entity:o,props:Object.fromEntries(o.propEntries()),children:l,...a.length>0?{omittedChildren:a}:{}}}upgradeEntities(){let e=new Map;for(let t of this.traverseLevelOrderBFS(!0))this.hasEntity(t.uuid)&&e.set(t.uuid,this.#d(t.uuid,2));for(let t of this.traverseLevelOrderBFS(!1))this.hasEntity(t.uuid)&&this.#d(t.uuid,1,e.get(t.uuid));e.clear()}run(e){this.logger.debug("sync",e);let t=0;try{ee(()=>{for(let r of e.changeTrail)this.#u(r),t++})}catch(r){throw new Ke(t,e.changeTrail.length,{cause:r})}}#u(e){switch(e.type){case w.CreateEntities:this.createEntity(e.uuid,e.token,e.parentUuid,e.order,e.properties,e.autoDestructionOnParentRemoval);break;case w.DestroyEntities:this.destroyEntity(e.uuid);break;case w.SetParent:this.setParent(e.uuid,e.parentUuid,e.order);break;case w.UpdateOrder:this.updateOrder(e.uuid,e.order);break;case w.ChangeProperties:this.changeProperties(e.uuid,e.properties);break;case w.ChangeToken:this.changeToken(e.uuid,e.token);break;case w.SendEvents:this.dispatchEventsToEntity(e.uuid,e.events);break}}createEntity(e,t,r,i=0,n,o=!1){if(this.#t.has(e))throw new Or(e);let a=new $r(this,e);a.order=i;let l={token:t,entity:a,usedConstructors:new Map};this.#t.set(e,l),this.noteEntityTreeChange(e);try{r&&(a.parentUuid=r),a.autoDestructionOnParentRemoval=o,n&&a.setProperties(n),this.#v(l)}catch(h){throw this.#g(e),h}}#g(e){x(this.logger,()=>this.destroyEntity(e),"rollback of a failed entity creation could not destroy the entity:",e)}destroyEntity(e){let t=this.#t.get(e);if(t===void 0)return;let{entity:r,usedConstructors:i}=t;try{let n=[...r.children];for(let a of n)x(this.logger,()=>{a.autoDestructionOnParentRemoval?this.destroyEntity(a.uuid):a.removeFromParent()},"child of a destroyed entity could not be handed on:",a.uuid);x(this.logger,()=>r.removeFromParent(),"entity could not be detached from its parent:",r.uuid);let o=this.findShadowObjects(r.uuid);for(let a of o)S(r,a),this.#y(a,r);x(this.logger,()=>W(r,re,r),"entity onDestroy notification failed:",r.uuid);for(let a of o)x(this.logger,()=>this.#a.get(a)?.tearDown(),"creation scope teardown of a destroyed entity failed:",r.uuid);x(this.logger,()=>r[re](),"entity release failed:",r.uuid)}finally{i.clear(),this.#t.delete(r.uuid),this.#s.delete(r.uuid),this.#n=!0}}setParent(e,t,r){let i=this.getEntity(e),n=r??i.order;if(!(i.parentUuid===t&&i.order===n)){if(t&&!this.#t.has(t))throw new Error(`entity with uuid "${t}" not found!`);t&&i.assertAttachableTo(this.getEntity(t)),i.removeFromParent(t==null),i.order=n,i.parentUuid=t,this.logger.debug("entity.onParentChanged",{uuid:e,parentUuid:t,order:n,entity:i}),x(this.logger,()=>W(i,sn,i),"entity onParentChanged notification failed:",e)}}updateOrder(e,t){this.getEntity(e).order=t}noteEntityTreeChange(e){this.#n=!0;let t=this.#t.get(e);t!==void 0&&(t.entity.hasParent?this.#s.delete(e):this.#s.add(e))}dispatchEventsToEntity(e,t){this.findEntity(e)?.dispatchViewEvents(t)}changeProperties(e,t){this.getEntity(e).setProperties(t),this.#d(e)}changeToken(e,t){let r=this.#t.get(e);if(r===void 0||r.token===t)return;let i=r.token;r.token=t,this.#d(e,0,void 0,i)}dispatchMessageToView(e){queueMicrotask(()=>{me(this,Mt,e)})}#d(e,t=0,r,i){let n=this.#c(e);r??=new Set(this.registry.findConstructors(n.token,n.entity.truthyProps()));let o=t===0||t===2,a=t===0||t===1,l=[],h=[];if(o){for(let[u,c]of n.usedConstructors)if(!r.has(u)){n.usedConstructors.delete(u),l.push({construct:u,count:c.size});for(let g of c)this.#w(g,n.entity)}}if(a){for(let u of r)if(!n.usedConstructors.has(u))try{h.push(this.#p(u,n))}catch(c){throw this.#f(n,h,l,i),c}}return r}#f(e,t,r,i){if(this.#t.get(e.entity.uuid)===e){i!==void 0&&(e.token=i);for(let n=t.length-1;n>=0;n--)x(this.logger,()=>this.#w(t[n],e.entity),"rollback of a failed shadow-object update could not remove a new shadow-object:",e.entity.uuid);for(let{construct:n,count:o}of r)for(let a=0;a<o;a++)x(this.logger,()=>this.#p(n,e),"rollback of a failed shadow-object update could not restore a shadow-object:",Lt(n),e.entity.uuid)}}#p(e,t){let r=new Dr(t.entity,this.logger,Lt(e),this.#h),i;try{i=$(new e(r.createAPI()))}catch(o){throw r.tearDown(),o}this.#a.set(i,r),r.bindTo(i,()=>{this.#a.delete(i)},()=>{let o=t.usedConstructors.get(e);o&&(o.delete(i),o.size===0&&t.usedConstructors.delete(e))});let n=t.usedConstructors.get(e);n?n.add(i):t.usedConstructors.set(e,new Set([i]));try{this.#m(i,t.entity)}catch(o){throw this.#w(i,t.entity),o}return i}#v(e){this.registry.findConstructors(e.token,e.entity.truthyProps())?.forEach(t=>{this.#p(t,e)})}findShadowObjects(e){let t=this.#t.get(e);if(t===void 0)return[];let{usedConstructors:r}=t;return Array.from(new Set(Array.from(r.values()).flatMap(i=>Array.from(i))))}describeShadowObjects(e){let t=this.#t.get(e);if(t===void 0)return[];let r=new Set,i=[];for(let[n,o]of t.usedConstructors)for(let a of o){if(r.has(a))continue;r.add(a);let l=this.#a.get(a),h=Ya.filter(([,u])=>typeof a[u]=="function").map(([u])=>u);i.push({...l?.describe()??{displayName:Lt(n),usesProperties:[],usesContexts:[],usesParentContexts:[],providesContexts:[],providesGlobalContexts:[]},definedUnder:this.registry.tokensOf(n),hooks:h})}return i}#m(e,t){for(let[r,i]of Ya)if(typeof e[r]=="function"&&typeof e[i]!="function"){let n=this.#a.get(e)?.displayName;this.logger.error(`the "${r}" lifecycle hook is a plain method and is never called; use the [${r}] symbol from "@spearwolf/shadow-objects/shadow-objects.js":`,n)}y(t,e),typeof e[Pr]=="function"&&e[Pr](t)}#y(e,t){let r=this.#a.get(e)?.displayName;typeof e[re]=="function"&&x(this.logger,()=>e[re](t),"shadow-object onDestroy hook failed:",r),x(this.logger,()=>W(e,re,t),"shadow-object onDestroy notification failed:",r)}#w(e,t){this.#y(e,t),this.#a.get(e)?.tearDown(),S(t,e)}findOrCreateRootContext(e){let t=this.#o.get(e);return t||(t=new be,this.#o.set(e,t)),t}rootContextNames(){return Array.from(this.#o.keys())}describeRootContext(e){let t=this.#o.get(e);if(t!==void 0)return{value:t.value,signals:t.signals}}destroy(){for(let e of this.traverseLevelOrderBFS(!0))x(this.logger,()=>this.destroyEntity(e.uuid),"entity teardown during kernel destroy failed:",e.uuid);this.#t.clear(),this.#s.clear(),this.#i.length=0,this.#r.length=0,this.#n=!0;for(let e of this.#o.values())e.dispose();this.#o.clear(),queueMicrotask(()=>{S(this)})}}});var Qa,Ja=f(()=>{"use strict";Q();Qa=s=>typeof s=="object"&&s!==null});var zr,hn,It,Xa=f(()=>{"use strict";Na();Ja();zr=2147483647,hn=s=>typeof s=="number"&&Number.isFinite(s)&&s>0&&s<=zr,It=(s,e,t=1e3,r,i)=>new Promise((n,o)=>{if(t!==0&&t!==1/0&&!hn(t)){o(new TypeError(`cannot wait for a ${e} message: expected a timeout of 1 to ${zr} milliseconds, or 0 or Infinity for no deadline, got ${String(t)}`));return}if(i?.aborted){o(i.reason);return}let a,l,h=()=>{clearTimeout(a),s.removeEventListener("message",l),i?.removeEventListener("abort",u)};function u(){h(),o(i.reason)}t!==0&&t!==1/0&&(a=setTimeout(()=>{h(),o(new Tr(e,t))},t)),l=c=>{if(Qa(c.data)&&c.data.type===e)try{(!r||r(c.data))&&(h(),n())}catch(g){h(),o(g)}},i?.addEventListener("abort",u,{once:!0}),s.addEventListener("message",l)})});var au,cn,Ze,Bt,Za,lu,Ut,un=f(()=>{"use strict";B();yr();V();Ma();Q();en();Xa();au=s=>{if(!Array.isArray(s))return{changeTrail:s};let e,t;for(let r=0;r<s.length;r++){let i=s[r];if(i?.transferables){t=t?[...t,...i.transferables]:[...i.transferables],e??=[...s];let n={...i};delete n.transferables,e[r]=n}}return{changeTrail:e??s,transferables:t}},cn=class extends Error{constructor(e,t,r){super(t,r),this.name="WorkerFailedError",this.type=e}},Ze=class extends Error{constructor(e="the worker environment has been destroyed"){super(e),this.name="WorkerDestroyedError"}},Bt=class extends Error{constructor(e,t){super(t),this.name=e||"Error"}},Za={loadTimeout:Yo,configureTimeout:Ko,changeTrailTimeout:Qo,inspectTimeout:Jo,destroyTimeout:Xo},lu=(s,e)=>{let t={...Za};if(s==null)return t;for(let r of Object.keys(Za)){if(!Object.hasOwn(s,r))continue;let i=s[r];i!==void 0&&(hn(i)?t[r]=i:e.error(`ignoring the ${r} option: expected a number of milliseconds from 1 to ${zr}, got`,i))}return t},Ut=class s{constructor(e){this.#t=!1,this.#s=0,this.#i=0,this.#r=new AbortController,this.#n=new E("RemoteWorkerEnv"),this.onWorkerError=t=>{this.handleWorkerFailure("error",t,t.message||"the worker reported an error")},this.onWorkerMessageError=t=>{this.handleWorkerFailure("messageerror",t,"the worker sent a message that could not be deserialized")},this.onMessageFromWorker=t=>{t.data?.type===Mt?this.onMessageToView?.(t.data.data):this.logger.debug("message from worker",t)},this.#o=Object.freeze(lu(e,this.logger)),ye(this,s.WorkerLoaded),ye(this,s.WorkerFailed)}static{this.WorkerLoaded="workerLoaded"}static{this.WorkerFailed="workerFailed"}#e;#t;#s;#i;#r;#n;get logger(){return this.#n}#o;get timeouts(){return this.#o}get isDestroyed(){return this.#t}get workerLoaded(){let{signal:e}=this.#r;return e.aborted?Promise.reject(e.reason):new Promise((t,r)=>{let i,n=!1,o=()=>{n||(n=!0,i?.(),r(e.reason))};i=T(this,s.WorkerLoaded,a=>{n||(n=!0,e.removeEventListener("abort",o),t(a))}),!n&&e.addEventListener("abort",o,{once:!0})})}async start(){let{signal:e}=this.#r;if(e.aborted)throw e.reason;if(this.#e)return this.logger.warn("already started"),this.workerLoaded.then(()=>{if(this.isDestroyed)throw new Ze});let t=this.#e=Ra();t.addEventListener("error",this.onWorkerError),t.addEventListener("messageerror",this.onWorkerMessageError),this.configureConsoleLogger(t);try{if(await It(t,Uo,this.timeouts.loadTimeout,void 0,e),this.isDestroyed)throw e.aborted?e.reason:new Ze;t.addEventListener("message",this.onMessageFromWorker),queueMicrotask(()=>{this.announceLoaded()})}catch(r){throw r!==e.reason&&this.logger.error("failed to start",r),this.stopListeningTo(t),this.#e=void 0,this.#t||t.terminate(),r}}applyChangeTrail(e,t){let{signal:r}=this.#r;if(r.aborted)return Promise.reject(r.reason);let i=this.#e;if(i==null)return Promise.reject(new Ze);let{changeTrail:n,transferables:o}=au(e),a={type:Fo,changeTrail:n};if(!t)return i.postMessage(a,o??[]),Promise.resolve();let l=++this.#s;return a.serial=l,i.postMessage(a,o??[]),It(i,Vo,this.timeouts.changeTrailTimeout,h=>{if(h.serial!==l)return!1;if(h.error){let u=new Bt(h.errorName,h.error);throw typeof h.appliedCount=="number"?new Ke(h.appliedCount,e.length,{cause:u}):u}return!0},r)}importScript(e){let{signal:t}=this.#r;if(t.aborted)return Promise.reject(t.reason);let r=this.#e;return r==null?Promise.reject(new Ze):(e=Ar(e),r.postMessage({type:_o,importModule:e}),It(r,Go,this.timeouts.configureTimeout,i=>{if(i.url!==e)return!1;if(i.error)throw new Bt(i.errorName,i.error);return!0},t))}inspect(e={},t){let{signal:r}=this.#r;if(r.aborted)return Promise.reject(r.reason);if(t?.aborted)return Promise.reject(t.reason);let i=this.#e;if(i==null)return Promise.reject(new Ze);let n=++this.#i,o={type:Io,serial:n,request:e};i.postMessage(o);let a;return It(i,Ho,this.timeouts.inspectTimeout,l=>{if(l.serial!==n)return!1;if(l.error)throw new Bt(l.errorName,l.error);return a=l.snapshot,!0},t===void 0?r:AbortSignal.any([r,t])).then(()=>{if(a===void 0)throw new Bt(void 0,"the worker answered the inspection without a snapshot");return a})}destroy(){this.#t=!0;let e=this.#e;this.#e=void 0,this.#r.abort(new Ze),e!=null&&(this.stopListeningTo(e),e.postMessage({type:Bo}),It(e,qo,this.timeouts.destroyTimeout).catch(t=>{this.logger.warn("the worker did not acknowledge the teardown",t)}).finally(()=>{e.terminate()}))}handleWorkerFailure(e,t,r){if(this.#t)return;this.#t=!0;let i=new cn(e,r,{cause:e==="error"?t.error??t:t});this.logger.error(r,t);let n=this.#e;this.#e=void 0,n!=null&&this.stopListeningTo(n),this.#r.abort(i),n?.terminate();try{this.onProxyFailed?.(i)}catch(o){this.logger.error("the proxy-failed callback threw",o)}this.announceFailure({env:this,type:e,message:r,reason:i,event:t})}announceLoaded(){try{W(this,s.WorkerLoaded,this)}catch(e){this.logger.error("a workerLoaded listener threw",e)}}announceFailure(e){try{W(this,s.WorkerFailed,e)}catch(t){this.logger.error("a workerFailed listener threw",t)}}stopListeningTo(e){e.removeEventListener("error",this.onWorkerError),e.removeEventListener("messageerror",this.onWorkerMessageError),e.removeEventListener("message",this.onMessageFromWorker)}configureConsoleLogger(e){let t=["RemoteWorkerEnv","workerConfig"],r=na(t),i=this.readWorkerConfig(t,r);this.logger.info("load console-logger worker config",{storageKey:r,workerConfig:i}),e.postMessage({type:ze,config:{...E.sharedConfig,enable:this.logger.isEnabled,...i,...E.isEnabled?{}:{enable:!1}}})}readWorkerConfig(e,t){let r=oa(e,"{}"),i;try{i=JSON.parse(r)}catch(n){return this.logger.error(`ignoring the unreadable console-logger worker config at "${t}"`,r,n),{}}return typeof i!="object"||i===null||Array.isArray(i)?(this.logger.error(`ignoring the console-logger worker config at "${t}": expected a JSON object`,r),{}):i}}});var hu,vn,cu,sl,Yt,uu,el,du,rl,Ms,fu,il,jr,nl,wn,pu,d,z,A,N,ol,al,ll,L,ue,vt,wt,qt,et,dn,tt,bn,En,j,Ht,M,fn,hl,Vt,Gt,Wr,_r,cl,pn,Cn,gn,mn,yn,ul,dl,de,gu,tl,mu,yu,q,F,Fr=f(()=>{"use strict";B();K();Ii();yr();V();Ta();Q();gt();un();hu=Object.create,vn=Object.defineProperty,cu=Object.getOwnPropertyDescriptor,sl=(s,e)=>(e=Symbol[s])?e:Symbol.for("Symbol."+s),Yt=s=>{throw TypeError(s)},uu=(s,e,t)=>e in s?vn(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,el=(s,e)=>vn(s,"name",{value:e,configurable:!0}),du=s=>[,,,hu(s?.[sl("metadata")]??null)],rl=["class","method","getter","setter","accessor","field","value","get","set"],Ms=s=>s!==void 0&&typeof s!="function"?Yt("Function expected"):s,fu=(s,e,t,r,i)=>({kind:rl[s],name:e,metadata:r,addInitializer:n=>t._?Yt("Already initialized"):i.push(Ms(n||null))}),il=(s,e)=>uu(e,sl("metadata"),s[3]),jr=(s,e,t,r)=>{for(var i=0,n=s[e>>1],o=n&&n.length;i<o;i++)e&1?n[i].call(t):r=n[i].call(t,r);return r},nl=(s,e,t,r,i,n)=>{var o,a,l,h,u,c=e&7,g=!!(e&8),p=!!(e&16),H=c>3?s.length+1:c?g?1:2:0,Qt=rl[c+5],Jt=c>3&&(s[H-1]=[]),Kr=s[H]||(s[H]=[]),C=c&&(!p&&!g&&(i=i.prototype),c<5&&(c>3||!p)&&cu(c<4?i:{get[t](){return d(this,n)},set[t](b){return A(this,n,b)}},t));c?p&&c<4&&el(n,(c>2?"set ":c>1?"get ":"")+t):el(i,t);for(var nt=r.length-1;nt>=0;nt--)h=fu(c,t,l={},s[3],Kr),c&&(h.static=g,h.private=p,u=h.access={has:p?b=>pu(i,b):b=>t in b},c^3&&(u.get=p?b=>(c^1?d:N)(b,i,c^4?n:C.get):b=>b[t]),c>2&&(u.set=p?(b,ot)=>A(b,i,ot,c^4?n:C.set):(b,ot)=>b[t]=ot)),a=(0,r[nt])(c?c<4?p?n:C[Qt]:c>4?void 0:{get:C.get,set:C.set}:i,h),l._=1,c^4||a===void 0?Ms(a)&&(c>4?Jt.unshift(a):c?p?n=a:C[Qt]=a:i=a):typeof a!="object"||a===null?Yt("Object expected"):(Ms(o=a.get)&&(C.get=o),Ms(o=a.set)&&(C.set=o),Ms(o=a.init)&&Jt.unshift(o));return c||il(s,i),C&&vn(i,t,C),p?c^4?n:C:i},wn=(s,e,t)=>e.has(s)||Yt("Cannot "+t),pu=(s,e)=>Object(e)!==e?Yt('Cannot use the "in" operator on this value'):s.has(e),d=(s,e,t)=>(wn(s,e,"read from private field"),t?t.call(s):e.get(s)),z=(s,e,t)=>e.has(s)?Yt("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,t),A=(s,e,t,r)=>(wn(s,e,"write to private field"),r?r.call(s,t):e.set(s,t),t),N=(s,e,t)=>(wn(s,e,"access private method"),t),ol=(s,e,t,r)=>({set _(i){A(s,e,i,t)},get _(){return d(s,e,r)}}),de=class extends Error{constructor(e="the shadow environment has been destroyed"){super(e),this.name="ShadowEnvDestroyedError"}},gu=s=>typeof s=="symbol"?s.description??String(s):s??"",tl=s=>s instanceof Error?{name:s.name,message:s.message}:{name:"Error",message:String(s)},mu=s=>{let e,t=new Promise((r,i)=>{e=()=>i(s.reason),s.addEventListener("abort",e,{once:!0})});return t.catch(()=>{}),{promise:t,dispose:()=>s.removeEventListener("abort",e)}},yu=s=>s===void 0?"none":s.isLocalEnv===!0?"local":s instanceof Ut?"worker":"custom";ll=[xs()],al=[xs()];q=class Ns{constructor(){z(this,M),z(this,L),z(this,ue),z(this,vt,!1),z(this,wt,!1),z(this,qt,!1),z(this,et),z(this,dn,new E("ShadowEnv")),this.ns$=m(),z(this,bn,jr(tt,8,this,!1)),jr(tt,11,this),z(this,En,jr(tt,12,this,!1)),jr(tt,15,this),z(this,j,!1),z(this,Ht),z(this,Vt,0),z(this,Gt),z(this,Wr),this.ready=async()=>{if(d(this,j))throw new de;return this.isReady?this:Promise.race([ii(this,Ns.ContextCreated),N(this,M,_r).call(this)])},z(this,pn,()=>{d(this,vt)&&N(this,M,Cn).call(this)});let e=this;ye(e,Ns.ContextCreated),y(e,Ns.ContextLost,Y.Critical,()=>{os(e,Ns.ContextCreated)})}static get(e){if(e!=null)return globalThis.__shadowEnvs?.get(e)}static async inspectAll(e={},t,r){let i=[];for(let[o,a]of globalThis.__shadowEnvs?.entries()??[])(r===void 0||r(o))&&i.push(a);return(await Promise.all(i.map(o=>o.inspect(e,t).catch(a=>{if(t?.aborted)throw t.reason;if(!(a instanceof de))throw a})))).filter(o=>o!==void 0)}get logger(){return d(this,dn)}get isDestroyed(){return d(this,j)}get view(){return d(this,L)}set view(e){e!==d(this,L)&&(e&&N(this,M,fn).call(this),N(this,M,hl).call(this,d(this,L)?.ns),A(this,L,e??void 0),d(this,L)?.ns&&(globalThis.__shadowEnvs??=new Map,globalThis.__shadowEnvs.has(d(this,L).ns)&&globalThis.__shadowEnvs.get(d(this,L).ns)!==this&&this.logger.warn("overwrite a namespace already in use",d(this,L).ns,globalThis.__shadowEnvs.get(d(this,L).ns)),globalThis.__shadowEnvs.set(d(this,L).ns,this)),this.ns$.set(d(this,L)?.ns),this.viewReady=!!e)}get envProxy(){return d(this,ue)}set envProxy(e){if(e!==d(this,ue)){e&&N(this,M,fn).call(this);let t=d(this,ue);A(this,ue,e??void 0);let r=++ol(this,Vt)._;d(this,ue)&&(d(this,ue).onMessageToView=N(this,M,ul).bind(this),d(this,ue).onProxyFailed=N(this,M,dl).bind(this)),t&&(t.destroy(),t.onProxyFailed=void 0,queueMicrotask(()=>{t.onMessageToView=void 0})),this.proxyReady=!1,e?.start().then(()=>{r===d(this,Vt)&&(this.proxyReady=!0)}).catch(i=>{r===d(this,Vt)&&(this.logger.error("failed to start envProxy",i),this.proxyReady=!1)})}}get isReady(){return!!(d(this,L)&&d(this,ue)&&this.proxyReady&&!this.isDestroyed)}sync(){if(!d(this,j)){if(!this.isReady){A(this,wt,!0);return}d(this,vt)||(A(this,vt,!0),queueMicrotask(d(this,pn)))}}syncWait(){return d(this,j)?Promise.reject(new de):(A(this,qt,!0),this.sync(),d(this,et)??A(this,et,N(this,M,cl).call(this)),d(this,et).promise)}async inspect(e={},t){if(d(this,j))throw new de;if(t?.aborted)throw t.reason;let r=d(this,L)?.ns,i=d(this,ue),n={namespace:gu(r),isGlobalNamespace:r===se,kind:yu(i),state:{viewReady:this.viewReady,proxyReady:this.proxyReady,isReady:this.isReady,isDestroyed:d(this,j)}};if(d(this,L))try{n.view=Aa(d(this,L),e)}catch(l){n.error=tl(l)}if(i===void 0||!this.proxyReady)return n;if(typeof i.inspect!="function")return n.error={name:"NotInspectable",message:"the environment proxy does not implement inspect()"},n;let o=t===void 0?void 0:mu(t),a=[i.inspect(e,t),N(this,M,_r).call(this)];o!==void 0&&a.push(o.promise);try{n.kernel=await Promise.race(a)}catch(l){if(d(this,j))throw new de;if(t?.aborted)throw t.reason;n.error===void 0&&(n.error=tl(l))}finally{o?.dispose()}return n}destroy(){var e;d(this,j)||(A(this,j,!0),A(this,vt,!1),A(this,wt,!1),A(this,qt,!1),this.envProxy=void 0,this.view=void 0,(e=d(this,Wr))==null||e.call(this,new de),A(this,et,void 0),d(this,Ht)?.destroy(),A(this,Ht,void 0),ps(this),S(this),Object.freeze(this))}};tt=du(null);L=new WeakMap;ue=new WeakMap;vt=new WeakMap;wt=new WeakMap;qt=new WeakMap;et=new WeakMap;dn=new WeakMap;bn=new WeakMap;En=new WeakMap;j=new WeakMap;Ht=new WeakMap;M=new WeakSet;fn=function(){if(d(this,j)||d(this,Ht)!=null)return;let s=this;te(()=>{A(this,Ht,O(()=>{if(this.viewReady&&this.proxyReady)return this.view.reCreateChanges(),N(this,M,mn).call(this,q.ContextCreated,s),d(this,wt)&&(A(this,wt,!1),N(this,M,Cn).call(this)),()=>{N(this,M,mn).call(this,q.ContextLost,s)}},[Ge(this,"viewReady"),Ge(this,"proxyReady")]))})};hl=function(s){if(!s)return;let e=globalThis.__shadowEnvs;e?.get(s)===this&&e.delete(s)};Vt=new WeakMap;Gt=new WeakMap;Wr=new WeakMap;_r=function(){return d(this,Gt)==null&&(A(this,Gt,new Promise((s,e)=>{A(this,Wr,e)})),d(this,Gt).catch(()=>{})),d(this,Gt)};cl=function(){let s,e,t=new Promise((r,i)=>{s=r,e=i});return{promise:Promise.race([t,N(this,M,_r).call(this)]),resolve:s,reject:e}};pn=new WeakMap;Cn=async function(){if(A(this,vt,!1),d(this,j))return;if(!this.isReady){A(this,wt,!0);return}let s=this.view.buildChangeTrails(!1),e=d(this,et);A(this,et,void 0);let t=d(this,qt);A(this,qt,!1);try{s.length>0&&await this.envProxy.applyChangeTrail(s,t)}catch(r){if(d(this,j))return;this.logger.error("failed to apply change trail",r),N(this,M,gn).call(this,s,r),N(this,M,yn).call(this,s,e,{reason:r});return}d(this,j)||(N(this,M,gn).call(this,s),N(this,M,yn).call(this,s,e))};gn=function(s,e){let t=e instanceof Ke?e.appliedCount:s.length;this.view?.commitChangeTrail(t,s)};mn=function(s,e){try{W(e,s,e)}catch(t){this.logger.error(`a ${s} listener threw`,t)}};yn=function(s,e,t){try{t?(e?.reject(t.reason),W(this,q.SyncFailed,t.reason,s,this)):(e?.resolve(s),W(this,q.AfterSync,s))}catch(r){this.logger.error("a sync cycle listener threw",r)}};ul=function(s){this.logger.debug("onMessageToView",s.type,s.data),this.view?.dispatchMessage(s.uuid,s.type,s.data,s.traverseChildren)};dl=function(s){if(!d(this,j)){this.logger.error("the environment proxy failed",s),++ol(this,Vt)._;try{W(this,q.ProxyFailed,s,this)}finally{this.proxyReady=!1}}};nl(tt,4,"viewReady",ll,q,bn);nl(tt,4,"proxyReady",al,q,En);il(tt,q);q.AfterSync="afterSync";q.SyncFailed="syncFailed";q.ContextLost="contextLost";q.ContextCreated="contextCreated";q.ProxyFailed="proxyFailed";F=q});function Cl(){let e=globalThis.document?.modelContext;if(El(e))return e;let r=globalThis.navigator?.modelContext;if(El(r))return r}var El,kl=f(()=>{"use strict";El=s=>typeof s=="object"&&s!==null&&typeof s.registerTool=="function"});function xl(s,e){for(let t of s.kernel?.roots??[])Tn(t,e);for(let t of s.view?.roots??[])Tn(t,e);return s}var Sl,Tn,On=f(()=>{"use strict";Sl=s=>{if(s===void 0)return;if(typeof s=="function")return s;let e=new Set(s);return t=>e.has(t)},Tn=(s,e)=>{for(let t of s.props??[])e(t.name,s.uuid)&&(t.value={$type:"redacted"});for(let t of s.children??[])Tn(t,e)}});var Ou,Pu,Tl,Ru,Ol,rt,J,Pn,Al,Pl,Ee,Mu,Nu,Ce,ke,Se,bt,it,xe,Et=f(()=>{"use strict";V();Fr();On();Ou=Object.freeze({readOnlyHint:!0,untrustedContentHint:!0}),Pu=s=>typeof s=="symbol"?s.description??"":s,Tl=Pu(se),Ru=s=>s===Tl?se:s,Ol=s=>{if(s===void 0)return;if(typeof s=="function")return s;let e=new Set(s);return t=>e.has(t)},rt=Object.freeze({type:"string",description:`The namespace of one Shadow Environment, as the list-envs tool reports it; the global namespace is "${Tl}". Without it, every environment answers.`}),J=class extends Error{constructor(){super(...arguments),this.name="ToolError"}},Pn=class{#e;constructor(e){this.#e=typeof e=="object"&&e!==null?e:{}}string(e){let t=this.#e[e];if(t!=null){if(typeof t!="string")throw new J(`"${e}" must be a string`);return t}}requiredString(e){let t=this.string(e);if(t===void 0||t==="")throw new J(`"${e}" is required`);return t}number(e){let t=this.#e[e];if(t!=null){if(typeof t!="number"||Number.isNaN(t))throw new J(`"${e}" must be a number`);return t}}stringList(e){let t=this.#e[e];if(t!=null){if(!Array.isArray(t)||!t.every(r=>typeof r=="string"))throw new J(`"${e}" must be a list of strings`);return t}}},Al=["props","shadowObjects","contexts","registry"],Pl=s=>{let e=s.stringList("include");if(e!==void 0){for(let t of e)if(!Al.includes(t))throw new J(`"include" knows only ${Al.join(", ")}; got "${t}"`);return e}},Ee=(s,e)=>({content:[{type:"text",text:`${s}
|
|
45
22
|
|
|
46
|
-
@spearwolf/signalize/dist/signalize.DjCVnTTt.js:
|
|
47
|
-
@spearwolf/signalize/dist/index.js:
|
|
48
|
-
@spearwolf/signalize/dist/decorators.js:
|
|
49
|
-
(*!
|
|
50
|
-
@file @spearwolf/signalize - signals and effects for all
|
|
51
|
-
@author Wolfger Schramm <wolfger@spearwolf.de>
|
|
52
|
-
@version 0.30.0+esm.20260520
|
|
53
|
-
|
|
54
|
-
Copyright 2022-2026 Wolfger Schramm
|
|
55
|
-
|
|
56
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
57
|
-
you may not use this file except in compliance with the License.
|
|
58
|
-
You may obtain a copy of the License at
|
|
59
|
-
|
|
60
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
61
|
-
|
|
62
|
-
Unless required by applicable law or agreed to in writing, software
|
|
63
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
64
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
65
|
-
See the License for the specific language governing permissions and
|
|
66
|
-
limitations under the License.
|
|
67
|
-
|
|
68
|
-
*)
|
|
69
|
-
*/
|
|
70
|
-
`)}var nr=()=>new js;var ft=(s,e,t=1e3,i,r)=>new Promise((n,o)=>{if(r?.aborted){o(r.reason);return}let a,f,m=()=>{clearTimeout(a),s.removeEventListener("message",f),r?.removeEventListener("abort",P)};function P(){m(),o(r.reason)}t!==0&&t!==1/0&&(a=setTimeout(()=>{m(),o(new Error(`Timeout waiting for message of type: ${e}`))},t)),f=c=>{if(c.data.type===e)try{(!i||i(c.data))&&(m(),n())}catch(D){m(),o(D)}},r?.addEventListener("abort",P,{once:!0}),s.addEventListener("message",f)});var un=s=>{let e;if(s!=null&&Array.isArray(s))for(let t of s)t.transferables&&(e?e=[...e,...t.transferables]:e=t.transferables,delete t.transferables);return e},zs=class extends Error{constructor(e,t,i){super(t,i),this.name="WorkerFailedError",this.type=e}},Le=class extends Error{constructor(e="the worker environment has been destroyed"){super(e),this.name="WorkerDestroyedError"}},Kt=class s{constructor(){this.#t=!1,this.#s=0,this.#i=new AbortController,this.logger=new N("RemoteWorkerEnv"),Y(this,s.WorkerLoaded),Y(this,s.WorkerFailed)}static{this.WorkerLoaded="workerLoaded"}static{this.WorkerFailed="workerFailed"}#e;#t;#s;#i;get isDestroyed(){return this.#t}get workerLoaded(){let{signal:e}=this.#i;return e.aborted?Promise.reject(e.reason):new Promise((t,i)=>{let r,n=!1,o=()=>{n||(n=!0,r?.(),i(e.reason))};r=C(this,s.WorkerLoaded,a=>{n||(n=!0,e.removeEventListener("abort",o),t(a))}),!n&&e.addEventListener("abort",o,{once:!0})})}async start(){let{signal:e}=this.#i;if(e.aborted)throw e.reason;if(this.#t)throw new Le;if(this.#e)return this.logger.isWarn&&this.logger.warn("already started"),this.workerLoaded.then(()=>{if(this.isDestroyed)throw new Le});let t=this.#e=nr();t.addEventListener("error",this.onWorkerError.bind(this)),t.addEventListener("messageerror",this.onWorkerMessageError.bind(this)),this.configureConsoleLogger(t);try{if(await ft(t,bi,Si,void 0,e),this.isDestroyed)throw new Le;t.addEventListener("message",this.onMessageFromWorker.bind(this)),queueMicrotask(()=>{g(this,s.WorkerLoaded,this)})}catch(i){throw i!==e.reason&&this.logger.error("failed to start",i),this.#e=void 0,this.#t||t.terminate(),i}}applyChangeTrail(e,t){let{signal:i}=this.#i;if(i.aborted)return Promise.reject(i.reason);let r=this.#e;if(r==null)return Promise.reject(new Le);let n=un(e),o={type:vi,changeTrail:e},a=++this.#s;return t&&(o.serial=a),r.postMessage(o,n??[]),t?ft(r,wi,Ai,f=>{if(f.error)throw f.error;return f.serial===a},i):Promise.resolve()}importScript(e){let{signal:t}=this.#i;if(t.aborted)return Promise.reject(t.reason);let i=this.#e;return i==null?Promise.reject(new Le):(e=Ht(e),i.postMessage({type:yi,importModule:e}),ft(i,Ei,ki,r=>{if(r.error)throw r.error;return r.url===e},t))}destroy(){if(!this.#e)return;let e=this.#e;this.#e=void 0,this.#t=!0,e.postMessage({type:mi}),ft(e,Ci,Pi).finally(()=>{e.terminate()})}onWorkerError(e){this.handleWorkerFailure("error",e,e.message||"the worker reported an error")}onWorkerMessageError(e){this.handleWorkerFailure("messageerror",e,"the worker sent a message that could not be deserialized")}handleWorkerFailure(e,t,i){if(this.#t)return;this.#t=!0;let r=new zs(e,i,{cause:e==="error"?t.error??t:t});this.logger.error(i,t);let n=this.#e;this.#e=void 0,this.#i.abort(r),n?.terminate();try{this.onProxyFailed?.(r)}catch(o){this.logger.error("the proxy-failed callback threw",o)}g(this,s.WorkerFailed,{env:this,type:e,message:i,reason:r,event:t})}onMessageFromWorker(e){e.data?.type===$e?this.onMessageToView?.(e.data.data):this.logger.isDebug&&this.logger.debug("message from worker",e)}configureConsoleLogger(e){let t=`${V}.RemoteWorkerEnv.workerConfig`,i=JSON.parse(localStorage.getItem(t)??"{}");this.logger.isInfo&&this.logger.info("load console-logger worker config",{localStorageKey:t,workerConfig:i}),e.postMessage({type:V,config:{...N.sharedConfig,enable:this.logger.isEnabled,...i,...N.isEnabled?{}:{enable:!1}}})}};var Yt=class s extends be{constructor(){super(),this.isShaeWorkerElement=!0,this.shadowEnv=new B,this.logger=new N("ShaeWorkerElement"),this.autostart=!0,this.isConnected$=y(!1),this.autoSync$=y(s.DefaultAutoSync),this.src$=y(""),this.#e=!1,this.#t=!1,this.#a=e=>{e instanceof me||this.logger.error("shadowEnv failed",e)},this.ns$.onChange(e=>{this.shadowEnv.view=I.get(e)}),b(this.shadowEnv,B.ContextCreated,()=>{this.#r?.run(),this.dispatchEvent(new CustomEvent(B.ContextCreated.toLowerCase(),{bubbles:!1,detail:{shadowEnv:this.shadowEnv}}))}),b(this.shadowEnv,B.ContextLost,()=>{this.dispatchEvent(new CustomEvent(B.ContextLost.toLowerCase(),{bubbles:!1,detail:{shadowEnv:this.shadowEnv}}))}),b(this.shadowEnv,B.ProxyFailed,e=>{this.dispatchEvent(new CustomEvent(B.ProxyFailed.toLowerCase(),{bubbles:!1,detail:{shadowEnv:this.shadowEnv,reason:e}}))}),this.autoSync$.onChange(e=>{let t=this.hasAttribute(H),i=t?this.getAttribute(H):void 0;e===s.DefaultAutoSync?t&&i!==e&&this.setAttribute(H,e):i!==e&&this.setAttribute(H,e)}),this.#h(),this.#n(),this.style.display="contents"}static{this.observedAttributes=[...be.observedAttributes,vt,"src",mt,H]}static{this.DefaultAutoSync="frame"}#e;#t;#s;#i;#r;#n(){this.#r=S(()=>{let e=this.src$.get();e&&this.importScript(e).catch(this.#a)},{autorun:!1})}#a;get shouldAutostart(){return this.autostart&&!at(this,Bs)}get autoSync(){return this.autoSync$.value}set autoSync(e){typeof e!="string"&&(e=e?s.DefaultAutoSync:"no"),this.autoSync$.set(`${e}`.trim().toLowerCase())}get frameLoop(){return this.#s??=new ht,this.#s}[ht.OnFrame](){this.syncShadowObjects()}async importScript(e){if(!e)throw new Error("src is blank");let t=await this.shadowEnv.ready();this.logger.isInfo&&this.logger.info("shadowEnv importScript:",e,{shadowEnv:t});let i=t.envProxy;if(i==null)throw new me;return await i.importScript(e),this}connectedCallback(){W(()=>{let e=this.getAttribute(H);e!=null&&this.autoSync$.set(e),this.isConnected$.set(!0)}),this.shouldAutostart&&this.start().catch(this.#a)}disconnectedCallback(){this.isConnected$.set(!1),this.#o()}attributeChangedCallback(e){if(super.attributeChangedCallback(e),e===vt&&this.shadowEnv.envProxy!=null)throw new Error('Changing the "local" attribute after the shadowEnv has been created is not supported.');if(e===mt&&this.#l(),e===H&&(this.autoSync=this.hasAttribute(H)?this.getAttribute(H):!0),e==="src"){let t=(this.getAttribute("src")||"").trim();this.src$.set(t),this.shadowEnv.isReady&&this.#r?.run()}}start(){if(!this.#t){if(this.#e=!1,this.shadowEnv.view??=I.get(this.ns),this.shadowEnv.envProxy==null){let e=at(this,vt)?new Qt:new Kt;this.shadowEnv.envProxy=e,this.#l()}this.#t=!0}return this.shadowEnv.ready()}destroy(){this.#i?.destroy(),this.#r?.destroy(),M(this.isConnected$,this.autoSync$,this.src$),this.shadowEnv.envProxy=void 0,this.shadowEnv.destroy()}#o(){this.#e||(this.#e=!0,queueMicrotask(()=>{this.#e&&this.destroy()}))}#h(){this.#i=S(()=>{if(this.isConnected$.get()){let e=(this.autoSync$.get()||s.DefaultAutoSync).trim().toLowerCase(),t;if(["true","yes","on","frame","auto-sync"].includes(e))return this.logger.isDebug&&this.logger.debug("auto-sync",e,this),this.frameLoop.start(this),()=>{this.frameLoop.stop(this)};if(e.toLowerCase().endsWith("fps")){let i=parseInt(e,10);i>0?t=Math.floor(1e3/i):this.logger.isWarn&&this.logger.warn(`invalid auto-sync value: ${e}`)}else t=parseInt(e,10),isNaN(t)&&(t=void 0,["false","no","off"].includes(e)||this.logger.error(`invalid auto-sync value: ${e}`));if(t!==void 0&&t>0){this.logger.isDebug&&this.logger.debug("auto-sync interval (ms)",t,this);let i=setInterval(()=>{this.syncShadowObjects()},t);return()=>{clearInterval(i)}}else this.logger.isDebug&&this.logger.debug("auto-sync off",this)}},[this.autoSync$,this.isConnected$])}#l(){let e=this.shadowEnv.envProxy;e?.isLocalEnv&&(e.disableStructuredClone=this.hasAttribute(mt))}};customElements.define(Us,Yt);globalThis.SHADOW_ENTS_BUNDLE_LOADED=!0;
|
|
23
|
+
${JSON.stringify(e)}`}],structuredContent:e}),Mu=s=>({content:[{type:"text",text:s}],isError:!0}),Nu=s=>s instanceof J?s.message:s instanceof Error?`${s.name}: ${s.message}`:String(s),Ce=s=>async(e,t)=>{let r=t?.signal;try{return await s(new Pn(e),r)}catch(i){if(r?.aborted)throw i;return Mu(Nu(i))}},ke=(s,e)=>{let t={...s,...e};return(s.values!==void 0||e.values!==void 0)&&(t.values={...s.values,...e.values}),t},Se=async(s,e,t,r)=>{let i=r.isExposed,n=r.redact,o;if(s===void 0)o=await F.inspectAll(e,t,i);else{let a=Ru(s),l=i===void 0||i(a)?F.get(a):void 0;if(l===void 0)throw new J(`no Shadow Environment holds the namespace "${s}"`);o=[await l.inspect(e,t)]}if(n!==void 0)for(let a of o)xl(a,n);return o},bt=s=>{let e=[s.kind,s.state.isReady?"ready":"not ready"];return s.kernel!==void 0&&e.push(`${s.kernel.counts.entities} entities`),s.error!==void 0&&e.push(`error: ${s.error.name}: ${s.error.message}`),`${s.namespace} (${e.join(", ")})`},it="no Shadow Environment holds a namespace",xe=(s,e,t)=>({name:`${s.prefix}${e}`,annotations:{...Ou},...t})});var Rl,Ml=f(()=>{"use strict";Et();Rl=s=>xe(s,"find-entities",{title:"Find Entities",description:"Search the Entity Tree of one Shadow Environment, or of every one, so that the answer stays small: every Entity that meets all given criteria, as uuid, token and the token path from the root. At least one criterion. The search runs where the Kernel runs and ships the matches, not the tree.",inputSchema:{type:"object",properties:{namespace:rt,token:{type:"string",description:"The token of the Entity, exact."},propName:{type:"string",description:"A property name the Entity carries."},shadowObject:{type:"string",description:"The display name of a Shadow Object attached to the Entity."},contextName:{type:"string",description:"A string Entity Context name the Entity uses or provides."},limit:{type:"integer",minimum:1,description:"How many matches to carry. Default 50; total counts every match regardless."}},additionalProperties:!1},execute:Ce(async(e,t)=>{let r={},i=e.string("token");i!==void 0&&(r.token=i);let n=e.string("propName");n!==void 0&&(r.propName=n);let o=e.string("shadowObject");o!==void 0&&(r.shadowObject=o);let a=e.string("contextName");a!==void 0&&(r.contextName=a);let l=e.number("limit");if(l!==void 0&&(r.limit=l),i===void 0&&n===void 0&&o===void 0&&a===void 0)throw new J("at least one of token, propName, shadowObject, contextName is required");let u=(await Se(e.string("namespace"),ke(s.limits,{filter:r,maxDepth:0,maxNodes:1,include:[]}),t,s)).map(g=>{let p={namespace:g.namespace,matches:g.kernel?.search?.matches??[],total:g.kernel?.search?.total??0};return g.error!==void 0&&(p.error=g.error),p}),c=u.map(g=>{let p=g.matches.length<g.total?`, ${g.matches.length} carried`:"",H=g.error===void 0?"":` (error: ${g.error.name}: ${g.error.message})`;return`${g.namespace}: ${g.total} match${g.total===1?"":"es"}${p}${H}`}).join("; ");return Ee(c||it,{results:u})})})});var Nl,$l=f(()=>{"use strict";Et();Nl=s=>xe(s,"get-entity",{title:"Get Entity",description:"One Entity in full -- token, properties, Shadow Objects, Entity Contexts, its children one level down -- with the chain of ancestors above it and the View's component of the same uuid next to it, which is where a divergence between View and Kernel becomes visible. Without a namespace every environment is asked; a uuid held in more than one comes back once per environment.",inputSchema:{type:"object",properties:{uuid:{type:"string",description:"The uuid of the Entity, as the tree and the search report it."},namespace:rt},required:["uuid"],additionalProperties:!1},execute:Ce(async(e,t)=>{let r=e.requiredString("uuid"),i=await Se(e.string("namespace"),ke(s.limits,{rootUuids:[r],maxDepth:1}),t,s),n=[];for(let l of i){let h=l.kernel?.roots[0];if(h===void 0)continue;let{ancestors:u=[],...c}=h,g={namespace:l.namespace,entity:c,ancestors:u},p=l.view?.roots[0];p!==void 0&&(g.view=p),l.kernel?.truncation!==void 0&&(g.truncation=l.kernel.truncation),n.push(g)}if(n.length===0){let l=i.filter(h=>h.error!==void 0).map(bt);throw new J(`no Shadow Environment holds an Entity "${r}"${l.length>0?` (${l.join("; ")})`:""}`)}let o=[];for(let l of i)l.error!==void 0&&o.push({namespace:l.namespace,error:l.error});let a=n.map(l=>{let h=l.ancestors.length===0?"a root":`under ${l.ancestors.map(u=>u.token).join(" > ")}`;return`${l.namespace}: ${l.entity.token} "${l.entity.uuid}", ${h}, ${l.entity.childCount} children`}).join("; ");return o.length>0&&(a+=`; failed: ${o.map(l=>`${l.namespace} (${l.error.name}: ${l.error.message})`).join(", ")}`),Ee(a,o.length>0?{matches:n,errors:o}:{matches:n})})})});var Dl,Ll=f(()=>{"use strict";Et();Dl=s=>xe(s,"get-entity-tree",{title:"Get Entity Tree",description:"The Entity Tree of one Shadow Environment, or of every one: per Entity its token, properties, Shadow Objects and Entity Contexts, next to the View's component tree of the same namespace. A cut walk carries truncation notes naming the uuids where it stopped; descend from there with rootUuid.",inputSchema:{type:"object",properties:{namespace:rt,rootUuid:{type:"string",description:"Descend from this Entity instead of the roots."},maxDepth:{type:"integer",minimum:0,description:"Tree depth below each root that is walked. Default 4."},maxNodes:{type:"integer",minimum:1,description:"Total number of Entities across the walk. Default 250."},include:{type:"array",items:{type:"string",enum:["props","shadowObjects","contexts","registry"]},description:"What to carry per Entity. Default: all four."},valueDepth:{type:"integer",minimum:0,description:"How deep nested property and context values are followed. Default 3."}},additionalProperties:!1},execute:Ce(async(e,t)=>{let r={},i=e.string("rootUuid");i!==void 0&&(r.rootUuids=[i]);let n=e.number("maxDepth");n!==void 0&&(r.maxDepth=n);let o=e.number("maxNodes");o!==void 0&&(r.maxNodes=o);let a=Pl(e);a!==void 0&&(r.include=a);let l=e.number("valueDepth");l!==void 0&&(r.values={maxDepth:l});let h=await Se(e.string("namespace"),ke(s.limits,r),t,s),u=h.map(c=>{let g=c.kernel?.truncation?.length??0;return g===0?bt(c):`${bt(c)}, ${g} truncation note${g===1?"":"s"}`}).join("; ");return Ee(u||it,{envs:h})})})});var zl,jl=f(()=>{"use strict";Et();zl=s=>xe(s,"get-registry",{title:"Get Registry",description:"The composition rules of one Shadow Environment, or of every one: which Shadow Objects each token defines, which tokens a token routes to, and which property routes exist. The answer to why a Shadow Object is, or is not, on an Entity.",inputSchema:{type:"object",properties:{namespace:rt},additionalProperties:!1},execute:Ce(async(e,t)=>{let i=(await Se(e.string("namespace"),ke(s.limits,{maxDepth:0,maxNodes:1,include:["registry"]}),t,s)).map(o=>{let a={namespace:o.namespace,kind:o.kind};return o.kernel?.registry!==void 0&&(a.registry=o.kernel.registry),o.error!==void 0&&(a.error=o.error),a}),n=i.map(o=>{if(o.registry===void 0)return`${o.namespace}: no registry${o.error===void 0?"":` (error: ${o.error.name}: ${o.error.message})`}`;let{tokens:a,routes:l,propRoutes:h,isDefault:u}=o.registry;return`${o.namespace}: ${Object.keys(a).length} tokens, ${Object.keys(l).length} routes, ${Object.keys(h).length} property routes${u?", the default registry":""}`}).join("; ");return Ee(n||it,{registries:i})})})});var $u,Wl,_l=f(()=>{"use strict";Et();$u=s=>{let e={namespace:s.namespace,isGlobalNamespace:s.isGlobalNamespace,kind:s.kind,state:s.state};return s.view!==void 0&&(e.view={takenAt:s.view.takenAt,counts:s.view.counts}),s.kernel!==void 0&&(e.kernel={takenAt:s.kernel.takenAt,thread:s.kernel.thread,counts:s.kernel.counts}),s.error!==void 0&&(e.error=s.error),e},Wl=s=>xe(s,"list-envs",{title:"List Shadow Environments",description:"Every Shadow Environment on the page: its namespace, kind (local, worker, custom, none), state, and the counts of View components and Kernel Entities. Carries no tree. The cheapest call and the one to make first; every other tool takes a namespace from this list.",inputSchema:{type:"object",properties:{},additionalProperties:!1},execute:Ce(async(e,t)=>{let r=await Se(void 0,ke(s.limits,{maxDepth:0,maxNodes:1,include:[]}),t,s),i=r.map($u),n=i.length===0?it:`${i.length} Shadow Environment${i.length===1?"":"s"}: ${r.map(bt).join("; ")}`;return Ee(n,{envs:i})})})});var Fl,Il=f(()=>{"use strict";Ml();$l();Ll();jl();_l();Fl=s=>[Wl(s),Dl(s),Nl(s),Rl(s),zl(s)]});function Ul(s,e,t,r){let i=Rn.get(s);i===void 0&&(i=new Map,Rn.set(s,i));let n=i.get(e);n===void 0?(n=ju(s,e,r),i.set(e,n)):Wu(n.settings,r)||Mn.warn(`the tools under "${e}" are already registered with other limits or exposedTo; the values of the first call apply`,{inEffect:n.settings,ignored:r});let o=n;o.members.add(t);let a=!1;return{tools:o.tools,leave(){a||(a=!0,o.members.delete(t),o.members.size===0&&Bl(s,e,o))}}}var Rn,Mn,Du,Lu,zu,ju,Bl,Wu,Vl=f(()=>{"use strict";Q();On();Et();Il();Rn=new WeakMap,Mn=new E("ModelContext"),Du=s=>{let e=[];for(let t of s){let r=Ol(t.namespaces);if(r===void 0)return;e.push(r)}return t=>e.some(r=>r(t))},Lu=s=>{let e=[];for(let t of s){let r=Sl(t.redactProps);r!==void 0&&e.push(r)}if(e.length!==0)return(t,r)=>e.some(i=>i(t,r))},zu=async(s,e,t)=>{let{controller:r,settings:i}=t,n={signal:r.signal};i.exposedTo!==void 0&&(n.exposedTo=i.exposedTo);let o=[];try{for(let a of Fl(e)){if(r.signal.aborted)break;await s.registerTool(a,n),o.push(a.name)}}catch(a){throw r.abort(a),Mn.error("registering the tools failed",a),a}return r.signal.aborted?[]:(Mn.info(`registered ${o.length} tools`,o),o)},ju=(s,e,t)=>{let r=new Set,i={members:r,controller:new AbortController,settings:t,tools:Promise.resolve([]),closed:!1},n={prefix:e,limits:t.limits,get isExposed(){return Du(r)},get redact(){return Lu(r)}};return i.tools=zu(s,n,i),i.tools.catch(()=>Bl(s,e,i)),i},Bl=(s,e,t)=>{if(t.closed)return;t.closed=!0,t.controller.abort();let r=Rn.get(s);r?.get(e)===t&&r.delete(e)},Wu=(s,e)=>JSON.stringify(s.limits)===JSON.stringify(e.limits)&&JSON.stringify(s.exposedTo)===JSON.stringify(e.exposedTo)});var ql={};Ql(ql,{DefaultToolPrefix:()=>Gl,exposeShadowEnvsToModelContext:()=>_u});async function _u(s={}){let e=s.modelContext??Cl();if(e===void 0)return new E("ModelContext").info("no model context on this platform, nothing registered"),{available:!1,tools:[],dispose(){}};let{signal:t}=s;if(t?.aborted)return{available:!0,tools:[],dispose(){}};let r={limits:s.limits??{},...s.exposedTo!==void 0?{exposedTo:s.exposedTo}:{}},i=Ul(e,s.toolPrefix??Gl,{namespaces:s.namespaces,redactProps:s.redactProps},r),n=()=>{i.leave(),t?.removeEventListener("abort",n)};t?.addEventListener("abort",n,{once:!0});try{return{available:!0,tools:await i.tools,dispose:n}}catch(o){throw n(),o}}var Gl,Hl=f(()=>{"use strict";Q();kl();Vl();Gl="shae-"});Te();B();K();V();var vs=new Set(["on","true","yes","local","1"]);lr();var Zo=s=>ft(s.getAttribute("ns")??void 0),Le=(s,e)=>{if(s.hasAttribute(e)){let t=s.getAttribute(e)?.trim()?.toLowerCase()||"1";return vs.has(t)}return!1},ea=(s,e)=>s.hasAttribute(e)?Number(s.getAttribute(e)):void 0,ta=(s,e)=>(s.getAttribute(e)??"").split(/[\s,]+/).filter(t=>t.length>0);Q();var $t=class{#e=!1;#t;constructor(e){this.#t=e}schedule(){this.#e||(this.#e=!0,queueMicrotask(()=>{this.#e=!1,this.#t()}))}};gt();B();V();Q();var pa=16,da=s=>{s[6]=s[6]&15|64,s[8]=s[8]&63|128;let e=Array.from(s,t=>t.toString(16).padStart(2,"0")).join("");return`${e.slice(0,8)}-${e.slice(8,12)}-${e.slice(12,16)}-${e.slice(16,20)}-${e.slice(20)}`},fa=!1,Lc=()=>{fa||(fa=!0,new E("generateUUID").error("no Web Crypto API in this realm: entity uuids come from Math.random() and are not unguessable"));let s=new Uint8Array(pa);for(let e=0;e<s.length;e++)s[e]=Math.random()*256|0;return s},ga=()=>{let s=globalThis.crypto;return typeof s?.randomUUID=="function"?s.randomUUID():typeof s?.getRandomValues=="function"?da(s.getRandomValues(new Uint8Array(pa))):da(Lc())};gt();var mt=class extends Error{constructor(e){super(e),this.name="ViewComponentError"}};function ma(s,e){if(s.context==null)throw new mt("cannot add a child to a destroyed view component");if(s.context!==e)throw new mt("cannot add a child from another context");if(!e.hasComponent(s))throw new mt("cannot add a child to a view component its context does not hold")}var ks=class s{static{this.Destroyed="view-component-destroyed"}#e;#t;#s;#i;#r=0;#n;get uuid(){return this.#e}get token(){return this.#t}set token(e){e??=U,e!==this.#t&&(this.#t=e,this.#s?.changeToken(this,e))}get parent(){return this.#i}set parent(e){e?e.addChild(this):this.removeFromParent()}get context(){return this.#s}set context(e){let t=e??void 0;if(this.#s===t)return;if(t?.isDisposed)throw new Cs(`the view component ${this.#e} cannot join the component context because it has been disposed`);let r=this.#s;this.#s&&this.#o(),this.#s=t;try{t?.addComponent(this)}catch(i){throw this.#s=void 0,i}t!=null&&r!=null&&r.transferPropertiesTo(this,t)}get isDestroyed(){return this.#s==null}get order(){return this.#r}set order(e){let t=this.#r;this.#r=e??0,t!==this.#r&&this.#s?.changeOrder(this)}get autoDestructionOnParentRemoval(){return this.#n}constructor(e,t){$(this),t instanceof s&&(t={parent:t}),this.#e=t?.uuid??ga(),this.#t=e??U,this.#r=t?.order??0,this.#i=t?.parent,this.#n=t?.autoDestructionOnParentRemoval??!1;let r=t?.context??P.get();this.#i&&ma(this.#i,r),this.context=r}isChildOf(e){return this.#i===e}removeFromParent(){this.#i?(this.#s?.removeFromParent(this,this.#i),this.#i=void 0):this.#s?.moveToRoot(this)}addChild(e){if(e.#s==null)throw new mt("cannot add a destroyed view component as a child");ma(this,e.#s);for(let t=this;t!=null;t=t.#i)if(t===e)throw new mt("cannot add the component itself or one of its ancestors as a child: this would create a cycle");e.isChildOf(this)||(e.removeFromParent(),e.#i=this,this.#s.addToChildren(this,e))}setProperty(e,t,r){return this.#s?.setProperty(this,e,t,r)??!1}setPropertyWithoutValue(e){return this.#s?.setPropertyWithoutValue(this,e)??!1}removeProperty(e){this.#s?.removeProperty(this,e)}dispatchShadowObjectsEvent(e,t,r){this.#s?.dispatchShadowObjectsEvent(this,e,t,r)}dispatchEvent(e,t,r){if(me(this,e,t),r)for(let i of this.#s?.getChildren(this)??[])i.dispatchEvent(e,t,r)}#o(){this.removeFromParent();let e=this.#s;this.#s=void 0,e?.destroyComponent(this)}destroy(){this.#o(),Object.hasOwn(this,"dispatchEvent")&&delete this.dispatchEvent,me(this,s.Destroyed),S(this)}};Te();gt();var _i=s=>s instanceof Set&&s.size===0,ya=(s,e)=>{if(s===e)return!0;if(s instanceof Set&&e instanceof Set){if(s.size!==e.size)return!1;for(let t of s)if(!e.has(t))return!1;return!0}return!1},va=(s,e,t)=>{if(!t||_i(t))return;let r=Object.hasOwn(s,"dispatchEvent")?Object.getPrototypeOf(s).dispatchEvent:s.dispatchEvent,i=t instanceof Set?t:void 0,n=(o,a,l)=>{r.call(s,o,a,l),!(o===P.ReRequestParentRoots||o===P.ReRequestParent||o===P.ReRequestEntHost)&&(i&&!i.has(o)||e.dispatchEvent(new CustomEvent(o,{bubbles:!0,composed:!0,detail:a})))};return Object.defineProperty(s,"dispatchEvent",{value:n,writable:!0,configurable:!0}),()=>{Object.hasOwn(s,"dispatchEvent")&&s.dispatchEvent===n&&delete s.dispatchEvent}};gt();var Ss=new WeakMap,wa=new WeakSet,ba=s=>{if(!wa.has(s)){wa.add(s);for(let e of P.getContextsMap().values())e.broadcastEvent(P.ReRequestParent),e.broadcastEvent(P.ReRequestEntHost)}},gr=class{#e;#t=new Set;constructor(e){this.#e=e}#s(e){for(let t=e.parentElement;t!=null;t=t.parentElement){if(t===this.#e)return!0;if(t.isShaeEntElement)return!1}return!1}#i(e){for(let t of this.#t){let r=t.deref();if(r===void 0)this.#t.delete(t);else if(r===e)return}this.#t.add(new WeakRef(e)),e.addEventListener("slotchange",this.#n,{capture:!1,passive:!1})}#r(e){e.removeEventListener("slotchange",this.#n,{capture:!1});for(let t of this.#t){let r=t.deref();(r===void 0||r===e)&&this.#t.delete(t)}}#n=e=>{let t=e.currentTarget;this.#s(t)||(this.#r(t),Ss.get(t)?.deref()===this.#e&&Ss.set(t,null),ba(e))};collect(){if(this.#e.findShadowRootHost()!=null)for(let e of this.#e.querySelectorAll("slot"))e.assignedNodes().length!==0&&this.#s(e)&&(Ss.set(e,new WeakRef(this.#e)),this.#i(e))}takeUp(e){let t=e.target;if(this.#s(t)){let r=Ss.get(t);Ss.set(t,new WeakRef(this.#e)),this.#i(t),r!==void 0&&r?.deref()!==this.#e&&ba(e)}}releaseAll(){for(let e of this.#t)e.deref()?.removeEventListener("slotchange",this.#n,{capture:!1});this.#t.clear()}};var yt=new WeakMap,Ea=(s,e)=>{let t=[];for(let{removedNodes:r}of e)for(let i of r){let n=s.watchers.get(i);n!=null&&(s.watchers.delete(i),t.push(n))}for(let r of t)try{r()}catch(i){console.error("a removal watcher failed:",i)}},zc=s=>{let e=new Map,t={observer:new MutationObserver((r,i)=>{Ea(t,r),e.size===0&&(i.disconnect(),yt.get(s)===t&&yt.delete(s))}),watchers:e};return t.observer.observe(s,{childList:!0,subtree:!1,attributes:!1}),t},Ca=(s,e,t)=>{let r=yt.get(s);r!=null&&(Ea(r,r.observer.takeRecords()),r=yt.get(s)),r==null&&(r=zc(s),yt.set(s,r)),r.watchers.set(e,t)},Fi=(s,e)=>{let t=yt.get(s);t!=null&&t.watchers.delete(e)&&t.watchers.size===0&&(t.observer.disconnect(),yt.delete(s))};Te();var mr=(s,e)=>{s.dispatchEvent(new CustomEvent(Xt,{bubbles:!0,composed:!0,detail:{...e,requester:s}}))};K();V();Q();dr();Dt();lr();Fr();K();var Ir=class{#e;#t=!1;#s=!1;constructor(e){this.#e=e}schedule(){this.#t=!0,!this.#s&&(this.#s=!0,queueMicrotask(()=>{this.#s=!1,this.#t&&(this.#t=!1,this.#e())}))}cancel(){this.#t=!1}};var fl=new WeakMap,pl=s=>`${Array.from(s,e=>CSS.escape(e)).join(",")}{display:contents}`,vu=s=>s.nodeType===9,wu=s=>s.nodeType===11&&s.host!=null,Br=(s,e)=>{let t,r,i;if(vu(s))t=s.head??s.documentElement??s,r=s,i=s;else if(wu(s))t=s,r=s.ownerDocument,i=s;else return;let n=fl.get(i);if(n?.style.isConnected){if(n.tags.has(e))return;n.tags.add(e),n.style.textContent=pl(n.tags);return}let o=n?.tags??new Set;o.add(e);let a=r.createElement("style");a.textContent=pl(o),t.prepend(a),fl.set(i,{tags:o,style:a})};var Kt=class extends HTMLElement{#e=!1;#t=!1;#s=new Ir(()=>this.destroy());get isDestroyed(){return this.#e}connectedCallback(){te(()=>{this.#s.cancel(),this.#e=!1,this.#t||(this.#t=!0,this.restore()),Br(this.getRootNode(),this.localName)})}disconnectedCallback(){this.#s.schedule()}destroy(){this.#e||(this.#e=!0,this.#t=!1,this.teardown())}restore(){}teardown(){}};var gl=(s,e)=>{e.set(Zo(s))},bu=new E("ShaeElement"),Eu=new Ye(s=>{for(let e of s.keys())x(bu,()=>F.get(e)?.sync(),"a namespace could not be synced:",e)}),ml=s=>{Eu.add(s)},st=class extends Kt{constructor(){super(),this.isShaeElement=!0,this.ns$=m(se),this.#e=!1,gl(this,this.ns$)}static{this.observedAttributes=["ns"]}get ns(){return this.ns$.value}set ns(e){typeof e=="symbol"?this.ns$.set(e):this.ns$.set(ft(e))}#e;#t;#s;#i(){this.#s=this.ns$.onChange(e=>this.#r(e))}#r(e){this.reflectAttribute("ns",()=>{typeof e=="string"&&e.length>0?this.getAttribute("ns")!==e&&this.setAttribute("ns",e):this.removeAttribute("ns")})}restore(){super.restore(),this.#i(),this.#r(this.ns$.value)}reflectAttribute(e,t){this.#e?t():(this.#t??=new Map,this.#t.set(e,t))}connectedCallback(){te(()=>{super.connectedCallback(),this.#e=!0;let e=this.#t;if(this.#t=void 0,e)for(let t of e.values())t()})}teardown(){this.#s?.(),this.#s=void 0,super.teardown()}attributeChangedCallback(e){e==="ns"&&gl(this,this.ns$)}syncShadowObjects(){ml(this.ns)}syncShadowObjectsOf(e){ml(e)}};var yl=s=>s.assignedSlot??s.parentNode??s.host??void 0,Cu=(s,e)=>{for(let t=yl(s);t!=null;t=yl(t))if(t===e)return!0;return!1},ku=s=>{for(let e=s.getRootNode();e?.host!=null;e=e.host.getRootNode())if(e.mode==="closed")return!0;return!1},Ur=class extends st{constructor(){super(),this.isShaeEntElement=!0,this.componentContext$=m(),this.viewComponent$=m(),this.token$=m(),this.forwardCustomEvents$=m(!1),this.#e=new E("ShaeEntElement"),this.#t=this.isConnected,this.#i=m(0),this.#r=new $t(()=>{this.#i.set(this.#i.value+1)}),this.#v=e=>{let t=this.token$.value,r=this.viewComponent$.value;try{r?r.context=e:e&&(r=new ks(t??U,{context:e,autoDestructionOnParentRemoval:Le(this,Ln)}),this.viewComponent$.set(r))}catch(i){this.logger.error("applying the component context of this entity failed:",{ns:this.ns,uuid:r?.uuid},i)}this.syncShadowObjects()},this.#k=!0,this.#M=new gr(this),this.#$=e=>{this.#A(),this.#M.takeUp(e);let t=this.findShadowRootHost();t!=null&&this.dispatchEvent(new CustomEvent(zs,{bubbles:!0,composed:!0,detail:{requester:this,shadowRootHost:t}}))},this.#D=e=>{let t=e.detail?.requester;if(t===this||!t?.isShaeEntElement||t.ns!==this.ns)return;e.detail?.shadowRootHost&&this.#O()},this.#L=e=>{let t=e.detail;t?.requester==null||t.requester===this||typeof t.answer=="function"&&(t.ns!==void 0&&t.ns!==this.ns||(e.stopPropagation(),t.answer(this)))},this.#z(),this.#W()}static{this.observedAttributes=[...st.observedAttributes,Ae,ie]}#e;get logger(){return this.#e}get componentContext(){return this.componentContext$.value}get viewComponent(){return this.viewComponent$.value}get uuid(){return this.viewComponent?.uuid}get token(){return this.token$.value}set token(e){this.token$.set(e)}#t;#s;#i;#r;#n;#o;#a;#h;#c;#l;#u(){this.#n=this.ns$.onChange(e=>{let t=this.componentContext,r=t?.ns,i=this.viewComponent;t!=null&&i!=null&&t.dispatchReRequestParentChildren(i),this.#P(void 0),this.componentContext$.set(P.get(e)),this.isConnected&&(this.#O(),this.#E()),r!=null&&r!==e&&this.syncShadowObjectsOf(r)}),this.#o=this.token$.onChange(e=>this.#g(e)),this.#a=this.forwardCustomEvents$.onChange(e=>this.#d(e)),this.#h=O(()=>{let e=this.viewComponent$.get();if(this.#i.get(),!e)return;let t=[y(e,P.ReRequestParentRoots,()=>this.#R()),y(e,P.ReRequestParent,r=>this.#T(r?.newAncestor)),y(e,P.ReRequestEntHost,()=>this.#A()),y(e,ks.Destroyed,()=>this.#r.schedule())];return()=>{for(let r of t)r()}}),this.#c=O(()=>{let e=this.viewComponent$.get();if(this.#i.get(),!!e)return va(e,this,this.forwardCustomEvents$.get())}),this.#l=this.token$.onChange(e=>this.#f(e))}#g(e){this.reflectAttribute(Ae,()=>{e==null?this.removeAttribute(Ae):this.getAttribute(Ae)!==e&&this.setAttribute(Ae,e)})}#d(e){this.reflectAttribute(ie,()=>{if(!e||_i(e))this.removeAttribute(ie);else if(e===!0)this.getAttribute(ie)!==""&&this.setAttribute(ie,"");else{let t=Array.from(e).join(",");this.getAttribute(ie)!==t&&this.setAttribute(ie,t)}})}#f(e){let t=this.viewComponent$.value;t==null||t.token===e||(t.token=e,this.syncShadowObjects())}restore(){super.restore(),this.#u(),this.#g(this.token$.value),this.#d(this.forwardCustomEvents$.value),this.#f(this.token$.value)}#p;#v;#m(){this.#p?.();let e=this.componentContext$.onChange(this.#v);this.#p=()=>{e()}}#y(){this.#p?.(),this.#p=void 0}#w(){return this.getRootNode()?.host}#C;#k;findShadowRootHost(){return this.#k&&(this.#k=!1,this.#C=this.#w()),this.#C}getParentNodeForObserver(){return this.parentNode??this.#w()??void 0}connectedCallback(){te(()=>{super.connectedCallback(),this.#k=!0,this.addEventListener("slotchange",this.#$,{capture:!1,passive:!1}),this.addEventListener(Xt,this.#L,{capture:!1,passive:!1}),this.#m(),fs(()=>this.#z());let e=this.#j();ya(e,this.forwardCustomEvents$.value)||this.forwardCustomEvents$.set(e),this.componentContext==null?this.componentContext$.set(P.get(this.ns)):this.#v(this.componentContext),this.#O(),this.#t&&(this.#E(),this.#A()),this.#M.collect(),this.#S(),this.syncShadowObjects()})}#S(){this.#b();let e=this.getParentNodeForObserver();if(e){Ca(e,this,()=>{this.#s=void 0;let r=this.getParentNodeForObserver();if(r===e){this.#S();return}this.onParentChanged(r,e)});let t=this.getParentNodeForObserver();if(t===e)this.#s=e;else if(Fi(e,this),this.#s==null&&this.isConnected)try{this.onParentChanged(t,e)}catch(r){console.error("a removal watcher failed:",r)}}}#b(){this.#s!=null&&(Fi(this.#s,this),this.#s=void 0)}onParentChanged(e,t){this.#P(void 0),this.#O(),this.#S()}attributeChangedCallback(e){super.attributeChangedCallback(e),e===Ae?this.#z():e===ie&&this.#W()}disconnectedCallback(){this.#k=!0,this.#b(),this.#M.releaseAll(),this.#x(),this.#A(),this.#P(void 0);let e=this.viewComponent;e!=null&&this.componentContext?.dispatchReRequestParentChildren(e),this.componentContext$.set(void 0),this.syncShadowObjects(),this.#y(),super.disconnectedCallback()}teardown(){if(this.#n?.(),this.#n=void 0,this.#o?.(),this.#o=void 0,this.#a?.(),this.#a=void 0,this.#h?.destroy(),this.#h=void 0,this.#c?.destroy(),this.#c=void 0,this.#l?.(),this.#l=void 0,this.#y(),this.#b(),this.#M.releaseAll(),this.#P(void 0),this.isConnected){this.#x(),this.#A();let e=this.viewComponent;e!=null&&this.componentContext?.dispatchReRequestParentChildren(e)}super.teardown()}#x(){this.removeEventListener("slotchange",this.#$,{capture:!1}),this.removeEventListener(Xt,this.#L,{capture:!1})}#R(){this.isConnected&&(this.#P(void 0),this.#O())}#T(e){this.isConnected&&(e?.isConnected&&!Cu(this,e)||this.#O())}#E(){let e=this.viewComponent;if(e==null)return;let t=ku(this)?void 0:this;this.componentContext?.collectPeerReRequest(e,{newAncestor:t})}#A(){this.dispatchEvent(new CustomEvent(Zt,{bubbles:!0,composed:!0,detail:{requester:this}}))}#O(){let e;mr(this,{ns:this.ns,answer:t=>e=t}),this.#P(e)}#N;#P(e){if(this.entParentNode!==e)if(this.entParentNode&&this.entParentNode.removeEventListener(zs,this.#D,{capture:!1}),this.entParentNode=e,this.entParentNode&&this.entParentNode.addEventListener(zs,this.#D,{capture:!1,passive:!1}),this.#N?.(),this.#N=void 0,e){let t=O(()=>{let r=this.viewComponent$.get();if(r){let i=e.viewComponent$.get(),n=r.context;r.parent=n!=null&&i?.context===n?i:void 0,r.parent==null&&queueMicrotask(()=>{this.#O()}),this.syncShadowObjects()}});this.#N=()=>t.destroy()}else{let t=this.viewComponent;t?.parent&&(t.parent=void 0,this.syncShadowObjects())}}#M;#$;#D;#L;#z(){if(this.hasAttribute(Ae)){let e=this.getAttribute(Ae)?.trim()||void 0;this.token$.set(e)}else this.token$.set(void 0)}#j(){if(!this.hasAttribute(ie))return!1;let e=this.getAttribute(ie);if(!e||e.trim().length===0)return!0;let t=new Set(e.split(",").map(r=>r.trim()).filter(r=>r.length>0));return t.size>0?t:!1}#W(){this.forwardCustomEvents$.set(this.#j())}};customElements.define(js,Ur);Te();K();Q();Te();var fe=s=>s.split(/\W+/),$s=s=>s.split(/\s+/),xn=(s,e)=>{if(Number.isNaN(s))throw new TypeError(`not a number: "${e}"`);return s},Sn=s=>e=>xn(s(e),e),Gr=(s,e)=>t=>e(t).map(r=>xn(s(r),r)),Vr=s=>Sn(e=>parseInt(e,s)),kn=s=>Gr(e=>parseInt(e,s),fe),Fe=(s,e)=>t=>new s(e(t).map(r=>xn(Number(r),r))),vl=s=>e=>new s(fe(e).map(t=>BigInt(t))),Su=s=>vs.has(s.toLowerCase()),xu=[[["string","text"],s=>s],[["number"],Sn(Number)],[["bigint"],s=>BigInt(s)],[["float"],Sn(parseFloat)],[["int","integer"],Vr(10)],[["hex","hexadecimal"],Vr(16)],[["oct","octal"],Vr(8)],[["bin","binary"],Vr(2)],[["bool","boolean"],Su],[["[]","text[]","string[]"],fe],[["number[]"],Gr(Number,$s)],[["float[]"],Gr(parseFloat,$s)],[["int[]","integer[]"],Gr(s=>parseInt(s,10),$s)],[["hex[]","hexadecimal[]"],kn(16)],[["oct[]","octal[]"],kn(8)],[["bin[]","binary[]"],kn(2)],[["bool[]","boolean[]"],s=>fe(s).map(e=>vs.has(e.toLowerCase()))],[["int8array"],Fe(Int8Array,fe)],[["uint8array"],Fe(Uint8Array,fe)],[["uint8clampedarray"],Fe(Uint8ClampedArray,fe)],[["int16array"],Fe(Int16Array,fe)],[["uint16array"],Fe(Uint16Array,fe)],[["int32array"],Fe(Int32Array,fe)],[["uint32array"],Fe(Uint32Array,fe)],[["float32array"],Fe(Float32Array,$s)],[["float64array"],Fe(Float64Array,$s)],[["bigint64array"],vl(BigInt64Array)],[["biguint64array"],vl(BigUint64Array)],[["json"],s=>JSON.parse(s)]],An=new Map(xu.flatMap(([s,e])=>s.map(t=>[t,e])));var qr=new WeakMap,Au=(s,e)=>{let t=qr.get(s);t==null&&(t=new Map,qr.set(s,t)),t.set(e,(t.get(e)??0)+1)},Tu=(s,e)=>{let t=qr.get(s);if(t==null)return!0;let r=(t.get(e)??1)-1;return r>0?(t.set(e,r),!1):(t.delete(e),t.size===0&&qr.delete(s),!0)},Hr=class extends Kt{constructor(){super(),this.isShaePropElement=!0,this.entNode$=m(),this.viewComponent$=m(),this.name$=m(),this.valueIn$=m(),this.valueOut$=m(),this.type$=m(),this.shouldTrim$=m(!0),this.#e=new E("ShaePropElement"),this.#n=!1,this.#a=new $t(()=>{this.isConnected&&!this.isDestroyed&&this.#c()}),this.#c=()=>{let e;mr(this,{answer:t=>e=t}),this.entNode$.set(e),e==null&&this.isConnected&&!this.#n&&(this.#n=!0,this.logger.warn(`[${this.name}] no entity above this element, the property is set nowhere`,{shaeProp:this})),this.#u()},this.#l=()=>{this.#a.schedule()},this.#u=()=>{let e=this.entNode$.value??this.ownerDocument;e!==this.#o&&(this.#g(),e.addEventListener(Zt,this.#l),this.#o=e)},this.#g=()=>{this.#o?.removeEventListener(Zt,this.#l),this.#o=void 0},this.#d=()=>{queueMicrotask(()=>{this.isConnected||this.entNode$.set(void 0)})},this.#f=()=>{this.name$.set(this.getAttribute(at)?.trim()??void 0)},this.#p=()=>{let e=this.getAttribute(es);this.valueIn$.set(e===null||e===""?void 0:e)},this.#v=()=>{let e=this.getAttribute(es);return e!==null&&e!==""},this.#m=()=>{let e=this.getAttribute(Fs)?.trim().toLowerCase();e&&!An.has(e)&&(this.logger.warn(`[${this.name}] unknown type "${e}"`,{shaeProp:this}),e=void 0),this.type$.set(e)},this.#y=()=>{this.shouldTrim$.set(!Le(this,Is))},ee(()=>{this.#f(),this.#p(),this.#m(),this.#y()})}static{this.observedAttributes=[at,es,Fs,Is]}#e;get logger(){return this.#e}#t;#s;#i;#r;#n;#o;#a;get name(){return this.name$.value}set name(e){let t=e?.trim();t?this.getAttribute(at)!==t&&this.setAttribute(at,t):this.removeAttribute(at)}get value(){return this.valueOut$.value}set value(e){this.valueIn$.set(e)}get shouldTrim(){return this.shouldTrim$.value}get entNode(){return this.entNode$.value}set entNode(e){this.entNode$.set(e)}get viewComponent(){return this.viewComponent$.value}#h(){this.#t=this.entNode$.onChange(e=>{if(e){let t=$e(e.viewComponent$,this.viewComponent$);return()=>{t.destroy()}}else this.viewComponent$.set(void 0)}),this.#s=O(()=>{let e=this.viewComponent$.get(),t=this.name$.get();if(e==null||!t)return;let r=this.entNode$.value;return Au(e,t),()=>{Tu(e,t)&&(e.removeProperty(t),r?.syncShadowObjects())}}),this.#i=O(()=>{let e=this.viewComponent$.get();if(e){let t=this.name$.get();if(t){let r=this.valueOut$.get();this.logger.debug(`[${this.name}] view-component set-property`,t,r,e.uuid,{viewComponent:e,shaeProp:this}),e.setProperty(t,r),this.isConnected&&this.entNode?.syncShadowObjects()}}}),this.#r=O(()=>{let e=this.type$.get(),t=this.shouldTrim$.get(),r=this.valueIn$.get();if(t&&typeof r=="string"&&(r=r.trim()),r=r??void 0,typeof r=="string"&&e){let i=An.get(e);if(i!=null)try{r=i(r)}catch(n){this.logger.error(`[${this.name}] could not convert the value into the type "${e}"`,{value:r,error:n,shaeProp:this}),r=void 0}}this.valueOut$.set(r)})}restore(){super.restore(),this.#h()}connectedCallback(){te(()=>{super.connectedCallback(),ee(()=>{this.#c(),this.#f(),this.#v()&&this.#p(),this.#m(),this.#y()})})}attributeChangedCallback(e){switch(e){case at:this.#f();break;case es:this.#p();break;case Fs:this.#m();break;case Is:this.#y();break}}disconnectedCallback(){this.#g(),this.#d(),super.disconnectedCallback()}teardown(){this.#g(),this.#t?.(),this.#t=void 0,this.#s?.destroy(),this.#s=void 0,this.#i?.destroy(),this.#i=void 0,this.#r?.destroy(),this.#r=void 0,super.teardown()}#c;#l;#u;#g;#d;#f;#p;#v;#m;#y};customElements.define(Dn,Hr);Te();B();K();Q();B();var wl=null,Ds=class s{static{this.OnFrame=Symbol("onFrame")}static get(){return wl??=new s,wl}static#e=.75;#t=0;#s=0;#i=0;#r=void 0;constructor(e=0){$(this),this.maxFps=e}get maxFps(){return this.#s}set maxFps(e){this.#s=Number.isFinite(e)&&e>0?e:0}get subscriptionCount(){return co(this)}start(e){if(e!=null)return y(this,s.OnFrame,e),this.#a(),()=>{this.stop(e)}}stop(e){e!=null&&(S(this,s.OnFrame,e),this.subscriptionCount===0&&(this.#h(),this.#r=void 0,this.#i=0))}#n=e=>{if(this.#t=0,this.#o(e)){let t=this.#r??e;this.#r=e,this.#i+=1;let r={now:e/1e3,lastNow:t/1e3,frameNo:this.#i,deltaTime:(e-t)/1e3};me(this,s.OnFrame,r)}this.subscriptionCount>0&&this.#a()};#o(e){return this.#s===0||this.#r===void 0?!0:e-this.#r>=s.#e*(1e3/this.#s)}#a(){this.#t===0&&(this.#t=requestAnimationFrame(this.#n))}#h(){this.#t!==0&&(cancelAnimationFrame(this.#t),this.#t=0)}};gt();B();V();Da();Ka();wr();Qi();en();function bl(s){return s.map(e=>{if(e.transferables&&e.transferables.length>0){let{transferables:t,...r}=e;return structuredClone(r,{transfer:t})}else return structuredClone(e)})}var Yr=class{constructor(e){this.#e=new Set,this.isLocalEnv=!0,this.disableStructuredClone=!1,this.kernel=new Lr(e),this.#t=We.isDefault(this.kernel.registry),y(this.kernel,Mt,t=>{let r=this.onMessageToView;if(r==null)return;let{type:i,uuid:n,traverseChildren:o}=t,a=structuredClone(t.data,{transfer:t.transferables??[]});r.call(this,{type:i,uuid:n,data:a,traverseChildren:o})})}#e;#t;get registry(){return this.kernel.registry}start(){return Promise.resolve()}applyChangeTrail(e,t){let r={changeTrail:this.disableStructuredClone?e:bl(e)},i;try{this.kernel.run(r),i=Promise.resolve()}catch(n){i=Promise.reject(n)}return t?i.then(()=>{}):i}inspect(e={},t){if(t?.aborted)return Promise.reject(t.reason);try{return Promise.resolve(xa(this.kernel,e))}catch(r){return Promise.reject(r)}}async importScript(e){let t=await import(Ar(e));if(!t[ys])throw new Error($a);await this.importModule(t[ys])}async importModule(e){return tn(this.kernel,e,this.#e)}destroy(){this.kernel.destroy(),this.#t||this.registry.clear(),this.#e.clear()}};un();Fr();Te();var Fu=[["loadTimeout",jn],["configureTimeout",Wn],["changeTrailTimeout",_n],["inspectTimeout",Fn],["destroyTimeout",In]];function Yl(s){return typeof s!="string"?s?Ls.DefaultAutoSync:"no":s.trim().toLowerCase()}var Ls=class s extends st{constructor(){super(...arguments),this.isShaeWorkerElement=!0,this.shadowEnv=new F,this.#e=new E("ShaeWorkerElement"),this.autostart=!0,this.isConnected$=m(!1),this.autoSync$=m(s.DefaultAutoSync),this.src$=m(""),this.#t=!1,this.#h=e=>{e instanceof de||this.logger.error("shadowEnv failed",e)}}static{this.observedAttributes=[...st.observedAttributes,Ie,"src",Ws,pe,_s]}static{this.DefaultAutoSync="frame"}#e;get logger(){return this.#e}#t;#s;#i;#r;get redactProps(){return ta(this,Bn)}get modelContextExposure(){return this.#r?.handle}#n;restore(){super.restore(),this.#n=this.ns$.onChange(e=>{this.shadowEnv.view=P.get(e)}),y(this.shadowEnv,F.ContextCreated,()=>{this.#i?.run(),this.dispatchEvent(new CustomEvent(F.ContextCreated.toLowerCase(),{bubbles:!1,detail:{shadowEnv:this.shadowEnv}}))}),y(this.shadowEnv,F.ContextLost,()=>{this.dispatchEvent(new CustomEvent(F.ContextLost.toLowerCase(),{bubbles:!1,detail:{shadowEnv:this.shadowEnv}}))}),y(this.shadowEnv,F.ProxyFailed,e=>{this.dispatchEvent(new CustomEvent(F.ProxyFailed.toLowerCase(),{bubbles:!1,detail:{shadowEnv:this.shadowEnv,reason:e}}))}),y(this.shadowEnv,F.SyncFailed,(e,t)=>{this.dispatchEvent(new CustomEvent(F.SyncFailed.toLowerCase(),{bubbles:!1,detail:{shadowEnv:this.shadowEnv,reason:e,changeTrail:t}}))}),this.autoSync$.onChange(e=>this.#o(e)),this.#o(this.autoSync$.value),this.#l(),this.#a(),this.shadowEnv.isReady&&this.#i?.run()}#o(e){this.reflectAttribute(pe,()=>{let t=this.hasAttribute(pe),r=t?this.getAttribute(pe):void 0;e===s.DefaultAutoSync?t&&r!==e&&this.setAttribute(pe,e):r!==e&&this.setAttribute(pe,e)})}#a(){this.#i=O(()=>{let e=this.src$.get();e&&this.importScript(e).catch(this.#h)},{autorun:!1})}#h;get shouldAutostart(){return this.autostart&&!Le(this,zn)}get autoSync(){return this.autoSync$.value}set autoSync(e){this.autoSync$.set(Yl(e))}get frameLoop(){return Ds.get()}[Ds.OnFrame](){this.syncShadowObjects()}async importScript(e){if(!e)throw new Error("src is blank");let t=await this.shadowEnv.ready();this.logger.info("shadowEnv importScript:",e,{shadowEnv:t});let r=t.envProxy;if(r==null)throw new de;return await r.importScript(e),this}connectedCallback(){te(()=>{if(this.isDestroyed){Br(this.getRootNode(),this.localName);return}super.connectedCallback(),ee(()=>{let e=this.getAttribute(pe);e!=null&&(this.autoSync=e),this.isConnected$.set(!0)}),this.shouldAutostart&&this.start().catch(this.#h),this.#d()})}disconnectedCallback(){this.isConnected$.set(!1),super.disconnectedCallback()}attributeChangedCallback(e){if(!this.isDestroyed){if(super.attributeChangedCallback(e),e===Ie&&this.#g(),e===Ws&&this.#u(),e===pe&&(this.autoSync=this.getAttribute(pe)??!0),e==="src"){let t=(this.getAttribute("src")||"").trim();this.src$.set(t),this.shadowEnv.isReady&&this.#i?.run()}e===_s&&this.#d()}}#c(){let e={};for(let[t,r]of Fu){let i=ea(this,r);i!==void 0&&(e[t]=i)}return e}start(){if(!this.#t){if(this.shadowEnv.view??=P.get(this.ns),this.shadowEnv.envProxy==null){let e=Le(this,Ie)?new Yr:new Ut(this.#c());this.shadowEnv.envProxy=e,this.#u()}this.#t=!0}return this.shadowEnv.ready()}teardown(){this.#p(),this.#n?.(),this.#n=void 0,this.#s?.destroy(),this.#i?.destroy(),R(this.isConnected$,this.autoSync$,this.src$),this.shadowEnv.envProxy=void 0,this.shadowEnv.destroy(),super.teardown()}#l(){this.#s=O(()=>{if(this.isConnected$.get()){let e=Yl(this.autoSync$.get()||s.DefaultAutoSync),t;if(["true","yes","on","frame","auto-sync"].includes(e))return this.logger.debug("auto-sync",e,this),this.frameLoop.start(this),()=>{this.frameLoop.stop(this)};if(e.endsWith("fps")){let r=parseInt(e,10);r>0?t=Math.floor(1e3/r):this.logger.warn(`invalid auto-sync value: ${e}`)}else t=parseInt(e,10),isNaN(t)&&(t=void 0,["false","no","off"].includes(e)||this.logger.error(`invalid auto-sync value: ${e}`));if(t!==void 0&&t>0){this.logger.debug("auto-sync interval (ms)",t,this);let r=setInterval(()=>{this.syncShadowObjects()},t);return()=>{clearInterval(r)}}else this.logger.debug("auto-sync off",this)}},[this.autoSync$,this.isConnected$])}#u(){let e=this.shadowEnv.envProxy;e?.isLocalEnv&&(e.disableStructuredClone=this.hasAttribute(Ws))}#g(){let e=this.shadowEnv.envProxy;if(e==null)return;let t=!!e.isLocalEnv;Le(this,Ie)!==t&&(this.logger.error(`the "local" attribute cannot change once the shadowEnv is built; it is reset to ${t?'the bare "local" form':"its absence"} \u2014 build a new <shae-worker> element to switch environments`),this.reflectAttribute(Ie,()=>{t?this.setAttribute(Ie,""):this.removeAttribute(Ie)}))}#d(){!this.isDestroyed&&this.isConnected&&Le(this,_s)?this.#f():this.#p()}#f(){if(this.#r!==void 0)return;let e=new AbortController,t=Promise.resolve().then(()=>(Hl(),ql)).then(({exposeShadowEnvsToModelContext:r})=>r({signal:e.signal,namespaces:i=>i===this.ns,redactProps:i=>this.redactProps.includes(i)}));this.#r={controller:e,handle:t},t.catch(r=>this.logger.error("expose-to-model-context: registering the tools failed",r))}#p(){let e=this.#r;e!==void 0&&(this.#r=void 0,e.controller.abort())}};customElements.define($n,Ls);globalThis.SHADOW_OBJECTS_BUNDLE_LOADED=!0;
|
|
71
24
|
/*! Bundled license information:
|
|
72
25
|
|
|
73
26
|
@spearwolf/eventize/lib/index.mjs:
|
|
74
27
|
(*!
|
|
75
28
|
=============================================================================
|
|
76
|
-
@spearwolf/eventize
|
|
29
|
+
@spearwolf/eventize 6.2.0+build.20260830
|
|
77
30
|
— git+https://github.com/spearwolf/eventize.git
|
|
78
31
|
=============================================================================
|
|
79
32
|
|
|
@@ -92,13 +45,13 @@ var pt="shaeRequestEntParent",gt="shaeReRequestEntParent",Us="shae-worker",yt="s
|
|
|
92
45
|
limitations under the License.
|
|
93
46
|
*)
|
|
94
47
|
|
|
95
|
-
@spearwolf/signalize/dist/signalize.
|
|
48
|
+
@spearwolf/signalize/dist/signalize.gcXQq0d2.js:
|
|
96
49
|
@spearwolf/signalize/dist/index.js:
|
|
97
50
|
@spearwolf/signalize/dist/decorators.js:
|
|
98
51
|
(*!
|
|
99
52
|
@file @spearwolf/signalize - signals and effects for all
|
|
100
53
|
@author Wolfger Schramm <wolfger@spearwolf.de>
|
|
101
|
-
@version 0.
|
|
54
|
+
@version 1.0.0+esm
|
|
102
55
|
|
|
103
56
|
Copyright 2022-2026 Wolfger Schramm
|
|
104
57
|
|