@spearwolf/shadow-objects 0.34.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 +30 -0
- package/README.md +11 -2
- package/bundle.js +4 -2
- package/package.json +9 -1
- package/src/WorkerTimeoutError.d.ts +4 -3
- package/src/WorkerTimeoutError.d.ts.map +1 -1
- package/src/WorkerTimeoutError.js.map +2 -2
- package/src/constants.d.ts +8 -4
- package/src/constants.d.ts.map +1 -1
- package/src/constants.js +6 -0
- package/src/constants.js.map +2 -2
- package/src/elements/ShaePropElement.d.ts +15 -6
- package/src/elements/ShaePropElement.d.ts.map +1 -1
- package/src/elements/ShaePropElement.js +31 -7
- package/src/elements/ShaePropElement.js.map +2 -2
- package/src/elements/ShaeWorkerElement.d.ts +10 -0
- package/src/elements/ShaeWorkerElement.d.ts.map +1 -1
- package/src/elements/ShaeWorkerElement.js +69 -2
- package/src/elements/ShaeWorkerElement.js.map +2 -2
- package/src/elements/constants.d.ts +3 -0
- package/src/elements/constants.d.ts.map +1 -1
- package/src/elements/constants.js +6 -0
- package/src/elements/constants.js.map +2 -2
- package/src/in-the-dark/Entity.d.ts +30 -0
- package/src/in-the-dark/Entity.d.ts.map +1 -1
- package/src/in-the-dark/Entity.js +38 -0
- package/src/in-the-dark/Entity.js.map +2 -2
- package/src/in-the-dark/Kernel.d.ts +24 -1
- package/src/in-the-dark/Kernel.d.ts.map +1 -1
- package/src/in-the-dark/Kernel.js +56 -1
- package/src/in-the-dark/Kernel.js.map +2 -2
- 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 +29 -0
- package/src/in-the-dark/Registry.js.map +2 -2
- package/src/in-the-dark/ShadowObjectCreationScope.d.ts +8 -1
- package/src/in-the-dark/ShadowObjectCreationScope.d.ts.map +1 -1
- package/src/in-the-dark/ShadowObjectCreationScope.js +23 -16
- package/src/in-the-dark/ShadowObjectCreationScope.js.map +2 -2
- 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 +4 -0
- 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/index.d.ts +2 -0
- package/src/index.d.ts.map +1 -1
- package/src/index.js +4 -0
- 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 +2 -0
- package/src/shadow-objects.d.ts.map +1 -1
- package/src/shadow-objects.js +4 -0
- package/src/shadow-objects.js.map +2 -2
- 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 +150 -10
- package/src/types.d.ts.map +1 -1
- package/src/utils/attr-utils.d.ts +5 -0
- package/src/utils/attr-utils.d.ts.map +1 -1
- package/src/utils/attr-utils.js +2 -0
- package/src/utils/attr-utils.js.map +2 -2
- package/src/view/IShadowObjectEnvProxy.d.ts +9 -0
- package/src/view/IShadowObjectEnvProxy.d.ts.map +1 -1
- package/src/view/LocalShadowObjectEnv.d.ts +7 -0
- package/src/view/LocalShadowObjectEnv.d.ts.map +1 -1
- package/src/view/LocalShadowObjectEnv.js +15 -1
- package/src/view/LocalShadowObjectEnv.js.map +2 -2
- package/src/view/RemoteWorkerEnv.d.ts +22 -3
- package/src/view/RemoteWorkerEnv.d.ts.map +1 -1
- package/src/view/RemoteWorkerEnv.js +50 -1
- package/src/view/RemoteWorkerEnv.js.map +2 -2
- package/src/view/ShadowEnv.d.ts +30 -0
- package/src/view/ShadowEnv.d.ts.map +1 -1
- package/src/view/ShadowEnv.js +101 -0
- package/src/view/ShadowEnv.js.map +3 -3
- package/src/worker/MessageRouter.d.ts.map +1 -1
- package/src/worker/MessageRouter.js +23 -0
- package/src/worker/MessageRouter.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,7 +18,9 @@ See the License for the specific language governing permissions and
|
|
|
18
18
|
limitations under the License.
|
|
19
19
|
|
|
20
20
|
*/
|
|
21
|
-
var Rt="shaeRequestEntParent",hs="shaeReRequestEntParent",Pt="shaeReRequestEntHost",xi="shae-worker",Oi="shae-ent",Mi="shae-prop",de="token",J="forward-custom-events",Li="auto-destruct";var ke="local",zi="no-autostart",cs="no-structured-clone",re="auto-sync";var Di="load-timeout",Wi="configure-timeout",$i="change-trail-timeout",Ni="destroy-timeout",us="name",ds="value",fs="type",gs="no-trim";var V="*",Ho=1,fr=2,gr=4,pr=Symbol.for("eventize"),yr=6,Yo="[eventize]",Ae=s=>s===V,vr=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}`)},Te=s=>{switch(typeof s){case"string":case"symbol":return!0;default:return!1}},mr=s=>s!=null&&(typeof s=="object"||typeof s=="function"),Ko=s=>Array.isArray(s),Qo=Object.prototype,Jo=(()=>{let s={},e=Function.prototype;for(let t of Reflect.ownKeys(Function.prototype))try{s[t]=e[t]}catch{}return s})(),Xo=(s,e)=>{if(e==="constructor"||e==="__proto__")return;let t=s[e];if(t!==void 0&&t!==Qo[e])return t===Jo[e]?void 0:t},Zo=(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},ea=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},ta=(s,e,t,r)=>{let i=s.emit;return typeof i=="function"&&vs(s,i,Zo(e,t),r)},ms=(s,e,t,r)=>vs(s,Xo(s,e),t,r)||ta(s,e,t,r),sa=typeof console<"u",fe=sa?console[typeof console.warn=="function"?"warn":"log"].bind(console,Yo):()=>{},ra=(s,e,t)=>(Object.defineProperty(s,e,{value:t,configurable:!1}),s),ia=0,na=(s,e)=>s.order-e.order,rt=s=>()=>{throw new Error(`EventKeeper: ${s} is the shared empty stand-in \u2014 replace it, never mutate it`)},xt=Object.freeze(Object.defineProperties(new Map,{set:{value:rt("events")},delete:{value:rt("events")},clear:{value:rt("events")}})),ps=Object.freeze(Object.defineProperties(new Set,{add:{value:rt("eventNames")},delete:{value:rt("eventNames")},clear:{value:rt("eventNames")}})),oa=s=>{if(s.length!==0){s.sort(na);for(let e of s)try{e.replay()}catch(t){fe("a retained replay threw; the batch continues. event:",e.eventName,t)}}},aa=s=>e=>{typeof e?.then=="function"&&e.then(void 0,t=>{fe("a retained replay rejected; the batch continues. event:",s,t)})},la=class{events=xt;eventNames=ps;mutableEvents(){return this.events===xt&&(this.events=new Map),this.events}mutableEventNames(){return this.eventNames===ps&&(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=ps)}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=xt)}removeAll(){this.eventNames=ps,this.events=xt}clearAll(){this.events=xt}retain(s,e){this.eventNames.size!==0&&this.eventNames.has(s)&&this.mutableEvents().set(s,{args:e,order:ia++})}hasRetainedFor(s){return this.events.size!==0&&(Ae(s)||this.events.has(s))}replayTo(s,e,t=[]){if(Ae(s))this.events.forEach((r,i)=>{Ae(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,aa(s))}})}return t}},ha=s=>s!=null,ca=s=>s!=null&&typeof s=="object",Mt=s=>{switch(typeof s){case"function":return Ho;case"string":case"symbol":return fr;case"object":return s===null?void 0:gr;default:return}},ua=0,da=()=>++ua,Hi=0,fa=()=>({settled:!1,members:[],sequence:Hi++,onSettled:void 0}),ga=class{id;eventName;isCatchEmAll;priority;listener;listenerObject;listenerType;callAfterApply;isRemoved;refCount;onceObligations;constructor(s,e,t,r=null){this.id=da(),this.eventName=s,this.isCatchEmAll=Ae(s),this.listener=t,this.listenerObject=r,this.priority=e,this.listenerType=Mt(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=Hi;if(typeof r=="function"){vs(i,r,e,t),this.callAfterApply&&this.callAfterApply(n);return}if(Te(r)){ha(i)&&vs(i,i[r],e,t)&&this.callAfterApply&&this.callAfterApply(n);return}ca(r)&&(this.isCatchEmAll||this.eventName===s)&&ms(r,s,e,t)&&this.callAfterApply&&this.callAfterApply(n)}},Ue=Symbol("eventize.EventStore.dedupIndex"),Yi=s=>s===gr||s===fr,pa=(s,e,t,r,i,n)=>s===n.listenerType?e===n.priority&&t===n.eventName&&i===n.listenerObject&&r===n.listener:!1,Ki=(s,e,t)=>s===gr?e:t,ya=s=>s!=null&&typeof s!="string"&&typeof s!="symbol",Qi=(s,e,t)=>{let r=e.listener,i=e.listenerObject,n=Yi(e.listenerType),o=n?Ki(e.listenerType,r,i):void 0;n&&t(s,o,e),ya(r)&&!(n&&o===r)&&t(s,r,e),mr(i)&&i!==r&&!(n&&o===i)&&t(s,i,e)},va=(s,e,t)=>{let r=s.get(e);r===void 0?s.set(e,[t]):r.push(t)},ma=(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))},wa=(s,e)=>{Qi(s[Ue]??=new Map,e,va)},_i=(s,e)=>{let t=s[Ue];t!==void 0&&Qi(t,e,ma)},ba=(s,e,t,r,i,n)=>{if(!Yi(s))return;let o=n[Ue];if(o===void 0)return;let a=o.get(Ki(s,r,i));if(a!==void 0){for(let l of a)if(pa(s,e,t,r,i,l))return l}},X=Symbol("eventize.EventStore.heldBy"),Ot=s=>{let e=s===void 0?[]:s.slice(0);return e[X]=0,e[Ue]=s===void 0?void 0:s[Ue],e},ys=s=>()=>{throw new Error(`EventStore: ${s} is the shared empty stand-in \u2014 replace it, never mutate it`)},Fi=Object.freeze(Object.defineProperties(new Map,{set:{value:ys("namedListeners")},delete:{value:ys("namedListeners")},clear:{value:ys("namedListeners")}})),Lt=Ot();for(let s of["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"])Object.defineProperty(Lt,s,{value:ys(`the catch-em-all bucket (${s}())`)});Object.freeze(Lt);var ur=s=>{s.forEach(e=>e.detach()),s[Ue]=void 0},Ea=(s,e)=>s.priority!==e.priority?e.priority-s.priority:s.id-e.id,Ca=(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");Ea(e,n)<0?r=i:t=i+1}return t},ji=(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)}},Sa=(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")}},ka=Object.freeze([]),Aa=class{namedBuckets=Fi;catchEmAllBucket=Lt;get namedListeners(){return this.namedBuckets}get catchEmAllListeners(){return this.mutableCatchEmAllBucket()}mutableNamedBuckets(){return this.namedBuckets===Fi&&(this.namedBuckets=new Map),this.namedBuckets}mutableCatchEmAllBucket(){return this.catchEmAllBucket===Lt&&(this.catchEmAllBucket=Ot()),this.catchEmAllBucket}getListenersForEventName(s){let e=this.namedBuckets.get(s);return e||(e=Ot(),this.mutableNamedBuckets().set(s,e)),e}peekListeners(s){return Ae(s)?this.catchEmAllBucket:this.namedBuckets.get(s)??ka}bucketForMutation(s,e){if(e[X]===0)return e;let t=Ot(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),_i(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),_i(r,n),n.detach())}return r}detachByIdentity(s,e,t,r,i){let n=e[Ue];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=Ae(s)?this.mutableCatchEmAllBucket():this.getListenersForEventName(s),o=Mt(t),a=ba(o,e,s,t,r,n),l=a??new ga(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(Ca(h,l),0,l),wa(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&&Ae(s)){this.removeAllListeners();return}if(e==null&&Te(s)){this.removeByEventName(s);return}if(t&&Te(s)){this.removeByEventNameAndListenerObject(s,e);return}this.removeByListener(s,e)}removeByEventName(s){let e=this.namedBuckets.get(s);e!==void 0&&(ur(e),e[X]===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(Ae(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(V,this.catchEmAllBucket,s,e,t)}removeAllListeners(){this.namedBuckets.size!==0&&(this.namedBuckets.forEach(e=>{ur(e),e[X]===0&&(e.length=0)}),this.namedBuckets.clear());let s=this.catchEmAllBucket;s!==Lt&&(ur(s),s[X]!==0?this.catchEmAllBucket=Ot():s.length=0)}forEach(s,e,t,r,i){let n=this.catchEmAllBucket,o=n.length>0?n:void 0,a=s===V?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[X]+=1;try{ji(o,e,t,r,i)}finally{o[X]-=1}return}l[X]+=1,o!==void 0&&(o[X]+=1);try{o===void 0?ji(l,e,t,r,i):Sa(l,o,e,t,r,i)}finally{l[X]-=1,o!==void 0&&(o[X]-=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(V),s}},Ta=s=>s[pr],Ra=s=>{throw new TypeError(`two incompatible copies of @spearwolf/eventize are active on this object (marker protocol ${String(s)}, expected ${yr}) \u2014 dedupe @spearwolf/eventize in your dependency tree so a single copy is loaded`)},Pa=s=>s?.protocol===yr,ie=s=>{let e=Ta(s);return Pa(e)?e:Ra(e?.protocol)},Z=s=>!!(s&&s[pr]);function zt(s){if(Z(s))return ie(s),s;if(!mr(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 Aa,t=new la;return ra(s,pr,{protocol:yr,keeper:t,store:e}),s}var Ji=(s,e,t,r)=>{s.apply(e,t,r)},xa=(s,e)=>{fe("a listener threw; the dispatch continues. event:",s,e)},N=null,Xi=(s,e)=>{N!==null?N.push(e):xa(s,e)},dr=s=>s.length===1?s[0]:new AggregateError(s,"emitStrict: one or more listeners failed"),ws=(s,e,t,r)=>{try{s.apply(e,t,r)}catch(i){Xi(e,i)}},Bi=(s,e,t,r,i,n)=>{e===V&&vr("emitted");let o=n??ie(s);return o.store.forEach(e,r,e,t,i),o.keeper.retain(e,t),o},it=(s,e,t,r,i)=>{if(Array.isArray(e)){let n;for(let o=0;o<e.length;o++)o in e&&(n=Bi(s,e[o],t,r,i,n))}else Bi(s,e,t,r,i)},bs=(s,e,t,r)=>{try{ms(s,e,t,r)}catch(i){Xi(e,i)}},Ii=(s,e,t,r,i)=>{e===V&&vr("emitted"),r(ea(s),e,t,i)},nt=(s,e,t,r,i)=>{if(Array.isArray(e))for(let n=0;n<e.length;n++)n in e&&Ii(s,e[n],t,r,i);else Ii(s,e,t,r,i)},ot=mr;function b(s,e,...t){Z(s)?it(s,e,t,Ji):ot(s)&&nt(s,e,t,ms)}function ne(s,e,...t){let r=N;N=null;try{Z(s)?it(s,e,t,ws):ot(s)&&nt(s,e,t,bs)}finally{N=r}}function W(s,e,...t){let r=N,i=[];N=i;try{Z(s)?it(s,e,t,ws):ot(s)&&nt(s,e,t,bs)}catch(n){i.push(n)}finally{N=r}if(i.length>0)throw dr(i)}var Ui=()=>{},Zi=s=>{for(let e of s)if(Array.isArray(e))for(let t of e)Promise.resolve(t).catch(Ui);else Promise.resolve(e).catch(Ui)};function Oa(s,e,...t){let r=[],i=n=>{r.push(n)};try{Z(s)?it(s,e,t,Ji,i):ot(s)&&nt(s,e,t,ms,i)}catch(n){throw Zi(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 Ma(s,e,...t){let r=[],i=o=>{r.push(o)},n=N;N=null;try{Z(s)?it(s,e,t,ws,i):ot(s)&&nt(s,e,t,bs,i)}catch(o){throw Zi(r),o}finally{N=n}return r.length>0?Promise.all(r.map(o=>Array.isArray(o)?Promise.all(o):Promise.resolve(o))):Promise.resolve(void 0)}var La=(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};function za(s,e,...t){let r=[],i=a=>{r.push(a)},n=N,o=[];N=o;try{Z(s)?it(s,e,t,ws,i):ot(s)&&nt(s,e,t,bs,i)}catch(a){o.push(a)}finally{N=n}return r.length===0?o.length>0?Promise.reject(dr(o)):Promise.resolve(void 0):Promise.allSettled(r.map(a=>Array.isArray(a)?Promise.allSettled(a):Promise.resolve(a))).then(a=>{let l=La(r,a,o);if(o.length>0)throw dr(o);return l})}var B={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},Da=(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,P,g)=>{a.settled||l.apply(c,P,g)}};o.events=e.replayTo(t,u,o.events)}return l},Vi=(s,e)=>{if(typeof s!="number"||Number.isNaN(s))throw fe("called with a NaN priority!",e),new Error("subscribeTo() called with a NaN priority",{cause:"invalid-priority"})},Gi=(s,e)=>{if(!Te(s))throw fe("called with a value that cannot be an event name!",e),new Error("subscribeTo() called with insufficient arguments",{cause:"invalid-name"})},Wa=(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=V,[l,h,u]=t):n>=3&&n<=4&&typeof t[1]=="number"?[a,l,h,u]=t:(l=B.Normal,o==="string"||o==="symbol"||Array.isArray(t[0])?[a,h,u]=t:(a=V,[h,u]=t)),!h||Mt(h)===void 0){let P=h==null?"missing-listener":Mt(h)===void 0?"not-dispatchable":"empty-method-name";throw fe(P==="missing-listener"?"called with insufficient arguments!":P==="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:P})}if(Mt(h)===fr&&u==null)throw fe("called with a method name but no listener object!",t),new Error("subscribeTo() called with insufficient arguments",{cause:"missing-listener-object"});Array.isArray(a)||Gi(a,t),Vi(l,t);let c=(P,g)=>Da(s,e,g,P,h,u,r,i);if(Array.isArray(a)){if(a.length===0)throw fe("called with an empty array of event names!",t),new Error("subscribeTo() called with insufficient arguments",{cause:"empty-names"});for(let g=0;g<a.length;g++)if(!(g in a))throw fe("called with a sparse array of event names!",t),new Error("subscribeTo() called with insufficient arguments",{cause:"sparse-names"});return a.map(g=>{let Q=Array.isArray(g)?[g[0],g[1]??l]:[g,l];return Gi(Q[0],t),Vi(Q[1],t),Q}).map(g=>c(g[1],g[0]))}return c(l,a)},en=(s,e,t,r=null)=>{let i={},n=Wa(s,e,t,i,r);return i.events!==void 0&&oa(i.events),n},$a=(s,e)=>{let t={host:s,listeners:e};return()=>{let r=t;if(r===null)return;t=null;let{store:i}=ie(r.host);Array.isArray(r.listeners)?r.listeners.forEach(n=>i.release(n)):i.release(r.listeners)}},Na=(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}=ie(r.host);i.releaseObligation(r.obligation)}},_a=s=>Array.isArray(s)?s.some(e=>e==null||e===V):s===V,p=(s,...e)=>{let t=zt(s),{store:r,keeper:i}=ie(t);return $a(t,en(r,i,e))},A=(s,...e)=>{let t=zt(s),{store:r,keeper:i}=ie(t),n=fa();return en(r,i,e,n),Na(t,n)},qi=s=>s.reason??new DOMException("This operation was aborted","AbortError");function wr(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(qi(r)),o;let a,l=!1,h=A(s,e,(...u)=>{l=!0,r!=null&&a!=null&&r.removeEventListener("abort",a),i(u[0])});return r!=null&&!l&&(a=()=>{h(),n(qi(r))},r.addEventListener("abort",a,{once:!0})),o}function E(s,e,t){if(!Z(s))return;let{store:r,keeper:i}=ie(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&&_a(a)){i.removeAll();return}t==null&&Ko(a)?i.remove(a.filter(Te)):Te(e)&&i.remove(e)}var tn=s=>Array.isArray(s)?s.some(e=>e===V):s===V,sn=(s,e)=>{if(!Array.isArray(e)){if(!Te(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(!Te(t))throw new Error(`${s}() called with a value that cannot be an event name`,{cause:"invalid-name"})},rn=(s,e,t,r,i)=>{if(!Z(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}=ie(e);if(tn(t)){r(n);return}sn(s,t),i(n,t)};function oe(s,e){tn(e)&&vr("retained"),sn("retain",e);let t=zt(s),{keeper:r}=ie(t);r.add(e)}function Dt(s,e){rn("retainClear",s,e,t=>t.clearAll(),(t,r)=>t.clear(r))}function br(s,e){rn("unretain",s,e,t=>t.removeAll(),(t,r)=>t.remove(r))}var Fa=p,ja=A,Ba=E,Ia=b,Ua=Oa,Va=ne,Ga=Ma,qa=W,Ha=za,Ya=wr,Ka=oe,Qa=Dt,Ja=br,Xa={on(...s){return Fa(this,...s)},once(...s){return ja(this,...s)},onceAsync(s,e){return Ya(this,s,e)},off(s,e){Ba(this,s,e)},emit(s,...e){Ia(this,s,...e)},emitAsync(s,...e){return Ua(this,s,...e)},emitSafe(s,...e){Va(this,s,...e)},emitSafeAsync(s,...e){return Ga(this,s,...e)},emitStrict(s,...e){qa(this,s,...e)},emitStrictAsync(s,...e){return Ha(this,s,...e)},retain(s){Ka(this,s)},retainClear(s){Qa(this,s)},unretain(s){Ja(this,s)}},nn=Object.entries(Xa),M=(()=>{let s=(e={})=>zt(e);return s.inject=(e={})=>{e=zt(e);for(let[t,r]of nn)Object.defineProperty(e,t,{value:r.bind(e),writable:!0,enumerable:!1,configurable:!0});return e},s.is=Z,s})(),Za=class{constructor(){M(this)}};for(let[s,e]of nn)Object.defineProperty(Za.prototype,s,{value:e,writable:!0,enumerable:!1,configurable:!0});var on=s=>Z(s)?ie(s).store.getSubscriptionCount():0;var ee=Symbol.for("@spearwolf/signalize/signal"),G=Symbol.for("@spearwolf/signalize/effect"),Dr=Symbol.for("@spearwolf/signalize/destroySignal"),dn=Symbol.for("@spearwolf/signalize/createEffect"),fn=Symbol.for("@spearwolf/signalize/destroyEffect"),gn=Symbol.for("@spearwolf/signalize/effectError"),el=Symbol.for("@spearwolf/signalize/signalizeError"),Pe=Symbol.for("@spearwolf/signalize/queueUnsubscribes"),Nt=Symbol.for("@spearwolf/signalize/autoMapResources"),tl=Symbol.for("@spearwolf/signalize/instances"),_t="value",Wr="mute",$r="unmute",ae="destroy",sl="off",ct=Symbol.for("@spearwolf/signalize/recall"),Ft=M(),le=M(),ye=M(),Nr=M(),rl=(s,e)=>{try{let t=globalThis[tl]??=[];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}},il=0;var nl=({level:s,message:e,error:t})=>{let r=s==="warn"?console.warn:console.error;t===void 0?r(e):r(e,t)},te=s=>{if(il>0)try{b(ye,el,s);return}catch(e){console.error(`[signalize] an onSignalizeError handler threw while reporting a ${s.source} diagnostic:`,e)}nl(s)};rl(import.meta.url,te);var an=new Set,Tr=(s,e)=>{an.has(s)||(an.add(s),te({level:"warn",source:"deprecation",message:e}))},Rr,pn=s=>{Rr=s},yn=()=>{if(Rr===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 Rr},jt=s=>s!=null&&typeof s.then=="function",As=(s,e,t,r)=>{if(jt(s))throw new TypeError(`[signalize] ${e}: ${t} must be synchronous, but it returned a thenable. ${r}`)},lt=0,ol="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 _r(s){lt++;try{let e=s();return As(e,"beQuiet","action",ol),e}finally{lt--}}function Ts(){return lt>0}function vn(){return lt}function mn(){lt=0}function wn(s){lt=s}var L=(s,e)=>{if(s.length!==0)throw s.length===1?s[0]:new AggregateError(s,`[signalize] ${s.length} errors while ${e}`)},y=(s,e)=>{try{e()}catch(t){s.push(t)}},Fr=0,Ge,Rs=()=>{Fr++;let s=Ge;return Ge=void 0,s},Ps=(s,e)=>{let t=Ge;Ge=s,Fr--,t!==void 0&&L(t,e)},ut=s=>Fr===0?!1:(Ge===void 0&&(Ge=[]),Ge.push(s),!0),qe=[],xs=()=>qe.at(-1),jr=(s,e)=>{qe.push(s);try{return e()}finally{qe.pop()}},bn=()=>qe.slice(),En=()=>{qe.length=0},Cn=s=>{qe.length=0,qe.push(...s)},Br=0,Sn=new FinalizationRegistry(()=>{--Br}),al=s=>{++Br,Sn.register(s,void 0,s)};function ln(s){Ts()||xs()?.whenSignalIsRead(s)}function Pr(s,e,t){if(!Ts()){let r=Rs();try{b(Ft,s,e,t)}catch(i){ut(i)}finally{Ps(r,"notifying the effects of a signal write")}}}var Re=s=>s!=null&&s[ee]!=null,$=s=>s?.[ee],x=(...s)=>{for(let e of s){let t=$(e);if(t!=null&&!t.destroyed){t.destroyed=!0,t.beforeRead=void 0,Sn.unregister(t),--Br;let r=Rs();try{b(le,t.id,t.id)}catch(i){ut(i)}finally{Ps(r,"notifying the subscribers of a destroyed signal")}}}};var ht=new WeakMap,ll=s=>{let e=ht.get(s);return e||(e={},ht.set(s,e)),e},xe=(s,e)=>ht.get(s)?.signals?.get(e),Ir=(s,e)=>ht.get(s)?.signals?.get(e);var kn=(s,e,t)=>{let r=ll(s);r.signals??=new Map,r.signals.set(e,t)};function Bt(...s){let e=[];for(let t of s)if(ht.has(t)){let r=ht.get(t);if(r.signals){for(let i of r.signals.values())y(e,()=>x(i));r.signals.clear(),r.signals=void 0}}L(e,"destroying the signals of an object")}function An(s){if(!Re(s)&&!Array.isArray(s))throw new TypeError("[signalize] touch: source must be a signal or an [object, propertyName] tuple");let e=$(Re(s)?s:xe(...s));e!=null&&!e.muted&&!e.destroyed&&Pr(e.id,e.value,{touch:!0})}function dt(s){if(!Re(s)&&!Array.isArray(s))throw new TypeError("[signalize] value: source must be a signal or an [object, propertyName] tuple");return Re(s)?$(s)?.value:$(xe(...s))?.value}var ks=class{[ee];constructor(e){this[ee]=e}get get(){return this[ee].reader}get set(){return this[ee].writer}get value(){return dt(this.get)}set value(e){this.set(e)}onChange(e){let{destroy:t}=yn()(()=>e(this.get()),[this.get]);return t}get muted(){return this[ee].muted}set muted(e){this[ee].muted=e}get destroyed(){return this[ee].destroyed}touch(){An(this)}destroy(){x(this)}},Ve=new WeakMap,at=new Set,ge=Symbol.for("@spearwolf/signalize/groupResources"),hn=new FinalizationRegistry(s=>{for(let e of s.unsubs)try{e()}catch(t){te({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)}),hl=s=>{let e=s[ge].selfRef;if(!(e==null||!at.has(e)))try{s.clear()}catch(t){te({level:"error",source:"group-finalizer",message:"[signalize] a SignalGroup teardown threw in the FinalizationRegistry callback, where no caller can catch it:",error:t})}},cn=new FinalizationRegistry(s=>{let e=s.deref();e!==void 0&&hl(e)});var cl=Symbol.for("@spearwolf/signalize/setParentGroup"),Er=1,Cr=2,Sr=4,kr=8,Ar=16,un="[signalize] Cannot attach a group to one of its own descendants: this would create a cycle in the group graph",Os="[signalize] internal error: a shared empty stand-in collection was written to",xr=class extends Set{add(){throw new Error(Os)}},Or=class extends Map{set(){throw new Error(Os)}},Mr=class extends WeakMap{set(){throw new Error(Os)}},Lr=class extends WeakSet{add(){throw new Error(Os)}},Wt=new xr,Ss=new Or,Tn=new Mr,Rn=new Lr,Es=s=>s===Wt?new Set:s,Cs=s=>s===Ss?new Map:s,ul=s=>s===Tn?new WeakMap:s,dl=s=>s===Rn?new WeakSet:s,pe=class s{#e=Wt;#t=new Set;#s=Ss;#r=Tn;#i=Ss;#n=Wt;#o=new Set;#a=Ss;[ge]={unsubs:Wt};#u=Wt;#c=Rn;#l;#h=0;#v;static get(e){if(e!=null)return e instanceof s?e:Ve.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:Ve.get(e)??new s(e)}static destroy(e){Tr("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}Ve.get(e)?.clear()}static clear(){let e=[];for(let t of[...at]){let r=t.deref();if(r===void 0){at.delete(t);continue}y(e,()=>r.clear())}L(e,"clearing all signal groups")}constructor(e){if(e!=null&&e instanceof s)return e;if(e??=this,Ve.has(e))return Ve.get(e);this.#v=new WeakRef(e),Ve.set(e,this);let t=new WeakRef(this);this[ge].selfRef=t,at.add(t),hn.register(this,this[ge],this),e!==this&&cn.register(e,t,this),M(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(un);if(r=r.#l,r==null)break;if(r===e)throw new Error(un);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=Es(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}[cl](e){this.#l=e}attachSignal(e){let t=this.#d(e);return t&&(this.#n=Es(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[ge].selfRef,i=new WeakRef(t),n=p(le,t.id,(a,l)=>{if(l?.detach)return;let h=i.deref(),u=r.deref();h!==void 0&&u!==void 0&&u.#p(h)});(this.#a=Cs(this.#a)).set(t,n);let o=this[ge];(o.unsubs=Es(o.unsubs)).add(n)}return t}#f(e){let t=this.#a.get(e);if(t)try{t()}finally{this.#a.delete(e),this[ge].unsubs.delete(t)}}#g(e,t){let r=this.#i.get(e);r&&(r.delete(t),r.size===0&&this.#i.delete(e));let i=this.#r.get(t);i&&(i.delete(e),i.size===0&&(this.#r.delete(t),this.#n.has(t)||(this.#f(t),this.#t.delete(t),x(t))))}#y(e,t){this.#n.has(t)||this.#g(e,t)}attachSignalByName(e,t){if(t){let r=this.#d(t),i=this.#s.get(e);i!=null&&i!==r&&this.#y(e,i),(this.#s=Cs(this.#s)).set(e,r);let n=this.#i.get(e);n?n.add(r):(this.#i=Cs(this.#i)).set(e,new Set([r])),this.#r.has(r)?this.#r.get(r).add(e):(this.#r=ul(this.#r)).set(r,new Set([e]))}else{let r=this.#i.get(e);if(r)for(let i of[...r])this.#g(e,i);this.#s.delete(e)}return t}hasSignal(e){if(this.#h&Er)return!1;this.#h|=Er;try{return this.#s.has(e)||!!this.#l?.hasSignal(e)}finally{this.#h&=~Er}}signal(e){if(!(this.#h&Cr)){this.#h|=Cr;try{return this.#s.get(e)?.object??this.#l?.signal(e)}finally{this.#h&=~Cr}}}detachSignal(e){let t=$(e);return t&&this.#p(t),e}#p(e){let t=[];if(y(t,()=>this.#f(e)),this.#t.delete(e),this.#n.delete(e),this.#r.has(e)){let r=this.#r.get(e);for(let i of r){let n=this.#i.get(i);if(n){if(n.delete(e),n.size===0)this.#s.delete(i),this.#i.delete(i);else if(this.#s.get(i)===e){let o;for(let a of n)o=a;(this.#s=Cs(this.#s)).set(i,o)}}}r.clear(),this.#r.delete(e)}L(t,"detaching a signal from a signal group")}attachEffect(e){let t=e!=null&&G in e?e[G]: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),A(t,ae,B.Max,()=>{this.#o.delete(t)})),e}runEffects(){if(!(this.#h&Sr)){this.#h|=Sr;try{for(let e of this.#o)e.run();for(let e of this.#e)e.runEffects()}finally{this.#h&=~Sr}}}attachLink(e){if(e?.isDestroyed)throw new Error("[signalize] Cannot attach a destroyed link to a group");return e&&((this.#u=Es(this.#u)).add(e),this.#c.has(e)||((this.#c=dl(this.#c)).add(e),A(e,ae,B.Max,()=>{this.#u.delete(e)}))),e}detachLink(e){return e&&this.#u.delete(e),e}get memberCounts(){return{signals:this.#t.size,namedSignals:this.#s.size,signalsByName:this.#i.size,effects:this.#o.size,links:this.#u.size,groups:this.#e.size}}destroy(){Tr("SignalGroup#destroy","[signalize] SignalGroup#destroy is deprecated. Use SignalGroup#clear instead."),this.clear()}off(){if(!(this.#h&kr)){this.#h|=kr;try{let e=[];for(let t of[...this.#e])y(e,()=>t.off());for(let t of[...this.#o])y(e,()=>t.destroy());this.#o.clear();for(let t of[...this.#u])y(e,()=>t.destroy());this.#u.clear();for(let t of[...this.#t])t.destroyed||y(e,()=>b(le,t.id,t.id,{detach:!0}));y(e,()=>b(this,sl,this)),L(e,"switching off a signal group")}finally{this.#h&=~kr}}}clear(){if(!(this.#h&Ar)){this.#h|=Ar;try{let e=[];y(e,()=>b(this,ae,this)),y(e,()=>E(this));for(let t of[...this.#e])y(e,()=>t.clear());for(let t of[...this.#o])y(e,()=>t.destroy());for(let t of[...this.#t])y(e,()=>x(t));for(let t of[...this.#u])y(e,()=>t.destroy());for(let t of[...this.#a.values()])y(e,()=>t());if(this.#a.clear(),this.#e.clear(),this.#t.clear(),this.#s.clear(),this.#i.clear(),this.#n.clear(),this.#o.clear(),this.#u.clear(),this.#l?.detachGroup(this),this.#v){let t=this.#v.deref();t!==void 0&&Ve.delete(t),this.#v=void 0}at.delete(this[ge].selfRef),this[ge].unsubs.clear(),cn.unregister(this),hn.unregister(this),L(e,"clearing a signal group")}finally{this.#h&=~Ar}}}},$t=class{#e;#t;constructor(e="id",t=1){this.#e=e,this.#t=t}make(){return Symbol(`${this.#e}${this.#t++}`)}},fl=new $t("si"),gl=["lazy","compare","beforeRead"],pl=(s,e)=>s===e;function yl(){Tr("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 vl=s=>{let e=t=>(s.destroyed||s.beforeRead?.(),t?(yl(),yn()(()=>(s.destroyed||ln(s.id),t(s.value)),[e])):s.destroyed||ln(s.id),s.value);return Object.defineProperty(e,ee,{value:s}),e},zr=class{id;lazy;get[ee](){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??pl;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)){Pr(this.id,this.#e);return}(t?.touch??!1)&&!this.muted&&!this.destroyed&&Pr(this.id,this.#e,{touch:!0})};object;constructor(e,t){this.id=fl.make(),al(this),this.lazy=e,this.lazy?(this.value=void 0,this.valueFn=t):(this.value=t,this.valueFn=void 0),this.reader=vl(this),this.object=new ks(this)}};function f(s=void 0,e){let t;if(Re(s)){t=$(s);let r=gl.filter(i=>e?.[i]!=null);r.length>0&&te({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 zr(r,s),t.beforeRead=e?.beforeRead,t.compare=e?.compare}return e?.attach!=null&&pe.findOrCreate(e.attach).attachSignal(t),t.object}var Vr=0,ml=()=>Vr>0,ve=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=[];Vr++;let r=Rs();try{t.push(p(ye,(i,n)=>{n===ct&&e.add(i)}),p(Nr,i=>{e.add(i)}));for(let[,i]of this.delayedEffects)for(let n of i)if(!e.has(n))try{b(ye,n,n,ct)}catch(o){ut(o)}}finally{try{for(let i of t)i()}finally{try{Ps(r,"flushing a batch of signal writes")}finally{Vr--}}}}},On=()=>ve.current,wl=()=>{ve.current=void 0},bl=s=>{ve.current=s},El="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 q(s){let e=ve.current;e?e=void 0:e=ve.current=new ve;let t;try{let r=s();As(r,"batch","callback",El)}catch(r){t=[r]}finally{if(e){ve.current=void 0;try{e.run()}catch(r){t===void 0?t=[r]:t.push(r)}}}t!==void 0&&L(t,"running a batch")}var Cl=()=>{},Gr=class{[G];constructor(e){this[G]=e,A(e,ae,()=>{this[G]=void 0})}run=()=>this[G]?.run();runImmediately=()=>this[G]?.runImmediately();get destroyed(){let e=this[G];return e==null||e.destroyed}destroy=()=>{this[G]?.destroy(),this[G]=void 0};onDestroy(e){let t=this[G];return t==null||t.destroyed?(e(),Cl):A(t,ae,e)}},Sl=0,kl=()=>Sl>0;var He,It=(s,e,t)=>{if(kl()){let r={error:e,effect:s,effectId:s.id,phase:t};try{b(ye,gn,r);return}catch(i){console.error(`[signalize] an onEffectError handler threw while reporting an error of effect ${s.id.toString()}:`,i)}}te({level:"error",source:"effect",message:`[signalize] unhandled rejection in the ${t} of effect ${s.id.toString()}:`,error:e})},qr=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)}},Ms=class{static idGen=new $t("ef");static count=0;static maxDepth=256;id;callback;#e;#t=new Set;#s=new Set;#r=new Map;#i=0;#n=new Set;#o=[];autorun=!0;shouldRun=!0;#a=!1;priority;#u;#c=!1;get destroyed(){return this.#c}#l=0;#h=!1;#v=0;#d=!1;constructor(e,t){M(this),this.callback=e;let r=t?.attach!=null?pe.findOrCreate(t.attach):void 0;this.autorun=t?.autorun??!0,this.#u=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=He.idGen.make(),this.priority=t?.priority??0,p(ye,this.id,ct,this),r?.attachEffect(this),++He.count}hasStaticDeps(){return this.#u!=null&&this.#u.length>0}saveSignalsFromDeps(){for(let e of this.#u){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 He(e,n);try{xs()?.attachChildEffect(o),b(ye,dn,o),o.hasStaticDeps()?o.destroyed||o.saveSignalsFromDeps():o.autorun&&o.run()}catch(a){let l=[a];n?.attach==null&&y(l,()=>o.destroy()),L(l,"creating an effect")}return new Gr(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=On();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>=He.maxDepth)throw new Error(`[signalize] Effect ${this.id.toString()} exceeded maxDepth=${He.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,ml()&&b(Nr,this.id,this.id);let r=++this.#v;this.hasStaticDeps()?this.runStaticCallback(r):this.runDynamicCallback(r)}finally{if(this.#l--,this.#l===0&&this.#h&&(this.#h=!1,!this.#c&&this.hasNoLiveSignals()))try{this.destroy()}catch(r){It(this,r,"cleanup")}}}runStaticCallback(e){this.saveSignalsFromDeps(),this.storeCleanupCallback(this.runWithoutAutoTracking(),e)}runDynamicCallback(e){let t=new qr(!Ts(),this.#i);if(t.active){this.#s.clear();for(let r of this.#t)this.#s.add(r)}try{this.storeCleanupCallback(jr(this,this.callback),e),t.complete()}finally{t.mayCommit(this.#i)&&(this.cleanupLostSignals(),this.#n.clear())}}runWithoutAutoTracking(){let e=this.#d;this.#d=!0;try{return jr(this,this.callback)}finally{this.#d=e}}[ct](){if(this.shouldRun=!0,!(!this.autorun&&!this.#a))try{this.run()}catch(e){if(!ut(e))throw e}}whenSignalIsRead(e){this.#c||this.#d||(this.#i++,this.#s.delete(e),this.#t.has(e)||(this.#t.add(e),this.#r.set(e,[p(Ft,e,this.priority,ct,this),A(le,e,Dr,this)])))}[Dr](e,t){try{this.onSignalDestroyed(e,t)}catch(r){if(t?.detach||!ut(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.#h=!0;return}this.destroy()}hasNoLiveSignals(){return this.#r.size===0}cleanupLostSignals(){if(this.#s.size===0)return;let e=[];for(let t of this.#s)y(e,()=>this.unsubscribeSignal(t)),this.#t.delete(t);L(e,"unsubscribing an effect from a signal")}destroyChildEffects(){if(this.#o.length===0)return;let e=[];this.collectDestroyChildEffects(e),L(e,"destroying an effect")}collectDestroyChildEffects(e){for(let t of this.#o)y(e,()=>t.destroy());this.#o.length=0}unsubscribeSignal(e){if(this.#r.has(e)){let t=[];try{this.#r.get(e).forEach(r=>{y(t,()=>r())})}finally{this.#r.delete(e)}L(t,"unsubscribing an effect from a signal")}}storeCleanupCallback(e,t){if(!jt(e)){typeof e=="function"&&this.acceptCleanupCallback(e,t);return}Promise.resolve(e).then(r=>{typeof r=="function"&&this.acceptCleanupCallback(r,t)},r=>{It(this,r,"callback")})}acceptCleanupCallback(e,t){if(this.#c||t!==this.#v){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();jt(t)&&Promise.resolve(t).catch(r=>{It(this,r,"cleanup")})}runOrphanedCleanupCallback(e){try{let t=e();jt(t)&&Promise.resolve(t).catch(r=>{It(this,r,"cleanup")})}catch(t){It(this,t,"cleanup")}}destroy(){if(this.#c)return;this.#c=!0,E(Ft,this),E(ye,this),E(le,this);let e=[];y(e,()=>b(this,ae,this)),y(e,()=>E(this)),y(e,()=>b(ye,fn,this)),y(e,()=>this.runCleanupCallback());try{this.collectDestroyChildEffects(e)}finally{this.#t.clear(),this.#s.clear(),this.#r.clear(),this.#n.clear(),--He.count}L(e,"destroying an effect")}};He=Ms;var T=(...s)=>Ms.createEffect(...s);pn(T);function Mn(s,e){let t=xs(),r=f();try{let i=e?.name||void 0,n=e?.attach!=null?pe.findOrCreate(e.attach):void 0;n!=null?i!=null?n.attachSignalByName(i,r):n.attachSignal(r):i!=null&&te({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=T(()=>{o?q(()=>{r.set(s())}):r.set(s())},{autorun:!(e?.lazy??!1),priority:e?.priority??B.C,attach:n}),l=$(r);l.beforeRead=a.runImmediately;let h=A(le,l.id,a.destroy);return a.onDestroy(()=>{h(),t!=null&&x(r)}),r.get}catch(i){let n=[i];e?.attach==null&&y(n,()=>x(r)),L(n,"creating a memo")}}var Al="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.";function H(s){let e=On(),t=vn(),r=bn();wl(),mn(),En();let i=[],n;try{e&&y(i,()=>e.flush()),y(i,()=>{n=s(),As(n,"hibernate","callback",Al)})}finally{bl(e),wn(t),Cn(r)}return L(i,"hibernating"),n}var Ln="[signalize] SignalLink destroyed before the next value arrived",Hr=class{#e;#t;#s;#r=[];#i=!1;constructor(e,t,r){this.#e=e,this.#t=t,this.#s=r}get hasSettled(){return this.#i}add(e){this.#r.push(e)}releaseAll(){this.#s!=null&&(this.#s.cancel=void 0),this.#r.forEach(e=>{e()})}settleWithValue(e){this.#i=!0,this.releaseAll(),this.#e(e)}settleWithDestroy(){this.releaseAll(),this.#t(new Error(Ln))}settleWithAbort(e){this.releaseAll(),this.#t(e)}settleWithCancel(){this.releaseAll(),this.#t(new Error("[signalize] SignalLink read cancelled by the iterator"))}},Ls=class{#e=!1;[Pe]=[];#t=0;#s=0;#r=0;source;lastValue;isDestroyed=!1;constructor(e){M(this),this.source=$(e);let t=new WeakRef(this);this[Pe].push(p(Ft,this.source.id,(r,i)=>{let n=t.deref();n!=null&&!n.#e&&!n.isDestroyed&&(i?.touch===!0?n.touch():n.write())})),this[Pe].push(A(le,this.source.id,()=>t.deref()?.destroy()))}releaseOnDestroy(e){this[Pe].push(e)}attach(e){let t=pe.findOrCreate(e);return t.attachLink(this),t}nextValue(e){return this.#i(null,e)}#i(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(Ln));return}let a=new Hr(n,o,r);if(r!=null&&(r.cancel=()=>a.settleWithCancel()),a.add(A(this,ae,()=>a.settleWithDestroy())),i!=null){let h=()=>a.settleWithAbort(i.reason);i.addEventListener("abort",h,{once:!0}),a.add(()=>i.removeEventListener("abort",h))}let l=p(this,_t,h=>{this.#n(e)&&a.settleWithValue(h)});a.hasSettled?l():a.add(l)})}#n(e){return e==null?!0:e.generation===this.#r?!1:(e.generation=this.#r,!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){oe(this,_t),this.#t+=1;let i={generation:0};try{let n=0;for(;!this.isDestroyed;)try{let o=await this.#i(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&&br(this,_t)}}destroy(){if(this.isDestroyed)return;this.isDestroyed=!0;let e=[];for(let t of this[Pe])y(e,t);this[Pe].length=0,y(e,()=>b(this,ae,this)),y(e,()=>E(this)),this.lastValue=void 0,Object.freeze(this),L(e,"tearing down a SignalLink")}get isMuted(){return this.#e}mute(){return!this.isDestroyed&&!this.#e&&(this.#e=!0,b(this,Wr,this)),this}unmute(){return!this.isDestroyed&&this.#e&&(this.#e=!1,b(this,$r,this)),this}toggleMute(){return this.isDestroyed||(this.#e=!this.#e,b(this,this.#e?Wr:$r,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.#r=t,b(this,_t,r),this.lastValue=r}}},Yr=class extends Ls{target;constructor(e,t){super(e),this.target=$(t);let r=new WeakRef(this);this.releaseOnDestroy(A(le,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)})}},Kr=class extends Ls{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)})}},Ur=new WeakMap,Ut=0,Pn=new FinalizationRegistry(s=>{for(let e of s)try{e()}catch(t){te({level:"error",source:"link-finalizer",message:"[signalize] link: releasing the queue subscriptions of a collected link failed",error:t})}s.length=0,Ut>0&&(Ut-=1)}),Tl=1e3,xn=new WeakSet;function me(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=Ur.get(r);if(o==null)o=new Map,Ur.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 Yr(s,i):new Kr(s,e),l=t?.attach;return l&&a.attach(l),o.set(n,a),Ut+=1,Pn.register(a,a[Pe],a),o.size>=Tl&&!xn.has(r)&&(xn.add(r),te({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.`})),A(a,ae,B.Max,()=>{o.delete(n),o.size===0&&Ur.delete(r),Pn.unregister(a),Ut>0&&(Ut-=1)}),a}var Rl=new FinalizationRegistry(s=>{for(let e of s.unsubs)try{e()}catch(t){te({level:"error",source:"automap-finalizer",message:"[signalize] releasing the destroy-queue subscriptions of a collected SignalAutoMap failed:",error:t})}s.unsubs.clear()}),zs=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.#r(n,o);return r}[Nt]={unsubs:new Set};#e=new Map;#t=new Map;#s=new WeakRef(this);constructor(){Rl.register(this,this[Nt],this)}#r(e,t){let r=f(t);this.#e.set(e,r);let i=this.#s,n=p(le,$(r).id,(o,a)=>{if(a?.detach)return;let l=i.deref();l!==void 0&&l.#i(e)});return this.#t.set(e,n),this[Nt].unsubs.add(n),r}#i(e){let t=this.#t.get(e);try{t()}finally{this.#t.delete(e),this[Nt].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()])y(t,()=>this.#i(r));for(let r of e)y(t,()=>r.destroy());L(t,"clearing a signal auto map")}delete(e){let t=this.#e.get(e);return t===void 0?!1:(this.#i(e),t.destroy(),!0)}has(e){return this.#e.has(e)}get(e){return this.#e.has(e)?this.#e.get(e):this.#r(e)}update(e){e.size&&q(()=>{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&&q(()=>{for(let[i,n]of r)this.get(i).set(n)})}};var we=(s=>(s[s.StructuralChanges=1]="StructuralChanges",s[s.ContentUpdates=2]="ContentUpdates",s[s.Removal=3]="Removal",s))(we||{}),v=(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))(v||{}),Ye=Symbol.for("ShadowObjectsGlobalNS"),_="#void",zn="contextLost",Dn="configure",Wn="changeTrail",$n="destroy",Nn="loaded",_n="appliedChangeTrail",Fn="importedModule",jn="destroyed",ft="messageToView",Bn=6e4,In=6e4,Un=5e3,Vn=5e3,Vt="shadowObjects";var Gt=new Set(["on","true","yes","local","1"]);var Ke=s=>typeof s=="string"?s.trim()||Ye:typeof s=="symbol"?s:Ye;var Gn=s=>Ke(s.getAttribute("ns")??void 0),Oe=(s,e)=>{if(s.hasAttribute(e)){let t=s.getAttribute(e)?.trim()?.toLowerCase()||"1";return Gt.has(t)}return!1},qn=(s,e)=>s.hasAttribute(e)?Number(s.getAttribute(e)):void 0;var be="ConsoleLogger",Pl=`${be}Storage`,xl=new Set(["localhost","127.0.0.1","::1","[::1]"]),Ol=xl.has(globalThis.location?.hostname??""),qt=(()=>{try{let s=globalThis.localStorage;if(typeof s?.getItem!="function"||typeof s.setItem!="function"||typeof s.removeItem!="function")return;let e=`${be}.probe`;try{s.setItem(e,e)}finally{s.removeItem(e)}return s}catch{return}})(),Kn=qt!=null,Ds=Symbol.for(be),Me=globalThis,Hn=!1,Yn=s=>{if(typeof s=="boolean")return s;switch(s.toLowerCase()){case"true":case"yes":case"on":return!0;default:return!1}},Qr=s=>[Kn?be:void 0,...Array.isArray(s)?s:[s]].filter(Boolean).join(".");function $s(s,e,t){let r=Qr(s),i=qt?qt.getItem(r):Me.ConsoleLoggerStorage?.[r];return i==null?t:e?e(i):i}function Ws(s,e){qt&&qt.setItem(Qr(s),e)}var Qn=s=>Qr(s),Jn=(s,e)=>$s(s,void 0,e);var C=class s{constructor(e){this.enable=!0,this.namespace=(e||"").trim()||be,Hn||(s.loadConfig(),Hn=!0);let t=[this.namespace,"enable"];this.enable=$s(t,Yn,this.enable)}static{this.sharedConfig={enable:Ol,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(){Kn?(["enable","debug","info","warn"].forEach(e=>{this.sharedConfig[e]=$s(e,Yn,this.sharedConfig[e])}),["debug","info","warn","error"].forEach(e=>{this.sharedStyles[e]=$s(["styles",e],void 0,this.sharedStyles[e])}),s.isDebug&&console.debug(`${be}: Load config from localStorage`,s.sharedConfig),Me.ConsoleLogger?.[Ds]||(Me.ConsoleLogger??={[Ds]:!0,get enable(){return s.sharedConfig.enable},set enable(e){s.sharedConfig.enable=e,Ws("enable",e?"true":"false")},get debug(){return s.sharedConfig.debug},set debug(e){s.sharedConfig.debug=e,Ws("debug",e?"true":"false")},get info(){return s.sharedConfig.info},set info(e){s.sharedConfig.info=e,Ws("info",e?"true":"false")},get warn(){return s.sharedConfig.warn},set warn(e){s.sharedConfig.warn=e,Ws("warn",e?"true":"false")}})):Me.ConsoleLoggerStorage?.[Ds]||(Me.ConsoleLoggerStorage={[Ds]:!0,...s.sharedConfig,...Me.ConsoleLoggerStorage},s.sharedConfig=Me.ConsoleLoggerStorage,s.isDebug&&console.debug(`${be}: Load config from ${Pl}`,Me.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 pt=class{#e=!1;#t;constructor(e){this.#t=e}schedule(){this.#e||(this.#e=!0,queueMicrotask(()=>{this.#e=!1,this.#t()}))}};var Le=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 S(s,e,t,...r){try{e()}catch(i){s.error(t,...r,i)}}function Xn(s,e){s.indexOf(e)===-1&&s.push(e)}function Jr(s,e){let t=s.indexOf(e);t!==-1&&s.splice(t,1),s.push(e)}function Ht(s,e){let t=s.indexOf(e);t!==-1&&s.splice(t,1)}var Qe="#root",Ee=Symbol("shadow-objects/property-without-value"),Yt=class{#e;get uuid(){return this.#e}constructor(e){this.#e=e}#t=!0;#s=0;#r=0;hasChanges(){return this.#t&&this.isCreated||this.isDestroyed||this.#u!==void 0&&this.#u!==this.#i||this.#h()||this.#l!==void 0&&this.#l!==this.#o||this.#f.length>0||this.#y.length>0}get isNew(){return this.#t}get isCreated(){return this.#s>0&&this.#s>this.#r}get isDestroyed(){return this.#r>0&&this.#r>=this.#s}#i=_;#n;#o=0;#a=!1;#u;#c;#l;create(e=_,t,r=0,i=!1){this.#s++,this.#u=e,this.#c=t??Qe,this.#l=r||void 0,this.#a=i}destroy(){this.#r++}#h(){return this.#c===void 0?!1:(this.#c===Qe?void 0:this.#c)!==this.#n}clear(){this.#u=void 0,this.#c=void 0,this.#l=void 0,this.#d.clear(),this.#f.length=0,this.#g=void 0,this.#y.length=0,this.#p.clear()}changeToken(e){e??=_,!(e===this.#i&&this.#u===void 0&&!this.#t)&&(this.#u=e)}setParent(e){let t=e??Qe;t===(this.#n??Qe)&&this.#c===void 0||(this.#c=t)}changeOrder(e){e===this.#o&&this.#l===void 0||(this.#l=e)}#v=new Map;#d=new Map;#f=[];#g;changeProperty(e,t,r){let i=(u,c)=>u===Ee||c===Ee||r==null?u===c:r(u,c),n=this.#f.includes(e),o=this.#g?.has(e)??!1,a;n?a=this.#d.get(e):o?a=this.#g.get(e):a=this.#v.get(e);let l=!i(t,a);return!o&&(n?i(t,this.#v.get(e)):!l)?(this.#d.delete(e),Ht(this.#f,e)):(this.#d.set(e,t),Jr(this.#f,e)),l}setPropertyWithoutValue(e){return this.changeProperty(e,Ee)}removeProperty(e){let t=this.#f.includes(e);if(this.#d.delete(e),!this.#v.has(e)&&!this.#g?.has(e)){Ht(this.#f,e);return}t||Jr(this.#f,e)}getProperties(){let e=new Map(this.#v);for(let t of this.#f){let r=this.#d.get(t);r===void 0?e.delete(t):e.set(t,r)}return e}#y=[];#p=new Set;createEvent(e,t,r){this.#y.push({type:e,data:t});for(let i of r??[])this.#p.add(i)}transferEventsTo(e){this.#y.length>0&&(e.#y.push(...this.#y),this.#y.length=0),this.#p.size>0&&(e.#p=new Set([...e.#p,...this.#p]),this.#p.clear())}buildChangeTrail(e,t){let{isNew:r,isCreated:i,isDestroyed:n}=this;if(!(r&&n))switch(t){case we.StructuralChanges:r?e.push(this.makeCreateEntityChange()):n||(this.#h()?e.push(this.makeSetParentChange()):this.#l!==void 0&&this.#l!==this.#o&&e.push(this.makeUpdateOrderChange()),this.#u!==void 0&&this.#u!==this.#i&&e.push(this.makeChangeToken()));break;case we.ContentUpdates:!r&&i&&this.#f.length>0&&e.push(this.makeChangePropertyChange()),this.#y.length>0&&e.push(this.makeEvents());break;case we.Removal:n&&e.push(this.makeDestroyEntityChange());break}}makeEvents(){let e={type:v.SendEvents,uuid:this.#e,events:this.#y.slice(0)};return this.#p.size>0&&(e.transferables=Array.from(this.#p)),e}makeCreateEntityChange(){let e=this.#u??this.#i,t={type:v.CreateEntities,uuid:this.#e,token:e};if(this.#c!==void 0&&this.#c!==Qe&&(t.parentUuid=this.#c),this.#d.size>0){let r=[];for(let[i,n]of this.#d)n===Ee?r.push([i]):n!==void 0&&r.push([i,n]);this.#m(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:v.DestroyEntities,uuid:this.#e}}makeSetParentChange(){let e={type:v.SetParent,uuid:this.#e,parentUuid:this.#c===Qe?void 0:this.#c};return this.#l!==void 0&&this.#l!==this.#o&&(e.order=this.#l),e}makeUpdateOrderChange(){return{type:v.UpdateOrder,uuid:this.#e,order:this.#l??0}}makeChangeToken(){return{type:v.ChangeToken,uuid:this.#e,token:this.#u??_}}makeChangePropertyChange(){let e=this.#f.map(t=>{let r=this.#d.get(t);return r===Ee?[t]:[t,r]});return this.#m(e),{type:v.ChangeProperties,uuid:this.#e,properties:e}}#m(e){this.#g=new Map(e.map(t=>[t[0],t.length===1?Ee:t[1]]))}commitChange(e){switch(e.type){case v.CreateEntities:this.#w(e.token),this.#S(e.parentUuid),this.#C(e.order??this.#o),this.#k(e.properties);for(let t of this.#f.slice(0))this.#d.get(t)===void 0&&!this.#v.has(t)&&(this.#d.delete(t),Ht(this.#f,t));this.#g=void 0,this.#t=!1;break;case v.SetParent:this.#S(e.parentUuid),this.#C(e.order??this.#o);break;case v.UpdateOrder:this.#C(e.order);break;case v.ChangeToken:this.#w(e.token);break;case v.ChangeProperties:this.#k(e.properties),this.#g=void 0;break;case v.SendEvents:this.#y.splice(0,e.events.length);for(let t of e.transferables??[])this.#p.delete(t);break;case v.DestroyEntities:this.#i=_,this.#n=void 0,this.#o=0,this.#v.clear(),this.#g=void 0,this.#t=!0;break}}#w(e){this.#i=e,this.#u===e&&(this.#u=void 0)}#S(e){this.#n=e,(this.#c===Qe?void 0:this.#c)===e&&(this.#c=void 0)}#C(e){this.#o=e,this.#l===e&&(this.#l=void 0)}#k(e){for(let t of e??[]){let r=t[0],i=t.length===1?Ee:t[1];i===void 0?this.#v.delete(r):this.#v.set(r,i),this.#d.get(r)===i&&(this.#d.delete(r),Ht(this.#f,r))}}};var Zn=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},Xr=(s,e)=>{if(s===e||e===void 0)return s;if(s===void 0)return Zn(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 Zn(s)};var Ns=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===v.CreateEntities)this.createEntity(t);else if(this.#e.has(t.uuid))switch(t.type){case v.DestroyEntities:this.destroyEntity(t);break;case v.SetParent:this.setParent(t);break;case v.UpdateOrder:this.updateOrder(t);break;case v.ChangeToken:this.changeToken(t);break;case v.ChangeProperties:this.changeProperties(t);break}}changeProperties({uuid:e,properties:t}){let r=this.getComponentState(e);r.properties=Xr(r.properties,t)}changeToken({uuid:e,token:t}){this.getComponentState(e).token=t||_}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||_,parentUuid:r,order:i??0,properties:Xr(void 0,n),...o?{autoDestructionOnParentRemoval:!0}:{}})}};var _s=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()}},Kt=class extends Error{constructor(e="the component context has been disposed"){super(e),this.name="ComponentContextDisposedError"}},Zr=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}},R=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=Ke(e),r=s.getContextsMap();return r.has(t)?r.get(t):new s(t)}#e=new Map;#t=new _s;#s=!1;#r=new Set;#i(e){let t=this.#e.get(e.uuid);return t!==void 0&&t.component===e?t:void 0}#n=new Ns;#o=new C("ComponentContext");#a;#u(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.#g(r.uuid,r)}#l(){let e=this.#a;e!=null&&(this.#a=void 0,this.#c(e.retiring))}constructor(e=Ye){let t=Ke(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 Kt(`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.#r.has(t.component))throw new Zr(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 _s,changes:new Yt(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.#p(e,this.#t),this.#r.add(e),this.#m=void 0}hasComponent(e){return this.#r.has(e)}hasComponents(){return this.#e.size>0}isRootComponent(e){return this.#i(e)!==void 0&&this.#t.has(e.uuid)}destroyComponent(e){this.#r.delete(e);let t=this.#i(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.#m=void 0}e.context===this&&e.destroy()}getChildren(e){let t=this.#i(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.#i(t);if(r===void 0)return;let i=this.#i(e);i!==void 0&&r.children.delete(e.uuid)&&(i.changes.setParent(void 0),this.#p(i.component,this.#t),this.#m=void 0)}moveToRoot(e){let t=this.#i(e);if(t===void 0)return;(e.parent?this.#i(e.parent):void 0)?.children.delete(e.uuid),t.changes.setParent(void 0),this.#p(t.component,this.#t),this.#m=void 0}changeToken(e,t){this.#i(e)?.changes.changeToken(t)}isChildOf(e,t){let r=this.#i(t);return r!==void 0&&this.#i(e)!==void 0&&r.children.has(e.uuid)}addToChildren(e,t){let r=this.#i(e);if(r){let i=this.#i(t);if(i===void 0)return;this.#p(t,r.children),i.changes.setParent(e.uuid),this.#t.delete(t.uuid),this.#m=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.#h(e,new Set)}#h(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.#h(i,t);this.#g(e),this.destroyComponent(r.component)}}setProperty(e,t,r,i){let n=this.#i(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.#i(e);return r!=null?(r.propIsEqual?.delete(t),r.changes.setPropertyWithoutValue(t)):!1}removeProperty(e,t){this.#i(e)?.changes.removeProperty(t)}transferPropertiesTo(e,t){let r=this.#i(e);if(r!==void 0)for(let[i,n]of r.changes.getProperties()){n===Ee?t.setPropertyWithoutValue(e,i):t.setProperty(e,i,n);let o=r.propIsEqual?.get(i);o!=null&&t.#v(e,i,o)}}#v(e,t,r){let i=this.#i(e);i!==void 0&&(i.propIsEqual??=new Map,i.propIsEqual.set(t,r))}changeOrder(e){let t=this.#i(e);if(t===void 0)return;let r=e.parent?this.#i(e.parent):void 0;r!==void 0?(r.children.delete(e.uuid),this.#p(e,r.children)):e.parent==null&&(this.#t.delete(e.uuid),this.#p(e,this.#t)),t.changes.changeOrder(e.order),this.#m=void 0}traverseLevelOrderBFS(){return this.#w().map(e=>e.component)}dispatchShadowObjectsEvent(e,t,r,i){this.#i(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 Le(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.#r.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)S(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.#y():[],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,we.StructuralChanges);for(let o of i)n(o,we.ContentUpdates);for(let o of i)n(o,we.Removal);return this.#a={entries:t,owners:r,retiring:this.#u(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 Yt(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(zn)}clear(){this.#m=void 0,this.#n.clear(),this.#a=void 0;for(let e of Array.from(this.#r))e.destroy();this.#r.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)}#g(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.#m=void 0}#y(){return this.#w().filter(e=>e.changes.hasChanges()).map(e=>e.changes)}#p(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)}#m;#w(){if(this.#m)return this.#m;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.#m=Array.from(e.entries()).sort((i,n)=>i[0]-n[0]).flatMap(([,i])=>i),this.#m}};var so=16,eo=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)}`},to=!1,Ml=()=>{to||(to=!0,new C("generateUUID").error("no Web Crypto API in this realm: entity uuids come from Math.random() and are not unguessable"));let s=new Uint8Array(so);for(let e=0;e<s.length;e++)s[e]=Math.random()*256|0;return s},ro=()=>{let s=globalThis.crypto;return typeof s?.randomUUID=="function"?s.randomUUID():typeof s?.getRandomValues=="function"?eo(s.getRandomValues(new Uint8Array(so))):eo(Ml())};var Je=class extends Error{constructor(e){super(e),this.name="ViewComponentError"}};function io(s,e){if(s.context==null)throw new Je("cannot add a child to a destroyed view component");if(s.context!==e)throw new Je("cannot add a child from another context");if(!e.hasComponent(s))throw new Je("cannot add a child to a view component its context does not hold")}var Qt=class s{static{this.Destroyed="view-component-destroyed"}#e;#t;#s;#r;#i=0;#n;get uuid(){return this.#e}get token(){return this.#t}set token(e){e??=_,e!==this.#t&&(this.#t=e,this.#s?.changeToken(this,e))}get parent(){return this.#r}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 Kt(`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.#i}set order(e){let t=this.#i;this.#i=e??0,t!==this.#i&&this.#s?.changeOrder(this)}get autoDestructionOnParentRemoval(){return this.#n}constructor(e,t){M(this),t instanceof s&&(t={parent:t}),this.#e=t?.uuid??ro(),this.#t=e??_,this.#i=t?.order??0,this.#r=t?.parent,this.#n=t?.autoDestructionOnParentRemoval??!1;let r=t?.context??R.get();this.#r&&io(this.#r,r),this.context=r}isChildOf(e){return this.#r===e}removeFromParent(){this.#r?(this.#s?.removeFromParent(this,this.#r),this.#r=void 0):this.#s?.moveToRoot(this)}addChild(e){if(e.#s==null)throw new Je("cannot add a destroyed view component as a child");io(this,e.#s);for(let t=this;t!=null;t=t.#r)if(t===e)throw new Je("cannot add the component itself or one of its ancestors as a child: this would create a cycle");e.isChildOf(this)||(e.removeFromParent(),e.#r=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(ne(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,ne(this,s.Destroyed),E(this)}};var ei=s=>s instanceof Set&&s.size===0,no=(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},oo=(s,e,t)=>{if(!t||ei(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===R.ReRequestParentRoots||o===R.ReRequestParent||o===R.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}};var Jt=new WeakMap,ao=new WeakSet,lo=s=>{if(!ao.has(s)){ao.add(s);for(let e of R.getContextsMap().values())e.broadcastEvent(R.ReRequestParent),e.broadcastEvent(R.ReRequestEntHost)}},Fs=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}#r(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})}#i(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.#i(t),Jt.get(t)?.deref()===this.#e&&Jt.set(t,null),lo(e))};collect(){if(this.#e.findShadowRootHost()!=null)for(let e of this.#e.querySelectorAll("slot"))e.assignedNodes().length!==0&&this.#s(e)&&(Jt.set(e,new WeakRef(this.#e)),this.#r(e))}takeUp(e){let t=e.target;if(this.#s(t)){let r=Jt.get(t);Jt.set(t,new WeakRef(this.#e)),this.#r(t),r!==void 0&&r?.deref()!==this.#e&&lo(e)}}releaseAll(){for(let e of this.#t)e.deref()?.removeEventListener("slotchange",this.#n,{capture:!1});this.#t.clear()}};var Xe=new WeakMap,ho=(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)}},Ll=s=>{let e=new Map,t={observer:new MutationObserver((r,i)=>{ho(t,r),e.size===0&&(i.disconnect(),Xe.get(s)===t&&Xe.delete(s))}),watchers:e};return t.observer.observe(s,{childList:!0,subtree:!1,attributes:!1}),t},co=(s,e,t)=>{let r=Xe.get(s);r!=null&&(ho(r,r.observer.takeRecords()),r=Xe.get(s)),r==null&&(r=Ll(s),Xe.set(s,r)),r.watchers.set(e,t)},ti=(s,e)=>{let t=Xe.get(s);t!=null&&t.watchers.delete(e)&&t.watchers.size===0&&(t.observer.disconnect(),Xe.delete(s))};var js=(s,e)=>{s.dispatchEvent(new CustomEvent(Rt,{bubbles:!0,composed:!0,detail:{...e,requester:s}}))};function Xt(s){return function(e,t){let r=s?.name||t.name,i=!!(s?.readAsValue??!1);return{get(){let n=Ir(this,r);if(n)return i?n.value:n.get()},set(n){Ir(this,r)?.set(n)},init(n){let o=f(n,s);return kn(this,r,o),pe.findOrCreate(this).attachSignalByName(r,o),o.value}}}}var ze=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 zl=Object.create,li=Object.defineProperty,Dl=Object.getOwnPropertyDescriptor,fo=(s,e)=>(e=Symbol[s])?e:Symbol.for("Symbol."+s),bt=s=>{throw TypeError(s)},Wl=(s,e,t)=>e in s?li(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,uo=(s,e)=>li(s,"name",{value:e,configurable:!0}),$l=s=>[,,,zl(s?.[fo("metadata")]??null)],go=["class","method","getter","setter","accessor","field","value","get","set"],Zt=s=>s!==void 0&&typeof s!="function"?bt("Function expected"):s,Nl=(s,e,t,r,i)=>({kind:go[s],name:e,metadata:r,addInitializer:n=>t._?bt("Already initialized"):i.push(Zt(n||null))}),po=(s,e)=>Wl(e,fo("metadata"),s[3]),Bs=(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},yo=(s,e,t,r,i,n)=>{var o,a,l,h,u,c=e&7,P=!!(e&8),g=!!(e&16),Q=c>3?s.length+1:c?P?1:2:0,At=go[c+5],Tt=c>3&&(s[Q-1]=[]),cr=s[Q]||(s[Q]=[]),w=c&&(!g&&!P&&(i=i.prototype),c<5&&(c>3||!g)&&Dl(c<4?i:{get[t](){return d(this,n)},set[t](m){return k(this,n,m)}},t));c?g&&c<4&&uo(n,(c>2?"set ":c>1?"get ":"")+t):uo(i,t);for(var Be=r.length-1;Be>=0;Be--)h=Nl(c,t,l={},s[3],cr),c&&(h.static=P,h.private=g,u=h.access={has:g?m=>_l(i,m):m=>t in m},c^3&&(u.get=g?m=>(c^1?d:z)(m,i,c^4?n:w.get):m=>m[t]),c>2&&(u.set=g?(m,Ie)=>k(m,i,Ie,c^4?n:w.set):(m,Ie)=>m[t]=Ie)),a=(0,r[Be])(c?c<4?g?n:w[At]:c>4?void 0:{get:w.get,set:w.set}:i,h),l._=1,c^4||a===void 0?Zt(a)&&(c>4?Tt.unshift(a):c?g?n=a:w[At]=a:i=a):typeof a!="object"||a===null?bt("Object expected"):(Zt(o=a.get)&&(w.get=o),Zt(o=a.set)&&(w.set=o),Zt(o=a.init)&&Tt.unshift(o));return c||po(s,i),w&&li(i,t,w),g?c^4?n:w:i},hi=(s,e,t)=>e.has(s)||bt("Cannot "+t),_l=(s,e)=>Object(e)!==e?bt('Cannot use the "in" operator on this value'):s.has(e),d=(s,e,t)=>(hi(s,e,"read from private field"),t?t.call(s):e.get(s)),D=(s,e,t)=>e.has(s)?bt("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,t),k=(s,e,t,r)=>(hi(s,e,"write to private field"),r?r.call(s,t):e.set(s,t),t),z=(s,e,t)=>(hi(s,e,"access private method"),t),vo=(s,e,t,r)=>({set _(i){k(s,e,i,t)},get _(){return d(s,e,r)}}),mo,wo,F,he,Ze,et,mt,De,si,We,ci,ui,I,wt,O,ri,bo,yt,vt,Is,di,Eo,ii,fi,ni,oi,ai,Co,So,$e=class extends Error{constructor(e="the shadow environment has been destroyed"){super(e),this.name="ShadowEnvDestroyedError"}};wo=[Xt()],mo=[Xt()];var j=class es{constructor(){D(this,O),D(this,F),D(this,he),D(this,Ze,!1),D(this,et,!1),D(this,mt,!1),D(this,De),D(this,si,new C("ShadowEnv")),this.ns$=f(),D(this,ci,Bs(We,8,this,!1)),Bs(We,11,this),D(this,ui,Bs(We,12,this,!1)),Bs(We,15,this),D(this,I,!1),D(this,wt),D(this,yt,0),D(this,vt),D(this,Is),this.ready=async()=>{if(d(this,I))throw new $e;return this.isReady?this:Promise.race([wr(this,es.ContextCreated),z(this,O,di).call(this)])},D(this,ii,()=>{d(this,Ze)&&z(this,O,fi).call(this)});let e=this;oe(e,es.ContextCreated),p(e,es.ContextLost,B.Critical,()=>{Dt(e,es.ContextCreated)})}static get(e){if(e!=null)return globalThis.__shadowEnvs?.get(e)}get logger(){return d(this,si)}get isDestroyed(){return d(this,I)}get view(){return d(this,F)}set view(e){e!==d(this,F)&&(e&&z(this,O,ri).call(this),z(this,O,bo).call(this,d(this,F)?.ns),k(this,F,e??void 0),d(this,F)?.ns&&(globalThis.__shadowEnvs??=new Map,globalThis.__shadowEnvs.has(d(this,F).ns)&&globalThis.__shadowEnvs.get(d(this,F).ns)!==this&&this.logger.warn("overwrite a namespace already in use",d(this,F).ns,globalThis.__shadowEnvs.get(d(this,F).ns)),globalThis.__shadowEnvs.set(d(this,F).ns,this)),this.ns$.set(d(this,F)?.ns),this.viewReady=!!e)}get envProxy(){return d(this,he)}set envProxy(e){if(e!==d(this,he)){e&&z(this,O,ri).call(this);let t=d(this,he);k(this,he,e??void 0);let r=++vo(this,yt)._;d(this,he)&&(d(this,he).onMessageToView=z(this,O,Co).bind(this),d(this,he).onProxyFailed=z(this,O,So).bind(this)),t&&(t.destroy(),t.onProxyFailed=void 0,queueMicrotask(()=>{t.onMessageToView=void 0})),this.proxyReady=!1,e?.start().then(()=>{r===d(this,yt)&&(this.proxyReady=!0)}).catch(i=>{r===d(this,yt)&&(this.logger.error("failed to start envProxy",i),this.proxyReady=!1)})}}get isReady(){return!!(d(this,F)&&d(this,he)&&this.proxyReady&&!this.isDestroyed)}sync(){if(!d(this,I)){if(!this.isReady){k(this,et,!0);return}d(this,Ze)||(k(this,Ze,!0),queueMicrotask(d(this,ii)))}}syncWait(){return d(this,I)?Promise.reject(new $e):(k(this,mt,!0),this.sync(),d(this,De)??k(this,De,z(this,O,Eo).call(this)),d(this,De).promise)}destroy(){var e;d(this,I)||(k(this,I,!0),k(this,Ze,!1),k(this,et,!1),k(this,mt,!1),this.envProxy=void 0,this.view=void 0,(e=d(this,Is))==null||e.call(this,new $e),k(this,De,void 0),d(this,wt)?.destroy(),k(this,wt,void 0),Bt(this),E(this),Object.freeze(this))}};We=$l(null);F=new WeakMap;he=new WeakMap;Ze=new WeakMap;et=new WeakMap;mt=new WeakMap;De=new WeakMap;si=new WeakMap;ci=new WeakMap;ui=new WeakMap;I=new WeakMap;wt=new WeakMap;O=new WeakSet;ri=function(){if(d(this,I)||d(this,wt)!=null)return;let s=this;H(()=>{k(this,wt,T(()=>{if(this.viewReady&&this.proxyReady)return this.view.reCreateChanges(),z(this,O,oi).call(this,j.ContextCreated,s),d(this,et)&&(k(this,et,!1),z(this,O,fi).call(this)),()=>{z(this,O,oi).call(this,j.ContextLost,s)}},[xe(this,"viewReady"),xe(this,"proxyReady")]))})};bo=function(s){if(!s)return;let e=globalThis.__shadowEnvs;e?.get(s)===this&&e.delete(s)};yt=new WeakMap;vt=new WeakMap;Is=new WeakMap;di=function(){return d(this,vt)==null&&(k(this,vt,new Promise((s,e)=>{k(this,Is,e)})),d(this,vt).catch(()=>{})),d(this,vt)};Eo=function(){let s,e,t=new Promise((r,i)=>{s=r,e=i});return{promise:Promise.race([t,z(this,O,di).call(this)]),resolve:s,reject:e}};ii=new WeakMap;fi=async function(){if(k(this,Ze,!1),d(this,I))return;if(!this.isReady){k(this,et,!0);return}let s=this.view.buildChangeTrails(!1),e=d(this,De);k(this,De,void 0);let t=d(this,mt);k(this,mt,!1);try{s.length>0&&await this.envProxy.applyChangeTrail(s,t)}catch(r){if(d(this,I))return;this.logger.error("failed to apply change trail",r),z(this,O,ni).call(this,s,r),z(this,O,ai).call(this,s,e,{reason:r});return}d(this,I)||(z(this,O,ni).call(this,s),z(this,O,ai).call(this,s,e))};ni=function(s,e){let t=e instanceof ze?e.appliedCount:s.length;this.view?.commitChangeTrail(t,s)};oi=function(s,e){try{W(e,s,e)}catch(t){this.logger.error(`a ${s} listener threw`,t)}};ai=function(s,e,t){try{t?(e?.reject(t.reason),W(this,j.SyncFailed,t.reason,s,this)):(e?.resolve(s),W(this,j.AfterSync,s))}catch(r){this.logger.error("a sync cycle listener threw",r)}};Co=function(s){this.logger.debug("onMessageToView",s.type,s.data),this.view?.dispatchMessage(s.uuid,s.type,s.data,s.traverseChildren)};So=function(s){if(!d(this,I)){this.logger.error("the environment proxy failed",s),++vo(this,yt)._;try{W(this,j.ProxyFailed,s,this)}finally{this.proxyReady=!1}}};yo(We,4,"viewReady",wo,j,ci);yo(We,4,"proxyReady",mo,j,ui);po(We,j);j.AfterSync="afterSync";j.SyncFailed="syncFailed";j.ContextLost="contextLost";j.ContextCreated="contextCreated";j.ProxyFailed="proxyFailed";var Y=j;var Us=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 ko=new WeakMap,Ao=s=>`${Array.from(s,e=>CSS.escape(e)).join(",")}{display:contents}`,Fl=s=>s.nodeType===9,jl=s=>s.nodeType===11&&s.host!=null,Vs=(s,e)=>{let t,r,i;if(Fl(s))t=s.head??s.documentElement??s,r=s,i=s;else if(jl(s))t=s,r=s.ownerDocument,i=s;else return;let n=ko.get(i);if(n?.style.isConnected){if(n.tags.has(e))return;n.tags.add(e),n.style.textContent=Ao(n.tags);return}let o=n?.tags??new Set;o.add(e);let a=r.createElement("style");a.textContent=Ao(o),t.prepend(a),ko.set(i,{tags:o,style:a})};var Et=class extends HTMLElement{#e=!1;#t=!1;#s=new Us(()=>this.destroy());get isDestroyed(){return this.#e}connectedCallback(){H(()=>{this.#s.cancel(),this.#e=!1,this.#t||(this.#t=!0,this.restore()),Vs(this.getRootNode(),this.localName)})}disconnectedCallback(){this.#s.schedule()}destroy(){this.#e||(this.#e=!0,this.#t=!1,this.teardown())}restore(){}teardown(){}};var To=(s,e)=>{e.set(Gn(s))},Bl=new C("ShaeElement"),Il=new Le(s=>{for(let e of s.keys())S(Bl,()=>Y.get(e)?.sync(),"a namespace could not be synced:",e)}),Ro=s=>{Il.add(s)},Ne=class extends Et{constructor(){super(),this.isShaeElement=!0,this.ns$=f(Ye),this.#e=!1,To(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(Ke(e))}#e;#t;#s;#r(){this.#s=this.ns$.onChange(e=>this.#i(e))}#i(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.#r(),this.#i(this.ns$.value)}reflectAttribute(e,t){this.#e?t():(this.#t??=new Map,this.#t.set(e,t))}connectedCallback(){H(()=>{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"&&To(this,this.ns$)}syncShadowObjects(){Ro(this.ns)}syncShadowObjectsOf(e){Ro(e)}};var Po=s=>s.assignedSlot??s.parentNode??s.host??void 0,Ul=(s,e)=>{for(let t=Po(s);t!=null;t=Po(t))if(t===e)return!0;return!1},Vl=s=>{for(let e=s.getRootNode();e?.host!=null;e=e.host.getRootNode())if(e.mode==="closed")return!0;return!1},Gs=class extends Ne{constructor(){super(),this.isShaeEntElement=!0,this.componentContext$=f(),this.viewComponent$=f(),this.token$=f(),this.forwardCustomEvents$=f(!1),this.#e=new C("ShaeEntElement"),this.#t=this.isConnected,this.#r=f(0),this.#i=new pt(()=>{this.#r.set(this.#r.value+1)}),this.#y=e=>{let t=this.token$.value,r=this.viewComponent$.value;try{r?r.context=e:e&&(r=new Qt(t??_,{context:e,autoDestructionOnParentRemoval:Oe(this,Li)}),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.#C=!0,this.#M=new Fs(this),this.#z=e=>{this.#T(),this.#M.takeUp(e);let t=this.findShadowRootHost();t!=null&&this.dispatchEvent(new CustomEvent(hs,{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.#P()},this.#W=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.#$(),this.#_()}static{this.observedAttributes=[...Ne.observedAttributes,de,J]}#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;#r;#i;#n;#o;#a;#u;#c;#l;#h(){this.#n=this.ns$.onChange(e=>{let t=this.componentContext,r=t?.ns,i=this.viewComponent;t!=null&&i!=null&&t.dispatchReRequestParentChildren(i),this.#x(void 0),this.componentContext$.set(R.get(e)),this.isConnected&&(this.#P(),this.#E()),r!=null&&r!==e&&this.syncShadowObjectsOf(r)}),this.#o=this.token$.onChange(e=>this.#v(e)),this.#a=this.forwardCustomEvents$.onChange(e=>this.#d(e)),this.#u=T(()=>{let e=this.viewComponent$.get();if(this.#r.get(),!e)return;let t=[p(e,R.ReRequestParentRoots,()=>this.#O()),p(e,R.ReRequestParent,r=>this.#R(r?.newAncestor)),p(e,R.ReRequestEntHost,()=>this.#T()),p(e,Qt.Destroyed,()=>this.#i.schedule())];return()=>{for(let r of t)r()}}),this.#c=T(()=>{let e=this.viewComponent$.get();if(this.#r.get(),!!e)return oo(e,this,this.forwardCustomEvents$.get())}),this.#l=this.token$.onChange(e=>this.#f(e))}#v(e){this.reflectAttribute(de,()=>{e==null?this.removeAttribute(de):this.getAttribute(de)!==e&&this.setAttribute(de,e)})}#d(e){this.reflectAttribute(J,()=>{if(!e||ei(e))this.removeAttribute(J);else if(e===!0)this.getAttribute(J)!==""&&this.setAttribute(J,"");else{let t=Array.from(e).join(",");this.getAttribute(J)!==t&&this.setAttribute(J,t)}})}#f(e){let t=this.viewComponent$.value;t==null||t.token===e||(t.token=e,this.syncShadowObjects())}restore(){super.restore(),this.#h(),this.#v(this.token$.value),this.#d(this.forwardCustomEvents$.value),this.#f(this.token$.value)}#g;#y;#p(){this.#g?.();let e=this.componentContext$.onChange(this.#y);this.#g=()=>{e()}}#m(){this.#g?.(),this.#g=void 0}#w(){return this.getRootNode()?.host}#S;#C;findShadowRootHost(){return this.#C&&(this.#C=!1,this.#S=this.#w()),this.#S}getParentNodeForObserver(){return this.parentNode??this.#w()??void 0}connectedCallback(){H(()=>{super.connectedCallback(),this.#C=!0,this.addEventListener("slotchange",this.#z,{capture:!1,passive:!1}),this.addEventListener(Rt,this.#W,{capture:!1,passive:!1}),this.#p(),_r(()=>this.#$());let e=this.#N();no(e,this.forwardCustomEvents$.value)||this.forwardCustomEvents$.set(e),this.componentContext==null?this.componentContext$.set(R.get(this.ns)):this.#y(this.componentContext),this.#P(),this.#t&&(this.#E(),this.#T()),this.#M.collect(),this.#k(),this.syncShadowObjects()})}#k(){this.#b();let e=this.getParentNodeForObserver();if(e){co(e,this,()=>{this.#s=void 0;let r=this.getParentNodeForObserver();if(r===e){this.#k();return}this.onParentChanged(r,e)});let t=this.getParentNodeForObserver();if(t===e)this.#s=e;else if(ti(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&&(ti(this.#s,this),this.#s=void 0)}onParentChanged(e,t){this.#x(void 0),this.#P(),this.#k()}attributeChangedCallback(e){super.attributeChangedCallback(e),e===de?this.#$():e===J&&this.#_()}disconnectedCallback(){this.#C=!0,this.#b(),this.#M.releaseAll(),this.#A(),this.#T(),this.#x(void 0);let e=this.viewComponent;e!=null&&this.componentContext?.dispatchReRequestParentChildren(e),this.componentContext$.set(void 0),this.syncShadowObjects(),this.#m(),super.disconnectedCallback()}teardown(){if(this.#n?.(),this.#n=void 0,this.#o?.(),this.#o=void 0,this.#a?.(),this.#a=void 0,this.#u?.destroy(),this.#u=void 0,this.#c?.destroy(),this.#c=void 0,this.#l?.(),this.#l=void 0,this.#m(),this.#b(),this.#M.releaseAll(),this.#x(void 0),this.isConnected){this.#A(),this.#T();let e=this.viewComponent;e!=null&&this.componentContext?.dispatchReRequestParentChildren(e)}super.teardown()}#A(){this.removeEventListener("slotchange",this.#z,{capture:!1}),this.removeEventListener(Rt,this.#W,{capture:!1})}#O(){this.isConnected&&(this.#x(void 0),this.#P())}#R(e){this.isConnected&&(e?.isConnected&&!Ul(this,e)||this.#P())}#E(){let e=this.viewComponent;if(e==null)return;let t=Vl(this)?void 0:this;this.componentContext?.collectPeerReRequest(e,{newAncestor:t})}#T(){this.dispatchEvent(new CustomEvent(Pt,{bubbles:!0,composed:!0,detail:{requester:this}}))}#P(){let e;js(this,{ns:this.ns,answer:t=>e=t}),this.#x(e)}#L;#x(e){if(this.entParentNode!==e)if(this.entParentNode&&this.entParentNode.removeEventListener(hs,this.#D,{capture:!1}),this.entParentNode=e,this.entParentNode&&this.entParentNode.addEventListener(hs,this.#D,{capture:!1,passive:!1}),this.#L?.(),this.#L=void 0,e){let t=T(()=>{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.#P()}),this.syncShadowObjects()}});this.#L=()=>t.destroy()}else{let t=this.viewComponent;t?.parent&&(t.parent=void 0,this.syncShadowObjects())}}#M;#z;#D;#W;#$(){if(this.hasAttribute(de)){let e=this.getAttribute(de)?.trim()||void 0;this.token$.set(e)}else this.token$.set(void 0)}#N(){if(!this.hasAttribute(J))return!1;let e=this.getAttribute(J);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}#_(){this.forwardCustomEvents$.set(this.#N())}};customElements.define(Oi,Gs);var se=s=>s.split(/\W+/),ts=s=>s.split(/\s+/),yi=(s,e)=>{if(Number.isNaN(s))throw new TypeError(`not a number: "${e}"`);return s},pi=s=>e=>yi(s(e),e),Hs=(s,e)=>t=>e(t).map(r=>yi(s(r),r)),qs=s=>pi(e=>parseInt(e,s)),gi=s=>Hs(e=>parseInt(e,s),se),Ce=(s,e)=>t=>new s(e(t).map(r=>yi(Number(r),r))),xo=s=>e=>new s(se(e).map(t=>BigInt(t))),Gl=s=>Gt.has(s.toLowerCase()),ql=[[["string","text"],s=>s],[["number"],pi(Number)],[["bigint"],s=>BigInt(s)],[["float"],pi(parseFloat)],[["int","integer"],qs(10)],[["hex","hexadecimal"],qs(16)],[["oct","octal"],qs(8)],[["bin","binary"],qs(2)],[["bool","boolean"],Gl],[["[]","text[]","string[]"],se],[["number[]"],Hs(Number,ts)],[["float[]"],Hs(parseFloat,ts)],[["int[]","integer[]"],Hs(s=>parseInt(s,10),ts)],[["hex[]","hexadecimal[]"],gi(16)],[["oct[]","octal[]"],gi(8)],[["bin[]","binary[]"],gi(2)],[["bool[]","boolean[]"],s=>se(s).map(e=>Gt.has(e.toLowerCase()))],[["int8array"],Ce(Int8Array,se)],[["uint8array"],Ce(Uint8Array,se)],[["uint8clampedarray"],Ce(Uint8ClampedArray,se)],[["int16array"],Ce(Int16Array,se)],[["uint16array"],Ce(Uint16Array,se)],[["int32array"],Ce(Int32Array,se)],[["uint32array"],Ce(Uint32Array,se)],[["float32array"],Ce(Float32Array,ts)],[["float64array"],Ce(Float64Array,ts)],[["bigint64array"],xo(BigInt64Array)],[["biguint64array"],xo(BigUint64Array)],[["json"],s=>JSON.parse(s)]],vi=new Map(ql.flatMap(([s,e])=>s.map(t=>[t,e])));var Ys=new WeakMap,Hl=(s,e)=>{let t=Ys.get(s);t==null&&(t=new Map,Ys.set(s,t)),t.set(e,(t.get(e)??0)+1)},Yl=(s,e)=>{let t=Ys.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&&Ys.delete(s),!0)},Ks=class extends Et{constructor(){super(),this.isShaePropElement=!0,this.entNode$=f(),this.viewComponent$=f(),this.name$=f(),this.valueIn$=f(),this.valueOut$=f(),this.type$=f(),this.shouldTrim$=f(!0),this.#e=new C("ShaePropElement"),this.#n=!1,this.#a=new pt(()=>{this.isConnected&&!this.isDestroyed&&this.#c()}),this.#c=()=>{let e;js(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.#h()},this.#l=()=>{this.#a.schedule()},this.#h=()=>{let e=this.entNode$.value??this.ownerDocument;e!==this.#o&&(this.#v(),e.addEventListener(Pt,this.#l),this.#o=e)},this.#v=()=>{this.#o?.removeEventListener(Pt,this.#l),this.#o=void 0},this.#d=()=>{queueMicrotask(()=>{this.isConnected||this.entNode$.set(void 0)})},this.#f=()=>{this.name$.set(this.getAttribute(us)?.trim()??void 0)},this.#g=()=>{let e=this.getAttribute(ds);this.valueIn$.set(e===null||e===""?void 0:e)},this.#y=()=>{let e=this.getAttribute(fs)?.trim().toLowerCase();e&&!vi.has(e)&&(this.logger.warn(`[${this.name}] unknown type "${e}"`,{shaeProp:this}),e=void 0),this.type$.set(e)},this.#p=()=>{this.shouldTrim$.set(!Oe(this,gs))},q(()=>{this.#f(),this.#g(),this.#y(),this.#p()})}static{this.observedAttributes=[us,ds,fs,gs]}#e;get logger(){return this.#e}#t;#s;#r;#i;#n;#o;#a;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}#u(){this.#t=this.entNode$.onChange(e=>{if(e){let t=me(e.viewComponent$,this.viewComponent$);return()=>{t.destroy()}}else this.viewComponent$.set(void 0)}),this.#s=T(()=>{let e=this.viewComponent$.get(),t=this.name$.get();if(e==null||!t)return;let r=this.entNode$.value;return Hl(e,t),()=>{Yl(e,t)&&(e.removeProperty(t),r?.syncShadowObjects())}}),this.#r=T(()=>{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.#i=T(()=>{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=vi.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.#u()}connectedCallback(){H(()=>{super.connectedCallback(),q(()=>{this.#c(),this.#f(),this.#g(),this.#y(),this.#p()})})}attributeChangedCallback(e){switch(e){case us:this.#f();break;case ds:this.#g();break;case fs:this.#y();break;case gs:this.#p();break}}disconnectedCallback(){this.#v(),this.#d(),super.disconnectedCallback()}teardown(){this.#v(),this.#t?.(),this.#t=void 0,this.#s?.destroy(),this.#s=void 0,this.#r?.destroy(),this.#r=void 0,this.#i?.destroy(),this.#i=void 0,super.teardown()}#c;#l;#h;#v;#d;#f;#g;#y;#p};customElements.define(Mi,Ks);var Oo=null,ss=class s{static{this.OnFrame=Symbol("onFrame")}static get(){return Oo??=new s,Oo}static#e=.75;#t=0;#s=0;#r=0;#i=void 0;constructor(e=0){M(this),this.maxFps=e}get maxFps(){return this.#s}set maxFps(e){this.#s=Number.isFinite(e)&&e>0?e:0}get subscriptionCount(){return on(this)}start(e){if(e!=null)return p(this,s.OnFrame,e),this.#a(),()=>{this.stop(e)}}stop(e){e!=null&&(E(this,s.OnFrame,e),this.subscriptionCount===0&&(this.#u(),this.#i=void 0,this.#r=0))}#n=e=>{if(this.#t=0,this.#o(e)){let t=this.#i??e;this.#i=e,this.#r+=1;let r={now:e/1e3,lastNow:t/1e3,frameNo:this.#r,deltaTime:(e-t)/1e3};ne(this,s.OnFrame,r)}this.subscriptionCount>0&&this.#a()};#o(e){return this.#s===0||this.#i===void 0?!0:e-this.#i>=s.#e*(1e3/this.#s)}#a(){this.#t===0&&(this.#t=requestAnimationFrame(this.#n))}#u(){this.#t!==0&&(cancelAnimationFrame(this.#t),this.#t=0)}};var Mo=`module has no "${Vt}" export`;async function mi(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=>mi(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 Qs=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 Js=Symbol("onCreate"),K=Symbol("onDestroy"),wi=Symbol("onParentChanged"),Ct=Symbol("onViewEvent");var Kl=Object.create,bi=Object.defineProperty,Ql=Object.getOwnPropertyDescriptor,Do=(s,e)=>(e=Symbol[s])?e:Symbol.for("Symbol."+s),kt=s=>{throw TypeError(s)},Jl=(s,e,t)=>e in s?bi(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,Lo=(s,e)=>bi(s,"name",{value:e,configurable:!0}),Xl=s=>[,,,Kl(s?.[Do("metadata")]??null)],Wo=["class","method","getter","setter","accessor","field","value","get","set"],rs=s=>s!==void 0&&typeof s!="function"?kt("Function expected"):s,Zl=(s,e,t,r,i)=>({kind:Wo[s],name:e,metadata:r,addInitializer:n=>t._?kt("Already initialized"):i.push(rs(n||null))}),$o=(s,e)=>Jl(e,Do("metadata"),s[3]),zo=(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},eh=(s,e,t,r,i,n)=>{var o,a,l,h,u,c=e&7,P=!!(e&8),g=!!(e&16),Q=c>3?s.length+1:c?P?1:2:0,At=Wo[c+5],Tt=c>3&&(s[Q-1]=[]),cr=s[Q]||(s[Q]=[]),w=c&&(!g&&!P&&(i=i.prototype),c<5&&(c>3||!g)&&Ql(c<4?i:{get[t](){return U(this,n)},set[t](m){return ns(this,n,m)}},t));c?g&&c<4&&Lo(n,(c>2?"set ":c>1?"get ":"")+t):Lo(i,t);for(var Be=r.length-1;Be>=0;Be--)h=Zl(c,t,l={},s[3],cr),c&&(h.static=P,h.private=g,u=h.access={has:g?m=>th(i,m):m=>t in m},c^3&&(u.get=g?m=>(c^1?U:_e)(m,i,c^4?n:w.get):m=>m[t]),c>2&&(u.set=g?(m,Ie)=>ns(m,i,Ie,c^4?n:w.set):(m,Ie)=>m[t]=Ie)),a=(0,r[Be])(c?c<4?g?n:w[At]:c>4?void 0:{get:w.get,set:w.set}:i,h),l._=1,c^4||a===void 0?rs(a)&&(c>4?Tt.unshift(a):c?g?n=a:w[At]=a:i=a):typeof a!="object"||a===null?kt("Object expected"):(rs(o=a.get)&&(w.get=o),rs(o=a.set)&&(w.set=o),rs(o=a.init)&&Tt.unshift(o));return c||$o(s,i),w&&bi(i,t,w),g?c^4?n:w:i},Ei=(s,e,t)=>e.has(s)||kt("Cannot "+t),th=(s,e)=>Object(e)!==e?kt('Cannot use the "in" operator on this value'):s.has(e),U=(s,e,t)=>(Ei(s,e,"read from private field"),t?t.call(s):e.get(s)),Xs=(s,e,t)=>e.has(s)?kt("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,t),ns=(s,e,t,r)=>(Ei(s,e,"write to private field"),r?r.call(s,t):e.set(s,t),t),_e=(s,e,t)=>(Ei(s,e,"access private method"),t),No,ce,Fe,os,Ci,Se,Zs,is,St="value";No=[Xt({name:St})];var ue=class{constructor(e){Xs(this,Se),Xs(this,ce,[]),Xs(this,Fe),Xs(this,Ci,zo(os,8,this)),zo(os,11,this),this.value$=void 0,oe(this,St),this.value$=xe(this,St),this.value$.onChange(t=>ne(this,St,t)),e&&this.add(...e)}add(...e){return U(this,ce).push(...e),_e(this,Se,is).call(this),_e(this,Se,Zs).call(this,e)}unshift(...e){return U(this,ce).unshift(...e),_e(this,Se,is).call(this),_e(this,Se,Zs).call(this,e)}remove(...e){_e(this,Se,Zs).call(this,e)()}clear(){U(this,ce).length=0,_e(this,Se,is).call(this)}dispose(){this.clear(),U(this,Fe)?.destroy(),ns(this,Fe,void 0),Dt(this,St),E(this),this.value$.destroy(),Bt(this)}};os=Xl(null);ce=new WeakMap;Fe=new WeakMap;Ci=new WeakMap;Se=new WeakSet;Zs=function(s){return()=>{for(let e of s){let t=U(this,ce).indexOf(e);t!==-1&&U(this,ce).splice(t,1)}_e(this,Se,is).call(this)}};is=function(){U(this,Fe)?.destroy(),U(this,ce).length===0?(ns(this,Fe,void 0),this.value=void 0):(ns(this,Fe,T(()=>{let s;for(let e of U(this,ce)){let t=dt(e);if(t!=null){s=t;break}}this.value=s},U(this,ce))),U(this,Fe).run())};eh(os,4,"value",No,ue,Ci);$o(os,ue);ue.Value=St;var _o=new WeakMap,sh=s=>{let e=_o.get(s);return e==null&&(e=new Le(t=>{for(let[r,i]of t)S(s.logger,()=>r.set(i.value),`an effect of a context value failed (${String(i.name)}):`,i.uuid)}),_o.set(s,e)),e},rh=(s,e,t,r,i)=>{sh(s).add(e,{value:t,name:r,uuid:i})},er=class s{#e;#t;#s=new zs;#r=new Map;#i=new Map;#n;#o=new Set;#a=[];#u=0;#c=!1;get kernel(){return this.#e}get uuid(){return this.#t}get order(){return this.#u}set order(e){this.#u!==e&&(this.#u=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.#p(),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)}}[K](){if(!this.#c){this.#c=!0,this.#h("properties",()=>this.#s.clear()),this.#h("listeners",()=>E(this)),this.#h("auto-destruction subscription",()=>this.#g?.());for(let e of this.#i.values())this.#h("global context cleanup",()=>e.cleanup()),this.#h("global context signal",()=>e.signal.destroy());for(let e of this.#r.values())this.#h("context value reset",()=>e.context.set(void 0)),this.#h("context value subscription",()=>e.unsubscribePathValue()),this.#h("context parent subscription",()=>e.unsubscribeFromParent?.()),this.#h("context value path",()=>e.valuePath.dispose()),this.#h("inherited context signal",()=>e.inherited.destroy()),this.#h("provided context signal",()=>e.provide.destroy()),this.#h("context signal",()=>e.context.destroy());this.#i.clear(),this.#r.clear(),this.#n=void 0,this.#o.clear(),this.#a.length=0}}#h(e,t){S(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.#v(e);for(let[,t]of e.#r)e.#A(t)}#v(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.#r)this.#A(t);this.#y(),this.#e.noteEntityTreeChange(this.#t)}}#f=!1;#g;get autoDestructionOnParentRemoval(){return this.#f}set autoDestructionOnParentRemoval(e){this.#f!==e&&(this.#f=e,this.#p())}#y(){this.#g&&(this.#g(),this.#g=void 0)}#p(){this.#y(),this.#f&&this.#n&&(this.#g=A(this.#n,K,B.Max,()=>{this.#g=void 0,this.#e.destroyEntity(this.#t)}))}reSubscribeToParentContexts(){for(let[,e]of this.#r)this.#A(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)S(this.#e.logger,()=>W(this,Ct,t,r),"entity view event delivery failed:",t,this.#t)}dispatchViewEvent(e,t){this.dispatchViewEvents([{type:e,data:t}])}#m(e){return this.#s.get(e)}getPropertyReader(e){return this.#m(e).get}getPropertyWriter(e){let t=this.#m(e);return(r,i)=>{this.clearTruthyPropsCache(),t.set(r,i)}}setProperties(e){q(()=>{for(let[t,r]of e)this.setProperty(t,r)})}setProperty(e,t){this.getPropertyWriter(e)(t)}getProperty(e){return dt(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.#r.has(e)}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.#k(e).signal}attachContextProvider(e,t){let r=this.#b(e);return s.#S(t,r.provide,r.providerFeeds)}attachGlobalContextProvider(e,t){let r=this.#k(e);return s.#S(t,r.signal,r.providerFeeds)}static#S(e,t,r){let i=me(e,t);return r.add(i),()=>{r.delete(i)&&(i.destroy(),s.#C(r))}}static#C(e){let t;for(let r of e)!r.isDestroyed&&r.source.value!=null&&(t=r);t?.touch()}#k(e){if(this.#i.has(e))return this.#i.get(e);let t=this.#e.findOrCreateRootContext(e),r=f(),n={cleanup:t.add(r),signal:r,providerFeeds:new Set};return this.#i.set(e,n),n}#b(e){if(this.#r.has(e))return this.#r.get(e);let t=f(),r=f(),i=f(),n=new ue([r,t]),o=p(n,ue.Value,l=>{rh(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.#r.set(e,a),this.#A(a),a}#A(e){if(e.unsubscribeFromParent?.(),e.unsubscribeFromParent=void 0,this.parent){let t=this.parent.#b(e.name),r=me(t.context,e.inherited);e.unsubscribeFromParent=r.destroy.bind(r)}else{let t=this.#e.findOrCreateRootContext(e.name),r=me(t.value$,e.inherited);e.unsubscribeFromParent=r.destroy.bind(r)}}};var Fo=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]}},tr=(s,e)=>{for(let t of e)s.add(t)},ih=(s,e)=>{if(s!=null)for(let t of s)e.add(t)},tt=class{static get(e){return e??nh}#e=new Map;#t=new Map;#s=new Map;#r=new Set;#i=new Map;define(e,t){let r=this.#e.get(e);r?Xn(r,t):this.#e.set(e,[t]),this.#n()}appendRoute(e,t){let r=Fo(e);if(r){this.#r.add(r.prop);let i=this.#s.get(r.key);i?tr(i,t):this.#s.set(r.key,new Set(t))}else{let i=this.#t.get(e);i?tr(i,t):this.#t.set(e,new Set(t))}this.#n()}clearRoute(e){let t=Fo(e);t?this.#s.delete(t.key):this.#t.delete(e),this.#n()}#n(){this.#i.clear()}#o(e){if(e===void 0||this.#r.size===0)return"";let t="";for(let r of e)this.#r.has(r)&&(t+=`${r.length}:${r}`);return t}#a(e,t){let r=this.#o(t),i=this.#i.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&&tr(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&&tr(o,c)}}while(l!==o.size)}return i===void 0&&(i=new Map,this.#i.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)ih(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)}clear(){this.#e.clear(),this.#t.clear(),this.#s.clear(),this.#r.clear(),this.#n()}},nh=new tt;var Si=s=>s??void 0;var je=()=>{let s=f(void 0);return x(s),s},oh=()=>{let s=T(()=>{},{autorun:!1});return s.destroy(),s},jo=()=>{},sr=class{#e;#t;#s;#r;#i=new Set;#n=new Set;#o=new Set;#a=new Map;#u=new Map;#c=new Map;#l=new Map;#h=new Map;#v=new Map;#d=new Set;#f=new Map;#g=new Map;#y;#p;#m;#w;#S=!1;#C=!1;#k;get displayName(){return this.#s}get debugHandles(){return{shadowObject:this.#y,releaseScope:this.#p,forgetShadowObject:this.#m,unsubscribeFromEntityDestroy:this.#w}}get debugCleanupCounts(){return{primary:this.#i.size,secondary:this.#n.size,contextFeeds:this.#o.size}}constructor(e,t,r,i){this.#e=e,this.#t=t,this.#s=r,this.#r=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.#S)throw new Error(`the creation scope of "${this.#s}" has torn down and cannot be bound`);if(this.#y!==void 0)throw new Error(`the creation scope of "${this.#s}" is already bound to a shadow-object`);this.#y=e,this.#p=t,this.#m=r,this.#t.info("create shadow-object",this.#s,{shadowObject:e,entity:this.#e}),this.#w=A(this.#e,K,B.Low,()=>{this.tearDown()})}tearDown(){if(this.#S)return;this.#S=!0,this.#b("scope release",()=>this.#p?.()),this.#b("entity destroy subscription",()=>this.#w?.()),this.#y!==void 0&&this.#t.info("destroy shadow-object",this.#s,{shadowObject:this.#y,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.#i,"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",()=>x(i));for(let i of this.#c.values())this.#b("parent context reader",()=>x(i));for(let i of this.#f.values())this.#b("property reader",()=>x(i));for(let i of this.#h.values())this.#b("context provider",()=>x(i));for(let i of this.#v.values())this.#b("global context provider",()=>x(i));this.#i.clear(),this.#n.clear(),this.#o.clear(),this.#a.clear(),this.#u.clear(),this.#c.clear(),this.#l.clear(),this.#f.clear(),this.#g.clear(),this.#h.clear(),this.#v.clear(),this.#d.clear(),this.#b("forget shadow-object",()=>this.#m?.()),this.#y=void 0,this.#p=void 0,this.#m=void 0,this.#w=void 0,this.#C=!0}#b(e,t){S(this.#t,t,`shadow-object teardown failed (${e}):`,this.#s)}#A(e){return this.#n.add(e),Object.assign(()=>{this.#n.delete(e),e()},e)}#O(e,t,r,i,n,o,a){let l=t.get(e);if(l===void 0){l=f(void 0,n).get,t.set(e,l),r.set(e,n?.compare);let h=me(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}#R(e,t){typeof e!="function"||this.#r.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.#r.add(t))}#E(e){return this.#C?(this.#k?.has(e)||((this.#k??=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 je().get;this.#R(t,"useProperty");let r=typeof t=="function"?{compare:t}:t;return this.#O(e,this.#f,this.#g,()=>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}#T(e,t,r,i,n){let o=t.get(e);if(o==null){let a=Re(i),l=a?void 0:Si(i);if(o=f(l,n?.compare?{compare:n.compare}:void 0),a){let h=me(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 je();this.#R(r,"provideContext");let i=typeof r=="function"?{compare:r}:r;return this.#T(e,this.#h,n=>this.#e.attachContextProvider(e,n),t,i)}provideGlobalContext(e,t,r){if(this.#E("provideGlobalContext"))return je();this.#R(r,"provideGlobalContext");let i=typeof r=="function"?{compare:r}:r;return this.#T(e,this.#v,n=>this.#e.attachGlobalContextProvider(e,n),t,i)}useContext(e,t){if(this.#E("useContext"))return je().get;this.#R(t,"useContext");let r=typeof t=="function"?{compare:t}:t;return this.#O(e,this.#a,this.#u,()=>this.#e.useContext(e),r,"useContext","context")}useParentContext(e,t){if(this.#E("useParentContext"))return je().get;this.#R(t,"useParentContext");let r=typeof t=="function"?{compare:t}:t;return this.#O(e,this.#c,this.#l,()=>this.#e.useParentContext(e),r,"useParentContext","parent context")}createSignal(...e){if(this.#E("createSignal"))return je();let t=f(...e);return this.#n.add(()=>{x(t)}),t}createEffect(...e){if(this.#E("createEffect"))return oh();let t=T(...e);return this.#n.add(t.destroy),t}createMemo(...e){if(this.#E("createMemo"))return je().get;let t=Mn(...e);return this.#n.add(()=>{x(t)}),t}createResource(e,t){if(this.#E("createResource"))return je();let r=f(),i=T(()=>{let n=Si(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),x(r)}}),r}on(...e){if(this.#E("on"))return jo;let[t]=e,r=typeof t=="string"||typeof t=="symbol"||Array.isArray(t)?p(this.#e,...e):p(...e);return this.#A(r)}once(...e){if(this.#E("once"))return jo;let[t]=e,r=typeof t=="string"||typeof t=="symbol"||Array.isArray(t)?A(this.#e,...e):A(...e);return this.#A(r)}emit(...e){if(this.#E("emit"))return;let[t]=e;typeof t=="string"||typeof t=="symbol"||Array.isArray(t)?b(this.#e,...e):b(...e)}onViewEvent(e){if(this.#E("onViewEvent"))return;let t=p(this.#e,Ct,(r,i)=>{e(r,i)});this.#n.add(t)}onDestroy(e){this.#E("onDestroy")||this.#i.add(e)}dispatchMessageToView(e,t,r,i=!1){this.#E("dispatchMessageToView")||this.#e.dispatchMessageToView(e,t,r,i)}};var Bo=s=>s.displayName||s.name,ah=[["onCreate",Js],["onDestroy",K],["onParentChanged",wi],["onViewEvent",Ct]],rr=class{#e=new C("Kernel");get logger(){return this.#e}#t=new Map;#s=new Set;#r=[];#i=[];#n=!0;#o=new Map;#a=new WeakMap;#u=new Set;constructor(e){M(this),this.registry=tt.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)}get debugEntityCounts(){return{entities:this.#t.size,rootEntities:this.#s.size,traversal:this.#r.length,traversalReversed:this.#i.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.#r=Array.from(t.entries()).sort((n,o)=>n[0]-o[0]).flatMap(([,n])=>n),this.#i=this.#r.slice().reverse(),this.#n=!1}return e?this.#i.slice():this.#r.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{q(()=>{for(let r of e.changeTrail)this.#h(r),t++})}catch(r){throw new ze(t,e.changeTrail.length,{cause:r})}}#h(e){switch(e.type){case v.CreateEntities:this.createEntity(e.uuid,e.token,e.parentUuid,e.order,e.properties,e.autoDestructionOnParentRemoval);break;case v.DestroyEntities:this.destroyEntity(e.uuid);break;case v.SetParent:this.setParent(e.uuid,e.parentUuid,e.order);break;case v.UpdateOrder:this.updateOrder(e.uuid,e.order);break;case v.ChangeProperties:this.changeProperties(e.uuid,e.properties);break;case v.ChangeToken:this.changeToken(e.uuid,e.token);break;case v.SendEvents:this.dispatchEventsToEntity(e.uuid,e.events);break}}createEntity(e,t,r,i=0,n,o=!1){if(this.#t.has(e))throw new Qs(e);let a=new er(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.#y(l)}catch(h){throw this.#v(e),h}}#v(e){S(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)S(this.logger,()=>{a.autoDestructionOnParentRemoval?this.destroyEntity(a.uuid):a.removeFromParent()},"child of a destroyed entity could not be handed on:",a.uuid);S(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)E(r,a),this.#m(a,r);S(this.logger,()=>W(r,K,r),"entity onDestroy notification failed:",r.uuid);for(let a of o)S(this.logger,()=>this.#a.get(a)?.tearDown(),"creation scope teardown of a destroyed entity failed:",r.uuid);S(this.logger,()=>r[K](),"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}),S(this.logger,()=>W(i,wi,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(()=>{ne(this,ft,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 P of c)this.#w(P,n.entity)}}if(a){for(let u of r)if(!n.usedConstructors.has(u))try{h.push(this.#g(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--)S(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++)S(this.logger,()=>this.#g(n,e),"rollback of a failed shadow-object update could not restore a shadow-object:",Bo(n),e.entity.uuid)}}#g(e,t){let r=new sr(t.entity,this.logger,Bo(e),this.#u),i;try{i=M(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.#p(i,t.entity)}catch(o){throw this.#w(i,t.entity),o}return i}#y(e){this.registry.findConstructors(e.token,e.entity.truthyProps())?.forEach(t=>{this.#g(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))))}#p(e,t){for(let[r,i]of ah)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)}p(t,e),typeof e[Js]=="function"&&e[Js](t)}#m(e,t){let r=this.#a.get(e)?.displayName;typeof e[K]=="function"&&S(this.logger,()=>e[K](t),"shadow-object onDestroy hook failed:",r),S(this.logger,()=>W(e,K,t),"shadow-object onDestroy notification failed:",r)}#w(e,t){this.#m(e,t),this.#a.get(e)?.tearDown(),E(t,e)}findOrCreateRootContext(e){let t=this.#o.get(e);return t||(t=new ue,this.#o.set(e,t)),t}destroy(){for(let e of this.traverseLevelOrderBFS(!0))S(this.logger,()=>this.destroyEntity(e.uuid),"entity teardown during kernel destroy failed:",e.uuid);this.#t.clear(),this.#s.clear(),this.#r.length=0,this.#i.length=0,this.#n=!0;for(let e of this.#o.values())e.dispose();this.#o.clear(),queueMicrotask(()=>{E(this)})}};var ir=s=>(typeof s=="string"&&(s=new URL(s,globalThis.location.href)),s.toString());function Io(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 nr=class{constructor(e){this.#e=new Set,this.isLocalEnv=!0,this.disableStructuredClone=!1,this.kernel=new rr(e),this.#t=this.kernel.registry===tt.get(),p(this.kernel,ft,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:Io(e)},i;try{this.kernel.run(r),i=Promise.resolve()}catch(n){i=Promise.reject(n)}return t?i.then(()=>{}):i}async importScript(e){let t=await import(ir(e));if(!t[Vt])throw new Error(Mo);await this.importModule(t[Vt])}async importModule(e){return mi(this.kernel,e,this.#e)}destroy(){this.kernel.destroy(),this.#t||this.registry.clear(),this.#e.clear()}};function ki(s){let e=new Blob([s],{type:"text/javascript"}),t=URL.createObjectURL(e),r=new Worker(t);return URL.revokeObjectURL(t),r}function Ai(){return ki('var va=Object.defineProperty,ba=Object.defineProperties;var ma=Object.getOwnPropertyDescriptors;var wr=Object.getOwnPropertySymbols;var Mn=Object.prototype.hasOwnProperty,Tn=Object.prototype.propertyIsEnumerable;var wa=(s,e)=>(e=Symbol[s])?e:Symbol.for("Symbol."+s),Ln=s=>{throw TypeError(s)};var ci=(s,e,t)=>e in s?va(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,ue=(s,e)=>{for(var t in e||(e={}))Mn.call(e,t)&&ci(s,t,e[t]);if(wr)for(var t of wr(e))Tn.call(e,t)&&ci(s,t,e[t]);return s},Dn=(s,e)=>ba(s,ma(e));var Bn=(s,e)=>{var t={};for(var r in s)Mn.call(s,r)&&e.indexOf(r)<0&&(t[r]=s[r]);if(s!=null&&wr)for(var r of wr(s))e.indexOf(r)<0&&Tn.call(s,r)&&(t[r]=s[r]);return t};var p=(s,e,t)=>ci(s,typeof e!="symbol"?e+"":e,t),hi=(s,e,t)=>e.has(s)||Ln("Cannot "+t);var i=(s,e,t)=>(hi(s,e,"read from private field"),t?t.call(s):e.get(s)),u=(s,e,t)=>e.has(s)?Ln("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,t),f=(s,e,t,r)=>(hi(s,e,"write to private field"),r?r.call(s,t):e.set(s,t),t),c=(s,e,t)=>(hi(s,e,"access private method"),t);var Je=(s,e,t,r)=>({set _(n){f(s,e,n,t)},get _(){return i(s,e,r)}});var ui=function(s,e){this[0]=s,this[1]=e},Fn=(s,e,t)=>{var r=(l,h,d,y)=>{try{var g=t[l](h),C=(h=g.value)instanceof ui,E=g.done;Promise.resolve(C?h[0]:h).then(O=>C?r(l==="return"?l:"next",h[1]?{done:O.done,value:O.value}:O,d,y):d({value:O,done:E})).catch(O=>r("throw",O,d,y))}catch(O){y(O)}},n=(l,h,d,y)=>a[l]=g=>(h=new Promise((C,E,O)=>(O=()=>r(l,g,C,E),o?o.then(O):O())),y=()=>o===d&&(o=0),o=d=h.then(y,y),h),o,a={};return t=t.apply(s,e),a[wa("asyncIterator")]=()=>a,n("next"),n("throw"),n("return"),a};var Te=(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))(Te||{});var $n="configure",_n="changeTrail",Er="destroy",Gn="loaded",fi="appliedChangeTrail",Sr="importedModule",In="destroyed",xs="messageToView";var zs="shadowObjects";var Le="ConsoleLogger",Ea=`${Le}Storage`,Sa=new Set(["localhost","127.0.0.1","::1","[::1]"]),Wn,Un,Ca=Sa.has((Un=(Wn=globalThis.location)==null?void 0:Wn.hostname)!=null?Un:""),Ms=(()=>{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=`${Le}.probe`;try{s.setItem(e,e)}finally{s.removeItem(e)}return s}catch(s){return}})(),Vn=Ms!=null,Ps=Symbol.for(Le),ee=globalThis,jn=!1,Nn=s=>{if(typeof s=="boolean")return s;switch(s.toLowerCase()){case"true":case"yes":case"on":return!0;default:return!1}},Hn=s=>[Vn?Le:void 0,...Array.isArray(s)?s:[s]].filter(Boolean).join(".");function di(s,e,t){var o;let r=Hn(s),n=Ms?Ms.getItem(r):(o=ee.ConsoleLoggerStorage)==null?void 0:o[r];return n==null?t:e?e(n):n}function Cr(s,e){Ms&&Ms.setItem(Hn(s),e)}function Qn(s){let e=ee.ConsoleLoggerStorage;if(e!=null&&e===De.sharedConfig){Object.assign(e,s,{[Ps]:!0});return}ee.ConsoleLoggerStorage=s}var bt,Rs,m=class m{constructor(e){u(this,bt);this.enable=!0,this.namespace=(e||"").trim()||Le,jn||(m.loadConfig(),jn=!0);let t=[this.namespace,"enable"];this.enable=di(t,Nn,this.enable)}static get isEnabled(){return m.sharedConfig.enable}static get isDebug(){return m.sharedConfig.enable&&m.sharedConfig.debug}static loadConfig(){var e,t,r;Vn?(["enable","debug","info","warn"].forEach(n=>{this.sharedConfig[n]=di(n,Nn,this.sharedConfig[n])}),["debug","info","warn","error"].forEach(n=>{this.sharedStyles[n]=di(["styles",n],void 0,this.sharedStyles[n])}),m.isDebug&&console.debug(`${Le}: Load config from localStorage`,m.sharedConfig),(e=ee.ConsoleLogger)!=null&&e[Ps]||(t=ee.ConsoleLogger)!=null||(ee.ConsoleLogger={[Ps]:!0,get enable(){return m.sharedConfig.enable},set enable(n){m.sharedConfig.enable=n,Cr("enable",n?"true":"false")},get debug(){return m.sharedConfig.debug},set debug(n){m.sharedConfig.debug=n,Cr("debug",n?"true":"false")},get info(){return m.sharedConfig.info},set info(n){m.sharedConfig.info=n,Cr("info",n?"true":"false")},get warn(){return m.sharedConfig.warn},set warn(n){m.sharedConfig.warn=n,Cr("warn",n?"true":"false")}})):(r=ee.ConsoleLoggerStorage)!=null&&r[Ps]||(ee.ConsoleLoggerStorage=ue(ue({[Ps]:!0},m.sharedConfig),ee.ConsoleLoggerStorage),m.sharedConfig=ee.ConsoleLoggerStorage,m.isDebug&&console.debug(`${Le}: Load config from ${Ea}`,ee.ConsoleLoggerStorage))}get isEnabled(){return this.enable&&m.sharedConfig.enable}get isDebug(){return this.isEnabled&&m.sharedConfig.debug}get isInfo(){return this.isEnabled&&m.sharedConfig.info}get isWarn(){return this.isEnabled&&m.sharedConfig.warn}debug(...e){this.isDebug&&c(this,bt,Rs).call(this,"debug",m.sharedStyles.debug,e)}info(...e){this.isInfo&&c(this,bt,Rs).call(this,"info",m.sharedStyles.info,e)}warn(...e){this.isWarn&&c(this,bt,Rs).call(this,"warn",m.sharedStyles.warn,e)}error(...e){c(this,bt,Rs).call(this,"error",m.sharedStyles.error,e)}};bt=new WeakSet,Rs=function(e,t,r){console[e](`%c${this.namespace}`,t,...r)},m.sharedConfig={enable:Ca,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"},m.sharedStyles={get debug(){return m.sharedConfig["styles.debug"]},set debug(e){m.sharedConfig["styles.debug"]=e},get info(){return m.sharedConfig["styles.info"]},set info(e){m.sharedConfig["styles.info"]=e},get warn(){return m.sharedConfig["styles.warn"]},set warn(e){m.sharedConfig["styles.warn"]=e},get error(){return m.sharedConfig["styles.error"]},set error(e){m.sharedConfig["styles.error"]=e}};var De=m;var te="*",ka=1,pi=2,vi=4,bi=Symbol.for("eventize"),mi=6,Aa="[eventize]",Xe=s=>s===te,wi=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}`)},Ze=s=>{switch(typeof s){case"string":case"symbol":return!0;default:return!1}},Ei=s=>s!=null&&(typeof s=="object"||typeof s=="function"),Oa=s=>Array.isArray(s),xa=Object.prototype,za=(()=>{let s={},e=Function.prototype;for(let t of Reflect.ownKeys(Function.prototype))try{s[t]=e[t]}catch(r){}return s})(),Pa=(s,e)=>{if(e==="constructor"||e==="__proto__")return;let t=s[e];if(t!==void 0&&t!==xa[e])return t===za[e]?void 0:t},Ra=(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},Ma=s=>s,Or=(s,e,t,r)=>{if(typeof e=="function"){let n=e.apply(s,t);return n!=null&&(r==null||r(n)),!0}return!1},Ta=(s,e,t,r)=>{let n=s.emit;return typeof n=="function"&&Or(s,n,Ra(e,t),r)},xr=(s,e,t,r)=>Or(s,Pa(s,e),t,r)||Ta(s,e,t,r),La=typeof console!="undefined",Be=La?console[typeof console.warn=="function"?"warn":"log"].bind(console,Aa):()=>{},Da=(s,e,t)=>(Object.defineProperty(s,e,{value:t,configurable:!1}),s),Ba=0,Fa=(s,e)=>s.order-e.order,Vt=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:Vt("events")},delete:{value:Vt("events")},clear:{value:Vt("events")}})),kr=Object.freeze(Object.defineProperties(new Set,{add:{value:Vt("eventNames")},delete:{value:Vt("eventNames")},clear:{value:Vt("eventNames")}})),$a=s=>{if(s.length!==0){s.sort(Fa);for(let e of s)try{e.replay()}catch(t){Be("a retained replay threw; the batch continues. event:",e.eventName,t)}}},_a=s=>e=>{typeof(e==null?void 0:e.then)=="function"&&e.then(void 0,t=>{Be("a retained replay rejected; the batch continues. event:",s,t)})},Ga=class{constructor(){p(this,"events",Ts);p(this,"eventNames",kr)}mutableEvents(){return this.events===Ts&&(this.events=new Map),this.events}mutableEventNames(){return this.eventNames===kr&&(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=kr)}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=kr,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:Ba++})}hasRetainedFor(s){return this.events.size!==0&&(Xe(s)||this.events.has(s))}replayTo(s,e,t=[]){if(Xe(s))this.events.forEach((r,n)=>{Xe(n)||this.replayTo(n,e,t)});else{let r=this.events.get(s);r!=null&&t.push({order:r.order,eventName:s,replay:()=>{let n=this.events.get(s);n!==void 0&&e.apply(s,n.args,_a(s))}})}return t}},Ia=s=>s!=null,ja=s=>s!=null&&typeof s=="object",Ds=s=>{switch(typeof s){case"function":return ka;case"string":case"symbol":return pi;case"object":return s===null?void 0:vi;default:return}},Na=0,Wa=()=>++Na,ro=0,Ua=()=>({settled:!1,members:[],sequence:ro++,onSettled:void 0}),Va=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=Wa(),this.eventName=s,this.isCatchEmAll=Xe(s),this.listener=t,this.listenerObject=r,this.priority=e,this.listenerType=Ds(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:n}=this,o=ro;if(typeof r=="function"){Or(n,r,e,t),this.callAfterApply&&this.callAfterApply(o);return}if(Ze(r)){Ia(n)&&Or(n,n[r],e,t)&&this.callAfterApply&&this.callAfterApply(o);return}ja(r)&&(this.isCatchEmAll||this.eventName===s)&&xr(r,s,e,t)&&this.callAfterApply&&this.callAfterApply(o)}},Fe=Symbol("eventize.EventStore.dedupIndex"),io=s=>s===vi||s===pi,Ha=(s,e,t,r,n,o)=>s===o.listenerType?e===o.priority&&t===o.eventName&&n===o.listenerObject&&r===o.listener:!1,no=(s,e,t)=>s===vi?e:t,Qa=s=>s!=null&&typeof s!="string"&&typeof s!="symbol",oo=(s,e,t)=>{let r=e.listener,n=e.listenerObject,o=io(e.listenerType),a=o?no(e.listenerType,r,n):void 0;o&&t(s,a,e),Qa(r)&&!(o&&a===r)&&t(s,r,e),Ei(n)&&n!==r&&!(o&&a===n)&&t(s,n,e)},Ya=(s,e,t)=>{let r=s.get(e);r===void 0?s.set(e,[t]):r.push(t)},qa=(s,e,t)=>{let r=s.get(e);if(r===void 0)return;let n=r.indexOf(t);n<0||(r.splice(n,1),r.length===0&&s.delete(e))},Ka=(s,e)=>{var t;oo((t=s[Fe])!=null?t:s[Fe]=new Map,e,Ya)},Yn=(s,e)=>{let t=s[Fe];t!==void 0&&oo(t,e,qa)},Ja=(s,e,t,r,n,o)=>{if(!io(s))return;let a=o[Fe];if(a===void 0)return;let l=a.get(no(s,r,n));if(l!==void 0){for(let h of l)if(Ha(s,e,t,r,n,h))return h}},fe=Symbol("eventize.EventStore.heldBy"),Ls=s=>{let e=s===void 0?[]:s.slice(0);return e[fe]=0,e[Fe]=s===void 0?void 0:s[Fe],e},Ar=s=>()=>{throw new Error(`EventStore: ${s} is the shared empty stand-in \\u2014 replace it, never mutate it`)},qn=Object.freeze(Object.defineProperties(new Map,{set:{value:Ar("namedListeners")},delete:{value:Ar("namedListeners")},clear:{value:Ar("namedListeners")}})),Bs=Ls();for(let s of["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"])Object.defineProperty(Bs,s,{value:Ar(`the catch-em-all bucket (${s}())`)});Object.freeze(Bs);var gi=s=>{s.forEach(e=>e.detach()),s[Fe]=void 0},Xa=(s,e)=>s.priority!==e.priority?e.priority-s.priority:s.id-e.id,Za=(s,e)=>{let t=0,r=s.length;for(;t<r;){let n=t+r>>>1,o=s[n];if(o===void 0)throw new Error("EventStore: findInsertIndex encountered a hole");Xa(e,o)<0?r=n:t=n+1}return t},Kn=(s,e,t,r,n)=>{let o=s.length;for(let a=0;a<o;a++){let l=s[a];l!==void 0&&e(l,t,r,n)}},el=(s,e,t,r,n,o)=>{let a=s.length,l=e.length,h=0,d=0;for(;h<a||d<l;){let y=h<a?s[h]:void 0,g=d<l?e[d]:void 0;if(y!==void 0&&(g===void 0||y.priority>=g.priority)){t(y,r,n,o),++h;continue}if(g!==void 0)t(g,r,n,o),++d;else throw new Error("EventStore: forEach encountered a hole")}},tl=Object.freeze([]),sl=class{constructor(){p(this,"namedBuckets",qn);p(this,"catchEmAllBucket",Bs);p(this,"lastAddCreatedListener",!1)}get namedListeners(){return this.namedBuckets}get catchEmAllListeners(){return this.mutableCatchEmAllBucket()}mutableNamedBuckets(){return this.namedBuckets===qn&&(this.namedBuckets=new Map),this.namedBuckets}mutableCatchEmAllBucket(){return this.catchEmAllBucket===Bs&&(this.catchEmAllBucket=Ls()),this.catchEmAllBucket}getListenersForEventName(s){let e=this.namedBuckets.get(s);return e||(e=Ls(),this.mutableNamedBuckets().set(s,e)),e}peekListeners(s){var e;return Xe(s)?this.catchEmAllBucket:(e=this.namedBuckets.get(s))!=null?e:tl}bucketForMutation(s,e){if(e[fe]===0)return e;let t=Ls(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 n=this.bucketForMutation(s,e);return n.splice(r,1),Yn(n,t),n}detachByAssociation(s,e,t){let r=e;for(let n=e.length-1;n>=0;n--){let o=e[n];o!==void 0&&o.eventName===s&&(o.listener===t||o.listenerObject===t)&&(r===e&&(r=this.bucketForMutation(s,e)),r.splice(n,1),Yn(r,o),o.detach())}return r}detachByIdentity(s,e,t,r,n){let o=e[Fe];if(o===void 0)return e;let a=o.get(t);if(a===void 0)return e;let l=r==null,h=e;for(let d of a.slice())((l?d.listener===t:d.isEqual(t,r))||l&&n&&d.listenerObject===t)&&(h=this.spliceOut(s,h,d),d.detach());return h}add(s,e,t,r=null,n=null){var y,g;let o=Xe(s)?this.mutableCatchEmAllBucket():this.getListenersForEventName(s),a=Ds(t),l=Ja(a,e,s,t,r,o),h=l!=null?l:new Va(s,e,t,r);if(n===null?h.refCount+=1:(y=h.onceObligations)!=null&&y.includes(n)||(((g=h.onceObligations)!=null?g:h.onceObligations=[]).push(n),n.members.push(h)),this.lastAddCreatedListener=!1,l)return l;let d=this.bucketForMutation(s,o);return d.splice(Za(d,h),0,h),Ka(d,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&&Xe(s)){this.removeAllListeners();return}if(e==null&&Ze(s)){this.removeByEventName(s);return}if(t&&Ze(s)){this.removeByEventNameAndListenerObject(s,e);return}this.removeByListener(s,e)}removeByEventName(s){let e=this.namedBuckets.get(s);e!==void 0&&(gi(e),e[fe]===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 n=r.onceObligations;if(n!==void 0){let o=n.indexOf(s);o>=0&&n.splice(o,1),n.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(Xe(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,n)=>{this.detachByIdentity(n,r,s,e,t).length===0&&this.namedBuckets.delete(n)}),this.detachByIdentity(te,this.catchEmAllBucket,s,e,t)}removeAllListeners(){this.namedBuckets.size!==0&&(this.namedBuckets.forEach(e=>{gi(e),e[fe]===0&&(e.length=0)}),this.namedBuckets.clear());let s=this.catchEmAllBucket;s!==Bs&&(gi(s),s[fe]!==0?this.catchEmAllBucket=Ls():s.length=0)}forEach(s,e,t,r,n){let o=this.catchEmAllBucket,a=o.length>0?o:void 0,l=s===te?void 0:this.namedBuckets.get(s),h=l!==void 0&&l.length>0?l:void 0;if(h===void 0){if(a===void 0)return;a[fe]+=1;try{Kn(a,e,t,r,n)}finally{a[fe]-=1}return}h[fe]+=1,a!==void 0&&(a[fe]+=1);try{a===void 0?Kn(h,e,t,r,n):el(h,a,e,t,r,n)}finally{h[fe]-=1,a!==void 0&&(a[fe]-=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(te),s}},rl=s=>s[bi],il=s=>{throw new TypeError(`two incompatible copies of @spearwolf/eventize are active on this object (marker protocol ${String(s)}, expected ${mi}) \\u2014 dedupe @spearwolf/eventize in your dependency tree so a single copy is loaded`)},nl=s=>(s==null?void 0:s.protocol)===mi,$e=s=>{let e=rl(s);return nl(e)?e:il(e==null?void 0:e.protocol)},me=s=>!!(s&&s[bi]);function Fs(s){if(me(s))return $e(s),s;if(!Ei(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 sl,t=new Ga;return Da(s,bi,{protocol:mi,keeper:t,store:e}),s}var ao=(s,e,t,r)=>{s.apply(e,t,r)},ol=(s,e)=>{Be("a listener threw; the dispatch continues. event:",s,e)},U=null,lo=(s,e)=>{U!==null?U.push(e):ol(s,e)},yi=s=>s.length===1?s[0]:new AggregateError(s,"emitStrict: one or more listeners failed"),zr=(s,e,t,r)=>{try{s.apply(e,t,r)}catch(n){lo(e,n)}},Jn=(s,e,t,r,n,o)=>{e===te&&wi("emitted");let a=o!=null?o:$e(s);return a.store.forEach(e,r,e,t,n),a.keeper.retain(e,t),a},Ht=(s,e,t,r,n)=>{if(Array.isArray(e)){let o;for(let a=0;a<e.length;a++)a in e&&(o=Jn(s,e[a],t,r,n,o))}else Jn(s,e,t,r,n)},Pr=(s,e,t,r)=>{try{xr(s,e,t,r)}catch(n){lo(e,n)}},Xn=(s,e,t,r,n)=>{e===te&&wi("emitted"),r(Ma(s),e,t,n)},Qt=(s,e,t,r,n)=>{if(Array.isArray(e))for(let o=0;o<e.length;o++)o in e&&Xn(s,e[o],t,r,n);else Xn(s,e,t,r,n)},Yt=Ei;function k(s,e,...t){me(s)?Ht(s,e,t,ao):Yt(s)&&Qt(s,e,t,xr)}function $s(s,e,...t){let r=U;U=null;try{me(s)?Ht(s,e,t,zr):Yt(s)&&Qt(s,e,t,Pr)}finally{U=r}}function mt(s,e,...t){let r=U,n=[];U=n;try{me(s)?Ht(s,e,t,zr):Yt(s)&&Qt(s,e,t,Pr)}catch(o){n.push(o)}finally{U=r}if(n.length>0)throw yi(n)}var Zn=()=>{},co=s=>{for(let e of s)if(Array.isArray(e))for(let t of e)Promise.resolve(t).catch(Zn);else Promise.resolve(e).catch(Zn)};function al(s,e,...t){let r=[],n=o=>{r.push(o)};try{me(s)?Ht(s,e,t,ao,n):Yt(s)&&Qt(s,e,t,xr,n)}catch(o){throw co(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 ll(s,e,...t){let r=[],n=a=>{r.push(a)},o=U;U=null;try{me(s)?Ht(s,e,t,zr,n):Yt(s)&&Qt(s,e,t,Pr,n)}catch(a){throw co(r),a}finally{U=o}return r.length>0?Promise.all(r.map(a=>Array.isArray(a)?Promise.all(a):Promise.resolve(a))):Promise.resolve(void 0)}var cl=(s,e,t)=>{let r=[];for(let[n,o]of e.entries()){if(o.status==="rejected"){t.push(o.reason);continue}if(!Array.isArray(s[n])){r.push(o.value);continue}let a=[];for(let l of o.value)l.status==="rejected"?t.push(l.reason):a.push(l.value);r.push(a)}return r};function hl(s,e,...t){let r=[],n=l=>{r.push(l)},o=U,a=[];U=a;try{me(s)?Ht(s,e,t,zr,n):Yt(s)&&Qt(s,e,t,Pr,n)}catch(l){a.push(l)}finally{U=o}return r.length===0?a.length>0?Promise.reject(yi(a)):Promise.resolve(void 0):Promise.allSettled(r.map(l=>Array.isArray(l)?Promise.allSettled(l):Promise.resolve(l))).then(l=>{let h=cl(r,l,a);if(a.length>0)throw yi(a);return h})}var de={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},ul=(s,e,t,r,n,o,a,l)=>{let h=s.add(t,r,n,o,l),d=s.lastAddCreatedListener;if(l!==null&&h.callAfterApply===void 0&&(h.callAfterApply=y=>s.settleOneShots(h,y)),e.hasRetainedFor(t)&&(d||l!==null)){let y=l===null?h:{apply:(g,C,E)=>{l.settled||h.apply(g,C,E)}};a.events=e.replayTo(t,y,a.events)}return h},eo=(s,e)=>{if(typeof s!="number"||Number.isNaN(s))throw Be("called with a NaN priority!",e),new Error("subscribeTo() called with a NaN priority",{cause:"invalid-priority"})},to=(s,e)=>{if(!Ze(s))throw Be("called with a value that cannot be an event name!",e),new Error("subscribeTo() called with insufficient arguments",{cause:"invalid-name"})},fl=(s,e,t,r,n)=>{let o=t.length,a=typeof t[0],l,h,d,y;if(o>=2&&o<=3&&a==="number"?(l=te,[h,d,y]=t):o>=3&&o<=4&&typeof t[1]=="number"?[l,h,d,y]=t:(h=de.Normal,a==="string"||a==="symbol"||Array.isArray(t[0])?[l,d,y]=t:(l=te,[d,y]=t)),!d||Ds(d)===void 0){let C=d==null?"missing-listener":Ds(d)===void 0?"not-dispatchable":"empty-method-name";throw Be(C==="missing-listener"?"called with insufficient arguments!":C==="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:C})}if(Ds(d)===pi&&y==null)throw Be("called with a method name but no listener object!",t),new Error("subscribeTo() called with insufficient arguments",{cause:"missing-listener-object"});Array.isArray(l)||to(l,t),eo(h,t);let g=(C,E)=>ul(s,e,E,C,d,y,r,n);if(Array.isArray(l)){if(l.length===0)throw Be("called with an empty array of event names!",t),new Error("subscribeTo() called with insufficient arguments",{cause:"empty-names"});for(let E=0;E<l.length;E++)if(!(E in l))throw Be("called with a sparse array of event names!",t),new Error("subscribeTo() called with insufficient arguments",{cause:"sparse-names"});return l.map(E=>{var Os;let O=Array.isArray(E)?[E[0],(Os=E[1])!=null?Os:h]:[E,h];return to(O[0],t),eo(O[1],t),O}).map(E=>g(E[1],E[0]))}return g(h,l)},ho=(s,e,t,r=null)=>{let n={},o=fl(s,e,t,n,r);return n.events!==void 0&&$a(n.events),o},dl=(s,e)=>{let t={host:s,listeners:e};return()=>{let r=t;if(r===null)return;t=null;let{store:n}=$e(r.host);Array.isArray(r.listeners)?r.listeners.forEach(o=>n.release(o)):n.release(r.listeners)}},gl=(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:n}=$e(r.host);n.releaseObligation(r.obligation)}},yl=s=>Array.isArray(s)?s.some(e=>e==null||e===te):s===te,A=(s,...e)=>{let t=Fs(s),{store:r,keeper:n}=$e(t);return dl(t,ho(r,n,e))},x=(s,...e)=>{let t=Fs(s),{store:r,keeper:n}=$e(t),o=Ua();return ho(r,n,e,o),gl(t,o)},so=s=>{var e;return(e=s.reason)!=null?e:new DOMException("This operation was aborted","AbortError")};function pl(s,e,t){let r=t==null?void 0:t.signal,n,o,a=new Promise((y,g)=>{n=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(so(r)),a;let l,h=!1,d=x(s,e,(...y)=>{h=!0,r!=null&&l!=null&&r.removeEventListener("abort",l),n(y[0])});return r!=null&&!h&&(l=()=>{d(),o(so(r))},r.addEventListener("abort",l,{once:!0})),a}function z(s,e,t){if(!me(s))return;let{store:r,keeper:n}=$e(s),o=typeof e,a=t!=null&&(o==="string"||o==="symbol");r.remove(e,t,a);let l=t==null&&Array.isArray(e)?e.flat(1/0):e;if(e==null||t==null&&yl(l)){n.removeAll();return}t==null&&Oa(l)?n.remove(l.filter(Ze)):Ze(e)&&n.remove(e)}var uo=s=>Array.isArray(s)?s.some(e=>e===te):s===te,fo=(s,e)=>{if(!Array.isArray(e)){if(!Ze(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(!Ze(t))throw new Error(`${s}() called with a value that cannot be an event name`,{cause:"invalid-name"})},go=(s,e,t,r,n)=>{if(!me(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}=$e(e);if(uo(t)){r(o);return}fo(s,t),n(o,t)};function _s(s,e){uo(e)&&wi("retained"),fo("retain",e);let t=Fs(s),{keeper:r}=$e(t);r.add(e)}function Si(s,e){go("retainClear",s,e,t=>t.clearAll(),(t,r)=>t.clear(r))}function Ci(s,e){go("unretain",s,e,t=>t.removeAll(),(t,r)=>t.remove(r))}var vl=A,bl=x,ml=z,wl=k,El=al,Sl=$s,Cl=ll,kl=mt,Al=hl,Ol=pl,xl=_s,zl=Si,Pl=Ci,Rl={on(...s){return vl(this,...s)},once(...s){return bl(this,...s)},onceAsync(s,e){return Ol(this,s,e)},off(s,e){ml(this,s,e)},emit(s,...e){wl(this,s,...e)},emitAsync(s,...e){return El(this,s,...e)},emitSafe(s,...e){Sl(this,s,...e)},emitSafeAsync(s,...e){return Cl(this,s,...e)},emitStrict(s,...e){kl(this,s,...e)},emitStrictAsync(s,...e){return Al(this,s,...e)},retain(s){xl(this,s)},retainClear(s){zl(this,s)},unretain(s){Pl(this,s)}},yo=Object.entries(Rl),Y=(()=>{let s=(e={})=>Fs(e);return s.inject=(e={})=>{e=Fs(e);for(let[t,r]of yo)Object.defineProperty(e,t,{value:r.bind(e),writable:!0,enumerable:!1,configurable:!0});return e},s.is=me,s})(),Ml=class{constructor(){Y(this)}};for(let[s,e]of yo)Object.defineProperty(Ml.prototype,s,{value:e,writable:!0,enumerable:!1,configurable:!0});var qt=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 po=`module has no "${zs}" export`;async function ki(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(l=>ki(s,l,t,!1)));let{registry:n}=s;if(e.define)for(let[l,h]of Object.entries(e.define))n.define(l,h);if(e.routes)for(let[l,h]of Object.entries(e.routes))n.appendRoute(l,h);await((a=(o=e.initialize)==null?void 0:o.call(e,{define:(l,h)=>n.define(l,h),kernel:s,registry:n}))!=null?a:Promise.resolve()),r&&s.upgradeEntities()}var ql={};var ye=Symbol.for("@spearwolf/signalize/signal"),ne=Symbol.for("@spearwolf/signalize/effect"),Ui=Symbol.for("@spearwolf/signalize/destroySignal"),ko=Symbol.for("@spearwolf/signalize/createEffect"),Ao=Symbol.for("@spearwolf/signalize/destroyEffect"),Oo=Symbol.for("@spearwolf/signalize/effectError"),Tl=Symbol.for("@spearwolf/signalize/signalizeError"),st=Symbol.for("@spearwolf/signalize/queueUnsubscribes"),Ws=Symbol.for("@spearwolf/signalize/autoMapResources"),Ai=Symbol.for("@spearwolf/signalize/instances"),Us="value",Vi="mute",Hi="unmute",Se="destroy",Ll="off",Zt=Symbol.for("@spearwolf/signalize/recall"),Vs=Y(),Ce=Y(),je=Y(),Qi=Y(),Dl=(s,e)=>{var t;try{let r=(t=globalThis[Ai])!=null?t:globalThis[Ai]=[];if(r.push({url:s,report:e}),r.length>1){let n={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(n)}catch(o){e(n)}}return r.length}catch(r){return 0}},Bl=0;var Fl=({level:s,message:e,error:t})=>{let r=s==="warn"?console.warn:console.error;t===void 0?r(e):r(e,t)},pe=s=>{if(Bl>0)try{k(je,Tl,s);return}catch(e){console.error(`[signalize] an onSignalizeError handler threw while reporting a ${s.source} diagnostic:`,e)}Fl(s)};Dl(ql.url,pe);var vo=new Set,Mi=(s,e)=>{vo.has(s)||(vo.add(s),pe({level:"warn",source:"deprecation",message:e}))},Ti,xo=s=>{Ti=s},zo=()=>{if(Ti===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 Ti},Hs=s=>s!=null&&typeof s.then=="function",Po=(s,e,t,r)=>{if(Hs(s))throw new TypeError(`[signalize] ${e}: ${t} must be synchronous, but it returned a thenable. ${r}`)},$l=0;function Dr(){return $l>0}var F=(s,e)=>{if(s.length!==0)throw s.length===1?s[0]:new AggregateError(s,`[signalize] ${s.length} errors while ${e}`)},S=(s,e)=>{try{e()}catch(t){s.push(t)}},Yi=0,St,Br=()=>{Yi++;let s=St;return St=void 0,s},Fr=(s,e)=>{let t=St;St=s,Yi--,t!==void 0&&F(t,e)},es=s=>Yi===0?!1:(St===void 0&&(St=[]),St.push(s),!0),Li=[],$r=()=>Li.at(-1),qi=(s,e)=>{Li.push(s);try{return e()}finally{Li.pop()}};var Ki=0,Ro=new FinalizationRegistry(()=>{--Ki}),_l=s=>{++Ki,Ro.register(s,void 0,s)};function bo(s){var e;Dr()||(e=$r())==null||e.whenSignalIsRead(s)}function Di(s,e,t){if(!Dr()){let r=Br();try{k(Vs,s,e,t)}catch(n){es(n)}finally{Fr(r,"notifying the effects of a signal write")}}}var tt=s=>s!=null&&s[ye]!=null,W=s=>s==null?void 0:s[ye],D=(...s)=>{for(let e of s){let t=W(e);if(t!=null&&!t.destroyed){t.destroyed=!0,t.beforeRead=void 0,Ro.unregister(t),--Ki;let r=Br();try{k(Ce,t.id,t.id)}catch(n){es(n)}finally{Fr(r,"notifying the subscribers of a destroyed signal")}}}};var Xt=new WeakMap,Gl=s=>{let e=Xt.get(s);return e||(e={},Xt.set(s,e)),e},Qs=(s,e)=>{var t,r;return(r=(t=Xt.get(s))==null?void 0:t.signals)==null?void 0:r.get(e)},Ji=(s,e)=>{var t,r;return(r=(t=Xt.get(s))==null?void 0:t.signals)==null?void 0:r.get(e)};var Mo=(s,e,t)=>{var n;let r=Gl(s);(n=r.signals)!=null||(r.signals=new Map),r.signals.set(e,t)};function Xi(...s){let e=[];for(let t of s)if(Xt.has(t)){let r=Xt.get(t);if(r.signals){for(let n of r.signals.values())S(e,()=>D(n));r.signals.clear(),r.signals=void 0}}F(e,"destroying the signals of an object")}function To(s){if(!tt(s)&&!Array.isArray(s))throw new TypeError("[signalize] touch: source must be a signal or an [object, propertyName] tuple");let e=W(tt(s)?s:Qs(...s));e!=null&&!e.muted&&!e.destroyed&&Di(e.id,e.value,{touch:!0})}function ts(s){var e,t;if(!tt(s)&&!Array.isArray(s))throw new TypeError("[signalize] value: source must be a signal or an [object, propertyName] tuple");return tt(s)?(e=W(s))==null?void 0:e.value:(t=W(Qs(...s)))==null?void 0:t.value}var So;So=ye;var Lr=class{constructor(e){p(this,So);this[ye]=e}get get(){return this[ye].reader}get set(){return this[ye].writer}get value(){return ts(this.get)}set value(e){this.set(e)}onChange(e){let{destroy:t}=zo()(()=>e(this.get()),[this.get]);return t}get muted(){return this[ye].muted}set muted(e){this[ye].muted=e}get destroyed(){return this[ye].destroyed}touch(){To(this)}destroy(){D(this)}},wt=new WeakMap,Kt=new Set,_e=Symbol.for("@spearwolf/signalize/groupResources"),mo=new FinalizationRegistry(s=>{for(let e of s.unsubs)try{e()}catch(t){pe({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&&Kt.delete(s.selfRef)}),Il=s=>{let e=s[_e].selfRef;if(!(e==null||!Kt.has(e)))try{s.clear()}catch(t){pe({level:"error",source:"group-finalizer",message:"[signalize] a SignalGroup teardown threw in the FinalizationRegistry callback, where no caller can catch it:",error:t})}},wo=new FinalizationRegistry(s=>{let e=s.deref();e!==void 0&&Il(e)});var jl=Symbol.for("@spearwolf/signalize/setParentGroup"),Oi=1,xi=2,zi=4,Pi=8,Ri=16,Eo="[signalize] Cannot attach a group to one of its own descendants: this would create a cycle in the group graph",_r="[signalize] internal error: a shared empty stand-in collection was written to",Bi=class extends Set{add(){throw new Error(_r)}},Fi=class extends Map{set(){throw new Error(_r)}},$i=class extends WeakMap{set(){throw new Error(_r)}},_i=class extends WeakSet{add(){throw new Error(_r)}},Gs=new Bi,Tr=new Fi,Lo=new $i,Do=new _i,Rr=s=>s===Gs?new Set:s,Mr=s=>s===Tr?new Map:s,Nl=s=>s===Lo?new WeakMap:s,Wl=s=>s===Do?new WeakSet:s,Co,q,we,N,se,K,Ge,re,Ee,ie,Jt,B,R,Et,$,Gi,Ii,ji,Bo,Ni,et=class et{constructor(e){u(this,$);u(this,q,Gs);u(this,we,new Set);u(this,N,Tr);u(this,se,Lo);u(this,K,Tr);u(this,Ge,Gs);u(this,re,new Set);u(this,Ee,Tr);p(this,Co,{unsubs:Gs});u(this,ie,Gs);u(this,Jt,Do);u(this,B);u(this,R,0);u(this,Et);if(e!=null&&e instanceof et)return e;if(e!=null||(e=this),wt.has(e))return wt.get(e);f(this,Et,new WeakRef(e)),wt.set(e,this);let t=new WeakRef(this);this[_e].selfRef=t,Kt.add(t),mo.register(this,this[_e],this),e!==this&&wo.register(e,t,this),Y(this)}static get(e){if(e!=null)return e instanceof et?e:wt.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 et?e:(t=wt.get(e))!=null?t:new et(e)}static destroy(e){Mi("SignalGroup.destroy","[signalize] SignalGroup.destroy(obj) is deprecated. Use SignalGroup.delete(obj) instead."),et.delete(e)}static delete(e){var t;if(e instanceof et){e.clear();return}(t=wt.get(e))==null||t.clear()}static clear(){let e=[];for(let t of[...Kt]){let r=t.deref();if(r===void 0){Kt.delete(t);continue}S(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=i(this,B);for(;r!=null;){if(r===e)throw new Error(Eo);if(r=i(r,B),r==null)break;if(r===e)throw new Error(Eo);if(r=i(r,B),t=i(t,B),r!=null&&r===t)throw new Error("[signalize] Cannot attach a group: the parent chain of this group is already cyclic")}return f(this,q,Rr(i(this,q))).add(e),i(e,B)&&i(e,B)!==this&&i(i(e,B),q).delete(e),f(e,B,this),e}detachGroup(e){return e!==this&&i(this,q).has(e)&&(i(this,q).delete(e),f(e,B,void 0)),e}[(Co=_e,jl)](e){f(this,B,e)}attachSignal(e){let t=c(this,$,Gi).call(this,e);return t&&f(this,Ge,Rr(i(this,Ge))).add(t),e}attachSignalByName(e,t){if(t){let r=c(this,$,Gi).call(this,t),n=i(this,N).get(e);n!=null&&n!==r&&c(this,$,Bo).call(this,e,n),f(this,N,Mr(i(this,N))).set(e,r);let o=i(this,K).get(e);o?o.add(r):f(this,K,Mr(i(this,K))).set(e,new Set([r])),i(this,se).has(r)?i(this,se).get(r).add(e):f(this,se,Nl(i(this,se))).set(r,new Set([e]))}else{let r=i(this,K).get(e);if(r)for(let n of[...r])c(this,$,ji).call(this,e,n);i(this,N).delete(e)}return t}hasSignal(e){var t;if(i(this,R)&Oi)return!1;f(this,R,i(this,R)|Oi);try{return i(this,N).has(e)||!!((t=i(this,B))!=null&&t.hasSignal(e))}finally{f(this,R,i(this,R)&~Oi)}}signal(e){var t,r,n;if(!(i(this,R)&xi)){f(this,R,i(this,R)|xi);try{return(n=(t=i(this,N).get(e))==null?void 0:t.object)!=null?n:(r=i(this,B))==null?void 0:r.signal(e)}finally{f(this,R,i(this,R)&~xi)}}}detachSignal(e){let t=W(e);return t&&c(this,$,Ni).call(this,t),e}attachEffect(e){let t=e!=null&&ne in e?e[ne]:e;if(t==null||t.destroyed)throw new Error("[signalize] Cannot attach a destroyed effect to a group");return i(this,re).has(t)||(i(this,re).add(t),x(t,Se,de.Max,()=>{i(this,re).delete(t)})),e}runEffects(){if(!(i(this,R)&zi)){f(this,R,i(this,R)|zi);try{for(let e of i(this,re))e.run();for(let e of i(this,q))e.runEffects()}finally{f(this,R,i(this,R)&~zi)}}}attachLink(e){if(e!=null&&e.isDestroyed)throw new Error("[signalize] Cannot attach a destroyed link to a group");return e&&(f(this,ie,Rr(i(this,ie))).add(e),i(this,Jt).has(e)||(f(this,Jt,Wl(i(this,Jt))).add(e),x(e,Se,de.Max,()=>{i(this,ie).delete(e)}))),e}detachLink(e){return e&&i(this,ie).delete(e),e}get memberCounts(){return{signals:i(this,we).size,namedSignals:i(this,N).size,signalsByName:i(this,K).size,effects:i(this,re).size,links:i(this,ie).size,groups:i(this,q).size}}destroy(){Mi("SignalGroup#destroy","[signalize] SignalGroup#destroy is deprecated. Use SignalGroup#clear instead."),this.clear()}off(){if(!(i(this,R)&Pi)){f(this,R,i(this,R)|Pi);try{let e=[];for(let t of[...i(this,q)])S(e,()=>t.off());for(let t of[...i(this,re)])S(e,()=>t.destroy());i(this,re).clear();for(let t of[...i(this,ie)])S(e,()=>t.destroy());i(this,ie).clear();for(let t of[...i(this,we)])t.destroyed||S(e,()=>k(Ce,t.id,t.id,{detach:!0}));S(e,()=>k(this,Ll,this)),F(e,"switching off a signal group")}finally{f(this,R,i(this,R)&~Pi)}}}clear(){var e;if(!(i(this,R)&Ri)){f(this,R,i(this,R)|Ri);try{let t=[];S(t,()=>k(this,Se,this)),S(t,()=>z(this));for(let r of[...i(this,q)])S(t,()=>r.clear());for(let r of[...i(this,re)])S(t,()=>r.destroy());for(let r of[...i(this,we)])S(t,()=>D(r));for(let r of[...i(this,ie)])S(t,()=>r.destroy());for(let r of[...i(this,Ee).values()])S(t,()=>r());if(i(this,Ee).clear(),i(this,q).clear(),i(this,we).clear(),i(this,N).clear(),i(this,K).clear(),i(this,Ge).clear(),i(this,re).clear(),i(this,ie).clear(),(e=i(this,B))==null||e.detachGroup(this),i(this,Et)){let r=i(this,Et).deref();r!==void 0&&wt.delete(r),f(this,Et,void 0)}Kt.delete(this[_e].selfRef),this[_e].unsubs.clear(),wo.unregister(this),mo.unregister(this),F(t,"clearing a signal group")}finally{f(this,R,i(this,R)&~Ri)}}}};q=new WeakMap,we=new WeakMap,N=new WeakMap,se=new WeakMap,K=new WeakMap,Ge=new WeakMap,re=new WeakMap,Ee=new WeakMap,ie=new WeakMap,Jt=new WeakMap,B=new WeakMap,R=new WeakMap,Et=new WeakMap,$=new WeakSet,Gi=function(e){let t=W(e);if(t!=null&&t.destroyed)throw new Error("[signalize] Cannot attach a destroyed signal to a group");if(t&&(i(this,we).add(t),!i(this,Ee).has(t))){let r=this[_e].selfRef,n=new WeakRef(t),o=A(Ce,t.id,(l,h)=>{var g;if(h!=null&&h.detach)return;let d=n.deref(),y=r.deref();d!==void 0&&y!==void 0&&c(g=y,$,Ni).call(g,d)});f(this,Ee,Mr(i(this,Ee))).set(t,o);let a=this[_e];(a.unsubs=Rr(a.unsubs)).add(o)}return t},Ii=function(e){let t=i(this,Ee).get(e);if(t)try{t()}finally{i(this,Ee).delete(e),this[_e].unsubs.delete(t)}},ji=function(e,t){let r=i(this,K).get(e);r&&(r.delete(t),r.size===0&&i(this,K).delete(e));let n=i(this,se).get(t);n&&(n.delete(e),n.size===0&&(i(this,se).delete(t),i(this,Ge).has(t)||(c(this,$,Ii).call(this,t),i(this,we).delete(t),D(t))))},Bo=function(e,t){i(this,Ge).has(t)||c(this,$,ji).call(this,e,t)},Ni=function(e){let t=[];if(S(t,()=>c(this,$,Ii).call(this,e)),i(this,we).delete(e),i(this,Ge).delete(e),i(this,se).has(e)){let r=i(this,se).get(e);for(let n of r){let o=i(this,K).get(n);if(o){if(o.delete(e),o.size===0)i(this,N).delete(n),i(this,K).delete(n);else if(i(this,N).get(n)===e){let a;for(let l of o)a=l;f(this,N,Mr(i(this,N))).set(n,a)}}}r.clear(),i(this,se).delete(e)}F(t,"detaching a signal from a signal group")};var Ie=et,js,Ns,Is=class{constructor(e="id",t=1){u(this,js);u(this,Ns);f(this,js,e),f(this,Ns,t)}make(){return Symbol(`${i(this,js)}${Je(this,Ns)._++}`)}};js=new WeakMap,Ns=new WeakMap;var Ul=new Is("si"),Vl=["lazy","compare","beforeRead"],Hl=(s,e)=>s===e;function Ql(){Mi("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 Yl=s=>{let e=t=>{var r;return s.destroyed||(r=s.beforeRead)==null||r.call(s),t?(Ql(),zo()(()=>(s.destroyed||bo(s.id),t(s.value)),[e])):s.destroyed||bo(s.id),s.value};return Object.defineProperty(e,ye,{value:s}),e},ge,Wi=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,ge);p(this,"valueFn");p(this,"reader");p(this,"writer",(e,t)=>{var l,h,d;let r=(l=t==null?void 0:t.lazy)!=null?l:!1,n=(h=t==null?void 0:t.compare)!=null?h:this.compare,o=n!=null?n:Hl;if((r!==this.lazy||r&&e!==this.valueFn||!r&&!o(e,i(this,ge)))&&(r?(f(this,ge,void 0),this.valueFn=e,this.lazy=!0):(f(this,ge,e),this.valueFn=void 0,this.lazy=!1),!this.muted&&!this.destroyed)){Di(this.id,i(this,ge));return}(d=t==null?void 0:t.touch)!=null&&d&&!this.muted&&!this.destroyed&&Di(this.id,i(this,ge),{touch:!0})});p(this,"object");this.id=Ul.make(),_l(this),this.lazy=e,this.lazy?(this.value=void 0,this.valueFn=t):(this.value=t,this.valueFn=void 0),this.reader=Yl(this),this.object=new Lr(this)}get[ye](){return this}get value(){return this.lazy&&(f(this,ge,this.valueFn()),this.valueFn=void 0,this.lazy=!1),i(this,ge)}set value(e){f(this,ge,e)}};ge=new WeakMap;function _(s=void 0,e){var r;let t;if(tt(s)){t=W(s);let n=Vl.filter(o=>(e==null?void 0:e[o])!=null);n.length>0&&pe({level:"warn",source:"ignored-option",message:`[signalize] createSignal(existingSignal, {${n.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 n=(r=e==null?void 0:e.lazy)!=null?r:!1;t=new Wi(n,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&&Ie.findOrCreate(e.attach).attachSignal(t),t.object}var en=0,Kl=()=>en>0,nt=class{constructor(){p(this,"delayedEffects",[])}batch(e,t){let r=this.delayedEffects.length;for(let n=0;n<r;n++){let[o,a]=this.delayedEffects[n];if(!(o>t)){if(o===t){a.add(e);return}this.delayedEffects.splice(n,0,[t,new Set([e])]);return}}this.delayedEffects.push([t,new Set([e])])}unbatch(e,t){let r=this.delayedEffects.length;for(let n=0;n<r;n++){let[o,a]=this.delayedEffects[n];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=[];en++;let r=Br();try{t.push(A(je,(n,o)=>{o===Zt&&e.add(n)}),A(Qi,n=>{e.add(n)}));for(let[,n]of this.delayedEffects)for(let o of n)if(!e.has(o))try{k(je,o,o,Zt)}catch(a){es(a)}}finally{try{for(let n of t)n()}finally{try{Fr(r,"flushing a batch of signal writes")}finally{en--}}}}};p(nt,"current");var Jl=()=>nt.current;var Xl="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 Rt(s){let e=nt.current;e?e=void 0:e=nt.current=new nt;let t;try{let r=s();Po(r,"batch","callback",Xl)}catch(r){t=[r]}finally{if(e){nt.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 Zl=()=>{},_o;_o=ne;var tn=class{constructor(e){p(this,_o);p(this,"run",()=>{var e;return(e=this[ne])==null?void 0:e.run()});p(this,"runImmediately",()=>{var e;return(e=this[ne])==null?void 0:e.runImmediately()});p(this,"destroy",()=>{var e;(e=this[ne])==null||e.destroy(),this[ne]=void 0});this[ne]=e,x(e,Se,()=>{this[ne]=void 0})}get destroyed(){let e=this[ne];return e==null||e.destroyed}onDestroy(e){let t=this[ne];return t==null||t.destroyed?(e(),Zl):x(t,Se,e)}},ec=0,tc=()=>ec>0;var Ct,Ys=(s,e,t)=>{if(tc()){let r={error:e,effect:s,effectId:s.id,phase:t};try{k(je,Oo,r);return}catch(n){console.error(`[signalize] an onEffectError handler threw while reporting an error of effect ${s.id.toString()}:`,n)}}pe({level:"error",source:"effect",message:`[signalize] unhandled rejection in the ${t} of effect ${s.id.toString()}:`,error:e})},Ks,Js,sn=class{constructor(e,t){p(this,"active");u(this,Ks);u(this,Js,!1);this.active=e,f(this,Ks,t)}complete(){f(this,Js,!0)}mayCommit(e){return this.active&&(i(this,Js)||e>i(this,Ks))}};Ks=new WeakMap,Js=new WeakMap;var At,ke,Ae,Ne,ss,rt,Ot,rs,xt,Oe,it,is,Xs,zt,Zs,rn,kt=class{constructor(e,t){u(this,Zs);p(this,"id");p(this,"callback");u(this,At);u(this,ke,new Set);u(this,Ae,new Set);u(this,Ne,new Map);u(this,ss,0);u(this,rt,new Set);u(this,Ot,[]);p(this,"autorun",!0);p(this,"shouldRun",!0);u(this,rs,!1);p(this,"priority");u(this,xt);u(this,Oe,!1);u(this,it,0);u(this,is,!1);u(this,Xs,0);u(this,zt,!1);var n,o;Y(this),this.callback=e;let r=(t==null?void 0:t.attach)!=null?Ie.findOrCreate(t.attach):void 0;this.autorun=(n=t==null?void 0:t.autorun)!=null?n:!0,f(this,xt,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 l=r.signal(a);if(l==null)throw new Error(`[signalize] createEffect: cannot resolve dependency "${String(a)}" \\u2014 no signal with that name is registered in the attached SignalGroup`);return l}default:return a}}):void 0),this.id=Ct.idGen.make(),this.priority=(o=t==null?void 0:t.priority)!=null?o:0,A(je,this.id,Zt,this),r==null||r.attachEffect(this),++Ct.count}get destroyed(){return i(this,Oe)}hasStaticDeps(){return i(this,xt)!=null&&i(this,xt).length>0}saveSignalsFromDeps(){for(let e of i(this,xt)){let t=W(e);t.destroyed||this.whenSignalIsRead(t.id)}}static createEffect(e,t,r){var l;let n=Array.isArray(t)?t:void 0,o=n?Dn(ue({},r),{dependencies:n}):t,a=new Ct(e,o);try{(l=$r())==null||l.attachChildEffect(a),k(je,ko,a),a.hasStaticDeps()?a.destroyed||a.saveSignalsFromDeps():a.autorun&&a.run()}catch(h){let d=[h];(o==null?void 0:o.attach)==null&&S(d,()=>a.destroy()),F(d,"creating an effect")}return new tn(a)}attachChildEffect(e){i(this,Ot).push(e)}run(){c(this,Zs,rn).call(this,!1)}runImmediately(){c(this,Zs,rn).call(this,!0)}runStaticCallback(e){this.saveSignalsFromDeps(),this.storeCleanupCallback(this.runWithoutAutoTracking(),e)}runDynamicCallback(e){let t=new sn(!Dr(),i(this,ss));if(t.active){i(this,Ae).clear();for(let r of i(this,ke))i(this,Ae).add(r)}try{this.storeCleanupCallback(qi(this,this.callback),e),t.complete()}finally{t.mayCommit(i(this,ss))&&(this.cleanupLostSignals(),i(this,rt).clear())}}runWithoutAutoTracking(){let e=i(this,zt);f(this,zt,!0);try{return qi(this,this.callback)}finally{f(this,zt,e)}}[Zt](){if(this.shouldRun=!0,!(!this.autorun&&!i(this,rs)))try{this.run()}catch(e){if(!es(e))throw e}}whenSignalIsRead(e){i(this,Oe)||i(this,zt)||(Je(this,ss)._++,i(this,Ae).delete(e),i(this,ke).has(e)||(i(this,ke).add(e),i(this,Ne).set(e,[A(Vs,e,this.priority,Zt,this),x(Ce,e,Ui,this)])))}[Ui](e,t){try{this.onSignalDestroyed(e,t)}catch(r){if(t!=null&&t.detach||!es(r))throw r}}onSignalDestroyed(e,t){if(i(this,ke).has(e)){if(t!=null&&t.detach){this.unsubscribeSignal(e),i(this,ke).delete(e),i(this,rt).delete(e),i(this,Ae).delete(e),this.hasNoLiveSignals()&&this.destroyWhenUntriggerable();return}i(this,rt).has(e)||(i(this,rt).add(e),this.unsubscribeSignal(e),this.hasNoLiveSignals()&&this.destroyWhenUntriggerable())}}destroyWhenUntriggerable(){if(i(this,it)>0){f(this,is,!0);return}this.destroy()}hasNoLiveSignals(){return i(this,Ne).size===0}cleanupLostSignals(){if(i(this,Ae).size===0)return;let e=[];for(let t of i(this,Ae))S(e,()=>this.unsubscribeSignal(t)),i(this,ke).delete(t);F(e,"unsubscribing an effect from a signal")}destroyChildEffects(){if(i(this,Ot).length===0)return;let e=[];this.collectDestroyChildEffects(e),F(e,"destroying an effect")}collectDestroyChildEffects(e){for(let t of i(this,Ot))S(e,()=>t.destroy());i(this,Ot).length=0}unsubscribeSignal(e){if(i(this,Ne).has(e)){let t=[];try{i(this,Ne).get(e).forEach(r=>{S(t,()=>r())})}finally{i(this,Ne).delete(e)}F(t,"unsubscribing an effect from a signal")}}storeCleanupCallback(e,t){if(!Hs(e)){typeof e=="function"&&this.acceptCleanupCallback(e,t);return}Promise.resolve(e).then(r=>{typeof r=="function"&&this.acceptCleanupCallback(r,t)},r=>{Ys(this,r,"callback")})}acceptCleanupCallback(e,t){if(i(this,Oe)||t!==i(this,Xs)){this.runOrphanedCleanupCallback(e);return}let r=i(this,At);f(this,At,e),r!=null&&this.runOrphanedCleanupCallback(r)}runCleanupCallback(){let e=i(this,At);if(e==null)return;f(this,At,void 0);let t=e();Hs(t)&&Promise.resolve(t).catch(r=>{Ys(this,r,"cleanup")})}runOrphanedCleanupCallback(e){try{let t=e();Hs(t)&&Promise.resolve(t).catch(r=>{Ys(this,r,"cleanup")})}catch(t){Ys(this,t,"cleanup")}}destroy(){if(i(this,Oe))return;f(this,Oe,!0),z(Vs,this),z(je,this),z(Ce,this);let e=[];S(e,()=>k(this,Se,this)),S(e,()=>z(this)),S(e,()=>k(je,Ao,this)),S(e,()=>this.runCleanupCallback());try{this.collectDestroyChildEffects(e)}finally{i(this,ke).clear(),i(this,Ae).clear(),i(this,Ne).clear(),i(this,rt).clear(),--Ct.count}F(e,"destroying an effect")}};At=new WeakMap,ke=new WeakMap,Ae=new WeakMap,Ne=new WeakMap,ss=new WeakMap,rt=new WeakMap,Ot=new WeakMap,rs=new WeakMap,xt=new WeakMap,Oe=new WeakMap,it=new WeakMap,is=new WeakMap,Xs=new WeakMap,zt=new WeakMap,Zs=new WeakSet,rn=function(e){if(i(this,Oe)||!this.shouldRun)return;let t=Jl();if(t){if(!e){this.autorun||f(this,rs,!0),t.batch(this.id,this.priority);return}t.unbatch(this.id,this.priority)}if(f(this,rs,!1),i(this,it)>=Ct.maxDepth)throw new Error(`[signalize] Effect ${this.id.toString()} exceeded maxDepth=${Ct.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.`);Je(this,it)._++;try{this.runCleanupCallback(),this.destroyChildEffects(),this.shouldRun=!1,Kl()&&k(Qi,this.id,this.id);let r=++Je(this,Xs)._;this.hasStaticDeps()?this.runStaticCallback(r):this.runDynamicCallback(r)}finally{if(Je(this,it)._--,i(this,it)===0&&i(this,is)&&(f(this,is,!1),!i(this,Oe)&&this.hasNoLiveSignals()))try{this.destroy()}catch(r){Ys(this,r,"cleanup")}}},p(kt,"idGen",new Is("ef")),p(kt,"count",0),p(kt,"maxDepth",256);Ct=kt;var ot=(...s)=>kt.createEffect(...s);xo(ot);function jo(s,e){var n,o,a;let t=$r(),r=_();try{let l=(e==null?void 0:e.name)||void 0,h=(e==null?void 0:e.attach)!=null?Ie.findOrCreate(e.attach):void 0;h!=null?l!=null?h.attachSignalByName(l,r):h.attachSignal(r):l!=null&&pe({level:"warn",source:"ignored-option",message:`[signalize] createMemo({name: ${String(l)}}) without {attach} is ignored: a name only exists within a SignalGroup. Pass {attach} as well, or drop the name.`});let d=(n=e==null?void 0:e.batchWrites)!=null?n:!1,y=ot(()=>{d?Rt(()=>{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:de.C,attach:h}),g=W(r);g.beforeRead=y.runImmediately;let C=x(Ce,g.id,y.destroy);return y.onDestroy(()=>{C(),t!=null&&D(r)}),r.get}catch(l){let h=[l];(e==null?void 0:e.attach)==null&&S(h,()=>D(r)),F(h,"creating a memo")}}var No="[signalize] SignalLink destroyed before the next value arrived",er,Pt,ns,tr,sr,nn=class{constructor(e,t,r){u(this,er);u(this,Pt);u(this,ns);u(this,tr,[]);u(this,sr,!1);f(this,er,e),f(this,Pt,t),f(this,ns,r)}get hasSettled(){return i(this,sr)}add(e){i(this,tr).push(e)}releaseAll(){i(this,ns)!=null&&(i(this,ns).cancel=void 0),i(this,tr).forEach(e=>{e()})}settleWithValue(e){f(this,sr,!0),this.releaseAll(),i(this,er).call(this,e)}settleWithDestroy(){this.releaseAll(),i(this,Pt).call(this,new Error(No))}settleWithAbort(e){this.releaseAll(),i(this,Pt).call(this,e)}settleWithCancel(){this.releaseAll(),i(this,Pt).call(this,new Error("[signalize] SignalLink read cancelled by the iterator"))}};er=new WeakMap,Pt=new WeakMap,ns=new WeakMap,tr=new WeakMap,sr=new WeakMap;var Go,V,os,rr,as,Ue,on,Wo,Uo;Go=st;var Ir=class{constructor(e){u(this,Ue);u(this,V,!1);p(this,Go,[]);u(this,os,0);u(this,rr,0);u(this,as,0);p(this,"source");p(this,"lastValue");p(this,"isDestroyed",!1);Y(this),this.source=W(e);let t=new WeakRef(this);this[st].push(A(Vs,this.source.id,(r,n)=>{let o=t.deref();o!=null&&!i(o,V)&&!o.isDestroyed&&((n==null?void 0:n.touch)===!0?o.touch():o.write())})),this[st].push(x(Ce,this.source.id,()=>{var r;return(r=t.deref())==null?void 0:r.destroy()}))}releaseOnDestroy(e){this[st].push(e)}attach(e){let t=Ie.findOrCreate(e);return t.attachLink(this),t}nextValue(e){return c(this,Ue,on).call(this,null,e)}asyncValues(e,t){let r={},n=c(this,Ue,Uo).call(this,r,e,t),o=n.return.bind(n);n.return=(l=>{var h;return(h=r.cancel)==null||h.call(r),o(l)});let a=n.throw.bind(n);return n.throw=(l=>{var h;return(h=r.cancel)==null||h.call(r),a(l)}),n}destroy(){if(this.isDestroyed)return;this.isDestroyed=!0;let e=[];for(let t of this[st])S(e,t);this[st].length=0,S(e,()=>k(this,Se,this)),S(e,()=>z(this)),this.lastValue=void 0,Object.freeze(this),F(e,"tearing down a SignalLink")}get isMuted(){return i(this,V)}mute(){return!this.isDestroyed&&!i(this,V)&&(f(this,V,!0),k(this,Vi,this)),this}unmute(){return!this.isDestroyed&&i(this,V)&&(f(this,V,!1),k(this,Hi,this)),this}toggleMute(){return this.isDestroyed||(f(this,V,!i(this,V)),k(this,i(this,V)?Vi:Hi,this)),i(this,V)}updateValue(e){if(!i(this,V)&&!this.isDestroyed){let t=++Je(this,rr)._,{value:r}=this.source;if(e(r),this.isDestroyed||i(this,rr)!==t)return;f(this,as,t),k(this,Us,r),this.lastValue=r}}};V=new WeakMap,os=new WeakMap,rr=new WeakMap,as=new WeakMap,Ue=new WeakSet,on=function(e,t,r){let{signal:n}=t!=null?t:{};return new Promise((o,a)=>{if(n!=null&&n.aborted){a(n.reason);return}if(this.isDestroyed){a(new Error(No));return}let l=new nn(o,a,r);if(r!=null&&(r.cancel=()=>l.settleWithCancel()),l.add(x(this,Se,()=>l.settleWithDestroy())),n!=null){let d=()=>l.settleWithAbort(n.reason);n.addEventListener("abort",d,{once:!0}),l.add(()=>n.removeEventListener("abort",d))}let h=A(this,Us,d=>{c(this,Ue,Wo).call(this,e)&&l.settleWithValue(d)});l.hasSettled?h():l.add(h)})},Wo=function(e){return e==null?!0:e.generation===i(this,as)?!1:(e.generation=i(this,as),!0)},Uo=function(e,t,r){return Fn(this,null,function*(){var o;_s(this,Us),f(this,os,i(this,os)+1);let n={generation:0};try{let a=0;for(;!this.isDestroyed;)try{let l=yield new ui(c(this,Ue,on).call(this,n,r,e));if(t!=null&&t(l,a++))break;yield l}catch(l){if((o=r==null?void 0:r.signal)!=null&&o.aborted&&l===r.signal.reason)throw l;break}}finally{f(this,os,i(this,os)-1),i(this,os)===0&&Ci(this,Us)}})};var an=class extends Ir{constructor(t,r){super(t);p(this,"target");this.target=W(r);let n=new WeakRef(this);this.releaseOnDestroy(x(Ce,this.target.id,()=>{var o;return(o=n.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)})}},ln=class extends Ir{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)})}},Zi=new WeakMap,qs=0,Fo=new FinalizationRegistry(s=>{for(let e of s)try{e()}catch(t){pe({level:"error",source:"link-finalizer",message:"[signalize] link: releasing the queue subscriptions of a collected link failed",error:t})}s.length=0,qs>0&&(qs-=1)}),sc=1e3,$o=new WeakSet;function Mt(s,e,t){let r=W(s);if(r==null)throw new TypeError("[signalize] link: source must be a signal");let n=W(e),o=n!=null?n:e,a=Zi.get(r);if(a==null)a=new Map,Zi.set(r,a);else if(a.has(o)){let d=a.get(o),y=t==null?void 0:t.attach;return y&&d.attach(y),d}let l=n!=null?new an(s,n):new ln(s,e),h=t==null?void 0:t.attach;return h&&l.attach(h),a.set(o,l),qs+=1,Fo.register(l,l[st],l),a.size>=sc&&!$o.has(r)&&($o.add(r),pe({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.`})),x(l,Se,de.Max,()=>{a.delete(o),a.size===0&&Zi.delete(r),Fo.unregister(l),qs>0&&(qs-=1)}),l}var rc=new FinalizationRegistry(s=>{for(let e of s.unsubs)try{e()}catch(t){pe({level:"error",source:"automap-finalizer",message:"[signalize] releasing the destroy-queue subscriptions of a collected SignalAutoMap failed:",error:t})}s.unsubs.clear()}),Io,H,ls,Nr,We,cn,Gr;Io=Ws;var hn=class hn{constructor(){u(this,We);p(this,Io,{unsubs:new Set});u(this,H,new Map);u(this,ls,new Map);u(this,Nr,new WeakRef(this));rc.register(this,this[Ws],this)}static fromProps(e,t){var o;let r=new hn,n=t?[...new Set(t)].map(a=>[a,e[a]]):Object.entries(e);for(let[a,l]of n)c(o=r,We,cn).call(o,a,l);return r}keys(){return i(this,H).keys()}signals(){return i(this,H).values()}entries(){return i(this,H).entries()}clear(){let e=[...i(this,H).values()],t=[];for(let r of[...i(this,H).keys()])S(t,()=>c(this,We,Gr).call(this,r));for(let r of e)S(t,()=>r.destroy());F(t,"clearing a signal auto map")}delete(e){let t=i(this,H).get(e);return t===void 0?!1:(c(this,We,Gr).call(this,e),t.destroy(),!0)}has(e){return i(this,H).has(e)}get(e){return i(this,H).has(e)?i(this,H).get(e):c(this,We,cn).call(this,e)}update(e){e.size&&Rt(()=>{for(let[t,r]of e.entries())this.get(t).set(r)})}updateFromProps(e,t){let r=t?t.map(n=>[n,e[n]]):Object.entries(e);r.length!==0&&Rt(()=>{for(let[n,o]of r)this.get(n).set(o)})}};H=new WeakMap,ls=new WeakMap,Nr=new WeakMap,We=new WeakSet,cn=function(e,t){let r=_(t);i(this,H).set(e,r);let n=i(this,Nr),o=A(Ce,W(r).id,(a,l)=>{var d;if(l!=null&&l.detach)return;let h=n.deref();h!==void 0&&c(d=h,We,Gr).call(d,e)});return i(this,ls).set(e,o),this[Ws].unsubs.add(o),r},Gr=function(e){let t=i(this,ls).get(e);try{t()}finally{i(this,ls).delete(e),this[Ws].unsubs.delete(t),i(this,H).delete(e)}};var jr=hn;var Wr=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 P(s,e,t,...r){try{e()}catch(n){s.error(t,...r,n)}}var Tt,cs,ir,Ur=class{constructor(e){u(this,Tt,new Map);u(this,cs,!1);u(this,ir);f(this,ir,e)}add(...[e,t]){i(this,Tt).set(e,t),!i(this,cs)&&(f(this,cs,!0),queueMicrotask(()=>this.flush()))}flush(){if(f(this,cs,!1),i(this,Tt).size===0)return;let e=i(this,Tt);f(this,Tt,new Map),i(this,ir).call(this,e)}};Tt=new WeakMap,cs=new WeakMap,ir=new WeakMap;var Vr=Symbol("onCreate"),oe=Symbol("onDestroy"),un=Symbol("onParentChanged"),hs=Symbol("onViewEvent");function Vo(s){return function(e,t){var o;let r=(s==null?void 0:s.name)||t.name,n=!!((o=s==null?void 0:s.readAsValue)!=null&&o);return{get(){let a=Ji(this,r);if(a)return n?a.value:a.get()},set(a){var l;(l=Ji(this,r))==null||l.set(a)},init(a){let l=_(a,s);return Mo(this,r,l),Ie.findOrCreate(this).attachSignalByName(r,l),l.value}}}}var ic=Object.create,fn=Object.defineProperty,nc=Object.getOwnPropertyDescriptor,Yo=(s,e)=>(e=Symbol[s])?e:Symbol.for("Symbol."+s),fs=s=>{throw TypeError(s)},oc=(s,e,t)=>e in s?fn(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,Ho=(s,e)=>fn(s,"name",{value:e,configurable:!0}),ac=s=>{var e;return[,,,ic((e=s==null?void 0:s[Yo("metadata")])!=null?e:null)]},qo=["class","method","getter","setter","accessor","field","value","get","set"],nr=s=>s!==void 0&&typeof s!="function"?fs("Function expected"):s,lc=(s,e,t,r,n)=>({kind:qo[s],name:e,metadata:r,addInitializer:o=>t._?fs("Already initialized"):n.push(nr(o||null))}),Ko=(s,e)=>oc(e,Yo("metadata"),s[3]),Qo=(s,e,t,r)=>{for(var n=0,o=s[e>>1],a=o&&o.length;n<a;n++)e&1?o[n].call(t):r=o[n].call(t,r);return r},cc=(s,e,t,r,n,o)=>{var a,l,h,d,y,g=e&7,C=!!(e&8),E=!!(e&16),O=g>3?s.length+1:g?C?1:2:0,Os=qo[g+5],Rn=g>3&&(s[O-1]=[]),pa=s[O]||(s[O]=[]),he=g&&(!E&&!C&&(n=n.prototype),g<5&&(g>3||!E)&&nc(g<4?n:{get[t](){return J(this,o)},set[t](Q){return ar(this,o,Q)}},t));g?E&&g<4&&Ho(o,(g>2?"set ":g>1?"get ":"")+t):Ho(n,t);for(var ai=r.length-1;ai>=0;ai--)d=lc(g,t,h={},s[3],pa),g&&(d.static=C,d.private=E,y=d.access={has:E?Q=>hc(n,Q):Q=>t in Q},g^3&&(y.get=E?Q=>(g^1?J:at)(Q,n,g^4?o:he.get):Q=>Q[t]),g>2&&(y.set=E?(Q,li)=>ar(Q,n,li,g^4?o:he.set):(Q,li)=>Q[t]=li)),l=(0,r[ai])(g?g<4?E?o:he[Os]:g>4?void 0:{get:he.get,set:he.set}:n,d),h._=1,g^4||l===void 0?nr(l)&&(g>4?Rn.unshift(l):g?E?o=l:he[Os]=l:n=l):typeof l!="object"||l===null?fs("Object expected"):(nr(a=l.get)&&(he.get=a),nr(a=l.set)&&(he.set=a),nr(a=l.init)&&Rn.unshift(a));return g||Ko(s,n),he&&fn(n,t,he),E?g^4?o:he:n},dn=(s,e,t)=>e.has(s)||fs("Cannot "+t),hc=(s,e)=>Object(e)!==e?fs(\'Cannot use the "in" operator on this value\'):s.has(e),J=(s,e,t)=>(dn(s,e,"read from private field"),t?t.call(s):e.get(s)),Hr=(s,e,t)=>e.has(s)?fs("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,t),ar=(s,e,t,r)=>(dn(s,e,"write to private field"),r?r.call(s,t):e.set(s,t),t),at=(s,e,t)=>(dn(s,e,"access private method"),t),Jo,xe,lt,lr,gn,Ve,Qr,or,us="value";Jo=[Vo({name:us})];var ze=class{constructor(e){Hr(this,Ve),Hr(this,xe,[]),Hr(this,lt),Hr(this,gn,Qo(lr,8,this)),Qo(lr,11,this),this.value$=void 0,_s(this,us),this.value$=Qs(this,us),this.value$.onChange(t=>$s(this,us,t)),e&&this.add(...e)}add(...e){return J(this,xe).push(...e),at(this,Ve,or).call(this),at(this,Ve,Qr).call(this,e)}unshift(...e){return J(this,xe).unshift(...e),at(this,Ve,or).call(this),at(this,Ve,Qr).call(this,e)}remove(...e){at(this,Ve,Qr).call(this,e)()}clear(){J(this,xe).length=0,at(this,Ve,or).call(this)}dispose(){var e;this.clear(),(e=J(this,lt))==null||e.destroy(),ar(this,lt,void 0),Si(this,us),z(this),this.value$.destroy(),Xi(this)}};lr=ac(null);xe=new WeakMap;lt=new WeakMap;gn=new WeakMap;Ve=new WeakSet;Qr=function(s){return()=>{for(let e of s){let t=J(this,xe).indexOf(e);t!==-1&&J(this,xe).splice(t,1)}at(this,Ve,or).call(this)}};or=function(){var s;(s=J(this,lt))==null||s.destroy(),J(this,xe).length===0?(ar(this,lt,void 0),this.value=void 0):(ar(this,lt,ot(()=>{let e;for(let t of J(this,xe)){let r=ts(t);if(r!=null){e=r;break}}this.value=e},J(this,xe))),J(this,lt).run())};cc(lr,4,"value",Jo,ze,gn);Ko(lr,ze);ze.Value=us;var Xo=new WeakMap,uc=s=>{let e=Xo.get(s);return e==null&&(e=new Ur(t=>{for(let[r,n]of t)P(s.logger,()=>r.set(n.value),`an effect of a context value failed (${String(n.name)}):`,n.uuid)}),Xo.set(s,e)),e},fc=(s,e,t,r,n)=>{uc(s).add(e,{value:t,name:r,uuid:n})},G,Z,ct,ae,ht,M,Lt,le,ys,hr,v,yn,X,Zo,pn,Dt,He,vn,bn,mn,ut,Bt,wn,ea,En,ds,cr,gs=class gs{constructor(e,t){u(this,v);u(this,G);u(this,Z);u(this,ct,new jr);u(this,ae,new Map);u(this,ht,new Map);u(this,M);u(this,Lt,new Set);u(this,le,[]);u(this,ys,0);u(this,hr,!1);u(this,Dt,!1);u(this,He);u(this,ut);f(this,G,e),f(this,Z,t)}get kernel(){return i(this,G)}get uuid(){return i(this,Z)}get order(){return i(this,ys)}set order(e){i(this,ys)!==e&&(f(this,ys,e),i(this,M)&&i(this,M).resortChildren(),i(this,G).noteEntityTreeChange(i(this,Z)))}get parentUuid(){var e;return(e=i(this,M))==null?void 0:e.uuid}set parentUuid(e){var t;if(((t=i(this,M))==null?void 0:t.uuid)!==e){let r=e?i(this,G).getEntity(e):void 0;r!=null&&this.assertAttachableTo(r),c(this,v,pn).call(this,r==null),f(this,M,r),i(this,M)&&i(this,M).addChild(this),c(this,v,bn).call(this),i(this,G).noteEntityTreeChange(i(this,Z))}}get parent(){return i(this,M)}set parent(e){this.parentUuid=e==null?void 0:e.uuid}get hasParent(){return!!i(this,M)}get children(){return i(this,le)}traverse(e){c(this,v,yn).call(this,e,new Set)}[oe](){if(!i(this,hr)){f(this,hr,!0),c(this,v,X).call(this,"properties",()=>i(this,ct).clear()),c(this,v,X).call(this,"listeners",()=>z(this)),c(this,v,X).call(this,"auto-destruction subscription",()=>{var e;return(e=i(this,He))==null?void 0:e.call(this)});for(let e of i(this,ht).values())c(this,v,X).call(this,"global context cleanup",()=>e.cleanup()),c(this,v,X).call(this,"global context signal",()=>e.signal.destroy());for(let e of i(this,ae).values())c(this,v,X).call(this,"context value reset",()=>e.context.set(void 0)),c(this,v,X).call(this,"context value subscription",()=>e.unsubscribePathValue()),c(this,v,X).call(this,"context parent subscription",()=>{var t;return(t=e.unsubscribeFromParent)==null?void 0:t.call(e)}),c(this,v,X).call(this,"context value path",()=>e.valuePath.dispose()),c(this,v,X).call(this,"inherited context signal",()=>e.inherited.destroy()),c(this,v,X).call(this,"provided context signal",()=>e.provide.destroy()),c(this,v,X).call(this,"context signal",()=>e.context.destroy());i(this,ht).clear(),i(this,ae).clear(),f(this,M,void 0),i(this,Lt).clear(),i(this,le).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(i(this,Lt).has(e.uuid))throw new Error(`child with uuid: ${e.uuid} already exists! parentUuid: ${this.uuid}`);i(this,Lt).add(e.uuid),c(this,v,Zo).call(this,e);for(let[,r]of i(e,ae))c(t=e,v,cr).call(t,r)}resortChildren(){i(this,le).sort((e,t)=>e.order-t.order)}removeChild(e){let t=i(this,le).indexOf(e);t!==-1&&(i(this,Lt).delete(e.uuid),i(this,le).splice(t,1))}removeFromParent(e=!0){c(this,v,pn).call(this,e)}get autoDestructionOnParentRemoval(){return i(this,Dt)}set autoDestructionOnParentRemoval(e){i(this,Dt)!==e&&(f(this,Dt,e),c(this,v,bn).call(this))}reSubscribeToParentContexts(){for(let[,e]of i(this,ae))c(this,v,cr).call(this,e)}dispatchMessageToView(e,t,r,n=!1){i(this,G).dispatchMessageToView({uuid:i(this,Z),type:e,data:t,transferables:r,traverseChildren:n})}dispatchViewEvents(e){for(let{type:t,data:r}of e)P(i(this,G).logger,()=>mt(this,hs,t,r),"entity view event delivery failed:",t,i(this,Z))}dispatchViewEvent(e,t){this.dispatchViewEvents([{type:e,data:t}])}getPropertyReader(e){return c(this,v,mn).call(this,e).get}getPropertyWriter(e){let t=c(this,v,mn).call(this,e);return(r,n)=>{this.clearTruthyPropsCache(),t.set(r,n)}}setProperties(e){Rt(()=>{for(let[t,r]of e)this.setProperty(t,r)})}setProperty(e,t){this.getPropertyWriter(e)(t)}getProperty(e){return ts(this.getPropertyReader(e))}propKeys(){return Array.from(i(this,ct).keys())}propEntries(){return Array.from(i(this,ct).entries()).map(([e,t])=>[e,t.value])}clearTruthyPropsCache(){f(this,ut,void 0)}truthyProps(){if(i(this,ut))return i(this,ut).size?i(this,ut):void 0;let e=new Set;for(let[t,r]of i(this,ct).entries())if(typeof t=="string"){let n=r.value;n!=null&&n!==!1&&n!==""&&e.add(t)}return f(this,ut,e),e.size?e:void 0}hasContext(e){return i(this,ae).has(e)}useContext(e){return c(this,v,ds).call(this,e).context.get}useParentContext(e){return c(this,v,ds).call(this,e).inherited.get}provideContext(e){return c(this,v,ds).call(this,e).provide}provideGlobalContext(e){return c(this,v,En).call(this,e).signal}attachContextProvider(e,t){var n;let r=c(this,v,ds).call(this,e);return c(n=gs,Bt,wn).call(n,t,r.provide,r.providerFeeds)}attachGlobalContextProvider(e,t){var n;let r=c(this,v,En).call(this,e);return c(n=gs,Bt,wn).call(n,t,r.signal,r.providerFeeds)}};G=new WeakMap,Z=new WeakMap,ct=new WeakMap,ae=new WeakMap,ht=new WeakMap,M=new WeakMap,Lt=new WeakMap,le=new WeakMap,ys=new WeakMap,hr=new WeakMap,v=new WeakSet,yn=function(e,t){var r;if(!t.has(this)){t.add(this),e(this);for(let n of i(this,le))c(r=n,v,yn).call(r,e,t)}},X=function(e,t){P(i(this,G).logger,t,`entity teardown step failed (${e}):`,i(this,Z))},Zo=function(e){let t=i(this,le).length;for(;t>0&&e.order<i(this,le)[t-1].order;)t--;i(this,le).splice(t,0,e)},pn=function(e){if(i(this,M)){if(i(this,M).removeChild(this),f(this,M,void 0),e)for(let[,t]of i(this,ae))c(this,v,cr).call(this,t);c(this,v,vn).call(this),i(this,G).noteEntityTreeChange(i(this,Z))}},Dt=new WeakMap,He=new WeakMap,vn=function(){i(this,He)&&(i(this,He).call(this),f(this,He,void 0))},bn=function(){c(this,v,vn).call(this),i(this,Dt)&&i(this,M)&&f(this,He,x(i(this,M),oe,de.Max,()=>{f(this,He,void 0),i(this,G).destroyEntity(i(this,Z))}))},mn=function(e){return i(this,ct).get(e)},ut=new WeakMap,Bt=new WeakSet,wn=function(e,t,r){let n=Mt(e,t);return r.add(n),()=>{var o;r.delete(n)&&(n.destroy(),c(o=gs,Bt,ea).call(o,r))}},ea=function(e){let t;for(let r of e)!r.isDestroyed&&r.source.value!=null&&(t=r);t==null||t.touch()},En=function(e){if(i(this,ht).has(e))return i(this,ht).get(e);let t=i(this,G).findOrCreateRootContext(e),r=_(),o={cleanup:t.add(r),signal:r,providerFeeds:new Set};return i(this,ht).set(e,o),o},ds=function(e){if(i(this,ae).has(e))return i(this,ae).get(e);let t=_(),r=_(),n=_(),o=new ze([r,t]),a=A(o,ze.Value,h=>{fc(i(this,G),n,h,e,i(this,Z))}),l={name:e,inherited:t,provide:r,context:n,valuePath:o,providerFeeds:new Set,unsubscribePathValue:a};return i(this,ae).set(e,l),c(this,v,cr).call(this,l),l},cr=function(e){var t,r;if((t=e.unsubscribeFromParent)==null||t.call(e),e.unsubscribeFromParent=void 0,this.parent){let n=c(r=this.parent,v,ds).call(r,e.name),o=Mt(n.context,e.inherited);e.unsubscribeFromParent=o.destroy.bind(o)}else{let n=i(this,G).findOrCreateRootContext(e.name),o=Mt(n.value$,e.inherited);e.unsubscribeFromParent=o.destroy.bind(o)}},u(gs,Bt);var Yr=gs;function ta(s,e){s.indexOf(e)===-1&&s.push(e)}var sa=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]}},qr=(s,e)=>{for(let t of e)s.add(t)},dc=(s,e)=>{if(s!=null)for(let t of s)e.add(t)},ft,Pe,Qe,Ft,ps,ce,ur,ra,Sn,fr=class{constructor(){u(this,ce);u(this,ft,new Map);u(this,Pe,new Map);u(this,Qe,new Map);u(this,Ft,new Set);u(this,ps,new Map)}static get(e){return e!=null?e:gc}define(e,t){let r=i(this,ft).get(e);r?ta(r,t):i(this,ft).set(e,[t]),c(this,ce,ur).call(this)}appendRoute(e,t){let r=sa(e);if(r){i(this,Ft).add(r.prop);let n=i(this,Qe).get(r.key);n?qr(n,t):i(this,Qe).set(r.key,new Set(t))}else{let n=i(this,Pe).get(e);n?qr(n,t):i(this,Pe).set(e,new Set(t))}c(this,ce,ur).call(this)}clearRoute(e){let t=sa(e);t?i(this,Qe).delete(t.key):i(this,Pe).delete(e),c(this,ce,ur).call(this)}findTokensByRoute(e,t){return new Set(c(this,ce,Sn).call(this,e,t))}findConstructors(e,t){let r=c(this,ce,Sn).call(this,e,t),n=new Set;for(let o of r)dc(i(this,ft).get(o),n);return n.size>0?Array.from(n):void 0}hasToken(e){return i(this,ft).has(e)}hasRoute(e){return i(this,Pe).has(e)}clear(){i(this,ft).clear(),i(this,Pe).clear(),i(this,Qe).clear(),i(this,Ft).clear(),c(this,ce,ur).call(this)}};ft=new WeakMap,Pe=new WeakMap,Qe=new WeakMap,Ft=new WeakMap,ps=new WeakMap,ce=new WeakSet,ur=function(){i(this,ps).clear()},ra=function(e){if(e===void 0||i(this,Ft).size===0)return"";let t="";for(let r of e)i(this,Ft).has(r)&&(t+=`${r.length}:${r}`);return t},Sn=function(e,t){var h;let r=c(this,ce,ra).call(this,t),n=i(this,ps).get(e),o=n==null?void 0:n.get(r);if(o!==void 0)return o;let a=new Set([e]),l=Array.from((h=i(this,Pe).get(e))!=null?h:[]);for(let d=l.shift();d!==void 0;d=l.shift()){if(a.has(d))continue;a.add(d);let y=i(this,Pe).get(d);y&&l.push(...Array.from(y).filter(g=>!a.has(g)))}if(t){for(let y of t){let g=i(this,Qe).get(y);g&&qr(a,g)}let d;do{d=a.size;for(let y of new Set(a))for(let g of t){let C=i(this,Qe).get(`${y}@${g}`);C&&qr(a,C)}}while(d!==a.size)}return n===void 0&&(n=new Map,i(this,ps).set(e,n)),n.set(r,a),a};var gc=new fr;var Cn=s=>s!=null?s:void 0;var dt=()=>{let s=_(void 0);return D(s),s},yc=()=>{let s=ot(()=>{},{autorun:!1});return s.destroy(),s},ia=()=>{},T,Re,be,bs,$t,j,_t,ms,dr,ws,gr,Es,Ss,Cs,ks,yr,Ye,Gt,It,jt,As,pr,vr,b,ve,kn,Kr,vs,I,An,Jr=class{constructor(e,t,r,n){u(this,b);u(this,T);u(this,Re);u(this,be);u(this,bs);u(this,$t,new Set);u(this,j,new Set);u(this,_t,new Set);u(this,ms,new Map);u(this,dr,new Map);u(this,ws,new Map);u(this,gr,new Map);u(this,Es,new Map);u(this,Ss,new Map);u(this,Cs,new Set);u(this,ks,new Map);u(this,yr,new Map);u(this,Ye);u(this,Gt);u(this,It);u(this,jt);u(this,As,!1);u(this,pr,!1);u(this,vr);f(this,T,e),f(this,Re,t),f(this,be,r),f(this,bs,n)}get displayName(){return i(this,be)}get debugHandles(){return{shadowObject:i(this,Ye),releaseScope:i(this,Gt),forgetShadowObject:i(this,It),unsubscribeFromEntityDestroy:i(this,jt)}}get debugCleanupCounts(){return{primary:i(this,$t).size,secondary:i(this,j).size,contextFeeds:i(this,_t).size}}createAPI(){return{entity:i(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(i(this,As))throw new Error(`the creation scope of "${i(this,be)}" has torn down and cannot be bound`);if(i(this,Ye)!==void 0)throw new Error(`the creation scope of "${i(this,be)}" is already bound to a shadow-object`);f(this,Ye,e),f(this,Gt,t),f(this,It,r),i(this,Re).info("create shadow-object",i(this,be),{shadowObject:e,entity:i(this,T)}),f(this,jt,x(i(this,T),oe,de.Low,()=>{this.tearDown()}))}tearDown(){if(i(this,As))return;f(this,As,!0),c(this,b,ve).call(this,"scope release",()=>{var n;return(n=i(this,Gt))==null?void 0:n.call(this)}),c(this,b,ve).call(this,"entity destroy subscription",()=>{var n;return(n=i(this,jt))==null?void 0:n.call(this)}),i(this,Ye)!==void 0&&i(this,Re).info("destroy shadow-object",i(this,be),{shadowObject:i(this,Ye),entity:i(this,T)});let e=new Set,t=(n,o)=>{let a=!1;for(let l of n)e.has(l)||(e.add(l),a=!0,c(this,b,ve).call(this,o,l));return a},r=!0;for(;r;){let n=t(i(this,$t),"onDestroy callback"),o=t(i(this,j),"creation-api cleanup");r=n||o}for(let n of i(this,_t))c(this,b,ve).call(this,"context feed release",n);for(let n of i(this,ms).values())c(this,b,ve).call(this,"context reader",()=>D(n));for(let n of i(this,ws).values())c(this,b,ve).call(this,"parent context reader",()=>D(n));for(let n of i(this,ks).values())c(this,b,ve).call(this,"property reader",()=>D(n));for(let n of i(this,Es).values())c(this,b,ve).call(this,"context provider",()=>D(n));for(let n of i(this,Ss).values())c(this,b,ve).call(this,"global context provider",()=>D(n));i(this,$t).clear(),i(this,j).clear(),i(this,_t).clear(),i(this,ms).clear(),i(this,dr).clear(),i(this,ws).clear(),i(this,gr).clear(),i(this,ks).clear(),i(this,yr).clear(),i(this,Es).clear(),i(this,Ss).clear(),i(this,Cs).clear(),c(this,b,ve).call(this,"forget shadow-object",()=>{var n;return(n=i(this,It))==null?void 0:n.call(this)}),f(this,Ye,void 0),f(this,Gt,void 0),f(this,It,void 0),f(this,jt,void 0),f(this,pr,!0)}useProperty(e,t){if(c(this,b,I).call(this,"useProperty"))return dt().get;c(this,b,vs).call(this,t,"useProperty");let r=typeof t=="function"?{compare:t}:t;return c(this,b,Kr).call(this,e,i(this,ks),i(this,yr),()=>i(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(c(this,b,I).call(this,"provideContext"))return dt();c(this,b,vs).call(this,r,"provideContext");let n=typeof r=="function"?{compare:r}:r;return c(this,b,An).call(this,e,i(this,Es),o=>i(this,T).attachContextProvider(e,o),t,n)}provideGlobalContext(e,t,r){if(c(this,b,I).call(this,"provideGlobalContext"))return dt();c(this,b,vs).call(this,r,"provideGlobalContext");let n=typeof r=="function"?{compare:r}:r;return c(this,b,An).call(this,e,i(this,Ss),o=>i(this,T).attachGlobalContextProvider(e,o),t,n)}useContext(e,t){if(c(this,b,I).call(this,"useContext"))return dt().get;c(this,b,vs).call(this,t,"useContext");let r=typeof t=="function"?{compare:t}:t;return c(this,b,Kr).call(this,e,i(this,ms),i(this,dr),()=>i(this,T).useContext(e),r,"useContext","context")}useParentContext(e,t){if(c(this,b,I).call(this,"useParentContext"))return dt().get;c(this,b,vs).call(this,t,"useParentContext");let r=typeof t=="function"?{compare:t}:t;return c(this,b,Kr).call(this,e,i(this,ws),i(this,gr),()=>i(this,T).useParentContext(e),r,"useParentContext","parent context")}createSignal(...e){if(c(this,b,I).call(this,"createSignal"))return dt();let t=_(...e);return i(this,j).add(()=>{D(t)}),t}createEffect(...e){if(c(this,b,I).call(this,"createEffect"))return yc();let t=ot(...e);return i(this,j).add(t.destroy),t}createMemo(...e){if(c(this,b,I).call(this,"createMemo"))return dt().get;let t=jo(...e);return i(this,j).add(()=>{D(t)}),t}createResource(e,t){if(c(this,b,I).call(this,"createResource"))return dt();let r=_(),n=ot(()=>{let o=Cn(e());return r.set(o),o!==void 0&&t?()=>{t(o),r.set(void 0)}:()=>{r.set(void 0)}});return i(this,j).add(()=>{try{n.destroy()}finally{r.set(void 0),D(r)}}),r}on(...e){if(c(this,b,I).call(this,"on"))return ia;let[t]=e,r=typeof t=="string"||typeof t=="symbol"||Array.isArray(t)?A(i(this,T),...e):A(...e);return c(this,b,kn).call(this,r)}once(...e){if(c(this,b,I).call(this,"once"))return ia;let[t]=e,r=typeof t=="string"||typeof t=="symbol"||Array.isArray(t)?x(i(this,T),...e):x(...e);return c(this,b,kn).call(this,r)}emit(...e){if(c(this,b,I).call(this,"emit"))return;let[t]=e;typeof t=="string"||typeof t=="symbol"||Array.isArray(t)?k(i(this,T),...e):k(...e)}onViewEvent(e){if(c(this,b,I).call(this,"onViewEvent"))return;let t=A(i(this,T),hs,(r,n)=>{e(r,n)});i(this,j).add(t)}onDestroy(e){c(this,b,I).call(this,"onDestroy")||i(this,$t).add(e)}dispatchMessageToView(e,t,r,n=!1){c(this,b,I).call(this,"dispatchMessageToView")||i(this,T).dispatchMessageToView(e,t,r,n)}};T=new WeakMap,Re=new WeakMap,be=new WeakMap,bs=new WeakMap,$t=new WeakMap,j=new WeakMap,_t=new WeakMap,ms=new WeakMap,dr=new WeakMap,ws=new WeakMap,gr=new WeakMap,Es=new WeakMap,Ss=new WeakMap,Cs=new WeakMap,ks=new WeakMap,yr=new WeakMap,Ye=new WeakMap,Gt=new WeakMap,It=new WeakMap,jt=new WeakMap,As=new WeakMap,pr=new WeakMap,vr=new WeakMap,b=new WeakSet,ve=function(e,t){P(i(this,Re),t,`shadow-object teardown failed (${e}):`,i(this,be))},kn=function(e){return i(this,j).add(e),Object.assign(()=>{i(this,j).delete(e),e()},e)},Kr=function(e,t,r,n,o,a,l){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 d=Mt(n(),h);i(this,j).add(d.destroy.bind(d))}else(o==null?void 0:o.compare)!=null&&r.get(e)!==o.compare&&i(this,Re).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 ${l}.`);return h},vs=function(e,t){typeof e!="function"||i(this,bs).has(t)||(i(this,Re).error(`[shadow-objects] Deprecation Warning: The "isEqual" option of "${t}()" is now passed as {compare} argument. Please update your code accordingly.`),i(this,bs).add(t))},I=function(e){var t,r;return i(this,pr)?((t=i(this,vr))!=null&&t.has(e)||(((r=i(this,vr))!=null?r:f(this,vr,new Set)).add(e),i(this,Re).error(`[shadow-objects] ${e}(): the creation scope of "${i(this,be)}" has torn down \\u2014 the call does nothing. Something is still holding the creation API past the end of its shadow-object.`)),!0):!1},An=function(e,t,r,n,o){var l;let a=t.get(e);if(a==null){let h=tt(n),d=h?void 0:Cn(n);if(a=_(d,o!=null&&o.compare?{compare:o.compare}:void 0),h){let y=Mt(n,a);i(this,j).add(y.destroy.bind(y))}i(this,_t).add(r(a)),t.set(e,a)}return((l=o==null?void 0:o.clearOnDestroy)==null||l)&&!i(this,Cs).has(a)&&(i(this,Cs).add(a),i(this,j).add(()=>{a.set(void 0)})),a};var na=s=>s.displayName||s.name,pc=[["onCreate",Vr],["onDestroy",oe],["onParentChanged",un],["onViewEvent",hs]],ti,L,Me,gt,Nt,yt,Wt,qe,si,w,On,xn,oa,aa,br,la,Xr,ca,ha,zn,Zr,ei=class{constructor(e){u(this,w);u(this,ti,new De("Kernel"));u(this,L,new Map);u(this,Me,new Set);u(this,gt,[]);u(this,Nt,[]);u(this,yt,!0);u(this,Wt,new Map);u(this,qe,new WeakMap);u(this,si,new Set);Y(this),this.registry=fr.get(e)}get logger(){return i(this,ti)}getEntity(e){return c(this,w,On).call(this,e).entity}findEntity(e){var t;return(t=i(this,L).get(e))==null?void 0:t.entity}hasEntity(e){return i(this,L).has(e)}get debugEntityCounts(){return{entities:i(this,L).size,rootEntities:i(this,Me).size,traversal:i(this,gt).length,traversalReversed:i(this,Nt).length}}traverseLevelOrderBFS(e=!1){if(i(this,yt)){let t=new Map,r=new Set,n=(o,a)=>{if(r.has(o))return;r.add(o);let l=this.findEntity(o);if(l===void 0)return;let h=t.get(a);h?h.push(l):t.set(a,[l]);for(let d of l.children)n(d.uuid,a+1)};i(this,Me).forEach(o=>{n(o,0)}),f(this,gt,Array.from(t.entries()).sort((o,a)=>o[0]-a[0]).flatMap(([,o])=>o)),f(this,Nt,i(this,gt).slice().reverse()),f(this,yt,!1)}return e?i(this,Nt).slice():i(this,gt).slice()}getEntityGraph(){let e=new Set;return Array.from(i(this,Me)).map(t=>c(this,w,xn).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,c(this,w,br).call(this,t.uuid,2));for(let t of this.traverseLevelOrderBFS(!1))this.hasEntity(t.uuid)&&c(this,w,br).call(this,t.uuid,1,e.get(t.uuid));e.clear()}run(e){this.logger.debug("sync",e);let t=0;try{Rt(()=>{for(let r of e.changeTrail)c(this,w,oa).call(this,r),t++})}catch(r){throw new qt(t,e.changeTrail.length,{cause:r})}}createEntity(e,t,r,n=0,o,a=!1){if(i(this,L).has(e))throw new Wr(e);let l=new Yr(this,e);l.order=n;let h={token:t,entity:l,usedConstructors:new Map};i(this,L).set(e,h),this.noteEntityTreeChange(e);try{r&&(l.parentUuid=r),l.autoDestructionOnParentRemoval=a,o&&l.setProperties(o),c(this,w,ca).call(this,h)}catch(d){throw c(this,w,aa).call(this,e),d}}destroyEntity(e){let t=i(this,L).get(e);if(t===void 0)return;let{entity:r,usedConstructors:n}=t;try{let o=[...r.children];for(let l of o)P(this.logger,()=>{l.autoDestructionOnParentRemoval?this.destroyEntity(l.uuid):l.removeFromParent()},"child of a destroyed entity could not be handed on:",l.uuid);P(this.logger,()=>r.removeFromParent(),"entity could not be detached from its parent:",r.uuid);let a=this.findShadowObjects(r.uuid);for(let l of a)z(r,l),c(this,w,zn).call(this,l,r);P(this.logger,()=>mt(r,oe,r),"entity onDestroy notification failed:",r.uuid);for(let l of a)P(this.logger,()=>{var h;return(h=i(this,qe).get(l))==null?void 0:h.tearDown()},"creation scope teardown of a destroyed entity failed:",r.uuid);P(this.logger,()=>r[oe](),"entity release failed:",r.uuid)}finally{n.clear(),i(this,L).delete(r.uuid),i(this,Me).delete(r.uuid),f(this,yt,!0)}}setParent(e,t,r){let n=this.getEntity(e),o=r!=null?r:n.order;if(!(n.parentUuid===t&&n.order===o)){if(t&&!i(this,L).has(t))throw new Error(`entity with uuid "${t}" not found!`);t&&n.assertAttachableTo(this.getEntity(t)),n.removeFromParent(t==null),n.order=o,n.parentUuid=t,this.logger.debug("entity.onParentChanged",{uuid:e,parentUuid:t,order:o,entity:n}),P(this.logger,()=>mt(n,un,n),"entity onParentChanged notification failed:",e)}}updateOrder(e,t){this.getEntity(e).order=t}noteEntityTreeChange(e){f(this,yt,!0);let t=i(this,L).get(e);t!==void 0&&(t.entity.hasParent?i(this,Me).delete(e):i(this,Me).add(e))}dispatchEventsToEntity(e,t){var r;(r=this.findEntity(e))==null||r.dispatchViewEvents(t)}changeProperties(e,t){this.getEntity(e).setProperties(t),c(this,w,br).call(this,e)}changeToken(e,t){let r=i(this,L).get(e);if(r===void 0||r.token===t)return;let n=r.token;r.token=t,c(this,w,br).call(this,e,0,void 0,n)}dispatchMessageToView(e){queueMicrotask(()=>{$s(this,xs,e)})}findShadowObjects(e){let t=i(this,L).get(e);if(t===void 0)return[];let{usedConstructors:r}=t;return Array.from(new Set(Array.from(r.values()).flatMap(n=>Array.from(n))))}findOrCreateRootContext(e){let t=i(this,Wt).get(e);return t||(t=new ze,i(this,Wt).set(e,t)),t}destroy(){for(let e of this.traverseLevelOrderBFS(!0))P(this.logger,()=>this.destroyEntity(e.uuid),"entity teardown during kernel destroy failed:",e.uuid);i(this,L).clear(),i(this,Me).clear(),i(this,gt).length=0,i(this,Nt).length=0,f(this,yt,!0);for(let e of i(this,Wt).values())e.dispose();i(this,Wt).clear(),queueMicrotask(()=>{z(this)})}};ti=new WeakMap,L=new WeakMap,Me=new WeakMap,gt=new WeakMap,Nt=new WeakMap,yt=new WeakMap,Wt=new WeakMap,qe=new WeakMap,si=new WeakMap,w=new WeakSet,On=function(e){let t=i(this,L).get(e);if(t===void 0)throw new Error(`entity with uuid "${e}" not found!`);return t},xn=function(e,t,r){let n=i(this,L).get(e);if(n===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}=n,l=[],h=a.children.map(d=>c(this,w,xn).call(this,d.uuid,t,l)).filter(d=>d!==void 0);return ue({token:o,entity:a,props:Object.fromEntries(a.propEntries()),children:h},l.length>0?{omittedChildren:l}:{})},oa=function(e){switch(e.type){case Te.CreateEntities:this.createEntity(e.uuid,e.token,e.parentUuid,e.order,e.properties,e.autoDestructionOnParentRemoval);break;case Te.DestroyEntities:this.destroyEntity(e.uuid);break;case Te.SetParent:this.setParent(e.uuid,e.parentUuid,e.order);break;case Te.UpdateOrder:this.updateOrder(e.uuid,e.order);break;case Te.ChangeProperties:this.changeProperties(e.uuid,e.properties);break;case Te.ChangeToken:this.changeToken(e.uuid,e.token);break;case Te.SendEvents:this.dispatchEventsToEntity(e.uuid,e.events);break}},aa=function(e){P(this.logger,()=>this.destroyEntity(e),"rollback of a failed entity creation could not destroy the entity:",e)},br=function(e,t=0,r,n){let o=c(this,w,On).call(this,e);r!=null||(r=new Set(this.registry.findConstructors(o.token,o.entity.truthyProps())));let a=t===0||t===2,l=t===0||t===1,h=[],d=[];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 C of g)c(this,w,Zr).call(this,C,o.entity)}}if(l){for(let y of r)if(!o.usedConstructors.has(y))try{d.push(c(this,w,Xr).call(this,y,o))}catch(g){throw c(this,w,la).call(this,o,d,h,n),g}}return r},la=function(e,t,r,n){if(i(this,L).get(e.entity.uuid)===e){n!==void 0&&(e.token=n);for(let o=t.length-1;o>=0;o--)P(this.logger,()=>c(this,w,Zr).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 l=0;l<a;l++)P(this.logger,()=>c(this,w,Xr).call(this,o,e),"rollback of a failed shadow-object update could not restore a shadow-object:",na(o),e.entity.uuid)}},Xr=function(e,t){let r=new Jr(t.entity,this.logger,na(e),i(this,si)),n;try{n=Y(new e(r.createAPI()))}catch(a){throw r.tearDown(),a}i(this,qe).set(n,r),r.bindTo(n,()=>{i(this,qe).delete(n)},()=>{let a=t.usedConstructors.get(e);a&&(a.delete(n),a.size===0&&t.usedConstructors.delete(e))});let o=t.usedConstructors.get(e);o?o.add(n):t.usedConstructors.set(e,new Set([n]));try{c(this,w,ha).call(this,n,t.entity)}catch(a){throw c(this,w,Zr).call(this,n,t.entity),a}return n},ca=function(e){var t;(t=this.registry.findConstructors(e.token,e.entity.truthyProps()))==null||t.forEach(r=>{c(this,w,Xr).call(this,r,e)})},ha=function(e,t){var r;for(let[n,o]of pc)if(typeof e[n]=="function"&&typeof e[o]!="function"){let a=(r=i(this,qe).get(e))==null?void 0:r.displayName;this.logger.error(`the "${n}" lifecycle hook is a plain method and is never called; use the [${n}] symbol from "@spearwolf/shadow-objects/shadow-objects.js":`,a)}A(t,e),typeof e[Vr]=="function"&&e[Vr](t)},zn=function(e,t){var n;let r=(n=i(this,qe).get(e))==null?void 0:n.displayName;typeof e[oe]=="function"&&P(this.logger,()=>e[oe](t),"shadow-object onDestroy hook failed:",r),P(this.logger,()=>mt(e,oe,t),"shadow-object onDestroy notification failed:",r)},Zr=function(e,t){var r;c(this,w,zn).call(this,e,t),(r=i(this,qe).get(e))==null||r.tearDown(),z(t,e)};var ua=s=>(typeof s=="string"&&(s=new URL(s,globalThis.location.href)),s.toString());var Pn=s=>typeof s=="object"&&s!==null,fa=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"}}},mr,ii,Ut,pt,da,ga,ya,ri=class{constructor(e){u(this,pt);u(this,mr,new Set);u(this,ii,new De("MessageRouter"));u(this,Ut,!1);var t,r;this.kernel=(t=e==null?void 0:e.kernel)!=null?t:new ei,this.postMessage=(r=e==null?void 0:e.postMessage)!=null?r:self.postMessage.bind(self),A(this.kernel,xs,"onMessageToView",this)}get logger(){return i(this,ii)}get isDestroyed(){return i(this,Ut)}route(e){var r;let t=e.data;if(!Pn(t)){this.logger.debug("discarding a message it cannot read",t);return}if(i(this,Ut)){this.logger.debug("discarding a message that arrived after the teardown",t.type);return}switch(t.type){case $n:c(this,pt,da).call(this,t);break;case _n:c(this,pt,ga).call(this,t);break;case Er:c(this,pt,ya).call(this,t);break;default:this.logger.warn("unknown message",(r=t.type)!=null?r:t)}}onMessageToView(e){let n=e,{transferables:t}=n,r=Bn(n,["transferables"]);this.postMessage({type:xs,data:r},{transfer:t!=null?t:[]})}};mr=new WeakMap,ii=new WeakMap,Ut=new WeakMap,pt=new WeakSet,da=async function(e){let t=e.importModule;try{if(!t)throw new Error(\'missing "importModule" url\');let r=await import(ua(t));if(i(this,Ut)){this.logger.debug("discarding a module that arrived after the teardown",t);return}r[zs]?(await ki(this.kernel,r[zs],i(this,mr)),this.postMessage({type:Sr,url:t})):this.postMessage({type:Sr,url:t,error:po})}catch(r){this.logger.error("failed to import module",r),this.postMessage(ue({type:Sr,url:t},fa(r)))}},ga=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 n=r instanceof qt?r:void 0;this.postMessage(ue(ue({type:fi,serial:e.serial},fa((t=n==null?void 0:n.cause)!=null?t:r)),n?{appliedCount:n.appliedCount}:{}))}return}e.serial!=null&&this.postMessage({type:fi,serial:e.serial})},ya=function(e){this.logger.debug("on destroy",e),f(this,Ut,!0),z(this.kernel,this);try{this.kernel.destroy()}catch(t){this.logger.error("failed to tear the kernel down",t)}i(this,mr).clear(),this.postMessage({type:In})};var oi,Ke,vt,ni=class{constructor(){u(this,oi);u(this,Ke);u(this,vt);f(this,Ke,!1),f(this,vt,!1),this.onmessage=e=>{var r;let t=e.data;if(!Pn(t)){this.logger.debug("discarding a message it cannot read",t);return}if(i(this,vt)){this.logger.debug("discarding a message that arrived after the teardown",t.type);return}if(t.type===Le){Qn(t.config),this.logger.debug("console-logger config installed",t.config);return}(r=this.router)!=null||(this.router=new ri),this.router.route(e),t.type===Er&&(f(this,vt,!0),this.stop(),this.router=void 0)}}get logger(){var e;return(e=i(this,oi))!=null?e:f(this,oi,new De("WorkerRuntime"))}get isStarted(){return i(this,Ke)}get isDestroyed(){return i(this,vt)}start(){i(this,vt)||i(this,Ke)||(f(this,Ke,!0),self.addEventListener("message",this.onmessage),self.postMessage({type:Gn}))}stop(){i(this,Ke)&&(f(this,Ke,!1),self.removeEventListener("message",this.onmessage))}};oi=new WeakMap,Ke=new WeakMap,vt=new WeakMap;var vc=new ni;vc.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 Uo=()=>new Ai;var or=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}};var Vo=s=>typeof s=="object"&&s!==null;var ar=2147483647,Ti=s=>typeof s=="number"&&Number.isFinite(s)&&s>0&&s<=ar,as=(s,e,t=1e3,r,i)=>new Promise((n,o)=>{if(t!==0&&t!==1/0&&!Ti(t)){o(new TypeError(`cannot wait for a ${e} message: expected a timeout of 1 to ${ar} 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 or(e,t))},t)),l=c=>{if(Vo(c.data)&&c.data.type===e)try{(!r||r(c.data))&&(h(),n())}catch(P){h(),o(P)}},i?.addEventListener("abort",u,{once:!0}),s.addEventListener("message",l)});var lh=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}},Ri=class extends Error{constructor(e,t,r){super(t,r),this.name="WorkerFailedError",this.type=e}},st=class extends Error{constructor(e="the worker environment has been destroyed"){super(e),this.name="WorkerDestroyedError"}},lr=class extends Error{constructor(e,t){super(t),this.name=e||"Error"}},Go={loadTimeout:Bn,configureTimeout:In,changeTrailTimeout:Un,destroyTimeout:Vn},hh=(s,e)=>{let t={...Go};if(s==null)return t;for(let r of Object.keys(Go)){if(!Object.hasOwn(s,r))continue;let i=s[r];i!==void 0&&(Ti(i)?t[r]=i:e.error(`ignoring the ${r} option: expected a number of milliseconds from 1 to ${ar}, got`,i))}return t},hr=class s{constructor(e){this.#t=!1,this.#s=0,this.#r=new AbortController,this.#i=new C("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===ft?this.onMessageToView?.(t.data.data):this.logger.debug("message from worker",t)},this.#n=Object.freeze(hh(e,this.logger)),oe(this,s.WorkerLoaded),oe(this,s.WorkerFailed)}static{this.WorkerLoaded="workerLoaded"}static{this.WorkerFailed="workerFailed"}#e;#t;#s;#r;#i;get logger(){return this.#i}#n;get timeouts(){return this.#n}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=A(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 st});let t=this.#e=Uo();t.addEventListener("error",this.onWorkerError),t.addEventListener("messageerror",this.onWorkerMessageError),this.configureConsoleLogger(t);try{if(await as(t,Nn,this.timeouts.loadTimeout,void 0,e),this.isDestroyed)throw e.aborted?e.reason:new st;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 st);let{changeTrail:n,transferables:o}=lh(e),a={type:Wn,changeTrail:n};if(!t)return i.postMessage(a,o??[]),Promise.resolve();let l=++this.#s;return a.serial=l,i.postMessage(a,o??[]),as(i,_n,this.timeouts.changeTrailTimeout,h=>{if(h.serial!==l)return!1;if(h.error){let u=new lr(h.errorName,h.error);throw typeof h.appliedCount=="number"?new ze(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 st):(e=ir(e),r.postMessage({type:Dn,importModule:e}),as(r,Fn,this.timeouts.configureTimeout,i=>{if(i.url!==e)return!1;if(i.error)throw new lr(i.errorName,i.error);return!0},t))}destroy(){this.#t=!0;let e=this.#e;this.#e=void 0,this.#r.abort(new st),e!=null&&(this.stopListeningTo(e),e.postMessage({type:$n}),as(e,jn,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 Ri(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=Qn(t),i=this.readWorkerConfig(t,r);this.logger.info("load console-logger worker config",{storageKey:r,workerConfig:i}),e.postMessage({type:be,config:{...C.sharedConfig,enable:this.logger.isEnabled,...i,...C.isEnabled?{}:{enable:!1}}})}readWorkerConfig(e,t){let r=Jn(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 ch=[["loadTimeout",Di],["configureTimeout",Wi],["changeTrailTimeout",$i],["destroyTimeout",Ni]];function qo(s){return typeof s!="string"?s?ls.DefaultAutoSync:"no":s.trim().toLowerCase()}var ls=class s extends Ne{constructor(){super(...arguments),this.isShaeWorkerElement=!0,this.shadowEnv=new Y,this.#e=new C("ShaeWorkerElement"),this.autostart=!0,this.isConnected$=f(!1),this.autoSync$=f(s.DefaultAutoSync),this.src$=f(""),this.#t=!1,this.#a=e=>{e instanceof $e||this.logger.error("shadowEnv failed",e)}}static{this.observedAttributes=[...Ne.observedAttributes,ke,"src",cs,re]}static{this.DefaultAutoSync="frame"}#e;get logger(){return this.#e}#t;#s;#r;#i;restore(){super.restore(),this.#i=this.ns$.onChange(e=>{this.shadowEnv.view=R.get(e)}),p(this.shadowEnv,Y.ContextCreated,()=>{this.#r?.run(),this.dispatchEvent(new CustomEvent(Y.ContextCreated.toLowerCase(),{bubbles:!1,detail:{shadowEnv:this.shadowEnv}}))}),p(this.shadowEnv,Y.ContextLost,()=>{this.dispatchEvent(new CustomEvent(Y.ContextLost.toLowerCase(),{bubbles:!1,detail:{shadowEnv:this.shadowEnv}}))}),p(this.shadowEnv,Y.ProxyFailed,e=>{this.dispatchEvent(new CustomEvent(Y.ProxyFailed.toLowerCase(),{bubbles:!1,detail:{shadowEnv:this.shadowEnv,reason:e}}))}),p(this.shadowEnv,Y.SyncFailed,(e,t)=>{this.dispatchEvent(new CustomEvent(Y.SyncFailed.toLowerCase(),{bubbles:!1,detail:{shadowEnv:this.shadowEnv,reason:e,changeTrail:t}}))}),this.autoSync$.onChange(e=>this.#n(e)),this.#n(this.autoSync$.value),this.#c(),this.#o(),this.shadowEnv.isReady&&this.#r?.run()}#n(e){this.reflectAttribute(re,()=>{let t=this.hasAttribute(re),r=t?this.getAttribute(re):void 0;e===s.DefaultAutoSync?t&&r!==e&&this.setAttribute(re,e):r!==e&&this.setAttribute(re,e)})}#o(){this.#r=T(()=>{let e=this.src$.get();e&&this.importScript(e).catch(this.#a)},{autorun:!1})}#a;get shouldAutostart(){return this.autostart&&!Oe(this,zi)}get autoSync(){return this.autoSync$.value}set autoSync(e){this.autoSync$.set(qo(e))}get frameLoop(){return ss.get()}[ss.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 $e;return await r.importScript(e),this}connectedCallback(){H(()=>{if(this.isDestroyed){Vs(this.getRootNode(),this.localName);return}super.connectedCallback(),q(()=>{let e=this.getAttribute(re);e!=null&&(this.autoSync=e),this.isConnected$.set(!0)}),this.shouldAutostart&&this.start().catch(this.#a)})}disconnectedCallback(){this.isConnected$.set(!1),super.disconnectedCallback()}attributeChangedCallback(e){if(!this.isDestroyed&&(super.attributeChangedCallback(e),e===ke&&this.#h(),e===cs&&this.#l(),e===re&&(this.autoSync=this.getAttribute(re)??!0),e==="src")){let t=(this.getAttribute("src")||"").trim();this.src$.set(t),this.shadowEnv.isReady&&this.#r?.run()}}#u(){let e={};for(let[t,r]of ch){let i=qn(this,r);i!==void 0&&(e[t]=i)}return e}start(){if(!this.#t){if(this.shadowEnv.view??=R.get(this.ns),this.shadowEnv.envProxy==null){let e=Oe(this,ke)?new nr:new hr(this.#u());this.shadowEnv.envProxy=e,this.#l()}this.#t=!0}return this.shadowEnv.ready()}teardown(){this.#i?.(),this.#i=void 0,this.#s?.destroy(),this.#r?.destroy(),x(this.isConnected$,this.autoSync$,this.src$),this.shadowEnv.envProxy=void 0,this.shadowEnv.destroy(),super.teardown()}#c(){this.#s=T(()=>{if(this.isConnected$.get()){let e=qo(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$])}#l(){let e=this.shadowEnv.envProxy;e?.isLocalEnv&&(e.disableStructuredClone=this.hasAttribute(cs))}#h(){let e=this.shadowEnv.envProxy;if(e==null)return;let t=!!e.isLocalEnv;Oe(this,ke)!==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(ke,()=>{t?this.setAttribute(ke,""):this.removeAttribute(ke)}))}};customElements.define(xi,ls);globalThis.SHADOW_OBJECTS_BUNDLE_LOADED=!0;
|
|
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}
|
|
22
|
+
|
|
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;
|
|
22
24
|
/*! Bundled license information:
|
|
23
25
|
|
|
24
26
|
@spearwolf/eventize/lib/index.mjs:
|