@spearwolf/shadow-objects 0.30.1 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +34 -10
  3. package/bundle.js +13 -13
  4. package/package.json +3 -3
  5. package/src/bundle.js +4 -4
  6. package/src/bundle.js.map +7 -1
  7. package/src/constants.js +53 -40
  8. package/src/constants.js.map +7 -1
  9. package/src/create-worker.bundle.js +6 -8
  10. package/src/create-worker.bundle.js.map +7 -1
  11. package/src/create-worker.js +5 -2
  12. package/src/create-worker.js.map +7 -1
  13. package/src/elements/ShaeElement.js +57 -54
  14. package/src/elements/ShaeElement.js.map +7 -1
  15. package/src/elements/ShaeEntElement.d.ts.map +1 -1
  16. package/src/elements/ShaeEntElement.js +320 -341
  17. package/src/elements/ShaeEntElement.js.map +7 -1
  18. package/src/elements/ShaePropElement.js +312 -320
  19. package/src/elements/ShaePropElement.js.map +7 -1
  20. package/src/elements/ShaeWorkerElement.js +234 -229
  21. package/src/elements/ShaeWorkerElement.js.map +7 -1
  22. package/src/elements/constants.js +37 -22
  23. package/src/elements/constants.js.map +7 -1
  24. package/src/elements/events.d.ts +1 -1
  25. package/src/elements/events.d.ts.map +1 -1
  26. package/src/elements/events.js +1 -2
  27. package/src/elements/events.js.map +7 -1
  28. package/src/elements.js +4 -4
  29. package/src/elements.js.map +7 -1
  30. package/src/in-the-dark/Entity.d.ts +3 -1
  31. package/src/in-the-dark/Entity.d.ts.map +1 -1
  32. package/src/in-the-dark/Entity.js +299 -275
  33. package/src/in-the-dark/Entity.js.map +7 -1
  34. package/src/in-the-dark/Kernel.d.ts +1 -1
  35. package/src/in-the-dark/Kernel.d.ts.map +1 -1
  36. package/src/in-the-dark/Kernel.js +556 -532
  37. package/src/in-the-dark/Kernel.js.map +7 -1
  38. package/src/in-the-dark/Registry.d.ts.map +1 -1
  39. package/src/in-the-dark/Registry.js +101 -104
  40. package/src/in-the-dark/Registry.js.map +7 -1
  41. package/src/in-the-dark/ShadowObject.d.ts.map +1 -1
  42. package/src/in-the-dark/ShadowObject.js +21 -23
  43. package/src/in-the-dark/ShadowObject.js.map +7 -1
  44. package/src/in-the-dark/SignalsPath.d.ts.map +1 -1
  45. package/src/in-the-dark/SignalsPath.js +139 -123
  46. package/src/in-the-dark/SignalsPath.js.map +7 -1
  47. package/src/in-the-dark/events.js +11 -9
  48. package/src/in-the-dark/events.js.map +7 -1
  49. package/src/in-the-dark/importModule.js +31 -29
  50. package/src/in-the-dark/importModule.js.map +7 -1
  51. package/src/index.d.ts +2 -2
  52. package/src/index.d.ts.map +1 -1
  53. package/src/index.js +14 -14
  54. package/src/index.js.map +7 -1
  55. package/src/shadow-objects.js +6 -6
  56. package/src/shadow-objects.js.map +7 -1
  57. package/src/shadow-objects.worker.js +3 -3
  58. package/src/shadow-objects.worker.js.map +7 -1
  59. package/src/shae-ent.js +3 -3
  60. package/src/shae-ent.js.map +7 -1
  61. package/src/shae-prop.js +3 -3
  62. package/src/shae-prop.js.map +7 -1
  63. package/src/shae-worker.js +3 -3
  64. package/src/shae-worker.js.map +7 -1
  65. package/src/types.d.ts +5 -4
  66. package/src/types.d.ts.map +1 -1
  67. package/src/types.js +1 -2
  68. package/src/types.js.map +7 -1
  69. package/src/utils/ConsoleLogger.js +179 -185
  70. package/src/utils/ConsoleLogger.js.map +7 -1
  71. package/src/utils/FrameLoop.js +41 -40
  72. package/src/utils/FrameLoop.js.map +7 -1
  73. package/src/utils/array-utils.js +22 -24
  74. package/src/utils/array-utils.js.map +7 -1
  75. package/src/utils/attr-utils.js +15 -11
  76. package/src/utils/attr-utils.js.map +7 -1
  77. package/src/utils/constants.js +5 -2
  78. package/src/utils/constants.js.map +7 -1
  79. package/src/utils/generateUUID.d.ts.map +1 -1
  80. package/src/utils/generateUUID.js +269 -32
  81. package/src/utils/generateUUID.js.map +7 -1
  82. package/src/utils/props-utils.js +34 -43
  83. package/src/utils/props-utils.js.map +7 -1
  84. package/src/utils/toMaybe.js +5 -2
  85. package/src/utils/toMaybe.js.map +7 -1
  86. package/src/utils/toNamespace.js +6 -3
  87. package/src/utils/toNamespace.js.map +7 -1
  88. package/src/utils/toUrlString.js +9 -6
  89. package/src/utils/toUrlString.js.map +7 -1
  90. package/src/utils/waitForMessageOfType.js +30 -32
  91. package/src/utils/waitForMessageOfType.js.map +7 -1
  92. package/src/view/ComponentChanges.d.ts +1 -1
  93. package/src/view/ComponentChanges.d.ts.map +1 -1
  94. package/src/view/ComponentChanges.js +249 -251
  95. package/src/view/ComponentChanges.js.map +7 -1
  96. package/src/view/ComponentContext.d.ts.map +1 -1
  97. package/src/view/ComponentContext.js +303 -331
  98. package/src/view/ComponentContext.js.map +7 -1
  99. package/src/view/ComponentMemory.d.ts +1 -0
  100. package/src/view/ComponentMemory.d.ts.map +1 -1
  101. package/src/view/ComponentMemory.js +73 -76
  102. package/src/view/ComponentMemory.js.map +7 -1
  103. package/src/view/IShadowObjectEnvProxy.js +1 -2
  104. package/src/view/IShadowObjectEnvProxy.js.map +7 -1
  105. package/src/view/LocalShadowObjectEnv.d.ts.map +1 -1
  106. package/src/view/LocalShadowObjectEnv.js +57 -52
  107. package/src/view/LocalShadowObjectEnv.js.map +7 -1
  108. package/src/view/RemoteWorkerEnv.js +134 -123
  109. package/src/view/RemoteWorkerEnv.js.map +7 -1
  110. package/src/view/ShadowEnv.d.ts.map +1 -1
  111. package/src/view/ShadowEnv.js +232 -228
  112. package/src/view/ShadowEnv.js.map +7 -1
  113. package/src/view/ViewComponent.d.ts +9 -0
  114. package/src/view/ViewComponent.d.ts.map +1 -1
  115. package/src/view/ViewComponent.js +142 -130
  116. package/src/view/ViewComponent.js.map +7 -1
  117. package/src/view/cloneChangeTrail.js +13 -11
  118. package/src/view/cloneChangeTrail.js.map +7 -1
  119. package/src/worker/MessageRouter.d.ts.map +1 -1
  120. package/src/worker/MessageRouter.js +78 -67
  121. package/src/worker/MessageRouter.js.map +7 -1
  122. package/src/worker/WorkerRuntime.js +22 -21
  123. package/src/worker/WorkerRuntime.js.map +7 -1
  124. package/tsconfig.lib.tsbuildinfo +0 -1
package/bundle.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*!
2
2
  @file @spearwolf/shadow-objects - a reactive entity-component framework that feels at home in the shadows
3
3
  @author Wolfger Schramm <wolfger@spearwolf.de>
4
- @version 0.30.1+bundle.20260209
4
+ @version 0.31.0+bundle.20260509
5
5
 
6
6
  Copyright 2026 Wolfger Schramm
7
7
 
@@ -18,17 +18,17 @@ See the License for the specific language governing permissions and
18
18
  limitations under the License.
19
19
 
20
20
  */
21
- var te="*",Zt=1,xt=2,kt=4,z=Symbol.for("eventize"),Hs="[eventize]",Fe=s=>s===te,es=s=>{switch(typeof s){case"string":case"symbol":return!0;default:return!1}},ts=typeof console<"u",Ks=ts?console[console.warn?"warn":"log"].bind(console,Hs):()=>{},Qs=(s,e,t)=>(Object.defineProperty(s,e,{value:t,configurable:!0}),s),Ys=0,ss=class{static publish(s){s.sort((e,t)=>e.order-t.order).forEach(e=>e.emit())}events=new Map;eventNames=new Set;add(s){Array.isArray(s)?s.forEach(e=>this.eventNames.add(e)):this.eventNames.add(s)}remove(s){Array.isArray(s)?s.forEach(e=>this.eventNames.delete(e)):this.eventNames.delete(s),this.clear(s)}clear(s){Array.isArray(s)?s.forEach(e=>this.events.delete(e)):this.events.delete(s)}retain(s,e){this.eventNames.has(s)&&this.events.set(s,{args:e,order:Ys++})}isKnown(s){return this.eventNames.has(s)}emit(s,e,t=[]){if(Fe(s))this.eventNames.forEach(r=>this.emit(r,e,t));else if(this.events.has(s)){let{order:r,args:i}=this.events.get(s);t.push({order:r,emit:()=>e.apply(s,i)})}return t}},Et=(s,e,t,r)=>{if(typeof e=="function"){let i=e.apply(s,t);i!=null&&r?.(i)}},Js=(s,e,t,r)=>Et(e,e.emit,[s].concat(t),r),Xs=s=>{switch(typeof s){case"function":return Zt;case"string":case"symbol":return xt;case"object":return kt}},Zs=0,er=()=>++Zs,rs=class{id;eventName;isCatchEmAll;priority;listener;listenerObject;listenerType;callAfterApply;isRemoved;refCount;constructor(s,e,t,r=null){this.id=er(),this.eventName=s,this.isCatchEmAll=Fe(s),this.listener=t,this.listenerObject=r,this.priority=e,this.listenerType=Xs(t),this.callAfterApply=void 0,this.isRemoved=!1,this.refCount=1}isEqual(s,e=null){if(s===this)return!0;let t=typeof s;return t==="number"&&s===this.id?!0:e===null&&(t==="string"||t==="symbol")?s===te||s===this.eventName:this.listener===s&&this.listenerObject===e}apply(s,e,t){if(this.isRemoved)return;let{listener:r,listenerObject:i}=this;switch(this.listenerType){case Zt:Et(i,r,e,t),this.callAfterApply&&this.callAfterApply();break;case xt:Et(i,i[r],e,t),this.callAfterApply&&this.callAfterApply();break;case kt:{let n=r[s];if(this.isCatchEmAll||this.eventName===s){if(typeof n=="function"){let o=n.apply(r,e);o!=null&&t?.(o)}else Js(s,r,e,t);this.callAfterApply&&this.callAfterApply()}break}}}},tr=(s,e)=>s.priority!==e.priority?e.priority-s.priority:s.id-e.id,Yt=s=>s?.slice(0),Jt=(s,e)=>{let t=s.indexOf(e);t>-1&&s.splice(t,1)},sr=s=>s===kt||s===xt,St=(s,e,t)=>{let r=s.findIndex(i=>i.isEqual(e,t));r>-1&&(s[r].isRemoved=!0,s.splice(r,1))},Ie=(s,e,t)=>{let r=[];for(let i of s)(e==null&&i.listenerObject===t||i.eventName===e&&i.listener===t)&&r.push(i);for(let i of r)St(s,i,void 0)},Ct=s=>{s&&(s.forEach(e=>{e.isRemoved=!0}),s.length=0)},rr=(s,e)=>s.listenerType===e.listenerType?s.priority===e.priority&&s.eventName===e.eventName&&s.listenerObject===e.listenerObject&&s.listener===e.listener:!1,ir=(s,e)=>{if(sr(s.listenerType))return e.find(t=>rr(s,t))},nr=(s,e)=>{let t=ir(s,e);return t?(t.refCount+=1,t):(e.push(s),e.sort(tr),s)},or=class{namedListeners;catchEmAllListeners;getListenersForEventName=s=>{let e=this.namedListeners.get(s);return e||(e=[],this.namedListeners.set(s,e)),e};constructor(){this.namedListeners=new Map,this.catchEmAllListeners=[]}add(s){return nr(s,s.isCatchEmAll?this.catchEmAllListeners:this.getListenersForEventName(s.eventName))}remove(s,e,t=!1){e==null&&Array.isArray(s)?s.forEach(r=>this.remove(r,null,t)):s==null||e==null&&Fe(s)?this.removeAllListeners():e==null&&es(s)?Ct(this.namedListeners.get(s)):s instanceof rs?s.isRemoved||(s.refCount-=1,s.refCount<1&&(s.isRemoved=!0,this.namedListeners.forEach(r=>Jt(r,s)),Jt(this.catchEmAllListeners,s))):t?Fe(s)&&typeof s=="object"?Ie(this.catchEmAllListeners,te,s):this.namedListeners.forEach(r=>Ie(r,s,e)):(this.namedListeners.forEach(r=>{St(r,s,e),typeof s=="object"&&Ie(r,void 0,s)}),St(this.catchEmAllListeners,s,e),typeof s=="object"&&Ie(this.catchEmAllListeners,void 0,s))}removeAllListeners(){this.namedListeners.forEach(s=>Ct(s)),this.namedListeners.clear(),Ct(this.catchEmAllListeners)}forEach(s,e){let t=Yt(this.catchEmAllListeners),r=Yt(this.namedListeners.get(s));if(s===te||!r||r.length===0)t.forEach(e);else if(t.length===0)r.forEach(e);else{let i=r.length,n=t.length,o=0,l=0;for(;o<i||l<n;){if(o<i){let a=r[o];if(l>=n||a.priority>=t[l].priority){e(a),++o;continue}}l<n&&(e(t[l]),++l)}}}getSubscriptionCount(){let s=this.catchEmAllListeners.length;for(let e of this.namedListeners.values())s+=e.length;return s}},se=s=>!!(s&&s[z]);function ve(s){if(se(s))return s;let e=new or,t=new ss;return Qs(s,z,{keeper:t,store:e}),s}var V={Max:Number.POSITIVE_INFINITY,AAA:1e9,BB:1e6,C:1e3,Default:0,Low:-1e4,Min:Number.NEGATIVE_INFINITY},ar=(s,e,t,r,i,n,o)=>{let l=s.add(new rs(t,r,i,n));return e.emit(t,l,o),l},hr=(s,e,t,r)=>{let i=t.length,n=typeof t[0],o,l,a,f;if(i>=2&&i<=3&&n==="number"?(o=te,[l,a,f]=t):i>=3&&i<=4&&typeof t[1]=="number"?[o,l,a,f]=t:(l=V.Default,n==="string"||n==="symbol"||Array.isArray(t[0])?[o,a,f]=t:(o=te,[a,f]=t)),!a&&ts)throw Ks("called with insufficient arguments!",t),"subscribeTo() called with insufficient arguments!";let w=v=>u=>ar(s,e,u,v,a,f,r);return Array.isArray(o)?o.map(v=>Array.isArray(v)?w(v[1])(v[0]):w(l)(v)):w(l)(o)},is=(s,e,t)=>{let r=[],i=hr(s,e,t,r);return ss.publish(r),i},Xt=s=>e=>{e.callAfterApply=()=>{s?.()}},ns=(s,e)=>Object.assign(()=>E(s,e),Array.isArray(e)?{listeners:e}:{listener:e}),os=(s,e,t,r)=>{let{store:i,keeper:n}=s[z];Array.isArray(e)?e.forEach(o=>{i.forEach(o,l=>l.apply(o,t,r)),n.retain(o,t)}):e!==te&&(i.forEach(e,o=>{o.apply(e,t,r)}),n.retain(e,t))},m=(s,...e)=>{let t=ve(s),{store:r,keeper:i}=t[z];return ns(t,is(r,i,e))},S=(s,...e)=>{let t=ve(s),{store:r,keeper:i}=t[z],n=is(r,i,e),o=ns(t,n),l=!1,a=()=>{l||(o(),l=!0)};return Array.isArray(n)?n.forEach(Xt(a)):Xt(a)(n),a},le=(s,e)=>new Promise(t=>{S(s,e,t)}),E=(s,e,t)=>{if(!se(s))throw new Error("object is not eventized");let{store:r,keeper:i}=s[z],n=typeof e,o=t!=null&&(n==="string"||n==="symbol");r.remove(e,t,o),Array.isArray(e)?i.remove(e.filter(l=>typeof l=="string")):es(e)&&i.remove(e)},y=(s,e,...t)=>{if(!se(s))throw new Error("object is not eventized");os(s,e,t)},lr=(s,e,...t)=>{if(!se(s))throw new Error("object is not eventized");let r=[];return os(s,e,t,i=>{r.push(i)}),r=r.map(i=>Array.isArray(i)?Promise.all(i):Promise.resolve(i)),r.length>0?Promise.all(r):Promise.resolve()},U=(s,e)=>{let t=ve(s),{keeper:r}=t[z];r.add(e)},Q=(s,e)=>{if(!se(s))throw new Error("object is not eventized");let{keeper:t}=s[z];t.clear(e)},x=(()=>{let s=(e={})=>ve(e);return s.inject=(e={})=>(e=ve(e),Object.assign(e,{on:(...t)=>m(e,...t),once:(...t)=>S(e,...t),onceAsync:t=>le(e,t),off:(t,r)=>E(e,t,r),emit:(t,...r)=>y(e,t,...r),emitAsync:(t,...r)=>lr(e,t,...r),retain:t=>U(e,t),retainClear:t=>Q(e,t)}),e),s.is=se,s})();var At=s=>se(s)?s[z]?.store?.getSubscriptionCount()??0:0;var $=Symbol.for("signal"),ue=Symbol.for("effect"),as=Symbol.for("destroySignal"),hs=Symbol.for("createEffect"),ur=Symbol.for("destroyEffect"),ce="value",Rt="mute",Mt="unmute",de="destroy",we=Symbol.for("recall"),Ce=x(),ne=x(),re=x(),us=x(),ie=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}else{this.delayedEffects.splice(i,0,[t,new Set([e])]);return}}this.delayedEffects.push([t,new Set([e])])}flush(){this.run(),this.delayedEffects.length=0}run(){let e=new Set,t=[m(re,(i,n)=>{n===we&&e.add(i)}),m(us,i=>{e.add(i)})],r=this.delayedEffects.flatMap(([,i])=>Array.from(i));for(let i of r)e.has(i)||y(re,i,i,we);t.forEach(i=>{i()})}},cs=()=>ie.current;function P(s){let e=ie.current;e?e=void 0:e=ie.current=new ie;try{s()}finally{e&&(ie.current=void 0,e.run())}}var Ot=0;function qe(s){Ot++;try{s()}finally{Ot--}}function Lt(){return Ot>0}var ze=class{[ue];constructor(e){this[ue]=e,S(e,Ue.Destroy,()=>{this[ue]=void 0})}run=()=>this[ue]?.run();destroy=()=>{this[ue]?.destroy(),this[ue]=void 0}},Y=new Map,B=class s{#e=new Set;#t=new Set;#s=new Map;#i=new WeakMap;#r=new Map;#n=new Set;#o=new Set;#a;#h;static get(e){if(e!=null)return e instanceof s?e:Y.get(e)}static findOrCreate(e){if(e==null)throw new Error("Cannot create a group with a null object");return new s(e)}static destroy(e){console.warn("SignalGroup.destroy(obj) is deprecated. Use SignalGroup.delete(obj) instead."),s.delete(e)}static delete(e){Y.get(e)?.clear()}static clear(){for(let e of Y.values())e.clear();Y.clear()}constructor(e){if(e!=null&&e instanceof s)return e;if(e??=this,Y.has(e))return Y.get(e);this.#h=e,Y.set(e,this),x(this)}attachGroup(e){if(e===this)throw new Error("Cannot attach a group to itself");return this.#e.add(e),e.#a&&e.#a!==this&&e.#a.#e.delete(e),e.#a=this,e}detachGroup(e){return e!==this&&this.#e.has(e)&&(this.#e.delete(e),e.#a=void 0),e}attachSignal(e){let t=k(e);if(t?.destroyed)throw new Error("Cannot attach a destroyed signal to a group");return t&&this.#t.add(t),e}attachSignalByName(e,t){if(t){this.attachSignal(t);let r=k(t);this.#s.set(e,r),this.#r.has(e)?this.#r.get(e).push(r):this.#r.set(e,[r]),this.#i.has(r)?this.#i.get(r).add(e):this.#i.set(r,new Set([e]))}else this.#s.delete(e);return t}hasSignal(e){return this.#s.has(e)||!!this.#a?.hasSignal(e)}signal(e){return this.#s.get(e)?.object??this.#a?.signal(e)}detachSignal(e){let t=k(e);if(t&&(this.#t.delete(t),this.#i.has(t))){let r=this.#i.get(t);for(let i of r)if(this.#r.has(i)){let n=this.#r.get(i);n.splice(n.indexOf(t),1),n.length===0?(this.#s.delete(i),this.#r.delete(i)):this.#s.get(i)===t&&this.#s.set(i,n.at(-1))}r.clear(),this.#i.delete(t)}return e}attachEffect(e){return this.#n.add(e),e}runEffects(){for(let e of this.#n)e.run();for(let e of this.#e)e.runEffects()}attachLink(e){if(e?.isDestroyed)throw new Error("Cannot attach a destroyed link to a group");return e&&this.#o.add(e),e}detachLink(e){return e&&this.#o.delete(e),e}destroy(){console.warn("SignalGroup#destroy is deprecated. Use SignalGroup#clear instead."),this.clear()}clear(){y(this,de,this),E(this);for(let e of this.#e)e.clear();for(let e of this.#n)e.destroy();for(let e of this.#t)O(e);for(let e of this.#o)e.destroy();this.#e.clear(),this.#t.clear(),this.#s.clear(),this.#r.clear(),this.#n.clear(),this.#o.clear(),this.#a?.detachGroup(this),this.#h&&(Y.delete(this.#h),this.#h=void 0)}},Ve=class{#e;#t;constructor(e="id",t=1){this.#e=e,this.#t=t}make(){return Symbol(`${this.#e}${this.#t++}`)}},Tt=[],ds=()=>Tt.at(-1),cr=(s,e)=>{Tt.push(s);try{return e()}finally{Tt.pop()}};var dr=s=>s!=null&&typeof s.then=="function",Ue=class s{static idGen=new Ve("ef");static Destroy="destroy";static count=0;id;callback;#e;#t=new Set;#s=new Set;#i=new Map;#r=new Set;parentEffect;childEffects=[];curChildEffectSlot=0;autorun=!0;shouldRun=!0;priority;#n;#o=!1;constructor(e,t){x(this),this.callback=e;let r;t?.attach!=null&&(r=B.findOrCreate(t.attach),r.attachEffect(this)),this.autorun=t?.autorun??!0,this.#n=t?.dependencies?t.dependencies.map(i=>{switch(typeof i){case"string":case"symbol":return r.signal(i);default:return i}}):void 0,this.id=s.idGen.make(),this.priority=t?.priority??0,m(re,this.id,we,this),++s.count}hasStaticDeps(){return this.#n!=null&&this.#n.length>0}saveSignalsFromDeps(){for(let e of this.#n)this.whenSignalIsRead(k(e).id)}static createEffect(e,t,r){let i=Array.isArray(t)?t:void 0,n=i?r??{dependencies:i}:t;n&&i&&(n.dependencies=i);let o,l=ds();return l!=null?(o=l.getCurrentChildEffect(),o==null&&(o=new s(e,n),l.attachChildEffect(o),y(re,hs,o)),l.curChildEffectSlot++):(o=new s(e,n),y(re,hs,o)),o.hasStaticDeps()?o.saveSignalsFromDeps():o.autorun&&o.run(),new ze(o)}getCurrentChildEffect(){return this.childEffects[this.curChildEffectSlot]}attachChildEffect(e){this.childEffects.push(e),this.parentEffect=this}run=()=>{if(this.#o||!this.shouldRun)return;let e=cs();e?e.batch(this.id,this.priority):(this.runCleanupCallback(),this.destroyChildEffects(),this.curChildEffectSlot=0,this.shouldRun=!1,y(us,this.id,this.id),this.hasStaticDeps()?this.#e=this.callback():(this.#s=new Set(this.#t),this.#e=cr(this,this.callback),this.cleanupLostSignals(),this.#r.clear()))};[we](){this.shouldRun=!0,this.autorun&&this.run()}whenSignalIsRead(e){this.#s.delete(e),this.#t.has(e)||(this.#t.add(e),this.#i.set(e,[m(Ce,e,this.priority,we,this),S(ne,e,as,this)]))}[as](e){!this.#r.has(e)&&this.#t.has(e)&&(this.#r.add(e),this.unsubscribeSignal(e),this.#r.size===this.#t.size&&this.destroy())}cleanupLostSignals(){for(let e of this.#s)this.unsubscribeSignal(e),this.#t.delete(e)}destroyChildEffects(){for(let e of this.childEffects)e.destroy();this.childEffects.length=0}unsubscribeSignal(e){this.#i.has(e)&&(this.#i.get(e).forEach(t=>{t()}),this.#i.delete(e))}runCleanupCallback(){if(this.#e!=null){let e=this.#e;this.#e=void 0,dr(e)?Promise.resolve(e).then(t=>{typeof t=="function"&&t()}):e()}}destroy=()=>{this.#o||(y(this,s.Destroy,this),E(this),y(re,ur,this),this.runCleanupCallback(),this.destroyChildEffects(),E(Ce,this),E(re,this),E(ne,this),this.#o=!0,this.#t.clear(),this.#s.clear(),this.#i.clear(),this.#r.clear(),--s.count)}},C=(...s)=>Ue.createEffect(...s);var Ee=new WeakMap,fr=s=>{let e=Ee.get(s);return e||(e={},Ee.set(s,e)),e},_=(s,e)=>Ee.get(s)?.signals?.get(e);var fs=(s,e,t)=>{let r=fr(s);r.signals??=new Map,r.signals.set(e,t)};function Se(...s){for(let e of s)if(Ee.has(e)){let t=Ee.get(e);if(t.signals){for(let r of t.signals.values())O(r);t.signals.clear(),t.signals=void 0}}}function ps(s){let e=k(oe(s)?s:_(...s));e!=null&&!e.muted&&!e.destroyed&&Pt(e.id,e.value,{touch:!0})}function fe(s){return oe(s)?k(s)?.value:k(_(...s))?.value}var Be=class{[$];constructor(e){this[$]=e}get get(){return this[$].reader}get set(){return this[$].writer}get value(){return fe(this.get)}set value(e){this.set(e)}onChange(e){let{destroy:t}=C(()=>e(this.value),[this.get]);return t}get muted(){return this[$].muted}set muted(e){this[$].muted=e}touch(){ps(this)}destroy(){O(this)}},pr=new Ve("si");function ls(s){Lt()||ds()?.whenSignalIsRead(s)}function Pt(s,e,t){Lt()||y(Ce,s,e,t)}var oe=s=>s!=null&&s[$]!=null,gr=s=>{let e=t=>(t?C(()=>(s.destroyed||ls(s.id),t(s.value)),[e]):s.destroyed||(s.beforeRead?.(),ls(s.id)),s.value);return Object.defineProperty(e,$,{value:s}),e},Ge=class s{static instanceCount=0;id;lazy;get[$](){return this}compare;beforeRead;muted=!1;destroyed=!1;#e=void 0;get value(){return this.lazy&&(this.#e=this.valueFn(),this.valueFn=void 0,this.lazy=!1),this.#e}set value(e){this.#e=e}valueFn;reader;writer=(e,t)=>{let r=t?.lazy??!1,n=t?.compare??this.compare??((l,a)=>l===a);if((r!==this.lazy||r&&e!==this.valueFn||!r&&!n(e,this.#e))&&(r?(this.#e=void 0,this.valueFn=e,this.lazy=!0):(this.#e=e,this.valueFn=void 0,this.lazy=!1),!this.muted&&!this.destroyed)){Pt(this.id,this.#e);return}(t?.touch??!1)&&Pt(this.id,this.#e,{touch:!0})};object;constructor(e,t){this.id=pr.make(),++s.instanceCount,this.lazy=e,this.lazy?(this.value=void 0,this.valueFn=t):(this.value=t,this.valueFn=void 0),this.reader=gr(this),this.object=new Be(this)}},k=s=>s?.[$];function p(s=void 0,e){let t;if(oe(s))t=k(s);else{let r=e?.lazy??!1;t=new Ge(r,s),t.beforeRead=e?.beforeRead,t.compare=e?.compare}return e?.attach!=null&&B.findOrCreate(e.attach).attachSignal(t),t.object}var O=(...s)=>{for(let e of s){let t=k(e);t!=null&&!t.destroyed&&(t.destroyed=!0,t.beforeRead=void 0,--Ge.instanceCount,y(ne,t.id,t.id))}};function He(s,e){let t=p(),r=e?.attach!=null?B.findOrCreate(e.attach):void 0;r!=null&&(e?.name?r.attachSignalByName(e.name,t):r.attachSignal(t));let i=C(()=>{P(()=>{t.set(s())})},{autorun:!(e?.lazy??!1),priority:e?.priority??V.C,attach:r}),n=k(t);return n.beforeRead=i.run,S(ne,n.id,i.destroy),t.get}var Qe=class{#e=!1;#t;source;lastValue;isDestroyed=!1;constructor(e){x(this),this.source=k(e),this.#t=m(Ce,this.source.id,(t,r)=>{!this.#e&&!this.isDestroyed&&(r?.touch===!0?this.touch():this.write())}),S(ne,this.source.id,()=>this.destroy())}attach(e){let t=B.findOrCreate(e);return t.attachLink(this),S(this,de,()=>{t.detachLink(this)}),t}nextValue(){return new Promise((e,t)=>{let r=[],i=()=>r.forEach(n=>{n()});r.push(S(this,ce,n=>{i(),e(n)}),S(this,de,()=>{i(),t()}))})}async*asyncValues(e){U(this,ce);try{let t=0;for(;!this.isDestroyed;)try{let r=await this.nextValue();if(e&&e(r,t++))break;yield r}catch{break}}finally{Q(this,ce)}}destroy(){this.isDestroyed||(this.#t?.(),this.#t=void 0,y(this,de,this),Q(this,ce),E(this),this.lastValue=void 0,this.isDestroyed=!0,Object.freeze(this))}get isMuted(){return this.#e}mute(){return!this.isDestroyed&&!this.#e&&(this.#e=!0,y(this,Rt,this)),this}unmute(){return!this.isDestroyed&&this.#e&&(this.#e=!1,y(this,Mt,this)),this}toggleMute(){return this.isDestroyed||(this.#e=!this.#e,y(this,this.#e?Rt:Mt,this)),this.#e}updateValue(e){if(!this.#e&&!this.isDestroyed){let{value:t}=this.source;e(t),y(this,ce,t),this.lastValue=t}}},jt=class extends Qe{target;constructor(e,t){super(e),this.target=k(t),S(ne,this.target.id,()=>this.destroy()),this.touch()}touch(){return this.updateValue(e=>{this.target.writer(e,{touch:!0})}),this}write(){this.updateValue(e=>{this.target.writer(e)})}},Dt=class extends Qe{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)})}},Ke=new Map;function R(s,e,t){let r=k(s),i;if(Ke.has(r)){i=Ke.get(r);let f=k(e)??e;if(i.has(f))return i.get(f)}else i=new Map,Ke.set(r,i);let n=k(e),o=n!=null?new jt(s,n):new Dt(s,e),l=t?.attach;l&&o.attach(l);let a=n??e;return i.set(a,o),S(o,de,()=>{i.delete(a),i.size===0&&Ke.delete(r)}),o}var Ye=class s{static fromProps(e,t){let r=new s,i=t?t.map(n=>[n,e[n]]):Object.entries(e);for(let[n,o]of i)r.#e.set(n,p(o));return r}#e=new Map;keys(){return this.#e.keys()}signals(){return this.#e.values()}entries(){return this.#e.entries()}clear(){for(let e of this.#e.values())e.destroy();this.#e.clear()}has(e){return this.#e.has(e)}get(e){if(!this.#e.has(e)){let t=p();return this.#e.set(e,t),t}return this.#e.get(e)}update(e){e.size&&P(()=>{for(let[t,r]of e.entries())this.get(t).set(r)})}updateFromProps(e,t){P(()=>{let r=t?t.map(i=>[i,e[i]]):Object.entries(e);for(let[i,n]of r)this.get(i).set(n)})}};var W;(function(s){s[s.StructuralChanges=1]="StructuralChanges",s[s.ContentUpdates=2]="ContentUpdates",s[s.Removal=3]="Removal"})(W||(W={}));var b;(function(s){s[s.CreateEntities=1]="CreateEntities",s[s.DestroyEntities=2]="DestroyEntities",s[s.SetParent=3]="SetParent",s[s.UpdateOrder=4]="UpdateOrder",s[s.ChangeProperties=5]="ChangeProperties",s[s.ChangeToken=6]="ChangeToken",s[s.SendEvents=7]="SendEvents"})(b||(b={}));var ae=Symbol.for("ShadowEntsGlobalNS"),G="#void",gs="contextLost",ys="configure",ms="changeTrail",bs="destroy",vs="loaded",ws="appliedChangeTrail",Cs="importedModule",Es="destroyed",pe="messageToView",Ss=6e4,xs=6e4,ks=5e3,As=5e3,_t="shadowObjects";function Os(s,e){s.indexOf(e)===-1&&s.push(e)}function Nt(s,e){let t=s.indexOf(e);t!==-1&&s.splice(t,1),s.push(e)}function J(s,e){let t=s.indexOf(e);t!==-1&&s.splice(t,1)}var he=s=>typeof s=="string"?s.trim()||ae:typeof s=="symbol"?s:ae;var xe="#root",ke=class{#e;get uuid(){return this.#e}#t=0;constructor(e){this.#e=e}#s=!0;#i=0;#r=0;hasChanges(){return this.#t>0}get isNew(){return this.#s}get isCreated(){return this.#i>0&&this.#i>this.#r}get isDestroyed(){return this.#r>0&&this.#r>=this.#i}#n=G;#o;#a=0;#h;#l;#u;create(e=G,t,r=0){this.#t++,this.#i++,this.#h=e,this.#l=t??xe,this.#u=r||void 0}destroy(){this.#r++,this.#t++}clear(){this.#t=0,this.#s=!1,this.#h=void 0,this.#l=void 0,this.#u=void 0,this.#d.clear(),this.#f.length=0,this.#g.length=0,this.#p.clear()}changeToken(e){e===this.#n?this.#h=void 0:(this.#h=e,this.#t++)}setParent(e){e===this.#o?this.#l=void 0:(this.#l=e??xe,this.#t++)}changeOrder(e){e===this.#a?this.#u=void 0:(this.#u=e,this.#t++)}#c=new Map;#d=new Map;#f=[];changeProperty(e,t,r){let i=this.#c.get(e);r==null&&t!==i||r!=null&&!r(t,i)?(this.#d.set(e,t),Nt(this.#f,e),this.#t++):(this.#d.delete(e),J(this.#f,e))}removeProperty(e){let t=this.#c.has(e);this.#d.has(e)?(this.#d.delete(e),t||J(this.#f,e)):t&&(Nt(this.#f,e),this.#t++)}#g=[];#p=new Set;createEvent(e,t,r){this.#g.push({type:e,data:t}),r?.forEach(i=>this.#p.add(i)),this.#t++}transferEventsTo(e){this.#g.length>0&&(e.#g.push(...this.#g),this.#g.length=0),this.#p.size>0&&(e.#p=new Set([...e.#p,...this.#p]),this.#p.clear())}buildChangeTrail(e,t){let{isNew:r,isCreated:i,isDestroyed:n}=this;if(!(r&&n))switch(t){case W.StructuralChanges:r?e.push(this.makeCreateEntityChange()):n||(this.#l!==void 0&&!(this.#l===xe&&this.#o===void 0)?e.push(this.makeSetParentChange()):this.#u!==void 0&&this.#u!==this.#a&&e.push(this.makeUpdateOrderChange()),this.#h!==void 0&&this.#h!==this.#n&&e.push(this.makeChangeToken()));break;case W.ContentUpdates:!r&&i&&this.#f.length>0&&e.push(this.makeChangePropertyChange()),this.#g.length>0&&e.push(this.makeEvents());break;case W.Removal:n&&e.push(this.makeDestroyEntityChange());break}}makeEvents(){let e={type:b.SendEvents,uuid:this.#e,events:this.#g.slice(0)};return this.#p.size>0&&(e.transferables=Array.from(this.#p)),e}makeCreateEntityChange(){let e={type:b.CreateEntities,uuid:this.#e,token:this.#h};if(this.#n=this.#h,this.#l!==void 0){let t=this.#l===xe?void 0:this.#l;this.#o=t,t!==void 0&&(e.parentUuid=t)}return this.#d.size>0&&(e.properties=Array.from(this.#d.entries()).filter(([,t])=>t!==void 0),e.properties.forEach(([t,r])=>this.#c.set(t,r))),this.#u!==void 0&&this.#u!==this.#a&&(e.order=this.#a=this.#u),e}makeDestroyEntityChange(){return{type:b.DestroyEntities,uuid:this.#e}}makeSetParentChange(){this.#o=this.#l===xe?void 0:this.#l;let e={type:b.SetParent,uuid:this.#e,parentUuid:this.#o};return this.#u!==void 0&&this.#u!==this.#a&&(e.order=this.#a=this.#u),e}makeUpdateOrderChange(){return this.#a=this.#u??0,{type:b.UpdateOrder,uuid:this.#e,order:this.#a}}makeChangeToken(){return this.#n=this.#h??G,{type:b.ChangeToken,uuid:this.#e,token:this.#n}}makeChangePropertyChange(){let e=this.#f.map(t=>{if(this.#d.has(t)){let r=this.#d.get(t);return this.#c.set(t,r),[t,r]}else return this.#c.delete(t),[t,void 0]});return{type:b.ChangeProperties,uuid:this.#e,properties:e}}};var Ts=s=>{if(!(s===void 0||s.length===0))return s.filter(e=>e.length===1||e[1]!==void 0)},$t=(s,e)=>{if(s===e||e===void 0)return s;if(s===void 0)return Ts(e);for(let[t,r]of e){let i=s.find(([n])=>n===t);i===void 0?s.push([t,r]):i[1]=r}return Ts(s)};var Je=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===b.CreateEntities)this.createEntity(t);else if(this.#e.has(t.uuid))switch(t.type){case b.DestroyEntities:this.destroyEntity(t);break;case b.SetParent:this.setParent(t);break;case b.UpdateOrder:this.updateOrder(t);break;case b.ChangeToken:this.changeToken(t);break;case b.ChangeProperties:this.changeProperties(t);break}}changeProperties({uuid:e,properties:t}){let r=this.getComponentState(e);r.properties=$t(r.properties,t)}changeToken({uuid:e,token:t}){this.getComponentState(e).token=t||G}updateOrder({uuid:e,order:t}){this.getComponentState(e).order=t??0}setParent({uuid:e,parentUuid:t,order:r}){let i=this.getComponentState(e);i.parentUuid=t,i.order=r??0}destroyEntity({uuid:e}){this.#e.delete(e)}createEntity({uuid:e,token:t,parentUuid:r,order:i,properties:n}){this.#e.set(e,{token:t||G,parentUuid:r,order:i??0,properties:$t(void 0,n)})}};var M=class s{static{this.ReRequestParentRoots="re-request-parent-roots"}static getContextsMap(){return globalThis.__shadowEntsContexts==null&&(globalThis.__shadowEntsContexts=new Map),globalThis.__shadowEntsContexts}static get(e){let t=he(e),r=s.getContextsMap();return r.has(t)?r.get(t):new s(t)}#e=new Map;#t=[];#s=new Je;constructor(e=ae){let t=he(e),r=s.getContextsMap();if(r.has(t))return r.get(t);this.ns=t,r.set(t,this)}addComponent(e){let t;this.#e.has(e.uuid)?(t=this.#e.get(e.uuid),t.component=e,t.children=[]):(t={component:e,children:[],changes:new ke(e.uuid),propIsEqual:void 0},this.#e.set(e.uuid,t)),t.changes.create(e.token,e.parent?.uuid,e.order),e.parent?(this.addToChildren(e.parent,e),t.changes.setParent(e.parent.uuid)):this.#n(e,this.#t),this.#o=void 0}hasComponent(e){return this.#e.has(e.uuid)}hasComponents(){return this.#e.size>0}isRootComponent(e){return this.#t.includes(e.uuid)}destroyComponent(e){if(this.hasComponent(e)){let t=this.#e.get(e.uuid);t.children.slice(0).forEach(r=>this.#e.get(r)?.component.removeFromParent()),t.changes.destroy(),this.#o=void 0}}getChildren(e){return this.#e.get(e.uuid)?.children.map(t=>this.#e.get(t).component)??[]}removeFromParent(e,t){if(this.hasComponent(t)){let r=this.#e.get(e),i=this.#e.get(t.uuid),n=i.children.indexOf(e);n!==-1&&(i.children.splice(n,1),r.changes.setParent(void 0)),this.#n(r.component,this.#t),this.#o=void 0}}moveToRoot(e){let t=this.#e.get(e);t&&(t.changes?.setParent(void 0),this.#n(t.component,this.#t)),this.#o=void 0}changeToken(e,t){this.#e.get(e.uuid)?.changes.changeToken(t)}isChildOf(e,t){return this.hasComponent(t)?this.#e.get(t.uuid).children.includes(e.uuid):!1}addToChildren(e,t){let r=this.#e.get(e.uuid);if(r)this.#n(t,r.children),this.#e.get(t.uuid)?.changes.setParent(e.uuid),J(this.#t,t.uuid),this.#o=void 0;else throw new Error(`the view component ${e.uuid} cannot have a child added to it because the component do not exist!`)}removeSubTree(e){let t=this.#e.get(e);t&&(t.children.slice(0).forEach(r=>this.removeSubTree(r)),this.destroyComponent(t.component),this.#i(e))}setProperty(e,t,r,i){let n=this.#e.get(e.uuid);return n!=null?(i!=null?(n.propIsEqual??=new Map,n.propIsEqual.set(t,i)):n.propIsEqual?.has(t)&&n.propIsEqual.delete(t),n.changes.changeProperty(t,r,i)):!1}removeProperty(e,t){this.#e.get(e.uuid)?.changes.removeProperty(t)}changeOrder(e){if(e.parent){let t=this.#e.get(e.parent.uuid);J(t.children,e.uuid),this.#n(e,t.children)}else J(this.#t,e.uuid),this.#n(e,this.#t);this.#e.get(e.uuid)?.changes.changeOrder(e.order),this.#o=void 0}traverseLevelOrderBFS(){return this.#a().map(e=>e.component)}dispatchShadowObjectsEvent(e,t,r,i){this.#e.get(e.uuid)?.changes.createEvent(t,r,i)}broadcastEvent(e,t=void 0){for(let r of this.traverseLevelOrderBFS())r.dispatchEvent(e,t,!1)}dispatchMessage(e,t,r=void 0,i=!1){this.#e.get(e)?.component.dispatchEvent(t,r,i)}dispatchReRequestParentRoots(){for(let e of this.#t)this.dispatchMessage(e,s.ReRequestParentRoots)}buildChangeTrails(e=!0){let t=[];if(!this.hasComponents())return t;let r=this.#r();for(let i of r)i.buildChangeTrail(t,W.StructuralChanges);for(let i of r)i.buildChangeTrail(t,W.ContentUpdates);for(let i of r)i.buildChangeTrail(t,W.Removal),(i.isDestroyed||i.isNew&&!i.isCreated)&&this.#i(i.uuid),e&&i.clear();return this.#s.write(t),t}reCreateChanges(){if(!this.#s.isEmpty()){this.buildChangeTrails(!1);for(let[e,t]of this.#s){let r=this.#e.get(e);if(r){let i=new ke(e);if(i.create(t.token,t.parentUuid,t.order),t.properties)for(let[n,o]of t.properties)i.changeProperty(n,o,r.propIsEqual?.get(n));r.changes.transferEventsTo(i),r.changes.clear(),r.changes=i}}this.#s.clear(),this.broadcastEvent(gs)}}clear(){if(this.#o=void 0,this.#s.clear(),this.#t.slice(0).forEach(e=>this.removeSubTree(e)),this.#t.length!==0)throw new Error("component-context panic: #rootComponents is not empty!");if(this.#e.size!==0)throw new Error("component-context panic: #components is not empty!")}#i(e){this.#e.has(e)&&(this.#e.delete(e),J(this.#t,e),this.#o=void 0)}#r(){return this.#a().filter(e=>e.changes.hasChanges()).map(e=>e.changes)}#n(e,t){if(t.length===0){t.push(e.uuid);return}if(t.includes(e.uuid))return;let r=t.length,i=new Array(r);if(i[0]=this.#e.get(t[0]).component,e.order<i[0].order){t.unshift(e.uuid);return}if(r===1){t.push(e.uuid);return}let n=r-1;if(i[n]=this.#e.get(t[n]).component,e.order>=i[n].order){t.push(e.uuid);return}if(r===2){t.splice(1,0,e.uuid);return}for(let o=n-1;o>=1;o--)if(i[o]=this.#e.get(t[o]).component,e.order>=i[o].order){t.splice(o+1,0,e.uuid);return}}#o;#a(){if(this.#o)return this.#o;let e=new Map,t=(r,i)=>{let n=this.#e.get(r);if(n!=null){e.has(i)?e.get(i).push(n):e.set(i,[n]);for(let o of n.children)t(o,i+1)}};return this.#t.forEach(r=>t(r,0)),this.#o=Array.from(e.entries()).sort((r,i)=>r[0]-i[0]).map(([,r])=>r).flat(),this.#o}};function Ae(s,e,t,r,i,n){function o(D){if(D!==void 0&&typeof D!="function")throw new TypeError("Function expected");return D}for(var l=r.kind,a=l==="getter"?"get":l==="setter"?"set":"value",f=!e&&s?r.static?s:s.prototype:null,w=e||(f?Object.getOwnPropertyDescriptor(f,r.name):{}),v,u=!1,h=t.length-1;h>=0;h--){var c={};for(var d in r)c[d]=d==="access"?{}:r[d];for(var d in r.access)c.access[d]=r.access[d];c.addInitializer=function(D){if(u)throw new TypeError("Cannot add initializers after decoration has completed");n.push(o(D||null))};var g=(0,t[h])(l==="accessor"?{get:w.get,set:w.set}:w[a],c);if(l==="accessor"){if(g===void 0)continue;if(g===null||typeof g!="object")throw new TypeError("Object expected");(v=o(g.get))&&(w.get=v),(v=o(g.set))&&(w.set=v),(v=o(g.init))&&i.unshift(v)}else(v=o(g))&&(l==="field"?i.unshift(v):w[a]=v)}f&&Object.defineProperty(f,r.name,w),u=!0}function X(s,e,t){for(var r=arguments.length>2,i=0;i<e.length;i++)t=r?e[i].call(s,t):e[i].call(s);return r?t:void 0}function Oe(s){return function(e,t){let r=s?.name||t.name,i=!!(s?.readAsValue??!1);return{get(){let n=_(this,r);if(n)return i?n.value:n.get()},set(n){_(this,r)?.set(n)},init(n){let o=p(n,s);return fs(this,r,o),B.findOrCreate(this).attachSignalByName(r,o),o.value}}}}var j="ConsoleLogger",L=`${j}Storage`,yr=!!(globalThis.location?.host?.startsWith("localhost")??!1),Pe="localStorage"in globalThis,Xe=Symbol.for(j),Ps=!1,Rs=s=>{if(typeof s=="boolean")return s;switch(s.toLowerCase()){case"true":case"yes":case"on":return!0;default:return!1}},It=s=>[Pe?j:void 0,...Array.isArray(s)?s:[s]].filter(Boolean).join(".");function Wt(s,e=void 0,t){let r=It(s),i=Pe?localStorage.getItem(r):globalThis[L]?.[r];return i!=null?e(i):t}function Te(s,e){Pe?localStorage.setItem(It(s),e):(globalThis[L]==null&&(globalThis[L]={},console.debug(`${j}: Initialize`,{[L]:globalThis[L]})),globalThis[L][It(s)]=e)}var T=class s{static{this.sharedConfig={enable:yr,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(){Pe?(["enable","debug","info","warn"].forEach(e=>{this.sharedConfig[e]=Wt(e,Rs,this.sharedConfig[e])}),["debug","info","warn","error"].forEach(e=>{this.sharedStyles[e]=Wt(["styles",e],void 0,this.sharedStyles[e])}),s.isDebug&&console.debug(`${j}: Load config from localStorage`,s.sharedConfig),globalThis[j]?.[Xe]||(globalThis[j]??={[Xe]:!0,get enable(){return s.sharedConfig.enable},set enable(e){s.sharedConfig.enable=e,Te("enable",e?"true":"false")},get debug(){return s.sharedConfig.debug},set debug(e){s.sharedConfig.debug=e,Te("debug",e?"true":"false")},get info(){return s.sharedConfig.info},set info(e){s.sharedConfig.info=e,Te("info",e?"true":"false")},get warn(){return s.sharedConfig.warn},set warn(e){s.sharedConfig.warn=e,Te("warn",e?"true":"false")}})):globalThis[L]?.[Xe]||(globalThis[L]={[Xe]:!0,...s.sharedConfig,...globalThis[L]},s.sharedConfig=globalThis[L],s.isDebug&&console.debug(`${j}: Load config from ${L}`,globalThis[L]))}constructor(e){this.enable=!0,this.namespace=(e||"").trim()||j,Ps||(s.loadConfig(),Ps=!0);let t=[this.namespace,"enable"];this.enable=Wt(t,Rs,this.enable),Te(t,Pe?this.enable?"true":"false":this.enable)}get isEnabled(){return this.enable&&s.sharedConfig.enable}get isDebug(){return this.isEnabled&&s.sharedConfig.debug}get isInfo(){return this.isEnabled&&s.sharedConfig.info}get isWarn(){return this.isEnabled&&s.sharedConfig.warn}debug(...e){this.#e("debug",s.sharedStyles.debug,e)}info(...e){this.#e("info",s.sharedStyles.info,e)}warn(...e){this.#e("warn",s.sharedStyles.warn,e)}error(...e){this.#e("error",s.sharedStyles.error,e)}#e(e,t,r){console[e](`%c${this.namespace}`,t,...r)}};var I=(()=>{var s;let e,t=[],r=[],i,n=[],o=[];return class q{static{let a=typeof Symbol=="function"&&Symbol.metadata?Object.create(null):void 0;e=[Oe()],i=[Oe()],Ae(this,null,e,{kind:"accessor",name:"viewReady",static:!1,private:!1,access:{has:f=>"viewReady"in f,get:f=>f.viewReady,set:(f,w)=>{f.viewReady=w}},metadata:a},t,r),Ae(this,null,i,{kind:"accessor",name:"proxyReady",static:!1,private:!1,access:{has:f=>"proxyReady"in f,get:f=>f.proxyReady,set:(f,w)=>{f.proxyReady=w}},metadata:a},n,o),a&&Object.defineProperty(this,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:a})}static{this.AfterSync="afterSync"}static{this.ContextLost="contextLost"}static{this.ContextCreated="contextCreated"}static get(a){if(a!=null)return globalThis.__shadowEnvs?.get(a)}#e;#t;#s;#i;#r;#n;#o;get viewReady(){return this.#o}set viewReady(a){this.#o=a}#a;get proxyReady(){return this.#a}set proxyReady(a){this.#a=a}#h;get isDestroyed(){return this.#h}constructor(){this.#s=!1,this.#i=!1,this.#r=!1,this.logger=new T("ShadowEnv"),this.ns$=p(),this.#o=X(this,t,!1),this.#a=(X(this,r),X(this,n,!1)),this.#h=(X(this,o),!1),this.ready=async()=>this.isReady?this:le(this,q.ContextCreated),this.#l=()=>{this.#s&&this.#u()},U(this,q.ContextCreated),m(this,q.ContextLost,V.AAA,()=>{Q(this,q.ContextCreated)}),C(()=>{if(this.viewReady&&this.proxyReady)return this.view.reCreateChanges(),y(this,q.ContextCreated,this),this.#i&&(this.#i=!1,this.#u()),()=>{y(this,q.ContextLost,this)}},[_(this,"viewReady"),_(this,"proxyReady")])}get view(){return this.#e}set view(a){a!==this.#e&&(this.#e&&this.#e.ns&&globalThis.__shadowEnvs&&globalThis.__shadowEnvs.delete(this.#e.ns),this.#e=a??void 0,this.#e&&this.#e.ns&&(globalThis.__shadowEnvs??=new Map,globalThis.__shadowEnvs.has(this.#e.ns)&&globalThis.__shadowEnvs.get(this.#e.ns)!==this&&this.logger.isWarn&&this.logger.warn("overwrite a namespace already in use",this.#e.ns,globalThis.__shadowEnvs.get(this.#e.ns)),globalThis.__shadowEnvs.set(this.#e.ns,this)),this.viewReady=!!a)}get envProxy(){return this.#t}set envProxy(a){if(a!==this.#t){let f=this.#t;this.#t=a??void 0,this.#t&&(this.#t.onMessageToView=this.#c.bind(this)),f&&f.destroy(),this.proxyReady=!1,a?.start().then(()=>{this.proxyReady=!0}).catch(w=>{this.logger.error("failed to start envProxy",w),this.proxyReady=!1})}}get isReady(){return!!(this.#e&&this.#t&&this.proxyReady&&!this.isDestroyed)}sync(){if(!this.isReady){this.#i=!0;return}this.#s||(this.#s=!0,queueMicrotask(this.#l))}syncWait(){return this.#r=!0,this.sync(),this.#n?this.#n:(this.#n=le(this,q.AfterSync).then(a=>(this.#n=void 0,a)),this.#n)}destroy(){let a=this.#e?.ns;this.envProxy?.destroy(),this.envProxy=void 0,this.view=void 0,a&&globalThis.__shadowEnvs.has(a)&&globalThis.__shadowEnvs.get(a)===this&&globalThis.__shadowEnvs.delete(a),Se(this),E(this),this.#h=!0,Object.freeze(this)}#l;async#u(){if(this.#s=!1,this.isReady){let a=this.view.buildChangeTrails();if(a.length>0)try{let f=this.#r;this.#r=!1,await this.envProxy.applyChangeTrail(a,f)}catch(f){this.logger.error("failed to apply change trail",f)}finally{y(this,q.AfterSync,a)}}}#c(a){this.logger.isDebug&&this.logger.debug("onMessageToView",a.type,a.data),this.view?.dispatchMessage(a.uuid,a.type,a.data,a.traverseChildren)}}})();var A=["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"],mr=()=>{let s=Math.random()*4294967295|0,e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,r=Math.random()*4294967295|0;return(A[s&255]+A[s>>8&255]+A[s>>16&255]+A[s>>24&255]+"-"+A[e&255]+A[e>>8&255]+"-"+A[e>>16&15|64]+A[e>>24&255]+"-"+A[t&63|128]+A[t>>8&255]+"-"+A[t>>16&255]+A[t>>24&255]+A[r&255]+A[r>>8&255]+A[r>>16&255]+A[r>>24&255]).toLowerCase()},Ms=()=>globalThis?.crypto?.randomUUID?.()??mr();var Re=class extends Error{constructor(e){super(e),this.name="ViewComponentError"}},Ze=class s{#e;#t;#s;#i;#r=0;get uuid(){return this.#e}get token(){return this.#t}set token(e){e??=G,e!==this.#t&&(this.#t=e,this.#s?.changeToken(this,e))}get parent(){return this.#i}set parent(e){if(e){if(e.#s!==this.#s)throw new Re("cannot set parent from different context");e.addChild(this)}else this.removeFromParent()}get context(){return this.#s}set context(e){this.#s!=e&&(this.#s&&this.destroy(),this.#s=e,e&&e.addComponent(this))}get order(){return this.#r}set order(e){let t=this.#r;this.#r=e??0,t!==this.#r&&this.#s.changeOrder(this)}constructor(e,t){x(this),t instanceof s&&(t={parent:t}),this.#e=t?.uuid??Ms(),this.#t=e,this.#r=t?.order??0,this.#i=t?.parent;let r=t?.context??M.get();if(this.#i&&this.#i.#s!==r)throw new Re("cannot set parent from different context");this.context=r}isChildOf(e){return this.#i===e}removeFromParent(){this.#i?(this.#s?.removeFromParent(this.uuid,this.#i),this.#i=void 0):this.#s?.moveToRoot(this.uuid)}addChild(e){if(e.#s!==this.#s)throw new Re("cannot add a child from another context");e.isChildOf(this)||(e.removeFromParent(),e.#i=this,this.#s.addToChildren(this,e))}setProperty(e,t,r){this.#s.setProperty(this,e,t,r)}removeProperty(e){this.#s.removeProperty(this,e)}dispatchShadowObjectsEvent(e,t,r){this.#s.dispatchShadowObjectsEvent(this,e,t,r)}dispatchEvent(e,t,r){if(y(this,e,t),r)for(let i of this.#s.getChildren(this))i.dispatchEvent(e,t,r)}destroy(){this.removeFromParent(),this.#s?.destroyComponent(this),this.#s=void 0}};var et="shaeRequestEntParent",tt="shaeReRequestEntParent",Ls="shae-worker",st="shae-ent",js="shae-prop",Z="token",F="forward-custom-events";var rt="local",Ds="no-autostart",it="no-structured-clone",N="auto-sync";var nt="name",ot="value",at="type",ht="no-trim";var Me=new Set(["on","true","yes","local","1"]);var _s=s=>he(s.getAttribute("ns")),je=(s,e)=>{if(s.hasAttribute(e)){let t=s.getAttribute(e)?.trim()?.toLowerCase()||"1";return Me.has(t)}return!1};var Ns=(s,e)=>{e.set(_s(s))},Ft=new Set,zt=!1,br=s=>{Ft.add(s),zt||(zt=!0,queueMicrotask(()=>{zt=!1;for(let e of Ft)I.get(e)?.sync();Ft.clear()}))},ee=class extends HTMLElement{static{this.observedAttributes=["ns"]}get ns(){return this.ns$.value}set ns(e){typeof e=="symbol"?this.ns$.set(e):this.ns$.set(he(e))}constructor(){super(),this.isShaeElement=!0,this.ns$=p(ae),this.ns$.onChange(e=>{typeof e=="string"&&e.length>0?this.getAttribute("ns")!==e&&this.setAttribute("ns",e):this.removeAttribute("ns")}),Ns(this,this.ns$)}attributeChangedCallback(e){e==="ns"&&Ns(this,this.ns$)}syncShadowObjects(){br(this.ns)}};var lt=class extends ee{static{this.observedAttributes=[...ee.observedAttributes,Z,F]}get componentContext(){return this.componentContext$.value}get viewComponent(){return this.viewComponent$.value}get uuid(){return this.viewComponent?.uuid}get token(){return this.token$.value}set token(e){this.token$.set(e)}#e;constructor(){super(),this.isShaeEntElement=!0,this.componentContext$=p(),this.viewComponent$=p(),this.token$=p(),this.forwardCustomEvents$=p(!1),this.#n=!0,this.#d=()=>{let e=this.findShadowRootHost();e!=null&&this.dispatchEvent(new CustomEvent(tt,{bubbles:!0,composed:!0,detail:{requester:this,shadowRootHost:e}}))},this.#f=e=>{let t=e.detail?.requester;if(t===this||!t?.isShaeEntElement||t.ns!==this.ns)return;e.detail?.shadowRootHost&&this.#l()},this.#g=e=>{let t=e.detail?.requester;t!==this&&t?.isShaeEntElement&&t.ns===this.ns&&(e.stopPropagation(),t.#c(this))},this.ns$.onChange(e=>{this.componentContext$.set(M.get(e)),this.isConnected&&this.#l()}),this.#p(),this.token$.onChange(e=>{e==null?this.removeAttribute(Z):this.getAttribute(Z)!==e&&this.setAttribute(Z,e)}),this.#y(),this.forwardCustomEvents$.onChange(e=>{if(!e)this.removeAttribute(F);else if(e===!0)this.hasAttribute(F)||this.setAttribute(F,"");else{let t=Array.from(e).join(",");this.getAttribute(F)!==t&&this.setAttribute(F,t)}}),C(()=>{let e=this.viewComponent$.get();if(e){let t=m(e,M.ReRequestParentRoots,()=>this.#h()),r=e.context?.ns;return()=>{t(),e.destroy(),r&&r!==this.ns?I.get(r)?.sync():this.syncShadowObjects()}}}),C(()=>{let e=this.viewComponent$.get();if(!e)return;let t=Object.hasOwn(e,"dispatchEvent")?Object.getPrototypeOf(e).dispatchEvent:e.dispatchEvent,r=this.forwardCustomEvents$.get();if(!r)return;let i=r instanceof Set?r:void 0,n=(o,l,a)=>{t.call(e,o,l,a),o!==M.ReRequestParentRoots&&(i&&!i.has(o)||this.dispatchEvent(new CustomEvent(o,{bubbles:!0,composed:!0,detail:l})))};return Object.defineProperty(e,"dispatchEvent",{value:n,writable:!0,configurable:!0}),()=>{Object.hasOwn(e,"dispatchEvent")&&e.dispatchEvent===n&&delete e.dispatchEvent}}),this.token$.onChange(e=>{let t=this.viewComponent$.value;t&&(t.token=e,this.syncShadowObjects())}),this.style.display="contents"}#t;#s(){this.#t?.();let e=this.componentContext$.onChange(t=>{let r=this.token$.value,i=this.viewComponent$.value;i?i.context=t:t&&(i=new Ze(r,{context:t}),this.viewComponent$.set(i)),this.syncShadowObjects()});this.#t=()=>{e()}}#i(){this.#t?.(),this.#t=void 0}#r;#n;findShadowRootHost(){if(this.#n){this.#n=!1;let e=this;for(;e;){if(e.parentElement==null){let t=e.parentNode;t&&(this.#r=t.host);break}e=e.parentElement}}return this.#r}getParentNodeForObserver(){let e=this.parentNode;return e||(e.host??e)}connectedCallback(){this.#n=!0,this.addEventListener("slotchange",this.#d,{capture:!1,passive:!1}),this.addEventListener(et,this.#g,{capture:!1,passive:!1}),this.#s(),qe(()=>this.#p()),qe(()=>this.#y()),this.componentContext==null&&this.componentContext$.set(M.get(this.ns)),this.#l(),this.componentContext?.dispatchReRequestParentRoots(),this.#o(),this.syncShadowObjects()}#o(){this.#a();let e=this.getParentNodeForObserver();e&&(this.#e=new MutationObserver((t,r)=>{for(let{target:i,removedNodes:n}of t)if(i===e){for(let o of n)if(o===this){this.#a(),this.onParentChanged(this.getParentNodeForObserver(),e);break}}}),this.#e.observe(e,{childList:!0,subtree:!1,attributes:!1}))}onParentChanged(e,t){this.#c(void 0),this.#l()}#a(){this.#e?.disconnect(),this.#e=void 0}attributeChangedCallback(e){super.attributeChangedCallback(e),e===Z?this.#p():e===F&&this.#y()}disconnectedCallback(){this.#n=!0,this.#a(),this.removeEventListener("slotchange",this.#d,{capture:!1}),this.removeEventListener(et,this.#g,{capture:!1}),this.#c(void 0),this.componentContext$.set(void 0),this.syncShadowObjects(),this.#i()}#h(){this.isConnected&&(this.#c(void 0),this.#l())}#l(){this.dispatchEvent(new CustomEvent(et,{bubbles:!0,composed:!0,detail:{requester:this}}))}#u;#c(e){if(this.entParentNode!==e)if(this.entParentNode&&this.entParentNode.removeEventListener(tt,this.#f,{capture:!1}),this.entParentNode=e,this.entParentNode&&this.entParentNode.addEventListener(tt,this.#f,{capture:!1,passive:!1}),this.#u?.(),this.#u=void 0,e){let t=C(()=>{let r=this.viewComponent$.get();if(r){let i=e.viewComponent$.get();r.parent=i&&i.context===r.context?i:void 0,r.parent==null&&queueMicrotask(()=>{this.#l()}),this.syncShadowObjects()}});this.#u=()=>t.destroy()}else{let t=this.viewComponent;t.parent&&(t.parent=void 0,this.syncShadowObjects())}}#d;#f;#g;#p(){if(this.hasAttribute(Z)){let e=this.getAttribute(Z)?.trim()||void 0;this.token$.set(e)}}#y(){if(this.hasAttribute(F)){let e=this.getAttribute(F);!e||e.trim().length===0?this.forwardCustomEvents$.set(!0):this.forwardCustomEvents$.set(new Set(e.split(",").map(t=>t.trim()).filter(t=>t.length>0)))}else this.forwardCustomEvents$.set(!1)}};customElements.define(st,lt);var vr=s=>{let e=s.parentElement;for(;e;){if(e.isShaeEntElement)return e;e=e.parentElement}},wr=new Set(["string","text","number","bigint","float","int","integer","hex","hexadecimal","oct","octal","bin","binary","bool","boolean","[]","text[]","string[]","number[]","float[]","int[]","integer[]","hex[]","hexadecimal[]","oct[]","octal[]","bin[]","binary[]","bool[]","boolean[]","int8array","uint8array","uint8clampedarray","int16array","uint16array","int32array","uint32array","float32array","float64array","bigint64array","biguint64array","json"]),ut=class extends HTMLElement{static{this.observedAttributes=[nt,ot,at,ht]}get name(){return this.name$.value}get value(){return this.valueOut$.value}set value(e){this.valueIn$.set(e)}get shouldTrim(){return this.shouldTrim$.value}get entNode(){return this.entNode$.value}set entNode(e){this.entNode$.set(e)}get viewComponent(){return this.viewComponent$.value}constructor(){super(),this.isShaeEntElement=!0,this.entNode$=p(),this.viewComponent$=p(),this.name$=p(),this.valueIn$=p(),this.valueOut$=p(),this.type$=p(),this.shouldTrim$=p(!0),this.logger=new T("ShaePropElement"),this.#e=()=>{this.entNode$.set(vr(this))},this.#t=()=>{queueMicrotask(()=>{this.isConnected||this.entNode$.set(void 0)})},this.#s=()=>{this.name$.set(this.getAttribute(nt)?.trim()??void 0)},this.#i=()=>{this.valueIn$.set(this.getAttribute(ot))},this.#r=()=>{let e=this.getAttribute(at)?.trim().toLowerCase();e&&!wr.has(e)&&(this.logger.isWarn&&this.logger.warn(`[${this.name}] unknown type "${e}"`,{shaeProp:this}),e=void 0),this.type$.set(e)},this.#n=()=>{this.shouldTrim$.set(!je(this,ht))},this.entNode$.onChange(e=>{if(e){let t=R(e.viewComponent$,this.viewComponent$);return()=>{t.destroy()}}else this.viewComponent$.set(void 0)}),C(()=>{let e=this.viewComponent$.get();if(e){let t=this.name$.get();if(t){let r=this.valueOut$.get();this.logger.isDebug&&this.logger.debug(`[${this.name}] view-component set-property`,t,r,e.uuid,{viewComponent:e,shaeProp:this}),e.setProperty(t,r),this.isConnected&&this.entNode?.syncShadowObjects()}}}),C(()=>{let e=this.type$.get(),t=this.shouldTrim$.get(),r=this.valueIn$.get();if(t&&typeof r=="string"&&(r=r.trim()),r=r||void 0,r!=null&&typeof r=="string"&&e)switch(e){case"string":case"text":break;case"number":r=Number(r);break;case"bigint":r=BigInt(r);break;case"float":r=parseFloat(r);break;case"int":case"integer":r=parseInt(r,10);break;case"hex":case"hexadecimal":r=parseInt(r,16);break;case"oct":case"octal":r=parseInt(r,8);break;case"bin":case"binary":r=parseInt(r,2);break;case"bool":case"boolean":r=Me.has(r.toLowerCase());break;case"[]":case"text[]":case"string[]":r=r.split(/\W+/);break;case"number[]":r=r.split(/\s+/).map(i=>Number(i));break;case"float[]":r=r.split(/\s+/).map(i=>parseFloat(i));break;case"int[]":case"integer[]":r=r.split(/\s+/).map(i=>parseInt(i));break;case"hex[]":case"hexadecimal[]":r=r.split(/\W+/).map(i=>parseInt(i,16));break;case"oct[]":case"octal[]":r=r.split(/\W+/).map(i=>parseInt(i,8));break;case"bin[]":case"binary[]":r=r.split(/\W+/).map(i=>parseInt(i,2));break;case"bool[]":case"boolean[]":r=r.split(/\W+/).map(i=>Me.has(i.toLowerCase()));break;case"int8array":r=new Int8Array(r.split(/\W+/).map(i=>Number(i)));break;case"uint8array":r=new Uint8Array(r.split(/\W+/).map(i=>Number(i)));break;case"uint8clampedarray":r=new Uint8ClampedArray(r.split(/\W+/).map(i=>Number(i)));break;case"int16array":r=new Int16Array(r.split(/\W+/).map(i=>Number(i)));break;case"uint16array":r=new Uint16Array(r.split(/\W+/).map(i=>Number(i)));break;case"int32array":r=new Int32Array(r.split(/\W+/).map(i=>Number(i)));break;case"uint32array":r=new Uint32Array(r.split(/\W+/).map(i=>Number(i)));break;case"float32array":r=new Float32Array(r.split(/\s+/).map(i=>Number(i)));break;case"float64array":r=new Float64Array(r.split(/\s+/).map(i=>Number(i)));break;case"bigint64array":r=new BigInt64Array(r.split(/\W+/).map(i=>BigInt(i)));break;case"biguint64array":r=new BigUint64Array(r.split(/\W+/).map(i=>BigInt(i)));break;case"json":r=JSON.parse(r);break;default:this.logger.isWarn&&this.logger.warn(`[${this.name}] unknown type "${e}"`,{value:r,shaeProp:this})}this.valueOut$.set(r)}),P(()=>{this.#s(),this.#i(),this.#r(),this.#n()}),this.style.display="contents"}connectedCallback(){P(()=>{this.#e(),this.#s(),this.#i(),this.#r(),this.#n()})}attributeChangedCallback(e){switch(e){case nt:this.#s();break;case ot:this.#i();break;case at:this.#r();break;case ht:this.#n();break}}disconnectedCallback(){this.#t()}#e;#t;#s;#i;#r;#n};customElements.whenDefined(st).then(()=>customElements.define(js,ut));var ct,Vt=null,ge=class{static{this.OnFrame=Symbol("onFrame")}#e=0;#t=0;constructor(){if(Vt)return Vt;x(this),Vt=this}start(e){if(e!=null)return At(this)===0&&this.#i(),m(this,ct.OnFrame,e),this.#t++,()=>{this.stop(e)}}stop(e){E(this,ct.OnFrame,e),At(this)===0&&this.#r()}#s=e=>{y(this,ct.OnFrame,e),this.#i()};#i(){this.#e=requestAnimationFrame(this.#s)}#r(){cancelAnimationFrame(this.#e),this.#e=0}};ct=ge;var dt=s=>s??void 0;var ye="value",De=(()=>{let s,e=[],t=[];return class{static{let i=typeof Symbol=="function"&&Symbol.metadata?Object.create(null):void 0;s=[Oe({name:ye})],Ae(this,null,s,{kind:"accessor",name:"value",static:!1,private:!1,access:{has:n=>"value"in n,get:n=>n.value,set:(n,o)=>{n.value=o}},metadata:i},e,t),i&&Object.defineProperty(this,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:i})}static{this.Value=ye}#e;#t;#s;get value(){return this.#s}set value(i){this.#s=i}constructor(i){this.#e=[],this.#s=X(this,e,void 0),this.value$=X(this,t),U(this,ye),this.value$=_(this,ye),this.value$.onChange(n=>y(this,ye,n)),i&&this.add(...i)}add(...i){return this.#e.push(...i),this.#r(),this.#i(i)}unshift(...i){return this.#e.unshift(...i),this.#r(),this.#i(i)}remove(...i){this.#i(i)()}clear(){this.#e.length=0,this.#r()}dispose(){this.clear(),this.#t?.destroy(),this.#t=void 0,Q(this,ye),E(this),this.value$.destroy(),Se(this)}#i(i){return()=>{for(let n of i){let o=this.#e.indexOf(n);o!==-1&&this.#e.splice(o,1)}this.#r()}}#r(){this.#t?.destroy(),this.#e.length===0?(this.#t=void 0,this.value=void 0):(this.#t=C(()=>{let i;for(let n of this.#e){let o=fe(n);if(o!=null){i=o;break}}this.value=i},this.#e),this.#t.run())}}})();var Ut=Symbol("onCreate"),H=Symbol("onDestroy"),$s=Symbol("onParentChanged"),ft=Symbol("onViewEvent");var Bt=new Map,Gt=!1,Cr=(s,e)=>{Bt.set(s,e),Gt||(Gt=!0,queueMicrotask(()=>{Gt=!1;let t=Array.from(Bt.entries());Bt.clear();for(let[r,i]of t)r.set(i)}))},pt=class{#e;#t;#s=new Ye;#i=new Map;#r=new Map;#n;#o;#a=new Set;#h=[];#l=0;get kernel(){return this.#e}get uuid(){return this.#t}get order(){return this.#l}set order(e){this.#l!==e&&(this.#l=e,this.#n&&this.parent.resortChildren())}get parentUuid(){return this.#n||void 0}set parentUuid(e){this.#n!==e&&(this.removeFromParent(),this.#n=e||void 0,this.#o=e?this.#e.getEntity(e):void 0,this.#o&&this.#o.addChild(this))}get parent(){return!this.#o&&this.#n&&(this.#o=this.#e.getEntity(this.#n)),this.#o}set parent(e){this.parentUuid=e?.uuid}get hasParent(){return!!this.#n}get children(){return this.#h}constructor(e,t){this.#e=e,this.#t=t,S(this,H,V.Min,this)}traverse(e){e(this);for(let t of this.#h)t.traverse(e)}[H](){this.#s.clear(),E(this);for(let e of this.#r.values())e.cleanup(),e.signal.destroy();this.#r.clear();for(let e of this.#i.values())e.context.set(void 0),e.unsubscribePathValue(),e.unsubscribeFromParent?.(),e.valuePath.dispose(),e.inherited.destroy(),e.provide.destroy(),e.context.destroy();this.#n=void 0,this.#o=void 0,this.#a.clear(),this.#h.length=0}addChild(e){if(this.#h.length===0){this.#a.add(e.uuid),this.#h.push(e);return}if(this.#a.has(e.uuid))throw new Error(`child with uuid: ${e.uuid} already exists! parentUuid: ${this.uuid}`);this.#a.add(e.uuid),this.#h.push(e),this.resortChildren();for(let[,t]of e.#i)e.#f(t)}resortChildren(){this.#h.sort((e,t)=>e.order-t.order)}removeChild(e){this.#a.has(e.uuid)&&(this.#a.delete(e.uuid),this.#h.splice(this.#h.indexOf(e),1))}removeFromParent(){if(this.#o){this.#o.removeChild(this),this.#o=void 0,this.#n=void 0;for(let[,e]of this.#i)e.unsubscribeFromParent&&(e.unsubscribeFromParent(),e.unsubscribeFromParent=void 0)}}reSubscribeToParentContexts(){for(let[,e]of this.#i)this.#f(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)y(this,ft,t,r)}dispatchViewEvent(e,t){this.dispatchViewEvents([{type:e,data:t}])}#u(e){return this.#s.get(e)}getPropertyReader(e){return this.#u(e).get}getPropertyWriter(e){return this.#u(e).set}setProperties(e){this.clearTruthyPropsCache(),P(()=>{for(let[t,r]of e)this.setProperty(t,r)})}setProperty(e,t){this.getPropertyWriter(e)(t)}getProperty(e){return fe(this.getPropertyReader(e))}propKeys(){return Array.from(this.#s.keys())}propEntries(){return Array.from(this.#s.entries()).map(([e,t])=>[e,t.value])}#c;clearTruthyPropsCache(){this.#c=void 0}truthyProps(){if(this.#c)return this.#c.size?this.#c: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.#c=e,e.size?e:void 0}hasContext(e){return this.#i.has(e)}useContext(e){return this.#d(e).context.get}useParentContext(e){return this.#d(e).inherited.get}provideContext(e){return this.#d(e).provide}provideGlobalContext(e){if(this.#r.has(e))return this.#r.get(e).signal;let t=this.#e.findOrCreateRootContext(e),r=p(),i=t.add(r);return this.#r.set(e,{cleanup:i,signal:r}),r}#d(e){if(this.#i.has(e))return this.#i.get(e);let t=p(),r=p(),i=p(),n=new De([r,t]),o=m(n,De.Value,a=>{Cr(i,a)}),l={name:e,inherited:t,provide:r,context:i,valuePath:n,unsubscribePathValue:o};return this.#i.set(e,l),this.#f(l),l}#f(e){if(e.unsubscribeFromParent?.(),e.unsubscribeFromParent=void 0,this.parent){let t=this.parent.#d(e.name),r=R(t.context,e.inherited);e.unsubscribeFromParent=r.destroy.bind(r)}else{let t=this.#e.findOrCreateRootContext(e.name),r=R(t.value$,e.inherited);e.unsubscribeFromParent=r.destroy.bind(r)}}};var Ws=s=>{let e=s.split("@").map(t=>t.trim());if(e.length===2&&e[1])return e[0]?{key:`${e[0]}@${e[1]}`,prop:e[1],token:e[0]}:{key:e[1],prop:e[1]}},gt=(s,e)=>{for(let t of e)s.add(t)},Er=(s,e)=>{if(s!=null)for(let t of s.constructors)e.add(t)},_e=class{static get(e){return e??Sr}#e=new Map;#t=new Map;#s=new Map;define(e,t){this.#e.has(e)?Os(this.#e.get(e).constructors,t):this.#e.set(e,{token:e,constructors:[t]})}appendRoute(e,t){let r=Ws(e);r?this.#s.has(r.key)?gt(this.#s.get(r.key).routes,t):this.#s.set(r.key,{routes:new Set(t),token:r.token}):this.#t.has(e)?gt(this.#t.get(e),t):this.#t.set(e,new Set(t))}clearRoute(e){let t=Ws(e);t?this.#s.delete(t.key):this.#t.delete(e)}findTokensByRoute(e,t){let r=new Set([e]),i=this.#t.has(e)?[...this.#t.get(e)]:[];for(;i.length;){let n=i.shift();r.has(n)||(r.add(n),this.#t.has(n)&&i.push(...Array.from(this.#t.get(n)).filter(o=>!r.has(o))))}if(t){for(let o of t)this.#s.has(o)&&gt(r,this.#s.get(o).routes);let n;do{n=r.size;for(let o of new Set(r))for(let l of t){let a=`${o}@${l}`;this.#s.has(a)&&gt(r,this.#s.get(a).routes)}}while(n!==r.size)}return r}findConstructors(e,t){let r=this.findTokensByRoute(e,t),i=new Set;for(let n of r)Er(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()}},Sr=new _e;var K;(function(s){s[s.CreateAndDestroy=0]="CreateAndDestroy",s[s.JustCreate=1]="JustCreate",s[s.DestroyOnly=2]="DestroyOnly"})(K||(K={}));var Is=s=>s.displayName||s.name,Fs=!1,zs=!1,Vs=!1,Us=!1,Bs=!1,yt=class{#e;#t;#s;#i;#r;#n;constructor(e){this.logger=new T("Kernel"),this.#e=new Map,this.#t=new Set,this.#r=!0,this.#n=new Map,x(this),this.registry=_e.get(e)}getEntity(e){let t=this.#e.get(e)?.entity;if(!t)throw new Error(`entity with uuid "${e}" not found!`);return t}hasEntity(e){return this.#e.has(e)}traverseLevelOrderBFS(e=!1){if(this.#r){let t=new Map,r=(i,n)=>{let o=this.getEntity(i);t.has(n)?t.get(n).push(o):t.set(n,[o]);for(let l of o.children)r(l.uuid,n+1)};this.#t.forEach(i=>{r(i,0)}),this.#s=Array.from(t.entries()).sort((i,n)=>i[0]-n[0]).flatMap(([,i])=>i),this.#i=this.#s.slice().reverse(),this.#r=!1}return e?this.#i:this.#s}getEntityGraph(){return Array.from(this.#t).map(e=>this.getEntityGraphNode(e))}getEntityGraphNode(e){if(!this.#e.has(e))return;let{token:t,entity:r}=this.#e.get(e);return{token:t,entity:r,props:Object.fromEntries(r.propEntries()),children:r.children.map(i=>this.getEntityGraphNode(i.uuid))}}upgradeEntities(){let e=new Map;for(let t of this.traverseLevelOrderBFS(!0))e.set(t.uuid,this.updateShadowObjects(t.uuid,K.DestroyOnly));for(let t of this.traverseLevelOrderBFS(!1))this.updateShadowObjects(t.uuid,K.JustCreate,e.get(t.uuid));e.clear()}run(e){this.logger.isDebug&&this.logger.debug("sync",e),P(()=>{for(let t of e.changeTrail)this.parse(t)})}parse(e){switch(e.type){case b.CreateEntities:this.createEntity(e.uuid,e.token,e.parentUuid,e.order,e.properties),this.#r=!0;break;case b.DestroyEntities:this.destroyEntity(e.uuid),this.#r=!0;break;case b.SetParent:this.setParent(e.uuid,e.parentUuid,e.order),this.#r=!0;break;case b.UpdateOrder:this.updateOrder(e.uuid,e.order),this.#r=!0;break;case b.ChangeProperties:this.changeProperties(e.uuid,e.properties);break;case b.ChangeToken:this.changeToken(e.uuid,e.token);break;case b.SendEvents:this.dispatchEventsToEntity(e.uuid,e.events);break}}createEntity(e,t,r,i=0,n){let o=new pt(this,e);o.order=i;let l={token:t,entity:o,usedConstructors:new Map};this.#e.set(e,l),r&&(o.parentUuid=r),o.hasParent||this.#t.add(e),n&&o.setProperties(n),this.createShadowObjects(e)}destroyEntity(e){if(!this.#e.has(e))return;let{entity:t,usedConstructors:r}=this.#e.get(e);t.removeFromParent(),y(t,H,t),r.clear(),this.#e.delete(t.uuid),this.#t.delete(t.uuid)}setParent(e,t,r=0){let i=this.getEntity(e);i.parentUuid===t&&i.order===r||(i.removeFromParent(),i.order=r,i.parentUuid=t,i.hasParent?this.#t.delete(e):this.#t.add(e),i.reSubscribeToParentContexts(),queueMicrotask(()=>{this.logger.isDebug&&this.logger.debug("entity.onParentChanged",{uuid:e,parentUuid:t,order:r,entity:i}),y(i,$s,i)}))}updateOrder(e,t){this.getEntity(e).order=t}dispatchEventsToEntity(e,t){this.getEntity(e)?.dispatchViewEvents(t)}changeProperties(e,t){this.getEntity(e).setProperties(t),this.updateShadowObjects(e)}changeToken(e,t){if(!this.#e.has(e))return;let r=this.#e.get(e);r.token!==t&&(r.token=t,this.updateShadowObjects(e))}dispatchMessageToView(e){queueMicrotask(()=>{y(this,pe,e)})}updateShadowObjects(e,t=K.CreateAndDestroy,r){let i=this.#e.get(e);r??=new Set(this.registry.findConstructors(i.token,i.entity.truthyProps()));let n=t===K.CreateAndDestroy||t===K.DestroyOnly,o=t===K.CreateAndDestroy||t===K.JustCreate;if(n){for(let[l,a]of i.usedConstructors)if(!r.has(l)){i.usedConstructors.delete(l);for(let f of a)this.destroyShadowObject(f,i.entity)}}if(o)for(let l of r)i.usedConstructors.has(l)||this.constructShadowObject(l,i);return r}constructShadowObject(e,t){let r=new Set,i=new Set,n=new Map,o=new Map,l=new Map,a=new Map,f=new Map,w=(u,h)=>{!Bs&&h!=null&&typeof h=="function"&&(console.warn('[shadow-objects] Deprecation Warning: The "isEqual" option of "useProperty()" is now passed as {compare} argument. Please update your code accordingly.'),Bs=!0);let c=typeof h=="function"?{compare:h}:h,d=f.get(u);if(d===void 0){d=p(void 0,c).get,f.set(u,d);let g=R(t.entity.getPropertyReader(u),d);i.add(g.destroy.bind(g))}return d},v=x(new e({entity:t.entity,provideContext(u,h,c){!Fs&&c!=null&&typeof c=="function"&&(console.warn('[shadow-objects] Deprecation Warning: The "isEqual" option of "provideContext()" is now passed as {compare} argument. Please update your code accordingly.'),Fs=!0);let d=typeof c=="function"?{compare:c}:c,g=l.get(u);if(g==null){let D=oe(h),wt=D?void 0:dt(h);if(g=p(wt,d?.compare?{compare:d.compare}:void 0),D){let be=R(h,g);i.add(be.destroy.bind(be))}let me=R(g,t.entity.provideContext(u));i.add(me.destroy.bind(me)),l.set(u,g)}return g!=null&&(d?.clearOnDestroy??!0)&&i.add(()=>{g.set(void 0)}),g},provideGlobalContext(u,h,c){!zs&&c!=null&&typeof c=="function"&&(console.warn('[shadow-objects] Deprecation Warning: The "isEqual" option of "provideGlobalContext()" is now passed as {compare} argument. Please update your code accordingly.'),zs=!0);let d=typeof c=="function"?{compare:c}:c,g=a.get(u);if(g==null){let D=oe(h),wt=D?void 0:dt(h);if(g=p(wt,d?.compare?{compare:d.compare}:void 0),D){let be=R(h,g);i.add(be.destroy.bind(be))}let me=R(g,t.entity.provideGlobalContext(u));i.add(me.destroy.bind(me)),a.set(u,g)}return g!=null&&(d?.clearOnDestroy??!0)&&i.add(()=>{g.set(void 0)}),g},useContext(u,h){!Vs&&h!=null&&typeof h=="function"&&(console.warn('[shadow-objects] Deprecation Warning: The "isEqual" option of "useContext()" is now passed as {compare} argument. Please update your code accordingly.'),Vs=!0);let c=typeof h=="function"?{compare:h}:h,d=n.get(u);if(d===void 0){d=p(void 0,c).get,n.set(u,d);let g=R(t.entity.useContext(u),d);i.add(g.destroy.bind(g))}return d},useParentContext(u,h){!Us&&h!=null&&typeof h=="function"&&(console.warn('[shadow-objects] Deprecation Warning: The "isEqual" option of "useParentContext()" is now passed as {compare} argument. Please update your code accordingly.'),Us=!0);let c=typeof h=="function"?{compare:h}:h,d=o.get(u);if(d===void 0){d=p(void 0,c).get,o.set(u,d);let g=R(t.entity.useParentContext(u),d);i.add(g.destroy.bind(g))}return d},dispatchMessageToView(u,h,c,d=!1){t.entity.dispatchMessageToView(u,h,c,d)},useProperty:w,useProperties(u){let h={};for(let c in u)Object.hasOwn(u,c)&&(h[c]=w(u[c]));return h},createResource(u,h){let c=p(),d=C(()=>{let g=dt(u());return c.set(g),g!==void 0&&h?()=>{h(g),c.set(void 0)}:()=>{c.set(void 0)}});return i.add(()=>{d.destroy(),c.set(void 0),O(c)}),c},createEffect(...u){let h=C(...u);return i.add(h.destroy),h},createSignal(...u){let h=p(...u);return i.add(()=>{O(h)}),h},createMemo(...u){let h=He(...u);return i.add(()=>{O(h)}),h},on(...u){let[h]=u;if(typeof h=="string"||typeof h=="symbol"||Array.isArray(h)){let d=m(t.entity,...u);return i.add(d),d}let c=m(...u);return i.add(c),Object.assign(()=>{i.delete(c),c()},c)},once(...u){let[h]=u;if(typeof h=="string"||typeof h=="symbol"||Array.isArray(h)){let d=S(t.entity,...u);return i.add(d),d}let c=S(...u);return i.add(c),Object.assign(()=>{i.delete(c),c()},c)},emit(...u){let[h]=u;typeof h=="string"||typeof h=="symbol"||Array.isArray(h)?y(t.entity,...u):y(...u)},onViewEvent(u){let h=m(t.entity,ft,(c,d)=>{u(c,d)});i.add(h)},onDestroy(u){r.add(u)}}));return this.logger.isInfo&&this.logger.info("create shadow-object",Is(e),{shadowObject:v,entity:t.entity}),S(t.entity,H,V.Low,()=>{this.logger.isInfo&&this.logger.info("destroy shadow-object",Is(e),{shadowObject:v,entity:t.entity});for(let h of r)h();for(let h of i)h();for(let h of n.values())O(h);for(let h of o.values())O(h);for(let h of f.values())O(h);for(let h of l.values())O(h);for(let h of a.values())O(h);r.clear(),i.clear(),n.clear(),o.clear(),f.clear(),l.clear(),a.clear();let u=t.usedConstructors.get(e);u&&(u.delete(v),u.size===0&&t.usedConstructors.delete(e))}),t.usedConstructors.has(e)?t.usedConstructors.get(e).add(v):t.usedConstructors.set(e,new Set([v])),this.attachShadowObject(v,t.entity),v}createShadowObjects(e){let t=this.#e.get(e);this.registry.findConstructors(t.token,t.entity.truthyProps())?.forEach(r=>{this.constructShadowObject(r,t)})}findShadowObjects(e){if(!this.#e.has(e))return[];let{usedConstructors:t}=this.#e.get(e);return Array.from(new Set(Array.from(t.values()).flatMap(r=>Array.from(r))))}attachShadowObject(e,t){m(t,e),typeof e[Ut]=="function"&&e[Ut](t)}destroyShadowObject(e,t){typeof e[H]=="function"&&e[H](t),y(e,H,t),E(t,e)}findOrCreateRootContext(e){let t=this.#n.get(e);return t||(t=new De,this.#n.set(e,t)),t}destroy(){for(let e of this.#n.values())e.dispose();this.#n.clear();for(let e of this.traverseLevelOrderBFS().reverse())this.destroyEntity(e.uuid)}};async function qt(s,e,t,r=!0){if(t.has(e)){console.warn("importModule: skipping already imported module",e);return}else t.add(e);e.extends&&await Promise.all(e.extends.map(n=>qt(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 mt=s=>(typeof s=="string"&&(s=new URL(s,globalThis.location.href)),s.toString());function Gs(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 bt=class{#e;get registry(){return this.kernel.registry}constructor(e){this.#e=new Set,this.isLocalEnv=!0,this.disableStructuredClone=!1,this.kernel=new yt(e),m(this.kernel,pe,t=>{if(this.onMessageToView!=null){let{type:r,uuid:i,traverseChildren:n}=t,o=structuredClone(t.data,{transfer:t.transferables});this.onMessageToView({type:r,uuid:i,data:o,traverseChildren:n})}})}start(){return Promise.resolve()}applyChangeTrail(e,t){let r={changeTrail:this.disableStructuredClone?e:Gs(e)},i;try{this.kernel.run(r),i=Promise.resolve()}catch(n){i=Promise.reject(n)}return i}async importScript(e){let t=await import(mt(e));t[_t]&&await this.importModule(t[_t])}async importModule(e){return qt(this.kernel,e,this.#e)}destroy(){this.kernel.destroy(),this.registry.clear(),this.#e.clear()}};function Ht(s){let e=new Blob([s],{type:"text/javascript"}),t=URL.createObjectURL(e),r=new Worker(t);return URL.revokeObjectURL(t),r}function Kt(){return Ht(`var Ys=Object.defineProperty;var oe=Object.getOwnPropertySymbols;var Be=Object.prototype.hasOwnProperty,We=Object.prototype.propertyIsEnumerable;var Xs=(e,t)=>(t=Symbol[e])?t:Symbol.for("Symbol."+e),qe=e=>{throw TypeError(e)};var me=(e,t,s)=>t in e?Ys(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,we=(e,t)=>{for(var s in t||(t={}))Be.call(t,s)&&me(e,s,t[s]);if(oe)for(var s of oe(t))We.call(t,s)&&me(e,s,t[s]);return e};var Je=(e,t)=>{var s={};for(var i in e)Be.call(e,i)&&t.indexOf(i)<0&&(s[i]=e[i]);if(e!=null&&oe)for(var i of oe(e))t.indexOf(i)<0&&We.call(e,i)&&(s[i]=e[i]);return s};var p=(e,t,s)=>me(e,typeof t!="symbol"?t+"":t,s),Ce=(e,t,s)=>t.has(e)||qe("Cannot "+s);var r=(e,t,s)=>(Ce(e,t,"read from private field"),s?s.call(e):t.get(e)),g=(e,t,s)=>t.has(e)?qe("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,s),f=(e,t,s,i)=>(Ce(e,t,"write to private field"),i?i.call(e,s):t.set(e,s),s),C=(e,t,s)=>(Ce(e,t,"access private method"),s);var Ke=(e,t,s,i)=>({set _(n){f(e,t,n,s)},get _(){return r(e,t,i)}});var Ee=function(e,t){this[0]=e,this[1]=t},Ye=(e,t,s)=>{var i=(a,d,y,m)=>{try{var w=s[a](d),h=(d=w.value)instanceof Ee,l=w.done;Promise.resolve(h?d[0]:d).then(u=>h?i(a==="return"?a:"next",d[1]?{done:u.done,value:u.value}:u,y,m):y({value:u,done:l})).catch(u=>i("throw",u,y,m))}catch(u){m(u)}},n=a=>o[a]=d=>new Promise((y,m)=>i(a,d,y,m)),o={};return s=s.apply(e,t),o[Xs("asyncIterator")]=()=>o,n("next"),n("throw"),n("return"),o};var Xe;(function(e){e[e.StructuralChanges=1]="StructuralChanges",e[e.ContentUpdates=2]="ContentUpdates",e[e.Removal=3]="Removal"})(Xe||(Xe={}));var tt;(function(e){e[e.CreateEntities=1]="CreateEntities",e[e.DestroyEntities=2]="DestroyEntities",e[e.SetParent=3]="SetParent",e[e.UpdateOrder=4]="UpdateOrder",e[e.ChangeProperties=5]="ChangeProperties",e[e.ChangeToken=6]="ChangeToken",e[e.SendEvents=7]="SendEvents"})(tt||(tt={}));var Zs="configure",Hs="changeTrail",Qs="destroy",_s="loaded",Ze="appliedChangeTrail",Se="importedModule",ti="destroyed",De="messageToView",ke="shadowObjects",N="ConsoleLogger",R=\`\${N}Storage\`,ys,bs,vs,ei=!!((vs=(bs=(ys=globalThis.location)==null?void 0:ys.host)==null?void 0:bs.startsWith("localhost"))!=null&&vs),Zt="localStorage"in globalThis,he=Symbol.for(N),He=!1,Qe=e=>{if(typeof e=="boolean")return e;switch(e.toLowerCase()){case"true":case"yes":case"on":return!0;default:return!1}},xe=e=>[Zt?N:void 0,...Array.isArray(e)?e:[e]].filter(Boolean).join(".");function Ae(e,t=void 0,s){var o;let i=xe(e),n=Zt?localStorage.getItem(i):(o=globalThis[R])==null?void 0:o[i];return n!=null?t(n):s}function Ut(e,t){Zt?localStorage.setItem(xe(e),t):(globalThis[R]==null&&(globalThis[R]={},console.debug(\`\${N}: Initialize\`,{[R]:globalThis[R]})),globalThis[R][xe(e)]=t)}var wt,Wt,b,si=(b=class{constructor(t){g(this,wt);this.enable=!0,this.namespace=(t||"").trim()||N,He||(b.loadConfig(),He=!0);let s=[this.namespace,"enable"];this.enable=Ae(s,Qe,this.enable),Ut(s,Zt?this.enable?"true":"false":this.enable)}static get isEnabled(){return b.sharedConfig.enable}static get isDebug(){return b.sharedConfig.enable&&b.sharedConfig.debug}static loadConfig(){var t,s,i;Zt?(["enable","debug","info","warn"].forEach(n=>{this.sharedConfig[n]=Ae(n,Qe,this.sharedConfig[n])}),["debug","info","warn","error"].forEach(n=>{this.sharedStyles[n]=Ae(["styles",n],void 0,this.sharedStyles[n])}),b.isDebug&&console.debug(\`\${N}: Load config from localStorage\`,b.sharedConfig),(t=globalThis[N])!=null&&t[he]||((s=globalThis[N])!=null||(globalThis[N]={[he]:!0,get enable(){return b.sharedConfig.enable},set enable(n){b.sharedConfig.enable=n,Ut("enable",n?"true":"false")},get debug(){return b.sharedConfig.debug},set debug(n){b.sharedConfig.debug=n,Ut("debug",n?"true":"false")},get info(){return b.sharedConfig.info},set info(n){b.sharedConfig.info=n,Ut("info",n?"true":"false")},get warn(){return b.sharedConfig.warn},set warn(n){b.sharedConfig.warn=n,Ut("warn",n?"true":"false")}}))):(i=globalThis[R])!=null&&i[he]||(globalThis[R]=we(we({[he]:!0},b.sharedConfig),globalThis[R]),b.sharedConfig=globalThis[R],b.isDebug&&console.debug(\`\${N}: Load config from \${R}\`,globalThis[R]))}get isEnabled(){return this.enable&&b.sharedConfig.enable}get isDebug(){return this.isEnabled&&b.sharedConfig.debug}get isInfo(){return this.isEnabled&&b.sharedConfig.info}get isWarn(){return this.isEnabled&&b.sharedConfig.warn}debug(...t){C(this,wt,Wt).call(this,"debug",b.sharedStyles.debug,t)}info(...t){C(this,wt,Wt).call(this,"info",b.sharedStyles.info,t)}warn(...t){C(this,wt,Wt).call(this,"warn",b.sharedStyles.warn,t)}error(...t){C(this,wt,Wt).call(this,"error",b.sharedStyles.error,t)}},wt=new WeakSet,Wt=function(t,s,i){console[t](\`%c\${this.namespace}\`,s,...i)},b.sharedConfig={enable:ei,debug:!1,info:!0,warn:!0,"styles.debug":"color: #111; background: #999; display: inline-block; padding: 0 0.25em; margin: 0; border-radius: 0.25em","styles.info":"color: #020; background: #8a8; display: inline-block; padding: 0 0.25em; margin: 0; border-radius: 0.25em","styles.warn":"color: #fa0; background: #a98; display: inline-block; padding: 0 0.25em; margin: 0; border-radius: 0.25em","styles.error":"color: #ff0; background: #a00; display: inline-block; padding: 0 0.25em; margin: 0; border-radius: 0.25em"},b.sharedStyles={get debug(){return b.sharedConfig["styles.debug"]},set debug(t){b.sharedConfig["styles.debug"]=t},get info(){return b.sharedConfig["styles.info"]},set info(t){b.sharedConfig["styles.info"]=t},get warn(){return b.sharedConfig["styles.warn"]},set warn(t){b.sharedConfig["styles.warn"]=t},get error(){return b.sharedConfig["styles.error"]},set error(t){b.sharedConfig["styles.error"]=t}},b),jt="*",Os=1,$e=2,Ie=4,bt=Symbol.for("eventize"),ii="[eventize]",pe=e=>e===jt,js=e=>{switch(typeof e){case"string":case"symbol":return!0;default:return!1}},Ms=typeof console<"u",ri=Ms?console[console.warn?"warn":"log"].bind(console,ii):()=>{},ni=(e,t,s)=>(Object.defineProperty(e,t,{value:s,configurable:!0}),e),ai=0,Ts=class{constructor(){p(this,"events",new Map);p(this,"eventNames",new Set)}static publish(e){e.sort((t,s)=>t.order-s.order).forEach(t=>t.emit())}add(e){Array.isArray(e)?e.forEach(t=>this.eventNames.add(t)):this.eventNames.add(e)}remove(e){Array.isArray(e)?e.forEach(t=>this.eventNames.delete(t)):this.eventNames.delete(e),this.clear(e)}clear(e){Array.isArray(e)?e.forEach(t=>this.events.delete(t)):this.events.delete(e)}retain(e,t){this.eventNames.has(e)&&this.events.set(e,{args:t,order:ai++})}isKnown(e){return this.eventNames.has(e)}emit(e,t,s=[]){if(pe(e))this.eventNames.forEach(i=>this.emit(i,t,s));else if(this.events.has(e)){let{order:i,args:n}=this.events.get(e);s.push({order:i,emit:()=>t.apply(e,n)})}return s}},Le=(e,t,s,i)=>{if(typeof t=="function"){let n=t.apply(e,s);n!=null&&(i==null||i(n))}},oi=(e,t,s,i)=>Le(t,t.emit,[e].concat(s),i),hi=e=>{switch(typeof e){case"function":return Os;case"string":case"symbol":return $e;case"object":return Ie}},li=0,di=()=>++li,Ds=class{constructor(e,t,s,i=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");this.id=di(),this.eventName=e,this.isCatchEmAll=pe(e),this.listener=s,this.listenerObject=i,this.priority=t,this.listenerType=hi(s),this.callAfterApply=void 0,this.isRemoved=!1,this.refCount=1}isEqual(e,t=null){if(e===this)return!0;let s=typeof e;return s==="number"&&e===this.id?!0:t===null&&(s==="string"||s==="symbol")?e===jt||e===this.eventName:this.listener===e&&this.listenerObject===t}apply(e,t,s){if(this.isRemoved)return;let{listener:i,listenerObject:n}=this;switch(this.listenerType){case Os:Le(n,i,t,s),this.callAfterApply&&this.callAfterApply();break;case $e:Le(n,n[i],t,s),this.callAfterApply&&this.callAfterApply();break;case Ie:{let o=i[e];if(this.isCatchEmAll||this.eventName===e){if(typeof o=="function"){let a=o.apply(i,t);a!=null&&(s==null||s(a))}else oi(e,i,t,s);this.callAfterApply&&this.callAfterApply()}break}}}},ui=(e,t)=>e.priority!==t.priority?t.priority-e.priority:e.id-t.id,_e=e=>e==null?void 0:e.slice(0),ts=(e,t)=>{let s=e.indexOf(t);s>-1&&e.splice(s,1)},ci=e=>e===Ie||e===$e,Re=(e,t,s)=>{let i=e.findIndex(n=>n.isEqual(t,s));i>-1&&(e[i].isRemoved=!0,e.splice(i,1))},le=(e,t,s)=>{let i=[];for(let n of e)(t==null&&n.listenerObject===s||n.eventName===t&&n.listener===s)&&i.push(n);for(let n of i)Re(e,n,void 0)},Pe=e=>{e&&(e.forEach(t=>{t.isRemoved=!0}),e.length=0)},fi=(e,t)=>e.listenerType===t.listenerType?e.priority===t.priority&&e.eventName===t.eventName&&e.listenerObject===t.listenerObject&&e.listener===t.listener:!1,pi=(e,t)=>{if(ci(e.listenerType))return t.find(s=>fi(e,s))},gi=(e,t)=>{let s=pi(e,t);return s?(s.refCount+=1,s):(t.push(e),t.sort(ui),e)},yi=class{constructor(){p(this,"namedListeners");p(this,"catchEmAllListeners");p(this,"getListenersForEventName",e=>{let t=this.namedListeners.get(e);return t||(t=[],this.namedListeners.set(e,t)),t});this.namedListeners=new Map,this.catchEmAllListeners=[]}add(e){return gi(e,e.isCatchEmAll?this.catchEmAllListeners:this.getListenersForEventName(e.eventName))}remove(e,t,s=!1){t==null&&Array.isArray(e)?e.forEach(i=>this.remove(i,null,s)):e==null||t==null&&pe(e)?this.removeAllListeners():t==null&&js(e)?Pe(this.namedListeners.get(e)):e instanceof Ds?e.isRemoved||(e.refCount-=1,e.refCount<1&&(e.isRemoved=!0,this.namedListeners.forEach(i=>ts(i,e)),ts(this.catchEmAllListeners,e))):s?pe(e)&&typeof e=="object"?le(this.catchEmAllListeners,jt,e):this.namedListeners.forEach(i=>le(i,e,t)):(this.namedListeners.forEach(i=>{Re(i,e,t),typeof e=="object"&&le(i,void 0,e)}),Re(this.catchEmAllListeners,e,t),typeof e=="object"&&le(this.catchEmAllListeners,void 0,e))}removeAllListeners(){this.namedListeners.forEach(e=>Pe(e)),this.namedListeners.clear(),Pe(this.catchEmAllListeners)}forEach(e,t){let s=_e(this.catchEmAllListeners),i=_e(this.namedListeners.get(e));if(e===jt||!i||i.length===0)s.forEach(t);else if(s.length===0)i.forEach(t);else{let n=i.length,o=s.length,a=0,d=0;for(;a<n||d<o;){if(a<n){let y=i[a];if(d>=o||y.priority>=s[d].priority){t(y),++a;continue}}d<o&&(t(s[d]),++d)}}}getSubscriptionCount(){let e=this.catchEmAllListeners.length;for(let t of this.namedListeners.values())e+=t.length;return e}},$t=e=>!!(e&&e[bt]);function Ht(e){if($t(e))return e;let t=new yi,s=new Ts;return ni(e,bt,{keeper:s,store:t}),e}var be={Max:Number.POSITIVE_INFINITY,AAA:1e9,BB:1e6,C:1e3,Default:0,Low:-1e4,Min:Number.NEGATIVE_INFINITY},bi=(e,t,s,i,n,o,a)=>{let d=e.add(new Ds(s,i,n,o));return t.emit(s,d,a),d},vi=(e,t,s,i)=>{let n=s.length,o=typeof s[0],a,d,y,m;if(n>=2&&n<=3&&o==="number"?(a=jt,[d,y,m]=s):n>=3&&n<=4&&typeof s[1]=="number"?[a,d,y,m]=s:(d=be.Default,o==="string"||o==="symbol"||Array.isArray(s[0])?[a,y,m]=s:(a=jt,[y,m]=s)),!y&&Ms)throw ri("called with insufficient arguments!",s),"subscribeTo() called with insufficient arguments!";let w=h=>l=>bi(e,t,l,h,y,m,i);return Array.isArray(a)?a.map(h=>Array.isArray(h)?w(h[1])(h[0]):w(d)(h)):w(d)(a)},xs=(e,t,s)=>{let i=[],n=vi(e,t,s,i);return Ts.publish(i),n},es=e=>t=>{t.callAfterApply=()=>{e==null||e()}},Ls=(e,t)=>Object.assign(()=>$(e,t),Array.isArray(t)?{listeners:t}:{listener:t}),Rs=(e,t,s,i)=>{let{store:n,keeper:o}=e[bt];Array.isArray(t)?t.forEach(a=>{n.forEach(a,d=>d.apply(a,s,i)),o.retain(a,s)}):t!==jt&&(n.forEach(t,a=>{a.apply(t,s,i)}),o.retain(t,s))},V=(e,...t)=>{let s=Ht(e),{store:i,keeper:n}=s[bt];return Ls(s,xs(i,n,t))},A=(e,...t)=>{let s=Ht(e),{store:i,keeper:n}=s[bt],o=xs(i,n,t),a=Ls(s,o),d=!1,y=()=>{d||(a(),d=!0)};return Array.isArray(o)?o.forEach(es(y)):es(y)(o),y},mi=(e,t)=>new Promise(s=>{A(e,t,s)}),$=(e,t,s)=>{if(!$t(e))throw new Error("object is not eventized");let{store:i,keeper:n}=e[bt],o=typeof t,a=s!=null&&(o==="string"||o==="symbol");i.remove(t,s,a),Array.isArray(t)?n.remove(t.filter(d=>typeof d=="string")):js(t)&&n.remove(t)},E=(e,t,...s)=>{if(!$t(e))throw new Error("object is not eventized");Rs(e,t,s)},wi=(e,t,...s)=>{if(!$t(e))throw new Error("object is not eventized");let i=[];return Rs(e,t,s,n=>{i.push(n)}),i=i.map(n=>Array.isArray(n)?Promise.all(n):Promise.resolve(n)),i.length>0?Promise.all(i):Promise.resolve()},Ge=(e,t)=>{let s=Ht(e),{keeper:i}=s[bt];i.add(t)},ge=(e,t)=>{if(!$t(e))throw new Error("object is not eventized");let{keeper:s}=e[bt];s.clear(t)},ot=(()=>{let e=(t={})=>Ht(t);return e.inject=(t={})=>(t=Ht(t),Object.assign(t,{on:(...s)=>V(t,...s),once:(...s)=>A(t,...s),onceAsync:s=>mi(t,s),off:(s,i)=>$(t,s,i),emit:(s,...i)=>E(t,s,...i),emitAsync:(s,...i)=>wi(t,s,...i),retain:s=>Ge(t,s),retainClear:s=>ge(t,s)}),t),e.is=$t,e})(),_=Symbol.for("signal"),Mt=Symbol.for("effect"),ss=Symbol.for("destroySignal"),is=Symbol.for("createEffect"),Ci=Symbol.for("destroyEffect"),Bt="value",rs="mute",ns="unmute",Yt="destroy",Xt=Symbol.for("recall"),ye=ot(),Nt=ot(),vt=ot(),zs=ot(),Te,qt=(Te=class{constructor(){p(this,"delayedEffects",[])}batch(e,t){let s=this.delayedEffects.length;for(let i=0;i<s;i++){let[n,o]=this.delayedEffects[i];if(!(n>t))if(n===t){o.add(e);return}else{this.delayedEffects.splice(i,0,[t,new Set([e])]);return}}this.delayedEffects.push([t,new Set([e])])}flush(){this.run(),this.delayedEffects.length=0}run(){let e=new Set,t=[V(vt,(i,n)=>{n===Xt&&e.add(i)}),V(zs,i=>{e.add(i)})],s=this.delayedEffects.flatMap(([,i])=>Array.from(i));for(let i of s)e.has(i)||E(vt,i,i,Xt);t.forEach(i=>{i()})}},p(Te,"current"),Te),Ei=()=>qt.current;function Qt(e){let t=qt.current;t?t=void 0:t=qt.current=new qt;try{e()}finally{t&&(qt.current=void 0,t.run())}}var Si=0;function Fs(){return Si>0}var ms,ki=(ms=Mt,class{constructor(e){p(this,ms);p(this,"run",()=>{var e;return(e=this[Mt])==null?void 0:e.run()});p(this,"destroy",()=>{var e;(e=this[Mt])==null||e.destroy(),this[Mt]=void 0});this[Mt]=e,A(e,$s.Destroy,()=>{this[Mt]=void 0})}}),ht=new Map,K,Ct,U,it,Y,Et,St,B,kt,at,ae=(at=class{constructor(t){g(this,K,new Set);g(this,Ct,new Set);g(this,U,new Map);g(this,it,new WeakMap);g(this,Y,new Map);g(this,Et,new Set);g(this,St,new Set);g(this,B);g(this,kt);if(t!=null&&t instanceof at)return t;if(t!=null||(t=this),ht.has(t))return ht.get(t);f(this,kt,t),ht.set(t,this),ot(this)}static get(t){if(t!=null)return t instanceof at?t:ht.get(t)}static findOrCreate(t){if(t==null)throw new Error("Cannot create a group with a null object");return new at(t)}static destroy(t){console.warn("SignalGroup.destroy(obj) is deprecated. Use SignalGroup.delete(obj) instead."),at.delete(t)}static delete(t){var s;(s=ht.get(t))==null||s.clear()}static clear(){for(let t of ht.values())t.clear();ht.clear()}attachGroup(t){if(t===this)throw new Error("Cannot attach a group to itself");return r(this,K).add(t),r(t,B)&&r(t,B)!==this&&r(r(t,B),K).delete(t),f(t,B,this),t}detachGroup(t){return t!==this&&r(this,K).has(t)&&(r(this,K).delete(t),f(t,B,void 0)),t}attachSignal(t){let s=P(t);if(s!=null&&s.destroyed)throw new Error("Cannot attach a destroyed signal to a group");return s&&r(this,Ct).add(s),t}attachSignalByName(t,s){if(s){this.attachSignal(s);let i=P(s);r(this,U).set(t,i),r(this,Y).has(t)?r(this,Y).get(t).push(i):r(this,Y).set(t,[i]),r(this,it).has(i)?r(this,it).get(i).add(t):r(this,it).set(i,new Set([t]))}else r(this,U).delete(t);return s}hasSignal(t){var s;return r(this,U).has(t)||!!((s=r(this,B))!=null&&s.hasSignal(t))}signal(t){var s,i,n;return(n=(s=r(this,U).get(t))==null?void 0:s.object)!=null?n:(i=r(this,B))==null?void 0:i.signal(t)}detachSignal(t){let s=P(t);if(s&&(r(this,Ct).delete(s),r(this,it).has(s))){let i=r(this,it).get(s);for(let n of i)if(r(this,Y).has(n)){let o=r(this,Y).get(n);o.splice(o.indexOf(s),1),o.length===0?(r(this,U).delete(n),r(this,Y).delete(n)):r(this,U).get(n)===s&&r(this,U).set(n,o.at(-1))}i.clear(),r(this,it).delete(s)}return t}attachEffect(t){return r(this,Et).add(t),t}runEffects(){for(let t of r(this,Et))t.run();for(let t of r(this,K))t.runEffects()}attachLink(t){if(t!=null&&t.isDestroyed)throw new Error("Cannot attach a destroyed link to a group");return t&&r(this,St).add(t),t}detachLink(t){return t&&r(this,St).delete(t),t}destroy(){console.warn("SignalGroup#destroy is deprecated. Use SignalGroup#clear instead."),this.clear()}clear(){var t;E(this,Yt,this),$(this);for(let s of r(this,K))s.clear();for(let s of r(this,Et))s.destroy();for(let s of r(this,Ct))G(s);for(let s of r(this,St))s.destroy();r(this,K).clear(),r(this,Ct).clear(),r(this,U).clear(),r(this,Y).clear(),r(this,Et).clear(),r(this,St).clear(),(t=r(this,B))==null||t.detachGroup(this),r(this,kt)&&(ht.delete(r(this,kt)),f(this,kt,void 0))}},K=new WeakMap,Ct=new WeakMap,U=new WeakMap,it=new WeakMap,Y=new WeakMap,Et=new WeakMap,St=new WeakMap,B=new WeakMap,kt=new WeakMap,at),se,ie,ws,Ns=(ws=class{constructor(e="id",t=1){g(this,se);g(this,ie);f(this,se,e),f(this,ie,t)}make(){return Symbol(\`\${r(this,se)}\${Ke(this,ie)._++}\`)}},se=new WeakMap,ie=new WeakMap,ws),ze=[],Vs=()=>ze.at(-1),Ai=(e,t)=>{ze.push(e);try{return t()}finally{ze.pop()}},Pi=e=>e!=null&&typeof e.then=="function",j,lt,X,At,dt,ut,Pt,Dt,$s=(j=class{constructor(t,s){p(this,"id");p(this,"callback");g(this,lt);g(this,X,new Set);g(this,At,new Set);g(this,dt,new Map);g(this,ut,new Set);p(this,"parentEffect");p(this,"childEffects",[]);p(this,"curChildEffectSlot",0);p(this,"autorun",!0);p(this,"shouldRun",!0);p(this,"priority");g(this,Pt);g(this,Dt,!1);p(this,"run",()=>{if(r(this,Dt)||!this.shouldRun)return;let t=Ei();t?t.batch(this.id,this.priority):(this.runCleanupCallback(),this.destroyChildEffects(),this.curChildEffectSlot=0,this.shouldRun=!1,E(zs,this.id,this.id),this.hasStaticDeps()?f(this,lt,this.callback()):(f(this,At,new Set(r(this,X))),f(this,lt,Ai(this,this.callback)),this.cleanupLostSignals(),r(this,ut).clear()))});p(this,"destroy",()=>{r(this,Dt)||(E(this,j.Destroy,this),$(this),E(vt,Ci,this),this.runCleanupCallback(),this.destroyChildEffects(),$(ye,this),$(vt,this),$(Nt,this),f(this,Dt,!0),r(this,X).clear(),r(this,At).clear(),r(this,dt).clear(),r(this,ut).clear(),--j.count)});var n,o;ot(this),this.callback=t;let i;(s==null?void 0:s.attach)!=null&&(i=ae.findOrCreate(s.attach),i.attachEffect(this)),this.autorun=(n=s==null?void 0:s.autorun)!=null?n:!0,f(this,Pt,s!=null&&s.dependencies?s.dependencies.map(a=>{switch(typeof a){case"string":case"symbol":return i.signal(a);default:return a}}):void 0),this.id=j.idGen.make(),this.priority=(o=s==null?void 0:s.priority)!=null?o:0,V(vt,this.id,Xt,this),++j.count}hasStaticDeps(){return r(this,Pt)!=null&&r(this,Pt).length>0}saveSignalsFromDeps(){for(let t of r(this,Pt))this.whenSignalIsRead(P(t).id)}static createEffect(t,s,i){let n=Array.isArray(s)?s:void 0,o=n?i!=null?i:{dependencies:n}:s;o&&n&&(o.dependencies=n);let a,d=Vs();return d!=null?(a=d.getCurrentChildEffect(),a==null&&(a=new j(t,o),d.attachChildEffect(a),E(vt,is,a)),d.curChildEffectSlot++):(a=new j(t,o),E(vt,is,a)),a.hasStaticDeps()?a.saveSignalsFromDeps():a.autorun&&a.run(),new ki(a)}getCurrentChildEffect(){return this.childEffects[this.curChildEffectSlot]}attachChildEffect(t){this.childEffects.push(t),this.parentEffect=this}[Xt](){this.shouldRun=!0,this.autorun&&this.run()}whenSignalIsRead(t){r(this,At).delete(t),r(this,X).has(t)||(r(this,X).add(t),r(this,dt).set(t,[V(ye,t,this.priority,Xt,this),A(Nt,t,ss,this)]))}[ss](t){!r(this,ut).has(t)&&r(this,X).has(t)&&(r(this,ut).add(t),this.unsubscribeSignal(t),r(this,ut).size===r(this,X).size&&this.destroy())}cleanupLostSignals(){for(let t of r(this,At))this.unsubscribeSignal(t),r(this,X).delete(t)}destroyChildEffects(){for(let t of this.childEffects)t.destroy();this.childEffects.length=0}unsubscribeSignal(t){r(this,dt).has(t)&&(r(this,dt).get(t).forEach(s=>{s()}),r(this,dt).delete(t))}runCleanupCallback(){if(r(this,lt)!=null){let t=r(this,lt);f(this,lt,void 0),Pi(t)?Promise.resolve(t).then(s=>{typeof s=="function"&&s()}):t()}}},lt=new WeakMap,X=new WeakMap,At=new WeakMap,dt=new WeakMap,ut=new WeakMap,Pt=new WeakMap,Dt=new WeakMap,p(j,"idGen",new Ns("ef")),p(j,"Destroy","destroy"),p(j,"count",0),j),Vt=(...e)=>$s.createEffect(...e),_t=new WeakMap,Oi=e=>{let t=_t.get(e);return t||(t={},_t.set(e,t)),t},te=(e,t)=>{var s,i;return(i=(s=_t.get(e))==null?void 0:s.signals)==null?void 0:i.get(t)},ji=(e,t,s)=>{var n;let i=Oi(e);(n=i.signals)!=null||(i.signals=new Map),i.signals.set(t,s)};function Mi(...e){for(let t of e)if(_t.has(t)){let s=_t.get(t);if(s.signals){for(let i of s.signals.values())G(i);s.signals.clear(),s.signals=void 0}}}function Ti(e){let t=P(ee(e)?e:te(...e));t!=null&&!t.muted&&!t.destroyed&&Fe(t.id,t.value,{touch:!0})}function Ue(e){var t,s;return ee(e)?(t=P(e))==null?void 0:t.value:(s=P(te(...e)))==null?void 0:s.value}var Cs,Di=(Cs=_,class{constructor(e){p(this,Cs);this[_]=e}get get(){return this[_].reader}get set(){return this[_].writer}get value(){return Ue(this.get)}set value(e){this.set(e)}onChange(e){let{destroy:t}=Vt(()=>e(this.value),[this.get]);return t}get muted(){return this[_].muted}set muted(e){this[_].muted=e}touch(){Ti(this)}destroy(){G(this)}}),xi=new Ns("si");function as(e){var t;Fs()||((t=Vs())==null||t.whenSignalIsRead(e))}function Fe(e,t,s){Fs()||E(ye,e,t,s)}var ee=e=>e!=null&&e[_]!=null,Li=e=>{let t=s=>{var i;return s?Vt(()=>(e.destroyed||as(e.id),s(e.value)),[t]):e.destroyed||((i=e.beforeRead)==null||i.call(e),as(e.id)),e.value};return Object.defineProperty(t,_,{value:e}),t},Ot,W,Is=(Ot=class{constructor(t,s){p(this,"id");p(this,"lazy");p(this,"compare");p(this,"beforeRead");p(this,"muted",!1);p(this,"destroyed",!1);g(this,W);p(this,"valueFn");p(this,"reader");p(this,"writer",(t,s)=>{var o,a,d,y;let i=(o=s==null?void 0:s.lazy)!=null?o:!1,n=(d=(a=s==null?void 0:s.compare)!=null?a:this.compare)!=null?d:((m,w)=>m===w);if((i!==this.lazy||i&&t!==this.valueFn||!i&&!n(t,r(this,W)))&&(i?(f(this,W,void 0),this.valueFn=t,this.lazy=!0):(f(this,W,t),this.valueFn=void 0,this.lazy=!1),!this.muted&&!this.destroyed)){Fe(this.id,r(this,W));return}(y=s==null?void 0:s.touch)!=null&&y&&Fe(this.id,r(this,W),{touch:!0})});p(this,"object");this.id=xi.make(),++Ot.instanceCount,this.lazy=t,this.lazy?(this.value=void 0,this.valueFn=s):(this.value=s,this.valueFn=void 0),this.reader=Li(this),this.object=new Di(this)}get[_](){return this}get value(){return this.lazy&&(f(this,W,this.valueFn()),this.valueFn=void 0,this.lazy=!1),r(this,W)}set value(t){f(this,W,t)}},W=new WeakMap,p(Ot,"instanceCount",0),Ot),P=e=>e==null?void 0:e[_];function k(e=void 0,t){var i;let s;if(ee(e))s=P(e);else{let n=(i=t==null?void 0:t.lazy)!=null?i:!1;s=new Is(n,e),s.beforeRead=t==null?void 0:t.beforeRead,s.compare=t==null?void 0:t.compare}return(t==null?void 0:t.attach)!=null&&ae.findOrCreate(t.attach).attachSignal(s),s.object}var G=(...e)=>{for(let t of e){let s=P(t);s!=null&&!s.destroyed&&(s.destroyed=!0,s.beforeRead=void 0,--Is.instanceCount,E(Nt,s.id,s.id))}};function Ri(e,t){var a,d;let s=k(),i=(t==null?void 0:t.attach)!=null?ae.findOrCreate(t.attach):void 0;i!=null&&(t!=null&&t.name?i.attachSignalByName(t.name,s):i.attachSignal(s));let n=Vt(()=>{Qt(()=>{s.set(e())})},{autorun:!((a=t==null?void 0:t.lazy)!=null&&a),priority:(d=t==null?void 0:t.priority)!=null?d:be.C,attach:i}),o=P(s);return o.beforeRead=n.run,A(Nt,o.id,n.destroy),s.get}var O,xt,Es,Gs=(Es=class{constructor(e){g(this,O,!1);g(this,xt);p(this,"source");p(this,"lastValue");p(this,"isDestroyed",!1);ot(this),this.source=P(e),f(this,xt,V(ye,this.source.id,(t,s)=>{!r(this,O)&&!this.isDestroyed&&((s==null?void 0:s.touch)===!0?this.touch():this.write())})),A(Nt,this.source.id,()=>this.destroy())}attach(e){let t=ae.findOrCreate(e);return t.attachLink(this),A(this,Yt,()=>{t.detachLink(this)}),t}nextValue(){return new Promise((e,t)=>{let s=[],i=()=>s.forEach(n=>{n()});s.push(A(this,Bt,n=>{i(),e(n)}),A(this,Yt,()=>{i(),t()}))})}asyncValues(e){return Ye(this,null,function*(){Ge(this,Bt);try{let t=0;for(;!this.isDestroyed;)try{let s=yield new Ee(this.nextValue());if(e&&e(s,t++))break;yield s}catch(s){break}}finally{ge(this,Bt)}})}destroy(){var e;this.isDestroyed||((e=r(this,xt))==null||e.call(this),f(this,xt,void 0),E(this,Yt,this),ge(this,Bt),$(this),this.lastValue=void 0,this.isDestroyed=!0,Object.freeze(this))}get isMuted(){return r(this,O)}mute(){return!this.isDestroyed&&!r(this,O)&&(f(this,O,!0),E(this,rs,this)),this}unmute(){return!this.isDestroyed&&r(this,O)&&(f(this,O,!1),E(this,ns,this)),this}toggleMute(){return this.isDestroyed||(f(this,O,!r(this,O)),E(this,r(this,O)?rs:ns,this)),r(this,O)}updateValue(e){if(!r(this,O)&&!this.isDestroyed){let{value:t}=this.source;e(t),E(this,Bt,t),this.lastValue=t}}},O=new WeakMap,xt=new WeakMap,Es),zi=class extends Gs{constructor(t,s){super(t);p(this,"target");this.target=P(s),A(Nt,this.target.id,()=>this.destroy()),this.touch()}touch(){return this.updateValue(t=>{this.target.writer(t,{touch:!0})}),this}write(){this.updateValue(t=>{this.target.writer(t)})}},Fi=class extends Gs{constructor(t,s){super(t);p(this,"target");this.target=s,this.touch()}touch(){return this.updateValue(t=>{this.target(t)}),this}write(){this.updateValue(t=>{this.target(t)})}},de=new Map;function et(e,t,s){var m;let i=P(e),n;if(de.has(i)){n=de.get(i);let w=(m=P(t))!=null?m:t;if(n.has(w))return n.get(w)}else n=new Map,de.set(i,n);let o=P(t),a=o!=null?new zi(e,o):new Fi(e,t),d=s==null?void 0:s.attach;d&&a.attach(d);let y=o!=null?o:t;return n.set(y,a),A(a,Yt,()=>{n.delete(y),n.size===0&&de.delete(i)}),a}var D,Lt,Ni=(Lt=class{constructor(){g(this,D,new Map)}static fromProps(t,s){let i=new Lt,n=s?s.map(o=>[o,t[o]]):Object.entries(t);for(let[o,a]of n)r(i,D).set(o,k(a));return i}keys(){return r(this,D).keys()}signals(){return r(this,D).values()}entries(){return r(this,D).entries()}clear(){for(let t of r(this,D).values())t.destroy();r(this,D).clear()}has(t){return r(this,D).has(t)}get(t){if(!r(this,D).has(t)){let s=k();return r(this,D).set(t,s),s}return r(this,D).get(t)}update(t){t.size&&Qt(()=>{for(let[s,i]of t.entries())this.get(s).set(i)})}updateFromProps(t,s){Qt(()=>{let i=s?s.map(n=>[n,t[n]]):Object.entries(t);for(let[n,o]of i)this.get(n).set(o)})}},D=new WeakMap,Lt),Oe=e=>e!=null?e:void 0;function Vi(e,t,s,i,n,o){function a(I){if(I!==void 0&&typeof I!="function")throw new TypeError("Function expected");return I}for(var d=i.kind,y=d==="getter"?"get":d==="setter"?"set":"value",m=!t&&e?i.static?e:e.prototype:null,w=t||(m?Object.getOwnPropertyDescriptor(m,i.name):{}),h,l=!1,u=s.length-1;u>=0;u--){var c={};for(var v in i)c[v]=v==="access"?{}:i[v];for(var v in i.access)c.access[v]=i.access[v];c.addInitializer=function(I){if(l)throw new TypeError("Cannot add initializers after decoration has completed");o.push(a(I||null))};var T=(0,s[u])(d==="accessor"?{get:w.get,set:w.set}:w[y],c);if(d==="accessor"){if(T===void 0)continue;if(T===null||typeof T!="object")throw new TypeError("Object expected");(h=a(T.get))&&(w.get=h),(h=a(T.set))&&(w.set=h),(h=a(T.init))&&n.unshift(h)}else(h=a(T))&&(d==="field"?n.unshift(h):w[y]=h)}m&&Object.defineProperty(m,i.name,w),l=!0}function os(e,t,s){for(var i=arguments.length>2,n=0;n<t.length;n++)s=i?t[n].call(e,s):t[n].call(e);return i?s:void 0}function $i(e){return function(t,s){var o;let i=(e==null?void 0:e.name)||s.name,n=!!((o=e==null?void 0:e.readAsValue)!=null&&o);return{get(){let a=te(this,i);if(a)return n?a.value:a.get()},set(a){var d;(d=te(this,i))==null||d.set(a)},init(a){let d=k(a,e);return ji(this,i,d),ae.findOrCreate(this).attachSignalByName(i,d),d.value}}}}var Tt="value",Ne=(()=>{var i,n,o,a,ce,Jt,m;let e,t=[],s=[];return m=class{constructor(h){g(this,a);g(this,i);g(this,n);g(this,o);f(this,i,[]),f(this,o,os(this,t,void 0)),this.value$=os(this,s),Ge(this,Tt),this.value$=te(this,Tt),this.value$.onChange(l=>E(this,Tt,l)),h&&this.add(...h)}get value(){return r(this,o)}set value(h){f(this,o,h)}add(...h){return r(this,i).push(...h),C(this,a,Jt).call(this),C(this,a,ce).call(this,h)}unshift(...h){return r(this,i).unshift(...h),C(this,a,Jt).call(this),C(this,a,ce).call(this,h)}remove(...h){C(this,a,ce).call(this,h)()}clear(){r(this,i).length=0,C(this,a,Jt).call(this)}dispose(){var h;this.clear(),(h=r(this,n))==null||h.destroy(),f(this,n,void 0),ge(this,Tt),$(this),this.value$.destroy(),Mi(this)}},i=new WeakMap,n=new WeakMap,o=new WeakMap,a=new WeakSet,ce=function(h){return()=>{for(let l of h){let u=r(this,i).indexOf(l);u!==-1&&r(this,i).splice(u,1)}C(this,a,Jt).call(this)}},Jt=function(){var h;(h=r(this,n))==null||h.destroy(),r(this,i).length===0?(f(this,n,void 0),this.value=void 0):(f(this,n,Vt(()=>{let l;for(let u of r(this,i)){let c=Ue(u);if(c!=null){l=c;break}}this.value=l},r(this,i))),r(this,n).run())},(()=>{let h=typeof Symbol=="function"&&Symbol.metadata?Object.create(null):void 0;e=[$i({name:Tt})],Vi(m,null,e,{kind:"accessor",name:"value",static:!1,private:!1,access:{has:l=>"value"in l,get:l=>l.value,set:(l,u)=>{l.value=u}},metadata:h},t,s),h&&Object.defineProperty(m,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:h})})(),m.Value=Tt,m})(),hs=Symbol("onCreate"),mt=Symbol("onDestroy"),Ii=Symbol("onParentChanged"),Us=Symbol("onViewEvent"),je=new Map,Me=!1,Gi=(e,t)=>{je.set(e,t),Me||(Me=!0,queueMicrotask(()=>{Me=!1;let s=Array.from(je.entries());je.clear();for(let[i,n]of s)i.set(n)}))},Z,Rt,ct,q,ft,z,x,rt,F,zt,M,Ve,pt,Kt,fe,Ss,Ui=(Ss=class{constructor(e,t){g(this,M);g(this,Z);g(this,Rt);g(this,ct,new Ni);g(this,q,new Map);g(this,ft,new Map);g(this,z);g(this,x);g(this,rt,new Set);g(this,F,[]);g(this,zt,0);g(this,pt);f(this,Z,e),f(this,Rt,t),A(this,mt,be.Min,this)}get kernel(){return r(this,Z)}get uuid(){return r(this,Rt)}get order(){return r(this,zt)}set order(e){r(this,zt)!==e&&(f(this,zt,e),r(this,z)&&this.parent.resortChildren())}get parentUuid(){return r(this,z)||void 0}set parentUuid(e){r(this,z)!==e&&(this.removeFromParent(),f(this,z,e||void 0),f(this,x,e?r(this,Z).getEntity(e):void 0),r(this,x)&&r(this,x).addChild(this))}get parent(){return!r(this,x)&&r(this,z)&&f(this,x,r(this,Z).getEntity(r(this,z))),r(this,x)}set parent(e){this.parentUuid=e==null?void 0:e.uuid}get hasParent(){return!!r(this,z)}get children(){return r(this,F)}traverse(e){e(this);for(let t of r(this,F))t.traverse(e)}[mt](){var e;r(this,ct).clear(),$(this);for(let t of r(this,ft).values())t.cleanup(),t.signal.destroy();r(this,ft).clear();for(let t of r(this,q).values())t.context.set(void 0),t.unsubscribePathValue(),(e=t.unsubscribeFromParent)==null||e.call(t),t.valuePath.dispose(),t.inherited.destroy(),t.provide.destroy(),t.context.destroy();f(this,z,void 0),f(this,x,void 0),r(this,rt).clear(),r(this,F).length=0}addChild(e){var t;if(r(this,F).length===0){r(this,rt).add(e.uuid),r(this,F).push(e);return}if(r(this,rt).has(e.uuid))throw new Error(\`child with uuid: \${e.uuid} already exists! parentUuid: \${this.uuid}\`);r(this,rt).add(e.uuid),r(this,F).push(e),this.resortChildren();for(let[,s]of r(e,q))C(t=e,M,fe).call(t,s)}resortChildren(){r(this,F).sort((e,t)=>e.order-t.order)}removeChild(e){r(this,rt).has(e.uuid)&&(r(this,rt).delete(e.uuid),r(this,F).splice(r(this,F).indexOf(e),1))}removeFromParent(){if(r(this,x)){r(this,x).removeChild(this),f(this,x,void 0),f(this,z,void 0);for(let[,e]of r(this,q))e.unsubscribeFromParent&&(e.unsubscribeFromParent(),e.unsubscribeFromParent=void 0)}}reSubscribeToParentContexts(){for(let[,e]of r(this,q))C(this,M,fe).call(this,e)}dispatchMessageToView(e,t,s,i=!1){r(this,Z).dispatchMessageToView({uuid:r(this,Rt),type:e,data:t,transferables:s,traverseChildren:i})}dispatchViewEvents(e){for(let{type:t,data:s}of e)E(this,Us,t,s)}dispatchViewEvent(e,t){this.dispatchViewEvents([{type:e,data:t}])}getPropertyReader(e){return C(this,M,Ve).call(this,e).get}getPropertyWriter(e){return C(this,M,Ve).call(this,e).set}setProperties(e){this.clearTruthyPropsCache(),Qt(()=>{for(let[t,s]of e)this.setProperty(t,s)})}setProperty(e,t){this.getPropertyWriter(e)(t)}getProperty(e){return Ue(this.getPropertyReader(e))}propKeys(){return Array.from(r(this,ct).keys())}propEntries(){return Array.from(r(this,ct).entries()).map(([e,t])=>[e,t.value])}clearTruthyPropsCache(){f(this,pt,void 0)}truthyProps(){if(r(this,pt))return r(this,pt).size?r(this,pt):void 0;let e=new Set;for(let[t,s]of r(this,ct).entries())if(typeof t=="string"){let i=s.value;i!=null&&i!==!1&&i!==""&&e.add(t)}return f(this,pt,e),e.size?e:void 0}hasContext(e){return r(this,q).has(e)}useContext(e){return C(this,M,Kt).call(this,e).context.get}useParentContext(e){return C(this,M,Kt).call(this,e).inherited.get}provideContext(e){return C(this,M,Kt).call(this,e).provide}provideGlobalContext(e){if(r(this,ft).has(e))return r(this,ft).get(e).signal;let t=r(this,Z).findOrCreateRootContext(e),s=k(),i=t.add(s);return r(this,ft).set(e,{cleanup:i,signal:s}),s}},Z=new WeakMap,Rt=new WeakMap,ct=new WeakMap,q=new WeakMap,ft=new WeakMap,z=new WeakMap,x=new WeakMap,rt=new WeakMap,F=new WeakMap,zt=new WeakMap,M=new WeakSet,Ve=function(e){return r(this,ct).get(e)},pt=new WeakMap,Kt=function(e){if(r(this,q).has(e))return r(this,q).get(e);let t=k(),s=k(),i=k(),n=new Ne([s,t]),o=V(n,Ne.Value,d=>{Gi(i,d)}),a={name:e,inherited:t,provide:s,context:i,valuePath:n,unsubscribePathValue:o};return r(this,q).set(e,a),C(this,M,fe).call(this,a),a},fe=function(e){var t,s;if((t=e.unsubscribeFromParent)==null||t.call(e),e.unsubscribeFromParent=void 0,this.parent){let i=C(s=this.parent,M,Kt).call(s,e.name),n=et(i.context,e.inherited);e.unsubscribeFromParent=n.destroy.bind(n)}else{let i=r(this,Z).findOrCreateRootContext(e.name),n=et(i.value$,e.inherited);e.unsubscribeFromParent=n.destroy.bind(n)}},Ss);function Bi(e,t){e.indexOf(t)===-1&&e.push(t)}var ls=e=>{let t=e.split("@").map(s=>s.trim());if(t.length===2&&t[1])return t[0]?{key:\`\${t[0]}@\${t[1]}\`,prop:t[1],token:t[0]}:{key:t[1],prop:t[1]}},ue=(e,t)=>{for(let s of t)e.add(s)},Wi=(e,t)=>{if(e!=null)for(let s of e.constructors)t.add(s)},nt,L,J,ks,Bs=(ks=class{constructor(){g(this,nt,new Map);g(this,L,new Map);g(this,J,new Map)}static get(e){return e!=null?e:qi}define(e,t){r(this,nt).has(e)?Bi(r(this,nt).get(e).constructors,t):r(this,nt).set(e,{token:e,constructors:[t]})}appendRoute(e,t){let s=ls(e);s?r(this,J).has(s.key)?ue(r(this,J).get(s.key).routes,t):r(this,J).set(s.key,{routes:new Set(t),token:s.token}):r(this,L).has(e)?ue(r(this,L).get(e),t):r(this,L).set(e,new Set(t))}clearRoute(e){let t=ls(e);t?r(this,J).delete(t.key):r(this,L).delete(e)}findTokensByRoute(e,t){let s=new Set([e]),i=r(this,L).has(e)?[...r(this,L).get(e)]:[];for(;i.length;){let n=i.shift();s.has(n)||(s.add(n),r(this,L).has(n)&&i.push(...Array.from(r(this,L).get(n)).filter(o=>!s.has(o))))}if(t){for(let o of t)r(this,J).has(o)&&ue(s,r(this,J).get(o).routes);let n;do{n=s.size;for(let o of new Set(s))for(let a of t){let d=\`\${o}@\${a}\`;r(this,J).has(d)&&ue(s,r(this,J).get(d).routes)}}while(n!==s.size)}return s}findConstructors(e,t){let s=this.findTokensByRoute(e,t),i=new Set;for(let n of s)Wi(r(this,nt).get(n),i);return i.size>0?Array.from(i):void 0}hasToken(e){return r(this,nt).has(e)}hasRoute(e){return r(this,L).has(e)}clear(){r(this,nt).clear(),r(this,L).clear()}},nt=new WeakMap,L=new WeakMap,J=new WeakMap,ks),qi=new Bs,st;(function(e){e[e.CreateAndDestroy=0]="CreateAndDestroy",e[e.JustCreate=1]="JustCreate",e[e.DestroyOnly=2]="DestroyOnly"})(st||(st={}));var ds=e=>e.displayName||e.name,us=!1,cs=!1,fs=!1,ps=!1,gs=!1,S,H,Ft,re,Q,gt,As,Ji=(As=class{constructor(e){g(this,S);g(this,H);g(this,Ft);g(this,re);g(this,Q);g(this,gt);this.logger=new si("Kernel"),f(this,S,new Map),f(this,H,new Set),f(this,Q,!0),f(this,gt,new Map),ot(this),this.registry=Bs.get(e)}getEntity(e){var s;let t=(s=r(this,S).get(e))==null?void 0:s.entity;if(!t)throw new Error(\`entity with uuid "\${e}" not found!\`);return t}hasEntity(e){return r(this,S).has(e)}traverseLevelOrderBFS(e=!1){if(r(this,Q)){let t=new Map,s=(i,n)=>{let o=this.getEntity(i);t.has(n)?t.get(n).push(o):t.set(n,[o]);for(let a of o.children)s(a.uuid,n+1)};r(this,H).forEach(i=>{s(i,0)}),f(this,Ft,Array.from(t.entries()).sort((i,n)=>i[0]-n[0]).flatMap(([,i])=>i)),f(this,re,r(this,Ft).slice().reverse()),f(this,Q,!1)}return e?r(this,re):r(this,Ft)}getEntityGraph(){return Array.from(r(this,H)).map(e=>this.getEntityGraphNode(e))}getEntityGraphNode(e){if(!r(this,S).has(e))return;let{token:t,entity:s}=r(this,S).get(e);return{token:t,entity:s,props:Object.fromEntries(s.propEntries()),children:s.children.map(i=>this.getEntityGraphNode(i.uuid))}}upgradeEntities(){let e=new Map;for(let t of this.traverseLevelOrderBFS(!0))e.set(t.uuid,this.updateShadowObjects(t.uuid,st.DestroyOnly));for(let t of this.traverseLevelOrderBFS(!1))this.updateShadowObjects(t.uuid,st.JustCreate,e.get(t.uuid));e.clear()}run(e){this.logger.isDebug&&this.logger.debug("sync",e),Qt(()=>{for(let t of e.changeTrail)this.parse(t)})}parse(e){switch(e.type){case tt.CreateEntities:this.createEntity(e.uuid,e.token,e.parentUuid,e.order,e.properties),f(this,Q,!0);break;case tt.DestroyEntities:this.destroyEntity(e.uuid),f(this,Q,!0);break;case tt.SetParent:this.setParent(e.uuid,e.parentUuid,e.order),f(this,Q,!0);break;case tt.UpdateOrder:this.updateOrder(e.uuid,e.order),f(this,Q,!0);break;case tt.ChangeProperties:this.changeProperties(e.uuid,e.properties);break;case tt.ChangeToken:this.changeToken(e.uuid,e.token);break;case tt.SendEvents:this.dispatchEventsToEntity(e.uuid,e.events);break}}createEntity(e,t,s,i=0,n){let o=new Ui(this,e);o.order=i;let a={token:t,entity:o,usedConstructors:new Map};r(this,S).set(e,a),s&&(o.parentUuid=s),o.hasParent||r(this,H).add(e),n&&o.setProperties(n),this.createShadowObjects(e)}destroyEntity(e){if(!r(this,S).has(e))return;let{entity:t,usedConstructors:s}=r(this,S).get(e);t.removeFromParent(),E(t,mt,t),s.clear(),r(this,S).delete(t.uuid),r(this,H).delete(t.uuid)}setParent(e,t,s=0){let i=this.getEntity(e);i.parentUuid===t&&i.order===s||(i.removeFromParent(),i.order=s,i.parentUuid=t,i.hasParent?r(this,H).delete(e):r(this,H).add(e),i.reSubscribeToParentContexts(),queueMicrotask(()=>{this.logger.isDebug&&this.logger.debug("entity.onParentChanged",{uuid:e,parentUuid:t,order:s,entity:i}),E(i,Ii,i)}))}updateOrder(e,t){this.getEntity(e).order=t}dispatchEventsToEntity(e,t){var s;(s=this.getEntity(e))==null||s.dispatchViewEvents(t)}changeProperties(e,t){this.getEntity(e).setProperties(t),this.updateShadowObjects(e)}changeToken(e,t){if(!r(this,S).has(e))return;let s=r(this,S).get(e);s.token!==t&&(s.token=t,this.updateShadowObjects(e))}dispatchMessageToView(e){queueMicrotask(()=>{E(this,De,e)})}updateShadowObjects(e,t=st.CreateAndDestroy,s){let i=r(this,S).get(e);s!=null||(s=new Set(this.registry.findConstructors(i.token,i.entity.truthyProps())));let n=t===st.CreateAndDestroy||t===st.DestroyOnly,o=t===st.CreateAndDestroy||t===st.JustCreate;if(n){for(let[a,d]of i.usedConstructors)if(!s.has(a)){i.usedConstructors.delete(a);for(let y of d)this.destroyShadowObject(y,i.entity)}}if(o)for(let a of s)i.usedConstructors.has(a)||this.constructShadowObject(a,i);return s}constructShadowObject(e,t){let s=new Set,i=new Set,n=new Map,o=new Map,a=new Map,d=new Map,y=new Map,m=(h,l)=>{!gs&&l!=null&&typeof l=="function"&&(console.warn('[shadow-objects] Deprecation Warning: The "isEqual" option of "useProperty()" is now passed as {compare} argument. Please update your code accordingly.'),gs=!0);let u=typeof l=="function"?{compare:l}:l,c=y.get(h);if(c===void 0){c=k(void 0,u).get,y.set(h,c);let v=et(t.entity.getPropertyReader(h),c);i.add(v.destroy.bind(v))}return c},w=ot(new e({entity:t.entity,provideContext(h,l,u){var T;!us&&u!=null&&typeof u=="function"&&(console.warn('[shadow-objects] Deprecation Warning: The "isEqual" option of "provideContext()" is now passed as {compare} argument. Please update your code accordingly.'),us=!0);let c=typeof u=="function"?{compare:u}:u,v=a.get(h);if(v==null){let I=ee(l),ve=I?void 0:Oe(l);if(v=k(ve,c!=null&&c.compare?{compare:c.compare}:void 0),I){let Gt=et(l,v);i.add(Gt.destroy.bind(Gt))}let It=et(v,t.entity.provideContext(h));i.add(It.destroy.bind(It)),a.set(h,v)}return v!=null&&((T=c==null?void 0:c.clearOnDestroy)==null||T)&&i.add(()=>{v.set(void 0)}),v},provideGlobalContext(h,l,u){var T;!cs&&u!=null&&typeof u=="function"&&(console.warn('[shadow-objects] Deprecation Warning: The "isEqual" option of "provideGlobalContext()" is now passed as {compare} argument. Please update your code accordingly.'),cs=!0);let c=typeof u=="function"?{compare:u}:u,v=d.get(h);if(v==null){let I=ee(l),ve=I?void 0:Oe(l);if(v=k(ve,c!=null&&c.compare?{compare:c.compare}:void 0),I){let Gt=et(l,v);i.add(Gt.destroy.bind(Gt))}let It=et(v,t.entity.provideGlobalContext(h));i.add(It.destroy.bind(It)),d.set(h,v)}return v!=null&&((T=c==null?void 0:c.clearOnDestroy)==null||T)&&i.add(()=>{v.set(void 0)}),v},useContext(h,l){!fs&&l!=null&&typeof l=="function"&&(console.warn('[shadow-objects] Deprecation Warning: The "isEqual" option of "useContext()" is now passed as {compare} argument. Please update your code accordingly.'),fs=!0);let u=typeof l=="function"?{compare:l}:l,c=n.get(h);if(c===void 0){c=k(void 0,u).get,n.set(h,c);let v=et(t.entity.useContext(h),c);i.add(v.destroy.bind(v))}return c},useParentContext(h,l){!ps&&l!=null&&typeof l=="function"&&(console.warn('[shadow-objects] Deprecation Warning: The "isEqual" option of "useParentContext()" is now passed as {compare} argument. Please update your code accordingly.'),ps=!0);let u=typeof l=="function"?{compare:l}:l,c=o.get(h);if(c===void 0){c=k(void 0,u).get,o.set(h,c);let v=et(t.entity.useParentContext(h),c);i.add(v.destroy.bind(v))}return c},dispatchMessageToView(h,l,u,c=!1){t.entity.dispatchMessageToView(h,l,u,c)},useProperty:m,useProperties(h){let l={};for(let u in h)Object.hasOwn(h,u)&&(l[u]=m(h[u]));return l},createResource(h,l){let u=k(),c=Vt(()=>{let v=Oe(h());return u.set(v),v!==void 0&&l?()=>{l(v),u.set(void 0)}:()=>{u.set(void 0)}});return i.add(()=>{c.destroy(),u.set(void 0),G(u)}),u},createEffect(...h){let l=Vt(...h);return i.add(l.destroy),l},createSignal(...h){let l=k(...h);return i.add(()=>{G(l)}),l},createMemo(...h){let l=Ri(...h);return i.add(()=>{G(l)}),l},on(...h){let[l]=h;if(typeof l=="string"||typeof l=="symbol"||Array.isArray(l)){let c=V(t.entity,...h);return i.add(c),c}let u=V(...h);return i.add(u),Object.assign(()=>{i.delete(u),u()},u)},once(...h){let[l]=h;if(typeof l=="string"||typeof l=="symbol"||Array.isArray(l)){let c=A(t.entity,...h);return i.add(c),c}let u=A(...h);return i.add(u),Object.assign(()=>{i.delete(u),u()},u)},emit(...h){let[l]=h;typeof l=="string"||typeof l=="symbol"||Array.isArray(l)?E(t.entity,...h):E(...h)},onViewEvent(h){let l=V(t.entity,Us,(u,c)=>{h(u,c)});i.add(l)},onDestroy(h){s.add(h)}}));return this.logger.isInfo&&this.logger.info("create shadow-object",ds(e),{shadowObject:w,entity:t.entity}),A(t.entity,mt,be.Low,()=>{this.logger.isInfo&&this.logger.info("destroy shadow-object",ds(e),{shadowObject:w,entity:t.entity});for(let l of s)l();for(let l of i)l();for(let l of n.values())G(l);for(let l of o.values())G(l);for(let l of y.values())G(l);for(let l of a.values())G(l);for(let l of d.values())G(l);s.clear(),i.clear(),n.clear(),o.clear(),y.clear(),a.clear(),d.clear();let h=t.usedConstructors.get(e);h&&(h.delete(w),h.size===0&&t.usedConstructors.delete(e))}),t.usedConstructors.has(e)?t.usedConstructors.get(e).add(w):t.usedConstructors.set(e,new Set([w])),this.attachShadowObject(w,t.entity),w}createShadowObjects(e){var s;let t=r(this,S).get(e);(s=this.registry.findConstructors(t.token,t.entity.truthyProps()))==null||s.forEach(i=>{this.constructShadowObject(i,t)})}findShadowObjects(e){if(!r(this,S).has(e))return[];let{usedConstructors:t}=r(this,S).get(e);return Array.from(new Set(Array.from(t.values()).flatMap(s=>Array.from(s))))}attachShadowObject(e,t){V(t,e),typeof e[hs]=="function"&&e[hs](t)}destroyShadowObject(e,t){typeof e[mt]=="function"&&e[mt](t),E(e,mt,t),$(t,e)}findOrCreateRootContext(e){let t=r(this,gt).get(e);return t||(t=new Ne,r(this,gt).set(e,t)),t}destroy(){for(let e of r(this,gt).values())e.dispose();r(this,gt).clear();for(let e of this.traverseLevelOrderBFS().reverse())this.destroyEntity(e.uuid)}},S=new WeakMap,H=new WeakMap,Ft=new WeakMap,re=new WeakMap,Q=new WeakMap,gt=new WeakMap,As);async function Ws(e,t,s,i=!0){var o,a;if(s.has(t)){console.warn("importModule: skipping already imported module",t);return}else s.add(t);t.extends&&await Promise.all(t.extends.map(d=>Ws(e,d,s,!1)));let{registry:n}=e;if(t.define)for(let[d,y]of Object.entries(t.define))n.define(d,y);if(t.routes)for(let[d,y]of Object.entries(t.routes))n.appendRoute(d,y);await((a=(o=t.initialize)==null?void 0:o.call(t,{define:(d,y)=>n.define(d,y),kernel:e,registry:n}))!=null?a:Promise.resolve()),i&&e.upgradeEntities()}var Ki=e=>(typeof e=="string"&&(e=new URL(e,globalThis.location.href)),e.toString()),ne,yt,qs,Js,Ks,Ps,Yi=(Ps=class{constructor(e){g(this,yt);g(this,ne,new Set);var t,s;this.kernel=(t=e==null?void 0:e.kernel)!=null?t:new Ji,this.postMessage=(s=e==null?void 0:e.postMessage)!=null?s:self.postMessage.bind(self),V(this.kernel,De,"onMessageToView",this)}route(e){var t;switch(e.data.type){case Zs:C(this,yt,qs).call(this,e.data);break;case Hs:C(this,yt,Js).call(this,e.data);break;case Qs:C(this,yt,Ks).call(this,e.data);break;default:console.warn("[MessageRouter] unknown message",(t=e.data.type)!=null?t:e.data)}}onMessageToView(e){let i=e,{transferables:t}=i,s=Je(i,["transferables"]);this.postMessage({type:De,data:s},{transfer:t})}},ne=new WeakMap,yt=new WeakSet,qs=async function(e){try{let t=await import(Ki(e.importModule));t[ke]?(await Ws(this.kernel,t[ke],r(this,ne)),this.postMessage({type:Se,url:e.importModule})):this.postMessage({type:Se,url:e.importModule,error:\`module has no "\${ke}" export\`})}catch(t){console.error("[MessageRouter] failed to import module",t),this.postMessage({type:Se,url:e.importModule,error:\`\${t}\`})}},Js=function(e){try{this.kernel.run(e)}catch(t){console.error("[MessageRouter] failed to apply change trail",t),this.postMessage({type:Ze,serial:e.serial,error:t.toString()})}e.serial&&this.postMessage({type:Ze,serial:e.serial})},Ks=function(e){console.debug("[MessageRouter] on destroy",e),$(this.kernel,this),r(this,ne).clear(),this.postMessage({type:ti})},Ps),Xi=class{constructor(){this.onmessage=e=>{var t;e.data.type===N?globalThis[R]=e.data.config:((t=this.router)!=null||(this.router=new Yi),this.router.route(e))}}start(){self.addEventListener("message",this.onmessage),self.postMessage({type:_s})}};console.debug("@spearwolf/shadow-objects/WorkerRuntime: hello!");var Zi=new Xi;Zi.start();
21
+ var ht="shaeRequestEntParent",lt="shaeReRequestEntParent",Ns="shae-worker",ct="shae-ent",_s="shae-prop",oe="token",q="forward-custom-events";var ut="local",Ws="no-autostart",dt="no-structured-clone",V="auto-sync";var ft="name",pt="value",gt="type",yt="no-trim";var ke="*",zs=1,Kt=2,Jt=4,H=Symbol.for("eventize"),qr="[eventize]",Xt=s=>s===ke,Bs=s=>{switch(typeof s){case"string":case"symbol":return!0;default:return!1}},Vs=typeof console<"u",Hr=Vs?console[console.warn?"warn":"log"].bind(console,qr):()=>{},Qr=(s,e,t)=>(Object.defineProperty(s,e,{value:t,configurable:!0}),s),Yr=0,Zt=class{static publish(s){s.sort((e,t)=>e.order-t.order).forEach(e=>e.replay())}events=new Map;eventNames=new Set;add(s){Array.isArray(s)?s.forEach(e=>this.eventNames.add(e)):this.eventNames.add(s)}remove(s){Array.isArray(s)?s.forEach(e=>this.eventNames.delete(e)):this.eventNames.delete(s),this.clear(s)}clear(s){Array.isArray(s)?s.forEach(e=>this.events.delete(e)):this.events.delete(s)}retain(s,e){this.eventNames.has(s)&&this.events.set(s,{args:e,order:Yr++})}isKnown(s){return this.eventNames.has(s)}replayTo(s,e,t=[]){if(Xt(s))this.eventNames.forEach(r=>this.replayTo(r,e,t));else if(this.events.has(s)){let{order:r,args:i}=this.events.get(s);t.push({order:r,replay:()=>e.apply(s,i)})}return t}},Qt=(s,e,t,r)=>{if(typeof e=="function"){let i=e.apply(s,t);i!=null&&r?.(i)}},Kr=(s,e,t,r)=>Qt(e,e.emit,[s].concat(t),r),Jr=s=>{switch(typeof s){case"function":return zs;case"string":case"symbol":return Kt;case"object":return Jt}},Xr=0,Zr=()=>++Xr,Us=class{id;eventName;isCatchEmAll;priority;listener;listenerObject;listenerType;callAfterApply;isRemoved;refCount;constructor(s,e,t,r=null){this.id=Zr(),this.eventName=s,this.isCatchEmAll=Xt(s),this.listener=t,this.listenerObject=r,this.priority=e,this.listenerType=Jr(t),this.callAfterApply=void 0,this.isRemoved=!1,this.refCount=1}isEqual(s,e=null){if(s===this)return!0;let t=typeof s;return t==="number"&&s===this.id?!0:e===null&&(t==="string"||t==="symbol")?s===ke||s===this.eventName:this.listener===s&&this.listenerObject===e}apply(s,e,t){if(this.isRemoved)return;let{listener:r,listenerObject:i}=this;switch(this.listenerType){case zs:Qt(i,r,e,t),this.callAfterApply&&this.callAfterApply();break;case Kt:Qt(i,i[r],e,t),this.callAfterApply&&this.callAfterApply();break;case Jt:{let n=r[s];if(this.isCatchEmAll||this.eventName===s){if(typeof n=="function"){let o=n.apply(r,e);o!=null&&t?.(o)}else Kr(s,r,e,t);this.callAfterApply&&this.callAfterApply()}break}}}},ei=(s,e)=>s.priority!==e.priority?e.priority-s.priority:s.id-e.id,ti=(s,e)=>{let t=0,r=s.length;for(;t<r;){let i=t+r>>>1;ei(e,s[i])<0?r=i:t=i+1}return t},$s=s=>s?.slice(0),js=(s,e)=>{let t=s.indexOf(e);t>-1&&s.splice(t,1)},si=s=>s===Jt||s===Kt,Yt=(s,e,t)=>{let r=s.findIndex(i=>i.isEqual(e,t));r>-1&&(s[r].isRemoved=!0,s.splice(r,1))},qt=(s,e,t)=>{let r=[];for(let i of s)(e==null&&i.listenerObject===t||i.eventName===e&&i.listener===t)&&r.push(i);for(let i of r)Yt(s,i,void 0)},Ht=s=>{s&&(s.forEach(e=>{e.isRemoved=!0}),s.length=0)},ri=(s,e)=>s.listenerType===e.listenerType?s.priority===e.priority&&s.eventName===e.eventName&&s.listenerObject===e.listenerObject&&s.listener===e.listener:!1,ii=(s,e)=>{if(si(s.listenerType))return e.find(t=>ri(s,t))},ni=(s,e)=>{let t=ii(s,e);return t?(t.refCount+=1,t):(e.splice(ti(e,s),0,s),s)},oi=class{namedListeners;catchEmAllListeners;getListenersForEventName=s=>{let e=this.namedListeners.get(s);return e||(e=[],this.namedListeners.set(s,e)),e};constructor(){this.namedListeners=new Map,this.catchEmAllListeners=[]}add(s){return ni(s,s.isCatchEmAll?this.catchEmAllListeners:this.getListenersForEventName(s.eventName))}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&&Xt(s)){this.removeAllListeners();return}if(e==null&&Bs(s)){this.removeByEventName(s);return}if(s instanceof Us){this.removeByEventListener(s);return}if(t){this.removeByEventNameAndListenerObject(s,e);return}this.removeByListener(s,e)}removeByEventName(s){Ht(this.namedListeners.get(s)),this.namedListeners.delete(s)}removeByEventListener(s){s.isRemoved||(s.refCount-=1,!(s.refCount>=1)&&(s.isRemoved=!0,this.namedListeners.forEach((e,t)=>{js(e,s),e.length===0&&this.namedListeners.delete(t)}),js(this.catchEmAllListeners,s)))}removeByEventNameAndListenerObject(s,e){this.namedListeners.forEach((t,r)=>{qt(t,s,e),t.length===0&&this.namedListeners.delete(r)})}removeByListener(s,e){let t=typeof s=="object";this.namedListeners.forEach((r,i)=>{Yt(r,s,e),t&&qt(r,void 0,s),r.length===0&&this.namedListeners.delete(i)}),Yt(this.catchEmAllListeners,s,e),t&&qt(this.catchEmAllListeners,void 0,s)}removeAllListeners(){this.namedListeners.forEach(s=>Ht(s)),this.namedListeners.clear(),Ht(this.catchEmAllListeners)}forEach(s,e){let t=$s(this.catchEmAllListeners),r=$s(this.namedListeners.get(s));if(s===ke||!r||r.length===0)t.forEach(e);else if(t.length===0)r.forEach(e);else{let i=r.length,n=t.length,o=0,a=0;for(;o<i||a<n;){if(o<i){let f=r[o];if(a>=n||f.priority>=t[a].priority){e(f),++o;continue}}a<n&&(e(t[a]),++a)}}}getSubscriptionCount(){let s=this.catchEmAllListeners.length;for(let e of this.namedListeners.values())s+=e.length;return s}},ae=s=>!!(s&&s[H]);function $e(s){if(ae(s))return s;let e=new oi,t=new Zt;return Qr(s,H,{keeper:t,store:e}),s}var Q={Max:Number.POSITIVE_INFINITY,Critical:1e9,High:1e6,Normal:0,Low:-1e4,Min:Number.NEGATIVE_INFINITY,AAA:1e9,BB:1e6,C:1e3,Default:0},ai=(s,e,t,r,i,n,o)=>{let a=s.add(new Us(t,r,i,n));return e.replayTo(t,a,o),a},Gs=(s,e,t,r)=>{let i=t.length,n=typeof t[0],o,a,f,m;if(i>=2&&i<=3&&n==="number"?(o=ke,[a,f,m]=t):i>=3&&i<=4&&typeof t[1]=="number"?[o,a,f,m]=t:(a=Q.Default,n==="string"||n==="symbol"||Array.isArray(t[0])?[o,f,m]=t:(o=ke,[f,m]=t)),!f)throw Vs&&Hr("called with insufficient arguments!",t),new Error("subscribeTo() called with insufficient arguments");let P=c=>j=>ai(s,e,j,c,f,m,r);return Array.isArray(o)?o.map(c=>Array.isArray(c)?P(c[1])(c[0]):P(a)(c)):P(a)(o)},hi=(s,e,t)=>{let r=[],i=Gs(s,e,t,r);return Zt.publish(r),i},li=(s,e,t)=>{let r=[];return{listeners:Gs(s,e,t,r),publishRetained:()=>Zt.publish(r)}},Fs=s=>e=>{e.callAfterApply=()=>{s?.()}},qs=(s,e)=>Object.assign(()=>A(s,e),Array.isArray(e)?{listeners:e}:{listener:e}),Is=(s,e,t,r)=>{if(e===ke)throw new Error("emit() must be called with a concrete event name \u2014 '*' is reserved for subscribing to all events and cannot be emitted");let{store:i,keeper:n}=s[H];i.forEach(e,o=>o.apply(e,t,r)),n.retain(e,t)},Hs=(s,e,t,r)=>{Array.isArray(e)?e.forEach(i=>Is(s,i,t,r)):Is(s,e,t,r)};function w(s,...e){let t=$e(s),{store:r,keeper:i}=t[H];return qs(t,hi(r,i,e))}function k(s,...e){let t=$e(s),{store:r,keeper:i}=t[H],{listeners:n,publishRetained:o}=li(r,i,e),a=qs(t,n),f=!1,m=()=>{f||(a(),f=!0)};return Array.isArray(n)?n.forEach(Fs(m)):Fs(m)(n),o(),m}function Ae(s,e){return new Promise(t=>{k(s,e,t)})}function A(s,e,t){if(!ae(s))return;let{store:r,keeper:i}=s[H],n=typeof e,o=t!=null&&(n==="string"||n==="symbol");r.remove(e,t,o),Array.isArray(e)?i.remove(e.filter(a=>typeof a=="string")):Bs(e)&&i.remove(e)}function y(s,e,...t){if(!ae(s))throw new Error("object is not eventized");Hs(s,e,t)}function ci(s,e,...t){if(!ae(s))throw new Error("object is not eventized");let r=[];return Hs(s,e,t,i=>{r.push(i)}),r=r.map(i=>Array.isArray(i)?Promise.all(i):Promise.resolve(i)),r.length>0?Promise.all(r):Promise.resolve()}function ee(s,e){let t=$e(s),{keeper:r}=t[H];r.add(e)}function he(s,e){if(!ae(s))throw new Error("object is not eventized");let{keeper:t}=s[H];t.clear(e)}function ui(s,e){if(!ae(s))throw new Error("object is not eventized");let{keeper:t}=s[H];t.remove(e)}var di=w,fi=k,pi=A,gi=y,yi=ci,vi=Ae,mi=ee,bi=he,wi=ui,O=(()=>{let s=(e={})=>$e(e);return s.inject=(e={})=>(e=$e(e),Object.assign(e,{on:(...t)=>di(e,...t),once:(...t)=>fi(e,...t),onceAsync:t=>vi(e,t),off:(t,r)=>pi(e,t,r),emit:(t,...r)=>gi(e,t,...r),emitAsync:(t,...r)=>yi(e,t,...r),retain:t=>mi(e,t),retainClear:t=>bi(e,t),unretain:t=>wi(e,t)}),e),s.is=ae,s})();var es=s=>ae(s)?s[H]?.store?.getSubscriptionCount()??0:0;var Y=Symbol.for("signal"),Pe=Symbol.for("effect"),Qs=Symbol.for("destroySignal"),Ys=Symbol.for("createEffect"),Ci=Symbol.for("destroyEffect"),Oe="value",ns="mute",os="unmute",le="destroy",je=Symbol.for("recall"),Fe=O(),be=O(),ve=O(),Xs=O(),me=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])])}flush(){this.run(),this.delayedEffects.length=0}run(){let e=new Set,t=[];try{t.push(w(ve,(r,i)=>{i===je&&e.add(r)}),w(Xs,r=>{e.add(r)}));for(let[,r]of this.delayedEffects)for(let i of r)e.has(i)||y(ve,i,i,je)}finally{for(let r of t)r()}}},Zs=()=>me.current;function N(s){let e=me.current;e?e=void 0:e=me.current=new me;try{s()}finally{e&&(me.current=void 0,e.run())}}var ts=0;function Et(s){ts++;try{s()}finally{ts--}}function as(){return ts>0}var mt=class{[Pe];constructor(e){this[Pe]=e,k(e,le,()=>{this[Pe]=void 0})}run=()=>this[Pe]?.run();destroy=()=>{this[Pe]?.destroy(),this[Pe]=void 0}},ss=[],er=()=>ss.at(-1),Ei=(s,e)=>{ss.push(s);try{return e()}finally{ss.pop()}};var Te=new WeakMap,vt=new Set,te=class s{#e=new Set;#t=new Set;#s=new Map;#i=new WeakMap;#r=new Map;#n=new Set;#o=new Set;#a;#l;static get(e){if(e!=null)return e instanceof s?e:Te.get(e)}static findOrCreate(e){if(e==null)throw new Error("Cannot create a group with a null object");return new s(e)}static destroy(e){console.warn("SignalGroup.destroy(obj) is deprecated. Use SignalGroup.delete(obj) instead."),s.delete(e)}static delete(e){Te.get(e)?.clear()}static clear(){for(let e of[...vt])e.clear();vt.clear()}constructor(e){if(e!=null&&e instanceof s)return e;if(e??=this,Te.has(e))return Te.get(e);this.#l=new WeakRef(e),Te.set(e,this),vt.add(this),O(this)}attachGroup(e){if(e===this)throw new Error("Cannot attach a group to itself");return this.#e.add(e),e.#a&&e.#a!==this&&e.#a.#e.delete(e),e.#a=this,e}detachGroup(e){return e!==this&&this.#e.has(e)&&(this.#e.delete(e),e.#a=void 0),e}attachSignal(e){let t=R(e);if(t?.destroyed)throw new Error("Cannot attach a destroyed signal to a group");return t&&this.#t.add(t),e}attachSignalByName(e,t){if(t){this.attachSignal(t);let r=R(t);this.#s.set(e,r),this.#r.has(e)?this.#r.get(e).push(r):this.#r.set(e,[r]),this.#i.has(r)?this.#i.get(r).add(e):this.#i.set(r,new Set([e]))}else this.#s.delete(e);return t}hasSignal(e){return this.#s.has(e)||!!this.#a?.hasSignal(e)}signal(e){return this.#s.get(e)?.object??this.#a?.signal(e)}detachSignal(e){let t=R(e);if(t&&(this.#t.delete(t),this.#i.has(t))){let r=this.#i.get(t);for(let i of r)if(this.#r.has(i)){let n=this.#r.get(i);n.splice(n.indexOf(t),1),n.length===0?(this.#s.delete(i),this.#r.delete(i)):this.#s.get(i)===t&&this.#s.set(i,n.at(-1))}r.clear(),this.#i.delete(t)}return e}attachEffect(e){return this.#n.add(e),e}runEffects(){for(let e of this.#n)e.run();for(let e of this.#e)e.runEffects()}attachLink(e){if(e?.isDestroyed)throw new Error("Cannot attach a destroyed link to a group");return e&&this.#o.add(e),e}detachLink(e){return e&&this.#o.delete(e),e}destroy(){console.warn("SignalGroup#destroy is deprecated. Use SignalGroup#clear instead."),this.clear()}clear(){y(this,le,this),A(this);for(let e of this.#e)e.clear();for(let e of this.#n)e.destroy();for(let e of this.#t)L(e);for(let e of this.#o)e.destroy();if(this.#e.clear(),this.#t.clear(),this.#s.clear(),this.#r.clear(),this.#n.clear(),this.#o.clear(),this.#a?.detachGroup(this),this.#l){let e=this.#l.deref();e!==void 0&&Te.delete(e),this.#l=void 0}vt.delete(this)}},bt=class{#e;#t;constructor(e="id",t=1){this.#e=e,this.#t=t}make(){return Symbol(`${this.#e}${this.#t++}`)}},Si=s=>s!=null&&typeof s.then=="function",rs=class s{static idGen=new bt("ef");static count=0;static maxDepth=256;id;callback;#e;#t=new Set;#s=new Set;#i=new Map;#r=new Set;childEffects=[];curChildEffectSlot=0;autorun=!0;shouldRun=!0;priority;#n;#o=!1;#a=0;constructor(e,t){O(this),this.callback=e;let r;t?.attach!=null&&(r=te.findOrCreate(t.attach),r.attachEffect(this)),this.autorun=t?.autorun??!0,this.#n=t?.dependencies?t.dependencies.map(i=>{switch(typeof i){case"string":case"symbol":return r.signal(i);default:return i}}):void 0,this.id=s.idGen.make(),this.priority=t?.priority??0,w(ve,this.id,je,this),++s.count}hasStaticDeps(){return this.#n!=null&&this.#n.length>0}saveSignalsFromDeps(){for(let e of this.#n)this.whenSignalIsRead(R(e).id)}static createEffect(e,t,r){let i=Array.isArray(t)?t:void 0,n=i?r??{dependencies:i}:t;n&&i&&(n.dependencies=i);let o,a=er();return a!=null?(o=a.getCurrentChildEffect(),o==null&&(o=new s(e,n),a.attachChildEffect(o),y(ve,Ys,o)),a.curChildEffectSlot++):(o=new s(e,n),y(ve,Ys,o)),o.hasStaticDeps()?o.saveSignalsFromDeps():o.autorun&&o.run(),new mt(o)}getCurrentChildEffect(){return this.childEffects[this.curChildEffectSlot]}attachChildEffect(e){this.childEffects.push(e)}run=()=>{if(this.#o||!this.shouldRun)return;let e=Zs();if(e){e.batch(this.id,this.priority);return}if(this.#a>=s.maxDepth)throw new Error(`[signalize] Effect ${this.id.toString()} exceeded maxDepth=${s.maxDepth}: an effect callback recursively re-triggered itself (likely by writing a signal it depends on). Break the cycle, or raise EffectImpl.maxDepth if the recursion is intentional.`);this.#a++;try{if(this.runCleanupCallback(),this.destroyChildEffects(),this.curChildEffectSlot=0,this.shouldRun=!1,y(Xs,this.id,this.id),this.hasStaticDeps())this.#e=this.callback();else{this.#s.clear();for(let t of this.#t)this.#s.add(t);this.#e=Ei(this,this.callback),this.cleanupLostSignals(),this.#r.clear()}}finally{this.#a--}};[je](){this.shouldRun=!0,this.autorun&&this.run()}whenSignalIsRead(e){this.#s.delete(e),this.#t.has(e)||(this.#t.add(e),this.#i.set(e,[w(Fe,e,this.priority,je,this),k(be,e,Qs,this)]))}[Qs](e){!this.#r.has(e)&&this.#t.has(e)&&(this.#r.add(e),this.unsubscribeSignal(e),this.#r.size===this.#t.size&&this.destroy())}cleanupLostSignals(){for(let e of this.#s)this.unsubscribeSignal(e),this.#t.delete(e)}destroyChildEffects(){for(let e of this.childEffects)e.destroy();this.childEffects.length=0}unsubscribeSignal(e){this.#i.has(e)&&(this.#i.get(e).forEach(t=>{t()}),this.#i.delete(e))}runCleanupCallback(){if(this.#e!=null){let e=this.#e;this.#e=void 0,Si(e)?Promise.resolve(e).then(t=>{typeof t=="function"&&t()}):e()}}destroy=()=>{this.#o||(y(this,le,this),A(this),y(ve,Ci,this),this.runCleanupCallback(),this.destroyChildEffects(),A(Fe,this),A(ve,this),A(be,this),this.#o=!0,this.#t.clear(),this.#s.clear(),this.#i.clear(),this.#r.clear(),--s.count)}},S=(...s)=>rs.createEffect(...s);var Ie=new WeakMap,ki=s=>{let e=Ie.get(s);return e||(e={},Ie.set(s,e)),e},U=(s,e)=>Ie.get(s)?.signals?.get(e);var tr=(s,e,t)=>{let r=ki(s);r.signals??=new Map,r.signals.set(e,t)};function ze(...s){for(let e of s)if(Ie.has(e)){let t=Ie.get(e);if(t.signals){for(let r of t.signals.values())L(r);t.signals.clear(),t.signals=void 0}}}function sr(s){let e=R(we(s)?s:U(...s));e!=null&&!e.muted&&!e.destroyed&&is(e.id,e.value,{touch:!0})}function xe(s){return we(s)?R(s)?.value:R(U(...s))?.value}var wt=class{[Y];constructor(e){this[Y]=e}get get(){return this[Y].reader}get set(){return this[Y].writer}get value(){return xe(this.get)}set value(e){this.set(e)}onChange(e){let{destroy:t}=S(()=>e(this.value),[this.get]);return t}get muted(){return this[Y].muted}set muted(e){this[Y].muted=e}touch(){sr(this)}destroy(){L(this)}},Ai=new bt("si"),Ks=!1;function Pi(){Ks||(Ks=!0,console.warn("signalReader(callback) is deprecated and will be removed in a future release. Use Signal.onChange(callback) instead \u2014 it returns an unsubscribe function for proper cleanup."))}function Js(s){as()||er()?.whenSignalIsRead(s)}function is(s,e,t){as()||y(Fe,s,e,t)}var we=s=>s!=null&&s[Y]!=null,Ti=s=>{let e=t=>(s.destroyed||s.beforeRead?.(),t?(Pi(),S(()=>(s.destroyed||Js(s.id),t(s.value)),[e])):s.destroyed||Js(s.id),s.value);return Object.defineProperty(e,Y,{value:s}),e},Ct=class s{static instanceCount=0;id;lazy;get[Y](){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??((a,f)=>a===f);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)){is(this.id,this.#e);return}(t?.touch??!1)&&!this.muted&&!this.destroyed&&is(this.id,this.#e,{touch:!0})};object;constructor(e,t){this.id=Ai.make(),++s.instanceCount,this.lazy=e,this.lazy?(this.value=void 0,this.valueFn=t):(this.value=t,this.valueFn=void 0),this.reader=Ti(this),this.object=new wt(this)}},R=s=>s?.[Y];function p(s=void 0,e){let t;if(we(s))t=R(s);else{let r=e?.lazy??!1;t=new Ct(r,s),t.beforeRead=e?.beforeRead,t.compare=e?.compare}return e?.attach!=null&&te.findOrCreate(e.attach).attachSignal(t),t.object}var L=(...s)=>{for(let e of s){let t=R(e);t!=null&&!t.destroyed&&(t.destroyed=!0,t.beforeRead=void 0,--Ct.instanceCount,y(be,t.id,t.id))}};function St(s,e){let t=p(),r=e?.attach!=null?te.findOrCreate(e.attach):void 0;r!=null&&(e?.name?r.attachSignalByName(e.name,t):r.attachSignal(t));let i=S(()=>{N(()=>{t.set(s())})},{autorun:!(e?.lazy??!1),priority:e?.priority??Q.C,attach:r}),n=R(t);return n.beforeRead=i.run,k(be,n.id,i.destroy),t.get}var At=class{#e=!1;#t;source;lastValue;isDestroyed=!1;constructor(e){O(this),this.source=R(e),this.#t=w(Fe,this.source.id,(t,r)=>{!this.#e&&!this.isDestroyed&&(r?.touch===!0?this.touch():this.write())}),k(be,this.source.id,()=>this.destroy())}attach(e){let t=te.findOrCreate(e);return t.attachLink(this),k(this,le,()=>{t.detachLink(this)}),t}nextValue(){return new Promise((e,t)=>{let r=[],i=()=>r.forEach(n=>{n()});r.push(k(this,Oe,n=>{i(),e(n)}),k(this,le,()=>{i(),t()}))})}async*asyncValues(e){ee(this,Oe);try{let t=0;for(;!this.isDestroyed;)try{let r=await this.nextValue();if(e?.(r,t++))break;yield r}catch{break}}finally{he(this,Oe)}}destroy(){this.isDestroyed||(this.#t?.(),this.#t=void 0,y(this,le,this),he(this,Oe),A(this),this.lastValue=void 0,this.isDestroyed=!0,Object.freeze(this))}get isMuted(){return this.#e}mute(){return!this.isDestroyed&&!this.#e&&(this.#e=!0,y(this,ns,this)),this}unmute(){return!this.isDestroyed&&this.#e&&(this.#e=!1,y(this,os,this)),this}toggleMute(){return this.isDestroyed||(this.#e=!this.#e,y(this,this.#e?ns:os,this)),this.#e}updateValue(e){if(!this.#e&&!this.isDestroyed){let{value:t}=this.source;e(t),y(this,Oe,t),this.lastValue=t}}},hs=class extends At{target;constructor(e,t){super(e),this.target=R(t),k(be,this.target.id,()=>this.destroy()),this.touch()}touch(){return this.updateValue(e=>{this.target.writer(e,{touch:!0})}),this}write(){this.updateValue(e=>{this.target.writer(e)})}},ls=class extends At{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)})}},kt=new Map;function _(s,e,t){let r=R(s),i=R(e),n=i??e,o;if(kt.has(r)){if(o=kt.get(r),o.has(n))return o.get(n)}else o=new Map,kt.set(r,o);let a=i!=null?new hs(s,i):new ls(s,e),f=t?.attach;return f&&a.attach(f),o.set(n,a),k(a,le,()=>{o.delete(n),o.size===0&&kt.delete(r)}),a}var Pt=class s{static fromProps(e,t){let r=new s,i=t?t.map(n=>[n,e[n]]):Object.entries(e);for(let[n,o]of i)r.#e.set(n,p(o));return r}#e=new Map;keys(){return this.#e.keys()}signals(){return this.#e.values()}entries(){return this.#e.entries()}clear(){for(let e of this.#e.values())e.destroy();this.#e.clear()}has(e){return this.#e.has(e)}get(e){if(!this.#e.has(e)){let t=p();return this.#e.set(e,t),t}return this.#e.get(e)}update(e){e.size&&N(()=>{for(let[t,r]of e.entries())this.get(t).set(r)})}updateFromProps(e,t){N(()=>{let r=t?t.map(i=>[i,e[i]]):Object.entries(e);for(let[i,n]of r)this.get(i).set(n)})}};var se=(s=>(s[s.StructuralChanges=1]="StructuralChanges",s[s.ContentUpdates=2]="ContentUpdates",s[s.Removal=3]="Removal",s))(se||{}),E=(s=>(s[s.CreateEntities=1]="CreateEntities",s[s.DestroyEntities=2]="DestroyEntities",s[s.SetParent=3]="SetParent",s[s.UpdateOrder=4]="UpdateOrder",s[s.ChangeProperties=5]="ChangeProperties",s[s.ChangeToken=6]="ChangeToken",s[s.SendEvents=7]="SendEvents",s))(E||{}),Ce=Symbol.for("ShadowEntsGlobalNS"),re="#void",rr="contextLost",ir="configure",nr="changeTrail",or="destroy",ar="loaded",hr="appliedChangeTrail",lr="importedModule",cr="destroyed",Me="messageToView",ur=6e4,dr=6e4,fr=5e3,pr=5e3,cs="shadowObjects";function gr(s,e){s.indexOf(e)===-1&&s.push(e)}function us(s,e){let t=s.indexOf(e);t!==-1&&s.splice(t,1),s.push(e)}function ce(s,e){let t=s.indexOf(e);t!==-1&&s.splice(t,1)}var Ee=s=>typeof s=="string"?s.trim()||Ce:typeof s=="symbol"?s:Ce;var Be="#root",Ve=class{#e;get uuid(){return this.#e}#t=0;constructor(e){this.#e=e}#s=!0;#i=0;#r=0;hasChanges(){return this.#t>0}get isNew(){return this.#s}get isCreated(){return this.#i>0&&this.#i>this.#r}get isDestroyed(){return this.#r>0&&this.#r>=this.#i}#n=re;#o;#a=0;#l=!1;#c;#u;#h;create(e=re,t,r=0,i=!1){this.#t++,this.#i++,this.#c=e,this.#u=t??Be,this.#h=r||void 0,this.#l=i}destroy(){this.#r++,this.#t++}clear(){this.#t=0,this.#s=!1,this.#c=void 0,this.#u=void 0,this.#h=void 0,this.#p.clear(),this.#g.length=0,this.#d.length=0,this.#f.clear()}changeToken(e){e===this.#n?this.#c=void 0:(this.#c=e,this.#t++)}setParent(e){e===this.#o?this.#u=void 0:(this.#u=e??Be,this.#t++)}changeOrder(e){e===this.#a?this.#h=void 0:(this.#h=e,this.#t++)}#y=new Map;#p=new Map;#g=[];changeProperty(e,t,r){let i=this.#y.get(e);r==null&&t!==i||r!=null&&!r(t,i)?(this.#p.set(e,t),us(this.#g,e),this.#t++):(this.#p.delete(e),ce(this.#g,e))}removeProperty(e){let t=this.#y.has(e);this.#p.has(e)?(this.#p.delete(e),t||ce(this.#g,e)):t&&(us(this.#g,e),this.#t++)}#d=[];#f=new Set;createEvent(e,t,r){this.#d.push({type:e,data:t}),r?.forEach(i=>this.#f.add(i)),this.#t++}transferEventsTo(e){this.#d.length>0&&(e.#d.push(...this.#d),this.#d.length=0),this.#f.size>0&&(e.#f=new Set([...e.#f,...this.#f]),this.#f.clear())}buildChangeTrail(e,t){let{isNew:r,isCreated:i,isDestroyed:n}=this;if(!(r&&n))switch(t){case se.StructuralChanges:r?e.push(this.makeCreateEntityChange()):n||(this.#u!==void 0&&!(this.#u===Be&&this.#o===void 0)?e.push(this.makeSetParentChange()):this.#h!==void 0&&this.#h!==this.#a&&e.push(this.makeUpdateOrderChange()),this.#c!==void 0&&this.#c!==this.#n&&e.push(this.makeChangeToken()));break;case se.ContentUpdates:!r&&i&&this.#g.length>0&&e.push(this.makeChangePropertyChange()),this.#d.length>0&&e.push(this.makeEvents());break;case se.Removal:n&&e.push(this.makeDestroyEntityChange());break}}makeEvents(){let e={type:E.SendEvents,uuid:this.#e,events:this.#d.slice(0)};return this.#f.size>0&&(e.transferables=Array.from(this.#f)),e}makeCreateEntityChange(){let e={type:E.CreateEntities,uuid:this.#e,token:this.#c};if(this.#n=this.#c,this.#u!==void 0){let t=this.#u===Be?void 0:this.#u;this.#o=t,t!==void 0&&(e.parentUuid=t)}return this.#p.size>0&&(e.properties=Array.from(this.#p.entries()).filter(([,t])=>t!==void 0),e.properties.forEach(([t,r])=>this.#y.set(t,r))),this.#h!==void 0&&this.#h!==this.#a&&(e.order=this.#a=this.#h),this.#l&&(e.autoDestructionOnParentRemoval=!0),e}makeDestroyEntityChange(){return{type:E.DestroyEntities,uuid:this.#e}}makeSetParentChange(){this.#o=this.#u===Be?void 0:this.#u;let e={type:E.SetParent,uuid:this.#e,parentUuid:this.#o};return this.#h!==void 0&&this.#h!==this.#a&&(e.order=this.#a=this.#h),e}makeUpdateOrderChange(){return this.#a=this.#h??0,{type:E.UpdateOrder,uuid:this.#e,order:this.#a}}makeChangeToken(){return this.#n=this.#c??re,{type:E.ChangeToken,uuid:this.#e,token:this.#n}}makeChangePropertyChange(){let e=this.#g.map(t=>{if(this.#p.has(t)){let r=this.#p.get(t);return this.#y.set(t,r),[t,r]}else return this.#y.delete(t),[t,void 0]});return{type:E.ChangeProperties,uuid:this.#e,properties:e}}};var yr=s=>{if(!(s===void 0||s.length===0))return s.filter(e=>e.length===1||e[1]!==void 0)},ds=(s,e)=>{if(s===e||e===void 0)return s;if(s===void 0)return yr(e);for(let[t,r]of e){let i=s.find(([n])=>n===t);i===void 0?s.push([t,r]):i[1]=r}return yr(s)};var Tt=class{#e=new Map;get[Symbol.iterator](){return this.#e.entries.bind(this.#e)}clear(){this.#e.clear()}isEmpty(){return this.#e.size===0}hasComponentState(e){return this.#e.has(e)}getComponentState(e){return this.#e.get(e)}write(e){for(let t of e)if(t.type===E.CreateEntities)this.createEntity(t);else if(this.#e.has(t.uuid))switch(t.type){case E.DestroyEntities:this.destroyEntity(t);break;case E.SetParent:this.setParent(t);break;case E.UpdateOrder:this.updateOrder(t);break;case E.ChangeToken:this.changeToken(t);break;case E.ChangeProperties:this.changeProperties(t);break}}changeProperties({uuid:e,properties:t}){let r=this.getComponentState(e);r.properties=ds(r.properties,t)}changeToken({uuid:e,token:t}){this.getComponentState(e).token=t||re}updateOrder({uuid:e,order:t}){this.getComponentState(e).order=t??0}setParent({uuid:e,parentUuid:t,order:r}){let i=this.getComponentState(e);i.parentUuid=t,i.order=r??0}destroyEntity({uuid:e}){this.#e.delete(e)}createEntity({uuid:e,token:t,parentUuid:r,order:i,properties:n,autoDestructionOnParentRemoval:o}){this.#e.set(e,{token:t||re,parentUuid:r,order:i??0,properties:ds(void 0,n),...o?{autoDestructionOnParentRemoval:!0}:{}})}};var F=class s{static{this.ReRequestParentRoots="re-request-parent-roots"}static getContextsMap(){return globalThis.__shadowEntsContexts==null&&(globalThis.__shadowEntsContexts=new Map),globalThis.__shadowEntsContexts}static get(e){let t=Ee(e),r=s.getContextsMap();return r.has(t)?r.get(t):new s(t)}#e=new Map;#t=[];#s=new Tt;constructor(e=Ce){let t=Ee(e),r=s.getContextsMap();if(r.has(t))return r.get(t);this.ns=t,r.set(t,this)}addComponent(e){let t;this.#e.has(e.uuid)?(t=this.#e.get(e.uuid),t.component=e,t.children=[]):(t={component:e,children:[],changes:new Ve(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.#n(e,this.#t),this.#o=void 0}hasComponent(e){return this.#e.has(e.uuid)}hasComponents(){return this.#e.size>0}isRootComponent(e){return this.#t.includes(e.uuid)}destroyComponent(e){if(this.hasComponent(e)){let t=this.#e.get(e.uuid);t.children.slice(0).forEach(r=>this.#e.get(r)?.component.removeFromParent()),t.changes.destroy(),this.#o=void 0}}getChildren(e){return this.#e.get(e.uuid)?.children.map(t=>this.#e.get(t).component)??[]}removeFromParent(e,t){if(this.hasComponent(t)){let r=this.#e.get(e),i=this.#e.get(t.uuid),n=i.children.indexOf(e);n!==-1&&(i.children.splice(n,1),r.changes.setParent(void 0)),this.#n(r.component,this.#t),this.#o=void 0}}moveToRoot(e){let t=this.#e.get(e);t&&(t.changes?.setParent(void 0),this.#n(t.component,this.#t)),this.#o=void 0}changeToken(e,t){this.#e.get(e.uuid)?.changes.changeToken(t)}isChildOf(e,t){return this.hasComponent(t)?this.#e.get(t.uuid).children.includes(e.uuid):!1}addToChildren(e,t){let r=this.#e.get(e.uuid);if(r)this.#n(t,r.children),this.#e.get(t.uuid)?.changes.setParent(e.uuid),ce(this.#t,t.uuid),this.#o=void 0;else throw new Error(`the view component ${e.uuid} cannot have a child added to it because the component do not exist!`)}removeSubTree(e){let t=this.#e.get(e);t&&(t.children.slice(0).forEach(r=>this.removeSubTree(r)),this.destroyComponent(t.component),this.#i(e))}setProperty(e,t,r,i){let n=this.#e.get(e.uuid);return n!=null?(i!=null?(n.propIsEqual??=new Map,n.propIsEqual.set(t,i)):n.propIsEqual?.has(t)&&n.propIsEqual.delete(t),n.changes.changeProperty(t,r,i)):!1}removeProperty(e,t){this.#e.get(e.uuid)?.changes.removeProperty(t)}changeOrder(e){if(e.parent){let t=this.#e.get(e.parent.uuid);ce(t.children,e.uuid),this.#n(e,t.children)}else ce(this.#t,e.uuid),this.#n(e,this.#t);this.#e.get(e.uuid)?.changes.changeOrder(e.order),this.#o=void 0}traverseLevelOrderBFS(){return this.#a().map(e=>e.component)}dispatchShadowObjectsEvent(e,t,r,i){this.#e.get(e.uuid)?.changes.createEvent(t,r,i)}broadcastEvent(e,t=void 0){for(let r of this.traverseLevelOrderBFS())r.dispatchEvent(e,t,!1)}dispatchMessage(e,t,r=void 0,i=!1){this.#e.get(e)?.component.dispatchEvent(t,r,i)}dispatchReRequestParentRoots(){for(let e of this.#t)this.dispatchMessage(e,s.ReRequestParentRoots)}buildChangeTrails(e=!0){let t=[];if(!this.hasComponents())return t;let r=this.#r();for(let i of r)i.buildChangeTrail(t,se.StructuralChanges);for(let i of r)i.buildChangeTrail(t,se.ContentUpdates);for(let i of r)i.buildChangeTrail(t,se.Removal),(i.isDestroyed||i.isNew&&!i.isCreated)&&this.#i(i.uuid),e&&i.clear();return this.#s.write(t),t}reCreateChanges(){if(!this.#s.isEmpty()){this.buildChangeTrails(!1);for(let[e,t]of this.#s){let r=this.#e.get(e);if(r){let i=new Ve(e);if(i.create(t.token,t.parentUuid,t.order,t.autoDestructionOnParentRemoval),t.properties)for(let[n,o]of t.properties)i.changeProperty(n,o,r.propIsEqual?.get(n));r.changes.transferEventsTo(i),r.changes.clear(),r.changes=i}}this.#s.clear(),this.broadcastEvent(rr)}}clear(){if(this.#o=void 0,this.#s.clear(),this.#t.slice(0).forEach(e=>this.removeSubTree(e)),this.#t.length!==0)throw new Error("component-context panic: #rootComponents is not empty!");if(this.#e.size!==0)throw new Error("component-context panic: #components is not empty!")}#i(e){this.#e.has(e)&&(this.#e.delete(e),ce(this.#t,e),this.#o=void 0)}#r(){return this.#a().filter(e=>e.changes.hasChanges()).map(e=>e.changes)}#n(e,t){if(t.length===0){t.push(e.uuid);return}if(t.includes(e.uuid))return;let r=t.length,i=new Array(r);if(i[0]=this.#e.get(t[0]).component,e.order<i[0].order){t.unshift(e.uuid);return}if(r===1){t.push(e.uuid);return}let n=r-1;if(i[n]=this.#e.get(t[n]).component,e.order>=i[n].order){t.push(e.uuid);return}if(r===2){t.splice(1,0,e.uuid);return}for(let o=n-1;o>=1;o--)if(i[o]=this.#e.get(t[o]).component,e.order>=i[o].order){t.splice(o+1,0,e.uuid);return}}#o;#a(){if(this.#o)return this.#o;let e=new Map,t=(r,i)=>{let n=this.#e.get(r);if(n!=null){e.has(i)?e.get(i).push(n):e.set(i,[n]);for(let o of n.children)t(o,i+1)}};return this.#t.forEach(r=>t(r,0)),this.#o=Array.from(e.entries()).sort((r,i)=>r[0]-i[0]).flatMap(([,r])=>r),this.#o}};function Ue(s){return function(e,t){let r=s?.name||t.name,i=!!(s?.readAsValue??!1);return{get(){let n=U(this,r);if(n)return i?n.value:n.get()},set(n){U(this,r)?.set(n)},init(n){let o=p(n,s);return tr(this,r,o),te.findOrCreate(this).attachSignalByName(r,o),o.value}}}}var z="ConsoleLogger",I=`${z}Storage`,Oi=!!(globalThis.location?.host?.startsWith("localhost")??!1),qe="localStorage"in globalThis,Ot=Symbol.for(z),vr=!1,mr=s=>{if(typeof s=="boolean")return s;switch(s.toLowerCase()){case"true":case"yes":case"on":return!0;default:return!1}},ps=s=>[qe?z:void 0,...Array.isArray(s)?s:[s]].filter(Boolean).join(".");function fs(s,e=void 0,t){let r=ps(s),i=qe?localStorage.getItem(r):globalThis[I]?.[r];return i!=null?e(i):t}function Ge(s,e){qe?localStorage.setItem(ps(s),e):(globalThis[I]==null&&(globalThis[I]={},console.debug(`${z}: Initialize`,{[I]:globalThis[I]})),globalThis[I][ps(s)]=e)}var D=class s{constructor(e){this.enable=!0,this.namespace=(e||"").trim()||z,vr||(s.loadConfig(),vr=!0);let t=[this.namespace,"enable"];this.enable=fs(t,mr,this.enable),Ge(t,qe?this.enable?"true":"false":this.enable)}static{this.sharedConfig={enable:Oi,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(){qe?(["enable","debug","info","warn"].forEach(e=>{this.sharedConfig[e]=fs(e,mr,this.sharedConfig[e])}),["debug","info","warn","error"].forEach(e=>{this.sharedStyles[e]=fs(["styles",e],void 0,this.sharedStyles[e])}),s.isDebug&&console.debug(`${z}: Load config from localStorage`,s.sharedConfig),globalThis[z]?.[Ot]||(globalThis[z]??={[Ot]:!0,get enable(){return s.sharedConfig.enable},set enable(e){s.sharedConfig.enable=e,Ge("enable",e?"true":"false")},get debug(){return s.sharedConfig.debug},set debug(e){s.sharedConfig.debug=e,Ge("debug",e?"true":"false")},get info(){return s.sharedConfig.info},set info(e){s.sharedConfig.info=e,Ge("info",e?"true":"false")},get warn(){return s.sharedConfig.warn},set warn(e){s.sharedConfig.warn=e,Ge("warn",e?"true":"false")}})):globalThis[I]?.[Ot]||(globalThis[I]={[Ot]:!0,...s.sharedConfig,...globalThis[I]},s.sharedConfig=globalThis[I],s.isDebug&&console.debug(`${z}: Load config from ${I}`,globalThis[I]))}get isEnabled(){return this.enable&&s.sharedConfig.enable}get isDebug(){return this.isEnabled&&s.sharedConfig.debug}get isInfo(){return this.isEnabled&&s.sharedConfig.info}get isWarn(){return this.isEnabled&&s.sharedConfig.warn}debug(...e){this.#e("debug",s.sharedStyles.debug,e)}info(...e){this.#e("info",s.sharedStyles.info,e)}warn(...e){this.#e("warn",s.sharedStyles.warn,e)}error(...e){this.#e("error",s.sharedStyles.error,e)}#e(e,t,r){console[e](`%c${this.namespace}`,t,...r)}};var xi=Object.create,vs=Object.defineProperty,Mi=Object.getOwnPropertyDescriptor,wr=(s,e)=>(e=Symbol[s])?e:Symbol.for("Symbol."+s),Le=s=>{throw TypeError(s)},Ri=(s,e,t)=>e in s?vs(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,br=(s,e)=>vs(s,"name",{value:e,configurable:!0}),Li=s=>[,,,xi(s?.[wr("metadata")]??null)],Cr=["class","method","getter","setter","accessor","field","value","get","set"],He=s=>s!==void 0&&typeof s!="function"?Le("Function expected"):s,Di=(s,e,t,r,i)=>({kind:Cr[s],name:e,metadata:r,addInitializer:n=>t._?Le("Already initialized"):i.push(He(n||null))}),Er=(s,e)=>Ri(e,wr("metadata"),s[3]),xt=(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},Sr=(s,e,t,r,i,n)=>{var o,a,f,m,P,c=e&7,j=!!(e&8),C=!!(e&16),M=c>3?s.length+1:c?j?1:2:0,l=Cr[c+5],h=c>3&&(s[M-1]=[]),d=s[M]||(s[M]=[]),u=c&&(!C&&!j&&(i=i.prototype),c<5&&(c>3||!C)&&Mi(c<4?i:{get[t](){return b(this,n)},set[t](v){return W(this,n,v)}},t));c?C&&c<4&&br(n,(c>2?"set ":c>1?"get ":"")+t):br(i,t);for(var g=r.length-1;g>=0;g--)m=Di(c,t,f={},s[3],d),c&&(m.static=j,m.private=C,P=m.access={has:C?v=>Ni(i,v):v=>t in v},c^3&&(P.get=C?v=>(c^1?b:Mt)(v,i,c^4?n:u.get):v=>v[t]),c>2&&(P.set=C?(v,B)=>W(v,i,B,c^4?n:u.set):(v,B)=>v[t]=B)),a=(0,r[g])(c?c<4?C?n:u[l]:c>4?void 0:{get:u.get,set:u.set}:i,m),f._=1,c^4||a===void 0?He(a)&&(c>4?h.unshift(a):c?C?n=a:u[l]=a:i=a):typeof a!="object"||a===null?Le("Object expected"):(He(o=a.get)&&(u.get=o),He(o=a.set)&&(u.set=o),He(o=a.init)&&h.unshift(o));return c||Er(s,i),u&&vs(i,t,u),C?c^4?n:u:i},ms=(s,e,t)=>e.has(s)||Le("Cannot "+t),Ni=(s,e)=>Object(e)!==e?Le('Cannot use the "in" operator on this value'):s.has(e),b=(s,e,t)=>(ms(s,e,"read from private field"),t?t.call(s):e.get(s)),G=(s,e,t)=>e.has(s)?Le("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,t),W=(s,e,t,r)=>(ms(s,e,"write to private field"),r?r.call(s,t):e.set(s,t),t),Mt=(s,e,t)=>(ms(s,e,"access private method"),t),kr,Ar,T,ie,Re,Qe,Ke,Se,de,bs,ws,Rt,gs,Ye,ys,Pr;Ar=[Ue()],kr=[Ue()];var fe=class ue{constructor(){G(this,Ye),G(this,T),G(this,ie),G(this,Re,!1),G(this,Qe,!1),G(this,Ke,!1),G(this,Se),this.logger=new D("ShadowEnv"),this.ns$=p(),G(this,bs,xt(de,8,this,!1)),xt(de,11,this),G(this,ws,xt(de,12,this,!1)),xt(de,15,this),G(this,Rt,!1),this.ready=async()=>this.isReady?this:Ae(this,ue.ContextCreated),G(this,gs,()=>{b(this,Re)&&Mt(this,Ye,ys).call(this)});let e=this;ee(e,ue.ContextCreated),w(e,ue.ContextLost,Q.AAA,()=>{he(e,ue.ContextCreated)}),S(()=>{if(this.viewReady&&this.proxyReady)return this.view.reCreateChanges(),y(e,ue.ContextCreated,e),b(this,Qe)&&(W(this,Qe,!1),Mt(this,Ye,ys).call(this)),()=>{y(e,ue.ContextLost,e)}},[U(this,"viewReady"),U(this,"proxyReady")])}static get(e){if(e!=null)return globalThis.__shadowEnvs?.get(e)}get isDestroyed(){return b(this,Rt)}get view(){return b(this,T)}set view(e){e!==b(this,T)&&(b(this,T)&&b(this,T).ns&&globalThis.__shadowEnvs&&globalThis.__shadowEnvs.delete(b(this,T).ns),W(this,T,e??void 0),b(this,T)&&b(this,T).ns&&(globalThis.__shadowEnvs??=new Map,globalThis.__shadowEnvs.has(b(this,T).ns)&&globalThis.__shadowEnvs.get(b(this,T).ns)!==this&&this.logger.isWarn&&this.logger.warn("overwrite a namespace already in use",b(this,T).ns,globalThis.__shadowEnvs.get(b(this,T).ns)),globalThis.__shadowEnvs.set(b(this,T).ns,this)),this.viewReady=!!e)}get envProxy(){return b(this,ie)}set envProxy(e){if(e!==b(this,ie)){let t=b(this,ie);W(this,ie,e??void 0),b(this,ie)&&(b(this,ie).onMessageToView=Mt(this,Ye,Pr).bind(this)),t&&t.destroy(),this.proxyReady=!1,e?.start().then(()=>{this.proxyReady=!0}).catch(r=>{this.logger.error("failed to start envProxy",r),this.proxyReady=!1})}}get isReady(){return!!(b(this,T)&&b(this,ie)&&this.proxyReady&&!this.isDestroyed)}sync(){if(!this.isReady){W(this,Qe,!0);return}b(this,Re)||(W(this,Re,!0),queueMicrotask(b(this,gs)))}syncWait(){return W(this,Ke,!0),this.sync(),b(this,Se)?b(this,Se):(W(this,Se,Ae(this,ue.AfterSync).then(e=>(W(this,Se,void 0),e))),b(this,Se))}destroy(){let e=b(this,T)?.ns;this.envProxy?.destroy(),this.envProxy=void 0,this.view=void 0,e&&globalThis.__shadowEnvs.has(e)&&globalThis.__shadowEnvs.get(e)===this&&globalThis.__shadowEnvs.delete(e),ze(this),A(this),W(this,Rt,!0),Object.freeze(this)}};de=Li(null);T=new WeakMap;ie=new WeakMap;Re=new WeakMap;Qe=new WeakMap;Ke=new WeakMap;Se=new WeakMap;bs=new WeakMap;ws=new WeakMap;Rt=new WeakMap;gs=new WeakMap;Ye=new WeakSet;ys=async function(){if(W(this,Re,!1),this.isReady){let s=this.view.buildChangeTrails();if(s.length>0)try{let e=b(this,Ke);W(this,Ke,!1),await this.envProxy.applyChangeTrail(s,e)}catch(e){this.logger.error("failed to apply change trail",e)}finally{y(this,fe.AfterSync,s)}}};Pr=function(s){this.logger.isDebug&&this.logger.debug("onMessageToView",s.type,s.data),this.view?.dispatchMessage(s.uuid,s.type,s.data,s.traverseChildren)};Sr(de,4,"viewReady",Ar,fe,bs);Sr(de,4,"proxyReady",kr,fe,ws);Er(de,fe);fe.AfterSync="afterSync";fe.ContextLost="contextLost";fe.ContextCreated="contextCreated";var K=fe;var x=["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"],_i=()=>{let s=Math.random()*4294967295|0,e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,r=Math.random()*4294967295|0;return(x[s&255]+x[s>>8&255]+x[s>>16&255]+x[s>>24&255]+"-"+x[e&255]+x[e>>8&255]+"-"+x[e>>16&15|64]+x[e>>24&255]+"-"+x[t&63|128]+x[t>>8&255]+"-"+x[t>>16&255]+x[t>>24&255]+x[r&255]+x[r>>8&255]+x[r>>16&255]+x[r>>24&255]).toLowerCase()},Tr=()=>globalThis?.crypto?.randomUUID?.()??_i();var Je=class extends Error{constructor(e){super(e),this.name="ViewComponentError"}},Lt=class s{#e;#t;#s;#i;#r=0;#n;get uuid(){return this.#e}get token(){return this.#t}set token(e){e??=re,e!==this.#t&&(this.#t=e,this.#s?.changeToken(this,e))}get parent(){return this.#i}set parent(e){if(e){if(e.#s!==this.#s)throw new Je("cannot set parent from different context");e.addChild(this)}else this.removeFromParent()}get context(){return this.#s}set context(e){this.#s!=e&&(this.#s&&this.destroy(),this.#s=e,e&&e.addComponent(this))}get order(){return this.#r}set order(e){let t=this.#r;this.#r=e??0,t!==this.#r&&this.#s.changeOrder(this)}get autoDestructionOnParentRemoval(){return this.#n}constructor(e,t){O(this),t instanceof s&&(t={parent:t}),this.#e=t?.uuid??Tr(),this.#t=e,this.#r=t?.order??0,this.#i=t?.parent,this.#n=t?.autoDestructionOnParentRemoval??!1;let r=t?.context??F.get();if(this.#i&&this.#i.#s!==r)throw new Je("cannot set parent from different context");this.context=r}isChildOf(e){return this.#i===e}removeFromParent(){this.#i?(this.#s?.removeFromParent(this.uuid,this.#i),this.#i=void 0):this.#s?.moveToRoot(this.uuid)}addChild(e){if(e.#s!==this.#s)throw new Je("cannot add a child from another context");e.isChildOf(this)||(e.removeFromParent(),e.#i=this,this.#s.addToChildren(this,e))}setProperty(e,t,r){this.#s.setProperty(this,e,t,r)}removeProperty(e){this.#s.removeProperty(this,e)}dispatchShadowObjectsEvent(e,t,r){this.#s.dispatchShadowObjectsEvent(this,e,t,r)}dispatchEvent(e,t,r){if(y(this,e,t),r)for(let i of this.#s.getChildren(this))i.dispatchEvent(e,t,r)}destroy(){this.removeFromParent(),this.#s?.destroyComponent(this),this.#s=void 0}};var Xe=new Set(["on","true","yes","local","1"]);var Or=s=>Ee(s.getAttribute("ns")),et=(s,e)=>{if(s.hasAttribute(e)){let t=s.getAttribute(e)?.trim()?.toLowerCase()||"1";return Xe.has(t)}return!1};var xr=(s,e)=>{e.set(Or(s))},Cs=new Set,Es=!1,Wi=s=>{Cs.add(s),Es||(Es=!0,queueMicrotask(()=>{Es=!1;for(let e of Cs)K.get(e)?.sync();Cs.clear()}))},pe=class extends HTMLElement{constructor(){super(),this.isShaeElement=!0,this.ns$=p(Ce),this.ns$.onChange(e=>{typeof e=="string"&&e.length>0?this.getAttribute("ns")!==e&&this.setAttribute("ns",e):this.removeAttribute("ns")}),xr(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(Ee(e))}attributeChangedCallback(e){e==="ns"&&xr(this,this.ns$)}syncShadowObjects(){Wi(this.ns)}};var Dt=class extends pe{constructor(){super(),this.isShaeEntElement=!0,this.componentContext$=p(),this.viewComponent$=p(),this.token$=p(),this.forwardCustomEvents$=p(!1),this.#n=!0,this.#y=()=>{let e=this.findShadowRootHost();e!=null&&this.dispatchEvent(new CustomEvent(lt,{bubbles:!0,composed:!0,detail:{requester:this,shadowRootHost:e}}))},this.#p=e=>{let t=e.detail?.requester;if(t===this||!t?.isShaeEntElement||t.ns!==this.ns)return;e.detail?.shadowRootHost&&this.#c()},this.#g=e=>{let t=e.detail?.requester;t!==this&&t?.isShaeEntElement&&t.ns===this.ns&&(e.stopPropagation(),t.#h(this))},this.ns$.onChange(e=>{this.componentContext$.set(F.get(e)),this.isConnected&&this.#c()}),this.#d(),this.token$.onChange(e=>{e==null?this.removeAttribute(oe):this.getAttribute(oe)!==e&&this.setAttribute(oe,e)}),this.#f(),this.forwardCustomEvents$.onChange(e=>{if(!e)this.removeAttribute(q);else if(e===!0)this.hasAttribute(q)||this.setAttribute(q,"");else{let t=Array.from(e).join(",");this.getAttribute(q)!==t&&this.setAttribute(q,t)}}),S(()=>{let e=this.viewComponent$.get();if(e){let t=w(e,F.ReRequestParentRoots,()=>this.#l()),r=e.context?.ns;return()=>{t(),e.destroy(),r&&r!==this.ns?K.get(r)?.sync():this.syncShadowObjects()}}}),S(()=>{let e=this.viewComponent$.get();if(!e)return;let t=Object.hasOwn(e,"dispatchEvent")?Object.getPrototypeOf(e).dispatchEvent:e.dispatchEvent,r=this.forwardCustomEvents$.get();if(!r)return;let i=r instanceof Set?r:void 0,n=(o,a,f)=>{t.call(e,o,a,f),o!==F.ReRequestParentRoots&&(i&&!i.has(o)||this.dispatchEvent(new CustomEvent(o,{bubbles:!0,composed:!0,detail:a})))};return Object.defineProperty(e,"dispatchEvent",{value:n,writable:!0,configurable:!0}),()=>{Object.hasOwn(e,"dispatchEvent")&&e.dispatchEvent===n&&delete e.dispatchEvent}}),this.token$.onChange(e=>{let t=this.viewComponent$.value;t&&(t.token=e,this.syncShadowObjects())}),this.style.display="contents"}static{this.observedAttributes=[...pe.observedAttributes,oe,q]}get componentContext(){return this.componentContext$.value}get viewComponent(){return this.viewComponent$.value}get uuid(){return this.viewComponent?.uuid}get token(){return this.token$.value}set token(e){this.token$.set(e)}#e;#t;#s(){this.#t?.();let e=this.componentContext$.onChange(t=>{let r=this.token$.value,i=this.viewComponent$.value;i?i.context=t:t&&(i=new Lt(r,{context:t}),this.viewComponent$.set(i)),this.syncShadowObjects()});this.#t=()=>{e()}}#i(){this.#t?.(),this.#t=void 0}#r;#n;findShadowRootHost(){if(this.#n){this.#n=!1;let e=this;for(;e;){if(e.parentElement==null){let t=e.parentNode;t&&(this.#r=t.host);break}e=e.parentElement}}return this.#r}getParentNodeForObserver(){let e=this.parentNode;return e||(e.host??e)}connectedCallback(){this.#n=!0,this.addEventListener("slotchange",this.#y,{capture:!1,passive:!1}),this.addEventListener(ht,this.#g,{capture:!1,passive:!1}),this.#s(),Et(()=>this.#d()),Et(()=>this.#f()),this.componentContext==null&&this.componentContext$.set(F.get(this.ns)),this.#c(),this.componentContext?.dispatchReRequestParentRoots(),this.#o(),this.syncShadowObjects()}#o(){this.#a();let e=this.getParentNodeForObserver();e&&(this.#e=new MutationObserver((t,r)=>{for(let{target:i,removedNodes:n}of t)if(i===e){for(let o of n)if(o===this){this.#a(),this.onParentChanged(this.getParentNodeForObserver(),e);break}}}),this.#e.observe(e,{childList:!0,subtree:!1,attributes:!1}))}onParentChanged(e,t){this.#h(void 0),this.#c()}#a(){this.#e?.disconnect(),this.#e=void 0}attributeChangedCallback(e){super.attributeChangedCallback(e),e===oe?this.#d():e===q&&this.#f()}disconnectedCallback(){this.#n=!0,this.#a(),this.removeEventListener("slotchange",this.#y,{capture:!1}),this.removeEventListener(ht,this.#g,{capture:!1}),this.#h(void 0),this.componentContext$.set(void 0),this.syncShadowObjects(),this.#i()}#l(){this.isConnected&&(this.#h(void 0),this.#c())}#c(){this.dispatchEvent(new CustomEvent(ht,{bubbles:!0,composed:!0,detail:{requester:this}}))}#u;#h(e){if(this.entParentNode!==e)if(this.entParentNode&&this.entParentNode.removeEventListener(lt,this.#p,{capture:!1}),this.entParentNode=e,this.entParentNode&&this.entParentNode.addEventListener(lt,this.#p,{capture:!1,passive:!1}),this.#u?.(),this.#u=void 0,e){let t=S(()=>{let r=this.viewComponent$.get();if(r){let i=e.viewComponent$.get();r.parent=i&&i.context===r.context?i:void 0,r.parent==null&&queueMicrotask(()=>{this.#c()}),this.syncShadowObjects()}});this.#u=()=>t.destroy()}else{let t=this.viewComponent;t.parent&&(t.parent=void 0,this.syncShadowObjects())}}#y;#p;#g;#d(){if(this.hasAttribute(oe)){let e=this.getAttribute(oe)?.trim()||void 0;this.token$.set(e)}}#f(){if(this.hasAttribute(q)){let e=this.getAttribute(q);!e||e.trim().length===0?this.forwardCustomEvents$.set(!0):this.forwardCustomEvents$.set(new Set(e.split(",").map(t=>t.trim()).filter(t=>t.length>0)))}else this.forwardCustomEvents$.set(!1)}};customElements.define(ct,Dt);var $i=s=>{let e=s.parentElement;for(;e;){if(e.isShaeEntElement)return e;e=e.parentElement}},ji=new Set(["string","text","number","bigint","float","int","integer","hex","hexadecimal","oct","octal","bin","binary","bool","boolean","[]","text[]","string[]","number[]","float[]","int[]","integer[]","hex[]","hexadecimal[]","oct[]","octal[]","bin[]","binary[]","bool[]","boolean[]","int8array","uint8array","uint8clampedarray","int16array","uint16array","int32array","uint32array","float32array","float64array","bigint64array","biguint64array","json"]),Nt=class extends HTMLElement{constructor(){super(),this.isShaeEntElement=!0,this.entNode$=p(),this.viewComponent$=p(),this.name$=p(),this.valueIn$=p(),this.valueOut$=p(),this.type$=p(),this.shouldTrim$=p(!0),this.logger=new D("ShaePropElement"),this.#e=()=>{this.entNode$.set($i(this))},this.#t=()=>{queueMicrotask(()=>{this.isConnected||this.entNode$.set(void 0)})},this.#s=()=>{this.name$.set(this.getAttribute(ft)?.trim()??void 0)},this.#i=()=>{this.valueIn$.set(this.getAttribute(pt))},this.#r=()=>{let e=this.getAttribute(gt)?.trim().toLowerCase();e&&!ji.has(e)&&(this.logger.isWarn&&this.logger.warn(`[${this.name}] unknown type "${e}"`,{shaeProp:this}),e=void 0),this.type$.set(e)},this.#n=()=>{this.shouldTrim$.set(!et(this,yt))},this.entNode$.onChange(e=>{if(e){let t=_(e.viewComponent$,this.viewComponent$);return()=>{t.destroy()}}else this.viewComponent$.set(void 0)}),S(()=>{let e=this.viewComponent$.get();if(e){let t=this.name$.get();if(t){let r=this.valueOut$.get();this.logger.isDebug&&this.logger.debug(`[${this.name}] view-component set-property`,t,r,e.uuid,{viewComponent:e,shaeProp:this}),e.setProperty(t,r),this.isConnected&&this.entNode?.syncShadowObjects()}}}),S(()=>{let e=this.type$.get(),t=this.shouldTrim$.get(),r=this.valueIn$.get();if(t&&typeof r=="string"&&(r=r.trim()),r=r||void 0,r!=null&&typeof r=="string"&&e)switch(e){case"string":case"text":break;case"number":r=Number(r);break;case"bigint":r=BigInt(r);break;case"float":r=parseFloat(r);break;case"int":case"integer":r=parseInt(r,10);break;case"hex":case"hexadecimal":r=parseInt(r,16);break;case"oct":case"octal":r=parseInt(r,8);break;case"bin":case"binary":r=parseInt(r,2);break;case"bool":case"boolean":r=Xe.has(r.toLowerCase());break;case"[]":case"text[]":case"string[]":r=r.split(/\W+/);break;case"number[]":r=r.split(/\s+/).map(i=>Number(i));break;case"float[]":r=r.split(/\s+/).map(i=>parseFloat(i));break;case"int[]":case"integer[]":r=r.split(/\s+/).map(i=>parseInt(i));break;case"hex[]":case"hexadecimal[]":r=r.split(/\W+/).map(i=>parseInt(i,16));break;case"oct[]":case"octal[]":r=r.split(/\W+/).map(i=>parseInt(i,8));break;case"bin[]":case"binary[]":r=r.split(/\W+/).map(i=>parseInt(i,2));break;case"bool[]":case"boolean[]":r=r.split(/\W+/).map(i=>Xe.has(i.toLowerCase()));break;case"int8array":r=new Int8Array(r.split(/\W+/).map(i=>Number(i)));break;case"uint8array":r=new Uint8Array(r.split(/\W+/).map(i=>Number(i)));break;case"uint8clampedarray":r=new Uint8ClampedArray(r.split(/\W+/).map(i=>Number(i)));break;case"int16array":r=new Int16Array(r.split(/\W+/).map(i=>Number(i)));break;case"uint16array":r=new Uint16Array(r.split(/\W+/).map(i=>Number(i)));break;case"int32array":r=new Int32Array(r.split(/\W+/).map(i=>Number(i)));break;case"uint32array":r=new Uint32Array(r.split(/\W+/).map(i=>Number(i)));break;case"float32array":r=new Float32Array(r.split(/\s+/).map(i=>Number(i)));break;case"float64array":r=new Float64Array(r.split(/\s+/).map(i=>Number(i)));break;case"bigint64array":r=new BigInt64Array(r.split(/\W+/).map(i=>BigInt(i)));break;case"biguint64array":r=new BigUint64Array(r.split(/\W+/).map(i=>BigInt(i)));break;case"json":r=JSON.parse(r);break;default:this.logger.isWarn&&this.logger.warn(`[${this.name}] unknown type "${e}"`,{value:r,shaeProp:this})}this.valueOut$.set(r)}),N(()=>{this.#s(),this.#i(),this.#r(),this.#n()}),this.style.display="contents"}static{this.observedAttributes=[ft,pt,gt,yt]}get name(){return this.name$.value}get value(){return this.valueOut$.value}set value(e){this.valueIn$.set(e)}get shouldTrim(){return this.shouldTrim$.value}get entNode(){return this.entNode$.value}set entNode(e){this.entNode$.set(e)}get viewComponent(){return this.viewComponent$.value}connectedCallback(){N(()=>{this.#e(),this.#s(),this.#i(),this.#r(),this.#n()})}attributeChangedCallback(e){switch(e){case ft:this.#s();break;case pt:this.#i();break;case gt:this.#r();break;case yt:this.#n();break}}disconnectedCallback(){this.#t()}#e;#t;#s;#i;#r;#n};customElements.whenDefined(ct).then(()=>customElements.define(_s,Nt));var Ss=null,tt=class s{static{this.OnFrame=Symbol("onFrame")}#e=0;#t=0;constructor(){if(Ss)return Ss;O(this),Ss=this}start(e){if(e!=null)return es(this)===0&&this.#i(),w(this,s.OnFrame,e),this.#t++,()=>{this.stop(e)}}stop(e){A(this,s.OnFrame,e),es(this)===0&&this.#r()}#s=e=>{y(this,s.OnFrame,e),this.#i()};#i(){this.#e=requestAnimationFrame(this.#s)}#r(){cancelAnimationFrame(this.#e),this.#e=0}};async function ks(s,e,t,r=!0){if(t.has(e)){console.warn("importModule: skipping already imported module",e);return}else t.add(e);e.extends&&await Promise.all(e.extends.map(n=>ks(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 _t=s=>s??void 0;var As=Symbol("onCreate"),J=Symbol("onDestroy"),Mr=Symbol("onParentChanged"),Wt=Symbol("onViewEvent");var Fi=Object.create,Ps=Object.defineProperty,Ii=Object.getOwnPropertyDescriptor,Dr=(s,e)=>(e=Symbol[s])?e:Symbol.for("Symbol."+s),Ne=s=>{throw TypeError(s)},zi=(s,e,t)=>e in s?Ps(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,Rr=(s,e)=>Ps(s,"name",{value:e,configurable:!0}),Bi=s=>[,,,Fi(s?.[Dr("metadata")]??null)],Nr=["class","method","getter","setter","accessor","field","value","get","set"],st=s=>s!==void 0&&typeof s!="function"?Ne("Function expected"):s,Vi=(s,e,t,r,i)=>({kind:Nr[s],name:e,metadata:r,addInitializer:n=>t._?Ne("Already initialized"):i.push(st(n||null))}),_r=(s,e)=>zi(e,Dr("metadata"),s[3]),Lr=(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},Ui=(s,e,t,r,i,n)=>{var o,a,f,m,P,c=e&7,j=!!(e&8),C=!!(e&16),M=c>3?s.length+1:c?j?1:2:0,l=Nr[c+5],h=c>3&&(s[M-1]=[]),d=s[M]||(s[M]=[]),u=c&&(!C&&!j&&(i=i.prototype),c<5&&(c>3||!C)&&Ii(c<4?i:{get[t](){return $(this,n)},set[t](v){return it(this,n,v)}},t));c?C&&c<4&&Rr(n,(c>2?"set ":c>1?"get ":"")+t):Rr(i,t);for(var g=r.length-1;g>=0;g--)m=Vi(c,t,f={},s[3],d),c&&(m.static=j,m.private=C,P=m.access={has:C?v=>Gi(i,v):v=>t in v},c^3&&(P.get=C?v=>(c^1?$:ge)(v,i,c^4?n:u.get):v=>v[t]),c>2&&(P.set=C?(v,B)=>it(v,i,B,c^4?n:u.set):(v,B)=>v[t]=B)),a=(0,r[g])(c?c<4?C?n:u[l]:c>4?void 0:{get:u.get,set:u.set}:i,m),f._=1,c^4||a===void 0?st(a)&&(c>4?h.unshift(a):c?C?n=a:u[l]=a:i=a):typeof a!="object"||a===null?Ne("Object expected"):(st(o=a.get)&&(u.get=o),st(o=a.set)&&(u.set=o),st(o=a.init)&&h.unshift(o));return c||_r(s,i),u&&Ps(i,t,u),C?c^4?n:u:i},Ts=(s,e,t)=>e.has(s)||Ne("Cannot "+t),Gi=(s,e)=>Object(e)!==e?Ne('Cannot use the "in" operator on this value'):s.has(e),$=(s,e,t)=>(Ts(s,e,"read from private field"),t?t.call(s):e.get(s)),$t=(s,e,t)=>e.has(s)?Ne("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,t),it=(s,e,t,r)=>(Ts(s,e,"write to private field"),r?r.call(s,t):e.set(s,t),t),ge=(s,e,t)=>(Ts(s,e,"access private method"),t),Wr,X,ye,nt,Os,ne,jt,rt,De="value";Wr=[Ue({name:De})];var Z=class{constructor(e){$t(this,ne),$t(this,X,[]),$t(this,ye),$t(this,Os,Lr(nt,8,this)),Lr(nt,11,this),this.value$=void 0,ee(this,De),this.value$=U(this,De),this.value$.onChange(t=>y(this,De,t)),e&&this.add(...e)}add(...e){return $(this,X).push(...e),ge(this,ne,rt).call(this),ge(this,ne,jt).call(this,e)}unshift(...e){return $(this,X).unshift(...e),ge(this,ne,rt).call(this),ge(this,ne,jt).call(this,e)}remove(...e){ge(this,ne,jt).call(this,e)()}clear(){$(this,X).length=0,ge(this,ne,rt).call(this)}dispose(){this.clear(),$(this,ye)?.destroy(),it(this,ye,void 0),he(this,De),A(this),this.value$.destroy(),ze(this)}};nt=Bi(null);X=new WeakMap;ye=new WeakMap;Os=new WeakMap;ne=new WeakSet;jt=function(s){return()=>{for(let e of s){let t=$(this,X).indexOf(e);t!==-1&&$(this,X).splice(t,1)}ge(this,ne,rt).call(this)}};rt=function(){$(this,ye)?.destroy(),$(this,X).length===0?(it(this,ye,void 0),this.value=void 0):(it(this,ye,S(()=>{let s;for(let e of $(this,X)){let t=xe(e);if(t!=null){s=t;break}}this.value=s},$(this,X))),$(this,ye).run())};Ui(nt,4,"value",Wr,Z,Os);_r(nt,Z);Z.Value=De;var xs=new Map,Ms=!1,qi=(s,e)=>{xs.set(s,e),Ms||(Ms=!0,queueMicrotask(()=>{Ms=!1;let t=Array.from(xs.entries());xs.clear();for(let[r,i]of t)r.set(i)}))},Ft=class{#e;#t;#s=new Pt;#i=new Map;#r=new Map;#n;#o;#a=new Set;#l=[];#c=0;get kernel(){return this.#e}get uuid(){return this.#t}get order(){return this.#c}set order(e){this.#c!==e&&(this.#c=e,this.#n&&this.parent.resortChildren())}get parentUuid(){return this.#n||void 0}set parentUuid(e){if(this.#n!==e){let t=e?this.#e.getEntity(e):void 0;this.removeFromParent(),this.#n=e||void 0,this.#o=t,this.#o&&this.#o.addChild(this),this.#p()}}get parent(){return!this.#o&&this.#n&&(this.#o=this.#e.getEntity(this.#n)),this.#o}set parent(e){this.parentUuid=e?.uuid}get hasParent(){return!!this.#n}get children(){return this.#l}constructor(e,t){this.#e=e,this.#t=t,k(this,J,Q.Min,this)}traverse(e){e(this);for(let t of this.#l)t.traverse(e)}[J](){this.#s.clear(),A(this),this.#h?.();for(let e of this.#r.values())e.cleanup(),e.signal.destroy();this.#r.clear();for(let e of this.#i.values())e.context.set(void 0),e.unsubscribePathValue(),e.unsubscribeFromParent?.(),e.valuePath.dispose(),e.inherited.destroy(),e.provide.destroy(),e.context.destroy();this.#n=void 0,this.#o=void 0,this.#a.clear(),this.#l.length=0}addChild(e){if(this.#l.length===0){this.#a.add(e.uuid),this.#l.push(e);return}if(this.#a.has(e.uuid))throw new Error(`child with uuid: ${e.uuid} already exists! parentUuid: ${this.uuid}`);this.#a.add(e.uuid),this.#l.push(e),this.resortChildren();for(let[,t]of e.#i)e.#v(t)}resortChildren(){this.#l.sort((e,t)=>e.order-t.order)}removeChild(e){this.#a.has(e.uuid)&&(this.#a.delete(e.uuid),this.#l.splice(this.#l.indexOf(e),1))}removeFromParent(){if(this.#o){this.#o.removeChild(this),this.#o=void 0,this.#n=void 0;for(let[,e]of this.#i)e.unsubscribeFromParent&&(e.unsubscribeFromParent(),e.unsubscribeFromParent=void 0);this.#y()}}#u=!1;#h;get autoDestructionOnParentRemoval(){return this.#u}set autoDestructionOnParentRemoval(e){this.#u!==e&&(this.#u=e,this.#p())}#y(){this.#h&&(this.#h(),this.#h=void 0)}#p(){this.#y(),this.#u&&this.#o&&(this.#h=k(this.#o,J,Q.Max,()=>{this.#h=void 0,this.#e.destroyEntity(this.#t)}))}reSubscribeToParentContexts(){for(let[,e]of this.#i)this.#v(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)y(this,Wt,t,r)}dispatchViewEvent(e,t){this.dispatchViewEvents([{type:e,data:t}])}#g(e){return this.#s.get(e)}getPropertyReader(e){return this.#g(e).get}getPropertyWriter(e){return this.#g(e).set}setProperties(e){this.clearTruthyPropsCache(),N(()=>{for(let[t,r]of e)this.setProperty(t,r)})}setProperty(e,t){this.getPropertyWriter(e)(t)}getProperty(e){return xe(this.getPropertyReader(e))}propKeys(){return Array.from(this.#s.keys())}propEntries(){return Array.from(this.#s.entries()).map(([e,t])=>[e,t.value])}#d;clearTruthyPropsCache(){this.#d=void 0}truthyProps(){if(this.#d)return this.#d.size?this.#d:void 0;let e=new Set;for(let[t,r]of this.#s.entries())if(typeof t=="string"){let i=r.value;i!=null&&i!==!1&&i!==""&&e.add(t)}return this.#d=e,e.size?e:void 0}hasContext(e){return this.#i.has(e)}useContext(e){return this.#f(e).context.get}useParentContext(e){return this.#f(e).inherited.get}provideContext(e){return this.#f(e).provide}provideGlobalContext(e){if(this.#r.has(e))return this.#r.get(e).signal;let t=this.#e.findOrCreateRootContext(e),r=p(),i=t.add(r);return this.#r.set(e,{cleanup:i,signal:r}),r}#f(e){if(this.#i.has(e))return this.#i.get(e);let t=p(),r=p(),i=p(),n=new Z([r,t]),o=w(n,Z.Value,f=>{qi(i,f)}),a={name:e,inherited:t,provide:r,context:i,valuePath:n,unsubscribePathValue:o};return this.#i.set(e,a),this.#v(a),a}#v(e){if(e.unsubscribeFromParent?.(),e.unsubscribeFromParent=void 0,this.parent){let t=this.parent.#f(e.name),r=_(t.context,e.inherited);e.unsubscribeFromParent=r.destroy.bind(r)}else{let t=this.#e.findOrCreateRootContext(e.name),r=_(t.value$,e.inherited);e.unsubscribeFromParent=r.destroy.bind(r)}}};var $r=s=>{let e=s.split("@").map(t=>t.trim());if(e.length===2&&e[1])return e[0]?{key:`${e[0]}@${e[1]}`,prop:e[1],token:e[0]}:{key:e[1],prop:e[1]}},It=(s,e)=>{for(let t of e)s.add(t)},Hi=(s,e)=>{if(s!=null)for(let t of s.constructors)e.add(t)},ot=class{static get(e){return e??Qi}#e=new Map;#t=new Map;#s=new Map;define(e,t){this.#e.has(e)?gr(this.#e.get(e).constructors,t):this.#e.set(e,{token:e,constructors:[t]})}appendRoute(e,t){let r=$r(e);r?this.#s.has(r.key)?It(this.#s.get(r.key).routes,t):this.#s.set(r.key,{routes:new Set(t),token:r.token}):this.#t.has(e)?It(this.#t.get(e),t):this.#t.set(e,new Set(t))}clearRoute(e){let t=$r(e);t?this.#s.delete(t.key):this.#t.delete(e)}findTokensByRoute(e,t){let r=new Set([e]),i=this.#t.has(e)?[...this.#t.get(e)]:[];for(;i.length;){let n=i.shift();r.has(n)||(r.add(n),this.#t.has(n)&&i.push(...Array.from(this.#t.get(n)).filter(o=>!r.has(o))))}if(t){for(let o of t)this.#s.has(o)&&It(r,this.#s.get(o).routes);let n;do{n=r.size;for(let o of new Set(r))for(let a of t){let f=`${o}@${a}`;this.#s.has(f)&&It(r,this.#s.get(f).routes)}}while(n!==r.size)}return r}findConstructors(e,t){let r=this.findTokensByRoute(e,t),i=new Set;for(let n of r)Hi(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()}},Qi=new ot;var jr=s=>s.displayName||s.name,Fr=!1,Ir=!1,zr=!1,Br=!1,Vr=!1,zt=class{constructor(e){this.logger=new D("Kernel"),this.#e=new Map,this.#t=new Set,this.#r=!0,this.#n=new Map,O(this),this.registry=ot.get(e)}#e;#t;#s;#i;#r;#n;getEntity(e){let t=this.#e.get(e)?.entity;if(!t)throw new Error(`entity with uuid "${e}" not found!`);return t}hasEntity(e){return this.#e.has(e)}traverseLevelOrderBFS(e=!1){if(this.#r){let t=new Map,r=(i,n)=>{let o=this.getEntity(i);t.has(n)?t.get(n).push(o):t.set(n,[o]);for(let a of o.children)r(a.uuid,n+1)};this.#t.forEach(i=>{r(i,0)}),this.#s=Array.from(t.entries()).sort((i,n)=>i[0]-n[0]).flatMap(([,i])=>i),this.#i=this.#s.slice().reverse(),this.#r=!1}return e?this.#i:this.#s}getEntityGraph(){return Array.from(this.#t).map(e=>this.getEntityGraphNode(e))}getEntityGraphNode(e){if(!this.#e.has(e))return;let{token:t,entity:r}=this.#e.get(e);return{token:t,entity:r,props:Object.fromEntries(r.propEntries()),children:r.children.map(i=>this.getEntityGraphNode(i.uuid))}}upgradeEntities(){let e=new Map;for(let t of this.traverseLevelOrderBFS(!0))e.set(t.uuid,this.updateShadowObjects(t.uuid,2));for(let t of this.traverseLevelOrderBFS(!1))this.updateShadowObjects(t.uuid,1,e.get(t.uuid));e.clear()}run(e){this.logger.isDebug&&this.logger.debug("sync",e),N(()=>{for(let t of e.changeTrail)this.parse(t)})}parse(e){switch(e.type){case E.CreateEntities:this.createEntity(e.uuid,e.token,e.parentUuid,e.order,e.properties,e.autoDestructionOnParentRemoval),this.#r=!0;break;case E.DestroyEntities:this.destroyEntity(e.uuid),this.#r=!0;break;case E.SetParent:this.setParent(e.uuid,e.parentUuid,e.order),this.#r=!0;break;case E.UpdateOrder:this.updateOrder(e.uuid,e.order),this.#r=!0;break;case E.ChangeProperties:this.changeProperties(e.uuid,e.properties);break;case E.ChangeToken:this.changeToken(e.uuid,e.token);break;case E.SendEvents:this.dispatchEventsToEntity(e.uuid,e.events);break}}createEntity(e,t,r,i=0,n,o=!1){let a=new Ft(this,e);a.order=i;let f={token:t,entity:a,usedConstructors:new Map};this.#e.set(e,f),r&&(a.parentUuid=r),a.autoDestructionOnParentRemoval=o,a.hasParent||this.#t.add(e),n&&a.setProperties(n),this.createShadowObjects(e)}destroyEntity(e){if(!this.#e.has(e))return;let{entity:t,usedConstructors:r}=this.#e.get(e),i=[...t.children];for(let n of i)n.autoDestructionOnParentRemoval?this.destroyEntity(n.uuid):(n.removeFromParent(),this.#t.add(n.uuid));t.removeFromParent(),y(t,J,t),r.clear(),this.#e.delete(t.uuid),this.#t.delete(t.uuid),this.#r=!0}setParent(e,t,r=0){let i=this.getEntity(e);if(!(i.parentUuid===t&&i.order===r)){if(t&&!this.#e.has(t))throw new Error(`entity with uuid "${t}" not found!`);i.removeFromParent(),i.order=r,i.parentUuid=t,i.hasParent?this.#t.delete(e):this.#t.add(e),i.reSubscribeToParentContexts(),queueMicrotask(()=>{this.logger.isDebug&&this.logger.debug("entity.onParentChanged",{uuid:e,parentUuid:t,order:r,entity:i}),y(i,Mr,i)})}}updateOrder(e,t){this.getEntity(e).order=t}dispatchEventsToEntity(e,t){this.getEntity(e)?.dispatchViewEvents(t)}changeProperties(e,t){this.getEntity(e).setProperties(t),this.updateShadowObjects(e)}changeToken(e,t){if(!this.#e.has(e))return;let r=this.#e.get(e);r.token!==t&&(r.token=t,this.updateShadowObjects(e))}dispatchMessageToView(e){queueMicrotask(()=>{y(this,Me,e)})}updateShadowObjects(e,t=0,r){let i=this.#e.get(e);r??=new Set(this.registry.findConstructors(i.token,i.entity.truthyProps()));let n=t===0||t===2,o=t===0||t===1;if(n){for(let[a,f]of i.usedConstructors)if(!r.has(a)){i.usedConstructors.delete(a);for(let m of f)this.destroyShadowObject(m,i.entity)}}if(o)for(let a of r)i.usedConstructors.has(a)||this.constructShadowObject(a,i);return r}constructShadowObject(e,t){let r=new Set,i=new Set,n=new Map,o=new Map,a=new Map,f=new Map,m=new Map,P=new Map,c=new Map,j=new Map,C=(l,h)=>{!Vr&&h!=null&&typeof h=="function"&&(console.warn('[shadow-objects] Deprecation Warning: The "isEqual" option of "useProperty()" is now passed as {compare} argument. Please update your code accordingly.'),Vr=!0);let d=typeof h=="function"?{compare:h}:h,u=c.get(l);if(u===void 0){u=p(void 0,d).get,c.set(l,u),j.set(l,d?.compare);let g=_(t.entity.getPropertyReader(l),u);i.add(g.destroy.bind(g))}else d?.compare!=null&&j.get(l)!==d.compare&&console.warn(`[shadow-objects] useProperty("${l}"): the cached signal already exists with a different (or no) {compare} function \u2014 the new options are ignored. Pass options only on the first call per property.`);return u},M=O(new e({entity:t.entity,provideContext(l,h,d){!Fr&&d!=null&&typeof d=="function"&&(console.warn('[shadow-objects] Deprecation Warning: The "isEqual" option of "provideContext()" is now passed as {compare} argument. Please update your code accordingly.'),Fr=!0);let u=typeof d=="function"?{compare:d}:d,g=m.get(l);if(g==null){let v=we(h),B=v?void 0:_t(h);if(g=p(B,u?.compare?{compare:u.compare}:void 0),v){let We=_(h,g);i.add(We.destroy.bind(We))}let _e=_(g,t.entity.provideContext(l));i.add(_e.destroy.bind(_e)),m.set(l,g)}return g!=null&&(u?.clearOnDestroy??!0)&&i.add(()=>{g.set(void 0)}),g},provideGlobalContext(l,h,d){!Ir&&d!=null&&typeof d=="function"&&(console.warn('[shadow-objects] Deprecation Warning: The "isEqual" option of "provideGlobalContext()" is now passed as {compare} argument. Please update your code accordingly.'),Ir=!0);let u=typeof d=="function"?{compare:d}:d,g=P.get(l);if(g==null){let v=we(h),B=v?void 0:_t(h);if(g=p(B,u?.compare?{compare:u.compare}:void 0),v){let We=_(h,g);i.add(We.destroy.bind(We))}let _e=_(g,t.entity.provideGlobalContext(l));i.add(_e.destroy.bind(_e)),P.set(l,g)}return g!=null&&(u?.clearOnDestroy??!0)&&i.add(()=>{g.set(void 0)}),g},useContext(l,h){!zr&&h!=null&&typeof h=="function"&&(console.warn('[shadow-objects] Deprecation Warning: The "isEqual" option of "useContext()" is now passed as {compare} argument. Please update your code accordingly.'),zr=!0);let d=typeof h=="function"?{compare:h}:h,u=n.get(l);if(u===void 0){u=p(void 0,d).get,n.set(l,u),o.set(l,d?.compare);let g=_(t.entity.useContext(l),u);i.add(g.destroy.bind(g))}else d?.compare!=null&&o.get(l)!==d.compare&&console.warn(`[shadow-objects] useContext("${String(l)}"): the cached signal already exists with a different (or no) {compare} function \u2014 the new options are ignored. Pass options only on the first call per context.`);return u},useParentContext(l,h){!Br&&h!=null&&typeof h=="function"&&(console.warn('[shadow-objects] Deprecation Warning: The "isEqual" option of "useParentContext()" is now passed as {compare} argument. Please update your code accordingly.'),Br=!0);let d=typeof h=="function"?{compare:h}:h,u=a.get(l);if(u===void 0){u=p(void 0,d).get,a.set(l,u),f.set(l,d?.compare);let g=_(t.entity.useParentContext(l),u);i.add(g.destroy.bind(g))}else d?.compare!=null&&f.get(l)!==d.compare&&console.warn(`[shadow-objects] useParentContext("${String(l)}"): the cached signal already exists with a different (or no) {compare} function \u2014 the new options are ignored. Pass options only on the first call per parent context.`);return u},dispatchMessageToView(l,h,d,u=!1){t.entity.dispatchMessageToView(l,h,d,u)},useProperty:C,useProperties(l){let h={};for(let d in l)Object.hasOwn(l,d)&&(h[d]=C(l[d]));return h},createResource(l,h){let d=p(),u=S(()=>{let g=_t(l());return d.set(g),g!==void 0&&h?()=>{h(g),d.set(void 0)}:()=>{d.set(void 0)}});return i.add(()=>{u.destroy(),d.set(void 0),L(d)}),d},createEffect(...l){let h=S(...l);return i.add(h.destroy),h},createSignal(...l){let h=p(...l);return i.add(()=>{L(h)}),h},createMemo(...l){let h=St(...l);return i.add(()=>{L(h)}),h},on(...l){let[h]=l;if(typeof h=="string"||typeof h=="symbol"||Array.isArray(h)){let u=w(t.entity,...l);return i.add(u),u}let d=w(...l);return i.add(d),Object.assign(()=>{i.delete(d),d()},d)},once(...l){let[h]=l;if(typeof h=="string"||typeof h=="symbol"||Array.isArray(h)){let u=k(t.entity,...l);return i.add(u),u}let d=k(...l);return i.add(d),Object.assign(()=>{i.delete(d),d()},d)},emit(...l){let[h]=l;typeof h=="string"||typeof h=="symbol"||Array.isArray(h)?y(t.entity,...l):y(...l)},onViewEvent(l){let h=w(t.entity,Wt,(d,u)=>{l(d,u)});i.add(h)},onDestroy(l){r.add(l)}}));return this.logger.isInfo&&this.logger.info("create shadow-object",jr(e),{shadowObject:M,entity:t.entity}),k(t.entity,J,Q.Low,()=>{this.logger.isInfo&&this.logger.info("destroy shadow-object",jr(e),{shadowObject:M,entity:t.entity});for(let h of r)h();for(let h of i)h();for(let h of n.values())L(h);for(let h of a.values())L(h);for(let h of c.values())L(h);for(let h of m.values())L(h);for(let h of P.values())L(h);r.clear(),i.clear(),n.clear(),a.clear(),c.clear(),m.clear(),P.clear();let l=t.usedConstructors.get(e);l&&(l.delete(M),l.size===0&&t.usedConstructors.delete(e))}),t.usedConstructors.has(e)?t.usedConstructors.get(e).add(M):t.usedConstructors.set(e,new Set([M])),this.attachShadowObject(M,t.entity),M}createShadowObjects(e){let t=this.#e.get(e);this.registry.findConstructors(t.token,t.entity.truthyProps())?.forEach(r=>{this.constructShadowObject(r,t)})}findShadowObjects(e){if(!this.#e.has(e))return[];let{usedConstructors:t}=this.#e.get(e);return Array.from(new Set(Array.from(t.values()).flatMap(r=>Array.from(r))))}attachShadowObject(e,t){w(t,e),typeof e[As]=="function"&&e[As](t)}destroyShadowObject(e,t){typeof e[J]=="function"&&e[J](t),y(e,J,t),A(t,e)}findOrCreateRootContext(e){let t=this.#n.get(e);return t||(t=new Z,this.#n.set(e,t)),t}destroy(){for(let e of this.#n.values())e.dispose();this.#n.clear();for(let e of this.traverseLevelOrderBFS().reverse())this.destroyEntity(e.uuid)}};var Bt=s=>(typeof s=="string"&&(s=new URL(s,globalThis.location.href)),s.toString());function Ur(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 Vt=class{constructor(e){this.#e=new Set,this.isLocalEnv=!0,this.disableStructuredClone=!1,this.kernel=new zt(e),w(this.kernel,Me,t=>{if(this.onMessageToView!=null){let{type:r,uuid:i,traverseChildren:n}=t,o=structuredClone(t.data,{transfer:t.transferables});this.onMessageToView({type:r,uuid:i,data:o,traverseChildren:n})}})}#e;get registry(){return this.kernel.registry}start(){return Promise.resolve()}applyChangeTrail(e,t){let r={changeTrail:this.disableStructuredClone?e:Ur(e)},i;try{this.kernel.run(r),i=Promise.resolve()}catch(n){i=Promise.reject(n)}return i}async importScript(e){let t=await import(Bt(e));t[cs]&&await this.importModule(t[cs])}async importModule(e){return ks(this.kernel,e,this.#e)}destroy(){this.kernel.destroy(),this.registry.clear(),this.#e.clear()}};function Rs(s){let e=new Blob([s],{type:"text/javascript"}),t=URL.createObjectURL(e),r=new Worker(t);return URL.revokeObjectURL(t),r}function Ls(){return Rs(`var Vr=Object.defineProperty;var Ot=Object.getOwnPropertySymbols;var Fs=Object.prototype.hasOwnProperty,Gs=Object.prototype.propertyIsEnumerable;var $r=(s,e)=>(e=Symbol[s])?e:Symbol.for("Symbol."+s),Ns=s=>{throw TypeError(s)};var ts=(s,e,t)=>e in s?Vr(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,ss=(s,e)=>{for(var t in e||(e={}))Fs.call(e,t)&&ts(s,t,e[t]);if(Ot)for(var t of Ot(e))Gs.call(e,t)&&ts(s,t,e[t]);return s};var Vs=(s,e)=>{var t={};for(var r in s)Fs.call(s,r)&&e.indexOf(r)<0&&(t[r]=s[r]);if(s!=null&&Ot)for(var r of Ot(s))e.indexOf(r)<0&&Gs.call(s,r)&&(t[r]=s[r]);return t};var y=(s,e,t)=>ts(s,typeof e!="symbol"?e+"":e,t),rs=(s,e,t)=>e.has(s)||Ns("Cannot "+t);var n=(s,e,t)=>(rs(s,e,"read from private field"),t?t.call(s):e.get(s)),d=(s,e,t)=>e.has(s)?Ns("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,t),g=(s,e,t,r)=>(rs(s,e,"write to private field"),r?r.call(s,t):e.set(s,t),t),C=(s,e,t)=>(rs(s,e,"access private method"),t);var Mt=(s,e,t,r)=>({set _(i){g(s,e,i,t)},get _(){return n(s,e,r)}});var is=function(s,e){this[0]=s,this[1]=e},$s=(s,e,t)=>{var r=(c,p,w,A)=>{try{var v=t[c](p),G=(p=v.value)instanceof is,R=v.done;Promise.resolve(G?p[0]:p).then(E=>G?r(c==="return"?c:"next",p[1]?{done:E.done,value:E.value}:E,w,A):w({value:E,done:R})).catch(E=>r("throw",E,w,A))}catch(E){A(E)}},i=(c,p,w,A)=>a[c]=v=>(p=new Promise((G,R,E)=>(E=()=>r(c,v,G,R),o?o.then(E):E())),A=()=>o===w&&(o=0),o=w=p.then(A,A),p),o,a={};return t=t.apply(s,e),a[$r("asyncIterator")]=()=>a,i("next"),i("throw"),i("return"),a};var le=(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))(le||{});var js="configure",Us="changeTrail",_s="destroy",Is="loaded",ns="appliedChangeTrail",Lt="importedModule",Ws="destroyed",ht="messageToView";var Rt="shadowObjects";var N="ConsoleLogger",z=\`\${N}Storage\`,Hs,Ks,Js,jr=!!((Js=(Ks=(Hs=globalThis.location)==null?void 0:Hs.host)==null?void 0:Ks.startsWith("localhost"))!=null&&Js),ft="localStorage"in globalThis,Tt=Symbol.for(N),Qs=!1,qs=s=>{if(typeof s=="boolean")return s;switch(s.toLowerCase()){case"true":case"yes":case"on":return!0;default:return!1}},as=s=>[ft?N:void 0,...Array.isArray(s)?s:[s]].filter(Boolean).join(".");function os(s,e=void 0,t){var o;let r=as(s),i=ft?localStorage.getItem(r):(o=globalThis[z])==null?void 0:o[r];return i!=null?e(i):t}function lt(s,e){ft?localStorage.setItem(as(s),e):(globalThis[z]==null&&(globalThis[z]={},console.debug(\`\${N}: Initialize\`,{[z]:globalThis[z]})),globalThis[z][as(s)]=e)}var ze,ut,m=class m{constructor(e){d(this,ze);this.enable=!0,this.namespace=(e||"").trim()||N,Qs||(m.loadConfig(),Qs=!0);let t=[this.namespace,"enable"];this.enable=os(t,qs,this.enable),lt(t,ft?this.enable?"true":"false":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;ft?(["enable","debug","info","warn"].forEach(i=>{this.sharedConfig[i]=os(i,qs,this.sharedConfig[i])}),["debug","info","warn","error"].forEach(i=>{this.sharedStyles[i]=os(["styles",i],void 0,this.sharedStyles[i])}),m.isDebug&&console.debug(\`\${N}: Load config from localStorage\`,m.sharedConfig),(e=globalThis[N])!=null&&e[Tt]||(t=globalThis[N])!=null||(globalThis[N]={[Tt]:!0,get enable(){return m.sharedConfig.enable},set enable(i){m.sharedConfig.enable=i,lt("enable",i?"true":"false")},get debug(){return m.sharedConfig.debug},set debug(i){m.sharedConfig.debug=i,lt("debug",i?"true":"false")},get info(){return m.sharedConfig.info},set info(i){m.sharedConfig.info=i,lt("info",i?"true":"false")},get warn(){return m.sharedConfig.warn},set warn(i){m.sharedConfig.warn=i,lt("warn",i?"true":"false")}})):(r=globalThis[z])!=null&&r[Tt]||(globalThis[z]=ss(ss({[Tt]:!0},m.sharedConfig),globalThis[z]),m.sharedConfig=globalThis[z],m.isDebug&&console.debug(\`\${N}: Load config from \${z}\`,globalThis[z]))}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){C(this,ze,ut).call(this,"debug",m.sharedStyles.debug,e)}info(...e){C(this,ze,ut).call(this,"info",m.sharedStyles.info,e)}warn(...e){C(this,ze,ut).call(this,"warn",m.sharedStyles.warn,e)}error(...e){C(this,ze,ut).call(this,"error",m.sharedStyles.error,e)}};ze=new WeakSet,ut=function(e,t,r){console[e](\`%c\${this.namespace}\`,t,...r)},m.sharedConfig={enable:jr,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 Dt=m;var qe="*",tr=1,fs=2,ds=4,ue=Symbol.for("eventize"),Ur="[eventize]",gs=s=>s===qe,sr=s=>{switch(typeof s){case"string":case"symbol":return!0;default:return!1}},rr=typeof console!="undefined",_r=rr?console[console.warn?"warn":"log"].bind(console,Ur):()=>{},Ir=(s,e,t)=>(Object.defineProperty(s,e,{value:t,configurable:!0}),s),Wr=0,ys=class{constructor(){y(this,"events",new Map);y(this,"eventNames",new Set)}static publish(s){s.sort((e,t)=>e.order-t.order).forEach(e=>e.replay())}add(s){Array.isArray(s)?s.forEach(e=>this.eventNames.add(e)):this.eventNames.add(s)}remove(s){Array.isArray(s)?s.forEach(e=>this.eventNames.delete(e)):this.eventNames.delete(s),this.clear(s)}clear(s){Array.isArray(s)?s.forEach(e=>this.events.delete(e)):this.events.delete(s)}retain(s,e){this.eventNames.has(s)&&this.events.set(s,{args:e,order:Wr++})}isKnown(s){return this.eventNames.has(s)}replayTo(s,e,t=[]){if(gs(s))this.eventNames.forEach(r=>this.replayTo(r,e,t));else if(this.events.has(s)){let{order:r,args:i}=this.events.get(s);t.push({order:r,replay:()=>e.apply(s,i)})}return t}},ls=(s,e,t,r)=>{if(typeof e=="function"){let i=e.apply(s,t);i!=null&&(r==null||r(i))}},Qr=(s,e,t,r)=>ls(e,e.emit,[s].concat(t),r),qr=s=>{switch(typeof s){case"function":return tr;case"string":case"symbol":return fs;case"object":return ds}},Hr=0,Kr=()=>++Hr,ir=class{constructor(s,e,t,r=null){y(this,"id");y(this,"eventName");y(this,"isCatchEmAll");y(this,"priority");y(this,"listener");y(this,"listenerObject");y(this,"listenerType");y(this,"callAfterApply");y(this,"isRemoved");y(this,"refCount");this.id=Kr(),this.eventName=s,this.isCatchEmAll=gs(s),this.listener=t,this.listenerObject=r,this.priority=e,this.listenerType=qr(t),this.callAfterApply=void 0,this.isRemoved=!1,this.refCount=1}isEqual(s,e=null){if(s===this)return!0;let t=typeof s;return t==="number"&&s===this.id?!0:e===null&&(t==="string"||t==="symbol")?s===qe||s===this.eventName:this.listener===s&&this.listenerObject===e}apply(s,e,t){if(this.isRemoved)return;let{listener:r,listenerObject:i}=this;switch(this.listenerType){case tr:ls(i,r,e,t),this.callAfterApply&&this.callAfterApply();break;case fs:ls(i,i[r],e,t),this.callAfterApply&&this.callAfterApply();break;case ds:{let o=r[s];if(this.isCatchEmAll||this.eventName===s){if(typeof o=="function"){let a=o.apply(r,e);a!=null&&(t==null||t(a))}else Qr(s,r,e,t);this.callAfterApply&&this.callAfterApply()}break}}}},Jr=(s,e)=>s.priority!==e.priority?e.priority-s.priority:s.id-e.id,Yr=(s,e)=>{let t=0,r=s.length;for(;t<r;){let i=t+r>>>1;Jr(e,s[i])<0?r=i:t=i+1}return t},Ys=s=>s==null?void 0:s.slice(0),Xs=(s,e)=>{let t=s.indexOf(e);t>-1&&s.splice(t,1)},Xr=s=>s===ds||s===fs,us=(s,e,t)=>{let r=s.findIndex(i=>i.isEqual(e,t));r>-1&&(s[r].isRemoved=!0,s.splice(r,1))},cs=(s,e,t)=>{let r=[];for(let i of s)(e==null&&i.listenerObject===t||i.eventName===e&&i.listener===t)&&r.push(i);for(let i of r)us(s,i,void 0)},hs=s=>{s&&(s.forEach(e=>{e.isRemoved=!0}),s.length=0)},Zr=(s,e)=>s.listenerType===e.listenerType?s.priority===e.priority&&s.eventName===e.eventName&&s.listenerObject===e.listenerObject&&s.listener===e.listener:!1,ei=(s,e)=>{if(Xr(s.listenerType))return e.find(t=>Zr(s,t))},ti=(s,e)=>{let t=ei(s,e);return t?(t.refCount+=1,t):(e.splice(Yr(e,s),0,s),s)},si=class{constructor(){y(this,"namedListeners");y(this,"catchEmAllListeners");y(this,"getListenersForEventName",s=>{let e=this.namedListeners.get(s);return e||(e=[],this.namedListeners.set(s,e)),e});this.namedListeners=new Map,this.catchEmAllListeners=[]}add(s){return ti(s,s.isCatchEmAll?this.catchEmAllListeners:this.getListenersForEventName(s.eventName))}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&&gs(s)){this.removeAllListeners();return}if(e==null&&sr(s)){this.removeByEventName(s);return}if(s instanceof ir){this.removeByEventListener(s);return}if(t){this.removeByEventNameAndListenerObject(s,e);return}this.removeByListener(s,e)}removeByEventName(s){hs(this.namedListeners.get(s)),this.namedListeners.delete(s)}removeByEventListener(s){s.isRemoved||(s.refCount-=1,!(s.refCount>=1)&&(s.isRemoved=!0,this.namedListeners.forEach((e,t)=>{Xs(e,s),e.length===0&&this.namedListeners.delete(t)}),Xs(this.catchEmAllListeners,s)))}removeByEventNameAndListenerObject(s,e){this.namedListeners.forEach((t,r)=>{cs(t,s,e),t.length===0&&this.namedListeners.delete(r)})}removeByListener(s,e){let t=typeof s=="object";this.namedListeners.forEach((r,i)=>{us(r,s,e),t&&cs(r,void 0,s),r.length===0&&this.namedListeners.delete(i)}),us(this.catchEmAllListeners,s,e),t&&cs(this.catchEmAllListeners,void 0,s)}removeAllListeners(){this.namedListeners.forEach(s=>hs(s)),this.namedListeners.clear(),hs(this.catchEmAllListeners)}forEach(s,e){let t=Ys(this.catchEmAllListeners),r=Ys(this.namedListeners.get(s));if(s===qe||!r||r.length===0)t.forEach(e);else if(t.length===0)r.forEach(e);else{let i=r.length,o=t.length,a=0,c=0;for(;a<i||c<o;){if(a<i){let p=r[a];if(c>=o||p.priority>=t[c].priority){e(p),++a;continue}}c<o&&(e(t[c]),++c)}}}getSubscriptionCount(){let s=this.catchEmAllListeners.length;for(let e of this.namedListeners.values())s+=e.length;return s}},Fe=s=>!!(s&&s[ue]);function dt(s){if(Fe(s))return s;let e=new si,t=new ys;return Ir(s,ue,{keeper:t,store:e}),s}var be={Max:Number.POSITIVE_INFINITY,Critical:1e9,High:1e6,Normal:0,Low:-1e4,Min:Number.NEGATIVE_INFINITY,AAA:1e9,BB:1e6,C:1e3,Default:0},ri=(s,e,t,r,i,o,a)=>{let c=s.add(new ir(t,r,i,o));return e.replayTo(t,c,a),c},nr=(s,e,t,r)=>{let i=t.length,o=typeof t[0],a,c,p,w;if(i>=2&&i<=3&&o==="number"?(a=qe,[c,p,w]=t):i>=3&&i<=4&&typeof t[1]=="number"?[a,c,p,w]=t:(c=be.Default,o==="string"||o==="symbol"||Array.isArray(t[0])?[a,p,w]=t:(a=qe,[p,w]=t)),!p)throw rr&&_r("called with insufficient arguments!",t),new Error("subscribeTo() called with insufficient arguments");let A=v=>G=>ri(s,e,G,v,p,w,r);return Array.isArray(a)?a.map(v=>Array.isArray(v)?A(v[1])(v[0]):A(c)(v)):A(c)(a)},ii=(s,e,t)=>{let r=[],i=nr(s,e,t,r);return ys.publish(r),i},ni=(s,e,t)=>{let r=[];return{listeners:nr(s,e,t,r),publishRetained:()=>ys.publish(r)}},Zs=s=>e=>{e.callAfterApply=()=>{s==null||s()}},or=(s,e)=>Object.assign(()=>L(s,e),Array.isArray(e)?{listeners:e}:{listener:e}),er=(s,e,t,r)=>{if(e===qe)throw new Error("emit() must be called with a concrete event name \\u2014 '*' is reserved for subscribing to all events and cannot be emitted");let{store:i,keeper:o}=s[ue];i.forEach(e,a=>a.apply(e,t,r)),o.retain(e,t)},ar=(s,e,t,r)=>{Array.isArray(e)?e.forEach(i=>er(s,i,t,r)):er(s,e,t,r)};function T(s,...e){let t=dt(s),{store:r,keeper:i}=t[ue];return or(t,ii(r,i,e))}function k(s,...e){let t=dt(s),{store:r,keeper:i}=t[ue],{listeners:o,publishRetained:a}=ni(r,i,e),c=or(t,o),p=!1,w=()=>{p||(c(),p=!0)};return Array.isArray(o)?o.forEach(Zs(w)):Zs(w)(o),a(),w}function oi(s,e){return new Promise(t=>{k(s,e,t)})}function L(s,e,t){if(!Fe(s))return;let{store:r,keeper:i}=s[ue],o=typeof e,a=t!=null&&(o==="string"||o==="symbol");r.remove(e,t,a),Array.isArray(e)?i.remove(e.filter(c=>typeof c=="string")):sr(e)&&i.remove(e)}function S(s,e,...t){if(!Fe(s))throw new Error("object is not eventized");ar(s,e,t)}function ai(s,e,...t){if(!Fe(s))throw new Error("object is not eventized");let r=[];return ar(s,e,t,i=>{r.push(i)}),r=r.map(i=>Array.isArray(i)?Promise.all(i):Promise.resolve(i)),r.length>0?Promise.all(r):Promise.resolve()}function gt(s,e){let t=dt(s),{keeper:r}=t[ue];r.add(e)}function He(s,e){if(!Fe(s))throw new Error("object is not eventized");let{keeper:t}=s[ue];t.clear(e)}function ci(s,e){if(!Fe(s))throw new Error("object is not eventized");let{keeper:t}=s[ue];t.remove(e)}var hi=T,li=k,ui=L,fi=S,di=ai,gi=oi,yi=gt,pi=He,vi=ci,_=(()=>{let s=(e={})=>dt(e);return s.inject=(e={})=>(e=dt(e),Object.assign(e,{on:(...t)=>hi(e,...t),once:(...t)=>li(e,...t),onceAsync:t=>gi(e,t),off:(t,r)=>ui(e,t,r),emit:(t,...r)=>fi(e,t,...r),emitAsync:(t,...r)=>di(e,t,...r),retain:t=>yi(e,t),retainClear:t=>pi(e,t),unretain:t=>vi(e,t)}),e),s.is=Fe,s})();async function ps(s,e,t,r=!0){var o,a;if(t.has(e)){console.warn("importModule: skipping already imported module",e);return}else t.add(e);e.extends&&await Promise.all(e.extends.map(c=>ps(s,c,t,!1)));let{registry:i}=s;if(e.define)for(let[c,p]of Object.entries(e.define))i.define(c,p);if(e.routes)for(let[c,p]of Object.entries(e.routes))i.appendRoute(c,p);await((a=(o=e.initialize)==null?void 0:o.call(e,{define:(c,p)=>i.define(c,p),kernel:s,registry:i}))!=null?a:Promise.resolve()),r&&s.upgradeEntities()}var ne=Symbol.for("signal"),Ke=Symbol.for("effect"),cr=Symbol.for("destroySignal"),hr=Symbol.for("createEffect"),mi=Symbol.for("destroyEffect"),et="value",ws="mute",Ss="unmute",ke="destroy",yt=Symbol.for("recall"),pt=_(),_e=_(),Ge=_(),gr=_(),Ae=class{constructor(){y(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])])}flush(){this.run(),this.delayedEffects.length=0}run(){let e=new Set,t=[];try{t.push(T(Ge,(r,i)=>{i===yt&&e.add(r)}),T(gr,r=>{e.add(r)}));for(let[,r]of this.delayedEffects)for(let i of r)e.has(i)||S(Ge,i,i,yt)}finally{for(let r of t)r()}}};y(Ae,"current");var yr=()=>Ae.current;function Pe(s){let e=Ae.current;e?e=void 0:e=Ae.current=new Ae;try{s()}finally{e&&(Ae.current=void 0,e.run())}}var bi=0;function Es(){return bi>0}var fr;fr=Ke;var zt=class{constructor(e){y(this,fr);y(this,"run",()=>{var e;return(e=this[Ke])==null?void 0:e.run()});y(this,"destroy",()=>{var e;(e=this[Ke])==null||e.destroy(),this[Ke]=void 0});this[Ke]=e,k(e,ke,()=>{this[Ke]=void 0})}},vs=[],pr=()=>vs.at(-1),wi=(s,e)=>{vs.push(s);try{return e()}finally{vs.pop()}};var Je=new WeakMap,Bt=new Set,se,Ne,H,fe,re,Ve,$e,K,je,Ye=class Ye{constructor(e){d(this,se,new Set);d(this,Ne,new Set);d(this,H,new Map);d(this,fe,new WeakMap);d(this,re,new Map);d(this,Ve,new Set);d(this,$e,new Set);d(this,K);d(this,je);if(e!=null&&e instanceof Ye)return e;if(e!=null||(e=this),Je.has(e))return Je.get(e);g(this,je,new WeakRef(e)),Je.set(e,this),Bt.add(this),_(this)}static get(e){if(e!=null)return e instanceof Ye?e:Je.get(e)}static findOrCreate(e){if(e==null)throw new Error("Cannot create a group with a null object");return new Ye(e)}static destroy(e){console.warn("SignalGroup.destroy(obj) is deprecated. Use SignalGroup.delete(obj) instead."),Ye.delete(e)}static delete(e){var t;(t=Je.get(e))==null||t.clear()}static clear(){for(let e of[...Bt])e.clear();Bt.clear()}attachGroup(e){if(e===this)throw new Error("Cannot attach a group to itself");return n(this,se).add(e),n(e,K)&&n(e,K)!==this&&n(n(e,K),se).delete(e),g(e,K,this),e}detachGroup(e){return e!==this&&n(this,se).has(e)&&(n(this,se).delete(e),g(e,K,void 0)),e}attachSignal(e){let t=D(e);if(t!=null&&t.destroyed)throw new Error("Cannot attach a destroyed signal to a group");return t&&n(this,Ne).add(t),e}attachSignalByName(e,t){if(t){this.attachSignal(t);let r=D(t);n(this,H).set(e,r),n(this,re).has(e)?n(this,re).get(e).push(r):n(this,re).set(e,[r]),n(this,fe).has(r)?n(this,fe).get(r).add(e):n(this,fe).set(r,new Set([e]))}else n(this,H).delete(e);return t}hasSignal(e){var t;return n(this,H).has(e)||!!((t=n(this,K))!=null&&t.hasSignal(e))}signal(e){var t,r,i;return(i=(t=n(this,H).get(e))==null?void 0:t.object)!=null?i:(r=n(this,K))==null?void 0:r.signal(e)}detachSignal(e){let t=D(e);if(t&&(n(this,Ne).delete(t),n(this,fe).has(t))){let r=n(this,fe).get(t);for(let i of r)if(n(this,re).has(i)){let o=n(this,re).get(i);o.splice(o.indexOf(t),1),o.length===0?(n(this,H).delete(i),n(this,re).delete(i)):n(this,H).get(i)===t&&n(this,H).set(i,o.at(-1))}r.clear(),n(this,fe).delete(t)}return e}attachEffect(e){return n(this,Ve).add(e),e}runEffects(){for(let e of n(this,Ve))e.run();for(let e of n(this,se))e.runEffects()}attachLink(e){if(e!=null&&e.isDestroyed)throw new Error("Cannot attach a destroyed link to a group");return e&&n(this,$e).add(e),e}detachLink(e){return e&&n(this,$e).delete(e),e}destroy(){console.warn("SignalGroup#destroy is deprecated. Use SignalGroup#clear instead."),this.clear()}clear(){var e;S(this,ke,this),L(this);for(let t of n(this,se))t.clear();for(let t of n(this,Ve))t.destroy();for(let t of n(this,Ne))V(t);for(let t of n(this,$e))t.destroy();if(n(this,se).clear(),n(this,Ne).clear(),n(this,H).clear(),n(this,re).clear(),n(this,Ve).clear(),n(this,$e).clear(),(e=n(this,K))==null||e.detachGroup(this),n(this,je)){let t=n(this,je).deref();t!==void 0&&Je.delete(t),g(this,je,void 0)}Bt.delete(this)}};se=new WeakMap,Ne=new WeakMap,H=new WeakMap,fe=new WeakMap,re=new WeakMap,Ve=new WeakMap,$e=new WeakMap,K=new WeakMap,je=new WeakMap;var de=Ye,mt,bt,Ft=class{constructor(e="id",t=1){d(this,mt);d(this,bt);g(this,mt,e),g(this,bt,t)}make(){return Symbol(\`\${n(this,mt)}\${Mt(this,bt)._++}\`)}};mt=new WeakMap,bt=new WeakMap;var Si=s=>s!=null&&typeof s.then=="function",we,ie,Se,Ee,Ce,Ue,Xe,Ze,I=class I{constructor(e,t){y(this,"id");y(this,"callback");d(this,we);d(this,ie,new Set);d(this,Se,new Set);d(this,Ee,new Map);d(this,Ce,new Set);y(this,"childEffects",[]);y(this,"curChildEffectSlot",0);y(this,"autorun",!0);y(this,"shouldRun",!0);y(this,"priority");d(this,Ue);d(this,Xe,!1);d(this,Ze,0);y(this,"run",()=>{if(n(this,Xe)||!this.shouldRun)return;let e=yr();if(e){e.batch(this.id,this.priority);return}if(n(this,Ze)>=I.maxDepth)throw new Error(\`[signalize] Effect \${this.id.toString()} exceeded maxDepth=\${I.maxDepth}: an effect callback recursively re-triggered itself (likely by writing a signal it depends on). Break the cycle, or raise EffectImpl.maxDepth if the recursion is intentional.\`);Mt(this,Ze)._++;try{if(this.runCleanupCallback(),this.destroyChildEffects(),this.curChildEffectSlot=0,this.shouldRun=!1,S(gr,this.id,this.id),this.hasStaticDeps())g(this,we,this.callback());else{n(this,Se).clear();for(let t of n(this,ie))n(this,Se).add(t);g(this,we,wi(this,this.callback)),this.cleanupLostSignals(),n(this,Ce).clear()}}finally{Mt(this,Ze)._--}});y(this,"destroy",()=>{n(this,Xe)||(S(this,ke,this),L(this),S(Ge,mi,this),this.runCleanupCallback(),this.destroyChildEffects(),L(pt,this),L(Ge,this),L(_e,this),g(this,Xe,!0),n(this,ie).clear(),n(this,Se).clear(),n(this,Ee).clear(),n(this,Ce).clear(),--I.count)});var i,o;_(this),this.callback=e;let r;(t==null?void 0:t.attach)!=null&&(r=de.findOrCreate(t.attach),r.attachEffect(this)),this.autorun=(i=t==null?void 0:t.autorun)!=null?i:!0,g(this,Ue,t!=null&&t.dependencies?t.dependencies.map(a=>{switch(typeof a){case"string":case"symbol":return r.signal(a);default:return a}}):void 0),this.id=I.idGen.make(),this.priority=(o=t==null?void 0:t.priority)!=null?o:0,T(Ge,this.id,yt,this),++I.count}hasStaticDeps(){return n(this,Ue)!=null&&n(this,Ue).length>0}saveSignalsFromDeps(){for(let e of n(this,Ue))this.whenSignalIsRead(D(e).id)}static createEffect(e,t,r){let i=Array.isArray(t)?t:void 0,o=i?r!=null?r:{dependencies:i}:t;o&&i&&(o.dependencies=i);let a,c=pr();return c!=null?(a=c.getCurrentChildEffect(),a==null&&(a=new I(e,o),c.attachChildEffect(a),S(Ge,hr,a)),c.curChildEffectSlot++):(a=new I(e,o),S(Ge,hr,a)),a.hasStaticDeps()?a.saveSignalsFromDeps():a.autorun&&a.run(),new zt(a)}getCurrentChildEffect(){return this.childEffects[this.curChildEffectSlot]}attachChildEffect(e){this.childEffects.push(e)}[yt](){this.shouldRun=!0,this.autorun&&this.run()}whenSignalIsRead(e){n(this,Se).delete(e),n(this,ie).has(e)||(n(this,ie).add(e),n(this,Ee).set(e,[T(pt,e,this.priority,yt,this),k(_e,e,cr,this)]))}[cr](e){!n(this,Ce).has(e)&&n(this,ie).has(e)&&(n(this,Ce).add(e),this.unsubscribeSignal(e),n(this,Ce).size===n(this,ie).size&&this.destroy())}cleanupLostSignals(){for(let e of n(this,Se))this.unsubscribeSignal(e),n(this,ie).delete(e)}destroyChildEffects(){for(let e of this.childEffects)e.destroy();this.childEffects.length=0}unsubscribeSignal(e){n(this,Ee).has(e)&&(n(this,Ee).get(e).forEach(t=>{t()}),n(this,Ee).delete(e))}runCleanupCallback(){if(n(this,we)!=null){let e=n(this,we);g(this,we,void 0),Si(e)?Promise.resolve(e).then(t=>{typeof t=="function"&&t()}):e()}}};we=new WeakMap,ie=new WeakMap,Se=new WeakMap,Ee=new WeakMap,Ce=new WeakMap,Ue=new WeakMap,Xe=new WeakMap,Ze=new WeakMap,y(I,"idGen",new Ft("ef")),y(I,"count",0),y(I,"maxDepth",256);var ms=I,ge=(...s)=>ms.createEffect(...s);var vt=new WeakMap,Ei=s=>{let e=vt.get(s);return e||(e={},vt.set(s,e)),e},xe=(s,e)=>{var t,r;return(r=(t=vt.get(s))==null?void 0:t.signals)==null?void 0:r.get(e)};var vr=(s,e,t)=>{var i;let r=Ei(s);(i=r.signals)!=null||(r.signals=new Map),r.signals.set(e,t)};function Cs(...s){for(let e of s)if(vt.has(e)){let t=vt.get(e);if(t.signals){for(let r of t.signals.values())V(r);t.signals.clear(),t.signals=void 0}}}function mr(s){let e=D(Ie(s)?s:xe(...s));e!=null&&!e.muted&&!e.destroyed&&bs(e.id,e.value,{touch:!0})}function tt(s){var e,t;return Ie(s)?(e=D(s))==null?void 0:e.value:(t=D(xe(...s)))==null?void 0:t.value}var dr;dr=ne;var Gt=class{constructor(e){y(this,dr);this[ne]=e}get get(){return this[ne].reader}get set(){return this[ne].writer}get value(){return tt(this.get)}set value(e){this.set(e)}onChange(e){let{destroy:t}=ge(()=>e(this.value),[this.get]);return t}get muted(){return this[ne].muted}set muted(e){this[ne].muted=e}touch(){mr(this)}destroy(){V(this)}},Ci=new Ft("si"),lr=!1;function Ai(){lr||(lr=!0,console.warn("signalReader(callback) is deprecated and will be removed in a future release. Use Signal.onChange(callback) instead \\u2014 it returns an unsubscribe function for proper cleanup."))}function ur(s){var e;Es()||(e=pr())==null||e.whenSignalIsRead(s)}function bs(s,e,t){Es()||S(pt,s,e,t)}var Ie=s=>s!=null&&s[ne]!=null,ki=s=>{let e=t=>{var r;return s.destroyed||(r=s.beforeRead)==null||r.call(s),t?(Ai(),ge(()=>(s.destroyed||ur(s.id),t(s.value)),[e])):s.destroyed||ur(s.id),s.value};return Object.defineProperty(e,ne,{value:s}),e},J,Vt=class Vt{constructor(e,t){y(this,"id");y(this,"lazy");y(this,"compare");y(this,"beforeRead");y(this,"muted",!1);y(this,"destroyed",!1);d(this,J);y(this,"valueFn");y(this,"reader");y(this,"writer",(e,t)=>{var c,p,w;let r=(c=t==null?void 0:t.lazy)!=null?c:!1,i=(p=t==null?void 0:t.compare)!=null?p:this.compare,o=i!=null?i:((A,v)=>A===v);if((r!==this.lazy||r&&e!==this.valueFn||!r&&!o(e,n(this,J)))&&(r?(g(this,J,void 0),this.valueFn=e,this.lazy=!0):(g(this,J,e),this.valueFn=void 0,this.lazy=!1),!this.muted&&!this.destroyed)){bs(this.id,n(this,J));return}(w=t==null?void 0:t.touch)!=null&&w&&!this.muted&&!this.destroyed&&bs(this.id,n(this,J),{touch:!0})});y(this,"object");this.id=Ci.make(),++Vt.instanceCount,this.lazy=e,this.lazy?(this.value=void 0,this.valueFn=t):(this.value=t,this.valueFn=void 0),this.reader=ki(this),this.object=new Gt(this)}get[ne](){return this}get value(){return this.lazy&&(g(this,J,this.valueFn()),this.valueFn=void 0,this.lazy=!1),n(this,J)}set value(e){g(this,J,e)}};J=new WeakMap,y(Vt,"instanceCount",0);var Nt=Vt,D=s=>s==null?void 0:s[ne];function O(s=void 0,e){var r;let t;if(Ie(s))t=D(s);else{let i=(r=e==null?void 0:e.lazy)!=null?r:!1;t=new Nt(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&&de.findOrCreate(e.attach).attachSignal(t),t.object}var V=(...s)=>{for(let e of s){let t=D(e);t!=null&&!t.destroyed&&(t.destroyed=!0,t.beforeRead=void 0,--Nt.instanceCount,S(_e,t.id,t.id))}};function $t(s,e){var a,c;let t=O(),r=(e==null?void 0:e.attach)!=null?de.findOrCreate(e.attach):void 0;r!=null&&(e!=null&&e.name?r.attachSignalByName(e.name,t):r.attachSignal(t));let i=ge(()=>{Pe(()=>{t.set(s())})},{autorun:!((a=e==null?void 0:e.lazy)!=null&&a),priority:(c=e==null?void 0:e.priority)!=null?c:be.C,attach:r}),o=D(t);return o.beforeRead=i.run,k(_e,o.id,i.destroy),t.get}var F,st,Ut=class{constructor(e){d(this,F,!1);d(this,st);y(this,"source");y(this,"lastValue");y(this,"isDestroyed",!1);_(this),this.source=D(e),g(this,st,T(pt,this.source.id,(t,r)=>{!n(this,F)&&!this.isDestroyed&&((r==null?void 0:r.touch)===!0?this.touch():this.write())})),k(_e,this.source.id,()=>this.destroy())}attach(e){let t=de.findOrCreate(e);return t.attachLink(this),k(this,ke,()=>{t.detachLink(this)}),t}nextValue(){return new Promise((e,t)=>{let r=[],i=()=>r.forEach(o=>{o()});r.push(k(this,et,o=>{i(),e(o)}),k(this,ke,()=>{i(),t()}))})}asyncValues(e){return $s(this,null,function*(){gt(this,et);try{let t=0;for(;!this.isDestroyed;)try{let r=yield new is(this.nextValue());if(e!=null&&e(r,t++))break;yield r}catch(r){break}}finally{He(this,et)}})}destroy(){var e;this.isDestroyed||((e=n(this,st))==null||e.call(this),g(this,st,void 0),S(this,ke,this),He(this,et),L(this),this.lastValue=void 0,this.isDestroyed=!0,Object.freeze(this))}get isMuted(){return n(this,F)}mute(){return!this.isDestroyed&&!n(this,F)&&(g(this,F,!0),S(this,ws,this)),this}unmute(){return!this.isDestroyed&&n(this,F)&&(g(this,F,!1),S(this,Ss,this)),this}toggleMute(){return this.isDestroyed||(g(this,F,!n(this,F)),S(this,n(this,F)?ws:Ss,this)),n(this,F)}updateValue(e){if(!n(this,F)&&!this.isDestroyed){let{value:t}=this.source;e(t),S(this,et,t),this.lastValue=t}}};F=new WeakMap,st=new WeakMap;var As=class extends Ut{constructor(t,r){super(t);y(this,"target");this.target=D(r),k(_e,this.target.id,()=>this.destroy()),this.touch()}touch(){return this.updateValue(t=>{this.target.writer(t,{touch:!0})}),this}write(){this.updateValue(t=>{this.target.writer(t)})}},ks=class extends Ut{constructor(t,r){super(t);y(this,"target");this.target=r,this.touch()}touch(){return this.updateValue(t=>{this.target(t)}),this}write(){this.updateValue(t=>{this.target(t)})}},jt=new Map;function Y(s,e,t){let r=D(s),i=D(e),o=i!=null?i:e,a;if(jt.has(r)){if(a=jt.get(r),a.has(o))return a.get(o)}else a=new Map,jt.set(r,a);let c=i!=null?new As(s,i):new ks(s,e),p=t==null?void 0:t.attach;return p&&c.attach(p),a.set(o,c),k(c,ke,()=>{a.delete(o),a.size===0&&jt.delete(r)}),c}var $,Ps=class Ps{constructor(){d(this,$,new Map)}static fromProps(e,t){let r=new Ps,i=t?t.map(o=>[o,e[o]]):Object.entries(e);for(let[o,a]of i)n(r,$).set(o,O(a));return r}keys(){return n(this,$).keys()}signals(){return n(this,$).values()}entries(){return n(this,$).entries()}clear(){for(let e of n(this,$).values())e.destroy();n(this,$).clear()}has(e){return n(this,$).has(e)}get(e){if(!n(this,$).has(e)){let t=O();return n(this,$).set(e,t),t}return n(this,$).get(e)}update(e){e.size&&Pe(()=>{for(let[t,r]of e.entries())this.get(t).set(r)})}updateFromProps(e,t){Pe(()=>{let r=t?t.map(i=>[i,e[i]]):Object.entries(e);for(let[i,o]of r)this.get(i).set(o)})}};$=new WeakMap;var _t=Ps;var It=s=>s!=null?s:void 0;var xs=Symbol("onCreate"),oe=Symbol("onDestroy"),br=Symbol("onParentChanged"),Wt=Symbol("onViewEvent");function wr(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=xe(this,r);if(a)return i?a.value:a.get()},set(a){var c;(c=xe(this,r))==null||c.set(a)},init(a){let c=O(a,s);return vr(this,r,c),de.findOrCreate(this).attachSignalByName(r,c),c.value}}}}var Pi=Object.create,Os=Object.defineProperty,xi=Object.getOwnPropertyDescriptor,Cr=(s,e)=>(e=Symbol[s])?e:Symbol.for("Symbol."+s),it=s=>{throw TypeError(s)},Oi=(s,e,t)=>e in s?Os(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,Sr=(s,e)=>Os(s,"name",{value:e,configurable:!0}),Mi=s=>{var e;return[,,,Pi((e=s==null?void 0:s[Cr("metadata")])!=null?e:null)]},Ar=["class","method","getter","setter","accessor","field","value","get","set"],wt=s=>s!==void 0&&typeof s!="function"?it("Function expected"):s,Li=(s,e,t,r,i)=>({kind:Ar[s],name:e,metadata:r,addInitializer:o=>t._?it("Already initialized"):i.push(wt(o||null))}),kr=(s,e)=>Oi(e,Cr("metadata"),s[3]),Er=(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},Ri=(s,e,t,r,i,o)=>{var a,c,p,w,A,v=e&7,G=!!(e&8),R=!!(e&16),E=v>3?s.length+1:v?G?1:2:0,l=Ar[v+5],h=v>3&&(s[E-1]=[]),u=s[E]||(s[E]=[]),f=v&&(!R&&!G&&(i=i.prototype),v<5&&(v>3||!R)&&xi(v<4?i:{get[t](){return j(this,o)},set[t](x){return Et(this,o,x)}},t));v?R&&v<4&&Sr(o,(v>2?"set ":v>1?"get ":"")+t):Sr(i,t);for(var b=r.length-1;b>=0;b--)w=Li(v,t,p={},s[3],u),v&&(w.static=G,w.private=R,A=w.access={has:R?x=>Ti(i,x):x=>t in x},v^3&&(A.get=R?x=>(v^1?j:Oe)(x,i,v^4?o:f.get):x=>x[t]),v>2&&(A.set=R?(x,he)=>Et(x,i,he,v^4?o:f.set):(x,he)=>x[t]=he)),c=(0,r[b])(v?v<4?R?o:f[l]:v>4?void 0:{get:f.get,set:f.set}:i,w),p._=1,v^4||c===void 0?wt(c)&&(v>4?h.unshift(c):v?R?o=c:f[l]=c:i=c):typeof c!="object"||c===null?it("Object expected"):(wt(a=c.get)&&(f.get=a),wt(a=c.set)&&(f.set=a),wt(a=c.init)&&h.unshift(a));return v||kr(s,i),f&&Os(i,t,f),R?v^4?o:f:i},Ms=(s,e,t)=>e.has(s)||it("Cannot "+t),Ti=(s,e)=>Object(e)!==e?it('Cannot use the "in" operator on this value'):s.has(e),j=(s,e,t)=>(Ms(s,e,"read from private field"),t?t.call(s):e.get(s)),Qt=(s,e,t)=>e.has(s)?it("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,t),Et=(s,e,t,r)=>(Ms(s,e,"write to private field"),r?r.call(s,t):e.set(s,t),t),Oe=(s,e,t)=>(Ms(s,e,"access private method"),t),Pr,ae,Me,Ct,Ls,ye,qt,St,rt="value";Pr=[wr({name:rt})];var ce=class{constructor(e){Qt(this,ye),Qt(this,ae,[]),Qt(this,Me),Qt(this,Ls,Er(Ct,8,this)),Er(Ct,11,this),this.value$=void 0,gt(this,rt),this.value$=xe(this,rt),this.value$.onChange(t=>S(this,rt,t)),e&&this.add(...e)}add(...e){return j(this,ae).push(...e),Oe(this,ye,St).call(this),Oe(this,ye,qt).call(this,e)}unshift(...e){return j(this,ae).unshift(...e),Oe(this,ye,St).call(this),Oe(this,ye,qt).call(this,e)}remove(...e){Oe(this,ye,qt).call(this,e)()}clear(){j(this,ae).length=0,Oe(this,ye,St).call(this)}dispose(){var e;this.clear(),(e=j(this,Me))==null||e.destroy(),Et(this,Me,void 0),He(this,rt),L(this),this.value$.destroy(),Cs(this)}};Ct=Mi(null);ae=new WeakMap;Me=new WeakMap;Ls=new WeakMap;ye=new WeakSet;qt=function(s){return()=>{for(let e of s){let t=j(this,ae).indexOf(e);t!==-1&&j(this,ae).splice(t,1)}Oe(this,ye,St).call(this)}};St=function(){var s;(s=j(this,Me))==null||s.destroy(),j(this,ae).length===0?(Et(this,Me,void 0),this.value=void 0):(Et(this,Me,ge(()=>{let e;for(let t of j(this,ae)){let r=tt(t);if(r!=null){e=r;break}}this.value=e},j(this,ae))),j(this,Me).run())};Ri(Ct,4,"value",Pr,ce,Ls);kr(Ct,ce);ce.Value=rt;var Rs=new Map,Ts=!1,Di=(s,e)=>{Rs.set(s,e),Ts||(Ts=!0,queueMicrotask(()=>{Ts=!1;let t=Array.from(Rs.entries());Rs.clear();for(let[r,i]of t)r.set(i)}))},X,We,Le,Z,Re,W,B,pe,Q,nt,Qe,ve,P,Ds,Bs,zs,Te,At,Ht,Kt=class{constructor(e,t){d(this,P);d(this,X);d(this,We);d(this,Le,new _t);d(this,Z,new Map);d(this,Re,new Map);d(this,W);d(this,B);d(this,pe,new Set);d(this,Q,[]);d(this,nt,0);d(this,Qe,!1);d(this,ve);d(this,Te);g(this,X,e),g(this,We,t),k(this,oe,be.Min,this)}get kernel(){return n(this,X)}get uuid(){return n(this,We)}get order(){return n(this,nt)}set order(e){n(this,nt)!==e&&(g(this,nt,e),n(this,W)&&this.parent.resortChildren())}get parentUuid(){return n(this,W)||void 0}set parentUuid(e){if(n(this,W)!==e){let t=e?n(this,X).getEntity(e):void 0;this.removeFromParent(),g(this,W,e||void 0),g(this,B,t),n(this,B)&&n(this,B).addChild(this),C(this,P,Bs).call(this)}}get parent(){return!n(this,B)&&n(this,W)&&g(this,B,n(this,X).getEntity(n(this,W))),n(this,B)}set parent(e){this.parentUuid=e==null?void 0:e.uuid}get hasParent(){return!!n(this,W)}get children(){return n(this,Q)}traverse(e){e(this);for(let t of n(this,Q))t.traverse(e)}[oe](){var e,t;n(this,Le).clear(),L(this),(e=n(this,ve))==null||e.call(this);for(let r of n(this,Re).values())r.cleanup(),r.signal.destroy();n(this,Re).clear();for(let r of n(this,Z).values())r.context.set(void 0),r.unsubscribePathValue(),(t=r.unsubscribeFromParent)==null||t.call(r),r.valuePath.dispose(),r.inherited.destroy(),r.provide.destroy(),r.context.destroy();g(this,W,void 0),g(this,B,void 0),n(this,pe).clear(),n(this,Q).length=0}addChild(e){var t;if(n(this,Q).length===0){n(this,pe).add(e.uuid),n(this,Q).push(e);return}if(n(this,pe).has(e.uuid))throw new Error(\`child with uuid: \${e.uuid} already exists! parentUuid: \${this.uuid}\`);n(this,pe).add(e.uuid),n(this,Q).push(e),this.resortChildren();for(let[,r]of n(e,Z))C(t=e,P,Ht).call(t,r)}resortChildren(){n(this,Q).sort((e,t)=>e.order-t.order)}removeChild(e){n(this,pe).has(e.uuid)&&(n(this,pe).delete(e.uuid),n(this,Q).splice(n(this,Q).indexOf(e),1))}removeFromParent(){if(n(this,B)){n(this,B).removeChild(this),g(this,B,void 0),g(this,W,void 0);for(let[,e]of n(this,Z))e.unsubscribeFromParent&&(e.unsubscribeFromParent(),e.unsubscribeFromParent=void 0);C(this,P,Ds).call(this)}}get autoDestructionOnParentRemoval(){return n(this,Qe)}set autoDestructionOnParentRemoval(e){n(this,Qe)!==e&&(g(this,Qe,e),C(this,P,Bs).call(this))}reSubscribeToParentContexts(){for(let[,e]of n(this,Z))C(this,P,Ht).call(this,e)}dispatchMessageToView(e,t,r,i=!1){n(this,X).dispatchMessageToView({uuid:n(this,We),type:e,data:t,transferables:r,traverseChildren:i})}dispatchViewEvents(e){for(let{type:t,data:r}of e)S(this,Wt,t,r)}dispatchViewEvent(e,t){this.dispatchViewEvents([{type:e,data:t}])}getPropertyReader(e){return C(this,P,zs).call(this,e).get}getPropertyWriter(e){return C(this,P,zs).call(this,e).set}setProperties(e){this.clearTruthyPropsCache(),Pe(()=>{for(let[t,r]of e)this.setProperty(t,r)})}setProperty(e,t){this.getPropertyWriter(e)(t)}getProperty(e){return tt(this.getPropertyReader(e))}propKeys(){return Array.from(n(this,Le).keys())}propEntries(){return Array.from(n(this,Le).entries()).map(([e,t])=>[e,t.value])}clearTruthyPropsCache(){g(this,Te,void 0)}truthyProps(){if(n(this,Te))return n(this,Te).size?n(this,Te):void 0;let e=new Set;for(let[t,r]of n(this,Le).entries())if(typeof t=="string"){let i=r.value;i!=null&&i!==!1&&i!==""&&e.add(t)}return g(this,Te,e),e.size?e:void 0}hasContext(e){return n(this,Z).has(e)}useContext(e){return C(this,P,At).call(this,e).context.get}useParentContext(e){return C(this,P,At).call(this,e).inherited.get}provideContext(e){return C(this,P,At).call(this,e).provide}provideGlobalContext(e){if(n(this,Re).has(e))return n(this,Re).get(e).signal;let t=n(this,X).findOrCreateRootContext(e),r=O(),i=t.add(r);return n(this,Re).set(e,{cleanup:i,signal:r}),r}};X=new WeakMap,We=new WeakMap,Le=new WeakMap,Z=new WeakMap,Re=new WeakMap,W=new WeakMap,B=new WeakMap,pe=new WeakMap,Q=new WeakMap,nt=new WeakMap,Qe=new WeakMap,ve=new WeakMap,P=new WeakSet,Ds=function(){n(this,ve)&&(n(this,ve).call(this),g(this,ve,void 0))},Bs=function(){C(this,P,Ds).call(this),n(this,Qe)&&n(this,B)&&g(this,ve,k(n(this,B),oe,be.Max,()=>{g(this,ve,void 0),n(this,X).destroyEntity(n(this,We))}))},zs=function(e){return n(this,Le).get(e)},Te=new WeakMap,At=function(e){if(n(this,Z).has(e))return n(this,Z).get(e);let t=O(),r=O(),i=O(),o=new ce([r,t]),a=T(o,ce.Value,p=>{Di(i,p)}),c={name:e,inherited:t,provide:r,context:i,valuePath:o,unsubscribePathValue:a};return n(this,Z).set(e,c),C(this,P,Ht).call(this,c),c},Ht=function(e){var t,r;if((t=e.unsubscribeFromParent)==null||t.call(e),e.unsubscribeFromParent=void 0,this.parent){let i=C(r=this.parent,P,At).call(r,e.name),o=Y(i.context,e.inherited);e.unsubscribeFromParent=o.destroy.bind(o)}else{let i=n(this,X).findOrCreateRootContext(e.name),o=Y(i.value$,e.inherited);e.unsubscribeFromParent=o.destroy.bind(o)}};function xr(s,e){s.indexOf(e)===-1&&s.push(e)}var Or=s=>{let e=s.split("@").map(t=>t.trim());if(e.length===2&&e[1])return e[0]?{key:\`\${e[0]}@\${e[1]}\`,prop:e[1],token:e[0]}:{key:e[1],prop:e[1]}},Jt=(s,e)=>{for(let t of e)s.add(t)},Bi=(s,e)=>{if(s!=null)for(let t of s.constructors)e.add(t)},me,U,q,kt=class{constructor(){d(this,me,new Map);d(this,U,new Map);d(this,q,new Map)}static get(e){return e!=null?e:zi}define(e,t){n(this,me).has(e)?xr(n(this,me).get(e).constructors,t):n(this,me).set(e,{token:e,constructors:[t]})}appendRoute(e,t){let r=Or(e);r?n(this,q).has(r.key)?Jt(n(this,q).get(r.key).routes,t):n(this,q).set(r.key,{routes:new Set(t),token:r.token}):n(this,U).has(e)?Jt(n(this,U).get(e),t):n(this,U).set(e,new Set(t))}clearRoute(e){let t=Or(e);t?n(this,q).delete(t.key):n(this,U).delete(e)}findTokensByRoute(e,t){let r=new Set([e]),i=n(this,U).has(e)?[...n(this,U).get(e)]:[];for(;i.length;){let o=i.shift();r.has(o)||(r.add(o),n(this,U).has(o)&&i.push(...Array.from(n(this,U).get(o)).filter(a=>!r.has(a))))}if(t){for(let a of t)n(this,q).has(a)&&Jt(r,n(this,q).get(a).routes);let o;do{o=r.size;for(let a of new Set(r))for(let c of t){let p=\`\${a}@\${c}\`;n(this,q).has(p)&&Jt(r,n(this,q).get(p).routes)}}while(o!==r.size)}return r}findConstructors(e,t){let r=this.findTokensByRoute(e,t),i=new Set;for(let o of r)Bi(n(this,me).get(o),i);return i.size>0?Array.from(i):void 0}hasToken(e){return n(this,me).has(e)}hasRoute(e){return n(this,U).has(e)}clear(){n(this,me).clear(),n(this,U).clear(),n(this,q).clear()}};me=new WeakMap,U=new WeakMap,q=new WeakMap;var zi=new kt;var Mr=s=>s.displayName||s.name,Lr=!1,Rr=!1,Tr=!1,Dr=!1,Br=!1,M,ee,ot,Pt,te,De,Yt=class{constructor(e){d(this,M);d(this,ee);d(this,ot);d(this,Pt);d(this,te);d(this,De);this.logger=new Dt("Kernel"),g(this,M,new Map),g(this,ee,new Set),g(this,te,!0),g(this,De,new Map),_(this),this.registry=kt.get(e)}getEntity(e){var r;let t=(r=n(this,M).get(e))==null?void 0:r.entity;if(!t)throw new Error(\`entity with uuid "\${e}" not found!\`);return t}hasEntity(e){return n(this,M).has(e)}traverseLevelOrderBFS(e=!1){if(n(this,te)){let t=new Map,r=(i,o)=>{let a=this.getEntity(i);t.has(o)?t.get(o).push(a):t.set(o,[a]);for(let c of a.children)r(c.uuid,o+1)};n(this,ee).forEach(i=>{r(i,0)}),g(this,ot,Array.from(t.entries()).sort((i,o)=>i[0]-o[0]).flatMap(([,i])=>i)),g(this,Pt,n(this,ot).slice().reverse()),g(this,te,!1)}return e?n(this,Pt):n(this,ot)}getEntityGraph(){return Array.from(n(this,ee)).map(e=>this.getEntityGraphNode(e))}getEntityGraphNode(e){if(!n(this,M).has(e))return;let{token:t,entity:r}=n(this,M).get(e);return{token:t,entity:r,props:Object.fromEntries(r.propEntries()),children:r.children.map(i=>this.getEntityGraphNode(i.uuid))}}upgradeEntities(){let e=new Map;for(let t of this.traverseLevelOrderBFS(!0))e.set(t.uuid,this.updateShadowObjects(t.uuid,2));for(let t of this.traverseLevelOrderBFS(!1))this.updateShadowObjects(t.uuid,1,e.get(t.uuid));e.clear()}run(e){this.logger.isDebug&&this.logger.debug("sync",e),Pe(()=>{for(let t of e.changeTrail)this.parse(t)})}parse(e){switch(e.type){case le.CreateEntities:this.createEntity(e.uuid,e.token,e.parentUuid,e.order,e.properties,e.autoDestructionOnParentRemoval),g(this,te,!0);break;case le.DestroyEntities:this.destroyEntity(e.uuid),g(this,te,!0);break;case le.SetParent:this.setParent(e.uuid,e.parentUuid,e.order),g(this,te,!0);break;case le.UpdateOrder:this.updateOrder(e.uuid,e.order),g(this,te,!0);break;case le.ChangeProperties:this.changeProperties(e.uuid,e.properties);break;case le.ChangeToken:this.changeToken(e.uuid,e.token);break;case le.SendEvents:this.dispatchEventsToEntity(e.uuid,e.events);break}}createEntity(e,t,r,i=0,o,a=!1){let c=new Kt(this,e);c.order=i;let p={token:t,entity:c,usedConstructors:new Map};n(this,M).set(e,p),r&&(c.parentUuid=r),c.autoDestructionOnParentRemoval=a,c.hasParent||n(this,ee).add(e),o&&c.setProperties(o),this.createShadowObjects(e)}destroyEntity(e){if(!n(this,M).has(e))return;let{entity:t,usedConstructors:r}=n(this,M).get(e),i=[...t.children];for(let o of i)o.autoDestructionOnParentRemoval?this.destroyEntity(o.uuid):(o.removeFromParent(),n(this,ee).add(o.uuid));t.removeFromParent(),S(t,oe,t),r.clear(),n(this,M).delete(t.uuid),n(this,ee).delete(t.uuid),g(this,te,!0)}setParent(e,t,r=0){let i=this.getEntity(e);if(!(i.parentUuid===t&&i.order===r)){if(t&&!n(this,M).has(t))throw new Error(\`entity with uuid "\${t}" not found!\`);i.removeFromParent(),i.order=r,i.parentUuid=t,i.hasParent?n(this,ee).delete(e):n(this,ee).add(e),i.reSubscribeToParentContexts(),queueMicrotask(()=>{this.logger.isDebug&&this.logger.debug("entity.onParentChanged",{uuid:e,parentUuid:t,order:r,entity:i}),S(i,br,i)})}}updateOrder(e,t){this.getEntity(e).order=t}dispatchEventsToEntity(e,t){var r;(r=this.getEntity(e))==null||r.dispatchViewEvents(t)}changeProperties(e,t){this.getEntity(e).setProperties(t),this.updateShadowObjects(e)}changeToken(e,t){if(!n(this,M).has(e))return;let r=n(this,M).get(e);r.token!==t&&(r.token=t,this.updateShadowObjects(e))}dispatchMessageToView(e){queueMicrotask(()=>{S(this,ht,e)})}updateShadowObjects(e,t=0,r){let i=n(this,M).get(e);r!=null||(r=new Set(this.registry.findConstructors(i.token,i.entity.truthyProps())));let o=t===0||t===2,a=t===0||t===1;if(o){for(let[c,p]of i.usedConstructors)if(!r.has(c)){i.usedConstructors.delete(c);for(let w of p)this.destroyShadowObject(w,i.entity)}}if(a)for(let c of r)i.usedConstructors.has(c)||this.constructShadowObject(c,i);return r}constructShadowObject(e,t){let r=new Set,i=new Set,o=new Map,a=new Map,c=new Map,p=new Map,w=new Map,A=new Map,v=new Map,G=new Map,R=(l,h)=>{!Br&&h!=null&&typeof h=="function"&&(console.warn('[shadow-objects] Deprecation Warning: The "isEqual" option of "useProperty()" is now passed as {compare} argument. Please update your code accordingly.'),Br=!0);let u=typeof h=="function"?{compare:h}:h,f=v.get(l);if(f===void 0){f=O(void 0,u).get,v.set(l,f),G.set(l,u==null?void 0:u.compare);let b=Y(t.entity.getPropertyReader(l),f);i.add(b.destroy.bind(b))}else(u==null?void 0:u.compare)!=null&&G.get(l)!==u.compare&&console.warn(\`[shadow-objects] useProperty("\${l}"): the cached signal already exists with a different (or no) {compare} function \\u2014 the new options are ignored. Pass options only on the first call per property.\`);return f},E=_(new e({entity:t.entity,provideContext(l,h,u){var x;!Lr&&u!=null&&typeof u=="function"&&(console.warn('[shadow-objects] Deprecation Warning: The "isEqual" option of "provideContext()" is now passed as {compare} argument. Please update your code accordingly.'),Lr=!0);let f=typeof u=="function"?{compare:u}:u,b=w.get(l);if(b==null){let he=Ie(h),es=he?void 0:It(h);if(b=O(es,f!=null&&f.compare?{compare:f.compare}:void 0),he){let ct=Y(h,b);i.add(ct.destroy.bind(ct))}let at=Y(b,t.entity.provideContext(l));i.add(at.destroy.bind(at)),w.set(l,b)}return b!=null&&((x=f==null?void 0:f.clearOnDestroy)==null||x)&&i.add(()=>{b.set(void 0)}),b},provideGlobalContext(l,h,u){var x;!Rr&&u!=null&&typeof u=="function"&&(console.warn('[shadow-objects] Deprecation Warning: The "isEqual" option of "provideGlobalContext()" is now passed as {compare} argument. Please update your code accordingly.'),Rr=!0);let f=typeof u=="function"?{compare:u}:u,b=A.get(l);if(b==null){let he=Ie(h),es=he?void 0:It(h);if(b=O(es,f!=null&&f.compare?{compare:f.compare}:void 0),he){let ct=Y(h,b);i.add(ct.destroy.bind(ct))}let at=Y(b,t.entity.provideGlobalContext(l));i.add(at.destroy.bind(at)),A.set(l,b)}return b!=null&&((x=f==null?void 0:f.clearOnDestroy)==null||x)&&i.add(()=>{b.set(void 0)}),b},useContext(l,h){!Tr&&h!=null&&typeof h=="function"&&(console.warn('[shadow-objects] Deprecation Warning: The "isEqual" option of "useContext()" is now passed as {compare} argument. Please update your code accordingly.'),Tr=!0);let u=typeof h=="function"?{compare:h}:h,f=o.get(l);if(f===void 0){f=O(void 0,u).get,o.set(l,f),a.set(l,u==null?void 0:u.compare);let b=Y(t.entity.useContext(l),f);i.add(b.destroy.bind(b))}else(u==null?void 0:u.compare)!=null&&a.get(l)!==u.compare&&console.warn(\`[shadow-objects] useContext("\${String(l)}"): the cached signal already exists with a different (or no) {compare} function \\u2014 the new options are ignored. Pass options only on the first call per context.\`);return f},useParentContext(l,h){!Dr&&h!=null&&typeof h=="function"&&(console.warn('[shadow-objects] Deprecation Warning: The "isEqual" option of "useParentContext()" is now passed as {compare} argument. Please update your code accordingly.'),Dr=!0);let u=typeof h=="function"?{compare:h}:h,f=c.get(l);if(f===void 0){f=O(void 0,u).get,c.set(l,f),p.set(l,u==null?void 0:u.compare);let b=Y(t.entity.useParentContext(l),f);i.add(b.destroy.bind(b))}else(u==null?void 0:u.compare)!=null&&p.get(l)!==u.compare&&console.warn(\`[shadow-objects] useParentContext("\${String(l)}"): the cached signal already exists with a different (or no) {compare} function \\u2014 the new options are ignored. Pass options only on the first call per parent context.\`);return f},dispatchMessageToView(l,h,u,f=!1){t.entity.dispatchMessageToView(l,h,u,f)},useProperty:R,useProperties(l){let h={};for(let u in l)Object.hasOwn(l,u)&&(h[u]=R(l[u]));return h},createResource(l,h){let u=O(),f=ge(()=>{let b=It(l());return u.set(b),b!==void 0&&h?()=>{h(b),u.set(void 0)}:()=>{u.set(void 0)}});return i.add(()=>{f.destroy(),u.set(void 0),V(u)}),u},createEffect(...l){let h=ge(...l);return i.add(h.destroy),h},createSignal(...l){let h=O(...l);return i.add(()=>{V(h)}),h},createMemo(...l){let h=$t(...l);return i.add(()=>{V(h)}),h},on(...l){let[h]=l;if(typeof h=="string"||typeof h=="symbol"||Array.isArray(h)){let f=T(t.entity,...l);return i.add(f),f}let u=T(...l);return i.add(u),Object.assign(()=>{i.delete(u),u()},u)},once(...l){let[h]=l;if(typeof h=="string"||typeof h=="symbol"||Array.isArray(h)){let f=k(t.entity,...l);return i.add(f),f}let u=k(...l);return i.add(u),Object.assign(()=>{i.delete(u),u()},u)},emit(...l){let[h]=l;typeof h=="string"||typeof h=="symbol"||Array.isArray(h)?S(t.entity,...l):S(...l)},onViewEvent(l){let h=T(t.entity,Wt,(u,f)=>{l(u,f)});i.add(h)},onDestroy(l){r.add(l)}}));return this.logger.isInfo&&this.logger.info("create shadow-object",Mr(e),{shadowObject:E,entity:t.entity}),k(t.entity,oe,be.Low,()=>{this.logger.isInfo&&this.logger.info("destroy shadow-object",Mr(e),{shadowObject:E,entity:t.entity});for(let h of r)h();for(let h of i)h();for(let h of o.values())V(h);for(let h of c.values())V(h);for(let h of v.values())V(h);for(let h of w.values())V(h);for(let h of A.values())V(h);r.clear(),i.clear(),o.clear(),c.clear(),v.clear(),w.clear(),A.clear();let l=t.usedConstructors.get(e);l&&(l.delete(E),l.size===0&&t.usedConstructors.delete(e))}),t.usedConstructors.has(e)?t.usedConstructors.get(e).add(E):t.usedConstructors.set(e,new Set([E])),this.attachShadowObject(E,t.entity),E}createShadowObjects(e){var r;let t=n(this,M).get(e);(r=this.registry.findConstructors(t.token,t.entity.truthyProps()))==null||r.forEach(i=>{this.constructShadowObject(i,t)})}findShadowObjects(e){if(!n(this,M).has(e))return[];let{usedConstructors:t}=n(this,M).get(e);return Array.from(new Set(Array.from(t.values()).flatMap(r=>Array.from(r))))}attachShadowObject(e,t){T(t,e),typeof e[xs]=="function"&&e[xs](t)}destroyShadowObject(e,t){typeof e[oe]=="function"&&e[oe](t),S(e,oe,t),L(t,e)}findOrCreateRootContext(e){let t=n(this,De).get(e);return t||(t=new ce,n(this,De).set(e,t)),t}destroy(){for(let e of n(this,De).values())e.dispose();n(this,De).clear();for(let e of this.traverseLevelOrderBFS().reverse())this.destroyEntity(e.uuid)}};M=new WeakMap,ee=new WeakMap,ot=new WeakMap,Pt=new WeakMap,te=new WeakMap,De=new WeakMap;var zr=s=>(typeof s=="string"&&(s=new URL(s,globalThis.location.href)),s.toString());var xt,Be,Fr,Gr,Nr,Xt=class{constructor(e){d(this,Be);d(this,xt,new Set);var t,r;this.kernel=(t=e==null?void 0:e.kernel)!=null?t:new Yt,this.postMessage=(r=e==null?void 0:e.postMessage)!=null?r:self.postMessage.bind(self),T(this.kernel,ht,"onMessageToView",this)}route(e){var t;switch(e.data.type){case js:C(this,Be,Fr).call(this,e.data);break;case Us:C(this,Be,Gr).call(this,e.data);break;case _s:C(this,Be,Nr).call(this,e.data);break;default:console.warn("[MessageRouter] unknown message",(t=e.data.type)!=null?t:e.data)}}onMessageToView(e){let i=e,{transferables:t}=i,r=Vs(i,["transferables"]);this.postMessage({type:ht,data:r},{transfer:t})}};xt=new WeakMap,Be=new WeakSet,Fr=async function(e){try{let t=await import(zr(e.importModule));t[Rt]?(await ps(this.kernel,t[Rt],n(this,xt)),this.postMessage({type:Lt,url:e.importModule})):this.postMessage({type:Lt,url:e.importModule,error:\`module has no "\${Rt}" export\`})}catch(t){console.error("[MessageRouter] failed to import module",t),this.postMessage({type:Lt,url:e.importModule,error:\`\${t}\`})}},Gr=function(e){try{this.kernel.run(e)}catch(t){console.error("[MessageRouter] failed to apply change trail",t),this.postMessage({type:ns,serial:e.serial,error:t.toString()})}e.serial&&this.postMessage({type:ns,serial:e.serial})},Nr=function(e){console.debug("[MessageRouter] on destroy",e),L(this.kernel,this),n(this,xt).clear(),this.postMessage({type:Ws})};var Zt=class{constructor(){this.onmessage=e=>{var t;e.data.type===N?globalThis[z]=e.data.config:((t=this.router)!=null||(this.router=new Xt),this.router.route(e))}}start(){self.addEventListener("message",this.onmessage),self.postMessage({type:Is})}};console.debug("@spearwolf/shadow-objects/WorkerRuntime: hello!");var Fi=new Zt;Fi.start();
22
22
  /*! Bundled license information:
23
23
 
24
24
  @spearwolf/eventize/lib/index.mjs:
25
25
  (*!
26
26
  =============================================================================
27
- @spearwolf/eventize 4.0.2+build.20250807
28
- \u2014 https://github.com/spearwolf/eventize.git
27
+ @spearwolf/eventize 4.3.1+build.20260508
28
+ \u2014 git+https://github.com/spearwolf/eventize.git
29
29
  =============================================================================
30
30
 
31
- Copyright 2015-2025 Wolfger Schramm
31
+ Copyright 2015-2026 Wolfger Schramm
32
32
 
33
33
  Licensed under the Apache License, Version 2.0 (the "License");
34
34
  you may not use this file except in compliance with the License.
@@ -43,13 +43,13 @@ var te="*",Zt=1,xt=2,kt=4,z=Symbol.for("eventize"),Hs="[eventize]",Fe=s=>s===te,
43
43
  limitations under the License.
44
44
  *)
45
45
 
46
- @spearwolf/signalize/dist/signalize.DWPi0AAt.js:
46
+ @spearwolf/signalize/dist/signalize.BdDWD_tl.js:
47
47
  @spearwolf/signalize/dist/index.js:
48
48
  @spearwolf/signalize/dist/decorators.js:
49
49
  (*!
50
50
  @file @spearwolf/signalize - signals and effects for all
51
51
  @author Wolfger Schramm <wolfger@spearwolf.de>
52
- @version 0.27.2+esm.20260204
52
+ @version 0.28.0+esm.20260508
53
53
 
54
54
  Copyright 2022-2026 Wolfger Schramm
55
55
 
@@ -67,17 +67,17 @@ var te="*",Zt=1,xt=2,kt=4,z=Symbol.for("eventize"),Hs="[eventize]",Fe=s=>s===te,
67
67
 
68
68
  *)
69
69
  */
70
- `)}var qs=()=>new Kt;var Ne=(s,e,t=1e3,r)=>new Promise((i,n)=>{let o,l,a=()=>{clearTimeout(o),s.removeEventListener("message",l)};t!==0&&t!==1/0&&(o=setTimeout(()=>{a(),n(new Error(`Timeout waiting for message of type: ${e}`))},t)),l=f=>{if(f.data.type===e)try{(!r||r(f.data))&&(a(),i())}catch(w){a(),n(w.toString())}},s.addEventListener("message",l)});var xr=s=>{let e;if(s!=null&&Array.isArray(s))for(let t of s)t.transferables&&(e?e=[...e,...t.transferables]:e=t.transferables,delete t.transferables);return e},vt=class s{static{this.WorkerLoaded="workerLoaded"}#e;#t;#s;get isDestroyed(){return this.#t}get workerLoaded(){return le(this,s.WorkerLoaded)}constructor(){this.#t=!1,this.#s=0,this.logger=new T("RemoteWorkerEnv"),U(this,s.WorkerLoaded)}async start(){if(this.#e)return this.logger.isWarn&&this.logger.warn("already started"),this.workerLoaded.then(()=>{if(this.isDestroyed)throw"worker was destroyed"});let e=this.#e=qs();this.configureConsoleLogger(e);try{if(await Ne(e,vs,Ss),this.isDestroyed)throw"worker was destroyed";e.addEventListener("message",this.onMessageFromWorker.bind(this)),queueMicrotask(()=>{y(this,s.WorkerLoaded,this)})}catch(t){throw this.logger.error("failed to start",t),this.#e=void 0,t}}applyChangeTrail(e,t){let r=xr(e),i={type:ms,changeTrail:e},n=++this.#s;return t&&(i.serial=n),this.#e.postMessage(i,r),t?Ne(this.#e,ws,ks,o=>{if(o.error)throw o.error;return o.serial===n}):Promise.resolve()}importScript(e){return e=mt(e),this.#e.postMessage({type:ys,importModule:e}),Ne(this.#e,Cs,xs,t=>{if(t.error)throw t.error;return t.url===e})}destroy(){if(!this.#e)return;let e=this.#e;this.#e=void 0,this.#t=!0,e.postMessage({type:bs}),Ne(e,Es,As).finally(()=>{e.terminate()})}onMessageFromWorker(e){e.data?.type===pe?this.onMessageToView?.(e.data.data):this.logger.isDebug&&this.logger.debug("message from worker",e)}configureConsoleLogger(e){let t=`${j}.RemoteWorkerEnv.workerConfig`,r=JSON.parse(localStorage.getItem(t)??"{}");this.logger.isInfo&&this.logger.info("load console-logger worker config",{localStorageKey:t,workerConfig:r}),e.postMessage({type:j,config:{...T.sharedConfig,enable:this.logger.isEnabled,...r,...T.isEnabled?{}:{enable:!1}}})}};var $e,We=class extends ee{static{this.observedAttributes=[...ee.observedAttributes,rt,"src",it,N]}static{this.DefaultAutoSync="frame"}#e;#t;#s;#i;#r;constructor(){super(),this.isShaeWorkerElement=!0,this.shadowEnv=new I,this.logger=new T("ShaeWorkerElement"),this.autostart=!0,this.isConnected$=p(!1),this.autoSync$=p($e.DefaultAutoSync),this.src$=p(""),this.#e=!1,this.#t=!1,this.ns$.onChange(e=>{this.shadowEnv.view=M.get(e)}),m(this.shadowEnv,I.ContextCreated,()=>{this.#r?.run(),this.dispatchEvent(new CustomEvent(I.ContextCreated.toLowerCase(),{bubbles:!1,detail:{shadowEnv:this.shadowEnv}}))}),m(this.shadowEnv,I.ContextLost,()=>{this.dispatchEvent(new CustomEvent(I.ContextLost.toLowerCase(),{bubbles:!1,detail:{shadowEnv:this.shadowEnv}}))}),this.autoSync$.onChange(e=>{let t=this.hasAttribute(N),r=t?this.getAttribute(N):void 0;e===$e.DefaultAutoSync?t&&r!==e&&this.setAttribute(N,e):r!==e&&this.setAttribute(N,e)}),this.#a(),this.#n(),this.style.display="contents"}#n(){this.#r=C(()=>{let e=this.src$.get();e&&this.importScript(e)},{autorun:!1})}get shouldAutostart(){return this.autostart&&!je(this,Ds)}get autoSync(){return this.autoSync$.value}set autoSync(e){typeof e!="string"&&(e=e?$e.DefaultAutoSync:"no"),this.autoSync$.set(`${e}`.trim().toLowerCase())}get frameLoop(){return this.#s??=new ge,this.#s}[ge.OnFrame](){this.syncShadowObjects()}async importScript(e){if(!e)throw new Error("src is blank");let t=await this.shadowEnv.ready();return this.logger.isInfo&&this.logger.info("shadowEnv importScript:",e,{shadowEnv:t}),await t.envProxy.importScript(e),this}connectedCallback(){P(()=>{this.hasAttribute(N)&&this.autoSync$.set(this.getAttribute(N)),this.isConnected$.set(!0)}),this.shouldAutostart&&this.start()}disconnectedCallback(){this.isConnected$.set(!1),this.#o()}attributeChangedCallback(e){if(super.attributeChangedCallback(e),e===rt&&this.shadowEnv.envProxy!=null)throw new Error('Changing the "local" attribute after the shadowEnv has been created is not supported.');if(e===it&&this.#h(),e===N&&(this.autoSync=this.hasAttribute(N)?this.getAttribute(N):!0),e==="src"){let t=(this.getAttribute("src")||"").trim();this.src$.set(t),this.shadowEnv.isReady&&this.#r?.run()}}start(){if(!this.#t){if(this.#e=!1,this.shadowEnv.view??=M.get(this.ns),this.shadowEnv.envProxy==null){let e=je(this,rt)?new bt:new vt;this.shadowEnv.envProxy=e,this.#h()}this.#t=!0}return this.shadowEnv.ready()}destroy(){this.#i?.destroy(),this.#r?.destroy(),O(this.isConnected$,this.autoSync$,this.src$),this.shadowEnv.envProxy=void 0,this.shadowEnv.destroy()}#o(){this.#e||(this.#e=!0,queueMicrotask(()=>{this.#e&&this.destroy()}))}#a(){this.#i=C(()=>{if(this.isConnected$.get()){let e=(this.autoSync$.get()||$e.DefaultAutoSync).trim().toLowerCase(),t;if(["true","yes","on","frame","auto-sync"].includes(e))return this.logger.isDebug&&this.logger.debug("auto-sync",e,this),this.frameLoop.start(this),()=>{this.frameLoop.stop(this)};if(e.toLowerCase().endsWith("fps")){let r=parseInt(e,10);r>0?t=Math.floor(1e3/r):this.logger.isWarn&&this.logger.warn(`invalid auto-sync value: ${e}`)}else t=parseInt(e,10),isNaN(t)&&(t=void 0,["false","no","off"].includes(e)||this.logger.error(`invalid auto-sync value: ${e}`));if(t!==void 0&&t>0){this.logger.isDebug&&this.logger.debug("auto-sync interval (ms)",t,this);let r=setInterval(()=>{this.syncShadowObjects()},t);return()=>{clearInterval(r)}}else this.logger.isDebug&&this.logger.debug("auto-sync off",this)}},[this.autoSync$,this.isConnected$])}#h(){let e=this.shadowEnv.envProxy;e?.isLocalEnv&&(e.disableStructuredClone=this.hasAttribute(it))}};$e=We;customElements.define(Ls,We);globalThis.SHADOW_ENTS_BUNDLE_LOADED=!0;
70
+ `)}var Gr=()=>new Ls;var at=(s,e,t=1e3,r)=>new Promise((i,n)=>{let o,a,f=()=>{clearTimeout(o),s.removeEventListener("message",a)};t!==0&&t!==1/0&&(o=setTimeout(()=>{f(),n(new Error(`Timeout waiting for message of type: ${e}`))},t)),a=m=>{if(m.data.type===e)try{(!r||r(m.data))&&(f(),i())}catch(P){f(),n(P.toString())}},s.addEventListener("message",a)});var Yi=s=>{let e;if(s!=null&&Array.isArray(s))for(let t of s)t.transferables&&(e?e=[...e,...t.transferables]:e=t.transferables,delete t.transferables);return e},Ut=class s{constructor(){this.#t=!1,this.#s=0,this.logger=new D("RemoteWorkerEnv"),ee(this,s.WorkerLoaded)}static{this.WorkerLoaded="workerLoaded"}#e;#t;#s;get isDestroyed(){return this.#t}get workerLoaded(){return Ae(this,s.WorkerLoaded)}async start(){if(this.#e)return this.logger.isWarn&&this.logger.warn("already started"),this.workerLoaded.then(()=>{if(this.isDestroyed)throw"worker was destroyed"});let e=this.#e=Gr();this.configureConsoleLogger(e);try{if(await at(e,ar,ur),this.isDestroyed)throw"worker was destroyed";e.addEventListener("message",this.onMessageFromWorker.bind(this)),queueMicrotask(()=>{y(this,s.WorkerLoaded,this)})}catch(t){throw this.logger.error("failed to start",t),this.#e=void 0,t}}applyChangeTrail(e,t){let r=Yi(e),i={type:nr,changeTrail:e},n=++this.#s;return t&&(i.serial=n),this.#e.postMessage(i,r),t?at(this.#e,hr,fr,o=>{if(o.error)throw o.error;return o.serial===n}):Promise.resolve()}importScript(e){return e=Bt(e),this.#e.postMessage({type:ir,importModule:e}),at(this.#e,lr,dr,t=>{if(t.error)throw t.error;return t.url===e})}destroy(){if(!this.#e)return;let e=this.#e;this.#e=void 0,this.#t=!0,e.postMessage({type:or}),at(e,cr,pr).finally(()=>{e.terminate()})}onMessageFromWorker(e){e.data?.type===Me?this.onMessageToView?.(e.data.data):this.logger.isDebug&&this.logger.debug("message from worker",e)}configureConsoleLogger(e){let t=`${z}.RemoteWorkerEnv.workerConfig`,r=JSON.parse(localStorage.getItem(t)??"{}");this.logger.isInfo&&this.logger.info("load console-logger worker config",{localStorageKey:t,workerConfig:r}),e.postMessage({type:z,config:{...D.sharedConfig,enable:this.logger.isEnabled,...r,...D.isEnabled?{}:{enable:!1}}})}};var Gt=class s extends pe{constructor(){super(),this.isShaeWorkerElement=!0,this.shadowEnv=new K,this.logger=new D("ShaeWorkerElement"),this.autostart=!0,this.isConnected$=p(!1),this.autoSync$=p(s.DefaultAutoSync),this.src$=p(""),this.#e=!1,this.#t=!1,this.ns$.onChange(e=>{this.shadowEnv.view=F.get(e)}),w(this.shadowEnv,K.ContextCreated,()=>{this.#r?.run(),this.dispatchEvent(new CustomEvent(K.ContextCreated.toLowerCase(),{bubbles:!1,detail:{shadowEnv:this.shadowEnv}}))}),w(this.shadowEnv,K.ContextLost,()=>{this.dispatchEvent(new CustomEvent(K.ContextLost.toLowerCase(),{bubbles:!1,detail:{shadowEnv:this.shadowEnv}}))}),this.autoSync$.onChange(e=>{let t=this.hasAttribute(V),r=t?this.getAttribute(V):void 0;e===s.DefaultAutoSync?t&&r!==e&&this.setAttribute(V,e):r!==e&&this.setAttribute(V,e)}),this.#a(),this.#n(),this.style.display="contents"}static{this.observedAttributes=[...pe.observedAttributes,ut,"src",dt,V]}static{this.DefaultAutoSync="frame"}#e;#t;#s;#i;#r;#n(){this.#r=S(()=>{let e=this.src$.get();e&&this.importScript(e)},{autorun:!1})}get shouldAutostart(){return this.autostart&&!et(this,Ws)}get autoSync(){return this.autoSync$.value}set autoSync(e){typeof e!="string"&&(e=e?s.DefaultAutoSync:"no"),this.autoSync$.set(`${e}`.trim().toLowerCase())}get frameLoop(){return this.#s??=new tt,this.#s}[tt.OnFrame](){this.syncShadowObjects()}async importScript(e){if(!e)throw new Error("src is blank");let t=await this.shadowEnv.ready();return this.logger.isInfo&&this.logger.info("shadowEnv importScript:",e,{shadowEnv:t}),await t.envProxy.importScript(e),this}connectedCallback(){N(()=>{this.hasAttribute(V)&&this.autoSync$.set(this.getAttribute(V)),this.isConnected$.set(!0)}),this.shouldAutostart&&this.start()}disconnectedCallback(){this.isConnected$.set(!1),this.#o()}attributeChangedCallback(e){if(super.attributeChangedCallback(e),e===ut&&this.shadowEnv.envProxy!=null)throw new Error('Changing the "local" attribute after the shadowEnv has been created is not supported.');if(e===dt&&this.#l(),e===V&&(this.autoSync=this.hasAttribute(V)?this.getAttribute(V):!0),e==="src"){let t=(this.getAttribute("src")||"").trim();this.src$.set(t),this.shadowEnv.isReady&&this.#r?.run()}}start(){if(!this.#t){if(this.#e=!1,this.shadowEnv.view??=F.get(this.ns),this.shadowEnv.envProxy==null){let e=et(this,ut)?new Vt:new Ut;this.shadowEnv.envProxy=e,this.#l()}this.#t=!0}return this.shadowEnv.ready()}destroy(){this.#i?.destroy(),this.#r?.destroy(),L(this.isConnected$,this.autoSync$,this.src$),this.shadowEnv.envProxy=void 0,this.shadowEnv.destroy()}#o(){this.#e||(this.#e=!0,queueMicrotask(()=>{this.#e&&this.destroy()}))}#a(){this.#i=S(()=>{if(this.isConnected$.get()){let e=(this.autoSync$.get()||s.DefaultAutoSync).trim().toLowerCase(),t;if(["true","yes","on","frame","auto-sync"].includes(e))return this.logger.isDebug&&this.logger.debug("auto-sync",e,this),this.frameLoop.start(this),()=>{this.frameLoop.stop(this)};if(e.toLowerCase().endsWith("fps")){let r=parseInt(e,10);r>0?t=Math.floor(1e3/r):this.logger.isWarn&&this.logger.warn(`invalid auto-sync value: ${e}`)}else t=parseInt(e,10),isNaN(t)&&(t=void 0,["false","no","off"].includes(e)||this.logger.error(`invalid auto-sync value: ${e}`));if(t!==void 0&&t>0){this.logger.isDebug&&this.logger.debug("auto-sync interval (ms)",t,this);let r=setInterval(()=>{this.syncShadowObjects()},t);return()=>{clearInterval(r)}}else this.logger.isDebug&&this.logger.debug("auto-sync off",this)}},[this.autoSync$,this.isConnected$])}#l(){let e=this.shadowEnv.envProxy;e?.isLocalEnv&&(e.disableStructuredClone=this.hasAttribute(dt))}};customElements.define(Ns,Gt);globalThis.SHADOW_ENTS_BUNDLE_LOADED=!0;
71
71
  /*! Bundled license information:
72
72
 
73
73
  @spearwolf/eventize/lib/index.mjs:
74
74
  (*!
75
75
  =============================================================================
76
- @spearwolf/eventize 4.0.2+build.20250807
77
- — https://github.com/spearwolf/eventize.git
76
+ @spearwolf/eventize 4.3.1+build.20260508
77
+ git+https://github.com/spearwolf/eventize.git
78
78
  =============================================================================
79
79
 
80
- Copyright 2015-2025 Wolfger Schramm
80
+ Copyright 2015-2026 Wolfger Schramm
81
81
 
82
82
  Licensed under the Apache License, Version 2.0 (the "License");
83
83
  you may not use this file except in compliance with the License.
@@ -92,13 +92,13 @@ var te="*",Zt=1,xt=2,kt=4,z=Symbol.for("eventize"),Hs="[eventize]",Fe=s=>s===te,
92
92
  limitations under the License.
93
93
  *)
94
94
 
95
- @spearwolf/signalize/dist/signalize.DWPi0AAt.js:
95
+ @spearwolf/signalize/dist/signalize.BdDWD_tl.js:
96
96
  @spearwolf/signalize/dist/index.js:
97
97
  @spearwolf/signalize/dist/decorators.js:
98
98
  (*!
99
99
  @file @spearwolf/signalize - signals and effects for all
100
100
  @author Wolfger Schramm <wolfger@spearwolf.de>
101
- @version 0.27.2+esm.20260204
101
+ @version 0.28.0+esm.20260508
102
102
 
103
103
  Copyright 2022-2026 Wolfger Schramm
104
104